Skip to contentSkip to conversation

ip: Support filter links/neighs with no master

PATCH Superseded Lahav Schlesinger 2 participants 4 messages Aug 19, 2021 – Aug 24, 2021

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ip: Support filter links/neighs with no master

Commit d3432bf10f17 ("net: Support filtering interfaces on no master") in the kernel added support for filtering interfaces/neighbours that have no master interface.

This patch completes it and adds this support to iproute2:
1. ip link show nomaster
2. ip address show nomaster
3. ip neighbour {show | flush} nomaster

---
 ip/ipaddress.c           | 4 +++-
 ip/iplink.c              | 2 +-
 ip/ipneigh.c             | 4 +++-
 man/man8/ip-address.8.in | 7 ++++++-
 man/man8/ip-link.8.in    | 7 ++++++-
 man/man8/ip-neighbour.8  | 7 ++++++-
 6 files changed, 25 insertions(+), 6 deletions(-)
ip/ipaddress.c +3 -1
index 85534aaf..a5b683f5 100644
@@ -61,7 +61,7 @@ static void usage(void)
 		"                            [ to PREFIX ] [ FLAG-LIST ] [ label LABEL ] [up]\n"
 		"       ip address [ show [ dev IFNAME ] [ scope SCOPE-ID ] [ master DEVICE ]\n"
 		"                         [ type TYPE ] [ to PREFIX ] [ FLAG-LIST ]\n"
-		"                         [ label LABEL ] [up] [ vrf NAME ] ]\n"
+		"                         [ label LABEL ] [up] [ vrf NAME ] [ nomaster ] ]\n"
 		"       ip address {showdump|restore}\n"
 		"IFADDR := PREFIX | ADDR peer PREFIX\n"
 		"          [ broadcast ADDR ] [ anycast ADDR ]\n"
@@ -2123,6 +2123,8 @@ static int ipaddr_list_flush_or_save(int argc, char **argv, int action)
 			if (!name_is_vrf(*argv))
 				invarg("Not a valid VRF name\n", *argv);
 			filter.master = ifindex;
+		} else if (strcmp(*argv, "nomaster") == 0) {
+			filter.master = -1;
 		} else if (strcmp(*argv, "type") == 0) {
 			int soff;
 
ip/iplink.c +1 -1
index 18b2ea25..f017f1f3 100644
@@ -119,7 +119,7 @@ void iplink_usage(void)
 		"		[ protodown_reason PREASON { on | off } ]\n"
 		"		[ gso_max_size BYTES ] | [ gso_max_segs PACKETS ]\n"
 		"\n"
-		"	ip link show [ DEVICE | group GROUP ] [up] [master DEV] [vrf NAME] [type TYPE]\n"
+		"	ip link show [ DEVICE | group GROUP ] [up] [master DEV] [vrf NAME] [type TYPE] [nomaster]\n"
 		"\n"
 		"	ip link xstats type TYPE [ ARGS ]\n"
 		"\n"
ip/ipneigh.c +3 -1
index 95bde520..b4a2f6df 100644
@@ -54,7 +54,7 @@ static void usage(void)
 		"		[ dev DEV ] [ router ] [ extern_learn ] [ protocol PROTO ]\n"
 		"\n"
 		"	ip neigh { show | flush } [ proxy ] [ to PREFIX ] [ dev DEV ] [ nud STATE ]\n"
-		"				  [ vrf NAME ]\n"
+		"				  [ vrf NAME ] [ nomaster ]\n"
 		"	ip neigh get { ADDR | proxy ADDR } dev DEV\n"
 		"\n"
 		"STATE := { delay | failed | incomplete | noarp | none |\n"
@@ -536,6 +536,8 @@ static int do_show_or_flush(int argc, char **argv, int flush)
 			if (!name_is_vrf(*argv))
 				invarg("Not a valid VRF name\n", *argv);
 			filter.master = ifindex;
+		} else if (strcmp(*argv, "nomaster") == 0) {
+			filter.master = -1;
 		} else if (strcmp(*argv, "unused") == 0) {
 			filter.unused_only = 1;
 		} else if (strcmp(*argv, "nud") == 0) {
man/man8/ip-address.8.in +6 -1
index fe773c91..65f67e06 100644
@@ -49,7 +49,8 @@ ip-address \- protocol address management
 .IR TYPE " ] [ "
 .B vrf
 .IR NAME " ] [ "
-.BR up " ] ]"
+.BR up " ] ["
+.BR nomaster " ] ]"
 
 .ti -8
 .BR "ip address" " { " showdump " | " restore " }"
@@ -340,6 +341,10 @@ output.
 .B up
 only list running interfaces.
 
+.TP
+.B nomaster
+only list interfaces with no master.
+
 .TP
 .BR dynamic " and " permanent
 (IPv6 only) only list addresses installed due to stateless
man/man8/ip-link.8.in +6 -1
index 572bed87..e749f23d 100644
@@ -179,7 +179,8 @@ ip-link \- network device configuration
 .B type
 .IR ETYPE " ] ["
 .B vrf
-.IR NAME " ]"
+.IR NAME " ] ["
+.BR nomaster " ]"
 
 .ti -8
 .B ip link xstats
@@ -2528,6 +2529,10 @@ interface list by comparing it with the relevant attribute in case the kernel
 didn't filter already. Therefore any string is accepted, but may lead to empty
 output.
 
+.TP
+.B nomaster
+only show devices with no master
+
 .SS  ip link xstats - display extended statistics
 
 .TP
man/man8/ip-neighbour.8 +6 -1
index a27f9ef8..02862964 100644
@@ -35,7 +35,8 @@ ip-neighbour \- neighbour/arp tables management.
 .B  nud
 .IR STATE " ] [ "
 .B  vrf
-.IR NAME " ] "
+.IR NAME " ] ["
+.BR nomaster " ]"
 
 .ti -8
 .B ip neigh get
@@ -191,6 +192,10 @@ only list the neighbours attached to this device.
 .BI vrf " NAME"
 only list the neighbours for given VRF.
 
+.TP
+.BI nomaster
+only list neighbours attached to an interface with no master.
+
 .TP
 .BI proxy
 list neighbour proxies.
Signature · 1 line
2.25.1
#1 lore raw
Quoted 24 lines · Lahav Schlesinger

Commit d3432bf10f17 ("net: Support filtering interfaces on no master") in the kernel added support for filtering interfaces/neighbours that have no master interface.

This patch completes it and adds this support to iproute2:
1. ip link show nomaster
2. ip address show nomaster
3. ip neighbour {show | flush} nomaster

---
 ip/ipaddress.c           | 4 +++-
 ip/iplink.c              | 2 +-
 ip/ipneigh.c             | 4 +++-
 man/man8/ip-address.8.in | 7 ++++++-
 man/man8/ip-link.8.in    | 7 ++++++-
 man/man8/ip-neighbour.8  | 7 ++++++-
 6 files changed, 25 insertions(+), 6 deletions(-)
ip/ipaddress.c +0 -0
index 85534aaf..a5b683f5 100644

ip/ipaddress.c static void usage(void) · line 62

Quoted 2 lines
ip/ipaddress.c +0 -0
@@ -61,7 +61,7 @@ static void usage(void)
 		"                            [ to PREFIX ] [ FLAG-LIST ] [ label LABEL ] [up]\n"
 		"       ip address [ show [ dev IFNAME ] [ scope SCOPE-ID ] [ master DEVICE ]\n"

move [ nomaster ] to here on a new line to keep the existing line length, and

ip/ipaddress.c static void usage(void) · line 64

Quoted 3 lines
ip/ipaddress.c +1 -1
 		"                         [ type TYPE ] [ to PREFIX ] [ FLAG-LIST ]\n"
-		"                         [ label LABEL ] [up] [ vrf NAME ] ]\n"
+		"                         [ label LABEL ] [up] [ vrf NAME ] [ nomaster ] ]\n"

make this 'novrf' for consistency with existing syntax.

Similarly for the other 2 commands.

ip/ipaddress.c static int ipaddr_list_flush_or_save(int argc, char **argv, int action) · line 2126

Quoted 8 lines
ip/ipaddress.c +1 -0
 		"       ip address {showdump|restore}\n"
 		"IFADDR := PREFIX | ADDR peer PREFIX\n"
 		"          [ broadcast ADDR ] [ anycast ADDR ]\n"
@@ -2123,6 +2123,8 @@ static int ipaddr_list_flush_or_save(int argc, char **argv, int action)
 			if (!name_is_vrf(*argv))
 				invarg("Not a valid VRF name\n", *argv);
 			filter.master = ifindex;
+		} else if (strcmp(*argv, "nomaster") == 0) {

and of course make this a compound check for novrf.

Quoted 9 lines
ip/ipaddress.c +1 -0
+			filter.master = -1;
 		} else if (strcmp(*argv, "type") == 0) {
 			int soff;
 
ip/iplink.c +0 -0
index 18b2ea25..f017f1f3 100644

ip/iplink.c void iplink_usage(void) · line 122

Quoted 5 lines
ip/iplink.c +1 -1
@@ -119,7 +119,7 @@ void iplink_usage(void)
 		"		[ protodown_reason PREASON { on | off } ]\n"
 		"		[ gso_max_size BYTES ] | [ gso_max_segs PACKETS ]\n"
 		"\n"
-		"	ip link show [ DEVICE | group GROUP ] [up] [master DEV] [vrf NAME] [type TYPE]\n"
+		"	ip link show [ DEVICE | group GROUP ] [up] [master DEV] [vrf NAME] [type TYPE] [nomaster]\n"

this line is already too long so add the new options on a new line.

Quoted 25 lines
ip/iplink.c +0 -0
 		"\n"
 		"	ip link xstats type TYPE [ ARGS ]\n"
 		"\n"
ip/ipneigh.c +3 -1
index 95bde520..b4a2f6df 100644
@@ -54,7 +54,7 @@ static void usage(void)
 		"		[ dev DEV ] [ router ] [ extern_learn ] [ protocol PROTO ]\n"
 		"\n"
 		"	ip neigh { show | flush } [ proxy ] [ to PREFIX ] [ dev DEV ] [ nud STATE ]\n"
-		"				  [ vrf NAME ]\n"
+		"				  [ vrf NAME ] [ nomaster ]\n"
 		"	ip neigh get { ADDR | proxy ADDR } dev DEV\n"
 		"\n"
 		"STATE := { delay | failed | incomplete | noarp | none |\n"
@@ -536,6 +536,8 @@ static int do_show_or_flush(int argc, char **argv, int flush)
 			if (!name_is_vrf(*argv))
 				invarg("Not a valid VRF name\n", *argv);
 			filter.master = ifindex;
+		} else if (strcmp(*argv, "nomaster") == 0) {
+			filter.master = -1;
 		} else if (strcmp(*argv, "unused") == 0) {
 			filter.unused_only = 1;
 		} else if (strcmp(*argv, "nud") == 0) {
#2 lore raw
Quoted 34 lines · David Ahern

CAUTION: External E-Mail - Use caution with links and attachments

Quoted 24 lines · Lahav Schlesinger

Commit d3432bf10f17 ("net: Support filtering interfaces on no master") in the kernel added support for filtering interfaces/neighbours that have no master interface.

This patch completes it and adds this support to iproute2:
1. ip link show nomaster
2. ip address show nomaster
3. ip neighbour {show | flush} nomaster

---
 ip/ipaddress.c           | 4 +++-
 ip/iplink.c              | 2 +-
 ip/ipneigh.c             | 4 +++-
 man/man8/ip-address.8.in | 7 ++++++-
 man/man8/ip-link.8.in    | 7 ++++++-
 man/man8/ip-neighbour.8  | 7 ++++++-
 6 files changed, 25 insertions(+), 6 deletions(-)
ip/ipaddress.c +0 -0
index 85534aaf..a5b683f5 100644

ip/ipaddress.c static void usage(void) · line 62

Quoted 2 lines
ip/ipaddress.c +0 -0
@@ -61,7 +61,7 @@ static void usage(void)
              "                            [ to PREFIX ] [ FLAG-LIST ] [ label LABEL ] [up]\n"
              "       ip address [ show [ dev IFNAME ] [ scope SCOPE-ID ] [ master DEVICE ]\n"

move [ nomaster ] to here on a new line to keep the existing line length, and

Quoted 7 lines

ip/ipaddress.c static void usage(void) · line 64

Quoted 3 lines
ip/ipaddress.c +1 -1
              "                         [ type TYPE ] [ to PREFIX ] [ FLAG-LIST ]\n"
-             "                         [ label LABEL ] [up] [ vrf NAME ] ]\n"
+             "                         [ label LABEL ] [up] [ vrf NAME ] [ nomaster ] ]\n"

make this 'novrf' for consistency with existing syntax.

Similarly for the other 2 commands.

I think "nomaster" is more fitting here, because this option only affects interfaces that have no master at all, so e.g. slaves of a bundle will not be returned by the "nomaster" option, even if they are in the default VRF.

I'm planning next to add support for the "novrf" option which will indeed only affect interfaces which are in the default VRF, even if they have a master.

Quoted 56 lines

ip/ipaddress.c static int ipaddr_list_flush_or_save(int argc, char **argv, int action) · line 2126

Quoted 9 lines
ip/ipaddress.c +1 -0
              "       ip address {showdump|restore}\n"
              "IFADDR := PREFIX | ADDR peer PREFIX\n"
              "          [ broadcast ADDR ] [ anycast ADDR ]\n"
@@ -2123,6 +2123,8 @@ static int ipaddr_list_flush_or_save(int argc, char **argv, int action)
                      if (!name_is_vrf(*argv))
                              invarg("Not a valid VRF name\n", *argv);
                      filter.master = ifindex;
+             } else if (strcmp(*argv, "nomaster") == 0) {

and of course make this a compound check for novrf.

Quoted 9 lines
ip/ipaddress.c +1 -0
+                     filter.master = -1;
              } else if (strcmp(*argv, "type") == 0) {
                      int soff;
 
ip/iplink.c +0 -0
index 18b2ea25..f017f1f3 100644

ip/iplink.c void iplink_usage(void) · line 122

Quoted 5 lines
ip/iplink.c +1 -1
@@ -119,7 +119,7 @@ void iplink_usage(void)
              "               [ protodown_reason PREASON { on | off } ]\n"
              "               [ gso_max_size BYTES ] | [ gso_max_segs PACKETS ]\n"
              "\n"
-             "       ip link show [ DEVICE | group GROUP ] [up] [master DEV] [vrf NAME] [type TYPE]\n"
+             "       ip link show [ DEVICE | group GROUP ] [up] [master DEV] [vrf NAME] [type TYPE] [nomaster]\n"

this line is already too long so add the new options on a new line.

Quoted 25 lines
ip/iplink.c +0 -0
              "\n"
              "       ip link xstats type TYPE [ ARGS ]\n"
              "\n"
ip/ipneigh.c +3 -1
index 95bde520..b4a2f6df 100644
@@ -54,7 +54,7 @@ static void usage(void)
              "               [ dev DEV ] [ router ] [ extern_learn ] [ protocol PROTO ]\n"
              "\n"
              "       ip neigh { show | flush } [ proxy ] [ to PREFIX ] [ dev DEV ] [ nud STATE ]\n"
-             "                                 [ vrf NAME ]\n"
+             "                                 [ vrf NAME ] [ nomaster ]\n"
              "       ip neigh get { ADDR | proxy ADDR } dev DEV\n"
              "\n"
              "STATE := { delay | failed | incomplete | noarp | none |\n"
@@ -536,6 +536,8 @@ static int do_show_or_flush(int argc, char **argv, int flush)
                      if (!name_is_vrf(*argv))
                              invarg("Not a valid VRF name\n", *argv);
                      filter.master = ifindex;
+             } else if (strcmp(*argv, "nomaster") == 0) {
+                     filter.master = -1;
              } else if (strcmp(*argv, "unused") == 0) {
                      filter.unused_only = 1;
              } else if (strcmp(*argv, "nud") == 0) {
#3 lore raw
Quoted 15 lines · Lahav Schlesinger
Quoted 15 lines

ip/ipaddress.c static void usage(void) · line 62

Quoted 7 lines
ip/ipaddress.c +0 -0
index 85534aaf..a5b683f5 100644
@@ -61,7 +61,7 @@ static void usage(void)
              "                            [ to PREFIX ] [ FLAG-LIST ] [ label LABEL ] [up]\n"
              "       ip address [ show [ dev IFNAME ] [ scope SCOPE-ID ] [ master DEVICE ]\n"

move [ nomaster ] to here on a new line to keep the existing line length, and

Quoted 3 lines
ip/ipaddress.c +1 -1
              "                         [ type TYPE ] [ to PREFIX ] [ FLAG-LIST ]\n"
-             "                         [ label LABEL ] [up] [ vrf NAME ] ]\n"
+             "                         [ label LABEL ] [up] [ vrf NAME ] [ nomaster ] ]\n"
Quoted 7 lines
Quoted 3 lines

make this 'novrf' for consistency with existing syntax.

Similarly for the other 2 commands.

I think "nomaster" is more fitting here, because this option only affects interfaces that have no master at all, so e.g. slaves of a bundle will not be returned by the "nomaster" option, even if they are in the default VRF.

I was thinking both - 'nomaster' for bridges and 'novrf' for VRFs. Just friendlier syntax for the latter.

Quoted 4 lines

I'm planning next to add support for the "novrf" option which will indeed only affect interfaces which are in the default VRF, even if they have a master.

ok,