udp: Add support for doing checksum unnecessary conversion
authorTom Herbert <therbert@google.com>
Sun, 31 Aug 2014 22:12:43 +0000 (15:12 -0700)
committerDavid S. Miller <davem@davemloft.net>
Tue, 2 Sep 2014 04:36:28 +0000 (21:36 -0700)
Add support for doing CHECKSUM_UNNECESSARY to CHECKSUM_COMPLETE
conversion in UDP tunneling path.

In the normal UDP path, we call skb_checksum_try_convert after locating
the UDP socket. The check is that checksum conversion is enabled for
the socket (new flag in UDP socket) and that checksum field is
non-zero.

In the UDP GRO path, we call skb_gro_checksum_try_convert after
checksum is validated and checksum field is non-zero. Since this is
already in GRO we assume that checksum conversion is always wanted.

Signed-off-by: Tom Herbert <therbert@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/linux/udp.h
net/ipv4/udp.c
net/ipv4/udp_offload.c
net/ipv6/udp.c
net/ipv6/udp_offload.c

index 247cfdcc4b08bbf377ff5819ebd02683806b0c83..ee3277593222cf314f9b030eec6ec09d0c38c4e4 100644 (file)
@@ -49,7 +49,11 @@ struct udp_sock {
        unsigned int     corkflag;      /* Cork is required */
        __u8             encap_type;    /* Is this an Encapsulation socket? */
        unsigned char    no_check6_tx:1,/* Send zero UDP6 checksums on TX? */
-                        no_check6_rx:1;/* Allow zero UDP6 checksums on RX? */
+                        no_check6_rx:1,/* Allow zero UDP6 checksums on RX? */
+                        convert_csum:1;/* On receive, convert checksum
+                                        * unnecessary to checksum complete
+                                        * if possible.
+                                        */
        /*
         * Following member retains the information to create a UDP header
         * when the socket is uncorked.
@@ -98,6 +102,16 @@ static inline bool udp_get_no_check6_rx(struct sock *sk)
        return udp_sk(sk)->no_check6_rx;
 }
 
+static inline void udp_set_convert_csum(struct sock *sk, bool val)
+{
+       udp_sk(sk)->convert_csum = val;
+}
+
+static inline bool udp_get_convert_csum(struct sock *sk)
+{
+       return udp_sk(sk)->convert_csum;
+}
+
 #define udp_portaddr_for_each_entry(__sk, node, list) \
        hlist_nulls_for_each_entry(__sk, node, list, __sk_common.skc_portaddr_node)
 
index 3549c21fe5f737a3744b6322ea1be33ab9aa46b3..0da3849fd35bb652631e03a08e76abbe29738ddd 100644 (file)
@@ -1788,6 +1788,10 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
        if (sk != NULL) {
                int ret;
 
+               if (udp_sk(sk)->convert_csum && uh->check && !IS_UDPLITE(sk))
+                       skb_checksum_try_convert(skb, IPPROTO_UDP, uh->check,
+                                                inet_compute_pseudo);
+
                ret = udp_queue_rcv_skb(sk, skb);
                sock_put(sk);
 
index a6adff98382a3797bc497cb299a5cb4c50f591d2..84e0e05c9c0e97b584b4fe42fe22a65dcc071615 100644 (file)
@@ -290,16 +290,25 @@ static struct sk_buff **udp4_gro_receive(struct sk_buff **head,
 {
        struct udphdr *uh = udp_gro_udphdr(skb);
 
-       /* Don't bother verifying checksum if we're going to flush anyway. */
-       if (unlikely(!uh) ||
-           (!NAPI_GRO_CB(skb)->flush &&
-            skb_gro_checksum_validate_zero_check(skb, IPPROTO_UDP, uh->check,
-                                                 inet_gro_compute_pseudo))) {
-               NAPI_GRO_CB(skb)->flush = 1;
-               return NULL;
-       }
+       if (unlikely(!uh))
+               goto flush;
 
+       /* Don't bother verifying checksum if we're going to flush anyway. */
+       if (!NAPI_GRO_CB(skb)->flush)
+               goto skip;
+
+       if (skb_gro_checksum_validate_zero_check(skb, IPPROTO_UDP, uh->check,
+                                                inet_gro_compute_pseudo))
+               goto flush;
+       else if (uh->check)
+               skb_gro_checksum_try_convert(skb, IPPROTO_UDP, uh->check,
+                                            inet_gro_compute_pseudo);
+skip:
        return udp_gro_receive(head, skb, uh);
+
+flush:
+       NAPI_GRO_CB(skb)->flush = 1;
+       return NULL;
 }
 
 int udp_gro_complete(struct sk_buff *skb, int nhoff)
index 12fcce8fba466654891671e450885e40c647f1d9..f6ba535b6febe40aad990e7f9541446fc573d511 100644 (file)
@@ -891,6 +891,10 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
                        goto csum_error;
                }
 
+               if (udp_sk(sk)->convert_csum && uh->check && !IS_UDPLITE(sk))
+                       skb_checksum_try_convert(skb, IPPROTO_UDP, uh->check,
+                                                ip6_compute_pseudo);
+
                ret = udpv6_queue_rcv_skb(sk, skb);
                sock_put(sk);
 
index b13e377e9c5370bec9dc117d336efde8ae6ae5f1..89cb9a9b853789eab136cff742f36e3a4d5ee19d 100644 (file)
@@ -134,16 +134,26 @@ static struct sk_buff **udp6_gro_receive(struct sk_buff **head,
 {
        struct udphdr *uh = udp_gro_udphdr(skb);
 
+       if (unlikely(!uh))
+               goto flush;
+
        /* Don't bother verifying checksum if we're going to flush anyway. */
-       if (unlikely(!uh) ||
-           (!NAPI_GRO_CB(skb)->flush &&
-            skb_gro_checksum_validate_zero_check(skb, IPPROTO_UDP, uh->check,
-                                                 ip6_gro_compute_pseudo))) {
-               NAPI_GRO_CB(skb)->flush = 1;
-               return NULL;
-       }
+       if (!NAPI_GRO_CB(skb)->flush)
+               goto skip;
 
+       if (skb_gro_checksum_validate_zero_check(skb, IPPROTO_UDP, uh->check,
+                                                ip6_gro_compute_pseudo))
+               goto flush;
+       else if (uh->check)
+               skb_gro_checksum_try_convert(skb, IPPROTO_UDP, uh->check,
+                                            ip6_gro_compute_pseudo);
+
+skip:
        return udp_gro_receive(head, skb, uh);
+
+flush:
+       NAPI_GRO_CB(skb)->flush = 1;
+       return NULL;
 }
 
 int udp6_gro_complete(struct sk_buff *skb, int nhoff)