[PATCH 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, sorry. David Gibson (6): udp: Refactor udp_sock[46]_iov_init() udp: Tweak interface to udp_update_hdr[46] udp: Clarify setting of addresses inin udp_update_hdr[46]() udp: Consistent port variable names in udp_update_hdr[46] udp: Avoid unnecessary pointer in udp_update_hdr4() udp: Clean up UDP checksum generation for inbound IPv6 packets udp.c | 235 +++++++++++++++++++++++++++------------------------------- 1 file changed, 108 insertions(+), 127 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
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
Both of these functions can set the final values of the addresses in the
header in several places, which can be hard to follow. Change it to use
temporary locals, 'src' and 'dst' to track the addresses we're going to
want then write it to the actual header in one place. This will make some
subsequent changes easier.
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
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, which involves
temporarily mangling the IPv6 header to match the UDP checksum
pseudo-header. It also assumes that the payload is contiguous with the
headers, which is true for now, but we want to change in future.
We already have a helper which correcly calculates UDP over IPv6 checksums,
which doesn't require temporarily modifying the headers and which handles
a non-contiguous payload, so use it. It turns out we were already
initializing the IPv6 version, nexthdr and hop_limit fields, even though
we overwrote them for each packet here, so we can just leave those in
place now.
Signed-off-by: David Gibson
participants (1)
-
David Gibson