Skip to content

Commit 7875069

Browse files
r-acostadceara
authored andcommitted
ovn-ic: Fix global blacklist filter for IPv6 addresses.
This commit fixes the prefix filter function as the return condition for IPv6 addresses is disabling the advertisement of all learned prefixes regardless of the match with the blacklist or not. Reported-at: https://bugs.launchpad.net/ubuntu/+source/ovn/+bug/2046804 Fixes: 57b347c ("ovn-ic: Route advertisement.") Signed-off-by: Roberto Bartzen Acosta <roberto.acosta@luizalabs.com> Signed-off-by: Dumitru Ceara <dceara@redhat.com>
1 parent f5c3ffb commit 7875069

File tree

2 files changed

+108
-6
lines changed

2 files changed

+108
-6
lines changed

ic/ovn-ic.c

+9-6
Original file line numberDiff line numberDiff line change
@@ -1068,12 +1068,15 @@ prefix_is_black_listed(const struct smap *nb_options,
10681068
continue;
10691069
}
10701070
} else {
1071-
struct in6_addr mask = ipv6_create_mask(bl_plen);
1072-
for (int i = 0; i < 16 && mask.s6_addr[i] != 0; i++) {
1073-
if ((prefix->s6_addr[i] & mask.s6_addr[i])
1074-
!= (bl_prefix.s6_addr[i] & mask.s6_addr[i])) {
1075-
continue;
1076-
}
1071+
struct in6_addr mask = ipv6_create_mask(plen);
1072+
/* First calculate the difference between bl_prefix and prefix, so
1073+
* use the bl mask to ensure prefixes are correctly validated.
1074+
* e.g.: 2005:1734:5678::/50 is a subnet of 2005:1234::/21 */
1075+
struct in6_addr m_prefixes = ipv6_addr_bitand(prefix, &bl_prefix);
1076+
struct in6_addr m_prefix = ipv6_addr_bitand(&m_prefixes, &mask);
1077+
struct in6_addr m_bl_prefix = ipv6_addr_bitand(&bl_prefix, &mask);
1078+
if (!ipv6_addr_equals(&m_prefix, &m_bl_prefix)) {
1079+
continue;
10771080
}
10781081
}
10791082
matched = true;

tests/ovn-ic.at

+99
Original file line numberDiff line numberDiff line change
@@ -1341,3 +1341,102 @@ AT_CHECK([ovn-ic-nbctl get ic_nb_global . sb_ic_cfg], [0], [dnl
13411341
OVN_CLEANUP_IC([az1])
13421342
AT_CLEANUP
13431343
])
1344+
1345+
OVN_FOR_EACH_NORTHD([
1346+
AT_SETUP([ovn-ic -- route sync -- IPv6 blacklist filter])
1347+
AT_KEYWORDS([IPv6-route-sync-blacklist])
1348+
1349+
ovn_init_ic_db
1350+
check ovn-ic-nbctl ts-add ts1
1351+
1352+
for i in 1 2; do
1353+
ovn_start az$i
1354+
ovn_as az$i
1355+
1356+
# Enable route learning at AZ level
1357+
check ovn-nbctl set nb_global . options:ic-route-learn=true
1358+
# Enable route advertising at AZ level
1359+
check ovn-nbctl set nb_global . options:ic-route-adv=true
1360+
# Enable blacklist single filter for IPv6
1361+
check ovn-nbctl set nb_global . options:ic-route-blacklist=" \
1362+
2003:db8:1::/64,2004:aaaa::/32,2005:1234::/21"
1363+
1364+
OVS_WAIT_UNTIL([ovn-nbctl show | grep ts1])
1365+
1366+
# Create LRP and connect to TS
1367+
check ovn-nbctl lr-add lr$i
1368+
check ovn-nbctl lrp-add lr$i lrp-lr$i-ts1 aa:aa:aa:aa:aa:0$i \
1369+
2001:db8:1::$i/64
1370+
check ovn-nbctl lsp-add ts1 lsp-ts1-lr$i \
1371+
-- lsp-set-addresses lsp-ts1-lr$i router \
1372+
-- lsp-set-type lsp-ts1-lr$i router \
1373+
-- lsp-set-options lsp-ts1-lr$i router-port=lrp-lr$i-ts1
1374+
1375+
check ovn-nbctl lrp-add lr$i lrp-lr$i-p$i 00:00:00:00:00:0$i \
1376+
2002:db8:1::$i/64
1377+
1378+
# Create blacklisted LRPs and connect to TS
1379+
check ovn-nbctl lrp-add lr$i lrp-lr$i-p-ext$i \
1380+
11:11:11:11:11:1$i 2003:db8:1::$i/64
1381+
1382+
check ovn-nbctl lrp-add lr$i lrp-lr$i-p-ext2$i \
1383+
22:22:22:22:22:2$i 2004:aaaa:bbb::$i/48
1384+
1385+
# filtered by 2005:1234::/21 - (2005:1000: - 2005:17ff:)
1386+
check ovn-nbctl lrp-add lr$i lrp-lr$i-p-ext3$i \
1387+
33:33:33:33:33:3$i 2005:1734:5678::$i/50
1388+
1389+
# additional not filtered prefix -> different subnet bits
1390+
check ovn-nbctl lrp-add lr$i lrp-lr$i-p-ext4$i \
1391+
44:44:44:44:44:4$i 2005:1834:5678::$i/50
1392+
done
1393+
1394+
for i in 1 2; do
1395+
OVS_WAIT_UNTIL([ovn_as az$i ovn-nbctl lr-route-list lr$i | grep learned])
1396+
done
1397+
1398+
AT_CHECK([ovn_as az1 ovn-nbctl lr-route-list lr1 |
1399+
awk '/learned/{print $1, $2}' ], [0], [dnl
1400+
2002:db8:1::/64 2001:db8:1::2
1401+
2005:1834:5678::/50 2001:db8:1::2
1402+
])
1403+
1404+
for i in 1 2; do
1405+
ovn_as az$i
1406+
1407+
# Drop blacklist
1408+
check ovn-nbctl remove nb_global . options ic-route-blacklist
1409+
done
1410+
1411+
OVS_WAIT_FOR_OUTPUT([ovn_as az1 ovn-nbctl lr-route-list lr1 |
1412+
awk '/learned/{print $1, $2}' | sort ], [0], [dnl
1413+
2002:db8:1::/64 2001:db8:1::2
1414+
2003:db8:1::/64 2001:db8:1::2
1415+
2004:aaaa:bbb::/48 2001:db8:1::2
1416+
2005:1734:5678::/50 2001:db8:1::2
1417+
2005:1834:5678::/50 2001:db8:1::2
1418+
])
1419+
1420+
for i in 1 2; do
1421+
ovn_as az$i
1422+
1423+
check ovn-nbctl set nb_global . \
1424+
options:ic-route-blacklist="2003:db8:1::/64,2004:db8:1::/64"
1425+
1426+
# Create an 'extra' blacklisted LRP and connect to TS
1427+
check ovn-nbctl lrp-add lr$i lrp-lr$i-p-ext5$i \
1428+
55:55:55:55:55:5$i 2004:db8:1::$i/64
1429+
done
1430+
1431+
OVS_WAIT_FOR_OUTPUT([ovn_as az1 ovn-nbctl lr-route-list lr1 |
1432+
awk '/learned/{print $1, $2}' | sort ], [0], [dnl
1433+
2002:db8:1::/64 2001:db8:1::2
1434+
2004:aaaa:bbb::/48 2001:db8:1::2
1435+
2005:1734:5678::/50 2001:db8:1::2
1436+
2005:1834:5678::/50 2001:db8:1::2
1437+
])
1438+
1439+
OVN_CLEANUP_IC([az1], [az2])
1440+
1441+
AT_CLEANUP
1442+
])

0 commit comments

Comments
 (0)