Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

team: add new options like link_watch_policy (jsc#PED-7183) #1000

Merged
merged 10 commits into from Feb 23, 2024
70 changes: 70 additions & 0 deletions client/compat.c
Expand Up @@ -773,6 +773,18 @@ __ni_compat_generate_team_runner(xml_node_t *tnode, const ni_team_runner_t *runn
return TRUE;
}

static ni_bool_t
ni_compat_generate_team_link_watch_policy(xml_node_t *tnode, const ni_team_link_watch_policy_t policy)
{
const char *name;

if (policy != NI_TEAM_LINK_WATCH_POLICY_ANY &&
(name = ni_team_link_watch_policy_type_to_name(policy)))
xml_node_new_element("link_watch_policy", tnode, name);

return TRUE;
}

static ni_bool_t
__ni_compat_generate_team_link_watch(xml_node_t *tnode, const ni_team_link_watch_array_t *array)
{
Expand Down Expand Up @@ -823,6 +835,9 @@ __ni_compat_generate_team_link_watch(xml_node_t *tnode, const ni_team_link_watch
xml_node_new_element("send_always", watch, ni_format_boolean(arp->send_always));

xml_node_new_element("missed_max", watch, ni_sprint_uint(arp->missed_max));

if (arp->vlanid != UINT16_MAX)
xml_node_new_element("vlanid", watch, ni_sprint_uint(arp->vlanid));
}
break;

Expand Down Expand Up @@ -904,6 +919,50 @@ __ni_compat_generate_team_ports(xml_node_t *tnode, const ni_team_port_array_t *a
return TRUE;
}

static ni_bool_t
ni_compat_generate_team_notify_peers(xml_node_t *parent, const ni_team_t *team)
{
xml_node_t *node;

if (!parent || !team)
cfconrad marked this conversation as resolved.
Show resolved Hide resolved
return FALSE;

if (team->notify_peers.count == -1U && team->notify_peers.interval == -1U)
return TRUE;

node = xml_node_create(parent, "notify_peers");

if (team->notify_peers.count != -1U)
xml_node_new_element("count", node, ni_sprint_uint(team->notify_peers.count));

if (team->notify_peers.interval != -1U)
xml_node_new_element("interval", node, ni_sprint_uint(team->notify_peers.interval));

return TRUE;
}

static ni_bool_t
ni_compat_generate_team_mcast_rejoin(xml_node_t *parent, const ni_team_t *team)
{
xml_node_t *node;

if (!parent || !team)
cfconrad marked this conversation as resolved.
Show resolved Hide resolved
return FALSE;

if (team->mcast_rejoin.count == -1U && team->mcast_rejoin.interval == -1U)
return TRUE;

node = xml_node_create(parent, "mcast_rejoin");

if (team->mcast_rejoin.count != -1U)
xml_node_new_element("count", node, ni_sprint_uint(team->mcast_rejoin.count));

if (team->mcast_rejoin.interval != -1U)
xml_node_new_element("interval", node, ni_sprint_uint(team->mcast_rejoin.interval));

return TRUE;
}

static ni_bool_t
__ni_compat_generate_team(xml_node_t *ifnode, const ni_compat_netdev_t *compat)
{
Expand All @@ -918,9 +977,20 @@ __ni_compat_generate_team(xml_node_t *ifnode, const ni_compat_netdev_t *compat)
ni_link_address_print(&compat->dev->link.hwaddr));
}

if (team->debug_level > 0)
xml_node_new_element("debug_level", tnode, ni_sprint_uint(team->debug_level));

if (!ni_compat_generate_team_notify_peers(tnode, team))
return FALSE;
if (!ni_compat_generate_team_mcast_rejoin(tnode, team))
return FALSE;

if (!__ni_compat_generate_team_runner(tnode, &team->runner))
return FALSE;

if (!ni_compat_generate_team_link_watch_policy(tnode, team->link_watch_policy))
return FALSE;

if (!__ni_compat_generate_team_link_watch(tnode, &team->link_watch))
return FALSE;

Expand Down
64 changes: 64 additions & 0 deletions client/suse/compat-suse.c
Expand Up @@ -2473,6 +2473,22 @@ try_add_team_link_watch(const ni_sysconfig_t *sc, ni_netdev_t *dev, const char *
goto failure;
}
}

if ((var = __find_indexed_variable(sc, "TEAM_LW_ARP_PING_VLANID", suffix))) {
uint32_t u32;

if (ni_parse_uint(var->value, &u32, 0) < 0) {
ni_error("ifcfg-%s: Cannot parse TEAM_LW_ARP_PING_VLANID%s='%s'",
dev->name, suffix, var->value);
goto failure;
}
if (u32 > 4096) {
ni_error("ifcfg-%s: Invalid value in TEAM_LW_ARP_PING_VLANID%s='%s'",
dev->name, suffix, var->value);
goto failure;
}
arp->vlanid = (uint16_t)u32;
}
}
break;

Expand Down Expand Up @@ -2798,6 +2814,54 @@ try_team(ni_sysconfig_t *sc, ni_compat_netdev_t *compat)
}
}

if ((value = ni_sysconfig_get_value(sc, "TEAM_DEBUG_LEVEL")) != NULL) {
if (ni_parse_uint(value, &team->debug_level, 0) < 0) {
ni_error("ifcfg-%s: Cannot parse TEAM_DEBUG_LEVEL='%s'",
dev->name, value);
return -1;
}
}

if ((value = ni_sysconfig_get_value(sc, "TEAM_NOTIFY_PEERS_COUNT")) != NULL) {
if (ni_parse_uint(value, &team->notify_peers.count, 0) < 0) {
ni_error("ifcfg-%s: Cannot parse TEAM_NOTIFY_PEERS_COUNT='%s'",
dev->name, value);
return -1;
}
}

if ((value = ni_sysconfig_get_value(sc, "TEAM_NOTIFY_PEERS_INTERVAL")) != NULL) {
if (ni_parse_uint(value, &team->notify_peers.interval, 0) < 0) {
ni_error("ifcfg-%s: Cannot parse TEAM_NOTIFY_PEERS_INTERVAL='%s'",
dev->name, value);
return -1;
}
}

if ((value = ni_sysconfig_get_value(sc, "TEAM_MCAST_REJOIN_COUNT")) != NULL) {
if (ni_parse_uint(value, &team->mcast_rejoin.count, 0) < 0) {
ni_error("ifcfg-%s: Cannot parse TEAM_MCAST_REJOIN_COUNT='%s'",
dev->name, value);
return -1;
}
}

if ((value = ni_sysconfig_get_value(sc, "TEAM_MCAST_REJOIN_INTERVAL")) != NULL) {
if (ni_parse_uint(value, &team->mcast_rejoin.interval, 0) < 0) {
ni_error("ifcfg-%s: Cannot parse TEAM_MCAST_REJOIN_INTERVAL='%s'",
dev->name, value);
return -1;
}
}

if ((value = ni_sysconfig_get_value(sc, "TEAM_LINK_WATCH_POLICY"))) {
if (!ni_team_link_watch_policy_name_to_type(value, &team->link_watch_policy)) {
ni_error("ifcfg-%s: Cannot parse TEAM_LINK_WATCH_POLICY='%s'",
dev->name, value);
return -1;
}
}

if (__process_indexed_variables(sc, dev, "TEAM_LW_NAME",
try_add_team_link_watch) < 0)
return -1;
Expand Down
23 changes: 23 additions & 0 deletions include/wicked/team.h
Expand Up @@ -158,6 +158,7 @@ typedef struct ni_team_link_watch_arp {
ni_bool_t validate_inactive;
ni_bool_t send_always;
unsigned int missed_max;
uint16_t vlanid;
} ni_team_link_watch_arp_t;

typedef struct ni_team_link_watch_tipc {
Expand Down Expand Up @@ -227,11 +228,29 @@ typedef struct ni_team_port_array {
ni_team_port_t ** data;
} ni_team_port_array_t;

typedef enum {
NI_TEAM_LINK_WATCH_POLICY_ANY = 0U,
NI_TEAM_LINK_WATCH_POLICY_ALL = 1,
} ni_team_link_watch_policy_t;

typedef struct ni_team_notify_peers {
unsigned int count;
unsigned int interval;
} ni_team_notify_peers_t;

typedef struct ni_team_mcast_rejoin {
unsigned int count;
unsigned int interval;
} ni_team_mcast_rejoin_t;
/*
* team device
*/
struct ni_team {
unsigned int debug_level;
ni_team_notify_peers_t notify_peers;
ni_team_mcast_rejoin_t mcast_rejoin;
ni_team_runner_t runner;
ni_team_link_watch_policy_t link_watch_policy;
ni_team_link_watch_array_t link_watch;
ni_team_port_array_t ports;
};
Expand Down Expand Up @@ -261,6 +280,10 @@ extern ni_bool_t ni_team_ab_hwaddr_policy_name_to_type(const char *, ni_team_
extern const char * ni_team_link_watch_type_to_name(ni_team_link_watch_type_t);
extern ni_bool_t ni_team_link_watch_name_to_type(const char *, ni_team_link_watch_type_t *);

extern const char * ni_team_link_watch_policy_type_to_name(ni_team_link_watch_policy_t);
extern ni_bool_t ni_team_link_watch_policy_name_to_type(const char *,
ni_team_link_watch_policy_t *);

extern ni_team_link_watch_t * ni_team_link_watch_new(ni_team_link_watch_type_t);
extern void ni_team_link_watch_free(ni_team_link_watch_t *);
extern ni_declare_ptr_array_append(ni_team_link_watch);
Expand Down