[PATCH 1/2] Add IP6_SADR support to Bird Core
This adds support for source-specific IPv6 routes to Bird core. This is based on Dean Luga's original patch, with the review comments addressed. Sadr support is added to network address parsing in confbase.Y and to the kernel protocol on Linux. A couple of issues remain with this patch: - Had to change the default addr_type in rt_setup() to NET_SADR_IP6 to get the kernel 'learn' mechanism to work. - Not sure if the logic in net_route_sadr_ip6() is right. - The config parser barfs on sadr route literals in the static protocol with an "Integer expression expected" error message. - There's no way to mix source-specific and non-source-specific routes (i.e., sadr tables cannot be connected to non-sadr tables). Signed-off-by: Toke Høiland-Jørgensen <toke@toke.dk> --- conf/confbase.Y | 22 ++++++++++++++++--- lib/net.c | 34 ++++++++++++++++++++++++++++++ lib/net.h | 57 ++++++++++++++++++++++++++++++++++++++++++++++---- nest/config.Y | 5 +++-- nest/rt-fib.c | 2 ++ nest/rt-table.c | 49 ++++++++++++++++++++++++++++++++++++++----- sysdep/linux/netlink.c | 31 +++++++++++++++++++++++++-- sysdep/unix/krt.c | 8 ++++--- 8 files changed, 189 insertions(+), 19 deletions(-) diff --git a/conf/confbase.Y b/conf/confbase.Y index 7e0537c5..246d6c3b 100644 --- a/conf/confbase.Y +++ b/conf/confbase.Y @@ -82,7 +82,7 @@ CF_DECLS %type <i> expr bool pxlen4 %type <time> expr_us time %type <a> ipa -%type <net> net_ip4_ net_ip6_ net_ip6 net_ip_ net_ip net_or_ipa +%type <net> net_ip4_ net_ip6_ net_sadr_ip6_ net_ip6 net_ip_ net_ip net_or_ipa %type <net_ptr> net_ net_any net_vpn4_ net_vpn6_ net_vpn_ net_roa4_ net_roa6_ net_roa_ net_mpls_ %type <mls> label_stack_start label_stack @@ -96,7 +96,7 @@ CF_DECLS %left '!' %nonassoc '.' -CF_KEYWORDS(DEFINE, ON, OFF, YES, NO, S, MS, US, PORT, VPN, MPLS) +CF_KEYWORDS(DEFINE, ON, OFF, YES, NO, S, MS, US, PORT, VPN, MPLS, FROM) CF_GRAMMAR @@ -206,6 +206,22 @@ net_ip6_: IP6 '/' NUM n->prefix, n->pxlen, ip6_and(n->prefix, ip6_mkmask(n->pxlen)), n->pxlen); }; +net_sadr_ip6_: IP6 '/' NUM FROM IP6 '/' NUM +{ + if ($3 > IP6_MAX_PREFIX_LENGTH) + cf_error("Invalid prefix length %u", $3); + + if ($7 > IP6_MAX_PREFIX_LENGTH) + cf_error("Invalid prefix length %u", $7); + + net_fill_sadr_ip6(&($$), $1, $3, $5, $7); + + net_addr_sadr_ip6 *n = (void *) &($$); + if (!net_validate_sadr_ip6(n)) + cf_error("Invalid SADR IPv6 prefix %I6/%d from %I6/%d", + n->dst_prefix, n->dst_pxlen, n->src_prefix, n->src_pxlen); +}; + net_vpn4_: VPN_RD net_ip4_ { $$ = cfg_alloc(sizeof(net_addr_vpn4)); @@ -240,7 +256,7 @@ net_mpls_: MPLS NUM net_fill_mpls($$, $2); } -net_ip_: net_ip4_ | net_ip6_ ; +net_ip_: net_ip4_ | net_ip6_ | net_sadr_ip6_; net_vpn_: net_vpn4_ | net_vpn6_ ; net_roa_: net_roa4_ | net_roa6_ ; diff --git a/lib/net.c b/lib/net.c index 9335b78f..a2dad51d 100644 --- a/lib/net.c +++ b/lib/net.c @@ -14,6 +14,7 @@ const char * const net_label[] = { [NET_ROA6] = "roa6", [NET_FLOW4] = "flow4", [NET_FLOW6] = "flow6", + [NET_SADR_IP6] = "sadr6", [NET_MPLS] = "mpls", }; @@ -26,6 +27,7 @@ const u16 net_addr_length[] = { [NET_ROA6] = sizeof(net_addr_roa6), [NET_FLOW4] = 0, [NET_FLOW6] = 0, + [NET_SADR_IP6]= sizeof(net_addr_sadr_ip6), [NET_MPLS] = sizeof(net_addr_mpls), }; @@ -38,6 +40,7 @@ const u8 net_max_prefix_length[] = { [NET_ROA6] = IP6_MAX_PREFIX_LENGTH, [NET_FLOW4] = IP4_MAX_PREFIX_LENGTH, [NET_FLOW6] = IP6_MAX_PREFIX_LENGTH, + [NET_SADR_IP6]= IP6_MAX_PREFIX_LENGTH, [NET_MPLS] = 0, }; @@ -50,6 +53,7 @@ const u16 net_max_text_length[] = { [NET_ROA6] = 60, /* "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff/128-128 AS4294967295" */ [NET_FLOW4] = 0, /* "flow4 { ... }" */ [NET_FLOW6] = 0, /* "flow6 { ... }" */ + [NET_SADR_IP6]= 92, /* "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff/128 from ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff/128" */ [NET_MPLS] = 7, /* "1048575" */ }; @@ -102,6 +106,8 @@ net_format(const net_addr *N, char *buf, int buflen) return flow4_net_format(buf, buflen, &n->flow4); case NET_FLOW6: return flow6_net_format(buf, buflen, &n->flow6); + case NET_SADR_IP6: + return bsnprintf(buf, buflen, "%I6/%d from %I6/%d", n->sadr_ip6.dst_prefix, n->sadr_ip6.dst_pxlen, n->sadr_ip6.src_prefix, n->sadr_ip6.src_pxlen); case NET_MPLS: return bsnprintf(buf, buflen, "%u", n->mpls.label); } @@ -126,12 +132,25 @@ net_pxmask(const net_addr *a) case NET_FLOW6: return ipa_from_ip6(ip6_mkmask(net6_pxlen(a))); + case NET_SADR_IP6: + return ipa_from_ip6(ip6_mkmask(net6_pxlen(a))); + case NET_MPLS: default: return IPA_NONE; } } +int +net_compare_sadr_ip6(const net_addr_sadr_ip6 *a, const net_addr_sadr_ip6 *b) +{ + int dst_cmp = ip6_compare(a->dst_prefix, b->dst_prefix) ?: uint_cmp(a->dst_pxlen, b->dst_pxlen); + if (dst_cmp) + return dst_cmp; + else + return ip6_compare(a->src_prefix, b->src_prefix) ?: uint_cmp(a->src_pxlen, b->src_pxlen); +} + int net_compare(const net_addr *a, const net_addr *b) { @@ -158,6 +177,8 @@ net_compare(const net_addr *a, const net_addr *b) return net_compare_flow6((const net_addr_flow6 *) a, (const net_addr_flow6 *) b); case NET_MPLS: return net_compare_mpls((const net_addr_mpls *) a, (const net_addr_mpls *) b); + case NET_SADR_IP6: + return net_compare_sadr_ip6((const net_addr_sadr_ip6 *) a, (const net_addr_sadr_ip6 *) b); } return 0; } @@ -177,6 +198,7 @@ net_hash(const net_addr *n) case NET_ROA6: return NET_HASH(n, roa6); case NET_FLOW4: return NET_HASH(n, flow4); case NET_FLOW6: return NET_HASH(n, flow6); + case NET_SADR_IP6: return NET_HASH(n, sadr_ip6); case NET_MPLS: return NET_HASH(n, mpls); default: bug("invalid type"); } @@ -199,6 +221,7 @@ net_validate(const net_addr *n) case NET_FLOW4: return NET_VALIDATE(n, flow4); case NET_FLOW6: return NET_VALIDATE(n, flow6); case NET_MPLS: return NET_VALIDATE(n, mpls); + case NET_SADR_IP6: return NET_VALIDATE(n, sadr_ip6); default: return 0; } } @@ -224,6 +247,9 @@ net_normalize(net_addr *N) case NET_MPLS: return; + + case NET_SADR_IP6: + return net_normalize_sadr_ip6(&n->sadr_ip6); } } @@ -248,6 +274,9 @@ net_classify(const net_addr *N) case NET_MPLS: return IADDR_HOST | SCOPE_UNIVERSE; + + case NET_SADR_IP6: + return ip6_zero(n->sadr_ip6.dst_prefix) ? (IADDR_HOST | SCOPE_UNIVERSE) : ip6_classify(&n->sadr_ip6.dst_prefix); } return IADDR_INVALID; @@ -274,6 +303,11 @@ ipa_in_netX(const ip_addr a, const net_addr *n) return ip6_zero(ip6_and(ip6_xor(ipa_to_ip6(a), net6_prefix(n)), ip6_mkmask(net6_pxlen(n)))); + case NET_SADR_IP6: + if (ipa_is_ip4(a)) return 0; + return ip6_zero(ip6_and(ip6_xor(ipa_to_ip6(a), net6_prefix(n)), + ip6_mkmask(net6_pxlen(n)))); + case NET_MPLS: default: return 0; diff --git a/lib/net.h b/lib/net.h index 69f00641..5204e6b5 100644 --- a/lib/net.h +++ b/lib/net.h @@ -12,7 +12,6 @@ #include "lib/ip.h" - #define NET_IP4 1 #define NET_IP6 2 #define NET_VPN4 3 @@ -21,8 +20,9 @@ #define NET_ROA6 6 #define NET_FLOW4 7 #define NET_FLOW6 8 -#define NET_MPLS 9 -#define NET_MAX 10 +#define NET_SADR_IP6 9 +#define NET_MPLS 10 +#define NET_MAX 11 #define NB_IP4 (1 << NET_IP4) #define NB_IP6 (1 << NET_IP6) @@ -32,12 +32,13 @@ #define NB_ROA6 (1 << NET_ROA6) #define NB_FLOW4 (1 << NET_FLOW4) #define NB_FLOW6 (1 << NET_FLOW6) +#define NB_SADR_IP6 (1 << NET_SADR_IP6) #define NB_MPLS (1 << NET_MPLS) #define NB_IP (NB_IP4 | NB_IP6) #define NB_VPN (NB_VPN4 | NB_VPN6) #define NB_FLOW (NB_FLOW4 | NB_FLOW6) -#define NB_DEST (NB_IP | NB_VPN | NB_MPLS) +#define NB_DEST (NB_IP | NB_SADR_IP6 | NB_VPN | NB_MPLS) #define NB_ANY 0xffffffff @@ -121,6 +122,15 @@ typedef struct net_addr_mpls { u32 label; } net_addr_mpls; +typedef struct net_addr_sadr_ip6 { + u8 type; + u8 dst_pxlen; + u16 length; + ip6_addr dst_prefix; + u32 src_pxlen; // if u8, NET_ADDR_SADR_IP6 would leave non-zero padding + ip6_addr src_prefix; +} net_addr_sadr_ip6; + typedef union net_addr_union { net_addr n; net_addr_ip4 ip4; @@ -132,6 +142,7 @@ typedef union net_addr_union { net_addr_flow4 flow4; net_addr_flow6 flow6; net_addr_mpls mpls; + net_addr_sadr_ip6 sadr_ip6; } net_addr_union; @@ -170,6 +181,9 @@ extern const u16 net_max_text_length[]; #define NET_ADDR_MPLS(label) \ ((net_addr_mpls) { NET_MPLS, 20, sizeof(net_addr_mpls), label }) +#define NET_ADDR_SADR_IP6(dst_prefix,dst_pxlen,src_prefix,src_pxlen) \ + ((net_addr_sadr_ip6) { NET_SADR_IP6, dst_pxlen, sizeof(net_addr_sadr_ip6), dst_prefix, src_pxlen, src_prefix }) + static inline void net_fill_ip4(net_addr *a, ip4_addr prefix, uint pxlen) { *(net_addr_ip4 *)a = NET_ADDR_IP4(prefix, pxlen); } @@ -192,6 +206,9 @@ static inline void net_fill_roa6(net_addr *a, ip6_addr prefix, uint pxlen, uint static inline void net_fill_mpls(net_addr *a, u32 label) { *(net_addr_mpls *)a = NET_ADDR_MPLS(label); } +static inline void net_fill_sadr_ip6(net_addr *a, ip6_addr dst_prefix, uint dst_pxlen, ip6_addr src_prefix, uint src_pxlen) +{ *(net_addr_sadr_ip6 *)a = NET_ADDR_SADR_IP6(dst_prefix, dst_pxlen, src_prefix, src_pxlen); } + static inline void net_fill_ipa(net_addr *a, ip_addr prefix, uint pxlen) { if (ipa_is_ip4(prefix)) @@ -240,6 +257,15 @@ static inline int net_is_roa(const net_addr *a) static inline int net_is_flow(const net_addr *a) { return (a->type == NET_FLOW4) || (a->type == NET_FLOW6); } +static inline int net_is_sadr(const net_addr *a) +{ return (a->type == NET_SADR_IP6); } + +static inline int net_is_sadr_set(const net_addr *a) +{ + net_addr_sadr_ip6 *sa = (void *) a; + return (a->type == NET_SADR_IP6 && sa->src_pxlen > 0); +} + static inline ip4_addr net4_prefix(const net_addr *a) { return ((net_addr_ip4 *) a)->prefix; } @@ -261,6 +287,7 @@ static inline ip_addr net_prefix(const net_addr *a) case NET_VPN6: case NET_ROA6: case NET_FLOW6: + case NET_SADR_IP6: return ipa_from_ip6(net6_prefix(a)); case NET_MPLS: @@ -331,6 +358,13 @@ static inline int net_equal_flow6(const net_addr_flow6 *a, const net_addr_flow6 static inline int net_equal_mpls(const net_addr_mpls *a, const net_addr_mpls *b) { return !memcmp(a, b, sizeof(net_addr_mpls)); } +typedef net_addr_ip6 net_addr_sadr_dst; +static inline int net_equal_sadr_dst(const net_addr_ip6 *a, const net_addr_ip6 *b) +{ return net_equal_ip6(a, b); } + +static inline int net_equal_sadr_ip6(const net_addr_sadr_ip6 *a, const net_addr_sadr_ip6 *b) +{ return !memcmp(a, b, sizeof(net_addr_sadr_ip6)); } + static inline int net_equal_prefix_roa4(const net_addr_roa4 *a, const net_addr_roa4 *b) { return ip4_equal(a->prefix, b->prefix) && (a->pxlen == b->pxlen); } @@ -394,6 +428,8 @@ static inline int net_compare_flow6(const net_addr_flow6 *a, const net_addr_flow static inline int net_compare_mpls(const net_addr_mpls *a, const net_addr_mpls *b) { return uint_cmp(a->label, b->label); } +int net_compare_sadr_ip6(const net_addr_sadr_ip6 *a, const net_addr_sadr_ip6 *b); + int net_compare(const net_addr *a, const net_addr *b); @@ -427,6 +463,9 @@ static inline void net_copy_flow6(net_addr_flow6 *dst, const net_addr_flow6 *src static inline void net_copy_mpls(net_addr_mpls *dst, const net_addr_mpls *src) { memcpy(dst, src, sizeof(net_addr_mpls)); } +static inline void net_copy_sadr_ip6(net_addr_sadr_ip6 *dst, const net_addr_sadr_ip6 *src) +{ memcpy(dst, src, sizeof(net_addr_sadr_ip6)); } + /* XXXX */ static inline u32 u64_hash(u64 a) @@ -438,6 +477,9 @@ static inline u32 net_hash_ip4(const net_addr_ip4 *n) static inline u32 net_hash_ip6(const net_addr_ip6 *n) { return ip6_hash(n->prefix) ^ ((u32) n->pxlen << 26); } +static inline u32 net_hash_sadr_ip6(const net_addr_sadr_ip6 *n) +{ return net_hash_ip6((net_addr_ip6 *)n); } + static inline u32 net_hash_vpn4(const net_addr_vpn4 *n) { return ip4_hash(n->prefix) ^ ((u32) n->pxlen << 26) ^ u64_hash(n->rd); } @@ -508,6 +550,9 @@ static inline int net_validate_flow6(const net_addr_flow6 *n) static inline int net_validate_mpls(const net_addr_mpls *n) { return n->label < (1 << 20); } +static inline int net_validate_sadr_ip6(const net_addr_sadr_ip6 *n) +{ return net_validate_px6(n->dst_prefix, n->dst_pxlen) && net_validate_px6(n->src_prefix, n->src_pxlen); } + int net_validate(const net_addr *N); @@ -523,6 +568,10 @@ static inline void net_normalize_vpn4(net_addr_vpn4 *n) static inline void net_normalize_vpn6(net_addr_vpn6 *n) { net_normalize_ip6((net_addr_ip6 *) n); } +static inline void net_normalize_sadr_ip6(net_addr_sadr_ip6 *n) +{ n->dst_prefix = ip6_and(n->dst_prefix, ip6_mkmask(n->dst_pxlen)); + n->src_prefix = ip6_and(n->src_prefix, ip6_mkmask(n->src_pxlen)); } + void net_normalize(net_addr *N); diff --git a/nest/config.Y b/nest/config.Y index 044aba2b..e8cb26e4 100644 --- a/nest/config.Y +++ b/nest/config.Y @@ -77,7 +77,7 @@ CF_KEYWORDS(TIMEFORMAT, ISO, SHORT, LONG, ROUTE, PROTOCOL, BASE, LOG, S, MS, US) CF_KEYWORDS(GRACEFUL, RESTART, WAIT, MAX, FLUSH, AS) /* For r_args_channel */ -CF_KEYWORDS(IPV4, IPV4_MC, IPV4_MPLS, IPV6, IPV6_MC, IPV6_MPLS, VPN4, VPN4_MC, VPN4_MPLS, VPN6, VPN6_MC, VPN6_MPLS, ROA4, ROA6, FLOW4, FLOW6, MPLS, PRI, SEC) +CF_KEYWORDS(IPV4, IPV4_MC, IPV4_MPLS, IPV6, IPV6_MC, IPV6_MPLS, SADR, VPN4, VPN4_MC, VPN4_MPLS, VPN6, VPN6_MC, VPN6_MPLS, ROA4, ROA6, FLOW4, FLOW6, MPLS, PRI, SEC) CF_ENUM(T_ENUM_RTS, RTS_, DUMMY, STATIC, INHERIT, DEVICE, STATIC_DEVICE, REDIRECT, RIP, OSPF, OSPF_IA, OSPF_EXT1, OSPF_EXT2, BGP, PIPE, BABEL) @@ -134,6 +134,7 @@ gr_opts: GRACEFUL RESTART WAIT expr ';' { new_config->gr_wait = $4; } ; net_type: IPV4 { $$ = NET_IP4; } | IPV6 { $$ = NET_IP6; } + | IPV6 SADR { $$ = NET_SADR_IP6; } | VPN4 { $$ = NET_VPN4; } | VPN6 { $$ = NET_VPN6; } | ROA4 { $$ = NET_ROA4; } @@ -143,7 +144,7 @@ net_type: | MPLS { $$ = NET_MPLS; } ; -CF_ENUM(T_ENUM_NETTYPE, NET_, IP4, IP6, VPN4, VPN6, ROA4, ROA6, FLOW4, FLOW6) +CF_ENUM(T_ENUM_NETTYPE, NET_, IP4, IP6, VPN4, VPN6, ROA4, ROA6, FLOW4, FLOW6, SADR_IP6) /* Creation of routing tables */ diff --git a/nest/rt-fib.c b/nest/rt-fib.c index c09f2759..1046350d 100644 --- a/nest/rt-fib.c +++ b/nest/rt-fib.c @@ -236,6 +236,7 @@ fib_find(struct fib *f, const net_addr *a) case NET_ROA6: return FIB_FIND(f, a, roa6); case NET_FLOW4: return FIB_FIND(f, a, flow4); case NET_FLOW6: return FIB_FIND(f, a, flow6); + case NET_SADR_IP6: return FIB_FIND(f, a, sadr_ip6); case NET_MPLS: return FIB_FIND(f, a, mpls); default: bug("invalid type"); } @@ -256,6 +257,7 @@ fib_insert(struct fib *f, const net_addr *a, struct fib_node *e) case NET_ROA6: FIB_INSERT(f, a, e, roa6); return; case NET_FLOW4: FIB_INSERT(f, a, e, flow4); return; case NET_FLOW6: FIB_INSERT(f, a, e, flow6); return; + case NET_SADR_IP6: FIB_INSERT(f, a, e, sadr_ip6); return; case NET_MPLS: FIB_INSERT(f, a, e, mpls); return; default: bug("invalid type"); } diff --git a/nest/rt-table.c b/nest/rt-table.c index 4640d6a9..c88dffef 100644 --- a/nest/rt-table.c +++ b/nest/rt-table.c @@ -85,6 +85,42 @@ net_route_ip6(rtable *t, net_addr_ip6 *n) return r; } +static inline void * +net_route_sadr_ip6(rtable *t, net_addr_sadr_ip6 *n) +{ + net *r; + + net_addr_ip6 dst = NET_ADDR_IP6(n->dst_prefix, n->dst_pxlen); + dst.type = NET_SADR_IP6; + + // search for matching dst + while (r = net_route_ip6(t, &dst)) + { + /* FIXME: Is this right? */ + net_addr_ip6 *n6 = (net_addr_ip6 *) r->n.addr; + dst.pxlen = n6->pxlen; + + // found a matching dst, start search for entries that match both prefixes + net_addr_sadr_ip6 full_addr = + NET_ADDR_SADR_IP6(dst.prefix, dst.pxlen, n->src_prefix, n->src_pxlen); + + while (r = net_find_valid(t, (net_addr *) &full_addr), (!r) && (full_addr.src_pxlen > 0)) + { + full_addr.src_pxlen--; + ip6_clrbit(&full_addr.src_prefix, full_addr.src_pxlen); + } + + if (r) + return r; + + if (!dst.pxlen) + break; + dst.pxlen--; + } + + return NULL; +} + void * net_route(rtable *tab, const net_addr *n) { @@ -105,6 +141,9 @@ net_route(rtable *tab, const net_addr *n) case NET_ROA6: return net_route_ip6(tab, (net_addr_ip6 *) n0); + case NET_SADR_IP6: + return net_route_sadr_ip6(tab, (net_addr_sadr_ip6 *) n0); + default: return NULL; } @@ -614,9 +653,9 @@ rt_notify_accepted(struct channel *c, net *net, rte *new_changed, rte *old_chang old_meet = 1; } - /* + /* * Second, handle the feed case. That means we do not care for - * old_best. It is NULL for feed, and the new_best for refeed. + * old_best. It is NULL for feed, and the new_best for refeed. * For refeed, there is a hack similar to one in rt_notify_basic() * to ensure withdraws in case of changed filters */ @@ -1387,7 +1426,7 @@ rte_update2(struct channel *c, const net_addr *n, rte *new, struct rte_src *src) /* Independent call to rte_announce(), used from next hop recalculation, outside of rte_update(). new must be non-NULL */ -static inline void +static inline void rte_announce_i(rtable *tab, unsigned type, net *net, rte *new, rte *old, rte *new_best, rte *old_best) { @@ -1604,7 +1643,7 @@ rt_setup(pool *p, rtable *t, char *name, struct rtable_config *cf) bzero(t, sizeof(*t)); t->name = name; t->config = cf; - t->addr_type = cf ? cf->addr_type : NET_IP4; + t->addr_type = cf ? cf->addr_type : NET_SADR_IP6; /* FIXME */ fib_init(&t->fib, p, t->addr_type, sizeof(net), OFFSETOF(net, n), 0, NULL); init_list(&t->channels); @@ -2360,7 +2399,7 @@ if_local_addr(ip_addr a, struct iface *i) return 0; } -static u32 +static u32 rt_get_igp_metric(rte *rt) { eattr *ea = ea_find(rt->attrs->eattrs, EA_GEN_IGP_METRIC); diff --git a/sysdep/linux/netlink.c b/sysdep/linux/netlink.c index 4cb51519..e59b4910 100644 --- a/sysdep/linux/netlink.c +++ b/sysdep/linux/netlink.c @@ -374,6 +374,7 @@ static struct nl_want_attrs rtm_attr_want4[BIRD_RTA_MAX] = { static struct nl_want_attrs rtm_attr_want6[BIRD_RTA_MAX] = { [RTA_DST] = { 1, 1, sizeof(ip6_addr) }, + [RTA_SRC] = { 1, 1, sizeof(ip6_addr) }, [RTA_IIF] = { 1, 1, sizeof(u32) }, [RTA_OIF] = { 1, 1, sizeof(u32) }, [RTA_GATEWAY] = { 1, 1, sizeof(ip6_addr) }, @@ -1221,7 +1222,16 @@ nl_send_route(struct krt_proto *p, rte *e, struct ea_list *eattrs, int op, int d } else #endif + { nl_add_attr_ipa(&r->h, rsize, RTA_DST, net_prefix(net->n.addr)); + // add source address for SADR routes + if (net->n.addr->type == NET_SADR_IP6) + { + net_addr_sadr_ip6 *sadr_addr = (void *) &net->n.addr; + r->r.rtm_src_len = sadr_addr->src_pxlen; + nl_add_attr_ipa(&r->h, rsize, RTA_SRC, sadr_addr->src_prefix); + } + } /* * Strange behavior for RTM_DELROUTE: @@ -1447,7 +1457,8 @@ nl_parse_route(struct nl_parse_state *s, struct nlmsghdr *h) struct rtattr *a[BIRD_RTA_MAX]; int new = h->nlmsg_type == RTM_NEWROUTE; - net_addr dst; + net_addr dst, sadr_src; + net_fill_ip6(&sadr_src, IP6_NONE, 0); u32 oif = ~0; u32 table_id; u32 priority = 0; @@ -1473,6 +1484,9 @@ nl_parse_route(struct nl_parse_state *s, struct nlmsghdr *h) if (!nl_parse_attrs(RTM_RTA(i), rtm_attr_want6, a, sizeof(a))) return; + if (a[RTA_SRC]) + net_fill_ip6(&sadr_src, rta_get_ip6(a[RTA_SRC]), i->rtm_src_len); + if (a[RTA_DST]) net_fill_ip6(&dst, rta_get_ip6(a[RTA_DST]), i->rtm_dst_len); else @@ -1551,7 +1565,20 @@ nl_parse_route(struct nl_parse_state *s, struct nlmsghdr *h) src = KRT_SRC_ALIEN; } - net *net = net_get(p->p.main_channel->table, &dst); + net *net; + if (p->p.main_channel->table->addr_type == NET_SADR_IP6) + { + net_addr_sadr_ip6 sadr_addr = + NET_ADDR_SADR_IP6(net_prefix(&dst), net_pxlen(&dst), + net_prefix(&sadr_src), net_pxlen(&sadr_src)); + net = net_get(p->p.main_channel->table, (net_addr *)&sadr_addr); + } + else + { + if (a[RTA_SRC]) + SKIP("sadr prefix for non-sadr channel\n"); + net = net_get(p->p.main_channel->table, &dst); + } if (s->net && !nl_mergable_route(s, net, p, priority, i->rtm_type)) nl_announce_route(s); diff --git a/sysdep/unix/krt.c b/sysdep/unix/krt.c index e7bd79e3..7166bbec 100644 --- a/sysdep/unix/krt.c +++ b/sysdep/unix/krt.c @@ -1103,7 +1103,9 @@ krt_start(struct proto *P) switch (p->p.net_type) { case NET_IP4: p->af = AF_INET; break; - case NET_IP6: p->af = AF_INET6; break; + case NET_IP6: + case NET_SADR_IP6: + p->af = AF_INET6; break; #ifdef AF_MPLS case NET_MPLS: p->af = AF_MPLS; break; #endif @@ -1219,9 +1221,9 @@ struct protocol proto_unix_kernel = { .attr_class = EAP_KRT, .preference = DEF_PREF_INHERITED, #ifdef HAVE_MPLS_KERNEL - .channel_mask = NB_IP | NB_MPLS, + .channel_mask = NB_IP | NB_SADR_IP6 | NB_MPLS, #else - .channel_mask = NB_IP, + .channel_mask = NB_IP | NB_SADR_IP6, #endif .proto_size = sizeof(struct krt_proto), .config_size = sizeof(struct krt_config), -- 2.16.1
Toke Høiland-Jørgensen <toke@toke.dk> writes:
This adds support for source-specific IPv6 routes to Bird core. This is based on Dean Luga's original patch, with the review comments addressed. Sadr support is added to network address parsing in confbase.Y and to the kernel protocol on Linux.
A couple of issues remain with this patch:
- Had to change the default addr_type in rt_setup() to NET_SADR_IP6 to get the kernel 'learn' mechanism to work.
- Not sure if the logic in net_route_sadr_ip6() is right.
- The config parser barfs on sadr route literals in the static protocol with an "Integer expression expected" error message.
- There's no way to mix source-specific and non-source-specific routes (i.e., sadr tables cannot be connected to non-sadr tables).
BTW, I'm sending this with these issues unresolved because I'm hoping to get some feedback on how best to resolve them; just in case that wasn't clear... ;) -Toke
On Sat, Feb 03, 2018 at 09:40:56PM +0100, Toke Høiland-Jørgensen wrote:
This adds support for source-specific IPv6 routes to Bird core. This is based on Dean Luga's original patch, with the review comments addressed. Sadr support is added to network address parsing in confbase.Y and to the kernel protocol on Linux.
Hi Thanks, i will look at it in details later.
A couple of issues remain with this patch:
- Had to change the default addr_type in rt_setup() to NET_SADR_IP6 to get the kernel 'learn' mechanism to work.
This seems like a bug in 'learn' in 2.0.x, i will fix that.
- Not sure if the logic in net_route_sadr_ip6() is right.
First, it should have a comment about what is the expected behavior, whether it should be longest-dst-then-src or longest-src-then-dst, or some other behavior. I would expect it to be consistent with Linux kernel, but i am not sure what is used there. The code mixes net_addr_ip6 and net_addr_sadr_ip6 during lookups, which likely trigger asserts in fib_find?
- The config parser barfs on sadr route literals in the static protocol with an "Integer expression expected" error message.
Perhaps it created more Bison grammar conflicts? I will check that later.
- There's no way to mix source-specific and non-source-specific routes (i.e., sadr tables cannot be connected to non-sadr tables).
This is OK for now. -- Elen sila lumenn' omentielvo Ondrej 'Santiago' Zajicek (email: santiago@crfreenet.org) OpenPGP encrypted e-mails preferred (KeyID 0x11DEADC3, wwwkeys.pgp.net) "To err is human -- to blame it on a computer is even more so."
On Sat, Feb 03, 2018 at 09:40:56PM +0100, Toke Høiland-Jørgensen wrote:
This adds support for source-specific IPv6 routes to Bird core. This is based on Dean Luga's original patch, with the review comments addressed. Sadr support is added to network address parsing in confbase.Y and to the kernel protocol on Linux.
First, some general comments: Put sadr_ip6 variant consistently above mpls variant. There are several places where it is in reverse. If you do not object, i would much prefer *_ip6_sadr than *_sadr_ip6 (also in uppercase variants). It will also be consistent with user visible channel and table keywords for this type.
-%type <net> net_ip4_ net_ip6_ net_ip6 net_ip_ net_ip net_or_ipa +%type <net> net_ip4_ net_ip6_ net_sadr_ip6_ net_ip6 net_ip_ net_ip net_or_ipa %type <net_ptr> net_ net_any net_vpn4_ net_vpn6_ net_vpn_ net_roa4_ net_roa6_ net_roa_ net_mpls_
net_sadr_ip6_ should be in <net_ptr> instead of <net>, as net_addr_sadr_ip6 is longer than net_addr, so must be passed as pointer. That fixes the "Integer expression expected" issue.
%type <mls> label_stack_start label_stack
@@ -96,7 +96,7 @@ CF_DECLS %left '!' %nonassoc '.'
-CF_KEYWORDS(DEFINE, ON, OFF, YES, NO, S, MS, US, PORT, VPN, MPLS) +CF_KEYWORDS(DEFINE, ON, OFF, YES, NO, S, MS, US, PORT, VPN, MPLS, FROM)
CF_GRAMMAR
@@ -206,6 +206,22 @@ net_ip6_: IP6 '/' NUM n->prefix, n->pxlen, ip6_and(n->prefix, ip6_mkmask(n->pxlen)), n->pxlen); };
+net_sadr_ip6_: IP6 '/' NUM FROM IP6 '/' NUM +{ + if ($3 > IP6_MAX_PREFIX_LENGTH) + cf_error("Invalid prefix length %u", $3); + + if ($7 > IP6_MAX_PREFIX_LENGTH) + cf_error("Invalid prefix length %u", $7); + + net_fill_sadr_ip6(&($$), $1, $3, $5, $7); + + net_addr_sadr_ip6 *n = (void *) &($$);
W.r.t. the change from <net> to <net_ptr> it should be: $$ = cfg_alloc(sizeof(net_addr_sadr_ip6)); net_fill_sadr_ip6($$, $1, $3, $5, $7); net_addr_sadr_ip6 *n = (void *) $$;
-net_ip_: net_ip4_ | net_ip6_ ; +net_ip_: net_ip4_ | net_ip6_ | net_sadr_ip6_;
Here net_sadr_ip6_ should be separate
net_vpn_: net_vpn4_ | net_vpn6_ ; net_roa_: net_roa4_ | net_roa6_ ;
diff --git a/lib/net.c b/lib/net.c index 9335b78f..a2dad51d 100644 --- a/lib/net.c +++ b/lib/net.c @@ -14,6 +14,7 @@ const char * const net_label[] = { [NET_ROA6] = "roa6", [NET_FLOW4] = "flow4", [NET_FLOW6] = "flow6", + [NET_SADR_IP6] = "sadr6",
"ipv4 sadr" to be consistent with table keywords?
+typedef struct net_addr_sadr_ip6 { + u8 type; + u8 dst_pxlen; + u16 length; + ip6_addr dst_prefix; + u32 src_pxlen; // if u8, NET_ADDR_SADR_IP6 would leave non-zero padding
Perhaps we should use s32 so it is promoted to same type as u8?
+int +net_compare_sadr_ip6(const net_addr_sadr_ip6 *a, const net_addr_sadr_ip6 *b) +{ + int dst_cmp = ip6_compare(a->dst_prefix, b->dst_prefix) ?: uint_cmp(a->dst_pxlen, b->dst_pxlen); + if (dst_cmp) + return dst_cmp; + else + return ip6_compare(a->src_prefix, b->src_prefix) ?: uint_cmp(a->src_pxlen, b->src_pxlen); +}
Seems too complicated. Perhaps just: { return ip6_compare(a->dst_prefix, b->dst_prefix) ?: uint_cmp(a->dst_pxlen, b->dst_pxlen) ?: ip6_compare(a->src_prefix, b->src_prefix) ?: uint_cmp(a->src_pxlen, b->src_pxlen); }
+static inline void * +net_route_sadr_ip6(rtable *t, net_addr_sadr_ip6 *n)
IMHO proper way how to implement this is like net_roa_check_ip6() is done. As nets are hashed by dst, you can use fib_get_chain() to get hash chain, walk through it and find the best matching src from nodes with the exact dst of the current iteration, and decrease dst_pxlen in further iterations if no match. Also note that in order to net_route is used in 'show route for', you should add net_sadr_ip6_ to r_args_for grammar in nest/config.Y
--- a/sysdep/unix/krt.c +++ b/sysdep/unix/krt.c @@ -1103,7 +1103,9 @@ krt_start(struct proto *P) switch (p->p.net_type) { case NET_IP4: p->af = AF_INET; break; - case NET_IP6: p->af = AF_INET6; break; + case NET_IP6: + case NET_SADR_IP6: + p->af = AF_INET6; break; #ifdef AF_MPLS case NET_MPLS: p->af = AF_MPLS; break; #endif @@ -1219,9 +1221,9 @@ struct protocol proto_unix_kernel = { .attr_class = EAP_KRT, .preference = DEF_PREF_INHERITED, #ifdef HAVE_MPLS_KERNEL - .channel_mask = NB_IP | NB_MPLS, + .channel_mask = NB_IP | NB_SADR_IP6 | NB_MPLS, #else - .channel_mask = NB_IP, + .channel_mask = NB_IP | NB_SADR_IP6, #endif
SADR is not supported in BSD, channel_mask should reflect mask. There should be define for CONFIG_SADR_IP6_KERNEL in sysdef/cf/linux.h, and then in sysdep/unix/krt.c: #ifdef CONFIG_SADR_IP6_KERNEL #define MAYBE_SADR_IP6 NB_SADR_IP #else #define MAYBE_SADR_IP6 0 #endif #ifdef HAVE_MPLS_KERNEL #define MAYBE_MPLS NB_MPLS #else #define MAYBE_MPLS 0 #endif struct protocol proto_unix_kernel = { ... .channel_mask = NB_IP | MAYBE_SADR_IP6 | MAYBE_MPLS ... }; -- Elen sila lumenn' omentielvo Ondrej 'Santiago' Zajicek (email: santiago@crfreenet.org) OpenPGP encrypted e-mails preferred (KeyID 0x11DEADC3, wwwkeys.pgp.net) "To err is human -- to blame it on a computer is even more so."
On Mon, Feb 05, 2018 at 03:08:51PM +0100, Ondrej Zajicek wrote:
"ipv4 sadr" to be consistent with table keywords?
Should be "ipv6 sadr" instead of "ipv4 sadr". -- Elen sila lumenn' omentielvo Ondrej 'Santiago' Zajicek (email: santiago@crfreenet.org) OpenPGP encrypted e-mails preferred (KeyID 0x11DEADC3, wwwkeys.pgp.net) "To err is human -- to blame it on a computer is even more so."
Ondrej Zajicek <santiago@crfreenet.org> writes:
On Sat, Feb 03, 2018 at 09:40:56PM +0100, Toke Høiland-Jørgensen wrote:
This adds support for source-specific IPv6 routes to Bird core. This is based on Dean Luga's original patch, with the review comments addressed. Sadr support is added to network address parsing in confbase.Y and to the kernel protocol on Linux.
First, some general comments:
Put sadr_ip6 variant consistently above mpls variant. There are several places where it is in reverse.
Sure; fixed a couple of those, but guess I missed some.
If you do not object, i would much prefer *_ip6_sadr than *_sadr_ip6 (also in uppercase variants). It will also be consistent with user visible channel and table keywords for this type.
Fine with me. Actually thought about changing this already, but then I was too lazy ;) Will fix and resubmit. What about the issue with 'learn'? :) -Toke
On Mon, Feb 05, 2018 at 03:33:25PM +0100, Toke Høiland-Jørgensen wrote:
Will fix and resubmit. What about the issue with 'learn'? :)
Fixed in 28b3b551222ab58456a067a9be4790824cdbb60e -- Elen sila lumenn' omentielvo Ondrej 'Santiago' Zajicek (email: santiago@crfreenet.org) OpenPGP encrypted e-mails preferred (KeyID 0x11DEADC3, wwwkeys.pgp.net) "To err is human -- to blame it on a computer is even more so."
Ondrej Zajicek <santiago@crfreenet.org> writes:
On Mon, Feb 05, 2018 at 03:33:25PM +0100, Toke Høiland-Jørgensen wrote:
Will fix and resubmit. What about the issue with 'learn'? :)
Fixed in 28b3b551222ab58456a067a9be4790824cdbb60e
Great, thanks! Do you want me to submit a new version of the patch series with that part removed, or are you OK with just dropping it when you merge? Assuming you don't have any more issues you want me to fix, of course ;) -Toke
On Tue, Feb 06, 2018 at 04:28:43PM +0100, Toke Høiland-Jørgensen wrote:
Ondrej Zajicek <santiago@crfreenet.org> writes:
On Mon, Feb 05, 2018 at 03:33:25PM +0100, Toke Høiland-Jørgensen wrote:
Will fix and resubmit. What about the issue with 'learn'? :)
Fixed in 28b3b551222ab58456a067a9be4790824cdbb60e
Great, thanks!
Do you want me to submit a new version of the patch series with that part removed, or are you OK with just dropping it when you merge? Assuming you don't have any more issues you want me to fix, of course ;)
Hi I will merge 1/2 as sent earlier. I did not check 2/2 yet, but i think it should support both regular ipv6 and ipv6 SADR channels/tables, not just the SADR ones. -- Elen sila lumenn' omentielvo Ondrej 'Santiago' Zajicek (email: santiago@crfreenet.org) OpenPGP encrypted e-mails preferred (KeyID 0x11DEADC3, wwwkeys.pgp.net) "To err is human -- to blame it on a computer is even more so."
Ondrej Zajicek <santiago@crfreenet.org> writes:
On Tue, Feb 06, 2018 at 04:28:43PM +0100, Toke Høiland-Jørgensen wrote:
Ondrej Zajicek <santiago@crfreenet.org> writes:
On Mon, Feb 05, 2018 at 03:33:25PM +0100, Toke Høiland-Jørgensen wrote:
Will fix and resubmit. What about the issue with 'learn'? :)
Fixed in 28b3b551222ab58456a067a9be4790824cdbb60e
Great, thanks!
Do you want me to submit a new version of the patch series with that part removed, or are you OK with just dropping it when you merge? Assuming you don't have any more issues you want me to fix, of course ;)
Hi
I will merge 1/2 as sent earlier.
Cool.
I did not check 2/2 yet, but i think it should support both regular ipv6 and ipv6 SADR channels/tables, not just the SADR ones.
Hmm, well, my assumption was that since sadr tables can hold normal ipv6 routes as well, the pipe hack you were talking about would be sufficient to support both? -Toke
On Tue, Feb 06, 2018 at 04:38:59PM +0100, Toke Høiland-Jørgensen wrote:
I did not check 2/2 yet, but i think it should support both regular ipv6 and ipv6 SADR channels/tables, not just the SADR ones.
Hmm, well, my assumption was that since sadr tables can hold normal ipv6 routes as well, the pipe hack you were talking about would be sufficient to support both?
It could, but that would be cumbersome for users that just want regular routes. The pipe hack is more for setups that integrate SADR routes from Babel with other (non-SADR) protocols. Simple setups should keep simple configs. -- Elen sila lumenn' omentielvo Ondrej 'Santiago' Zajicek (email: santiago@crfreenet.org) OpenPGP encrypted e-mails preferred (KeyID 0x11DEADC3, wwwkeys.pgp.net) "To err is human -- to blame it on a computer is even more so."
Ondrej Zajicek <santiago@crfreenet.org> writes:
On Tue, Feb 06, 2018 at 04:38:59PM +0100, Toke Høiland-Jørgensen wrote:
I did not check 2/2 yet, but i think it should support both regular ipv6 and ipv6 SADR channels/tables, not just the SADR ones.
Hmm, well, my assumption was that since sadr tables can hold normal ipv6 routes as well, the pipe hack you were talking about would be sufficient to support both?
It could, but that would be cumbersome for users that just want regular routes. The pipe hack is more for setups that integrate SADR routes from Babel with other (non-SADR) protocols. Simple setups should keep simple configs.
What, we have to be nice to the users now? ;) Fair enough, I'll add support for both types of channels. Should it be possible to connect the same instance to both an ipv6 and and ipv6_sadr channel type, or is it OK to enforce that there's only one of those active? -Toke
On Tue, Feb 06, 2018 at 04:57:43PM +0100, Toke Høiland-Jørgensen wrote:
What, we have to be nice to the users now? ;)
Fair enough, I'll add support for both types of channels. Should it be possible to connect the same instance to both an ipv6 and and ipv6_sadr channel type, or is it OK to enforce that there's only one of those active?
It is OK to enforce that there is only one of those active. How non-SADR-aware Babel should handle SADR routes? Is it mandatory sub-TLV, so they are ignored; or optional sub-TLV, so they are handled as regular routes? -- Elen sila lumenn' omentielvo Ondrej 'Santiago' Zajicek (email: santiago@crfreenet.org) OpenPGP encrypted e-mails preferred (KeyID 0x11DEADC3, wwwkeys.pgp.net) "To err is human -- to blame it on a computer is even more so."
Ondrej Zajicek <santiago@crfreenet.org> writes:
On Tue, Feb 06, 2018 at 04:57:43PM +0100, Toke Høiland-Jørgensen wrote:
What, we have to be nice to the users now? ;)
Fair enough, I'll add support for both types of channels. Should it be possible to connect the same instance to both an ipv6 and and ipv6_sadr channel type, or is it OK to enforce that there's only one of those active?
It is OK to enforce that there is only one of those active. How non-SADR-aware Babel should handle SADR routes? Is it mandatory sub-TLV, so they are ignored; or optional sub-TLV, so they are handled as regular routes?
It's mandatory, otherwise you can get routing loops. See https://tools.ietf.org/html/draft-ietf-babel-source-specific-03#section-6 I figure the packet parser needs to be aware of whether it is configured to support SADR routes and drop all source-specific updates if not... -Toke
On Tue, Feb 06, 2018 at 05:20:25PM +0100, Toke Høiland-Jørgensen wrote:
It's mandatory, otherwise you can get routing loops. See https://tools.ietf.org/html/draft-ietf-babel-source-specific-03#section-6
I figure the packet parser needs to be aware of whether it is configured to support SADR routes and drop all source-specific updates if not...
OK, so there is no need to have separate option, it could be handled just by which channel type is defined. -- Elen sila lumenn' omentielvo Ondrej 'Santiago' Zajicek (email: santiago@crfreenet.org) OpenPGP encrypted e-mails preferred (KeyID 0x11DEADC3, wwwkeys.pgp.net) "To err is human -- to blame it on a computer is even more so."
Ondrej Zajicek <santiago@crfreenet.org> writes:
On Tue, Feb 06, 2018 at 05:20:25PM +0100, Toke Høiland-Jørgensen wrote:
It's mandatory, otherwise you can get routing loops. See https://tools.ietf.org/html/draft-ietf-babel-source-specific-03#section-6
I figure the packet parser needs to be aware of whether it is configured to support SADR routes and drop all source-specific updates if not...
OK, so there is no need to have separate option, it could be handled just by which channel type is defined.
Yeah, that was my thought. Will add that :) -Toke
This adds support for source-specific IPv6 routes to Bird core. This is based on Dean Luga's original patch, with the review comments addressed. Sadr support is added to network address parsing in confbase.Y and to the kernel protocol on Linux. A couple of issues remain with this patch: - Had to change the default addr_type in rt_setup() to NET_SADR_IP6 to get the kernel 'learn' mechanism to work. - There's no way to mix source-specific and non-source-specific routes (i.e., sadr tables cannot be connected to non-sadr tables). Signed-off-by: Toke Høiland-Jørgensen <toke@toke.dk> --- conf/confbase.Y | 24 +++++++++++++++++-- lib/net.c | 24 +++++++++++++++++++ lib/net.h | 62 ++++++++++++++++++++++++++++++++++++++++++++++---- nest/config.Y | 6 +++-- nest/rt-fib.c | 2 ++ nest/rt-table.c | 45 +++++++++++++++++++++++++++++++++++- sysdep/cf/linux.h | 1 + sysdep/linux/netlink.c | 31 +++++++++++++++++++++++-- sysdep/unix/krt.c | 22 +++++++++++++----- 9 files changed, 200 insertions(+), 17 deletions(-) diff --git a/conf/confbase.Y b/conf/confbase.Y index 7e0537c5..c2d647eb 100644 --- a/conf/confbase.Y +++ b/conf/confbase.Y @@ -83,7 +83,7 @@ CF_DECLS %type <time> expr_us time %type <a> ipa %type <net> net_ip4_ net_ip6_ net_ip6 net_ip_ net_ip net_or_ipa -%type <net_ptr> net_ net_any net_vpn4_ net_vpn6_ net_vpn_ net_roa4_ net_roa6_ net_roa_ net_mpls_ +%type <net_ptr> net_ net_any net_vpn4_ net_vpn6_ net_vpn_ net_roa4_ net_roa6_ net_roa_ net_ip6_sadr_ net_mpls_ %type <mls> label_stack_start label_stack %type <t> text opttext @@ -96,7 +96,7 @@ CF_DECLS %left '!' %nonassoc '.' -CF_KEYWORDS(DEFINE, ON, OFF, YES, NO, S, MS, US, PORT, VPN, MPLS) +CF_KEYWORDS(DEFINE, ON, OFF, YES, NO, S, MS, US, PORT, VPN, MPLS, FROM) CF_GRAMMAR @@ -206,6 +206,25 @@ net_ip6_: IP6 '/' NUM n->prefix, n->pxlen, ip6_and(n->prefix, ip6_mkmask(n->pxlen)), n->pxlen); }; +net_ip6_sadr_: IP6 '/' NUM FROM IP6 '/' NUM +{ + if ($3 > IP6_MAX_PREFIX_LENGTH) + cf_error("Invalid prefix length %u", $3); + + if ($7 > IP6_MAX_PREFIX_LENGTH) + cf_error("Invalid prefix length %u", $7); + + $$ = cfg_alloc(sizeof(net_addr_ip6_sadr)); + net_fill_ip6_sadr($$, $1, $3, $5, $7); + + net_addr_ip6_sadr *n = (void *) $$; + if (!net_validate_ip6_sadr(n)) + cf_error("Invalid SADR IPv6 prefix %I6/%d from %I6/%d, maybe you wanted %I6/%d from %I6/%d", + n->dst_prefix, n->dst_pxlen, n->src_prefix, n->src_pxlen, + ip6_and(n->dst_prefix, ip6_mkmask(n->dst_pxlen)), n->dst_pxlen, + ip6_and(n->src_prefix, ip6_mkmask(n->src_pxlen)), n->src_pxlen); +}; + net_vpn4_: VPN_RD net_ip4_ { $$ = cfg_alloc(sizeof(net_addr_vpn4)); @@ -249,6 +268,7 @@ net_: | net_vpn_ | net_roa_ | net_flow_ + | net_ip6_sadr_ | net_mpls_ ; diff --git a/lib/net.c b/lib/net.c index 9335b78f..61f2d554 100644 --- a/lib/net.c +++ b/lib/net.c @@ -14,6 +14,7 @@ const char * const net_label[] = { [NET_ROA6] = "roa6", [NET_FLOW4] = "flow4", [NET_FLOW6] = "flow6", + [NET_IP6_SADR]= "ipv6 sadr6", [NET_MPLS] = "mpls", }; @@ -26,6 +27,7 @@ const u16 net_addr_length[] = { [NET_ROA6] = sizeof(net_addr_roa6), [NET_FLOW4] = 0, [NET_FLOW6] = 0, + [NET_IP6_SADR]= sizeof(net_addr_ip6_sadr), [NET_MPLS] = sizeof(net_addr_mpls), }; @@ -38,6 +40,7 @@ const u8 net_max_prefix_length[] = { [NET_ROA6] = IP6_MAX_PREFIX_LENGTH, [NET_FLOW4] = IP4_MAX_PREFIX_LENGTH, [NET_FLOW6] = IP6_MAX_PREFIX_LENGTH, + [NET_IP6_SADR]= IP6_MAX_PREFIX_LENGTH, [NET_MPLS] = 0, }; @@ -50,6 +53,7 @@ const u16 net_max_text_length[] = { [NET_ROA6] = 60, /* "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff/128-128 AS4294967295" */ [NET_FLOW4] = 0, /* "flow4 { ... }" */ [NET_FLOW6] = 0, /* "flow6 { ... }" */ + [NET_IP6_SADR]= 92, /* "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff/128 from ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff/128" */ [NET_MPLS] = 7, /* "1048575" */ }; @@ -102,6 +106,8 @@ net_format(const net_addr *N, char *buf, int buflen) return flow4_net_format(buf, buflen, &n->flow4); case NET_FLOW6: return flow6_net_format(buf, buflen, &n->flow6); + case NET_IP6_SADR: + return bsnprintf(buf, buflen, "%I6/%d from %I6/%d", n->ip6_sadr.dst_prefix, n->ip6_sadr.dst_pxlen, n->ip6_sadr.src_prefix, n->ip6_sadr.src_pxlen); case NET_MPLS: return bsnprintf(buf, buflen, "%u", n->mpls.label); } @@ -126,6 +132,9 @@ net_pxmask(const net_addr *a) case NET_FLOW6: return ipa_from_ip6(ip6_mkmask(net6_pxlen(a))); + case NET_IP6_SADR: + return ipa_from_ip6(ip6_mkmask(net6_pxlen(a))); + case NET_MPLS: default: return IPA_NONE; @@ -156,6 +165,8 @@ net_compare(const net_addr *a, const net_addr *b) return net_compare_flow4((const net_addr_flow4 *) a, (const net_addr_flow4 *) b); case NET_FLOW6: return net_compare_flow6((const net_addr_flow6 *) a, (const net_addr_flow6 *) b); + case NET_IP6_SADR: + return net_compare_ip6_sadr((const net_addr_ip6_sadr *) a, (const net_addr_ip6_sadr *) b); case NET_MPLS: return net_compare_mpls((const net_addr_mpls *) a, (const net_addr_mpls *) b); } @@ -177,6 +188,7 @@ net_hash(const net_addr *n) case NET_ROA6: return NET_HASH(n, roa6); case NET_FLOW4: return NET_HASH(n, flow4); case NET_FLOW6: return NET_HASH(n, flow6); + case NET_IP6_SADR: return NET_HASH(n, ip6_sadr); case NET_MPLS: return NET_HASH(n, mpls); default: bug("invalid type"); } @@ -198,6 +210,7 @@ net_validate(const net_addr *n) case NET_ROA6: return NET_VALIDATE(n, roa6); case NET_FLOW4: return NET_VALIDATE(n, flow4); case NET_FLOW6: return NET_VALIDATE(n, flow6); + case NET_IP6_SADR: return NET_VALIDATE(n, ip6_sadr); case NET_MPLS: return NET_VALIDATE(n, mpls); default: return 0; } @@ -222,6 +235,9 @@ net_normalize(net_addr *N) case NET_FLOW6: return net_normalize_ip6(&n->ip6); + case NET_IP6_SADR: + return net_normalize_ip6_sadr(&n->ip6_sadr); + case NET_MPLS: return; } @@ -246,6 +262,9 @@ net_classify(const net_addr *N) case NET_FLOW6: return ip6_zero(n->ip6.prefix) ? (IADDR_HOST | SCOPE_UNIVERSE) : ip6_classify(&n->ip6.prefix); + case NET_IP6_SADR: + return ip6_zero(n->ip6_sadr.dst_prefix) ? (IADDR_HOST | SCOPE_UNIVERSE) : ip6_classify(&n->ip6_sadr.dst_prefix); + case NET_MPLS: return IADDR_HOST | SCOPE_UNIVERSE; } @@ -274,6 +293,11 @@ ipa_in_netX(const ip_addr a, const net_addr *n) return ip6_zero(ip6_and(ip6_xor(ipa_to_ip6(a), net6_prefix(n)), ip6_mkmask(net6_pxlen(n)))); + case NET_IP6_SADR: + if (ipa_is_ip4(a)) return 0; + return ip6_zero(ip6_and(ip6_xor(ipa_to_ip6(a), net6_prefix(n)), + ip6_mkmask(net6_pxlen(n)))); + case NET_MPLS: default: return 0; diff --git a/lib/net.h b/lib/net.h index 69f00641..083a37f4 100644 --- a/lib/net.h +++ b/lib/net.h @@ -12,7 +12,6 @@ #include "lib/ip.h" - #define NET_IP4 1 #define NET_IP6 2 #define NET_VPN4 3 @@ -21,8 +20,9 @@ #define NET_ROA6 6 #define NET_FLOW4 7 #define NET_FLOW6 8 -#define NET_MPLS 9 -#define NET_MAX 10 +#define NET_IP6_SADR 9 +#define NET_MPLS 10 +#define NET_MAX 11 #define NB_IP4 (1 << NET_IP4) #define NB_IP6 (1 << NET_IP6) @@ -32,12 +32,13 @@ #define NB_ROA6 (1 << NET_ROA6) #define NB_FLOW4 (1 << NET_FLOW4) #define NB_FLOW6 (1 << NET_FLOW6) +#define NB_IP6_SADR (1 << NET_IP6_SADR) #define NB_MPLS (1 << NET_MPLS) #define NB_IP (NB_IP4 | NB_IP6) #define NB_VPN (NB_VPN4 | NB_VPN6) #define NB_FLOW (NB_FLOW4 | NB_FLOW6) -#define NB_DEST (NB_IP | NB_VPN | NB_MPLS) +#define NB_DEST (NB_IP | NB_IP6_SADR | NB_VPN | NB_MPLS) #define NB_ANY 0xffffffff @@ -121,6 +122,15 @@ typedef struct net_addr_mpls { u32 label; } net_addr_mpls; +typedef struct net_addr_ip6_sadr { + u8 type; + u8 dst_pxlen; + u16 length; + ip6_addr dst_prefix; + s32 src_pxlen; // if u8, NET_ADDR_IP6_SADR would leave non-zero padding + ip6_addr src_prefix; +} net_addr_ip6_sadr; + typedef union net_addr_union { net_addr n; net_addr_ip4 ip4; @@ -132,6 +142,7 @@ typedef union net_addr_union { net_addr_flow4 flow4; net_addr_flow6 flow6; net_addr_mpls mpls; + net_addr_ip6_sadr ip6_sadr; } net_addr_union; @@ -170,6 +181,9 @@ extern const u16 net_max_text_length[]; #define NET_ADDR_MPLS(label) \ ((net_addr_mpls) { NET_MPLS, 20, sizeof(net_addr_mpls), label }) +#define NET_ADDR_IP6_SADR(dst_prefix,dst_pxlen,src_prefix,src_pxlen) \ + ((net_addr_ip6_sadr) { NET_IP6_SADR, dst_pxlen, sizeof(net_addr_ip6_sadr), dst_prefix, src_pxlen, src_prefix }) + static inline void net_fill_ip4(net_addr *a, ip4_addr prefix, uint pxlen) { *(net_addr_ip4 *)a = NET_ADDR_IP4(prefix, pxlen); } @@ -192,6 +206,9 @@ static inline void net_fill_roa6(net_addr *a, ip6_addr prefix, uint pxlen, uint static inline void net_fill_mpls(net_addr *a, u32 label) { *(net_addr_mpls *)a = NET_ADDR_MPLS(label); } +static inline void net_fill_ip6_sadr(net_addr *a, ip6_addr dst_prefix, uint dst_pxlen, ip6_addr src_prefix, uint src_pxlen) +{ *(net_addr_ip6_sadr *)a = NET_ADDR_IP6_SADR(dst_prefix, dst_pxlen, src_prefix, src_pxlen); } + static inline void net_fill_ipa(net_addr *a, ip_addr prefix, uint pxlen) { if (ipa_is_ip4(prefix)) @@ -240,6 +257,15 @@ static inline int net_is_roa(const net_addr *a) static inline int net_is_flow(const net_addr *a) { return (a->type == NET_FLOW4) || (a->type == NET_FLOW6); } +static inline int net_is_sadr(const net_addr *a) +{ return (a->type == NET_IP6_SADR); } + +static inline int net_is_sadr_set(const net_addr *a) +{ + net_addr_ip6_sadr *sa = (void *) a; + return (a->type == NET_IP6_SADR && sa->src_pxlen > 0); +} + static inline ip4_addr net4_prefix(const net_addr *a) { return ((net_addr_ip4 *) a)->prefix; } @@ -261,6 +287,7 @@ static inline ip_addr net_prefix(const net_addr *a) case NET_VPN6: case NET_ROA6: case NET_FLOW6: + case NET_IP6_SADR: return ipa_from_ip6(net6_prefix(a)); case NET_MPLS: @@ -331,6 +358,13 @@ static inline int net_equal_flow6(const net_addr_flow6 *a, const net_addr_flow6 static inline int net_equal_mpls(const net_addr_mpls *a, const net_addr_mpls *b) { return !memcmp(a, b, sizeof(net_addr_mpls)); } +typedef net_addr_ip6 net_addr_sadr_dst; +static inline int net_equal_sadr_dst(const net_addr_ip6 *a, const net_addr_ip6 *b) +{ return net_equal_ip6(a, b); } + +static inline int net_equal_ip6_sadr(const net_addr_ip6_sadr *a, const net_addr_ip6_sadr *b) +{ return !memcmp(a, b, sizeof(net_addr_ip6_sadr)); } + static inline int net_equal_prefix_roa4(const net_addr_roa4 *a, const net_addr_roa4 *b) { return ip4_equal(a->prefix, b->prefix) && (a->pxlen == b->pxlen); } @@ -394,6 +428,13 @@ static inline int net_compare_flow6(const net_addr_flow6 *a, const net_addr_flow static inline int net_compare_mpls(const net_addr_mpls *a, const net_addr_mpls *b) { return uint_cmp(a->label, b->label); } +static inline int net_compare_ip6_sadr(const net_addr_ip6_sadr *a, const net_addr_ip6_sadr *b) +{ + return + ip6_compare(a->dst_prefix, b->dst_prefix) ?: uint_cmp(a->dst_pxlen, b->dst_pxlen) ?: + ip6_compare(a->src_prefix, b->src_prefix) ?: uint_cmp(a->src_pxlen, b->src_pxlen); +} + int net_compare(const net_addr *a, const net_addr *b); @@ -427,6 +468,9 @@ static inline void net_copy_flow6(net_addr_flow6 *dst, const net_addr_flow6 *src static inline void net_copy_mpls(net_addr_mpls *dst, const net_addr_mpls *src) { memcpy(dst, src, sizeof(net_addr_mpls)); } +static inline void net_copy_ip6_sadr(net_addr_ip6_sadr *dst, const net_addr_ip6_sadr *src) +{ memcpy(dst, src, sizeof(net_addr_ip6_sadr)); } + /* XXXX */ static inline u32 u64_hash(u64 a) @@ -438,6 +482,9 @@ static inline u32 net_hash_ip4(const net_addr_ip4 *n) static inline u32 net_hash_ip6(const net_addr_ip6 *n) { return ip6_hash(n->prefix) ^ ((u32) n->pxlen << 26); } +static inline u32 net_hash_ip6_sadr(const net_addr_ip6_sadr *n) +{ return net_hash_ip6((net_addr_ip6 *)n); } + static inline u32 net_hash_vpn4(const net_addr_vpn4 *n) { return ip4_hash(n->prefix) ^ ((u32) n->pxlen << 26) ^ u64_hash(n->rd); } @@ -508,6 +555,9 @@ static inline int net_validate_flow6(const net_addr_flow6 *n) static inline int net_validate_mpls(const net_addr_mpls *n) { return n->label < (1 << 20); } +static inline int net_validate_ip6_sadr(const net_addr_ip6_sadr *n) +{ return net_validate_px6(n->dst_prefix, n->dst_pxlen) && net_validate_px6(n->src_prefix, n->src_pxlen); } + int net_validate(const net_addr *N); @@ -523,6 +573,10 @@ static inline void net_normalize_vpn4(net_addr_vpn4 *n) static inline void net_normalize_vpn6(net_addr_vpn6 *n) { net_normalize_ip6((net_addr_ip6 *) n); } +static inline void net_normalize_ip6_sadr(net_addr_ip6_sadr *n) +{ n->dst_prefix = ip6_and(n->dst_prefix, ip6_mkmask(n->dst_pxlen)); + n->src_prefix = ip6_and(n->src_prefix, ip6_mkmask(n->src_pxlen)); } + void net_normalize(net_addr *N); diff --git a/nest/config.Y b/nest/config.Y index 044aba2b..9f4e6215 100644 --- a/nest/config.Y +++ b/nest/config.Y @@ -77,7 +77,7 @@ CF_KEYWORDS(TIMEFORMAT, ISO, SHORT, LONG, ROUTE, PROTOCOL, BASE, LOG, S, MS, US) CF_KEYWORDS(GRACEFUL, RESTART, WAIT, MAX, FLUSH, AS) /* For r_args_channel */ -CF_KEYWORDS(IPV4, IPV4_MC, IPV4_MPLS, IPV6, IPV6_MC, IPV6_MPLS, VPN4, VPN4_MC, VPN4_MPLS, VPN6, VPN6_MC, VPN6_MPLS, ROA4, ROA6, FLOW4, FLOW6, MPLS, PRI, SEC) +CF_KEYWORDS(IPV4, IPV4_MC, IPV4_MPLS, IPV6, IPV6_MC, IPV6_MPLS, SADR, VPN4, VPN4_MC, VPN4_MPLS, VPN6, VPN6_MC, VPN6_MPLS, ROA4, ROA6, FLOW4, FLOW6, MPLS, PRI, SEC) CF_ENUM(T_ENUM_RTS, RTS_, DUMMY, STATIC, INHERIT, DEVICE, STATIC_DEVICE, REDIRECT, RIP, OSPF, OSPF_IA, OSPF_EXT1, OSPF_EXT2, BGP, PIPE, BABEL) @@ -134,6 +134,7 @@ gr_opts: GRACEFUL RESTART WAIT expr ';' { new_config->gr_wait = $4; } ; net_type: IPV4 { $$ = NET_IP4; } | IPV6 { $$ = NET_IP6; } + | IPV6 SADR { $$ = NET_IP6_SADR; } | VPN4 { $$ = NET_VPN4; } | VPN6 { $$ = NET_VPN6; } | ROA4 { $$ = NET_ROA4; } @@ -143,7 +144,7 @@ net_type: | MPLS { $$ = NET_MPLS; } ; -CF_ENUM(T_ENUM_NETTYPE, NET_, IP4, IP6, VPN4, VPN6, ROA4, ROA6, FLOW4, FLOW6) +CF_ENUM(T_ENUM_NETTYPE, NET_, IP4, IP6, VPN4, VPN6, ROA4, ROA6, FLOW4, FLOW6, IP6_SADR) /* Creation of routing tables */ @@ -625,6 +626,7 @@ r_args_for: } | net_vpn4_ | net_vpn6_ + | net_ip6_sadr_ | VPN_RD IP4 { $$ = cfg_alloc(sizeof(net_addr_vpn4)); net_fill_vpn4($$, $2, IP4_MAX_PREFIX_LENGTH, $1); diff --git a/nest/rt-fib.c b/nest/rt-fib.c index c09f2759..36a8f442 100644 --- a/nest/rt-fib.c +++ b/nest/rt-fib.c @@ -236,6 +236,7 @@ fib_find(struct fib *f, const net_addr *a) case NET_ROA6: return FIB_FIND(f, a, roa6); case NET_FLOW4: return FIB_FIND(f, a, flow4); case NET_FLOW6: return FIB_FIND(f, a, flow6); + case NET_IP6_SADR: return FIB_FIND(f, a, ip6_sadr); case NET_MPLS: return FIB_FIND(f, a, mpls); default: bug("invalid type"); } @@ -256,6 +257,7 @@ fib_insert(struct fib *f, const net_addr *a, struct fib_node *e) case NET_ROA6: FIB_INSERT(f, a, e, roa6); return; case NET_FLOW4: FIB_INSERT(f, a, e, flow4); return; case NET_FLOW6: FIB_INSERT(f, a, e, flow6); return; + case NET_IP6_SADR: FIB_INSERT(f, a, e, ip6_sadr); return; case NET_MPLS: FIB_INSERT(f, a, e, mpls); return; default: bug("invalid type"); } diff --git a/nest/rt-table.c b/nest/rt-table.c index 4640d6a9..af5d7282 100644 --- a/nest/rt-table.c +++ b/nest/rt-table.c @@ -85,6 +85,46 @@ net_route_ip6(rtable *t, net_addr_ip6 *n) return r; } +static inline void * +net_route_ip6_sadr(rtable *t, net_addr_ip6_sadr *n) +{ + struct fib_node *fn; + + while (1) + { + net *best = NULL; + u8 best_pxlen = 0; + + /* We need to do dst first matching. Since sadr addresses are hashed on dst + prefix only, find the hash table chain and go through it to find the + match with the smallest matching src prefix. */ + for (fn = fib_get_chain(&t->fib, (net_addr *) n); fn; fn = fn->next) + { + net_addr_ip6_sadr *ip6_sadr = (void *) fn->addr; + net *r = fib_node_to_user(&t->fib, fn); + net_addr_ip6 a = NET_ADDR_IP6(n->src_prefix, n->src_pxlen); + net_addr_ip6 b = NET_ADDR_IP6(ip6_sadr->src_prefix, ip6_sadr->src_pxlen); + + if (net_in_net_ip6((struct net_addr_ip6*) n, (struct net_addr_ip6*) ip6_sadr) + && net_in_net_ip6(&a, &b) && ip6_sadr->src_pxlen >= best_pxlen) { + best = r; + best_pxlen = ip6_sadr->src_pxlen; + } + } + + if (best) + return best; + + if (!n->dst_pxlen) + break; + + n->dst_pxlen--; + ip6_clrbit(&n->dst_prefix, n->dst_pxlen); + } + + return NULL; +} + void * net_route(rtable *tab, const net_addr *n) { @@ -105,6 +145,9 @@ net_route(rtable *tab, const net_addr *n) case NET_ROA6: return net_route_ip6(tab, (net_addr_ip6 *) n0); + case NET_IP6_SADR: + return net_route_ip6_sadr(tab, (net_addr_ip6_sadr *) n0); + default: return NULL; } @@ -1604,7 +1647,7 @@ rt_setup(pool *p, rtable *t, char *name, struct rtable_config *cf) bzero(t, sizeof(*t)); t->name = name; t->config = cf; - t->addr_type = cf ? cf->addr_type : NET_IP4; + t->addr_type = cf ? cf->addr_type : NET_IP6_SADR; /* FIXME */ fib_init(&t->fib, p, t->addr_type, sizeof(net), OFFSETOF(net, n), 0, NULL); init_list(&t->channels); diff --git a/sysdep/cf/linux.h b/sysdep/cf/linux.h index 3a3a15da..047d3764 100644 --- a/sysdep/cf/linux.h +++ b/sysdep/cf/linux.h @@ -10,6 +10,7 @@ #define CONFIG_SELF_CONSCIOUS #define CONFIG_MULTIPLE_TABLES #define CONFIG_ALL_TABLES_AT_ONCE +#define CONFIG_IP6_SADR_KERNEL #define CONFIG_MC_PROPER_SRC #define CONFIG_UNIX_DONTROUTE diff --git a/sysdep/linux/netlink.c b/sysdep/linux/netlink.c index 4cb51519..c6f2e1fc 100644 --- a/sysdep/linux/netlink.c +++ b/sysdep/linux/netlink.c @@ -374,6 +374,7 @@ static struct nl_want_attrs rtm_attr_want4[BIRD_RTA_MAX] = { static struct nl_want_attrs rtm_attr_want6[BIRD_RTA_MAX] = { [RTA_DST] = { 1, 1, sizeof(ip6_addr) }, + [RTA_SRC] = { 1, 1, sizeof(ip6_addr) }, [RTA_IIF] = { 1, 1, sizeof(u32) }, [RTA_OIF] = { 1, 1, sizeof(u32) }, [RTA_GATEWAY] = { 1, 1, sizeof(ip6_addr) }, @@ -1221,7 +1222,16 @@ nl_send_route(struct krt_proto *p, rte *e, struct ea_list *eattrs, int op, int d } else #endif + { nl_add_attr_ipa(&r->h, rsize, RTA_DST, net_prefix(net->n.addr)); + // add source address for SADR routes + if (net->n.addr->type == NET_IP6_SADR) + { + net_addr_ip6_sadr *sadr_addr = (void *) &net->n.addr; + r->r.rtm_src_len = sadr_addr->src_pxlen; + nl_add_attr_ipa(&r->h, rsize, RTA_SRC, sadr_addr->src_prefix); + } + } /* * Strange behavior for RTM_DELROUTE: @@ -1447,7 +1457,8 @@ nl_parse_route(struct nl_parse_state *s, struct nlmsghdr *h) struct rtattr *a[BIRD_RTA_MAX]; int new = h->nlmsg_type == RTM_NEWROUTE; - net_addr dst; + net_addr dst, sadr_src; + net_fill_ip6(&sadr_src, IP6_NONE, 0); u32 oif = ~0; u32 table_id; u32 priority = 0; @@ -1473,6 +1484,9 @@ nl_parse_route(struct nl_parse_state *s, struct nlmsghdr *h) if (!nl_parse_attrs(RTM_RTA(i), rtm_attr_want6, a, sizeof(a))) return; + if (a[RTA_SRC]) + net_fill_ip6(&sadr_src, rta_get_ip6(a[RTA_SRC]), i->rtm_src_len); + if (a[RTA_DST]) net_fill_ip6(&dst, rta_get_ip6(a[RTA_DST]), i->rtm_dst_len); else @@ -1551,7 +1565,20 @@ nl_parse_route(struct nl_parse_state *s, struct nlmsghdr *h) src = KRT_SRC_ALIEN; } - net *net = net_get(p->p.main_channel->table, &dst); + net *net; + if (p->p.main_channel->table->addr_type == NET_IP6_SADR) + { + net_addr_ip6_sadr sadr_addr = + NET_ADDR_IP6_SADR(net_prefix(&dst), net_pxlen(&dst), + net_prefix(&sadr_src), net_pxlen(&sadr_src)); + net = net_get(p->p.main_channel->table, (net_addr *)&sadr_addr); + } + else + { + if (a[RTA_SRC]) + SKIP("sadr prefix for non-sadr channel\n"); + net = net_get(p->p.main_channel->table, &dst); + } if (s->net && !nl_mergable_route(s, net, p, priority, i->rtm_type)) nl_announce_route(s); diff --git a/sysdep/unix/krt.c b/sysdep/unix/krt.c index e7bd79e3..d89e7355 100644 --- a/sysdep/unix/krt.c +++ b/sysdep/unix/krt.c @@ -1103,7 +1103,9 @@ krt_start(struct proto *P) switch (p->p.net_type) { case NET_IP4: p->af = AF_INET; break; - case NET_IP6: p->af = AF_INET6; break; + case NET_IP6: + case NET_IP6_SADR: + p->af = AF_INET6; break; #ifdef AF_MPLS case NET_MPLS: p->af = AF_MPLS; break; #endif @@ -1213,16 +1215,24 @@ krt_get_attr(eattr *a, byte *buf, int buflen) } +#ifdef CONFIG_IP6_SADR_KERNEL +#define MAYBE_IP6_SADR NB_IP6_SADR +#else +#define MAYBE_IP6_SADR 0 +#endif + +#ifdef HAVE_MPLS_KERNEL +#define MAYBE_MPLS NB_MPLS +#else +#define MAYBE_MPLS 0 +#endif + struct protocol proto_unix_kernel = { .name = "Kernel", .template = "kernel%d", .attr_class = EAP_KRT, .preference = DEF_PREF_INHERITED, -#ifdef HAVE_MPLS_KERNEL - .channel_mask = NB_IP | NB_MPLS, -#else - .channel_mask = NB_IP, -#endif + .channel_mask = NB_IP | MAYBE_IP6_SADR | MAYBE_MPLS, .proto_size = sizeof(struct krt_proto), .config_size = sizeof(struct krt_config), .preconfig = krt_preconfig, -- 2.16.1
participants (2)
-
Ondrej Zajicek -
Toke Høiland-Jørgensen