net: ipv4: Add ability to have GRE ignore DF bit in IPv4 payloads
Subsystems (3)
PATCH 1/1 net: ipv4: Add ability to have GRE ignore DF bit in IPv4 payloads
From: Philip Prindeville <[email protected]>
In the presence of firewalls which improperly block ICMP Unreachable (including Fragmentation Required) messages, Path MTU Discovery is prevented from working.
A workaround is to handle IPv4 payloads opaquely, ignoring the DF bit--as is done for other payloads like AppleTalk--and doing transparent fragmentation and reassembly.
--- include/net/ip_tunnels.h | 1 + include/uapi/linux/if_tunnel.h | 1 + net/ipv4/ip_gre.c | 13 +++++++++++-- net/ipv4/ip_tunnel.c | 2 +- 4 files changed, 14 insertions(+), 3 deletions(-)
include/net/ip_tunnels.h +1 -0
@@ -132,6 +132,7 @@ struct ip_tunnel {int ip_tnl_net_id;struct gro_cells gro_cells;bool collect_md; +bool ignore_df; };#define TUNNEL_CSUM __cpu_to_be16(0x01)
include/uapi/linux/if_tunnel.h +1 -0
@@ -113,6 +113,7 @@ enum {IFLA_GRE_ENCAP_SPORT ,IFLA_GRE_ENCAP_DPORT ,IFLA_GRE_COLLECT_METADATA , +IFLA_GRE_IGNORE_DF , __IFLA_GRE_MAX, };
net/ipv4/ip_gre.c +11 -2
@@ -846,6 +846,8 @@ static void ipgre_netlink_parms(struct net_device *dev,struct nlattr *tb[], struct ip_tunnel_parm *parms) { + struct ip_tunnel *t = netdev_priv(dev); +memset (parms,0 ,sizeof (*parms)); parms->iph.protocol =IPPROTO_GRE ;
@@ -884,12 +886,13 @@ static void ipgre_netlink_parms(struct net_device *dev, parms->iph.frag_off =htons (IP_DF );if (data[IFLA_GRE_COLLECT_METADATA ]) { -struct ip_tunnel *t =netdev_priv (dev); - t->collect_md = true;if (dev->type ==ARPHRD_IPGRE ) dev->type =ARPHRD_NONE ; } + +if (data[IFLA_GRE_IGNORE_DF ]) + t->ignore_df = !!nla_get_u8 (data[IFLA_GRE_IGNORE_DF ]); }/* This function returns true when ENCAP attributes are present in the nl msg */
@@ -1024,6 +1027,8 @@ static size_t ipgre_get_size(const struct net_device *dev)nla_total_size (2 ) +/* IFLA_GRE_COLLECT_METADATA */ nla_total_size (0 ) + +/* IFLA_GRE_IGNORE_DF */ +nla_total_size (1 ) +0 ; }
@@ -1057,6 +1062,9 @@ static int ipgre_fill_info(struct sk_buff *skb, const struct net_device *dev) t->encap.flags)) goto nla_put_failure; +if (nla_put_u8 (skb,IFLA_GRE_IGNORE_DF , t->ignore_df)) + goto nla_put_failure; +if (t->collect_md) {if (nla_put_flag (skb,IFLA_GRE_COLLECT_METADATA )) goto nla_put_failure;
@@ -1084,6 +1092,7 @@ static const struct nla_policy ipgre_policy[IFLA_GRE_MAX + 1] = { [IFLA_GRE_ENCAP_SPORT] = { .type = NLA_U16 }, [IFLA_GRE_ENCAP_DPORT] = { .type = NLA_U16 }, [IFLA_GRE_COLLECT_METADATA] = { .type = NLA_FLAG }, + [IFLA_GRE_IGNORE_DF] = { .type = NLA_U8 }, };static struct rtnl_link_ops ipgre_link_ops__read_mostly = {
net/ipv4/ip_tunnel.c +1 -1
@@ -682,7 +682,7 @@ void ip_tunnel_xmit(struct sk_buff *skb, struct net_device *dev, } df = tnl_params->frag_off; -if (skb->protocol ==htons (ETH_P_IP )) +if (skb->protocol ==htons (ETH_P_IP ) && !tunnel->ignore_df) df |= (inner_iph->frag_off&htons (IP_DF )); max_headroom =LL_RESERVED_SPACE (rt->dst.dev) +sizeof (struct iphdr )
Quoted 14 lines · Philip Prindeville
static struct
rtnl_link_opsipgre_link_ops__read_mostly= {net/ipv4/ip_tunnel.c +1
-1@@ -682,7 +682,7 @@ void ip_tunnel_xmit(struct sk_buff *skb, structnet_device *dev, } df = tnl_params->frag_off; -if (skb->protocol ==htons (ETH_P_IP )) +if (skb->protocol ==htons (ETH_P_IP ) && !tunnel->ignore_df) df |= (inner_iph->frag_off&htons (IP_DF ));
Quoted 1 line
max_headroom=LL_RESERVED_SPACE(rt->dst.dev)+ sizeof(struct iphdr)
Is still enforce that we inherit the ttl from the inner header to the outer header if we don't set df bit?
Thanks,
Hannes
Quoted 16 lines · Hannes Frederic Sowa
Quoted 14 lines · Philip Prindeville
static struct rtnl_link_ops ipgre_link_ops __read_mostly = {net/ipv4/ip_tunnel.c +1
-1@@ -682,7 +682,7 @@ void ip_tunnel_xmit(struct sk_buff *skb, structnet_device *dev, } df = tnl_params->frag_off; -if (skb->protocol ==htons (ETH_P_IP )) +if (skb->protocol ==htons (ETH_P_IP ) && !tunnel->ignore_df) df |= (inner_iph->frag_off&htons (IP_DF ));
Quoted 6 lines
Quoted 1 line
max_headroom=LL_RESERVED_SPACE(rt->dst.dev)+ sizeof(struct iphdr)Is still enforce that we inherit the ttl from the inner header to the outer header if we don't set df bit?
Thanks,
Hannes
That's correct. That happens a few lines above and we don't change that behavior with this patch.
-Philip
Hannes Frederic Sowa
Acked-byQuoted 20 lines · Philip Prindeville
Quoted 19 lines · Hannes Frederic Sowa
Quoted 6 lines · Philip Prindeville
static struct rtnl_link_ops ipgre_link_ops __read_mostly = {net/ipv4/ip_tunnel.c +0
-0net/ipv4/ip_tunnel.c void ip_tunnel_xmit(struct sk_buff *skb, struct · line 688
Quoted 8 lines
net/ipv4/ip_tunnel.c +1
-1@@ -682,7 +682,7 @@ void ip_tunnel_xmit(struct sk_buff *skb, structnet_device *dev, } df = tnl_params->frag_off; -if (skb->protocol ==htons (ETH_P_IP )) +if (skb->protocol ==htons (ETH_P_IP ) && !tunnel->ignore_df) df |= (inner_iph->frag_off&htons (IP_DF )); max_headroom =LL_RESERVED_SPACE (rt->dst.dev) +sizeof (struct iphdr )Is still enforce that we inherit the ttl from the inner header to the outer header if we don't set df bit?
Quoted 5 lines
Quoted 2 lines
Thanks,
HannesThat's correct. That happens a few lines above and we don't change that behavior with this patch.
It should be discouraged to use this feature, but I have to admit that I already used stripping of DF bit, too.
Thanks,
Hannes
Quoted 24 lines · Hannes Frederic Sowa
Quoted 19 lines · Philip Prindeville
Quoted 18 lines · Hannes Frederic Sowa
Quoted 6 lines · Philip Prindeville
static struct rtnl_link_ops ipgre_link_ops __read_mostly = {net/ipv4/ip_tunnel.c +0
-0net/ipv4/ip_tunnel.c void ip_tunnel_xmit(struct sk_buff *skb, struct · line 688
Quoted 8 lines
net/ipv4/ip_tunnel.c +1
-1@@ -682,7 +682,7 @@ void ip_tunnel_xmit(struct sk_buff *skb, structnet_device *dev, } df = tnl_params->frag_off; -if (skb->protocol ==htons (ETH_P_IP )) +if (skb->protocol ==htons (ETH_P_IP ) && !tunnel->ignore_df) df |= (inner_iph->frag_off&htons (IP_DF )); max_headroom =LL_RESERVED_SPACE (rt->dst.dev) +sizeof (struct iphdr )Is still enforce that we inherit the ttl from the inner header to the outer header if we don't set df bit?
Quoted 4 lines
Quoted 2 lines
Thanks,
HannesThat's correct. That happens a few lines above and we don't change that behavior with this patch.
Quoted 7 lines
It should be discouraged to use this feature, but I have to admit that I already used stripping of DF bit, too.
Thanks,
Hannes
Yeah, it's admittedly a kludge to get around broken customer firewalls which are discarding ICMP's they have no business filtering.
It's the "least ugly workaround" in this scenario.
If you have control over the offending firewalls, it's easier (and better) to fix them than configuring this option... but sometimes you have to put up with other people having broken equipment on your network.
-Philip
Quoted 59 lines · Philip Prindeville
From: Philip Prindeville <[email protected]>
In the presence of firewalls which improperly block ICMP Unreachable (including Fragmentation Required) messages, Path MTU Discovery is prevented from working.
A workaround is to handle IPv4 payloads opaquely, ignoring the DF bit--as is done for other payloads like AppleTalk--and doing transparent fragmentation and reassembly.
Reviewed-by Stephen Hemminger <[email protected]>Signed-off-by Philip Prindeville <[email protected]>--- include/net/ip_tunnels.h | 1 + include/uapi/linux/if_tunnel.h | 1 + net/ipv4/ip_gre.c | 13 +++++++++++-- net/ipv4/ip_tunnel.c | 2 +- 4 files changed, 14 insertions(+), 3 deletions(-)include/net/ip_tunnels.h +1
-0@@ -132,6 +132,7 @@ struct ip_tunnel {int ip_tnl_net_id;struct gro_cells gro_cells;bool collect_md; +bool ignore_df; };#define TUNNEL_CSUM __cpu_to_be16(0x01)include/uapi/linux/if_tunnel.h +1
-0@@ -113,6 +113,7 @@ enum {IFLA_GRE_ENCAP_SPORT ,IFLA_GRE_ENCAP_DPORT ,IFLA_GRE_COLLECT_METADATA , +IFLA_GRE_IGNORE_DF , __IFLA_GRE_MAX, };net/ipv4/ip_gre.c +2
-0@@ -846,6 +846,8 @@ static void ipgre_netlink_parms(struct net_device *dev,struct nlattr *tb[], struct ip_tunnel_parm *parms) { + struct ip_tunnel *t = netdev_priv(dev); +memset (parms,0 ,sizeof (*parms)); parms->iph.protocol =IPPROTO_GRE ;@@ -884,12 +886,13 @@ static void ipgre_netlink_parms(struct net_device *dev, parms->iph.frag_off =htons (IP_DF );
net/ipv4/ip_gre.c static void ipgre_netlink_parms(struct net_device *dev, · line 895
Quoted 10 lines
net/ipv4/ip_gre.c +3
-2if (data[IFLA_GRE_COLLECT_METADATA ]) { -struct ip_tunnel *t =netdev_priv (dev); - t->collect_md = true;if (dev->type ==ARPHRD_IPGRE ) dev->type =ARPHRD_NONE ; } + +if (data[IFLA_GRE_IGNORE_DF ]) + t->ignore_df = !!nla_get_u8 (data[IFLA_GRE_IGNORE_DF ]);
Why are you passing this as a u8? Why not just pass it as a flag since it defaults to off?
net/ipv4/ip_gre.c static size_t ipgre_get_size(const struct net_device *dev) · line 1033
Quoted 11 lines
net/ipv4/ip_gre.c +2
-0}/* This function returns true when ENCAP attributes are present in the nl msg */ @@ -1024,6 +1027,8 @@ static size_t ipgre_get_size(const struct net_device *dev)nla_total_size (2 ) +/* IFLA_GRE_COLLECT_METADATA */ nla_total_size (0 ) + +/* IFLA_GRE_IGNORE_DF */ +nla_total_size (1 ) +0 ; }
Switching it to a flag would help reduce the total size.
Quoted 11 lines
net/ipv4/ip_gre.c +3
-0@@ -1057,6 +1062,9 @@ static int ipgre_fill_info(struct sk_buff *skb, const struct net_device *dev) t->encap.flags)) goto nla_put_failure; +if (nla_put_u8 (skb,IFLA_GRE_IGNORE_DF , t->ignore_df)) + goto nla_put_failure; +if (t->collect_md) {if (nla_put_flag (skb,IFLA_GRE_COLLECT_METADATA )) goto nla_put_failure;
net/ipv4/ip_gre.c static const struct nla_policy ipgre_policy[IFLA_GRE_MAX + 1] = { · line 1097
Quoted 6 lines
net/ipv4/ip_gre.c +1
-0@@ -1084,6 +1092,7 @@ static const struct nla_policy ipgre_policy[IFLA_GRE_MAX + 1] = { [IFLA_GRE_ENCAP_SPORT] = { .type = NLA_U16 }, [IFLA_GRE_ENCAP_DPORT] = { .type = NLA_U16 }, [IFLA_GRE_COLLECT_METADATA] = { .type = NLA_FLAG }, + [IFLA_GRE_IGNORE_DF] = { .type = NLA_U8 }, };
You could just copy the approach used for COLLECT_METADATA and skip the need to pass any data and instead just use a flag.
Quoted 6 lines
net/ipv4/ip_gre.c +0
-0static struct rtnl_link_ops ipgre_link_ops__read_mostly = {net/ipv4/ip_tunnel.c +0
-0
net/ipv4/ip_tunnel.c void ip_tunnel_xmit(struct sk_buff *skb, struct net_device *dev, · line 688
Quoted 8 lines
net/ipv4/ip_tunnel.c +1
-1@@ -682,7 +682,7 @@ void ip_tunnel_xmit(struct sk_buff *skb, struct net_device *dev, } df = tnl_params->frag_off; -if (skb->protocol ==htons (ETH_P_IP )) +if (skb->protocol ==htons (ETH_P_IP ) && !tunnel->ignore_df) df |= (inner_iph->frag_off&htons (IP_DF )); max_headroom =LL_RESERVED_SPACE (rt->dst.dev) +sizeof (struct iphdr )
Looking at this it appears that you should probably make the feature mutually exclusive from the pmtudisc feature. It wouldn't make much sense to set the tunnel to ignore the inner DF bit and then turn around and set it because you are enforcing path MTU discovery on the tunnel itself.
Quoted 96 lines · Alexander Duyck
Quoted 59 lines · Philip Prindeville
From: Philip Prindeville <[email protected]>
In the presence of firewalls which improperly block ICMP Unreachable (including Fragmentation Required) messages, Path MTU Discovery is prevented from working.
A workaround is to handle IPv4 payloads opaquely, ignoring the DF bit--as is done for other payloads like AppleTalk--and doing transparent fragmentation and reassembly.
Reviewed-by Stephen Hemminger <[email protected]>Signed-off-by Philip Prindeville <[email protected]>---
include/net/ip_tunnels.h | 1 + include/uapi/linux/if_tunnel.h | 1 + net/ipv4/ip_gre.c | 13 +++++++++++-- net/ipv4/ip_tunnel.c | 2 +- 4 files changed, 14 insertions(+), 3 deletions(-)include/net/ip_tunnels.h +1
-0@@ -132,6 +132,7 @@ struct ip_tunnel {int ip_tnl_net_id;struct gro_cells gro_cells;bool collect_md; +bool ignore_df; };#define TUNNEL_CSUM __cpu_to_be16(0x01)include/uapi/linux/if_tunnel.h +1
-0@@ -113,6 +113,7 @@ enum {IFLA_GRE_ENCAP_SPORT ,IFLA_GRE_ENCAP_DPORT ,IFLA_GRE_COLLECT_METADATA , +IFLA_GRE_IGNORE_DF , __IFLA_GRE_MAX, };net/ipv4/ip_gre.c +2
-0@@ -846,6 +846,8 @@ static void ipgre_netlink_parms(struct net_device *dev,struct nlattr *tb[], struct ip_tunnel_parm *parms) { + struct ip_tunnel *t = netdev_priv(dev); +memset (parms,0 ,sizeof (*parms)); parms->iph.protocol =IPPROTO_GRE ;@@ -884,12 +886,13 @@ static void ipgre_netlink_parms(struct net_device *dev, parms->iph.frag_off =htons (IP_DF );net/ipv4/ip_gre.c static void ipgre_netlink_parms(struct net_device *dev, · line 895
Quoted 10 lines
net/ipv4/ip_gre.c +3
-2if (data[IFLA_GRE_COLLECT_METADATA ]) { -struct ip_tunnel *t =netdev_priv (dev); - t->collect_md = true;if (dev->type ==ARPHRD_IPGRE ) dev->type =ARPHRD_NONE ; } + +if (data[IFLA_GRE_IGNORE_DF ]) + t->ignore_df = !!nla_get_u8 (data[IFLA_GRE_IGNORE_DF ]);Why are you passing this as a u8? Why not just pass it as a flag since it defaults to off?
net/ipv4/ip_gre.c static size_t ipgre_get_size(const struct net_device *dev) · line 1033
Quoted 11 lines
net/ipv4/ip_gre.c +2
-0}/* This function returns true when ENCAP attributes are present in the nl msg */ @@ -1024,6 +1027,8 @@ static size_t ipgre_get_size(const struct net_device *dev)nla_total_size (2 ) +/* IFLA_GRE_COLLECT_METADATA */ nla_total_size (0 ) + +/* IFLA_GRE_IGNORE_DF */ +nla_total_size (1 ) +0 ; }Switching it to a flag would help reduce the total size.
Quoted 4 lines
net/ipv4/ip_gre.c +0
-0@@ -1057,6 +1062,9 @@ static int ipgre_fill_info(struct sk_buff *skb, const struct net_device *dev) t->encap.flags)) goto nla_put_failure;
Quoted 16 lines
net/ipv4/ip_gre.c static const struct nla_policy ipgre_policy[IFLA_GRE_MAX + 1] = { · line 1097
Quoted 13 lines
net/ipv4/ip_gre.c +4
-0+if (nla_put_u8 (skb,IFLA_GRE_IGNORE_DF , t->ignore_df)) + goto nla_put_failure; +if (t->collect_md) {if (nla_put_flag (skb,IFLA_GRE_COLLECT_METADATA )) goto nla_put_failure;@@ -1084,6 +1092,7 @@ static const struct nla_policy ipgre_policy[IFLA_GRE_MAX + 1] = { [IFLA_GRE_ENCAP_SPORT] = { .type = NLA_U16 }, [IFLA_GRE_ENCAP_DPORT] = { .type = NLA_U16 }, [IFLA_GRE_COLLECT_METADATA] = { .type = NLA_FLAG }, + [IFLA_GRE_IGNORE_DF] = { .type = NLA_U8 }, };You could just copy the approach used for
COLLECT_METADATAand skip the need to pass any data and instead just use a flag.
I looked at doing that, but decided not to because there’s no way to turn it back off once you turn it on that way.
-Philip
Quoted 21 lines
Quoted 7 lines
net/ipv4/ip_gre.c +0
-0static struct rtnl_link_ops ipgre_link_ops__read_mostly = {net/ipv4/ip_tunnel.c +0
-0net/ipv4/ip_tunnel.c void ip_tunnel_xmit(struct sk_buff *skb, struct net_device *dev, · line 688
Quoted 8 lines
net/ipv4/ip_tunnel.c +1
-1@@ -682,7 +682,7 @@ void ip_tunnel_xmit(struct sk_buff *skb, struct net_device *dev, } df = tnl_params->frag_off; -if (skb->protocol ==htons (ETH_P_IP )) +if (skb->protocol ==htons (ETH_P_IP ) && !tunnel->ignore_df) df |= (inner_iph->frag_off&htons (IP_DF )); max_headroom =LL_RESERVED_SPACE (rt->dst.dev) +sizeof (struct iphdr )Looking at this it appears that you should probably make the feature mutually exclusive from the pmtudisc feature. It wouldn't make much sense to set the tunnel to ignore the inner DF bit and then turn around and set it because you are enforcing path MTU discovery on the tunnel itself.
David Miller
maintainerFrom: "Philip Prindeville" <[email protected]>
Date: Tue, 7 Jun 2016 13:48:46 -0600
Quoted 6 lines
From: Philip Prindeville <[email protected]>
In the presence of firewalls which improperly block ICMP Unreachable (including Fragmentation Required) messages, Path MTU Discovery is prevented from working.
Quoted 6 lines
A workaround is to handle IPv4 payloads opaquely, ignoring the DF bit--as is done for other payloads like AppleTalk--and doing transparent fragmentation and reassembly.
Reviewed-by Stephen Hemminger <[email protected]>Signed-off-by Philip Prindeville <[email protected]>
I think the feedback that this feature should be mutually exclusive to pmtudisc is valid and you should address that.
Quoted 16 lines · David Miller
From: "Philip Prindeville" <[email protected]>
Date: Tue, 7 Jun 2016 13:48:46 -0600Quoted 10 lines
From: Philip Prindeville <[email protected]>
In the presence of firewalls which improperly block ICMP Unreachable (including Fragmentation Required) messages, Path MTU Discovery is prevented from working.
A workaround is to handle IPv4 payloads opaquely, ignoring the DF bit--as is done for other payloads like AppleTalk--and doing transparent fragmentation and reassembly.
Quoted 5 lines
Quoted 2 lines
Reviewed-by Stephen Hemminger <[email protected]>Signed-off-by Philip Prindeville <[email protected]>I think the feedback that this feature should be mutually exclusive to pmtudisc is valid and you should address that.
Yes, understood. Looking into this.
-Philip