aboutsummaryrefslogtreecommitdiffstats
path: root/net/ipv4
diff options
context:
space:
mode:
Diffstat (limited to 'net/ipv4')
-rw-r--r--net/ipv4/af_inet.c74
-rw-r--r--net/ipv4/ah4.c20
-rw-r--r--net/ipv4/arp.c68
-rw-r--r--net/ipv4/datagram.c16
-rw-r--r--net/ipv4/devinet.c60
-rw-r--r--net/ipv4/esp4.c8
-rw-r--r--net/ipv4/fib_frontend.c22
-rw-r--r--net/ipv4/fib_hash.c12
-rw-r--r--net/ipv4/fib_semantics.c28
-rw-r--r--net/ipv4/fib_trie.c104
-rw-r--r--net/ipv4/icmp.c16
-rw-r--r--net/ipv4/igmp.c52
-rw-r--r--net/ipv4/inet_connection_sock.c6
-rw-r--r--net/ipv4/inet_diag.c23
-rw-r--r--net/ipv4/inet_hashtables.c106
-rw-r--r--net/ipv4/inet_timewait_sock.c4
-rw-r--r--net/ipv4/ip_forward.c22
-rw-r--r--net/ipv4/ip_fragment.c18
-rw-r--r--net/ipv4/ip_gre.c19
-rw-r--r--net/ipv4/ip_input.c28
-rw-r--r--net/ipv4/ip_options.c14
-rw-r--r--net/ipv4/ip_output.c42
-rw-r--r--net/ipv4/ip_sockglue.c82
-rw-r--r--net/ipv4/ipcomp.c32
-rw-r--r--net/ipv4/ipconfig.c32
-rw-r--r--net/ipv4/ipip.c17
-rw-r--r--net/ipv4/ipmr.c136
-rw-r--r--net/ipv4/ipvs/ip_vs_app.c2
-rw-r--r--net/ipv4/ipvs/ip_vs_conn.c15
-rw-r--r--net/ipv4/ipvs/ip_vs_core.c20
-rw-r--r--net/ipv4/ipvs/ip_vs_ctl.c4
-rw-r--r--net/ipv4/ipvs/ip_vs_ftp.c2
-rw-r--r--net/ipv4/ipvs/ip_vs_lblc.c12
-rw-r--r--net/ipv4/ipvs/ip_vs_lblcr.c8
-rw-r--r--net/ipv4/ipvs/ip_vs_rr.c2
-rw-r--r--net/ipv4/multipath_drr.c6
-rw-r--r--net/ipv4/multipath_random.c4
-rw-r--r--net/ipv4/multipath_rr.c2
-rw-r--r--net/ipv4/multipath_wrandom.c6
-rw-r--r--net/ipv4/netfilter.c6
-rw-r--r--net/ipv4/netfilter/Kconfig34
-rw-r--r--net/ipv4/netfilter/Makefile1
-rw-r--r--net/ipv4/netfilter/arp_tables.c6
-rw-r--r--net/ipv4/netfilter/arpt_mangle.c2
-rw-r--r--net/ipv4/netfilter/ip_conntrack_amanda.c4
-rw-r--r--net/ipv4/netfilter/ip_conntrack_core.c128
-rw-r--r--net/ipv4/netfilter/ip_conntrack_ftp.c12
-rw-r--r--net/ipv4/netfilter/ip_conntrack_helper_h323.c2
-rw-r--r--net/ipv4/netfilter/ip_conntrack_helper_pptp.c6
-rw-r--r--net/ipv4/netfilter/ip_conntrack_irc.c18
-rw-r--r--net/ipv4/netfilter/ip_conntrack_netbios_ns.c2
-rw-r--r--net/ipv4/netfilter/ip_conntrack_netlink.c118
-rw-r--r--net/ipv4/netfilter/ip_conntrack_proto_icmp.c12
-rw-r--r--net/ipv4/netfilter/ip_conntrack_proto_sctp.c94
-rw-r--r--net/ipv4/netfilter/ip_conntrack_proto_tcp.c314
-rw-r--r--net/ipv4/netfilter/ip_conntrack_proto_udp.c8
-rw-r--r--net/ipv4/netfilter/ip_conntrack_sip.c10
-rw-r--r--net/ipv4/netfilter/ip_conntrack_standalone.c49
-rw-r--r--net/ipv4/netfilter/ip_conntrack_tftp.c4
-rw-r--r--net/ipv4/netfilter/ip_nat_core.c100
-rw-r--r--net/ipv4/netfilter/ip_nat_ftp.c6
-rw-r--r--net/ipv4/netfilter/ip_nat_helper.c36
-rw-r--r--net/ipv4/netfilter/ip_nat_helper_pptp.c10
-rw-r--r--net/ipv4/netfilter/ip_nat_irc.c4
-rw-r--r--net/ipv4/netfilter/ip_nat_proto_icmp.c2
-rw-r--r--net/ipv4/netfilter/ip_nat_proto_tcp.c5
-rw-r--r--net/ipv4/netfilter/ip_nat_proto_udp.c5
-rw-r--r--net/ipv4/netfilter/ip_nat_rule.c38
-rw-r--r--net/ipv4/netfilter/ip_nat_sip.c14
-rw-r--r--net/ipv4/netfilter/ip_nat_snmp_basic.c362
-rw-r--r--net/ipv4/netfilter/ip_nat_standalone.c22
-rw-r--r--net/ipv4/netfilter/ip_queue.c150
-rw-r--r--net/ipv4/netfilter/ip_tables.c50
-rw-r--r--net/ipv4/netfilter/ipt_CLUSTERIP.c61
-rw-r--r--net/ipv4/netfilter/ipt_ECN.c23
-rw-r--r--net/ipv4/netfilter/ipt_LOG.c28
-rw-r--r--net/ipv4/netfilter/ipt_MASQUERADE.c13
-rw-r--r--net/ipv4/netfilter/ipt_NETMAP.c12
-rw-r--r--net/ipv4/netfilter/ipt_REDIRECT.c10
-rw-r--r--net/ipv4/netfilter/ipt_REJECT.c60
-rw-r--r--net/ipv4/netfilter/ipt_SAME.c24
-rw-r--r--net/ipv4/netfilter/ipt_TCPMSS.c207
-rw-r--r--net/ipv4/netfilter/ipt_TOS.c15
-rw-r--r--net/ipv4/netfilter/ipt_TTL.c19
-rw-r--r--net/ipv4/netfilter/ipt_ULOG.c50
-rw-r--r--net/ipv4/netfilter/ipt_addrtype.c11
-rw-r--r--net/ipv4/netfilter/ipt_ah.c14
-rw-r--r--net/ipv4/netfilter/ipt_ecn.c10
-rw-r--r--net/ipv4/netfilter/ipt_iprange.c14
-rw-r--r--net/ipv4/netfilter/ipt_owner.c15
-rw-r--r--net/ipv4/netfilter/ipt_recent.c16
-rw-r--r--net/ipv4/netfilter/ipt_tos.c10
-rw-r--r--net/ipv4/netfilter/ipt_ttl.c15
-rw-r--r--net/ipv4/netfilter/iptable_filter.c4
-rw-r--r--net/ipv4/netfilter/iptable_mangle.c8
-rw-r--r--net/ipv4/netfilter/iptable_raw.c28
-rw-r--r--net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c24
-rw-r--r--net/ipv4/netfilter/nf_conntrack_l3proto_ipv4_compat.c14
-rw-r--r--net/ipv4/netfilter/nf_conntrack_proto_icmp.c32
-rw-r--r--net/ipv4/netfilter/nf_nat_core.c93
-rw-r--r--net/ipv4/netfilter/nf_nat_h323.c2
-rw-r--r--net/ipv4/netfilter/nf_nat_helper.c12
-rw-r--r--net/ipv4/netfilter/nf_nat_pptp.c10
-rw-r--r--net/ipv4/netfilter/nf_nat_proto_icmp.c2
-rw-r--r--net/ipv4/netfilter/nf_nat_proto_tcp.c4
-rw-r--r--net/ipv4/netfilter/nf_nat_proto_udp.c4
-rw-r--r--net/ipv4/netfilter/nf_nat_rule.c26
-rw-r--r--net/ipv4/netfilter/nf_nat_sip.c14
-rw-r--r--net/ipv4/netfilter/nf_nat_snmp_basic.c98
-rw-r--r--net/ipv4/netfilter/nf_nat_standalone.c26
-rw-r--r--net/ipv4/proc.c16
-rw-r--r--net/ipv4/protocol.c2
-rw-r--r--net/ipv4/raw.c30
-rw-r--r--net/ipv4/route.c173
-rw-r--r--net/ipv4/syncookies.c58
-rw-r--r--net/ipv4/sysctl_net_ipv4.c20
-rw-r--r--net/ipv4/tcp.c19
-rw-r--r--net/ipv4/tcp_cong.c38
-rw-r--r--net/ipv4/tcp_cubic.c68
-rw-r--r--net/ipv4/tcp_highspeed.c4
-rw-r--r--net/ipv4/tcp_htcp.c67
-rw-r--r--net/ipv4/tcp_input.c221
-rw-r--r--net/ipv4/tcp_ipv4.c38
-rw-r--r--net/ipv4/tcp_minisocks.c12
-rw-r--r--net/ipv4/tcp_output.c65
-rw-r--r--net/ipv4/tcp_probe.c2
-rw-r--r--net/ipv4/tcp_timer.c12
-rw-r--r--net/ipv4/tcp_vegas.c4
-rw-r--r--net/ipv4/tcp_westwood.c24
-rw-r--r--net/ipv4/udp.c111
-rw-r--r--net/ipv4/udp_impl.h2
-rw-r--r--net/ipv4/xfrm4_input.c6
-rw-r--r--net/ipv4/xfrm4_mode_tunnel.c57
-rw-r--r--net/ipv4/xfrm4_output.c8
-rw-r--r--net/ipv4/xfrm4_policy.c59
-rw-r--r--net/ipv4/xfrm4_state.c1
-rw-r--r--net/ipv4/xfrm4_tunnel.c2
137 files changed, 2430 insertions, 2495 deletions
diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
index 864009643675..cf358c84c440 100644
--- a/net/ipv4/af_inet.c
+++ b/net/ipv4/af_inet.c
@@ -550,7 +550,7 @@ int inet_stream_connect(struct socket *sock, struct sockaddr *uaddr,
550 if (err < 0) 550 if (err < 0)
551 goto out; 551 goto out;
552 552
553 sock->state = SS_CONNECTING; 553 sock->state = SS_CONNECTING;
554 554
555 /* Just entered SS_CONNECTING state; the only 555 /* Just entered SS_CONNECTING state; the only
556 * difference is that return value in non-blocking 556 * difference is that return value in non-blocking
@@ -878,36 +878,36 @@ static struct net_proto_family inet_family_ops = {
878 */ 878 */
879static struct inet_protosw inetsw_array[] = 879static struct inet_protosw inetsw_array[] =
880{ 880{
881 { 881 {
882 .type = SOCK_STREAM, 882 .type = SOCK_STREAM,
883 .protocol = IPPROTO_TCP, 883 .protocol = IPPROTO_TCP,
884 .prot = &tcp_prot, 884 .prot = &tcp_prot,
885 .ops = &inet_stream_ops, 885 .ops = &inet_stream_ops,
886 .capability = -1, 886 .capability = -1,
887 .no_check = 0, 887 .no_check = 0,
888 .flags = INET_PROTOSW_PERMANENT | 888 .flags = INET_PROTOSW_PERMANENT |
889 INET_PROTOSW_ICSK, 889 INET_PROTOSW_ICSK,
890 }, 890 },
891 891
892 { 892 {
893 .type = SOCK_DGRAM, 893 .type = SOCK_DGRAM,
894 .protocol = IPPROTO_UDP, 894 .protocol = IPPROTO_UDP,
895 .prot = &udp_prot, 895 .prot = &udp_prot,
896 .ops = &inet_dgram_ops, 896 .ops = &inet_dgram_ops,
897 .capability = -1, 897 .capability = -1,
898 .no_check = UDP_CSUM_DEFAULT, 898 .no_check = UDP_CSUM_DEFAULT,
899 .flags = INET_PROTOSW_PERMANENT, 899 .flags = INET_PROTOSW_PERMANENT,
900 }, 900 },
901 901
902 902
903 { 903 {
904 .type = SOCK_RAW, 904 .type = SOCK_RAW,
905 .protocol = IPPROTO_IP, /* wild card */ 905 .protocol = IPPROTO_IP, /* wild card */
906 .prot = &raw_prot, 906 .prot = &raw_prot,
907 .ops = &inet_sockraw_ops, 907 .ops = &inet_sockraw_ops,
908 .capability = CAP_NET_RAW, 908 .capability = CAP_NET_RAW,
909 .no_check = UDP_CSUM_DEFAULT, 909 .no_check = UDP_CSUM_DEFAULT,
910 .flags = INET_PROTOSW_REUSE, 910 .flags = INET_PROTOSW_REUSE,
911 } 911 }
912}; 912};
913 913
@@ -946,7 +946,7 @@ void inet_register_protosw(struct inet_protosw *p)
946 /* Add the new entry after the last permanent entry if any, so that 946 /* Add the new entry after the last permanent entry if any, so that
947 * the new entry does not override a permanent entry when matched with 947 * the new entry does not override a permanent entry when matched with
948 * a wild-card protocol. But it is allowed to override any existing 948 * a wild-card protocol. But it is allowed to override any existing
949 * non-permanent entry. This means that when we remove this entry, the 949 * non-permanent entry. This means that when we remove this entry, the
950 * system automatically returns to the old behavior. 950 * system automatically returns to the old behavior.
951 */ 951 */
952 list_add_rcu(&p->list, last_perm); 952 list_add_rcu(&p->list, last_perm);
@@ -1007,7 +1007,7 @@ static int inet_sk_reselect_saddr(struct sock *sk)
1007 RT_CONN_FLAGS(sk), 1007 RT_CONN_FLAGS(sk),
1008 sk->sk_bound_dev_if, 1008 sk->sk_bound_dev_if,
1009 sk->sk_protocol, 1009 sk->sk_protocol,
1010 inet->sport, inet->dport, sk); 1010 inet->sport, inet->dport, sk, 0);
1011 if (err) 1011 if (err)
1012 return err; 1012 return err;
1013 1013
@@ -1073,7 +1073,7 @@ int inet_sk_rebuild_header(struct sock *sk)
1073 }, 1073 },
1074 }, 1074 },
1075 }; 1075 };
1076 1076
1077 security_sk_classify_flow(sk, &fl); 1077 security_sk_classify_flow(sk, &fl);
1078 err = ip_route_output_flow(&rt, &fl, sk, 0); 1078 err = ip_route_output_flow(&rt, &fl, sk, 0);
1079} 1079}
@@ -1273,10 +1273,10 @@ static int __init inet_init(void)
1273 goto out_unregister_udp_proto; 1273 goto out_unregister_udp_proto;
1274 1274
1275 /* 1275 /*
1276 * Tell SOCKET that we are alive... 1276 * Tell SOCKET that we are alive...
1277 */ 1277 */
1278 1278
1279 (void)sock_register(&inet_family_ops); 1279 (void)sock_register(&inet_family_ops);
1280 1280
1281 /* 1281 /*
1282 * Add all the base protocols. 1282 * Add all the base protocols.
@@ -1306,9 +1306,9 @@ static int __init inet_init(void)
1306 1306
1307 arp_init(); 1307 arp_init();
1308 1308
1309 /* 1309 /*
1310 * Set the IP module up 1310 * Set the IP module up
1311 */ 1311 */
1312 1312
1313 ip_init(); 1313 ip_init();
1314 1314
@@ -1334,11 +1334,11 @@ static int __init inet_init(void)
1334#endif 1334#endif
1335 /* 1335 /*
1336 * Initialise per-cpu ipv4 mibs 1336 * Initialise per-cpu ipv4 mibs
1337 */ 1337 */
1338 1338
1339 if(init_ipv4_mibs()) 1339 if(init_ipv4_mibs())
1340 printk(KERN_CRIT "inet_init: Cannot init ipv4 mibs\n"); ; 1340 printk(KERN_CRIT "inet_init: Cannot init ipv4 mibs\n"); ;
1341 1341
1342 ipv4_proc_init(); 1342 ipv4_proc_init();
1343 1343
1344 ipfrag_init(); 1344 ipfrag_init();
diff --git a/net/ipv4/ah4.c b/net/ipv4/ah4.c
index 67a5509e26fc..7194eb40b6d0 100644
--- a/net/ipv4/ah4.c
+++ b/net/ipv4/ah4.c
@@ -91,7 +91,7 @@ static int ah_output(struct xfrm_state *x, struct sk_buff *skb)
91 top_iph->check = 0; 91 top_iph->check = 0;
92 92
93 ahp = x->data; 93 ahp = x->data;
94 ah->hdrlen = (XFRM_ALIGN8(sizeof(struct ip_auth_hdr) + 94 ah->hdrlen = (XFRM_ALIGN8(sizeof(struct ip_auth_hdr) +
95 ahp->icv_trunc_len) >> 2) - 2; 95 ahp->icv_trunc_len) >> 2) - 2;
96 96
97 ah->reserved = 0; 97 ah->reserved = 0;
@@ -135,9 +135,9 @@ static int ah_input(struct xfrm_state *x, struct sk_buff *skb)
135 ah = (struct ip_auth_hdr*)skb->data; 135 ah = (struct ip_auth_hdr*)skb->data;
136 ahp = x->data; 136 ahp = x->data;
137 ah_hlen = (ah->hdrlen + 2) << 2; 137 ah_hlen = (ah->hdrlen + 2) << 2;
138 138
139 if (ah_hlen != XFRM_ALIGN8(sizeof(struct ip_auth_hdr) + ahp->icv_full_len) && 139 if (ah_hlen != XFRM_ALIGN8(sizeof(struct ip_auth_hdr) + ahp->icv_full_len) &&
140 ah_hlen != XFRM_ALIGN8(sizeof(struct ip_auth_hdr) + ahp->icv_trunc_len)) 140 ah_hlen != XFRM_ALIGN8(sizeof(struct ip_auth_hdr) + ahp->icv_trunc_len))
141 goto out; 141 goto out;
142 142
143 if (!pskb_may_pull(skb, ah_hlen)) 143 if (!pskb_may_pull(skb, ah_hlen))
@@ -166,9 +166,9 @@ static int ah_input(struct xfrm_state *x, struct sk_buff *skb)
166 if (ip_clear_mutable_options(iph, &dummy)) 166 if (ip_clear_mutable_options(iph, &dummy))
167 goto out; 167 goto out;
168 } 168 }
169 { 169 {
170 u8 auth_data[MAX_AH_AUTH_LEN]; 170 u8 auth_data[MAX_AH_AUTH_LEN];
171 171
172 memcpy(auth_data, ah->auth_data, ahp->icv_trunc_len); 172 memcpy(auth_data, ah->auth_data, ahp->icv_trunc_len);
173 skb_push(skb, ihl); 173 skb_push(skb, ihl);
174 err = ah_mac_digest(ahp, skb, ah->auth_data); 174 err = ah_mac_digest(ahp, skb, ah->auth_data);
@@ -237,7 +237,7 @@ static int ah_init_state(struct xfrm_state *x)
237 ahp->tfm = tfm; 237 ahp->tfm = tfm;
238 if (crypto_hash_setkey(tfm, ahp->key, ahp->key_len)) 238 if (crypto_hash_setkey(tfm, ahp->key, ahp->key_len))
239 goto error; 239 goto error;
240 240
241 /* 241 /*
242 * Lookup the algorithm description maintained by xfrm_algo, 242 * Lookup the algorithm description maintained by xfrm_algo,
243 * verify crypto transform properties, and store information 243 * verify crypto transform properties, and store information
@@ -254,16 +254,16 @@ static int ah_init_state(struct xfrm_state *x)
254 aalg_desc->uinfo.auth.icv_fullbits/8); 254 aalg_desc->uinfo.auth.icv_fullbits/8);
255 goto error; 255 goto error;
256 } 256 }
257 257
258 ahp->icv_full_len = aalg_desc->uinfo.auth.icv_fullbits/8; 258 ahp->icv_full_len = aalg_desc->uinfo.auth.icv_fullbits/8;
259 ahp->icv_trunc_len = aalg_desc->uinfo.auth.icv_truncbits/8; 259 ahp->icv_trunc_len = aalg_desc->uinfo.auth.icv_truncbits/8;
260 260
261 BUG_ON(ahp->icv_trunc_len > MAX_AH_AUTH_LEN); 261 BUG_ON(ahp->icv_trunc_len > MAX_AH_AUTH_LEN);
262 262
263 ahp->work_icv = kmalloc(ahp->icv_full_len, GFP_KERNEL); 263 ahp->work_icv = kmalloc(ahp->icv_full_len, GFP_KERNEL);
264 if (!ahp->work_icv) 264 if (!ahp->work_icv)
265 goto error; 265 goto error;
266 266
267 x->props.header_len = XFRM_ALIGN8(sizeof(struct ip_auth_hdr) + ahp->icv_trunc_len); 267 x->props.header_len = XFRM_ALIGN8(sizeof(struct ip_auth_hdr) + ahp->icv_trunc_len);
268 if (x->props.mode == XFRM_MODE_TUNNEL) 268 if (x->props.mode == XFRM_MODE_TUNNEL)
269 x->props.header_len += sizeof(struct iphdr); 269 x->props.header_len += sizeof(struct iphdr);
diff --git a/net/ipv4/arp.c b/net/ipv4/arp.c
index 3981e8be9ab8..0ffd2d2920c3 100644
--- a/net/ipv4/arp.c
+++ b/net/ipv4/arp.c
@@ -15,9 +15,9 @@
15 * 2 of the License, or (at your option) any later version. 15 * 2 of the License, or (at your option) any later version.
16 * 16 *
17 * Fixes: 17 * Fixes:
18 * Alan Cox : Removed the Ethernet assumptions in 18 * Alan Cox : Removed the Ethernet assumptions in
19 * Florian's code 19 * Florian's code
20 * Alan Cox : Fixed some small errors in the ARP 20 * Alan Cox : Fixed some small errors in the ARP
21 * logic 21 * logic
22 * Alan Cox : Allow >4K in /proc 22 * Alan Cox : Allow >4K in /proc
23 * Alan Cox : Make ARP add its own protocol entry 23 * Alan Cox : Make ARP add its own protocol entry
@@ -39,18 +39,18 @@
39 * Jonathan Naylor : Only lookup the hardware address for 39 * Jonathan Naylor : Only lookup the hardware address for
40 * the correct hardware type. 40 * the correct hardware type.
41 * Germano Caronni : Assorted subtle races. 41 * Germano Caronni : Assorted subtle races.
42 * Craig Schlenter : Don't modify permanent entry 42 * Craig Schlenter : Don't modify permanent entry
43 * during arp_rcv. 43 * during arp_rcv.
44 * Russ Nelson : Tidied up a few bits. 44 * Russ Nelson : Tidied up a few bits.
45 * Alexey Kuznetsov: Major changes to caching and behaviour, 45 * Alexey Kuznetsov: Major changes to caching and behaviour,
46 * eg intelligent arp probing and 46 * eg intelligent arp probing and
47 * generation 47 * generation
48 * of host down events. 48 * of host down events.
49 * Alan Cox : Missing unlock in device events. 49 * Alan Cox : Missing unlock in device events.
50 * Eckes : ARP ioctl control errors. 50 * Eckes : ARP ioctl control errors.
51 * Alexey Kuznetsov: Arp free fix. 51 * Alexey Kuznetsov: Arp free fix.
52 * Manuel Rodriguez: Gratuitous ARP. 52 * Manuel Rodriguez: Gratuitous ARP.
53 * Jonathan Layes : Added arpd support through kerneld 53 * Jonathan Layes : Added arpd support through kerneld
54 * message queue (960314) 54 * message queue (960314)
55 * Mike Shaver : /proc/sys/net/ipv4/arp_* support 55 * Mike Shaver : /proc/sys/net/ipv4/arp_* support
56 * Mike McLagan : Routing by source 56 * Mike McLagan : Routing by source
@@ -210,7 +210,7 @@ int arp_mc_map(__be32 addr, u8 *haddr, struct net_device *dev, int dir)
210 case ARPHRD_FDDI: 210 case ARPHRD_FDDI:
211 case ARPHRD_IEEE802: 211 case ARPHRD_IEEE802:
212 ip_eth_mc_map(addr, haddr); 212 ip_eth_mc_map(addr, haddr);
213 return 0; 213 return 0;
214 case ARPHRD_IEEE802_TR: 214 case ARPHRD_IEEE802_TR:
215 ip_tr_mc_map(addr, haddr); 215 ip_tr_mc_map(addr, haddr);
216 return 0; 216 return 0;
@@ -288,7 +288,7 @@ static int arp_constructor(struct neighbour *neigh)
288 switch (dev->type) { 288 switch (dev->type) {
289 default: 289 default:
290 break; 290 break;
291 case ARPHRD_ROSE: 291 case ARPHRD_ROSE:
292#if defined(CONFIG_AX25) || defined(CONFIG_AX25_MODULE) 292#if defined(CONFIG_AX25) || defined(CONFIG_AX25_MODULE)
293 case ARPHRD_AX25: 293 case ARPHRD_AX25:
294#if defined(CONFIG_NETROM) || defined(CONFIG_NETROM_MODULE) 294#if defined(CONFIG_NETROM) || defined(CONFIG_NETROM_MODULE)
@@ -425,18 +425,18 @@ static int arp_filter(__be32 sip, __be32 tip, struct net_device *dev)
425 struct flowi fl = { .nl_u = { .ip4_u = { .daddr = sip, 425 struct flowi fl = { .nl_u = { .ip4_u = { .daddr = sip,
426 .saddr = tip } } }; 426 .saddr = tip } } };
427 struct rtable *rt; 427 struct rtable *rt;
428 int flag = 0; 428 int flag = 0;
429 /*unsigned long now; */ 429 /*unsigned long now; */
430 430
431 if (ip_route_output_key(&rt, &fl) < 0) 431 if (ip_route_output_key(&rt, &fl) < 0)
432 return 1; 432 return 1;
433 if (rt->u.dst.dev != dev) { 433 if (rt->u.dst.dev != dev) {
434 NET_INC_STATS_BH(LINUX_MIB_ARPFILTER); 434 NET_INC_STATS_BH(LINUX_MIB_ARPFILTER);
435 flag = 1; 435 flag = 1;
436 } 436 }
437 ip_rt_put(rt); 437 ip_rt_put(rt);
438 return flag; 438 return flag;
439} 439}
440 440
441/* OBSOLETE FUNCTIONS */ 441/* OBSOLETE FUNCTIONS */
442 442
@@ -490,7 +490,7 @@ int arp_find(unsigned char *haddr, struct sk_buff *skb)
490 n->used = jiffies; 490 n->used = jiffies;
491 if (n->nud_state&NUD_VALID || neigh_event_send(n, skb) == 0) { 491 if (n->nud_state&NUD_VALID || neigh_event_send(n, skb) == 0) {
492 read_lock_bh(&n->lock); 492 read_lock_bh(&n->lock);
493 memcpy(haddr, n->ha, dev->addr_len); 493 memcpy(haddr, n->ha, dev->addr_len);
494 read_unlock_bh(&n->lock); 494 read_unlock_bh(&n->lock);
495 neigh_release(n); 495 neigh_release(n);
496 return 0; 496 return 0;
@@ -572,7 +572,7 @@ struct sk_buff *arp_create(int type, int ptype, __be32 dest_ip,
572 /* 572 /*
573 * Allocate a buffer 573 * Allocate a buffer
574 */ 574 */
575 575
576 skb = alloc_skb(sizeof(struct arphdr)+ 2*(dev->addr_len+4) 576 skb = alloc_skb(sizeof(struct arphdr)+ 2*(dev->addr_len+4)
577 + LL_RESERVED_SPACE(dev), GFP_ATOMIC); 577 + LL_RESERVED_SPACE(dev), GFP_ATOMIC);
578 if (skb == NULL) 578 if (skb == NULL)
@@ -685,7 +685,7 @@ void arp_send(int type, int ptype, __be32 dest_ip,
685 /* 685 /*
686 * No arp on this interface. 686 * No arp on this interface.
687 */ 687 */
688 688
689 if (dev->flags&IFF_NOARP) 689 if (dev->flags&IFF_NOARP)
690 return; 690 return;
691 691
@@ -725,7 +725,7 @@ static int arp_process(struct sk_buff *skb)
725 arp = skb->nh.arph; 725 arp = skb->nh.arph;
726 726
727 switch (dev_type) { 727 switch (dev_type) {
728 default: 728 default:
729 if (arp->ar_pro != htons(ETH_P_IP) || 729 if (arp->ar_pro != htons(ETH_P_IP) ||
730 htons(dev_type) != arp->ar_hrd) 730 htons(dev_type) != arp->ar_hrd)
731 goto out; 731 goto out;
@@ -792,7 +792,7 @@ static int arp_process(struct sk_buff *skb)
792 tha = arp_ptr; 792 tha = arp_ptr;
793 arp_ptr += dev->addr_len; 793 arp_ptr += dev->addr_len;
794 memcpy(&tip, arp_ptr, 4); 794 memcpy(&tip, arp_ptr, 4);
795/* 795/*
796 * Check for bad requests for 127.x.x.x and requests for multicast 796 * Check for bad requests for 127.x.x.x and requests for multicast
797 * addresses. If this is one such, delete it. 797 * addresses. If this is one such, delete it.
798 */ 798 */
@@ -809,16 +809,16 @@ static int arp_process(struct sk_buff *skb)
809 * Process entry. The idea here is we want to send a reply if it is a 809 * Process entry. The idea here is we want to send a reply if it is a
810 * request for us or if it is a request for someone else that we hold 810 * request for us or if it is a request for someone else that we hold
811 * a proxy for. We want to add an entry to our cache if it is a reply 811 * a proxy for. We want to add an entry to our cache if it is a reply
812 * to us or if it is a request for our address. 812 * to us or if it is a request for our address.
813 * (The assumption for this last is that if someone is requesting our 813 * (The assumption for this last is that if someone is requesting our
814 * address, they are probably intending to talk to us, so it saves time 814 * address, they are probably intending to talk to us, so it saves time
815 * if we cache their address. Their address is also probably not in 815 * if we cache their address. Their address is also probably not in
816 * our cache, since ours is not in their cache.) 816 * our cache, since ours is not in their cache.)
817 * 817 *
818 * Putting this another way, we only care about replies if they are to 818 * Putting this another way, we only care about replies if they are to
819 * us, in which case we add them to the cache. For requests, we care 819 * us, in which case we add them to the cache. For requests, we care
820 * about those for us and those for our proxies. We reply to both, 820 * about those for us and those for our proxies. We reply to both,
821 * and in the case of requests for us we add the requester to the arp 821 * and in the case of requests for us we add the requester to the arp
822 * cache. 822 * cache.
823 */ 823 */
824 824
@@ -845,7 +845,7 @@ static int arp_process(struct sk_buff *skb)
845 if (!dont_send) 845 if (!dont_send)
846 dont_send |= arp_ignore(in_dev,dev,sip,tip); 846 dont_send |= arp_ignore(in_dev,dev,sip,tip);
847 if (!dont_send && IN_DEV_ARPFILTER(in_dev)) 847 if (!dont_send && IN_DEV_ARPFILTER(in_dev))
848 dont_send |= arp_filter(sip,tip,dev); 848 dont_send |= arp_filter(sip,tip,dev);
849 if (!dont_send) 849 if (!dont_send)
850 arp_send(ARPOP_REPLY,ETH_P_ARP,sip,dev,tip,sha,dev->dev_addr,sha); 850 arp_send(ARPOP_REPLY,ETH_P_ARP,sip,dev,tip,sha,dev->dev_addr,sha);
851 851
@@ -860,7 +860,7 @@ static int arp_process(struct sk_buff *skb)
860 if (n) 860 if (n)
861 neigh_release(n); 861 neigh_release(n);
862 862
863 if (NEIGH_CB(skb)->flags & LOCALLY_ENQUEUED || 863 if (NEIGH_CB(skb)->flags & LOCALLY_ENQUEUED ||
864 skb->pkt_type == PACKET_HOST || 864 skb->pkt_type == PACKET_HOST ||
865 in_dev->arp_parms->proxy_delay == 0) { 865 in_dev->arp_parms->proxy_delay == 0) {
866 arp_send(ARPOP_REPLY,ETH_P_ARP,sip,dev,tip,sha,dev->dev_addr,sha); 866 arp_send(ARPOP_REPLY,ETH_P_ARP,sip,dev,tip,sha,dev->dev_addr,sha);
@@ -1039,7 +1039,7 @@ static int arp_req_set(struct arpreq *r, struct net_device * dev)
1039 if (r->arp_flags & ATF_PERM) 1039 if (r->arp_flags & ATF_PERM)
1040 state = NUD_PERMANENT; 1040 state = NUD_PERMANENT;
1041 err = neigh_update(neigh, (r->arp_flags&ATF_COM) ? 1041 err = neigh_update(neigh, (r->arp_flags&ATF_COM) ?
1042 r->arp_ha.sa_data : NULL, state, 1042 r->arp_ha.sa_data : NULL, state,
1043 NEIGH_UPDATE_F_OVERRIDE| 1043 NEIGH_UPDATE_F_OVERRIDE|
1044 NEIGH_UPDATE_F_ADMIN); 1044 NEIGH_UPDATE_F_ADMIN);
1045 neigh_release(neigh); 1045 neigh_release(neigh);
@@ -1121,7 +1121,7 @@ static int arp_req_delete(struct arpreq *r, struct net_device * dev)
1121 neigh = neigh_lookup(&arp_tbl, &ip, dev); 1121 neigh = neigh_lookup(&arp_tbl, &ip, dev);
1122 if (neigh) { 1122 if (neigh) {
1123 if (neigh->nud_state&~NUD_NOARP) 1123 if (neigh->nud_state&~NUD_NOARP)
1124 err = neigh_update(neigh, NULL, NUD_FAILED, 1124 err = neigh_update(neigh, NULL, NUD_FAILED,
1125 NEIGH_UPDATE_F_OVERRIDE| 1125 NEIGH_UPDATE_F_OVERRIDE|
1126 NEIGH_UPDATE_F_ADMIN); 1126 NEIGH_UPDATE_F_ADMIN);
1127 neigh_release(neigh); 1127 neigh_release(neigh);
@@ -1181,7 +1181,7 @@ int arp_ioctl(unsigned int cmd, void __user *arg)
1181 1181
1182 switch(cmd) { 1182 switch(cmd) {
1183 case SIOCDARP: 1183 case SIOCDARP:
1184 err = arp_req_delete(&r, dev); 1184 err = arp_req_delete(&r, dev);
1185 break; 1185 break;
1186 case SIOCSARP: 1186 case SIOCSARP:
1187 err = arp_req_set(&r, dev); 1187 err = arp_req_set(&r, dev);
@@ -1268,14 +1268,14 @@ static char *ax2asc2(ax25_address *a, char *buf)
1268 1268
1269 if (c != ' ') *s++ = c; 1269 if (c != ' ') *s++ = c;
1270 } 1270 }
1271 1271
1272 *s++ = '-'; 1272 *s++ = '-';
1273 1273
1274 if ((n = ((a->ax25_call[6] >> 1) & 0x0F)) > 9) { 1274 if ((n = ((a->ax25_call[6] >> 1) & 0x0F)) > 9) {
1275 *s++ = '1'; 1275 *s++ = '1';
1276 n -= 10; 1276 n -= 10;
1277 } 1277 }
1278 1278
1279 *s++ = n + '0'; 1279 *s++ = n + '0';
1280 *s++ = '\0'; 1280 *s++ = '\0';
1281 1281
@@ -1373,7 +1373,7 @@ static int arp_seq_open(struct inode *inode, struct file *file)
1373 struct seq_file *seq; 1373 struct seq_file *seq;
1374 int rc = -ENOMEM; 1374 int rc = -ENOMEM;
1375 struct neigh_seq_state *s = kzalloc(sizeof(*s), GFP_KERNEL); 1375 struct neigh_seq_state *s = kzalloc(sizeof(*s), GFP_KERNEL);
1376 1376
1377 if (!s) 1377 if (!s)
1378 goto out; 1378 goto out;
1379 1379
@@ -1390,7 +1390,7 @@ out_kfree:
1390 goto out; 1390 goto out;
1391} 1391}
1392 1392
1393static struct file_operations arp_seq_fops = { 1393static const struct file_operations arp_seq_fops = {
1394 .owner = THIS_MODULE, 1394 .owner = THIS_MODULE,
1395 .open = arp_seq_open, 1395 .open = arp_seq_open,
1396 .read = seq_read, 1396 .read = seq_read,
diff --git a/net/ipv4/datagram.c b/net/ipv4/datagram.c
index 7b068a891953..dd02a45d0f67 100644
--- a/net/ipv4/datagram.c
+++ b/net/ipv4/datagram.c
@@ -29,12 +29,12 @@ int ip4_datagram_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len)
29 int oif; 29 int oif;
30 int err; 30 int err;
31 31
32
33 if (addr_len < sizeof(*usin))
34 return -EINVAL;
35 32
36 if (usin->sin_family != AF_INET) 33 if (addr_len < sizeof(*usin))
37 return -EAFNOSUPPORT; 34 return -EINVAL;
35
36 if (usin->sin_family != AF_INET)
37 return -EAFNOSUPPORT;
38 38
39 sk_dst_reset(sk); 39 sk_dst_reset(sk);
40 40
@@ -49,15 +49,15 @@ int ip4_datagram_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len)
49 err = ip_route_connect(&rt, usin->sin_addr.s_addr, saddr, 49 err = ip_route_connect(&rt, usin->sin_addr.s_addr, saddr,
50 RT_CONN_FLAGS(sk), oif, 50 RT_CONN_FLAGS(sk), oif,
51 sk->sk_protocol, 51 sk->sk_protocol,
52 inet->sport, usin->sin_port, sk); 52 inet->sport, usin->sin_port, sk, 1);
53 if (err) 53 if (err)
54 return err; 54 return err;
55 if ((rt->rt_flags & RTCF_BROADCAST) && !sock_flag(sk, SOCK_BROADCAST)) { 55 if ((rt->rt_flags & RTCF_BROADCAST) && !sock_flag(sk, SOCK_BROADCAST)) {
56 ip_rt_put(rt); 56 ip_rt_put(rt);
57 return -EACCES; 57 return -EACCES;
58 } 58 }
59 if (!inet->saddr) 59 if (!inet->saddr)
60 inet->saddr = rt->rt_src; /* Update source address */ 60 inet->saddr = rt->rt_src; /* Update source address */
61 if (!inet->rcv_saddr) 61 if (!inet->rcv_saddr)
62 inet->rcv_saddr = rt->rt_src; 62 inet->rcv_saddr = rt->rt_src;
63 inet->daddr = rt->rt_dst; 63 inet->daddr = rt->rt_dst;
diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
index 480ace9819f6..ba5e7f4cd127 100644
--- a/net/ipv4/devinet.c
+++ b/net/ipv4/devinet.c
@@ -252,7 +252,7 @@ static void __inet_del_ifa(struct in_device *in_dev, struct in_ifaddr **ifap,
252 252
253 ASSERT_RTNL(); 253 ASSERT_RTNL();
254 254
255 /* 1. Deleting primary ifaddr forces deletion all secondaries 255 /* 1. Deleting primary ifaddr forces deletion all secondaries
256 * unless alias promotion is set 256 * unless alias promotion is set
257 **/ 257 **/
258 258
@@ -260,7 +260,7 @@ static void __inet_del_ifa(struct in_device *in_dev, struct in_ifaddr **ifap,
260 struct in_ifaddr **ifap1 = &ifa1->ifa_next; 260 struct in_ifaddr **ifap1 = &ifa1->ifa_next;
261 261
262 while ((ifa = *ifap1) != NULL) { 262 while ((ifa = *ifap1) != NULL) {
263 if (!(ifa->ifa_flags & IFA_F_SECONDARY) && 263 if (!(ifa->ifa_flags & IFA_F_SECONDARY) &&
264 ifa1->ifa_scope <= ifa->ifa_scope) 264 ifa1->ifa_scope <= ifa->ifa_scope)
265 last_prim = ifa; 265 last_prim = ifa;
266 266
@@ -583,8 +583,8 @@ static __inline__ int inet_abc_len(__be32 addr)
583{ 583{
584 int rc = -1; /* Something else, probably a multicast. */ 584 int rc = -1; /* Something else, probably a multicast. */
585 585
586 if (ZERONET(addr)) 586 if (ZERONET(addr))
587 rc = 0; 587 rc = 0;
588 else { 588 else {
589 __u32 haddr = ntohl(addr); 589 __u32 haddr = ntohl(addr);
590 590
@@ -596,7 +596,7 @@ static __inline__ int inet_abc_len(__be32 addr)
596 rc = 24; 596 rc = 24;
597 } 597 }
598 598
599 return rc; 599 return rc;
600} 600}
601 601
602 602
@@ -1020,29 +1020,29 @@ int unregister_inetaddr_notifier(struct notifier_block *nb)
1020 * alias numbering and to create unique labels if possible. 1020 * alias numbering and to create unique labels if possible.
1021*/ 1021*/
1022static void inetdev_changename(struct net_device *dev, struct in_device *in_dev) 1022static void inetdev_changename(struct net_device *dev, struct in_device *in_dev)
1023{ 1023{
1024 struct in_ifaddr *ifa; 1024 struct in_ifaddr *ifa;
1025 int named = 0; 1025 int named = 0;
1026 1026
1027 for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) { 1027 for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) {
1028 char old[IFNAMSIZ], *dot; 1028 char old[IFNAMSIZ], *dot;
1029 1029
1030 memcpy(old, ifa->ifa_label, IFNAMSIZ); 1030 memcpy(old, ifa->ifa_label, IFNAMSIZ);
1031 memcpy(ifa->ifa_label, dev->name, IFNAMSIZ); 1031 memcpy(ifa->ifa_label, dev->name, IFNAMSIZ);
1032 if (named++ == 0) 1032 if (named++ == 0)
1033 continue; 1033 continue;
1034 dot = strchr(ifa->ifa_label, ':'); 1034 dot = strchr(ifa->ifa_label, ':');
1035 if (dot == NULL) { 1035 if (dot == NULL) {
1036 sprintf(old, ":%d", named); 1036 sprintf(old, ":%d", named);
1037 dot = old; 1037 dot = old;
1038 } 1038 }
1039 if (strlen(dot) + strlen(dev->name) < IFNAMSIZ) { 1039 if (strlen(dot) + strlen(dev->name) < IFNAMSIZ) {
1040 strcat(ifa->ifa_label, dot); 1040 strcat(ifa->ifa_label, dot);
1041 } else { 1041 } else {
1042 strcpy(ifa->ifa_label + (IFNAMSIZ - strlen(dot) - 1), dot); 1042 strcpy(ifa->ifa_label + (IFNAMSIZ - strlen(dot) - 1), dot);
1043 } 1043 }
1044 } 1044 }
1045} 1045}
1046 1046
1047/* Called only under RTNL semaphore */ 1047/* Called only under RTNL semaphore */
1048 1048
@@ -1140,7 +1140,7 @@ static int inet_fill_ifaddr(struct sk_buff *skb, struct in_ifaddr *ifa,
1140 1140
1141 nlh = nlmsg_put(skb, pid, seq, event, sizeof(*ifm), flags); 1141 nlh = nlmsg_put(skb, pid, seq, event, sizeof(*ifm), flags);
1142 if (nlh == NULL) 1142 if (nlh == NULL)
1143 return -ENOBUFS; 1143 return -EMSGSIZE;
1144 1144
1145 ifm = nlmsg_data(nlh); 1145 ifm = nlmsg_data(nlh);
1146 ifm->ifa_family = AF_INET; 1146 ifm->ifa_family = AF_INET;
@@ -1167,7 +1167,8 @@ static int inet_fill_ifaddr(struct sk_buff *skb, struct in_ifaddr *ifa,
1167 return nlmsg_end(skb, nlh); 1167 return nlmsg_end(skb, nlh);
1168 1168
1169nla_put_failure: 1169nla_put_failure:
1170 return nlmsg_cancel(skb, nlh); 1170 nlmsg_cancel(skb, nlh);
1171 return -EMSGSIZE;
1171} 1172}
1172 1173
1173static int inet_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb) 1174static int inet_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
@@ -1225,9 +1226,12 @@ static void rtmsg_ifa(int event, struct in_ifaddr* ifa, struct nlmsghdr *nlh,
1225 goto errout; 1226 goto errout;
1226 1227
1227 err = inet_fill_ifaddr(skb, ifa, pid, seq, event, 0); 1228 err = inet_fill_ifaddr(skb, ifa, pid, seq, event, 0);
1228 /* failure implies BUG in inet_nlmsg_size() */ 1229 if (err < 0) {
1229 BUG_ON(err < 0); 1230 /* -EMSGSIZE implies BUG in inet_nlmsg_size() */
1230 1231 WARN_ON(err == -EMSGSIZE);
1232 kfree_skb(skb);
1233 goto errout;
1234 }
1231 err = rtnl_notify(skb, pid, RTNLGRP_IPV4_IFADDR, nlh, GFP_KERNEL); 1235 err = rtnl_notify(skb, pid, RTNLGRP_IPV4_IFADDR, nlh, GFP_KERNEL);
1232errout: 1236errout:
1233 if (err < 0) 1237 if (err < 0)
@@ -1535,7 +1539,7 @@ static struct devinet_sysctl_table {
1535 }, 1539 },
1536 }, 1540 },
1537 .devinet_conf_dir = { 1541 .devinet_conf_dir = {
1538 { 1542 {
1539 .ctl_name = NET_IPV4_CONF, 1543 .ctl_name = NET_IPV4_CONF,
1540 .procname = "conf", 1544 .procname = "conf",
1541 .mode = 0555, 1545 .mode = 0555,
@@ -1577,18 +1581,18 @@ static void devinet_sysctl_register(struct in_device *in_dev,
1577 } 1581 }
1578 1582
1579 if (dev) { 1583 if (dev) {
1580 dev_name = dev->name; 1584 dev_name = dev->name;
1581 t->devinet_dev[0].ctl_name = dev->ifindex; 1585 t->devinet_dev[0].ctl_name = dev->ifindex;
1582 } else { 1586 } else {
1583 dev_name = "default"; 1587 dev_name = "default";
1584 t->devinet_dev[0].ctl_name = NET_PROTO_CONF_DEFAULT; 1588 t->devinet_dev[0].ctl_name = NET_PROTO_CONF_DEFAULT;
1585 } 1589 }
1586 1590
1587 /* 1591 /*
1588 * Make a copy of dev_name, because '.procname' is regarded as const 1592 * Make a copy of dev_name, because '.procname' is regarded as const
1589 * by sysctl and we wouldn't want anyone to change it under our feet 1593 * by sysctl and we wouldn't want anyone to change it under our feet
1590 * (see SIOCSIFNAME). 1594 * (see SIOCSIFNAME).
1591 */ 1595 */
1592 dev_name = kstrdup(dev_name, GFP_KERNEL); 1596 dev_name = kstrdup(dev_name, GFP_KERNEL);
1593 if (!dev_name) 1597 if (!dev_name)
1594 goto free; 1598 goto free;
diff --git a/net/ipv4/esp4.c b/net/ipv4/esp4.c
index f2c6776ea0e6..31041127eeb8 100644
--- a/net/ipv4/esp4.c
+++ b/net/ipv4/esp4.c
@@ -215,7 +215,7 @@ static int esp_input(struct xfrm_state *x, struct sk_buff *skb)
215 if (padlen+2 >= elen) 215 if (padlen+2 >= elen)
216 goto out; 216 goto out;
217 217
218 /* ... check padding bits here. Silly. :-) */ 218 /* ... check padding bits here. Silly. :-) */
219 219
220 iph = skb->nh.iph; 220 iph = skb->nh.iph;
221 ihl = iph->ihl * 4; 221 ihl = iph->ihl * 4;
@@ -236,7 +236,7 @@ static int esp_input(struct xfrm_state *x, struct sk_buff *skb)
236 236
237 ipaddr.a4 = iph->saddr; 237 ipaddr.a4 = iph->saddr;
238 km_new_mapping(x, &ipaddr, uh->source); 238 km_new_mapping(x, &ipaddr, uh->source);
239 239
240 /* XXX: perhaps add an extra 240 /* XXX: perhaps add an extra
241 * policy check here, to see 241 * policy check here, to see
242 * if we should allow or 242 * if we should allow or
@@ -245,7 +245,7 @@ static int esp_input(struct xfrm_state *x, struct sk_buff *skb)
245 * address/port. 245 * address/port.
246 */ 246 */
247 } 247 }
248 248
249 /* 249 /*
250 * 2) ignore UDP/TCP checksums in case 250 * 2) ignore UDP/TCP checksums in case
251 * of NAT-T in Transport Mode, or 251 * of NAT-T in Transport Mode, or
@@ -284,7 +284,7 @@ static u32 esp4_get_max_size(struct xfrm_state *x, int mtu)
284 mtu = ALIGN(mtu + 2, 4) + blksize - 4; 284 mtu = ALIGN(mtu + 2, 4) + blksize - 4;
285 break; 285 break;
286 case XFRM_MODE_BEET: 286 case XFRM_MODE_BEET:
287 /* The worst case. */ 287 /* The worst case. */
288 enclen = IPV4_BEET_PHMAXLEN; 288 enclen = IPV4_BEET_PHMAXLEN;
289 mtu = ALIGN(mtu + enclen + 2, blksize); 289 mtu = ALIGN(mtu + enclen + 2, blksize);
290 break; 290 break;
diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
index d47b72af89ed..64f31e63db7f 100644
--- a/net/ipv4/fib_frontend.c
+++ b/net/ipv4/fib_frontend.c
@@ -160,7 +160,7 @@ unsigned inet_addr_type(__be32 addr)
160#ifdef CONFIG_IP_MULTIPLE_TABLES 160#ifdef CONFIG_IP_MULTIPLE_TABLES
161 res.r = NULL; 161 res.r = NULL;
162#endif 162#endif
163 163
164 if (ip_fib_local_table) { 164 if (ip_fib_local_table) {
165 ret = RTN_UNICAST; 165 ret = RTN_UNICAST;
166 if (!ip_fib_local_table->tb_lookup(ip_fib_local_table, 166 if (!ip_fib_local_table->tb_lookup(ip_fib_local_table,
@@ -378,7 +378,7 @@ static int rtentry_to_fib_config(int cmd, struct rtentry *rt,
378 int len = 0; 378 int len = 0;
379 379
380 mx = kzalloc(3 * nla_total_size(4), GFP_KERNEL); 380 mx = kzalloc(3 * nla_total_size(4), GFP_KERNEL);
381 if (mx == NULL) 381 if (mx == NULL)
382 return -ENOMEM; 382 return -ENOMEM;
383 383
384 if (rt->rt_flags & RTF_MTU) 384 if (rt->rt_flags & RTF_MTU)
@@ -400,7 +400,7 @@ static int rtentry_to_fib_config(int cmd, struct rtentry *rt,
400/* 400/*
401 * Handle IP routing ioctl calls. These are used to manipulate the routing tables 401 * Handle IP routing ioctl calls. These are used to manipulate the routing tables
402 */ 402 */
403 403
404int ip_rt_ioctl(unsigned int cmd, void __user *arg) 404int ip_rt_ioctl(unsigned int cmd, void __user *arg)
405{ 405{
406 struct fib_config cfg; 406 struct fib_config cfg;
@@ -600,7 +600,7 @@ int inet_dump_fib(struct sk_buff *skb, struct netlink_callback *cb)
600 goto next; 600 goto next;
601 if (dumped) 601 if (dumped)
602 memset(&cb->args[2], 0, sizeof(cb->args) - 602 memset(&cb->args[2], 0, sizeof(cb->args) -
603 2 * sizeof(cb->args[0])); 603 2 * sizeof(cb->args[0]));
604 if (tb->tb_dump(tb, skb, cb) < 0) 604 if (tb->tb_dump(tb, skb, cb) < 0)
605 goto out; 605 goto out;
606 dumped = 1; 606 dumped = 1;
@@ -766,7 +766,7 @@ static void fib_del_ifaddr(struct in_ifaddr *ifa)
766 766
767static void nl_fib_lookup(struct fib_result_nl *frn, struct fib_table *tb ) 767static void nl_fib_lookup(struct fib_result_nl *frn, struct fib_table *tb )
768{ 768{
769 769
770 struct fib_result res; 770 struct fib_result res;
771 struct flowi fl = { .mark = frn->fl_mark, 771 struct flowi fl = { .mark = frn->fl_mark,
772 .nl_u = { .ip4_u = { .daddr = frn->fl_addr, 772 .nl_u = { .ip4_u = { .daddr = frn->fl_addr,
@@ -791,11 +791,11 @@ static void nl_fib_lookup(struct fib_result_nl *frn, struct fib_table *tb )
791static void nl_fib_input(struct sock *sk, int len) 791static void nl_fib_input(struct sock *sk, int len)
792{ 792{
793 struct sk_buff *skb = NULL; 793 struct sk_buff *skb = NULL;
794 struct nlmsghdr *nlh = NULL; 794 struct nlmsghdr *nlh = NULL;
795 struct fib_result_nl *frn; 795 struct fib_result_nl *frn;
796 u32 pid; 796 u32 pid;
797 struct fib_table *tb; 797 struct fib_table *tb;
798 798
799 skb = skb_dequeue(&sk->sk_receive_queue); 799 skb = skb_dequeue(&sk->sk_receive_queue);
800 nlh = (struct nlmsghdr *)skb->data; 800 nlh = (struct nlmsghdr *)skb->data;
801 if (skb->len < NLMSG_SPACE(0) || skb->len < nlh->nlmsg_len || 801 if (skb->len < NLMSG_SPACE(0) || skb->len < nlh->nlmsg_len ||
@@ -803,17 +803,17 @@ static void nl_fib_input(struct sock *sk, int len)
803 kfree_skb(skb); 803 kfree_skb(skb);
804 return; 804 return;
805 } 805 }
806 806
807 frn = (struct fib_result_nl *) NLMSG_DATA(nlh); 807 frn = (struct fib_result_nl *) NLMSG_DATA(nlh);
808 tb = fib_get_table(frn->tb_id_in); 808 tb = fib_get_table(frn->tb_id_in);
809 809
810 nl_fib_lookup(frn, tb); 810 nl_fib_lookup(frn, tb);
811 811
812 pid = nlh->nlmsg_pid; /*pid of sending process */ 812 pid = nlh->nlmsg_pid; /*pid of sending process */
813 NETLINK_CB(skb).pid = 0; /* from kernel */ 813 NETLINK_CB(skb).pid = 0; /* from kernel */
814 NETLINK_CB(skb).dst_group = 0; /* unicast */ 814 NETLINK_CB(skb).dst_group = 0; /* unicast */
815 netlink_unicast(sk, skb, pid, MSG_DONTWAIT); 815 netlink_unicast(sk, skb, pid, MSG_DONTWAIT);
816} 816}
817 817
818static void nl_fib_lookup_init(void) 818static void nl_fib_lookup_init(void)
819{ 819{
diff --git a/net/ipv4/fib_hash.c b/net/ipv4/fib_hash.c
index 648f47c1c399..b21bb28d1fd0 100644
--- a/net/ipv4/fib_hash.c
+++ b/net/ipv4/fib_hash.c
@@ -146,7 +146,7 @@ static void fn_rehash_zone(struct fn_zone *fz)
146 struct hlist_head *ht, *old_ht; 146 struct hlist_head *ht, *old_ht;
147 int old_divisor, new_divisor; 147 int old_divisor, new_divisor;
148 u32 new_hashmask; 148 u32 new_hashmask;
149 149
150 old_divisor = fz->fz_divisor; 150 old_divisor = fz->fz_divisor;
151 151
152 switch (old_divisor) { 152 switch (old_divisor) {
@@ -911,7 +911,7 @@ static struct fib_alias *fib_get_next(struct seq_file *seq)
911 911
912 if (!iter->zone) 912 if (!iter->zone)
913 goto out; 913 goto out;
914 914
915 iter->bucket = 0; 915 iter->bucket = 0;
916 iter->hash_head = iter->zone->fz_hash; 916 iter->hash_head = iter->zone->fz_hash;
917 917
@@ -932,7 +932,7 @@ static struct fib_alias *fib_get_idx(struct seq_file *seq, loff_t pos)
932{ 932{
933 struct fib_iter_state *iter = seq->private; 933 struct fib_iter_state *iter = seq->private;
934 struct fib_alias *fa; 934 struct fib_alias *fa;
935 935
936 if (iter->valid && pos >= iter->pos && iter->genid == fib_hash_genid) { 936 if (iter->valid && pos >= iter->pos && iter->genid == fib_hash_genid) {
937 fa = iter->fa; 937 fa = iter->fa;
938 pos -= iter->pos; 938 pos -= iter->pos;
@@ -981,7 +981,7 @@ static unsigned fib_flag_trans(int type, __be32 mask, struct fib_info *fi)
981 return flags; 981 return flags;
982} 982}
983 983
984/* 984/*
985 * This outputs /proc/net/route. 985 * This outputs /proc/net/route.
986 * 986 *
987 * It always works in backward compatibility mode. 987 * It always works in backward compatibility mode.
@@ -1040,7 +1040,7 @@ static int fib_seq_open(struct inode *inode, struct file *file)
1040 struct seq_file *seq; 1040 struct seq_file *seq;
1041 int rc = -ENOMEM; 1041 int rc = -ENOMEM;
1042 struct fib_iter_state *s = kzalloc(sizeof(*s), GFP_KERNEL); 1042 struct fib_iter_state *s = kzalloc(sizeof(*s), GFP_KERNEL);
1043 1043
1044 if (!s) 1044 if (!s)
1045 goto out; 1045 goto out;
1046 1046
@@ -1057,7 +1057,7 @@ out_kfree:
1057 goto out; 1057 goto out;
1058} 1058}
1059 1059
1060static struct file_operations fib_seq_fops = { 1060static const struct file_operations fib_seq_fops = {
1061 .owner = THIS_MODULE, 1061 .owner = THIS_MODULE,
1062 .open = fib_seq_open, 1062 .open = fib_seq_open,
1063 .read = seq_read, 1063 .read = seq_read,
diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
index e63b8a98fb4d..2f1fdae6efa6 100644
--- a/net/ipv4/fib_semantics.c
+++ b/net/ipv4/fib_semantics.c
@@ -85,12 +85,12 @@ for (nhsel=0; nhsel < 1; nhsel++)
85#define endfor_nexthops(fi) } 85#define endfor_nexthops(fi) }
86 86
87 87
88static const struct 88static const struct
89{ 89{
90 int error; 90 int error;
91 u8 scope; 91 u8 scope;
92} fib_props[RTA_MAX + 1] = { 92} fib_props[RTA_MAX + 1] = {
93 { 93 {
94 .error = 0, 94 .error = 0,
95 .scope = RT_SCOPE_NOWHERE, 95 .scope = RT_SCOPE_NOWHERE,
96 }, /* RTN_UNSPEC */ 96 }, /* RTN_UNSPEC */
@@ -314,9 +314,12 @@ void rtmsg_fib(int event, __be32 key, struct fib_alias *fa,
314 err = fib_dump_info(skb, info->pid, seq, event, tb_id, 314 err = fib_dump_info(skb, info->pid, seq, event, tb_id,
315 fa->fa_type, fa->fa_scope, key, dst_len, 315 fa->fa_type, fa->fa_scope, key, dst_len,
316 fa->fa_tos, fa->fa_info, 0); 316 fa->fa_tos, fa->fa_info, 0);
317 /* failure implies BUG in fib_nlmsg_size() */ 317 if (err < 0) {
318 BUG_ON(err < 0); 318 /* -EMSGSIZE implies BUG in fib_nlmsg_size() */
319 319 WARN_ON(err == -EMSGSIZE);
320 kfree_skb(skb);
321 goto errout;
322 }
320 err = rtnl_notify(skb, info->pid, RTNLGRP_IPV4_ROUTE, 323 err = rtnl_notify(skb, info->pid, RTNLGRP_IPV4_ROUTE,
321 info->nlh, GFP_KERNEL); 324 info->nlh, GFP_KERNEL);
322errout: 325errout:
@@ -436,7 +439,7 @@ int fib_nh_match(struct fib_config *cfg, struct fib_info *fi)
436 439
437 rtnh = cfg->fc_mp; 440 rtnh = cfg->fc_mp;
438 remaining = cfg->fc_mp_len; 441 remaining = cfg->fc_mp_len;
439 442
440 for_nexthops(fi) { 443 for_nexthops(fi) {
441 int attrlen; 444 int attrlen;
442 445
@@ -505,9 +508,9 @@ int fib_nh_match(struct fib_config *cfg, struct fib_info *fi)
505 Normally it looks as following. 508 Normally it looks as following.
506 509
507 {universe prefix} -> (gw, oif) [scope link] 510 {universe prefix} -> (gw, oif) [scope link]
508 | 511 |
509 |-> {link prefix} -> (gw, oif) [scope local] 512 |-> {link prefix} -> (gw, oif) [scope local]
510 | 513 |
511 |-> {local prefix} (terminal node) 514 |-> {local prefix} (terminal node)
512 */ 515 */
513 516
@@ -861,7 +864,7 @@ err_inval:
861 err = -EINVAL; 864 err = -EINVAL;
862 865
863failure: 866failure:
864 if (fi) { 867 if (fi) {
865 fi->fib_dead = 1; 868 fi->fib_dead = 1;
866 free_fib_info(fi); 869 free_fib_info(fi);
867 } 870 }
@@ -960,7 +963,7 @@ int fib_dump_info(struct sk_buff *skb, u32 pid, u32 seq, int event,
960 963
961 nlh = nlmsg_put(skb, pid, seq, event, sizeof(*rtm), flags); 964 nlh = nlmsg_put(skb, pid, seq, event, sizeof(*rtm), flags);
962 if (nlh == NULL) 965 if (nlh == NULL)
963 return -ENOBUFS; 966 return -EMSGSIZE;
964 967
965 rtm = nlmsg_data(nlh); 968 rtm = nlmsg_data(nlh);
966 rtm->rtm_family = AF_INET; 969 rtm->rtm_family = AF_INET;
@@ -1031,7 +1034,8 @@ int fib_dump_info(struct sk_buff *skb, u32 pid, u32 seq, int event,
1031 return nlmsg_end(skb, nlh); 1034 return nlmsg_end(skb, nlh);
1032 1035
1033nla_put_failure: 1036nla_put_failure:
1034 return nlmsg_cancel(skb, nlh); 1037 nlmsg_cancel(skb, nlh);
1038 return -EMSGSIZE;
1035} 1039}
1036 1040
1037/* 1041/*
@@ -1045,7 +1049,7 @@ int fib_sync_down(__be32 local, struct net_device *dev, int force)
1045{ 1049{
1046 int ret = 0; 1050 int ret = 0;
1047 int scope = RT_SCOPE_NOWHERE; 1051 int scope = RT_SCOPE_NOWHERE;
1048 1052
1049 if (force) 1053 if (force)
1050 scope = -1; 1054 scope = -1;
1051 1055
diff --git a/net/ipv4/fib_trie.c b/net/ipv4/fib_trie.c
index 1e589b91605e..c33dca073801 100644
--- a/net/ipv4/fib_trie.c
+++ b/net/ipv4/fib_trie.c
@@ -7,13 +7,13 @@
7 * Robert Olsson <robert.olsson@its.uu.se> Uppsala Universitet 7 * Robert Olsson <robert.olsson@its.uu.se> Uppsala Universitet
8 * & Swedish University of Agricultural Sciences. 8 * & Swedish University of Agricultural Sciences.
9 * 9 *
10 * Jens Laas <jens.laas@data.slu.se> Swedish University of 10 * Jens Laas <jens.laas@data.slu.se> Swedish University of
11 * Agricultural Sciences. 11 * Agricultural Sciences.
12 * 12 *
13 * Hans Liss <hans.liss@its.uu.se> Uppsala Universitet 13 * Hans Liss <hans.liss@its.uu.se> Uppsala Universitet
14 * 14 *
15 * This work is based on the LPC-trie which is originally descibed in: 15 * This work is based on the LPC-trie which is originally descibed in:
16 * 16 *
17 * An experimental study of compression methods for dynamic tries 17 * An experimental study of compression methods for dynamic tries
18 * Stefan Nilsson and Matti Tikkanen. Algorithmica, 33(1):19-33, 2002. 18 * Stefan Nilsson and Matti Tikkanen. Algorithmica, 33(1):19-33, 2002.
19 * http://www.nada.kth.se/~snilsson/public/papers/dyntrie2/ 19 * http://www.nada.kth.se/~snilsson/public/papers/dyntrie2/
@@ -224,34 +224,34 @@ static inline int tkey_mismatch(t_key a, int offset, t_key b)
224} 224}
225 225
226/* 226/*
227 To understand this stuff, an understanding of keys and all their bits is 227 To understand this stuff, an understanding of keys and all their bits is
228 necessary. Every node in the trie has a key associated with it, but not 228 necessary. Every node in the trie has a key associated with it, but not
229 all of the bits in that key are significant. 229 all of the bits in that key are significant.
230 230
231 Consider a node 'n' and its parent 'tp'. 231 Consider a node 'n' and its parent 'tp'.
232 232
233 If n is a leaf, every bit in its key is significant. Its presence is 233 If n is a leaf, every bit in its key is significant. Its presence is
234 necessitated by path compression, since during a tree traversal (when 234 necessitated by path compression, since during a tree traversal (when
235 searching for a leaf - unless we are doing an insertion) we will completely 235 searching for a leaf - unless we are doing an insertion) we will completely
236 ignore all skipped bits we encounter. Thus we need to verify, at the end of 236 ignore all skipped bits we encounter. Thus we need to verify, at the end of
237 a potentially successful search, that we have indeed been walking the 237 a potentially successful search, that we have indeed been walking the
238 correct key path. 238 correct key path.
239 239
240 Note that we can never "miss" the correct key in the tree if present by 240 Note that we can never "miss" the correct key in the tree if present by
241 following the wrong path. Path compression ensures that segments of the key 241 following the wrong path. Path compression ensures that segments of the key
242 that are the same for all keys with a given prefix are skipped, but the 242 that are the same for all keys with a given prefix are skipped, but the
243 skipped part *is* identical for each node in the subtrie below the skipped 243 skipped part *is* identical for each node in the subtrie below the skipped
244 bit! trie_insert() in this implementation takes care of that - note the 244 bit! trie_insert() in this implementation takes care of that - note the
245 call to tkey_sub_equals() in trie_insert(). 245 call to tkey_sub_equals() in trie_insert().
246 246
247 if n is an internal node - a 'tnode' here, the various parts of its key 247 if n is an internal node - a 'tnode' here, the various parts of its key
248 have many different meanings. 248 have many different meanings.
249 249
250 Example: 250 Example:
251 _________________________________________________________________ 251 _________________________________________________________________
252 | i | i | i | i | i | i | i | N | N | N | S | S | S | S | S | C | 252 | i | i | i | i | i | i | i | N | N | N | S | S | S | S | S | C |
253 ----------------------------------------------------------------- 253 -----------------------------------------------------------------
254 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 254 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
255 255
256 _________________________________________________________________ 256 _________________________________________________________________
257 | C | C | C | u | u | u | u | u | u | u | u | u | u | u | u | u | 257 | C | C | C | u | u | u | u | u | u | u | u | u | u | u | u | u |
@@ -263,23 +263,23 @@ static inline int tkey_mismatch(t_key a, int offset, t_key b)
263 n->pos = 15 263 n->pos = 15
264 n->bits = 4 264 n->bits = 4
265 265
266 First, let's just ignore the bits that come before the parent tp, that is 266 First, let's just ignore the bits that come before the parent tp, that is
267 the bits from 0 to (tp->pos-1). They are *known* but at this point we do 267 the bits from 0 to (tp->pos-1). They are *known* but at this point we do
268 not use them for anything. 268 not use them for anything.
269 269
270 The bits from (tp->pos) to (tp->pos + tp->bits - 1) - "N", above - are the 270 The bits from (tp->pos) to (tp->pos + tp->bits - 1) - "N", above - are the
271 index into the parent's child array. That is, they will be used to find 271 index into the parent's child array. That is, they will be used to find
272 'n' among tp's children. 272 'n' among tp's children.
273 273
274 The bits from (tp->pos + tp->bits) to (n->pos - 1) - "S" - are skipped bits 274 The bits from (tp->pos + tp->bits) to (n->pos - 1) - "S" - are skipped bits
275 for the node n. 275 for the node n.
276 276
277 All the bits we have seen so far are significant to the node n. The rest 277 All the bits we have seen so far are significant to the node n. The rest
278 of the bits are really not needed or indeed known in n->key. 278 of the bits are really not needed or indeed known in n->key.
279 279
280 The bits from (n->pos) to (n->pos + n->bits - 1) - "C" - are the index into 280 The bits from (n->pos) to (n->pos + n->bits - 1) - "C" - are the index into
281 n's child array, and will of course be different for each child. 281 n's child array, and will of course be different for each child.
282 282
283 283
284 The rest of the bits, from (n->pos + n->bits) onward, are completely unknown 284 The rest of the bits, from (n->pos + n->bits) onward, are completely unknown
285 at this point. 285 at this point.
@@ -294,7 +294,7 @@ static inline void check_tnode(const struct tnode *tn)
294static int halve_threshold = 25; 294static int halve_threshold = 25;
295static int inflate_threshold = 50; 295static int inflate_threshold = 50;
296static int halve_threshold_root = 15; 296static int halve_threshold_root = 15;
297static int inflate_threshold_root = 25; 297static int inflate_threshold_root = 25;
298 298
299 299
300static void __alias_free_mem(struct rcu_head *head) 300static void __alias_free_mem(struct rcu_head *head)
@@ -355,7 +355,7 @@ static inline void tnode_free(struct tnode *tn)
355 struct leaf *l = (struct leaf *) tn; 355 struct leaf *l = (struct leaf *) tn;
356 call_rcu_bh(&l->rcu, __leaf_free_rcu); 356 call_rcu_bh(&l->rcu, __leaf_free_rcu);
357 } 357 }
358 else 358 else
359 call_rcu(&tn->rcu, __tnode_free_rcu); 359 call_rcu(&tn->rcu, __tnode_free_rcu);
360} 360}
361 361
@@ -461,7 +461,7 @@ static struct node *resize(struct trie *t, struct tnode *tn)
461 int inflate_threshold_use; 461 int inflate_threshold_use;
462 int halve_threshold_use; 462 int halve_threshold_use;
463 463
464 if (!tn) 464 if (!tn)
465 return NULL; 465 return NULL;
466 466
467 pr_debug("In tnode_resize %p inflate_threshold=%d threshold=%d\n", 467 pr_debug("In tnode_resize %p inflate_threshold=%d threshold=%d\n",
@@ -556,7 +556,7 @@ static struct node *resize(struct trie *t, struct tnode *tn)
556 556
557 if(!tn->parent) 557 if(!tn->parent)
558 inflate_threshold_use = inflate_threshold_root; 558 inflate_threshold_use = inflate_threshold_root;
559 else 559 else
560 inflate_threshold_use = inflate_threshold; 560 inflate_threshold_use = inflate_threshold;
561 561
562 err = 0; 562 err = 0;
@@ -587,7 +587,7 @@ static struct node *resize(struct trie *t, struct tnode *tn)
587 587
588 if(!tn->parent) 588 if(!tn->parent)
589 halve_threshold_use = halve_threshold_root; 589 halve_threshold_use = halve_threshold_root;
590 else 590 else
591 halve_threshold_use = halve_threshold; 591 halve_threshold_use = halve_threshold;
592 592
593 err = 0; 593 err = 0;
@@ -665,10 +665,10 @@ static struct tnode *inflate(struct trie *t, struct tnode *tn)
665 right = tnode_new(inode->key|m, inode->pos + 1, 665 right = tnode_new(inode->key|m, inode->pos + 1,
666 inode->bits - 1); 666 inode->bits - 1);
667 667
668 if (!right) { 668 if (!right) {
669 tnode_free(left); 669 tnode_free(left);
670 goto nomem; 670 goto nomem;
671 } 671 }
672 672
673 put_child(t, tn, 2*i, (struct node *) left); 673 put_child(t, tn, 2*i, (struct node *) left);
674 put_child(t, tn, 2*i+1, (struct node *) right); 674 put_child(t, tn, 2*i+1, (struct node *) right);
@@ -890,23 +890,23 @@ static inline struct list_head * get_fa_head(struct leaf *l, int plen)
890 890
891static void insert_leaf_info(struct hlist_head *head, struct leaf_info *new) 891static void insert_leaf_info(struct hlist_head *head, struct leaf_info *new)
892{ 892{
893 struct leaf_info *li = NULL, *last = NULL; 893 struct leaf_info *li = NULL, *last = NULL;
894 struct hlist_node *node; 894 struct hlist_node *node;
895 895
896 if (hlist_empty(head)) { 896 if (hlist_empty(head)) {
897 hlist_add_head_rcu(&new->hlist, head); 897 hlist_add_head_rcu(&new->hlist, head);
898 } else { 898 } else {
899 hlist_for_each_entry(li, node, head, hlist) { 899 hlist_for_each_entry(li, node, head, hlist) {
900 if (new->plen > li->plen) 900 if (new->plen > li->plen)
901 break; 901 break;
902 902
903 last = li; 903 last = li;
904 } 904 }
905 if (last) 905 if (last)
906 hlist_add_after_rcu(&last->hlist, &new->hlist); 906 hlist_add_after_rcu(&last->hlist, &new->hlist);
907 else 907 else
908 hlist_add_before_rcu(&new->hlist, &li->hlist); 908 hlist_add_before_rcu(&new->hlist, &li->hlist);
909 } 909 }
910} 910}
911 911
912/* rcu_read_lock needs to be hold by caller from readside */ 912/* rcu_read_lock needs to be hold by caller from readside */
@@ -1700,7 +1700,7 @@ static struct leaf *nextleaf(struct trie *t, struct leaf *thisleaf)
1700 /* Decend if tnode */ 1700 /* Decend if tnode */
1701 while (IS_TNODE(c)) { 1701 while (IS_TNODE(c)) {
1702 p = (struct tnode *) c; 1702 p = (struct tnode *) c;
1703 idx = 0; 1703 idx = 0;
1704 1704
1705 /* Rightmost non-NULL branch */ 1705 /* Rightmost non-NULL branch */
1706 if (p && IS_TNODE(p)) 1706 if (p && IS_TNODE(p))
@@ -2173,7 +2173,7 @@ static int fib_triestat_seq_open(struct inode *inode, struct file *file)
2173 return single_open(file, fib_triestat_seq_show, NULL); 2173 return single_open(file, fib_triestat_seq_show, NULL);
2174} 2174}
2175 2175
2176static struct file_operations fib_triestat_fops = { 2176static const struct file_operations fib_triestat_fops = {
2177 .owner = THIS_MODULE, 2177 .owner = THIS_MODULE,
2178 .open = fib_triestat_seq_open, 2178 .open = fib_triestat_seq_open,
2179 .read = seq_read, 2179 .read = seq_read,
@@ -2303,9 +2303,9 @@ static int fib_trie_seq_show(struct seq_file *seq, void *v)
2303 2303
2304 seq_indent(seq, iter->depth-1); 2304 seq_indent(seq, iter->depth-1);
2305 seq_printf(seq, " +-- %d.%d.%d.%d/%d %d %d %d\n", 2305 seq_printf(seq, " +-- %d.%d.%d.%d/%d %d %d %d\n",
2306 NIPQUAD(prf), tn->pos, tn->bits, tn->full_children, 2306 NIPQUAD(prf), tn->pos, tn->bits, tn->full_children,
2307 tn->empty_children); 2307 tn->empty_children);
2308 2308
2309 } else { 2309 } else {
2310 struct leaf *l = (struct leaf *) n; 2310 struct leaf *l = (struct leaf *) n;
2311 int i; 2311 int i;
@@ -2364,7 +2364,7 @@ out_kfree:
2364 goto out; 2364 goto out;
2365} 2365}
2366 2366
2367static struct file_operations fib_trie_fops = { 2367static const struct file_operations fib_trie_fops = {
2368 .owner = THIS_MODULE, 2368 .owner = THIS_MODULE,
2369 .open = fib_trie_seq_open, 2369 .open = fib_trie_seq_open,
2370 .read = seq_read, 2370 .read = seq_read,
@@ -2485,7 +2485,7 @@ out_kfree:
2485 goto out; 2485 goto out;
2486} 2486}
2487 2487
2488static struct file_operations fib_route_fops = { 2488static const struct file_operations fib_route_fops = {
2489 .owner = THIS_MODULE, 2489 .owner = THIS_MODULE,
2490 .open = fib_route_seq_open, 2490 .open = fib_route_seq_open,
2491 .read = seq_read, 2491 .read = seq_read,
diff --git a/net/ipv4/icmp.c b/net/ipv4/icmp.c
index 40cf0d0e1b83..4b7a0d946a0d 100644
--- a/net/ipv4/icmp.c
+++ b/net/ipv4/icmp.c
@@ -304,7 +304,7 @@ static inline int icmpv4_xrlim_allow(struct rtable *rt, int type, int code)
304 304
305 /* No rate limit on loopback */ 305 /* No rate limit on loopback */
306 if (dst->dev && (dst->dev->flags&IFF_LOOPBACK)) 306 if (dst->dev && (dst->dev->flags&IFF_LOOPBACK))
307 goto out; 307 goto out;
308 308
309 /* Limit if icmp type is enabled in ratemask. */ 309 /* Limit if icmp type is enabled in ratemask. */
310 if ((1 << type) & sysctl_icmp_ratemask) 310 if ((1 << type) & sysctl_icmp_ratemask)
@@ -350,9 +350,9 @@ static void icmp_push_reply(struct icmp_bxm *icmp_param,
350 struct sk_buff *skb; 350 struct sk_buff *skb;
351 351
352 if (ip_append_data(icmp_socket->sk, icmp_glue_bits, icmp_param, 352 if (ip_append_data(icmp_socket->sk, icmp_glue_bits, icmp_param,
353 icmp_param->data_len+icmp_param->head_len, 353 icmp_param->data_len+icmp_param->head_len,
354 icmp_param->head_len, 354 icmp_param->head_len,
355 ipc, rt, MSG_DONTWAIT) < 0) 355 ipc, rt, MSG_DONTWAIT) < 0)
356 ip_flush_pending_frames(icmp_socket->sk); 356 ip_flush_pending_frames(icmp_socket->sk);
357 else if ((skb = skb_peek(&icmp_socket->sk->sk_write_queue)) != NULL) { 357 else if ((skb = skb_peek(&icmp_socket->sk->sk_write_queue)) != NULL) {
358 struct icmphdr *icmph = skb->h.icmph; 358 struct icmphdr *icmph = skb->h.icmph;
@@ -755,7 +755,7 @@ static void icmp_redirect(struct sk_buff *skb)
755 skb->h.icmph->un.gateway, 755 skb->h.icmph->un.gateway,
756 iph->saddr, skb->dev); 756 iph->saddr, skb->dev);
757 break; 757 break;
758 } 758 }
759out: 759out:
760 return; 760 return;
761out_err: 761out_err:
@@ -959,7 +959,7 @@ int icmp_rcv(struct sk_buff *skb)
959 * Parse the ICMP message 959 * Parse the ICMP message
960 */ 960 */
961 961
962 if (rt->rt_flags & (RTCF_BROADCAST | RTCF_MULTICAST)) { 962 if (rt->rt_flags & (RTCF_BROADCAST | RTCF_MULTICAST)) {
963 /* 963 /*
964 * RFC 1122: 3.2.2.6 An ICMP_ECHO to broadcast MAY be 964 * RFC 1122: 3.2.2.6 An ICMP_ECHO to broadcast MAY be
965 * silently ignored (we let user decide with a sysctl). 965 * silently ignored (we let user decide with a sysctl).
@@ -976,7 +976,7 @@ int icmp_rcv(struct sk_buff *skb)
976 icmph->type != ICMP_ADDRESS && 976 icmph->type != ICMP_ADDRESS &&
977 icmph->type != ICMP_ADDRESSREPLY) { 977 icmph->type != ICMP_ADDRESSREPLY) {
978 goto error; 978 goto error;
979 } 979 }
980 } 980 }
981 981
982 ICMP_INC_STATS_BH(icmp_pointers[icmph->type].input_entry); 982 ICMP_INC_STATS_BH(icmp_pointers[icmph->type].input_entry);
@@ -1085,7 +1085,7 @@ static const struct icmp_control icmp_pointers[NR_ICMP_TYPES + 1] = {
1085 .input_entry = ICMP_MIB_DUMMY, 1085 .input_entry = ICMP_MIB_DUMMY,
1086 .handler = icmp_discard, 1086 .handler = icmp_discard,
1087 }, 1087 },
1088 [ICMP_INFO_REPLY] = { 1088 [ICMP_INFO_REPLY] = {
1089 .output_entry = ICMP_MIB_DUMMY, 1089 .output_entry = ICMP_MIB_DUMMY,
1090 .input_entry = ICMP_MIB_DUMMY, 1090 .input_entry = ICMP_MIB_DUMMY,
1091 .handler = icmp_discard, 1091 .handler = icmp_discard,
diff --git a/net/ipv4/igmp.c b/net/ipv4/igmp.c
index 0017ccb01d6d..063721302ebf 100644
--- a/net/ipv4/igmp.c
+++ b/net/ipv4/igmp.c
@@ -35,7 +35,7 @@
35 * 35 *
36 * Chih-Jen Chang : Tried to revise IGMP to Version 2 36 * Chih-Jen Chang : Tried to revise IGMP to Version 2
37 * Tsu-Sheng Tsao E-mail: chihjenc@scf.usc.edu and tsusheng@scf.usc.edu 37 * Tsu-Sheng Tsao E-mail: chihjenc@scf.usc.edu and tsusheng@scf.usc.edu
38 * The enhancements are mainly based on Steve Deering's 38 * The enhancements are mainly based on Steve Deering's
39 * ipmulti-3.5 source code. 39 * ipmulti-3.5 source code.
40 * Chih-Jen Chang : Added the igmp_get_mrouter_info and 40 * Chih-Jen Chang : Added the igmp_get_mrouter_info and
41 * Tsu-Sheng Tsao igmp_set_mrouter_info to keep track of 41 * Tsu-Sheng Tsao igmp_set_mrouter_info to keep track of
@@ -49,11 +49,11 @@
49 * Alan Cox : Stop IGMP from 0.0.0.0 being accepted. 49 * Alan Cox : Stop IGMP from 0.0.0.0 being accepted.
50 * Alan Cox : Use GFP_ATOMIC in the right places. 50 * Alan Cox : Use GFP_ATOMIC in the right places.
51 * Christian Daudt : igmp timer wasn't set for local group 51 * Christian Daudt : igmp timer wasn't set for local group
52 * memberships but was being deleted, 52 * memberships but was being deleted,
53 * which caused a "del_timer() called 53 * which caused a "del_timer() called
54 * from %p with timer not initialized\n" 54 * from %p with timer not initialized\n"
55 * message (960131). 55 * message (960131).
56 * Christian Daudt : removed del_timer from 56 * Christian Daudt : removed del_timer from
57 * igmp_timer_expire function (960205). 57 * igmp_timer_expire function (960205).
58 * Christian Daudt : igmp_heard_report now only calls 58 * Christian Daudt : igmp_heard_report now only calls
59 * igmp_timer_expire if tm->running is 59 * igmp_timer_expire if tm->running is
@@ -455,6 +455,8 @@ static struct sk_buff *add_grec(struct sk_buff *skb, struct ip_mc_list *pmc,
455 skb = add_grhead(skb, pmc, type, &pgr); 455 skb = add_grhead(skb, pmc, type, &pgr);
456 first = 0; 456 first = 0;
457 } 457 }
458 if (!skb)
459 return NULL;
458 psrc = (__be32 *)skb_put(skb, sizeof(__be32)); 460 psrc = (__be32 *)skb_put(skb, sizeof(__be32));
459 *psrc = psf->sf_inaddr; 461 *psrc = psf->sf_inaddr;
460 scount++; stotal++; 462 scount++; stotal++;
@@ -716,7 +718,7 @@ static void igmp_ifc_event(struct in_device *in_dev)
716{ 718{
717 if (IGMP_V1_SEEN(in_dev) || IGMP_V2_SEEN(in_dev)) 719 if (IGMP_V1_SEEN(in_dev) || IGMP_V2_SEEN(in_dev))
718 return; 720 return;
719 in_dev->mr_ifc_count = in_dev->mr_qrv ? in_dev->mr_qrv : 721 in_dev->mr_ifc_count = in_dev->mr_qrv ? in_dev->mr_qrv :
720 IGMP_Unsolicited_Report_Count; 722 IGMP_Unsolicited_Report_Count;
721 igmp_ifc_start_timer(in_dev, 1); 723 igmp_ifc_start_timer(in_dev, 1);
722} 724}
@@ -836,7 +838,7 @@ static void igmp_heard_query(struct in_device *in_dev, struct sk_buff *skb,
836 if (len == 8) { 838 if (len == 8) {
837 if (ih->code == 0) { 839 if (ih->code == 0) {
838 /* Alas, old v1 router presents here. */ 840 /* Alas, old v1 router presents here. */
839 841
840 max_delay = IGMP_Query_Response_Interval; 842 max_delay = IGMP_Query_Response_Interval;
841 in_dev->mr_v1_seen = jiffies + 843 in_dev->mr_v1_seen = jiffies +
842 IGMP_V1_Router_Present_Timeout; 844 IGMP_V1_Router_Present_Timeout;
@@ -858,10 +860,10 @@ static void igmp_heard_query(struct in_device *in_dev, struct sk_buff *skb,
858 } else { /* v3 */ 860 } else { /* v3 */
859 if (!pskb_may_pull(skb, sizeof(struct igmpv3_query))) 861 if (!pskb_may_pull(skb, sizeof(struct igmpv3_query)))
860 return; 862 return;
861 863
862 ih3 = (struct igmpv3_query *) skb->h.raw; 864 ih3 = (struct igmpv3_query *) skb->h.raw;
863 if (ih3->nsrcs) { 865 if (ih3->nsrcs) {
864 if (!pskb_may_pull(skb, sizeof(struct igmpv3_query) 866 if (!pskb_may_pull(skb, sizeof(struct igmpv3_query)
865 + ntohs(ih3->nsrcs)*sizeof(__be32))) 867 + ntohs(ih3->nsrcs)*sizeof(__be32)))
866 return; 868 return;
867 ih3 = (struct igmpv3_query *) skb->h.raw; 869 ih3 = (struct igmpv3_query *) skb->h.raw;
@@ -907,7 +909,7 @@ static void igmp_heard_query(struct in_device *in_dev, struct sk_buff *skb,
907 else 909 else
908 im->gsquery = mark; 910 im->gsquery = mark;
909 changed = !im->gsquery || 911 changed = !im->gsquery ||
910 igmp_marksources(im, ntohs(ih3->nsrcs), ih3->srcs); 912 igmp_marksources(im, ntohs(ih3->nsrcs), ih3->srcs);
911 spin_unlock_bh(&im->lock); 913 spin_unlock_bh(&im->lock);
912 if (changed) 914 if (changed)
913 igmp_mod_timer(im, max_delay); 915 igmp_mod_timer(im, max_delay);
@@ -1255,9 +1257,9 @@ out:
1255void ip_mc_dec_group(struct in_device *in_dev, __be32 addr) 1257void ip_mc_dec_group(struct in_device *in_dev, __be32 addr)
1256{ 1258{
1257 struct ip_mc_list *i, **ip; 1259 struct ip_mc_list *i, **ip;
1258 1260
1259 ASSERT_RTNL(); 1261 ASSERT_RTNL();
1260 1262
1261 for (ip=&in_dev->mc_list; (i=*ip)!=NULL; ip=&i->next) { 1263 for (ip=&in_dev->mc_list; (i=*ip)!=NULL; ip=&i->next) {
1262 if (i->multiaddr==addr) { 1264 if (i->multiaddr==addr) {
1263 if (--i->users == 0) { 1265 if (--i->users == 0) {
@@ -1434,7 +1436,7 @@ static int ip_mc_del1_src(struct ip_mc_list *pmc, int sfmode,
1434#ifdef CONFIG_IP_MULTICAST 1436#ifdef CONFIG_IP_MULTICAST
1435 if (psf->sf_oldin && 1437 if (psf->sf_oldin &&
1436 !IGMP_V1_SEEN(in_dev) && !IGMP_V2_SEEN(in_dev)) { 1438 !IGMP_V1_SEEN(in_dev) && !IGMP_V2_SEEN(in_dev)) {
1437 psf->sf_crcount = in_dev->mr_qrv ? in_dev->mr_qrv : 1439 psf->sf_crcount = in_dev->mr_qrv ? in_dev->mr_qrv :
1438 IGMP_Unsolicited_Report_Count; 1440 IGMP_Unsolicited_Report_Count;
1439 psf->sf_next = pmc->tomb; 1441 psf->sf_next = pmc->tomb;
1440 pmc->tomb = psf; 1442 pmc->tomb = psf;
@@ -1498,7 +1500,7 @@ static int ip_mc_del_src(struct in_device *in_dev, __be32 *pmca, int sfmode,
1498 /* filter mode change */ 1500 /* filter mode change */
1499 pmc->sfmode = MCAST_INCLUDE; 1501 pmc->sfmode = MCAST_INCLUDE;
1500#ifdef CONFIG_IP_MULTICAST 1502#ifdef CONFIG_IP_MULTICAST
1501 pmc->crcount = in_dev->mr_qrv ? in_dev->mr_qrv : 1503 pmc->crcount = in_dev->mr_qrv ? in_dev->mr_qrv :
1502 IGMP_Unsolicited_Report_Count; 1504 IGMP_Unsolicited_Report_Count;
1503 in_dev->mr_ifc_count = pmc->crcount; 1505 in_dev->mr_ifc_count = pmc->crcount;
1504 for (psf=pmc->sources; psf; psf = psf->sf_next) 1506 for (psf=pmc->sources; psf; psf = psf->sf_next)
@@ -1677,7 +1679,7 @@ static int ip_mc_add_src(struct in_device *in_dev, __be32 *pmca, int sfmode,
1677#ifdef CONFIG_IP_MULTICAST 1679#ifdef CONFIG_IP_MULTICAST
1678 /* else no filters; keep old mode for reports */ 1680 /* else no filters; keep old mode for reports */
1679 1681
1680 pmc->crcount = in_dev->mr_qrv ? in_dev->mr_qrv : 1682 pmc->crcount = in_dev->mr_qrv ? in_dev->mr_qrv :
1681 IGMP_Unsolicited_Report_Count; 1683 IGMP_Unsolicited_Report_Count;
1682 in_dev->mr_ifc_count = pmc->crcount; 1684 in_dev->mr_ifc_count = pmc->crcount;
1683 for (psf=pmc->sources; psf; psf = psf->sf_next) 1685 for (psf=pmc->sources; psf; psf = psf->sf_next)
@@ -1871,7 +1873,7 @@ int ip_mc_source(int add, int omode, struct sock *sk, struct
1871 } else if (pmc->sfmode != omode) { 1873 } else if (pmc->sfmode != omode) {
1872 /* allow mode switches for empty-set filters */ 1874 /* allow mode switches for empty-set filters */
1873 ip_mc_add_src(in_dev, &mreqs->imr_multiaddr, omode, 0, NULL, 0); 1875 ip_mc_add_src(in_dev, &mreqs->imr_multiaddr, omode, 0, NULL, 0);
1874 ip_mc_del_src(in_dev, &mreqs->imr_multiaddr, pmc->sfmode, 0, 1876 ip_mc_del_src(in_dev, &mreqs->imr_multiaddr, pmc->sfmode, 0,
1875 NULL, 0); 1877 NULL, 0);
1876 pmc->sfmode = omode; 1878 pmc->sfmode = omode;
1877 } 1879 }
@@ -1897,7 +1899,7 @@ int ip_mc_source(int add, int omode, struct sock *sk, struct
1897 } 1899 }
1898 1900
1899 /* update the interface filter */ 1901 /* update the interface filter */
1900 ip_mc_del_src(in_dev, &mreqs->imr_multiaddr, omode, 1, 1902 ip_mc_del_src(in_dev, &mreqs->imr_multiaddr, omode, 1,
1901 &mreqs->imr_sourceaddr, 1); 1903 &mreqs->imr_sourceaddr, 1);
1902 1904
1903 for (j=i+1; j<psl->sl_count; j++) 1905 for (j=i+1; j<psl->sl_count; j++)
@@ -1947,7 +1949,7 @@ int ip_mc_source(int add, int omode, struct sock *sk, struct
1947 psl->sl_count++; 1949 psl->sl_count++;
1948 err = 0; 1950 err = 0;
1949 /* update the interface list */ 1951 /* update the interface list */
1950 ip_mc_add_src(in_dev, &mreqs->imr_multiaddr, omode, 1, 1952 ip_mc_add_src(in_dev, &mreqs->imr_multiaddr, omode, 1,
1951 &mreqs->imr_sourceaddr, 1); 1953 &mreqs->imr_sourceaddr, 1);
1952done: 1954done:
1953 rtnl_unlock(); 1955 rtnl_unlock();
@@ -2262,7 +2264,7 @@ static inline struct ip_mc_list *igmp_mc_get_first(struct seq_file *seq)
2262 struct igmp_mc_iter_state *state = igmp_mc_seq_private(seq); 2264 struct igmp_mc_iter_state *state = igmp_mc_seq_private(seq);
2263 2265
2264 for (state->dev = dev_base, state->in_dev = NULL; 2266 for (state->dev = dev_base, state->in_dev = NULL;
2265 state->dev; 2267 state->dev;
2266 state->dev = state->dev->next) { 2268 state->dev = state->dev->next) {
2267 struct in_device *in_dev; 2269 struct in_device *in_dev;
2268 in_dev = in_dev_get(state->dev); 2270 in_dev = in_dev_get(state->dev);
@@ -2344,7 +2346,7 @@ static void igmp_mc_seq_stop(struct seq_file *seq, void *v)
2344static int igmp_mc_seq_show(struct seq_file *seq, void *v) 2346static int igmp_mc_seq_show(struct seq_file *seq, void *v)
2345{ 2347{
2346 if (v == SEQ_START_TOKEN) 2348 if (v == SEQ_START_TOKEN)
2347 seq_puts(seq, 2349 seq_puts(seq,
2348 "Idx\tDevice : Count Querier\tGroup Users Timer\tReporter\n"); 2350 "Idx\tDevice : Count Querier\tGroup Users Timer\tReporter\n");
2349 else { 2351 else {
2350 struct ip_mc_list *im = (struct ip_mc_list *)v; 2352 struct ip_mc_list *im = (struct ip_mc_list *)v;
@@ -2401,7 +2403,7 @@ out_kfree:
2401 goto out; 2403 goto out;
2402} 2404}
2403 2405
2404static struct file_operations igmp_mc_seq_fops = { 2406static const struct file_operations igmp_mc_seq_fops = {
2405 .owner = THIS_MODULE, 2407 .owner = THIS_MODULE,
2406 .open = igmp_mc_seq_open, 2408 .open = igmp_mc_seq_open,
2407 .read = seq_read, 2409 .read = seq_read,
@@ -2424,7 +2426,7 @@ static inline struct ip_sf_list *igmp_mcf_get_first(struct seq_file *seq)
2424 struct igmp_mcf_iter_state *state = igmp_mcf_seq_private(seq); 2426 struct igmp_mcf_iter_state *state = igmp_mcf_seq_private(seq);
2425 2427
2426 for (state->dev = dev_base, state->idev = NULL, state->im = NULL; 2428 for (state->dev = dev_base, state->idev = NULL, state->im = NULL;
2427 state->dev; 2429 state->dev;
2428 state->dev = state->dev->next) { 2430 state->dev = state->dev->next) {
2429 struct in_device *idev; 2431 struct in_device *idev;
2430 idev = in_dev_get(state->dev); 2432 idev = in_dev_get(state->dev);
@@ -2529,7 +2531,7 @@ static int igmp_mcf_seq_show(struct seq_file *seq, void *v)
2529 struct igmp_mcf_iter_state *state = igmp_mcf_seq_private(seq); 2531 struct igmp_mcf_iter_state *state = igmp_mcf_seq_private(seq);
2530 2532
2531 if (v == SEQ_START_TOKEN) { 2533 if (v == SEQ_START_TOKEN) {
2532 seq_printf(seq, 2534 seq_printf(seq,
2533 "%3s %6s " 2535 "%3s %6s "
2534 "%10s %10s %6s %6s\n", "Idx", 2536 "%10s %10s %6s %6s\n", "Idx",
2535 "Device", "MCA", 2537 "Device", "MCA",
@@ -2537,8 +2539,8 @@ static int igmp_mcf_seq_show(struct seq_file *seq, void *v)
2537 } else { 2539 } else {
2538 seq_printf(seq, 2540 seq_printf(seq,
2539 "%3d %6.6s 0x%08x " 2541 "%3d %6.6s 0x%08x "
2540 "0x%08x %6lu %6lu\n", 2542 "0x%08x %6lu %6lu\n",
2541 state->dev->ifindex, state->dev->name, 2543 state->dev->ifindex, state->dev->name,
2542 ntohl(state->im->multiaddr), 2544 ntohl(state->im->multiaddr),
2543 ntohl(psf->sf_inaddr), 2545 ntohl(psf->sf_inaddr),
2544 psf->sf_count[MCAST_INCLUDE], 2546 psf->sf_count[MCAST_INCLUDE],
@@ -2575,7 +2577,7 @@ out_kfree:
2575 goto out; 2577 goto out;
2576} 2578}
2577 2579
2578static struct file_operations igmp_mcf_seq_fops = { 2580static const struct file_operations igmp_mcf_seq_fops = {
2579 .owner = THIS_MODULE, 2581 .owner = THIS_MODULE,
2580 .open = igmp_mcf_seq_open, 2582 .open = igmp_mcf_seq_open,
2581 .read = seq_read, 2583 .read = seq_read,
diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
index 9d68837888d3..43fb1600f1f0 100644
--- a/net/ipv4/inet_connection_sock.c
+++ b/net/ipv4/inet_connection_sock.c
@@ -149,7 +149,7 @@ success:
149 if (!inet_csk(sk)->icsk_bind_hash) 149 if (!inet_csk(sk)->icsk_bind_hash)
150 inet_bind_hash(sk, tb, snum); 150 inet_bind_hash(sk, tb, snum);
151 BUG_TRAP(inet_csk(sk)->icsk_bind_hash == tb); 151 BUG_TRAP(inet_csk(sk)->icsk_bind_hash == tb);
152 ret = 0; 152 ret = 0;
153 153
154fail_unlock: 154fail_unlock:
155 spin_unlock(&head->lock); 155 spin_unlock(&head->lock);
@@ -255,7 +255,7 @@ EXPORT_SYMBOL(inet_csk_accept);
255 255
256/* 256/*
257 * Using different timers for retransmit, delayed acks and probes 257 * Using different timers for retransmit, delayed acks and probes
258 * We may wish use just one timer maintaining a list of expire jiffies 258 * We may wish use just one timer maintaining a list of expire jiffies
259 * to optimize. 259 * to optimize.
260 */ 260 */
261void inet_csk_init_xmit_timers(struct sock *sk, 261void inet_csk_init_xmit_timers(struct sock *sk,
@@ -273,7 +273,7 @@ void inet_csk_init_xmit_timers(struct sock *sk,
273 icsk->icsk_delack_timer.function = delack_handler; 273 icsk->icsk_delack_timer.function = delack_handler;
274 sk->sk_timer.function = keepalive_handler; 274 sk->sk_timer.function = keepalive_handler;
275 275
276 icsk->icsk_retransmit_timer.data = 276 icsk->icsk_retransmit_timer.data =
277 icsk->icsk_delack_timer.data = 277 icsk->icsk_delack_timer.data =
278 sk->sk_timer.data = (unsigned long)sk; 278 sk->sk_timer.data = (unsigned long)sk;
279 279
diff --git a/net/ipv4/inet_diag.c b/net/ipv4/inet_diag.c
index 77761ac4f7bb..5df71cd08da8 100644
--- a/net/ipv4/inet_diag.c
+++ b/net/ipv4/inet_diag.c
@@ -153,7 +153,7 @@ static int inet_csk_diag_fill(struct sock *sk,
153rtattr_failure: 153rtattr_failure:
154nlmsg_failure: 154nlmsg_failure:
155 skb_trim(skb, b - skb->data); 155 skb_trim(skb, b - skb->data);
156 return -1; 156 return -EMSGSIZE;
157} 157}
158 158
159static int inet_twsk_diag_fill(struct inet_timewait_sock *tw, 159static int inet_twsk_diag_fill(struct inet_timewait_sock *tw,
@@ -209,7 +209,7 @@ static int inet_twsk_diag_fill(struct inet_timewait_sock *tw,
209 return skb->len; 209 return skb->len;
210nlmsg_failure: 210nlmsg_failure:
211 skb_trim(skb, previous_tail - skb->data); 211 skb_trim(skb, previous_tail - skb->data);
212 return -1; 212 return -EMSGSIZE;
213} 213}
214 214
215static int sk_diag_fill(struct sock *sk, struct sk_buff *skb, 215static int sk_diag_fill(struct sock *sk, struct sk_buff *skb,
@@ -274,11 +274,14 @@ static int inet_diag_get_exact(struct sk_buff *in_skb,
274 if (!rep) 274 if (!rep)
275 goto out; 275 goto out;
276 276
277 if (sk_diag_fill(sk, rep, req->idiag_ext, 277 err = sk_diag_fill(sk, rep, req->idiag_ext,
278 NETLINK_CB(in_skb).pid, 278 NETLINK_CB(in_skb).pid,
279 nlh->nlmsg_seq, 0, nlh) <= 0) 279 nlh->nlmsg_seq, 0, nlh);
280 BUG(); 280 if (err < 0) {
281 281 WARN_ON(err == -EMSGSIZE);
282 kfree_skb(rep);
283 goto out;
284 }
282 err = netlink_unicast(idiagnl, rep, NETLINK_CB(in_skb).pid, 285 err = netlink_unicast(idiagnl, rep, NETLINK_CB(in_skb).pid,
283 MSG_DONTWAIT); 286 MSG_DONTWAIT);
284 if (err > 0) 287 if (err > 0)
@@ -378,7 +381,7 @@ static int inet_diag_bc_run(const void *bc, int len,
378 if (addr[0] == 0 && addr[1] == 0 && 381 if (addr[0] == 0 && addr[1] == 0 &&
379 addr[2] == htonl(0xffff) && 382 addr[2] == htonl(0xffff) &&
380 bitstring_match(addr + 3, cond->addr, 383 bitstring_match(addr + 3, cond->addr,
381 cond->prefix_len)) 384 cond->prefix_len))
382 break; 385 break;
383 } 386 }
384 yes = 0; 387 yes = 0;
@@ -515,7 +518,7 @@ static int inet_twsk_diag_dump(struct inet_timewait_sock *tw,
515 } 518 }
516 entry.sport = tw->tw_num; 519 entry.sport = tw->tw_num;
517 entry.dport = ntohs(tw->tw_dport); 520 entry.dport = ntohs(tw->tw_dport);
518 entry.userlocks = 0; 521 entry.userlocks = 0;
519 522
520 if (!inet_diag_bc_run(RTA_DATA(bc), RTA_PAYLOAD(bc), &entry)) 523 if (!inet_diag_bc_run(RTA_DATA(bc), RTA_PAYLOAD(bc), &entry))
521 return 0; 524 return 0;
@@ -775,7 +778,7 @@ next_normal:
775 struct inet_timewait_sock *tw; 778 struct inet_timewait_sock *tw;
776 779
777 inet_twsk_for_each(tw, node, 780 inet_twsk_for_each(tw, node,
778 &hashinfo->ehash[i + hashinfo->ehash_size].chain) { 781 &head->twchain) {
779 782
780 if (num < s_num) 783 if (num < s_num)
781 goto next_dying; 784 goto next_dying;
diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
index 8c79c8a4ea5c..fb662621c54e 100644
--- a/net/ipv4/inet_hashtables.c
+++ b/net/ipv4/inet_hashtables.c
@@ -212,7 +212,7 @@ static int __inet_check_established(struct inet_timewait_death_row *death_row,
212 write_lock(&head->lock); 212 write_lock(&head->lock);
213 213
214 /* Check TIME-WAIT sockets first. */ 214 /* Check TIME-WAIT sockets first. */
215 sk_for_each(sk2, node, &(head + hinfo->ehash_size)->chain) { 215 sk_for_each(sk2, node, &head->twchain) {
216 tw = inet_twsk(sk2); 216 tw = inet_twsk(sk2);
217 217
218 if (INET_TW_MATCH(sk2, hash, acookie, saddr, daddr, ports, dif)) { 218 if (INET_TW_MATCH(sk2, hash, acookie, saddr, daddr, ports, dif)) {
@@ -262,7 +262,7 @@ not_unique:
262static inline u32 inet_sk_port_offset(const struct sock *sk) 262static inline u32 inet_sk_port_offset(const struct sock *sk)
263{ 263{
264 const struct inet_sock *inet = inet_sk(sk); 264 const struct inet_sock *inet = inet_sk(sk);
265 return secure_ipv4_port_ephemeral(inet->rcv_saddr, inet->daddr, 265 return secure_ipv4_port_ephemeral(inet->rcv_saddr, inet->daddr,
266 inet->dport); 266 inet->dport);
267} 267}
268 268
@@ -274,81 +274,81 @@ int inet_hash_connect(struct inet_timewait_death_row *death_row,
274{ 274{
275 struct inet_hashinfo *hinfo = death_row->hashinfo; 275 struct inet_hashinfo *hinfo = death_row->hashinfo;
276 const unsigned short snum = inet_sk(sk)->num; 276 const unsigned short snum = inet_sk(sk)->num;
277 struct inet_bind_hashbucket *head; 277 struct inet_bind_hashbucket *head;
278 struct inet_bind_bucket *tb; 278 struct inet_bind_bucket *tb;
279 int ret; 279 int ret;
280 280
281 if (!snum) { 281 if (!snum) {
282 int low = sysctl_local_port_range[0]; 282 int low = sysctl_local_port_range[0];
283 int high = sysctl_local_port_range[1]; 283 int high = sysctl_local_port_range[1];
284 int range = high - low; 284 int range = high - low;
285 int i; 285 int i;
286 int port; 286 int port;
287 static u32 hint; 287 static u32 hint;
288 u32 offset = hint + inet_sk_port_offset(sk); 288 u32 offset = hint + inet_sk_port_offset(sk);
289 struct hlist_node *node; 289 struct hlist_node *node;
290 struct inet_timewait_sock *tw = NULL; 290 struct inet_timewait_sock *tw = NULL;
291 291
292 local_bh_disable(); 292 local_bh_disable();
293 for (i = 1; i <= range; i++) { 293 for (i = 1; i <= range; i++) {
294 port = low + (i + offset) % range; 294 port = low + (i + offset) % range;
295 head = &hinfo->bhash[inet_bhashfn(port, hinfo->bhash_size)]; 295 head = &hinfo->bhash[inet_bhashfn(port, hinfo->bhash_size)];
296 spin_lock(&head->lock); 296 spin_lock(&head->lock);
297 297
298 /* Does not bother with rcv_saddr checks, 298 /* Does not bother with rcv_saddr checks,
299 * because the established check is already 299 * because the established check is already
300 * unique enough. 300 * unique enough.
301 */ 301 */
302 inet_bind_bucket_for_each(tb, node, &head->chain) { 302 inet_bind_bucket_for_each(tb, node, &head->chain) {
303 if (tb->port == port) { 303 if (tb->port == port) {
304 BUG_TRAP(!hlist_empty(&tb->owners)); 304 BUG_TRAP(!hlist_empty(&tb->owners));
305 if (tb->fastreuse >= 0) 305 if (tb->fastreuse >= 0)
306 goto next_port; 306 goto next_port;
307 if (!__inet_check_established(death_row, 307 if (!__inet_check_established(death_row,
308 sk, port, 308 sk, port,
309 &tw)) 309 &tw))
310 goto ok; 310 goto ok;
311 goto next_port; 311 goto next_port;
312 } 312 }
313 } 313 }
314 314
315 tb = inet_bind_bucket_create(hinfo->bind_bucket_cachep, head, port); 315 tb = inet_bind_bucket_create(hinfo->bind_bucket_cachep, head, port);
316 if (!tb) { 316 if (!tb) {
317 spin_unlock(&head->lock); 317 spin_unlock(&head->lock);
318 break; 318 break;
319 } 319 }
320 tb->fastreuse = -1; 320 tb->fastreuse = -1;
321 goto ok; 321 goto ok;
322 322
323 next_port: 323 next_port:
324 spin_unlock(&head->lock); 324 spin_unlock(&head->lock);
325 } 325 }
326 local_bh_enable(); 326 local_bh_enable();
327 327
328 return -EADDRNOTAVAIL; 328 return -EADDRNOTAVAIL;
329 329
330ok: 330ok:
331 hint += i; 331 hint += i;
332 332
333 /* Head lock still held and bh's disabled */ 333 /* Head lock still held and bh's disabled */
334 inet_bind_hash(sk, tb, port); 334 inet_bind_hash(sk, tb, port);
335 if (sk_unhashed(sk)) { 335 if (sk_unhashed(sk)) {
336 inet_sk(sk)->sport = htons(port); 336 inet_sk(sk)->sport = htons(port);
337 __inet_hash(hinfo, sk, 0); 337 __inet_hash(hinfo, sk, 0);
338 } 338 }
339 spin_unlock(&head->lock); 339 spin_unlock(&head->lock);
340 340
341 if (tw) { 341 if (tw) {
342 inet_twsk_deschedule(tw, death_row); 342 inet_twsk_deschedule(tw, death_row);
343 inet_twsk_put(tw); 343 inet_twsk_put(tw);
344 } 344 }
345 345
346 ret = 0; 346 ret = 0;
347 goto out; 347 goto out;
348 } 348 }
349 349
350 head = &hinfo->bhash[inet_bhashfn(snum, hinfo->bhash_size)]; 350 head = &hinfo->bhash[inet_bhashfn(snum, hinfo->bhash_size)];
351 tb = inet_csk(sk)->icsk_bind_hash; 351 tb = inet_csk(sk)->icsk_bind_hash;
352 spin_lock_bh(&head->lock); 352 spin_lock_bh(&head->lock);
353 if (sk_head(&tb->owners) == sk && !sk->sk_bind_node.next) { 353 if (sk_head(&tb->owners) == sk && !sk->sk_bind_node.next) {
354 __inet_hash(hinfo, sk, 0); 354 __inet_hash(hinfo, sk, 0);
diff --git a/net/ipv4/inet_timewait_sock.c b/net/ipv4/inet_timewait_sock.c
index 9f414e35c488..a73cf93cee36 100644
--- a/net/ipv4/inet_timewait_sock.c
+++ b/net/ipv4/inet_timewait_sock.c
@@ -78,8 +78,8 @@ void __inet_twsk_hashdance(struct inet_timewait_sock *tw, struct sock *sk,
78 if (__sk_del_node_init(sk)) 78 if (__sk_del_node_init(sk))
79 sock_prot_dec_use(sk->sk_prot); 79 sock_prot_dec_use(sk->sk_prot);
80 80
81 /* Step 3: Hash TW into TIMEWAIT half of established hash table. */ 81 /* Step 3: Hash TW into TIMEWAIT chain. */
82 inet_twsk_add_node(tw, &(ehead + hashinfo->ehash_size)->chain); 82 inet_twsk_add_node(tw, &ehead->twchain);
83 atomic_inc(&tw->tw_refcnt); 83 atomic_inc(&tw->tw_refcnt);
84 84
85 write_unlock(&ehead->lock); 85 write_unlock(&ehead->lock);
diff --git a/net/ipv4/ip_forward.c b/net/ipv4/ip_forward.c
index a22d11d2911c..c3ea0cd2e584 100644
--- a/net/ipv4/ip_forward.c
+++ b/net/ipv4/ip_forward.c
@@ -4,15 +4,15 @@
4 * interface as the means of communication with the user level. 4 * interface as the means of communication with the user level.
5 * 5 *
6 * The IP forwarding functionality. 6 * The IP forwarding functionality.
7 * 7 *
8 * Version: $Id: ip_forward.c,v 1.48 2000/12/13 18:31:48 davem Exp $ 8 * Version: $Id: ip_forward.c,v 1.48 2000/12/13 18:31:48 davem Exp $
9 * 9 *
10 * Authors: see ip.c 10 * Authors: see ip.c
11 * 11 *
12 * Fixes: 12 * Fixes:
13 * Many : Split from ip.c , see ip_input.c for 13 * Many : Split from ip.c , see ip_input.c for
14 * history. 14 * history.
15 * Dave Gregorich : NULL ip_rt_put fix for multicast 15 * Dave Gregorich : NULL ip_rt_put fix for multicast
16 * routing. 16 * routing.
17 * Jos Vos : Add call_out_firewall before sending, 17 * Jos Vos : Add call_out_firewall before sending,
18 * use output device for accounting. 18 * use output device for accounting.
@@ -69,14 +69,14 @@ int ip_forward(struct sk_buff *skb)
69 goto drop; 69 goto drop;
70 70
71 skb->ip_summed = CHECKSUM_NONE; 71 skb->ip_summed = CHECKSUM_NONE;
72 72
73 /* 73 /*
74 * According to the RFC, we must first decrease the TTL field. If 74 * According to the RFC, we must first decrease the TTL field. If
75 * that reaches zero, we must reply an ICMP control message telling 75 * that reaches zero, we must reply an ICMP control message telling
76 * that the packet's lifetime expired. 76 * that the packet's lifetime expired.
77 */ 77 */
78 if (skb->nh.iph->ttl <= 1) 78 if (skb->nh.iph->ttl <= 1)
79 goto too_many_hops; 79 goto too_many_hops;
80 80
81 if (!xfrm4_route_forward(skb)) 81 if (!xfrm4_route_forward(skb))
82 goto drop; 82 goto drop;
@@ -107,16 +107,16 @@ int ip_forward(struct sk_buff *skb)
107 ip_forward_finish); 107 ip_forward_finish);
108 108
109sr_failed: 109sr_failed:
110 /* 110 /*
111 * Strict routing permits no gatewaying 111 * Strict routing permits no gatewaying
112 */ 112 */
113 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_SR_FAILED, 0); 113 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_SR_FAILED, 0);
114 goto drop; 114 goto drop;
115 115
116too_many_hops: 116too_many_hops:
117 /* Tell the sender its packet died... */ 117 /* Tell the sender its packet died... */
118 IP_INC_STATS_BH(IPSTATS_MIB_INHDRERRORS); 118 IP_INC_STATS_BH(IPSTATS_MIB_INHDRERRORS);
119 icmp_send(skb, ICMP_TIME_EXCEEDED, ICMP_EXC_TTL, 0); 119 icmp_send(skb, ICMP_TIME_EXCEEDED, ICMP_EXC_TTL, 0);
120drop: 120drop:
121 kfree_skb(skb); 121 kfree_skb(skb);
122 return NET_RX_DROP; 122 return NET_RX_DROP;
diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
index 8ce00d3703da..b6f055380373 100644
--- a/net/ipv4/ip_fragment.c
+++ b/net/ipv4/ip_fragment.c
@@ -4,7 +4,7 @@
4 * interface as the means of communication with the user level. 4 * interface as the means of communication with the user level.
5 * 5 *
6 * The IP fragmentation functionality. 6 * The IP fragmentation functionality.
7 * 7 *
8 * Version: $Id: ip_fragment.c,v 1.59 2002/01/12 07:54:56 davem Exp $ 8 * Version: $Id: ip_fragment.c,v 1.59 2002/01/12 07:54:56 davem Exp $
9 * 9 *
10 * Authors: Fred N. van Kempen <waltje@uWalt.NL.Mugnet.ORG> 10 * Authors: Fred N. van Kempen <waltje@uWalt.NL.Mugnet.ORG>
@@ -238,7 +238,7 @@ static void ipq_kill(struct ipq *ipq)
238 } 238 }
239} 239}
240 240
241/* Memory limiting on fragments. Evictor trashes the oldest 241/* Memory limiting on fragments. Evictor trashes the oldest
242 * fragment queue until we are back under the threshold. 242 * fragment queue until we are back under the threshold.
243 */ 243 */
244static void ip_evictor(void) 244static void ip_evictor(void)
@@ -479,14 +479,14 @@ static void ip_frag_queue(struct ipq *qp, struct sk_buff *skb)
479 goto err; 479 goto err;
480 } 480 }
481 481
482 offset = ntohs(skb->nh.iph->frag_off); 482 offset = ntohs(skb->nh.iph->frag_off);
483 flags = offset & ~IP_OFFSET; 483 flags = offset & ~IP_OFFSET;
484 offset &= IP_OFFSET; 484 offset &= IP_OFFSET;
485 offset <<= 3; /* offset is in 8-byte chunks */ 485 offset <<= 3; /* offset is in 8-byte chunks */
486 ihl = skb->nh.iph->ihl * 4; 486 ihl = skb->nh.iph->ihl * 4;
487 487
488 /* Determine the position of this fragment. */ 488 /* Determine the position of this fragment. */
489 end = offset + skb->len - ihl; 489 end = offset + skb->len - ihl;
490 490
491 /* Is this the final fragment? */ 491 /* Is this the final fragment? */
492 if ((flags & IP_MF) == 0) { 492 if ((flags & IP_MF) == 0) {
@@ -589,8 +589,8 @@ static void ip_frag_queue(struct ipq *qp, struct sk_buff *skb)
589 else 589 else
590 qp->fragments = skb; 590 qp->fragments = skb;
591 591
592 if (skb->dev) 592 if (skb->dev)
593 qp->iif = skb->dev->ifindex; 593 qp->iif = skb->dev->ifindex;
594 skb->dev = NULL; 594 skb->dev = NULL;
595 skb_get_timestamp(skb, &qp->stamp); 595 skb_get_timestamp(skb, &qp->stamp);
596 qp->meat += skb->len; 596 qp->meat += skb->len;
@@ -684,7 +684,7 @@ static struct sk_buff *ip_frag_reasm(struct ipq *qp, struct net_device *dev)
684 return head; 684 return head;
685 685
686out_nomem: 686out_nomem:
687 LIMIT_NETDEBUG(KERN_ERR "IP: queue_glue: no memory for gluing " 687 LIMIT_NETDEBUG(KERN_ERR "IP: queue_glue: no memory for gluing "
688 "queue %p\n", qp); 688 "queue %p\n", qp);
689 goto out_fail; 689 goto out_fail;
690out_oversize: 690out_oversize:
@@ -703,7 +703,7 @@ struct sk_buff *ip_defrag(struct sk_buff *skb, u32 user)
703 struct iphdr *iph = skb->nh.iph; 703 struct iphdr *iph = skb->nh.iph;
704 struct ipq *qp; 704 struct ipq *qp;
705 struct net_device *dev; 705 struct net_device *dev;
706 706
707 IP_INC_STATS_BH(IPSTATS_MIB_REASMREQDS); 707 IP_INC_STATS_BH(IPSTATS_MIB_REASMREQDS);
708 708
709 /* Start by cleaning up the memory. */ 709 /* Start by cleaning up the memory. */
diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
index 476cb6084c75..f12c0d6623a0 100644
--- a/net/ipv4/ip_gre.c
+++ b/net/ipv4/ip_gre.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * Linux NET3: GRE over IP protocol decoder. 2 * Linux NET3: GRE over IP protocol decoder.
3 * 3 *
4 * Authors: Alexey Kuznetsov (kuznet@ms2.inr.ac.ru) 4 * Authors: Alexey Kuznetsov (kuznet@ms2.inr.ac.ru)
5 * 5 *
@@ -63,7 +63,7 @@
63 solution, but it supposes maintaing new variable in ALL 63 solution, but it supposes maintaing new variable in ALL
64 skb, even if no tunneling is used. 64 skb, even if no tunneling is used.
65 65
66 Current solution: t->recursion lock breaks dead loops. It looks 66 Current solution: t->recursion lock breaks dead loops. It looks
67 like dev->tbusy flag, but I preferred new variable, because 67 like dev->tbusy flag, but I preferred new variable, because
68 the semantics is different. One day, when hard_start_xmit 68 the semantics is different. One day, when hard_start_xmit
69 will be multithreaded we will have to use skb->encapsulation. 69 will be multithreaded we will have to use skb->encapsulation.
@@ -613,7 +613,7 @@ static int ipgre_rcv(struct sk_buff *skb)
613 if (flags == 0 && 613 if (flags == 0 &&
614 skb->protocol == htons(ETH_P_WCCP)) { 614 skb->protocol == htons(ETH_P_WCCP)) {
615 skb->protocol = htons(ETH_P_IP); 615 skb->protocol = htons(ETH_P_IP);
616 if ((*(h + offset) & 0xF0) != 0x40) 616 if ((*(h + offset) & 0xF0) != 0x40)
617 offset += 4; 617 offset += 4;
618 } 618 }
619 619
@@ -816,7 +816,7 @@ static int ipgre_tunnel_xmit(struct sk_buff *skb, struct net_device *dev)
816 struct sk_buff *new_skb = skb_realloc_headroom(skb, max_headroom); 816 struct sk_buff *new_skb = skb_realloc_headroom(skb, max_headroom);
817 if (!new_skb) { 817 if (!new_skb) {
818 ip_rt_put(rt); 818 ip_rt_put(rt);
819 stats->tx_dropped++; 819 stats->tx_dropped++;
820 dev_kfree_skb(skb); 820 dev_kfree_skb(skb);
821 tunnel->recursion--; 821 tunnel->recursion--;
822 return 0; 822 return 0;
@@ -1008,7 +1008,8 @@ ipgre_tunnel_ioctl (struct net_device *dev, struct ifreq *ifr, int cmd)
1008 goto done; 1008 goto done;
1009 dev = t->dev; 1009 dev = t->dev;
1010 } 1010 }
1011 err = unregister_netdevice(dev); 1011 unregister_netdevice(dev);
1012 err = 0;
1012 break; 1013 break;
1013 1014
1014 default: 1015 default:
@@ -1043,7 +1044,7 @@ static int ipgre_tunnel_change_mtu(struct net_device *dev, int new_mtu)
1043 so that I had to set ARPHRD_IPGRE to a random value. 1044 so that I had to set ARPHRD_IPGRE to a random value.
1044 I have an impression, that Cisco could make something similar, 1045 I have an impression, that Cisco could make something similar,
1045 but this feature is apparently missing in IOS<=11.2(8). 1046 but this feature is apparently missing in IOS<=11.2(8).
1046 1047
1047 I set up 10.66.66/24 and fec0:6666:6666::0/96 as virtual networks 1048 I set up 10.66.66/24 and fec0:6666:6666::0/96 as virtual networks
1048 with broadcast 224.66.66.66. If you have access to mbone, play with me :-) 1049 with broadcast 224.66.66.66. If you have access to mbone, play with me :-)
1049 1050
@@ -1075,9 +1076,9 @@ static int ipgre_header(struct sk_buff *skb, struct net_device *dev, unsigned sh
1075 p[1] = htons(type); 1076 p[1] = htons(type);
1076 1077
1077 /* 1078 /*
1078 * Set the source hardware address. 1079 * Set the source hardware address.
1079 */ 1080 */
1080 1081
1081 if (saddr) 1082 if (saddr)
1082 memcpy(&iph->saddr, saddr, 4); 1083 memcpy(&iph->saddr, saddr, 4);
1083 1084
@@ -1087,7 +1088,7 @@ static int ipgre_header(struct sk_buff *skb, struct net_device *dev, unsigned sh
1087 } 1088 }
1088 if (iph->daddr && !MULTICAST(iph->daddr)) 1089 if (iph->daddr && !MULTICAST(iph->daddr))
1089 return t->hlen; 1090 return t->hlen;
1090 1091
1091 return -t->hlen; 1092 return -t->hlen;
1092} 1093}
1093 1094
diff --git a/net/ipv4/ip_input.c b/net/ipv4/ip_input.c
index 212734ca238f..f38e97647ac0 100644
--- a/net/ipv4/ip_input.c
+++ b/net/ipv4/ip_input.c
@@ -15,7 +15,7 @@
15 * Stefan Becker, <stefanb@yello.ping.de> 15 * Stefan Becker, <stefanb@yello.ping.de>
16 * Jorge Cwik, <jorge@laser.satlink.net> 16 * Jorge Cwik, <jorge@laser.satlink.net>
17 * Arnt Gulbrandsen, <agulbra@nvg.unit.no> 17 * Arnt Gulbrandsen, <agulbra@nvg.unit.no>
18 * 18 *
19 * 19 *
20 * Fixes: 20 * Fixes:
21 * Alan Cox : Commented a couple of minor bits of surplus code 21 * Alan Cox : Commented a couple of minor bits of surplus code
@@ -98,13 +98,13 @@
98 * Jos Vos : Do accounting *before* call_in_firewall 98 * Jos Vos : Do accounting *before* call_in_firewall
99 * Willy Konynenberg : Transparent proxying support 99 * Willy Konynenberg : Transparent proxying support
100 * 100 *
101 * 101 *
102 * 102 *
103 * To Fix: 103 * To Fix:
104 * IP fragmentation wants rewriting cleanly. The RFC815 algorithm is much more efficient 104 * IP fragmentation wants rewriting cleanly. The RFC815 algorithm is much more efficient
105 * and could be made very efficient with the addition of some virtual memory hacks to permit 105 * and could be made very efficient with the addition of some virtual memory hacks to permit
106 * the allocation of a buffer that can then be 'grown' by twiddling page tables. 106 * the allocation of a buffer that can then be 'grown' by twiddling page tables.
107 * Output fragmentation wants updating along with the buffer management to use a single 107 * Output fragmentation wants updating along with the buffer management to use a single
108 * interleaved copy algorithm so that fragmenting has a one copy overhead. Actual packet 108 * interleaved copy algorithm so that fragmenting has a one copy overhead. Actual packet
109 * output should probably do its own fragmentation at the UDP/RAW layer. TCP shouldn't cause 109 * output should probably do its own fragmentation at the UDP/RAW layer. TCP shouldn't cause
110 * fragmentation anyway. 110 * fragmentation anyway.
@@ -154,7 +154,7 @@ DEFINE_SNMP_STAT(struct ipstats_mib, ip_statistics) __read_mostly;
154 154
155/* 155/*
156 * Process Router Attention IP option 156 * Process Router Attention IP option
157 */ 157 */
158int ip_call_ra_chain(struct sk_buff *skb) 158int ip_call_ra_chain(struct sk_buff *skb)
159{ 159{
160 struct ip_ra_chain *ra; 160 struct ip_ra_chain *ra;
@@ -202,8 +202,8 @@ static inline int ip_local_deliver_finish(struct sk_buff *skb)
202 202
203 __skb_pull(skb, ihl); 203 __skb_pull(skb, ihl);
204 204
205 /* Point into the IP datagram, just past the header. */ 205 /* Point into the IP datagram, just past the header. */
206 skb->h.raw = skb->data; 206 skb->h.raw = skb->data;
207 207
208 rcu_read_lock(); 208 rcu_read_lock();
209 { 209 {
@@ -259,7 +259,7 @@ static inline int ip_local_deliver_finish(struct sk_buff *skb)
259 259
260/* 260/*
261 * Deliver IP Packets to the higher protocol layers. 261 * Deliver IP Packets to the higher protocol layers.
262 */ 262 */
263int ip_local_deliver(struct sk_buff *skb) 263int ip_local_deliver(struct sk_buff *skb)
264{ 264{
265 /* 265 /*
@@ -335,14 +335,14 @@ static inline int ip_rcv_finish(struct sk_buff *skb)
335 /* 335 /*
336 * Initialise the virtual path cache for the packet. It describes 336 * Initialise the virtual path cache for the packet. It describes
337 * how the packet travels inside Linux networking. 337 * how the packet travels inside Linux networking.
338 */ 338 */
339 if (skb->dst == NULL) { 339 if (skb->dst == NULL) {
340 int err = ip_route_input(skb, iph->daddr, iph->saddr, iph->tos, 340 int err = ip_route_input(skb, iph->daddr, iph->saddr, iph->tos,
341 skb->dev); 341 skb->dev);
342 if (unlikely(err)) { 342 if (unlikely(err)) {
343 if (err == -EHOSTUNREACH) 343 if (err == -EHOSTUNREACH)
344 IP_INC_STATS_BH(IPSTATS_MIB_INADDRERRORS); 344 IP_INC_STATS_BH(IPSTATS_MIB_INADDRERRORS);
345 goto drop; 345 goto drop;
346 } 346 }
347 } 347 }
348 348
@@ -363,13 +363,13 @@ static inline int ip_rcv_finish(struct sk_buff *skb)
363 return dst_input(skb); 363 return dst_input(skb);
364 364
365drop: 365drop:
366 kfree_skb(skb); 366 kfree_skb(skb);
367 return NET_RX_DROP; 367 return NET_RX_DROP;
368} 368}
369 369
370/* 370/*
371 * Main IP Receive routine. 371 * Main IP Receive routine.
372 */ 372 */
373int ip_rcv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt, struct net_device *orig_dev) 373int ip_rcv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt, struct net_device *orig_dev)
374{ 374{
375 struct iphdr *iph; 375 struct iphdr *iph;
@@ -437,9 +437,9 @@ int ip_rcv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt,
437inhdr_error: 437inhdr_error:
438 IP_INC_STATS_BH(IPSTATS_MIB_INHDRERRORS); 438 IP_INC_STATS_BH(IPSTATS_MIB_INHDRERRORS);
439drop: 439drop:
440 kfree_skb(skb); 440 kfree_skb(skb);
441out: 441out:
442 return NET_RX_DROP; 442 return NET_RX_DROP;
443} 443}
444 444
445EXPORT_SYMBOL(ip_statistics); 445EXPORT_SYMBOL(ip_statistics);
diff --git a/net/ipv4/ip_options.c b/net/ipv4/ip_options.c
index 9f02917d6f45..f906a80d5a87 100644
--- a/net/ipv4/ip_options.c
+++ b/net/ipv4/ip_options.c
@@ -8,7 +8,7 @@
8 * Version: $Id: ip_options.c,v 1.21 2001/09/01 00:31:50 davem Exp $ 8 * Version: $Id: ip_options.c,v 1.21 2001/09/01 00:31:50 davem Exp $
9 * 9 *
10 * Authors: A.N.Kuznetsov 10 * Authors: A.N.Kuznetsov
11 * 11 *
12 */ 12 */
13 13
14#include <linux/capability.h> 14#include <linux/capability.h>
@@ -26,7 +26,7 @@
26#include <net/route.h> 26#include <net/route.h>
27#include <net/cipso_ipv4.h> 27#include <net/cipso_ipv4.h>
28 28
29/* 29/*
30 * Write options to IP header, record destination address to 30 * Write options to IP header, record destination address to
31 * source route option, address of outgoing interface 31 * source route option, address of outgoing interface
32 * (we should already know it, so that this function is allowed be 32 * (we should already know it, so that this function is allowed be
@@ -76,7 +76,7 @@ void ip_options_build(struct sk_buff * skb, struct ip_options * opt,
76 } 76 }
77} 77}
78 78
79/* 79/*
80 * Provided (sopt, skb) points to received options, 80 * Provided (sopt, skb) points to received options,
81 * build in dopt compiled option set appropriate for answering. 81 * build in dopt compiled option set appropriate for answering.
82 * i.e. invert SRR option, copy anothers, 82 * i.e. invert SRR option, copy anothers,
@@ -85,7 +85,7 @@ void ip_options_build(struct sk_buff * skb, struct ip_options * opt,
85 * NOTE: dopt cannot point to skb. 85 * NOTE: dopt cannot point to skb.
86 */ 86 */
87 87
88int ip_options_echo(struct ip_options * dopt, struct sk_buff * skb) 88int ip_options_echo(struct ip_options * dopt, struct sk_buff * skb)
89{ 89{
90 struct ip_options *sopt; 90 struct ip_options *sopt;
91 unsigned char *sptr, *dptr; 91 unsigned char *sptr, *dptr;
@@ -215,7 +215,7 @@ int ip_options_echo(struct ip_options * dopt, struct sk_buff * skb)
215 * Simple and stupid 8), but the most efficient way. 215 * Simple and stupid 8), but the most efficient way.
216 */ 216 */
217 217
218void ip_options_fragment(struct sk_buff * skb) 218void ip_options_fragment(struct sk_buff * skb)
219{ 219{
220 unsigned char * optptr = skb->nh.raw + sizeof(struct iphdr); 220 unsigned char * optptr = skb->nh.raw + sizeof(struct iphdr);
221 struct ip_options * opt = &(IPCB(skb)->opt); 221 struct ip_options * opt = &(IPCB(skb)->opt);
@@ -370,7 +370,7 @@ int ip_options_compile(struct ip_options * opt, struct sk_buff * skb)
370 switch (optptr[3]&0xF) { 370 switch (optptr[3]&0xF) {
371 case IPOPT_TS_TSONLY: 371 case IPOPT_TS_TSONLY:
372 opt->ts = optptr - iph; 372 opt->ts = optptr - iph;
373 if (skb) 373 if (skb)
374 timeptr = (__be32*)&optptr[optptr[2]-1]; 374 timeptr = (__be32*)&optptr[optptr[2]-1];
375 opt->ts_needtime = 1; 375 opt->ts_needtime = 1;
376 optptr[2] += 4; 376 optptr[2] += 4;
@@ -448,7 +448,7 @@ int ip_options_compile(struct ip_options * opt, struct sk_buff * skb)
448 goto error; 448 goto error;
449 } 449 }
450 opt->cipso = optptr - iph; 450 opt->cipso = optptr - iph;
451 if (cipso_v4_validate(&optptr)) { 451 if (cipso_v4_validate(&optptr)) {
452 pp_ptr = optptr; 452 pp_ptr = optptr;
453 goto error; 453 goto error;
454 } 454 }
diff --git a/net/ipv4/ip_output.c b/net/ipv4/ip_output.c
index a0f2008584bc..bb0bb8f07c54 100644
--- a/net/ipv4/ip_output.c
+++ b/net/ipv4/ip_output.c
@@ -22,7 +22,7 @@
22 * Fixes: 22 * Fixes:
23 * Alan Cox : Missing nonblock feature in ip_build_xmit. 23 * Alan Cox : Missing nonblock feature in ip_build_xmit.
24 * Mike Kilburn : htons() missing in ip_build_xmit. 24 * Mike Kilburn : htons() missing in ip_build_xmit.
25 * Bradford Johnson: Fix faulty handling of some frames when 25 * Bradford Johnson: Fix faulty handling of some frames when
26 * no route is found. 26 * no route is found.
27 * Alexander Demenshin: Missing sk/skb free in ip_queue_xmit 27 * Alexander Demenshin: Missing sk/skb free in ip_queue_xmit
28 * (in case if packet not accepted by 28 * (in case if packet not accepted by
@@ -33,9 +33,9 @@
33 * some redundant tests. 33 * some redundant tests.
34 * Vitaly E. Lavrov : Transparent proxy revived after year coma. 34 * Vitaly E. Lavrov : Transparent proxy revived after year coma.
35 * Andi Kleen : Replace ip_reply with ip_send_reply. 35 * Andi Kleen : Replace ip_reply with ip_send_reply.
36 * Andi Kleen : Split fast and slow ip_build_xmit path 36 * Andi Kleen : Split fast and slow ip_build_xmit path
37 * for decreased register pressure on x86 37 * for decreased register pressure on x86
38 * and more readibility. 38 * and more readibility.
39 * Marc Boucher : When call_out_firewall returns FW_QUEUE, 39 * Marc Boucher : When call_out_firewall returns FW_QUEUE,
40 * silently drop skb instead of failing with -EPERM. 40 * silently drop skb instead of failing with -EPERM.
41 * Detlev Wengorz : Copy protocol for fragments. 41 * Detlev Wengorz : Copy protocol for fragments.
@@ -114,7 +114,7 @@ static inline int ip_select_ttl(struct inet_sock *inet, struct dst_entry *dst)
114 return ttl; 114 return ttl;
115} 115}
116 116
117/* 117/*
118 * Add an ip header to a skbuff and send it out. 118 * Add an ip header to a skbuff and send it out.
119 * 119 *
120 */ 120 */
@@ -243,7 +243,7 @@ int ip_mc_output(struct sk_buff *skb)
243 struct sk_buff *newskb = skb_clone(skb, GFP_ATOMIC); 243 struct sk_buff *newskb = skb_clone(skb, GFP_ATOMIC);
244 if (newskb) 244 if (newskb)
245 NF_HOOK(PF_INET, NF_IP_POST_ROUTING, newskb, NULL, 245 NF_HOOK(PF_INET, NF_IP_POST_ROUTING, newskb, NULL,
246 newskb->dev, 246 newskb->dev,
247 ip_dev_loopback_xmit); 247 ip_dev_loopback_xmit);
248 } 248 }
249 249
@@ -277,7 +277,7 @@ int ip_output(struct sk_buff *skb)
277 skb->protocol = htons(ETH_P_IP); 277 skb->protocol = htons(ETH_P_IP);
278 278
279 return NF_HOOK_COND(PF_INET, NF_IP_POST_ROUTING, skb, NULL, dev, 279 return NF_HOOK_COND(PF_INET, NF_IP_POST_ROUTING, skb, NULL, dev,
280 ip_finish_output, 280 ip_finish_output,
281 !(IPCB(skb)->flags & IPSKB_REROUTED)); 281 !(IPCB(skb)->flags & IPSKB_REROUTED));
282} 282}
283 283
@@ -660,7 +660,7 @@ slow_path:
660 return err; 660 return err;
661 661
662fail: 662fail:
663 kfree_skb(skb); 663 kfree_skb(skb);
664 IP_INC_STATS(IPSTATS_MIB_FRAGFAILS); 664 IP_INC_STATS(IPSTATS_MIB_FRAGFAILS);
665 return err; 665 return err;
666} 666}
@@ -755,7 +755,7 @@ static inline int ip_ufo_append_data(struct sock *sk,
755 * from many pieces of data. Each pieces will be holded on the socket 755 * from many pieces of data. Each pieces will be holded on the socket
756 * until ip_push_pending_frames() is called. Each piece can be a page 756 * until ip_push_pending_frames() is called. Each piece can be a page
757 * or non-page data. 757 * or non-page data.
758 * 758 *
759 * Not only UDP, other transport protocols - e.g. raw sockets - can use 759 * Not only UDP, other transport protocols - e.g. raw sockets - can use
760 * this interface potentially. 760 * this interface potentially.
761 * 761 *
@@ -888,7 +888,7 @@ alloc_new_skb:
888 datalen = maxfraglen - fragheaderlen; 888 datalen = maxfraglen - fragheaderlen;
889 fraglen = datalen + fragheaderlen; 889 fraglen = datalen + fragheaderlen;
890 890
891 if ((flags & MSG_MORE) && 891 if ((flags & MSG_MORE) &&
892 !(rt->u.dst.dev->features&NETIF_F_SG)) 892 !(rt->u.dst.dev->features&NETIF_F_SG))
893 alloclen = mtu; 893 alloclen = mtu;
894 else 894 else
@@ -903,14 +903,14 @@ alloc_new_skb:
903 alloclen += rt->u.dst.trailer_len; 903 alloclen += rt->u.dst.trailer_len;
904 904
905 if (transhdrlen) { 905 if (transhdrlen) {
906 skb = sock_alloc_send_skb(sk, 906 skb = sock_alloc_send_skb(sk,
907 alloclen + hh_len + 15, 907 alloclen + hh_len + 15,
908 (flags & MSG_DONTWAIT), &err); 908 (flags & MSG_DONTWAIT), &err);
909 } else { 909 } else {
910 skb = NULL; 910 skb = NULL;
911 if (atomic_read(&sk->sk_wmem_alloc) <= 911 if (atomic_read(&sk->sk_wmem_alloc) <=
912 2 * sk->sk_sndbuf) 912 2 * sk->sk_sndbuf)
913 skb = sock_wmalloc(sk, 913 skb = sock_wmalloc(sk,
914 alloclen + hh_len + 15, 1, 914 alloclen + hh_len + 15, 1,
915 sk->sk_allocation); 915 sk->sk_allocation);
916 if (unlikely(skb == NULL)) 916 if (unlikely(skb == NULL))
@@ -971,7 +971,7 @@ alloc_new_skb:
971 unsigned int off; 971 unsigned int off;
972 972
973 off = skb->len; 973 off = skb->len;
974 if (getfrag(from, skb_put(skb, copy), 974 if (getfrag(from, skb_put(skb, copy),
975 offset, copy, off, skb) < 0) { 975 offset, copy, off, skb) < 0) {
976 __skb_trim(skb, off); 976 __skb_trim(skb, off);
977 err = -EFAULT; 977 err = -EFAULT;
@@ -993,7 +993,7 @@ alloc_new_skb:
993 goto error; 993 goto error;
994 } 994 }
995 get_page(page); 995 get_page(page);
996 skb_fill_page_desc(skb, i, page, sk->sk_sndmsg_off, 0); 996 skb_fill_page_desc(skb, i, page, sk->sk_sndmsg_off, 0);
997 frag = &skb_shinfo(skb)->frags[i]; 997 frag = &skb_shinfo(skb)->frags[i];
998 } 998 }
999 } else if (i < MAX_SKB_FRAGS) { 999 } else if (i < MAX_SKB_FRAGS) {
@@ -1033,7 +1033,7 @@ alloc_new_skb:
1033error: 1033error:
1034 inet->cork.length -= length; 1034 inet->cork.length -= length;
1035 IP_INC_STATS(IPSTATS_MIB_OUTDISCARDS); 1035 IP_INC_STATS(IPSTATS_MIB_OUTDISCARDS);
1036 return err; 1036 return err;
1037} 1037}
1038 1038
1039ssize_t ip_append_page(struct sock *sk, struct page *page, 1039ssize_t ip_append_page(struct sock *sk, struct page *page,
@@ -1257,7 +1257,7 @@ int ip_push_pending_frames(struct sock *sk)
1257 skb->dst = dst_clone(&rt->u.dst); 1257 skb->dst = dst_clone(&rt->u.dst);
1258 1258
1259 /* Netfilter gets whole the not fragmented skb. */ 1259 /* Netfilter gets whole the not fragmented skb. */
1260 err = NF_HOOK(PF_INET, NF_IP_LOCAL_OUT, skb, NULL, 1260 err = NF_HOOK(PF_INET, NF_IP_LOCAL_OUT, skb, NULL,
1261 skb->dst->dev, dst_output); 1261 skb->dst->dev, dst_output);
1262 if (err) { 1262 if (err) {
1263 if (err > 0) 1263 if (err > 0)
@@ -1305,21 +1305,21 @@ void ip_flush_pending_frames(struct sock *sk)
1305/* 1305/*
1306 * Fetch data from kernel space and fill in checksum if needed. 1306 * Fetch data from kernel space and fill in checksum if needed.
1307 */ 1307 */
1308static int ip_reply_glue_bits(void *dptr, char *to, int offset, 1308static int ip_reply_glue_bits(void *dptr, char *to, int offset,
1309 int len, int odd, struct sk_buff *skb) 1309 int len, int odd, struct sk_buff *skb)
1310{ 1310{
1311 __wsum csum; 1311 __wsum csum;
1312 1312
1313 csum = csum_partial_copy_nocheck(dptr+offset, to, len, 0); 1313 csum = csum_partial_copy_nocheck(dptr+offset, to, len, 0);
1314 skb->csum = csum_block_add(skb->csum, csum, odd); 1314 skb->csum = csum_block_add(skb->csum, csum, odd);
1315 return 0; 1315 return 0;
1316} 1316}
1317 1317
1318/* 1318/*
1319 * Generic function to send a packet as reply to another packet. 1319 * Generic function to send a packet as reply to another packet.
1320 * Used to send TCP resets so far. ICMP should use this function too. 1320 * Used to send TCP resets so far. ICMP should use this function too.
1321 * 1321 *
1322 * Should run single threaded per socket because it uses the sock 1322 * Should run single threaded per socket because it uses the sock
1323 * structure to pass arguments. 1323 * structure to pass arguments.
1324 * 1324 *
1325 * LATER: switch from ip_build_xmit to ip_append_* 1325 * LATER: switch from ip_build_xmit to ip_append_*
@@ -1357,7 +1357,7 @@ void ip_send_reply(struct sock *sk, struct sk_buff *skb, struct ip_reply_arg *ar
1357 /* Not quite clean, but right. */ 1357 /* Not quite clean, but right. */
1358 .uli_u = { .ports = 1358 .uli_u = { .ports =
1359 { .sport = skb->h.th->dest, 1359 { .sport = skb->h.th->dest,
1360 .dport = skb->h.th->source } }, 1360 .dport = skb->h.th->source } },
1361 .proto = sk->sk_protocol }; 1361 .proto = sk->sk_protocol };
1362 security_skb_classify_flow(skb, &fl); 1362 security_skb_classify_flow(skb, &fl);
1363 if (ip_route_output_key(&rt, &fl)) 1363 if (ip_route_output_key(&rt, &fl))
diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
index 57d4bae6f080..e120686c3cb8 100644
--- a/net/ipv4/ip_sockglue.c
+++ b/net/ipv4/ip_sockglue.c
@@ -4,7 +4,7 @@
4 * interface as the means of communication with the user level. 4 * interface as the means of communication with the user level.
5 * 5 *
6 * The IP to API glue. 6 * The IP to API glue.
7 * 7 *
8 * Version: $Id: ip_sockglue.c,v 1.62 2002/02/01 22:01:04 davem Exp $ 8 * Version: $Id: ip_sockglue.c,v 1.62 2002/02/01 22:01:04 davem Exp $
9 * 9 *
10 * Authors: see ip.c 10 * Authors: see ip.c
@@ -12,7 +12,7 @@
12 * Fixes: 12 * Fixes:
13 * Many : Split from ip.c , see ip.c for history. 13 * Many : Split from ip.c , see ip.c for history.
14 * Martin Mares : TOS setting fixed. 14 * Martin Mares : TOS setting fixed.
15 * Alan Cox : Fixed a couple of oopses in Martin's 15 * Alan Cox : Fixed a couple of oopses in Martin's
16 * TOS tweaks. 16 * TOS tweaks.
17 * Mike McLagan : Routing by source 17 * Mike McLagan : Routing by source
18 */ 18 */
@@ -253,7 +253,7 @@ int ip_ra_control(struct sock *sk, unsigned char on, void (*destructor)(struct s
253 return 0; 253 return 0;
254} 254}
255 255
256void ip_icmp_error(struct sock *sk, struct sk_buff *skb, int err, 256void ip_icmp_error(struct sock *sk, struct sk_buff *skb, int err,
257 __be16 port, u32 info, u8 *payload) 257 __be16 port, u32 info, u8 *payload)
258{ 258{
259 struct inet_sock *inet = inet_sk(sk); 259 struct inet_sock *inet = inet_sk(sk);
@@ -266,10 +266,10 @@ void ip_icmp_error(struct sock *sk, struct sk_buff *skb, int err,
266 if (!skb) 266 if (!skb)
267 return; 267 return;
268 268
269 serr = SKB_EXT_ERR(skb); 269 serr = SKB_EXT_ERR(skb);
270 serr->ee.ee_errno = err; 270 serr->ee.ee_errno = err;
271 serr->ee.ee_origin = SO_EE_ORIGIN_ICMP; 271 serr->ee.ee_origin = SO_EE_ORIGIN_ICMP;
272 serr->ee.ee_type = skb->h.icmph->type; 272 serr->ee.ee_type = skb->h.icmph->type;
273 serr->ee.ee_code = skb->h.icmph->code; 273 serr->ee.ee_code = skb->h.icmph->code;
274 serr->ee.ee_pad = 0; 274 serr->ee.ee_pad = 0;
275 serr->ee.ee_info = info; 275 serr->ee.ee_info = info;
@@ -301,10 +301,10 @@ void ip_local_error(struct sock *sk, int err, __be32 daddr, __be16 port, u32 inf
301 skb->nh.iph = iph; 301 skb->nh.iph = iph;
302 iph->daddr = daddr; 302 iph->daddr = daddr;
303 303
304 serr = SKB_EXT_ERR(skb); 304 serr = SKB_EXT_ERR(skb);
305 serr->ee.ee_errno = err; 305 serr->ee.ee_errno = err;
306 serr->ee.ee_origin = SO_EE_ORIGIN_LOCAL; 306 serr->ee.ee_origin = SO_EE_ORIGIN_LOCAL;
307 serr->ee.ee_type = 0; 307 serr->ee.ee_type = 0;
308 serr->ee.ee_code = 0; 308 serr->ee.ee_code = 0;
309 serr->ee.ee_pad = 0; 309 serr->ee.ee_pad = 0;
310 serr->ee.ee_info = info; 310 serr->ee.ee_info = info;
@@ -319,7 +319,7 @@ void ip_local_error(struct sock *sk, int err, __be32 daddr, __be16 port, u32 inf
319 kfree_skb(skb); 319 kfree_skb(skb);
320} 320}
321 321
322/* 322/*
323 * Handle MSG_ERRQUEUE 323 * Handle MSG_ERRQUEUE
324 */ 324 */
325int ip_recv_error(struct sock *sk, struct msghdr *msg, int len) 325int ip_recv_error(struct sock *sk, struct msghdr *msg, int len)
@@ -391,7 +391,7 @@ int ip_recv_error(struct sock *sk, struct msghdr *msg, int len)
391 } else 391 } else
392 spin_unlock_bh(&sk->sk_error_queue.lock); 392 spin_unlock_bh(&sk->sk_error_queue.lock);
393 393
394out_free_skb: 394out_free_skb:
395 kfree_skb(skb); 395 kfree_skb(skb);
396out: 396out:
397 return err; 397 return err;
@@ -409,15 +409,15 @@ static int do_ip_setsockopt(struct sock *sk, int level,
409 struct inet_sock *inet = inet_sk(sk); 409 struct inet_sock *inet = inet_sk(sk);
410 int val=0,err; 410 int val=0,err;
411 411
412 if (((1<<optname) & ((1<<IP_PKTINFO) | (1<<IP_RECVTTL) | 412 if (((1<<optname) & ((1<<IP_PKTINFO) | (1<<IP_RECVTTL) |
413 (1<<IP_RECVOPTS) | (1<<IP_RECVTOS) | 413 (1<<IP_RECVOPTS) | (1<<IP_RECVTOS) |
414 (1<<IP_RETOPTS) | (1<<IP_TOS) | 414 (1<<IP_RETOPTS) | (1<<IP_TOS) |
415 (1<<IP_TTL) | (1<<IP_HDRINCL) | 415 (1<<IP_TTL) | (1<<IP_HDRINCL) |
416 (1<<IP_MTU_DISCOVER) | (1<<IP_RECVERR) | 416 (1<<IP_MTU_DISCOVER) | (1<<IP_RECVERR) |
417 (1<<IP_ROUTER_ALERT) | (1<<IP_FREEBIND) | 417 (1<<IP_ROUTER_ALERT) | (1<<IP_FREEBIND) |
418 (1<<IP_PASSSEC))) || 418 (1<<IP_PASSSEC))) ||
419 optname == IP_MULTICAST_TTL || 419 optname == IP_MULTICAST_TTL ||
420 optname == IP_MULTICAST_LOOP) { 420 optname == IP_MULTICAST_LOOP) {
421 if (optlen >= sizeof(int)) { 421 if (optlen >= sizeof(int)) {
422 if (get_user(val, (int __user *) optval)) 422 if (get_user(val, (int __user *) optval))
423 return -EFAULT; 423 return -EFAULT;
@@ -511,7 +511,7 @@ static int do_ip_setsockopt(struct sock *sk, int level,
511 val &= ~3; 511 val &= ~3;
512 val |= inet->tos & 3; 512 val |= inet->tos & 3;
513 } 513 }
514 if (IPTOS_PREC(val) >= IPTOS_PREC_CRITIC_ECP && 514 if (IPTOS_PREC(val) >= IPTOS_PREC_CRITIC_ECP &&
515 !capable(CAP_NET_ADMIN)) { 515 !capable(CAP_NET_ADMIN)) {
516 err = -EPERM; 516 err = -EPERM;
517 break; 517 break;
@@ -519,7 +519,7 @@ static int do_ip_setsockopt(struct sock *sk, int level,
519 if (inet->tos != val) { 519 if (inet->tos != val) {
520 inet->tos = val; 520 inet->tos = val;
521 sk->sk_priority = rt_tos2priority(val); 521 sk->sk_priority = rt_tos2priority(val);
522 sk_dst_reset(sk); 522 sk_dst_reset(sk);
523 } 523 }
524 break; 524 break;
525 case IP_TTL: 525 case IP_TTL:
@@ -556,13 +556,13 @@ static int do_ip_setsockopt(struct sock *sk, int level,
556 if (val < 0 || val > 255) 556 if (val < 0 || val > 255)
557 goto e_inval; 557 goto e_inval;
558 inet->mc_ttl = val; 558 inet->mc_ttl = val;
559 break; 559 break;
560 case IP_MULTICAST_LOOP: 560 case IP_MULTICAST_LOOP:
561 if (optlen<1) 561 if (optlen<1)
562 goto e_inval; 562 goto e_inval;
563 inet->mc_loop = !!val; 563 inet->mc_loop = !!val;
564 break; 564 break;
565 case IP_MULTICAST_IF: 565 case IP_MULTICAST_IF:
566 { 566 {
567 struct ip_mreqn mreq; 567 struct ip_mreqn mreq;
568 struct net_device *dev = NULL; 568 struct net_device *dev = NULL;
@@ -616,7 +616,7 @@ static int do_ip_setsockopt(struct sock *sk, int level,
616 } 616 }
617 617
618 case IP_ADD_MEMBERSHIP: 618 case IP_ADD_MEMBERSHIP:
619 case IP_DROP_MEMBERSHIP: 619 case IP_DROP_MEMBERSHIP:
620 { 620 {
621 struct ip_mreqn mreq; 621 struct ip_mreqn mreq;
622 622
@@ -629,7 +629,7 @@ static int do_ip_setsockopt(struct sock *sk, int level,
629 } else { 629 } else {
630 memset(&mreq, 0, sizeof(mreq)); 630 memset(&mreq, 0, sizeof(mreq));
631 if (copy_from_user(&mreq,optval,sizeof(struct ip_mreq))) 631 if (copy_from_user(&mreq,optval,sizeof(struct ip_mreq)))
632 break; 632 break;
633 } 633 }
634 634
635 if (optname == IP_ADD_MEMBERSHIP) 635 if (optname == IP_ADD_MEMBERSHIP)
@@ -714,7 +714,7 @@ static int do_ip_setsockopt(struct sock *sk, int level,
714 break; 714 break;
715 } 715 }
716 case MCAST_JOIN_GROUP: 716 case MCAST_JOIN_GROUP:
717 case MCAST_LEAVE_GROUP: 717 case MCAST_LEAVE_GROUP:
718 { 718 {
719 struct group_req greq; 719 struct group_req greq;
720 struct sockaddr_in *psin; 720 struct sockaddr_in *psin;
@@ -858,16 +858,16 @@ mc_msf_out:
858 kfree(gsf); 858 kfree(gsf);
859 break; 859 break;
860 } 860 }
861 case IP_ROUTER_ALERT: 861 case IP_ROUTER_ALERT:
862 err = ip_ra_control(sk, val ? 1 : 0, NULL); 862 err = ip_ra_control(sk, val ? 1 : 0, NULL);
863 break; 863 break;
864 864
865 case IP_FREEBIND: 865 case IP_FREEBIND:
866 if (optlen<1) 866 if (optlen<1)
867 goto e_inval; 867 goto e_inval;
868 inet->freebind = !!val; 868 inet->freebind = !!val;
869 break; 869 break;
870 870
871 case IP_IPSEC_POLICY: 871 case IP_IPSEC_POLICY:
872 case IP_XFRM_POLICY: 872 case IP_XFRM_POLICY:
873 err = -EPERM; 873 err = -EPERM;
@@ -954,7 +954,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
954 struct inet_sock *inet = inet_sk(sk); 954 struct inet_sock *inet = inet_sk(sk);
955 int val; 955 int val;
956 int len; 956 int len;
957 957
958 if(level!=SOL_IP) 958 if(level!=SOL_IP)
959 return -EOPNOTSUPP; 959 return -EOPNOTSUPP;
960 960
@@ -969,7 +969,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
969 return -EFAULT; 969 return -EFAULT;
970 if(len < 0) 970 if(len < 0)
971 return -EINVAL; 971 return -EINVAL;
972 972
973 lock_sock(sk); 973 lock_sock(sk);
974 974
975 switch(optname) { 975 switch(optname) {
@@ -984,7 +984,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
984 inet->opt->optlen); 984 inet->opt->optlen);
985 release_sock(sk); 985 release_sock(sk);
986 986
987 if (opt->optlen == 0) 987 if (opt->optlen == 0)
988 return put_user(0, optlen); 988 return put_user(0, optlen);
989 989
990 ip_options_undo(opt); 990 ip_options_undo(opt);
@@ -1059,8 +1059,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
1059 addr.s_addr = inet->mc_addr; 1059 addr.s_addr = inet->mc_addr;
1060 release_sock(sk); 1060 release_sock(sk);
1061 1061
1062 if(put_user(len, optlen)) 1062 if(put_user(len, optlen))
1063 return -EFAULT; 1063 return -EFAULT;
1064 if(copy_to_user(optval, &addr, len)) 1064 if(copy_to_user(optval, &addr, len))
1065 return -EFAULT; 1065 return -EFAULT;
1066 return 0; 1066 return 0;
@@ -1101,7 +1101,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
1101 release_sock(sk); 1101 release_sock(sk);
1102 return err; 1102 return err;
1103 } 1103 }
1104 case IP_PKTOPTIONS: 1104 case IP_PKTOPTIONS:
1105 { 1105 {
1106 struct msghdr msg; 1106 struct msghdr msg;
1107 1107
@@ -1129,15 +1129,15 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
1129 len -= msg.msg_controllen; 1129 len -= msg.msg_controllen;
1130 return put_user(len, optlen); 1130 return put_user(len, optlen);
1131 } 1131 }
1132 case IP_FREEBIND: 1132 case IP_FREEBIND:
1133 val = inet->freebind; 1133 val = inet->freebind;
1134 break; 1134 break;
1135 default: 1135 default:
1136 release_sock(sk); 1136 release_sock(sk);
1137 return -ENOPROTOOPT; 1137 return -ENOPROTOOPT;
1138 } 1138 }
1139 release_sock(sk); 1139 release_sock(sk);
1140 1140
1141 if (len < sizeof(int) && len > 0 && val>=0 && val<255) { 1141 if (len < sizeof(int) && len > 0 && val>=0 && val<255) {
1142 unsigned char ucval = (unsigned char)val; 1142 unsigned char ucval = (unsigned char)val;
1143 len = 1; 1143 len = 1;
@@ -1168,7 +1168,7 @@ int ip_getsockopt(struct sock *sk, int level,
1168 && (optname < MRT_BASE || optname > MRT_BASE+10) 1168 && (optname < MRT_BASE || optname > MRT_BASE+10)
1169#endif 1169#endif
1170 ) { 1170 ) {
1171 int len; 1171 int len;
1172 1172
1173 if(get_user(len,optlen)) 1173 if(get_user(len,optlen))
1174 return -EFAULT; 1174 return -EFAULT;
@@ -1197,7 +1197,7 @@ int compat_ip_getsockopt(struct sock *sk, int level, int optname,
1197 && (optname < MRT_BASE || optname > MRT_BASE+10) 1197 && (optname < MRT_BASE || optname > MRT_BASE+10)
1198#endif 1198#endif
1199 ) { 1199 ) {
1200 int len; 1200 int len;
1201 1201
1202 if (get_user(len, optlen)) 1202 if (get_user(len, optlen))
1203 return -EFAULT; 1203 return -EFAULT;
diff --git a/net/ipv4/ipcomp.c b/net/ipv4/ipcomp.c
index 3839b706142e..aa704b88f014 100644
--- a/net/ipv4/ipcomp.c
+++ b/net/ipv4/ipcomp.c
@@ -5,7 +5,7 @@
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify it 6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the Free 7 * under the terms of the GNU General Public License as published by the Free
8 * Software Foundation; either version 2 of the License, or (at your option) 8 * Software Foundation; either version 2 of the License, or (at your option)
9 * any later version. 9 * any later version.
10 * 10 *
11 * Todo: 11 * Todo:
@@ -48,7 +48,7 @@ static int ipcomp_decompress(struct xfrm_state *x, struct sk_buff *skb)
48 u8 *start, *scratch; 48 u8 *start, *scratch;
49 struct crypto_comp *tfm; 49 struct crypto_comp *tfm;
50 int cpu; 50 int cpu;
51 51
52 plen = skb->len; 52 plen = skb->len;
53 dlen = IPCOMP_SCRATCH_SIZE; 53 dlen = IPCOMP_SCRATCH_SIZE;
54 start = skb->data; 54 start = skb->data;
@@ -69,11 +69,11 @@ static int ipcomp_decompress(struct xfrm_state *x, struct sk_buff *skb)
69 err = pskb_expand_head(skb, 0, dlen - plen, GFP_ATOMIC); 69 err = pskb_expand_head(skb, 0, dlen - plen, GFP_ATOMIC);
70 if (err) 70 if (err)
71 goto out; 71 goto out;
72 72
73 skb->truesize += dlen - plen; 73 skb->truesize += dlen - plen;
74 __skb_put(skb, dlen - plen); 74 __skb_put(skb, dlen - plen);
75 memcpy(skb->data, scratch, dlen); 75 memcpy(skb->data, scratch, dlen);
76out: 76out:
77 put_cpu(); 77 put_cpu();
78 return err; 78 return err;
79} 79}
@@ -85,11 +85,11 @@ static int ipcomp_input(struct xfrm_state *x, struct sk_buff *skb)
85 struct ip_comp_hdr *ipch; 85 struct ip_comp_hdr *ipch;
86 86
87 if (skb_linearize_cow(skb)) 87 if (skb_linearize_cow(skb))
88 goto out; 88 goto out;
89 89
90 skb->ip_summed = CHECKSUM_NONE; 90 skb->ip_summed = CHECKSUM_NONE;
91 91
92 /* Remove ipcomp header and decompress original payload */ 92 /* Remove ipcomp header and decompress original payload */
93 iph = skb->nh.iph; 93 iph = skb->nh.iph;
94 ipch = (void *)skb->data; 94 ipch = (void *)skb->data;
95 iph->protocol = ipch->nexthdr; 95 iph->protocol = ipch->nexthdr;
@@ -97,7 +97,7 @@ static int ipcomp_input(struct xfrm_state *x, struct sk_buff *skb)
97 __skb_pull(skb, sizeof(*ipch)); 97 __skb_pull(skb, sizeof(*ipch));
98 err = ipcomp_decompress(x, skb); 98 err = ipcomp_decompress(x, skb);
99 99
100out: 100out:
101 return err; 101 return err;
102} 102}
103 103
@@ -109,7 +109,7 @@ static int ipcomp_compress(struct xfrm_state *x, struct sk_buff *skb)
109 u8 *start, *scratch; 109 u8 *start, *scratch;
110 struct crypto_comp *tfm; 110 struct crypto_comp *tfm;
111 int cpu; 111 int cpu;
112 112
113 ihlen = iph->ihl * 4; 113 ihlen = iph->ihl * 4;
114 plen = skb->len - ihlen; 114 plen = skb->len - ihlen;
115 dlen = IPCOMP_SCRATCH_SIZE; 115 dlen = IPCOMP_SCRATCH_SIZE;
@@ -127,14 +127,14 @@ static int ipcomp_compress(struct xfrm_state *x, struct sk_buff *skb)
127 err = -EMSGSIZE; 127 err = -EMSGSIZE;
128 goto out; 128 goto out;
129 } 129 }
130 130
131 memcpy(start + sizeof(struct ip_comp_hdr), scratch, dlen); 131 memcpy(start + sizeof(struct ip_comp_hdr), scratch, dlen);
132 put_cpu(); 132 put_cpu();
133 133
134 pskb_trim(skb, ihlen + dlen + sizeof(struct ip_comp_hdr)); 134 pskb_trim(skb, ihlen + dlen + sizeof(struct ip_comp_hdr));
135 return 0; 135 return 0;
136 136
137out: 137out:
138 put_cpu(); 138 put_cpu();
139 return err; 139 return err;
140} 140}
@@ -157,7 +157,7 @@ static int ipcomp_output(struct xfrm_state *x, struct sk_buff *skb)
157 157
158 if (skb_linearize_cow(skb)) 158 if (skb_linearize_cow(skb))
159 goto out_ok; 159 goto out_ok;
160 160
161 err = ipcomp_compress(x, skb); 161 err = ipcomp_compress(x, skb);
162 iph = skb->nh.iph; 162 iph = skb->nh.iph;
163 163
@@ -194,7 +194,7 @@ static void ipcomp4_err(struct sk_buff *skb, u32 info)
194 194
195 spi = htonl(ntohs(ipch->cpi)); 195 spi = htonl(ntohs(ipch->cpi));
196 x = xfrm_state_lookup((xfrm_address_t *)&iph->daddr, 196 x = xfrm_state_lookup((xfrm_address_t *)&iph->daddr,
197 spi, IPPROTO_COMP, AF_INET); 197 spi, IPPROTO_COMP, AF_INET);
198 if (!x) 198 if (!x)
199 return; 199 return;
200 NETDEBUG(KERN_DEBUG "pmtu discovery on SA IPCOMP/%08x/%u.%u.%u.%u\n", 200 NETDEBUG(KERN_DEBUG "pmtu discovery on SA IPCOMP/%08x/%u.%u.%u.%u\n",
@@ -202,12 +202,12 @@ static void ipcomp4_err(struct sk_buff *skb, u32 info)
202 xfrm_state_put(x); 202 xfrm_state_put(x);
203} 203}
204 204
205/* We always hold one tunnel user reference to indicate a tunnel */ 205/* We always hold one tunnel user reference to indicate a tunnel */
206static struct xfrm_state *ipcomp_tunnel_create(struct xfrm_state *x) 206static struct xfrm_state *ipcomp_tunnel_create(struct xfrm_state *x)
207{ 207{
208 struct xfrm_state *t; 208 struct xfrm_state *t;
209 u8 mode = XFRM_MODE_TUNNEL; 209 u8 mode = XFRM_MODE_TUNNEL;
210 210
211 t = xfrm_state_alloc(); 211 t = xfrm_state_alloc();
212 if (t == NULL) 212 if (t == NULL)
213 goto out; 213 goto out;
@@ -247,7 +247,7 @@ static int ipcomp_tunnel_attach(struct xfrm_state *x)
247 struct xfrm_state *t; 247 struct xfrm_state *t;
248 248
249 t = xfrm_state_lookup((xfrm_address_t *)&x->id.daddr.a4, 249 t = xfrm_state_lookup((xfrm_address_t *)&x->id.daddr.a4,
250 x->props.saddr.a4, IPPROTO_IPIP, AF_INET); 250 x->props.saddr.a4, IPPROTO_IPIP, AF_INET);
251 if (!t) { 251 if (!t) {
252 t = ipcomp_tunnel_create(x); 252 t = ipcomp_tunnel_create(x);
253 if (!t) { 253 if (!t) {
diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
index afa60b9a003f..cf49de1a4983 100644
--- a/net/ipv4/ipconfig.c
+++ b/net/ipv4/ipconfig.c
@@ -12,7 +12,7 @@
12 * BOOTP rewritten to construct and analyse packets itself instead 12 * BOOTP rewritten to construct and analyse packets itself instead
13 * of misusing the IP layer. num_bugs_causing_wrong_arp_replies--; 13 * of misusing the IP layer. num_bugs_causing_wrong_arp_replies--;
14 * -- MJ, December 1998 14 * -- MJ, December 1998
15 * 15 *
16 * Fixed ip_auto_config_setup calling at startup in the new "Linker Magic" 16 * Fixed ip_auto_config_setup calling at startup in the new "Linker Magic"
17 * initialization scheme. 17 * initialization scheme.
18 * - Arnaldo Carvalho de Melo <acme@conectiva.com.br>, 08/11/1999 18 * - Arnaldo Carvalho de Melo <acme@conectiva.com.br>, 08/11/1999
@@ -98,8 +98,8 @@
98#define CONF_TIMEOUT_RANDOM (HZ) /* Maximum amount of randomization */ 98#define CONF_TIMEOUT_RANDOM (HZ) /* Maximum amount of randomization */
99#define CONF_TIMEOUT_MULT *7/4 /* Rate of timeout growth */ 99#define CONF_TIMEOUT_MULT *7/4 /* Rate of timeout growth */
100#define CONF_TIMEOUT_MAX (HZ*30) /* Maximum allowed timeout */ 100#define CONF_TIMEOUT_MAX (HZ*30) /* Maximum allowed timeout */
101#define CONF_NAMESERVERS_MAX 3 /* Maximum number of nameservers 101#define CONF_NAMESERVERS_MAX 3 /* Maximum number of nameservers
102 - '3' from resolv.h */ 102 - '3' from resolv.h */
103 103
104#define NONE __constant_htonl(INADDR_NONE) 104#define NONE __constant_htonl(INADDR_NONE)
105 105
@@ -365,7 +365,7 @@ static int __init ic_defaults(void)
365 * At this point we have no userspace running so need not 365 * At this point we have no userspace running so need not
366 * claim locks on system_utsname 366 * claim locks on system_utsname
367 */ 367 */
368 368
369 if (!ic_host_name_set) 369 if (!ic_host_name_set)
370 sprintf(init_utsname()->nodename, "%u.%u.%u.%u", NIPQUAD(ic_myaddr)); 370 sprintf(init_utsname()->nodename, "%u.%u.%u.%u", NIPQUAD(ic_myaddr));
371 371
@@ -650,9 +650,9 @@ static void __init ic_bootp_init_ext(u8 *e)
650 *e++ = 40; 650 *e++ = 40;
651 e += 40; 651 e += 40;
652 652
653 *e++ = 57; /* set extension buffer size for reply */ 653 *e++ = 57; /* set extension buffer size for reply */
654 *e++ = 2; 654 *e++ = 2;
655 *e++ = 1; /* 128+236+8+20+14, see dhcpd sources */ 655 *e++ = 1; /* 128+236+8+20+14, see dhcpd sources */
656 *e++ = 150; 656 *e++ = 150;
657 657
658 *e++ = 255; /* End of the list */ 658 *e++ = 255; /* End of the list */
@@ -913,7 +913,7 @@ static int __init ic_bootp_recv(struct sk_buff *skb, struct net_device *dev, str
913 /* Parse extensions */ 913 /* Parse extensions */
914 if (ext_len >= 4 && 914 if (ext_len >= 4 &&
915 !memcmp(b->exten, ic_bootp_cookie, 4)) { /* Check magic cookie */ 915 !memcmp(b->exten, ic_bootp_cookie, 4)) { /* Check magic cookie */
916 u8 *end = (u8 *) b + ntohs(b->iph.tot_len); 916 u8 *end = (u8 *) b + ntohs(b->iph.tot_len);
917 u8 *ext; 917 u8 *ext;
918 918
919#ifdef IPCONFIG_DHCP 919#ifdef IPCONFIG_DHCP
@@ -1020,7 +1020,7 @@ drop:
1020 kfree_skb(skb); 1020 kfree_skb(skb);
1021 1021
1022 return 0; 1022 return 0;
1023} 1023}
1024 1024
1025 1025
1026#endif 1026#endif
@@ -1080,7 +1080,7 @@ static int __init ic_dynamic(void)
1080 * seems to be a terrible waste of CPU time, but actually there is 1080 * seems to be a terrible waste of CPU time, but actually there is
1081 * only one process running at all, so we don't need to use any 1081 * only one process running at all, so we don't need to use any
1082 * scheduler functions. 1082 * scheduler functions.
1083 * [Actually we could now, but the nothing else running note still 1083 * [Actually we could now, but the nothing else running note still
1084 * applies.. - AC] 1084 * applies.. - AC]
1085 */ 1085 */
1086 printk(KERN_NOTICE "Sending %s%s%s requests .", 1086 printk(KERN_NOTICE "Sending %s%s%s requests .",
@@ -1156,7 +1156,7 @@ static int __init ic_dynamic(void)
1156 } 1156 }
1157 1157
1158 printk("IP-Config: Got %s answer from %u.%u.%u.%u, ", 1158 printk("IP-Config: Got %s answer from %u.%u.%u.%u, ",
1159 ((ic_got_reply & IC_RARP) ? "RARP" 1159 ((ic_got_reply & IC_RARP) ? "RARP"
1160 : (ic_proto_enabled & IC_USE_DHCP) ? "DHCP" : "BOOTP"), 1160 : (ic_proto_enabled & IC_USE_DHCP) ? "DHCP" : "BOOTP"),
1161 NIPQUAD(ic_servaddr)); 1161 NIPQUAD(ic_servaddr));
1162 printk("my address is %u.%u.%u.%u\n", NIPQUAD(ic_myaddr)); 1162 printk("my address is %u.%u.%u.%u\n", NIPQUAD(ic_myaddr));
@@ -1200,7 +1200,7 @@ static int pnp_seq_open(struct inode *indoe, struct file *file)
1200 return single_open(file, pnp_seq_show, NULL); 1200 return single_open(file, pnp_seq_show, NULL);
1201} 1201}
1202 1202
1203static struct file_operations pnp_seq_fops = { 1203static const struct file_operations pnp_seq_fops = {
1204 .owner = THIS_MODULE, 1204 .owner = THIS_MODULE,
1205 .open = pnp_seq_open, 1205 .open = pnp_seq_open,
1206 .read = seq_read, 1206 .read = seq_read,
@@ -1286,7 +1286,7 @@ static int __init ip_auto_config(void)
1286#endif 1286#endif
1287 ic_first_dev->next) { 1287 ic_first_dev->next) {
1288#ifdef IPCONFIG_DYNAMIC 1288#ifdef IPCONFIG_DYNAMIC
1289 1289
1290 int retries = CONF_OPEN_RETRIES; 1290 int retries = CONF_OPEN_RETRIES;
1291 1291
1292 if (ic_dynamic() < 0) { 1292 if (ic_dynamic() < 0) {
@@ -1308,14 +1308,14 @@ static int __init ip_auto_config(void)
1308 */ 1308 */
1309#ifdef CONFIG_ROOT_NFS 1309#ifdef CONFIG_ROOT_NFS
1310 if (ROOT_DEV == Root_NFS) { 1310 if (ROOT_DEV == Root_NFS) {
1311 printk(KERN_ERR 1311 printk(KERN_ERR
1312 "IP-Config: Retrying forever (NFS root)...\n"); 1312 "IP-Config: Retrying forever (NFS root)...\n");
1313 goto try_try_again; 1313 goto try_try_again;
1314 } 1314 }
1315#endif 1315#endif
1316 1316
1317 if (--retries) { 1317 if (--retries) {
1318 printk(KERN_ERR 1318 printk(KERN_ERR
1319 "IP-Config: Reopening network devices...\n"); 1319 "IP-Config: Reopening network devices...\n");
1320 goto try_try_again; 1320 goto try_try_again;
1321 } 1321 }
@@ -1443,8 +1443,8 @@ static int __init ip_auto_config_setup(char *addrs)
1443 1443
1444 ic_set_manually = 1; 1444 ic_set_manually = 1;
1445 1445
1446 ic_enable = (*addrs && 1446 ic_enable = (*addrs &&
1447 (strcmp(addrs, "off") != 0) && 1447 (strcmp(addrs, "off") != 0) &&
1448 (strcmp(addrs, "none") != 0)); 1448 (strcmp(addrs, "none") != 0));
1449 if (!ic_enable) 1449 if (!ic_enable)
1450 return 1; 1450 return 1;
diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c
index 9d719d664e5b..475bcd1e4181 100644
--- a/net/ipv4/ipip.c
+++ b/net/ipv4/ipip.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * Linux NET3: IP/IP protocol decoder. 2 * Linux NET3: IP/IP protocol decoder.
3 * 3 *
4 * Version: $Id: ipip.c,v 1.50 2001/10/02 02:22:36 davem Exp $ 4 * Version: $Id: ipip.c,v 1.50 2001/10/02 02:22:36 davem Exp $
5 * 5 *
@@ -35,14 +35,14 @@
35 Thanks for the great code! 35 Thanks for the great code!
36 36
37 -Sam Lantinga (slouken@cs.ucdavis.edu) 02/01/95 37 -Sam Lantinga (slouken@cs.ucdavis.edu) 02/01/95
38 38
39 Minor tweaks: 39 Minor tweaks:
40 Cleaned up the code a little and added some pre-1.3.0 tweaks. 40 Cleaned up the code a little and added some pre-1.3.0 tweaks.
41 dev->hard_header/hard_header_len changed to use no headers. 41 dev->hard_header/hard_header_len changed to use no headers.
42 Comments/bracketing tweaked. 42 Comments/bracketing tweaked.
43 Made the tunnels use dev->name not tunnel: when error reporting. 43 Made the tunnels use dev->name not tunnel: when error reporting.
44 Added tx_dropped stat 44 Added tx_dropped stat
45 45
46 -Alan Cox (Alan.Cox@linux.org) 21 March 95 46 -Alan Cox (Alan.Cox@linux.org) 21 March 95
47 47
48 Reworked: 48 Reworked:
@@ -52,7 +52,7 @@
52 Note: There is currently no firewall or ICMP handling done. 52 Note: There is currently no firewall or ICMP handling done.
53 53
54 -Sam Lantinga (slouken@cs.ucdavis.edu) 02/13/96 54 -Sam Lantinga (slouken@cs.ucdavis.edu) 02/13/96
55 55
56*/ 56*/
57 57
58/* Things I wish I had known when writing the tunnel driver: 58/* Things I wish I had known when writing the tunnel driver:
@@ -75,7 +75,7 @@
75 "allocated" with skb_put(). You can then write up to skb->len 75 "allocated" with skb_put(). You can then write up to skb->len
76 bytes to that buffer. If you need more, you can call skb_put() 76 bytes to that buffer. If you need more, you can call skb_put()
77 again with the additional amount of space you need. You can 77 again with the additional amount of space you need. You can
78 find out how much more space you can allocate by calling 78 find out how much more space you can allocate by calling
79 "skb_tailroom(skb)". 79 "skb_tailroom(skb)".
80 Now, to add header space, call "skb_push(skb, header_len)". 80 Now, to add header space, call "skb_push(skb, header_len)".
81 This creates space at the beginning of the buffer and returns 81 This creates space at the beginning of the buffer and returns
@@ -92,7 +92,7 @@
92 For comments look at net/ipv4/ip_gre.c --ANK 92 For comments look at net/ipv4/ip_gre.c --ANK
93 */ 93 */
94 94
95 95
96#include <linux/capability.h> 96#include <linux/capability.h>
97#include <linux/module.h> 97#include <linux/module.h>
98#include <linux/types.h> 98#include <linux/types.h>
@@ -607,7 +607,7 @@ static int ipip_tunnel_xmit(struct sk_buff *skb, struct net_device *dev)
607 struct sk_buff *new_skb = skb_realloc_headroom(skb, max_headroom); 607 struct sk_buff *new_skb = skb_realloc_headroom(skb, max_headroom);
608 if (!new_skb) { 608 if (!new_skb) {
609 ip_rt_put(rt); 609 ip_rt_put(rt);
610 stats->tx_dropped++; 610 stats->tx_dropped++;
611 dev_kfree_skb(skb); 611 dev_kfree_skb(skb);
612 tunnel->recursion--; 612 tunnel->recursion--;
613 return 0; 613 return 0;
@@ -754,7 +754,8 @@ ipip_tunnel_ioctl (struct net_device *dev, struct ifreq *ifr, int cmd)
754 goto done; 754 goto done;
755 dev = t->dev; 755 dev = t->dev;
756 } 756 }
757 err = unregister_netdevice(dev); 757 unregister_netdevice(dev);
758 err = 0;
758 break; 759 break;
759 760
760 default: 761 default:
diff --git a/net/ipv4/ipmr.c b/net/ipv4/ipmr.c
index ecb5422ea237..e6d11abd7841 100644
--- a/net/ipv4/ipmr.c
+++ b/net/ipv4/ipmr.c
@@ -241,7 +241,7 @@ failure:
241/* 241/*
242 * Delete a VIF entry 242 * Delete a VIF entry
243 */ 243 */
244 244
245static int vif_delete(int vifi) 245static int vif_delete(int vifi)
246{ 246{
247 struct vif_device *v; 247 struct vif_device *v;
@@ -409,7 +409,7 @@ static int vif_add(struct vifctl *vifc, int mrtsock)
409 return -ENOBUFS; 409 return -ENOBUFS;
410 break; 410 break;
411#endif 411#endif
412 case VIFF_TUNNEL: 412 case VIFF_TUNNEL:
413 dev = ipmr_new_tunnel(vifc); 413 dev = ipmr_new_tunnel(vifc);
414 if (!dev) 414 if (!dev)
415 return -ENOBUFS; 415 return -ENOBUFS;
@@ -479,20 +479,18 @@ static struct mfc_cache *ipmr_cache_find(__be32 origin, __be32 mcastgrp)
479 */ 479 */
480static struct mfc_cache *ipmr_cache_alloc(void) 480static struct mfc_cache *ipmr_cache_alloc(void)
481{ 481{
482 struct mfc_cache *c=kmem_cache_alloc(mrt_cachep, GFP_KERNEL); 482 struct mfc_cache *c=kmem_cache_zalloc(mrt_cachep, GFP_KERNEL);
483 if(c==NULL) 483 if(c==NULL)
484 return NULL; 484 return NULL;
485 memset(c, 0, sizeof(*c));
486 c->mfc_un.res.minvif = MAXVIFS; 485 c->mfc_un.res.minvif = MAXVIFS;
487 return c; 486 return c;
488} 487}
489 488
490static struct mfc_cache *ipmr_cache_alloc_unres(void) 489static struct mfc_cache *ipmr_cache_alloc_unres(void)
491{ 490{
492 struct mfc_cache *c=kmem_cache_alloc(mrt_cachep, GFP_ATOMIC); 491 struct mfc_cache *c=kmem_cache_zalloc(mrt_cachep, GFP_ATOMIC);
493 if(c==NULL) 492 if(c==NULL)
494 return NULL; 493 return NULL;
495 memset(c, 0, sizeof(*c));
496 skb_queue_head_init(&c->mfc_un.unres.unresolved); 494 skb_queue_head_init(&c->mfc_un.unres.unresolved);
497 c->mfc_un.unres.expires = jiffies + 10*HZ; 495 c->mfc_un.unres.expires = jiffies + 10*HZ;
498 return c; 496 return c;
@@ -501,7 +499,7 @@ static struct mfc_cache *ipmr_cache_alloc_unres(void)
501/* 499/*
502 * A cache entry has gone into a resolved state from queued 500 * A cache entry has gone into a resolved state from queued
503 */ 501 */
504 502
505static void ipmr_cache_resolve(struct mfc_cache *uc, struct mfc_cache *c) 503static void ipmr_cache_resolve(struct mfc_cache *uc, struct mfc_cache *c)
506{ 504{
507 struct sk_buff *skb; 505 struct sk_buff *skb;
@@ -538,7 +536,7 @@ static void ipmr_cache_resolve(struct mfc_cache *uc, struct mfc_cache *c)
538 * 536 *
539 * Called under mrt_lock. 537 * Called under mrt_lock.
540 */ 538 */
541 539
542static int ipmr_cache_report(struct sk_buff *pkt, vifi_t vifi, int assert) 540static int ipmr_cache_report(struct sk_buff *pkt, vifi_t vifi, int assert)
543{ 541{
544 struct sk_buff *skb; 542 struct sk_buff *skb;
@@ -569,13 +567,13 @@ static int ipmr_cache_report(struct sk_buff *pkt, vifi_t vifi, int assert)
569 memcpy(msg, pkt->nh.raw, sizeof(struct iphdr)); 567 memcpy(msg, pkt->nh.raw, sizeof(struct iphdr));
570 msg->im_msgtype = IGMPMSG_WHOLEPKT; 568 msg->im_msgtype = IGMPMSG_WHOLEPKT;
571 msg->im_mbz = 0; 569 msg->im_mbz = 0;
572 msg->im_vif = reg_vif_num; 570 msg->im_vif = reg_vif_num;
573 skb->nh.iph->ihl = sizeof(struct iphdr) >> 2; 571 skb->nh.iph->ihl = sizeof(struct iphdr) >> 2;
574 skb->nh.iph->tot_len = htons(ntohs(pkt->nh.iph->tot_len) + sizeof(struct iphdr)); 572 skb->nh.iph->tot_len = htons(ntohs(pkt->nh.iph->tot_len) + sizeof(struct iphdr));
575 } else 573 } else
576#endif 574#endif
577 { 575 {
578 576
579 /* 577 /*
580 * Copy the IP header 578 * Copy the IP header
581 */ 579 */
@@ -597,7 +595,7 @@ static int ipmr_cache_report(struct sk_buff *pkt, vifi_t vifi, int assert)
597 igmp->code = 0; 595 igmp->code = 0;
598 skb->nh.iph->tot_len=htons(skb->len); /* Fix the length */ 596 skb->nh.iph->tot_len=htons(skb->len); /* Fix the length */
599 skb->h.raw = skb->nh.raw; 597 skb->h.raw = skb->nh.raw;
600 } 598 }
601 599
602 if (mroute_socket == NULL) { 600 if (mroute_socket == NULL) {
603 kfree_skb(skb); 601 kfree_skb(skb);
@@ -619,7 +617,7 @@ static int ipmr_cache_report(struct sk_buff *pkt, vifi_t vifi, int assert)
619/* 617/*
620 * Queue a packet for resolution. It gets locked cache entry! 618 * Queue a packet for resolution. It gets locked cache entry!
621 */ 619 */
622 620
623static int 621static int
624ipmr_cache_unresolved(vifi_t vifi, struct sk_buff *skb) 622ipmr_cache_unresolved(vifi_t vifi, struct sk_buff *skb)
625{ 623{
@@ -657,7 +655,7 @@ ipmr_cache_unresolved(vifi_t vifi, struct sk_buff *skb)
657 * Reflect first query at mrouted. 655 * Reflect first query at mrouted.
658 */ 656 */
659 if ((err = ipmr_cache_report(skb, vifi, IGMPMSG_NOCACHE))<0) { 657 if ((err = ipmr_cache_report(skb, vifi, IGMPMSG_NOCACHE))<0) {
660 /* If the report failed throw the cache entry 658 /* If the report failed throw the cache entry
661 out - Brad Parker 659 out - Brad Parker
662 */ 660 */
663 spin_unlock_bh(&mfc_unres_lock); 661 spin_unlock_bh(&mfc_unres_lock);
@@ -783,11 +781,11 @@ static int ipmr_mfc_add(struct mfcctl *mfc, int mrtsock)
783/* 781/*
784 * Close the multicast socket, and clear the vif tables etc 782 * Close the multicast socket, and clear the vif tables etc
785 */ 783 */
786 784
787static void mroute_clean_tables(struct sock *sk) 785static void mroute_clean_tables(struct sock *sk)
788{ 786{
789 int i; 787 int i;
790 788
791 /* 789 /*
792 * Shut down all active vif entries 790 * Shut down all active vif entries
793 */ 791 */
@@ -854,13 +852,13 @@ static void mrtsock_destruct(struct sock *sk)
854 * that's how BSD mrouted happens to think. Maybe one day with a proper 852 * that's how BSD mrouted happens to think. Maybe one day with a proper
855 * MOSPF/PIM router set up we can clean this up. 853 * MOSPF/PIM router set up we can clean this up.
856 */ 854 */
857 855
858int ip_mroute_setsockopt(struct sock *sk,int optname,char __user *optval,int optlen) 856int ip_mroute_setsockopt(struct sock *sk,int optname,char __user *optval,int optlen)
859{ 857{
860 int ret; 858 int ret;
861 struct vifctl vif; 859 struct vifctl vif;
862 struct mfcctl mfc; 860 struct mfcctl mfc;
863 861
864 if(optname!=MRT_INIT) 862 if(optname!=MRT_INIT)
865 { 863 {
866 if(sk!=mroute_socket && !capable(CAP_NET_ADMIN)) 864 if(sk!=mroute_socket && !capable(CAP_NET_ADMIN))
@@ -901,7 +899,7 @@ int ip_mroute_setsockopt(struct sock *sk,int optname,char __user *optval,int opt
901 if(optlen!=sizeof(vif)) 899 if(optlen!=sizeof(vif))
902 return -EINVAL; 900 return -EINVAL;
903 if (copy_from_user(&vif,optval,sizeof(vif))) 901 if (copy_from_user(&vif,optval,sizeof(vif)))
904 return -EFAULT; 902 return -EFAULT;
905 if(vif.vifc_vifi >= MAXVIFS) 903 if(vif.vifc_vifi >= MAXVIFS)
906 return -ENFILE; 904 return -ENFILE;
907 rtnl_lock(); 905 rtnl_lock();
@@ -980,13 +978,13 @@ int ip_mroute_setsockopt(struct sock *sk,int optname,char __user *optval,int opt
980/* 978/*
981 * Getsock opt support for the multicast routing system. 979 * Getsock opt support for the multicast routing system.
982 */ 980 */
983 981
984int ip_mroute_getsockopt(struct sock *sk,int optname,char __user *optval,int __user *optlen) 982int ip_mroute_getsockopt(struct sock *sk,int optname,char __user *optval,int __user *optlen)
985{ 983{
986 int olr; 984 int olr;
987 int val; 985 int val;
988 986
989 if(optname!=MRT_VERSION && 987 if(optname!=MRT_VERSION &&
990#ifdef CONFIG_IP_PIMSM 988#ifdef CONFIG_IP_PIMSM
991 optname!=MRT_PIM && 989 optname!=MRT_PIM &&
992#endif 990#endif
@@ -999,7 +997,7 @@ int ip_mroute_getsockopt(struct sock *sk,int optname,char __user *optval,int __u
999 olr = min_t(unsigned int, olr, sizeof(int)); 997 olr = min_t(unsigned int, olr, sizeof(int));
1000 if (olr < 0) 998 if (olr < 0)
1001 return -EINVAL; 999 return -EINVAL;
1002 1000
1003 if(put_user(olr,optlen)) 1001 if(put_user(olr,optlen))
1004 return -EFAULT; 1002 return -EFAULT;
1005 if(optname==MRT_VERSION) 1003 if(optname==MRT_VERSION)
@@ -1018,19 +1016,19 @@ int ip_mroute_getsockopt(struct sock *sk,int optname,char __user *optval,int __u
1018/* 1016/*
1019 * The IP multicast ioctl support routines. 1017 * The IP multicast ioctl support routines.
1020 */ 1018 */
1021 1019
1022int ipmr_ioctl(struct sock *sk, int cmd, void __user *arg) 1020int ipmr_ioctl(struct sock *sk, int cmd, void __user *arg)
1023{ 1021{
1024 struct sioc_sg_req sr; 1022 struct sioc_sg_req sr;
1025 struct sioc_vif_req vr; 1023 struct sioc_vif_req vr;
1026 struct vif_device *vif; 1024 struct vif_device *vif;
1027 struct mfc_cache *c; 1025 struct mfc_cache *c;
1028 1026
1029 switch(cmd) 1027 switch(cmd)
1030 { 1028 {
1031 case SIOCGETVIFCNT: 1029 case SIOCGETVIFCNT:
1032 if (copy_from_user(&vr,arg,sizeof(vr))) 1030 if (copy_from_user(&vr,arg,sizeof(vr)))
1033 return -EFAULT; 1031 return -EFAULT;
1034 if(vr.vifi>=maxvif) 1032 if(vr.vifi>=maxvif)
1035 return -EINVAL; 1033 return -EINVAL;
1036 read_lock(&mrt_lock); 1034 read_lock(&mrt_lock);
@@ -1096,7 +1094,7 @@ static struct notifier_block ip_mr_notifier={
1096 * This avoids tunnel drivers and other mess and gives us the speed so 1094 * This avoids tunnel drivers and other mess and gives us the speed so
1097 * important for multicast video. 1095 * important for multicast video.
1098 */ 1096 */
1099 1097
1100static void ip_encap(struct sk_buff *skb, __be32 saddr, __be32 daddr) 1098static void ip_encap(struct sk_buff *skb, __be32 saddr, __be32 daddr)
1101{ 1099{
1102 struct iphdr *iph = (struct iphdr *)skb_push(skb,sizeof(struct iphdr)); 1100 struct iphdr *iph = (struct iphdr *)skb_push(skb,sizeof(struct iphdr));
@@ -1194,7 +1192,7 @@ static void ipmr_queue_xmit(struct sk_buff *skb, struct mfc_cache *c, int vifi)
1194 encap += LL_RESERVED_SPACE(dev) + rt->u.dst.header_len; 1192 encap += LL_RESERVED_SPACE(dev) + rt->u.dst.header_len;
1195 1193
1196 if (skb_cow(skb, encap)) { 1194 if (skb_cow(skb, encap)) {
1197 ip_rt_put(rt); 1195 ip_rt_put(rt);
1198 goto out_free; 1196 goto out_free;
1199 } 1197 }
1200 1198
@@ -1228,7 +1226,7 @@ static void ipmr_queue_xmit(struct sk_buff *skb, struct mfc_cache *c, int vifi)
1228 * not mrouter) cannot join to more than one interface - it will 1226 * not mrouter) cannot join to more than one interface - it will
1229 * result in receiving multiple packets. 1227 * result in receiving multiple packets.
1230 */ 1228 */
1231 NF_HOOK(PF_INET, NF_IP_FORWARD, skb, skb->dev, dev, 1229 NF_HOOK(PF_INET, NF_IP_FORWARD, skb, skb->dev, dev,
1232 ipmr_forward_finish); 1230 ipmr_forward_finish);
1233 return; 1231 return;
1234 1232
@@ -1289,7 +1287,7 @@ static int ip_mr_forward(struct sk_buff *skb, struct mfc_cache *cache, int local
1289 large chunk of pimd to kernel. Ough... --ANK 1287 large chunk of pimd to kernel. Ough... --ANK
1290 */ 1288 */
1291 (mroute_do_pim || cache->mfc_un.res.ttls[true_vifi] < 255) && 1289 (mroute_do_pim || cache->mfc_un.res.ttls[true_vifi] < 255) &&
1292 time_after(jiffies, 1290 time_after(jiffies,
1293 cache->mfc_un.res.last_assert + MFC_ASSERT_THRESH)) { 1291 cache->mfc_un.res.last_assert + MFC_ASSERT_THRESH)) {
1294 cache->mfc_un.res.last_assert = jiffies; 1292 cache->mfc_un.res.last_assert = jiffies;
1295 ipmr_cache_report(skb, true_vifi, IGMPMSG_WRONGVIF); 1293 ipmr_cache_report(skb, true_vifi, IGMPMSG_WRONGVIF);
@@ -1426,14 +1424,14 @@ int pim_rcv_v1(struct sk_buff * skb)
1426 struct iphdr *encap; 1424 struct iphdr *encap;
1427 struct net_device *reg_dev = NULL; 1425 struct net_device *reg_dev = NULL;
1428 1426
1429 if (!pskb_may_pull(skb, sizeof(*pim) + sizeof(*encap))) 1427 if (!pskb_may_pull(skb, sizeof(*pim) + sizeof(*encap)))
1430 goto drop; 1428 goto drop;
1431 1429
1432 pim = (struct igmphdr*)skb->h.raw; 1430 pim = (struct igmphdr*)skb->h.raw;
1433 1431
1434 if (!mroute_do_pim || 1432 if (!mroute_do_pim ||
1435 skb->len < sizeof(*pim) + sizeof(*encap) || 1433 skb->len < sizeof(*pim) + sizeof(*encap) ||
1436 pim->group != PIM_V1_VERSION || pim->code != PIM_V1_REGISTER) 1434 pim->group != PIM_V1_VERSION || pim->code != PIM_V1_REGISTER)
1437 goto drop; 1435 goto drop;
1438 1436
1439 encap = (struct iphdr*)(skb->h.raw + sizeof(struct igmphdr)); 1437 encap = (struct iphdr*)(skb->h.raw + sizeof(struct igmphdr));
@@ -1445,7 +1443,7 @@ int pim_rcv_v1(struct sk_buff * skb)
1445 */ 1443 */
1446 if (!MULTICAST(encap->daddr) || 1444 if (!MULTICAST(encap->daddr) ||
1447 encap->tot_len == 0 || 1445 encap->tot_len == 0 ||
1448 ntohs(encap->tot_len) + sizeof(*pim) > skb->len) 1446 ntohs(encap->tot_len) + sizeof(*pim) > skb->len)
1449 goto drop; 1447 goto drop;
1450 1448
1451 read_lock(&mrt_lock); 1449 read_lock(&mrt_lock);
@@ -1455,7 +1453,7 @@ int pim_rcv_v1(struct sk_buff * skb)
1455 dev_hold(reg_dev); 1453 dev_hold(reg_dev);
1456 read_unlock(&mrt_lock); 1454 read_unlock(&mrt_lock);
1457 1455
1458 if (reg_dev == NULL) 1456 if (reg_dev == NULL)
1459 goto drop; 1457 goto drop;
1460 1458
1461 skb->mac.raw = skb->nh.raw; 1459 skb->mac.raw = skb->nh.raw;
@@ -1486,13 +1484,13 @@ static int pim_rcv(struct sk_buff * skb)
1486 struct iphdr *encap; 1484 struct iphdr *encap;
1487 struct net_device *reg_dev = NULL; 1485 struct net_device *reg_dev = NULL;
1488 1486
1489 if (!pskb_may_pull(skb, sizeof(*pim) + sizeof(*encap))) 1487 if (!pskb_may_pull(skb, sizeof(*pim) + sizeof(*encap)))
1490 goto drop; 1488 goto drop;
1491 1489
1492 pim = (struct pimreghdr*)skb->h.raw; 1490 pim = (struct pimreghdr*)skb->h.raw;
1493 if (pim->type != ((PIM_VERSION<<4)|(PIM_REGISTER)) || 1491 if (pim->type != ((PIM_VERSION<<4)|(PIM_REGISTER)) ||
1494 (pim->flags&PIM_NULL_REGISTER) || 1492 (pim->flags&PIM_NULL_REGISTER) ||
1495 (ip_compute_csum((void *)pim, sizeof(*pim)) != 0 && 1493 (ip_compute_csum((void *)pim, sizeof(*pim)) != 0 &&
1496 csum_fold(skb_checksum(skb, 0, skb->len, 0)))) 1494 csum_fold(skb_checksum(skb, 0, skb->len, 0))))
1497 goto drop; 1495 goto drop;
1498 1496
@@ -1500,7 +1498,7 @@ static int pim_rcv(struct sk_buff * skb)
1500 encap = (struct iphdr*)(skb->h.raw + sizeof(struct pimreghdr)); 1498 encap = (struct iphdr*)(skb->h.raw + sizeof(struct pimreghdr));
1501 if (!MULTICAST(encap->daddr) || 1499 if (!MULTICAST(encap->daddr) ||
1502 encap->tot_len == 0 || 1500 encap->tot_len == 0 ||
1503 ntohs(encap->tot_len) + sizeof(*pim) > skb->len) 1501 ntohs(encap->tot_len) + sizeof(*pim) > skb->len)
1504 goto drop; 1502 goto drop;
1505 1503
1506 read_lock(&mrt_lock); 1504 read_lock(&mrt_lock);
@@ -1510,7 +1508,7 @@ static int pim_rcv(struct sk_buff * skb)
1510 dev_hold(reg_dev); 1508 dev_hold(reg_dev);
1511 read_unlock(&mrt_lock); 1509 read_unlock(&mrt_lock);
1512 1510
1513 if (reg_dev == NULL) 1511 if (reg_dev == NULL)
1514 goto drop; 1512 goto drop;
1515 1513
1516 skb->mac.raw = skb->nh.raw; 1514 skb->mac.raw = skb->nh.raw;
@@ -1616,7 +1614,7 @@ int ipmr_get_route(struct sk_buff *skb, struct rtmsg *rtm, int nowait)
1616 return err; 1614 return err;
1617} 1615}
1618 1616
1619#ifdef CONFIG_PROC_FS 1617#ifdef CONFIG_PROC_FS
1620/* 1618/*
1621 * The /proc interfaces to multicast routing /proc/ip_mr_cache /proc/ip_mr_vif 1619 * The /proc interfaces to multicast routing /proc/ip_mr_cache /proc/ip_mr_vif
1622 */ 1620 */
@@ -1630,7 +1628,7 @@ static struct vif_device *ipmr_vif_seq_idx(struct ipmr_vif_iter *iter,
1630 for (iter->ct = 0; iter->ct < maxvif; ++iter->ct) { 1628 for (iter->ct = 0; iter->ct < maxvif; ++iter->ct) {
1631 if(!VIF_EXISTS(iter->ct)) 1629 if(!VIF_EXISTS(iter->ct))
1632 continue; 1630 continue;
1633 if (pos-- == 0) 1631 if (pos-- == 0)
1634 return &vif_table[iter->ct]; 1632 return &vif_table[iter->ct];
1635 } 1633 }
1636 return NULL; 1634 return NULL;
@@ -1639,7 +1637,7 @@ static struct vif_device *ipmr_vif_seq_idx(struct ipmr_vif_iter *iter,
1639static void *ipmr_vif_seq_start(struct seq_file *seq, loff_t *pos) 1637static void *ipmr_vif_seq_start(struct seq_file *seq, loff_t *pos)
1640{ 1638{
1641 read_lock(&mrt_lock); 1639 read_lock(&mrt_lock);
1642 return *pos ? ipmr_vif_seq_idx(seq->private, *pos - 1) 1640 return *pos ? ipmr_vif_seq_idx(seq->private, *pos - 1)
1643 : SEQ_START_TOKEN; 1641 : SEQ_START_TOKEN;
1644} 1642}
1645 1643
@@ -1650,7 +1648,7 @@ static void *ipmr_vif_seq_next(struct seq_file *seq, void *v, loff_t *pos)
1650 ++*pos; 1648 ++*pos;
1651 if (v == SEQ_START_TOKEN) 1649 if (v == SEQ_START_TOKEN)
1652 return ipmr_vif_seq_idx(iter, 0); 1650 return ipmr_vif_seq_idx(iter, 0);
1653 1651
1654 while (++iter->ct < maxvif) { 1652 while (++iter->ct < maxvif) {
1655 if(!VIF_EXISTS(iter->ct)) 1653 if(!VIF_EXISTS(iter->ct))
1656 continue; 1654 continue;
@@ -1667,7 +1665,7 @@ static void ipmr_vif_seq_stop(struct seq_file *seq, void *v)
1667static int ipmr_vif_seq_show(struct seq_file *seq, void *v) 1665static int ipmr_vif_seq_show(struct seq_file *seq, void *v)
1668{ 1666{
1669 if (v == SEQ_START_TOKEN) { 1667 if (v == SEQ_START_TOKEN) {
1670 seq_puts(seq, 1668 seq_puts(seq,
1671 "Interface BytesIn PktsIn BytesOut PktsOut Flags Local Remote\n"); 1669 "Interface BytesIn PktsIn BytesOut PktsOut Flags Local Remote\n");
1672 } else { 1670 } else {
1673 const struct vif_device *vif = v; 1671 const struct vif_device *vif = v;
@@ -1676,7 +1674,7 @@ static int ipmr_vif_seq_show(struct seq_file *seq, void *v)
1676 seq_printf(seq, 1674 seq_printf(seq,
1677 "%2Zd %-10s %8ld %7ld %8ld %7ld %05X %08X %08X\n", 1675 "%2Zd %-10s %8ld %7ld %8ld %7ld %05X %08X %08X\n",
1678 vif - vif_table, 1676 vif - vif_table,
1679 name, vif->bytes_in, vif->pkt_in, 1677 name, vif->bytes_in, vif->pkt_in,
1680 vif->bytes_out, vif->pkt_out, 1678 vif->bytes_out, vif->pkt_out,
1681 vif->flags, vif->local, vif->remote); 1679 vif->flags, vif->local, vif->remote);
1682 } 1680 }
@@ -1695,7 +1693,7 @@ static int ipmr_vif_open(struct inode *inode, struct file *file)
1695 struct seq_file *seq; 1693 struct seq_file *seq;
1696 int rc = -ENOMEM; 1694 int rc = -ENOMEM;
1697 struct ipmr_vif_iter *s = kmalloc(sizeof(*s), GFP_KERNEL); 1695 struct ipmr_vif_iter *s = kmalloc(sizeof(*s), GFP_KERNEL);
1698 1696
1699 if (!s) 1697 if (!s)
1700 goto out; 1698 goto out;
1701 1699
@@ -1714,7 +1712,7 @@ out_kfree:
1714 1712
1715} 1713}
1716 1714
1717static struct file_operations ipmr_vif_fops = { 1715static const struct file_operations ipmr_vif_fops = {
1718 .owner = THIS_MODULE, 1716 .owner = THIS_MODULE,
1719 .open = ipmr_vif_open, 1717 .open = ipmr_vif_open,
1720 .read = seq_read, 1718 .read = seq_read,
@@ -1734,15 +1732,15 @@ static struct mfc_cache *ipmr_mfc_seq_idx(struct ipmr_mfc_iter *it, loff_t pos)
1734 1732
1735 it->cache = mfc_cache_array; 1733 it->cache = mfc_cache_array;
1736 read_lock(&mrt_lock); 1734 read_lock(&mrt_lock);
1737 for (it->ct = 0; it->ct < MFC_LINES; it->ct++) 1735 for (it->ct = 0; it->ct < MFC_LINES; it->ct++)
1738 for(mfc = mfc_cache_array[it->ct]; mfc; mfc = mfc->next) 1736 for(mfc = mfc_cache_array[it->ct]; mfc; mfc = mfc->next)
1739 if (pos-- == 0) 1737 if (pos-- == 0)
1740 return mfc; 1738 return mfc;
1741 read_unlock(&mrt_lock); 1739 read_unlock(&mrt_lock);
1742 1740
1743 it->cache = &mfc_unres_queue; 1741 it->cache = &mfc_unres_queue;
1744 spin_lock_bh(&mfc_unres_lock); 1742 spin_lock_bh(&mfc_unres_lock);
1745 for(mfc = mfc_unres_queue; mfc; mfc = mfc->next) 1743 for(mfc = mfc_unres_queue; mfc; mfc = mfc->next)
1746 if (pos-- == 0) 1744 if (pos-- == 0)
1747 return mfc; 1745 return mfc;
1748 spin_unlock_bh(&mfc_unres_lock); 1746 spin_unlock_bh(&mfc_unres_lock);
@@ -1757,7 +1755,7 @@ static void *ipmr_mfc_seq_start(struct seq_file *seq, loff_t *pos)
1757 struct ipmr_mfc_iter *it = seq->private; 1755 struct ipmr_mfc_iter *it = seq->private;
1758 it->cache = NULL; 1756 it->cache = NULL;
1759 it->ct = 0; 1757 it->ct = 0;
1760 return *pos ? ipmr_mfc_seq_idx(seq->private, *pos - 1) 1758 return *pos ? ipmr_mfc_seq_idx(seq->private, *pos - 1)
1761 : SEQ_START_TOKEN; 1759 : SEQ_START_TOKEN;
1762} 1760}
1763 1761
@@ -1773,8 +1771,8 @@ static void *ipmr_mfc_seq_next(struct seq_file *seq, void *v, loff_t *pos)
1773 1771
1774 if (mfc->next) 1772 if (mfc->next)
1775 return mfc->next; 1773 return mfc->next;
1776 1774
1777 if (it->cache == &mfc_unres_queue) 1775 if (it->cache == &mfc_unres_queue)
1778 goto end_of_list; 1776 goto end_of_list;
1779 1777
1780 BUG_ON(it->cache != mfc_cache_array); 1778 BUG_ON(it->cache != mfc_cache_array);
@@ -1789,10 +1787,10 @@ static void *ipmr_mfc_seq_next(struct seq_file *seq, void *v, loff_t *pos)
1789 read_unlock(&mrt_lock); 1787 read_unlock(&mrt_lock);
1790 it->cache = &mfc_unres_queue; 1788 it->cache = &mfc_unres_queue;
1791 it->ct = 0; 1789 it->ct = 0;
1792 1790
1793 spin_lock_bh(&mfc_unres_lock); 1791 spin_lock_bh(&mfc_unres_lock);
1794 mfc = mfc_unres_queue; 1792 mfc = mfc_unres_queue;
1795 if (mfc) 1793 if (mfc)
1796 return mfc; 1794 return mfc;
1797 1795
1798 end_of_list: 1796 end_of_list:
@@ -1817,12 +1815,12 @@ static int ipmr_mfc_seq_show(struct seq_file *seq, void *v)
1817 int n; 1815 int n;
1818 1816
1819 if (v == SEQ_START_TOKEN) { 1817 if (v == SEQ_START_TOKEN) {
1820 seq_puts(seq, 1818 seq_puts(seq,
1821 "Group Origin Iif Pkts Bytes Wrong Oifs\n"); 1819 "Group Origin Iif Pkts Bytes Wrong Oifs\n");
1822 } else { 1820 } else {
1823 const struct mfc_cache *mfc = v; 1821 const struct mfc_cache *mfc = v;
1824 const struct ipmr_mfc_iter *it = seq->private; 1822 const struct ipmr_mfc_iter *it = seq->private;
1825 1823
1826 seq_printf(seq, "%08lX %08lX %-3d %8ld %8ld %8ld", 1824 seq_printf(seq, "%08lX %08lX %-3d %8ld %8ld %8ld",
1827 (unsigned long) mfc->mfc_mcastgrp, 1825 (unsigned long) mfc->mfc_mcastgrp,
1828 (unsigned long) mfc->mfc_origin, 1826 (unsigned long) mfc->mfc_origin,
@@ -1832,12 +1830,12 @@ static int ipmr_mfc_seq_show(struct seq_file *seq, void *v)
1832 mfc->mfc_un.res.wrong_if); 1830 mfc->mfc_un.res.wrong_if);
1833 1831
1834 if (it->cache != &mfc_unres_queue) { 1832 if (it->cache != &mfc_unres_queue) {
1835 for(n = mfc->mfc_un.res.minvif; 1833 for(n = mfc->mfc_un.res.minvif;
1836 n < mfc->mfc_un.res.maxvif; n++ ) { 1834 n < mfc->mfc_un.res.maxvif; n++ ) {
1837 if(VIF_EXISTS(n) 1835 if(VIF_EXISTS(n)
1838 && mfc->mfc_un.res.ttls[n] < 255) 1836 && mfc->mfc_un.res.ttls[n] < 255)
1839 seq_printf(seq, 1837 seq_printf(seq,
1840 " %2d:%-3d", 1838 " %2d:%-3d",
1841 n, mfc->mfc_un.res.ttls[n]); 1839 n, mfc->mfc_un.res.ttls[n]);
1842 } 1840 }
1843 } 1841 }
@@ -1858,7 +1856,7 @@ static int ipmr_mfc_open(struct inode *inode, struct file *file)
1858 struct seq_file *seq; 1856 struct seq_file *seq;
1859 int rc = -ENOMEM; 1857 int rc = -ENOMEM;
1860 struct ipmr_mfc_iter *s = kmalloc(sizeof(*s), GFP_KERNEL); 1858 struct ipmr_mfc_iter *s = kmalloc(sizeof(*s), GFP_KERNEL);
1861 1859
1862 if (!s) 1860 if (!s)
1863 goto out; 1861 goto out;
1864 1862
@@ -1876,14 +1874,14 @@ out_kfree:
1876 1874
1877} 1875}
1878 1876
1879static struct file_operations ipmr_mfc_fops = { 1877static const struct file_operations ipmr_mfc_fops = {
1880 .owner = THIS_MODULE, 1878 .owner = THIS_MODULE,
1881 .open = ipmr_mfc_open, 1879 .open = ipmr_mfc_open,
1882 .read = seq_read, 1880 .read = seq_read,
1883 .llseek = seq_lseek, 1881 .llseek = seq_lseek,
1884 .release = seq_release_private, 1882 .release = seq_release_private,
1885}; 1883};
1886#endif 1884#endif
1887 1885
1888#ifdef CONFIG_IP_PIMSM_V2 1886#ifdef CONFIG_IP_PIMSM_V2
1889static struct net_protocol pim_protocol = { 1887static struct net_protocol pim_protocol = {
@@ -1895,7 +1893,7 @@ static struct net_protocol pim_protocol = {
1895/* 1893/*
1896 * Setup for IP multicast routing 1894 * Setup for IP multicast routing
1897 */ 1895 */
1898 1896
1899void __init ip_mr_init(void) 1897void __init ip_mr_init(void)
1900{ 1898{
1901 mrt_cachep = kmem_cache_create("ip_mrt_cache", 1899 mrt_cachep = kmem_cache_create("ip_mrt_cache",
@@ -1905,8 +1903,8 @@ void __init ip_mr_init(void)
1905 init_timer(&ipmr_expire_timer); 1903 init_timer(&ipmr_expire_timer);
1906 ipmr_expire_timer.function=ipmr_expire_process; 1904 ipmr_expire_timer.function=ipmr_expire_process;
1907 register_netdevice_notifier(&ip_mr_notifier); 1905 register_netdevice_notifier(&ip_mr_notifier);
1908#ifdef CONFIG_PROC_FS 1906#ifdef CONFIG_PROC_FS
1909 proc_net_fops_create("ip_mr_vif", 0, &ipmr_vif_fops); 1907 proc_net_fops_create("ip_mr_vif", 0, &ipmr_vif_fops);
1910 proc_net_fops_create("ip_mr_cache", 0, &ipmr_mfc_fops); 1908 proc_net_fops_create("ip_mr_cache", 0, &ipmr_mfc_fops);
1911#endif 1909#endif
1912} 1910}
diff --git a/net/ipv4/ipvs/ip_vs_app.c b/net/ipv4/ipvs/ip_vs_app.c
index 6c40899aa161..22e104c6a493 100644
--- a/net/ipv4/ipvs/ip_vs_app.c
+++ b/net/ipv4/ipvs/ip_vs_app.c
@@ -561,7 +561,7 @@ static int ip_vs_app_open(struct inode *inode, struct file *file)
561 return seq_open(file, &ip_vs_app_seq_ops); 561 return seq_open(file, &ip_vs_app_seq_ops);
562} 562}
563 563
564static struct file_operations ip_vs_app_fops = { 564static const struct file_operations ip_vs_app_fops = {
565 .owner = THIS_MODULE, 565 .owner = THIS_MODULE,
566 .open = ip_vs_app_open, 566 .open = ip_vs_app_open,
567 .read = seq_read, 567 .read = seq_read,
diff --git a/net/ipv4/ipvs/ip_vs_conn.c b/net/ipv4/ipvs/ip_vs_conn.c
index 8086787a2c51..7018f97c75dc 100644
--- a/net/ipv4/ipvs/ip_vs_conn.c
+++ b/net/ipv4/ipvs/ip_vs_conn.c
@@ -494,8 +494,8 @@ int ip_vs_check_template(struct ip_vs_conn *ct)
494 * Checking the dest server status. 494 * Checking the dest server status.
495 */ 495 */
496 if ((dest == NULL) || 496 if ((dest == NULL) ||
497 !(dest->flags & IP_VS_DEST_F_AVAILABLE) || 497 !(dest->flags & IP_VS_DEST_F_AVAILABLE) ||
498 (sysctl_ip_vs_expire_quiescent_template && 498 (sysctl_ip_vs_expire_quiescent_template &&
499 (atomic_read(&dest->weight) == 0))) { 499 (atomic_read(&dest->weight) == 0))) {
500 IP_VS_DBG(9, "check_template: dest not available for " 500 IP_VS_DBG(9, "check_template: dest not available for "
501 "protocol %s s:%u.%u.%u.%u:%d v:%u.%u.%u.%u:%d " 501 "protocol %s s:%u.%u.%u.%u:%d v:%u.%u.%u.%u:%d "
@@ -603,13 +603,12 @@ ip_vs_conn_new(int proto, __be32 caddr, __be16 cport, __be32 vaddr, __be16 vport
603 struct ip_vs_conn *cp; 603 struct ip_vs_conn *cp;
604 struct ip_vs_protocol *pp = ip_vs_proto_get(proto); 604 struct ip_vs_protocol *pp = ip_vs_proto_get(proto);
605 605
606 cp = kmem_cache_alloc(ip_vs_conn_cachep, GFP_ATOMIC); 606 cp = kmem_cache_zalloc(ip_vs_conn_cachep, GFP_ATOMIC);
607 if (cp == NULL) { 607 if (cp == NULL) {
608 IP_VS_ERR_RL("ip_vs_conn_new: no memory available.\n"); 608 IP_VS_ERR_RL("ip_vs_conn_new: no memory available.\n");
609 return NULL; 609 return NULL;
610 } 610 }
611 611
612 memset(cp, 0, sizeof(*cp));
613 INIT_LIST_HEAD(&cp->c_list); 612 INIT_LIST_HEAD(&cp->c_list);
614 init_timer(&cp->timer); 613 init_timer(&cp->timer);
615 cp->timer.data = (unsigned long)cp; 614 cp->timer.data = (unsigned long)cp;
@@ -667,7 +666,7 @@ static void *ip_vs_conn_array(struct seq_file *seq, loff_t pos)
667{ 666{
668 int idx; 667 int idx;
669 struct ip_vs_conn *cp; 668 struct ip_vs_conn *cp;
670 669
671 for(idx = 0; idx < IP_VS_CONN_TAB_SIZE; idx++) { 670 for(idx = 0; idx < IP_VS_CONN_TAB_SIZE; idx++) {
672 ct_read_lock_bh(idx); 671 ct_read_lock_bh(idx);
673 list_for_each_entry(cp, &ip_vs_conn_tab[idx], c_list) { 672 list_for_each_entry(cp, &ip_vs_conn_tab[idx], c_list) {
@@ -695,7 +694,7 @@ static void *ip_vs_conn_seq_next(struct seq_file *seq, void *v, loff_t *pos)
695 int idx; 694 int idx;
696 695
697 ++*pos; 696 ++*pos;
698 if (v == SEQ_START_TOKEN) 697 if (v == SEQ_START_TOKEN)
699 return ip_vs_conn_array(seq, 0); 698 return ip_vs_conn_array(seq, 0);
700 699
701 /* more on same hash chain? */ 700 /* more on same hash chain? */
@@ -710,7 +709,7 @@ static void *ip_vs_conn_seq_next(struct seq_file *seq, void *v, loff_t *pos)
710 list_for_each_entry(cp, &ip_vs_conn_tab[idx], c_list) { 709 list_for_each_entry(cp, &ip_vs_conn_tab[idx], c_list) {
711 seq->private = &ip_vs_conn_tab[idx]; 710 seq->private = &ip_vs_conn_tab[idx];
712 return cp; 711 return cp;
713 } 712 }
714 ct_read_unlock_bh(idx); 713 ct_read_unlock_bh(idx);
715 } 714 }
716 seq->private = NULL; 715 seq->private = NULL;
@@ -758,7 +757,7 @@ static int ip_vs_conn_open(struct inode *inode, struct file *file)
758 return seq_open(file, &ip_vs_conn_seq_ops); 757 return seq_open(file, &ip_vs_conn_seq_ops);
759} 758}
760 759
761static struct file_operations ip_vs_conn_fops = { 760static const struct file_operations ip_vs_conn_fops = {
762 .owner = THIS_MODULE, 761 .owner = THIS_MODULE,
763 .open = ip_vs_conn_open, 762 .open = ip_vs_conn_open,
764 .read = seq_read, 763 .read = seq_read,
diff --git a/net/ipv4/ipvs/ip_vs_core.c b/net/ipv4/ipvs/ip_vs_core.c
index 34257520a3a6..24d7b66eb6d2 100644
--- a/net/ipv4/ipvs/ip_vs_core.c
+++ b/net/ipv4/ipvs/ip_vs_core.c
@@ -813,14 +813,14 @@ ip_vs_out(unsigned int hooknum, struct sk_buff **pskb,
813 skb->nh.iph->saddr = cp->vaddr; 813 skb->nh.iph->saddr = cp->vaddr;
814 ip_send_check(skb->nh.iph); 814 ip_send_check(skb->nh.iph);
815 815
816 /* For policy routing, packets originating from this 816 /* For policy routing, packets originating from this
817 * machine itself may be routed differently to packets 817 * machine itself may be routed differently to packets
818 * passing through. We want this packet to be routed as 818 * passing through. We want this packet to be routed as
819 * if it came from this machine itself. So re-compute 819 * if it came from this machine itself. So re-compute
820 * the routing information. 820 * the routing information.
821 */ 821 */
822 if (ip_route_me_harder(pskb, RTN_LOCAL) != 0) 822 if (ip_route_me_harder(pskb, RTN_LOCAL) != 0)
823 goto drop; 823 goto drop;
824 skb = *pskb; 824 skb = *pskb;
825 825
826 IP_VS_DBG_PKT(10, pp, skb, 0, "After SNAT"); 826 IP_VS_DBG_PKT(10, pp, skb, 0, "After SNAT");
@@ -847,7 +847,7 @@ ip_vs_out(unsigned int hooknum, struct sk_buff **pskb,
847 * forward to the right destination host if relevant. 847 * forward to the right destination host if relevant.
848 * Currently handles error types - unreachable, quench, ttl exceeded. 848 * Currently handles error types - unreachable, quench, ttl exceeded.
849 */ 849 */
850static int 850static int
851ip_vs_in_icmp(struct sk_buff **pskb, int *related, unsigned int hooknum) 851ip_vs_in_icmp(struct sk_buff **pskb, int *related, unsigned int hooknum)
852{ 852{
853 struct sk_buff *skb = *pskb; 853 struct sk_buff *skb = *pskb;
@@ -863,7 +863,7 @@ ip_vs_in_icmp(struct sk_buff **pskb, int *related, unsigned int hooknum)
863 /* reassemble IP fragments */ 863 /* reassemble IP fragments */
864 if (skb->nh.iph->frag_off & __constant_htons(IP_MF|IP_OFFSET)) { 864 if (skb->nh.iph->frag_off & __constant_htons(IP_MF|IP_OFFSET)) {
865 skb = ip_vs_gather_frags(skb, 865 skb = ip_vs_gather_frags(skb,
866 hooknum == NF_IP_LOCAL_IN ? 866 hooknum == NF_IP_LOCAL_IN ?
867 IP_DEFRAG_VS_IN : IP_DEFRAG_VS_FWD); 867 IP_DEFRAG_VS_IN : IP_DEFRAG_VS_FWD);
868 if (!skb) 868 if (!skb)
869 return NF_STOLEN; 869 return NF_STOLEN;
diff --git a/net/ipv4/ipvs/ip_vs_ctl.c b/net/ipv4/ipvs/ip_vs_ctl.c
index 9b933381ebbe..8b08d9cdcbc8 100644
--- a/net/ipv4/ipvs/ip_vs_ctl.c
+++ b/net/ipv4/ipvs/ip_vs_ctl.c
@@ -1812,7 +1812,7 @@ out_kfree:
1812 goto out; 1812 goto out;
1813} 1813}
1814 1814
1815static struct file_operations ip_vs_info_fops = { 1815static const struct file_operations ip_vs_info_fops = {
1816 .owner = THIS_MODULE, 1816 .owner = THIS_MODULE,
1817 .open = ip_vs_info_open, 1817 .open = ip_vs_info_open,
1818 .read = seq_read, 1818 .read = seq_read,
@@ -1859,7 +1859,7 @@ static int ip_vs_stats_seq_open(struct inode *inode, struct file *file)
1859 return single_open(file, ip_vs_stats_show, NULL); 1859 return single_open(file, ip_vs_stats_show, NULL);
1860} 1860}
1861 1861
1862static struct file_operations ip_vs_stats_fops = { 1862static const struct file_operations ip_vs_stats_fops = {
1863 .owner = THIS_MODULE, 1863 .owner = THIS_MODULE,
1864 .open = ip_vs_stats_seq_open, 1864 .open = ip_vs_stats_seq_open,
1865 .read = seq_read, 1865 .read = seq_read,
diff --git a/net/ipv4/ipvs/ip_vs_ftp.c b/net/ipv4/ipvs/ip_vs_ftp.c
index 687c1de1146f..847c47af040c 100644
--- a/net/ipv4/ipvs/ip_vs_ftp.c
+++ b/net/ipv4/ipvs/ip_vs_ftp.c
@@ -370,7 +370,7 @@ static int __init ip_vs_ftp_init(void)
370 if (ret) 370 if (ret)
371 break; 371 break;
372 IP_VS_INFO("%s: loaded support on port[%d] = %d\n", 372 IP_VS_INFO("%s: loaded support on port[%d] = %d\n",
373 app->name, i, ports[i]); 373 app->name, i, ports[i]);
374 } 374 }
375 375
376 if (ret) 376 if (ret)
diff --git a/net/ipv4/ipvs/ip_vs_lblc.c b/net/ipv4/ipvs/ip_vs_lblc.c
index a4385a2180ee..76fd1fb91878 100644
--- a/net/ipv4/ipvs/ip_vs_lblc.c
+++ b/net/ipv4/ipvs/ip_vs_lblc.c
@@ -118,7 +118,7 @@ static ctl_table vs_vars_table[] = {
118 .procname = "lblc_expiration", 118 .procname = "lblc_expiration",
119 .data = &sysctl_ip_vs_lblc_expiration, 119 .data = &sysctl_ip_vs_lblc_expiration,
120 .maxlen = sizeof(int), 120 .maxlen = sizeof(int),
121 .mode = 0644, 121 .mode = 0644,
122 .proc_handler = &proc_dointvec_jiffies, 122 .proc_handler = &proc_dointvec_jiffies,
123 }, 123 },
124 { .ctl_name = 0 } 124 { .ctl_name = 0 }
@@ -128,7 +128,7 @@ static ctl_table vs_table[] = {
128 { 128 {
129 .ctl_name = NET_IPV4_VS, 129 .ctl_name = NET_IPV4_VS,
130 .procname = "vs", 130 .procname = "vs",
131 .mode = 0555, 131 .mode = 0555,
132 .child = vs_vars_table 132 .child = vs_vars_table
133 }, 133 },
134 { .ctl_name = 0 } 134 { .ctl_name = 0 }
@@ -137,7 +137,7 @@ static ctl_table vs_table[] = {
137static ctl_table ipvs_ipv4_table[] = { 137static ctl_table ipvs_ipv4_table[] = {
138 { 138 {
139 .ctl_name = NET_IPV4, 139 .ctl_name = NET_IPV4,
140 .procname = "ipv4", 140 .procname = "ipv4",
141 .mode = 0555, 141 .mode = 0555,
142 .child = vs_table 142 .child = vs_table
143 }, 143 },
@@ -147,8 +147,8 @@ static ctl_table ipvs_ipv4_table[] = {
147static ctl_table lblc_root_table[] = { 147static ctl_table lblc_root_table[] = {
148 { 148 {
149 .ctl_name = CTL_NET, 149 .ctl_name = CTL_NET,
150 .procname = "net", 150 .procname = "net",
151 .mode = 0555, 151 .mode = 0555,
152 .child = ipvs_ipv4_table 152 .child = ipvs_ipv4_table
153 }, 153 },
154 { .ctl_name = 0 } 154 { .ctl_name = 0 }
@@ -288,7 +288,7 @@ static inline void ip_vs_lblc_full_check(struct ip_vs_lblc_table *tbl)
288 288
289 write_lock(&tbl->lock); 289 write_lock(&tbl->lock);
290 list_for_each_entry_safe(en, nxt, &tbl->bucket[j], list) { 290 list_for_each_entry_safe(en, nxt, &tbl->bucket[j], list) {
291 if (time_before(now, 291 if (time_before(now,
292 en->lastuse + sysctl_ip_vs_lblc_expiration)) 292 en->lastuse + sysctl_ip_vs_lblc_expiration))
293 continue; 293 continue;
294 294
diff --git a/net/ipv4/ipvs/ip_vs_lblcr.c b/net/ipv4/ipvs/ip_vs_lblcr.c
index fe1af5d079af..bf1e7f272b84 100644
--- a/net/ipv4/ipvs/ip_vs_lblcr.c
+++ b/net/ipv4/ipvs/ip_vs_lblcr.c
@@ -307,7 +307,7 @@ static ctl_table vs_vars_table[] = {
307 .procname = "lblcr_expiration", 307 .procname = "lblcr_expiration",
308 .data = &sysctl_ip_vs_lblcr_expiration, 308 .data = &sysctl_ip_vs_lblcr_expiration,
309 .maxlen = sizeof(int), 309 .maxlen = sizeof(int),
310 .mode = 0644, 310 .mode = 0644,
311 .proc_handler = &proc_dointvec_jiffies, 311 .proc_handler = &proc_dointvec_jiffies,
312 }, 312 },
313 { .ctl_name = 0 } 313 { .ctl_name = 0 }
@@ -326,7 +326,7 @@ static ctl_table vs_table[] = {
326static ctl_table ipvs_ipv4_table[] = { 326static ctl_table ipvs_ipv4_table[] = {
327 { 327 {
328 .ctl_name = NET_IPV4, 328 .ctl_name = NET_IPV4,
329 .procname = "ipv4", 329 .procname = "ipv4",
330 .mode = 0555, 330 .mode = 0555,
331 .child = vs_table 331 .child = vs_table
332 }, 332 },
@@ -336,8 +336,8 @@ static ctl_table ipvs_ipv4_table[] = {
336static ctl_table lblcr_root_table[] = { 336static ctl_table lblcr_root_table[] = {
337 { 337 {
338 .ctl_name = CTL_NET, 338 .ctl_name = CTL_NET,
339 .procname = "net", 339 .procname = "net",
340 .mode = 0555, 340 .mode = 0555,
341 .child = ipvs_ipv4_table 341 .child = ipvs_ipv4_table
342 }, 342 },
343 { .ctl_name = 0 } 343 { .ctl_name = 0 }
diff --git a/net/ipv4/ipvs/ip_vs_rr.c b/net/ipv4/ipvs/ip_vs_rr.c
index b23bab231cab..433f8a947924 100644
--- a/net/ipv4/ipvs/ip_vs_rr.c
+++ b/net/ipv4/ipvs/ip_vs_rr.c
@@ -68,7 +68,7 @@ ip_vs_rr_schedule(struct ip_vs_service *svc, const struct sk_buff *skb)
68 q = q->next; 68 q = q->next;
69 continue; 69 continue;
70 } 70 }
71 71
72 dest = list_entry(q, struct ip_vs_dest, n_list); 72 dest = list_entry(q, struct ip_vs_dest, n_list);
73 if (!(dest->flags & IP_VS_DEST_F_OVERLOAD) && 73 if (!(dest->flags & IP_VS_DEST_F_OVERLOAD) &&
74 atomic_read(&dest->weight) > 0) 74 atomic_read(&dest->weight) > 0)
diff --git a/net/ipv4/multipath_drr.c b/net/ipv4/multipath_drr.c
index 252e837b17a5..cb8fce467349 100644
--- a/net/ipv4/multipath_drr.c
+++ b/net/ipv4/multipath_drr.c
@@ -134,7 +134,7 @@ static void drr_select_route(const struct flowi *flp,
134 struct rtable *first, struct rtable **rp) 134 struct rtable *first, struct rtable **rp)
135{ 135{
136 struct rtable *nh, *result, *cur_min; 136 struct rtable *nh, *result, *cur_min;
137 int min_usecount = -1; 137 int min_usecount = -1;
138 int devidx = -1; 138 int devidx = -1;
139 int cur_min_devidx = -1; 139 int cur_min_devidx = -1;
140 140
@@ -143,7 +143,7 @@ static void drr_select_route(const struct flowi *flp,
143 result = NULL; 143 result = NULL;
144 cur_min = NULL; 144 cur_min = NULL;
145 for (nh = rcu_dereference(first); nh; 145 for (nh = rcu_dereference(first); nh;
146 nh = rcu_dereference(nh->u.rt_next)) { 146 nh = rcu_dereference(nh->u.dst.rt_next)) {
147 if ((nh->u.dst.flags & DST_BALANCED) != 0 && 147 if ((nh->u.dst.flags & DST_BALANCED) != 0 &&
148 multipath_comparekeys(&nh->fl, flp)) { 148 multipath_comparekeys(&nh->fl, flp)) {
149 int nh_ifidx = nh->u.dst.dev->ifindex; 149 int nh_ifidx = nh->u.dst.dev->ifindex;
@@ -161,7 +161,7 @@ static void drr_select_route(const struct flowi *flp,
161 */ 161 */
162 devidx = __multipath_finddev(nh_ifidx); 162 devidx = __multipath_finddev(nh_ifidx);
163 if (devidx == -1) { 163 if (devidx == -1) {
164 /* add the interface to the array 164 /* add the interface to the array
165 * SMP safe 165 * SMP safe
166 */ 166 */
167 spin_lock_bh(&state_lock); 167 spin_lock_bh(&state_lock);
diff --git a/net/ipv4/multipath_random.c b/net/ipv4/multipath_random.c
index b8c289f247cb..047e861f06bd 100644
--- a/net/ipv4/multipath_random.c
+++ b/net/ipv4/multipath_random.c
@@ -74,7 +74,7 @@ static void random_select_route(const struct flowi *flp,
74 74
75 /* count all candidate */ 75 /* count all candidate */
76 for (rt = rcu_dereference(first); rt; 76 for (rt = rcu_dereference(first); rt;
77 rt = rcu_dereference(rt->u.rt_next)) { 77 rt = rcu_dereference(rt->u.dst.rt_next)) {
78 if ((rt->u.dst.flags & DST_BALANCED) != 0 && 78 if ((rt->u.dst.flags & DST_BALANCED) != 0 &&
79 multipath_comparekeys(&rt->fl, flp)) 79 multipath_comparekeys(&rt->fl, flp))
80 ++candidate_count; 80 ++candidate_count;
@@ -90,7 +90,7 @@ static void random_select_route(const struct flowi *flp,
90 /* find chosen candidate and adjust GC data for all candidates 90 /* find chosen candidate and adjust GC data for all candidates
91 * to ensure they stay in cache 91 * to ensure they stay in cache
92 */ 92 */
93 for (rt = first; rt; rt = rt->u.rt_next) { 93 for (rt = first; rt; rt = rt->u.dst.rt_next) {
94 if ((rt->u.dst.flags & DST_BALANCED) != 0 && 94 if ((rt->u.dst.flags & DST_BALANCED) != 0 &&
95 multipath_comparekeys(&rt->fl, flp)) { 95 multipath_comparekeys(&rt->fl, flp)) {
96 rt->u.dst.lastuse = jiffies; 96 rt->u.dst.lastuse = jiffies;
diff --git a/net/ipv4/multipath_rr.c b/net/ipv4/multipath_rr.c
index bba5abe5542d..896246d8040e 100644
--- a/net/ipv4/multipath_rr.c
+++ b/net/ipv4/multipath_rr.c
@@ -58,7 +58,7 @@ static void rr_select_route(const struct flowi *flp,
58 */ 58 */
59 result = NULL; 59 result = NULL;
60 for (nh = rcu_dereference(first); nh; 60 for (nh = rcu_dereference(first); nh;
61 nh = rcu_dereference(nh->u.rt_next)) { 61 nh = rcu_dereference(nh->u.dst.rt_next)) {
62 if ((nh->u.dst.flags & DST_BALANCED) != 0 && 62 if ((nh->u.dst.flags & DST_BALANCED) != 0 &&
63 multipath_comparekeys(&nh->fl, flp)) { 63 multipath_comparekeys(&nh->fl, flp)) {
64 nh->u.dst.lastuse = jiffies; 64 nh->u.dst.lastuse = jiffies;
diff --git a/net/ipv4/multipath_wrandom.c b/net/ipv4/multipath_wrandom.c
index 92b04823e034..7e22f15d13df 100644
--- a/net/ipv4/multipath_wrandom.c
+++ b/net/ipv4/multipath_wrandom.c
@@ -142,7 +142,7 @@ out:
142 return weight; 142 return weight;
143} 143}
144 144
145static void wrandom_init_state(void) 145static void wrandom_init_state(void)
146{ 146{
147 int i; 147 int i;
148 148
@@ -167,7 +167,7 @@ static void wrandom_select_route(const struct flowi *flp,
167 167
168 /* collect all candidates and identify their weights */ 168 /* collect all candidates and identify their weights */
169 for (rt = rcu_dereference(first); rt; 169 for (rt = rcu_dereference(first); rt;
170 rt = rcu_dereference(rt->u.rt_next)) { 170 rt = rcu_dereference(rt->u.dst.rt_next)) {
171 if ((rt->u.dst.flags & DST_BALANCED) != 0 && 171 if ((rt->u.dst.flags & DST_BALANCED) != 0 &&
172 multipath_comparekeys(&rt->fl, flp)) { 172 multipath_comparekeys(&rt->fl, flp)) {
173 struct multipath_candidate* mpc = 173 struct multipath_candidate* mpc =
@@ -287,7 +287,7 @@ static void __multipath_free(struct rcu_head *head)
287 287
288static void __multipath_free_dst(struct rcu_head *head) 288static void __multipath_free_dst(struct rcu_head *head)
289{ 289{
290 struct multipath_dest *dst = container_of(head, 290 struct multipath_dest *dst = container_of(head,
291 struct multipath_dest, 291 struct multipath_dest,
292 rcu); 292 rcu);
293 kfree(dst); 293 kfree(dst);
diff --git a/net/ipv4/netfilter.c b/net/ipv4/netfilter.c
index c47ce7076bd5..6069a11514f6 100644
--- a/net/ipv4/netfilter.c
+++ b/net/ipv4/netfilter.c
@@ -53,7 +53,7 @@ int ip_route_me_harder(struct sk_buff **pskb, unsigned addr_type)
53 dst_release(&rt->u.dst); 53 dst_release(&rt->u.dst);
54 dst_release(odst); 54 dst_release(odst);
55 } 55 }
56 56
57 if ((*pskb)->dst->error) 57 if ((*pskb)->dst->error)
58 return -1; 58 return -1;
59 59
@@ -70,7 +70,7 @@ int ip_route_me_harder(struct sk_buff **pskb, unsigned addr_type)
70 struct sk_buff *nskb; 70 struct sk_buff *nskb;
71 71
72 nskb = skb_realloc_headroom(*pskb, hh_len); 72 nskb = skb_realloc_headroom(*pskb, hh_len);
73 if (!nskb) 73 if (!nskb)
74 return -1; 74 return -1;
75 if ((*pskb)->sk) 75 if ((*pskb)->sk)
76 skb_set_owner_w(nskb, (*pskb)->sk); 76 skb_set_owner_w(nskb, (*pskb)->sk);
@@ -177,7 +177,7 @@ __sum16 nf_ip_checksum(struct sk_buff *skb, unsigned int hook,
177 break; 177 break;
178 if ((protocol == 0 && !csum_fold(skb->csum)) || 178 if ((protocol == 0 && !csum_fold(skb->csum)) ||
179 !csum_tcpudp_magic(iph->saddr, iph->daddr, 179 !csum_tcpudp_magic(iph->saddr, iph->daddr,
180 skb->len - dataoff, protocol, 180 skb->len - dataoff, protocol,
181 skb->csum)) { 181 skb->csum)) {
182 skb->ip_summed = CHECKSUM_UNNECESSARY; 182 skb->ip_summed = CHECKSUM_UNNECESSARY;
183 break; 183 break;
diff --git a/net/ipv4/netfilter/Kconfig b/net/ipv4/netfilter/Kconfig
index 47bd3ad18b71..601808c796ec 100644
--- a/net/ipv4/netfilter/Kconfig
+++ b/net/ipv4/netfilter/Kconfig
@@ -226,7 +226,7 @@ config IP_NF_QUEUE
226 226
227config IP_NF_IPTABLES 227config IP_NF_IPTABLES
228 tristate "IP tables support (required for filtering/masq/NAT)" 228 tristate "IP tables support (required for filtering/masq/NAT)"
229 depends on NETFILTER_XTABLES 229 select NETFILTER_XTABLES
230 help 230 help
231 iptables is a general, extensible packet identification framework. 231 iptables is a general, extensible packet identification framework.
232 The packet filtering and full NAT (masquerading, port forwarding, 232 The packet filtering and full NAT (masquerading, port forwarding,
@@ -361,32 +361,6 @@ config IP_NF_TARGET_ULOG
361 361
362 To compile it as a module, choose M here. If unsure, say N. 362 To compile it as a module, choose M here. If unsure, say N.
363 363
364config IP_NF_TARGET_TCPMSS
365 tristate "TCPMSS target support"
366 depends on IP_NF_IPTABLES
367 ---help---
368 This option adds a `TCPMSS' target, which allows you to alter the
369 MSS value of TCP SYN packets, to control the maximum size for that
370 connection (usually limiting it to your outgoing interface's MTU
371 minus 40).
372
373 This is used to overcome criminally braindead ISPs or servers which
374 block ICMP Fragmentation Needed packets. The symptoms of this
375 problem are that everything works fine from your Linux
376 firewall/router, but machines behind it can never exchange large
377 packets:
378 1) Web browsers connect, then hang with no data received.
379 2) Small mail works fine, but large emails hang.
380 3) ssh works fine, but scp hangs after initial handshaking.
381
382 Workaround: activate this option and add a rule to your firewall
383 configuration like:
384
385 iptables -A FORWARD -p tcp --tcp-flags SYN,RST SYN \
386 -j TCPMSS --clamp-mss-to-pmtu
387
388 To compile it as a module, choose M here. If unsure, say N.
389
390# NAT + specific targets: ip_conntrack 364# NAT + specific targets: ip_conntrack
391config IP_NF_NAT 365config IP_NF_NAT
392 tristate "Full NAT" 366 tristate "Full NAT"
@@ -632,7 +606,9 @@ config IP_NF_TARGET_TTL
632config IP_NF_TARGET_CLUSTERIP 606config IP_NF_TARGET_CLUSTERIP
633 tristate "CLUSTERIP target support (EXPERIMENTAL)" 607 tristate "CLUSTERIP target support (EXPERIMENTAL)"
634 depends on IP_NF_MANGLE && EXPERIMENTAL 608 depends on IP_NF_MANGLE && EXPERIMENTAL
635 depends on (IP_NF_CONNTRACK && IP_NF_CONNTRACK_MARK) || (NF_CONNTRACK_MARK && NF_CONNTRACK_IPV4) 609 depends on IP_NF_CONNTRACK || NF_CONNTRACK_IPV4
610 select IP_NF_CONNTRACK_MARK if IP_NF_CONNTRACK
611 select NF_CONNTRACK_MARK if NF_CONNTRACK_IPV4
636 help 612 help
637 The CLUSTERIP target allows you to build load-balancing clusters of 613 The CLUSTERIP target allows you to build load-balancing clusters of
638 network servers without having a dedicated load-balancing 614 network servers without having a dedicated load-balancing
@@ -655,7 +631,7 @@ config IP_NF_RAW
655# ARP tables 631# ARP tables
656config IP_NF_ARPTABLES 632config IP_NF_ARPTABLES
657 tristate "ARP tables support" 633 tristate "ARP tables support"
658 depends on NETFILTER_XTABLES 634 select NETFILTER_XTABLES
659 help 635 help
660 arptables is a general, extensible packet identification framework. 636 arptables is a general, extensible packet identification framework.
661 The ARP packet filtering and mangling (manipulation)subsystems 637 The ARP packet filtering and mangling (manipulation)subsystems
diff --git a/net/ipv4/netfilter/Makefile b/net/ipv4/netfilter/Makefile
index 16d177b71bf8..6625ec68180c 100644
--- a/net/ipv4/netfilter/Makefile
+++ b/net/ipv4/netfilter/Makefile
@@ -103,7 +103,6 @@ obj-$(CONFIG_IP_NF_TARGET_SAME) += ipt_SAME.o
103obj-$(CONFIG_IP_NF_NAT_SNMP_BASIC) += ip_nat_snmp_basic.o 103obj-$(CONFIG_IP_NF_NAT_SNMP_BASIC) += ip_nat_snmp_basic.o
104obj-$(CONFIG_IP_NF_TARGET_LOG) += ipt_LOG.o 104obj-$(CONFIG_IP_NF_TARGET_LOG) += ipt_LOG.o
105obj-$(CONFIG_IP_NF_TARGET_ULOG) += ipt_ULOG.o 105obj-$(CONFIG_IP_NF_TARGET_ULOG) += ipt_ULOG.o
106obj-$(CONFIG_IP_NF_TARGET_TCPMSS) += ipt_TCPMSS.o
107obj-$(CONFIG_IP_NF_TARGET_CLUSTERIP) += ipt_CLUSTERIP.o 106obj-$(CONFIG_IP_NF_TARGET_CLUSTERIP) += ipt_CLUSTERIP.o
108obj-$(CONFIG_IP_NF_TARGET_TTL) += ipt_TTL.o 107obj-$(CONFIG_IP_NF_TARGET_TTL) += ipt_TTL.o
109 108
diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
index 9aa22398b3dc..5170f5c75f9d 100644
--- a/net/ipv4/netfilter/arp_tables.c
+++ b/net/ipv4/netfilter/arp_tables.c
@@ -544,7 +544,7 @@ static inline int check_entry_size_and_hooks(struct arpt_entry *e,
544 } 544 }
545 545
546 /* FIXME: underflows must be unconditional, standard verdicts 546 /* FIXME: underflows must be unconditional, standard verdicts
547 < 0 (not ARPT_RETURN). --RR */ 547 < 0 (not ARPT_RETURN). --RR */
548 548
549 /* Clear counters and comefrom */ 549 /* Clear counters and comefrom */
550 e->counters = ((struct xt_counters) { 0, 0 }); 550 e->counters = ((struct xt_counters) { 0, 0 });
@@ -869,8 +869,8 @@ static int do_replace(void __user *user, unsigned int len)
869 /* Update module usage count based on number of rules */ 869 /* Update module usage count based on number of rules */
870 duprintf("do_replace: oldnum=%u, initnum=%u, newnum=%u\n", 870 duprintf("do_replace: oldnum=%u, initnum=%u, newnum=%u\n",
871 oldinfo->number, oldinfo->initial_entries, newinfo->number); 871 oldinfo->number, oldinfo->initial_entries, newinfo->number);
872 if ((oldinfo->number > oldinfo->initial_entries) || 872 if ((oldinfo->number > oldinfo->initial_entries) ||
873 (newinfo->number <= oldinfo->initial_entries)) 873 (newinfo->number <= oldinfo->initial_entries))
874 module_put(t->me); 874 module_put(t->me);
875 if ((oldinfo->number > oldinfo->initial_entries) && 875 if ((oldinfo->number > oldinfo->initial_entries) &&
876 (newinfo->number <= oldinfo->initial_entries)) 876 (newinfo->number <= oldinfo->initial_entries))
diff --git a/net/ipv4/netfilter/arpt_mangle.c b/net/ipv4/netfilter/arpt_mangle.c
index d12b1df252a1..709db4d3f48f 100644
--- a/net/ipv4/netfilter/arpt_mangle.c
+++ b/net/ipv4/netfilter/arpt_mangle.c
@@ -67,7 +67,7 @@ target(struct sk_buff **pskb,
67 67
68static int 68static int
69checkentry(const char *tablename, const void *e, const struct xt_target *target, 69checkentry(const char *tablename, const void *e, const struct xt_target *target,
70 void *targinfo, unsigned int hook_mask) 70 void *targinfo, unsigned int hook_mask)
71{ 71{
72 const struct arpt_mangle *mangle = targinfo; 72 const struct arpt_mangle *mangle = targinfo;
73 73
diff --git a/net/ipv4/netfilter/ip_conntrack_amanda.c b/net/ipv4/netfilter/ip_conntrack_amanda.c
index ad246ba7790b..4f561f52c83a 100644
--- a/net/ipv4/netfilter/ip_conntrack_amanda.c
+++ b/net/ipv4/netfilter/ip_conntrack_amanda.c
@@ -9,7 +9,7 @@
9 * 9 *
10 * Module load syntax: 10 * Module load syntax:
11 * insmod ip_conntrack_amanda.o [master_timeout=n] 11 * insmod ip_conntrack_amanda.o [master_timeout=n]
12 * 12 *
13 * Where master_timeout is the timeout (in seconds) of the master 13 * Where master_timeout is the timeout (in seconds) of the master
14 * connection (port 10080). This defaults to 5 minutes but if 14 * connection (port 10080). This defaults to 5 minutes but if
15 * your clients take longer than 5 minutes to do their work 15 * your clients take longer than 5 minutes to do their work
@@ -84,7 +84,7 @@ static struct {
84}; 84};
85 85
86static int help(struct sk_buff **pskb, 86static int help(struct sk_buff **pskb,
87 struct ip_conntrack *ct, enum ip_conntrack_info ctinfo) 87 struct ip_conntrack *ct, enum ip_conntrack_info ctinfo)
88{ 88{
89 struct ts_state ts; 89 struct ts_state ts;
90 struct ip_conntrack_expect *exp; 90 struct ip_conntrack_expect *exp;
diff --git a/net/ipv4/netfilter/ip_conntrack_core.c b/net/ipv4/netfilter/ip_conntrack_core.c
index 8556a4f4f60a..07ba1dd136b5 100644
--- a/net/ipv4/netfilter/ip_conntrack_core.c
+++ b/net/ipv4/netfilter/ip_conntrack_core.c
@@ -2,7 +2,7 @@
2 but required by, the NAT layer; it can also be used by an iptables 2 but required by, the NAT layer; it can also be used by an iptables
3 extension. */ 3 extension. */
4 4
5/* (C) 1999-2001 Paul `Rusty' Russell 5/* (C) 1999-2001 Paul `Rusty' Russell
6 * (C) 2002-2004 Netfilter Core Team <coreteam@netfilter.org> 6 * (C) 2002-2004 Netfilter Core Team <coreteam@netfilter.org>
7 * 7 *
8 * This program is free software; you can redistribute it and/or modify 8 * This program is free software; you can redistribute it and/or modify
@@ -99,7 +99,7 @@ __ip_ct_deliver_cached_events(struct ip_conntrack_ecache *ecache)
99void ip_ct_deliver_cached_events(const struct ip_conntrack *ct) 99void ip_ct_deliver_cached_events(const struct ip_conntrack *ct)
100{ 100{
101 struct ip_conntrack_ecache *ecache; 101 struct ip_conntrack_ecache *ecache;
102 102
103 local_bh_disable(); 103 local_bh_disable();
104 ecache = &__get_cpu_var(ip_conntrack_ecache); 104 ecache = &__get_cpu_var(ip_conntrack_ecache);
105 if (ecache->ct == ct) 105 if (ecache->ct == ct)
@@ -147,9 +147,9 @@ static u_int32_t __hash_conntrack(const struct ip_conntrack_tuple *tuple,
147 unsigned int size, unsigned int rnd) 147 unsigned int size, unsigned int rnd)
148{ 148{
149 return (jhash_3words((__force u32)tuple->src.ip, 149 return (jhash_3words((__force u32)tuple->src.ip,
150 ((__force u32)tuple->dst.ip ^ tuple->dst.protonum), 150 ((__force u32)tuple->dst.ip ^ tuple->dst.protonum),
151 (tuple->src.u.all | (tuple->dst.u.all << 16)), 151 (tuple->src.u.all | (tuple->dst.u.all << 16)),
152 rnd) % size); 152 rnd) % size);
153} 153}
154 154
155static u_int32_t 155static u_int32_t
@@ -219,7 +219,7 @@ struct ip_conntrack_expect *
219__ip_conntrack_expect_find(const struct ip_conntrack_tuple *tuple) 219__ip_conntrack_expect_find(const struct ip_conntrack_tuple *tuple)
220{ 220{
221 struct ip_conntrack_expect *i; 221 struct ip_conntrack_expect *i;
222 222
223 list_for_each_entry(i, &ip_conntrack_expect_list, list) { 223 list_for_each_entry(i, &ip_conntrack_expect_list, list) {
224 if (ip_ct_tuple_mask_cmp(tuple, &i->tuple, &i->mask)) 224 if (ip_ct_tuple_mask_cmp(tuple, &i->tuple, &i->mask))
225 return i; 225 return i;
@@ -232,7 +232,7 @@ struct ip_conntrack_expect *
232ip_conntrack_expect_find_get(const struct ip_conntrack_tuple *tuple) 232ip_conntrack_expect_find_get(const struct ip_conntrack_tuple *tuple)
233{ 233{
234 struct ip_conntrack_expect *i; 234 struct ip_conntrack_expect *i;
235 235
236 read_lock_bh(&ip_conntrack_lock); 236 read_lock_bh(&ip_conntrack_lock);
237 i = __ip_conntrack_expect_find(tuple); 237 i = __ip_conntrack_expect_find(tuple);
238 if (i) 238 if (i)
@@ -303,6 +303,7 @@ destroy_conntrack(struct nf_conntrack *nfct)
303 struct ip_conntrack *ct = (struct ip_conntrack *)nfct; 303 struct ip_conntrack *ct = (struct ip_conntrack *)nfct;
304 struct ip_conntrack_protocol *proto; 304 struct ip_conntrack_protocol *proto;
305 struct ip_conntrack_helper *helper; 305 struct ip_conntrack_helper *helper;
306 typeof(ip_conntrack_destroyed) destroyed;
306 307
307 DEBUGP("destroy_conntrack(%p)\n", ct); 308 DEBUGP("destroy_conntrack(%p)\n", ct);
308 IP_NF_ASSERT(atomic_read(&nfct->use) == 0); 309 IP_NF_ASSERT(atomic_read(&nfct->use) == 0);
@@ -318,12 +319,16 @@ destroy_conntrack(struct nf_conntrack *nfct)
318 /* To make sure we don't get any weird locking issues here: 319 /* To make sure we don't get any weird locking issues here:
319 * destroy_conntrack() MUST NOT be called with a write lock 320 * destroy_conntrack() MUST NOT be called with a write lock
320 * to ip_conntrack_lock!!! -HW */ 321 * to ip_conntrack_lock!!! -HW */
322 rcu_read_lock();
321 proto = __ip_conntrack_proto_find(ct->tuplehash[IP_CT_DIR_REPLY].tuple.dst.protonum); 323 proto = __ip_conntrack_proto_find(ct->tuplehash[IP_CT_DIR_REPLY].tuple.dst.protonum);
322 if (proto && proto->destroy) 324 if (proto && proto->destroy)
323 proto->destroy(ct); 325 proto->destroy(ct);
324 326
325 if (ip_conntrack_destroyed) 327 destroyed = rcu_dereference(ip_conntrack_destroyed);
326 ip_conntrack_destroyed(ct); 328 if (destroyed)
329 destroyed(ct);
330
331 rcu_read_unlock();
327 332
328 write_lock_bh(&ip_conntrack_lock); 333 write_lock_bh(&ip_conntrack_lock);
329 /* Expectations will have been removed in clean_from_lists, 334 /* Expectations will have been removed in clean_from_lists,
@@ -398,7 +403,7 @@ ip_conntrack_find_get(const struct ip_conntrack_tuple *tuple,
398 403
399static void __ip_conntrack_hash_insert(struct ip_conntrack *ct, 404static void __ip_conntrack_hash_insert(struct ip_conntrack *ct,
400 unsigned int hash, 405 unsigned int hash,
401 unsigned int repl_hash) 406 unsigned int repl_hash)
402{ 407{
403 ct->id = ++ip_conntrack_next_id; 408 ct->id = ++ip_conntrack_next_id;
404 list_add(&ct->tuplehash[IP_CT_DIR_ORIGINAL].list, 409 list_add(&ct->tuplehash[IP_CT_DIR_ORIGINAL].list,
@@ -446,15 +451,15 @@ __ip_conntrack_confirm(struct sk_buff **pskb)
446 /* IP_NF_ASSERT(atomic_read(&ct->ct_general.use) == 1); */ 451 /* IP_NF_ASSERT(atomic_read(&ct->ct_general.use) == 1); */
447 452
448 /* No external references means noone else could have 453 /* No external references means noone else could have
449 confirmed us. */ 454 confirmed us. */
450 IP_NF_ASSERT(!is_confirmed(ct)); 455 IP_NF_ASSERT(!is_confirmed(ct));
451 DEBUGP("Confirming conntrack %p\n", ct); 456 DEBUGP("Confirming conntrack %p\n", ct);
452 457
453 write_lock_bh(&ip_conntrack_lock); 458 write_lock_bh(&ip_conntrack_lock);
454 459
455 /* See if there's one in the list already, including reverse: 460 /* See if there's one in the list already, including reverse:
456 NAT could have grabbed it without realizing, since we're 461 NAT could have grabbed it without realizing, since we're
457 not in the hash. If there is, we lost race. */ 462 not in the hash. If there is, we lost race. */
458 list_for_each_entry(h, &ip_conntrack_hash[hash], list) 463 list_for_each_entry(h, &ip_conntrack_hash[hash], list)
459 if (ip_ct_tuple_equal(&ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple, 464 if (ip_ct_tuple_equal(&ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple,
460 &h->tuple)) 465 &h->tuple))
@@ -536,7 +541,7 @@ static int early_drop(struct list_head *chain)
536 if (del_timer(&ct->timeout)) { 541 if (del_timer(&ct->timeout)) {
537 death_by_timeout((unsigned long)ct); 542 death_by_timeout((unsigned long)ct);
538 dropped = 1; 543 dropped = 1;
539 CONNTRACK_STAT_INC(early_drop); 544 CONNTRACK_STAT_INC_ATOMIC(early_drop);
540 } 545 }
541 ip_conntrack_put(ct); 546 ip_conntrack_put(ct);
542 return dropped; 547 return dropped;
@@ -595,14 +600,14 @@ ip_conntrack_proto_find_get(u_int8_t protocol)
595{ 600{
596 struct ip_conntrack_protocol *p; 601 struct ip_conntrack_protocol *p;
597 602
598 preempt_disable(); 603 rcu_read_lock();
599 p = __ip_conntrack_proto_find(protocol); 604 p = __ip_conntrack_proto_find(protocol);
600 if (p) { 605 if (p) {
601 if (!try_module_get(p->me)) 606 if (!try_module_get(p->me))
602 p = &ip_conntrack_generic_protocol; 607 p = &ip_conntrack_generic_protocol;
603 } 608 }
604 preempt_enable(); 609 rcu_read_unlock();
605 610
606 return p; 611 return p;
607} 612}
608 613
@@ -638,14 +643,13 @@ struct ip_conntrack *ip_conntrack_alloc(struct ip_conntrack_tuple *orig,
638 } 643 }
639 } 644 }
640 645
641 conntrack = kmem_cache_alloc(ip_conntrack_cachep, GFP_ATOMIC); 646 conntrack = kmem_cache_zalloc(ip_conntrack_cachep, GFP_ATOMIC);
642 if (!conntrack) { 647 if (!conntrack) {
643 DEBUGP("Can't allocate conntrack.\n"); 648 DEBUGP("Can't allocate conntrack.\n");
644 atomic_dec(&ip_conntrack_count); 649 atomic_dec(&ip_conntrack_count);
645 return ERR_PTR(-ENOMEM); 650 return ERR_PTR(-ENOMEM);
646 } 651 }
647 652
648 memset(conntrack, 0, sizeof(*conntrack));
649 atomic_set(&conntrack->ct_general.use, 1); 653 atomic_set(&conntrack->ct_general.use, 1);
650 conntrack->ct_general.destroy = destroy_conntrack; 654 conntrack->ct_general.destroy = destroy_conntrack;
651 conntrack->tuplehash[IP_CT_DIR_ORIGINAL].tuple = *orig; 655 conntrack->tuplehash[IP_CT_DIR_ORIGINAL].tuple = *orig;
@@ -746,7 +750,7 @@ resolve_normal_ct(struct sk_buff *skb,
746 750
747 IP_NF_ASSERT((skb->nh.iph->frag_off & htons(IP_OFFSET)) == 0); 751 IP_NF_ASSERT((skb->nh.iph->frag_off & htons(IP_OFFSET)) == 0);
748 752
749 if (!ip_ct_get_tuple(skb->nh.iph, skb, skb->nh.iph->ihl*4, 753 if (!ip_ct_get_tuple(skb->nh.iph, skb, skb->nh.iph->ihl*4,
750 &tuple,proto)) 754 &tuple,proto))
751 return NULL; 755 return NULL;
752 756
@@ -771,7 +775,7 @@ resolve_normal_ct(struct sk_buff *skb,
771 if (test_bit(IPS_SEEN_REPLY_BIT, &ct->status)) { 775 if (test_bit(IPS_SEEN_REPLY_BIT, &ct->status)) {
772 DEBUGP("ip_conntrack_in: normal packet for %p\n", 776 DEBUGP("ip_conntrack_in: normal packet for %p\n",
773 ct); 777 ct);
774 *ctinfo = IP_CT_ESTABLISHED; 778 *ctinfo = IP_CT_ESTABLISHED;
775 } else if (test_bit(IPS_EXPECTED_BIT, &ct->status)) { 779 } else if (test_bit(IPS_EXPECTED_BIT, &ct->status)) {
776 DEBUGP("ip_conntrack_in: related packet for %p\n", 780 DEBUGP("ip_conntrack_in: related packet for %p\n",
777 ct); 781 ct);
@@ -803,7 +807,7 @@ unsigned int ip_conntrack_in(unsigned int hooknum,
803 807
804 /* Previously seen (loopback or untracked)? Ignore. */ 808 /* Previously seen (loopback or untracked)? Ignore. */
805 if ((*pskb)->nfct) { 809 if ((*pskb)->nfct) {
806 CONNTRACK_STAT_INC(ignore); 810 CONNTRACK_STAT_INC_ATOMIC(ignore);
807 return NF_ACCEPT; 811 return NF_ACCEPT;
808 } 812 }
809 813
@@ -822,7 +826,7 @@ unsigned int ip_conntrack_in(unsigned int hooknum,
822 if ((*pskb)->pkt_type == PACKET_BROADCAST) { 826 if ((*pskb)->pkt_type == PACKET_BROADCAST) {
823 printk("Broadcast packet!\n"); 827 printk("Broadcast packet!\n");
824 return NF_ACCEPT; 828 return NF_ACCEPT;
825 } else if (((*pskb)->nh.iph->daddr & htonl(0x000000FF)) 829 } else if (((*pskb)->nh.iph->daddr & htonl(0x000000FF))
826 == htonl(0x000000FF)) { 830 == htonl(0x000000FF)) {
827 printk("Should bcast: %u.%u.%u.%u->%u.%u.%u.%u (sk=%p, ptype=%u)\n", 831 printk("Should bcast: %u.%u.%u.%u->%u.%u.%u.%u (sk=%p, ptype=%u)\n",
828 NIPQUAD((*pskb)->nh.iph->saddr), 832 NIPQUAD((*pskb)->nh.iph->saddr),
@@ -831,27 +835,28 @@ unsigned int ip_conntrack_in(unsigned int hooknum,
831 } 835 }
832#endif 836#endif
833 837
838 /* rcu_read_lock()ed by nf_hook_slow */
834 proto = __ip_conntrack_proto_find((*pskb)->nh.iph->protocol); 839 proto = __ip_conntrack_proto_find((*pskb)->nh.iph->protocol);
835 840
836 /* It may be an special packet, error, unclean... 841 /* It may be an special packet, error, unclean...
837 * inverse of the return code tells to the netfilter 842 * inverse of the return code tells to the netfilter
838 * core what to do with the packet. */ 843 * core what to do with the packet. */
839 if (proto->error != NULL 844 if (proto->error != NULL
840 && (ret = proto->error(*pskb, &ctinfo, hooknum)) <= 0) { 845 && (ret = proto->error(*pskb, &ctinfo, hooknum)) <= 0) {
841 CONNTRACK_STAT_INC(error); 846 CONNTRACK_STAT_INC_ATOMIC(error);
842 CONNTRACK_STAT_INC(invalid); 847 CONNTRACK_STAT_INC_ATOMIC(invalid);
843 return -ret; 848 return -ret;
844 } 849 }
845 850
846 if (!(ct = resolve_normal_ct(*pskb, proto,&set_reply,hooknum,&ctinfo))) { 851 if (!(ct = resolve_normal_ct(*pskb, proto,&set_reply,hooknum,&ctinfo))) {
847 /* Not valid part of a connection */ 852 /* Not valid part of a connection */
848 CONNTRACK_STAT_INC(invalid); 853 CONNTRACK_STAT_INC_ATOMIC(invalid);
849 return NF_ACCEPT; 854 return NF_ACCEPT;
850 } 855 }
851 856
852 if (IS_ERR(ct)) { 857 if (IS_ERR(ct)) {
853 /* Too stressed to deal. */ 858 /* Too stressed to deal. */
854 CONNTRACK_STAT_INC(drop); 859 CONNTRACK_STAT_INC_ATOMIC(drop);
855 return NF_DROP; 860 return NF_DROP;
856 } 861 }
857 862
@@ -863,7 +868,7 @@ unsigned int ip_conntrack_in(unsigned int hooknum,
863 * the netfilter core what to do*/ 868 * the netfilter core what to do*/
864 nf_conntrack_put((*pskb)->nfct); 869 nf_conntrack_put((*pskb)->nfct);
865 (*pskb)->nfct = NULL; 870 (*pskb)->nfct = NULL;
866 CONNTRACK_STAT_INC(invalid); 871 CONNTRACK_STAT_INC_ATOMIC(invalid);
867 return -ret; 872 return -ret;
868 } 873 }
869 874
@@ -876,8 +881,15 @@ unsigned int ip_conntrack_in(unsigned int hooknum,
876int invert_tuplepr(struct ip_conntrack_tuple *inverse, 881int invert_tuplepr(struct ip_conntrack_tuple *inverse,
877 const struct ip_conntrack_tuple *orig) 882 const struct ip_conntrack_tuple *orig)
878{ 883{
879 return ip_ct_invert_tuple(inverse, orig, 884 struct ip_conntrack_protocol *proto;
880 __ip_conntrack_proto_find(orig->dst.protonum)); 885 int ret;
886
887 rcu_read_lock();
888 proto = __ip_conntrack_proto_find(orig->dst.protonum);
889 ret = ip_ct_invert_tuple(inverse, orig, proto);
890 rcu_read_unlock();
891
892 return ret;
881} 893}
882 894
883/* Would two expected things clash? */ 895/* Would two expected things clash? */
@@ -885,7 +897,7 @@ static inline int expect_clash(const struct ip_conntrack_expect *a,
885 const struct ip_conntrack_expect *b) 897 const struct ip_conntrack_expect *b)
886{ 898{
887 /* Part covered by intersection of masks must be unequal, 899 /* Part covered by intersection of masks must be unequal,
888 otherwise they clash */ 900 otherwise they clash */
889 struct ip_conntrack_tuple intersect_mask 901 struct ip_conntrack_tuple intersect_mask
890 = { { a->mask.src.ip & b->mask.src.ip, 902 = { { a->mask.src.ip & b->mask.src.ip,
891 { a->mask.src.u.all & b->mask.src.u.all } }, 903 { a->mask.src.u.all & b->mask.src.u.all } },
@@ -923,7 +935,7 @@ void ip_conntrack_unexpect_related(struct ip_conntrack_expect *exp)
923} 935}
924 936
925/* We don't increase the master conntrack refcount for non-fulfilled 937/* We don't increase the master conntrack refcount for non-fulfilled
926 * conntracks. During the conntrack destruction, the expectations are 938 * conntracks. During the conntrack destruction, the expectations are
927 * always killed before the conntrack itself */ 939 * always killed before the conntrack itself */
928struct ip_conntrack_expect *ip_conntrack_expect_alloc(struct ip_conntrack *me) 940struct ip_conntrack_expect *ip_conntrack_expect_alloc(struct ip_conntrack *me)
929{ 941{
@@ -1012,7 +1024,7 @@ int ip_conntrack_expect_related(struct ip_conntrack_expect *expect)
1012 } 1024 }
1013 1025
1014 /* Will be over limit? */ 1026 /* Will be over limit? */
1015 if (expect->master->helper->max_expected && 1027 if (expect->master->helper->max_expected &&
1016 expect->master->expecting >= expect->master->helper->max_expected) 1028 expect->master->expecting >= expect->master->helper->max_expected)
1017 evict_oldest_expect(expect->master); 1029 evict_oldest_expect(expect->master);
1018 1030
@@ -1021,7 +1033,7 @@ int ip_conntrack_expect_related(struct ip_conntrack_expect *expect)
1021 ret = 0; 1033 ret = 0;
1022out: 1034out:
1023 write_unlock_bh(&ip_conntrack_lock); 1035 write_unlock_bh(&ip_conntrack_lock);
1024 return ret; 1036 return ret;
1025} 1037}
1026 1038
1027/* Alter reply tuple (maybe alter helper). This is for NAT, and is 1039/* Alter reply tuple (maybe alter helper). This is for NAT, and is
@@ -1069,7 +1081,7 @@ static inline void unhelp(struct ip_conntrack_tuple_hash *i,
1069 const struct ip_conntrack_helper *me) 1081 const struct ip_conntrack_helper *me)
1070{ 1082{
1071 if (tuplehash_to_ctrack(i)->helper == me) { 1083 if (tuplehash_to_ctrack(i)->helper == me) {
1072 ip_conntrack_event(IPCT_HELPER, tuplehash_to_ctrack(i)); 1084 ip_conntrack_event(IPCT_HELPER, tuplehash_to_ctrack(i));
1073 tuplehash_to_ctrack(i)->helper = NULL; 1085 tuplehash_to_ctrack(i)->helper = NULL;
1074 } 1086 }
1075} 1087}
@@ -1105,8 +1117,8 @@ void ip_conntrack_helper_unregister(struct ip_conntrack_helper *me)
1105} 1117}
1106 1118
1107/* Refresh conntrack for this many jiffies and do accounting if do_acct is 1 */ 1119/* Refresh conntrack for this many jiffies and do accounting if do_acct is 1 */
1108void __ip_ct_refresh_acct(struct ip_conntrack *ct, 1120void __ip_ct_refresh_acct(struct ip_conntrack *ct,
1109 enum ip_conntrack_info ctinfo, 1121 enum ip_conntrack_info ctinfo,
1110 const struct sk_buff *skb, 1122 const struct sk_buff *skb,
1111 unsigned long extra_jiffies, 1123 unsigned long extra_jiffies,
1112 int do_acct) 1124 int do_acct)
@@ -1140,7 +1152,7 @@ void __ip_ct_refresh_acct(struct ip_conntrack *ct,
1140#ifdef CONFIG_IP_NF_CT_ACCT 1152#ifdef CONFIG_IP_NF_CT_ACCT
1141 if (do_acct) { 1153 if (do_acct) {
1142 ct->counters[CTINFO2DIR(ctinfo)].packets++; 1154 ct->counters[CTINFO2DIR(ctinfo)].packets++;
1143 ct->counters[CTINFO2DIR(ctinfo)].bytes += 1155 ct->counters[CTINFO2DIR(ctinfo)].bytes +=
1144 ntohs(skb->nh.iph->tot_len); 1156 ntohs(skb->nh.iph->tot_len);
1145 if ((ct->counters[CTINFO2DIR(ctinfo)].packets & 0x80000000) 1157 if ((ct->counters[CTINFO2DIR(ctinfo)].packets & 0x80000000)
1146 || (ct->counters[CTINFO2DIR(ctinfo)].bytes & 0x80000000)) 1158 || (ct->counters[CTINFO2DIR(ctinfo)].bytes & 0x80000000))
@@ -1194,7 +1206,7 @@ ip_ct_gather_frags(struct sk_buff *skb, u_int32_t user)
1194{ 1206{
1195 skb_orphan(skb); 1207 skb_orphan(skb);
1196 1208
1197 local_bh_disable(); 1209 local_bh_disable();
1198 skb = ip_defrag(skb, user); 1210 skb = ip_defrag(skb, user);
1199 local_bh_enable(); 1211 local_bh_enable();
1200 1212
@@ -1211,7 +1223,7 @@ static void ip_conntrack_attach(struct sk_buff *nskb, struct sk_buff *skb)
1211 1223
1212 /* This ICMP is in reverse direction to the packet which caused it */ 1224 /* This ICMP is in reverse direction to the packet which caused it */
1213 ct = ip_conntrack_get(skb, &ctinfo); 1225 ct = ip_conntrack_get(skb, &ctinfo);
1214 1226
1215 if (CTINFO2DIR(ctinfo) == IP_CT_DIR_ORIGINAL) 1227 if (CTINFO2DIR(ctinfo) == IP_CT_DIR_ORIGINAL)
1216 ctinfo = IP_CT_RELATED + IP_CT_IS_REPLY; 1228 ctinfo = IP_CT_RELATED + IP_CT_IS_REPLY;
1217 else 1229 else
@@ -1279,7 +1291,7 @@ getorigdst(struct sock *sk, int optval, void __user *user, int *len)
1279 struct inet_sock *inet = inet_sk(sk); 1291 struct inet_sock *inet = inet_sk(sk);
1280 struct ip_conntrack_tuple_hash *h; 1292 struct ip_conntrack_tuple_hash *h;
1281 struct ip_conntrack_tuple tuple; 1293 struct ip_conntrack_tuple tuple;
1282 1294
1283 IP_CT_TUPLE_U_BLANK(&tuple); 1295 IP_CT_TUPLE_U_BLANK(&tuple);
1284 tuple.src.ip = inet->rcv_saddr; 1296 tuple.src.ip = inet->rcv_saddr;
1285 tuple.src.u.tcp.port = inet->sport; 1297 tuple.src.u.tcp.port = inet->sport;
@@ -1347,7 +1359,7 @@ static void free_conntrack_hash(struct list_head *hash, int vmalloced,int size)
1347 if (vmalloced) 1359 if (vmalloced)
1348 vfree(hash); 1360 vfree(hash);
1349 else 1361 else
1350 free_pages((unsigned long)hash, 1362 free_pages((unsigned long)hash,
1351 get_order(sizeof(struct list_head) * size)); 1363 get_order(sizeof(struct list_head) * size));
1352} 1364}
1353 1365
@@ -1355,11 +1367,11 @@ static void free_conntrack_hash(struct list_head *hash, int vmalloced,int size)
1355 supposed to kill the mall. */ 1367 supposed to kill the mall. */
1356void ip_conntrack_cleanup(void) 1368void ip_conntrack_cleanup(void)
1357{ 1369{
1358 ip_ct_attach = NULL; 1370 rcu_assign_pointer(ip_ct_attach, NULL);
1359 1371
1360 /* This makes sure all current packets have passed through 1372 /* This makes sure all current packets have passed through
1361 netfilter framework. Roll on, two-stage module 1373 netfilter framework. Roll on, two-stage module
1362 delete... */ 1374 delete... */
1363 synchronize_net(); 1375 synchronize_net();
1364 1376
1365 ip_ct_event_cache_flush(); 1377 ip_ct_event_cache_flush();
@@ -1385,11 +1397,11 @@ static struct list_head *alloc_hashtable(int size, int *vmalloced)
1385 struct list_head *hash; 1397 struct list_head *hash;
1386 unsigned int i; 1398 unsigned int i;
1387 1399
1388 *vmalloced = 0; 1400 *vmalloced = 0;
1389 hash = (void*)__get_free_pages(GFP_KERNEL, 1401 hash = (void*)__get_free_pages(GFP_KERNEL,
1390 get_order(sizeof(struct list_head) 1402 get_order(sizeof(struct list_head)
1391 * size)); 1403 * size));
1392 if (!hash) { 1404 if (!hash) {
1393 *vmalloced = 1; 1405 *vmalloced = 1;
1394 printk(KERN_WARNING"ip_conntrack: falling back to vmalloc.\n"); 1406 printk(KERN_WARNING"ip_conntrack: falling back to vmalloc.\n");
1395 hash = vmalloc(sizeof(struct list_head) * size); 1407 hash = vmalloc(sizeof(struct list_head) * size);
@@ -1422,7 +1434,7 @@ static int set_hashsize(const char *val, struct kernel_param *kp)
1422 if (!hash) 1434 if (!hash)
1423 return -ENOMEM; 1435 return -ENOMEM;
1424 1436
1425 /* We have to rehash for the new table anyway, so we also can 1437 /* We have to rehash for the new table anyway, so we also can
1426 * use a new random seed */ 1438 * use a new random seed */
1427 get_random_bytes(&rnd, 4); 1439 get_random_bytes(&rnd, 4);
1428 1440
@@ -1460,7 +1472,7 @@ int __init ip_conntrack_init(void)
1460 1472
1461 /* Idea from tcp.c: use 1/16384 of memory. On i386: 32MB 1473 /* Idea from tcp.c: use 1/16384 of memory. On i386: 32MB
1462 * machine has 256 buckets. >= 1GB machines have 8192 buckets. */ 1474 * machine has 256 buckets. >= 1GB machines have 8192 buckets. */
1463 if (!ip_conntrack_htable_size) { 1475 if (!ip_conntrack_htable_size) {
1464 ip_conntrack_htable_size 1476 ip_conntrack_htable_size
1465 = (((num_physpages << PAGE_SHIFT) / 16384) 1477 = (((num_physpages << PAGE_SHIFT) / 16384)
1466 / sizeof(struct list_head)); 1478 / sizeof(struct list_head));
@@ -1490,8 +1502,8 @@ int __init ip_conntrack_init(void)
1490 } 1502 }
1491 1503
1492 ip_conntrack_cachep = kmem_cache_create("ip_conntrack", 1504 ip_conntrack_cachep = kmem_cache_create("ip_conntrack",
1493 sizeof(struct ip_conntrack), 0, 1505 sizeof(struct ip_conntrack), 0,
1494 0, NULL, NULL); 1506 0, NULL, NULL);
1495 if (!ip_conntrack_cachep) { 1507 if (!ip_conntrack_cachep) {
1496 printk(KERN_ERR "Unable to create ip_conntrack slab cache\n"); 1508 printk(KERN_ERR "Unable to create ip_conntrack slab cache\n");
1497 goto err_free_hash; 1509 goto err_free_hash;
@@ -1508,15 +1520,15 @@ int __init ip_conntrack_init(void)
1508 /* Don't NEED lock here, but good form anyway. */ 1520 /* Don't NEED lock here, but good form anyway. */
1509 write_lock_bh(&ip_conntrack_lock); 1521 write_lock_bh(&ip_conntrack_lock);
1510 for (i = 0; i < MAX_IP_CT_PROTO; i++) 1522 for (i = 0; i < MAX_IP_CT_PROTO; i++)
1511 ip_ct_protos[i] = &ip_conntrack_generic_protocol; 1523 rcu_assign_pointer(ip_ct_protos[i], &ip_conntrack_generic_protocol);
1512 /* Sew in builtin protocols. */ 1524 /* Sew in builtin protocols. */
1513 ip_ct_protos[IPPROTO_TCP] = &ip_conntrack_protocol_tcp; 1525 rcu_assign_pointer(ip_ct_protos[IPPROTO_TCP], &ip_conntrack_protocol_tcp);
1514 ip_ct_protos[IPPROTO_UDP] = &ip_conntrack_protocol_udp; 1526 rcu_assign_pointer(ip_ct_protos[IPPROTO_UDP], &ip_conntrack_protocol_udp);
1515 ip_ct_protos[IPPROTO_ICMP] = &ip_conntrack_protocol_icmp; 1527 rcu_assign_pointer(ip_ct_protos[IPPROTO_ICMP], &ip_conntrack_protocol_icmp);
1516 write_unlock_bh(&ip_conntrack_lock); 1528 write_unlock_bh(&ip_conntrack_lock);
1517 1529
1518 /* For use by ipt_REJECT */ 1530 /* For use by ipt_REJECT */
1519 ip_ct_attach = ip_conntrack_attach; 1531 rcu_assign_pointer(ip_ct_attach, ip_conntrack_attach);
1520 1532
1521 /* Set up fake conntrack: 1533 /* Set up fake conntrack:
1522 - to never be deleted, not in any hashes */ 1534 - to never be deleted, not in any hashes */
diff --git a/net/ipv4/netfilter/ip_conntrack_ftp.c b/net/ipv4/netfilter/ip_conntrack_ftp.c
index 0410c99cacae..1faa68ab9432 100644
--- a/net/ipv4/netfilter/ip_conntrack_ftp.c
+++ b/net/ipv4/netfilter/ip_conntrack_ftp.c
@@ -1,6 +1,6 @@
1/* FTP extension for IP connection tracking. */ 1/* FTP extension for IP connection tracking. */
2 2
3/* (C) 1999-2001 Paul `Rusty' Russell 3/* (C) 1999-2001 Paul `Rusty' Russell
4 * (C) 2002-2004 Netfilter Core Team <coreteam@netfilter.org> 4 * (C) 2002-2004 Netfilter Core Team <coreteam@netfilter.org>
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify 6 * This program is free software; you can redistribute it and/or modify
@@ -169,7 +169,7 @@ static int try_eprt(const char *data, size_t dlen, u_int32_t array[6],
169 int length; 169 int length;
170 170
171 /* First character is delimiter, then "1" for IPv4, then 171 /* First character is delimiter, then "1" for IPv4, then
172 delimiter again. */ 172 delimiter again. */
173 if (dlen <= 3) return 0; 173 if (dlen <= 3) return 0;
174 delim = data[0]; 174 delim = data[0];
175 if (isdigit(delim) || delim < 33 || delim > 126 175 if (isdigit(delim) || delim < 33 || delim > 126
@@ -344,14 +344,14 @@ static int help(struct sk_buff **pskb,
344 if (!find_nl_seq(ntohl(th->seq), ct_ftp_info, dir)) { 344 if (!find_nl_seq(ntohl(th->seq), ct_ftp_info, dir)) {
345 /* Now if this ends in \n, update ftp info. */ 345 /* Now if this ends in \n, update ftp info. */
346 DEBUGP("ip_conntrack_ftp_help: wrong seq pos %s(%u) or %s(%u)\n", 346 DEBUGP("ip_conntrack_ftp_help: wrong seq pos %s(%u) or %s(%u)\n",
347 ct_ftp_info->seq_aft_nl[0][dir] 347 ct_ftp_info->seq_aft_nl[0][dir]
348 old_seq_aft_nl_set ? "":"(UNSET) ", old_seq_aft_nl); 348 old_seq_aft_nl_set ? "":"(UNSET) ", old_seq_aft_nl);
349 ret = NF_ACCEPT; 349 ret = NF_ACCEPT;
350 goto out_update_nl; 350 goto out_update_nl;
351 } 351 }
352 352
353 /* Initialize IP array to expected address (it's not mentioned 353 /* Initialize IP array to expected address (it's not mentioned
354 in EPSV responses) */ 354 in EPSV responses) */
355 array[0] = (ntohl(ct->tuplehash[dir].tuple.src.ip) >> 24) & 0xFF; 355 array[0] = (ntohl(ct->tuplehash[dir].tuple.src.ip) >> 24) & 0xFF;
356 array[1] = (ntohl(ct->tuplehash[dir].tuple.src.ip) >> 16) & 0xFF; 356 array[1] = (ntohl(ct->tuplehash[dir].tuple.src.ip) >> 16) & 0xFF;
357 array[2] = (ntohl(ct->tuplehash[dir].tuple.src.ip) >> 8) & 0xFF; 357 array[2] = (ntohl(ct->tuplehash[dir].tuple.src.ip) >> 8) & 0xFF;
@@ -386,7 +386,7 @@ static int help(struct sk_buff **pskb,
386 386
387 DEBUGP("conntrack_ftp: match `%s' (%u bytes at %u)\n", 387 DEBUGP("conntrack_ftp: match `%s' (%u bytes at %u)\n",
388 fb_ptr + matchoff, matchlen, ntohl(th->seq) + matchoff); 388 fb_ptr + matchoff, matchlen, ntohl(th->seq) + matchoff);
389 389
390 /* Allocate expectation which will be inserted */ 390 /* Allocate expectation which will be inserted */
391 exp = ip_conntrack_expect_alloc(ct); 391 exp = ip_conntrack_expect_alloc(ct);
392 if (exp == NULL) { 392 if (exp == NULL) {
@@ -504,7 +504,7 @@ static int __init ip_conntrack_ftp_init(void)
504 sprintf(tmpname, "ftp-%d", ports[i]); 504 sprintf(tmpname, "ftp-%d", ports[i]);
505 ftp[i].name = tmpname; 505 ftp[i].name = tmpname;
506 506
507 DEBUGP("ip_ct_ftp: registering helper for port %d\n", 507 DEBUGP("ip_ct_ftp: registering helper for port %d\n",
508 ports[i]); 508 ports[i]);
509 ret = ip_conntrack_helper_register(&ftp[i]); 509 ret = ip_conntrack_helper_register(&ftp[i]);
510 510
diff --git a/net/ipv4/netfilter/ip_conntrack_helper_h323.c b/net/ipv4/netfilter/ip_conntrack_helper_h323.c
index aabfe1c06905..53eb365ccc7e 100644
--- a/net/ipv4/netfilter/ip_conntrack_helper_h323.c
+++ b/net/ipv4/netfilter/ip_conntrack_helper_h323.c
@@ -42,7 +42,7 @@ MODULE_PARM_DESC(gkrouted_only, "only accept calls from gatekeeper");
42static int callforward_filter = 1; 42static int callforward_filter = 1;
43module_param(callforward_filter, bool, 0600); 43module_param(callforward_filter, bool, 0600);
44MODULE_PARM_DESC(callforward_filter, "only create call forwarding expectations " 44MODULE_PARM_DESC(callforward_filter, "only create call forwarding expectations "
45 "if both endpoints are on different sides " 45 "if both endpoints are on different sides "
46 "(determined by routing information)"); 46 "(determined by routing information)");
47 47
48/* Hooks for NAT */ 48/* Hooks for NAT */
diff --git a/net/ipv4/netfilter/ip_conntrack_helper_pptp.c b/net/ipv4/netfilter/ip_conntrack_helper_pptp.c
index 4d19373bbf0d..2b760c5cf709 100644
--- a/net/ipv4/netfilter/ip_conntrack_helper_pptp.c
+++ b/net/ipv4/netfilter/ip_conntrack_helper_pptp.c
@@ -560,7 +560,7 @@ conntrack_pptp_help(struct sk_buff **pskb,
560 tcph = skb_header_pointer(*pskb, nexthdr_off, sizeof(_tcph), &_tcph); 560 tcph = skb_header_pointer(*pskb, nexthdr_off, sizeof(_tcph), &_tcph);
561 BUG_ON(!tcph); 561 BUG_ON(!tcph);
562 nexthdr_off += tcph->doff * 4; 562 nexthdr_off += tcph->doff * 4;
563 datalen = tcplen - tcph->doff * 4; 563 datalen = tcplen - tcph->doff * 4;
564 564
565 pptph = skb_header_pointer(*pskb, nexthdr_off, sizeof(_pptph), &_pptph); 565 pptph = skb_header_pointer(*pskb, nexthdr_off, sizeof(_pptph), &_pptph);
566 if (!pptph) { 566 if (!pptph) {
@@ -624,7 +624,7 @@ static struct ip_conntrack_helper pptp = {
624 .max_expected = 2, 624 .max_expected = 2,
625 .timeout = 5 * 60, 625 .timeout = 5 * 60,
626 .tuple = { .src = { .ip = 0, 626 .tuple = { .src = { .ip = 0,
627 .u = { .tcp = { .port = 627 .u = { .tcp = { .port =
628 __constant_htons(PPTP_CONTROL_PORT) } } 628 __constant_htons(PPTP_CONTROL_PORT) } }
629 }, 629 },
630 .dst = { .ip = 0, 630 .dst = { .ip = 0,
@@ -638,7 +638,7 @@ static struct ip_conntrack_helper pptp = {
638 .dst = { .ip = 0, 638 .dst = { .ip = 0,
639 .u = { .all = 0 }, 639 .u = { .all = 0 },
640 .protonum = 0xff 640 .protonum = 0xff
641 } 641 }
642 }, 642 },
643 .help = conntrack_pptp_help, 643 .help = conntrack_pptp_help,
644 .destroy = pptp_destroy_siblings, 644 .destroy = pptp_destroy_siblings,
diff --git a/net/ipv4/netfilter/ip_conntrack_irc.c b/net/ipv4/netfilter/ip_conntrack_irc.c
index 91832eca4106..053e591f407a 100644
--- a/net/ipv4/netfilter/ip_conntrack_irc.c
+++ b/net/ipv4/netfilter/ip_conntrack_irc.c
@@ -1,6 +1,6 @@
1/* IRC extension for IP connection tracking, Version 1.21 1/* IRC extension for IP connection tracking, Version 1.21
2 * (C) 2000-2002 by Harald Welte <laforge@gnumonks.org> 2 * (C) 2000-2002 by Harald Welte <laforge@gnumonks.org>
3 * based on RR's ip_conntrack_ftp.c 3 * based on RR's ip_conntrack_ftp.c
4 * 4 *
5 * ip_conntrack_irc.c,v 1.21 2002/02/05 14:49:26 laforge Exp 5 * ip_conntrack_irc.c,v 1.21 2002/02/05 14:49:26 laforge Exp
6 * 6 *
@@ -12,12 +12,12 @@
12 * Module load syntax: 12 * Module load syntax:
13 * insmod ip_conntrack_irc.o ports=port1,port2,...port<MAX_PORTS> 13 * insmod ip_conntrack_irc.o ports=port1,port2,...port<MAX_PORTS>
14 * max_dcc_channels=n dcc_timeout=secs 14 * max_dcc_channels=n dcc_timeout=secs
15 * 15 *
16 * please give the ports of all IRC servers You wish to connect to. 16 * please give the ports of all IRC servers You wish to connect to.
17 * If You don't specify ports, the default will be port 6667. 17 * If You don't specify ports, the default will be port 6667.
18 * With max_dcc_channels you can define the maximum number of not 18 * With max_dcc_channels you can define the maximum number of not
19 * yet answered DCC channels per IRC session (default 8). 19 * yet answered DCC channels per IRC session (default 8).
20 * With dcc_timeout you can specify how long the system waits for 20 * With dcc_timeout you can specify how long the system waits for
21 * an expected DCC channel (default 300 seconds). 21 * an expected DCC channel (default 300 seconds).
22 * 22 *
23 */ 23 */
@@ -63,7 +63,7 @@ static const char *dccprotos[] = { "SEND ", "CHAT ", "MOVE ", "TSEND ", "SCHAT "
63 63
64#if 0 64#if 0
65#define DEBUGP(format, args...) printk(KERN_DEBUG "%s:%s:" format, \ 65#define DEBUGP(format, args...) printk(KERN_DEBUG "%s:%s:" format, \
66 __FILE__, __FUNCTION__ , ## args) 66 __FILE__, __FUNCTION__ , ## args)
67#else 67#else
68#define DEBUGP(format, args...) 68#define DEBUGP(format, args...)
69#endif 69#endif
@@ -71,7 +71,7 @@ static const char *dccprotos[] = { "SEND ", "CHAT ", "MOVE ", "TSEND ", "SCHAT "
71static int parse_dcc(char *data, char *data_end, u_int32_t *ip, 71static int parse_dcc(char *data, char *data_end, u_int32_t *ip,
72 u_int16_t *port, char **ad_beg_p, char **ad_end_p) 72 u_int16_t *port, char **ad_beg_p, char **ad_end_p)
73/* tries to get the ip_addr and port out of a dcc command 73/* tries to get the ip_addr and port out of a dcc command
74 return value: -1 on failure, 0 on success 74 return value: -1 on failure, 0 on success
75 data pointer to first byte of DCC command data 75 data pointer to first byte of DCC command data
76 data_end pointer to last byte of dcc command data 76 data_end pointer to last byte of dcc command data
77 ip returns parsed ip of dcc command 77 ip returns parsed ip of dcc command
@@ -90,7 +90,7 @@ static int parse_dcc(char *data, char *data_end, u_int32_t *ip,
90 90
91 /* skip blanks between ip and port */ 91 /* skip blanks between ip and port */
92 while (*data == ' ') { 92 while (*data == ' ') {
93 if (data >= data_end) 93 if (data >= data_end)
94 return -1; 94 return -1;
95 data++; 95 data++;
96 } 96 }
@@ -171,7 +171,7 @@ static int help(struct sk_buff **pskb,
171 171
172 DEBUGP("DCC %s detected\n", dccprotos[i]); 172 DEBUGP("DCC %s detected\n", dccprotos[i]);
173 data += strlen(dccprotos[i]); 173 data += strlen(dccprotos[i]);
174 /* we have at least 174 /* we have at least
175 * (19+MINMATCHLEN)-5-dccprotos[i].matchlen bytes valid 175 * (19+MINMATCHLEN)-5-dccprotos[i].matchlen bytes valid
176 * data left (== 14/13 bytes) */ 176 * data left (== 14/13 bytes) */
177 if (parse_dcc((char *)data, data_limit, &dcc_ip, 177 if (parse_dcc((char *)data, data_limit, &dcc_ip,
@@ -260,7 +260,7 @@ static int __init ip_conntrack_irc_init(void)
260 irc_buffer = kmalloc(65536, GFP_KERNEL); 260 irc_buffer = kmalloc(65536, GFP_KERNEL);
261 if (!irc_buffer) 261 if (!irc_buffer)
262 return -ENOMEM; 262 return -ENOMEM;
263 263
264 /* If no port given, default to standard irc port */ 264 /* If no port given, default to standard irc port */
265 if (ports_c == 0) 265 if (ports_c == 0)
266 ports[ports_c++] = IRC_PORT; 266 ports[ports_c++] = IRC_PORT;
@@ -297,7 +297,7 @@ static int __init ip_conntrack_irc_init(void)
297 return 0; 297 return 0;
298} 298}
299 299
300/* This function is intentionally _NOT_ defined as __exit, because 300/* This function is intentionally _NOT_ defined as __exit, because
301 * it is needed by the init function */ 301 * it is needed by the init function */
302static void ip_conntrack_irc_fini(void) 302static void ip_conntrack_irc_fini(void)
303{ 303{
diff --git a/net/ipv4/netfilter/ip_conntrack_netbios_ns.c b/net/ipv4/netfilter/ip_conntrack_netbios_ns.c
index a1d6a89f64aa..cc6dd49c9da0 100644
--- a/net/ipv4/netfilter/ip_conntrack_netbios_ns.c
+++ b/net/ipv4/netfilter/ip_conntrack_netbios_ns.c
@@ -42,7 +42,7 @@ module_param(timeout, uint, 0400);
42MODULE_PARM_DESC(timeout, "timeout for master connection/replies in seconds"); 42MODULE_PARM_DESC(timeout, "timeout for master connection/replies in seconds");
43 43
44static int help(struct sk_buff **pskb, 44static int help(struct sk_buff **pskb,
45 struct ip_conntrack *ct, enum ip_conntrack_info ctinfo) 45 struct ip_conntrack *ct, enum ip_conntrack_info ctinfo)
46{ 46{
47 struct ip_conntrack_expect *exp; 47 struct ip_conntrack_expect *exp;
48 struct iphdr *iph = (*pskb)->nh.iph; 48 struct iphdr *iph = (*pskb)->nh.iph;
diff --git a/net/ipv4/netfilter/ip_conntrack_netlink.c b/net/ipv4/netfilter/ip_conntrack_netlink.c
index 7f70b0886b83..9228b76ccd9a 100644
--- a/net/ipv4/netfilter/ip_conntrack_netlink.c
+++ b/net/ipv4/netfilter/ip_conntrack_netlink.c
@@ -6,10 +6,10 @@
6 * (C) 2003 by Patrick Mchardy <kaber@trash.net> 6 * (C) 2003 by Patrick Mchardy <kaber@trash.net>
7 * (C) 2005-2006 by Pablo Neira Ayuso <pablo@eurodev.net> 7 * (C) 2005-2006 by Pablo Neira Ayuso <pablo@eurodev.net>
8 * 8 *
9 * I've reworked this stuff to use attributes instead of conntrack 9 * I've reworked this stuff to use attributes instead of conntrack
10 * structures. 5.44 am. I need more tea. --pablo 05/07/11. 10 * structures. 5.44 am. I need more tea. --pablo 05/07/11.
11 * 11 *
12 * Initial connection tracking via netlink development funded and 12 * Initial connection tracking via netlink development funded and
13 * generally made possible by Network Robots, Inc. (www.networkrobots.com) 13 * generally made possible by Network Robots, Inc. (www.networkrobots.com)
14 * 14 *
15 * Further development of this code funded by Astaro AG (http://www.astaro.com) 15 * Further development of this code funded by Astaro AG (http://www.astaro.com)
@@ -45,7 +45,7 @@ MODULE_LICENSE("GPL");
45static char __initdata version[] = "0.90"; 45static char __initdata version[] = "0.90";
46 46
47static inline int 47static inline int
48ctnetlink_dump_tuples_proto(struct sk_buff *skb, 48ctnetlink_dump_tuples_proto(struct sk_buff *skb,
49 const struct ip_conntrack_tuple *tuple, 49 const struct ip_conntrack_tuple *tuple,
50 struct ip_conntrack_protocol *proto) 50 struct ip_conntrack_protocol *proto)
51{ 51{
@@ -56,7 +56,7 @@ ctnetlink_dump_tuples_proto(struct sk_buff *skb,
56 56
57 if (likely(proto->tuple_to_nfattr)) 57 if (likely(proto->tuple_to_nfattr))
58 ret = proto->tuple_to_nfattr(skb, tuple); 58 ret = proto->tuple_to_nfattr(skb, tuple);
59 59
60 NFA_NEST_END(skb, nest_parms); 60 NFA_NEST_END(skb, nest_parms);
61 61
62 return ret; 62 return ret;
@@ -70,7 +70,7 @@ ctnetlink_dump_tuples_ip(struct sk_buff *skb,
70 const struct ip_conntrack_tuple *tuple) 70 const struct ip_conntrack_tuple *tuple)
71{ 71{
72 struct nfattr *nest_parms = NFA_NEST(skb, CTA_TUPLE_IP); 72 struct nfattr *nest_parms = NFA_NEST(skb, CTA_TUPLE_IP);
73 73
74 NFA_PUT(skb, CTA_IP_V4_SRC, sizeof(__be32), &tuple->src.ip); 74 NFA_PUT(skb, CTA_IP_V4_SRC, sizeof(__be32), &tuple->src.ip);
75 NFA_PUT(skb, CTA_IP_V4_DST, sizeof(__be32), &tuple->dst.ip); 75 NFA_PUT(skb, CTA_IP_V4_DST, sizeof(__be32), &tuple->dst.ip);
76 76
@@ -121,7 +121,7 @@ ctnetlink_dump_timeout(struct sk_buff *skb, const struct ip_conntrack *ct)
121 timeout = 0; 121 timeout = 0;
122 else 122 else
123 timeout = htonl(timeout_l / HZ); 123 timeout = htonl(timeout_l / HZ);
124 124
125 NFA_PUT(skb, CTA_TIMEOUT, sizeof(timeout), &timeout); 125 NFA_PUT(skb, CTA_TIMEOUT, sizeof(timeout), &timeout);
126 return 0; 126 return 0;
127 127
@@ -141,7 +141,7 @@ ctnetlink_dump_protoinfo(struct sk_buff *skb, const struct ip_conntrack *ct)
141 ip_conntrack_proto_put(proto); 141 ip_conntrack_proto_put(proto);
142 return 0; 142 return 0;
143 } 143 }
144 144
145 nest_proto = NFA_NEST(skb, CTA_PROTOINFO); 145 nest_proto = NFA_NEST(skb, CTA_PROTOINFO);
146 146
147 ret = proto->to_nfattr(skb, nest_proto, ct); 147 ret = proto->to_nfattr(skb, nest_proto, ct);
@@ -164,7 +164,7 @@ ctnetlink_dump_helpinfo(struct sk_buff *skb, const struct ip_conntrack *ct)
164 164
165 if (!ct->helper) 165 if (!ct->helper)
166 return 0; 166 return 0;
167 167
168 nest_helper = NFA_NEST(skb, CTA_HELP); 168 nest_helper = NFA_NEST(skb, CTA_HELP);
169 NFA_PUT(skb, CTA_HELP_NAME, strlen(ct->helper->name), ct->helper->name); 169 NFA_PUT(skb, CTA_HELP_NAME, strlen(ct->helper->name), ct->helper->name);
170 170
@@ -236,7 +236,7 @@ static inline int
236ctnetlink_dump_use(struct sk_buff *skb, const struct ip_conntrack *ct) 236ctnetlink_dump_use(struct sk_buff *skb, const struct ip_conntrack *ct)
237{ 237{
238 __be32 use = htonl(atomic_read(&ct->ct_general.use)); 238 __be32 use = htonl(atomic_read(&ct->ct_general.use));
239 239
240 NFA_PUT(skb, CTA_USE, sizeof(__be32), &use); 240 NFA_PUT(skb, CTA_USE, sizeof(__be32), &use);
241 return 0; 241 return 0;
242 242
@@ -248,7 +248,7 @@ nfattr_failure:
248 248
249static int 249static int
250ctnetlink_fill_info(struct sk_buff *skb, u32 pid, u32 seq, 250ctnetlink_fill_info(struct sk_buff *skb, u32 pid, u32 seq,
251 int event, int nowait, 251 int event, int nowait,
252 const struct ip_conntrack *ct) 252 const struct ip_conntrack *ct)
253{ 253{
254 struct nlmsghdr *nlh; 254 struct nlmsghdr *nlh;
@@ -271,7 +271,7 @@ ctnetlink_fill_info(struct sk_buff *skb, u32 pid, u32 seq,
271 if (ctnetlink_dump_tuples(skb, tuple(ct, IP_CT_DIR_ORIGINAL)) < 0) 271 if (ctnetlink_dump_tuples(skb, tuple(ct, IP_CT_DIR_ORIGINAL)) < 0)
272 goto nfattr_failure; 272 goto nfattr_failure;
273 NFA_NEST_END(skb, nest_parms); 273 NFA_NEST_END(skb, nest_parms);
274 274
275 nest_parms = NFA_NEST(skb, CTA_TUPLE_REPLY); 275 nest_parms = NFA_NEST(skb, CTA_TUPLE_REPLY);
276 if (ctnetlink_dump_tuples(skb, tuple(ct, IP_CT_DIR_REPLY)) < 0) 276 if (ctnetlink_dump_tuples(skb, tuple(ct, IP_CT_DIR_REPLY)) < 0)
277 goto nfattr_failure; 277 goto nfattr_failure;
@@ -299,7 +299,7 @@ nfattr_failure:
299 299
300#ifdef CONFIG_IP_NF_CONNTRACK_EVENTS 300#ifdef CONFIG_IP_NF_CONNTRACK_EVENTS
301static int ctnetlink_conntrack_event(struct notifier_block *this, 301static int ctnetlink_conntrack_event(struct notifier_block *this,
302 unsigned long events, void *ptr) 302 unsigned long events, void *ptr)
303{ 303{
304 struct nlmsghdr *nlh; 304 struct nlmsghdr *nlh;
305 struct nfgenmsg *nfmsg; 305 struct nfgenmsg *nfmsg;
@@ -324,7 +324,7 @@ static int ctnetlink_conntrack_event(struct notifier_block *this,
324 } else if (events & (IPCT_STATUS | IPCT_PROTOINFO)) { 324 } else if (events & (IPCT_STATUS | IPCT_PROTOINFO)) {
325 type = IPCTNL_MSG_CT_NEW; 325 type = IPCTNL_MSG_CT_NEW;
326 group = NFNLGRP_CONNTRACK_UPDATE; 326 group = NFNLGRP_CONNTRACK_UPDATE;
327 } else 327 } else
328 return NOTIFY_DONE; 328 return NOTIFY_DONE;
329 329
330 if (!nfnetlink_has_listeners(group)) 330 if (!nfnetlink_has_listeners(group))
@@ -349,7 +349,7 @@ static int ctnetlink_conntrack_event(struct notifier_block *this,
349 if (ctnetlink_dump_tuples(skb, tuple(ct, IP_CT_DIR_ORIGINAL)) < 0) 349 if (ctnetlink_dump_tuples(skb, tuple(ct, IP_CT_DIR_ORIGINAL)) < 0)
350 goto nfattr_failure; 350 goto nfattr_failure;
351 NFA_NEST_END(skb, nest_parms); 351 NFA_NEST_END(skb, nest_parms);
352 352
353 nest_parms = NFA_NEST(skb, CTA_TUPLE_REPLY); 353 nest_parms = NFA_NEST(skb, CTA_TUPLE_REPLY);
354 if (ctnetlink_dump_tuples(skb, tuple(ct, IP_CT_DIR_REPLY)) < 0) 354 if (ctnetlink_dump_tuples(skb, tuple(ct, IP_CT_DIR_REPLY)) < 0)
355 goto nfattr_failure; 355 goto nfattr_failure;
@@ -368,16 +368,16 @@ static int ctnetlink_conntrack_event(struct notifier_block *this,
368 368
369 if (events & IPCT_PROTOINFO 369 if (events & IPCT_PROTOINFO
370 && ctnetlink_dump_protoinfo(skb, ct) < 0) 370 && ctnetlink_dump_protoinfo(skb, ct) < 0)
371 goto nfattr_failure; 371 goto nfattr_failure;
372 372
373 if ((events & IPCT_HELPER || ct->helper) 373 if ((events & IPCT_HELPER || ct->helper)
374 && ctnetlink_dump_helpinfo(skb, ct) < 0) 374 && ctnetlink_dump_helpinfo(skb, ct) < 0)
375 goto nfattr_failure; 375 goto nfattr_failure;
376 376
377#ifdef CONFIG_IP_NF_CONNTRACK_MARK 377#ifdef CONFIG_IP_NF_CONNTRACK_MARK
378 if ((events & IPCT_MARK || ct->mark) 378 if ((events & IPCT_MARK || ct->mark)
379 && ctnetlink_dump_mark(skb, ct) < 0) 379 && ctnetlink_dump_mark(skb, ct) < 0)
380 goto nfattr_failure; 380 goto nfattr_failure;
381#endif 381#endif
382 382
383 if (events & IPCT_COUNTER_FILLING && 383 if (events & IPCT_COUNTER_FILLING &&
@@ -426,7 +426,7 @@ restart:
426 cb->args[1] = 0; 426 cb->args[1] = 0;
427 } 427 }
428 if (ctnetlink_fill_info(skb, NETLINK_CB(cb->skb).pid, 428 if (ctnetlink_fill_info(skb, NETLINK_CB(cb->skb).pid,
429 cb->nlh->nlmsg_seq, 429 cb->nlh->nlmsg_seq,
430 IPCTNL_MSG_CT_NEW, 430 IPCTNL_MSG_CT_NEW,
431 1, ct) < 0) { 431 1, ct) < 0) {
432 nf_conntrack_get(&ct->ct_general); 432 nf_conntrack_get(&ct->ct_general);
@@ -488,7 +488,7 @@ static const size_t cta_min_proto[CTA_PROTO_MAX] = {
488}; 488};
489 489
490static inline int 490static inline int
491ctnetlink_parse_tuple_proto(struct nfattr *attr, 491ctnetlink_parse_tuple_proto(struct nfattr *attr,
492 struct ip_conntrack_tuple *tuple) 492 struct ip_conntrack_tuple *tuple)
493{ 493{
494 struct nfattr *tb[CTA_PROTO_MAX]; 494 struct nfattr *tb[CTA_PROTO_MAX];
@@ -508,9 +508,9 @@ ctnetlink_parse_tuple_proto(struct nfattr *attr,
508 508
509 if (likely(proto->nfattr_to_tuple)) 509 if (likely(proto->nfattr_to_tuple))
510 ret = proto->nfattr_to_tuple(tb, tuple); 510 ret = proto->nfattr_to_tuple(tb, tuple);
511 511
512 ip_conntrack_proto_put(proto); 512 ip_conntrack_proto_put(proto);
513 513
514 return ret; 514 return ret;
515} 515}
516 516
@@ -595,7 +595,7 @@ ctnetlink_parse_nat(struct nfattr *nat,
595 int err; 595 int err;
596 596
597 memset(range, 0, sizeof(*range)); 597 memset(range, 0, sizeof(*range));
598 598
599 nfattr_parse_nested(tb, CTA_NAT_MAX, nat); 599 nfattr_parse_nested(tb, CTA_NAT_MAX, nat);
600 600
601 if (nfattr_bad_size(tb, CTA_NAT_MAX, cta_min_nat)) 601 if (nfattr_bad_size(tb, CTA_NAT_MAX, cta_min_nat))
@@ -647,7 +647,7 @@ static const size_t cta_min[CTA_MAX] = {
647}; 647};
648 648
649static int 649static int
650ctnetlink_del_conntrack(struct sock *ctnl, struct sk_buff *skb, 650ctnetlink_del_conntrack(struct sock *ctnl, struct sk_buff *skb,
651 struct nlmsghdr *nlh, struct nfattr *cda[], int *errp) 651 struct nlmsghdr *nlh, struct nfattr *cda[], int *errp)
652{ 652{
653 struct ip_conntrack_tuple_hash *h; 653 struct ip_conntrack_tuple_hash *h;
@@ -676,14 +676,14 @@ ctnetlink_del_conntrack(struct sock *ctnl, struct sk_buff *skb,
676 return -ENOENT; 676 return -ENOENT;
677 677
678 ct = tuplehash_to_ctrack(h); 678 ct = tuplehash_to_ctrack(h);
679 679
680 if (cda[CTA_ID-1]) { 680 if (cda[CTA_ID-1]) {
681 u_int32_t id = ntohl(*(__be32 *)NFA_DATA(cda[CTA_ID-1])); 681 u_int32_t id = ntohl(*(__be32 *)NFA_DATA(cda[CTA_ID-1]));
682 if (ct->id != id) { 682 if (ct->id != id) {
683 ip_conntrack_put(ct); 683 ip_conntrack_put(ct);
684 return -ENOENT; 684 return -ENOENT;
685 } 685 }
686 } 686 }
687 if (del_timer(&ct->timeout)) 687 if (del_timer(&ct->timeout))
688 ct->timeout.function((unsigned long)ct); 688 ct->timeout.function((unsigned long)ct);
689 689
@@ -693,7 +693,7 @@ ctnetlink_del_conntrack(struct sock *ctnl, struct sk_buff *skb,
693} 693}
694 694
695static int 695static int
696ctnetlink_get_conntrack(struct sock *ctnl, struct sk_buff *skb, 696ctnetlink_get_conntrack(struct sock *ctnl, struct sk_buff *skb,
697 struct nlmsghdr *nlh, struct nfattr *cda[], int *errp) 697 struct nlmsghdr *nlh, struct nfattr *cda[], int *errp)
698{ 698{
699 struct ip_conntrack_tuple_hash *h; 699 struct ip_conntrack_tuple_hash *h;
@@ -714,8 +714,8 @@ ctnetlink_get_conntrack(struct sock *ctnl, struct sk_buff *skb,
714 return -ENOTSUPP; 714 return -ENOTSUPP;
715#endif 715#endif
716 if ((*errp = netlink_dump_start(ctnl, skb, nlh, 716 if ((*errp = netlink_dump_start(ctnl, skb, nlh,
717 ctnetlink_dump_table, 717 ctnetlink_dump_table,
718 ctnetlink_done)) != 0) 718 ctnetlink_done)) != 0)
719 return -EINVAL; 719 return -EINVAL;
720 720
721 rlen = NLMSG_ALIGN(nlh->nlmsg_len); 721 rlen = NLMSG_ALIGN(nlh->nlmsg_len);
@@ -751,7 +751,7 @@ ctnetlink_get_conntrack(struct sock *ctnl, struct sk_buff *skb,
751 return -ENOMEM; 751 return -ENOMEM;
752 } 752 }
753 753
754 err = ctnetlink_fill_info(skb2, NETLINK_CB(skb).pid, nlh->nlmsg_seq, 754 err = ctnetlink_fill_info(skb2, NETLINK_CB(skb).pid, nlh->nlmsg_seq,
755 IPCTNL_MSG_CT_NEW, 1, ct); 755 IPCTNL_MSG_CT_NEW, 1, ct);
756 ip_conntrack_put(ct); 756 ip_conntrack_put(ct);
757 if (err <= 0) 757 if (err <= 0)
@@ -779,12 +779,12 @@ ctnetlink_change_status(struct ip_conntrack *ct, struct nfattr *cda[])
779 if (d & (IPS_EXPECTED|IPS_CONFIRMED|IPS_DYING)) 779 if (d & (IPS_EXPECTED|IPS_CONFIRMED|IPS_DYING))
780 /* unchangeable */ 780 /* unchangeable */
781 return -EINVAL; 781 return -EINVAL;
782 782
783 if (d & IPS_SEEN_REPLY && !(status & IPS_SEEN_REPLY)) 783 if (d & IPS_SEEN_REPLY && !(status & IPS_SEEN_REPLY))
784 /* SEEN_REPLY bit can only be set */ 784 /* SEEN_REPLY bit can only be set */
785 return -EINVAL; 785 return -EINVAL;
786 786
787 787
788 if (d & IPS_ASSURED && !(status & IPS_ASSURED)) 788 if (d & IPS_ASSURED && !(status & IPS_ASSURED))
789 /* ASSURED bit can only be set */ 789 /* ASSURED bit can only be set */
790 return -EINVAL; 790 return -EINVAL;
@@ -857,7 +857,7 @@ ctnetlink_change_helper(struct ip_conntrack *ct, struct nfattr *cda[])
857 memset(&ct->help, 0, sizeof(ct->help)); 857 memset(&ct->help, 0, sizeof(ct->help));
858 } 858 }
859 } 859 }
860 860
861 ct->helper = helper; 861 ct->helper = helper;
862 862
863 return 0; 863 return 0;
@@ -867,7 +867,7 @@ static inline int
867ctnetlink_change_timeout(struct ip_conntrack *ct, struct nfattr *cda[]) 867ctnetlink_change_timeout(struct ip_conntrack *ct, struct nfattr *cda[])
868{ 868{
869 u_int32_t timeout = ntohl(*(__be32 *)NFA_DATA(cda[CTA_TIMEOUT-1])); 869 u_int32_t timeout = ntohl(*(__be32 *)NFA_DATA(cda[CTA_TIMEOUT-1]));
870 870
871 if (!del_timer(&ct->timeout)) 871 if (!del_timer(&ct->timeout))
872 return -ETIME; 872 return -ETIME;
873 873
@@ -891,7 +891,7 @@ ctnetlink_change_protoinfo(struct ip_conntrack *ct, struct nfattr *cda[])
891 891
892 if (proto->from_nfattr) 892 if (proto->from_nfattr)
893 err = proto->from_nfattr(tb, ct); 893 err = proto->from_nfattr(tb, ct);
894 ip_conntrack_proto_put(proto); 894 ip_conntrack_proto_put(proto);
895 895
896 return err; 896 return err;
897} 897}
@@ -934,7 +934,7 @@ ctnetlink_change_conntrack(struct ip_conntrack *ct, struct nfattr *cda[])
934} 934}
935 935
936static int 936static int
937ctnetlink_create_conntrack(struct nfattr *cda[], 937ctnetlink_create_conntrack(struct nfattr *cda[],
938 struct ip_conntrack_tuple *otuple, 938 struct ip_conntrack_tuple *otuple,
939 struct ip_conntrack_tuple *rtuple) 939 struct ip_conntrack_tuple *rtuple)
940{ 940{
@@ -943,7 +943,7 @@ ctnetlink_create_conntrack(struct nfattr *cda[],
943 943
944 ct = ip_conntrack_alloc(otuple, rtuple); 944 ct = ip_conntrack_alloc(otuple, rtuple);
945 if (ct == NULL || IS_ERR(ct)) 945 if (ct == NULL || IS_ERR(ct))
946 return -ENOMEM; 946 return -ENOMEM;
947 947
948 if (!cda[CTA_TIMEOUT-1]) 948 if (!cda[CTA_TIMEOUT-1])
949 goto err; 949 goto err;
@@ -979,13 +979,13 @@ ctnetlink_create_conntrack(struct nfattr *cda[],
979 979
980 return 0; 980 return 0;
981 981
982err: 982err:
983 ip_conntrack_free(ct); 983 ip_conntrack_free(ct);
984 return err; 984 return err;
985} 985}
986 986
987static int 987static int
988ctnetlink_new_conntrack(struct sock *ctnl, struct sk_buff *skb, 988ctnetlink_new_conntrack(struct sock *ctnl, struct sk_buff *skb,
989 struct nlmsghdr *nlh, struct nfattr *cda[], int *errp) 989 struct nlmsghdr *nlh, struct nfattr *cda[], int *errp)
990{ 990{
991 struct ip_conntrack_tuple otuple, rtuple; 991 struct ip_conntrack_tuple otuple, rtuple;
@@ -1039,9 +1039,9 @@ out_unlock:
1039 return err; 1039 return err;
1040} 1040}
1041 1041
1042/*********************************************************************** 1042/***********************************************************************
1043 * EXPECT 1043 * EXPECT
1044 ***********************************************************************/ 1044 ***********************************************************************/
1045 1045
1046static inline int 1046static inline int
1047ctnetlink_exp_dump_tuple(struct sk_buff *skb, 1047ctnetlink_exp_dump_tuple(struct sk_buff *skb,
@@ -1049,7 +1049,7 @@ ctnetlink_exp_dump_tuple(struct sk_buff *skb,
1049 enum ctattr_expect type) 1049 enum ctattr_expect type)
1050{ 1050{
1051 struct nfattr *nest_parms = NFA_NEST(skb, type); 1051 struct nfattr *nest_parms = NFA_NEST(skb, type);
1052 1052
1053 if (ctnetlink_dump_tuples(skb, tuple) < 0) 1053 if (ctnetlink_dump_tuples(skb, tuple) < 0)
1054 goto nfattr_failure; 1054 goto nfattr_failure;
1055 1055
@@ -1059,7 +1059,7 @@ ctnetlink_exp_dump_tuple(struct sk_buff *skb,
1059 1059
1060nfattr_failure: 1060nfattr_failure:
1061 return -1; 1061 return -1;
1062} 1062}
1063 1063
1064static inline int 1064static inline int
1065ctnetlink_exp_dump_mask(struct sk_buff *skb, 1065ctnetlink_exp_dump_mask(struct sk_buff *skb,
@@ -1090,7 +1090,7 @@ nfattr_failure:
1090 1090
1091static inline int 1091static inline int
1092ctnetlink_exp_dump_expect(struct sk_buff *skb, 1092ctnetlink_exp_dump_expect(struct sk_buff *skb,
1093 const struct ip_conntrack_expect *exp) 1093 const struct ip_conntrack_expect *exp)
1094{ 1094{
1095 struct ip_conntrack *master = exp->master; 1095 struct ip_conntrack *master = exp->master;
1096 __be32 timeout = htonl((exp->timeout.expires - jiffies) / HZ); 1096 __be32 timeout = htonl((exp->timeout.expires - jiffies) / HZ);
@@ -1104,20 +1104,20 @@ ctnetlink_exp_dump_expect(struct sk_buff *skb,
1104 &master->tuplehash[IP_CT_DIR_ORIGINAL].tuple, 1104 &master->tuplehash[IP_CT_DIR_ORIGINAL].tuple,
1105 CTA_EXPECT_MASTER) < 0) 1105 CTA_EXPECT_MASTER) < 0)
1106 goto nfattr_failure; 1106 goto nfattr_failure;
1107 1107
1108 NFA_PUT(skb, CTA_EXPECT_TIMEOUT, sizeof(__be32), &timeout); 1108 NFA_PUT(skb, CTA_EXPECT_TIMEOUT, sizeof(__be32), &timeout);
1109 NFA_PUT(skb, CTA_EXPECT_ID, sizeof(__be32), &id); 1109 NFA_PUT(skb, CTA_EXPECT_ID, sizeof(__be32), &id);
1110 1110
1111 return 0; 1111 return 0;
1112 1112
1113nfattr_failure: 1113nfattr_failure:
1114 return -1; 1114 return -1;
1115} 1115}
1116 1116
1117static int 1117static int
1118ctnetlink_exp_fill_info(struct sk_buff *skb, u32 pid, u32 seq, 1118ctnetlink_exp_fill_info(struct sk_buff *skb, u32 pid, u32 seq,
1119 int event, 1119 int event,
1120 int nowait, 1120 int nowait,
1121 const struct ip_conntrack_expect *exp) 1121 const struct ip_conntrack_expect *exp)
1122{ 1122{
1123 struct nlmsghdr *nlh; 1123 struct nlmsghdr *nlh;
@@ -1216,7 +1216,7 @@ ctnetlink_exp_dump_table(struct sk_buff *skb, struct netlink_callback *cb)
1216 goto out; 1216 goto out;
1217 *id = exp->id; 1217 *id = exp->id;
1218 } 1218 }
1219out: 1219out:
1220 read_unlock_bh(&ip_conntrack_lock); 1220 read_unlock_bh(&ip_conntrack_lock);
1221 1221
1222 return skb->len; 1222 return skb->len;
@@ -1228,7 +1228,7 @@ static const size_t cta_min_exp[CTA_EXPECT_MAX] = {
1228}; 1228};
1229 1229
1230static int 1230static int
1231ctnetlink_get_expect(struct sock *ctnl, struct sk_buff *skb, 1231ctnetlink_get_expect(struct sock *ctnl, struct sk_buff *skb,
1232 struct nlmsghdr *nlh, struct nfattr *cda[], int *errp) 1232 struct nlmsghdr *nlh, struct nfattr *cda[], int *errp)
1233{ 1233{
1234 struct ip_conntrack_tuple tuple; 1234 struct ip_conntrack_tuple tuple;
@@ -1247,7 +1247,7 @@ ctnetlink_get_expect(struct sock *ctnl, struct sk_buff *skb,
1247 return -EAFNOSUPPORT; 1247 return -EAFNOSUPPORT;
1248 1248
1249 if ((*errp = netlink_dump_start(ctnl, skb, nlh, 1249 if ((*errp = netlink_dump_start(ctnl, skb, nlh,
1250 ctnetlink_exp_dump_table, 1250 ctnetlink_exp_dump_table,
1251 ctnetlink_done)) != 0) 1251 ctnetlink_done)) != 0)
1252 return -EINVAL; 1252 return -EINVAL;
1253 rlen = NLMSG_ALIGN(nlh->nlmsg_len); 1253 rlen = NLMSG_ALIGN(nlh->nlmsg_len);
@@ -1275,14 +1275,14 @@ ctnetlink_get_expect(struct sock *ctnl, struct sk_buff *skb,
1275 ip_conntrack_expect_put(exp); 1275 ip_conntrack_expect_put(exp);
1276 return -ENOENT; 1276 return -ENOENT;
1277 } 1277 }
1278 } 1278 }
1279 1279
1280 err = -ENOMEM; 1280 err = -ENOMEM;
1281 skb2 = alloc_skb(NLMSG_GOODSIZE, GFP_KERNEL); 1281 skb2 = alloc_skb(NLMSG_GOODSIZE, GFP_KERNEL);
1282 if (!skb2) 1282 if (!skb2)
1283 goto out; 1283 goto out;
1284 1284
1285 err = ctnetlink_exp_fill_info(skb2, NETLINK_CB(skb).pid, 1285 err = ctnetlink_exp_fill_info(skb2, NETLINK_CB(skb).pid,
1286 nlh->nlmsg_seq, IPCTNL_MSG_EXP_NEW, 1286 nlh->nlmsg_seq, IPCTNL_MSG_EXP_NEW,
1287 1, exp); 1287 1, exp);
1288 if (err <= 0) 1288 if (err <= 0)
@@ -1300,7 +1300,7 @@ out:
1300} 1300}
1301 1301
1302static int 1302static int
1303ctnetlink_del_expect(struct sock *ctnl, struct sk_buff *skb, 1303ctnetlink_del_expect(struct sock *ctnl, struct sk_buff *skb,
1304 struct nlmsghdr *nlh, struct nfattr *cda[], int *errp) 1304 struct nlmsghdr *nlh, struct nfattr *cda[], int *errp)
1305{ 1305{
1306 struct ip_conntrack_expect *exp, *tmp; 1306 struct ip_conntrack_expect *exp, *tmp;
@@ -1333,7 +1333,7 @@ ctnetlink_del_expect(struct sock *ctnl, struct sk_buff *skb,
1333 1333
1334 /* after list removal, usage count == 1 */ 1334 /* after list removal, usage count == 1 */
1335 ip_conntrack_unexpect_related(exp); 1335 ip_conntrack_unexpect_related(exp);
1336 /* have to put what we 'get' above. 1336 /* have to put what we 'get' above.
1337 * after this line usage count == 0 */ 1337 * after this line usage count == 0 */
1338 ip_conntrack_expect_put(exp); 1338 ip_conntrack_expect_put(exp);
1339 } else if (cda[CTA_EXPECT_HELP_NAME-1]) { 1339 } else if (cda[CTA_EXPECT_HELP_NAME-1]) {
@@ -1348,7 +1348,7 @@ ctnetlink_del_expect(struct sock *ctnl, struct sk_buff *skb,
1348 } 1348 }
1349 list_for_each_entry_safe(exp, tmp, &ip_conntrack_expect_list, 1349 list_for_each_entry_safe(exp, tmp, &ip_conntrack_expect_list,
1350 list) { 1350 list) {
1351 if (exp->master->helper == h 1351 if (exp->master->helper == h
1352 && del_timer(&exp->timeout)) { 1352 && del_timer(&exp->timeout)) {
1353 ip_ct_unlink_expect(exp); 1353 ip_ct_unlink_expect(exp);
1354 ip_conntrack_expect_put(exp); 1354 ip_conntrack_expect_put(exp);
@@ -1413,7 +1413,7 @@ ctnetlink_create_expect(struct nfattr *cda[])
1413 err = -ENOMEM; 1413 err = -ENOMEM;
1414 goto out; 1414 goto out;
1415 } 1415 }
1416 1416
1417 exp->expectfn = NULL; 1417 exp->expectfn = NULL;
1418 exp->flags = 0; 1418 exp->flags = 0;
1419 exp->master = ct; 1419 exp->master = ct;
@@ -1423,7 +1423,7 @@ ctnetlink_create_expect(struct nfattr *cda[])
1423 err = ip_conntrack_expect_related(exp); 1423 err = ip_conntrack_expect_related(exp);
1424 ip_conntrack_expect_put(exp); 1424 ip_conntrack_expect_put(exp);
1425 1425
1426out: 1426out:
1427 ip_conntrack_put(tuplehash_to_ctrack(h)); 1427 ip_conntrack_put(tuplehash_to_ctrack(h));
1428 return err; 1428 return err;
1429} 1429}
diff --git a/net/ipv4/netfilter/ip_conntrack_proto_icmp.c b/net/ipv4/netfilter/ip_conntrack_proto_icmp.c
index 295b6fa340db..ec71abead00c 100644
--- a/net/ipv4/netfilter/ip_conntrack_proto_icmp.c
+++ b/net/ipv4/netfilter/ip_conntrack_proto_icmp.c
@@ -94,9 +94,9 @@ static int icmp_packet(struct ip_conntrack *ct,
94 enum ip_conntrack_info ctinfo) 94 enum ip_conntrack_info ctinfo)
95{ 95{
96 /* Try to delete connection immediately after all replies: 96 /* Try to delete connection immediately after all replies:
97 won't actually vanish as we still have skb, and del_timer 97 won't actually vanish as we still have skb, and del_timer
98 means this will only run once even if count hits zero twice 98 means this will only run once even if count hits zero twice
99 (theoretically possible with SMP) */ 99 (theoretically possible with SMP) */
100 if (CTINFO2DIR(ctinfo) == IP_CT_DIR_REPLY) { 100 if (CTINFO2DIR(ctinfo) == IP_CT_DIR_REPLY) {
101 if (atomic_dec_and_test(&ct->proto.icmp.count) 101 if (atomic_dec_and_test(&ct->proto.icmp.count)
102 && del_timer(&ct->timeout)) 102 && del_timer(&ct->timeout))
@@ -114,11 +114,11 @@ static int icmp_packet(struct ip_conntrack *ct,
114static int icmp_new(struct ip_conntrack *conntrack, 114static int icmp_new(struct ip_conntrack *conntrack,
115 const struct sk_buff *skb) 115 const struct sk_buff *skb)
116{ 116{
117 static const u_int8_t valid_new[] = { 117 static const u_int8_t valid_new[] = {
118 [ICMP_ECHO] = 1, 118 [ICMP_ECHO] = 1,
119 [ICMP_TIMESTAMP] = 1, 119 [ICMP_TIMESTAMP] = 1,
120 [ICMP_INFO_REQUEST] = 1, 120 [ICMP_INFO_REQUEST] = 1,
121 [ICMP_ADDRESS] = 1 121 [ICMP_ADDRESS] = 1
122 }; 122 };
123 123
124 if (conntrack->tuplehash[0].tuple.dst.u.icmp.type >= sizeof(valid_new) 124 if (conntrack->tuplehash[0].tuple.dst.u.icmp.type >= sizeof(valid_new)
@@ -282,7 +282,7 @@ static int icmp_nfattr_to_tuple(struct nfattr *tb[],
282 || !tb[CTA_PROTO_ICMP_ID-1]) 282 || !tb[CTA_PROTO_ICMP_ID-1])
283 return -EINVAL; 283 return -EINVAL;
284 284
285 tuple->dst.u.icmp.type = 285 tuple->dst.u.icmp.type =
286 *(u_int8_t *)NFA_DATA(tb[CTA_PROTO_ICMP_TYPE-1]); 286 *(u_int8_t *)NFA_DATA(tb[CTA_PROTO_ICMP_TYPE-1]);
287 tuple->dst.u.icmp.code = 287 tuple->dst.u.icmp.code =
288 *(u_int8_t *)NFA_DATA(tb[CTA_PROTO_ICMP_CODE-1]); 288 *(u_int8_t *)NFA_DATA(tb[CTA_PROTO_ICMP_CODE-1]);
diff --git a/net/ipv4/netfilter/ip_conntrack_proto_sctp.c b/net/ipv4/netfilter/ip_conntrack_proto_sctp.c
index 2443322e4128..9d5b917f49cd 100644
--- a/net/ipv4/netfilter/ip_conntrack_proto_sctp.c
+++ b/net/ipv4/netfilter/ip_conntrack_proto_sctp.c
@@ -1,9 +1,9 @@
1/* 1/*
2 * Connection tracking protocol helper module for SCTP. 2 * Connection tracking protocol helper module for SCTP.
3 * 3 *
4 * SCTP is defined in RFC 2960. References to various sections in this code 4 * SCTP is defined in RFC 2960. References to various sections in this code
5 * are to this RFC. 5 * are to this RFC.
6 * 6 *
7 * This program is free software; you can redistribute it and/or modify 7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as 8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation. 9 * published by the Free Software Foundation.
@@ -38,7 +38,7 @@
38static DEFINE_RWLOCK(sctp_lock); 38static DEFINE_RWLOCK(sctp_lock);
39 39
40/* FIXME: Examine ipfilter's timeouts and conntrack transitions more 40/* FIXME: Examine ipfilter's timeouts and conntrack transitions more
41 closely. They're more complex. --RR 41 closely. They're more complex. --RR
42 42
43 And so for me for SCTP :D -Kiran */ 43 And so for me for SCTP :D -Kiran */
44 44
@@ -87,32 +87,32 @@ static const unsigned int * sctp_timeouts[]
87#define sSA SCTP_CONNTRACK_SHUTDOWN_ACK_SENT 87#define sSA SCTP_CONNTRACK_SHUTDOWN_ACK_SENT
88#define sIV SCTP_CONNTRACK_MAX 88#define sIV SCTP_CONNTRACK_MAX
89 89
90/* 90/*
91 These are the descriptions of the states: 91 These are the descriptions of the states:
92 92
93NOTE: These state names are tantalizingly similar to the states of an 93NOTE: These state names are tantalizingly similar to the states of an
94SCTP endpoint. But the interpretation of the states is a little different, 94SCTP endpoint. But the interpretation of the states is a little different,
95considering that these are the states of the connection and not of an end 95considering that these are the states of the connection and not of an end
96point. Please note the subtleties. -Kiran 96point. Please note the subtleties. -Kiran
97 97
98NONE - Nothing so far. 98NONE - Nothing so far.
99COOKIE WAIT - We have seen an INIT chunk in the original direction, or also 99COOKIE WAIT - We have seen an INIT chunk in the original direction, or also
100 an INIT_ACK chunk in the reply direction. 100 an INIT_ACK chunk in the reply direction.
101COOKIE ECHOED - We have seen a COOKIE_ECHO chunk in the original direction. 101COOKIE ECHOED - We have seen a COOKIE_ECHO chunk in the original direction.
102ESTABLISHED - We have seen a COOKIE_ACK in the reply direction. 102ESTABLISHED - We have seen a COOKIE_ACK in the reply direction.
103SHUTDOWN_SENT - We have seen a SHUTDOWN chunk in the original direction. 103SHUTDOWN_SENT - We have seen a SHUTDOWN chunk in the original direction.
104SHUTDOWN_RECD - We have seen a SHUTDOWN chunk in the reply directoin. 104SHUTDOWN_RECD - We have seen a SHUTDOWN chunk in the reply directoin.
105SHUTDOWN_ACK_SENT - We have seen a SHUTDOWN_ACK chunk in the direction opposite 105SHUTDOWN_ACK_SENT - We have seen a SHUTDOWN_ACK chunk in the direction opposite
106 to that of the SHUTDOWN chunk. 106 to that of the SHUTDOWN chunk.
107CLOSED - We have seen a SHUTDOWN_COMPLETE chunk in the direction of 107CLOSED - We have seen a SHUTDOWN_COMPLETE chunk in the direction of
108 the SHUTDOWN chunk. Connection is closed. 108 the SHUTDOWN chunk. Connection is closed.
109*/ 109*/
110 110
111/* TODO 111/* TODO
112 - I have assumed that the first INIT is in the original direction. 112 - I have assumed that the first INIT is in the original direction.
113 This messes things when an INIT comes in the reply direction in CLOSED 113 This messes things when an INIT comes in the reply direction in CLOSED
114 state. 114 state.
115 - Check the error type in the reply dir before transitioning from 115 - Check the error type in the reply dir before transitioning from
116cookie echoed to closed. 116cookie echoed to closed.
117 - Sec 5.2.4 of RFC 2960 117 - Sec 5.2.4 of RFC 2960
118 - Multi Homing support. 118 - Multi Homing support.
@@ -229,7 +229,7 @@ static int do_basic_checks(struct ip_conntrack *conntrack,
229 for_each_sctp_chunk (skb, sch, _sch, offset, count) { 229 for_each_sctp_chunk (skb, sch, _sch, offset, count) {
230 DEBUGP("Chunk Num: %d Type: %d\n", count, sch->type); 230 DEBUGP("Chunk Num: %d Type: %d\n", count, sch->type);
231 231
232 if (sch->type == SCTP_CID_INIT 232 if (sch->type == SCTP_CID_INIT
233 || sch->type == SCTP_CID_INIT_ACK 233 || sch->type == SCTP_CID_INIT_ACK
234 || sch->type == SCTP_CID_SHUTDOWN_COMPLETE) { 234 || sch->type == SCTP_CID_SHUTDOWN_COMPLETE) {
235 flag = 1; 235 flag = 1;
@@ -269,42 +269,42 @@ static int new_state(enum ip_conntrack_dir dir,
269 DEBUGP("Chunk type: %d\n", chunk_type); 269 DEBUGP("Chunk type: %d\n", chunk_type);
270 270
271 switch (chunk_type) { 271 switch (chunk_type) {
272 case SCTP_CID_INIT: 272 case SCTP_CID_INIT:
273 DEBUGP("SCTP_CID_INIT\n"); 273 DEBUGP("SCTP_CID_INIT\n");
274 i = 0; break; 274 i = 0; break;
275 case SCTP_CID_INIT_ACK: 275 case SCTP_CID_INIT_ACK:
276 DEBUGP("SCTP_CID_INIT_ACK\n"); 276 DEBUGP("SCTP_CID_INIT_ACK\n");
277 i = 1; break; 277 i = 1; break;
278 case SCTP_CID_ABORT: 278 case SCTP_CID_ABORT:
279 DEBUGP("SCTP_CID_ABORT\n"); 279 DEBUGP("SCTP_CID_ABORT\n");
280 i = 2; break; 280 i = 2; break;
281 case SCTP_CID_SHUTDOWN: 281 case SCTP_CID_SHUTDOWN:
282 DEBUGP("SCTP_CID_SHUTDOWN\n"); 282 DEBUGP("SCTP_CID_SHUTDOWN\n");
283 i = 3; break; 283 i = 3; break;
284 case SCTP_CID_SHUTDOWN_ACK: 284 case SCTP_CID_SHUTDOWN_ACK:
285 DEBUGP("SCTP_CID_SHUTDOWN_ACK\n"); 285 DEBUGP("SCTP_CID_SHUTDOWN_ACK\n");
286 i = 4; break; 286 i = 4; break;
287 case SCTP_CID_ERROR: 287 case SCTP_CID_ERROR:
288 DEBUGP("SCTP_CID_ERROR\n"); 288 DEBUGP("SCTP_CID_ERROR\n");
289 i = 5; break; 289 i = 5; break;
290 case SCTP_CID_COOKIE_ECHO: 290 case SCTP_CID_COOKIE_ECHO:
291 DEBUGP("SCTP_CID_COOKIE_ECHO\n"); 291 DEBUGP("SCTP_CID_COOKIE_ECHO\n");
292 i = 6; break; 292 i = 6; break;
293 case SCTP_CID_COOKIE_ACK: 293 case SCTP_CID_COOKIE_ACK:
294 DEBUGP("SCTP_CID_COOKIE_ACK\n"); 294 DEBUGP("SCTP_CID_COOKIE_ACK\n");
295 i = 7; break; 295 i = 7; break;
296 case SCTP_CID_SHUTDOWN_COMPLETE: 296 case SCTP_CID_SHUTDOWN_COMPLETE:
297 DEBUGP("SCTP_CID_SHUTDOWN_COMPLETE\n"); 297 DEBUGP("SCTP_CID_SHUTDOWN_COMPLETE\n");
298 i = 8; break; 298 i = 8; break;
299 default: 299 default:
300 /* Other chunks like DATA, SACK, HEARTBEAT and 300 /* Other chunks like DATA, SACK, HEARTBEAT and
301 its ACK do not cause a change in state */ 301 its ACK do not cause a change in state */
302 DEBUGP("Unknown chunk type, Will stay in %s\n", 302 DEBUGP("Unknown chunk type, Will stay in %s\n",
303 sctp_conntrack_names[cur_state]); 303 sctp_conntrack_names[cur_state]);
304 return cur_state; 304 return cur_state;
305 } 305 }
306 306
307 DEBUGP("dir: %d cur_state: %s chunk_type: %d new_state: %s\n", 307 DEBUGP("dir: %d cur_state: %s chunk_type: %d new_state: %s\n",
308 dir, sctp_conntrack_names[cur_state], chunk_type, 308 dir, sctp_conntrack_names[cur_state], chunk_type,
309 sctp_conntrack_names[sctp_conntracks[dir][i][cur_state]]); 309 sctp_conntrack_names[sctp_conntracks[dir][i][cur_state]]);
310 310
@@ -367,7 +367,7 @@ static int sctp_packet(struct ip_conntrack *conntrack,
367 /* Sec 8.5.1 (C) */ 367 /* Sec 8.5.1 (C) */
368 if (!(sh->vtag == conntrack->proto.sctp.vtag[CTINFO2DIR(ctinfo)]) 368 if (!(sh->vtag == conntrack->proto.sctp.vtag[CTINFO2DIR(ctinfo)])
369 && !(sh->vtag == conntrack->proto.sctp.vtag 369 && !(sh->vtag == conntrack->proto.sctp.vtag
370 [1 - CTINFO2DIR(ctinfo)] 370 [1 - CTINFO2DIR(ctinfo)]
371 && (sch->flags & 1))) { 371 && (sch->flags & 1))) {
372 write_unlock_bh(&sctp_lock); 372 write_unlock_bh(&sctp_lock);
373 return -1; 373 return -1;
@@ -392,17 +392,17 @@ static int sctp_packet(struct ip_conntrack *conntrack,
392 } 392 }
393 393
394 /* If it is an INIT or an INIT ACK note down the vtag */ 394 /* If it is an INIT or an INIT ACK note down the vtag */
395 if (sch->type == SCTP_CID_INIT 395 if (sch->type == SCTP_CID_INIT
396 || sch->type == SCTP_CID_INIT_ACK) { 396 || sch->type == SCTP_CID_INIT_ACK) {
397 sctp_inithdr_t _inithdr, *ih; 397 sctp_inithdr_t _inithdr, *ih;
398 398
399 ih = skb_header_pointer(skb, offset + sizeof(sctp_chunkhdr_t), 399 ih = skb_header_pointer(skb, offset + sizeof(sctp_chunkhdr_t),
400 sizeof(_inithdr), &_inithdr); 400 sizeof(_inithdr), &_inithdr);
401 if (ih == NULL) { 401 if (ih == NULL) {
402 write_unlock_bh(&sctp_lock); 402 write_unlock_bh(&sctp_lock);
403 return -1; 403 return -1;
404 } 404 }
405 DEBUGP("Setting vtag %x for dir %d\n", 405 DEBUGP("Setting vtag %x for dir %d\n",
406 ih->init_tag, !CTINFO2DIR(ctinfo)); 406 ih->init_tag, !CTINFO2DIR(ctinfo));
407 conntrack->proto.sctp.vtag[!CTINFO2DIR(ctinfo)] = ih->init_tag; 407 conntrack->proto.sctp.vtag[!CTINFO2DIR(ctinfo)] = ih->init_tag;
408 } 408 }
@@ -427,7 +427,7 @@ static int sctp_packet(struct ip_conntrack *conntrack,
427} 427}
428 428
429/* Called when a new connection for this protocol found. */ 429/* Called when a new connection for this protocol found. */
430static int sctp_new(struct ip_conntrack *conntrack, 430static int sctp_new(struct ip_conntrack *conntrack,
431 const struct sk_buff *skb) 431 const struct sk_buff *skb)
432{ 432{
433 enum sctp_conntrack newconntrack; 433 enum sctp_conntrack newconntrack;
@@ -457,7 +457,7 @@ static int sctp_new(struct ip_conntrack *conntrack,
457 newconntrack = SCTP_CONNTRACK_MAX; 457 newconntrack = SCTP_CONNTRACK_MAX;
458 for_each_sctp_chunk (skb, sch, _sch, offset, count) { 458 for_each_sctp_chunk (skb, sch, _sch, offset, count) {
459 /* Don't need lock here: this conntrack not in circulation yet */ 459 /* Don't need lock here: this conntrack not in circulation yet */
460 newconntrack = new_state (IP_CT_DIR_ORIGINAL, 460 newconntrack = new_state (IP_CT_DIR_ORIGINAL,
461 SCTP_CONNTRACK_NONE, sch->type); 461 SCTP_CONNTRACK_NONE, sch->type);
462 462
463 /* Invalid: delete conntrack */ 463 /* Invalid: delete conntrack */
@@ -472,14 +472,14 @@ static int sctp_new(struct ip_conntrack *conntrack,
472 sctp_inithdr_t _inithdr, *ih; 472 sctp_inithdr_t _inithdr, *ih;
473 473
474 ih = skb_header_pointer(skb, offset + sizeof(sctp_chunkhdr_t), 474 ih = skb_header_pointer(skb, offset + sizeof(sctp_chunkhdr_t),
475 sizeof(_inithdr), &_inithdr); 475 sizeof(_inithdr), &_inithdr);
476 if (ih == NULL) 476 if (ih == NULL)
477 return 0; 477 return 0;
478 478
479 DEBUGP("Setting vtag %x for new conn\n", 479 DEBUGP("Setting vtag %x for new conn\n",
480 ih->init_tag); 480 ih->init_tag);
481 481
482 conntrack->proto.sctp.vtag[IP_CT_DIR_REPLY] = 482 conntrack->proto.sctp.vtag[IP_CT_DIR_REPLY] =
483 ih->init_tag; 483 ih->init_tag;
484 } else { 484 } else {
485 /* Sec 8.5.1 (A) */ 485 /* Sec 8.5.1 (A) */
@@ -489,7 +489,7 @@ static int sctp_new(struct ip_conntrack *conntrack,
489 /* If it is a shutdown ack OOTB packet, we expect a return 489 /* If it is a shutdown ack OOTB packet, we expect a return
490 shutdown complete, otherwise an ABORT Sec 8.4 (5) and (8) */ 490 shutdown complete, otherwise an ABORT Sec 8.4 (5) and (8) */
491 else { 491 else {
492 DEBUGP("Setting vtag %x for new conn OOTB\n", 492 DEBUGP("Setting vtag %x for new conn OOTB\n",
493 sh->vtag); 493 sh->vtag);
494 conntrack->proto.sctp.vtag[IP_CT_DIR_REPLY] = sh->vtag; 494 conntrack->proto.sctp.vtag[IP_CT_DIR_REPLY] = sh->vtag;
495 } 495 }
@@ -500,16 +500,16 @@ static int sctp_new(struct ip_conntrack *conntrack,
500 return 1; 500 return 1;
501} 501}
502 502
503static struct ip_conntrack_protocol ip_conntrack_protocol_sctp = { 503static struct ip_conntrack_protocol ip_conntrack_protocol_sctp = {
504 .proto = IPPROTO_SCTP, 504 .proto = IPPROTO_SCTP,
505 .name = "sctp", 505 .name = "sctp",
506 .pkt_to_tuple = sctp_pkt_to_tuple, 506 .pkt_to_tuple = sctp_pkt_to_tuple,
507 .invert_tuple = sctp_invert_tuple, 507 .invert_tuple = sctp_invert_tuple,
508 .print_tuple = sctp_print_tuple, 508 .print_tuple = sctp_print_tuple,
509 .print_conntrack = sctp_print_conntrack, 509 .print_conntrack = sctp_print_conntrack,
510 .packet = sctp_packet, 510 .packet = sctp_packet,
511 .new = sctp_new, 511 .new = sctp_new,
512 .destroy = NULL, 512 .destroy = NULL,
513 .me = THIS_MODULE, 513 .me = THIS_MODULE,
514#if defined(CONFIG_IP_NF_CONNTRACK_NETLINK) || \ 514#if defined(CONFIG_IP_NF_CONNTRACK_NETLINK) || \
515 defined(CONFIG_IP_NF_CONNTRACK_NETLINK_MODULE) 515 defined(CONFIG_IP_NF_CONNTRACK_NETLINK_MODULE)
@@ -603,7 +603,7 @@ static ctl_table ip_ct_net_table[] = {
603 { 603 {
604 .ctl_name = CTL_NET, 604 .ctl_name = CTL_NET,
605 .procname = "net", 605 .procname = "net",
606 .mode = 0555, 606 .mode = 0555,
607 .child = ip_ct_ipv4_table, 607 .child = ip_ct_ipv4_table,
608 }, 608 },
609 { .ctl_name = 0 } 609 { .ctl_name = 0 }
@@ -638,7 +638,7 @@ static int __init ip_conntrack_proto_sctp_init(void)
638 ip_conntrack_protocol_unregister(&ip_conntrack_protocol_sctp); 638 ip_conntrack_protocol_unregister(&ip_conntrack_protocol_sctp);
639#endif 639#endif
640 out: 640 out:
641 DEBUGP("SCTP conntrack module loading %s\n", 641 DEBUGP("SCTP conntrack module loading %s\n",
642 ret ? "failed": "succeeded"); 642 ret ? "failed": "succeeded");
643 return ret; 643 return ret;
644} 644}
@@ -647,7 +647,7 @@ static void __exit ip_conntrack_proto_sctp_fini(void)
647{ 647{
648 ip_conntrack_protocol_unregister(&ip_conntrack_protocol_sctp); 648 ip_conntrack_protocol_unregister(&ip_conntrack_protocol_sctp);
649#ifdef CONFIG_SYSCTL 649#ifdef CONFIG_SYSCTL
650 unregister_sysctl_table(ip_ct_sysctl_header); 650 unregister_sysctl_table(ip_ct_sysctl_header);
651#endif 651#endif
652 DEBUGP("SCTP conntrack module unloaded\n"); 652 DEBUGP("SCTP conntrack module unloaded\n");
653} 653}
diff --git a/net/ipv4/netfilter/ip_conntrack_proto_tcp.c b/net/ipv4/netfilter/ip_conntrack_proto_tcp.c
index 06e4e8a6dd9f..fa35b49fe2fa 100644
--- a/net/ipv4/netfilter/ip_conntrack_proto_tcp.c
+++ b/net/ipv4/netfilter/ip_conntrack_proto_tcp.c
@@ -45,20 +45,17 @@
45/* Protects conntrack->proto.tcp */ 45/* Protects conntrack->proto.tcp */
46static DEFINE_RWLOCK(tcp_lock); 46static DEFINE_RWLOCK(tcp_lock);
47 47
48/* "Be conservative in what you do, 48/* "Be conservative in what you do,
49 be liberal in what you accept from others." 49 be liberal in what you accept from others."
50 If it's non-zero, we mark only out of window RST segments as INVALID. */ 50 If it's non-zero, we mark only out of window RST segments as INVALID. */
51int ip_ct_tcp_be_liberal __read_mostly = 0; 51int ip_ct_tcp_be_liberal __read_mostly = 0;
52 52
53/* When connection is picked up from the middle, how many packets are required 53/* If it is set to zero, we disable picking up already established
54 to pass in each direction when we assume we are in sync - if any side uses
55 window scaling, we lost the game.
56 If it is set to zero, we disable picking up already established
57 connections. */ 54 connections. */
58int ip_ct_tcp_loose __read_mostly = 3; 55int ip_ct_tcp_loose __read_mostly = 1;
59 56
60/* Max number of the retransmitted packets without receiving an (acceptable) 57/* Max number of the retransmitted packets without receiving an (acceptable)
61 ACK from the destination. If this number is reached, a shorter timer 58 ACK from the destination. If this number is reached, a shorter timer
62 will be started. */ 59 will be started. */
63int ip_ct_tcp_max_retrans __read_mostly = 3; 60int ip_ct_tcp_max_retrans __read_mostly = 3;
64 61
@@ -77,7 +74,7 @@ static const char *tcp_conntrack_names[] = {
77 "CLOSE", 74 "CLOSE",
78 "LISTEN" 75 "LISTEN"
79}; 76};
80 77
81#define SECS * HZ 78#define SECS * HZ
82#define MINS * 60 SECS 79#define MINS * 60 SECS
83#define HOURS * 60 MINS 80#define HOURS * 60 MINS
@@ -93,10 +90,10 @@ unsigned int ip_ct_tcp_timeout_time_wait __read_mostly = 2 MINS;
93unsigned int ip_ct_tcp_timeout_close __read_mostly = 10 SECS; 90unsigned int ip_ct_tcp_timeout_close __read_mostly = 10 SECS;
94 91
95/* RFC1122 says the R2 limit should be at least 100 seconds. 92/* RFC1122 says the R2 limit should be at least 100 seconds.
96 Linux uses 15 packets as limit, which corresponds 93 Linux uses 15 packets as limit, which corresponds
97 to ~13-30min depending on RTO. */ 94 to ~13-30min depending on RTO. */
98unsigned int ip_ct_tcp_timeout_max_retrans __read_mostly = 5 MINS; 95unsigned int ip_ct_tcp_timeout_max_retrans __read_mostly = 5 MINS;
99 96
100static const unsigned int * tcp_timeouts[] 97static const unsigned int * tcp_timeouts[]
101= { NULL, /* TCP_CONNTRACK_NONE */ 98= { NULL, /* TCP_CONNTRACK_NONE */
102 &ip_ct_tcp_timeout_syn_sent, /* TCP_CONNTRACK_SYN_SENT, */ 99 &ip_ct_tcp_timeout_syn_sent, /* TCP_CONNTRACK_SYN_SENT, */
@@ -109,7 +106,7 @@ static const unsigned int * tcp_timeouts[]
109 &ip_ct_tcp_timeout_close, /* TCP_CONNTRACK_CLOSE, */ 106 &ip_ct_tcp_timeout_close, /* TCP_CONNTRACK_CLOSE, */
110 NULL, /* TCP_CONNTRACK_LISTEN */ 107 NULL, /* TCP_CONNTRACK_LISTEN */
111 }; 108 };
112 109
113#define sNO TCP_CONNTRACK_NONE 110#define sNO TCP_CONNTRACK_NONE
114#define sSS TCP_CONNTRACK_SYN_SENT 111#define sSS TCP_CONNTRACK_SYN_SENT
115#define sSR TCP_CONNTRACK_SYN_RECV 112#define sSR TCP_CONNTRACK_SYN_RECV
@@ -132,13 +129,13 @@ enum tcp_bit_set {
132 TCP_RST_SET, 129 TCP_RST_SET,
133 TCP_NONE_SET, 130 TCP_NONE_SET,
134}; 131};
135 132
136/* 133/*
137 * The TCP state transition table needs a few words... 134 * The TCP state transition table needs a few words...
138 * 135 *
139 * We are the man in the middle. All the packets go through us 136 * We are the man in the middle. All the packets go through us
140 * but might get lost in transit to the destination. 137 * but might get lost in transit to the destination.
141 * It is assumed that the destinations can't receive segments 138 * It is assumed that the destinations can't receive segments
142 * we haven't seen. 139 * we haven't seen.
143 * 140 *
144 * The checked segment is in window, but our windows are *not* 141 * The checked segment is in window, but our windows are *not*
@@ -148,11 +145,11 @@ enum tcp_bit_set {
148 * The meaning of the states are: 145 * The meaning of the states are:
149 * 146 *
150 * NONE: initial state 147 * NONE: initial state
151 * SYN_SENT: SYN-only packet seen 148 * SYN_SENT: SYN-only packet seen
152 * SYN_RECV: SYN-ACK packet seen 149 * SYN_RECV: SYN-ACK packet seen
153 * ESTABLISHED: ACK packet seen 150 * ESTABLISHED: ACK packet seen
154 * FIN_WAIT: FIN packet seen 151 * FIN_WAIT: FIN packet seen
155 * CLOSE_WAIT: ACK seen (after FIN) 152 * CLOSE_WAIT: ACK seen (after FIN)
156 * LAST_ACK: FIN seen (after FIN) 153 * LAST_ACK: FIN seen (after FIN)
157 * TIME_WAIT: last ACK seen 154 * TIME_WAIT: last ACK seen
158 * CLOSE: closed connection 155 * CLOSE: closed connection
@@ -160,8 +157,8 @@ enum tcp_bit_set {
160 * LISTEN state is not used. 157 * LISTEN state is not used.
161 * 158 *
162 * Packets marked as IGNORED (sIG): 159 * Packets marked as IGNORED (sIG):
163 * if they may be either invalid or valid 160 * if they may be either invalid or valid
164 * and the receiver may send back a connection 161 * and the receiver may send back a connection
165 * closing RST or a SYN/ACK. 162 * closing RST or a SYN/ACK.
166 * 163 *
167 * Packets marked as INVALID (sIV): 164 * Packets marked as INVALID (sIV):
@@ -178,7 +175,7 @@ static const enum tcp_conntrack tcp_conntracks[2][6][TCP_CONNTRACK_MAX] = {
178 * sSS -> sSS Retransmitted SYN 175 * sSS -> sSS Retransmitted SYN
179 * sSR -> sIG Late retransmitted SYN? 176 * sSR -> sIG Late retransmitted SYN?
180 * sES -> sIG Error: SYNs in window outside the SYN_SENT state 177 * sES -> sIG Error: SYNs in window outside the SYN_SENT state
181 * are errors. Receiver will reply with RST 178 * are errors. Receiver will reply with RST
182 * and close the connection. 179 * and close the connection.
183 * Or we are not in sync and hold a dead connection. 180 * Or we are not in sync and hold a dead connection.
184 * sFW -> sIG 181 * sFW -> sIG
@@ -191,10 +188,10 @@ static const enum tcp_conntrack tcp_conntracks[2][6][TCP_CONNTRACK_MAX] = {
191/*synack*/ { sIV, sIV, sIV, sIV, sIV, sIV, sIV, sIV, sIV, sIV }, 188/*synack*/ { sIV, sIV, sIV, sIV, sIV, sIV, sIV, sIV, sIV, sIV },
192/* 189/*
193 * A SYN/ACK from the client is always invalid: 190 * A SYN/ACK from the client is always invalid:
194 * - either it tries to set up a simultaneous open, which is 191 * - either it tries to set up a simultaneous open, which is
195 * not supported; 192 * not supported;
196 * - or the firewall has just been inserted between the two hosts 193 * - or the firewall has just been inserted between the two hosts
197 * during the session set-up. The SYN will be retransmitted 194 * during the session set-up. The SYN will be retransmitted
198 * by the true client (or it'll time out). 195 * by the true client (or it'll time out).
199 */ 196 */
200/* sNO, sSS, sSR, sES, sFW, sCW, sLA, sTW, sCL, sLI */ 197/* sNO, sSS, sSR, sES, sFW, sCW, sLA, sTW, sCL, sLI */
@@ -204,9 +201,9 @@ static const enum tcp_conntrack tcp_conntracks[2][6][TCP_CONNTRACK_MAX] = {
204 * sSS -> sIV Client migth not send FIN in this state: 201 * sSS -> sIV Client migth not send FIN in this state:
205 * we enforce waiting for a SYN/ACK reply first. 202 * we enforce waiting for a SYN/ACK reply first.
206 * sSR -> sFW Close started. 203 * sSR -> sFW Close started.
207 * sES -> sFW 204 * sES -> sFW
208 * sFW -> sLA FIN seen in both directions, waiting for 205 * sFW -> sLA FIN seen in both directions, waiting for
209 * the last ACK. 206 * the last ACK.
210 * Migth be a retransmitted FIN as well... 207 * Migth be a retransmitted FIN as well...
211 * sCW -> sLA 208 * sCW -> sLA
212 * sLA -> sLA Retransmitted FIN. Remain in the same state. 209 * sLA -> sLA Retransmitted FIN. Remain in the same state.
@@ -284,7 +281,7 @@ static const enum tcp_conntrack tcp_conntracks[2][6][TCP_CONNTRACK_MAX] = {
284/* sNO, sSS, sSR, sES, sFW, sCW, sLA, sTW, sCL, sLI */ 281/* sNO, sSS, sSR, sES, sFW, sCW, sLA, sTW, sCL, sLI */
285/*rst*/ { sIV, sCL, sCL, sCL, sCL, sCL, sCL, sCL, sCL, sIV }, 282/*rst*/ { sIV, sCL, sCL, sCL, sCL, sCL, sCL, sCL, sCL, sIV },
286/*none*/ { sIV, sIV, sIV, sIV, sIV, sIV, sIV, sIV, sIV, sIV } 283/*none*/ { sIV, sIV, sIV, sIV, sIV, sIV, sIV, sIV, sIV, sIV }
287 } 284 }
288}; 285};
289 286
290static int tcp_pkt_to_tuple(const struct sk_buff *skb, 287static int tcp_pkt_to_tuple(const struct sk_buff *skb,
@@ -340,7 +337,7 @@ static int tcp_to_nfattr(struct sk_buff *skb, struct nfattr *nfa,
340 const struct ip_conntrack *ct) 337 const struct ip_conntrack *ct)
341{ 338{
342 struct nfattr *nest_parms; 339 struct nfattr *nest_parms;
343 340
344 read_lock_bh(&tcp_lock); 341 read_lock_bh(&tcp_lock);
345 nest_parms = NFA_NEST(skb, CTA_PROTOINFO_TCP); 342 nest_parms = NFA_NEST(skb, CTA_PROTOINFO_TCP);
346 NFA_PUT(skb, CTA_PROTOINFO_TCP_STATE, sizeof(u_int8_t), 343 NFA_PUT(skb, CTA_PROTOINFO_TCP_STATE, sizeof(u_int8_t),
@@ -370,7 +367,7 @@ static int nfattr_to_tcp(struct nfattr *cda[], struct ip_conntrack *ct)
370 if (!attr) 367 if (!attr)
371 return 0; 368 return 0;
372 369
373 nfattr_parse_nested(tb, CTA_PROTOINFO_TCP_MAX, attr); 370 nfattr_parse_nested(tb, CTA_PROTOINFO_TCP_MAX, attr);
374 371
375 if (nfattr_bad_size(tb, CTA_PROTOINFO_TCP_MAX, cta_min_tcp)) 372 if (nfattr_bad_size(tb, CTA_PROTOINFO_TCP_MAX, cta_min_tcp))
376 return -EINVAL; 373 return -EINVAL;
@@ -379,7 +376,7 @@ static int nfattr_to_tcp(struct nfattr *cda[], struct ip_conntrack *ct)
379 return -EINVAL; 376 return -EINVAL;
380 377
381 write_lock_bh(&tcp_lock); 378 write_lock_bh(&tcp_lock);
382 ct->proto.tcp.state = 379 ct->proto.tcp.state =
383 *(u_int8_t *)NFA_DATA(tb[CTA_PROTOINFO_TCP_STATE-1]); 380 *(u_int8_t *)NFA_DATA(tb[CTA_PROTOINFO_TCP_STATE-1]);
384 write_unlock_bh(&tcp_lock); 381 write_unlock_bh(&tcp_lock);
385 382
@@ -398,30 +395,30 @@ static unsigned int get_conntrack_index(const struct tcphdr *tcph)
398 395
399/* TCP connection tracking based on 'Real Stateful TCP Packet Filtering 396/* TCP connection tracking based on 'Real Stateful TCP Packet Filtering
400 in IP Filter' by Guido van Rooij. 397 in IP Filter' by Guido van Rooij.
401 398
402 http://www.nluug.nl/events/sane2000/papers.html 399 http://www.nluug.nl/events/sane2000/papers.html
403 http://www.iae.nl/users/guido/papers/tcp_filtering.ps.gz 400 http://www.iae.nl/users/guido/papers/tcp_filtering.ps.gz
404 401
405 The boundaries and the conditions are changed according to RFC793: 402 The boundaries and the conditions are changed according to RFC793:
406 the packet must intersect the window (i.e. segments may be 403 the packet must intersect the window (i.e. segments may be
407 after the right or before the left edge) and thus receivers may ACK 404 after the right or before the left edge) and thus receivers may ACK
408 segments after the right edge of the window. 405 segments after the right edge of the window.
409 406
410 td_maxend = max(sack + max(win,1)) seen in reply packets 407 td_maxend = max(sack + max(win,1)) seen in reply packets
411 td_maxwin = max(max(win, 1)) + (sack - ack) seen in sent packets 408 td_maxwin = max(max(win, 1)) + (sack - ack) seen in sent packets
412 td_maxwin += seq + len - sender.td_maxend 409 td_maxwin += seq + len - sender.td_maxend
413 if seq + len > sender.td_maxend 410 if seq + len > sender.td_maxend
414 td_end = max(seq + len) seen in sent packets 411 td_end = max(seq + len) seen in sent packets
415 412
416 I. Upper bound for valid data: seq <= sender.td_maxend 413 I. Upper bound for valid data: seq <= sender.td_maxend
417 II. Lower bound for valid data: seq + len >= sender.td_end - receiver.td_maxwin 414 II. Lower bound for valid data: seq + len >= sender.td_end - receiver.td_maxwin
418 III. Upper bound for valid ack: sack <= receiver.td_end 415 III. Upper bound for valid ack: sack <= receiver.td_end
419 IV. Lower bound for valid ack: ack >= receiver.td_end - MAXACKWINDOW 416 IV. Lower bound for valid ack: ack >= receiver.td_end - MAXACKWINDOW
420 417
421 where sack is the highest right edge of sack block found in the packet. 418 where sack is the highest right edge of sack block found in the packet.
422 419
423 The upper bound limit for a valid ack is not ignored - 420 The upper bound limit for a valid ack is not ignored -
424 we doesn't have to deal with fragments. 421 we doesn't have to deal with fragments.
425*/ 422*/
426 423
427static inline __u32 segment_seq_plus_len(__u32 seq, 424static inline __u32 segment_seq_plus_len(__u32 seq,
@@ -432,25 +429,25 @@ static inline __u32 segment_seq_plus_len(__u32 seq,
432 return (seq + len - (iph->ihl + tcph->doff)*4 429 return (seq + len - (iph->ihl + tcph->doff)*4
433 + (tcph->syn ? 1 : 0) + (tcph->fin ? 1 : 0)); 430 + (tcph->syn ? 1 : 0) + (tcph->fin ? 1 : 0));
434} 431}
435 432
436/* Fixme: what about big packets? */ 433/* Fixme: what about big packets? */
437#define MAXACKWINCONST 66000 434#define MAXACKWINCONST 66000
438#define MAXACKWINDOW(sender) \ 435#define MAXACKWINDOW(sender) \
439 ((sender)->td_maxwin > MAXACKWINCONST ? (sender)->td_maxwin \ 436 ((sender)->td_maxwin > MAXACKWINCONST ? (sender)->td_maxwin \
440 : MAXACKWINCONST) 437 : MAXACKWINCONST)
441 438
442/* 439/*
443 * Simplified tcp_parse_options routine from tcp_input.c 440 * Simplified tcp_parse_options routine from tcp_input.c
444 */ 441 */
445static void tcp_options(const struct sk_buff *skb, 442static void tcp_options(const struct sk_buff *skb,
446 struct iphdr *iph, 443 struct iphdr *iph,
447 struct tcphdr *tcph, 444 struct tcphdr *tcph,
448 struct ip_ct_tcp_state *state) 445 struct ip_ct_tcp_state *state)
449{ 446{
450 unsigned char buff[(15 * 4) - sizeof(struct tcphdr)]; 447 unsigned char buff[(15 * 4) - sizeof(struct tcphdr)];
451 unsigned char *ptr; 448 unsigned char *ptr;
452 int length = (tcph->doff*4) - sizeof(struct tcphdr); 449 int length = (tcph->doff*4) - sizeof(struct tcphdr);
453 450
454 if (!length) 451 if (!length)
455 return; 452 return;
456 453
@@ -459,13 +456,13 @@ static void tcp_options(const struct sk_buff *skb,
459 length, buff); 456 length, buff);
460 BUG_ON(ptr == NULL); 457 BUG_ON(ptr == NULL);
461 458
462 state->td_scale = 459 state->td_scale =
463 state->flags = 0; 460 state->flags = 0;
464 461
465 while (length > 0) { 462 while (length > 0) {
466 int opcode=*ptr++; 463 int opcode=*ptr++;
467 int opsize; 464 int opsize;
468 465
469 switch (opcode) { 466 switch (opcode) {
470 case TCPOPT_EOL: 467 case TCPOPT_EOL:
471 return; 468 return;
@@ -479,13 +476,13 @@ static void tcp_options(const struct sk_buff *skb,
479 if (opsize > length) 476 if (opsize > length)
480 break; /* don't parse partial options */ 477 break; /* don't parse partial options */
481 478
482 if (opcode == TCPOPT_SACK_PERM 479 if (opcode == TCPOPT_SACK_PERM
483 && opsize == TCPOLEN_SACK_PERM) 480 && opsize == TCPOLEN_SACK_PERM)
484 state->flags |= IP_CT_TCP_FLAG_SACK_PERM; 481 state->flags |= IP_CT_TCP_FLAG_SACK_PERM;
485 else if (opcode == TCPOPT_WINDOW 482 else if (opcode == TCPOPT_WINDOW
486 && opsize == TCPOLEN_WINDOW) { 483 && opsize == TCPOLEN_WINDOW) {
487 state->td_scale = *(u_int8_t *)ptr; 484 state->td_scale = *(u_int8_t *)ptr;
488 485
489 if (state->td_scale > 14) { 486 if (state->td_scale > 14) {
490 /* See RFC1323 */ 487 /* See RFC1323 */
491 state->td_scale = 14; 488 state->td_scale = 14;
@@ -520,16 +517,16 @@ static void tcp_sack(const struct sk_buff *skb,
520 /* Fast path for timestamp-only option */ 517 /* Fast path for timestamp-only option */
521 if (length == TCPOLEN_TSTAMP_ALIGNED*4 518 if (length == TCPOLEN_TSTAMP_ALIGNED*4
522 && *(__be32 *)ptr == 519 && *(__be32 *)ptr ==
523 __constant_htonl((TCPOPT_NOP << 24) 520 __constant_htonl((TCPOPT_NOP << 24)
524 | (TCPOPT_NOP << 16) 521 | (TCPOPT_NOP << 16)
525 | (TCPOPT_TIMESTAMP << 8) 522 | (TCPOPT_TIMESTAMP << 8)
526 | TCPOLEN_TIMESTAMP)) 523 | TCPOLEN_TIMESTAMP))
527 return; 524 return;
528 525
529 while (length > 0) { 526 while (length > 0) {
530 int opcode=*ptr++; 527 int opcode=*ptr++;
531 int opsize, i; 528 int opsize, i;
532 529
533 switch (opcode) { 530 switch (opcode) {
534 case TCPOPT_EOL: 531 case TCPOPT_EOL:
535 return; 532 return;
@@ -543,16 +540,16 @@ static void tcp_sack(const struct sk_buff *skb,
543 if (opsize > length) 540 if (opsize > length)
544 break; /* don't parse partial options */ 541 break; /* don't parse partial options */
545 542
546 if (opcode == TCPOPT_SACK 543 if (opcode == TCPOPT_SACK
547 && opsize >= (TCPOLEN_SACK_BASE 544 && opsize >= (TCPOLEN_SACK_BASE
548 + TCPOLEN_SACK_PERBLOCK) 545 + TCPOLEN_SACK_PERBLOCK)
549 && !((opsize - TCPOLEN_SACK_BASE) 546 && !((opsize - TCPOLEN_SACK_BASE)
550 % TCPOLEN_SACK_PERBLOCK)) { 547 % TCPOLEN_SACK_PERBLOCK)) {
551 for (i = 0; 548 for (i = 0;
552 i < (opsize - TCPOLEN_SACK_BASE); 549 i < (opsize - TCPOLEN_SACK_BASE);
553 i += TCPOLEN_SACK_PERBLOCK) { 550 i += TCPOLEN_SACK_PERBLOCK) {
554 tmp = ntohl(*((__be32 *)(ptr+i)+1)); 551 tmp = ntohl(*((__be32 *)(ptr+i)+1));
555 552
556 if (after(tmp, *sack)) 553 if (after(tmp, *sack))
557 *sack = tmp; 554 *sack = tmp;
558 } 555 }
@@ -564,18 +561,18 @@ static void tcp_sack(const struct sk_buff *skb,
564 } 561 }
565} 562}
566 563
567static int tcp_in_window(struct ip_ct_tcp *state, 564static int tcp_in_window(struct ip_ct_tcp *state,
568 enum ip_conntrack_dir dir, 565 enum ip_conntrack_dir dir,
569 unsigned int index, 566 unsigned int index,
570 const struct sk_buff *skb, 567 const struct sk_buff *skb,
571 struct iphdr *iph, 568 struct iphdr *iph,
572 struct tcphdr *tcph) 569 struct tcphdr *tcph)
573{ 570{
574 struct ip_ct_tcp_state *sender = &state->seen[dir]; 571 struct ip_ct_tcp_state *sender = &state->seen[dir];
575 struct ip_ct_tcp_state *receiver = &state->seen[!dir]; 572 struct ip_ct_tcp_state *receiver = &state->seen[!dir];
576 __u32 seq, ack, sack, end, win, swin; 573 __u32 seq, ack, sack, end, win, swin;
577 int res; 574 int res;
578 575
579 /* 576 /*
580 * Get the required data from the packet. 577 * Get the required data from the packet.
581 */ 578 */
@@ -583,23 +580,23 @@ static int tcp_in_window(struct ip_ct_tcp *state,
583 ack = sack = ntohl(tcph->ack_seq); 580 ack = sack = ntohl(tcph->ack_seq);
584 win = ntohs(tcph->window); 581 win = ntohs(tcph->window);
585 end = segment_seq_plus_len(seq, skb->len, iph, tcph); 582 end = segment_seq_plus_len(seq, skb->len, iph, tcph);
586 583
587 if (receiver->flags & IP_CT_TCP_FLAG_SACK_PERM) 584 if (receiver->flags & IP_CT_TCP_FLAG_SACK_PERM)
588 tcp_sack(skb, iph, tcph, &sack); 585 tcp_sack(skb, iph, tcph, &sack);
589 586
590 DEBUGP("tcp_in_window: START\n"); 587 DEBUGP("tcp_in_window: START\n");
591 DEBUGP("tcp_in_window: src=%u.%u.%u.%u:%hu dst=%u.%u.%u.%u:%hu " 588 DEBUGP("tcp_in_window: src=%u.%u.%u.%u:%hu dst=%u.%u.%u.%u:%hu "
592 "seq=%u ack=%u sack=%u win=%u end=%u\n", 589 "seq=%u ack=%u sack=%u win=%u end=%u\n",
593 NIPQUAD(iph->saddr), ntohs(tcph->source), 590 NIPQUAD(iph->saddr), ntohs(tcph->source),
594 NIPQUAD(iph->daddr), ntohs(tcph->dest), 591 NIPQUAD(iph->daddr), ntohs(tcph->dest),
595 seq, ack, sack, win, end); 592 seq, ack, sack, win, end);
596 DEBUGP("tcp_in_window: sender end=%u maxend=%u maxwin=%u scale=%i " 593 DEBUGP("tcp_in_window: sender end=%u maxend=%u maxwin=%u scale=%i "
597 "receiver end=%u maxend=%u maxwin=%u scale=%i\n", 594 "receiver end=%u maxend=%u maxwin=%u scale=%i\n",
598 sender->td_end, sender->td_maxend, sender->td_maxwin, 595 sender->td_end, sender->td_maxend, sender->td_maxwin,
599 sender->td_scale, 596 sender->td_scale,
600 receiver->td_end, receiver->td_maxend, receiver->td_maxwin, 597 receiver->td_end, receiver->td_maxend, receiver->td_maxwin,
601 receiver->td_scale); 598 receiver->td_scale);
602 599
603 if (sender->td_end == 0) { 600 if (sender->td_end == 0) {
604 /* 601 /*
605 * Initialize sender data. 602 * Initialize sender data.
@@ -608,26 +605,26 @@ static int tcp_in_window(struct ip_ct_tcp *state,
608 /* 605 /*
609 * Outgoing SYN-ACK in reply to a SYN. 606 * Outgoing SYN-ACK in reply to a SYN.
610 */ 607 */
611 sender->td_end = 608 sender->td_end =
612 sender->td_maxend = end; 609 sender->td_maxend = end;
613 sender->td_maxwin = (win == 0 ? 1 : win); 610 sender->td_maxwin = (win == 0 ? 1 : win);
614 611
615 tcp_options(skb, iph, tcph, sender); 612 tcp_options(skb, iph, tcph, sender);
616 /* 613 /*
617 * RFC 1323: 614 * RFC 1323:
618 * Both sides must send the Window Scale option 615 * Both sides must send the Window Scale option
619 * to enable window scaling in either direction. 616 * to enable window scaling in either direction.
620 */ 617 */
621 if (!(sender->flags & IP_CT_TCP_FLAG_WINDOW_SCALE 618 if (!(sender->flags & IP_CT_TCP_FLAG_WINDOW_SCALE
622 && receiver->flags & IP_CT_TCP_FLAG_WINDOW_SCALE)) 619 && receiver->flags & IP_CT_TCP_FLAG_WINDOW_SCALE))
623 sender->td_scale = 620 sender->td_scale =
624 receiver->td_scale = 0; 621 receiver->td_scale = 0;
625 } else { 622 } else {
626 /* 623 /*
627 * We are in the middle of a connection, 624 * We are in the middle of a connection,
628 * its history is lost for us. 625 * its history is lost for us.
629 * Let's try to use the data from the packet. 626 * Let's try to use the data from the packet.
630 */ 627 */
631 sender->td_end = end; 628 sender->td_end = end;
632 sender->td_maxwin = (win == 0 ? 1 : win); 629 sender->td_maxwin = (win == 0 ? 1 : win);
633 sender->td_maxend = end + sender->td_maxwin; 630 sender->td_maxend = end + sender->td_maxwin;
@@ -635,11 +632,11 @@ static int tcp_in_window(struct ip_ct_tcp *state,
635 } else if (((state->state == TCP_CONNTRACK_SYN_SENT 632 } else if (((state->state == TCP_CONNTRACK_SYN_SENT
636 && dir == IP_CT_DIR_ORIGINAL) 633 && dir == IP_CT_DIR_ORIGINAL)
637 || (state->state == TCP_CONNTRACK_SYN_RECV 634 || (state->state == TCP_CONNTRACK_SYN_RECV
638 && dir == IP_CT_DIR_REPLY)) 635 && dir == IP_CT_DIR_REPLY))
639 && after(end, sender->td_end)) { 636 && after(end, sender->td_end)) {
640 /* 637 /*
641 * RFC 793: "if a TCP is reinitialized ... then it need 638 * RFC 793: "if a TCP is reinitialized ... then it need
642 * not wait at all; it must only be sure to use sequence 639 * not wait at all; it must only be sure to use sequence
643 * numbers larger than those recently used." 640 * numbers larger than those recently used."
644 */ 641 */
645 sender->td_end = 642 sender->td_end =
@@ -648,14 +645,14 @@ static int tcp_in_window(struct ip_ct_tcp *state,
648 645
649 tcp_options(skb, iph, tcph, sender); 646 tcp_options(skb, iph, tcph, sender);
650 } 647 }
651 648
652 if (!(tcph->ack)) { 649 if (!(tcph->ack)) {
653 /* 650 /*
654 * If there is no ACK, just pretend it was set and OK. 651 * If there is no ACK, just pretend it was set and OK.
655 */ 652 */
656 ack = sack = receiver->td_end; 653 ack = sack = receiver->td_end;
657 } else if (((tcp_flag_word(tcph) & (TCP_FLAG_ACK|TCP_FLAG_RST)) == 654 } else if (((tcp_flag_word(tcph) & (TCP_FLAG_ACK|TCP_FLAG_RST)) ==
658 (TCP_FLAG_ACK|TCP_FLAG_RST)) 655 (TCP_FLAG_ACK|TCP_FLAG_RST))
659 && (ack == 0)) { 656 && (ack == 0)) {
660 /* 657 /*
661 * Broken TCP stacks, that set ACK in RST packets as well 658 * Broken TCP stacks, that set ACK in RST packets as well
@@ -665,8 +662,8 @@ static int tcp_in_window(struct ip_ct_tcp *state,
665 } 662 }
666 663
667 if (seq == end 664 if (seq == end
668 && (!tcph->rst 665 && (!tcph->rst
669 || (seq == 0 && state->state == TCP_CONNTRACK_SYN_SENT))) 666 || (seq == 0 && state->state == TCP_CONNTRACK_SYN_SENT)))
670 /* 667 /*
671 * Packets contains no data: we assume it is valid 668 * Packets contains no data: we assume it is valid
672 * and check the ack value only. 669 * and check the ack value only.
@@ -675,7 +672,7 @@ static int tcp_in_window(struct ip_ct_tcp *state,
675 * SYN. 672 * SYN.
676 */ 673 */
677 seq = end = sender->td_end; 674 seq = end = sender->td_end;
678 675
679 DEBUGP("tcp_in_window: src=%u.%u.%u.%u:%hu dst=%u.%u.%u.%u:%hu " 676 DEBUGP("tcp_in_window: src=%u.%u.%u.%u:%hu dst=%u.%u.%u.%u:%hu "
680 "seq=%u ack=%u sack =%u win=%u end=%u\n", 677 "seq=%u ack=%u sack =%u win=%u end=%u\n",
681 NIPQUAD(iph->saddr), ntohs(tcph->source), 678 NIPQUAD(iph->saddr), ntohs(tcph->source),
@@ -684,27 +681,26 @@ static int tcp_in_window(struct ip_ct_tcp *state,
684 DEBUGP("tcp_in_window: sender end=%u maxend=%u maxwin=%u scale=%i " 681 DEBUGP("tcp_in_window: sender end=%u maxend=%u maxwin=%u scale=%i "
685 "receiver end=%u maxend=%u maxwin=%u scale=%i\n", 682 "receiver end=%u maxend=%u maxwin=%u scale=%i\n",
686 sender->td_end, sender->td_maxend, sender->td_maxwin, 683 sender->td_end, sender->td_maxend, sender->td_maxwin,
687 sender->td_scale, 684 sender->td_scale,
688 receiver->td_end, receiver->td_maxend, receiver->td_maxwin, 685 receiver->td_end, receiver->td_maxend, receiver->td_maxwin,
689 receiver->td_scale); 686 receiver->td_scale);
690 687
691 DEBUGP("tcp_in_window: I=%i II=%i III=%i IV=%i\n", 688 DEBUGP("tcp_in_window: I=%i II=%i III=%i IV=%i\n",
692 before(seq, sender->td_maxend + 1), 689 before(seq, sender->td_maxend + 1),
693 after(end, sender->td_end - receiver->td_maxwin - 1), 690 after(end, sender->td_end - receiver->td_maxwin - 1),
694 before(sack, receiver->td_end + 1), 691 before(sack, receiver->td_end + 1),
695 after(ack, receiver->td_end - MAXACKWINDOW(sender))); 692 after(ack, receiver->td_end - MAXACKWINDOW(sender)));
696 693
697 if (sender->loose || receiver->loose || 694 if (before(seq, sender->td_maxend + 1) &&
698 (before(seq, sender->td_maxend + 1) && 695 after(end, sender->td_end - receiver->td_maxwin - 1) &&
699 after(end, sender->td_end - receiver->td_maxwin - 1) && 696 before(sack, receiver->td_end + 1) &&
700 before(sack, receiver->td_end + 1) && 697 after(ack, receiver->td_end - MAXACKWINDOW(sender))) {
701 after(ack, receiver->td_end - MAXACKWINDOW(sender)))) { 698 /*
702 /*
703 * Take into account window scaling (RFC 1323). 699 * Take into account window scaling (RFC 1323).
704 */ 700 */
705 if (!tcph->syn) 701 if (!tcph->syn)
706 win <<= sender->td_scale; 702 win <<= sender->td_scale;
707 703
708 /* 704 /*
709 * Update sender data. 705 * Update sender data.
710 */ 706 */
@@ -724,7 +720,7 @@ static int tcp_in_window(struct ip_ct_tcp *state,
724 receiver->td_maxend++; 720 receiver->td_maxend++;
725 } 721 }
726 722
727 /* 723 /*
728 * Check retransmissions. 724 * Check retransmissions.
729 */ 725 */
730 if (index == TCP_ACK_SET) { 726 if (index == TCP_ACK_SET) {
@@ -743,15 +739,13 @@ static int tcp_in_window(struct ip_ct_tcp *state,
743 state->retrans = 0; 739 state->retrans = 0;
744 } 740 }
745 } 741 }
746 /*
747 * Close the window of disabled window tracking :-)
748 */
749 if (sender->loose)
750 sender->loose--;
751
752 res = 1; 742 res = 1;
753 } else { 743 } else {
754 if (LOG_INVALID(IPPROTO_TCP)) 744 res = 0;
745 if (sender->flags & IP_CT_TCP_FLAG_BE_LIBERAL ||
746 ip_ct_tcp_be_liberal)
747 res = 1;
748 if (!res && LOG_INVALID(IPPROTO_TCP))
755 nf_log_packet(PF_INET, 0, skb, NULL, NULL, NULL, 749 nf_log_packet(PF_INET, 0, skb, NULL, NULL, NULL,
756 "ip_ct_tcp: %s ", 750 "ip_ct_tcp: %s ",
757 before(seq, sender->td_maxend + 1) ? 751 before(seq, sender->td_maxend + 1) ?
@@ -762,13 +756,11 @@ static int tcp_in_window(struct ip_ct_tcp *state,
762 : "ACK is over the upper bound (ACKed data not seen yet)" 756 : "ACK is over the upper bound (ACKed data not seen yet)"
763 : "SEQ is under the lower bound (already ACKed data retransmitted)" 757 : "SEQ is under the lower bound (already ACKed data retransmitted)"
764 : "SEQ is over the upper bound (over the window of the receiver)"); 758 : "SEQ is over the upper bound (over the window of the receiver)");
759 }
765 760
766 res = ip_ct_tcp_be_liberal;
767 }
768
769 DEBUGP("tcp_in_window: res=%i sender end=%u maxend=%u maxwin=%u " 761 DEBUGP("tcp_in_window: res=%i sender end=%u maxend=%u maxwin=%u "
770 "receiver end=%u maxend=%u maxwin=%u\n", 762 "receiver end=%u maxend=%u maxwin=%u\n",
771 res, sender->td_end, sender->td_maxend, sender->td_maxwin, 763 res, sender->td_end, sender->td_maxend, sender->td_maxwin,
772 receiver->td_end, receiver->td_maxend, receiver->td_maxwin); 764 receiver->td_end, receiver->td_maxend, receiver->td_maxwin);
773 765
774 return res; 766 return res;
@@ -777,7 +769,7 @@ static int tcp_in_window(struct ip_ct_tcp *state,
777#ifdef CONFIG_IP_NF_NAT_NEEDED 769#ifdef CONFIG_IP_NF_NAT_NEEDED
778/* Update sender->td_end after NAT successfully mangled the packet */ 770/* Update sender->td_end after NAT successfully mangled the packet */
779void ip_conntrack_tcp_update(struct sk_buff *skb, 771void ip_conntrack_tcp_update(struct sk_buff *skb,
780 struct ip_conntrack *conntrack, 772 struct ip_conntrack *conntrack,
781 enum ip_conntrack_dir dir) 773 enum ip_conntrack_dir dir)
782{ 774{
783 struct iphdr *iph = skb->nh.iph; 775 struct iphdr *iph = skb->nh.iph;
@@ -789,7 +781,7 @@ void ip_conntrack_tcp_update(struct sk_buff *skb,
789#endif 781#endif
790 782
791 end = segment_seq_plus_len(ntohl(tcph->seq), skb->len, iph, tcph); 783 end = segment_seq_plus_len(ntohl(tcph->seq), skb->len, iph, tcph);
792 784
793 write_lock_bh(&tcp_lock); 785 write_lock_bh(&tcp_lock);
794 /* 786 /*
795 * We have to worry for the ack in the reply packet only... 787 * We have to worry for the ack in the reply packet only...
@@ -801,11 +793,11 @@ void ip_conntrack_tcp_update(struct sk_buff *skb,
801 DEBUGP("tcp_update: sender end=%u maxend=%u maxwin=%u scale=%i " 793 DEBUGP("tcp_update: sender end=%u maxend=%u maxwin=%u scale=%i "
802 "receiver end=%u maxend=%u maxwin=%u scale=%i\n", 794 "receiver end=%u maxend=%u maxwin=%u scale=%i\n",
803 sender->td_end, sender->td_maxend, sender->td_maxwin, 795 sender->td_end, sender->td_maxend, sender->td_maxwin,
804 sender->td_scale, 796 sender->td_scale,
805 receiver->td_end, receiver->td_maxend, receiver->td_maxwin, 797 receiver->td_end, receiver->td_maxend, receiver->td_maxwin,
806 receiver->td_scale); 798 receiver->td_scale);
807} 799}
808 800
809#endif 801#endif
810 802
811#define TH_FIN 0x01 803#define TH_FIN 0x01
@@ -855,8 +847,8 @@ static int tcp_error(struct sk_buff *skb,
855 nf_log_packet(PF_INET, 0, skb, NULL, NULL, NULL, 847 nf_log_packet(PF_INET, 0, skb, NULL, NULL, NULL,
856 "ip_ct_tcp: short packet "); 848 "ip_ct_tcp: short packet ");
857 return -NF_ACCEPT; 849 return -NF_ACCEPT;
858 } 850 }
859 851
860 /* Not whole TCP header or malformed packet */ 852 /* Not whole TCP header or malformed packet */
861 if (th->doff*4 < sizeof(struct tcphdr) || tcplen < th->doff*4) { 853 if (th->doff*4 < sizeof(struct tcphdr) || tcplen < th->doff*4) {
862 if (LOG_INVALID(IPPROTO_TCP)) 854 if (LOG_INVALID(IPPROTO_TCP))
@@ -864,7 +856,7 @@ static int tcp_error(struct sk_buff *skb,
864 "ip_ct_tcp: truncated/malformed packet "); 856 "ip_ct_tcp: truncated/malformed packet ");
865 return -NF_ACCEPT; 857 return -NF_ACCEPT;
866 } 858 }
867 859
868 /* Checksum invalid? Ignore. 860 /* Checksum invalid? Ignore.
869 * We skip checking packets on the outgoing path 861 * We skip checking packets on the outgoing path
870 * because it is assumed to be correct. 862 * because it is assumed to be correct.
@@ -901,11 +893,11 @@ static int tcp_packet(struct ip_conntrack *conntrack,
901 struct tcphdr *th, _tcph; 893 struct tcphdr *th, _tcph;
902 unsigned long timeout; 894 unsigned long timeout;
903 unsigned int index; 895 unsigned int index;
904 896
905 th = skb_header_pointer(skb, iph->ihl * 4, 897 th = skb_header_pointer(skb, iph->ihl * 4,
906 sizeof(_tcph), &_tcph); 898 sizeof(_tcph), &_tcph);
907 BUG_ON(th == NULL); 899 BUG_ON(th == NULL);
908 900
909 write_lock_bh(&tcp_lock); 901 write_lock_bh(&tcp_lock);
910 old_state = conntrack->proto.tcp.state; 902 old_state = conntrack->proto.tcp.state;
911 dir = CTINFO2DIR(ctinfo); 903 dir = CTINFO2DIR(ctinfo);
@@ -915,7 +907,7 @@ static int tcp_packet(struct ip_conntrack *conntrack,
915 switch (new_state) { 907 switch (new_state) {
916 case TCP_CONNTRACK_IGNORE: 908 case TCP_CONNTRACK_IGNORE:
917 /* Ignored packets: 909 /* Ignored packets:
918 * 910 *
919 * a) SYN in ORIGINAL 911 * a) SYN in ORIGINAL
920 * b) SYN/ACK in REPLY 912 * b) SYN/ACK in REPLY
921 * c) ACK in reply direction after initial SYN in original. 913 * c) ACK in reply direction after initial SYN in original.
@@ -924,30 +916,30 @@ static int tcp_packet(struct ip_conntrack *conntrack,
924 && conntrack->proto.tcp.last_index == TCP_SYN_SET 916 && conntrack->proto.tcp.last_index == TCP_SYN_SET
925 && conntrack->proto.tcp.last_dir != dir 917 && conntrack->proto.tcp.last_dir != dir
926 && ntohl(th->ack_seq) == 918 && ntohl(th->ack_seq) ==
927 conntrack->proto.tcp.last_end) { 919 conntrack->proto.tcp.last_end) {
928 /* This SYN/ACK acknowledges a SYN that we earlier 920 /* This SYN/ACK acknowledges a SYN that we earlier
929 * ignored as invalid. This means that the client and 921 * ignored as invalid. This means that the client and
930 * the server are both in sync, while the firewall is 922 * the server are both in sync, while the firewall is
931 * not. We kill this session and block the SYN/ACK so 923 * not. We kill this session and block the SYN/ACK so
932 * that the client cannot but retransmit its SYN and 924 * that the client cannot but retransmit its SYN and
933 * thus initiate a clean new session. 925 * thus initiate a clean new session.
934 */ 926 */
935 write_unlock_bh(&tcp_lock); 927 write_unlock_bh(&tcp_lock);
936 if (LOG_INVALID(IPPROTO_TCP)) 928 if (LOG_INVALID(IPPROTO_TCP))
937 nf_log_packet(PF_INET, 0, skb, NULL, NULL, 929 nf_log_packet(PF_INET, 0, skb, NULL, NULL,
938 NULL, "ip_ct_tcp: " 930 NULL, "ip_ct_tcp: "
939 "killing out of sync session "); 931 "killing out of sync session ");
940 if (del_timer(&conntrack->timeout)) 932 if (del_timer(&conntrack->timeout))
941 conntrack->timeout.function((unsigned long) 933 conntrack->timeout.function((unsigned long)
942 conntrack); 934 conntrack);
943 return -NF_DROP; 935 return -NF_DROP;
944 } 936 }
945 conntrack->proto.tcp.last_index = index; 937 conntrack->proto.tcp.last_index = index;
946 conntrack->proto.tcp.last_dir = dir; 938 conntrack->proto.tcp.last_dir = dir;
947 conntrack->proto.tcp.last_seq = ntohl(th->seq); 939 conntrack->proto.tcp.last_seq = ntohl(th->seq);
948 conntrack->proto.tcp.last_end = 940 conntrack->proto.tcp.last_end =
949 segment_seq_plus_len(ntohl(th->seq), skb->len, iph, th); 941 segment_seq_plus_len(ntohl(th->seq), skb->len, iph, th);
950 942
951 write_unlock_bh(&tcp_lock); 943 write_unlock_bh(&tcp_lock);
952 if (LOG_INVALID(IPPROTO_TCP)) 944 if (LOG_INVALID(IPPROTO_TCP))
953 nf_log_packet(PF_INET, 0, skb, NULL, NULL, NULL, 945 nf_log_packet(PF_INET, 0, skb, NULL, NULL, NULL,
@@ -967,16 +959,16 @@ static int tcp_packet(struct ip_conntrack *conntrack,
967 if (old_state < TCP_CONNTRACK_TIME_WAIT) 959 if (old_state < TCP_CONNTRACK_TIME_WAIT)
968 break; 960 break;
969 if ((conntrack->proto.tcp.seen[dir].flags & 961 if ((conntrack->proto.tcp.seen[dir].flags &
970 IP_CT_TCP_FLAG_CLOSE_INIT) 962 IP_CT_TCP_FLAG_CLOSE_INIT)
971 || after(ntohl(th->seq), 963 || after(ntohl(th->seq),
972 conntrack->proto.tcp.seen[dir].td_end)) { 964 conntrack->proto.tcp.seen[dir].td_end)) {
973 /* Attempt to reopen a closed connection. 965 /* Attempt to reopen a closed connection.
974 * Delete this connection and look up again. */ 966 * Delete this connection and look up again. */
975 write_unlock_bh(&tcp_lock); 967 write_unlock_bh(&tcp_lock);
976 if (del_timer(&conntrack->timeout)) 968 if (del_timer(&conntrack->timeout))
977 conntrack->timeout.function((unsigned long) 969 conntrack->timeout.function((unsigned long)
978 conntrack); 970 conntrack);
979 return -NF_REPEAT; 971 return -NF_REPEAT;
980 } else { 972 } else {
981 write_unlock_bh(&tcp_lock); 973 write_unlock_bh(&tcp_lock);
982 if (LOG_INVALID(IPPROTO_TCP)) 974 if (LOG_INVALID(IPPROTO_TCP))
@@ -987,9 +979,9 @@ static int tcp_packet(struct ip_conntrack *conntrack,
987 case TCP_CONNTRACK_CLOSE: 979 case TCP_CONNTRACK_CLOSE:
988 if (index == TCP_RST_SET 980 if (index == TCP_RST_SET
989 && ((test_bit(IPS_SEEN_REPLY_BIT, &conntrack->status) 981 && ((test_bit(IPS_SEEN_REPLY_BIT, &conntrack->status)
990 && conntrack->proto.tcp.last_index == TCP_SYN_SET) 982 && conntrack->proto.tcp.last_index == TCP_SYN_SET)
991 || (!test_bit(IPS_ASSURED_BIT, &conntrack->status) 983 || (!test_bit(IPS_ASSURED_BIT, &conntrack->status)
992 && conntrack->proto.tcp.last_index == TCP_ACK_SET)) 984 && conntrack->proto.tcp.last_index == TCP_ACK_SET))
993 && ntohl(th->ack_seq) == conntrack->proto.tcp.last_end) { 985 && ntohl(th->ack_seq) == conntrack->proto.tcp.last_end) {
994 /* RST sent to invalid SYN or ACK we had let through 986 /* RST sent to invalid SYN or ACK we had let through
995 * at a) and c) above: 987 * at a) and c) above:
@@ -1008,13 +1000,13 @@ static int tcp_packet(struct ip_conntrack *conntrack,
1008 break; 1000 break;
1009 } 1001 }
1010 1002
1011 if (!tcp_in_window(&conntrack->proto.tcp, dir, index, 1003 if (!tcp_in_window(&conntrack->proto.tcp, dir, index,
1012 skb, iph, th)) { 1004 skb, iph, th)) {
1013 write_unlock_bh(&tcp_lock); 1005 write_unlock_bh(&tcp_lock);
1014 return -NF_ACCEPT; 1006 return -NF_ACCEPT;
1015 } 1007 }
1016 in_window: 1008 in_window:
1017 /* From now on we have got in-window packets */ 1009 /* From now on we have got in-window packets */
1018 conntrack->proto.tcp.last_index = index; 1010 conntrack->proto.tcp.last_index = index;
1019 1011
1020 DEBUGP("tcp_conntracks: src=%u.%u.%u.%u:%hu dst=%u.%u.%u.%u:%hu " 1012 DEBUGP("tcp_conntracks: src=%u.%u.%u.%u:%hu dst=%u.%u.%u.%u:%hu "
@@ -1026,9 +1018,9 @@ static int tcp_packet(struct ip_conntrack *conntrack,
1026 old_state, new_state); 1018 old_state, new_state);
1027 1019
1028 conntrack->proto.tcp.state = new_state; 1020 conntrack->proto.tcp.state = new_state;
1029 if (old_state != new_state 1021 if (old_state != new_state
1030 && (new_state == TCP_CONNTRACK_FIN_WAIT 1022 && (new_state == TCP_CONNTRACK_FIN_WAIT
1031 || new_state == TCP_CONNTRACK_CLOSE)) 1023 || new_state == TCP_CONNTRACK_CLOSE))
1032 conntrack->proto.tcp.seen[dir].flags |= IP_CT_TCP_FLAG_CLOSE_INIT; 1024 conntrack->proto.tcp.seen[dir].flags |= IP_CT_TCP_FLAG_CLOSE_INIT;
1033 timeout = conntrack->proto.tcp.retrans >= ip_ct_tcp_max_retrans 1025 timeout = conntrack->proto.tcp.retrans >= ip_ct_tcp_max_retrans
1034 && *tcp_timeouts[new_state] > ip_ct_tcp_timeout_max_retrans 1026 && *tcp_timeouts[new_state] > ip_ct_tcp_timeout_max_retrans
@@ -1054,8 +1046,8 @@ static int tcp_packet(struct ip_conntrack *conntrack,
1054 && (old_state == TCP_CONNTRACK_SYN_RECV 1046 && (old_state == TCP_CONNTRACK_SYN_RECV
1055 || old_state == TCP_CONNTRACK_ESTABLISHED) 1047 || old_state == TCP_CONNTRACK_ESTABLISHED)
1056 && new_state == TCP_CONNTRACK_ESTABLISHED) { 1048 && new_state == TCP_CONNTRACK_ESTABLISHED) {
1057 /* Set ASSURED if we see see valid ack in ESTABLISHED 1049 /* Set ASSURED if we see see valid ack in ESTABLISHED
1058 after SYN_RECV or a valid answer for a picked up 1050 after SYN_RECV or a valid answer for a picked up
1059 connection. */ 1051 connection. */
1060 set_bit(IPS_ASSURED_BIT, &conntrack->status); 1052 set_bit(IPS_ASSURED_BIT, &conntrack->status);
1061 ip_conntrack_event_cache(IPCT_STATUS, skb); 1053 ip_conntrack_event_cache(IPCT_STATUS, skb);
@@ -1064,7 +1056,7 @@ static int tcp_packet(struct ip_conntrack *conntrack,
1064 1056
1065 return NF_ACCEPT; 1057 return NF_ACCEPT;
1066} 1058}
1067 1059
1068/* Called when a new connection for this protocol found. */ 1060/* Called when a new connection for this protocol found. */
1069static int tcp_new(struct ip_conntrack *conntrack, 1061static int tcp_new(struct ip_conntrack *conntrack,
1070 const struct sk_buff *skb) 1062 const struct sk_buff *skb)
@@ -1080,7 +1072,7 @@ static int tcp_new(struct ip_conntrack *conntrack,
1080 th = skb_header_pointer(skb, iph->ihl * 4, 1072 th = skb_header_pointer(skb, iph->ihl * 4,
1081 sizeof(_tcph), &_tcph); 1073 sizeof(_tcph), &_tcph);
1082 BUG_ON(th == NULL); 1074 BUG_ON(th == NULL);
1083 1075
1084 /* Don't need lock here: this conntrack not in circulation yet */ 1076 /* Don't need lock here: this conntrack not in circulation yet */
1085 new_state 1077 new_state
1086 = tcp_conntracks[0][get_conntrack_index(th)] 1078 = tcp_conntracks[0][get_conntrack_index(th)]
@@ -1105,8 +1097,6 @@ static int tcp_new(struct ip_conntrack *conntrack,
1105 1097
1106 tcp_options(skb, iph, th, &conntrack->proto.tcp.seen[0]); 1098 tcp_options(skb, iph, th, &conntrack->proto.tcp.seen[0]);
1107 conntrack->proto.tcp.seen[1].flags = 0; 1099 conntrack->proto.tcp.seen[1].flags = 0;
1108 conntrack->proto.tcp.seen[0].loose =
1109 conntrack->proto.tcp.seen[1].loose = 0;
1110 } else if (ip_ct_tcp_loose == 0) { 1100 } else if (ip_ct_tcp_loose == 0) {
1111 /* Don't try to pick up connections. */ 1101 /* Don't try to pick up connections. */
1112 return 0; 1102 return 0;
@@ -1123,35 +1113,35 @@ static int tcp_new(struct ip_conntrack *conntrack,
1123 if (conntrack->proto.tcp.seen[0].td_maxwin == 0) 1113 if (conntrack->proto.tcp.seen[0].td_maxwin == 0)
1124 conntrack->proto.tcp.seen[0].td_maxwin = 1; 1114 conntrack->proto.tcp.seen[0].td_maxwin = 1;
1125 conntrack->proto.tcp.seen[0].td_maxend = 1115 conntrack->proto.tcp.seen[0].td_maxend =
1126 conntrack->proto.tcp.seen[0].td_end + 1116 conntrack->proto.tcp.seen[0].td_end +
1127 conntrack->proto.tcp.seen[0].td_maxwin; 1117 conntrack->proto.tcp.seen[0].td_maxwin;
1128 conntrack->proto.tcp.seen[0].td_scale = 0; 1118 conntrack->proto.tcp.seen[0].td_scale = 0;
1129 1119
1130 /* We assume SACK. Should we assume window scaling too? */ 1120 /* We assume SACK and liberal window checking to handle
1121 * window scaling */
1131 conntrack->proto.tcp.seen[0].flags = 1122 conntrack->proto.tcp.seen[0].flags =
1132 conntrack->proto.tcp.seen[1].flags = IP_CT_TCP_FLAG_SACK_PERM; 1123 conntrack->proto.tcp.seen[1].flags = IP_CT_TCP_FLAG_SACK_PERM |
1133 conntrack->proto.tcp.seen[0].loose = 1124 IP_CT_TCP_FLAG_BE_LIBERAL;
1134 conntrack->proto.tcp.seen[1].loose = ip_ct_tcp_loose;
1135 } 1125 }
1136 1126
1137 conntrack->proto.tcp.seen[1].td_end = 0; 1127 conntrack->proto.tcp.seen[1].td_end = 0;
1138 conntrack->proto.tcp.seen[1].td_maxend = 0; 1128 conntrack->proto.tcp.seen[1].td_maxend = 0;
1139 conntrack->proto.tcp.seen[1].td_maxwin = 1; 1129 conntrack->proto.tcp.seen[1].td_maxwin = 1;
1140 conntrack->proto.tcp.seen[1].td_scale = 0; 1130 conntrack->proto.tcp.seen[1].td_scale = 0;
1141 1131
1142 /* tcp_packet will set them */ 1132 /* tcp_packet will set them */
1143 conntrack->proto.tcp.state = TCP_CONNTRACK_NONE; 1133 conntrack->proto.tcp.state = TCP_CONNTRACK_NONE;
1144 conntrack->proto.tcp.last_index = TCP_NONE_SET; 1134 conntrack->proto.tcp.last_index = TCP_NONE_SET;
1145 1135
1146 DEBUGP("tcp_new: sender end=%u maxend=%u maxwin=%u scale=%i " 1136 DEBUGP("tcp_new: sender end=%u maxend=%u maxwin=%u scale=%i "
1147 "receiver end=%u maxend=%u maxwin=%u scale=%i\n", 1137 "receiver end=%u maxend=%u maxwin=%u scale=%i\n",
1148 sender->td_end, sender->td_maxend, sender->td_maxwin, 1138 sender->td_end, sender->td_maxend, sender->td_maxwin,
1149 sender->td_scale, 1139 sender->td_scale,
1150 receiver->td_end, receiver->td_maxend, receiver->td_maxwin, 1140 receiver->td_end, receiver->td_maxend, receiver->td_maxwin,
1151 receiver->td_scale); 1141 receiver->td_scale);
1152 return 1; 1142 return 1;
1153} 1143}
1154 1144
1155struct ip_conntrack_protocol ip_conntrack_protocol_tcp = 1145struct ip_conntrack_protocol ip_conntrack_protocol_tcp =
1156{ 1146{
1157 .proto = IPPROTO_TCP, 1147 .proto = IPPROTO_TCP,
diff --git a/net/ipv4/netfilter/ip_conntrack_proto_udp.c b/net/ipv4/netfilter/ip_conntrack_proto_udp.c
index d0e8a16970ec..a99a7c75e5b5 100644
--- a/net/ipv4/netfilter/ip_conntrack_proto_udp.c
+++ b/net/ipv4/netfilter/ip_conntrack_proto_udp.c
@@ -70,7 +70,7 @@ static int udp_packet(struct ip_conntrack *conntrack,
70 /* If we've seen traffic both ways, this is some kind of UDP 70 /* If we've seen traffic both ways, this is some kind of UDP
71 stream. Extend timeout. */ 71 stream. Extend timeout. */
72 if (test_bit(IPS_SEEN_REPLY_BIT, &conntrack->status)) { 72 if (test_bit(IPS_SEEN_REPLY_BIT, &conntrack->status)) {
73 ip_ct_refresh_acct(conntrack, ctinfo, skb, 73 ip_ct_refresh_acct(conntrack, ctinfo, skb,
74 ip_ct_udp_timeout_stream); 74 ip_ct_udp_timeout_stream);
75 /* Also, more likely to be important, and not a probe */ 75 /* Also, more likely to be important, and not a probe */
76 if (!test_and_set_bit(IPS_ASSURED_BIT, &conntrack->status)) 76 if (!test_and_set_bit(IPS_ASSURED_BIT, &conntrack->status))
@@ -102,7 +102,7 @@ static int udp_error(struct sk_buff *skb, enum ip_conntrack_info *ctinfo,
102 "ip_ct_udp: short packet "); 102 "ip_ct_udp: short packet ");
103 return -NF_ACCEPT; 103 return -NF_ACCEPT;
104 } 104 }
105 105
106 /* Truncated/malformed packets */ 106 /* Truncated/malformed packets */
107 if (ntohs(hdr->len) > udplen || ntohs(hdr->len) < sizeof(*hdr)) { 107 if (ntohs(hdr->len) > udplen || ntohs(hdr->len) < sizeof(*hdr)) {
108 if (LOG_INVALID(IPPROTO_UDP)) 108 if (LOG_INVALID(IPPROTO_UDP))
@@ -110,7 +110,7 @@ static int udp_error(struct sk_buff *skb, enum ip_conntrack_info *ctinfo,
110 "ip_ct_udp: truncated/malformed packet "); 110 "ip_ct_udp: truncated/malformed packet ");
111 return -NF_ACCEPT; 111 return -NF_ACCEPT;
112 } 112 }
113 113
114 /* Packet with no checksum */ 114 /* Packet with no checksum */
115 if (!hdr->check) 115 if (!hdr->check)
116 return NF_ACCEPT; 116 return NF_ACCEPT;
@@ -126,7 +126,7 @@ static int udp_error(struct sk_buff *skb, enum ip_conntrack_info *ctinfo,
126 "ip_ct_udp: bad UDP checksum "); 126 "ip_ct_udp: bad UDP checksum ");
127 return -NF_ACCEPT; 127 return -NF_ACCEPT;
128 } 128 }
129 129
130 return NF_ACCEPT; 130 return NF_ACCEPT;
131} 131}
132 132
diff --git a/net/ipv4/netfilter/ip_conntrack_sip.c b/net/ipv4/netfilter/ip_conntrack_sip.c
index 11c588a10e6b..c59a962c1f61 100644
--- a/net/ipv4/netfilter/ip_conntrack_sip.c
+++ b/net/ipv4/netfilter/ip_conntrack_sip.c
@@ -321,7 +321,7 @@ int ct_sip_get_info(const char *dptr, size_t dlen,
321 continue; 321 continue;
322 } 322 }
323 aux = ct_sip_search(hnfo->ln_str, dptr, hnfo->ln_strlen, 323 aux = ct_sip_search(hnfo->ln_str, dptr, hnfo->ln_strlen,
324 ct_sip_lnlen(dptr, limit), 324 ct_sip_lnlen(dptr, limit),
325 hnfo->case_sensitive); 325 hnfo->case_sensitive);
326 if (!aux) { 326 if (!aux) {
327 DEBUGP("'%s' not found in '%s'.\n", hnfo->ln_str, 327 DEBUGP("'%s' not found in '%s'.\n", hnfo->ln_str,
@@ -406,7 +406,7 @@ static int sip_help(struct sk_buff **pskb,
406 if (dataoff >= (*pskb)->len) { 406 if (dataoff >= (*pskb)->len) {
407 DEBUGP("skb->len = %u\n", (*pskb)->len); 407 DEBUGP("skb->len = %u\n", (*pskb)->len);
408 return NF_ACCEPT; 408 return NF_ACCEPT;
409 } 409 }
410 410
411 ip_ct_refresh(ct, *pskb, sip_timeout * HZ); 411 ip_ct_refresh(ct, *pskb, sip_timeout * HZ);
412 412
@@ -439,16 +439,16 @@ static int sip_help(struct sk_buff **pskb,
439 } 439 }
440 /* Get ip and port address from SDP packet. */ 440 /* Get ip and port address from SDP packet. */
441 if (ct_sip_get_info(dptr, datalen, &matchoff, &matchlen, 441 if (ct_sip_get_info(dptr, datalen, &matchoff, &matchlen,
442 POS_CONNECTION) > 0) { 442 POS_CONNECTION) > 0) {
443 443
444 /* We'll drop only if there are parse problems. */ 444 /* We'll drop only if there are parse problems. */
445 if (parse_ipaddr(dptr + matchoff, NULL, &ipaddr, 445 if (parse_ipaddr(dptr + matchoff, NULL, &ipaddr,
446 dptr + datalen) < 0) { 446 dptr + datalen) < 0) {
447 ret = NF_DROP; 447 ret = NF_DROP;
448 goto out; 448 goto out;
449 } 449 }
450 if (ct_sip_get_info(dptr, datalen, &matchoff, &matchlen, 450 if (ct_sip_get_info(dptr, datalen, &matchoff, &matchlen,
451 POS_MEDIA) > 0) { 451 POS_MEDIA) > 0) {
452 452
453 port = simple_strtoul(dptr + matchoff, NULL, 10); 453 port = simple_strtoul(dptr + matchoff, NULL, 10);
454 if (port < 1024) { 454 if (port < 1024) {
diff --git a/net/ipv4/netfilter/ip_conntrack_standalone.c b/net/ipv4/netfilter/ip_conntrack_standalone.c
index 86efb5449676..c7c1ec61b0f5 100644
--- a/net/ipv4/netfilter/ip_conntrack_standalone.c
+++ b/net/ipv4/netfilter/ip_conntrack_standalone.c
@@ -46,7 +46,7 @@ DECLARE_PER_CPU(struct ip_conntrack_stat, ip_conntrack_stat);
46 46
47static int kill_proto(struct ip_conntrack *i, void *data) 47static int kill_proto(struct ip_conntrack *i, void *data)
48{ 48{
49 return (i->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.protonum == 49 return (i->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.protonum ==
50 *((u_int8_t *) data)); 50 *((u_int8_t *) data));
51} 51}
52 52
@@ -124,12 +124,12 @@ static void *ct_seq_next(struct seq_file *s, void *v, loff_t *pos)
124 (*pos)++; 124 (*pos)++;
125 return ct_get_next(s, v); 125 return ct_get_next(s, v);
126} 126}
127 127
128static void ct_seq_stop(struct seq_file *s, void *v) 128static void ct_seq_stop(struct seq_file *s, void *v)
129{ 129{
130 read_unlock_bh(&ip_conntrack_lock); 130 read_unlock_bh(&ip_conntrack_lock);
131} 131}
132 132
133static int ct_seq_show(struct seq_file *s, void *v) 133static int ct_seq_show(struct seq_file *s, void *v)
134{ 134{
135 const struct ip_conntrack_tuple_hash *hash = v; 135 const struct ip_conntrack_tuple_hash *hash = v;
@@ -155,12 +155,12 @@ static int ct_seq_show(struct seq_file *s, void *v)
155 155
156 if (proto->print_conntrack(s, conntrack)) 156 if (proto->print_conntrack(s, conntrack))
157 return -ENOSPC; 157 return -ENOSPC;
158 158
159 if (print_tuple(s, &conntrack->tuplehash[IP_CT_DIR_ORIGINAL].tuple, 159 if (print_tuple(s, &conntrack->tuplehash[IP_CT_DIR_ORIGINAL].tuple,
160 proto)) 160 proto))
161 return -ENOSPC; 161 return -ENOSPC;
162 162
163 if (seq_print_counters(s, &conntrack->counters[IP_CT_DIR_ORIGINAL])) 163 if (seq_print_counters(s, &conntrack->counters[IP_CT_DIR_ORIGINAL]))
164 return -ENOSPC; 164 return -ENOSPC;
165 165
166 if (!(test_bit(IPS_SEEN_REPLY_BIT, &conntrack->status))) 166 if (!(test_bit(IPS_SEEN_REPLY_BIT, &conntrack->status)))
@@ -171,7 +171,7 @@ static int ct_seq_show(struct seq_file *s, void *v)
171 proto)) 171 proto))
172 return -ENOSPC; 172 return -ENOSPC;
173 173
174 if (seq_print_counters(s, &conntrack->counters[IP_CT_DIR_REPLY])) 174 if (seq_print_counters(s, &conntrack->counters[IP_CT_DIR_REPLY]))
175 return -ENOSPC; 175 return -ENOSPC;
176 176
177 if (test_bit(IPS_ASSURED_BIT, &conntrack->status)) 177 if (test_bit(IPS_ASSURED_BIT, &conntrack->status))
@@ -200,7 +200,7 @@ static struct seq_operations ct_seq_ops = {
200 .stop = ct_seq_stop, 200 .stop = ct_seq_stop,
201 .show = ct_seq_show 201 .show = ct_seq_show
202}; 202};
203 203
204static int ct_open(struct inode *inode, struct file *file) 204static int ct_open(struct inode *inode, struct file *file)
205{ 205{
206 struct seq_file *seq; 206 struct seq_file *seq;
@@ -222,14 +222,14 @@ out_free:
222 return ret; 222 return ret;
223} 223}
224 224
225static struct file_operations ct_file_ops = { 225static const struct file_operations ct_file_ops = {
226 .owner = THIS_MODULE, 226 .owner = THIS_MODULE,
227 .open = ct_open, 227 .open = ct_open,
228 .read = seq_read, 228 .read = seq_read,
229 .llseek = seq_lseek, 229 .llseek = seq_lseek,
230 .release = seq_release_private, 230 .release = seq_release_private,
231}; 231};
232 232
233/* expects */ 233/* expects */
234static void *exp_seq_start(struct seq_file *s, loff_t *pos) 234static void *exp_seq_start(struct seq_file *s, loff_t *pos)
235{ 235{
@@ -253,7 +253,7 @@ static void *exp_seq_start(struct seq_file *s, loff_t *pos)
253 253
254static void *exp_seq_next(struct seq_file *s, void *v, loff_t *pos) 254static void *exp_seq_next(struct seq_file *s, void *v, loff_t *pos)
255{ 255{
256 struct list_head *e = v; 256 struct list_head *e = v;
257 257
258 ++*pos; 258 ++*pos;
259 e = e->next; 259 e = e->next;
@@ -297,8 +297,8 @@ static int exp_open(struct inode *inode, struct file *file)
297{ 297{
298 return seq_open(file, &exp_seq_ops); 298 return seq_open(file, &exp_seq_ops);
299} 299}
300 300
301static struct file_operations exp_file_ops = { 301static const struct file_operations exp_file_ops = {
302 .owner = THIS_MODULE, 302 .owner = THIS_MODULE,
303 .open = exp_open, 303 .open = exp_open,
304 .read = seq_read, 304 .read = seq_read,
@@ -386,7 +386,7 @@ static int ct_cpu_seq_open(struct inode *inode, struct file *file)
386 return seq_open(file, &ct_cpu_seq_ops); 386 return seq_open(file, &ct_cpu_seq_ops);
387} 387}
388 388
389static struct file_operations ct_cpu_seq_fops = { 389static const struct file_operations ct_cpu_seq_fops = {
390 .owner = THIS_MODULE, 390 .owner = THIS_MODULE,
391 .open = ct_cpu_seq_open, 391 .open = ct_cpu_seq_open,
392 .read = seq_read, 392 .read = seq_read,
@@ -426,14 +426,14 @@ static unsigned int ip_conntrack_help(unsigned int hooknum,
426} 426}
427 427
428static unsigned int ip_conntrack_defrag(unsigned int hooknum, 428static unsigned int ip_conntrack_defrag(unsigned int hooknum,
429 struct sk_buff **pskb, 429 struct sk_buff **pskb,
430 const struct net_device *in, 430 const struct net_device *in,
431 const struct net_device *out, 431 const struct net_device *out,
432 int (*okfn)(struct sk_buff *)) 432 int (*okfn)(struct sk_buff *))
433{ 433{
434#if !defined(CONFIG_IP_NF_NAT) && !defined(CONFIG_IP_NF_NAT_MODULE) 434#if !defined(CONFIG_IP_NF_NAT) && !defined(CONFIG_IP_NF_NAT_MODULE)
435 /* Previously seen (loopback)? Ignore. Do this before 435 /* Previously seen (loopback)? Ignore. Do this before
436 fragment check. */ 436 fragment check. */
437 if ((*pskb)->nfct) 437 if ((*pskb)->nfct)
438 return NF_ACCEPT; 438 return NF_ACCEPT;
439#endif 439#endif
@@ -441,7 +441,7 @@ static unsigned int ip_conntrack_defrag(unsigned int hooknum,
441 /* Gather fragments. */ 441 /* Gather fragments. */
442 if ((*pskb)->nh.iph->frag_off & htons(IP_MF|IP_OFFSET)) { 442 if ((*pskb)->nh.iph->frag_off & htons(IP_MF|IP_OFFSET)) {
443 *pskb = ip_ct_gather_frags(*pskb, 443 *pskb = ip_ct_gather_frags(*pskb,
444 hooknum == NF_IP_PRE_ROUTING ? 444 hooknum == NF_IP_PRE_ROUTING ?
445 IP_DEFRAG_CONNTRACK_IN : 445 IP_DEFRAG_CONNTRACK_IN :
446 IP_DEFRAG_CONNTRACK_OUT); 446 IP_DEFRAG_CONNTRACK_OUT);
447 if (!*pskb) 447 if (!*pskb)
@@ -776,7 +776,7 @@ static ctl_table ip_ct_net_table[] = {
776 { 776 {
777 .ctl_name = CTL_NET, 777 .ctl_name = CTL_NET,
778 .procname = "net", 778 .procname = "net",
779 .mode = 0555, 779 .mode = 0555,
780 .child = ip_ct_ipv4_table, 780 .child = ip_ct_ipv4_table,
781 }, 781 },
782 { .ctl_name = 0 } 782 { .ctl_name = 0 }
@@ -796,7 +796,7 @@ int ip_conntrack_protocol_register(struct ip_conntrack_protocol *proto)
796 ret = -EBUSY; 796 ret = -EBUSY;
797 goto out; 797 goto out;
798 } 798 }
799 ip_ct_protos[proto->proto] = proto; 799 rcu_assign_pointer(ip_ct_protos[proto->proto], proto);
800 out: 800 out:
801 write_unlock_bh(&ip_conntrack_lock); 801 write_unlock_bh(&ip_conntrack_lock);
802 return ret; 802 return ret;
@@ -805,11 +805,10 @@ int ip_conntrack_protocol_register(struct ip_conntrack_protocol *proto)
805void ip_conntrack_protocol_unregister(struct ip_conntrack_protocol *proto) 805void ip_conntrack_protocol_unregister(struct ip_conntrack_protocol *proto)
806{ 806{
807 write_lock_bh(&ip_conntrack_lock); 807 write_lock_bh(&ip_conntrack_lock);
808 ip_ct_protos[proto->proto] = &ip_conntrack_generic_protocol; 808 rcu_assign_pointer(ip_ct_protos[proto->proto],
809 &ip_conntrack_generic_protocol);
809 write_unlock_bh(&ip_conntrack_lock); 810 write_unlock_bh(&ip_conntrack_lock);
810 811 synchronize_rcu();
811 /* Somebody could be still looking at the proto in bh. */
812 synchronize_net();
813 812
814 /* Remove all contrack entries for this protocol */ 813 /* Remove all contrack entries for this protocol */
815 ip_ct_iterate_cleanup(kill_proto, &proto->proto); 814 ip_ct_iterate_cleanup(kill_proto, &proto->proto);
diff --git a/net/ipv4/netfilter/ip_conntrack_tftp.c b/net/ipv4/netfilter/ip_conntrack_tftp.c
index ef56de2eff0c..76e175e7a972 100644
--- a/net/ipv4/netfilter/ip_conntrack_tftp.c
+++ b/net/ipv4/netfilter/ip_conntrack_tftp.c
@@ -33,7 +33,7 @@ MODULE_PARM_DESC(ports, "port numbers of tftp servers");
33 33
34#if 0 34#if 0
35#define DEBUGP(format, args...) printk("%s:%s:" format, \ 35#define DEBUGP(format, args...) printk("%s:%s:" format, \
36 __FILE__, __FUNCTION__ , ## args) 36 __FILE__, __FUNCTION__ , ## args)
37#else 37#else
38#define DEBUGP(format, args...) 38#define DEBUGP(format, args...)
39#endif 39#endif
@@ -113,7 +113,7 @@ static void ip_conntrack_tftp_fini(void)
113 DEBUGP("unregistering helper for port %d\n", 113 DEBUGP("unregistering helper for port %d\n",
114 ports[i]); 114 ports[i]);
115 ip_conntrack_helper_unregister(&tftp[i]); 115 ip_conntrack_helper_unregister(&tftp[i]);
116 } 116 }
117} 117}
118 118
119static int __init ip_conntrack_tftp_init(void) 119static int __init ip_conntrack_tftp_init(void)
diff --git a/net/ipv4/netfilter/ip_nat_core.c b/net/ipv4/netfilter/ip_nat_core.c
index 9d1a5175dcd4..40737fdbe9a7 100644
--- a/net/ipv4/netfilter/ip_nat_core.c
+++ b/net/ipv4/netfilter/ip_nat_core.c
@@ -50,7 +50,7 @@ static struct ip_nat_protocol *ip_nat_protos[MAX_IP_NAT_PROTO];
50static inline struct ip_nat_protocol * 50static inline struct ip_nat_protocol *
51__ip_nat_proto_find(u_int8_t protonum) 51__ip_nat_proto_find(u_int8_t protonum)
52{ 52{
53 return ip_nat_protos[protonum]; 53 return rcu_dereference(ip_nat_protos[protonum]);
54} 54}
55 55
56struct ip_nat_protocol * 56struct ip_nat_protocol *
@@ -58,13 +58,11 @@ ip_nat_proto_find_get(u_int8_t protonum)
58{ 58{
59 struct ip_nat_protocol *p; 59 struct ip_nat_protocol *p;
60 60
61 /* we need to disable preemption to make sure 'p' doesn't get 61 rcu_read_lock();
62 * removed until we've grabbed the reference */
63 preempt_disable();
64 p = __ip_nat_proto_find(protonum); 62 p = __ip_nat_proto_find(protonum);
65 if (!try_module_get(p->me)) 63 if (!try_module_get(p->me))
66 p = &ip_nat_unknown_protocol; 64 p = &ip_nat_unknown_protocol;
67 preempt_enable(); 65 rcu_read_unlock();
68 66
69 return p; 67 return p;
70} 68}
@@ -120,8 +118,8 @@ static int
120in_range(const struct ip_conntrack_tuple *tuple, 118in_range(const struct ip_conntrack_tuple *tuple,
121 const struct ip_nat_range *range) 119 const struct ip_nat_range *range)
122{ 120{
123 struct ip_nat_protocol *proto = 121 struct ip_nat_protocol *proto;
124 __ip_nat_proto_find(tuple->dst.protonum); 122 int ret = 0;
125 123
126 /* If we are supposed to map IPs, then we must be in the 124 /* If we are supposed to map IPs, then we must be in the
127 range specified, otherwise let this drag us onto a new src IP. */ 125 range specified, otherwise let this drag us onto a new src IP. */
@@ -131,12 +129,15 @@ in_range(const struct ip_conntrack_tuple *tuple,
131 return 0; 129 return 0;
132 } 130 }
133 131
132 rcu_read_lock();
133 proto = __ip_nat_proto_find(tuple->dst.protonum);
134 if (!(range->flags & IP_NAT_RANGE_PROTO_SPECIFIED) 134 if (!(range->flags & IP_NAT_RANGE_PROTO_SPECIFIED)
135 || proto->in_range(tuple, IP_NAT_MANIP_SRC, 135 || proto->in_range(tuple, IP_NAT_MANIP_SRC,
136 &range->min, &range->max)) 136 &range->min, &range->max))
137 return 1; 137 ret = 1;
138 rcu_read_unlock();
138 139
139 return 0; 140 return ret;
140} 141}
141 142
142static inline int 143static inline int
@@ -246,8 +247,9 @@ get_unique_tuple(struct ip_conntrack_tuple *tuple,
246 if (maniptype == IP_NAT_MANIP_SRC) { 247 if (maniptype == IP_NAT_MANIP_SRC) {
247 if (find_appropriate_src(orig_tuple, tuple, range)) { 248 if (find_appropriate_src(orig_tuple, tuple, range)) {
248 DEBUGP("get_unique_tuple: Found current src map\n"); 249 DEBUGP("get_unique_tuple: Found current src map\n");
249 if (!ip_nat_used_tuple(tuple, conntrack)) 250 if (!(range->flags & IP_NAT_RANGE_PROTO_RANDOM))
250 return; 251 if (!ip_nat_used_tuple(tuple, conntrack))
252 return;
251 } 253 }
252 } 254 }
253 255
@@ -259,20 +261,25 @@ get_unique_tuple(struct ip_conntrack_tuple *tuple,
259 /* 3) The per-protocol part of the manip is made to map into 261 /* 3) The per-protocol part of the manip is made to map into
260 the range to make a unique tuple. */ 262 the range to make a unique tuple. */
261 263
262 proto = ip_nat_proto_find_get(orig_tuple->dst.protonum); 264 rcu_read_lock();
265 proto = __ip_nat_proto_find(orig_tuple->dst.protonum);
266
267 /* Change protocol info to have some randomization */
268 if (range->flags & IP_NAT_RANGE_PROTO_RANDOM) {
269 proto->unique_tuple(tuple, range, maniptype, conntrack);
270 goto out;
271 }
263 272
264 /* Only bother mapping if it's not already in range and unique */ 273 /* Only bother mapping if it's not already in range and unique */
265 if ((!(range->flags & IP_NAT_RANGE_PROTO_SPECIFIED) 274 if ((!(range->flags & IP_NAT_RANGE_PROTO_SPECIFIED)
266 || proto->in_range(tuple, maniptype, &range->min, &range->max)) 275 || proto->in_range(tuple, maniptype, &range->min, &range->max))
267 && !ip_nat_used_tuple(tuple, conntrack)) { 276 && !ip_nat_used_tuple(tuple, conntrack))
268 ip_nat_proto_put(proto); 277 goto out;
269 return;
270 }
271 278
272 /* Last change: get protocol to try to obtain unique tuple. */ 279 /* Last change: get protocol to try to obtain unique tuple. */
273 proto->unique_tuple(tuple, range, maniptype, conntrack); 280 proto->unique_tuple(tuple, range, maniptype, conntrack);
274 281out:
275 ip_nat_proto_put(proto); 282 rcu_read_unlock();
276} 283}
277 284
278unsigned int 285unsigned int
@@ -352,12 +359,11 @@ manip_pkt(u_int16_t proto,
352 iph = (void *)(*pskb)->data + iphdroff; 359 iph = (void *)(*pskb)->data + iphdroff;
353 360
354 /* Manipulate protcol part. */ 361 /* Manipulate protcol part. */
355 p = ip_nat_proto_find_get(proto); 362
356 if (!p->manip_pkt(pskb, iphdroff, target, maniptype)) { 363 /* rcu_read_lock()ed by nf_hook_slow */
357 ip_nat_proto_put(p); 364 p = __ip_nat_proto_find(proto);
365 if (!p->manip_pkt(pskb, iphdroff, target, maniptype))
358 return 0; 366 return 0;
359 }
360 ip_nat_proto_put(p);
361 367
362 iph = (void *)(*pskb)->data + iphdroff; 368 iph = (void *)(*pskb)->data + iphdroff;
363 369
@@ -414,6 +420,7 @@ int ip_nat_icmp_reply_translation(struct ip_conntrack *ct,
414 struct icmphdr icmp; 420 struct icmphdr icmp;
415 struct iphdr ip; 421 struct iphdr ip;
416 } *inside; 422 } *inside;
423 struct ip_conntrack_protocol *proto;
417 struct ip_conntrack_tuple inner, target; 424 struct ip_conntrack_tuple inner, target;
418 int hdrlen = (*pskb)->nh.iph->ihl * 4; 425 int hdrlen = (*pskb)->nh.iph->ihl * 4;
419 enum ip_conntrack_dir dir = CTINFO2DIR(ctinfo); 426 enum ip_conntrack_dir dir = CTINFO2DIR(ctinfo);
@@ -435,8 +442,8 @@ int ip_nat_icmp_reply_translation(struct ip_conntrack *ct,
435 (*pskb)->nfctinfo == IP_CT_RELATED+IP_CT_IS_REPLY); 442 (*pskb)->nfctinfo == IP_CT_RELATED+IP_CT_IS_REPLY);
436 443
437 /* Redirects on non-null nats must be dropped, else they'll 444 /* Redirects on non-null nats must be dropped, else they'll
438 start talking to each other without our translation, and be 445 start talking to each other without our translation, and be
439 confused... --RR */ 446 confused... --RR */
440 if (inside->icmp.type == ICMP_REDIRECT) { 447 if (inside->icmp.type == ICMP_REDIRECT) {
441 /* If NAT isn't finished, assume it and drop. */ 448 /* If NAT isn't finished, assume it and drop. */
442 if ((ct->status & IPS_NAT_DONE_MASK) != IPS_NAT_DONE_MASK) 449 if ((ct->status & IPS_NAT_DONE_MASK) != IPS_NAT_DONE_MASK)
@@ -449,10 +456,11 @@ int ip_nat_icmp_reply_translation(struct ip_conntrack *ct,
449 DEBUGP("icmp_reply_translation: translating error %p manp %u dir %s\n", 456 DEBUGP("icmp_reply_translation: translating error %p manp %u dir %s\n",
450 *pskb, manip, dir == IP_CT_DIR_ORIGINAL ? "ORIG" : "REPLY"); 457 *pskb, manip, dir == IP_CT_DIR_ORIGINAL ? "ORIG" : "REPLY");
451 458
459 /* rcu_read_lock()ed by nf_hook_slow */
460 proto = __ip_conntrack_proto_find(inside->ip.protocol);
452 if (!ip_ct_get_tuple(&inside->ip, *pskb, (*pskb)->nh.iph->ihl*4 + 461 if (!ip_ct_get_tuple(&inside->ip, *pskb, (*pskb)->nh.iph->ihl*4 +
453 sizeof(struct icmphdr) + inside->ip.ihl*4, 462 sizeof(struct icmphdr) + inside->ip.ihl*4,
454 &inner, 463 &inner, proto))
455 __ip_conntrack_proto_find(inside->ip.protocol)))
456 return 0; 464 return 0;
457 465
458 /* Change inner back to look like incoming packet. We do the 466 /* Change inner back to look like incoming packet. We do the
@@ -507,7 +515,7 @@ int ip_nat_protocol_register(struct ip_nat_protocol *proto)
507 ret = -EBUSY; 515 ret = -EBUSY;
508 goto out; 516 goto out;
509 } 517 }
510 ip_nat_protos[proto->protonum] = proto; 518 rcu_assign_pointer(ip_nat_protos[proto->protonum], proto);
511 out: 519 out:
512 write_unlock_bh(&ip_nat_lock); 520 write_unlock_bh(&ip_nat_lock);
513 return ret; 521 return ret;
@@ -518,18 +526,17 @@ EXPORT_SYMBOL(ip_nat_protocol_register);
518void ip_nat_protocol_unregister(struct ip_nat_protocol *proto) 526void ip_nat_protocol_unregister(struct ip_nat_protocol *proto)
519{ 527{
520 write_lock_bh(&ip_nat_lock); 528 write_lock_bh(&ip_nat_lock);
521 ip_nat_protos[proto->protonum] = &ip_nat_unknown_protocol; 529 rcu_assign_pointer(ip_nat_protos[proto->protonum],
530 &ip_nat_unknown_protocol);
522 write_unlock_bh(&ip_nat_lock); 531 write_unlock_bh(&ip_nat_lock);
523 532 synchronize_rcu();
524 /* Someone could be still looking at the proto in a bh. */
525 synchronize_net();
526} 533}
527EXPORT_SYMBOL(ip_nat_protocol_unregister); 534EXPORT_SYMBOL(ip_nat_protocol_unregister);
528 535
529#if defined(CONFIG_IP_NF_CONNTRACK_NETLINK) || \ 536#if defined(CONFIG_IP_NF_CONNTRACK_NETLINK) || \
530 defined(CONFIG_IP_NF_CONNTRACK_NETLINK_MODULE) 537 defined(CONFIG_IP_NF_CONNTRACK_NETLINK_MODULE)
531int 538int
532ip_nat_port_range_to_nfattr(struct sk_buff *skb, 539ip_nat_port_range_to_nfattr(struct sk_buff *skb,
533 const struct ip_nat_range *range) 540 const struct ip_nat_range *range)
534{ 541{
535 NFA_PUT(skb, CTA_PROTONAT_PORT_MIN, sizeof(__be16), 542 NFA_PUT(skb, CTA_PROTONAT_PORT_MIN, sizeof(__be16),
@@ -547,21 +554,21 @@ int
547ip_nat_port_nfattr_to_range(struct nfattr *tb[], struct ip_nat_range *range) 554ip_nat_port_nfattr_to_range(struct nfattr *tb[], struct ip_nat_range *range)
548{ 555{
549 int ret = 0; 556 int ret = 0;
550 557
551 /* we have to return whether we actually parsed something or not */ 558 /* we have to return whether we actually parsed something or not */
552 559
553 if (tb[CTA_PROTONAT_PORT_MIN-1]) { 560 if (tb[CTA_PROTONAT_PORT_MIN-1]) {
554 ret = 1; 561 ret = 1;
555 range->min.tcp.port = 562 range->min.tcp.port =
556 *(__be16 *)NFA_DATA(tb[CTA_PROTONAT_PORT_MIN-1]); 563 *(__be16 *)NFA_DATA(tb[CTA_PROTONAT_PORT_MIN-1]);
557 } 564 }
558 565
559 if (!tb[CTA_PROTONAT_PORT_MAX-1]) { 566 if (!tb[CTA_PROTONAT_PORT_MAX-1]) {
560 if (ret) 567 if (ret)
561 range->max.tcp.port = range->min.tcp.port; 568 range->max.tcp.port = range->min.tcp.port;
562 } else { 569 } else {
563 ret = 1; 570 ret = 1;
564 range->max.tcp.port = 571 range->max.tcp.port =
565 *(__be16 *)NFA_DATA(tb[CTA_PROTONAT_PORT_MAX-1]); 572 *(__be16 *)NFA_DATA(tb[CTA_PROTONAT_PORT_MAX-1]);
566 } 573 }
567 574
@@ -586,10 +593,10 @@ static int __init ip_nat_init(void)
586 /* Sew in builtin protocols. */ 593 /* Sew in builtin protocols. */
587 write_lock_bh(&ip_nat_lock); 594 write_lock_bh(&ip_nat_lock);
588 for (i = 0; i < MAX_IP_NAT_PROTO; i++) 595 for (i = 0; i < MAX_IP_NAT_PROTO; i++)
589 ip_nat_protos[i] = &ip_nat_unknown_protocol; 596 rcu_assign_pointer(ip_nat_protos[i], &ip_nat_unknown_protocol);
590 ip_nat_protos[IPPROTO_TCP] = &ip_nat_protocol_tcp; 597 rcu_assign_pointer(ip_nat_protos[IPPROTO_TCP], &ip_nat_protocol_tcp);
591 ip_nat_protos[IPPROTO_UDP] = &ip_nat_protocol_udp; 598 rcu_assign_pointer(ip_nat_protos[IPPROTO_UDP], &ip_nat_protocol_udp);
592 ip_nat_protos[IPPROTO_ICMP] = &ip_nat_protocol_icmp; 599 rcu_assign_pointer(ip_nat_protos[IPPROTO_ICMP], &ip_nat_protocol_icmp);
593 write_unlock_bh(&ip_nat_lock); 600 write_unlock_bh(&ip_nat_lock);
594 601
595 for (i = 0; i < ip_nat_htable_size; i++) { 602 for (i = 0; i < ip_nat_htable_size; i++) {
@@ -597,8 +604,8 @@ static int __init ip_nat_init(void)
597 } 604 }
598 605
599 /* FIXME: Man, this is a hack. <SIGH> */ 606 /* FIXME: Man, this is a hack. <SIGH> */
600 IP_NF_ASSERT(ip_conntrack_destroyed == NULL); 607 IP_NF_ASSERT(rcu_dereference(ip_conntrack_destroyed) == NULL);
601 ip_conntrack_destroyed = &ip_nat_cleanup_conntrack; 608 rcu_assign_pointer(ip_conntrack_destroyed, ip_nat_cleanup_conntrack);
602 609
603 /* Initialize fake conntrack so that NAT will skip it */ 610 /* Initialize fake conntrack so that NAT will skip it */
604 ip_conntrack_untracked.status |= IPS_NAT_DONE_MASK; 611 ip_conntrack_untracked.status |= IPS_NAT_DONE_MASK;
@@ -616,7 +623,8 @@ static int clean_nat(struct ip_conntrack *i, void *data)
616static void __exit ip_nat_cleanup(void) 623static void __exit ip_nat_cleanup(void)
617{ 624{
618 ip_ct_iterate_cleanup(&clean_nat, NULL); 625 ip_ct_iterate_cleanup(&clean_nat, NULL);
619 ip_conntrack_destroyed = NULL; 626 rcu_assign_pointer(ip_conntrack_destroyed, NULL);
627 synchronize_rcu();
620 vfree(bysource); 628 vfree(bysource);
621} 629}
622 630
diff --git a/net/ipv4/netfilter/ip_nat_ftp.c b/net/ipv4/netfilter/ip_nat_ftp.c
index 913960e1380f..32e01d8dffcb 100644
--- a/net/ipv4/netfilter/ip_nat_ftp.c
+++ b/net/ipv4/netfilter/ip_nat_ftp.c
@@ -50,7 +50,7 @@ mangle_rfc959_packet(struct sk_buff **pskb,
50 DEBUGP("calling ip_nat_mangle_tcp_packet\n"); 50 DEBUGP("calling ip_nat_mangle_tcp_packet\n");
51 51
52 *seq += strlen(buffer) - matchlen; 52 *seq += strlen(buffer) - matchlen;
53 return ip_nat_mangle_tcp_packet(pskb, ct, ctinfo, matchoff, 53 return ip_nat_mangle_tcp_packet(pskb, ct, ctinfo, matchoff,
54 matchlen, buffer, strlen(buffer)); 54 matchlen, buffer, strlen(buffer));
55} 55}
56 56
@@ -72,7 +72,7 @@ mangle_eprt_packet(struct sk_buff **pskb,
72 DEBUGP("calling ip_nat_mangle_tcp_packet\n"); 72 DEBUGP("calling ip_nat_mangle_tcp_packet\n");
73 73
74 *seq += strlen(buffer) - matchlen; 74 *seq += strlen(buffer) - matchlen;
75 return ip_nat_mangle_tcp_packet(pskb, ct, ctinfo, matchoff, 75 return ip_nat_mangle_tcp_packet(pskb, ct, ctinfo, matchoff,
76 matchlen, buffer, strlen(buffer)); 76 matchlen, buffer, strlen(buffer));
77} 77}
78 78
@@ -94,7 +94,7 @@ mangle_epsv_packet(struct sk_buff **pskb,
94 DEBUGP("calling ip_nat_mangle_tcp_packet\n"); 94 DEBUGP("calling ip_nat_mangle_tcp_packet\n");
95 95
96 *seq += strlen(buffer) - matchlen; 96 *seq += strlen(buffer) - matchlen;
97 return ip_nat_mangle_tcp_packet(pskb, ct, ctinfo, matchoff, 97 return ip_nat_mangle_tcp_packet(pskb, ct, ctinfo, matchoff,
98 matchlen, buffer, strlen(buffer)); 98 matchlen, buffer, strlen(buffer));
99} 99}
100 100
diff --git a/net/ipv4/netfilter/ip_nat_helper.c b/net/ipv4/netfilter/ip_nat_helper.c
index ee80feb4b2a9..dc778cfef58b 100644
--- a/net/ipv4/netfilter/ip_nat_helper.c
+++ b/net/ipv4/netfilter/ip_nat_helper.c
@@ -1,4 +1,4 @@
1/* ip_nat_helper.c - generic support functions for NAT helpers 1/* ip_nat_helper.c - generic support functions for NAT helpers
2 * 2 *
3 * (C) 2000-2002 Harald Welte <laforge@netfilter.org> 3 * (C) 2000-2002 Harald Welte <laforge@netfilter.org>
4 * (C) 2003-2004 Netfilter Core Team <coreteam@netfilter.org> 4 * (C) 2003-2004 Netfilter Core Team <coreteam@netfilter.org>
@@ -8,7 +8,7 @@
8 * published by the Free Software Foundation. 8 * published by the Free Software Foundation.
9 * 9 *
10 * 14 Jan 2002 Harald Welte <laforge@gnumonks.org>: 10 * 14 Jan 2002 Harald Welte <laforge@gnumonks.org>:
11 * - add support for SACK adjustment 11 * - add support for SACK adjustment
12 * 14 Mar 2002 Harald Welte <laforge@gnumonks.org>: 12 * 14 Mar 2002 Harald Welte <laforge@gnumonks.org>:
13 * - merge SACK support into newnat API 13 * - merge SACK support into newnat API
14 * 16 Aug 2002 Brian J. Murrell <netfilter@interlinx.bc.ca>: 14 * 16 Aug 2002 Brian J. Murrell <netfilter@interlinx.bc.ca>:
@@ -45,10 +45,10 @@
45static DEFINE_SPINLOCK(ip_nat_seqofs_lock); 45static DEFINE_SPINLOCK(ip_nat_seqofs_lock);
46 46
47/* Setup TCP sequence correction given this change at this sequence */ 47/* Setup TCP sequence correction given this change at this sequence */
48static inline void 48static inline void
49adjust_tcp_sequence(u32 seq, 49adjust_tcp_sequence(u32 seq,
50 int sizediff, 50 int sizediff,
51 struct ip_conntrack *ct, 51 struct ip_conntrack *ct,
52 enum ip_conntrack_info ctinfo) 52 enum ip_conntrack_info ctinfo)
53{ 53{
54 int dir; 54 int dir;
@@ -150,7 +150,7 @@ static int enlarge_skb(struct sk_buff **pskb, unsigned int extra)
150 * skb enlargement, ... 150 * skb enlargement, ...
151 * 151 *
152 * */ 152 * */
153int 153int
154ip_nat_mangle_tcp_packet(struct sk_buff **pskb, 154ip_nat_mangle_tcp_packet(struct sk_buff **pskb,
155 struct ip_conntrack *ct, 155 struct ip_conntrack *ct,
156 enum ip_conntrack_info ctinfo, 156 enum ip_conntrack_info ctinfo,
@@ -183,10 +183,10 @@ ip_nat_mangle_tcp_packet(struct sk_buff **pskb,
183 datalen = (*pskb)->len - iph->ihl*4; 183 datalen = (*pskb)->len - iph->ihl*4;
184 if ((*pskb)->ip_summed != CHECKSUM_PARTIAL) { 184 if ((*pskb)->ip_summed != CHECKSUM_PARTIAL) {
185 tcph->check = 0; 185 tcph->check = 0;
186 tcph->check = tcp_v4_check(tcph, datalen, 186 tcph->check = tcp_v4_check(datalen,
187 iph->saddr, iph->daddr, 187 iph->saddr, iph->daddr,
188 csum_partial((char *)tcph, 188 csum_partial((char *)tcph,
189 datalen, 0)); 189 datalen, 0));
190 } else 190 } else
191 nf_proto_csum_replace2(&tcph->check, *pskb, 191 nf_proto_csum_replace2(&tcph->check, *pskb,
192 htons(oldlen), htons(datalen), 1); 192 htons(oldlen), htons(datalen), 1);
@@ -202,7 +202,7 @@ ip_nat_mangle_tcp_packet(struct sk_buff **pskb,
202 return 1; 202 return 1;
203} 203}
204EXPORT_SYMBOL(ip_nat_mangle_tcp_packet); 204EXPORT_SYMBOL(ip_nat_mangle_tcp_packet);
205 205
206/* Generic function for mangling variable-length address changes inside 206/* Generic function for mangling variable-length address changes inside
207 * NATed UDP connections (like the CONNECT DATA XXXXX MESG XXXXX INDEX XXXXX 207 * NATed UDP connections (like the CONNECT DATA XXXXX MESG XXXXX INDEX XXXXX
208 * command in the Amanda protocol) 208 * command in the Amanda protocol)
@@ -213,7 +213,7 @@ EXPORT_SYMBOL(ip_nat_mangle_tcp_packet);
213 * XXX - This function could be merged with ip_nat_mangle_tcp_packet which 213 * XXX - This function could be merged with ip_nat_mangle_tcp_packet which
214 * should be fairly easy to do. 214 * should be fairly easy to do.
215 */ 215 */
216int 216int
217ip_nat_mangle_udp_packet(struct sk_buff **pskb, 217ip_nat_mangle_udp_packet(struct sk_buff **pskb,
218 struct ip_conntrack *ct, 218 struct ip_conntrack *ct,
219 enum ip_conntrack_info ctinfo, 219 enum ip_conntrack_info ctinfo,
@@ -228,8 +228,8 @@ ip_nat_mangle_udp_packet(struct sk_buff **pskb,
228 228
229 /* UDP helpers might accidentally mangle the wrong packet */ 229 /* UDP helpers might accidentally mangle the wrong packet */
230 iph = (*pskb)->nh.iph; 230 iph = (*pskb)->nh.iph;
231 if ((*pskb)->len < iph->ihl*4 + sizeof(*udph) + 231 if ((*pskb)->len < iph->ihl*4 + sizeof(*udph) +
232 match_offset + match_len) 232 match_offset + match_len)
233 return 0; 233 return 0;
234 234
235 if (!skb_make_writable(pskb, (*pskb)->len)) 235 if (!skb_make_writable(pskb, (*pskb)->len))
@@ -258,9 +258,9 @@ ip_nat_mangle_udp_packet(struct sk_buff **pskb,
258 if ((*pskb)->ip_summed != CHECKSUM_PARTIAL) { 258 if ((*pskb)->ip_summed != CHECKSUM_PARTIAL) {
259 udph->check = 0; 259 udph->check = 0;
260 udph->check = csum_tcpudp_magic(iph->saddr, iph->daddr, 260 udph->check = csum_tcpudp_magic(iph->saddr, iph->daddr,
261 datalen, IPPROTO_UDP, 261 datalen, IPPROTO_UDP,
262 csum_partial((char *)udph, 262 csum_partial((char *)udph,
263 datalen, 0)); 263 datalen, 0));
264 if (!udph->check) 264 if (!udph->check)
265 udph->check = CSUM_MANGLED_0; 265 udph->check = CSUM_MANGLED_0;
266 } else 266 } else
@@ -273,7 +273,7 @@ EXPORT_SYMBOL(ip_nat_mangle_udp_packet);
273/* Adjust one found SACK option including checksum correction */ 273/* Adjust one found SACK option including checksum correction */
274static void 274static void
275sack_adjust(struct sk_buff *skb, 275sack_adjust(struct sk_buff *skb,
276 struct tcphdr *tcph, 276 struct tcphdr *tcph,
277 unsigned int sackoff, 277 unsigned int sackoff,
278 unsigned int sackend, 278 unsigned int sackend,
279 struct ip_nat_seq *natseq) 279 struct ip_nat_seq *natseq)
@@ -360,14 +360,14 @@ ip_nat_sack_adjust(struct sk_buff **pskb,
360 360
361/* TCP sequence number adjustment. Returns 1 on success, 0 on failure */ 361/* TCP sequence number adjustment. Returns 1 on success, 0 on failure */
362int 362int
363ip_nat_seq_adjust(struct sk_buff **pskb, 363ip_nat_seq_adjust(struct sk_buff **pskb,
364 struct ip_conntrack *ct, 364 struct ip_conntrack *ct,
365 enum ip_conntrack_info ctinfo) 365 enum ip_conntrack_info ctinfo)
366{ 366{
367 struct tcphdr *tcph; 367 struct tcphdr *tcph;
368 int dir; 368 int dir;
369 __be32 newseq, newack; 369 __be32 newseq, newack;
370 struct ip_nat_seq *this_way, *other_way; 370 struct ip_nat_seq *this_way, *other_way;
371 371
372 dir = CTINFO2DIR(ctinfo); 372 dir = CTINFO2DIR(ctinfo);
373 373
diff --git a/net/ipv4/netfilter/ip_nat_helper_pptp.c b/net/ipv4/netfilter/ip_nat_helper_pptp.c
index ec957bbb5366..24ce4a5023d7 100644
--- a/net/ipv4/netfilter/ip_nat_helper_pptp.c
+++ b/net/ipv4/netfilter/ip_nat_helper_pptp.c
@@ -202,10 +202,10 @@ pptp_outbound_pkt(struct sk_buff **pskb,
202 202
203 /* mangle packet */ 203 /* mangle packet */
204 if (ip_nat_mangle_tcp_packet(pskb, ct, ctinfo, 204 if (ip_nat_mangle_tcp_packet(pskb, ct, ctinfo,
205 cid_off + sizeof(struct pptp_pkt_hdr) + 205 cid_off + sizeof(struct pptp_pkt_hdr) +
206 sizeof(struct PptpControlHeader), 206 sizeof(struct PptpControlHeader),
207 sizeof(new_callid), (char *)&new_callid, 207 sizeof(new_callid), (char *)&new_callid,
208 sizeof(new_callid)) == 0) 208 sizeof(new_callid)) == 0)
209 return NF_DROP; 209 return NF_DROP;
210 210
211 return NF_ACCEPT; 211 return NF_ACCEPT;
@@ -293,7 +293,7 @@ pptp_inbound_pkt(struct sk_buff **pskb,
293 ntohs(REQ_CID(pptpReq, pcid_off)), ntohs(new_pcid)); 293 ntohs(REQ_CID(pptpReq, pcid_off)), ntohs(new_pcid));
294 294
295 if (ip_nat_mangle_tcp_packet(pskb, ct, ctinfo, 295 if (ip_nat_mangle_tcp_packet(pskb, ct, ctinfo,
296 pcid_off + sizeof(struct pptp_pkt_hdr) + 296 pcid_off + sizeof(struct pptp_pkt_hdr) +
297 sizeof(struct PptpControlHeader), 297 sizeof(struct PptpControlHeader),
298 sizeof(new_pcid), (char *)&new_pcid, 298 sizeof(new_pcid), (char *)&new_pcid,
299 sizeof(new_pcid)) == 0) 299 sizeof(new_pcid)) == 0)
diff --git a/net/ipv4/netfilter/ip_nat_irc.c b/net/ipv4/netfilter/ip_nat_irc.c
index feb26b48f1d5..cfaeea38314f 100644
--- a/net/ipv4/netfilter/ip_nat_irc.c
+++ b/net/ipv4/netfilter/ip_nat_irc.c
@@ -88,8 +88,8 @@ static unsigned int help(struct sk_buff **pskb,
88 DEBUGP("ip_nat_irc: Inserting '%s' == %u.%u.%u.%u, port %u\n", 88 DEBUGP("ip_nat_irc: Inserting '%s' == %u.%u.%u.%u, port %u\n",
89 buffer, NIPQUAD(exp->tuple.src.ip), port); 89 buffer, NIPQUAD(exp->tuple.src.ip), port);
90 90
91 ret = ip_nat_mangle_tcp_packet(pskb, exp->master, ctinfo, 91 ret = ip_nat_mangle_tcp_packet(pskb, exp->master, ctinfo,
92 matchoff, matchlen, buffer, 92 matchoff, matchlen, buffer,
93 strlen(buffer)); 93 strlen(buffer));
94 if (ret != NF_ACCEPT) 94 if (ret != NF_ACCEPT)
95 ip_conntrack_unexpect_related(exp); 95 ip_conntrack_unexpect_related(exp);
diff --git a/net/ipv4/netfilter/ip_nat_proto_icmp.c b/net/ipv4/netfilter/ip_nat_proto_icmp.c
index fb716edd5bc6..22a528ae0380 100644
--- a/net/ipv4/netfilter/ip_nat_proto_icmp.c
+++ b/net/ipv4/netfilter/ip_nat_proto_icmp.c
@@ -45,7 +45,7 @@ icmp_unique_tuple(struct ip_conntrack_tuple *tuple,
45 45
46 for (i = 0; i < range_size; i++, id++) { 46 for (i = 0; i < range_size; i++, id++) {
47 tuple->src.u.icmp.id = htons(ntohs(range->min.icmp.id) + 47 tuple->src.u.icmp.id = htons(ntohs(range->min.icmp.id) +
48 (id % range_size)); 48 (id % range_size));
49 if (!ip_nat_used_tuple(tuple, conntrack)) 49 if (!ip_nat_used_tuple(tuple, conntrack))
50 return 1; 50 return 1;
51 } 51 }
diff --git a/net/ipv4/netfilter/ip_nat_proto_tcp.c b/net/ipv4/netfilter/ip_nat_proto_tcp.c
index b586d18b3fb3..14ff24f53a7a 100644
--- a/net/ipv4/netfilter/ip_nat_proto_tcp.c
+++ b/net/ipv4/netfilter/ip_nat_proto_tcp.c
@@ -8,6 +8,7 @@
8 8
9#include <linux/types.h> 9#include <linux/types.h>
10#include <linux/init.h> 10#include <linux/init.h>
11#include <linux/random.h>
11#include <linux/netfilter.h> 12#include <linux/netfilter.h>
12#include <linux/ip.h> 13#include <linux/ip.h>
13#include <linux/tcp.h> 14#include <linux/tcp.h>
@@ -75,6 +76,10 @@ tcp_unique_tuple(struct ip_conntrack_tuple *tuple,
75 range_size = ntohs(range->max.tcp.port) - min + 1; 76 range_size = ntohs(range->max.tcp.port) - min + 1;
76 } 77 }
77 78
79 /* Start from random port to avoid prediction */
80 if (range->flags & IP_NAT_RANGE_PROTO_RANDOM)
81 port = net_random();
82
78 for (i = 0; i < range_size; i++, port++) { 83 for (i = 0; i < range_size; i++, port++) {
79 *portptr = htons(min + port % range_size); 84 *portptr = htons(min + port % range_size);
80 if (!ip_nat_used_tuple(tuple, conntrack)) { 85 if (!ip_nat_used_tuple(tuple, conntrack)) {
diff --git a/net/ipv4/netfilter/ip_nat_proto_udp.c b/net/ipv4/netfilter/ip_nat_proto_udp.c
index 5ced0877b32f..dfd521672891 100644
--- a/net/ipv4/netfilter/ip_nat_proto_udp.c
+++ b/net/ipv4/netfilter/ip_nat_proto_udp.c
@@ -8,6 +8,7 @@
8 8
9#include <linux/types.h> 9#include <linux/types.h>
10#include <linux/init.h> 10#include <linux/init.h>
11#include <linux/random.h>
11#include <linux/netfilter.h> 12#include <linux/netfilter.h>
12#include <linux/ip.h> 13#include <linux/ip.h>
13#include <linux/udp.h> 14#include <linux/udp.h>
@@ -74,6 +75,10 @@ udp_unique_tuple(struct ip_conntrack_tuple *tuple,
74 range_size = ntohs(range->max.udp.port) - min + 1; 75 range_size = ntohs(range->max.udp.port) - min + 1;
75 } 76 }
76 77
78 /* Start from random port to avoid prediction */
79 if (range->flags & IP_NAT_RANGE_PROTO_RANDOM)
80 port = net_random();
81
77 for (i = 0; i < range_size; i++, port++) { 82 for (i = 0; i < range_size; i++, port++) {
78 *portptr = htons(min + port % range_size); 83 *portptr = htons(min + port % range_size);
79 if (!ip_nat_used_tuple(tuple, conntrack)) 84 if (!ip_nat_used_tuple(tuple, conntrack))
diff --git a/net/ipv4/netfilter/ip_nat_rule.c b/net/ipv4/netfilter/ip_nat_rule.c
index a176aa3031e0..080eb1d92200 100644
--- a/net/ipv4/netfilter/ip_nat_rule.c
+++ b/net/ipv4/netfilter/ip_nat_rule.c
@@ -86,7 +86,7 @@ static struct
86 } 86 }
87}; 87};
88 88
89static struct ipt_table nat_table = { 89static struct xt_table nat_table = {
90 .name = "nat", 90 .name = "nat",
91 .valid_hooks = NAT_VALID_HOOKS, 91 .valid_hooks = NAT_VALID_HOOKS,
92 .lock = RW_LOCK_UNLOCKED, 92 .lock = RW_LOCK_UNLOCKED,
@@ -99,7 +99,7 @@ static unsigned int ipt_snat_target(struct sk_buff **pskb,
99 const struct net_device *in, 99 const struct net_device *in,
100 const struct net_device *out, 100 const struct net_device *out,
101 unsigned int hooknum, 101 unsigned int hooknum,
102 const struct ipt_target *target, 102 const struct xt_target *target,
103 const void *targinfo) 103 const void *targinfo)
104{ 104{
105 struct ip_conntrack *ct; 105 struct ip_conntrack *ct;
@@ -112,7 +112,7 @@ static unsigned int ipt_snat_target(struct sk_buff **pskb,
112 112
113 /* Connection must be valid and new. */ 113 /* Connection must be valid and new. */
114 IP_NF_ASSERT(ct && (ctinfo == IP_CT_NEW || ctinfo == IP_CT_RELATED 114 IP_NF_ASSERT(ct && (ctinfo == IP_CT_NEW || ctinfo == IP_CT_RELATED
115 || ctinfo == IP_CT_RELATED + IP_CT_IS_REPLY)); 115 || ctinfo == IP_CT_RELATED + IP_CT_IS_REPLY));
116 IP_NF_ASSERT(out); 116 IP_NF_ASSERT(out);
117 117
118 return ip_nat_setup_info(ct, &mr->range[0], hooknum); 118 return ip_nat_setup_info(ct, &mr->range[0], hooknum);
@@ -141,7 +141,7 @@ static unsigned int ipt_dnat_target(struct sk_buff **pskb,
141 const struct net_device *in, 141 const struct net_device *in,
142 const struct net_device *out, 142 const struct net_device *out,
143 unsigned int hooknum, 143 unsigned int hooknum,
144 const struct ipt_target *target, 144 const struct xt_target *target,
145 const void *targinfo) 145 const void *targinfo)
146{ 146{
147 struct ip_conntrack *ct; 147 struct ip_conntrack *ct;
@@ -166,7 +166,7 @@ static unsigned int ipt_dnat_target(struct sk_buff **pskb,
166 166
167static int ipt_snat_checkentry(const char *tablename, 167static int ipt_snat_checkentry(const char *tablename,
168 const void *entry, 168 const void *entry,
169 const struct ipt_target *target, 169 const struct xt_target *target,
170 void *targinfo, 170 void *targinfo,
171 unsigned int hook_mask) 171 unsigned int hook_mask)
172{ 172{
@@ -182,7 +182,7 @@ static int ipt_snat_checkentry(const char *tablename,
182 182
183static int ipt_dnat_checkentry(const char *tablename, 183static int ipt_dnat_checkentry(const char *tablename,
184 const void *entry, 184 const void *entry,
185 const struct ipt_target *target, 185 const struct xt_target *target,
186 void *targinfo, 186 void *targinfo,
187 unsigned int hook_mask) 187 unsigned int hook_mask)
188{ 188{
@@ -193,6 +193,10 @@ static int ipt_dnat_checkentry(const char *tablename,
193 printk("DNAT: multiple ranges no longer supported\n"); 193 printk("DNAT: multiple ranges no longer supported\n");
194 return 0; 194 return 0;
195 } 195 }
196 if (mr->range[0].flags & IP_NAT_RANGE_PROTO_RANDOM) {
197 printk("DNAT: port randomization not supported\n");
198 return 0;
199 }
196 return 1; 200 return 1;
197} 201}
198 202
@@ -219,8 +223,8 @@ alloc_null_binding(struct ip_conntrack *conntrack,
219 223
220unsigned int 224unsigned int
221alloc_null_binding_confirmed(struct ip_conntrack *conntrack, 225alloc_null_binding_confirmed(struct ip_conntrack *conntrack,
222 struct ip_nat_info *info, 226 struct ip_nat_info *info,
223 unsigned int hooknum) 227 unsigned int hooknum)
224{ 228{
225 __be32 ip 229 __be32 ip
226 = (HOOK2MANIP(hooknum) == IP_NAT_MANIP_SRC 230 = (HOOK2MANIP(hooknum) == IP_NAT_MANIP_SRC
@@ -257,8 +261,9 @@ int ip_nat_rule_find(struct sk_buff **pskb,
257 return ret; 261 return ret;
258} 262}
259 263
260static struct ipt_target ipt_snat_reg = { 264static struct xt_target ipt_snat_reg = {
261 .name = "SNAT", 265 .name = "SNAT",
266 .family = AF_INET,
262 .target = ipt_snat_target, 267 .target = ipt_snat_target,
263 .targetsize = sizeof(struct ip_nat_multi_range_compat), 268 .targetsize = sizeof(struct ip_nat_multi_range_compat),
264 .table = "nat", 269 .table = "nat",
@@ -266,8 +271,9 @@ static struct ipt_target ipt_snat_reg = {
266 .checkentry = ipt_snat_checkentry, 271 .checkentry = ipt_snat_checkentry,
267}; 272};
268 273
269static struct ipt_target ipt_dnat_reg = { 274static struct xt_target ipt_dnat_reg = {
270 .name = "DNAT", 275 .name = "DNAT",
276 .family = AF_INET,
271 .target = ipt_dnat_target, 277 .target = ipt_dnat_target,
272 .targetsize = sizeof(struct ip_nat_multi_range_compat), 278 .targetsize = sizeof(struct ip_nat_multi_range_compat),
273 .table = "nat", 279 .table = "nat",
@@ -282,27 +288,27 @@ int __init ip_nat_rule_init(void)
282 ret = ipt_register_table(&nat_table, &nat_initial_table.repl); 288 ret = ipt_register_table(&nat_table, &nat_initial_table.repl);
283 if (ret != 0) 289 if (ret != 0)
284 return ret; 290 return ret;
285 ret = ipt_register_target(&ipt_snat_reg); 291 ret = xt_register_target(&ipt_snat_reg);
286 if (ret != 0) 292 if (ret != 0)
287 goto unregister_table; 293 goto unregister_table;
288 294
289 ret = ipt_register_target(&ipt_dnat_reg); 295 ret = xt_register_target(&ipt_dnat_reg);
290 if (ret != 0) 296 if (ret != 0)
291 goto unregister_snat; 297 goto unregister_snat;
292 298
293 return ret; 299 return ret;
294 300
295 unregister_snat: 301 unregister_snat:
296 ipt_unregister_target(&ipt_snat_reg); 302 xt_unregister_target(&ipt_snat_reg);
297 unregister_table: 303 unregister_table:
298 ipt_unregister_table(&nat_table); 304 xt_unregister_table(&nat_table);
299 305
300 return ret; 306 return ret;
301} 307}
302 308
303void ip_nat_rule_cleanup(void) 309void ip_nat_rule_cleanup(void)
304{ 310{
305 ipt_unregister_target(&ipt_dnat_reg); 311 xt_unregister_target(&ipt_dnat_reg);
306 ipt_unregister_target(&ipt_snat_reg); 312 xt_unregister_target(&ipt_snat_reg);
307 ipt_unregister_table(&nat_table); 313 ipt_unregister_table(&nat_table);
308} 314}
diff --git a/net/ipv4/netfilter/ip_nat_sip.c b/net/ipv4/netfilter/ip_nat_sip.c
index 6223abc924ff..325c5a9dc2ef 100644
--- a/net/ipv4/netfilter/ip_nat_sip.c
+++ b/net/ipv4/netfilter/ip_nat_sip.c
@@ -88,7 +88,7 @@ static int map_sip_addr(struct sk_buff **pskb, enum ip_conntrack_info ctinfo,
88 return 1; 88 return 1;
89 89
90 if (!ip_nat_mangle_udp_packet(pskb, ct, ctinfo, 90 if (!ip_nat_mangle_udp_packet(pskb, ct, ctinfo,
91 matchoff, matchlen, addr, addrlen)) 91 matchoff, matchlen, addr, addrlen))
92 return 0; 92 return 0;
93 *dptr = (*pskb)->data + (*pskb)->nh.iph->ihl*4 + sizeof(struct udphdr); 93 *dptr = (*pskb)->data + (*pskb)->nh.iph->ihl*4 + sizeof(struct udphdr);
94 return 1; 94 return 1;
@@ -149,7 +149,7 @@ static unsigned int mangle_sip_packet(struct sk_buff **pskb,
149 return 0; 149 return 0;
150 150
151 if (!ip_nat_mangle_udp_packet(pskb, ct, ctinfo, 151 if (!ip_nat_mangle_udp_packet(pskb, ct, ctinfo,
152 matchoff, matchlen, buffer, bufflen)) 152 matchoff, matchlen, buffer, bufflen))
153 return 0; 153 return 0;
154 154
155 /* We need to reload this. Thanks Patrick. */ 155 /* We need to reload this. Thanks Patrick. */
@@ -170,7 +170,7 @@ static int mangle_content_len(struct sk_buff **pskb,
170 170
171 /* Get actual SDP lenght */ 171 /* Get actual SDP lenght */
172 if (ct_sip_get_info(dptr, (*pskb)->len - dataoff, &matchoff, 172 if (ct_sip_get_info(dptr, (*pskb)->len - dataoff, &matchoff,
173 &matchlen, POS_SDP_HEADER) > 0) { 173 &matchlen, POS_SDP_HEADER) > 0) {
174 174
175 /* since ct_sip_get_info() give us a pointer passing 'v=' 175 /* since ct_sip_get_info() give us a pointer passing 'v='
176 we need to add 2 bytes in this count. */ 176 we need to add 2 bytes in this count. */
@@ -178,7 +178,7 @@ static int mangle_content_len(struct sk_buff **pskb,
178 178
179 /* Now, update SDP lenght */ 179 /* Now, update SDP lenght */
180 if (ct_sip_get_info(dptr, (*pskb)->len - dataoff, &matchoff, 180 if (ct_sip_get_info(dptr, (*pskb)->len - dataoff, &matchoff,
181 &matchlen, POS_CONTENT) > 0) { 181 &matchlen, POS_CONTENT) > 0) {
182 182
183 bufflen = sprintf(buffer, "%u", c_len); 183 bufflen = sprintf(buffer, "%u", c_len);
184 184
@@ -204,17 +204,17 @@ static unsigned int mangle_sdp(struct sk_buff **pskb,
204 /* Mangle owner and contact info. */ 204 /* Mangle owner and contact info. */
205 bufflen = sprintf(buffer, "%u.%u.%u.%u", NIPQUAD(newip)); 205 bufflen = sprintf(buffer, "%u.%u.%u.%u", NIPQUAD(newip));
206 if (!mangle_sip_packet(pskb, ctinfo, ct, &dptr, (*pskb)->len - dataoff, 206 if (!mangle_sip_packet(pskb, ctinfo, ct, &dptr, (*pskb)->len - dataoff,
207 buffer, bufflen, POS_OWNER)) 207 buffer, bufflen, POS_OWNER))
208 return 0; 208 return 0;
209 209
210 if (!mangle_sip_packet(pskb, ctinfo, ct, &dptr, (*pskb)->len - dataoff, 210 if (!mangle_sip_packet(pskb, ctinfo, ct, &dptr, (*pskb)->len - dataoff,
211 buffer, bufflen, POS_CONNECTION)) 211 buffer, bufflen, POS_CONNECTION))
212 return 0; 212 return 0;
213 213
214 /* Mangle media port. */ 214 /* Mangle media port. */
215 bufflen = sprintf(buffer, "%u", port); 215 bufflen = sprintf(buffer, "%u", port);
216 if (!mangle_sip_packet(pskb, ctinfo, ct, &dptr, (*pskb)->len - dataoff, 216 if (!mangle_sip_packet(pskb, ctinfo, ct, &dptr, (*pskb)->len - dataoff,
217 buffer, bufflen, POS_MEDIA)) 217 buffer, bufflen, POS_MEDIA))
218 return 0; 218 return 0;
219 219
220 return mangle_content_len(pskb, ctinfo, ct, dptr); 220 return mangle_content_len(pskb, ctinfo, ct, dptr);
diff --git a/net/ipv4/netfilter/ip_nat_snmp_basic.c b/net/ipv4/netfilter/ip_nat_snmp_basic.c
index c3d9f3b090c4..e41d0efae515 100644
--- a/net/ipv4/netfilter/ip_nat_snmp_basic.c
+++ b/net/ipv4/netfilter/ip_nat_snmp_basic.c
@@ -3,11 +3,11 @@
3 * 3 *
4 * Basic SNMP Application Layer Gateway 4 * Basic SNMP Application Layer Gateway
5 * 5 *
6 * This IP NAT module is intended for use with SNMP network 6 * This IP NAT module is intended for use with SNMP network
7 * discovery and monitoring applications where target networks use 7 * discovery and monitoring applications where target networks use
8 * conflicting private address realms. 8 * conflicting private address realms.
9 * 9 *
10 * Static NAT is used to remap the networks from the view of the network 10 * Static NAT is used to remap the networks from the view of the network
11 * management system at the IP layer, and this module remaps some application 11 * management system at the IP layer, and this module remaps some application
12 * layer addresses to match. 12 * layer addresses to match.
13 * 13 *
@@ -20,7 +20,7 @@
20 * More information on ALG and associated issues can be found in 20 * More information on ALG and associated issues can be found in
21 * RFC 2962 21 * RFC 2962
22 * 22 *
23 * The ASB.1/BER parsing code is derived from the gxsnmp package by Gregory 23 * The ASB.1/BER parsing code is derived from the gxsnmp package by Gregory
24 * McLean & Jochen Friedrich, stripped down for use in the kernel. 24 * McLean & Jochen Friedrich, stripped down for use in the kernel.
25 * 25 *
26 * Copyright (c) 2000 RP Internet (www.rpi.net.au). 26 * Copyright (c) 2000 RP Internet (www.rpi.net.au).
@@ -69,8 +69,8 @@ MODULE_DESCRIPTION("Basic SNMP Application Layer Gateway");
69static int debug; 69static int debug;
70static DEFINE_SPINLOCK(snmp_lock); 70static DEFINE_SPINLOCK(snmp_lock);
71 71
72/* 72/*
73 * Application layer address mapping mimics the NAT mapping, but 73 * Application layer address mapping mimics the NAT mapping, but
74 * only for the first octet in this case (a more flexible system 74 * only for the first octet in this case (a more flexible system
75 * can be implemented if needed). 75 * can be implemented if needed).
76 */ 76 */
@@ -80,7 +80,7 @@ struct oct1_map
80 u_int8_t to; 80 u_int8_t to;
81}; 81};
82 82
83 83
84/***************************************************************************** 84/*****************************************************************************
85 * 85 *
86 * Basic ASN.1 decoding routines (gxsnmp author Dirk Wisse) 86 * Basic ASN.1 decoding routines (gxsnmp author Dirk Wisse)
@@ -129,7 +129,7 @@ struct oct1_map
129#define ASN1_ERR_DEC_LENGTH_MISMATCH 4 129#define ASN1_ERR_DEC_LENGTH_MISMATCH 4
130#define ASN1_ERR_DEC_BADVALUE 5 130#define ASN1_ERR_DEC_BADVALUE 5
131 131
132/* 132/*
133 * ASN.1 context. 133 * ASN.1 context.
134 */ 134 */
135struct asn1_ctx 135struct asn1_ctx
@@ -148,10 +148,10 @@ struct asn1_octstr
148 unsigned char *data; 148 unsigned char *data;
149 unsigned int len; 149 unsigned int len;
150}; 150};
151 151
152static void asn1_open(struct asn1_ctx *ctx, 152static void asn1_open(struct asn1_ctx *ctx,
153 unsigned char *buf, 153 unsigned char *buf,
154 unsigned int len) 154 unsigned int len)
155{ 155{
156 ctx->begin = buf; 156 ctx->begin = buf;
157 ctx->end = buf + len; 157 ctx->end = buf + len;
@@ -172,9 +172,9 @@ static unsigned char asn1_octet_decode(struct asn1_ctx *ctx, unsigned char *ch)
172static unsigned char asn1_tag_decode(struct asn1_ctx *ctx, unsigned int *tag) 172static unsigned char asn1_tag_decode(struct asn1_ctx *ctx, unsigned int *tag)
173{ 173{
174 unsigned char ch; 174 unsigned char ch;
175 175
176 *tag = 0; 176 *tag = 0;
177 177
178 do 178 do
179 { 179 {
180 if (!asn1_octet_decode(ctx, &ch)) 180 if (!asn1_octet_decode(ctx, &ch))
@@ -185,20 +185,20 @@ static unsigned char asn1_tag_decode(struct asn1_ctx *ctx, unsigned int *tag)
185 return 1; 185 return 1;
186} 186}
187 187
188static unsigned char asn1_id_decode(struct asn1_ctx *ctx, 188static unsigned char asn1_id_decode(struct asn1_ctx *ctx,
189 unsigned int *cls, 189 unsigned int *cls,
190 unsigned int *con, 190 unsigned int *con,
191 unsigned int *tag) 191 unsigned int *tag)
192{ 192{
193 unsigned char ch; 193 unsigned char ch;
194 194
195 if (!asn1_octet_decode(ctx, &ch)) 195 if (!asn1_octet_decode(ctx, &ch))
196 return 0; 196 return 0;
197 197
198 *cls = (ch & 0xC0) >> 6; 198 *cls = (ch & 0xC0) >> 6;
199 *con = (ch & 0x20) >> 5; 199 *con = (ch & 0x20) >> 5;
200 *tag = (ch & 0x1F); 200 *tag = (ch & 0x1F);
201 201
202 if (*tag == 0x1F) { 202 if (*tag == 0x1F) {
203 if (!asn1_tag_decode(ctx, tag)) 203 if (!asn1_tag_decode(ctx, tag))
204 return 0; 204 return 0;
@@ -207,25 +207,25 @@ static unsigned char asn1_id_decode(struct asn1_ctx *ctx,
207} 207}
208 208
209static unsigned char asn1_length_decode(struct asn1_ctx *ctx, 209static unsigned char asn1_length_decode(struct asn1_ctx *ctx,
210 unsigned int *def, 210 unsigned int *def,
211 unsigned int *len) 211 unsigned int *len)
212{ 212{
213 unsigned char ch, cnt; 213 unsigned char ch, cnt;
214 214
215 if (!asn1_octet_decode(ctx, &ch)) 215 if (!asn1_octet_decode(ctx, &ch))
216 return 0; 216 return 0;
217 217
218 if (ch == 0x80) 218 if (ch == 0x80)
219 *def = 0; 219 *def = 0;
220 else { 220 else {
221 *def = 1; 221 *def = 1;
222 222
223 if (ch < 0x80) 223 if (ch < 0x80)
224 *len = ch; 224 *len = ch;
225 else { 225 else {
226 cnt = (unsigned char) (ch & 0x7F); 226 cnt = (unsigned char) (ch & 0x7F);
227 *len = 0; 227 *len = 0;
228 228
229 while (cnt > 0) { 229 while (cnt > 0) {
230 if (!asn1_octet_decode(ctx, &ch)) 230 if (!asn1_octet_decode(ctx, &ch))
231 return 0; 231 return 0;
@@ -239,20 +239,20 @@ static unsigned char asn1_length_decode(struct asn1_ctx *ctx,
239} 239}
240 240
241static unsigned char asn1_header_decode(struct asn1_ctx *ctx, 241static unsigned char asn1_header_decode(struct asn1_ctx *ctx,
242 unsigned char **eoc, 242 unsigned char **eoc,
243 unsigned int *cls, 243 unsigned int *cls,
244 unsigned int *con, 244 unsigned int *con,
245 unsigned int *tag) 245 unsigned int *tag)
246{ 246{
247 unsigned int def, len; 247 unsigned int def, len;
248 248
249 if (!asn1_id_decode(ctx, cls, con, tag)) 249 if (!asn1_id_decode(ctx, cls, con, tag))
250 return 0; 250 return 0;
251 251
252 def = len = 0; 252 def = len = 0;
253 if (!asn1_length_decode(ctx, &def, &len)) 253 if (!asn1_length_decode(ctx, &def, &len))
254 return 0; 254 return 0;
255 255
256 if (def) 256 if (def)
257 *eoc = ctx->pointer + len; 257 *eoc = ctx->pointer + len;
258 else 258 else
@@ -263,19 +263,19 @@ static unsigned char asn1_header_decode(struct asn1_ctx *ctx,
263static unsigned char asn1_eoc_decode(struct asn1_ctx *ctx, unsigned char *eoc) 263static unsigned char asn1_eoc_decode(struct asn1_ctx *ctx, unsigned char *eoc)
264{ 264{
265 unsigned char ch; 265 unsigned char ch;
266 266
267 if (eoc == 0) { 267 if (eoc == 0) {
268 if (!asn1_octet_decode(ctx, &ch)) 268 if (!asn1_octet_decode(ctx, &ch))
269 return 0; 269 return 0;
270 270
271 if (ch != 0x00) { 271 if (ch != 0x00) {
272 ctx->error = ASN1_ERR_DEC_EOC_MISMATCH; 272 ctx->error = ASN1_ERR_DEC_EOC_MISMATCH;
273 return 0; 273 return 0;
274 } 274 }
275 275
276 if (!asn1_octet_decode(ctx, &ch)) 276 if (!asn1_octet_decode(ctx, &ch))
277 return 0; 277 return 0;
278 278
279 if (ch != 0x00) { 279 if (ch != 0x00) {
280 ctx->error = ASN1_ERR_DEC_EOC_MISMATCH; 280 ctx->error = ASN1_ERR_DEC_EOC_MISMATCH;
281 return 0; 281 return 0;
@@ -297,27 +297,27 @@ static unsigned char asn1_null_decode(struct asn1_ctx *ctx, unsigned char *eoc)
297} 297}
298 298
299static unsigned char asn1_long_decode(struct asn1_ctx *ctx, 299static unsigned char asn1_long_decode(struct asn1_ctx *ctx,
300 unsigned char *eoc, 300 unsigned char *eoc,
301 long *integer) 301 long *integer)
302{ 302{
303 unsigned char ch; 303 unsigned char ch;
304 unsigned int len; 304 unsigned int len;
305 305
306 if (!asn1_octet_decode(ctx, &ch)) 306 if (!asn1_octet_decode(ctx, &ch))
307 return 0; 307 return 0;
308 308
309 *integer = (signed char) ch; 309 *integer = (signed char) ch;
310 len = 1; 310 len = 1;
311 311
312 while (ctx->pointer < eoc) { 312 while (ctx->pointer < eoc) {
313 if (++len > sizeof (long)) { 313 if (++len > sizeof (long)) {
314 ctx->error = ASN1_ERR_DEC_BADVALUE; 314 ctx->error = ASN1_ERR_DEC_BADVALUE;
315 return 0; 315 return 0;
316 } 316 }
317 317
318 if (!asn1_octet_decode(ctx, &ch)) 318 if (!asn1_octet_decode(ctx, &ch))
319 return 0; 319 return 0;
320 320
321 *integer <<= 8; 321 *integer <<= 8;
322 *integer |= ch; 322 *integer |= ch;
323 } 323 }
@@ -325,28 +325,28 @@ static unsigned char asn1_long_decode(struct asn1_ctx *ctx,
325} 325}
326 326
327static unsigned char asn1_uint_decode(struct asn1_ctx *ctx, 327static unsigned char asn1_uint_decode(struct asn1_ctx *ctx,
328 unsigned char *eoc, 328 unsigned char *eoc,
329 unsigned int *integer) 329 unsigned int *integer)
330{ 330{
331 unsigned char ch; 331 unsigned char ch;
332 unsigned int len; 332 unsigned int len;
333 333
334 if (!asn1_octet_decode(ctx, &ch)) 334 if (!asn1_octet_decode(ctx, &ch))
335 return 0; 335 return 0;
336 336
337 *integer = ch; 337 *integer = ch;
338 if (ch == 0) len = 0; 338 if (ch == 0) len = 0;
339 else len = 1; 339 else len = 1;
340 340
341 while (ctx->pointer < eoc) { 341 while (ctx->pointer < eoc) {
342 if (++len > sizeof (unsigned int)) { 342 if (++len > sizeof (unsigned int)) {
343 ctx->error = ASN1_ERR_DEC_BADVALUE; 343 ctx->error = ASN1_ERR_DEC_BADVALUE;
344 return 0; 344 return 0;
345 } 345 }
346 346
347 if (!asn1_octet_decode(ctx, &ch)) 347 if (!asn1_octet_decode(ctx, &ch))
348 return 0; 348 return 0;
349 349
350 *integer <<= 8; 350 *integer <<= 8;
351 *integer |= ch; 351 *integer |= ch;
352 } 352 }
@@ -354,28 +354,28 @@ static unsigned char asn1_uint_decode(struct asn1_ctx *ctx,
354} 354}
355 355
356static unsigned char asn1_ulong_decode(struct asn1_ctx *ctx, 356static unsigned char asn1_ulong_decode(struct asn1_ctx *ctx,
357 unsigned char *eoc, 357 unsigned char *eoc,
358 unsigned long *integer) 358 unsigned long *integer)
359{ 359{
360 unsigned char ch; 360 unsigned char ch;
361 unsigned int len; 361 unsigned int len;
362 362
363 if (!asn1_octet_decode(ctx, &ch)) 363 if (!asn1_octet_decode(ctx, &ch))
364 return 0; 364 return 0;
365 365
366 *integer = ch; 366 *integer = ch;
367 if (ch == 0) len = 0; 367 if (ch == 0) len = 0;
368 else len = 1; 368 else len = 1;
369 369
370 while (ctx->pointer < eoc) { 370 while (ctx->pointer < eoc) {
371 if (++len > sizeof (unsigned long)) { 371 if (++len > sizeof (unsigned long)) {
372 ctx->error = ASN1_ERR_DEC_BADVALUE; 372 ctx->error = ASN1_ERR_DEC_BADVALUE;
373 return 0; 373 return 0;
374 } 374 }
375 375
376 if (!asn1_octet_decode(ctx, &ch)) 376 if (!asn1_octet_decode(ctx, &ch))
377 return 0; 377 return 0;
378 378
379 *integer <<= 8; 379 *integer <<= 8;
380 *integer |= ch; 380 *integer |= ch;
381 } 381 }
@@ -383,21 +383,21 @@ static unsigned char asn1_ulong_decode(struct asn1_ctx *ctx,
383} 383}
384 384
385static unsigned char asn1_octets_decode(struct asn1_ctx *ctx, 385static unsigned char asn1_octets_decode(struct asn1_ctx *ctx,
386 unsigned char *eoc, 386 unsigned char *eoc,
387 unsigned char **octets, 387 unsigned char **octets,
388 unsigned int *len) 388 unsigned int *len)
389{ 389{
390 unsigned char *ptr; 390 unsigned char *ptr;
391 391
392 *len = 0; 392 *len = 0;
393 393
394 *octets = kmalloc(eoc - ctx->pointer, GFP_ATOMIC); 394 *octets = kmalloc(eoc - ctx->pointer, GFP_ATOMIC);
395 if (*octets == NULL) { 395 if (*octets == NULL) {
396 if (net_ratelimit()) 396 if (net_ratelimit())
397 printk("OOM in bsalg (%d)\n", __LINE__); 397 printk("OOM in bsalg (%d)\n", __LINE__);
398 return 0; 398 return 0;
399 } 399 }
400 400
401 ptr = *octets; 401 ptr = *octets;
402 while (ctx->pointer < eoc) { 402 while (ctx->pointer < eoc) {
403 if (!asn1_octet_decode(ctx, (unsigned char *)ptr++)) { 403 if (!asn1_octet_decode(ctx, (unsigned char *)ptr++)) {
@@ -411,16 +411,16 @@ static unsigned char asn1_octets_decode(struct asn1_ctx *ctx,
411} 411}
412 412
413static unsigned char asn1_subid_decode(struct asn1_ctx *ctx, 413static unsigned char asn1_subid_decode(struct asn1_ctx *ctx,
414 unsigned long *subid) 414 unsigned long *subid)
415{ 415{
416 unsigned char ch; 416 unsigned char ch;
417 417
418 *subid = 0; 418 *subid = 0;
419 419
420 do { 420 do {
421 if (!asn1_octet_decode(ctx, &ch)) 421 if (!asn1_octet_decode(ctx, &ch))
422 return 0; 422 return 0;
423 423
424 *subid <<= 7; 424 *subid <<= 7;
425 *subid |= ch & 0x7F; 425 *subid |= ch & 0x7F;
426 } while ((ch & 0x80) == 0x80); 426 } while ((ch & 0x80) == 0x80);
@@ -428,14 +428,14 @@ static unsigned char asn1_subid_decode(struct asn1_ctx *ctx,
428} 428}
429 429
430static unsigned char asn1_oid_decode(struct asn1_ctx *ctx, 430static unsigned char asn1_oid_decode(struct asn1_ctx *ctx,
431 unsigned char *eoc, 431 unsigned char *eoc,
432 unsigned long **oid, 432 unsigned long **oid,
433 unsigned int *len) 433 unsigned int *len)
434{ 434{
435 unsigned long subid; 435 unsigned long subid;
436 unsigned int size; 436 unsigned int size;
437 unsigned long *optr; 437 unsigned long *optr;
438 438
439 size = eoc - ctx->pointer + 1; 439 size = eoc - ctx->pointer + 1;
440 *oid = kmalloc(size * sizeof(unsigned long), GFP_ATOMIC); 440 *oid = kmalloc(size * sizeof(unsigned long), GFP_ATOMIC);
441 if (*oid == NULL) { 441 if (*oid == NULL) {
@@ -443,15 +443,15 @@ static unsigned char asn1_oid_decode(struct asn1_ctx *ctx,
443 printk("OOM in bsalg (%d)\n", __LINE__); 443 printk("OOM in bsalg (%d)\n", __LINE__);
444 return 0; 444 return 0;
445 } 445 }
446 446
447 optr = *oid; 447 optr = *oid;
448 448
449 if (!asn1_subid_decode(ctx, &subid)) { 449 if (!asn1_subid_decode(ctx, &subid)) {
450 kfree(*oid); 450 kfree(*oid);
451 *oid = NULL; 451 *oid = NULL;
452 return 0; 452 return 0;
453 } 453 }
454 454
455 if (subid < 40) { 455 if (subid < 40) {
456 optr [0] = 0; 456 optr [0] = 0;
457 optr [1] = subid; 457 optr [1] = subid;
@@ -462,10 +462,10 @@ static unsigned char asn1_oid_decode(struct asn1_ctx *ctx,
462 optr [0] = 2; 462 optr [0] = 2;
463 optr [1] = subid - 80; 463 optr [1] = subid - 80;
464 } 464 }
465 465
466 *len = 2; 466 *len = 2;
467 optr += 2; 467 optr += 2;
468 468
469 while (ctx->pointer < eoc) { 469 while (ctx->pointer < eoc) {
470 if (++(*len) > size) { 470 if (++(*len) > size) {
471 ctx->error = ASN1_ERR_DEC_BADVALUE; 471 ctx->error = ASN1_ERR_DEC_BADVALUE;
@@ -473,7 +473,7 @@ static unsigned char asn1_oid_decode(struct asn1_ctx *ctx,
473 *oid = NULL; 473 *oid = NULL;
474 return 0; 474 return 0;
475 } 475 }
476 476
477 if (!asn1_subid_decode(ctx, optr++)) { 477 if (!asn1_subid_decode(ctx, optr++)) {
478 kfree(*oid); 478 kfree(*oid);
479 *oid = NULL; 479 *oid = NULL;
@@ -611,9 +611,9 @@ struct snmp_v1_trap
611#define SERR_EOM 2 611#define SERR_EOM 2
612 612
613static inline void mangle_address(unsigned char *begin, 613static inline void mangle_address(unsigned char *begin,
614 unsigned char *addr, 614 unsigned char *addr,
615 const struct oct1_map *map, 615 const struct oct1_map *map,
616 __sum16 *check); 616 __sum16 *check);
617struct snmp_cnv 617struct snmp_cnv
618{ 618{
619 unsigned int class; 619 unsigned int class;
@@ -633,7 +633,7 @@ static struct snmp_cnv snmp_conv [] =
633 {ASN1_APL, SNMP_GGE, SNMP_GAUGE}, /* Gauge32 == Unsigned32 */ 633 {ASN1_APL, SNMP_GGE, SNMP_GAUGE}, /* Gauge32 == Unsigned32 */
634 {ASN1_APL, SNMP_TIT, SNMP_TIMETICKS}, 634 {ASN1_APL, SNMP_TIT, SNMP_TIMETICKS},
635 {ASN1_APL, SNMP_OPQ, SNMP_OPAQUE}, 635 {ASN1_APL, SNMP_OPQ, SNMP_OPAQUE},
636 636
637 /* SNMPv2 data types and errors */ 637 /* SNMPv2 data types and errors */
638 {ASN1_UNI, ASN1_BTS, SNMP_BITSTR}, 638 {ASN1_UNI, ASN1_BTS, SNMP_BITSTR},
639 {ASN1_APL, SNMP_C64, SNMP_COUNTER64}, 639 {ASN1_APL, SNMP_C64, SNMP_COUNTER64},
@@ -644,13 +644,13 @@ static struct snmp_cnv snmp_conv [] =
644}; 644};
645 645
646static unsigned char snmp_tag_cls2syntax(unsigned int tag, 646static unsigned char snmp_tag_cls2syntax(unsigned int tag,
647 unsigned int cls, 647 unsigned int cls,
648 unsigned short *syntax) 648 unsigned short *syntax)
649{ 649{
650 struct snmp_cnv *cnv; 650 struct snmp_cnv *cnv;
651 651
652 cnv = snmp_conv; 652 cnv = snmp_conv;
653 653
654 while (cnv->syntax != -1) { 654 while (cnv->syntax != -1) {
655 if (cnv->tag == tag && cnv->class == cls) { 655 if (cnv->tag == tag && cnv->class == cls) {
656 *syntax = cnv->syntax; 656 *syntax = cnv->syntax;
@@ -662,7 +662,7 @@ static unsigned char snmp_tag_cls2syntax(unsigned int tag,
662} 662}
663 663
664static unsigned char snmp_object_decode(struct asn1_ctx *ctx, 664static unsigned char snmp_object_decode(struct asn1_ctx *ctx,
665 struct snmp_object **obj) 665 struct snmp_object **obj)
666{ 666{
667 unsigned int cls, con, tag, len, idlen; 667 unsigned int cls, con, tag, len, idlen;
668 unsigned short type; 668 unsigned short type;
@@ -670,41 +670,41 @@ static unsigned char snmp_object_decode(struct asn1_ctx *ctx,
670 unsigned long *lp, *id; 670 unsigned long *lp, *id;
671 unsigned long ul; 671 unsigned long ul;
672 long l; 672 long l;
673 673
674 *obj = NULL; 674 *obj = NULL;
675 id = NULL; 675 id = NULL;
676 676
677 if (!asn1_header_decode(ctx, &eoc, &cls, &con, &tag)) 677 if (!asn1_header_decode(ctx, &eoc, &cls, &con, &tag))
678 return 0; 678 return 0;
679 679
680 if (cls != ASN1_UNI || con != ASN1_CON || tag != ASN1_SEQ) 680 if (cls != ASN1_UNI || con != ASN1_CON || tag != ASN1_SEQ)
681 return 0; 681 return 0;
682 682
683 if (!asn1_header_decode(ctx, &end, &cls, &con, &tag)) 683 if (!asn1_header_decode(ctx, &end, &cls, &con, &tag))
684 return 0; 684 return 0;
685 685
686 if (cls != ASN1_UNI || con != ASN1_PRI || tag != ASN1_OJI) 686 if (cls != ASN1_UNI || con != ASN1_PRI || tag != ASN1_OJI)
687 return 0; 687 return 0;
688 688
689 if (!asn1_oid_decode(ctx, end, &id, &idlen)) 689 if (!asn1_oid_decode(ctx, end, &id, &idlen))
690 return 0; 690 return 0;
691 691
692 if (!asn1_header_decode(ctx, &end, &cls, &con, &tag)) { 692 if (!asn1_header_decode(ctx, &end, &cls, &con, &tag)) {
693 kfree(id); 693 kfree(id);
694 return 0; 694 return 0;
695 } 695 }
696 696
697 if (con != ASN1_PRI) { 697 if (con != ASN1_PRI) {
698 kfree(id); 698 kfree(id);
699 return 0; 699 return 0;
700 } 700 }
701 701
702 type = 0; 702 type = 0;
703 if (!snmp_tag_cls2syntax(tag, cls, &type)) { 703 if (!snmp_tag_cls2syntax(tag, cls, &type)) {
704 kfree(id); 704 kfree(id);
705 return 0; 705 return 0;
706 } 706 }
707 707
708 l = 0; 708 l = 0;
709 switch (type) { 709 switch (type) {
710 case SNMP_INTEGER: 710 case SNMP_INTEGER:
@@ -714,7 +714,7 @@ static unsigned char snmp_object_decode(struct asn1_ctx *ctx,
714 return 0; 714 return 0;
715 } 715 }
716 *obj = kmalloc(sizeof(struct snmp_object) + len, 716 *obj = kmalloc(sizeof(struct snmp_object) + len,
717 GFP_ATOMIC); 717 GFP_ATOMIC);
718 if (*obj == NULL) { 718 if (*obj == NULL) {
719 kfree(id); 719 kfree(id);
720 if (net_ratelimit()) 720 if (net_ratelimit())
@@ -730,7 +730,7 @@ static unsigned char snmp_object_decode(struct asn1_ctx *ctx,
730 return 0; 730 return 0;
731 } 731 }
732 *obj = kmalloc(sizeof(struct snmp_object) + len, 732 *obj = kmalloc(sizeof(struct snmp_object) + len,
733 GFP_ATOMIC); 733 GFP_ATOMIC);
734 if (*obj == NULL) { 734 if (*obj == NULL) {
735 kfree(id); 735 kfree(id);
736 if (net_ratelimit()) 736 if (net_ratelimit())
@@ -818,12 +818,12 @@ static unsigned char snmp_object_decode(struct asn1_ctx *ctx,
818 kfree(id); 818 kfree(id);
819 return 0; 819 return 0;
820 } 820 }
821 821
822 (*obj)->syntax_len = len; 822 (*obj)->syntax_len = len;
823 (*obj)->type = type; 823 (*obj)->type = type;
824 (*obj)->id = id; 824 (*obj)->id = id;
825 (*obj)->id_len = idlen; 825 (*obj)->id_len = idlen;
826 826
827 if (!asn1_eoc_decode(ctx, eoc)) { 827 if (!asn1_eoc_decode(ctx, eoc)) {
828 kfree(id); 828 kfree(id);
829 kfree(*obj); 829 kfree(*obj);
@@ -834,49 +834,49 @@ static unsigned char snmp_object_decode(struct asn1_ctx *ctx,
834} 834}
835 835
836static unsigned char snmp_request_decode(struct asn1_ctx *ctx, 836static unsigned char snmp_request_decode(struct asn1_ctx *ctx,
837 struct snmp_request *request) 837 struct snmp_request *request)
838{ 838{
839 unsigned int cls, con, tag; 839 unsigned int cls, con, tag;
840 unsigned char *end; 840 unsigned char *end;
841 841
842 if (!asn1_header_decode(ctx, &end, &cls, &con, &tag)) 842 if (!asn1_header_decode(ctx, &end, &cls, &con, &tag))
843 return 0; 843 return 0;
844 844
845 if (cls != ASN1_UNI || con != ASN1_PRI || tag != ASN1_INT) 845 if (cls != ASN1_UNI || con != ASN1_PRI || tag != ASN1_INT)
846 return 0; 846 return 0;
847 847
848 if (!asn1_ulong_decode(ctx, end, &request->id)) 848 if (!asn1_ulong_decode(ctx, end, &request->id))
849 return 0; 849 return 0;
850 850
851 if (!asn1_header_decode(ctx, &end, &cls, &con, &tag)) 851 if (!asn1_header_decode(ctx, &end, &cls, &con, &tag))
852 return 0; 852 return 0;
853 853
854 if (cls != ASN1_UNI || con != ASN1_PRI || tag != ASN1_INT) 854 if (cls != ASN1_UNI || con != ASN1_PRI || tag != ASN1_INT)
855 return 0; 855 return 0;
856 856
857 if (!asn1_uint_decode(ctx, end, &request->error_status)) 857 if (!asn1_uint_decode(ctx, end, &request->error_status))
858 return 0; 858 return 0;
859 859
860 if (!asn1_header_decode(ctx, &end, &cls, &con, &tag)) 860 if (!asn1_header_decode(ctx, &end, &cls, &con, &tag))
861 return 0; 861 return 0;
862 862
863 if (cls != ASN1_UNI || con != ASN1_PRI || tag != ASN1_INT) 863 if (cls != ASN1_UNI || con != ASN1_PRI || tag != ASN1_INT)
864 return 0; 864 return 0;
865 865
866 if (!asn1_uint_decode(ctx, end, &request->error_index)) 866 if (!asn1_uint_decode(ctx, end, &request->error_index))
867 return 0; 867 return 0;
868 868
869 return 1; 869 return 1;
870} 870}
871 871
872/* 872/*
873 * Fast checksum update for possibly oddly-aligned UDP byte, from the 873 * Fast checksum update for possibly oddly-aligned UDP byte, from the
874 * code example in the draft. 874 * code example in the draft.
875 */ 875 */
876static void fast_csum(__sum16 *csum, 876static void fast_csum(__sum16 *csum,
877 const unsigned char *optr, 877 const unsigned char *optr,
878 const unsigned char *nptr, 878 const unsigned char *nptr,
879 int offset) 879 int offset)
880{ 880{
881 unsigned char s[4]; 881 unsigned char s[4];
882 882
@@ -893,30 +893,30 @@ static void fast_csum(__sum16 *csum,
893 *csum = csum_fold(csum_partial(s, 4, ~csum_unfold(*csum))); 893 *csum = csum_fold(csum_partial(s, 4, ~csum_unfold(*csum)));
894} 894}
895 895
896/* 896/*
897 * Mangle IP address. 897 * Mangle IP address.
898 * - begin points to the start of the snmp messgae 898 * - begin points to the start of the snmp messgae
899 * - addr points to the start of the address 899 * - addr points to the start of the address
900 */ 900 */
901static inline void mangle_address(unsigned char *begin, 901static inline void mangle_address(unsigned char *begin,
902 unsigned char *addr, 902 unsigned char *addr,
903 const struct oct1_map *map, 903 const struct oct1_map *map,
904 __sum16 *check) 904 __sum16 *check)
905{ 905{
906 if (map->from == NOCT1(addr)) { 906 if (map->from == NOCT1(addr)) {
907 u_int32_t old; 907 u_int32_t old;
908 908
909 if (debug) 909 if (debug)
910 memcpy(&old, (unsigned char *)addr, sizeof(old)); 910 memcpy(&old, (unsigned char *)addr, sizeof(old));
911 911
912 *addr = map->to; 912 *addr = map->to;
913 913
914 /* Update UDP checksum if being used */ 914 /* Update UDP checksum if being used */
915 if (*check) { 915 if (*check) {
916 fast_csum(check, 916 fast_csum(check,
917 &map->from, &map->to, addr - begin); 917 &map->from, &map->to, addr - begin);
918 } 918 }
919 919
920 if (debug) 920 if (debug)
921 printk(KERN_DEBUG "bsalg: mapped %u.%u.%u.%u to " 921 printk(KERN_DEBUG "bsalg: mapped %u.%u.%u.%u to "
922 "%u.%u.%u.%u\n", NIPQUAD(old), NIPQUAD(*addr)); 922 "%u.%u.%u.%u\n", NIPQUAD(old), NIPQUAD(*addr));
@@ -924,66 +924,66 @@ static inline void mangle_address(unsigned char *begin,
924} 924}
925 925
926static unsigned char snmp_trap_decode(struct asn1_ctx *ctx, 926static unsigned char snmp_trap_decode(struct asn1_ctx *ctx,
927 struct snmp_v1_trap *trap, 927 struct snmp_v1_trap *trap,
928 const struct oct1_map *map, 928 const struct oct1_map *map,
929 __sum16 *check) 929 __sum16 *check)
930{ 930{
931 unsigned int cls, con, tag, len; 931 unsigned int cls, con, tag, len;
932 unsigned char *end; 932 unsigned char *end;
933 933
934 if (!asn1_header_decode(ctx, &end, &cls, &con, &tag)) 934 if (!asn1_header_decode(ctx, &end, &cls, &con, &tag))
935 return 0; 935 return 0;
936 936
937 if (cls != ASN1_UNI || con != ASN1_PRI || tag != ASN1_OJI) 937 if (cls != ASN1_UNI || con != ASN1_PRI || tag != ASN1_OJI)
938 return 0; 938 return 0;
939 939
940 if (!asn1_oid_decode(ctx, end, &trap->id, &trap->id_len)) 940 if (!asn1_oid_decode(ctx, end, &trap->id, &trap->id_len))
941 return 0; 941 return 0;
942 942
943 if (!asn1_header_decode(ctx, &end, &cls, &con, &tag)) 943 if (!asn1_header_decode(ctx, &end, &cls, &con, &tag))
944 goto err_id_free; 944 goto err_id_free;
945 945
946 if (!((cls == ASN1_APL && con == ASN1_PRI && tag == SNMP_IPA) || 946 if (!((cls == ASN1_APL && con == ASN1_PRI && tag == SNMP_IPA) ||
947 (cls == ASN1_UNI && con == ASN1_PRI && tag == ASN1_OTS))) 947 (cls == ASN1_UNI && con == ASN1_PRI && tag == ASN1_OTS)))
948 goto err_id_free; 948 goto err_id_free;
949 949
950 if (!asn1_octets_decode(ctx, end, (unsigned char **)&trap->ip_address, &len)) 950 if (!asn1_octets_decode(ctx, end, (unsigned char **)&trap->ip_address, &len))
951 goto err_id_free; 951 goto err_id_free;
952 952
953 /* IPv4 only */ 953 /* IPv4 only */
954 if (len != 4) 954 if (len != 4)
955 goto err_addr_free; 955 goto err_addr_free;
956 956
957 mangle_address(ctx->begin, ctx->pointer - 4, map, check); 957 mangle_address(ctx->begin, ctx->pointer - 4, map, check);
958 958
959 if (!asn1_header_decode(ctx, &end, &cls, &con, &tag)) 959 if (!asn1_header_decode(ctx, &end, &cls, &con, &tag))
960 goto err_addr_free; 960 goto err_addr_free;
961 961
962 if (cls != ASN1_UNI || con != ASN1_PRI || tag != ASN1_INT) 962 if (cls != ASN1_UNI || con != ASN1_PRI || tag != ASN1_INT)
963 goto err_addr_free; 963 goto err_addr_free;
964 964
965 if (!asn1_uint_decode(ctx, end, &trap->general)) 965 if (!asn1_uint_decode(ctx, end, &trap->general))
966 goto err_addr_free; 966 goto err_addr_free;
967 967
968 if (!asn1_header_decode(ctx, &end, &cls, &con, &tag)) 968 if (!asn1_header_decode(ctx, &end, &cls, &con, &tag))
969 goto err_addr_free; 969 goto err_addr_free;
970 970
971 if (cls != ASN1_UNI || con != ASN1_PRI || tag != ASN1_INT) 971 if (cls != ASN1_UNI || con != ASN1_PRI || tag != ASN1_INT)
972 goto err_addr_free; 972 goto err_addr_free;
973 973
974 if (!asn1_uint_decode(ctx, end, &trap->specific)) 974 if (!asn1_uint_decode(ctx, end, &trap->specific))
975 goto err_addr_free; 975 goto err_addr_free;
976 976
977 if (!asn1_header_decode(ctx, &end, &cls, &con, &tag)) 977 if (!asn1_header_decode(ctx, &end, &cls, &con, &tag))
978 goto err_addr_free; 978 goto err_addr_free;
979 979
980 if (!((cls == ASN1_APL && con == ASN1_PRI && tag == SNMP_TIT) || 980 if (!((cls == ASN1_APL && con == ASN1_PRI && tag == SNMP_TIT) ||
981 (cls == ASN1_UNI && con == ASN1_PRI && tag == ASN1_INT))) 981 (cls == ASN1_UNI && con == ASN1_PRI && tag == ASN1_INT)))
982 goto err_addr_free; 982 goto err_addr_free;
983 983
984 if (!asn1_ulong_decode(ctx, end, &trap->time)) 984 if (!asn1_ulong_decode(ctx, end, &trap->time))
985 goto err_addr_free; 985 goto err_addr_free;
986 986
987 return 1; 987 return 1;
988 988
989err_addr_free: 989err_addr_free:
@@ -1004,7 +1004,7 @@ err_id_free:
1004static void hex_dump(unsigned char *buf, size_t len) 1004static void hex_dump(unsigned char *buf, size_t len)
1005{ 1005{
1006 size_t i; 1006 size_t i;
1007 1007
1008 for (i = 0; i < len; i++) { 1008 for (i = 0; i < len; i++) {
1009 if (i && !(i % 16)) 1009 if (i && !(i % 16))
1010 printk("\n"); 1010 printk("\n");
@@ -1018,30 +1018,30 @@ static void hex_dump(unsigned char *buf, size_t len)
1018 * (And this is the fucking 'basic' method). 1018 * (And this is the fucking 'basic' method).
1019 */ 1019 */
1020static int snmp_parse_mangle(unsigned char *msg, 1020static int snmp_parse_mangle(unsigned char *msg,
1021 u_int16_t len, 1021 u_int16_t len,
1022 const struct oct1_map *map, 1022 const struct oct1_map *map,
1023 __sum16 *check) 1023 __sum16 *check)
1024{ 1024{
1025 unsigned char *eoc, *end; 1025 unsigned char *eoc, *end;
1026 unsigned int cls, con, tag, vers, pdutype; 1026 unsigned int cls, con, tag, vers, pdutype;
1027 struct asn1_ctx ctx; 1027 struct asn1_ctx ctx;
1028 struct asn1_octstr comm; 1028 struct asn1_octstr comm;
1029 struct snmp_object **obj; 1029 struct snmp_object **obj;
1030 1030
1031 if (debug > 1) 1031 if (debug > 1)
1032 hex_dump(msg, len); 1032 hex_dump(msg, len);
1033 1033
1034 asn1_open(&ctx, msg, len); 1034 asn1_open(&ctx, msg, len);
1035 1035
1036 /* 1036 /*
1037 * Start of SNMP message. 1037 * Start of SNMP message.
1038 */ 1038 */
1039 if (!asn1_header_decode(&ctx, &eoc, &cls, &con, &tag)) 1039 if (!asn1_header_decode(&ctx, &eoc, &cls, &con, &tag))
1040 return 0; 1040 return 0;
1041 if (cls != ASN1_UNI || con != ASN1_CON || tag != ASN1_SEQ) 1041 if (cls != ASN1_UNI || con != ASN1_CON || tag != ASN1_SEQ)
1042 return 0; 1042 return 0;
1043 1043
1044 /* 1044 /*
1045 * Version 1 or 2 handled. 1045 * Version 1 or 2 handled.
1046 */ 1046 */
1047 if (!asn1_header_decode(&ctx, &end, &cls, &con, &tag)) 1047 if (!asn1_header_decode(&ctx, &end, &cls, &con, &tag))
@@ -1054,7 +1054,7 @@ static int snmp_parse_mangle(unsigned char *msg,
1054 printk(KERN_DEBUG "bsalg: snmp version: %u\n", vers + 1); 1054 printk(KERN_DEBUG "bsalg: snmp version: %u\n", vers + 1);
1055 if (vers > 1) 1055 if (vers > 1)
1056 return 1; 1056 return 1;
1057 1057
1058 /* 1058 /*
1059 * Community. 1059 * Community.
1060 */ 1060 */
@@ -1066,14 +1066,14 @@ static int snmp_parse_mangle(unsigned char *msg,
1066 return 0; 1066 return 0;
1067 if (debug > 1) { 1067 if (debug > 1) {
1068 unsigned int i; 1068 unsigned int i;
1069 1069
1070 printk(KERN_DEBUG "bsalg: community: "); 1070 printk(KERN_DEBUG "bsalg: community: ");
1071 for (i = 0; i < comm.len; i++) 1071 for (i = 0; i < comm.len; i++)
1072 printk("%c", comm.data[i]); 1072 printk("%c", comm.data[i]);
1073 printk("\n"); 1073 printk("\n");
1074 } 1074 }
1075 kfree(comm.data); 1075 kfree(comm.data);
1076 1076
1077 /* 1077 /*
1078 * PDU type 1078 * PDU type
1079 */ 1079 */
@@ -1092,7 +1092,7 @@ static int snmp_parse_mangle(unsigned char *msg,
1092 [SNMP_PDU_INFORM] = "inform", 1092 [SNMP_PDU_INFORM] = "inform",
1093 [SNMP_PDU_TRAP2] = "trapv2" 1093 [SNMP_PDU_TRAP2] = "trapv2"
1094 }; 1094 };
1095 1095
1096 if (pdutype > SNMP_PDU_TRAP2) 1096 if (pdutype > SNMP_PDU_TRAP2)
1097 printk(KERN_DEBUG "bsalg: bad pdu type %u\n", pdutype); 1097 printk(KERN_DEBUG "bsalg: bad pdu type %u\n", pdutype);
1098 else 1098 else
@@ -1101,56 +1101,56 @@ static int snmp_parse_mangle(unsigned char *msg,
1101 if (pdutype != SNMP_PDU_RESPONSE && 1101 if (pdutype != SNMP_PDU_RESPONSE &&
1102 pdutype != SNMP_PDU_TRAP1 && pdutype != SNMP_PDU_TRAP2) 1102 pdutype != SNMP_PDU_TRAP1 && pdutype != SNMP_PDU_TRAP2)
1103 return 1; 1103 return 1;
1104 1104
1105 /* 1105 /*
1106 * Request header or v1 trap 1106 * Request header or v1 trap
1107 */ 1107 */
1108 if (pdutype == SNMP_PDU_TRAP1) { 1108 if (pdutype == SNMP_PDU_TRAP1) {
1109 struct snmp_v1_trap trap; 1109 struct snmp_v1_trap trap;
1110 unsigned char ret = snmp_trap_decode(&ctx, &trap, map, check); 1110 unsigned char ret = snmp_trap_decode(&ctx, &trap, map, check);
1111 1111
1112 if (ret) { 1112 if (ret) {
1113 kfree(trap.id); 1113 kfree(trap.id);
1114 kfree((unsigned long *)trap.ip_address); 1114 kfree((unsigned long *)trap.ip_address);
1115 } else 1115 } else
1116 return ret; 1116 return ret;
1117 1117
1118 } else { 1118 } else {
1119 struct snmp_request req; 1119 struct snmp_request req;
1120 1120
1121 if (!snmp_request_decode(&ctx, &req)) 1121 if (!snmp_request_decode(&ctx, &req))
1122 return 0; 1122 return 0;
1123 1123
1124 if (debug > 1) 1124 if (debug > 1)
1125 printk(KERN_DEBUG "bsalg: request: id=0x%lx error_status=%u " 1125 printk(KERN_DEBUG "bsalg: request: id=0x%lx error_status=%u "
1126 "error_index=%u\n", req.id, req.error_status, 1126 "error_index=%u\n", req.id, req.error_status,
1127 req.error_index); 1127 req.error_index);
1128 } 1128 }
1129 1129
1130 /* 1130 /*
1131 * Loop through objects, look for IP addresses to mangle. 1131 * Loop through objects, look for IP addresses to mangle.
1132 */ 1132 */
1133 if (!asn1_header_decode(&ctx, &eoc, &cls, &con, &tag)) 1133 if (!asn1_header_decode(&ctx, &eoc, &cls, &con, &tag))
1134 return 0; 1134 return 0;
1135 1135
1136 if (cls != ASN1_UNI || con != ASN1_CON || tag != ASN1_SEQ) 1136 if (cls != ASN1_UNI || con != ASN1_CON || tag != ASN1_SEQ)
1137 return 0; 1137 return 0;
1138 1138
1139 obj = kmalloc(sizeof(struct snmp_object), GFP_ATOMIC); 1139 obj = kmalloc(sizeof(struct snmp_object), GFP_ATOMIC);
1140 if (obj == NULL) { 1140 if (obj == NULL) {
1141 if (net_ratelimit()) 1141 if (net_ratelimit())
1142 printk(KERN_WARNING "OOM in bsalg(%d)\n", __LINE__); 1142 printk(KERN_WARNING "OOM in bsalg(%d)\n", __LINE__);
1143 return 0; 1143 return 0;
1144 } 1144 }
1145 1145
1146 while (!asn1_eoc_decode(&ctx, eoc)) { 1146 while (!asn1_eoc_decode(&ctx, eoc)) {
1147 unsigned int i; 1147 unsigned int i;
1148 1148
1149 if (!snmp_object_decode(&ctx, obj)) { 1149 if (!snmp_object_decode(&ctx, obj)) {
1150 if (*obj) { 1150 if (*obj) {
1151 kfree((*obj)->id); 1151 kfree((*obj)->id);
1152 kfree(*obj); 1152 kfree(*obj);
1153 } 1153 }
1154 kfree(obj); 1154 kfree(obj);
1155 return 0; 1155 return 0;
1156 } 1156 }
@@ -1163,20 +1163,20 @@ static int snmp_parse_mangle(unsigned char *msg,
1163 printk("%lu", (*obj)->id[i]); 1163 printk("%lu", (*obj)->id[i]);
1164 } 1164 }
1165 printk(": type=%u\n", (*obj)->type); 1165 printk(": type=%u\n", (*obj)->type);
1166 1166
1167 } 1167 }
1168 1168
1169 if ((*obj)->type == SNMP_IPADDR) 1169 if ((*obj)->type == SNMP_IPADDR)
1170 mangle_address(ctx.begin, ctx.pointer - 4 , map, check); 1170 mangle_address(ctx.begin, ctx.pointer - 4 , map, check);
1171 1171
1172 kfree((*obj)->id); 1172 kfree((*obj)->id);
1173 kfree(*obj); 1173 kfree(*obj);
1174 } 1174 }
1175 kfree(obj); 1175 kfree(obj);
1176 1176
1177 if (!asn1_eoc_decode(&ctx, eoc)) 1177 if (!asn1_eoc_decode(&ctx, eoc))
1178 return 0; 1178 return 0;
1179 1179
1180 return 1; 1180 return 1;
1181} 1181}
1182 1182
@@ -1186,12 +1186,12 @@ static int snmp_parse_mangle(unsigned char *msg,
1186 * 1186 *
1187 *****************************************************************************/ 1187 *****************************************************************************/
1188 1188
1189/* 1189/*
1190 * SNMP translation routine. 1190 * SNMP translation routine.
1191 */ 1191 */
1192static int snmp_translate(struct ip_conntrack *ct, 1192static int snmp_translate(struct ip_conntrack *ct,
1193 enum ip_conntrack_info ctinfo, 1193 enum ip_conntrack_info ctinfo,
1194 struct sk_buff **pskb) 1194 struct sk_buff **pskb)
1195{ 1195{
1196 struct iphdr *iph = (*pskb)->nh.iph; 1196 struct iphdr *iph = (*pskb)->nh.iph;
1197 struct udphdr *udph = (struct udphdr *)((__be32 *)iph + iph->ihl); 1197 struct udphdr *udph = (struct udphdr *)((__be32 *)iph + iph->ihl);
@@ -1213,12 +1213,12 @@ static int snmp_translate(struct ip_conntrack *ct,
1213 map.from = NOCT1(&ct->tuplehash[IP_CT_DIR_REPLY].tuple.src.ip); 1213 map.from = NOCT1(&ct->tuplehash[IP_CT_DIR_REPLY].tuple.src.ip);
1214 map.to = NOCT1(&ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.ip); 1214 map.to = NOCT1(&ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.ip);
1215 } 1215 }
1216 1216
1217 if (map.from == map.to) 1217 if (map.from == map.to)
1218 return NF_ACCEPT; 1218 return NF_ACCEPT;
1219 1219
1220 if (!snmp_parse_mangle((unsigned char *)udph + sizeof(struct udphdr), 1220 if (!snmp_parse_mangle((unsigned char *)udph + sizeof(struct udphdr),
1221 paylen, &map, &udph->check)) { 1221 paylen, &map, &udph->check)) {
1222 if (net_ratelimit()) 1222 if (net_ratelimit())
1223 printk(KERN_WARNING "bsalg: parser failed\n"); 1223 printk(KERN_WARNING "bsalg: parser failed\n");
1224 return NF_DROP; 1224 return NF_DROP;
@@ -1247,7 +1247,7 @@ static int help(struct sk_buff **pskb,
1247 if (!(ct->status & IPS_NAT_MASK)) 1247 if (!(ct->status & IPS_NAT_MASK))
1248 return NF_ACCEPT; 1248 return NF_ACCEPT;
1249 1249
1250 /* 1250 /*
1251 * Make sure the packet length is ok. So far, we were only guaranteed 1251 * Make sure the packet length is ok. So far, we were only guaranteed
1252 * to have a valid length IP header plus 8 bytes, which means we have 1252 * to have a valid length IP header plus 8 bytes, which means we have
1253 * enough room for a UDP header. Just verify the UDP length field so we 1253 * enough room for a UDP header. Just verify the UDP length field so we
@@ -1305,7 +1305,7 @@ static struct ip_conntrack_helper snmp_trap_helper = {
1305 * Module stuff. 1305 * Module stuff.
1306 * 1306 *
1307 *****************************************************************************/ 1307 *****************************************************************************/
1308 1308
1309static int __init ip_nat_snmp_basic_init(void) 1309static int __init ip_nat_snmp_basic_init(void)
1310{ 1310{
1311 int ret = 0; 1311 int ret = 0;
diff --git a/net/ipv4/netfilter/ip_nat_standalone.c b/net/ipv4/netfilter/ip_nat_standalone.c
index ad66328baa5d..adf25f9f70e1 100644
--- a/net/ipv4/netfilter/ip_nat_standalone.c
+++ b/net/ipv4/netfilter/ip_nat_standalone.c
@@ -81,7 +81,7 @@ static void nat_decode_session(struct sk_buff *skb, struct flowi *fl)
81 } 81 }
82} 82}
83#endif 83#endif
84 84
85static unsigned int 85static unsigned int
86ip_nat_fn(unsigned int hooknum, 86ip_nat_fn(unsigned int hooknum,
87 struct sk_buff **pskb, 87 struct sk_buff **pskb,
@@ -107,8 +107,8 @@ ip_nat_fn(unsigned int hooknum,
107 protocol. 8) --RR */ 107 protocol. 8) --RR */
108 if (!ct) { 108 if (!ct) {
109 /* Exception: ICMP redirect to new connection (not in 109 /* Exception: ICMP redirect to new connection (not in
110 hash table yet). We must not let this through, in 110 hash table yet). We must not let this through, in
111 case we're doing NAT to the same network. */ 111 case we're doing NAT to the same network. */
112 if ((*pskb)->nh.iph->protocol == IPPROTO_ICMP) { 112 if ((*pskb)->nh.iph->protocol == IPPROTO_ICMP) {
113 struct icmphdr _hdr, *hp; 113 struct icmphdr _hdr, *hp;
114 114
@@ -148,7 +148,7 @@ ip_nat_fn(unsigned int hooknum,
148 if (unlikely(is_confirmed(ct))) 148 if (unlikely(is_confirmed(ct)))
149 /* NAT module was loaded late */ 149 /* NAT module was loaded late */
150 ret = alloc_null_binding_confirmed(ct, info, 150 ret = alloc_null_binding_confirmed(ct, info,
151 hooknum); 151 hooknum);
152 else if (hooknum == NF_IP_LOCAL_IN) 152 else if (hooknum == NF_IP_LOCAL_IN)
153 /* LOCAL_IN hook doesn't have a chain! */ 153 /* LOCAL_IN hook doesn't have a chain! */
154 ret = alloc_null_binding(ct, info, hooknum); 154 ret = alloc_null_binding(ct, info, hooknum);
@@ -179,10 +179,10 @@ ip_nat_fn(unsigned int hooknum,
179 179
180static unsigned int 180static unsigned int
181ip_nat_in(unsigned int hooknum, 181ip_nat_in(unsigned int hooknum,
182 struct sk_buff **pskb, 182 struct sk_buff **pskb,
183 const struct net_device *in, 183 const struct net_device *in,
184 const struct net_device *out, 184 const struct net_device *out,
185 int (*okfn)(struct sk_buff *)) 185 int (*okfn)(struct sk_buff *))
186{ 186{
187 unsigned int ret; 187 unsigned int ret;
188 __be32 daddr = (*pskb)->nh.iph->daddr; 188 __be32 daddr = (*pskb)->nh.iph->daddr;
@@ -277,9 +277,9 @@ ip_nat_adjust(unsigned int hooknum,
277 277
278 ct = ip_conntrack_get(*pskb, &ctinfo); 278 ct = ip_conntrack_get(*pskb, &ctinfo);
279 if (ct && test_bit(IPS_SEQ_ADJUST_BIT, &ct->status)) { 279 if (ct && test_bit(IPS_SEQ_ADJUST_BIT, &ct->status)) {
280 DEBUGP("ip_nat_standalone: adjusting sequence number\n"); 280 DEBUGP("ip_nat_standalone: adjusting sequence number\n");
281 if (!ip_nat_seq_adjust(pskb, ct, ctinfo)) 281 if (!ip_nat_seq_adjust(pskb, ct, ctinfo))
282 return NF_DROP; 282 return NF_DROP;
283 } 283 }
284 return NF_ACCEPT; 284 return NF_ACCEPT;
285} 285}
diff --git a/net/ipv4/netfilter/ip_queue.c b/net/ipv4/netfilter/ip_queue.c
index cd520df4dcf4..68bf19f3b01c 100644
--- a/net/ipv4/netfilter/ip_queue.c
+++ b/net/ipv4/netfilter/ip_queue.c
@@ -11,13 +11,13 @@
11 * 11 *
12 * 2000-03-27: Simplified code (thanks to Andi Kleen for clues). 12 * 2000-03-27: Simplified code (thanks to Andi Kleen for clues).
13 * 2000-05-20: Fixed notifier problems (following Miguel Freitas' report). 13 * 2000-05-20: Fixed notifier problems (following Miguel Freitas' report).
14 * 2000-06-19: Fixed so nfmark is copied to metadata (reported by Sebastian 14 * 2000-06-19: Fixed so nfmark is copied to metadata (reported by Sebastian
15 * Zander). 15 * Zander).
16 * 2000-08-01: Added Nick Williams' MAC support. 16 * 2000-08-01: Added Nick Williams' MAC support.
17 * 2002-06-25: Code cleanup. 17 * 2002-06-25: Code cleanup.
18 * 2005-01-10: Added /proc counter for dropped packets; fixed so 18 * 2005-01-10: Added /proc counter for dropped packets; fixed so
19 * packets aren't delivered to user space if they're going 19 * packets aren't delivered to user space if they're going
20 * to be dropped. 20 * to be dropped.
21 * 2005-05-26: local_bh_{disable,enable} around nf_reinject (Harald Welte) 21 * 2005-05-26: local_bh_{disable,enable} around nf_reinject (Harald Welte)
22 * 22 *
23 */ 23 */
@@ -97,7 +97,7 @@ __ipq_find_entry(ipq_cmpfn cmpfn, unsigned long data)
97 97
98 list_for_each_prev(p, &queue_list) { 98 list_for_each_prev(p, &queue_list) {
99 struct ipq_queue_entry *entry = (struct ipq_queue_entry *)p; 99 struct ipq_queue_entry *entry = (struct ipq_queue_entry *)p;
100 100
101 if (!cmpfn || cmpfn(entry, data)) 101 if (!cmpfn || cmpfn(entry, data))
102 return entry; 102 return entry;
103 } 103 }
@@ -129,7 +129,7 @@ static inline void
129__ipq_flush(int verdict) 129__ipq_flush(int verdict)
130{ 130{
131 struct ipq_queue_entry *entry; 131 struct ipq_queue_entry *entry;
132 132
133 while ((entry = __ipq_find_dequeue_entry(NULL, 0))) 133 while ((entry = __ipq_find_dequeue_entry(NULL, 0)))
134 ipq_issue_verdict(entry, verdict); 134 ipq_issue_verdict(entry, verdict);
135} 135}
@@ -138,21 +138,21 @@ static inline int
138__ipq_set_mode(unsigned char mode, unsigned int range) 138__ipq_set_mode(unsigned char mode, unsigned int range)
139{ 139{
140 int status = 0; 140 int status = 0;
141 141
142 switch(mode) { 142 switch(mode) {
143 case IPQ_COPY_NONE: 143 case IPQ_COPY_NONE:
144 case IPQ_COPY_META: 144 case IPQ_COPY_META:
145 copy_mode = mode; 145 copy_mode = mode;
146 copy_range = 0; 146 copy_range = 0;
147 break; 147 break;
148 148
149 case IPQ_COPY_PACKET: 149 case IPQ_COPY_PACKET:
150 copy_mode = mode; 150 copy_mode = mode;
151 copy_range = range; 151 copy_range = range;
152 if (copy_range > 0xFFFF) 152 if (copy_range > 0xFFFF)
153 copy_range = 0xFFFF; 153 copy_range = 0xFFFF;
154 break; 154 break;
155 155
156 default: 156 default:
157 status = -EINVAL; 157 status = -EINVAL;
158 158
@@ -173,7 +173,7 @@ static struct ipq_queue_entry *
173ipq_find_dequeue_entry(ipq_cmpfn cmpfn, unsigned long data) 173ipq_find_dequeue_entry(ipq_cmpfn cmpfn, unsigned long data)
174{ 174{
175 struct ipq_queue_entry *entry; 175 struct ipq_queue_entry *entry;
176 176
177 write_lock_bh(&queue_lock); 177 write_lock_bh(&queue_lock);
178 entry = __ipq_find_dequeue_entry(cmpfn, data); 178 entry = __ipq_find_dequeue_entry(cmpfn, data);
179 write_unlock_bh(&queue_lock); 179 write_unlock_bh(&queue_lock);
@@ -199,14 +199,14 @@ ipq_build_packet_message(struct ipq_queue_entry *entry, int *errp)
199 struct nlmsghdr *nlh; 199 struct nlmsghdr *nlh;
200 200
201 read_lock_bh(&queue_lock); 201 read_lock_bh(&queue_lock);
202 202
203 switch (copy_mode) { 203 switch (copy_mode) {
204 case IPQ_COPY_META: 204 case IPQ_COPY_META:
205 case IPQ_COPY_NONE: 205 case IPQ_COPY_NONE:
206 size = NLMSG_SPACE(sizeof(*pmsg)); 206 size = NLMSG_SPACE(sizeof(*pmsg));
207 data_len = 0; 207 data_len = 0;
208 break; 208 break;
209 209
210 case IPQ_COPY_PACKET: 210 case IPQ_COPY_PACKET:
211 if ((entry->skb->ip_summed == CHECKSUM_PARTIAL || 211 if ((entry->skb->ip_summed == CHECKSUM_PARTIAL ||
212 entry->skb->ip_summed == CHECKSUM_COMPLETE) && 212 entry->skb->ip_summed == CHECKSUM_COMPLETE) &&
@@ -218,10 +218,10 @@ ipq_build_packet_message(struct ipq_queue_entry *entry, int *errp)
218 data_len = entry->skb->len; 218 data_len = entry->skb->len;
219 else 219 else
220 data_len = copy_range; 220 data_len = copy_range;
221 221
222 size = NLMSG_SPACE(sizeof(*pmsg) + data_len); 222 size = NLMSG_SPACE(sizeof(*pmsg) + data_len);
223 break; 223 break;
224 224
225 default: 225 default:
226 *errp = -EINVAL; 226 *errp = -EINVAL;
227 read_unlock_bh(&queue_lock); 227 read_unlock_bh(&queue_lock);
@@ -233,7 +233,7 @@ ipq_build_packet_message(struct ipq_queue_entry *entry, int *errp)
233 skb = alloc_skb(size, GFP_ATOMIC); 233 skb = alloc_skb(size, GFP_ATOMIC);
234 if (!skb) 234 if (!skb)
235 goto nlmsg_failure; 235 goto nlmsg_failure;
236 236
237 old_tail= skb->tail; 237 old_tail= skb->tail;
238 nlh = NLMSG_PUT(skb, 0, 0, IPQM_PACKET, size - sizeof(*nlh)); 238 nlh = NLMSG_PUT(skb, 0, 0, IPQM_PACKET, size - sizeof(*nlh));
239 pmsg = NLMSG_DATA(nlh); 239 pmsg = NLMSG_DATA(nlh);
@@ -246,29 +246,29 @@ ipq_build_packet_message(struct ipq_queue_entry *entry, int *errp)
246 pmsg->mark = entry->skb->mark; 246 pmsg->mark = entry->skb->mark;
247 pmsg->hook = entry->info->hook; 247 pmsg->hook = entry->info->hook;
248 pmsg->hw_protocol = entry->skb->protocol; 248 pmsg->hw_protocol = entry->skb->protocol;
249 249
250 if (entry->info->indev) 250 if (entry->info->indev)
251 strcpy(pmsg->indev_name, entry->info->indev->name); 251 strcpy(pmsg->indev_name, entry->info->indev->name);
252 else 252 else
253 pmsg->indev_name[0] = '\0'; 253 pmsg->indev_name[0] = '\0';
254 254
255 if (entry->info->outdev) 255 if (entry->info->outdev)
256 strcpy(pmsg->outdev_name, entry->info->outdev->name); 256 strcpy(pmsg->outdev_name, entry->info->outdev->name);
257 else 257 else
258 pmsg->outdev_name[0] = '\0'; 258 pmsg->outdev_name[0] = '\0';
259 259
260 if (entry->info->indev && entry->skb->dev) { 260 if (entry->info->indev && entry->skb->dev) {
261 pmsg->hw_type = entry->skb->dev->type; 261 pmsg->hw_type = entry->skb->dev->type;
262 if (entry->skb->dev->hard_header_parse) 262 if (entry->skb->dev->hard_header_parse)
263 pmsg->hw_addrlen = 263 pmsg->hw_addrlen =
264 entry->skb->dev->hard_header_parse(entry->skb, 264 entry->skb->dev->hard_header_parse(entry->skb,
265 pmsg->hw_addr); 265 pmsg->hw_addr);
266 } 266 }
267 267
268 if (data_len) 268 if (data_len)
269 if (skb_copy_bits(entry->skb, 0, pmsg->payload, data_len)) 269 if (skb_copy_bits(entry->skb, 0, pmsg->payload, data_len))
270 BUG(); 270 BUG();
271 271
272 nlh->nlmsg_len = skb->tail - old_tail; 272 nlh->nlmsg_len = skb->tail - old_tail;
273 return skb; 273 return skb;
274 274
@@ -303,26 +303,26 @@ ipq_enqueue_packet(struct sk_buff *skb, struct nf_info *info,
303 nskb = ipq_build_packet_message(entry, &status); 303 nskb = ipq_build_packet_message(entry, &status);
304 if (nskb == NULL) 304 if (nskb == NULL)
305 goto err_out_free; 305 goto err_out_free;
306 306
307 write_lock_bh(&queue_lock); 307 write_lock_bh(&queue_lock);
308 308
309 if (!peer_pid) 309 if (!peer_pid)
310 goto err_out_free_nskb; 310 goto err_out_free_nskb;
311 311
312 if (queue_total >= queue_maxlen) { 312 if (queue_total >= queue_maxlen) {
313 queue_dropped++; 313 queue_dropped++;
314 status = -ENOSPC; 314 status = -ENOSPC;
315 if (net_ratelimit()) 315 if (net_ratelimit())
316 printk (KERN_WARNING "ip_queue: full at %d entries, " 316 printk (KERN_WARNING "ip_queue: full at %d entries, "
317 "dropping packets(s). Dropped: %d\n", queue_total, 317 "dropping packets(s). Dropped: %d\n", queue_total,
318 queue_dropped); 318 queue_dropped);
319 goto err_out_free_nskb; 319 goto err_out_free_nskb;
320 } 320 }
321 321
322 /* netlink_unicast will either free the nskb or attach it to a socket */ 322 /* netlink_unicast will either free the nskb or attach it to a socket */
323 status = netlink_unicast(ipqnl, nskb, peer_pid, MSG_DONTWAIT); 323 status = netlink_unicast(ipqnl, nskb, peer_pid, MSG_DONTWAIT);
324 if (status < 0) { 324 if (status < 0) {
325 queue_user_dropped++; 325 queue_user_dropped++;
326 goto err_out_unlock; 326 goto err_out_unlock;
327 } 327 }
328 328
@@ -332,8 +332,8 @@ ipq_enqueue_packet(struct sk_buff *skb, struct nf_info *info,
332 return status; 332 return status;
333 333
334err_out_free_nskb: 334err_out_free_nskb:
335 kfree_skb(nskb); 335 kfree_skb(nskb);
336 336
337err_out_unlock: 337err_out_unlock:
338 write_unlock_bh(&queue_lock); 338 write_unlock_bh(&queue_lock);
339 339
@@ -359,11 +359,11 @@ ipq_mangle_ipv4(ipq_verdict_msg_t *v, struct ipq_queue_entry *e)
359 return -EINVAL; 359 return -EINVAL;
360 if (diff > skb_tailroom(e->skb)) { 360 if (diff > skb_tailroom(e->skb)) {
361 struct sk_buff *newskb; 361 struct sk_buff *newskb;
362 362
363 newskb = skb_copy_expand(e->skb, 363 newskb = skb_copy_expand(e->skb,
364 skb_headroom(e->skb), 364 skb_headroom(e->skb),
365 diff, 365 diff,
366 GFP_ATOMIC); 366 GFP_ATOMIC);
367 if (newskb == NULL) { 367 if (newskb == NULL) {
368 printk(KERN_WARNING "ip_queue: OOM " 368 printk(KERN_WARNING "ip_queue: OOM "
369 "in mangle, dropping packet\n"); 369 "in mangle, dropping packet\n");
@@ -403,11 +403,11 @@ ipq_set_verdict(struct ipq_verdict_msg *vmsg, unsigned int len)
403 return -ENOENT; 403 return -ENOENT;
404 else { 404 else {
405 int verdict = vmsg->value; 405 int verdict = vmsg->value;
406 406
407 if (vmsg->data_len && vmsg->data_len == len) 407 if (vmsg->data_len && vmsg->data_len == len)
408 if (ipq_mangle_ipv4(vmsg, entry) < 0) 408 if (ipq_mangle_ipv4(vmsg, entry) < 0)
409 verdict = NF_DROP; 409 verdict = NF_DROP;
410 410
411 ipq_issue_verdict(entry, verdict); 411 ipq_issue_verdict(entry, verdict);
412 return 0; 412 return 0;
413 } 413 }
@@ -426,7 +426,7 @@ ipq_set_mode(unsigned char mode, unsigned int range)
426 426
427static int 427static int
428ipq_receive_peer(struct ipq_peer_msg *pmsg, 428ipq_receive_peer(struct ipq_peer_msg *pmsg,
429 unsigned char type, unsigned int len) 429 unsigned char type, unsigned int len)
430{ 430{
431 int status = 0; 431 int status = 0;
432 432
@@ -436,15 +436,15 @@ ipq_receive_peer(struct ipq_peer_msg *pmsg,
436 switch (type) { 436 switch (type) {
437 case IPQM_MODE: 437 case IPQM_MODE:
438 status = ipq_set_mode(pmsg->msg.mode.value, 438 status = ipq_set_mode(pmsg->msg.mode.value,
439 pmsg->msg.mode.range); 439 pmsg->msg.mode.range);
440 break; 440 break;
441 441
442 case IPQM_VERDICT: 442 case IPQM_VERDICT:
443 if (pmsg->msg.verdict.value > NF_MAX_VERDICT) 443 if (pmsg->msg.verdict.value > NF_MAX_VERDICT)
444 status = -EINVAL; 444 status = -EINVAL;
445 else 445 else
446 status = ipq_set_verdict(&pmsg->msg.verdict, 446 status = ipq_set_verdict(&pmsg->msg.verdict,
447 len - sizeof(*pmsg)); 447 len - sizeof(*pmsg));
448 break; 448 break;
449 default: 449 default:
450 status = -EINVAL; 450 status = -EINVAL;
@@ -468,7 +468,7 @@ dev_cmp(struct ipq_queue_entry *entry, unsigned long ifindex)
468 return 1; 468 return 1;
469 if (entry->skb->nf_bridge->physoutdev && 469 if (entry->skb->nf_bridge->physoutdev &&
470 entry->skb->nf_bridge->physoutdev->ifindex == ifindex) 470 entry->skb->nf_bridge->physoutdev->ifindex == ifindex)
471 return 1; 471 return 1;
472 } 472 }
473#endif 473#endif
474 return 0; 474 return 0;
@@ -478,7 +478,7 @@ static void
478ipq_dev_drop(int ifindex) 478ipq_dev_drop(int ifindex)
479{ 479{
480 struct ipq_queue_entry *entry; 480 struct ipq_queue_entry *entry;
481 481
482 while ((entry = ipq_find_dequeue_entry(dev_cmp, ifindex)) != NULL) 482 while ((entry = ipq_find_dequeue_entry(dev_cmp, ifindex)) != NULL)
483 ipq_issue_verdict(entry, NF_DROP); 483 ipq_issue_verdict(entry, NF_DROP);
484} 484}
@@ -502,25 +502,25 @@ ipq_rcv_skb(struct sk_buff *skb)
502 502
503 pid = nlh->nlmsg_pid; 503 pid = nlh->nlmsg_pid;
504 flags = nlh->nlmsg_flags; 504 flags = nlh->nlmsg_flags;
505 505
506 if(pid <= 0 || !(flags & NLM_F_REQUEST) || flags & NLM_F_MULTI) 506 if(pid <= 0 || !(flags & NLM_F_REQUEST) || flags & NLM_F_MULTI)
507 RCV_SKB_FAIL(-EINVAL); 507 RCV_SKB_FAIL(-EINVAL);
508 508
509 if (flags & MSG_TRUNC) 509 if (flags & MSG_TRUNC)
510 RCV_SKB_FAIL(-ECOMM); 510 RCV_SKB_FAIL(-ECOMM);
511 511
512 type = nlh->nlmsg_type; 512 type = nlh->nlmsg_type;
513 if (type < NLMSG_NOOP || type >= IPQM_MAX) 513 if (type < NLMSG_NOOP || type >= IPQM_MAX)
514 RCV_SKB_FAIL(-EINVAL); 514 RCV_SKB_FAIL(-EINVAL);
515 515
516 if (type <= IPQM_BASE) 516 if (type <= IPQM_BASE)
517 return; 517 return;
518 518
519 if (security_netlink_recv(skb, CAP_NET_ADMIN)) 519 if (security_netlink_recv(skb, CAP_NET_ADMIN))
520 RCV_SKB_FAIL(-EPERM); 520 RCV_SKB_FAIL(-EPERM);
521 521
522 write_lock_bh(&queue_lock); 522 write_lock_bh(&queue_lock);
523 523
524 if (peer_pid) { 524 if (peer_pid) {
525 if (peer_pid != pid) { 525 if (peer_pid != pid) {
526 write_unlock_bh(&queue_lock); 526 write_unlock_bh(&queue_lock);
@@ -530,17 +530,17 @@ ipq_rcv_skb(struct sk_buff *skb)
530 net_enable_timestamp(); 530 net_enable_timestamp();
531 peer_pid = pid; 531 peer_pid = pid;
532 } 532 }
533 533
534 write_unlock_bh(&queue_lock); 534 write_unlock_bh(&queue_lock);
535 535
536 status = ipq_receive_peer(NLMSG_DATA(nlh), type, 536 status = ipq_receive_peer(NLMSG_DATA(nlh), type,
537 nlmsglen - NLMSG_LENGTH(0)); 537 nlmsglen - NLMSG_LENGTH(0));
538 if (status < 0) 538 if (status < 0)
539 RCV_SKB_FAIL(status); 539 RCV_SKB_FAIL(status);
540 540
541 if (flags & NLM_F_ACK) 541 if (flags & NLM_F_ACK)
542 netlink_ack(skb, nlh, 0); 542 netlink_ack(skb, nlh, 0);
543 return; 543 return;
544} 544}
545 545
546static void 546static void
@@ -550,19 +550,19 @@ ipq_rcv_sk(struct sock *sk, int len)
550 unsigned int qlen; 550 unsigned int qlen;
551 551
552 mutex_lock(&ipqnl_mutex); 552 mutex_lock(&ipqnl_mutex);
553 553
554 for (qlen = skb_queue_len(&sk->sk_receive_queue); qlen; qlen--) { 554 for (qlen = skb_queue_len(&sk->sk_receive_queue); qlen; qlen--) {
555 skb = skb_dequeue(&sk->sk_receive_queue); 555 skb = skb_dequeue(&sk->sk_receive_queue);
556 ipq_rcv_skb(skb); 556 ipq_rcv_skb(skb);
557 kfree_skb(skb); 557 kfree_skb(skb);
558 } 558 }
559 559
560 mutex_unlock(&ipqnl_mutex); 560 mutex_unlock(&ipqnl_mutex);
561} 561}
562 562
563static int 563static int
564ipq_rcv_dev_event(struct notifier_block *this, 564ipq_rcv_dev_event(struct notifier_block *this,
565 unsigned long event, void *ptr) 565 unsigned long event, void *ptr)
566{ 566{
567 struct net_device *dev = ptr; 567 struct net_device *dev = ptr;
568 568
@@ -578,7 +578,7 @@ static struct notifier_block ipq_dev_notifier = {
578 578
579static int 579static int
580ipq_rcv_nl_event(struct notifier_block *this, 580ipq_rcv_nl_event(struct notifier_block *this,
581 unsigned long event, void *ptr) 581 unsigned long event, void *ptr)
582{ 582{
583 struct netlink_notify *n = ptr; 583 struct netlink_notify *n = ptr;
584 584
@@ -607,7 +607,7 @@ static ctl_table ipq_table[] = {
607 .mode = 0644, 607 .mode = 0644,
608 .proc_handler = proc_dointvec 608 .proc_handler = proc_dointvec
609 }, 609 },
610 { .ctl_name = 0 } 610 { .ctl_name = 0 }
611}; 611};
612 612
613static ctl_table ipq_dir_table[] = { 613static ctl_table ipq_dir_table[] = {
@@ -637,25 +637,25 @@ ipq_get_info(char *buffer, char **start, off_t offset, int length)
637 int len; 637 int len;
638 638
639 read_lock_bh(&queue_lock); 639 read_lock_bh(&queue_lock);
640 640
641 len = sprintf(buffer, 641 len = sprintf(buffer,
642 "Peer PID : %d\n" 642 "Peer PID : %d\n"
643 "Copy mode : %hu\n" 643 "Copy mode : %hu\n"
644 "Copy range : %u\n" 644 "Copy range : %u\n"
645 "Queue length : %u\n" 645 "Queue length : %u\n"
646 "Queue max. length : %u\n" 646 "Queue max. length : %u\n"
647 "Queue dropped : %u\n" 647 "Queue dropped : %u\n"
648 "Netlink dropped : %u\n", 648 "Netlink dropped : %u\n",
649 peer_pid, 649 peer_pid,
650 copy_mode, 650 copy_mode,
651 copy_range, 651 copy_range,
652 queue_total, 652 queue_total,
653 queue_maxlen, 653 queue_maxlen,
654 queue_dropped, 654 queue_dropped,
655 queue_user_dropped); 655 queue_user_dropped);
656 656
657 read_unlock_bh(&queue_lock); 657 read_unlock_bh(&queue_lock);
658 658
659 *start = buffer + offset; 659 *start = buffer + offset;
660 len -= offset; 660 len -= offset;
661 if (len > length) 661 if (len > length)
@@ -675,7 +675,7 @@ static int __init ip_queue_init(void)
675{ 675{
676 int status = -ENOMEM; 676 int status = -ENOMEM;
677 struct proc_dir_entry *proc; 677 struct proc_dir_entry *proc;
678 678
679 netlink_register_notifier(&ipq_nl_notifier); 679 netlink_register_notifier(&ipq_nl_notifier);
680 ipqnl = netlink_kernel_create(NETLINK_FIREWALL, 0, ipq_rcv_sk, 680 ipqnl = netlink_kernel_create(NETLINK_FIREWALL, 0, ipq_rcv_sk,
681 THIS_MODULE); 681 THIS_MODULE);
@@ -691,10 +691,10 @@ static int __init ip_queue_init(void)
691 printk(KERN_ERR "ip_queue: failed to create proc entry\n"); 691 printk(KERN_ERR "ip_queue: failed to create proc entry\n");
692 goto cleanup_ipqnl; 692 goto cleanup_ipqnl;
693 } 693 }
694 694
695 register_netdevice_notifier(&ipq_dev_notifier); 695 register_netdevice_notifier(&ipq_dev_notifier);
696 ipq_sysctl_header = register_sysctl_table(ipq_root_table, 0); 696 ipq_sysctl_header = register_sysctl_table(ipq_root_table, 0);
697 697
698 status = nf_register_queue_handler(PF_INET, &nfqh); 698 status = nf_register_queue_handler(PF_INET, &nfqh);
699 if (status < 0) { 699 if (status < 0) {
700 printk(KERN_ERR "ip_queue: failed to register queue handler\n"); 700 printk(KERN_ERR "ip_queue: failed to register queue handler\n");
@@ -706,12 +706,12 @@ cleanup_sysctl:
706 unregister_sysctl_table(ipq_sysctl_header); 706 unregister_sysctl_table(ipq_sysctl_header);
707 unregister_netdevice_notifier(&ipq_dev_notifier); 707 unregister_netdevice_notifier(&ipq_dev_notifier);
708 proc_net_remove(IPQ_PROC_FS_NAME); 708 proc_net_remove(IPQ_PROC_FS_NAME);
709 709
710cleanup_ipqnl: 710cleanup_ipqnl:
711 sock_release(ipqnl->sk_socket); 711 sock_release(ipqnl->sk_socket);
712 mutex_lock(&ipqnl_mutex); 712 mutex_lock(&ipqnl_mutex);
713 mutex_unlock(&ipqnl_mutex); 713 mutex_unlock(&ipqnl_mutex);
714 714
715cleanup_netlink_notifier: 715cleanup_netlink_notifier:
716 netlink_unregister_notifier(&ipq_nl_notifier); 716 netlink_unregister_notifier(&ipq_nl_notifier);
717 return status; 717 return status;
diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
index fc1f153c86ba..50cc4b92e284 100644
--- a/net/ipv4/netfilter/ip_tables.c
+++ b/net/ipv4/netfilter/ip_tables.c
@@ -216,7 +216,7 @@ ipt_do_table(struct sk_buff **pskb,
216 unsigned int hook, 216 unsigned int hook,
217 const struct net_device *in, 217 const struct net_device *in,
218 const struct net_device *out, 218 const struct net_device *out,
219 struct ipt_table *table) 219 struct xt_table *table)
220{ 220{
221 static const char nulldevname[IFNAMSIZ] __attribute__((aligned(sizeof(long)))); 221 static const char nulldevname[IFNAMSIZ] __attribute__((aligned(sizeof(long))));
222 u_int16_t offset; 222 u_int16_t offset;
@@ -297,7 +297,7 @@ ipt_do_table(struct sk_buff **pskb,
297 e = get_entry(table_base, v); 297 e = get_entry(table_base, v);
298 } else { 298 } else {
299 /* Targets which reenter must return 299 /* Targets which reenter must return
300 abs. verdicts */ 300 abs. verdicts */
301#ifdef CONFIG_NETFILTER_DEBUG 301#ifdef CONFIG_NETFILTER_DEBUG
302 ((struct ipt_entry *)table_base)->comefrom 302 ((struct ipt_entry *)table_base)->comefrom
303 = 0xeeeeeeec; 303 = 0xeeeeeeec;
@@ -507,7 +507,7 @@ check_entry(struct ipt_entry *e, const char *name)
507static inline int check_match(struct ipt_entry_match *m, const char *name, 507static inline int check_match(struct ipt_entry_match *m, const char *name,
508 const struct ipt_ip *ip, unsigned int hookmask) 508 const struct ipt_ip *ip, unsigned int hookmask)
509{ 509{
510 struct ipt_match *match; 510 struct xt_match *match;
511 int ret; 511 int ret;
512 512
513 match = m->u.kernel.match; 513 match = m->u.kernel.match;
@@ -531,7 +531,7 @@ find_check_match(struct ipt_entry_match *m,
531 unsigned int hookmask, 531 unsigned int hookmask,
532 unsigned int *i) 532 unsigned int *i)
533{ 533{
534 struct ipt_match *match; 534 struct xt_match *match;
535 int ret; 535 int ret;
536 536
537 match = try_then_request_module(xt_find_match(AF_INET, m->u.user.name, 537 match = try_then_request_module(xt_find_match(AF_INET, m->u.user.name,
@@ -556,9 +556,9 @@ err:
556 556
557static inline int check_target(struct ipt_entry *e, const char *name) 557static inline int check_target(struct ipt_entry *e, const char *name)
558{ 558{
559 struct ipt_entry_target *t; 559 struct ipt_entry_target *t;
560 struct ipt_target *target; 560 struct xt_target *target;
561 int ret; 561 int ret;
562 562
563 t = ipt_get_target(e); 563 t = ipt_get_target(e);
564 target = t->u.kernel.target; 564 target = t->u.kernel.target;
@@ -580,7 +580,7 @@ find_check_entry(struct ipt_entry *e, const char *name, unsigned int size,
580 unsigned int *i) 580 unsigned int *i)
581{ 581{
582 struct ipt_entry_target *t; 582 struct ipt_entry_target *t;
583 struct ipt_target *target; 583 struct xt_target *target;
584 int ret; 584 int ret;
585 unsigned int j; 585 unsigned int j;
586 586
@@ -652,7 +652,7 @@ check_entry_size_and_hooks(struct ipt_entry *e,
652 } 652 }
653 653
654 /* FIXME: underflows must be unconditional, standard verdicts 654 /* FIXME: underflows must be unconditional, standard verdicts
655 < 0 (not IPT_RETURN). --RR */ 655 < 0 (not IPT_RETURN). --RR */
656 656
657 /* Clear counters and comefrom */ 657 /* Clear counters and comefrom */
658 e->counters = ((struct xt_counters) { 0, 0 }); 658 e->counters = ((struct xt_counters) { 0, 0 });
@@ -818,7 +818,7 @@ get_counters(const struct xt_table_info *t,
818 } 818 }
819} 819}
820 820
821static inline struct xt_counters * alloc_counters(struct ipt_table *table) 821static inline struct xt_counters * alloc_counters(struct xt_table *table)
822{ 822{
823 unsigned int countersize; 823 unsigned int countersize;
824 struct xt_counters *counters; 824 struct xt_counters *counters;
@@ -843,7 +843,7 @@ static inline struct xt_counters * alloc_counters(struct ipt_table *table)
843 843
844static int 844static int
845copy_entries_to_user(unsigned int total_size, 845copy_entries_to_user(unsigned int total_size,
846 struct ipt_table *table, 846 struct xt_table *table,
847 void __user *userptr) 847 void __user *userptr)
848{ 848{
849 unsigned int off, num; 849 unsigned int off, num;
@@ -1046,7 +1046,7 @@ static int compat_table_info(struct xt_table_info *info,
1046static int get_info(void __user *user, int *len, int compat) 1046static int get_info(void __user *user, int *len, int compat)
1047{ 1047{
1048 char name[IPT_TABLE_MAXNAMELEN]; 1048 char name[IPT_TABLE_MAXNAMELEN];
1049 struct ipt_table *t; 1049 struct xt_table *t;
1050 int ret; 1050 int ret;
1051 1051
1052 if (*len != sizeof(struct ipt_getinfo)) { 1052 if (*len != sizeof(struct ipt_getinfo)) {
@@ -1107,7 +1107,7 @@ get_entries(struct ipt_get_entries __user *uptr, int *len)
1107{ 1107{
1108 int ret; 1108 int ret;
1109 struct ipt_get_entries get; 1109 struct ipt_get_entries get;
1110 struct ipt_table *t; 1110 struct xt_table *t;
1111 1111
1112 if (*len < sizeof(get)) { 1112 if (*len < sizeof(get)) {
1113 duprintf("get_entries: %u < %d\n", *len, 1113 duprintf("get_entries: %u < %d\n", *len,
@@ -1151,7 +1151,7 @@ __do_replace(const char *name, unsigned int valid_hooks,
1151 void __user *counters_ptr) 1151 void __user *counters_ptr)
1152{ 1152{
1153 int ret; 1153 int ret;
1154 struct ipt_table *t; 1154 struct xt_table *t;
1155 struct xt_table_info *oldinfo; 1155 struct xt_table_info *oldinfo;
1156 struct xt_counters *counters; 1156 struct xt_counters *counters;
1157 void *loc_cpu_old_entry; 1157 void *loc_cpu_old_entry;
@@ -1302,7 +1302,7 @@ do_add_counters(void __user *user, unsigned int len, int compat)
1302 char *name; 1302 char *name;
1303 int size; 1303 int size;
1304 void *ptmp; 1304 void *ptmp;
1305 struct ipt_table *t; 1305 struct xt_table *t;
1306 struct xt_table_info *private; 1306 struct xt_table_info *private;
1307 int ret = 0; 1307 int ret = 0;
1308 void *loc_cpu_entry; 1308 void *loc_cpu_entry;
@@ -1437,7 +1437,7 @@ compat_check_calc_match(struct ipt_entry_match *m,
1437 unsigned int hookmask, 1437 unsigned int hookmask,
1438 int *size, int *i) 1438 int *size, int *i)
1439{ 1439{
1440 struct ipt_match *match; 1440 struct xt_match *match;
1441 1441
1442 match = try_then_request_module(xt_find_match(AF_INET, m->u.user.name, 1442 match = try_then_request_module(xt_find_match(AF_INET, m->u.user.name,
1443 m->u.user.revision), 1443 m->u.user.revision),
@@ -1466,7 +1466,7 @@ check_compat_entry_size_and_hooks(struct ipt_entry *e,
1466 const char *name) 1466 const char *name)
1467{ 1467{
1468 struct ipt_entry_target *t; 1468 struct ipt_entry_target *t;
1469 struct ipt_target *target; 1469 struct xt_target *target;
1470 unsigned int entry_offset; 1470 unsigned int entry_offset;
1471 int ret, off, h, j; 1471 int ret, off, h, j;
1472 1472
@@ -1550,7 +1550,7 @@ static int compat_copy_entry_from_user(struct ipt_entry *e, void **dstptr,
1550 struct xt_table_info *newinfo, unsigned char *base) 1550 struct xt_table_info *newinfo, unsigned char *base)
1551{ 1551{
1552 struct ipt_entry_target *t; 1552 struct ipt_entry_target *t;
1553 struct ipt_target *target; 1553 struct xt_target *target;
1554 struct ipt_entry *de; 1554 struct ipt_entry *de;
1555 unsigned int origsize; 1555 unsigned int origsize;
1556 int ret, h; 1556 int ret, h;
@@ -1795,7 +1795,7 @@ struct compat_ipt_get_entries
1795}; 1795};
1796 1796
1797static int compat_copy_entries_to_user(unsigned int total_size, 1797static int compat_copy_entries_to_user(unsigned int total_size,
1798 struct ipt_table *table, void __user *userptr) 1798 struct xt_table *table, void __user *userptr)
1799{ 1799{
1800 unsigned int off, num; 1800 unsigned int off, num;
1801 struct compat_ipt_entry e; 1801 struct compat_ipt_entry e;
@@ -1869,7 +1869,7 @@ compat_get_entries(struct compat_ipt_get_entries __user *uptr, int *len)
1869{ 1869{
1870 int ret; 1870 int ret;
1871 struct compat_ipt_get_entries get; 1871 struct compat_ipt_get_entries get;
1872 struct ipt_table *t; 1872 struct xt_table *t;
1873 1873
1874 1874
1875 if (*len < sizeof(get)) { 1875 if (*len < sizeof(get)) {
@@ -2052,12 +2052,12 @@ int ipt_register_table(struct xt_table *table, const struct ipt_replace *repl)
2052 return 0; 2052 return 0;
2053} 2053}
2054 2054
2055void ipt_unregister_table(struct ipt_table *table) 2055void ipt_unregister_table(struct xt_table *table)
2056{ 2056{
2057 struct xt_table_info *private; 2057 struct xt_table_info *private;
2058 void *loc_cpu_entry; 2058 void *loc_cpu_entry;
2059 2059
2060 private = xt_unregister_table(table); 2060 private = xt_unregister_table(table);
2061 2061
2062 /* Decrease module usage counts and free resources */ 2062 /* Decrease module usage counts and free resources */
2063 loc_cpu_entry = private->entries[raw_smp_processor_id()]; 2063 loc_cpu_entry = private->entries[raw_smp_processor_id()];
@@ -2124,7 +2124,7 @@ icmp_checkentry(const char *tablename,
2124} 2124}
2125 2125
2126/* The built-in targets: standard (NULL) and error. */ 2126/* The built-in targets: standard (NULL) and error. */
2127static struct ipt_target ipt_standard_target = { 2127static struct xt_target ipt_standard_target = {
2128 .name = IPT_STANDARD_TARGET, 2128 .name = IPT_STANDARD_TARGET,
2129 .targetsize = sizeof(int), 2129 .targetsize = sizeof(int),
2130 .family = AF_INET, 2130 .family = AF_INET,
@@ -2135,7 +2135,7 @@ static struct ipt_target ipt_standard_target = {
2135#endif 2135#endif
2136}; 2136};
2137 2137
2138static struct ipt_target ipt_error_target = { 2138static struct xt_target ipt_error_target = {
2139 .name = IPT_ERROR_TARGET, 2139 .name = IPT_ERROR_TARGET,
2140 .target = ipt_error, 2140 .target = ipt_error,
2141 .targetsize = IPT_FUNCTION_MAXNAMELEN, 2141 .targetsize = IPT_FUNCTION_MAXNAMELEN,
@@ -2158,7 +2158,7 @@ static struct nf_sockopt_ops ipt_sockopts = {
2158#endif 2158#endif
2159}; 2159};
2160 2160
2161static struct ipt_match icmp_matchstruct = { 2161static struct xt_match icmp_matchstruct = {
2162 .name = "icmp", 2162 .name = "icmp",
2163 .match = icmp_match, 2163 .match = icmp_match,
2164 .matchsize = sizeof(struct ipt_icmp), 2164 .matchsize = sizeof(struct ipt_icmp),
diff --git a/net/ipv4/netfilter/ipt_CLUSTERIP.c b/net/ipv4/netfilter/ipt_CLUSTERIP.c
index b1c11160b9de..e965b333c997 100644
--- a/net/ipv4/netfilter/ipt_CLUSTERIP.c
+++ b/net/ipv4/netfilter/ipt_CLUSTERIP.c
@@ -1,4 +1,4 @@
1/* Cluster IP hashmark target 1/* Cluster IP hashmark target
2 * (C) 2003-2004 by Harald Welte <laforge@netfilter.org> 2 * (C) 2003-2004 by Harald Welte <laforge@netfilter.org>
3 * based on ideas of Fabio Olive Leite <olive@unixforge.org> 3 * based on ideas of Fabio Olive Leite <olive@unixforge.org>
4 * 4 *
@@ -26,6 +26,7 @@
26 26
27#include <linux/netfilter_arp.h> 27#include <linux/netfilter_arp.h>
28 28
29#include <linux/netfilter/x_tables.h>
29#include <linux/netfilter_ipv4/ip_tables.h> 30#include <linux/netfilter_ipv4/ip_tables.h>
30#include <linux/netfilter_ipv4/ipt_CLUSTERIP.h> 31#include <linux/netfilter_ipv4/ipt_CLUSTERIP.h>
31#include <net/netfilter/nf_conntrack_compat.h> 32#include <net/netfilter/nf_conntrack_compat.h>
@@ -69,7 +70,7 @@ static LIST_HEAD(clusterip_configs);
69static DEFINE_RWLOCK(clusterip_lock); 70static DEFINE_RWLOCK(clusterip_lock);
70 71
71#ifdef CONFIG_PROC_FS 72#ifdef CONFIG_PROC_FS
72static struct file_operations clusterip_proc_fops; 73static const struct file_operations clusterip_proc_fops;
73static struct proc_dir_entry *clusterip_procdir; 74static struct proc_dir_entry *clusterip_procdir;
74#endif 75#endif
75 76
@@ -122,7 +123,7 @@ __clusterip_config_find(__be32 clusterip)
122 struct list_head *pos; 123 struct list_head *pos;
123 124
124 list_for_each(pos, &clusterip_configs) { 125 list_for_each(pos, &clusterip_configs) {
125 struct clusterip_config *c = list_entry(pos, 126 struct clusterip_config *c = list_entry(pos,
126 struct clusterip_config, list); 127 struct clusterip_config, list);
127 if (c->clusterip == clusterip) { 128 if (c->clusterip == clusterip) {
128 return c; 129 return c;
@@ -228,7 +229,7 @@ clusterip_del_node(struct clusterip_config *c, u_int16_t nodenum)
228 if (nodenum == 0 || 229 if (nodenum == 0 ||
229 nodenum > c->num_total_nodes) 230 nodenum > c->num_total_nodes)
230 return 1; 231 return 1;
231 232
232 if (test_and_clear_bit(nodenum - 1, &c->local_nodes)) 233 if (test_and_clear_bit(nodenum - 1, &c->local_nodes))
233 return 0; 234 return 0;
234 235
@@ -247,6 +248,7 @@ clusterip_hashfn(struct sk_buff *skb, struct clusterip_config *config)
247 switch (iph->protocol) { 248 switch (iph->protocol) {
248 case IPPROTO_TCP: 249 case IPPROTO_TCP:
249 case IPPROTO_UDP: 250 case IPPROTO_UDP:
251 case IPPROTO_UDPLITE:
250 case IPPROTO_SCTP: 252 case IPPROTO_SCTP:
251 case IPPROTO_DCCP: 253 case IPPROTO_DCCP:
252 case IPPROTO_ICMP: 254 case IPPROTO_ICMP:
@@ -268,7 +270,7 @@ clusterip_hashfn(struct sk_buff *skb, struct clusterip_config *config)
268 config->hash_initval); 270 config->hash_initval);
269 break; 271 break;
270 case CLUSTERIP_HASHMODE_SIP_SPT: 272 case CLUSTERIP_HASHMODE_SIP_SPT:
271 hashval = jhash_2words(ntohl(iph->saddr), sport, 273 hashval = jhash_2words(ntohl(iph->saddr), sport,
272 config->hash_initval); 274 config->hash_initval);
273 break; 275 break;
274 case CLUSTERIP_HASHMODE_SIP_SPT_DPT: 276 case CLUSTERIP_HASHMODE_SIP_SPT_DPT:
@@ -295,8 +297,8 @@ clusterip_responsible(struct clusterip_config *config, u_int32_t hash)
295 return test_bit(hash - 1, &config->local_nodes); 297 return test_bit(hash - 1, &config->local_nodes);
296} 298}
297 299
298/*********************************************************************** 300/***********************************************************************
299 * IPTABLES TARGET 301 * IPTABLES TARGET
300 ***********************************************************************/ 302 ***********************************************************************/
301 303
302static unsigned int 304static unsigned int
@@ -319,7 +321,7 @@ target(struct sk_buff **pskb,
319 if (mark == NULL) { 321 if (mark == NULL) {
320 printk(KERN_ERR "CLUSTERIP: no conntrack!\n"); 322 printk(KERN_ERR "CLUSTERIP: no conntrack!\n");
321 /* FIXME: need to drop invalid ones, since replies 323 /* FIXME: need to drop invalid ones, since replies
322 * to outgoing connections of other nodes will be 324 * to outgoing connections of other nodes will be
323 * marked as INVALID */ 325 * marked as INVALID */
324 return NF_DROP; 326 return NF_DROP;
325 } 327 }
@@ -327,11 +329,11 @@ target(struct sk_buff **pskb,
327 /* special case: ICMP error handling. conntrack distinguishes between 329 /* special case: ICMP error handling. conntrack distinguishes between
328 * error messages (RELATED) and information requests (see below) */ 330 * error messages (RELATED) and information requests (see below) */
329 if ((*pskb)->nh.iph->protocol == IPPROTO_ICMP 331 if ((*pskb)->nh.iph->protocol == IPPROTO_ICMP
330 && (ctinfo == IP_CT_RELATED 332 && (ctinfo == IP_CT_RELATED
331 || ctinfo == IP_CT_RELATED+IP_CT_IS_REPLY)) 333 || ctinfo == IP_CT_RELATED+IP_CT_IS_REPLY))
332 return IPT_CONTINUE; 334 return XT_CONTINUE;
333 335
334 /* ip_conntrack_icmp guarantees us that we only have ICMP_ECHO, 336 /* ip_conntrack_icmp guarantees us that we only have ICMP_ECHO,
335 * TIMESTAMP, INFO_REQUEST or ADDRESS type icmp packets from here 337 * TIMESTAMP, INFO_REQUEST or ADDRESS type icmp packets from here
336 * on, which all have an ID field [relevant for hashing]. */ 338 * on, which all have an ID field [relevant for hashing]. */
337 339
@@ -367,15 +369,15 @@ target(struct sk_buff **pskb,
367 * actually a unicast IP packet. TCP doesn't like PACKET_MULTICAST */ 369 * actually a unicast IP packet. TCP doesn't like PACKET_MULTICAST */
368 (*pskb)->pkt_type = PACKET_HOST; 370 (*pskb)->pkt_type = PACKET_HOST;
369 371
370 return IPT_CONTINUE; 372 return XT_CONTINUE;
371} 373}
372 374
373static int 375static int
374checkentry(const char *tablename, 376checkentry(const char *tablename,
375 const void *e_void, 377 const void *e_void,
376 const struct xt_target *target, 378 const struct xt_target *target,
377 void *targinfo, 379 void *targinfo,
378 unsigned int hook_mask) 380 unsigned int hook_mask)
379{ 381{
380 struct ipt_clusterip_tgt_info *cipinfo = targinfo; 382 struct ipt_clusterip_tgt_info *cipinfo = targinfo;
381 const struct ipt_entry *e = e_void; 383 const struct ipt_entry *e = e_void;
@@ -435,7 +437,7 @@ checkentry(const char *tablename,
435 return 0; 437 return 0;
436 } 438 }
437 439
438 config = clusterip_config_init(cipinfo, 440 config = clusterip_config_init(cipinfo,
439 e->ip.dst.s_addr, dev); 441 e->ip.dst.s_addr, dev);
440 if (!config) { 442 if (!config) {
441 printk(KERN_WARNING "CLUSTERIP: cannot allocate config\n"); 443 printk(KERN_WARNING "CLUSTERIP: cannot allocate config\n");
@@ -470,8 +472,9 @@ static void destroy(const struct xt_target *target, void *targinfo)
470 nf_ct_l3proto_module_put(target->family); 472 nf_ct_l3proto_module_put(target->family);
471} 473}
472 474
473static struct ipt_target clusterip_tgt = { 475static struct xt_target clusterip_tgt = {
474 .name = "CLUSTERIP", 476 .name = "CLUSTERIP",
477 .family = AF_INET,
475 .target = target, 478 .target = target,
476 .targetsize = sizeof(struct ipt_clusterip_tgt_info), 479 .targetsize = sizeof(struct ipt_clusterip_tgt_info),
477 .checkentry = checkentry, 480 .checkentry = checkentry,
@@ -480,8 +483,8 @@ static struct ipt_target clusterip_tgt = {
480}; 483};
481 484
482 485
483/*********************************************************************** 486/***********************************************************************
484 * ARP MANGLING CODE 487 * ARP MANGLING CODE
485 ***********************************************************************/ 488 ***********************************************************************/
486 489
487/* hardcoded for 48bit ethernet and 32bit ipv4 addresses */ 490/* hardcoded for 48bit ethernet and 32bit ipv4 addresses */
@@ -493,7 +496,7 @@ struct arp_payload {
493} __attribute__ ((packed)); 496} __attribute__ ((packed));
494 497
495#ifdef CLUSTERIP_DEBUG 498#ifdef CLUSTERIP_DEBUG
496static void arp_print(struct arp_payload *payload) 499static void arp_print(struct arp_payload *payload)
497{ 500{
498#define HBUFFERLEN 30 501#define HBUFFERLEN 30
499 char hbuffer[HBUFFERLEN]; 502 char hbuffer[HBUFFERLEN];
@@ -507,7 +510,7 @@ static void arp_print(struct arp_payload *payload)
507 } 510 }
508 hbuffer[--k]='\0'; 511 hbuffer[--k]='\0';
509 512
510 printk("src %u.%u.%u.%u@%s, dst %u.%u.%u.%u\n", 513 printk("src %u.%u.%u.%u@%s, dst %u.%u.%u.%u\n",
511 NIPQUAD(payload->src_ip), hbuffer, 514 NIPQUAD(payload->src_ip), hbuffer,
512 NIPQUAD(payload->dst_ip)); 515 NIPQUAD(payload->dst_ip));
513} 516}
@@ -537,13 +540,13 @@ arp_mangle(unsigned int hook,
537 540
538 payload = (void *)(arp+1); 541 payload = (void *)(arp+1);
539 542
540 /* if there is no clusterip configuration for the arp reply's 543 /* if there is no clusterip configuration for the arp reply's
541 * source ip, we don't want to mangle it */ 544 * source ip, we don't want to mangle it */
542 c = clusterip_config_find_get(payload->src_ip, 0); 545 c = clusterip_config_find_get(payload->src_ip, 0);
543 if (!c) 546 if (!c)
544 return NF_ACCEPT; 547 return NF_ACCEPT;
545 548
546 /* normally the linux kernel always replies to arp queries of 549 /* normally the linux kernel always replies to arp queries of
547 * addresses on different interfacs. However, in the CLUSTERIP case 550 * addresses on different interfacs. However, in the CLUSTERIP case
548 * this wouldn't work, since we didn't subscribe the mcast group on 551 * this wouldn't work, since we didn't subscribe the mcast group on
549 * other interfaces */ 552 * other interfaces */
@@ -574,8 +577,8 @@ static struct nf_hook_ops cip_arp_ops = {
574 .priority = -1 577 .priority = -1
575}; 578};
576 579
577/*********************************************************************** 580/***********************************************************************
578 * PROC DIR HANDLING 581 * PROC DIR HANDLING
579 ***********************************************************************/ 582 ***********************************************************************/
580 583
581#ifdef CONFIG_PROC_FS 584#ifdef CONFIG_PROC_FS
@@ -637,7 +640,7 @@ static int clusterip_seq_show(struct seq_file *s, void *v)
637{ 640{
638 struct clusterip_seq_position *idx = (struct clusterip_seq_position *)v; 641 struct clusterip_seq_position *idx = (struct clusterip_seq_position *)v;
639 642
640 if (idx->pos != 0) 643 if (idx->pos != 0)
641 seq_putc(s, ','); 644 seq_putc(s, ',');
642 645
643 seq_printf(s, "%u", idx->bit); 646 seq_printf(s, "%u", idx->bit);
@@ -712,7 +715,7 @@ static ssize_t clusterip_proc_write(struct file *file, const char __user *input,
712 return size; 715 return size;
713} 716}
714 717
715static struct file_operations clusterip_proc_fops = { 718static const struct file_operations clusterip_proc_fops = {
716 .owner = THIS_MODULE, 719 .owner = THIS_MODULE,
717 .open = clusterip_proc_open, 720 .open = clusterip_proc_open,
718 .read = seq_read, 721 .read = seq_read,
@@ -727,7 +730,7 @@ static int __init ipt_clusterip_init(void)
727{ 730{
728 int ret; 731 int ret;
729 732
730 ret = ipt_register_target(&clusterip_tgt); 733 ret = xt_register_target(&clusterip_tgt);
731 if (ret < 0) 734 if (ret < 0)
732 return ret; 735 return ret;
733 736
@@ -753,7 +756,7 @@ cleanup_hook:
753 nf_unregister_hook(&cip_arp_ops); 756 nf_unregister_hook(&cip_arp_ops);
754#endif /* CONFIG_PROC_FS */ 757#endif /* CONFIG_PROC_FS */
755cleanup_target: 758cleanup_target:
756 ipt_unregister_target(&clusterip_tgt); 759 xt_unregister_target(&clusterip_tgt);
757 return ret; 760 return ret;
758} 761}
759 762
@@ -765,7 +768,7 @@ static void __exit ipt_clusterip_fini(void)
765 remove_proc_entry(clusterip_procdir->name, clusterip_procdir->parent); 768 remove_proc_entry(clusterip_procdir->name, clusterip_procdir->parent);
766#endif 769#endif
767 nf_unregister_hook(&cip_arp_ops); 770 nf_unregister_hook(&cip_arp_ops);
768 ipt_unregister_target(&clusterip_tgt); 771 xt_unregister_target(&clusterip_tgt);
769} 772}
770 773
771module_init(ipt_clusterip_init); 774module_init(ipt_clusterip_init);
diff --git a/net/ipv4/netfilter/ipt_ECN.c b/net/ipv4/netfilter/ipt_ECN.c
index b55d670a24df..4f565633631d 100644
--- a/net/ipv4/netfilter/ipt_ECN.c
+++ b/net/ipv4/netfilter/ipt_ECN.c
@@ -1,20 +1,22 @@
1/* iptables module for the IPv4 and TCP ECN bits, Version 1.5 1/* iptables module for the IPv4 and TCP ECN bits, Version 1.5
2 * 2 *
3 * (C) 2002 by Harald Welte <laforge@netfilter.org> 3 * (C) 2002 by Harald Welte <laforge@netfilter.org>
4 * 4 *
5 * This program is free software; you can redistribute it and/or modify 5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as 6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * ipt_ECN.c,v 1.5 2002/08/18 19:36:51 laforge Exp 9 * ipt_ECN.c,v 1.5 2002/08/18 19:36:51 laforge Exp
10*/ 10*/
11 11
12#include <linux/in.h>
12#include <linux/module.h> 13#include <linux/module.h>
13#include <linux/skbuff.h> 14#include <linux/skbuff.h>
14#include <linux/ip.h> 15#include <linux/ip.h>
15#include <linux/tcp.h> 16#include <linux/tcp.h>
16#include <net/checksum.h> 17#include <net/checksum.h>
17 18
19#include <linux/netfilter/x_tables.h>
18#include <linux/netfilter_ipv4/ip_tables.h> 20#include <linux/netfilter_ipv4/ip_tables.h>
19#include <linux/netfilter_ipv4/ipt_ECN.h> 21#include <linux/netfilter_ipv4/ipt_ECN.h>
20 22
@@ -38,7 +40,7 @@ set_ect_ip(struct sk_buff **pskb, const struct ipt_ECN_info *einfo)
38 iph->tos &= ~IPT_ECN_IP_MASK; 40 iph->tos &= ~IPT_ECN_IP_MASK;
39 iph->tos |= (einfo->ip_ect & IPT_ECN_IP_MASK); 41 iph->tos |= (einfo->ip_ect & IPT_ECN_IP_MASK);
40 nf_csum_replace2(&iph->check, htons(oldtos), htons(iph->tos)); 42 nf_csum_replace2(&iph->check, htons(oldtos), htons(iph->tos));
41 } 43 }
42 return 1; 44 return 1;
43} 45}
44 46
@@ -95,15 +97,15 @@ target(struct sk_buff **pskb,
95 if (!set_ect_tcp(pskb, einfo)) 97 if (!set_ect_tcp(pskb, einfo))
96 return NF_DROP; 98 return NF_DROP;
97 99
98 return IPT_CONTINUE; 100 return XT_CONTINUE;
99} 101}
100 102
101static int 103static int
102checkentry(const char *tablename, 104checkentry(const char *tablename,
103 const void *e_void, 105 const void *e_void,
104 const struct xt_target *target, 106 const struct xt_target *target,
105 void *targinfo, 107 void *targinfo,
106 unsigned int hook_mask) 108 unsigned int hook_mask)
107{ 109{
108 const struct ipt_ECN_info *einfo = (struct ipt_ECN_info *)targinfo; 110 const struct ipt_ECN_info *einfo = (struct ipt_ECN_info *)targinfo;
109 const struct ipt_entry *e = e_void; 111 const struct ipt_entry *e = e_void;
@@ -119,7 +121,7 @@ checkentry(const char *tablename,
119 return 0; 121 return 0;
120 } 122 }
121 if ((einfo->operation & (IPT_ECN_OP_SET_ECE|IPT_ECN_OP_SET_CWR)) 123 if ((einfo->operation & (IPT_ECN_OP_SET_ECE|IPT_ECN_OP_SET_CWR))
122 && (e->ip.proto != IPPROTO_TCP || (e->ip.invflags & IPT_INV_PROTO))) { 124 && (e->ip.proto != IPPROTO_TCP || (e->ip.invflags & XT_INV_PROTO))) {
123 printk(KERN_WARNING "ECN: cannot use TCP operations on a " 125 printk(KERN_WARNING "ECN: cannot use TCP operations on a "
124 "non-tcp rule\n"); 126 "non-tcp rule\n");
125 return 0; 127 return 0;
@@ -127,8 +129,9 @@ checkentry(const char *tablename,
127 return 1; 129 return 1;
128} 130}
129 131
130static struct ipt_target ipt_ecn_reg = { 132static struct xt_target ipt_ecn_reg = {
131 .name = "ECN", 133 .name = "ECN",
134 .family = AF_INET,
132 .target = target, 135 .target = target,
133 .targetsize = sizeof(struct ipt_ECN_info), 136 .targetsize = sizeof(struct ipt_ECN_info),
134 .table = "mangle", 137 .table = "mangle",
@@ -138,12 +141,12 @@ static struct ipt_target ipt_ecn_reg = {
138 141
139static int __init ipt_ecn_init(void) 142static int __init ipt_ecn_init(void)
140{ 143{
141 return ipt_register_target(&ipt_ecn_reg); 144 return xt_register_target(&ipt_ecn_reg);
142} 145}
143 146
144static void __exit ipt_ecn_fini(void) 147static void __exit ipt_ecn_fini(void)
145{ 148{
146 ipt_unregister_target(&ipt_ecn_reg); 149 xt_unregister_target(&ipt_ecn_reg);
147} 150}
148 151
149module_init(ipt_ecn_init); 152module_init(ipt_ecn_init);
diff --git a/net/ipv4/netfilter/ipt_LOG.c b/net/ipv4/netfilter/ipt_LOG.c
index c96de16fefae..d9c37fd94228 100644
--- a/net/ipv4/netfilter/ipt_LOG.c
+++ b/net/ipv4/netfilter/ipt_LOG.c
@@ -20,7 +20,7 @@
20#include <net/route.h> 20#include <net/route.h>
21 21
22#include <linux/netfilter.h> 22#include <linux/netfilter.h>
23#include <linux/netfilter_ipv4/ip_tables.h> 23#include <linux/netfilter/x_tables.h>
24#include <linux/netfilter_ipv4/ipt_LOG.h> 24#include <linux/netfilter_ipv4/ipt_LOG.h>
25 25
26MODULE_LICENSE("GPL"); 26MODULE_LICENSE("GPL");
@@ -289,7 +289,7 @@ static void dump_packet(const struct nf_loginfo *info,
289 289
290 if (ntohs(ih->frag_off) & IP_OFFSET) 290 if (ntohs(ih->frag_off) & IP_OFFSET)
291 break; 291 break;
292 292
293 /* Max length: 9 "PROTO=AH " */ 293 /* Max length: 9 "PROTO=AH " */
294 printk("PROTO=AH "); 294 printk("PROTO=AH ");
295 295
@@ -334,10 +334,10 @@ static void dump_packet(const struct nf_loginfo *info,
334 } 334 }
335 335
336 /* Max length: 15 "UID=4294967295 " */ 336 /* Max length: 15 "UID=4294967295 " */
337 if ((logflags & IPT_LOG_UID) && !iphoff && skb->sk) { 337 if ((logflags & IPT_LOG_UID) && !iphoff && skb->sk) {
338 read_lock_bh(&skb->sk->sk_callback_lock); 338 read_lock_bh(&skb->sk->sk_callback_lock);
339 if (skb->sk->sk_socket && skb->sk->sk_socket->file) 339 if (skb->sk->sk_socket && skb->sk->sk_socket->file)
340 printk("UID=%u ", skb->sk->sk_socket->file->f_uid); 340 printk("UID=%u ", skb->sk->sk_socket->file->f_uid);
341 read_unlock_bh(&skb->sk->sk_callback_lock); 341 read_unlock_bh(&skb->sk->sk_callback_lock);
342 } 342 }
343 343
@@ -431,8 +431,8 @@ ipt_log_target(struct sk_buff **pskb,
431 li.u.log.logflags = loginfo->logflags; 431 li.u.log.logflags = loginfo->logflags;
432 432
433 ipt_log_packet(PF_INET, hooknum, *pskb, in, out, &li, 433 ipt_log_packet(PF_INET, hooknum, *pskb, in, out, &li,
434 loginfo->prefix); 434 loginfo->prefix);
435 return IPT_CONTINUE; 435 return XT_CONTINUE;
436} 436}
437 437
438static int ipt_log_checkentry(const char *tablename, 438static int ipt_log_checkentry(const char *tablename,
@@ -455,8 +455,9 @@ static int ipt_log_checkentry(const char *tablename,
455 return 1; 455 return 1;
456} 456}
457 457
458static struct ipt_target ipt_log_reg = { 458static struct xt_target ipt_log_reg = {
459 .name = "LOG", 459 .name = "LOG",
460 .family = AF_INET,
460 .target = ipt_log_target, 461 .target = ipt_log_target,
461 .targetsize = sizeof(struct ipt_log_info), 462 .targetsize = sizeof(struct ipt_log_info),
462 .checkentry = ipt_log_checkentry, 463 .checkentry = ipt_log_checkentry,
@@ -471,22 +472,25 @@ static struct nf_logger ipt_log_logger ={
471 472
472static int __init ipt_log_init(void) 473static int __init ipt_log_init(void)
473{ 474{
474 if (ipt_register_target(&ipt_log_reg)) 475 int ret;
475 return -EINVAL; 476
477 ret = xt_register_target(&ipt_log_reg);
478 if (ret < 0)
479 return ret;
476 if (nf_log_register(PF_INET, &ipt_log_logger) < 0) { 480 if (nf_log_register(PF_INET, &ipt_log_logger) < 0) {
477 printk(KERN_WARNING "ipt_LOG: not logging via system console " 481 printk(KERN_WARNING "ipt_LOG: not logging via system console "
478 "since somebody else already registered for PF_INET\n"); 482 "since somebody else already registered for PF_INET\n");
479 /* we cannot make module load fail here, since otherwise 483 /* we cannot make module load fail here, since otherwise
480 * iptables userspace would abort */ 484 * iptables userspace would abort */
481 } 485 }
482 486
483 return 0; 487 return 0;
484} 488}
485 489
486static void __exit ipt_log_fini(void) 490static void __exit ipt_log_fini(void)
487{ 491{
488 nf_log_unregister_logger(&ipt_log_logger); 492 nf_log_unregister(&ipt_log_logger);
489 ipt_unregister_target(&ipt_log_reg); 493 xt_unregister_target(&ipt_log_reg);
490} 494}
491 495
492module_init(ipt_log_init); 496module_init(ipt_log_init);
diff --git a/net/ipv4/netfilter/ipt_MASQUERADE.c b/net/ipv4/netfilter/ipt_MASQUERADE.c
index d669685afd04..b5955f3a3f8f 100644
--- a/net/ipv4/netfilter/ipt_MASQUERADE.c
+++ b/net/ipv4/netfilter/ipt_MASQUERADE.c
@@ -25,7 +25,7 @@
25#else 25#else
26#include <linux/netfilter_ipv4/ip_nat_rule.h> 26#include <linux/netfilter_ipv4/ip_nat_rule.h>
27#endif 27#endif
28#include <linux/netfilter_ipv4/ip_tables.h> 28#include <linux/netfilter/x_tables.h>
29 29
30MODULE_LICENSE("GPL"); 30MODULE_LICENSE("GPL");
31MODULE_AUTHOR("Netfilter Core Team <coreteam@netfilter.org>"); 31MODULE_AUTHOR("Netfilter Core Team <coreteam@netfilter.org>");
@@ -86,7 +86,7 @@ masquerade_target(struct sk_buff **pskb,
86 nat = nfct_nat(ct); 86 nat = nfct_nat(ct);
87#endif 87#endif
88 IP_NF_ASSERT(ct && (ctinfo == IP_CT_NEW || ctinfo == IP_CT_RELATED 88 IP_NF_ASSERT(ct && (ctinfo == IP_CT_NEW || ctinfo == IP_CT_RELATED
89 || ctinfo == IP_CT_RELATED + IP_CT_IS_REPLY)); 89 || ctinfo == IP_CT_RELATED + IP_CT_IS_REPLY));
90 90
91 /* Source address is 0.0.0.0 - locally generated packet that is 91 /* Source address is 0.0.0.0 - locally generated packet that is
92 * probably not supposed to be masqueraded. 92 * probably not supposed to be masqueraded.
@@ -190,8 +190,9 @@ static struct notifier_block masq_inet_notifier = {
190 .notifier_call = masq_inet_event, 190 .notifier_call = masq_inet_event,
191}; 191};
192 192
193static struct ipt_target masquerade = { 193static struct xt_target masquerade = {
194 .name = "MASQUERADE", 194 .name = "MASQUERADE",
195 .family = AF_INET,
195 .target = masquerade_target, 196 .target = masquerade_target,
196 .targetsize = sizeof(struct ip_nat_multi_range_compat), 197 .targetsize = sizeof(struct ip_nat_multi_range_compat),
197 .table = "nat", 198 .table = "nat",
@@ -204,7 +205,7 @@ static int __init ipt_masquerade_init(void)
204{ 205{
205 int ret; 206 int ret;
206 207
207 ret = ipt_register_target(&masquerade); 208 ret = xt_register_target(&masquerade);
208 209
209 if (ret == 0) { 210 if (ret == 0) {
210 /* Register for device down reports */ 211 /* Register for device down reports */
@@ -218,9 +219,9 @@ static int __init ipt_masquerade_init(void)
218 219
219static void __exit ipt_masquerade_fini(void) 220static void __exit ipt_masquerade_fini(void)
220{ 221{
221 ipt_unregister_target(&masquerade); 222 xt_unregister_target(&masquerade);
222 unregister_netdevice_notifier(&masq_dev_notifier); 223 unregister_netdevice_notifier(&masq_dev_notifier);
223 unregister_inetaddr_notifier(&masq_inet_notifier); 224 unregister_inetaddr_notifier(&masq_inet_notifier);
224} 225}
225 226
226module_init(ipt_masquerade_init); 227module_init(ipt_masquerade_init);
diff --git a/net/ipv4/netfilter/ipt_NETMAP.c b/net/ipv4/netfilter/ipt_NETMAP.c
index 9390e90f2b25..fd7aaa347cd8 100644
--- a/net/ipv4/netfilter/ipt_NETMAP.c
+++ b/net/ipv4/netfilter/ipt_NETMAP.c
@@ -15,6 +15,7 @@
15#include <linux/netdevice.h> 15#include <linux/netdevice.h>
16#include <linux/netfilter.h> 16#include <linux/netfilter.h>
17#include <linux/netfilter_ipv4.h> 17#include <linux/netfilter_ipv4.h>
18#include <linux/netfilter/x_tables.h>
18#ifdef CONFIG_NF_NAT_NEEDED 19#ifdef CONFIG_NF_NAT_NEEDED
19#include <net/netfilter/nf_nat_rule.h> 20#include <net/netfilter/nf_nat_rule.h>
20#else 21#else
@@ -88,25 +89,26 @@ target(struct sk_buff **pskb,
88 return ip_nat_setup_info(ct, &newrange, hooknum); 89 return ip_nat_setup_info(ct, &newrange, hooknum);
89} 90}
90 91
91static struct ipt_target target_module = { 92static struct xt_target target_module = {
92 .name = MODULENAME, 93 .name = MODULENAME,
93 .target = target, 94 .family = AF_INET,
95 .target = target,
94 .targetsize = sizeof(struct ip_nat_multi_range_compat), 96 .targetsize = sizeof(struct ip_nat_multi_range_compat),
95 .table = "nat", 97 .table = "nat",
96 .hooks = (1 << NF_IP_PRE_ROUTING) | (1 << NF_IP_POST_ROUTING) | 98 .hooks = (1 << NF_IP_PRE_ROUTING) | (1 << NF_IP_POST_ROUTING) |
97 (1 << NF_IP_LOCAL_OUT), 99 (1 << NF_IP_LOCAL_OUT),
98 .checkentry = check, 100 .checkentry = check,
99 .me = THIS_MODULE 101 .me = THIS_MODULE
100}; 102};
101 103
102static int __init ipt_netmap_init(void) 104static int __init ipt_netmap_init(void)
103{ 105{
104 return ipt_register_target(&target_module); 106 return xt_register_target(&target_module);
105} 107}
106 108
107static void __exit ipt_netmap_fini(void) 109static void __exit ipt_netmap_fini(void)
108{ 110{
109 ipt_unregister_target(&target_module); 111 xt_unregister_target(&target_module);
110} 112}
111 113
112module_init(ipt_netmap_init); 114module_init(ipt_netmap_init);
diff --git a/net/ipv4/netfilter/ipt_REDIRECT.c b/net/ipv4/netfilter/ipt_REDIRECT.c
index 462eceb3a1b1..c2b6b80670f8 100644
--- a/net/ipv4/netfilter/ipt_REDIRECT.c
+++ b/net/ipv4/netfilter/ipt_REDIRECT.c
@@ -18,6 +18,7 @@
18#include <net/protocol.h> 18#include <net/protocol.h>
19#include <net/checksum.h> 19#include <net/checksum.h>
20#include <linux/netfilter_ipv4.h> 20#include <linux/netfilter_ipv4.h>
21#include <linux/netfilter/x_tables.h>
21#ifdef CONFIG_NF_NAT_NEEDED 22#ifdef CONFIG_NF_NAT_NEEDED
22#include <net/netfilter/nf_nat_rule.h> 23#include <net/netfilter/nf_nat_rule.h>
23#else 24#else
@@ -83,7 +84,7 @@ redirect_target(struct sk_buff **pskb,
83 struct in_ifaddr *ifa; 84 struct in_ifaddr *ifa;
84 85
85 newdst = 0; 86 newdst = 0;
86 87
87 rcu_read_lock(); 88 rcu_read_lock();
88 indev = __in_dev_get_rcu((*pskb)->dev); 89 indev = __in_dev_get_rcu((*pskb)->dev);
89 if (indev && (ifa = indev->ifa_list)) 90 if (indev && (ifa = indev->ifa_list))
@@ -104,8 +105,9 @@ redirect_target(struct sk_buff **pskb,
104 return ip_nat_setup_info(ct, &newrange, hooknum); 105 return ip_nat_setup_info(ct, &newrange, hooknum);
105} 106}
106 107
107static struct ipt_target redirect_reg = { 108static struct xt_target redirect_reg = {
108 .name = "REDIRECT", 109 .name = "REDIRECT",
110 .family = AF_INET,
109 .target = redirect_target, 111 .target = redirect_target,
110 .targetsize = sizeof(struct ip_nat_multi_range_compat), 112 .targetsize = sizeof(struct ip_nat_multi_range_compat),
111 .table = "nat", 113 .table = "nat",
@@ -116,12 +118,12 @@ static struct ipt_target redirect_reg = {
116 118
117static int __init ipt_redirect_init(void) 119static int __init ipt_redirect_init(void)
118{ 120{
119 return ipt_register_target(&redirect_reg); 121 return xt_register_target(&redirect_reg);
120} 122}
121 123
122static void __exit ipt_redirect_fini(void) 124static void __exit ipt_redirect_fini(void)
123{ 125{
124 ipt_unregister_target(&redirect_reg); 126 xt_unregister_target(&redirect_reg);
125} 127}
126 128
127module_init(ipt_redirect_init); 129module_init(ipt_redirect_init);
diff --git a/net/ipv4/netfilter/ipt_REJECT.c b/net/ipv4/netfilter/ipt_REJECT.c
index f0319e5ee437..a9eb3635fff2 100644
--- a/net/ipv4/netfilter/ipt_REJECT.c
+++ b/net/ipv4/netfilter/ipt_REJECT.c
@@ -22,6 +22,7 @@
22#include <net/tcp.h> 22#include <net/tcp.h>
23#include <net/route.h> 23#include <net/route.h>
24#include <net/dst.h> 24#include <net/dst.h>
25#include <linux/netfilter/x_tables.h>
25#include <linux/netfilter_ipv4/ip_tables.h> 26#include <linux/netfilter_ipv4/ip_tables.h>
26#include <linux/netfilter_ipv4/ipt_REJECT.h> 27#include <linux/netfilter_ipv4/ipt_REJECT.h>
27#ifdef CONFIG_BRIDGE_NETFILTER 28#ifdef CONFIG_BRIDGE_NETFILTER
@@ -56,7 +57,7 @@ static void send_reset(struct sk_buff *oldskb, int hook)
56 oth = skb_header_pointer(oldskb, oldskb->nh.iph->ihl * 4, 57 oth = skb_header_pointer(oldskb, oldskb->nh.iph->ihl * 4,
57 sizeof(_otcph), &_otcph); 58 sizeof(_otcph), &_otcph);
58 if (oth == NULL) 59 if (oth == NULL)
59 return; 60 return;
60 61
61 /* No RST for RST. */ 62 /* No RST for RST. */
62 if (oth->rst) 63 if (oth->rst)
@@ -116,7 +117,7 @@ static void send_reset(struct sk_buff *oldskb, int hook)
116 117
117 /* Adjust TCP checksum */ 118 /* Adjust TCP checksum */
118 tcph->check = 0; 119 tcph->check = 0;
119 tcph->check = tcp_v4_check(tcph, sizeof(struct tcphdr), 120 tcph->check = tcp_v4_check(sizeof(struct tcphdr),
120 nskb->nh.iph->saddr, 121 nskb->nh.iph->saddr,
121 nskb->nh.iph->daddr, 122 nskb->nh.iph->daddr,
122 csum_partial((char *)tcph, 123 csum_partial((char *)tcph,
@@ -144,7 +145,7 @@ static void send_reset(struct sk_buff *oldskb, int hook)
144 145
145 /* Adjust IP checksum */ 146 /* Adjust IP checksum */
146 nskb->nh.iph->check = 0; 147 nskb->nh.iph->check = 0;
147 nskb->nh.iph->check = ip_fast_csum((unsigned char *)nskb->nh.iph, 148 nskb->nh.iph->check = ip_fast_csum((unsigned char *)nskb->nh.iph,
148 nskb->nh.iph->ihl); 149 nskb->nh.iph->ihl);
149 150
150 /* "Never happens" */ 151 /* "Never happens" */
@@ -164,7 +165,7 @@ static void send_reset(struct sk_buff *oldskb, int hook)
164static inline void send_unreach(struct sk_buff *skb_in, int code) 165static inline void send_unreach(struct sk_buff *skb_in, int code)
165{ 166{
166 icmp_send(skb_in, ICMP_DEST_UNREACH, code, 0); 167 icmp_send(skb_in, ICMP_DEST_UNREACH, code, 0);
167} 168}
168 169
169static unsigned int reject(struct sk_buff **pskb, 170static unsigned int reject(struct sk_buff **pskb,
170 const struct net_device *in, 171 const struct net_device *in,
@@ -176,33 +177,33 @@ static unsigned int reject(struct sk_buff **pskb,
176 const struct ipt_reject_info *reject = targinfo; 177 const struct ipt_reject_info *reject = targinfo;
177 178
178 /* Our naive response construction doesn't deal with IP 179 /* Our naive response construction doesn't deal with IP
179 options, and probably shouldn't try. */ 180 options, and probably shouldn't try. */
180 if ((*pskb)->nh.iph->ihl<<2 != sizeof(struct iphdr)) 181 if ((*pskb)->nh.iph->ihl<<2 != sizeof(struct iphdr))
181 return NF_DROP; 182 return NF_DROP;
182 183
183 /* WARNING: This code causes reentry within iptables. 184 /* WARNING: This code causes reentry within iptables.
184 This means that the iptables jump stack is now crap. We 185 This means that the iptables jump stack is now crap. We
185 must return an absolute verdict. --RR */ 186 must return an absolute verdict. --RR */
186 switch (reject->with) { 187 switch (reject->with) {
187 case IPT_ICMP_NET_UNREACHABLE: 188 case IPT_ICMP_NET_UNREACHABLE:
188 send_unreach(*pskb, ICMP_NET_UNREACH); 189 send_unreach(*pskb, ICMP_NET_UNREACH);
189 break; 190 break;
190 case IPT_ICMP_HOST_UNREACHABLE: 191 case IPT_ICMP_HOST_UNREACHABLE:
191 send_unreach(*pskb, ICMP_HOST_UNREACH); 192 send_unreach(*pskb, ICMP_HOST_UNREACH);
192 break; 193 break;
193 case IPT_ICMP_PROT_UNREACHABLE: 194 case IPT_ICMP_PROT_UNREACHABLE:
194 send_unreach(*pskb, ICMP_PROT_UNREACH); 195 send_unreach(*pskb, ICMP_PROT_UNREACH);
195 break; 196 break;
196 case IPT_ICMP_PORT_UNREACHABLE: 197 case IPT_ICMP_PORT_UNREACHABLE:
197 send_unreach(*pskb, ICMP_PORT_UNREACH); 198 send_unreach(*pskb, ICMP_PORT_UNREACH);
198 break; 199 break;
199 case IPT_ICMP_NET_PROHIBITED: 200 case IPT_ICMP_NET_PROHIBITED:
200 send_unreach(*pskb, ICMP_NET_ANO); 201 send_unreach(*pskb, ICMP_NET_ANO);
201 break; 202 break;
202 case IPT_ICMP_HOST_PROHIBITED: 203 case IPT_ICMP_HOST_PROHIBITED:
203 send_unreach(*pskb, ICMP_HOST_ANO); 204 send_unreach(*pskb, ICMP_HOST_ANO);
204 break; 205 break;
205 case IPT_ICMP_ADMIN_PROHIBITED: 206 case IPT_ICMP_ADMIN_PROHIBITED:
206 send_unreach(*pskb, ICMP_PKT_FILTERED); 207 send_unreach(*pskb, ICMP_PKT_FILTERED);
207 break; 208 break;
208 case IPT_TCP_RESET: 209 case IPT_TCP_RESET:
@@ -221,7 +222,7 @@ static int check(const char *tablename,
221 void *targinfo, 222 void *targinfo,
222 unsigned int hook_mask) 223 unsigned int hook_mask)
223{ 224{
224 const struct ipt_reject_info *rejinfo = targinfo; 225 const struct ipt_reject_info *rejinfo = targinfo;
225 const struct ipt_entry *e = e_void; 226 const struct ipt_entry *e = e_void;
226 227
227 if (rejinfo->with == IPT_ICMP_ECHOREPLY) { 228 if (rejinfo->with == IPT_ICMP_ECHOREPLY) {
@@ -230,7 +231,7 @@ static int check(const char *tablename,
230 } else if (rejinfo->with == IPT_TCP_RESET) { 231 } else if (rejinfo->with == IPT_TCP_RESET) {
231 /* Must specify that it's a TCP packet */ 232 /* Must specify that it's a TCP packet */
232 if (e->ip.proto != IPPROTO_TCP 233 if (e->ip.proto != IPPROTO_TCP
233 || (e->ip.invflags & IPT_INV_PROTO)) { 234 || (e->ip.invflags & XT_INV_PROTO)) {
234 DEBUGP("REJECT: TCP_RESET invalid for non-tcp\n"); 235 DEBUGP("REJECT: TCP_RESET invalid for non-tcp\n");
235 return 0; 236 return 0;
236 } 237 }
@@ -238,8 +239,9 @@ static int check(const char *tablename,
238 return 1; 239 return 1;
239} 240}
240 241
241static struct ipt_target ipt_reject_reg = { 242static struct xt_target ipt_reject_reg = {
242 .name = "REJECT", 243 .name = "REJECT",
244 .family = AF_INET,
243 .target = reject, 245 .target = reject,
244 .targetsize = sizeof(struct ipt_reject_info), 246 .targetsize = sizeof(struct ipt_reject_info),
245 .table = "filter", 247 .table = "filter",
@@ -251,12 +253,12 @@ static struct ipt_target ipt_reject_reg = {
251 253
252static int __init ipt_reject_init(void) 254static int __init ipt_reject_init(void)
253{ 255{
254 return ipt_register_target(&ipt_reject_reg); 256 return xt_register_target(&ipt_reject_reg);
255} 257}
256 258
257static void __exit ipt_reject_fini(void) 259static void __exit ipt_reject_fini(void)
258{ 260{
259 ipt_unregister_target(&ipt_reject_reg); 261 xt_unregister_target(&ipt_reject_reg);
260} 262}
261 263
262module_init(ipt_reject_init); 264module_init(ipt_reject_init);
diff --git a/net/ipv4/netfilter/ipt_SAME.c b/net/ipv4/netfilter/ipt_SAME.c
index 3dcf29411337..bd4404e5c688 100644
--- a/net/ipv4/netfilter/ipt_SAME.c
+++ b/net/ipv4/netfilter/ipt_SAME.c
@@ -34,6 +34,7 @@
34#include <net/protocol.h> 34#include <net/protocol.h>
35#include <net/checksum.h> 35#include <net/checksum.h>
36#include <linux/netfilter_ipv4.h> 36#include <linux/netfilter_ipv4.h>
37#include <linux/netfilter/x_tables.h>
37#ifdef CONFIG_NF_NAT_NEEDED 38#ifdef CONFIG_NF_NAT_NEEDED
38#include <net/netfilter/nf_nat_rule.h> 39#include <net/netfilter/nf_nat_rule.h>
39#else 40#else
@@ -86,24 +87,24 @@ same_check(const char *tablename,
86 DEBUGP("same_check: bad MAP_IPS.\n"); 87 DEBUGP("same_check: bad MAP_IPS.\n");
87 return 0; 88 return 0;
88 } 89 }
89 rangeip = (ntohl(mr->range[count].max_ip) - 90 rangeip = (ntohl(mr->range[count].max_ip) -
90 ntohl(mr->range[count].min_ip) + 1); 91 ntohl(mr->range[count].min_ip) + 1);
91 mr->ipnum += rangeip; 92 mr->ipnum += rangeip;
92 93
93 DEBUGP("same_check: range %u, ipnum = %u\n", count, rangeip); 94 DEBUGP("same_check: range %u, ipnum = %u\n", count, rangeip);
94 } 95 }
95 DEBUGP("same_check: total ipaddresses = %u\n", mr->ipnum); 96 DEBUGP("same_check: total ipaddresses = %u\n", mr->ipnum);
96 97
97 mr->iparray = kmalloc((sizeof(u_int32_t) * mr->ipnum), GFP_KERNEL); 98 mr->iparray = kmalloc((sizeof(u_int32_t) * mr->ipnum), GFP_KERNEL);
98 if (!mr->iparray) { 99 if (!mr->iparray) {
99 DEBUGP("same_check: Couldn't allocate %u bytes " 100 DEBUGP("same_check: Couldn't allocate %u bytes "
100 "for %u ipaddresses!\n", 101 "for %u ipaddresses!\n",
101 (sizeof(u_int32_t) * mr->ipnum), mr->ipnum); 102 (sizeof(u_int32_t) * mr->ipnum), mr->ipnum);
102 return 0; 103 return 0;
103 } 104 }
104 DEBUGP("same_check: Allocated %u bytes for %u ipaddresses.\n", 105 DEBUGP("same_check: Allocated %u bytes for %u ipaddresses.\n",
105 (sizeof(u_int32_t) * mr->ipnum), mr->ipnum); 106 (sizeof(u_int32_t) * mr->ipnum), mr->ipnum);
106 107
107 for (count = 0; count < mr->rangesize; count++) { 108 for (count = 0; count < mr->rangesize; count++) {
108 for (countess = ntohl(mr->range[count].min_ip); 109 for (countess = ntohl(mr->range[count].min_ip);
109 countess <= ntohl(mr->range[count].max_ip); 110 countess <= ntohl(mr->range[count].max_ip);
@@ -118,13 +119,13 @@ same_check(const char *tablename,
118 return 1; 119 return 1;
119} 120}
120 121
121static void 122static void
122same_destroy(const struct xt_target *target, void *targinfo) 123same_destroy(const struct xt_target *target, void *targinfo)
123{ 124{
124 struct ipt_same_info *mr = targinfo; 125 struct ipt_same_info *mr = targinfo;
125 126
126 kfree(mr->iparray); 127 kfree(mr->iparray);
127 128
128 DEBUGP("same_destroy: Deallocated %u bytes for %u ipaddresses.\n", 129 DEBUGP("same_destroy: Deallocated %u bytes for %u ipaddresses.\n",
129 (sizeof(u_int32_t) * mr->ipnum), mr->ipnum); 130 (sizeof(u_int32_t) * mr->ipnum), mr->ipnum);
130} 131}
@@ -155,7 +156,7 @@ same_target(struct sk_buff **pskb,
155 giving some hope for consistency across reboots. 156 giving some hope for consistency across reboots.
156 Here we calculate the index in same->iparray which 157 Here we calculate the index in same->iparray which
157 holds the ipaddress we should use */ 158 holds the ipaddress we should use */
158 159
159#ifdef CONFIG_NF_NAT_NEEDED 160#ifdef CONFIG_NF_NAT_NEEDED
160 tmpip = ntohl(t->src.u3.ip); 161 tmpip = ntohl(t->src.u3.ip);
161 162
@@ -186,8 +187,9 @@ same_target(struct sk_buff **pskb,
186 return ip_nat_setup_info(ct, &newrange, hooknum); 187 return ip_nat_setup_info(ct, &newrange, hooknum);
187} 188}
188 189
189static struct ipt_target same_reg = { 190static struct xt_target same_reg = {
190 .name = "SAME", 191 .name = "SAME",
192 .family = AF_INET,
191 .target = same_target, 193 .target = same_target,
192 .targetsize = sizeof(struct ipt_same_info), 194 .targetsize = sizeof(struct ipt_same_info),
193 .table = "nat", 195 .table = "nat",
@@ -199,12 +201,12 @@ static struct ipt_target same_reg = {
199 201
200static int __init ipt_same_init(void) 202static int __init ipt_same_init(void)
201{ 203{
202 return ipt_register_target(&same_reg); 204 return xt_register_target(&same_reg);
203} 205}
204 206
205static void __exit ipt_same_fini(void) 207static void __exit ipt_same_fini(void)
206{ 208{
207 ipt_unregister_target(&same_reg); 209 xt_unregister_target(&same_reg);
208} 210}
209 211
210module_init(ipt_same_init); 212module_init(ipt_same_init);
diff --git a/net/ipv4/netfilter/ipt_TCPMSS.c b/net/ipv4/netfilter/ipt_TCPMSS.c
deleted file mode 100644
index 93eb5c3c1884..000000000000
--- a/net/ipv4/netfilter/ipt_TCPMSS.c
+++ /dev/null
@@ -1,207 +0,0 @@
1/*
2 * This is a module which is used for setting the MSS option in TCP packets.
3 *
4 * Copyright (C) 2000 Marc Boucher <marc@mbsi.ca>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
10
11#include <linux/module.h>
12#include <linux/skbuff.h>
13
14#include <linux/ip.h>
15#include <net/tcp.h>
16
17#include <linux/netfilter_ipv4/ip_tables.h>
18#include <linux/netfilter_ipv4/ipt_TCPMSS.h>
19
20MODULE_LICENSE("GPL");
21MODULE_AUTHOR("Marc Boucher <marc@mbsi.ca>");
22MODULE_DESCRIPTION("iptables TCP MSS modification module");
23
24static inline unsigned int
25optlen(const u_int8_t *opt, unsigned int offset)
26{
27 /* Beware zero-length options: make finite progress */
28 if (opt[offset] <= TCPOPT_NOP || opt[offset+1] == 0)
29 return 1;
30 else
31 return opt[offset+1];
32}
33
34static unsigned int
35ipt_tcpmss_target(struct sk_buff **pskb,
36 const struct net_device *in,
37 const struct net_device *out,
38 unsigned int hooknum,
39 const struct xt_target *target,
40 const void *targinfo)
41{
42 const struct ipt_tcpmss_info *tcpmssinfo = targinfo;
43 struct tcphdr *tcph;
44 struct iphdr *iph;
45 u_int16_t tcplen, newmss;
46 __be16 newtotlen, oldval;
47 unsigned int i;
48 u_int8_t *opt;
49
50 if (!skb_make_writable(pskb, (*pskb)->len))
51 return NF_DROP;
52
53 iph = (*pskb)->nh.iph;
54 tcplen = (*pskb)->len - iph->ihl*4;
55 tcph = (void *)iph + iph->ihl*4;
56
57 /* Since it passed flags test in tcp match, we know it is is
58 not a fragment, and has data >= tcp header length. SYN
59 packets should not contain data: if they did, then we risk
60 running over MTU, sending Frag Needed and breaking things
61 badly. --RR */
62 if (tcplen != tcph->doff*4) {
63 if (net_ratelimit())
64 printk(KERN_ERR
65 "ipt_tcpmss_target: bad length (%d bytes)\n",
66 (*pskb)->len);
67 return NF_DROP;
68 }
69
70 if (tcpmssinfo->mss == IPT_TCPMSS_CLAMP_PMTU) {
71 if (dst_mtu((*pskb)->dst) <= sizeof(struct iphdr) +
72 sizeof(struct tcphdr)) {
73 if (net_ratelimit())
74 printk(KERN_ERR "ipt_tcpmss_target: "
75 "unknown or invalid path-MTU (%d)\n",
76 dst_mtu((*pskb)->dst));
77 return NF_DROP; /* or IPT_CONTINUE ?? */
78 }
79
80 newmss = dst_mtu((*pskb)->dst) - sizeof(struct iphdr) -
81 sizeof(struct tcphdr);
82 } else
83 newmss = tcpmssinfo->mss;
84
85 opt = (u_int8_t *)tcph;
86 for (i = sizeof(struct tcphdr); i < tcph->doff*4; i += optlen(opt, i)) {
87 if (opt[i] == TCPOPT_MSS && tcph->doff*4 - i >= TCPOLEN_MSS &&
88 opt[i+1] == TCPOLEN_MSS) {
89 u_int16_t oldmss;
90
91 oldmss = (opt[i+2] << 8) | opt[i+3];
92
93 if (tcpmssinfo->mss == IPT_TCPMSS_CLAMP_PMTU &&
94 oldmss <= newmss)
95 return IPT_CONTINUE;
96
97 opt[i+2] = (newmss & 0xff00) >> 8;
98 opt[i+3] = (newmss & 0x00ff);
99
100 nf_proto_csum_replace2(&tcph->check, *pskb,
101 htons(oldmss), htons(newmss), 0);
102 return IPT_CONTINUE;
103 }
104 }
105
106 /*
107 * MSS Option not found ?! add it..
108 */
109 if (skb_tailroom((*pskb)) < TCPOLEN_MSS) {
110 struct sk_buff *newskb;
111
112 newskb = skb_copy_expand(*pskb, skb_headroom(*pskb),
113 TCPOLEN_MSS, GFP_ATOMIC);
114 if (!newskb)
115 return NF_DROP;
116 kfree_skb(*pskb);
117 *pskb = newskb;
118 iph = (*pskb)->nh.iph;
119 tcph = (void *)iph + iph->ihl*4;
120 }
121
122 skb_put((*pskb), TCPOLEN_MSS);
123
124 opt = (u_int8_t *)tcph + sizeof(struct tcphdr);
125 memmove(opt + TCPOLEN_MSS, opt, tcplen - sizeof(struct tcphdr));
126
127 nf_proto_csum_replace2(&tcph->check, *pskb,
128 htons(tcplen), htons(tcplen + TCPOLEN_MSS), 1);
129 opt[0] = TCPOPT_MSS;
130 opt[1] = TCPOLEN_MSS;
131 opt[2] = (newmss & 0xff00) >> 8;
132 opt[3] = (newmss & 0x00ff);
133
134 nf_proto_csum_replace4(&tcph->check, *pskb, 0, *((__be32 *)opt), 0);
135
136 oldval = ((__be16 *)tcph)[6];
137 tcph->doff += TCPOLEN_MSS/4;
138 nf_proto_csum_replace2(&tcph->check, *pskb,
139 oldval, ((__be16 *)tcph)[6], 0);
140
141 newtotlen = htons(ntohs(iph->tot_len) + TCPOLEN_MSS);
142 nf_csum_replace2(&iph->check, iph->tot_len, newtotlen);
143 iph->tot_len = newtotlen;
144 return IPT_CONTINUE;
145}
146
147#define TH_SYN 0x02
148
149static inline int find_syn_match(const struct ipt_entry_match *m)
150{
151 const struct ipt_tcp *tcpinfo = (const struct ipt_tcp *)m->data;
152
153 if (strcmp(m->u.kernel.match->name, "tcp") == 0 &&
154 tcpinfo->flg_cmp & TH_SYN &&
155 !(tcpinfo->invflags & IPT_TCP_INV_FLAGS))
156 return 1;
157
158 return 0;
159}
160
161/* Must specify -p tcp --syn/--tcp-flags SYN */
162static int
163ipt_tcpmss_checkentry(const char *tablename,
164 const void *e_void,
165 const struct xt_target *target,
166 void *targinfo,
167 unsigned int hook_mask)
168{
169 const struct ipt_tcpmss_info *tcpmssinfo = targinfo;
170 const struct ipt_entry *e = e_void;
171
172 if (tcpmssinfo->mss == IPT_TCPMSS_CLAMP_PMTU &&
173 (hook_mask & ~((1 << NF_IP_FORWARD) |
174 (1 << NF_IP_LOCAL_OUT) |
175 (1 << NF_IP_POST_ROUTING))) != 0) {
176 printk("TCPMSS: path-MTU clamping only supported in "
177 "FORWARD, OUTPUT and POSTROUTING hooks\n");
178 return 0;
179 }
180
181 if (IPT_MATCH_ITERATE(e, find_syn_match))
182 return 1;
183 printk("TCPMSS: Only works on TCP SYN packets\n");
184 return 0;
185}
186
187static struct ipt_target ipt_tcpmss_reg = {
188 .name = "TCPMSS",
189 .target = ipt_tcpmss_target,
190 .targetsize = sizeof(struct ipt_tcpmss_info),
191 .proto = IPPROTO_TCP,
192 .checkentry = ipt_tcpmss_checkentry,
193 .me = THIS_MODULE,
194};
195
196static int __init ipt_tcpmss_init(void)
197{
198 return ipt_register_target(&ipt_tcpmss_reg);
199}
200
201static void __exit ipt_tcpmss_fini(void)
202{
203 ipt_unregister_target(&ipt_tcpmss_reg);
204}
205
206module_init(ipt_tcpmss_init);
207module_exit(ipt_tcpmss_fini);
diff --git a/net/ipv4/netfilter/ipt_TOS.c b/net/ipv4/netfilter/ipt_TOS.c
index 18e74ac4d425..cedf9f7d9d6e 100644
--- a/net/ipv4/netfilter/ipt_TOS.c
+++ b/net/ipv4/netfilter/ipt_TOS.c
@@ -13,7 +13,7 @@
13#include <linux/ip.h> 13#include <linux/ip.h>
14#include <net/checksum.h> 14#include <net/checksum.h>
15 15
16#include <linux/netfilter_ipv4/ip_tables.h> 16#include <linux/netfilter/x_tables.h>
17#include <linux/netfilter_ipv4/ipt_TOS.h> 17#include <linux/netfilter_ipv4/ipt_TOS.h>
18 18
19MODULE_LICENSE("GPL"); 19MODULE_LICENSE("GPL");
@@ -40,15 +40,15 @@ target(struct sk_buff **pskb,
40 iph->tos = (iph->tos & IPTOS_PREC_MASK) | tosinfo->tos; 40 iph->tos = (iph->tos & IPTOS_PREC_MASK) | tosinfo->tos;
41 nf_csum_replace2(&iph->check, htons(oldtos), htons(iph->tos)); 41 nf_csum_replace2(&iph->check, htons(oldtos), htons(iph->tos));
42 } 42 }
43 return IPT_CONTINUE; 43 return XT_CONTINUE;
44} 44}
45 45
46static int 46static int
47checkentry(const char *tablename, 47checkentry(const char *tablename,
48 const void *e_void, 48 const void *e_void,
49 const struct xt_target *target, 49 const struct xt_target *target,
50 void *targinfo, 50 void *targinfo,
51 unsigned int hook_mask) 51 unsigned int hook_mask)
52{ 52{
53 const u_int8_t tos = ((struct ipt_tos_target_info *)targinfo)->tos; 53 const u_int8_t tos = ((struct ipt_tos_target_info *)targinfo)->tos;
54 54
@@ -63,8 +63,9 @@ checkentry(const char *tablename,
63 return 1; 63 return 1;
64} 64}
65 65
66static struct ipt_target ipt_tos_reg = { 66static struct xt_target ipt_tos_reg = {
67 .name = "TOS", 67 .name = "TOS",
68 .family = AF_INET,
68 .target = target, 69 .target = target,
69 .targetsize = sizeof(struct ipt_tos_target_info), 70 .targetsize = sizeof(struct ipt_tos_target_info),
70 .table = "mangle", 71 .table = "mangle",
@@ -74,12 +75,12 @@ static struct ipt_target ipt_tos_reg = {
74 75
75static int __init ipt_tos_init(void) 76static int __init ipt_tos_init(void)
76{ 77{
77 return ipt_register_target(&ipt_tos_reg); 78 return xt_register_target(&ipt_tos_reg);
78} 79}
79 80
80static void __exit ipt_tos_fini(void) 81static void __exit ipt_tos_fini(void)
81{ 82{
82 ipt_unregister_target(&ipt_tos_reg); 83 xt_unregister_target(&ipt_tos_reg);
83} 84}
84 85
85module_init(ipt_tos_init); 86module_init(ipt_tos_init);
diff --git a/net/ipv4/netfilter/ipt_TTL.c b/net/ipv4/netfilter/ipt_TTL.c
index fffe5ca82e91..64be31c22ba9 100644
--- a/net/ipv4/netfilter/ipt_TTL.c
+++ b/net/ipv4/netfilter/ipt_TTL.c
@@ -12,14 +12,14 @@
12#include <linux/ip.h> 12#include <linux/ip.h>
13#include <net/checksum.h> 13#include <net/checksum.h>
14 14
15#include <linux/netfilter_ipv4/ip_tables.h> 15#include <linux/netfilter/x_tables.h>
16#include <linux/netfilter_ipv4/ipt_TTL.h> 16#include <linux/netfilter_ipv4/ipt_TTL.h>
17 17
18MODULE_AUTHOR("Harald Welte <laforge@netfilter.org>"); 18MODULE_AUTHOR("Harald Welte <laforge@netfilter.org>");
19MODULE_DESCRIPTION("IP tables TTL modification module"); 19MODULE_DESCRIPTION("IP tables TTL modification module");
20MODULE_LICENSE("GPL"); 20MODULE_LICENSE("GPL");
21 21
22static unsigned int 22static unsigned int
23ipt_ttl_target(struct sk_buff **pskb, 23ipt_ttl_target(struct sk_buff **pskb,
24 const struct net_device *in, const struct net_device *out, 24 const struct net_device *in, const struct net_device *out,
25 unsigned int hooknum, const struct xt_target *target, 25 unsigned int hooknum, const struct xt_target *target,
@@ -59,7 +59,7 @@ ipt_ttl_target(struct sk_buff **pskb,
59 iph->ttl = new_ttl; 59 iph->ttl = new_ttl;
60 } 60 }
61 61
62 return IPT_CONTINUE; 62 return XT_CONTINUE;
63} 63}
64 64
65static int ipt_ttl_checkentry(const char *tablename, 65static int ipt_ttl_checkentry(const char *tablename,
@@ -71,7 +71,7 @@ static int ipt_ttl_checkentry(const char *tablename,
71 struct ipt_TTL_info *info = targinfo; 71 struct ipt_TTL_info *info = targinfo;
72 72
73 if (info->mode > IPT_TTL_MAXMODE) { 73 if (info->mode > IPT_TTL_MAXMODE) {
74 printk(KERN_WARNING "ipt_TTL: invalid or unknown Mode %u\n", 74 printk(KERN_WARNING "ipt_TTL: invalid or unknown Mode %u\n",
75 info->mode); 75 info->mode);
76 return 0; 76 return 0;
77 } 77 }
@@ -80,23 +80,24 @@ static int ipt_ttl_checkentry(const char *tablename,
80 return 1; 80 return 1;
81} 81}
82 82
83static struct ipt_target ipt_TTL = { 83static struct xt_target ipt_TTL = {
84 .name = "TTL", 84 .name = "TTL",
85 .target = ipt_ttl_target, 85 .family = AF_INET,
86 .target = ipt_ttl_target,
86 .targetsize = sizeof(struct ipt_TTL_info), 87 .targetsize = sizeof(struct ipt_TTL_info),
87 .table = "mangle", 88 .table = "mangle",
88 .checkentry = ipt_ttl_checkentry, 89 .checkentry = ipt_ttl_checkentry,
89 .me = THIS_MODULE, 90 .me = THIS_MODULE,
90}; 91};
91 92
92static int __init ipt_ttl_init(void) 93static int __init ipt_ttl_init(void)
93{ 94{
94 return ipt_register_target(&ipt_TTL); 95 return xt_register_target(&ipt_TTL);
95} 96}
96 97
97static void __exit ipt_ttl_fini(void) 98static void __exit ipt_ttl_fini(void)
98{ 99{
99 ipt_unregister_target(&ipt_TTL); 100 xt_unregister_target(&ipt_TTL);
100} 101}
101 102
102module_init(ipt_ttl_init); 103module_init(ipt_ttl_init);
diff --git a/net/ipv4/netfilter/ipt_ULOG.c b/net/ipv4/netfilter/ipt_ULOG.c
index dbd34783a64d..a26404dbe212 100644
--- a/net/ipv4/netfilter/ipt_ULOG.c
+++ b/net/ipv4/netfilter/ipt_ULOG.c
@@ -4,9 +4,9 @@
4 * (C) 2000-2004 by Harald Welte <laforge@netfilter.org> 4 * (C) 2000-2004 by Harald Welte <laforge@netfilter.org>
5 * 5 *
6 * 2000/09/22 ulog-cprange feature added 6 * 2000/09/22 ulog-cprange feature added
7 * 2001/01/04 in-kernel queue as proposed by Sebastian Zander 7 * 2001/01/04 in-kernel queue as proposed by Sebastian Zander
8 * <zander@fokus.gmd.de> 8 * <zander@fokus.gmd.de>
9 * 2001/01/30 per-rule nlgroup conflicts with global queue. 9 * 2001/01/30 per-rule nlgroup conflicts with global queue.
10 * nlgroup now global (sysctl) 10 * nlgroup now global (sysctl)
11 * 2001/04/19 ulog-queue reworked, now fixed buffer size specified at 11 * 2001/04/19 ulog-queue reworked, now fixed buffer size specified at
12 * module loadtime -HW 12 * module loadtime -HW
@@ -23,8 +23,8 @@
23 * it under the terms of the GNU General Public License version 2 as 23 * it under the terms of the GNU General Public License version 2 as
24 * published by the Free Software Foundation. 24 * published by the Free Software Foundation.
25 * 25 *
26 * This module accepts two parameters: 26 * This module accepts two parameters:
27 * 27 *
28 * nlbufsiz: 28 * nlbufsiz:
29 * The parameter specifies how big the buffer for each netlink multicast 29 * The parameter specifies how big the buffer for each netlink multicast
30 * group is. e.g. If you say nlbufsiz=8192, up to eight kb of packets will 30 * group is. e.g. If you say nlbufsiz=8192, up to eight kb of packets will
@@ -57,7 +57,7 @@
57#include <linux/mm.h> 57#include <linux/mm.h>
58#include <linux/moduleparam.h> 58#include <linux/moduleparam.h>
59#include <linux/netfilter.h> 59#include <linux/netfilter.h>
60#include <linux/netfilter_ipv4/ip_tables.h> 60#include <linux/netfilter/x_tables.h>
61#include <linux/netfilter_ipv4/ipt_ULOG.h> 61#include <linux/netfilter_ipv4/ipt_ULOG.h>
62#include <net/sock.h> 62#include <net/sock.h>
63#include <linux/bitops.h> 63#include <linux/bitops.h>
@@ -72,7 +72,7 @@ MODULE_ALIAS_NET_PF_PROTO(PF_NETLINK, NETLINK_NFLOG);
72 72
73#if 0 73#if 0
74#define DEBUGP(format, args...) printk("%s:%s:" format, \ 74#define DEBUGP(format, args...) printk("%s:%s:" format, \
75 __FILE__, __FUNCTION__ , ## args) 75 __FILE__, __FUNCTION__ , ## args)
76#else 76#else
77#define DEBUGP(format, args...) 77#define DEBUGP(format, args...)
78#endif 78#endif
@@ -132,7 +132,6 @@ static void ulog_send(unsigned int nlgroupnum)
132 ub->qlen = 0; 132 ub->qlen = 0;
133 ub->skb = NULL; 133 ub->skb = NULL;
134 ub->lastnlh = NULL; 134 ub->lastnlh = NULL;
135
136} 135}
137 136
138 137
@@ -163,7 +162,7 @@ static struct sk_buff *ulog_alloc_skb(unsigned int size)
163 PRINTR("ipt_ULOG: can't alloc whole buffer %ub!\n", n); 162 PRINTR("ipt_ULOG: can't alloc whole buffer %ub!\n", n);
164 163
165 if (n > size) { 164 if (n > size) {
166 /* try to allocate only as much as we need for 165 /* try to allocate only as much as we need for
167 * current packet */ 166 * current packet */
168 167
169 skb = alloc_skb(size, GFP_ATOMIC); 168 skb = alloc_skb(size, GFP_ATOMIC);
@@ -204,7 +203,7 @@ static void ipt_ulog_packet(unsigned int hooknum,
204 size = NLMSG_SPACE(sizeof(*pm) + copy_len); 203 size = NLMSG_SPACE(sizeof(*pm) + copy_len);
205 204
206 ub = &ulog_buffers[groupnum]; 205 ub = &ulog_buffers[groupnum];
207 206
208 spin_lock_bh(&ulog_lock); 207 spin_lock_bh(&ulog_lock);
209 208
210 if (!ub->skb) { 209 if (!ub->skb) {
@@ -212,7 +211,7 @@ static void ipt_ulog_packet(unsigned int hooknum,
212 goto alloc_failure; 211 goto alloc_failure;
213 } else if (ub->qlen >= loginfo->qthreshold || 212 } else if (ub->qlen >= loginfo->qthreshold ||
214 size > skb_tailroom(ub->skb)) { 213 size > skb_tailroom(ub->skb)) {
215 /* either the queue len is too high or we don't have 214 /* either the queue len is too high or we don't have
216 * enough room in nlskb left. send it to userspace. */ 215 * enough room in nlskb left. send it to userspace. */
217 216
218 ulog_send(groupnum); 217 ulog_send(groupnum);
@@ -221,11 +220,11 @@ static void ipt_ulog_packet(unsigned int hooknum,
221 goto alloc_failure; 220 goto alloc_failure;
222 } 221 }
223 222
224 DEBUGP("ipt_ULOG: qlen %d, qthreshold %d\n", ub->qlen, 223 DEBUGP("ipt_ULOG: qlen %d, qthreshold %d\n", ub->qlen,
225 loginfo->qthreshold); 224 loginfo->qthreshold);
226 225
227 /* NLMSG_PUT contains a hidden goto nlmsg_failure !!! */ 226 /* NLMSG_PUT contains a hidden goto nlmsg_failure !!! */
228 nlh = NLMSG_PUT(ub->skb, 0, ub->qlen, ULOG_NL_EVENT, 227 nlh = NLMSG_PUT(ub->skb, 0, ub->qlen, ULOG_NL_EVENT,
229 sizeof(*pm)+copy_len); 228 sizeof(*pm)+copy_len);
230 ub->qlen++; 229 ub->qlen++;
231 230
@@ -269,7 +268,7 @@ static void ipt_ulog_packet(unsigned int hooknum,
269 /* copy_len <= skb->len, so can't fail. */ 268 /* copy_len <= skb->len, so can't fail. */
270 if (skb_copy_bits(skb, 0, pm->payload, copy_len) < 0) 269 if (skb_copy_bits(skb, 0, pm->payload, copy_len) < 0)
271 BUG(); 270 BUG();
272 271
273 /* check if we are building multi-part messages */ 272 /* check if we are building multi-part messages */
274 if (ub->qlen > 1) { 273 if (ub->qlen > 1) {
275 ub->lastnlh->nlmsg_flags |= NLM_F_MULTI; 274 ub->lastnlh->nlmsg_flags |= NLM_F_MULTI;
@@ -313,10 +312,10 @@ static unsigned int ipt_ulog_target(struct sk_buff **pskb,
313 struct ipt_ulog_info *loginfo = (struct ipt_ulog_info *) targinfo; 312 struct ipt_ulog_info *loginfo = (struct ipt_ulog_info *) targinfo;
314 313
315 ipt_ulog_packet(hooknum, *pskb, in, out, loginfo, NULL); 314 ipt_ulog_packet(hooknum, *pskb, in, out, loginfo, NULL);
316 315
317 return IPT_CONTINUE; 316 return XT_CONTINUE;
318} 317}
319 318
320static void ipt_logfn(unsigned int pf, 319static void ipt_logfn(unsigned int pf,
321 unsigned int hooknum, 320 unsigned int hooknum,
322 const struct sk_buff *skb, 321 const struct sk_buff *skb,
@@ -363,8 +362,9 @@ static int ipt_ulog_checkentry(const char *tablename,
363 return 1; 362 return 1;
364} 363}
365 364
366static struct ipt_target ipt_ulog_reg = { 365static struct xt_target ipt_ulog_reg = {
367 .name = "ULOG", 366 .name = "ULOG",
367 .family = AF_INET,
368 .target = ipt_ulog_target, 368 .target = ipt_ulog_target,
369 .targetsize = sizeof(struct ipt_ulog_info), 369 .targetsize = sizeof(struct ipt_ulog_info),
370 .checkentry = ipt_ulog_checkentry, 370 .checkentry = ipt_ulog_checkentry,
@@ -379,7 +379,7 @@ static struct nf_logger ipt_ulog_logger = {
379 379
380static int __init ipt_ulog_init(void) 380static int __init ipt_ulog_init(void)
381{ 381{
382 int i; 382 int ret, i;
383 383
384 DEBUGP("ipt_ULOG: init module\n"); 384 DEBUGP("ipt_ULOG: init module\n");
385 385
@@ -396,17 +396,18 @@ static int __init ipt_ulog_init(void)
396 } 396 }
397 397
398 nflognl = netlink_kernel_create(NETLINK_NFLOG, ULOG_MAXNLGROUPS, NULL, 398 nflognl = netlink_kernel_create(NETLINK_NFLOG, ULOG_MAXNLGROUPS, NULL,
399 THIS_MODULE); 399 THIS_MODULE);
400 if (!nflognl) 400 if (!nflognl)
401 return -ENOMEM; 401 return -ENOMEM;
402 402
403 if (ipt_register_target(&ipt_ulog_reg) != 0) { 403 ret = xt_register_target(&ipt_ulog_reg);
404 if (ret < 0) {
404 sock_release(nflognl->sk_socket); 405 sock_release(nflognl->sk_socket);
405 return -EINVAL; 406 return ret;
406 } 407 }
407 if (nflog) 408 if (nflog)
408 nf_log_register(PF_INET, &ipt_ulog_logger); 409 nf_log_register(PF_INET, &ipt_ulog_logger);
409 410
410 return 0; 411 return 0;
411} 412}
412 413
@@ -418,8 +419,8 @@ static void __exit ipt_ulog_fini(void)
418 DEBUGP("ipt_ULOG: cleanup_module\n"); 419 DEBUGP("ipt_ULOG: cleanup_module\n");
419 420
420 if (nflog) 421 if (nflog)
421 nf_log_unregister_logger(&ipt_ulog_logger); 422 nf_log_unregister(&ipt_ulog_logger);
422 ipt_unregister_target(&ipt_ulog_reg); 423 xt_unregister_target(&ipt_ulog_reg);
423 sock_release(nflognl->sk_socket); 424 sock_release(nflognl->sk_socket);
424 425
425 /* remove pending timers and free allocated skb's */ 426 /* remove pending timers and free allocated skb's */
@@ -435,7 +436,6 @@ static void __exit ipt_ulog_fini(void)
435 ub->skb = NULL; 436 ub->skb = NULL;
436 } 437 }
437 } 438 }
438
439} 439}
440 440
441module_init(ipt_ulog_init); 441module_init(ipt_ulog_init);
diff --git a/net/ipv4/netfilter/ipt_addrtype.c b/net/ipv4/netfilter/ipt_addrtype.c
index 7b60eb74788b..cfa0472617f6 100644
--- a/net/ipv4/netfilter/ipt_addrtype.c
+++ b/net/ipv4/netfilter/ipt_addrtype.c
@@ -16,7 +16,7 @@
16#include <net/route.h> 16#include <net/route.h>
17 17
18#include <linux/netfilter_ipv4/ipt_addrtype.h> 18#include <linux/netfilter_ipv4/ipt_addrtype.h>
19#include <linux/netfilter_ipv4/ip_tables.h> 19#include <linux/netfilter/x_tables.h>
20 20
21MODULE_LICENSE("GPL"); 21MODULE_LICENSE("GPL");
22MODULE_AUTHOR("Patrick McHardy <kaber@trash.net>"); 22MODULE_AUTHOR("Patrick McHardy <kaber@trash.net>");
@@ -40,12 +40,13 @@ static int match(const struct sk_buff *skb,
40 ret &= match_type(iph->saddr, info->source)^info->invert_source; 40 ret &= match_type(iph->saddr, info->source)^info->invert_source;
41 if (info->dest) 41 if (info->dest)
42 ret &= match_type(iph->daddr, info->dest)^info->invert_dest; 42 ret &= match_type(iph->daddr, info->dest)^info->invert_dest;
43 43
44 return ret; 44 return ret;
45} 45}
46 46
47static struct ipt_match addrtype_match = { 47static struct xt_match addrtype_match = {
48 .name = "addrtype", 48 .name = "addrtype",
49 .family = AF_INET,
49 .match = match, 50 .match = match,
50 .matchsize = sizeof(struct ipt_addrtype_info), 51 .matchsize = sizeof(struct ipt_addrtype_info),
51 .me = THIS_MODULE 52 .me = THIS_MODULE
@@ -53,12 +54,12 @@ static struct ipt_match addrtype_match = {
53 54
54static int __init ipt_addrtype_init(void) 55static int __init ipt_addrtype_init(void)
55{ 56{
56 return ipt_register_match(&addrtype_match); 57 return xt_register_match(&addrtype_match);
57} 58}
58 59
59static void __exit ipt_addrtype_fini(void) 60static void __exit ipt_addrtype_fini(void)
60{ 61{
61 ipt_unregister_match(&addrtype_match); 62 xt_unregister_match(&addrtype_match);
62} 63}
63 64
64module_init(ipt_addrtype_init); 65module_init(ipt_addrtype_init);
diff --git a/net/ipv4/netfilter/ipt_ah.c b/net/ipv4/netfilter/ipt_ah.c
index 1798f86bc534..18a16782cf40 100644
--- a/net/ipv4/netfilter/ipt_ah.c
+++ b/net/ipv4/netfilter/ipt_ah.c
@@ -6,12 +6,13 @@
6 * published by the Free Software Foundation. 6 * published by the Free Software Foundation.
7 */ 7 */
8 8
9#include <linux/in.h>
9#include <linux/module.h> 10#include <linux/module.h>
10#include <linux/skbuff.h> 11#include <linux/skbuff.h>
11#include <linux/ip.h> 12#include <linux/ip.h>
12 13
13#include <linux/netfilter_ipv4/ipt_ah.h> 14#include <linux/netfilter_ipv4/ipt_ah.h>
14#include <linux/netfilter_ipv4/ip_tables.h> 15#include <linux/netfilter/x_tables.h>
15 16
16MODULE_LICENSE("GPL"); 17MODULE_LICENSE("GPL");
17MODULE_AUTHOR("Yon Uriarte <yon@astaro.de>"); 18MODULE_AUTHOR("Yon Uriarte <yon@astaro.de>");
@@ -28,8 +29,8 @@ static inline int
28spi_match(u_int32_t min, u_int32_t max, u_int32_t spi, int invert) 29spi_match(u_int32_t min, u_int32_t max, u_int32_t spi, int invert)
29{ 30{
30 int r=0; 31 int r=0;
31 duprintf("ah spi_match:%c 0x%x <= 0x%x <= 0x%x",invert? '!':' ', 32 duprintf("ah spi_match:%c 0x%x <= 0x%x <= 0x%x",invert? '!':' ',
32 min,spi,max); 33 min,spi,max);
33 r=(spi >= min && spi <= max) ^ invert; 34 r=(spi >= min && spi <= max) ^ invert;
34 duprintf(" result %s\n",r? "PASS" : "FAILED"); 35 duprintf(" result %s\n",r? "PASS" : "FAILED");
35 return r; 36 return r;
@@ -86,8 +87,9 @@ checkentry(const char *tablename,
86 return 1; 87 return 1;
87} 88}
88 89
89static struct ipt_match ah_match = { 90static struct xt_match ah_match = {
90 .name = "ah", 91 .name = "ah",
92 .family = AF_INET,
91 .match = match, 93 .match = match,
92 .matchsize = sizeof(struct ipt_ah), 94 .matchsize = sizeof(struct ipt_ah),
93 .proto = IPPROTO_AH, 95 .proto = IPPROTO_AH,
@@ -97,12 +99,12 @@ static struct ipt_match ah_match = {
97 99
98static int __init ipt_ah_init(void) 100static int __init ipt_ah_init(void)
99{ 101{
100 return ipt_register_match(&ah_match); 102 return xt_register_match(&ah_match);
101} 103}
102 104
103static void __exit ipt_ah_fini(void) 105static void __exit ipt_ah_fini(void)
104{ 106{
105 ipt_unregister_match(&ah_match); 107 xt_unregister_match(&ah_match);
106} 108}
107 109
108module_init(ipt_ah_init); 110module_init(ipt_ah_init);
diff --git a/net/ipv4/netfilter/ipt_ecn.c b/net/ipv4/netfilter/ipt_ecn.c
index dafbdec0efc0..37508b2cfea6 100644
--- a/net/ipv4/netfilter/ipt_ecn.c
+++ b/net/ipv4/netfilter/ipt_ecn.c
@@ -9,10 +9,13 @@
9 * published by the Free Software Foundation. 9 * published by the Free Software Foundation.
10 */ 10 */
11 11
12#include <linux/in.h>
13#include <linux/ip.h>
12#include <linux/module.h> 14#include <linux/module.h>
13#include <linux/skbuff.h> 15#include <linux/skbuff.h>
14#include <linux/tcp.h> 16#include <linux/tcp.h>
15 17
18#include <linux/netfilter/x_tables.h>
16#include <linux/netfilter_ipv4/ip_tables.h> 19#include <linux/netfilter_ipv4/ip_tables.h>
17#include <linux/netfilter_ipv4/ipt_ecn.h> 20#include <linux/netfilter_ipv4/ipt_ecn.h>
18 21
@@ -109,8 +112,9 @@ static int checkentry(const char *tablename, const void *ip_void,
109 return 1; 112 return 1;
110} 113}
111 114
112static struct ipt_match ecn_match = { 115static struct xt_match ecn_match = {
113 .name = "ecn", 116 .name = "ecn",
117 .family = AF_INET,
114 .match = match, 118 .match = match,
115 .matchsize = sizeof(struct ipt_ecn_info), 119 .matchsize = sizeof(struct ipt_ecn_info),
116 .checkentry = checkentry, 120 .checkentry = checkentry,
@@ -119,12 +123,12 @@ static struct ipt_match ecn_match = {
119 123
120static int __init ipt_ecn_init(void) 124static int __init ipt_ecn_init(void)
121{ 125{
122 return ipt_register_match(&ecn_match); 126 return xt_register_match(&ecn_match);
123} 127}
124 128
125static void __exit ipt_ecn_fini(void) 129static void __exit ipt_ecn_fini(void)
126{ 130{
127 ipt_unregister_match(&ecn_match); 131 xt_unregister_match(&ecn_match);
128} 132}
129 133
130module_init(ipt_ecn_init); 134module_init(ipt_ecn_init);
diff --git a/net/ipv4/netfilter/ipt_iprange.c b/net/ipv4/netfilter/ipt_iprange.c
index 5202edd8d333..bc5d5e6091e4 100644
--- a/net/ipv4/netfilter/ipt_iprange.c
+++ b/net/ipv4/netfilter/ipt_iprange.c
@@ -10,7 +10,7 @@
10#include <linux/module.h> 10#include <linux/module.h>
11#include <linux/skbuff.h> 11#include <linux/skbuff.h>
12#include <linux/ip.h> 12#include <linux/ip.h>
13#include <linux/netfilter_ipv4/ip_tables.h> 13#include <linux/netfilter/x_tables.h>
14#include <linux/netfilter_ipv4/ipt_iprange.h> 14#include <linux/netfilter_ipv4/ipt_iprange.h>
15 15
16MODULE_LICENSE("GPL"); 16MODULE_LICENSE("GPL");
@@ -41,7 +41,7 @@ match(const struct sk_buff *skb,
41 DEBUGP("src IP %u.%u.%u.%u NOT in range %s" 41 DEBUGP("src IP %u.%u.%u.%u NOT in range %s"
42 "%u.%u.%u.%u-%u.%u.%u.%u\n", 42 "%u.%u.%u.%u-%u.%u.%u.%u\n",
43 NIPQUAD(iph->saddr), 43 NIPQUAD(iph->saddr),
44 info->flags & IPRANGE_SRC_INV ? "(INV) " : "", 44 info->flags & IPRANGE_SRC_INV ? "(INV) " : "",
45 NIPQUAD(info->src.min_ip), 45 NIPQUAD(info->src.min_ip),
46 NIPQUAD(info->src.max_ip)); 46 NIPQUAD(info->src.max_ip));
47 return 0; 47 return 0;
@@ -54,7 +54,7 @@ match(const struct sk_buff *skb,
54 DEBUGP("dst IP %u.%u.%u.%u NOT in range %s" 54 DEBUGP("dst IP %u.%u.%u.%u NOT in range %s"
55 "%u.%u.%u.%u-%u.%u.%u.%u\n", 55 "%u.%u.%u.%u-%u.%u.%u.%u\n",
56 NIPQUAD(iph->daddr), 56 NIPQUAD(iph->daddr),
57 info->flags & IPRANGE_DST_INV ? "(INV) " : "", 57 info->flags & IPRANGE_DST_INV ? "(INV) " : "",
58 NIPQUAD(info->dst.min_ip), 58 NIPQUAD(info->dst.min_ip),
59 NIPQUAD(info->dst.max_ip)); 59 NIPQUAD(info->dst.max_ip));
60 return 0; 60 return 0;
@@ -63,22 +63,22 @@ match(const struct sk_buff *skb,
63 return 1; 63 return 1;
64} 64}
65 65
66static struct ipt_match iprange_match = { 66static struct xt_match iprange_match = {
67 .name = "iprange", 67 .name = "iprange",
68 .family = AF_INET,
68 .match = match, 69 .match = match,
69 .matchsize = sizeof(struct ipt_iprange_info), 70 .matchsize = sizeof(struct ipt_iprange_info),
70 .destroy = NULL,
71 .me = THIS_MODULE 71 .me = THIS_MODULE
72}; 72};
73 73
74static int __init ipt_iprange_init(void) 74static int __init ipt_iprange_init(void)
75{ 75{
76 return ipt_register_match(&iprange_match); 76 return xt_register_match(&iprange_match);
77} 77}
78 78
79static void __exit ipt_iprange_fini(void) 79static void __exit ipt_iprange_fini(void)
80{ 80{
81 ipt_unregister_match(&iprange_match); 81 xt_unregister_match(&iprange_match);
82} 82}
83 83
84module_init(ipt_iprange_init); 84module_init(ipt_iprange_init);
diff --git a/net/ipv4/netfilter/ipt_owner.c b/net/ipv4/netfilter/ipt_owner.c
index 78c336f12a9e..7fae9aa8944c 100644
--- a/net/ipv4/netfilter/ipt_owner.c
+++ b/net/ipv4/netfilter/ipt_owner.c
@@ -15,7 +15,7 @@
15#include <net/sock.h> 15#include <net/sock.h>
16 16
17#include <linux/netfilter_ipv4/ipt_owner.h> 17#include <linux/netfilter_ipv4/ipt_owner.h>
18#include <linux/netfilter_ipv4/ip_tables.h> 18#include <linux/netfilter/x_tables.h>
19 19
20MODULE_LICENSE("GPL"); 20MODULE_LICENSE("GPL");
21MODULE_AUTHOR("Marc Boucher <marc@mbsi.ca>"); 21MODULE_AUTHOR("Marc Boucher <marc@mbsi.ca>");
@@ -53,10 +53,10 @@ match(const struct sk_buff *skb,
53 53
54static int 54static int
55checkentry(const char *tablename, 55checkentry(const char *tablename,
56 const void *ip, 56 const void *ip,
57 const struct xt_match *match, 57 const struct xt_match *match,
58 void *matchinfo, 58 void *matchinfo,
59 unsigned int hook_mask) 59 unsigned int hook_mask)
60{ 60{
61 const struct ipt_owner_info *info = matchinfo; 61 const struct ipt_owner_info *info = matchinfo;
62 62
@@ -68,8 +68,9 @@ checkentry(const char *tablename,
68 return 1; 68 return 1;
69} 69}
70 70
71static struct ipt_match owner_match = { 71static struct xt_match owner_match = {
72 .name = "owner", 72 .name = "owner",
73 .family = AF_INET,
73 .match = match, 74 .match = match,
74 .matchsize = sizeof(struct ipt_owner_info), 75 .matchsize = sizeof(struct ipt_owner_info),
75 .hooks = (1 << NF_IP_LOCAL_OUT) | (1 << NF_IP_POST_ROUTING), 76 .hooks = (1 << NF_IP_LOCAL_OUT) | (1 << NF_IP_POST_ROUTING),
@@ -79,12 +80,12 @@ static struct ipt_match owner_match = {
79 80
80static int __init ipt_owner_init(void) 81static int __init ipt_owner_init(void)
81{ 82{
82 return ipt_register_match(&owner_match); 83 return xt_register_match(&owner_match);
83} 84}
84 85
85static void __exit ipt_owner_fini(void) 86static void __exit ipt_owner_fini(void)
86{ 87{
87 ipt_unregister_match(&owner_match); 88 xt_unregister_match(&owner_match);
88} 89}
89 90
90module_init(ipt_owner_init); 91module_init(ipt_owner_init);
diff --git a/net/ipv4/netfilter/ipt_recent.c b/net/ipv4/netfilter/ipt_recent.c
index 4db0e73c56f1..aecb9c48e152 100644
--- a/net/ipv4/netfilter/ipt_recent.c
+++ b/net/ipv4/netfilter/ipt_recent.c
@@ -12,6 +12,7 @@
12 * Copyright 2002-2003, Stephen Frost, 2.5.x port by laforge@netfilter.org 12 * Copyright 2002-2003, Stephen Frost, 2.5.x port by laforge@netfilter.org
13 */ 13 */
14#include <linux/init.h> 14#include <linux/init.h>
15#include <linux/ip.h>
15#include <linux/moduleparam.h> 16#include <linux/moduleparam.h>
16#include <linux/proc_fs.h> 17#include <linux/proc_fs.h>
17#include <linux/seq_file.h> 18#include <linux/seq_file.h>
@@ -24,7 +25,7 @@
24#include <linux/skbuff.h> 25#include <linux/skbuff.h>
25#include <linux/inet.h> 26#include <linux/inet.h>
26 27
27#include <linux/netfilter_ipv4/ip_tables.h> 28#include <linux/netfilter/x_tables.h>
28#include <linux/netfilter_ipv4/ipt_recent.h> 29#include <linux/netfilter_ipv4/ipt_recent.h>
29 30
30MODULE_AUTHOR("Patrick McHardy <kaber@trash.net>"); 31MODULE_AUTHOR("Patrick McHardy <kaber@trash.net>");
@@ -78,7 +79,7 @@ static DEFINE_MUTEX(recent_mutex);
78 79
79#ifdef CONFIG_PROC_FS 80#ifdef CONFIG_PROC_FS
80static struct proc_dir_entry *proc_dir; 81static struct proc_dir_entry *proc_dir;
81static struct file_operations recent_fops; 82static const struct file_operations recent_fops;
82#endif 83#endif
83 84
84static u_int32_t hash_rnd; 85static u_int32_t hash_rnd;
@@ -453,7 +454,7 @@ static ssize_t recent_proc_write(struct file *file, const char __user *input,
453 return size; 454 return size;
454} 455}
455 456
456static struct file_operations recent_fops = { 457static const struct file_operations recent_fops = {
457 .open = recent_seq_open, 458 .open = recent_seq_open,
458 .read = seq_read, 459 .read = seq_read,
459 .write = recent_proc_write, 460 .write = recent_proc_write,
@@ -462,8 +463,9 @@ static struct file_operations recent_fops = {
462}; 463};
463#endif /* CONFIG_PROC_FS */ 464#endif /* CONFIG_PROC_FS */
464 465
465static struct ipt_match recent_match = { 466static struct xt_match recent_match = {
466 .name = "recent", 467 .name = "recent",
468 .family = AF_INET,
467 .match = ipt_recent_match, 469 .match = ipt_recent_match,
468 .matchsize = sizeof(struct ipt_recent_info), 470 .matchsize = sizeof(struct ipt_recent_info),
469 .checkentry = ipt_recent_checkentry, 471 .checkentry = ipt_recent_checkentry,
@@ -479,13 +481,13 @@ static int __init ipt_recent_init(void)
479 return -EINVAL; 481 return -EINVAL;
480 ip_list_hash_size = 1 << fls(ip_list_tot); 482 ip_list_hash_size = 1 << fls(ip_list_tot);
481 483
482 err = ipt_register_match(&recent_match); 484 err = xt_register_match(&recent_match);
483#ifdef CONFIG_PROC_FS 485#ifdef CONFIG_PROC_FS
484 if (err) 486 if (err)
485 return err; 487 return err;
486 proc_dir = proc_mkdir("ipt_recent", proc_net); 488 proc_dir = proc_mkdir("ipt_recent", proc_net);
487 if (proc_dir == NULL) { 489 if (proc_dir == NULL) {
488 ipt_unregister_match(&recent_match); 490 xt_unregister_match(&recent_match);
489 err = -ENOMEM; 491 err = -ENOMEM;
490 } 492 }
491#endif 493#endif
@@ -495,7 +497,7 @@ static int __init ipt_recent_init(void)
495static void __exit ipt_recent_exit(void) 497static void __exit ipt_recent_exit(void)
496{ 498{
497 BUG_ON(!list_empty(&tables)); 499 BUG_ON(!list_empty(&tables));
498 ipt_unregister_match(&recent_match); 500 xt_unregister_match(&recent_match);
499#ifdef CONFIG_PROC_FS 501#ifdef CONFIG_PROC_FS
500 remove_proc_entry("ipt_recent", proc_net); 502 remove_proc_entry("ipt_recent", proc_net);
501#endif 503#endif
diff --git a/net/ipv4/netfilter/ipt_tos.c b/net/ipv4/netfilter/ipt_tos.c
index 5549c39c7851..5d33b51d49d8 100644
--- a/net/ipv4/netfilter/ipt_tos.c
+++ b/net/ipv4/netfilter/ipt_tos.c
@@ -8,11 +8,12 @@
8 * published by the Free Software Foundation. 8 * published by the Free Software Foundation.
9 */ 9 */
10 10
11#include <linux/ip.h>
11#include <linux/module.h> 12#include <linux/module.h>
12#include <linux/skbuff.h> 13#include <linux/skbuff.h>
13 14
14#include <linux/netfilter_ipv4/ipt_tos.h> 15#include <linux/netfilter_ipv4/ipt_tos.h>
15#include <linux/netfilter_ipv4/ip_tables.h> 16#include <linux/netfilter/x_tables.h>
16 17
17MODULE_LICENSE("GPL"); 18MODULE_LICENSE("GPL");
18MODULE_DESCRIPTION("iptables TOS match module"); 19MODULE_DESCRIPTION("iptables TOS match module");
@@ -32,8 +33,9 @@ match(const struct sk_buff *skb,
32 return (skb->nh.iph->tos == info->tos) ^ info->invert; 33 return (skb->nh.iph->tos == info->tos) ^ info->invert;
33} 34}
34 35
35static struct ipt_match tos_match = { 36static struct xt_match tos_match = {
36 .name = "tos", 37 .name = "tos",
38 .family = AF_INET,
37 .match = match, 39 .match = match,
38 .matchsize = sizeof(struct ipt_tos_info), 40 .matchsize = sizeof(struct ipt_tos_info),
39 .me = THIS_MODULE, 41 .me = THIS_MODULE,
@@ -41,12 +43,12 @@ static struct ipt_match tos_match = {
41 43
42static int __init ipt_multiport_init(void) 44static int __init ipt_multiport_init(void)
43{ 45{
44 return ipt_register_match(&tos_match); 46 return xt_register_match(&tos_match);
45} 47}
46 48
47static void __exit ipt_multiport_fini(void) 49static void __exit ipt_multiport_fini(void)
48{ 50{
49 ipt_unregister_match(&tos_match); 51 xt_unregister_match(&tos_match);
50} 52}
51 53
52module_init(ipt_multiport_init); 54module_init(ipt_multiport_init);
diff --git a/net/ipv4/netfilter/ipt_ttl.c b/net/ipv4/netfilter/ipt_ttl.c
index a5243bdb87d7..1eca9f400374 100644
--- a/net/ipv4/netfilter/ipt_ttl.c
+++ b/net/ipv4/netfilter/ipt_ttl.c
@@ -1,4 +1,4 @@
1/* IP tables module for matching the value of the TTL 1/* IP tables module for matching the value of the TTL
2 * 2 *
3 * ipt_ttl.c,v 1.5 2000/11/13 11:16:08 laforge Exp 3 * ipt_ttl.c,v 1.5 2000/11/13 11:16:08 laforge Exp
4 * 4 *
@@ -9,11 +9,12 @@
9 * published by the Free Software Foundation. 9 * published by the Free Software Foundation.
10 */ 10 */
11 11
12#include <linux/ip.h>
12#include <linux/module.h> 13#include <linux/module.h>
13#include <linux/skbuff.h> 14#include <linux/skbuff.h>
14 15
15#include <linux/netfilter_ipv4/ipt_ttl.h> 16#include <linux/netfilter_ipv4/ipt_ttl.h>
16#include <linux/netfilter_ipv4/ip_tables.h> 17#include <linux/netfilter/x_tables.h>
17 18
18MODULE_AUTHOR("Harald Welte <laforge@netfilter.org>"); 19MODULE_AUTHOR("Harald Welte <laforge@netfilter.org>");
19MODULE_DESCRIPTION("IP tables TTL matching module"); 20MODULE_DESCRIPTION("IP tables TTL matching module");
@@ -40,7 +41,7 @@ static int match(const struct sk_buff *skb,
40 return (skb->nh.iph->ttl > info->ttl); 41 return (skb->nh.iph->ttl > info->ttl);
41 break; 42 break;
42 default: 43 default:
43 printk(KERN_WARNING "ipt_ttl: unknown mode %d\n", 44 printk(KERN_WARNING "ipt_ttl: unknown mode %d\n",
44 info->mode); 45 info->mode);
45 return 0; 46 return 0;
46 } 47 }
@@ -48,8 +49,9 @@ static int match(const struct sk_buff *skb,
48 return 0; 49 return 0;
49} 50}
50 51
51static struct ipt_match ttl_match = { 52static struct xt_match ttl_match = {
52 .name = "ttl", 53 .name = "ttl",
54 .family = AF_INET,
53 .match = match, 55 .match = match,
54 .matchsize = sizeof(struct ipt_ttl_info), 56 .matchsize = sizeof(struct ipt_ttl_info),
55 .me = THIS_MODULE, 57 .me = THIS_MODULE,
@@ -57,13 +59,12 @@ static struct ipt_match ttl_match = {
57 59
58static int __init ipt_ttl_init(void) 60static int __init ipt_ttl_init(void)
59{ 61{
60 return ipt_register_match(&ttl_match); 62 return xt_register_match(&ttl_match);
61} 63}
62 64
63static void __exit ipt_ttl_fini(void) 65static void __exit ipt_ttl_fini(void)
64{ 66{
65 ipt_unregister_match(&ttl_match); 67 xt_unregister_match(&ttl_match);
66
67} 68}
68 69
69module_init(ipt_ttl_init); 70module_init(ipt_ttl_init);
diff --git a/net/ipv4/netfilter/iptable_filter.c b/net/ipv4/netfilter/iptable_filter.c
index e2e7dd8d7903..d1d61e97b976 100644
--- a/net/ipv4/netfilter/iptable_filter.c
+++ b/net/ipv4/netfilter/iptable_filter.c
@@ -25,7 +25,7 @@ static struct
25 struct ipt_replace repl; 25 struct ipt_replace repl;
26 struct ipt_standard entries[3]; 26 struct ipt_standard entries[3];
27 struct ipt_error term; 27 struct ipt_error term;
28} initial_table __initdata 28} initial_table __initdata
29= { { "filter", FILTER_VALID_HOOKS, 4, 29= { { "filter", FILTER_VALID_HOOKS, 4,
30 sizeof(struct ipt_standard) * 3 + sizeof(struct ipt_error), 30 sizeof(struct ipt_standard) * 3 + sizeof(struct ipt_error),
31 { [NF_IP_LOCAL_IN] = 0, 31 { [NF_IP_LOCAL_IN] = 0,
@@ -74,7 +74,7 @@ static struct
74 } 74 }
75}; 75};
76 76
77static struct ipt_table packet_filter = { 77static struct xt_table packet_filter = {
78 .name = "filter", 78 .name = "filter",
79 .valid_hooks = FILTER_VALID_HOOKS, 79 .valid_hooks = FILTER_VALID_HOOKS,
80 .lock = RW_LOCK_UNLOCKED, 80 .lock = RW_LOCK_UNLOCKED,
diff --git a/net/ipv4/netfilter/iptable_mangle.c b/net/ipv4/netfilter/iptable_mangle.c
index af2939889444..98b66ef0c714 100644
--- a/net/ipv4/netfilter/iptable_mangle.c
+++ b/net/ipv4/netfilter/iptable_mangle.c
@@ -58,7 +58,7 @@ static struct
58 { { { { IPT_ALIGN(sizeof(struct ipt_standard_target)), "" } }, { } }, 58 { { { { IPT_ALIGN(sizeof(struct ipt_standard_target)), "" } }, { } },
59 -NF_ACCEPT - 1 } }, 59 -NF_ACCEPT - 1 } },
60 /* LOCAL_IN */ 60 /* LOCAL_IN */
61 { { { { 0 }, { 0 }, { 0 }, { 0 }, "", "", { 0 }, { 0 }, 0, 0, 0 }, 61 { { { { 0 }, { 0 }, { 0 }, { 0 }, "", "", { 0 }, { 0 }, 0, 0, 0 },
62 0, 62 0,
63 sizeof(struct ipt_entry), 63 sizeof(struct ipt_entry),
64 sizeof(struct ipt_standard), 64 sizeof(struct ipt_standard),
@@ -66,7 +66,7 @@ static struct
66 { { { { IPT_ALIGN(sizeof(struct ipt_standard_target)), "" } }, { } }, 66 { { { { IPT_ALIGN(sizeof(struct ipt_standard_target)), "" } }, { } },
67 -NF_ACCEPT - 1 } }, 67 -NF_ACCEPT - 1 } },
68 /* FORWARD */ 68 /* FORWARD */
69 { { { { 0 }, { 0 }, { 0 }, { 0 }, "", "", { 0 }, { 0 }, 0, 0, 0 }, 69 { { { { 0 }, { 0 }, { 0 }, { 0 }, "", "", { 0 }, { 0 }, 0, 0, 0 },
70 0, 70 0,
71 sizeof(struct ipt_entry), 71 sizeof(struct ipt_entry),
72 sizeof(struct ipt_standard), 72 sizeof(struct ipt_standard),
@@ -103,7 +103,7 @@ static struct
103 } 103 }
104}; 104};
105 105
106static struct ipt_table packet_mangler = { 106static struct xt_table packet_mangler = {
107 .name = "mangle", 107 .name = "mangle",
108 .valid_hooks = MANGLE_VALID_HOOKS, 108 .valid_hooks = MANGLE_VALID_HOOKS,
109 .lock = RW_LOCK_UNLOCKED, 109 .lock = RW_LOCK_UNLOCKED,
@@ -166,7 +166,7 @@ static struct nf_hook_ops ipt_ops[] = {
166 .hook = ipt_route_hook, 166 .hook = ipt_route_hook,
167 .owner = THIS_MODULE, 167 .owner = THIS_MODULE,
168 .pf = PF_INET, 168 .pf = PF_INET,
169 .hooknum = NF_IP_PRE_ROUTING, 169 .hooknum = NF_IP_PRE_ROUTING,
170 .priority = NF_IP_PRI_MANGLE, 170 .priority = NF_IP_PRI_MANGLE,
171 }, 171 },
172 { 172 {
diff --git a/net/ipv4/netfilter/iptable_raw.c b/net/ipv4/netfilter/iptable_raw.c
index bcbeb4aeacd9..18c3d4c9ff51 100644
--- a/net/ipv4/netfilter/iptable_raw.c
+++ b/net/ipv4/netfilter/iptable_raw.c
@@ -1,4 +1,4 @@
1/* 1/*
2 * 'raw' table, which is the very first hooked in at PRE_ROUTING and LOCAL_OUT . 2 * 'raw' table, which is the very first hooked in at PRE_ROUTING and LOCAL_OUT .
3 * 3 *
4 * Copyright (C) 2003 Jozsef Kadlecsik <kadlec@blackhole.kfki.hu> 4 * Copyright (C) 2003 Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
@@ -15,26 +15,26 @@ static struct
15 struct ipt_error term; 15 struct ipt_error term;
16} initial_table __initdata = { 16} initial_table __initdata = {
17 .repl = { 17 .repl = {
18 .name = "raw", 18 .name = "raw",
19 .valid_hooks = RAW_VALID_HOOKS, 19 .valid_hooks = RAW_VALID_HOOKS,
20 .num_entries = 3, 20 .num_entries = 3,
21 .size = sizeof(struct ipt_standard) * 2 + sizeof(struct ipt_error), 21 .size = sizeof(struct ipt_standard) * 2 + sizeof(struct ipt_error),
22 .hook_entry = { 22 .hook_entry = {
23 [NF_IP_PRE_ROUTING] = 0, 23 [NF_IP_PRE_ROUTING] = 0,
24 [NF_IP_LOCAL_OUT] = sizeof(struct ipt_standard) }, 24 [NF_IP_LOCAL_OUT] = sizeof(struct ipt_standard) },
25 .underflow = { 25 .underflow = {
26 [NF_IP_PRE_ROUTING] = 0, 26 [NF_IP_PRE_ROUTING] = 0,
27 [NF_IP_LOCAL_OUT] = sizeof(struct ipt_standard) }, 27 [NF_IP_LOCAL_OUT] = sizeof(struct ipt_standard) },
28 }, 28 },
29 .entries = { 29 .entries = {
30 /* PRE_ROUTING */ 30 /* PRE_ROUTING */
31 { 31 {
32 .entry = { 32 .entry = {
33 .target_offset = sizeof(struct ipt_entry), 33 .target_offset = sizeof(struct ipt_entry),
34 .next_offset = sizeof(struct ipt_standard), 34 .next_offset = sizeof(struct ipt_standard),
35 }, 35 },
36 .target = { 36 .target = {
37 .target = { 37 .target = {
38 .u = { 38 .u = {
39 .target_size = IPT_ALIGN(sizeof(struct ipt_standard_target)), 39 .target_size = IPT_ALIGN(sizeof(struct ipt_standard_target)),
40 }, 40 },
@@ -69,7 +69,7 @@ static struct
69 .target = { 69 .target = {
70 .u = { 70 .u = {
71 .user = { 71 .user = {
72 .target_size = IPT_ALIGN(sizeof(struct ipt_error_target)), 72 .target_size = IPT_ALIGN(sizeof(struct ipt_error_target)),
73 .name = IPT_ERROR_TARGET, 73 .name = IPT_ERROR_TARGET,
74 }, 74 },
75 }, 75 },
@@ -79,10 +79,10 @@ static struct
79 } 79 }
80}; 80};
81 81
82static struct ipt_table packet_raw = { 82static struct xt_table packet_raw = {
83 .name = "raw", 83 .name = "raw",
84 .valid_hooks = RAW_VALID_HOOKS, 84 .valid_hooks = RAW_VALID_HOOKS,
85 .lock = RW_LOCK_UNLOCKED, 85 .lock = RW_LOCK_UNLOCKED,
86 .me = THIS_MODULE, 86 .me = THIS_MODULE,
87 .af = AF_INET, 87 .af = AF_INET,
88}; 88};
diff --git a/net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c b/net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c
index 471b638cedec..b984db771258 100644
--- a/net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c
+++ b/net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c
@@ -66,7 +66,7 @@ static int ipv4_print_tuple(struct seq_file *s,
66 const struct nf_conntrack_tuple *tuple) 66 const struct nf_conntrack_tuple *tuple)
67{ 67{
68 return seq_printf(s, "src=%u.%u.%u.%u dst=%u.%u.%u.%u ", 68 return seq_printf(s, "src=%u.%u.%u.%u dst=%u.%u.%u.%u ",
69 NIPQUAD(tuple->src.u3.ip), 69 NIPQUAD(tuple->src.u3.ip),
70 NIPQUAD(tuple->dst.u3.ip)); 70 NIPQUAD(tuple->dst.u3.ip));
71} 71}
72 72
@@ -82,14 +82,14 @@ nf_ct_ipv4_gather_frags(struct sk_buff *skb, u_int32_t user)
82{ 82{
83 skb_orphan(skb); 83 skb_orphan(skb);
84 84
85 local_bh_disable(); 85 local_bh_disable();
86 skb = ip_defrag(skb, user); 86 skb = ip_defrag(skb, user);
87 local_bh_enable(); 87 local_bh_enable();
88 88
89 if (skb) 89 if (skb)
90 ip_send_check(skb->nh.iph); 90 ip_send_check(skb->nh.iph);
91 91
92 return skb; 92 return skb;
93} 93}
94 94
95static int 95static int
@@ -192,10 +192,10 @@ static unsigned int ipv4_conntrack_in(unsigned int hooknum,
192} 192}
193 193
194static unsigned int ipv4_conntrack_local(unsigned int hooknum, 194static unsigned int ipv4_conntrack_local(unsigned int hooknum,
195 struct sk_buff **pskb, 195 struct sk_buff **pskb,
196 const struct net_device *in, 196 const struct net_device *in,
197 const struct net_device *out, 197 const struct net_device *out,
198 int (*okfn)(struct sk_buff *)) 198 int (*okfn)(struct sk_buff *))
199{ 199{
200 /* root is playing with raw sockets. */ 200 /* root is playing with raw sockets. */
201 if ((*pskb)->len < sizeof(struct iphdr) 201 if ((*pskb)->len < sizeof(struct iphdr)
@@ -332,7 +332,7 @@ getorigdst(struct sock *sk, int optval, void __user *user, int *len)
332 struct inet_sock *inet = inet_sk(sk); 332 struct inet_sock *inet = inet_sk(sk);
333 struct nf_conntrack_tuple_hash *h; 333 struct nf_conntrack_tuple_hash *h;
334 struct nf_conntrack_tuple tuple; 334 struct nf_conntrack_tuple tuple;
335 335
336 NF_CT_TUPLE_U_BLANK(&tuple); 336 NF_CT_TUPLE_U_BLANK(&tuple);
337 tuple.src.u3.ip = inet->rcv_saddr; 337 tuple.src.u3.ip = inet->rcv_saddr;
338 tuple.src.u.tcp.port = inet->sport; 338 tuple.src.u.tcp.port = inet->sport;
@@ -501,7 +501,7 @@ static int __init nf_conntrack_l3proto_ipv4_init(void)
501 return ret; 501 return ret;
502#if defined(CONFIG_PROC_FS) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT) 502#if defined(CONFIG_PROC_FS) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT)
503 cleanup_hooks: 503 cleanup_hooks:
504 nf_unregister_hooks(ipv4_conntrack_ops, ARRAY_SIZE(ipv4_conntrack_ops)); 504 nf_unregister_hooks(ipv4_conntrack_ops, ARRAY_SIZE(ipv4_conntrack_ops));
505#endif 505#endif
506 cleanup_ipv4: 506 cleanup_ipv4:
507 nf_conntrack_l3proto_unregister(&nf_conntrack_l3proto_ipv4); 507 nf_conntrack_l3proto_unregister(&nf_conntrack_l3proto_ipv4);
diff --git a/net/ipv4/netfilter/nf_conntrack_l3proto_ipv4_compat.c b/net/ipv4/netfilter/nf_conntrack_l3proto_ipv4_compat.c
index 3b31bc649608..89f933e81035 100644
--- a/net/ipv4/netfilter/nf_conntrack_l3proto_ipv4_compat.c
+++ b/net/ipv4/netfilter/nf_conntrack_l3proto_ipv4_compat.c
@@ -135,7 +135,7 @@ static int ct_seq_show(struct seq_file *s, void *v)
135 l3proto, l4proto)) 135 l3proto, l4proto))
136 return -ENOSPC; 136 return -ENOSPC;
137 137
138 if (seq_print_counters(s, &ct->counters[IP_CT_DIR_ORIGINAL])) 138 if (seq_print_counters(s, &ct->counters[IP_CT_DIR_ORIGINAL]))
139 return -ENOSPC; 139 return -ENOSPC;
140 140
141 if (!(test_bit(IPS_SEEN_REPLY_BIT, &ct->status))) 141 if (!(test_bit(IPS_SEEN_REPLY_BIT, &ct->status)))
@@ -146,7 +146,7 @@ static int ct_seq_show(struct seq_file *s, void *v)
146 l3proto, l4proto)) 146 l3proto, l4proto))
147 return -ENOSPC; 147 return -ENOSPC;
148 148
149 if (seq_print_counters(s, &ct->counters[IP_CT_DIR_REPLY])) 149 if (seq_print_counters(s, &ct->counters[IP_CT_DIR_REPLY]))
150 return -ENOSPC; 150 return -ENOSPC;
151 151
152 if (test_bit(IPS_ASSURED_BIT, &ct->status)) 152 if (test_bit(IPS_ASSURED_BIT, &ct->status))
@@ -197,7 +197,7 @@ out_free:
197 return ret; 197 return ret;
198} 198}
199 199
200static struct file_operations ct_file_ops = { 200static const struct file_operations ct_file_ops = {
201 .owner = THIS_MODULE, 201 .owner = THIS_MODULE,
202 .open = ct_open, 202 .open = ct_open,
203 .read = seq_read, 203 .read = seq_read,
@@ -228,7 +228,7 @@ static void *exp_seq_start(struct seq_file *s, loff_t *pos)
228 228
229static void *exp_seq_next(struct seq_file *s, void *v, loff_t *pos) 229static void *exp_seq_next(struct seq_file *s, void *v, loff_t *pos)
230{ 230{
231 struct list_head *e = v; 231 struct list_head *e = v;
232 232
233 ++*pos; 233 ++*pos;
234 e = e->next; 234 e = e->next;
@@ -262,7 +262,7 @@ static int exp_seq_show(struct seq_file *s, void *v)
262 print_tuple(s, &exp->tuple, 262 print_tuple(s, &exp->tuple,
263 __nf_ct_l3proto_find(exp->tuple.src.l3num), 263 __nf_ct_l3proto_find(exp->tuple.src.l3num),
264 __nf_ct_l4proto_find(exp->tuple.src.l3num, 264 __nf_ct_l4proto_find(exp->tuple.src.l3num,
265 exp->tuple.dst.protonum)); 265 exp->tuple.dst.protonum));
266 return seq_putc(s, '\n'); 266 return seq_putc(s, '\n');
267} 267}
268 268
@@ -278,7 +278,7 @@ static int exp_open(struct inode *inode, struct file *file)
278 return seq_open(file, &exp_seq_ops); 278 return seq_open(file, &exp_seq_ops);
279} 279}
280 280
281static struct file_operations ip_exp_file_ops = { 281static const struct file_operations ip_exp_file_ops = {
282 .owner = THIS_MODULE, 282 .owner = THIS_MODULE,
283 .open = exp_open, 283 .open = exp_open,
284 .read = seq_read, 284 .read = seq_read,
@@ -366,7 +366,7 @@ static int ct_cpu_seq_open(struct inode *inode, struct file *file)
366 return seq_open(file, &ct_cpu_seq_ops); 366 return seq_open(file, &ct_cpu_seq_ops);
367} 367}
368 368
369static struct file_operations ct_cpu_seq_fops = { 369static const struct file_operations ct_cpu_seq_fops = {
370 .owner = THIS_MODULE, 370 .owner = THIS_MODULE,
371 .open = ct_cpu_seq_open, 371 .open = ct_cpu_seq_open,
372 .read = seq_read, 372 .read = seq_read,
diff --git a/net/ipv4/netfilter/nf_conntrack_proto_icmp.c b/net/ipv4/netfilter/nf_conntrack_proto_icmp.c
index db9e7c45d3b4..e5aa4d849b00 100644
--- a/net/ipv4/netfilter/nf_conntrack_proto_icmp.c
+++ b/net/ipv4/netfilter/nf_conntrack_proto_icmp.c
@@ -101,9 +101,9 @@ static int icmp_packet(struct nf_conn *ct,
101 unsigned int hooknum) 101 unsigned int hooknum)
102{ 102{
103 /* Try to delete connection immediately after all replies: 103 /* Try to delete connection immediately after all replies:
104 won't actually vanish as we still have skb, and del_timer 104 won't actually vanish as we still have skb, and del_timer
105 means this will only run once even if count hits zero twice 105 means this will only run once even if count hits zero twice
106 (theoretically possible with SMP) */ 106 (theoretically possible with SMP) */
107 if (CTINFO2DIR(ctinfo) == IP_CT_DIR_REPLY) { 107 if (CTINFO2DIR(ctinfo) == IP_CT_DIR_REPLY) {
108 if (atomic_dec_and_test(&ct->proto.icmp.count) 108 if (atomic_dec_and_test(&ct->proto.icmp.count)
109 && del_timer(&ct->timeout)) 109 && del_timer(&ct->timeout))
@@ -144,8 +144,8 @@ extern struct nf_conntrack_l3proto nf_conntrack_l3proto_ipv4;
144/* Returns conntrack if it dealt with ICMP, and filled in skb fields */ 144/* Returns conntrack if it dealt with ICMP, and filled in skb fields */
145static int 145static int
146icmp_error_message(struct sk_buff *skb, 146icmp_error_message(struct sk_buff *skb,
147 enum ip_conntrack_info *ctinfo, 147 enum ip_conntrack_info *ctinfo,
148 unsigned int hooknum) 148 unsigned int hooknum)
149{ 149{
150 struct nf_conntrack_tuple innertuple, origtuple; 150 struct nf_conntrack_tuple innertuple, origtuple;
151 struct { 151 struct {
@@ -170,7 +170,9 @@ icmp_error_message(struct sk_buff *skb,
170 return -NF_ACCEPT; 170 return -NF_ACCEPT;
171 } 171 }
172 172
173 /* rcu_read_lock()ed by nf_hook_slow */
173 innerproto = __nf_ct_l4proto_find(PF_INET, inside->ip.protocol); 174 innerproto = __nf_ct_l4proto_find(PF_INET, inside->ip.protocol);
175
174 dataoff = skb->nh.iph->ihl*4 + sizeof(inside->icmp); 176 dataoff = skb->nh.iph->ihl*4 + sizeof(inside->icmp);
175 /* Are they talking about one of our connections? */ 177 /* Are they talking about one of our connections? */
176 if (!nf_ct_get_tuple(skb, dataoff, dataoff + inside->ip.ihl*4, PF_INET, 178 if (!nf_ct_get_tuple(skb, dataoff, dataoff + inside->ip.ihl*4, PF_INET,
@@ -181,9 +183,9 @@ icmp_error_message(struct sk_buff *skb,
181 return -NF_ACCEPT; 183 return -NF_ACCEPT;
182 } 184 }
183 185
184 /* Ordinarily, we'd expect the inverted tupleproto, but it's 186 /* Ordinarily, we'd expect the inverted tupleproto, but it's
185 been preserved inside the ICMP. */ 187 been preserved inside the ICMP. */
186 if (!nf_ct_invert_tuple(&innertuple, &origtuple, 188 if (!nf_ct_invert_tuple(&innertuple, &origtuple,
187 &nf_conntrack_l3proto_ipv4, innerproto)) { 189 &nf_conntrack_l3proto_ipv4, innerproto)) {
188 DEBUGP("icmp_error_message: no match\n"); 190 DEBUGP("icmp_error_message: no match\n");
189 return -NF_ACCEPT; 191 return -NF_ACCEPT;
@@ -212,10 +214,10 @@ icmp_error_message(struct sk_buff *skb,
212 *ctinfo += IP_CT_IS_REPLY; 214 *ctinfo += IP_CT_IS_REPLY;
213 } 215 }
214 216
215 /* Update skb to refer to this connection */ 217 /* Update skb to refer to this connection */
216 skb->nfct = &nf_ct_tuplehash_to_ctrack(h)->ct_general; 218 skb->nfct = &nf_ct_tuplehash_to_ctrack(h)->ct_general;
217 skb->nfctinfo = *ctinfo; 219 skb->nfctinfo = *ctinfo;
218 return -NF_ACCEPT; 220 return -NF_ACCEPT;
219} 221}
220 222
221/* Small and modified version of icmp_rcv */ 223/* Small and modified version of icmp_rcv */
@@ -306,7 +308,7 @@ static int icmp_nfattr_to_tuple(struct nfattr *tb[],
306 if (nfattr_bad_size(tb, CTA_PROTO_MAX, cta_min_proto)) 308 if (nfattr_bad_size(tb, CTA_PROTO_MAX, cta_min_proto))
307 return -EINVAL; 309 return -EINVAL;
308 310
309 tuple->dst.u.icmp.type = 311 tuple->dst.u.icmp.type =
310 *(u_int8_t *)NFA_DATA(tb[CTA_PROTO_ICMP_TYPE-1]); 312 *(u_int8_t *)NFA_DATA(tb[CTA_PROTO_ICMP_TYPE-1]);
311 tuple->dst.u.icmp.code = 313 tuple->dst.u.icmp.code =
312 *(u_int8_t *)NFA_DATA(tb[CTA_PROTO_ICMP_CODE-1]); 314 *(u_int8_t *)NFA_DATA(tb[CTA_PROTO_ICMP_CODE-1]);
@@ -332,7 +334,7 @@ static struct ctl_table icmp_sysctl_table[] = {
332 .mode = 0644, 334 .mode = 0644,
333 .proc_handler = &proc_dointvec_jiffies, 335 .proc_handler = &proc_dointvec_jiffies,
334 }, 336 },
335 { 337 {
336 .ctl_name = 0 338 .ctl_name = 0
337 } 339 }
338}; 340};
@@ -346,7 +348,7 @@ static struct ctl_table icmp_compat_sysctl_table[] = {
346 .mode = 0644, 348 .mode = 0644,
347 .proc_handler = &proc_dointvec_jiffies, 349 .proc_handler = &proc_dointvec_jiffies,
348 }, 350 },
349 { 351 {
350 .ctl_name = 0 352 .ctl_name = 0
351 } 353 }
352}; 354};
diff --git a/net/ipv4/netfilter/nf_nat_core.c b/net/ipv4/netfilter/nf_nat_core.c
index 86a92272b053..2c01378d3592 100644
--- a/net/ipv4/netfilter/nf_nat_core.c
+++ b/net/ipv4/netfilter/nf_nat_core.c
@@ -53,7 +53,7 @@ static struct nf_nat_protocol *nf_nat_protos[MAX_IP_NAT_PROTO];
53static inline struct nf_nat_protocol * 53static inline struct nf_nat_protocol *
54__nf_nat_proto_find(u_int8_t protonum) 54__nf_nat_proto_find(u_int8_t protonum)
55{ 55{
56 return nf_nat_protos[protonum]; 56 return rcu_dereference(nf_nat_protos[protonum]);
57} 57}
58 58
59struct nf_nat_protocol * 59struct nf_nat_protocol *
@@ -61,13 +61,11 @@ nf_nat_proto_find_get(u_int8_t protonum)
61{ 61{
62 struct nf_nat_protocol *p; 62 struct nf_nat_protocol *p;
63 63
64 /* we need to disable preemption to make sure 'p' doesn't get 64 rcu_read_lock();
65 * removed until we've grabbed the reference */
66 preempt_disable();
67 p = __nf_nat_proto_find(protonum); 65 p = __nf_nat_proto_find(protonum);
68 if (!try_module_get(p->me)) 66 if (!try_module_get(p->me))
69 p = &nf_nat_unknown_protocol; 67 p = &nf_nat_unknown_protocol;
70 preempt_enable(); 68 rcu_read_unlock();
71 69
72 return p; 70 return p;
73} 71}
@@ -126,8 +124,8 @@ in_range(const struct nf_conntrack_tuple *tuple,
126 const struct nf_nat_range *range) 124 const struct nf_nat_range *range)
127{ 125{
128 struct nf_nat_protocol *proto; 126 struct nf_nat_protocol *proto;
127 int ret = 0;
129 128
130 proto = __nf_nat_proto_find(tuple->dst.protonum);
131 /* If we are supposed to map IPs, then we must be in the 129 /* If we are supposed to map IPs, then we must be in the
132 range specified, otherwise let this drag us onto a new src IP. */ 130 range specified, otherwise let this drag us onto a new src IP. */
133 if (range->flags & IP_NAT_RANGE_MAP_IPS) { 131 if (range->flags & IP_NAT_RANGE_MAP_IPS) {
@@ -136,12 +134,15 @@ in_range(const struct nf_conntrack_tuple *tuple,
136 return 0; 134 return 0;
137 } 135 }
138 136
137 rcu_read_lock();
138 proto = __nf_nat_proto_find(tuple->dst.protonum);
139 if (!(range->flags & IP_NAT_RANGE_PROTO_SPECIFIED) || 139 if (!(range->flags & IP_NAT_RANGE_PROTO_SPECIFIED) ||
140 proto->in_range(tuple, IP_NAT_MANIP_SRC, 140 proto->in_range(tuple, IP_NAT_MANIP_SRC,
141 &range->min, &range->max)) 141 &range->min, &range->max))
142 return 1; 142 ret = 1;
143 rcu_read_unlock();
143 144
144 return 0; 145 return ret;
145} 146}
146 147
147static inline int 148static inline int
@@ -254,8 +255,9 @@ get_unique_tuple(struct nf_conntrack_tuple *tuple,
254 if (maniptype == IP_NAT_MANIP_SRC) { 255 if (maniptype == IP_NAT_MANIP_SRC) {
255 if (find_appropriate_src(orig_tuple, tuple, range)) { 256 if (find_appropriate_src(orig_tuple, tuple, range)) {
256 DEBUGP("get_unique_tuple: Found current src map\n"); 257 DEBUGP("get_unique_tuple: Found current src map\n");
257 if (!nf_nat_used_tuple(tuple, ct)) 258 if (!(range->flags & IP_NAT_RANGE_PROTO_RANDOM))
258 return; 259 if (!nf_nat_used_tuple(tuple, ct))
260 return;
259 } 261 }
260 } 262 }
261 263
@@ -267,20 +269,25 @@ get_unique_tuple(struct nf_conntrack_tuple *tuple,
267 /* 3) The per-protocol part of the manip is made to map into 269 /* 3) The per-protocol part of the manip is made to map into
268 the range to make a unique tuple. */ 270 the range to make a unique tuple. */
269 271
270 proto = nf_nat_proto_find_get(orig_tuple->dst.protonum); 272 rcu_read_lock();
273 proto = __nf_nat_proto_find(orig_tuple->dst.protonum);
274
275 /* Change protocol info to have some randomization */
276 if (range->flags & IP_NAT_RANGE_PROTO_RANDOM) {
277 proto->unique_tuple(tuple, range, maniptype, ct);
278 goto out;
279 }
271 280
272 /* Only bother mapping if it's not already in range and unique */ 281 /* Only bother mapping if it's not already in range and unique */
273 if ((!(range->flags & IP_NAT_RANGE_PROTO_SPECIFIED) || 282 if ((!(range->flags & IP_NAT_RANGE_PROTO_SPECIFIED) ||
274 proto->in_range(tuple, maniptype, &range->min, &range->max)) && 283 proto->in_range(tuple, maniptype, &range->min, &range->max)) &&
275 !nf_nat_used_tuple(tuple, ct)) { 284 !nf_nat_used_tuple(tuple, ct))
276 nf_nat_proto_put(proto); 285 goto out;
277 return;
278 }
279 286
280 /* Last change: get protocol to try to obtain unique tuple. */ 287 /* Last change: get protocol to try to obtain unique tuple. */
281 proto->unique_tuple(tuple, range, maniptype, ct); 288 proto->unique_tuple(tuple, range, maniptype, ct);
282 289out:
283 nf_nat_proto_put(proto); 290 rcu_read_unlock();
284} 291}
285 292
286unsigned int 293unsigned int
@@ -361,12 +368,11 @@ manip_pkt(u_int16_t proto,
361 iph = (void *)(*pskb)->data + iphdroff; 368 iph = (void *)(*pskb)->data + iphdroff;
362 369
363 /* Manipulate protcol part. */ 370 /* Manipulate protcol part. */
364 p = nf_nat_proto_find_get(proto); 371
365 if (!p->manip_pkt(pskb, iphdroff, target, maniptype)) { 372 /* rcu_read_lock()ed by nf_hook_slow */
366 nf_nat_proto_put(p); 373 p = __nf_nat_proto_find(proto);
374 if (!p->manip_pkt(pskb, iphdroff, target, maniptype))
367 return 0; 375 return 0;
368 }
369 nf_nat_proto_put(p);
370 376
371 iph = (void *)(*pskb)->data + iphdroff; 377 iph = (void *)(*pskb)->data + iphdroff;
372 378
@@ -423,6 +429,7 @@ int nf_nat_icmp_reply_translation(struct nf_conn *ct,
423 struct icmphdr icmp; 429 struct icmphdr icmp;
424 struct iphdr ip; 430 struct iphdr ip;
425 } *inside; 431 } *inside;
432 struct nf_conntrack_l4proto *l4proto;
426 struct nf_conntrack_tuple inner, target; 433 struct nf_conntrack_tuple inner, target;
427 int hdrlen = (*pskb)->nh.iph->ihl * 4; 434 int hdrlen = (*pskb)->nh.iph->ihl * 4;
428 enum ip_conntrack_dir dir = CTINFO2DIR(ctinfo); 435 enum ip_conntrack_dir dir = CTINFO2DIR(ctinfo);
@@ -444,8 +451,8 @@ int nf_nat_icmp_reply_translation(struct nf_conn *ct,
444 (*pskb)->nfctinfo == IP_CT_RELATED+IP_CT_IS_REPLY); 451 (*pskb)->nfctinfo == IP_CT_RELATED+IP_CT_IS_REPLY);
445 452
446 /* Redirects on non-null nats must be dropped, else they'll 453 /* Redirects on non-null nats must be dropped, else they'll
447 start talking to each other without our translation, and be 454 start talking to each other without our translation, and be
448 confused... --RR */ 455 confused... --RR */
449 if (inside->icmp.type == ICMP_REDIRECT) { 456 if (inside->icmp.type == ICMP_REDIRECT) {
450 /* If NAT isn't finished, assume it and drop. */ 457 /* If NAT isn't finished, assume it and drop. */
451 if ((ct->status & IPS_NAT_DONE_MASK) != IPS_NAT_DONE_MASK) 458 if ((ct->status & IPS_NAT_DONE_MASK) != IPS_NAT_DONE_MASK)
@@ -458,16 +465,16 @@ int nf_nat_icmp_reply_translation(struct nf_conn *ct,
458 DEBUGP("icmp_reply_translation: translating error %p manp %u dir %s\n", 465 DEBUGP("icmp_reply_translation: translating error %p manp %u dir %s\n",
459 *pskb, manip, dir == IP_CT_DIR_ORIGINAL ? "ORIG" : "REPLY"); 466 *pskb, manip, dir == IP_CT_DIR_ORIGINAL ? "ORIG" : "REPLY");
460 467
468 /* rcu_read_lock()ed by nf_hook_slow */
469 l4proto = __nf_ct_l4proto_find(PF_INET, inside->ip.protocol);
470
461 if (!nf_ct_get_tuple(*pskb, 471 if (!nf_ct_get_tuple(*pskb,
462 (*pskb)->nh.iph->ihl*4 + sizeof(struct icmphdr), 472 (*pskb)->nh.iph->ihl*4 + sizeof(struct icmphdr),
463 (*pskb)->nh.iph->ihl*4 + 473 (*pskb)->nh.iph->ihl*4 +
464 sizeof(struct icmphdr) + inside->ip.ihl*4, 474 sizeof(struct icmphdr) + inside->ip.ihl*4,
465 (u_int16_t)AF_INET, 475 (u_int16_t)AF_INET,
466 inside->ip.protocol, 476 inside->ip.protocol,
467 &inner, 477 &inner, l3proto, l4proto))
468 l3proto,
469 __nf_ct_l4proto_find((u_int16_t)PF_INET,
470 inside->ip.protocol)))
471 return 0; 478 return 0;
472 479
473 /* Change inner back to look like incoming packet. We do the 480 /* Change inner back to look like incoming packet. We do the
@@ -521,7 +528,7 @@ int nf_nat_protocol_register(struct nf_nat_protocol *proto)
521 ret = -EBUSY; 528 ret = -EBUSY;
522 goto out; 529 goto out;
523 } 530 }
524 nf_nat_protos[proto->protonum] = proto; 531 rcu_assign_pointer(nf_nat_protos[proto->protonum], proto);
525 out: 532 out:
526 write_unlock_bh(&nf_nat_lock); 533 write_unlock_bh(&nf_nat_lock);
527 return ret; 534 return ret;
@@ -532,11 +539,10 @@ EXPORT_SYMBOL(nf_nat_protocol_register);
532void nf_nat_protocol_unregister(struct nf_nat_protocol *proto) 539void nf_nat_protocol_unregister(struct nf_nat_protocol *proto)
533{ 540{
534 write_lock_bh(&nf_nat_lock); 541 write_lock_bh(&nf_nat_lock);
535 nf_nat_protos[proto->protonum] = &nf_nat_unknown_protocol; 542 rcu_assign_pointer(nf_nat_protos[proto->protonum],
543 &nf_nat_unknown_protocol);
536 write_unlock_bh(&nf_nat_lock); 544 write_unlock_bh(&nf_nat_lock);
537 545 synchronize_rcu();
538 /* Someone could be still looking at the proto in a bh. */
539 synchronize_net();
540} 546}
541EXPORT_SYMBOL(nf_nat_protocol_unregister); 547EXPORT_SYMBOL(nf_nat_protocol_unregister);
542 548
@@ -600,10 +606,10 @@ static int __init nf_nat_init(void)
600 /* Sew in builtin protocols. */ 606 /* Sew in builtin protocols. */
601 write_lock_bh(&nf_nat_lock); 607 write_lock_bh(&nf_nat_lock);
602 for (i = 0; i < MAX_IP_NAT_PROTO; i++) 608 for (i = 0; i < MAX_IP_NAT_PROTO; i++)
603 nf_nat_protos[i] = &nf_nat_unknown_protocol; 609 rcu_assign_pointer(nf_nat_protos[i], &nf_nat_unknown_protocol);
604 nf_nat_protos[IPPROTO_TCP] = &nf_nat_protocol_tcp; 610 rcu_assign_pointer(nf_nat_protos[IPPROTO_TCP], &nf_nat_protocol_tcp);
605 nf_nat_protos[IPPROTO_UDP] = &nf_nat_protocol_udp; 611 rcu_assign_pointer(nf_nat_protos[IPPROTO_UDP], &nf_nat_protocol_udp);
606 nf_nat_protos[IPPROTO_ICMP] = &nf_nat_protocol_icmp; 612 rcu_assign_pointer(nf_nat_protos[IPPROTO_ICMP], &nf_nat_protocol_icmp);
607 write_unlock_bh(&nf_nat_lock); 613 write_unlock_bh(&nf_nat_lock);
608 614
609 for (i = 0; i < nf_nat_htable_size; i++) { 615 for (i = 0; i < nf_nat_htable_size; i++) {
@@ -611,8 +617,8 @@ static int __init nf_nat_init(void)
611 } 617 }
612 618
613 /* FIXME: Man, this is a hack. <SIGH> */ 619 /* FIXME: Man, this is a hack. <SIGH> */
614 NF_CT_ASSERT(nf_conntrack_destroyed == NULL); 620 NF_CT_ASSERT(rcu_dereference(nf_conntrack_destroyed) == NULL);
615 nf_conntrack_destroyed = &nf_nat_cleanup_conntrack; 621 rcu_assign_pointer(nf_conntrack_destroyed, nf_nat_cleanup_conntrack);
616 622
617 /* Initialize fake conntrack so that NAT will skip it */ 623 /* Initialize fake conntrack so that NAT will skip it */
618 nf_conntrack_untracked.status |= IPS_NAT_DONE_MASK; 624 nf_conntrack_untracked.status |= IPS_NAT_DONE_MASK;
@@ -636,7 +642,8 @@ static int clean_nat(struct nf_conn *i, void *data)
636static void __exit nf_nat_cleanup(void) 642static void __exit nf_nat_cleanup(void)
637{ 643{
638 nf_ct_iterate_cleanup(&clean_nat, NULL); 644 nf_ct_iterate_cleanup(&clean_nat, NULL);
639 nf_conntrack_destroyed = NULL; 645 rcu_assign_pointer(nf_conntrack_destroyed, NULL);
646 synchronize_rcu();
640 vfree(bysource); 647 vfree(bysource);
641 nf_ct_l3proto_put(l3proto); 648 nf_ct_l3proto_put(l3proto);
642} 649}
diff --git a/net/ipv4/netfilter/nf_nat_h323.c b/net/ipv4/netfilter/nf_nat_h323.c
index fb9ab0114c23..9cbf3f9be13b 100644
--- a/net/ipv4/netfilter/nf_nat_h323.c
+++ b/net/ipv4/netfilter/nf_nat_h323.c
@@ -256,7 +256,7 @@ static int nat_rtp_rtcp(struct sk_buff **pskb, struct nf_conn *ct,
256 if (set_h245_addr(pskb, data, dataoff, taddr, 256 if (set_h245_addr(pskb, data, dataoff, taddr,
257 &ct->tuplehash[!dir].tuple.dst.u3, 257 &ct->tuplehash[!dir].tuple.dst.u3,
258 htons((port & htons(1)) ? nated_port + 1 : 258 htons((port & htons(1)) ? nated_port + 1 :
259 nated_port)) == 0) { 259 nated_port)) == 0) {
260 /* Save ports */ 260 /* Save ports */
261 info->rtp_port[i][dir] = rtp_port; 261 info->rtp_port[i][dir] = rtp_port;
262 info->rtp_port[i][!dir] = htons(nated_port); 262 info->rtp_port[i][!dir] = htons(nated_port);
diff --git a/net/ipv4/netfilter/nf_nat_helper.c b/net/ipv4/netfilter/nf_nat_helper.c
index 98fbfc84d183..49a90c39ffce 100644
--- a/net/ipv4/netfilter/nf_nat_helper.c
+++ b/net/ipv4/netfilter/nf_nat_helper.c
@@ -176,10 +176,10 @@ nf_nat_mangle_tcp_packet(struct sk_buff **pskb,
176 datalen = (*pskb)->len - iph->ihl*4; 176 datalen = (*pskb)->len - iph->ihl*4;
177 if ((*pskb)->ip_summed != CHECKSUM_PARTIAL) { 177 if ((*pskb)->ip_summed != CHECKSUM_PARTIAL) {
178 tcph->check = 0; 178 tcph->check = 0;
179 tcph->check = tcp_v4_check(tcph, datalen, 179 tcph->check = tcp_v4_check(datalen,
180 iph->saddr, iph->daddr, 180 iph->saddr, iph->daddr,
181 csum_partial((char *)tcph, 181 csum_partial((char *)tcph,
182 datalen, 0)); 182 datalen, 0));
183 } else 183 } else
184 nf_proto_csum_replace2(&tcph->check, *pskb, 184 nf_proto_csum_replace2(&tcph->check, *pskb,
185 htons(oldlen), htons(datalen), 1); 185 htons(oldlen), htons(datalen), 1);
@@ -223,7 +223,7 @@ nf_nat_mangle_udp_packet(struct sk_buff **pskb,
223 /* UDP helpers might accidentally mangle the wrong packet */ 223 /* UDP helpers might accidentally mangle the wrong packet */
224 iph = (*pskb)->nh.iph; 224 iph = (*pskb)->nh.iph;
225 if ((*pskb)->len < iph->ihl*4 + sizeof(*udph) + 225 if ((*pskb)->len < iph->ihl*4 + sizeof(*udph) +
226 match_offset + match_len) 226 match_offset + match_len)
227 return 0; 227 return 0;
228 228
229 if (!skb_make_writable(pskb, (*pskb)->len)) 229 if (!skb_make_writable(pskb, (*pskb)->len))
@@ -252,9 +252,9 @@ nf_nat_mangle_udp_packet(struct sk_buff **pskb,
252 if ((*pskb)->ip_summed != CHECKSUM_PARTIAL) { 252 if ((*pskb)->ip_summed != CHECKSUM_PARTIAL) {
253 udph->check = 0; 253 udph->check = 0;
254 udph->check = csum_tcpudp_magic(iph->saddr, iph->daddr, 254 udph->check = csum_tcpudp_magic(iph->saddr, iph->daddr,
255 datalen, IPPROTO_UDP, 255 datalen, IPPROTO_UDP,
256 csum_partial((char *)udph, 256 csum_partial((char *)udph,
257 datalen, 0)); 257 datalen, 0));
258 if (!udph->check) 258 if (!udph->check)
259 udph->check = CSUM_MANGLED_0; 259 udph->check = CSUM_MANGLED_0;
260 } else 260 } else
diff --git a/net/ipv4/netfilter/nf_nat_pptp.c b/net/ipv4/netfilter/nf_nat_pptp.c
index 5df4fcae3ab6..7ba341c22eaa 100644
--- a/net/ipv4/netfilter/nf_nat_pptp.c
+++ b/net/ipv4/netfilter/nf_nat_pptp.c
@@ -184,10 +184,10 @@ pptp_outbound_pkt(struct sk_buff **pskb,
184 184
185 /* mangle packet */ 185 /* mangle packet */
186 if (nf_nat_mangle_tcp_packet(pskb, ct, ctinfo, 186 if (nf_nat_mangle_tcp_packet(pskb, ct, ctinfo,
187 cid_off + sizeof(struct pptp_pkt_hdr) + 187 cid_off + sizeof(struct pptp_pkt_hdr) +
188 sizeof(struct PptpControlHeader), 188 sizeof(struct PptpControlHeader),
189 sizeof(new_callid), (char *)&new_callid, 189 sizeof(new_callid), (char *)&new_callid,
190 sizeof(new_callid)) == 0) 190 sizeof(new_callid)) == 0)
191 return NF_DROP; 191 return NF_DROP;
192 return NF_ACCEPT; 192 return NF_ACCEPT;
193} 193}
@@ -276,7 +276,7 @@ pptp_inbound_pkt(struct sk_buff **pskb,
276 ntohs(REQ_CID(pptpReq, pcid_off)), ntohs(new_pcid)); 276 ntohs(REQ_CID(pptpReq, pcid_off)), ntohs(new_pcid));
277 277
278 if (nf_nat_mangle_tcp_packet(pskb, ct, ctinfo, 278 if (nf_nat_mangle_tcp_packet(pskb, ct, ctinfo,
279 pcid_off + sizeof(struct pptp_pkt_hdr) + 279 pcid_off + sizeof(struct pptp_pkt_hdr) +
280 sizeof(struct PptpControlHeader), 280 sizeof(struct PptpControlHeader),
281 sizeof(new_pcid), (char *)&new_pcid, 281 sizeof(new_pcid), (char *)&new_pcid,
282 sizeof(new_pcid)) == 0) 282 sizeof(new_pcid)) == 0)
diff --git a/net/ipv4/netfilter/nf_nat_proto_icmp.c b/net/ipv4/netfilter/nf_nat_proto_icmp.c
index dcfd772972d7..6bc2f06de055 100644
--- a/net/ipv4/netfilter/nf_nat_proto_icmp.c
+++ b/net/ipv4/netfilter/nf_nat_proto_icmp.c
@@ -44,7 +44,7 @@ icmp_unique_tuple(struct nf_conntrack_tuple *tuple,
44 44
45 for (i = 0; i < range_size; i++, id++) { 45 for (i = 0; i < range_size; i++, id++) {
46 tuple->src.u.icmp.id = htons(ntohs(range->min.icmp.id) + 46 tuple->src.u.icmp.id = htons(ntohs(range->min.icmp.id) +
47 (id % range_size)); 47 (id % range_size));
48 if (!nf_nat_used_tuple(tuple, ct)) 48 if (!nf_nat_used_tuple(tuple, ct))
49 return 1; 49 return 1;
50 } 50 }
diff --git a/net/ipv4/netfilter/nf_nat_proto_tcp.c b/net/ipv4/netfilter/nf_nat_proto_tcp.c
index 7e26a7e9bee1..439164c7a626 100644
--- a/net/ipv4/netfilter/nf_nat_proto_tcp.c
+++ b/net/ipv4/netfilter/nf_nat_proto_tcp.c
@@ -8,6 +8,7 @@
8 8
9#include <linux/types.h> 9#include <linux/types.h>
10#include <linux/init.h> 10#include <linux/init.h>
11#include <linux/random.h>
11#include <linux/ip.h> 12#include <linux/ip.h>
12#include <linux/tcp.h> 13#include <linux/tcp.h>
13 14
@@ -75,6 +76,9 @@ tcp_unique_tuple(struct nf_conntrack_tuple *tuple,
75 range_size = ntohs(range->max.tcp.port) - min + 1; 76 range_size = ntohs(range->max.tcp.port) - min + 1;
76 } 77 }
77 78
79 if (range->flags & IP_NAT_RANGE_PROTO_RANDOM)
80 port = net_random();
81
78 for (i = 0; i < range_size; i++, port++) { 82 for (i = 0; i < range_size; i++, port++) {
79 *portptr = htons(min + port % range_size); 83 *portptr = htons(min + port % range_size);
80 if (!nf_nat_used_tuple(tuple, ct)) 84 if (!nf_nat_used_tuple(tuple, ct))
diff --git a/net/ipv4/netfilter/nf_nat_proto_udp.c b/net/ipv4/netfilter/nf_nat_proto_udp.c
index ab0ce4c8699f..8cae6e063bb6 100644
--- a/net/ipv4/netfilter/nf_nat_proto_udp.c
+++ b/net/ipv4/netfilter/nf_nat_proto_udp.c
@@ -8,6 +8,7 @@
8 8
9#include <linux/types.h> 9#include <linux/types.h>
10#include <linux/init.h> 10#include <linux/init.h>
11#include <linux/random.h>
11#include <linux/ip.h> 12#include <linux/ip.h>
12#include <linux/udp.h> 13#include <linux/udp.h>
13 14
@@ -73,6 +74,9 @@ udp_unique_tuple(struct nf_conntrack_tuple *tuple,
73 range_size = ntohs(range->max.udp.port) - min + 1; 74 range_size = ntohs(range->max.udp.port) - min + 1;
74 } 75 }
75 76
77 if (range->flags & IP_NAT_RANGE_PROTO_RANDOM)
78 port = net_random();
79
76 for (i = 0; i < range_size; i++, port++) { 80 for (i = 0; i < range_size; i++, port++) {
77 *portptr = htons(min + port % range_size); 81 *portptr = htons(min + port % range_size);
78 if (!nf_nat_used_tuple(tuple, ct)) 82 if (!nf_nat_used_tuple(tuple, ct))
diff --git a/net/ipv4/netfilter/nf_nat_rule.c b/net/ipv4/netfilter/nf_nat_rule.c
index b868ee0195d4..147a4370cf03 100644
--- a/net/ipv4/netfilter/nf_nat_rule.c
+++ b/net/ipv4/netfilter/nf_nat_rule.c
@@ -56,8 +56,8 @@ static struct
56 /* PRE_ROUTING */ 56 /* PRE_ROUTING */
57 { 57 {
58 .entry = { 58 .entry = {
59 .target_offset = sizeof(struct ipt_entry), 59 .target_offset = sizeof(struct ipt_entry),
60 .next_offset = sizeof(struct ipt_standard), 60 .next_offset = sizeof(struct ipt_standard),
61 }, 61 },
62 .target = { 62 .target = {
63 .target = { 63 .target = {
@@ -71,8 +71,8 @@ static struct
71 /* POST_ROUTING */ 71 /* POST_ROUTING */
72 { 72 {
73 .entry = { 73 .entry = {
74 .target_offset = sizeof(struct ipt_entry), 74 .target_offset = sizeof(struct ipt_entry),
75 .next_offset = sizeof(struct ipt_standard), 75 .next_offset = sizeof(struct ipt_standard),
76 }, 76 },
77 .target = { 77 .target = {
78 .target = { 78 .target = {
@@ -86,8 +86,8 @@ static struct
86 /* LOCAL_OUT */ 86 /* LOCAL_OUT */
87 { 87 {
88 .entry = { 88 .entry = {
89 .target_offset = sizeof(struct ipt_entry), 89 .target_offset = sizeof(struct ipt_entry),
90 .next_offset = sizeof(struct ipt_standard), 90 .next_offset = sizeof(struct ipt_standard),
91 }, 91 },
92 .target = { 92 .target = {
93 .target = { 93 .target = {
@@ -119,7 +119,7 @@ static struct
119 } 119 }
120}; 120};
121 121
122static struct ipt_table nat_table = { 122static struct xt_table nat_table = {
123 .name = "nat", 123 .name = "nat",
124 .valid_hooks = NAT_VALID_HOOKS, 124 .valid_hooks = NAT_VALID_HOOKS,
125 .lock = RW_LOCK_UNLOCKED, 125 .lock = RW_LOCK_UNLOCKED,
@@ -145,7 +145,7 @@ static unsigned int ipt_snat_target(struct sk_buff **pskb,
145 145
146 /* Connection must be valid and new. */ 146 /* Connection must be valid and new. */
147 NF_CT_ASSERT(ct && (ctinfo == IP_CT_NEW || ctinfo == IP_CT_RELATED || 147 NF_CT_ASSERT(ct && (ctinfo == IP_CT_NEW || ctinfo == IP_CT_RELATED ||
148 ctinfo == IP_CT_RELATED + IP_CT_IS_REPLY)); 148 ctinfo == IP_CT_RELATED + IP_CT_IS_REPLY));
149 NF_CT_ASSERT(out); 149 NF_CT_ASSERT(out);
150 150
151 return nf_nat_setup_info(ct, &mr->range[0], hooknum); 151 return nf_nat_setup_info(ct, &mr->range[0], hooknum);
@@ -226,6 +226,10 @@ static int ipt_dnat_checkentry(const char *tablename,
226 printk("DNAT: multiple ranges no longer supported\n"); 226 printk("DNAT: multiple ranges no longer supported\n");
227 return 0; 227 return 0;
228 } 228 }
229 if (mr->range[0].flags & IP_NAT_RANGE_PROTO_RANDOM) {
230 printk("DNAT: port randomization not supported\n");
231 return 0;
232 }
229 return 1; 233 return 1;
230} 234}
231 235
@@ -252,8 +256,8 @@ alloc_null_binding(struct nf_conn *ct,
252 256
253unsigned int 257unsigned int
254alloc_null_binding_confirmed(struct nf_conn *ct, 258alloc_null_binding_confirmed(struct nf_conn *ct,
255 struct nf_nat_info *info, 259 struct nf_nat_info *info,
256 unsigned int hooknum) 260 unsigned int hooknum)
257{ 261{
258 __be32 ip 262 __be32 ip
259 = (HOOK2MANIP(hooknum) == IP_NAT_MANIP_SRC 263 = (HOOK2MANIP(hooknum) == IP_NAT_MANIP_SRC
@@ -290,7 +294,7 @@ int nf_nat_rule_find(struct sk_buff **pskb,
290 return ret; 294 return ret;
291} 295}
292 296
293static struct ipt_target ipt_snat_reg = { 297static struct xt_target ipt_snat_reg = {
294 .name = "SNAT", 298 .name = "SNAT",
295 .target = ipt_snat_target, 299 .target = ipt_snat_target,
296 .targetsize = sizeof(struct nf_nat_multi_range_compat), 300 .targetsize = sizeof(struct nf_nat_multi_range_compat),
diff --git a/net/ipv4/netfilter/nf_nat_sip.c b/net/ipv4/netfilter/nf_nat_sip.c
index 3d524b957310..b12cd7c314ca 100644
--- a/net/ipv4/netfilter/nf_nat_sip.c
+++ b/net/ipv4/netfilter/nf_nat_sip.c
@@ -90,7 +90,7 @@ static int map_sip_addr(struct sk_buff **pskb, enum ip_conntrack_info ctinfo,
90 return 1; 90 return 1;
91 91
92 if (!nf_nat_mangle_udp_packet(pskb, ct, ctinfo, 92 if (!nf_nat_mangle_udp_packet(pskb, ct, ctinfo,
93 matchoff, matchlen, addr, addrlen)) 93 matchoff, matchlen, addr, addrlen))
94 return 0; 94 return 0;
95 *dptr = (*pskb)->data + (*pskb)->nh.iph->ihl*4 + sizeof(struct udphdr); 95 *dptr = (*pskb)->data + (*pskb)->nh.iph->ihl*4 + sizeof(struct udphdr);
96 return 1; 96 return 1;
@@ -151,7 +151,7 @@ static unsigned int mangle_sip_packet(struct sk_buff **pskb,
151 return 0; 151 return 0;
152 152
153 if (!nf_nat_mangle_udp_packet(pskb, ct, ctinfo, 153 if (!nf_nat_mangle_udp_packet(pskb, ct, ctinfo,
154 matchoff, matchlen, buffer, bufflen)) 154 matchoff, matchlen, buffer, bufflen))
155 return 0; 155 return 0;
156 156
157 /* We need to reload this. Thanks Patrick. */ 157 /* We need to reload this. Thanks Patrick. */
@@ -172,7 +172,7 @@ static int mangle_content_len(struct sk_buff **pskb,
172 172
173 /* Get actual SDP lenght */ 173 /* Get actual SDP lenght */
174 if (ct_sip_get_info(ct, dptr, (*pskb)->len - dataoff, &matchoff, 174 if (ct_sip_get_info(ct, dptr, (*pskb)->len - dataoff, &matchoff,
175 &matchlen, POS_SDP_HEADER) > 0) { 175 &matchlen, POS_SDP_HEADER) > 0) {
176 176
177 /* since ct_sip_get_info() give us a pointer passing 'v=' 177 /* since ct_sip_get_info() give us a pointer passing 'v='
178 we need to add 2 bytes in this count. */ 178 we need to add 2 bytes in this count. */
@@ -180,7 +180,7 @@ static int mangle_content_len(struct sk_buff **pskb,
180 180
181 /* Now, update SDP length */ 181 /* Now, update SDP length */
182 if (ct_sip_get_info(ct, dptr, (*pskb)->len - dataoff, &matchoff, 182 if (ct_sip_get_info(ct, dptr, (*pskb)->len - dataoff, &matchoff,
183 &matchlen, POS_CONTENT) > 0) { 183 &matchlen, POS_CONTENT) > 0) {
184 184
185 bufflen = sprintf(buffer, "%u", c_len); 185 bufflen = sprintf(buffer, "%u", c_len);
186 return nf_nat_mangle_udp_packet(pskb, ct, ctinfo, 186 return nf_nat_mangle_udp_packet(pskb, ct, ctinfo,
@@ -205,17 +205,17 @@ static unsigned int mangle_sdp(struct sk_buff **pskb,
205 /* Mangle owner and contact info. */ 205 /* Mangle owner and contact info. */
206 bufflen = sprintf(buffer, "%u.%u.%u.%u", NIPQUAD(newip)); 206 bufflen = sprintf(buffer, "%u.%u.%u.%u", NIPQUAD(newip));
207 if (!mangle_sip_packet(pskb, ctinfo, ct, &dptr, (*pskb)->len - dataoff, 207 if (!mangle_sip_packet(pskb, ctinfo, ct, &dptr, (*pskb)->len - dataoff,
208 buffer, bufflen, POS_OWNER_IP4)) 208 buffer, bufflen, POS_OWNER_IP4))
209 return 0; 209 return 0;
210 210
211 if (!mangle_sip_packet(pskb, ctinfo, ct, &dptr, (*pskb)->len - dataoff, 211 if (!mangle_sip_packet(pskb, ctinfo, ct, &dptr, (*pskb)->len - dataoff,
212 buffer, bufflen, POS_CONNECTION_IP4)) 212 buffer, bufflen, POS_CONNECTION_IP4))
213 return 0; 213 return 0;
214 214
215 /* Mangle media port. */ 215 /* Mangle media port. */
216 bufflen = sprintf(buffer, "%u", port); 216 bufflen = sprintf(buffer, "%u", port);
217 if (!mangle_sip_packet(pskb, ctinfo, ct, &dptr, (*pskb)->len - dataoff, 217 if (!mangle_sip_packet(pskb, ctinfo, ct, &dptr, (*pskb)->len - dataoff,
218 buffer, bufflen, POS_MEDIA)) 218 buffer, bufflen, POS_MEDIA))
219 return 0; 219 return 0;
220 220
221 return mangle_content_len(pskb, ctinfo, ct, dptr); 221 return mangle_content_len(pskb, ctinfo, ct, dptr);
diff --git a/net/ipv4/netfilter/nf_nat_snmp_basic.c b/net/ipv4/netfilter/nf_nat_snmp_basic.c
index f12528fe1bf9..ce5c4939a6ee 100644
--- a/net/ipv4/netfilter/nf_nat_snmp_basic.c
+++ b/net/ipv4/netfilter/nf_nat_snmp_basic.c
@@ -150,8 +150,8 @@ struct asn1_octstr
150}; 150};
151 151
152static void asn1_open(struct asn1_ctx *ctx, 152static void asn1_open(struct asn1_ctx *ctx,
153 unsigned char *buf, 153 unsigned char *buf,
154 unsigned int len) 154 unsigned int len)
155{ 155{
156 ctx->begin = buf; 156 ctx->begin = buf;
157 ctx->end = buf + len; 157 ctx->end = buf + len;
@@ -186,9 +186,9 @@ static unsigned char asn1_tag_decode(struct asn1_ctx *ctx, unsigned int *tag)
186} 186}
187 187
188static unsigned char asn1_id_decode(struct asn1_ctx *ctx, 188static unsigned char asn1_id_decode(struct asn1_ctx *ctx,
189 unsigned int *cls, 189 unsigned int *cls,
190 unsigned int *con, 190 unsigned int *con,
191 unsigned int *tag) 191 unsigned int *tag)
192{ 192{
193 unsigned char ch; 193 unsigned char ch;
194 194
@@ -207,8 +207,8 @@ static unsigned char asn1_id_decode(struct asn1_ctx *ctx,
207} 207}
208 208
209static unsigned char asn1_length_decode(struct asn1_ctx *ctx, 209static unsigned char asn1_length_decode(struct asn1_ctx *ctx,
210 unsigned int *def, 210 unsigned int *def,
211 unsigned int *len) 211 unsigned int *len)
212{ 212{
213 unsigned char ch, cnt; 213 unsigned char ch, cnt;
214 214
@@ -239,10 +239,10 @@ static unsigned char asn1_length_decode(struct asn1_ctx *ctx,
239} 239}
240 240
241static unsigned char asn1_header_decode(struct asn1_ctx *ctx, 241static unsigned char asn1_header_decode(struct asn1_ctx *ctx,
242 unsigned char **eoc, 242 unsigned char **eoc,
243 unsigned int *cls, 243 unsigned int *cls,
244 unsigned int *con, 244 unsigned int *con,
245 unsigned int *tag) 245 unsigned int *tag)
246{ 246{
247 unsigned int def, len; 247 unsigned int def, len;
248 248
@@ -297,8 +297,8 @@ static unsigned char asn1_null_decode(struct asn1_ctx *ctx, unsigned char *eoc)
297} 297}
298 298
299static unsigned char asn1_long_decode(struct asn1_ctx *ctx, 299static unsigned char asn1_long_decode(struct asn1_ctx *ctx,
300 unsigned char *eoc, 300 unsigned char *eoc,
301 long *integer) 301 long *integer)
302{ 302{
303 unsigned char ch; 303 unsigned char ch;
304 unsigned int len; 304 unsigned int len;
@@ -325,8 +325,8 @@ static unsigned char asn1_long_decode(struct asn1_ctx *ctx,
325} 325}
326 326
327static unsigned char asn1_uint_decode(struct asn1_ctx *ctx, 327static unsigned char asn1_uint_decode(struct asn1_ctx *ctx,
328 unsigned char *eoc, 328 unsigned char *eoc,
329 unsigned int *integer) 329 unsigned int *integer)
330{ 330{
331 unsigned char ch; 331 unsigned char ch;
332 unsigned int len; 332 unsigned int len;
@@ -354,8 +354,8 @@ static unsigned char asn1_uint_decode(struct asn1_ctx *ctx,
354} 354}
355 355
356static unsigned char asn1_ulong_decode(struct asn1_ctx *ctx, 356static unsigned char asn1_ulong_decode(struct asn1_ctx *ctx,
357 unsigned char *eoc, 357 unsigned char *eoc,
358 unsigned long *integer) 358 unsigned long *integer)
359{ 359{
360 unsigned char ch; 360 unsigned char ch;
361 unsigned int len; 361 unsigned int len;
@@ -383,9 +383,9 @@ static unsigned char asn1_ulong_decode(struct asn1_ctx *ctx,
383} 383}
384 384
385static unsigned char asn1_octets_decode(struct asn1_ctx *ctx, 385static unsigned char asn1_octets_decode(struct asn1_ctx *ctx,
386 unsigned char *eoc, 386 unsigned char *eoc,
387 unsigned char **octets, 387 unsigned char **octets,
388 unsigned int *len) 388 unsigned int *len)
389{ 389{
390 unsigned char *ptr; 390 unsigned char *ptr;
391 391
@@ -411,7 +411,7 @@ static unsigned char asn1_octets_decode(struct asn1_ctx *ctx,
411} 411}
412 412
413static unsigned char asn1_subid_decode(struct asn1_ctx *ctx, 413static unsigned char asn1_subid_decode(struct asn1_ctx *ctx,
414 unsigned long *subid) 414 unsigned long *subid)
415{ 415{
416 unsigned char ch; 416 unsigned char ch;
417 417
@@ -428,9 +428,9 @@ static unsigned char asn1_subid_decode(struct asn1_ctx *ctx,
428} 428}
429 429
430static unsigned char asn1_oid_decode(struct asn1_ctx *ctx, 430static unsigned char asn1_oid_decode(struct asn1_ctx *ctx,
431 unsigned char *eoc, 431 unsigned char *eoc,
432 unsigned long **oid, 432 unsigned long **oid,
433 unsigned int *len) 433 unsigned int *len)
434{ 434{
435 unsigned long subid; 435 unsigned long subid;
436 unsigned int size; 436 unsigned int size;
@@ -611,9 +611,9 @@ struct snmp_v1_trap
611#define SERR_EOM 2 611#define SERR_EOM 2
612 612
613static inline void mangle_address(unsigned char *begin, 613static inline void mangle_address(unsigned char *begin,
614 unsigned char *addr, 614 unsigned char *addr,
615 const struct oct1_map *map, 615 const struct oct1_map *map,
616 __sum16 *check); 616 __sum16 *check);
617struct snmp_cnv 617struct snmp_cnv
618{ 618{
619 unsigned int class; 619 unsigned int class;
@@ -644,8 +644,8 @@ static struct snmp_cnv snmp_conv [] =
644}; 644};
645 645
646static unsigned char snmp_tag_cls2syntax(unsigned int tag, 646static unsigned char snmp_tag_cls2syntax(unsigned int tag,
647 unsigned int cls, 647 unsigned int cls,
648 unsigned short *syntax) 648 unsigned short *syntax)
649{ 649{
650 struct snmp_cnv *cnv; 650 struct snmp_cnv *cnv;
651 651
@@ -662,7 +662,7 @@ static unsigned char snmp_tag_cls2syntax(unsigned int tag,
662} 662}
663 663
664static unsigned char snmp_object_decode(struct asn1_ctx *ctx, 664static unsigned char snmp_object_decode(struct asn1_ctx *ctx,
665 struct snmp_object **obj) 665 struct snmp_object **obj)
666{ 666{
667 unsigned int cls, con, tag, len, idlen; 667 unsigned int cls, con, tag, len, idlen;
668 unsigned short type; 668 unsigned short type;
@@ -714,7 +714,7 @@ static unsigned char snmp_object_decode(struct asn1_ctx *ctx,
714 return 0; 714 return 0;
715 } 715 }
716 *obj = kmalloc(sizeof(struct snmp_object) + len, 716 *obj = kmalloc(sizeof(struct snmp_object) + len,
717 GFP_ATOMIC); 717 GFP_ATOMIC);
718 if (*obj == NULL) { 718 if (*obj == NULL) {
719 kfree(id); 719 kfree(id);
720 if (net_ratelimit()) 720 if (net_ratelimit())
@@ -730,7 +730,7 @@ static unsigned char snmp_object_decode(struct asn1_ctx *ctx,
730 return 0; 730 return 0;
731 } 731 }
732 *obj = kmalloc(sizeof(struct snmp_object) + len, 732 *obj = kmalloc(sizeof(struct snmp_object) + len,
733 GFP_ATOMIC); 733 GFP_ATOMIC);
734 if (*obj == NULL) { 734 if (*obj == NULL) {
735 kfree(id); 735 kfree(id);
736 if (net_ratelimit()) 736 if (net_ratelimit())
@@ -834,7 +834,7 @@ static unsigned char snmp_object_decode(struct asn1_ctx *ctx,
834} 834}
835 835
836static unsigned char snmp_request_decode(struct asn1_ctx *ctx, 836static unsigned char snmp_request_decode(struct asn1_ctx *ctx,
837 struct snmp_request *request) 837 struct snmp_request *request)
838{ 838{
839 unsigned int cls, con, tag; 839 unsigned int cls, con, tag;
840 unsigned char *end; 840 unsigned char *end;
@@ -874,9 +874,9 @@ static unsigned char snmp_request_decode(struct asn1_ctx *ctx,
874 * code example in the draft. 874 * code example in the draft.
875 */ 875 */
876static void fast_csum(__sum16 *csum, 876static void fast_csum(__sum16 *csum,
877 const unsigned char *optr, 877 const unsigned char *optr,
878 const unsigned char *nptr, 878 const unsigned char *nptr,
879 int offset) 879 int offset)
880{ 880{
881 unsigned char s[4]; 881 unsigned char s[4];
882 882
@@ -899,9 +899,9 @@ static void fast_csum(__sum16 *csum,
899 * - addr points to the start of the address 899 * - addr points to the start of the address
900 */ 900 */
901static inline void mangle_address(unsigned char *begin, 901static inline void mangle_address(unsigned char *begin,
902 unsigned char *addr, 902 unsigned char *addr,
903 const struct oct1_map *map, 903 const struct oct1_map *map,
904 __sum16 *check) 904 __sum16 *check)
905{ 905{
906 if (map->from == NOCT1(addr)) { 906 if (map->from == NOCT1(addr)) {
907 u_int32_t old; 907 u_int32_t old;
@@ -914,7 +914,7 @@ static inline void mangle_address(unsigned char *begin,
914 /* Update UDP checksum if being used */ 914 /* Update UDP checksum if being used */
915 if (*check) { 915 if (*check) {
916 fast_csum(check, 916 fast_csum(check,
917 &map->from, &map->to, addr - begin); 917 &map->from, &map->to, addr - begin);
918 918
919 } 919 }
920 920
@@ -925,9 +925,9 @@ static inline void mangle_address(unsigned char *begin,
925} 925}
926 926
927static unsigned char snmp_trap_decode(struct asn1_ctx *ctx, 927static unsigned char snmp_trap_decode(struct asn1_ctx *ctx,
928 struct snmp_v1_trap *trap, 928 struct snmp_v1_trap *trap,
929 const struct oct1_map *map, 929 const struct oct1_map *map,
930 __sum16 *check) 930 __sum16 *check)
931{ 931{
932 unsigned int cls, con, tag, len; 932 unsigned int cls, con, tag, len;
933 unsigned char *end; 933 unsigned char *end;
@@ -1019,9 +1019,9 @@ static void hex_dump(unsigned char *buf, size_t len)
1019 * (And this is the fucking 'basic' method). 1019 * (And this is the fucking 'basic' method).
1020 */ 1020 */
1021static int snmp_parse_mangle(unsigned char *msg, 1021static int snmp_parse_mangle(unsigned char *msg,
1022 u_int16_t len, 1022 u_int16_t len,
1023 const struct oct1_map *map, 1023 const struct oct1_map *map,
1024 __sum16 *check) 1024 __sum16 *check)
1025{ 1025{
1026 unsigned char *eoc, *end; 1026 unsigned char *eoc, *end;
1027 unsigned int cls, con, tag, vers, pdutype; 1027 unsigned int cls, con, tag, vers, pdutype;
@@ -1191,8 +1191,8 @@ static int snmp_parse_mangle(unsigned char *msg,
1191 * SNMP translation routine. 1191 * SNMP translation routine.
1192 */ 1192 */
1193static int snmp_translate(struct nf_conn *ct, 1193static int snmp_translate(struct nf_conn *ct,
1194 enum ip_conntrack_info ctinfo, 1194 enum ip_conntrack_info ctinfo,
1195 struct sk_buff **pskb) 1195 struct sk_buff **pskb)
1196{ 1196{
1197 struct iphdr *iph = (*pskb)->nh.iph; 1197 struct iphdr *iph = (*pskb)->nh.iph;
1198 struct udphdr *udph = (struct udphdr *)((__be32 *)iph + iph->ihl); 1198 struct udphdr *udph = (struct udphdr *)((__be32 *)iph + iph->ihl);
@@ -1219,7 +1219,7 @@ static int snmp_translate(struct nf_conn *ct,
1219 return NF_ACCEPT; 1219 return NF_ACCEPT;
1220 1220
1221 if (!snmp_parse_mangle((unsigned char *)udph + sizeof(struct udphdr), 1221 if (!snmp_parse_mangle((unsigned char *)udph + sizeof(struct udphdr),
1222 paylen, &map, &udph->check)) { 1222 paylen, &map, &udph->check)) {
1223 if (net_ratelimit()) 1223 if (net_ratelimit())
1224 printk(KERN_WARNING "bsalg: parser failed\n"); 1224 printk(KERN_WARNING "bsalg: parser failed\n");
1225 return NF_DROP; 1225 return NF_DROP;
diff --git a/net/ipv4/netfilter/nf_nat_standalone.c b/net/ipv4/netfilter/nf_nat_standalone.c
index 00d6dea9f7f3..e4d3ef17d45b 100644
--- a/net/ipv4/netfilter/nf_nat_standalone.c
+++ b/net/ipv4/netfilter/nf_nat_standalone.c
@@ -32,12 +32,6 @@
32#define DEBUGP(format, args...) 32#define DEBUGP(format, args...)
33#endif 33#endif
34 34
35#define HOOKNAME(hooknum) ((hooknum) == NF_IP_POST_ROUTING ? "POST_ROUTING" \
36 : ((hooknum) == NF_IP_PRE_ROUTING ? "PRE_ROUTING" \
37 : ((hooknum) == NF_IP_LOCAL_OUT ? "LOCAL_OUT" \
38 : ((hooknum) == NF_IP_LOCAL_IN ? "LOCAL_IN" \
39 : "*ERROR*")))
40
41#ifdef CONFIG_XFRM 35#ifdef CONFIG_XFRM
42static void nat_decode_session(struct sk_buff *skb, struct flowi *fl) 36static void nat_decode_session(struct sk_buff *skb, struct flowi *fl)
43{ 37{
@@ -102,8 +96,8 @@ nf_nat_fn(unsigned int hooknum,
102 protocol. 8) --RR */ 96 protocol. 8) --RR */
103 if (!ct) { 97 if (!ct) {
104 /* Exception: ICMP redirect to new connection (not in 98 /* Exception: ICMP redirect to new connection (not in
105 hash table yet). We must not let this through, in 99 hash table yet). We must not let this through, in
106 case we're doing NAT to the same network. */ 100 case we're doing NAT to the same network. */
107 if ((*pskb)->nh.iph->protocol == IPPROTO_ICMP) { 101 if ((*pskb)->nh.iph->protocol == IPPROTO_ICMP) {
108 struct icmphdr _hdr, *hp; 102 struct icmphdr _hdr, *hp;
109 103
@@ -147,7 +141,7 @@ nf_nat_fn(unsigned int hooknum,
147 if (unlikely(nf_ct_is_confirmed(ct))) 141 if (unlikely(nf_ct_is_confirmed(ct)))
148 /* NAT module was loaded late */ 142 /* NAT module was loaded late */
149 ret = alloc_null_binding_confirmed(ct, info, 143 ret = alloc_null_binding_confirmed(ct, info,
150 hooknum); 144 hooknum);
151 else if (hooknum == NF_IP_LOCAL_IN) 145 else if (hooknum == NF_IP_LOCAL_IN)
152 /* LOCAL_IN hook doesn't have a chain! */ 146 /* LOCAL_IN hook doesn't have a chain! */
153 ret = alloc_null_binding(ct, info, hooknum); 147 ret = alloc_null_binding(ct, info, hooknum);
@@ -177,10 +171,10 @@ nf_nat_fn(unsigned int hooknum,
177 171
178static unsigned int 172static unsigned int
179nf_nat_in(unsigned int hooknum, 173nf_nat_in(unsigned int hooknum,
180 struct sk_buff **pskb, 174 struct sk_buff **pskb,
181 const struct net_device *in, 175 const struct net_device *in,
182 const struct net_device *out, 176 const struct net_device *out,
183 int (*okfn)(struct sk_buff *)) 177 int (*okfn)(struct sk_buff *))
184{ 178{
185 unsigned int ret; 179 unsigned int ret;
186 __be32 daddr = (*pskb)->nh.iph->daddr; 180 __be32 daddr = (*pskb)->nh.iph->daddr;
@@ -275,9 +269,9 @@ nf_nat_adjust(unsigned int hooknum,
275 269
276 ct = nf_ct_get(*pskb, &ctinfo); 270 ct = nf_ct_get(*pskb, &ctinfo);
277 if (ct && test_bit(IPS_SEQ_ADJUST_BIT, &ct->status)) { 271 if (ct && test_bit(IPS_SEQ_ADJUST_BIT, &ct->status)) {
278 DEBUGP("nf_nat_standalone: adjusting sequence number\n"); 272 DEBUGP("nf_nat_standalone: adjusting sequence number\n");
279 if (!nf_nat_seq_adjust(pskb, ct, ctinfo)) 273 if (!nf_nat_seq_adjust(pskb, ct, ctinfo))
280 return NF_DROP; 274 return NF_DROP;
281 } 275 }
282 return NF_ACCEPT; 276 return NF_ACCEPT;
283} 277}
diff --git a/net/ipv4/proc.c b/net/ipv4/proc.c
index cd873da54cbe..ae68a691e8cd 100644
--- a/net/ipv4/proc.c
+++ b/net/ipv4/proc.c
@@ -79,7 +79,7 @@ static int sockstat_seq_open(struct inode *inode, struct file *file)
79 return single_open(file, sockstat_seq_show, NULL); 79 return single_open(file, sockstat_seq_show, NULL);
80} 80}
81 81
82static struct file_operations sockstat_seq_fops = { 82static const struct file_operations sockstat_seq_fops = {
83 .owner = THIS_MODULE, 83 .owner = THIS_MODULE,
84 .open = sockstat_seq_open, 84 .open = sockstat_seq_open,
85 .read = seq_read, 85 .read = seq_read,
@@ -266,7 +266,7 @@ static int snmp_seq_show(struct seq_file *seq, void *v)
266 266
267 for (i = 0; snmp4_ipstats_list[i].name != NULL; i++) 267 for (i = 0; snmp4_ipstats_list[i].name != NULL; i++)
268 seq_printf(seq, " %lu", 268 seq_printf(seq, " %lu",
269 fold_field((void **) ip_statistics, 269 fold_field((void **) ip_statistics,
270 snmp4_ipstats_list[i].entry)); 270 snmp4_ipstats_list[i].entry));
271 271
272 seq_puts(seq, "\nIcmp:"); 272 seq_puts(seq, "\nIcmp:");
@@ -276,7 +276,7 @@ static int snmp_seq_show(struct seq_file *seq, void *v)
276 seq_puts(seq, "\nIcmp:"); 276 seq_puts(seq, "\nIcmp:");
277 for (i = 0; snmp4_icmp_list[i].name != NULL; i++) 277 for (i = 0; snmp4_icmp_list[i].name != NULL; i++)
278 seq_printf(seq, " %lu", 278 seq_printf(seq, " %lu",
279 fold_field((void **) icmp_statistics, 279 fold_field((void **) icmp_statistics,
280 snmp4_icmp_list[i].entry)); 280 snmp4_icmp_list[i].entry));
281 281
282 seq_puts(seq, "\nTcp:"); 282 seq_puts(seq, "\nTcp:");
@@ -288,7 +288,7 @@ static int snmp_seq_show(struct seq_file *seq, void *v)
288 /* MaxConn field is signed, RFC 2012 */ 288 /* MaxConn field is signed, RFC 2012 */
289 if (snmp4_tcp_list[i].entry == TCP_MIB_MAXCONN) 289 if (snmp4_tcp_list[i].entry == TCP_MIB_MAXCONN)
290 seq_printf(seq, " %ld", 290 seq_printf(seq, " %ld",
291 fold_field((void **) tcp_statistics, 291 fold_field((void **) tcp_statistics,
292 snmp4_tcp_list[i].entry)); 292 snmp4_tcp_list[i].entry));
293 else 293 else
294 seq_printf(seq, " %lu", 294 seq_printf(seq, " %lu",
@@ -303,7 +303,7 @@ static int snmp_seq_show(struct seq_file *seq, void *v)
303 seq_puts(seq, "\nUdp:"); 303 seq_puts(seq, "\nUdp:");
304 for (i = 0; snmp4_udp_list[i].name != NULL; i++) 304 for (i = 0; snmp4_udp_list[i].name != NULL; i++)
305 seq_printf(seq, " %lu", 305 seq_printf(seq, " %lu",
306 fold_field((void **) udp_statistics, 306 fold_field((void **) udp_statistics,
307 snmp4_udp_list[i].entry)); 307 snmp4_udp_list[i].entry));
308 308
309 /* the UDP and UDP-Lite MIBs are the same */ 309 /* the UDP and UDP-Lite MIBs are the same */
@@ -326,7 +326,7 @@ static int snmp_seq_open(struct inode *inode, struct file *file)
326 return single_open(file, snmp_seq_show, NULL); 326 return single_open(file, snmp_seq_show, NULL);
327} 327}
328 328
329static struct file_operations snmp_seq_fops = { 329static const struct file_operations snmp_seq_fops = {
330 .owner = THIS_MODULE, 330 .owner = THIS_MODULE,
331 .open = snmp_seq_open, 331 .open = snmp_seq_open,
332 .read = seq_read, 332 .read = seq_read,
@@ -348,7 +348,7 @@ static int netstat_seq_show(struct seq_file *seq, void *v)
348 seq_puts(seq, "\nTcpExt:"); 348 seq_puts(seq, "\nTcpExt:");
349 for (i = 0; snmp4_net_list[i].name != NULL; i++) 349 for (i = 0; snmp4_net_list[i].name != NULL; i++)
350 seq_printf(seq, " %lu", 350 seq_printf(seq, " %lu",
351 fold_field((void **) net_statistics, 351 fold_field((void **) net_statistics,
352 snmp4_net_list[i].entry)); 352 snmp4_net_list[i].entry));
353 353
354 seq_putc(seq, '\n'); 354 seq_putc(seq, '\n');
@@ -360,7 +360,7 @@ static int netstat_seq_open(struct inode *inode, struct file *file)
360 return single_open(file, netstat_seq_show, NULL); 360 return single_open(file, netstat_seq_show, NULL);
361} 361}
362 362
363static struct file_operations netstat_seq_fops = { 363static const struct file_operations netstat_seq_fops = {
364 .owner = THIS_MODULE, 364 .owner = THIS_MODULE,
365 .open = netstat_seq_open, 365 .open = netstat_seq_open,
366 .read = seq_read, 366 .read = seq_read,
diff --git a/net/ipv4/protocol.c b/net/ipv4/protocol.c
index 05f5114828ea..6cd6340de8bd 100644
--- a/net/ipv4/protocol.c
+++ b/net/ipv4/protocol.c
@@ -74,7 +74,7 @@ int inet_add_protocol(struct net_protocol *prot, unsigned char protocol)
74/* 74/*
75 * Remove a protocol from the hash tables. 75 * Remove a protocol from the hash tables.
76 */ 76 */
77 77
78int inet_del_protocol(struct net_protocol *prot, unsigned char protocol) 78int inet_del_protocol(struct net_protocol *prot, unsigned char protocol)
79{ 79{
80 int hash, ret; 80 int hash, ret;
diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
index a6c63bbd9ddb..87e9c1618100 100644
--- a/net/ipv4/raw.c
+++ b/net/ipv4/raw.c
@@ -95,7 +95,7 @@ static void raw_v4_hash(struct sock *sk)
95 95
96static void raw_v4_unhash(struct sock *sk) 96static void raw_v4_unhash(struct sock *sk)
97{ 97{
98 write_lock_bh(&raw_v4_lock); 98 write_lock_bh(&raw_v4_lock);
99 if (sk_del_node_init(sk)) 99 if (sk_del_node_init(sk))
100 sock_prot_dec_use(sk->sk_prot); 100 sock_prot_dec_use(sk->sk_prot);
101 write_unlock_bh(&raw_v4_lock); 101 write_unlock_bh(&raw_v4_lock);
@@ -238,7 +238,7 @@ void raw_err (struct sock *sk, struct sk_buff *skb, u32 info)
238static int raw_rcv_skb(struct sock * sk, struct sk_buff * skb) 238static int raw_rcv_skb(struct sock * sk, struct sk_buff * skb)
239{ 239{
240 /* Charge it to the socket. */ 240 /* Charge it to the socket. */
241 241
242 if (sock_queue_rcv_skb(sk, skb) < 0) { 242 if (sock_queue_rcv_skb(sk, skb) < 0) {
243 /* FIXME: increment a raw drops counter here */ 243 /* FIXME: increment a raw drops counter here */
244 kfree_skb(skb); 244 kfree_skb(skb);
@@ -263,7 +263,7 @@ int raw_rcv(struct sock *sk, struct sk_buff *skb)
263} 263}
264 264
265static int raw_send_hdrinc(struct sock *sk, void *from, size_t length, 265static int raw_send_hdrinc(struct sock *sk, void *from, size_t length,
266 struct rtable *rt, 266 struct rtable *rt,
267 unsigned int flags) 267 unsigned int flags)
268{ 268{
269 struct inet_sock *inet = inet_sk(sk); 269 struct inet_sock *inet = inet_sk(sk);
@@ -285,7 +285,7 @@ static int raw_send_hdrinc(struct sock *sk, void *from, size_t length,
285 skb = sock_alloc_send_skb(sk, length+hh_len+15, 285 skb = sock_alloc_send_skb(sk, length+hh_len+15,
286 flags&MSG_DONTWAIT, &err); 286 flags&MSG_DONTWAIT, &err);
287 if (skb == NULL) 287 if (skb == NULL)
288 goto error; 288 goto error;
289 skb_reserve(skb, hh_len); 289 skb_reserve(skb, hh_len);
290 290
291 skb->priority = sk->sk_priority; 291 skb->priority = sk->sk_priority;
@@ -326,7 +326,7 @@ error_fault:
326 kfree_skb(skb); 326 kfree_skb(skb);
327error: 327error:
328 IP_INC_STATS(IPSTATS_MIB_OUTDISCARDS); 328 IP_INC_STATS(IPSTATS_MIB_OUTDISCARDS);
329 return err; 329 return err;
330} 330}
331 331
332static int raw_probe_proto_opt(struct flowi *fl, struct msghdr *msg) 332static int raw_probe_proto_opt(struct flowi *fl, struct msghdr *msg)
@@ -399,9 +399,9 @@ static int raw_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
399 err = -EOPNOTSUPP; 399 err = -EOPNOTSUPP;
400 if (msg->msg_flags & MSG_OOB) /* Mirror BSD error message */ 400 if (msg->msg_flags & MSG_OOB) /* Mirror BSD error message */
401 goto out; /* compatibility */ 401 goto out; /* compatibility */
402 402
403 /* 403 /*
404 * Get and verify the address. 404 * Get and verify the address.
405 */ 405 */
406 406
407 if (msg->msg_namelen) { 407 if (msg->msg_namelen) {
@@ -426,7 +426,7 @@ static int raw_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
426 */ 426 */
427 } else { 427 } else {
428 err = -EDESTADDRREQ; 428 err = -EDESTADDRREQ;
429 if (sk->sk_state != TCP_ESTABLISHED) 429 if (sk->sk_state != TCP_ESTABLISHED)
430 goto out; 430 goto out;
431 daddr = inet->daddr; 431 daddr = inet->daddr;
432 } 432 }
@@ -480,7 +480,7 @@ static int raw_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
480 .saddr = saddr, 480 .saddr = saddr,
481 .tos = tos } }, 481 .tos = tos } },
482 .proto = inet->hdrincl ? IPPROTO_RAW : 482 .proto = inet->hdrincl ? IPPROTO_RAW :
483 sk->sk_protocol, 483 sk->sk_protocol,
484 }; 484 };
485 if (!inet->hdrincl) { 485 if (!inet->hdrincl) {
486 err = raw_probe_proto_opt(&fl, msg); 486 err = raw_probe_proto_opt(&fl, msg);
@@ -489,7 +489,7 @@ static int raw_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
489 } 489 }
490 490
491 security_sk_classify_flow(sk, &fl); 491 security_sk_classify_flow(sk, &fl);
492 err = ip_route_output_flow(&rt, &fl, sk, !(msg->msg_flags&MSG_DONTWAIT)); 492 err = ip_route_output_flow(&rt, &fl, sk, 1);
493 } 493 }
494 if (err) 494 if (err)
495 goto done; 495 goto done;
@@ -503,9 +503,9 @@ static int raw_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
503back_from_confirm: 503back_from_confirm:
504 504
505 if (inet->hdrincl) 505 if (inet->hdrincl)
506 err = raw_send_hdrinc(sk, msg->msg_iov, len, 506 err = raw_send_hdrinc(sk, msg->msg_iov, len,
507 rt, msg->msg_flags); 507 rt, msg->msg_flags);
508 508
509 else { 509 else {
510 if (!ipc.addr) 510 if (!ipc.addr)
511 ipc.addr = rt->rt_dst; 511 ipc.addr = rt->rt_dst;
@@ -538,7 +538,7 @@ do_confirm:
538 538
539static void raw_close(struct sock *sk, long timeout) 539static void raw_close(struct sock *sk, long timeout)
540{ 540{
541 /* 541 /*
542 * Raw sockets may have direct kernel refereneces. Kill them. 542 * Raw sockets may have direct kernel refereneces. Kill them.
543 */ 543 */
544 ip_ra_control(sk, 0, NULL); 544 ip_ra_control(sk, 0, NULL);
@@ -861,7 +861,7 @@ static __inline__ char *get_raw_sock(struct sock *sp, char *tmpbuf, int i)
861 861
862 sprintf(tmpbuf, "%4d: %08X:%04X %08X:%04X" 862 sprintf(tmpbuf, "%4d: %08X:%04X %08X:%04X"
863 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %lu %d %p", 863 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %lu %d %p",
864 i, src, srcp, dest, destp, sp->sk_state, 864 i, src, srcp, dest, destp, sp->sk_state,
865 atomic_read(&sp->sk_wmem_alloc), 865 atomic_read(&sp->sk_wmem_alloc),
866 atomic_read(&sp->sk_rmem_alloc), 866 atomic_read(&sp->sk_rmem_alloc),
867 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp), 867 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
@@ -916,7 +916,7 @@ out_kfree:
916 goto out; 916 goto out;
917} 917}
918 918
919static struct file_operations raw_seq_fops = { 919static const struct file_operations raw_seq_fops = {
920 .owner = THIS_MODULE, 920 .owner = THIS_MODULE,
921 .open = raw_seq_open, 921 .open = raw_seq_open,
922 .read = seq_read, 922 .read = seq_read,
diff --git a/net/ipv4/route.c b/net/ipv4/route.c
index 2daa0dc19d33..9b5e56481d53 100644
--- a/net/ipv4/route.c
+++ b/net/ipv4/route.c
@@ -20,7 +20,7 @@
20 * (rco@di.uminho.pt) Routing table insertion and update 20 * (rco@di.uminho.pt) Routing table insertion and update
21 * Linus Torvalds : Rewrote bits to be sensible 21 * Linus Torvalds : Rewrote bits to be sensible
22 * Alan Cox : Added BSD route gw semantics 22 * Alan Cox : Added BSD route gw semantics
23 * Alan Cox : Super /proc >4K 23 * Alan Cox : Super /proc >4K
24 * Alan Cox : MTU in route table 24 * Alan Cox : MTU in route table
25 * Alan Cox : MSS actually. Also added the window 25 * Alan Cox : MSS actually. Also added the window
26 * clamper. 26 * clamper.
@@ -38,7 +38,7 @@
38 * Alan Cox : Faster /proc handling 38 * Alan Cox : Faster /proc handling
39 * Alexey Kuznetsov : Massive rework to support tree based routing, 39 * Alexey Kuznetsov : Massive rework to support tree based routing,
40 * routing caches and better behaviour. 40 * routing caches and better behaviour.
41 * 41 *
42 * Olaf Erb : irtt wasn't being copied right. 42 * Olaf Erb : irtt wasn't being copied right.
43 * Bjorn Ekwall : Kerneld route support. 43 * Bjorn Ekwall : Kerneld route support.
44 * Alan Cox : Multicast fixed (I hope) 44 * Alan Cox : Multicast fixed (I hope)
@@ -289,7 +289,7 @@ static struct rtable *rt_cache_get_next(struct seq_file *seq, struct rtable *r)
289{ 289{
290 struct rt_cache_iter_state *st = rcu_dereference(seq->private); 290 struct rt_cache_iter_state *st = rcu_dereference(seq->private);
291 291
292 r = r->u.rt_next; 292 r = r->u.dst.rt_next;
293 while (!r) { 293 while (!r) {
294 rcu_read_unlock_bh(); 294 rcu_read_unlock_bh();
295 if (--st->bucket < 0) 295 if (--st->bucket < 0)
@@ -361,8 +361,8 @@ static int rt_cache_seq_show(struct seq_file *seq, void *v)
361 dev_queue_xmit) : 0, 361 dev_queue_xmit) : 0,
362 r->rt_spec_dst); 362 r->rt_spec_dst);
363 seq_printf(seq, "%-127s\n", temp); 363 seq_printf(seq, "%-127s\n", temp);
364 } 364 }
365 return 0; 365 return 0;
366} 366}
367 367
368static struct seq_operations rt_cache_seq_ops = { 368static struct seq_operations rt_cache_seq_ops = {
@@ -393,7 +393,7 @@ out_kfree:
393 goto out; 393 goto out;
394} 394}
395 395
396static struct file_operations rt_cache_seq_fops = { 396static const struct file_operations rt_cache_seq_fops = {
397 .owner = THIS_MODULE, 397 .owner = THIS_MODULE,
398 .open = rt_cache_seq_open, 398 .open = rt_cache_seq_open,
399 .read = seq_read, 399 .read = seq_read,
@@ -429,7 +429,7 @@ static void *rt_cpu_seq_next(struct seq_file *seq, void *v, loff_t *pos)
429 return &per_cpu(rt_cache_stat, cpu); 429 return &per_cpu(rt_cache_stat, cpu);
430 } 430 }
431 return NULL; 431 return NULL;
432 432
433} 433}
434 434
435static void rt_cpu_seq_stop(struct seq_file *seq, void *v) 435static void rt_cpu_seq_stop(struct seq_file *seq, void *v)
@@ -445,7 +445,7 @@ static int rt_cpu_seq_show(struct seq_file *seq, void *v)
445 seq_printf(seq, "entries in_hit in_slow_tot in_slow_mc in_no_route in_brd in_martian_dst in_martian_src out_hit out_slow_tot out_slow_mc gc_total gc_ignored gc_goal_miss gc_dst_overflow in_hlist_search out_hlist_search\n"); 445 seq_printf(seq, "entries in_hit in_slow_tot in_slow_mc in_no_route in_brd in_martian_dst in_martian_src out_hit out_slow_tot out_slow_mc gc_total gc_ignored gc_goal_miss gc_dst_overflow in_hlist_search out_hlist_search\n");
446 return 0; 446 return 0;
447 } 447 }
448 448
449 seq_printf(seq,"%08x %08x %08x %08x %08x %08x %08x %08x " 449 seq_printf(seq,"%08x %08x %08x %08x %08x %08x %08x %08x "
450 " %08x %08x %08x %08x %08x %08x %08x %08x %08x \n", 450 " %08x %08x %08x %08x %08x %08x %08x %08x %08x \n",
451 atomic_read(&ipv4_dst_ops.entries), 451 atomic_read(&ipv4_dst_ops.entries),
@@ -459,7 +459,7 @@ static int rt_cpu_seq_show(struct seq_file *seq, void *v)
459 459
460 st->out_hit, 460 st->out_hit,
461 st->out_slow_tot, 461 st->out_slow_tot,
462 st->out_slow_mc, 462 st->out_slow_mc,
463 463
464 st->gc_total, 464 st->gc_total,
465 st->gc_ignored, 465 st->gc_ignored,
@@ -484,7 +484,7 @@ static int rt_cpu_seq_open(struct inode *inode, struct file *file)
484 return seq_open(file, &rt_cpu_seq_ops); 484 return seq_open(file, &rt_cpu_seq_ops);
485} 485}
486 486
487static struct file_operations rt_cpu_seq_fops = { 487static const struct file_operations rt_cpu_seq_fops = {
488 .owner = THIS_MODULE, 488 .owner = THIS_MODULE,
489 .open = rt_cpu_seq_open, 489 .open = rt_cpu_seq_open,
490 .read = seq_read, 490 .read = seq_read,
@@ -493,7 +493,7 @@ static struct file_operations rt_cpu_seq_fops = {
493}; 493};
494 494
495#endif /* CONFIG_PROC_FS */ 495#endif /* CONFIG_PROC_FS */
496 496
497static __inline__ void rt_free(struct rtable *rt) 497static __inline__ void rt_free(struct rtable *rt)
498{ 498{
499 multipath_remove(rt); 499 multipath_remove(rt);
@@ -512,7 +512,7 @@ static __inline__ int rt_fast_clean(struct rtable *rth)
512 /* Kill broadcast/multicast entries very aggresively, if they 512 /* Kill broadcast/multicast entries very aggresively, if they
513 collide in hash table with more useful entries */ 513 collide in hash table with more useful entries */
514 return (rth->rt_flags & (RTCF_BROADCAST | RTCF_MULTICAST)) && 514 return (rth->rt_flags & (RTCF_BROADCAST | RTCF_MULTICAST)) &&
515 rth->fl.iif && rth->u.rt_next; 515 rth->fl.iif && rth->u.dst.rt_next;
516} 516}
517 517
518static __inline__ int rt_valuable(struct rtable *rth) 518static __inline__ int rt_valuable(struct rtable *rth)
@@ -595,10 +595,10 @@ static struct rtable **rt_remove_balanced_route(struct rtable **chain_head,
595 if (((*rthp)->u.dst.flags & DST_BALANCED) != 0 && 595 if (((*rthp)->u.dst.flags & DST_BALANCED) != 0 &&
596 compare_keys(&(*rthp)->fl, &expentry->fl)) { 596 compare_keys(&(*rthp)->fl, &expentry->fl)) {
597 if (*rthp == expentry) { 597 if (*rthp == expentry) {
598 *rthp = rth->u.rt_next; 598 *rthp = rth->u.dst.rt_next;
599 continue; 599 continue;
600 } else { 600 } else {
601 *rthp = rth->u.rt_next; 601 *rthp = rth->u.dst.rt_next;
602 rt_free(rth); 602 rt_free(rth);
603 if (removed_count) 603 if (removed_count)
604 ++(*removed_count); 604 ++(*removed_count);
@@ -606,9 +606,9 @@ static struct rtable **rt_remove_balanced_route(struct rtable **chain_head,
606 } else { 606 } else {
607 if (!((*rthp)->u.dst.flags & DST_BALANCED) && 607 if (!((*rthp)->u.dst.flags & DST_BALANCED) &&
608 passedexpired && !nextstep) 608 passedexpired && !nextstep)
609 nextstep = &rth->u.rt_next; 609 nextstep = &rth->u.dst.rt_next;
610 610
611 rthp = &rth->u.rt_next; 611 rthp = &rth->u.dst.rt_next;
612 } 612 }
613 } 613 }
614 614
@@ -649,12 +649,12 @@ static void rt_check_expire(unsigned long dummy)
649 /* Entry is expired even if it is in use */ 649 /* Entry is expired even if it is in use */
650 if (time_before_eq(now, rth->u.dst.expires)) { 650 if (time_before_eq(now, rth->u.dst.expires)) {
651 tmo >>= 1; 651 tmo >>= 1;
652 rthp = &rth->u.rt_next; 652 rthp = &rth->u.dst.rt_next;
653 continue; 653 continue;
654 } 654 }
655 } else if (!rt_may_expire(rth, tmo, ip_rt_gc_timeout)) { 655 } else if (!rt_may_expire(rth, tmo, ip_rt_gc_timeout)) {
656 tmo >>= 1; 656 tmo >>= 1;
657 rthp = &rth->u.rt_next; 657 rthp = &rth->u.dst.rt_next;
658 continue; 658 continue;
659 } 659 }
660 660
@@ -668,12 +668,12 @@ static void rt_check_expire(unsigned long dummy)
668 if (!rthp) 668 if (!rthp)
669 break; 669 break;
670 } else { 670 } else {
671 *rthp = rth->u.rt_next; 671 *rthp = rth->u.dst.rt_next;
672 rt_free(rth); 672 rt_free(rth);
673 } 673 }
674#else /* CONFIG_IP_ROUTE_MULTIPATH_CACHED */ 674#else /* CONFIG_IP_ROUTE_MULTIPATH_CACHED */
675 *rthp = rth->u.rt_next; 675 *rthp = rth->u.dst.rt_next;
676 rt_free(rth); 676 rt_free(rth);
677#endif /* CONFIG_IP_ROUTE_MULTIPATH_CACHED */ 677#endif /* CONFIG_IP_ROUTE_MULTIPATH_CACHED */
678 } 678 }
679 spin_unlock(rt_hash_lock_addr(i)); 679 spin_unlock(rt_hash_lock_addr(i));
@@ -706,7 +706,7 @@ static void rt_run_flush(unsigned long dummy)
706 spin_unlock_bh(rt_hash_lock_addr(i)); 706 spin_unlock_bh(rt_hash_lock_addr(i));
707 707
708 for (; rth; rth = next) { 708 for (; rth; rth = next) {
709 next = rth->u.rt_next; 709 next = rth->u.dst.rt_next;
710 rt_free(rth); 710 rt_free(rth);
711 } 711 }
712 } 712 }
@@ -739,7 +739,7 @@ void rt_cache_flush(int delay)
739 739
740 if (user_mode && tmo < ip_rt_max_delay-ip_rt_min_delay) 740 if (user_mode && tmo < ip_rt_max_delay-ip_rt_min_delay)
741 tmo = 0; 741 tmo = 0;
742 742
743 if (delay > tmo) 743 if (delay > tmo)
744 delay = tmo; 744 delay = tmo;
745 } 745 }
@@ -840,7 +840,7 @@ static int rt_garbage_collect(void)
840 while ((rth = *rthp) != NULL) { 840 while ((rth = *rthp) != NULL) {
841 if (!rt_may_expire(rth, tmo, expire)) { 841 if (!rt_may_expire(rth, tmo, expire)) {
842 tmo >>= 1; 842 tmo >>= 1;
843 rthp = &rth->u.rt_next; 843 rthp = &rth->u.dst.rt_next;
844 continue; 844 continue;
845 } 845 }
846#ifdef CONFIG_IP_ROUTE_MULTIPATH_CACHED 846#ifdef CONFIG_IP_ROUTE_MULTIPATH_CACHED
@@ -858,12 +858,12 @@ static int rt_garbage_collect(void)
858 if (!rthp) 858 if (!rthp)
859 break; 859 break;
860 } else { 860 } else {
861 *rthp = rth->u.rt_next; 861 *rthp = rth->u.dst.rt_next;
862 rt_free(rth); 862 rt_free(rth);
863 goal--; 863 goal--;
864 } 864 }
865#else /* CONFIG_IP_ROUTE_MULTIPATH_CACHED */ 865#else /* CONFIG_IP_ROUTE_MULTIPATH_CACHED */
866 *rthp = rth->u.rt_next; 866 *rthp = rth->u.dst.rt_next;
867 rt_free(rth); 867 rt_free(rth);
868 goal--; 868 goal--;
869#endif /* CONFIG_IP_ROUTE_MULTIPATH_CACHED */ 869#endif /* CONFIG_IP_ROUTE_MULTIPATH_CACHED */
@@ -947,13 +947,13 @@ restart:
947 if (compare_keys(&rth->fl, &rt->fl)) { 947 if (compare_keys(&rth->fl, &rt->fl)) {
948#endif 948#endif
949 /* Put it first */ 949 /* Put it first */
950 *rthp = rth->u.rt_next; 950 *rthp = rth->u.dst.rt_next;
951 /* 951 /*
952 * Since lookup is lockfree, the deletion 952 * Since lookup is lockfree, the deletion
953 * must be visible to another weakly ordered CPU before 953 * must be visible to another weakly ordered CPU before
954 * the insertion at the start of the hash chain. 954 * the insertion at the start of the hash chain.
955 */ 955 */
956 rcu_assign_pointer(rth->u.rt_next, 956 rcu_assign_pointer(rth->u.dst.rt_next,
957 rt_hash_table[hash].chain); 957 rt_hash_table[hash].chain);
958 /* 958 /*
959 * Since lookup is lockfree, the update writes 959 * Since lookup is lockfree, the update writes
@@ -983,7 +983,7 @@ restart:
983 983
984 chain_length++; 984 chain_length++;
985 985
986 rthp = &rth->u.rt_next; 986 rthp = &rth->u.dst.rt_next;
987 } 987 }
988 988
989 if (cand) { 989 if (cand) {
@@ -994,7 +994,7 @@ restart:
994 * only 2 entries per bucket. We will see. 994 * only 2 entries per bucket. We will see.
995 */ 995 */
996 if (chain_length > ip_rt_gc_elasticity) { 996 if (chain_length > ip_rt_gc_elasticity) {
997 *candp = cand->u.rt_next; 997 *candp = cand->u.dst.rt_next;
998 rt_free(cand); 998 rt_free(cand);
999 } 999 }
1000 } 1000 }
@@ -1034,13 +1034,13 @@ restart:
1034 } 1034 }
1035 } 1035 }
1036 1036
1037 rt->u.rt_next = rt_hash_table[hash].chain; 1037 rt->u.dst.rt_next = rt_hash_table[hash].chain;
1038#if RT_CACHE_DEBUG >= 2 1038#if RT_CACHE_DEBUG >= 2
1039 if (rt->u.rt_next) { 1039 if (rt->u.dst.rt_next) {
1040 struct rtable *trt; 1040 struct rtable *trt;
1041 printk(KERN_DEBUG "rt_cache @%02x: %u.%u.%u.%u", hash, 1041 printk(KERN_DEBUG "rt_cache @%02x: %u.%u.%u.%u", hash,
1042 NIPQUAD(rt->rt_dst)); 1042 NIPQUAD(rt->rt_dst));
1043 for (trt = rt->u.rt_next; trt; trt = trt->u.rt_next) 1043 for (trt = rt->u.dst.rt_next; trt; trt = trt->u.dst.rt_next)
1044 printk(" . %u.%u.%u.%u", NIPQUAD(trt->rt_dst)); 1044 printk(" . %u.%u.%u.%u", NIPQUAD(trt->rt_dst));
1045 printk("\n"); 1045 printk("\n");
1046 } 1046 }
@@ -1104,7 +1104,7 @@ void __ip_select_ident(struct iphdr *iph, struct dst_entry *dst, int more)
1104 return; 1104 return;
1105 } 1105 }
1106 } else 1106 } else
1107 printk(KERN_DEBUG "rt_bind_peer(0) @%p\n", 1107 printk(KERN_DEBUG "rt_bind_peer(0) @%p\n",
1108 __builtin_return_address(0)); 1108 __builtin_return_address(0));
1109 1109
1110 ip_select_fb_ident(iph); 1110 ip_select_fb_ident(iph);
@@ -1117,9 +1117,9 @@ static void rt_del(unsigned hash, struct rtable *rt)
1117 spin_lock_bh(rt_hash_lock_addr(hash)); 1117 spin_lock_bh(rt_hash_lock_addr(hash));
1118 ip_rt_put(rt); 1118 ip_rt_put(rt);
1119 for (rthp = &rt_hash_table[hash].chain; *rthp; 1119 for (rthp = &rt_hash_table[hash].chain; *rthp;
1120 rthp = &(*rthp)->u.rt_next) 1120 rthp = &(*rthp)->u.dst.rt_next)
1121 if (*rthp == rt) { 1121 if (*rthp == rt) {
1122 *rthp = rt->u.rt_next; 1122 *rthp = rt->u.dst.rt_next;
1123 rt_free(rt); 1123 rt_free(rt);
1124 break; 1124 break;
1125 } 1125 }
@@ -1167,7 +1167,7 @@ void ip_rt_redirect(__be32 old_gw, __be32 daddr, __be32 new_gw,
1167 rth->fl.fl4_src != skeys[i] || 1167 rth->fl.fl4_src != skeys[i] ||
1168 rth->fl.oif != ikeys[k] || 1168 rth->fl.oif != ikeys[k] ||
1169 rth->fl.iif != 0) { 1169 rth->fl.iif != 0) {
1170 rthp = &rth->u.rt_next; 1170 rthp = &rth->u.dst.rt_next;
1171 continue; 1171 continue;
1172 } 1172 }
1173 1173
@@ -1190,7 +1190,7 @@ void ip_rt_redirect(__be32 old_gw, __be32 daddr, __be32 new_gw,
1190 1190
1191 /* Copy all the information. */ 1191 /* Copy all the information. */
1192 *rt = *rth; 1192 *rt = *rth;
1193 INIT_RCU_HEAD(&rt->u.dst.rcu_head); 1193 INIT_RCU_HEAD(&rt->u.dst.rcu_head);
1194 rt->u.dst.__use = 1; 1194 rt->u.dst.__use = 1;
1195 atomic_set(&rt->u.dst.__refcnt, 1); 1195 atomic_set(&rt->u.dst.__refcnt, 1);
1196 rt->u.dst.child = NULL; 1196 rt->u.dst.child = NULL;
@@ -1225,11 +1225,11 @@ void ip_rt_redirect(__be32 old_gw, __be32 daddr, __be32 new_gw,
1225 rt_drop(rt); 1225 rt_drop(rt);
1226 goto do_next; 1226 goto do_next;
1227 } 1227 }
1228 1228
1229 netevent.old = &rth->u.dst; 1229 netevent.old = &rth->u.dst;
1230 netevent.new = &rt->u.dst; 1230 netevent.new = &rt->u.dst;
1231 call_netevent_notifiers(NETEVENT_REDIRECT, 1231 call_netevent_notifiers(NETEVENT_REDIRECT,
1232 &netevent); 1232 &netevent);
1233 1233
1234 rt_del(hash, rth); 1234 rt_del(hash, rth);
1235 if (!rt_intern_hash(hash, rt, &rt)) 1235 if (!rt_intern_hash(hash, rt, &rt))
@@ -1343,7 +1343,7 @@ void ip_rt_send_redirect(struct sk_buff *skb)
1343#endif 1343#endif
1344 } 1344 }
1345out: 1345out:
1346 in_dev_put(in_dev); 1346 in_dev_put(in_dev);
1347} 1347}
1348 1348
1349static int ip_error(struct sk_buff *skb) 1349static int ip_error(struct sk_buff *skb)
@@ -1379,7 +1379,7 @@ static int ip_error(struct sk_buff *skb)
1379 1379
1380out: kfree_skb(skb); 1380out: kfree_skb(skb);
1381 return 0; 1381 return 0;
1382} 1382}
1383 1383
1384/* 1384/*
1385 * The last two values are not from the RFC but 1385 * The last two values are not from the RFC but
@@ -1392,7 +1392,7 @@ static const unsigned short mtu_plateau[] =
1392static __inline__ unsigned short guess_mtu(unsigned short old_mtu) 1392static __inline__ unsigned short guess_mtu(unsigned short old_mtu)
1393{ 1393{
1394 int i; 1394 int i;
1395 1395
1396 for (i = 0; i < ARRAY_SIZE(mtu_plateau); i++) 1396 for (i = 0; i < ARRAY_SIZE(mtu_plateau); i++)
1397 if (old_mtu > mtu_plateau[i]) 1397 if (old_mtu > mtu_plateau[i])
1398 return mtu_plateau[i]; 1398 return mtu_plateau[i];
@@ -1416,7 +1416,7 @@ unsigned short ip_rt_frag_needed(struct iphdr *iph, unsigned short new_mtu)
1416 1416
1417 rcu_read_lock(); 1417 rcu_read_lock();
1418 for (rth = rcu_dereference(rt_hash_table[hash].chain); rth; 1418 for (rth = rcu_dereference(rt_hash_table[hash].chain); rth;
1419 rth = rcu_dereference(rth->u.rt_next)) { 1419 rth = rcu_dereference(rth->u.dst.rt_next)) {
1420 if (rth->fl.fl4_dst == daddr && 1420 if (rth->fl.fl4_dst == daddr &&
1421 rth->fl.fl4_src == skeys[i] && 1421 rth->fl.fl4_src == skeys[i] &&
1422 rth->rt_dst == daddr && 1422 rth->rt_dst == daddr &&
@@ -1436,7 +1436,7 @@ unsigned short ip_rt_frag_needed(struct iphdr *iph, unsigned short new_mtu)
1436 mtu = guess_mtu(old_mtu); 1436 mtu = guess_mtu(old_mtu);
1437 } 1437 }
1438 if (mtu <= rth->u.dst.metrics[RTAX_MTU-1]) { 1438 if (mtu <= rth->u.dst.metrics[RTAX_MTU-1]) {
1439 if (mtu < rth->u.dst.metrics[RTAX_MTU-1]) { 1439 if (mtu < rth->u.dst.metrics[RTAX_MTU-1]) {
1440 dst_confirm(&rth->u.dst); 1440 dst_confirm(&rth->u.dst);
1441 if (mtu < ip_rt_min_pmtu) { 1441 if (mtu < ip_rt_min_pmtu) {
1442 mtu = ip_rt_min_pmtu; 1442 mtu = ip_rt_min_pmtu;
@@ -1600,7 +1600,7 @@ static void rt_set_nexthop(struct rtable *rt, struct fib_result *res, u32 itag)
1600#endif 1600#endif
1601 set_class_tag(rt, itag); 1601 set_class_tag(rt, itag);
1602#endif 1602#endif
1603 rt->rt_type = res->type; 1603 rt->rt_type = res->type;
1604} 1604}
1605 1605
1606static int ip_route_input_mc(struct sk_buff *skb, __be32 daddr, __be32 saddr, 1606static int ip_route_input_mc(struct sk_buff *skb, __be32 daddr, __be32 saddr,
@@ -1714,11 +1714,11 @@ static void ip_handle_martian_source(struct net_device *dev,
1714#endif 1714#endif
1715} 1715}
1716 1716
1717static inline int __mkroute_input(struct sk_buff *skb, 1717static inline int __mkroute_input(struct sk_buff *skb,
1718 struct fib_result* res, 1718 struct fib_result* res,
1719 struct in_device *in_dev, 1719 struct in_device *in_dev,
1720 __be32 daddr, __be32 saddr, u32 tos, 1720 __be32 daddr, __be32 saddr, u32 tos,
1721 struct rtable **result) 1721 struct rtable **result)
1722{ 1722{
1723 1723
1724 struct rtable *rth; 1724 struct rtable *rth;
@@ -1738,12 +1738,12 @@ static inline int __mkroute_input(struct sk_buff *skb,
1738 } 1738 }
1739 1739
1740 1740
1741 err = fib_validate_source(saddr, daddr, tos, FIB_RES_OIF(*res), 1741 err = fib_validate_source(saddr, daddr, tos, FIB_RES_OIF(*res),
1742 in_dev->dev, &spec_dst, &itag); 1742 in_dev->dev, &spec_dst, &itag);
1743 if (err < 0) { 1743 if (err < 0) {
1744 ip_handle_martian_source(in_dev->dev, in_dev, skb, daddr, 1744 ip_handle_martian_source(in_dev->dev, in_dev, skb, daddr,
1745 saddr); 1745 saddr);
1746 1746
1747 err = -EINVAL; 1747 err = -EINVAL;
1748 goto cleanup; 1748 goto cleanup;
1749 } 1749 }
@@ -1811,10 +1811,10 @@ static inline int __mkroute_input(struct sk_buff *skb,
1811 /* release the working reference to the output device */ 1811 /* release the working reference to the output device */
1812 in_dev_put(out_dev); 1812 in_dev_put(out_dev);
1813 return err; 1813 return err;
1814} 1814}
1815 1815
1816static inline int ip_mkroute_input_def(struct sk_buff *skb, 1816static inline int ip_mkroute_input_def(struct sk_buff *skb,
1817 struct fib_result* res, 1817 struct fib_result* res,
1818 const struct flowi *fl, 1818 const struct flowi *fl,
1819 struct in_device *in_dev, 1819 struct in_device *in_dev,
1820 __be32 daddr, __be32 saddr, u32 tos) 1820 __be32 daddr, __be32 saddr, u32 tos)
@@ -1835,11 +1835,11 @@ static inline int ip_mkroute_input_def(struct sk_buff *skb,
1835 1835
1836 /* put it into the cache */ 1836 /* put it into the cache */
1837 hash = rt_hash(daddr, saddr, fl->iif); 1837 hash = rt_hash(daddr, saddr, fl->iif);
1838 return rt_intern_hash(hash, rth, (struct rtable**)&skb->dst); 1838 return rt_intern_hash(hash, rth, (struct rtable**)&skb->dst);
1839} 1839}
1840 1840
1841static inline int ip_mkroute_input(struct sk_buff *skb, 1841static inline int ip_mkroute_input(struct sk_buff *skb,
1842 struct fib_result* res, 1842 struct fib_result* res,
1843 const struct flowi *fl, 1843 const struct flowi *fl,
1844 struct in_device *in_dev, 1844 struct in_device *in_dev,
1845 __be32 daddr, __be32 saddr, u32 tos) 1845 __be32 daddr, __be32 saddr, u32 tos)
@@ -1859,7 +1859,7 @@ static inline int ip_mkroute_input(struct sk_buff *skb,
1859 if (hopcount < 2) 1859 if (hopcount < 2)
1860 return ip_mkroute_input_def(skb, res, fl, in_dev, daddr, 1860 return ip_mkroute_input_def(skb, res, fl, in_dev, daddr,
1861 saddr, tos); 1861 saddr, tos);
1862 1862
1863 /* add all alternatives to the routing cache */ 1863 /* add all alternatives to the routing cache */
1864 for (hop = 0; hop < hopcount; hop++) { 1864 for (hop = 0; hop < hopcount; hop++) {
1865 res->nh_sel = hop; 1865 res->nh_sel = hop;
@@ -1988,7 +1988,7 @@ static int ip_route_input_slow(struct sk_buff *skb, __be32 daddr, __be32 saddr,
1988 goto e_nobufs; 1988 goto e_nobufs;
1989 if (err == -EINVAL) 1989 if (err == -EINVAL)
1990 goto e_inval; 1990 goto e_inval;
1991 1991
1992done: 1992done:
1993 in_dev_put(in_dev); 1993 in_dev_put(in_dev);
1994 if (free_res) 1994 if (free_res)
@@ -2071,8 +2071,8 @@ martian_destination:
2071#endif 2071#endif
2072 2072
2073e_hostunreach: 2073e_hostunreach:
2074 err = -EHOSTUNREACH; 2074 err = -EHOSTUNREACH;
2075 goto done; 2075 goto done;
2076 2076
2077e_inval: 2077e_inval:
2078 err = -EINVAL; 2078 err = -EINVAL;
@@ -2099,7 +2099,7 @@ int ip_route_input(struct sk_buff *skb, __be32 daddr, __be32 saddr,
2099 2099
2100 rcu_read_lock(); 2100 rcu_read_lock();
2101 for (rth = rcu_dereference(rt_hash_table[hash].chain); rth; 2101 for (rth = rcu_dereference(rt_hash_table[hash].chain); rth;
2102 rth = rcu_dereference(rth->u.rt_next)) { 2102 rth = rcu_dereference(rth->u.dst.rt_next)) {
2103 if (rth->fl.fl4_dst == daddr && 2103 if (rth->fl.fl4_dst == daddr &&
2104 rth->fl.fl4_src == saddr && 2104 rth->fl.fl4_src == saddr &&
2105 rth->fl.iif == iif && 2105 rth->fl.iif == iif &&
@@ -2153,11 +2153,11 @@ int ip_route_input(struct sk_buff *skb, __be32 daddr, __be32 saddr,
2153} 2153}
2154 2154
2155static inline int __mkroute_output(struct rtable **result, 2155static inline int __mkroute_output(struct rtable **result,
2156 struct fib_result* res, 2156 struct fib_result* res,
2157 const struct flowi *fl, 2157 const struct flowi *fl,
2158 const struct flowi *oldflp, 2158 const struct flowi *oldflp,
2159 struct net_device *dev_out, 2159 struct net_device *dev_out,
2160 unsigned flags) 2160 unsigned flags)
2161{ 2161{
2162 struct rtable *rth; 2162 struct rtable *rth;
2163 struct in_device *in_dev; 2163 struct in_device *in_dev;
@@ -2190,7 +2190,7 @@ static inline int __mkroute_output(struct rtable **result,
2190 } 2190 }
2191 } else if (res->type == RTN_MULTICAST) { 2191 } else if (res->type == RTN_MULTICAST) {
2192 flags |= RTCF_MULTICAST|RTCF_LOCAL; 2192 flags |= RTCF_MULTICAST|RTCF_LOCAL;
2193 if (!ip_check_mc(in_dev, oldflp->fl4_dst, oldflp->fl4_src, 2193 if (!ip_check_mc(in_dev, oldflp->fl4_dst, oldflp->fl4_src,
2194 oldflp->proto)) 2194 oldflp->proto))
2195 flags &= ~RTCF_LOCAL; 2195 flags &= ~RTCF_LOCAL;
2196 /* If multicast route do not exist use 2196 /* If multicast route do not exist use
@@ -2208,7 +2208,7 @@ static inline int __mkroute_output(struct rtable **result,
2208 if (!rth) { 2208 if (!rth) {
2209 err = -ENOBUFS; 2209 err = -ENOBUFS;
2210 goto cleanup; 2210 goto cleanup;
2211 } 2211 }
2212 2212
2213 atomic_set(&rth->u.dst.__refcnt, 1); 2213 atomic_set(&rth->u.dst.__refcnt, 1);
2214 rth->u.dst.flags= DST_HOST; 2214 rth->u.dst.flags= DST_HOST;
@@ -2232,7 +2232,7 @@ static inline int __mkroute_output(struct rtable **result,
2232 rth->rt_dst = fl->fl4_dst; 2232 rth->rt_dst = fl->fl4_dst;
2233 rth->rt_src = fl->fl4_src; 2233 rth->rt_src = fl->fl4_src;
2234 rth->rt_iif = oldflp->oif ? : dev_out->ifindex; 2234 rth->rt_iif = oldflp->oif ? : dev_out->ifindex;
2235 /* get references to the devices that are to be hold by the routing 2235 /* get references to the devices that are to be hold by the routing
2236 cache entry */ 2236 cache entry */
2237 rth->u.dst.dev = dev_out; 2237 rth->u.dst.dev = dev_out;
2238 dev_hold(dev_out); 2238 dev_hold(dev_out);
@@ -2250,7 +2250,7 @@ static inline int __mkroute_output(struct rtable **result,
2250 } 2250 }
2251 if (flags & (RTCF_BROADCAST | RTCF_MULTICAST)) { 2251 if (flags & (RTCF_BROADCAST | RTCF_MULTICAST)) {
2252 rth->rt_spec_dst = fl->fl4_src; 2252 rth->rt_spec_dst = fl->fl4_src;
2253 if (flags & RTCF_LOCAL && 2253 if (flags & RTCF_LOCAL &&
2254 !(dev_out->flags & IFF_LOOPBACK)) { 2254 !(dev_out->flags & IFF_LOOPBACK)) {
2255 rth->u.dst.output = ip_mc_output; 2255 rth->u.dst.output = ip_mc_output;
2256 RT_CACHE_STAT_INC(out_slow_mc); 2256 RT_CACHE_STAT_INC(out_slow_mc);
@@ -2292,7 +2292,7 @@ static inline int ip_mkroute_output_def(struct rtable **rp,
2292 hash = rt_hash(oldflp->fl4_dst, oldflp->fl4_src, oldflp->oif); 2292 hash = rt_hash(oldflp->fl4_dst, oldflp->fl4_src, oldflp->oif);
2293 err = rt_intern_hash(hash, rth, rp); 2293 err = rt_intern_hash(hash, rth, rp);
2294 } 2294 }
2295 2295
2296 return err; 2296 return err;
2297} 2297}
2298 2298
@@ -2563,7 +2563,7 @@ int __ip_route_output_key(struct rtable **rp, const struct flowi *flp)
2563 2563
2564 rcu_read_lock_bh(); 2564 rcu_read_lock_bh();
2565 for (rth = rcu_dereference(rt_hash_table[hash].chain); rth; 2565 for (rth = rcu_dereference(rt_hash_table[hash].chain); rth;
2566 rth = rcu_dereference(rth->u.rt_next)) { 2566 rth = rcu_dereference(rth->u.dst.rt_next)) {
2567 if (rth->fl.fl4_dst == flp->fl4_dst && 2567 if (rth->fl.fl4_dst == flp->fl4_dst &&
2568 rth->fl.fl4_src == flp->fl4_src && 2568 rth->fl.fl4_src == flp->fl4_src &&
2569 rth->fl.iif == 0 && 2569 rth->fl.iif == 0 &&
@@ -2635,7 +2635,7 @@ static int rt_fill_info(struct sk_buff *skb, u32 pid, u32 seq, int event,
2635 2635
2636 nlh = nlmsg_put(skb, pid, seq, event, sizeof(*r), flags); 2636 nlh = nlmsg_put(skb, pid, seq, event, sizeof(*r), flags);
2637 if (nlh == NULL) 2637 if (nlh == NULL)
2638 return -ENOBUFS; 2638 return -EMSGSIZE;
2639 2639
2640 r = nlmsg_data(nlh); 2640 r = nlmsg_data(nlh);
2641 r->rtm_family = AF_INET; 2641 r->rtm_family = AF_INET;
@@ -2718,7 +2718,8 @@ static int rt_fill_info(struct sk_buff *skb, u32 pid, u32 seq, int event,
2718 return nlmsg_end(skb, nlh); 2718 return nlmsg_end(skb, nlh);
2719 2719
2720nla_put_failure: 2720nla_put_failure:
2721 return nlmsg_cancel(skb, nlh); 2721 nlmsg_cancel(skb, nlh);
2722 return -EMSGSIZE;
2722} 2723}
2723 2724
2724int inet_rtm_getroute(struct sk_buff *in_skb, struct nlmsghdr* nlh, void *arg) 2725int inet_rtm_getroute(struct sk_buff *in_skb, struct nlmsghdr* nlh, void *arg)
@@ -2824,12 +2825,12 @@ int ip_rt_dump(struct sk_buff *skb, struct netlink_callback *cb)
2824 s_idx = 0; 2825 s_idx = 0;
2825 rcu_read_lock_bh(); 2826 rcu_read_lock_bh();
2826 for (rt = rcu_dereference(rt_hash_table[h].chain), idx = 0; rt; 2827 for (rt = rcu_dereference(rt_hash_table[h].chain), idx = 0; rt;
2827 rt = rcu_dereference(rt->u.rt_next), idx++) { 2828 rt = rcu_dereference(rt->u.dst.rt_next), idx++) {
2828 if (idx < s_idx) 2829 if (idx < s_idx)
2829 continue; 2830 continue;
2830 skb->dst = dst_clone(&rt->u.dst); 2831 skb->dst = dst_clone(&rt->u.dst);
2831 if (rt_fill_info(skb, NETLINK_CB(cb->skb).pid, 2832 if (rt_fill_info(skb, NETLINK_CB(cb->skb).pid,
2832 cb->nlh->nlmsg_seq, RTM_NEWROUTE, 2833 cb->nlh->nlmsg_seq, RTM_NEWROUTE,
2833 1, NLM_F_MULTI) <= 0) { 2834 1, NLM_F_MULTI) <= 0) {
2834 dst_release(xchg(&skb->dst, NULL)); 2835 dst_release(xchg(&skb->dst, NULL));
2835 rcu_read_unlock_bh(); 2836 rcu_read_unlock_bh();
@@ -2862,7 +2863,7 @@ static int ipv4_sysctl_rtcache_flush(ctl_table *ctl, int write,
2862 proc_dointvec(ctl, write, filp, buffer, lenp, ppos); 2863 proc_dointvec(ctl, write, filp, buffer, lenp, ppos);
2863 rt_cache_flush(flush_delay); 2864 rt_cache_flush(flush_delay);
2864 return 0; 2865 return 0;
2865 } 2866 }
2866 2867
2867 return -EINVAL; 2868 return -EINVAL;
2868} 2869}
@@ -2879,13 +2880,13 @@ static int ipv4_sysctl_rtcache_flush_strategy(ctl_table *table,
2879 if (newlen != sizeof(int)) 2880 if (newlen != sizeof(int))
2880 return -EINVAL; 2881 return -EINVAL;
2881 if (get_user(delay, (int __user *)newval)) 2882 if (get_user(delay, (int __user *)newval))
2882 return -EFAULT; 2883 return -EFAULT;
2883 rt_cache_flush(delay); 2884 rt_cache_flush(delay);
2884 return 0; 2885 return 0;
2885} 2886}
2886 2887
2887ctl_table ipv4_route_table[] = { 2888ctl_table ipv4_route_table[] = {
2888 { 2889 {
2889 .ctl_name = NET_IPV4_ROUTE_FLUSH, 2890 .ctl_name = NET_IPV4_ROUTE_FLUSH,
2890 .procname = "flush", 2891 .procname = "flush",
2891 .data = &flush_delay, 2892 .data = &flush_delay,
@@ -2930,7 +2931,7 @@ ctl_table ipv4_route_table[] = {
2930 }, 2931 },
2931 { 2932 {
2932 /* Deprecated. Use gc_min_interval_ms */ 2933 /* Deprecated. Use gc_min_interval_ms */
2933 2934
2934 .ctl_name = NET_IPV4_ROUTE_GC_MIN_INTERVAL, 2935 .ctl_name = NET_IPV4_ROUTE_GC_MIN_INTERVAL,
2935 .procname = "gc_min_interval", 2936 .procname = "gc_min_interval",
2936 .data = &ip_rt_gc_min_interval, 2937 .data = &ip_rt_gc_min_interval,
@@ -3179,8 +3180,8 @@ int __init ip_rt_init(void)
3179 { 3180 {
3180 struct proc_dir_entry *rtstat_pde = NULL; /* keep gcc happy */ 3181 struct proc_dir_entry *rtstat_pde = NULL; /* keep gcc happy */
3181 if (!proc_net_fops_create("rt_cache", S_IRUGO, &rt_cache_seq_fops) || 3182 if (!proc_net_fops_create("rt_cache", S_IRUGO, &rt_cache_seq_fops) ||
3182 !(rtstat_pde = create_proc_entry("rt_cache", S_IRUGO, 3183 !(rtstat_pde = create_proc_entry("rt_cache", S_IRUGO,
3183 proc_net_stat))) { 3184 proc_net_stat))) {
3184 return -ENOMEM; 3185 return -ENOMEM;
3185 } 3186 }
3186 rtstat_pde->proc_fops = &rt_cpu_seq_fops; 3187 rtstat_pde->proc_fops = &rt_cpu_seq_fops;
diff --git a/net/ipv4/syncookies.c b/net/ipv4/syncookies.c
index 6b19530905af..33016cc90f0b 100644
--- a/net/ipv4/syncookies.c
+++ b/net/ipv4/syncookies.c
@@ -2,16 +2,16 @@
2 * Syncookies implementation for the Linux kernel 2 * Syncookies implementation for the Linux kernel
3 * 3 *
4 * Copyright (C) 1997 Andi Kleen 4 * Copyright (C) 1997 Andi Kleen
5 * Based on ideas by D.J.Bernstein and Eric Schenk. 5 * Based on ideas by D.J.Bernstein and Eric Schenk.
6 * 6 *
7 * This program is free software; you can redistribute it and/or 7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License 8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 9 * as published by the Free Software Foundation; either version
10 * 2 of the License, or (at your option) any later version. 10 * 2 of the License, or (at your option) any later version.
11 * 11 *
12 * $Id: syncookies.c,v 1.18 2002/02/01 22:01:04 davem Exp $ 12 * $Id: syncookies.c,v 1.18 2002/02/01 22:01:04 davem Exp $
13 * 13 *
14 * Missing: IPv6 support. 14 * Missing: IPv6 support.
15 */ 15 */
16 16
17#include <linux/tcp.h> 17#include <linux/tcp.h>
@@ -57,7 +57,7 @@ static __u32 secure_tcp_syn_cookie(__be32 saddr, __be32 daddr, __be16 sport,
57 /* 57 /*
58 * Compute the secure sequence number. 58 * Compute the secure sequence number.
59 * The output should be: 59 * The output should be:
60 * HASH(sec1,saddr,sport,daddr,dport,sec1) + sseq + (count * 2^24) 60 * HASH(sec1,saddr,sport,daddr,dport,sec1) + sseq + (count * 2^24)
61 * + (HASH(sec2,saddr,sport,daddr,dport,count,sec2) % 2^24). 61 * + (HASH(sec2,saddr,sport,daddr,dport,count,sec2) % 2^24).
62 * Where sseq is their sequence number and count increases every 62 * Where sseq is their sequence number and count increases every
63 * minute by 1. 63 * minute by 1.
@@ -99,17 +99,17 @@ static __u32 check_tcp_syn_cookie(__u32 cookie, __be32 saddr, __be32 daddr,
99 & COOKIEMASK; /* Leaving the data behind */ 99 & COOKIEMASK; /* Leaving the data behind */
100} 100}
101 101
102/* 102/*
103 * This table has to be sorted and terminated with (__u16)-1. 103 * This table has to be sorted and terminated with (__u16)-1.
104 * XXX generate a better table. 104 * XXX generate a better table.
105 * Unresolved Issues: HIPPI with a 64k MSS is not well supported. 105 * Unresolved Issues: HIPPI with a 64k MSS is not well supported.
106 */ 106 */
107static __u16 const msstab[] = { 107static __u16 const msstab[] = {
108 64 - 1, 108 64 - 1,
109 256 - 1, 109 256 - 1,
110 512 - 1, 110 512 - 1,
111 536 - 1, 111 536 - 1,
112 1024 - 1, 112 1024 - 1,
113 1440 - 1, 113 1440 - 1,
114 1460 - 1, 114 1460 - 1,
115 4312 - 1, 115 4312 - 1,
@@ -128,7 +128,7 @@ __u32 cookie_v4_init_sequence(struct sock *sk, struct sk_buff *skb, __u16 *mssp)
128 int mssind; 128 int mssind;
129 const __u16 mss = *mssp; 129 const __u16 mss = *mssp;
130 130
131 131
132 tp->last_synq_overflow = jiffies; 132 tp->last_synq_overflow = jiffies;
133 133
134 /* XXX sort msstab[] by probability? Binary search? */ 134 /* XXX sort msstab[] by probability? Binary search? */
@@ -144,23 +144,23 @@ __u32 cookie_v4_init_sequence(struct sock *sk, struct sk_buff *skb, __u16 *mssp)
144 jiffies / (HZ * 60), mssind); 144 jiffies / (HZ * 60), mssind);
145} 145}
146 146
147/* 147/*
148 * This (misnamed) value is the age of syncookie which is permitted. 148 * This (misnamed) value is the age of syncookie which is permitted.
149 * Its ideal value should be dependent on TCP_TIMEOUT_INIT and 149 * Its ideal value should be dependent on TCP_TIMEOUT_INIT and
150 * sysctl_tcp_retries1. It's a rather complicated formula (exponential 150 * sysctl_tcp_retries1. It's a rather complicated formula (exponential
151 * backoff) to compute at runtime so it's currently hardcoded here. 151 * backoff) to compute at runtime so it's currently hardcoded here.
152 */ 152 */
153#define COUNTER_TRIES 4 153#define COUNTER_TRIES 4
154/* 154/*
155 * Check if a ack sequence number is a valid syncookie. 155 * Check if a ack sequence number is a valid syncookie.
156 * Return the decoded mss if it is, or 0 if not. 156 * Return the decoded mss if it is, or 0 if not.
157 */ 157 */
158static inline int cookie_check(struct sk_buff *skb, __u32 cookie) 158static inline int cookie_check(struct sk_buff *skb, __u32 cookie)
159{ 159{
160 __u32 seq; 160 __u32 seq;
161 __u32 mssind; 161 __u32 mssind;
162 162
163 seq = ntohl(skb->h.th->seq)-1; 163 seq = ntohl(skb->h.th->seq)-1;
164 mssind = check_tcp_syn_cookie(cookie, 164 mssind = check_tcp_syn_cookie(cookie,
165 skb->nh.iph->saddr, skb->nh.iph->daddr, 165 skb->nh.iph->saddr, skb->nh.iph->daddr,
166 skb->h.th->source, skb->h.th->dest, 166 skb->h.th->source, skb->h.th->dest,
@@ -191,19 +191,19 @@ struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb,
191 struct inet_request_sock *ireq; 191 struct inet_request_sock *ireq;
192 struct tcp_request_sock *treq; 192 struct tcp_request_sock *treq;
193 struct tcp_sock *tp = tcp_sk(sk); 193 struct tcp_sock *tp = tcp_sk(sk);
194 __u32 cookie = ntohl(skb->h.th->ack_seq) - 1; 194 __u32 cookie = ntohl(skb->h.th->ack_seq) - 1;
195 struct sock *ret = sk; 195 struct sock *ret = sk;
196 struct request_sock *req; 196 struct request_sock *req;
197 int mss; 197 int mss;
198 struct rtable *rt; 198 struct rtable *rt;
199 __u8 rcv_wscale; 199 __u8 rcv_wscale;
200 200
201 if (!sysctl_tcp_syncookies || !skb->h.th->ack) 201 if (!sysctl_tcp_syncookies || !skb->h.th->ack)
202 goto out; 202 goto out;
203 203
204 if (time_after(jiffies, tp->last_synq_overflow + TCP_TIMEOUT_INIT) || 204 if (time_after(jiffies, tp->last_synq_overflow + TCP_TIMEOUT_INIT) ||
205 (mss = cookie_check(skb, cookie)) == 0) { 205 (mss = cookie_check(skb, cookie)) == 0) {
206 NET_INC_STATS_BH(LINUX_MIB_SYNCOOKIESFAILED); 206 NET_INC_STATS_BH(LINUX_MIB_SYNCOOKIESFAILED);
207 goto out; 207 goto out;
208 } 208 }
209 209
@@ -221,9 +221,9 @@ struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb,
221 ireq = inet_rsk(req); 221 ireq = inet_rsk(req);
222 treq = tcp_rsk(req); 222 treq = tcp_rsk(req);
223 treq->rcv_isn = ntohl(skb->h.th->seq) - 1; 223 treq->rcv_isn = ntohl(skb->h.th->seq) - 1;
224 treq->snt_isn = cookie; 224 treq->snt_isn = cookie;
225 req->mss = mss; 225 req->mss = mss;
226 ireq->rmt_port = skb->h.th->source; 226 ireq->rmt_port = skb->h.th->source;
227 ireq->loc_addr = skb->nh.iph->daddr; 227 ireq->loc_addr = skb->nh.iph->daddr;
228 ireq->rmt_addr = skb->nh.iph->saddr; 228 ireq->rmt_addr = skb->nh.iph->saddr;
229 ireq->opt = NULL; 229 ireq->opt = NULL;
@@ -242,15 +242,15 @@ struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb,
242 } 242 }
243 243
244 ireq->snd_wscale = ireq->rcv_wscale = ireq->tstamp_ok = 0; 244 ireq->snd_wscale = ireq->rcv_wscale = ireq->tstamp_ok = 0;
245 ireq->wscale_ok = ireq->sack_ok = 0; 245 ireq->wscale_ok = ireq->sack_ok = 0;
246 req->expires = 0UL; 246 req->expires = 0UL;
247 req->retrans = 0; 247 req->retrans = 0;
248 248
249 /* 249 /*
250 * We need to lookup the route here to get at the correct 250 * We need to lookup the route here to get at the correct
251 * window size. We should better make sure that the window size 251 * window size. We should better make sure that the window size
252 * hasn't changed since we received the original syn, but I see 252 * hasn't changed since we received the original syn, but I see
253 * no easy way to do this. 253 * no easy way to do this.
254 */ 254 */
255 { 255 {
256 struct flowi fl = { .nl_u = { .ip4_u = 256 struct flowi fl = { .nl_u = { .ip4_u =
@@ -266,17 +266,17 @@ struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb,
266 security_req_classify_flow(req, &fl); 266 security_req_classify_flow(req, &fl);
267 if (ip_route_output_key(&rt, &fl)) { 267 if (ip_route_output_key(&rt, &fl)) {
268 reqsk_free(req); 268 reqsk_free(req);
269 goto out; 269 goto out;
270 } 270 }
271 } 271 }
272 272
273 /* Try to redo what tcp_v4_send_synack did. */ 273 /* Try to redo what tcp_v4_send_synack did. */
274 req->window_clamp = dst_metric(&rt->u.dst, RTAX_WINDOW); 274 req->window_clamp = dst_metric(&rt->u.dst, RTAX_WINDOW);
275 tcp_select_initial_window(tcp_full_space(sk), req->mss, 275 tcp_select_initial_window(tcp_full_space(sk), req->mss,
276 &req->rcv_wnd, &req->window_clamp, 276 &req->rcv_wnd, &req->window_clamp,
277 0, &rcv_wscale); 277 0, &rcv_wscale);
278 /* BTW win scale with syncookies is 0 by definition */ 278 /* BTW win scale with syncookies is 0 by definition */
279 ireq->rcv_wscale = rcv_wscale; 279 ireq->rcv_wscale = rcv_wscale;
280 280
281 ret = get_cookie_sock(sk, skb, req, &rt->u.dst); 281 ret = get_cookie_sock(sk, skb, req, &rt->u.dst);
282out: return ret; 282out: return ret;
diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
index fabf69a9108c..0aa304711a96 100644
--- a/net/ipv4/sysctl_net_ipv4.c
+++ b/net/ipv4/sysctl_net_ipv4.c
@@ -24,7 +24,7 @@ extern int sysctl_ip_nonlocal_bind;
24 24
25#ifdef CONFIG_SYSCTL 25#ifdef CONFIG_SYSCTL
26static int zero; 26static int zero;
27static int tcp_retr1_max = 255; 27static int tcp_retr1_max = 255;
28static int ip_local_port_range_min[] = { 1, 1 }; 28static int ip_local_port_range_min[] = { 1, 1 };
29static int ip_local_port_range_max[] = { 65535, 65535 }; 29static int ip_local_port_range_max[] = { 65535, 65535 };
30#endif 30#endif
@@ -187,7 +187,7 @@ static int strategy_allowed_congestion_control(ctl_table *table, int __user *nam
187} 187}
188 188
189ctl_table ipv4_table[] = { 189ctl_table ipv4_table[] = {
190 { 190 {
191 .ctl_name = NET_IPV4_TCP_TIMESTAMPS, 191 .ctl_name = NET_IPV4_TCP_TIMESTAMPS,
192 .procname = "tcp_timestamps", 192 .procname = "tcp_timestamps",
193 .data = &sysctl_tcp_timestamps, 193 .data = &sysctl_tcp_timestamps,
@@ -195,7 +195,7 @@ ctl_table ipv4_table[] = {
195 .mode = 0644, 195 .mode = 0644,
196 .proc_handler = &proc_dointvec 196 .proc_handler = &proc_dointvec
197 }, 197 },
198 { 198 {
199 .ctl_name = NET_IPV4_TCP_WINDOW_SCALING, 199 .ctl_name = NET_IPV4_TCP_WINDOW_SCALING,
200 .procname = "tcp_window_scaling", 200 .procname = "tcp_window_scaling",
201 .data = &sysctl_tcp_window_scaling, 201 .data = &sysctl_tcp_window_scaling,
@@ -203,7 +203,7 @@ ctl_table ipv4_table[] = {
203 .mode = 0644, 203 .mode = 0644,
204 .proc_handler = &proc_dointvec 204 .proc_handler = &proc_dointvec
205 }, 205 },
206 { 206 {
207 .ctl_name = NET_IPV4_TCP_SACK, 207 .ctl_name = NET_IPV4_TCP_SACK,
208 .procname = "tcp_sack", 208 .procname = "tcp_sack",
209 .data = &sysctl_tcp_sack, 209 .data = &sysctl_tcp_sack,
@@ -211,7 +211,7 @@ ctl_table ipv4_table[] = {
211 .mode = 0644, 211 .mode = 0644,
212 .proc_handler = &proc_dointvec 212 .proc_handler = &proc_dointvec
213 }, 213 },
214 { 214 {
215 .ctl_name = NET_IPV4_TCP_RETRANS_COLLAPSE, 215 .ctl_name = NET_IPV4_TCP_RETRANS_COLLAPSE,
216 .procname = "tcp_retrans_collapse", 216 .procname = "tcp_retrans_collapse",
217 .data = &sysctl_tcp_retrans_collapse, 217 .data = &sysctl_tcp_retrans_collapse,
@@ -219,7 +219,7 @@ ctl_table ipv4_table[] = {
219 .mode = 0644, 219 .mode = 0644,
220 .proc_handler = &proc_dointvec 220 .proc_handler = &proc_dointvec
221 }, 221 },
222 { 222 {
223 .ctl_name = NET_IPV4_FORWARD, 223 .ctl_name = NET_IPV4_FORWARD,
224 .procname = "ip_forward", 224 .procname = "ip_forward",
225 .data = &ipv4_devconf.forwarding, 225 .data = &ipv4_devconf.forwarding,
@@ -228,16 +228,16 @@ ctl_table ipv4_table[] = {
228 .proc_handler = &ipv4_sysctl_forward, 228 .proc_handler = &ipv4_sysctl_forward,
229 .strategy = &ipv4_sysctl_forward_strategy 229 .strategy = &ipv4_sysctl_forward_strategy
230 }, 230 },
231 { 231 {
232 .ctl_name = NET_IPV4_DEFAULT_TTL, 232 .ctl_name = NET_IPV4_DEFAULT_TTL,
233 .procname = "ip_default_ttl", 233 .procname = "ip_default_ttl",
234 .data = &sysctl_ip_default_ttl, 234 .data = &sysctl_ip_default_ttl,
235 .maxlen = sizeof(int), 235 .maxlen = sizeof(int),
236 .mode = 0644, 236 .mode = 0644,
237 .proc_handler = &ipv4_doint_and_flush, 237 .proc_handler = &ipv4_doint_and_flush,
238 .strategy = &ipv4_doint_and_flush_strategy, 238 .strategy = &ipv4_doint_and_flush_strategy,
239 }, 239 },
240 { 240 {
241 .ctl_name = NET_IPV4_NO_PMTU_DISC, 241 .ctl_name = NET_IPV4_NO_PMTU_DISC,
242 .procname = "ip_no_pmtu_disc", 242 .procname = "ip_no_pmtu_disc",
243 .data = &ipv4_config.no_pmtu_disc, 243 .data = &ipv4_config.no_pmtu_disc,
@@ -728,7 +728,7 @@ ctl_table ipv4_table[] = {
728 .mode = 0644, 728 .mode = 0644,
729 .proc_handler = &proc_dointvec, 729 .proc_handler = &proc_dointvec,
730 }, 730 },
731 { 731 {
732 .ctl_name = NET_IPV4_TCP_WORKAROUND_SIGNED_WINDOWS, 732 .ctl_name = NET_IPV4_TCP_WORKAROUND_SIGNED_WINDOWS,
733 .procname = "tcp_workaround_signed_windows", 733 .procname = "tcp_workaround_signed_windows",
734 .data = &sysctl_tcp_workaround_signed_windows, 734 .data = &sysctl_tcp_workaround_signed_windows,
diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
index b67e0dd743be..ac6516c642a1 100644
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ -475,7 +475,7 @@ static inline void skb_entail(struct sock *sk, struct tcp_sock *tp,
475 if (!sk->sk_send_head) 475 if (!sk->sk_send_head)
476 sk->sk_send_head = skb; 476 sk->sk_send_head = skb;
477 if (tp->nonagle & TCP_NAGLE_PUSH) 477 if (tp->nonagle & TCP_NAGLE_PUSH)
478 tp->nonagle &= ~TCP_NAGLE_PUSH; 478 tp->nonagle &= ~TCP_NAGLE_PUSH;
479} 479}
480 480
481static inline void tcp_mark_urg(struct tcp_sock *tp, int flags, 481static inline void tcp_mark_urg(struct tcp_sock *tp, int flags,
@@ -557,7 +557,7 @@ new_segment:
557 } 557 }
558 if (!sk_stream_wmem_schedule(sk, copy)) 558 if (!sk_stream_wmem_schedule(sk, copy))
559 goto wait_for_memory; 559 goto wait_for_memory;
560 560
561 if (can_coalesce) { 561 if (can_coalesce) {
562 skb_shinfo(skb)->frags[i - 1].size += copy; 562 skb_shinfo(skb)->frags[i - 1].size += copy;
563 } else { 563 } else {
@@ -1439,12 +1439,12 @@ skip_copy:
1439 dma_async_memcpy_issue_pending(tp->ucopy.dma_chan); 1439 dma_async_memcpy_issue_pending(tp->ucopy.dma_chan);
1440 1440
1441 while (dma_async_memcpy_complete(tp->ucopy.dma_chan, 1441 while (dma_async_memcpy_complete(tp->ucopy.dma_chan,
1442 tp->ucopy.dma_cookie, &done, 1442 tp->ucopy.dma_cookie, &done,
1443 &used) == DMA_IN_PROGRESS) { 1443 &used) == DMA_IN_PROGRESS) {
1444 /* do partial cleanup of sk_async_wait_queue */ 1444 /* do partial cleanup of sk_async_wait_queue */
1445 while ((skb = skb_peek(&sk->sk_async_wait_queue)) && 1445 while ((skb = skb_peek(&sk->sk_async_wait_queue)) &&
1446 (dma_async_is_complete(skb->dma_cookie, done, 1446 (dma_async_is_complete(skb->dma_cookie, done,
1447 used) == DMA_SUCCESS)) { 1447 used) == DMA_SUCCESS)) {
1448 __skb_dequeue(&sk->sk_async_wait_queue); 1448 __skb_dequeue(&sk->sk_async_wait_queue);
1449 kfree_skb(skb); 1449 kfree_skb(skb);
1450 } 1450 }
@@ -2006,7 +2006,7 @@ void tcp_get_info(struct sock *sk, struct tcp_info *info)
2006 info->tcpi_options |= TCPI_OPT_WSCALE; 2006 info->tcpi_options |= TCPI_OPT_WSCALE;
2007 info->tcpi_snd_wscale = tp->rx_opt.snd_wscale; 2007 info->tcpi_snd_wscale = tp->rx_opt.snd_wscale;
2008 info->tcpi_rcv_wscale = tp->rx_opt.rcv_wscale; 2008 info->tcpi_rcv_wscale = tp->rx_opt.rcv_wscale;
2009 } 2009 }
2010 2010
2011 if (tp->ecn_flags&TCP_ECN_OK) 2011 if (tp->ecn_flags&TCP_ECN_OK)
2012 info->tcpi_options |= TCPI_OPT_ECN; 2012 info->tcpi_options |= TCPI_OPT_ECN;
@@ -2415,10 +2415,11 @@ void __init tcp_init(void)
2415 &tcp_hashinfo.ehash_size, 2415 &tcp_hashinfo.ehash_size,
2416 NULL, 2416 NULL,
2417 0); 2417 0);
2418 tcp_hashinfo.ehash_size = (1 << tcp_hashinfo.ehash_size) >> 1; 2418 tcp_hashinfo.ehash_size = 1 << tcp_hashinfo.ehash_size;
2419 for (i = 0; i < (tcp_hashinfo.ehash_size << 1); i++) { 2419 for (i = 0; i < tcp_hashinfo.ehash_size; i++) {
2420 rwlock_init(&tcp_hashinfo.ehash[i].lock); 2420 rwlock_init(&tcp_hashinfo.ehash[i].lock);
2421 INIT_HLIST_HEAD(&tcp_hashinfo.ehash[i].chain); 2421 INIT_HLIST_HEAD(&tcp_hashinfo.ehash[i].chain);
2422 INIT_HLIST_HEAD(&tcp_hashinfo.ehash[i].twchain);
2422 } 2423 }
2423 2424
2424 tcp_hashinfo.bhash = 2425 tcp_hashinfo.bhash =
@@ -2475,7 +2476,7 @@ void __init tcp_init(void)
2475 2476
2476 printk(KERN_INFO "TCP: Hash tables configured " 2477 printk(KERN_INFO "TCP: Hash tables configured "
2477 "(established %d bind %d)\n", 2478 "(established %d bind %d)\n",
2478 tcp_hashinfo.ehash_size << 1, tcp_hashinfo.bhash_size); 2479 tcp_hashinfo.ehash_size, tcp_hashinfo.bhash_size);
2479 2480
2480 tcp_register_congestion_control(&tcp_reno); 2481 tcp_register_congestion_control(&tcp_reno);
2481} 2482}
diff --git a/net/ipv4/tcp_cong.c b/net/ipv4/tcp_cong.c
index 5ca7723d0798..c1b34f1edb32 100644
--- a/net/ipv4/tcp_cong.c
+++ b/net/ipv4/tcp_cong.c
@@ -313,28 +313,28 @@ void tcp_reno_cong_avoid(struct sock *sk, u32 ack, u32 rtt, u32 in_flight,
313 return; 313 return;
314 314
315 /* In "safe" area, increase. */ 315 /* In "safe" area, increase. */
316 if (tp->snd_cwnd <= tp->snd_ssthresh) 316 if (tp->snd_cwnd <= tp->snd_ssthresh)
317 tcp_slow_start(tp); 317 tcp_slow_start(tp);
318 318
319 /* In dangerous area, increase slowly. */ 319 /* In dangerous area, increase slowly. */
320 else if (sysctl_tcp_abc) { 320 else if (sysctl_tcp_abc) {
321 /* RFC3465: Appropriate Byte Count 321 /* RFC3465: Appropriate Byte Count
322 * increase once for each full cwnd acked 322 * increase once for each full cwnd acked
323 */ 323 */
324 if (tp->bytes_acked >= tp->snd_cwnd*tp->mss_cache) { 324 if (tp->bytes_acked >= tp->snd_cwnd*tp->mss_cache) {
325 tp->bytes_acked -= tp->snd_cwnd*tp->mss_cache; 325 tp->bytes_acked -= tp->snd_cwnd*tp->mss_cache;
326 if (tp->snd_cwnd < tp->snd_cwnd_clamp) 326 if (tp->snd_cwnd < tp->snd_cwnd_clamp)
327 tp->snd_cwnd++; 327 tp->snd_cwnd++;
328 } 328 }
329 } else { 329 } else {
330 /* In theory this is tp->snd_cwnd += 1 / tp->snd_cwnd */ 330 /* In theory this is tp->snd_cwnd += 1 / tp->snd_cwnd */
331 if (tp->snd_cwnd_cnt >= tp->snd_cwnd) { 331 if (tp->snd_cwnd_cnt >= tp->snd_cwnd) {
332 if (tp->snd_cwnd < tp->snd_cwnd_clamp) 332 if (tp->snd_cwnd < tp->snd_cwnd_clamp)
333 tp->snd_cwnd++; 333 tp->snd_cwnd++;
334 tp->snd_cwnd_cnt = 0; 334 tp->snd_cwnd_cnt = 0;
335 } else 335 } else
336 tp->snd_cwnd_cnt++; 336 tp->snd_cwnd_cnt++;
337 } 337 }
338} 338}
339EXPORT_SYMBOL_GPL(tcp_reno_cong_avoid); 339EXPORT_SYMBOL_GPL(tcp_reno_cong_avoid);
340 340
diff --git a/net/ipv4/tcp_cubic.c b/net/ipv4/tcp_cubic.c
index 6ad184802266..9a582fb4ef9f 100644
--- a/net/ipv4/tcp_cubic.c
+++ b/net/ipv4/tcp_cubic.c
@@ -26,16 +26,16 @@
26 */ 26 */
27#define BICTCP_HZ 10 /* BIC HZ 2^10 = 1024 */ 27#define BICTCP_HZ 10 /* BIC HZ 2^10 = 1024 */
28 28
29static int fast_convergence = 1; 29static int fast_convergence __read_mostly = 1;
30static int max_increment = 16; 30static int max_increment __read_mostly = 16;
31static int beta = 819; /* = 819/1024 (BICTCP_BETA_SCALE) */ 31static int beta __read_mostly = 819; /* = 819/1024 (BICTCP_BETA_SCALE) */
32static int initial_ssthresh = 100; 32static int initial_ssthresh __read_mostly = 100;
33static int bic_scale = 41; 33static int bic_scale __read_mostly = 41;
34static int tcp_friendliness = 1; 34static int tcp_friendliness __read_mostly = 1;
35 35
36static u32 cube_rtt_scale; 36static u32 cube_rtt_scale __read_mostly;
37static u32 beta_scale; 37static u32 beta_scale __read_mostly;
38static u64 cube_factor; 38static u64 cube_factor __read_mostly;
39 39
40/* Note parameters that are used for precomputing scale factors are read-only */ 40/* Note parameters that are used for precomputing scale factors are read-only */
41module_param(fast_convergence, int, 0644); 41module_param(fast_convergence, int, 0644);
@@ -175,42 +175,42 @@ static inline void bictcp_update(struct bictcp *ca, u32 cwnd)
175 } 175 }
176 } 176 }
177 177
178 /* cubic function - calc*/ 178 /* cubic function - calc*/
179 /* calculate c * time^3 / rtt, 179 /* calculate c * time^3 / rtt,
180 * while considering overflow in calculation of time^3 180 * while considering overflow in calculation of time^3
181 * (so time^3 is done by using 64 bit) 181 * (so time^3 is done by using 64 bit)
182 * and without the support of division of 64bit numbers 182 * and without the support of division of 64bit numbers
183 * (so all divisions are done by using 32 bit) 183 * (so all divisions are done by using 32 bit)
184 * also NOTE the unit of those veriables 184 * also NOTE the unit of those veriables
185 * time = (t - K) / 2^bictcp_HZ 185 * time = (t - K) / 2^bictcp_HZ
186 * c = bic_scale >> 10 186 * c = bic_scale >> 10
187 * rtt = (srtt >> 3) / HZ 187 * rtt = (srtt >> 3) / HZ
188 * !!! The following code does not have overflow problems, 188 * !!! The following code does not have overflow problems,
189 * if the cwnd < 1 million packets !!! 189 * if the cwnd < 1 million packets !!!
190 */ 190 */
191 191
192 /* change the unit from HZ to bictcp_HZ */ 192 /* change the unit from HZ to bictcp_HZ */
193 t = ((tcp_time_stamp + (ca->delay_min>>3) - ca->epoch_start) 193 t = ((tcp_time_stamp + (ca->delay_min>>3) - ca->epoch_start)
194 << BICTCP_HZ) / HZ; 194 << BICTCP_HZ) / HZ;
195 195
196 if (t < ca->bic_K) /* t - K */ 196 if (t < ca->bic_K) /* t - K */
197 offs = ca->bic_K - t; 197 offs = ca->bic_K - t;
198 else 198 else
199 offs = t - ca->bic_K; 199 offs = t - ca->bic_K;
200 200
201 /* c/rtt * (t-K)^3 */ 201 /* c/rtt * (t-K)^3 */
202 delta = (cube_rtt_scale * offs * offs * offs) >> (10+3*BICTCP_HZ); 202 delta = (cube_rtt_scale * offs * offs * offs) >> (10+3*BICTCP_HZ);
203 if (t < ca->bic_K) /* below origin*/ 203 if (t < ca->bic_K) /* below origin*/
204 bic_target = ca->bic_origin_point - delta; 204 bic_target = ca->bic_origin_point - delta;
205 else /* above origin*/ 205 else /* above origin*/
206 bic_target = ca->bic_origin_point + delta; 206 bic_target = ca->bic_origin_point + delta;
207 207
208 /* cubic function - calc bictcp_cnt*/ 208 /* cubic function - calc bictcp_cnt*/
209 if (bic_target > cwnd) { 209 if (bic_target > cwnd) {
210 ca->cnt = cwnd / (bic_target - cwnd); 210 ca->cnt = cwnd / (bic_target - cwnd);
211 } else { 211 } else {
212 ca->cnt = 100 * cwnd; /* very small increment*/ 212 ca->cnt = 100 * cwnd; /* very small increment*/
213 } 213 }
214 214
215 if (ca->delay_min > 0) { 215 if (ca->delay_min > 0) {
216 /* max increment = Smax * rtt / 0.1 */ 216 /* max increment = Smax * rtt / 0.1 */
@@ -219,7 +219,7 @@ static inline void bictcp_update(struct bictcp *ca, u32 cwnd)
219 ca->cnt = min_cnt; 219 ca->cnt = min_cnt;
220 } 220 }
221 221
222 /* slow start and low utilization */ 222 /* slow start and low utilization */
223 if (ca->loss_cwnd == 0) /* could be aggressive in slow start */ 223 if (ca->loss_cwnd == 0) /* could be aggressive in slow start */
224 ca->cnt = 50; 224 ca->cnt = 50;
225 225
@@ -227,9 +227,9 @@ static inline void bictcp_update(struct bictcp *ca, u32 cwnd)
227 if (tcp_friendliness) { 227 if (tcp_friendliness) {
228 u32 scale = beta_scale; 228 u32 scale = beta_scale;
229 delta = (cwnd * scale) >> 3; 229 delta = (cwnd * scale) >> 3;
230 while (ca->ack_cnt > delta) { /* update tcp cwnd */ 230 while (ca->ack_cnt > delta) { /* update tcp cwnd */
231 ca->ack_cnt -= delta; 231 ca->ack_cnt -= delta;
232 ca->tcp_cwnd++; 232 ca->tcp_cwnd++;
233 } 233 }
234 234
235 if (ca->tcp_cwnd > cwnd){ /* if bic is slower than tcp */ 235 if (ca->tcp_cwnd > cwnd){ /* if bic is slower than tcp */
@@ -238,7 +238,7 @@ static inline void bictcp_update(struct bictcp *ca, u32 cwnd)
238 if (ca->cnt > max_cnt) 238 if (ca->cnt > max_cnt)
239 ca->cnt = max_cnt; 239 ca->cnt = max_cnt;
240 } 240 }
241 } 241 }
242 242
243 ca->cnt = (ca->cnt << ACK_RATIO_SHIFT) / ca->delayed_ack; 243 ca->cnt = (ca->cnt << ACK_RATIO_SHIFT) / ca->delayed_ack;
244 if (ca->cnt == 0) /* cannot be zero */ 244 if (ca->cnt == 0) /* cannot be zero */
diff --git a/net/ipv4/tcp_highspeed.c b/net/ipv4/tcp_highspeed.c
index c4fc811bf377..a291097fcc0a 100644
--- a/net/ipv4/tcp_highspeed.c
+++ b/net/ipv4/tcp_highspeed.c
@@ -14,8 +14,8 @@
14 * with fixed-point MD scaled <<8. 14 * with fixed-point MD scaled <<8.
15 */ 15 */
16static const struct hstcp_aimd_val { 16static const struct hstcp_aimd_val {
17 unsigned int cwnd; 17 unsigned int cwnd;
18 unsigned int md; 18 unsigned int md;
19} hstcp_aimd_vals[] = { 19} hstcp_aimd_vals[] = {
20 { 38, 128, /* 0.50 */ }, 20 { 38, 128, /* 0.50 */ },
21 { 118, 112, /* 0.44 */ }, 21 { 118, 112, /* 0.44 */ },
diff --git a/net/ipv4/tcp_htcp.c b/net/ipv4/tcp_htcp.c
index 753987a1048f..1020eb48d8d1 100644
--- a/net/ipv4/tcp_htcp.c
+++ b/net/ipv4/tcp_htcp.c
@@ -10,22 +10,23 @@
10#include <linux/module.h> 10#include <linux/module.h>
11#include <net/tcp.h> 11#include <net/tcp.h>
12 12
13#define ALPHA_BASE (1<<7) /* 1.0 with shift << 7 */ 13#define ALPHA_BASE (1<<7) /* 1.0 with shift << 7 */
14#define BETA_MIN (1<<6) /* 0.5 with shift << 7 */ 14#define BETA_MIN (1<<6) /* 0.5 with shift << 7 */
15#define BETA_MAX 102 /* 0.8 with shift << 7 */ 15#define BETA_MAX 102 /* 0.8 with shift << 7 */
16 16
17static int use_rtt_scaling = 1; 17static int use_rtt_scaling __read_mostly = 1;
18module_param(use_rtt_scaling, int, 0644); 18module_param(use_rtt_scaling, int, 0644);
19MODULE_PARM_DESC(use_rtt_scaling, "turn on/off RTT scaling"); 19MODULE_PARM_DESC(use_rtt_scaling, "turn on/off RTT scaling");
20 20
21static int use_bandwidth_switch = 1; 21static int use_bandwidth_switch __read_mostly = 1;
22module_param(use_bandwidth_switch, int, 0644); 22module_param(use_bandwidth_switch, int, 0644);
23MODULE_PARM_DESC(use_bandwidth_switch, "turn on/off bandwidth switcher"); 23MODULE_PARM_DESC(use_bandwidth_switch, "turn on/off bandwidth switcher");
24 24
25struct htcp { 25struct htcp {
26 u32 alpha; /* Fixed point arith, << 7 */ 26 u32 alpha; /* Fixed point arith, << 7 */
27 u8 beta; /* Fixed point arith, << 7 */ 27 u8 beta; /* Fixed point arith, << 7 */
28 u8 modeswitch; /* Delay modeswitch until we had at least one congestion event */ 28 u8 modeswitch; /* Delay modeswitch
29 until we had at least one congestion event */
29 u16 pkts_acked; 30 u16 pkts_acked;
30 u32 packetcount; 31 u32 packetcount;
31 u32 minRTT; 32 u32 minRTT;
@@ -44,14 +45,14 @@ struct htcp {
44 u32 lasttime; 45 u32 lasttime;
45}; 46};
46 47
47static inline u32 htcp_cong_time(struct htcp *ca) 48static inline u32 htcp_cong_time(const struct htcp *ca)
48{ 49{
49 return jiffies - ca->last_cong; 50 return jiffies - ca->last_cong;
50} 51}
51 52
52static inline u32 htcp_ccount(struct htcp *ca) 53static inline u32 htcp_ccount(const struct htcp *ca)
53{ 54{
54 return htcp_cong_time(ca)/ca->minRTT; 55 return htcp_cong_time(ca) / ca->minRTT;
55} 56}
56 57
57static inline void htcp_reset(struct htcp *ca) 58static inline void htcp_reset(struct htcp *ca)
@@ -67,10 +68,12 @@ static u32 htcp_cwnd_undo(struct sock *sk)
67{ 68{
68 const struct tcp_sock *tp = tcp_sk(sk); 69 const struct tcp_sock *tp = tcp_sk(sk);
69 struct htcp *ca = inet_csk_ca(sk); 70 struct htcp *ca = inet_csk_ca(sk);
71
70 ca->last_cong = ca->undo_last_cong; 72 ca->last_cong = ca->undo_last_cong;
71 ca->maxRTT = ca->undo_maxRTT; 73 ca->maxRTT = ca->undo_maxRTT;
72 ca->old_maxB = ca->undo_old_maxB; 74 ca->old_maxB = ca->undo_old_maxB;
73 return max(tp->snd_cwnd, (tp->snd_ssthresh<<7)/ca->beta); 75
76 return max(tp->snd_cwnd, (tp->snd_ssthresh << 7) / ca->beta);
74} 77}
75 78
76static inline void measure_rtt(struct sock *sk) 79static inline void measure_rtt(struct sock *sk)
@@ -78,17 +81,19 @@ static inline void measure_rtt(struct sock *sk)
78 const struct inet_connection_sock *icsk = inet_csk(sk); 81 const struct inet_connection_sock *icsk = inet_csk(sk);
79 const struct tcp_sock *tp = tcp_sk(sk); 82 const struct tcp_sock *tp = tcp_sk(sk);
80 struct htcp *ca = inet_csk_ca(sk); 83 struct htcp *ca = inet_csk_ca(sk);
81 u32 srtt = tp->srtt>>3; 84 u32 srtt = tp->srtt >> 3;
82 85
83 /* keep track of minimum RTT seen so far, minRTT is zero at first */ 86 /* keep track of minimum RTT seen so far, minRTT is zero at first */
84 if (ca->minRTT > srtt || !ca->minRTT) 87 if (ca->minRTT > srtt || !ca->minRTT)
85 ca->minRTT = srtt; 88 ca->minRTT = srtt;
86 89
87 /* max RTT */ 90 /* max RTT */
88 if (icsk->icsk_ca_state == TCP_CA_Open && tp->snd_ssthresh < 0xFFFF && htcp_ccount(ca) > 3) { 91 if (icsk->icsk_ca_state == TCP_CA_Open
92 && tp->snd_ssthresh < 0xFFFF && htcp_ccount(ca) > 3) {
89 if (ca->maxRTT < ca->minRTT) 93 if (ca->maxRTT < ca->minRTT)
90 ca->maxRTT = ca->minRTT; 94 ca->maxRTT = ca->minRTT;
91 if (ca->maxRTT < srtt && srtt <= ca->maxRTT+msecs_to_jiffies(20)) 95 if (ca->maxRTT < srtt
96 && srtt <= ca->maxRTT + msecs_to_jiffies(20))
92 ca->maxRTT = srtt; 97 ca->maxRTT = srtt;
93 } 98 }
94} 99}
@@ -116,15 +121,16 @@ static void measure_achieved_throughput(struct sock *sk, u32 pkts_acked)
116 121
117 ca->packetcount += pkts_acked; 122 ca->packetcount += pkts_acked;
118 123
119 if (ca->packetcount >= tp->snd_cwnd - (ca->alpha>>7? : 1) 124 if (ca->packetcount >= tp->snd_cwnd - (ca->alpha >> 7 ? : 1)
120 && now - ca->lasttime >= ca->minRTT 125 && now - ca->lasttime >= ca->minRTT
121 && ca->minRTT > 0) { 126 && ca->minRTT > 0) {
122 __u32 cur_Bi = ca->packetcount*HZ/(now - ca->lasttime); 127 __u32 cur_Bi = ca->packetcount * HZ / (now - ca->lasttime);
128
123 if (htcp_ccount(ca) <= 3) { 129 if (htcp_ccount(ca) <= 3) {
124 /* just after backoff */ 130 /* just after backoff */
125 ca->minB = ca->maxB = ca->Bi = cur_Bi; 131 ca->minB = ca->maxB = ca->Bi = cur_Bi;
126 } else { 132 } else {
127 ca->Bi = (3*ca->Bi + cur_Bi)/4; 133 ca->Bi = (3 * ca->Bi + cur_Bi) / 4;
128 if (ca->Bi > ca->maxB) 134 if (ca->Bi > ca->maxB)
129 ca->maxB = ca->Bi; 135 ca->maxB = ca->Bi;
130 if (ca->minB > ca->maxB) 136 if (ca->minB > ca->maxB)
@@ -142,7 +148,7 @@ static inline void htcp_beta_update(struct htcp *ca, u32 minRTT, u32 maxRTT)
142 u32 old_maxB = ca->old_maxB; 148 u32 old_maxB = ca->old_maxB;
143 ca->old_maxB = ca->maxB; 149 ca->old_maxB = ca->maxB;
144 150
145 if (!between(5*maxB, 4*old_maxB, 6*old_maxB)) { 151 if (!between(5 * maxB, 4 * old_maxB, 6 * old_maxB)) {
146 ca->beta = BETA_MIN; 152 ca->beta = BETA_MIN;
147 ca->modeswitch = 0; 153 ca->modeswitch = 0;
148 return; 154 return;
@@ -150,7 +156,7 @@ static inline void htcp_beta_update(struct htcp *ca, u32 minRTT, u32 maxRTT)
150 } 156 }
151 157
152 if (ca->modeswitch && minRTT > msecs_to_jiffies(10) && maxRTT) { 158 if (ca->modeswitch && minRTT > msecs_to_jiffies(10) && maxRTT) {
153 ca->beta = (minRTT<<7)/maxRTT; 159 ca->beta = (minRTT << 7) / maxRTT;
154 if (ca->beta < BETA_MIN) 160 if (ca->beta < BETA_MIN)
155 ca->beta = BETA_MIN; 161 ca->beta = BETA_MIN;
156 else if (ca->beta > BETA_MAX) 162 else if (ca->beta > BETA_MAX)
@@ -169,23 +175,26 @@ static inline void htcp_alpha_update(struct htcp *ca)
169 175
170 if (diff > HZ) { 176 if (diff > HZ) {
171 diff -= HZ; 177 diff -= HZ;
172 factor = 1+ ( 10*diff + ((diff/2)*(diff/2)/HZ) )/HZ; 178 factor = 1 + (10 * diff + ((diff / 2) * (diff / 2) / HZ)) / HZ;
173 } 179 }
174 180
175 if (use_rtt_scaling && minRTT) { 181 if (use_rtt_scaling && minRTT) {
176 u32 scale = (HZ<<3)/(10*minRTT); 182 u32 scale = (HZ << 3) / (10 * minRTT);
177 scale = min(max(scale, 1U<<2), 10U<<3); /* clamping ratio to interval [0.5,10]<<3 */ 183
178 factor = (factor<<3)/scale; 184 /* clamping ratio to interval [0.5,10]<<3 */
185 scale = min(max(scale, 1U << 2), 10U << 3);
186 factor = (factor << 3) / scale;
179 if (!factor) 187 if (!factor)
180 factor = 1; 188 factor = 1;
181 } 189 }
182 190
183 ca->alpha = 2*factor*((1<<7)-ca->beta); 191 ca->alpha = 2 * factor * ((1 << 7) - ca->beta);
184 if (!ca->alpha) 192 if (!ca->alpha)
185 ca->alpha = ALPHA_BASE; 193 ca->alpha = ALPHA_BASE;
186} 194}
187 195
188/* After we have the rtt data to calculate beta, we'd still prefer to wait one 196/*
197 * After we have the rtt data to calculate beta, we'd still prefer to wait one
189 * rtt before we adjust our beta to ensure we are working from a consistent 198 * rtt before we adjust our beta to ensure we are working from a consistent
190 * data. 199 * data.
191 * 200 *
@@ -202,15 +211,16 @@ static void htcp_param_update(struct sock *sk)
202 htcp_beta_update(ca, minRTT, maxRTT); 211 htcp_beta_update(ca, minRTT, maxRTT);
203 htcp_alpha_update(ca); 212 htcp_alpha_update(ca);
204 213
205 /* add slowly fading memory for maxRTT to accommodate routing changes etc */ 214 /* add slowly fading memory for maxRTT to accommodate routing changes */
206 if (minRTT > 0 && maxRTT > minRTT) 215 if (minRTT > 0 && maxRTT > minRTT)
207 ca->maxRTT = minRTT + ((maxRTT-minRTT)*95)/100; 216 ca->maxRTT = minRTT + ((maxRTT - minRTT) * 95) / 100;
208} 217}
209 218
210static u32 htcp_recalc_ssthresh(struct sock *sk) 219static u32 htcp_recalc_ssthresh(struct sock *sk)
211{ 220{
212 const struct tcp_sock *tp = tcp_sk(sk); 221 const struct tcp_sock *tp = tcp_sk(sk);
213 const struct htcp *ca = inet_csk_ca(sk); 222 const struct htcp *ca = inet_csk_ca(sk);
223
214 htcp_param_update(sk); 224 htcp_param_update(sk);
215 return max((tp->snd_cwnd * ca->beta) >> 7, 2U); 225 return max((tp->snd_cwnd * ca->beta) >> 7, 2U);
216} 226}
@@ -224,10 +234,9 @@ static void htcp_cong_avoid(struct sock *sk, u32 ack, u32 rtt,
224 if (!tcp_is_cwnd_limited(sk, in_flight)) 234 if (!tcp_is_cwnd_limited(sk, in_flight))
225 return; 235 return;
226 236
227 if (tp->snd_cwnd <= tp->snd_ssthresh) 237 if (tp->snd_cwnd <= tp->snd_ssthresh)
228 tcp_slow_start(tp); 238 tcp_slow_start(tp);
229 else { 239 else {
230
231 measure_rtt(sk); 240 measure_rtt(sk);
232 241
233 /* In dangerous area, increase slowly. 242 /* In dangerous area, increase slowly.
diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
index c26076fb890e..1a14191687ac 100644
--- a/net/ipv4/tcp_input.c
+++ b/net/ipv4/tcp_input.c
@@ -50,9 +50,9 @@
50 * Andi Kleen: Make sure we never ack data there is not 50 * Andi Kleen: Make sure we never ack data there is not
51 * enough room for. Also make this condition 51 * enough room for. Also make this condition
52 * a fatal error if it might still happen. 52 * a fatal error if it might still happen.
53 * Andi Kleen: Add tcp_measure_rcv_mss to make 53 * Andi Kleen: Add tcp_measure_rcv_mss to make
54 * connections with MSS<min(MTU,ann. MSS) 54 * connections with MSS<min(MTU,ann. MSS)
55 * work without delayed acks. 55 * work without delayed acks.
56 * Andi Kleen: Process packets with PSH set in the 56 * Andi Kleen: Process packets with PSH set in the
57 * fast path. 57 * fast path.
58 * J Hadi Salim: ECN support 58 * J Hadi Salim: ECN support
@@ -112,17 +112,17 @@ int sysctl_tcp_abc __read_mostly;
112 112
113#define TCP_REMNANT (TCP_FLAG_FIN|TCP_FLAG_URG|TCP_FLAG_SYN|TCP_FLAG_PSH) 113#define TCP_REMNANT (TCP_FLAG_FIN|TCP_FLAG_URG|TCP_FLAG_SYN|TCP_FLAG_PSH)
114 114
115/* Adapt the MSS value used to make delayed ack decision to the 115/* Adapt the MSS value used to make delayed ack decision to the
116 * real world. 116 * real world.
117 */ 117 */
118static void tcp_measure_rcv_mss(struct sock *sk, 118static void tcp_measure_rcv_mss(struct sock *sk,
119 const struct sk_buff *skb) 119 const struct sk_buff *skb)
120{ 120{
121 struct inet_connection_sock *icsk = inet_csk(sk); 121 struct inet_connection_sock *icsk = inet_csk(sk);
122 const unsigned int lss = icsk->icsk_ack.last_seg_size; 122 const unsigned int lss = icsk->icsk_ack.last_seg_size;
123 unsigned int len; 123 unsigned int len;
124 124
125 icsk->icsk_ack.last_seg_size = 0; 125 icsk->icsk_ack.last_seg_size = 0;
126 126
127 /* skb->len may jitter because of SACKs, even if peer 127 /* skb->len may jitter because of SACKs, even if peer
128 * sends good full-sized frames. 128 * sends good full-sized frames.
@@ -440,15 +440,15 @@ void tcp_rcv_space_adjust(struct sock *sk)
440 struct tcp_sock *tp = tcp_sk(sk); 440 struct tcp_sock *tp = tcp_sk(sk);
441 int time; 441 int time;
442 int space; 442 int space;
443 443
444 if (tp->rcvq_space.time == 0) 444 if (tp->rcvq_space.time == 0)
445 goto new_measure; 445 goto new_measure;
446 446
447 time = tcp_time_stamp - tp->rcvq_space.time; 447 time = tcp_time_stamp - tp->rcvq_space.time;
448 if (time < (tp->rcv_rtt_est.rtt >> 3) || 448 if (time < (tp->rcv_rtt_est.rtt >> 3) ||
449 tp->rcv_rtt_est.rtt == 0) 449 tp->rcv_rtt_est.rtt == 0)
450 return; 450 return;
451 451
452 space = 2 * (tp->copied_seq - tp->rcvq_space.seq); 452 space = 2 * (tp->copied_seq - tp->rcvq_space.seq);
453 453
454 space = max(tp->rcvq_space.space, space); 454 space = max(tp->rcvq_space.space, space);
@@ -483,7 +483,7 @@ void tcp_rcv_space_adjust(struct sock *sk)
483 } 483 }
484 } 484 }
485 } 485 }
486 486
487new_measure: 487new_measure:
488 tp->rcvq_space.seq = tp->copied_seq; 488 tp->rcvq_space.seq = tp->copied_seq;
489 tp->rcvq_space.time = tcp_time_stamp; 489 tp->rcvq_space.time = tcp_time_stamp;
@@ -509,7 +509,7 @@ static void tcp_event_data_recv(struct sock *sk, struct tcp_sock *tp, struct sk_
509 tcp_measure_rcv_mss(sk, skb); 509 tcp_measure_rcv_mss(sk, skb);
510 510
511 tcp_rcv_rtt_measure(tp); 511 tcp_rcv_rtt_measure(tp);
512 512
513 now = tcp_time_stamp; 513 now = tcp_time_stamp;
514 514
515 if (!icsk->icsk_ack.ato) { 515 if (!icsk->icsk_ack.ato) {
@@ -561,7 +561,7 @@ static void tcp_rtt_estimator(struct sock *sk, const __u32 mrtt)
561 /* The following amusing code comes from Jacobson's 561 /* The following amusing code comes from Jacobson's
562 * article in SIGCOMM '88. Note that rtt and mdev 562 * article in SIGCOMM '88. Note that rtt and mdev
563 * are scaled versions of rtt and mean deviation. 563 * are scaled versions of rtt and mean deviation.
564 * This is designed to be as fast as possible 564 * This is designed to be as fast as possible
565 * m stands for "measurement". 565 * m stands for "measurement".
566 * 566 *
567 * On a 1990 paper the rto value is changed to: 567 * On a 1990 paper the rto value is changed to:
@@ -936,28 +936,58 @@ tcp_sacktag_write_queue(struct sock *sk, struct sk_buff *ack_skb, u32 prior_snd_
936 struct tcp_sock *tp = tcp_sk(sk); 936 struct tcp_sock *tp = tcp_sk(sk);
937 unsigned char *ptr = ack_skb->h.raw + TCP_SKB_CB(ack_skb)->sacked; 937 unsigned char *ptr = ack_skb->h.raw + TCP_SKB_CB(ack_skb)->sacked;
938 struct tcp_sack_block_wire *sp = (struct tcp_sack_block_wire *)(ptr+2); 938 struct tcp_sack_block_wire *sp = (struct tcp_sack_block_wire *)(ptr+2);
939 struct sk_buff *cached_skb;
939 int num_sacks = (ptr[1] - TCPOLEN_SACK_BASE)>>3; 940 int num_sacks = (ptr[1] - TCPOLEN_SACK_BASE)>>3;
940 int reord = tp->packets_out; 941 int reord = tp->packets_out;
941 int prior_fackets; 942 int prior_fackets;
942 u32 lost_retrans = 0; 943 u32 lost_retrans = 0;
943 int flag = 0; 944 int flag = 0;
944 int dup_sack = 0; 945 int dup_sack = 0;
946 int cached_fack_count;
945 int i; 947 int i;
948 int first_sack_index;
946 949
947 if (!tp->sacked_out) 950 if (!tp->sacked_out)
948 tp->fackets_out = 0; 951 tp->fackets_out = 0;
949 prior_fackets = tp->fackets_out; 952 prior_fackets = tp->fackets_out;
950 953
954 /* Check for D-SACK. */
955 if (before(ntohl(sp[0].start_seq), TCP_SKB_CB(ack_skb)->ack_seq)) {
956 dup_sack = 1;
957 tp->rx_opt.sack_ok |= 4;
958 NET_INC_STATS_BH(LINUX_MIB_TCPDSACKRECV);
959 } else if (num_sacks > 1 &&
960 !after(ntohl(sp[0].end_seq), ntohl(sp[1].end_seq)) &&
961 !before(ntohl(sp[0].start_seq), ntohl(sp[1].start_seq))) {
962 dup_sack = 1;
963 tp->rx_opt.sack_ok |= 4;
964 NET_INC_STATS_BH(LINUX_MIB_TCPDSACKOFORECV);
965 }
966
967 /* D-SACK for already forgotten data...
968 * Do dumb counting. */
969 if (dup_sack &&
970 !after(ntohl(sp[0].end_seq), prior_snd_una) &&
971 after(ntohl(sp[0].end_seq), tp->undo_marker))
972 tp->undo_retrans--;
973
974 /* Eliminate too old ACKs, but take into
975 * account more or less fresh ones, they can
976 * contain valid SACK info.
977 */
978 if (before(TCP_SKB_CB(ack_skb)->ack_seq, prior_snd_una - tp->max_window))
979 return 0;
980
951 /* SACK fastpath: 981 /* SACK fastpath:
952 * if the only SACK change is the increase of the end_seq of 982 * if the only SACK change is the increase of the end_seq of
953 * the first block then only apply that SACK block 983 * the first block then only apply that SACK block
954 * and use retrans queue hinting otherwise slowpath */ 984 * and use retrans queue hinting otherwise slowpath */
955 flag = 1; 985 flag = 1;
956 for (i = 0; i< num_sacks; i++) { 986 for (i = 0; i < num_sacks; i++) {
957 __u32 start_seq = ntohl(sp[i].start_seq); 987 __be32 start_seq = sp[i].start_seq;
958 __u32 end_seq = ntohl(sp[i].end_seq); 988 __be32 end_seq = sp[i].end_seq;
959 989
960 if (i == 0){ 990 if (i == 0) {
961 if (tp->recv_sack_cache[i].start_seq != start_seq) 991 if (tp->recv_sack_cache[i].start_seq != start_seq)
962 flag = 0; 992 flag = 0;
963 } else { 993 } else {
@@ -967,39 +997,14 @@ tcp_sacktag_write_queue(struct sock *sk, struct sk_buff *ack_skb, u32 prior_snd_
967 } 997 }
968 tp->recv_sack_cache[i].start_seq = start_seq; 998 tp->recv_sack_cache[i].start_seq = start_seq;
969 tp->recv_sack_cache[i].end_seq = end_seq; 999 tp->recv_sack_cache[i].end_seq = end_seq;
970 1000 }
971 /* Check for D-SACK. */ 1001 /* Clear the rest of the cache sack blocks so they won't match mistakenly. */
972 if (i == 0) { 1002 for (; i < ARRAY_SIZE(tp->recv_sack_cache); i++) {
973 u32 ack = TCP_SKB_CB(ack_skb)->ack_seq; 1003 tp->recv_sack_cache[i].start_seq = 0;
974 1004 tp->recv_sack_cache[i].end_seq = 0;
975 if (before(start_seq, ack)) {
976 dup_sack = 1;
977 tp->rx_opt.sack_ok |= 4;
978 NET_INC_STATS_BH(LINUX_MIB_TCPDSACKRECV);
979 } else if (num_sacks > 1 &&
980 !after(end_seq, ntohl(sp[1].end_seq)) &&
981 !before(start_seq, ntohl(sp[1].start_seq))) {
982 dup_sack = 1;
983 tp->rx_opt.sack_ok |= 4;
984 NET_INC_STATS_BH(LINUX_MIB_TCPDSACKOFORECV);
985 }
986
987 /* D-SACK for already forgotten data...
988 * Do dumb counting. */
989 if (dup_sack &&
990 !after(end_seq, prior_snd_una) &&
991 after(end_seq, tp->undo_marker))
992 tp->undo_retrans--;
993
994 /* Eliminate too old ACKs, but take into
995 * account more or less fresh ones, they can
996 * contain valid SACK info.
997 */
998 if (before(ack, prior_snd_una - tp->max_window))
999 return 0;
1000 }
1001 } 1005 }
1002 1006
1007 first_sack_index = 0;
1003 if (flag) 1008 if (flag)
1004 num_sacks = 1; 1009 num_sacks = 1;
1005 else { 1010 else {
@@ -1016,6 +1021,10 @@ tcp_sacktag_write_queue(struct sock *sk, struct sk_buff *ack_skb, u32 prior_snd_
1016 tmp = sp[j]; 1021 tmp = sp[j];
1017 sp[j] = sp[j+1]; 1022 sp[j] = sp[j+1];
1018 sp[j+1] = tmp; 1023 sp[j+1] = tmp;
1024
1025 /* Track where the first SACK block goes to */
1026 if (j == first_sack_index)
1027 first_sack_index = j+1;
1019 } 1028 }
1020 1029
1021 } 1030 }
@@ -1025,20 +1034,22 @@ tcp_sacktag_write_queue(struct sock *sk, struct sk_buff *ack_skb, u32 prior_snd_
1025 /* clear flag as used for different purpose in following code */ 1034 /* clear flag as used for different purpose in following code */
1026 flag = 0; 1035 flag = 0;
1027 1036
1037 /* Use SACK fastpath hint if valid */
1038 cached_skb = tp->fastpath_skb_hint;
1039 cached_fack_count = tp->fastpath_cnt_hint;
1040 if (!cached_skb) {
1041 cached_skb = sk->sk_write_queue.next;
1042 cached_fack_count = 0;
1043 }
1044
1028 for (i=0; i<num_sacks; i++, sp++) { 1045 for (i=0; i<num_sacks; i++, sp++) {
1029 struct sk_buff *skb; 1046 struct sk_buff *skb;
1030 __u32 start_seq = ntohl(sp->start_seq); 1047 __u32 start_seq = ntohl(sp->start_seq);
1031 __u32 end_seq = ntohl(sp->end_seq); 1048 __u32 end_seq = ntohl(sp->end_seq);
1032 int fack_count; 1049 int fack_count;
1033 1050
1034 /* Use SACK fastpath hint if valid */ 1051 skb = cached_skb;
1035 if (tp->fastpath_skb_hint) { 1052 fack_count = cached_fack_count;
1036 skb = tp->fastpath_skb_hint;
1037 fack_count = tp->fastpath_cnt_hint;
1038 } else {
1039 skb = sk->sk_write_queue.next;
1040 fack_count = 0;
1041 }
1042 1053
1043 /* Event "B" in the comment above. */ 1054 /* Event "B" in the comment above. */
1044 if (after(end_seq, tp->high_seq)) 1055 if (after(end_seq, tp->high_seq))
@@ -1048,8 +1059,12 @@ tcp_sacktag_write_queue(struct sock *sk, struct sk_buff *ack_skb, u32 prior_snd_
1048 int in_sack, pcount; 1059 int in_sack, pcount;
1049 u8 sacked; 1060 u8 sacked;
1050 1061
1051 tp->fastpath_skb_hint = skb; 1062 cached_skb = skb;
1052 tp->fastpath_cnt_hint = fack_count; 1063 cached_fack_count = fack_count;
1064 if (i == first_sack_index) {
1065 tp->fastpath_skb_hint = skb;
1066 tp->fastpath_cnt_hint = fack_count;
1067 }
1053 1068
1054 /* The retransmission queue is always in order, so 1069 /* The retransmission queue is always in order, so
1055 * we can short-circuit the walk early. 1070 * we can short-circuit the walk early.
@@ -1234,8 +1249,8 @@ void tcp_enter_frto(struct sock *sk)
1234 tp->frto_counter = 1; 1249 tp->frto_counter = 1;
1235 1250
1236 if (icsk->icsk_ca_state <= TCP_CA_Disorder || 1251 if (icsk->icsk_ca_state <= TCP_CA_Disorder ||
1237 tp->snd_una == tp->high_seq || 1252 tp->snd_una == tp->high_seq ||
1238 (icsk->icsk_ca_state == TCP_CA_Loss && !icsk->icsk_retransmits)) { 1253 (icsk->icsk_ca_state == TCP_CA_Loss && !icsk->icsk_retransmits)) {
1239 tp->prior_ssthresh = tcp_current_ssthresh(sk); 1254 tp->prior_ssthresh = tcp_current_ssthresh(sk);
1240 tp->snd_ssthresh = icsk->icsk_ca_ops->ssthresh(sk); 1255 tp->snd_ssthresh = icsk->icsk_ca_ops->ssthresh(sk);
1241 tcp_ca_event(sk, CA_EVENT_FRTO); 1256 tcp_ca_event(sk, CA_EVENT_FRTO);
@@ -1954,11 +1969,11 @@ tcp_fastretrans_alert(struct sock *sk, u32 prior_snd_una,
1954 * 1. Reno does not count dupacks (sacked_out) automatically. */ 1969 * 1. Reno does not count dupacks (sacked_out) automatically. */
1955 if (!tp->packets_out) 1970 if (!tp->packets_out)
1956 tp->sacked_out = 0; 1971 tp->sacked_out = 0;
1957 /* 2. SACK counts snd_fack in packets inaccurately. */ 1972 /* 2. SACK counts snd_fack in packets inaccurately. */
1958 if (tp->sacked_out == 0) 1973 if (tp->sacked_out == 0)
1959 tp->fackets_out = 0; 1974 tp->fackets_out = 0;
1960 1975
1961 /* Now state machine starts. 1976 /* Now state machine starts.
1962 * A. ECE, hence prohibit cwnd undoing, the reduction is required. */ 1977 * A. ECE, hence prohibit cwnd undoing, the reduction is required. */
1963 if (flag&FLAG_ECE) 1978 if (flag&FLAG_ECE)
1964 tp->prior_ssthresh = 0; 1979 tp->prior_ssthresh = 0;
@@ -2188,7 +2203,7 @@ static int tcp_tso_acked(struct sock *sk, struct sk_buff *skb,
2188 __u32 now, __s32 *seq_rtt) 2203 __u32 now, __s32 *seq_rtt)
2189{ 2204{
2190 struct tcp_sock *tp = tcp_sk(sk); 2205 struct tcp_sock *tp = tcp_sk(sk);
2191 struct tcp_skb_cb *scb = TCP_SKB_CB(skb); 2206 struct tcp_skb_cb *scb = TCP_SKB_CB(skb);
2192 __u32 seq = tp->snd_una; 2207 __u32 seq = tp->snd_una;
2193 __u32 packets_acked; 2208 __u32 packets_acked;
2194 int acked = 0; 2209 int acked = 0;
@@ -2264,7 +2279,7 @@ static int tcp_clean_rtx_queue(struct sock *sk, __s32 *seq_rtt_p)
2264 2279
2265 while ((skb = skb_peek(&sk->sk_write_queue)) && 2280 while ((skb = skb_peek(&sk->sk_write_queue)) &&
2266 skb != sk->sk_send_head) { 2281 skb != sk->sk_send_head) {
2267 struct tcp_skb_cb *scb = TCP_SKB_CB(skb); 2282 struct tcp_skb_cb *scb = TCP_SKB_CB(skb);
2268 __u8 sacked = scb->sacked; 2283 __u8 sacked = scb->sacked;
2269 2284
2270 /* If our packet is before the ack sequence we can 2285 /* If our packet is before the ack sequence we can
@@ -2455,9 +2470,9 @@ static int tcp_ack_update_window(struct sock *sk, struct tcp_sock *tp,
2455static void tcp_process_frto(struct sock *sk, u32 prior_snd_una) 2470static void tcp_process_frto(struct sock *sk, u32 prior_snd_una)
2456{ 2471{
2457 struct tcp_sock *tp = tcp_sk(sk); 2472 struct tcp_sock *tp = tcp_sk(sk);
2458 2473
2459 tcp_sync_left_out(tp); 2474 tcp_sync_left_out(tp);
2460 2475
2461 if (tp->snd_una == prior_snd_una || 2476 if (tp->snd_una == prior_snd_una ||
2462 !before(tp->snd_una, tp->frto_highmark)) { 2477 !before(tp->snd_una, tp->frto_highmark)) {
2463 /* RTO was caused by loss, start retransmitting in 2478 /* RTO was caused by loss, start retransmitting in
@@ -2612,7 +2627,7 @@ void tcp_parse_options(struct sk_buff *skb, struct tcp_options_received *opt_rx,
2612 opt_rx->saw_tstamp = 0; 2627 opt_rx->saw_tstamp = 0;
2613 2628
2614 while(length>0) { 2629 while(length>0) {
2615 int opcode=*ptr++; 2630 int opcode=*ptr++;
2616 int opsize; 2631 int opsize;
2617 2632
2618 switch (opcode) { 2633 switch (opcode) {
@@ -2627,7 +2642,7 @@ void tcp_parse_options(struct sk_buff *skb, struct tcp_options_received *opt_rx,
2627 return; 2642 return;
2628 if (opsize > length) 2643 if (opsize > length)
2629 return; /* don't parse partial options */ 2644 return; /* don't parse partial options */
2630 switch(opcode) { 2645 switch(opcode) {
2631 case TCPOPT_MSS: 2646 case TCPOPT_MSS:
2632 if(opsize==TCPOLEN_MSS && th->syn && !estab) { 2647 if(opsize==TCPOLEN_MSS && th->syn && !estab) {
2633 u16 in_mss = ntohs(get_unaligned((__be16 *)ptr)); 2648 u16 in_mss = ntohs(get_unaligned((__be16 *)ptr));
@@ -2686,10 +2701,10 @@ void tcp_parse_options(struct sk_buff *skb, struct tcp_options_received *opt_rx,
2686 */ 2701 */
2687 break; 2702 break;
2688#endif 2703#endif
2689 }; 2704 };
2690 ptr+=opsize-2; 2705 ptr+=opsize-2;
2691 length-=opsize; 2706 length-=opsize;
2692 }; 2707 };
2693 } 2708 }
2694} 2709}
2695 2710
@@ -3248,7 +3263,7 @@ drop:
3248 TCP_SKB_CB(skb)->end_seq); 3263 TCP_SKB_CB(skb)->end_seq);
3249 3264
3250 tcp_dsack_set(tp, TCP_SKB_CB(skb)->seq, tp->rcv_nxt); 3265 tcp_dsack_set(tp, TCP_SKB_CB(skb)->seq, tp->rcv_nxt);
3251 3266
3252 /* If window is closed, drop tail of packet. But after 3267 /* If window is closed, drop tail of packet. But after
3253 * remembering D-SACK for its head made in previous line. 3268 * remembering D-SACK for its head made in previous line.
3254 */ 3269 */
@@ -3327,7 +3342,7 @@ drop:
3327 } 3342 }
3328 } 3343 }
3329 __skb_insert(skb, skb1, skb1->next, &tp->out_of_order_queue); 3344 __skb_insert(skb, skb1, skb1->next, &tp->out_of_order_queue);
3330 3345
3331 /* And clean segments covered by new one as whole. */ 3346 /* And clean segments covered by new one as whole. */
3332 while ((skb1 = skb->next) != 3347 while ((skb1 = skb->next) !=
3333 (struct sk_buff*)&tp->out_of_order_queue && 3348 (struct sk_buff*)&tp->out_of_order_queue &&
@@ -3492,7 +3507,7 @@ static void tcp_collapse_ofo_queue(struct sock *sk)
3492 */ 3507 */
3493static int tcp_prune_queue(struct sock *sk) 3508static int tcp_prune_queue(struct sock *sk)
3494{ 3509{
3495 struct tcp_sock *tp = tcp_sk(sk); 3510 struct tcp_sock *tp = tcp_sk(sk);
3496 3511
3497 SOCK_DEBUG(sk, "prune_queue: c=%x\n", tp->copied_seq); 3512 SOCK_DEBUG(sk, "prune_queue: c=%x\n", tp->copied_seq);
3498 3513
@@ -3602,7 +3617,7 @@ static void tcp_new_space(struct sock *sk)
3602 struct tcp_sock *tp = tcp_sk(sk); 3617 struct tcp_sock *tp = tcp_sk(sk);
3603 3618
3604 if (tcp_should_expand_sndbuf(sk, tp)) { 3619 if (tcp_should_expand_sndbuf(sk, tp)) {
3605 int sndmem = max_t(u32, tp->rx_opt.mss_clamp, tp->mss_cache) + 3620 int sndmem = max_t(u32, tp->rx_opt.mss_clamp, tp->mss_cache) +
3606 MAX_TCP_HEADER + 16 + sizeof(struct sk_buff), 3621 MAX_TCP_HEADER + 16 + sizeof(struct sk_buff),
3607 demanded = max_t(unsigned int, tp->snd_cwnd, 3622 demanded = max_t(unsigned int, tp->snd_cwnd,
3608 tp->reordering + 1); 3623 tp->reordering + 1);
@@ -3675,7 +3690,7 @@ static inline void tcp_ack_snd_check(struct sock *sk)
3675 * For 1003.1g we should support a new option TCP_STDURG to permit 3690 * For 1003.1g we should support a new option TCP_STDURG to permit
3676 * either form (or just set the sysctl tcp_stdurg). 3691 * either form (or just set the sysctl tcp_stdurg).
3677 */ 3692 */
3678 3693
3679static void tcp_check_urg(struct sock * sk, struct tcphdr * th) 3694static void tcp_check_urg(struct sock * sk, struct tcphdr * th)
3680{ 3695{
3681 struct tcp_sock *tp = tcp_sk(sk); 3696 struct tcp_sock *tp = tcp_sk(sk);
@@ -3756,7 +3771,7 @@ static void tcp_urg(struct sock *sk, struct sk_buff *skb, struct tcphdr *th)
3756 u32 ptr = tp->urg_seq - ntohl(th->seq) + (th->doff * 4) - 3771 u32 ptr = tp->urg_seq - ntohl(th->seq) + (th->doff * 4) -
3757 th->syn; 3772 th->syn;
3758 3773
3759 /* Is the urgent pointer pointing into this packet? */ 3774 /* Is the urgent pointer pointing into this packet? */
3760 if (ptr < skb->len) { 3775 if (ptr < skb->len) {
3761 u8 tmp; 3776 u8 tmp;
3762 if (skb_copy_bits(skb, ptr, &tmp, 1)) 3777 if (skb_copy_bits(skb, ptr, &tmp, 1))
@@ -3820,7 +3835,7 @@ static int tcp_dma_try_early_copy(struct sock *sk, struct sk_buff *skb, int hlen
3820 int copied_early = 0; 3835 int copied_early = 0;
3821 3836
3822 if (tp->ucopy.wakeup) 3837 if (tp->ucopy.wakeup)
3823 return 0; 3838 return 0;
3824 3839
3825 if (!tp->ucopy.dma_chan && tp->ucopy.pinned_list) 3840 if (!tp->ucopy.dma_chan && tp->ucopy.pinned_list)
3826 tp->ucopy.dma_chan = get_softnet_dma(); 3841 tp->ucopy.dma_chan = get_softnet_dma();
@@ -3856,26 +3871,26 @@ out:
3856#endif /* CONFIG_NET_DMA */ 3871#endif /* CONFIG_NET_DMA */
3857 3872
3858/* 3873/*
3859 * TCP receive function for the ESTABLISHED state. 3874 * TCP receive function for the ESTABLISHED state.
3860 * 3875 *
3861 * It is split into a fast path and a slow path. The fast path is 3876 * It is split into a fast path and a slow path. The fast path is
3862 * disabled when: 3877 * disabled when:
3863 * - A zero window was announced from us - zero window probing 3878 * - A zero window was announced from us - zero window probing
3864 * is only handled properly in the slow path. 3879 * is only handled properly in the slow path.
3865 * - Out of order segments arrived. 3880 * - Out of order segments arrived.
3866 * - Urgent data is expected. 3881 * - Urgent data is expected.
3867 * - There is no buffer space left 3882 * - There is no buffer space left
3868 * - Unexpected TCP flags/window values/header lengths are received 3883 * - Unexpected TCP flags/window values/header lengths are received
3869 * (detected by checking the TCP header against pred_flags) 3884 * (detected by checking the TCP header against pred_flags)
3870 * - Data is sent in both directions. Fast path only supports pure senders 3885 * - Data is sent in both directions. Fast path only supports pure senders
3871 * or pure receivers (this means either the sequence number or the ack 3886 * or pure receivers (this means either the sequence number or the ack
3872 * value must stay constant) 3887 * value must stay constant)
3873 * - Unexpected TCP option. 3888 * - Unexpected TCP option.
3874 * 3889 *
3875 * When these conditions are not satisfied it drops into a standard 3890 * When these conditions are not satisfied it drops into a standard
3876 * receive procedure patterned after RFC793 to handle all cases. 3891 * receive procedure patterned after RFC793 to handle all cases.
3877 * The first three cases are guaranteed by proper pred_flags setting, 3892 * The first three cases are guaranteed by proper pred_flags setting,
3878 * the rest is checked inline. Fast processing is turned on in 3893 * the rest is checked inline. Fast processing is turned on in
3879 * tcp_data_queue when everything is OK. 3894 * tcp_data_queue when everything is OK.
3880 */ 3895 */
3881int tcp_rcv_established(struct sock *sk, struct sk_buff *skb, 3896int tcp_rcv_established(struct sock *sk, struct sk_buff *skb,
@@ -3885,15 +3900,15 @@ int tcp_rcv_established(struct sock *sk, struct sk_buff *skb,
3885 3900
3886 /* 3901 /*
3887 * Header prediction. 3902 * Header prediction.
3888 * The code loosely follows the one in the famous 3903 * The code loosely follows the one in the famous
3889 * "30 instruction TCP receive" Van Jacobson mail. 3904 * "30 instruction TCP receive" Van Jacobson mail.
3890 * 3905 *
3891 * Van's trick is to deposit buffers into socket queue 3906 * Van's trick is to deposit buffers into socket queue
3892 * on a device interrupt, to call tcp_recv function 3907 * on a device interrupt, to call tcp_recv function
3893 * on the receive process context and checksum and copy 3908 * on the receive process context and checksum and copy
3894 * the buffer to user space. smart... 3909 * the buffer to user space. smart...
3895 * 3910 *
3896 * Our current scheme is not silly either but we take the 3911 * Our current scheme is not silly either but we take the
3897 * extra cost of the net_bh soft interrupt processing... 3912 * extra cost of the net_bh soft interrupt processing...
3898 * We do checksum and copy also but from device to kernel. 3913 * We do checksum and copy also but from device to kernel.
3899 */ 3914 */
@@ -3904,7 +3919,7 @@ int tcp_rcv_established(struct sock *sk, struct sk_buff *skb,
3904 * if header_prediction is to be made 3919 * if header_prediction is to be made
3905 * 'S' will always be tp->tcp_header_len >> 2 3920 * 'S' will always be tp->tcp_header_len >> 2
3906 * '?' will be 0 for the fast path, otherwise pred_flags is 0 to 3921 * '?' will be 0 for the fast path, otherwise pred_flags is 0 to
3907 * turn it off (when there are holes in the receive 3922 * turn it off (when there are holes in the receive
3908 * space for instance) 3923 * space for instance)
3909 * PSH flag is ignored. 3924 * PSH flag is ignored.
3910 */ 3925 */
@@ -3928,7 +3943,7 @@ int tcp_rcv_established(struct sock *sk, struct sk_buff *skb,
3928 goto slow_path; 3943 goto slow_path;
3929 3944
3930 tp->rx_opt.saw_tstamp = 1; 3945 tp->rx_opt.saw_tstamp = 1;
3931 ++ptr; 3946 ++ptr;
3932 tp->rx_opt.rcv_tsval = ntohl(*ptr); 3947 tp->rx_opt.rcv_tsval = ntohl(*ptr);
3933 ++ptr; 3948 ++ptr;
3934 tp->rx_opt.rcv_tsecr = ntohl(*ptr); 3949 tp->rx_opt.rcv_tsecr = ntohl(*ptr);
@@ -3960,7 +3975,7 @@ int tcp_rcv_established(struct sock *sk, struct sk_buff *skb,
3960 * on entry. 3975 * on entry.
3961 */ 3976 */
3962 tcp_ack(sk, skb, 0); 3977 tcp_ack(sk, skb, 0);
3963 __kfree_skb(skb); 3978 __kfree_skb(skb);
3964 tcp_data_snd_check(sk, tp); 3979 tcp_data_snd_check(sk, tp);
3965 return 0; 3980 return 0;
3966 } else { /* Header too small */ 3981 } else { /* Header too small */
@@ -4378,11 +4393,11 @@ reset_and_undo:
4378 4393
4379/* 4394/*
4380 * This function implements the receiving procedure of RFC 793 for 4395 * This function implements the receiving procedure of RFC 793 for
4381 * all states except ESTABLISHED and TIME_WAIT. 4396 * all states except ESTABLISHED and TIME_WAIT.
4382 * It's called from both tcp_v4_rcv and tcp_v6_rcv and should be 4397 * It's called from both tcp_v4_rcv and tcp_v6_rcv and should be
4383 * address independent. 4398 * address independent.
4384 */ 4399 */
4385 4400
4386int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb, 4401int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
4387 struct tcphdr *th, unsigned len) 4402 struct tcphdr *th, unsigned len)
4388{ 4403{
@@ -4407,19 +4422,19 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
4407 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0) 4422 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
4408 return 1; 4423 return 1;
4409 4424
4410 /* Now we have several options: In theory there is 4425 /* Now we have several options: In theory there is
4411 * nothing else in the frame. KA9Q has an option to 4426 * nothing else in the frame. KA9Q has an option to
4412 * send data with the syn, BSD accepts data with the 4427 * send data with the syn, BSD accepts data with the
4413 * syn up to the [to be] advertised window and 4428 * syn up to the [to be] advertised window and
4414 * Solaris 2.1 gives you a protocol error. For now 4429 * Solaris 2.1 gives you a protocol error. For now
4415 * we just ignore it, that fits the spec precisely 4430 * we just ignore it, that fits the spec precisely
4416 * and avoids incompatibilities. It would be nice in 4431 * and avoids incompatibilities. It would be nice in
4417 * future to drop through and process the data. 4432 * future to drop through and process the data.
4418 * 4433 *
4419 * Now that TTCP is starting to be used we ought to 4434 * Now that TTCP is starting to be used we ought to
4420 * queue this data. 4435 * queue this data.
4421 * But, this leaves one open to an easy denial of 4436 * But, this leaves one open to an easy denial of
4422 * service attack, and SYN cookies can't defend 4437 * service attack, and SYN cookies can't defend
4423 * against this problem. So, we drop the data 4438 * against this problem. So, we drop the data
4424 * in the interest of security over speed unless 4439 * in the interest of security over speed unless
4425 * it's still in use. 4440 * it's still in use.
@@ -4609,7 +4624,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
4609 case TCP_FIN_WAIT1: 4624 case TCP_FIN_WAIT1:
4610 case TCP_FIN_WAIT2: 4625 case TCP_FIN_WAIT2:
4611 /* RFC 793 says to queue data in these states, 4626 /* RFC 793 says to queue data in these states,
4612 * RFC 1122 says we MUST send a reset. 4627 * RFC 1122 says we MUST send a reset.
4613 * BSD 4.4 also does reset. 4628 * BSD 4.4 also does reset.
4614 */ 4629 */
4615 if (sk->sk_shutdown & RCV_SHUTDOWN) { 4630 if (sk->sk_shutdown & RCV_SHUTDOWN) {
@@ -4621,7 +4636,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
4621 } 4636 }
4622 } 4637 }
4623 /* Fall through */ 4638 /* Fall through */
4624 case TCP_ESTABLISHED: 4639 case TCP_ESTABLISHED:
4625 tcp_data_queue(sk, skb); 4640 tcp_data_queue(sk, skb);
4626 queued = 1; 4641 queued = 1;
4627 break; 4642 break;
@@ -4633,7 +4648,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
4633 tcp_ack_snd_check(sk); 4648 tcp_ack_snd_check(sk);
4634 } 4649 }
4635 4650
4636 if (!queued) { 4651 if (!queued) {
4637discard: 4652discard:
4638 __kfree_skb(skb); 4653 __kfree_skb(skb);
4639 } 4654 }
diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
index 12de90a5047c..0ba74bbe7d30 100644
--- a/net/ipv4/tcp_ipv4.c
+++ b/net/ipv4/tcp_ipv4.c
@@ -191,7 +191,7 @@ int tcp_v4_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len)
191 tmp = ip_route_connect(&rt, nexthop, inet->saddr, 191 tmp = ip_route_connect(&rt, nexthop, inet->saddr,
192 RT_CONN_FLAGS(sk), sk->sk_bound_dev_if, 192 RT_CONN_FLAGS(sk), sk->sk_bound_dev_if,
193 IPPROTO_TCP, 193 IPPROTO_TCP,
194 inet->sport, usin->sin_port, sk); 194 inet->sport, usin->sin_port, sk, 1);
195 if (tmp < 0) 195 if (tmp < 0)
196 return tmp; 196 return tmp;
197 197
@@ -303,7 +303,7 @@ static void do_pmtu_discovery(struct sock *sk, struct iphdr *iph, u32 mtu)
303 /* We don't check in the destentry if pmtu discovery is forbidden 303 /* We don't check in the destentry if pmtu discovery is forbidden
304 * on this route. We just assume that no packet_to_big packets 304 * on this route. We just assume that no packet_to_big packets
305 * are send back when pmtu discovery is not active. 305 * are send back when pmtu discovery is not active.
306 * There is a small race when the user changes this flag in the 306 * There is a small race when the user changes this flag in the
307 * route, but I think that's acceptable. 307 * route, but I think that's acceptable.
308 */ 308 */
309 if ((dst = __sk_dst_check(sk, 0)) == NULL) 309 if ((dst = __sk_dst_check(sk, 0)) == NULL)
@@ -502,11 +502,11 @@ void tcp_v4_send_check(struct sock *sk, int len, struct sk_buff *skb)
502 struct tcphdr *th = skb->h.th; 502 struct tcphdr *th = skb->h.th;
503 503
504 if (skb->ip_summed == CHECKSUM_PARTIAL) { 504 if (skb->ip_summed == CHECKSUM_PARTIAL) {
505 th->check = ~tcp_v4_check(th, len, 505 th->check = ~tcp_v4_check(len, inet->saddr,
506 inet->saddr, inet->daddr, 0); 506 inet->daddr, 0);
507 skb->csum_offset = offsetof(struct tcphdr, check); 507 skb->csum_offset = offsetof(struct tcphdr, check);
508 } else { 508 } else {
509 th->check = tcp_v4_check(th, len, inet->saddr, inet->daddr, 509 th->check = tcp_v4_check(len, inet->saddr, inet->daddr,
510 csum_partial((char *)th, 510 csum_partial((char *)th,
511 th->doff << 2, 511 th->doff << 2,
512 skb->csum)); 512 skb->csum));
@@ -525,7 +525,7 @@ int tcp_v4_gso_send_check(struct sk_buff *skb)
525 th = skb->h.th; 525 th = skb->h.th;
526 526
527 th->check = 0; 527 th->check = 0;
528 th->check = ~tcp_v4_check(th, skb->len, iph->saddr, iph->daddr, 0); 528 th->check = ~tcp_v4_check(skb->len, iph->saddr, iph->daddr, 0);
529 skb->csum_offset = offsetof(struct tcphdr, check); 529 skb->csum_offset = offsetof(struct tcphdr, check);
530 skb->ip_summed = CHECKSUM_PARTIAL; 530 skb->ip_summed = CHECKSUM_PARTIAL;
531 return 0; 531 return 0;
@@ -747,7 +747,7 @@ static int tcp_v4_send_synack(struct sock *sk, struct request_sock *req,
747 if (skb) { 747 if (skb) {
748 struct tcphdr *th = skb->h.th; 748 struct tcphdr *th = skb->h.th;
749 749
750 th->check = tcp_v4_check(th, skb->len, 750 th->check = tcp_v4_check(skb->len,
751 ireq->loc_addr, 751 ireq->loc_addr,
752 ireq->rmt_addr, 752 ireq->rmt_addr,
753 csum_partial((char *)th, skb->len, 753 csum_partial((char *)th, skb->len,
@@ -880,7 +880,7 @@ int tcp_v4_md5_do_add(struct sock *sk, __be32 addr,
880 880
881 if (md5sig->alloced4 == md5sig->entries4) { 881 if (md5sig->alloced4 == md5sig->entries4) {
882 keys = kmalloc((sizeof(*keys) * 882 keys = kmalloc((sizeof(*keys) *
883 (md5sig->entries4 + 1)), GFP_ATOMIC); 883 (md5sig->entries4 + 1)), GFP_ATOMIC);
884 if (!keys) { 884 if (!keys) {
885 kfree(newkey); 885 kfree(newkey);
886 tcp_free_md5sig_pool(); 886 tcp_free_md5sig_pool();
@@ -934,7 +934,7 @@ int tcp_v4_md5_do_del(struct sock *sk, __be32 addr)
934 memcpy(&tp->md5sig_info->keys4[i], 934 memcpy(&tp->md5sig_info->keys4[i],
935 &tp->md5sig_info->keys4[i+1], 935 &tp->md5sig_info->keys4[i+1],
936 (tp->md5sig_info->entries4 - i) * 936 (tp->md5sig_info->entries4 - i) *
937 sizeof(struct tcp4_md5sig_key)); 937 sizeof(struct tcp4_md5sig_key));
938 } 938 }
939 tcp_free_md5sig_pool(); 939 tcp_free_md5sig_pool();
940 return 0; 940 return 0;
@@ -1388,7 +1388,7 @@ int tcp_v4_conn_request(struct sock *sk, struct sk_buff *skb)
1388 goto drop_and_free; 1388 goto drop_and_free;
1389 1389
1390 if (want_cookie) { 1390 if (want_cookie) {
1391 reqsk_free(req); 1391 reqsk_free(req);
1392 } else { 1392 } else {
1393 inet_csk_reqsk_queue_hash_add(sk, req, TCP_TIMEOUT_INIT); 1393 inet_csk_reqsk_queue_hash_add(sk, req, TCP_TIMEOUT_INIT);
1394 } 1394 }
@@ -1514,7 +1514,7 @@ static struct sock *tcp_v4_hnd_req(struct sock *sk, struct sk_buff *skb)
1514static __sum16 tcp_v4_checksum_init(struct sk_buff *skb) 1514static __sum16 tcp_v4_checksum_init(struct sk_buff *skb)
1515{ 1515{
1516 if (skb->ip_summed == CHECKSUM_COMPLETE) { 1516 if (skb->ip_summed == CHECKSUM_COMPLETE) {
1517 if (!tcp_v4_check(skb->h.th, skb->len, skb->nh.iph->saddr, 1517 if (!tcp_v4_check(skb->len, skb->nh.iph->saddr,
1518 skb->nh.iph->daddr, skb->csum)) { 1518 skb->nh.iph->daddr, skb->csum)) {
1519 skb->ip_summed = CHECKSUM_UNNECESSARY; 1519 skb->ip_summed = CHECKSUM_UNNECESSARY;
1520 return 0; 1520 return 0;
@@ -1704,7 +1704,7 @@ bad_packet:
1704discard_it: 1704discard_it:
1705 /* Discard frame. */ 1705 /* Discard frame. */
1706 kfree_skb(skb); 1706 kfree_skb(skb);
1707 return 0; 1707 return 0;
1708 1708
1709discard_and_relse: 1709discard_and_relse:
1710 sock_put(sk); 1710 sock_put(sk);
@@ -1890,10 +1890,10 @@ int tcp_v4_destroy_sock(struct sock *sk)
1890 tcp_cleanup_congestion_control(sk); 1890 tcp_cleanup_congestion_control(sk);
1891 1891
1892 /* Cleanup up the write buffer. */ 1892 /* Cleanup up the write buffer. */
1893 sk_stream_writequeue_purge(sk); 1893 sk_stream_writequeue_purge(sk);
1894 1894
1895 /* Cleans up our, hopefully empty, out_of_order_queue. */ 1895 /* Cleans up our, hopefully empty, out_of_order_queue. */
1896 __skb_queue_purge(&tp->out_of_order_queue); 1896 __skb_queue_purge(&tp->out_of_order_queue);
1897 1897
1898#ifdef CONFIG_TCP_MD5SIG 1898#ifdef CONFIG_TCP_MD5SIG
1899 /* Clean up the MD5 key list, if any */ 1899 /* Clean up the MD5 key list, if any */
@@ -1906,7 +1906,7 @@ int tcp_v4_destroy_sock(struct sock *sk)
1906 1906
1907#ifdef CONFIG_NET_DMA 1907#ifdef CONFIG_NET_DMA
1908 /* Cleans up our sk_async_wait_queue */ 1908 /* Cleans up our sk_async_wait_queue */
1909 __skb_queue_purge(&sk->sk_async_wait_queue); 1909 __skb_queue_purge(&sk->sk_async_wait_queue);
1910#endif 1910#endif
1911 1911
1912 /* Clean prequeue, it must be empty really */ 1912 /* Clean prequeue, it must be empty really */
@@ -1983,7 +1983,7 @@ get_req:
1983 st->state = TCP_SEQ_STATE_LISTENING; 1983 st->state = TCP_SEQ_STATE_LISTENING;
1984 read_unlock_bh(&icsk->icsk_accept_queue.syn_wait_lock); 1984 read_unlock_bh(&icsk->icsk_accept_queue.syn_wait_lock);
1985 } else { 1985 } else {
1986 icsk = inet_csk(sk); 1986 icsk = inet_csk(sk);
1987 read_lock_bh(&icsk->icsk_accept_queue.syn_wait_lock); 1987 read_lock_bh(&icsk->icsk_accept_queue.syn_wait_lock);
1988 if (reqsk_queue_len(&icsk->icsk_accept_queue)) 1988 if (reqsk_queue_len(&icsk->icsk_accept_queue))
1989 goto start_req; 1989 goto start_req;
@@ -1996,7 +1996,7 @@ get_sk:
1996 cur = sk; 1996 cur = sk;
1997 goto out; 1997 goto out;
1998 } 1998 }
1999 icsk = inet_csk(sk); 1999 icsk = inet_csk(sk);
2000 read_lock_bh(&icsk->icsk_accept_queue.syn_wait_lock); 2000 read_lock_bh(&icsk->icsk_accept_queue.syn_wait_lock);
2001 if (reqsk_queue_len(&icsk->icsk_accept_queue)) { 2001 if (reqsk_queue_len(&icsk->icsk_accept_queue)) {
2002start_req: 2002start_req:
@@ -2051,7 +2051,7 @@ static void *established_get_first(struct seq_file *seq)
2051 } 2051 }
2052 st->state = TCP_SEQ_STATE_TIME_WAIT; 2052 st->state = TCP_SEQ_STATE_TIME_WAIT;
2053 inet_twsk_for_each(tw, node, 2053 inet_twsk_for_each(tw, node,
2054 &tcp_hashinfo.ehash[st->bucket + tcp_hashinfo.ehash_size].chain) { 2054 &tcp_hashinfo.ehash[st->bucket].twchain) {
2055 if (tw->tw_family != st->family) { 2055 if (tw->tw_family != st->family) {
2056 continue; 2056 continue;
2057 } 2057 }
@@ -2107,7 +2107,7 @@ get_tw:
2107 } 2107 }
2108 2108
2109 st->state = TCP_SEQ_STATE_TIME_WAIT; 2109 st->state = TCP_SEQ_STATE_TIME_WAIT;
2110 tw = tw_head(&tcp_hashinfo.ehash[st->bucket + tcp_hashinfo.ehash_size].chain); 2110 tw = tw_head(&tcp_hashinfo.ehash[st->bucket].twchain);
2111 goto get_tw; 2111 goto get_tw;
2112found: 2112found:
2113 cur = sk; 2113 cur = sk;
diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
index 4a3889dd1943..30b1e520ad94 100644
--- a/net/ipv4/tcp_minisocks.c
+++ b/net/ipv4/tcp_minisocks.c
@@ -64,7 +64,7 @@ static __inline__ int tcp_in_window(u32 seq, u32 end_seq, u32 s_win, u32 e_win)
64 return (seq == e_win && seq == end_seq); 64 return (seq == e_win && seq == end_seq);
65} 65}
66 66
67/* 67/*
68 * * Main purpose of TIME-WAIT state is to close connection gracefully, 68 * * Main purpose of TIME-WAIT state is to close connection gracefully,
69 * when one of ends sits in LAST-ACK or CLOSING retransmitting FIN 69 * when one of ends sits in LAST-ACK or CLOSING retransmitting FIN
70 * (and, probably, tail of data) and one or more our ACKs are lost. 70 * (and, probably, tail of data) and one or more our ACKs are lost.
@@ -176,13 +176,13 @@ kill_with_rst:
176 * "When a connection is [...] on TIME-WAIT state [...] 176 * "When a connection is [...] on TIME-WAIT state [...]
177 * [a TCP] MAY accept a new SYN from the remote TCP to 177 * [a TCP] MAY accept a new SYN from the remote TCP to
178 * reopen the connection directly, if it: 178 * reopen the connection directly, if it:
179 * 179 *
180 * (1) assigns its initial sequence number for the new 180 * (1) assigns its initial sequence number for the new
181 * connection to be larger than the largest sequence 181 * connection to be larger than the largest sequence
182 * number it used on the previous connection incarnation, 182 * number it used on the previous connection incarnation,
183 * and 183 * and
184 * 184 *
185 * (2) returns to TIME-WAIT state if the SYN turns out 185 * (2) returns to TIME-WAIT state if the SYN turns out
186 * to be an old duplicate". 186 * to be an old duplicate".
187 */ 187 */
188 188
@@ -266,9 +266,9 @@ kill:
266 return TCP_TW_SUCCESS; 266 return TCP_TW_SUCCESS;
267} 267}
268 268
269/* 269/*
270 * Move a socket to time-wait or dead fin-wait-2 state. 270 * Move a socket to time-wait or dead fin-wait-2 state.
271 */ 271 */
272void tcp_time_wait(struct sock *sk, int state, int timeo) 272void tcp_time_wait(struct sock *sk, int state, int timeo)
273{ 273{
274 struct inet_timewait_sock *tw = NULL; 274 struct inet_timewait_sock *tw = NULL;
@@ -481,7 +481,7 @@ struct sock *tcp_create_openreq_child(struct sock *sk, struct request_sock *req,
481 return newsk; 481 return newsk;
482} 482}
483 483
484/* 484/*
485 * Process an incoming packet for SYN_RECV sockets represented 485 * Process an incoming packet for SYN_RECV sockets represented
486 * as a request_sock. 486 * as a request_sock.
487 */ 487 */
diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c
index 975f4472af29..cebe9aa918a3 100644
--- a/net/ipv4/tcp_output.c
+++ b/net/ipv4/tcp_output.c
@@ -198,7 +198,7 @@ void tcp_select_initial_window(int __space, __u32 mss,
198 (*rcv_wscale) = 0; 198 (*rcv_wscale) = 0;
199 if (wscale_ok) { 199 if (wscale_ok) {
200 /* Set window scaling on max possible window 200 /* Set window scaling on max possible window
201 * See RFC1323 for an explanation of the limit to 14 201 * See RFC1323 for an explanation of the limit to 14
202 */ 202 */
203 space = max_t(u32, sysctl_tcp_rmem[2], sysctl_rmem_max); 203 space = max_t(u32, sysctl_tcp_rmem[2], sysctl_rmem_max);
204 space = min_t(u32, space, *window_clamp); 204 space = min_t(u32, space, *window_clamp);
@@ -451,7 +451,7 @@ static int tcp_transmit_skb(struct sock *sk, struct sk_buff *skb, int clone_it,
451 (tp->rx_opt.eff_sacks * 451 (tp->rx_opt.eff_sacks *
452 TCPOLEN_SACK_PERBLOCK)); 452 TCPOLEN_SACK_PERBLOCK));
453 } 453 }
454 454
455 if (tcp_packets_in_flight(tp) == 0) 455 if (tcp_packets_in_flight(tp) == 0)
456 tcp_ca_event(sk, CA_EVENT_TX_START); 456 tcp_ca_event(sk, CA_EVENT_TX_START);
457 457
@@ -555,7 +555,7 @@ static int tcp_transmit_skb(struct sock *sk, struct sk_buff *skb, int clone_it,
555} 555}
556 556
557 557
558/* This routine just queue's the buffer 558/* This routine just queue's the buffer
559 * 559 *
560 * NOTE: probe0 timer is not checked, do not forget tcp_push_pending_frames, 560 * NOTE: probe0 timer is not checked, do not forget tcp_push_pending_frames,
561 * otherwise socket can stall. 561 * otherwise socket can stall.
@@ -597,7 +597,7 @@ static void tcp_set_skb_tso_segs(struct sock *sk, struct sk_buff *skb, unsigned
597 597
598/* Function to create two new TCP segments. Shrinks the given segment 598/* Function to create two new TCP segments. Shrinks the given segment
599 * to the specified size and appends a new segment with the rest of the 599 * to the specified size and appends a new segment with the rest of the
600 * packet to the list. This won't be called frequently, I hope. 600 * packet to the list. This won't be called frequently, I hope.
601 * Remember, these are still headerless SKBs at this point. 601 * Remember, these are still headerless SKBs at this point.
602 */ 602 */
603int tcp_fragment(struct sock *sk, struct sk_buff *skb, u32 len, unsigned int mss_now) 603int tcp_fragment(struct sock *sk, struct sk_buff *skb, u32 len, unsigned int mss_now)
@@ -610,7 +610,7 @@ int tcp_fragment(struct sock *sk, struct sk_buff *skb, u32 len, unsigned int mss
610 610
611 BUG_ON(len > skb->len); 611 BUG_ON(len > skb->len);
612 612
613 clear_all_retrans_hints(tp); 613 clear_all_retrans_hints(tp);
614 nsize = skb_headlen(skb) - len; 614 nsize = skb_headlen(skb) - len;
615 if (nsize < 0) 615 if (nsize < 0)
616 nsize = 0; 616 nsize = 0;
@@ -821,7 +821,7 @@ void tcp_mtup_init(struct sock *sk)
821 821
822 icsk->icsk_mtup.enabled = sysctl_tcp_mtu_probing > 1; 822 icsk->icsk_mtup.enabled = sysctl_tcp_mtu_probing > 1;
823 icsk->icsk_mtup.search_high = tp->rx_opt.mss_clamp + sizeof(struct tcphdr) + 823 icsk->icsk_mtup.search_high = tp->rx_opt.mss_clamp + sizeof(struct tcphdr) +
824 icsk->icsk_af_ops->net_header_len; 824 icsk->icsk_af_ops->net_header_len;
825 icsk->icsk_mtup.search_low = tcp_mss_to_mtu(sk, sysctl_tcp_base_mss); 825 icsk->icsk_mtup.search_low = tcp_mss_to_mtu(sk, sysctl_tcp_base_mss);
826 icsk->icsk_mtup.probe_size = 0; 826 icsk->icsk_mtup.probe_size = 0;
827} 827}
@@ -965,7 +965,8 @@ static inline unsigned int tcp_cwnd_test(struct tcp_sock *tp, struct sk_buff *sk
965 u32 in_flight, cwnd; 965 u32 in_flight, cwnd;
966 966
967 /* Don't be strict about the congestion window for the final FIN. */ 967 /* Don't be strict about the congestion window for the final FIN. */
968 if (TCP_SKB_CB(skb)->flags & TCPCB_FLAG_FIN) 968 if ((TCP_SKB_CB(skb)->flags & TCPCB_FLAG_FIN) &&
969 tcp_skb_pcount(skb) == 1)
969 return 1; 970 return 1;
970 971
971 in_flight = tcp_packets_in_flight(tp); 972 in_flight = tcp_packets_in_flight(tp);
@@ -1007,7 +1008,7 @@ static inline int tcp_minshall_check(const struct tcp_sock *tp)
1007 */ 1008 */
1008 1009
1009static inline int tcp_nagle_check(const struct tcp_sock *tp, 1010static inline int tcp_nagle_check(const struct tcp_sock *tp,
1010 const struct sk_buff *skb, 1011 const struct sk_buff *skb,
1011 unsigned mss_now, int nonagle) 1012 unsigned mss_now, int nonagle)
1012{ 1013{
1013 return (skb->len < mss_now && 1014 return (skb->len < mss_now &&
@@ -1077,7 +1078,7 @@ static unsigned int tcp_snd_test(struct sock *sk, struct sk_buff *skb,
1077 return cwnd_quota; 1078 return cwnd_quota;
1078} 1079}
1079 1080
1080static inline int tcp_skb_is_last(const struct sock *sk, 1081static inline int tcp_skb_is_last(const struct sock *sk,
1081 const struct sk_buff *skb) 1082 const struct sk_buff *skb)
1082{ 1083{
1083 return skb->next == (struct sk_buff *)&sk->sk_write_queue; 1084 return skb->next == (struct sk_buff *)&sk->sk_write_queue;
@@ -1297,7 +1298,7 @@ static int tcp_mtu_probe(struct sock *sk)
1297 skb_copy_bits(skb, 0, skb_put(nskb, copy), copy); 1298 skb_copy_bits(skb, 0, skb_put(nskb, copy), copy);
1298 else 1299 else
1299 nskb->csum = skb_copy_and_csum_bits(skb, 0, 1300 nskb->csum = skb_copy_and_csum_bits(skb, 0,
1300 skb_put(nskb, copy), copy, nskb->csum); 1301 skb_put(nskb, copy), copy, nskb->csum);
1301 1302
1302 if (skb->len <= copy) { 1303 if (skb->len <= copy) {
1303 /* We've eaten all the data from this skb. 1304 /* We've eaten all the data from this skb.
@@ -1307,7 +1308,7 @@ static int tcp_mtu_probe(struct sock *sk)
1307 sk_stream_free_skb(sk, skb); 1308 sk_stream_free_skb(sk, skb);
1308 } else { 1309 } else {
1309 TCP_SKB_CB(nskb)->flags |= TCP_SKB_CB(skb)->flags & 1310 TCP_SKB_CB(nskb)->flags |= TCP_SKB_CB(skb)->flags &
1310 ~(TCPCB_FLAG_FIN|TCPCB_FLAG_PSH); 1311 ~(TCPCB_FLAG_FIN|TCPCB_FLAG_PSH);
1311 if (!skb_shinfo(skb)->nr_frags) { 1312 if (!skb_shinfo(skb)->nr_frags) {
1312 skb_pull(skb, copy); 1313 skb_pull(skb, copy);
1313 if (skb->ip_summed != CHECKSUM_PARTIAL) 1314 if (skb->ip_summed != CHECKSUM_PARTIAL)
@@ -1500,7 +1501,7 @@ void tcp_push_one(struct sock *sk, unsigned int mss_now)
1500 1501
1501/* This function returns the amount that we can raise the 1502/* This function returns the amount that we can raise the
1502 * usable window based on the following constraints 1503 * usable window based on the following constraints
1503 * 1504 *
1504 * 1. The window can never be shrunk once it is offered (RFC 793) 1505 * 1. The window can never be shrunk once it is offered (RFC 793)
1505 * 2. We limit memory per socket 1506 * 2. We limit memory per socket
1506 * 1507 *
@@ -1519,12 +1520,12 @@ void tcp_push_one(struct sock *sk, unsigned int mss_now)
1519 * side SWS prevention criteria. The problem is that under this rule 1520 * side SWS prevention criteria. The problem is that under this rule
1520 * a stream of single byte packets will cause the right side of the 1521 * a stream of single byte packets will cause the right side of the
1521 * window to always advance by a single byte. 1522 * window to always advance by a single byte.
1522 * 1523 *
1523 * Of course, if the sender implements sender side SWS prevention 1524 * Of course, if the sender implements sender side SWS prevention
1524 * then this will not be a problem. 1525 * then this will not be a problem.
1525 * 1526 *
1526 * BSD seems to make the following compromise: 1527 * BSD seems to make the following compromise:
1527 * 1528 *
1528 * If the free space is less than the 1/4 of the maximum 1529 * If the free space is less than the 1/4 of the maximum
1529 * space available and the free space is less than 1/2 mss, 1530 * space available and the free space is less than 1/2 mss,
1530 * then set the window to 0. 1531 * then set the window to 0.
@@ -1566,7 +1567,7 @@ u32 __tcp_select_window(struct sock *sk)
1566 int window; 1567 int window;
1567 1568
1568 if (mss > full_space) 1569 if (mss > full_space)
1569 mss = full_space; 1570 mss = full_space;
1570 1571
1571 if (free_space < full_space/2) { 1572 if (free_space < full_space/2) {
1572 icsk->icsk_ack.quick = 0; 1573 icsk->icsk_ack.quick = 0;
@@ -1690,9 +1691,9 @@ static void tcp_retrans_try_collapse(struct sock *sk, struct sk_buff *skb, int m
1690} 1691}
1691 1692
1692/* Do a simple retransmit without using the backoff mechanisms in 1693/* Do a simple retransmit without using the backoff mechanisms in
1693 * tcp_timer. This is used for path mtu discovery. 1694 * tcp_timer. This is used for path mtu discovery.
1694 * The socket is already locked here. 1695 * The socket is already locked here.
1695 */ 1696 */
1696void tcp_simple_retransmit(struct sock *sk) 1697void tcp_simple_retransmit(struct sock *sk)
1697{ 1698{
1698 const struct inet_connection_sock *icsk = inet_csk(sk); 1699 const struct inet_connection_sock *icsk = inet_csk(sk);
@@ -1702,7 +1703,7 @@ void tcp_simple_retransmit(struct sock *sk)
1702 int lost = 0; 1703 int lost = 0;
1703 1704
1704 sk_stream_for_retrans_queue(skb, sk) { 1705 sk_stream_for_retrans_queue(skb, sk) {
1705 if (skb->len > mss && 1706 if (skb->len > mss &&
1706 !(TCP_SKB_CB(skb)->sacked&TCPCB_SACKED_ACKED)) { 1707 !(TCP_SKB_CB(skb)->sacked&TCPCB_SACKED_ACKED)) {
1707 if (TCP_SKB_CB(skb)->sacked&TCPCB_SACKED_RETRANS) { 1708 if (TCP_SKB_CB(skb)->sacked&TCPCB_SACKED_RETRANS) {
1708 TCP_SKB_CB(skb)->sacked &= ~TCPCB_SACKED_RETRANS; 1709 TCP_SKB_CB(skb)->sacked &= ~TCPCB_SACKED_RETRANS;
@@ -1723,7 +1724,7 @@ void tcp_simple_retransmit(struct sock *sk)
1723 1724
1724 tcp_sync_left_out(tp); 1725 tcp_sync_left_out(tp);
1725 1726
1726 /* Don't muck with the congestion window here. 1727 /* Don't muck with the congestion window here.
1727 * Reason is that we do not increase amount of _data_ 1728 * Reason is that we do not increase amount of _data_
1728 * in network, but units changed and effective 1729 * in network, but units changed and effective
1729 * cwnd/ssthresh really reduced now. 1730 * cwnd/ssthresh really reduced now.
@@ -1746,7 +1747,7 @@ int tcp_retransmit_skb(struct sock *sk, struct sk_buff *skb)
1746{ 1747{
1747 struct tcp_sock *tp = tcp_sk(sk); 1748 struct tcp_sock *tp = tcp_sk(sk);
1748 struct inet_connection_sock *icsk = inet_csk(sk); 1749 struct inet_connection_sock *icsk = inet_csk(sk);
1749 unsigned int cur_mss = tcp_current_mss(sk, 0); 1750 unsigned int cur_mss = tcp_current_mss(sk, 0);
1750 int err; 1751 int err;
1751 1752
1752 /* Inconslusive MTU probe */ 1753 /* Inconslusive MTU probe */
@@ -1983,10 +1984,10 @@ void tcp_xmit_retransmit_queue(struct sock *sk)
1983 */ 1984 */
1984void tcp_send_fin(struct sock *sk) 1985void tcp_send_fin(struct sock *sk)
1985{ 1986{
1986 struct tcp_sock *tp = tcp_sk(sk); 1987 struct tcp_sock *tp = tcp_sk(sk);
1987 struct sk_buff *skb = skb_peek_tail(&sk->sk_write_queue); 1988 struct sk_buff *skb = skb_peek_tail(&sk->sk_write_queue);
1988 int mss_now; 1989 int mss_now;
1989 1990
1990 /* Optimization, tack on the FIN if we have a queue of 1991 /* Optimization, tack on the FIN if we have a queue of
1991 * unsent frames. But be careful about outgoing SACKS 1992 * unsent frames. But be careful about outgoing SACKS
1992 * and IP options. 1993 * and IP options.
@@ -2145,17 +2146,17 @@ struct sk_buff * tcp_make_synack(struct sock *sk, struct dst_entry *dst,
2145 th->seq = htonl(TCP_SKB_CB(skb)->seq); 2146 th->seq = htonl(TCP_SKB_CB(skb)->seq);
2146 th->ack_seq = htonl(tcp_rsk(req)->rcv_isn + 1); 2147 th->ack_seq = htonl(tcp_rsk(req)->rcv_isn + 1);
2147 if (req->rcv_wnd == 0) { /* ignored for retransmitted syns */ 2148 if (req->rcv_wnd == 0) { /* ignored for retransmitted syns */
2148 __u8 rcv_wscale; 2149 __u8 rcv_wscale;
2149 /* Set this up on the first call only */ 2150 /* Set this up on the first call only */
2150 req->window_clamp = tp->window_clamp ? : dst_metric(dst, RTAX_WINDOW); 2151 req->window_clamp = tp->window_clamp ? : dst_metric(dst, RTAX_WINDOW);
2151 /* tcp_full_space because it is guaranteed to be the first packet */ 2152 /* tcp_full_space because it is guaranteed to be the first packet */
2152 tcp_select_initial_window(tcp_full_space(sk), 2153 tcp_select_initial_window(tcp_full_space(sk),
2153 dst_metric(dst, RTAX_ADVMSS) - (ireq->tstamp_ok ? TCPOLEN_TSTAMP_ALIGNED : 0), 2154 dst_metric(dst, RTAX_ADVMSS) - (ireq->tstamp_ok ? TCPOLEN_TSTAMP_ALIGNED : 0),
2154 &req->rcv_wnd, 2155 &req->rcv_wnd,
2155 &req->window_clamp, 2156 &req->window_clamp,
2156 ireq->wscale_ok, 2157 ireq->wscale_ok,
2157 &rcv_wscale); 2158 &rcv_wscale);
2158 ireq->rcv_wscale = rcv_wscale; 2159 ireq->rcv_wscale = rcv_wscale;
2159 } 2160 }
2160 2161
2161 /* RFC1323: The window in SYN & SYN/ACK segments is never scaled. */ 2162 /* RFC1323: The window in SYN & SYN/ACK segments is never scaled. */
@@ -2191,9 +2192,9 @@ struct sk_buff * tcp_make_synack(struct sock *sk, struct dst_entry *dst,
2191 return skb; 2192 return skb;
2192} 2193}
2193 2194
2194/* 2195/*
2195 * Do all connect socket setups that can be done AF independent. 2196 * Do all connect socket setups that can be done AF independent.
2196 */ 2197 */
2197static void tcp_connect_init(struct sock *sk) 2198static void tcp_connect_init(struct sock *sk)
2198{ 2199{
2199 struct dst_entry *dst = __sk_dst_get(sk); 2200 struct dst_entry *dst = __sk_dst_get(sk);
@@ -2250,7 +2251,7 @@ static void tcp_connect_init(struct sock *sk)
2250 2251
2251/* 2252/*
2252 * Build a SYN and send it off. 2253 * Build a SYN and send it off.
2253 */ 2254 */
2254int tcp_connect(struct sock *sk) 2255int tcp_connect(struct sock *sk)
2255{ 2256{
2256 struct tcp_sock *tp = tcp_sk(sk); 2257 struct tcp_sock *tp = tcp_sk(sk);
@@ -2408,7 +2409,7 @@ static int tcp_xmit_probe_skb(struct sock *sk, int urgent)
2408 2409
2409 /* We don't queue it, tcp_transmit_skb() sets ownership. */ 2410 /* We don't queue it, tcp_transmit_skb() sets ownership. */
2410 skb = alloc_skb(MAX_TCP_HEADER, GFP_ATOMIC); 2411 skb = alloc_skb(MAX_TCP_HEADER, GFP_ATOMIC);
2411 if (skb == NULL) 2412 if (skb == NULL)
2412 return -1; 2413 return -1;
2413 2414
2414 /* Reserve space for headers and set control bits. */ 2415 /* Reserve space for headers and set control bits. */
@@ -2497,7 +2498,7 @@ void tcp_send_probe0(struct sock *sk)
2497 if (icsk->icsk_backoff < sysctl_tcp_retries2) 2498 if (icsk->icsk_backoff < sysctl_tcp_retries2)
2498 icsk->icsk_backoff++; 2499 icsk->icsk_backoff++;
2499 icsk->icsk_probes_out++; 2500 icsk->icsk_probes_out++;
2500 inet_csk_reset_xmit_timer(sk, ICSK_TIME_PROBE0, 2501 inet_csk_reset_xmit_timer(sk, ICSK_TIME_PROBE0,
2501 min(icsk->icsk_rto << icsk->icsk_backoff, TCP_RTO_MAX), 2502 min(icsk->icsk_rto << icsk->icsk_backoff, TCP_RTO_MAX),
2502 TCP_RTO_MAX); 2503 TCP_RTO_MAX);
2503 } else { 2504 } else {
@@ -2509,7 +2510,7 @@ void tcp_send_probe0(struct sock *sk)
2509 */ 2510 */
2510 if (!icsk->icsk_probes_out) 2511 if (!icsk->icsk_probes_out)
2511 icsk->icsk_probes_out = 1; 2512 icsk->icsk_probes_out = 1;
2512 inet_csk_reset_xmit_timer(sk, ICSK_TIME_PROBE0, 2513 inet_csk_reset_xmit_timer(sk, ICSK_TIME_PROBE0,
2513 min(icsk->icsk_rto << icsk->icsk_backoff, 2514 min(icsk->icsk_rto << icsk->icsk_backoff,
2514 TCP_RESOURCE_PROBE_INTERVAL), 2515 TCP_RESOURCE_PROBE_INTERVAL),
2515 TCP_RTO_MAX); 2516 TCP_RTO_MAX);
diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
index 41c157848181..61f406f27294 100644
--- a/net/ipv4/tcp_probe.c
+++ b/net/ipv4/tcp_probe.c
@@ -143,7 +143,7 @@ out_free:
143 return error ? error : cnt; 143 return error ? error : cnt;
144} 144}
145 145
146static struct file_operations tcpprobe_fops = { 146static const struct file_operations tcpprobe_fops = {
147 .owner = THIS_MODULE, 147 .owner = THIS_MODULE,
148 .open = tcpprobe_open, 148 .open = tcpprobe_open,
149 .read = tcpprobe_read, 149 .read = tcpprobe_read,
diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
index 3355c276b611..a9243cfc1bea 100644
--- a/net/ipv4/tcp_timer.c
+++ b/net/ipv4/tcp_timer.c
@@ -69,7 +69,7 @@ static int tcp_out_of_resources(struct sock *sk, int do_reset)
69 struct tcp_sock *tp = tcp_sk(sk); 69 struct tcp_sock *tp = tcp_sk(sk);
70 int orphans = atomic_read(&tcp_orphan_count); 70 int orphans = atomic_read(&tcp_orphan_count);
71 71
72 /* If peer does not open window for long time, or did not transmit 72 /* If peer does not open window for long time, or did not transmit
73 * anything for long time, penalize it. */ 73 * anything for long time, penalize it. */
74 if ((s32)(tcp_time_stamp - tp->lsndtime) > 2*TCP_RTO_MAX || !do_reset) 74 if ((s32)(tcp_time_stamp - tp->lsndtime) > 2*TCP_RTO_MAX || !do_reset)
75 orphans <<= 1; 75 orphans <<= 1;
@@ -137,7 +137,7 @@ static int tcp_write_timeout(struct sock *sk)
137 tcp_sync_mss(sk, icsk->icsk_pmtu_cookie); 137 tcp_sync_mss(sk, icsk->icsk_pmtu_cookie);
138 } else { 138 } else {
139 mss = min(sysctl_tcp_base_mss, 139 mss = min(sysctl_tcp_base_mss,
140 tcp_mtu_to_mss(sk, icsk->icsk_mtup.search_low)/2); 140 tcp_mtu_to_mss(sk, icsk->icsk_mtup.search_low)/2);
141 mss = max(mss, 68 - tp->tcp_header_len); 141 mss = max(mss, 68 - tp->tcp_header_len);
142 icsk->icsk_mtup.search_low = tcp_mss_to_mtu(sk, mss); 142 icsk->icsk_mtup.search_low = tcp_mss_to_mtu(sk, mss);
143 tcp_sync_mss(sk, icsk->icsk_pmtu_cookie); 143 tcp_sync_mss(sk, icsk->icsk_pmtu_cookie);
@@ -150,7 +150,7 @@ static int tcp_write_timeout(struct sock *sk)
150 retry_until = sysctl_tcp_retries2; 150 retry_until = sysctl_tcp_retries2;
151 if (sock_flag(sk, SOCK_DEAD)) { 151 if (sock_flag(sk, SOCK_DEAD)) {
152 const int alive = (icsk->icsk_rto < TCP_RTO_MAX); 152 const int alive = (icsk->icsk_rto < TCP_RTO_MAX);
153 153
154 retry_until = tcp_orphan_retries(sk, alive); 154 retry_until = tcp_orphan_retries(sk, alive);
155 155
156 if (tcp_out_of_resources(sk, alive || icsk->icsk_retransmits < retry_until)) 156 if (tcp_out_of_resources(sk, alive || icsk->icsk_retransmits < retry_until))
@@ -257,7 +257,7 @@ static void tcp_probe_timer(struct sock *sk)
257 257
258 if (sock_flag(sk, SOCK_DEAD)) { 258 if (sock_flag(sk, SOCK_DEAD)) {
259 const int alive = ((icsk->icsk_rto << icsk->icsk_backoff) < TCP_RTO_MAX); 259 const int alive = ((icsk->icsk_rto << icsk->icsk_backoff) < TCP_RTO_MAX);
260 260
261 max_probes = tcp_orphan_retries(sk, alive); 261 max_probes = tcp_orphan_retries(sk, alive);
262 262
263 if (tcp_out_of_resources(sk, alive || icsk->icsk_probes_out <= max_probes)) 263 if (tcp_out_of_resources(sk, alive || icsk->icsk_probes_out <= max_probes))
@@ -453,7 +453,7 @@ static void tcp_keepalive_timer (unsigned long data)
453 /* Only process if socket is not in use. */ 453 /* Only process if socket is not in use. */
454 bh_lock_sock(sk); 454 bh_lock_sock(sk);
455 if (sock_owned_by_user(sk)) { 455 if (sock_owned_by_user(sk)) {
456 /* Try again later. */ 456 /* Try again later. */
457 inet_csk_reset_keepalive_timer (sk, HZ/20); 457 inet_csk_reset_keepalive_timer (sk, HZ/20);
458 goto out; 458 goto out;
459 } 459 }
@@ -515,7 +515,7 @@ resched:
515 inet_csk_reset_keepalive_timer (sk, elapsed); 515 inet_csk_reset_keepalive_timer (sk, elapsed);
516 goto out; 516 goto out;
517 517
518death: 518death:
519 tcp_done(sk); 519 tcp_done(sk);
520 520
521out: 521out:
diff --git a/net/ipv4/tcp_vegas.c b/net/ipv4/tcp_vegas.c
index ddc4bcc5785e..5c484dceb967 100644
--- a/net/ipv4/tcp_vegas.c
+++ b/net/ipv4/tcp_vegas.c
@@ -330,9 +330,9 @@ static void tcp_vegas_cong_avoid(struct sock *sk, u32 ack,
330 vegas->minRTT = 0x7fffffff; 330 vegas->minRTT = 0x7fffffff;
331 } 331 }
332 /* Use normal slow start */ 332 /* Use normal slow start */
333 else if (tp->snd_cwnd <= tp->snd_ssthresh) 333 else if (tp->snd_cwnd <= tp->snd_ssthresh)
334 tcp_slow_start(tp); 334 tcp_slow_start(tp);
335 335
336} 336}
337 337
338/* Extract info for Tcp socket info provided via netlink. */ 338/* Extract info for Tcp socket info provided via netlink. */
diff --git a/net/ipv4/tcp_westwood.c b/net/ipv4/tcp_westwood.c
index 4f42a86c77f3..4e1b61032a9c 100644
--- a/net/ipv4/tcp_westwood.c
+++ b/net/ipv4/tcp_westwood.c
@@ -63,10 +63,10 @@ static void tcp_westwood_init(struct sock *sk)
63 struct westwood *w = inet_csk_ca(sk); 63 struct westwood *w = inet_csk_ca(sk);
64 64
65 w->bk = 0; 65 w->bk = 0;
66 w->bw_ns_est = 0; 66 w->bw_ns_est = 0;
67 w->bw_est = 0; 67 w->bw_est = 0;
68 w->accounted = 0; 68 w->accounted = 0;
69 w->cumul_ack = 0; 69 w->cumul_ack = 0;
70 w->reset_rtt_min = 1; 70 w->reset_rtt_min = 1;
71 w->rtt_min = w->rtt = TCP_WESTWOOD_INIT_RTT; 71 w->rtt_min = w->rtt = TCP_WESTWOOD_INIT_RTT;
72 w->rtt_win_sx = tcp_time_stamp; 72 w->rtt_win_sx = tcp_time_stamp;
@@ -121,7 +121,7 @@ static void westwood_update_window(struct sock *sk)
121 * to fix mismatch between tp->snd_una and w->snd_una for the first 121 * to fix mismatch between tp->snd_una and w->snd_una for the first
122 * bandwidth sample 122 * bandwidth sample
123 */ 123 */
124 if (w->first_ack) { 124 if (w->first_ack) {
125 w->snd_una = tcp_sk(sk)->snd_una; 125 w->snd_una = tcp_sk(sk)->snd_una;
126 w->first_ack = 0; 126 w->first_ack = 0;
127 } 127 }
@@ -147,7 +147,7 @@ static inline void update_rtt_min(struct westwood *w)
147{ 147{
148 if (w->reset_rtt_min) { 148 if (w->reset_rtt_min) {
149 w->rtt_min = w->rtt; 149 w->rtt_min = w->rtt;
150 w->reset_rtt_min = 0; 150 w->reset_rtt_min = 0;
151 } else 151 } else
152 w->rtt_min = min(w->rtt, w->rtt_min); 152 w->rtt_min = min(w->rtt, w->rtt_min);
153} 153}
@@ -183,15 +183,15 @@ static inline u32 westwood_acked_count(struct sock *sk)
183 183
184 w->cumul_ack = tp->snd_una - w->snd_una; 184 w->cumul_ack = tp->snd_una - w->snd_una;
185 185
186 /* If cumul_ack is 0 this is a dupack since it's not moving 186 /* If cumul_ack is 0 this is a dupack since it's not moving
187 * tp->snd_una. 187 * tp->snd_una.
188 */ 188 */
189 if (!w->cumul_ack) { 189 if (!w->cumul_ack) {
190 w->accounted += tp->mss_cache; 190 w->accounted += tp->mss_cache;
191 w->cumul_ack = tp->mss_cache; 191 w->cumul_ack = tp->mss_cache;
192 } 192 }
193 193
194 if (w->cumul_ack > tp->mss_cache) { 194 if (w->cumul_ack > tp->mss_cache) {
195 /* Partial or delayed ack */ 195 /* Partial or delayed ack */
196 if (w->accounted >= w->cumul_ack) { 196 if (w->accounted >= w->cumul_ack) {
197 w->accounted -= w->cumul_ack; 197 w->accounted -= w->cumul_ack;
@@ -237,7 +237,7 @@ static void tcp_westwood_event(struct sock *sk, enum tcp_ca_event event)
237 237
238 case CA_EVENT_FRTO: 238 case CA_EVENT_FRTO:
239 tp->snd_ssthresh = tcp_westwood_bw_rttmin(sk); 239 tp->snd_ssthresh = tcp_westwood_bw_rttmin(sk);
240 /* Update RTT_min when next ack arrives */ 240 /* Update RTT_min when next ack arrives */
241 w->reset_rtt_min = 1; 241 w->reset_rtt_min = 1;
242 break; 242 break;
243 243
diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
index cfff930f2baf..ce6c46034314 100644
--- a/net/ipv4/udp.c
+++ b/net/ipv4/udp.c
@@ -20,8 +20,8 @@
20 * for udp at least is 'valid'. 20 * for udp at least is 'valid'.
21 * Alan Cox : Fixed icmp handling properly 21 * Alan Cox : Fixed icmp handling properly
22 * Alan Cox : Correct error for oversized datagrams 22 * Alan Cox : Correct error for oversized datagrams
23 * Alan Cox : Tidied select() semantics. 23 * Alan Cox : Tidied select() semantics.
24 * Alan Cox : udp_err() fixed properly, also now 24 * Alan Cox : udp_err() fixed properly, also now
25 * select and read wake correctly on errors 25 * select and read wake correctly on errors
26 * Alan Cox : udp_send verify_area moved to avoid mem leak 26 * Alan Cox : udp_send verify_area moved to avoid mem leak
27 * Alan Cox : UDP can count its memory 27 * Alan Cox : UDP can count its memory
@@ -56,7 +56,7 @@
56 * does have a high hit rate. 56 * does have a high hit rate.
57 * Olaf Kirch : Don't linearise iovec on sendmsg. 57 * Olaf Kirch : Don't linearise iovec on sendmsg.
58 * Andi Kleen : Some cleanups, cache destination entry 58 * Andi Kleen : Some cleanups, cache destination entry
59 * for connect. 59 * for connect.
60 * Vitaly E. Lavrov : Transparent proxy revived after year coma. 60 * Vitaly E. Lavrov : Transparent proxy revived after year coma.
61 * Melvin Smith : Check msg_name not msg_namelen in sendto(), 61 * Melvin Smith : Check msg_name not msg_namelen in sendto(),
62 * return ENOTCONN for unconnected sockets (POSIX) 62 * return ENOTCONN for unconnected sockets (POSIX)
@@ -77,7 +77,7 @@
77 * as published by the Free Software Foundation; either version 77 * as published by the Free Software Foundation; either version
78 * 2 of the License, or (at your option) any later version. 78 * 2 of the License, or (at your option) any later version.
79 */ 79 */
80 80
81#include <asm/system.h> 81#include <asm/system.h>
82#include <asm/uaccess.h> 82#include <asm/uaccess.h>
83#include <asm/ioctls.h> 83#include <asm/ioctls.h>
@@ -120,7 +120,7 @@ static inline int __udp_lib_lport_inuse(__u16 num, struct hlist_head udptable[])
120 struct hlist_node *node; 120 struct hlist_node *node;
121 121
122 sk_for_each(sk, node, &udptable[num & (UDP_HTABLE_SIZE - 1)]) 122 sk_for_each(sk, node, &udptable[num & (UDP_HTABLE_SIZE - 1)])
123 if (inet_sk(sk)->num == num) 123 if (sk->sk_hash == num)
124 return 1; 124 return 1;
125 return 0; 125 return 0;
126} 126}
@@ -191,7 +191,7 @@ gotit:
191 head = &udptable[snum & (UDP_HTABLE_SIZE - 1)]; 191 head = &udptable[snum & (UDP_HTABLE_SIZE - 1)];
192 192
193 sk_for_each(sk2, node, head) 193 sk_for_each(sk2, node, head)
194 if (inet_sk(sk2)->num == snum && 194 if (sk2->sk_hash == snum &&
195 sk2 != sk && 195 sk2 != sk &&
196 (!sk2->sk_reuse || !sk->sk_reuse) && 196 (!sk2->sk_reuse || !sk->sk_reuse) &&
197 (!sk2->sk_bound_dev_if || !sk->sk_bound_dev_if 197 (!sk2->sk_bound_dev_if || !sk->sk_bound_dev_if
@@ -200,6 +200,7 @@ gotit:
200 goto fail; 200 goto fail;
201 } 201 }
202 inet_sk(sk)->num = snum; 202 inet_sk(sk)->num = snum;
203 sk->sk_hash = snum;
203 if (sk_unhashed(sk)) { 204 if (sk_unhashed(sk)) {
204 head = &udptable[snum & (UDP_HTABLE_SIZE - 1)]; 205 head = &udptable[snum & (UDP_HTABLE_SIZE - 1)];
205 sk_add_node(sk, head); 206 sk_add_node(sk, head);
@@ -247,7 +248,7 @@ static struct sock *__udp4_lib_lookup(__be32 saddr, __be16 sport,
247 sk_for_each(sk, node, &udptable[hnum & (UDP_HTABLE_SIZE - 1)]) { 248 sk_for_each(sk, node, &udptable[hnum & (UDP_HTABLE_SIZE - 1)]) {
248 struct inet_sock *inet = inet_sk(sk); 249 struct inet_sock *inet = inet_sk(sk);
249 250
250 if (inet->num == hnum && !ipv6_only_sock(sk)) { 251 if (sk->sk_hash == hnum && !ipv6_only_sock(sk)) {
251 int score = (sk->sk_family == PF_INET ? 1 : 0); 252 int score = (sk->sk_family == PF_INET ? 1 : 0);
252 if (inet->rcv_saddr) { 253 if (inet->rcv_saddr) {
253 if (inet->rcv_saddr != daddr) 254 if (inet->rcv_saddr != daddr)
@@ -296,7 +297,7 @@ static inline struct sock *udp_v4_mcast_next(struct sock *sk,
296 sk_for_each_from(s, node) { 297 sk_for_each_from(s, node) {
297 struct inet_sock *inet = inet_sk(s); 298 struct inet_sock *inet = inet_sk(s);
298 299
299 if (inet->num != hnum || 300 if (s->sk_hash != hnum ||
300 (inet->daddr && inet->daddr != rmt_addr) || 301 (inet->daddr && inet->daddr != rmt_addr) ||
301 (inet->dport != rmt_port && inet->dport) || 302 (inet->dport != rmt_port && inet->dport) ||
302 (inet->rcv_saddr && inet->rcv_saddr != loc_addr) || 303 (inet->rcv_saddr && inet->rcv_saddr != loc_addr) ||
@@ -306,17 +307,17 @@ static inline struct sock *udp_v4_mcast_next(struct sock *sk,
306 if (!ip_mc_sf_allow(s, loc_addr, rmt_addr, dif)) 307 if (!ip_mc_sf_allow(s, loc_addr, rmt_addr, dif))
307 continue; 308 continue;
308 goto found; 309 goto found;
309 } 310 }
310 s = NULL; 311 s = NULL;
311found: 312found:
312 return s; 313 return s;
313} 314}
314 315
315/* 316/*
316 * This routine is called by the ICMP module when it gets some 317 * This routine is called by the ICMP module when it gets some
317 * sort of error condition. If err < 0 then the socket should 318 * sort of error condition. If err < 0 then the socket should
318 * be closed and the error returned to the user. If err > 0 319 * be closed and the error returned to the user. If err > 0
319 * it's just the icmp type << 8 | icmp code. 320 * it's just the icmp type << 8 | icmp code.
320 * Header points to the ip header of the error packet. We move 321 * Header points to the ip header of the error packet. We move
321 * on past this. Then (as it used to claim before adjustment) 322 * on past this. Then (as it used to claim before adjustment)
322 * header points to the first 8 bytes of the udp header. We need 323 * header points to the first 8 bytes of the udp header. We need
@@ -338,7 +339,7 @@ void __udp4_lib_err(struct sk_buff *skb, u32 info, struct hlist_head udptable[])
338 skb->dev->ifindex, udptable ); 339 skb->dev->ifindex, udptable );
339 if (sk == NULL) { 340 if (sk == NULL) {
340 ICMP_INC_STATS_BH(ICMP_MIB_INERRORS); 341 ICMP_INC_STATS_BH(ICMP_MIB_INERRORS);
341 return; /* No socket for error */ 342 return; /* No socket for error */
342 } 343 }
343 344
344 err = 0; 345 err = 0;
@@ -374,7 +375,7 @@ void __udp4_lib_err(struct sk_buff *skb, u32 info, struct hlist_head udptable[])
374 } 375 }
375 376
376 /* 377 /*
377 * RFC1122: OK. Passes ICMP errors back to application, as per 378 * RFC1122: OK. Passes ICMP errors back to application, as per
378 * 4.1.3.3. 379 * 4.1.3.3.
379 */ 380 */
380 if (!inet->recverr) { 381 if (!inet->recverr) {
@@ -524,7 +525,7 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
524 if (len > 0xFFFF) 525 if (len > 0xFFFF)
525 return -EMSGSIZE; 526 return -EMSGSIZE;
526 527
527 /* 528 /*
528 * Check the flags. 529 * Check the flags.
529 */ 530 */
530 531
@@ -536,7 +537,7 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
536 if (up->pending) { 537 if (up->pending) {
537 /* 538 /*
538 * There are pending frames. 539 * There are pending frames.
539 * The socket lock must be held while it's corked. 540 * The socket lock must be held while it's corked.
540 */ 541 */
541 lock_sock(sk); 542 lock_sock(sk);
542 if (likely(up->pending)) { 543 if (likely(up->pending)) {
@@ -544,14 +545,14 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
544 release_sock(sk); 545 release_sock(sk);
545 return -EINVAL; 546 return -EINVAL;
546 } 547 }
547 goto do_append_data; 548 goto do_append_data;
548 } 549 }
549 release_sock(sk); 550 release_sock(sk);
550 } 551 }
551 ulen += sizeof(struct udphdr); 552 ulen += sizeof(struct udphdr);
552 553
553 /* 554 /*
554 * Get and verify the address. 555 * Get and verify the address.
555 */ 556 */
556 if (msg->msg_name) { 557 if (msg->msg_name) {
557 struct sockaddr_in * usin = (struct sockaddr_in*)msg->msg_name; 558 struct sockaddr_in * usin = (struct sockaddr_in*)msg->msg_name;
@@ -575,7 +576,7 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
575 Route will not be used, if at least one option is set. 576 Route will not be used, if at least one option is set.
576 */ 577 */
577 connected = 1; 578 connected = 1;
578 } 579 }
579 ipc.addr = inet->saddr; 580 ipc.addr = inet->saddr;
580 581
581 ipc.oif = sk->sk_bound_dev_if; 582 ipc.oif = sk->sk_bound_dev_if;
@@ -601,7 +602,7 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
601 } 602 }
602 tos = RT_TOS(inet->tos); 603 tos = RT_TOS(inet->tos);
603 if (sock_flag(sk, SOCK_LOCALROUTE) || 604 if (sock_flag(sk, SOCK_LOCALROUTE) ||
604 (msg->msg_flags & MSG_DONTROUTE) || 605 (msg->msg_flags & MSG_DONTROUTE) ||
605 (ipc.opt && ipc.opt->is_strictroute)) { 606 (ipc.opt && ipc.opt->is_strictroute)) {
606 tos |= RTO_ONLINK; 607 tos |= RTO_ONLINK;
607 connected = 0; 608 connected = 0;
@@ -629,7 +630,7 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
629 { .sport = inet->sport, 630 { .sport = inet->sport,
630 .dport = dport } } }; 631 .dport = dport } } };
631 security_sk_classify_flow(sk, &fl); 632 security_sk_classify_flow(sk, &fl);
632 err = ip_route_output_flow(&rt, &fl, sk, !(msg->msg_flags&MSG_DONTWAIT)); 633 err = ip_route_output_flow(&rt, &fl, sk, 1);
633 if (err) 634 if (err)
634 goto out; 635 goto out;
635 636
@@ -761,10 +762,10 @@ out:
761/* 762/*
762 * IOCTL requests applicable to the UDP protocol 763 * IOCTL requests applicable to the UDP protocol
763 */ 764 */
764 765
765int udp_ioctl(struct sock *sk, int cmd, unsigned long arg) 766int udp_ioctl(struct sock *sk, int cmd, unsigned long arg)
766{ 767{
767 switch(cmd) 768 switch(cmd)
768 { 769 {
769 case SIOCOUTQ: 770 case SIOCOUTQ:
770 { 771 {
@@ -804,11 +805,11 @@ int udp_ioctl(struct sock *sk, int cmd, unsigned long arg)
804 */ 805 */
805 806
806int udp_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg, 807int udp_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
807 size_t len, int noblock, int flags, int *addr_len) 808 size_t len, int noblock, int flags, int *addr_len)
808{ 809{
809 struct inet_sock *inet = inet_sk(sk); 810 struct inet_sock *inet = inet_sk(sk);
810 struct sockaddr_in *sin = (struct sockaddr_in *)msg->msg_name; 811 struct sockaddr_in *sin = (struct sockaddr_in *)msg->msg_name;
811 struct sk_buff *skb; 812 struct sk_buff *skb;
812 int copied, err, copy_only, is_udplite = IS_UDPLITE(sk); 813 int copied, err, copy_only, is_udplite = IS_UDPLITE(sk);
813 814
814 /* 815 /*
@@ -824,8 +825,8 @@ try_again:
824 skb = skb_recv_datagram(sk, flags, noblock, &err); 825 skb = skb_recv_datagram(sk, flags, noblock, &err);
825 if (!skb) 826 if (!skb)
826 goto out; 827 goto out;
827 828
828 copied = skb->len - sizeof(struct udphdr); 829 copied = skb->len - sizeof(struct udphdr);
829 if (copied > len) { 830 if (copied > len) {
830 copied = len; 831 copied = len;
831 msg->msg_flags |= MSG_TRUNC; 832 msg->msg_flags |= MSG_TRUNC;
@@ -868,18 +869,18 @@ try_again:
868 sin->sin_port = skb->h.uh->source; 869 sin->sin_port = skb->h.uh->source;
869 sin->sin_addr.s_addr = skb->nh.iph->saddr; 870 sin->sin_addr.s_addr = skb->nh.iph->saddr;
870 memset(sin->sin_zero, 0, sizeof(sin->sin_zero)); 871 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
871 } 872 }
872 if (inet->cmsg_flags) 873 if (inet->cmsg_flags)
873 ip_cmsg_recv(msg, skb); 874 ip_cmsg_recv(msg, skb);
874 875
875 err = copied; 876 err = copied;
876 if (flags & MSG_TRUNC) 877 if (flags & MSG_TRUNC)
877 err = skb->len - sizeof(struct udphdr); 878 err = skb->len - sizeof(struct udphdr);
878 879
879out_free: 880out_free:
880 skb_free_datagram(sk, skb); 881 skb_free_datagram(sk, skb);
881out: 882out:
882 return err; 883 return err;
883 884
884csum_copy_err: 885csum_copy_err:
885 UDP_INC_STATS_BH(UDP_MIB_INERRORS, is_udplite); 886 UDP_INC_STATS_BH(UDP_MIB_INERRORS, is_udplite);
@@ -887,7 +888,7 @@ csum_copy_err:
887 skb_kill_datagram(sk, skb, flags); 888 skb_kill_datagram(sk, skb, flags);
888 889
889 if (noblock) 890 if (noblock)
890 return -EAGAIN; 891 return -EAGAIN;
891 goto try_again; 892 goto try_again;
892} 893}
893 894
@@ -898,7 +899,7 @@ int udp_disconnect(struct sock *sk, int flags)
898 /* 899 /*
899 * 1003.1g - break association. 900 * 1003.1g - break association.
900 */ 901 */
901 902
902 sk->sk_state = TCP_CLOSE; 903 sk->sk_state = TCP_CLOSE;
903 inet->daddr = 0; 904 inet->daddr = 0;
904 inet->dport = 0; 905 inet->dport = 0;
@@ -922,13 +923,13 @@ int udp_disconnect(struct sock *sk, int flags)
922static int udp_encap_rcv(struct sock * sk, struct sk_buff *skb) 923static int udp_encap_rcv(struct sock * sk, struct sk_buff *skb)
923{ 924{
924#ifndef CONFIG_XFRM 925#ifndef CONFIG_XFRM
925 return 1; 926 return 1;
926#else 927#else
927 struct udp_sock *up = udp_sk(sk); 928 struct udp_sock *up = udp_sk(sk);
928 struct udphdr *uh; 929 struct udphdr *uh;
929 struct iphdr *iph; 930 struct iphdr *iph;
930 int iphlen, len; 931 int iphlen, len;
931 932
932 __u8 *udpdata; 933 __u8 *udpdata;
933 __be32 *udpdata32; 934 __be32 *udpdata32;
934 __u16 encap_type = up->encap_type; 935 __u16 encap_type = up->encap_type;
@@ -971,7 +972,7 @@ static int udp_encap_rcv(struct sock * sk, struct sk_buff *skb)
971 return 0; 972 return 0;
972 } else if (len > 2 * sizeof(u32) + sizeof(struct ip_esp_hdr) && 973 } else if (len > 2 * sizeof(u32) + sizeof(struct ip_esp_hdr) &&
973 udpdata32[0] == 0 && udpdata32[1] == 0) { 974 udpdata32[0] == 0 && udpdata32[1] == 0) {
974 975
975 /* ESP Packet with Non-IKE marker */ 976 /* ESP Packet with Non-IKE marker */
976 len = sizeof(struct udphdr) + 2 * sizeof(u32); 977 len = sizeof(struct udphdr) + 2 * sizeof(u32);
977 } else 978 } else
@@ -1187,14 +1188,14 @@ static inline void udp4_csum_init(struct sk_buff *skb, struct udphdr *uh)
1187} 1188}
1188 1189
1189/* 1190/*
1190 * All we need to do is get the socket, and then do a checksum. 1191 * All we need to do is get the socket, and then do a checksum.
1191 */ 1192 */
1192 1193
1193int __udp4_lib_rcv(struct sk_buff *skb, struct hlist_head udptable[], 1194int __udp4_lib_rcv(struct sk_buff *skb, struct hlist_head udptable[],
1194 int is_udplite) 1195 int is_udplite)
1195{ 1196{
1196 struct sock *sk; 1197 struct sock *sk;
1197 struct udphdr *uh = skb->h.uh; 1198 struct udphdr *uh = skb->h.uh;
1198 unsigned short ulen; 1199 unsigned short ulen;
1199 struct rtable *rt = (struct rtable*)skb->dst; 1200 struct rtable *rt = (struct rtable*)skb->dst;
1200 __be32 saddr = skb->nh.iph->saddr; 1201 __be32 saddr = skb->nh.iph->saddr;
@@ -1270,9 +1271,9 @@ short_packet:
1270 goto drop; 1271 goto drop;
1271 1272
1272csum_error: 1273csum_error:
1273 /* 1274 /*
1274 * RFC1122: OK. Discards the bad packet silently (as far as 1275 * RFC1122: OK. Discards the bad packet silently (as far as
1275 * the network is concerned, anyway) as per 4.1.3.4 (MUST). 1276 * the network is concerned, anyway) as per 4.1.3.4 (MUST).
1276 */ 1277 */
1277 LIMIT_NETDEBUG(KERN_DEBUG "UDP%s: bad checksum. From %d.%d.%d.%d:%d to %d.%d.%d.%d:%d ulen %d\n", 1278 LIMIT_NETDEBUG(KERN_DEBUG "UDP%s: bad checksum. From %d.%d.%d.%d:%d to %d.%d.%d.%d:%d ulen %d\n",
1278 is_udplite? "-Lite" : "", 1279 is_udplite? "-Lite" : "",
@@ -1328,7 +1329,7 @@ int udp_lib_setsockopt(struct sock *sk, int level, int optname,
1328 release_sock(sk); 1329 release_sock(sk);
1329 } 1330 }
1330 break; 1331 break;
1331 1332
1332 case UDP_ENCAP: 1333 case UDP_ENCAP:
1333 switch (val) { 1334 switch (val) {
1334 case 0: 1335 case 0:
@@ -1356,8 +1357,8 @@ int udp_lib_setsockopt(struct sock *sk, int level, int optname,
1356 up->pcflag |= UDPLITE_SEND_CC; 1357 up->pcflag |= UDPLITE_SEND_CC;
1357 break; 1358 break;
1358 1359
1359 /* The receiver specifies a minimum checksum coverage value. To make 1360 /* The receiver specifies a minimum checksum coverage value. To make
1360 * sense, this should be set to at least 8 (as done below). If zero is 1361 * sense, this should be set to at least 8 (as done below). If zero is
1361 * used, this again means full checksum coverage. */ 1362 * used, this again means full checksum coverage. */
1362 case UDPLITE_RECV_CSCOV: 1363 case UDPLITE_RECV_CSCOV:
1363 if (!up->pcflag) /* Disable the option on UDP sockets */ 1364 if (!up->pcflag) /* Disable the option on UDP sockets */
@@ -1406,7 +1407,7 @@ int udp_lib_getsockopt(struct sock *sk, int level, int optname,
1406 return -EFAULT; 1407 return -EFAULT;
1407 1408
1408 len = min_t(unsigned int, len, sizeof(int)); 1409 len = min_t(unsigned int, len, sizeof(int));
1409 1410
1410 if(len < 0) 1411 if(len < 0)
1411 return -EINVAL; 1412 return -EINVAL;
1412 1413
@@ -1433,11 +1434,11 @@ int udp_lib_getsockopt(struct sock *sk, int level, int optname,
1433 return -ENOPROTOOPT; 1434 return -ENOPROTOOPT;
1434 }; 1435 };
1435 1436
1436 if(put_user(len, optlen)) 1437 if(put_user(len, optlen))
1437 return -EFAULT; 1438 return -EFAULT;
1438 if(copy_to_user(optval, &val,len)) 1439 if(copy_to_user(optval, &val,len))
1439 return -EFAULT; 1440 return -EFAULT;
1440 return 0; 1441 return 0;
1441} 1442}
1442 1443
1443int udp_getsockopt(struct sock *sk, int level, int optname, 1444int udp_getsockopt(struct sock *sk, int level, int optname,
@@ -1463,7 +1464,7 @@ int compat_udp_getsockopt(struct sock *sk, int level, int optname,
1463 * @sock - socket 1464 * @sock - socket
1464 * @wait - poll table 1465 * @wait - poll table
1465 * 1466 *
1466 * This is same as datagram poll, except for the special case of 1467 * This is same as datagram poll, except for the special case of
1467 * blocking sockets. If application is using a blocking fd 1468 * blocking sockets. If application is using a blocking fd
1468 * and a packet with checksum error is in the queue; 1469 * and a packet with checksum error is in the queue;
1469 * then it could get return from select indicating data available 1470 * then it could get return from select indicating data available
@@ -1502,11 +1503,11 @@ unsigned int udp_poll(struct file *file, struct socket *sock, poll_table *wait)
1502 } 1503 }
1503 1504
1504 return mask; 1505 return mask;
1505 1506
1506} 1507}
1507 1508
1508struct proto udp_prot = { 1509struct proto udp_prot = {
1509 .name = "UDP", 1510 .name = "UDP",
1510 .owner = THIS_MODULE, 1511 .owner = THIS_MODULE,
1511 .close = udp_lib_close, 1512 .close = udp_lib_close,
1512 .connect = ip4_datagram_connect, 1513 .connect = ip4_datagram_connect,
@@ -1670,7 +1671,7 @@ static void udp4_format_sock(struct sock *sp, char *tmpbuf, int bucket)
1670 1671
1671 sprintf(tmpbuf, "%4d: %08X:%04X %08X:%04X" 1672 sprintf(tmpbuf, "%4d: %08X:%04X %08X:%04X"
1672 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %lu %d %p", 1673 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %lu %d %p",
1673 bucket, src, srcp, dest, destp, sp->sk_state, 1674 bucket, src, srcp, dest, destp, sp->sk_state,
1674 atomic_read(&sp->sk_wmem_alloc), 1675 atomic_read(&sp->sk_wmem_alloc),
1675 atomic_read(&sp->sk_rmem_alloc), 1676 atomic_read(&sp->sk_rmem_alloc),
1676 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp), 1677 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
diff --git a/net/ipv4/udp_impl.h b/net/ipv4/udp_impl.h
index f6f4277ba6dc..820a477cfaa6 100644
--- a/net/ipv4/udp_impl.h
+++ b/net/ipv4/udp_impl.h
@@ -10,7 +10,7 @@ extern void __udp4_lib_err(struct sk_buff *, u32, struct hlist_head []);
10 10
11extern int __udp_lib_get_port(struct sock *sk, unsigned short snum, 11extern int __udp_lib_get_port(struct sock *sk, unsigned short snum,
12 struct hlist_head udptable[], int *port_rover, 12 struct hlist_head udptable[], int *port_rover,
13 int (*)(const struct sock*,const struct sock*)); 13 int (*)(const struct sock*,const struct sock*));
14extern int ipv4_rcv_saddr_equal(const struct sock *, const struct sock *); 14extern int ipv4_rcv_saddr_equal(const struct sock *, const struct sock *);
15 15
16 16
diff --git a/net/ipv4/xfrm4_input.c b/net/ipv4/xfrm4_input.c
index 8655d038364c..289146bdb8b0 100644
--- a/net/ipv4/xfrm4_input.c
+++ b/net/ipv4/xfrm4_input.c
@@ -6,7 +6,7 @@
6 * Split up af-specific portion 6 * Split up af-specific portion
7 * Derek Atkins <derek@ihtfp.com> 7 * Derek Atkins <derek@ihtfp.com>
8 * Add Encapsulation support 8 * Add Encapsulation support
9 * 9 *
10 */ 10 */
11 11
12#include <linux/module.h> 12#include <linux/module.h>
@@ -42,7 +42,7 @@ static inline int xfrm4_rcv_encap_finish(struct sk_buff *skb)
42 42
43 if (skb->dst == NULL) { 43 if (skb->dst == NULL) {
44 if (ip_route_input(skb, iph->daddr, iph->saddr, iph->tos, 44 if (ip_route_input(skb, iph->daddr, iph->saddr, iph->tos,
45 skb->dev)) 45 skb->dev))
46 goto drop; 46 goto drop;
47 } 47 }
48 return dst_input(skb); 48 return dst_input(skb);
@@ -149,7 +149,7 @@ int xfrm4_rcv_encap(struct sk_buff *skb, __u16 encap_type)
149 ip_send_check(skb->nh.iph); 149 ip_send_check(skb->nh.iph);
150 150
151 NF_HOOK(PF_INET, NF_IP_PRE_ROUTING, skb, skb->dev, NULL, 151 NF_HOOK(PF_INET, NF_IP_PRE_ROUTING, skb, skb->dev, NULL,
152 xfrm4_rcv_encap_finish); 152 xfrm4_rcv_encap_finish);
153 return 0; 153 return 0;
154#else 154#else
155 return -skb->nh.iph->protocol; 155 return -skb->nh.iph->protocol;
diff --git a/net/ipv4/xfrm4_mode_tunnel.c b/net/ipv4/xfrm4_mode_tunnel.c
index e23c21d31a53..e54c5494c88f 100644
--- a/net/ipv4/xfrm4_mode_tunnel.c
+++ b/net/ipv4/xfrm4_mode_tunnel.c
@@ -23,6 +23,12 @@ static inline void ipip_ecn_decapsulate(struct sk_buff *skb)
23 IP_ECN_set_ce(inner_iph); 23 IP_ECN_set_ce(inner_iph);
24} 24}
25 25
26static inline void ipip6_ecn_decapsulate(struct iphdr *iph, struct sk_buff *skb)
27{
28 if (INET_ECN_is_ce(iph->tos))
29 IP6_ECN_set_ce(skb->nh.ipv6h);
30}
31
26/* Add encapsulation header. 32/* Add encapsulation header.
27 * 33 *
28 * The top IP header will be constructed per RFC 2401. The following fields 34 * The top IP header will be constructed per RFC 2401. The following fields
@@ -36,6 +42,7 @@ static inline void ipip_ecn_decapsulate(struct sk_buff *skb)
36static int xfrm4_tunnel_output(struct xfrm_state *x, struct sk_buff *skb) 42static int xfrm4_tunnel_output(struct xfrm_state *x, struct sk_buff *skb)
37{ 43{
38 struct dst_entry *dst = skb->dst; 44 struct dst_entry *dst = skb->dst;
45 struct xfrm_dst *xdst = (struct xfrm_dst*)dst;
39 struct iphdr *iph, *top_iph; 46 struct iphdr *iph, *top_iph;
40 int flags; 47 int flags;
41 48
@@ -48,15 +55,27 @@ static int xfrm4_tunnel_output(struct xfrm_state *x, struct sk_buff *skb)
48 top_iph->ihl = 5; 55 top_iph->ihl = 5;
49 top_iph->version = 4; 56 top_iph->version = 4;
50 57
58 flags = x->props.flags;
59
51 /* DS disclosed */ 60 /* DS disclosed */
52 top_iph->tos = INET_ECN_encapsulate(iph->tos, iph->tos); 61 if (xdst->route->ops->family == AF_INET) {
62 top_iph->protocol = IPPROTO_IPIP;
63 top_iph->tos = INET_ECN_encapsulate(iph->tos, iph->tos);
64 top_iph->frag_off = (flags & XFRM_STATE_NOPMTUDISC) ?
65 0 : (iph->frag_off & htons(IP_DF));
66 }
67#if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
68 else {
69 struct ipv6hdr *ipv6h = (struct ipv6hdr*)iph;
70 top_iph->protocol = IPPROTO_IPV6;
71 top_iph->tos = INET_ECN_encapsulate(iph->tos, ipv6_get_dsfield(ipv6h));
72 top_iph->frag_off = 0;
73 }
74#endif
53 75
54 flags = x->props.flags;
55 if (flags & XFRM_STATE_NOECN) 76 if (flags & XFRM_STATE_NOECN)
56 IP_ECN_clear(top_iph); 77 IP_ECN_clear(top_iph);
57 78
58 top_iph->frag_off = (flags & XFRM_STATE_NOPMTUDISC) ?
59 0 : (iph->frag_off & htons(IP_DF));
60 if (!top_iph->frag_off) 79 if (!top_iph->frag_off)
61 __ip_select_ident(top_iph, dst->child, 0); 80 __ip_select_ident(top_iph, dst->child, 0);
62 81
@@ -64,7 +83,6 @@ static int xfrm4_tunnel_output(struct xfrm_state *x, struct sk_buff *skb)
64 83
65 top_iph->saddr = x->props.saddr.a4; 84 top_iph->saddr = x->props.saddr.a4;
66 top_iph->daddr = x->id.daddr.a4; 85 top_iph->daddr = x->id.daddr.a4;
67 top_iph->protocol = IPPROTO_IPIP;
68 86
69 memset(&(IPCB(skb)->opt), 0, sizeof(struct ip_options)); 87 memset(&(IPCB(skb)->opt), 0, sizeof(struct ip_options));
70 return 0; 88 return 0;
@@ -75,8 +93,16 @@ static int xfrm4_tunnel_input(struct xfrm_state *x, struct sk_buff *skb)
75 struct iphdr *iph = skb->nh.iph; 93 struct iphdr *iph = skb->nh.iph;
76 int err = -EINVAL; 94 int err = -EINVAL;
77 95
78 if (iph->protocol != IPPROTO_IPIP) 96 switch(iph->protocol){
79 goto out; 97 case IPPROTO_IPIP:
98#if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
99 case IPPROTO_IPV6:
100 break;
101#endif
102 default:
103 goto out;
104 }
105
80 if (!pskb_may_pull(skb, sizeof(struct iphdr))) 106 if (!pskb_may_pull(skb, sizeof(struct iphdr)))
81 goto out; 107 goto out;
82 108
@@ -84,10 +110,19 @@ static int xfrm4_tunnel_input(struct xfrm_state *x, struct sk_buff *skb)
84 (err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC))) 110 (err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC)))
85 goto out; 111 goto out;
86 112
87 if (x->props.flags & XFRM_STATE_DECAP_DSCP) 113 if (iph->protocol == IPPROTO_IPIP) {
88 ipv4_copy_dscp(iph, skb->h.ipiph); 114 if (x->props.flags & XFRM_STATE_DECAP_DSCP)
89 if (!(x->props.flags & XFRM_STATE_NOECN)) 115 ipv4_copy_dscp(iph, skb->h.ipiph);
90 ipip_ecn_decapsulate(skb); 116 if (!(x->props.flags & XFRM_STATE_NOECN))
117 ipip_ecn_decapsulate(skb);
118 }
119#if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
120 else {
121 if (!(x->props.flags & XFRM_STATE_NOECN))
122 ipip6_ecn_decapsulate(iph, skb);
123 skb->protocol = htons(ETH_P_IPV6);
124 }
125#endif
91 skb->mac.raw = memmove(skb->data - skb->mac_len, 126 skb->mac.raw = memmove(skb->data - skb->mac_len,
92 skb->mac.raw, skb->mac_len); 127 skb->mac.raw, skb->mac_len);
93 skb->nh.raw = skb->data; 128 skb->nh.raw = skb->data;
diff --git a/net/ipv4/xfrm4_output.c b/net/ipv4/xfrm4_output.c
index 04403fb01a58..038ca160fe2c 100644
--- a/net/ipv4/xfrm4_output.c
+++ b/net/ipv4/xfrm4_output.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * xfrm4_output.c - Common IPsec encapsulation code for IPv4. 2 * xfrm4_output.c - Common IPsec encapsulation code for IPv4.
3 * Copyright (c) 2004 Herbert Xu <herbert@gondor.apana.org.au> 3 * Copyright (c) 2004 Herbert Xu <herbert@gondor.apana.org.au>
4 * 4 *
5 * This program is free software; you can redistribute it and/or 5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License 6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 7 * as published by the Free Software Foundation; either version
@@ -28,7 +28,7 @@ static int xfrm4_tunnel_check_size(struct sk_buff *skb)
28 goto out; 28 goto out;
29 29
30 IPCB(skb)->flags |= IPSKB_XFRM_TUNNEL_SIZE; 30 IPCB(skb)->flags |= IPSKB_XFRM_TUNNEL_SIZE;
31 31
32 if (!(iph->frag_off & htons(IP_DF)) || skb->local_df) 32 if (!(iph->frag_off & htons(IP_DF)) || skb->local_df)
33 goto out; 33 goto out;
34 34
@@ -47,7 +47,7 @@ static int xfrm4_output_one(struct sk_buff *skb)
47 struct dst_entry *dst = skb->dst; 47 struct dst_entry *dst = skb->dst;
48 struct xfrm_state *x = dst->xfrm; 48 struct xfrm_state *x = dst->xfrm;
49 int err; 49 int err;
50 50
51 if (skb->ip_summed == CHECKSUM_PARTIAL) { 51 if (skb->ip_summed == CHECKSUM_PARTIAL) {
52 err = skb_checksum_help(skb); 52 err = skb_checksum_help(skb);
53 if (err) 53 if (err)
@@ -78,7 +78,7 @@ static int xfrm4_output_one(struct sk_buff *skb)
78 x->curlft.packets++; 78 x->curlft.packets++;
79 79
80 spin_unlock_bh(&x->lock); 80 spin_unlock_bh(&x->lock);
81 81
82 if (!(skb->dst = dst_pop(dst))) { 82 if (!(skb->dst = dst_pop(dst))) {
83 err = -EHOSTUNREACH; 83 err = -EHOSTUNREACH;
84 goto error_nolock; 84 goto error_nolock;
diff --git a/net/ipv4/xfrm4_policy.c b/net/ipv4/xfrm4_policy.c
index fb9f69c616f5..fef19c6bcb98 100644
--- a/net/ipv4/xfrm4_policy.c
+++ b/net/ipv4/xfrm4_policy.c
@@ -1,11 +1,11 @@
1/* 1/*
2 * xfrm4_policy.c 2 * xfrm4_policy.c
3 * 3 *
4 * Changes: 4 * Changes:
5 * Kazunori MIYAZAWA @USAGI 5 * Kazunori MIYAZAWA @USAGI
6 * YOSHIFUJI Hideaki @USAGI 6 * YOSHIFUJI Hideaki @USAGI
7 * Split up af-specific portion 7 * Split up af-specific portion
8 * 8 *
9 */ 9 */
10 10
11#include <linux/compiler.h> 11#include <linux/compiler.h>
@@ -50,8 +50,8 @@ __xfrm4_find_bundle(struct flowi *fl, struct xfrm_policy *policy)
50 struct xfrm_dst *xdst = (struct xfrm_dst*)dst; 50 struct xfrm_dst *xdst = (struct xfrm_dst*)dst;
51 if (xdst->u.rt.fl.oif == fl->oif && /*XXX*/ 51 if (xdst->u.rt.fl.oif == fl->oif && /*XXX*/
52 xdst->u.rt.fl.fl4_dst == fl->fl4_dst && 52 xdst->u.rt.fl.fl4_dst == fl->fl4_dst &&
53 xdst->u.rt.fl.fl4_src == fl->fl4_src && 53 xdst->u.rt.fl.fl4_src == fl->fl4_src &&
54 xdst->u.rt.fl.fl4_tos == fl->fl4_tos && 54 xdst->u.rt.fl.fl4_tos == fl->fl4_tos &&
55 xfrm_bundle_ok(policy, xdst, fl, AF_INET, 0)) { 55 xfrm_bundle_ok(policy, xdst, fl, AF_INET, 0)) {
56 dst_clone(dst); 56 dst_clone(dst);
57 break; 57 break;
@@ -72,13 +72,11 @@ __xfrm4_bundle_create(struct xfrm_policy *policy, struct xfrm_state **xfrm, int
72 struct dst_entry *dst, *dst_prev; 72 struct dst_entry *dst, *dst_prev;
73 struct rtable *rt0 = (struct rtable*)(*dst_p); 73 struct rtable *rt0 = (struct rtable*)(*dst_p);
74 struct rtable *rt = rt0; 74 struct rtable *rt = rt0;
75 __be32 remote = fl->fl4_dst;
76 __be32 local = fl->fl4_src;
77 struct flowi fl_tunnel = { 75 struct flowi fl_tunnel = {
78 .nl_u = { 76 .nl_u = {
79 .ip4_u = { 77 .ip4_u = {
80 .saddr = local, 78 .saddr = fl->fl4_src,
81 .daddr = remote, 79 .daddr = fl->fl4_dst,
82 .tos = fl->fl4_tos 80 .tos = fl->fl4_tos
83 } 81 }
84 } 82 }
@@ -94,7 +92,6 @@ __xfrm4_bundle_create(struct xfrm_policy *policy, struct xfrm_state **xfrm, int
94 for (i = 0; i < nx; i++) { 92 for (i = 0; i < nx; i++) {
95 struct dst_entry *dst1 = dst_alloc(&xfrm4_dst_ops); 93 struct dst_entry *dst1 = dst_alloc(&xfrm4_dst_ops);
96 struct xfrm_dst *xdst; 94 struct xfrm_dst *xdst;
97 int tunnel = 0;
98 95
99 if (unlikely(dst1 == NULL)) { 96 if (unlikely(dst1 == NULL)) {
100 err = -ENOBUFS; 97 err = -ENOBUFS;
@@ -116,19 +113,28 @@ __xfrm4_bundle_create(struct xfrm_policy *policy, struct xfrm_state **xfrm, int
116 113
117 dst1->next = dst_prev; 114 dst1->next = dst_prev;
118 dst_prev = dst1; 115 dst_prev = dst1;
119 if (xfrm[i]->props.mode != XFRM_MODE_TRANSPORT) { 116
120 remote = xfrm[i]->id.daddr.a4;
121 local = xfrm[i]->props.saddr.a4;
122 tunnel = 1;
123 }
124 header_len += xfrm[i]->props.header_len; 117 header_len += xfrm[i]->props.header_len;
125 trailer_len += xfrm[i]->props.trailer_len; 118 trailer_len += xfrm[i]->props.trailer_len;
126 119
127 if (tunnel) { 120 if (xfrm[i]->props.mode == XFRM_MODE_TUNNEL) {
128 fl_tunnel.fl4_src = local; 121 unsigned short encap_family = xfrm[i]->props.family;
129 fl_tunnel.fl4_dst = remote; 122 switch(encap_family) {
123 case AF_INET:
124 fl_tunnel.fl4_dst = xfrm[i]->id.daddr.a4;
125 fl_tunnel.fl4_src = xfrm[i]->props.saddr.a4;
126 break;
127#if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
128 case AF_INET6:
129 ipv6_addr_copy(&fl_tunnel.fl6_dst, (struct in6_addr*)&xfrm[i]->id.daddr.a6);
130 ipv6_addr_copy(&fl_tunnel.fl6_src, (struct in6_addr*)&xfrm[i]->props.saddr.a6);
131 break;
132#endif
133 default:
134 BUG_ON(1);
135 }
130 err = xfrm_dst_lookup((struct xfrm_dst **)&rt, 136 err = xfrm_dst_lookup((struct xfrm_dst **)&rt,
131 &fl_tunnel, AF_INET); 137 &fl_tunnel, encap_family);
132 if (err) 138 if (err)
133 goto error; 139 goto error;
134 } else 140 } else
@@ -145,6 +151,7 @@ __xfrm4_bundle_create(struct xfrm_policy *policy, struct xfrm_state **xfrm, int
145 i = 0; 151 i = 0;
146 for (; dst_prev != &rt->u.dst; dst_prev = dst_prev->child) { 152 for (; dst_prev != &rt->u.dst; dst_prev = dst_prev->child) {
147 struct xfrm_dst *x = (struct xfrm_dst*)dst_prev; 153 struct xfrm_dst *x = (struct xfrm_dst*)dst_prev;
154 struct xfrm_state_afinfo *afinfo;
148 x->u.rt.fl = *fl; 155 x->u.rt.fl = *fl;
149 156
150 dst_prev->xfrm = xfrm[i++]; 157 dst_prev->xfrm = xfrm[i++];
@@ -162,8 +169,18 @@ __xfrm4_bundle_create(struct xfrm_policy *policy, struct xfrm_state **xfrm, int
162 /* Copy neighbout for reachability confirmation */ 169 /* Copy neighbout for reachability confirmation */
163 dst_prev->neighbour = neigh_clone(rt->u.dst.neighbour); 170 dst_prev->neighbour = neigh_clone(rt->u.dst.neighbour);
164 dst_prev->input = rt->u.dst.input; 171 dst_prev->input = rt->u.dst.input;
165 dst_prev->output = xfrm4_output; 172 /* XXX: When IPv6 module can be unloaded, we should manage reference
166 if (rt->peer) 173 * to xfrm6_output in afinfo->output. Miyazawa
174 * */
175 afinfo = xfrm_state_get_afinfo(dst_prev->xfrm->props.family);
176 if (!afinfo) {
177 dst = *dst_p;
178 err = -EAFNOSUPPORT;
179 goto error;
180 }
181 dst_prev->output = afinfo->output;
182 xfrm_state_put_afinfo(afinfo);
183 if (dst_prev->xfrm->props.family == AF_INET && rt->peer)
167 atomic_inc(&rt->peer->refcnt); 184 atomic_inc(&rt->peer->refcnt);
168 x->u.rt.peer = rt->peer; 185 x->u.rt.peer = rt->peer;
169 /* Sheit... I remember I did this right. Apparently, 186 /* Sheit... I remember I did this right. Apparently,
@@ -274,7 +291,7 @@ static void xfrm4_dst_destroy(struct dst_entry *dst)
274 291
275 if (likely(xdst->u.rt.idev)) 292 if (likely(xdst->u.rt.idev))
276 in_dev_put(xdst->u.rt.idev); 293 in_dev_put(xdst->u.rt.idev);
277 if (likely(xdst->u.rt.peer)) 294 if (dst->xfrm->props.family == AF_INET && likely(xdst->u.rt.peer))
278 inet_putpeer(xdst->u.rt.peer); 295 inet_putpeer(xdst->u.rt.peer);
279 xfrm_dst_destroy(xdst); 296 xfrm_dst_destroy(xdst);
280} 297}
diff --git a/net/ipv4/xfrm4_state.c b/net/ipv4/xfrm4_state.c
index 3cc3df0c6ece..93e2c061cdda 100644
--- a/net/ipv4/xfrm4_state.c
+++ b/net/ipv4/xfrm4_state.c
@@ -51,6 +51,7 @@ static struct xfrm_state_afinfo xfrm4_state_afinfo = {
51 .family = AF_INET, 51 .family = AF_INET,
52 .init_flags = xfrm4_init_flags, 52 .init_flags = xfrm4_init_flags,
53 .init_tempsel = __xfrm4_init_tempsel, 53 .init_tempsel = __xfrm4_init_tempsel,
54 .output = xfrm4_output,
54}; 55};
55 56
56void __init xfrm4_state_init(void) 57void __init xfrm4_state_init(void)
diff --git a/net/ipv4/xfrm4_tunnel.c b/net/ipv4/xfrm4_tunnel.c
index f110af5b1319..1be6762b2d47 100644
--- a/net/ipv4/xfrm4_tunnel.c
+++ b/net/ipv4/xfrm4_tunnel.c
@@ -13,7 +13,7 @@
13static int ipip_output(struct xfrm_state *x, struct sk_buff *skb) 13static int ipip_output(struct xfrm_state *x, struct sk_buff *skb)
14{ 14{
15 struct iphdr *iph; 15 struct iphdr *iph;
16 16
17 iph = skb->nh.iph; 17 iph = skb->nh.iph;
18 iph->tot_len = htons(skb->len); 18 iph->tot_len = htons(skb->len);
19 ip_send_check(iph); 19 ip_send_check(iph);