chiark / gitweb /
systemd-networkd: Use IFA_F_NOPREFIXROUTE with IPv6 addresses
[elogind.git] / src / network / networkd-link.c
index 26ef0feaae2d6c635d9fe6284e0db28adfb6b635..437c59843ed9aaa4c971dfb28635c59427516fd0 100644 (file)
 #include <linux/if.h>
 #include <unistd.h>
 
-#include "networkd-link.h"
-#include "networkd-netdev.h"
-#include "libudev-private.h"
-#include "udev-util.h"
 #include "util.h"
 #include "virt.h"
+#include "fileio.h"
 #include "bus-util.h"
+#include "udev-util.h"
 #include "network-internal.h"
-#include "conf-parser.h"
-
-#include "dhcp-lease-internal.h"
+#include "networkd-link.h"
+#include "networkd-netdev.h"
 
-static bool link_dhcp6_enabled(Link *link) {
+bool link_dhcp6_enabled(Link *link) {
         if (link->flags & IFF_LOOPBACK)
                 return false;
 
         if (!link->network)
                 return false;
 
-        return IN_SET(link->network->dhcp, DHCP_SUPPORT_V6, DHCP_SUPPORT_BOTH);
+        return IN_SET(link->network->dhcp, ADDRESS_FAMILY_IPV6, ADDRESS_FAMILY_YES);
 }
 
-static bool link_dhcp4_enabled(Link *link) {
+bool link_dhcp4_enabled(Link *link) {
         if (link->flags & IFF_LOOPBACK)
                 return false;
 
         if (!link->network)
                 return false;
 
-        return IN_SET(link->network->dhcp, DHCP_SUPPORT_V4, DHCP_SUPPORT_BOTH);
+        return IN_SET(link->network->dhcp, ADDRESS_FAMILY_IPV4, ADDRESS_FAMILY_YES);
 }
 
-static bool link_dhcp4_server_enabled(Link *link) {
+bool link_dhcp4_server_enabled(Link *link) {
         if (link->flags & IFF_LOOPBACK)
                 return false;
 
@@ -65,14 +62,57 @@ static bool link_dhcp4_server_enabled(Link *link) {
         return link->network->dhcp_server;
 }
 
-static bool link_ipv4ll_enabled(Link *link) {
+bool link_ipv4ll_enabled(Link *link) {
+        if (link->flags & IFF_LOOPBACK)
+                return false;
+
+        if (!link->network)
+                return false;
+
+        return IN_SET(link->network->link_local, ADDRESS_FAMILY_IPV4, ADDRESS_FAMILY_YES);
+}
+
+bool link_ipv6ll_enabled(Link *link) {
+        if (link->flags & IFF_LOOPBACK)
+                return false;
+
+        if (!link->network)
+                return false;
+
+        return IN_SET(link->network->link_local, ADDRESS_FAMILY_IPV6, ADDRESS_FAMILY_YES);
+}
+
+bool link_lldp_enabled(Link *link) {
+        if (link->flags & IFF_LOOPBACK)
+                return false;
+
+        if (!link->network)
+                return false;
+
+        if (link->network->bridge)
+                return false;
+
+        return link->network->lldp;
+}
+
+static bool link_ipv4_forward_enabled(Link *link) {
+        if (link->flags & IFF_LOOPBACK)
+                return false;
+
+        if (!link->network)
+                return false;
+
+        return IN_SET(link->network->ip_forward, ADDRESS_FAMILY_IPV4, ADDRESS_FAMILY_YES);
+}
+
+static bool link_ipv6_forward_enabled(Link *link) {
         if (link->flags & IFF_LOOPBACK)
                 return false;
 
         if (!link->network)
                 return false;
 
-        return link->network->ipv4ll;
+        return IN_SET(link->network->ip_forward, ADDRESS_FAMILY_IPV6, ADDRESS_FAMILY_YES);
 }
 
 #define FLAG_STRING(string, flag, old, new) \
@@ -89,7 +129,7 @@ static int link_update_flags(Link *link, sd_rtnl_message *m) {
 
         r = sd_rtnl_message_link_get_flags(m, &flags);
         if (r < 0) {
-                log_warning_link(link, "Could not get link flags");
+                log_link_warning(link, "Could not get link flags");
                 return r;
         }
 
@@ -103,7 +143,7 @@ static int link_update_flags(Link *link, sd_rtnl_message *m) {
                 return 0;
 
         if (link->flags != flags) {
-                log_debug_link(link, "flags change:%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
+                log_link_debug(link, "flags change:%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
                                FLAG_STRING("LOOPBACK", IFF_LOOPBACK, link->flags, flags),
                                FLAG_STRING("MASTER", IFF_MASTER, link->flags, flags),
                                FLAG_STRING("SLAVE", IFF_SLAVE, link->flags, flags),
@@ -136,12 +176,12 @@ static int link_update_flags(Link *link, sd_rtnl_message *m) {
                 /* link flags are currently at most 18 bits, let's align to
                  * printing 20 */
                 if (unknown_flags_added)
-                        log_debug_link(link,
+                        log_link_debug(link,
                                        "unknown link flags gained: %#.5x (ignoring)",
                                        unknown_flags_added);
 
                 if (unknown_flags_removed)
-                        log_debug_link(link,
+                        log_link_debug(link,
                                        "unknown link flags lost: %#.5x (ignoring)",
                                        unknown_flags_removed);
         }
@@ -194,7 +234,7 @@ static int link_new(Manager *manager, sd_rtnl_message *message, Link **ret) {
 
         r = sd_rtnl_message_read_ether_addr(message, IFLA_ADDRESS, &link->mac);
         if (r < 0)
-                log_debug_link(link, "MAC address not found for new device, continuing without");
+                log_link_debug(link, "MAC address not found for new device, continuing without");
 
         r = asprintf(&link->state_file, "/run/systemd/netif/links/%d",
                      link->ifindex);
@@ -206,6 +246,12 @@ static int link_new(Manager *manager, sd_rtnl_message *message, Link **ret) {
         if (r < 0)
                 return -ENOMEM;
 
+        r = asprintf(&link->lldp_file, "/run/systemd/netif/lldp/%d",
+                     link->ifindex);
+        if (r < 0)
+                return -ENOMEM;
+
+
         r = hashmap_ensure_allocated(&manager->links, NULL);
         if (r < 0)
                 return r;
@@ -226,6 +272,8 @@ static int link_new(Manager *manager, sd_rtnl_message *message, Link **ret) {
 
 static void link_free(Link *link) {
         Address *address;
+        Iterator i;
+        Link *carrier;
 
         if (!link)
                 return;
@@ -240,12 +288,16 @@ static void link_free(Link *link) {
                 address_free(address);
         }
 
+        sd_dhcp_server_unref(link->dhcp_server);
         sd_dhcp_client_unref(link->dhcp_client);
         sd_dhcp_lease_unref(link->dhcp_lease);
 
-        unlink(link->lease_file);
         free(link->lease_file);
 
+        sd_lldp_free(link->lldp);
+
+        free(link->lldp_file);
+
         sd_ipv4ll_unref(link->ipv4ll);
         sd_dhcp6_client_unref(link->dhcp6_client);
         sd_icmp6_nd_unref(link->icmp6_router_discovery);
@@ -255,11 +307,18 @@ static void link_free(Link *link) {
 
         free(link->ifname);
 
-        unlink(link->state_file);
         free(link->state_file);
 
         udev_device_unref(link->udev_device);
 
+        HASHMAP_FOREACH (carrier, link->bound_to_links, i)
+                hashmap_remove(link->bound_to_links, INT_TO_PTR(carrier->ifindex));
+        hashmap_free(link->bound_to_links);
+
+        HASHMAP_FOREACH (carrier, link->bound_by_links, i)
+                hashmap_remove(link->bound_by_links, INT_TO_PTR(carrier->ifindex));
+        hashmap_free(link->bound_by_links);
+
         free(link);
 }
 
@@ -293,15 +352,15 @@ int link_get(Manager *m, int ifindex, Link **ret) {
         return 0;
 }
 
-void link_drop(Link *link) {
-        if (!link || link->state == LINK_STATE_LINGER)
-                return;
+static void link_set_state(Link *link, LinkState state) {
+        assert(link);
 
-        link->state = LINK_STATE_LINGER;
+        if (link->state == state)
+                return;
 
-        log_debug_link(link, "link removed");
+        link->state = state;
 
-        link_unref(link);
+        link_send_changed(link, "AdministrativeState", NULL);
 
         return;
 }
@@ -309,9 +368,9 @@ void link_drop(Link *link) {
 static void link_enter_unmanaged(Link *link) {
         assert(link);
 
-        log_debug_link(link, "unmanaged");
+        log_link_debug(link, "unmanaged");
 
-        link->state = LINK_STATE_UNMANAGED;
+        link_set_state(link, LINK_STATE_UNMANAGED);
 
         link_save(link);
 }
@@ -329,7 +388,7 @@ static int link_stop_clients(Link *link) {
         if (link->dhcp_client) {
                 k = sd_dhcp_client_stop(link->dhcp_client);
                 if (k < 0) {
-                        log_warning_link(link, "Could not stop DHCPv4 client: %s",
+                        log_link_warning(link, "Could not stop DHCPv4 client: %s",
                                          strerror(-r));
                         r = k;
                 }
@@ -338,7 +397,7 @@ static int link_stop_clients(Link *link) {
         if (link->ipv4ll) {
                 k = sd_ipv4ll_stop(link->ipv4ll);
                 if (k < 0) {
-                        log_warning_link(link, "Could not stop IPv4 link-local: %s",
+                        log_link_warning(link, "Could not stop IPv4 link-local: %s",
                                          strerror(-r));
                         r = k;
                 }
@@ -349,7 +408,7 @@ static int link_stop_clients(Link *link) {
                 if (link->dhcp6_client) {
                         k = sd_dhcp6_client_stop(link->dhcp6_client);
                         if (k < 0) {
-                                log_warning_link(link, "Could not stop DHCPv6 client: %s",
+                                log_link_warning(link, "Could not stop DHCPv6 client: %s",
                                                  strerror(-r));
                                 r = k;
                         }
@@ -357,13 +416,23 @@ static int link_stop_clients(Link *link) {
 
                 k = sd_icmp6_nd_stop(link->icmp6_router_discovery);
                 if (k < 0) {
-                        log_warning_link(link,
+                        log_link_warning(link,
                                          "Could not stop ICMPv6 router discovery: %s",
                                          strerror(-r));
                         r = k;
                 }
         }
 
+        if (link->lldp) {
+
+                k = sd_lldp_stop(link->lldp);
+                if (k < 0) {
+                        log_link_warning(link, "Could not stop LLDP : %s",
+                                         strerror(-r));
+                        r = k;
+                }
+        }
+
         return r;
 }
 
@@ -373,9 +442,9 @@ void link_enter_failed(Link *link) {
         if (IN_SET(link->state, LINK_STATE_FAILED, LINK_STATE_LINGER))
                 return;
 
-        log_warning_link(link, "failed");
+        log_link_warning(link, "failed");
 
-        link->state = LINK_STATE_FAILED;
+        link_set_state(link, LINK_STATE_FAILED);
 
         link_stop_clients(link);
 
@@ -388,7 +457,7 @@ static Address* link_find_dhcp_server_address(Link *link) {
         assert(link);
         assert(link->network);
 
-        /* The the first statically configured address if there is any */
+        /* The first statically configured address if there is any */
         LIST_FOREACH(addresses, address, link->network->static_addresses) {
 
                 if (address->family != AF_INET)
@@ -412,66 +481,13 @@ static Address* link_find_dhcp_server_address(Link *link) {
 }
 
 static int link_enter_configured(Link *link) {
-        int r;
-
         assert(link);
         assert(link->network);
         assert(link->state == LINK_STATE_SETTING_ROUTES);
 
-        if (link_dhcp4_server_enabled(link) &&
-            !sd_dhcp_server_is_running(link->dhcp_server)) {
-                struct in_addr pool_start;
-                Address *address;
-
-                address = link_find_dhcp_server_address(link);
-                if (!address) {
-                        log_warning_link(link,
-                                         "Failed to find suitable address for DHCPv4 server instance.");
-                        link_enter_failed(link);
-                        return 0;
-                }
-
-                log_debug_link(link, "offering DHCPv4 leases");
-
-                r = sd_dhcp_server_set_address(link->dhcp_server,
-                                               &address->in_addr.in,
-                                               address->prefixlen);
-                if (r < 0)
-                        return r;
-
-                /* offer 32 addresses starting from the address following the server address */
-                pool_start.s_addr = htobe32(be32toh(address->in_addr.in.s_addr) + 1);
-                r = sd_dhcp_server_set_lease_pool(link->dhcp_server,
-                                                  &pool_start, 32);
-                if (r < 0)
-                        return r;
-
-                /* TODO:
-                r = sd_dhcp_server_set_router(link->dhcp_server,
-                                              &main_address->in_addr.in);
-                if (r < 0)
-                        return r;
-
-                r = sd_dhcp_server_set_prefixlen(link->dhcp_server,
-                                                 main_address->prefixlen);
-                if (r < 0)
-                        return r;
-                */
-
-                r = sd_dhcp_server_start(link->dhcp_server);
-                if (r < 0) {
-                        log_warning_link(link, "could not start DHCPv4 server "
-                                         "instance: %s", strerror(-r));
-
-                        link_enter_failed(link);
-
-                        return 0;
-                }
-        }
-
-        log_info_link(link, "link configured");
+        log_link_info(link, "link configured");
 
-        link->state = LINK_STATE_CONFIGURED;
+        link_set_state(link, LINK_STATE_CONFIGURED);
 
         link_save(link);
 
@@ -515,15 +531,10 @@ static int route_handler(sd_rtnl *rtnl, sd_rtnl_message *m, void *userdata) {
 
         r = sd_rtnl_message_get_errno(m);
         if (r < 0 && r != -EEXIST)
-                log_struct_link(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_debug_link(link, "routes set");
+                log_link_debug(link, "routes set");
                 link->static_configured = true;
                 link_client_handler(link);
         }
@@ -539,12 +550,12 @@ static int link_enter_set_routes(Link *link) {
         assert(link->network);
         assert(link->state == LINK_STATE_SETTING_ADDRESSES);
 
-        link->state = LINK_STATE_SETTING_ROUTES;
+        link_set_state(link, LINK_STATE_SETTING_ROUTES);
 
         LIST_FOREACH(routes, rt, link->network->static_routes) {
                 r = route_configure(rt, link, &route_handler);
                 if (r < 0) {
-                        log_warning_link(link,
+                        log_link_warning(link,
                                          "could not set routes: %s",
                                          strerror(-r));
                         link_enter_failed(link);
@@ -558,7 +569,7 @@ static int link_enter_set_routes(Link *link) {
                 link->static_configured = true;
                 link_client_handler(link);
         } else
-                log_debug_link(link, "setting routes");
+                log_link_debug(link, "setting routes");
 
         return 0;
 }
@@ -576,38 +587,7 @@ int link_route_drop_handler(sd_rtnl *rtnl, sd_rtnl_message *m, void *userdata) {
 
         r = sd_rtnl_message_get_errno(m);
         if (r < 0 && r != -ESRCH)
-                log_struct_link(LOG_WARNING, link,
-                                "MESSAGE=%-*s: could not drop route: %s",
-                                IFNAMSIZ,
-                                link->ifname, strerror(-r),
-                                "ERRNO=%d", -r,
-                                NULL);
-
-        return 1;
-}
-
-int link_get_address_handler(sd_rtnl *rtnl, sd_rtnl_message *m, void *userdata) {
-        _cleanup_link_unref_ Link *link = userdata;
-        int r;
-
-        assert(rtnl);
-        assert(m);
-        assert(link);
-        assert(link->manager);
-
-        for (; m; m = sd_rtnl_message_next(m)) {
-                r = sd_rtnl_message_get_errno(m);
-                if (r < 0) {
-                        log_debug_link(link, "getting address failed: %s",
-                                       strerror(-r));
-                        continue;
-                }
-
-                r = link_rtnl_process_address(rtnl, m, link->manager);
-                if (r < 0)
-                        log_warning_link(link, "could not process address: %s",
-                                         strerror(-r));
-        }
+                log_link_warning_errno(link, -r, "%-*s: could not drop route: %m", IFNAMSIZ, link->ifname);
 
         return 1;
 }
@@ -631,20 +611,12 @@ static int address_handler(sd_rtnl *rtnl, sd_rtnl_message *m, void *userdata) {
 
         r = sd_rtnl_message_get_errno(m);
         if (r < 0 && r != -EEXIST)
-                log_struct_link(LOG_WARNING, link,
-                                "MESSAGE=%-*s: could not set address: %s",
-                                IFNAMSIZ,
-                                link->ifname, strerror(-r),
-                                "ERRNO=%d", -r,
-                                NULL);
-        else if (r >= 0) {
-                /* calling handler directly so take a ref */
-                link_ref(link);
-                link_get_address_handler(rtnl, m, link);
-        }
+                log_link_warning_errno(link, -r, "%-*s: could not set address: %m", IFNAMSIZ, link->ifname);
+        else if (r >= 0)
+                link_rtnl_process_address(rtnl, m, link->manager);
 
         if (link->link_messages == 0) {
-                log_debug_link(link, "addresses set");
+                log_link_debug(link, "addresses set");
                 link_enter_set_routes(link);
         }
 
@@ -659,14 +631,12 @@ static int link_enter_set_addresses(Link *link) {
         assert(link->network);
         assert(link->state != _LINK_STATE_INVALID);
 
-        link->state = LINK_STATE_SETTING_ADDRESSES;
+        link_set_state(link, LINK_STATE_SETTING_ADDRESSES);
 
         LIST_FOREACH(addresses, ad, link->network->static_addresses) {
                 r = address_configure(ad, link, &address_handler);
                 if (r < 0) {
-                        log_warning_link(link,
-                                         "could not set addresses: %s",
-                                         strerror(-r));
+                        log_link_warning_errno(link, r, "Could not set addresses: %m");
                         link_enter_failed(link);
                         return r;
                 }
@@ -674,10 +644,62 @@ static int link_enter_set_addresses(Link *link) {
                 link->link_messages ++;
         }
 
+        /* now that we can figure out a default address for the dhcp server,
+           start it */
+        if (link_dhcp4_server_enabled(link)) {
+                struct in_addr pool_start;
+                Address *address;
+
+                address = link_find_dhcp_server_address(link);
+                if (!address) {
+                        log_link_warning(link,
+                                         "Failed to find suitable address for DHCPv4 server instance.");
+                        link_enter_failed(link);
+                        return 0;
+                }
+
+                r = sd_dhcp_server_set_address(link->dhcp_server,
+                                               &address->in_addr.in,
+                                               address->prefixlen);
+                if (r < 0)
+                        return r;
+
+                /* offer 32 addresses starting from the address following the server address */
+                pool_start.s_addr = htobe32(be32toh(address->in_addr.in.s_addr) + 1);
+                r = sd_dhcp_server_set_lease_pool(link->dhcp_server,
+                                                  &pool_start, 32);
+                if (r < 0)
+                        return r;
+
+                /* TODO:
+                r = sd_dhcp_server_set_router(link->dhcp_server,
+                                              &main_address->in_addr.in);
+                if (r < 0)
+                        return r;
+
+                r = sd_dhcp_server_set_prefixlen(link->dhcp_server,
+                                                 main_address->prefixlen);
+                if (r < 0)
+                        return r;
+                */
+
+                r = sd_dhcp_server_start(link->dhcp_server);
+                if (r < 0) {
+                        log_link_warning(link, "could not start DHCPv4 server "
+                                         "instance: %s", strerror(-r));
+
+                        link_enter_failed(link);
+
+                        return 0;
+                }
+
+                log_link_debug(link, "offering DHCPv4 leases");
+        }
+
         if (link->link_messages == 0) {
                 link_enter_set_routes(link);
         } else
-                log_debug_link(link, "setting addresses");
+                log_link_debug(link, "setting addresses");
 
         return 0;
 }
@@ -695,14 +717,45 @@ int link_address_drop_handler(sd_rtnl *rtnl, sd_rtnl_message *m, void *userdata)
 
         r = sd_rtnl_message_get_errno(m);
         if (r < 0 && r != -EADDRNOTAVAIL)
-                log_struct_link(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_bridge_fdb(Link *const link) {
+        FdbEntry *fdb_entry;
+        int r = 0;
+
+        LIST_FOREACH(static_fdb_entries, fdb_entry, link->network->static_fdb_entries) {
+                r = fdb_entry_configure(link, fdb_entry);
+                if(r < 0) {
+                        log_link_error(link, "Failed to add MAC entry to static MAC table: %s", strerror(-r));
+                        break;
+                }
+        }
+
+        return r;
+}
+
+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,
@@ -717,7 +770,7 @@ static int set_hostname_handler(sd_bus *bus, sd_bus_message *m, void *userdata,
 
         r = sd_bus_message_get_errno(m);
         if (r > 0)
-                log_warning_link(link, "Could not set hostname: %s",
+                log_link_warning(link, "Could not set hostname: %s",
                                  strerror(r));
 
         return 1;
@@ -731,11 +784,11 @@ int link_set_hostname(Link *link, const char *hostname) {
         assert(link->manager);
         assert(hostname);
 
-        log_debug_link(link, "Setting transient hostname: '%s'", hostname);
+        log_link_debug(link, "Setting transient hostname: '%s'", hostname);
 
         if (!link->manager->bus) {
                 /* TODO: replace by assert when we can rely on kdbus */
-                log_info_link(link,
+                log_link_info(link,
                               "Not connected to system bus, ignoring transient hostname.");
                 return 0;
         }
@@ -757,7 +810,7 @@ int link_set_hostname(Link *link, const char *hostname) {
         r = sd_bus_call_async(link->manager->bus, NULL, m, set_hostname_handler,
                               link, 0);
         if (r < 0) {
-                log_error_link(link, "Could not set transient hostname: %s",
+                log_link_error(link, "Could not set transient hostname: %s",
                                strerror(-r));
                 return r;
         }
@@ -780,11 +833,7 @@ static int set_mtu_handler(sd_rtnl *rtnl, sd_rtnl_message *m, void *userdata) {
 
         r = sd_rtnl_message_get_errno(m);
         if (r < 0)
-                log_struct_link(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;
 }
@@ -797,25 +846,25 @@ int link_set_mtu(Link *link, uint32_t mtu) {
         assert(link->manager);
         assert(link->manager->rtnl);
 
-        log_debug_link(link, "setting MTU: %" PRIu32, mtu);
+        log_link_debug(link, "setting MTU: %" PRIu32, mtu);
 
         r = sd_rtnl_message_new_link(link->manager->rtnl, &req,
                                      RTM_SETLINK, link->ifindex);
         if (r < 0) {
-                log_error_link(link, "Could not allocate RTM_SETLINK message");
+                log_link_error(link, "Could not allocate RTM_SETLINK message");
                 return r;
         }
 
         r = sd_rtnl_message_append_u32(req, IFLA_MTU, mtu);
         if (r < 0) {
-                log_error_link(link, "Could not append MTU: %s", strerror(-r));
+                log_link_error(link, "Could not append MTU: %s", strerror(-r));
                 return r;
         }
 
         r = sd_rtnl_call_async(link->manager->rtnl, req, set_mtu_handler, link,
                                0, NULL);
         if (r < 0) {
-                log_error_link(link,
+                log_link_error(link,
                                "Could not send rtnetlink message: %s",
                                strerror(-r));
                 return r;
@@ -826,104 +875,84 @@ int link_set_mtu(Link *link, uint32_t mtu) {
         return 0;
 }
 
-static void dhcp6_handler(sd_dhcp6_client *client, int event, void *userdata) {
-        Link *link = userdata;
+static int link_set_bridge(Link *link) {
+        _cleanup_rtnl_message_unref_ sd_rtnl_message *req = NULL;
+        int r;
 
         assert(link);
         assert(link->network);
-        assert(link->manager);
-
-        if (IN_SET(link->state, LINK_STATE_FAILED, LINK_STATE_LINGER))
-                return;
 
-        switch(event) {
-        case DHCP6_EVENT_STOP:
-        case DHCP6_EVENT_RESEND_EXPIRE:
-        case DHCP6_EVENT_RETRANS_MAX:
-        case DHCP6_EVENT_IP_ACQUIRE:
-                log_debug_link(link, "DHCPv6 event %d", event);
+        if(link->network->cost == 0)
+                return 0;
 
-                break;
+        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;
+        }
 
-        default:
-                if (event < 0)
-                        log_warning_link(link, "DHCPv6 error: %s",
-                                         strerror(-event));
-                else
-                        log_warning_link(link, "DHCPv6 unknown event: %d",
-                                         event);
-                return;
+        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;
         }
-}
 
-static void icmp6_router_handler(sd_icmp6_nd *nd, int event, void *userdata) {
-        Link *link = userdata;
-        int 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;
+        }
 
-        assert(link);
-        assert(link->network);
-        assert(link->manager);
+        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;
+                }
+        }
 
-        if (IN_SET(link->state, LINK_STATE_FAILED, LINK_STATE_LINGER))
-                return;
-
-        switch(event) {
-        case ICMP6_EVENT_ROUTER_ADVERTISMENT_NONE:
-        case ICMP6_EVENT_ROUTER_ADVERTISMENT_OTHER:
-                return;
-
-        case ICMP6_EVENT_ROUTER_ADVERTISMENT_TIMEOUT:
-        case ICMP6_EVENT_ROUTER_ADVERTISMENT_MANAGED:
-                break;
-
-        default:
-                if (event < 0)
-                        log_warning_link(link, "ICMPv6 error: %s",
-                                         strerror(-event));
-                else
-                        log_warning_link(link, "ICMPv6 unknown event: %d",
-                                         event);
-
-                return;
-        }
-
-        if (link->dhcp6_client)
-                return;
-
-        r = sd_dhcp6_client_new(&link->dhcp6_client);
-        if (r < 0)
-                return;
-
-        r = sd_dhcp6_client_attach_event(link->dhcp6_client, NULL, 0);
+        r = sd_rtnl_message_close_container(req);
         if (r < 0) {
-                link->dhcp6_client = sd_dhcp6_client_unref(link->dhcp6_client);
-                return;
+                log_link_error(link,
+                               "Could not append IFLA_LINKINFO attribute: %s",
+                               strerror(-r));
+                return r;
         }
 
-        r = sd_dhcp6_client_set_mac(link->dhcp6_client,
-                                    (const uint8_t *) &link->mac,
-                                    sizeof (link->mac), ARPHRD_ETHER);
+        r = sd_rtnl_call_async(link->manager->rtnl, req, link_set_handler, link, 0, NULL);
         if (r < 0) {
-                link->dhcp6_client = sd_dhcp6_client_unref(link->dhcp6_client);
-                return;
+                log_link_error(link,
+                               "Could not send rtnetlink message: %s",
+                               strerror(-r));
+                return r;
         }
 
-        r = sd_dhcp6_client_set_index(link->dhcp6_client, link->ifindex);
-        if (r < 0) {
-                link->dhcp6_client = sd_dhcp6_client_unref(link->dhcp6_client);
-                return;
-        }
+        link_ref(link);
 
-        r = sd_dhcp6_client_set_callback(link->dhcp6_client, dhcp6_handler,
-                                         link);
-        if (r < 0) {
-                link->dhcp6_client = sd_dhcp6_client_unref(link->dhcp6_client);
+        return r;
+}
+
+static void lldp_handler(sd_lldp *lldp, int event, void *userdata) {
+        Link *link = userdata;
+        int r;
+
+        assert(link);
+        assert(link->network);
+        assert(link->manager);
+
+        if (event != UPDATE_INFO)
                 return;
-        }
 
-        r = sd_dhcp6_client_start(link->dhcp6_client);
+        r = sd_lldp_save(link->lldp, link->lldp_file);
         if (r < 0)
-                link->dhcp6_client = sd_dhcp6_client_unref(link->dhcp6_client);
+                log_link_warning(link, "could not save LLDP");
+
 }
 
 static int link_acquire_conf(Link *link) {
@@ -937,11 +966,11 @@ static int link_acquire_conf(Link *link) {
         if (link_ipv4ll_enabled(link)) {
                 assert(link->ipv4ll);
 
-                log_debug_link(link, "acquiring IPv4 link-local address");
+                log_link_debug(link, "acquiring IPv4 link-local address");
 
                 r = sd_ipv4ll_start(link->ipv4ll);
                 if (r < 0) {
-                        log_warning_link(link, "could not acquire IPv4 "
+                        log_link_warning(link, "could not acquire IPv4 "
                                          "link-local address");
                         return r;
                 }
@@ -950,11 +979,11 @@ static int link_acquire_conf(Link *link) {
         if (link_dhcp4_enabled(link)) {
                 assert(link->dhcp_client);
 
-                log_debug_link(link, "acquiring DHCPv4 lease");
+                log_link_debug(link, "acquiring DHCPv4 lease");
 
                 r = sd_dhcp_client_start(link->dhcp_client);
                 if (r < 0) {
-                        log_warning_link(link, "could not acquire DHCPv4 "
+                        log_link_warning(link, "could not acquire DHCPv4 "
                                          "lease");
                         return r;
                 }
@@ -963,93 +992,459 @@ static int link_acquire_conf(Link *link) {
         if (link_dhcp6_enabled(link)) {
                 assert(link->icmp6_router_discovery);
 
-                log_debug_link(link, "discovering IPv6 routers");
+                log_link_debug(link, "discovering IPv6 routers");
 
                 r = sd_icmp6_router_solicitation_start(link->icmp6_router_discovery);
                 if (r < 0) {
-                        log_warning_link(link,
+                        log_link_warning(link,
                                          "could not start IPv6 router discovery");
                         return r;
                 }
         }
 
+        if (link_lldp_enabled(link)) {
+                assert(link->lldp);
+
+                log_link_debug(link, "Starting LLDP");
+
+                r = sd_lldp_start(link->lldp);
+                if (r < 0) {
+                        log_link_warning(link, "could not start LLDP ");
+                        return r;
+                }
+        }
+
+        return 0;
+}
+
+bool link_has_carrier(Link *link) {
+        /* see Documentation/networking/operstates.txt in the kernel sources */
+
+        if (link->kernel_operstate == IF_OPER_UP)
+                return true;
+
+        if (link->kernel_operstate == IF_OPER_UNKNOWN)
+                /* operstate may not be implemented, so fall back to flags */
+                if ((link->flags & IFF_LOWER_UP) && !(link->flags & IFF_DORMANT))
+                        return true;
+
+        return false;
+}
+
+static int link_up_handler(sd_rtnl *rtnl, sd_rtnl_message *m, void *userdata) {
+        _cleanup_link_unref_ Link *link = userdata;
+        int r;
+
+        assert(link);
+
+        if (IN_SET(link->state, LINK_STATE_FAILED, LINK_STATE_LINGER))
+                return 1;
+
+        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_link_warning_errno(link, -r, "%-*s: could not bring up interface: %m", IFNAMSIZ, link->ifname);
+        }
+
+        return 1;
+}
+
+static int link_up(Link *link) {
+        _cleanup_rtnl_message_unref_ sd_rtnl_message *req = NULL;
+        uint8_t ipv6ll_mode;
+        int r;
+
+        assert(link);
+        assert(link->network);
+        assert(link->manager);
+        assert(link->manager->rtnl);
+
+        log_link_debug(link, "bringing link up");
+
+        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_flags(req, IFF_UP, IFF_UP);
+        if (r < 0) {
+                log_link_error(link, "Could not set link flags: %s",
+                               strerror(-r));
+                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_message_open_container(req, IFLA_AF_SPEC);
+        if (r < 0) {
+                log_link_error(link, "Could not open IFLA_AF_SPEC container: %s", strerror(-r));
+                return r;
+        }
+
+        r = sd_rtnl_message_open_container(req, AF_INET6);
+        if (r < 0) {
+                log_link_error(link, "Could not open AF_INET6 container: %s", strerror(-r));
+                return r;
+        }
+
+        ipv6ll_mode = link_ipv6ll_enabled(link) ? IN6_ADDR_GEN_MODE_EUI64 : IN6_ADDR_GEN_MODE_NONE;
+        r = sd_rtnl_message_append_u8(req, IFLA_INET6_ADDR_GEN_MODE, ipv6ll_mode);
+        if (r < 0) {
+                log_link_error(link, "Could not append IFLA_INET6_ADDR_GEN_MODE: %s", strerror(-r));
+                return r;
+        }
+
+        if (!in_addr_is_null(AF_INET6, &link->network->ipv6_token)) {
+                r = sd_rtnl_message_append_in6_addr(req, IFLA_INET6_TOKEN, &link->network->ipv6_token.in6);
+                if (r < 0) {
+                        log_link_error(link, "Could not append IFLA_INET6_TOKEN: %s", strerror(-r));
+                        return r;
+                }
+        }
+
+        r = sd_rtnl_message_close_container(req);
+        if (r < 0) {
+                log_link_error(link, "Could not close AF_INET6 container: %s", strerror(-r));
+                return r;
+        }
+
+        r = sd_rtnl_message_close_container(req);
+        if (r < 0) {
+                log_link_error(link, "Could not close IFLA_AF_SPEC container: %s", strerror(-r));
+                return r;
+        }
+
+        r = sd_rtnl_call_async(link->manager->rtnl, req, link_up_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 0;
+}
+
+static int link_down_handler(sd_rtnl *rtnl, sd_rtnl_message *m, void *userdata) {
+        _cleanup_link_unref_ Link *link = userdata;
+        int r;
+
+        assert(link);
+
+        if (IN_SET(link->state, LINK_STATE_FAILED, LINK_STATE_LINGER))
+                return 1;
+
+        r = sd_rtnl_message_get_errno(m);
+        if (r < 0)
+                log_link_warning_errno(link, -r, "%-*s: could not bring down interface: %m", IFNAMSIZ, link->ifname);
+
+        return 1;
+}
+
+static int link_down(Link *link) {
+        _cleanup_rtnl_message_unref_ sd_rtnl_message *req = NULL;
+        int r;
+
+        assert(link);
+        assert(link->manager);
+        assert(link->manager->rtnl);
+
+        log_link_debug(link, "bringing link down");
+
+        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_flags(req, 0, IFF_UP);
+        if (r < 0) {
+                log_link_error(link, "Could not set link flags: %s",
+                               strerror(-r));
+                return r;
+        }
+
+        r = sd_rtnl_call_async(link->manager->rtnl, req, link_down_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 0;
+}
+
+static int link_handle_bound_to_list(Link *link) {
+        Link *l;
+        Iterator i;
+        int r;
+        bool required_up = false;
+        bool link_is_up = false;
+
+        assert(link);
+
+        if (hashmap_isempty(link->bound_to_links))
+                return 0;
+
+        if (link->flags & IFF_UP)
+                link_is_up = true;
+
+        HASHMAP_FOREACH (l, link->bound_to_links, i)
+                if (link_has_carrier(l)) {
+                        required_up = true;
+                        break;
+                }
+
+        if (!required_up && link_is_up) {
+                r = link_down(link);
+                if (r < 0)
+                        return r;
+        } else if (required_up && !link_is_up) {
+                r = link_up(link);
+                if (r < 0)
+                        return r;
+        }
+
+        return 0;
+}
+
+static int link_handle_bound_by_list(Link *link) {
+        Iterator i;
+        Link *l;
+        int r;
+
+        assert(link);
+
+        if (hashmap_isempty(link->bound_by_links))
+                return 0;
+
+        HASHMAP_FOREACH (l, link->bound_by_links, i) {
+                r = link_handle_bound_to_list(l);
+                if (r < 0)
+                        return r;
+        }
+
+        return 0;
+}
+
+static int link_put_carrier(Link *link, Link *carrier, Hashmap **h) {
+        int r;
+
+        assert(link);
+        assert(carrier);
+
+        if (link == carrier)
+                return 0;
+
+        if (hashmap_get(*h, INT_TO_PTR(carrier->ifindex)))
+                return 0;
+
+        r = hashmap_ensure_allocated(h, NULL);
+        if (r < 0)
+                return r;
+
+        r = hashmap_put(*h, INT_TO_PTR(carrier->ifindex), carrier);
+        if (r < 0)
+                return r;
+
+        return 0;
+}
+
+static int link_new_bound_by_list(Link *link) {
+        Manager *m;
+        Link *carrier;
+        Iterator i;
+        int r;
+        bool list_updated = false;
+
+        assert(link);
+        assert(link->manager);
+
+        m = link->manager;
+
+        HASHMAP_FOREACH (carrier, m->links, i) {
+                if (!carrier->network)
+                        continue;
+
+                if (strv_isempty(carrier->network->bind_carrier))
+                        continue;
+
+                if (strv_fnmatch(carrier->network->bind_carrier, link->ifname, 0)) {
+                        r = link_put_carrier(link, carrier, &link->bound_by_links);
+                        if (r < 0)
+                                return r;
+
+                        list_updated = true;
+                }
+        }
+
+        if (list_updated)
+                link_save(link);
+
+        HASHMAP_FOREACH (carrier, link->bound_by_links, i) {
+                r = link_put_carrier(carrier, link, &carrier->bound_to_links);
+                if (r < 0)
+                        return r;
+
+                link_save(carrier);
+        }
+
+        return 0;
+}
+
+static int link_new_bound_to_list(Link *link) {
+        Manager *m;
+        Link *carrier;
+        Iterator i;
+        int r;
+        bool list_updated = false;
+
+        assert(link);
+        assert(link->manager);
+
+        if (!link->network)
+                return 0;
+
+        if (strv_isempty(link->network->bind_carrier))
+                return 0;
+
+        m = link->manager;
+
+        HASHMAP_FOREACH (carrier, m->links, i) {
+                if (strv_fnmatch(link->network->bind_carrier, carrier->ifname, 0)) {
+                        r = link_put_carrier(link, carrier, &link->bound_to_links);
+                        if (r < 0)
+                                return r;
+
+                        list_updated = true;
+                }
+        }
+
+        if (list_updated)
+                link_save(link);
+
+        HASHMAP_FOREACH (carrier, link->bound_to_links, i) {
+                r = link_put_carrier(carrier, link, &carrier->bound_by_links);
+                if (r < 0)
+                        return r;
+
+                link_save(carrier);
+        }
+
+        return 0;
+}
+
+static int link_new_carrier_maps(Link *link) {
+        int r;
+
+        r = link_new_bound_by_list(link);
+        if (r < 0)
+                return r;
+
+        r = link_handle_bound_by_list(link);
+        if (r < 0)
+                return r;
+
+        r = link_new_bound_to_list(link);
+        if (r < 0)
+                return r;
+
+        r = link_handle_bound_to_list(link);
+        if (r < 0)
+                return r;
+
         return 0;
 }
 
-bool link_has_carrier(Link *link) {
-        /* see Documentation/networking/operstates.txt in the kernel sources */
+static void link_free_bound_to_list(Link *link) {
+        Link *bound_to;
+        Iterator i;
 
-        if (link->kernel_operstate == IF_OPER_UP)
-                return true;
+        HASHMAP_FOREACH (bound_to, link->bound_to_links, i) {
+                hashmap_remove(link->bound_to_links, INT_TO_PTR(bound_to->ifindex));
 
-        if (link->kernel_operstate == IF_OPER_UNKNOWN)
-                /* operstate may not be implemented, so fall back to flags */
-                if ((link->flags & IFF_LOWER_UP) && !(link->flags & IFF_DORMANT))
-                        return true;
+                if (hashmap_remove(bound_to->bound_by_links, INT_TO_PTR(link->ifindex)))
+                        link_save(bound_to);
+        }
 
-        return false;
+        return;
 }
 
-static int link_up_handler(sd_rtnl *rtnl, sd_rtnl_message *m, void *userdata) {
-        _cleanup_link_unref_ Link *link = userdata;
-        int r;
-
-        assert(link);
+static void link_free_bound_by_list(Link *link) {
+        Link *bound_by;
+        Iterator i;
 
-        if (IN_SET(link->state, LINK_STATE_FAILED, LINK_STATE_LINGER))
-                return 1;
+        HASHMAP_FOREACH (bound_by, link->bound_by_links, i) {
+                hashmap_remove(link->bound_by_links, INT_TO_PTR(bound_by->ifindex));
 
-        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",
-                                IFNAMSIZ,
-                                link->ifname, strerror(-r),
-                                "ERRNO=%d", -r,
-                                NULL);
+                if (hashmap_remove(bound_by->bound_to_links, INT_TO_PTR(link->ifindex))) {
+                        link_save(bound_by);
+                        link_handle_bound_to_list(bound_by);
+                }
         }
 
-        return 1;
+        return;
 }
 
-static int link_up(Link *link) {
-        _cleanup_rtnl_message_unref_ sd_rtnl_message *req = NULL;
-        int r;
+static void link_free_carrier_maps(Link *link) {
+        bool list_updated = false;
 
         assert(link);
-        assert(link->manager);
-        assert(link->manager->rtnl);
-
-        log_debug_link(link, "bringing link up");
 
-        r = sd_rtnl_message_new_link(link->manager->rtnl, &req,
-                                     RTM_SETLINK, link->ifindex);
-        if (r < 0) {
-                log_error_link(link, "Could not allocate RTM_SETLINK message");
-                return r;
+        if (!hashmap_isempty(link->bound_to_links)) {
+                link_free_bound_to_list(link);
+                list_updated = true;
         }
 
-        r = sd_rtnl_message_link_set_flags(req, IFF_UP, IFF_UP);
-        if (r < 0) {
-                log_error_link(link, "Could not set link flags: %s",
-                               strerror(-r));
-                return r;
+        if (!hashmap_isempty(link->bound_by_links)) {
+                link_free_bound_by_list(link);
+                list_updated = true;
         }
 
-        r = sd_rtnl_call_async(link->manager->rtnl, req, link_up_handler, link,
-                               0, NULL);
-        if (r < 0) {
-                log_error_link(link,
-                               "Could not send rtnetlink message: %s",
-                               strerror(-r));
-                return r;
-        }
+        if (list_updated)
+                link_save(link);
 
-        link_ref(link);
+        return;
+}
 
-        return 0;
+void link_drop(Link *link) {
+        if (!link || link->state == LINK_STATE_LINGER)
+                return;
+
+        link_set_state(link, LINK_STATE_LINGER);
+
+        link_free_carrier_maps(link);
+
+        log_link_debug(link, "link removed");
+
+        link_unref(link);
+
+        return;
 }
 
 static int link_joined(Link *link) {
@@ -1058,7 +1453,11 @@ static int link_joined(Link *link) {
         assert(link);
         assert(link->network);
 
-        if (!(link->flags & IFF_UP)) {
+        if (!hashmap_isempty(link->bound_to_links)) {
+                r = link_handle_bound_to_list(link);
+                if (r < 0)
+                        return r;
+        } else if (!(link->flags & IFF_UP)) {
                 r = link_up(link);
                 if (r < 0) {
                         link_enter_failed(link);
@@ -1066,6 +1465,15 @@ static int link_joined(Link *link) {
                 }
         }
 
+        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);
 }
 
@@ -1084,16 +1492,11 @@ static int netdev_join_handler(sd_rtnl *rtnl, sd_rtnl_message *m,
 
         r = sd_rtnl_message_get_errno(m);
         if (r < 0 && r != -EEXIST) {
-                log_struct_link(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
-                log_debug_link(link, "joined netdev");
+                log_link_debug(link, "joined netdev");
 
         if (link->enslaving <= 0)
                 link_joined(link);
@@ -1110,7 +1513,7 @@ static int link_enter_join_netdev(Link *link) {
         assert(link->network);
         assert(link->state == LINK_STATE_PENDING);
 
-        link->state = LINK_STATE_ENSLAVING;
+        link_set_state(link, LINK_STATE_ENSLAVING);
 
         link_save(link);
 
@@ -1120,7 +1523,7 @@ static int link_enter_join_netdev(Link *link) {
                 return link_joined(link);
 
         if (link->network->bond) {
-                log_struct_link(LOG_DEBUG, link,
+                log_link_struct(link, LOG_DEBUG,
                                 "MESSAGE=%-*s: enslaving by '%s'",
                                 IFNAMSIZ,
                                 link->ifname, link->network->bond->ifname,
@@ -1129,7 +1532,7 @@ static int link_enter_join_netdev(Link *link) {
 
                 r = netdev_join(link->network->bond, link, &netdev_join_handler);
                 if (r < 0) {
-                        log_struct_link(LOG_WARNING, link,
+                        log_link_struct(link, LOG_WARNING,
                                         "MESSAGE=%-*s: could not join netdev '%s': %s",
                                         IFNAMSIZ,
                                         link->ifname, link->network->bond->ifname,
@@ -1144,7 +1547,7 @@ static int link_enter_join_netdev(Link *link) {
         }
 
         if (link->network->bridge) {
-                log_struct_link(LOG_DEBUG, link,
+                log_link_struct(link, LOG_DEBUG,
                                 "MESSAGE=%-*s: enslaving by '%s'",
                                 IFNAMSIZ,
                                 link->ifname, link->network->bridge->ifname,
@@ -1154,7 +1557,7 @@ static int link_enter_join_netdev(Link *link) {
                 r = netdev_join(link->network->bridge, link,
                                 &netdev_join_handler);
                 if (r < 0) {
-                        log_struct_link(LOG_WARNING, link,
+                        log_link_struct(link, LOG_WARNING,
                                         "MESSAGE=%-*s: could not join netdev '%s': %s",
                                         IFNAMSIZ,
                                         link->ifname, link->network->bridge->ifname,
@@ -1169,7 +1572,7 @@ static int link_enter_join_netdev(Link *link) {
         }
 
         HASHMAP_FOREACH(netdev, link->network->stacked_netdevs, i) {
-                log_struct_link(LOG_DEBUG, link,
+                log_link_struct(link, LOG_DEBUG,
                                 "MESSAGE=%-*s: enslaving by '%s'",
                                 IFNAMSIZ,
                                 link->ifname, netdev->ifname, NETDEVIF(netdev),
@@ -1177,7 +1580,7 @@ static int link_enter_join_netdev(Link *link) {
 
                 r = netdev_join(netdev, link, &netdev_join_handler);
                 if (r < 0) {
-                        log_struct_link(LOG_WARNING, link,
+                        log_link_struct(link, LOG_WARNING,
                                         "MESSAGE=%-*s: could not join netdev '%s': %s",
                                         IFNAMSIZ,
                                         link->ifname, netdev->ifname,
@@ -1193,6 +1596,56 @@ static int link_enter_join_netdev(Link *link) {
         return 0;
 }
 
+static int link_set_ipv4_forward(Link *link) {
+        const char *p = NULL;
+        bool b;
+        int r;
+
+        b = link_ipv4_forward_enabled(link);
+
+        p = strjoina("/proc/sys/net/ipv4/conf/", link->ifname, "/forwarding");
+        r = write_string_file_no_create(p, one_zero(b));
+        if (r < 0)
+                log_link_warning_errno(link, r, "Cannot configure IPv4 forwarding for interface %s: %m", link->ifname);
+
+        if (b) {
+                _cleanup_free_ char *buf = NULL;
+
+                /* If IP forwarding is turned on for this interface,
+                 * then propagate this to the global setting. Given
+                 * that turning this on has side-effects on other
+                 * fields, we'll try to avoid doing this unless
+                 * necessary, hence check the previous value
+                 * first. Note that we never turn this option off
+                 * again, since all interfaces we manage do not do
+                 * forwarding anyway by default, and ownership rules
+                 * of this control are so unclear. */
+
+                r = read_one_line_file("/proc/sys/net/ipv4/ip_forward", &buf);
+                if (r < 0)
+                        log_link_warning_errno(link, r, "Cannot read /proc/sys/net/ipv4/ip_forward: %m");
+                else if (!streq(buf, "1")) {
+                        r = write_string_file_no_create("/proc/sys/net/ipv4/ip_forward", "1");
+                        if (r < 0)
+                                log_link_warning_errno(link, r, "Cannot write /proc/sys/net/ipv4/ip_forward: %m");
+                }
+        }
+
+        return 0;
+}
+
+static int link_set_ipv6_forward(Link *link) {
+        const char *p = NULL;
+        int r;
+
+        p = strjoina("/proc/sys/net/ipv6/conf/", link->ifname, "/forwarding");
+        r = write_string_file_no_create(p, one_zero(link_ipv6_forward_enabled(link)));
+        if (r < 0)
+                log_link_warning_errno(link, r, "Cannot configure IPv6 forwarding for interface: %m");
+
+        return 0;
+}
+
 static int link_configure(Link *link) {
         int r;
 
@@ -1200,6 +1653,18 @@ static int link_configure(Link *link) {
         assert(link->network);
         assert(link->state == LINK_STATE_PENDING);
 
+        r = link_set_bridge_fdb(link);
+        if (r < 0)
+                return r;
+
+        r = link_set_ipv4_forward(link);
+        if (r < 0)
+                return r;
+
+        r = link_set_ipv6_forward(link);
+        if (r < 0)
+                return r;
+
         if (link_ipv4ll_enabled(link)) {
                 r = ipv4ll_configure(link);
                 if (r < 0)
@@ -1223,27 +1688,22 @@ static int link_configure(Link *link) {
         }
 
         if (link_dhcp6_enabled(link)) {
-                r = sd_icmp6_nd_new(&link->icmp6_router_discovery);
-                if (r < 0)
-                        return r;
-
-                r = sd_icmp6_nd_attach_event(link->icmp6_router_discovery,
-                                             NULL, 0);
+                r = icmp6_configure(link);
                 if (r < 0)
                         return r;
+        }
 
-                r = sd_icmp6_nd_set_mac(link->icmp6_router_discovery,
-                                        &link->mac);
+        if (link_lldp_enabled(link)) {
+                r = sd_lldp_new(link->ifindex, link->ifname, &link->mac, &link->lldp);
                 if (r < 0)
                         return r;
 
-                r = sd_icmp6_nd_set_index(link->icmp6_router_discovery,
-                                          link->ifindex);
+                r = sd_lldp_attach_event(link->lldp, NULL, 0);
                 if (r < 0)
                         return r;
 
-                r = sd_icmp6_nd_set_callback(link->icmp6_router_discovery,
-                                             icmp6_router_handler, link);
+                r = sd_lldp_set_callback(link->lldp,
+                                         lldp_handler, link);
                 if (r < 0)
                         return r;
         }
@@ -1270,7 +1730,15 @@ static int link_initialized_and_synced(sd_rtnl *rtnl, sd_rtnl_message *m,
         if (link->state != LINK_STATE_PENDING)
                 return 1;
 
-        log_debug_link(link, "link state is up-to-date");
+        log_link_debug(link, "link state is up-to-date");
+
+        r = link_new_bound_by_list(link);
+        if (r < 0)
+                return r;
+
+        r = link_handle_bound_by_list(link);
+        if (r < 0)
+                return r;
 
         r = network_get(link->manager, link->udev_device, link->ifname,
                         &link->mac, &network);
@@ -1281,20 +1749,24 @@ static int link_initialized_and_synced(sd_rtnl *rtnl, sd_rtnl_message *m,
                 return r;
 
         if (link->flags & IFF_LOOPBACK) {
-                if (network->ipv4ll)
-                        log_debug_link(link, "ignoring IPv4LL for loopback link");
+                if (network->link_local != ADDRESS_FAMILY_NO)
+                        log_link_debug(link, "ignoring link-local autoconfiguration for loopback link");
 
-                if (network->dhcp != DHCP_SUPPORT_NONE)
-                        log_debug_link(link, "ignoring DHCP clients for loopback link");
+                if (network->dhcp != ADDRESS_FAMILY_NO)
+                        log_link_debug(link, "ignoring DHCP clients for loopback link");
 
                 if (network->dhcp_server)
-                        log_debug_link(link, "ignoring DHCP server for loopback link");
+                        log_link_debug(link, "ignoring DHCP server for loopback link");
         }
 
         r = network_apply(link->manager, network, link);
         if (r < 0)
                 return r;
 
+        r = link_new_bound_to_list(link);
+        if (r < 0)
+                return r;
+
         r = link_configure(link);
         if (r < 0)
                 return r;
@@ -1317,7 +1789,7 @@ int link_initialized(Link *link, struct udev_device *device) {
         if (link->udev_device)
                 return 0;
 
-        log_debug_link(link, "udev initialized link");
+        log_link_debug(link, "udev initialized link");
 
         link->udev_device = udev_device_ref(device);
 
@@ -1341,23 +1813,42 @@ int link_initialized(Link *link, struct udev_device *device) {
         return 0;
 }
 
-int link_rtnl_process_address(sd_rtnl *rtnl, sd_rtnl_message *message,
-                              void *userdata) {
+static Address* link_get_equal_address(Link *link, Address *needle) {
+        Address *i;
+
+        assert(link);
+        assert(needle);
+
+        LIST_FOREACH(addresses, i, link->addresses)
+                if (address_equal(i, needle))
+                        return i;
+
+        return NULL;
+}
+
+int link_rtnl_process_address(sd_rtnl *rtnl, sd_rtnl_message *message, void *userdata) {
         Manager *m = userdata;
         Link *link = NULL;
         uint16_t type;
         _cleanup_address_free_ Address *address = NULL;
-        Address *ad;
-        char buf[INET6_ADDRSTRLEN];
-        char valid_buf[FORMAT_TIMESPAN_MAX];
+        unsigned char flags;
+        Address *existing;
+        char buf[INET6_ADDRSTRLEN], valid_buf[FORMAT_TIMESPAN_MAX];
         const char *valid_str = NULL;
-        bool address_dropped = false;
         int r, ifindex;
 
         assert(rtnl);
         assert(message);
         assert(m);
 
+        if (sd_rtnl_message_is_error(message)) {
+                r = sd_rtnl_message_get_errno(message);
+                if (r < 0)
+                        log_warning_errno(r, "rtnl: failed to receive address: %m");
+
+                return 0;
+        }
+
         r = sd_rtnl_message_get_type(message, &type);
         if (r < 0) {
                 log_warning("rtnl: could not get message type");
@@ -1365,13 +1856,19 @@ int link_rtnl_process_address(sd_rtnl *rtnl, sd_rtnl_message *message,
         }
 
         r = sd_rtnl_message_addr_get_ifindex(message, &ifindex);
-        if (r < 0 || ifindex <= 0) {
-                log_warning("rtnl: received address message without valid ifindex, ignoring");
+        if (r < 0) {
+                log_warning_errno(r, "rtnl: could not get ifindex: %m");
+                return 0;
+        } else if (ifindex <= 0) {
+                log_warning("rtnl: received address message with invalid ifindex: %d", ifindex);
                 return 0;
         } else {
                 r = link_get(m, ifindex, &link);
                 if (r < 0 || !link) {
-                        log_warning("rtnl: received address for a nonexistent link (%d), ignoring", ifindex);
+                        /* when enumerating we might be out of sync, but we will
+                         * get the address again, so just ignore it */
+                        if (!m->enumerating)
+                                log_warning("rtnl: received address for nonexistent link (%d), ignoring", ifindex);
                         return 0;
                 }
         }
@@ -1382,50 +1879,43 @@ int link_rtnl_process_address(sd_rtnl *rtnl, sd_rtnl_message *message,
 
         r = sd_rtnl_message_addr_get_family(message, &address->family);
         if (r < 0 || !IN_SET(address->family, AF_INET, AF_INET6)) {
-                log_warning_link(link,
-                                 "rtnl: received address with invalid family, ignoring");
+                log_link_warning(link, "rtnl: received address with invalid family, ignoring");
                 return 0;
         }
 
         r = sd_rtnl_message_addr_get_prefixlen(message, &address->prefixlen);
         if (r < 0) {
-                log_warning_link(link,
-                                 "rtnl: received address with invalid prefixlen, ignoring");
+                log_link_warning(link, "rtnl: received address with invalid prefixlen, ignoring");
                 return 0;
         }
 
         r = sd_rtnl_message_addr_get_scope(message, &address->scope);
         if (r < 0) {
-                log_warning_link(link,
-                                 "rtnl: received address with invalid scope, ignoring");
+                log_link_warning(link, "rtnl: received address with invalid scope, ignoring");
                 return 0;
         }
 
-        r = sd_rtnl_message_addr_get_flags(message, &address->flags);
+        r = sd_rtnl_message_addr_get_flags(message, &flags);
         if (r < 0) {
-                log_warning_link(link,
-                                 "rtnl: received address with invalid flags, ignoring");
+                log_link_warning(link, "rtnl: received address with invalid flags, ignoring");
                 return 0;
         }
+        address->flags = flags;
 
         switch (address->family) {
         case AF_INET:
-                r = sd_rtnl_message_read_in_addr(message, IFA_LOCAL,
-                                                 &address->in_addr.in);
+                r = sd_rtnl_message_read_in_addr(message, IFA_LOCAL, &address->in_addr.in);
                 if (r < 0) {
-                        log_warning_link(link,
-                                         "rtnl: received address without valid address, ignoring");
+                        log_link_warning(link, "rtnl: received address without valid address, ignoring");
                         return 0;
                 }
 
                 break;
 
         case AF_INET6:
-                r = sd_rtnl_message_read_in6_addr(message, IFA_ADDRESS,
-                                                  &address->in_addr.in6);
+                r = sd_rtnl_message_read_in6_addr(message, IFA_ADDRESS, &address->in_addr.in6);
                 if (r < 0) {
-                        log_warning_link(link,
-                                         "rtnl: received address without valid address, ignoring");
+                        log_link_warning(link, "rtnl: received address without valid address, ignoring");
                         return 0;
                 }
 
@@ -1435,14 +1925,12 @@ int link_rtnl_process_address(sd_rtnl *rtnl, sd_rtnl_message *message,
                 assert_not_reached("invalid address family");
         }
 
-        if (!inet_ntop(address->family, &address->in_addr, buf,
-                       INET6_ADDRSTRLEN)) {
-                log_warning_link(link, "could not print address");
+        if (!inet_ntop(address->family, &address->in_addr, buf, INET6_ADDRSTRLEN)) {
+                log_link_warning(link, "could not print address");
                 return 0;
         }
 
-        r = sd_rtnl_message_read_cache_info(message, IFA_CACHEINFO,
-                                            &address->cinfo);
+        r = sd_rtnl_message_read_cache_info(message, IFA_CACHEINFO, &address->cinfo);
         if (r >= 0) {
                 if (address->cinfo.ifa_valid == CACHE_INFO_INFINITY_LIFE_TIME)
                         valid_str = "ever";
@@ -1452,43 +1940,40 @@ int link_rtnl_process_address(sd_rtnl *rtnl, sd_rtnl_message *message,
                                                     USEC_PER_SEC);
         }
 
-        LIST_FOREACH(addresses, ad, link->addresses) {
-                if (address_equal(ad, address)) {
-                        LIST_REMOVE(addresses, link->addresses, ad);
+        existing = link_get_equal_address(link, address);
 
-                        address_free(ad);
+        switch (type) {
+        case RTM_NEWADDR:
+                if (existing) {
+                        log_link_debug(link, "Updating address: %s/%u (valid for %s)", buf, address->prefixlen, valid_str);
 
-                        address_dropped = true;
 
-                        break;
-                }
-        }
+                        existing->scope = address->scope;
+                        existing->flags = address->flags;
+                        existing->cinfo = address->cinfo;
 
-        switch (type) {
-        case RTM_NEWADDR:
-                if (!address_dropped)
-                        log_debug_link(link, "added address: %s/%u (valid for %s)",
-                                       buf, address->prefixlen, valid_str);
-                else
-                        log_debug_link(link, "updated address: %s/%u (valid for %s)",
-                                       buf, address->prefixlen, valid_str);
+                } else {
+                        log_link_debug(link, "Adding address: %s/%u (valid for %s)", buf, address->prefixlen, valid_str);
 
-                LIST_PREPEND(addresses, link->addresses, address);
-                address = NULL;
+                        LIST_PREPEND(addresses, link->addresses, address);
+                        address_establish(address, link);
 
-                link_save(link);
+                        address = NULL;
+
+                        link_save(link);
+                }
 
                 break;
+
         case RTM_DELADDR:
-                if (address_dropped) {
-                        log_debug_link(link, "removed address: %s/%u (valid for %s)",
-                                       buf, address->prefixlen, valid_str);
 
-                        link_save(link);
+                if (existing) {
+                        log_link_debug(link, "Removing address: %s/%u (valid for %s)", buf, address->prefixlen, valid_str);
+                        address_release(existing, link);
+                        LIST_REMOVE(addresses, link->addresses, existing);
+                        address_free(existing);
                 } else
-                        log_warning_link(link,
-                                         "removing non-existent address: %s/%u (valid for %s)",
-                                         buf, address->prefixlen, valid_str);
+                        log_link_warning(link, "Removing non-existent address: %s/%u (valid for %s)", buf, address->prefixlen, valid_str);
 
                 break;
         default:
@@ -1500,7 +1985,6 @@ int link_rtnl_process_address(sd_rtnl *rtnl, sd_rtnl_message *message,
 
 int link_add(Manager *m, sd_rtnl_message *message, Link **ret) {
         Link *link;
-        _cleanup_rtnl_message_unref_ sd_rtnl_message *req = NULL;
         _cleanup_udev_device_unref_ struct udev_device *device = NULL;
         char ifindex_str[2 + DECIMAL_STR_MAX(int)];
         int r;
@@ -1516,33 +2000,21 @@ int link_add(Manager *m, sd_rtnl_message *message, Link **ret) {
 
         link = *ret;
 
-        log_debug_link(link, "link %d added", link->ifindex);
-
-        r = sd_rtnl_message_new_addr(m->rtnl, &req, RTM_GETADDR, link->ifindex,
-                                     0);
-        if (r < 0)
-                return r;
-
-        r = sd_rtnl_call_async(m->rtnl, req, link_get_address_handler, link, 0,
-                               NULL);
-        if (r < 0)
-                return r;
-
-        link_ref(link);
+        log_link_debug(link, "link %d added", link->ifindex);
 
         if (detect_container(NULL) <= 0) {
                 /* not in a container, udev will be around */
                 sprintf(ifindex_str, "n%d", link->ifindex);
                 device = udev_device_new_from_device_id(m->udev, ifindex_str);
                 if (!device) {
-                        log_warning_link(link,
+                        log_link_warning(link,
                                          "could not find udev device: %m");
                         return -errno;
                 }
 
                 if (udev_device_get_is_initialized(device) <= 0) {
                         /* not yet ready */
-                        log_debug_link(link, "link pending udev initialization...");
+                        log_link_debug(link, "link pending udev initialization...");
                         return 0;
                 }
 
@@ -1561,6 +2033,65 @@ int link_add(Manager *m, sd_rtnl_message *message, Link **ret) {
         return 0;
 }
 
+static int link_carrier_gained(Link *link) {
+        int r;
+
+        assert(link);
+
+        if (link->network) {
+                r = link_acquire_conf(link);
+                if (r < 0) {
+                        link_enter_failed(link);
+                        return r;
+                }
+        }
+
+        r = link_handle_bound_by_list(link);
+        if (r < 0)
+                return r;
+
+        return 0;
+}
+
+static int link_carrier_lost(Link *link) {
+        int r;
+
+        assert(link);
+
+        r = link_stop_clients(link);
+        if (r < 0) {
+                link_enter_failed(link);
+                return r;
+        }
+
+        r = link_handle_bound_by_list(link);
+        if (r < 0)
+                return r;
+
+        return 0;
+}
+
+int link_carrier_reset(Link *link) {
+        int r;
+
+        assert(link);
+
+        if (link_has_carrier(link)) {
+                r = link_carrier_lost(link);
+                if (r < 0)
+                        return r;
+
+                r = link_carrier_gained(link);
+                if (r < 0)
+                        return r;
+
+                log_link_info(link, "reset carrier");
+        }
+
+        return 0;
+}
+
+
 int link_update(Link *link, sd_rtnl_message *m) {
         struct ether_addr mac;
         const char *ifname;
@@ -1574,18 +2105,28 @@ int link_update(Link *link, sd_rtnl_message *m) {
 
         if (link->state == LINK_STATE_LINGER) {
                 link_ref(link);
-                log_info_link(link, "link readded");
-                link->state = LINK_STATE_ENSLAVING;
+                log_link_info(link, "link readded");
+                link_set_state(link, LINK_STATE_ENSLAVING);
+
+                r = link_new_carrier_maps(link);
+                if (r < 0)
+                        return r;
         }
 
         r = sd_rtnl_message_read_string(m, IFLA_IFNAME, &ifname);
         if (r >= 0 && !streq(ifname, link->ifname)) {
-                log_info_link(link, "renamed to %s", ifname);
+                log_link_info(link, "renamed to %s", ifname);
+
+                link_free_carrier_maps(link);
 
                 free(link->ifname);
                 link->ifname = strdup(ifname);
                 if (!link->ifname)
                         return -ENOMEM;
+
+                r = link_new_carrier_maps(link);
+                if (r < 0)
+                        return r;
         }
 
         r = sd_rtnl_message_read_u32(m, IFLA_MTU, &mtu);
@@ -1593,7 +2134,7 @@ int link_update(Link *link, sd_rtnl_message *m) {
                 link->mtu = mtu;
                 if (!link->original_mtu) {
                         link->original_mtu = mtu;
-                        log_debug_link(link, "saved original MTU: %"
+                        log_link_debug(link, "saved original MTU: %"
                                        PRIu32, link->original_mtu);
                 }
 
@@ -1601,7 +2142,7 @@ int link_update(Link *link, sd_rtnl_message *m) {
                         r = sd_dhcp_client_set_mtu(link->dhcp_client,
                                                    link->mtu);
                         if (r < 0) {
-                                log_warning_link(link,
+                                log_link_warning(link,
                                                  "Could not update MTU in DHCP client: %s",
                                                  strerror(-r));
                                 return r;
@@ -1619,7 +2160,7 @@ int link_update(Link *link, sd_rtnl_message *m) {
                         memcpy(link->mac.ether_addr_octet, mac.ether_addr_octet,
                                ETH_ALEN);
 
-                        log_debug_link(link, "MAC address: "
+                        log_link_debug(link, "MAC address: "
                                        "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx",
                                        mac.ether_addr_octet[0],
                                        mac.ether_addr_octet[1],
@@ -1631,7 +2172,7 @@ int link_update(Link *link, sd_rtnl_message *m) {
                         if (link->ipv4ll) {
                                 r = sd_ipv4ll_set_mac(link->ipv4ll, &link->mac);
                                 if (r < 0) {
-                                        log_warning_link(link,
+                                        log_link_warning(link,
                                                          "Could not update MAC address in IPv4LL client: %s",
                                                          strerror(-r));
                                         return r;
@@ -1644,7 +2185,7 @@ int link_update(Link *link, sd_rtnl_message *m) {
                                                            sizeof (link->mac),
                                                            ARPHRD_ETHER);
                                 if (r < 0) {
-                                        log_warning_link(link,
+                                        log_link_warning(link,
                                                          "Could not update MAC address in DHCP client: %s",
                                                          strerror(-r));
                                         return r;
@@ -1657,7 +2198,7 @@ int link_update(Link *link, sd_rtnl_message *m) {
                                                             sizeof (link->mac),
                                                             ARPHRD_ETHER);
                                 if (r < 0) {
-                                        log_warning_link(link,
+                                        log_link_warning(link,
                                                          "Could not update MAC address in DHCPv6 client: %s",
                                                          strerror(-r));
                                         return r;
@@ -1676,34 +2217,29 @@ int link_update(Link *link, sd_rtnl_message *m) {
         carrier_lost = had_carrier && !link_has_carrier(link);
 
         if (carrier_gained) {
-                log_info_link(link, "gained carrier");
+                log_link_info(link, "gained carrier");
 
-                if (link->network) {
-                        r = link_acquire_conf(link);
-                        if (r < 0) {
-                                link_enter_failed(link);
-                                return r;
-                        }
-                }
+                r = link_carrier_gained(link);
+                if (r < 0)
+                        return r;
         } else if (carrier_lost) {
-                log_info_link(link, "lost carrier");
+                log_link_info(link, "lost carrier");
 
-                r = link_stop_clients(link);
-                if (r < 0) {
-                        link_enter_failed(link);
+                r = link_carrier_lost(link);
+                if (r < 0)
                         return r;
-                }
+
         }
 
         return 0;
 }
 
 static void link_update_operstate(Link *link) {
-
+        LinkOperationalState operstate;
         assert(link);
 
         if (link->kernel_operstate == IF_OPER_DORMANT)
-                link->operstate = LINK_OPERSTATE_DORMANT;
+                operstate = LINK_OPERSTATE_DORMANT;
         else if (link_has_carrier(link)) {
                 Address *address;
                 uint8_t scope = RT_SCOPE_NOWHERE;
@@ -1719,17 +2255,22 @@ static void link_update_operstate(Link *link) {
 
                 if (scope < RT_SCOPE_SITE)
                         /* universally accessible addresses found */
-                        link->operstate = LINK_OPERSTATE_ROUTABLE;
+                        operstate = LINK_OPERSTATE_ROUTABLE;
                 else if (scope < RT_SCOPE_HOST)
                         /* only link or site local addresses found */
-                        link->operstate = LINK_OPERSTATE_DEGRADED;
+                        operstate = LINK_OPERSTATE_DEGRADED;
                 else
                         /* no useful addresses found */
-                        link->operstate = LINK_OPERSTATE_CARRIER;
+                        operstate = LINK_OPERSTATE_CARRIER;
         } else if (link->flags & IFF_UP)
-                link->operstate = LINK_OPERSTATE_NO_CARRIER;
+                operstate = LINK_OPERSTATE_NO_CARRIER;
         else
-                link->operstate = LINK_OPERSTATE_OFF;
+                operstate = LINK_OPERSTATE_OFF;
+
+        if (link->operstate != operstate) {
+                link->operstate = operstate;
+                link_send_changed(link, "OperationalState", NULL);
+        }
 }
 
 int link_save(Link *link) {
@@ -1854,10 +2395,43 @@ int link_save(Link *link) {
                         llmnr_support_to_string(link->network->llmnr));
         }
 
+        if (!hashmap_isempty(link->bound_to_links)) {
+                Link *carrier;
+                Iterator i;
+                bool space = false;
+
+                fputs("CARRIER_BOUND_TO=", f);
+                HASHMAP_FOREACH(carrier, link->bound_to_links, i) {
+                        if (space)
+                                fputc(' ', f);
+                        fputs(carrier->ifname, f);
+                        space = true;
+                }
+
+                fputs("\n", f);
+        }
+
+        if (!hashmap_isempty(link->bound_by_links)) {
+                Link *carrier;
+                Iterator i;
+                bool space = false;
+
+                fputs("CARRIER_BOUND_BY=", f);
+                space = false;
+                HASHMAP_FOREACH(carrier, link->bound_by_links, i) {
+                        if (space)
+                                fputc(' ', f);
+                        fputs(carrier->ifname, f);
+                        space = true;
+                }
+
+                fputs("\n", f);
+        }
+
         if (link->dhcp_lease) {
                 assert(link->network);
 
-                r = dhcp_lease_save(link->dhcp_lease, link->lease_file);
+                r = sd_dhcp_lease_save(link->dhcp_lease, link->lease_file);
                 if (r < 0)
                         goto fail;
 
@@ -1867,6 +2441,19 @@ int link_save(Link *link) {
         } else
                 unlink(link->lease_file);
 
+        if (link->lldp) {
+                assert(link->network);
+
+                r = sd_lldp_save(link->lldp, link->lldp_file);
+                if (r < 0)
+                        goto fail;
+
+                fprintf(f,
+                        "LLDP_FILE=%s\n",
+                        link->lldp_file);
+        } else
+                unlink(link->lldp_file);
+
         r = fflush_and_check(f);
         if (r < 0)
                 goto fail;
@@ -1878,7 +2465,7 @@ int link_save(Link *link) {
 
         return 0;
 fail:
-        log_error_link(link, "Failed to save link data to %s: %s", link->state_file, strerror(-r));
+        log_link_error(link, "Failed to save link data to %s: %s", link->state_file, strerror(-r));
         unlink(link->state_file);
         unlink(temp_path);
         return r;