From: Serhey Popovych <serhe.popovych@gmail.com>
To: netdev@vger.kernel.org
Cc: dsahern@gmail.com
Subject: [PATCH iproute2-next v3 5/8] veth,vxcan: Save/reinitialize/restore whole @struct ifinfomsg
Date: Thu, 22 Feb 2018 15:02:03 +0200 [thread overview]
Message-ID: <1519304526-18848-6-git-send-email-serhe.popovych@gmail.com> (raw)
In-Reply-To: <1519304526-18848-1-git-send-email-serhe.popovych@gmail.com>
Now in iplink_parse() we use ->ifi_change and ->ifi_flags fields and
plan to use ->ifi_index with upcoming change.
Saving, restoring and reinitializing individual fields is error prone:
using new field in iplink_parse() without updating callers in veth and
vxcan will overwrite main device ifinfomsg data.
Since @struct ifinfomsg is small enough with known sizeof() compiler may
inline memcpy()/memset() with few load/store instructions.
Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com>
---
ip/iplink_vxcan.c | 22 ++++++++--------------
ip/link_veth.c | 22 ++++++++--------------
2 files changed, 16 insertions(+), 28 deletions(-)
diff --git a/ip/iplink_vxcan.c b/ip/iplink_vxcan.c
index ebe9e56..d7e94a0 100644
--- a/ip/iplink_vxcan.c
+++ b/ip/iplink_vxcan.c
@@ -38,11 +38,10 @@ static int vxcan_parse_opt(struct link_util *lu, int argc, char **argv,
char *link = NULL;
char *type = NULL;
int index = 0;
+ int group;
int err;
struct rtattr *data;
- int group;
- struct ifinfomsg *ifm, *peer_ifm;
- unsigned int ifi_flags, ifi_change;
+ struct ifinfomsg ifm_save, *ifm, *peer_ifm;
if (strcmp(argv[0], "peer") != 0) {
usage();
@@ -50,10 +49,8 @@ static int vxcan_parse_opt(struct link_util *lu, int argc, char **argv,
}
ifm = NLMSG_DATA(n);
- ifi_flags = ifm->ifi_flags;
- ifi_change = ifm->ifi_change;
- ifm->ifi_flags = 0;
- ifm->ifi_change = 0;
+ memcpy(&ifm_save, ifm, sizeof(*ifm));
+ memset(ifm, 0, sizeof(*ifm));
data = addattr_nest(n, 1024, VXCAN_INFO_PEER);
@@ -72,16 +69,13 @@ static int vxcan_parse_opt(struct link_util *lu, int argc, char **argv,
IFLA_IFNAME, name, strlen(name) + 1);
}
- peer_ifm = RTA_DATA(data);
- peer_ifm->ifi_index = index;
- peer_ifm->ifi_flags = ifm->ifi_flags;
- peer_ifm->ifi_change = ifm->ifi_change;
- ifm->ifi_flags = ifi_flags;
- ifm->ifi_change = ifi_change;
-
if (group != -1)
addattr32(n, 1024, IFLA_GROUP, group);
+ peer_ifm = RTA_DATA(data);
+ memcpy(peer_ifm, ifm, sizeof(*ifm));
+ memcpy(ifm, &ifm_save, sizeof(*ifm));
+
addattr_nest_end(n, data);
return argc - 1 - err;
}
diff --git a/ip/link_veth.c b/ip/link_veth.c
index a8e7cf7..b6d37b9 100644
--- a/ip/link_veth.c
+++ b/ip/link_veth.c
@@ -36,11 +36,10 @@ static int veth_parse_opt(struct link_util *lu, int argc, char **argv,
char *link = NULL;
char *type = NULL;
int index = 0;
+ int group;
int err;
struct rtattr *data;
- int group;
- struct ifinfomsg *ifm, *peer_ifm;
- unsigned int ifi_flags, ifi_change;
+ struct ifinfomsg ifm_save, *ifm, *peer_ifm;
if (strcmp(argv[0], "peer") != 0) {
usage();
@@ -48,10 +47,8 @@ static int veth_parse_opt(struct link_util *lu, int argc, char **argv,
}
ifm = NLMSG_DATA(n);
- ifi_flags = ifm->ifi_flags;
- ifi_change = ifm->ifi_change;
- ifm->ifi_flags = 0;
- ifm->ifi_change = 0;
+ memcpy(&ifm_save, ifm, sizeof(*ifm));
+ memset(ifm, 0, sizeof(*ifm));
data = addattr_nest(n, 1024, VETH_INFO_PEER);
@@ -70,16 +67,13 @@ static int veth_parse_opt(struct link_util *lu, int argc, char **argv,
IFLA_IFNAME, name, strlen(name) + 1);
}
- peer_ifm = RTA_DATA(data);
- peer_ifm->ifi_index = index;
- peer_ifm->ifi_flags = ifm->ifi_flags;
- peer_ifm->ifi_change = ifm->ifi_change;
- ifm->ifi_flags = ifi_flags;
- ifm->ifi_change = ifi_change;
-
if (group != -1)
addattr32(n, 1024, IFLA_GROUP, group);
+ peer_ifm = RTA_DATA(data);
+ memcpy(peer_ifm, ifm, sizeof(*ifm));
+ memcpy(ifm, &ifm_save, sizeof(*ifm));
+
addattr_nest_end(n, data);
return argc - 1 - err;
}
--
1.7.10.4
next prev parent reply other threads:[~2018-02-22 13:02 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-22 13:01 [PATCH iproute2-next v3 0/8] iplink: Improve iplink_parse() Serhey Popovych
2018-02-22 13:01 ` [PATCH iproute2-next v3 1/8] utils: Introduce and use nodev() helper routine Serhey Popovych
2018-02-22 13:02 ` [PATCH iproute2-next v3 2/8] iplink: Correctly report error when network device isn't found Serhey Popovych
2018-02-23 23:41 ` David Ahern
2018-02-25 12:07 ` Serhey Popovych
2018-02-22 13:02 ` [PATCH iproute2-next v3 3/8] iplink: Use "dev" and "name" parameters interchangeable when possible Serhey Popovych
2018-02-22 13:02 ` [PATCH iproute2-next v3 4/8] iplink: Follow documented behaviour when "index" is given Serhey Popovych
2018-02-22 13:02 ` Serhey Popovych [this message]
2018-02-26 3:28 ` [PATCH iproute2-next v3 5/8] veth,vxcan: Save/reinitialize/restore whole @struct ifinfomsg David Ahern
2018-02-26 15:48 ` Serhey Popovych
2018-02-26 15:57 ` Serhey Popovych
2018-02-22 13:02 ` [PATCH iproute2-next v3 6/8] iplink: Perform most of request buffer setups and checks in iplink_parse() Serhey Popovych
2018-02-26 3:31 ` David Ahern
2018-02-26 15:51 ` Serhey Popovych
2018-02-22 13:02 ` [PATCH iproute2-next v3 7/8] iplink: Move data structures to block of their users Serhey Popovych
2018-02-22 13:02 ` [PATCH iproute2-next v3 8/8] iplink: Reduce number of arguments to iplink_parse() Serhey Popovych
2018-02-26 3:35 ` David Ahern
2018-02-26 15:44 ` Serhey Popovych
2018-02-26 16:07 ` Serhey Popovych
2018-02-26 18:06 ` Stephen Hemminger
2018-02-26 18:20 ` Serhey Popovych
2018-02-26 18:27 ` David Ahern
2018-02-26 18:38 ` Serhey Popovych
2018-02-26 20:09 ` Serhey Popovych
2018-02-26 21:35 ` Stephen Hemminger
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1519304526-18848-6-git-send-email-serhe.popovych@gmail.com \
--to=serhe.popovych@gmail.com \
--cc=dsahern@gmail.com \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).