]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
ip: Minor cleanups
authorSerhey Popovych <serhe.popovych@gmail.com>
Wed, 31 Jan 2018 08:15:07 +0000 (10:15 +0200)
committerDavid Ahern <dsahern@gmail.com>
Fri, 2 Feb 2018 22:58:26 +0000 (14:58 -0800)
  1) Rename @hdr parameter to @n to be coherent with rest of the parsing
     code.

  2) Use NLMSG_DATA() to get pointer to the data after nlmsghdr instead
     of calculating it directly in ip/tunnel code.

Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com>
Signed-off-by: David Ahern <dsahern@gmail.com>
ip/iplink_vxcan.c
ip/ipmacsec.c
ip/link_gre.c
ip/link_gre6.c
ip/link_ip6tnl.c
ip/link_iptnl.c
ip/link_veth.c
ip/link_vti.c
ip/link_vti6.c

index ed0ad8b98ce87d1b0f8635c0909db02662634b67..87be5a673f7eeb69dbdd8b4bc83d27caef3063b3 100644 (file)
@@ -31,7 +31,7 @@ static void usage(void)
 }
 
 static int vxcan_parse_opt(struct link_util *lu, int argc, char **argv,
-                         struct nlmsghdr *hdr)
+                         struct nlmsghdr *n)
 {
        char *dev = NULL;
        char *name = NULL;
@@ -49,18 +49,18 @@ static int vxcan_parse_opt(struct link_util *lu, int argc, char **argv,
                return -1;
        }
 
-       ifm = NLMSG_DATA(hdr);
+       ifm = NLMSG_DATA(n);
        ifi_flags = ifm->ifi_flags;
        ifi_change = ifm->ifi_change;
        ifm->ifi_flags = 0;
        ifm->ifi_change = 0;
 
-       data = NLMSG_TAIL(hdr);
-       addattr_l(hdr, 1024, VXCAN_INFO_PEER, NULL, 0);
+       data = NLMSG_TAIL(n);
+       addattr_l(n, 1024, VXCAN_INFO_PEER, NULL, 0);
 
-       hdr->nlmsg_len += sizeof(struct ifinfomsg);
+       n->nlmsg_len += sizeof(struct ifinfomsg);
 
-       err = iplink_parse(argc - 1, argv + 1, (struct iplink_req *)hdr,
+       err = iplink_parse(argc - 1, argv + 1, (struct iplink_req *)n,
                           &name, &type, &link, &dev, &group, &index);
        if (err < 0)
                return err;
@@ -69,7 +69,7 @@ static int vxcan_parse_opt(struct link_util *lu, int argc, char **argv,
                duparg("type", argv[err]);
 
        if (name) {
-               addattr_l(hdr, 1024,
+               addattr_l(n, 1024,
                          IFLA_IFNAME, name, strlen(name) + 1);
        }
 
@@ -81,9 +81,9 @@ static int vxcan_parse_opt(struct link_util *lu, int argc, char **argv,
        ifm->ifi_change = ifi_change;
 
        if (group != -1)
-               addattr32(hdr, 1024, IFLA_GROUP, group);
+               addattr32(n, 1024, IFLA_GROUP, group);
 
-       data->rta_len = (void *)NLMSG_TAIL(hdr) - (void *)data;
+       data->rta_len = (void *)NLMSG_TAIL(n) - (void *)data;
        return argc - 1 - err;
 }
 
index 345a7073c76b69e6721cc429a8725fe7100e2112..c0b45f5a12d5cc9bfaf7f5ea3a1fc14fd36b6f12 100644 (file)
@@ -1132,7 +1132,7 @@ static void usage(FILE *f)
 }
 
 static int macsec_parse_opt(struct link_util *lu, int argc, char **argv,
-                           struct nlmsghdr *hdr)
+                           struct nlmsghdr *n)
 {
        int ret;
        __u8 encoding_sa = 0xff;
@@ -1151,10 +1151,10 @@ static int macsec_parse_opt(struct link_util *lu, int argc, char **argv,
 
        if (ret > 0) {
                if (sci.sci)
-                       addattr_l(hdr, MACSEC_BUFLEN, IFLA_MACSEC_SCI,
+                       addattr_l(n, MACSEC_BUFLEN, IFLA_MACSEC_SCI,
                                  &sci.sci, sizeof(sci.sci));
                else
-                       addattr_l(hdr, MACSEC_BUFLEN, IFLA_MACSEC_PORT,
+                       addattr_l(n, MACSEC_BUFLEN, IFLA_MACSEC_PORT,
                                  &sci.port, sizeof(sci.port));
        }
 
@@ -1183,7 +1183,7 @@ static int macsec_parse_opt(struct link_util *lu, int argc, char **argv,
                                     ARRAY_SIZE(values_on_off), &i);
                        if (ret != 0)
                                return ret;
-                       addattr8(hdr, MACSEC_BUFLEN, IFLA_MACSEC_ENCRYPT, i);
+                       addattr8(n, MACSEC_BUFLEN, IFLA_MACSEC_ENCRYPT, i);
                } else if (strcmp(*argv, "send_sci") == 0) {
                        NEXT_ARG();
                        int i;
@@ -1193,7 +1193,7 @@ static int macsec_parse_opt(struct link_util *lu, int argc, char **argv,
                        if (ret != 0)
                                return ret;
                        send_sci = i;
-                       addattr8(hdr, MACSEC_BUFLEN,
+                       addattr8(n, MACSEC_BUFLEN,
                                 IFLA_MACSEC_INC_SCI, send_sci);
                } else if (strcmp(*argv, "end_station") == 0) {
                        NEXT_ARG();
@@ -1204,7 +1204,7 @@ static int macsec_parse_opt(struct link_util *lu, int argc, char **argv,
                        if (ret != 0)
                                return ret;
                        es = i;
-                       addattr8(hdr, MACSEC_BUFLEN, IFLA_MACSEC_ES, es);
+                       addattr8(n, MACSEC_BUFLEN, IFLA_MACSEC_ES, es);
                } else if (strcmp(*argv, "scb") == 0) {
                        NEXT_ARG();
                        int i;
@@ -1214,7 +1214,7 @@ static int macsec_parse_opt(struct link_util *lu, int argc, char **argv,
                        if (ret != 0)
                                return ret;
                        scb = i;
-                       addattr8(hdr, MACSEC_BUFLEN, IFLA_MACSEC_SCB, scb);
+                       addattr8(n, MACSEC_BUFLEN, IFLA_MACSEC_SCB, scb);
                } else if (strcmp(*argv, "protect") == 0) {
                        NEXT_ARG();
                        int i;
@@ -1223,7 +1223,7 @@ static int macsec_parse_opt(struct link_util *lu, int argc, char **argv,
                                     ARRAY_SIZE(values_on_off), &i);
                        if (ret != 0)
                                return ret;
-                       addattr8(hdr, MACSEC_BUFLEN, IFLA_MACSEC_PROTECT, i);
+                       addattr8(n, MACSEC_BUFLEN, IFLA_MACSEC_PROTECT, i);
                } else if (strcmp(*argv, "replay") == 0) {
                        NEXT_ARG();
                        int i;
@@ -1245,7 +1245,7 @@ static int macsec_parse_opt(struct link_util *lu, int argc, char **argv,
                                     (int *)&validate);
                        if (ret != 0)
                                return ret;
-                       addattr8(hdr, MACSEC_BUFLEN,
+                       addattr8(n, MACSEC_BUFLEN,
                                 IFLA_MACSEC_VALIDATION, validate);
                } else if (strcmp(*argv, "encodingsa") == 0) {
                        if (encoding_sa != 0xff)
@@ -1281,20 +1281,20 @@ static int macsec_parse_opt(struct link_util *lu, int argc, char **argv,
        }
 
        if (cipher.id)
-               addattr_l(hdr, MACSEC_BUFLEN, IFLA_MACSEC_CIPHER_SUITE,
+               addattr_l(n, MACSEC_BUFLEN, IFLA_MACSEC_CIPHER_SUITE,
                          &cipher.id, sizeof(cipher.id));
        if (cipher.icv_len)
-               addattr_l(hdr, MACSEC_BUFLEN, IFLA_MACSEC_ICV_LEN,
+               addattr_l(n, MACSEC_BUFLEN, IFLA_MACSEC_ICV_LEN,
                          &cipher.icv_len, sizeof(cipher.icv_len));
 
        if (replay_protect != -1) {
-               addattr32(hdr, MACSEC_BUFLEN, IFLA_MACSEC_WINDOW, window);
-               addattr8(hdr, MACSEC_BUFLEN, IFLA_MACSEC_REPLAY_PROTECT,
+               addattr32(n, MACSEC_BUFLEN, IFLA_MACSEC_WINDOW, window);
+               addattr8(n, MACSEC_BUFLEN, IFLA_MACSEC_REPLAY_PROTECT,
                         replay_protect);
        }
 
        if (encoding_sa != 0xff) {
-               addattr_l(hdr, MACSEC_BUFLEN, IFLA_MACSEC_ENCODING_SA,
+               addattr_l(n, MACSEC_BUFLEN, IFLA_MACSEC_ENCODING_SA,
                          &encoding_sa, sizeof(encoding_sa));
        }
 
index 8fb8fe5d679294de290d05f1418496f9044d85fc..b2573a1b749c5af8fe4e4b364616661039e8eea1 100644 (file)
@@ -69,7 +69,7 @@ static void usage(void)
 static int gre_parse_opt(struct link_util *lu, int argc, char **argv,
                         struct nlmsghdr *n)
 {
-       struct ifinfomsg *ifi = (struct ifinfomsg *)(n + 1);
+       struct ifinfomsg *ifi = NLMSG_DATA(n);
        struct {
                struct nlmsghdr n;
                struct ifinfomsg i;
index 4045f656157233f2d214959ace2fdfe2f9d75878..880b75dafe4d3cae92263d848a02309dd9f93bed 100644 (file)
@@ -79,7 +79,7 @@ static void usage(void)
 static int gre_parse_opt(struct link_util *lu, int argc, char **argv,
                         struct nlmsghdr *n)
 {
-       struct ifinfomsg *ifi = (struct ifinfomsg *)(n + 1);
+       struct ifinfomsg *ifi = NLMSG_DATA(n);
        struct {
                struct nlmsghdr n;
                struct ifinfomsg i;
index ccc79ff91d6c49ac5ac2efca9212c4e4009055b9..91d7d99fe61ec40fd38b18f901dc813259f75275 100644 (file)
@@ -72,7 +72,7 @@ static void usage(void)
 static int ip6tunnel_parse_opt(struct link_util *lu, int argc, char **argv,
                               struct nlmsghdr *n)
 {
-       struct ifinfomsg *ifi = (struct ifinfomsg *)(n + 1);
+       struct ifinfomsg *ifi = NLMSG_DATA(n);
        struct {
                struct nlmsghdr n;
                struct ifinfomsg i;
index 622c6f143632f58756c23a00cd1327e9f32ba77f..3e653b77facfa404849804df407186a3f1eaed3e 100644 (file)
@@ -72,7 +72,7 @@ static void usage(int sit)
 static int iptunnel_parse_opt(struct link_util *lu, int argc, char **argv,
                              struct nlmsghdr *n)
 {
-       struct ifinfomsg *ifi = (struct ifinfomsg *)(n + 1);
+       struct ifinfomsg *ifi = NLMSG_DATA(n);
        struct {
                struct nlmsghdr n;
                struct ifinfomsg i;
index fddb7ac3c6a5cbd62a462cb6ab57247a62dec7c4..e6219e72bdb18a1b21f9eaa9a83b4116fbde829e 100644 (file)
@@ -29,7 +29,7 @@ static void usage(void)
 }
 
 static int veth_parse_opt(struct link_util *lu, int argc, char **argv,
-                         struct nlmsghdr *hdr)
+                         struct nlmsghdr *n)
 {
        char *dev = NULL;
        char *name = NULL;
@@ -47,18 +47,18 @@ static int veth_parse_opt(struct link_util *lu, int argc, char **argv,
                return -1;
        }
 
-       ifm = NLMSG_DATA(hdr);
+       ifm = NLMSG_DATA(n);
        ifi_flags = ifm->ifi_flags;
        ifi_change = ifm->ifi_change;
        ifm->ifi_flags = 0;
        ifm->ifi_change = 0;
 
-       data = NLMSG_TAIL(hdr);
-       addattr_l(hdr, 1024, VETH_INFO_PEER, NULL, 0);
+       data = NLMSG_TAIL(n);
+       addattr_l(n, 1024, VETH_INFO_PEER, NULL, 0);
 
-       hdr->nlmsg_len += sizeof(struct ifinfomsg);
+       n->nlmsg_len += sizeof(struct ifinfomsg);
 
-       err = iplink_parse(argc - 1, argv + 1, (struct iplink_req *)hdr,
+       err = iplink_parse(argc - 1, argv + 1, (struct iplink_req *)n,
                           &name, &type, &link, &dev, &group, &index);
        if (err < 0)
                return err;
@@ -67,7 +67,7 @@ static int veth_parse_opt(struct link_util *lu, int argc, char **argv,
                duparg("type", argv[err]);
 
        if (name) {
-               addattr_l(hdr, 1024,
+               addattr_l(n, 1024,
                          IFLA_IFNAME, name, strlen(name) + 1);
        }
 
@@ -79,9 +79,9 @@ static int veth_parse_opt(struct link_util *lu, int argc, char **argv,
        ifm->ifi_change = ifi_change;
 
        if (group != -1)
-               addattr32(hdr, 1024, IFLA_GROUP, group);
+               addattr32(n, 1024, IFLA_GROUP, group);
 
-       data->rta_len = (void *)NLMSG_TAIL(hdr) - (void *)data;
+       data->rta_len = (void *)NLMSG_TAIL(n) - (void *)data;
        return argc - 1 - err;
 }
 
index a5b84a0759d127e13256d9db04a1fb1846a64325..49b87e99b4fdd3c1a82ba29559531750070ac3c3 100644 (file)
@@ -49,7 +49,7 @@ static void usage(void)
 static int vti_parse_opt(struct link_util *lu, int argc, char **argv,
                         struct nlmsghdr *n)
 {
-       struct ifinfomsg *ifi = (struct ifinfomsg *)(n + 1);
+       struct ifinfomsg *ifi = NLMSG_DATA(n);
        struct {
                struct nlmsghdr n;
                struct ifinfomsg i;
index 39d12e63a4cb97b9c7887376df25791354eeab2c..d1fbec543480909a576b59059b4bee96279954d5 100644 (file)
@@ -49,7 +49,7 @@ static void usage(void)
 static int vti6_parse_opt(struct link_util *lu, int argc, char **argv,
                          struct nlmsghdr *n)
 {
-       struct ifinfomsg *ifi = (struct ifinfomsg *)(n + 1);
+       struct ifinfomsg *ifi = NLMSG_DATA(n);
        struct {
                struct nlmsghdr n;
                struct ifinfomsg i;