1 /* SIP extension for IP connection tracking.
4 * based on RR's ip_conntrack_ftp.c and other modules.
5 * (C) 2007 United Security Providers
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.
13 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
15 #include <linux/module.h>
16 #include <linux/ctype.h>
17 #include <linux/skbuff.h>
18 #include <linux/inet.h>
20 #include <linux/udp.h>
21 #include <linux/tcp.h>
22 #include <linux/netfilter.h>
24 #include <net/netfilter/nf_conntrack.h>
25 #include <net/netfilter/nf_conntrack_core.h>
26 #include <net/netfilter/nf_conntrack_expect.h>
27 #include <net/netfilter/nf_conntrack_helper.h>
28 #include <net/netfilter/nf_conntrack_zones.h>
29 #include <linux/netfilter/nf_conntrack_sip.h>
31 MODULE_LICENSE("GPL");
33 MODULE_DESCRIPTION("SIP connection tracking helper");
34 MODULE_ALIAS("ip_conntrack_sip");
35 MODULE_ALIAS_NFCT_HELPER("sip");
38 static unsigned short ports[MAX_PORTS];
39 static unsigned int ports_c;
40 module_param_array(ports, ushort, &ports_c, 0400);
41 MODULE_PARM_DESC(ports, "port numbers of SIP servers");
43 static unsigned int sip_timeout __read_mostly = SIP_TIMEOUT;
44 module_param(sip_timeout, uint, 0600);
45 MODULE_PARM_DESC(sip_timeout, "timeout for the master SIP session");
47 static int sip_direct_signalling __read_mostly = 1;
48 module_param(sip_direct_signalling, int, 0600);
49 MODULE_PARM_DESC(sip_direct_signalling, "expect incoming calls from registrar "
52 static int sip_direct_media __read_mostly = 1;
53 module_param(sip_direct_media, int, 0600);
54 MODULE_PARM_DESC(sip_direct_media, "Expect Media streams between signalling "
55 "endpoints only (default 1)");
57 const struct nf_nat_sip_hooks *nf_nat_sip_hooks;
58 EXPORT_SYMBOL_GPL(nf_nat_sip_hooks);
60 static int string_len(const struct nf_conn *ct, const char *dptr,
61 const char *limit, int *shift)
65 while (dptr < limit && isalpha(*dptr)) {
72 static int digits_len(const struct nf_conn *ct, const char *dptr,
73 const char *limit, int *shift)
76 while (dptr < limit && isdigit(*dptr)) {
83 static int iswordc(const char c)
85 if (isalnum(c) || c == '!' || c == '"' || c == '%' ||
86 (c >= '(' && c <= '+') || c == ':' || c == '<' || c == '>' ||
87 c == '?' || (c >= '[' && c <= ']') || c == '_' || c == '`' ||
88 c == '{' || c == '}' || c == '~' || (c >= '-' && c <= '/') ||
94 static int word_len(const char *dptr, const char *limit)
97 while (dptr < limit && iswordc(*dptr)) {
104 static int callid_len(const struct nf_conn *ct, const char *dptr,
105 const char *limit, int *shift)
109 len = word_len(dptr, limit);
111 if (!len || dptr == limit || *dptr != '@')
116 domain_len = word_len(dptr, limit);
119 return len + domain_len;
122 /* get media type + port length */
123 static int media_len(const struct nf_conn *ct, const char *dptr,
124 const char *limit, int *shift)
126 int len = string_len(ct, dptr, limit, shift);
129 if (dptr >= limit || *dptr != ' ')
134 return len + digits_len(ct, dptr, limit, shift);
137 static int sip_parse_addr(const struct nf_conn *ct, const char *cp,
138 const char **endp, union nf_inet_addr *addr,
139 const char *limit, bool delim)
147 memset(addr, 0, sizeof(*addr));
148 switch (nf_ct_l3num(ct)) {
150 ret = in4_pton(cp, limit - cp, (u8 *)&addr->ip, -1, &end);
155 if (cp < limit && *cp == '[')
160 ret = in6_pton(cp, limit - cp, (u8 *)&addr->ip6, -1, &end);
164 if (end < limit && *end == ']')
178 /* skip ip address. returns its length. */
179 static int epaddr_len(const struct nf_conn *ct, const char *dptr,
180 const char *limit, int *shift)
182 union nf_inet_addr addr;
183 const char *aux = dptr;
185 if (!sip_parse_addr(ct, dptr, &dptr, &addr, limit, true)) {
186 pr_debug("ip: %s parse failed.!\n", dptr);
193 dptr += digits_len(ct, dptr, limit, shift);
198 /* get address length, skiping user info. */
199 static int skp_epaddr_len(const struct nf_conn *ct, const char *dptr,
200 const char *limit, int *shift)
202 const char *start = dptr;
205 /* Search for @, but stop at the end of the line.
206 * We are inside a sip: URI, so we don't need to worry about
207 * continuation lines. */
208 while (dptr < limit &&
209 *dptr != '@' && *dptr != '\r' && *dptr != '\n') {
214 if (dptr < limit && *dptr == '@') {
222 return epaddr_len(ct, dptr, limit, shift);
225 /* Parse a SIP request line of the form:
227 * Request-Line = Method SP Request-URI SP SIP-Version CRLF
229 * and return the offset and length of the address contained in the Request-URI.
231 int ct_sip_parse_request(const struct nf_conn *ct,
232 const char *dptr, unsigned int datalen,
233 unsigned int *matchoff, unsigned int *matchlen,
234 union nf_inet_addr *addr, __be16 *port)
236 const char *start = dptr, *limit = dptr + datalen, *end;
241 /* Skip method and following whitespace */
242 mlen = string_len(ct, dptr, limit, NULL);
250 for (; dptr < limit - strlen("sip:"); dptr++) {
251 if (*dptr == '\r' || *dptr == '\n')
253 if (strncasecmp(dptr, "sip:", strlen("sip:")) == 0) {
254 dptr += strlen("sip:");
258 if (!skp_epaddr_len(ct, dptr, limit, &shift))
262 if (!sip_parse_addr(ct, dptr, &end, addr, limit, true))
264 if (end < limit && *end == ':') {
266 p = simple_strtoul(end, (char **)&end, 10);
267 if (p < 1024 || p > 65535)
271 *port = htons(SIP_PORT);
275 *matchoff = dptr - start;
276 *matchlen = end - dptr;
279 EXPORT_SYMBOL_GPL(ct_sip_parse_request);
281 /* SIP header parsing: SIP headers are located at the beginning of a line, but
282 * may span several lines, in which case the continuation lines begin with a
283 * whitespace character. RFC 2543 allows lines to be terminated with CR, LF or
284 * CRLF, RFC 3261 allows only CRLF, we support both.
286 * Headers are followed by (optionally) whitespace, a colon, again (optionally)
287 * whitespace and the values. Whitespace in this context means any amount of
288 * tabs, spaces and continuation lines, which are treated as a single whitespace
291 * Some headers may appear multiple times. A comma separated list of values is
292 * equivalent to multiple headers.
294 static const struct sip_header ct_sip_hdrs[] = {
295 [SIP_HDR_CSEQ] = SIP_HDR("CSeq", NULL, NULL, digits_len),
296 [SIP_HDR_FROM] = SIP_HDR("From", "f", "sip:", skp_epaddr_len),
297 [SIP_HDR_TO] = SIP_HDR("To", "t", "sip:", skp_epaddr_len),
298 [SIP_HDR_CONTACT] = SIP_HDR("Contact", "m", "sip:", skp_epaddr_len),
299 [SIP_HDR_VIA_UDP] = SIP_HDR("Via", "v", "UDP ", epaddr_len),
300 [SIP_HDR_VIA_TCP] = SIP_HDR("Via", "v", "TCP ", epaddr_len),
301 [SIP_HDR_EXPIRES] = SIP_HDR("Expires", NULL, NULL, digits_len),
302 [SIP_HDR_CONTENT_LENGTH] = SIP_HDR("Content-Length", "l", NULL, digits_len),
303 [SIP_HDR_CALL_ID] = SIP_HDR("Call-Id", "i", NULL, callid_len),
306 static const char *sip_follow_continuation(const char *dptr, const char *limit)
308 /* Walk past newline */
312 /* Skip '\n' in CR LF */
313 if (*(dptr - 1) == '\r' && *dptr == '\n') {
318 /* Continuation line? */
319 if (*dptr != ' ' && *dptr != '\t')
322 /* skip leading whitespace */
323 for (; dptr < limit; dptr++) {
324 if (*dptr != ' ' && *dptr != '\t')
330 static const char *sip_skip_whitespace(const char *dptr, const char *limit)
332 for (; dptr < limit; dptr++) {
333 if (*dptr == ' ' || *dptr == '\t')
335 if (*dptr != '\r' && *dptr != '\n')
337 dptr = sip_follow_continuation(dptr, limit);
343 /* Search within a SIP header value, dealing with continuation lines */
344 static const char *ct_sip_header_search(const char *dptr, const char *limit,
345 const char *needle, unsigned int len)
347 for (limit -= len; dptr < limit; dptr++) {
348 if (*dptr == '\r' || *dptr == '\n') {
349 dptr = sip_follow_continuation(dptr, limit);
355 if (strncasecmp(dptr, needle, len) == 0)
361 int ct_sip_get_header(const struct nf_conn *ct, const char *dptr,
362 unsigned int dataoff, unsigned int datalen,
363 enum sip_header_types type,
364 unsigned int *matchoff, unsigned int *matchlen)
366 const struct sip_header *hdr = &ct_sip_hdrs[type];
367 const char *start = dptr, *limit = dptr + datalen;
370 for (dptr += dataoff; dptr < limit; dptr++) {
371 /* Find beginning of line */
372 if (*dptr != '\r' && *dptr != '\n')
376 if (*(dptr - 1) == '\r' && *dptr == '\n') {
381 /* Skip continuation lines */
382 if (*dptr == ' ' || *dptr == '\t')
385 /* Find header. Compact headers must be followed by a
386 * non-alphabetic character to avoid mismatches. */
387 if (limit - dptr >= hdr->len &&
388 strncasecmp(dptr, hdr->name, hdr->len) == 0)
390 else if (hdr->cname && limit - dptr >= hdr->clen + 1 &&
391 strncasecmp(dptr, hdr->cname, hdr->clen) == 0 &&
392 !isalpha(*(dptr + hdr->clen)))
397 /* Find and skip colon */
398 dptr = sip_skip_whitespace(dptr, limit);
401 if (*dptr != ':' || ++dptr >= limit)
404 /* Skip whitespace after colon */
405 dptr = sip_skip_whitespace(dptr, limit);
409 *matchoff = dptr - start;
411 dptr = ct_sip_header_search(dptr, limit, hdr->search,
418 *matchlen = hdr->match_len(ct, dptr, limit, &shift);
421 *matchoff = dptr - start + shift;
426 EXPORT_SYMBOL_GPL(ct_sip_get_header);
428 /* Get next header field in a list of comma separated values */
429 static int ct_sip_next_header(const struct nf_conn *ct, const char *dptr,
430 unsigned int dataoff, unsigned int datalen,
431 enum sip_header_types type,
432 unsigned int *matchoff, unsigned int *matchlen)
434 const struct sip_header *hdr = &ct_sip_hdrs[type];
435 const char *start = dptr, *limit = dptr + datalen;
440 dptr = ct_sip_header_search(dptr, limit, ",", strlen(","));
444 dptr = ct_sip_header_search(dptr, limit, hdr->search, hdr->slen);
449 *matchoff = dptr - start;
450 *matchlen = hdr->match_len(ct, dptr, limit, &shift);
457 /* Walk through headers until a parsable one is found or no header of the
458 * given type is left. */
459 static int ct_sip_walk_headers(const struct nf_conn *ct, const char *dptr,
460 unsigned int dataoff, unsigned int datalen,
461 enum sip_header_types type, int *in_header,
462 unsigned int *matchoff, unsigned int *matchlen)
466 if (in_header && *in_header) {
468 ret = ct_sip_next_header(ct, dptr, dataoff, datalen,
469 type, matchoff, matchlen);
474 dataoff += *matchoff;
480 ret = ct_sip_get_header(ct, dptr, dataoff, datalen,
481 type, matchoff, matchlen);
486 dataoff += *matchoff;
494 /* Locate a SIP header, parse the URI and return the offset and length of
495 * the address as well as the address and port themselves. A stream of
496 * headers can be parsed by handing in a non-NULL datalen and in_header
499 int ct_sip_parse_header_uri(const struct nf_conn *ct, const char *dptr,
500 unsigned int *dataoff, unsigned int datalen,
501 enum sip_header_types type, int *in_header,
502 unsigned int *matchoff, unsigned int *matchlen,
503 union nf_inet_addr *addr, __be16 *port)
505 const char *c, *limit = dptr + datalen;
509 ret = ct_sip_walk_headers(ct, dptr, dataoff ? *dataoff : 0, datalen,
510 type, in_header, matchoff, matchlen);
515 if (!sip_parse_addr(ct, dptr + *matchoff, &c, addr, limit, true))
519 p = simple_strtoul(c, (char **)&c, 10);
520 if (p < 1024 || p > 65535)
524 *port = htons(SIP_PORT);
530 EXPORT_SYMBOL_GPL(ct_sip_parse_header_uri);
532 static int ct_sip_parse_param(const struct nf_conn *ct, const char *dptr,
533 unsigned int dataoff, unsigned int datalen,
535 unsigned int *matchoff, unsigned int *matchlen)
537 const char *limit = dptr + datalen;
541 limit = ct_sip_header_search(dptr + dataoff, limit, ",", strlen(","));
543 limit = dptr + datalen;
545 start = ct_sip_header_search(dptr + dataoff, limit, name, strlen(name));
548 start += strlen(name);
550 end = ct_sip_header_search(start, limit, ";", strlen(";"));
554 *matchoff = start - dptr;
555 *matchlen = end - start;
559 /* Parse address from header parameter and return address, offset and length */
560 int ct_sip_parse_address_param(const struct nf_conn *ct, const char *dptr,
561 unsigned int dataoff, unsigned int datalen,
563 unsigned int *matchoff, unsigned int *matchlen,
564 union nf_inet_addr *addr, bool delim)
566 const char *limit = dptr + datalen;
567 const char *start, *end;
569 limit = ct_sip_header_search(dptr + dataoff, limit, ",", strlen(","));
571 limit = dptr + datalen;
573 start = ct_sip_header_search(dptr + dataoff, limit, name, strlen(name));
577 start += strlen(name);
578 if (!sip_parse_addr(ct, start, &end, addr, limit, delim))
580 *matchoff = start - dptr;
581 *matchlen = end - start;
584 EXPORT_SYMBOL_GPL(ct_sip_parse_address_param);
586 /* Parse numerical header parameter and return value, offset and length */
587 int ct_sip_parse_numerical_param(const struct nf_conn *ct, const char *dptr,
588 unsigned int dataoff, unsigned int datalen,
590 unsigned int *matchoff, unsigned int *matchlen,
593 const char *limit = dptr + datalen;
597 limit = ct_sip_header_search(dptr + dataoff, limit, ",", strlen(","));
599 limit = dptr + datalen;
601 start = ct_sip_header_search(dptr + dataoff, limit, name, strlen(name));
605 start += strlen(name);
606 *val = simple_strtoul(start, &end, 0);
609 if (matchoff && matchlen) {
610 *matchoff = start - dptr;
611 *matchlen = end - start;
615 EXPORT_SYMBOL_GPL(ct_sip_parse_numerical_param);
617 static int ct_sip_parse_transport(struct nf_conn *ct, const char *dptr,
618 unsigned int dataoff, unsigned int datalen,
621 unsigned int matchoff, matchlen;
623 if (ct_sip_parse_param(ct, dptr, dataoff, datalen, "transport=",
624 &matchoff, &matchlen)) {
625 if (!strncasecmp(dptr + matchoff, "TCP", strlen("TCP")))
626 *proto = IPPROTO_TCP;
627 else if (!strncasecmp(dptr + matchoff, "UDP", strlen("UDP")))
628 *proto = IPPROTO_UDP;
632 if (*proto != nf_ct_protonum(ct))
635 *proto = nf_ct_protonum(ct);
640 static int sdp_parse_addr(const struct nf_conn *ct, const char *cp,
641 const char **endp, union nf_inet_addr *addr,
647 memset(addr, 0, sizeof(*addr));
648 switch (nf_ct_l3num(ct)) {
650 ret = in4_pton(cp, limit - cp, (u8 *)&addr->ip, -1, &end);
653 ret = in6_pton(cp, limit - cp, (u8 *)&addr->ip6, -1, &end);
666 /* skip ip address. returns its length. */
667 static int sdp_addr_len(const struct nf_conn *ct, const char *dptr,
668 const char *limit, int *shift)
670 union nf_inet_addr addr;
671 const char *aux = dptr;
673 if (!sdp_parse_addr(ct, dptr, &dptr, &addr, limit)) {
674 pr_debug("ip: %s parse failed.!\n", dptr);
681 /* SDP header parsing: a SDP session description contains an ordered set of
682 * headers, starting with a section containing general session parameters,
683 * optionally followed by multiple media descriptions.
685 * SDP headers always start at the beginning of a line. According to RFC 2327:
686 * "The sequence CRLF (0x0d0a) is used to end a record, although parsers should
687 * be tolerant and also accept records terminated with a single newline
688 * character". We handle both cases.
690 static const struct sip_header ct_sdp_hdrs_v4[] = {
691 [SDP_HDR_VERSION] = SDP_HDR("v=", NULL, digits_len),
692 [SDP_HDR_OWNER] = SDP_HDR("o=", "IN IP4 ", sdp_addr_len),
693 [SDP_HDR_CONNECTION] = SDP_HDR("c=", "IN IP4 ", sdp_addr_len),
694 [SDP_HDR_MEDIA] = SDP_HDR("m=", NULL, media_len),
697 static const struct sip_header ct_sdp_hdrs_v6[] = {
698 [SDP_HDR_VERSION] = SDP_HDR("v=", NULL, digits_len),
699 [SDP_HDR_OWNER] = SDP_HDR("o=", "IN IP6 ", sdp_addr_len),
700 [SDP_HDR_CONNECTION] = SDP_HDR("c=", "IN IP6 ", sdp_addr_len),
701 [SDP_HDR_MEDIA] = SDP_HDR("m=", NULL, media_len),
704 /* Linear string search within SDP header values */
705 static const char *ct_sdp_header_search(const char *dptr, const char *limit,
706 const char *needle, unsigned int len)
708 for (limit -= len; dptr < limit; dptr++) {
709 if (*dptr == '\r' || *dptr == '\n')
711 if (strncmp(dptr, needle, len) == 0)
717 /* Locate a SDP header (optionally a substring within the header value),
718 * optionally stopping at the first occurrence of the term header, parse
719 * it and return the offset and length of the data we're interested in.
721 int ct_sip_get_sdp_header(const struct nf_conn *ct, const char *dptr,
722 unsigned int dataoff, unsigned int datalen,
723 enum sdp_header_types type,
724 enum sdp_header_types term,
725 unsigned int *matchoff, unsigned int *matchlen)
727 const struct sip_header *hdrs, *hdr, *thdr;
728 const char *start = dptr, *limit = dptr + datalen;
731 hdrs = nf_ct_l3num(ct) == NFPROTO_IPV4 ? ct_sdp_hdrs_v4 : ct_sdp_hdrs_v6;
735 for (dptr += dataoff; dptr < limit; dptr++) {
736 /* Find beginning of line */
737 if (*dptr != '\r' && *dptr != '\n')
741 if (*(dptr - 1) == '\r' && *dptr == '\n') {
746 if (term != SDP_HDR_UNSPEC &&
747 limit - dptr >= thdr->len &&
748 strncasecmp(dptr, thdr->name, thdr->len) == 0)
750 else if (limit - dptr >= hdr->len &&
751 strncasecmp(dptr, hdr->name, hdr->len) == 0)
756 *matchoff = dptr - start;
758 dptr = ct_sdp_header_search(dptr, limit, hdr->search,
765 *matchlen = hdr->match_len(ct, dptr, limit, &shift);
768 *matchoff = dptr - start + shift;
773 EXPORT_SYMBOL_GPL(ct_sip_get_sdp_header);
775 static int ct_sip_parse_sdp_addr(const struct nf_conn *ct, const char *dptr,
776 unsigned int dataoff, unsigned int datalen,
777 enum sdp_header_types type,
778 enum sdp_header_types term,
779 unsigned int *matchoff, unsigned int *matchlen,
780 union nf_inet_addr *addr)
784 ret = ct_sip_get_sdp_header(ct, dptr, dataoff, datalen, type, term,
789 if (!sdp_parse_addr(ct, dptr + *matchoff, NULL, addr,
790 dptr + *matchoff + *matchlen))
795 static int refresh_signalling_expectation(struct nf_conn *ct,
796 union nf_inet_addr *addr,
797 u8 proto, __be16 port,
798 unsigned int expires)
800 struct nf_conn_help *help = nfct_help(ct);
801 struct nf_conntrack_expect *exp;
802 struct hlist_node *next;
805 spin_lock_bh(&nf_conntrack_expect_lock);
806 hlist_for_each_entry_safe(exp, next, &help->expectations, lnode) {
807 if (exp->class != SIP_EXPECT_SIGNALLING ||
808 !nf_inet_addr_cmp(&exp->tuple.dst.u3, addr) ||
809 exp->tuple.dst.protonum != proto ||
810 exp->tuple.dst.u.udp.port != port)
812 if (mod_timer_pending(&exp->timeout, jiffies + expires * HZ)) {
813 exp->flags &= ~NF_CT_EXPECT_INACTIVE;
818 spin_unlock_bh(&nf_conntrack_expect_lock);
822 static void flush_expectations(struct nf_conn *ct, bool media)
824 struct nf_conn_help *help = nfct_help(ct);
825 struct nf_conntrack_expect *exp;
826 struct hlist_node *next;
828 spin_lock_bh(&nf_conntrack_expect_lock);
829 hlist_for_each_entry_safe(exp, next, &help->expectations, lnode) {
830 if ((exp->class != SIP_EXPECT_SIGNALLING) ^ media)
832 if (!del_timer(&exp->timeout))
834 nf_ct_unlink_expect(exp);
835 nf_ct_expect_put(exp);
839 spin_unlock_bh(&nf_conntrack_expect_lock);
842 static int set_expected_rtp_rtcp(struct sk_buff *skb, unsigned int protoff,
843 unsigned int dataoff,
844 const char **dptr, unsigned int *datalen,
845 union nf_inet_addr *daddr, __be16 port,
846 enum sip_expectation_classes class,
847 unsigned int mediaoff, unsigned int medialen)
849 struct nf_conntrack_expect *exp, *rtp_exp, *rtcp_exp;
850 enum ip_conntrack_info ctinfo;
851 struct nf_conn *ct = nf_ct_get(skb, &ctinfo);
852 struct net *net = nf_ct_net(ct);
853 enum ip_conntrack_dir dir = CTINFO2DIR(ctinfo);
854 union nf_inet_addr *saddr;
855 struct nf_conntrack_tuple tuple;
856 int direct_rtp = 0, skip_expect = 0, ret = NF_DROP;
858 __be16 rtp_port, rtcp_port;
859 const struct nf_nat_sip_hooks *hooks;
862 if (sip_direct_media) {
863 if (!nf_inet_addr_cmp(daddr, &ct->tuplehash[dir].tuple.src.u3))
865 saddr = &ct->tuplehash[!dir].tuple.src.u3;
868 /* We need to check whether the registration exists before attempting
869 * to register it since we can see the same media description multiple
870 * times on different connections in case multiple endpoints receive
873 * RTP optimization: if we find a matching media channel expectation
874 * and both the expectation and this connection are SNATed, we assume
875 * both sides can reach each other directly and use the final
876 * destination address from the expectation. We still need to keep
877 * the NATed expectations for media that might arrive from the
878 * outside, and additionally need to expect the direct RTP stream
879 * in case it passes through us even without NAT.
881 memset(&tuple, 0, sizeof(tuple));
883 tuple.src.u3 = *saddr;
884 tuple.src.l3num = nf_ct_l3num(ct);
885 tuple.dst.protonum = IPPROTO_UDP;
886 tuple.dst.u3 = *daddr;
887 tuple.dst.u.udp.port = port;
891 exp = __nf_ct_expect_find(net, nf_ct_zone(ct), &tuple);
893 if (!exp || exp->master == ct ||
894 nfct_help(exp->master)->helper != nfct_help(ct)->helper ||
897 #ifdef CONFIG_NF_NAT_NEEDED
899 (!nf_inet_addr_cmp(&exp->saved_addr, &exp->tuple.dst.u3) ||
900 exp->saved_proto.udp.port != exp->tuple.dst.u.udp.port) &&
901 ct->status & IPS_NAT_MASK) {
902 *daddr = exp->saved_addr;
903 tuple.dst.u3 = exp->saved_addr;
904 tuple.dst.u.udp.port = exp->saved_proto.udp.port;
909 } while (!skip_expect);
911 base_port = ntohs(tuple.dst.u.udp.port) & ~1;
912 rtp_port = htons(base_port);
913 rtcp_port = htons(base_port + 1);
916 hooks = rcu_dereference(nf_nat_sip_hooks);
918 !hooks->sdp_port(skb, protoff, dataoff, dptr, datalen,
919 mediaoff, medialen, ntohs(rtp_port)))
928 rtp_exp = nf_ct_expect_alloc(ct);
931 nf_ct_expect_init(rtp_exp, class, nf_ct_l3num(ct), saddr, daddr,
932 IPPROTO_UDP, NULL, &rtp_port);
934 rtcp_exp = nf_ct_expect_alloc(ct);
935 if (rtcp_exp == NULL)
937 nf_ct_expect_init(rtcp_exp, class, nf_ct_l3num(ct), saddr, daddr,
938 IPPROTO_UDP, NULL, &rtcp_port);
940 hooks = rcu_dereference(nf_nat_sip_hooks);
941 if (hooks && ct->status & IPS_NAT_MASK && !direct_rtp)
942 ret = hooks->sdp_media(skb, protoff, dataoff, dptr,
943 datalen, rtp_exp, rtcp_exp,
944 mediaoff, medialen, daddr);
946 if (nf_ct_expect_related(rtp_exp) == 0) {
947 if (nf_ct_expect_related(rtcp_exp) != 0)
948 nf_ct_unexpect_related(rtp_exp);
953 nf_ct_expect_put(rtcp_exp);
955 nf_ct_expect_put(rtp_exp);
961 static const struct sdp_media_type sdp_media_types[] = {
962 SDP_MEDIA_TYPE("audio ", SIP_EXPECT_AUDIO),
963 SDP_MEDIA_TYPE("video ", SIP_EXPECT_VIDEO),
964 SDP_MEDIA_TYPE("image ", SIP_EXPECT_IMAGE),
967 static const struct sdp_media_type *sdp_media_type(const char *dptr,
968 unsigned int matchoff,
969 unsigned int matchlen)
971 const struct sdp_media_type *t;
974 for (i = 0; i < ARRAY_SIZE(sdp_media_types); i++) {
975 t = &sdp_media_types[i];
976 if (matchlen < t->len ||
977 strncmp(dptr + matchoff, t->name, t->len))
984 static int process_sdp(struct sk_buff *skb, unsigned int protoff,
985 unsigned int dataoff,
986 const char **dptr, unsigned int *datalen,
989 enum ip_conntrack_info ctinfo;
990 struct nf_conn *ct = nf_ct_get(skb, &ctinfo);
991 unsigned int matchoff, matchlen;
992 unsigned int mediaoff, medialen;
994 unsigned int caddr_len, maddr_len;
996 union nf_inet_addr caddr, maddr, rtp_addr;
997 const struct nf_nat_sip_hooks *hooks;
999 const struct sdp_media_type *t;
1000 int ret = NF_ACCEPT;
1002 hooks = rcu_dereference(nf_nat_sip_hooks);
1004 /* Find beginning of session description */
1005 if (ct_sip_get_sdp_header(ct, *dptr, 0, *datalen,
1006 SDP_HDR_VERSION, SDP_HDR_UNSPEC,
1007 &matchoff, &matchlen) <= 0)
1011 /* The connection information is contained in the session description
1012 * and/or once per media description. The first media description marks
1013 * the end of the session description. */
1015 if (ct_sip_parse_sdp_addr(ct, *dptr, sdpoff, *datalen,
1016 SDP_HDR_CONNECTION, SDP_HDR_MEDIA,
1017 &matchoff, &matchlen, &caddr) > 0)
1018 caddr_len = matchlen;
1021 for (i = 0; i < ARRAY_SIZE(sdp_media_types); ) {
1022 if (ct_sip_get_sdp_header(ct, *dptr, mediaoff, *datalen,
1023 SDP_HDR_MEDIA, SDP_HDR_UNSPEC,
1024 &mediaoff, &medialen) <= 0)
1027 /* Get media type and port number. A media port value of zero
1028 * indicates an inactive stream. */
1029 t = sdp_media_type(*dptr, mediaoff, medialen);
1031 mediaoff += medialen;
1037 port = simple_strtoul(*dptr + mediaoff, NULL, 10);
1040 if (port < 1024 || port > 65535) {
1041 nf_ct_helper_log(skb, ct, "wrong port %u", port);
1045 /* The media description overrides the session description. */
1047 if (ct_sip_parse_sdp_addr(ct, *dptr, mediaoff, *datalen,
1048 SDP_HDR_CONNECTION, SDP_HDR_MEDIA,
1049 &matchoff, &matchlen, &maddr) > 0) {
1050 maddr_len = matchlen;
1051 memcpy(&rtp_addr, &maddr, sizeof(rtp_addr));
1052 } else if (caddr_len)
1053 memcpy(&rtp_addr, &caddr, sizeof(rtp_addr));
1055 nf_ct_helper_log(skb, ct, "cannot parse SDP message");
1059 ret = set_expected_rtp_rtcp(skb, protoff, dataoff,
1061 &rtp_addr, htons(port), t->class,
1062 mediaoff, medialen);
1063 if (ret != NF_ACCEPT) {
1064 nf_ct_helper_log(skb, ct,
1065 "cannot add expectation for voice");
1069 /* Update media connection address if present */
1070 if (maddr_len && hooks && ct->status & IPS_NAT_MASK) {
1071 ret = hooks->sdp_addr(skb, protoff, dataoff,
1072 dptr, datalen, mediaoff,
1076 if (ret != NF_ACCEPT) {
1077 nf_ct_helper_log(skb, ct, "cannot mangle SDP");
1084 /* Update session connection and owner addresses */
1085 hooks = rcu_dereference(nf_nat_sip_hooks);
1086 if (hooks && ct->status & IPS_NAT_MASK)
1087 ret = hooks->sdp_session(skb, protoff, dataoff,
1088 dptr, datalen, sdpoff,
1093 static int process_invite_response(struct sk_buff *skb, unsigned int protoff,
1094 unsigned int dataoff,
1095 const char **dptr, unsigned int *datalen,
1096 unsigned int cseq, unsigned int code)
1098 enum ip_conntrack_info ctinfo;
1099 struct nf_conn *ct = nf_ct_get(skb, &ctinfo);
1100 struct nf_ct_sip_master *ct_sip_info = nfct_help_data(ct);
1102 if ((code >= 100 && code <= 199) ||
1103 (code >= 200 && code <= 299))
1104 return process_sdp(skb, protoff, dataoff, dptr, datalen, cseq);
1105 else if (ct_sip_info->invite_cseq == cseq)
1106 flush_expectations(ct, true);
1110 static int process_update_response(struct sk_buff *skb, unsigned int protoff,
1111 unsigned int dataoff,
1112 const char **dptr, unsigned int *datalen,
1113 unsigned int cseq, unsigned int code)
1115 enum ip_conntrack_info ctinfo;
1116 struct nf_conn *ct = nf_ct_get(skb, &ctinfo);
1117 struct nf_ct_sip_master *ct_sip_info = nfct_help_data(ct);
1119 if ((code >= 100 && code <= 199) ||
1120 (code >= 200 && code <= 299))
1121 return process_sdp(skb, protoff, dataoff, dptr, datalen, cseq);
1122 else if (ct_sip_info->invite_cseq == cseq)
1123 flush_expectations(ct, true);
1127 static int process_prack_response(struct sk_buff *skb, unsigned int protoff,
1128 unsigned int dataoff,
1129 const char **dptr, unsigned int *datalen,
1130 unsigned int cseq, unsigned int code)
1132 enum ip_conntrack_info ctinfo;
1133 struct nf_conn *ct = nf_ct_get(skb, &ctinfo);
1134 struct nf_ct_sip_master *ct_sip_info = nfct_help_data(ct);
1136 if ((code >= 100 && code <= 199) ||
1137 (code >= 200 && code <= 299))
1138 return process_sdp(skb, protoff, dataoff, dptr, datalen, cseq);
1139 else if (ct_sip_info->invite_cseq == cseq)
1140 flush_expectations(ct, true);
1144 static int process_invite_request(struct sk_buff *skb, unsigned int protoff,
1145 unsigned int dataoff,
1146 const char **dptr, unsigned int *datalen,
1149 enum ip_conntrack_info ctinfo;
1150 struct nf_conn *ct = nf_ct_get(skb, &ctinfo);
1151 struct nf_ct_sip_master *ct_sip_info = nfct_help_data(ct);
1154 flush_expectations(ct, true);
1155 ret = process_sdp(skb, protoff, dataoff, dptr, datalen, cseq);
1156 if (ret == NF_ACCEPT)
1157 ct_sip_info->invite_cseq = cseq;
1161 static int process_bye_request(struct sk_buff *skb, unsigned int protoff,
1162 unsigned int dataoff,
1163 const char **dptr, unsigned int *datalen,
1166 enum ip_conntrack_info ctinfo;
1167 struct nf_conn *ct = nf_ct_get(skb, &ctinfo);
1169 flush_expectations(ct, true);
1173 /* Parse a REGISTER request and create a permanent expectation for incoming
1174 * signalling connections. The expectation is marked inactive and is activated
1175 * when receiving a response indicating success from the registrar.
1177 static int process_register_request(struct sk_buff *skb, unsigned int protoff,
1178 unsigned int dataoff,
1179 const char **dptr, unsigned int *datalen,
1182 enum ip_conntrack_info ctinfo;
1183 struct nf_conn *ct = nf_ct_get(skb, &ctinfo);
1184 struct nf_ct_sip_master *ct_sip_info = nfct_help_data(ct);
1185 enum ip_conntrack_dir dir = CTINFO2DIR(ctinfo);
1186 unsigned int matchoff, matchlen;
1187 struct nf_conntrack_expect *exp;
1188 union nf_inet_addr *saddr, daddr;
1189 const struct nf_nat_sip_hooks *hooks;
1192 unsigned int expires = 0;
1195 /* Expected connections can not register again. */
1196 if (ct->status & IPS_EXPECTED)
1199 /* We must check the expiration time: a value of zero signals the
1200 * registrar to release the binding. We'll remove our expectation
1201 * when receiving the new bindings in the response, but we don't
1202 * want to create new ones.
1204 * The expiration time may be contained in Expires: header, the
1205 * Contact: header parameters or the URI parameters.
1207 if (ct_sip_get_header(ct, *dptr, 0, *datalen, SIP_HDR_EXPIRES,
1208 &matchoff, &matchlen) > 0)
1209 expires = simple_strtoul(*dptr + matchoff, NULL, 10);
1211 ret = ct_sip_parse_header_uri(ct, *dptr, NULL, *datalen,
1212 SIP_HDR_CONTACT, NULL,
1213 &matchoff, &matchlen, &daddr, &port);
1215 nf_ct_helper_log(skb, ct, "cannot parse contact");
1217 } else if (ret == 0)
1220 /* We don't support third-party registrations */
1221 if (!nf_inet_addr_cmp(&ct->tuplehash[dir].tuple.src.u3, &daddr))
1224 if (ct_sip_parse_transport(ct, *dptr, matchoff + matchlen, *datalen,
1228 if (ct_sip_parse_numerical_param(ct, *dptr,
1229 matchoff + matchlen, *datalen,
1230 "expires=", NULL, NULL, &expires) < 0) {
1231 nf_ct_helper_log(skb, ct, "cannot parse expires");
1240 exp = nf_ct_expect_alloc(ct);
1242 nf_ct_helper_log(skb, ct, "cannot alloc expectation");
1247 if (sip_direct_signalling)
1248 saddr = &ct->tuplehash[!dir].tuple.src.u3;
1250 nf_ct_expect_init(exp, SIP_EXPECT_SIGNALLING, nf_ct_l3num(ct),
1251 saddr, &daddr, proto, NULL, &port);
1252 exp->timeout.expires = sip_timeout * HZ;
1253 exp->helper = nfct_help(ct)->helper;
1254 exp->flags = NF_CT_EXPECT_PERMANENT | NF_CT_EXPECT_INACTIVE;
1256 hooks = rcu_dereference(nf_nat_sip_hooks);
1257 if (hooks && ct->status & IPS_NAT_MASK)
1258 ret = hooks->expect(skb, protoff, dataoff, dptr, datalen,
1259 exp, matchoff, matchlen);
1261 if (nf_ct_expect_related(exp) != 0) {
1262 nf_ct_helper_log(skb, ct, "cannot add expectation");
1267 nf_ct_expect_put(exp);
1270 if (ret == NF_ACCEPT)
1271 ct_sip_info->register_cseq = cseq;
1275 static int process_register_response(struct sk_buff *skb, unsigned int protoff,
1276 unsigned int dataoff,
1277 const char **dptr, unsigned int *datalen,
1278 unsigned int cseq, unsigned int code)
1280 enum ip_conntrack_info ctinfo;
1281 struct nf_conn *ct = nf_ct_get(skb, &ctinfo);
1282 struct nf_ct_sip_master *ct_sip_info = nfct_help_data(ct);
1283 enum ip_conntrack_dir dir = CTINFO2DIR(ctinfo);
1284 union nf_inet_addr addr;
1287 unsigned int matchoff, matchlen, coff = 0;
1288 unsigned int expires = 0;
1289 int in_contact = 0, ret;
1291 /* According to RFC 3261, "UAs MUST NOT send a new registration until
1292 * they have received a final response from the registrar for the
1293 * previous one or the previous REGISTER request has timed out".
1295 * However, some servers fail to detect retransmissions and send late
1296 * responses, so we store the sequence number of the last valid
1297 * request and compare it here.
1299 if (ct_sip_info->register_cseq != cseq)
1302 if (code >= 100 && code <= 199)
1304 if (code < 200 || code > 299)
1307 if (ct_sip_get_header(ct, *dptr, 0, *datalen, SIP_HDR_EXPIRES,
1308 &matchoff, &matchlen) > 0)
1309 expires = simple_strtoul(*dptr + matchoff, NULL, 10);
1312 unsigned int c_expires = expires;
1314 ret = ct_sip_parse_header_uri(ct, *dptr, &coff, *datalen,
1315 SIP_HDR_CONTACT, &in_contact,
1316 &matchoff, &matchlen,
1319 nf_ct_helper_log(skb, ct, "cannot parse contact");
1321 } else if (ret == 0)
1324 /* We don't support third-party registrations */
1325 if (!nf_inet_addr_cmp(&ct->tuplehash[dir].tuple.dst.u3, &addr))
1328 if (ct_sip_parse_transport(ct, *dptr, matchoff + matchlen,
1329 *datalen, &proto) == 0)
1332 ret = ct_sip_parse_numerical_param(ct, *dptr,
1333 matchoff + matchlen,
1334 *datalen, "expires=",
1335 NULL, NULL, &c_expires);
1337 nf_ct_helper_log(skb, ct, "cannot parse expires");
1342 if (refresh_signalling_expectation(ct, &addr, proto, port,
1348 flush_expectations(ct, false);
1352 static const struct sip_handler sip_handlers[] = {
1353 SIP_HANDLER("INVITE", process_invite_request, process_invite_response),
1354 SIP_HANDLER("UPDATE", process_sdp, process_update_response),
1355 SIP_HANDLER("ACK", process_sdp, NULL),
1356 SIP_HANDLER("PRACK", process_sdp, process_prack_response),
1357 SIP_HANDLER("BYE", process_bye_request, NULL),
1358 SIP_HANDLER("REGISTER", process_register_request, process_register_response),
1361 static int process_sip_response(struct sk_buff *skb, unsigned int protoff,
1362 unsigned int dataoff,
1363 const char **dptr, unsigned int *datalen)
1365 enum ip_conntrack_info ctinfo;
1366 struct nf_conn *ct = nf_ct_get(skb, &ctinfo);
1367 unsigned int matchoff, matchlen, matchend;
1368 unsigned int code, cseq, i;
1370 if (*datalen < strlen("SIP/2.0 200"))
1372 code = simple_strtoul(*dptr + strlen("SIP/2.0 "), NULL, 10);
1374 nf_ct_helper_log(skb, ct, "cannot get code");
1378 if (ct_sip_get_header(ct, *dptr, 0, *datalen, SIP_HDR_CSEQ,
1379 &matchoff, &matchlen) <= 0) {
1380 nf_ct_helper_log(skb, ct, "cannot parse cseq");
1383 cseq = simple_strtoul(*dptr + matchoff, NULL, 10);
1384 if (!cseq && *(*dptr + matchoff) != '0') {
1385 nf_ct_helper_log(skb, ct, "cannot get cseq");
1388 matchend = matchoff + matchlen + 1;
1390 for (i = 0; i < ARRAY_SIZE(sip_handlers); i++) {
1391 const struct sip_handler *handler;
1393 handler = &sip_handlers[i];
1394 if (handler->response == NULL)
1396 if (*datalen < matchend + handler->len ||
1397 strncasecmp(*dptr + matchend, handler->method, handler->len))
1399 return handler->response(skb, protoff, dataoff, dptr, datalen,
1405 static int process_sip_request(struct sk_buff *skb, unsigned int protoff,
1406 unsigned int dataoff,
1407 const char **dptr, unsigned int *datalen)
1409 enum ip_conntrack_info ctinfo;
1410 struct nf_conn *ct = nf_ct_get(skb, &ctinfo);
1411 struct nf_ct_sip_master *ct_sip_info = nfct_help_data(ct);
1412 enum ip_conntrack_dir dir = CTINFO2DIR(ctinfo);
1413 unsigned int matchoff, matchlen;
1414 unsigned int cseq, i;
1415 union nf_inet_addr addr;
1418 /* Many Cisco IP phones use a high source port for SIP requests, but
1419 * listen for the response on port 5060. If we are the local
1420 * router for one of these phones, save the port number from the
1421 * Via: header so that nf_nat_sip can redirect the responses to
1424 if (ct_sip_parse_header_uri(ct, *dptr, NULL, *datalen,
1425 SIP_HDR_VIA_UDP, NULL, &matchoff,
1426 &matchlen, &addr, &port) > 0 &&
1427 port != ct->tuplehash[dir].tuple.src.u.udp.port &&
1428 nf_inet_addr_cmp(&addr, &ct->tuplehash[dir].tuple.src.u3))
1429 ct_sip_info->forced_dport = port;
1431 for (i = 0; i < ARRAY_SIZE(sip_handlers); i++) {
1432 const struct sip_handler *handler;
1434 handler = &sip_handlers[i];
1435 if (handler->request == NULL)
1437 if (*datalen < handler->len + 2 ||
1438 strncasecmp(*dptr, handler->method, handler->len))
1440 if ((*dptr)[handler->len] != ' ' ||
1441 !isalpha((*dptr)[handler->len+1]))
1444 if (ct_sip_get_header(ct, *dptr, 0, *datalen, SIP_HDR_CSEQ,
1445 &matchoff, &matchlen) <= 0) {
1446 nf_ct_helper_log(skb, ct, "cannot parse cseq");
1449 cseq = simple_strtoul(*dptr + matchoff, NULL, 10);
1450 if (!cseq && *(*dptr + matchoff) != '0') {
1451 nf_ct_helper_log(skb, ct, "cannot get cseq");
1455 return handler->request(skb, protoff, dataoff, dptr, datalen,
1461 static int process_sip_msg(struct sk_buff *skb, struct nf_conn *ct,
1462 unsigned int protoff, unsigned int dataoff,
1463 const char **dptr, unsigned int *datalen)
1465 const struct nf_nat_sip_hooks *hooks;
1468 if (strncasecmp(*dptr, "SIP/2.0 ", strlen("SIP/2.0 ")) != 0)
1469 ret = process_sip_request(skb, protoff, dataoff, dptr, datalen);
1471 ret = process_sip_response(skb, protoff, dataoff, dptr, datalen);
1473 if (ret == NF_ACCEPT && ct->status & IPS_NAT_MASK) {
1474 hooks = rcu_dereference(nf_nat_sip_hooks);
1475 if (hooks && !hooks->msg(skb, protoff, dataoff,
1477 nf_ct_helper_log(skb, ct, "cannot NAT SIP message");
1485 static int sip_help_tcp(struct sk_buff *skb, unsigned int protoff,
1486 struct nf_conn *ct, enum ip_conntrack_info ctinfo)
1488 struct tcphdr *th, _tcph;
1489 unsigned int dataoff, datalen;
1490 unsigned int matchoff, matchlen, clen;
1491 unsigned int msglen, origlen;
1492 const char *dptr, *end;
1493 s16 diff, tdiff = 0;
1494 int ret = NF_ACCEPT;
1497 if (ctinfo != IP_CT_ESTABLISHED &&
1498 ctinfo != IP_CT_ESTABLISHED_REPLY)
1502 th = skb_header_pointer(skb, protoff, sizeof(_tcph), &_tcph);
1505 dataoff = protoff + th->doff * 4;
1506 if (dataoff >= skb->len)
1509 nf_ct_refresh(ct, skb, sip_timeout * HZ);
1511 if (unlikely(skb_linearize(skb)))
1514 dptr = skb->data + dataoff;
1515 datalen = skb->len - dataoff;
1516 if (datalen < strlen("SIP/2.0 200"))
1520 if (ct_sip_get_header(ct, dptr, 0, datalen,
1521 SIP_HDR_CONTENT_LENGTH,
1522 &matchoff, &matchlen) <= 0)
1525 clen = simple_strtoul(dptr + matchoff, (char **)&end, 10);
1526 if (dptr + matchoff == end)
1530 for (; end + strlen("\r\n\r\n") <= dptr + datalen; end++) {
1531 if (end[0] == '\r' && end[1] == '\n' &&
1532 end[2] == '\r' && end[3] == '\n') {
1539 end += strlen("\r\n\r\n") + clen;
1541 msglen = origlen = end - dptr;
1542 if (msglen > datalen)
1545 ret = process_sip_msg(skb, ct, protoff, dataoff,
1547 /* process_sip_* functions report why this packet is dropped */
1548 if (ret != NF_ACCEPT)
1550 diff = msglen - origlen;
1555 datalen = datalen + diff - msglen;
1558 if (ret == NF_ACCEPT && ct->status & IPS_NAT_MASK) {
1559 const struct nf_nat_sip_hooks *hooks;
1561 hooks = rcu_dereference(nf_nat_sip_hooks);
1563 hooks->seq_adjust(skb, protoff, tdiff);
1569 static int sip_help_udp(struct sk_buff *skb, unsigned int protoff,
1570 struct nf_conn *ct, enum ip_conntrack_info ctinfo)
1572 unsigned int dataoff, datalen;
1576 dataoff = protoff + sizeof(struct udphdr);
1577 if (dataoff >= skb->len)
1580 nf_ct_refresh(ct, skb, sip_timeout * HZ);
1582 if (unlikely(skb_linearize(skb)))
1585 dptr = skb->data + dataoff;
1586 datalen = skb->len - dataoff;
1587 if (datalen < strlen("SIP/2.0 200"))
1590 return process_sip_msg(skb, ct, protoff, dataoff, &dptr, &datalen);
1593 static struct nf_conntrack_helper sip[MAX_PORTS * 4] __read_mostly;
1595 static const struct nf_conntrack_expect_policy sip_exp_policy[SIP_EXPECT_MAX + 1] = {
1596 [SIP_EXPECT_SIGNALLING] = {
1597 .name = "signalling",
1601 [SIP_EXPECT_AUDIO] = {
1603 .max_expected = 2 * IP_CT_DIR_MAX,
1606 [SIP_EXPECT_VIDEO] = {
1608 .max_expected = 2 * IP_CT_DIR_MAX,
1611 [SIP_EXPECT_IMAGE] = {
1613 .max_expected = IP_CT_DIR_MAX,
1618 static void nf_conntrack_sip_fini(void)
1620 nf_conntrack_helpers_unregister(sip, ports_c * 4);
1623 static int __init nf_conntrack_sip_init(void)
1628 ports[ports_c++] = SIP_PORT;
1630 for (i = 0; i < ports_c; i++) {
1631 nf_ct_helper_init(&sip[4 * i], AF_INET, IPPROTO_UDP, "sip",
1632 SIP_PORT, ports[i], i, sip_exp_policy,
1634 sizeof(struct nf_ct_sip_master), sip_help_udp,
1636 nf_ct_helper_init(&sip[4 * i + 1], AF_INET, IPPROTO_TCP, "sip",
1637 SIP_PORT, ports[i], i, sip_exp_policy,
1639 sizeof(struct nf_ct_sip_master), sip_help_tcp,
1641 nf_ct_helper_init(&sip[4 * i + 2], AF_INET6, IPPROTO_UDP, "sip",
1642 SIP_PORT, ports[i], i, sip_exp_policy,
1644 sizeof(struct nf_ct_sip_master), sip_help_udp,
1646 nf_ct_helper_init(&sip[4 * i + 3], AF_INET6, IPPROTO_TCP, "sip",
1647 SIP_PORT, ports[i], i, sip_exp_policy,
1649 sizeof(struct nf_ct_sip_master), sip_help_tcp,
1653 ret = nf_conntrack_helpers_register(sip, ports_c * 4);
1655 pr_err("failed to register helpers\n");
1661 module_init(nf_conntrack_sip_init);
1662 module_exit(nf_conntrack_sip_fini);