netfilter 00/08: SIP conntrack TCP/T.38 FAX support
Subsystems (2)
Following is the final version of my SIP conntrack TCP/T.38 FAX patches.
I've done some more testing and everything appears to work fine, so I'll commit them to the nf-next tree sometime today. If anyone has comments or wants to add a Tested-by: tag, please do so within the next hours.
The only change since the last posting is removal of some debugging code.
include/linux/netfilter/nf_conntrack_sip.h | 19 ++- include/net/netfilter/nf_conntrack.h | 2 +- include/net/netfilter/nf_conntrack_expect.h | 1 + include/net/netfilter/nf_nat_helper.h | 32 ++- net/ipv4/netfilter/nf_nat_helper.c | 39 ++-- net/ipv4/netfilter/nf_nat_sip.c | 158 ++++++++----- net/netfilter/nf_conntrack_expect.c | 9 + net/netfilter/nf_conntrack_netlink.c | 4 + net/netfilter/nf_conntrack_sip.c | 327 +++++++++++++++++++++------ 9 files changed, 433 insertions(+), 158 deletions(-)
Patrick McHardy (8):
netfilter: ctnetlink: dump expectation helper name
netfilter: nf_conntrack: show helper and class in /proc/net/nf_conntrack_expect
netfilter: nf_conntrack_sip: fix ct_sip_parse_request() REGISTER request parsing
netfilter: nf_conntrack_sip: pass data offset to NAT functions
netfilter: nf_conntrack_sip: add TCP support
netfilter: nf_nat: support mangling a single TCP packet multiple times
netfilter: nf_nat_sip: add TCP support
netfilter: nf_conntrack_sip: add T.38 FAX support
netfilter 01/08: ctnetlink: dump expectation helper name
commit 3844404984222e1b9e6c32b90592fa7ecb51ee28
Author: Patrick McHardy <[email protected]> Date: Thu Feb 11 07:40:29 2010 +0100
netfilter: ctnetlink: dump expectation helper name
net/netfilter/nf_conntrack_netlink.c +4 -0
@@ -1512,6 +1512,7 @@ ctnetlink_exp_dump_expect(struct sk_buff *skb, const struct nf_conntrack_expect *exp) {struct nf_conn *master = exp->master; +struct nf_conntrack_helper *helper;long timeout = (exp->timeout.expires - jiffies) /HZ ;if (timeout <0 )
@@ -1528,6 +1529,9 @@ ctnetlink_exp_dump_expect(struct sk_buff *skb,NLA_PUT_BE32 (skb,CTA_EXPECT_TIMEOUT ,htonl (timeout));NLA_PUT_BE32 (skb,CTA_EXPECT_ID ,htonl ((unsigned long )exp)); + helper =rcu_dereference (nfct_help (master)->helper); +if (helper) +NLA_PUT_STRING (skb,CTA_EXPECT_HELP_NAME , helper->name);return 0 ;
netfilter 02/08: nf_conntrack: show helper and class in /proc/net/nf_conntrack_expect
In reply to Patrick McHardycommit 4e4aa88c264e9f8d013e3742e48a6bea37ca1c4c
Author: Patrick McHardy <[email protected]> Date: Thu Feb 11 07:40:30 2010 +0100
netfilter: nf_conntrack: show helper and class in /proc/net/nf_conntrack_expect
Make the output a bit more informative by showing the helper an expectation belongs to and the expectation class.
include/net/netfilter/nf_conntrack_expect.h +1 -0
@@ -66,6 +66,7 @@ static inline struct net *nf_ct_exp_net(struct nf_conntrack_expect *exp)struct nf_conntrack_expect_policy {unsigned int max_expected;unsigned int timeout; +const char *name; };#define NF_CT_EXPECT_CLASS_DEFAULT 0
net/netfilter/nf_conntrack_expect.c +9 -0
@@ -500,6 +500,7 @@ static void exp_seq_stop(struct seq_file *seq, void *v)static int exp_seq_show (struct seq_file *s,void *v) {struct nf_conntrack_expect *expect; +struct nf_conntrack_helper *helper;struct hlist_node *n = v;char *delim ="" ;
@@ -525,6 +526,14 @@ static int exp_seq_show(struct seq_file *s, void *v)if (expect->flags &NF_CT_EXPECT_INACTIVE )seq_printf (s,"%sINACTIVE" , delim); + helper =rcu_dereference (nfct_help (expect->master)->helper); +if (helper) { +seq_printf (s,"%s%s" , expect->flags ?" " :"" , helper->name); +if (helper->expect_policy[expect->class].name) +seq_printf (s,"/%s" , + helper->expect_policy[expect->class].name); + } +return seq_putc (s,'\n' ); }
net/netfilter/nf_conntrack_sip.c +3 -0
@@ -1305,14 +1305,17 @@ static char sip_names[MAX_PORTS][2][sizeof("sip-65535")] __read_mostly;static const struct nf_conntrack_expect_policy sip_exp_policy[SIP_EXPECT_MAX +1 ] = { [SIP_EXPECT_SIGNALLING ] = { + .name ="signalling" , .max_expected =1 , .timeout =3 *60 , }, [SIP_EXPECT_AUDIO ] = { + .name ="audio" , .max_expected =2 *IP_CT_DIR_MAX , .timeout =3 *60 , }, [SIP_EXPECT_VIDEO ] = { + .name ="video" , .max_expected =2 *IP_CT_DIR_MAX , .timeout =3 *60 , },
Re: netfilter 02/08: nf_conntrack: show helper and class in /proc/net/nf_conntrack_expect
Quoted 5 lines · Patrick McHardy
commit
4e4aa88c264e9f8d013e3742e48a6bea37ca1c4cAuthor: Patrick McHardy <[email protected]> Date: Thu Feb 11 07:40:30 2010 +0100netfilter:
nf_conntrack: show helper and class in/proc/net/nf_conntrack_expect
Were not there any plans on obsoleting these procfs files?
Re: netfilter 02/08: nf_conntrack: show helper and class in /proc/net/nf_conntrack_expect
Quoted 10 lines · Jan Engelhardt
Quoted 5 lines · Patrick McHardy
commit
4e4aa88c264e9f8d013e3742e48a6bea37ca1c4cAuthor: Patrick McHardy <[email protected]> Date: Thu Feb 11 07:40:30 2010 +0100netfilter:
nf_conntrack: show helper and class in/proc/net/nf_conntrack_expectWere not there any plans on obsoleting these procfs files?
Not from me, I often find them useful.
netfilter 03/08: nf_conntrack_sip: fix ct_sip_parse_request() REGISTER request parsing
In reply to Patrick McHardycommit b595ec74123dc71c56401feec6c35c822a8fc310
Author: Patrick McHardy <[email protected]> Date: Thu Feb 11 07:40:30 2010 +0100
netfilter: nf_conntrack_sip: fix ct_sip_parse_request() REGISTER request parsing
When requests are parsed, the "sip:" part of the SIP URI should be skipped.
Usually this doesn't matter because address parsing skips forward until after the username part, but in case REGISTER requests it doesn't contain a username and the address can not be parsed.
net/netfilter/nf_conntrack_sip.c +4 -3
@@ -236,12 +236,13 @@ int ct_sip_parse_request(const struct nf_conn *ct,return 0 ;/* Find SIP URI */ - limit -=strlen ("sip:" ); -for (; dptr < limit; dptr++) { +for (; dptr < limit -strlen ("sip:" ); dptr++) {if (*dptr =='\r' || *dptr =='\n' )return -1 ; -if (strnicmp (dptr,"sip:" ,strlen ("sip:" )) ==0 ) +if (strnicmp (dptr,"sip:" ,strlen ("sip:" )) ==0 ) { + dptr +=strlen ("sip:" );break ; + } }if (!skp_epaddr_len (ct, dptr, limit, &shift))return 0 ;
netfilter 04/08: nf_conntrack_sip: pass data offset to NAT functions
In reply to Patrick McHardycommit 49b09299e02a5b322918f676c97b294f9a8eac4a
Author: Patrick McHardy <[email protected]> Date: Thu Feb 11 07:40:32 2010 +0100
netfilter: nf_conntrack_sip: pass data offset to NAT functions
When using TCP multiple SIP messages might be present in a single packet. A following patch will parse them by setting the dptr to the beginning of each message. The NAT helper needs to reload the dptr value after mangling the packet however, so it needs to know the offset of the message to the beginning of the packet.
include/linux/netfilter/nf_conntrack_sip.h +10 -4
@@ -34,10 +34,10 @@ struct sdp_media_type {struct sip_handler {const char *method;unsigned int len; -int (*request)(struct sk_buff *skb, +int (*request)(struct sk_buff *skb,unsigned int dataoff,const char **dptr,unsigned int *datalen,unsigned int cseq); -int (*response)(struct sk_buff *skb, +int (*response)(struct sk_buff *skb,unsigned int dataoff,const char **dptr,unsigned int *datalen,unsigned int cseq,unsigned int code); };
@@ -100,33 +100,39 @@ enum sdp_header_types { };extern unsigned int (*nf_nat_sip_hook)(struct sk_buff *skb, +unsigned int dataoff,const char **dptr,unsigned int *datalen);extern unsigned int (*nf_nat_sip_expect_hook)(struct sk_buff *skb, +unsigned int dataoff,const char **dptr,unsigned int *datalen,struct nf_conntrack_expect *exp,unsigned int matchoff,unsigned int matchlen);extern unsigned int (*nf_nat_sdp_addr_hook)(struct sk_buff *skb, -const char **dptr,unsigned int dataoff, +const char **dptr,unsigned int *datalen, +unsigned int sdpoff,enum sdp_header_types type,enum sdp_header_types term,const union nf_inet_addr *addr);extern unsigned int (*nf_nat_sdp_port_hook)(struct sk_buff *skb, +unsigned int dataoff,const char **dptr,unsigned int *datalen,unsigned int matchoff,unsigned int matchlen,u_int16_t port);extern unsigned int (*nf_nat_sdp_session_hook)(struct sk_buff *skb, -const char **dptr,unsigned int dataoff, +const char **dptr,unsigned int *datalen, +unsigned int sdpoff,const union nf_inet_addr *addr); extern unsigned int (*nf_nat_sdp_media_hook)(struct sk_buff *skb, + unsigned int dataoff, const char **dptr, unsigned int *datalen, struct nf_conntrack_expect *rtp_exp,
net/ipv4/netfilter/nf_nat_sip.c +51 -50
269 lines not on this page · raw message
net/netfilter/nf_conntrack_sip.c +44 -38
273 lines not on this page · raw message
netfilter 05/08: nf_conntrack_sip: add TCP support
In reply to Patrick McHardycommit 52923fa05b52853ee58d1f4dac8d7110bef8f30a
Author: Patrick McHardy <[email protected]> Date: Thu Feb 11 07:40:33 2010 +0100
netfilter: nf_conntrack_sip: add TCP support
Add TCP support, which is mandated by RFC3261 for all SIP elements.
SIP over TCP is similar to UDP, except that messages are delimited by Content-Length: headers and multiple messages may appear in one packet.
include/linux/netfilter/nf_conntrack_sip.h +2 -1
@@ -84,7 +84,8 @@ enum sip_header_types {SIP_HDR_FROM ,SIP_HDR_TO ,SIP_HDR_CONTACT , -SIP_HDR_VIA , +SIP_HDR_VIA_UDP , +SIP_HDR_VIA_TCP ,SIP_HDR_EXPIRES , SIP_HDR_CONTENT_LENGTH, };
net/ipv4/netfilter/nf_nat_sip.c +1 -1
@@ -122,7 +122,7 @@ static unsigned int ip_nat_sip(struct sk_buff *skb, unsigned int dataoff,/* Translate topmost Via header and parameters */ if (ct_sip_parse_header_uri (ct, *dptr,NULL , *datalen, -SIP_HDR_VIA ,NULL , &matchoff, &matchlen, +SIP_HDR_VIA_UDP ,NULL , &matchoff, &matchlen, &addr, &port) >0 ) {unsigned int matchend, poff, plen, buflen, n;char buffer[sizeof ("nnn.nnn.nnn.nnn:nnnnn" )];
net/netfilter/nf_conntrack_sip.c +176 -29
323 lines not on this page · raw message
Re: netfilter 05/08: nf_conntrack_sip: add TCP support
Quoted 7 lines · Patrick McHardy
netfilter:
nf_conntrack_sip: add TCP supportAdd TCP support, which is mandated by RFC3261 for all SIP elements.
SIP over TCP is similar to UDP, except that messages are delimited by Content-Length: headers and multiple messages may appear in one packet.
Does it cope with TCP segmentation?
Re: netfilter 05/08: nf_conntrack_sip: add TCP support
Quoted 11 lines · Jan Engelhardt
Quoted 7 lines · Patrick McHardy
netfilter:
nf_conntrack_sip: add TCP supportAdd TCP support, which is mandated by RFC3261 for all SIP elements.
SIP over TCP is similar to UDP, except that messages are delimited by Content-Length: headers and multiple messages may appear in one packet.
Does it cope with TCP segmentation?
No, messages split over multiple packets can't be handled, similar to other helpers.
netfilter 06/08: nf_nat: support mangling a single TCP packet multiple times
In reply to Patrick McHardycommit dd724e4ee502dc31747453025a8a113d3e2f1a62
Author: Patrick McHardy <[email protected]> Date: Thu Feb 11 07:40:33 2010 +0100
netfilter: nf_nat: support mangling a single TCP packet multiple times
nf_nat_mangle_tcp_packet() can currently only handle a single mangling per window because it only maintains two sequence adjustment positions:
the one before the last adjustment and the one after.
This patch makes sequence number adjustment tracking in nf_nat_mangle_tcp_packet() optional and allows a helper to manually update the offsets after the packet has been fully handled.
include/net/netfilter/nf_nat_helper.h +25 -7
@@ -7,13 +7,27 @@struct sk_buff ;/* These return true or false. */ -extern int nf_nat_mangle_tcp_packet (struct sk_buff *skb, -struct nf_conn *ct, -enum ip_conntrack_info ctinfo, -unsigned int match_offset, -unsigned int match_len, -const char *rep_buffer, -unsigned int rep_len); +extern int __nf_nat_mangle_tcp_packet (struct sk_buff *skb, +struct nf_conn *ct, +enum ip_conntrack_info ctinfo, +unsigned int match_offset, +unsigned int match_len, +const char *rep_buffer, +unsigned int rep_len,bool adjust); + +static inline int nf_nat_mangle_tcp_packet (struct sk_buff *skb, +struct nf_conn *ct, +enum ip_conntrack_info ctinfo, +unsigned int match_offset, +unsigned int match_len, +const char *rep_buffer, +unsigned int rep_len) +{ +return __nf_nat_mangle_tcp_packet (skb, ct, ctinfo, + match_offset, match_len, + rep_buffer, rep_len, true); +} + extern int nf_nat_mangle_udp_packet(struct sk_buff *skb, struct nf_conn *ct, enum ip_conntrack_info ctinfo,
@@ -21,6 +35,10 @@ extern int nf_nat_mangle_udp_packet(struct sk_buff *skb,unsigned int match_len, const char *rep_buffer, unsigned int rep_len); + +extern void nf_nat_set_seq_adjust (struct nf_conn *ct, +enum ip_conntrack_info ctinfo, +__be32 seq,s16 off);extern int nf_nat_seq_adjust (struct sk_buff *skb,struct nf_conn *ct,enum ip_conntrack_info ctinfo);
net/ipv4/netfilter/nf_nat_helper.c +23 -16
@@ -141,6 +141,17 @@ static int enlarge_skb(struct sk_buff *skb, unsigned int extra)return 1 ; } +void nf_nat_set_seq_adjust (struct nf_conn *ct,enum ip_conntrack_info ctinfo, +__be32 seq,s16 off) +{ +if (!off) +return ; +set_bit (IPS_SEQ_ADJUST_BIT , &ct->status); +adjust_tcp_sequence (ntohl (seq), off, ct, ctinfo); +nf_conntrack_event_cache (IPCT_NATSEQADJ , ct); +} +EXPORT_SYMBOL_GPL (nf_nat_set_seq_adjust); +/* Generic function for mangling variable-length address changes inside * NATed TCP connections (like the PORT XXX,XXX,XXX,XXX,XXX,XXX * command in FTP).
@@ -149,14 +160,13 @@ static int enlarge_skb(struct sk_buff *skb, unsigned int extra)* skb enlargement, ... * * */ -int -nf_nat_mangle_tcp_packet (struct sk_buff *skb, -struct nf_conn *ct, -enum ip_conntrack_info ctinfo, -unsigned int match_offset, -unsigned int match_len, -const char *rep_buffer, -unsigned int rep_len) +int __nf_nat_mangle_tcp_packet (struct sk_buff *skb, +struct nf_conn *ct, +enum ip_conntrack_info ctinfo, +unsigned int match_offset, +unsigned int match_len, +const char *rep_buffer, +unsigned int rep_len,bool adjust) {struct rtable *rt =skb_rtable (skb);struct iphdr *iph;
@@ -202,16 +212,13 @@ nf_nat_mangle_tcp_packet(struct sk_buff *skb,inet_proto_csum_replace2 (&tcph->check, skb,htons (oldlen),htons (datalen),1 ); -if (rep_len != match_len) { -set_bit (IPS_SEQ_ADJUST_BIT , &ct->status); -adjust_tcp_sequence (ntohl (tcph->seq), - (int )rep_len - (int )match_len, - ct, ctinfo); -nf_conntrack_event_cache (IPCT_NATSEQADJ , ct); - } +if (adjust && rep_len != match_len) +nf_nat_set_seq_adjust (ct, ctinfo, tcph->seq, + (int )rep_len - (int )match_len); +return 1 ; } -EXPORT_SYMBOL (nf_nat_mangle_tcp_packet); +EXPORT_SYMBOL (__nf_nat_mangle_tcp_packet);/* Generic function for mangling variable-length address changes inside * NATed UDP connections (like the CONNECT DATA XXXXX MESG XXXXX INDEX XXXXX
netfilter 07/08: nf_nat_sip: add TCP support
In reply to Patrick McHardycommit ed23b7593761f4d57be5906ada862d1b74137af8
Author: Patrick McHardy <[email protected]> Date: Thu Feb 11 07:40:34 2010 +0100
netfilter: nf_nat_sip: add TCP support
include/linux/netfilter/nf_conntrack_sip.h +1 -0
@@ -104,6 +104,7 @@ extern unsigned int (*nf_nat_sip_hook)(struct sk_buff *skb,unsigned int dataoff, const char **dptr, unsigned int *datalen); +extern void (*nf_nat_sip_seq_adjust_hook)(struct sk_buff *skb,s16 off); extern unsigned int (*nf_nat_sip_expect_hook)(struct sk_buff *skb, unsigned int dataoff, const char **dptr,
net/ipv4/netfilter/nf_nat_sip.c +49 -8
119 lines not on this page · raw message
net/netfilter/nf_conntrack_sip.c +10 -0
@@ -56,6 +56,9 @@ unsigned int (*nf_nat_sip_hook)(struct sk_buff *skb, unsigned int dataoff, unsigned int *datalen) __read_mostly;EXPORT_SYMBOL_GPL (nf_nat_sip_hook); +void (*nf_nat_sip_seq_adjust_hook)(struct sk_buff *skb,s16 off)__read_mostly ; +EXPORT_SYMBOL_GPL (nf_nat_sip_seq_adjust_hook); + unsigned int (*nf_nat_sip_expect_hook)(struct sk_buff *skb, unsigned int dataoff, const char **dptr,
@@ -1360,6 +1363,7 @@ static int sip_help_tcp(struct sk_buff *skb, unsigned int protoff,const char *dptr, *end;s16 diff, tdiff =0 ;int ret; +typeof (nf_nat_sip_seq_adjust_hook) nf_nat_sip_seq_adjust;if (ctinfo !=IP_CT_ESTABLISHED && ctinfo !=IP_CT_ESTABLISHED +IP_CT_IS_REPLY )
@@ -1415,6 +1419,12 @@ static int sip_help_tcp(struct sk_buff *skb, unsigned int protoff, datalen = datalen + diff - msglen; } +if (ret ==NF_ACCEPT && ct->status &IPS_NAT_MASK ) { + nf_nat_sip_seq_adjust =rcu_dereference (nf_nat_sip_seq_adjust_hook); +if (nf_nat_sip_seq_adjust) +nf_nat_sip_seq_adjust (skb, tdiff); + } +return ret; }
netfilter 08/08: nf_conntrack_sip: add T.38 FAX support
In reply to Patrick McHardycommit 9811ea1e1a05af3cde40d4dca040c03a0c10540e
Author: Patrick McHardy <[email protected]> Date: Thu Feb 11 07:40:34 2010 +0100
netfilter: nf_conntrack_sip: add T.38 FAX support
include/linux/netfilter/nf_conntrack_sip.h +1 -0
@@ -14,6 +14,7 @@ enum sip_expectation_classes {SIP_EXPECT_SIGNALLING ,SIP_EXPECT_AUDIO ,SIP_EXPECT_VIDEO , +SIP_EXPECT_IMAGE , __SIP_EXPECT_MAX };#define SIP_EXPECT_MAX (__SIP_EXPECT_MAX - 1)
include/net/netfilter/nf_conntrack.h +1 -1
@@ -70,7 +70,7 @@ union nf_conntrack_help {struct nf_conntrack_helper ;/* Must be kept in sync with the classes defined by helpers */ -#define NF_CT_MAX_EXPECT_CLASSES 3 +#define NF_CT_MAX_EXPECT_CLASSES 4/* nf_conn feature for connections that have a helper */ struct nf_conn_help {
net/netfilter/nf_conntrack_sip.c +23 -5
@@ -907,6 +907,7 @@ err1:static const struct sdp_media_type sdp_media_types[] = {SDP_MEDIA_TYPE ("audio " ,SIP_EXPECT_AUDIO ),SDP_MEDIA_TYPE ("video " ,SIP_EXPECT_VIDEO ), +SDP_MEDIA_TYPE ("image " ,SIP_EXPECT_IMAGE ), }; static const struct sdp_media_type *sdp_media_type(const char *dptr,
@@ -932,7 +933,6 @@ static int process_sdp(struct sk_buff *skb, unsigned int dataoff, {enum ip_conntrack_info ctinfo;struct nf_conn *ct =nf_ct_get (skb, &ctinfo); -struct nf_conn_help *help =nfct_help (ct);unsigned int matchoff, matchlen;unsigned int mediaoff, medialen;unsigned int sdpoff;
@@ -1024,9 +1024,6 @@ static int process_sdp(struct sk_buff *skb, unsigned int dataoff, ret =nf_nat_sdp_session (skb, dataoff, dptr, datalen, sdpoff, &rtp_addr); -if (ret ==NF_ACCEPT && i >0 ) - help->help.ct_sip_info.invite_cseq = cseq; -return ret; } static int process_invite_response(struct sk_buff *skb, unsigned int dataoff,
@@ -1077,6 +1074,22 @@ static int process_prack_response(struct sk_buff *skb, unsigned int dataoff,return NF_ACCEPT ; } +static int process_invite_request (struct sk_buff *skb,unsigned int dataoff, +const char **dptr,unsigned int *datalen, +unsigned int cseq) +{ +enum ip_conntrack_info ctinfo; +struct nf_conn *ct =nf_ct_get (skb, &ctinfo); +struct nf_conn_help *help =nfct_help (ct); +unsigned int ret; + +flush_expectations (ct, true); + ret =process_sdp (skb, dataoff, dptr, datalen, cseq); +if (ret ==NF_ACCEPT ) + help->help.ct_sip_info.invite_cseq = cseq; +return ret; +} +static int process_bye_request (struct sk_buff *skb,unsigned int dataoff,const char **dptr,unsigned int *datalen,unsigned int cseq)
@@ -1257,7 +1270,7 @@ flush: }static const struct sip_handler sip_handlers[] = { -SIP_HANDLER ("INVITE" , process_sdp, process_invite_response), +SIP_HANDLER ("INVITE" , process_invite_request, process_invite_response),SIP_HANDLER ("UPDATE" , process_sdp, process_update_response),SIP_HANDLER ("ACK" , process_sdp,NULL ),SIP_HANDLER ("PRACK" , process_sdp, process_prack_response),
@@ -1473,6 +1486,11 @@ static const struct nf_conntrack_expect_policy sip_exp_policy[SIP_EXPECT_MAX + 1 .max_expected = 2 * IP_CT_DIR_MAX, .timeout = 3 * 60, }, + [SIP_EXPECT_IMAGE] = { + .name = "image", + .max_expected = IP_CT_DIR_MAX, + .timeout = 3 * 60, + }, };static void nf_conntrack_sip_fini (void )