ip: Minor cleanups

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>
This commit is contained in:
Serhey Popovych 2018-01-31 10:15:07 +02:00 committed by David Ahern
parent f7af0dc580
commit 28254695d1
9 changed files with 38 additions and 38 deletions

View File

@ -31,7 +31,7 @@ static void usage(void)
} }
static int vxcan_parse_opt(struct link_util *lu, int argc, char **argv, static int vxcan_parse_opt(struct link_util *lu, int argc, char **argv,
struct nlmsghdr *hdr) struct nlmsghdr *n)
{ {
char *dev = NULL; char *dev = NULL;
char *name = NULL; char *name = NULL;
@ -49,18 +49,18 @@ static int vxcan_parse_opt(struct link_util *lu, int argc, char **argv,
return -1; return -1;
} }
ifm = NLMSG_DATA(hdr); ifm = NLMSG_DATA(n);
ifi_flags = ifm->ifi_flags; ifi_flags = ifm->ifi_flags;
ifi_change = ifm->ifi_change; ifi_change = ifm->ifi_change;
ifm->ifi_flags = 0; ifm->ifi_flags = 0;
ifm->ifi_change = 0; ifm->ifi_change = 0;
data = NLMSG_TAIL(hdr); data = NLMSG_TAIL(n);
addattr_l(hdr, 1024, VXCAN_INFO_PEER, NULL, 0); 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); &name, &type, &link, &dev, &group, &index);
if (err < 0) if (err < 0)
return err; return err;
@ -69,7 +69,7 @@ static int vxcan_parse_opt(struct link_util *lu, int argc, char **argv,
duparg("type", argv[err]); duparg("type", argv[err]);
if (name) { if (name) {
addattr_l(hdr, 1024, addattr_l(n, 1024,
IFLA_IFNAME, name, strlen(name) + 1); 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; ifm->ifi_change = ifi_change;
if (group != -1) 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; return argc - 1 - err;
} }

View File

@ -1132,7 +1132,7 @@ static void usage(FILE *f)
} }
static int macsec_parse_opt(struct link_util *lu, int argc, char **argv, static int macsec_parse_opt(struct link_util *lu, int argc, char **argv,
struct nlmsghdr *hdr) struct nlmsghdr *n)
{ {
int ret; int ret;
__u8 encoding_sa = 0xff; __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 (ret > 0) {
if (sci.sci) if (sci.sci)
addattr_l(hdr, MACSEC_BUFLEN, IFLA_MACSEC_SCI, addattr_l(n, MACSEC_BUFLEN, IFLA_MACSEC_SCI,
&sci.sci, sizeof(sci.sci)); &sci.sci, sizeof(sci.sci));
else else
addattr_l(hdr, MACSEC_BUFLEN, IFLA_MACSEC_PORT, addattr_l(n, MACSEC_BUFLEN, IFLA_MACSEC_PORT,
&sci.port, sizeof(sci.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); ARRAY_SIZE(values_on_off), &i);
if (ret != 0) if (ret != 0)
return ret; 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) { } else if (strcmp(*argv, "send_sci") == 0) {
NEXT_ARG(); NEXT_ARG();
int i; int i;
@ -1193,7 +1193,7 @@ static int macsec_parse_opt(struct link_util *lu, int argc, char **argv,
if (ret != 0) if (ret != 0)
return ret; return ret;
send_sci = i; send_sci = i;
addattr8(hdr, MACSEC_BUFLEN, addattr8(n, MACSEC_BUFLEN,
IFLA_MACSEC_INC_SCI, send_sci); IFLA_MACSEC_INC_SCI, send_sci);
} else if (strcmp(*argv, "end_station") == 0) { } else if (strcmp(*argv, "end_station") == 0) {
NEXT_ARG(); NEXT_ARG();
@ -1204,7 +1204,7 @@ static int macsec_parse_opt(struct link_util *lu, int argc, char **argv,
if (ret != 0) if (ret != 0)
return ret; return ret;
es = i; es = i;
addattr8(hdr, MACSEC_BUFLEN, IFLA_MACSEC_ES, es); addattr8(n, MACSEC_BUFLEN, IFLA_MACSEC_ES, es);
} else if (strcmp(*argv, "scb") == 0) { } else if (strcmp(*argv, "scb") == 0) {
NEXT_ARG(); NEXT_ARG();
int i; int i;
@ -1214,7 +1214,7 @@ static int macsec_parse_opt(struct link_util *lu, int argc, char **argv,
if (ret != 0) if (ret != 0)
return ret; return ret;
scb = i; scb = i;
addattr8(hdr, MACSEC_BUFLEN, IFLA_MACSEC_SCB, scb); addattr8(n, MACSEC_BUFLEN, IFLA_MACSEC_SCB, scb);
} else if (strcmp(*argv, "protect") == 0) { } else if (strcmp(*argv, "protect") == 0) {
NEXT_ARG(); NEXT_ARG();
int i; 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); ARRAY_SIZE(values_on_off), &i);
if (ret != 0) if (ret != 0)
return ret; return ret;
addattr8(hdr, MACSEC_BUFLEN, IFLA_MACSEC_PROTECT, i); addattr8(n, MACSEC_BUFLEN, IFLA_MACSEC_PROTECT, i);
} else if (strcmp(*argv, "replay") == 0) { } else if (strcmp(*argv, "replay") == 0) {
NEXT_ARG(); NEXT_ARG();
int i; int i;
@ -1245,7 +1245,7 @@ static int macsec_parse_opt(struct link_util *lu, int argc, char **argv,
(int *)&validate); (int *)&validate);
if (ret != 0) if (ret != 0)
return ret; return ret;
addattr8(hdr, MACSEC_BUFLEN, addattr8(n, MACSEC_BUFLEN,
IFLA_MACSEC_VALIDATION, validate); IFLA_MACSEC_VALIDATION, validate);
} else if (strcmp(*argv, "encodingsa") == 0) { } else if (strcmp(*argv, "encodingsa") == 0) {
if (encoding_sa != 0xff) if (encoding_sa != 0xff)
@ -1281,20 +1281,20 @@ static int macsec_parse_opt(struct link_util *lu, int argc, char **argv,
} }
if (cipher.id) 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)); &cipher.id, sizeof(cipher.id));
if (cipher.icv_len) 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)); &cipher.icv_len, sizeof(cipher.icv_len));
if (replay_protect != -1) { if (replay_protect != -1) {
addattr32(hdr, MACSEC_BUFLEN, IFLA_MACSEC_WINDOW, window); addattr32(n, MACSEC_BUFLEN, IFLA_MACSEC_WINDOW, window);
addattr8(hdr, MACSEC_BUFLEN, IFLA_MACSEC_REPLAY_PROTECT, addattr8(n, MACSEC_BUFLEN, IFLA_MACSEC_REPLAY_PROTECT,
replay_protect); replay_protect);
} }
if (encoding_sa != 0xff) { 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)); &encoding_sa, sizeof(encoding_sa));
} }

View File

@ -69,7 +69,7 @@ static void usage(void)
static int gre_parse_opt(struct link_util *lu, int argc, char **argv, static int gre_parse_opt(struct link_util *lu, int argc, char **argv,
struct nlmsghdr *n) struct nlmsghdr *n)
{ {
struct ifinfomsg *ifi = (struct ifinfomsg *)(n + 1); struct ifinfomsg *ifi = NLMSG_DATA(n);
struct { struct {
struct nlmsghdr n; struct nlmsghdr n;
struct ifinfomsg i; struct ifinfomsg i;

View File

@ -79,7 +79,7 @@ static void usage(void)
static int gre_parse_opt(struct link_util *lu, int argc, char **argv, static int gre_parse_opt(struct link_util *lu, int argc, char **argv,
struct nlmsghdr *n) struct nlmsghdr *n)
{ {
struct ifinfomsg *ifi = (struct ifinfomsg *)(n + 1); struct ifinfomsg *ifi = NLMSG_DATA(n);
struct { struct {
struct nlmsghdr n; struct nlmsghdr n;
struct ifinfomsg i; struct ifinfomsg i;

View File

@ -72,7 +72,7 @@ static void usage(void)
static int ip6tunnel_parse_opt(struct link_util *lu, int argc, char **argv, static int ip6tunnel_parse_opt(struct link_util *lu, int argc, char **argv,
struct nlmsghdr *n) struct nlmsghdr *n)
{ {
struct ifinfomsg *ifi = (struct ifinfomsg *)(n + 1); struct ifinfomsg *ifi = NLMSG_DATA(n);
struct { struct {
struct nlmsghdr n; struct nlmsghdr n;
struct ifinfomsg i; struct ifinfomsg i;

View File

@ -72,7 +72,7 @@ static void usage(int sit)
static int iptunnel_parse_opt(struct link_util *lu, int argc, char **argv, static int iptunnel_parse_opt(struct link_util *lu, int argc, char **argv,
struct nlmsghdr *n) struct nlmsghdr *n)
{ {
struct ifinfomsg *ifi = (struct ifinfomsg *)(n + 1); struct ifinfomsg *ifi = NLMSG_DATA(n);
struct { struct {
struct nlmsghdr n; struct nlmsghdr n;
struct ifinfomsg i; struct ifinfomsg i;

View File

@ -29,7 +29,7 @@ static void usage(void)
} }
static int veth_parse_opt(struct link_util *lu, int argc, char **argv, static int veth_parse_opt(struct link_util *lu, int argc, char **argv,
struct nlmsghdr *hdr) struct nlmsghdr *n)
{ {
char *dev = NULL; char *dev = NULL;
char *name = NULL; char *name = NULL;
@ -47,18 +47,18 @@ static int veth_parse_opt(struct link_util *lu, int argc, char **argv,
return -1; return -1;
} }
ifm = NLMSG_DATA(hdr); ifm = NLMSG_DATA(n);
ifi_flags = ifm->ifi_flags; ifi_flags = ifm->ifi_flags;
ifi_change = ifm->ifi_change; ifi_change = ifm->ifi_change;
ifm->ifi_flags = 0; ifm->ifi_flags = 0;
ifm->ifi_change = 0; ifm->ifi_change = 0;
data = NLMSG_TAIL(hdr); data = NLMSG_TAIL(n);
addattr_l(hdr, 1024, VETH_INFO_PEER, NULL, 0); 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); &name, &type, &link, &dev, &group, &index);
if (err < 0) if (err < 0)
return err; return err;
@ -67,7 +67,7 @@ static int veth_parse_opt(struct link_util *lu, int argc, char **argv,
duparg("type", argv[err]); duparg("type", argv[err]);
if (name) { if (name) {
addattr_l(hdr, 1024, addattr_l(n, 1024,
IFLA_IFNAME, name, strlen(name) + 1); 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; ifm->ifi_change = ifi_change;
if (group != -1) 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; return argc - 1 - err;
} }

View File

@ -49,7 +49,7 @@ static void usage(void)
static int vti_parse_opt(struct link_util *lu, int argc, char **argv, static int vti_parse_opt(struct link_util *lu, int argc, char **argv,
struct nlmsghdr *n) struct nlmsghdr *n)
{ {
struct ifinfomsg *ifi = (struct ifinfomsg *)(n + 1); struct ifinfomsg *ifi = NLMSG_DATA(n);
struct { struct {
struct nlmsghdr n; struct nlmsghdr n;
struct ifinfomsg i; struct ifinfomsg i;

View File

@ -49,7 +49,7 @@ static void usage(void)
static int vti6_parse_opt(struct link_util *lu, int argc, char **argv, static int vti6_parse_opt(struct link_util *lu, int argc, char **argv,
struct nlmsghdr *n) struct nlmsghdr *n)
{ {
struct ifinfomsg *ifi = (struct ifinfomsg *)(n + 1); struct ifinfomsg *ifi = NLMSG_DATA(n);
struct { struct {
struct nlmsghdr n; struct nlmsghdr n;
struct ifinfomsg i; struct ifinfomsg i;