#include "networkd-lldp-tx.h"
#include "networkd-manager.h"
#include "networkd-ndisc.h"
+#include "networkd-radv.h"
#include "set.h"
#include "socket-util.h"
#include "stdio-util.h"
return link_ipv6ll_enabled(link) || network_has_static_ipv6_addresses(link->network);
}
+static bool link_radv_enabled(Link *link) {
+ assert(link);
+
+ if (!link_ipv6ll_enabled(link))
+ return false;
+
+ return link->network->router_prefix_delegation;
+}
+
static bool link_lldp_rx_enabled(Link *link) {
assert(link);
if (!link->network)
return false;
- if (link->network->bridge)
+ /* LLDP should be handled on bridge slaves as those have a direct
+ * connection to their peers not on the bridge master. Linux doesn't
+ * even (by default) forward lldp packets to the bridge master.*/
+ if (streq_ptr("bridge", link->kind))
return false;
return link->network->lldp_mode != LLDP_MODE_NO;
sd_ipv4ll_unref(link->ipv4ll);
sd_dhcp6_client_unref(link->dhcp6_client);
sd_ndisc_unref(link->ndisc);
+ sd_radv_unref(link->radv);
if (link->manager)
hashmap_remove(link->manager->links, INT_TO_PTR(link->ifindex));
r = log_link_warning_errno(link, k, "Could not stop IPv6 Router Discovery: %m");
}
+ if (link->radv) {
+ k = sd_radv_stop(link->radv);
+ if (k < 0)
+ r = log_link_warning_errno(link, k, "Could not stop IPv6 Router Advertisement: %m");
+ }
+
link_lldp_emit_stop(link);
return r;
}
return log_link_warning_errno(link, r, "Could not start IPv6 Router Discovery: %m");
}
+ if (link_radv_enabled(link)) {
+ assert(link->radv);
+ assert(in_addr_is_link_local(AF_INET6, (const union in_addr_union*)&link->ipv6ll_address) > 0);
+
+ log_link_debug(link, "Starting IPv6 Router Advertisements");
+
+ r = sd_radv_start(link->radv);
+ if (r < 0 && r != -EBUSY)
+ return log_link_warning_errno(link, r, "Could not start IPv6 Router Advertisement: %m");
+ }
+
return 0;
}
log_link_error_errno(link, r, "Could not set bridge vlan: %m");
}
+ /* Skip setting up addresses until it gets carrier,
+ or it would try to set addresses twice,
+ which is bad for non-idempotent steps. */
+ if (!link_has_carrier(link))
+ return 0;
+
return link_enter_set_addresses(link);
}
}
static int link_drop_config(Link *link) {
- Address *address;
+ Address *address, *pool_address;
Route *route;
Iterator i;
int r;
r = address_remove(address, link, link_address_remove_handler);
if (r < 0)
return r;
+
+ /* If this address came from an address pool, clean up the pool */
+ LIST_FOREACH(addresses, pool_address, link->pool_addresses) {
+ if (address_equal(address, pool_address)) {
+ LIST_REMOVE(addresses, link->pool_addresses, pool_address);
+ address_free(pool_address);
+ break;
+ }
+ }
}
SET_FOREACH(route, link->routes, i) {
return r;
}
+ if (link_radv_enabled(link)) {
+ r = radv_configure(link);
+ if (r < 0)
+ return r;
+ }
+
if (link_lldp_rx_enabled(link)) {
r = sd_lldp_new(&link->lldp);
if (r < 0)
return r;
}
+ (void) sd_dhcp_server_stop(link->dhcp_server);
+
r = link_drop_config(link);
if (r < 0)
return r;
return r;
}
}
+
+ if (link->radv) {
+ r = sd_radv_set_mtu(link->radv, link->mtu);
+ if (r < 0)
+ return log_link_warning_errno(link, r, "Could not set MTU for Router Advertisement: %m");
+ }
}
/* The kernel may broadcast NEWLINK messages without the MAC address
if (r < 0)
return log_link_warning_errno(link, r, "Could not update DHCPv6 DUID: %m");
}
+
+ if (link->radv) {
+ r = sd_radv_set_mac(link->radv, &link->mac);
+ if (r < 0)
+ return log_link_warning_errno(link, r, "Could not update MAC for Router Advertisement: %m");
+ }
}
}
if (hashmap_isempty(h))
return;
- fputs(prefix, f);
+ fputs_unlocked(prefix, f);
HASHMAP_FOREACH(link, h, i) {
if (space)
- fputc(' ', f);
+ fputc_unlocked(' ', f);
fprintf(f, "%i", link->ifindex);
space = true;
}
- fputc('\n', f);
+ fputc_unlocked('\n', f);
}
int link_save(Link *link) {
sd_dhcp6_lease *dhcp6_lease = NULL;
const char *dhcp_domainname = NULL;
char **dhcp6_domains = NULL;
+ char **dhcp_domains = NULL;
unsigned j;
if (link->dhcp6_client) {
fprintf(f, "NETWORK_FILE=%s\n", link->network->filename);
- fputs("DNS=", f);
+ fputs_unlocked("DNS=", f);
space = false;
for (j = 0; j < link->network->n_dns; j++) {
}
if (space)
- fputc(' ', f);
- fputs(b, f);
+ fputc_unlocked(' ', f);
+ fputs_unlocked(b, f);
space = true;
}
r = sd_dhcp_lease_get_dns(link->dhcp_lease, &addresses);
if (r > 0) {
if (space)
- fputc(' ', f);
+ fputc_unlocked(' ', f);
serialize_in_addrs(f, addresses, r);
space = true;
}
r = sd_dhcp6_lease_get_dns(dhcp6_lease, &in6_addrs);
if (r > 0) {
if (space)
- fputc(' ', f);
+ fputc_unlocked(' ', f);
serialize_in6_addrs(f, in6_addrs, r);
space = true;
}
SET_FOREACH(dd, link->ndisc_rdnss, i) {
if (space)
- fputc(' ', f);
+ fputc_unlocked(' ', f);
serialize_in6_addrs(f, &dd->address, 1);
space = true;
}
}
- fputc('\n', f);
+ fputc_unlocked('\n', f);
- fputs("NTP=", f);
+ fputs_unlocked("NTP=", f);
space = false;
fputstrv(f, link->network->ntp, NULL, &space);
r = sd_dhcp_lease_get_ntp(link->dhcp_lease, &addresses);
if (r > 0) {
if (space)
- fputc(' ', f);
+ fputc_unlocked(' ', f);
serialize_in_addrs(f, addresses, r);
space = true;
}
&in6_addrs);
if (r > 0) {
if (space)
- fputc(' ', f);
+ fputc_unlocked(' ', f);
serialize_in6_addrs(f, in6_addrs, r);
space = true;
}
fputstrv(f, hosts, NULL, &space);
}
- fputc('\n', f);
+ fputc_unlocked('\n', f);
if (link->network->dhcp_use_domains != DHCP_USE_DOMAINS_NO) {
- if (link->dhcp_lease)
+ if (link->dhcp_lease) {
(void) sd_dhcp_lease_get_domainname(link->dhcp_lease, &dhcp_domainname);
+ (void) sd_dhcp_lease_get_search_domains(link->dhcp_lease, &dhcp_domains);
+ }
if (dhcp6_lease)
(void) sd_dhcp6_lease_get_domains(dhcp6_lease, &dhcp6_domains);
}
- fputs("DOMAINS=", f);
+ fputs_unlocked("DOMAINS=", f);
+ space = false;
fputstrv(f, link->network->search_domains, NULL, &space);
if (link->network->dhcp_use_domains == DHCP_USE_DOMAINS_YES) {
if (dhcp_domainname)
fputs_with_space(f, dhcp_domainname, NULL, &space);
+ if (dhcp_domains)
+ fputstrv(f, dhcp_domains, NULL, &space);
if (dhcp6_domains)
fputstrv(f, dhcp6_domains, NULL, &space);
fputs_with_space(f, NDISC_DNSSL_DOMAIN(dd), NULL, &space);
}
- fputc('\n', f);
+ fputc_unlocked('\n', f);
- fputs("ROUTE_DOMAINS=", f);
- fputstrv(f, link->network->route_domains, NULL, NULL);
+ fputs_unlocked("ROUTE_DOMAINS=", f);
+ space = false;
+ fputstrv(f, link->network->route_domains, NULL, &space);
if (link->network->dhcp_use_domains == DHCP_USE_DOMAINS_ROUTE) {
NDiscDNSSL *dd;
if (dhcp_domainname)
fputs_with_space(f, dhcp_domainname, NULL, &space);
+ if (dhcp_domains)
+ fputstrv(f, dhcp_domains, NULL, &space);
if (dhcp6_domains)
fputstrv(f, dhcp6_domains, NULL, &space);
fputs_with_space(f, NDISC_DNSSL_DOMAIN(dd), NULL, &space);
}
- fputc('\n', f);
+ fputc_unlocked('\n', f);
fprintf(f, "LLMNR=%s\n",
resolve_support_to_string(link->network->llmnr));
if (!set_isempty(link->network->dnssec_negative_trust_anchors)) {
const char *n;
- fputs("DNSSEC_NTA=", f);
+ fputs_unlocked("DNSSEC_NTA=", f);
space = false;
SET_FOREACH(n, link->network->dnssec_negative_trust_anchors, i)
fputs_with_space(f, n, NULL, &space);
- fputc('\n', f);
+ fputc_unlocked('\n', f);
}
- fputs("ADDRESSES=", f);
+ fputs_unlocked("ADDRESSES=", f);
space = false;
SET_FOREACH(a, link->addresses, i) {
_cleanup_free_ char *address_str = NULL;
fprintf(f, "%s%s/%u", space ? " " : "", address_str, a->prefixlen);
space = true;
}
- fputc('\n', f);
+ fputc_unlocked('\n', f);
- fputs("ROUTES=", f);
+ fputs_unlocked("ROUTES=", f);
space = false;
SET_FOREACH(route, link->routes, i) {
_cleanup_free_ char *route_str = NULL;
space = true;
}
- fputc('\n', f);
+ fputc_unlocked('\n', f);
}
print_link_hashmap(f, "CARRIER_BOUND_TO=", link->bound_to_links);
r = sd_dhcp_lease_get_address(link->dhcp_lease, &address);
if (r >= 0) {
- fputs("DHCP4_ADDRESS=", f);
+ fputs_unlocked("DHCP4_ADDRESS=", f);
serialize_in_addrs(f, &address, 1);
- fputc('\n', f);
+ fputc_unlocked('\n', f);
}
r = dhcp_lease_save(link->dhcp_lease, link->lease_file);
r = sd_ipv4ll_get_address(link->ipv4ll, &address);
if (r >= 0) {
- fputs("IPV4LL_ADDRESS=", f);
+ fputs_unlocked("IPV4LL_ADDRESS=", f);
serialize_in_addrs(f, &address, 1);
- fputc('\n', f);
+ fputc_unlocked('\n', f);
}
}