1 diff -urN linux-2.6.16.4/net/ipv4/netfilter/ip_conntrack_sip.c linux-2.6.16.4.new/net/ipv4/netfilter/ip_conntrack_sip.c
2 --- linux-2.6.16.4/net/ipv4/netfilter/ip_conntrack_sip.c 1970-01-01 01:00:00.000000000 +0100
3 +++ linux-2.6.16.4.new/net/ipv4/netfilter/ip_conntrack_sip.c 2006-04-12 17:31:44.000000000 +0200
5 +/* SIP extension for IP connection tracking.
7 + * (C) 2005 by Christian Hentschel <chentschel@arnet.com.ar>
8 + * based on RR's ip_conntrack_ftp.c and other modules.
10 + * This program is free software; you can redistribute it and/or modify
11 + * it under the terms of the GNU General Public License version 2 as
12 + * published by the Free Software Foundation.
15 +#include <linux/config.h>
16 +#include <linux/module.h>
17 +#include <linux/netfilter.h>
18 +#include <linux/ip.h>
19 +#include <linux/ctype.h>
20 +#include <linux/in.h>
21 +#include <linux/udp.h>
22 +#include <net/checksum.h>
25 +#include <linux/netfilter_ipv4/ip_conntrack_helper.h>
26 +#include <linux/netfilter_ipv4/ip_conntrack_sip.h>
28 +MODULE_LICENSE("GPL");
29 +MODULE_AUTHOR("Christian Hentschel <chentschel@arnet.com.ar>");
30 +MODULE_DESCRIPTION("SIP connection tracking helper");
32 +static DEFINE_SPINLOCK(sipbf_lock);
36 +static int ports[MAX_PORTS];
38 +module_param_array(ports, int, &ports_c, 0400);
39 +MODULE_PARM_DESC(ports, " port numbers of sip servers");
41 +static unsigned int sip_timeout = SIP_TIMEOUT;
43 +module_param(sip_timeout, int, 0600);
44 +MODULE_PARM_DESC(sip_timeout, "timeout for the master sip session");
46 +unsigned int (*ip_nat_sip_hook)(struct sk_buff **pskb,
47 + enum ip_conntrack_info ctinfo,
48 + struct ip_conntrack *ct,
50 +EXPORT_SYMBOL_GPL(ip_nat_sip_hook);
52 +unsigned int (*ip_nat_sdp_hook)(struct sk_buff **pskb,
53 + enum ip_conntrack_info ctinfo,
54 + struct ip_conntrack_expect *exp,
56 +EXPORT_SYMBOL_GPL(ip_nat_sdp_hook);
58 +int ct_sip_get_info(const char *dptr, size_t dlen,
59 + unsigned int *matchoff,
60 + unsigned int *matchlen,
61 + struct sip_header_nfo *hnfo);
62 +EXPORT_SYMBOL(ct_sip_get_info);
65 +#define DEBUGP printk
67 +#define DEBUGP(format, args...)
70 +static int digits_len(const char *dptr, const char *limit, int *shift);
71 +static int epaddr_len(const char *dptr, const char *limit, int *shift);
72 +static int skp_digits_len(const char *dptr, const char *limit, int *shift);
73 +static int skp_epaddr_len(const char *dptr, const char *limit, int *shift);
75 +struct sip_header_nfo ct_sip_hdrs[] = {
77 + "Via:", sizeof("Via:") - 1,
78 + "\r\nv:", sizeof("\r\nv:") - 1, /* rfc3261 "\r\n" */
79 + "UDP ", sizeof("UDP ") - 1,
82 + { /* Contact header */
83 + "Contact:", sizeof("Contact:") - 1,
84 + "\r\nm:", sizeof("\r\nm:") - 1,
85 + "sip:", sizeof("sip:") - 1,
88 + { /* Content length header */
89 + "Content-Length:", sizeof("Content-Length:") - 1,
90 + "\r\nl:", sizeof("\r\nl:") - 1,
91 + ":", sizeof(":") - 1,
94 + { /* SDP media info */
95 + "\nm=", sizeof("\nm=") - 1,
96 + "\rm=", sizeof("\rm=") - 1,
97 + "audio ", sizeof("audio ") - 1,
100 + { /* SDP owner address*/
101 + "\no=", sizeof("\no=") - 1,
102 + "\ro=", sizeof("\ro=") - 1,
103 + "IN IP4 ", sizeof("IN IP4 ") - 1,
106 + { /* SDP connection info */
107 + "\nc=", sizeof("\nc=") - 1,
108 + "\rc=", sizeof("\rc=") - 1,
109 + "IN IP4 ", sizeof("IN IP4 ") - 1,
112 + { /* Requests headers */
113 + "sip:", sizeof("sip:") - 1,
114 + "sip:", sizeof("sip:") - 1, /* yes, i know.. ;) */
115 + "@", sizeof("@") - 1,
118 + { /* SDP version header */
119 + "\nv=", sizeof("\nv=") - 1,
120 + "\rv=", sizeof("\rv=") - 1,
121 + "=", sizeof("=") - 1,
125 +EXPORT_SYMBOL(ct_sip_hdrs);
128 +static int digits_len(const char *dptr, const char *limit, int *shift)
131 + while (dptr <= limit && isdigit(*dptr)) {
138 +/* get digits lenght, skiping blank spaces. */
139 +static int skp_digits_len(const char *dptr, const char *limit, int *shift)
141 + for (; dptr <= limit && *dptr == ' '; dptr++)
144 + return digits_len(dptr, limit, shift);
147 +/* Simple ipaddr parser.. */
148 +static int parse_ipaddr(const char *cp, const char **endp,
149 + uint32_t *ipaddr, const char *limit)
151 + unsigned long int val;
154 + for (i = 0, *ipaddr = 0; cp <= limit && i < 4; i++) {
159 + val = simple_strtoul(cp, (char **)&cp, 10);
163 + ((uint8_t *)ipaddr)[i] = val;
179 +/* skip ip address. returns it lenght. */
180 +static int epaddr_len(const char *dptr, const char *limit, int *shift)
182 + const char *aux = dptr;
185 + if (parse_ipaddr(dptr, &dptr, &ip, limit) < 0) {
186 + DEBUGP("ip: %s parse failed.!\n", dptr);
191 + if (*dptr == ':') {
193 + dptr += digits_len(dptr, limit, shift);
198 +/* get address lenght, skiping user info. */
199 +static int skp_epaddr_len(const char *dptr, const char *limit, int *shift)
201 + for (; dptr <= limit && *dptr != '@'; dptr++)
204 + if (*dptr == '@') {
207 + return epaddr_len(dptr, limit, shift);
212 +/* Returns 0 if not found, -1 error parsing. */
213 +int ct_sip_get_info(const char *dptr, size_t dlen,
214 + unsigned int *matchoff,
215 + unsigned int *matchlen,
216 + struct sip_header_nfo *hnfo)
218 + const char *limit, *aux, *k = dptr;
221 + limit = dptr + (dlen - hnfo->lnlen);
223 + while (dptr <= limit) {
224 + if ((strncmp(dptr, hnfo->lname, hnfo->lnlen) != 0) &&
225 + (strncmp(dptr, hnfo->sname, hnfo->snlen) != 0))
230 + aux = ct_sip_search(hnfo->ln_str, dptr, hnfo->ln_strlen,
231 + ct_sip_lnlen(dptr, limit));
233 + DEBUGP("'%s' not found in '%s'.\n", hnfo->ln_str, hnfo->lname);
236 + aux += hnfo->ln_strlen;
238 + *matchlen = hnfo->match_len(aux, limit, &shift);
242 + *matchoff = (aux - k) + shift;
244 + DEBUGP("%s match succeeded! - len: %u\n", hnfo->lname, *matchlen);
247 + DEBUGP("%s header not found.\n", hnfo->lname);
251 +static int set_expected_rtp(struct sk_buff **pskb,
252 + struct ip_conntrack *ct,
253 + enum ip_conntrack_info ctinfo,
254 + uint32_t ipaddr, uint16_t port,
257 + struct ip_conntrack_expect *exp;
260 + exp = ip_conntrack_expect_alloc(ct);
264 + exp->tuple = ((struct ip_conntrack_tuple)
265 + { { ct->tuplehash[IP_CT_DIR_REPLY].tuple.src.ip, { 0 } },
266 + { ipaddr, { .udp = { htons(port) } }, IPPROTO_UDP }});
268 + exp->mask = ((struct ip_conntrack_tuple)
269 + { { 0xFFFFFFFF, { 0 } },
270 + { 0xFFFFFFFF, { .udp = { 0xFFFF } }, 0xFF }});
272 + exp->expectfn = NULL;
274 + if (ip_nat_sdp_hook)
275 + ret = ip_nat_sdp_hook(pskb, ctinfo, exp, dptr);
277 + if (ip_conntrack_expect_related(exp) != 0)
282 + ip_conntrack_expect_put(exp);
287 +static int sip_help(struct sk_buff **pskb,
288 + struct ip_conntrack *ct,
289 + enum ip_conntrack_info ctinfo)
291 + unsigned int dataoff, datalen;
293 + int ret = NF_ACCEPT;
294 + int matchoff, matchlen;
299 + dataoff = (*pskb)->nh.iph->ihl*4 + sizeof(struct udphdr);
300 + if (dataoff >= (*pskb)->len) {
301 + DEBUGP("skb->len = %u\n", (*pskb)->len);
305 + ip_ct_refresh(ct, *pskb, sip_timeout * HZ);
307 + spin_lock_bh(&sipbf_lock);
309 + if ((dataoff + (*pskb)->len - dataoff) <= skb_headlen(*pskb))
310 + dptr = (*pskb)->data + dataoff;
312 + DEBUGP("Copy of skbuff not supported yet.\n");
316 + if (ip_nat_sip_hook) {
317 + if (!ip_nat_sip_hook(pskb, ctinfo, ct, &dptr)) {
323 + if ((ctinfo) >= IP_CT_IS_REPLY)
326 + /* After this point NAT, could have mangled skb, so
327 + we need to recalculate payload lenght. */
328 + datalen = (*pskb)->len - dataoff;
330 + if (datalen < (sizeof("SIP/2.0 200") - 1))
333 + /* RTP info only in some SDP pkts */
334 + if (memcmp(dptr, "INVITE", sizeof("INVITE") - 1) != 0 &&
335 + memcmp(dptr, "SIP/2.0 200", sizeof("SIP/2.0 200") - 1) != 0) {
338 + /* Get ip and port address from SDP packet. */
339 + if (ct_sip_get_info(dptr, datalen, &matchoff, &matchlen,
340 + &ct_sip_hdrs[POS_CONECTION]) > 0) {
342 + /* We'll drop only if there are parse problems. */
343 + if (parse_ipaddr(dptr + matchoff, NULL, &ipaddr,
344 + dptr + datalen) < 0) {
348 + if (ct_sip_get_info(dptr, datalen, &matchoff, &matchlen,
349 + &ct_sip_hdrs[POS_MEDIA]) > 0) {
351 + port = simple_strtoul(dptr + matchoff, NULL, 10);
356 + ret = set_expected_rtp(pskb, ct, ctinfo,
357 + ipaddr, port, dptr);
360 +out: spin_unlock_bh(&sipbf_lock);
364 +static struct ip_conntrack_helper sip[MAX_PORTS];
365 +static char sip_names[MAX_PORTS][10];
367 +static void fini(void)
370 + for (; i < ports_c; i++) {
371 + DEBUGP("unregistering helper for port %d\n", ports[i]);
372 + ip_conntrack_helper_unregister(&sip[i]);
376 +static int __init init(void)
382 + ports[ports_c++] = SIP_PORT;
384 + for (i = 0; i < ports_c; i++) {
385 + /* Create helper structure */
386 + memset(&sip[i], 0, sizeof(struct ip_conntrack_helper));
388 + sip[i].tuple.dst.protonum = IPPROTO_UDP;
389 + sip[i].tuple.src.u.udp.port = htons(ports[i]);
390 + sip[i].mask.src.u.udp.port = 0xFFFF;
391 + sip[i].mask.dst.protonum = 0xFF;
392 + sip[i].max_expected = 1;
393 + sip[i].timeout = 3 * 60; /* 3 minutes */
394 + sip[i].me = THIS_MODULE;
395 + sip[i].help = sip_help;
397 + tmpname = &sip_names[i][0];
398 + if (ports[i] == SIP_PORT)
399 + sprintf(tmpname, "sip");
401 + sprintf(tmpname, "sip-%d", i);
402 + sip[i].name = tmpname;
404 + DEBUGP("port #%d: %d\n", i, ports[i]);
406 + ret=ip_conntrack_helper_register(&sip[i]);
408 + printk("ERROR registering helper for port %d\n",
419 diff -urN linux-2.6.16.4/net/ipv4/netfilter/ip_nat_sip.c linux-2.6.16.4.new/net/ipv4/netfilter/ip_nat_sip.c
420 --- linux-2.6.16.4/net/ipv4/netfilter/ip_nat_sip.c 1970-01-01 01:00:00.000000000 +0100
421 +++ linux-2.6.16.4.new/net/ipv4/netfilter/ip_nat_sip.c 2006-04-12 17:31:53.000000000 +0200
423 +/* SIP extension for UDP NAT alteration.
425 + * (C) 2005 by Christian Hentschel <chentschel@arnet.com.ar>
426 + * based on RR's ip_nat_ftp.c and other modules.
428 + * This program is free software; you can redistribute it and/or modify
429 + * it under the terms of the GNU General Public License version 2 as
430 + * published by the Free Software Foundation.
433 +#include <linux/module.h>
434 +#include <linux/netfilter_ipv4.h>
435 +#include <linux/ip.h>
436 +#include <linux/udp.h>
437 +#include <net/udp.h>
439 +#include <linux/netfilter_ipv4/ip_nat.h>
440 +#include <linux/netfilter_ipv4/ip_nat_helper.h>
441 +#include <linux/netfilter_ipv4/ip_conntrack_helper.h>
442 +#include <linux/netfilter_ipv4/ip_conntrack_sip.h>
444 +MODULE_LICENSE("GPL");
445 +MODULE_AUTHOR("Christian Hentschel <chentschel@arnet.com.ar>");
446 +MODULE_DESCRIPTION("SIP NAT helper");
449 +#define DEBUGP printk
451 +#define DEBUGP(format, args...)
454 +extern struct sip_header_nfo ct_sip_hdrs[];
456 +static unsigned int mangle_sip_packet(struct sk_buff **pskb,
457 + enum ip_conntrack_info ctinfo,
458 + struct ip_conntrack *ct,
459 + const char **dptr, size_t dlen,
460 + char *buffer, int bufflen,
461 + struct sip_header_nfo *hnfo)
463 + unsigned int matchlen, matchoff;
465 + if (ct_sip_get_info(*dptr, dlen, &matchoff, &matchlen, hnfo) <= 0)
468 + if (!ip_nat_mangle_udp_packet(pskb, ct, ctinfo,
469 + matchoff, matchlen, buffer, bufflen)) {
472 + /* We need to reload this. Thanks Patrick. */
473 + *dptr = (*pskb)->data + (*pskb)->nh.iph->ihl*4 + sizeof(struct udphdr);
477 +static unsigned int ip_nat_sip(struct sk_buff **pskb,
478 + enum ip_conntrack_info ctinfo,
479 + struct ip_conntrack *ct,
482 + char buffer[sizeof("nnn.nnn.nnn.nnn:nnnnn")];
483 + unsigned int bufflen, dataoff;
487 + dataoff = (*pskb)->nh.iph->ihl*4 + sizeof(struct udphdr);
489 + if ((ctinfo) >= IP_CT_IS_REPLY) {
490 + ip = ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.src.ip;
491 + port = ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.src.u.udp.port;
493 + ip = ct->tuplehash[IP_CT_DIR_REPLY].tuple.dst.ip;
494 + port = ct->tuplehash[IP_CT_DIR_REPLY].tuple.dst.u.udp.port;
496 + bufflen = sprintf(buffer, "%u.%u.%u.%u:%u", NIPQUAD(ip), ntohs(port));
498 + /* short packet ? */
499 + if (((*pskb)->len - dataoff) < (sizeof("SIP/2.0") - 1))
502 + /* Basic rules: requests and responses. */
503 + if (memcmp(*dptr, "SIP/2.0", sizeof("SIP/2.0") - 1) == 0) {
505 + if ((ctinfo) < IP_CT_IS_REPLY) {
506 + mangle_sip_packet(pskb, ctinfo, ct, dptr,
507 + (*pskb)->len - dataoff, buffer, bufflen,
508 + &ct_sip_hdrs[POS_CONTACT]);
512 + if (!mangle_sip_packet(pskb, ctinfo, ct, dptr, (*pskb)->len - dataoff,
513 + buffer, bufflen, &ct_sip_hdrs[POS_VIA])) {
517 + /* This search should ignore case, but later.. */
518 + const char *aux = ct_sip_search("CSeq:", *dptr, sizeof("CSeq:") - 1,
519 + (*pskb)->len - dataoff);
523 + if (!ct_sip_search("REGISTER", aux, sizeof("REGISTER"),
524 + ct_sip_lnlen(aux, *dptr + (*pskb)->len - dataoff))) {
527 + return mangle_sip_packet(pskb, ctinfo, ct, dptr, (*pskb)->len - dataoff,
528 + buffer, bufflen, &ct_sip_hdrs[POS_CONTACT]);
530 + if ((ctinfo) < IP_CT_IS_REPLY) {
531 + if (!mangle_sip_packet(pskb, ctinfo, ct, dptr, (*pskb)->len - dataoff,
532 + buffer, bufflen, &ct_sip_hdrs[POS_VIA])) {
536 + /* Mangle Contact if exists only. - watch udp_nat_mangle()! */
537 + mangle_sip_packet(pskb, ctinfo, ct, dptr, (*pskb)->len - dataoff,
538 + buffer, bufflen, &ct_sip_hdrs[POS_CONTACT]);
541 + /* This mangle requests headers. */
542 + return mangle_sip_packet(pskb, ctinfo, ct, dptr,
543 + ct_sip_lnlen(*dptr, *dptr + (*pskb)->len - dataoff),
544 + buffer, bufflen, &ct_sip_hdrs[POS_REQ_HEADER]);
547 +static int mangle_content_len(struct sk_buff **pskb,
548 + enum ip_conntrack_info ctinfo,
549 + struct ip_conntrack *ct,
552 + unsigned int dataoff, matchoff, matchlen;
553 + char buffer[sizeof("65536")];
556 + dataoff = (*pskb)->nh.iph->ihl*4 + sizeof(struct udphdr);
558 + /* Get actual SDP lenght */
559 + if (ct_sip_get_info(dptr, (*pskb)->len - dataoff, &matchoff,
560 + &matchlen, &ct_sip_hdrs[POS_SDP_HEADER]) > 0) {
562 + /* since ct_sip_get_info() give us a pointer passing 'v='
563 + we need to add 2 bytes in this count. */
564 + int c_len = (*pskb)->len - dataoff - matchoff + 2;
566 + /* Now, update SDP lenght */
567 + if (ct_sip_get_info(dptr, (*pskb)->len - dataoff, &matchoff,
568 + &matchlen, &ct_sip_hdrs[POS_CONTENT]) > 0) {
570 + bufflen = sprintf(buffer, "%u", c_len);
572 + return ip_nat_mangle_udp_packet(pskb, ct, ctinfo, matchoff,
573 + matchlen, buffer, bufflen);
579 +static unsigned int mangle_sdp(struct sk_buff **pskb,
580 + enum ip_conntrack_info ctinfo,
581 + struct ip_conntrack *ct,
582 + uint32_t newip, uint16_t port,
585 + char buffer[sizeof("nnn.nnn.nnn.nnn")];
586 + unsigned int dataoff, bufflen;
588 + dataoff = (*pskb)->nh.iph->ihl*4 + sizeof(struct udphdr);
590 + /* Mangle owner and contact info. */
591 + bufflen = sprintf(buffer, "%u.%u.%u.%u", NIPQUAD(newip));
592 + if (!mangle_sip_packet(pskb, ctinfo, ct, &dptr, (*pskb)->len - dataoff,
593 + buffer, bufflen, &ct_sip_hdrs[POS_OWNER])) {
597 + if (!mangle_sip_packet(pskb, ctinfo, ct, &dptr, (*pskb)->len - dataoff,
598 + buffer, bufflen, &ct_sip_hdrs[POS_CONECTION])) {
602 + /* Mangle media port. */
603 + bufflen = sprintf(buffer, "%u", port);
604 + if (!mangle_sip_packet(pskb, ctinfo, ct, &dptr, (*pskb)->len - dataoff,
605 + buffer, bufflen, &ct_sip_hdrs[POS_MEDIA])) {
609 + return mangle_content_len(pskb, ctinfo, ct, dptr);
612 +/* So, this packet has hit the connection tracking matching code.
613 + Mangle it, and change the expectation to match the new version. */
614 +static unsigned int ip_nat_sdp(struct sk_buff **pskb,
615 + enum ip_conntrack_info ctinfo,
616 + struct ip_conntrack_expect *exp,
619 + struct ip_conntrack *ct = exp->master;
623 + DEBUGP("ip_nat_sdp():\n");
625 + /* Connection will come from reply */
626 + newip = ct->tuplehash[IP_CT_DIR_REPLY].tuple.dst.ip;
628 + exp->tuple.dst.ip = newip;
629 + exp->saved_proto.udp.port = exp->tuple.dst.u.udp.port;
630 + exp->dir = IP_CT_DIR_REPLY;
632 + /* When you see the packet, we need to NAT it the same as the
634 + exp->expectfn = ip_nat_follow_master;
636 + /* Try to get same port: if not, try to change it. */
637 + for (port = ntohs(exp->saved_proto.udp.port); port != 0; port++) {
638 + exp->tuple.dst.u.udp.port = htons(port);
639 + if (ip_conntrack_expect_related(exp) == 0)
646 + if (!mangle_sdp(pskb, ctinfo, ct, newip, port, dptr)) {
647 + ip_conntrack_unexpect_related(exp);
653 +static void __exit fini(void)
655 + ip_nat_sip_hook = NULL;
656 + ip_nat_sdp_hook = NULL;
657 + /* Make sure noone calls it, meanwhile. */
661 +static int __init init(void)
663 + BUG_ON(ip_nat_sip_hook);
664 + BUG_ON(ip_nat_sdp_hook);
665 + ip_nat_sip_hook = ip_nat_sip;
666 + ip_nat_sdp_hook = ip_nat_sdp;
672 diff -urN linux-2.6.16.4/net/ipv4/netfilter/Kconfig linux-2.6.16.4.new/net/ipv4/netfilter/Kconfig
673 --- linux-2.6.16.4/net/ipv4/netfilter/Kconfig 2006-04-12 17:29:19.000000000 +0200
674 +++ linux-2.6.16.4.new/net/ipv4/netfilter/Kconfig 2006-04-12 17:32:53.000000000 +0200
676 If you want to compile it as a module, say M here and read
677 Documentation/modules.txt. If unsure, say `N'.
680 + tristate 'SIP support'
681 + depends on IP_NF_CONNTRACK
683 + SIP is an application-layer control protocol that can establish,
684 + modify, and terminate multimedia sessions (conferences) such as
685 + Internet telephony calls. With the ip_conntrack_sip and
686 + the ip_nat_sip modules you can support the protocol on a connection
687 + tracking/NATing firewall.
689 + If you want to compile it as a module, say 'M' here and read
690 + Documentation/modules.txt. If unsure, say 'N'.
693 tristate "IP Userspace queueing via NETLINK (OBSOLETE)"
696 default IP_NF_NAT if IP_NF_PPTP=y
697 default m if IP_NF_PPTP=m
699 +config IP_NF_NAT_SIP
701 + depends on IP_NF_CONNTRACK!=n && IP_NF_NAT!=n
702 + default IP_NF_NAT if IP_NF_SIP=y
703 + default m if IP_NF_SIP=m
705 # mangle + specific targets
707 tristate "Packet mangling"
708 diff -urN linux-2.6.16.4/net/ipv4/netfilter/Makefile linux-2.6.16.4.new/net/ipv4/netfilter/Makefile
709 --- linux-2.6.16.4/net/ipv4/netfilter/Makefile 2006-04-12 17:29:19.000000000 +0200
710 +++ linux-2.6.16.4.new/net/ipv4/netfilter/Makefile 2006-04-12 17:33:39.000000000 +0200
712 obj-$(CONFIG_IP_NF_FTP) += ip_conntrack_ftp.o
713 obj-$(CONFIG_IP_NF_IRC) += ip_conntrack_irc.o
714 obj-$(CONFIG_IP_NF_NETBIOS_NS) += ip_conntrack_netbios_ns.o
715 +obj-$(CONFIG_IP_NF_SIP) += ip_conntrack_sip.o
718 obj-$(CONFIG_IP_NF_NAT_PPTP) += ip_nat_pptp.o
720 obj-$(CONFIG_IP_NF_NAT_TFTP) += ip_nat_tftp.o
721 obj-$(CONFIG_IP_NF_NAT_FTP) += ip_nat_ftp.o
722 obj-$(CONFIG_IP_NF_NAT_IRC) += ip_nat_irc.o
723 +obj-$(CONFIG_IP_NF_NAT_SIP) += ip_nat_sip.o
726 obj-$(CONFIG_IP_NF_IPTABLES) += ip_tables.o
727 diff -urN linux-2.6.16.4/include/linux/netfilter_ipv4/ip_conntrack.h linux-2.6.16.4.new/include/linux/netfilter_ipv4/ip_conntrack.h
728 --- linux-2.6.16.4/include/linux/netfilter_ipv4/ip_conntrack.h 2006-04-12 17:29:19.000000000 +0200
729 +++ linux-2.6.16.4.new/include/linux/netfilter_ipv4/ip_conntrack.h 2006-04-12 17:30:38.000000000 +0200
731 #include <linux/netfilter_ipv4/ip_conntrack_amanda.h>
732 #include <linux/netfilter_ipv4/ip_conntrack_ftp.h>
733 #include <linux/netfilter_ipv4/ip_conntrack_irc.h>
734 +#include <linux/netfilter_ipv4/ip_conntrack_sip.h>
736 /* per conntrack: application helper private data */
737 union ip_conntrack_help {
739 struct ip_ct_pptp_master ct_pptp_info;
740 struct ip_ct_ftp_master ct_ftp_info;
741 struct ip_ct_irc_master ct_irc_info;
742 + struct ip_ct_sip_master ct_sip_info;
745 #ifdef CONFIG_IP_NF_NAT_NEEDED
746 diff -urN linux-2.6.16.4/include/linux/netfilter_ipv4/ip_conntrack_sip.h linux-2.6.16.4.new/include/linux/netfilter_ipv4/ip_conntrack_sip.h
747 --- linux-2.6.16.4/include/linux/netfilter_ipv4/ip_conntrack_sip.h 1970-01-01 01:00:00.000000000 +0100
748 +++ linux-2.6.16.4.new/include/linux/netfilter_ipv4/ip_conntrack_sip.h 2006-04-12 17:31:12.000000000 +0200
750 +#ifndef __IP_CONNTRACK_SIP_H__
751 +#define __IP_CONNTRACK_SIP_H__
756 +#define SIP_PORT 5060
757 +#define SIP_TIMEOUT 3600
760 +#define POS_CONTACT 1
761 +#define POS_CONTENT 2
764 +#define POS_CONECTION 5
765 +#define POS_REQ_HEADER 6
766 +#define POS_SDP_HEADER 7
768 +struct ip_ct_sip_master {
771 +struct sip_header_nfo {
776 + const char *ln_str;
778 + int (*match_len)(const char *, const char *, int *);
782 +extern unsigned int (*ip_nat_sip_hook)(struct sk_buff **pskb,
783 + enum ip_conntrack_info ctinfo,
784 + struct ip_conntrack *ct,
785 + const char **dptr);
787 +/* For NAT to hook in when on expect. */
788 +extern unsigned int (*ip_nat_sdp_hook)(struct sk_buff **pskb,
789 + enum ip_conntrack_info ctinfo,
790 + struct ip_conntrack_expect *exp,
793 +extern int ct_sip_get_info(const char *dptr, size_t dlen,
794 + unsigned int *matchoff,
795 + unsigned int *matchlen,
796 + struct sip_header_nfo *hnfo);
798 +/* get line lenght until first CR or LF seen. */
799 +static __inline__ int ct_sip_lnlen(const char *line, const char *limit)
801 + const char *k = line;
803 + while ((line <= limit) && (*line == '\r' || *line == '\n'))
806 + while (line <= limit) {
807 + if (*line == '\r' || *line == '\n')
814 +/* Linear string search, case sensitive. */
816 +const char *ct_sip_search(const char *needle, const char *haystack,
817 + size_t needle_len, size_t haystack_len)
819 + const char *limit = haystack + (haystack_len - needle_len);
821 + while (haystack <= limit) {
822 + if (memcmp(haystack, needle, needle_len) == 0)
828 +#endif /* __KERNEL__ */
830 +#endif /* __IP_CONNTRACK_SIP_H__ */