Lines Matching refs:network

29 #include "network-internal.h"
30 #include "networkd-network.h"
40 _cleanup_network_free_ Network *network = NULL;
63 network = new0(Network, 1);
64 if (!network)
67 network->manager = manager;
69 LIST_HEAD_INIT(network->static_addresses);
70 LIST_HEAD_INIT(network->static_routes);
71 LIST_HEAD_INIT(network->static_fdb_entries);
73 network->stacked_netdevs = hashmap_new(&string_hash_ops);
74 if (!network->stacked_netdevs)
77 network->addresses_by_section = hashmap_new(NULL);
78 if (!network->addresses_by_section)
81 network->routes_by_section = hashmap_new(NULL);
82 if (!network->routes_by_section)
85 network->fdb_entries_by_section = hashmap_new(NULL);
86 if (!network->fdb_entries_by_section)
89 network->filename = strdup(filename);
90 if (!network->filename)
93 network->name = strdup(basename(filename));
94 if (!network->name)
97 d = strrchr(network->name, '.');
101 assert(streq(d, ".network"));
105 network->dhcp = ADDRESS_FAMILY_NO;
106 network->dhcp_use_ntp = true;
107 network->dhcp_use_dns = true;
108 network->dhcp_use_hostname = true;
109 network->dhcp_use_routes = true;
110 network->dhcp_send_hostname = true;
111 network->dhcp_route_metric = DHCP_ROUTE_METRIC;
112 network->dhcp_client_identifier = DHCP_CLIENT_ID_DUID;
114 network->dhcp_server_emit_dns = true;
115 network->dhcp_server_emit_ntp = true;
116 network->dhcp_server_emit_timezone = true;
118 network->use_bpdu = true;
119 network->allow_port_to_be_root = true;
120 network->unicast_flood = true;
122 network->llmnr = RESOLVE_SUPPORT_YES;
123 network->mdns = RESOLVE_SUPPORT_NO;
124 network->dnssec_mode = _DNSSEC_MODE_INVALID;
126 network->link_local = ADDRESS_FAMILY_IPV6;
128 network->ipv6_privacy_extensions = IPV6_PRIVACY_EXTENSIONS_NO;
129 network->ipv6_accept_ra = -1;
130 network->ipv6_dad_transmits = -1;
131 network->ipv6_hop_limit = -1;
145 false, false, true, network);
150 if (network->ip_masquerade)
151 network->ip_forward |= ADDRESS_FAMILY_IPV4;
153 LIST_PREPEND(networks, manager->networks, network);
159 r = hashmap_put(manager->networks_by_name, network->name, network);
163 LIST_FOREACH(routes, route, network->static_routes) {
171 LIST_FOREACH(addresses, address, network->static_addresses) {
179 network = NULL;
185 Network *network;
192 while ((network = manager->networks))
193 network_free(network);
195 r = conf_files_list_strv(&files, ".network", NULL, network_dirs);
197 return log_error_errno(r, "Failed to enumerate network files: %m");
208 void network_free(Network *network) {
215 if (!network)
218 free(network->filename);
220 free(network->match_mac);
221 strv_free(network->match_path);
222 strv_free(network->match_driver);
223 strv_free(network->match_type);
224 strv_free(network->match_name);
226 free(network->description);
227 free(network->dhcp_vendor_class_identifier);
228 free(network->dhcp_hostname);
230 free(network->mac);
232 strv_free(network->ntp);
233 strv_free(network->dns);
234 strv_free(network->search_domains);
235 strv_free(network->route_domains);
236 strv_free(network->bind_carrier);
238 netdev_unref(network->bridge);
240 netdev_unref(network->bond);
242 HASHMAP_FOREACH(netdev, network->stacked_netdevs, i) {
243 hashmap_remove(network->stacked_netdevs, netdev->ifname);
246 hashmap_free(network->stacked_netdevs);
248 while ((route = network->static_routes))
251 while ((address = network->static_addresses))
254 while ((fdb_entry = network->static_fdb_entries))
257 hashmap_free(network->addresses_by_section);
258 hashmap_free(network->routes_by_section);
259 hashmap_free(network->fdb_entries_by_section);
261 if (network->manager) {
262 if (network->manager->networks)
263 LIST_REMOVE(networks, network->manager->networks, network);
265 if (network->manager->networks_by_name)
266 hashmap_remove(network->manager->networks_by_name, network->name);
269 free(network->name);
271 condition_free_list(network->match_host);
272 condition_free_list(network->match_virt);
273 condition_free_list(network->match_kernel);
274 condition_free_list(network->match_arch);
276 free(network->dhcp_server_timezone);
277 free(network->dhcp_server_dns);
278 free(network->dhcp_server_ntp);
280 set_free_free(network->dnssec_negative_trust_anchors);
282 free(network);
286 Network *network;
292 network = hashmap_get(manager->networks_by_name, name);
293 if (!network)
296 *ret = network;
304 Network *network;
323 LIST_FOREACH(networks, network, manager->networks) {
324 if (net_match_config(network->match_mac, network->match_path,
325 network->match_driver, network->match_type,
326 network->match_name, network->match_host,
327 network->match_virt, network->match_kernel,
328 network->match_arch,
331 if (network->match_name && device) {
340 log_warning("%s: found matching network '%s', based on potentially unpredictable ifname",
341 ifname, network->filename);
343 log_debug("%s: found matching network '%s'", ifname, network->filename);
345 log_debug("%s: found matching network '%s'", ifname, network->filename);
347 *ret = network;
357 int network_apply(Manager *manager, Network *network, Link *link) {
361 assert(network);
364 link->network = network;
366 if (network->ipv4ll_route) {
369 r = route_new_static(network, 0, &route);
386 if (!strv_isempty(network->dns) ||
387 !strv_isempty(network->ntp) ||
388 !strv_isempty(network->search_domains) ||
389 !strv_isempty(network->route_domains)) {
407 Network *network = userdata;
433 r = netdev_get(network->manager, rvalue, &netdev);
446 network->bridge = netdev;
450 network->bond = netdev;
458 r = hashmap_put(network->stacked_netdevs, netdev->ifname, netdev);
460 log_syntax(unit, LOG_ERR, filename, line, r, "Can not add VLAN '%s' to network: %m", rvalue);
566 Network *network = userdata;
575 r = netdev_get(network->manager, rvalue, &netdev);
596 r = hashmap_put(network->stacked_netdevs, netdev->ifname, netdev);
598 log_syntax(unit, LOG_ERR, filename, line, r, "Cannot add VLAN '%s' to network, ignoring: %m", rvalue);