#include <netinet/ether.h>
#include <linux/if.h>
+#include <unistd.h>
#include "networkd.h"
#include "libudev-private.h"
return r;
}
- link_ref(link);
link->route_messages ++;
}
return r;
}
- link_ref(link);
link->route_messages ++;
}
return r;
}
- link_ref(link);
link->route_messages ++;
}
}
return r;
}
- link_ref(link);
link->route_messages ++;
route->family = AF_INET;
return r;
}
- link_ref(link);
link->route_messages ++;
}
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);
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");
return r;
}
- link_ref(link);
link->addr_messages ++;
}
return r;
}
- link_ref(link);
link->addr_messages ++;
}
}
return r;
}
- link_ref(link);
link->addr_messages ++;
}
route->dst_prefixlen = routes[i].dst_prefixlen;
route_drop(route, link, &route_drop_handler);
- link_ref(link);
}
}
}
route_gw->scope = RT_SCOPE_LINK;
route_drop(route_gw, link, &route_drop_handler);
- link_ref(link);
}
r = route_new_dynamic(&route);
route->in_addr.in = gateway;
route_drop(route, link, &route_drop_handler);
- link_ref(link);
}
}
address->prefixlen = prefixlen;
address_drop(address, link, &address_drop_handler);
- link_ref(link);
}
if (link->network->dhcp_mtu) {
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;
address->scope = RT_SCOPE_LINK;
address_drop(address, link, &address_drop_handler);
- link_ref(link);
r = route_new_dynamic(&route);
if (r < 0) {
route->metrics = 99;
route_drop(route, link, &route_drop_handler);
- link_ref(link);
}
return 0;
assert(link->state == LINK_STATE_ENSLAVING);
assert(link->network);
+ log_debug_link(link, "enslaved");
+
if (!(link->flags & IFF_UP)) {
r = link_up(link);
if (r < 0) {
return 1;
r = sd_rtnl_message_get_errno(m);
- if (r < 0) {
+ if (r < 0 && r != -EEXIST) {
log_struct_link(LOG_ERR, link,
"MESSAGE=%-*s: could not enslave: %s",
IFNAMSIZ,
return 1;
}
- log_debug_link(link, "enslaved");
-
- if (link->enslaving == 0)
+ if (link->enslaving <= 0)
link_enslaved(link);
return 1;
return r;
}
- link_ref(link);
link->enslaving ++;
}
return r;
}
- link_ref(link);
link->enslaving ++;
}
return r;
}
- link_ref(link);
link->enslaving ++;
}
return r;
}
- link_ref(link);
link->enslaving ++;
}
return r;
}
- link_ref(link);
link->enslaving ++;
}
return r;
}
- link_ref(link);
link->enslaving ++;
}
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)
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) {
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)) {
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;
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:
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;