mirror of
https://github.com/followmsi/android_kernel_google_msm.git
synced 2024-11-06 23:17:41 +00:00
ipv4: fix path MTU discovery with connection tracking
IPv4 conntrack defragments incoming packet at the PRE_ROUTING hook and (in case of forwarded packets) refragments them at POST_ROUTING independent of the IP_DF flag. Refragmentation uses the dst_mtu() of the local route without caring about the original fragment sizes, thereby breaking PMTUD. This patch fixes this by keeping track of the largest received fragment with IP_DF set and generates an ICMP fragmentation required error during refragmentation if that size exceeds the MTU. Change-Id: Ibac77b728baba05841286ea5a8a2089d56e6ad65 Signed-off-by: Patrick McHardy <kaber@trash.net> Acked-by: Eric Dumazet <edumazet@google.com> Acked-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
69adc8757e
commit
d1e8c3336e
4 changed files with 14 additions and 2 deletions
|
@ -29,6 +29,8 @@ struct inet_frag_queue {
|
||||||
#define INET_FRAG_COMPLETE 4
|
#define INET_FRAG_COMPLETE 4
|
||||||
#define INET_FRAG_FIRST_IN 2
|
#define INET_FRAG_FIRST_IN 2
|
||||||
#define INET_FRAG_LAST_IN 1
|
#define INET_FRAG_LAST_IN 1
|
||||||
|
|
||||||
|
u16 max_size;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define INETFRAGS_HASHSZ 64
|
#define INETFRAGS_HASHSZ 64
|
||||||
|
|
|
@ -43,6 +43,8 @@ struct inet_skb_parm {
|
||||||
#define IPSKB_FRAG_COMPLETE BIT(3)
|
#define IPSKB_FRAG_COMPLETE BIT(3)
|
||||||
#define IPSKB_REROUTED BIT(4)
|
#define IPSKB_REROUTED BIT(4)
|
||||||
#define IPSKB_DOREDIRECT BIT(5)
|
#define IPSKB_DOREDIRECT BIT(5)
|
||||||
|
|
||||||
|
u16 frag_max_size;
|
||||||
};
|
};
|
||||||
|
|
||||||
static inline unsigned int ip_hdrlen(const struct sk_buff *skb)
|
static inline unsigned int ip_hdrlen(const struct sk_buff *skb)
|
||||||
|
|
|
@ -515,6 +515,10 @@ found:
|
||||||
if (offset == 0)
|
if (offset == 0)
|
||||||
qp->q.last_in |= INET_FRAG_FIRST_IN;
|
qp->q.last_in |= INET_FRAG_FIRST_IN;
|
||||||
|
|
||||||
|
if (ip_hdr(skb)->frag_off & htons(IP_DF) &&
|
||||||
|
skb->len + ihl > qp->q.max_size)
|
||||||
|
qp->q.max_size = skb->len + ihl;
|
||||||
|
|
||||||
if (qp->q.last_in == (INET_FRAG_FIRST_IN | INET_FRAG_LAST_IN) &&
|
if (qp->q.last_in == (INET_FRAG_FIRST_IN | INET_FRAG_LAST_IN) &&
|
||||||
qp->q.meat == qp->q.len) {
|
qp->q.meat == qp->q.len) {
|
||||||
unsigned long orefdst = skb->_skb_refdst;
|
unsigned long orefdst = skb->_skb_refdst;
|
||||||
|
@ -632,9 +636,11 @@ static int ip_frag_reasm(struct ipq *qp, struct sk_buff *prev,
|
||||||
head->next = NULL;
|
head->next = NULL;
|
||||||
head->dev = dev;
|
head->dev = dev;
|
||||||
head->tstamp = qp->q.stamp;
|
head->tstamp = qp->q.stamp;
|
||||||
|
IPCB(head)->frag_max_size = qp->q.max_size;
|
||||||
|
|
||||||
iph = ip_hdr(head);
|
iph = ip_hdr(head);
|
||||||
iph->frag_off = 0;
|
/* max_size != 0 implies at least one fragment had IP_DF set */
|
||||||
|
iph->frag_off = qp->q.max_size ? htons(IP_DF) : 0;
|
||||||
iph->tot_len = htons(len);
|
iph->tot_len = htons(len);
|
||||||
iph->tos |= ecn;
|
iph->tos |= ecn;
|
||||||
ip_send_check(iph);
|
ip_send_check(iph);
|
||||||
|
|
|
@ -475,7 +475,9 @@ int ip_fragment(struct sk_buff *skb, int (*output)(struct sk_buff *))
|
||||||
|
|
||||||
iph = ip_hdr(skb);
|
iph = ip_hdr(skb);
|
||||||
|
|
||||||
if (unlikely((iph->frag_off & htons(IP_DF)) && !skb->local_df)) {
|
if (unlikely(((iph->frag_off & htons(IP_DF)) && !skb->local_df) ||
|
||||||
|
(IPCB(skb)->frag_max_size &&
|
||||||
|
IPCB(skb)->frag_max_size > dst_mtu(&rt->dst)))) {
|
||||||
IP_INC_STATS(dev_net(dev), IPSTATS_MIB_FRAGFAILS);
|
IP_INC_STATS(dev_net(dev), IPSTATS_MIB_FRAGFAILS);
|
||||||
icmp_send(skb, ICMP_DEST_UNREACH, ICMP_FRAG_NEEDED,
|
icmp_send(skb, ICMP_DEST_UNREACH, ICMP_FRAG_NEEDED,
|
||||||
htonl(ip_skb_dst_mtu(skb)));
|
htonl(ip_skb_dst_mtu(skb)));
|
||||||
|
|
Loading…
Reference in a new issue