Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1 | /* |
| 2 | * H.323 connection tracking helper |
| 3 | * |
| 4 | * Copyright (c) 2006 Jing Min Zhao <zhaojingmin@users.sourceforge.net> |
| 5 | * |
| 6 | * This source code is licensed under General Public License version 2. |
| 7 | * |
| 8 | * Based on the 'brute force' H.323 connection tracking module by |
| 9 | * Jozsef Kadlecsik <kadlec@blackhole.kfki.hu> |
| 10 | * |
| 11 | * For more information, please see http://nath323.sourceforge.net/ |
| 12 | */ |
| 13 | |
| 14 | #include <linux/module.h> |
| 15 | #include <linux/moduleparam.h> |
| 16 | #include <linux/ctype.h> |
| 17 | #include <linux/inet.h> |
| 18 | #include <linux/in.h> |
| 19 | #include <linux/ip.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 20 | #include <linux/slab.h> |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 21 | #include <linux/udp.h> |
| 22 | #include <linux/tcp.h> |
| 23 | #include <linux/skbuff.h> |
| 24 | #include <net/route.h> |
| 25 | #include <net/ip6_route.h> |
| 26 | |
| 27 | #include <net/netfilter/nf_conntrack.h> |
| 28 | #include <net/netfilter/nf_conntrack_core.h> |
| 29 | #include <net/netfilter/nf_conntrack_tuple.h> |
| 30 | #include <net/netfilter/nf_conntrack_expect.h> |
| 31 | #include <net/netfilter/nf_conntrack_ecache.h> |
| 32 | #include <net/netfilter/nf_conntrack_helper.h> |
Patrick McHardy | 5d0aa2c | 2010-02-15 18:13:33 +0100 | [diff] [blame] | 33 | #include <net/netfilter/nf_conntrack_zones.h> |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 34 | #include <linux/netfilter/nf_conntrack_h323.h> |
| 35 | |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 36 | /* Parameters */ |
| 37 | static unsigned int default_rrq_ttl __read_mostly = 300; |
| 38 | module_param(default_rrq_ttl, uint, 0600); |
| 39 | MODULE_PARM_DESC(default_rrq_ttl, "use this TTL if it's missing in RRQ"); |
| 40 | |
| 41 | static int gkrouted_only __read_mostly = 1; |
| 42 | module_param(gkrouted_only, int, 0600); |
| 43 | MODULE_PARM_DESC(gkrouted_only, "only accept calls from gatekeeper"); |
| 44 | |
| 45 | static int callforward_filter __read_mostly = 1; |
| 46 | module_param(callforward_filter, bool, 0600); |
| 47 | MODULE_PARM_DESC(callforward_filter, "only create call forwarding expectations " |
YOSHIFUJI Hideaki | 601e68e | 2007-02-12 11:15:49 -0800 | [diff] [blame] | 48 | "if both endpoints are on different sides " |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 49 | "(determined by routing information)"); |
| 50 | |
| 51 | /* Hooks for NAT */ |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 52 | int (*set_h245_addr_hook) (struct sk_buff *skb, |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 53 | unsigned char **data, int dataoff, |
| 54 | H245_TransportAddress *taddr, |
Jan Engelhardt | 643a2c1 | 2007-12-17 22:43:50 -0800 | [diff] [blame] | 55 | union nf_inet_addr *addr, __be16 port) |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 56 | __read_mostly; |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 57 | int (*set_h225_addr_hook) (struct sk_buff *skb, |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 58 | unsigned char **data, int dataoff, |
| 59 | TransportAddress *taddr, |
Jan Engelhardt | 643a2c1 | 2007-12-17 22:43:50 -0800 | [diff] [blame] | 60 | union nf_inet_addr *addr, __be16 port) |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 61 | __read_mostly; |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 62 | int (*set_sig_addr_hook) (struct sk_buff *skb, |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 63 | struct nf_conn *ct, |
| 64 | enum ip_conntrack_info ctinfo, |
| 65 | unsigned char **data, |
| 66 | TransportAddress *taddr, int count) __read_mostly; |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 67 | int (*set_ras_addr_hook) (struct sk_buff *skb, |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 68 | struct nf_conn *ct, |
| 69 | enum ip_conntrack_info ctinfo, |
| 70 | unsigned char **data, |
| 71 | TransportAddress *taddr, int count) __read_mostly; |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 72 | int (*nat_rtp_rtcp_hook) (struct sk_buff *skb, |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 73 | struct nf_conn *ct, |
| 74 | enum ip_conntrack_info ctinfo, |
| 75 | unsigned char **data, int dataoff, |
| 76 | H245_TransportAddress *taddr, |
| 77 | __be16 port, __be16 rtp_port, |
| 78 | struct nf_conntrack_expect *rtp_exp, |
| 79 | struct nf_conntrack_expect *rtcp_exp) __read_mostly; |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 80 | int (*nat_t120_hook) (struct sk_buff *skb, |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 81 | struct nf_conn *ct, |
| 82 | enum ip_conntrack_info ctinfo, |
| 83 | unsigned char **data, int dataoff, |
| 84 | H245_TransportAddress *taddr, __be16 port, |
| 85 | struct nf_conntrack_expect *exp) __read_mostly; |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 86 | int (*nat_h245_hook) (struct sk_buff *skb, |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 87 | struct nf_conn *ct, |
| 88 | enum ip_conntrack_info ctinfo, |
| 89 | unsigned char **data, int dataoff, |
| 90 | TransportAddress *taddr, __be16 port, |
| 91 | struct nf_conntrack_expect *exp) __read_mostly; |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 92 | int (*nat_callforwarding_hook) (struct sk_buff *skb, |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 93 | struct nf_conn *ct, |
| 94 | enum ip_conntrack_info ctinfo, |
| 95 | unsigned char **data, int dataoff, |
| 96 | TransportAddress *taddr, __be16 port, |
| 97 | struct nf_conntrack_expect *exp) __read_mostly; |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 98 | int (*nat_q931_hook) (struct sk_buff *skb, |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 99 | struct nf_conn *ct, |
| 100 | enum ip_conntrack_info ctinfo, |
| 101 | unsigned char **data, TransportAddress *taddr, int idx, |
| 102 | __be16 port, struct nf_conntrack_expect *exp) |
| 103 | __read_mostly; |
| 104 | |
| 105 | static DEFINE_SPINLOCK(nf_h323_lock); |
| 106 | static char *h323_buffer; |
| 107 | |
| 108 | static struct nf_conntrack_helper nf_conntrack_helper_h245; |
| 109 | static struct nf_conntrack_helper nf_conntrack_helper_q931[]; |
| 110 | static struct nf_conntrack_helper nf_conntrack_helper_ras[]; |
| 111 | |
| 112 | /****************************************************************************/ |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 113 | static int get_tpkt_data(struct sk_buff *skb, unsigned int protoff, |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 114 | struct nf_conn *ct, enum ip_conntrack_info ctinfo, |
| 115 | unsigned char **data, int *datalen, int *dataoff) |
| 116 | { |
| 117 | struct nf_ct_h323_master *info = &nfct_help(ct)->help.ct_h323_info; |
| 118 | int dir = CTINFO2DIR(ctinfo); |
Jan Engelhardt | 905e3e8 | 2008-01-31 04:50:05 -0800 | [diff] [blame] | 119 | const struct tcphdr *th; |
| 120 | struct tcphdr _tcph; |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 121 | int tcpdatalen; |
| 122 | int tcpdataoff; |
| 123 | unsigned char *tpkt; |
| 124 | int tpktlen; |
| 125 | int tpktoff; |
| 126 | |
| 127 | /* Get TCP header */ |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 128 | th = skb_header_pointer(skb, protoff, sizeof(_tcph), &_tcph); |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 129 | if (th == NULL) |
| 130 | return 0; |
| 131 | |
| 132 | /* Get TCP data offset */ |
| 133 | tcpdataoff = protoff + th->doff * 4; |
| 134 | |
| 135 | /* Get TCP data length */ |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 136 | tcpdatalen = skb->len - tcpdataoff; |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 137 | if (tcpdatalen <= 0) /* No TCP data */ |
| 138 | goto clear_out; |
| 139 | |
| 140 | if (*data == NULL) { /* first TPKT */ |
| 141 | /* Get first TPKT pointer */ |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 142 | tpkt = skb_header_pointer(skb, tcpdataoff, tcpdatalen, |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 143 | h323_buffer); |
| 144 | BUG_ON(tpkt == NULL); |
| 145 | |
| 146 | /* Validate TPKT identifier */ |
| 147 | if (tcpdatalen < 4 || tpkt[0] != 0x03 || tpkt[1] != 0) { |
| 148 | /* Netmeeting sends TPKT header and data separately */ |
| 149 | if (info->tpkt_len[dir] > 0) { |
Patrick McHardy | 0d53778 | 2007-07-07 22:39:38 -0700 | [diff] [blame] | 150 | pr_debug("nf_ct_h323: previous packet " |
| 151 | "indicated separate TPKT data of %hu " |
| 152 | "bytes\n", info->tpkt_len[dir]); |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 153 | if (info->tpkt_len[dir] <= tcpdatalen) { |
| 154 | /* Yes, there was a TPKT header |
| 155 | * received */ |
| 156 | *data = tpkt; |
| 157 | *datalen = info->tpkt_len[dir]; |
| 158 | *dataoff = 0; |
| 159 | goto out; |
| 160 | } |
| 161 | |
| 162 | /* Fragmented TPKT */ |
Patrick McHardy | 0d53778 | 2007-07-07 22:39:38 -0700 | [diff] [blame] | 163 | pr_debug("nf_ct_h323: fragmented TPKT\n"); |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 164 | goto clear_out; |
| 165 | } |
| 166 | |
| 167 | /* It is not even a TPKT */ |
| 168 | return 0; |
| 169 | } |
| 170 | tpktoff = 0; |
| 171 | } else { /* Next TPKT */ |
| 172 | tpktoff = *dataoff + *datalen; |
| 173 | tcpdatalen -= tpktoff; |
| 174 | if (tcpdatalen <= 4) /* No more TPKT */ |
| 175 | goto clear_out; |
| 176 | tpkt = *data + *datalen; |
| 177 | |
| 178 | /* Validate TPKT identifier */ |
| 179 | if (tpkt[0] != 0x03 || tpkt[1] != 0) |
| 180 | goto clear_out; |
| 181 | } |
| 182 | |
| 183 | /* Validate TPKT length */ |
| 184 | tpktlen = tpkt[2] * 256 + tpkt[3]; |
| 185 | if (tpktlen < 4) |
| 186 | goto clear_out; |
| 187 | if (tpktlen > tcpdatalen) { |
| 188 | if (tcpdatalen == 4) { /* Separate TPKT header */ |
| 189 | /* Netmeeting sends TPKT header and data separately */ |
Patrick McHardy | 0d53778 | 2007-07-07 22:39:38 -0700 | [diff] [blame] | 190 | pr_debug("nf_ct_h323: separate TPKT header indicates " |
| 191 | "there will be TPKT data of %hu bytes\n", |
| 192 | tpktlen - 4); |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 193 | info->tpkt_len[dir] = tpktlen - 4; |
| 194 | return 0; |
| 195 | } |
| 196 | |
Patrick McHardy | e772c34 | 2010-05-01 18:29:43 +0200 | [diff] [blame] | 197 | pr_debug("nf_ct_h323: incomplete TPKT (fragmented?)\n"); |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 198 | goto clear_out; |
| 199 | } |
| 200 | |
| 201 | /* This is the encapsulated data */ |
| 202 | *data = tpkt + 4; |
| 203 | *datalen = tpktlen - 4; |
| 204 | *dataoff = tpktoff + 4; |
| 205 | |
| 206 | out: |
| 207 | /* Clear TPKT length */ |
| 208 | info->tpkt_len[dir] = 0; |
| 209 | return 1; |
| 210 | |
| 211 | clear_out: |
| 212 | info->tpkt_len[dir] = 0; |
| 213 | return 0; |
| 214 | } |
| 215 | |
| 216 | /****************************************************************************/ |
Jan Engelhardt | 905e3e8 | 2008-01-31 04:50:05 -0800 | [diff] [blame] | 217 | static int get_h245_addr(struct nf_conn *ct, const unsigned char *data, |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 218 | H245_TransportAddress *taddr, |
Jan Engelhardt | 643a2c1 | 2007-12-17 22:43:50 -0800 | [diff] [blame] | 219 | union nf_inet_addr *addr, __be16 *port) |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 220 | { |
Jan Engelhardt | 905e3e8 | 2008-01-31 04:50:05 -0800 | [diff] [blame] | 221 | const unsigned char *p; |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 222 | int len; |
| 223 | |
| 224 | if (taddr->choice != eH245_TransportAddress_unicastAddress) |
| 225 | return 0; |
| 226 | |
| 227 | switch (taddr->unicastAddress.choice) { |
| 228 | case eUnicastAddress_iPAddress: |
Patrick McHardy | 5e8fbe2 | 2008-04-14 11:15:52 +0200 | [diff] [blame] | 229 | if (nf_ct_l3num(ct) != AF_INET) |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 230 | return 0; |
| 231 | p = data + taddr->unicastAddress.iPAddress.network; |
| 232 | len = 4; |
| 233 | break; |
| 234 | case eUnicastAddress_iP6Address: |
Patrick McHardy | 5e8fbe2 | 2008-04-14 11:15:52 +0200 | [diff] [blame] | 235 | if (nf_ct_l3num(ct) != AF_INET6) |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 236 | return 0; |
| 237 | p = data + taddr->unicastAddress.iP6Address.network; |
| 238 | len = 16; |
| 239 | break; |
| 240 | default: |
| 241 | return 0; |
| 242 | } |
| 243 | |
| 244 | memcpy(addr, p, len); |
| 245 | memset((void *)addr + len, 0, sizeof(*addr) - len); |
| 246 | memcpy(port, p + len, sizeof(__be16)); |
| 247 | |
| 248 | return 1; |
| 249 | } |
| 250 | |
| 251 | /****************************************************************************/ |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 252 | static int expect_rtp_rtcp(struct sk_buff *skb, struct nf_conn *ct, |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 253 | enum ip_conntrack_info ctinfo, |
| 254 | unsigned char **data, int dataoff, |
| 255 | H245_TransportAddress *taddr) |
| 256 | { |
| 257 | int dir = CTINFO2DIR(ctinfo); |
| 258 | int ret = 0; |
| 259 | __be16 port; |
| 260 | __be16 rtp_port, rtcp_port; |
Jan Engelhardt | 643a2c1 | 2007-12-17 22:43:50 -0800 | [diff] [blame] | 261 | union nf_inet_addr addr; |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 262 | struct nf_conntrack_expect *rtp_exp; |
| 263 | struct nf_conntrack_expect *rtcp_exp; |
| 264 | typeof(nat_rtp_rtcp_hook) nat_rtp_rtcp; |
| 265 | |
| 266 | /* Read RTP or RTCP address */ |
| 267 | if (!get_h245_addr(ct, *data, taddr, &addr, &port) || |
| 268 | memcmp(&addr, &ct->tuplehash[dir].tuple.src.u3, sizeof(addr)) || |
| 269 | port == 0) |
| 270 | return 0; |
| 271 | |
| 272 | /* RTP port is even */ |
| 273 | port &= htons(~1); |
| 274 | rtp_port = port; |
| 275 | rtcp_port = htons(ntohs(port) + 1); |
| 276 | |
| 277 | /* Create expect for RTP */ |
Patrick McHardy | 6823645 | 2007-07-07 22:30:49 -0700 | [diff] [blame] | 278 | if ((rtp_exp = nf_ct_expect_alloc(ct)) == NULL) |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 279 | return -1; |
Patrick McHardy | 5e8fbe2 | 2008-04-14 11:15:52 +0200 | [diff] [blame] | 280 | nf_ct_expect_init(rtp_exp, NF_CT_EXPECT_CLASS_DEFAULT, nf_ct_l3num(ct), |
Patrick McHardy | 6823645 | 2007-07-07 22:30:49 -0700 | [diff] [blame] | 281 | &ct->tuplehash[!dir].tuple.src.u3, |
| 282 | &ct->tuplehash[!dir].tuple.dst.u3, |
| 283 | IPPROTO_UDP, NULL, &rtp_port); |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 284 | |
| 285 | /* Create expect for RTCP */ |
Patrick McHardy | 6823645 | 2007-07-07 22:30:49 -0700 | [diff] [blame] | 286 | if ((rtcp_exp = nf_ct_expect_alloc(ct)) == NULL) { |
| 287 | nf_ct_expect_put(rtp_exp); |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 288 | return -1; |
| 289 | } |
Patrick McHardy | 5e8fbe2 | 2008-04-14 11:15:52 +0200 | [diff] [blame] | 290 | nf_ct_expect_init(rtcp_exp, NF_CT_EXPECT_CLASS_DEFAULT, nf_ct_l3num(ct), |
Patrick McHardy | 6823645 | 2007-07-07 22:30:49 -0700 | [diff] [blame] | 291 | &ct->tuplehash[!dir].tuple.src.u3, |
| 292 | &ct->tuplehash[!dir].tuple.dst.u3, |
| 293 | IPPROTO_UDP, NULL, &rtcp_port); |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 294 | |
| 295 | if (memcmp(&ct->tuplehash[dir].tuple.src.u3, |
YOSHIFUJI Hideaki | 601e68e | 2007-02-12 11:15:49 -0800 | [diff] [blame] | 296 | &ct->tuplehash[!dir].tuple.dst.u3, |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 297 | sizeof(ct->tuplehash[dir].tuple.src.u3)) && |
| 298 | (nat_rtp_rtcp = rcu_dereference(nat_rtp_rtcp_hook)) && |
| 299 | ct->status & IPS_NAT_MASK) { |
| 300 | /* NAT needed */ |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 301 | ret = nat_rtp_rtcp(skb, ct, ctinfo, data, dataoff, |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 302 | taddr, port, rtp_port, rtp_exp, rtcp_exp); |
| 303 | } else { /* Conntrack only */ |
Patrick McHardy | 6823645 | 2007-07-07 22:30:49 -0700 | [diff] [blame] | 304 | if (nf_ct_expect_related(rtp_exp) == 0) { |
| 305 | if (nf_ct_expect_related(rtcp_exp) == 0) { |
Patrick McHardy | 0d53778 | 2007-07-07 22:39:38 -0700 | [diff] [blame] | 306 | pr_debug("nf_ct_h323: expect RTP "); |
Jan Engelhardt | 3c9fba6 | 2008-04-14 11:15:54 +0200 | [diff] [blame] | 307 | nf_ct_dump_tuple(&rtp_exp->tuple); |
Patrick McHardy | 0d53778 | 2007-07-07 22:39:38 -0700 | [diff] [blame] | 308 | pr_debug("nf_ct_h323: expect RTCP "); |
Jan Engelhardt | 3c9fba6 | 2008-04-14 11:15:54 +0200 | [diff] [blame] | 309 | nf_ct_dump_tuple(&rtcp_exp->tuple); |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 310 | } else { |
Patrick McHardy | 6823645 | 2007-07-07 22:30:49 -0700 | [diff] [blame] | 311 | nf_ct_unexpect_related(rtp_exp); |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 312 | ret = -1; |
| 313 | } |
| 314 | } else |
| 315 | ret = -1; |
| 316 | } |
| 317 | |
Patrick McHardy | 6823645 | 2007-07-07 22:30:49 -0700 | [diff] [blame] | 318 | nf_ct_expect_put(rtp_exp); |
| 319 | nf_ct_expect_put(rtcp_exp); |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 320 | |
| 321 | return ret; |
| 322 | } |
| 323 | |
| 324 | /****************************************************************************/ |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 325 | static int expect_t120(struct sk_buff *skb, |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 326 | struct nf_conn *ct, |
| 327 | enum ip_conntrack_info ctinfo, |
| 328 | unsigned char **data, int dataoff, |
| 329 | H245_TransportAddress *taddr) |
| 330 | { |
| 331 | int dir = CTINFO2DIR(ctinfo); |
| 332 | int ret = 0; |
| 333 | __be16 port; |
Jan Engelhardt | 643a2c1 | 2007-12-17 22:43:50 -0800 | [diff] [blame] | 334 | union nf_inet_addr addr; |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 335 | struct nf_conntrack_expect *exp; |
| 336 | typeof(nat_t120_hook) nat_t120; |
| 337 | |
| 338 | /* Read T.120 address */ |
| 339 | if (!get_h245_addr(ct, *data, taddr, &addr, &port) || |
| 340 | memcmp(&addr, &ct->tuplehash[dir].tuple.src.u3, sizeof(addr)) || |
| 341 | port == 0) |
| 342 | return 0; |
| 343 | |
| 344 | /* Create expect for T.120 connections */ |
Patrick McHardy | 6823645 | 2007-07-07 22:30:49 -0700 | [diff] [blame] | 345 | if ((exp = nf_ct_expect_alloc(ct)) == NULL) |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 346 | return -1; |
Patrick McHardy | 5e8fbe2 | 2008-04-14 11:15:52 +0200 | [diff] [blame] | 347 | nf_ct_expect_init(exp, NF_CT_EXPECT_CLASS_DEFAULT, nf_ct_l3num(ct), |
Patrick McHardy | 6823645 | 2007-07-07 22:30:49 -0700 | [diff] [blame] | 348 | &ct->tuplehash[!dir].tuple.src.u3, |
| 349 | &ct->tuplehash[!dir].tuple.dst.u3, |
| 350 | IPPROTO_TCP, NULL, &port); |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 351 | exp->flags = NF_CT_EXPECT_PERMANENT; /* Accept multiple channels */ |
| 352 | |
| 353 | if (memcmp(&ct->tuplehash[dir].tuple.src.u3, |
| 354 | &ct->tuplehash[!dir].tuple.dst.u3, |
| 355 | sizeof(ct->tuplehash[dir].tuple.src.u3)) && |
| 356 | (nat_t120 = rcu_dereference(nat_t120_hook)) && |
| 357 | ct->status & IPS_NAT_MASK) { |
| 358 | /* NAT needed */ |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 359 | ret = nat_t120(skb, ct, ctinfo, data, dataoff, taddr, |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 360 | port, exp); |
| 361 | } else { /* Conntrack only */ |
Patrick McHardy | 6823645 | 2007-07-07 22:30:49 -0700 | [diff] [blame] | 362 | if (nf_ct_expect_related(exp) == 0) { |
Patrick McHardy | 0d53778 | 2007-07-07 22:39:38 -0700 | [diff] [blame] | 363 | pr_debug("nf_ct_h323: expect T.120 "); |
Jan Engelhardt | 3c9fba6 | 2008-04-14 11:15:54 +0200 | [diff] [blame] | 364 | nf_ct_dump_tuple(&exp->tuple); |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 365 | } else |
| 366 | ret = -1; |
| 367 | } |
| 368 | |
Patrick McHardy | 6823645 | 2007-07-07 22:30:49 -0700 | [diff] [blame] | 369 | nf_ct_expect_put(exp); |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 370 | |
| 371 | return ret; |
| 372 | } |
| 373 | |
| 374 | /****************************************************************************/ |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 375 | static int process_h245_channel(struct sk_buff *skb, |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 376 | struct nf_conn *ct, |
| 377 | enum ip_conntrack_info ctinfo, |
| 378 | unsigned char **data, int dataoff, |
| 379 | H2250LogicalChannelParameters *channel) |
| 380 | { |
| 381 | int ret; |
| 382 | |
| 383 | if (channel->options & eH2250LogicalChannelParameters_mediaChannel) { |
| 384 | /* RTP */ |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 385 | ret = expect_rtp_rtcp(skb, ct, ctinfo, data, dataoff, |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 386 | &channel->mediaChannel); |
| 387 | if (ret < 0) |
| 388 | return -1; |
| 389 | } |
| 390 | |
| 391 | if (channel-> |
| 392 | options & eH2250LogicalChannelParameters_mediaControlChannel) { |
| 393 | /* RTCP */ |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 394 | ret = expect_rtp_rtcp(skb, ct, ctinfo, data, dataoff, |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 395 | &channel->mediaControlChannel); |
| 396 | if (ret < 0) |
| 397 | return -1; |
| 398 | } |
| 399 | |
| 400 | return 0; |
| 401 | } |
| 402 | |
| 403 | /****************************************************************************/ |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 404 | static int process_olc(struct sk_buff *skb, struct nf_conn *ct, |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 405 | enum ip_conntrack_info ctinfo, |
| 406 | unsigned char **data, int dataoff, |
| 407 | OpenLogicalChannel *olc) |
| 408 | { |
| 409 | int ret; |
| 410 | |
Patrick McHardy | 0d53778 | 2007-07-07 22:39:38 -0700 | [diff] [blame] | 411 | pr_debug("nf_ct_h323: OpenLogicalChannel\n"); |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 412 | |
| 413 | if (olc->forwardLogicalChannelParameters.multiplexParameters.choice == |
| 414 | eOpenLogicalChannel_forwardLogicalChannelParameters_multiplexParameters_h2250LogicalChannelParameters) |
| 415 | { |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 416 | ret = process_h245_channel(skb, ct, ctinfo, data, dataoff, |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 417 | &olc-> |
| 418 | forwardLogicalChannelParameters. |
| 419 | multiplexParameters. |
| 420 | h2250LogicalChannelParameters); |
| 421 | if (ret < 0) |
| 422 | return -1; |
| 423 | } |
| 424 | |
| 425 | if ((olc->options & |
| 426 | eOpenLogicalChannel_reverseLogicalChannelParameters) && |
| 427 | (olc->reverseLogicalChannelParameters.options & |
| 428 | eOpenLogicalChannel_reverseLogicalChannelParameters_multiplexParameters) |
| 429 | && (olc->reverseLogicalChannelParameters.multiplexParameters. |
| 430 | choice == |
| 431 | eOpenLogicalChannel_reverseLogicalChannelParameters_multiplexParameters_h2250LogicalChannelParameters)) |
| 432 | { |
| 433 | ret = |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 434 | process_h245_channel(skb, ct, ctinfo, data, dataoff, |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 435 | &olc-> |
| 436 | reverseLogicalChannelParameters. |
| 437 | multiplexParameters. |
| 438 | h2250LogicalChannelParameters); |
| 439 | if (ret < 0) |
| 440 | return -1; |
| 441 | } |
| 442 | |
| 443 | if ((olc->options & eOpenLogicalChannel_separateStack) && |
| 444 | olc->forwardLogicalChannelParameters.dataType.choice == |
| 445 | eDataType_data && |
| 446 | olc->forwardLogicalChannelParameters.dataType.data.application. |
| 447 | choice == eDataApplicationCapability_application_t120 && |
| 448 | olc->forwardLogicalChannelParameters.dataType.data.application. |
| 449 | t120.choice == eDataProtocolCapability_separateLANStack && |
| 450 | olc->separateStack.networkAddress.choice == |
| 451 | eNetworkAccessParameters_networkAddress_localAreaAddress) { |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 452 | ret = expect_t120(skb, ct, ctinfo, data, dataoff, |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 453 | &olc->separateStack.networkAddress. |
| 454 | localAreaAddress); |
| 455 | if (ret < 0) |
| 456 | return -1; |
| 457 | } |
| 458 | |
| 459 | return 0; |
| 460 | } |
| 461 | |
| 462 | /****************************************************************************/ |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 463 | static int process_olca(struct sk_buff *skb, struct nf_conn *ct, |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 464 | enum ip_conntrack_info ctinfo, |
| 465 | unsigned char **data, int dataoff, |
| 466 | OpenLogicalChannelAck *olca) |
| 467 | { |
| 468 | H2250LogicalChannelAckParameters *ack; |
| 469 | int ret; |
| 470 | |
Patrick McHardy | 0d53778 | 2007-07-07 22:39:38 -0700 | [diff] [blame] | 471 | pr_debug("nf_ct_h323: OpenLogicalChannelAck\n"); |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 472 | |
| 473 | if ((olca->options & |
| 474 | eOpenLogicalChannelAck_reverseLogicalChannelParameters) && |
| 475 | (olca->reverseLogicalChannelParameters.options & |
| 476 | eOpenLogicalChannelAck_reverseLogicalChannelParameters_multiplexParameters) |
| 477 | && (olca->reverseLogicalChannelParameters.multiplexParameters. |
| 478 | choice == |
| 479 | eOpenLogicalChannelAck_reverseLogicalChannelParameters_multiplexParameters_h2250LogicalChannelParameters)) |
| 480 | { |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 481 | ret = process_h245_channel(skb, ct, ctinfo, data, dataoff, |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 482 | &olca-> |
| 483 | reverseLogicalChannelParameters. |
| 484 | multiplexParameters. |
| 485 | h2250LogicalChannelParameters); |
| 486 | if (ret < 0) |
| 487 | return -1; |
| 488 | } |
| 489 | |
| 490 | if ((olca->options & |
| 491 | eOpenLogicalChannelAck_forwardMultiplexAckParameters) && |
| 492 | (olca->forwardMultiplexAckParameters.choice == |
| 493 | eOpenLogicalChannelAck_forwardMultiplexAckParameters_h2250LogicalChannelAckParameters)) |
| 494 | { |
| 495 | ack = &olca->forwardMultiplexAckParameters. |
| 496 | h2250LogicalChannelAckParameters; |
| 497 | if (ack->options & |
| 498 | eH2250LogicalChannelAckParameters_mediaChannel) { |
| 499 | /* RTP */ |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 500 | ret = expect_rtp_rtcp(skb, ct, ctinfo, data, dataoff, |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 501 | &ack->mediaChannel); |
| 502 | if (ret < 0) |
| 503 | return -1; |
| 504 | } |
| 505 | |
| 506 | if (ack->options & |
| 507 | eH2250LogicalChannelAckParameters_mediaControlChannel) { |
| 508 | /* RTCP */ |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 509 | ret = expect_rtp_rtcp(skb, ct, ctinfo, data, dataoff, |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 510 | &ack->mediaControlChannel); |
| 511 | if (ret < 0) |
| 512 | return -1; |
| 513 | } |
| 514 | } |
| 515 | |
Jing Min Zhao | f8f1c08 | 2007-05-24 16:44:11 -0700 | [diff] [blame] | 516 | if ((olca->options & eOpenLogicalChannelAck_separateStack) && |
| 517 | olca->separateStack.networkAddress.choice == |
| 518 | eNetworkAccessParameters_networkAddress_localAreaAddress) { |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 519 | ret = expect_t120(skb, ct, ctinfo, data, dataoff, |
Jing Min Zhao | f8f1c08 | 2007-05-24 16:44:11 -0700 | [diff] [blame] | 520 | &olca->separateStack.networkAddress. |
| 521 | localAreaAddress); |
| 522 | if (ret < 0) |
| 523 | return -1; |
| 524 | } |
| 525 | |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 526 | return 0; |
| 527 | } |
| 528 | |
| 529 | /****************************************************************************/ |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 530 | static int process_h245(struct sk_buff *skb, struct nf_conn *ct, |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 531 | enum ip_conntrack_info ctinfo, |
| 532 | unsigned char **data, int dataoff, |
| 533 | MultimediaSystemControlMessage *mscm) |
| 534 | { |
| 535 | switch (mscm->choice) { |
| 536 | case eMultimediaSystemControlMessage_request: |
| 537 | if (mscm->request.choice == |
| 538 | eRequestMessage_openLogicalChannel) { |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 539 | return process_olc(skb, ct, ctinfo, data, dataoff, |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 540 | &mscm->request.openLogicalChannel); |
| 541 | } |
Patrick McHardy | 0d53778 | 2007-07-07 22:39:38 -0700 | [diff] [blame] | 542 | pr_debug("nf_ct_h323: H.245 Request %d\n", |
| 543 | mscm->request.choice); |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 544 | break; |
| 545 | case eMultimediaSystemControlMessage_response: |
| 546 | if (mscm->response.choice == |
| 547 | eResponseMessage_openLogicalChannelAck) { |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 548 | return process_olca(skb, ct, ctinfo, data, dataoff, |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 549 | &mscm->response. |
| 550 | openLogicalChannelAck); |
| 551 | } |
Patrick McHardy | 0d53778 | 2007-07-07 22:39:38 -0700 | [diff] [blame] | 552 | pr_debug("nf_ct_h323: H.245 Response %d\n", |
| 553 | mscm->response.choice); |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 554 | break; |
| 555 | default: |
Patrick McHardy | 0d53778 | 2007-07-07 22:39:38 -0700 | [diff] [blame] | 556 | pr_debug("nf_ct_h323: H.245 signal %d\n", mscm->choice); |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 557 | break; |
| 558 | } |
| 559 | |
| 560 | return 0; |
| 561 | } |
| 562 | |
| 563 | /****************************************************************************/ |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 564 | static int h245_help(struct sk_buff *skb, unsigned int protoff, |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 565 | struct nf_conn *ct, enum ip_conntrack_info ctinfo) |
| 566 | { |
| 567 | static MultimediaSystemControlMessage mscm; |
| 568 | unsigned char *data = NULL; |
| 569 | int datalen; |
| 570 | int dataoff; |
| 571 | int ret; |
| 572 | |
| 573 | /* Until there's been traffic both ways, don't look in packets. */ |
Eric Dumazet | fb04883 | 2011-05-19 15:44:27 +0200 | [diff] [blame] | 574 | if (ctinfo != IP_CT_ESTABLISHED && ctinfo != IP_CT_ESTABLISHED_REPLY) |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 575 | return NF_ACCEPT; |
Eric Dumazet | fb04883 | 2011-05-19 15:44:27 +0200 | [diff] [blame] | 576 | |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 577 | pr_debug("nf_ct_h245: skblen = %u\n", skb->len); |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 578 | |
| 579 | spin_lock_bh(&nf_h323_lock); |
| 580 | |
| 581 | /* Process each TPKT */ |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 582 | while (get_tpkt_data(skb, protoff, ct, ctinfo, |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 583 | &data, &datalen, &dataoff)) { |
Patrick McHardy | 0d53778 | 2007-07-07 22:39:38 -0700 | [diff] [blame] | 584 | pr_debug("nf_ct_h245: TPKT len=%d ", datalen); |
Jan Engelhardt | 3c9fba6 | 2008-04-14 11:15:54 +0200 | [diff] [blame] | 585 | nf_ct_dump_tuple(&ct->tuplehash[CTINFO2DIR(ctinfo)].tuple); |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 586 | |
| 587 | /* Decode H.245 signal */ |
| 588 | ret = DecodeMultimediaSystemControlMessage(data, datalen, |
| 589 | &mscm); |
| 590 | if (ret < 0) { |
Patrick McHardy | 0d53778 | 2007-07-07 22:39:38 -0700 | [diff] [blame] | 591 | pr_debug("nf_ct_h245: decoding error: %s\n", |
| 592 | ret == H323_ERROR_BOUND ? |
| 593 | "out of bound" : "out of range"); |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 594 | /* We don't drop when decoding error */ |
| 595 | break; |
| 596 | } |
| 597 | |
| 598 | /* Process H.245 signal */ |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 599 | if (process_h245(skb, ct, ctinfo, &data, dataoff, &mscm) < 0) |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 600 | goto drop; |
| 601 | } |
| 602 | |
| 603 | spin_unlock_bh(&nf_h323_lock); |
| 604 | return NF_ACCEPT; |
| 605 | |
| 606 | drop: |
| 607 | spin_unlock_bh(&nf_h323_lock); |
| 608 | if (net_ratelimit()) |
Stephen Hemminger | 654d0fb | 2010-05-13 15:02:08 +0200 | [diff] [blame] | 609 | pr_info("nf_ct_h245: packet dropped\n"); |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 610 | return NF_DROP; |
| 611 | } |
| 612 | |
| 613 | /****************************************************************************/ |
Patrick McHardy | 6002f26 | 2008-03-25 20:09:15 -0700 | [diff] [blame] | 614 | static const struct nf_conntrack_expect_policy h245_exp_policy = { |
| 615 | .max_expected = H323_RTP_CHANNEL_MAX * 4 + 2 /* T.120 */, |
| 616 | .timeout = 240, |
| 617 | }; |
| 618 | |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 619 | static struct nf_conntrack_helper nf_conntrack_helper_h245 __read_mostly = { |
| 620 | .name = "H.245", |
| 621 | .me = THIS_MODULE, |
Patrick McHardy | a56b8f8 | 2008-06-17 15:52:32 -0700 | [diff] [blame] | 622 | .tuple.src.l3num = AF_UNSPEC, |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 623 | .tuple.dst.protonum = IPPROTO_UDP, |
Patrick McHardy | 6002f26 | 2008-03-25 20:09:15 -0700 | [diff] [blame] | 624 | .help = h245_help, |
| 625 | .expect_policy = &h245_exp_policy, |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 626 | }; |
| 627 | |
| 628 | /****************************************************************************/ |
| 629 | int get_h225_addr(struct nf_conn *ct, unsigned char *data, |
| 630 | TransportAddress *taddr, |
Jan Engelhardt | 643a2c1 | 2007-12-17 22:43:50 -0800 | [diff] [blame] | 631 | union nf_inet_addr *addr, __be16 *port) |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 632 | { |
Jan Engelhardt | 905e3e8 | 2008-01-31 04:50:05 -0800 | [diff] [blame] | 633 | const unsigned char *p; |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 634 | int len; |
| 635 | |
| 636 | switch (taddr->choice) { |
| 637 | case eTransportAddress_ipAddress: |
Patrick McHardy | 5e8fbe2 | 2008-04-14 11:15:52 +0200 | [diff] [blame] | 638 | if (nf_ct_l3num(ct) != AF_INET) |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 639 | return 0; |
| 640 | p = data + taddr->ipAddress.ip; |
| 641 | len = 4; |
| 642 | break; |
| 643 | case eTransportAddress_ip6Address: |
Patrick McHardy | 5e8fbe2 | 2008-04-14 11:15:52 +0200 | [diff] [blame] | 644 | if (nf_ct_l3num(ct) != AF_INET6) |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 645 | return 0; |
Jing Min Zhao | bb80724 | 2007-05-24 16:43:07 -0700 | [diff] [blame] | 646 | p = data + taddr->ip6Address.ip; |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 647 | len = 16; |
| 648 | break; |
| 649 | default: |
| 650 | return 0; |
| 651 | } |
| 652 | |
| 653 | memcpy(addr, p, len); |
| 654 | memset((void *)addr + len, 0, sizeof(*addr) - len); |
| 655 | memcpy(port, p + len, sizeof(__be16)); |
| 656 | |
| 657 | return 1; |
| 658 | } |
| 659 | |
| 660 | /****************************************************************************/ |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 661 | static int expect_h245(struct sk_buff *skb, struct nf_conn *ct, |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 662 | enum ip_conntrack_info ctinfo, |
| 663 | unsigned char **data, int dataoff, |
| 664 | TransportAddress *taddr) |
| 665 | { |
| 666 | int dir = CTINFO2DIR(ctinfo); |
| 667 | int ret = 0; |
| 668 | __be16 port; |
Jan Engelhardt | 643a2c1 | 2007-12-17 22:43:50 -0800 | [diff] [blame] | 669 | union nf_inet_addr addr; |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 670 | struct nf_conntrack_expect *exp; |
| 671 | typeof(nat_h245_hook) nat_h245; |
| 672 | |
| 673 | /* Read h245Address */ |
| 674 | if (!get_h225_addr(ct, *data, taddr, &addr, &port) || |
| 675 | memcmp(&addr, &ct->tuplehash[dir].tuple.src.u3, sizeof(addr)) || |
| 676 | port == 0) |
| 677 | return 0; |
| 678 | |
| 679 | /* Create expect for h245 connection */ |
Patrick McHardy | 6823645 | 2007-07-07 22:30:49 -0700 | [diff] [blame] | 680 | if ((exp = nf_ct_expect_alloc(ct)) == NULL) |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 681 | return -1; |
Patrick McHardy | 5e8fbe2 | 2008-04-14 11:15:52 +0200 | [diff] [blame] | 682 | nf_ct_expect_init(exp, NF_CT_EXPECT_CLASS_DEFAULT, nf_ct_l3num(ct), |
Patrick McHardy | 6823645 | 2007-07-07 22:30:49 -0700 | [diff] [blame] | 683 | &ct->tuplehash[!dir].tuple.src.u3, |
| 684 | &ct->tuplehash[!dir].tuple.dst.u3, |
| 685 | IPPROTO_TCP, NULL, &port); |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 686 | exp->helper = &nf_conntrack_helper_h245; |
| 687 | |
| 688 | if (memcmp(&ct->tuplehash[dir].tuple.src.u3, |
| 689 | &ct->tuplehash[!dir].tuple.dst.u3, |
| 690 | sizeof(ct->tuplehash[dir].tuple.src.u3)) && |
| 691 | (nat_h245 = rcu_dereference(nat_h245_hook)) && |
| 692 | ct->status & IPS_NAT_MASK) { |
| 693 | /* NAT needed */ |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 694 | ret = nat_h245(skb, ct, ctinfo, data, dataoff, taddr, |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 695 | port, exp); |
| 696 | } else { /* Conntrack only */ |
Patrick McHardy | 6823645 | 2007-07-07 22:30:49 -0700 | [diff] [blame] | 697 | if (nf_ct_expect_related(exp) == 0) { |
Patrick McHardy | 0d53778 | 2007-07-07 22:39:38 -0700 | [diff] [blame] | 698 | pr_debug("nf_ct_q931: expect H.245 "); |
Jan Engelhardt | 3c9fba6 | 2008-04-14 11:15:54 +0200 | [diff] [blame] | 699 | nf_ct_dump_tuple(&exp->tuple); |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 700 | } else |
| 701 | ret = -1; |
| 702 | } |
| 703 | |
Patrick McHardy | 6823645 | 2007-07-07 22:30:49 -0700 | [diff] [blame] | 704 | nf_ct_expect_put(exp); |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 705 | |
| 706 | return ret; |
| 707 | } |
| 708 | |
| 709 | /* If the calling party is on the same side of the forward-to party, |
| 710 | * we don't need to track the second call */ |
Jan Engelhardt | 905e3e8 | 2008-01-31 04:50:05 -0800 | [diff] [blame] | 711 | static int callforward_do_filter(const union nf_inet_addr *src, |
Jan Engelhardt | 76108ce | 2008-10-08 11:35:00 +0200 | [diff] [blame] | 712 | const union nf_inet_addr *dst, |
| 713 | u_int8_t family) |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 714 | { |
Patrick McHardy | 1e796fd | 2007-12-17 22:42:27 -0800 | [diff] [blame] | 715 | const struct nf_afinfo *afinfo; |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 716 | int ret = 0; |
| 717 | |
Patrick McHardy | 1841a4c | 2007-12-05 01:22:05 -0800 | [diff] [blame] | 718 | /* rcu_read_lock()ed by nf_hook_slow() */ |
| 719 | afinfo = nf_get_afinfo(family); |
| 720 | if (!afinfo) |
| 721 | return 0; |
| 722 | |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 723 | switch (family) { |
| 724 | case AF_INET: { |
David S. Miller | 5a49d0e | 2011-03-12 02:14:05 -0500 | [diff] [blame] | 725 | struct flowi4 fl1, fl2; |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 726 | struct rtable *rt1, *rt2; |
| 727 | |
David S. Miller | 5a49d0e | 2011-03-12 02:14:05 -0500 | [diff] [blame] | 728 | memset(&fl1, 0, sizeof(fl1)); |
| 729 | fl1.daddr = src->ip; |
| 730 | |
| 731 | memset(&fl2, 0, sizeof(fl2)); |
| 732 | fl2.daddr = dst->ip; |
Florian Westphal | 31ad3dd | 2011-04-04 16:56:29 +0200 | [diff] [blame] | 733 | if (!afinfo->route(&init_net, (struct dst_entry **)&rt1, |
Florian Westphal | 0fae2e7 | 2011-04-04 17:00:54 +0200 | [diff] [blame] | 734 | flowi4_to_flowi(&fl1), false)) { |
Florian Westphal | 31ad3dd | 2011-04-04 16:56:29 +0200 | [diff] [blame] | 735 | if (!afinfo->route(&init_net, (struct dst_entry **)&rt2, |
Florian Westphal | 0fae2e7 | 2011-04-04 17:00:54 +0200 | [diff] [blame] | 736 | flowi4_to_flowi(&fl2), false)) { |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 737 | if (rt1->rt_gateway == rt2->rt_gateway && |
Changli Gao | d8d1f30 | 2010-06-10 23:31:35 -0700 | [diff] [blame] | 738 | rt1->dst.dev == rt2->dst.dev) |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 739 | ret = 1; |
Changli Gao | d8d1f30 | 2010-06-10 23:31:35 -0700 | [diff] [blame] | 740 | dst_release(&rt2->dst); |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 741 | } |
Changli Gao | d8d1f30 | 2010-06-10 23:31:35 -0700 | [diff] [blame] | 742 | dst_release(&rt1->dst); |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 743 | } |
| 744 | break; |
| 745 | } |
Patrick McHardy | 1841a4c | 2007-12-05 01:22:05 -0800 | [diff] [blame] | 746 | #if defined(CONFIG_NF_CONNTRACK_IPV6) || \ |
| 747 | defined(CONFIG_NF_CONNTRACK_IPV6_MODULE) |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 748 | case AF_INET6: { |
David S. Miller | 5a49d0e | 2011-03-12 02:14:05 -0500 | [diff] [blame] | 749 | struct flowi6 fl1, fl2; |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 750 | struct rt6_info *rt1, *rt2; |
| 751 | |
David S. Miller | 5a49d0e | 2011-03-12 02:14:05 -0500 | [diff] [blame] | 752 | memset(&fl1, 0, sizeof(fl1)); |
| 753 | ipv6_addr_copy(&fl1.daddr, &src->in6); |
| 754 | |
| 755 | memset(&fl2, 0, sizeof(fl2)); |
| 756 | ipv6_addr_copy(&fl2.daddr, &dst->in6); |
Florian Westphal | 31ad3dd | 2011-04-04 16:56:29 +0200 | [diff] [blame] | 757 | if (!afinfo->route(&init_net, (struct dst_entry **)&rt1, |
Florian Westphal | 0fae2e7 | 2011-04-04 17:00:54 +0200 | [diff] [blame] | 758 | flowi6_to_flowi(&fl1), false)) { |
Florian Westphal | 31ad3dd | 2011-04-04 16:56:29 +0200 | [diff] [blame] | 759 | if (!afinfo->route(&init_net, (struct dst_entry **)&rt2, |
Florian Westphal | 0fae2e7 | 2011-04-04 17:00:54 +0200 | [diff] [blame] | 760 | flowi6_to_flowi(&fl2), false)) { |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 761 | if (!memcmp(&rt1->rt6i_gateway, &rt2->rt6i_gateway, |
YOSHIFUJI Hideaki | 601e68e | 2007-02-12 11:15:49 -0800 | [diff] [blame] | 762 | sizeof(rt1->rt6i_gateway)) && |
Changli Gao | d8d1f30 | 2010-06-10 23:31:35 -0700 | [diff] [blame] | 763 | rt1->dst.dev == rt2->dst.dev) |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 764 | ret = 1; |
Changli Gao | d8d1f30 | 2010-06-10 23:31:35 -0700 | [diff] [blame] | 765 | dst_release(&rt2->dst); |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 766 | } |
Changli Gao | d8d1f30 | 2010-06-10 23:31:35 -0700 | [diff] [blame] | 767 | dst_release(&rt1->dst); |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 768 | } |
| 769 | break; |
| 770 | } |
| 771 | #endif |
| 772 | } |
| 773 | return ret; |
| 774 | |
| 775 | } |
| 776 | |
| 777 | /****************************************************************************/ |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 778 | static int expect_callforwarding(struct sk_buff *skb, |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 779 | struct nf_conn *ct, |
| 780 | enum ip_conntrack_info ctinfo, |
| 781 | unsigned char **data, int dataoff, |
| 782 | TransportAddress *taddr) |
| 783 | { |
| 784 | int dir = CTINFO2DIR(ctinfo); |
| 785 | int ret = 0; |
| 786 | __be16 port; |
Jan Engelhardt | 643a2c1 | 2007-12-17 22:43:50 -0800 | [diff] [blame] | 787 | union nf_inet_addr addr; |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 788 | struct nf_conntrack_expect *exp; |
| 789 | typeof(nat_callforwarding_hook) nat_callforwarding; |
| 790 | |
| 791 | /* Read alternativeAddress */ |
| 792 | if (!get_h225_addr(ct, *data, taddr, &addr, &port) || port == 0) |
| 793 | return 0; |
| 794 | |
| 795 | /* If the calling party is on the same side of the forward-to party, |
| 796 | * we don't need to track the second call */ |
| 797 | if (callforward_filter && |
| 798 | callforward_do_filter(&addr, &ct->tuplehash[!dir].tuple.src.u3, |
Patrick McHardy | 5e8fbe2 | 2008-04-14 11:15:52 +0200 | [diff] [blame] | 799 | nf_ct_l3num(ct))) { |
Patrick McHardy | 0d53778 | 2007-07-07 22:39:38 -0700 | [diff] [blame] | 800 | pr_debug("nf_ct_q931: Call Forwarding not tracked\n"); |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 801 | return 0; |
| 802 | } |
| 803 | |
| 804 | /* Create expect for the second call leg */ |
Patrick McHardy | 6823645 | 2007-07-07 22:30:49 -0700 | [diff] [blame] | 805 | if ((exp = nf_ct_expect_alloc(ct)) == NULL) |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 806 | return -1; |
Patrick McHardy | 5e8fbe2 | 2008-04-14 11:15:52 +0200 | [diff] [blame] | 807 | nf_ct_expect_init(exp, NF_CT_EXPECT_CLASS_DEFAULT, nf_ct_l3num(ct), |
Patrick McHardy | 6823645 | 2007-07-07 22:30:49 -0700 | [diff] [blame] | 808 | &ct->tuplehash[!dir].tuple.src.u3, &addr, |
| 809 | IPPROTO_TCP, NULL, &port); |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 810 | exp->helper = nf_conntrack_helper_q931; |
| 811 | |
| 812 | if (memcmp(&ct->tuplehash[dir].tuple.src.u3, |
| 813 | &ct->tuplehash[!dir].tuple.dst.u3, |
| 814 | sizeof(ct->tuplehash[dir].tuple.src.u3)) && |
| 815 | (nat_callforwarding = rcu_dereference(nat_callforwarding_hook)) && |
| 816 | ct->status & IPS_NAT_MASK) { |
| 817 | /* Need NAT */ |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 818 | ret = nat_callforwarding(skb, ct, ctinfo, data, dataoff, |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 819 | taddr, port, exp); |
| 820 | } else { /* Conntrack only */ |
Patrick McHardy | 6823645 | 2007-07-07 22:30:49 -0700 | [diff] [blame] | 821 | if (nf_ct_expect_related(exp) == 0) { |
Patrick McHardy | 0d53778 | 2007-07-07 22:39:38 -0700 | [diff] [blame] | 822 | pr_debug("nf_ct_q931: expect Call Forwarding "); |
Jan Engelhardt | 3c9fba6 | 2008-04-14 11:15:54 +0200 | [diff] [blame] | 823 | nf_ct_dump_tuple(&exp->tuple); |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 824 | } else |
| 825 | ret = -1; |
| 826 | } |
| 827 | |
Patrick McHardy | 6823645 | 2007-07-07 22:30:49 -0700 | [diff] [blame] | 828 | nf_ct_expect_put(exp); |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 829 | |
| 830 | return ret; |
| 831 | } |
| 832 | |
| 833 | /****************************************************************************/ |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 834 | static int process_setup(struct sk_buff *skb, struct nf_conn *ct, |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 835 | enum ip_conntrack_info ctinfo, |
| 836 | unsigned char **data, int dataoff, |
| 837 | Setup_UUIE *setup) |
| 838 | { |
| 839 | int dir = CTINFO2DIR(ctinfo); |
| 840 | int ret; |
| 841 | int i; |
| 842 | __be16 port; |
Jan Engelhardt | 643a2c1 | 2007-12-17 22:43:50 -0800 | [diff] [blame] | 843 | union nf_inet_addr addr; |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 844 | typeof(set_h225_addr_hook) set_h225_addr; |
| 845 | |
Patrick McHardy | 0d53778 | 2007-07-07 22:39:38 -0700 | [diff] [blame] | 846 | pr_debug("nf_ct_q931: Setup\n"); |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 847 | |
| 848 | if (setup->options & eSetup_UUIE_h245Address) { |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 849 | ret = expect_h245(skb, ct, ctinfo, data, dataoff, |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 850 | &setup->h245Address); |
| 851 | if (ret < 0) |
| 852 | return -1; |
| 853 | } |
| 854 | |
| 855 | set_h225_addr = rcu_dereference(set_h225_addr_hook); |
| 856 | if ((setup->options & eSetup_UUIE_destCallSignalAddress) && |
Roel Kluin | 6aebb9b | 2008-03-20 15:06:23 -0700 | [diff] [blame] | 857 | (set_h225_addr) && ct->status & IPS_NAT_MASK && |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 858 | get_h225_addr(ct, *data, &setup->destCallSignalAddress, |
YOSHIFUJI Hideaki | 601e68e | 2007-02-12 11:15:49 -0800 | [diff] [blame] | 859 | &addr, &port) && |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 860 | memcmp(&addr, &ct->tuplehash[!dir].tuple.src.u3, sizeof(addr))) { |
Harvey Harrison | 5b095d989 | 2008-10-29 12:52:50 -0700 | [diff] [blame] | 861 | pr_debug("nf_ct_q931: set destCallSignalAddress %pI6:%hu->%pI6:%hu\n", |
Harvey Harrison | 38ff4fa | 2008-10-28 16:08:13 -0700 | [diff] [blame] | 862 | &addr, ntohs(port), &ct->tuplehash[!dir].tuple.src.u3, |
Patrick McHardy | 0d53778 | 2007-07-07 22:39:38 -0700 | [diff] [blame] | 863 | ntohs(ct->tuplehash[!dir].tuple.src.u.tcp.port)); |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 864 | ret = set_h225_addr(skb, data, dataoff, |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 865 | &setup->destCallSignalAddress, |
| 866 | &ct->tuplehash[!dir].tuple.src.u3, |
| 867 | ct->tuplehash[!dir].tuple.src.u.tcp.port); |
| 868 | if (ret < 0) |
| 869 | return -1; |
| 870 | } |
| 871 | |
| 872 | if ((setup->options & eSetup_UUIE_sourceCallSignalAddress) && |
| 873 | (set_h225_addr) && ct->status & IPS_NAT_MASK && |
| 874 | get_h225_addr(ct, *data, &setup->sourceCallSignalAddress, |
YOSHIFUJI Hideaki | 601e68e | 2007-02-12 11:15:49 -0800 | [diff] [blame] | 875 | &addr, &port) && |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 876 | memcmp(&addr, &ct->tuplehash[!dir].tuple.dst.u3, sizeof(addr))) { |
Harvey Harrison | 5b095d989 | 2008-10-29 12:52:50 -0700 | [diff] [blame] | 877 | pr_debug("nf_ct_q931: set sourceCallSignalAddress %pI6:%hu->%pI6:%hu\n", |
Harvey Harrison | 38ff4fa | 2008-10-28 16:08:13 -0700 | [diff] [blame] | 878 | &addr, ntohs(port), &ct->tuplehash[!dir].tuple.dst.u3, |
Patrick McHardy | 0d53778 | 2007-07-07 22:39:38 -0700 | [diff] [blame] | 879 | ntohs(ct->tuplehash[!dir].tuple.dst.u.tcp.port)); |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 880 | ret = set_h225_addr(skb, data, dataoff, |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 881 | &setup->sourceCallSignalAddress, |
| 882 | &ct->tuplehash[!dir].tuple.dst.u3, |
| 883 | ct->tuplehash[!dir].tuple.dst.u.tcp.port); |
| 884 | if (ret < 0) |
| 885 | return -1; |
| 886 | } |
| 887 | |
| 888 | if (setup->options & eSetup_UUIE_fastStart) { |
| 889 | for (i = 0; i < setup->fastStart.count; i++) { |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 890 | ret = process_olc(skb, ct, ctinfo, data, dataoff, |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 891 | &setup->fastStart.item[i]); |
| 892 | if (ret < 0) |
| 893 | return -1; |
| 894 | } |
| 895 | } |
| 896 | |
| 897 | return 0; |
| 898 | } |
| 899 | |
| 900 | /****************************************************************************/ |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 901 | static int process_callproceeding(struct sk_buff *skb, |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 902 | struct nf_conn *ct, |
| 903 | enum ip_conntrack_info ctinfo, |
| 904 | unsigned char **data, int dataoff, |
| 905 | CallProceeding_UUIE *callproc) |
| 906 | { |
| 907 | int ret; |
| 908 | int i; |
| 909 | |
Patrick McHardy | 0d53778 | 2007-07-07 22:39:38 -0700 | [diff] [blame] | 910 | pr_debug("nf_ct_q931: CallProceeding\n"); |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 911 | |
| 912 | if (callproc->options & eCallProceeding_UUIE_h245Address) { |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 913 | ret = expect_h245(skb, ct, ctinfo, data, dataoff, |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 914 | &callproc->h245Address); |
| 915 | if (ret < 0) |
| 916 | return -1; |
| 917 | } |
| 918 | |
| 919 | if (callproc->options & eCallProceeding_UUIE_fastStart) { |
| 920 | for (i = 0; i < callproc->fastStart.count; i++) { |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 921 | ret = process_olc(skb, ct, ctinfo, data, dataoff, |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 922 | &callproc->fastStart.item[i]); |
| 923 | if (ret < 0) |
| 924 | return -1; |
| 925 | } |
| 926 | } |
| 927 | |
| 928 | return 0; |
| 929 | } |
| 930 | |
| 931 | /****************************************************************************/ |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 932 | static int process_connect(struct sk_buff *skb, struct nf_conn *ct, |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 933 | enum ip_conntrack_info ctinfo, |
| 934 | unsigned char **data, int dataoff, |
| 935 | Connect_UUIE *connect) |
| 936 | { |
| 937 | int ret; |
| 938 | int i; |
| 939 | |
Patrick McHardy | 0d53778 | 2007-07-07 22:39:38 -0700 | [diff] [blame] | 940 | pr_debug("nf_ct_q931: Connect\n"); |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 941 | |
| 942 | if (connect->options & eConnect_UUIE_h245Address) { |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 943 | ret = expect_h245(skb, ct, ctinfo, data, dataoff, |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 944 | &connect->h245Address); |
| 945 | if (ret < 0) |
| 946 | return -1; |
| 947 | } |
| 948 | |
| 949 | if (connect->options & eConnect_UUIE_fastStart) { |
| 950 | for (i = 0; i < connect->fastStart.count; i++) { |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 951 | ret = process_olc(skb, ct, ctinfo, data, dataoff, |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 952 | &connect->fastStart.item[i]); |
| 953 | if (ret < 0) |
| 954 | return -1; |
| 955 | } |
| 956 | } |
| 957 | |
| 958 | return 0; |
| 959 | } |
| 960 | |
| 961 | /****************************************************************************/ |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 962 | static int process_alerting(struct sk_buff *skb, struct nf_conn *ct, |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 963 | enum ip_conntrack_info ctinfo, |
| 964 | unsigned char **data, int dataoff, |
| 965 | Alerting_UUIE *alert) |
| 966 | { |
| 967 | int ret; |
| 968 | int i; |
| 969 | |
Patrick McHardy | 0d53778 | 2007-07-07 22:39:38 -0700 | [diff] [blame] | 970 | pr_debug("nf_ct_q931: Alerting\n"); |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 971 | |
| 972 | if (alert->options & eAlerting_UUIE_h245Address) { |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 973 | ret = expect_h245(skb, ct, ctinfo, data, dataoff, |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 974 | &alert->h245Address); |
| 975 | if (ret < 0) |
| 976 | return -1; |
| 977 | } |
| 978 | |
| 979 | if (alert->options & eAlerting_UUIE_fastStart) { |
| 980 | for (i = 0; i < alert->fastStart.count; i++) { |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 981 | ret = process_olc(skb, ct, ctinfo, data, dataoff, |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 982 | &alert->fastStart.item[i]); |
| 983 | if (ret < 0) |
| 984 | return -1; |
| 985 | } |
| 986 | } |
| 987 | |
| 988 | return 0; |
| 989 | } |
| 990 | |
| 991 | /****************************************************************************/ |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 992 | static int process_facility(struct sk_buff *skb, struct nf_conn *ct, |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 993 | enum ip_conntrack_info ctinfo, |
| 994 | unsigned char **data, int dataoff, |
| 995 | Facility_UUIE *facility) |
| 996 | { |
| 997 | int ret; |
| 998 | int i; |
| 999 | |
Patrick McHardy | 0d53778 | 2007-07-07 22:39:38 -0700 | [diff] [blame] | 1000 | pr_debug("nf_ct_q931: Facility\n"); |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1001 | |
| 1002 | if (facility->reason.choice == eFacilityReason_callForwarded) { |
| 1003 | if (facility->options & eFacility_UUIE_alternativeAddress) |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 1004 | return expect_callforwarding(skb, ct, ctinfo, data, |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1005 | dataoff, |
| 1006 | &facility-> |
| 1007 | alternativeAddress); |
| 1008 | return 0; |
| 1009 | } |
| 1010 | |
| 1011 | if (facility->options & eFacility_UUIE_h245Address) { |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 1012 | ret = expect_h245(skb, ct, ctinfo, data, dataoff, |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1013 | &facility->h245Address); |
| 1014 | if (ret < 0) |
| 1015 | return -1; |
| 1016 | } |
| 1017 | |
| 1018 | if (facility->options & eFacility_UUIE_fastStart) { |
| 1019 | for (i = 0; i < facility->fastStart.count; i++) { |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 1020 | ret = process_olc(skb, ct, ctinfo, data, dataoff, |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1021 | &facility->fastStart.item[i]); |
| 1022 | if (ret < 0) |
| 1023 | return -1; |
| 1024 | } |
| 1025 | } |
| 1026 | |
| 1027 | return 0; |
| 1028 | } |
| 1029 | |
| 1030 | /****************************************************************************/ |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 1031 | static int process_progress(struct sk_buff *skb, struct nf_conn *ct, |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1032 | enum ip_conntrack_info ctinfo, |
| 1033 | unsigned char **data, int dataoff, |
| 1034 | Progress_UUIE *progress) |
| 1035 | { |
| 1036 | int ret; |
| 1037 | int i; |
| 1038 | |
Patrick McHardy | 0d53778 | 2007-07-07 22:39:38 -0700 | [diff] [blame] | 1039 | pr_debug("nf_ct_q931: Progress\n"); |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1040 | |
| 1041 | if (progress->options & eProgress_UUIE_h245Address) { |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 1042 | ret = expect_h245(skb, ct, ctinfo, data, dataoff, |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1043 | &progress->h245Address); |
| 1044 | if (ret < 0) |
| 1045 | return -1; |
| 1046 | } |
| 1047 | |
| 1048 | if (progress->options & eProgress_UUIE_fastStart) { |
| 1049 | for (i = 0; i < progress->fastStart.count; i++) { |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 1050 | ret = process_olc(skb, ct, ctinfo, data, dataoff, |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1051 | &progress->fastStart.item[i]); |
| 1052 | if (ret < 0) |
| 1053 | return -1; |
| 1054 | } |
| 1055 | } |
| 1056 | |
| 1057 | return 0; |
| 1058 | } |
| 1059 | |
| 1060 | /****************************************************************************/ |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 1061 | static int process_q931(struct sk_buff *skb, struct nf_conn *ct, |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1062 | enum ip_conntrack_info ctinfo, |
| 1063 | unsigned char **data, int dataoff, Q931 *q931) |
| 1064 | { |
| 1065 | H323_UU_PDU *pdu = &q931->UUIE.h323_uu_pdu; |
| 1066 | int i; |
| 1067 | int ret = 0; |
| 1068 | |
| 1069 | switch (pdu->h323_message_body.choice) { |
| 1070 | case eH323_UU_PDU_h323_message_body_setup: |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 1071 | ret = process_setup(skb, ct, ctinfo, data, dataoff, |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1072 | &pdu->h323_message_body.setup); |
| 1073 | break; |
| 1074 | case eH323_UU_PDU_h323_message_body_callProceeding: |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 1075 | ret = process_callproceeding(skb, ct, ctinfo, data, dataoff, |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1076 | &pdu->h323_message_body. |
| 1077 | callProceeding); |
| 1078 | break; |
| 1079 | case eH323_UU_PDU_h323_message_body_connect: |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 1080 | ret = process_connect(skb, ct, ctinfo, data, dataoff, |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1081 | &pdu->h323_message_body.connect); |
| 1082 | break; |
| 1083 | case eH323_UU_PDU_h323_message_body_alerting: |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 1084 | ret = process_alerting(skb, ct, ctinfo, data, dataoff, |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1085 | &pdu->h323_message_body.alerting); |
| 1086 | break; |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1087 | case eH323_UU_PDU_h323_message_body_facility: |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 1088 | ret = process_facility(skb, ct, ctinfo, data, dataoff, |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1089 | &pdu->h323_message_body.facility); |
| 1090 | break; |
| 1091 | case eH323_UU_PDU_h323_message_body_progress: |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 1092 | ret = process_progress(skb, ct, ctinfo, data, dataoff, |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1093 | &pdu->h323_message_body.progress); |
| 1094 | break; |
| 1095 | default: |
Patrick McHardy | 0d53778 | 2007-07-07 22:39:38 -0700 | [diff] [blame] | 1096 | pr_debug("nf_ct_q931: Q.931 signal %d\n", |
| 1097 | pdu->h323_message_body.choice); |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1098 | break; |
| 1099 | } |
| 1100 | |
| 1101 | if (ret < 0) |
| 1102 | return -1; |
| 1103 | |
| 1104 | if (pdu->options & eH323_UU_PDU_h245Control) { |
| 1105 | for (i = 0; i < pdu->h245Control.count; i++) { |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 1106 | ret = process_h245(skb, ct, ctinfo, data, dataoff, |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1107 | &pdu->h245Control.item[i]); |
| 1108 | if (ret < 0) |
| 1109 | return -1; |
| 1110 | } |
| 1111 | } |
| 1112 | |
| 1113 | return 0; |
| 1114 | } |
| 1115 | |
| 1116 | /****************************************************************************/ |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 1117 | static int q931_help(struct sk_buff *skb, unsigned int protoff, |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1118 | struct nf_conn *ct, enum ip_conntrack_info ctinfo) |
| 1119 | { |
| 1120 | static Q931 q931; |
| 1121 | unsigned char *data = NULL; |
| 1122 | int datalen; |
| 1123 | int dataoff; |
| 1124 | int ret; |
| 1125 | |
| 1126 | /* Until there's been traffic both ways, don't look in packets. */ |
Eric Dumazet | fb04883 | 2011-05-19 15:44:27 +0200 | [diff] [blame] | 1127 | if (ctinfo != IP_CT_ESTABLISHED && ctinfo != IP_CT_ESTABLISHED_REPLY) |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1128 | return NF_ACCEPT; |
Eric Dumazet | fb04883 | 2011-05-19 15:44:27 +0200 | [diff] [blame] | 1129 | |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 1130 | pr_debug("nf_ct_q931: skblen = %u\n", skb->len); |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1131 | |
| 1132 | spin_lock_bh(&nf_h323_lock); |
| 1133 | |
| 1134 | /* Process each TPKT */ |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 1135 | while (get_tpkt_data(skb, protoff, ct, ctinfo, |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1136 | &data, &datalen, &dataoff)) { |
Patrick McHardy | 0d53778 | 2007-07-07 22:39:38 -0700 | [diff] [blame] | 1137 | pr_debug("nf_ct_q931: TPKT len=%d ", datalen); |
Jan Engelhardt | 3c9fba6 | 2008-04-14 11:15:54 +0200 | [diff] [blame] | 1138 | nf_ct_dump_tuple(&ct->tuplehash[CTINFO2DIR(ctinfo)].tuple); |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1139 | |
| 1140 | /* Decode Q.931 signal */ |
| 1141 | ret = DecodeQ931(data, datalen, &q931); |
| 1142 | if (ret < 0) { |
Patrick McHardy | 0d53778 | 2007-07-07 22:39:38 -0700 | [diff] [blame] | 1143 | pr_debug("nf_ct_q931: decoding error: %s\n", |
| 1144 | ret == H323_ERROR_BOUND ? |
| 1145 | "out of bound" : "out of range"); |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1146 | /* We don't drop when decoding error */ |
| 1147 | break; |
| 1148 | } |
| 1149 | |
| 1150 | /* Process Q.931 signal */ |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 1151 | if (process_q931(skb, ct, ctinfo, &data, dataoff, &q931) < 0) |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1152 | goto drop; |
| 1153 | } |
| 1154 | |
| 1155 | spin_unlock_bh(&nf_h323_lock); |
| 1156 | return NF_ACCEPT; |
| 1157 | |
| 1158 | drop: |
| 1159 | spin_unlock_bh(&nf_h323_lock); |
| 1160 | if (net_ratelimit()) |
Stephen Hemminger | 654d0fb | 2010-05-13 15:02:08 +0200 | [diff] [blame] | 1161 | pr_info("nf_ct_q931: packet dropped\n"); |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1162 | return NF_DROP; |
| 1163 | } |
| 1164 | |
| 1165 | /****************************************************************************/ |
Patrick McHardy | 6002f26 | 2008-03-25 20:09:15 -0700 | [diff] [blame] | 1166 | static const struct nf_conntrack_expect_policy q931_exp_policy = { |
| 1167 | /* T.120 and H.245 */ |
| 1168 | .max_expected = H323_RTP_CHANNEL_MAX * 4 + 4, |
| 1169 | .timeout = 240, |
| 1170 | }; |
| 1171 | |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1172 | static struct nf_conntrack_helper nf_conntrack_helper_q931[] __read_mostly = { |
| 1173 | { |
| 1174 | .name = "Q.931", |
| 1175 | .me = THIS_MODULE, |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1176 | .tuple.src.l3num = AF_INET, |
Harvey Harrison | 09640e6 | 2009-02-01 00:45:17 -0800 | [diff] [blame] | 1177 | .tuple.src.u.tcp.port = cpu_to_be16(Q931_PORT), |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1178 | .tuple.dst.protonum = IPPROTO_TCP, |
Patrick McHardy | 6002f26 | 2008-03-25 20:09:15 -0700 | [diff] [blame] | 1179 | .help = q931_help, |
| 1180 | .expect_policy = &q931_exp_policy, |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1181 | }, |
| 1182 | { |
| 1183 | .name = "Q.931", |
| 1184 | .me = THIS_MODULE, |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1185 | .tuple.src.l3num = AF_INET6, |
Harvey Harrison | 09640e6 | 2009-02-01 00:45:17 -0800 | [diff] [blame] | 1186 | .tuple.src.u.tcp.port = cpu_to_be16(Q931_PORT), |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1187 | .tuple.dst.protonum = IPPROTO_TCP, |
Patrick McHardy | 6002f26 | 2008-03-25 20:09:15 -0700 | [diff] [blame] | 1188 | .help = q931_help, |
| 1189 | .expect_policy = &q931_exp_policy, |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1190 | }, |
| 1191 | }; |
| 1192 | |
| 1193 | /****************************************************************************/ |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 1194 | static unsigned char *get_udp_data(struct sk_buff *skb, unsigned int protoff, |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1195 | int *datalen) |
| 1196 | { |
Jan Engelhardt | 905e3e8 | 2008-01-31 04:50:05 -0800 | [diff] [blame] | 1197 | const struct udphdr *uh; |
| 1198 | struct udphdr _uh; |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1199 | int dataoff; |
| 1200 | |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 1201 | uh = skb_header_pointer(skb, protoff, sizeof(_uh), &_uh); |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1202 | if (uh == NULL) |
| 1203 | return NULL; |
| 1204 | dataoff = protoff + sizeof(_uh); |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 1205 | if (dataoff >= skb->len) |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1206 | return NULL; |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 1207 | *datalen = skb->len - dataoff; |
| 1208 | return skb_header_pointer(skb, dataoff, *datalen, h323_buffer); |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1209 | } |
| 1210 | |
| 1211 | /****************************************************************************/ |
| 1212 | static struct nf_conntrack_expect *find_expect(struct nf_conn *ct, |
Jan Engelhardt | 643a2c1 | 2007-12-17 22:43:50 -0800 | [diff] [blame] | 1213 | union nf_inet_addr *addr, |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1214 | __be16 port) |
| 1215 | { |
Alexey Dobriyan | 84541cc | 2008-10-08 11:35:09 +0200 | [diff] [blame] | 1216 | struct net *net = nf_ct_net(ct); |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1217 | struct nf_conntrack_expect *exp; |
| 1218 | struct nf_conntrack_tuple tuple; |
| 1219 | |
| 1220 | memset(&tuple.src.u3, 0, sizeof(tuple.src.u3)); |
| 1221 | tuple.src.u.tcp.port = 0; |
| 1222 | memcpy(&tuple.dst.u3, addr, sizeof(tuple.dst.u3)); |
| 1223 | tuple.dst.u.tcp.port = port; |
| 1224 | tuple.dst.protonum = IPPROTO_TCP; |
| 1225 | |
Patrick McHardy | 5d0aa2c | 2010-02-15 18:13:33 +0100 | [diff] [blame] | 1226 | exp = __nf_ct_expect_find(net, nf_ct_zone(ct), &tuple); |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1227 | if (exp && exp->master == ct) |
| 1228 | return exp; |
| 1229 | return NULL; |
| 1230 | } |
| 1231 | |
| 1232 | /****************************************************************************/ |
| 1233 | static int set_expect_timeout(struct nf_conntrack_expect *exp, |
| 1234 | unsigned timeout) |
| 1235 | { |
| 1236 | if (!exp || !del_timer(&exp->timeout)) |
| 1237 | return 0; |
| 1238 | |
| 1239 | exp->timeout.expires = jiffies + timeout * HZ; |
| 1240 | add_timer(&exp->timeout); |
| 1241 | |
| 1242 | return 1; |
| 1243 | } |
| 1244 | |
| 1245 | /****************************************************************************/ |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 1246 | static int expect_q931(struct sk_buff *skb, struct nf_conn *ct, |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1247 | enum ip_conntrack_info ctinfo, |
| 1248 | unsigned char **data, |
| 1249 | TransportAddress *taddr, int count) |
| 1250 | { |
| 1251 | struct nf_ct_h323_master *info = &nfct_help(ct)->help.ct_h323_info; |
| 1252 | int dir = CTINFO2DIR(ctinfo); |
| 1253 | int ret = 0; |
| 1254 | int i; |
| 1255 | __be16 port; |
Jan Engelhardt | 643a2c1 | 2007-12-17 22:43:50 -0800 | [diff] [blame] | 1256 | union nf_inet_addr addr; |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1257 | struct nf_conntrack_expect *exp; |
| 1258 | typeof(nat_q931_hook) nat_q931; |
| 1259 | |
| 1260 | /* Look for the first related address */ |
| 1261 | for (i = 0; i < count; i++) { |
| 1262 | if (get_h225_addr(ct, *data, &taddr[i], &addr, &port) && |
| 1263 | memcmp(&addr, &ct->tuplehash[dir].tuple.src.u3, |
YOSHIFUJI Hideaki | 601e68e | 2007-02-12 11:15:49 -0800 | [diff] [blame] | 1264 | sizeof(addr)) == 0 && port != 0) |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1265 | break; |
| 1266 | } |
| 1267 | |
| 1268 | if (i >= count) /* Not found */ |
| 1269 | return 0; |
| 1270 | |
| 1271 | /* Create expect for Q.931 */ |
Patrick McHardy | 6823645 | 2007-07-07 22:30:49 -0700 | [diff] [blame] | 1272 | if ((exp = nf_ct_expect_alloc(ct)) == NULL) |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1273 | return -1; |
Patrick McHardy | 5e8fbe2 | 2008-04-14 11:15:52 +0200 | [diff] [blame] | 1274 | nf_ct_expect_init(exp, NF_CT_EXPECT_CLASS_DEFAULT, nf_ct_l3num(ct), |
Patrick McHardy | 6823645 | 2007-07-07 22:30:49 -0700 | [diff] [blame] | 1275 | gkrouted_only ? /* only accept calls from GK? */ |
| 1276 | &ct->tuplehash[!dir].tuple.src.u3 : NULL, |
| 1277 | &ct->tuplehash[!dir].tuple.dst.u3, |
| 1278 | IPPROTO_TCP, NULL, &port); |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1279 | exp->helper = nf_conntrack_helper_q931; |
| 1280 | exp->flags = NF_CT_EXPECT_PERMANENT; /* Accept multiple calls */ |
| 1281 | |
| 1282 | nat_q931 = rcu_dereference(nat_q931_hook); |
| 1283 | if (nat_q931 && ct->status & IPS_NAT_MASK) { /* Need NAT */ |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 1284 | ret = nat_q931(skb, ct, ctinfo, data, taddr, i, port, exp); |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1285 | } else { /* Conntrack only */ |
Patrick McHardy | 6823645 | 2007-07-07 22:30:49 -0700 | [diff] [blame] | 1286 | if (nf_ct_expect_related(exp) == 0) { |
Patrick McHardy | 0d53778 | 2007-07-07 22:39:38 -0700 | [diff] [blame] | 1287 | pr_debug("nf_ct_ras: expect Q.931 "); |
Jan Engelhardt | 3c9fba6 | 2008-04-14 11:15:54 +0200 | [diff] [blame] | 1288 | nf_ct_dump_tuple(&exp->tuple); |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1289 | |
| 1290 | /* Save port for looking up expect in processing RCF */ |
| 1291 | info->sig_port[dir] = port; |
| 1292 | } else |
| 1293 | ret = -1; |
| 1294 | } |
| 1295 | |
Patrick McHardy | 6823645 | 2007-07-07 22:30:49 -0700 | [diff] [blame] | 1296 | nf_ct_expect_put(exp); |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1297 | |
| 1298 | return ret; |
| 1299 | } |
| 1300 | |
| 1301 | /****************************************************************************/ |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 1302 | static int process_grq(struct sk_buff *skb, struct nf_conn *ct, |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1303 | enum ip_conntrack_info ctinfo, |
| 1304 | unsigned char **data, GatekeeperRequest *grq) |
| 1305 | { |
| 1306 | typeof(set_ras_addr_hook) set_ras_addr; |
| 1307 | |
Patrick McHardy | 0d53778 | 2007-07-07 22:39:38 -0700 | [diff] [blame] | 1308 | pr_debug("nf_ct_ras: GRQ\n"); |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1309 | |
| 1310 | set_ras_addr = rcu_dereference(set_ras_addr_hook); |
| 1311 | if (set_ras_addr && ct->status & IPS_NAT_MASK) /* NATed */ |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 1312 | return set_ras_addr(skb, ct, ctinfo, data, |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1313 | &grq->rasAddress, 1); |
| 1314 | return 0; |
| 1315 | } |
| 1316 | |
| 1317 | /****************************************************************************/ |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 1318 | static int process_gcf(struct sk_buff *skb, struct nf_conn *ct, |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1319 | enum ip_conntrack_info ctinfo, |
| 1320 | unsigned char **data, GatekeeperConfirm *gcf) |
| 1321 | { |
| 1322 | int dir = CTINFO2DIR(ctinfo); |
| 1323 | int ret = 0; |
| 1324 | __be16 port; |
Jan Engelhardt | 643a2c1 | 2007-12-17 22:43:50 -0800 | [diff] [blame] | 1325 | union nf_inet_addr addr; |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1326 | struct nf_conntrack_expect *exp; |
| 1327 | |
Patrick McHardy | 0d53778 | 2007-07-07 22:39:38 -0700 | [diff] [blame] | 1328 | pr_debug("nf_ct_ras: GCF\n"); |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1329 | |
| 1330 | if (!get_h225_addr(ct, *data, &gcf->rasAddress, &addr, &port)) |
| 1331 | return 0; |
| 1332 | |
| 1333 | /* Registration port is the same as discovery port */ |
| 1334 | if (!memcmp(&addr, &ct->tuplehash[dir].tuple.src.u3, sizeof(addr)) && |
| 1335 | port == ct->tuplehash[dir].tuple.src.u.udp.port) |
| 1336 | return 0; |
| 1337 | |
| 1338 | /* Avoid RAS expectation loops. A GCF is never expected. */ |
| 1339 | if (test_bit(IPS_EXPECTED_BIT, &ct->status)) |
| 1340 | return 0; |
| 1341 | |
| 1342 | /* Need new expect */ |
Patrick McHardy | 6823645 | 2007-07-07 22:30:49 -0700 | [diff] [blame] | 1343 | if ((exp = nf_ct_expect_alloc(ct)) == NULL) |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1344 | return -1; |
Patrick McHardy | 5e8fbe2 | 2008-04-14 11:15:52 +0200 | [diff] [blame] | 1345 | nf_ct_expect_init(exp, NF_CT_EXPECT_CLASS_DEFAULT, nf_ct_l3num(ct), |
Patrick McHardy | 6823645 | 2007-07-07 22:30:49 -0700 | [diff] [blame] | 1346 | &ct->tuplehash[!dir].tuple.src.u3, &addr, |
| 1347 | IPPROTO_UDP, NULL, &port); |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1348 | exp->helper = nf_conntrack_helper_ras; |
| 1349 | |
Patrick McHardy | 6823645 | 2007-07-07 22:30:49 -0700 | [diff] [blame] | 1350 | if (nf_ct_expect_related(exp) == 0) { |
Patrick McHardy | 0d53778 | 2007-07-07 22:39:38 -0700 | [diff] [blame] | 1351 | pr_debug("nf_ct_ras: expect RAS "); |
Jan Engelhardt | 3c9fba6 | 2008-04-14 11:15:54 +0200 | [diff] [blame] | 1352 | nf_ct_dump_tuple(&exp->tuple); |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1353 | } else |
| 1354 | ret = -1; |
| 1355 | |
Patrick McHardy | 6823645 | 2007-07-07 22:30:49 -0700 | [diff] [blame] | 1356 | nf_ct_expect_put(exp); |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1357 | |
| 1358 | return ret; |
| 1359 | } |
| 1360 | |
| 1361 | /****************************************************************************/ |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 1362 | static int process_rrq(struct sk_buff *skb, struct nf_conn *ct, |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1363 | enum ip_conntrack_info ctinfo, |
| 1364 | unsigned char **data, RegistrationRequest *rrq) |
| 1365 | { |
| 1366 | struct nf_ct_h323_master *info = &nfct_help(ct)->help.ct_h323_info; |
| 1367 | int ret; |
| 1368 | typeof(set_ras_addr_hook) set_ras_addr; |
| 1369 | |
Patrick McHardy | 0d53778 | 2007-07-07 22:39:38 -0700 | [diff] [blame] | 1370 | pr_debug("nf_ct_ras: RRQ\n"); |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1371 | |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 1372 | ret = expect_q931(skb, ct, ctinfo, data, |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1373 | rrq->callSignalAddress.item, |
| 1374 | rrq->callSignalAddress.count); |
| 1375 | if (ret < 0) |
| 1376 | return -1; |
| 1377 | |
| 1378 | set_ras_addr = rcu_dereference(set_ras_addr_hook); |
| 1379 | if (set_ras_addr && ct->status & IPS_NAT_MASK) { |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 1380 | ret = set_ras_addr(skb, ct, ctinfo, data, |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1381 | rrq->rasAddress.item, |
| 1382 | rrq->rasAddress.count); |
| 1383 | if (ret < 0) |
| 1384 | return -1; |
| 1385 | } |
| 1386 | |
| 1387 | if (rrq->options & eRegistrationRequest_timeToLive) { |
Patrick McHardy | 0d53778 | 2007-07-07 22:39:38 -0700 | [diff] [blame] | 1388 | pr_debug("nf_ct_ras: RRQ TTL = %u seconds\n", rrq->timeToLive); |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1389 | info->timeout = rrq->timeToLive; |
| 1390 | } else |
| 1391 | info->timeout = default_rrq_ttl; |
| 1392 | |
| 1393 | return 0; |
| 1394 | } |
| 1395 | |
| 1396 | /****************************************************************************/ |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 1397 | static int process_rcf(struct sk_buff *skb, struct nf_conn *ct, |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1398 | enum ip_conntrack_info ctinfo, |
| 1399 | unsigned char **data, RegistrationConfirm *rcf) |
| 1400 | { |
| 1401 | struct nf_ct_h323_master *info = &nfct_help(ct)->help.ct_h323_info; |
| 1402 | int dir = CTINFO2DIR(ctinfo); |
| 1403 | int ret; |
| 1404 | struct nf_conntrack_expect *exp; |
| 1405 | typeof(set_sig_addr_hook) set_sig_addr; |
| 1406 | |
Patrick McHardy | 0d53778 | 2007-07-07 22:39:38 -0700 | [diff] [blame] | 1407 | pr_debug("nf_ct_ras: RCF\n"); |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1408 | |
| 1409 | set_sig_addr = rcu_dereference(set_sig_addr_hook); |
| 1410 | if (set_sig_addr && ct->status & IPS_NAT_MASK) { |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 1411 | ret = set_sig_addr(skb, ct, ctinfo, data, |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1412 | rcf->callSignalAddress.item, |
| 1413 | rcf->callSignalAddress.count); |
| 1414 | if (ret < 0) |
| 1415 | return -1; |
| 1416 | } |
| 1417 | |
| 1418 | if (rcf->options & eRegistrationConfirm_timeToLive) { |
Patrick McHardy | 0d53778 | 2007-07-07 22:39:38 -0700 | [diff] [blame] | 1419 | pr_debug("nf_ct_ras: RCF TTL = %u seconds\n", rcf->timeToLive); |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1420 | info->timeout = rcf->timeToLive; |
| 1421 | } |
| 1422 | |
| 1423 | if (info->timeout > 0) { |
Patrick McHardy | 0d53778 | 2007-07-07 22:39:38 -0700 | [diff] [blame] | 1424 | pr_debug("nf_ct_ras: set RAS connection timeout to " |
| 1425 | "%u seconds\n", info->timeout); |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 1426 | nf_ct_refresh(ct, skb, info->timeout * HZ); |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1427 | |
| 1428 | /* Set expect timeout */ |
Patrick McHardy | f8ba1af | 2008-01-31 04:38:58 -0800 | [diff] [blame] | 1429 | spin_lock_bh(&nf_conntrack_lock); |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1430 | exp = find_expect(ct, &ct->tuplehash[dir].tuple.dst.u3, |
| 1431 | info->sig_port[!dir]); |
| 1432 | if (exp) { |
Patrick McHardy | 0d53778 | 2007-07-07 22:39:38 -0700 | [diff] [blame] | 1433 | pr_debug("nf_ct_ras: set Q.931 expect " |
| 1434 | "timeout to %u seconds for", |
| 1435 | info->timeout); |
Jan Engelhardt | 3c9fba6 | 2008-04-14 11:15:54 +0200 | [diff] [blame] | 1436 | nf_ct_dump_tuple(&exp->tuple); |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1437 | set_expect_timeout(exp, info->timeout); |
| 1438 | } |
Patrick McHardy | f8ba1af | 2008-01-31 04:38:58 -0800 | [diff] [blame] | 1439 | spin_unlock_bh(&nf_conntrack_lock); |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1440 | } |
| 1441 | |
| 1442 | return 0; |
| 1443 | } |
| 1444 | |
| 1445 | /****************************************************************************/ |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 1446 | static int process_urq(struct sk_buff *skb, struct nf_conn *ct, |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1447 | enum ip_conntrack_info ctinfo, |
| 1448 | unsigned char **data, UnregistrationRequest *urq) |
| 1449 | { |
| 1450 | struct nf_ct_h323_master *info = &nfct_help(ct)->help.ct_h323_info; |
| 1451 | int dir = CTINFO2DIR(ctinfo); |
| 1452 | int ret; |
| 1453 | typeof(set_sig_addr_hook) set_sig_addr; |
| 1454 | |
Patrick McHardy | 0d53778 | 2007-07-07 22:39:38 -0700 | [diff] [blame] | 1455 | pr_debug("nf_ct_ras: URQ\n"); |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1456 | |
| 1457 | set_sig_addr = rcu_dereference(set_sig_addr_hook); |
| 1458 | if (set_sig_addr && ct->status & IPS_NAT_MASK) { |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 1459 | ret = set_sig_addr(skb, ct, ctinfo, data, |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1460 | urq->callSignalAddress.item, |
| 1461 | urq->callSignalAddress.count); |
| 1462 | if (ret < 0) |
| 1463 | return -1; |
| 1464 | } |
| 1465 | |
| 1466 | /* Clear old expect */ |
| 1467 | nf_ct_remove_expectations(ct); |
| 1468 | info->sig_port[dir] = 0; |
| 1469 | info->sig_port[!dir] = 0; |
| 1470 | |
| 1471 | /* Give it 30 seconds for UCF or URJ */ |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 1472 | nf_ct_refresh(ct, skb, 30 * HZ); |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1473 | |
| 1474 | return 0; |
| 1475 | } |
| 1476 | |
| 1477 | /****************************************************************************/ |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 1478 | static int process_arq(struct sk_buff *skb, struct nf_conn *ct, |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1479 | enum ip_conntrack_info ctinfo, |
| 1480 | unsigned char **data, AdmissionRequest *arq) |
| 1481 | { |
Jan Engelhardt | 905e3e8 | 2008-01-31 04:50:05 -0800 | [diff] [blame] | 1482 | const struct nf_ct_h323_master *info = &nfct_help(ct)->help.ct_h323_info; |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1483 | int dir = CTINFO2DIR(ctinfo); |
| 1484 | __be16 port; |
Jan Engelhardt | 643a2c1 | 2007-12-17 22:43:50 -0800 | [diff] [blame] | 1485 | union nf_inet_addr addr; |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1486 | typeof(set_h225_addr_hook) set_h225_addr; |
| 1487 | |
Patrick McHardy | 0d53778 | 2007-07-07 22:39:38 -0700 | [diff] [blame] | 1488 | pr_debug("nf_ct_ras: ARQ\n"); |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1489 | |
| 1490 | set_h225_addr = rcu_dereference(set_h225_addr_hook); |
| 1491 | if ((arq->options & eAdmissionRequest_destCallSignalAddress) && |
| 1492 | get_h225_addr(ct, *data, &arq->destCallSignalAddress, |
YOSHIFUJI Hideaki | 601e68e | 2007-02-12 11:15:49 -0800 | [diff] [blame] | 1493 | &addr, &port) && |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1494 | !memcmp(&addr, &ct->tuplehash[dir].tuple.src.u3, sizeof(addr)) && |
| 1495 | port == info->sig_port[dir] && |
| 1496 | set_h225_addr && ct->status & IPS_NAT_MASK) { |
| 1497 | /* Answering ARQ */ |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 1498 | return set_h225_addr(skb, data, 0, |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1499 | &arq->destCallSignalAddress, |
| 1500 | &ct->tuplehash[!dir].tuple.dst.u3, |
| 1501 | info->sig_port[!dir]); |
| 1502 | } |
| 1503 | |
| 1504 | if ((arq->options & eAdmissionRequest_srcCallSignalAddress) && |
| 1505 | get_h225_addr(ct, *data, &arq->srcCallSignalAddress, |
YOSHIFUJI Hideaki | 601e68e | 2007-02-12 11:15:49 -0800 | [diff] [blame] | 1506 | &addr, &port) && |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1507 | !memcmp(&addr, &ct->tuplehash[dir].tuple.src.u3, sizeof(addr)) && |
| 1508 | set_h225_addr && ct->status & IPS_NAT_MASK) { |
| 1509 | /* Calling ARQ */ |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 1510 | return set_h225_addr(skb, data, 0, |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1511 | &arq->srcCallSignalAddress, |
| 1512 | &ct->tuplehash[!dir].tuple.dst.u3, |
| 1513 | port); |
| 1514 | } |
| 1515 | |
| 1516 | return 0; |
| 1517 | } |
| 1518 | |
| 1519 | /****************************************************************************/ |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 1520 | static int process_acf(struct sk_buff *skb, struct nf_conn *ct, |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1521 | enum ip_conntrack_info ctinfo, |
| 1522 | unsigned char **data, AdmissionConfirm *acf) |
| 1523 | { |
| 1524 | int dir = CTINFO2DIR(ctinfo); |
| 1525 | int ret = 0; |
| 1526 | __be16 port; |
Jan Engelhardt | 643a2c1 | 2007-12-17 22:43:50 -0800 | [diff] [blame] | 1527 | union nf_inet_addr addr; |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1528 | struct nf_conntrack_expect *exp; |
| 1529 | typeof(set_sig_addr_hook) set_sig_addr; |
| 1530 | |
Patrick McHardy | 0d53778 | 2007-07-07 22:39:38 -0700 | [diff] [blame] | 1531 | pr_debug("nf_ct_ras: ACF\n"); |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1532 | |
| 1533 | if (!get_h225_addr(ct, *data, &acf->destCallSignalAddress, |
| 1534 | &addr, &port)) |
| 1535 | return 0; |
| 1536 | |
| 1537 | if (!memcmp(&addr, &ct->tuplehash[dir].tuple.dst.u3, sizeof(addr))) { |
| 1538 | /* Answering ACF */ |
| 1539 | set_sig_addr = rcu_dereference(set_sig_addr_hook); |
| 1540 | if (set_sig_addr && ct->status & IPS_NAT_MASK) |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 1541 | return set_sig_addr(skb, ct, ctinfo, data, |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1542 | &acf->destCallSignalAddress, 1); |
| 1543 | return 0; |
| 1544 | } |
| 1545 | |
| 1546 | /* Need new expect */ |
Patrick McHardy | 6823645 | 2007-07-07 22:30:49 -0700 | [diff] [blame] | 1547 | if ((exp = nf_ct_expect_alloc(ct)) == NULL) |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1548 | return -1; |
Patrick McHardy | 5e8fbe2 | 2008-04-14 11:15:52 +0200 | [diff] [blame] | 1549 | nf_ct_expect_init(exp, NF_CT_EXPECT_CLASS_DEFAULT, nf_ct_l3num(ct), |
Patrick McHardy | 6823645 | 2007-07-07 22:30:49 -0700 | [diff] [blame] | 1550 | &ct->tuplehash[!dir].tuple.src.u3, &addr, |
| 1551 | IPPROTO_TCP, NULL, &port); |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1552 | exp->flags = NF_CT_EXPECT_PERMANENT; |
| 1553 | exp->helper = nf_conntrack_helper_q931; |
| 1554 | |
Patrick McHardy | 6823645 | 2007-07-07 22:30:49 -0700 | [diff] [blame] | 1555 | if (nf_ct_expect_related(exp) == 0) { |
Patrick McHardy | 0d53778 | 2007-07-07 22:39:38 -0700 | [diff] [blame] | 1556 | pr_debug("nf_ct_ras: expect Q.931 "); |
Jan Engelhardt | 3c9fba6 | 2008-04-14 11:15:54 +0200 | [diff] [blame] | 1557 | nf_ct_dump_tuple(&exp->tuple); |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1558 | } else |
| 1559 | ret = -1; |
| 1560 | |
Patrick McHardy | 6823645 | 2007-07-07 22:30:49 -0700 | [diff] [blame] | 1561 | nf_ct_expect_put(exp); |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1562 | |
| 1563 | return ret; |
| 1564 | } |
| 1565 | |
| 1566 | /****************************************************************************/ |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 1567 | static int process_lrq(struct sk_buff *skb, struct nf_conn *ct, |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1568 | enum ip_conntrack_info ctinfo, |
| 1569 | unsigned char **data, LocationRequest *lrq) |
| 1570 | { |
| 1571 | typeof(set_ras_addr_hook) set_ras_addr; |
| 1572 | |
Patrick McHardy | 0d53778 | 2007-07-07 22:39:38 -0700 | [diff] [blame] | 1573 | pr_debug("nf_ct_ras: LRQ\n"); |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1574 | |
| 1575 | set_ras_addr = rcu_dereference(set_ras_addr_hook); |
| 1576 | if (set_ras_addr && ct->status & IPS_NAT_MASK) |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 1577 | return set_ras_addr(skb, ct, ctinfo, data, |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1578 | &lrq->replyAddress, 1); |
| 1579 | return 0; |
| 1580 | } |
| 1581 | |
| 1582 | /****************************************************************************/ |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 1583 | static int process_lcf(struct sk_buff *skb, struct nf_conn *ct, |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1584 | enum ip_conntrack_info ctinfo, |
| 1585 | unsigned char **data, LocationConfirm *lcf) |
| 1586 | { |
| 1587 | int dir = CTINFO2DIR(ctinfo); |
| 1588 | int ret = 0; |
| 1589 | __be16 port; |
Jan Engelhardt | 643a2c1 | 2007-12-17 22:43:50 -0800 | [diff] [blame] | 1590 | union nf_inet_addr addr; |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1591 | struct nf_conntrack_expect *exp; |
| 1592 | |
Patrick McHardy | 0d53778 | 2007-07-07 22:39:38 -0700 | [diff] [blame] | 1593 | pr_debug("nf_ct_ras: LCF\n"); |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1594 | |
| 1595 | if (!get_h225_addr(ct, *data, &lcf->callSignalAddress, |
| 1596 | &addr, &port)) |
| 1597 | return 0; |
| 1598 | |
| 1599 | /* Need new expect for call signal */ |
Patrick McHardy | 6823645 | 2007-07-07 22:30:49 -0700 | [diff] [blame] | 1600 | if ((exp = nf_ct_expect_alloc(ct)) == NULL) |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1601 | return -1; |
Patrick McHardy | 5e8fbe2 | 2008-04-14 11:15:52 +0200 | [diff] [blame] | 1602 | nf_ct_expect_init(exp, NF_CT_EXPECT_CLASS_DEFAULT, nf_ct_l3num(ct), |
Patrick McHardy | 6823645 | 2007-07-07 22:30:49 -0700 | [diff] [blame] | 1603 | &ct->tuplehash[!dir].tuple.src.u3, &addr, |
| 1604 | IPPROTO_TCP, NULL, &port); |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1605 | exp->flags = NF_CT_EXPECT_PERMANENT; |
| 1606 | exp->helper = nf_conntrack_helper_q931; |
| 1607 | |
Patrick McHardy | 6823645 | 2007-07-07 22:30:49 -0700 | [diff] [blame] | 1608 | if (nf_ct_expect_related(exp) == 0) { |
Patrick McHardy | 0d53778 | 2007-07-07 22:39:38 -0700 | [diff] [blame] | 1609 | pr_debug("nf_ct_ras: expect Q.931 "); |
Jan Engelhardt | 3c9fba6 | 2008-04-14 11:15:54 +0200 | [diff] [blame] | 1610 | nf_ct_dump_tuple(&exp->tuple); |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1611 | } else |
| 1612 | ret = -1; |
| 1613 | |
Patrick McHardy | 6823645 | 2007-07-07 22:30:49 -0700 | [diff] [blame] | 1614 | nf_ct_expect_put(exp); |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1615 | |
| 1616 | /* Ignore rasAddress */ |
| 1617 | |
| 1618 | return ret; |
| 1619 | } |
| 1620 | |
| 1621 | /****************************************************************************/ |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 1622 | static int process_irr(struct sk_buff *skb, struct nf_conn *ct, |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1623 | enum ip_conntrack_info ctinfo, |
| 1624 | unsigned char **data, InfoRequestResponse *irr) |
| 1625 | { |
| 1626 | int ret; |
| 1627 | typeof(set_ras_addr_hook) set_ras_addr; |
| 1628 | typeof(set_sig_addr_hook) set_sig_addr; |
| 1629 | |
Patrick McHardy | 0d53778 | 2007-07-07 22:39:38 -0700 | [diff] [blame] | 1630 | pr_debug("nf_ct_ras: IRR\n"); |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1631 | |
| 1632 | set_ras_addr = rcu_dereference(set_ras_addr_hook); |
| 1633 | if (set_ras_addr && ct->status & IPS_NAT_MASK) { |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 1634 | ret = set_ras_addr(skb, ct, ctinfo, data, |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1635 | &irr->rasAddress, 1); |
| 1636 | if (ret < 0) |
| 1637 | return -1; |
| 1638 | } |
| 1639 | |
| 1640 | set_sig_addr = rcu_dereference(set_sig_addr_hook); |
| 1641 | if (set_sig_addr && ct->status & IPS_NAT_MASK) { |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 1642 | ret = set_sig_addr(skb, ct, ctinfo, data, |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1643 | irr->callSignalAddress.item, |
| 1644 | irr->callSignalAddress.count); |
| 1645 | if (ret < 0) |
| 1646 | return -1; |
| 1647 | } |
| 1648 | |
| 1649 | return 0; |
| 1650 | } |
| 1651 | |
| 1652 | /****************************************************************************/ |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 1653 | static int process_ras(struct sk_buff *skb, struct nf_conn *ct, |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1654 | enum ip_conntrack_info ctinfo, |
| 1655 | unsigned char **data, RasMessage *ras) |
| 1656 | { |
| 1657 | switch (ras->choice) { |
| 1658 | case eRasMessage_gatekeeperRequest: |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 1659 | return process_grq(skb, ct, ctinfo, data, |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1660 | &ras->gatekeeperRequest); |
| 1661 | case eRasMessage_gatekeeperConfirm: |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 1662 | return process_gcf(skb, ct, ctinfo, data, |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1663 | &ras->gatekeeperConfirm); |
| 1664 | case eRasMessage_registrationRequest: |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 1665 | return process_rrq(skb, ct, ctinfo, data, |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1666 | &ras->registrationRequest); |
| 1667 | case eRasMessage_registrationConfirm: |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 1668 | return process_rcf(skb, ct, ctinfo, data, |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1669 | &ras->registrationConfirm); |
| 1670 | case eRasMessage_unregistrationRequest: |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 1671 | return process_urq(skb, ct, ctinfo, data, |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1672 | &ras->unregistrationRequest); |
| 1673 | case eRasMessage_admissionRequest: |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 1674 | return process_arq(skb, ct, ctinfo, data, |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1675 | &ras->admissionRequest); |
| 1676 | case eRasMessage_admissionConfirm: |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 1677 | return process_acf(skb, ct, ctinfo, data, |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1678 | &ras->admissionConfirm); |
| 1679 | case eRasMessage_locationRequest: |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 1680 | return process_lrq(skb, ct, ctinfo, data, |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1681 | &ras->locationRequest); |
| 1682 | case eRasMessage_locationConfirm: |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 1683 | return process_lcf(skb, ct, ctinfo, data, |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1684 | &ras->locationConfirm); |
| 1685 | case eRasMessage_infoRequestResponse: |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 1686 | return process_irr(skb, ct, ctinfo, data, |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1687 | &ras->infoRequestResponse); |
| 1688 | default: |
Patrick McHardy | 0d53778 | 2007-07-07 22:39:38 -0700 | [diff] [blame] | 1689 | pr_debug("nf_ct_ras: RAS message %d\n", ras->choice); |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1690 | break; |
| 1691 | } |
| 1692 | |
| 1693 | return 0; |
| 1694 | } |
| 1695 | |
| 1696 | /****************************************************************************/ |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 1697 | static int ras_help(struct sk_buff *skb, unsigned int protoff, |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1698 | struct nf_conn *ct, enum ip_conntrack_info ctinfo) |
| 1699 | { |
| 1700 | static RasMessage ras; |
| 1701 | unsigned char *data; |
| 1702 | int datalen = 0; |
| 1703 | int ret; |
| 1704 | |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 1705 | pr_debug("nf_ct_ras: skblen = %u\n", skb->len); |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1706 | |
| 1707 | spin_lock_bh(&nf_h323_lock); |
| 1708 | |
| 1709 | /* Get UDP data */ |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 1710 | data = get_udp_data(skb, protoff, &datalen); |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1711 | if (data == NULL) |
| 1712 | goto accept; |
Patrick McHardy | 0d53778 | 2007-07-07 22:39:38 -0700 | [diff] [blame] | 1713 | pr_debug("nf_ct_ras: RAS message len=%d ", datalen); |
Jan Engelhardt | 3c9fba6 | 2008-04-14 11:15:54 +0200 | [diff] [blame] | 1714 | nf_ct_dump_tuple(&ct->tuplehash[CTINFO2DIR(ctinfo)].tuple); |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1715 | |
| 1716 | /* Decode RAS message */ |
| 1717 | ret = DecodeRasMessage(data, datalen, &ras); |
| 1718 | if (ret < 0) { |
Patrick McHardy | 0d53778 | 2007-07-07 22:39:38 -0700 | [diff] [blame] | 1719 | pr_debug("nf_ct_ras: decoding error: %s\n", |
| 1720 | ret == H323_ERROR_BOUND ? |
| 1721 | "out of bound" : "out of range"); |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1722 | goto accept; |
| 1723 | } |
| 1724 | |
| 1725 | /* Process RAS message */ |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 1726 | if (process_ras(skb, ct, ctinfo, &data, &ras) < 0) |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1727 | goto drop; |
| 1728 | |
| 1729 | accept: |
| 1730 | spin_unlock_bh(&nf_h323_lock); |
| 1731 | return NF_ACCEPT; |
| 1732 | |
| 1733 | drop: |
| 1734 | spin_unlock_bh(&nf_h323_lock); |
| 1735 | if (net_ratelimit()) |
Stephen Hemminger | 654d0fb | 2010-05-13 15:02:08 +0200 | [diff] [blame] | 1736 | pr_info("nf_ct_ras: packet dropped\n"); |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1737 | return NF_DROP; |
| 1738 | } |
| 1739 | |
| 1740 | /****************************************************************************/ |
Patrick McHardy | 6002f26 | 2008-03-25 20:09:15 -0700 | [diff] [blame] | 1741 | static const struct nf_conntrack_expect_policy ras_exp_policy = { |
| 1742 | .max_expected = 32, |
| 1743 | .timeout = 240, |
| 1744 | }; |
| 1745 | |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1746 | static struct nf_conntrack_helper nf_conntrack_helper_ras[] __read_mostly = { |
| 1747 | { |
| 1748 | .name = "RAS", |
| 1749 | .me = THIS_MODULE, |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1750 | .tuple.src.l3num = AF_INET, |
Harvey Harrison | 09640e6 | 2009-02-01 00:45:17 -0800 | [diff] [blame] | 1751 | .tuple.src.u.udp.port = cpu_to_be16(RAS_PORT), |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1752 | .tuple.dst.protonum = IPPROTO_UDP, |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1753 | .help = ras_help, |
Patrick McHardy | 6002f26 | 2008-03-25 20:09:15 -0700 | [diff] [blame] | 1754 | .expect_policy = &ras_exp_policy, |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1755 | }, |
| 1756 | { |
| 1757 | .name = "RAS", |
| 1758 | .me = THIS_MODULE, |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1759 | .tuple.src.l3num = AF_INET6, |
Harvey Harrison | 09640e6 | 2009-02-01 00:45:17 -0800 | [diff] [blame] | 1760 | .tuple.src.u.udp.port = cpu_to_be16(RAS_PORT), |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1761 | .tuple.dst.protonum = IPPROTO_UDP, |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1762 | .help = ras_help, |
Patrick McHardy | 6002f26 | 2008-03-25 20:09:15 -0700 | [diff] [blame] | 1763 | .expect_policy = &ras_exp_policy, |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1764 | }, |
| 1765 | }; |
| 1766 | |
| 1767 | /****************************************************************************/ |
| 1768 | static void __exit nf_conntrack_h323_fini(void) |
| 1769 | { |
| 1770 | nf_conntrack_helper_unregister(&nf_conntrack_helper_ras[1]); |
| 1771 | nf_conntrack_helper_unregister(&nf_conntrack_helper_ras[0]); |
| 1772 | nf_conntrack_helper_unregister(&nf_conntrack_helper_q931[1]); |
| 1773 | nf_conntrack_helper_unregister(&nf_conntrack_helper_q931[0]); |
Patrick McHardy | a56b8f8 | 2008-06-17 15:52:32 -0700 | [diff] [blame] | 1774 | nf_conntrack_helper_unregister(&nf_conntrack_helper_h245); |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1775 | kfree(h323_buffer); |
Patrick McHardy | 0d53778 | 2007-07-07 22:39:38 -0700 | [diff] [blame] | 1776 | pr_debug("nf_ct_h323: fini\n"); |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1777 | } |
| 1778 | |
| 1779 | /****************************************************************************/ |
| 1780 | static int __init nf_conntrack_h323_init(void) |
| 1781 | { |
| 1782 | int ret; |
| 1783 | |
| 1784 | h323_buffer = kmalloc(65536, GFP_KERNEL); |
| 1785 | if (!h323_buffer) |
| 1786 | return -ENOMEM; |
Patrick McHardy | a56b8f8 | 2008-06-17 15:52:32 -0700 | [diff] [blame] | 1787 | ret = nf_conntrack_helper_register(&nf_conntrack_helper_h245); |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1788 | if (ret < 0) |
| 1789 | goto err1; |
Patrick McHardy | a56b8f8 | 2008-06-17 15:52:32 -0700 | [diff] [blame] | 1790 | ret = nf_conntrack_helper_register(&nf_conntrack_helper_q931[0]); |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1791 | if (ret < 0) |
| 1792 | goto err2; |
Patrick McHardy | a56b8f8 | 2008-06-17 15:52:32 -0700 | [diff] [blame] | 1793 | ret = nf_conntrack_helper_register(&nf_conntrack_helper_q931[1]); |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1794 | if (ret < 0) |
| 1795 | goto err3; |
Patrick McHardy | a56b8f8 | 2008-06-17 15:52:32 -0700 | [diff] [blame] | 1796 | ret = nf_conntrack_helper_register(&nf_conntrack_helper_ras[0]); |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1797 | if (ret < 0) |
| 1798 | goto err4; |
Patrick McHardy | a56b8f8 | 2008-06-17 15:52:32 -0700 | [diff] [blame] | 1799 | ret = nf_conntrack_helper_register(&nf_conntrack_helper_ras[1]); |
| 1800 | if (ret < 0) |
| 1801 | goto err5; |
Patrick McHardy | 0d53778 | 2007-07-07 22:39:38 -0700 | [diff] [blame] | 1802 | pr_debug("nf_ct_h323: init success\n"); |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1803 | return 0; |
| 1804 | |
Patrick McHardy | a56b8f8 | 2008-06-17 15:52:32 -0700 | [diff] [blame] | 1805 | err5: |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1806 | nf_conntrack_helper_unregister(&nf_conntrack_helper_ras[0]); |
Patrick McHardy | a56b8f8 | 2008-06-17 15:52:32 -0700 | [diff] [blame] | 1807 | err4: |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1808 | nf_conntrack_helper_unregister(&nf_conntrack_helper_q931[1]); |
Patrick McHardy | a56b8f8 | 2008-06-17 15:52:32 -0700 | [diff] [blame] | 1809 | err3: |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1810 | nf_conntrack_helper_unregister(&nf_conntrack_helper_q931[0]); |
Patrick McHardy | a56b8f8 | 2008-06-17 15:52:32 -0700 | [diff] [blame] | 1811 | err2: |
| 1812 | nf_conntrack_helper_unregister(&nf_conntrack_helper_h245); |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1813 | err1: |
Patrick McHardy | 8a54886 | 2008-06-17 15:52:07 -0700 | [diff] [blame] | 1814 | kfree(h323_buffer); |
Patrick McHardy | f587de0 | 2006-12-02 22:08:46 -0800 | [diff] [blame] | 1815 | return ret; |
| 1816 | } |
| 1817 | |
| 1818 | /****************************************************************************/ |
| 1819 | module_init(nf_conntrack_h323_init); |
| 1820 | module_exit(nf_conntrack_h323_fini); |
| 1821 | |
| 1822 | EXPORT_SYMBOL_GPL(get_h225_addr); |
| 1823 | EXPORT_SYMBOL_GPL(set_h245_addr_hook); |
| 1824 | EXPORT_SYMBOL_GPL(set_h225_addr_hook); |
| 1825 | EXPORT_SYMBOL_GPL(set_sig_addr_hook); |
| 1826 | EXPORT_SYMBOL_GPL(set_ras_addr_hook); |
| 1827 | EXPORT_SYMBOL_GPL(nat_rtp_rtcp_hook); |
| 1828 | EXPORT_SYMBOL_GPL(nat_t120_hook); |
| 1829 | EXPORT_SYMBOL_GPL(nat_h245_hook); |
| 1830 | EXPORT_SYMBOL_GPL(nat_callforwarding_hook); |
| 1831 | EXPORT_SYMBOL_GPL(nat_q931_hook); |
| 1832 | |
| 1833 | MODULE_AUTHOR("Jing Min Zhao <zhaojingmin@users.sourceforge.net>"); |
| 1834 | MODULE_DESCRIPTION("H.323 connection tracking helper"); |
| 1835 | MODULE_LICENSE("GPL"); |
| 1836 | MODULE_ALIAS("ip_conntrack_h323"); |
Pablo Neira Ayuso | 4dc06f9 | 2008-11-17 16:01:42 +0100 | [diff] [blame] | 1837 | MODULE_ALIAS_NFCT_HELPER("h323"); |