aboutsummaryrefslogtreecommitdiff
path: root/networking/libiproute
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2016-08-14 02:08:56 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2016-08-14 02:08:56 +0200
commit454829379951cb15d03d7e51ff292addde8548df (patch)
tree29e6ba865e59d7491fd94a0406a178a2d91adabe /networking/libiproute
parent34ecc3b7aefdd6c31e8691bd5485037bbabedbd4 (diff)
downloadbusybox-454829379951cb15d03d7e51ff292addde8548df.tar.gz
libiproute: eliminate some redundant zero stores
function old new delta do_iprule 974 955 -19 rtnl_dump_request 173 146 -27 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-46) Total: -46 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'networking/libiproute')
-rw-r--r--networking/libiproute/iprule.c8
-rw-r--r--networking/libiproute/libnetlink.c50
2 files changed, 31 insertions, 27 deletions
diff --git a/networking/libiproute/iprule.c b/networking/libiproute/iprule.c
index dba64346f..c486834b0 100644
--- a/networking/libiproute/iprule.c
+++ b/networking/libiproute/iprule.c
@@ -197,9 +197,11 @@ static int iprule_modify(int cmd, char **argv)
req.n.nlmsg_flags = NLM_F_REQUEST;
req.r.rtm_family = preferred_family;
req.r.rtm_protocol = RTPROT_BOOT;
- req.r.rtm_scope = RT_SCOPE_UNIVERSE;
- req.r.rtm_table = 0;
- req.r.rtm_type = RTN_UNSPEC;
+ if (RT_SCOPE_UNIVERSE != 0)
+ req.r.rtm_scope = RT_SCOPE_UNIVERSE;
+ /*req.r.rtm_table = 0; - already is */
+ if (RTN_UNSPEC != 0)
+ req.r.rtm_type = RTN_UNSPEC;
if (cmd == RTM_NEWRULE) {
req.n.nlmsg_flags |= NLM_F_CREATE|NLM_F_EXCL;
diff --git a/networking/libiproute/libnetlink.c b/networking/libiproute/libnetlink.c
index cbb5daf95..9d5c6416b 100644
--- a/networking/libiproute/libnetlink.c
+++ b/networking/libiproute/libnetlink.c
@@ -68,30 +68,32 @@ int FAST_FUNC rtnl_send(struct rtnl_handle *rth, char *buf, int len)
int FAST_FUNC rtnl_dump_request(struct rtnl_handle *rth, int type, void *req, int len)
{
- struct nlmsghdr nlh;
- struct sockaddr_nl nladdr;
- struct iovec iov[2] = { { &nlh, sizeof(nlh) }, { req, len } };
- /* Use designated initializers, struct layout is non-portable */
- struct msghdr msg = {
- .msg_name = (void*)&nladdr,
- .msg_namelen = sizeof(nladdr),
- .msg_iov = iov,
- .msg_iovlen = 2,
- .msg_control = NULL,
- .msg_controllen = 0,
- .msg_flags = 0
- };
-
- memset(&nladdr, 0, sizeof(nladdr));
- nladdr.nl_family = AF_NETLINK;
-
- nlh.nlmsg_len = NLMSG_LENGTH(len);
- nlh.nlmsg_type = type;
- nlh.nlmsg_flags = NLM_F_ROOT|NLM_F_MATCH|NLM_F_REQUEST;
- nlh.nlmsg_pid = 0;
- nlh.nlmsg_seq = rth->dump = ++rth->seq;
-
- return sendmsg(rth->fd, &msg, 0);
+ struct {
+ struct nlmsghdr nlh;
+ struct msghdr msg;
+ struct sockaddr_nl nladdr;
+ } s;
+ struct iovec iov[2] = { { &s.nlh, sizeof(s.nlh) }, { req, len } };
+
+ memset(&s, 0, sizeof(s));
+
+ s.msg.msg_name = (void*)&s.nladdr;
+ s.msg.msg_namelen = sizeof(s.nladdr);
+ s.msg.msg_iov = iov;
+ s.msg.msg_iovlen = 2;
+ /*s.msg.msg_control = NULL; - already is */
+ /*s.msg.msg_controllen = 0; - already is */
+ /*s.msg.msg_flags = 0; - already is */
+
+ s.nladdr.nl_family = AF_NETLINK;
+
+ s.nlh.nlmsg_len = NLMSG_LENGTH(len);
+ s.nlh.nlmsg_type = type;
+ s.nlh.nlmsg_flags = NLM_F_ROOT|NLM_F_MATCH|NLM_F_REQUEST;
+ /*s.nlh.nlmsg_pid = 0; - already is */
+ s.nlh.nlmsg_seq = rth->dump = ++rth->seq;
+
+ return sendmsg(rth->fd, &s.msg, 0);
}
static int rtnl_dump_filter(struct rtnl_handle *rth,