All of lore.kernel.org
 help / color / mirror / Atom feed
* [iproute2 net-next v2 0/3] ip netconf improvements
@ 2017-03-24  2:51 David Ahern
  2017-03-24  2:51 ` [iproute2 net-next v2 1/3] netlink: Add flag to suppress print of nlmsg error David Ahern
                   ` (5 more replies)
  0 siblings, 6 replies; 9+ messages in thread
From: David Ahern @ 2017-03-24  2:51 UTC (permalink / raw)
  To: netdev, stephen; +Cc: nicolas.dichtel, David Ahern

Currently, ip netconf only shows data for ipv4 and ipv6 for dumps
and just ipv4 for device requests. Improve the user experience by
using the new kernel patch to dump all address families that have
registered. For example, if mpls_router module is loaded then mpls
values are displayed along with ipv4 and ipv6.

If the new feature is not supported (new iproute2 on older kernel)
the kernel returns the nlmsg error EOPNOTSUPP which can be trapped
and fallback to existing behavior.

v2
- fixed index conversion in patch 3 per nicholas' comment

David Ahern (3):
  netlink: Add flag to suppress print of nlmsg error
  ip netconf: Show all address families by default in dumps
  ip netconf: show all families on dev request

 include/libnetlink.h |  1 +
 ip/ipnetconf.c       | 36 +++++++++++++++++++++++++-----------
 lib/libnetlink.c     |  3 ++-
 3 files changed, 28 insertions(+), 12 deletions(-)

-- 
2.1.4

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [iproute2 net-next v2 1/3] netlink: Add flag to suppress print of nlmsg error
  2017-03-24  2:51 [iproute2 net-next v2 0/3] ip netconf improvements David Ahern
@ 2017-03-24  2:51 ` David Ahern
  2017-03-24  2:51 ` [iproute2 net-next v2 2/3] ip netconf: Show all address families by default in dumps David Ahern
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 9+ messages in thread
From: David Ahern @ 2017-03-24  2:51 UTC (permalink / raw)
  To: netdev, stephen; +Cc: nicolas.dichtel, David Ahern

Allow callers of the dump API to handle nlmsg errors (e.g., an
unsupported feature). Setting RTNL_HANDLE_F_SUPPRESS_NLERR in the
rtnl_handle avoids unnecessary messages to the users in some case.
For example,

  RTNETLINK answers: Operation not supported

when probing for support of a new feature.

Signed-off-by: David Ahern <dsa@cumulusnetworks.com>
---
 include/libnetlink.h | 1 +
 lib/libnetlink.c     | 3 ++-
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/include/libnetlink.h b/include/libnetlink.h
index bd0267dfcc02..c43ab0a2d9d9 100644
--- a/include/libnetlink.h
+++ b/include/libnetlink.h
@@ -21,6 +21,7 @@ struct rtnl_handle {
 	int			proto;
 	FILE		       *dump_fp;
 #define RTNL_HANDLE_F_LISTEN_ALL_NSID		0x01
+#define RTNL_HANDLE_F_SUPPRESS_NLERR		0x02
 	int			flags;
 };
 
diff --git a/lib/libnetlink.c b/lib/libnetlink.c
index 9303b6686e2c..5b75b2db4e0b 100644
--- a/lib/libnetlink.c
+++ b/lib/libnetlink.c
@@ -299,7 +299,8 @@ static void rtnl_dump_error(const struct rtnl_handle *rth,
 		     errno == EOPNOTSUPP))
 			return;
 
-		perror("RTNETLINK answers");
+		if (!(rth->flags & RTNL_HANDLE_F_SUPPRESS_NLERR))
+			perror("RTNETLINK answers");
 	}
 }
 
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [iproute2 net-next v2 2/3] ip netconf: Show all address families by default in dumps
  2017-03-24  2:51 [iproute2 net-next v2 0/3] ip netconf improvements David Ahern
  2017-03-24  2:51 ` [iproute2 net-next v2 1/3] netlink: Add flag to suppress print of nlmsg error David Ahern
@ 2017-03-24  2:51 ` David Ahern
  2017-03-24  2:51 ` [iproute2 net-next v2 3/3] ip netconf: show all families on dev request David Ahern
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 9+ messages in thread
From: David Ahern @ 2017-03-24  2:51 UTC (permalink / raw)
  To: netdev, stephen; +Cc: nicolas.dichtel, David Ahern

Currently, 'ip netconf' only shows ipv4 and ipv6 netconf settings. If IPv6
is not enabled, the dump ends with
    RTNETLINK answers: Operation not supported

when IPv6 request is attempted. Further, if the mpls_router module is also
loaded a separate request is needed to get MPLS settings.

To make this better going forward, use the new PF_UNSPEC dump all option
if the kernel supports it. If the kernel does not, it sets NLMSG_ERROR and
returns EOPNOTSUPP which is trapped and we fall back to the existing output
to maintain compatibility with existing kernels.

Signed-off-by: David Ahern <dsa@cumulusnetworks.com>
---
 ip/ipnetconf.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/ip/ipnetconf.c b/ip/ipnetconf.c
index af539f5e945c..dc0851025223 100644
--- a/ip/ipnetconf.c
+++ b/ip/ipnetconf.c
@@ -19,6 +19,7 @@
 #include <sys/time.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
+#include <errno.h>
 
 #include "rt_names.h"
 #include "utils.h"
@@ -197,16 +198,26 @@ static int do_show(int argc, char **argv)
 		}
 		rtnl_listen(&rth, print_netconf, stdout);
 	} else {
+		rth.flags = RTNL_HANDLE_F_SUPPRESS_NLERR;
 dump:
 		if (rtnl_wilddump_request(&rth, filter.family, RTM_GETNETCONF) < 0) {
 			perror("Cannot send dump request");
 			exit(1);
 		}
 		if (rtnl_dump_filter(&rth, print_netconf2, stdout) < 0) {
+			/* kernel does not support netconf dump on AF_UNSPEC;
+			 * fall back to requesting by family
+			 */
+			if (errno == EOPNOTSUPP &&
+			    filter.family == AF_UNSPEC) {
+				filter.family = AF_INET;
+				goto dump;
+			}
+			perror("RTNETLINK answers");
 			fprintf(stderr, "Dump terminated\n");
 			exit(1);
 		}
-		if (preferred_family == AF_UNSPEC) {
+		if (preferred_family == AF_UNSPEC && filter.family == AF_INET) {
 			preferred_family = AF_INET6;
 			filter.family = AF_INET6;
 			goto dump;
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [iproute2 net-next v2 3/3] ip netconf: show all families on dev request
  2017-03-24  2:51 [iproute2 net-next v2 0/3] ip netconf improvements David Ahern
  2017-03-24  2:51 ` [iproute2 net-next v2 1/3] netlink: Add flag to suppress print of nlmsg error David Ahern
  2017-03-24  2:51 ` [iproute2 net-next v2 2/3] ip netconf: Show all address families by default in dumps David Ahern
@ 2017-03-24  2:51 ` David Ahern
  2017-03-24  8:37 ` [iproute2 net-next v2 0/3] ip netconf improvements Nicolas Dichtel
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 9+ messages in thread
From: David Ahern @ 2017-03-24  2:51 UTC (permalink / raw)
  To: netdev, stephen; +Cc: nicolas.dichtel, David Ahern

Currently specifying a device to ip netconf and it dumps only values
for IPv4. Change this to dump data for all families unless a specific
family is given.

Signed-off-by: David Ahern <dsa@cumulusnetworks.com>
---
 ip/ipnetconf.c | 23 +++++++++++++----------
 1 file changed, 13 insertions(+), 10 deletions(-)

diff --git a/ip/ipnetconf.c b/ip/ipnetconf.c
index dc0851025223..696e3dd51a1c 100644
--- a/ip/ipnetconf.c
+++ b/ip/ipnetconf.c
@@ -56,6 +56,7 @@ int print_netconf(const struct sockaddr_nl *who, struct rtnl_ctrl_data *ctrl,
 	struct netconfmsg *ncm = NLMSG_DATA(n);
 	int len = n->nlmsg_len;
 	struct rtattr *tb[NETCONFA_MAX+1];
+	int ifindex = 0;
 
 	if (n->nlmsg_type == NLMSG_ERROR)
 		return -1;
@@ -77,6 +78,12 @@ int print_netconf(const struct sockaddr_nl *who, struct rtnl_ctrl_data *ctrl,
 	parse_rtattr(tb, NETCONFA_MAX, netconf_rta(ncm),
 		     NLMSG_PAYLOAD(n, sizeof(*ncm)));
 
+	if (tb[NETCONFA_IFINDEX])
+		ifindex = rta_getattr_u32(tb[NETCONFA_IFINDEX]);
+
+	if (filter.ifindex && filter.ifindex != ifindex)
+		return 0;
+
 	switch (ncm->ncm_family) {
 	case AF_INET:
 		fprintf(fp, "ipv4 ");
@@ -93,9 +100,7 @@ int print_netconf(const struct sockaddr_nl *who, struct rtnl_ctrl_data *ctrl,
 	}
 
 	if (tb[NETCONFA_IFINDEX]) {
-		int *ifindex = (int *)rta_getattr_str(tb[NETCONFA_IFINDEX]);
-
-		switch (*ifindex) {
+		switch (ifindex) {
 		case NETCONFA_IFINDEX_ALL:
 			fprintf(fp, "all ");
 			break;
@@ -103,7 +108,7 @@ int print_netconf(const struct sockaddr_nl *who, struct rtnl_ctrl_data *ctrl,
 			fprintf(fp, "default ");
 			break;
 		default:
-			fprintf(fp, "dev %s ", ll_index_to_name(*ifindex));
+			fprintf(fp, "dev %s ", ll_index_to_name(ifindex));
 			break;
 		}
 	}
@@ -169,8 +174,6 @@ static int do_show(int argc, char **argv)
 
 	ipnetconf_reset_filter(0);
 	filter.family = preferred_family;
-	if (filter.family == AF_UNSPEC)
-		filter.family = AF_INET;
 
 	while (argc > 0) {
 		if (strcmp(*argv, "dev") == 0) {
@@ -186,11 +189,11 @@ static int do_show(int argc, char **argv)
 	}
 
 	ll_init_map(&rth);
-	if (filter.ifindex) {
+
+	if (filter.ifindex && filter.family != AF_UNSPEC) {
 		req.ncm.ncm_family = filter.family;
-		if (filter.ifindex)
-			addattr_l(&req.n, sizeof(req), NETCONFA_IFINDEX,
-				  &filter.ifindex, sizeof(filter.ifindex));
+		addattr_l(&req.n, sizeof(req), NETCONFA_IFINDEX,
+			  &filter.ifindex, sizeof(filter.ifindex));
 
 		if (rtnl_send(&rth, &req.n, req.n.nlmsg_len) < 0) {
 			perror("Can not send request");
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [iproute2 net-next v2 0/3] ip netconf improvements
  2017-03-24  2:51 [iproute2 net-next v2 0/3] ip netconf improvements David Ahern
                   ` (2 preceding siblings ...)
  2017-03-24  2:51 ` [iproute2 net-next v2 3/3] ip netconf: show all families on dev request David Ahern
@ 2017-03-24  8:37 ` Nicolas Dichtel
  2017-04-04 21:07 ` David Ahern
  2017-04-14 23:02 ` Stephen Hemminger
  5 siblings, 0 replies; 9+ messages in thread
From: Nicolas Dichtel @ 2017-03-24  8:37 UTC (permalink / raw)
  To: David Ahern, netdev, stephen

Le 24/03/2017 à 03:51, David Ahern a écrit :
> Currently, ip netconf only shows data for ipv4 and ipv6 for dumps
> and just ipv4 for device requests. Improve the user experience by
> using the new kernel patch to dump all address families that have
> registered. For example, if mpls_router module is loaded then mpls
> values are displayed along with ipv4 and ipv6.
> 
> If the new feature is not supported (new iproute2 on older kernel)
> the kernel returns the nlmsg error EOPNOTSUPP which can be trapped
> and fallback to existing behavior.
Acked-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [iproute2 net-next v2 0/3] ip netconf improvements
  2017-03-24  2:51 [iproute2 net-next v2 0/3] ip netconf improvements David Ahern
                   ` (3 preceding siblings ...)
  2017-03-24  8:37 ` [iproute2 net-next v2 0/3] ip netconf improvements Nicolas Dichtel
@ 2017-04-04 21:07 ` David Ahern
  2017-04-04 21:39   ` Stephen Hemminger
  2017-04-14 23:02 ` Stephen Hemminger
  5 siblings, 1 reply; 9+ messages in thread
From: David Ahern @ 2017-04-04 21:07 UTC (permalink / raw)
  To: netdev, stephen; +Cc: nicolas.dichtel

On 3/23/17 10:51 PM, David Ahern wrote:
> Currently, ip netconf only shows data for ipv4 and ipv6 for dumps
> and just ipv4 for device requests. Improve the user experience by
> using the new kernel patch to dump all address families that have
> registered. For example, if mpls_router module is loaded then mpls
> values are displayed along with ipv4 and ipv6.
> 
> If the new feature is not supported (new iproute2 on older kernel)
> the kernel returns the nlmsg error EOPNOTSUPP which can be trapped
> and fallback to existing behavior.
> 
> v2
> - fixed index conversion in patch 3 per nicholas' comment
> 
> David Ahern (3):
>   netlink: Add flag to suppress print of nlmsg error
>   ip netconf: Show all address families by default in dumps
>   ip netconf: show all families on dev request
> 
>  include/libnetlink.h |  1 +
>  ip/ipnetconf.c       | 36 +++++++++++++++++++++++++-----------
>  lib/libnetlink.c     |  3 ++-
>  3 files changed, 28 insertions(+), 12 deletions(-)
> 

Hi Stephen: any comments? are you ok with this change?

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [iproute2 net-next v2 0/3] ip netconf improvements
  2017-04-04 21:07 ` David Ahern
@ 2017-04-04 21:39   ` Stephen Hemminger
  2017-04-05 12:18     ` David Ahern
  0 siblings, 1 reply; 9+ messages in thread
From: Stephen Hemminger @ 2017-04-04 21:39 UTC (permalink / raw)
  To: David Ahern; +Cc: netdev, nicolas.dichtel

On Tue, 4 Apr 2017 17:07:31 -0400
David Ahern <dsa@cumulusnetworks.com> wrote:

> On 3/23/17 10:51 PM, David Ahern wrote:
> > Currently, ip netconf only shows data for ipv4 and ipv6 for dumps
> > and just ipv4 for device requests. Improve the user experience by
> > using the new kernel patch to dump all address families that have
> > registered. For example, if mpls_router module is loaded then mpls
> > values are displayed along with ipv4 and ipv6.
> > 
> > If the new feature is not supported (new iproute2 on older kernel)
> > the kernel returns the nlmsg error EOPNOTSUPP which can be trapped
> > and fallback to existing behavior.
> > 
> > v2
> > - fixed index conversion in patch 3 per nicholas' comment
> > 
> > David Ahern (3):
> >   netlink: Add flag to suppress print of nlmsg error
> >   ip netconf: Show all address families by default in dumps
> >   ip netconf: show all families on dev request
> > 
> >  include/libnetlink.h |  1 +
> >  ip/ipnetconf.c       | 36 +++++++++++++++++++++++++-----------
> >  lib/libnetlink.c     |  3 ++-
> >  3 files changed, 28 insertions(+), 12 deletions(-)
> >   
> 
> Hi Stephen: any comments? are you ok with this change?

I was holding off until all the upstream commits went through. Other than
that fine.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [iproute2 net-next v2 0/3] ip netconf improvements
  2017-04-04 21:39   ` Stephen Hemminger
@ 2017-04-05 12:18     ` David Ahern
  0 siblings, 0 replies; 9+ messages in thread
From: David Ahern @ 2017-04-05 12:18 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: netdev, nicolas.dichtel

On 4/4/17 5:39 PM, Stephen Hemminger wrote:
> On Tue, 4 Apr 2017 17:07:31 -0400
> David Ahern <dsa@cumulusnetworks.com> wrote:
> 
>> On 3/23/17 10:51 PM, David Ahern wrote:
>>> Currently, ip netconf only shows data for ipv4 and ipv6 for dumps
>>> and just ipv4 for device requests. Improve the user experience by
>>> using the new kernel patch to dump all address families that have
>>> registered. For example, if mpls_router module is loaded then mpls
>>> values are displayed along with ipv4 and ipv6.
>>>
>>> If the new feature is not supported (new iproute2 on older kernel)
>>> the kernel returns the nlmsg error EOPNOTSUPP which can be trapped
>>> and fallback to existing behavior.
>>>
>>> v2
>>> - fixed index conversion in patch 3 per nicholas' comment
>>>
>>> David Ahern (3):
>>>   netlink: Add flag to suppress print of nlmsg error
>>>   ip netconf: Show all address families by default in dumps
>>>   ip netconf: show all families on dev request
>>>
>>>  include/libnetlink.h |  1 +
>>>  ip/ipnetconf.c       | 36 +++++++++++++++++++++++++-----------
>>>  lib/libnetlink.c     |  3 ++-
>>>  3 files changed, 28 insertions(+), 12 deletions(-)
>>>   
>>
>> Hi Stephen: any comments? are you ok with this change?
> 
> I was holding off until all the upstream commits went through. Other than
> that fine.
> 

I'm not aware of any kernel commits that not in net-next, so I think we
good to go on the kernel side.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [iproute2 net-next v2 0/3] ip netconf improvements
  2017-03-24  2:51 [iproute2 net-next v2 0/3] ip netconf improvements David Ahern
                   ` (4 preceding siblings ...)
  2017-04-04 21:07 ` David Ahern
@ 2017-04-14 23:02 ` Stephen Hemminger
  5 siblings, 0 replies; 9+ messages in thread
From: Stephen Hemminger @ 2017-04-14 23:02 UTC (permalink / raw)
  To: David Ahern; +Cc: netdev, nicolas.dichtel

On Thu, 23 Mar 2017 19:51:19 -0700
David Ahern <dsa@cumulusnetworks.com> wrote:

> Currently, ip netconf only shows data for ipv4 and ipv6 for dumps
> and just ipv4 for device requests. Improve the user experience by
> using the new kernel patch to dump all address families that have
> registered. For example, if mpls_router module is loaded then mpls
> values are displayed along with ipv4 and ipv6.
> 
> If the new feature is not supported (new iproute2 on older kernel)
> the kernel returns the nlmsg error EOPNOTSUPP which can be trapped
> and fallback to existing behavior.
> 
> v2
> - fixed index conversion in patch 3 per nicholas' comment
> 
> David Ahern (3):
>   netlink: Add flag to suppress print of nlmsg error
>   ip netconf: Show all address families by default in dumps
>   ip netconf: show all families on dev request
> 
>  include/libnetlink.h |  1 +
>  ip/ipnetconf.c       | 36 +++++++++++++++++++++++++-----------
>  lib/libnetlink.c     |  3 ++-
>  3 files changed, 28 insertions(+), 12 deletions(-)
> 

Sure applied, just wanted to make sure there was nothing interrelated
with recent spate of changes to netlink notifications.

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2017-04-14 23:02 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-24  2:51 [iproute2 net-next v2 0/3] ip netconf improvements David Ahern
2017-03-24  2:51 ` [iproute2 net-next v2 1/3] netlink: Add flag to suppress print of nlmsg error David Ahern
2017-03-24  2:51 ` [iproute2 net-next v2 2/3] ip netconf: Show all address families by default in dumps David Ahern
2017-03-24  2:51 ` [iproute2 net-next v2 3/3] ip netconf: show all families on dev request David Ahern
2017-03-24  8:37 ` [iproute2 net-next v2 0/3] ip netconf improvements Nicolas Dichtel
2017-04-04 21:07 ` David Ahern
2017-04-04 21:39   ` Stephen Hemminger
2017-04-05 12:18     ` David Ahern
2017-04-14 23:02 ` Stephen Hemminger

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.