diff mbox series

[iproute2-next,01/11] libnetlink: Convert GETADDR dumps to use rtnl_addrdump_req

Message ID 20180929175931.18448-2-dsahern@kernel.org
State Accepted, archived
Delegated to: David Ahern
Headers show
Series Fix dump requests to use proper header for type | expand

Commit Message

David Ahern Sept. 29, 2018, 5:59 p.m. UTC
From: David Ahern <dsahern@gmail.com>

Add rtnl_addrdump_req for address dumps using the proper ifaddrmsg
as the header. Convert existing RTM_GETADDR dumps to use it.

Signed-off-by: David Ahern <dsahern@gmail.com>
---
 include/libnetlink.h |  4 ++++
 ip/ipaddress.c       |  6 +++---
 lib/libnetlink.c     | 16 ++++++++++++++++
 3 files changed, 23 insertions(+), 3 deletions(-)

Comments

Stephen Hemminger Sept. 30, 2018, 9:35 a.m. UTC | #1
On Sat, 29 Sep 2018 10:59:21 -0700
David Ahern <dsahern@kernel.org> wrote:

> From: David Ahern <dsahern@gmail.com>
> 
> Add rtnl_addrdump_req for address dumps using the proper ifaddrmsg
> as the header. Convert existing RTM_GETADDR dumps to use it.
> 
> Signed-off-by: David Ahern <dsahern@gmail.com>

 }
>  
> +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,
...
David Ahern Sept. 30, 2018, 3:37 p.m. UTC | #2
On 9/30/18 3:35 AM, Stephen Hemminger wrote:
> On Sat, 29 Sep 2018 10:59:21 -0700
> David Ahern <dsahern@kernel.org> wrote:
> 
>> From: David Ahern <dsahern@gmail.com>
>>
>> Add rtnl_addrdump_req for address dumps using the proper ifaddrmsg
>> as the header. Convert existing RTM_GETADDR dumps to use it.
>>
>> Signed-off-by: David Ahern <dsahern@gmail.com>
> 
>  }
>>  
>> +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,
> ...
> 

I kept the inline because it is the style everywhere else in the
iproute2 code.
diff mbox series

Patch

diff --git a/include/libnetlink.h b/include/libnetlink.h
index 9d9249e634dc..2d9f6190230c 100644
--- a/include/libnetlink.h
+++ b/include/libnetlink.h
@@ -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,
diff --git a/ip/ipaddress.c b/ip/ipaddress.c
index 8dc6c32fd6d9..f29480ce51d4 100644
--- a/ip/ipaddress.c
+++ b/ip/ipaddress.c
@@ -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);
 		}
diff --git a/lib/libnetlink.c b/lib/libnetlink.c
index f18dceac2b5e..749cf4fbb88e 100644
--- a/lib/libnetlink.c
+++ b/lib/libnetlink.c
@@ -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);