blob: 251a9a44d189aee033969ff0da717aa248f0e60a [file] [log] [blame]
Patrick McHardy9fafcd72006-12-02 22:09:57 -08001/* SIP extension for IP connection tracking.
2 *
3 * (C) 2005 by Christian Hentschel <chentschel@arnet.com.ar>
4 * based on RR's ip_conntrack_ftp.c and other modules.
Patrick McHardyf49e1aa2008-03-25 20:27:05 -07005 * (C) 2007 United Security Providers
6 * (C) 2007, 2008 Patrick McHardy <kaber@trash.net>
Patrick McHardy9fafcd72006-12-02 22:09:57 -08007 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 */
12
Pablo Neira Ayusoad6d9502016-01-03 22:41:24 +010013#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
14
Patrick McHardy9fafcd72006-12-02 22:09:57 -080015#include <linux/module.h>
16#include <linux/ctype.h>
17#include <linux/skbuff.h>
18#include <linux/inet.h>
19#include <linux/in.h>
20#include <linux/udp.h>
Patrick McHardyf5b321b2010-02-11 12:26:19 +010021#include <linux/tcp.h>
Yasuyuki Kozakai1863f092006-12-02 22:12:54 -080022#include <linux/netfilter.h>
Patrick McHardy9fafcd72006-12-02 22:09:57 -080023
24#include <net/netfilter/nf_conntrack.h>
Patrick McHardy9467ee32008-03-25 20:24:04 -070025#include <net/netfilter/nf_conntrack_core.h>
Patrick McHardy9fafcd72006-12-02 22:09:57 -080026#include <net/netfilter/nf_conntrack_expect.h>
27#include <net/netfilter/nf_conntrack_helper.h>
Patrick McHardy5d0aa2c2010-02-15 18:13:33 +010028#include <net/netfilter/nf_conntrack_zones.h>
Patrick McHardy9fafcd72006-12-02 22:09:57 -080029#include <linux/netfilter/nf_conntrack_sip.h>
30
Patrick McHardy9fafcd72006-12-02 22:09:57 -080031MODULE_LICENSE("GPL");
32MODULE_AUTHOR("Christian Hentschel <chentschel@arnet.com.ar>");
33MODULE_DESCRIPTION("SIP connection tracking helper");
34MODULE_ALIAS("ip_conntrack_sip");
Pablo Neira Ayuso4dc06f92008-11-17 16:01:42 +010035MODULE_ALIAS_NFCT_HELPER("sip");
Patrick McHardy9fafcd72006-12-02 22:09:57 -080036
37#define MAX_PORTS 8
38static unsigned short ports[MAX_PORTS];
Stephen Hemminger2f0d2f12008-01-31 04:08:10 -080039static unsigned int ports_c;
Patrick McHardy9fafcd72006-12-02 22:09:57 -080040module_param_array(ports, ushort, &ports_c, 0400);
41MODULE_PARM_DESC(ports, "port numbers of SIP servers");
42
43static unsigned int sip_timeout __read_mostly = SIP_TIMEOUT;
44module_param(sip_timeout, uint, 0600);
45MODULE_PARM_DESC(sip_timeout, "timeout for the master SIP session");
46
Patrick McHardy0f32a402008-03-25 20:25:13 -070047static int sip_direct_signalling __read_mostly = 1;
48module_param(sip_direct_signalling, int, 0600);
49MODULE_PARM_DESC(sip_direct_signalling, "expect incoming calls from registrar "
50 "only (default 1)");
51
Patrick McHardyd901a932008-03-25 20:25:32 -070052static int sip_direct_media __read_mostly = 1;
53module_param(sip_direct_media, int, 0600);
54MODULE_PARM_DESC(sip_direct_media, "Expect Media streams between signalling "
55 "endpoints only (default 1)");
56
holger@eitzenberger.org180cf722013-09-30 17:07:28 +020057const struct nf_nat_sip_hooks *nf_nat_sip_hooks;
58EXPORT_SYMBOL_GPL(nf_nat_sip_hooks);
Patrick McHardy9fafcd72006-12-02 22:09:57 -080059
Patrick McHardyac367742008-03-25 20:18:40 -070060static int string_len(const struct nf_conn *ct, const char *dptr,
61 const char *limit, int *shift)
62{
63 int len = 0;
64
65 while (dptr < limit && isalpha(*dptr)) {
66 dptr++;
67 len++;
68 }
69 return len;
70}
71
Jan Engelhardt13f7d632008-01-31 04:50:25 -080072static int digits_len(const struct nf_conn *ct, const char *dptr,
Patrick McHardy9fafcd72006-12-02 22:09:57 -080073 const char *limit, int *shift)
74{
75 int len = 0;
Patrick McHardyb1ec4882008-03-25 20:10:11 -070076 while (dptr < limit && isdigit(*dptr)) {
Patrick McHardy9fafcd72006-12-02 22:09:57 -080077 dptr++;
78 len++;
79 }
80 return len;
81}
82
Simon Horman001985b2010-08-22 21:37:51 +090083static int iswordc(const char c)
84{
85 if (isalnum(c) || c == '!' || c == '"' || c == '%' ||
86 (c >= '(' && c <= '/') || c == ':' || c == '<' || c == '>' ||
87 c == '?' || (c >= '[' && c <= ']') || c == '_' || c == '`' ||
88 c == '{' || c == '}' || c == '~')
89 return 1;
90 return 0;
91}
92
93static int word_len(const char *dptr, const char *limit)
94{
95 int len = 0;
96 while (dptr < limit && iswordc(*dptr)) {
97 dptr++;
98 len++;
99 }
100 return len;
101}
102
103static int callid_len(const struct nf_conn *ct, const char *dptr,
104 const char *limit, int *shift)
105{
106 int len, domain_len;
107
108 len = word_len(dptr, limit);
109 dptr += len;
110 if (!len || dptr == limit || *dptr != '@')
111 return len;
112 dptr++;
113 len++;
114
115 domain_len = word_len(dptr, limit);
116 if (!domain_len)
117 return 0;
118 return len + domain_len;
119}
120
Patrick McHardy0d0ab032008-03-25 20:26:24 -0700121/* get media type + port length */
122static int media_len(const struct nf_conn *ct, const char *dptr,
123 const char *limit, int *shift)
124{
125 int len = string_len(ct, dptr, limit, shift);
126
127 dptr += len;
128 if (dptr >= limit || *dptr != ' ')
129 return 0;
130 len++;
131 dptr++;
132
133 return len + digits_len(ct, dptr, limit, shift);
134}
135
Patrick McHardy02b69cb2012-08-09 10:08:46 +0000136static int sip_parse_addr(const struct nf_conn *ct, const char *cp,
137 const char **endp, union nf_inet_addr *addr,
138 const char *limit, bool delim)
Patrick McHardy9fafcd72006-12-02 22:09:57 -0800139{
140 const char *end;
Patrick McHardy02b69cb2012-08-09 10:08:46 +0000141 int ret;
Patrick McHardy9fafcd72006-12-02 22:09:57 -0800142
Simon Horman5adbb9f2010-08-22 21:37:51 +0900143 if (!ct)
144 return 0;
145
Patrick McHardyfa913dd2008-04-14 11:15:45 +0200146 memset(addr, 0, sizeof(*addr));
Patrick McHardy5e8fbe22008-04-14 11:15:52 +0200147 switch (nf_ct_l3num(ct)) {
Patrick McHardy9fafcd72006-12-02 22:09:57 -0800148 case AF_INET:
149 ret = in4_pton(cp, limit - cp, (u8 *)&addr->ip, -1, &end);
Patrick McHardy02b69cb2012-08-09 10:08:46 +0000150 if (ret == 0)
151 return 0;
Patrick McHardy9fafcd72006-12-02 22:09:57 -0800152 break;
153 case AF_INET6:
Patrick McHardy02b69cb2012-08-09 10:08:46 +0000154 if (cp < limit && *cp == '[')
155 cp++;
156 else if (delim)
157 return 0;
158
Patrick McHardy9fafcd72006-12-02 22:09:57 -0800159 ret = in6_pton(cp, limit - cp, (u8 *)&addr->ip6, -1, &end);
Patrick McHardy02b69cb2012-08-09 10:08:46 +0000160 if (ret == 0)
161 return 0;
162
163 if (end < limit && *end == ']')
164 end++;
165 else if (delim)
166 return 0;
Patrick McHardy9fafcd72006-12-02 22:09:57 -0800167 break;
168 default:
169 BUG();
170 }
171
Patrick McHardy9fafcd72006-12-02 22:09:57 -0800172 if (endp)
173 *endp = end;
174 return 1;
175}
176
177/* skip ip address. returns its length. */
Jan Engelhardt13f7d632008-01-31 04:50:25 -0800178static int epaddr_len(const struct nf_conn *ct, const char *dptr,
Patrick McHardy9fafcd72006-12-02 22:09:57 -0800179 const char *limit, int *shift)
180{
Jan Engelhardt643a2c12007-12-17 22:43:50 -0800181 union nf_inet_addr addr;
Patrick McHardy9fafcd72006-12-02 22:09:57 -0800182 const char *aux = dptr;
183
Patrick McHardy02b69cb2012-08-09 10:08:46 +0000184 if (!sip_parse_addr(ct, dptr, &dptr, &addr, limit, true)) {
Patrick McHardy0d537782007-07-07 22:39:38 -0700185 pr_debug("ip: %s parse failed.!\n", dptr);
Patrick McHardy9fafcd72006-12-02 22:09:57 -0800186 return 0;
187 }
188
189 /* Port number */
190 if (*dptr == ':') {
191 dptr++;
192 dptr += digits_len(ct, dptr, limit, shift);
193 }
194 return dptr - aux;
195}
196
197/* get address length, skiping user info. */
Jan Engelhardt13f7d632008-01-31 04:50:25 -0800198static int skp_epaddr_len(const struct nf_conn *ct, const char *dptr,
Patrick McHardy9fafcd72006-12-02 22:09:57 -0800199 const char *limit, int *shift)
200{
Patrick McHardyaa584ed2007-08-14 13:14:35 -0700201 const char *start = dptr;
Patrick McHardy9fafcd72006-12-02 22:09:57 -0800202 int s = *shift;
203
Lars Immisch7da5bfb2007-01-30 14:24:57 -0800204 /* Search for @, but stop at the end of the line.
205 * We are inside a sip: URI, so we don't need to worry about
206 * continuation lines. */
Patrick McHardyb1ec4882008-03-25 20:10:11 -0700207 while (dptr < limit &&
Lars Immisch7da5bfb2007-01-30 14:24:57 -0800208 *dptr != '@' && *dptr != '\r' && *dptr != '\n') {
Patrick McHardy9fafcd72006-12-02 22:09:57 -0800209 (*shift)++;
Lars Immisch7da5bfb2007-01-30 14:24:57 -0800210 dptr++;
211 }
Patrick McHardy9fafcd72006-12-02 22:09:57 -0800212
Patrick McHardyb1ec4882008-03-25 20:10:11 -0700213 if (dptr < limit && *dptr == '@') {
Patrick McHardy9fafcd72006-12-02 22:09:57 -0800214 dptr++;
215 (*shift)++;
Patrick McHardyaa584ed2007-08-14 13:14:35 -0700216 } else {
217 dptr = start;
Patrick McHardy9fafcd72006-12-02 22:09:57 -0800218 *shift = s;
Patrick McHardyaa584ed2007-08-14 13:14:35 -0700219 }
Patrick McHardy9fafcd72006-12-02 22:09:57 -0800220
221 return epaddr_len(ct, dptr, limit, shift);
222}
223
Patrick McHardyac367742008-03-25 20:18:40 -0700224/* Parse a SIP request line of the form:
225 *
226 * Request-Line = Method SP Request-URI SP SIP-Version CRLF
227 *
228 * and return the offset and length of the address contained in the Request-URI.
229 */
230int ct_sip_parse_request(const struct nf_conn *ct,
231 const char *dptr, unsigned int datalen,
Patrick McHardy624f8b72008-03-25 20:19:30 -0700232 unsigned int *matchoff, unsigned int *matchlen,
233 union nf_inet_addr *addr, __be16 *port)
Patrick McHardyac367742008-03-25 20:18:40 -0700234{
Patrick McHardy624f8b72008-03-25 20:19:30 -0700235 const char *start = dptr, *limit = dptr + datalen, *end;
Patrick McHardyac367742008-03-25 20:18:40 -0700236 unsigned int mlen;
Patrick McHardy624f8b72008-03-25 20:19:30 -0700237 unsigned int p;
Patrick McHardyac367742008-03-25 20:18:40 -0700238 int shift = 0;
239
240 /* Skip method and following whitespace */
241 mlen = string_len(ct, dptr, limit, NULL);
242 if (!mlen)
243 return 0;
244 dptr += mlen;
245 if (++dptr >= limit)
246 return 0;
247
248 /* Find SIP URI */
Patrick McHardy54101f42010-02-11 12:23:12 +0100249 for (; dptr < limit - strlen("sip:"); dptr++) {
Patrick McHardyac367742008-03-25 20:18:40 -0700250 if (*dptr == '\r' || *dptr == '\n')
251 return -1;
Rasmus Villemoes18082742014-10-13 15:54:31 -0700252 if (strncasecmp(dptr, "sip:", strlen("sip:")) == 0) {
Patrick McHardy54101f42010-02-11 12:23:12 +0100253 dptr += strlen("sip:");
Patrick McHardyac367742008-03-25 20:18:40 -0700254 break;
Patrick McHardy54101f42010-02-11 12:23:12 +0100255 }
Patrick McHardyac367742008-03-25 20:18:40 -0700256 }
Patrick McHardy624f8b72008-03-25 20:19:30 -0700257 if (!skp_epaddr_len(ct, dptr, limit, &shift))
Patrick McHardyac367742008-03-25 20:18:40 -0700258 return 0;
Patrick McHardy624f8b72008-03-25 20:19:30 -0700259 dptr += shift;
260
Patrick McHardy02b69cb2012-08-09 10:08:46 +0000261 if (!sip_parse_addr(ct, dptr, &end, addr, limit, true))
Patrick McHardy624f8b72008-03-25 20:19:30 -0700262 return -1;
263 if (end < limit && *end == ':') {
264 end++;
265 p = simple_strtoul(end, (char **)&end, 10);
266 if (p < 1024 || p > 65535)
267 return -1;
268 *port = htons(p);
269 } else
270 *port = htons(SIP_PORT);
271
272 if (end == dptr)
273 return 0;
274 *matchoff = dptr - start;
275 *matchlen = end - dptr;
Patrick McHardyac367742008-03-25 20:18:40 -0700276 return 1;
277}
278EXPORT_SYMBOL_GPL(ct_sip_parse_request);
279
Patrick McHardyea45f122008-03-25 20:18:57 -0700280/* SIP header parsing: SIP headers are located at the beginning of a line, but
281 * may span several lines, in which case the continuation lines begin with a
282 * whitespace character. RFC 2543 allows lines to be terminated with CR, LF or
283 * CRLF, RFC 3261 allows only CRLF, we support both.
284 *
285 * Headers are followed by (optionally) whitespace, a colon, again (optionally)
286 * whitespace and the values. Whitespace in this context means any amount of
287 * tabs, spaces and continuation lines, which are treated as a single whitespace
288 * character.
Patrick McHardy05e3ced2008-03-25 20:19:13 -0700289 *
Daniel Mack3ad2f3f2010-02-03 08:01:28 +0800290 * Some headers may appear multiple times. A comma separated list of values is
Patrick McHardy05e3ced2008-03-25 20:19:13 -0700291 * equivalent to multiple headers.
Patrick McHardyea45f122008-03-25 20:18:57 -0700292 */
293static const struct sip_header ct_sip_hdrs[] = {
Patrick McHardy30f33e62008-03-25 20:22:20 -0700294 [SIP_HDR_CSEQ] = SIP_HDR("CSeq", NULL, NULL, digits_len),
Patrick McHardyea45f122008-03-25 20:18:57 -0700295 [SIP_HDR_FROM] = SIP_HDR("From", "f", "sip:", skp_epaddr_len),
296 [SIP_HDR_TO] = SIP_HDR("To", "t", "sip:", skp_epaddr_len),
297 [SIP_HDR_CONTACT] = SIP_HDR("Contact", "m", "sip:", skp_epaddr_len),
Patrick McHardyf5b321b2010-02-11 12:26:19 +0100298 [SIP_HDR_VIA_UDP] = SIP_HDR("Via", "v", "UDP ", epaddr_len),
299 [SIP_HDR_VIA_TCP] = SIP_HDR("Via", "v", "TCP ", epaddr_len),
Patrick McHardy0f32a402008-03-25 20:25:13 -0700300 [SIP_HDR_EXPIRES] = SIP_HDR("Expires", NULL, NULL, digits_len),
Patrick McHardyea45f122008-03-25 20:18:57 -0700301 [SIP_HDR_CONTENT_LENGTH] = SIP_HDR("Content-Length", "l", NULL, digits_len),
Simon Horman001985b2010-08-22 21:37:51 +0900302 [SIP_HDR_CALL_ID] = SIP_HDR("Call-Id", "i", NULL, callid_len),
Patrick McHardyea45f122008-03-25 20:18:57 -0700303};
304
305static const char *sip_follow_continuation(const char *dptr, const char *limit)
Patrick McHardy9fafcd72006-12-02 22:09:57 -0800306{
Patrick McHardyea45f122008-03-25 20:18:57 -0700307 /* Walk past newline */
308 if (++dptr >= limit)
309 return NULL;
Patrick McHardy9fafcd72006-12-02 22:09:57 -0800310
Patrick McHardyea45f122008-03-25 20:18:57 -0700311 /* Skip '\n' in CR LF */
312 if (*(dptr - 1) == '\r' && *dptr == '\n') {
313 if (++dptr >= limit)
314 return NULL;
315 }
Patrick McHardy9fafcd72006-12-02 22:09:57 -0800316
Patrick McHardyea45f122008-03-25 20:18:57 -0700317 /* Continuation line? */
318 if (*dptr != ' ' && *dptr != '\t')
319 return NULL;
320
321 /* skip leading whitespace */
322 for (; dptr < limit; dptr++) {
323 if (*dptr != ' ' && *dptr != '\t')
324 break;
325 }
326 return dptr;
327}
328
329static const char *sip_skip_whitespace(const char *dptr, const char *limit)
330{
331 for (; dptr < limit; dptr++) {
332 if (*dptr == ' ')
333 continue;
334 if (*dptr != '\r' && *dptr != '\n')
335 break;
336 dptr = sip_follow_continuation(dptr, limit);
Marco Angaroni68cb9fe2016-08-30 18:48:19 +0200337 break;
Patrick McHardyea45f122008-03-25 20:18:57 -0700338 }
339 return dptr;
340}
341
342/* Search within a SIP header value, dealing with continuation lines */
343static const char *ct_sip_header_search(const char *dptr, const char *limit,
344 const char *needle, unsigned int len)
345{
346 for (limit -= len; dptr < limit; dptr++) {
347 if (*dptr == '\r' || *dptr == '\n') {
348 dptr = sip_follow_continuation(dptr, limit);
349 if (dptr == NULL)
350 break;
Patrick McHardy9fafcd72006-12-02 22:09:57 -0800351 continue;
352 }
Patrick McHardy9fafcd72006-12-02 22:09:57 -0800353
Rasmus Villemoes18082742014-10-13 15:54:31 -0700354 if (strncasecmp(dptr, needle, len) == 0)
Patrick McHardyea45f122008-03-25 20:18:57 -0700355 return dptr;
356 }
357 return NULL;
358}
359
360int ct_sip_get_header(const struct nf_conn *ct, const char *dptr,
361 unsigned int dataoff, unsigned int datalen,
362 enum sip_header_types type,
363 unsigned int *matchoff, unsigned int *matchlen)
364{
365 const struct sip_header *hdr = &ct_sip_hdrs[type];
366 const char *start = dptr, *limit = dptr + datalen;
367 int shift = 0;
368
369 for (dptr += dataoff; dptr < limit; dptr++) {
370 /* Find beginning of line */
371 if (*dptr != '\r' && *dptr != '\n')
372 continue;
373 if (++dptr >= limit)
374 break;
375 if (*(dptr - 1) == '\r' && *dptr == '\n') {
376 if (++dptr >= limit)
377 break;
378 }
379
380 /* Skip continuation lines */
381 if (*dptr == ' ' || *dptr == '\t')
382 continue;
383
384 /* Find header. Compact headers must be followed by a
385 * non-alphabetic character to avoid mismatches. */
386 if (limit - dptr >= hdr->len &&
Rasmus Villemoes18082742014-10-13 15:54:31 -0700387 strncasecmp(dptr, hdr->name, hdr->len) == 0)
Patrick McHardyea45f122008-03-25 20:18:57 -0700388 dptr += hdr->len;
389 else if (hdr->cname && limit - dptr >= hdr->clen + 1 &&
Rasmus Villemoes18082742014-10-13 15:54:31 -0700390 strncasecmp(dptr, hdr->cname, hdr->clen) == 0 &&
Patrick McHardy135d0182010-01-19 19:06:59 +0100391 !isalpha(*(dptr + hdr->clen)))
Patrick McHardyea45f122008-03-25 20:18:57 -0700392 dptr += hdr->clen;
393 else
394 continue;
395
396 /* Find and skip colon */
397 dptr = sip_skip_whitespace(dptr, limit);
398 if (dptr == NULL)
399 break;
400 if (*dptr != ':' || ++dptr >= limit)
401 break;
402
403 /* Skip whitespace after colon */
404 dptr = sip_skip_whitespace(dptr, limit);
405 if (dptr == NULL)
406 break;
407
408 *matchoff = dptr - start;
409 if (hdr->search) {
410 dptr = ct_sip_header_search(dptr, limit, hdr->search,
411 hdr->slen);
412 if (!dptr)
413 return -1;
414 dptr += hdr->slen;
415 }
416
417 *matchlen = hdr->match_len(ct, dptr, limit, &shift);
Patrick McHardy9fafcd72006-12-02 22:09:57 -0800418 if (!*matchlen)
419 return -1;
Patrick McHardyea45f122008-03-25 20:18:57 -0700420 *matchoff = dptr - start + shift;
Patrick McHardy9fafcd72006-12-02 22:09:57 -0800421 return 1;
422 }
Patrick McHardy9fafcd72006-12-02 22:09:57 -0800423 return 0;
424}
Patrick McHardyea45f122008-03-25 20:18:57 -0700425EXPORT_SYMBOL_GPL(ct_sip_get_header);
Patrick McHardy9fafcd72006-12-02 22:09:57 -0800426
Daniel Mack3ad2f3f2010-02-03 08:01:28 +0800427/* Get next header field in a list of comma separated values */
Patrick McHardy05e3ced2008-03-25 20:19:13 -0700428static int ct_sip_next_header(const struct nf_conn *ct, const char *dptr,
429 unsigned int dataoff, unsigned int datalen,
430 enum sip_header_types type,
431 unsigned int *matchoff, unsigned int *matchlen)
432{
433 const struct sip_header *hdr = &ct_sip_hdrs[type];
434 const char *start = dptr, *limit = dptr + datalen;
435 int shift = 0;
436
437 dptr += dataoff;
438
439 dptr = ct_sip_header_search(dptr, limit, ",", strlen(","));
440 if (!dptr)
441 return 0;
442
443 dptr = ct_sip_header_search(dptr, limit, hdr->search, hdr->slen);
444 if (!dptr)
445 return 0;
446 dptr += hdr->slen;
447
448 *matchoff = dptr - start;
449 *matchlen = hdr->match_len(ct, dptr, limit, &shift);
450 if (!*matchlen)
451 return -1;
452 *matchoff += shift;
453 return 1;
454}
455
456/* Walk through headers until a parsable one is found or no header of the
457 * given type is left. */
458static int ct_sip_walk_headers(const struct nf_conn *ct, const char *dptr,
459 unsigned int dataoff, unsigned int datalen,
460 enum sip_header_types type, int *in_header,
461 unsigned int *matchoff, unsigned int *matchlen)
462{
463 int ret;
464
465 if (in_header && *in_header) {
466 while (1) {
467 ret = ct_sip_next_header(ct, dptr, dataoff, datalen,
468 type, matchoff, matchlen);
469 if (ret > 0)
470 return ret;
471 if (ret == 0)
472 break;
473 dataoff += *matchoff;
474 }
475 *in_header = 0;
476 }
477
478 while (1) {
479 ret = ct_sip_get_header(ct, dptr, dataoff, datalen,
480 type, matchoff, matchlen);
481 if (ret > 0)
482 break;
483 if (ret == 0)
484 return ret;
485 dataoff += *matchoff;
486 }
487
488 if (in_header)
489 *in_header = 1;
490 return 1;
491}
492
493/* Locate a SIP header, parse the URI and return the offset and length of
494 * the address as well as the address and port themselves. A stream of
495 * headers can be parsed by handing in a non-NULL datalen and in_header
496 * pointer.
497 */
498int ct_sip_parse_header_uri(const struct nf_conn *ct, const char *dptr,
499 unsigned int *dataoff, unsigned int datalen,
500 enum sip_header_types type, int *in_header,
501 unsigned int *matchoff, unsigned int *matchlen,
502 union nf_inet_addr *addr, __be16 *port)
503{
504 const char *c, *limit = dptr + datalen;
505 unsigned int p;
506 int ret;
507
508 ret = ct_sip_walk_headers(ct, dptr, dataoff ? *dataoff : 0, datalen,
509 type, in_header, matchoff, matchlen);
510 WARN_ON(ret < 0);
511 if (ret == 0)
512 return ret;
513
Patrick McHardy02b69cb2012-08-09 10:08:46 +0000514 if (!sip_parse_addr(ct, dptr + *matchoff, &c, addr, limit, true))
Patrick McHardy05e3ced2008-03-25 20:19:13 -0700515 return -1;
516 if (*c == ':') {
517 c++;
518 p = simple_strtoul(c, (char **)&c, 10);
519 if (p < 1024 || p > 65535)
520 return -1;
521 *port = htons(p);
522 } else
523 *port = htons(SIP_PORT);
524
525 if (dataoff)
526 *dataoff = c - dptr;
527 return 1;
528}
529EXPORT_SYMBOL_GPL(ct_sip_parse_header_uri);
530
Patrick McHardyf5b321b2010-02-11 12:26:19 +0100531static int ct_sip_parse_param(const struct nf_conn *ct, const char *dptr,
532 unsigned int dataoff, unsigned int datalen,
533 const char *name,
534 unsigned int *matchoff, unsigned int *matchlen)
535{
536 const char *limit = dptr + datalen;
537 const char *start;
538 const char *end;
539
540 limit = ct_sip_header_search(dptr + dataoff, limit, ",", strlen(","));
541 if (!limit)
542 limit = dptr + datalen;
543
544 start = ct_sip_header_search(dptr + dataoff, limit, name, strlen(name));
545 if (!start)
546 return 0;
547 start += strlen(name);
548
549 end = ct_sip_header_search(start, limit, ";", strlen(";"));
550 if (!end)
551 end = limit;
552
553 *matchoff = start - dptr;
554 *matchlen = end - start;
555 return 1;
556}
557
Patrick McHardy2bbb2112008-03-25 20:24:24 -0700558/* Parse address from header parameter and return address, offset and length */
559int ct_sip_parse_address_param(const struct nf_conn *ct, const char *dptr,
560 unsigned int dataoff, unsigned int datalen,
561 const char *name,
562 unsigned int *matchoff, unsigned int *matchlen,
Patrick McHardy02b69cb2012-08-09 10:08:46 +0000563 union nf_inet_addr *addr, bool delim)
Patrick McHardy2bbb2112008-03-25 20:24:24 -0700564{
565 const char *limit = dptr + datalen;
566 const char *start, *end;
567
568 limit = ct_sip_header_search(dptr + dataoff, limit, ",", strlen(","));
569 if (!limit)
570 limit = dptr + datalen;
571
572 start = ct_sip_header_search(dptr + dataoff, limit, name, strlen(name));
573 if (!start)
574 return 0;
575
576 start += strlen(name);
Patrick McHardy02b69cb2012-08-09 10:08:46 +0000577 if (!sip_parse_addr(ct, start, &end, addr, limit, delim))
Patrick McHardy2bbb2112008-03-25 20:24:24 -0700578 return 0;
579 *matchoff = start - dptr;
580 *matchlen = end - start;
581 return 1;
582}
583EXPORT_SYMBOL_GPL(ct_sip_parse_address_param);
584
585/* Parse numerical header parameter and return value, offset and length */
586int ct_sip_parse_numerical_param(const struct nf_conn *ct, const char *dptr,
587 unsigned int dataoff, unsigned int datalen,
588 const char *name,
589 unsigned int *matchoff, unsigned int *matchlen,
590 unsigned int *val)
591{
592 const char *limit = dptr + datalen;
593 const char *start;
594 char *end;
595
596 limit = ct_sip_header_search(dptr + dataoff, limit, ",", strlen(","));
597 if (!limit)
598 limit = dptr + datalen;
599
600 start = ct_sip_header_search(dptr + dataoff, limit, name, strlen(name));
601 if (!start)
602 return 0;
603
604 start += strlen(name);
605 *val = simple_strtoul(start, &end, 0);
606 if (start == end)
607 return 0;
608 if (matchoff && matchlen) {
609 *matchoff = start - dptr;
610 *matchlen = end - start;
611 }
612 return 1;
613}
614EXPORT_SYMBOL_GPL(ct_sip_parse_numerical_param);
615
Patrick McHardyf5b321b2010-02-11 12:26:19 +0100616static int ct_sip_parse_transport(struct nf_conn *ct, const char *dptr,
617 unsigned int dataoff, unsigned int datalen,
618 u8 *proto)
619{
620 unsigned int matchoff, matchlen;
621
622 if (ct_sip_parse_param(ct, dptr, dataoff, datalen, "transport=",
623 &matchoff, &matchlen)) {
Rasmus Villemoes18082742014-10-13 15:54:31 -0700624 if (!strncasecmp(dptr + matchoff, "TCP", strlen("TCP")))
Patrick McHardyf5b321b2010-02-11 12:26:19 +0100625 *proto = IPPROTO_TCP;
Rasmus Villemoes18082742014-10-13 15:54:31 -0700626 else if (!strncasecmp(dptr + matchoff, "UDP", strlen("UDP")))
Patrick McHardyf5b321b2010-02-11 12:26:19 +0100627 *proto = IPPROTO_UDP;
628 else
629 return 0;
630
631 if (*proto != nf_ct_protonum(ct))
632 return 0;
633 } else
634 *proto = nf_ct_protonum(ct);
635
636 return 1;
637}
638
Patrick McHardy02b69cb2012-08-09 10:08:46 +0000639static int sdp_parse_addr(const struct nf_conn *ct, const char *cp,
640 const char **endp, union nf_inet_addr *addr,
641 const char *limit)
642{
643 const char *end;
644 int ret;
645
646 memset(addr, 0, sizeof(*addr));
647 switch (nf_ct_l3num(ct)) {
648 case AF_INET:
649 ret = in4_pton(cp, limit - cp, (u8 *)&addr->ip, -1, &end);
650 break;
651 case AF_INET6:
652 ret = in6_pton(cp, limit - cp, (u8 *)&addr->ip6, -1, &end);
653 break;
654 default:
655 BUG();
656 }
657
658 if (ret == 0)
659 return 0;
660 if (endp)
661 *endp = end;
662 return 1;
663}
664
665/* skip ip address. returns its length. */
666static int sdp_addr_len(const struct nf_conn *ct, const char *dptr,
667 const char *limit, int *shift)
668{
669 union nf_inet_addr addr;
670 const char *aux = dptr;
671
672 if (!sdp_parse_addr(ct, dptr, &dptr, &addr, limit)) {
673 pr_debug("ip: %s parse failed.!\n", dptr);
674 return 0;
675 }
676
677 return dptr - aux;
678}
679
Patrick McHardy3e9b4600b2008-03-25 20:17:55 -0700680/* SDP header parsing: a SDP session description contains an ordered set of
681 * headers, starting with a section containing general session parameters,
682 * optionally followed by multiple media descriptions.
683 *
684 * SDP headers always start at the beginning of a line. According to RFC 2327:
685 * "The sequence CRLF (0x0d0a) is used to end a record, although parsers should
686 * be tolerant and also accept records terminated with a single newline
687 * character". We handle both cases.
688 */
Patrick McHardy9a664822012-08-26 19:14:25 +0200689static const struct sip_header ct_sdp_hdrs_v4[] = {
690 [SDP_HDR_VERSION] = SDP_HDR("v=", NULL, digits_len),
691 [SDP_HDR_OWNER] = SDP_HDR("o=", "IN IP4 ", sdp_addr_len),
692 [SDP_HDR_CONNECTION] = SDP_HDR("c=", "IN IP4 ", sdp_addr_len),
693 [SDP_HDR_MEDIA] = SDP_HDR("m=", NULL, media_len),
694};
695
696static const struct sip_header ct_sdp_hdrs_v6[] = {
697 [SDP_HDR_VERSION] = SDP_HDR("v=", NULL, digits_len),
698 [SDP_HDR_OWNER] = SDP_HDR("o=", "IN IP6 ", sdp_addr_len),
699 [SDP_HDR_CONNECTION] = SDP_HDR("c=", "IN IP6 ", sdp_addr_len),
700 [SDP_HDR_MEDIA] = SDP_HDR("m=", NULL, media_len),
Patrick McHardy3e9b4600b2008-03-25 20:17:55 -0700701};
702
703/* Linear string search within SDP header values */
704static const char *ct_sdp_header_search(const char *dptr, const char *limit,
705 const char *needle, unsigned int len)
706{
707 for (limit -= len; dptr < limit; dptr++) {
708 if (*dptr == '\r' || *dptr == '\n')
709 break;
710 if (strncmp(dptr, needle, len) == 0)
711 return dptr;
712 }
713 return NULL;
714}
715
716/* Locate a SDP header (optionally a substring within the header value),
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300717 * optionally stopping at the first occurrence of the term header, parse
Patrick McHardy3e9b4600b2008-03-25 20:17:55 -0700718 * it and return the offset and length of the data we're interested in.
719 */
720int ct_sip_get_sdp_header(const struct nf_conn *ct, const char *dptr,
721 unsigned int dataoff, unsigned int datalen,
722 enum sdp_header_types type,
723 enum sdp_header_types term,
724 unsigned int *matchoff, unsigned int *matchlen)
725{
Patrick McHardy9a664822012-08-26 19:14:25 +0200726 const struct sip_header *hdrs, *hdr, *thdr;
Patrick McHardy3e9b4600b2008-03-25 20:17:55 -0700727 const char *start = dptr, *limit = dptr + datalen;
728 int shift = 0;
729
Patrick McHardy9a664822012-08-26 19:14:25 +0200730 hdrs = nf_ct_l3num(ct) == NFPROTO_IPV4 ? ct_sdp_hdrs_v4 : ct_sdp_hdrs_v6;
731 hdr = &hdrs[type];
732 thdr = &hdrs[term];
733
Patrick McHardy3e9b4600b2008-03-25 20:17:55 -0700734 for (dptr += dataoff; dptr < limit; dptr++) {
735 /* Find beginning of line */
736 if (*dptr != '\r' && *dptr != '\n')
737 continue;
738 if (++dptr >= limit)
739 break;
740 if (*(dptr - 1) == '\r' && *dptr == '\n') {
741 if (++dptr >= limit)
742 break;
743 }
744
745 if (term != SDP_HDR_UNSPEC &&
746 limit - dptr >= thdr->len &&
Rasmus Villemoes18082742014-10-13 15:54:31 -0700747 strncasecmp(dptr, thdr->name, thdr->len) == 0)
Patrick McHardy3e9b4600b2008-03-25 20:17:55 -0700748 break;
749 else if (limit - dptr >= hdr->len &&
Rasmus Villemoes18082742014-10-13 15:54:31 -0700750 strncasecmp(dptr, hdr->name, hdr->len) == 0)
Patrick McHardy3e9b4600b2008-03-25 20:17:55 -0700751 dptr += hdr->len;
752 else
753 continue;
754
755 *matchoff = dptr - start;
756 if (hdr->search) {
757 dptr = ct_sdp_header_search(dptr, limit, hdr->search,
758 hdr->slen);
759 if (!dptr)
760 return -1;
761 dptr += hdr->slen;
762 }
763
764 *matchlen = hdr->match_len(ct, dptr, limit, &shift);
765 if (!*matchlen)
766 return -1;
767 *matchoff = dptr - start + shift;
768 return 1;
769 }
770 return 0;
771}
772EXPORT_SYMBOL_GPL(ct_sip_get_sdp_header);
773
Patrick McHardy4ab9e642008-03-25 20:26:08 -0700774static int ct_sip_parse_sdp_addr(const struct nf_conn *ct, const char *dptr,
775 unsigned int dataoff, unsigned int datalen,
776 enum sdp_header_types type,
777 enum sdp_header_types term,
778 unsigned int *matchoff, unsigned int *matchlen,
779 union nf_inet_addr *addr)
780{
781 int ret;
782
783 ret = ct_sip_get_sdp_header(ct, dptr, dataoff, datalen, type, term,
784 matchoff, matchlen);
785 if (ret <= 0)
786 return ret;
787
Patrick McHardy02b69cb2012-08-09 10:08:46 +0000788 if (!sdp_parse_addr(ct, dptr + *matchoff, NULL, addr,
789 dptr + *matchoff + *matchlen))
Patrick McHardy4ab9e642008-03-25 20:26:08 -0700790 return -1;
791 return 1;
792}
793
Patrick McHardy0f32a402008-03-25 20:25:13 -0700794static int refresh_signalling_expectation(struct nf_conn *ct,
795 union nf_inet_addr *addr,
Patrick McHardyf5b321b2010-02-11 12:26:19 +0100796 u8 proto, __be16 port,
Patrick McHardy0f32a402008-03-25 20:25:13 -0700797 unsigned int expires)
798{
799 struct nf_conn_help *help = nfct_help(ct);
800 struct nf_conntrack_expect *exp;
Sasha Levinb67bfe02013-02-27 17:06:00 -0800801 struct hlist_node *next;
Patrick McHardy0f32a402008-03-25 20:25:13 -0700802 int found = 0;
803
Jesper Dangaard Brouerca7433d2014-03-03 14:46:01 +0100804 spin_lock_bh(&nf_conntrack_expect_lock);
Sasha Levinb67bfe02013-02-27 17:06:00 -0800805 hlist_for_each_entry_safe(exp, next, &help->expectations, lnode) {
Patrick McHardy0f32a402008-03-25 20:25:13 -0700806 if (exp->class != SIP_EXPECT_SIGNALLING ||
807 !nf_inet_addr_cmp(&exp->tuple.dst.u3, addr) ||
Patrick McHardyf5b321b2010-02-11 12:26:19 +0100808 exp->tuple.dst.protonum != proto ||
Patrick McHardy0f32a402008-03-25 20:25:13 -0700809 exp->tuple.dst.u.udp.port != port)
810 continue;
811 if (!del_timer(&exp->timeout))
812 continue;
813 exp->flags &= ~NF_CT_EXPECT_INACTIVE;
814 exp->timeout.expires = jiffies + expires * HZ;
815 add_timer(&exp->timeout);
816 found = 1;
817 break;
818 }
Jesper Dangaard Brouerca7433d2014-03-03 14:46:01 +0100819 spin_unlock_bh(&nf_conntrack_expect_lock);
Patrick McHardy0f32a402008-03-25 20:25:13 -0700820 return found;
821}
822
823static void flush_expectations(struct nf_conn *ct, bool media)
Patrick McHardy9467ee32008-03-25 20:24:04 -0700824{
825 struct nf_conn_help *help = nfct_help(ct);
826 struct nf_conntrack_expect *exp;
Sasha Levinb67bfe02013-02-27 17:06:00 -0800827 struct hlist_node *next;
Patrick McHardy9467ee32008-03-25 20:24:04 -0700828
Jesper Dangaard Brouerca7433d2014-03-03 14:46:01 +0100829 spin_lock_bh(&nf_conntrack_expect_lock);
Sasha Levinb67bfe02013-02-27 17:06:00 -0800830 hlist_for_each_entry_safe(exp, next, &help->expectations, lnode) {
Patrick McHardy0f32a402008-03-25 20:25:13 -0700831 if ((exp->class != SIP_EXPECT_SIGNALLING) ^ media)
832 continue;
Patrick McHardy9467ee32008-03-25 20:24:04 -0700833 if (!del_timer(&exp->timeout))
834 continue;
835 nf_ct_unlink_expect(exp);
836 nf_ct_expect_put(exp);
Patrick McHardy0f32a402008-03-25 20:25:13 -0700837 if (!media)
838 break;
Patrick McHardy9467ee32008-03-25 20:24:04 -0700839 }
Jesper Dangaard Brouerca7433d2014-03-03 14:46:01 +0100840 spin_unlock_bh(&nf_conntrack_expect_lock);
Patrick McHardy9467ee32008-03-25 20:24:04 -0700841}
842
Patrick McHardy051966c2012-08-26 19:14:04 +0200843static int set_expected_rtp_rtcp(struct sk_buff *skb, unsigned int protoff,
844 unsigned int dataoff,
Patrick McHardya9c1d352008-03-25 20:25:49 -0700845 const char **dptr, unsigned int *datalen,
Patrick McHardy4ab9e642008-03-25 20:26:08 -0700846 union nf_inet_addr *daddr, __be16 port,
Patrick McHardy0d0ab032008-03-25 20:26:24 -0700847 enum sip_expectation_classes class,
Patrick McHardy4ab9e642008-03-25 20:26:08 -0700848 unsigned int mediaoff, unsigned int medialen)
Patrick McHardy9fafcd72006-12-02 22:09:57 -0800849{
Patrick McHardya9c1d352008-03-25 20:25:49 -0700850 struct nf_conntrack_expect *exp, *rtp_exp, *rtcp_exp;
Patrick McHardy212440a2008-03-25 20:17:13 -0700851 enum ip_conntrack_info ctinfo;
852 struct nf_conn *ct = nf_ct_get(skb, &ctinfo);
Alexey Dobriyana5c3a802008-10-08 11:35:09 +0200853 struct net *net = nf_ct_net(ct);
Patrick McHardy9fafcd72006-12-02 22:09:57 -0800854 enum ip_conntrack_dir dir = CTINFO2DIR(ctinfo);
Patrick McHardyd901a932008-03-25 20:25:32 -0700855 union nf_inet_addr *saddr;
856 struct nf_conntrack_tuple tuple;
Patrick McHardyc7f485a2008-03-25 20:26:43 -0700857 int direct_rtp = 0, skip_expect = 0, ret = NF_DROP;
Patrick McHardya9c1d352008-03-25 20:25:49 -0700858 u_int16_t base_port;
859 __be16 rtp_port, rtcp_port;
holger@eitzenberger.org180cf722013-09-30 17:07:28 +0200860 const struct nf_nat_sip_hooks *hooks;
Patrick McHardy9fafcd72006-12-02 22:09:57 -0800861
Patrick McHardyd901a932008-03-25 20:25:32 -0700862 saddr = NULL;
863 if (sip_direct_media) {
864 if (!nf_inet_addr_cmp(daddr, &ct->tuplehash[dir].tuple.src.u3))
865 return NF_ACCEPT;
866 saddr = &ct->tuplehash[!dir].tuple.src.u3;
867 }
868
869 /* We need to check whether the registration exists before attempting
870 * to register it since we can see the same media description multiple
871 * times on different connections in case multiple endpoints receive
872 * the same call.
Patrick McHardyc7f485a2008-03-25 20:26:43 -0700873 *
874 * RTP optimization: if we find a matching media channel expectation
875 * and both the expectation and this connection are SNATed, we assume
876 * both sides can reach each other directly and use the final
877 * destination address from the expectation. We still need to keep
878 * the NATed expectations for media that might arrive from the
879 * outside, and additionally need to expect the direct RTP stream
880 * in case it passes through us even without NAT.
Patrick McHardyd901a932008-03-25 20:25:32 -0700881 */
882 memset(&tuple, 0, sizeof(tuple));
883 if (saddr)
884 tuple.src.u3 = *saddr;
Patrick McHardy5e8fbe22008-04-14 11:15:52 +0200885 tuple.src.l3num = nf_ct_l3num(ct);
Patrick McHardyd901a932008-03-25 20:25:32 -0700886 tuple.dst.protonum = IPPROTO_UDP;
887 tuple.dst.u3 = *daddr;
888 tuple.dst.u.udp.port = port;
889
890 rcu_read_lock();
Patrick McHardyc7f485a2008-03-25 20:26:43 -0700891 do {
Patrick McHardy5d0aa2c2010-02-15 18:13:33 +0100892 exp = __nf_ct_expect_find(net, nf_ct_zone(ct), &tuple);
Patrick McHardyd901a932008-03-25 20:25:32 -0700893
Patrick McHardyc7f485a2008-03-25 20:26:43 -0700894 if (!exp || exp->master == ct ||
895 nfct_help(exp->master)->helper != nfct_help(ct)->helper ||
896 exp->class != class)
897 break;
Patrick McHardye1f9a462008-04-19 17:53:52 -0700898#ifdef CONFIG_NF_NAT_NEEDED
Patrick McHardy9a664822012-08-26 19:14:25 +0200899 if (!direct_rtp &&
900 (!nf_inet_addr_cmp(&exp->saved_addr, &exp->tuple.dst.u3) ||
Patrick McHardyc7f485a2008-03-25 20:26:43 -0700901 exp->saved_proto.udp.port != exp->tuple.dst.u.udp.port) &&
902 ct->status & IPS_NAT_MASK) {
Patrick McHardy9a664822012-08-26 19:14:25 +0200903 *daddr = exp->saved_addr;
904 tuple.dst.u3 = exp->saved_addr;
Patrick McHardyc7f485a2008-03-25 20:26:43 -0700905 tuple.dst.u.udp.port = exp->saved_proto.udp.port;
906 direct_rtp = 1;
907 } else
Patrick McHardye1f9a462008-04-19 17:53:52 -0700908#endif
Patrick McHardyc7f485a2008-03-25 20:26:43 -0700909 skip_expect = 1;
910 } while (!skip_expect);
Patrick McHardyd901a932008-03-25 20:25:32 -0700911
Patrick McHardya9c1d352008-03-25 20:25:49 -0700912 base_port = ntohs(tuple.dst.u.udp.port) & ~1;
913 rtp_port = htons(base_port);
914 rtcp_port = htons(base_port + 1);
915
Patrick McHardyc7f485a2008-03-25 20:26:43 -0700916 if (direct_rtp) {
holger@eitzenberger.org180cf722013-09-30 17:07:28 +0200917 hooks = rcu_dereference(nf_nat_sip_hooks);
918 if (hooks &&
919 !hooks->sdp_port(skb, protoff, dataoff, dptr, datalen,
Patrick McHardyc7f485a2008-03-25 20:26:43 -0700920 mediaoff, medialen, ntohs(rtp_port)))
921 goto err1;
922 }
923
holger@eitzenberger.orgb21613a2013-09-20 22:43:04 +0200924 if (skip_expect) {
925 rcu_read_unlock();
Patrick McHardyc7f485a2008-03-25 20:26:43 -0700926 return NF_ACCEPT;
holger@eitzenberger.orgb21613a2013-09-20 22:43:04 +0200927 }
Patrick McHardyc7f485a2008-03-25 20:26:43 -0700928
Patrick McHardya9c1d352008-03-25 20:25:49 -0700929 rtp_exp = nf_ct_expect_alloc(ct);
930 if (rtp_exp == NULL)
931 goto err1;
Patrick McHardy5e8fbe22008-04-14 11:15:52 +0200932 nf_ct_expect_init(rtp_exp, class, nf_ct_l3num(ct), saddr, daddr,
Patrick McHardya9c1d352008-03-25 20:25:49 -0700933 IPPROTO_UDP, NULL, &rtp_port);
934
935 rtcp_exp = nf_ct_expect_alloc(ct);
936 if (rtcp_exp == NULL)
937 goto err2;
Patrick McHardy5e8fbe22008-04-14 11:15:52 +0200938 nf_ct_expect_init(rtcp_exp, class, nf_ct_l3num(ct), saddr, daddr,
Patrick McHardya9c1d352008-03-25 20:25:49 -0700939 IPPROTO_UDP, NULL, &rtcp_port);
Patrick McHardy9fafcd72006-12-02 22:09:57 -0800940
holger@eitzenberger.org180cf722013-09-30 17:07:28 +0200941 hooks = rcu_dereference(nf_nat_sip_hooks);
942 if (hooks && ct->status & IPS_NAT_MASK && !direct_rtp)
943 ret = hooks->sdp_media(skb, protoff, dataoff, dptr,
944 datalen, rtp_exp, rtcp_exp,
Patrick McHardy4ab9e642008-03-25 20:26:08 -0700945 mediaoff, medialen, daddr);
Patrick McHardy9fafcd72006-12-02 22:09:57 -0800946 else {
Patrick McHardya9c1d352008-03-25 20:25:49 -0700947 if (nf_ct_expect_related(rtp_exp) == 0) {
948 if (nf_ct_expect_related(rtcp_exp) != 0)
949 nf_ct_unexpect_related(rtp_exp);
950 else
951 ret = NF_ACCEPT;
952 }
Patrick McHardy9fafcd72006-12-02 22:09:57 -0800953 }
Patrick McHardya9c1d352008-03-25 20:25:49 -0700954 nf_ct_expect_put(rtcp_exp);
955err2:
956 nf_ct_expect_put(rtp_exp);
957err1:
holger@eitzenberger.orgb21613a2013-09-20 22:43:04 +0200958 rcu_read_unlock();
Patrick McHardy9fafcd72006-12-02 22:09:57 -0800959 return ret;
960}
961
Patrick McHardy0d0ab032008-03-25 20:26:24 -0700962static const struct sdp_media_type sdp_media_types[] = {
963 SDP_MEDIA_TYPE("audio ", SIP_EXPECT_AUDIO),
964 SDP_MEDIA_TYPE("video ", SIP_EXPECT_VIDEO),
Patrick McHardy9d288df2010-02-11 12:30:21 +0100965 SDP_MEDIA_TYPE("image ", SIP_EXPECT_IMAGE),
Patrick McHardy0d0ab032008-03-25 20:26:24 -0700966};
967
968static const struct sdp_media_type *sdp_media_type(const char *dptr,
969 unsigned int matchoff,
970 unsigned int matchlen)
971{
972 const struct sdp_media_type *t;
973 unsigned int i;
974
975 for (i = 0; i < ARRAY_SIZE(sdp_media_types); i++) {
976 t = &sdp_media_types[i];
977 if (matchlen < t->len ||
978 strncmp(dptr + matchoff, t->name, t->len))
979 continue;
980 return t;
981 }
982 return NULL;
983}
984
Patrick McHardy051966c2012-08-26 19:14:04 +0200985static int process_sdp(struct sk_buff *skb, unsigned int protoff,
986 unsigned int dataoff,
Patrick McHardy30f33e62008-03-25 20:22:20 -0700987 const char **dptr, unsigned int *datalen,
988 unsigned int cseq)
Patrick McHardy7d3dd042008-03-25 20:19:46 -0700989{
990 enum ip_conntrack_info ctinfo;
991 struct nf_conn *ct = nf_ct_get(skb, &ctinfo);
Patrick McHardy7d3dd042008-03-25 20:19:46 -0700992 unsigned int matchoff, matchlen;
Patrick McHardy4ab9e642008-03-25 20:26:08 -0700993 unsigned int mediaoff, medialen;
994 unsigned int sdpoff;
995 unsigned int caddr_len, maddr_len;
Patrick McHardy0d0ab032008-03-25 20:26:24 -0700996 unsigned int i;
Patrick McHardy4ab9e642008-03-25 20:26:08 -0700997 union nf_inet_addr caddr, maddr, rtp_addr;
holger@eitzenberger.org180cf722013-09-30 17:07:28 +0200998 const struct nf_nat_sip_hooks *hooks;
Patrick McHardy7d3dd042008-03-25 20:19:46 -0700999 unsigned int port;
Patrick McHardy0d0ab032008-03-25 20:26:24 -07001000 const struct sdp_media_type *t;
1001 int ret = NF_ACCEPT;
Patrick McHardy7d3dd042008-03-25 20:19:46 -07001002
holger@eitzenberger.org180cf722013-09-30 17:07:28 +02001003 hooks = rcu_dereference(nf_nat_sip_hooks);
Patrick McHardy7d3dd042008-03-25 20:19:46 -07001004
Patrick McHardy4ab9e642008-03-25 20:26:08 -07001005 /* Find beginning of session description */
Patrick McHardy7d3dd042008-03-25 20:19:46 -07001006 if (ct_sip_get_sdp_header(ct, *dptr, 0, *datalen,
Patrick McHardy4ab9e642008-03-25 20:26:08 -07001007 SDP_HDR_VERSION, SDP_HDR_UNSPEC,
Patrick McHardy7d3dd042008-03-25 20:19:46 -07001008 &matchoff, &matchlen) <= 0)
1009 return NF_ACCEPT;
Patrick McHardy4ab9e642008-03-25 20:26:08 -07001010 sdpoff = matchoff;
Patrick McHardy7d3dd042008-03-25 20:19:46 -07001011
Patrick McHardy4ab9e642008-03-25 20:26:08 -07001012 /* The connection information is contained in the session description
1013 * and/or once per media description. The first media description marks
1014 * the end of the session description. */
1015 caddr_len = 0;
1016 if (ct_sip_parse_sdp_addr(ct, *dptr, sdpoff, *datalen,
Patrick McHardy9a664822012-08-26 19:14:25 +02001017 SDP_HDR_CONNECTION, SDP_HDR_MEDIA,
Patrick McHardy4ab9e642008-03-25 20:26:08 -07001018 &matchoff, &matchlen, &caddr) > 0)
1019 caddr_len = matchlen;
Patrick McHardy7d3dd042008-03-25 20:19:46 -07001020
Patrick McHardy0d0ab032008-03-25 20:26:24 -07001021 mediaoff = sdpoff;
1022 for (i = 0; i < ARRAY_SIZE(sdp_media_types); ) {
1023 if (ct_sip_get_sdp_header(ct, *dptr, mediaoff, *datalen,
1024 SDP_HDR_MEDIA, SDP_HDR_UNSPEC,
1025 &mediaoff, &medialen) <= 0)
1026 break;
Patrick McHardy7d3dd042008-03-25 20:19:46 -07001027
Patrick McHardy0d0ab032008-03-25 20:26:24 -07001028 /* Get media type and port number. A media port value of zero
1029 * indicates an inactive stream. */
1030 t = sdp_media_type(*dptr, mediaoff, medialen);
1031 if (!t) {
1032 mediaoff += medialen;
1033 continue;
1034 }
1035 mediaoff += t->len;
1036 medialen -= t->len;
Patrick McHardy7d3dd042008-03-25 20:19:46 -07001037
Patrick McHardy0d0ab032008-03-25 20:26:24 -07001038 port = simple_strtoul(*dptr + mediaoff, NULL, 10);
1039 if (port == 0)
1040 continue;
Pablo Neira Ayusob20ab9cc2013-02-10 18:56:56 +01001041 if (port < 1024 || port > 65535) {
1042 nf_ct_helper_log(skb, ct, "wrong port %u", port);
Patrick McHardy0d0ab032008-03-25 20:26:24 -07001043 return NF_DROP;
Pablo Neira Ayusob20ab9cc2013-02-10 18:56:56 +01001044 }
Patrick McHardy4ab9e642008-03-25 20:26:08 -07001045
Patrick McHardy0d0ab032008-03-25 20:26:24 -07001046 /* The media description overrides the session description. */
1047 maddr_len = 0;
1048 if (ct_sip_parse_sdp_addr(ct, *dptr, mediaoff, *datalen,
Patrick McHardy9a664822012-08-26 19:14:25 +02001049 SDP_HDR_CONNECTION, SDP_HDR_MEDIA,
Patrick McHardy0d0ab032008-03-25 20:26:24 -07001050 &matchoff, &matchlen, &maddr) > 0) {
1051 maddr_len = matchlen;
1052 memcpy(&rtp_addr, &maddr, sizeof(rtp_addr));
1053 } else if (caddr_len)
1054 memcpy(&rtp_addr, &caddr, sizeof(rtp_addr));
Pablo Neira Ayusob20ab9cc2013-02-10 18:56:56 +01001055 else {
1056 nf_ct_helper_log(skb, ct, "cannot parse SDP message");
Patrick McHardy0d0ab032008-03-25 20:26:24 -07001057 return NF_DROP;
Pablo Neira Ayusob20ab9cc2013-02-10 18:56:56 +01001058 }
Patrick McHardy4ab9e642008-03-25 20:26:08 -07001059
Patrick McHardy051966c2012-08-26 19:14:04 +02001060 ret = set_expected_rtp_rtcp(skb, protoff, dataoff,
1061 dptr, datalen,
Patrick McHardy0d0ab032008-03-25 20:26:24 -07001062 &rtp_addr, htons(port), t->class,
1063 mediaoff, medialen);
Pablo Neira Ayusob20ab9cc2013-02-10 18:56:56 +01001064 if (ret != NF_ACCEPT) {
1065 nf_ct_helper_log(skb, ct,
1066 "cannot add expectation for voice");
Patrick McHardy0d0ab032008-03-25 20:26:24 -07001067 return ret;
Pablo Neira Ayusob20ab9cc2013-02-10 18:56:56 +01001068 }
Patrick McHardy0d0ab032008-03-25 20:26:24 -07001069
1070 /* Update media connection address if present */
holger@eitzenberger.org180cf722013-09-30 17:07:28 +02001071 if (maddr_len && hooks && ct->status & IPS_NAT_MASK) {
1072 ret = hooks->sdp_addr(skb, protoff, dataoff,
Patrick McHardy9a664822012-08-26 19:14:25 +02001073 dptr, datalen, mediaoff,
holger@eitzenberger.org180cf722013-09-30 17:07:28 +02001074 SDP_HDR_CONNECTION,
1075 SDP_HDR_MEDIA,
Patrick McHardy3b6b9fa2010-02-11 12:23:53 +01001076 &rtp_addr);
Pablo Neira Ayusob20ab9cc2013-02-10 18:56:56 +01001077 if (ret != NF_ACCEPT) {
1078 nf_ct_helper_log(skb, ct, "cannot mangle SDP");
Patrick McHardy4ab9e642008-03-25 20:26:08 -07001079 return ret;
Pablo Neira Ayusob20ab9cc2013-02-10 18:56:56 +01001080 }
Patrick McHardy4ab9e642008-03-25 20:26:08 -07001081 }
Patrick McHardy0d0ab032008-03-25 20:26:24 -07001082 i++;
Patrick McHardy4ab9e642008-03-25 20:26:08 -07001083 }
1084
1085 /* Update session connection and owner addresses */
holger@eitzenberger.org180cf722013-09-30 17:07:28 +02001086 hooks = rcu_dereference(nf_nat_sip_hooks);
1087 if (hooks && ct->status & IPS_NAT_MASK)
1088 ret = hooks->sdp_session(skb, protoff, dataoff,
1089 dptr, datalen, sdpoff,
1090 &rtp_addr);
Patrick McHardy4ab9e642008-03-25 20:26:08 -07001091
1092 return ret;
Patrick McHardy7d3dd042008-03-25 20:19:46 -07001093}
Patrick McHardy051966c2012-08-26 19:14:04 +02001094static int process_invite_response(struct sk_buff *skb, unsigned int protoff,
1095 unsigned int dataoff,
Patrick McHardy30f33e62008-03-25 20:22:20 -07001096 const char **dptr, unsigned int *datalen,
1097 unsigned int cseq, unsigned int code)
1098{
Patrick McHardy9467ee32008-03-25 20:24:04 -07001099 enum ip_conntrack_info ctinfo;
1100 struct nf_conn *ct = nf_ct_get(skb, &ctinfo);
Pablo Neira Ayuso1afc5672012-06-07 12:11:50 +02001101 struct nf_ct_sip_master *ct_sip_info = nfct_help_data(ct);
Patrick McHardy9467ee32008-03-25 20:24:04 -07001102
Patrick McHardy30f33e62008-03-25 20:22:20 -07001103 if ((code >= 100 && code <= 199) ||
1104 (code >= 200 && code <= 299))
Patrick McHardy051966c2012-08-26 19:14:04 +02001105 return process_sdp(skb, protoff, dataoff, dptr, datalen, cseq);
Pablo Neira Ayuso1afc5672012-06-07 12:11:50 +02001106 else if (ct_sip_info->invite_cseq == cseq)
Patrick McHardy0f32a402008-03-25 20:25:13 -07001107 flush_expectations(ct, true);
Patrick McHardyef75d492008-05-08 01:15:21 -07001108 return NF_ACCEPT;
Patrick McHardy30f33e62008-03-25 20:22:20 -07001109}
1110
Patrick McHardy051966c2012-08-26 19:14:04 +02001111static int process_update_response(struct sk_buff *skb, unsigned int protoff,
1112 unsigned int dataoff,
Patrick McHardy30f33e62008-03-25 20:22:20 -07001113 const char **dptr, unsigned int *datalen,
1114 unsigned int cseq, unsigned int code)
1115{
Patrick McHardy9467ee32008-03-25 20:24:04 -07001116 enum ip_conntrack_info ctinfo;
1117 struct nf_conn *ct = nf_ct_get(skb, &ctinfo);
Pablo Neira Ayuso1afc5672012-06-07 12:11:50 +02001118 struct nf_ct_sip_master *ct_sip_info = nfct_help_data(ct);
Patrick McHardy9467ee32008-03-25 20:24:04 -07001119
Patrick McHardy30f33e62008-03-25 20:22:20 -07001120 if ((code >= 100 && code <= 199) ||
1121 (code >= 200 && code <= 299))
Patrick McHardy051966c2012-08-26 19:14:04 +02001122 return process_sdp(skb, protoff, dataoff, dptr, datalen, cseq);
Pablo Neira Ayuso1afc5672012-06-07 12:11:50 +02001123 else if (ct_sip_info->invite_cseq == cseq)
Patrick McHardy0f32a402008-03-25 20:25:13 -07001124 flush_expectations(ct, true);
Patrick McHardyef75d492008-05-08 01:15:21 -07001125 return NF_ACCEPT;
Patrick McHardy30f33e62008-03-25 20:22:20 -07001126}
1127
Patrick McHardy051966c2012-08-26 19:14:04 +02001128static int process_prack_response(struct sk_buff *skb, unsigned int protoff,
1129 unsigned int dataoff,
Patrick McHardy595a8ec2008-03-25 20:22:53 -07001130 const char **dptr, unsigned int *datalen,
1131 unsigned int cseq, unsigned int code)
1132{
Patrick McHardy9467ee32008-03-25 20:24:04 -07001133 enum ip_conntrack_info ctinfo;
1134 struct nf_conn *ct = nf_ct_get(skb, &ctinfo);
Pablo Neira Ayuso1afc5672012-06-07 12:11:50 +02001135 struct nf_ct_sip_master *ct_sip_info = nfct_help_data(ct);
Patrick McHardy9467ee32008-03-25 20:24:04 -07001136
Patrick McHardy595a8ec2008-03-25 20:22:53 -07001137 if ((code >= 100 && code <= 199) ||
1138 (code >= 200 && code <= 299))
Patrick McHardy051966c2012-08-26 19:14:04 +02001139 return process_sdp(skb, protoff, dataoff, dptr, datalen, cseq);
Pablo Neira Ayuso1afc5672012-06-07 12:11:50 +02001140 else if (ct_sip_info->invite_cseq == cseq)
Patrick McHardy0f32a402008-03-25 20:25:13 -07001141 flush_expectations(ct, true);
Patrick McHardyef75d492008-05-08 01:15:21 -07001142 return NF_ACCEPT;
Patrick McHardy9467ee32008-03-25 20:24:04 -07001143}
Patrick McHardy595a8ec2008-03-25 20:22:53 -07001144
Patrick McHardy051966c2012-08-26 19:14:04 +02001145static int process_invite_request(struct sk_buff *skb, unsigned int protoff,
1146 unsigned int dataoff,
Patrick McHardy9d288df2010-02-11 12:30:21 +01001147 const char **dptr, unsigned int *datalen,
1148 unsigned int cseq)
1149{
1150 enum ip_conntrack_info ctinfo;
1151 struct nf_conn *ct = nf_ct_get(skb, &ctinfo);
Pablo Neira Ayuso1afc5672012-06-07 12:11:50 +02001152 struct nf_ct_sip_master *ct_sip_info = nfct_help_data(ct);
Patrick McHardy9d288df2010-02-11 12:30:21 +01001153 unsigned int ret;
1154
1155 flush_expectations(ct, true);
Patrick McHardy051966c2012-08-26 19:14:04 +02001156 ret = process_sdp(skb, protoff, dataoff, dptr, datalen, cseq);
Patrick McHardy9d288df2010-02-11 12:30:21 +01001157 if (ret == NF_ACCEPT)
Pablo Neira Ayuso1afc5672012-06-07 12:11:50 +02001158 ct_sip_info->invite_cseq = cseq;
Patrick McHardy9d288df2010-02-11 12:30:21 +01001159 return ret;
1160}
1161
Patrick McHardy051966c2012-08-26 19:14:04 +02001162static int process_bye_request(struct sk_buff *skb, unsigned int protoff,
1163 unsigned int dataoff,
Patrick McHardy9467ee32008-03-25 20:24:04 -07001164 const char **dptr, unsigned int *datalen,
1165 unsigned int cseq)
1166{
1167 enum ip_conntrack_info ctinfo;
1168 struct nf_conn *ct = nf_ct_get(skb, &ctinfo);
1169
Patrick McHardy0f32a402008-03-25 20:25:13 -07001170 flush_expectations(ct, true);
1171 return NF_ACCEPT;
1172}
1173
1174/* Parse a REGISTER request and create a permanent expectation for incoming
1175 * signalling connections. The expectation is marked inactive and is activated
1176 * when receiving a response indicating success from the registrar.
1177 */
Patrick McHardy051966c2012-08-26 19:14:04 +02001178static int process_register_request(struct sk_buff *skb, unsigned int protoff,
1179 unsigned int dataoff,
Patrick McHardy0f32a402008-03-25 20:25:13 -07001180 const char **dptr, unsigned int *datalen,
1181 unsigned int cseq)
1182{
1183 enum ip_conntrack_info ctinfo;
1184 struct nf_conn *ct = nf_ct_get(skb, &ctinfo);
Pablo Neira Ayuso1afc5672012-06-07 12:11:50 +02001185 struct nf_ct_sip_master *ct_sip_info = nfct_help_data(ct);
Patrick McHardy0f32a402008-03-25 20:25:13 -07001186 enum ip_conntrack_dir dir = CTINFO2DIR(ctinfo);
Patrick McHardy0f32a402008-03-25 20:25:13 -07001187 unsigned int matchoff, matchlen;
1188 struct nf_conntrack_expect *exp;
1189 union nf_inet_addr *saddr, daddr;
holger@eitzenberger.org180cf722013-09-30 17:07:28 +02001190 const struct nf_nat_sip_hooks *hooks;
Patrick McHardy0f32a402008-03-25 20:25:13 -07001191 __be16 port;
Patrick McHardyf5b321b2010-02-11 12:26:19 +01001192 u8 proto;
Patrick McHardy0f32a402008-03-25 20:25:13 -07001193 unsigned int expires = 0;
1194 int ret;
Patrick McHardy0f32a402008-03-25 20:25:13 -07001195
1196 /* Expected connections can not register again. */
1197 if (ct->status & IPS_EXPECTED)
1198 return NF_ACCEPT;
1199
1200 /* We must check the expiration time: a value of zero signals the
1201 * registrar to release the binding. We'll remove our expectation
1202 * when receiving the new bindings in the response, but we don't
1203 * want to create new ones.
1204 *
1205 * The expiration time may be contained in Expires: header, the
1206 * Contact: header parameters or the URI parameters.
1207 */
1208 if (ct_sip_get_header(ct, *dptr, 0, *datalen, SIP_HDR_EXPIRES,
1209 &matchoff, &matchlen) > 0)
1210 expires = simple_strtoul(*dptr + matchoff, NULL, 10);
1211
1212 ret = ct_sip_parse_header_uri(ct, *dptr, NULL, *datalen,
1213 SIP_HDR_CONTACT, NULL,
1214 &matchoff, &matchlen, &daddr, &port);
Pablo Neira Ayusob20ab9cc2013-02-10 18:56:56 +01001215 if (ret < 0) {
1216 nf_ct_helper_log(skb, ct, "cannot parse contact");
Patrick McHardy0f32a402008-03-25 20:25:13 -07001217 return NF_DROP;
Pablo Neira Ayusob20ab9cc2013-02-10 18:56:56 +01001218 } else if (ret == 0)
Patrick McHardy0f32a402008-03-25 20:25:13 -07001219 return NF_ACCEPT;
1220
1221 /* We don't support third-party registrations */
1222 if (!nf_inet_addr_cmp(&ct->tuplehash[dir].tuple.src.u3, &daddr))
1223 return NF_ACCEPT;
1224
Patrick McHardyf5b321b2010-02-11 12:26:19 +01001225 if (ct_sip_parse_transport(ct, *dptr, matchoff + matchlen, *datalen,
1226 &proto) == 0)
1227 return NF_ACCEPT;
1228
Patrick McHardy0f32a402008-03-25 20:25:13 -07001229 if (ct_sip_parse_numerical_param(ct, *dptr,
1230 matchoff + matchlen, *datalen,
Pablo Neira Ayusob20ab9cc2013-02-10 18:56:56 +01001231 "expires=", NULL, NULL, &expires) < 0) {
1232 nf_ct_helper_log(skb, ct, "cannot parse expires");
Patrick McHardy0f32a402008-03-25 20:25:13 -07001233 return NF_DROP;
Pablo Neira Ayusob20ab9cc2013-02-10 18:56:56 +01001234 }
Patrick McHardy0f32a402008-03-25 20:25:13 -07001235
1236 if (expires == 0) {
1237 ret = NF_ACCEPT;
1238 goto store_cseq;
1239 }
1240
1241 exp = nf_ct_expect_alloc(ct);
Pablo Neira Ayusob20ab9cc2013-02-10 18:56:56 +01001242 if (!exp) {
1243 nf_ct_helper_log(skb, ct, "cannot alloc expectation");
Patrick McHardy0f32a402008-03-25 20:25:13 -07001244 return NF_DROP;
Pablo Neira Ayusob20ab9cc2013-02-10 18:56:56 +01001245 }
Patrick McHardy0f32a402008-03-25 20:25:13 -07001246
1247 saddr = NULL;
1248 if (sip_direct_signalling)
1249 saddr = &ct->tuplehash[!dir].tuple.src.u3;
1250
Patrick McHardy5e8fbe22008-04-14 11:15:52 +02001251 nf_ct_expect_init(exp, SIP_EXPECT_SIGNALLING, nf_ct_l3num(ct),
Patrick McHardyf5b321b2010-02-11 12:26:19 +01001252 saddr, &daddr, proto, NULL, &port);
Patrick McHardy0f32a402008-03-25 20:25:13 -07001253 exp->timeout.expires = sip_timeout * HZ;
1254 exp->helper = nfct_help(ct)->helper;
1255 exp->flags = NF_CT_EXPECT_PERMANENT | NF_CT_EXPECT_INACTIVE;
1256
holger@eitzenberger.org180cf722013-09-30 17:07:28 +02001257 hooks = rcu_dereference(nf_nat_sip_hooks);
1258 if (hooks && ct->status & IPS_NAT_MASK)
1259 ret = hooks->expect(skb, protoff, dataoff, dptr, datalen,
1260 exp, matchoff, matchlen);
Patrick McHardy0f32a402008-03-25 20:25:13 -07001261 else {
Pablo Neira Ayusob20ab9cc2013-02-10 18:56:56 +01001262 if (nf_ct_expect_related(exp) != 0) {
1263 nf_ct_helper_log(skb, ct, "cannot add expectation");
Patrick McHardy0f32a402008-03-25 20:25:13 -07001264 ret = NF_DROP;
Pablo Neira Ayusob20ab9cc2013-02-10 18:56:56 +01001265 } else
Patrick McHardy0f32a402008-03-25 20:25:13 -07001266 ret = NF_ACCEPT;
1267 }
1268 nf_ct_expect_put(exp);
1269
1270store_cseq:
1271 if (ret == NF_ACCEPT)
Pablo Neira Ayuso1afc5672012-06-07 12:11:50 +02001272 ct_sip_info->register_cseq = cseq;
Patrick McHardy0f32a402008-03-25 20:25:13 -07001273 return ret;
1274}
1275
Patrick McHardy051966c2012-08-26 19:14:04 +02001276static int process_register_response(struct sk_buff *skb, unsigned int protoff,
1277 unsigned int dataoff,
Patrick McHardy0f32a402008-03-25 20:25:13 -07001278 const char **dptr, unsigned int *datalen,
1279 unsigned int cseq, unsigned int code)
1280{
1281 enum ip_conntrack_info ctinfo;
1282 struct nf_conn *ct = nf_ct_get(skb, &ctinfo);
Pablo Neira Ayuso1afc5672012-06-07 12:11:50 +02001283 struct nf_ct_sip_master *ct_sip_info = nfct_help_data(ct);
Patrick McHardy0f32a402008-03-25 20:25:13 -07001284 enum ip_conntrack_dir dir = CTINFO2DIR(ctinfo);
1285 union nf_inet_addr addr;
1286 __be16 port;
Patrick McHardyf5b321b2010-02-11 12:26:19 +01001287 u8 proto;
Patrick McHardy3b6b9fa2010-02-11 12:23:53 +01001288 unsigned int matchoff, matchlen, coff = 0;
Patrick McHardy0f32a402008-03-25 20:25:13 -07001289 unsigned int expires = 0;
1290 int in_contact = 0, ret;
1291
1292 /* According to RFC 3261, "UAs MUST NOT send a new registration until
1293 * they have received a final response from the registrar for the
1294 * previous one or the previous REGISTER request has timed out".
1295 *
1296 * However, some servers fail to detect retransmissions and send late
1297 * responses, so we store the sequence number of the last valid
1298 * request and compare it here.
1299 */
Pablo Neira Ayuso1afc5672012-06-07 12:11:50 +02001300 if (ct_sip_info->register_cseq != cseq)
Patrick McHardy0f32a402008-03-25 20:25:13 -07001301 return NF_ACCEPT;
1302
1303 if (code >= 100 && code <= 199)
1304 return NF_ACCEPT;
1305 if (code < 200 || code > 299)
1306 goto flush;
1307
1308 if (ct_sip_get_header(ct, *dptr, 0, *datalen, SIP_HDR_EXPIRES,
1309 &matchoff, &matchlen) > 0)
1310 expires = simple_strtoul(*dptr + matchoff, NULL, 10);
1311
1312 while (1) {
1313 unsigned int c_expires = expires;
1314
Patrick McHardy3b6b9fa2010-02-11 12:23:53 +01001315 ret = ct_sip_parse_header_uri(ct, *dptr, &coff, *datalen,
Patrick McHardy0f32a402008-03-25 20:25:13 -07001316 SIP_HDR_CONTACT, &in_contact,
1317 &matchoff, &matchlen,
1318 &addr, &port);
Pablo Neira Ayusob20ab9cc2013-02-10 18:56:56 +01001319 if (ret < 0) {
1320 nf_ct_helper_log(skb, ct, "cannot parse contact");
Patrick McHardy0f32a402008-03-25 20:25:13 -07001321 return NF_DROP;
Pablo Neira Ayusob20ab9cc2013-02-10 18:56:56 +01001322 } else if (ret == 0)
Patrick McHardy0f32a402008-03-25 20:25:13 -07001323 break;
1324
1325 /* We don't support third-party registrations */
1326 if (!nf_inet_addr_cmp(&ct->tuplehash[dir].tuple.dst.u3, &addr))
1327 continue;
1328
Patrick McHardyf5b321b2010-02-11 12:26:19 +01001329 if (ct_sip_parse_transport(ct, *dptr, matchoff + matchlen,
1330 *datalen, &proto) == 0)
1331 continue;
1332
Patrick McHardy0f32a402008-03-25 20:25:13 -07001333 ret = ct_sip_parse_numerical_param(ct, *dptr,
1334 matchoff + matchlen,
1335 *datalen, "expires=",
1336 NULL, NULL, &c_expires);
Pablo Neira Ayusob20ab9cc2013-02-10 18:56:56 +01001337 if (ret < 0) {
1338 nf_ct_helper_log(skb, ct, "cannot parse expires");
Patrick McHardy0f32a402008-03-25 20:25:13 -07001339 return NF_DROP;
Pablo Neira Ayusob20ab9cc2013-02-10 18:56:56 +01001340 }
Patrick McHardy0f32a402008-03-25 20:25:13 -07001341 if (c_expires == 0)
1342 break;
Patrick McHardyf5b321b2010-02-11 12:26:19 +01001343 if (refresh_signalling_expectation(ct, &addr, proto, port,
1344 c_expires))
Patrick McHardy0f32a402008-03-25 20:25:13 -07001345 return NF_ACCEPT;
1346 }
1347
1348flush:
1349 flush_expectations(ct, false);
Patrick McHardy595a8ec2008-03-25 20:22:53 -07001350 return NF_ACCEPT;
1351}
1352
Patrick McHardy30f33e62008-03-25 20:22:20 -07001353static const struct sip_handler sip_handlers[] = {
Patrick McHardy9d288df2010-02-11 12:30:21 +01001354 SIP_HANDLER("INVITE", process_invite_request, process_invite_response),
Patrick McHardy30f33e62008-03-25 20:22:20 -07001355 SIP_HANDLER("UPDATE", process_sdp, process_update_response),
Patrick McHardy595a8ec2008-03-25 20:22:53 -07001356 SIP_HANDLER("ACK", process_sdp, NULL),
1357 SIP_HANDLER("PRACK", process_sdp, process_prack_response),
Patrick McHardy9467ee32008-03-25 20:24:04 -07001358 SIP_HANDLER("BYE", process_bye_request, NULL),
Patrick McHardy0f32a402008-03-25 20:25:13 -07001359 SIP_HANDLER("REGISTER", process_register_request, process_register_response),
Patrick McHardy30f33e62008-03-25 20:22:20 -07001360};
1361
Patrick McHardy051966c2012-08-26 19:14:04 +02001362static int process_sip_response(struct sk_buff *skb, unsigned int protoff,
1363 unsigned int dataoff,
Patrick McHardy30f33e62008-03-25 20:22:20 -07001364 const char **dptr, unsigned int *datalen)
1365{
Patrick McHardy30f33e62008-03-25 20:22:20 -07001366 enum ip_conntrack_info ctinfo;
1367 struct nf_conn *ct = nf_ct_get(skb, &ctinfo);
Patrick McHardy3b6b9fa2010-02-11 12:23:53 +01001368 unsigned int matchoff, matchlen, matchend;
1369 unsigned int code, cseq, i;
Patrick McHardy30f33e62008-03-25 20:22:20 -07001370
1371 if (*datalen < strlen("SIP/2.0 200"))
1372 return NF_ACCEPT;
1373 code = simple_strtoul(*dptr + strlen("SIP/2.0 "), NULL, 10);
Pablo Neira Ayusob20ab9cc2013-02-10 18:56:56 +01001374 if (!code) {
1375 nf_ct_helper_log(skb, ct, "cannot get code");
Patrick McHardy30f33e62008-03-25 20:22:20 -07001376 return NF_DROP;
Pablo Neira Ayusob20ab9cc2013-02-10 18:56:56 +01001377 }
Patrick McHardy30f33e62008-03-25 20:22:20 -07001378
1379 if (ct_sip_get_header(ct, *dptr, 0, *datalen, SIP_HDR_CSEQ,
Pablo Neira Ayusob20ab9cc2013-02-10 18:56:56 +01001380 &matchoff, &matchlen) <= 0) {
1381 nf_ct_helper_log(skb, ct, "cannot parse cseq");
Patrick McHardy30f33e62008-03-25 20:22:20 -07001382 return NF_DROP;
Pablo Neira Ayusob20ab9cc2013-02-10 18:56:56 +01001383 }
Patrick McHardy30f33e62008-03-25 20:22:20 -07001384 cseq = simple_strtoul(*dptr + matchoff, NULL, 10);
Christophe Leroy0d35d0812016-08-03 12:41:40 +02001385 if (!cseq && *(*dptr + matchoff) != '0') {
Pablo Neira Ayusob20ab9cc2013-02-10 18:56:56 +01001386 nf_ct_helper_log(skb, ct, "cannot get cseq");
Patrick McHardy30f33e62008-03-25 20:22:20 -07001387 return NF_DROP;
Pablo Neira Ayusob20ab9cc2013-02-10 18:56:56 +01001388 }
Patrick McHardy3b6b9fa2010-02-11 12:23:53 +01001389 matchend = matchoff + matchlen + 1;
Patrick McHardy30f33e62008-03-25 20:22:20 -07001390
1391 for (i = 0; i < ARRAY_SIZE(sip_handlers); i++) {
Alexey Dobriyan66bf7912008-09-07 18:19:25 -07001392 const struct sip_handler *handler;
1393
Patrick McHardy30f33e62008-03-25 20:22:20 -07001394 handler = &sip_handlers[i];
1395 if (handler->response == NULL)
1396 continue;
Patrick McHardy3b6b9fa2010-02-11 12:23:53 +01001397 if (*datalen < matchend + handler->len ||
Rasmus Villemoes18082742014-10-13 15:54:31 -07001398 strncasecmp(*dptr + matchend, handler->method, handler->len))
Patrick McHardy30f33e62008-03-25 20:22:20 -07001399 continue;
Patrick McHardy051966c2012-08-26 19:14:04 +02001400 return handler->response(skb, protoff, dataoff, dptr, datalen,
Patrick McHardy3b6b9fa2010-02-11 12:23:53 +01001401 cseq, code);
Patrick McHardy30f33e62008-03-25 20:22:20 -07001402 }
1403 return NF_ACCEPT;
1404}
1405
Patrick McHardy051966c2012-08-26 19:14:04 +02001406static int process_sip_request(struct sk_buff *skb, unsigned int protoff,
1407 unsigned int dataoff,
Patrick McHardy30f33e62008-03-25 20:22:20 -07001408 const char **dptr, unsigned int *datalen)
1409{
Patrick McHardy30f33e62008-03-25 20:22:20 -07001410 enum ip_conntrack_info ctinfo;
1411 struct nf_conn *ct = nf_ct_get(skb, &ctinfo);
Kevin Cernekee72665072012-12-17 18:33:58 +00001412 struct nf_ct_sip_master *ct_sip_info = nfct_help_data(ct);
1413 enum ip_conntrack_dir dir = CTINFO2DIR(ctinfo);
Patrick McHardy30f33e62008-03-25 20:22:20 -07001414 unsigned int matchoff, matchlen;
1415 unsigned int cseq, i;
Kevin Cernekee72665072012-12-17 18:33:58 +00001416 union nf_inet_addr addr;
1417 __be16 port;
1418
1419 /* Many Cisco IP phones use a high source port for SIP requests, but
1420 * listen for the response on port 5060. If we are the local
1421 * router for one of these phones, save the port number from the
1422 * Via: header so that nf_nat_sip can redirect the responses to
1423 * the correct port.
1424 */
1425 if (ct_sip_parse_header_uri(ct, *dptr, NULL, *datalen,
1426 SIP_HDR_VIA_UDP, NULL, &matchoff,
1427 &matchlen, &addr, &port) > 0 &&
1428 port != ct->tuplehash[dir].tuple.src.u.udp.port &&
1429 nf_inet_addr_cmp(&addr, &ct->tuplehash[dir].tuple.src.u3))
1430 ct_sip_info->forced_dport = port;
Patrick McHardy30f33e62008-03-25 20:22:20 -07001431
1432 for (i = 0; i < ARRAY_SIZE(sip_handlers); i++) {
Alexey Dobriyan66bf7912008-09-07 18:19:25 -07001433 const struct sip_handler *handler;
1434
Patrick McHardy30f33e62008-03-25 20:22:20 -07001435 handler = &sip_handlers[i];
1436 if (handler->request == NULL)
1437 continue;
1438 if (*datalen < handler->len ||
Rasmus Villemoes18082742014-10-13 15:54:31 -07001439 strncasecmp(*dptr, handler->method, handler->len))
Patrick McHardy30f33e62008-03-25 20:22:20 -07001440 continue;
1441
1442 if (ct_sip_get_header(ct, *dptr, 0, *datalen, SIP_HDR_CSEQ,
Pablo Neira Ayusob20ab9cc2013-02-10 18:56:56 +01001443 &matchoff, &matchlen) <= 0) {
1444 nf_ct_helper_log(skb, ct, "cannot parse cseq");
Patrick McHardy30f33e62008-03-25 20:22:20 -07001445 return NF_DROP;
Pablo Neira Ayusob20ab9cc2013-02-10 18:56:56 +01001446 }
Patrick McHardy30f33e62008-03-25 20:22:20 -07001447 cseq = simple_strtoul(*dptr + matchoff, NULL, 10);
Christophe Leroy0d35d0812016-08-03 12:41:40 +02001448 if (!cseq && *(*dptr + matchoff) != '0') {
Pablo Neira Ayusob20ab9cc2013-02-10 18:56:56 +01001449 nf_ct_helper_log(skb, ct, "cannot get cseq");
Patrick McHardy30f33e62008-03-25 20:22:20 -07001450 return NF_DROP;
Pablo Neira Ayusob20ab9cc2013-02-10 18:56:56 +01001451 }
Patrick McHardy30f33e62008-03-25 20:22:20 -07001452
Patrick McHardy051966c2012-08-26 19:14:04 +02001453 return handler->request(skb, protoff, dataoff, dptr, datalen,
1454 cseq);
Patrick McHardy30f33e62008-03-25 20:22:20 -07001455 }
1456 return NF_ACCEPT;
1457}
Patrick McHardy7d3dd042008-03-25 20:19:46 -07001458
Patrick McHardyf5b321b2010-02-11 12:26:19 +01001459static int process_sip_msg(struct sk_buff *skb, struct nf_conn *ct,
Patrick McHardy051966c2012-08-26 19:14:04 +02001460 unsigned int protoff, unsigned int dataoff,
1461 const char **dptr, unsigned int *datalen)
Patrick McHardyf5b321b2010-02-11 12:26:19 +01001462{
holger@eitzenberger.org180cf722013-09-30 17:07:28 +02001463 const struct nf_nat_sip_hooks *hooks;
Patrick McHardyf5b321b2010-02-11 12:26:19 +01001464 int ret;
1465
Rasmus Villemoes18082742014-10-13 15:54:31 -07001466 if (strncasecmp(*dptr, "SIP/2.0 ", strlen("SIP/2.0 ")) != 0)
Patrick McHardy051966c2012-08-26 19:14:04 +02001467 ret = process_sip_request(skb, protoff, dataoff, dptr, datalen);
Patrick McHardyf5b321b2010-02-11 12:26:19 +01001468 else
Patrick McHardy051966c2012-08-26 19:14:04 +02001469 ret = process_sip_response(skb, protoff, dataoff, dptr, datalen);
Patrick McHardyf5b321b2010-02-11 12:26:19 +01001470
Patrick McHardy9a664822012-08-26 19:14:25 +02001471 if (ret == NF_ACCEPT && ct->status & IPS_NAT_MASK) {
holger@eitzenberger.org180cf722013-09-30 17:07:28 +02001472 hooks = rcu_dereference(nf_nat_sip_hooks);
1473 if (hooks && !hooks->msg(skb, protoff, dataoff,
1474 dptr, datalen)) {
Pablo Neira Ayusob20ab9cc2013-02-10 18:56:56 +01001475 nf_ct_helper_log(skb, ct, "cannot NAT SIP message");
Patrick McHardyf5b321b2010-02-11 12:26:19 +01001476 ret = NF_DROP;
Pablo Neira Ayusob20ab9cc2013-02-10 18:56:56 +01001477 }
Patrick McHardyf5b321b2010-02-11 12:26:19 +01001478 }
1479
1480 return ret;
1481}
1482
1483static int sip_help_tcp(struct sk_buff *skb, unsigned int protoff,
1484 struct nf_conn *ct, enum ip_conntrack_info ctinfo)
1485{
1486 struct tcphdr *th, _tcph;
1487 unsigned int dataoff, datalen;
1488 unsigned int matchoff, matchlen, clen;
1489 unsigned int msglen, origlen;
1490 const char *dptr, *end;
1491 s16 diff, tdiff = 0;
Simon Horman78748962010-09-21 21:17:30 +00001492 int ret = NF_ACCEPT;
Patrick McHardye6e4d9e2011-05-16 14:45:39 +02001493 bool term;
Patrick McHardyf5b321b2010-02-11 12:26:19 +01001494
1495 if (ctinfo != IP_CT_ESTABLISHED &&
Eric Dumazetfb048832011-05-19 15:44:27 +02001496 ctinfo != IP_CT_ESTABLISHED_REPLY)
Patrick McHardyf5b321b2010-02-11 12:26:19 +01001497 return NF_ACCEPT;
1498
1499 /* No Data ? */
1500 th = skb_header_pointer(skb, protoff, sizeof(_tcph), &_tcph);
1501 if (th == NULL)
1502 return NF_ACCEPT;
1503 dataoff = protoff + th->doff * 4;
1504 if (dataoff >= skb->len)
1505 return NF_ACCEPT;
1506
1507 nf_ct_refresh(ct, skb, sip_timeout * HZ);
1508
Patrick McHardya1d7c1b2010-05-14 21:18:17 +02001509 if (unlikely(skb_linearize(skb)))
1510 return NF_DROP;
Patrick McHardyf5b321b2010-02-11 12:26:19 +01001511
1512 dptr = skb->data + dataoff;
1513 datalen = skb->len - dataoff;
1514 if (datalen < strlen("SIP/2.0 200"))
1515 return NF_ACCEPT;
1516
1517 while (1) {
1518 if (ct_sip_get_header(ct, dptr, 0, datalen,
1519 SIP_HDR_CONTENT_LENGTH,
1520 &matchoff, &matchlen) <= 0)
1521 break;
1522
1523 clen = simple_strtoul(dptr + matchoff, (char **)&end, 10);
1524 if (dptr + matchoff == end)
1525 break;
1526
Patrick McHardye6e4d9e2011-05-16 14:45:39 +02001527 term = false;
1528 for (; end + strlen("\r\n\r\n") <= dptr + datalen; end++) {
1529 if (end[0] == '\r' && end[1] == '\n' &&
1530 end[2] == '\r' && end[3] == '\n') {
1531 term = true;
1532 break;
1533 }
1534 }
1535 if (!term)
Patrick McHardyf5b321b2010-02-11 12:26:19 +01001536 break;
1537 end += strlen("\r\n\r\n") + clen;
1538
1539 msglen = origlen = end - dptr;
Patrick McHardy3a7b21e2013-04-05 08:13:30 +00001540 if (msglen > datalen)
1541 return NF_ACCEPT;
Patrick McHardyf5b321b2010-02-11 12:26:19 +01001542
Patrick McHardy051966c2012-08-26 19:14:04 +02001543 ret = process_sip_msg(skb, ct, protoff, dataoff,
1544 &dptr, &msglen);
Pablo Neira Ayusob20ab9cc2013-02-10 18:56:56 +01001545 /* process_sip_* functions report why this packet is dropped */
Patrick McHardyf5b321b2010-02-11 12:26:19 +01001546 if (ret != NF_ACCEPT)
1547 break;
1548 diff = msglen - origlen;
1549 tdiff += diff;
1550
1551 dataoff += msglen;
1552 dptr += msglen;
1553 datalen = datalen + diff - msglen;
1554 }
1555
Patrick McHardy9a664822012-08-26 19:14:25 +02001556 if (ret == NF_ACCEPT && ct->status & IPS_NAT_MASK) {
holger@eitzenberger.org180cf722013-09-30 17:07:28 +02001557 const struct nf_nat_sip_hooks *hooks;
1558
1559 hooks = rcu_dereference(nf_nat_sip_hooks);
1560 if (hooks)
1561 hooks->seq_adjust(skb, protoff, tdiff);
Patrick McHardy48f8ac22010-02-11 12:29:38 +01001562 }
1563
Patrick McHardyf5b321b2010-02-11 12:26:19 +01001564 return ret;
1565}
1566
1567static int sip_help_udp(struct sk_buff *skb, unsigned int protoff,
1568 struct nf_conn *ct, enum ip_conntrack_info ctinfo)
Patrick McHardy9fafcd72006-12-02 22:09:57 -08001569{
Patrick McHardy9fafcd72006-12-02 22:09:57 -08001570 unsigned int dataoff, datalen;
1571 const char *dptr;
Patrick McHardy9fafcd72006-12-02 22:09:57 -08001572
1573 /* No Data ? */
1574 dataoff = protoff + sizeof(struct udphdr);
Herbert Xu3db05fe2007-10-15 00:53:15 -07001575 if (dataoff >= skb->len)
Patrick McHardy9fafcd72006-12-02 22:09:57 -08001576 return NF_ACCEPT;
1577
Herbert Xu3db05fe2007-10-15 00:53:15 -07001578 nf_ct_refresh(ct, skb, sip_timeout * HZ);
Patrick McHardy9fafcd72006-12-02 22:09:57 -08001579
Patrick McHardya1d7c1b2010-05-14 21:18:17 +02001580 if (unlikely(skb_linearize(skb)))
1581 return NF_DROP;
Patrick McHardy9fafcd72006-12-02 22:09:57 -08001582
Patrick McHardyf5b321b2010-02-11 12:26:19 +01001583 dptr = skb->data + dataoff;
Herbert Xu3db05fe2007-10-15 00:53:15 -07001584 datalen = skb->len - dataoff;
Patrick McHardy779382e2008-03-25 20:17:36 -07001585 if (datalen < strlen("SIP/2.0 200"))
Patrick McHardy7d3dd042008-03-25 20:19:46 -07001586 return NF_ACCEPT;
Patrick McHardy9fafcd72006-12-02 22:09:57 -08001587
Patrick McHardy051966c2012-08-26 19:14:04 +02001588 return process_sip_msg(skb, ct, protoff, dataoff, &dptr, &datalen);
Patrick McHardy9fafcd72006-12-02 22:09:57 -08001589}
1590
Gao Feng82de0be2016-07-18 11:39:23 +08001591static struct nf_conntrack_helper sip[MAX_PORTS * 4] __read_mostly;
Patrick McHardy9fafcd72006-12-02 22:09:57 -08001592
Patrick McHardy0f32a402008-03-25 20:25:13 -07001593static const struct nf_conntrack_expect_policy sip_exp_policy[SIP_EXPECT_MAX + 1] = {
1594 [SIP_EXPECT_SIGNALLING] = {
Patrick McHardyb87921b2010-02-11 12:22:48 +01001595 .name = "signalling",
Patrick McHardy0f32a402008-03-25 20:25:13 -07001596 .max_expected = 1,
1597 .timeout = 3 * 60,
1598 },
1599 [SIP_EXPECT_AUDIO] = {
Patrick McHardyb87921b2010-02-11 12:22:48 +01001600 .name = "audio",
Patrick McHardya9c1d352008-03-25 20:25:49 -07001601 .max_expected = 2 * IP_CT_DIR_MAX,
Patrick McHardy0f32a402008-03-25 20:25:13 -07001602 .timeout = 3 * 60,
1603 },
Patrick McHardy0d0ab032008-03-25 20:26:24 -07001604 [SIP_EXPECT_VIDEO] = {
Patrick McHardyb87921b2010-02-11 12:22:48 +01001605 .name = "video",
Patrick McHardy0d0ab032008-03-25 20:26:24 -07001606 .max_expected = 2 * IP_CT_DIR_MAX,
1607 .timeout = 3 * 60,
1608 },
Patrick McHardy9d288df2010-02-11 12:30:21 +01001609 [SIP_EXPECT_IMAGE] = {
1610 .name = "image",
1611 .max_expected = IP_CT_DIR_MAX,
1612 .timeout = 3 * 60,
1613 },
Patrick McHardy6002f2662008-03-25 20:09:15 -07001614};
1615
Patrick McHardy9fafcd72006-12-02 22:09:57 -08001616static void nf_conntrack_sip_fini(void)
1617{
Gao Feng82de0be2016-07-18 11:39:23 +08001618 nf_conntrack_helpers_unregister(sip, ports_c * 4);
Patrick McHardy9fafcd72006-12-02 22:09:57 -08001619}
1620
1621static int __init nf_conntrack_sip_init(void)
1622{
Gao Feng82de0be2016-07-18 11:39:23 +08001623 int i, ret;
Patrick McHardy9fafcd72006-12-02 22:09:57 -08001624
1625 if (ports_c == 0)
1626 ports[ports_c++] = SIP_PORT;
1627
1628 for (i = 0; i < ports_c; i++) {
1629 memset(&sip[i], 0, sizeof(sip[i]));
1630
Gao Feng82de0be2016-07-18 11:39:23 +08001631 nf_ct_helper_init(&sip[4 * i], AF_INET, IPPROTO_UDP, "sip",
1632 SIP_PORT, ports[i], i, sip_exp_policy,
1633 SIP_EXPECT_MAX,
1634 sizeof(struct nf_ct_sip_master), sip_help_udp,
1635 NULL, THIS_MODULE);
1636 nf_ct_helper_init(&sip[4 * i + 1], AF_INET, IPPROTO_TCP, "sip",
1637 SIP_PORT, ports[i], i, sip_exp_policy,
1638 SIP_EXPECT_MAX,
1639 sizeof(struct nf_ct_sip_master), sip_help_tcp,
1640 NULL, THIS_MODULE);
1641 nf_ct_helper_init(&sip[4 * i + 2], AF_INET6, IPPROTO_UDP, "sip",
1642 SIP_PORT, ports[i], i, sip_exp_policy,
1643 SIP_EXPECT_MAX,
1644 sizeof(struct nf_ct_sip_master), sip_help_udp,
1645 NULL, THIS_MODULE);
1646 nf_ct_helper_init(&sip[4 * i + 3], AF_INET6, IPPROTO_TCP, "sip",
1647 SIP_PORT, ports[i], i, sip_exp_policy,
1648 SIP_EXPECT_MAX,
1649 sizeof(struct nf_ct_sip_master), sip_help_tcp,
1650 NULL, THIS_MODULE);
1651 }
Patrick McHardyf5b321b2010-02-11 12:26:19 +01001652
Gao Feng82de0be2016-07-18 11:39:23 +08001653 ret = nf_conntrack_helpers_register(sip, ports_c * 4);
1654 if (ret < 0) {
1655 pr_err("failed to register helpers\n");
1656 return ret;
Patrick McHardy9fafcd72006-12-02 22:09:57 -08001657 }
1658 return 0;
1659}
1660
1661module_init(nf_conntrack_sip_init);
1662module_exit(nf_conntrack_sip_fini);