From 89db629fe26ab3eaae043d6fe34f36d554b202a3 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 6 Sep 2022 10:17:04 +0200 Subject: [PATCH] platform: use signed int for NMPlatformLnkBond.primary On netlink API, the attribute is indeed u32. However, this is an ifindex which in most other kernel APIs and in NetworkManager code is a signed integer. Note that of course kernel would only ever assign numbers that are valid ifindexes, thus in the suitable range. (cherry picked from commit c28dd78c05074cab1ee4a08df5369b01bdd65769) --- src/libnm-platform/nm-linux-platform.c | 4 ++-- src/libnm-platform/nm-platform.c | 2 +- src/libnm-platform/nm-platform.h | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libnm-platform/nm-linux-platform.c b/src/libnm-platform/nm-linux-platform.c index ce795a92ce..766c059826 100644 --- a/src/libnm-platform/nm-linux-platform.c +++ b/src/libnm-platform/nm-linux-platform.c @@ -1590,7 +1590,7 @@ _parse_lnk_bond(const char *kind, struct nlattr *info_data) if (tb[IFLA_BOND_MODE]) props->mode = nla_get_u8(tb[IFLA_BOND_MODE]); if (tb[IFLA_BOND_PRIMARY]) - props->primary = nla_get_u32(tb[IFLA_BOND_PRIMARY]); + props->primary = NM_CLAMP((int) nla_get_u32(tb[IFLA_BOND_PRIMARY]), 0, G_MAXINT); if (tb[IFLA_BOND_MIIMON]) { props->miimon = nla_get_u32(tb[IFLA_BOND_MIIMON]); props->miimon_has = TRUE; @@ -4536,7 +4536,7 @@ _nl_msg_new_link_set_linkinfo(struct nl_msg *msg, NMLinkType link_type, gconstpo NLA_PUT_U32(msg, IFLA_BOND_PACKETS_PER_SLAVE, props->packets_per_port); if (props->peer_notif_delay_has) NLA_PUT_U32(msg, IFLA_BOND_PEER_NOTIF_DELAY, props->peer_notif_delay); - if (props->primary) + if (props->primary > 0) NLA_PUT_U32(msg, IFLA_BOND_PRIMARY, props->primary); if (props->resend_igmp_has) NLA_PUT_U32(msg, IFLA_BOND_RESEND_IGMP, props->resend_igmp); diff --git a/src/libnm-platform/nm-platform.c b/src/libnm-platform/nm-platform.c index df177485ff..35e6bf5956 100644 --- a/src/libnm-platform/nm-platform.c +++ b/src/libnm-platform/nm-platform.c @@ -6096,7 +6096,7 @@ nm_platform_lnk_bond_to_string(const NMPlatformLnkBond *lnk, char *buf, gsize le &len, "bond" " mode %u" - " primary %u" + " primary %d" "%s" /* miimon */ "%s" /* updelay */ "%s" /* downdelay */ diff --git a/src/libnm-platform/nm-platform.h b/src/libnm-platform/nm-platform.h index 90ffbed02e..74629217c9 100644 --- a/src/libnm-platform/nm-platform.h +++ b/src/libnm-platform/nm-platform.h @@ -895,6 +895,7 @@ extern const NMPlatformLnkBridge nm_platform_lnk_bridge_default; #define NM_BOND_MAX_ARP_TARGETS 16 typedef struct { + int primary; in_addr_t arp_ip_target[NM_BOND_MAX_ARP_TARGETS]; guint32 arp_all_targets; guint32 arp_interval; @@ -905,7 +906,6 @@ typedef struct { guint32 min_links; guint32 packets_per_port; guint32 peer_notif_delay; - guint32 primary; guint32 resend_igmp; guint32 updelay; guint16 ad_actor_sys_prio;