Skip to content

Commit 097499f

Browse files
Fix issue with setting IP address in run time.
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.
1 parent 7c34bdf commit 097499f

File tree

2 files changed

+46
-25
lines changed

2 files changed

+46
-25
lines changed

orchagent/intfsorch.cpp

+44-24
Original file line numberDiff line numberDiff line change
@@ -87,33 +87,53 @@ void IntfsOrch::doTask(Consumer &consumer)
8787
}
8888

8989
auto it_intfs = m_syncdIntfses.find(alias);
90-
if (it_intfs == m_syncdIntfses.end() ||
91-
!m_syncdIntfses[alias].ip_addresses.contains(ip_prefix.getIp()))
90+
if (it_intfs == m_syncdIntfses.end())
9291
{
93-
if (it_intfs == m_syncdIntfses.end())
92+
if (addRouterIntfs(port))
9493
{
95-
if (addRouterIntfs(port))
96-
{
97-
IntfsEntry intfs_entry;
98-
intfs_entry.ref_count = 0;
99-
m_syncdIntfses[alias] = intfs_entry;
100-
}
101-
else
102-
{
103-
it++;
104-
continue;
105-
}
94+
IntfsEntry intfs_entry;
95+
intfs_entry.ref_count = 0;
96+
m_syncdIntfses[alias] = intfs_entry;
97+
}
98+
else
99+
{
100+
it++;
101+
continue;
106102
}
107-
108-
addSubnetRoute(port, ip_prefix);
109-
addIp2MeRoute(ip_prefix);
110-
111-
m_syncdIntfses[alias].ip_addresses.add(ip_prefix.getIp());
112-
it = consumer.m_toSync.erase(it);
113103
}
114-
else
104+
105+
if (m_syncdIntfses[alias].ip_addresses.count(ip_prefix))
106+
{
115107
/* Duplicate entry */
116108
it = consumer.m_toSync.erase(it);
109+
continue;
110+
}
111+
112+
bool overlaps = false;
113+
for (const auto &prefixIt: m_syncdIntfses[alias].ip_addresses)
114+
{
115+
if (prefixIt.isAddressInSubnet(ip_prefix.getIp()) ||
116+
ip_prefix.isAddressInSubnet(prefixIt.getIp()))
117+
{
118+
overlaps = true;
119+
SWSS_LOG_NOTICE("Router interface %s IP %s overlaps with %s.", port.m_alias.c_str(),
120+
prefixIt.to_string().c_str(), ip_prefix.to_string().c_str());
121+
break;
122+
}
123+
}
124+
125+
if (overlaps)
126+
{
127+
/* Overlap of IP address network */
128+
++it;
129+
continue;
130+
}
131+
132+
addSubnetRoute(port, ip_prefix);
133+
addIp2MeRoute(ip_prefix);
134+
135+
m_syncdIntfses[alias].ip_addresses.insert(ip_prefix);
136+
it = consumer.m_toSync.erase(it);
117137
}
118138
else if (op == DEL_COMMAND)
119139
{
@@ -134,16 +154,16 @@ void IntfsOrch::doTask(Consumer &consumer)
134154

135155
if (m_syncdIntfses.find(alias) != m_syncdIntfses.end())
136156
{
137-
if (m_syncdIntfses[alias].ip_addresses.contains(ip_prefix.getIp()))
157+
if (m_syncdIntfses[alias].ip_addresses.count(ip_prefix))
138158
{
139159
removeSubnetRoute(port, ip_prefix);
140160
removeIp2MeRoute(ip_prefix);
141161

142-
m_syncdIntfses[alias].ip_addresses.remove(ip_prefix.getIp());
162+
m_syncdIntfses[alias].ip_addresses.erase(ip_prefix);
143163
}
144164

145165
/* Remove router interface that no IP addresses are associated with */
146-
if (m_syncdIntfses[alias].ip_addresses.getSize() == 0)
166+
if (m_syncdIntfses[alias].ip_addresses.size() == 0)
147167
{
148168
if (removeRouterIntfs(port))
149169
{

orchagent/intfsorch.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@
99
#include "macaddress.h"
1010

1111
#include <map>
12+
#include <set>
1213

1314
extern sai_object_id_t gVirtualRouterId;
1415
extern MacAddress gMacAddress;
1516

1617
struct IntfsEntry
1718
{
18-
IpAddresses ip_addresses;
19+
std::set<IpPrefix> ip_addresses;
1920
int ref_count;
2021
};
2122

0 commit comments

Comments
 (0)