r = sd_rtnl_message_get_errno(m);
if (r < 0 && r != -EEXIST)
- log_link_struct(LOG_WARNING, link,
- "MESSAGE=%-*s: could not set route: %s",
- IFNAMSIZ,
- link->ifname, strerror(-r),
- "ERRNO=%d", -r,
- NULL);
+ log_link_warning_errno(link, -r, "%-*s: could not set route: %m", IFNAMSIZ, link->ifname);
if (link->link_messages == 0) {
log_link_debug(link, "routes set");
r = sd_rtnl_message_get_errno(m);
if (r < 0 && r != -ESRCH)
- log_link_struct(LOG_WARNING, link,
- "MESSAGE=%-*s: could not drop route: %s",
- IFNAMSIZ,
- link->ifname, strerror(-r),
- "ERRNO=%d", -r,
- NULL);
+ log_link_warning_errno(link, -r, "%-*s: could not drop route: %m", IFNAMSIZ, link->ifname);
return 1;
}
r = sd_rtnl_message_get_errno(m);
if (r < 0 && r != -EEXIST)
- log_link_struct(LOG_WARNING, link,
- "MESSAGE=%-*s: could not set address: %s",
- IFNAMSIZ,
- link->ifname, strerror(-r),
- "ERRNO=%d", -r,
- NULL);
+ log_link_warning_errno(link, -r, "%-*s: could not set address: %m", IFNAMSIZ, link->ifname);
else if (r >= 0) {
/* calling handler directly so take a ref */
link_ref(link);
r = sd_rtnl_message_get_errno(m);
if (r < 0 && r != -EADDRNOTAVAIL)
- log_link_struct(LOG_WARNING, link,
- "MESSAGE=%-*s: could not drop address: %s",
+ log_link_warning_errno(link, -r, "%-*s: could not drop address: %m", IFNAMSIZ, link->ifname);
+
+ return 1;
+}
+
+static int link_set_handler(sd_rtnl *rtnl, sd_rtnl_message *m, void *userdata) {
+ _cleanup_link_unref_ Link *link = userdata;
+ int r;
+
+ log_link_debug(link, "set link");
+
+ r = sd_rtnl_message_get_errno(m);
+ if (r < 0 && r != -EEXIST) {
+ log_link_struct(link, LOG_ERR,
+ "MESSAGE=%-*s: could not join netdev: %s",
IFNAMSIZ,
link->ifname, strerror(-r),
"ERRNO=%d", -r,
NULL);
+ link_enter_failed(link);
+ return 1;
+ }
- return 1;
+ return 0;
}
static int set_hostname_handler(sd_bus *bus, sd_bus_message *m, void *userdata,
r = sd_rtnl_message_get_errno(m);
if (r < 0)
- log_link_struct(LOG_WARNING, link,
- "MESSAGE=%-*s: could not set MTU: %s",
- IFNAMSIZ, link->ifname, strerror(-r),
- "ERRNO=%d", -r,
- NULL);
+ log_link_warning_errno(link, -r, "%-*s: could not set MTU: %m", IFNAMSIZ, link->ifname);
return 1;
}
return 0;
}
+static int link_set_bridge(Link *link) {
+ _cleanup_rtnl_message_unref_ sd_rtnl_message *req = NULL;
+ int r;
+
+ assert(link);
+ assert(link->network);
+
+ if(link->network->cost == 0)
+ return 0;
+
+ r = sd_rtnl_message_new_link(link->manager->rtnl, &req,
+ RTM_SETLINK, link->ifindex);
+ if (r < 0) {
+ log_link_error(link, "Could not allocate RTM_SETLINK message");
+ return r;
+ }
+
+ r = sd_rtnl_message_link_set_family(req, PF_BRIDGE);
+ if (r < 0) {
+ log_link_error(link,
+ "Could not set message family %s", strerror(-r));
+ return r;
+ }
+
+ r = sd_rtnl_message_open_container(req, IFLA_PROTINFO);
+ if (r < 0) {
+ log_link_error(link,
+ "Could not append IFLA_PROTINFO attribute: %s",
+ strerror(-r));
+ return r;
+ }
+
+ if(link->network->cost != 0) {
+ r = sd_rtnl_message_append_u32(req, IFLA_BRPORT_COST, link->network->cost);
+ if (r < 0) {
+ log_link_error(link,
+ "Could not append IFLA_BRPORT_COST attribute: %s",
+ strerror(-r));
+ return r;
+ }
+ }
+
+ r = sd_rtnl_message_close_container(req);
+ if (r < 0) {
+ log_link_error(link,
+ "Could not append IFLA_LINKINFO attribute: %s",
+ strerror(-r));
+ return r;
+ }
+
+ r = sd_rtnl_call_async(link->manager->rtnl, req, link_set_handler, link, 0, NULL);
+ if (r < 0) {
+ log_link_error(link,
+ "Could not send rtnetlink message: %s",
+ strerror(-r));
+ return r;
+ }
+
+ link_ref(link);
+
+ return r;
+}
+
static void dhcp6_handler(sd_dhcp6_client *client, int event, void *userdata) {
Link *link = userdata;
if (r < 0) {
/* we warn but don't fail the link, as it may
be brought up later */
- log_link_struct(LOG_WARNING, link,
- "MESSAGE=%-*s: could not bring up interface: %s",
- IFNAMSIZ,
- link->ifname, strerror(-r),
- "ERRNO=%d", -r,
- NULL);
+ log_link_warning_errno(link, -r, "%-*s: could not bring up interface: %m", IFNAMSIZ, link->ifname);
}
return 1;
int r;
assert(link);
+ assert(link->network);
assert(link->manager);
assert(link->manager->rtnl);
return r;
}
+ if (link->network->mac) {
+ r = sd_rtnl_message_append_ether_addr(req, IFLA_ADDRESS, link->network->mac);
+ if (r < 0) {
+ log_link_error(link, "Could not set MAC address: %s", strerror(-r));
+ return r;
+ }
+ }
+
+ if (link->network->mtu) {
+ r = sd_rtnl_message_append_u32(req, IFLA_MTU, link->network->mtu);
+ if (r < 0) {
+ log_link_error(link, "Could not set MTU: %s", strerror(-r));
+ return r;
+ }
+ }
+
r = sd_rtnl_call_async(link->manager->rtnl, req, link_up_handler, link,
0, NULL);
if (r < 0) {
}
}
+ if(link->network->bridge) {
+ r = link_set_bridge(link);
+ if (r < 0) {
+ log_link_error(link,
+ "Could not set bridge message: %s",
+ strerror(-r));
+ }
+ }
+
return link_enter_set_addresses(link);
}
r = sd_rtnl_message_get_errno(m);
if (r < 0 && r != -EEXIST) {
- log_link_struct(LOG_ERR, link,
- "MESSAGE=%-*s: could not join netdev: %s",
- IFNAMSIZ,
- link->ifname, strerror(-r),
- "ERRNO=%d", -r,
- NULL);
+ log_link_error_errno(link, -r, "%-*s: could not join netdev: %m", IFNAMSIZ, link->ifname);
link_enter_failed(link);
return 1;
} else
return link_joined(link);
if (link->network->bond) {
- log_link_struct(LOG_DEBUG, link,
+ log_link_struct(link, LOG_DEBUG,
"MESSAGE=%-*s: enslaving by '%s'",
IFNAMSIZ,
link->ifname, link->network->bond->ifname,
r = netdev_join(link->network->bond, link, &netdev_join_handler);
if (r < 0) {
- log_link_struct(LOG_WARNING, link,
+ log_link_struct(link, LOG_WARNING,
"MESSAGE=%-*s: could not join netdev '%s': %s",
IFNAMSIZ,
link->ifname, link->network->bond->ifname,
}
if (link->network->bridge) {
- log_link_struct(LOG_DEBUG, link,
+ log_link_struct(link, LOG_DEBUG,
"MESSAGE=%-*s: enslaving by '%s'",
IFNAMSIZ,
link->ifname, link->network->bridge->ifname,
r = netdev_join(link->network->bridge, link,
&netdev_join_handler);
if (r < 0) {
- log_link_struct(LOG_WARNING, link,
+ log_link_struct(link, LOG_WARNING,
"MESSAGE=%-*s: could not join netdev '%s': %s",
IFNAMSIZ,
link->ifname, link->network->bridge->ifname,
}
HASHMAP_FOREACH(netdev, link->network->stacked_netdevs, i) {
- log_link_struct(LOG_DEBUG, link,
+ log_link_struct(link, LOG_DEBUG,
"MESSAGE=%-*s: enslaving by '%s'",
IFNAMSIZ,
link->ifname, netdev->ifname, NETDEVIF(netdev),
r = netdev_join(netdev, link, &netdev_join_handler);
if (r < 0) {
- log_link_struct(LOG_WARNING, link,
+ log_link_struct(link, LOG_WARNING,
"MESSAGE=%-*s: could not join netdev '%s': %s",
IFNAMSIZ,
link->ifname, netdev->ifname,