support for vxlan vni filtering
Subsystems (3)
v2 cover support for vxlan vni filtering
This series adds bridge command to manage recently added vnifilter on a collect metadata vxlan (external) device. Also includes per vni stats support.
examples:
$bridge vni add dev vxlan0 vni 400
$bridge vni add dev vxlan0 vni 200 group 239.1.1.101
$bridge vni del dev vxlan0 vni 400
$bridge vni show
$bridge -s vni show
Nikolay Aleksandrov (1):
bridge: vni: add support for stats dumping
Roopa Prabhu (2):
bridge: vxlan device vnifilter support
ip: iplink_vxlan: add support to set vnifiltering flag on vxlan device
v2 : replace matches by strcmp in bridge/vni.c. v2 still uses matches in iplink_vxlan.c to match the rest of the code
bridge/Makefile | 2 +- bridge/br_common.h | 2 + bridge/bridge.c | 1 + bridge/monitor.c | 28 ++- bridge/vni.c | 439 ++++++++++++++++++++++++++++++++++++++++++ include/libnetlink.h | 9 + ip/iplink_vxlan.c | 23 ++- lib/libnetlink.c | 20 ++ man/man8/bridge.8 | 77 +++++++- man/man8/ip-link.8.in | 9 + 10 files changed, 606 insertions(+), 4 deletions(-) create mode 100644 bridge/vni.c
Signature · 1 line
2.25.1
PATCH v2 2/3 ip: iplink_vxlan: add support to set vnifiltering flag on vxlan device
This patch adds option to set vnifilter flag on a vxlan device. vnifilter is only supported on a collect metadata device.
example: set vnifilter flag
$ ip link add vxlan0 type vxlan external vnifilter local 172.16.0.1
--- ip/iplink_vxlan.c | 23 ++++++++++++++++++++++- man/man8/ip-link.8.in | 9 +++++++++ 2 files changed, 31 insertions(+), 1 deletion(-)
ip/iplink_vxlan.c +22 -1
@@ -48,6 +48,7 @@ static void print_explain(FILE *f)" [ [no]udp6zerocsumrx ]\n" " [ [no]remcsumtx ] [ [no]remcsumrx ]\n" " [ [no]external ] [ gbp ] [ gpe ]\n" +" [ [no]vnifilter ]\n" "\n" "Where: VNI := 0-16777215\n" " ADDR := { IP_ADDRESS | any }\n"
@@ -81,6 +82,7 @@ static int vxlan_parse_opt(struct link_util *lu, int argc, char **argv,__u8 learning =1 ;__u16 dstport =0 ;__u8 metadata =0 ; +__u8 vnifilter =0 ;__u64 attrs =0 ;bool set_op = (n->nlmsg_type ==RTM_NEWLINK && !(n->nlmsg_flags &NLM_F_CREATE ));
@@ -330,6 +332,15 @@ static int vxlan_parse_opt(struct link_util *lu, int argc, char **argv, }else if (!matches (*argv,"gpe" )) {check_duparg (&attrs,IFLA_VXLAN_GPE , *argv, *argv);addattr_l (n,1024 ,IFLA_VXLAN_GPE ,NULL ,0 ); + }else if (!matches (*argv,"vnifilter" )) { +check_duparg (&attrs,IFLA_VXLAN_VNIFILTER , + *argv, *argv); +addattr8 (n,1024 ,IFLA_VXLAN_VNIFILTER ,1 ); + vnifilter =1 ; + }else if (!matches (*argv,"novnifilter" )) { +check_duparg (&attrs,IFLA_VXLAN_VNIFILTER , + *argv, *argv); +addattr8 (n,1024 ,IFLA_VXLAN_VNIFILTER ,0 ); }else if (matches (*argv,"help" ) ==0 ) {explain ();return -1 ;
@@ -341,12 +352,17 @@ static int vxlan_parse_opt(struct link_util *lu, int argc, char **argv, argc--, argv++; } +if (!metadata && vnifilter) { +fprintf (stderr,"vxlan: vnifilter is valid only when 'external' is set\n" ); +return -1 ; + } +if (metadata &&VXLAN_ATTRSET (attrs,IFLA_VXLAN_ID )) {fprintf (stderr,"vxlan: both 'external' and vni cannot be specified\n" );return -1 ; } -if (!metadata && !VXLAN_ATTRSET (attrs,IFLA_VXLAN_ID ) && !set_op) { +if (!metadata && !vnifilter && !VXLAN_ATTRSET (attrs,IFLA_VXLAN_ID ) && !set_op) {fprintf (stderr,"vxlan: missing virtual network identifier\n" );return -1 ; }
@@ -420,6 +436,11 @@ static void vxlan_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])print_bool (PRINT_ANY ,"external" ,"external " , true); } +if (tb[IFLA_VXLAN_VNIFILTER ] && +rta_getattr_u8 (tb[IFLA_VXLAN_VNIFILTER ])) { +print_bool (PRINT_ANY ,"vnifilter" ,"vnifilter" , true); + } +if (tb[IFLA_VXLAN_ID ] &&RTA_PAYLOAD (tb[IFLA_VXLAN_ID ]) >=sizeof (__u32)) {print_uint (PRINT_ANY ,"id" ,"id %u " ,rta_getattr_u32 (tb[IFLA_VXLAN_ID ]));
man/man8/ip-link.8.in +9 -0
@@ -601,6 +601,8 @@ the following additional arguments are supported: .B gbp ] [ .B gpe +] [ +.RB [ no ] vnifilter ] .in +8
@@ -712,6 +714,13 @@ are entered into the VXLAN device forwarding database. .RB "(e.g. " "ip route encap" ) or the internal FDB should be used. +.sp +.RB [ no ] vnifilter +- specifies whether the vxlan device is capable of vni filtering. Only works with a vxlan +device with external flag set. once enabled, bridge vni command is used to manage the +vni filtering table on the device. The device can only receive packets with vni's configured +in the vni filtering table. + .sp .B gbp - enables the Group Policy extension (VXLAN-GBP).
Signature · 1 line
2.25.1
PATCH v2 3/3 bridge: vni: add support for stats dumping
In reply to Roopa PrabhuFrom: Nikolay Aleksandrov <[email protected]>
Add support for "-s" option which causes bridge vni to dump per-vni statistics. Note that it disables vni range compression.
Example:
$ bridge -s vni | more
dev vni group/remote
vxlan0 1024 239.1.1.1
RX: bytes 0 pkts 0 drops 0 errors 0
TX: bytes 0 pkts 0 drops 0 errors 0
1025 239.1.1.1
RX: bytes 0 pkts 0 drops 0 errors 0
TX: bytes 0 pkts 0 drops 0 errors 0--- bridge/vni.c | 93 ++++++++++++++++++++++++++++++++++++-------- include/libnetlink.h | 3 +- lib/libnetlink.c | 4 +- 3 files changed, 81 insertions(+), 19 deletions(-)
bridge/vni.c +76 -17
@@ -186,6 +186,59 @@ static void print_range(const char *name, __u32 start, __u32 id) } +static void print_vnifilter_entry_stats (struct rtattr *stats_attr) +{ +struct rtattr *stb[VNIFILTER_ENTRY_STATS_MAX +1 ]; +__u64 stat; + +open_json_object ("stats" ); +parse_rtattr_flags (stb,VNIFILTER_ENTRY_STATS_MAX ,RTA_DATA (stats_attr), +RTA_PAYLOAD (stats_attr),NLA_F_NESTED ); + +print_nl (); + print_string(PRINT_FP, NULL, "%-" __stringify(IFNAMSIZ) "s ", ""); +print_string (PRINT_FP ,NULL ,"RX: " ,"" ); + +if (stb[VNIFILTER_ENTRY_STATS_RX_BYTES ]) { + stat =rta_getattr_u64 (stb[VNIFILTER_ENTRY_STATS_RX_BYTES ]); +print_lluint (PRINT_ANY ,"rx_bytes" ,"bytes %llu " , stat); + } +if (stb[VNIFILTER_ENTRY_STATS_RX_PKTS ]) { + stat =rta_getattr_u64 (stb[VNIFILTER_ENTRY_STATS_RX_PKTS ]); +print_lluint (PRINT_ANY ,"rx_pkts" ,"pkts %llu " , stat); + } +if (stb[VNIFILTER_ENTRY_STATS_RX_DROPS ]) { + stat =rta_getattr_u64 (stb[VNIFILTER_ENTRY_STATS_RX_DROPS ]); +print_lluint (PRINT_ANY ,"rx_drops" ,"drops %llu " , stat); + } +if (stb[VNIFILTER_ENTRY_STATS_RX_ERRORS ]) { + stat =rta_getattr_u64 (stb[VNIFILTER_ENTRY_STATS_RX_ERRORS ]); +print_lluint (PRINT_ANY ,"rx_errors" ,"errors %llu " , stat); + } + +print_nl (); + print_string(PRINT_FP, NULL, "%-" __stringify(IFNAMSIZ) "s ", ""); +print_string (PRINT_FP ,NULL ,"TX: " ,"" ); + +if (stb[VNIFILTER_ENTRY_STATS_TX_BYTES ]) { + stat =rta_getattr_u64 (stb[VNIFILTER_ENTRY_STATS_TX_BYTES ]); +print_lluint (PRINT_ANY ,"tx_bytes" ,"bytes %llu " , stat); + } +if (stb[VNIFILTER_ENTRY_STATS_TX_PKTS ]) { + stat =rta_getattr_u64 (stb[VNIFILTER_ENTRY_STATS_TX_PKTS ]); +print_lluint (PRINT_ANY ,"tx_pkts" ,"pkts %llu " , stat); + } +if (stb[VNIFILTER_ENTRY_STATS_TX_DROPS ]) { + stat =rta_getattr_u64 (stb[VNIFILTER_ENTRY_STATS_TX_DROPS ]); +print_lluint (PRINT_ANY ,"tx_drops" ,"drops %llu " , stat); + } +if (stb[VNIFILTER_ENTRY_STATS_TX_ERRORS ]) { + stat =rta_getattr_u64 (stb[VNIFILTER_ENTRY_STATS_TX_ERRORS ]); +print_lluint (PRINT_ANY ,"tx_errors" ,"errors %llu " , stat); + } +close_json_object (); +} +static void print_vni (struct rtattr *t,int ifindex) {struct rtattr *ttb[VXLAN_VNIFILTER_ENTRY_MAX +1 ];
@@ -242,6 +295,10 @@ static void print_vni(struct rtattr *t, int ifindex) &addr)); } } + +if (ttb[VXLAN_VNIFILTER_ENTRY_STATS ]) +print_vnifilter_entry_stats (ttb[VXLAN_VNIFILTER_ENTRY_STATS ]); +close_json_object ();print_string (PRINT_FP ,NULL ,"%s" , _SL_); }
@@ -310,6 +367,7 @@ static int print_vnifilter_rtm_filter(struct nlmsghdr *n, void *arg)static int vni_show (int argc,char **argv) {char *filter_dev =NULL ; +__u8 flags =0 ;int ret =0 ;while (argc >0 ) {
@@ -330,25 +388,26 @@ static int vni_show(int argc, char **argv)new_json_obj (json); -if (!show_stats) { -if (rtnl_tunneldump_req (&rth,PF_BRIDGE , filter_index) <0 ) { -perror ("Cannot send dump request" ); -exit (1 ); - } +if (show_stats) + flags =TUNNEL_MSG_FLAG_STATS ; -if (!is_json_context ()) { - printf("%-" __stringify(IFNAMSIZ) "s %-" - __stringify(VXLAN_ID_LEN) "s %-" - __stringify(15) "s", -"dev" ,"vni" ,"group/remote" ); -printf ("\n" ); - } +if (rtnl_tunneldump_req (&rth,PF_BRIDGE , filter_index, flags) <0 ) { +perror ("Cannot send dump request" ); +exit (1 ); + } - ret =rtnl_dump_filter (&rth, print_vnifilter_rtm_filter,NULL ); -if (ret <0 ) { -fprintf (stderr,"Dump ternminated\n" ); -exit (1 ); - } +if (!is_json_context ()) { + printf("%-" __stringify(IFNAMSIZ) "s %-" + __stringify(VXLAN_ID_LEN) "s %-" + __stringify(15) "s", +"dev" ,"vni" ,"group/remote" ); +printf ("\n" ); + } + + ret =rtnl_dump_filter (&rth, print_vnifilter_rtm_filter,NULL ); +if (ret <0 ) { +fprintf (stderr,"Dump ternminated\n" ); +exit (1 ); }delete_json_obj ();
include/libnetlink.h +2 -1
@@ -112,7 +112,8 @@ int rtnl_nexthop_bucket_dump_req(struct rtnl_handle *rth, int family, req_filter_fn_t filter_fn) __attribute__((warn_unused_result)); -int rtnl_tunneldump_req (struct rtnl_handle *rth,int family,int ifindex) +int rtnl_tunneldump_req (struct rtnl_handle *rth,int family,int ifindex, +__u8 flags) __attribute__((warn_unused_result));struct rtnl_ctrl_data {
lib/libnetlink.c +3 -1
@@ -1610,7 +1610,8 @@ void nl_print_policy(const struct rtattr *attr, FILE *fp) } } -int rtnl_tunneldump_req (struct rtnl_handle *rth,int family,int ifindex) +int rtnl_tunneldump_req (struct rtnl_handle *rth,int family,int ifindex, +__u8 flags) {struct {struct nlmsghdr nlh;
@@ -1622,6 +1623,7 @@ int rtnl_tunneldump_req(struct rtnl_handle *rth, int family, int ifindex) .nlh.nlmsg_flags = NLM_F_DUMP | NLM_F_REQUEST, .nlh.nlmsg_seq = rth->dump = ++rth->seq, .tmsg.family = family, + .tmsg.flags = flags, .tmsg.ifindex = ifindex, };
Signature · 1 line
2.25.1
PATCH v2 1/3 bridge: vxlan device vnifilter support
In reply to Roopa PrabhuThis patch adds bridge command to manage
recently added vnifilter on a collect metadata
vxlan device.
examples:
$bridge vni add dev vxlan0 vni 400
$bridge vni add dev vxlan0 vni 200 group 239.1.1.101
$bridge vni del dev vxlan0 vni 400
$bridge vni show
$bridge -s vni show
--- bridge/Makefile | 2 +- bridge/br_common.h | 2 + bridge/bridge.c | 1 + bridge/monitor.c | 28 +++- bridge/vni.c | 380 +++++++++++++++++++++++++++++++++++++++++++ include/libnetlink.h | 8 + lib/libnetlink.c | 18 ++ man/man8/bridge.8 | 77 ++++++++- 8 files changed, 513 insertions(+), 3 deletions(-) create mode 100644 bridge/vni.c
bridge/Makefile +1 -1
@@ -1,5 +1,5 @@ # SPDX-License-Identifier: GPL-2.0 -BROBJ = bridge.o fdb.o monitor.o link.o mdb.o vlan.o +BROBJ = bridge.o fdb.o monitor.o link.o mdb.o vlan.o vni.o include ../config.mk
bridge/br_common.h +2 -0
@@ -14,6 +14,7 @@ void print_stp_state(__u8 state);int parse_stp_state (const char *arg);int print_vlan_rtm (struct nlmsghdr *n,void *arg,bool monitor,bool global_only); +int print_vnifilter_rtm (struct nlmsghdr *n,void *arg,bool monitor);void br_print_router_port_stats (struct rtattr *pattr);int do_fdb (int argc,char **argv);
@@ -21,6 +22,7 @@ int do_mdb(int argc, char **argv);int do_monitor (int argc,char **argv);int do_vlan (int argc,char **argv);int do_link (int argc,char **argv); +int do_vni (int argc,char **argv);extern int preferred_family;extern int show_stats;
bridge/bridge.c +1 -0
@@ -58,6 +58,7 @@ static const struct cmd { { "fdb", do_fdb }, { "mdb", do_mdb }, { "vlan", do_vlan }, + { "vni", do_vni }, { "monitor", do_monitor }, { "help", do_help }, { 0 }
bridge/monitor.c +27 -1
@@ -31,10 +31,20 @@ static int prefix_banner;static void usage (void ) { -fprintf (stderr,"Usage: bridge monitor [file | link | fdb | mdb | vlan | all]\n" ); +fprintf (stderr,"Usage: bridge monitor [file | link | fdb | mdb | vlan | vni | all]\n" );exit (-1 ); } +static int print_tunnel_rtm (struct nlmsghdr *n,void *arg,bool monitor) +{ +struct tunnel_msg *tmsg =NLMSG_DATA (n); + +if (tmsg->family ==PF_BRIDGE ) +return print_vnifilter_rtm (n, arg, monitor); + +return 0 ; +} +static int accept_msg (struct rtnl_ctrl_data *ctrl,struct nlmsghdr *n,void *arg) {
@@ -73,6 +83,12 @@ static int accept_msg(struct rtnl_ctrl_data *ctrl,fprintf (fp,"[VLAN]" );return print_vlan_rtm (n, arg, true, false); +case RTM_NEWTUNNEL : +case RTM_DELTUNNEL : +if (prefix_banner) +fprintf (fp,"[TUNNEL]" ); +return print_tunnel_rtm (n, arg, true); +default :return 0 ; }
@@ -86,6 +102,7 @@ int do_monitor(int argc, char **argv)int lneigh =0 ;int lmdb =0 ;int lvlan =0 ; +int lvni =0 ;rtnl_close (&rth);
@@ -105,9 +122,13 @@ int do_monitor(int argc, char **argv) }else if (matches (*argv,"vlan" ) ==0 ) { lvlan =1 ; groups =0 ; + }else if (strcmp (*argv,"vni" ) ==0 ) { + lvni =1 ; + groups =0 ; }else if (strcmp (*argv,"all" ) ==0 ) { groups = ~RTMGRP_TC ; lvlan =1 ; + lvni =1 ; prefix_banner =1 ; }else if (matches (*argv,"help" ) ==0 ) {usage ();
@@ -151,6 +172,11 @@ int do_monitor(int argc, char **argv)exit (1 ); } +if (lvni &&rtnl_add_nl_group (&rth,RTNLGRP_TUNNEL ) <0 ) { +fprintf (stderr,"Failed to add bridge vni group to list\n" ); +exit (1 ); + } +ll_init_map (&rth);if (rtnl_listen (&rth, accept_msg, stdout) <0 )
bridge/vni.c new file +380 -0
380 lines not on this page · raw message
include/libnetlink.h +8 -0
@@ -112,6 +112,9 @@ int rtnl_nexthop_bucket_dump_req(struct rtnl_handle *rth, int family, req_filter_fn_t filter_fn) __attribute__((warn_unused_result)); +int rtnl_tunneldump_req (struct rtnl_handle *rth,int family,int ifindex) + __attribute__((warn_unused_result)); +struct rtnl_ctrl_data {int nsid; };
@@ -331,6 +334,11 @@ int rtnl_from_file(FILE *, rtnl_listen_filter_t handler, ((struct rtattr *)(((char *)(r)) + NLMSG_ALIGN(sizeof(struct br_vlan_msg))))#endif +#ifndef TUNNEL_RTA +#define TUNNEL_RTA (r) \ + ((struct rtattr *)(((char *)(r)) + NLMSG_ALIGN(sizeof(struct tunnel_msg)))) +#endif +/* User defined nlmsg_type which is used mostly for logging netlink * messages from dump file */ #define NLMSG_TSTAMP 15
lib/libnetlink.c +18 -0
@@ -1609,3 +1609,21 @@ void nl_print_policy(const struct rtattr *attr, FILE *fp) } } } + +int rtnl_tunneldump_req (struct rtnl_handle *rth,int family,int ifindex) +{ +struct { +struct nlmsghdr nlh; +struct tunnel_msg tmsg; +char buf[256 ]; + } req = { + .nlh.nlmsg_len =NLMSG_LENGTH (sizeof (struct tunnel_msg )), + .nlh.nlmsg_type =RTM_GETTUNNEL , + .nlh.nlmsg_flags =NLM_F_DUMP |NLM_F_REQUEST , + .nlh.nlmsg_seq = rth->dump = ++rth->seq, + .tmsg.family = family, + .tmsg.ifindex = ifindex, + }; + +return send (rth->fd, &req,sizeof (req),0 ); +}
man/man8/bridge.8 +76 -1
101 lines not on this page · raw message
Signature · 1 line
2.25.1
Quoted 19 lines · Roopa Prabhu
This series adds bridge command to manage recently added vnifilter on a collect metadata vxlan (external) device. Also includes per vni stats support.
examples:
$bridge vni add dev vxlan0 vni 400$bridge vni add dev vxlan0 vni 200 group 239.1.1.101
$bridge vni del dev vxlan0 vni 400
$bridge vni show
$bridge -s vni show
Nikolay Aleksandrov (1):
bridge: vni: add support for stats dumping
Quoted 7 lines
Roopa Prabhu (2):
bridge: vxlan device vnifilter support
ip:iplink_vxlan: add support to set vnifiltering flag on vxlan devicev2 : replace matches by strcmp in
bridge/vni.c. v2 still uses matches iniplink_vxlan.cto match the rest of the code
fixed those as well and applied to iproute2-next. We are not taking any more uses of matches(), even for legacy commands.
This series was applied to iproute2/iproute2-next.git (main) by David Ahern <[email protected]>:
Hello:
This series was applied to iproute2/iproute2-next.git (main) by David Ahern <[email protected]>:
Quoted 9 lines · On Sun, 8 May 2022 04:53:37 +0000 you wrote:
This series adds bridge command to manage recently added vnifilter on a collect metadata vxlan (external) device. Also includes per vni stats support.
examples:
$bridge vni add dev vxlan0 vni 400[...]
Here is the summary with links:
- [iproute2,net-next,v2,1/3] bridge: vxlan device vnifilter support
https://git.kernel.org/pub/scm/network/iproute2/iproute2-next.git/commit/?id=45cd32f9f7d5 - [iproute2,net-next,v2,2/3] ip: iplink_vxlan: add support to set vnifiltering flag on vxlan device (no matching commit) - [iproute2,net-next,v2,3/3] bridge: vni: add support for stats dumping https://git.kernel.org/pub/scm/network/iproute2/iproute2-next.git/commit/?id=40b50f153c52
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html
Quoted 24 lines · David Ahern
Quoted 23 lines · Roopa Prabhu
This series adds bridge command to manage recently added vnifilter on a collect metadata vxlan (external) device. Also includes per vni stats support.
examples:
$bridge vni add dev vxlan0 vni 400$bridge vni add dev vxlan0 vni 200 group 239.1.1.101
$bridge vni del dev vxlan0 vni 400
$bridge vni show
$bridge -s vni show
Nikolay Aleksandrov (1):
bridge: vni: add support for stats dumpingRoopa Prabhu (2):
bridge: vxlan device vnifilter support
ip:iplink_vxlan: add support to set vnifiltering flag on vxlan device
Quoted 5 lines
Quoted 3 lines
v2 : replace matches by strcmp in
bridge/vni.c. v2 still uses matches iniplink_vxlan.cto match the rest of the codefixed those as well and applied to iproute2-next. We are not taking any more uses of
matches(), even for legacy commands.
ok, thank you.