|
| 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 | + |
0 commit comments