SIP/RTP support coming?
Subsystems (2)
Quoted 1 line
From the FAQ on the netfilter site, I see the comment:
"The netfilter/iptables team has currently no resources to implement SIP conntrack/NAT support, but we're always open for sponsors :)"
I have also noticed that Linksys have implemented some basic support for SIP/SDP/RTP conntrack/NAT. I believe that due to the complexity of the SIP protocol, there are one or two small problems with certain message types - mentioned in
https://lists.netfilter.org/pipermail/netfilter/2004-December/057518.html
(A patch taken from the linksys code was offered in
https://lists.netfilter.org/pipermail/netfilter-devel/2005-January/018252.html)
Are there plans to integrate this officially? Should I take time to (try to) update the patch to the 2.6.x kernel? Am I missing something?
Thanks,
Steve
Quoted 3 lines · Steve Davies
Are there plans to integrate this officially? Should I take time to (try to) update the patch to the 2.6.x kernel? Am I missing something?
I believe nobody is working on that yet; I planned to look at the code when I'm done with the H.323 module, but that will take some time.
A lot people would be thankful if you hacked the source, and ported that to Linux 2.6.11-rc3 (the API has changed very much since 2.6.10; don't use the old API).
You should start with providing a patch-o-matic module (see netfilter home page) of the original code, and then send patches with your changes.
Max
Quoted 3 lines · Max Kellermann
A lot people would be thankful if you hacked the source, and ported that to Linux 2.6.11-rc3 (the API has changed very much since 2.6.10; don't use the old API).
Agreed! There are lots of us out here would be thrilled to help test a SIP/SDP ALG for netfilter.
Quoted 8 lines · Max Kellermann
Quoted 3 lines · Steve Davies
Are there plans to integrate this officially? Should I take time to (try to) update the patch to the 2.6.x kernel? Am I missing something?
I believe nobody is working on that yet; I planned to look at the code when I'm done with the H.323 module, but that will take some time.
Quoted 8 lines
A lot people would be thankful if you hacked the source, and ported that to Linux 2.6.11-rc3 (the API has changed very much since 2.6.10; don't use the old API).
You should start with providing a patch-o-matic module (see netfilter home page) of the original code, and then send patches with your changes.
Thanks for the pointers... I just started a new job, so I am HUGELY busy, but given the potential benefit of this for me personally, I think I'll try and make the time :)
Regards,
Steve
Hi, i'm very interesting in a conntrack/nat helper for sip. Currently i'm working on this and help with testing will be great. i've used kernel 2.6.10 for this.
Christian.
Quoted 19 lines · Max Kellermann
Quoted 3 lines · Steve Davies
Are there plans to integrate this officially? Should I take time to (try to) update the patch to the 2.6.x kernel? Am I missing something?
I believe nobody is working on that yet; I planned to look at the code when I'm done with the H.323 module, but that will take some time.
A lot people would be thankful if you hacked the source, and ported that to Linux 2.6.11-rc3 (the API has changed very much since 2.6.10; don't use the old API).
You should start with providing a patch-o-matic module (see netfilter home page) of the original code, and then send patches with your changes.
Max
obj-m := ip_conntrack_sip.o
KDIR := /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
default:
$(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules
clean:
rm -f *.ko *.o *mod.c
/* SIP extension for IP connection tracking.
*
* (C) 2005 Christian Hentschel
* based on RR's ip_conntrack_ftp.c and other modules.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*/
#include <linux/config.h>
#include <linux/module.h>
#include <linux/netfilter.h>
#include <linux/ip.h>
#include <linux/ctype.h>
#include <net/checksum.h>
#include <net/udp.h>
#include <linux/netfilter_ipv4/lockhelp.h> #include <linux/netfilter_ipv4/ip_conntrack_helper.h>
MODULE_LICENSE("GPL");MODULE_AUTHOR("Christian Hentschel <[email protected]>"); MODULE_DESCRIPTION("SIP connection tracking helper");
#define SIP_PORT 5060
#define RTP_TIMEOUT 180
static char sip_buffer[65536];
static DECLARE_LOCK(sipbf_lock);
struct module *ip_conntrack_sip = THIS_MODULE;
#define MAX_PORTS 8
static int ports[MAX_PORTS];
static int ports_c;module_param_array(ports, int, &ports_c, 0400); MODULE_PARM_DESC(ports, " port numbers of sip servers");
//#if 0
#define DEBUGP printk
//#else
//#define DEBUGP(format, args...)
//#endif
struct ip_ct_sip_expect {
u_int32_t ip_offset;
u_int32_t ip_len;
u_int32_t port_offset;
u_int32_t port_len;
u_int16_t port;
};static int rtp_expectfn(struct ip_conntrack *new)
{
DEBUGP("ct_sip: Got RTP..\n");
return 0;
}static int skip_atoi(const char **str)
{
unsigned int result = 0;
while (isdigit(**str))
result = result*10 + *((*str)++) - '0';
return result;
}static int get_ep_addr(const char *dptr,
u_int32_t *ip, struct ip_ct_sip_expect *exp)
{
int i;
const char *aux = dptr;
dptr = strstr(dptr, "c=IN IP4 ");
if (!dptr) {
DEBUGP("ct_sip: 'c=' not found.\n");
return -1;
}
dptr += 9;
// exp->ip_offset = (dptr - aux);
for (i = 3; i >= 0; i--){
((unsigned char *)ip)[i] = skip_atoi(&dptr);
dptr++;
}
// exp->ip_len = (dptr - exp->ip_offset);
dptr = strstr(dptr, "m=audio ");
if (!dptr) {
DEBUGP("ct_sip: 'm=' not found.\n");
return -1;
}
dptr += 8;
// exp->port_offset = (dptr - aux);
exp->port = skip_atoi(&dptr);
// exp->port_len = (dptr - exp->port_offset);
if (exp->port < 1024)
return -1;
return 0;
}static int sip_help(struct sk_buff *skb,
struct ip_conntrack *ct, enum ip_conntrack_info ctinfo)
{
struct ip_ct_sip_expect *exp_sip_info, exp_tmp;
struct ip_conntrack_expect *exp;
unsigned int dataoff, datalen;
char *dptr;
u_int32_t rtp_ip;
if (ctinfo >= IP_CT_IS_REPLY)
return NF_ACCEPT;
/* No Data ? */
dataoff = skb->nh.iph->ihl * 4 + sizeof(struct udphdr);
if (dataoff >= skb->len){
DEBUGP("ct_sip: skb->len = %u\n", skb->len);
return NF_ACCEPT;
}
datalen = skb->len - dataoff;
LOCK_BH(&sipbf_lock);
dptr = skb_header_pointer(skb, dataoff, datalen, sip_buffer);
BUG_ON(dptr == NULL);
DEBUGP("ct_sip: datalen %u\n", datalen);
if (memcmp(dptr, "INVITE", 6) != 0 && memcmp(dptr, "SIP/2.0 200", 11) != 0) {
DEBUGP("ct_sip: Not interesting pkt.\n");
goto out;
}
*(dptr + datalen) = '\0';
if (get_ep_addr(dptr, &rtp_ip, &exp_tmp) < 0)
goto out;
DUMP_TUPLE(&ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple);
DUMP_TUPLE(&ct->tuplehash[IP_CT_DIR_REPLY].tuple);
exp = ip_conntrack_expect_alloc();
if (exp == NULL)
goto out;/* exp_sip_info = &exp->help.exp_sip_info;
exp_sip_info->port_offset = exp_tmp->port_offset;
exp_sip_info->ip_offset = exp_tmp->ip_offset;
exp_sip_info->port_len = exp_tmp->port_len;
exp_sip_info->ip_len = exp_tmp->ip_len;
exp_sip_info->port = exp_tmp->port;
*/
exp->tuple = ((struct ip_conntrack_tuple)
{ { ct->tuplehash[IP_CT_DIR_REPLY].tuple.src.ip, { 0 } },
{ htonl(rtp_ip), { .udp = { htons(exp_tmp.port) } },
IPPROTO_UDP }});
exp->mask = ((struct ip_conntrack_tuple)
{ { 0xFFFFFFFF, { 0 } },
{ 0xFFFFFFFF, { .udp = { 0xFFFF } }, 0xFFFF }});
exp->expectfn = rtp_expectfn; //NULL;
DUMP_TUPLE(&exp->tuple);
DUMP_TUPLE(&exp->mask);
ip_conntrack_expect_related(exp, ct);
out:
UNLOCK_BH(&sipbf_lock);
return NF_ACCEPT;
} static struct ip_conntrack_helper sip[MAX_PORTS];
static char sip_names[MAX_PORTS][10];
static void fini(void)
{
int i=0;
for (; i < ports_c; i++) {
DEBUGP("ip_ct_sip: unregistering helper for port %d\n", ports[i]);
ip_conntrack_helper_unregister(&sip[i]);
}
}static int __init init(void)
{
int i, ret;
char *tmpname;
if (ports_c == 0)
ports[ports_c++] = SIP_PORT;
for (i=0; i < ports_c; i++) {
sip[i].tuple.src.u.udp.port = htons(ports[i]);
sip[i].tuple.dst.protonum = IPPROTO_UDP;
sip[i].mask.src.u.udp.port = 0xFFFF;
sip[i].mask.dst.protonum = 0xFFFF;
sip[i].max_expected = 1;
sip[i].timeout = RTP_TIMEOUT;
sip[i].flags = IP_CT_HELPER_F_REUSE_EXPECT;
sip[i].me = ip_conntrack_sip;
sip[i].help = sip_help;
tmpname = &sip_names[i][0];
if (ports[i] == SIP_PORT)
sprintf(tmpname, "sip");
else
sprintf(tmpname, "sip-%d", ports[i]);
sip[i].name = tmpname;
DEBUGP("ip_ct_sip: registering helper for port %d\n", ports[i]);
ret = ip_conntrack_helper_register(&sip[i]);
if (ret) {
DEBUGP("ip_ct_sip: error registering "
"helper for port %d\n", ports[i]);
fini();
return ret;
}
}
return 0;
}PROVIDES_CONNTRACK(sip);module_init(init);module_exit(fini);
Christian,
Sorry about taking so long to get back to you - I have been using your SIP conntrack helper for a little while now, and it seems to work very well for me, also with kernel 2.6.10.
Many thanks for providing it.
One small problem I do have is the netfilter API change in kernel 2.6.11 - Is this change documented anywhere? Is there a porting/updating guide anywhere?
Thanks,
Steve
Quoted 30 lines · Christian Hentschel
Hi, i'm very interesting in a conntrack/nat helper for sip. Currently i'm working on this and help with testing will be great. i've used kernel 2.6.10 for this.
Christian.
Quoted 12 lines · Max Kellermann
Quoted 3 lines · Steve Davies
Are there plans to integrate this officially? Should I take time to (try to) update the patch to the 2.6.x kernel? Am I missing something?
I believe nobody is working on that yet; I planned to look at the code when I'm done with the H.323 module, but that will take some time.
A lot people would be thankful if you hacked the source, and ported that to Linux 2.6.11-rc3 (the API has changed very much since 2.6.10; don't use the old API).
Quoted 7 lines
You should start with providing a patch-o-matic module (see netfilter home page) of the original code, and then send patches with your changes.
Max
--
Quoted 11 lines · Steve Davies
Christian,
Sorry about taking so long to get back to you - I have been using your SIP conntrack helper for a little while now, and it seems to work very well for me, also with kernel 2.6.10.
Many thanks for providing it.
One small problem I do have is the netfilter API change in kernel 2.6.11 - Is this change documented anywhere? Is there a porting/updating guide anywhere?
unfortunately not. I suggest looking at a diff between 2.6.10 and 2.6.11 version of a helper (e.g. within patch-o-matic).
Signature · 5 lines
- Harald Welte <[email protected]> http://netfilter.org/ ============================================================================ "Fragmentation is like classful addressing -- an interesting early architectural error that shows how much experimentation was going on while IP was being designed." -- Paul Vixie
Ok, here goes 2.6.11 patch.
I'm still working on nat SIP/SDP content mangling. But u should try this patch meanwhile. It'd be great some help with it.
Let me know later.
Herald? Would it be possible to add it to pom if this works realiable?
Quoted 16 lines · Harald Welte
Quoted 11 lines · Steve Davies
Christian,
Sorry about taking so long to get back to you - I have been using your SIP conntrack helper for a little while now, and it seems to work very well for me, also with kernel 2.6.10.
Many thanks for providing it.
One small problem I do have is the netfilter API change in kernel 2.6.11 - Is this change documented anywhere? Is there a porting/updating guide anywhere?
unfortunately not. I suggest looking at a diff between 2.6.10 and 2.6.11 version of a helper (e.g. within patch-o-matic).
include/linux/netfilter_ipv4/ip_conntrack_sip.h +24 -0
@@ -0,0 +1,24 @@ +#ifndef __IP_CONNTRACK_SIP_H__ +#define __IP_CONNTRACK_SIP_H__ +/* SIP tracking. */ + +#ifdef __KERNEL__ + +#define SIP_PORT 5060 + +#endif /* __KERNEL__ */ + +/* This structure exists only once per master */ +struct ip_ct_sip_master { +int dummy; +}; + +struct ip_conntrack_expect ; + +/* For NAT to hook in when we find a packet which describes what other +* connection we should expect. */ +extern unsigned int (*ip_nat_sip_hook)(struct sk_buff **pskb, +enum ip_conntrack_info ctinfo, +struct ip_conntrack_expect *exp); + +#endif /* __IP_CONNTRACK_SIP_H__ */
net/ipv4/netfilter/Makefile.ladd +6 -0
@@ -0,0 +1,6 @@ +obj-$(CONFIG_IP_NF_CONNTRACK) += ip_conntrack.o + +# SIP support +obj-$(CONFIG_IP_NF_SIP) += ip_conntrack_sip.o +obj-$(CONFIG_IP_NF_NAT_SIP) += ip_nat_sip.o +
net/ipv4/netfilter/ip_conntrack_sip.c +269 -0
269 lines not on this page · raw message
net/ipv4/netfilter/ip_nat_sip.c +97 -0
97 lines not on this page · raw message
info +5 -0
@@ -0,0 +1,5 @@ +Title: h323 connection tracking and NAT helper +Author: Jozsef Kadlecsik <[email protected]>, Max Kellermann <[email protected]> +Status: Alpha +Repository: extra +Requires: linux-2.6 >= 2.6.11
Ups, sorry here goes again with "info" file fixed.
Quoted 16 lines · Harald Welte
Quoted 11 lines · Steve Davies
Christian,
Sorry about taking so long to get back to you - I have been using your SIP conntrack helper for a little while now, and it seems to work very well for me, also with kernel 2.6.10.
Many thanks for providing it.
One small problem I do have is the netfilter API change in kernel 2.6.11 - Is this change documented anywhere? Is there a porting/updating guide anywhere?
unfortunately not. I suggest looking at a diff between 2.6.10 and 2.6.11 version of a helper (e.g. within patch-o-matic).
include/linux/netfilter_ipv4/ip_conntrack_sip.h +24 -0
@@ -0,0 +1,24 @@ +#ifndef __IP_CONNTRACK_SIP_H__ +#define __IP_CONNTRACK_SIP_H__ +/* SIP tracking. */ + +#ifdef __KERNEL__ + +#define SIP_PORT 5060 + +#endif /* __KERNEL__ */ + +/* This structure exists only once per master */ +struct ip_ct_sip_master { +int dummy; +}; + +struct ip_conntrack_expect ; + +/* For NAT to hook in when we find a packet which describes what other +* connection we should expect. */ +extern unsigned int (*ip_nat_sip_hook)(struct sk_buff **pskb, +enum ip_conntrack_info ctinfo, +struct ip_conntrack_expect *exp); + +#endif /* __IP_CONNTRACK_SIP_H__ */
net/ipv4/netfilter/Makefile.ladd +6 -0
@@ -0,0 +1,6 @@ +obj-$(CONFIG_IP_NF_CONNTRACK) += ip_conntrack.o + +# SIP support +obj-$(CONFIG_IP_NF_SIP) += ip_conntrack_sip.o +obj-$(CONFIG_IP_NF_NAT_SIP) += ip_nat_sip.o +
net/ipv4/netfilter/ip_conntrack_sip.c +269 -0
269 lines not on this page · raw message
net/ipv4/netfilter/ip_nat_sip.c +97 -0
97 lines not on this page · raw message
info +5 -0
@@ -0,0 +1,5 @@ +Title: SIP connection tracking and NAT helper +Author: Christian Hentschel <[email protected]> +Status: Alpha +Repository: extra +Requires: linux-2.6 >= 2.6.11