From: David Gibson <david@gibson.dropbear.id.au>
To: Stefano Brivio <sbrivio@redhat.com>, passt-dev@passt.top
Cc: David Gibson <david@gibson.dropbear.id.au>
Subject: [PATCH 5/8] tcp, udp: Don't pre-fill IPv4 destination address in headers
Date: Fri, 28 Jul 2023 19:48:28 +1000 [thread overview]
Message-ID: <20230728094831.4097571-6-david@gibson.dropbear.id.au> (raw)
In-Reply-To: <20230728094831.4097571-1-david@gibson.dropbear.id.au>
Because packets sent on the tap interface will always be going to the
guest/namespace, we more-or-less know what address they'll be going to. So
we pre-fill this destination address in our header buffers for IPv4. We
can't do the same for IPv6 because we could need either the global or
link-local address for the guest. In future we're going to want more
flexibility for the destination address, so this pre-filling will get in
the way.
Change the flow so we always fill in the IPv4 destination address for each
packet, rather than prefilling it from proto_update_l2_buf(). In fact for
TCP we already redundantly filled the destination for each packet anyway.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
---
passt.c | 10 ++++------
passt.h | 4 ++--
pasta.c | 2 +-
tap.c | 8 +++-----
tcp.c | 8 +-------
tcp.h | 3 +--
udp.c | 9 ++-------
udp.h | 3 +--
8 files changed, 15 insertions(+), 32 deletions(-)
diff --git a/passt.c b/passt.c
index 3b9b36b..05672eb 100644
--- a/passt.c
+++ b/passt.c
@@ -135,13 +135,11 @@ static void timer_init(struct ctx *c, const struct timespec *now)
* proto_update_l2_buf() - Update scatter-gather L2 buffers in protocol handlers
* @eth_d: Ethernet destination address, NULL if unchanged
* @eth_s: Ethernet source address, NULL if unchanged
- * @ip_da: Pointer to IPv4 destination address, NULL if unchanged
*/
-void proto_update_l2_buf(const unsigned char *eth_d, const unsigned char *eth_s,
- const struct in_addr *ip_da)
+void proto_update_l2_buf(const unsigned char *eth_d, const unsigned char *eth_s)
{
- tcp_update_l2_buf(eth_d, eth_s, ip_da);
- udp_update_l2_buf(eth_d, eth_s, ip_da);
+ tcp_update_l2_buf(eth_d, eth_s);
+ udp_update_l2_buf(eth_d, eth_s);
}
/**
@@ -265,7 +263,7 @@ int main(int argc, char **argv)
if (!c.no_icmp)
icmp_init();
- proto_update_l2_buf(c.mac_guest, c.mac, &c.ip4.addr);
+ proto_update_l2_buf(c.mac_guest, c.mac);
if (c.ifi4 && !c.no_dhcp)
dhcp_init();
diff --git a/passt.h b/passt.h
index 96fd27b..a40cbda 100644
--- a/passt.h
+++ b/passt.h
@@ -267,7 +267,7 @@ struct ctx {
int low_rmem;
};
-void proto_update_l2_buf(const unsigned char *eth_d, const unsigned char *eth_s,
- const struct in_addr *ip_da);
+void proto_update_l2_buf(const unsigned char *eth_d,
+ const unsigned char *eth_s);
#endif /* PASST_H */
diff --git a/pasta.c b/pasta.c
index 8c85546..3b73cb2 100644
--- a/pasta.c
+++ b/pasta.c
@@ -298,7 +298,7 @@ void pasta_ns_conf(struct ctx *c)
nl_link(1, c->pasta_ifi, c->mac_guest, 0, 0);
}
- proto_update_l2_buf(c->mac_guest, NULL, NULL);
+ proto_update_l2_buf(c->mac_guest, NULL);
}
/**
diff --git a/tap.c b/tap.c
index 5e1daf8..8024c4b 100644
--- a/tap.c
+++ b/tap.c
@@ -624,10 +624,8 @@ resume:
l4_len = l3_len - hlen;
- if (iph->saddr && c->ip4.addr_seen.s_addr != iph->saddr) {
+ if (iph->saddr && c->ip4.addr_seen.s_addr != iph->saddr)
c->ip4.addr_seen.s_addr = iph->saddr;
- proto_update_l2_buf(NULL, NULL, &c->ip4.addr_seen);
- }
l4h = packet_get(in, i, sizeof(*eh) + hlen, l4_len, NULL);
if (!l4h)
@@ -950,7 +948,7 @@ redo:
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, NULL);
+ proto_update_l2_buf(c->mac_guest, NULL);
}
switch (ntohs(eh->h_proto)) {
@@ -1010,7 +1008,7 @@ restart:
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, NULL);
+ proto_update_l2_buf(c->mac_guest, NULL);
}
switch (ntohs(eh->h_proto)) {
diff --git a/tcp.c b/tcp.c
index c0bffb3..ac7ae60 100644
--- a/tcp.c
+++ b/tcp.c
@@ -999,10 +999,8 @@ static void tcp_update_check_tcp6(struct tcp6_l2_buf_t *buf)
* tcp_update_l2_buf() - Update L2 buffers with Ethernet and IPv4 addresses
* @eth_d: Ethernet destination address, NULL if unchanged
* @eth_s: Ethernet source address, NULL if unchanged
- * @ip_da: Pointer to IPv4 destination address, NULL if unchanged
*/
-void tcp_update_l2_buf(const unsigned char *eth_d, const unsigned char *eth_s,
- const struct in_addr *ip_da)
+void tcp_update_l2_buf(const unsigned char *eth_d, const unsigned char *eth_s)
{
int i;
@@ -1016,10 +1014,6 @@ void tcp_update_l2_buf(const unsigned char *eth_d, const unsigned char *eth_s,
tap_update_mac(&b6->taph, eth_d, eth_s);
tap_update_mac(&b4f->taph, eth_d, eth_s);
tap_update_mac(&b6f->taph, eth_d, eth_s);
-
- if (ip_da) {
- b4f->iph.daddr = b4->iph.daddr = ip_da->s_addr;
- }
}
}
diff --git a/tcp.h b/tcp.h
index 66a73eb..97de89e 100644
--- a/tcp.h
+++ b/tcp.h
@@ -24,8 +24,7 @@ void tcp_timer(struct ctx *c, const struct timespec *ts);
void tcp_defer_handler(struct ctx *c);
void tcp_sock_set_bufsize(const struct ctx *c, int s);
-void tcp_update_l2_buf(const unsigned char *eth_d, const unsigned char *eth_s,
- const struct in_addr *ip_da);
+void tcp_update_l2_buf(const unsigned char *eth_d, const unsigned char *eth_s);
/**
* union tcp_epoll_ref - epoll reference portion for TCP connections
diff --git a/udp.c b/udp.c
index b82aea5..3262842 100644
--- a/udp.c
+++ b/udp.c
@@ -276,10 +276,8 @@ static void udp_update_check4(struct udp4_l2_buf_t *buf)
* udp_update_l2_buf() - Update L2 buffers with Ethernet and IPv4 addresses
* @eth_d: Ethernet destination address, NULL if unchanged
* @eth_s: Ethernet source address, NULL if unchanged
- * @ip_da: Pointer to IPv4 destination address, NULL if unchanged
*/
-void udp_update_l2_buf(const unsigned char *eth_d, const unsigned char *eth_s,
- const struct in_addr *ip_da)
+void udp_update_l2_buf(const unsigned char *eth_d, const unsigned char *eth_s)
{
int i;
@@ -289,10 +287,6 @@ void udp_update_l2_buf(const unsigned char *eth_d, const unsigned char *eth_s,
tap_update_mac(&b4->taph, eth_d, eth_s);
tap_update_mac(&b6->taph, eth_d, eth_s);
-
- if (ip_da) {
- b4->iph.daddr = ip_da->s_addr;
- }
}
}
@@ -579,6 +573,7 @@ static size_t udp_update_hdr4(const struct ctx *c, int n, in_port_t dstport,
ip_len = udp4_l2_mh_sock[n].msg_len + sizeof(b->iph) + sizeof(b->uh);
b->iph.tot_len = htons(ip_len);
+ b->iph.daddr = c->ip4.addr_seen.s_addr;
src_port = ntohs(b->s_in.sin_port);
diff --git a/udp.h b/udp.h
index 060ae35..a3599b4 100644
--- a/udp.h
+++ b/udp.h
@@ -16,8 +16,7 @@ int udp_sock_init(const struct ctx *c, int ns, sa_family_t af,
const void *addr, const char *ifname, in_port_t port);
int udp_init(struct ctx *c);
void udp_timer(struct ctx *c, const struct timespec *ts);
-void udp_update_l2_buf(const unsigned char *eth_d, const unsigned char *eth_s,
- const struct in_addr *ip_da);
+void udp_update_l2_buf(const unsigned char *eth_d, const unsigned char *eth_s);
/**
* union udp_epoll_ref - epoll reference portion for TCP connections
--
@@ -16,8 +16,7 @@ int udp_sock_init(const struct ctx *c, int ns, sa_family_t af,
const void *addr, const char *ifname, in_port_t port);
int udp_init(struct ctx *c);
void udp_timer(struct ctx *c, const struct timespec *ts);
-void udp_update_l2_buf(const unsigned char *eth_d, const unsigned char *eth_s,
- const struct in_addr *ip_da);
+void udp_update_l2_buf(const unsigned char *eth_d, const unsigned char *eth_s);
/**
* union udp_epoll_ref - epoll reference portion for TCP connections
--
2.41.0
next prev parent reply other threads:[~2023-07-28 9:48 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-28 9:48 [PATCH 0/8] RFC: Generalize flow tracking, part 1 David Gibson
2023-07-28 9:48 ` [PATCH 1/8] tap: Don't clobber source address in tap6_handler() David Gibson
2023-07-28 9:48 ` [PATCH 2/8] tap: Pass source address to protocol handler functions David Gibson
2023-07-28 9:48 ` [PATCH 3/8] tcp: More precise terms for addresses and ports David Gibson
2023-07-28 9:48 ` [PATCH 4/8] tcp, udp: Don't include destination address in partially precomputed csums David Gibson
2023-07-28 9:48 ` David Gibson [this message]
2023-07-28 9:48 ` [PATCH 6/8] tcp: Track guest-side correspondent address David Gibson
2023-07-28 9:48 ` [PATCH 7/8] tcp, flow: Introduce struct demiflow David Gibson
2023-07-28 9:48 ` [PATCH 8/8] tcp, flow: Perform TCP hash calculations based on demiflow structure 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=20230728094831.4097571-6-david@gibson.dropbear.id.au \
--to=david@gibson.dropbear.id.au \
--cc=passt-dev@passt.top \
--cc=sbrivio@redhat.com \
/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).