fou: Split out {fou,gue}_build_header
authorTom Herbert <tom@herbertland.com>
Wed, 18 May 2016 16:06:15 +0000 (09:06 -0700)
committerDavid S. Miller <davem@davemloft.net>
Fri, 20 May 2016 22:03:16 +0000 (18:03 -0400)
Create __fou_build_header and __gue_build_header. These implement the
protocol generic parts of building the fou and gue header.
fou_build_header and gue_build_header implement the IPv4 specific
functions and call the __*_build_header functions.

Signed-off-by: Tom Herbert <tom@herbertland.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/net/fou.h
net/ipv4/fou.c

index 19b8a0c..7d2fda2 100644 (file)
@@ -11,9 +11,9 @@
 size_t fou_encap_hlen(struct ip_tunnel_encap *e);
 static size_t gue_encap_hlen(struct ip_tunnel_encap *e);
 
-int fou_build_header(struct sk_buff *skb, struct ip_tunnel_encap *e,
-                    u8 *protocol, struct flowi4 *fl4);
-int gue_build_header(struct sk_buff *skb, struct ip_tunnel_encap *e,
-                    u8 *protocol, struct flowi4 *fl4);
+int __fou_build_header(struct sk_buff *skb, struct ip_tunnel_encap *e,
+                      u8 *protocol, __be16 *sport, int type);
+int __gue_build_header(struct sk_buff *skb, struct ip_tunnel_encap *e,
+                      u8 *protocol, __be16 *sport, int type);
 
 #endif
index 6cbc725..f4f2ddd 100644 (file)
@@ -780,6 +780,22 @@ static void fou_build_udp(struct sk_buff *skb, struct ip_tunnel_encap *e,
        *protocol = IPPROTO_UDP;
 }
 
+int __fou_build_header(struct sk_buff *skb, struct ip_tunnel_encap *e,
+                      u8 *protocol, __be16 *sport, int type)
+{
+       int err;
+
+       err = iptunnel_handle_offloads(skb, type);
+       if (err)
+               return err;
+
+       *sport = e->sport ? : udp_flow_src_port(dev_net(skb->dev),
+                                               skb, 0, 0, false);
+
+       return 0;
+}
+EXPORT_SYMBOL(__fou_build_header);
+
 int fou_build_header(struct sk_buff *skb, struct ip_tunnel_encap *e,
                     u8 *protocol, struct flowi4 *fl4)
 {
@@ -788,26 +804,21 @@ int fou_build_header(struct sk_buff *skb, struct ip_tunnel_encap *e,
        __be16 sport;
        int err;
 
-       err = iptunnel_handle_offloads(skb, type);
+       err = __fou_build_header(skb, e, protocol, &sport, type);
        if (err)
                return err;
 
-       sport = e->sport ? : udp_flow_src_port(dev_net(skb->dev),
-                                              skb, 0, 0, false);
        fou_build_udp(skb, e, fl4, protocol, sport);
 
        return 0;
 }
 EXPORT_SYMBOL(fou_build_header);
 
-int gue_build_header(struct sk_buff *skb, struct ip_tunnel_encap *e,
-                    u8 *protocol, struct flowi4 *fl4)
+int __gue_build_header(struct sk_buff *skb, struct ip_tunnel_encap *e,
+                      u8 *protocol, __be16 *sport, int type)
 {
-       int type = e->flags & TUNNEL_ENCAP_FLAG_CSUM ? SKB_GSO_UDP_TUNNEL_CSUM :
-                                                      SKB_GSO_UDP_TUNNEL;
        struct guehdr *guehdr;
        size_t hdrlen, optlen = 0;
-       __be16 sport;
        void *data;
        bool need_priv = false;
        int err;
@@ -826,8 +837,8 @@ int gue_build_header(struct sk_buff *skb, struct ip_tunnel_encap *e,
                return err;
 
        /* Get source port (based on flow hash) before skb_push */
-       sport = e->sport ? : udp_flow_src_port(dev_net(skb->dev),
-                                              skb, 0, 0, false);
+       *sport = e->sport ? : udp_flow_src_port(dev_net(skb->dev),
+                                               skb, 0, 0, false);
 
        hdrlen = sizeof(struct guehdr) + optlen;
 
@@ -872,6 +883,22 @@ int gue_build_header(struct sk_buff *skb, struct ip_tunnel_encap *e,
 
        }
 
+       return 0;
+}
+EXPORT_SYMBOL(__gue_build_header);
+
+int gue_build_header(struct sk_buff *skb, struct ip_tunnel_encap *e,
+                    u8 *protocol, struct flowi4 *fl4)
+{
+       int type = e->flags & TUNNEL_ENCAP_FLAG_CSUM ? SKB_GSO_UDP_TUNNEL_CSUM :
+                                                      SKB_GSO_UDP_TUNNEL;
+       __be16 sport;
+       int err;
+
+       err = __gue_build_header(skb, e, protocol, &sport, type);
+       if (err)
+               return err;
+
        fou_build_udp(skb, e, fl4, protocol, sport);
 
        return 0;