[systemd-devel] [PATCH] networkd: Add bridge port path cost
Tom Gundersen
teg at jklm.no
Thu Dec 4 02:13:03 PST 2014
Applied. Thanks! (sorry for the delay)
On Sat, Nov 15, 2014 at 4:17 AM, Susant Sahani <susant at redhat.com> wrote:
> This patch add support to specify path cost of the
> bridge port to be configured via conf file.
>
> Exampe: conf
>
> file: br.netdev
>
> [NetDev]
> Name=br-test
> Kind=bridge
>
> file: br.network
> [Match]
> Name=em1
>
> [Network]
> Bridge=br-test
>
> [BridgePort]
> Cost=332
>
> bridge link
> 2: em1 state UP : <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 master
> br-test state disabled priority 32 cost 332
> ---
> man/systemd.network.xml | 13 +++++
> src/network/networkd-link.c | 93 ++++++++++++++++++++++++++++++++
> src/network/networkd-network-gperf.gperf | 1 +
> src/network/networkd-network.c | 2 +-
> src/network/networkd.h | 2 +
> 5 files changed, 110 insertions(+), 1 deletion(-)
>
> diff --git a/man/systemd.network.xml b/man/systemd.network.xml
> index 4cc13b2..c9c946c 100644
> --- a/man/systemd.network.xml
> +++ b/man/systemd.network.xml
> @@ -505,6 +505,19 @@
> </refsect1>
>
> <refsect1>
> + <title>[BridgePort] Section Options</title>
> + <para>The <literal>[BridgePort]</literal> section accepts the following keys.</para>
> + <variablelist class='network-directives'>
> + <varlistentry>
> + <term><varname>Cost=</varname></term>
> + <listitem>
> + <para>Each port in a bridge may have different speed. Cost is used to decide which link to use. Faster interfaces should have lower costs</para>
> + </listitem>
> + </varlistentry>
> + </variablelist>
> + </refsect1>
> +
> + <refsect1>
> <title>Example</title>
> <example>
> <title>/etc/systemd/network/50-static.network</title>
> diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c
> index 26ef0fe..dbc804b 100644
> --- a/src/network/networkd-link.c
> +++ b/src/network/networkd-link.c
> @@ -705,6 +705,27 @@ int link_address_drop_handler(sd_rtnl *rtnl, sd_rtnl_message *m, void *userdata)
> return 1;
> }
>
> +static int link_set_handler(sd_rtnl *rtnl, sd_rtnl_message *m, void *userdata) {
> + _cleanup_link_unref_ Link *link = userdata;
> + int r;
> +
> + log_debug_link(link, "set link");
> +
> + 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);
> + link_enter_failed(link);
> + return 1;
> + }
> +
> + return 0;
> +}
> +
> static int set_hostname_handler(sd_bus *bus, sd_bus_message *m, void *userdata,
> sd_bus_error *ret_error) {
> _cleanup_link_unref_ Link *link = userdata;
> @@ -826,6 +847,69 @@ int link_set_mtu(Link *link, uint32_t mtu) {
> return 0;
> }
>
> +static int link_set_bridge(Link *link) {
> + _cleanup_rtnl_message_unref_ sd_rtnl_message *req = NULL;
> + int r;
> +
> + assert(link);
> + assert(link->network);
> +
> + if(link->network->cost == 0)
> + return 0;
> +
> + 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;
> + }
> +
> + r = sd_rtnl_message_link_set_family(req, PF_BRIDGE);
> + if (r < 0) {
> + log_error_link(link,
> + "Could not set message family %s", strerror(-r));
> + return r;
> + }
> +
> + r = sd_rtnl_message_open_container(req, IFLA_PROTINFO);
> + if (r < 0) {
> + log_error_link(link,
> + "Could not append IFLA_PROTINFO attribute: %s",
> + strerror(-r));
> + return r;
> + }
> +
> + if(link->network->cost != 0) {
> + r = sd_rtnl_message_append_u32(req, IFLA_BRPORT_COST, link->network->cost);
> + if (r < 0) {
> + log_error_link(link,
> + "Could not append IFLA_BRPORT_COST attribute: %s",
> + strerror(-r));
> + return r;
> + }
> + }
> +
> + r = sd_rtnl_message_close_container(req);
> + if (r < 0) {
> + log_error_link(link,
> + "Could not append IFLA_LINKINFO attribute: %s",
> + strerror(-r));
> + return r;
> + }
> +
> + r = sd_rtnl_call_async(link->manager->rtnl, req, link_set_handler, link, 0, NULL);
> + if (r < 0) {
> + log_error_link(link,
> + "Could not send rtnetlink message: %s",
> + strerror(-r));
> + return r;
> + }
> +
> + link_ref(link);
> +
> + return r;
> +}
> +
> static void dhcp6_handler(sd_dhcp6_client *client, int event, void *userdata) {
> Link *link = userdata;
>
> @@ -1066,6 +1150,15 @@ static int link_joined(Link *link) {
> }
> }
>
> + if(link->network->bridge) {
> + r = link_set_bridge(link);
> + if (r < 0) {
> + log_error_link(link,
> + "Could not set bridge message: %s",
> + strerror(-r));
> + }
> + }
> +
> return link_enter_set_addresses(link);
> }
>
> diff --git a/src/network/networkd-network-gperf.gperf b/src/network/networkd-network-gperf.gperf
> index a736461..1aef090 100644
> --- a/src/network/networkd-network-gperf.gperf
> +++ b/src/network/networkd-network-gperf.gperf
> @@ -58,6 +58,7 @@ DHCP.RequestBroadcast, config_parse_bool, 0,
> DHCP.CriticalConnection, config_parse_bool, 0, offsetof(Network, dhcp_critical)
> DHCP.VendorClassIdentifier, config_parse_string, 0, offsetof(Network, dhcp_vendor_class_identifier)
> DHCP.RouteMetric, config_parse_unsigned, 0, offsetof(Network, dhcp_route_metric)
> +BridgePort.Cost, config_parse_unsigned, 0, offsetof(Network, cost)
> /* backwards compatibility: do not add new entries to this section */
> DHCPv4.UseDNS, config_parse_bool, 0, offsetof(Network, dhcp_dns)
> DHCPv4.UseMTU, config_parse_bool, 0, offsetof(Network, dhcp_mtu)
> diff --git a/src/network/networkd-network.c b/src/network/networkd-network.c
> index aad9923..df236a4 100644
> --- a/src/network/networkd-network.c
> +++ b/src/network/networkd-network.c
> @@ -90,7 +90,7 @@ static int network_load_one(Manager *manager, const char *filename) {
> network->llmnr = LLMNR_SUPPORT_YES;
>
> r = config_parse(NULL, filename, file,
> - "Match\0Network\0Address\0Route\0DHCP\0DHCPv4\0",
> + "Match\0Network\0Address\0Route\0DHCP\0DHCPv4\0BridgePort\0",
> config_item_perf_lookup, network_network_gperf_lookup,
> false, false, true, network);
> if (r < 0)
> diff --git a/src/network/networkd.h b/src/network/networkd.h
> index 19a661e..0f879a8 100644
> --- a/src/network/networkd.h
> +++ b/src/network/networkd.h
> @@ -106,6 +106,8 @@ struct Network {
>
> bool dhcp_server;
>
> + unsigned cost;
> +
> LIST_HEAD(Address, static_addresses);
> LIST_HEAD(Route, static_routes);
>
> --
> 2.1.0
>
> _______________________________________________
> systemd-devel mailing list
> systemd-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/systemd-devel
More information about the systemd-devel
mailing list