ip netconf improvements
Subsystems (3)
v2 cover ip netconf improvements
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(-)
Signature · 1 line
2.1.4
PATCH v2 1/3 netlink: Add flag to suppress print of nlmsg error
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.
--- include/libnetlink.h | 1 + lib/libnetlink.c | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-)
include/libnetlink.h +1 -0
@@ -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 0x02int flags; };
lib/libnetlink.c +2 -1
@@ -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" ); } }
Signature · 1 line
2.1.4
PATCH v2 2/3 ip netconf: Show all address families by default in dumps
In reply to David AhernCurrently, '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.
--- ip/ipnetconf.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)
ip/ipnetconf.c +12 -1
@@ -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;
Signature · 1 line
2.1.4
PATCH v2 3/3 ip netconf: show all families on dev request
In reply to David AhernCurrently 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.
--- ip/ipnetconf.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-)
ip/ipnetconf.c +13 -10
@@ -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" );
Signature · 1 line
2.1.4
Quoted 9 lines · 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_routermodule 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.
Quoted 18 lines · 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_routermodule 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' commentDavid 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
Quoted 5 lines
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?
Quoted 19 lines · On Tue, 4 Apr 2017 17:07:31 -0400 David Ahern <[email protected]> wrote:
Quoted 18 lines · 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_routermodule 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' commentDavid 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
Quoted 7 lines
Quoted 5 lines
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.
Quoted 28 lines · Stephen Hemminger
Quoted 25 lines · On Tue, 4 Apr 2017 17:07:31 -0400 David Ahern <[email protected]> wrote:
Quoted 23 lines · 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_routermodule 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' commentDavid 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 requestinclude/libnetlink.h | 1 + ip/ipnetconf.c | 36 +++++++++++++++++++++++++----------- lib/libnetlink.c | 3 ++- 3 files changed, 28 insertions(+), 12 deletions(-)
Quoted 5 lines
Quoted 1 line
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.
Quoted 18 lines · On Thu, 23 Mar 2017 19:51:19 -0700 David Ahern <[email protected]> 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_routermodule 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' commentDavid 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
Quoted 5 lines
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.