[systemd-devel] [PATCH] Add FDB support
Signed-off-by: Alin Rauta --- Makefile.am | 1 + man/systemd.network.xml | 31 +++ src/libsystemd/sd-rtnl/rtnl-message.c| 56 - src/libsystemd/sd-rtnl/rtnl-types.c | 15 +- src/network/networkd-fdb.c | 357 +++ src/network/networkd-link.c | 37 src/network/networkd-network-gperf.gperf | 3 + src/network/networkd-network.c | 13 ++ src/network/networkd.h | 32 +++ src/systemd/sd-rtnl.h| 4 + 10 files changed, 539 insertions(+), 10 deletions(-) create mode 100644 src/network/networkd-fdb.c diff --git a/Makefile.am b/Makefile.am index 6f02c74..02dd273 100644 --- a/Makefile.am +++ b/Makefile.am @@ -5252,6 +5252,7 @@ libsystemd_networkd_core_la_SOURCES = \ src/network/networkd-address.c \ src/network/networkd-route.c \ src/network/networkd-manager.c \ + src/network/networkd-fdb.c \ src/network/networkd-address-pool.c nodist_libsystemd_networkd_core_la_SOURCES = \ diff --git a/man/systemd.network.xml b/man/systemd.network.xml index 1edaa0b..9d44641 100644 --- a/man/systemd.network.xml +++ b/man/systemd.network.xml @@ -249,6 +249,15 @@ + FDBControlled= + +A boolean. When true, deletes existing FDB entries +and configures those specified in [FDBEntry] section. Defaults +to false. + + + + LLMNR= A boolean or resolve. When true, enables @@ -549,6 +558,28 @@ +[FDBEntry] Section Options +The [FDBEntry] section accepts the following keys. Specify +several [FDBEntry] sections to configure several static MAC table entries. + + + + MACAddress= + +As in the [Network] section. This key is mandatory. + + + +VLAN= + +The VLAN for the new static MAC table entry. +If omitted, no VLAN info is appended to the new static MAC table entry. + + + + + + Example /etc/systemd/network/50-static.network diff --git a/src/libsystemd/sd-rtnl/rtnl-message.c b/src/libsystemd/sd-rtnl/rtnl-message.c index 165e84d..9099440 100644 --- a/src/libsystemd/sd-rtnl/rtnl-message.c +++ b/src/libsystemd/sd-rtnl/rtnl-message.c @@ -220,6 +220,58 @@ int sd_rtnl_message_new_route(sd_rtnl *rtnl, sd_rtnl_message **ret, return 0; } +int sd_rtnl_message_neigh_set_flags(sd_rtnl_message *m, uint8_t flags) { +struct ndmsg *ndm; + +assert_return(m, -EINVAL); +assert_return(m->hdr, -EINVAL); +assert_return(rtnl_message_type_is_neigh(m->hdr->nlmsg_type), -EINVAL); + +ndm = NLMSG_DATA(m->hdr); +ndm->ndm_flags |= flags; + +return 0; +} + +int sd_rtnl_message_neigh_set_state(sd_rtnl_message *m, uint16_t state) { +struct ndmsg *ndm; + +assert_return(m, -EINVAL); +assert_return(m->hdr, -EINVAL); +assert_return(rtnl_message_type_is_neigh(m->hdr->nlmsg_type), -EINVAL); + +ndm = NLMSG_DATA(m->hdr); +ndm->ndm_state |= state; + +return 0; +} + +int sd_rtnl_message_neigh_get_flags(sd_rtnl_message *m, uint8_t *flags) { +struct ndmsg *ndm; + +assert_return(m, -EINVAL); +assert_return(m->hdr, -EINVAL); +assert_return(rtnl_message_type_is_neigh(m->hdr->nlmsg_type), -EINVAL); + +ndm = NLMSG_DATA(m->hdr); +*flags = ndm->ndm_flags; + +return 0; +} + +int sd_rtnl_message_neigh_get_state(sd_rtnl_message *m, uint16_t *state) { +struct ndmsg *ndm; + +assert_return(m, -EINVAL); +assert_return(m->hdr, -EINVAL); +assert_return(rtnl_message_type_is_neigh(m->hdr->nlmsg_type), -EINVAL); + +
[systemd-devel] [PATCH] Add FDB support
Hi, I've added support for handling the forwarding database table for a port. FDB entries can be configured statically through the ".network" files. To resume, - I've added a new boolean for the main network structure, named "FDBControlled" which is read from the .network file and defaults to false. - I've added a new section "FDBEntry" accepting 2 key-value pairs: -MACAddress (mandatory) -VLAN (optional) When FDBControlled is set to "yes" in the network section, networkd: - gets the FDB entries for current port; - clears them - configures those specified in the [FDBEntry] section. Configuration example: [Network] DHCP=v4 FDBControlled=yes [FDBEntry] MACAddress=44:44:12:34:56:71 VLAN=9 [FDBEntry] MACAddress=44:44:12:34:56:72 VLAN=10 Thanks, Alin Alin Rauta (1): Add FDB support Makefile.am | 1 + man/systemd.network.xml | 31 +++ src/libsystemd/sd-rtnl/rtnl-message.c| 56 - src/libsystemd/sd-rtnl/rtnl-types.c | 15 +- src/network/networkd-fdb.c | 357 +++ src/network/networkd-link.c | 37 src/network/networkd-network-gperf.gperf | 3 + src/network/networkd-network.c | 13 ++ src/network/networkd.h | 32 +++ src/systemd/sd-rtnl.h| 4 + 10 files changed, 539 insertions(+), 10 deletions(-) create mode 100644 src/network/networkd-fdb.c -- 1.9.3 ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
[systemd-devel] [PATCH v2] Add FDB support
Hi, Based on your feedback, I've created a new patch for adding the FDB support. networkd takes ownership of the FDB table. Configuration example: > cat /etc/systemd/network/em1.network [Match] Name=em1 [Network] DHCP=v4 [BridgeFDB] MACAddress=04:44:12:34:56:70 VLAN=2 [BridgeFDB] MACAddress=04:44:12:34:56:69 VLAN=3 Let me know what you think. Thanks, Alin Alin Rauta (1): Add FDB support Makefile.am | 1 + man/systemd.network.xml | 22 ++ src/libsystemd/sd-rtnl/rtnl-message.c| 56 - src/libsystemd/sd-rtnl/rtnl-types.c | 15 +- src/network/networkd-fdb.c | 357 +++ src/network/networkd-link.c | 25 +++ src/network/networkd-network-gperf.gperf | 2 + src/network/networkd-network.c | 13 +- src/network/networkd.h | 30 +++ src/systemd/sd-rtnl.h| 4 + 10 files changed, 514 insertions(+), 11 deletions(-) create mode 100644 src/network/networkd-fdb.c -- 1.9.3 ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
[systemd-devel] [PATCH v2] Add FDB support
Signed-off-by: Alin Rauta --- Makefile.am | 1 + man/systemd.network.xml | 22 ++ src/libsystemd/sd-rtnl/rtnl-message.c| 56 - src/libsystemd/sd-rtnl/rtnl-types.c | 15 +- src/network/networkd-fdb.c | 357 +++ src/network/networkd-link.c | 25 +++ src/network/networkd-network-gperf.gperf | 2 + src/network/networkd-network.c | 13 +- src/network/networkd.h | 30 +++ src/systemd/sd-rtnl.h| 4 + 10 files changed, 514 insertions(+), 11 deletions(-) create mode 100644 src/network/networkd-fdb.c diff --git a/Makefile.am b/Makefile.am index 84b587d..226d298 100644 --- a/Makefile.am +++ b/Makefile.am @@ -5271,6 +5271,7 @@ libsystemd_networkd_core_la_SOURCES = \ src/network/networkd-address.c \ src/network/networkd-route.c \ src/network/networkd-manager.c \ + src/network/networkd-fdb.c \ src/network/networkd-address-pool.c nodist_libsystemd_networkd_core_la_SOURCES = \ diff --git a/man/systemd.network.xml b/man/systemd.network.xml index 79c7a23..39bf385 100644 --- a/man/systemd.network.xml +++ b/man/systemd.network.xml @@ -549,6 +549,28 @@ +[BridgeFDB] Section Options +The [BridgeFDB] section manages the forwarding database table of a port and accepts the following keys. Specify +several [BridgeFDB] sections to configure several static MAC table entries. + + + + MACAddress= + +As in the [Network] section. This key is mandatory. + + + +VLAN= + +The VLAN for the new static MAC table entry. +If omitted, no VLAN info is appended to the new static MAC table entry. + + + + + + Example /etc/systemd/network/50-static.network diff --git a/src/libsystemd/sd-rtnl/rtnl-message.c b/src/libsystemd/sd-rtnl/rtnl-message.c index 165e84d..9099440 100644 --- a/src/libsystemd/sd-rtnl/rtnl-message.c +++ b/src/libsystemd/sd-rtnl/rtnl-message.c @@ -220,6 +220,58 @@ int sd_rtnl_message_new_route(sd_rtnl *rtnl, sd_rtnl_message **ret, return 0; } +int sd_rtnl_message_neigh_set_flags(sd_rtnl_message *m, uint8_t flags) { +struct ndmsg *ndm; + +assert_return(m, -EINVAL); +assert_return(m->hdr, -EINVAL); +assert_return(rtnl_message_type_is_neigh(m->hdr->nlmsg_type), -EINVAL); + +ndm = NLMSG_DATA(m->hdr); +ndm->ndm_flags |= flags; + +return 0; +} + +int sd_rtnl_message_neigh_set_state(sd_rtnl_message *m, uint16_t state) { +struct ndmsg *ndm; + +assert_return(m, -EINVAL); +assert_return(m->hdr, -EINVAL); +assert_return(rtnl_message_type_is_neigh(m->hdr->nlmsg_type), -EINVAL); + +ndm = NLMSG_DATA(m->hdr); +ndm->ndm_state |= state; + +return 0; +} + +int sd_rtnl_message_neigh_get_flags(sd_rtnl_message *m, uint8_t *flags) { +struct ndmsg *ndm; + +assert_return(m, -EINVAL); +assert_return(m->hdr, -EINVAL); +assert_return(rtnl_message_type_is_neigh(m->hdr->nlmsg_type), -EINVAL); + +ndm = NLMSG_DATA(m->hdr); +*flags = ndm->ndm_flags; + +return 0; +} + +int sd_rtnl_message_neigh_get_state(sd_rtnl_message *m, uint16_t *state) { +struct ndmsg *ndm; + +assert_return(m, -EINVAL); +assert_return(m->hdr, -EINVAL); +assert_return(rtnl_message_type_is_neigh(m->hdr->nlmsg_type), -EINVAL); + +ndm = NLMSG_DATA(m->hdr); +*state = ndm->ndm_state; + +return 0; +} + int sd_rtnl_message_neigh_get_family(sd_rtnl_message *m, int *family) { struct ndmsg *ndm; @@ -255,7 +307,9 @@ int sd_rtnl_message_new_neigh(sd_rtnl *rtnl, sd_rtnl_message **ret, uint16_t nlm int r; assert_return(rtnl_message_type_is_neigh(nlmsg_type), -EINVAL); -assert_return(ndm_family == AF_INET || ndm_family == AF_INET6, -EINVAL); +assert_return(ndm_family == AF_INET || + ndm_family == AF_INET6 || + ndm_family == PF_BRIDGE, -EINVAL); assert_return(ret, -EINVAL); r = message_new(rtnl, ret, nlmsg_type); diff --git a/src/libsystemd/sd-rtnl/rtnl-types.c b/src/libsystemd/
[systemd-devel] [PATCH v3] Add FDB support
Hi Tom, I've formatted the patch based on our previous discussions. This one has support only for adding FDB entries. An example configuration is like below: [Match] Name=em1 [Network] DHCP=v4 [BridgeFDB] MACAddress=44:44:12:34:56:71 VLANId=9 [BridgeFDB] MACAddress=44:44:12:34:56:70 VLANId=2 Please let me know what you think. Thanks, Alin Alin Rauta (1): Add FDB support Makefile.am | 1 + man/systemd.network.xml | 22 +++ src/libsystemd/sd-rtnl/rtnl-message.c| 56 ++- src/libsystemd/sd-rtnl/rtnl-types.c | 15 +- src/network/networkd-fdb.c | 252 +++ src/network/networkd-link.c | 19 +++ src/network/networkd-network-gperf.gperf | 2 + src/network/networkd-network.c | 13 +- src/network/networkd.h | 29 src/systemd/sd-rtnl.h| 4 + 10 files changed, 402 insertions(+), 11 deletions(-) create mode 100644 src/network/networkd-fdb.c -- 1.9.3 ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
[systemd-devel] [PATCH v3] Add FDB support
Signed-off-by: Alin Rauta --- Makefile.am | 1 + man/systemd.network.xml | 22 +++ src/libsystemd/sd-rtnl/rtnl-message.c| 56 ++- src/libsystemd/sd-rtnl/rtnl-types.c | 15 +- src/network/networkd-fdb.c | 252 +++ src/network/networkd-link.c | 19 +++ src/network/networkd-network-gperf.gperf | 2 + src/network/networkd-network.c | 13 +- src/network/networkd.h | 29 src/systemd/sd-rtnl.h| 4 + 10 files changed, 402 insertions(+), 11 deletions(-) create mode 100644 src/network/networkd-fdb.c diff --git a/Makefile.am b/Makefile.am index ab07d3b..6896c4b 100644 --- a/Makefile.am +++ b/Makefile.am @@ -5281,6 +5281,7 @@ libsystemd_networkd_core_la_SOURCES = \ src/network/networkd-address.c \ src/network/networkd-route.c \ src/network/networkd-manager.c \ + src/network/networkd-fdb.c \ src/network/networkd-address-pool.c nodist_libsystemd_networkd_core_la_SOURCES = \ diff --git a/man/systemd.network.xml b/man/systemd.network.xml index 79c7a23..360c57c 100644 --- a/man/systemd.network.xml +++ b/man/systemd.network.xml @@ -549,6 +549,28 @@ +[BridgeFDB] Section Options +The [BridgeFDB] section manages the forwarding database table of a port and accepts the following keys. Specify +several [BridgeFDB] sections to configure several static MAC table entries. + + + + MACAddress= + +As in the [Network] section. This key is mandatory. + + + +VLANId= + +The VLAN Id for the new static MAC table entry. +If omitted, no VLAN Id info is appended to the new static MAC table entry. + + + + + + Example /etc/systemd/network/50-static.network diff --git a/src/libsystemd/sd-rtnl/rtnl-message.c b/src/libsystemd/sd-rtnl/rtnl-message.c index 165e84d..9099440 100644 --- a/src/libsystemd/sd-rtnl/rtnl-message.c +++ b/src/libsystemd/sd-rtnl/rtnl-message.c @@ -220,6 +220,58 @@ int sd_rtnl_message_new_route(sd_rtnl *rtnl, sd_rtnl_message **ret, return 0; } +int sd_rtnl_message_neigh_set_flags(sd_rtnl_message *m, uint8_t flags) { +struct ndmsg *ndm; + +assert_return(m, -EINVAL); +assert_return(m->hdr, -EINVAL); +assert_return(rtnl_message_type_is_neigh(m->hdr->nlmsg_type), -EINVAL); + +ndm = NLMSG_DATA(m->hdr); +ndm->ndm_flags |= flags; + +return 0; +} + +int sd_rtnl_message_neigh_set_state(sd_rtnl_message *m, uint16_t state) { +struct ndmsg *ndm; + +assert_return(m, -EINVAL); +assert_return(m->hdr, -EINVAL); +assert_return(rtnl_message_type_is_neigh(m->hdr->nlmsg_type), -EINVAL); + +ndm = NLMSG_DATA(m->hdr); +ndm->ndm_state |= state; + +return 0; +} + +int sd_rtnl_message_neigh_get_flags(sd_rtnl_message *m, uint8_t *flags) { +struct ndmsg *ndm; + +assert_return(m, -EINVAL); +assert_return(m->hdr, -EINVAL); +assert_return(rtnl_message_type_is_neigh(m->hdr->nlmsg_type), -EINVAL); + +ndm = NLMSG_DATA(m->hdr); +*flags = ndm->ndm_flags; + +return 0; +} + +int sd_rtnl_message_neigh_get_state(sd_rtnl_message *m, uint16_t *state) { +struct ndmsg *ndm; + +assert_return(m, -EINVAL); +assert_return(m->hdr, -EINVAL); +assert_return(rtnl_message_type_is_neigh(m->hdr->nlmsg_type), -EINVAL); + +ndm = NLMSG_DATA(m->hdr); +*state = ndm->ndm_state; + +return 0; +} + int sd_rtnl_message_neigh_get_family(sd_rtnl_message *m, int *family) { struct ndmsg *ndm; @@ -255,7 +307,9 @@ int sd_rtnl_message_new_neigh(sd_rtnl *rtnl, sd_rtnl_message **ret, uint16_t nlm int r; assert_return(rtnl_message_type_is_neigh(nlmsg_type), -EINVAL); -assert_return(ndm_family == AF_INET || ndm_family == AF_INET6, -EINVAL); +assert_return(ndm_family == AF_INET || + ndm_family == AF_INET6 || + ndm_family == PF_BRIDGE, -EINVAL); assert_return(ret, -EINVAL); r = message_new(rtnl, ret, nlmsg_type); diff --git a/src/libsystemd/sd-rtnl/rtnl-types.c
[systemd-devel] [PATCH] Added Uplink failure detection feature to networkd
--- Makefile.am |4 + man/systemd.netdev.xml | 72 +- src/libsystemd/sd-network/sd-network.c | 117 +++ src/network/networkctl.c| 153 src/network/networkd-link.c | 35 + src/network/networkd-manager.c | 36 + src/network/networkd-netdev-gperf.gperf |3 + src/network/networkd-netdev-ufd-group.c | 298 +++ src/network/networkd-netdev-ufd-group.h | 85 ++ src/network/networkd-netdev.c | 36 + src/network/networkd-netdev.h |6 + src/network/networkd-ufd-daemon.c | 1321 +++ src/network/networkd-ufd-daemon.h | 34 + src/network/networkd.c |7 + src/network/networkd.h |6 + src/systemd/sd-network.h| 20 + 16 files changed, 2231 insertions(+), 2 deletions(-) create mode 100644 src/network/networkd-netdev-ufd-group.c create mode 100644 src/network/networkd-netdev-ufd-group.h create mode 100644 src/network/networkd-ufd-daemon.c create mode 100644 src/network/networkd-ufd-daemon.h diff --git a/Makefile.am b/Makefile.am index 45d7a34..604173b 100644 --- a/Makefile.am +++ b/Makefile.am @@ -5575,6 +5575,8 @@ libsystemd_networkd_core_la_SOURCES = \ src/network/networkd-netdev-tuntap.h \ src/network/networkd-netdev-bond.h \ src/network/networkd-netdev-bridge.h \ + src/network/networkd-netdev-ufd-group.h \ + src/network/networkd-ufd-daemon.h \ src/network/networkd-netdev.c \ src/network/networkd-netdev-tunnel.c \ src/network/networkd-netdev-veth.c \ @@ -5586,6 +5588,8 @@ libsystemd_networkd_core_la_SOURCES = \ src/network/networkd-netdev-tuntap.c \ src/network/networkd-netdev-bond.c \ src/network/networkd-netdev-bridge.c \ + src/network/networkd-netdev-ufd-group.c \ + src/network/networkd-ufd-daemon.c \ src/network/networkd-link.c \ src/network/networkd-ipv4ll.c \ src/network/networkd-dhcp4.c \ diff --git a/man/systemd.netdev.xml b/man/systemd.netdev.xml index 7edec36..3c60441 100644 --- a/man/systemd.netdev.xml +++ b/man/systemd.netdev.xml @@ -168,8 +168,8 @@ ipip, gre, gretap, sit, vti, veth, -tun, tap and -dummy +tun, tap, +ufd and dummy are supported. This option is compulsory. @@ -553,6 +553,52 @@ +[UFDGroup] Section Options + +The [UFDGroup] section is used to define uplink failure detection group parameters. +The section only applies for netdevs of kind ufd, and accepts the following key: + + + + +Id= + +Uplink failure detection group Id. This option is compulsory. + + + + + + +[UFDLink] Section Options + +The [UFDLink] section is used to define one or more uplink failure detection links. +The section only applies for netdevs of kind ufd, and accepts the following key: + + + + +Name= + +An interface name or an enumeration of interface names separated by comma. +This option is compulsory. + + + + +Type= + +A string defining the link(s) type. +It can only take the following string values: uplink +or downlink. This option is compulsory. + + + + + + + + Example /etc/systemd/network/bridge.netdev @@ -645,6 +691,28 @@ Name=veth-peer +/etc/systemd/network/ufd.netdev +
[systemd-devel] [PATCH] Added UFD (Uplink failure detection) support to networkd
Hi, Uplink Failure Detection (UFD) is a key enhancement to networkd, that will provide support for the switch use case. The links can be configured as uplinks or as downlinks inside an UFD group. When all uplinks for a group are down, the failure is propagated to the downlinks, so the devices connected to them can take a defined action. When at least one uplink become available, the daemon tries to bring the downlink ports up. Multiple UFD groups can be configured through ".netdev" files. See below a configuration example: [NetDev] Name=group1 Kind=ufd [UFDGroup] Id=10 [UFDLink] Name=sw0p1,sw0p2 Type=uplink [UFDLink] Name=sw0p3 Type=downlink [UFDLink] Name=sw0p4 Type=downlink Few details on implementation: Networkd waits until all links are enumerated (either static configured or unmanaged). Only then it starts enumerating the groups. "networkctl" command was also updated to support listing of ufd groups & configuration. See below a print-out: # networkctl ufd 10 ? UFD Group: 10 Config File: /etc/systemd/network/ufd_to_test.netdev State: configured Uplinks: ? 3: sw0p1 ? 4: sw0p2 Downlinks: ? 6: sw0p4 ? 5: sw0p3 Please let me know what you think. Thanks, Alin Alin Rauta (1): Added Uplink failure detection feature to networkd Makefile.am |4 + man/systemd.netdev.xml | 72 +- src/libsystemd/sd-network/sd-network.c | 117 +++ src/network/networkctl.c| 153 src/network/networkd-link.c | 35 + src/network/networkd-manager.c | 36 + src/network/networkd-netdev-gperf.gperf |3 + src/network/networkd-netdev-ufd-group.c | 298 +++ src/network/networkd-netdev-ufd-group.h | 85 ++ src/network/networkd-netdev.c | 36 + src/network/networkd-netdev.h |6 + src/network/networkd-ufd-daemon.c | 1321 +++ src/network/networkd-ufd-daemon.h | 34 + src/network/networkd.c |7 + src/network/networkd.h |6 + src/systemd/sd-network.h| 20 + 16 files changed, 2231 insertions(+), 2 deletions(-) create mode 100644 src/network/networkd-netdev-ufd-group.c create mode 100644 src/network/networkd-netdev-ufd-group.h create mode 100644 src/network/networkd-ufd-daemon.c create mode 100644 src/network/networkd-ufd-daemon.h -- 1.9.3 ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
[systemd-devel] [PATCH v2] Added support for Uplink Failure Detection using BindCarrier
Hi, I've added Uplink failure detection support through "BindCarrier=" flag. Please let me know what you think. /Alin Alin Rauta (1): Added support for Uplink Failure Detection using BindCarrier man/systemd.network.xml | 11 ++ src/libsystemd/sd-network/sd-network.c | 4 + src/network/networkctl.c | 212 --- src/network/networkd-link.c | 178 ++ src/network/networkd-link.h | 10 ++ src/network/networkd-manager.c | 7 + src/network/networkd-network-gperf.gperf | 1 + src/network/networkd.h | 2 + src/systemd/sd-network.h | 3 + 9 files changed, 412 insertions(+), 16 deletions(-) -- 1.9.3 ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
[systemd-devel] [PATCH v2] Added support for Uplink Failure Detection using BindCarrier
--- man/systemd.network.xml | 11 ++ src/libsystemd/sd-network/sd-network.c | 4 + src/network/networkctl.c | 212 --- src/network/networkd-link.c | 178 ++ src/network/networkd-link.h | 10 ++ src/network/networkd-manager.c | 7 + src/network/networkd-network-gperf.gperf | 1 + src/network/networkd.h | 2 + src/systemd/sd-network.h | 3 + 9 files changed, 412 insertions(+), 16 deletions(-) diff --git a/man/systemd.network.xml b/man/systemd.network.xml index b8facdc..5f2c328 100644 --- a/man/systemd.network.xml +++ b/man/systemd.network.xml @@ -268,6 +268,17 @@ + BindCarrier= + +A port or a list of ports. When set, controls the +behaviour of the current interface. When all ports in the list +are operational down, the failure is propagated to the current +interface. When at least one port has carrier, the current +interface is brought up. + + + + Address= A static IPv4 or IPv6 address and its prefix length, diff --git a/src/libsystemd/sd-network/sd-network.c b/src/libsystemd/sd-network/sd-network.c index c735cac..b574d19 100644 --- a/src/libsystemd/sd-network/sd-network.c +++ b/src/libsystemd/sd-network/sd-network.c @@ -264,6 +264,10 @@ _public_ int sd_network_link_get_domains(int ifindex, char ***ret) { return network_get_link_strv("DOMAINS", ifindex, ret); } +_public_ int sd_network_link_get_carriers(int ifindex, char ***ret) { +return network_get_link_strv("CARRIERS", ifindex, ret); +} + _public_ int sd_network_link_get_wildcard_domain(int ifindex) { int r; _cleanup_free_ char *p = NULL, *s = NULL; diff --git a/src/network/networkctl.c b/src/network/networkctl.c index aa83f32..fe9248f 100644 --- a/src/network/networkctl.c +++ b/src/network/networkctl.c @@ -22,6 +22,7 @@ #include #include #include +#include #include "sd-network.h" #include "sd-rtnl.h" @@ -393,6 +394,162 @@ static int get_gateway_description( return -ENODATA; } +static bool is_carrier(const char *ifname, + char **carriers) { + char **i; + + STRV_FOREACH(i, carriers) + if (0 == fnmatch(*i, ifname, 0)) + return true; + + return false; +} + +/* get the links that are bound to this port. */ +static int get_downlinks(const char *name, + sd_rtnl_message *m, + LinkInfo **downlinks, + int *down_count) { +_cleanup_free_ LinkInfo *links = NULL; +sd_rtnl_message *i; +size_t size = 0; +size_t c = 0; +int r; + +assert(m); +assert(name); + +*down_count = 0; +*downlinks = NULL; + +for (i = m; i; i = sd_rtnl_message_next(i)) { +_cleanup_strv_free_ char **carriers = NULL; +const char *link_name; +int ifindex; + +r = sd_rtnl_message_link_get_ifindex(i, &ifindex); +if (r < 0) +return r; + +r = sd_rtnl_message_read_string(i, IFLA_IFNAME, &link_name); +if (r < 0) +return r; + +r = sd_network_link_get_carriers(ifindex, &carriers); +if ((-ENODATA == r) || (NULL == carriers)) +continue; + +if (r < 0) { +log_warning("Failed to get carrier list for port: %s", name); +continue; +} + +if (is_carrier(name, carriers)) { + if (!GREEDY_REALLOC(links, size, c+1)) + return -ENOMEM; + + links[c].name = link_name; + c++; +} +} + +*downlinks = links; +*down_count = (int) c; + +links = NULL; + +return 0; +} + +/* get the links to which current port is bound to. */ +static int get_uplinks(int ifindex, + sd_rtnl_message *m, + LinkInfo **uplinks, + int *up_count) { +_cleanup_free_ LinkInfo *links = NULL; +_cleanup_strv_free_ char **carriers = NULL; +sd_rtnl_message *i; +size_t size = 0, c = 0; +int r; + +assert(m); + +*up_count = 0; +*uplinks = NULL; + +/* check if this port has carriers. */ +r = sd_network_link_get_carriers(ifindex, &carriers); +if ((-ENODATA == r) || (NULL == carriers)) +return 0; + +if (r < 0) +return r; + +for (i = m; i; i = sd_rtnl_message_next(i)) { +
[systemd-devel] [PATCH v3] Added support for Uplink Failure Detection using BindCarrier
--- man/systemd.network.xml | 11 ++ src/libsystemd/sd-network/sd-network.c | 4 + src/network/networkctl.c | 211 --- src/network/networkd-link.c | 123 +- src/network/networkd-link.h | 1 + src/network/networkd-manager.c | 7 + src/network/networkd-network-gperf.gperf | 1 + src/network/networkd-network.c | 10 ++ src/network/networkd.h | 2 +- src/systemd/sd-network.h | 3 + 10 files changed, 355 insertions(+), 18 deletions(-) diff --git a/man/systemd.network.xml b/man/systemd.network.xml index 9b3a92d..8b2ca4e 100644 --- a/man/systemd.network.xml +++ b/man/systemd.network.xml @@ -270,6 +270,17 @@ + BindCarrier= + +A port or a list of ports. When set, controls the +behaviour of the current interface. When all ports in the list +are operational down, the failure is propagated to the current +interface. When at least one port has carrier, the current +interface is brought up. + + + + Address= A static IPv4 or IPv6 address and its prefix length, diff --git a/src/libsystemd/sd-network/sd-network.c b/src/libsystemd/sd-network/sd-network.c index c735cac..b574d19 100644 --- a/src/libsystemd/sd-network/sd-network.c +++ b/src/libsystemd/sd-network/sd-network.c @@ -264,6 +264,10 @@ _public_ int sd_network_link_get_domains(int ifindex, char ***ret) { return network_get_link_strv("DOMAINS", ifindex, ret); } +_public_ int sd_network_link_get_carriers(int ifindex, char ***ret) { +return network_get_link_strv("CARRIERS", ifindex, ret); +} + _public_ int sd_network_link_get_wildcard_domain(int ifindex) { int r; _cleanup_free_ char *p = NULL, *s = NULL; diff --git a/src/network/networkctl.c b/src/network/networkctl.c index aa83f32..ffb38e8 100644 --- a/src/network/networkctl.c +++ b/src/network/networkctl.c @@ -22,6 +22,7 @@ #include #include #include +#include #include "sd-network.h" #include "sd-rtnl.h" @@ -393,6 +394,161 @@ static int get_gateway_description( return -ENODATA; } +static bool is_carrier(const char *ifname, + char **carriers) { + char **i; + + STRV_FOREACH(i, carriers) + if (fnmatch(*i, ifname, 0) == 0) + return true; + + return false; +} + +/* get the links that are bound to this port. */ +static int get_downlinks(const char *name, + sd_rtnl_message *m, + LinkInfo **downlinks, + int *down_count) { +_cleanup_free_ LinkInfo *links = NULL; +sd_rtnl_message *i; +size_t size = 0; +size_t c = 0; +int r; + +assert(m); +assert(name); + +*down_count = 0; +*downlinks = NULL; + +for (i = m; i; i = sd_rtnl_message_next(i)) { +_cleanup_strv_free_ char **carriers = NULL; +const char *link_name; +int ifindex; + +r = sd_rtnl_message_link_get_ifindex(i, &ifindex); +if (r < 0) +return r; + +r = sd_rtnl_message_read_string(i, IFLA_IFNAME, &link_name); +if (r < 0) +return r; + +r = sd_network_link_get_carriers(ifindex, &carriers); +if (r == -ENODATA || strv_isempty(carriers)) +continue; + +if (r < 0) { +log_warning("Failed to get carrier list for port: %s", name); +continue; +} + +if (is_carrier(name, carriers)) { + if (!GREEDY_REALLOC(links, size, c+1)) + return -ENOMEM; + + links[c].name = link_name; + c++; +} +} + +*downlinks = links; +*down_count = (int) c; + +links = NULL; + +return 0; +} + +/* get the links to which current port is bound to. */ +static int get_uplinks(int ifindex, + sd_rtnl_message *m, + LinkInfo **uplinks, + int *up_count) { +_cleanup_free_ LinkInfo *links = NULL; +_cleanup_strv_free_ char **carriers = NULL; +sd_rtnl_message *i; +size_t size = 0, c = 0; +int r; + +assert(m); + +*up_count = 0; +*uplinks = NULL; + +/* check if this port has carriers. */ +r = sd_network_link_get_carriers(ifindex, &carriers); +if (r == -ENODATA || strv_isempty(carriers)) +return 0; + +if (r < 0) +return r; + +for (i
[systemd-devel] [PATCH v3] Added support for Uplink Failure Detection using BindCarrier
Hi Zbyszek, Thanks for your review. I've handled your remarks. Let me know what you think. Best Regards, Alin Alin Rauta (1): Added support for Uplink Failure Detection using BindCarrier man/systemd.network.xml | 11 ++ src/libsystemd/sd-network/sd-network.c | 4 + src/network/networkctl.c | 211 --- src/network/networkd-link.c | 123 +- src/network/networkd-link.h | 1 + src/network/networkd-manager.c | 7 + src/network/networkd-network-gperf.gperf | 1 + src/network/networkd-network.c | 10 ++ src/network/networkd.h | 2 +- src/systemd/sd-network.h | 3 + 10 files changed, 355 insertions(+), 18 deletions(-) -- 1.9.3 ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
[systemd-devel] [PATCH v4] Added support for Uplink Failure Detection using BindCarrier
Hi, I've creating patch v4 after addressing your comments. I provided two APIs for networkctl command: 1. int sd_network_link_get_carrier_bound_to(int ifindex, char ***carriers); 2. int sd_network_link_get_carrier_bound_by(int ifindex, char ***carriers); This way, only few changes were needed in "networkctl". Only the "bound_by" links (uplinks) are monitored. The "bound_by" map is evaluated only when the carrier is lost or gained. When a link is added, its "bound_by" & "bound_to" maps are created. When a link is dropped, both maps are removed. When a link is readded, the maps are created again. When a link is renamed, the old "bound_by" & "bound_to" maps are removed and new ones are created taking into account the new name. Let me know what you think, Alin Alin Rauta (1): Added support for Uplink Failure Detection using BindCarrier man/systemd.network.xml | 11 + src/libsystemd/sd-network/sd-network.c | 8 + src/network/networkctl.c | 43 ++-- src/network/networkd-link.c | 394 +-- src/network/networkd-link.h | 3 + src/network/networkd-network-gperf.gperf | 1 + src/network/networkd-network.c | 1 + src/network/networkd.h | 2 +- src/systemd/sd-network.h | 6 + 9 files changed, 438 insertions(+), 31 deletions(-) -- 1.9.3 ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
[systemd-devel] [PATCH v4] Added support for Uplink Failure Detection using BindCarrier
--- man/systemd.network.xml | 11 + src/libsystemd/sd-network/sd-network.c | 8 + src/network/networkctl.c | 43 ++-- src/network/networkd-link.c | 394 +-- src/network/networkd-link.h | 3 + src/network/networkd-network-gperf.gperf | 1 + src/network/networkd-network.c | 1 + src/network/networkd.h | 2 +- src/systemd/sd-network.h | 6 + 9 files changed, 438 insertions(+), 31 deletions(-) diff --git a/man/systemd.network.xml b/man/systemd.network.xml index 485876b..60252e5 100644 --- a/man/systemd.network.xml +++ b/man/systemd.network.xml @@ -280,6 +280,17 @@ + BindCarrier= + +A port or a list of ports. When set, controls the +behaviour of the current interface. When all ports in the list +are in an operational down state, the current interface is brought +down. When at least one port has carrier, the current interface +is brought up. + + + + Address= A static IPv4 or IPv6 address and its prefix length, diff --git a/src/libsystemd/sd-network/sd-network.c b/src/libsystemd/sd-network/sd-network.c index c4713fe..fb5152c 100644 --- a/src/libsystemd/sd-network/sd-network.c +++ b/src/libsystemd/sd-network/sd-network.c @@ -264,6 +264,14 @@ _public_ int sd_network_link_get_domains(int ifindex, char ***ret) { return network_get_link_strv("DOMAINS", ifindex, ret); } +_public_ int sd_network_link_get_carrier_bound_to(int ifindex, char ***ret) { +return network_get_link_strv("CARRIER_BOUND_TO", ifindex, ret); +} + +_public_ int sd_network_link_get_carrier_bound_by(int ifindex, char ***ret) { +return network_get_link_strv("CARRIER_BOUND_BY", ifindex, ret); +} + _public_ int sd_network_link_get_wildcard_domain(int ifindex) { int r; _cleanup_free_ char *p = NULL, *s = NULL; diff --git a/src/network/networkctl.c b/src/network/networkctl.c index aa83f32..0637513 100644 --- a/src/network/networkctl.c +++ b/src/network/networkctl.c @@ -508,6 +508,8 @@ static int link_status_one( const char *driver = NULL, *path = NULL, *vendor = NULL, *model = NULL, *link = NULL; const char *on_color_operational, *off_color_operational, *on_color_setup, *off_color_setup; +_cleanup_strv_free_ char **carrier_bound_to = NULL; +_cleanup_strv_free_ char **carrier_bound_by = NULL; struct ether_addr e; unsigned iftype; int r, ifindex; @@ -606,12 +608,15 @@ static int link_status_one( sd_network_link_get_network_file(ifindex, &network); +sd_network_link_get_carrier_bound_to(ifindex, &carrier_bound_to); +sd_network_link_get_carrier_bound_by(ifindex, &carrier_bound_by); + printf("%s%s%s %i: %s\n", on_color_operational, draw_special_char(DRAW_BLACK_CIRCLE), off_color_operational, ifindex, name); -printf(" Link File: %s\n" - "Network File: %s\n" - "Type: %s\n" - " State: %s%s%s (%s%s%s)\n", +printf(" Link File: %s\n" + "Network File: %s\n" + "Type: %s\n" + " State: %s%s%s (%s%s%s)\n", strna(link), strna(network), strna(t), @@ -619,13 +624,13 @@ static int link_status_one( on_color_setup, strna(setup_state), off_color_setup); if (path) -printf("Path: %s\n", path); +printf("Path: %s\n", path); if (driver) -printf(" Driver: %s\n", driver); +printf(" Driver: %s\n", driver); if (vendor) -printf(" Vendor: %s\n", vendor); +printf(" Vendor: %s\n", vendor); if (model) -printf(" Model: %s\n", model); +printf(" Model: %s\n", model); if (have_mac) { _cleanup_free_ char *description = NULL; @@ -634,23 +639,29 @@ static int link_status_one( ieee_oui(hwdb, &e, &description); if (description) -printf(" HW Address: %s (%s)\n", ether_addr_to_string(&e, ea), description); +printf(" HW Address: %s (%s)\n", ether_addr_to_string(&e, ea), description); else -printf(" HW Address: %s\n", ether_addr_to_string(&e, ea)); +printf(" HW Address: %s\n", ether_addr_to_string(&e, ea)); } if (mtu > 0) -printf(" MTU: %u\n", mtu); +printf(" MTU: %u\n", mtu); -dump_addresses(rtnl, " Add
[systemd-devel] [PATCH] libsystemd doesn't handle properly empty messages from kernel
Hi, Systemd strips out NLMSG_DONE piece from a multi-part message adding into the receive queue only the messages containing actual data. If we send a request to the kernel for getting the forwarding database table (just an example), the response will be a multi-part message like below: 1. FDB entry 1; 2. FDB entry 2; 3. NLMSG_DONE; libsystemd strips out "3. NLMSG_DONE;" part and places into the receive queue a pointer to "1. FDB entry 1;". But if the FDB table is empty, the respose from the kernel will look like below: 1. NLMSG_DONE; libsystemd strips out "1. NLMSG_DONE;" part and since there is no actual data got, it continues waiting until reaching timeout. Therefore, a call to "sd_rtnl_call" to send and wait for a response from kernel will exit with timeout which is interpreted as error in communication. The patch I've attached, adds "1. NLMSG_DONE;" to the receive queue only when getting empty response from kernel. This way, a call like "sd_rtnl_call" will not block anymore. It works fine, but it may be just an workaround. Let me know what you think. Alin Rauta (1): libsystemd doesn't handle properly empty messages from kernel src/libsystemd/sd-rtnl/rtnl-message.c | 4 +++- src/libsystemd/sd-rtnl/rtnl-types.c | 1 + src/libsystemd/sd-rtnl/sd-rtnl.c | 14 ++ 3 files changed, 18 insertions(+), 1 deletion(-) -- 1.9.3 ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
[systemd-devel] [PATCH] libsystemd doesn't handle properly empty messages from kernel
--- src/libsystemd/sd-rtnl/rtnl-message.c | 4 +++- src/libsystemd/sd-rtnl/rtnl-types.c | 1 + src/libsystemd/sd-rtnl/sd-rtnl.c | 14 ++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/libsystemd/sd-rtnl/rtnl-message.c b/src/libsystemd/sd-rtnl/rtnl-message.c index 5a71900..c938471 100644 --- a/src/libsystemd/sd-rtnl/rtnl-message.c +++ b/src/libsystemd/sd-rtnl/rtnl-message.c @@ -1554,7 +1554,9 @@ int socket_read_message(sd_rtnl *rtnl) { /* finished reading multi-part message */ done = true; -continue; +/* if first is not defined, put NLMSG_DONE into the receive queue. */ +if (first) +continue; } /* check that we support this message type */ diff --git a/src/libsystemd/sd-rtnl/rtnl-types.c b/src/libsystemd/sd-rtnl/rtnl-types.c index e21c898..bf7278f 100644 --- a/src/libsystemd/sd-rtnl/rtnl-types.c +++ b/src/libsystemd/sd-rtnl/rtnl-types.c @@ -411,6 +411,7 @@ static const NLTypeSystem rtnl_neigh_type_system = { }; static const NLType rtnl_types[RTM_MAX + 1] = { +[NLMSG_DONE] = { .type = NLA_META, .size = 0 }, [NLMSG_ERROR] = { .type = NLA_META, .size = sizeof(struct nlmsgerr) }, [RTM_NEWLINK] = { .type = NLA_NESTED, .type_system = &rtnl_link_type_system, .size = sizeof(struct ifinfomsg) }, [RTM_DELLINK] = { .type = NLA_NESTED, .type_system = &rtnl_link_type_system, .size = sizeof(struct ifinfomsg) }, diff --git a/src/libsystemd/sd-rtnl/sd-rtnl.c b/src/libsystemd/sd-rtnl/sd-rtnl.c index 50162c3..abec6f7 100644 --- a/src/libsystemd/sd-rtnl/sd-rtnl.c +++ b/src/libsystemd/sd-rtnl/sd-rtnl.c @@ -726,6 +726,8 @@ int sd_rtnl_call(sd_rtnl *rtnl, received_serial = rtnl_message_get_serial(incoming); if (received_serial == serial) { +uint16_t type; + /* found a match, remove from rqueue and return it */ memmove(rtnl->rqueue + i,rtnl->rqueue + i + 1, sizeof(sd_rtnl_message*) * (rtnl->rqueue_size - i - 1)); @@ -737,6 +739,18 @@ int sd_rtnl_call(sd_rtnl *rtnl, return r; } +r = sd_rtnl_message_get_type(incoming, &type); +if (r < 0) { +sd_rtnl_message_unref(incoming); +return r; +} + +if (type == NLMSG_DONE) { +log_debug("Got empty message"); +sd_rtnl_message_unref(incoming); +return 1; +} + if (ret) { *ret = incoming; } else -- 1.9.3 ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel