[PATCH v2 0/6] udp: Small cleanups
Following on from the recent set of small fixes for UDP, here are a number of small cleanups to the UDP code, which will simplify later more complex fixes and improvements. Laurent, I expect this will have some conflicts with part 2 of your vhost-user work, though I hope they won't be too bad. This is now based on part 1 of Laurent's vhost-user series (specifically the version I posted with the static checker regressions fixed). Changes since v1: * Rebased on Laurent's vhost-user part 1 patches * Some improved commit messages David Gibson (6): udp: Refactor udp_sock[46]_iov_init() udp: Consistent port variable names in udp_update_hdr[46] udp: Pass data length explicitly to to udp_update_hdr[46] udp: Re-order udp_update_hdr[46] for clarity and brevity udp: Avoid unnecessary pointer in udp_update_hdr4() udp: Use existing helper for UDP checksum on inbound IPv6 packets udp.c | 211 +++++++++++++++++++++++++++------------------------------- 1 file changed, 99 insertions(+), 112 deletions(-) -- 2.44.0
Each of these functions have 3 essentially identical loops in a row.
Merge the loops into a single common udp_sock_iov_init() function, calling
udp_sock[46]_iov_init_one() helpers to initialize each "slot" in the
various parallel arrays. This is slightly neater now, and more naturally
allows changes we want to make where more initialization will become common
between IPv4 and IPv6.
Signed-off-by: David Gibson
In these functions we have 'dstport' for the destination port, but
'src_port' for the source port. Change the latter to 'srcport' for
consistency.
Signed-off-by: David Gibson
These functions take an index to the L2 buffer whose header information to
update. They use that for two things: to locate the buffer pointer itself,
and to retrieve the length of the received message from the paralllel
udp[46]_l2_mh_sock array. The latter is arguably a failure to separate
concerns. Change these functions to explicitly take a buffer pointer and
payload length as parameters.
Signed-off-by: David Gibson
The order of things in these functions is a bit odd for historical reasons.
We initialise some IP header fields early, the more later after making
some tests. Likewise we declare some variables without initialisation,
but then unconditionally set them to values we could calculate at the
start of the function.
Previous cleanups have removed the reasons for some of these choices, so
reorder for clarity, and where possible move the first assignment into an
initialiser.
Signed-off-by: David Gibson
We carry around the source address as a pointer to a constant struct
in_addr. But it's silly to carry around a 4 or 8 byte pointer to a 4 byte
IPv4 address. Just copy the IPv4 address around by value.
Signed-off-by: David Gibson
Currently we open code the calculation of the UDP checksum in
udp_update_hdr6(). We calling a helper to handle the IPv6 pseudo-header,
and preset the checksum field to 0 so an uninitialised value doesn't get
folded in. We already have a helper to do this: csum_udp6() which we use
in some slow paths. Use it here as well.
Signed-off-by: David Gibson
On Wed, 6 Mar 2024 16:34:22 +1100
David Gibson
Following on from the recent set of small fixes for UDP, here are a number of small cleanups to the UDP code, which will simplify later more complex fixes and improvements.
Laurent, I expect this will have some conflicts with part 2 of your vhost-user work, though I hope they won't be too bad.
This is now based on part 1 of Laurent's vhost-user series (specifically the version I posted with the static checker regressions fixed).
Changes since v1: * Rebased on Laurent's vhost-user part 1 patches * Some improved commit messages
Applied. -- Stefano
participants (2)
-
David Gibson
-
Stefano Brivio