Skip to content

Commit e7a409c

Browse files
edumazetdavem330
authored andcommitted
ipv4: fix IPSKB_FRAG_PMTU handling with fragmentation
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 <[email protected]> Signed-off-by: Eric Dumazet <[email protected]> Signed-off-by: Pablo Neira Ayuso <[email protected]> Signed-off-by: Linus Torvalds <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 40c5b2b commit e7a409c

File tree

3 files changed

+9
-8
lines changed

3 files changed

+9
-8
lines changed

include/net/ip.h

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

187187
struct ip_frag_state {
188-
struct iphdr *iph;
188+
bool DF;
189189
unsigned int hlen;
190190
unsigned int ll_rs;
191191
unsigned int mtu;
@@ -196,7 +196,7 @@ struct ip_frag_state {
196196
};
197197

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

net/bridge/netfilter/nf_conntrack_bridge.c

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

100100
while (state.left > 0) {
101101
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
@@ -883,7 +883,8 @@ int ip_do_fragment(struct net *net, struct sock *sk, struct sk_buff *skb,
883883
* Fragment the datagram.
884884
*/
885885

886-
ip_frag_init(skb, hlen, ll_rs, mtu, &state);
886+
ip_frag_init(skb, hlen, ll_rs, mtu, IPCB(skb)->flags & IPSKB_FRAG_PMTU,
887+
&state);
887888

888889
/*
889890
* Keep copying data until we run out.

0 commit comments

Comments
 (0)