Skip to content

Commit f1a88cd

Browse files
stchengyxieca
authored andcommitted
[libteam]: Fix libteam race condition when interface is created and enslaved (sonic-net#3250)
The race condition could happen like this: When an interface is enslaved into the port channel immediately after it is created, the order of creating the ifinfo and linking the ifinfo to the port is not guaranteed. Please check the patch commit message to get full details. Signed-off-by: Shu0T1an ChenG <[email protected]>
1 parent e9d3858 commit f1a88cd

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
From 9a27e9b85afbbf6235e61c2426481e49a2139219 Mon Sep 17 00:00:00 2001
2+
From: Shu0T1an ChenG <[email protected]>
3+
Date: Tue, 15 Jan 2019 12:23:02 -0800
4+
Subject: [PATCH] Fix ifinfo_link_with_port race condition with newlink
5+
6+
The race condition could happen like this:
7+
When an interface is enslaved into the port channel immediately after
8+
it is created, the order of creating the ifinfo and linking the ifinfo to
9+
the port is not guaranteed.
10+
11+
The team handler will listen to both netlink message to track new links
12+
get created to allocate the ifinfo and add the ifinfo into its linked list,
13+
and the team port change message to link the new port with ifinfo found
14+
in its linkedin list. However, when the ifinfo is not yet created, the error
15+
message "Failed to link port with ifinfo" is thrown with member port failed
16+
to be added into the team handler's port list.
17+
18+
This fix adds a condition to check if ifinfo_link_with_port is linking ifinfo
19+
to a port or to the team interface itself. If it is a port, ifinfo_find_create
20+
function is used to fix the race condition.
21+
22+
Signed-off-by: Shu0T1an ChenG <[email protected]>
23+
---
24+
libteam/ifinfo.c | 5 ++++-
25+
1 file changed, 4 insertions(+), 1 deletion(-)
26+
27+
diff --git a/libteam/ifinfo.c b/libteam/ifinfo.c
28+
index 44de4ca..444e0cd 100644
29+
--- a/libteam/ifinfo.c
30+
+++ b/libteam/ifinfo.c
31+
@@ -429,7 +429,10 @@ int ifinfo_link_with_port(struct team_handle *th, uint32_t ifindex,
32+
{
33+
struct team_ifinfo *ifinfo;
34+
35+
- ifinfo = ifinfo_find(th, ifindex);
36+
+ if (port)
37+
+ ifinfo = ifinfo_find_create(th, ifindex);
38+
+ else
39+
+ ifinfo = ifinfo_find(th, ifindex);
40+
if (!ifinfo)
41+
return -ENOENT;
42+
if (ifinfo->linked)
43+
--
44+
2.1.4
45+

src/libteam/patch/series

+1
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@
66
0006-teamd-Administratively-shutdown-port-channel-has-mem.patch
77
0007-Send-LACP-PDU-immediately-if-our-state-changed.patch
88
0008-libteam-Add-warm_reboot-mode.patch
9+
0009-Fix-ifinfo_link_with_port-race-condition-with-newlink.patch

0 commit comments

Comments
 (0)