Skip to content

Commit dc9df3f

Browse files
edumazetgregkh
authored andcommitted
ipv4: fix IPSKB_FRAG_PMTU handling with fragmentation
[ Upstream commit e7a409c ] This patch removes the iph field from the state structure, which is not properly initialized. Instead, add a new field to make the "do we want to set DF" be the state bit and move the code to set the DF flag from ip_frag_next(). Joint work with Pablo and Linus. Fixes: 19c3401 ("net: ipv4: place control buffer handling away from fragmentation iterators") Reported-by: Patrick Schönthaler <patrick@notvads.ovh> Signed-off-by: Eric Dumazet <edumazet@google.com> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: David S. Miller <davem@davemloft.net> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 372a4ff commit dc9df3f

3 files changed

Lines changed: 9 additions & 8 deletions

File tree

‎include/net/ip.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ static inline struct sk_buff *ip_fraglist_next(struct ip_fraglist_iter *iter)
184184
}
185185

186186
struct ip_frag_state {
187-
struct iphdr *iph;
187+
bool DF;
188188
unsigned int hlen;
189189
unsigned int ll_rs;
190190
unsigned int mtu;
@@ -195,7 +195,7 @@ struct ip_frag_state {
195195
};
196196

197197
void ip_frag_init(struct sk_buff *skb, unsigned int hlen, unsigned int ll_rs,
198-
unsigned int mtu, struct ip_frag_state *state);
198+
unsigned int mtu, bool DF, struct ip_frag_state *state);
199199
struct sk_buff *ip_frag_next(struct sk_buff *skb,
200200
struct ip_frag_state *state);
201201

‎net/bridge/netfilter/nf_conntrack_bridge.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ static int nf_br_ip_fragment(struct net *net, struct sock *sk,
9494
* This may also be a clone skbuff, we could preserve the geometry for
9595
* the copies but probably not worth the effort.
9696
*/
97-
ip_frag_init(skb, hlen, ll_rs, frag_max_size, &state);
97+
ip_frag_init(skb, hlen, ll_rs, frag_max_size, false, &state);
9898

9999
while (state.left > 0) {
100100
struct sk_buff *skb2;

‎net/ipv4/ip_output.c‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -645,11 +645,12 @@ void ip_fraglist_prepare(struct sk_buff *skb, struct ip_fraglist_iter *iter)
645645
EXPORT_SYMBOL(ip_fraglist_prepare);
646646

647647
void ip_frag_init(struct sk_buff *skb, unsigned int hlen,
648-
unsigned int ll_rs, unsigned int mtu,
648+
unsigned int ll_rs, unsigned int mtu, bool DF,
649649
struct ip_frag_state *state)
650650
{
651651
struct iphdr *iph = ip_hdr(skb);
652652

653+
state->DF = DF;
653654
state->hlen = hlen;
654655
state->ll_rs = ll_rs;
655656
state->mtu = mtu;
@@ -668,9 +669,6 @@ static void ip_frag_ipcb(struct sk_buff *from, struct sk_buff *to,
668669
/* Copy the flags to each fragment. */
669670
IPCB(to)->flags = IPCB(from)->flags;
670671

671-
if (IPCB(from)->flags & IPSKB_FRAG_PMTU)
672-
state->iph->frag_off |= htons(IP_DF);
673-
674672
/* ANK: dirty, but effective trick. Upgrade options only if
675673
* the segment to be fragmented was THE FIRST (otherwise,
676674
* options are already fixed) and make it ONCE
@@ -738,6 +736,8 @@ struct sk_buff *ip_frag_next(struct sk_buff *skb, struct ip_frag_state *state)
738736
*/
739737
iph = ip_hdr(skb2);
740738
iph->frag_off = htons((state->offset >> 3));
739+
if (state->DF)
740+
iph->frag_off |= htons(IP_DF);
741741

742742
/*
743743
* Added AC : If we are fragmenting a fragment that's not the
@@ -881,7 +881,8 @@ int ip_do_fragment(struct net *net, struct sock *sk, struct sk_buff *skb,
881881
* Fragment the datagram.
882882
*/
883883

884-
ip_frag_init(skb, hlen, ll_rs, mtu, &state);
884+
ip_frag_init(skb, hlen, ll_rs, mtu, IPCB(skb)->flags & IPSKB_FRAG_PMTU,
885+
&state);
885886

886887
/*
887888
* Keep copying data until we run out.

0 commit comments

Comments
 (0)