From: David Ahern <dsahern@kernel.org>
To: netdev@vger.kernel.org
Cc: stephen@networkplumber.org, David Ahern <dsahern@gmail.com>
Subject: [PATCH iproute2-next 08/12] ip address: Split ip_linkaddr_list into link and addr functions
Date: Wed, 19 Dec 2018 19:54:23 -0800 [thread overview]
Message-ID: <20181220035427.14453-9-dsahern@kernel.org> (raw)
In-Reply-To: <20181220035427.14453-1-dsahern@kernel.org>
From: David Ahern <dsahern@gmail.com>
Split ip_linkaddr_list into one function that generates a list of devices
and a second that generates the list of addresses.
Signed-off-by: David Ahern <dsahern@gmail.com>
---
ip/ip_common.h | 3 +--
ip/ipaddress.c | 39 ++++++++++++++++++++-------------------
ip/ipvrf.c | 2 +-
3 files changed, 22 insertions(+), 22 deletions(-)
diff --git a/ip/ip_common.h b/ip/ip_common.h
index 53668f598cd2..d67575c63c24 100644
--- a/ip/ip_common.h
+++ b/ip/ip_common.h
@@ -84,8 +84,7 @@ int do_seg6(int argc, char **argv);
int iplink_get(char *name, __u32 filt_mask);
int iplink_ifla_xstats(int argc, char **argv);
-int ip_linkaddr_list(int family, req_filter_fn_t filter_fn,
- struct nlmsg_chain *linfo, struct nlmsg_chain *ainfo);
+int ip_link_list(req_filter_fn_t filter_fn, struct nlmsg_chain *linfo);
void free_nlmsg_chain(struct nlmsg_chain *info);
static inline int rtm_get_table(struct rtmsg *r, struct rtattr **tb)
diff --git a/ip/ipaddress.c b/ip/ipaddress.c
index 016662e910e9..746dbfc58627 100644
--- a/ip/ipaddress.c
+++ b/ip/ipaddress.c
@@ -1766,8 +1766,7 @@ static int iplink_filter_req(struct nlmsghdr *nlh, int reqlen)
* caller can walk lists as desired and must call free_nlmsg_chain for
* both when done
*/
-int ip_linkaddr_list(int family, req_filter_fn_t filter_fn,
- struct nlmsg_chain *linfo, struct nlmsg_chain *ainfo)
+int ip_link_list(req_filter_fn_t filter_fn, struct nlmsg_chain *linfo)
{
if (rtnl_linkdump_req_filter_fn(&rth, preferred_family,
filter_fn) < 0) {
@@ -1780,16 +1779,19 @@ int ip_linkaddr_list(int family, req_filter_fn_t filter_fn,
return 1;
}
- if (ainfo) {
- if (rtnl_addrdump_req(&rth, family) < 0) {
- perror("Cannot send dump request");
- return 1;
- }
+ return 0;
+}
- if (rtnl_dump_filter(&rth, store_nlmsg, ainfo) < 0) {
- fprintf(stderr, "Dump terminated\n");
- return 1;
- }
+static int ip_addr_list(struct nlmsg_chain *ainfo)
+{
+ if (rtnl_addrdump_req(&rth, filter.family) < 0) {
+ perror("Cannot send dump request");
+ return 1;
+ }
+
+ if (rtnl_dump_filter(&rth, store_nlmsg, ainfo) < 0) {
+ fprintf(stderr, "Dump terminated\n");
+ return 1;
}
return 0;
@@ -1798,7 +1800,7 @@ int ip_linkaddr_list(int family, req_filter_fn_t filter_fn,
static int ipaddr_list_flush_or_save(int argc, char **argv, int action)
{
struct nlmsg_chain linfo = { NULL, NULL};
- struct nlmsg_chain _ainfo = { NULL, NULL}, *ainfo = NULL;
+ struct nlmsg_chain _ainfo = { NULL, NULL}, *ainfo = &_ainfo;
struct nlmsg_list *l;
char *filter_dev = NULL;
int no_link = 0;
@@ -1940,19 +1942,18 @@ static int ipaddr_list_flush_or_save(int argc, char **argv, int action)
goto out;
}
- if (filter.family != AF_PACKET) {
- ainfo = &_ainfo;
+ if (ip_link_list(iplink_filter_req, &linfo) != 0)
+ goto out;
+ if (filter.family != AF_PACKET) {
if (filter.oneline)
no_link = 1;
- }
- if (ip_linkaddr_list(filter.family, iplink_filter_req,
- &linfo, ainfo) != 0)
- goto out;
+ if (ip_addr_list(ainfo) != 0)
+ goto out;
- if (filter.family != AF_PACKET)
ipaddr_filter(&linfo, ainfo);
+ }
for (l = linfo.head; l; l = l->next) {
struct nlmsghdr *n = &l->h;
diff --git a/ip/ipvrf.c b/ip/ipvrf.c
index 8a6b7f977b14..08a0d45b2570 100644
--- a/ip/ipvrf.c
+++ b/ip/ipvrf.c
@@ -589,7 +589,7 @@ static int ipvrf_show(int argc, char **argv)
return 0;
}
- if (ip_linkaddr_list(0, ipvrf_filter_req, &linfo, NULL) == 0) {
+ if (ip_link_list(ipvrf_filter_req, &linfo) == 0) {
struct nlmsg_list *l;
unsigned nvrf = 0;
int n;
--
2.11.0
next prev parent reply other threads:[~2018-12-20 3:53 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-12-20 3:54 [PATCH iproute2-next 00/12] Updates for strict checking and kernel side filtering David Ahern
2018-12-20 3:54 ` [PATCH iproute2-next 01/12] libnetlink: dump extack string in done message David Ahern
2018-12-20 3:54 ` [PATCH iproute2-next 02/12] libnetlink: Use NLMSG_LENGTH to set nlmsg_len David Ahern
2018-12-20 3:54 ` [PATCH iproute2-next 03/12] libnetlink: linkdump_req: Only AF_UNSPEC family expects an ext_filter_mask David Ahern
2018-12-20 3:54 ` [PATCH iproute2-next 04/12] ip route: Remove rtnl_rtcache_request David Ahern
2018-12-20 3:54 ` [PATCH iproute2-next 05/12] ip route: Add protocol, table id and device to dump request David Ahern
2018-12-20 3:54 ` [PATCH iproute2-next 06/12] mroute: fix up family handling David Ahern
2018-12-20 3:54 ` [PATCH iproute2-next 07/12] mroute: Add table id attribute for kernel side filtering David Ahern
2018-12-20 3:54 ` David Ahern [this message]
2018-12-20 3:54 ` [PATCH iproute2-next 09/12] ip address: Set device index in dump request David Ahern
2018-12-20 3:54 ` [PATCH iproute2-next 10/12] ip bridge: Set NETLINK_DUMP_STRICT_CHK on socket David Ahern
2018-12-20 3:54 ` [PATCH iproute2-next 11/12] ip route: Rename do_ipv6 to dump_family David Ahern
2018-12-20 3:54 ` [PATCH iproute2-next 12/12] neighbor: Add support for protocol attribute David Ahern
2018-12-30 14:17 ` [PATCH iproute2-next 00/12] Updates for strict checking and kernel side filtering Ido Schimmel
2018-12-30 15:10 ` David Ahern
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20181220035427.14453-9-dsahern@kernel.org \
--to=dsahern@kernel.org \
--cc=dsahern@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=stephen@networkplumber.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.