All of lore.kernel.org
 help / color / mirror / Atom feed
* [iproute2 net-next 0/3] ip netconf improvements
@ 2017-03-22 21:59 David Ahern
  2017-03-22 21:59 ` [iproute2 net-next 1/3] netlink: Add flag to suppress print of nlmsg error David Ahern
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: David Ahern @ 2017-03-22 21:59 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.

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] 5+ messages in thread

* [iproute2 net-next 1/3] netlink: Add flag to suppress print of nlmsg error
  2017-03-22 21:59 [iproute2 net-next 0/3] ip netconf improvements David Ahern
@ 2017-03-22 21:59 ` David Ahern
  2017-03-22 21:59 ` [iproute2 net-next 2/3] ip netconf: Show all address families by default in dumps David Ahern
  2017-03-22 21:59 ` [iproute2 net-next 3/3] ip netconf: Show all families on dev request David Ahern
  2 siblings, 0 replies; 5+ messages in thread
From: David Ahern @ 2017-03-22 21:59 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] 5+ messages in thread

* [iproute2 net-next 2/3] ip netconf: Show all address families by default in dumps
  2017-03-22 21:59 [iproute2 net-next 0/3] ip netconf improvements David Ahern
  2017-03-22 21:59 ` [iproute2 net-next 1/3] netlink: Add flag to suppress print of nlmsg error David Ahern
@ 2017-03-22 21:59 ` David Ahern
  2017-03-22 21:59 ` [iproute2 net-next 3/3] ip netconf: Show all families on dev request David Ahern
  2 siblings, 0 replies; 5+ messages in thread
From: David Ahern @ 2017-03-22 21:59 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] 5+ messages in thread

* [iproute2 net-next 3/3] ip netconf: Show all families on dev request
  2017-03-22 21:59 [iproute2 net-next 0/3] ip netconf improvements David Ahern
  2017-03-22 21:59 ` [iproute2 net-next 1/3] netlink: Add flag to suppress print of nlmsg error David Ahern
  2017-03-22 21:59 ` [iproute2 net-next 2/3] ip netconf: Show all address families by default in dumps David Ahern
@ 2017-03-22 21:59 ` David Ahern
  2017-03-23 16:04   ` Nicolas Dichtel
  2 siblings, 1 reply; 5+ messages in thread
From: David Ahern @ 2017-03-22 21:59 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..ab4c1d9db7c8 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 = *((int *)rta_getattr_str(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] 5+ messages in thread

* Re: [iproute2 net-next 3/3] ip netconf: Show all families on dev request
  2017-03-22 21:59 ` [iproute2 net-next 3/3] ip netconf: Show all families on dev request David Ahern
@ 2017-03-23 16:04   ` Nicolas Dichtel
  0 siblings, 0 replies; 5+ messages in thread
From: Nicolas Dichtel @ 2017-03-23 16:04 UTC (permalink / raw)
  To: David Ahern, netdev, stephen

Le 22/03/2017 à 22:59, David Ahern a écrit :
> 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..ab4c1d9db7c8 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 = *((int *)rta_getattr_str(tb[NETCONFA_IFINDEX]));
This line is moved, but rta_getattr_u32() is probably more right.


Regards,
Nicolas

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

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

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-22 21:59 [iproute2 net-next 0/3] ip netconf improvements David Ahern
2017-03-22 21:59 ` [iproute2 net-next 1/3] netlink: Add flag to suppress print of nlmsg error David Ahern
2017-03-22 21:59 ` [iproute2 net-next 2/3] ip netconf: Show all address families by default in dumps David Ahern
2017-03-22 21:59 ` [iproute2 net-next 3/3] ip netconf: Show all families on dev request David Ahern
2017-03-23 16:04   ` Nicolas Dichtel

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.