Signed-off-by: Pravin B Shelar <[email protected]>
---
net/ipv4/ip_gre.c | 82 ++++++++++++++++++++++++++---------------------------
1 file changed, 41 insertions(+), 41 deletions(-)
diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
index 3bda6e2..48c4a74 100644
--- a/net/ipv4/ip_gre.c
+++ b/net/ipv4/ip_gre.c
@@ -631,6 +631,30 @@ drop_nolock:
return 0;
}
+static void build_ip_header(struct sk_buff *skb, struct flowi4 *fl4, int
gre_hlen, __be16 df, u8 tos, u8 ttl)
+{
+ struct iphdr *iph; /* Our new IP header */
+
+ skb_reset_transport_header(skb);
+ skb_push(skb, gre_hlen);
+ skb_reset_network_header(skb);
+
+ /*
+ * Push down and install the IPIP header.
+ */
+
+ iph = ip_hdr(skb);
+ iph->version = 4;
+ iph->ihl = sizeof(struct iphdr) >> 2;
+ iph->frag_off = df;
+ iph->protocol = IPPROTO_GRE;
+ iph->tos = tos;
+ iph->daddr = fl4->daddr;
+ iph->saddr = fl4->saddr;
+ iph->ttl = ttl;
+
+}
+
static netdev_tx_t ipgre_tunnel_xmit(struct sk_buff *skb, struct net_device
*dev)
{
struct ip_tunnel *tunnel = netdev_priv(dev);
@@ -638,12 +662,12 @@ static netdev_tx_t ipgre_tunnel_xmit(struct sk_buff *skb,
struct net_device *dev
const struct iphdr *old_iph = ip_hdr(skb);
const struct iphdr *tiph;
struct flowi4 fl4;
- u8 tos;
+ u8 tos, ttl;
__be16 df;
struct rtable *rt; /* Route to the other host */
struct net_device *tdev; /* Device to other host */
- struct iphdr *iph; /* Our new IP header */
unsigned int max_headroom; /* The extra header space
needed */
+ struct iphdr *iph; /* Our new IP header */
int gre_hlen;
__be32 dst;
int mtu;
@@ -803,63 +827,39 @@ static netdev_tx_t ipgre_tunnel_xmit(struct sk_buff *skb,
struct net_device *dev
old_iph = ip_hdr(skb);
}
- skb_reset_transport_header(skb);
- skb_push(skb, gre_hlen);
- skb_reset_network_header(skb);
memset(&(IPCB(skb)->opt), 0, sizeof(IPCB(skb)->opt));
IPCB(skb)->flags &= ~(IPSKB_XFRM_TUNNEL_SIZE | IPSKB_XFRM_TRANSFORMED |
IPSKB_REROUTED);
skb_dst_drop(skb);
skb_dst_set(skb, &rt->dst);
- /*
- * Push down and install the IPIP header.
- */
+ tos = ipgre_ecn_encapsulate(tos, old_iph, skb);
- iph = ip_hdr(skb);
- iph->version = 4;
- iph->ihl = sizeof(struct iphdr) >> 2;
- iph->frag_off = df;
- iph->protocol = IPPROTO_GRE;
- iph->tos = ipgre_ecn_encapsulate(tos, old_iph,
skb);
- iph->daddr = fl4.daddr;
- iph->saddr = fl4.saddr;
-
- if ((iph->ttl = tiph->ttl) == 0) {
+ if ((ttl = tiph->ttl) == 0) {
if (skb->protocol == htons(ETH_P_IP))
- iph->ttl = old_iph->ttl;
+ ttl = old_iph->ttl;
#if IS_ENABLED(CONFIG_IPV6)
else if (skb->protocol == htons(ETH_P_IPV6))
- iph->ttl = ((const struct ipv6hdr *)old_iph)->hop_limit;
+ ttl = ((const struct ipv6hdr *)old_iph)->hop_limit;
#endif
else
- iph->ttl = ip4_dst_hoplimit(&rt->dst);
+ ttl = ip4_dst_hoplimit(&rt->dst);
}
- ((__be16 *)(iph + 1))[0] = tunnel->parms.o_flags;
- ((__be16 *)(iph + 1))[1] = (dev->type == ARPHRD_ETHER) ?
- htons(ETH_P_TEB) : skb->protocol;
-
- if (tunnel->parms.o_flags&(GRE_KEY|GRE_CSUM|GRE_SEQ)) {
- __be32 *ptr = (__be32 *)(((u8 *)iph) + tunnel->hlen - 4);
+ /*
+ * Push down and install the IPIP header.
+ */
+ build_ip_header(skb, &fl4, gre_hlen, df, tos, ttl);
+ if (tunnel->parms.o_flags&GRE_SEQ)
+ ++tunnel->o_seqno;
- if (tunnel->parms.o_flags&GRE_SEQ) {
- ++tunnel->o_seqno;
- *ptr = htonl(tunnel->o_seqno);
- ptr--;
- }
- if (tunnel->parms.o_flags&GRE_KEY) {
- *ptr = tunnel->parms.o_key;
- ptr--;
- }
- if (tunnel->parms.o_flags&GRE_CSUM) {
- *ptr = 0;
- *(__sum16 *)ptr = ip_compute_csum((void *)(iph+1),
skb->len - sizeof(struct iphdr));
- }
- }
+ build_gre_header(skb, tunnel->hlen, tunnel->parms.o_flags,
+ (dev->type == ARPHRD_ETHER) ? htons(ETH_P_TEB) :
skb->protocol,
+ tunnel->parms.o_key, tunnel->o_seqno);
nf_reset(skb);
tstats = this_cpu_ptr(dev->tstats);
+ iph = ip_hdr(skb);
__IPTUNNEL_XMIT(tstats, &dev->stats);
return NETDEV_TX_OK;
--
1.7.10
_______________________________________________
dev mailing list
[email protected]
http://openvswitch.org/mailman/listinfo/dev