return -EAFNOSUPPORT;
}
+bool in4_addr_equal(const struct in_addr *a, const struct in_addr *b) {
+ assert(a);
+ assert(b);
+
+ return a->s_addr == b->s_addr;
+}
+
int in_addr_equal(int family, const union in_addr_union *a, const union in_addr_union *b) {
assert(a);
assert(b);
if (family == AF_INET)
- return a->in.s_addr == b->in.s_addr;
+ return in4_addr_equal(&a->in, &b->in);
if (family == AF_INET6)
return
bool in4_addr_is_non_local(const struct in_addr *a);
+bool in4_addr_equal(const struct in_addr *a, const struct in_addr *b);
int in_addr_equal(int family, const union in_addr_union *a, const union in_addr_union *b);
int in_addr_prefix_intersect(int family, const union in_addr_union *a, unsigned aprefixlen, const union in_addr_union *b, unsigned bprefixlen);
int in_addr_prefix_next(int family, union in_addr_union *u, unsigned prefixlen);
assert(route);
assert(self_addr);
- if (in_addr_is_localhost(AF_INET, &route->dst) ||
- (self_addr->s_addr && route->dst.in.s_addr == self_addr->s_addr))
+ if (in4_addr_is_localhost(&route->dst.in) ||
+ (!in4_addr_is_null(self_addr) && in4_addr_equal(&route->dst.in, self_addr)))
return RT_SCOPE_HOST;
else if (in4_addr_is_null(&route->gw.in))
return RT_SCOPE_LINK;
r = route_configure(route, link, dhcp4_route_handler);
if (r < 0)
return log_link_error_errno(link, r, "Could not set host route: %m");
-
- link->dhcp4_messages++;
+ if (r > 0)
+ link->dhcp4_messages++;
}
r = sd_dhcp_lease_get_router(link->dhcp_lease, &router);
r = route_configure(route_gw, link, dhcp4_route_handler);
if (r < 0)
return log_link_error_errno(link, r, "Could not set host route: %m");
-
- link->dhcp4_messages++;
+ if (r > 0)
+ link->dhcp4_messages++;
r = route_new(&route);
if (r < 0)
r = route_configure(route, link, dhcp4_route_handler);
if (r < 0)
return log_link_error_errno(link, r, "Could not set routes: %m");
-
- link->dhcp4_messages++;
+ if (r > 0)
+ link->dhcp4_messages++;
}
return 0;
link_enter_failed(link);
return 1;
}
-
- manager_rtnl_process_address(rtnl, m, link->manager);
+ if (r >= 0)
+ manager_rtnl_process_address(rtnl, m, link->manager);
r = link_set_dhcp_routes(link);
if (r < 0) {
log_link_error_errno(link, r, "Could not set DHCPv6 address: %m");
link_enter_failed(link);
-
- } else if (r >= 0)
+ return 1;
+ }
+ if (r >= 0)
manager_rtnl_process_address(rtnl, m, link->manager);
+ link_request_set_routes(link);
+
return 1;
}
#include "missing_network.h"
#include "networkd-dhcp6.h"
+#include "networkd-manager.h"
#include "networkd-ndisc.h"
#include "networkd-route.h"
#include "strv.h"
#define NDISC_RDNSS_MAX 64U
#define NDISC_PREFIX_LFT_MIN 7200U
-static int ndisc_netlink_message_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) {
+static int ndisc_netlink_route_message_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) {
int r;
assert(link);
if (link->ndisc_messages == 0) {
link->ndisc_configured = true;
+ link_request_set_routes(link);
+ link_check_ready(link);
+ }
+
+ return 1;
+}
+
+static int ndisc_netlink_address_message_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) {
+ int r;
+
+ assert(link);
+ assert(link->ndisc_messages > 0);
+
+ link->ndisc_messages--;
+
+ r = sd_netlink_message_get_errno(m);
+ if (r < 0 && r != -EEXIST)
+ log_link_error_errno(link, r, "Could not set NDisc route or address: %m");
+ else if (r >= 0)
+ manager_rtnl_process_address(rtnl, m, link->manager);
+
+ if (link->ndisc_messages == 0) {
+ link->ndisc_configured = true;
+ link_request_set_routes(link);
link_check_ready(link);
}
route->lifetime = time_now + lifetime * USEC_PER_SEC;
route->mtu = mtu;
- r = route_configure(route, link, ndisc_netlink_message_handler);
+ r = route_configure(route, link, ndisc_netlink_route_message_handler);
if (r < 0) {
log_link_warning_errno(link, r, "Could not set default route: %m");
link_enter_failed(link);
if (address->cinfo.ifa_valid == 0)
return 0;
- r = address_configure(address, link, ndisc_netlink_message_handler, true);
+ r = address_configure(address, link, ndisc_netlink_address_message_handler, true);
if (r < 0) {
log_link_warning_errno(link, r, "Could not set SLAAC address: %m");
link_enter_failed(link);
if (r < 0)
return log_link_error_errno(link, r, "Failed to get prefix address: %m");
- r = route_configure(route, link, ndisc_netlink_message_handler);
+ r = route_configure(route, link, ndisc_netlink_route_message_handler);
if (r < 0) {
log_link_warning_errno(link, r, "Could not set prefix route: %m");
link_enter_failed(link);
if (r < 0)
return log_link_error_errno(link, r, "Failed to get route address: %m");
- r = route_configure(route, link, ndisc_netlink_message_handler);
+ r = route_configure(route, link, ndisc_netlink_route_message_handler);
if (r < 0) {
log_link_warning_errno(link, r, "Could not set additional route: %m");
link_enter_failed(link);
--- /dev/null
+[Match]
+Name=veth99
+
+[Network]
+IPv6AcceptRA=yes
+
+[Route]
+Destination=2600:0:0:1::/64
'dhcp-client-keep-configuration-dhcp-on-stop.network',
'dhcp-client-keep-configuration-dhcp.network',
'dhcp-client-listen-port.network',
+ 'dhcp-client-reassign-static-routes-ipv4.network',
+ 'dhcp-client-reassign-static-routes-ipv6.network',
'dhcp-client-route-metric.network',
'dhcp-client-route-table.network',
'dhcp-client-use-dns-ipv4-and-ra.network',
print(output)
self.assertRegex(output, 'metric 24')
- def test_dhcp_client_use_routes_no(self):
+ def test_dhcp_client_reassign_static_routes_ipv4(self):
copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network',
- 'dhcp-client-use-routes-no.network')
+ 'dhcp-client-reassign-static-routes-ipv4.network')
start_networkd()
wait_online(['veth-peer:carrier'])
start_dnsmasq(lease_time='2m')
self.assertRegex(output, r'192.168.6.0/24 proto static')
self.assertRegex(output, r'192.168.7.0/24 proto static')
+ stop_dnsmasq(dnsmasq_pid_file)
+ start_dnsmasq(ipv4_range='192.168.5.210,192.168.5.220', lease_time='2m')
+
# Sleep for 120 sec as the dnsmasq minimum lease time can only be set to 120
print('Wait for the dynamic address to be renewed')
time.sleep(125)
self.assertRegex(output, r'192.168.6.0/24 proto static')
self.assertRegex(output, r'192.168.7.0/24 proto static')
+ def test_dhcp_client_reassign_static_routes_ipv6(self):
+ copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network',
+ 'dhcp-client-reassign-static-routes-ipv6.network')
+ start_networkd()
+ wait_online(['veth-peer:carrier'])
+ start_dnsmasq(lease_time='2m')
+ wait_online(['veth99:routable', 'veth-peer:routable'])
+
+ output = check_output('ip address show dev veth99 scope global')
+ print(output)
+ self.assertRegex(output, r'inet6 2600::[0-9a-f]*/128 scope global (?:noprefixroute dynamic|dynamic noprefixroute)')
+
+ output = check_output('ip -6 route show dev veth99')
+ print(output)
+ self.assertRegex(output, r'2600::/64 proto ra metric 1024')
+ self.assertRegex(output, r'2600:0:0:1::/64 proto static metric 1024 pref medium')
+
+ stop_dnsmasq(dnsmasq_pid_file)
+ start_dnsmasq(ipv6_range='2600::30,2600::40', lease_time='2m')
+
+ # Sleep for 120 sec as the dnsmasq minimum lease time can only be set to 120
+ print('Wait for the dynamic address to be renewed')
+ time.sleep(125)
+
+ wait_online(['veth99:routable'])
+
+ output = check_output('ip -6 route show dev veth99')
+ print(output)
+ self.assertRegex(output, r'2600::/64 proto ra metric 1024')
+ self.assertRegex(output, r'2600:0:0:1::/64 proto static metric 1024 pref medium')
+
def test_dhcp_keep_configuration_dhcp(self):
copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-v4-server-veth-peer.network', 'dhcp-client-keep-configuration-dhcp.network')
start_networkd()