@@ -61,6 +61,26 @@ static void nft_exthdr_ipv6_eval(const struct nft_expr *expr,
61
61
regs -> verdict .code = NFT_BREAK ;
62
62
}
63
63
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
+
64
84
static void nft_exthdr_tcp_eval (const struct nft_expr * expr ,
65
85
struct nft_regs * regs ,
66
86
const struct nft_pktinfo * pkt )
@@ -72,18 +92,7 @@ static void nft_exthdr_tcp_eval(const struct nft_expr *expr,
72
92
struct tcphdr * tcph ;
73
93
u8 * opt ;
74
94
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 );
87
96
if (!tcph )
88
97
goto err ;
89
98
0 commit comments