Skip to content

Commit a181770

Browse files
Florian Westphalummakynes
authored andcommitted
netfilter: exthdr: factor out tcp option access
Signed-off-by: Florian Westphal <[email protected]> Signed-off-by: Pablo Neira Ayuso <[email protected]>
1 parent 46b20c3 commit a181770

File tree

1 file changed

+21
-12
lines changed

1 file changed

+21
-12
lines changed

net/netfilter/nft_exthdr.c

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,26 @@ static void nft_exthdr_ipv6_eval(const struct nft_expr *expr,
6161
regs->verdict.code = NFT_BREAK;
6262
}
6363

64+
static void *
65+
nft_tcp_header_pointer(const struct nft_pktinfo *pkt,
66+
unsigned int len, void *buffer, unsigned int *tcphdr_len)
67+
{
68+
struct tcphdr *tcph;
69+
70+
if (!pkt->tprot_set || pkt->tprot != IPPROTO_TCP)
71+
return NULL;
72+
73+
tcph = skb_header_pointer(pkt->skb, pkt->xt.thoff, sizeof(*tcph), buffer);
74+
if (!tcph)
75+
return NULL;
76+
77+
*tcphdr_len = __tcp_hdrlen(tcph);
78+
if (*tcphdr_len < sizeof(*tcph) || *tcphdr_len > len)
79+
return NULL;
80+
81+
return skb_header_pointer(pkt->skb, pkt->xt.thoff, *tcphdr_len, buffer);
82+
}
83+
6484
static void nft_exthdr_tcp_eval(const struct nft_expr *expr,
6585
struct nft_regs *regs,
6686
const struct nft_pktinfo *pkt)
@@ -72,18 +92,7 @@ static void nft_exthdr_tcp_eval(const struct nft_expr *expr,
7292
struct tcphdr *tcph;
7393
u8 *opt;
7494

75-
if (!pkt->tprot_set || pkt->tprot != IPPROTO_TCP)
76-
goto err;
77-
78-
tcph = skb_header_pointer(pkt->skb, pkt->xt.thoff, sizeof(*tcph), buff);
79-
if (!tcph)
80-
goto err;
81-
82-
tcphdr_len = __tcp_hdrlen(tcph);
83-
if (tcphdr_len < sizeof(*tcph))
84-
goto err;
85-
86-
tcph = skb_header_pointer(pkt->skb, pkt->xt.thoff, tcphdr_len, buff);
95+
tcph = nft_tcp_header_pointer(pkt, sizeof(buff), buff, &tcphdr_len);
8796
if (!tcph)
8897
goto err;
8998

0 commit comments

Comments
 (0)