-
Notifications
You must be signed in to change notification settings - Fork 580
[teamsyncd]: Add LAG members to syncd when created. #183
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
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
#include <sys/socket.h> | ||
#include <linux/if.h> | ||
#include <netlink/route/link.h> | ||
#include <teamdctl.h> | ||
#include "logger.h" | ||
#include "netmsg.h" | ||
#include "dbconnector.h" | ||
|
@@ -28,20 +29,29 @@ void TeamSync::onMsg(int nlmsg_type, struct nl_object *obj) | |
if ((nlmsg_type != RTM_NEWLINK) && (nlmsg_type != RTM_DELLINK)) | ||
return; | ||
|
||
string lagName = rtnl_link_get_name(link); | ||
string intfName = rtnl_link_get_name(link); | ||
/* Listens to LAG messages */ | ||
char *type = rtnl_link_get_type(link); | ||
if (!type || (strcmp(type, TEAM_DRV_NAME) != 0)) | ||
{ | ||
if (nlmsg_type == RTM_NEWLINK) | ||
{ | ||
for (const auto& i : m_teamPorts) | ||
{ | ||
i.second->syncMember(intfName); | ||
} | ||
} | ||
return; | ||
} | ||
|
||
if (nlmsg_type == RTM_DELLINK) | ||
{ | ||
/* Remove LAG ports and delete LAG */ | ||
removeLag(lagName); | ||
removeLag(intfName); | ||
return; | ||
} | ||
|
||
addLag(lagName, rtnl_link_get_ifindex(link), | ||
addLag(intfName, rtnl_link_get_ifindex(link), | ||
rtnl_link_get_flags(link) & IFF_UP, | ||
rtnl_link_get_flags(link) & IFF_LOWER_UP, | ||
rtnl_link_get_mtu(link)); | ||
|
@@ -121,6 +131,19 @@ TeamSync::TeamPortSync::TeamPortSync(const string &lagName, int ifindex, | |
"Unable to register port change event"); | ||
} | ||
|
||
m_tdc = teamdctl_alloc(); | ||
|
||
if (m_tdc == NULL) | ||
{ | ||
SWSS_LOG_THROW("Failed to allocate teamdctl context."); | ||
} | ||
|
||
err = teamdctl_connect(m_tdc, m_lagName.c_str(), NULL, NULL); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where is this defined? I'm sorry but I couldn't find the function. Can you please tell me which file has it? |
||
if (err) | ||
{ | ||
SWSS_LOG_THROW("Failed to connect to %s teamdctl.", m_lagName.c_str()); | ||
} | ||
|
||
/* Sync LAG at first */ | ||
onChange(); | ||
} | ||
|
@@ -132,6 +155,12 @@ TeamSync::TeamPortSync::~TeamPortSync() | |
team_change_handler_unregister(m_team, &gPortChangeHandler, this); | ||
team_free(m_team); | ||
} | ||
|
||
if (m_tdc) | ||
{ | ||
teamdctl_disconnect(m_tdc); | ||
teamdctl_free(m_tdc); | ||
} | ||
} | ||
|
||
int TeamSync::TeamPortSync::onChange() | ||
|
@@ -209,3 +238,24 @@ void TeamSync::TeamPortSync::readMe() | |
{ | ||
team_handle_events(m_team); | ||
} | ||
|
||
void TeamSync::TeamPortSync::syncMember(const std::string& intfName) | ||
{ | ||
const std::string config(teamdctl_config_get_raw(m_tdc)); | ||
const std::string intfNameStr("\"" + intfName + "\""); | ||
|
||
if (config.find(intfNameStr) == std::string::npos) | ||
{ | ||
return; | ||
} | ||
|
||
if (m_lagMembers.find(intfName) != m_lagMembers.end()) | ||
{ | ||
return; | ||
} | ||
|
||
if (teamdctl_port_add(m_tdc, intfName.c_str())) | ||
{ | ||
SWSS_LOG_ERROR("Failed to add port %s to %s", intfName.c_str(), m_lagName.c_str()); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or change to teamName?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here we can have either a LAG or its member, so I picked a more general name
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please put a comment to that effect. That this can be the LAG or a member.