From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: passt.top; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=TuFft29P; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by passt.top (Postfix) with ESMTPS id 366EA5A028A for ; Thu, 12 Jun 2025 17:17:49 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1749741468; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=uPytrV7FSdnpKaf26ZjYtyNFgtZEbLpPykCr/WsZ+/0=; b=TuFft29P9QVi8XlVcLfKFPOfoqwx81YnWVp03E3DmC5D+ffb8sgb8Y3rEOLfkKJblqe1nh bJVI6pcsYHpM5nMCEkXmd4XS7eRB1MPua7w6jlya4DmWzAUdUVrjOkEkO8kzL2+le1Cmh5 a0633k1puvC5lWxfmil9z9stiLtqBI0= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-631-Z3-HYfD3Oi6SwCxkMA86RQ-1; Thu, 12 Jun 2025 11:17:46 -0400 X-MC-Unique: Z3-HYfD3Oi6SwCxkMA86RQ-1 X-Mimecast-MFC-AGG-ID: Z3-HYfD3Oi6SwCxkMA86RQ_1749741466 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-453018b4ddeso5594875e9.3 for ; Thu, 12 Jun 2025 08:17:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749741464; x=1750346264; h=content-transfer-encoding:mime-version:organization:references :in-reply-to:message-id:subject:cc:to:from:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=uPytrV7FSdnpKaf26ZjYtyNFgtZEbLpPykCr/WsZ+/0=; b=mWpbEAJTKV2/6omsGTA48EWBM/JD0V3knWBNOmXhDbnfRVtdYY1pZK0Bpcu3Ew32V9 OUSh6yXA6M49LmC3lc5xnCKBUYC4nveYGdVmrdXW5cLAra5x8H4fXKmaTSK5Nmv+k/As xcfsvAF5w9BTGtrSyjG9RO2l3GmOZsxiq5w2Q+lUxRSUGrJZ1FiQ6PxPdMXV3YvjbWRX iMAxpozMqG7Whe7+NvFBJQ14unlj8ZwaLfTtsxBZ46iccy4RjPksxjVDIj4/hqe0Cy6v 3Rj1jR7VfPsgpoaESRjx/NK6r2/eUSQ9GDt0UTFEQQye/oErwXKlWpoAjGOrKgm5hDsa Q70g== X-Forwarded-Encrypted: i=1; AJvYcCWXDA57jnBAXtqJsIqvsq1e0LihhhP8DkXWX+OiD9/cSW6catCzRArN0ql/O+uVmc4wChTbFc4A7ic=@passt.top X-Gm-Message-State: AOJu0YxQVarFmG/Ulvp6i+hKStoYHJ+KpebKNh8gATl9E4i1W1Aie463 8XhHwzDQCtuN3uf/UCAgS/A1HGrhfrKghuTJqYQ7Fc8bT/QkIaE8Z+lhyZGH+Byecdm0NM20C9s /iwIG8ZkuUXy2JneiINxkhA0yp7qQhOeAmCiUUnt+5LBhYgxU6tJ6rsKP7pswP2OVo2KVICESIp +tfG5IWPNmt7UtE/qM2E3+99hfggn6I1eTKCSZ X-Gm-Gg: ASbGncsdMgxg7d6SmfnBScEX9CdX6YnxuytJQyN1EbPkS+uuaW8R+SVzvgF3ZUH6foh Ahq2li61QRsDaS9vwm1GnWQC10qerZGII/jKE0eyyvHAtfLQoMGIgtJ50zuM+BFfXeeBH6pAm0Y AN+gsvrRTqFQQ/41/rybLhbmiG5PIdBPPsNQH46cP+qS4ubqnJ5TCo+5qWtpZ8h5ExclV75KG8i FZjyaTP7MJfJ18eubJirkUi2VA9Eo73hthXN/MYT6eakbVYvciKt099NS4d0Mq2uGpt62jxgP3V k+B3BFWcPdzIunyuRYdNUrM14fW7Tmd7WZneSnfrvVVtVtrkLq8= X-Received: by 2002:a5d:588c:0:b0:3a4:eeb6:3b6b with SMTP id ffacd0b85a97d-3a5586f1d20mr6851171f8f.43.1749741464551; Thu, 12 Jun 2025 08:17:44 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEQHa5zZQV0T/9UZUgvhuPvsI7PJpdyvK4pe+Bue2H7VVRGqST9gtzxZhoYi8JNzLkyPOMojg== X-Received: by 2002:a5d:588c:0:b0:3a4:eeb6:3b6b with SMTP id ffacd0b85a97d-3a5586f1d20mr6851129f8f.43.1749741464113; Thu, 12 Jun 2025 08:17:44 -0700 (PDT) Received: from maya.myfinge.rs (ifcgrfdd.trafficplex.cloud. [176.103.220.4]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3a5619a84e8sm2227159f8f.42.2025.06.12.08.17.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Jun 2025 08:17:43 -0700 (PDT) Date: Thu, 12 Jun 2025 17:17:42 +0200 From: Stefano Brivio To: Jon Maloy Subject: Re: [PATCH v2 4/8] udp: forward external source mac address through tap interface Message-ID: <20250612171742.0a88e4cf@elisabeth> In-Reply-To: <20250612042152.695879-5-jmaloy@redhat.com> References: <20250612042152.695879-1-jmaloy@redhat.com> <20250612042152.695879-5-jmaloy@redhat.com> Organization: Red Hat X-Mailer: Claws Mail 4.2.0 (GTK 3.24.49; x86_64-pc-linux-gnu) MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: vLWDVMgG3foqOad8mtH5-hSRVuzb-oxSjq-TGTBGFGI_1749741466 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: RVRMMPVNU5L6J43CQIE5DCZA7KRXCGGC X-Message-ID-Hash: RVRMMPVNU5L6J43CQIE5DCZA7KRXCGGC X-MailFrom: sbrivio@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 CC: dgibson@redhat.com, passt-dev@passt.top 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 Thu, 12 Jun 2025 00:21:48 -0400 Jon Maloy wrote: > We forward the incoming mac address through the tap interface when > receiving incoming packets from network local hosts. Packets from > the local host are excepted from this rule, and are still forwarded > with the default passt/pasta mac address as source. > > This is a part of the solution to bug #120 > > Signed-off-by: Jon Maloy > --- > udp.c | 29 +++++++++++++---------------- > 1 file changed, 13 insertions(+), 16 deletions(-) > > diff --git a/udp.c b/udp.c > index 65a52e0..ae8fbaf 100644 > --- a/udp.c > +++ b/udp.c > @@ -133,11 +133,8 @@ static int udp_splice_init[IP_VERSIONS][NUM_PORTS]; > /* UDP header and data for inbound messages */ > static struct udp_payload_t udp_payload[UDP_MAX_FRAMES]; > > -/* Ethernet header for IPv4 frames */ > -static struct ethhdr udp4_eth_hdr; > - > -/* Ethernet header for IPv6 frames */ > -static struct ethhdr udp6_eth_hdr; > +/* Ethernet headers for IPv4 and IPv6 frames */ > +static struct ethhdr udp_eth_hdr[UDP_MAX_FRAMES]; An alternative could be to keep two separated sets of headers. It avoids setting eh->h_proto every time. I'm not sure if it's worth it, perhaps a quick throughput test would be a good idea, just to be sure it's fine (I don't expect any substantial regression). > > /** > * struct udp_meta_t - Pre-cooked headers for UDP packets > @@ -214,8 +211,10 @@ void udp_portmap_clear(void) > */ > void udp_update_l2_buf(const unsigned char *eth_d, const unsigned char *eth_s) > { > - eth_update_mac(&udp4_eth_hdr, eth_d, eth_s); > - eth_update_mac(&udp6_eth_hdr, eth_d, eth_s); > + int i; > + > + for (i = 0; i < UDP_MAX_FRAMES; i++) > + eth_update_mac(&udp_eth_hdr[i], eth_d, eth_s); > } > > /** > @@ -238,6 +237,7 @@ static void udp_iov_init_one(const struct ctx *c, size_t i) > > *siov = IOV_OF_LVALUE(payload->data); > > + tiov[UDP_IOV_ETH] = IOV_OF_LVALUE(udp_eth_hdr[i]); > tiov[UDP_IOV_TAP] = tap_hdr_iov(c, &meta->taph); > tiov[UDP_IOV_PAYLOAD].iov_base = payload; > > @@ -253,9 +253,6 @@ static void udp_iov_init(const struct ctx *c) > { > size_t i; > > - udp4_eth_hdr.h_proto = htons_constant(ETH_P_IP); > - udp6_eth_hdr.h_proto = htons_constant(ETH_P_IPV6); > - > for (i = 0; i < UDP_MAX_FRAMES; i++) > udp_iov_init_one(c, i); > } > @@ -362,21 +359,21 @@ static void udp_tap_prepare(const struct mmsghdr *mmh, > struct iovec (*tap_iov)[UDP_NUM_IOVS] = &udp_l2_iov[idx]; > struct udp_payload_t *bp = &udp_payload[idx]; > struct udp_meta_t *bm = &udp_meta[idx]; > + struct ethhdr *eh = (*tap_iov)[UDP_IOV_ETH].iov_base; Nit: this could be moved after the declaration of tap_iov, so that we keep initialisers from longest to shortest. > size_t l4len; > > + eth_update_mac(eh, 0, toside->mac); > if (!inany_v4(&toside->eaddr) || !inany_v4(&toside->oaddr)) { > l4len = udp_update_hdr6(&bm->ip6h, bp, toside, > mmh[idx].msg_len, no_udp_csum); > - tap_hdr_update(&bm->taph, l4len + sizeof(bm->ip6h) + > - sizeof(udp6_eth_hdr)); > - (*tap_iov)[UDP_IOV_ETH] = IOV_OF_LVALUE(udp6_eth_hdr); > + tap_hdr_update(&bm->taph, l4len + sizeof(bm->ip6h) + ETH_HLEN); > + eh->h_proto = htons_constant(ETH_P_IPV6); > (*tap_iov)[UDP_IOV_IP] = IOV_OF_LVALUE(bm->ip6h); > } else { > l4len = udp_update_hdr4(&bm->ip4h, bp, toside, > mmh[idx].msg_len, no_udp_csum); > - tap_hdr_update(&bm->taph, l4len + sizeof(bm->ip4h) + > - sizeof(udp4_eth_hdr)); > - (*tap_iov)[UDP_IOV_ETH] = IOV_OF_LVALUE(udp4_eth_hdr); > + tap_hdr_update(&bm->taph, l4len + sizeof(bm->ip4h) + ETH_HLEN); > + eh->h_proto = htons_constant(ETH_P_IP); > (*tap_iov)[UDP_IOV_IP] = IOV_OF_LVALUE(bm->ip4h); > } > (*tap_iov)[UDP_IOV_PAYLOAD].iov_len = l4len; -- Stefano