0
0
mirror of https://gitlab.nic.cz/labs/bird.git synced 2024-11-09 12:48:43 +00:00

Filter: Add support for src filter op to access SADR source prefix

The patch allows to use 'net.src' to access SADR source prefix
from filters.

Thanks to Toke Hoiland-Jorgensen for the original patch for srclen.
This commit is contained in:
Ondrej Zajicek (work) 2018-05-16 11:19:29 +02:00
parent eaf63d314d
commit b24b781117
4 changed files with 20 additions and 1 deletions

View File

@ -411,7 +411,7 @@ CF_KEYWORDS(FUNCTION, PRINT, PRINTN, UNSET, RETURN,
TRUE, FALSE, RT, RO, UNKNOWN, GENERIC, TRUE, FALSE, RT, RO, UNKNOWN, GENERIC,
FROM, GW, NET, MASK, PROTO, SOURCE, SCOPE, DEST, IFNAME, IFINDEX, FROM, GW, NET, MASK, PROTO, SOURCE, SCOPE, DEST, IFNAME, IFINDEX,
PREFERENCE, PREFERENCE,
ROA_CHECK, ASN, ROA_CHECK, ASN, SRC,
IS_V4, IS_V6, IS_V4, IS_V6,
LEN, MAXLEN, LEN, MAXLEN,
DEFINED, DEFINED,
@ -898,6 +898,7 @@ term:
| term '.' LEN { $$ = f_new_inst(FI_LENGTH); $$->a1.p = $1; } | term '.' LEN { $$ = f_new_inst(FI_LENGTH); $$->a1.p = $1; }
| term '.' MAXLEN { $$ = f_new_inst(FI_ROA_MAXLEN); $$->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 '.' 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 '.' 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 '.' FIRST { $$ = f_new_inst(FI_AS_PATH_FIRST); $$->a1.p = $1; }
| term '.' LAST { $$ = f_new_inst(FI_AS_PATH_LAST); $$->a1.p = $1; } | term '.' LAST { $$ = f_new_inst(FI_AS_PATH_LAST); $$->a1.p = $1; }

View File

@ -1241,6 +1241,20 @@ interpret(struct f_inst *what)
default: runtime( "Prefix, path, clist or eclist expected" ); default: runtime( "Prefix, path, clist or eclist expected" );
} }
break; 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 */ case FI_ROA_MAXLEN: /* Get ROA max prefix length */
ONEARG; ONEARG;
if (v1.type != T_NET || !net_is_roa(v1.val.net)) 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_RETURN: ONEARG; break;
case FI_ROA_MAXLEN: ONEARG; break; case FI_ROA_MAXLEN: ONEARG; break;
case FI_ROA_ASN: ONEARG; break; case FI_ROA_ASN: ONEARG; break;
case FI_SADR_SRC: ONEARG; break;
case FI_IP: ONEARG; break; case FI_IP: ONEARG; break;
case FI_IS_V4: ONEARG; break; case FI_IS_V4: ONEARG; break;
case FI_ROUTE_DISTINGUISHER: ONEARG; break; case FI_ROUTE_DISTINGUISHER: ONEARG; break;

View File

@ -55,6 +55,7 @@
F(FI_LENGTH, 0, 'L') \ F(FI_LENGTH, 0, 'L') \
F(FI_ROA_MAXLEN, 'R', 'M') \ F(FI_ROA_MAXLEN, 'R', 'M') \
F(FI_ROA_ASN, 'R', 'A') \ F(FI_ROA_ASN, 'R', 'A') \
F(FI_SADR_SRC, 'n', 's') \
F(FI_IP, 'c', 'p') \ F(FI_IP, 'c', 'p') \
F(FI_ROUTE_DISTINGUISHER, 'R', 'D') \ F(FI_ROUTE_DISTINGUISHER, 'R', 'D') \
F(FI_AS_PATH_FIRST, 'a', 'f') \ F(FI_AS_PATH_FIRST, 'a', 'f') \

View File

@ -268,6 +268,8 @@ static inline int net_is_roa(const net_addr *a)
static inline int net_is_flow(const net_addr *a) static inline int net_is_flow(const net_addr *a)
{ return (a->type == NET_FLOW4) || (a->type == NET_FLOW6); } { 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) static inline ip4_addr net4_prefix(const net_addr *a)
{ return ((net_addr_ip4 *) a)->prefix; } { return ((net_addr_ip4 *) a)->prefix; }