]> git.proxmox.com Git - mirror_iproute2.git/commitdiff
ip bridge: Set NETLINK_GET_STRICT_CHK on socket
authorDavid Ahern <dsahern@gmail.com>
Fri, 5 Oct 2018 20:49:41 +0000 (13:49 -0700)
committerDavid Ahern <dsahern@gmail.com>
Thu, 27 Dec 2018 23:36:29 +0000 (15:36 -0800)
iproute2 has been updated for the new strict policy in the kernel. Add a
helper to call setsockopt to enable the feature. Add a call to ip.c and
bridge.c

The setsockopt fails on older kernels and the error can be safely ignored
- any new fields or attributes are ignored by the older kernel.

Signed-off-by: David Ahern <dsahern@gmail.com>
bridge/bridge.c
include/libnetlink.h
ip/ip.c
lib/libnetlink.c

index a3d8154be898e33b6f48a0f2e12fc93f6bd272fb..a50d9d59b4c5a452bf2356f0419e4eee847c0946 100644 (file)
@@ -97,6 +97,8 @@ static int batch(const char *name)
                return EXIT_FAILURE;
        }
 
+       rtnl_set_strict_dump(&rth);
+
        cmdlineno = 0;
        while (getcmdline(&line, &len, stdin) != -1) {
                char *largv[100];
@@ -205,6 +207,8 @@ main(int argc, char **argv)
        if (rtnl_open(&rth, 0) < 0)
                exit(1);
 
+       rtnl_set_strict_dump(&rth);
+
        if (argc > 1)
                return do_cmd(argv[1], argc-1, argv+1);
 
index 2621bc99ce7bdd21d2273c0f5fcbdefb23021443..dc0c9c4eb3f5218c33263dbd1bb1962125c1b533 100644 (file)
@@ -46,6 +46,7 @@ int rtnl_open_byproto(struct rtnl_handle *rth, unsigned int subscriptions,
        __attribute__((warn_unused_result));
 
 void rtnl_close(struct rtnl_handle *rth);
+void rtnl_set_strict_dump(struct rtnl_handle *rth);
 
 typedef int (*req_filter_fn_t)(struct nlmsghdr *nlh, int reqlen);
 
diff --git a/ip/ip.c b/ip/ip.c
index a5bbacb4bb0f589a8305279b66a571c9d1bc1af4..e4131714018f9a843a02cbff2fa9054eae75e75d 100644 (file)
--- a/ip/ip.c
+++ b/ip/ip.c
@@ -308,6 +308,8 @@ int main(int argc, char **argv)
        if (rtnl_open(&rth, 0) < 0)
                exit(1);
 
+       rtnl_set_strict_dump(&rth);
+
        if (strlen(basename) > 2)
                return do_cmd(basename+2, argc, argv);
 
index 0ddd646a87758113843be12185f962485f88925e..4d7d081054fd324c8b92c8bf141b89ab8393db6c 100644 (file)
@@ -161,6 +161,15 @@ static int nl_dump_ext_ack_done(const struct nlmsghdr *nlh, int error)
 }
 #endif
 
+/* Older kernels may not support strict dump and filtering */
+void rtnl_set_strict_dump(struct rtnl_handle *rth)
+{
+       int one = 1;
+
+       setsockopt(rth->fd, SOL_NETLINK, NETLINK_GET_STRICT_CHK,
+                  &one, sizeof(one));
+}
+
 void rtnl_close(struct rtnl_handle *rth)
 {
        if (rth->fd >= 0) {