int control_add_ipv4_local_entry(struct in_addr* nexthop, struct in_addr* saddr, uint8_t depth, uint32_t port_id, int32_t socket_id) { int s; uint16_t nexthop_id; s = neighbor4_lookup_nexthop(neighbor4_struct[socket_id], nexthop, &nexthop_id); if (s < 0) { s = neighbor4_add_nexthop(neighbor4_struct[socket_id], nexthop, &nexthop_id, NEI_ACTION_KNI); if (s < 0) { RTE_LOG( ERR, PKTJ_CTRL1, "failed to add a nexthop during route adding...\n"); return -1; } } neighbor4_set_port(neighbor4_struct[socket_id], nexthop_id, port_id); s = rte_lpm_add(ipv4_pktj_lookup_struct[socket_id], rte_be_to_cpu_32(saddr->s_addr), depth, nexthop_id); if (s < 0) { RTE_LOG( ERR, PKTJ_CTRL1, "failed to add a route in lpm during route adding...\n"); return -1; } neighbor4_refcount_incr(neighbor4_struct[socket_id], nexthop_id); return nexthop_id; }
static int add_invalid_neighbor4(neighbor_struct_t *neighbor_struct, struct in_addr *ip, uint16_t dst_port) { struct ether_addr invalid_mac = {{0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}; uint8_t nexthop_id; if (neighbor4_add_nexthop(neighbor_struct, ip, &nexthop_id, NEI_ACTION_DROP) < 0) { return -1; } neighbor4_refcount_incr(neighbor_struct, nexthop_id); neighbor4_set_lladdr_port(neighbor_struct, nexthop_id, &invalid_mac, &invalid_mac, dst_port, -1); return 0; }
static int route4(__rte_unused struct rtmsg* route, route_action_t action, struct in_addr* addr, uint8_t depth, struct in_addr* nexthop, uint8_t type, void* args) { // If route add // lookup next hop in neighbor table ipv4 // if not lookup // create next hop, with flag invalid and addr = nexthop // nexthopid = last id // // register new route in lpm, with nexthop id // increment refcount in neighbor // If route delete // lookup next hop in neighbor table ipv4 // if not lookup // then WTF TABLE CORRUPTED // remove route from lpm // decrement refcount in neighbor // if refcount reached 0 // then flag entry empty struct control_handle* handle = args; assert(handle != NULL); uint16_t nexthop_id; int s; int32_t socket_id = handle->socket_id; struct in_addr blackhole_addr4 = {rte_be_to_cpu_32(INADDR_ANY)}; if (type == RTN_BLACKHOLE) { nexthop = &blackhole_addr4; } if (action == ROUTE_ADD) { RTE_LOG(DEBUG, PKTJ_CTRL1, "adding an ipv4 route...\n"); // lookup nexthop s = neighbor4_lookup_nexthop(neighbor4_struct[socket_id], nexthop, &nexthop_id); if (s < 0) { s = neighbor4_add_nexthop(neighbor4_struct[socket_id], nexthop, &nexthop_id, NEI_ACTION_FWD); if (s < 0) { RTE_LOG(ERR, PKTJ_CTRL1, "failed to add a " "nexthop during " "route adding...\n"); return -1; } } s = rte_lpm_add(ipv4_pktj_lookup_struct[socket_id], rte_be_to_cpu_32(addr->s_addr), depth, nexthop_id); if (s < 0) { lpm4_stats[socket_id].nb_add_ko++; RTE_LOG(ERR, PKTJ_CTRL1, "failed to add a route in " "lpm during route " "adding...\n"); return -1; } neighbor4_refcount_incr(neighbor4_struct[socket_id], nexthop_id); lpm4_stats[socket_id].nb_add_ok++; } if (action == ROUTE_DELETE) { RTE_LOG(DEBUG, PKTJ_CTRL1, "deleting an ipv4 route...\n"); // lookup nexthop s = neighbor4_lookup_nexthop(neighbor4_struct[socket_id], nexthop, &nexthop_id); if (s < 0) { RTE_LOG(ERR, PKTJ_CTRL1, "failed to find nexthop " "during route deletion...\n"); return -1; } s = rte_lpm_delete(ipv4_pktj_lookup_struct[socket_id], rte_be_to_cpu_32(addr->s_addr), depth); if (s < 0) { lpm4_stats[socket_id].nb_del_ko++; RTE_LOG(ERR, PKTJ_CTRL1, "failed to delete route...\n"); return -1; } neighbor4_refcount_decr(neighbor4_struct[socket_id], nexthop_id); lpm4_stats[socket_id].nb_del_ok++; } RTE_LOG(DEBUG, PKTJ_CTRL1, "route ope success\n"); return 0; }