#include "bus-util.h"
#include "network-internal.h"
+#include "network-util.h"
#include "dhcp-lease-internal.h"
static int ipv4ll_address_update(Link *link, bool deprecate);
struct in_addr gateway;
r = sd_dhcp_lease_get_router(link->dhcp_lease, &gateway);
- if (r < 0) {
- log_warning_link(link, "DHCP error: no router: %s",
- strerror(-r));
+ if (r < 0 && r != -ENOENT) {
+ log_warning_link(link, "DHCP error: %s", strerror(-r));
return r;
}
- r = route_new_dynamic(&route);
- if (r < 0) {
- log_error_link(link, "Could not allocate route: %s",
- strerror(-r));
- return r;
- }
+ if (r >= 0) {
+ r = route_new_dynamic(&route);
+ if (r < 0) {
+ log_error_link(link, "Could not allocate route: %s",
+ strerror(-r));
+ return r;
+ }
- r = route_new_dynamic(&route_gw);
- if (r < 0) {
- log_error_link(link, "Could not allocate route: %s",
- strerror(-r));
- return r;
- }
+ r = route_new_dynamic(&route_gw);
+ if (r < 0) {
+ log_error_link(link, "Could not allocate route: %s",
+ strerror(-r));
+ return r;
+ }
- /* The dhcp netmask may mask out the gateway. Add an explicit
- * route for the gw host so that we can route no matter the
- * netmask or existing kernel route tables. */
- route_gw->family = AF_INET;
- route_gw->dst_addr.in = gateway;
- route_gw->dst_prefixlen = 32;
- route_gw->scope = RT_SCOPE_LINK;
+ /* The dhcp netmask may mask out the gateway. Add an explicit
+ * route for the gw host so that we can route no matter the
+ * netmask or existing kernel route tables. */
+ route_gw->family = AF_INET;
+ route_gw->dst_addr.in = gateway;
+ route_gw->dst_prefixlen = 32;
+ route_gw->scope = RT_SCOPE_LINK;
- r = route_configure(route_gw, link, &route_handler);
- if (r < 0) {
- log_warning_link(link,
- "could not set host route: %s", strerror(-r));
- return r;
- }
+ r = route_configure(route_gw, link, &route_handler);
+ if (r < 0) {
+ log_warning_link(link,
+ "could not set host route: %s", strerror(-r));
+ return r;
+ }
- link->route_messages ++;
+ link->route_messages ++;
- route->family = AF_INET;
- route->in_addr.in = gateway;
+ route->family = AF_INET;
+ route->in_addr.in = gateway;
- r = route_configure(route, link, &route_handler);
- if (r < 0) {
- log_warning_link(link,
- "could not set routes: %s", strerror(-r));
- link_enter_failed(link);
- return r;
+ r = route_configure(route, link, &route_handler);
+ if (r < 0) {
+ log_warning_link(link,
+ "could not set routes: %s", strerror(-r));
+ link_enter_failed(link);
+ return r;
+ }
+
+ link->route_messages ++;
}
+ }
- link->route_messages ++;
+ if (link->route_messages == 0) {
+ link_enter_configured(link);
}
return 0;
r = address_new_dynamic(&address);
if (r >= 0) {
- sd_dhcp_lease_get_address(link->dhcp_lease, &addr);
- sd_dhcp_lease_get_netmask(link->dhcp_lease, &netmask);
- sd_dhcp_lease_get_router(link->dhcp_lease, &gateway);
- prefixlen = net_netmask_to_prefixlen(&netmask);
-
- r = route_new_dynamic(&route_gw);
+ r = sd_dhcp_lease_get_router(link->dhcp_lease, &gateway);
if (r >= 0) {
- route_gw->family = AF_INET;
- route_gw->dst_addr.in = gateway;
- route_gw->dst_prefixlen = 32;
- route_gw->scope = RT_SCOPE_LINK;
+ r = route_new_dynamic(&route_gw);
+ if (r >= 0) {
+ route_gw->family = AF_INET;
+ route_gw->dst_addr.in = gateway;
+ route_gw->dst_prefixlen = 32;
+ route_gw->scope = RT_SCOPE_LINK;
- route_drop(route_gw, link, &route_drop_handler);
- }
+ route_drop(route_gw, link, &route_drop_handler);
+ }
- r = route_new_dynamic(&route);
- if (r >= 0) {
- route->family = AF_INET;
- route->in_addr.in = gateway;
+ r = route_new_dynamic(&route);
+ if (r >= 0) {
+ route->family = AF_INET;
+ route->in_addr.in = gateway;
- route_drop(route, link, &route_drop_handler);
+ route_drop(route, link, &route_drop_handler);
+ }
}
+ sd_dhcp_lease_get_address(link->dhcp_lease, &addr);
+ sd_dhcp_lease_get_netmask(link->dhcp_lease, &netmask);
+ prefixlen = net_netmask_to_prefixlen(&netmask);
+
address->family = AF_INET;
address->in_addr.in = addr;
address->prefixlen = prefixlen;
prefixlen = net_netmask_to_prefixlen(&netmask);
r = sd_dhcp_lease_get_router(lease, &gateway);
- if (r < 0) {
- log_warning_link(link, "DHCP error: no router: %s",
- strerror(-r));
+ if (r < 0 && r != -ENOENT) {
+ log_warning_link(link, "DHCP error: %s", strerror(-r));
return r;
}
- log_struct_link(LOG_INFO, link,
- "MESSAGE=%s: DHCPv4 address %u.%u.%u.%u/%u via %u.%u.%u.%u",
- link->ifname,
- ADDRESS_FMT_VAL(address),
- prefixlen,
- ADDRESS_FMT_VAL(gateway),
- "ADDRESS=%u.%u.%u.%u",
- ADDRESS_FMT_VAL(address),
- "PREFIXLEN=%u",
- prefixlen,
- "GATEWAY=%u.%u.%u.%u",
- ADDRESS_FMT_VAL(gateway),
- NULL);
+ if (r >= 0)
+ log_struct_link(LOG_INFO, link,
+ "MESSAGE=%s: DHCPv4 address %u.%u.%u.%u/%u via %u.%u.%u.%u",
+ link->ifname,
+ ADDRESS_FMT_VAL(address),
+ prefixlen,
+ ADDRESS_FMT_VAL(gateway),
+ "ADDRESS=%u.%u.%u.%u",
+ ADDRESS_FMT_VAL(address),
+ "PREFIXLEN=%u",
+ prefixlen,
+ "GATEWAY=%u.%u.%u.%u",
+ ADDRESS_FMT_VAL(gateway),
+ NULL);
+ else
+ log_struct_link(LOG_INFO, link,
+ "MESSAGE=%s: DHCPv4 address %u.%u.%u.%u/%u",
+ link->ifname,
+ ADDRESS_FMT_VAL(address),
+ prefixlen,
+ "ADDRESS=%u.%u.%u.%u",
+ ADDRESS_FMT_VAL(address),
+ "PREFIXLEN=%u",
+ prefixlen,
+ NULL);
link->dhcp_lease = lease;
return 0;
}
-static bool link_has_carrier(unsigned flags, uint8_t operstate) {
- /* see Documentation/networking/operstates.txt in the kernel sources */
-
- if (operstate == IF_OPER_UP)
- return true;
-
- if (operstate == IF_OPER_UNKNOWN)
- /* operstate may not be implemented, so fall back to flags */
- if ((flags & IFF_LOWER_UP) && !(flags & IFF_DORMANT))
- return true;
-
- return false;
-}
-
static int link_update_flags(Link *link, sd_rtnl_message *m) {
unsigned flags, flags_added, flags_removed, generic_flags;
uint8_t operstate;
flags_removed = (link->flags ^ flags) & link->flags;
generic_flags = ~(IFF_UP | IFF_LOWER_UP | IFF_DORMANT | IFF_DEBUG |
IFF_MULTICAST | IFF_BROADCAST | IFF_PROMISC |
- IFF_NOARP | IFF_MASTER | IFF_SLAVE);
+ IFF_NOARP | IFF_MASTER | IFF_SLAVE | IFF_RUNNING);
if (flags_added & IFF_UP)
log_debug_link(link, "link is up");
r = sd_rtnl_message_get_errno(m);
if (r < 0) {
+ /* we warn but don't fail the link, as it may
+ be brought up later */
log_struct_link(LOG_WARNING, link,
"MESSAGE=%s: could not bring up interface: %s",
link->ifname, strerror(-r),
"ERRNO=%d", -r,
NULL);
- link_enter_failed(link);
}
return 1;
}
if (link_has_carrier(link->flags, link->operstate))
+ {
r = link_acquire_conf(link);
if (r < 0)
return r;
+ }
return link_enter_enslave(link);
}