ip, link: Add support for netkit
Subsystems (2)
PATCH v2 1/1 ip, link: Add support for netkit
Add base support for creating/dumping netkit devices.
Minimal example usage:
# ip link add type netkit
# ip -d a
[...]
7: nk0@nk1: <BROADCAST,MULTICAST,NOARP,M-DOWN> mtu 1500 qdisc noop state DOWN group default qlen 1000
link/ether 00:00:00:00:00:00 brd ff:ff:ff:ff:ff:ff promiscuity 0 allmulti 0 minmtu 68 maxmtu 65535
netkit mode l3 type peer policy forward numtxqueues 1 numrxqueues 1 [...]
8: nk1@nk0: <BROADCAST,MULTICAST,NOARP,M-DOWN> mtu 1500 qdisc noop state DOWN group default qlen 1000
link/ether 00:00:00:00:00:00 brd ff:ff:ff:ff:ff:ff promiscuity 0 allmulti 0 minmtu 68 maxmtu 65535
netkit mode l3 type primary policy forward numtxqueues 1 numrxqueues 1 [...]Example usage with netns (for BPF examples, see BPF selftests linked below):
# ip netns add blue # ip link add nk0 type netkit peer nk1 netns blue # ip link set up nk0 # ip addr add 10.0.0.1/24 dev nk0 # ip -n blue link set up nk1 # ip -n blue addr add 10.0.0.2/24 dev nk1 # ping -c1 10.0.0.2 PING 10.0.0.2 (10.0.0.2) 56(84) bytes of data. 64 bytes from 10.0.0.2: icmp_seq=1 ttl=64 time=0.021 ms
Example usage with L2 mode and peer blackholing when no BPF is attached:
# ip link add foo type netkit mode l2 forward peer blackhole bar
# ip -d a
[...]
13: bar@foo: <BROADCAST,MULTICAST,M-DOWN> mtu 1500 qdisc noop state DOWN group default qlen 1000
link/ether 5e:5b:81:17:02:27 brd ff:ff:ff:ff:ff:ff promiscuity 0 allmulti 0 minmtu 68 maxmtu 65535
netkit mode l2 type peer policy blackhole numtxqueues 1 numrxqueues 1 [...]
14: foo@bar: <BROADCAST,MULTICAST,M-DOWN> mtu 1500 qdisc noop state DOWN group default qlen 1000
link/ether de:01:a5:88:9e:99 brd ff:ff:ff:ff:ff:ff promiscuity 0 allmulti 0 minmtu 68 maxmtu 65535
netkit mode l2 type primary policy forward numtxqueues 1 numrxqueues 1 [...]---
[ Targetted for iproute2 6.7 release. ]
v1 -> v2:
- Add table-driven approach for netlink settings dump
- Remove matches, use strcmp
- Fix nit with braces
- Add maintainers entry
MAINTAINERS | 6 ++ ip/Makefile | 2 +- ip/iplink.c | 4 +- ip/iplink_netkit.c | 165 +++++++++++++++++++++++++++++++++++++++ man/man8/ip-address.8.in | 3 +- man/man8/ip-link.8.in | 44 +++++++++++ 6 files changed, 220 insertions(+), 4 deletions(-) create mode 100644 ip/iplink_netkit.c
MAINTAINERS +6 -0
@@ -39,6 +39,12 @@ devlink M: Jiri Pirko <[email protected]> F: devlink/* +netkit +M: Daniel Borkmann <[email protected]> +M: Nikolay Aleksandrov <[email protected]> +L: [email protected] +F: ip/iplink_netkit.c + Remote DMA - rdma M: Leon Romanovsky <[email protected]> F: rdma/*
ip/Makefile +1 -1
@@ -13,7 +13,7 @@ IPOBJ=ip.o ipaddress.o ipaddrlabel.o iproute.o iprule.o ipnetns.o \ ipvrf.o iplink_xstats.o ipseg6.o iplink_netdevsim.o iplink_rmnet.o \ ipnexthop.o ipmptcp.o iplink_bareudp.o iplink_wwan.o ipioam6.o \ iplink_amt.o iplink_batadv.o iplink_gtp.o iplink_virt_wifi.o \ - ipstats.o + iplink_netkit.o ipstats.o RTMONOBJ=rtmon.o
ip/iplink.c +2 -2
@@ -46,8 +46,8 @@ void iplink_types_usage(void)" dsa | dummy | erspan | geneve | gre | gretap | gtp | ifb |\n" " ip6erspan | ip6gre | ip6gretap | ip6tnl |\n" " ipip | ipoib | ipvlan | ipvtap |\n" -" macsec | macvlan | macvtap |\n" -" netdevsim | nlmon | rmnet | sit | team | team_slave |\n" +" macsec | macvlan | macvtap | netdevsim |\n" +" netkit | nlmon | rmnet | sit | team | team_slave |\n" " vcan | veth | vlan | vrf | vti | vxcan | vxlan | wwan |\n" " xfrm | virt_wifi }\n"); }
ip/iplink_netkit.c new file +165 -0
165 lines not on this page · raw message
man/man8/ip-address.8.in +2 -1
@@ -146,7 +146,8 @@ ip-address \- protocol address management .BR ipvlan " |" .BR lowpan " |" .BR geneve " |" -.BR macsec " ]" +.BR macsec " |" +.BR netkit " ]" .SH "DESCRIPTION" The
man/man8/ip-link.8.in +44 -0
62 lines not on this page · raw message
Signature · 1 line
2.34.1
Quoted 51 lines · Daniel Borkmann
Add base support for creating/dumping netkit devices.
Minimal example usage:
# ip link add type netkit # ip -d a [...] 7: nk0@nk1: <BROADCAST,MULTICAST,NOARP,M-DOWN> mtu 1500 qdisc noop state DOWN group default qlen 1000 link/ether 00:00:00:00:00:00 brd ff:ff:ff:ff:ff:ff promiscuity 0 allmulti 0 minmtu 68 maxmtu 65535 netkit mode l3 type peer policy forward numtxqueues 1 numrxqueues 1 [...] 8: nk1@nk0: <BROADCAST,MULTICAST,NOARP,M-DOWN> mtu 1500 qdisc noop state DOWN group default qlen 1000 link/ether 00:00:00:00:00:00 brd ff:ff:ff:ff:ff:ff promiscuity 0 allmulti 0 minmtu 68 maxmtu 65535 netkit mode l3 type primary policy forward numtxqueues 1 numrxqueues 1 [...]Example usage with netns (for BPF examples, see BPF selftests linked below):
# ip netns add blue # ip link add nk0 type netkit peer nk1 netns blue # ip link set up nk0 # ip addr add 10.0.0.1/24 dev nk0 # ip -n blue link set up nk1 # ip -n blue addr add 10.0.0.2/24 dev nk1 # ping -c1 10.0.0.2 PING 10.0.0.2 (10.0.0.2) 56(84) bytes of data. 64 bytes from 10.0.0.2: icmp_seq=1 ttl=64 time=0.021 msExample usage with L2 mode and peer blackholing when no BPF is attached:
# ip link add foo type netkit mode l2 forward peer blackhole bar # ip -d a [...] 13: bar@foo: <BROADCAST,MULTICAST,M-DOWN> mtu 1500 qdisc noop state DOWN group default qlen 1000 link/ether 5e:5b:81:17:02:27 brd ff:ff:ff:ff:ff:ff promiscuity 0 allmulti 0 minmtu 68 maxmtu 65535 netkit mode l2 type peer policy blackhole numtxqueues 1 numrxqueues 1 [...] 14: foo@bar: <BROADCAST,MULTICAST,M-DOWN> mtu 1500 qdisc noop state DOWN group default qlen 1000 link/ether de:01:a5:88:9e:99 brd ff:ff:ff:ff:ff:ff promiscuity 0 allmulti 0 minmtu 68 maxmtu 65535 netkit mode l2 type primary policy forward numtxqueues 1 numrxqueues 1 [...]Signed-off-by Daniel Borkmann <[email protected]>---
[ Targetted for iproute2 6.7 release. ]v1 -> v2:
- Add table-driven approach for netlink settings dump
- Remove matches, use strcmp
- Fix nit with braces
- Add maintainers entry
Quoted 9 lines
MAINTAINERS | 6 ++ ip/Makefile | 2 +- ip/iplink.c | 4 +- ip/iplink_netkit.c | 165 +++++++++++++++++++++++++++++++++++++++ man/man8/ip-address.8.in | 3 +- man/man8/ip-link.8.in | 44 +++++++++++ 6 files changed, 220 insertions(+), 4 deletions(-)create mode 100644
ip/iplink_netkit.c
Looks good to me,
ip/iplink_netkit.c line 137
Quoted 9 lines · On Mon, 20 Nov 2023 22:10:54 +0100 Daniel Borkmann <[email protected]> wrote:
ip/iplink_netkit.c new file +9
-0+static void netkit_print_opt (struct link_util *lu,FILE *f,struct rtattr *tb[]) +{ +if (!tb) +return ; +if (tb[IFLA_NETKIT_MODE ]) { +__u32 mode =rta_getattr_u32 (tb[IFLA_NETKIT_MODE ]); + +print_string (PRINT_ANY ,"mode" ,"mode %s " , + netkit_mode_strings[mode]);
What if kernel adds a new mode in future?
Probably want something like:
print_string(PRINT_ANY, "mode", "mode %s ", mode >= ARRAY_SIZE(netkit_mode_strings) ? "UNKNOWN" : netkit_mode_strings[mode]);
Quoted 16 lines · Stephen Hemminger
ip/iplink_netkit.c line 137
Quoted 9 lines · On Mon, 20 Nov 2023 22:10:54 +0100 Daniel Borkmann <[email protected]> wrote:
ip/iplink_netkit.c new file +9
-0+static void netkit_print_opt (struct link_util *lu,FILE *f,struct rtattr *tb[]) +{ +if (!tb) +return ; +if (tb[IFLA_NETKIT_MODE ]) { +__u32 mode =rta_getattr_u32 (tb[IFLA_NETKIT_MODE ]); + +print_string (PRINT_ANY ,"mode" ,"mode %s " , + netkit_mode_strings[mode]);What if kernel adds a new mode in future?
Probably want something like:
Quoted 2 lines
print_string(PRINT_ANY, "mode", "mode %s ", mode >= ARRAY_SIZE(netkit_mode_strings) ? "UNKNOWN" : netkit_mode_strings[mode]);
that is why I asked for a table driven helper. Helper handles the mode
Quoted 1 line
=
ARRAY_SIZE.
Quoted 17 lines · David Ahern
Quoted 16 lines · Stephen Hemminger
ip/iplink_netkit.c line 137
Quoted 9 lines · On Mon, 20 Nov 2023 22:10:54 +0100 Daniel Borkmann <[email protected]> wrote:
ip/iplink_netkit.c new file +9
-0+static void netkit_print_opt (struct link_util *lu,FILE *f,struct rtattr *tb[]) +{ +if (!tb) +return ; +if (tb[IFLA_NETKIT_MODE ]) { +__u32 mode =rta_getattr_u32 (tb[IFLA_NETKIT_MODE ]); + +print_string (PRINT_ANY ,"mode" ,"mode %s " , + netkit_mode_strings[mode]);What if kernel adds a new mode in future?
Probably want something like:
Quoted 4 lines
Quoted 2 lines
print_string(PRINT_ANY, "mode", "mode %s ", mode >= ARRAY_SIZE(netkit_mode_strings) ? "UNKNOWN" : netkit_mode_strings[mode]);that is why I asked for a table driven helper. Helper handles the mode
Ok, fair, will add.
Thanks,
Daniel