]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
ip: nexthop: keep cache netlink socket open
authorNikolay Aleksandrov <nikolay@nvidia.com>
Mon, 4 Oct 2021 09:03:28 +0000 (12:03 +0300)
committerDavid Ahern <dsahern@kernel.org>
Tue, 5 Oct 2021 14:34:29 +0000 (08:34 -0600)
Since we use the cache netlink socket for each nexthop we can keep it open
instead of opening and closing it on every add call. The socket is opened
once, on the first add call and then reused for the rest.

Suggested-by: David Ahern <dsahern@gmail.com>
Signed-off-by: Nikolay Aleksandrov <nikolay@nvidia.com>
Signed-off-by: David Ahern <dsahern@kernel.org>
ip/ipnexthop.c

index b4d44a86429cdb93d304e68d78266b402d9d2766..83a5540e771cf2fecca6f9ee8530ef9ba394135d 100644 (file)
@@ -35,6 +35,7 @@ enum {
                        NLMSG_ALIGN(sizeof(struct nhmsg))))
 
 static struct hlist_head nh_cache[NH_CACHE_SIZE];
+static struct rtnl_handle nh_cache_rth = { .fd = -1 };
 
 static void usage(void) __attribute__((noreturn));
 
@@ -563,14 +564,15 @@ static int __ipnh_cache_parse_nlmsg(const struct nlmsghdr *n,
 
 static struct nh_entry *ipnh_cache_add(__u32 nh_id)
 {
-       struct rtnl_handle cache_rth = { .fd = -1 };
        struct nlmsghdr *answer = NULL;
        struct nh_entry *nhe = NULL;
 
-       if (rtnl_open(&cache_rth, 0) < 0)
+       if (nh_cache_rth.fd < 0 && rtnl_open(&nh_cache_rth, 0) < 0) {
+               nh_cache_rth.fd = -1;
                goto out;
+       }
 
-       if (__ipnh_get_id(&cache_rth, nh_id, &answer) < 0)
+       if (__ipnh_get_id(&nh_cache_rth, nh_id, &answer) < 0)
                goto out;
 
        nhe = malloc(sizeof(*nhe));
@@ -585,7 +587,6 @@ static struct nh_entry *ipnh_cache_add(__u32 nh_id)
 out:
        if (answer)
                free(answer);
-       rtnl_close(&cache_rth);
 
        return nhe;