Skip to content

Commit 752f36d

Browse files
Pravin B Shelardavem330
authored andcommitted
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>
1 parent bda7bb4 commit 752f36d

3 files changed

Lines changed: 35 additions & 39 deletions

File tree

‎include/net/gre.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ struct gre_cisco_protocol {
3232

3333
int gre_cisco_register(struct gre_cisco_protocol *proto);
3434
int gre_cisco_unregister(struct gre_cisco_protocol *proto);
35+
void gre_build_header(struct sk_buff *skb, const struct tnl_ptk_info *tpi,
36+
int hdr_len);
3537

3638
static inline int ip_gre_calc_hlen(__be16 o_flags)
3739
{

‎net/ipv4/gre.c‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,38 @@ int gre_del_protocol(const struct gre_protocol *proto, u8 version)
6161
}
6262
EXPORT_SYMBOL_GPL(gre_del_protocol);
6363

64+
void 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+
}
94+
EXPORT_SYMBOL_GPL(gre_build_header);
95+
6496
static __sum16 check_checksum(struct sk_buff *skb)
6597
{
6698
__sum16 csum = 0;

‎net/ipv4/ip_gre.c‎

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -248,40 +248,6 @@ static struct sk_buff *handle_offloads(struct ip_tunnel *tunnel, struct sk_buff
248248
return ERR_PTR(err);
249249
}
250250

251-
static 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-
285251
static void __gre_xmit(struct sk_buff *skb, struct net_device *dev,
286252
const struct iphdr *tnl_params,
287253
__be16 proto)
@@ -302,11 +268,7 @@ static void __gre_xmit(struct sk_buff *skb, struct net_device *dev,
302268
tpi.seq = htonl(tunnel->o_seqno);
303269

304270
/* Push GRE header. */
305-
skb = gre_build_header(skb, &tpi, tunnel->hlen);
306-
if (unlikely(!skb)) {
307-
dev->stats.tx_dropped++;
308-
return;
309-
}
271+
gre_build_header(skb, &tpi, tunnel->hlen);
310272

311273
ip_tunnel_xmit(skb, dev, tnl_params, tnl_params->protocol);
312274
}

0 commit comments

Comments
 (0)