| 1 |
/* SPDX-License-Identifier: LGPL-2.1-or-later */ |
| 2 |
|
| 3 |
#include <unistd.h> |
| 4 |
|
| 5 |
#include "alloc-util.h" |
| 6 |
#include "condition.h" |
| 7 |
#include "conf-files.h" |
| 8 |
#include "conf-parser.h" |
| 9 |
#include "in-addr-util.h" |
| 10 |
#include "iovec-util.h" |
| 11 |
#include "net-condition.h" |
| 12 |
#include "netdev/macvlan.h" |
| 13 |
#include "netif-sriov.h" |
| 14 |
#include "network-util.h" |
| 15 |
#include "networkd-address.h" |
| 16 |
#include "networkd-address-label.h" |
| 17 |
#include "networkd-bridge-fdb.h" |
| 18 |
#include "networkd-bridge-mdb.h" |
| 19 |
#include "networkd-dhcp-common.h" |
| 20 |
#include "networkd-dhcp-server-static-lease.h" |
| 21 |
#include "networkd-ipv6-proxy-ndp.h" |
| 22 |
#include "networkd-manager.h" |
| 23 |
#include "networkd-ndisc.h" |
| 24 |
#include "networkd-neighbor.h" |
| 25 |
#include "networkd-network.h" |
| 26 |
#include "networkd-nexthop.h" |
| 27 |
#include "networkd-radv.h" |
| 28 |
#include "networkd-route.h" |
| 29 |
#include "networkd-routing-policy-rule.h" |
| 30 |
#include "ordered-set.h" |
| 31 |
#include "parse-util.h" |
| 32 |
#include "path-util.h" |
| 33 |
#include "qdisc.h" |
| 34 |
#include "radv-internal.h" |
| 35 |
#include "set.h" |
| 36 |
#include "socket-util.h" |
| 37 |
#include "stat-util.h" |
| 38 |
#include "string-table.h" |
| 39 |
#include "string-util.h" |
| 40 |
#include "strv.h" |
| 41 |
#include "tclass.h" |
| 42 |
|
| 43 |
DEFINE_PRIVATE_HASH_OPS_WITH_VALUE_DESTRUCTOR( |
| 44 |
network_hash_ops, |
| 45 |
char, string_hash_func, string_compare_func, |
| 46 |
Network, network_unref); |
| 47 |
|
| 48 |
DEFINE_PRIVATE_HASH_OPS_WITH_VALUE_DESTRUCTOR( |
| 49 |
stacked_netdevs_hash_ops, |
| 50 |
char, string_hash_func, string_compare_func, |
| 51 |
NetDev, netdev_unref); |
| 52 |
|
| 53 |
static int network_resolve_netdev_one(Network *network, const char *name, NetDevKind kind, NetDev **ret) { |
| 54 |
const char *kind_string; |
| 55 |
NetDev *netdev; |
| 56 |
int r; |
| 57 |
|
| 58 |
/* For test-networkd-conf, the check must be earlier than the assertions. */ |
| 59 |
if (!name) |
| 60 |
return 0; |
| 61 |
|
| 62 |
assert(network); |
| 63 |
assert(network->manager); |
| 64 |
assert(network->filename); |
| 65 |
assert(ret); |
| 66 |
|
| 67 |
if (kind == _NETDEV_KIND_TUNNEL) |
| 68 |
kind_string = "tunnel"; |
| 69 |
else { |
| 70 |
kind_string = netdev_kind_to_string(kind); |
| 71 |
if (!kind_string) |
| 72 |
return log_warning_errno(SYNTHETIC_ERRNO(EINVAL), |
| 73 |
"%s: Invalid NetDev kind of %s, ignoring assignment.", |
| 74 |
network->filename, name); |
| 75 |
} |
| 76 |
|
| 77 |
r = netdev_get(network->manager, name, &netdev); |
| 78 |
if (r < 0) |
| 79 |
return log_warning_errno(r, "%s: %s NetDev could not be found, ignoring assignment.", |
| 80 |
network->filename, name); |
| 81 |
|
| 82 |
if (netdev->kind != kind && !(kind == _NETDEV_KIND_TUNNEL && |
| 83 |
IN_SET(netdev->kind, |
| 84 |
NETDEV_KIND_ERSPAN, |
| 85 |
NETDEV_KIND_GRE, |
| 86 |
NETDEV_KIND_GRETAP, |
| 87 |
NETDEV_KIND_IP6GRE, |
| 88 |
NETDEV_KIND_IP6GRETAP, |
| 89 |
NETDEV_KIND_IP6TNL, |
| 90 |
NETDEV_KIND_IPIP, |
| 91 |
NETDEV_KIND_SIT, |
| 92 |
NETDEV_KIND_VTI, |
| 93 |
NETDEV_KIND_VTI6))) |
| 94 |
return log_warning_errno(SYNTHETIC_ERRNO(EINVAL), |
| 95 |
"%s: NetDev %s is not a %s, ignoring assignment", |
| 96 |
network->filename, name, kind_string); |
| 97 |
|
| 98 |
*ret = netdev_ref(netdev); |
| 99 |
return 1; |
| 100 |
} |
| 101 |
|
| 102 |
static int network_resolve_stacked_netdevs(Network *network) { |
| 103 |
void *name, *kind; |
| 104 |
int r; |
| 105 |
|
| 106 |
assert(network); |
| 107 |
|
| 108 |
HASHMAP_FOREACH_KEY(kind, name, network->stacked_netdev_names) { |
| 109 |
_cleanup_(netdev_unrefp) NetDev *netdev = NULL; |
| 110 |
|
| 111 |
if (network_resolve_netdev_one(network, name, PTR_TO_INT(kind), &netdev) <= 0) |
| 112 |
continue; |
| 113 |
|
| 114 |
r = hashmap_ensure_put(&network->stacked_netdevs, &stacked_netdevs_hash_ops, netdev->ifname, netdev); |
| 115 |
if (r == -ENOMEM) |
| 116 |
return log_oom(); |
| 117 |
if (r < 0) |
| 118 |
log_warning_errno(r, "%s: Failed to add NetDev '%s' to network, ignoring: %m", |
| 119 |
network->filename, (const char *) name); |
| 120 |
|
| 121 |
TAKE_PTR(netdev); |
| 122 |
} |
| 123 |
|
| 124 |
return 0; |
| 125 |
} |
| 126 |
|
| 127 |
int network_verify(Network *network) { |
| 128 |
int r; |
| 129 |
|
| 130 |
assert(network); |
| 131 |
assert(network->manager); |
| 132 |
assert(network->filename); |
| 133 |
|
| 134 |
if (net_match_is_empty(&network->match) && !network->conditions) |
| 135 |
return log_warning_errno(SYNTHETIC_ERRNO(EINVAL), |
| 136 |
"%s: No valid settings found in the [Match] section, ignoring file. " |
| 137 |
"To match all interfaces, add Name=* in the [Match] section.", |
| 138 |
network->filename); |
| 139 |
|
| 140 |
/* skip out early if configuration does not match the environment */ |
| 141 |
if (!condition_test_list(network->conditions, environ, NULL, NULL, NULL)) |
| 142 |
return log_debug_errno(SYNTHETIC_ERRNO(EINVAL), |
| 143 |
"%s: Conditions in the file do not match the system environment, skipping.", |
| 144 |
network->filename); |
| 145 |
|
| 146 |
if (network->keep_master) { |
| 147 |
if (network->batadv_name) |
| 148 |
log_warning("%s: BatmanAdvanced= set with KeepMaster= enabled, ignoring BatmanAdvanced=.", |
| 149 |
network->filename); |
| 150 |
if (network->bond_name) |
| 151 |
log_warning("%s: Bond= set with KeepMaster= enabled, ignoring Bond=.", |
| 152 |
network->filename); |
| 153 |
if (network->bridge_name) |
| 154 |
log_warning("%s: Bridge= set with KeepMaster= enabled, ignoring Bridge=.", |
| 155 |
network->filename); |
| 156 |
if (network->vrf_name) |
| 157 |
log_warning("%s: VRF= set with KeepMaster= enabled, ignoring VRF=.", |
| 158 |
network->filename); |
| 159 |
|
| 160 |
network->batadv_name = mfree(network->batadv_name); |
| 161 |
network->bond_name = mfree(network->bond_name); |
| 162 |
network->bridge_name = mfree(network->bridge_name); |
| 163 |
network->vrf_name = mfree(network->vrf_name); |
| 164 |
} |
| 165 |
|
| 166 |
(void) network_resolve_netdev_one(network, network->batadv_name, NETDEV_KIND_BATADV, &network->batadv); |
| 167 |
(void) network_resolve_netdev_one(network, network->bond_name, NETDEV_KIND_BOND, &network->bond); |
| 168 |
(void) network_resolve_netdev_one(network, network->bridge_name, NETDEV_KIND_BRIDGE, &network->bridge); |
| 169 |
(void) network_resolve_netdev_one(network, network->vrf_name, NETDEV_KIND_VRF, &network->vrf); |
| 170 |
r = network_resolve_stacked_netdevs(network); |
| 171 |
if (r < 0) |
| 172 |
return r; |
| 173 |
|
| 174 |
/* Free unnecessary entries. */ |
| 175 |
network->batadv_name = mfree(network->batadv_name); |
| 176 |
network->bond_name = mfree(network->bond_name); |
| 177 |
network->bridge_name = mfree(network->bridge_name); |
| 178 |
network->vrf_name = mfree(network->vrf_name); |
| 179 |
network->stacked_netdev_names = hashmap_free(network->stacked_netdev_names); |
| 180 |
|
| 181 |
if (network->bond) { |
| 182 |
/* Bonding slave does not support addressing. */ |
| 183 |
if (network->link_local >= 0 && network->link_local != ADDRESS_FAMILY_NO) { |
| 184 |
log_warning("%s: Cannot enable LinkLocalAddressing= when Bond= is specified, disabling LinkLocalAddressing=.", |
| 185 |
network->filename); |
| 186 |
network->link_local = ADDRESS_FAMILY_NO; |
| 187 |
} |
| 188 |
if (!ordered_hashmap_isempty(network->addresses_by_section)) |
| 189 |
log_warning("%s: Cannot set addresses when Bond= is specified, ignoring addresses.", |
| 190 |
network->filename); |
| 191 |
if (!hashmap_isempty(network->routes_by_section)) |
| 192 |
log_warning("%s: Cannot set routes when Bond= is specified, ignoring routes.", |
| 193 |
network->filename); |
| 194 |
|
| 195 |
network->addresses_by_section = ordered_hashmap_free(network->addresses_by_section); |
| 196 |
network->routes_by_section = hashmap_free(network->routes_by_section); |
| 197 |
} |
| 198 |
|
| 199 |
if (network->link_local < 0) { |
| 200 |
network->link_local = ADDRESS_FAMILY_IPV6; |
| 201 |
|
| 202 |
if (network->keep_master || network->bridge) |
| 203 |
network->link_local = ADDRESS_FAMILY_NO; |
| 204 |
else { |
| 205 |
NetDev *netdev; |
| 206 |
|
| 207 |
HASHMAP_FOREACH(netdev, network->stacked_netdevs) { |
| 208 |
MacVlan *m; |
| 209 |
|
| 210 |
if (netdev->kind == NETDEV_KIND_MACVLAN) |
| 211 |
m = MACVLAN(netdev); |
| 212 |
else if (netdev->kind == NETDEV_KIND_MACVTAP) |
| 213 |
m = MACVTAP(netdev); |
| 214 |
else |
| 215 |
continue; |
| 216 |
|
| 217 |
if (m->mode == NETDEV_MACVLAN_MODE_PASSTHRU) |
| 218 |
network->link_local = ADDRESS_FAMILY_NO; |
| 219 |
|
| 220 |
/* There won't be a passthru MACVLAN/MACVTAP if there's already one in another mode */ |
| 221 |
break; |
| 222 |
} |
| 223 |
} |
| 224 |
} |
| 225 |
|
| 226 |
if (network->ipv6ll_address_gen_mode == IPV6_LINK_LOCAL_ADDRESSS_GEN_MODE_NONE) |
| 227 |
SET_FLAG(network->link_local, ADDRESS_FAMILY_IPV6, false); |
| 228 |
|
| 229 |
if (in6_addr_is_set(&network->ipv6ll_stable_secret) && |
| 230 |
network->ipv6ll_address_gen_mode < 0) |
| 231 |
network->ipv6ll_address_gen_mode = IPV6_LINK_LOCAL_ADDRESSS_GEN_MODE_STABLE_PRIVACY; |
| 232 |
|
| 233 |
network_adjust_ipv6_proxy_ndp(network); |
| 234 |
network_adjust_ndisc(network); |
| 235 |
network_adjust_dhcp(network); |
| 236 |
network_adjust_radv(network); |
| 237 |
network_adjust_bridge_vlan(network); |
| 238 |
|
| 239 |
if (network->mtu > 0 && network->dhcp_use_mtu) { |
| 240 |
log_warning("%s: MTUBytes= in [Link] section and UseMTU= in [DHCP] section are set. " |
| 241 |
"Disabling UseMTU=.", network->filename); |
| 242 |
network->dhcp_use_mtu = false; |
| 243 |
} |
| 244 |
|
| 245 |
if (network->dhcp_critical >= 0) { |
| 246 |
if (network->keep_configuration >= 0) { |
| 247 |
if (network->manager->keep_configuration < 0) |
| 248 |
log_warning("%s: Both KeepConfiguration= and deprecated CriticalConnection= are set. " |
| 249 |
"Ignoring CriticalConnection=.", network->filename); |
| 250 |
} else if (network->dhcp_critical) |
| 251 |
/* CriticalConnection=yes also preserve foreign static configurations. */ |
| 252 |
network->keep_configuration = KEEP_CONFIGURATION_YES; |
| 253 |
else |
| 254 |
network->keep_configuration = KEEP_CONFIGURATION_NO; |
| 255 |
} |
| 256 |
|
| 257 |
if (!strv_isempty(network->bind_carrier)) { |
| 258 |
if (!IN_SET(network->activation_policy, _ACTIVATION_POLICY_INVALID, ACTIVATION_POLICY_BOUND)) |
| 259 |
log_warning("%s: ActivationPolicy=bound is required with BindCarrier=. " |
| 260 |
"Setting ActivationPolicy=bound.", network->filename); |
| 261 |
network->activation_policy = ACTIVATION_POLICY_BOUND; |
| 262 |
} else if (network->activation_policy == ACTIVATION_POLICY_BOUND) { |
| 263 |
log_warning("%s: ActivationPolicy=bound requires BindCarrier=. " |
| 264 |
"Ignoring ActivationPolicy=bound.", network->filename); |
| 265 |
network->activation_policy = ACTIVATION_POLICY_UP; |
| 266 |
} |
| 267 |
|
| 268 |
if (network->activation_policy == _ACTIVATION_POLICY_INVALID) |
| 269 |
network->activation_policy = ACTIVATION_POLICY_UP; |
| 270 |
|
| 271 |
if (network->activation_policy == ACTIVATION_POLICY_ALWAYS_UP) { |
| 272 |
if (network->ignore_carrier_loss_set && network->ignore_carrier_loss_usec < USEC_INFINITY) |
| 273 |
log_warning("%s: IgnoreCarrierLoss=no or finite timespan conflicts with ActivationPolicy=always-up. " |
| 274 |
"Setting IgnoreCarrierLoss=yes.", network->filename); |
| 275 |
network->ignore_carrier_loss_set = true; |
| 276 |
network->ignore_carrier_loss_usec = USEC_INFINITY; |
| 277 |
} |
| 278 |
|
| 279 |
if (!network->ignore_carrier_loss_set) /* Set implied default. */ |
| 280 |
network->ignore_carrier_loss_usec = network->configure_without_carrier ? USEC_INFINITY : 0; |
| 281 |
|
| 282 |
if (IN_SET(network->activation_policy, ACTIVATION_POLICY_DOWN, ACTIVATION_POLICY_ALWAYS_DOWN, ACTIVATION_POLICY_MANUAL)) { |
| 283 |
if (network->required_for_online < 0 || |
| 284 |
(network->required_for_online == true && network->activation_policy == ACTIVATION_POLICY_ALWAYS_DOWN)) { |
| 285 |
log_debug("%s: Setting RequiredForOnline=no because ActivationPolicy=%s.", network->filename, |
| 286 |
activation_policy_to_string(network->activation_policy)); |
| 287 |
network->required_for_online = false; |
| 288 |
} else if (network->required_for_online == true) |
| 289 |
log_warning("%s: RequiredForOnline=yes and ActivationPolicy=%s, " |
| 290 |
"this may cause a delay at boot.", network->filename, |
| 291 |
activation_policy_to_string(network->activation_policy)); |
| 292 |
} |
| 293 |
|
| 294 |
if (network->required_for_online < 0) |
| 295 |
network->required_for_online = true; |
| 296 |
|
| 297 |
if (network->keep_configuration < 0) |
| 298 |
network->keep_configuration = KEEP_CONFIGURATION_NO; |
| 299 |
|
| 300 |
r = network_drop_invalid_addresses(network); |
| 301 |
if (r < 0) |
| 302 |
return r; /* network_drop_invalid_addresses() logs internally. */ |
| 303 |
network_drop_invalid_routes(network); |
| 304 |
r = network_drop_invalid_nexthops(network); |
| 305 |
if (r < 0) |
| 306 |
return r; |
| 307 |
network_drop_invalid_bridge_fdb_entries(network); |
| 308 |
network_drop_invalid_bridge_mdb_entries(network); |
| 309 |
r = network_drop_invalid_neighbors(network); |
| 310 |
if (r < 0) |
| 311 |
return r; |
| 312 |
network_drop_invalid_address_labels(network); |
| 313 |
network_drop_invalid_routing_policy_rules(network); |
| 314 |
network_drop_invalid_qdisc(network); |
| 315 |
network_drop_invalid_tclass(network); |
| 316 |
r = sr_iov_drop_invalid_sections(UINT32_MAX, network->sr_iov_by_section); |
| 317 |
if (r < 0) |
| 318 |
return r; /* sr_iov_drop_invalid_sections() logs internally. */ |
| 319 |
network_drop_invalid_static_leases(network); |
| 320 |
|
| 321 |
return 0; |
| 322 |
} |
| 323 |
|
| 324 |
int network_load_one(Manager *manager, OrderedHashmap **networks, const char *filename) { |
| 325 |
_cleanup_free_ char *fname = NULL, *name = NULL; |
| 326 |
_cleanup_(network_unrefp) Network *network = NULL; |
| 327 |
const char *dropin_dirname; |
| 328 |
char *d; |
| 329 |
int r; |
| 330 |
|
| 331 |
assert(manager); |
| 332 |
assert(filename); |
| 333 |
|
| 334 |
r = null_or_empty_path(filename); |
| 335 |
if (r < 0) |
| 336 |
return log_warning_errno(r, "Failed to check if \"%s\" is empty: %m", filename); |
| 337 |
if (r > 0) { |
| 338 |
log_debug("Skipping empty file: %s", filename); |
| 339 |
return 0; |
| 340 |
} |
| 341 |
|
| 342 |
fname = strdup(filename); |
| 343 |
if (!fname) |
| 344 |
return log_oom(); |
| 345 |
|
| 346 |
r = path_extract_filename(filename, &name); |
| 347 |
if (r < 0) |
| 348 |
return log_warning_errno(r, "Failed to extract file name of \"%s\": %m", filename); |
| 349 |
|
| 350 |
d = strrchr(name, '.'); |
| 351 |
if (!d) |
| 352 |
return log_warning_errno(SYNTHETIC_ERRNO(EINVAL), "Invalid file name: %s", filename); |
| 353 |
|
| 354 |
*d = '\0'; |
| 355 |
|
| 356 |
dropin_dirname = strjoina(name, ".network.d"); |
| 357 |
|
| 358 |
network = new(Network, 1); |
| 359 |
if (!network) |
| 360 |
return log_oom(); |
| 361 |
|
| 362 |
*network = (Network) { |
| 363 |
.filename = TAKE_PTR(fname), |
| 364 |
.name = TAKE_PTR(name), |
| 365 |
|
| 366 |
.manager = manager, |
| 367 |
.n_ref = 1, |
| 368 |
|
| 369 |
.required_for_online = -1, |
| 370 |
.required_operstate_for_online = LINK_OPERSTATE_RANGE_INVALID, |
| 371 |
.activation_policy = _ACTIVATION_POLICY_INVALID, |
| 372 |
.group = -1, |
| 373 |
.arp = -1, |
| 374 |
.multicast = -1, |
| 375 |
.allmulticast = -1, |
| 376 |
.promiscuous = -1, |
| 377 |
|
| 378 |
.keep_configuration = manager->keep_configuration, |
| 379 |
|
| 380 |
.use_domains = _USE_DOMAINS_INVALID, |
| 381 |
|
| 382 |
.compat_dhcp_use_domains = _USE_DOMAINS_INVALID, |
| 383 |
.compat_dhcp_use_dns = -1, |
| 384 |
.compat_dhcp_use_ntp = -1, |
| 385 |
|
| 386 |
.dhcp_duid.type = _DUID_TYPE_INVALID, |
| 387 |
.dhcp_critical = -1, |
| 388 |
.dhcp_use_ntp = -1, |
| 389 |
.dhcp_routes_to_ntp = true, |
| 390 |
.dhcp_use_sip = true, |
| 391 |
.dhcp_use_captive_portal = true, |
| 392 |
.dhcp_use_dns = -1, |
| 393 |
.dhcp_use_dnr = -1, |
| 394 |
.dhcp_routes_to_dns = true, |
| 395 |
.dhcp_use_domains = _USE_DOMAINS_INVALID, |
| 396 |
.dhcp_use_hostname = true, |
| 397 |
.dhcp_use_routes = true, |
| 398 |
.dhcp_use_gateway = -1, |
| 399 |
.dhcp_send_hostname = true, |
| 400 |
.dhcp_send_release = true, |
| 401 |
.dhcp_extra_options = TLV_INIT(TLV_DHCP4), |
| 402 |
.dhcp_vendor_options = TLV_INIT(TLV_DHCP4_SUBOPTION), |
| 403 |
.dhcp_route_metric = DHCP_ROUTE_METRIC, |
| 404 |
.dhcp_use_rapid_commit = -1, |
| 405 |
.dhcp_client_identifier = _DHCP_CLIENT_ID_INVALID, |
| 406 |
.dhcp_route_table = RT_TABLE_MAIN, |
| 407 |
.dhcp_ip_service_type = -1, |
| 408 |
.dhcp_socket_priority = -1, |
| 409 |
.dhcp_broadcast = -1, |
| 410 |
.dhcp_ipv6_only_mode = -1, |
| 411 |
.dhcp_6rd_prefix_route_type = RTN_UNREACHABLE, |
| 412 |
|
| 413 |
.dhcp6_use_address = true, |
| 414 |
.dhcp6_use_pd_prefix = true, |
| 415 |
.dhcp6_use_dns = -1, |
| 416 |
.dhcp6_use_dnr = -1, |
| 417 |
.dhcp6_use_domains = _USE_DOMAINS_INVALID, |
| 418 |
.dhcp6_use_hostname = true, |
| 419 |
.dhcp6_use_ntp = -1, |
| 420 |
.dhcp6_use_sip = true, |
| 421 |
.dhcp6_use_captive_portal = true, |
| 422 |
.dhcp6_use_rapid_commit = true, |
| 423 |
.dhcp6_send_hostname = true, |
| 424 |
.dhcp6_duid.type = _DUID_TYPE_INVALID, |
| 425 |
.dhcp6_client_start_mode = _DHCP6_CLIENT_START_MODE_INVALID, |
| 426 |
.dhcp6_send_release = true, |
| 427 |
.dhcp6_pd_prefix_route_type = RTN_UNREACHABLE, |
| 428 |
.dhcp6_route_table = RT_TABLE_MAIN, |
| 429 |
|
| 430 |
.dhcp_pd = -1, |
| 431 |
.dhcp_pd_announce = true, |
| 432 |
.dhcp_pd_assign = true, |
| 433 |
.dhcp_pd_manage_temporary_address = true, |
| 434 |
.dhcp_pd_subnet_id = -1, |
| 435 |
.dhcp_pd_route_metric = DHCP6PD_ROUTE_METRIC, |
| 436 |
|
| 437 |
.dhcp_relay_interface_mode = _DHCP_RELAY_INTERFACE_INVALID, |
| 438 |
.dhcp_relay_extra_options = TLV_INIT(TLV_DHCP4_SUBOPTION), |
| 439 |
|
| 440 |
.dhcp_server_emit[SD_DHCP_LEASE_DNS].emit = true, |
| 441 |
.dhcp_server_emit[SD_DHCP_LEASE_NTP].emit = true, |
| 442 |
.dhcp_server_emit[SD_DHCP_LEASE_SIP].emit = true, |
| 443 |
.dhcp_server_emit_router = true, |
| 444 |
.dhcp_server_emit_timezone = true, |
| 445 |
.dhcp_server_rapid_commit = true, |
| 446 |
.dhcp_server_extra_options = TLV_INIT(TLV_DHCP4), |
| 447 |
.dhcp_server_vendor_options = TLV_INIT(TLV_DHCP4_SUBOPTION), |
| 448 |
.dhcp_server_persist_leases = _DHCP_SERVER_PERSIST_LEASES_INVALID, |
| 449 |
|
| 450 |
.router_lifetime_usec = RADV_DEFAULT_ROUTER_LIFETIME_USEC, |
| 451 |
.router_dns_lifetime_usec = RADV_DEFAULT_VALID_LIFETIME_USEC, |
| 452 |
.router_emit_dns = true, |
| 453 |
.router_emit_domains = true, |
| 454 |
|
| 455 |
.use_bpdu = -1, |
| 456 |
.hairpin = -1, |
| 457 |
.isolated = -1, |
| 458 |
.fast_leave = -1, |
| 459 |
.allow_port_to_be_root = -1, |
| 460 |
.unicast_flood = -1, |
| 461 |
.multicast_flood = -1, |
| 462 |
.multicast_to_unicast = -1, |
| 463 |
.neighbor_suppression = -1, |
| 464 |
.learning = -1, |
| 465 |
.bridge_proxy_arp = -1, |
| 466 |
.bridge_proxy_arp_wifi = -1, |
| 467 |
.priority = LINK_BRIDGE_PORT_PRIORITY_INVALID, |
| 468 |
.multicast_router = _MULTICAST_ROUTER_INVALID, |
| 469 |
.bridge_locked = -1, |
| 470 |
.bridge_mac_authentication_bypass = -1, |
| 471 |
.bridge_vlan_tunnel = -1, |
| 472 |
|
| 473 |
.bridge_vlan_pvid = BRIDGE_VLAN_KEEP_PVID, |
| 474 |
|
| 475 |
.lldp_mode = LLDP_MODE_ROUTERS_ONLY, |
| 476 |
.lldp_multicast_mode = _SD_LLDP_MULTICAST_MODE_INVALID, |
| 477 |
|
| 478 |
.dns_default_route = -1, |
| 479 |
.llmnr = RESOLVE_SUPPORT_YES, |
| 480 |
.mdns = RESOLVE_SUPPORT_NO, |
| 481 |
.dnssec_mode = _DNSSEC_MODE_INVALID, |
| 482 |
.dns_over_tls_mode = _DNS_OVER_TLS_MODE_INVALID, |
| 483 |
|
| 484 |
/* If LinkLocalAddressing= is not set, then set to ADDRESS_FAMILY_IPV6 later. */ |
| 485 |
.link_local = _ADDRESS_FAMILY_INVALID, |
| 486 |
.ipv6ll_address_gen_mode = _IPV6_LINK_LOCAL_ADDRESS_GEN_MODE_INVALID, |
| 487 |
|
| 488 |
.ip_forwarding = { -1, -1, }, |
| 489 |
.ipv4_accept_local = -1, |
| 490 |
.ipv4_route_localnet = -1, |
| 491 |
.ipv4_src_valid_mark = -1, |
| 492 |
.ipv6_privacy_extensions = _IPV6_PRIVACY_EXTENSIONS_INVALID, |
| 493 |
.ipv6_dad_transmits = -1, |
| 494 |
.ipv6_proxy_ndp = -1, |
| 495 |
.proxy_arp = -1, |
| 496 |
.proxy_arp_pvlan = -1, |
| 497 |
.ipv4_rp_filter = _IP_REVERSE_PATH_FILTER_INVALID, |
| 498 |
.ipv4_force_igmp_version = _IPV4_FORCE_IGMP_VERSION_INVALID, |
| 499 |
.mpls_input = -1, |
| 500 |
|
| 501 |
.ndisc = -1, |
| 502 |
.ndisc_use_redirect = true, |
| 503 |
.ndisc_use_dns = -1, |
| 504 |
.ndisc_use_dnr = -1, |
| 505 |
.ndisc_use_gateway = true, |
| 506 |
.ndisc_use_captive_portal = true, |
| 507 |
.ndisc_use_route_prefix = true, |
| 508 |
.ndisc_use_autonomous_prefix = true, |
| 509 |
.ndisc_use_onlink_prefix = true, |
| 510 |
.ndisc_use_mtu = true, |
| 511 |
.ndisc_use_hop_limit = true, |
| 512 |
.ndisc_use_reachable_time = true, |
| 513 |
.ndisc_use_retransmission_time = true, |
| 514 |
.ndisc_use_domains = _USE_DOMAINS_INVALID, |
| 515 |
.ndisc_route_table = RT_TABLE_MAIN, |
| 516 |
.ndisc_route_metric_high = IPV6RA_ROUTE_METRIC_HIGH, |
| 517 |
.ndisc_route_metric_medium = IPV6RA_ROUTE_METRIC_MEDIUM, |
| 518 |
.ndisc_route_metric_low = IPV6RA_ROUTE_METRIC_LOW, |
| 519 |
.ndisc_start_dhcp6_client = IPV6_ACCEPT_RA_START_DHCP6_CLIENT_YES, |
| 520 |
|
| 521 |
.can_termination = -1, |
| 522 |
|
| 523 |
.ipoib_mode = _IP_OVER_INFINIBAND_MODE_INVALID, |
| 524 |
.ipoib_umcast = -1, |
| 525 |
|
| 526 |
.mm_allow_roaming = true, |
| 527 |
.mm_allowed_auth = MM_BEARER_ALLOWED_AUTH_UNKNOWN, |
| 528 |
.mm_ip_family = MM_BEARER_IP_FAMILY_NONE, |
| 529 |
.mm_use_gateway = -1, |
| 530 |
}; |
| 531 |
|
| 532 |
r = config_parse_many_full( |
| 533 |
STRV_MAKE_CONST(filename), |
| 534 |
NETWORK_DIRS, |
| 535 |
dropin_dirname, |
| 536 |
/* root= */ NULL, |
| 537 |
/* root_fd= */ -EBADF, |
| 538 |
"Match\0" |
| 539 |
"Link\0" |
| 540 |
"SR-IOV\0" |
| 541 |
"Network\0" |
| 542 |
"Address\0" |
| 543 |
"Neighbor\0" |
| 544 |
"IPv6AddressLabel\0" |
| 545 |
"RoutingPolicyRule\0" |
| 546 |
"Route\0" |
| 547 |
"NextHop\0" |
| 548 |
"DHCP\0" /* compat */ |
| 549 |
"DHCPv4\0" |
| 550 |
"DHCPv6\0" |
| 551 |
"DHCPv6PrefixDelegation\0" /* compat */ |
| 552 |
"DHCPPrefixDelegation\0" |
| 553 |
"DHCPRelay\0" |
| 554 |
"DHCPServer\0" |
| 555 |
"DHCPServerStaticLease\0" |
| 556 |
"IPv6AcceptRA\0" |
| 557 |
"Bridge\0" |
| 558 |
"BridgeFDB\0" |
| 559 |
"BridgeMDB\0" |
| 560 |
"BridgeVLAN\0" |
| 561 |
"IPv6SendRA\0" |
| 562 |
"IPv6PrefixDelegation\0" |
| 563 |
"IPv6Prefix\0" |
| 564 |
"IPv6RoutePrefix\0" |
| 565 |
"IPv6PREF64Prefix\0" |
| 566 |
"LLDP\0" |
| 567 |
"TrafficControlQueueingDiscipline\0" |
| 568 |
"CAN\0" |
| 569 |
"MobileNetwork\0" |
| 570 |
"QDisc\0" |
| 571 |
"BFIFO\0" |
| 572 |
"CAKE\0" |
| 573 |
"ControlledDelay\0" |
| 574 |
"DeficitRoundRobinScheduler\0" |
| 575 |
"DeficitRoundRobinSchedulerClass\0" |
| 576 |
"EnhancedTransmissionSelection\0" |
| 577 |
"FairQueueing\0" |
| 578 |
"FairQueueingControlledDelay\0" |
| 579 |
"FlowQueuePIE\0" |
| 580 |
"GenericRandomEarlyDetection\0" |
| 581 |
"HeavyHitterFilter\0" |
| 582 |
"HierarchyTokenBucket\0" |
| 583 |
"HierarchyTokenBucketClass\0" |
| 584 |
"ClassfulMultiQueueing\0" |
| 585 |
"BandMultiQueueing\0" |
| 586 |
"NetworkEmulator\0" |
| 587 |
"PFIFO\0" |
| 588 |
"PFIFOFast\0" |
| 589 |
"PFIFOHeadDrop\0" |
| 590 |
"PIE\0" |
| 591 |
"QuickFairQueueing\0" |
| 592 |
"QuickFairQueueingClass\0" |
| 593 |
"StochasticFairBlue\0" |
| 594 |
"StochasticFairnessQueueing\0" |
| 595 |
"TokenBucketFilter\0" |
| 596 |
"TrivialLinkEqualizer\0", |
| 597 |
config_item_perf_lookup, |
| 598 |
network_network_gperf_lookup, |
| 599 |
CONFIG_PARSE_WARN, |
| 600 |
network, |
| 601 |
&network->stats_by_path, |
| 602 |
&network->dropins); |
| 603 |
if (r < 0) |
| 604 |
return r; /* config_parse_many() logs internally. */ |
| 605 |
|
| 606 |
r = network_add_ipv4ll_route(network); |
| 607 |
if (r < 0) |
| 608 |
return log_warning_errno(r, "%s: Failed to add IPv4LL route: %m", network->filename); |
| 609 |
|
| 610 |
r = network_add_default_route_on_device(network); |
| 611 |
if (r < 0) |
| 612 |
return log_warning_errno(r, "%s: Failed to add default route on device: %m", |
| 613 |
network->filename); |
| 614 |
|
| 615 |
r = network_verify(network); |
| 616 |
if (r < 0) |
| 617 |
return r; /* network_verify() logs internally. */ |
| 618 |
|
| 619 |
r = ordered_hashmap_ensure_put(networks, &network_hash_ops, network->name, network); |
| 620 |
if (r < 0) |
| 621 |
return log_warning_errno(r, "%s: Failed to store configuration into hashmap: %m", filename); |
| 622 |
|
| 623 |
TAKE_PTR(network); |
| 624 |
log_syntax(/* unit= */ NULL, LOG_DEBUG, filename, /* config_line= */ 0, /* error= */ 0, "Successfully loaded."); |
| 625 |
return 0; |
| 626 |
} |
| 627 |
|
| 628 |
int network_load(Manager *manager, OrderedHashmap **ret) { |
| 629 |
_cleanup_strv_free_ char **files = NULL; |
| 630 |
OrderedHashmap *networks = NULL; |
| 631 |
int r; |
| 632 |
|
| 633 |
assert(manager); |
| 634 |
assert(ret); |
| 635 |
|
| 636 |
r = conf_files_list_strv(&files, ".network", /* root= */ NULL, CONF_FILES_WARN, NETWORK_DIRS); |
| 637 |
if (r < 0) |
| 638 |
return log_error_errno(r, "Failed to enumerate network files: %m"); |
| 639 |
|
| 640 |
STRV_FOREACH(f, files) |
| 641 |
(void) network_load_one(manager, &networks, *f); |
| 642 |
|
| 643 |
*ret = TAKE_PTR(networks); |
| 644 |
return 0; |
| 645 |
} |
| 646 |
|
| 647 |
static bool network_netdev_equal(Network *a, Network *b) { |
| 648 |
assert(a); |
| 649 |
assert(b); |
| 650 |
|
| 651 |
if (a->batadv != b->batadv || |
| 652 |
a->bridge != b->bridge || |
| 653 |
a->bond != b->bond || |
| 654 |
a->vrf != b->vrf || |
| 655 |
a->xfrm != b->xfrm) |
| 656 |
return false; |
| 657 |
|
| 658 |
if (hashmap_size(a->stacked_netdevs) != hashmap_size(b->stacked_netdevs)) |
| 659 |
return false; |
| 660 |
|
| 661 |
NetDev *n; |
| 662 |
HASHMAP_FOREACH(n, a->stacked_netdevs) |
| 663 |
if (hashmap_get(b->stacked_netdevs, n->ifname) != n) |
| 664 |
return false; |
| 665 |
|
| 666 |
return true; |
| 667 |
} |
| 668 |
|
| 669 |
int network_reload(Manager *manager) { |
| 670 |
_cleanup_ordered_hashmap_free_ OrderedHashmap *new_networks = NULL; |
| 671 |
Network *n, *old; |
| 672 |
int r; |
| 673 |
|
| 674 |
assert(manager); |
| 675 |
|
| 676 |
r = network_load(manager, &new_networks); |
| 677 |
if (r < 0) |
| 678 |
return r; |
| 679 |
|
| 680 |
ORDERED_HASHMAP_FOREACH(n, new_networks) { |
| 681 |
r = network_get_by_name(manager, n->name, &old); |
| 682 |
if (r < 0) { |
| 683 |
log_debug("%s: Found new .network file.", n->filename); |
| 684 |
continue; |
| 685 |
} |
| 686 |
|
| 687 |
if (!stats_by_path_equal(n->stats_by_path, old->stats_by_path)) { |
| 688 |
log_debug("%s: Found updated .network file.", n->filename); |
| 689 |
continue; |
| 690 |
} |
| 691 |
|
| 692 |
if (!network_netdev_equal(n, old)) { |
| 693 |
log_debug("%s: Detected update of referenced .netdev file(s).", n->filename); |
| 694 |
continue; |
| 695 |
} |
| 696 |
|
| 697 |
/* Nothing updated, use the existing Network object, and drop the new one. */ |
| 698 |
r = ordered_hashmap_replace(new_networks, old->name, old); |
| 699 |
if (r < 0) |
| 700 |
return r; |
| 701 |
|
| 702 |
network_ref(old); |
| 703 |
network_unref(n); |
| 704 |
} |
| 705 |
|
| 706 |
ordered_hashmap_free_and_replace(manager->networks, new_networks); |
| 707 |
|
| 708 |
r = manager_build_dhcp_pd_subnet_ids(manager); |
| 709 |
if (r < 0) |
| 710 |
return r; |
| 711 |
|
| 712 |
r = manager_build_nexthop_ids(manager); |
| 713 |
if (r < 0) |
| 714 |
return r; |
| 715 |
|
| 716 |
return 0; |
| 717 |
} |
| 718 |
|
| 719 |
int manager_build_dhcp_pd_subnet_ids(Manager *manager) { |
| 720 |
Network *n; |
| 721 |
int r; |
| 722 |
|
| 723 |
assert(manager); |
| 724 |
|
| 725 |
set_clear(manager->dhcp_pd_subnet_ids); |
| 726 |
|
| 727 |
ORDERED_HASHMAP_FOREACH(n, manager->networks) { |
| 728 |
if (n->unmanaged) |
| 729 |
continue; |
| 730 |
|
| 731 |
if (!n->dhcp_pd) |
| 732 |
continue; |
| 733 |
|
| 734 |
if (n->dhcp_pd_subnet_id < 0) |
| 735 |
continue; |
| 736 |
|
| 737 |
r = set_ensure_put(&manager->dhcp_pd_subnet_ids, &uint64_hash_ops, &n->dhcp_pd_subnet_id); |
| 738 |
if (r < 0) |
| 739 |
return r; |
| 740 |
} |
| 741 |
|
| 742 |
return 0; |
| 743 |
} |
| 744 |
|
| 745 |
static Network *network_free(Network *network) { |
| 746 |
if (!network) |
| 747 |
return NULL; |
| 748 |
|
| 749 |
free(network->name); |
| 750 |
free(network->filename); |
| 751 |
free(network->description); |
| 752 |
strv_free(network->dropins); |
| 753 |
hashmap_free(network->stats_by_path); |
| 754 |
|
| 755 |
/* conditions */ |
| 756 |
net_match_clear(&network->match); |
| 757 |
condition_free_list(network->conditions); |
| 758 |
|
| 759 |
/* link settings */ |
| 760 |
strv_free(network->bind_carrier); |
| 761 |
|
| 762 |
/* NTP */ |
| 763 |
strv_free(network->ntp); |
| 764 |
|
| 765 |
/* DNS */ |
| 766 |
for (unsigned i = 0; i < network->n_dns; i++) |
| 767 |
in_addr_full_free(network->dns[i]); |
| 768 |
free(network->dns); |
| 769 |
ordered_set_free(network->search_domains); |
| 770 |
ordered_set_free(network->route_domains); |
| 771 |
set_free(network->dnssec_negative_trust_anchors); |
| 772 |
|
| 773 |
/* DHCP relay agent */ |
| 774 |
iovec_done(&network->dhcp_relay_remote_id); |
| 775 |
iovec_done(&network->dhcp_relay_circuit_id); |
| 776 |
iovec_done(&network->dhcp_relay_vss); |
| 777 |
tlv_done(&network->dhcp_relay_extra_options); |
| 778 |
|
| 779 |
/* DHCP server */ |
| 780 |
free(network->dhcp_server_boot_server_name); |
| 781 |
free(network->dhcp_server_boot_filename); |
| 782 |
free(network->dhcp_server_timezone); |
| 783 |
free(network->dhcp_server_domain); |
| 784 |
free(network->dhcp_server_uplink_name); |
| 785 |
for (sd_dhcp_lease_server_type_t t = 0; t < _SD_DHCP_LEASE_SERVER_TYPE_MAX; t++) |
| 786 |
free(network->dhcp_server_emit[t].addresses); |
| 787 |
tlv_done(&network->dhcp_server_extra_options); |
| 788 |
tlv_done(&network->dhcp_server_vendor_options); |
| 789 |
free(network->dhcp_server_local_lease_domain); |
| 790 |
|
| 791 |
/* DHCP client */ |
| 792 |
free(network->dhcp_vendor_class_identifier); |
| 793 |
free(network->dhcp_mudurl); |
| 794 |
free(network->dhcp_hostname); |
| 795 |
free(network->dhcp_label); |
| 796 |
set_free(network->dhcp_deny_listed_ip); |
| 797 |
set_free(network->dhcp_allow_listed_ip); |
| 798 |
iovw_done_free(&network->dhcp_user_class); |
| 799 |
set_free(network->dhcp_request_options); |
| 800 |
tlv_done(&network->dhcp_extra_options); |
| 801 |
tlv_done(&network->dhcp_vendor_options); |
| 802 |
free(network->dhcp_netlabel); |
| 803 |
nft_set_context_clear(&network->dhcp_nft_set_context); |
| 804 |
|
| 805 |
/* DHCPv6 client */ |
| 806 |
free(network->dhcp6_mudurl); |
| 807 |
free(network->dhcp6_hostname); |
| 808 |
strv_free(network->dhcp6_user_class); |
| 809 |
strv_free(network->dhcp6_vendor_class); |
| 810 |
set_free(network->dhcp6_request_options); |
| 811 |
ordered_hashmap_free(network->dhcp6_client_send_options); |
| 812 |
ordered_hashmap_free(network->dhcp6_client_send_vendor_options); |
| 813 |
free(network->dhcp6_netlabel); |
| 814 |
nft_set_context_clear(&network->dhcp6_nft_set_context); |
| 815 |
|
| 816 |
/* DHCP PD */ |
| 817 |
free(network->dhcp_pd_uplink_name); |
| 818 |
set_free(network->dhcp_pd_tokens); |
| 819 |
free(network->dhcp_pd_netlabel); |
| 820 |
nft_set_context_clear(&network->dhcp_pd_nft_set_context); |
| 821 |
|
| 822 |
/* Router advertisement */ |
| 823 |
ordered_set_free(network->router_search_domains); |
| 824 |
free(network->router_dns); |
| 825 |
free(network->router_uplink_name); |
| 826 |
|
| 827 |
/* NDisc */ |
| 828 |
set_free(network->ndisc_deny_listed_router); |
| 829 |
set_free(network->ndisc_allow_listed_router); |
| 830 |
set_free(network->ndisc_deny_listed_prefix); |
| 831 |
set_free(network->ndisc_allow_listed_prefix); |
| 832 |
set_free(network->ndisc_deny_listed_route_prefix); |
| 833 |
set_free(network->ndisc_allow_listed_route_prefix); |
| 834 |
set_free(network->ndisc_tokens); |
| 835 |
free(network->ndisc_netlabel); |
| 836 |
nft_set_context_clear(&network->ndisc_nft_set_context); |
| 837 |
|
| 838 |
/* LLDP */ |
| 839 |
free(network->lldp_mudurl); |
| 840 |
|
| 841 |
/* netdev */ |
| 842 |
free(network->batadv_name); |
| 843 |
free(network->bridge_name); |
| 844 |
free(network->bond_name); |
| 845 |
free(network->vrf_name); |
| 846 |
hashmap_free(network->stacked_netdev_names); |
| 847 |
netdev_unref(network->bridge); |
| 848 |
netdev_unref(network->bond); |
| 849 |
netdev_unref(network->vrf); |
| 850 |
hashmap_free(network->stacked_netdevs); |
| 851 |
|
| 852 |
/* static configs */ |
| 853 |
set_free(network->ipv6_proxy_ndp_addresses); |
| 854 |
ordered_hashmap_free(network->addresses_by_section); |
| 855 |
hashmap_free(network->routes_by_section); |
| 856 |
ordered_hashmap_free(network->nexthops_by_section); |
| 857 |
hashmap_free(network->bridge_fdb_entries_by_section); |
| 858 |
hashmap_free(network->bridge_mdb_entries_by_section); |
| 859 |
ordered_hashmap_free(network->neighbors_by_section); |
| 860 |
hashmap_free(network->address_labels_by_section); |
| 861 |
hashmap_free(network->prefixes_by_section); |
| 862 |
hashmap_free(network->route_prefixes_by_section); |
| 863 |
hashmap_free(network->pref64_prefixes_by_section); |
| 864 |
hashmap_free(network->rules_by_section); |
| 865 |
hashmap_free(network->dhcp_static_leases_by_section); |
| 866 |
ordered_hashmap_free(network->sr_iov_by_section); |
| 867 |
hashmap_free(network->qdiscs_by_section); |
| 868 |
hashmap_free(network->tclasses_by_section); |
| 869 |
|
| 870 |
/* ModemManager */ |
| 871 |
free(network->mm_apn); |
| 872 |
free(network->mm_operator_id); |
| 873 |
free(network->mm_user); |
| 874 |
free(network->mm_password); |
| 875 |
free(network->mm_pin); |
| 876 |
|
| 877 |
return mfree(network); |
| 878 |
} |
| 879 |
|
| 880 |
DEFINE_TRIVIAL_REF_UNREF_FUNC(Network, network, network_free); |
| 881 |
|
| 882 |
int network_get_by_name(Manager *manager, const char *name, Network **ret) { |
| 883 |
Network *network; |
| 884 |
|
| 885 |
assert(manager); |
| 886 |
assert(name); |
| 887 |
assert(ret); |
| 888 |
|
| 889 |
network = ordered_hashmap_get(manager->networks, name); |
| 890 |
if (!network) |
| 891 |
return -ENOENT; |
| 892 |
|
| 893 |
*ret = network; |
| 894 |
|
| 895 |
return 0; |
| 896 |
} |
| 897 |
|
| 898 |
bool network_has_static_ipv6_configurations(Network *network) { |
| 899 |
Address *address; |
| 900 |
Route *route; |
| 901 |
BridgeFDB *fdb; |
| 902 |
BridgeMDB *mdb; |
| 903 |
Neighbor *neighbor; |
| 904 |
|
| 905 |
assert(network); |
| 906 |
|
| 907 |
ORDERED_HASHMAP_FOREACH(address, network->addresses_by_section) |
| 908 |
if (address->family == AF_INET6) |
| 909 |
return true; |
| 910 |
|
| 911 |
HASHMAP_FOREACH(route, network->routes_by_section) |
| 912 |
if (route->family == AF_INET6) |
| 913 |
return true; |
| 914 |
|
| 915 |
HASHMAP_FOREACH(fdb, network->bridge_fdb_entries_by_section) |
| 916 |
if (fdb->family == AF_INET6) |
| 917 |
return true; |
| 918 |
|
| 919 |
HASHMAP_FOREACH(mdb, network->bridge_mdb_entries_by_section) |
| 920 |
if (mdb->family == AF_INET6) |
| 921 |
return true; |
| 922 |
|
| 923 |
ORDERED_HASHMAP_FOREACH(neighbor, network->neighbors_by_section) |
| 924 |
if (neighbor->dst_addr.family == AF_INET6) |
| 925 |
return true; |
| 926 |
|
| 927 |
if (!hashmap_isempty(network->address_labels_by_section)) |
| 928 |
return true; |
| 929 |
|
| 930 |
if (!hashmap_isempty(network->prefixes_by_section)) |
| 931 |
return true; |
| 932 |
|
| 933 |
if (!hashmap_isempty(network->route_prefixes_by_section)) |
| 934 |
return true; |
| 935 |
|
| 936 |
if (!hashmap_isempty(network->pref64_prefixes_by_section)) |
| 937 |
return true; |
| 938 |
|
| 939 |
return false; |
| 940 |
} |
| 941 |
|
| 942 |
int config_parse_stacked_netdev( |
| 943 |
const char *unit, |
| 944 |
const char *filename, |
| 945 |
unsigned line, |
| 946 |
const char *section, |
| 947 |
unsigned section_line, |
| 948 |
const char *lvalue, |
| 949 |
int ltype, |
| 950 |
const char *rvalue, |
| 951 |
void *data, |
| 952 |
void *userdata) { |
| 953 |
|
| 954 |
_cleanup_free_ char *name = NULL; |
| 955 |
NetDevKind kind = ltype; |
| 956 |
Hashmap **h = ASSERT_PTR(data); |
| 957 |
int r; |
| 958 |
|
| 959 |
assert(filename); |
| 960 |
assert(lvalue); |
| 961 |
assert(rvalue); |
| 962 |
assert(IN_SET(kind, |
| 963 |
NETDEV_KIND_IPOIB, |
| 964 |
NETDEV_KIND_IPVLAN, |
| 965 |
NETDEV_KIND_IPVTAP, |
| 966 |
NETDEV_KIND_MACSEC, |
| 967 |
NETDEV_KIND_MACVLAN, |
| 968 |
NETDEV_KIND_MACVTAP, |
| 969 |
NETDEV_KIND_VLAN, |
| 970 |
NETDEV_KIND_VXLAN, |
| 971 |
NETDEV_KIND_XFRM, |
| 972 |
_NETDEV_KIND_TUNNEL)); |
| 973 |
|
| 974 |
if (!ifname_valid(rvalue)) { |
| 975 |
log_syntax(unit, LOG_WARNING, filename, line, 0, |
| 976 |
"Invalid netdev name in %s=, ignoring assignment: %s", lvalue, rvalue); |
| 977 |
return 0; |
| 978 |
} |
| 979 |
|
| 980 |
name = strdup(rvalue); |
| 981 |
if (!name) |
| 982 |
return log_oom(); |
| 983 |
|
| 984 |
r = hashmap_ensure_put(h, &string_hash_ops_free, name, INT_TO_PTR(kind)); |
| 985 |
if (r == -ENOMEM) |
| 986 |
return log_oom(); |
| 987 |
if (r < 0) |
| 988 |
log_syntax(unit, LOG_WARNING, filename, line, r, |
| 989 |
"Cannot add NetDev '%s' to network, ignoring assignment: %m", name); |
| 990 |
else if (r == 0) |
| 991 |
log_syntax(unit, LOG_DEBUG, filename, line, r, |
| 992 |
"NetDev '%s' specified twice, ignoring.", name); |
| 993 |
else |
| 994 |
TAKE_PTR(name); |
| 995 |
|
| 996 |
return 0; |
| 997 |
} |
| 998 |
|
| 999 |
int config_parse_required_for_online( |
| 1000 |
const char *unit, |
| 1001 |
const char *filename, |
| 1002 |
unsigned line, |
| 1003 |
const char *section, |
| 1004 |
unsigned section_line, |
| 1005 |
const char *lvalue, |
| 1006 |
int ltype, |
| 1007 |
const char *rvalue, |
| 1008 |
void *data, |
| 1009 |
void *userdata) { |
| 1010 |
|
| 1011 |
Network *network = ASSERT_PTR(userdata); |
| 1012 |
int r; |
| 1013 |
|
| 1014 |
assert(filename); |
| 1015 |
assert(lvalue); |
| 1016 |
assert(rvalue); |
| 1017 |
|
| 1018 |
if (isempty(rvalue)) { |
| 1019 |
network->required_for_online = -1; |
| 1020 |
network->required_operstate_for_online = LINK_OPERSTATE_RANGE_INVALID; |
| 1021 |
return 0; |
| 1022 |
} |
| 1023 |
|
| 1024 |
r = parse_operational_state_range(rvalue, &network->required_operstate_for_online); |
| 1025 |
if (r < 0) { |
| 1026 |
r = parse_boolean(rvalue); |
| 1027 |
if (r < 0) { |
| 1028 |
log_syntax(unit, LOG_WARNING, filename, line, r, |
| 1029 |
"Failed to parse %s= setting, ignoring assignment: %s", |
| 1030 |
lvalue, rvalue); |
| 1031 |
return 0; |
| 1032 |
} |
| 1033 |
|
| 1034 |
network->required_for_online = r; |
| 1035 |
network->required_operstate_for_online = LINK_OPERSTATE_RANGE_DEFAULT; |
| 1036 |
return 0; |
| 1037 |
} |
| 1038 |
|
| 1039 |
network->required_for_online = true; |
| 1040 |
return 0; |
| 1041 |
} |
| 1042 |
|
| 1043 |
int config_parse_link_group( |
| 1044 |
const char *unit, |
| 1045 |
const char *filename, |
| 1046 |
unsigned line, |
| 1047 |
const char *section, |
| 1048 |
unsigned section_line, |
| 1049 |
const char *lvalue, |
| 1050 |
int ltype, |
| 1051 |
const char *rvalue, |
| 1052 |
void *data, |
| 1053 |
void *userdata) { |
| 1054 |
|
| 1055 |
Network *network = ASSERT_PTR(userdata); |
| 1056 |
int r; |
| 1057 |
int32_t group; |
| 1058 |
|
| 1059 |
assert(filename); |
| 1060 |
assert(lvalue); |
| 1061 |
assert(rvalue); |
| 1062 |
|
| 1063 |
if (isempty(rvalue)) { |
| 1064 |
network->group = -1; |
| 1065 |
return 0; |
| 1066 |
} |
| 1067 |
|
| 1068 |
r = safe_atoi32(rvalue, &group); |
| 1069 |
if (r < 0) { |
| 1070 |
log_syntax(unit, LOG_WARNING, filename, line, r, |
| 1071 |
"Failed to parse Group=, ignoring assignment: %s", rvalue); |
| 1072 |
return 0; |
| 1073 |
} |
| 1074 |
|
| 1075 |
if (group < 0) { |
| 1076 |
log_syntax(unit, LOG_WARNING, filename, line, r, |
| 1077 |
"Value of Group= must be in the range 0…2147483647, ignoring assignment: %s", rvalue); |
| 1078 |
return 0; |
| 1079 |
} |
| 1080 |
|
| 1081 |
network->group = group; |
| 1082 |
return 0; |
| 1083 |
} |
| 1084 |
|
| 1085 |
int config_parse_ignore_carrier_loss( |
| 1086 |
const char *unit, |
| 1087 |
const char *filename, |
| 1088 |
unsigned line, |
| 1089 |
const char *section, |
| 1090 |
unsigned section_line, |
| 1091 |
const char *lvalue, |
| 1092 |
int ltype, |
| 1093 |
const char *rvalue, |
| 1094 |
void *data, |
| 1095 |
void *userdata) { |
| 1096 |
|
| 1097 |
Network *network = ASSERT_PTR(userdata); |
| 1098 |
usec_t usec; |
| 1099 |
int r; |
| 1100 |
|
| 1101 |
assert(filename); |
| 1102 |
assert(lvalue); |
| 1103 |
assert(rvalue); |
| 1104 |
|
| 1105 |
if (isempty(rvalue)) { |
| 1106 |
network->ignore_carrier_loss_set = false; |
| 1107 |
return 0; |
| 1108 |
} |
| 1109 |
|
| 1110 |
r = parse_boolean(rvalue); |
| 1111 |
if (r >= 0) { |
| 1112 |
network->ignore_carrier_loss_set = true; |
| 1113 |
network->ignore_carrier_loss_usec = r > 0 ? USEC_INFINITY : 0; |
| 1114 |
return 0; |
| 1115 |
} |
| 1116 |
|
| 1117 |
r = parse_sec(rvalue, &usec); |
| 1118 |
if (r < 0) { |
| 1119 |
log_syntax(unit, LOG_WARNING, filename, line, r, |
| 1120 |
"Failed to parse %s=, ignoring assignment: %s", lvalue, rvalue); |
| 1121 |
return 0; |
| 1122 |
} |
| 1123 |
|
| 1124 |
network->ignore_carrier_loss_set = true; |
| 1125 |
network->ignore_carrier_loss_usec = usec; |
| 1126 |
return 0; |
| 1127 |
} |
| 1128 |
|
| 1129 |
int config_parse_keep_configuration( |
| 1130 |
const char *unit, |
| 1131 |
const char *filename, |
| 1132 |
unsigned line, |
| 1133 |
const char *section, |
| 1134 |
unsigned section_line, |
| 1135 |
const char *lvalue, |
| 1136 |
int ltype, |
| 1137 |
const char *rvalue, |
| 1138 |
void *data, |
| 1139 |
void *userdata) { |
| 1140 |
|
| 1141 |
KeepConfiguration t, *k = ASSERT_PTR(data); |
| 1142 |
Network *network = ASSERT_PTR(userdata); |
| 1143 |
|
| 1144 |
if (isempty(rvalue)) { |
| 1145 |
*k = ASSERT_PTR(network->manager)->keep_configuration; |
| 1146 |
return 0; |
| 1147 |
} |
| 1148 |
|
| 1149 |
/* backward compatibility */ |
| 1150 |
if (streq(rvalue, "dhcp")) { |
| 1151 |
*k = KEEP_CONFIGURATION_DYNAMIC; |
| 1152 |
return 0; |
| 1153 |
} |
| 1154 |
|
| 1155 |
if (streq(rvalue, "dhcp-on-stop")) { |
| 1156 |
*k = KEEP_CONFIGURATION_DYNAMIC_ON_STOP; |
| 1157 |
return 0; |
| 1158 |
} |
| 1159 |
|
| 1160 |
t = keep_configuration_from_string(rvalue); |
| 1161 |
if (t < 0) |
| 1162 |
return log_syntax_parse_error(unit, filename, line, t, lvalue, rvalue); |
| 1163 |
|
| 1164 |
*k = t; |
| 1165 |
return 0; |
| 1166 |
} |
| 1167 |
|
| 1168 |
DEFINE_CONFIG_PARSE_ENUM(config_parse_required_family_for_online, link_required_address_family, AddressFamily); |
| 1169 |
|
| 1170 |
static const char* const keep_configuration_table[_KEEP_CONFIGURATION_MAX] = { |
| 1171 |
[KEEP_CONFIGURATION_NO] = "no", |
| 1172 |
[KEEP_CONFIGURATION_DYNAMIC_ON_STOP] = "dynamic-on-stop", |
| 1173 |
[KEEP_CONFIGURATION_DYNAMIC] = "dynamic", |
| 1174 |
[KEEP_CONFIGURATION_STATIC] = "static", |
| 1175 |
[KEEP_CONFIGURATION_YES] = "yes", |
| 1176 |
}; |
| 1177 |
|
| 1178 |
DEFINE_STRING_TABLE_LOOKUP_WITH_BOOLEAN(keep_configuration, KeepConfiguration, KEEP_CONFIGURATION_YES); |
| 1179 |
|
| 1180 |
static const char* const activation_policy_table[_ACTIVATION_POLICY_MAX] = { |
| 1181 |
[ACTIVATION_POLICY_UP] = "up", |
| 1182 |
[ACTIVATION_POLICY_ALWAYS_UP] = "always-up", |
| 1183 |
[ACTIVATION_POLICY_MANUAL] = "manual", |
| 1184 |
[ACTIVATION_POLICY_ALWAYS_DOWN] = "always-down", |
| 1185 |
[ACTIVATION_POLICY_DOWN] = "down", |
| 1186 |
[ACTIVATION_POLICY_BOUND] = "bound", |
| 1187 |
}; |
| 1188 |
|
| 1189 |
DEFINE_STRING_TABLE_LOOKUP(activation_policy, ActivationPolicy); |
| 1190 |
DEFINE_CONFIG_PARSE_ENUM(config_parse_activation_policy, activation_policy, ActivationPolicy); |