summaryrefslogtreecommitdiff
path: root/src/network/networkd-link.c
diff options
context:
space:
mode:
authorTom Gundersen <teg@jklm.no>2013-11-24 23:37:56 +0100
committerTom Gundersen <teg@jklm.no>2013-11-26 01:32:25 +0100
commit02b59d57e0c08231645120077f651151f5bb2bab (patch)
tree10549c36b26f6fda4daf7b9d11c994adfc6a88ff /src/network/networkd-link.c
parentc166a070553511e402de5ad216d3fb62b49bdacb (diff)
networkd: add bridge support
A bridge is specified in a .netdev file with a section [Bridge] and at least the entry Name=. A link may be joined to a bridge if the .network applied to it has a Bridge= entry giving the name of the bridge in its [Network] section. We eagerly create all bridges on startup, and links are added to bridges as soon as they both appear.
Diffstat (limited to 'src/network/networkd-link.c')
-rw-r--r--src/network/networkd-link.c57
1 files changed, 55 insertions, 2 deletions
diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c
index 255b413586..09de862819 100644
--- a/src/network/networkd-link.c
+++ b/src/network/networkd-link.c
@@ -85,6 +85,7 @@ int link_add(Manager *m, struct udev_device *device) {
Network *network;
int r;
uint64_t ifindex;
+ const char *devtype;
assert(m);
assert(device);
@@ -100,6 +101,13 @@ int link_add(Manager *m, struct udev_device *device) {
return r;
}
+ devtype = udev_device_get_devtype(device);
+ if (streq_ptr(devtype, "bridge")) {
+ r = bridge_set_link(m, link);
+ if (r < 0)
+ return r == -ENOENT ? 0 : r;
+ }
+
r = network_get(m, device, &network);
if (r < 0)
return r == -ENOENT ? 0 : r;
@@ -287,14 +295,59 @@ static int link_up(Link *link) {
return 0;
}
-int link_configure(Link *link) {
+static int link_enter_bridge_joined(Link *link) {
int r;
r = link_up(link);
if (r < 0)
return link_enter_failed(link);
- r = link_enter_set_addresses(link);
+ link->state = LINK_STATE_BRIDGE_JOINED;
+
+ return link_enter_set_addresses(link);
+}
+
+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);
+
+ if (link->state == LINK_STATE_FAILED)
+ return 1;
+
+ r = sd_rtnl_message_get_errno(m);
+ if (r < 0)
+ log_warning("Could not join interface '%s' to bridge: %s",
+ link->ifname, strerror(-r));
+
+ link_enter_bridge_joined(link);
+
+ return 1;
+}
+
+static int link_enter_join_bridge(Link *link) {
+ int r;
+
+ assert(link);
+ assert(link->network);
+
+ if (!link->network->bridge)
+ return link_enter_bridge_joined(link);
+
+ link->state = LINK_STATE_JOIN_BRIDGE;
+
+ r = bridge_join(link->network->bridge, link, &bridge_handler);
+ if (r < 0)
+ return link_enter_failed(link);
+
+ return 0;
+}
+
+int link_configure(Link *link) {
+ int r;
+
+ r = link_enter_join_bridge(link);
if (r < 0)
return link_enter_failed(link);