Skip to content

Commit

Permalink
Fix issue with setting IP address in run time.
Browse files Browse the repository at this point in the history
Issue: sonic-net/SONiC#22
Issue was observed only when setting IP address via ifconfig
command. Caused by ifconfig command behavior: first is sets
IP address with netmask /8 and then changes netmask to specified
in command. Problem is not observed when set IP address with
"ip addr" command.
  • Loading branch information
oleksandrivantsiv committed Jun 9, 2017
1 parent 7c34bdf commit 097499f
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 25 deletions.
68 changes: 44 additions & 24 deletions orchagent/intfsorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,33 +87,53 @@ void IntfsOrch::doTask(Consumer &consumer)
}

auto it_intfs = m_syncdIntfses.find(alias);
if (it_intfs == m_syncdIntfses.end() ||
!m_syncdIntfses[alias].ip_addresses.contains(ip_prefix.getIp()))
if (it_intfs == m_syncdIntfses.end())
{
if (it_intfs == m_syncdIntfses.end())
if (addRouterIntfs(port))
{
if (addRouterIntfs(port))
{
IntfsEntry intfs_entry;
intfs_entry.ref_count = 0;
m_syncdIntfses[alias] = intfs_entry;
}
else
{
it++;
continue;
}
IntfsEntry intfs_entry;
intfs_entry.ref_count = 0;
m_syncdIntfses[alias] = intfs_entry;
}
else
{
it++;
continue;
}

addSubnetRoute(port, ip_prefix);
addIp2MeRoute(ip_prefix);

m_syncdIntfses[alias].ip_addresses.add(ip_prefix.getIp());
it = consumer.m_toSync.erase(it);
}
else

if (m_syncdIntfses[alias].ip_addresses.count(ip_prefix))
{
/* Duplicate entry */
it = consumer.m_toSync.erase(it);
continue;
}

bool overlaps = false;
for (const auto &prefixIt: m_syncdIntfses[alias].ip_addresses)
{
if (prefixIt.isAddressInSubnet(ip_prefix.getIp()) ||
ip_prefix.isAddressInSubnet(prefixIt.getIp()))
{
overlaps = true;
SWSS_LOG_NOTICE("Router interface %s IP %s overlaps with %s.", port.m_alias.c_str(),
prefixIt.to_string().c_str(), ip_prefix.to_string().c_str());
break;
}
}

if (overlaps)
{
/* Overlap of IP address network */
++it;
continue;
}

addSubnetRoute(port, ip_prefix);
addIp2MeRoute(ip_prefix);

m_syncdIntfses[alias].ip_addresses.insert(ip_prefix);
it = consumer.m_toSync.erase(it);
}
else if (op == DEL_COMMAND)
{
Expand All @@ -134,16 +154,16 @@ void IntfsOrch::doTask(Consumer &consumer)

if (m_syncdIntfses.find(alias) != m_syncdIntfses.end())
{
if (m_syncdIntfses[alias].ip_addresses.contains(ip_prefix.getIp()))
if (m_syncdIntfses[alias].ip_addresses.count(ip_prefix))
{
removeSubnetRoute(port, ip_prefix);
removeIp2MeRoute(ip_prefix);

m_syncdIntfses[alias].ip_addresses.remove(ip_prefix.getIp());
m_syncdIntfses[alias].ip_addresses.erase(ip_prefix);
}

/* Remove router interface that no IP addresses are associated with */
if (m_syncdIntfses[alias].ip_addresses.getSize() == 0)
if (m_syncdIntfses[alias].ip_addresses.size() == 0)
{
if (removeRouterIntfs(port))
{
Expand Down
3 changes: 2 additions & 1 deletion orchagent/intfsorch.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@
#include "macaddress.h"

#include <map>
#include <set>

extern sai_object_id_t gVirtualRouterId;
extern MacAddress gMacAddress;

struct IntfsEntry
{
IpAddresses ip_addresses;
std::set<IpPrefix> ip_addresses;
int ref_count;
};

Expand Down

0 comments on commit 097499f

Please sign in to comment.