summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTom Gundersen <teg@jklm.no>2013-11-24 23:36:58 +0100
committerTom Gundersen <teg@jklm.no>2013-11-26 01:32:25 +0100
commitc166a070553511e402de5ad216d3fb62b49bdacb (patch)
tree9aedfe31b512a6f72b4ac27124d7c8e21ed6219e /src
parent46fabae6b33386277f5ee394cf0d5382376586da (diff)
networkd: minor fixes
In particular, store the ifname, though we should only use it carefully, as it is not guaranteed to be stable. Using it for logging is fine though.
Diffstat (limited to 'src')
-rw-r--r--src/network/networkd-address.c7
-rw-r--r--src/network/networkd-link.c50
-rw-r--r--src/network/networkd-route.c2
-rw-r--r--src/network/networkd.h1
4 files changed, 33 insertions, 27 deletions
diff --git a/src/network/networkd-address.c b/src/network/networkd-address.c
index 9cfc0955d3..0555d317a4 100644
--- a/src/network/networkd-address.c
+++ b/src/network/networkd-address.c
@@ -79,7 +79,12 @@ int address_configure(Address *address, Link *link,
_cleanup_sd_rtnl_message_unref_ sd_rtnl_message *req = NULL;
int r;
+ assert(address);
+ assert(address->family == AF_INET || address->family == AF_INET6);
+ assert(link);
+ assert(link->ifindex > 0);
assert(link->manager);
+ assert(link->manager->rtnl);
r = sd_rtnl_message_addr_new(RTM_NEWADDR, link->ifindex,
address->family, address->prefixlen,
@@ -125,8 +130,6 @@ int address_configure(Address *address, Link *link,
return r;
}
- link->rtnl_messages ++;
-
return 0;
}
diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c
index ab5da3612e..255b413586 100644
--- a/src/network/networkd-link.c
+++ b/src/network/networkd-link.c
@@ -30,6 +30,7 @@ int link_new(Manager *manager, struct udev_device *device, Link **ret) {
_cleanup_link_free_ Link *link = NULL;
const char *mac;
struct ether_addr *mac_addr;
+ const char *ifname;
int r;
assert(device);
@@ -53,6 +54,9 @@ int link_new(Manager *manager, struct udev_device *device, Link **ret) {
memcpy(&link->mac, mac_addr, sizeof(struct ether_addr));
}
+ ifname = udev_device_get_sysname(device);
+ link->ifname = strdup(ifname);
+
r = hashmap_put(manager->links, &link->ifindex, link);
if (r < 0)
return r;
@@ -71,6 +75,8 @@ void link_free(Link *link) {
hashmap_remove(link->manager->links, &link->ifindex);
+ free(link->ifname);
+
free(link);
}
@@ -90,7 +96,7 @@ int link_add(Manager *m, struct udev_device *device) {
r = link_new(m, device, &link);
if (r < 0) {
- log_error("could not create link: %s", strerror(-r));
+ log_error("Could not create link: %s", strerror(-r));
return r;
}
@@ -106,7 +112,7 @@ int link_add(Manager *m, struct udev_device *device) {
}
static int link_enter_configured(Link *link) {
- log_info("Link configured successfully.");
+ log_info("Link '%s' configured", link->ifname);
link->state = LINK_STATE_CONFIGURED;
@@ -114,7 +120,7 @@ static int link_enter_configured(Link *link) {
}
static int link_enter_failed(Link *link) {
- log_warning("Could not configure link.");
+ log_warning("Could not configure link '%s'", link->ifname);
link->state = LINK_STATE_FAILED;
@@ -126,7 +132,7 @@ static bool link_is_up(Link *link) {
}
static int link_enter_routes_set(Link *link) {
- log_info("Routes set for link %ju", link->ifindex);
+ log_info("Routes set for link '%s'", link->ifname);
if (link_is_up(link))
return link_enter_configured(link);
@@ -149,11 +155,9 @@ static int route_handler(sd_rtnl *rtnl, sd_rtnl_message *m, void *userdata) {
return 1;
r = sd_rtnl_message_get_errno(m);
- if (r < 0 && r != -EEXIST) {
- log_warning("Could not set route on interface %ju: %s",
- link->ifindex, strerror(-r));
- return link_enter_failed(link);
- }
+ if (r < 0 && r != -EEXIST)
+ log_warning("Could not set route on interface '%s': %s",
+ link->ifname, strerror(-r));
if (link->rtnl_messages == 0)
return link_enter_routes_set(link);
@@ -178,14 +182,16 @@ static int link_enter_set_routes(Link *link) {
LIST_FOREACH(routes, route, link->network->routes) {
r = route_configure(route, link, &route_handler);
if (r < 0)
- link_enter_failed(link);
+ return link_enter_failed(link);
+
+ link->rtnl_messages ++;
}
return 0;
}
static int link_enter_addresses_set(Link *link) {
- log_info("Addresses set for link %ju", link->ifindex);
+ log_info("Addresses set for link '%s'", link->ifname);
link->state = LINK_STATE_ADDRESSES_SET;
@@ -205,11 +211,9 @@ static int address_handler(sd_rtnl *rtnl, sd_rtnl_message *m, void *userdata) {
return 1;
r = sd_rtnl_message_get_errno(m);
- if (r < 0 && r != -EEXIST) {
- log_warning("Could not set address on interface %ju: %s",
- link->ifindex, strerror(-r));
- link_enter_failed(link);
- }
+ if (r < 0 && r != -EEXIST)
+ log_warning("Could not set address on interface '%s': %s",
+ link->ifname, strerror(-r));
if (link->rtnl_messages == 0)
link_enter_addresses_set(link);
@@ -233,7 +237,9 @@ static int link_enter_set_addresses(Link *link) {
LIST_FOREACH(addresses, address, link->network->addresses) {
r = address_configure(address, link, &address_handler);
if (r < 0)
- link_enter_failed(link);
+ return link_enter_failed(link);
+
+ link->rtnl_messages ++;
}
return 0;
@@ -244,15 +250,13 @@ static int link_handler(sd_rtnl *rtnl, sd_rtnl_message *m, void *userdata) {
int r;
r = sd_rtnl_message_get_errno(m);
- if (r < 0) {
- log_warning("Could not bring up interface %ju: %s",
- link->ifindex, strerror(-r));
- return link_enter_failed(link);
- }
+ if (r < 0)
+ log_warning("Could not bring up interface '%s': %s",
+ link->ifname, strerror(-r));
link->flags |= IFF_UP;
- log_info("Link is UP.");
+ log_info("Link '%s' is up", link->ifname);
if (link->state == LINK_STATE_ROUTES_SET)
return link_enter_configured(link);
diff --git a/src/network/networkd-route.c b/src/network/networkd-route.c
index b88c622614..1166a99a79 100644
--- a/src/network/networkd-route.c
+++ b/src/network/networkd-route.c
@@ -118,8 +118,6 @@ int route_configure(Route *route, Link *link,
return r;
}
- link->rtnl_messages ++;
-
return 0;
}
diff --git a/src/network/networkd.h b/src/network/networkd.h
index 04a56ea8c8..913f17d3a0 100644
--- a/src/network/networkd.h
+++ b/src/network/networkd.h
@@ -113,6 +113,7 @@ struct Link {
Manager *manager;
uint64_t ifindex;
+ char *ifname;
struct ether_addr mac;
unsigned flags;