4 #include <linux/skbuff.h>
5 #include <net/ip_tunnels.h>
11 #define GRE_HEADER_SECTION 4
13 #define GREPROTO_CISCO 0
14 #define GREPROTO_PPTP 1
15 #define GREPROTO_MAX 2
16 #define GRE_IP_PROTO_MAX 2
19 int (*handler)(struct sk_buff *skb);
20 void (*err_handler)(struct sk_buff *skb, u32 info);
23 int gre_add_protocol(const struct gre_protocol *proto, u8 version);
24 int gre_del_protocol(const struct gre_protocol *proto, u8 version);
26 struct net_device *gretap_fb_dev_create(struct net *net, const char *name,
28 int gre_parse_header(struct sk_buff *skb, struct tnl_ptk_info *tpi,
29 bool *csum_err, __be16 proto, int nhs);
31 static inline int gre_calc_hlen(__be16 o_flags)
35 if (o_flags & TUNNEL_CSUM)
37 if (o_flags & TUNNEL_KEY)
39 if (o_flags & TUNNEL_SEQ)
44 static inline __be16 gre_flags_to_tnl_flags(__be16 flags)
49 tflags |= TUNNEL_CSUM;
50 if (flags & GRE_ROUTING)
51 tflags |= TUNNEL_ROUTING;
56 if (flags & GRE_STRICT)
57 tflags |= TUNNEL_STRICT;
60 if (flags & GRE_VERSION)
61 tflags |= TUNNEL_VERSION;
66 static inline __be16 gre_tnl_flags_to_gre_flags(__be16 tflags)
70 if (tflags & TUNNEL_CSUM)
72 if (tflags & TUNNEL_ROUTING)
74 if (tflags & TUNNEL_KEY)
76 if (tflags & TUNNEL_SEQ)
78 if (tflags & TUNNEL_STRICT)
80 if (tflags & TUNNEL_REC)
82 if (tflags & TUNNEL_VERSION)
88 static inline __sum16 gre_checksum(struct sk_buff *skb)
92 if (skb->ip_summed == CHECKSUM_PARTIAL)
95 csum = skb_checksum(skb, 0, skb->len, 0);
96 return csum_fold(csum);
99 static inline void gre_build_header(struct sk_buff *skb, int hdr_len,
100 __be16 flags, __be16 proto,
101 __be32 key, __be32 seq)
103 struct gre_base_hdr *greh;
105 skb_push(skb, hdr_len);
107 skb_reset_transport_header(skb);
108 greh = (struct gre_base_hdr *)skb->data;
109 greh->flags = gre_tnl_flags_to_gre_flags(flags);
110 greh->protocol = proto;
112 if (flags & (TUNNEL_KEY | TUNNEL_CSUM | TUNNEL_SEQ)) {
113 __be32 *ptr = (__be32 *)(((u8 *)greh) + hdr_len - 4);
115 if (flags & TUNNEL_SEQ) {
119 if (flags & TUNNEL_KEY) {
123 if (flags & TUNNEL_CSUM &&
124 !(skb_shinfo(skb)->gso_type &
125 (SKB_GSO_GRE | SKB_GSO_GRE_CSUM))) {
127 *(__sum16 *)ptr = gre_checksum(skb);