ip: nexthop: factor out ipnh_get_id rtnl talk into a helper
Factor out ipnh_get_id's rtnl talk portion into a separate helper which will be reused later to retrieve nexthops for caching. Signed-off-by: Nikolay Aleksandrov <nikolay@nvidia.com> Signed-off-by: David Ahern <dsahern@kernel.org>
This commit is contained in:
parent
a2ca431215
commit
53d7c43bd3
|
|
@ -485,6 +485,25 @@ static void __print_nexthop_entry(FILE *fp, const char *jsobj,
|
||||||
close_json_object();
|
close_json_object();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int __ipnh_get_id(struct rtnl_handle *rthp, __u32 nh_id,
|
||||||
|
struct nlmsghdr **answer)
|
||||||
|
{
|
||||||
|
struct {
|
||||||
|
struct nlmsghdr n;
|
||||||
|
struct nhmsg nhm;
|
||||||
|
char buf[1024];
|
||||||
|
} req = {
|
||||||
|
.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct nhmsg)),
|
||||||
|
.n.nlmsg_flags = NLM_F_REQUEST,
|
||||||
|
.n.nlmsg_type = RTM_GETNEXTHOP,
|
||||||
|
.nhm.nh_family = preferred_family,
|
||||||
|
};
|
||||||
|
|
||||||
|
addattr32(&req.n, sizeof(req), NHA_ID, nh_id);
|
||||||
|
|
||||||
|
return rtnl_talk(rthp, &req.n, answer);
|
||||||
|
}
|
||||||
|
|
||||||
int print_nexthop(struct nlmsghdr *n, void *arg)
|
int print_nexthop(struct nlmsghdr *n, void *arg)
|
||||||
{
|
{
|
||||||
struct nhmsg *nhm = NLMSG_DATA(n);
|
struct nhmsg *nhm = NLMSG_DATA(n);
|
||||||
|
|
@ -827,21 +846,9 @@ static int ipnh_modify(int cmd, unsigned int flags, int argc, char **argv)
|
||||||
|
|
||||||
static int ipnh_get_id(__u32 id)
|
static int ipnh_get_id(__u32 id)
|
||||||
{
|
{
|
||||||
struct {
|
|
||||||
struct nlmsghdr n;
|
|
||||||
struct nhmsg nhm;
|
|
||||||
char buf[1024];
|
|
||||||
} req = {
|
|
||||||
.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct nhmsg)),
|
|
||||||
.n.nlmsg_flags = NLM_F_REQUEST,
|
|
||||||
.n.nlmsg_type = RTM_GETNEXTHOP,
|
|
||||||
.nhm.nh_family = preferred_family,
|
|
||||||
};
|
|
||||||
struct nlmsghdr *answer;
|
struct nlmsghdr *answer;
|
||||||
|
|
||||||
addattr32(&req.n, sizeof(req), NHA_ID, id);
|
if (__ipnh_get_id(&rth, id, &answer) < 0)
|
||||||
|
|
||||||
if (rtnl_talk(&rth, &req.n, &answer) < 0)
|
|
||||||
return -2;
|
return -2;
|
||||||
|
|
||||||
new_json_obj(json);
|
new_json_obj(json);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue