Exemplo n.º 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;
}
Exemplo n.º 2
0
static int
add_invalid_neighbor6(neighbor_struct_t *neighbor_struct, struct in6_addr *ip,
		      uint16_t dst_port)
{
	struct ether_addr invalid_mac = {{0x00, 0x00, 0x00, 0x00, 0x00, 0x00}};
	uint8_t nexthop_id;

	if (neighbor6_add_nexthop(neighbor_struct, ip, &nexthop_id,
				  NEI_ACTION_DROP) < 0) {
		return -1;
	}

	neighbor6_refcount_incr(neighbor_struct, nexthop_id);
	neighbor6_set_lladdr_port(neighbor_struct, nexthop_id, &invalid_mac,
				  &invalid_mac, dst_port, -1);
	return 0;
}
Exemplo n.º 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;
}