Skip to content

Commit 8fcf43d

Browse files
vasant17lguohan
authored andcommitted
Provide broadcast IP while configuring interface ip address (sonic-net#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 [email protected]
1 parent 51393a2 commit 8fcf43d

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

cfgmgr/intfmgr.cpp

+16-8
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,27 @@ IntfMgr::IntfMgr(DBConnector *cfgDb, DBConnector *appDb, DBConnector *stateDb, c
3030
}
3131

3232
void IntfMgr::setIntfIp(const string &alias, const string &opCmd,
33-
const string &ipPrefixStr, const bool ipv4)
33+
const IpPrefix &ipPrefix)
3434
{
35-
stringstream cmd;
36-
string res;
35+
stringstream cmd;
36+
string res;
37+
string ipPrefixStr = ipPrefix.to_string();
38+
string broadcastIpStr = ipPrefix.getBroadcastIp().to_string();
39+
int prefixLen = ipPrefix.getMaskLength();
3740

38-
if (ipv4)
41+
if (ipPrefix.isV4())
3942
{
40-
cmd << IP_CMD << " address " << opCmd << " " << ipPrefixStr << " dev " << alias;
43+
(prefixLen < 31) ?
44+
(cmd << IP_CMD << " address " << opCmd << " " << ipPrefixStr << " broadcast " << broadcastIpStr <<" dev " << alias) :
45+
(cmd << IP_CMD << " address " << opCmd << " " << ipPrefixStr << " dev " << alias);
4146
}
4247
else
4348
{
44-
cmd << IP_CMD << " -6 address " << opCmd << " " << ipPrefixStr << " dev " << alias;
49+
(prefixLen < 127) ?
50+
(cmd << IP_CMD << " -6 address " << opCmd << " " << ipPrefixStr << " broadcast " << broadcastIpStr << " dev " << alias) :
51+
(cmd << IP_CMD << " -6 address " << opCmd << " " << ipPrefixStr << " dev " << alias);
4552
}
53+
4654
int ret = swss::exec(cmd.str(), res);
4755
if (ret)
4856
{
@@ -202,7 +210,7 @@ bool IntfMgr::doIntfAddrTask(const vector<string>& keys,
202210
// Set Interface IP except for lo
203211
if (!is_lo)
204212
{
205-
setIntfIp(alias, "add", ip_prefix.to_string(), ip_prefix.isV4());
213+
setIntfIp(alias, "add", ip_prefix);
206214
}
207215

208216
std::vector<FieldValueTuple> fvVector;
@@ -219,7 +227,7 @@ bool IntfMgr::doIntfAddrTask(const vector<string>& keys,
219227
// Set Interface IP except for lo
220228
if (!is_lo)
221229
{
222-
setIntfIp(alias, "del", ip_prefix.to_string(), ip_prefix.isV4());
230+
setIntfIp(alias, "del", ip_prefix);
223231
}
224232
m_appIntfTableProducer.del(appKey);
225233
m_stateIntfTable.del(keys[0] + state_db_key_delimiter + keys[1]);

cfgmgr/intfmgr.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class IntfMgr : public Orch
2121
Table m_cfgIntfTable, m_cfgVlanIntfTable;
2222
Table m_statePortTable, m_stateLagTable, m_stateVlanTable, m_stateVrfTable, m_stateIntfTable;
2323

24-
void setIntfIp(const string &alias, const string &opCmd, const string &ipPrefixStr, const bool ipv4 = true);
24+
void setIntfIp(const string &alias, const string &opCmd, const IpPrefix &ipPrefix);
2525
void setIntfVrf(const string &alias, const string vrfName);
2626
bool doIntfGeneralTask(const vector<string>& keys, const vector<FieldValueTuple>& data, const string& op);
2727
bool doIntfAddrTask(const vector<string>& keys, const vector<FieldValueTuple>& data, const string& op);

0 commit comments

Comments
 (0)