chiark / gitweb /
rtnl: simplify route_new()
authorTom Gundersen <teg@jklm.no>
Sat, 7 Dec 2013 20:18:44 +0000 (21:18 +0100)
committerTom Gundersen <teg@jklm.no>
Mon, 16 Dec 2013 16:28:18 +0000 (17:28 +0100)
Drop most of the arguments and instead introduce set_dst_prefixlen().

src/libsystemd-rtnl/rtnl-message.c
src/libsystemd-rtnl/test-rtnl.c
src/network/networkd-route.c
src/systemd/sd-rtnl.h

index 8a3aa63..f8f2bcd 100644 (file)
@@ -125,15 +125,23 @@ bool message_type_is_addr(uint16_t type) {
         }
 }
 
+int sd_rtnl_message_route_set_dst_prefixlen(sd_rtnl_message *m, unsigned char prefixlen) {
+        struct rtmsg *rtm;
+
+        rtm = NLMSG_DATA(m->hdr);
+
+        rtm->rtm_dst_len = prefixlen;
+
+        return 0;
+}
+
 int sd_rtnl_message_route_new(uint16_t nlmsg_type, unsigned char rtm_family,
-                              unsigned char rtm_dst_len, unsigned char rtm_src_len,
-                              unsigned char rtm_tos, unsigned char rtm_table,
-                              unsigned char rtm_scope, unsigned char rtm_protocol,
-                              unsigned char rtm_type, unsigned rtm_flags, sd_rtnl_message **ret) {
+                              sd_rtnl_message **ret) {
         struct rtmsg *rtm;
         int r;
 
         assert_return(message_type_is_route(nlmsg_type), -EINVAL);
+        assert_return(rtm_family == AF_INET || rtm_family == AF_INET6, -EINVAL);
         assert_return(ret, -EINVAL);
 
         r = message_new(ret, NLMSG_SPACE(sizeof(struct rtmsg)));
@@ -148,14 +156,10 @@ int sd_rtnl_message_route_new(uint16_t nlmsg_type, unsigned char rtm_family,
         rtm = NLMSG_DATA((*ret)->hdr);
 
         rtm->rtm_family = rtm_family;
-        rtm->rtm_dst_len = rtm_dst_len;
-        rtm->rtm_src_len = rtm_src_len;
-        rtm->rtm_tos = rtm_tos;
-        rtm->rtm_table = rtm_table;
-        rtm->rtm_protocol = rtm_protocol;
-        rtm->rtm_scope = rtm_scope;
-        rtm->rtm_type = rtm_type;
-        rtm->rtm_flags = rtm_flags;
+        rtm->rtm_scope = RT_SCOPE_UNIVERSE;
+        rtm->rtm_type = RTN_UNICAST;
+        rtm->rtm_table = RT_TABLE_MAIN;
+        rtm->rtm_protocol = RTPROT_BOOT;
 
         return 0;
 }
index 409a0fa..bfcfc85 100644 (file)
@@ -65,9 +65,7 @@ static void test_route(void) {
         void *data;
         int r;
 
-        r = sd_rtnl_message_route_new(RTM_NEWROUTE, AF_INET, 0, 0, 0,
-                                      RT_TABLE_MAIN, RT_SCOPE_UNIVERSE, RTPROT_BOOT,
-                                      RTN_UNICAST, 0, &req);
+        r = sd_rtnl_message_route_new(RTM_NEWROUTE, AF_INET, &req);
         if (r < 0) {
                 log_error("Could not create RTM_NEWROUTE message: %s", strerror(-r));
                 return;
index 1ea6237..f8580e9 100644 (file)
@@ -86,9 +86,7 @@ int route_configure(Route *route, Link *link,
         assert(link->ifindex > 0);
         assert(route->family == AF_INET || route->family == AF_INET6);
 
-        r = sd_rtnl_message_route_new(RTM_NEWROUTE, route->family, route->dst_prefixlen,
-                                      0, 0, RT_TABLE_MAIN, RT_SCOPE_UNIVERSE,
-                                      RTPROT_BOOT, RTN_UNICAST, 0, &req);
+        r = sd_rtnl_message_route_new(RTM_NEWROUTE, route->family, &req);
         if (r < 0) {
                 log_error("Could not create RTM_NEWROUTE message: %s", strerror(-r));
                 return r;
@@ -106,6 +104,12 @@ int route_configure(Route *route, Link *link,
                 return r;
         }
 
+        r = sd_rtnl_message_route_set_dst_prefixlen(req, route->dst_prefixlen);
+        if (r < 0) {
+                log_error("Could not set destination prefix length: %s", strerror(-r));
+                return r;
+        }
+
         r = sd_rtnl_message_append(req, RTA_OIF, &link->ifindex);
         if (r < 0) {
                 log_error("Could not append RTA_OIF attribute: %s", strerror(-r));
index 066d778..f851afa 100644 (file)
@@ -69,10 +69,13 @@ int sd_rtnl_message_addr_new(uint16_t msg_type, int index, unsigned char family,
                              unsigned char prefixlen, unsigned char flags,
                              unsigned char scope, sd_rtnl_message **ret);
 int sd_rtnl_message_route_new(uint16_t nlmsg_type, unsigned char rtm_family,
+                              sd_rtnl_message **ret);
+/*
                               unsigned char rtm_dst_len, unsigned char rtm_src_len,
                               unsigned char rtm_tos, unsigned char rtm_table,
                               unsigned char rtm_scope, unsigned char rtm_protocol,
                               unsigned char rtm_type, unsigned flags, sd_rtnl_message **ret);
+*/
 sd_rtnl_message *sd_rtnl_message_ref(sd_rtnl_message *m);
 sd_rtnl_message *sd_rtnl_message_unref(sd_rtnl_message *m);
 
@@ -84,6 +87,8 @@ int sd_rtnl_message_link_set_type(sd_rtnl_message *m, unsigned type);
 int sd_rtnl_message_link_get_ifindex(sd_rtnl_message *m, int *ifindex);
 int sd_rtnl_message_link_get_flags(sd_rtnl_message *m, unsigned *flags);
 
+int sd_rtnl_message_route_set_dst_prefixlen(sd_rtnl_message *m, unsigned char prefixlen);
+
 int sd_rtnl_message_append(sd_rtnl_message *m, unsigned short type, const void *data);
 int sd_rtnl_message_open_container(sd_rtnl_message *m, unsigned short type);
 int sd_rtnl_message_close_container(sd_rtnl_message *m);