netfilter: nf_conntrack_expect: add and use nf_ct_expect_related_pair()
Subsystems (2)
Pablo Neira Ayuso
maintainerPATCH v2 1/1 netfilter: nf_conntrack_expect: add and use nf_ct_expect_related_pair()
Add a new function to insert a pair of expectations, this is required by the SIP and H323 NAT helpers. The spinlock is held to check if there is a slot for both expectations, in such case, insert them.
This removes the need for nf_ct_unexpect_related() inside the loop to find a pair of consecutive ports, otherwise inserting expectations whose dead flag is already set on can happen.
Fixes b8b09dc2bf35 ("netfilter: nf_conntrack_expect: use conntrack GC to reap expectations")
Reported-by Jaeyeong Lee <[email protected]>
Signed-off-by Pablo Neira Ayuso <[email protected]>
---
v2: address sashiko comments on maximum number of expectations check
overflow and the missing safety check for null master_help.
include/net/netfilter/nf_conntrack_expect.h | 3 ++ net/ipv4/netfilter/nf_nat_h323.c | 22 ++++------- net/netfilter/nf_conntrack_expect.c | 41 +++++++++++++++++++-- net/netfilter/nf_nat_sip.c | 20 +++------- 4 files changed, 53 insertions(+), 33 deletions(-)
include/net/netfilter/nf_conntrack_expect.h +3 -0
@@ -161,6 +161,9 @@ static inline int nf_ct_expect_related(struct nf_conntrack_expect *expect,return nf_ct_expect_related_report (expect,0 ,0 , flags); } +int nf_ct_expect_related_pair (struct nf_conntrack_expect *expect[], +unsigned int flag); +struct nf_conn_help ;void nf_ct_expectation_gc (struct nf_conn_help *master_help);
net/ipv4/netfilter/nf_nat_h323.c +7 -15
@@ -182,6 +182,7 @@ static int nat_rtp_rtcp(struct sk_buff *skb, struct nf_conn *ct,struct nf_conntrack_expect *rtp_exp, struct nf_conntrack_expect *rtcp_exp) { + struct nf_conntrack_expect *rtp_pair[2] = { rtp_exp, rtcp_exp };struct nf_ct_h323_master *info =nfct_help_data (ct);int dir =CTINFO2DIR (ctinfo);int i;
@@ -227,22 +228,13 @@ static int nat_rtp_rtcp(struct sk_buff *skb, struct nf_conn *ct,int ret; rtp_exp->tuple.dst.u.udp.port =htons (nated_port); - ret =nf_ct_expect_related (rtp_exp,0 ); + rtcp_exp->tuple.dst.u.udp.port =htons (nated_port +1 ); + ret =nf_ct_expect_related_pair (rtp_pair,0 );if (ret ==0 ) { - rtcp_exp->tuple.dst.u.udp.port = -htons (nated_port +1 ); - ret =nf_ct_expect_related (rtcp_exp,0 ); -if (ret ==0 ) -break ; -else if (ret == -EBUSY ) { -nf_ct_unexpect_related (rtp_exp); -continue ; - }else if (ret <0 ) { -nf_ct_unexpect_related (rtp_exp); - nated_port =0 ; -break ; - } - }else if (ret != -EBUSY ) { +break ; + }else if (ret == -EBUSY ) { +continue ; + }else if (ret <0 ) { nated_port =0 ;break ; }
net/netfilter/nf_conntrack_expect.c +37 -4
82 lines not on this page · raw message
net/netfilter/nf_nat_sip.c +6 -14
@@ -592,6 +592,7 @@ static unsigned int nf_nat_sdp_media(struct sk_buff *skb, unsigned int protoff,unsigned int medialen, union nf_inet_addr *rtp_addr) { + struct nf_conntrack_expect *rtp_pair[2] = { rtp_exp, rtcp_exp };enum ip_conntrack_info ctinfo;struct nf_conn *ct =nf_ct_get (skb, &ctinfo);enum ip_conntrack_dir dir =CTINFO2DIR (ctinfo);
@@ -622,24 +623,15 @@ static unsigned int nf_nat_sdp_media(struct sk_buff *skb, unsigned int protoff,int ret; rtp_exp->tuple.dst.u.udp.port =htons (port); - ret =nf_ct_expect_related (rtp_exp, -NF_CT_EXP_F_SKIP_MASTER ); -if (ret == -EBUSY ) -continue ; -else if (ret <0 ) { - port =0 ; -break ; - } rtcp_exp->tuple.dst.u.udp.port =htons (port +1 ); - ret =nf_ct_expect_related (rtcp_exp, -NF_CT_EXP_F_SKIP_MASTER ); + + ret =nf_ct_expect_related_pair (rtp_pair, +NF_CT_EXP_F_SKIP_MASTER );if (ret ==0 )break ; -else if (ret == -EBUSY ) { -nf_ct_unexpect_related (rtp_exp); +else if (ret == -EBUSY )continue ; - }else if (ret <0 ) { -nf_ct_unexpect_related (rtp_exp); +else if (ret <0 ) { port =0 ;break ; }
Signature · 1 line
2.47.3