|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
From 46b0c76e2c355c0d0cc4792abb98cde07b28bc53 Mon Sep 17 00:00:00 2001
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
From: Emil Renner Berthing <systemd@esmil.dk>
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
Date: Fri, 5 Sep 2014 11:56:02 +0200
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
Subject: [PATCH] networkd: add preferred source to dhcp4 gateway route
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
This makes DHCPv4 and IPv4LL coexist peacefully.
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
[tomegun: apply to both the dhcp routes, use in_addr_is_null() rather than a
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
separate variable to indicate when prefsrc should be applied]
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
---
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
src/network/networkd-dhcp4.c | 11 +++++++++++
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
src/network/networkd-route.c | 22 ++++++++++++++++++++++
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
src/network/networkd.h | 1 +
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
3 files changed, 34 insertions(+)
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
diff --git a/src/network/networkd-dhcp4.c b/src/network/networkd-dhcp4.c
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
index 5e4ff2b80b..b87fa73082 100644
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
--- a/src/network/networkd-dhcp4.c
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+++ b/src/network/networkd-dhcp4.c
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
@@ -67,9 +67,18 @@ static int link_set_dhcp_routes(Link *link) {
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
return r;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
}
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
if (r >= 0) {
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ struct in_addr address;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
_cleanup_route_free_ Route *route = NULL;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
_cleanup_route_free_ Route *route_gw = NULL;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ r = sd_dhcp_lease_get_address(link->dhcp_lease, &address);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ if (r < 0) {
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ log_warning_link(link,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ "DHCP error: could not get address: %s",
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ strerror(-r));
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ return r;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ }
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
r = route_new_dynamic(&route, RTPROT_DHCP);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
if (r < 0) {
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
log_error_link(link,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
@@ -92,6 +101,7 @@ static int link_set_dhcp_routes(Link *link) {
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
route_gw->family = AF_INET;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
route_gw->dst_addr.in = gateway;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
route_gw->dst_prefixlen = 32;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ route_gw->prefsrc_addr.in = address;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
route_gw->scope = RT_SCOPE_LINK;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
route_gw->metrics = DHCP_ROUTE_METRIC;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
@@ -107,6 +117,7 @@ static int link_set_dhcp_routes(Link *link) {
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
route->family = AF_INET;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
route->in_addr.in = gateway;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ route->prefsrc_addr.in = address;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
route->metrics = DHCP_ROUTE_METRIC;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
r = route_configure(route, link, &dhcp4_route_handler);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
diff --git a/src/network/networkd-route.c b/src/network/networkd-route.c
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
index aead4fbb9e..10d8cd902a 100644
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
--- a/src/network/networkd-route.c
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+++ b/src/network/networkd-route.c
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
@@ -144,6 +144,17 @@ int route_drop(Route *route, Link *link,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
}
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
}
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ if (!in_addr_is_null(route->family, &route->prefsrc_addr)) {
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ if (route->family == AF_INET)
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ r = sd_rtnl_message_append_in_addr(req, RTA_PREFSRC, &route->prefsrc_addr.in);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ else if (route->family == AF_INET6)
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ r = sd_rtnl_message_append_in6_addr(req, RTA_PREFSRC, &route->prefsrc_addr.in6);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ if (r < 0) {
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ log_error("Could not append RTA_PREFSRC attribute: %s", strerror(-r));
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ return r;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ }
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ }
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
r = sd_rtnl_message_route_set_scope(req, route->scope);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
if (r < 0) {
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
log_error("Could not set scope: %s", strerror(-r));
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
@@ -218,6 +229,17 @@ int route_configure(Route *route, Link *link,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
}
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
}
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ if (!in_addr_is_null(route->family, &route->prefsrc_addr)) {
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ if (route->family == AF_INET)
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ r = sd_rtnl_message_append_in_addr(req, RTA_PREFSRC, &route->prefsrc_addr.in);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ else if (route->family == AF_INET6)
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ r = sd_rtnl_message_append_in6_addr(req, RTA_PREFSRC, &route->prefsrc_addr.in6);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ if (r < 0) {
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ log_error("Could not append RTA_PREFSRC attribute: %s", strerror(-r));
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ return r;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ }
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ }
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
r = sd_rtnl_message_route_set_scope(req, route->scope);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
if (r < 0) {
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
log_error("Could not set scope: %s", strerror(-r));
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
diff --git a/src/network/networkd.h b/src/network/networkd.h
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
index ab5df1aa3c..c6e6b22c38 100644
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
--- a/src/network/networkd.h
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+++ b/src/network/networkd.h
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
@@ -150,6 +150,7 @@ struct Route {
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
union in_addr_union in_addr;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
union in_addr_union dst_addr;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ union in_addr_union prefsrc_addr;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
LIST_FIELDS(Route, routes);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
};
|