From 88f20c56870074fd43b295fcd7a7ee34578d2355 Mon Sep 17 00:00:00 2001 From: Ethan Jackson Date: Wed, 21 Dec 2011 11:19:28 -0800 Subject: [PATCH] dpif-netdev: Fix UDP checksum calculation. dpif-netdev incorrectly calculated the UDP checksum when modifying source and destination ports. Signed-off-by: Ethan Jackson --- lib/dpif-netdev.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c index 2c416e35..742d00c6 100644 --- a/lib/dpif-netdev.c +++ b/lib/dpif-netdev.c @@ -1137,11 +1137,21 @@ dp_netdev_set_udp_port(struct ofpbuf *packet, const struct ovs_key_udp *udp_key) { struct udp_header *uh = packet->l4; - if (uh->udp_src != udp_key->udp_src) { - dp_netdev_set_port(&uh->udp_src, udp_key->udp_src, &uh->udp_csum); - } - if (uh->udp_dst != udp_key->udp_dst) { - dp_netdev_set_port(&uh->udp_dst, udp_key->udp_dst, &uh->udp_csum); + if (uh->udp_csum) { + if (uh->udp_src != udp_key->udp_src) { + dp_netdev_set_port(&uh->udp_src, udp_key->udp_src, &uh->udp_csum); + } + + if (uh->udp_dst != udp_key->udp_dst) { + dp_netdev_set_port(&uh->udp_dst, udp_key->udp_dst, &uh->udp_csum); + } + + if (!uh->udp_csum) { + uh->udp_csum = htons(0xffff); + } + } else { + uh->udp_src = udp_key->udp_src; + uh->udp_dst = udp_key->udp_dst; } } -- 2.30.2