add 3.7-rc6 support (patch 820 still has to be fixed)
[openwrt/staging/chunkeey.git] / target / linux / generic / patches-3.7 / 604-netfilter_cisco_794x_iphone.patch
1 --- a/include/linux/netfilter/nf_conntrack_sip.h
2 +++ b/include/linux/netfilter/nf_conntrack_sip.h
3 @@ -4,12 +4,15 @@
4
5 #include <net/netfilter/nf_conntrack_expect.h>
6
7 +#include <linux/types.h>
8 +
9 #define SIP_PORT 5060
10 #define SIP_TIMEOUT 3600
11
12 struct nf_ct_sip_master {
13 unsigned int register_cseq;
14 unsigned int invite_cseq;
15 + __be16 forced_dport;
16 };
17
18 enum sip_expectation_classes {
19 --- a/net/netfilter/nf_nat_sip.c
20 +++ b/net/netfilter/nf_nat_sip.c
21 @@ -95,11 +95,14 @@ static int map_addr(struct sk_buff *skb,
22 enum ip_conntrack_info ctinfo;
23 struct nf_conn *ct = nf_ct_get(skb, &ctinfo);
24 enum ip_conntrack_dir dir = CTINFO2DIR(ctinfo);
25 + struct nf_ct_sip_master *ct_sip_info;
26 char buffer[INET6_ADDRSTRLEN + sizeof("[]:nnnnn")];
27 unsigned int buflen;
28 union nf_inet_addr newaddr;
29 __be16 newport;
30
31 + ct_sip_info = nfct_help_data(ct->master);
32 +
33 if (nf_inet_addr_cmp(&ct->tuplehash[dir].tuple.src.u3, addr) &&
34 ct->tuplehash[dir].tuple.src.u.udp.port == port) {
35 newaddr = ct->tuplehash[!dir].tuple.dst.u3;
36 @@ -107,7 +110,8 @@ static int map_addr(struct sk_buff *skb,
37 } else if (nf_inet_addr_cmp(&ct->tuplehash[dir].tuple.dst.u3, addr) &&
38 ct->tuplehash[dir].tuple.dst.u.udp.port == port) {
39 newaddr = ct->tuplehash[!dir].tuple.src.u3;
40 - newport = ct->tuplehash[!dir].tuple.src.u.udp.port;
41 + newport = ct_sip_info->forced_dport ? :
42 + ct->tuplehash[!dir].tuple.src.u.udp.port;
43 } else
44 return 1;
45
46 @@ -144,6 +148,7 @@ static unsigned int nf_nat_sip(struct sk
47 enum ip_conntrack_info ctinfo;
48 struct nf_conn *ct = nf_ct_get(skb, &ctinfo);
49 enum ip_conntrack_dir dir = CTINFO2DIR(ctinfo);
50 + struct nf_conn_help *help = nfct_help(ct);
51 unsigned int coff, matchoff, matchlen;
52 enum sip_header_types hdr;
53 union nf_inet_addr addr;
54 @@ -258,6 +263,22 @@ next:
55 !map_sip_addr(skb, protoff, dataoff, dptr, datalen, SIP_HDR_TO))
56 return NF_DROP;
57
58 + struct nf_ct_sip_master *ct_sip_info = nfct_help_data(ct->master);
59 +
60 + /* Mangle destination port for Cisco phones, then fix up checksums */
61 + if (dir == IP_CT_DIR_REPLY && ct_sip_info->forced_dport) {
62 + struct udphdr *uh;
63 +
64 + if (!skb_make_writable(skb, skb->len))
65 + return NF_DROP;
66 +
67 + uh = (struct udphdr *)(skb->data + ip_hdrlen(skb));
68 + uh->dest = ct_sip_info->forced_dport;
69 +
70 + if (!nf_nat_mangle_udp_packet(skb, ct, ctinfo, 0, 0, NULL, 0))
71 + return NF_DROP;
72 + }
73 +
74 return NF_ACCEPT;
75 }
76
77 @@ -311,10 +332,13 @@ static unsigned int nf_nat_sip_expect(st
78 enum ip_conntrack_info ctinfo;
79 struct nf_conn *ct = nf_ct_get(skb, &ctinfo);
80 enum ip_conntrack_dir dir = CTINFO2DIR(ctinfo);
81 + struct nf_conn_help *help = nfct_help(ct);
82 union nf_inet_addr newaddr;
83 u_int16_t port;
84 + __be16 srcport;
85 char buffer[INET6_ADDRSTRLEN + sizeof("[]:nnnnn")];
86 unsigned int buflen;
87 + struct nf_ct_sip_master *ct_sip_info = nfct_help_data(ct->master);
88
89 /* Connection will come from reply */
90 if (nf_inet_addr_cmp(&ct->tuplehash[dir].tuple.src.u3,
91 @@ -326,8 +350,9 @@ static unsigned int nf_nat_sip_expect(st
92 /* If the signalling port matches the connection's source port in the
93 * original direction, try to use the destination port in the opposite
94 * direction. */
95 - if (exp->tuple.dst.u.udp.port ==
96 - ct->tuplehash[dir].tuple.src.u.udp.port)
97 + srcport = ct_sip_info->forced_dport ? :
98 + ct->tuplehash[dir].tuple.src.u.udp.port;
99 + if (exp->tuple.dst.u.udp.port == srcport)
100 port = ntohs(ct->tuplehash[!dir].tuple.dst.u.udp.port);
101 else
102 port = ntohs(exp->tuple.dst.u.udp.port);
103 --- a/net/netfilter/nf_conntrack_sip.c
104 +++ b/net/netfilter/nf_conntrack_sip.c
105 @@ -1440,8 +1440,26 @@ static int process_sip_request(struct sk
106 {
107 enum ip_conntrack_info ctinfo;
108 struct nf_conn *ct = nf_ct_get(skb, &ctinfo);
109 + struct nf_conn_help *help = nfct_help(ct);
110 + enum ip_conntrack_dir dir = CTINFO2DIR(ctinfo);
111 unsigned int matchoff, matchlen;
112 unsigned int cseq, i;
113 + union nf_inet_addr addr;
114 + __be16 port;
115 + struct nf_ct_sip_master *ct_sip_info = nfct_help_data(ct->master);
116 +
117 + /* Many Cisco IP phones use a high source port for SIP requests, but
118 + * listen for the response on port 5060. If we are the local
119 + * router for one of these phones, save the port number from the
120 + * Via: header so that nf_nat_sip can redirect the responses to
121 + * the correct port.
122 + */
123 + if (ct_sip_parse_header_uri(ct, *dptr, NULL, *datalen,
124 + SIP_HDR_VIA_UDP, NULL, &matchoff,
125 + &matchlen, &addr, &port) > 0 &&
126 + port != ct->tuplehash[dir].tuple.src.u.udp.port &&
127 + nf_inet_addr_cmp(&addr, &ct->tuplehash[dir].tuple.src.u3))
128 + ct_sip_info->forced_dport = port;
129
130 for (i = 0; i < ARRAY_SIZE(sip_handlers); i++) {
131 const struct sip_handler *handler;