static ucli_status_t ppe_ucli_utm__checkf__(ucli_context_t* uc) { ppe_header_t cheader; ppe_header_t pheader; UCLI_COMMAND_INFO(uc, "checkf", 1, "Check the packet format."); UCLI_ARGPARSE_OR_RETURN(uc, "{ppe_header}", &cheader); ppe_packet_format_get(&ppec->ppep, &pheader); if(pheader != cheader) { return ucli_error(uc, "packet format is currently %{ppe_header}.", pheader); } return UCLI_STATUS_OK; }
indigo_error_t dhcpra_create_send_packet_in (of_port_no_t in_port, of_octets_t *of_octets) { of_packet_in_t *of_packet_in; of_match_t match; ppe_packet_t ppep; ppe_header_t format; uint8_t buf[1500]; int option; int debug_dump = 0; if (!of_octets) return INDIGO_ERROR_UNKNOWN; /* * Check if the packet_in is untagged, then add the Vlan tag */ ppe_packet_init(&ppep, of_octets->data, of_octets->bytes); if (ppe_parse(&ppep) < 0) { printf("RAW untag linux packet parsing failed.\n"); return INDIGO_ERROR_UNKNOWN; } if (!(ppe_header_get(&ppep, PPE_HEADER_DHCP))) { /* Since we listen to all pkt_in * Rate is high, no need add debug msg here * Not LLDP packet, simply return */ printf("in_port=%u: NOT DHCP packet IGNORED", in_port); return INDIGO_ERROR_NONE; } /* Dump up to DHCP hdr */ printf("RAW untag Linux dump\n"); get_dhcp_options(&ppep, of_octets->bytes, debug_dump, &option); ppe_packet_format_get(&ppep, &format); if (format != PPE_HEADER_8021Q) { of_octets->bytes += 4; memcpy(buf, of_octets->data, of_octets->bytes); memcpy(of_octets->data+16, buf+12, of_octets->bytes-16); of_octets->data[12] = ETHERTYPE_DOT1Q >> 8; of_octets->data[13] = ETHERTYPE_DOT1Q & 0xFF; of_octets->data[14] = 0; of_octets->data[15] = VLAN_TEST; //7; } else {
static ucli_status_t ppe_ucli_utm__fdump__(ucli_context_t* uc) { ppe_field_t field; ppe_header_t format; UCLI_COMMAND_INFO(uc, "fdump", 0, "Dump all packet fields."); ppe_packet_format_get(&ppec->ppep, &format); ucli_printf(uc, "format=%{ppe_header}, size=%d\n", format, ppec->ppep.size); for(field = 0; field < PPE_FIELD_COUNT; field++) { const ppe_field_info_t* fi = ppe_field_info_get(field); if(fi->size_bits == 0) { continue; } if(ppe_field_exists(&ppec->ppep, field) == 0) { continue; } if(fi->size_bits <= 32) { uint32_t data; ppe_field_get(&ppec->ppep, field, &data); ucli_printf(uc, "%{ppe_field} = 0x%x (%d)\n", field, data, data); } else { uint8_t* p = ppe_fieldp_get(&ppec->ppep, field); ucli_printf(uc, "%{ppe_field} = %{data}\n", field, p, fi->size_bits/8); } } return UCLI_STATUS_OK; }
/* * This is clearly an unscaleable approach. * If the combinations increase this should be * rewritten properly. */ int ppe_packet_format_set(ppe_packet_t* ppep, ppe_header_t type) { int rv = 0; ppe_header_t current; ppe_packet_format_get(ppep, ¤t); PPE_LOG_FORMAT("convert (data=%p,size=%d) from format %s to format %s", ppep->data, ppep->size, ppe_header_name(current), ppe_header_name(type)); if(current == type) { /* Already in the requested format. */ return 0; } else { switch(current) { case PPE_HEADER_8021Q: { switch(type) { case PPE_HEADER_ETHERII: { PPE_MEMMOVE(ppep->data + 12, ppep->data + 16, ppep->size - 16); ppep->size -= 4; break; } default: { AIM_LOG_ERROR("invalid format set (%s)", ppe_header_name(type)); return -1; } } break; } case PPE_HEADER_ETHERII: { switch(type) { case PPE_HEADER_8021Q: { /* @fixme architecture */ ppep->size += 4; ppep->_data = ppep->data; ppep->data = aim_zmalloc(ppep->size); PPE_MEMCPY(ppep->data, ppep->_data, 12); PPE_MEMCPY(ppep->data+16, ppep->_data+12, ppep->size-16); ppep->data[12] = 0x81; ppep->data[13] = 0; ppep->data[14] = 0; ppep->data[15] = 0; ppep->realloc = 1; rv = 1; break; } default: { AIM_LOG_ERROR("invalid format set(%s)", ppe_header_name(type)); return -1; } } break; } default: { AIM_LOG_ERROR("cannot convert from current format (%s)", ppe_header_name(type)); return -1; } } /** * Need to reparse */ ppe_parse(ppep); return rv; } }