From: David Gibson <david@gibson.dropbear.id.au>
To: Laurent Vivier <lvivier@redhat.com>
Cc: passt-dev@passt.top
Subject: Re: [PATCH v5 5/9] udp: little cleanup in udp_update_hdrX() to prepare future changes
Date: Mon, 4 Mar 2024 11:46:25 +1100 [thread overview]
Message-ID: <ZeUZ4WWoa9-kNubZ@zatzit> (raw)
In-Reply-To: <20240303135114.1023026-6-lvivier@redhat.com>
[-- Attachment #1: Type: text/plain, Size: 4735 bytes --]
On Sun, Mar 03, 2024 at 02:51:10PM +0100, Laurent Vivier wrote:
> in udp_update_hdr4():
>
> Assign the source address to src, either b->s_in.sin_addr,
> c->ip4.dns_match or c->ip4.gw and then set b->iph.saddr to src->s_addr.
>
> in udp_update_hdr6():
>
> Assign the source address to src, either b->s_in6.sin6_addr,
> c->ip6.dns_match, c->ip6.gw or c->ip6.addr_ll.
> Assign the destination to dst, either c->ip6.addr_seen or
> &c->ip6.addr_ll_seen.
> Then set dst to b->ip6h.daddr and src to b->ip6h.saddr.
>
> Signed-off-by: Laurent Vivier <lvivier@redhat.com>
Heh, this does something quite similar to one of the patches in my
small udp cleanups series.
Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
I don't want to delay this further, so I'll rebase my other UDP work
on top of this.
> ---
>
> Notes:
> v5:
> - new patch to introduce the use of struct in_addr with
> csum_ip4_header()
>
> udp.c | 39 +++++++++++++++++++--------------------
> 1 file changed, 19 insertions(+), 20 deletions(-)
>
> diff --git a/udp.c b/udp.c
> index 26774df7018c..2b41a1bdff61 100644
> --- a/udp.c
> +++ b/udp.c
> @@ -588,7 +588,7 @@ static size_t udp_update_hdr4(const struct ctx *c, int n, in_port_t dstport,
> const struct timespec *now)
> {
> struct udp4_l2_buf_t *b = &udp4_l2_buf[n];
> - struct in_addr *src;
> + const struct in_addr *src;
> in_port_t src_port;
> size_t ip_len;
>
> @@ -602,10 +602,9 @@ static size_t udp_update_hdr4(const struct ctx *c, int n, in_port_t dstport,
>
> if (!IN4_IS_ADDR_UNSPECIFIED(&c->ip4.dns_match) &&
> IN4_ARE_ADDR_EQUAL(src, &c->ip4.dns_host) && src_port == 53) {
> - b->iph.saddr = c->ip4.dns_match.s_addr;
> + src = &c->ip4.dns_match;
> } else if (IN4_IS_ADDR_LOOPBACK(src) ||
> IN4_ARE_ADDR_EQUAL(src, &c->ip4.addr_seen)) {
> - b->iph.saddr = c->ip4.gw.s_addr;
> udp_tap_map[V4][src_port].ts = now->tv_sec;
> udp_tap_map[V4][src_port].flags |= PORT_LOCAL;
>
> @@ -615,9 +614,10 @@ static size_t udp_update_hdr4(const struct ctx *c, int n, in_port_t dstport,
> udp_tap_map[V4][src_port].flags &= ~PORT_LOOPBACK;
>
> bitmap_set(udp_act[V4][UDP_ACT_TAP], src_port);
> - } else {
> - b->iph.saddr = src->s_addr;
> +
> + src = &c->ip4.gw;
> }
> + b->iph.saddr = src->s_addr;
>
> udp_update_check4(b);
> b->uh.source = b->s_in.sin_port;
> @@ -640,10 +640,11 @@ static size_t udp_update_hdr6(const struct ctx *c, int n, in_port_t dstport,
> const struct timespec *now)
> {
> struct udp6_l2_buf_t *b = &udp6_l2_buf[n];
> - struct in6_addr *src;
> + const struct in6_addr *src, *dst;
> in_port_t src_port;
> size_t ip_len;
>
> + dst = &c->ip6.addr_seen;
> src = &b->s_in6.sin6_addr;
> src_port = ntohs(b->s_in6.sin6_port);
>
> @@ -652,23 +653,14 @@ static size_t udp_update_hdr6(const struct ctx *c, int n, in_port_t dstport,
> b->ip6h.payload_len = htons(udp6_l2_mh_sock[n].msg_len + sizeof(b->uh));
>
> if (IN6_IS_ADDR_LINKLOCAL(src)) {
> - b->ip6h.daddr = c->ip6.addr_ll_seen;
> - b->ip6h.saddr = b->s_in6.sin6_addr;
> + dst = &c->ip6.addr_ll_seen;
> } else if (!IN6_IS_ADDR_UNSPECIFIED(&c->ip6.dns_match) &&
> IN6_ARE_ADDR_EQUAL(src, &c->ip6.dns_host) &&
> src_port == 53) {
> - b->ip6h.daddr = c->ip6.addr_seen;
> - b->ip6h.saddr = c->ip6.dns_match;
> + src = &c->ip6.dns_match;
> } else if (IN6_IS_ADDR_LOOPBACK(src) ||
> IN6_ARE_ADDR_EQUAL(src, &c->ip6.addr_seen) ||
> IN6_ARE_ADDR_EQUAL(src, &c->ip6.addr)) {
> - b->ip6h.daddr = c->ip6.addr_ll_seen;
> -
> - if (IN6_IS_ADDR_LINKLOCAL(&c->ip6.gw))
> - b->ip6h.saddr = c->ip6.gw;
> - else
> - b->ip6h.saddr = c->ip6.addr_ll;
> -
> udp_tap_map[V6][src_port].ts = now->tv_sec;
> udp_tap_map[V6][src_port].flags |= PORT_LOCAL;
>
> @@ -683,10 +675,17 @@ static size_t udp_update_hdr6(const struct ctx *c, int n, in_port_t dstport,
> udp_tap_map[V6][src_port].flags &= ~PORT_GUA;
>
> bitmap_set(udp_act[V6][UDP_ACT_TAP], src_port);
> - } else {
> - b->ip6h.daddr = c->ip6.addr_seen;
> - b->ip6h.saddr = b->s_in6.sin6_addr;
> +
> + dst = &c->ip6.addr_ll_seen;
> +
> + if (IN6_IS_ADDR_LINKLOCAL(&c->ip6.gw))
> + src = &c->ip6.gw;
> + else
> + src = &c->ip6.addr_ll;
> +
> }
> + b->ip6h.daddr = *dst;
> + b->ip6h.saddr = *src;
>
> b->uh.source = b->s_in6.sin6_port;
> b->uh.dest = htons(dstport);
--
David Gibson | I'll have my music baroque, and my code
david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_
| _way_ _around_!
http://www.ozlabs.org/~dgibson
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next prev parent reply other threads:[~2024-03-04 0:55 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-03 13:51 [PATCH v5 0/9] Add vhost-user support to passt (part 1) Laurent Vivier
2024-03-03 13:51 ` [PATCH v5 1/9] pcap: add pcap_iov() Laurent Vivier
2024-03-03 13:51 ` [PATCH v5 2/9] checksum: align buffers Laurent Vivier
2024-03-03 13:51 ` [PATCH v5 3/9] checksum: add csum_iov() Laurent Vivier
2024-03-03 13:51 ` [PATCH v5 4/9] util: move IP stuff from util.[ch] to ip.[ch] Laurent Vivier
2024-03-03 13:51 ` [PATCH v5 5/9] udp: little cleanup in udp_update_hdrX() to prepare future changes Laurent Vivier
2024-03-04 0:46 ` David Gibson [this message]
2024-03-03 13:51 ` [PATCH v5 6/9] checksum: use csum_ip4_header() in udp.c and tcp.c Laurent Vivier
2024-03-03 13:51 ` [PATCH v5 7/9] checksum: introduce functions to compute the header part checksum for TCP/UDP Laurent Vivier
2024-03-04 0:52 ` David Gibson
2024-03-03 13:51 ` [PATCH v5 8/9] tap: make tap_update_mac() generic Laurent Vivier
2024-03-03 13:51 ` [PATCH v5 9/9] tcp: Introduce ipv4_fill_headers()/ipv6_fill_headers() Laurent Vivier
2024-03-04 0:54 ` David Gibson
2024-03-05 22:12 ` [PATCH v5 0/9] Add vhost-user support to passt (part 1) Stefano Brivio
2024-03-06 3:22 ` David Gibson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ZeUZ4WWoa9-kNubZ@zatzit \
--to=david@gibson.dropbear.id.au \
--cc=lvivier@redhat.com \
--cc=passt-dev@passt.top \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://passt.top/passt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for IMAP folder(s).