Skip to content

Commit 182a352

Browse files
tomratbertdavem330
authored andcommitted
gre: Create common functions for transmit
Create common functions for both IPv4 and IPv6 GRE in transmit. These are put into gre.h. Common functions are for: - GRE checksum calculation. Move gre_checksum to gre.h. - Building a GRE header. Move GRE build_header and rename gre_build_header. Signed-off-by: Tom Herbert <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 8eb30be commit 182a352

File tree

2 files changed

+49
-47
lines changed

2 files changed

+49
-47
lines changed

include/net/gre.h

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,48 @@ static inline __be16 gre_tnl_flags_to_gre_flags(__be16 tflags)
8585
return flags;
8686
}
8787

88+
static inline __sum16 gre_checksum(struct sk_buff *skb)
89+
{
90+
__wsum csum;
91+
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);
97+
}
98+
99+
static inline void gre_build_header(struct sk_buff *skb, int hdr_len,
100+
__be16 flags, __be16 proto,
101+
__be32 key, __be32 seq)
102+
{
103+
struct gre_base_hdr *greh;
104+
105+
skb_push(skb, hdr_len);
106+
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;
111+
112+
if (flags & (TUNNEL_KEY | TUNNEL_CSUM | TUNNEL_SEQ)) {
113+
__be32 *ptr = (__be32 *)(((u8 *)greh) + hdr_len - 4);
114+
115+
if (flags & TUNNEL_SEQ) {
116+
*ptr = seq;
117+
ptr--;
118+
}
119+
if (flags & TUNNEL_KEY) {
120+
*ptr = key;
121+
ptr--;
122+
}
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);
128+
}
129+
}
130+
}
131+
88132
#endif

net/ipv4/ip_gre.c

Lines changed: 5 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -329,49 +329,6 @@ static int gre_rcv(struct sk_buff *skb)
329329
return 0;
330330
}
331331

332-
static __sum16 gre_checksum(struct sk_buff *skb)
333-
{
334-
__wsum csum;
335-
336-
if (skb->ip_summed == CHECKSUM_PARTIAL)
337-
csum = lco_csum(skb);
338-
else
339-
csum = skb_checksum(skb, 0, skb->len, 0);
340-
return csum_fold(csum);
341-
}
342-
343-
static void build_header(struct sk_buff *skb, int hdr_len, __be16 flags,
344-
__be16 proto, __be32 key, __be32 seq)
345-
{
346-
struct gre_base_hdr *greh;
347-
348-
skb_push(skb, hdr_len);
349-
350-
skb_reset_transport_header(skb);
351-
greh = (struct gre_base_hdr *)skb->data;
352-
greh->flags = gre_tnl_flags_to_gre_flags(flags);
353-
greh->protocol = proto;
354-
355-
if (flags & (TUNNEL_KEY | TUNNEL_CSUM | TUNNEL_SEQ)) {
356-
__be32 *ptr = (__be32 *)(((u8 *)greh) + hdr_len - 4);
357-
358-
if (flags & TUNNEL_SEQ) {
359-
*ptr = seq;
360-
ptr--;
361-
}
362-
if (flags & TUNNEL_KEY) {
363-
*ptr = key;
364-
ptr--;
365-
}
366-
if (flags & TUNNEL_CSUM &&
367-
!(skb_shinfo(skb)->gso_type &
368-
(SKB_GSO_GRE | SKB_GSO_GRE_CSUM))) {
369-
*ptr = 0;
370-
*(__sum16 *)ptr = gre_checksum(skb);
371-
}
372-
}
373-
}
374-
375332
static void __gre_xmit(struct sk_buff *skb, struct net_device *dev,
376333
const struct iphdr *tnl_params,
377334
__be16 proto)
@@ -382,8 +339,9 @@ static void __gre_xmit(struct sk_buff *skb, struct net_device *dev,
382339
tunnel->o_seqno++;
383340

384341
/* Push GRE header. */
385-
build_header(skb, tunnel->tun_hlen, tunnel->parms.o_flags,
386-
proto, tunnel->parms.o_key, htonl(tunnel->o_seqno));
342+
gre_build_header(skb, tunnel->tun_hlen,
343+
tunnel->parms.o_flags, proto, tunnel->parms.o_key,
344+
htonl(tunnel->o_seqno));
387345

388346
skb_set_inner_protocol(skb, proto);
389347
ip_tunnel_xmit(skb, dev, tnl_params, tnl_params->protocol);
@@ -460,8 +418,8 @@ static void gre_fb_xmit(struct sk_buff *skb, struct net_device *dev)
460418
goto err_free_rt;
461419

462420
flags = tun_info->key.tun_flags & (TUNNEL_CSUM | TUNNEL_KEY);
463-
build_header(skb, tunnel_hlen, flags, htons(ETH_P_TEB),
464-
tunnel_id_to_key(tun_info->key.tun_id), 0);
421+
gre_build_header(skb, tunnel_hlen, flags, htons(ETH_P_TEB),
422+
tunnel_id_to_key(tun_info->key.tun_id), 0);
465423

466424
df = key->tun_flags & TUNNEL_DONT_FRAGMENT ? htons(IP_DF) : 0;
467425

0 commit comments

Comments
 (0)