chiark / gitweb /
networkd: route - allow routes without a gateway
[elogind.git] / src / network / networkd-route.c
index 77c2daddc50f052339062812b332aa2263d83606..82c9e002fdd337942dd666570f88d7826a8c4662 100644 (file)
@@ -22,6 +22,7 @@
 #include <net/if.h>
 
 #include "networkd.h"
+#include "networkd-link.h"
 
 #include "utf8.h"
 #include "util.h"
@@ -117,13 +118,15 @@ int route_drop(Route *route, Link *link,
                 return r;
         }
 
-        if (route->family == AF_INET)
-                r = sd_rtnl_message_append_in_addr(req, RTA_GATEWAY, &route->in_addr.in);
-        else if (route->family == AF_INET6)
-                r = sd_rtnl_message_append_in6_addr(req, RTA_GATEWAY, &route->in_addr.in6);
-        if (r < 0) {
-                log_error("Could not append RTA_GATEWAY attribute: %s", strerror(-r));
-                return r;
+        if (!in_addr_is_null(route->family, &route->in_addr)) {
+                if (route->family == AF_INET)
+                        r = sd_rtnl_message_append_in_addr(req, RTA_GATEWAY, &route->in_addr.in);
+                else if (route->family == AF_INET6)
+                        r = sd_rtnl_message_append_in6_addr(req, RTA_GATEWAY, &route->in_addr.in6);
+                if (r < 0) {
+                        log_error("Could not append RTA_GATEWAY attribute: %s", strerror(-r));
+                        return r;
+                }
         }
 
         if (route->dst_prefixlen) {
@@ -143,6 +146,17 @@ int route_drop(Route *route, Link *link,
                 }
         }
 
+        if (!in_addr_is_null(route->family, &route->prefsrc_addr)) {
+                if (route->family == AF_INET)
+                        r = sd_rtnl_message_append_in_addr(req, RTA_PREFSRC, &route->prefsrc_addr.in);
+                else if (route->family == AF_INET6)
+                        r = sd_rtnl_message_append_in6_addr(req, RTA_PREFSRC, &route->prefsrc_addr.in6);
+                if (r < 0) {
+                        log_error("Could not append RTA_PREFSRC attribute: %s", strerror(-r));
+                        return r;
+                }
+        }
+
         r = sd_rtnl_message_route_set_scope(req, route->scope);
         if (r < 0) {
                 log_error("Could not set scope: %s", strerror(-r));
@@ -191,13 +205,15 @@ int route_configure(Route *route, Link *link,
                 return r;
         }
 
-        if (route->family == AF_INET)
-                r = sd_rtnl_message_append_in_addr(req, RTA_GATEWAY, &route->in_addr.in);
-        else if (route->family == AF_INET6)
-                r = sd_rtnl_message_append_in6_addr(req, RTA_GATEWAY, &route->in_addr.in6);
-        if (r < 0) {
-                log_error("Could not append RTA_GATEWAY attribute: %s", strerror(-r));
-                return r;
+        if (!in_addr_is_null(route->family, &route->in_addr)) {
+                if (route->family == AF_INET)
+                        r = sd_rtnl_message_append_in_addr(req, RTA_GATEWAY, &route->in_addr.in);
+                else if (route->family == AF_INET6)
+                        r = sd_rtnl_message_append_in6_addr(req, RTA_GATEWAY, &route->in_addr.in6);
+                if (r < 0) {
+                        log_error("Could not append RTA_GATEWAY attribute: %s", strerror(-r));
+                        return r;
+                }
         }
 
         if (route->dst_prefixlen) {
@@ -217,6 +233,17 @@ int route_configure(Route *route, Link *link,
                 }
         }
 
+        if (!in_addr_is_null(route->family, &route->prefsrc_addr)) {
+                if (route->family == AF_INET)
+                        r = sd_rtnl_message_append_in_addr(req, RTA_PREFSRC, &route->prefsrc_addr.in);
+                else if (route->family == AF_INET6)
+                        r = sd_rtnl_message_append_in6_addr(req, RTA_PREFSRC, &route->prefsrc_addr.in6);
+                if (r < 0) {
+                        log_error("Could not append RTA_PREFSRC attribute: %s", strerror(-r));
+                        return r;
+                }
+        }
+
         r = sd_rtnl_message_route_set_scope(req, route->scope);
         if (r < 0) {
                 log_error("Could not set scope: %s", strerror(-r));