Commit d3f2d0a2 authored by Florian Westphal's avatar Florian Westphal Committed by Pablo Neira Ayuso

netfilter: h323: merge nat hook pointers into one

sparse complains about incorrect rcu usage.

Code uses the correct rcu access primitives, but the function pointers
lack rcu annotations.

Collapse all of them into a single structure, then annotate the pointer.
Signed-off-by: default avatarFlorian Westphal <fw@strlen.de>
Signed-off-by: default avatarPablo Neira Ayuso <pablo@netfilter.org>
parent e14575fa
...@@ -38,60 +38,63 @@ void nf_conntrack_h245_expect(struct nf_conn *new, ...@@ -38,60 +38,63 @@ void nf_conntrack_h245_expect(struct nf_conn *new,
struct nf_conntrack_expect *this); struct nf_conntrack_expect *this);
void nf_conntrack_q931_expect(struct nf_conn *new, void nf_conntrack_q931_expect(struct nf_conn *new,
struct nf_conntrack_expect *this); struct nf_conntrack_expect *this);
extern int (*set_h245_addr_hook) (struct sk_buff *skb, unsigned int protoff,
struct nfct_h323_nat_hooks {
int (*set_h245_addr)(struct sk_buff *skb, unsigned int protoff,
unsigned char **data, int dataoff, unsigned char **data, int dataoff,
H245_TransportAddress *taddr, H245_TransportAddress *taddr,
union nf_inet_addr *addr, union nf_inet_addr *addr, __be16 port);
__be16 port); int (*set_h225_addr)(struct sk_buff *skb, unsigned int protoff,
extern int (*set_h225_addr_hook) (struct sk_buff *skb, unsigned int protoff,
unsigned char **data, int dataoff, unsigned char **data, int dataoff,
TransportAddress *taddr, TransportAddress *taddr,
union nf_inet_addr *addr, union nf_inet_addr *addr, __be16 port);
__be16 port); int (*set_sig_addr)(struct sk_buff *skb,
extern int (*set_sig_addr_hook) (struct sk_buff *skb,
struct nf_conn *ct, struct nf_conn *ct,
enum ip_conntrack_info ctinfo, enum ip_conntrack_info ctinfo,
unsigned int protoff, unsigned char **data, unsigned int protoff, unsigned char **data,
TransportAddress *taddr, int count); TransportAddress *taddr, int count);
extern int (*set_ras_addr_hook) (struct sk_buff *skb, int (*set_ras_addr)(struct sk_buff *skb,
struct nf_conn *ct, struct nf_conn *ct,
enum ip_conntrack_info ctinfo, enum ip_conntrack_info ctinfo,
unsigned int protoff, unsigned char **data, unsigned int protoff, unsigned char **data,
TransportAddress *taddr, int count); TransportAddress *taddr, int count);
extern int (*nat_rtp_rtcp_hook) (struct sk_buff *skb, int (*nat_rtp_rtcp)(struct sk_buff *skb,
struct nf_conn *ct, struct nf_conn *ct,
enum ip_conntrack_info ctinfo, enum ip_conntrack_info ctinfo,
unsigned int protoff, unsigned char **data, unsigned int protoff,
int dataoff, unsigned char **data, int dataoff,
H245_TransportAddress *taddr, H245_TransportAddress *taddr,
__be16 port, __be16 rtp_port, __be16 port, __be16 rtp_port,
struct nf_conntrack_expect *rtp_exp, struct nf_conntrack_expect *rtp_exp,
struct nf_conntrack_expect *rtcp_exp); struct nf_conntrack_expect *rtcp_exp);
extern int (*nat_t120_hook) (struct sk_buff *skb, struct nf_conn *ct, int (*nat_t120)(struct sk_buff *skb,
struct nf_conn *ct,
enum ip_conntrack_info ctinfo, enum ip_conntrack_info ctinfo,
unsigned int protoff, unsigned int protoff,
unsigned char **data, int dataoff, unsigned char **data, int dataoff,
H245_TransportAddress *taddr, __be16 port, H245_TransportAddress *taddr, __be16 port,
struct nf_conntrack_expect *exp); struct nf_conntrack_expect *exp);
extern int (*nat_h245_hook) (struct sk_buff *skb, struct nf_conn *ct, int (*nat_h245)(struct sk_buff *skb,
struct nf_conn *ct,
enum ip_conntrack_info ctinfo, enum ip_conntrack_info ctinfo,
unsigned int protoff, unsigned int protoff,
unsigned char **data, int dataoff, unsigned char **data, int dataoff,
TransportAddress *taddr, __be16 port, TransportAddress *taddr, __be16 port,
struct nf_conntrack_expect *exp); struct nf_conntrack_expect *exp);
extern int (*nat_callforwarding_hook) (struct sk_buff *skb, int (*nat_callforwarding)(struct sk_buff *skb,
struct nf_conn *ct, struct nf_conn *ct,
enum ip_conntrack_info ctinfo, enum ip_conntrack_info ctinfo,
unsigned int protoff, unsigned int protoff,
unsigned char **data, int dataoff, unsigned char **data, int dataoff,
TransportAddress *taddr, TransportAddress *taddr, __be16 port,
__be16 port,
struct nf_conntrack_expect *exp); struct nf_conntrack_expect *exp);
extern int (*nat_q931_hook) (struct sk_buff *skb, struct nf_conn *ct, int (*nat_q931)(struct sk_buff *skb,
struct nf_conn *ct,
enum ip_conntrack_info ctinfo, enum ip_conntrack_info ctinfo,
unsigned int protoff, unsigned int protoff,
unsigned char **data, TransportAddress *taddr, unsigned char **data, TransportAddress *taddr, int idx,
int idx, __be16 port, __be16 port, struct nf_conntrack_expect *exp);
struct nf_conntrack_expect *exp); };
extern const struct nfct_h323_nat_hooks __rcu *nfct_h323_nat_hook;
#endif #endif
...@@ -579,28 +579,22 @@ static struct nf_ct_helper_expectfn callforwarding_nat = { ...@@ -579,28 +579,22 @@ static struct nf_ct_helper_expectfn callforwarding_nat = {
.expectfn = ip_nat_callforwarding_expect, .expectfn = ip_nat_callforwarding_expect,
}; };
static const struct nfct_h323_nat_hooks nathooks = {
.set_h245_addr = set_h245_addr,
.set_h225_addr = set_h225_addr,
.set_sig_addr = set_sig_addr,
.set_ras_addr = set_ras_addr,
.nat_rtp_rtcp = nat_rtp_rtcp,
.nat_t120 = nat_t120,
.nat_h245 = nat_h245,
.nat_callforwarding = nat_callforwarding,
.nat_q931 = nat_q931,
};
/****************************************************************************/ /****************************************************************************/
static int __init nf_nat_h323_init(void) static int __init nf_nat_h323_init(void)
{ {
BUG_ON(set_h245_addr_hook != NULL); RCU_INIT_POINTER(nfct_h323_nat_hook, &nathooks);
BUG_ON(set_h225_addr_hook != NULL);
BUG_ON(set_sig_addr_hook != NULL);
BUG_ON(set_ras_addr_hook != NULL);
BUG_ON(nat_rtp_rtcp_hook != NULL);
BUG_ON(nat_t120_hook != NULL);
BUG_ON(nat_h245_hook != NULL);
BUG_ON(nat_callforwarding_hook != NULL);
BUG_ON(nat_q931_hook != NULL);
RCU_INIT_POINTER(set_h245_addr_hook, set_h245_addr);
RCU_INIT_POINTER(set_h225_addr_hook, set_h225_addr);
RCU_INIT_POINTER(set_sig_addr_hook, set_sig_addr);
RCU_INIT_POINTER(set_ras_addr_hook, set_ras_addr);
RCU_INIT_POINTER(nat_rtp_rtcp_hook, nat_rtp_rtcp);
RCU_INIT_POINTER(nat_t120_hook, nat_t120);
RCU_INIT_POINTER(nat_h245_hook, nat_h245);
RCU_INIT_POINTER(nat_callforwarding_hook, nat_callforwarding);
RCU_INIT_POINTER(nat_q931_hook, nat_q931);
nf_ct_helper_expectfn_register(&q931_nat); nf_ct_helper_expectfn_register(&q931_nat);
nf_ct_helper_expectfn_register(&callforwarding_nat); nf_ct_helper_expectfn_register(&callforwarding_nat);
return 0; return 0;
...@@ -609,15 +603,7 @@ static int __init nf_nat_h323_init(void) ...@@ -609,15 +603,7 @@ static int __init nf_nat_h323_init(void)
/****************************************************************************/ /****************************************************************************/
static void __exit nf_nat_h323_fini(void) static void __exit nf_nat_h323_fini(void)
{ {
RCU_INIT_POINTER(set_h245_addr_hook, NULL); RCU_INIT_POINTER(nfct_h323_nat_hook, NULL);
RCU_INIT_POINTER(set_h225_addr_hook, NULL);
RCU_INIT_POINTER(set_sig_addr_hook, NULL);
RCU_INIT_POINTER(set_ras_addr_hook, NULL);
RCU_INIT_POINTER(nat_rtp_rtcp_hook, NULL);
RCU_INIT_POINTER(nat_t120_hook, NULL);
RCU_INIT_POINTER(nat_h245_hook, NULL);
RCU_INIT_POINTER(nat_callforwarding_hook, NULL);
RCU_INIT_POINTER(nat_q931_hook, NULL);
nf_ct_helper_expectfn_unregister(&q931_nat); nf_ct_helper_expectfn_unregister(&q931_nat);
nf_ct_helper_expectfn_unregister(&callforwarding_nat); nf_ct_helper_expectfn_unregister(&callforwarding_nat);
synchronize_rcu(); synchronize_rcu();
......
...@@ -49,64 +49,8 @@ MODULE_PARM_DESC(callforward_filter, "only create call forwarding expectations " ...@@ -49,64 +49,8 @@ MODULE_PARM_DESC(callforward_filter, "only create call forwarding expectations "
"if both endpoints are on different sides " "if both endpoints are on different sides "
"(determined by routing information)"); "(determined by routing information)");
/* Hooks for NAT */ const struct nfct_h323_nat_hooks __rcu *nfct_h323_nat_hook __read_mostly;
int (*set_h245_addr_hook) (struct sk_buff *skb, unsigned int protoff, EXPORT_SYMBOL_GPL(nfct_h323_nat_hook);
unsigned char **data, int dataoff,
H245_TransportAddress *taddr,
union nf_inet_addr *addr, __be16 port)
__read_mostly;
int (*set_h225_addr_hook) (struct sk_buff *skb, unsigned int protoff,
unsigned char **data, int dataoff,
TransportAddress *taddr,
union nf_inet_addr *addr, __be16 port)
__read_mostly;
int (*set_sig_addr_hook) (struct sk_buff *skb,
struct nf_conn *ct,
enum ip_conntrack_info ctinfo,
unsigned int protoff, unsigned char **data,
TransportAddress *taddr, int count) __read_mostly;
int (*set_ras_addr_hook) (struct sk_buff *skb,
struct nf_conn *ct,
enum ip_conntrack_info ctinfo,
unsigned int protoff, unsigned char **data,
TransportAddress *taddr, int count) __read_mostly;
int (*nat_rtp_rtcp_hook) (struct sk_buff *skb,
struct nf_conn *ct,
enum ip_conntrack_info ctinfo,
unsigned int protoff,
unsigned char **data, int dataoff,
H245_TransportAddress *taddr,
__be16 port, __be16 rtp_port,
struct nf_conntrack_expect *rtp_exp,
struct nf_conntrack_expect *rtcp_exp) __read_mostly;
int (*nat_t120_hook) (struct sk_buff *skb,
struct nf_conn *ct,
enum ip_conntrack_info ctinfo,
unsigned int protoff,
unsigned char **data, int dataoff,
H245_TransportAddress *taddr, __be16 port,
struct nf_conntrack_expect *exp) __read_mostly;
int (*nat_h245_hook) (struct sk_buff *skb,
struct nf_conn *ct,
enum ip_conntrack_info ctinfo,
unsigned int protoff,
unsigned char **data, int dataoff,
TransportAddress *taddr, __be16 port,
struct nf_conntrack_expect *exp) __read_mostly;
int (*nat_callforwarding_hook) (struct sk_buff *skb,
struct nf_conn *ct,
enum ip_conntrack_info ctinfo,
unsigned int protoff,
unsigned char **data, int dataoff,
TransportAddress *taddr, __be16 port,
struct nf_conntrack_expect *exp) __read_mostly;
int (*nat_q931_hook) (struct sk_buff *skb,
struct nf_conn *ct,
enum ip_conntrack_info ctinfo,
unsigned int protoff,
unsigned char **data, TransportAddress *taddr, int idx,
__be16 port, struct nf_conntrack_expect *exp)
__read_mostly;
static DEFINE_SPINLOCK(nf_h323_lock); static DEFINE_SPINLOCK(nf_h323_lock);
static char *h323_buffer; static char *h323_buffer;
...@@ -259,6 +203,7 @@ static int expect_rtp_rtcp(struct sk_buff *skb, struct nf_conn *ct, ...@@ -259,6 +203,7 @@ static int expect_rtp_rtcp(struct sk_buff *skb, struct nf_conn *ct,
unsigned char **data, int dataoff, unsigned char **data, int dataoff,
H245_TransportAddress *taddr) H245_TransportAddress *taddr)
{ {
const struct nfct_h323_nat_hooks *nathook;
int dir = CTINFO2DIR(ctinfo); int dir = CTINFO2DIR(ctinfo);
int ret = 0; int ret = 0;
__be16 port; __be16 port;
...@@ -266,7 +211,6 @@ static int expect_rtp_rtcp(struct sk_buff *skb, struct nf_conn *ct, ...@@ -266,7 +211,6 @@ static int expect_rtp_rtcp(struct sk_buff *skb, struct nf_conn *ct,
union nf_inet_addr addr; union nf_inet_addr addr;
struct nf_conntrack_expect *rtp_exp; struct nf_conntrack_expect *rtp_exp;
struct nf_conntrack_expect *rtcp_exp; struct nf_conntrack_expect *rtcp_exp;
typeof(nat_rtp_rtcp_hook) nat_rtp_rtcp;
/* Read RTP or RTCP address */ /* Read RTP or RTCP address */
if (!get_h245_addr(ct, *data, taddr, &addr, &port) || if (!get_h245_addr(ct, *data, taddr, &addr, &port) ||
...@@ -296,14 +240,15 @@ static int expect_rtp_rtcp(struct sk_buff *skb, struct nf_conn *ct, ...@@ -296,14 +240,15 @@ static int expect_rtp_rtcp(struct sk_buff *skb, struct nf_conn *ct,
&ct->tuplehash[!dir].tuple.dst.u3, &ct->tuplehash[!dir].tuple.dst.u3,
IPPROTO_UDP, NULL, &rtcp_port); IPPROTO_UDP, NULL, &rtcp_port);
nathook = rcu_dereference(nfct_h323_nat_hook);
if (memcmp(&ct->tuplehash[dir].tuple.src.u3, if (memcmp(&ct->tuplehash[dir].tuple.src.u3,
&ct->tuplehash[!dir].tuple.dst.u3, &ct->tuplehash[!dir].tuple.dst.u3,
sizeof(ct->tuplehash[dir].tuple.src.u3)) && sizeof(ct->tuplehash[dir].tuple.src.u3)) &&
(nat_rtp_rtcp = rcu_dereference(nat_rtp_rtcp_hook)) && nathook &&
nf_ct_l3num(ct) == NFPROTO_IPV4 && nf_ct_l3num(ct) == NFPROTO_IPV4 &&
ct->status & IPS_NAT_MASK) { ct->status & IPS_NAT_MASK) {
/* NAT needed */ /* NAT needed */
ret = nat_rtp_rtcp(skb, ct, ctinfo, protoff, data, dataoff, ret = nathook->nat_rtp_rtcp(skb, ct, ctinfo, protoff, data, dataoff,
taddr, port, rtp_port, rtp_exp, rtcp_exp); taddr, port, rtp_port, rtp_exp, rtcp_exp);
} else { /* Conntrack only */ } else { /* Conntrack only */
if (nf_ct_expect_related(rtp_exp, 0) == 0) { if (nf_ct_expect_related(rtp_exp, 0) == 0) {
...@@ -333,12 +278,12 @@ static int expect_t120(struct sk_buff *skb, ...@@ -333,12 +278,12 @@ static int expect_t120(struct sk_buff *skb,
unsigned char **data, int dataoff, unsigned char **data, int dataoff,
H245_TransportAddress *taddr) H245_TransportAddress *taddr)
{ {
const struct nfct_h323_nat_hooks *nathook;
int dir = CTINFO2DIR(ctinfo); int dir = CTINFO2DIR(ctinfo);
int ret = 0; int ret = 0;
__be16 port; __be16 port;
union nf_inet_addr addr; union nf_inet_addr addr;
struct nf_conntrack_expect *exp; struct nf_conntrack_expect *exp;
typeof(nat_t120_hook) nat_t120;
/* Read T.120 address */ /* Read T.120 address */
if (!get_h245_addr(ct, *data, taddr, &addr, &port) || if (!get_h245_addr(ct, *data, taddr, &addr, &port) ||
...@@ -355,15 +300,16 @@ static int expect_t120(struct sk_buff *skb, ...@@ -355,15 +300,16 @@ static int expect_t120(struct sk_buff *skb,
IPPROTO_TCP, NULL, &port); IPPROTO_TCP, NULL, &port);
exp->flags = NF_CT_EXPECT_PERMANENT; /* Accept multiple channels */ exp->flags = NF_CT_EXPECT_PERMANENT; /* Accept multiple channels */
nathook = rcu_dereference(nfct_h323_nat_hook);
if (memcmp(&ct->tuplehash[dir].tuple.src.u3, if (memcmp(&ct->tuplehash[dir].tuple.src.u3,
&ct->tuplehash[!dir].tuple.dst.u3, &ct->tuplehash[!dir].tuple.dst.u3,
sizeof(ct->tuplehash[dir].tuple.src.u3)) && sizeof(ct->tuplehash[dir].tuple.src.u3)) &&
(nat_t120 = rcu_dereference(nat_t120_hook)) && nathook &&
nf_ct_l3num(ct) == NFPROTO_IPV4 && nf_ct_l3num(ct) == NFPROTO_IPV4 &&
ct->status & IPS_NAT_MASK) { ct->status & IPS_NAT_MASK) {
/* NAT needed */ /* NAT needed */
ret = nat_t120(skb, ct, ctinfo, protoff, data, dataoff, taddr, ret = nathook->nat_t120(skb, ct, ctinfo, protoff, data,
port, exp); dataoff, taddr, port, exp);
} else { /* Conntrack only */ } else { /* Conntrack only */
if (nf_ct_expect_related(exp, 0) == 0) { if (nf_ct_expect_related(exp, 0) == 0) {
pr_debug("nf_ct_h323: expect T.120 "); pr_debug("nf_ct_h323: expect T.120 ");
...@@ -664,18 +610,19 @@ int get_h225_addr(struct nf_conn *ct, unsigned char *data, ...@@ -664,18 +610,19 @@ int get_h225_addr(struct nf_conn *ct, unsigned char *data,
return 1; return 1;
} }
EXPORT_SYMBOL_GPL(get_h225_addr);
static int expect_h245(struct sk_buff *skb, struct nf_conn *ct, static int expect_h245(struct sk_buff *skb, struct nf_conn *ct,
enum ip_conntrack_info ctinfo, enum ip_conntrack_info ctinfo,
unsigned int protoff, unsigned char **data, int dataoff, unsigned int protoff, unsigned char **data, int dataoff,
TransportAddress *taddr) TransportAddress *taddr)
{ {
const struct nfct_h323_nat_hooks *nathook;
int dir = CTINFO2DIR(ctinfo); int dir = CTINFO2DIR(ctinfo);
int ret = 0; int ret = 0;
__be16 port; __be16 port;
union nf_inet_addr addr; union nf_inet_addr addr;
struct nf_conntrack_expect *exp; struct nf_conntrack_expect *exp;
typeof(nat_h245_hook) nat_h245;
/* Read h245Address */ /* Read h245Address */
if (!get_h225_addr(ct, *data, taddr, &addr, &port) || if (!get_h225_addr(ct, *data, taddr, &addr, &port) ||
...@@ -692,15 +639,16 @@ static int expect_h245(struct sk_buff *skb, struct nf_conn *ct, ...@@ -692,15 +639,16 @@ static int expect_h245(struct sk_buff *skb, struct nf_conn *ct,
IPPROTO_TCP, NULL, &port); IPPROTO_TCP, NULL, &port);
exp->helper = &nf_conntrack_helper_h245; exp->helper = &nf_conntrack_helper_h245;
nathook = rcu_dereference(nfct_h323_nat_hook);
if (memcmp(&ct->tuplehash[dir].tuple.src.u3, if (memcmp(&ct->tuplehash[dir].tuple.src.u3,
&ct->tuplehash[!dir].tuple.dst.u3, &ct->tuplehash[!dir].tuple.dst.u3,
sizeof(ct->tuplehash[dir].tuple.src.u3)) && sizeof(ct->tuplehash[dir].tuple.src.u3)) &&
(nat_h245 = rcu_dereference(nat_h245_hook)) && nathook &&
nf_ct_l3num(ct) == NFPROTO_IPV4 && nf_ct_l3num(ct) == NFPROTO_IPV4 &&
ct->status & IPS_NAT_MASK) { ct->status & IPS_NAT_MASK) {
/* NAT needed */ /* NAT needed */
ret = nat_h245(skb, ct, ctinfo, protoff, data, dataoff, taddr, ret = nathook->nat_h245(skb, ct, ctinfo, protoff, data,
port, exp); dataoff, taddr, port, exp);
} else { /* Conntrack only */ } else { /* Conntrack only */
if (nf_ct_expect_related(exp, 0) == 0) { if (nf_ct_expect_related(exp, 0) == 0) {
pr_debug("nf_ct_q931: expect H.245 "); pr_debug("nf_ct_q931: expect H.245 ");
...@@ -785,13 +733,13 @@ static int expect_callforwarding(struct sk_buff *skb, ...@@ -785,13 +733,13 @@ static int expect_callforwarding(struct sk_buff *skb,
unsigned char **data, int dataoff, unsigned char **data, int dataoff,
TransportAddress *taddr) TransportAddress *taddr)
{ {
const struct nfct_h323_nat_hooks *nathook;
int dir = CTINFO2DIR(ctinfo); int dir = CTINFO2DIR(ctinfo);
int ret = 0; int ret = 0;
__be16 port; __be16 port;
union nf_inet_addr addr; union nf_inet_addr addr;
struct nf_conntrack_expect *exp; struct nf_conntrack_expect *exp;
struct net *net = nf_ct_net(ct); struct net *net = nf_ct_net(ct);
typeof(nat_callforwarding_hook) nat_callforwarding;
/* Read alternativeAddress */ /* Read alternativeAddress */
if (!get_h225_addr(ct, *data, taddr, &addr, &port) || port == 0) if (!get_h225_addr(ct, *data, taddr, &addr, &port) || port == 0)
...@@ -815,14 +763,15 @@ static int expect_callforwarding(struct sk_buff *skb, ...@@ -815,14 +763,15 @@ static int expect_callforwarding(struct sk_buff *skb,
IPPROTO_TCP, NULL, &port); IPPROTO_TCP, NULL, &port);
exp->helper = nf_conntrack_helper_q931; exp->helper = nf_conntrack_helper_q931;
nathook = rcu_dereference(nfct_h323_nat_hook);
if (memcmp(&ct->tuplehash[dir].tuple.src.u3, if (memcmp(&ct->tuplehash[dir].tuple.src.u3,
&ct->tuplehash[!dir].tuple.dst.u3, &ct->tuplehash[!dir].tuple.dst.u3,
sizeof(ct->tuplehash[dir].tuple.src.u3)) && sizeof(ct->tuplehash[dir].tuple.src.u3)) &&
(nat_callforwarding = rcu_dereference(nat_callforwarding_hook)) && nathook &&
nf_ct_l3num(ct) == NFPROTO_IPV4 && nf_ct_l3num(ct) == NFPROTO_IPV4 &&
ct->status & IPS_NAT_MASK) { ct->status & IPS_NAT_MASK) {
/* Need NAT */ /* Need NAT */
ret = nat_callforwarding(skb, ct, ctinfo, ret = nathook->nat_callforwarding(skb, ct, ctinfo,
protoff, data, dataoff, protoff, data, dataoff,
taddr, port, exp); taddr, port, exp);
} else { /* Conntrack only */ } else { /* Conntrack only */
...@@ -844,12 +793,12 @@ static int process_setup(struct sk_buff *skb, struct nf_conn *ct, ...@@ -844,12 +793,12 @@ static int process_setup(struct sk_buff *skb, struct nf_conn *ct,
unsigned char **data, int dataoff, unsigned char **data, int dataoff,
Setup_UUIE *setup) Setup_UUIE *setup)
{ {
const struct nfct_h323_nat_hooks *nathook;
int dir = CTINFO2DIR(ctinfo); int dir = CTINFO2DIR(ctinfo);
int ret; int ret;
int i; int i;
__be16 port; __be16 port;
union nf_inet_addr addr; union nf_inet_addr addr;
typeof(set_h225_addr_hook) set_h225_addr;
pr_debug("nf_ct_q931: Setup\n"); pr_debug("nf_ct_q931: Setup\n");
...@@ -860,9 +809,9 @@ static int process_setup(struct sk_buff *skb, struct nf_conn *ct, ...@@ -860,9 +809,9 @@ static int process_setup(struct sk_buff *skb, struct nf_conn *ct,
return -1; return -1;
} }
set_h225_addr = rcu_dereference(set_h225_addr_hook); nathook = rcu_dereference(nfct_h323_nat_hook);
if ((setup->options & eSetup_UUIE_destCallSignalAddress) && if ((setup->options & eSetup_UUIE_destCallSignalAddress) &&
(set_h225_addr) && nf_ct_l3num(ct) == NFPROTO_IPV4 && nathook && nf_ct_l3num(ct) == NFPROTO_IPV4 &&
ct->status & IPS_NAT_MASK && ct->status & IPS_NAT_MASK &&
get_h225_addr(ct, *data, &setup->destCallSignalAddress, get_h225_addr(ct, *data, &setup->destCallSignalAddress,
&addr, &port) && &addr, &port) &&
...@@ -870,7 +819,7 @@ static int process_setup(struct sk_buff *skb, struct nf_conn *ct, ...@@ -870,7 +819,7 @@ static int process_setup(struct sk_buff *skb, struct nf_conn *ct,
pr_debug("nf_ct_q931: set destCallSignalAddress %pI6:%hu->%pI6:%hu\n", pr_debug("nf_ct_q931: set destCallSignalAddress %pI6:%hu->%pI6:%hu\n",
&addr, ntohs(port), &ct->tuplehash[!dir].tuple.src.u3, &addr, ntohs(port), &ct->tuplehash[!dir].tuple.src.u3,
ntohs(ct->tuplehash[!dir].tuple.src.u.tcp.port)); ntohs(ct->tuplehash[!dir].tuple.src.u.tcp.port));
ret = set_h225_addr(skb, protoff, data, dataoff, ret = nathook->set_h225_addr(skb, protoff, data, dataoff,
&setup->destCallSignalAddress, &setup->destCallSignalAddress,
&ct->tuplehash[!dir].tuple.src.u3, &ct->tuplehash[!dir].tuple.src.u3,
ct->tuplehash[!dir].tuple.src.u.tcp.port); ct->tuplehash[!dir].tuple.src.u.tcp.port);
...@@ -879,7 +828,7 @@ static int process_setup(struct sk_buff *skb, struct nf_conn *ct, ...@@ -879,7 +828,7 @@ static int process_setup(struct sk_buff *skb, struct nf_conn *ct,
} }
if ((setup->options & eSetup_UUIE_sourceCallSignalAddress) && if ((setup->options & eSetup_UUIE_sourceCallSignalAddress) &&
(set_h225_addr) && nf_ct_l3num(ct) == NFPROTO_IPV4 && nathook && nf_ct_l3num(ct) == NFPROTO_IPV4 &&
ct->status & IPS_NAT_MASK && ct->status & IPS_NAT_MASK &&
get_h225_addr(ct, *data, &setup->sourceCallSignalAddress, get_h225_addr(ct, *data, &setup->sourceCallSignalAddress,
&addr, &port) && &addr, &port) &&
...@@ -887,7 +836,7 @@ static int process_setup(struct sk_buff *skb, struct nf_conn *ct, ...@@ -887,7 +836,7 @@ static int process_setup(struct sk_buff *skb, struct nf_conn *ct,
pr_debug("nf_ct_q931: set sourceCallSignalAddress %pI6:%hu->%pI6:%hu\n", pr_debug("nf_ct_q931: set sourceCallSignalAddress %pI6:%hu->%pI6:%hu\n",
&addr, ntohs(port), &ct->tuplehash[!dir].tuple.dst.u3, &addr, ntohs(port), &ct->tuplehash[!dir].tuple.dst.u3,
ntohs(ct->tuplehash[!dir].tuple.dst.u.tcp.port)); ntohs(ct->tuplehash[!dir].tuple.dst.u.tcp.port));
ret = set_h225_addr(skb, protoff, data, dataoff, ret = nathook->set_h225_addr(skb, protoff, data, dataoff,
&setup->sourceCallSignalAddress, &setup->sourceCallSignalAddress,
&ct->tuplehash[!dir].tuple.dst.u3, &ct->tuplehash[!dir].tuple.dst.u3,
ct->tuplehash[!dir].tuple.dst.u.tcp.port); ct->tuplehash[!dir].tuple.dst.u.tcp.port);
...@@ -1249,13 +1198,13 @@ static int expect_q931(struct sk_buff *skb, struct nf_conn *ct, ...@@ -1249,13 +1198,13 @@ static int expect_q931(struct sk_buff *skb, struct nf_conn *ct,
TransportAddress *taddr, int count) TransportAddress *taddr, int count)
{ {
struct nf_ct_h323_master *info = nfct_help_data(ct); struct nf_ct_h323_master *info = nfct_help_data(ct);
const struct nfct_h323_nat_hooks *nathook;
int dir = CTINFO2DIR(ctinfo); int dir = CTINFO2DIR(ctinfo);
int ret = 0; int ret = 0;
int i; int i;
__be16 port; __be16 port;
union nf_inet_addr addr; union nf_inet_addr addr;
struct nf_conntrack_expect *exp; struct nf_conntrack_expect *exp;
typeof(nat_q931_hook) nat_q931;
/* Look for the first related address */ /* Look for the first related address */
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
...@@ -1279,10 +1228,10 @@ static int expect_q931(struct sk_buff *skb, struct nf_conn *ct, ...@@ -1279,10 +1228,10 @@ static int expect_q931(struct sk_buff *skb, struct nf_conn *ct,
exp->helper = nf_conntrack_helper_q931; exp->helper = nf_conntrack_helper_q931;
exp->flags = NF_CT_EXPECT_PERMANENT; /* Accept multiple calls */ exp->flags = NF_CT_EXPECT_PERMANENT; /* Accept multiple calls */
nat_q931 = rcu_dereference(nat_q931_hook); nathook = rcu_dereference(nfct_h323_nat_hook);
if (nat_q931 && nf_ct_l3num(ct) == NFPROTO_IPV4 && if (nathook && nf_ct_l3num(ct) == NFPROTO_IPV4 &&
ct->status & IPS_NAT_MASK) { /* Need NAT */ ct->status & IPS_NAT_MASK) { /* Need NAT */
ret = nat_q931(skb, ct, ctinfo, protoff, data, ret = nathook->nat_q931(skb, ct, ctinfo, protoff, data,
taddr, i, port, exp); taddr, i, port, exp);
} else { /* Conntrack only */ } else { /* Conntrack only */
if (nf_ct_expect_related(exp, 0) == 0) { if (nf_ct_expect_related(exp, 0) == 0) {
...@@ -1305,14 +1254,14 @@ static int process_grq(struct sk_buff *skb, struct nf_conn *ct, ...@@ -1305,14 +1254,14 @@ static int process_grq(struct sk_buff *skb, struct nf_conn *ct,
unsigned int protoff, unsigned int protoff,
unsigned char **data, GatekeeperRequest *grq) unsigned char **data, GatekeeperRequest *grq)
{ {
typeof(set_ras_addr_hook) set_ras_addr; const struct nfct_h323_nat_hooks *nathook;
pr_debug("nf_ct_ras: GRQ\n"); pr_debug("nf_ct_ras: GRQ\n");
set_ras_addr = rcu_dereference(set_ras_addr_hook); nathook = rcu_dereference(nfct_h323_nat_hook);
if (set_ras_addr && nf_ct_l3num(ct) == NFPROTO_IPV4 && if (nathook && nf_ct_l3num(ct) == NFPROTO_IPV4 &&
ct->status & IPS_NAT_MASK) /* NATed */ ct->status & IPS_NAT_MASK) /* NATed */
return set_ras_addr(skb, ct, ctinfo, protoff, data, return nathook->set_ras_addr(skb, ct, ctinfo, protoff, data,
&grq->rasAddress, 1); &grq->rasAddress, 1);
return 0; return 0;
} }
...@@ -1367,8 +1316,8 @@ static int process_rrq(struct sk_buff *skb, struct nf_conn *ct, ...@@ -1367,8 +1316,8 @@ static int process_rrq(struct sk_buff *skb, struct nf_conn *ct,
unsigned char **data, RegistrationRequest *rrq) unsigned char **data, RegistrationRequest *rrq)
{ {
struct nf_ct_h323_master *info = nfct_help_data(ct); struct nf_ct_h323_master *info = nfct_help_data(ct);
const struct nfct_h323_nat_hooks *nathook;
int ret; int ret;
typeof(set_ras_addr_hook) set_ras_addr;
pr_debug("nf_ct_ras: RRQ\n"); pr_debug("nf_ct_ras: RRQ\n");
...@@ -1378,10 +1327,10 @@ static int process_rrq(struct sk_buff *skb, struct nf_conn *ct, ...@@ -1378,10 +1327,10 @@ static int process_rrq(struct sk_buff *skb, struct nf_conn *ct,
if (ret < 0) if (ret < 0)
return -1; return -1;
set_ras_addr = rcu_dereference(set_ras_addr_hook); nathook = rcu_dereference(nfct_h323_nat_hook);
if (set_ras_addr && nf_ct_l3num(ct) == NFPROTO_IPV4 && if (nathook && nf_ct_l3num(ct) == NFPROTO_IPV4 &&
ct->status & IPS_NAT_MASK) { ct->status & IPS_NAT_MASK) {
ret = set_ras_addr(skb, ct, ctinfo, protoff, data, ret = nathook->set_ras_addr(skb, ct, ctinfo, protoff, data,
rrq->rasAddress.item, rrq->rasAddress.item,
rrq->rasAddress.count); rrq->rasAddress.count);
if (ret < 0) if (ret < 0)
...@@ -1403,17 +1352,17 @@ static int process_rcf(struct sk_buff *skb, struct nf_conn *ct, ...@@ -1403,17 +1352,17 @@ static int process_rcf(struct sk_buff *skb, struct nf_conn *ct,
unsigned char **data, RegistrationConfirm *rcf) unsigned char **data, RegistrationConfirm *rcf)
{ {
struct nf_ct_h323_master *info = nfct_help_data(ct); struct nf_ct_h323_master *info = nfct_help_data(ct);
const struct nfct_h323_nat_hooks *nathook;
int dir = CTINFO2DIR(ctinfo); int dir = CTINFO2DIR(ctinfo);
int ret; int ret;
struct nf_conntrack_expect *exp; struct nf_conntrack_expect *exp;
typeof(set_sig_addr_hook) set_sig_addr;
pr_debug("nf_ct_ras: RCF\n"); pr_debug("nf_ct_ras: RCF\n");
set_sig_addr = rcu_dereference(set_sig_addr_hook); nathook = rcu_dereference(nfct_h323_nat_hook);
if (set_sig_addr && nf_ct_l3num(ct) == NFPROTO_IPV4 && if (nathook && nf_ct_l3num(ct) == NFPROTO_IPV4 &&
ct->status & IPS_NAT_MASK) { ct->status & IPS_NAT_MASK) {
ret = set_sig_addr(skb, ct, ctinfo, protoff, data, ret = nathook->set_sig_addr(skb, ct, ctinfo, protoff, data,
rcf->callSignalAddress.item, rcf->callSignalAddress.item,
rcf->callSignalAddress.count); rcf->callSignalAddress.count);
if (ret < 0) if (ret < 0)
...@@ -1454,16 +1403,16 @@ static int process_urq(struct sk_buff *skb, struct nf_conn *ct, ...@@ -1454,16 +1403,16 @@ static int process_urq(struct sk_buff *skb, struct nf_conn *ct,
unsigned char **data, UnregistrationRequest *urq) unsigned char **data, UnregistrationRequest *urq)
{ {
struct nf_ct_h323_master *info = nfct_help_data(ct); struct nf_ct_h323_master *info = nfct_help_data(ct);
const struct nfct_h323_nat_hooks *nathook;
int dir = CTINFO2DIR(ctinfo); int dir = CTINFO2DIR(ctinfo);
int ret; int ret;
typeof(set_sig_addr_hook) set_sig_addr;
pr_debug("nf_ct_ras: URQ\n"); pr_debug("nf_ct_ras: URQ\n");
set_sig_addr = rcu_dereference(set_sig_addr_hook); nathook = rcu_dereference(nfct_h323_nat_hook);
if (set_sig_addr && nf_ct_l3num(ct) == NFPROTO_IPV4 && if (nathook && nf_ct_l3num(ct) == NFPROTO_IPV4 &&
ct->status & IPS_NAT_MASK) { ct->status & IPS_NAT_MASK) {
ret = set_sig_addr(skb, ct, ctinfo, protoff, data, ret = nathook->set_sig_addr(skb, ct, ctinfo, protoff, data,
urq->callSignalAddress.item, urq->callSignalAddress.item,
urq->callSignalAddress.count); urq->callSignalAddress.count);
if (ret < 0) if (ret < 0)
...@@ -1487,23 +1436,26 @@ static int process_arq(struct sk_buff *skb, struct nf_conn *ct, ...@@ -1487,23 +1436,26 @@ static int process_arq(struct sk_buff *skb, struct nf_conn *ct,
unsigned char **data, AdmissionRequest *arq) unsigned char **data, AdmissionRequest *arq)
{ {
const struct nf_ct_h323_master *info = nfct_help_data(ct); const struct nf_ct_h323_master *info = nfct_help_data(ct);
const struct nfct_h323_nat_hooks *nathook;
int dir = CTINFO2DIR(ctinfo); int dir = CTINFO2DIR(ctinfo);
__be16 port; __be16 port;
union nf_inet_addr addr; union nf_inet_addr addr;
typeof(set_h225_addr_hook) set_h225_addr;
pr_debug("nf_ct_ras: ARQ\n"); pr_debug("nf_ct_ras: ARQ\n");
set_h225_addr = rcu_dereference(set_h225_addr_hook); nathook = rcu_dereference(nfct_h323_nat_hook);
if (!nathook)
return 0;
if ((arq->options & eAdmissionRequest_destCallSignalAddress) && if ((arq->options & eAdmissionRequest_destCallSignalAddress) &&
get_h225_addr(ct, *data, &arq->destCallSignalAddress, get_h225_addr(ct, *data, &arq->destCallSignalAddress,
&addr, &port) && &addr, &port) &&
!memcmp(&addr, &ct->tuplehash[dir].tuple.src.u3, sizeof(addr)) && !memcmp(&addr, &ct->tuplehash[dir].tuple.src.u3, sizeof(addr)) &&
port == info->sig_port[dir] && port == info->sig_port[dir] &&
nf_ct_l3num(ct) == NFPROTO_IPV4 && nf_ct_l3num(ct) == NFPROTO_IPV4 &&
set_h225_addr && ct->status & IPS_NAT_MASK) { ct->status & IPS_NAT_MASK) {
/* Answering ARQ */ /* Answering ARQ */
return set_h225_addr(skb, protoff, data, 0, return nathook->set_h225_addr(skb, protoff, data, 0,
&arq->destCallSignalAddress, &arq->destCallSignalAddress,
&ct->tuplehash[!dir].tuple.dst.u3, &ct->tuplehash[!dir].tuple.dst.u3,
info->sig_port[!dir]); info->sig_port[!dir]);
...@@ -1513,10 +1465,10 @@ static int process_arq(struct sk_buff *skb, struct nf_conn *ct, ...@@ -1513,10 +1465,10 @@ static int process_arq(struct sk_buff *skb, struct nf_conn *ct,
get_h225_addr(ct, *data, &arq->srcCallSignalAddress, get_h225_addr(ct, *data, &arq->srcCallSignalAddress,
&addr, &port) && &addr, &port) &&
!memcmp(&addr, &ct->tuplehash[dir].tuple.src.u3, sizeof(addr)) && !memcmp(&addr, &ct->tuplehash[dir].tuple.src.u3, sizeof(addr)) &&
set_h225_addr && nf_ct_l3num(ct) == NFPROTO_IPV4 && nf_ct_l3num(ct) == NFPROTO_IPV4 &&
ct->status & IPS_NAT_MASK) { ct->status & IPS_NAT_MASK) {
/* Calling ARQ */ /* Calling ARQ */
return set_h225_addr(skb, protoff, data, 0, return nathook->set_h225_addr(skb, protoff, data, 0,
&arq->srcCallSignalAddress, &arq->srcCallSignalAddress,
&ct->tuplehash[!dir].tuple.dst.u3, &ct->tuplehash[!dir].tuple.dst.u3,
port); port);
...@@ -1535,7 +1487,6 @@ static int process_acf(struct sk_buff *skb, struct nf_conn *ct, ...@@ -1535,7 +1487,6 @@ static int process_acf(struct sk_buff *skb, struct nf_conn *ct,
__be16 port; __be16 port;
union nf_inet_addr addr; union nf_inet_addr addr;
struct nf_conntrack_expect *exp; struct nf_conntrack_expect *exp;
typeof(set_sig_addr_hook) set_sig_addr;
pr_debug("nf_ct_ras: ACF\n"); pr_debug("nf_ct_ras: ACF\n");
...@@ -1544,11 +1495,14 @@ static int process_acf(struct sk_buff *skb, struct nf_conn *ct, ...@@ -1544,11 +1495,14 @@ static int process_acf(struct sk_buff *skb, struct nf_conn *ct,
return 0; return 0;
if (!memcmp(&addr, &ct->tuplehash[dir].tuple.dst.u3, sizeof(addr))) { if (!memcmp(&addr, &ct->tuplehash[dir].tuple.dst.u3, sizeof(addr))) {
const struct nfct_h323_nat_hooks *nathook;
/* Answering ACF */ /* Answering ACF */
set_sig_addr = rcu_dereference(set_sig_addr_hook); nathook = rcu_dereference(nfct_h323_nat_hook);
if (set_sig_addr && nf_ct_l3num(ct) == NFPROTO_IPV4 && if (nathook && nf_ct_l3num(ct) == NFPROTO_IPV4 &&
ct->status & IPS_NAT_MASK) ct->status & IPS_NAT_MASK)
return set_sig_addr(skb, ct, ctinfo, protoff, data, return nathook->set_sig_addr(skb, ct, ctinfo, protoff,
data,
&acf->destCallSignalAddress, 1); &acf->destCallSignalAddress, 1);
return 0; return 0;
} }
...@@ -1578,14 +1532,14 @@ static int process_lrq(struct sk_buff *skb, struct nf_conn *ct, ...@@ -1578,14 +1532,14 @@ static int process_lrq(struct sk_buff *skb, struct nf_conn *ct,
unsigned int protoff, unsigned int protoff,
unsigned char **data, LocationRequest *lrq) unsigned char **data, LocationRequest *lrq)
{ {
typeof(set_ras_addr_hook) set_ras_addr; const struct nfct_h323_nat_hooks *nathook;
pr_debug("nf_ct_ras: LRQ\n"); pr_debug("nf_ct_ras: LRQ\n");
set_ras_addr = rcu_dereference(set_ras_addr_hook); nathook = rcu_dereference(nfct_h323_nat_hook);
if (set_ras_addr && nf_ct_l3num(ct) == NFPROTO_IPV4 && if (nathook && nf_ct_l3num(ct) == NFPROTO_IPV4 &&
ct->status & IPS_NAT_MASK) ct->status & IPS_NAT_MASK)
return set_ras_addr(skb, ct, ctinfo, protoff, data, return nathook->set_ras_addr(skb, ct, ctinfo, protoff, data,
&lrq->replyAddress, 1); &lrq->replyAddress, 1);
return 0; return 0;
} }
...@@ -1634,25 +1588,20 @@ static int process_irr(struct sk_buff *skb, struct nf_conn *ct, ...@@ -1634,25 +1588,20 @@ static int process_irr(struct sk_buff *skb, struct nf_conn *ct,
unsigned int protoff, unsigned int protoff,
unsigned char **data, InfoRequestResponse *irr) unsigned char **data, InfoRequestResponse *irr)
{ {
const struct nfct_h323_nat_hooks *nathook;
int ret; int ret;
typeof(set_ras_addr_hook) set_ras_addr;
typeof(set_sig_addr_hook) set_sig_addr;
pr_debug("nf_ct_ras: IRR\n"); pr_debug("nf_ct_ras: IRR\n");
set_ras_addr = rcu_dereference(set_ras_addr_hook); nathook = rcu_dereference(nfct_h323_nat_hook);
if (set_ras_addr && nf_ct_l3num(ct) == NFPROTO_IPV4 && if (nathook && nf_ct_l3num(ct) == NFPROTO_IPV4 &&
ct->status & IPS_NAT_MASK) { ct->status & IPS_NAT_MASK) {
ret = set_ras_addr(skb, ct, ctinfo, protoff, data, ret = nathook->set_ras_addr(skb, ct, ctinfo, protoff, data,
&irr->rasAddress, 1); &irr->rasAddress, 1);
if (ret < 0) if (ret < 0)
return -1; return -1;
}
set_sig_addr = rcu_dereference(set_sig_addr_hook); ret = nathook->set_sig_addr(skb, ct, ctinfo, protoff, data,
if (set_sig_addr && nf_ct_l3num(ct) == NFPROTO_IPV4 &&
ct->status & IPS_NAT_MASK) {
ret = set_sig_addr(skb, ct, ctinfo, protoff, data,
irr->callSignalAddress.item, irr->callSignalAddress.item,
irr->callSignalAddress.count); irr->callSignalAddress.count);
if (ret < 0) if (ret < 0)
...@@ -1837,17 +1786,6 @@ static int __init nf_conntrack_h323_init(void) ...@@ -1837,17 +1786,6 @@ static int __init nf_conntrack_h323_init(void)
module_init(nf_conntrack_h323_init); module_init(nf_conntrack_h323_init);
module_exit(nf_conntrack_h323_fini); module_exit(nf_conntrack_h323_fini);
EXPORT_SYMBOL_GPL(get_h225_addr);
EXPORT_SYMBOL_GPL(set_h245_addr_hook);
EXPORT_SYMBOL_GPL(set_h225_addr_hook);
EXPORT_SYMBOL_GPL(set_sig_addr_hook);
EXPORT_SYMBOL_GPL(set_ras_addr_hook);
EXPORT_SYMBOL_GPL(nat_rtp_rtcp_hook);
EXPORT_SYMBOL_GPL(nat_t120_hook);
EXPORT_SYMBOL_GPL(nat_h245_hook);
EXPORT_SYMBOL_GPL(nat_callforwarding_hook);
EXPORT_SYMBOL_GPL(nat_q931_hook);
MODULE_AUTHOR("Jing Min Zhao <zhaojingmin@users.sourceforge.net>"); MODULE_AUTHOR("Jing Min Zhao <zhaojingmin@users.sourceforge.net>");
MODULE_DESCRIPTION("H.323 connection tracking helper"); MODULE_DESCRIPTION("H.323 connection tracking helper");
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment