Merge remote-tracking branch 'regulator/topic/wm8350' into regulator-next
[firefly-linux-kernel-4.4.55.git] / net / ipv4 / fou.c
index b986298a7ba39908290ccd808a24947d776b91b4..ff069f6597ace6302b46add285c787942645aac2 100644 (file)
@@ -22,14 +22,18 @@ static LIST_HEAD(fou_list);
 struct fou {
        struct socket *sock;
        u8 protocol;
+       u8 flags;
        u16 port;
        struct udp_offload udp_offloads;
        struct list_head list;
 };
 
+#define FOU_F_REMCSUM_NOPARTIAL BIT(0)
+
 struct fou_cfg {
        u16 type;
        u8 protocol;
+       u8 flags;
        struct udp_port_cfg udp_config;
 };
 
@@ -64,32 +68,20 @@ static int fou_udp_recv(struct sock *sk, struct sk_buff *skb)
 }
 
 static struct guehdr *gue_remcsum(struct sk_buff *skb, struct guehdr *guehdr,
-                                 void *data, size_t hdrlen, u8 ipproto)
+                                 void *data, size_t hdrlen, u8 ipproto,
+                                 bool nopartial)
 {
        __be16 *pd = data;
        size_t start = ntohs(pd[0]);
        size_t offset = ntohs(pd[1]);
        size_t plen = hdrlen + max_t(size_t, offset + sizeof(u16), start);
-       __wsum delta;
-
-       if (skb->remcsum_offload) {
-               /* Already processed in GRO path */
-               skb->remcsum_offload = 0;
-               return guehdr;
-       }
 
        if (!pskb_may_pull(skb, plen))
                return NULL;
        guehdr = (struct guehdr *)&udp_hdr(skb)[1];
 
-       if (unlikely(skb->ip_summed != CHECKSUM_COMPLETE))
-               __skb_checksum_complete(skb);
-
-       delta = remcsum_adjust((void *)guehdr + hdrlen,
-                              skb->csum, start, offset);
-
-       /* Adjust skb->csum since we changed the packet */
-       skb->csum = csum_add(skb->csum, delta);
+       skb_remcsum_process(skb, (void *)guehdr + hdrlen,
+                           start, offset, nopartial);
 
        return guehdr;
 }
@@ -150,7 +142,9 @@ static int gue_udp_recv(struct sock *sk, struct sk_buff *skb)
 
                if (flags & GUE_PFLAG_REMCSUM) {
                        guehdr = gue_remcsum(skb, guehdr, data + doffset,
-                                            hdrlen, guehdr->proto_ctype);
+                                            hdrlen, guehdr->proto_ctype,
+                                            !!(fou->flags &
+                                               FOU_F_REMCSUM_NOPARTIAL));
                        if (!guehdr)
                                goto drop;
 
@@ -174,7 +168,8 @@ drop:
 }
 
 static struct sk_buff **fou_gro_receive(struct sk_buff **head,
-                                       struct sk_buff *skb)
+                                       struct sk_buff *skb,
+                                       struct udp_offload *uoff)
 {
        const struct net_offload *ops;
        struct sk_buff **pp = NULL;
@@ -195,7 +190,8 @@ out_unlock:
        return pp;
 }
 
-static int fou_gro_complete(struct sk_buff *skb, int nhoff)
+static int fou_gro_complete(struct sk_buff *skb, int nhoff,
+                           struct udp_offload *uoff)
 {
        const struct net_offload *ops;
        u8 proto = NAPI_GRO_CB(skb)->proto;
@@ -220,16 +216,16 @@ out_unlock:
 
 static struct guehdr *gue_gro_remcsum(struct sk_buff *skb, unsigned int off,
                                      struct guehdr *guehdr, void *data,
-                                     size_t hdrlen, u8 ipproto)
+                                     size_t hdrlen, u8 ipproto,
+                                     struct gro_remcsum *grc, bool nopartial)
 {
        __be16 *pd = data;
        size_t start = ntohs(pd[0]);
        size_t offset = ntohs(pd[1]);
        size_t plen = hdrlen + max_t(size_t, offset + sizeof(u16), start);
-       __wsum delta;
 
        if (skb->remcsum_offload)
-               return guehdr;
+               return NULL;
 
        if (!NAPI_GRO_CB(skb)->csum_valid)
                return NULL;
@@ -241,12 +237,8 @@ static struct guehdr *gue_gro_remcsum(struct sk_buff *skb, unsigned int off,
                        return NULL;
        }
 
-       delta = remcsum_adjust((void *)guehdr + hdrlen,
-                              NAPI_GRO_CB(skb)->csum, start, offset);
-
-       /* Adjust skb->csum since we changed the packet */
-       skb->csum = csum_add(skb->csum, delta);
-       NAPI_GRO_CB(skb)->csum = csum_add(NAPI_GRO_CB(skb)->csum, delta);
+       skb_gro_remcsum_process(skb, (void *)guehdr + hdrlen,
+                               start, offset, grc, nopartial);
 
        skb->remcsum_offload = 1;
 
@@ -254,7 +246,8 @@ static struct guehdr *gue_gro_remcsum(struct sk_buff *skb, unsigned int off,
 }
 
 static struct sk_buff **gue_gro_receive(struct sk_buff **head,
-                                       struct sk_buff *skb)
+                                       struct sk_buff *skb,
+                                       struct udp_offload *uoff)
 {
        const struct net_offload **offloads;
        const struct net_offload *ops;
@@ -265,6 +258,10 @@ static struct sk_buff **gue_gro_receive(struct sk_buff **head,
        void *data;
        u16 doffset = 0;
        int flush = 1;
+       struct fou *fou = container_of(uoff, struct fou, udp_offloads);
+       struct gro_remcsum grc;
+
+       skb_gro_remcsum_init(&grc);
 
        off = skb_gro_offset(skb);
        len = off + sizeof(*guehdr);
@@ -306,7 +303,9 @@ static struct sk_buff **gue_gro_receive(struct sk_buff **head,
                if (flags & GUE_PFLAG_REMCSUM) {
                        guehdr = gue_gro_remcsum(skb, off, guehdr,
                                                 data + doffset, hdrlen,
-                                                guehdr->proto_ctype);
+                                                guehdr->proto_ctype, &grc,
+                                                !!(fou->flags &
+                                                   FOU_F_REMCSUM_NOPARTIAL));
                        if (!guehdr)
                                goto out;
 
@@ -356,11 +355,13 @@ out_unlock:
        rcu_read_unlock();
 out:
        NAPI_GRO_CB(skb)->flush |= flush;
+       skb_gro_remcsum_cleanup(skb, &grc);
 
        return pp;
 }
 
-static int gue_gro_complete(struct sk_buff *skb, int nhoff)
+static int gue_gro_complete(struct sk_buff *skb, int nhoff,
+                           struct udp_offload *uoff)
 {
        const struct net_offload **offloads;
        struct guehdr *guehdr = (struct guehdr *)(skb->data + nhoff);
@@ -465,6 +466,7 @@ static int fou_create(struct net *net, struct fou_cfg *cfg,
 
        sk = sock->sk;
 
+       fou->flags = cfg->flags;
        fou->port = cfg->udp_config.local_udp_port;
 
        /* Initial for fou type */
@@ -490,7 +492,7 @@ static int fou_create(struct net *net, struct fou_cfg *cfg,
        sk->sk_user_data = fou;
        fou->sock = sock;
 
-       udp_set_convert_csum(sk, true);
+       inet_inc_convert_csum(sk);
 
        sk->sk_allocation = GFP_ATOMIC;
 
@@ -551,6 +553,7 @@ static struct nla_policy fou_nl_policy[FOU_ATTR_MAX + 1] = {
        [FOU_ATTR_AF] = { .type = NLA_U8, },
        [FOU_ATTR_IPPROTO] = { .type = NLA_U8, },
        [FOU_ATTR_TYPE] = { .type = NLA_U8, },
+       [FOU_ATTR_REMCSUM_NOPARTIAL] = { .type = NLA_FLAG, },
 };
 
 static int parse_nl_config(struct genl_info *info,
@@ -581,6 +584,9 @@ static int parse_nl_config(struct genl_info *info,
        if (info->attrs[FOU_ATTR_TYPE])
                cfg->type = nla_get_u8(info->attrs[FOU_ATTR_TYPE]);
 
+       if (info->attrs[FOU_ATTR_REMCSUM_NOPARTIAL])
+               cfg->flags |= FOU_F_REMCSUM_NOPARTIAL;
+
        return 0;
 }