ip address: Split ip_linkaddr_list into link and addr functions
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>
This commit is contained in:
parent
e41ede8939
commit
7ca9cee8d8
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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 (filter.oneline)
|
||||
no_link = 1;
|
||||
}
|
||||
|
||||
if (ip_linkaddr_list(filter.family, iplink_filter_req,
|
||||
&linfo, ainfo) != 0)
|
||||
if (ip_link_list(iplink_filter_req, &linfo) != 0)
|
||||
goto out;
|
||||
|
||||
if (filter.family != AF_PACKET)
|
||||
if (filter.family != AF_PACKET) {
|
||||
if (filter.oneline)
|
||||
no_link = 1;
|
||||
|
||||
if (ip_addr_list(ainfo) != 0)
|
||||
goto out;
|
||||
|
||||
ipaddr_filter(&linfo, ainfo);
|
||||
}
|
||||
|
||||
for (l = linfo.head; l; l = l->next) {
|
||||
struct nlmsghdr *n = &l->h;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in New Issue