diff options
Diffstat (limited to 'netlink')
-rw-r--r-- | netlink/librtnl/mapper.c | 45 | ||||
-rw-r--r-- | netlink/test/test.c | 9 |
2 files changed, 54 insertions, 0 deletions
diff --git a/netlink/librtnl/mapper.c b/netlink/librtnl/mapper.c index dd53684..b82fae8 100644 --- a/netlink/librtnl/mapper.c +++ b/netlink/librtnl/mapper.c @@ -19,6 +19,13 @@ #include <vnet/ip/ip.h> #include <vnet/ip/lookup.h> +#ifdef ip6_add_del_route_next_hop +#define FIB_VERSION 1 +#else +#include <vnet/fib/fib.h> +#define FIB_VERSION 2 +#endif + typedef struct { int linux_ifindex; u32 sw_if_index; @@ -63,6 +70,7 @@ int mapper_add_del_route(mapper_ns_t *ns, ns_route_t *route, int del) if (route->rtm.rtm_dst_len >= 8 && route->dst[0] == 0xff) return 0; +#if FIB_VERSION == 1 struct ip6_main_t *im = &ip6_main; ip6_add_del_route_next_hop(im, //ip6_main del?IP6_ROUTE_FLAG_DEL:IP6_ROUTE_FLAG_ADD, //flags (not del) @@ -73,7 +81,26 @@ int mapper_add_del_route(mapper_ns_t *ns, ns_route_t *route, int del) 0, //weight ~0, //adj_index ns->v6fib_index); +#else + fib_prefix_t prefix; + ip46_address_t nh; + + memset (&prefix, 0, sizeof (prefix)); + prefix.fp_len = route->rtm.rtm_dst_len; + prefix.fp_proto = FIB_PROTOCOL_IP6; + clib_memcpy (&prefix.fp_addr.ip6, route->dst, sizeof (prefix.fp_addr.ip6)); + + memset (&nh, 0, sizeof (nh)); + clib_memcpy (&nh.ip6, route->gateway, sizeof (nh.ip6)); + + fib_table_entry_path_add (ns->v6fib_index, &prefix, FIB_SOURCE_API, + FIB_ENTRY_FLAG_NONE, prefix.fp_proto, + &nh, map->sw_if_index, ns->v6fib_index, + 0 /* weight */, MPLS_LABEL_INVALID, + FIB_ROUTE_PATH_FLAG_NONE); +#endif /* FIB_VERSION == 1 */ } else { +#if FIB_VERSION == 1 struct ip4_main_t *im = &ip4_main; ip4_add_del_route_next_hop(im, //ip4_main del?IP4_ROUTE_FLAG_DEL:IP4_ROUTE_FLAG_ADD, //flags (not del) @@ -84,6 +111,24 @@ int mapper_add_del_route(mapper_ns_t *ns, ns_route_t *route, int del) 0, //weight ~0, //adj_index ns->v4fib_index); +#else + fib_prefix_t prefix; + ip46_address_t nh; + + memset (&prefix, 0, sizeof (prefix)); + prefix.fp_len = route->rtm.rtm_dst_len; + prefix.fp_proto = FIB_PROTOCOL_IP4; + clib_memcpy (&prefix.fp_addr.ip4, route->dst, sizeof (prefix.fp_addr.ip4)); + + memset (&nh, 0, sizeof (nh)); + clib_memcpy (&nh.ip4, route->gateway, sizeof (nh.ip4)); + + fib_table_entry_path_add (ns->v4fib_index, &prefix, FIB_SOURCE_API, + FIB_ENTRY_FLAG_NONE, prefix.fp_proto, + &nh, map->sw_if_index, ns->v4fib_index, + 0 /* weight */, MPLS_LABEL_INVALID, + FIB_ROUTE_PATH_FLAG_NONE); +#endif /* FIB_VERSION == 1 */ } return 0; diff --git a/netlink/test/test.c b/netlink/test/test.c index 5a62558..96f49f8 100644 --- a/netlink/test/test.c +++ b/netlink/test/test.c @@ -121,8 +121,17 @@ mapper_ns_add_command_fn (vlib_main_t * vm, if (!strcmp(nsname, "default")) nsname[0] = 0; +#ifdef find_ip4_fib_by_table_index_or_id u32 fib4 = find_ip4_fib_by_table_index_or_id(&ip4_main, table_id, 0) - ip4_main.fibs; +#else + u32 fib4 = fib_table_id_find_fib_index (FIB_PROTOCOL_IP4, table_id); +#endif + +#ifdef find_ip6_fib_by_table_index_or_id u32 fib6 = find_ip6_fib_by_table_index_or_id(&ip6_main, table_id, 0) - ip6_main.fibs; +#else + u32 fib6 = fib_table_id_find_fib_index (FIB_PROTOCOL_IP6, table_id); +#endif if (mapper_add_ns(nsname, fib4, fib6, &mapper_indexes[index])) return clib_error_return(0, "Could not add ns %s", nsname); |