Skip to content

Commit 41a8b58

Browse files
simonartxavierSimon Horman
authored andcommitted
conntrack: Fix flush not flushing all elements.
On netdev datapath, when a ct element was cleaned, the cmap could be shrinked, potentially causing some elements to be skipped in the flush iteration. Fixes: 967bb5c ("conntrack: Add rcu support.") Signed-off-by: Xavier Simonart <xsimonar@redhat.com> Acked-by: Mike Pattrick <mkp@redhat.com> Signed-off-by: Simon Horman <horms@ovn.org>
1 parent ad92b0d commit 41a8b58

3 files changed

Lines changed: 64 additions & 11 deletions

File tree

lib/conntrack.c

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2632,25 +2632,19 @@ conntrack_dump_start(struct conntrack *ct, struct conntrack_dump *dump,
26322632

26332633
dump->ct = ct;
26342634
*ptot_bkts = 1; /* Need to clean up the callers. */
2635+
dump->cursor = cmap_cursor_start(&ct->conns);
26352636
return 0;
26362637
}
26372638

26382639
int
26392640
conntrack_dump_next(struct conntrack_dump *dump, struct ct_dpif_entry *entry)
26402641
{
2641-
struct conntrack *ct = dump->ct;
26422642
long long now = time_msec();
26432643

2644-
for (;;) {
2645-
struct cmap_node *cm_node = cmap_next_position(&ct->conns,
2646-
&dump->cm_pos);
2647-
if (!cm_node) {
2648-
break;
2649-
}
2650-
struct conn_key_node *keyn;
2651-
struct conn *conn;
2644+
struct conn_key_node *keyn;
2645+
struct conn *conn;
26522646

2653-
INIT_CONTAINER(keyn, cm_node, cm_node);
2647+
CMAP_CURSOR_FOR_EACH_CONTINUE (keyn, cm_node, &dump->cursor) {
26542648
if (keyn->dir != CT_DIR_FWD) {
26552649
continue;
26562650
}

lib/conntrack.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ struct conntrack_dump {
101101
struct conntrack *ct;
102102
unsigned bucket;
103103
union {
104-
struct cmap_position cm_pos;
105104
struct hmap_position hmap_pos;
105+
struct cmap_cursor cursor;
106106
};
107107
bool filter_zone;
108108
uint16_t zone;

tests/system-traffic.at

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7913,6 +7913,65 @@ AT_CHECK([ovs-pcap client.pcap | grep 000000002010000000002000], [0], [dnl
79137913
OVS_TRAFFIC_VSWITCHD_STOP
79147914
AT_CLEANUP
79157915

7916+
AT_SETUP([conntrack - Flush many conntrack entries by port])
7917+
CHECK_CONNTRACK()
7918+
OVS_TRAFFIC_VSWITCHD_START()
7919+
7920+
ADD_NAMESPACES(at_ns0, at_ns1)
7921+
7922+
ADD_VETH(p0, at_ns0, br0, "10.1.1.1/24")
7923+
ADD_VETH(p1, at_ns1, br0, "10.1.1.2/24")
7924+
7925+
AT_DATA([flows.txt], [dnl
7926+
priority=100,in_port=1,udp,action=ct(zone=1,commit),2
7927+
])
7928+
7929+
AT_CHECK([ovs-ofctl --bundle add-flows br0 flows.txt])
7930+
7931+
dnl 20 packets from port 1 and 1 packet from port 2.
7932+
flow_l3="\
7933+
eth_src=50:54:00:00:00:09,eth_dst=50:54:00:00:00:0a,dl_type=0x0800,\
7934+
nw_src=10.1.1.1,nw_dst=10.1.1.2,nw_proto=17,nw_ttl=64,nw_frag=no"
7935+
7936+
head="50540000000a50540000000908004500005c000000004011648d0a0101010a010102"
7937+
len=72
7938+
base_csum=1366
7939+
tail="000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f\
7940+
202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f"
7941+
7942+
dst_port=1
7943+
for src_port in $(seq 1 20); do
7944+
csum=$((base_csum - src_port - dst_port))
7945+
frame=$(printf "%s%04x%04x%04x%04x%s" $head 1 $src_port $len $csum $tail)
7946+
AT_CHECK([ovs-ofctl -O OpenFlow13 packet-out br0 "in_port=1 packet=$frame actions=resubmit(,0)"])
7947+
done
7948+
7949+
src_port=2
7950+
dst_port=1
7951+
csum=$((base_csum - src_port - dst_port))
7952+
frame=$(printf "%s%04x%04x%04x%04x%s" $head $src_port $dst_port $len $csum $tail)
7953+
AT_CHECK([ovs-ofctl -O OpenFlow13 packet-out br0 "in_port=1 packet=$frame actions=resubmit(,0)"])
7954+
7955+
: > conntrack
7956+
7957+
for i in $(seq 1 20); do
7958+
echo "udp,orig=(src=10.1.1.1,dst=10.1.1.2,sport=1,dport=${i}),reply=(src=10.1.1.2,dst=10.1.1.1,sport=${i},dport=1),zone=1" >> conntrack
7959+
done
7960+
echo "udp,orig=(src=10.1.1.1,dst=10.1.1.2,sport=2,dport=1),reply=(src=10.1.1.2,dst=10.1.1.1,sport=1,dport=2),zone=1" >> conntrack
7961+
7962+
sort conntrack > expout
7963+
7964+
AT_CHECK([ovs-appctl dpctl/dump-conntrack zone=1 | grep -F "src=10.1.1.1," | sort ], [0], [expout])
7965+
7966+
dnl Check that flushing conntrack by port 1 flush all ct for port 1 but keeps ct for port 2.
7967+
AT_CHECK([ovs-appctl dpctl/flush-conntrack zone=1 'ct_nw_proto=17,ct_tp_src=1'])
7968+
AT_CHECK([ovs-appctl dpctl/dump-conntrack zone=1 | grep -F "src=10.1.1.1," | sort ], [0], [dnl
7969+
udp,orig=(src=10.1.1.1,dst=10.1.1.2,sport=2,dport=1),reply=(src=10.1.1.2,dst=10.1.1.1,sport=1,dport=2),zone=1
7970+
])
7971+
7972+
OVS_TRAFFIC_VSWITCHD_STOP
7973+
AT_CLEANUP
7974+
79167975
AT_BANNER([IGMP])
79177976

79187977
AT_SETUP([IGMP - flood under normal action])

0 commit comments

Comments
 (0)