Fix dump requests to use proper header for type
Subsystems (3)
cover Fix dump requests to use proper header for type
From: David Ahern <[email protected]>
iproute2 currently uses ifinfomsg as the header for all dumps using the wilddump headers. This is wrong as each message type actually has its own header type. While the kernel has traditionally let it go as it for the most part only uses the family entry, the use of kernel side filters is increasing to alter what is returned on a request. The kernel side filters really need to use the proper header type.
To that end, fix iproute2 to use the proper header struct for the GET type.
David Ahern (11):
libnetlink: Convert GETADDR dumps to use rtnl_addrdump_req
libnetlink: Convert GETROUTE dumps to use rtnl_routedump_req
libnetlink: Convert GETADDRLABEL dumps to use rtnl_addrlbldump_req
libnetlink: Convert GETMDB dumps to use rtnl_mdbdump_req
libnetlink: Convert GETNETCONF dumps to use rtnl_netconfdump_req
libnetlink: Convert GETRULE dumps to use rtnl_ruledump_req
libnetlink: Convert GETNEIGH dumps to use rtnl_neighdump_req
libnetlink: Convert GETNEIGHTBL dumps to use rtnl_neightbldump_req
libnetlink: Convert GETNSID dumps to use rtnl_nsiddump_req
libnetlink: Rename rtnl_wilddump_* to rtnl_linkdump_*
libnetlink: Rename rtnl_wilddump_stats_req_filter to
rtnl_statsdump_req_filter
bridge/link.c | 4 +- bridge/mdb.c | 2 +- bridge/vlan.c | 10 +--- include/libnetlink.h | 30 ++++++++-- ip/ipaddress.c | 10 ++-- ip/ipaddrlabel.c | 4 +- ip/iplink.c | 4 +- ip/iplink_xstats.c | 4 +- ip/ipmroute.c | 2 +- ip/ipnetconf.c | 3 +- ip/ipnetns.c | 2 +- ip/ipntable.c | 2 +- ip/iproute.c | 4 +- ip/iprule.c | 2 +- ip/iptoken.c | 2 +- ip/iptuntap.c | 2 +- ip/rtmon.c | 2 +- ip/tunnel.c | 2 +- lib/libnetlink.c | 164 ++++++++++++++++++++++++++++++++++++++++++++++++--- lib/ll_map.c | 2 +- misc/arpd.c | 2 +- misc/ifstat.c | 6 +- 22 files changed, 210 insertions(+), 55 deletions(-)
Signature · 1 line
2.11.0
PATCH 1/11 libnetlink: Convert GETADDR dumps to use rtnl_addrdump_req
From: David Ahern <[email protected]>
Add rtnl_addrdump_req for address dumps using the proper ifaddrmsg as the header. Convert existing RTM_GETADDR dumps to use it.
--- include/libnetlink.h | 4 ++++ ip/ipaddress.c | 6 +++--- lib/libnetlink.c | 16 ++++++++++++++++ 3 files changed, 23 insertions(+), 3 deletions(-)
include/libnetlink.h +4 -0
@@ -46,6 +46,10 @@ int rtnl_open_byproto(struct rtnl_handle *rth, unsigned int subscriptions, __attribute__((warn_unused_result));void rtnl_close (struct rtnl_handle *rth); + +int rtnl_addrdump_req (struct rtnl_handle *rth,int family) + __attribute__((warn_unused_result)); +int rtnl_wilddump_request (struct rtnl_handle *rth,int fam,int type) __attribute__((warn_unused_result)); int rtnl_wilddump_req_filter(struct rtnl_handle *rth, int fam, int type,
ip/ipaddress.c +3 -3
@@ -1698,7 +1698,7 @@ static int ipaddr_flush(void) filter.flushe =sizeof (flushb);while ((max_flush_loops ==0 ) || (round < max_flush_loops)) { -if (rtnl_wilddump_request (&rth, filter.family,RTM_GETADDR ) <0 ) { +if (rtnl_addrdump_req (&rth, filter.family) <0 ) {perror ("Cannot send dump request" );exit (1 ); }
@@ -1790,7 +1790,7 @@ int ip_linkaddr_list(int family, req_filter_fn_t filter_fn, }if (ainfo) { -if (rtnl_wilddump_request (&rth, family,RTM_GETADDR ) <0 ) { +if (rtnl_addrdump_req (&rth, family) <0 ) {perror ("Cannot send dump request" );return 1 ; }
@@ -1915,7 +1915,7 @@ static int ipaddr_list_flush_or_save(int argc, char **argv, int action)if (ipadd_save_prep ())exit (1 ); -if (rtnl_wilddump_request (&rth, preferred_family,RTM_GETADDR ) <0 ) { +if (rtnl_addrdump_req (&rth, preferred_family) <0 ) {perror ("Cannot send dump request" );exit (1 ); }
lib/libnetlink.c +16 -0
@@ -199,6 +199,22 @@ int rtnl_open(struct rtnl_handle *rth, unsigned int subscriptions)return rtnl_open_byproto (rth, subscriptions,NETLINK_ROUTE ); } +int rtnl_addrdump_req (struct rtnl_handle *rth,int family) +{ +struct { +struct nlmsghdr nlh; +struct ifaddrmsg ifm; + } req = { + .nlh.nlmsg_len =sizeof (req), + .nlh.nlmsg_type =RTM_GETADDR , + .nlh.nlmsg_flags =NLM_F_DUMP |NLM_F_REQUEST , + .nlh.nlmsg_seq = rth->dump = ++rth->seq, + .ifm.ifa_family = family, + }; + +return send (rth->fd, &req,sizeof (req),0 ); +} +int rtnl_wilddump_request (struct rtnl_handle *rth,int family,int type) {return rtnl_wilddump_req_filter (rth, family, type,RTEXT_FILTER_VF );
Signature · 1 line
2.11.0
PATCH 2/11 libnetlink: Convert GETROUTE dumps to use rtnl_routedump_req
In reply to David AhernFrom: David Ahern <[email protected]>
Add rtnl_routedump_req for route dumps using the proper rtmsg as the header. Convert existing RTM_GETROUTE dumps to use it.
--- include/libnetlink.h | 2 ++ ip/ipmroute.c | 2 +- ip/iproute.c | 4 ++-- lib/libnetlink.c | 16 ++++++++++++++++ 4 files changed, 21 insertions(+), 3 deletions(-)
include/libnetlink.h +2 -0
@@ -49,6 +49,8 @@ void rtnl_close(struct rtnl_handle *rth);int rtnl_addrdump_req (struct rtnl_handle *rth,int family) __attribute__((warn_unused_result)); +int rtnl_routedump_req (struct rtnl_handle *rth,int family) + __attribute__((warn_unused_result));int rtnl_wilddump_request (struct rtnl_handle *rth,int fam,int type) __attribute__((warn_unused_result));
ip/ipmroute.c +1 -1
@@ -283,7 +283,7 @@ static int mroute_list(int argc, char **argv) filter.iif = idx; } -if (rtnl_wilddump_request (&rth, filter.af,RTM_GETROUTE ) <0 ) { +if (rtnl_routedump_req (&rth, filter.af) <0 ) {perror ("Cannot send dump request" );return 1 ; }
ip/iproute.c +2 -2
@@ -1645,7 +1645,7 @@ static int iproute_flush(int do_ipv6, rtnl_filter_t filter_fn) filter.flushe =sizeof (flushb);for (;;) { -if (rtnl_wilddump_request (&rth, do_ipv6,RTM_GETROUTE ) <0 ) { +if (rtnl_routedump_req (&rth, do_ipv6) <0 ) {perror ("Cannot send dump request" );return -2 ; }
@@ -1891,7 +1891,7 @@ static int iproute_list_flush_or_save(int argc, char **argv, int action)return iproute_flush (do_ipv6, filter_fn);if (!filter.cloned) { -if (rtnl_wilddump_request (&rth, do_ipv6,RTM_GETROUTE ) <0 ) { +if (rtnl_routedump_req (&rth, do_ipv6) <0 ) {perror ("Cannot send dump request" );return -2 ; }
lib/libnetlink.c +16 -0
@@ -215,6 +215,22 @@ int rtnl_addrdump_req(struct rtnl_handle *rth, int family)return send (rth->fd, &req,sizeof (req),0 ); } +int rtnl_routedump_req (struct rtnl_handle *rth,int family) +{ +struct { +struct nlmsghdr nlh; +struct rtmsg rtm; + } req = { + .nlh.nlmsg_len =sizeof (req), + .nlh.nlmsg_type =RTM_GETROUTE , + .nlh.nlmsg_flags =NLM_F_DUMP |NLM_F_REQUEST , + .nlh.nlmsg_seq = rth->dump = ++rth->seq, + .rtm.rtm_family = family, + }; + +return send (rth->fd, &req,sizeof (req),0 ); +} +int rtnl_wilddump_request (struct rtnl_handle *rth,int family,int type) {return rtnl_wilddump_req_filter (rth, family, type,RTEXT_FILTER_VF );
Signature · 1 line
2.11.0
PATCH 4/11 libnetlink: Convert GETMDB dumps to use rtnl_mdbdump_req
In reply to David AhernFrom: David Ahern <[email protected]>
Add rtnl_mdbdump_req for mdb dumps using the proper br_port_msg as the header. Convert existing RTM_GETMDB dumps to use it.
--- bridge/mdb.c | 2 +- include/libnetlink.h | 2 ++ lib/libnetlink.c | 17 +++++++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-)
bridge/mdb.c +1 -1
@@ -293,7 +293,7 @@ static int mdb_show(int argc, char **argv)new_json_obj (json);/* get mdb entries*/ -if (rtnl_wilddump_request (&rth,PF_BRIDGE ,RTM_GETMDB ) <0 ) { +if (rtnl_mdbdump_req (&rth,PF_BRIDGE ) <0 ) {perror ("Cannot send dump request" );return -1 ; }
include/libnetlink.h +2 -0
@@ -53,6 +53,8 @@ int rtnl_addrlbldump_req(struct rtnl_handle *rth, int family) __attribute__((warn_unused_result));int rtnl_routedump_req (struct rtnl_handle *rth,int family) __attribute__((warn_unused_result)); +int rtnl_mdbdump_req (struct rtnl_handle *rth,int family) + __attribute__((warn_unused_result));int rtnl_wilddump_request (struct rtnl_handle *rth,int fam,int type) __attribute__((warn_unused_result));
lib/libnetlink.c +17 -0
@@ -23,6 +23,7 @@#include <time.h> #include <sys/uio.h> #include <linux/if_addrlabel.h> +#include <linux/if_bridge.h> #include "libnetlink.h"
@@ -248,6 +249,22 @@ int rtnl_routedump_req(struct rtnl_handle *rth, int family)return send (rth->fd, &req,sizeof (req),0 ); } +int rtnl_mdbdump_req (struct rtnl_handle *rth,int family) +{ +struct { +struct nlmsghdr nlh; +struct br_port_msg bpm; + } req = { + .nlh.nlmsg_len =sizeof (req), + .nlh.nlmsg_type =RTM_GETMDB , + .nlh.nlmsg_flags =NLM_F_DUMP |NLM_F_REQUEST , + .nlh.nlmsg_seq = rth->dump = ++rth->seq, + .bpm.family = family, + }; + +return send (rth->fd, &req,sizeof (req),0 ); +} +int rtnl_wilddump_request (struct rtnl_handle *rth,int family,int type) {return rtnl_wilddump_req_filter (rth, family, type,RTEXT_FILTER_VF );
Signature · 1 line
2.11.0
PATCH 3/11 libnetlink: Convert GETADDRLABEL dumps to use rtnl_addrlbldump_req
In reply to David AhernFrom: David Ahern <[email protected]>
Add rtnl_addrlbldump_req for address label dumps using the proper ifaddrlblmsg as the header. Convert existing RTM_GETADDRALBEL dumps to use it.
--- include/libnetlink.h | 2 ++ ip/ipaddrlabel.c | 4 ++-- lib/libnetlink.c | 17 +++++++++++++++++ 3 files changed, 21 insertions(+), 2 deletions(-)
include/libnetlink.h +2 -0
@@ -49,6 +49,8 @@ void rtnl_close(struct rtnl_handle *rth);int rtnl_addrdump_req (struct rtnl_handle *rth,int family) __attribute__((warn_unused_result)); +int rtnl_addrlbldump_req (struct rtnl_handle *rth,int family) + __attribute__((warn_unused_result));int rtnl_routedump_req (struct rtnl_handle *rth,int family) __attribute__((warn_unused_result));
ip/ipaddrlabel.c +2 -2
@@ -118,7 +118,7 @@ static int ipaddrlabel_list(int argc, char **argv)return -1 ; } -if (rtnl_wilddump_request (&rth, af,RTM_GETADDRLABEL ) <0 ) { +if (rtnl_addrlbldump_req (&rth, af) <0 ) {perror ("Cannot send dump request" );return 1 ; }
@@ -237,7 +237,7 @@ static int ipaddrlabel_flush(int argc, char **argv)return -1 ; } -if (rtnl_wilddump_request (&rth, af,RTM_GETADDRLABEL ) <0 ) { +if (rtnl_addrlbldump_req (&rth, af) <0 ) {perror ("Cannot send dump request" );return -1 ; }
lib/libnetlink.c +17 -0
@@ -22,6 +22,7 @@#include <errno.h> #include <time.h> #include <sys/uio.h> +#include <linux/if_addrlabel.h> #include "libnetlink.h"
@@ -215,6 +216,22 @@ int rtnl_addrdump_req(struct rtnl_handle *rth, int family)return send (rth->fd, &req,sizeof (req),0 ); } +int rtnl_addrlbldump_req (struct rtnl_handle *rth,int family) +{ +struct { +struct nlmsghdr nlh; +struct ifaddrlblmsg ifal; + } req = { + .nlh.nlmsg_len =sizeof (req), + .nlh.nlmsg_type =RTM_GETADDRLABEL , + .nlh.nlmsg_flags =NLM_F_DUMP |NLM_F_REQUEST , + .nlh.nlmsg_seq = rth->dump = ++rth->seq, + .ifal.ifal_family = family, + }; + +return send (rth->fd, &req,sizeof (req),0 ); +} +int rtnl_routedump_req (struct rtnl_handle *rth,int family) {struct {
Signature · 1 line
2.11.0
PATCH 5/11 libnetlink: Convert GETNETCONF dumps to use rtnl_netconfdump_req
In reply to David AhernFrom: David Ahern <[email protected]>
Add rtnl_netconfdump_req for netconf dumps using the proper netconfmsg as the header. Convert existing RTM_GETNETCONF dumps to use it.
--- include/libnetlink.h | 2 ++ ip/ipnetconf.c | 3 +-- lib/libnetlink.c | 16 ++++++++++++++++ 3 files changed, 19 insertions(+), 2 deletions(-)
include/libnetlink.h +2 -0
@@ -55,6 +55,8 @@ int rtnl_routedump_req(struct rtnl_handle *rth, int family) __attribute__((warn_unused_result));int rtnl_mdbdump_req (struct rtnl_handle *rth,int family) __attribute__((warn_unused_result)); +int rtnl_netconfdump_req (struct rtnl_handle *rth,int family) + __attribute__((warn_unused_result));int rtnl_wilddump_request (struct rtnl_handle *rth,int fam,int type) __attribute__((warn_unused_result));
ip/ipnetconf.c +1 -2
@@ -210,8 +210,7 @@ static int do_show(int argc, char **argv) }else { rth.flags =RTNL_HANDLE_F_SUPPRESS_NLERR ; dump: -if (rtnl_wilddump_request (&rth, filter.family, -RTM_GETNETCONF ) <0 ) { +if (rtnl_netconfdump_req (&rth, filter.family) <0 ) {perror ("Cannot send dump request" );exit (1 ); }
lib/libnetlink.c +16 -0
@@ -265,6 +265,22 @@ int rtnl_mdbdump_req(struct rtnl_handle *rth, int family)return send (rth->fd, &req,sizeof (req),0 ); } +int rtnl_netconfdump_req (struct rtnl_handle *rth,int family) +{ +struct { +struct nlmsghdr nlh; +struct netconfmsg ncm; + } req = { + .nlh.nlmsg_len =sizeof (req), + .nlh.nlmsg_type =RTM_GETNETCONF , + .nlh.nlmsg_flags =NLM_F_DUMP |NLM_F_REQUEST , + .nlh.nlmsg_seq = rth->dump = ++rth->seq, + .ncm.ncm_family = family, + }; + +return send (rth->fd, &req,sizeof (req),0 ); +} +int rtnl_wilddump_request (struct rtnl_handle *rth,int family,int type) {return rtnl_wilddump_req_filter (rth, family, type,RTEXT_FILTER_VF );
Signature · 1 line
2.11.0
PATCH 6/11 libnetlink: Convert GETRULE dumps to use rtnl_ruledump_req
In reply to David AhernFrom: David Ahern <[email protected]>
Add rtnl_ruledump_req for fib fule dumps using the proper fib_rule_hdr as the header. Convert existing RTM_GETRULE dumps to use it.
--- include/libnetlink.h | 2 ++ ip/iprule.c | 2 +- lib/libnetlink.c | 17 +++++++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-)
include/libnetlink.h +2 -0
@@ -53,6 +53,8 @@ int rtnl_addrlbldump_req(struct rtnl_handle *rth, int family) __attribute__((warn_unused_result));int rtnl_routedump_req (struct rtnl_handle *rth,int family) __attribute__((warn_unused_result)); +int rtnl_ruledump_req (struct rtnl_handle *rth,int family) + __attribute__((warn_unused_result));int rtnl_mdbdump_req (struct rtnl_handle *rth,int family) __attribute__((warn_unused_result));int rtnl_netconfdump_req (struct rtnl_handle *rth,int family)
ip/iprule.c +1 -1
@@ -615,7 +615,7 @@ static int iprule_list_flush_or_save(int argc, char **argv, int action) argc--; argv++; } -if (rtnl_wilddump_request (&rth, af,RTM_GETRULE ) <0 ) { +if (rtnl_ruledump_req (&rth, af) <0 ) {perror ("Cannot send dump request" );return 1 ; }
lib/libnetlink.c +17 -0
@@ -22,6 +22,7 @@#include <errno.h> #include <time.h> #include <sys/uio.h> +#include <linux/fib_rules.h> #include <linux/if_addrlabel.h> #include <linux/if_bridge.h>
@@ -249,6 +250,22 @@ int rtnl_routedump_req(struct rtnl_handle *rth, int family)return send (rth->fd, &req,sizeof (req),0 ); } +int rtnl_ruledump_req (struct rtnl_handle *rth,int family) +{ +struct { +struct nlmsghdr nlh; +struct fib_rule_hdr frh; + } req = { + .nlh.nlmsg_len =sizeof (req), + .nlh.nlmsg_type =RTM_GETRULE , + .nlh.nlmsg_flags =NLM_F_DUMP |NLM_F_REQUEST , + .nlh.nlmsg_seq = rth->dump = ++rth->seq, + .frh.family = family + }; + +return send (rth->fd, &req,sizeof (req),0 ); +} +int rtnl_mdbdump_req (struct rtnl_handle *rth,int family) {struct {
Signature · 1 line
2.11.0
PATCH 7/11 libnetlink: Convert GETNEIGH dumps to use rtnl_neighdump_req
In reply to David AhernFrom: David Ahern <[email protected]>
Add rtnl_neighdump_req for neighbor dumps using the proper ndmsg as the header. Convert existing rtnl_wilddump_request for RTM_GETNEIGH to use it.
--- include/libnetlink.h | 2 ++ lib/libnetlink.c | 16 ++++++++++++++++ misc/arpd.c | 2 +- 3 files changed, 19 insertions(+), 1 deletion(-)
include/libnetlink.h +2 -0
@@ -55,6 +55,8 @@ int rtnl_routedump_req(struct rtnl_handle *rth, int family) __attribute__((warn_unused_result));int rtnl_ruledump_req (struct rtnl_handle *rth,int family) __attribute__((warn_unused_result)); +int rtnl_neighdump_req (struct rtnl_handle *rth,int family) + __attribute__((warn_unused_result));int rtnl_mdbdump_req (struct rtnl_handle *rth,int family) __attribute__((warn_unused_result));int rtnl_netconfdump_req (struct rtnl_handle *rth,int family)
lib/libnetlink.c +16 -0
@@ -266,6 +266,22 @@ int rtnl_ruledump_req(struct rtnl_handle *rth, int family)return send (rth->fd, &req,sizeof (req),0 ); } +int rtnl_neighdump_req (struct rtnl_handle *rth,int family) +{ +struct { +struct nlmsghdr nlh; +struct ndmsg ndm; + } req = { + .nlh.nlmsg_len =sizeof (req), + .nlh.nlmsg_type =RTM_GETNEIGH , + .nlh.nlmsg_flags =NLM_F_DUMP |NLM_F_REQUEST , + .nlh.nlmsg_seq = rth->dump = ++rth->seq, + .ndm.ndm_family = family, + }; + +return send (rth->fd, &req,sizeof (req),0 ); +} +int rtnl_mdbdump_req (struct rtnl_handle *rth,int family) {struct {
misc/arpd.c +1 -1
@@ -424,7 +424,7 @@ static int do_one_request(struct nlmsghdr *n)static void load_initial_table (void ) { -if (rtnl_wilddump_request (&rth,AF_INET ,RTM_GETNEIGH ) <0 ) { +if (rtnl_neighdump_req (&rth,AF_INET ) <0 ) {perror ("dump request failed" );exit (1 ); }
Signature · 1 line
2.11.0
PATCH 8/11 libnetlink: Convert GETNEIGHTBL dumps to use rtnl_neightbldump_req
In reply to David AhernFrom: David Ahern <[email protected]>
Add rtnl_neightbldump_req for neighbor table dumps using the proper ndtmsg as the header. Convert existing RTM_GETNEIGHTBL dumps to use it.
--- include/libnetlink.h | 2 ++ ip/ipntable.c | 2 +- lib/libnetlink.c | 16 ++++++++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-)
include/libnetlink.h +2 -0
@@ -57,6 +57,8 @@ int rtnl_ruledump_req(struct rtnl_handle *rth, int family) __attribute__((warn_unused_result));int rtnl_neighdump_req (struct rtnl_handle *rth,int family) __attribute__((warn_unused_result)); +int rtnl_neightbldump_req (struct rtnl_handle *rth,int family) + __attribute__((warn_unused_result));int rtnl_mdbdump_req (struct rtnl_handle *rth,int family) __attribute__((warn_unused_result));int rtnl_netconfdump_req (struct rtnl_handle *rth,int family)
ip/ipntable.c +1 -1
@@ -658,7 +658,7 @@ static int ipntable_show(int argc, char **argv) argc--; argv++; } -if (rtnl_wilddump_request (&rth, preferred_family,RTM_GETNEIGHTBL ) <0 ) { +if (rtnl_neightbldump_req (&rth, preferred_family) <0 ) {perror ("Cannot send dump request" );exit (1 ); }
lib/libnetlink.c +16 -0
@@ -282,6 +282,22 @@ int rtnl_neighdump_req(struct rtnl_handle *rth, int family)return send (rth->fd, &req,sizeof (req),0 ); } +int rtnl_neightbldump_req (struct rtnl_handle *rth,int family) +{ +struct { +struct nlmsghdr nlh; +struct ndtmsg ndtmsg; + } req = { + .nlh.nlmsg_len =sizeof (req), + .nlh.nlmsg_type =RTM_GETNEIGHTBL , + .nlh.nlmsg_flags =NLM_F_DUMP |NLM_F_REQUEST , + .nlh.nlmsg_seq = rth->dump = ++rth->seq, + .ndtmsg.ndtm_family = family, + }; + +return send (rth->fd, &req,sizeof (req),0 ); +} +int rtnl_mdbdump_req (struct rtnl_handle *rth,int family) {struct {
Signature · 1 line
2.11.0
PATCH 9/11 libnetlink: Convert GETNSID dumps to use rtnl_nsiddump_req
In reply to David AhernFrom: David Ahern <[email protected]>
Add rtnl_nsiddump_req for namespace id dumps using the proper rtgenmsg as the header. Convert existing RTM_GETNSID dumps to use it.
--- include/libnetlink.h | 2 ++ ip/ipnetns.c | 2 +- lib/libnetlink.c | 16 ++++++++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-)
include/libnetlink.h +2 -0
@@ -63,6 +63,8 @@ int rtnl_mdbdump_req(struct rtnl_handle *rth, int family) __attribute__((warn_unused_result));int rtnl_netconfdump_req (struct rtnl_handle *rth,int family) __attribute__((warn_unused_result)); +int rtnl_nsiddump_req (struct rtnl_handle *rth,int family) + __attribute__((warn_unused_result));int rtnl_wilddump_request (struct rtnl_handle *rth,int fam,int type) __attribute__((warn_unused_result));
ip/ipnetns.c +1 -1
@@ -346,7 +346,7 @@ static int netns_list_id(int argc, char **argv)return -ENOTSUP ; } -if (rtnl_wilddump_request (&rth,AF_UNSPEC ,RTM_GETNSID ) <0 ) { +if (rtnl_nsiddump_req (&rth,AF_UNSPEC ) <0 ) {perror ("Cannot send dump request" );exit (1 ); }
lib/libnetlink.c +16 -0
@@ -330,6 +330,22 @@ int rtnl_netconfdump_req(struct rtnl_handle *rth, int family)return send (rth->fd, &req,sizeof (req),0 ); } +int rtnl_nsiddump_req (struct rtnl_handle *rth,int family) +{ +struct { +struct nlmsghdr nlh; +struct rtgenmsg rtm; + } req = { + .nlh.nlmsg_len =sizeof (req), + .nlh.nlmsg_type =RTM_GETNSID , + .nlh.nlmsg_flags =NLM_F_DUMP |NLM_F_REQUEST , + .nlh.nlmsg_seq = rth->dump = ++rth->seq, + .rtm.rtgen_family = family, + }; + +return send (rth->fd, &req,sizeof (req),0 ); +} +int rtnl_wilddump_request (struct rtnl_handle *rth,int family,int type) {return rtnl_wilddump_req_filter (rth, family, type,RTEXT_FILTER_VF );
Signature · 1 line
2.11.0
PATCH 11/11 libnetlink: Rename rtnl_wilddump_stats_req_filter to rtnl_statsdump_req_filter
In reply to David AhernFrom: David Ahern <[email protected]>
rtnl_wilddump_stats_req_filter only takes RTM_GETSTATS as the type argument so rename to rtnl_statsdump_req_filter for consistency with other request functions and hardcode the type argument.
--- bridge/vlan.c | 8 ++------ include/libnetlink.h | 3 +-- ip/iplink.c | 4 +--- ip/iplink_xstats.c | 4 +--- lib/libnetlink.c | 5 ++--- misc/ifstat.c | 4 ++-- 6 files changed, 9 insertions(+), 19 deletions(-)
bridge/vlan.c +2 -6
@@ -603,9 +603,7 @@ static int vlan_show(int argc, char **argv)__u32 filt_mask; filt_mask =IFLA_STATS_FILTER_BIT (IFLA_STATS_LINK_XSTATS ); -if (rtnl_wilddump_stats_req_filter (&rth,AF_UNSPEC , -RTM_GETSTATS , - filt_mask) <0 ) { +if (rtnl_statsdump_req_filter (&rth,AF_UNSPEC , filt_mask) <0 ) {perror ("Cannont send dump request" );exit (1 ); }
@@ -619,9 +617,7 @@ static int vlan_show(int argc, char **argv) } filt_mask =IFLA_STATS_FILTER_BIT (IFLA_STATS_LINK_XSTATS_SLAVE ); -if (rtnl_wilddump_stats_req_filter (&rth,AF_UNSPEC , -RTM_GETSTATS , - filt_mask) <0 ) { +if (rtnl_statsdump_req_filter (&rth,AF_UNSPEC , filt_mask) <0 ) {perror ("Cannont send slave dump request" );exit (1 ); }
include/libnetlink.h +1 -2
@@ -76,8 +76,7 @@ typedef int (*req_filter_fn_t)(struct nlmsghdr *nlh, int reqlen);int rtnl_linkdump_req_filter_fn (struct rtnl_handle *rth,int fam,req_filter_fn_t fn) __attribute__((warn_unused_result)); -int rtnl_wilddump_stats_req_filter (struct rtnl_handle *rth,int fam,int type, -__u32 filt_mask) +int rtnl_statsdump_req_filter (struct rtnl_handle *rth,int fam,__u32 filt_mask) __attribute__((warn_unused_result));int rtnl_dump_request (struct rtnl_handle *rth,int type,void *req,int len)
ip/iplink.c +1 -3
@@ -1601,9 +1601,7 @@ static int iplink_afstats(int argc, char **argv) } } -if (rtnl_wilddump_stats_req_filter (&rth,AF_UNSPEC , -RTM_GETSTATS , - filt_mask) <0 ) { +if (rtnl_statsdump_req_filter (&rth,AF_UNSPEC , filt_mask) <0 ) {perror ("Cannont send dump request" );return 1 ; }
ip/iplink_xstats.c +1 -3
@@ -65,9 +65,7 @@ int iplink_ifla_xstats(int argc, char **argv)else filt_mask =IFLA_STATS_FILTER_BIT (IFLA_STATS_LINK_XSTATS ); -if (rtnl_wilddump_stats_req_filter (&rth,AF_UNSPEC , -RTM_GETSTATS , - filt_mask) <0 ) { +if (rtnl_statsdump_req_filter (&rth,AF_UNSPEC , filt_mask) <0 ) {perror ("Cannont send dump request" );return -1 ; }
lib/libnetlink.c +2 -3
@@ -400,8 +400,7 @@ int rtnl_linkdump_req_filter_fn(struct rtnl_handle *rth, int family,return send (rth->fd, &req, req.nlh.nlmsg_len,0 ); } -int rtnl_wilddump_stats_req_filter (struct rtnl_handle *rth,int fam,int type, -__u32 filt_mask) +int rtnl_statsdump_req_filter (struct rtnl_handle *rth,int fam,__u32 filt_mask) {struct {struct nlmsghdr nlh;
@@ -410,7 +409,7 @@ int rtnl_wilddump_stats_req_filter(struct rtnl_handle *rth, int fam, int type,memset (&req,0 ,sizeof (req)); req.nlh.nlmsg_len =NLMSG_LENGTH (sizeof (struct if_stats_msg )); - req.nlh.nlmsg_type = type; + req.nlh.nlmsg_type =RTM_GETSTATS ; req.nlh.nlmsg_flags =NLM_F_DUMP |NLM_F_REQUEST ; req.nlh.nlmsg_pid =0 ; req.nlh.nlmsg_seq = rth->dump = ++rth->seq;
misc/ifstat.c +2 -2
@@ -203,8 +203,8 @@ static void load_info(void)if (is_extended) {ll_init_map (&rth); filter_mask =IFLA_STATS_FILTER_BIT (filter_type); -if (rtnl_wilddump_stats_req_filter (&rth,AF_UNSPEC ,RTM_GETSTATS , - filter_mask) <0 ) { +if (rtnl_statsdump_req_filter (&rth,AF_UNSPEC , + filter_mask) <0 ) {perror ("Cannot send dump request" );exit (1 ); }
Signature · 1 line
2.11.0
PATCH 10/11 libnetlink: Rename rtnl_wilddump_* to rtnl_linkdump_*
In reply to David AhernFrom: David Ahern <[email protected]>
Rename rtnl_wilddump_req_filter to rtnl_linkdump_req_filter, rtnl_wilddump_request to rtnl_linkdump_request and rtnl_wilddump_req_filter_fn to rtnl_linkdump_req_filter_fn.
In all cases drop the type argument which at this point is only RTM_GETLINK and hardcode in the functions.
--- bridge/link.c | 4 ++-- bridge/vlan.c | 2 +- include/libnetlink.h | 7 +++---- ip/ipaddress.c | 4 ++-- ip/iptoken.c | 2 +- ip/iptuntap.c | 2 +- ip/rtmon.c | 2 +- ip/tunnel.c | 2 +- lib/libnetlink.c | 12 ++++++------ lib/ll_map.c | 2 +- misc/ifstat.c | 2 +- 11 files changed, 20 insertions(+), 21 deletions(-)
bridge/link.c +2 -2
@@ -502,7 +502,7 @@ static int brlink_show(int argc, char **argv) }if (show_details) { -if (rtnl_wilddump_req_filter (&rth,PF_BRIDGE ,RTM_GETLINK , +if (rtnl_linkdump_req_filter (&rth,PF_BRIDGE , (compress_vlans ?RTEXT_FILTER_BRVLAN_COMPRESSED :RTEXT_FILTER_BRVLAN )) <0 ) {
@@ -510,7 +510,7 @@ static int brlink_show(int argc, char **argv)exit (1 ); } }else { -if (rtnl_wilddump_request (&rth,PF_BRIDGE ,RTM_GETLINK ) <0 ) { +if (rtnl_linkdump_request (&rth,PF_BRIDGE ) <0 ) {perror ("Cannon send dump request" );exit (1 ); }
bridge/vlan.c +1 -1
@@ -575,7 +575,7 @@ static int vlan_show(int argc, char **argv)new_json_obj (json);if (!show_stats) { -if (rtnl_wilddump_req_filter (&rth,PF_BRIDGE ,RTM_GETLINK , +if (rtnl_linkdump_req_filter (&rth,PF_BRIDGE , (compress_vlans ?RTEXT_FILTER_BRVLAN_COMPRESSED :RTEXT_FILTER_BRVLAN )) <0 ) {
include/libnetlink.h +3 -4
@@ -66,15 +66,14 @@ int rtnl_netconfdump_req(struct rtnl_handle *rth, int family)int rtnl_nsiddump_req (struct rtnl_handle *rth,int family) __attribute__((warn_unused_result)); -int rtnl_wilddump_request (struct rtnl_handle *rth,int fam,int type) +int rtnl_linkdump_request (struct rtnl_handle *rth,int fam) __attribute__((warn_unused_result)); -int rtnl_wilddump_req_filter (struct rtnl_handle *rth,int fam,int type, -__u32 filt_mask) +int rtnl_linkdump_req_filter (struct rtnl_handle *rth,int fam,__u32 filt_mask) __attribute__((warn_unused_result));typedef int (*req_filter_fn_t )(struct nlmsghdr *nlh,int reqlen); -int rtnl_wilddump_req_filter_fn (struct rtnl_handle *rth,int fam,int type, +int rtnl_linkdump_req_filter_fn (struct rtnl_handle *rth,int fam,req_filter_fn_t fn) __attribute__((warn_unused_result)); int rtnl_wilddump_stats_req_filter(struct rtnl_handle *rth, int fam, int type,
ip/ipaddress.c +2 -2
@@ -1778,7 +1778,7 @@ static int iplink_filter_req(struct nlmsghdr *nlh, int reqlen)int ip_linkaddr_list (int family,req_filter_fn_t filter_fn,struct nlmsg_chain *linfo,struct nlmsg_chain *ainfo) { -if (rtnl_wilddump_req_filter_fn (&rth, preferred_family,RTM_GETLINK , +if (rtnl_linkdump_req_filter_fn (&rth, preferred_family, filter_fn) <0 ) {perror ("Cannot send dump request" );return 1 ;
@@ -2031,7 +2031,7 @@ void ipaddr_get_vf_rate(int vfnum, int *min, int *max, const char *dev)exit (1 ); } -if (rtnl_wilddump_request (&rth,AF_UNSPEC ,RTM_GETLINK ) <0 ) { +if (rtnl_linkdump_request (&rth,AF_UNSPEC ) <0 ) {perror ("Cannot send dump request" );exit (1 ); }
ip/iptoken.c +1 -1
@@ -109,7 +109,7 @@ static int iptoken_list(int argc, char **argv) argc--; argv++; } -if (rtnl_wilddump_request (&rth, af,RTM_GETLINK ) <0 ) { +if (rtnl_linkdump_request (&rth, af) <0 ) {perror ("Cannot send dump request" );return -1 ; }
ip/iptuntap.c +1 -1
@@ -459,7 +459,7 @@ static int print_tuntap(const struct sockaddr_nl *who,static int do_show (int argc,char **argv) { -if (rtnl_wilddump_req_filter_fn (&rth,AF_UNSPEC ,RTM_GETLINK , +if (rtnl_linkdump_req_filter_fn (&rth,AF_UNSPEC , tuntap_filter_req) <0 ) {perror ("Cannot send dump request\n" );return -1 ;
ip/rtmon.c +1 -1
@@ -163,7 +163,7 @@ main(int argc, char **argv)if (rtnl_open (&rth, groups) <0 )exit (1 ); -if (rtnl_wilddump_request (&rth,AF_UNSPEC ,RTM_GETLINK ) <0 ) { +if (rtnl_linkdump_request (&rth,AF_UNSPEC ) <0 ) {perror ("Cannot send dump request" );exit (1 ); }
ip/tunnel.c +1 -1
@@ -392,7 +392,7 @@ static int print_nlmsg_tunnel(const struct sockaddr_nl *who,int do_tunnels_list (struct tnl_print_nlmsg_info *info) { -if (rtnl_wilddump_request (&rth, preferred_family,RTM_GETLINK ) <0 ) { +if (rtnl_linkdump_request (&rth, preferred_family) <0 ) {perror ("Cannot send dump request\n" );return -1 ; }
lib/libnetlink.c +6 -6
@@ -346,12 +346,12 @@ int rtnl_nsiddump_req(struct rtnl_handle *rth, int family)return send (rth->fd, &req,sizeof (req),0 ); } -int rtnl_wilddump_request (struct rtnl_handle *rth,int family,int type) +int rtnl_linkdump_request (struct rtnl_handle *rth,int family) { -return rtnl_wilddump_req_filter (rth, family, type,RTEXT_FILTER_VF ); +return rtnl_linkdump_req_filter (rth, family,RTEXT_FILTER_VF ); } -int rtnl_wilddump_req_filter (struct rtnl_handle *rth,int family,int type, +int rtnl_linkdump_req_filter (struct rtnl_handle *rth,int family,__u32 filt_mask) {struct {
@@ -362,7 +362,7 @@ int rtnl_wilddump_req_filter(struct rtnl_handle *rth, int family, int type,__u32 ext_filter_mask; } req = { .nlh.nlmsg_len = sizeof(req), - .nlh.nlmsg_type = type, + .nlh.nlmsg_type = RTM_GETLINK, .nlh.nlmsg_flags = NLM_F_DUMP | NLM_F_REQUEST, .nlh.nlmsg_seq = rth->dump = ++rth->seq, .ifm.ifi_family = family,
@@ -374,7 +374,7 @@ int rtnl_wilddump_req_filter(struct rtnl_handle *rth, int family, int type,return send (rth->fd, &req,sizeof (req),0 ); } -int rtnl_wilddump_req_filter_fn (struct rtnl_handle *rth,int family,int type, +int rtnl_linkdump_req_filter_fn (struct rtnl_handle *rth,int family,req_filter_fn_t filter_fn) {struct {
@@ -383,7 +383,7 @@ int rtnl_wilddump_req_filter_fn(struct rtnl_handle *rth, int family, int type,char buf[1024 ]; } req = { .nlh.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg)), - .nlh.nlmsg_type = type, + .nlh.nlmsg_type = RTM_GETLINK, .nlh.nlmsg_flags = NLM_F_DUMP | NLM_F_REQUEST, .nlh.nlmsg_seq = rth->dump = ++rth->seq, .ifm.ifi_family = family,
lib/ll_map.c +1 -1
@@ -218,7 +218,7 @@ void ll_init_map(struct rtnl_handle *rth)if (initialized)return ; -if (rtnl_wilddump_request (rth,AF_UNSPEC ,RTM_GETLINK ) <0 ) { +if (rtnl_linkdump_request (rth,AF_UNSPEC ) <0 ) {perror ("Cannot send dump request" );exit (1 ); }
misc/ifstat.c +1 -1
@@ -214,7 +214,7 @@ static void load_info(void)exit (1 ); } }else { -if (rtnl_wilddump_request (&rth,AF_INET ,RTM_GETLINK ) <0 ) { +if (rtnl_linkdump_request (&rth,AF_INET ) <0 ) {perror ("Cannot send dump request" );exit (1 ); }
Signature · 1 line
2.11.0
Re: [PATCH iproute2-next 01/11] libnetlink: Convert GETADDR dumps to use rtnl_addrdump_req
In reply to David AhernQuoted 6 lines · On Sat, 29 Sep 2018 10:59:21 -0700 David Ahern <[email protected]> wrote:
From: David Ahern <[email protected]>
Add
rtnl_addrdump_reqfor address dumps using the proper ifaddrmsg as the header. Convert existingRTM_GETADDRdumps to use it.Signed-off-by David Ahern <[email protected]>
}
lib/libnetlink.c int rtnl_open(struct rtnl_handle *rth, unsigned int subscriptions) · line 213
Quoted 13 lines
lib/libnetlink.c +12
-0+int rtnl_addrdump_req (struct rtnl_handle *rth,int family) +{ +struct { +struct nlmsghdr nlh; +struct ifaddrmsg ifm; + } req = { + .nlh.nlmsg_len =sizeof (req), + .nlh.nlmsg_type =RTM_GETADDR , + .nlh.nlmsg_flags =NLM_F_DUMP |NLM_F_REQUEST , + .nlh.nlmsg_seq = rth->dump = ++rth->seq, + .ifm.ifa_family = family, + };
This could be:
} req = {
.nlh = {
.nlmsg_len = sizeof(req),
.nlmsg_type = RTM_GETADDR,...
Re: [PATCH iproute2-next 01/11] libnetlink: Convert GETADDR dumps to use rtnl_addrdump_req
Quoted 27 lines · Stephen Hemminger
Quoted 6 lines · On Sat, 29 Sep 2018 10:59:21 -0700 David Ahern <[email protected]> wrote:
From: David Ahern <[email protected]>
Add
rtnl_addrdump_reqfor address dumps using the proper ifaddrmsg as the header. Convert existingRTM_GETADDRdumps to use it.Signed-off-by David Ahern <[email protected]>}
lib/libnetlink.c int rtnl_open(struct rtnl_handle *rth, unsigned int subscriptions) · line 213
Quoted 13 lines
lib/libnetlink.c +12
-0+int rtnl_addrdump_req (struct rtnl_handle *rth,int family) +{ +struct { +struct nlmsghdr nlh; +struct ifaddrmsg ifm; + } req = { + .nlh.nlmsg_len =sizeof (req), + .nlh.nlmsg_type =RTM_GETADDR , + .nlh.nlmsg_flags =NLM_F_DUMP |NLM_F_REQUEST , + .nlh.nlmsg_seq = rth->dump = ++rth->seq, + .ifm.ifa_family = family, + };This could be:
Quoted 6 lines
} req = { .nlh = { .nlmsg_len = sizeof(req), .nlmsg_type = RTM_GETADDR,...
I kept the inline because it is the style everywhere else in the iproute2 code.
Quoted 10 lines · David Ahern
From: David Ahern <[email protected]>
iproute2 currently uses ifinfomsg as the header for all dumps using the wilddump headers. This is wrong as each message type actually has its own header type. While the kernel has traditionally let it go as it for the most part only uses the family entry, the use of kernel side filters is increasing to alter what is returned on a request. The kernel side filters really need to use the proper header type.
To that end, fix iproute2 to use the proper header struct for the GET type.
Thanks for doing this, David!
Christian
Quoted 42 lines
David Ahern (11):
libnetlink: Convert GETADDR dumps to usertnl_addrdump_req
libnetlink: Convert GETROUTE dumps to usertnl_routedump_req
libnetlink: Convert GETADDRLABEL dumps to usertnl_addrlbldump_req
libnetlink: Convert GETMDB dumps to usertnl_mdbdump_req
libnetlink: Convert GETNETCONF dumps to usertnl_netconfdump_req
libnetlink: Convert GETRULE dumps to usertnl_ruledump_req
libnetlink: Convert GETNEIGH dumps to usertnl_neighdump_req
libnetlink: Convert GETNEIGHTBL dumps to usertnl_neightbldump_req
libnetlink: Convert GETNSID dumps to usertnl_nsiddump_req
libnetlink: Rename rtnl_wilddump_* to rtnl_linkdump_*
libnetlink: Renamertnl_wilddump_stats_req_filterto
rtnl_statsdump_req_filterbridge/link.c | 4 +- bridge/mdb.c | 2 +- bridge/vlan.c | 10 +--- include/libnetlink.h | 30 ++++++++-- ip/ipaddress.c | 10 ++-- ip/ipaddrlabel.c | 4 +- ip/iplink.c | 4 +- ip/iplink_xstats.c | 4 +- ip/ipmroute.c | 2 +- ip/ipnetconf.c | 3 +- ip/ipnetns.c | 2 +- ip/ipntable.c | 2 +- ip/iproute.c | 4 +- ip/iprule.c | 2 +- ip/iptoken.c | 2 +- ip/iptuntap.c | 2 +- ip/rtmon.c | 2 +- ip/tunnel.c | 2 +- lib/libnetlink.c | 164 ++++++++++++++++++++++++++++++++++++++++++++++++--- lib/ll_map.c | 2 +- misc/arpd.c | 2 +- misc/ifstat.c | 6 +- 22 files changed, 210 insertions(+), 55 deletions(-)Signature · 1 line
2.11.0