aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPravin B Shelar <pshelar@nicira.com>2013-06-17 20:49:45 -0400
committerDavid S. Miller <davem@davemloft.net>2013-06-19 21:07:40 -0400
commit752f36da68e9136df8918461d651723a43627e04 (patch)
tree4701b050f7b67559162f935d4fbb626597738ee1
parentbda7bb46343647f68591366731295a0f3eea59ed (diff)
gre: export gre_build_header() function.
This is required for ovs gre module. Signed-off-by: Pravin B Shelar <pshelar@nicira.com> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--include/net/gre.h2
-rw-r--r--net/ipv4/gre.c32
-rw-r--r--net/ipv4/ip_gre.c40
3 files changed, 35 insertions, 39 deletions
diff --git a/include/net/gre.h b/include/net/gre.h
index c6ea0c72c605..cbb9d51d82c1 100644
--- a/include/net/gre.h
+++ b/include/net/gre.h
@@ -32,6 +32,8 @@ struct gre_cisco_protocol {
32 32
33int gre_cisco_register(struct gre_cisco_protocol *proto); 33int gre_cisco_register(struct gre_cisco_protocol *proto);
34int gre_cisco_unregister(struct gre_cisco_protocol *proto); 34int gre_cisco_unregister(struct gre_cisco_protocol *proto);
35void gre_build_header(struct sk_buff *skb, const struct tnl_ptk_info *tpi,
36 int hdr_len);
35 37
36static inline int ip_gre_calc_hlen(__be16 o_flags) 38static inline int ip_gre_calc_hlen(__be16 o_flags)
37{ 39{
diff --git a/net/ipv4/gre.c b/net/ipv4/gre.c
index 8b9a373890ab..1cbc46536d1f 100644
--- a/net/ipv4/gre.c
+++ b/net/ipv4/gre.c
@@ -61,6 +61,38 @@ int gre_del_protocol(const struct gre_protocol *proto, u8 version)
61} 61}
62EXPORT_SYMBOL_GPL(gre_del_protocol); 62EXPORT_SYMBOL_GPL(gre_del_protocol);
63 63
64void gre_build_header(struct sk_buff *skb, const struct tnl_ptk_info *tpi,
65 int hdr_len)
66{
67 struct gre_base_hdr *greh;
68
69 skb_push(skb, hdr_len);
70
71 greh = (struct gre_base_hdr *)skb->data;
72 greh->flags = tnl_flags_to_gre_flags(tpi->flags);
73 greh->protocol = tpi->proto;
74
75 if (tpi->flags&(TUNNEL_KEY|TUNNEL_CSUM|TUNNEL_SEQ)) {
76 __be32 *ptr = (__be32 *)(((u8 *)greh) + hdr_len - 4);
77
78 if (tpi->flags&TUNNEL_SEQ) {
79 *ptr = tpi->seq;
80 ptr--;
81 }
82 if (tpi->flags&TUNNEL_KEY) {
83 *ptr = tpi->key;
84 ptr--;
85 }
86 if (tpi->flags&TUNNEL_CSUM &&
87 !(skb_shinfo(skb)->gso_type & SKB_GSO_GRE)) {
88 *ptr = 0;
89 *(__sum16 *)ptr = csum_fold(skb_checksum(skb, 0,
90 skb->len, 0));
91 }
92 }
93}
94EXPORT_SYMBOL_GPL(gre_build_header);
95
64static __sum16 check_checksum(struct sk_buff *skb) 96static __sum16 check_checksum(struct sk_buff *skb)
65{ 97{
66 __sum16 csum = 0; 98 __sum16 csum = 0;
diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
index 19863a81cea1..362c7c4c13ca 100644
--- a/net/ipv4/ip_gre.c
+++ b/net/ipv4/ip_gre.c
@@ -248,40 +248,6 @@ error:
248 return ERR_PTR(err); 248 return ERR_PTR(err);
249} 249}
250 250
251static struct sk_buff *gre_build_header(struct sk_buff *skb,
252 const struct tnl_ptk_info *tpi,
253 int hdr_len)
254{
255 struct gre_base_hdr *greh;
256
257 skb_push(skb, hdr_len);
258
259 greh = (struct gre_base_hdr *)skb->data;
260 greh->flags = tnl_flags_to_gre_flags(tpi->flags);
261 greh->protocol = tpi->proto;
262
263 if (tpi->flags&(TUNNEL_KEY|TUNNEL_CSUM|TUNNEL_SEQ)) {
264 __be32 *ptr = (__be32 *)(((u8 *)greh) + hdr_len - 4);
265
266 if (tpi->flags&TUNNEL_SEQ) {
267 *ptr = tpi->seq;
268 ptr--;
269 }
270 if (tpi->flags&TUNNEL_KEY) {
271 *ptr = tpi->key;
272 ptr--;
273 }
274 if (tpi->flags&TUNNEL_CSUM &&
275 !(skb_shinfo(skb)->gso_type & SKB_GSO_GRE)) {
276 *(__sum16 *)ptr = 0;
277 *(__sum16 *)ptr = csum_fold(skb_checksum(skb, 0,
278 skb->len, 0));
279 }
280 }
281
282 return skb;
283}
284
285static void __gre_xmit(struct sk_buff *skb, struct net_device *dev, 251static void __gre_xmit(struct sk_buff *skb, struct net_device *dev,
286 const struct iphdr *tnl_params, 252 const struct iphdr *tnl_params,
287 __be16 proto) 253 __be16 proto)
@@ -302,11 +268,7 @@ static void __gre_xmit(struct sk_buff *skb, struct net_device *dev,
302 tpi.seq = htonl(tunnel->o_seqno); 268 tpi.seq = htonl(tunnel->o_seqno);
303 269
304 /* Push GRE header. */ 270 /* Push GRE header. */
305 skb = gre_build_header(skb, &tpi, tunnel->hlen); 271 gre_build_header(skb, &tpi, tunnel->hlen);
306 if (unlikely(!skb)) {
307 dev->stats.tx_dropped++;
308 return;
309 }
310 272
311 ip_tunnel_xmit(skb, dev, tnl_params, tnl_params->protocol); 273 ip_tunnel_xmit(skb, dev, tnl_params, tnl_params->protocol);
312} 274}