Preinitialize more fields of the RTNL request
authorFelix Fietkau <nbd@openwrt.org>
Wed, 11 Aug 2010 15:53:07 +0000 (17:53 +0200)
committerFelix Fietkau <nbd@openwrt.org>
Wed, 11 Aug 2010 16:21:14 +0000 (18:21 +0200)
route.c

diff --git a/route.c b/route.c
index 5425d51..3be2a97 100644 (file)
--- a/route.c
+++ b/route.c
@@ -52,24 +52,29 @@ static void rtnl_route_set(struct relayd_host *host, bool add)
                        struct rtattr rta;
                        int ifindex;
                } __packed dev;
-       } __packed req;
-
-       memset(&req, 0, sizeof(req));
-
-       req.nl.nlmsg_len = sizeof(req);
-       req.rt.rtm_family = AF_INET;
-       req.rt.rtm_dst_len = 32;
+       } __packed req = {
+               .nl = {
+                       .nlmsg_len = sizeof(req),
+               },
+               .rt = {
+                       .rtm_family = AF_INET,
+                       .rtm_dst_len = 32,
+                       .rtm_table = RT_TABLE_MAIN,
+               },
+               .dst.rta = {
+                       .rta_type = RTA_DST,
+                       .rta_len = sizeof(req.dst),
+               },
+               .dev.rta = {
+                       .rta_type = RTA_OIF,
+                       .rta_len = sizeof(req.dev),
+               },
+       };
 
-       req.dst.rta.rta_type = RTA_DST;
-       req.dst.rta.rta_len = sizeof(req.dst);
        memcpy(req.dst.ipaddr, host->ipaddr, sizeof(req.dst.ipaddr));
-
-       req.dev.rta.rta_type = RTA_OIF;
-       req.dev.rta.rta_len = sizeof(req.dev);
        req.dev.ifindex = host->rif->sll.sll_ifindex;
 
        req.nl.nlmsg_flags = NLM_F_REQUEST;
-       req.rt.rtm_table = RT_TABLE_MAIN;
        if (add) {
                req.nl.nlmsg_type = RTM_NEWROUTE;
                req.nl.nlmsg_flags |= NLM_F_CREATE | NLM_F_REPLACE;