Skip to content

Commit 6c15e96

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> (cherry picked from commit 7875069)
1 parent d74c2ce commit 6c15e96

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
@@ -1058,12 +1058,15 @@ prefix_is_black_listed(const struct smap *nb_options,
10581058
continue;
10591059
}
10601060
} else {
1061-
struct in6_addr mask = ipv6_create_mask(bl_plen);
1062-
for (int i = 0; i < 16 && mask.s6_addr[i] != 0; i++) {
1063-
if ((prefix->s6_addr[i] & mask.s6_addr[i])
1064-
!= (bl_prefix.s6_addr[i] & mask.s6_addr[i])) {
1065-
continue;
1066-
}
1061+
struct in6_addr mask = ipv6_create_mask(plen);
1062+
/* First calculate the difference between bl_prefix and prefix, so
1063+
* use the bl mask to ensure prefixes are correctly validated.
1064+
* e.g.: 2005:1734:5678::/50 is a subnet of 2005:1234::/21 */
1065+
struct in6_addr m_prefixes = ipv6_addr_bitand(prefix, &bl_prefix);
1066+
struct in6_addr m_prefix = ipv6_addr_bitand(&m_prefixes, &mask);
1067+
struct in6_addr m_bl_prefix = ipv6_addr_bitand(&bl_prefix, &mask);
1068+
if (!ipv6_addr_equals(&m_prefix, &m_bl_prefix)) {
1069+
continue;
10671070
}
10681071
}
10691072
matched = true;

tests/ovn-ic.at

+99
Original file line numberDiff line numberDiff line change
@@ -1206,3 +1206,102 @@ OVS_WAIT_FOR_OUTPUT([ovn_as az2 ovn-nbctl lr-route-list lr12 | grep dst-ip | sor
12061206

12071207
AT_CLEANUP
12081208
])
1209+
1210+
OVN_FOR_EACH_NORTHD([
1211+
AT_SETUP([ovn-ic -- route sync -- IPv6 blacklist filter])
1212+
AT_KEYWORDS([IPv6-route-sync-blacklist])
1213+
1214+
ovn_init_ic_db
1215+
check ovn-ic-nbctl ts-add ts1
1216+
1217+
for i in 1 2; do
1218+
ovn_start az$i
1219+
ovn_as az$i
1220+
1221+
# Enable route learning at AZ level
1222+
check ovn-nbctl set nb_global . options:ic-route-learn=true
1223+
# Enable route advertising at AZ level
1224+
check ovn-nbctl set nb_global . options:ic-route-adv=true
1225+
# Enable blacklist single filter for IPv6
1226+
check ovn-nbctl set nb_global . options:ic-route-blacklist=" \
1227+
2003:db8:1::/64,2004:aaaa::/32,2005:1234::/21"
1228+
1229+
OVS_WAIT_UNTIL([ovn-nbctl show | grep ts1])
1230+
1231+
# Create LRP and connect to TS
1232+
check ovn-nbctl lr-add lr$i
1233+
check ovn-nbctl lrp-add lr$i lrp-lr$i-ts1 aa:aa:aa:aa:aa:0$i \
1234+
2001:db8:1::$i/64
1235+
check ovn-nbctl lsp-add ts1 lsp-ts1-lr$i \
1236+
-- lsp-set-addresses lsp-ts1-lr$i router \
1237+
-- lsp-set-type lsp-ts1-lr$i router \
1238+
-- lsp-set-options lsp-ts1-lr$i router-port=lrp-lr$i-ts1
1239+
1240+
check ovn-nbctl lrp-add lr$i lrp-lr$i-p$i 00:00:00:00:00:0$i \
1241+
2002:db8:1::$i/64
1242+
1243+
# Create blacklisted LRPs and connect to TS
1244+
check ovn-nbctl lrp-add lr$i lrp-lr$i-p-ext$i \
1245+
11:11:11:11:11:1$i 2003:db8:1::$i/64
1246+
1247+
check ovn-nbctl lrp-add lr$i lrp-lr$i-p-ext2$i \
1248+
22:22:22:22:22:2$i 2004:aaaa:bbb::$i/48
1249+
1250+
# filtered by 2005:1234::/21 - (2005:1000: - 2005:17ff:)
1251+
check ovn-nbctl lrp-add lr$i lrp-lr$i-p-ext3$i \
1252+
33:33:33:33:33:3$i 2005:1734:5678::$i/50
1253+
1254+
# additional not filtered prefix -> different subnet bits
1255+
check ovn-nbctl lrp-add lr$i lrp-lr$i-p-ext4$i \
1256+
44:44:44:44:44:4$i 2005:1834:5678::$i/50
1257+
done
1258+
1259+
for i in 1 2; do
1260+
OVS_WAIT_UNTIL([ovn_as az$i ovn-nbctl lr-route-list lr$i | grep learned])
1261+
done
1262+
1263+
AT_CHECK([ovn_as az1 ovn-nbctl lr-route-list lr1 |
1264+
awk '/learned/{print $1, $2}' ], [0], [dnl
1265+
2002:db8:1::/64 2001:db8:1::2
1266+
2005:1834:5678::/50 2001:db8:1::2
1267+
])
1268+
1269+
for i in 1 2; do
1270+
ovn_as az$i
1271+
1272+
# Drop blacklist
1273+
check ovn-nbctl remove nb_global . options ic-route-blacklist
1274+
done
1275+
1276+
OVS_WAIT_FOR_OUTPUT([ovn_as az1 ovn-nbctl lr-route-list lr1 |
1277+
awk '/learned/{print $1, $2}' | sort ], [0], [dnl
1278+
2002:db8:1::/64 2001:db8:1::2
1279+
2003:db8:1::/64 2001:db8:1::2
1280+
2004:aaaa:bbb::/48 2001:db8:1::2
1281+
2005:1734:5678::/50 2001:db8:1::2
1282+
2005:1834:5678::/50 2001:db8:1::2
1283+
])
1284+
1285+
for i in 1 2; do
1286+
ovn_as az$i
1287+
1288+
check ovn-nbctl set nb_global . \
1289+
options:ic-route-blacklist="2003:db8:1::/64,2004:db8:1::/64"
1290+
1291+
# Create an 'extra' blacklisted LRP and connect to TS
1292+
check ovn-nbctl lrp-add lr$i lrp-lr$i-p-ext5$i \
1293+
55:55:55:55:55:5$i 2004:db8:1::$i/64
1294+
done
1295+
1296+
OVS_WAIT_FOR_OUTPUT([ovn_as az1 ovn-nbctl lr-route-list lr1 |
1297+
awk '/learned/{print $1, $2}' | sort ], [0], [dnl
1298+
2002:db8:1::/64 2001:db8:1::2
1299+
2004:aaaa:bbb::/48 2001:db8:1::2
1300+
2005:1734:5678::/50 2001:db8:1::2
1301+
2005:1834:5678::/50 2001:db8:1::2
1302+
])
1303+
1304+
OVN_CLEANUP_IC([az1], [az2])
1305+
1306+
AT_CLEANUP
1307+
])

0 commit comments

Comments
 (0)