Lines Matching refs:link

128         if (address->link) {  in address_free()
129 set_remove(address->link->addresses, address); in address_free()
132 in6_addr_equal(&address->in_addr.in6, &address->link->ipv6ll_address)) in address_free()
133 memzero(&address->link->ipv6ll_address, sizeof(struct in6_addr)); in address_free()
161 void link_mark_addresses(Link *link, NetworkConfigSource source, const struct in6_addr *router) { in link_mark_addresses() argument
164 assert(link); in link_mark_addresses()
166 SET_FOREACH(a, link->addresses) { in link_mark_addresses()
178 static bool address_needs_to_set_broadcast(const Address *a, Link *link) { in address_needs_to_set_broadcast() argument
180 assert(link); in address_needs_to_set_broadcast()
202 return !streq_ptr(link->kind, "wireguard"); in address_needs_to_set_broadcast()
205 void address_set_broadcast(Address *a, Link *link) { in address_set_broadcast() argument
207 assert(link); in address_set_broadcast()
209 if (!address_needs_to_set_broadcast(a, link)) in address_set_broadcast()
399 dest->link = NULL; in address_dup()
418 assert(address->link); in address_set_masquerade()
420 if (!address->link->network) in address_set_masquerade()
424 !FLAGS_SET(address->link->network->ip_masquerade, ADDRESS_FAMILY_IPV4)) in address_set_masquerade()
428 !FLAGS_SET(address->link->network->ip_masquerade, ADDRESS_FAMILY_IPV6)) in address_set_masquerade()
442 …r = fw_add_masquerade(&address->link->manager->fw_ctx, add, address->family, &masked, address->pre… in address_set_masquerade()
451 static int address_add(Link *link, Address *address) { in address_add() argument
454 assert(link); in address_add()
457 r = set_ensure_put(&link->addresses, &address_hash_ops_free, address); in address_add()
463 address->link = link; in address_add()
468 Link *link; in address_update() local
472 assert(address->link); in address_update()
474 link = address->link; in address_update()
479 in6_addr_is_null(&link->ipv6ll_address)) { in address_update()
481 link->ipv6ll_address = address->in_addr.in6; in address_update()
483 r = link_ipv6ll_gained(link); in address_update()
488 if (IN_SET(link->state, LINK_STATE_FAILED, LINK_STATE_LINGER)) in address_update()
493 return log_link_warning_errno(link, r, "Could not enable IP masquerading: %m"); in address_update()
501 link_update_operstate(link, true); in address_update()
502 link_check_ready(link); in address_update()
507 Link *link; in address_drop() local
512 assert(address->link); in address_drop()
515 link = address->link; in address_drop()
519 log_link_warning_errno(link, r, "Failed to disable IP masquerading, ignoring: %m"); in address_drop()
524 link_update_operstate(link, true); in address_drop()
526 if (link && !ready) in address_drop()
527 link_check_ready(link); in address_drop()
532 int address_get(Link *link, const Address *in, Address **ret) { in address_get() argument
535 assert(link); in address_get()
538 existing = set_get(link->addresses, in); in address_get()
547 int link_get_address(Link *link, int family, const union in_addr_union *address, unsigned char pref… in link_get_address() argument
551 assert(link); in link_get_address()
571 address_set_broadcast(tmp, link); in link_get_address()
573 if (address_get(link, tmp, &a) >= 0) { in link_get_address()
587 SET_FOREACH(a, link->addresses) { in link_get_address()
607 Link *link; in manager_get_address() local
613 HASHMAP_FOREACH(link, manager->links_by_index) { in manager_get_address()
614 if (!IN_SET(link->state, LINK_STATE_CONFIGURING, LINK_STATE_CONFIGURED)) in manager_get_address()
617 if (link_get_address(link, family, address, prefixlen, ret) >= 0) in manager_get_address()
650 static void log_address_debug(const Address *address, const char *str, const Link *link) { in log_address_debug() argument
655 assert(link); in log_address_debug()
668 …log_link_debug(link, "%s %s address (%s): %s%s%s/%u (valid %s, preferred %s), flags: %s, scope: %s… in log_address_debug()
676 static int address_set_netlink_message(const Address *address, sd_netlink_message *m, Link *link) { in address_set_netlink_message() argument
682 assert(link); in address_set_netlink_message()
710 static int address_remove_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) { in address_remove_handler() argument
714 assert(link); in address_remove_handler()
716 if (IN_SET(link->state, LINK_STATE_FAILED, LINK_STATE_LINGER)) in address_remove_handler()
721 log_link_message_warning_errno(link, m, r, "Could not drop address"); in address_remove_handler()
728 Link *link; in address_remove() local
733 assert(address->link); in address_remove()
734 assert(address->link->ifindex > 0); in address_remove()
735 assert(address->link->manager); in address_remove()
736 assert(address->link->manager->rtnl); in address_remove()
738 link = address->link; in address_remove()
740 log_address_debug(address, "Removing", link); in address_remove()
742 r = sd_rtnl_message_new_addr(link->manager->rtnl, &m, RTM_DELADDR, in address_remove()
743 link->ifindex, address->family); in address_remove()
745 … return log_link_warning_errno(link, r, "Could not allocate RTM_DELADDR message: %m"); in address_remove()
747 r = address_set_netlink_message(address, m, link); in address_remove()
749 return log_link_warning_errno(link, r, "Could not set netlink attributes: %m"); in address_remove()
751 r = netlink_call_async(link->manager->rtnl, NULL, m, in address_remove()
753 link_netlink_destroy_callback, link); in address_remove()
755 return log_link_warning_errno(link, r, "Could not send rtnetlink message: %m"); in address_remove()
757 link_ref(link); in address_remove()
763 link_update_operstate(link, true); in address_remove()
767 bool link_address_is_dynamic(const Link *link, const Address *address) { in link_address_is_dynamic() argument
770 assert(link); in link_address_is_dynamic()
779 SET_FOREACH(route, link->routes) { in link_address_is_dynamic()
800 int link_drop_ipv6ll_addresses(Link *link) { in link_drop_ipv6ll_addresses() argument
804 assert(link); in link_drop_ipv6ll_addresses()
805 assert(link->manager); in link_drop_ipv6ll_addresses()
806 assert(link->manager->rtnl); in link_drop_ipv6ll_addresses()
811 if (link_may_have_ipv6ll(link)) in link_drop_ipv6ll_addresses()
814 … r = sd_rtnl_message_new_addr(link->manager->rtnl, &req, RTM_GETADDR, link->ifindex, AF_INET6); in link_drop_ipv6ll_addresses()
822 r = sd_netlink_call(link->manager->rtnl, req, 0, &reply); in link_drop_ipv6ll_addresses()
837 …log_link_debug_errno(link, r, "rtnl: received address message without valid ifindex, ignoring: %m"… in link_drop_ipv6ll_addresses()
839 } else if (link->ifindex != ifindex) in link_drop_ipv6ll_addresses()
844 … log_link_debug_errno(link, r, "rtnl: received address message without valid flags, ignoring: %m"); in link_drop_ipv6ll_addresses()
850 … log_link_debug_errno(link, r, "rtnl: received address message without prefixlen, ignoring: %m"); in link_drop_ipv6ll_addresses()
860 …log_link_debug_errno(link, r, "rtnl: received address message without valid address, ignoring: %m"… in link_drop_ipv6ll_addresses()
876 if (address_get(link, a, &existing) < 0) { in link_drop_ipv6ll_addresses()
877 r = address_add(link, a); in link_drop_ipv6ll_addresses()
892 int link_drop_foreign_addresses(Link *link) { in link_drop_foreign_addresses() argument
896 assert(link); in link_drop_foreign_addresses()
897 assert(link->network); in link_drop_foreign_addresses()
900 SET_FOREACH(address, link->addresses) { in link_drop_foreign_addresses()
906 …if (link->flags & IFF_LOOPBACK && in_addr_is_localhost_one(address->family, &address->in_addr) > 0) in link_drop_foreign_addresses()
918 …if (IN_SET(link->network->keep_configuration, KEEP_CONFIGURATION_DHCP, KEEP_CONFIGURATION_STATIC) … in link_drop_foreign_addresses()
919 …link_address_is_dynamic(link, address) == (link->network->keep_configuration == KEEP_CONFIGURATION… in link_drop_foreign_addresses()
926 ORDERED_HASHMAP_FOREACH(address, link->network->addresses_by_section) { in link_drop_foreign_addresses()
929 if (address_get(link, address, &existing) >= 0) in link_drop_foreign_addresses()
934 SET_FOREACH(address, link->addresses) { in link_drop_foreign_addresses()
946 int link_drop_managed_addresses(Link *link) { in link_drop_managed_addresses() argument
950 assert(link); in link_drop_managed_addresses()
952 SET_FOREACH(address, link->addresses) { in link_drop_managed_addresses()
971 void link_foreignize_addresses(Link *link) { in link_foreignize_addresses() argument
974 assert(link); in link_foreignize_addresses()
976 SET_FOREACH(address, link->addresses) in link_foreignize_addresses()
980 static int address_acquire(Link *link, const Address *original, Address **ret) { in address_acquire() argument
985 assert(link); in address_acquire()
997 r = address_pool_acquire(link->manager, original->family, original->prefixlen, &in_addr); in address_acquire()
1019 int address_configure_handler_internal(sd_netlink *rtnl, sd_netlink_message *m, Link *link, const c… in address_configure_handler_internal() argument
1024 assert(link); in address_configure_handler_internal()
1029 log_link_message_warning_errno(link, m, r, error_msg); in address_configure_handler_internal()
1030 link_enter_failed(link); in address_configure_handler_internal()
1037 static int address_configure(const Address *address, Link *link, Request *req) { in address_configure() argument
1043 assert(link); in address_configure()
1044 assert(link->ifindex > 0); in address_configure()
1045 assert(link->manager); in address_configure()
1046 assert(link->manager->rtnl); in address_configure()
1049 log_address_debug(address, "Configuring", link); in address_configure()
1051 … r = sd_rtnl_message_new_addr_update(link->manager->rtnl, &m, link->ifindex, address->family); in address_configure()
1055 r = address_set_netlink_message(address, m, link); in address_configure()
1088 return request_call_netlink_async(link->manager->rtnl, m, req); in address_configure()
1091 static bool address_is_ready_to_configure(Link *link, const Address *address) { in address_is_ready_to_configure() argument
1092 assert(link); in address_is_ready_to_configure()
1095 if (!link_is_ready_to_configure(link, false)) in address_is_ready_to_configure()
1102 if (set_size(link->addresses) >= ADDRESSES_PER_LINK_MAX) in address_is_ready_to_configure()
1108 static int address_process_request(Request *req, Link *link, Address *address) { in address_process_request() argument
1112 assert(link); in address_process_request()
1115 if (!address_is_ready_to_configure(link, address)) in address_process_request()
1118 r = address_configure(address, link, req); in address_process_request()
1120 return log_link_warning_errno(link, r, "Failed to configure address: %m"); in address_process_request()
1127 Link *link, in link_request_address() argument
1137 assert(link); in link_request_address()
1141 r = address_acquire(link, address, &acquired); in link_request_address()
1143 … return log_link_warning_errno(link, r, "Failed to acquire an address from pool: %m"); in link_request_address()
1152 if (address_needs_to_set_broadcast(address, link)) { in link_request_address()
1164 address_set_broadcast(address, link); in link_request_address()
1167 if (address_get(link, address, &existing) < 0) { in link_request_address()
1181 r = address_add(link, tmp); in link_request_address()
1199 log_address_debug(existing, "Requesting", link); in link_request_address()
1200 r = link_queue_request_safe(link, REQUEST_TYPE_ADDRESS, in link_request_address()
1207 return log_link_warning_errno(link, r, "Failed to request address: %m"); in link_request_address()
1216 static int static_address_handler(sd_netlink *rtnl, sd_netlink_message *m, Request *req, Link *link in static_address_handler() argument
1219 assert(link); in static_address_handler()
1221 r = address_configure_handler_internal(rtnl, m, link, "Failed to set static address"); in static_address_handler()
1225 if (link->static_address_messages == 0) { in static_address_handler()
1226 log_link_debug(link, "Addresses set"); in static_address_handler()
1227 link->static_addresses_configured = true; in static_address_handler()
1228 link_check_ready(link); in static_address_handler()
1234 int link_request_static_address(Link *link, Address *address, bool consume) { in link_request_static_address() argument
1235 assert(link); in link_request_static_address()
1239 return link_request_address(link, address, consume, &link->static_address_messages, in link_request_static_address()
1243 int link_request_static_addresses(Link *link) { in link_request_static_addresses() argument
1247 assert(link); in link_request_static_addresses()
1248 assert(link->network); in link_request_static_addresses()
1250 link->static_addresses_configured = false; in link_request_static_addresses()
1252 ORDERED_HASHMAP_FOREACH(a, link->network->addresses_by_section) { in link_request_static_addresses()
1253 r = link_request_static_address(link, a, false); in link_request_static_addresses()
1258 r = link_request_radv_addresses(link); in link_request_static_addresses()
1262 r = link_request_dhcp_server_address(link); in link_request_static_addresses()
1266 if (link->static_address_messages == 0) { in link_request_static_addresses()
1267 link->static_addresses_configured = true; in link_request_static_addresses()
1268 link_check_ready(link); in link_request_static_addresses()
1270 log_link_debug(link, "Setting addresses"); in link_request_static_addresses()
1271 link_set_state(link, LINK_STATE_CONFIGURING); in link_request_static_addresses()
1281 assert(address->link); in address_cancel_request()
1287 .link = address->link, in address_cancel_request()
1294 request_detach(address->link->manager, &req); in address_cancel_request()
1301 Link *link = NULL; in manager_rtnl_process_address() local
1336 r = link_get_by_index(m, ifindex, &link); in manager_rtnl_process_address()
1337 if (r < 0 || !link) { in manager_rtnl_process_address()
1351 log_link_warning(link, "rtnl: received address message without family, ignoring."); in manager_rtnl_process_address()
1354 …log_link_debug(link, "rtnl: received address message with invalid family '%i', ignoring.", tmp->fa… in manager_rtnl_process_address()
1360 … log_link_warning_errno(link, r, "rtnl: received address message without prefixlen, ignoring: %m"); in manager_rtnl_process_address()
1366 … log_link_warning_errno(link, r, "rtnl: received address message without scope, ignoring: %m"); in manager_rtnl_process_address()
1380 … log_link_warning_errno(link, r, "rtnl: received address message without flags, ignoring: %m"); in manager_rtnl_process_address()
1388 …log_link_warning_errno(link, r, "rtnl: received address message without valid address, ignoring: %… in manager_rtnl_process_address()
1394 …log_link_warning_errno(link, r, "rtnl: could not get peer address from address message, ignoring: … in manager_rtnl_process_address()
1403 …log_link_warning_errno(link, r, "rtnl: could not get broadcast from address message, ignoring: %m"… in manager_rtnl_process_address()
1409 … log_link_warning_errno(link, r, "rtnl: could not get label from address message, ignoring: %m"); in manager_rtnl_process_address()
1411 } else if (r >= 0 && streq_ptr(tmp->label, link->ifname)) in manager_rtnl_process_address()
1422 …log_link_warning_errno(link, r, "rtnl: could not get peer address from address message, ignoring: … in manager_rtnl_process_address()
1429 …log_link_warning_errno(link, r, "rtnl: received address message without valid address, ignoring: %… in manager_rtnl_process_address()
1433 …log_link_warning_errno(link, r, "rtnl: could not get local address from address message, ignoring:… in manager_rtnl_process_address()
1445 … log_link_warning_errno(link, r, "rtnl: cannot get IFA_CACHEINFO attribute, ignoring: %m"); in manager_rtnl_process_address()
1449 (void) address_get(link, tmp, &address); in manager_rtnl_process_address()
1459 log_address_debug(address, "Received updated", link); in manager_rtnl_process_address()
1463 log_address_debug(tmp, "Received new", link); in manager_rtnl_process_address()
1465 r = address_add(link, tmp); in manager_rtnl_process_address()
1470 … log_link_warning_errno(link, r, "Failed to remember foreign address %s, ignoring: %m", in manager_rtnl_process_address()
1481 link_enter_failed(link); in manager_rtnl_process_address()
1488 … log_address_debug(address, address->state == 0 ? "Forgetting" : "Removed", link); in manager_rtnl_process_address()
1491 log_address_debug(tmp, "Kernel removed unknown", link); in manager_rtnl_process_address()