diff --git a/filter/config.Y b/filter/config.Y index f8170a83..e01e02ef 100644 --- a/filter/config.Y +++ b/filter/config.Y @@ -411,7 +411,7 @@ CF_KEYWORDS(FUNCTION, PRINT, PRINTN, UNSET, RETURN, TRUE, FALSE, RT, RO, UNKNOWN, GENERIC, FROM, GW, NET, MASK, PROTO, SOURCE, SCOPE, DEST, IFNAME, IFINDEX, PREFERENCE, - ROA_CHECK, ASN, + ROA_CHECK, ASN, SRC, IS_V4, IS_V6, LEN, MAXLEN, DEFINED, @@ -898,6 +898,7 @@ term: | term '.' LEN { $$ = f_new_inst(FI_LENGTH); $$->a1.p = $1; } | term '.' MAXLEN { $$ = f_new_inst(FI_ROA_MAXLEN); $$->a1.p = $1; } | term '.' ASN { $$ = f_new_inst(FI_ROA_ASN); $$->a1.p = $1; } + | term '.' SRC { $$ = f_new_inst(FI_SADR_SRC); $$->a1.p = $1; } | term '.' MASK '(' term ')' { $$ = f_new_inst(FI_IP_MASK); $$->a1.p = $1; $$->a2.p = $5; } | term '.' FIRST { $$ = f_new_inst(FI_AS_PATH_FIRST); $$->a1.p = $1; } | term '.' LAST { $$ = f_new_inst(FI_AS_PATH_LAST); $$->a1.p = $1; } diff --git a/filter/filter.c b/filter/filter.c index 881ba420..3d7b5c9f 100644 --- a/filter/filter.c +++ b/filter/filter.c @@ -1241,6 +1241,20 @@ interpret(struct f_inst *what) default: runtime( "Prefix, path, clist or eclist expected" ); } break; + case FI_SADR_SRC: /* Get SADR src prefix */ + ONEARG; + if (v1.type != T_NET || !net_is_sadr(v1.val.net)) + runtime( "SADR expected" ); + + { + net_addr_ip6_sadr *net = (void *) v1.val.net; + net_addr *src = lp_alloc(f_pool, sizeof(net_addr_ip6)); + net_fill_ip6(src, net->src_prefix, net->src_pxlen); + + res.type = T_NET; + res.val.net = src; + } + break; case FI_ROA_MAXLEN: /* Get ROA max prefix length */ ONEARG; if (v1.type != T_NET || !net_is_roa(v1.val.net)) @@ -1714,6 +1728,7 @@ i_same(struct f_inst *f1, struct f_inst *f2) case FI_RETURN: ONEARG; break; case FI_ROA_MAXLEN: ONEARG; break; case FI_ROA_ASN: ONEARG; break; + case FI_SADR_SRC: ONEARG; break; case FI_IP: ONEARG; break; case FI_IS_V4: ONEARG; break; case FI_ROUTE_DISTINGUISHER: ONEARG; break; diff --git a/filter/filter.h b/filter/filter.h index d347924a..982276f0 100644 --- a/filter/filter.h +++ b/filter/filter.h @@ -55,6 +55,7 @@ F(FI_LENGTH, 0, 'L') \ F(FI_ROA_MAXLEN, 'R', 'M') \ F(FI_ROA_ASN, 'R', 'A') \ + F(FI_SADR_SRC, 'n', 's') \ F(FI_IP, 'c', 'p') \ F(FI_ROUTE_DISTINGUISHER, 'R', 'D') \ F(FI_AS_PATH_FIRST, 'a', 'f') \ diff --git a/lib/net.h b/lib/net.h index ad4000fd..0cd5f735 100644 --- a/lib/net.h +++ b/lib/net.h @@ -268,6 +268,8 @@ 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 ip4_addr net4_prefix(const net_addr *a) { return ((net_addr_ip4 *) a)->prefix; }