]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
networkd: route - simplify route_new()
authorTom Gundersen <teg@jklm.no>
Fri, 9 Oct 2015 21:43:52 +0000 (23:43 +0200)
committerTom Gundersen <teg@jklm.no>
Wed, 21 Oct 2015 01:24:23 +0000 (03:24 +0200)
src/network/networkd-dhcp4.c
src/network/networkd-ipv4ll.c
src/network/networkd-route.c
src/network/networkd-route.h

index 6ba16581f8754ac6906c4ba3cd91a751f7a28389..22594a9415505a950a92413970f41c904c5fe7cb 100644 (file)
@@ -72,11 +72,13 @@ static int link_set_dhcp_routes(Link *link) {
                 if (r < 0)
                         return log_link_warning_errno(link, r, "DHCP error: could not get address: %m");
 
-                r = route_new(&route, RTPROT_DHCP);
+                r = route_new(&route);
                 if (r < 0)
                         return log_link_error_errno(link, r, "Could not allocate route: %m");
 
-                r = route_new(&route_gw, RTPROT_DHCP);
+                route->protocol = RTPROT_DHCP;
+
+                r = route_new(&route_gw);
                 if (r < 0)
                         return log_link_error_errno(link, r,  "Could not allocate route: %m");
 
@@ -88,6 +90,7 @@ static int link_set_dhcp_routes(Link *link) {
                 route_gw->dst_prefixlen = 32;
                 route_gw->prefsrc_addr.in = address;
                 route_gw->scope = RT_SCOPE_LINK;
+                route_gw->protocol = RTPROT_DHCP;
                 route_gw->metrics = link->network->dhcp_route_metric;
 
                 r = route_configure(route_gw, link, &dhcp4_route_handler);
@@ -120,11 +123,12 @@ static int link_set_dhcp_routes(Link *link) {
         for (i = 0; i < n; i++) {
                 _cleanup_route_free_ Route *route = NULL;
 
-                r = route_new(&route, RTPROT_DHCP);
+                r = route_new(&route);
                 if (r < 0)
                         return log_link_error_errno(link, r, "Could not allocate route: %m");
 
                 route->family = AF_INET;
+                route->protocol = RTPROT_DHCP;
                 route->in_addr.in = static_routes[i].gw_addr;
                 route->dst_addr.in = static_routes[i].dst_addr;
                 route->dst_prefixlen = static_routes[i].dst_prefixlen;
@@ -162,7 +166,7 @@ static int dhcp_lease_lost(Link *link) {
                         for (i = 0; i < n; i++) {
                                 _cleanup_route_free_ Route *route = NULL;
 
-                                r = route_new(&route, RTPROT_UNSPEC);
+                                r = route_new(&route);
                                 if (r >= 0) {
                                         route->family = AF_INET;
                                         route->in_addr.in = routes[i].gw_addr;
@@ -183,7 +187,7 @@ static int dhcp_lease_lost(Link *link) {
                         _cleanup_route_free_ Route *route_gw = NULL;
                         _cleanup_route_free_ Route *route = NULL;
 
-                        r = route_new(&route_gw, RTPROT_UNSPEC);
+                        r = route_new(&route_gw);
                         if (r >= 0) {
                                 route_gw->family = AF_INET;
                                 route_gw->dst_addr.in = gateway;
@@ -194,7 +198,7 @@ static int dhcp_lease_lost(Link *link) {
                                            &link_route_remove_handler);
                         }
 
-                        r = route_new(&route, RTPROT_UNSPEC);
+                        r = route_new(&route);
                         if (r >= 0) {
                                 route->family = AF_INET;
                                 route->in_addr.in = gateway;
index 26397b273f28aae084d0e9cf3ecc0f58ff52e757..2fdb77ef6c5a64e6f0e44d24f85d314742266e92 100644 (file)
@@ -55,7 +55,7 @@ static int ipv4ll_address_lost(Link *link) {
 
         address_remove(address, link, &link_address_remove_handler);
 
-        r = route_new(&route, RTPROT_UNSPEC);
+        r = route_new(&route);
         if (r < 0) {
                 log_link_error_errno(link, r, "Could not allocate route: %m");
                 return r;
@@ -149,12 +149,13 @@ static int ipv4ll_address_claimed(sd_ipv4ll *ll, Link *link) {
 
         link->ipv4ll_address = false;
 
-        r = route_new(&route, RTPROT_STATIC);
+        r = route_new(&route);
         if (r < 0)
                 return r;
 
         route->family = AF_INET;
         route->scope = RT_SCOPE_LINK;
+        route->protocol = RTPROT_STATIC;
         route->metrics = IPV4LL_ROUTE_METRIC;
 
         r = route_configure(route, link, ipv4ll_route_handler);
index 1c8302ffaa9360b7e047a221cdea3022f0debf14..66b165f661ec42bab3b42b6ac7b6b85445c362b7 100644 (file)
@@ -26,7 +26,7 @@
 #include "networkd.h"
 #include "networkd-route.h"
 
-int route_new(Route **ret, unsigned char rtm_protocol) {
+int route_new(Route **ret) {
         _cleanup_route_free_ Route *route = NULL;
 
         route = new0(Route, 1);
@@ -35,7 +35,7 @@ int route_new(Route **ret, unsigned char rtm_protocol) {
 
         route->family = AF_UNSPEC;
         route->scope = RT_SCOPE_UNIVERSE;
-        route->protocol = rtm_protocol;
+        route->protocol = RTPROT_UNSPEC;
 
         *ret = route;
         route = NULL;
@@ -58,10 +58,11 @@ int route_new_static(Network *network, unsigned section, Route **ret) {
                 }
         }
 
-        r = route_new(&route, RTPROT_STATIC);
+        r = route_new(&route);
         if (r < 0)
                 return r;
 
+        route->protocol = RTPROT_STATIC;
         route->network = network;
 
         LIST_PREPEND(routes, network->static_routes, route);
index e3ed1be86671497b76871363e48863b00ba2d5f2..7f2d7f37f499eaf7a10d16f5a9b2b94daf476a88 100644 (file)
@@ -46,7 +46,7 @@ struct Route {
 };
 
 int route_new_static(Network *network, unsigned section, Route **ret);
-int route_new(Route **ret, unsigned char rtm_protocol);
+int route_new(Route **ret);
 void route_free(Route *route);
 int route_configure(Route *route, Link *link, sd_netlink_message_handler_t callback);
 int route_remove(Route *route, Link *link, sd_netlink_message_handler_t callback);