Exemple #1
0
int
control_add_ipv6_local_entry(struct in6_addr *nexthop, struct in6_addr *saddr,
			     uint8_t depth, uint32_t port_id, int32_t socket_id)
{
	int s;
	uint8_t nexthop_id;

	s = neighbor6_lookup_nexthop(neighbor6_struct[socket_id], nexthop,
				     &nexthop_id);
	if (s < 0) {
		s = neighbor6_add_nexthop(neighbor6_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;
		}

		// apply rate limit rule if next hop neighbor is in the table
		apply_rate_limit_ipv6(nexthop, nexthop_id, socket_id);
	}
	neighbor6_set_port(neighbor6_struct[socket_id], nexthop_id, port_id);
	s = rte_lpm6_add(ipv6_pktj_lookup_struct[socket_id], saddr->s6_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;
	}
	neighbor6_refcount_incr(neighbor6_struct[socket_id], nexthop_id);
	return nexthop_id;
}
Exemple #2
0
static int
neighbor6(neighbor_action_t action,
	  int32_t port_id,
	  struct in6_addr* addr,
	  struct ether_addr* lladdr,
	  uint8_t flags,
	  __rte_unused uint16_t vlan_id,
	  void* args)
{
	// if port_id is not handled
	//   ignore, return immediatly
	// if neighbor add
	//   lookup neighbor
	//   if exists
	//     update lladdr, set flag as REACHABLE/STALE/DELAY
	//   else
	//     // This should not happen
	//     insert new nexthop
	//     set insert date=now, refcount = 0, flag=REACHABLE/STALE/DELAY
	// if neighbor delete
	//   lookup neighbor
	//   if exists
	//     if refcount != 0
	//       set nexthop as invalid
	//     else
	//       set flag empty
	//   else
	//     do nothing
	//     // this should not happen

	struct control_handle* handle = args;
	assert(handle != NULL);
	int s;
	uint16_t nexthop_id, find_id;
	int32_t socket_id = handle->socket_id;
	char ipbuf[INET6_ADDRSTRLEN];

	assert(neighbor6_struct != NULL);

	if (addr == NULL)
		return -1;
	inet_ntop(AF_INET6, addr, ipbuf, INET6_ADDRSTRLEN);

	if (action == NEIGHBOR_ADD) {
		if (lladdr == NULL)
			return -1;
		char ibuf[IFNAMSIZ];
		unsigned kni_vlan;

		if_indextoname(port_id, ibuf);
		s = sscanf(ibuf, "dpdk%10u.%10u", &port_id, &kni_vlan);

		if (s <= 0) {
			RTE_LOG(ERR, PKTJ_CTRL1,
				"received a neighbor "
				"announce for an unmanaged "
				"iface %s\n",
				ibuf);
			return -1;
		}

		s = neighbor6_lookup_nexthop(neighbor6_struct[socket_id], addr,
					     &nexthop_id);
		if (s < 0) {
			if (flags != NUD_NONE && flags != NUD_NOARP &&
			    flags != NUD_STALE) {
				RTE_LOG(ERR, PKTJ_CTRL1,
					"failed to change state in neighbor6 "
					"table (state %d, %s)...\n",
					flags, ipbuf);
				return -1;
			}

			{
				RTE_LOG(
				    DEBUG, PKTJ_CTRL1,
				    "adding ipv6 neighbor %s with port_id %d "
				    "vlan_id %d...\n",
				    ipbuf, port_id, kni_vlan);
			}

			s = neighbor6_add_nexthop(neighbor6_struct[socket_id],
						  addr, &nexthop_id,
						  NEI_ACTION_FWD);
			if (s < 0) {
				RTE_LOG(ERR, PKTJ_CTRL1,
					"failed to add a "
					"nexthop in neighbor "
					"table...\n");
				return -1;
			}

			// apply rate limit rule if next hop neighbor is in the
			// table
			apply_rate_limit_ipv6(addr, nexthop_id, socket_id);

			if (rte_lpm6_lookup(ipv6_pktj_lookup_struct[socket_id],
					    addr->s6_addr, &find_id) == 0) {
				s = rte_lpm6_add(
				    ipv6_pktj_lookup_struct[socket_id],
				    addr->s6_addr, 128, nexthop_id);
				if (s < 0) {
					lpm6_stats[socket_id].nb_add_ko++;
					RTE_LOG(ERR, PKTJ_CTRL1,
						"failed to add a route in "
						"lpm during neighbor "
						"adding...\n");
					return -1;
				}
				lpm6_stats[socket_id].nb_add_ok++;
			}
		}

		if (flags == NUD_FAILED) {
			neighbor6_set_action(neighbor6_struct[socket_id],
					     nexthop_id, NEI_ACTION_KNI);
		} else {
			neighbor6_set_action(neighbor6_struct[socket_id],
					     nexthop_id, NEI_ACTION_FWD);
		}
		RTE_LOG(DEBUG, PKTJ_CTRL1,
			"set neighbor6 with port_id %d state %d \n", port_id,
			flags);
		neighbor6_set_lladdr_port(neighbor6_struct[socket_id],
					  nexthop_id, &ports_eth_addr[port_id],
					  lladdr, port_id, kni_vlan);
		neighbor6_set_state(neighbor6_struct[socket_id], nexthop_id,
				    flags);
	}
	if (action == NEIGHBOR_DELETE) {
		if (flags != NUD_FAILED && flags != NUD_STALE) {
			RTE_LOG(
			    DEBUG, PKTJ_CTRL1,
			    "neighbor6 delete ope failed, bad NUD state: %d \n",
			    flags);
			return -1;
		}

		RTE_LOG(DEBUG, PKTJ_CTRL1, "deleting ipv6 neighbor...\n");
		s = neighbor6_lookup_nexthop(neighbor6_struct[socket_id], addr,
					     &nexthop_id);
		if (s < 0) {
			RTE_LOG(ERR, PKTJ_CTRL1,
				"failed to find a nexthop to "
				"delete in neighbor "
				"table...\n");
			return 0;
		}
		neighbor6_delete(neighbor6_struct[socket_id], nexthop_id);
		// FIXME not thread safe
		if (neighbor6_struct[socket_id]
			->entries.t6[nexthop_id]
			.neighbor.refcnt == 0) {
			s = rte_lpm6_delete(ipv6_pktj_lookup_struct[socket_id],
					    addr->s6_addr, 128);
			if (s < 0) {
				lpm6_stats[socket_id].nb_del_ko++;
				RTE_LOG(ERR, PKTJ_CTRL1,
					"failed to delete route...\n");
				return -1;
			}

			// reset rate limit for this id
			rlimit6_max[socket_id][nexthop_id] = UINT32_MAX;

			lpm6_stats[socket_id].nb_del_ok++;
		}
	}
	RTE_LOG(DEBUG, PKTJ_CTRL1, "neigh %s ope success\n", ipbuf);
	return 0;
}
Exemple #3
0
static int
route6(__rte_unused struct rtmsg* route,
       route_action_t action,
       struct in6_addr* addr,
       uint8_t depth,
       struct in6_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;
	static struct in6_addr blackhole_addr6 = IN6ADDR_ANY_INIT;

	if (type == RTN_BLACKHOLE) {
		nexthop = &blackhole_addr6;
	}

	if (action == ROUTE_ADD) {
		RTE_LOG(DEBUG, PKTJ_CTRL1, "adding an ipv6 route...\n");
		// lookup nexthop
		s = neighbor6_lookup_nexthop(neighbor6_struct[socket_id],
					     nexthop, &nexthop_id);
		if (s < 0) {
			s = neighbor6_add_nexthop(neighbor6_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;
			}

			// apply rate limit rule if next hop neighbor is in the
			// table
			apply_rate_limit_ipv6(nexthop, nexthop_id, socket_id);
		}
		s = rte_lpm6_add(ipv6_pktj_lookup_struct[socket_id],
				 addr->s6_addr, depth, nexthop_id);
		if (s < 0) {
			lpm6_stats[socket_id].nb_add_ko++;
			RTE_LOG(ERR, PKTJ_CTRL1,
				"failed to add a route in "
				"lpm during route "
				"adding...\n");
			return -1;
		}
		neighbor6_refcount_incr(neighbor6_struct[socket_id],
					nexthop_id);
		lpm6_stats[socket_id].nb_add_ok++;
	}

	if (action == ROUTE_DELETE) {
		RTE_LOG(DEBUG, PKTJ_CTRL1, "deleting an ipv6 route...\n");
		// lookup nexthop
		s = neighbor6_lookup_nexthop(neighbor6_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_lpm6_delete(ipv6_pktj_lookup_struct[socket_id],
				    addr->s6_addr, depth);
		if (s < 0) {
			lpm6_stats[socket_id].nb_del_ko++;
			RTE_LOG(ERR, PKTJ_CTRL1, "failed to delete route...\n");
			return -1;
		}
		neighbor6_refcount_decr(neighbor6_struct[socket_id],
					nexthop_id);
		lpm6_stats[socket_id].nb_del_ok++;
	}
	RTE_LOG(DEBUG, PKTJ_CTRL1, "route ope success\n");
	return 0;
}