Skip to content

Commit fde2010

Browse files
Gerrit RenkerArnaldo Carvalho de Melo
authored andcommitted
[DCCP]: Retrieve packet sequence number for error reporting
This fixes a problem when analysing erroneous packets in dccp_v{4,6}_err: * dccp_hdr_seq currently takes an skb * however, the transport headers in the skb are shifted, due to the preceding IPv4/v6 header. Fixed for v4 and v6 by changing dccp_hdr_seq to take a struct dccp_hdr as argument. Verified that the correct sequence number is now reported in the error handler. Signed-off-by: Gerrit Renker <gerrit@erg.abdn.ac.uk> Acked-by: Ian McDonald <ian.mcdonald@jandi.co.nz> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent 03cf786 commit fde2010

3 files changed

Lines changed: 8 additions & 10 deletions

File tree

‎include/linux/dccp.h‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -270,10 +270,9 @@ static inline struct dccp_hdr *dccp_zeroed_hdr(struct sk_buff *skb, int headlen)
270270
return memset(skb_transport_header(skb), 0, headlen);
271271
}
272272

273-
static inline struct dccp_hdr_ext *dccp_hdrx(const struct sk_buff *skb)
273+
static inline struct dccp_hdr_ext *dccp_hdrx(const struct dccp_hdr *dh)
274274
{
275-
return (struct dccp_hdr_ext *)(skb_transport_header(skb) +
276-
sizeof(struct dccp_hdr));
275+
return (struct dccp_hdr_ext *)((unsigned char *)dh + sizeof(*dh));
277276
}
278277

279278
static inline unsigned int __dccp_basic_hdr_len(const struct dccp_hdr *dh)
@@ -287,13 +286,12 @@ static inline unsigned int dccp_basic_hdr_len(const struct sk_buff *skb)
287286
return __dccp_basic_hdr_len(dh);
288287
}
289288

290-
static inline __u64 dccp_hdr_seq(const struct sk_buff *skb)
289+
static inline __u64 dccp_hdr_seq(const struct dccp_hdr *dh)
291290
{
292-
const struct dccp_hdr *dh = dccp_hdr(skb);
293291
__u64 seq_nr = ntohs(dh->dccph_seq);
294292

295293
if (dh->dccph_x != 0)
296-
seq_nr = (seq_nr << 32) + ntohl(dccp_hdrx(skb)->dccph_seq_low);
294+
seq_nr = (seq_nr << 32) + ntohl(dccp_hdrx(dh)->dccph_seq_low);
297295
else
298296
seq_nr += (u32)dh->dccph_seq2 << 16;
299297

‎net/dccp/ipv4.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ static void dccp_v4_err(struct sk_buff *skb, u32 info)
241241
goto out;
242242

243243
dp = dccp_sk(sk);
244-
seq = dccp_hdr_seq(skb);
244+
seq = dccp_hdr_seq(dh);
245245
if (sk->sk_state != DCCP_LISTEN &&
246246
!between48(seq, dp->dccps_swl, dp->dccps_swh)) {
247247
NET_INC_STATS_BH(LINUX_MIB_OUTOFWINDOWICMPS);
@@ -795,7 +795,7 @@ static int dccp_v4_rcv(struct sk_buff *skb)
795795

796796
dh = dccp_hdr(skb);
797797

798-
DCCP_SKB_CB(skb)->dccpd_seq = dccp_hdr_seq(skb);
798+
DCCP_SKB_CB(skb)->dccpd_seq = dccp_hdr_seq(dh);
799799
DCCP_SKB_CB(skb)->dccpd_type = dh->dccph_type;
800800

801801
dccp_pr_debug("%8.8s "

‎net/dccp/ipv6.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ static void dccp_v6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
173173

174174
icmpv6_err_convert(type, code, &err);
175175

176-
seq = DCCP_SKB_CB(skb)->dccpd_seq;
176+
seq = dccp_hdr_seq(dh);
177177
/* Might be for an request_sock */
178178
switch (sk->sk_state) {
179179
struct request_sock *req, **prev;
@@ -787,7 +787,7 @@ static int dccp_v6_rcv(struct sk_buff *skb)
787787

788788
dh = dccp_hdr(skb);
789789

790-
DCCP_SKB_CB(skb)->dccpd_seq = dccp_hdr_seq(skb);
790+
DCCP_SKB_CB(skb)->dccpd_seq = dccp_hdr_seq(dh);
791791
DCCP_SKB_CB(skb)->dccpd_type = dh->dccph_type;
792792

793793
if (dccp_packet_without_ack(skb))

0 commit comments

Comments
 (0)