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>
This commit is contained in:
Denys Vlasenko 2016-08-14 02:08:56 +02:00
parent 34ecc3b7ae
commit 4548293799
2 changed files with 28 additions and 24 deletions

View File

@ -197,8 +197,10 @@ static int iprule_modify(int cmd, char **argv)
req.n.nlmsg_flags = NLM_F_REQUEST; req.n.nlmsg_flags = NLM_F_REQUEST;
req.r.rtm_family = preferred_family; req.r.rtm_family = preferred_family;
req.r.rtm_protocol = RTPROT_BOOT; req.r.rtm_protocol = RTPROT_BOOT;
if (RT_SCOPE_UNIVERSE != 0)
req.r.rtm_scope = RT_SCOPE_UNIVERSE; req.r.rtm_scope = RT_SCOPE_UNIVERSE;
req.r.rtm_table = 0; /*req.r.rtm_table = 0; - already is */
if (RTN_UNSPEC != 0)
req.r.rtm_type = RTN_UNSPEC; req.r.rtm_type = RTN_UNSPEC;
if (cmd == RTM_NEWRULE) { if (cmd == RTM_NEWRULE) {

View File

@ -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) int FAST_FUNC rtnl_dump_request(struct rtnl_handle *rth, int type, void *req, int len)
{ {
struct {
struct nlmsghdr nlh; struct nlmsghdr nlh;
struct msghdr msg;
struct sockaddr_nl nladdr; struct sockaddr_nl nladdr;
struct iovec iov[2] = { { &nlh, sizeof(nlh) }, { req, len } }; } s;
/* Use designated initializers, struct layout is non-portable */ struct iovec iov[2] = { { &s.nlh, sizeof(s.nlh) }, { req, len } };
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)); memset(&s, 0, sizeof(s));
nladdr.nl_family = AF_NETLINK;
nlh.nlmsg_len = NLMSG_LENGTH(len); s.msg.msg_name = (void*)&s.nladdr;
nlh.nlmsg_type = type; s.msg.msg_namelen = sizeof(s.nladdr);
nlh.nlmsg_flags = NLM_F_ROOT|NLM_F_MATCH|NLM_F_REQUEST; s.msg.msg_iov = iov;
nlh.nlmsg_pid = 0; s.msg.msg_iovlen = 2;
nlh.nlmsg_seq = rth->dump = ++rth->seq; /*s.msg.msg_control = NULL; - already is */
/*s.msg.msg_controllen = 0; - already is */
/*s.msg.msg_flags = 0; - already is */
return sendmsg(rth->fd, &msg, 0); 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, static int rtnl_dump_filter(struct rtnl_handle *rth,