Skip to content

Commit

Permalink
Provide broadcast IP while configuring interface ip address (sonic-ne…
Browse files Browse the repository at this point in the history
…t#1007)


Problem: When SONiC CLI command is used to display summary of interface(s), broadcast address is always 0.0.0.0 irrespective of prefix length

Solution: When interface ip address is added using the command "ip addr add ...", we can specify the broadcast address as well. I did NOT set broadcast addr for interface with point-to-point link addresses(/31, and /127)

Signed-off-by: Vasant Patil vapatil@linkedin.com
  • Loading branch information
vasant17 authored and lguohan committed Aug 3, 2019
1 parent 51393a2 commit 8fcf43d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
24 changes: 16 additions & 8 deletions cfgmgr/intfmgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,27 @@ IntfMgr::IntfMgr(DBConnector *cfgDb, DBConnector *appDb, DBConnector *stateDb, c
}

void IntfMgr::setIntfIp(const string &alias, const string &opCmd,
const string &ipPrefixStr, const bool ipv4)
const IpPrefix &ipPrefix)
{
stringstream cmd;
string res;
stringstream cmd;
string res;
string ipPrefixStr = ipPrefix.to_string();
string broadcastIpStr = ipPrefix.getBroadcastIp().to_string();
int prefixLen = ipPrefix.getMaskLength();

if (ipv4)
if (ipPrefix.isV4())
{
cmd << IP_CMD << " address " << opCmd << " " << ipPrefixStr << " dev " << alias;
(prefixLen < 31) ?
(cmd << IP_CMD << " address " << opCmd << " " << ipPrefixStr << " broadcast " << broadcastIpStr <<" dev " << alias) :
(cmd << IP_CMD << " address " << opCmd << " " << ipPrefixStr << " dev " << alias);
}
else
{
cmd << IP_CMD << " -6 address " << opCmd << " " << ipPrefixStr << " dev " << alias;
(prefixLen < 127) ?
(cmd << IP_CMD << " -6 address " << opCmd << " " << ipPrefixStr << " broadcast " << broadcastIpStr << " dev " << alias) :
(cmd << IP_CMD << " -6 address " << opCmd << " " << ipPrefixStr << " dev " << alias);
}

int ret = swss::exec(cmd.str(), res);
if (ret)
{
Expand Down Expand Up @@ -202,7 +210,7 @@ bool IntfMgr::doIntfAddrTask(const vector<string>& keys,
// Set Interface IP except for lo
if (!is_lo)
{
setIntfIp(alias, "add", ip_prefix.to_string(), ip_prefix.isV4());
setIntfIp(alias, "add", ip_prefix);
}

std::vector<FieldValueTuple> fvVector;
Expand All @@ -219,7 +227,7 @@ bool IntfMgr::doIntfAddrTask(const vector<string>& keys,
// Set Interface IP except for lo
if (!is_lo)
{
setIntfIp(alias, "del", ip_prefix.to_string(), ip_prefix.isV4());
setIntfIp(alias, "del", ip_prefix);
}
m_appIntfTableProducer.del(appKey);
m_stateIntfTable.del(keys[0] + state_db_key_delimiter + keys[1]);
Expand Down
2 changes: 1 addition & 1 deletion cfgmgr/intfmgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class IntfMgr : public Orch
Table m_cfgIntfTable, m_cfgVlanIntfTable;
Table m_statePortTable, m_stateLagTable, m_stateVlanTable, m_stateVrfTable, m_stateIntfTable;

void setIntfIp(const string &alias, const string &opCmd, const string &ipPrefixStr, const bool ipv4 = true);
void setIntfIp(const string &alias, const string &opCmd, const IpPrefix &ipPrefix);
void setIntfVrf(const string &alias, const string vrfName);
bool doIntfGeneralTask(const vector<string>& keys, const vector<FieldValueTuple>& data, const string& op);
bool doIntfAddrTask(const vector<string>& keys, const vector<FieldValueTuple>& data, const string& op);
Expand Down

0 comments on commit 8fcf43d

Please sign in to comment.