[ovs-dev] [PATCH] dpif-netdev: Fix UDP checksum calculation.

Ben Pfaff blp at nicira.com
Wed Dec 21 19:43:22 UTC 2011


Jesse, don't we have the same bug in the datapath?  I don't see any
special case for a zero UDP checksum there either.

Ethan, your fix looks fine, thanks.

On Wed, Dec 21, 2011 at 11:27:59AM -0800, Ethan Jackson wrote:
> dpif-netdev incorrectly calculated the UDP checksum when modifying
> source and destination ports.
> 
> Signed-off-by: Ethan Jackson <ethan at nicira.com>
> ---
>  lib/dpif-netdev.c |   20 +++++++++++++++-----
>  1 files changed, 15 insertions(+), 5 deletions(-)
> 
> diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c
> index 2c416e3..742d00c 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;
>      }
>  }



More information about the dev mailing list