[systemd-commits] 3 commits - src/network
Tom Gundersen
tomegun at kemper.freedesktop.org
Tue Dec 17 13:08:35 PST 2013
src/network/networkd-bridge.c | 4
src/network/networkd-link.c | 176 +++++++++++++++++++++++------------------
src/network/networkd-manager.c | 7 -
src/network/networkd.h | 10 --
4 files changed, 110 insertions(+), 87 deletions(-)
New commits:
commit d638dee035bea5ce1082cce6448ad4d8f8cedf55
Author: Tom Gundersen <teg at jklm.no>
Date: Tue Dec 17 19:56:09 2013 +0100
networkd: bridge - fix state machine
We were entering BRIDGE_STATE_CREATED rather than BRIDGE_STATE_READY.
diff --git a/src/network/networkd-bridge.c b/src/network/networkd-bridge.c
index ed0d692..f110b8a 100644
--- a/src/network/networkd-bridge.c
+++ b/src/network/networkd-bridge.c
@@ -139,8 +139,8 @@ static int bridge_create_handler(sd_rtnl *rtnl, sd_rtnl_message *m, void *userda
if (bridge->link)
bridge_enter_ready(bridge);
-
- bridge->state = BRIDGE_STATE_CREATED;
+ else
+ bridge->state = BRIDGE_STATE_CREATED;
return 1;
}
commit ef1ba6065c6ccea94d4ee867f36df7bbc53a5224
Author: Tom Gundersen <teg at jklm.no>
Date: Sat Dec 14 23:39:04 2013 +0530
networkd: link - remove useless states
Rework the state-machine a bit.
diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c
index 447b2a9..cc5441b 100644
--- a/src/network/networkd-link.c
+++ b/src/network/networkd-link.c
@@ -120,6 +120,9 @@ int link_add(Manager *m, struct udev_device *device) {
}
static int link_enter_configured(Link *link) {
+ assert(link);
+ assert(link->state == LINK_STATE_SETTING_ROUTES);
+
log_info("Link '%s' configured", link->ifname);
link->state = LINK_STATE_CONFIGURED;
@@ -127,10 +130,10 @@ static int link_enter_configured(Link *link) {
return 0;
}
-static int link_enter_failed(Link *link) {
- link->state = LINK_STATE_FAILED;
+static void link_enter_failed(Link *link) {
+ assert(link);
- return 0;
+ link->state = LINK_STATE_FAILED;
}
static int route_handler(sd_rtnl *rtnl, sd_rtnl_message *m, void *userdata) {
@@ -138,7 +141,7 @@ static int route_handler(sd_rtnl *rtnl, sd_rtnl_message *m, void *userdata) {
int r;
assert(link->rtnl_messages > 0);
- assert(link->state == LINK_STATE_SET_ROUTES || link->state == LINK_STATE_FAILED);
+ assert(link->state == LINK_STATE_SETTING_ROUTES || link->state == LINK_STATE_FAILED);
link->rtnl_messages --;
@@ -165,9 +168,9 @@ static int link_enter_set_routes(Link *link) {
assert(link);
assert(link->network);
assert(link->rtnl_messages == 0);
- assert(link->state == LINK_STATE_ADDRESSES_SET);
+ assert(link->state == LINK_STATE_SETTING_ADDRESSES);
- link->state = LINK_STATE_SET_ROUTES;
+ link->state = LINK_STATE_SETTING_ROUTES;
if (!link->network->routes)
return link_enter_configured(link);
@@ -176,7 +179,8 @@ static int link_enter_set_routes(Link *link) {
r = route_configure(route, link, &route_handler);
if (r < 0) {
log_warning("Could not set routes for link '%s'", link->ifname);
- return link_enter_failed(link);
+ link_enter_failed(link);
+ return r;
}
link->rtnl_messages ++;
@@ -185,18 +189,12 @@ static int link_enter_set_routes(Link *link) {
return 0;
}
-static int link_enter_addresses_set(Link *link) {
- link->state = LINK_STATE_ADDRESSES_SET;
-
- return link_enter_set_routes(link);
-}
-
static int address_handler(sd_rtnl *rtnl, sd_rtnl_message *m, void *userdata) {
Link *link = userdata;
int r;
assert(link->rtnl_messages > 0);
- assert(link->state == LINK_STATE_SET_ADDRESSES || link->state == LINK_STATE_FAILED);
+ assert(link->state == LINK_STATE_SETTING_ADDRESSES || link->state == LINK_STATE_FAILED);
link->rtnl_messages --;
@@ -210,7 +208,7 @@ static int address_handler(sd_rtnl *rtnl, sd_rtnl_message *m, void *userdata) {
if (link->rtnl_messages == 0) {
log_info("Addresses set for link '%s'", link->ifname);
- link_enter_addresses_set(link);
+ link_enter_set_routes(link);
}
return 1;
@@ -222,18 +220,20 @@ static int link_enter_set_addresses(Link *link) {
assert(link);
assert(link->network);
+ assert(link->state == LINK_STATE_JOINING_BRIDGE);
assert(link->rtnl_messages == 0);
- if (!link->network->addresses)
- return link_enter_addresses_set(link);
+ link->state = LINK_STATE_SETTING_ADDRESSES;
- link->state = LINK_STATE_SET_ADDRESSES;
+ if (!link->network->addresses)
+ return link_enter_set_routes(link);
LIST_FOREACH(addresses, address, link->network->addresses) {
r = address_configure(address, link, &address_handler);
if (r < 0) {
log_warning("Could not set addresses for link '%s'", link->ifname);
- return link_enter_failed(link);
+ link_enter_failed(link);
+ return r;
}
link->rtnl_messages ++;
@@ -242,43 +242,6 @@ static int link_enter_set_addresses(Link *link) {
return 0;
}
-static int link_get_handler(sd_rtnl *rtnl, sd_rtnl_message *m, void *userdata) {
- Link *link = userdata;
- int r;
-
- r = sd_rtnl_message_get_errno(m);
- if (r < 0) {
- log_warning("Could not get state of interface '%s': %s",
- link->ifname, strerror(-r));
- link_enter_failed(link);
- }
-
- return 1;
-}
-
-static int link_get(Link *link) {
- _cleanup_sd_rtnl_message_unref_ sd_rtnl_message *req = NULL;
- int r;
-
- assert(link);
- assert(link->manager);
- assert(link->manager->rtnl);
-
- r = sd_rtnl_message_link_new(RTM_GETLINK, link->ifindex, &req);
- if (r < 0) {
- log_error("Could not allocate RTM_GETLINK message");
- return r;
- }
-
- r = sd_rtnl_call_async(link->manager->rtnl, req, link_get_handler, link, 0, NULL);
- if (r < 0) {
- log_error("Could not send rtnetlink message: %s", strerror(-r));
- return r;
- }
-
- return 0;
-}
-
static int link_up_handler(sd_rtnl *rtnl, sd_rtnl_message *m, void *userdata) {
Link *link = userdata;
int r;
@@ -322,36 +285,48 @@ static int link_up(Link *link) {
return 0;
}
-static int link_enter_bridge_joined(Link *link) {
+static int link_bridge_joined(Link *link) {
int r;
- link->state = LINK_STATE_BRIDGE_JOINED;
+ assert(link);
+ assert(link->state == LINK_STATE_JOINING_BRIDGE);
r = link_up(link);
- if (r < 0)
- return link_enter_failed(link);
+ if (r < 0) {
+ link_enter_failed(link);
+ return r;
+ }
- return link_enter_set_addresses(link);
+ r = link_enter_set_addresses(link);
+ if (r < 0) {
+ link_enter_failed(link);
+ return r;
+ }
+
+ return 0;
}
static int bridge_handler(sd_rtnl *rtnl, sd_rtnl_message *m, void *userdata) {
Link *link = userdata;
int r;
- assert(link->state == LINK_STATE_JOIN_BRIDGE || link->state == LINK_STATE_FAILED);
+ assert(link->state == LINK_STATE_JOINING_BRIDGE || link->state == LINK_STATE_FAILED);
+ assert(link->network);
if (link->state == LINK_STATE_FAILED)
return 1;
r = sd_rtnl_message_get_errno(m);
- if (r < 0)
+ if (r < 0) {
log_warning("Could not join interface '%s' to bridge '%s': %s",
link->ifname, link->network->bridge->name, strerror(-r));
- else
+ link_enter_failed(link);
+ return 1;
+ } else
log_info("Join interface '%s' to bridge: %s",
link->ifname, link->network->bridge->name);
- link_enter_bridge_joined(link);
+ link_bridge_joined(link);
return 1;
}
@@ -361,17 +336,56 @@ static int link_enter_join_bridge(Link *link) {
assert(link);
assert(link->network);
+ assert(link->state == _LINK_STATE_INVALID);
- if (!link->network->bridge)
- return link_enter_bridge_joined(link);
+ link->state = LINK_STATE_JOINING_BRIDGE;
- link->state = LINK_STATE_JOIN_BRIDGE;
+ if (!link->network->bridge)
+ return link_bridge_joined(link);
r = bridge_join(link->network->bridge, link, &bridge_handler);
if (r < 0) {
log_warning("Could not join link '%s' to bridge '%s'", link->ifname,
link->network->bridge->name);
- return link_enter_failed(link);
+ link_enter_failed(link);
+ return r;
+ }
+
+ return 0;
+}
+
+static int link_get_handler(sd_rtnl *rtnl, sd_rtnl_message *m, void *userdata) {
+ Link *link = userdata;
+ int r;
+
+ r = sd_rtnl_message_get_errno(m);
+ if (r < 0) {
+ log_warning("Could not get state of interface '%s': %s",
+ link->ifname, strerror(-r));
+ link_enter_failed(link);
+ }
+
+ return 1;
+}
+
+static int link_get(Link *link) {
+ _cleanup_sd_rtnl_message_unref_ sd_rtnl_message *req = NULL;
+ int r;
+
+ assert(link);
+ assert(link->manager);
+ assert(link->manager->rtnl);
+
+ r = sd_rtnl_message_link_new(RTM_GETLINK, link->ifindex, &req);
+ if (r < 0) {
+ log_error("Could not allocate RTM_GETLINK message");
+ return r;
+ }
+
+ r = sd_rtnl_call_async(link->manager->rtnl, req, link_get_handler, link, 0, NULL);
+ if (r < 0) {
+ log_error("Could not send rtnetlink message: %s", strerror(-r));
+ return r;
}
return 0;
@@ -380,13 +394,19 @@ static int link_enter_join_bridge(Link *link) {
int link_configure(Link *link) {
int r;
+ assert(link);
+ assert(link->network);
+ assert(link->state == _LINK_STATE_INVALID);
+
r = link_get(link);
- if (r < 0)
- return link_enter_failed(link);
+ if (r < 0) {
+ link_enter_failed(link);
+ return r;
+ }
r = link_enter_join_bridge(link);
if (r < 0)
- return link_enter_failed(link);
+ return r;
return 0;
}
diff --git a/src/network/networkd.h b/src/network/networkd.h
index d1bc348..c28c90f 100644
--- a/src/network/networkd.h
+++ b/src/network/networkd.h
@@ -133,11 +133,9 @@ struct Route {
};
typedef enum LinkState {
- LINK_STATE_JOIN_BRIDGE,
- LINK_STATE_BRIDGE_JOINED,
- LINK_STATE_SET_ADDRESSES,
- LINK_STATE_ADDRESSES_SET,
- LINK_STATE_SET_ROUTES,
+ LINK_STATE_JOINING_BRIDGE,
+ LINK_STATE_SETTING_ADDRESSES,
+ LINK_STATE_SETTING_ROUTES,
LINK_STATE_CONFIGURED,
LINK_STATE_FAILED,
_LINK_STATE_MAX,
commit 22936833e177d9e477e059ec2b4f4fa9213b4e19
Author: Tom Gundersen <teg at jklm.no>
Date: Tue Dec 17 18:36:09 2013 +0100
networkd: rename link_update_flags to link_update
We are likely to track more than the flags in the future.
diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c
index 4cf34a6..447b2a9 100644
--- a/src/network/networkd-link.c
+++ b/src/network/networkd-link.c
@@ -391,8 +391,18 @@ int link_configure(Link *link) {
return 0;
}
-int link_update_flags(Link *link, unsigned flags) {
+int link_update(Link *link, sd_rtnl_message *m) {
+ unsigned flags;
+ int r;
+
assert(link);
+ assert(m);
+
+ r = sd_rtnl_message_link_get_flags(m, &flags);
+ if (r < 0) {
+ log_warning("Could not get link flags of '%s'", link->ifname);
+ return r;
+ }
if (link->flags & IFF_UP && !(flags & IFF_UP))
log_info("Interface '%s' is down", link->ifname);
diff --git a/src/network/networkd-manager.c b/src/network/networkd-manager.c
index 1b5837e..724e5e5 100644
--- a/src/network/networkd-manager.c
+++ b/src/network/networkd-manager.c
@@ -243,7 +243,6 @@ int manager_udev_listen(Manager *m) {
static int manager_rtnl_process_link(sd_rtnl *rtnl, sd_rtnl_message *message, void *userdata) {
Manager *m = userdata;
Link *link;
- unsigned flags;
int r, ifindex;
r = sd_rtnl_message_link_get_ifindex(message, &ifindex);
@@ -254,11 +253,7 @@ static int manager_rtnl_process_link(sd_rtnl *rtnl, sd_rtnl_message *message, vo
if (!link)
return 0;
- r = sd_rtnl_message_link_get_flags(message, &flags);
- if (r < 0)
- return 0;
-
- r = link_update_flags(link, flags);
+ r = link_update(link, message);
if (r < 0)
return 0;
diff --git a/src/network/networkd.h b/src/network/networkd.h
index 075cc12..d1bc348 100644
--- a/src/network/networkd.h
+++ b/src/network/networkd.h
@@ -263,7 +263,7 @@ void link_free(Link *link);
int link_add(Manager *manager, struct udev_device *device);
int link_configure(Link *link);
-int link_update_flags(Link *link, unsigned flags);
+int link_update(Link *link, sd_rtnl_message *message);
DEFINE_TRIVIAL_CLEANUP_FUNC(Link*, link_free);
#define _cleanup_link_free_ _cleanup_(link_freep)
More information about the systemd-commits
mailing list