From ab71c595359b008fbdcc85ff8dd7186a6e515adfec3fce2d26a349929bd2edb0 Mon Sep 17 00:00:00 2001 From: Jan Engelhardt Date: Tue, 27 Jun 2023 07:39:39 +0000 Subject: [PATCH] Accepting request 1095530 from home:ohollmann:branches:network - Add option to change evaluation logic of multiple link-watchers (jsc@PED2209) Add 0001-teamd-Add-option-to-change-evaluation-logic-of-multi.patch OBS-URL: https://build.opensuse.org/request/show/1095530 OBS-URL: https://build.opensuse.org/package/show/network/libteam?expand=0&rev=23 --- ...-to-change-evaluation-logic-of-multi.patch | 217 ++++++++++++++++++ libteam.changes | 6 + libteam.spec | 10 +- 3 files changed, 229 insertions(+), 4 deletions(-) create mode 100644 0001-teamd-Add-option-to-change-evaluation-logic-of-multi.patch diff --git a/0001-teamd-Add-option-to-change-evaluation-logic-of-multi.patch b/0001-teamd-Add-option-to-change-evaluation-logic-of-multi.patch new file mode 100644 index 0000000..f178c19 --- /dev/null +++ b/0001-teamd-Add-option-to-change-evaluation-logic-of-multi.patch @@ -0,0 +1,217 @@ +From 7cb5de8b01be132bd4150eff460bfd83296414b6 Mon Sep 17 00:00:00 2001 +From: Otto Hollmann +Date: Tue, 2 May 2023 17:36:15 +0200 +Subject: [PATCH] teamd: Add option to change evaluation logic of multiple + link-watchers + +Now, if multiple link watchers are used, link is up if any of the +link-watchers reports the link up. + +Introduce new option "link_watch_policy" to change this behaviour. +Possible values are "any" and "all". If nothing specified, default value +"any" will be used and there will be no change in current behaviour. If +value "all" will be set, link will be up only if ALL the link-watchers +report the link up. + +Signed-off-by: Otto Hollmann +Signed-off-by: Jiri Pirko +--- + man/teamd.conf.5 | 47 +++++++++++++++++++ + .../activebackup_multi_lw_2.conf | 25 ++++++++++ + teamd/teamd.c | 26 ++++++++++ + teamd/teamd.h | 1 + + teamd/teamd_link_watch.c | 27 +++++++++-- + 5 files changed, 121 insertions(+), 5 deletions(-) + create mode 100644 teamd/example_configs/activebackup_multi_lw_2.conf + +diff --git a/man/teamd.conf.5 b/man/teamd.conf.5 +index dc913cd..8c65c33 100644 +--- a/man/teamd.conf.5 ++++ b/man/teamd.conf.5 +@@ -407,6 +407,23 @@ Default: + .TP + .BR "link_watch.target_host "| " ports.PORTIFNAME.link_watch.target_host " (hostname) + Hostname to be converted to IPv6 address which will be filled into NS packet as target address. ++.TP ++.BR "link_watch_policy " (string) ++Name of link-watchers evaluation policy. Available options are following: ++.RS 7 ++.PP ++.BR "any "\(em ++Link is up if ++.BR any ++of the link-watchers reports the link up. ++.PP ++.BR "all "\(em ++Link is up if ++.BR all ++of the link-watchers reports the link up. ++.PP ++Default: ++.BR "any" + .SH EXAMPLES + .PP + .nf +@@ -518,6 +535,36 @@ This configuration uses ARP ping link watch. + Similar to the previous one, only this time two link watchers are used at the same time. + .PP + .nf ++{ ++ "device": "team0", ++ "runner": {"name": "activebackup"}, ++ "link_watch_policy": "all", ++ "link_watch": [ ++ { ++ "name": "arp_ping", ++ "interval": 100, ++ "missed_max": 30, ++ "target_host": "192.168.23.1" ++ }, ++ { ++ "name": "ethtool" ++ } ++ ], ++ "ports": { ++ "eth1": { ++ "prio": -10, ++ "sticky": true ++ }, ++ "eth2": { ++ "prio": 100 ++ } ++ } ++} ++.fi ++.PP ++Two link-watchers are used at the same time. Link is up only if all configured link-watchers report link is up. ++.PP ++.nf + { + "device": "team0", + "runner": { +diff --git a/teamd/example_configs/activebackup_multi_lw_2.conf b/teamd/example_configs/activebackup_multi_lw_2.conf +new file mode 100644 +index 0000000..a9073d7 +--- /dev/null ++++ b/teamd/example_configs/activebackup_multi_lw_2.conf +@@ -0,0 +1,25 @@ ++{ ++ "device": "team0", ++ "runner": {"name": "activebackup"}, ++ "link_watch_policy": "all", ++ "link_watch": [ ++ { ++ "name": "arp_ping", ++ "interval": 100, ++ "missed_max": 30, ++ "target_host": "192.168.23.1" ++ }, ++ { ++ "name": "ethtool" ++ } ++ ], ++ "ports": { ++ "eth1": { ++ "prio": -10, ++ "sticky": true ++ }, ++ "eth2": { ++ "prio": 100 ++ } ++ } ++} +\ No newline at end of file +diff --git a/teamd/teamd.c b/teamd/teamd.c +index a89b702..f351599 100644 +--- a/teamd/teamd.c ++++ b/teamd/teamd.c +@@ -1805,6 +1805,28 @@ static int teamd_drop_privileges() + + #endif + ++static int teamd_get_link_watch_policy(struct teamd_context *ctx) ++{ ++ int err; ++ const char *link_watch_policy; ++ ++ err = teamd_config_string_get(ctx, &link_watch_policy, "$.link_watch_policy"); ++ if (!err) { ++ if (!strcmp(link_watch_policy, "all")) { ++ ctx->evaluate_all_watchers = true; ++ } else if (!strcmp(link_watch_policy, "any")) { ++ ctx->evaluate_all_watchers = false; ++ } else { ++ teamd_log_err("Unrecognized value for link_watch_policy."); ++ teamd_log_err("Only \"any\" or \"all\" are allowed but \"%s\" found in config.", link_watch_policy); ++ return -EINVAL; ++ } ++ } else { ++ teamd_log_dbg(ctx, "No link_watch_policy specified in config, using default value \"any\"."); ++ } ++ return 0; ++} ++ + int main(int argc, char **argv) + { + enum teamd_exit_code ret = TEAMD_EXIT_FAILURE; +@@ -1863,6 +1885,10 @@ int main(int argc, char **argv) + if (err) + goto config_free; + ++ err = teamd_get_link_watch_policy(ctx); ++ if (err) ++ goto config_free; ++ + err = teamd_set_default_pid_file(ctx); + if (err) + goto config_free; +diff --git a/teamd/teamd.h b/teamd/teamd.h +index 541d2a7..bc2ce36 100644 +--- a/teamd/teamd.h ++++ b/teamd/teamd.h +@@ -105,6 +105,7 @@ struct teamd_context { + bool no_quit_destroy; + bool init_no_ports; + bool pre_add_ports; ++ bool evaluate_all_watchers; + char * config_file; + char * config_text; + json_t * config_json; +diff --git a/teamd/teamd_link_watch.c b/teamd/teamd_link_watch.c +index cae6549..11f4697 100644 +--- a/teamd/teamd_link_watch.c ++++ b/teamd/teamd_link_watch.c +@@ -133,11 +133,28 @@ bool teamd_link_watch_port_up(struct teamd_context *ctx, + if (!tdport) + return true; + link = true; +- teamd_for_each_port_priv_by_creator(common_ppriv, tdport, +- LW_PORT_PRIV_CREATOR_PRIV) { +- link = common_ppriv->link_up; +- if (link) +- return link; ++ if (ctx->evaluate_all_watchers) { ++ /* ++ * If multiple link-watchers used at the same time, ++ * link is up if ALL of the link-watchers reports the link up. ++ */ ++ teamd_for_each_port_priv_by_creator(common_ppriv, tdport, ++ LW_PORT_PRIV_CREATOR_PRIV) { ++ link = common_ppriv->link_up; ++ if (!link) ++ return link; ++ } ++ } else { ++ /* ++ * If multiple link-watchers used at the same time, ++ * link is up if ANY of the link-watchers reports the link up. ++ */ ++ teamd_for_each_port_priv_by_creator(common_ppriv, tdport, ++ LW_PORT_PRIV_CREATOR_PRIV) { ++ link = common_ppriv->link_up; ++ if (link) ++ return link; ++ } + } + return link; + } diff --git a/libteam.changes b/libteam.changes index 1ee7c40..a77d19e 100644 --- a/libteam.changes +++ b/libteam.changes @@ -1,3 +1,9 @@ +------------------------------------------------------------------- +Mon Jun 26 13:28:06 UTC 2023 - Otto Hollmann + +- Add option to change evaluation logic of multiple link-watchers (jsc@PED2209) + Add 0001-teamd-Add-option-to-change-evaluation-logic-of-multi.patch + ------------------------------------------------------------------- Fri Nov 5 17:14:17 UTC 2021 - Otto Hollmann diff --git a/libteam.spec b/libteam.spec index 6737756..2b24c37 100644 --- a/libteam.spec +++ b/libteam.spec @@ -1,7 +1,7 @@ # # spec file for package libteam # -# Copyright (c) 2018 SUSE LINUX GmbH, Nuernberg, Germany. +# Copyright (c) 2023 SUSE LLC # # All modifications and additions to the file contributed by third parties # remain the property of their copyright owners, unless otherwise agreed @@ -12,7 +12,7 @@ # license that conforms to the Open Source Definition (Version 1.9) # published by the Open Source Initiative. -# Please submit bugfixes or comments via http://bugs.opensuse.org/ +# Please submit bugfixes or comments via https://bugs.opensuse.org/ # @@ -23,7 +23,7 @@ Name: libteam Version: 1.31 Release: 0 Summary: Utilities for controlling 802.1AX team network device -License: LGPL-2.1+ +License: LGPL-2.1-or-later Group: System/Kernel URL: http://libteam.org/ @@ -33,8 +33,10 @@ Patch1: check_if_psr_ops_were_initialized.patch Patch2: start_teamd_from_usr_sbin.patch Patch3: ignore_ebusy_for_team_hwaddr_set.patch Patch4: 0001-allow-send_interface-dbus.patch -Patch5: harden_teamd@.service.patch +Patch5: harden_teamd@.service.patch Patch6: better_handle_failures_to_chown.patch +# PATCH-FIX-UPSTREAM jsc#PED-2209 Add option to change link-watchers logic +Patch7: 0001-teamd-Add-option-to-change-evaluation-logic-of-multi.patch BuildRequires: doxygen BuildRequires: libcap-devel BuildRequires: libtool