netfilter patches for nf-next-2.6
Subsystems (3)
[email protected]
maintainercover netfilter patches for nf-next-2.6
From: Pablo Neira Ayuso <[email protected]>
Hi Patrick,
These are the patches that I collected for nf-next-2.6. Please, take recent Jozsef's patches directly from him.
Eric Dumazet (1):
netfilter: nf_conntrack: remove one synchronize_net()
Jan Engelhardt (1):
netfilter: nf_conntrack: provide config option to disable ancient
procfs parts
Jesper Juhl (1):
ipvs: Avoid undefined order of evaluation in assignments to struct
nf_conn *
Kevin Cernekee (1):
netfilter: nf_conntrack_sip: Handle Cisco 7941/7945 IP phones
include/linux/netfilter/nf_conntrack_sip.h | 3 ++ net/ipv4/netfilter/Kconfig | 2 +- net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c | 1 - net/ipv4/netfilter/nf_nat_sip.c | 26 +++++++++++++++++++++-- net/netfilter/Kconfig | 10 +++++++++ net/netfilter/ipvs/ip_vs_nfct.c | 2 +- net/netfilter/ipvs/ip_vs_xmit.c | 8 +++--- net/netfilter/nf_conntrack_expect.c | 12 +++++----- net/netfilter/nf_conntrack_sip.c | 17 +++++++++++++++ net/netfilter/nf_conntrack_standalone.c | 4 +- 10 files changed, 67 insertions(+), 18 deletions(-)
Signature · 1 line
1.7.2.5
[email protected]
maintainerPATCH 1/4 netfilter: nf_conntrack_sip: Handle Cisco 7941/7945 IP phones
From: Kevin Cernekee <[email protected]>
Most SIP devices use a source port of 5060/udp on SIP requests, so the response automatically comes back to port 5060:
phone_ip:5060 -> proxy_ip:5060 REGISTER
proxy_ip:5060 -> phone_ip:5060 100 Trying
The newer Cisco IP phones, however, use a randomly chosen high source port for the SIP request but expect the response on port 5060:
phone_ip:49173 -> proxy_ip:5060 REGISTER
proxy_ip:5060 -> phone_ip:5060 100 Trying
Standard Linux NAT, with or without nf_nat_sip, will send the reply back to port 49173, not 5060:
phone_ip:49173 -> proxy_ip:5060 REGISTER
proxy_ip:5060 -> phone_ip:49173 100 Trying
But the phone is not listening on 49173, so it will never see the reply.
This patch modifies nf_*_sip to work around this quirk by extracting the SIP response port from the Via: header, iff the source IP in the packet header matches the source IP in the SIP request.
--- include/linux/netfilter/nf_conntrack_sip.h | 3 +++ net/ipv4/netfilter/nf_nat_sip.c | 26 +++++++++++++++++++++++--- net/netfilter/nf_conntrack_sip.c | 17 +++++++++++++++++ 3 files changed, 43 insertions(+), 3 deletions(-)
include/linux/netfilter/nf_conntrack_sip.h +3 -0
@@ -2,12 +2,15 @@#define __NF_CONNTRACK_SIP_H__#ifdef __KERNEL__ +#include <linux/types.h> +#define SIP_PORT 5060#define SIP_TIMEOUT 3600struct nf_ct_sip_master {unsigned int register_cseq;unsigned int invite_cseq; +__be16 forced_dport; }; enum sip_expectation_classes {
net/ipv4/netfilter/nf_nat_sip.c +23 -3
@@ -73,6 +73,7 @@ static int map_addr(struct sk_buff *skb, unsigned int dataoff,enum ip_conntrack_info ctinfo;struct nf_conn *ct =nf_ct_get (skb, &ctinfo);enum ip_conntrack_dir dir =CTINFO2DIR (ctinfo); +struct nf_conn_help *help =nfct_help (ct);char buffer[sizeof ("nnn.nnn.nnn.nnn:nnnnn" )];unsigned int buflen;__be32 newaddr;
@@ -85,7 +86,8 @@ static int map_addr(struct sk_buff *skb, unsigned int dataoff, }else if (ct->tuplehash[dir].tuple.dst.u3.ip == addr->ip && ct->tuplehash[dir].tuple.dst.u.udp.port == port) { newaddr = ct->tuplehash[!dir].tuple.src.u3.ip; - newport = ct->tuplehash[!dir].tuple.src.u.udp.port; + newport = help->help.ct_sip_info.forced_dport ? : + ct->tuplehash[!dir].tuple.src.u.udp.port; }else return 1 ;
@@ -121,6 +123,7 @@ static unsigned int ip_nat_sip(struct sk_buff *skb, unsigned int dataoff,enum ip_conntrack_info ctinfo;struct nf_conn *ct =nf_ct_get (skb, &ctinfo);enum ip_conntrack_dir dir =CTINFO2DIR (ctinfo); +struct nf_conn_help *help =nfct_help (ct);unsigned int coff, matchoff, matchlen;enum sip_header_types hdr;union nf_inet_addr addr;
@@ -229,6 +232,20 @@ next: !map_sip_addr(skb, dataoff, dptr, datalen, SIP_HDR_TO))return NF_DROP ; +/* Mangle destination port for Cisco phones, then fix up checksums */ +if (dir ==IP_CT_DIR_REPLY && help->help.ct_sip_info.forced_dport) { +struct udphdr *uh; + +if (!skb_make_writable (skb, skb->len)) +return NF_DROP ; + + uh = (struct udphdr *)(skb->data +ip_hdrlen (skb)); + uh->dest = help->help.ct_sip_info.forced_dport; + +if (!nf_nat_mangle_udp_packet (skb, ct, ctinfo,0 ,0 ,NULL ,0 )) +return NF_DROP ; + } +return NF_ACCEPT ; }
@@ -280,8 +297,10 @@ static unsigned int ip_nat_sip_expect(struct sk_buff *skb, unsigned int dataoff,enum ip_conntrack_info ctinfo;struct nf_conn *ct =nf_ct_get (skb, &ctinfo);enum ip_conntrack_dir dir =CTINFO2DIR (ctinfo); +struct nf_conn_help *help =nfct_help (ct);__be32 newip;u_int16_t port; +__be16 srcport;char buffer[sizeof ("nnn.nnn.nnn.nnn:nnnnn" )];unsigned buflen;
@@ -294,8 +313,9 @@ static unsigned int ip_nat_sip_expect(struct sk_buff *skb, unsigned int dataoff,/* If the signalling port matches the connection's source port in the * original direction, try to use the destination port in the opposite * direction. */ -if (exp->tuple.dst.u.udp.port == - ct->tuplehash[dir].tuple.src.u.udp.port) + srcport = help->help.ct_sip_info.forced_dport ? : + ct->tuplehash[dir].tuple.src.u.udp.port; +if (exp->tuple.dst.u.udp.port == srcport) port =ntohs (ct->tuplehash[!dir].tuple.dst.u.udp.port);else port =ntohs (exp->tuple.dst.u.udp.port);
net/netfilter/nf_conntrack_sip.c +17 -0
@@ -1363,8 +1363,25 @@ static int process_sip_request(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); +enum ip_conntrack_dir dir =CTINFO2DIR (ctinfo);unsigned int matchoff, matchlen;unsigned int cseq, i; +union nf_inet_addr addr; +__be16 port; + +/* Many Cisco IP phones use a high source port for SIP requests, but +* listen for the response on port 5060. If we are the local +* router for one of these phones, save the port number from the +* Via: header so that nf_nat_sip can redirect the responses to +* the correct port. +*/ +if (ct_sip_parse_header_uri (ct, *dptr,NULL , *datalen, +SIP_HDR_VIA_UDP ,NULL , &matchoff, + &matchlen, &addr, &port) >0 && + port != ct->tuplehash[dir].tuple.src.u.udp.port && +nf_inet_addr_cmp (&addr, &ct->tuplehash[dir].tuple.src.u3)) + help->help.ct_sip_info.forced_dport = port;for (i =0 ; i <ARRAY_SIZE (sip_handlers); i++) {const struct sip_handler *handler;
Signature · 1 line
1.7.2.5
[email protected]
maintainerPATCH 2/4 ipvs: Avoid undefined order of evaluation in assignments to struct nf_conn *
In reply to [email protected]From: Jesper Juhl <[email protected]>
In net/netfilter/ipvs/ip_vs_nfct.c::ip_vs_update_conntrack(), net/netfilter/ipvs/ip_vs_xmit.c::ip_vs_nat_xmit(), net/netfilter/ipvs/ip_vs_xmit.c::ip_vs_nat_xmit_v6(), net/netfilter/ipvs/ip_vs_xmit.c::ip_vs_icmp_xmit)() net/netfilter/ipvs/ip_vs_xmit.c::and ip_vs_icmp_xmit_v6() we do this:
... struct nf_conn *ct = ct = nf_ct_get(skb, &ctinfo); ...
Since '=' is not a sequence point the order of these assignments happening is undefined. Luckily it's easy to avoid by just doing what is obviously the intended thing:
struct nf_conn *ct = nf_ct_get(skb, &ctinfo);
--- net/netfilter/ipvs/ip_vs_nfct.c | 2 +- net/netfilter/ipvs/ip_vs_xmit.c | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-)
net/netfilter/ipvs/ip_vs_nfct.c +1 -1
@@ -82,7 +82,7 @@ void ip_vs_update_conntrack(struct sk_buff *skb, struct ip_vs_conn *cp, int outin) { enum ip_conntrack_info ctinfo; -struct nf_conn *ct = ct =nf_ct_get (skb, &ctinfo); +struct nf_conn *ct =nf_ct_get (skb, &ctinfo);struct nf_conntrack_tuple new_tuple; if (ct == NULL || nf_ct_is_confirmed(ct) || nf_ct_is_untracked(ct) ||
net/netfilter/ipvs/ip_vs_xmit.c +4 -4
@@ -544,7 +544,7 @@ ip_vs_nat_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,#if defined(CONFIG_NF_CONNTRACK ) || defined(CONFIG_NF_CONNTRACK_MODULE )if (cp->flags &IP_VS_CONN_F_SYNC && local) {enum ip_conntrack_info ctinfo; -struct nf_conn *ct = ct =nf_ct_get (skb, &ctinfo); +struct nf_conn *ct =nf_ct_get (skb, &ctinfo);if (ct && !nf_ct_is_untracked (ct)) { IP_VS_DBG_RL_PKT(10, AF_INET, pp, skb, 0,
@@ -661,7 +661,7 @@ ip_vs_nat_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,#if defined(CONFIG_NF_CONNTRACK ) || defined(CONFIG_NF_CONNTRACK_MODULE )if (cp->flags &IP_VS_CONN_F_SYNC && local) {enum ip_conntrack_info ctinfo; -struct nf_conn *ct = ct =nf_ct_get (skb, &ctinfo); +struct nf_conn *ct =nf_ct_get (skb, &ctinfo);if (ct && !nf_ct_is_untracked (ct)) { IP_VS_DBG_RL_PKT(10, AF_INET6, pp, skb, 0,
@@ -1176,7 +1176,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,#if defined(CONFIG_NF_CONNTRACK ) || defined(CONFIG_NF_CONNTRACK_MODULE )if (cp->flags &IP_VS_CONN_F_SYNC && local) {enum ip_conntrack_info ctinfo; -struct nf_conn *ct = ct =nf_ct_get (skb, &ctinfo); +struct nf_conn *ct =nf_ct_get (skb, &ctinfo);if (ct && !nf_ct_is_untracked (ct)) { IP_VS_DBG(10, "%s(): "
@@ -1296,7 +1296,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,#if defined(CONFIG_NF_CONNTRACK ) || defined(CONFIG_NF_CONNTRACK_MODULE )if (cp->flags &IP_VS_CONN_F_SYNC && local) {enum ip_conntrack_info ctinfo; -struct nf_conn *ct = ct =nf_ct_get (skb, &ctinfo); +struct nf_conn *ct =nf_ct_get (skb, &ctinfo);if (ct && !nf_ct_is_untracked (ct)) { IP_VS_DBG(10, "%s(): "
Signature · 1 line
1.7.2.5
[email protected]
maintainerPATCH 3/4 netfilter: nf_conntrack: remove one synchronize_net()
In reply to [email protected]From: Eric Dumazet <[email protected]>
No point to wait a rcu grace period before the unregisters.
--- net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c | 1 - 1 files changed, 0 insertions(+), 1 deletions(-)
net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c +0 -1
@@ -435,7 +435,6 @@ static int __init nf_conntrack_l3proto_ipv4_init(void) static void __exit nf_conntrack_l3proto_ipv4_fini(void) { -synchronize_net ();#if defined(CONFIG_PROC_FS ) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT )nf_conntrack_ipv4_compat_fini ();#endif
Signature · 1 line
1.7.2.5
[email protected]
maintainerPATCH 4/4 netfilter: nf_conntrack: provide config option to disable ancient procfs parts
In reply to [email protected]From: Jan Engelhardt <[email protected]>
This option enables for the list of known conntrack entries to be shown in procfs under net/netfilter/nf_conntrack. This is considered obsolete in favor of using the conntrack(8) tool which uses Netlink.
--- net/ipv4/netfilter/Kconfig | 2 +- net/netfilter/Kconfig | 10 ++++++++++ net/netfilter/nf_conntrack_expect.c | 12 ++++++------ net/netfilter/nf_conntrack_standalone.c | 4 ++-- 4 files changed, 19 insertions(+), 9 deletions(-)
net/ipv4/netfilter/Kconfig +1 -1
@@ -27,7 +27,7 @@ config NF_CONNTRACK_IPV4 config NF_CONNTRACK_PROC_COMPAT bool "proc/sysctl compatibility with old connection tracking" - depends on NF_CONNTRACK_IPV4 + depends on NF_CONNTRACK_PROCFS && NF_CONNTRACK_IPV4 default y help This option enables /proc and sysctl compatibility with the old
net/netfilter/Kconfig +10 -0
@@ -75,6 +75,16 @@ config NF_CONNTRACK_ZONES If unsure, say `N'. +config NF_CONNTRACK_PROCFS + bool "Supply CT list in procfs (OBSOLETE)" + default y + depends on PROC_FS + ---help--- + This option enables for the list of known conntrack entries + to be shown in procfs under net/netfilter/nf_conntrack. This + is considered obsolete in favor of using the conntrack(8) + tool which uses Netlink. + config NF_CONNTRACK_EVENTS bool "Connection tracking events" depends on NETFILTER_ADVANCED
net/netfilter/nf_conntrack_expect.c +6 -6
@@ -474,7 +474,7 @@ void nf_ct_remove_userspace_expectations(void) }EXPORT_SYMBOL_GPL (nf_ct_remove_userspace_expectations); -#ifdef CONFIG_PROC_FS +#ifdef CONFIG_NF_CONNTRACK_PROCFS struct ct_expect_iter_state { struct seq_net_private p; unsigned int bucket;
@@ -602,25 +602,25 @@ static const struct file_operations exp_file_ops = { .llseek = seq_lseek, .release = seq_release_net, }; -#endif /* CONFIG_PROC_FS */ +#endif /* CONFIG_NF_CONNTRACK_PROCFS */ static int exp_proc_init (struct net *net) { -#ifdef CONFIG_PROC_FS +#ifdef CONFIG_NF_CONNTRACK_PROCFS struct proc_dir_entry *proc; proc =proc_net_fops_create (net,"nf_conntrack_expect" ,0440 , &exp_file_ops);if (!proc)return -ENOMEM ; -#endif /* CONFIG_PROC_FS */ +#endif /* CONFIG_NF_CONNTRACK_PROCFS */ return 0 ; }static void exp_proc_remove (struct net *net) { -#ifdef CONFIG_PROC_FS +#ifdef CONFIG_NF_CONNTRACK_PROCFS proc_net_remove (net,"nf_conntrack_expect" ); -#endif /* CONFIG_PROC_FS */ +#endif /* CONFIG_NF_CONNTRACK_PROCFS */ }module_param_named (expect_hashsize, nf_ct_expect_hsize, uint,0400 );
net/netfilter/nf_conntrack_standalone.c +2 -2
@@ -34,7 +34,7 @@MODULE_LICENSE ("GPL" ); -#ifdef CONFIG_PROC_FS +#ifdef CONFIG_NF_CONNTRACK_PROCFS int print_tuple(struct seq_file *s, const struct nf_conntrack_tuple *tuple, const struct nf_conntrack_l3proto *l3proto,
@@ -396,7 +396,7 @@ static int nf_conntrack_standalone_init_proc(struct net *net)static void nf_conntrack_standalone_fini_proc (struct net *net) { } -#endif /* CONFIG_PROC_FS */ +#endif /* CONFIG_NF_CONNTRACK_PROCFS */ /* Sysctl support */
Signature · 1 line
1.7.2.5