dt-bindings: Document rk3399 rk-timer bindings
[linux/fpc-iii.git] / include / net / gre.h
blob5dce30a6abe3e67091c5d14facd2750edd8426f0
1 #ifndef __LINUX_GRE_H
2 #define __LINUX_GRE_H
4 #include <linux/skbuff.h>
5 #include <net/ip_tunnels.h>
7 struct gre_base_hdr {
8 __be16 flags;
9 __be16 protocol;
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
18 struct gre_protocol {
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,
27 u8 name_assign_type);
28 int gre_parse_header(struct sk_buff *skb, struct tnl_ptk_info *tpi,
29 bool *csum_err, __be16 proto);
31 static inline int gre_calc_hlen(__be16 o_flags)
33 int addend = 4;
35 if (o_flags & TUNNEL_CSUM)
36 addend += 4;
37 if (o_flags & TUNNEL_KEY)
38 addend += 4;
39 if (o_flags & TUNNEL_SEQ)
40 addend += 4;
41 return addend;
44 static inline __be16 gre_flags_to_tnl_flags(__be16 flags)
46 __be16 tflags = 0;
48 if (flags & GRE_CSUM)
49 tflags |= TUNNEL_CSUM;
50 if (flags & GRE_ROUTING)
51 tflags |= TUNNEL_ROUTING;
52 if (flags & GRE_KEY)
53 tflags |= TUNNEL_KEY;
54 if (flags & GRE_SEQ)
55 tflags |= TUNNEL_SEQ;
56 if (flags & GRE_STRICT)
57 tflags |= TUNNEL_STRICT;
58 if (flags & GRE_REC)
59 tflags |= TUNNEL_REC;
60 if (flags & GRE_VERSION)
61 tflags |= TUNNEL_VERSION;
63 return tflags;
66 static inline __be16 gre_tnl_flags_to_gre_flags(__be16 tflags)
68 __be16 flags = 0;
70 if (tflags & TUNNEL_CSUM)
71 flags |= GRE_CSUM;
72 if (tflags & TUNNEL_ROUTING)
73 flags |= GRE_ROUTING;
74 if (tflags & TUNNEL_KEY)
75 flags |= GRE_KEY;
76 if (tflags & TUNNEL_SEQ)
77 flags |= GRE_SEQ;
78 if (tflags & TUNNEL_STRICT)
79 flags |= GRE_STRICT;
80 if (tflags & TUNNEL_REC)
81 flags |= GRE_REC;
82 if (tflags & TUNNEL_VERSION)
83 flags |= GRE_VERSION;
85 return flags;
88 static inline __sum16 gre_checksum(struct sk_buff *skb)
90 __wsum csum;
92 if (skb->ip_summed == CHECKSUM_PARTIAL)
93 csum = lco_csum(skb);
94 else
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) {
116 *ptr = seq;
117 ptr--;
119 if (flags & TUNNEL_KEY) {
120 *ptr = key;
121 ptr--;
123 if (flags & TUNNEL_CSUM &&
124 !(skb_shinfo(skb)->gso_type &
125 (SKB_GSO_GRE | SKB_GSO_GRE_CSUM))) {
126 *ptr = 0;
127 *(__sum16 *)ptr = gre_checksum(skb);
132 #endif