X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fnetwork%2Fnetworkd-link.c;h=6257372ffdcfa38a9f5f1e35daef7821021f5e5b;hb=4958aee4977f325be19f0e1e4b424922c3cada5f;hp=a523a3e9b2d7f47f16785e9ef8b3a46d7d671fd0;hpb=856f962c7a2e13b33f5b1c691efb2780f2c7afc3;p=elogind.git diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c index a523a3e9b..6257372ff 100644 --- a/src/network/networkd-link.c +++ b/src/network/networkd-link.c @@ -21,6 +21,7 @@ #include #include +#include #include "networkd.h" #include "libudev-private.h" @@ -435,7 +436,6 @@ static int link_set_dhcp_routes(Link *link) { return r; } - link_ref(link); link->route_messages ++; } @@ -467,7 +467,6 @@ static int link_enter_set_routes(Link *link) { return r; } - link_ref(link); link->route_messages ++; } @@ -502,7 +501,6 @@ static int link_enter_set_routes(Link *link) { return r; } - link_ref(link); link->route_messages ++; } } @@ -550,7 +548,6 @@ static int link_enter_set_routes(Link *link) { return r; } - link_ref(link); link->route_messages ++; route->family = AF_INET; @@ -565,7 +562,6 @@ static int link_enter_set_routes(Link *link) { return r; } - link_ref(link); link->route_messages ++; } @@ -603,10 +599,35 @@ static int route_drop_handler(sd_rtnl *rtnl, sd_rtnl_message *m, void *userdata) return 0; } +static int link_get_address_handler(sd_rtnl *rtnl, sd_rtnl_message *m, void *userdata) { + _cleanup_link_unref_ Link *link = userdata; + int r; + + assert(rtnl); + assert(m); + assert(link); + assert(link->manager); + + for (; m; m = sd_rtnl_message_next(m)) { + r = sd_rtnl_message_get_errno(m); + if (r < 0) { + log_debug_link(link, "getting address failed: %s", strerror(-r)); + continue; + } + + r = link_rtnl_process_address(rtnl, m, link->manager); + if (r < 0) + log_warning_link(link, "could not process address: %s", strerror(-r)); + } + + return 1; +} + static int address_handler(sd_rtnl *rtnl, sd_rtnl_message *m, void *userdata) { _cleanup_link_unref_ Link *link = userdata; int r; + assert(rtnl); assert(m); assert(link); assert(link->ifname); @@ -627,6 +648,11 @@ static int address_handler(sd_rtnl *rtnl, sd_rtnl_message *m, void *userdata) { link->ifname, strerror(-r), "ERRNO=%d", -r, NULL); + if (r >= 0) { + /* calling handler directly so take a ref */ + link_ref(link); + link_get_address_handler(rtnl, m, link); + } if (link->addr_messages == 0) { log_debug_link(link, "addresses set"); @@ -662,7 +688,6 @@ static int link_enter_set_addresses(Link *link) { return r; } - link_ref(link); link->addr_messages ++; } @@ -698,7 +723,6 @@ static int link_enter_set_addresses(Link *link) { return r; } - link_ref(link); link->addr_messages ++; } } @@ -759,7 +783,6 @@ static int link_enter_set_addresses(Link *link) { return r; } - link_ref(link); link->addr_messages ++; } @@ -956,7 +979,6 @@ static int dhcp_lease_lost(Link *link) { route->dst_prefixlen = routes[i].dst_prefixlen; route_drop(route, link, &route_drop_handler); - link_ref(link); } } } @@ -977,7 +999,6 @@ static int dhcp_lease_lost(Link *link) { route_gw->scope = RT_SCOPE_LINK; route_drop(route_gw, link, &route_drop_handler); - link_ref(link); } r = route_new_dynamic(&route); @@ -986,7 +1007,6 @@ static int dhcp_lease_lost(Link *link) { route->in_addr.in = gateway; route_drop(route, link, &route_drop_handler); - link_ref(link); } } @@ -999,7 +1019,6 @@ static int dhcp_lease_lost(Link *link) { address->prefixlen = prefixlen; address_drop(address, link, &address_drop_handler); - link_ref(link); } if (link->network->dhcp_mtu) { @@ -1266,7 +1285,6 @@ static int ipv4ll_address_update(Link *link, bool deprecate) { address->broadcast.s_addr = address->in_addr.in.s_addr | htonl(0xfffffffflu >> address->prefixlen); address_update(address, link, &address_update_handler); - link_ref(link); } return 0; @@ -1299,7 +1317,6 @@ static int ipv4ll_address_lost(Link *link) { address->scope = RT_SCOPE_LINK; address_drop(address, link, &address_drop_handler); - link_ref(link); r = route_new_dynamic(&route); if (r < 0) { @@ -1313,7 +1330,6 @@ static int ipv4ll_address_lost(Link *link) { route->metrics = 99; route_drop(route, link, &route_drop_handler); - link_ref(link); } return 0; @@ -1809,7 +1825,6 @@ static int link_enter_enslave(Link *link) { return r; } - link_ref(link); link->enslaving ++; } @@ -1833,7 +1848,6 @@ static int link_enter_enslave(Link *link) { return r; } - link_ref(link); link->enslaving ++; } @@ -1857,7 +1871,6 @@ static int link_enter_enslave(Link *link) { return r; } - link_ref(link); link->enslaving ++; } @@ -1878,7 +1891,6 @@ static int link_enter_enslave(Link *link) { return r; } - link_ref(link); link->enslaving ++; } @@ -1899,7 +1911,6 @@ static int link_enter_enslave(Link *link) { return r; } - link_ref(link); link->enslaving ++; } @@ -1920,7 +1931,6 @@ static int link_enter_enslave(Link *link) { return r; } - link_ref(link); link->enslaving ++; } @@ -1992,6 +2002,7 @@ static int link_configure(Link *link) { if (r < 0) return r; } + if (link->network->dhcp_routes) { r = sd_dhcp_client_set_request_option(link->dhcp_client, DHCP_OPTION_STATIC_ROUTE); if (r < 0) @@ -2000,6 +2011,18 @@ static int link_configure(Link *link) { if (r < 0) return r; } + + if (link->network->dhcp_sendhost) { + _cleanup_free_ char *hostname = gethostname_malloc(); + if (!hostname) + return -ENOMEM; + + if (!is_localhost(hostname)) { + r = sd_dhcp_client_set_hostname(link->dhcp_client, hostname); + if (r < 0) + return r; + } + } } if (link->network->dhcp_server) { @@ -2147,7 +2170,7 @@ int link_rtnl_process_address(sd_rtnl *rtnl, sd_rtnl_message *message, void *use r = address_new_dynamic(&address); if (r < 0) - return 0; + return r; r = sd_rtnl_message_addr_get_family(message, &address->family); if (r < 0 || !IN_SET(address->family, AF_INET, AF_INET6)) { @@ -2211,7 +2234,10 @@ int link_rtnl_process_address(sd_rtnl *rtnl, sd_rtnl_message *message, void *use case RTM_NEWADDR: if (!address_dropped) log_debug_link(link, "added address: %s/%u", buf, - address->prefixlen); + address->prefixlen); + else + log_debug_link(link, "updated address: %s/%u", buf, + address->prefixlen); LIST_PREPEND(addresses, link->addresses, address); address = NULL; @@ -2222,10 +2248,12 @@ int link_rtnl_process_address(sd_rtnl *rtnl, sd_rtnl_message *message, void *use case RTM_DELADDR: if (address_dropped) { log_debug_link(link, "removed address: %s/%u", buf, - address->prefixlen); + address->prefixlen); link_save(link); - } + } else + log_warning_link(link, "removing non-existent address: %s/%u", + buf, address->prefixlen); break; default: @@ -2235,30 +2263,6 @@ int link_rtnl_process_address(sd_rtnl *rtnl, sd_rtnl_message *message, void *use return 1; } -static int link_get_address_handler(sd_rtnl *rtnl, sd_rtnl_message *m, void *userdata) { - _cleanup_link_unref_ Link *link = userdata; - int r; - - assert(rtnl); - assert(m); - assert(link); - assert(link->manager); - - for (; m; m = sd_rtnl_message_next(m)) { - r = sd_rtnl_message_get_errno(m); - if (r < 0) { - log_debug_link(link, "getting address failed: %s", strerror(-r)); - continue; - } - - r = link_rtnl_process_address(rtnl, m, link->manager); - if (r < 0) - log_warning_link(link, "could not process address: %s", strerror(-r)); - } - - return 1; -} - int link_add(Manager *m, sd_rtnl_message *message, Link **ret) { Link *link; _cleanup_rtnl_message_unref_ sd_rtnl_message *req = NULL;