tcp, tap: Correctly advance through packets in tcp_tap_handler()
In both tap4_handler() and tap6_handler(), once we've sorted incoming l3 packets into "sequences", we then step through all the packets in each TCP sequence calling tcp_tap_handler(). Or so it appears. In fact, tcp_tap_handler() doesn't take an index and always looks at packet 0 of the sequence, except when it calls tcp_data_from_tap() to process data packets. It appears to be written with the idea that the struct pool is a queue, from which it consumes packets as it processes them, but that's not how the pool data structure works - they are more like an array of packets. We only get away with this, because setup packets for TCP tend to come in separate batches (because we need to reply in between) and so we only get a bunch of packets for the same connection together when they're data packets (tcp_data_from_tap() has its own loop through packets). Correct this by adding an index parameter to tcp_tap_handler() and altering the loops in tap.c to step through the pool properly. Link: https://bugs.passt.top/show_bug.cgi?id=68 Signed-off-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
This commit is contained in:

committed by
Stefano Brivio

parent
ee58f37db0
commit
043a70b885
25
tap.c
25
tap.c
@@ -707,16 +707,20 @@ append:
|
||||
|
||||
for (j = 0, seq = tap4_l4; j < seq_count; j++, seq++) {
|
||||
struct pool *p = (struct pool *)&seq->p;
|
||||
size_t n = p->count;
|
||||
|
||||
tap_packet_debug(NULL, NULL, seq, 0, NULL, n);
|
||||
tap_packet_debug(NULL, NULL, seq, 0, NULL, p->count);
|
||||
|
||||
if (seq->protocol == IPPROTO_TCP) {
|
||||
size_t k;
|
||||
|
||||
if (c->no_tcp)
|
||||
continue;
|
||||
while ((n -= tcp_tap_handler(c, AF_INET, &seq->saddr,
|
||||
&seq->daddr, p, now)));
|
||||
for (k = 0; k < p->count; )
|
||||
k += tcp_tap_handler(c, AF_INET, &seq->saddr,
|
||||
&seq->daddr, p, k, now);
|
||||
} else if (seq->protocol == IPPROTO_UDP) {
|
||||
size_t n = p->count;
|
||||
|
||||
if (c->no_udp)
|
||||
continue;
|
||||
while ((n -= udp_tap_handler(c, AF_INET, &seq->saddr,
|
||||
@@ -868,16 +872,21 @@ append:
|
||||
|
||||
for (j = 0, seq = tap6_l4; j < seq_count; j++, seq++) {
|
||||
struct pool *p = (struct pool *)&seq->p;
|
||||
size_t n = p->count;
|
||||
|
||||
tap_packet_debug(NULL, NULL, NULL, seq->protocol, seq, n);
|
||||
tap_packet_debug(NULL, NULL, NULL, seq->protocol, seq,
|
||||
p->count);
|
||||
|
||||
if (seq->protocol == IPPROTO_TCP) {
|
||||
size_t k;
|
||||
|
||||
if (c->no_tcp)
|
||||
continue;
|
||||
while ((n -= tcp_tap_handler(c, AF_INET6, &seq->saddr,
|
||||
&seq->daddr, p, now)));
|
||||
for (k = 0; k < p->count; )
|
||||
k += tcp_tap_handler(c, AF_INET6, &seq->saddr,
|
||||
&seq->daddr, p, k, now);
|
||||
} else if (seq->protocol == IPPROTO_UDP) {
|
||||
size_t n = p->count;
|
||||
|
||||
if (c->no_udp)
|
||||
continue;
|
||||
while ((n -= udp_tap_handler(c, AF_INET6, &seq->saddr,
|
||||
|
Reference in New Issue
Block a user