ip route: Remove rtnl_rtcache_request
Add a filter option to rtnl_routedump_req and use it to set rtm_flags removing the need for rtnl_rtcache_request for dump requests. Signed-off-by: David Ahern <dsahern@gmail.com>
This commit is contained in:
parent
d97b16b2c9
commit
43fd93ae46
|
|
@ -47,11 +47,14 @@ int rtnl_open_byproto(struct rtnl_handle *rth, unsigned int subscriptions,
|
||||||
|
|
||||||
void rtnl_close(struct rtnl_handle *rth);
|
void rtnl_close(struct rtnl_handle *rth);
|
||||||
|
|
||||||
|
typedef int (*req_filter_fn_t)(struct nlmsghdr *nlh, int reqlen);
|
||||||
|
|
||||||
int rtnl_addrdump_req(struct rtnl_handle *rth, int family)
|
int rtnl_addrdump_req(struct rtnl_handle *rth, int family)
|
||||||
__attribute__((warn_unused_result));
|
__attribute__((warn_unused_result));
|
||||||
int rtnl_addrlbldump_req(struct rtnl_handle *rth, int family)
|
int rtnl_addrlbldump_req(struct rtnl_handle *rth, int family)
|
||||||
__attribute__((warn_unused_result));
|
__attribute__((warn_unused_result));
|
||||||
int rtnl_routedump_req(struct rtnl_handle *rth, int family)
|
int rtnl_routedump_req(struct rtnl_handle *rth, int family,
|
||||||
|
req_filter_fn_t filter_fn)
|
||||||
__attribute__((warn_unused_result));
|
__attribute__((warn_unused_result));
|
||||||
int rtnl_ruledump_req(struct rtnl_handle *rth, int family)
|
int rtnl_ruledump_req(struct rtnl_handle *rth, int family)
|
||||||
__attribute__((warn_unused_result));
|
__attribute__((warn_unused_result));
|
||||||
|
|
@ -71,8 +74,6 @@ int rtnl_linkdump_req(struct rtnl_handle *rth, int fam)
|
||||||
int rtnl_linkdump_req_filter(struct rtnl_handle *rth, int fam, __u32 filt_mask)
|
int rtnl_linkdump_req_filter(struct rtnl_handle *rth, int fam, __u32 filt_mask)
|
||||||
__attribute__((warn_unused_result));
|
__attribute__((warn_unused_result));
|
||||||
|
|
||||||
typedef int (*req_filter_fn_t)(struct nlmsghdr *nlh, int reqlen);
|
|
||||||
|
|
||||||
int rtnl_linkdump_req_filter_fn(struct rtnl_handle *rth, int fam,
|
int rtnl_linkdump_req_filter_fn(struct rtnl_handle *rth, int fam,
|
||||||
req_filter_fn_t fn)
|
req_filter_fn_t fn)
|
||||||
__attribute__((warn_unused_result));
|
__attribute__((warn_unused_result));
|
||||||
|
|
|
||||||
|
|
@ -283,7 +283,7 @@ static int mroute_list(int argc, char **argv)
|
||||||
filter.iif = idx;
|
filter.iif = idx;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rtnl_routedump_req(&rth, filter.af) < 0) {
|
if (rtnl_routedump_req(&rth, filter.af, NULL) < 0) {
|
||||||
perror("Cannot send dump request");
|
perror("Cannot send dump request");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
43
ip/iproute.c
43
ip/iproute.c
|
|
@ -1535,24 +1535,6 @@ static int iproute_modify(int cmd, unsigned int flags, int argc, char **argv)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int rtnl_rtcache_request(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_ROOT | NLM_F_REQUEST,
|
|
||||||
.nlh.nlmsg_seq = rth->dump = ++rth->seq,
|
|
||||||
.rtm.rtm_family = family,
|
|
||||||
.rtm.rtm_flags = RTM_F_CLONED,
|
|
||||||
};
|
|
||||||
struct sockaddr_nl nladdr = { .nl_family = AF_NETLINK };
|
|
||||||
|
|
||||||
return sendto(rth->fd, (void *)&req, sizeof(req), 0, (struct sockaddr *)&nladdr, sizeof(nladdr));
|
|
||||||
}
|
|
||||||
|
|
||||||
static int iproute_flush_cache(void)
|
static int iproute_flush_cache(void)
|
||||||
{
|
{
|
||||||
#define ROUTE_FLUSH_PATH "/proc/sys/net/ipv4/route/flush"
|
#define ROUTE_FLUSH_PATH "/proc/sys/net/ipv4/route/flush"
|
||||||
|
|
@ -1644,7 +1626,7 @@ static int iproute_flush(int do_ipv6, rtnl_filter_t filter_fn)
|
||||||
filter.flushe = sizeof(flushb);
|
filter.flushe = sizeof(flushb);
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
if (rtnl_routedump_req(&rth, do_ipv6) < 0) {
|
if (rtnl_routedump_req(&rth, do_ipv6, NULL) < 0) {
|
||||||
perror("Cannot send dump request");
|
perror("Cannot send dump request");
|
||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
|
|
@ -1684,6 +1666,16 @@ static int iproute_flush(int do_ipv6, rtnl_filter_t filter_fn)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int iproute_dump_filter(struct nlmsghdr *nlh, int reqlen)
|
||||||
|
{
|
||||||
|
struct rtmsg *rtm = NLMSG_DATA(nlh);
|
||||||
|
|
||||||
|
if (filter.cloned)
|
||||||
|
rtm->rtm_flags |= RTM_F_CLONED;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int iproute_list_flush_or_save(int argc, char **argv, int action)
|
static int iproute_list_flush_or_save(int argc, char **argv, int action)
|
||||||
{
|
{
|
||||||
int do_ipv6 = preferred_family;
|
int do_ipv6 = preferred_family;
|
||||||
|
|
@ -1889,16 +1881,9 @@ static int iproute_list_flush_or_save(int argc, char **argv, int action)
|
||||||
if (action == IPROUTE_FLUSH)
|
if (action == IPROUTE_FLUSH)
|
||||||
return iproute_flush(do_ipv6, filter_fn);
|
return iproute_flush(do_ipv6, filter_fn);
|
||||||
|
|
||||||
if (!filter.cloned) {
|
if (rtnl_routedump_req(&rth, do_ipv6, iproute_dump_filter) < 0) {
|
||||||
if (rtnl_routedump_req(&rth, do_ipv6) < 0) {
|
perror("Cannot send dump request");
|
||||||
perror("Cannot send dump request");
|
return -2;
|
||||||
return -2;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (rtnl_rtcache_request(&rth, do_ipv6) < 0) {
|
|
||||||
perror("Cannot send dump request");
|
|
||||||
return -2;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
new_json_obj(json);
|
new_json_obj(json);
|
||||||
|
|
|
||||||
|
|
@ -266,11 +266,13 @@ int rtnl_addrlbldump_req(struct rtnl_handle *rth, int family)
|
||||||
return send(rth->fd, &req, sizeof(req), 0);
|
return send(rth->fd, &req, sizeof(req), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int rtnl_routedump_req(struct rtnl_handle *rth, int family)
|
int rtnl_routedump_req(struct rtnl_handle *rth, int family,
|
||||||
|
req_filter_fn_t filter_fn)
|
||||||
{
|
{
|
||||||
struct {
|
struct {
|
||||||
struct nlmsghdr nlh;
|
struct nlmsghdr nlh;
|
||||||
struct rtmsg rtm;
|
struct rtmsg rtm;
|
||||||
|
char buf[128];
|
||||||
} req = {
|
} req = {
|
||||||
.nlh.nlmsg_len = NLMSG_LENGTH(sizeof(struct rtmsg)),
|
.nlh.nlmsg_len = NLMSG_LENGTH(sizeof(struct rtmsg)),
|
||||||
.nlh.nlmsg_type = RTM_GETROUTE,
|
.nlh.nlmsg_type = RTM_GETROUTE,
|
||||||
|
|
@ -279,6 +281,14 @@ int rtnl_routedump_req(struct rtnl_handle *rth, int family)
|
||||||
.rtm.rtm_family = family,
|
.rtm.rtm_family = family,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (filter_fn) {
|
||||||
|
int err;
|
||||||
|
|
||||||
|
err = filter_fn(&req.nlh, sizeof(req));
|
||||||
|
if (err)
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
return send(rth->fd, &req, sizeof(req), 0);
|
return send(rth->fd, &req, sizeof(req), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue