From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by passt.top (Postfix) with ESMTP id 39F445A026F for ; Fri, 2 Feb 2024 15:29:49 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1706884188; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=RLZNOdZ7/OnpjV8HGj/p1oczuMo7cfAjH8xvJgWPQrQ=; b=djz+3Ih4nhO0kr0J4ho8gle6zu3+Z2xrvAMGd1EGdeXqf5LLxGsOD9vZ7Pb3MYM0D15qkQ HA2X3CShxc9h47Ig766OfS3qPayDn6+VwOeTDg+O1V6SQw1nZT78XBgHJ64l5y+9kXPkrm hzrqgptbDwQGdz4MykyEvF27Vl7Awuo= Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-495-a2WP-ds6MhCQ7kzkWvQlNg-1; Fri, 02 Feb 2024 09:29:46 -0500 X-MC-Unique: a2WP-ds6MhCQ7kzkWvQlNg-1 Received: by mail-qk1-f200.google.com with SMTP id af79cd13be357-78315f41c6cso246385785a.1 for ; Fri, 02 Feb 2024 06:29:46 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706884185; x=1707488985; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=RLZNOdZ7/OnpjV8HGj/p1oczuMo7cfAjH8xvJgWPQrQ=; b=Uah/xjwa0WGPjtIoupz5FOnWv5e58/PqNScyNPQ9v3yx/EoF4Q8kcHC4MWqXOrmHPs pTRNTA12gehuppCHoVt/nTmtYDurJFzxo+41rGba+Eos7XHMORkt00oOzGIP74ZXIpfi 03lUC5dzJ7iyfbI/ElozIeL7J7SY3jZLmjVQn+85b9HRWYiNFYLRGT9JNfyoKVCaGZtA TagaWA2DwmpWvckpueHum4QiZFStjEwvAmiOdBcfnG0uFEVBgr9TJys2+4o75+rjUnbg DQVZhXSjxfpk3ISTar++4VlCubRLBo7YfO75xcUWUX9gI/cuu9yk3/nKx2GC9CJcniuX QI+g== X-Gm-Message-State: AOJu0YwIeDI0u0r8I8oAxMSMy9EEdN99T4DmRhxUhPMgqpPtHMdGczI4 D25ZiZxYXFmZzFF8D5V8ahhLC0ag24xqWm5F/StSyin9kneMGWjVNo3QjSu4o55RLD/PHBpRUSb jweN3ny88vLNJSVBh2pR+FHiw0+cuff8iaa7Eh2ep67yqWqY7dR4/lvQxaTH+1dF0/9Qkn8XHeS 7g7r+Hgq2oINSVctmOpLNF+R//ChvZYg8D X-Received: by 2002:a05:620a:450f:b0:783:915c:1fc4 with SMTP id t15-20020a05620a450f00b00783915c1fc4mr6891657qkp.20.1706884185600; Fri, 02 Feb 2024 06:29:45 -0800 (PST) X-Google-Smtp-Source: AGHT+IEif/bElJtd9qNuZcC4uQK6pcjQU10mgCMUVMTWblcW7XYjlWXiX/vkHvy7Rc2qj3WCsLGObQ== X-Received: by 2002:a05:620a:450f:b0:783:915c:1fc4 with SMTP id t15-20020a05620a450f00b00783915c1fc4mr6891636qkp.20.1706884185249; Fri, 02 Feb 2024 06:29:45 -0800 (PST) Received: from [192.168.100.30] ([82.142.8.70]) by smtp.gmail.com with ESMTPSA id ay14-20020a05620a178e00b00783df78821dsm719103qkb.25.2024.02.02.06.29.44 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 02 Feb 2024 06:29:44 -0800 (PST) Message-ID: <7458c407-4683-4df8-91e7-62ee39377756@redhat.com> Date: Fri, 2 Feb 2024 15:29:42 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 13/24] tap: export pool_flush()/tapX_handler()/packet_add() To: passt-dev@passt.top References: <20240202141151.3762941-1-lvivier@redhat.com> <20240202141151.3762941-14-lvivier@redhat.com> From: Laurent Vivier In-Reply-To: <20240202141151.3762941-14-lvivier@redhat.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Message-ID-Hash: 6YYDKL3EAUWEEIUSELGTNWYFKB2W3D7U X-Message-ID-Hash: 6YYDKL3EAUWEEIUSELGTNWYFKB2W3D7U X-MailFrom: lvivier@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: On 2/2/24 15:11, Laurent Vivier wrote: > From: Laurent Vivier > > Signed-off-by: Laurent Vivier I will fix S-o-B and author in v2. Thanks; Laurent > --- > tap.c | 98 +++++++++++++++++++++++++++++------------------------------ > tap.h | 7 +++++ > 2 files changed, 56 insertions(+), 49 deletions(-) > > diff --git a/tap.c b/tap.c > index 29f389057ac1..5b1b61550c13 100644 > --- a/tap.c > +++ b/tap.c > @@ -911,6 +911,45 @@ append: > return in->count; > } > > +void pool_flush_all(void) > +{ > + pool_flush(pool_tap4); > + pool_flush(pool_tap6); > +} > + > +void tap_handler_all(struct ctx *c, const struct timespec *now) > +{ > + tap4_handler(c, pool_tap4, now); > + tap6_handler(c, pool_tap6, now); > +} > + > +void packet_add_all_do(struct ctx *c, ssize_t len, char *p, > + const char *func, int line) > +{ > + const struct ethhdr *eh; > + > + pcap(p, len); > + > + eh = (struct ethhdr *)p; > + > + if (memcmp(c->mac_guest, eh->h_source, ETH_ALEN)) { > + memcpy(c->mac_guest, eh->h_source, ETH_ALEN); > + proto_update_l2_buf(c->mac_guest, NULL); > + } > + > + switch (ntohs(eh->h_proto)) { > + case ETH_P_ARP: > + case ETH_P_IP: > + packet_add_do(pool_tap4, len, p, func, line); > + break; > + case ETH_P_IPV6: > + packet_add_do(pool_tap6, len, p, func, line); > + break; > + default: > + break; > + } > +} > + > /** > * tap_sock_reset() - Handle closing or failure of connect AF_UNIX socket > * @c: Execution context > @@ -937,7 +976,6 @@ static void tap_sock_reset(struct ctx *c) > void tap_handler_passt(struct ctx *c, uint32_t events, > const struct timespec *now) > { > - const struct ethhdr *eh; > ssize_t n, rem; > char *p; > > @@ -950,8 +988,7 @@ redo: > p = pkt_buf; > rem = 0; > > - pool_flush(pool_tap4); > - pool_flush(pool_tap6); > + pool_flush_all(); > > n = recv(c->fd_tap, p, TAP_BUF_FILL, MSG_DONTWAIT); > if (n < 0) { > @@ -978,37 +1015,18 @@ redo: > /* Complete the partial read above before discarding a malformed > * frame, otherwise the stream will be inconsistent. > */ > - if (len < (ssize_t)sizeof(*eh) || len > (ssize_t)ETH_MAX_MTU) > + if (len < (ssize_t)sizeof(struct ethhdr) || > + len > (ssize_t)ETH_MAX_MTU) > goto next; > > - pcap(p, len); > - > - eh = (struct ethhdr *)p; > - > - if (memcmp(c->mac_guest, eh->h_source, ETH_ALEN)) { > - memcpy(c->mac_guest, eh->h_source, ETH_ALEN); > - proto_update_l2_buf(c->mac_guest, NULL); > - } > - > - switch (ntohs(eh->h_proto)) { > - case ETH_P_ARP: > - case ETH_P_IP: > - packet_add(pool_tap4, len, p); > - break; > - case ETH_P_IPV6: > - packet_add(pool_tap6, len, p); > - break; > - default: > - break; > - } > + packet_add_all(c, len, p); > > next: > p += len; > n -= len; > } > > - tap4_handler(c, pool_tap4, now); > - tap6_handler(c, pool_tap6, now); > + tap_handler_all(c, now); > > /* We can't use EPOLLET otherwise. */ > if (rem) > @@ -1033,35 +1051,18 @@ void tap_handler_pasta(struct ctx *c, uint32_t events, > redo: > n = 0; > > - pool_flush(pool_tap4); > - pool_flush(pool_tap6); > + pool_flush_all(); > restart: > while ((len = read(c->fd_tap, pkt_buf + n, TAP_BUF_BYTES - n)) > 0) { > - const struct ethhdr *eh = (struct ethhdr *)(pkt_buf + n); > > - if (len < (ssize_t)sizeof(*eh) || len > (ssize_t)ETH_MAX_MTU) { > + if (len < (ssize_t)sizeof(struct ethhdr) || > + len > (ssize_t)ETH_MAX_MTU) { > n += len; > continue; > } > > - pcap(pkt_buf + n, len); > > - if (memcmp(c->mac_guest, eh->h_source, ETH_ALEN)) { > - memcpy(c->mac_guest, eh->h_source, ETH_ALEN); > - proto_update_l2_buf(c->mac_guest, NULL); > - } > - > - switch (ntohs(eh->h_proto)) { > - case ETH_P_ARP: > - case ETH_P_IP: > - packet_add(pool_tap4, len, pkt_buf + n); > - break; > - case ETH_P_IPV6: > - packet_add(pool_tap6, len, pkt_buf + n); > - break; > - default: > - break; > - } > + packet_add_all(c, len, pkt_buf + n); > > if ((n += len) == TAP_BUF_BYTES) > break; > @@ -1072,8 +1073,7 @@ restart: > > ret = errno; > > - tap4_handler(c, pool_tap4, now); > - tap6_handler(c, pool_tap6, now); > + tap_handler_all(c, now); > > if (len > 0 || ret == EAGAIN) > return; > diff --git a/tap.h b/tap.h > index 437b9aa2b43f..7157ef37ee6e 100644 > --- a/tap.h > +++ b/tap.h > @@ -82,5 +82,12 @@ void tap_handler_pasta(struct ctx *c, uint32_t events, > void tap_handler_passt(struct ctx *c, uint32_t events, > const struct timespec *now); > void tap_sock_init(struct ctx *c); > +void pool_flush_all(void); > +void tap_handler_all(struct ctx *c, const struct timespec *now); > + > +void packet_add_do(struct pool *p, size_t len, const char *start, > + const char *func, int line); > +#define packet_add_all(p, len, start) \ > + packet_add_all_do(p, len, start, __func__, __LINE__) > > #endif /* TAP_H */