+ if (strcmp(targ->route_table, "") != 0) {
+ struct lpm4 *lpm;
+ int ret;
+
+ PROX_PANIC(port->n_vlans == 0, "missing local_ipv4 while route table is specified in L3 mode\n");
+
+ // LPM might be modified runtime => do not share with other cores
+ ret = lua_to_lpm4(prox_lua(), GLOBAL, targ->route_table, socket_id, &lpm);
+ PROX_PANIC(ret, "Failed to load IPv4 LPM:\n%s\n", get_lua_to_errors());
+
+ tbase->l3.ipv4_lpm = lpm->rte_lpm;
+ tbase->l3.next_hops = prox_zmalloc(sizeof(*tbase->l3.next_hops) * MAX_HOP_INDEX, socket_id);
+ PROX_PANIC(tbase->l3.next_hops == NULL, "Could not allocate memory for next hop\n");
+
+ for (uint32_t i = 0; i < MAX_HOP_INDEX; i++) {
+ if (!lpm->next_hops[i].ip_dst)
+ continue;
+ tbase->l3.nb_gws++;
+ tbase->l3.next_hops[i].ip = rte_bswap32(lpm->next_hops[i].ip_dst);
+ int tx_port = lpm->next_hops[i].mac_port.out_idx;
+ // gen only supports one port right now .... hence port = 0
+ if ((tx_port > targ->nb_txports - 1) && (tx_port > targ->nb_txrings - 1)) {
+ PROX_PANIC(1, "Routing Table contains port %d but only %d tx port/ %d ring:\n", tx_port, targ->nb_txports, targ->nb_txrings);
+ }
+ }
+ plog_info("Using routing table %s in l3 mode, with %d gateways\n", targ->route_table, tbase->l3.nb_gws);
+
+ // Last but one (x n_vlans) "next_hop_index" is not a gateway but direct routes
+ for (int vlan_id = 0; vlan_id < port->n_vlans; vlan_id++) {
+ tbase->l3.next_hops[tbase->l3.nb_gws].ip = 0;
+ ret = rte_lpm_add(tbase->l3.ipv4_lpm, port->ip_addr[vlan_id].ip, port->ip_addr[vlan_id].prefix, tbase->l3.nb_gws++);
+ PROX_PANIC(ret, "Failed to add local_ipv4 "IPv4_BYTES_FMT"/%d to lpm\n", IP4(port->ip_addr[vlan_id].ip), port->ip_addr[vlan_id].prefix);
+ }
+
+ // Last "next_hop_index" is default gw
+ tbase->l3.next_hops[tbase->l3.nb_gws].ip = rte_bswap32(targ->gateway_ipv4);
+ if (targ->gateway_ipv4) {
+ ret = rte_lpm_add(tbase->l3.ipv4_lpm, targ->gateway_ipv4, 0, tbase->l3.nb_gws++);
+ PROX_PANIC(ret, "Failed to add gateway_ipv4 "IPv4_BYTES_FMT"/%d to lpm\n", IP4(tbase->l3.gw.ip), 0);
+ }
+ }
+
+ master_init_vdev(tbase->l3.tmaster, tbase->l3.reachable_port_id, targ->lconf->id, targ->id);
+
+ // Create IPv6 addr if none were configured
+ if (targ->flags & TASK_ARG_NDP) {
+ if (!memcmp(&targ->local_ipv6, &null_addr, sizeof(struct ipv6_addr))) {
+ set_link_local(&targ->local_ipv6);
+ set_EUI(&targ->local_ipv6, &port->eth_addr);
+ }
+ plog_info("\tCore %d, task %d, local IPv6 addr is "IPv6_BYTES_FMT" (%s)\n",
+ targ->lconf->id, targ->id,
+ IPv6_BYTES(targ->local_ipv6.bytes),
+ IP6_Canonical(&targ->local_ipv6));
+ memcpy(&tbase->l3.local_ipv6, &targ->local_ipv6, sizeof(struct ipv6_addr));
+
+ if (memcmp(&targ->global_ipv6, &null_addr, sizeof(struct ipv6_addr))) {
+ memcpy(&tbase->l3.global_ipv6, &targ->global_ipv6, sizeof(struct ipv6_addr));
+ plog_info("\tCore %d, task %d, global IPv6 addr is "IPv6_BYTES_FMT" (%s)\n",
+ targ->lconf->id, targ->id,
+ IPv6_BYTES(targ->global_ipv6.bytes),
+ IP6_Canonical(&targ->global_ipv6));
+ }
+ if (targ->ipv6_router)
+ register_router_to_ctrl_plane(tbase->l3.tmaster, tbase->l3.reachable_port_id, targ->lconf->id, targ->id, &targ->local_ipv6, &targ->global_ipv6, &targ->router_prefix);
+ else
+ register_node_to_ctrl_plane(tbase->l3.tmaster, &targ->local_ipv6, &targ->global_ipv6, tbase->l3.reachable_port_id, targ->lconf->id, targ->id);
+ }
+