On Tue, Oct 18, 2022 at 05:03:49AM +0200, Stefano Brivio wrote:
On Mon, 17 Oct 2022 19:57:58 +1100 David Gibson
wrote: We calculate IPv4 header checksums in at least two places, in dhcp() and in tap_ip_send. Add a helper to handle this calculation in both places.
Signed-off-by: David Gibson
--- checksum.c | 6 ++++++ checksum.h | 1 + dhcp.c | 3 +-- tap.c | 3 +-- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/checksum.c b/checksum.c index 72f1cfb..f25a96a 100644 --- a/checksum.c +++ b/checksum.c @@ -114,6 +114,12 @@ uint16_t csum_unaligned(const void *buf, size_t len, uint32_t init) return (uint16_t)~csum_fold(sum_16b(buf, len) + init); }
/** * csum_ip4_header() - Calculate and set IPv4 header checksum * @iph: IPv4 header */
...I just tried to run Doxygen, I think it would be nice to have eventually (especially for DOT call graphs), things don't look too bad.
+void csum_ip4_header(struct iphdr *ip4hr) +{ + ip4hr->check = 0; + ip4hr->check = csum_unaligned(ip4hr, (size_t)ip4hr->ihl * 4, 0);
iph, for consistency.
As noted before, I'd prefer to avoid the implication that IPv4 is normal and IPv6 is special. I have changed to just ip4h, though. -- 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