From 8fcf43ddb02ac55684f414ccb6b41c46809fafe9 Mon Sep 17 00:00:00 2001 From: Vasant Patil <36455926+vasant17@users.noreply.github.com> Date: Fri, 2 Aug 2019 20:21:55 -0700 Subject: [PATCH] Provide broadcast IP while configuring interface ip address (#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 --- cfgmgr/intfmgr.cpp | 24 ++++++++++++++++-------- cfgmgr/intfmgr.h | 2 +- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/cfgmgr/intfmgr.cpp b/cfgmgr/intfmgr.cpp index cd509b3bbd74..e7365f538d53 100644 --- a/cfgmgr/intfmgr.cpp +++ b/cfgmgr/intfmgr.cpp @@ -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) { @@ -202,7 +210,7 @@ bool IntfMgr::doIntfAddrTask(const vector& 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 fvVector; @@ -219,7 +227,7 @@ bool IntfMgr::doIntfAddrTask(const vector& 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]); diff --git a/cfgmgr/intfmgr.h b/cfgmgr/intfmgr.h index d10b5d8b4c49..a250ff65fbf1 100644 --- a/cfgmgr/intfmgr.h +++ b/cfgmgr/intfmgr.h @@ -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& keys, const vector& data, const string& op); bool doIntfAddrTask(const vector& keys, const vector& data, const string& op);