aboutsummaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorDmitry Torokhov <dmitry.torokhov@gmail.com>2009-11-03 01:10:07 -0500
committerDmitry Torokhov <dmitry.torokhov@gmail.com>2009-11-03 01:10:07 -0500
commit7a53c7f56bbfc9b0ef892e68f5cfae3d902544d1 (patch)
tree19dec256fc80ad06d631ece78b9eb68a457ce66b /net
parente57130698fe3dd2b7d617d90bbf86474473cb40c (diff)
parent012abeea669ea49636cf952d13298bb68654146a (diff)
Merge commit 'v2.6.32-rc5' into for-linus
Diffstat (limited to 'net')
-rw-r--r--net/8021q/vlan_netlink.c1
-rw-r--r--net/9p/trans_virtio.c5
-rw-r--r--net/appletalk/ddp.c2
-rw-r--r--net/atm/common.c2
-rw-r--r--net/atm/common.h2
-rw-r--r--net/atm/pvc.c2
-rw-r--r--net/atm/svc.c2
-rw-r--r--net/ax25/af_ax25.c54
-rw-r--r--net/bluetooth/hci_sock.c2
-rw-r--r--net/bluetooth/hci_sysfs.c4
-rw-r--r--net/bluetooth/hidp/core.c7
-rw-r--r--net/bluetooth/l2cap.c4
-rw-r--r--net/bluetooth/rfcomm/sock.c4
-rw-r--r--net/bluetooth/sco.c2
-rw-r--r--net/bridge/br_if.c1
-rw-r--r--net/bridge/br_netfilter.c4
-rw-r--r--net/can/af_can.c4
-rw-r--r--net/can/raw.c2
-rw-r--r--net/compat.c12
-rw-r--r--net/core/dev.c10
-rw-r--r--net/core/net-sysfs.c18
-rw-r--r--net/core/pktgen.c170
-rw-r--r--net/core/sock.c31
-rw-r--r--net/dcb/dcbnl.c15
-rw-r--r--net/dccp/ccids/Kconfig6
-rw-r--r--net/dccp/ccids/ccid2.c2
-rw-r--r--net/dccp/ccids/ccid2.h8
-rw-r--r--net/dccp/ccids/ccid3.c5
-rw-r--r--net/dccp/ccids/ccid3.h50
-rw-r--r--net/dccp/ccids/lib/loss_interval.c7
-rw-r--r--net/dccp/ccids/lib/loss_interval.h2
-rw-r--r--net/dccp/ccids/lib/packet_history.c4
-rw-r--r--net/dccp/ccids/lib/packet_history.h1
-rw-r--r--net/dccp/ccids/lib/tfrc.h4
-rw-r--r--net/dccp/ccids/lib/tfrc_equation.c26
-rw-r--r--net/dccp/dccp.h4
-rw-r--r--net/dccp/ipv4.c2
-rw-r--r--net/dccp/ipv6.c4
-rw-r--r--net/dccp/proto.c16
-rw-r--r--net/decnet/af_decnet.c6
-rw-r--r--net/decnet/dn_dev.c5
-rw-r--r--net/decnet/dn_route.c2
-rw-r--r--net/decnet/sysctl_net_decnet.c2
-rw-r--r--net/ieee802154/dgram.c2
-rw-r--r--net/ieee802154/netlink.c4
-rw-r--r--net/ieee802154/raw.c2
-rw-r--r--net/ipv4/af_inet.c19
-rw-r--r--net/ipv4/ah4.c2
-rw-r--r--net/ipv4/devinet.c34
-rw-r--r--net/ipv4/esp4.c2
-rw-r--r--net/ipv4/icmp.c2
-rw-r--r--net/ipv4/igmp.c22
-rw-r--r--net/ipv4/inet_connection_sock.c2
-rw-r--r--net/ipv4/ip_gre.c15
-rw-r--r--net/ipv4/ip_input.c2
-rw-r--r--net/ipv4/ip_output.c1
-rw-r--r--net/ipv4/ip_sockglue.c9
-rw-r--r--net/ipv4/ipcomp.c2
-rw-r--r--net/ipv4/ipip.c8
-rw-r--r--net/ipv4/ipmr.c8
-rw-r--r--net/ipv4/protocol.c6
-rw-r--r--net/ipv4/raw.c6
-rw-r--r--net/ipv4/route.c9
-rw-r--r--net/ipv4/sysctl_net_ipv4.c16
-rw-r--r--net/ipv4/tcp.c16
-rw-r--r--net/ipv4/tcp_input.c2
-rw-r--r--net/ipv4/tcp_ipv4.c4
-rw-r--r--net/ipv4/tcp_minisocks.c5
-rw-r--r--net/ipv4/tcp_output.c11
-rw-r--r--net/ipv4/tunnel4.c4
-rw-r--r--net/ipv4/udp.c80
-rw-r--r--net/ipv4/udp_impl.h4
-rw-r--r--net/ipv4/udplite.c2
-rw-r--r--net/ipv6/addrconf.c31
-rw-r--r--net/ipv6/af_inet6.c10
-rw-r--r--net/ipv6/ah6.c2
-rw-r--r--net/ipv6/esp6.c2
-rw-r--r--net/ipv6/exthdrs.c6
-rw-r--r--net/ipv6/icmp.c4
-rw-r--r--net/ipv6/ip6_input.c2
-rw-r--r--net/ipv6/ip6_tunnel.c7
-rw-r--r--net/ipv6/ip6mr.c10
-rw-r--r--net/ipv6/ipcomp6.c2
-rw-r--r--net/ipv6/ipv6_sockglue.c6
-rw-r--r--net/ipv6/mcast.c19
-rw-r--r--net/ipv6/ndisc.c9
-rw-r--r--net/ipv6/protocol.c6
-rw-r--r--net/ipv6/raw.c6
-rw-r--r--net/ipv6/reassembly.c2
-rw-r--r--net/ipv6/route.c6
-rw-r--r--net/ipv6/sit.c68
-rw-r--r--net/ipv6/tcp_ipv6.c7
-rw-r--r--net/ipv6/tunnel6.c4
-rw-r--r--net/ipv6/udp.c6
-rw-r--r--net/ipv6/udp_impl.h4
-rw-r--r--net/ipv6/udplite.c2
-rw-r--r--net/ipx/af_ipx.c2
-rw-r--r--net/irda/af_irda.c2
-rw-r--r--net/irda/ircomm/ircomm_tty_attach.c1
-rw-r--r--net/irda/irlan/irlan_common.c1
-rw-r--r--net/irda/irlan/irlan_eth.c1
-rw-r--r--net/irda/irnet/irnet_irda.c1
-rw-r--r--net/irda/irnet/irnet_ppp.c1
-rw-r--r--net/irda/irsysctl.c8
-rw-r--r--net/iucv/af_iucv.c35
-rw-r--r--net/iucv/iucv.c38
-rw-r--r--net/llc/af_llc.c2
-rw-r--r--net/mac80211/ibss.c4
-rw-r--r--net/mac80211/mlme.c18
-rw-r--r--net/mac80211/rc80211_minstrel.c2
-rw-r--r--net/mac80211/rc80211_pid_debugfs.c1
-rw-r--r--net/mac80211/rx.c12
-rw-r--r--net/mac80211/scan.c4
-rw-r--r--net/mac80211/sta_info.c2
-rw-r--r--net/mac80211/tx.c8
-rw-r--r--net/mac80211/util.c4
-rw-r--r--net/netfilter/ipvs/ip_vs_ctl.c8
-rw-r--r--net/netfilter/nf_conntrack_core.c5
-rw-r--r--net/netfilter/nf_log.c4
-rw-r--r--net/netfilter/nf_sockopt.c4
-rw-r--r--net/netfilter/x_tables.c2
-rw-r--r--net/netfilter/xt_hashlimit.c8
-rw-r--r--net/netlink/af_netlink.c80
-rw-r--r--net/netlink/genetlink.c9
-rw-r--r--net/netrom/af_netrom.c2
-rw-r--r--net/packet/af_packet.c4
-rw-r--r--net/phonet/af_phonet.c6
-rw-r--r--net/phonet/pep.c2
-rw-r--r--net/phonet/pn_dev.c9
-rw-r--r--net/phonet/socket.c17
-rw-r--r--net/phonet/sysctl.c4
-rw-r--r--net/rds/af_rds.c4
-rw-r--r--net/rfkill/core.c1
-rw-r--r--net/rose/af_rose.c6
-rw-r--r--net/rxrpc/af_rxrpc.c2
-rw-r--r--net/rxrpc/ar-ack.c6
-rw-r--r--net/rxrpc/ar-call.c2
-rw-r--r--net/rxrpc/ar-internal.h32
-rw-r--r--net/rxrpc/ar-key.c914
-rw-r--r--net/rxrpc/ar-security.c8
-rw-r--r--net/rxrpc/rxkad.c47
-rw-r--r--net/sched/act_pedit.c2
-rw-r--r--net/sched/cls_api.c2
-rw-r--r--net/sched/sch_api.c29
-rw-r--r--net/sched/sch_drr.c4
-rw-r--r--net/sched/sch_hfsc.c2
-rw-r--r--net/sched/sch_mq.c14
-rw-r--r--net/sched/sch_multiq.c1
-rw-r--r--net/sched/sch_prio.c1
-rw-r--r--net/sctp/ipv6.c2
-rw-r--r--net/sctp/protocol.c8
-rw-r--r--net/sctp/socket.c62
-rw-r--r--net/socket.c15
-rw-r--r--net/sunrpc/auth.c20
-rw-r--r--net/sunrpc/auth_generic.c4
-rw-r--r--net/sunrpc/auth_gss/svcauth_gss.c6
-rw-r--r--net/sunrpc/auth_null.c1
-rw-r--r--net/sunrpc/cache.c109
-rw-r--r--net/sunrpc/clnt.c6
-rw-r--r--net/sunrpc/rpc_pipe.c5
-rw-r--r--net/sunrpc/sched.c7
-rw-r--r--net/sunrpc/sunrpc.h14
-rw-r--r--net/sunrpc/svc_xprt.c25
-rw-r--r--net/sunrpc/svcauth_unix.c1
-rw-r--r--net/sunrpc/svcsock.c335
-rw-r--r--net/sunrpc/sysctl.c4
-rw-r--r--net/sunrpc/xprt.c15
-rw-r--r--net/sunrpc/xprtrdma/svc_rdma.c2
-rw-r--r--net/sunrpc/xprtrdma/svc_rdma_transport.c5
-rw-r--r--net/sunrpc/xprtsock.c251
-rw-r--r--net/tipc/socket.c2
-rw-r--r--net/wireless/core.c1
-rw-r--r--net/wireless/nl80211.c3
-rw-r--r--net/wireless/scan.c7
-rw-r--r--net/wireless/sme.c24
-rw-r--r--net/wireless/wext-compat.c2
-rw-r--r--net/wireless/wext-sme.c8
-rw-r--r--net/wireless/wext.c11
-rw-r--r--net/x25/af_x25.c2
179 files changed, 2367 insertions, 1016 deletions
diff --git a/net/8021q/vlan_netlink.c b/net/8021q/vlan_netlink.c
index 343146e1bceb..a91504850195 100644
--- a/net/8021q/vlan_netlink.c
+++ b/net/8021q/vlan_netlink.c
@@ -169,6 +169,7 @@ static size_t vlan_get_size(const struct net_device *dev)
169 struct vlan_dev_info *vlan = vlan_dev_info(dev); 169 struct vlan_dev_info *vlan = vlan_dev_info(dev);
170 170
171 return nla_total_size(2) + /* IFLA_VLAN_ID */ 171 return nla_total_size(2) + /* IFLA_VLAN_ID */
172 sizeof(struct ifla_vlan_flags) + /* IFLA_VLAN_FLAGS */
172 vlan_qos_map_size(vlan->nr_ingress_mappings) + 173 vlan_qos_map_size(vlan->nr_ingress_mappings) +
173 vlan_qos_map_size(vlan->nr_egress_mappings); 174 vlan_qos_map_size(vlan->nr_egress_mappings);
174} 175}
diff --git a/net/9p/trans_virtio.c b/net/9p/trans_virtio.c
index 9bf0b737aa51..b2e07f0dd298 100644
--- a/net/9p/trans_virtio.c
+++ b/net/9p/trans_virtio.c
@@ -43,6 +43,7 @@
43#include <net/9p/transport.h> 43#include <net/9p/transport.h>
44#include <linux/scatterlist.h> 44#include <linux/scatterlist.h>
45#include <linux/virtio.h> 45#include <linux/virtio.h>
46#include <linux/virtio_ids.h>
46#include <linux/virtio_9p.h> 47#include <linux/virtio_9p.h>
47 48
48#define VIRTQUEUE_NUM 128 49#define VIRTQUEUE_NUM 128
@@ -200,7 +201,7 @@ p9_virtio_request(struct p9_client *client, struct p9_req_t *req)
200 201
201 req->status = REQ_STATUS_SENT; 202 req->status = REQ_STATUS_SENT;
202 203
203 if (chan->vq->vq_ops->add_buf(chan->vq, chan->sg, out, in, req->tc)) { 204 if (chan->vq->vq_ops->add_buf(chan->vq, chan->sg, out, in, req->tc) < 0) {
204 P9_DPRINTK(P9_DEBUG_TRANS, 205 P9_DPRINTK(P9_DEBUG_TRANS,
205 "9p debug: virtio rpc add_buf returned failure"); 206 "9p debug: virtio rpc add_buf returned failure");
206 return -EIO; 207 return -EIO;
@@ -334,8 +335,6 @@ static void p9_virtio_remove(struct virtio_device *vdev)
334 } 335 }
335} 336}
336 337
337#define VIRTIO_ID_9P 9
338
339static struct virtio_device_id id_table[] = { 338static struct virtio_device_id id_table[] = {
340 { VIRTIO_ID_9P, VIRTIO_DEV_ANY_ID }, 339 { VIRTIO_ID_9P, VIRTIO_DEV_ANY_ID },
341 { 0 }, 340 { 0 },
diff --git a/net/appletalk/ddp.c b/net/appletalk/ddp.c
index 4a6ff2ba4d07..b1a4290996b5 100644
--- a/net/appletalk/ddp.c
+++ b/net/appletalk/ddp.c
@@ -1372,7 +1372,7 @@ static int atalk_route_packet(struct sk_buff *skb, struct net_device *dev,
1372 1372
1373 if (aarp_send_ddp(rt->dev, skb, &ta, NULL) == NET_XMIT_DROP) 1373 if (aarp_send_ddp(rt->dev, skb, &ta, NULL) == NET_XMIT_DROP)
1374 return NET_RX_DROP; 1374 return NET_RX_DROP;
1375 return NET_XMIT_SUCCESS; 1375 return NET_RX_SUCCESS;
1376free_it: 1376free_it:
1377 kfree_skb(skb); 1377 kfree_skb(skb);
1378drop: 1378drop:
diff --git a/net/atm/common.c b/net/atm/common.c
index 8c4d843eb17f..950bd16d2383 100644
--- a/net/atm/common.c
+++ b/net/atm/common.c
@@ -679,7 +679,7 @@ static int check_qos(const struct atm_qos *qos)
679} 679}
680 680
681int vcc_setsockopt(struct socket *sock, int level, int optname, 681int vcc_setsockopt(struct socket *sock, int level, int optname,
682 char __user *optval, int optlen) 682 char __user *optval, unsigned int optlen)
683{ 683{
684 struct atm_vcc *vcc; 684 struct atm_vcc *vcc;
685 unsigned long value; 685 unsigned long value;
diff --git a/net/atm/common.h b/net/atm/common.h
index 92e2981f479f..f48a76b6cdf4 100644
--- a/net/atm/common.h
+++ b/net/atm/common.h
@@ -21,7 +21,7 @@ unsigned int vcc_poll(struct file *file, struct socket *sock, poll_table *wait);
21int vcc_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg); 21int vcc_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg);
22int vcc_compat_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg); 22int vcc_compat_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg);
23int vcc_setsockopt(struct socket *sock, int level, int optname, 23int vcc_setsockopt(struct socket *sock, int level, int optname,
24 char __user *optval, int optlen); 24 char __user *optval, unsigned int optlen);
25int vcc_getsockopt(struct socket *sock, int level, int optname, 25int vcc_getsockopt(struct socket *sock, int level, int optname,
26 char __user *optval, int __user *optlen); 26 char __user *optval, int __user *optlen);
27 27
diff --git a/net/atm/pvc.c b/net/atm/pvc.c
index e1d22d9430dd..d4c024504f99 100644
--- a/net/atm/pvc.c
+++ b/net/atm/pvc.c
@@ -59,7 +59,7 @@ static int pvc_connect(struct socket *sock,struct sockaddr *sockaddr,
59} 59}
60 60
61static int pvc_setsockopt(struct socket *sock, int level, int optname, 61static int pvc_setsockopt(struct socket *sock, int level, int optname,
62 char __user *optval, int optlen) 62 char __user *optval, unsigned int optlen)
63{ 63{
64 struct sock *sk = sock->sk; 64 struct sock *sk = sock->sk;
65 int error; 65 int error;
diff --git a/net/atm/svc.c b/net/atm/svc.c
index 7b831b526d0b..f90d143c4b25 100644
--- a/net/atm/svc.c
+++ b/net/atm/svc.c
@@ -446,7 +446,7 @@ int svc_change_qos(struct atm_vcc *vcc,struct atm_qos *qos)
446 446
447 447
448static int svc_setsockopt(struct socket *sock, int level, int optname, 448static int svc_setsockopt(struct socket *sock, int level, int optname,
449 char __user *optval, int optlen) 449 char __user *optval, unsigned int optlen)
450{ 450{
451 struct sock *sk = sock->sk; 451 struct sock *sk = sock->sk;
452 struct atm_vcc *vcc = ATM_SD(sock); 452 struct atm_vcc *vcc = ATM_SD(sock);
diff --git a/net/ax25/af_ax25.c b/net/ax25/af_ax25.c
index da0f64f82b57..f45460730371 100644
--- a/net/ax25/af_ax25.c
+++ b/net/ax25/af_ax25.c
@@ -358,6 +358,7 @@ static int ax25_ctl_ioctl(const unsigned int cmd, void __user *arg)
358 ax25_dev *ax25_dev; 358 ax25_dev *ax25_dev;
359 ax25_cb *ax25; 359 ax25_cb *ax25;
360 unsigned int k; 360 unsigned int k;
361 int ret = 0;
361 362
362 if (copy_from_user(&ax25_ctl, arg, sizeof(ax25_ctl))) 363 if (copy_from_user(&ax25_ctl, arg, sizeof(ax25_ctl)))
363 return -EFAULT; 364 return -EFAULT;
@@ -388,57 +389,63 @@ static int ax25_ctl_ioctl(const unsigned int cmd, void __user *arg)
388 case AX25_WINDOW: 389 case AX25_WINDOW:
389 if (ax25->modulus == AX25_MODULUS) { 390 if (ax25->modulus == AX25_MODULUS) {
390 if (ax25_ctl.arg < 1 || ax25_ctl.arg > 7) 391 if (ax25_ctl.arg < 1 || ax25_ctl.arg > 7)
391 return -EINVAL; 392 goto einval_put;
392 } else { 393 } else {
393 if (ax25_ctl.arg < 1 || ax25_ctl.arg > 63) 394 if (ax25_ctl.arg < 1 || ax25_ctl.arg > 63)
394 return -EINVAL; 395 goto einval_put;
395 } 396 }
396 ax25->window = ax25_ctl.arg; 397 ax25->window = ax25_ctl.arg;
397 break; 398 break;
398 399
399 case AX25_T1: 400 case AX25_T1:
400 if (ax25_ctl.arg < 1) 401 if (ax25_ctl.arg < 1)
401 return -EINVAL; 402 goto einval_put;
402 ax25->rtt = (ax25_ctl.arg * HZ) / 2; 403 ax25->rtt = (ax25_ctl.arg * HZ) / 2;
403 ax25->t1 = ax25_ctl.arg * HZ; 404 ax25->t1 = ax25_ctl.arg * HZ;
404 break; 405 break;
405 406
406 case AX25_T2: 407 case AX25_T2:
407 if (ax25_ctl.arg < 1) 408 if (ax25_ctl.arg < 1)
408 return -EINVAL; 409 goto einval_put;
409 ax25->t2 = ax25_ctl.arg * HZ; 410 ax25->t2 = ax25_ctl.arg * HZ;
410 break; 411 break;
411 412
412 case AX25_N2: 413 case AX25_N2:
413 if (ax25_ctl.arg < 1 || ax25_ctl.arg > 31) 414 if (ax25_ctl.arg < 1 || ax25_ctl.arg > 31)
414 return -EINVAL; 415 goto einval_put;
415 ax25->n2count = 0; 416 ax25->n2count = 0;
416 ax25->n2 = ax25_ctl.arg; 417 ax25->n2 = ax25_ctl.arg;
417 break; 418 break;
418 419
419 case AX25_T3: 420 case AX25_T3:
420 if (ax25_ctl.arg < 0) 421 if (ax25_ctl.arg < 0)
421 return -EINVAL; 422 goto einval_put;
422 ax25->t3 = ax25_ctl.arg * HZ; 423 ax25->t3 = ax25_ctl.arg * HZ;
423 break; 424 break;
424 425
425 case AX25_IDLE: 426 case AX25_IDLE:
426 if (ax25_ctl.arg < 0) 427 if (ax25_ctl.arg < 0)
427 return -EINVAL; 428 goto einval_put;
428 ax25->idle = ax25_ctl.arg * 60 * HZ; 429 ax25->idle = ax25_ctl.arg * 60 * HZ;
429 break; 430 break;
430 431
431 case AX25_PACLEN: 432 case AX25_PACLEN:
432 if (ax25_ctl.arg < 16 || ax25_ctl.arg > 65535) 433 if (ax25_ctl.arg < 16 || ax25_ctl.arg > 65535)
433 return -EINVAL; 434 goto einval_put;
434 ax25->paclen = ax25_ctl.arg; 435 ax25->paclen = ax25_ctl.arg;
435 break; 436 break;
436 437
437 default: 438 default:
438 return -EINVAL; 439 goto einval_put;
439 } 440 }
440 441
441 return 0; 442out_put:
443 ax25_cb_put(ax25);
444 return ret;
445
446einval_put:
447 ret = -EINVAL;
448 goto out_put;
442} 449}
443 450
444static void ax25_fillin_cb_from_dev(ax25_cb *ax25, ax25_dev *ax25_dev) 451static void ax25_fillin_cb_from_dev(ax25_cb *ax25, ax25_dev *ax25_dev)
@@ -527,7 +534,7 @@ ax25_cb *ax25_create_cb(void)
527 */ 534 */
528 535
529static int ax25_setsockopt(struct socket *sock, int level, int optname, 536static int ax25_setsockopt(struct socket *sock, int level, int optname,
530 char __user *optval, int optlen) 537 char __user *optval, unsigned int optlen)
531{ 538{
532 struct sock *sk = sock->sk; 539 struct sock *sk = sock->sk;
533 ax25_cb *ax25; 540 ax25_cb *ax25;
@@ -634,15 +641,10 @@ static int ax25_setsockopt(struct socket *sock, int level, int optname,
634 641
635 case SO_BINDTODEVICE: 642 case SO_BINDTODEVICE:
636 if (optlen > IFNAMSIZ) 643 if (optlen > IFNAMSIZ)
637 optlen=IFNAMSIZ; 644 optlen = IFNAMSIZ;
638 if (copy_from_user(devname, optval, optlen)) {
639 res = -EFAULT;
640 break;
641 }
642 645
643 dev = dev_get_by_name(&init_net, devname); 646 if (copy_from_user(devname, optval, optlen)) {
644 if (dev == NULL) { 647 res = -EFAULT;
645 res = -ENODEV;
646 break; 648 break;
647 } 649 }
648 650
@@ -650,12 +652,18 @@ static int ax25_setsockopt(struct socket *sock, int level, int optname,
650 (sock->state != SS_UNCONNECTED || 652 (sock->state != SS_UNCONNECTED ||
651 sk->sk_state == TCP_LISTEN)) { 653 sk->sk_state == TCP_LISTEN)) {
652 res = -EADDRNOTAVAIL; 654 res = -EADDRNOTAVAIL;
653 dev_put(dev); 655 break;
656 }
657
658 dev = dev_get_by_name(&init_net, devname);
659 if (!dev) {
660 res = -ENODEV;
654 break; 661 break;
655 } 662 }
656 663
657 ax25->ax25_dev = ax25_dev_ax25dev(dev); 664 ax25->ax25_dev = ax25_dev_ax25dev(dev);
658 ax25_fillin_cb(ax25, ax25->ax25_dev); 665 ax25_fillin_cb(ax25, ax25->ax25_dev);
666 dev_put(dev);
659 break; 667 break;
660 668
661 default: 669 default:
@@ -893,7 +901,6 @@ struct sock *ax25_make_new(struct sock *osk, struct ax25_dev *ax25_dev)
893 901
894 sock_init_data(NULL, sk); 902 sock_init_data(NULL, sk);
895 903
896 sk->sk_destruct = ax25_free_sock;
897 sk->sk_type = osk->sk_type; 904 sk->sk_type = osk->sk_type;
898 sk->sk_priority = osk->sk_priority; 905 sk->sk_priority = osk->sk_priority;
899 sk->sk_protocol = osk->sk_protocol; 906 sk->sk_protocol = osk->sk_protocol;
@@ -931,6 +938,7 @@ struct sock *ax25_make_new(struct sock *osk, struct ax25_dev *ax25_dev)
931 } 938 }
932 939
933 sk->sk_protinfo = ax25; 940 sk->sk_protinfo = ax25;
941 sk->sk_destruct = ax25_free_sock;
934 ax25->sk = sk; 942 ax25->sk = sk;
935 943
936 return sk; 944 return sk;
@@ -1781,8 +1789,8 @@ static int ax25_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
1781 ax25_info.idletimer = ax25_display_timer(&ax25->idletimer) / (60 * HZ); 1789 ax25_info.idletimer = ax25_display_timer(&ax25->idletimer) / (60 * HZ);
1782 ax25_info.n2count = ax25->n2count; 1790 ax25_info.n2count = ax25->n2count;
1783 ax25_info.state = ax25->state; 1791 ax25_info.state = ax25->state;
1784 ax25_info.rcv_q = sk_wmem_alloc_get(sk); 1792 ax25_info.rcv_q = sk_rmem_alloc_get(sk);
1785 ax25_info.snd_q = sk_rmem_alloc_get(sk); 1793 ax25_info.snd_q = sk_wmem_alloc_get(sk);
1786 ax25_info.vs = ax25->vs; 1794 ax25_info.vs = ax25->vs;
1787 ax25_info.vr = ax25->vr; 1795 ax25_info.vr = ax25->vr;
1788 ax25_info.va = ax25->va; 1796 ax25_info.va = ax25->va;
diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
index 4f9621f759a0..75302a986067 100644
--- a/net/bluetooth/hci_sock.c
+++ b/net/bluetooth/hci_sock.c
@@ -466,7 +466,7 @@ drop:
466 goto done; 466 goto done;
467} 467}
468 468
469static int hci_sock_setsockopt(struct socket *sock, int level, int optname, char __user *optval, int len) 469static int hci_sock_setsockopt(struct socket *sock, int level, int optname, char __user *optval, unsigned int len)
470{ 470{
471 struct hci_ufilter uf = { .opcode = 0 }; 471 struct hci_ufilter uf = { .opcode = 0 };
472 struct sock *sk = sock->sk; 472 struct sock *sk = sock->sk;
diff --git a/net/bluetooth/hci_sysfs.c b/net/bluetooth/hci_sysfs.c
index 95f7a7a544b4..7f939ce29801 100644
--- a/net/bluetooth/hci_sysfs.c
+++ b/net/bluetooth/hci_sysfs.c
@@ -68,7 +68,7 @@ static struct attribute_group bt_link_group = {
68 .attrs = bt_link_attrs, 68 .attrs = bt_link_attrs,
69}; 69};
70 70
71static struct attribute_group *bt_link_groups[] = { 71static const struct attribute_group *bt_link_groups[] = {
72 &bt_link_group, 72 &bt_link_group,
73 NULL 73 NULL
74}; 74};
@@ -392,7 +392,7 @@ static struct attribute_group bt_host_group = {
392 .attrs = bt_host_attrs, 392 .attrs = bt_host_attrs,
393}; 393};
394 394
395static struct attribute_group *bt_host_groups[] = { 395static const struct attribute_group *bt_host_groups[] = {
396 &bt_host_group, 396 &bt_host_group,
397 NULL 397 NULL
398}; 398};
diff --git a/net/bluetooth/hidp/core.c b/net/bluetooth/hidp/core.c
index 09bedeb5579c..49d8495d69be 100644
--- a/net/bluetooth/hidp/core.c
+++ b/net/bluetooth/hidp/core.c
@@ -577,11 +577,6 @@ static int hidp_session(void *arg)
577 } 577 }
578 578
579 if (session->hid) { 579 if (session->hid) {
580 if (session->hid->claimed & HID_CLAIMED_INPUT)
581 hidinput_disconnect(session->hid);
582 if (session->hid->claimed & HID_CLAIMED_HIDRAW)
583 hidraw_disconnect(session->hid);
584
585 hid_destroy_device(session->hid); 580 hid_destroy_device(session->hid);
586 session->hid = NULL; 581 session->hid = NULL;
587 } 582 }
@@ -747,8 +742,6 @@ static void hidp_stop(struct hid_device *hid)
747 skb_queue_purge(&session->ctrl_transmit); 742 skb_queue_purge(&session->ctrl_transmit);
748 skb_queue_purge(&session->intr_transmit); 743 skb_queue_purge(&session->intr_transmit);
749 744
750 if (hid->claimed & HID_CLAIMED_INPUT)
751 hidinput_disconnect(hid);
752 hid->claimed = 0; 745 hid->claimed = 0;
753} 746}
754 747
diff --git a/net/bluetooth/l2cap.c b/net/bluetooth/l2cap.c
index b03012564647..555d9da1869b 100644
--- a/net/bluetooth/l2cap.c
+++ b/net/bluetooth/l2cap.c
@@ -1698,7 +1698,7 @@ static int l2cap_sock_recvmsg(struct kiocb *iocb, struct socket *sock, struct ms
1698 return bt_sock_recvmsg(iocb, sock, msg, len, flags); 1698 return bt_sock_recvmsg(iocb, sock, msg, len, flags);
1699} 1699}
1700 1700
1701static int l2cap_sock_setsockopt_old(struct socket *sock, int optname, char __user *optval, int optlen) 1701static int l2cap_sock_setsockopt_old(struct socket *sock, int optname, char __user *optval, unsigned int optlen)
1702{ 1702{
1703 struct sock *sk = sock->sk; 1703 struct sock *sk = sock->sk;
1704 struct l2cap_options opts; 1704 struct l2cap_options opts;
@@ -1755,7 +1755,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname, char __us
1755 return err; 1755 return err;
1756} 1756}
1757 1757
1758static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, char __user *optval, int optlen) 1758static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, char __user *optval, unsigned int optlen)
1759{ 1759{
1760 struct sock *sk = sock->sk; 1760 struct sock *sk = sock->sk;
1761 struct bt_security sec; 1761 struct bt_security sec;
diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
index 0b85e8116859..8a20aaf1f231 100644
--- a/net/bluetooth/rfcomm/sock.c
+++ b/net/bluetooth/rfcomm/sock.c
@@ -730,7 +730,7 @@ out:
730 return copied ? : err; 730 return copied ? : err;
731} 731}
732 732
733static int rfcomm_sock_setsockopt_old(struct socket *sock, int optname, char __user *optval, int optlen) 733static int rfcomm_sock_setsockopt_old(struct socket *sock, int optname, char __user *optval, unsigned int optlen)
734{ 734{
735 struct sock *sk = sock->sk; 735 struct sock *sk = sock->sk;
736 int err = 0; 736 int err = 0;
@@ -766,7 +766,7 @@ static int rfcomm_sock_setsockopt_old(struct socket *sock, int optname, char __u
766 return err; 766 return err;
767} 767}
768 768
769static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, char __user *optval, int optlen) 769static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, char __user *optval, unsigned int optlen)
770{ 770{
771 struct sock *sk = sock->sk; 771 struct sock *sk = sock->sk;
772 struct bt_security sec; 772 struct bt_security sec;
diff --git a/net/bluetooth/sco.c b/net/bluetooth/sco.c
index 13c27f17192c..77f4153bdb5e 100644
--- a/net/bluetooth/sco.c
+++ b/net/bluetooth/sco.c
@@ -644,7 +644,7 @@ static int sco_sock_sendmsg(struct kiocb *iocb, struct socket *sock,
644 return err; 644 return err;
645} 645}
646 646
647static int sco_sock_setsockopt(struct socket *sock, int level, int optname, char __user *optval, int optlen) 647static int sco_sock_setsockopt(struct socket *sock, int level, int optname, char __user *optval, unsigned int optlen)
648{ 648{
649 struct sock *sk = sock->sk; 649 struct sock *sk = sock->sk;
650 int err = 0; 650 int err = 0;
diff --git a/net/bridge/br_if.c b/net/bridge/br_if.c
index 142ebac14176..b1b3b0fbf41c 100644
--- a/net/bridge/br_if.c
+++ b/net/bridge/br_if.c
@@ -432,6 +432,7 @@ err2:
432 br_fdb_delete_by_port(br, p, 1); 432 br_fdb_delete_by_port(br, p, 1);
433err1: 433err1:
434 kobject_put(&p->kobj); 434 kobject_put(&p->kobj);
435 p = NULL; /* kobject_put frees */
435err0: 436err0:
436 dev_set_promiscuity(dev, -1); 437 dev_set_promiscuity(dev, -1);
437put_back: 438put_back:
diff --git a/net/bridge/br_netfilter.c b/net/bridge/br_netfilter.c
index 907a82e9023d..a16a2342f6bf 100644
--- a/net/bridge/br_netfilter.c
+++ b/net/bridge/br_netfilter.c
@@ -965,12 +965,12 @@ static struct nf_hook_ops br_nf_ops[] __read_mostly = {
965 965
966#ifdef CONFIG_SYSCTL 966#ifdef CONFIG_SYSCTL
967static 967static
968int brnf_sysctl_call_tables(ctl_table * ctl, int write, struct file *filp, 968int brnf_sysctl_call_tables(ctl_table * ctl, int write,
969 void __user * buffer, size_t * lenp, loff_t * ppos) 969 void __user * buffer, size_t * lenp, loff_t * ppos)
970{ 970{
971 int ret; 971 int ret;
972 972
973 ret = proc_dointvec(ctl, write, filp, buffer, lenp, ppos); 973 ret = proc_dointvec(ctl, write, buffer, lenp, ppos);
974 974
975 if (write && *(int *)(ctl->data)) 975 if (write && *(int *)(ctl->data))
976 *(int *)(ctl->data) = 1; 976 *(int *)(ctl->data) = 1;
diff --git a/net/can/af_can.c b/net/can/af_can.c
index ef1c43a2ed56..606832115674 100644
--- a/net/can/af_can.c
+++ b/net/can/af_can.c
@@ -199,6 +199,8 @@ static int can_create(struct net *net, struct socket *sock, int protocol)
199 * @skb: pointer to socket buffer with CAN frame in data section 199 * @skb: pointer to socket buffer with CAN frame in data section
200 * @loop: loopback for listeners on local CAN sockets (recommended default!) 200 * @loop: loopback for listeners on local CAN sockets (recommended default!)
201 * 201 *
202 * Due to the loopback this routine must not be called from hardirq context.
203 *
202 * Return: 204 * Return:
203 * 0 on success 205 * 0 on success
204 * -ENETDOWN when the selected interface is down 206 * -ENETDOWN when the selected interface is down
@@ -278,7 +280,7 @@ int can_send(struct sk_buff *skb, int loop)
278 } 280 }
279 281
280 if (newskb) 282 if (newskb)
281 netif_rx(newskb); 283 netif_rx_ni(newskb);
282 284
283 /* update statistics */ 285 /* update statistics */
284 can_stats.tx_frames++; 286 can_stats.tx_frames++;
diff --git a/net/can/raw.c b/net/can/raw.c
index db3152df7d2b..b5e897922d32 100644
--- a/net/can/raw.c
+++ b/net/can/raw.c
@@ -411,7 +411,7 @@ static int raw_getname(struct socket *sock, struct sockaddr *uaddr,
411} 411}
412 412
413static int raw_setsockopt(struct socket *sock, int level, int optname, 413static int raw_setsockopt(struct socket *sock, int level, int optname,
414 char __user *optval, int optlen) 414 char __user *optval, unsigned int optlen)
415{ 415{
416 struct sock *sk = sock->sk; 416 struct sock *sk = sock->sk;
417 struct raw_sock *ro = raw_sk(sk); 417 struct raw_sock *ro = raw_sk(sk);
diff --git a/net/compat.c b/net/compat.c
index 12728b17a226..a407c3addbae 100644
--- a/net/compat.c
+++ b/net/compat.c
@@ -331,7 +331,7 @@ struct compat_sock_fprog {
331}; 331};
332 332
333static int do_set_attach_filter(struct socket *sock, int level, int optname, 333static int do_set_attach_filter(struct socket *sock, int level, int optname,
334 char __user *optval, int optlen) 334 char __user *optval, unsigned int optlen)
335{ 335{
336 struct compat_sock_fprog __user *fprog32 = (struct compat_sock_fprog __user *)optval; 336 struct compat_sock_fprog __user *fprog32 = (struct compat_sock_fprog __user *)optval;
337 struct sock_fprog __user *kfprog = compat_alloc_user_space(sizeof(struct sock_fprog)); 337 struct sock_fprog __user *kfprog = compat_alloc_user_space(sizeof(struct sock_fprog));
@@ -351,7 +351,7 @@ static int do_set_attach_filter(struct socket *sock, int level, int optname,
351} 351}
352 352
353static int do_set_sock_timeout(struct socket *sock, int level, 353static int do_set_sock_timeout(struct socket *sock, int level,
354 int optname, char __user *optval, int optlen) 354 int optname, char __user *optval, unsigned int optlen)
355{ 355{
356 struct compat_timeval __user *up = (struct compat_timeval __user *) optval; 356 struct compat_timeval __user *up = (struct compat_timeval __user *) optval;
357 struct timeval ktime; 357 struct timeval ktime;
@@ -373,7 +373,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
373} 373}
374 374
375static int compat_sock_setsockopt(struct socket *sock, int level, int optname, 375static int compat_sock_setsockopt(struct socket *sock, int level, int optname,
376 char __user *optval, int optlen) 376 char __user *optval, unsigned int optlen)
377{ 377{
378 if (optname == SO_ATTACH_FILTER) 378 if (optname == SO_ATTACH_FILTER)
379 return do_set_attach_filter(sock, level, optname, 379 return do_set_attach_filter(sock, level, optname,
@@ -385,7 +385,7 @@ static int compat_sock_setsockopt(struct socket *sock, int level, int optname,
385} 385}
386 386
387asmlinkage long compat_sys_setsockopt(int fd, int level, int optname, 387asmlinkage long compat_sys_setsockopt(int fd, int level, int optname,
388 char __user *optval, int optlen) 388 char __user *optval, unsigned int optlen)
389{ 389{
390 int err; 390 int err;
391 struct socket *sock; 391 struct socket *sock;
@@ -558,8 +558,8 @@ struct compat_group_filter {
558 558
559 559
560int compat_mc_setsockopt(struct sock *sock, int level, int optname, 560int compat_mc_setsockopt(struct sock *sock, int level, int optname,
561 char __user *optval, int optlen, 561 char __user *optval, unsigned int optlen,
562 int (*setsockopt)(struct sock *,int,int,char __user *,int)) 562 int (*setsockopt)(struct sock *,int,int,char __user *,unsigned int))
563{ 563{
564 char __user *koptval = optval; 564 char __user *koptval = optval;
565 int koptlen = optlen; 565 int koptlen = optlen;
diff --git a/net/core/dev.c b/net/core/dev.c
index 84945470ab38..b8f74cfb1bfd 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -1017,9 +1017,9 @@ void netdev_state_change(struct net_device *dev)
1017} 1017}
1018EXPORT_SYMBOL(netdev_state_change); 1018EXPORT_SYMBOL(netdev_state_change);
1019 1019
1020void netdev_bonding_change(struct net_device *dev) 1020void netdev_bonding_change(struct net_device *dev, unsigned long event)
1021{ 1021{
1022 call_netdevice_notifiers(NETDEV_BONDING_FAILOVER, dev); 1022 call_netdevice_notifiers(event, dev);
1023} 1023}
1024EXPORT_SYMBOL(netdev_bonding_change); 1024EXPORT_SYMBOL(netdev_bonding_change);
1025 1025
@@ -2288,6 +2288,9 @@ int netif_receive_skb(struct sk_buff *skb)
2288 int ret = NET_RX_DROP; 2288 int ret = NET_RX_DROP;
2289 __be16 type; 2289 __be16 type;
2290 2290
2291 if (!skb->tstamp.tv64)
2292 net_timestamp(skb);
2293
2291 if (skb->vlan_tci && vlan_hwaccel_do_receive(skb)) 2294 if (skb->vlan_tci && vlan_hwaccel_do_receive(skb))
2292 return NET_RX_SUCCESS; 2295 return NET_RX_SUCCESS;
2293 2296
@@ -2295,9 +2298,6 @@ int netif_receive_skb(struct sk_buff *skb)
2295 if (netpoll_receive_skb(skb)) 2298 if (netpoll_receive_skb(skb))
2296 return NET_RX_DROP; 2299 return NET_RX_DROP;
2297 2300
2298 if (!skb->tstamp.tv64)
2299 net_timestamp(skb);
2300
2301 if (!skb->iif) 2301 if (!skb->iif)
2302 skb->iif = skb->dev->ifindex; 2302 skb->iif = skb->dev->ifindex;
2303 2303
diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
index ad91e9e5f475..427ded841224 100644
--- a/net/core/net-sysfs.c
+++ b/net/core/net-sysfs.c
@@ -16,7 +16,7 @@
16#include <net/sock.h> 16#include <net/sock.h>
17#include <linux/rtnetlink.h> 17#include <linux/rtnetlink.h>
18#include <linux/wireless.h> 18#include <linux/wireless.h>
19#include <net/iw_handler.h> 19#include <net/wext.h>
20 20
21#include "net-sysfs.h" 21#include "net-sysfs.h"
22 22
@@ -363,18 +363,16 @@ static ssize_t wireless_show(struct device *d, char *buf,
363 char *)) 363 char *))
364{ 364{
365 struct net_device *dev = to_net_dev(d); 365 struct net_device *dev = to_net_dev(d);
366 const struct iw_statistics *iw = NULL; 366 const struct iw_statistics *iw;
367 ssize_t ret = -EINVAL; 367 ssize_t ret = -EINVAL;
368 368
369 read_lock(&dev_base_lock); 369 rtnl_lock();
370 if (dev_isalive(dev)) { 370 if (dev_isalive(dev)) {
371 if (dev->wireless_handlers && 371 iw = get_wireless_stats(dev);
372 dev->wireless_handlers->get_wireless_stats) 372 if (iw)
373 iw = dev->wireless_handlers->get_wireless_stats(dev);
374 if (iw != NULL)
375 ret = (*format)(iw, buf); 373 ret = (*format)(iw, buf);
376 } 374 }
377 read_unlock(&dev_base_lock); 375 rtnl_unlock();
378 376
379 return ret; 377 return ret;
380} 378}
@@ -493,7 +491,7 @@ void netdev_unregister_kobject(struct net_device * net)
493int netdev_register_kobject(struct net_device *net) 491int netdev_register_kobject(struct net_device *net)
494{ 492{
495 struct device *dev = &(net->dev); 493 struct device *dev = &(net->dev);
496 struct attribute_group **groups = net->sysfs_groups; 494 const struct attribute_group **groups = net->sysfs_groups;
497 495
498 dev->class = &net_class; 496 dev->class = &net_class;
499 dev->platform_data = net; 497 dev->platform_data = net;
@@ -505,7 +503,7 @@ int netdev_register_kobject(struct net_device *net)
505 *groups++ = &netstat_group; 503 *groups++ = &netstat_group;
506 504
507#ifdef CONFIG_WIRELESS_EXT_SYSFS 505#ifdef CONFIG_WIRELESS_EXT_SYSFS
508 if (net->wireless_handlers && net->wireless_handlers->get_wireless_stats) 506 if (net->wireless_handlers || net->ieee80211_ptr)
509 *groups++ = &wireless_group; 507 *groups++ = &wireless_group;
510#endif 508#endif
511#endif /* CONFIG_SYSFS */ 509#endif /* CONFIG_SYSFS */
diff --git a/net/core/pktgen.c b/net/core/pktgen.c
index 0bcecbf06581..86acdba0a97d 100644
--- a/net/core/pktgen.c
+++ b/net/core/pktgen.c
@@ -192,11 +192,10 @@
192#define F_QUEUE_MAP_CPU (1<<14) /* queue map mirrors smp_processor_id() */ 192#define F_QUEUE_MAP_CPU (1<<14) /* queue map mirrors smp_processor_id() */
193 193
194/* Thread control flag bits */ 194/* Thread control flag bits */
195#define T_TERMINATE (1<<0) 195#define T_STOP (1<<0) /* Stop run */
196#define T_STOP (1<<1) /* Stop run */ 196#define T_RUN (1<<1) /* Start run */
197#define T_RUN (1<<2) /* Start run */ 197#define T_REMDEVALL (1<<2) /* Remove all devs */
198#define T_REMDEVALL (1<<3) /* Remove all devs */ 198#define T_REMDEV (1<<3) /* Remove one dev */
199#define T_REMDEV (1<<4) /* Remove one dev */
200 199
201/* If lock -- can be removed after some work */ 200/* If lock -- can be removed after some work */
202#define if_lock(t) spin_lock(&(t->if_lock)); 201#define if_lock(t) spin_lock(&(t->if_lock));
@@ -965,7 +964,7 @@ static ssize_t pktgen_if_write(struct file *file,
965 if (value == 0x7FFFFFFF) 964 if (value == 0x7FFFFFFF)
966 pkt_dev->delay = ULLONG_MAX; 965 pkt_dev->delay = ULLONG_MAX;
967 else 966 else
968 pkt_dev->delay = (u64)value * NSEC_PER_USEC; 967 pkt_dev->delay = (u64)value;
969 968
970 sprintf(pg_result, "OK: delay=%llu", 969 sprintf(pg_result, "OK: delay=%llu",
971 (unsigned long long) pkt_dev->delay); 970 (unsigned long long) pkt_dev->delay);
@@ -2105,18 +2104,20 @@ static void pktgen_setup_inject(struct pktgen_dev *pkt_dev)
2105 2104
2106static void spin(struct pktgen_dev *pkt_dev, ktime_t spin_until) 2105static void spin(struct pktgen_dev *pkt_dev, ktime_t spin_until)
2107{ 2106{
2108 ktime_t start; 2107 ktime_t start_time, end_time;
2109 s32 remaining; 2108 s64 remaining;
2110 struct hrtimer_sleeper t; 2109 struct hrtimer_sleeper t;
2111 2110
2112 hrtimer_init_on_stack(&t.timer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS); 2111 hrtimer_init_on_stack(&t.timer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS);
2113 hrtimer_set_expires(&t.timer, spin_until); 2112 hrtimer_set_expires(&t.timer, spin_until);
2114 2113
2115 remaining = ktime_to_us(hrtimer_expires_remaining(&t.timer)); 2114 remaining = ktime_to_us(hrtimer_expires_remaining(&t.timer));
2116 if (remaining <= 0) 2115 if (remaining <= 0) {
2116 pkt_dev->next_tx = ktime_add_ns(spin_until, pkt_dev->delay);
2117 return; 2117 return;
2118 }
2118 2119
2119 start = ktime_now(); 2120 start_time = ktime_now();
2120 if (remaining < 100) 2121 if (remaining < 100)
2121 udelay(remaining); /* really small just spin */ 2122 udelay(remaining); /* really small just spin */
2122 else { 2123 else {
@@ -2135,7 +2136,10 @@ static void spin(struct pktgen_dev *pkt_dev, ktime_t spin_until)
2135 } while (t.task && pkt_dev->running && !signal_pending(current)); 2136 } while (t.task && pkt_dev->running && !signal_pending(current));
2136 __set_current_state(TASK_RUNNING); 2137 __set_current_state(TASK_RUNNING);
2137 } 2138 }
2138 pkt_dev->idle_acc += ktime_to_ns(ktime_sub(ktime_now(), start)); 2139 end_time = ktime_now();
2140
2141 pkt_dev->idle_acc += ktime_to_ns(ktime_sub(end_time, start_time));
2142 pkt_dev->next_tx = ktime_add_ns(end_time, pkt_dev->delay);
2139} 2143}
2140 2144
2141static inline void set_pkt_overhead(struct pktgen_dev *pkt_dev) 2145static inline void set_pkt_overhead(struct pktgen_dev *pkt_dev)
@@ -2208,7 +2212,7 @@ static void set_cur_queue_map(struct pktgen_dev *pkt_dev)
2208 if (pkt_dev->flags & F_QUEUE_MAP_CPU) 2212 if (pkt_dev->flags & F_QUEUE_MAP_CPU)
2209 pkt_dev->cur_queue_map = smp_processor_id(); 2213 pkt_dev->cur_queue_map = smp_processor_id();
2210 2214
2211 else if (pkt_dev->queue_map_min < pkt_dev->queue_map_max) { 2215 else if (pkt_dev->queue_map_min <= pkt_dev->queue_map_max) {
2212 __u16 t; 2216 __u16 t;
2213 if (pkt_dev->flags & F_QUEUE_MAP_RND) { 2217 if (pkt_dev->flags & F_QUEUE_MAP_RND) {
2214 t = random32() % 2218 t = random32() %
@@ -3365,19 +3369,29 @@ static void pktgen_rem_thread(struct pktgen_thread *t)
3365 mutex_unlock(&pktgen_thread_lock); 3369 mutex_unlock(&pktgen_thread_lock);
3366} 3370}
3367 3371
3368static void idle(struct pktgen_dev *pkt_dev) 3372static void pktgen_resched(struct pktgen_dev *pkt_dev)
3369{ 3373{
3370 ktime_t idle_start = ktime_now(); 3374 ktime_t idle_start = ktime_now();
3375 schedule();
3376 pkt_dev->idle_acc += ktime_to_ns(ktime_sub(ktime_now(), idle_start));
3377}
3371 3378
3372 if (need_resched()) 3379static void pktgen_wait_for_skb(struct pktgen_dev *pkt_dev)
3373 schedule(); 3380{
3374 else 3381 ktime_t idle_start = ktime_now();
3375 cpu_relax(); 3382
3383 while (atomic_read(&(pkt_dev->skb->users)) != 1) {
3384 if (signal_pending(current))
3385 break;
3376 3386
3387 if (need_resched())
3388 pktgen_resched(pkt_dev);
3389 else
3390 cpu_relax();
3391 }
3377 pkt_dev->idle_acc += ktime_to_ns(ktime_sub(ktime_now(), idle_start)); 3392 pkt_dev->idle_acc += ktime_to_ns(ktime_sub(ktime_now(), idle_start));
3378} 3393}
3379 3394
3380
3381static void pktgen_xmit(struct pktgen_dev *pkt_dev) 3395static void pktgen_xmit(struct pktgen_dev *pkt_dev)
3382{ 3396{
3383 struct net_device *odev = pkt_dev->odev; 3397 struct net_device *odev = pkt_dev->odev;
@@ -3387,36 +3401,21 @@ static void pktgen_xmit(struct pktgen_dev *pkt_dev)
3387 u16 queue_map; 3401 u16 queue_map;
3388 int ret; 3402 int ret;
3389 3403
3390 if (pkt_dev->delay) { 3404 /* If device is offline, then don't send */
3391 spin(pkt_dev, pkt_dev->next_tx); 3405 if (unlikely(!netif_running(odev) || !netif_carrier_ok(odev))) {
3392 3406 pktgen_stop_device(pkt_dev);
3393 /* This is max DELAY, this has special meaning of 3407 return;
3394 * "never transmit"
3395 */
3396 if (pkt_dev->delay == ULLONG_MAX) {
3397 pkt_dev->next_tx = ktime_add_ns(ktime_now(), ULONG_MAX);
3398 return;
3399 }
3400 }
3401
3402 if (!pkt_dev->skb) {
3403 set_cur_queue_map(pkt_dev);
3404 queue_map = pkt_dev->cur_queue_map;
3405 } else {
3406 queue_map = skb_get_queue_mapping(pkt_dev->skb);
3407 } 3408 }
3408 3409
3409 txq = netdev_get_tx_queue(odev, queue_map); 3410 /* This is max DELAY, this has special meaning of
3410 /* Did we saturate the queue already? */ 3411 * "never transmit"
3411 if (netif_tx_queue_stopped(txq) || netif_tx_queue_frozen(txq)) { 3412 */
3412 /* If device is down, then all queues are permnantly frozen */ 3413 if (unlikely(pkt_dev->delay == ULLONG_MAX)) {
3413 if (netif_running(odev)) 3414 pkt_dev->next_tx = ktime_add_ns(ktime_now(), ULONG_MAX);
3414 idle(pkt_dev);
3415 else
3416 pktgen_stop_device(pkt_dev);
3417 return; 3415 return;
3418 } 3416 }
3419 3417
3418 /* If no skb or clone count exhausted then get new one */
3420 if (!pkt_dev->skb || (pkt_dev->last_ok && 3419 if (!pkt_dev->skb || (pkt_dev->last_ok &&
3421 ++pkt_dev->clone_count >= pkt_dev->clone_skb)) { 3420 ++pkt_dev->clone_count >= pkt_dev->clone_skb)) {
3422 /* build a new pkt */ 3421 /* build a new pkt */
@@ -3435,54 +3434,45 @@ static void pktgen_xmit(struct pktgen_dev *pkt_dev)
3435 pkt_dev->clone_count = 0; /* reset counter */ 3434 pkt_dev->clone_count = 0; /* reset counter */
3436 } 3435 }
3437 3436
3438 /* fill_packet() might have changed the queue */ 3437 if (pkt_dev->delay && pkt_dev->last_ok)
3438 spin(pkt_dev, pkt_dev->next_tx);
3439
3439 queue_map = skb_get_queue_mapping(pkt_dev->skb); 3440 queue_map = skb_get_queue_mapping(pkt_dev->skb);
3440 txq = netdev_get_tx_queue(odev, queue_map); 3441 txq = netdev_get_tx_queue(odev, queue_map);
3441 3442
3442 __netif_tx_lock_bh(txq); 3443 __netif_tx_lock_bh(txq);
3443 if (unlikely(netif_tx_queue_stopped(txq) || netif_tx_queue_frozen(txq))) 3444 atomic_inc(&(pkt_dev->skb->users));
3444 pkt_dev->last_ok = 0;
3445 else {
3446 atomic_inc(&(pkt_dev->skb->users));
3447 3445
3448 retry_now: 3446 if (unlikely(netif_tx_queue_stopped(txq) || netif_tx_queue_frozen(txq)))
3447 ret = NETDEV_TX_BUSY;
3448 else
3449 ret = (*xmit)(pkt_dev->skb, odev); 3449 ret = (*xmit)(pkt_dev->skb, odev);
3450 switch (ret) { 3450
3451 case NETDEV_TX_OK: 3451 switch (ret) {
3452 txq_trans_update(txq); 3452 case NETDEV_TX_OK:
3453 pkt_dev->last_ok = 1; 3453 txq_trans_update(txq);
3454 pkt_dev->sofar++; 3454 pkt_dev->last_ok = 1;
3455 pkt_dev->seq_num++; 3455 pkt_dev->sofar++;
3456 pkt_dev->tx_bytes += pkt_dev->cur_pkt_size; 3456 pkt_dev->seq_num++;
3457 break; 3457 pkt_dev->tx_bytes += pkt_dev->cur_pkt_size;
3458 case NETDEV_TX_LOCKED: 3458 break;
3459 cpu_relax(); 3459 default: /* Drivers are not supposed to return other values! */
3460 goto retry_now; 3460 if (net_ratelimit())
3461 default: /* Drivers are not supposed to return other values! */ 3461 pr_info("pktgen: %s xmit error: %d\n",
3462 if (net_ratelimit()) 3462 odev->name, ret);
3463 pr_info("pktgen: %s xmit error: %d\n", 3463 pkt_dev->errors++;
3464 odev->name, ret); 3464 /* fallthru */
3465 pkt_dev->errors++; 3465 case NETDEV_TX_LOCKED:
3466 /* fallthru */ 3466 case NETDEV_TX_BUSY:
3467 case NETDEV_TX_BUSY: 3467 /* Retry it next time */
3468 /* Retry it next time */ 3468 atomic_dec(&(pkt_dev->skb->users));
3469 atomic_dec(&(pkt_dev->skb->users)); 3469 pkt_dev->last_ok = 0;
3470 pkt_dev->last_ok = 0;
3471 }
3472
3473 if (pkt_dev->delay)
3474 pkt_dev->next_tx = ktime_add_ns(ktime_now(),
3475 pkt_dev->delay);
3476 } 3470 }
3477 __netif_tx_unlock_bh(txq); 3471 __netif_tx_unlock_bh(txq);
3478 3472
3479 /* If pkt_dev->count is zero, then run forever */ 3473 /* If pkt_dev->count is zero, then run forever */
3480 if ((pkt_dev->count != 0) && (pkt_dev->sofar >= pkt_dev->count)) { 3474 if ((pkt_dev->count != 0) && (pkt_dev->sofar >= pkt_dev->count)) {
3481 while (atomic_read(&(pkt_dev->skb->users)) != 1) { 3475 pktgen_wait_for_skb(pkt_dev);
3482 if (signal_pending(current))
3483 break;
3484 idle(pkt_dev);
3485 }
3486 3476
3487 /* Done with this */ 3477 /* Done with this */
3488 pktgen_stop_device(pkt_dev); 3478 pktgen_stop_device(pkt_dev);
@@ -3515,20 +3505,24 @@ static int pktgen_thread_worker(void *arg)
3515 while (!kthread_should_stop()) { 3505 while (!kthread_should_stop()) {
3516 pkt_dev = next_to_run(t); 3506 pkt_dev = next_to_run(t);
3517 3507
3518 if (!pkt_dev && 3508 if (unlikely(!pkt_dev && t->control == 0)) {
3519 (t->control & (T_STOP | T_RUN | T_REMDEVALL | T_REMDEV)) 3509 wait_event_interruptible_timeout(t->queue,
3520 == 0) { 3510 t->control != 0,
3521 prepare_to_wait(&(t->queue), &wait, 3511 HZ/10);
3522 TASK_INTERRUPTIBLE); 3512 continue;
3523 schedule_timeout(HZ / 10);
3524 finish_wait(&(t->queue), &wait);
3525 } 3513 }
3526 3514
3527 __set_current_state(TASK_RUNNING); 3515 __set_current_state(TASK_RUNNING);
3528 3516
3529 if (pkt_dev) 3517 if (likely(pkt_dev)) {
3530 pktgen_xmit(pkt_dev); 3518 pktgen_xmit(pkt_dev);
3531 3519
3520 if (need_resched())
3521 pktgen_resched(pkt_dev);
3522 else
3523 cpu_relax();
3524 }
3525
3532 if (t->control & T_STOP) { 3526 if (t->control & T_STOP) {
3533 pktgen_stop(t); 3527 pktgen_stop(t);
3534 t->control &= ~(T_STOP); 3528 t->control &= ~(T_STOP);
diff --git a/net/core/sock.c b/net/core/sock.c
index 30d5446512f9..7626b6aacd68 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -446,7 +446,7 @@ static inline void sock_valbool_flag(struct sock *sk, int bit, int valbool)
446 */ 446 */
447 447
448int sock_setsockopt(struct socket *sock, int level, int optname, 448int sock_setsockopt(struct socket *sock, int level, int optname,
449 char __user *optval, int optlen) 449 char __user *optval, unsigned int optlen)
450{ 450{
451 struct sock *sk = sock->sk; 451 struct sock *sk = sock->sk;
452 int val; 452 int val;
@@ -1206,12 +1206,12 @@ EXPORT_SYMBOL_GPL(sk_setup_caps);
1206 1206
1207void __init sk_init(void) 1207void __init sk_init(void)
1208{ 1208{
1209 if (num_physpages <= 4096) { 1209 if (totalram_pages <= 4096) {
1210 sysctl_wmem_max = 32767; 1210 sysctl_wmem_max = 32767;
1211 sysctl_rmem_max = 32767; 1211 sysctl_rmem_max = 32767;
1212 sysctl_wmem_default = 32767; 1212 sysctl_wmem_default = 32767;
1213 sysctl_rmem_default = 32767; 1213 sysctl_rmem_default = 32767;
1214 } else if (num_physpages >= 131072) { 1214 } else if (totalram_pages >= 131072) {
1215 sysctl_wmem_max = 131071; 1215 sysctl_wmem_max = 131071;
1216 sysctl_rmem_max = 131071; 1216 sysctl_rmem_max = 131071;
1217 } 1217 }
@@ -1228,17 +1228,22 @@ void __init sk_init(void)
1228void sock_wfree(struct sk_buff *skb) 1228void sock_wfree(struct sk_buff *skb)
1229{ 1229{
1230 struct sock *sk = skb->sk; 1230 struct sock *sk = skb->sk;
1231 int res; 1231 unsigned int len = skb->truesize;
1232 1232
1233 /* In case it might be waiting for more memory. */ 1233 if (!sock_flag(sk, SOCK_USE_WRITE_QUEUE)) {
1234 res = atomic_sub_return(skb->truesize, &sk->sk_wmem_alloc); 1234 /*
1235 if (!sock_flag(sk, SOCK_USE_WRITE_QUEUE)) 1235 * Keep a reference on sk_wmem_alloc, this will be released
1236 * after sk_write_space() call
1237 */
1238 atomic_sub(len - 1, &sk->sk_wmem_alloc);
1236 sk->sk_write_space(sk); 1239 sk->sk_write_space(sk);
1240 len = 1;
1241 }
1237 /* 1242 /*
1238 * if sk_wmem_alloc reached 0, we are last user and should 1243 * if sk_wmem_alloc reaches 0, we must finish what sk_free()
1239 * free this sock, as sk_free() call could not do it. 1244 * could not do because of in-flight packets
1240 */ 1245 */
1241 if (res == 0) 1246 if (atomic_sub_and_test(len, &sk->sk_wmem_alloc))
1242 __sk_free(sk); 1247 __sk_free(sk);
1243} 1248}
1244EXPORT_SYMBOL(sock_wfree); 1249EXPORT_SYMBOL(sock_wfree);
@@ -1697,7 +1702,7 @@ int sock_no_shutdown(struct socket *sock, int how)
1697EXPORT_SYMBOL(sock_no_shutdown); 1702EXPORT_SYMBOL(sock_no_shutdown);
1698 1703
1699int sock_no_setsockopt(struct socket *sock, int level, int optname, 1704int sock_no_setsockopt(struct socket *sock, int level, int optname,
1700 char __user *optval, int optlen) 1705 char __user *optval, unsigned int optlen)
1701{ 1706{
1702 return -EOPNOTSUPP; 1707 return -EOPNOTSUPP;
1703} 1708}
@@ -2018,7 +2023,7 @@ EXPORT_SYMBOL(sock_common_recvmsg);
2018 * Set socket options on an inet socket. 2023 * Set socket options on an inet socket.
2019 */ 2024 */
2020int sock_common_setsockopt(struct socket *sock, int level, int optname, 2025int sock_common_setsockopt(struct socket *sock, int level, int optname,
2021 char __user *optval, int optlen) 2026 char __user *optval, unsigned int optlen)
2022{ 2027{
2023 struct sock *sk = sock->sk; 2028 struct sock *sk = sock->sk;
2024 2029
@@ -2028,7 +2033,7 @@ EXPORT_SYMBOL(sock_common_setsockopt);
2028 2033
2029#ifdef CONFIG_COMPAT 2034#ifdef CONFIG_COMPAT
2030int compat_sock_common_setsockopt(struct socket *sock, int level, int optname, 2035int compat_sock_common_setsockopt(struct socket *sock, int level, int optname,
2031 char __user *optval, int optlen) 2036 char __user *optval, unsigned int optlen)
2032{ 2037{
2033 struct sock *sk = sock->sk; 2038 struct sock *sk = sock->sk;
2034 2039
diff --git a/net/dcb/dcbnl.c b/net/dcb/dcbnl.c
index e0879bfb7dd5..ac1205df6c86 100644
--- a/net/dcb/dcbnl.c
+++ b/net/dcb/dcbnl.c
@@ -194,7 +194,7 @@ static int dcbnl_reply(u8 value, u8 event, u8 cmd, u8 attr, u32 pid,
194 nlmsg_end(dcbnl_skb, nlh); 194 nlmsg_end(dcbnl_skb, nlh);
195 ret = rtnl_unicast(dcbnl_skb, &init_net, pid); 195 ret = rtnl_unicast(dcbnl_skb, &init_net, pid);
196 if (ret) 196 if (ret)
197 goto err; 197 return -EINVAL;
198 198
199 return 0; 199 return 0;
200nlmsg_failure: 200nlmsg_failure:
@@ -275,7 +275,7 @@ static int dcbnl_getpfccfg(struct net_device *netdev, struct nlattr **tb,
275 275
276 ret = rtnl_unicast(dcbnl_skb, &init_net, pid); 276 ret = rtnl_unicast(dcbnl_skb, &init_net, pid);
277 if (ret) 277 if (ret)
278 goto err; 278 goto err_out;
279 279
280 return 0; 280 return 0;
281nlmsg_failure: 281nlmsg_failure:
@@ -316,12 +316,11 @@ static int dcbnl_getperm_hwaddr(struct net_device *netdev, struct nlattr **tb,
316 316
317 ret = rtnl_unicast(dcbnl_skb, &init_net, pid); 317 ret = rtnl_unicast(dcbnl_skb, &init_net, pid);
318 if (ret) 318 if (ret)
319 goto err; 319 goto err_out;
320 320
321 return 0; 321 return 0;
322 322
323nlmsg_failure: 323nlmsg_failure:
324err:
325 kfree_skb(dcbnl_skb); 324 kfree_skb(dcbnl_skb);
326err_out: 325err_out:
327 return -EINVAL; 326 return -EINVAL;
@@ -383,7 +382,7 @@ static int dcbnl_getcap(struct net_device *netdev, struct nlattr **tb,
383 382
384 ret = rtnl_unicast(dcbnl_skb, &init_net, pid); 383 ret = rtnl_unicast(dcbnl_skb, &init_net, pid);
385 if (ret) 384 if (ret)
386 goto err; 385 goto err_out;
387 386
388 return 0; 387 return 0;
389nlmsg_failure: 388nlmsg_failure:
@@ -460,7 +459,7 @@ static int dcbnl_getnumtcs(struct net_device *netdev, struct nlattr **tb,
460 ret = rtnl_unicast(dcbnl_skb, &init_net, pid); 459 ret = rtnl_unicast(dcbnl_skb, &init_net, pid);
461 if (ret) { 460 if (ret) {
462 ret = -EINVAL; 461 ret = -EINVAL;
463 goto err; 462 goto err_out;
464 } 463 }
465 464
466 return 0; 465 return 0;
@@ -799,7 +798,7 @@ static int __dcbnl_pg_getcfg(struct net_device *netdev, struct nlattr **tb,
799 798
800 ret = rtnl_unicast(dcbnl_skb, &init_net, pid); 799 ret = rtnl_unicast(dcbnl_skb, &init_net, pid);
801 if (ret) 800 if (ret)
802 goto err; 801 goto err_out;
803 802
804 return 0; 803 return 0;
805 804
@@ -1063,7 +1062,7 @@ static int dcbnl_bcn_getcfg(struct net_device *netdev, struct nlattr **tb,
1063 1062
1064 ret = rtnl_unicast(dcbnl_skb, &init_net, pid); 1063 ret = rtnl_unicast(dcbnl_skb, &init_net, pid);
1065 if (ret) 1064 if (ret)
1066 goto err; 1065 goto err_out;
1067 1066
1068 return 0; 1067 return 0;
1069 1068
diff --git a/net/dccp/ccids/Kconfig b/net/dccp/ccids/Kconfig
index 4b5db44970aa..8408398cd44e 100644
--- a/net/dccp/ccids/Kconfig
+++ b/net/dccp/ccids/Kconfig
@@ -66,9 +66,9 @@ config IP_DCCP_CCID3_RTO
66 A value of 0 disables this feature by enforcing the value specified 66 A value of 0 disables this feature by enforcing the value specified
67 in RFC 3448. The following values have been suggested as bounds for 67 in RFC 3448. The following values have been suggested as bounds for
68 experimental use: 68 experimental use:
69 * 16-20ms to match the typical multimedia inter-frame interval 69 * 16-20ms to match the typical multimedia inter-frame interval
70 * 100ms as a reasonable compromise [default] 70 * 100ms as a reasonable compromise [default]
71 * 1000ms corresponds to the lower TCP RTO bound (RFC 2988, 2.4) 71 * 1000ms corresponds to the lower TCP RTO bound (RFC 2988, 2.4)
72 72
73 The default of 100ms is a compromise between a large value for 73 The default of 100ms is a compromise between a large value for
74 efficient DCCP implementations, and a small value to avoid disrupting 74 efficient DCCP implementations, and a small value to avoid disrupting
diff --git a/net/dccp/ccids/ccid2.c b/net/dccp/ccids/ccid2.c
index d235294ace23..e8cf99e880b0 100644
--- a/net/dccp/ccids/ccid2.c
+++ b/net/dccp/ccids/ccid2.c
@@ -1,6 +1,4 @@
1/* 1/*
2 * net/dccp/ccids/ccid2.c
3 *
4 * Copyright (c) 2005, 2006 Andrea Bittau <a.bittau@cs.ucl.ac.uk> 2 * Copyright (c) 2005, 2006 Andrea Bittau <a.bittau@cs.ucl.ac.uk>
5 * 3 *
6 * Changes to meet Linux coding standards, and DCCP infrastructure fixes. 4 * Changes to meet Linux coding standards, and DCCP infrastructure fixes.
diff --git a/net/dccp/ccids/ccid2.h b/net/dccp/ccids/ccid2.h
index 2c94ca029010..326ac90fb909 100644
--- a/net/dccp/ccids/ccid2.h
+++ b/net/dccp/ccids/ccid2.h
@@ -1,6 +1,4 @@
1/* 1/*
2 * net/dccp/ccids/ccid2.h
3 *
4 * Copyright (c) 2005 Andrea Bittau <a.bittau@cs.ucl.ac.uk> 2 * Copyright (c) 2005 Andrea Bittau <a.bittau@cs.ucl.ac.uk>
5 * 3 *
6 * This program is free software; you can redistribute it and/or modify 4 * This program is free software; you can redistribute it and/or modify
@@ -40,14 +38,14 @@ struct ccid2_seq {
40#define CCID2_SEQBUF_LEN 1024 38#define CCID2_SEQBUF_LEN 1024
41#define CCID2_SEQBUF_MAX 128 39#define CCID2_SEQBUF_MAX 128
42 40
43/** struct ccid2_hc_tx_sock - CCID2 TX half connection 41/**
44 * 42 * struct ccid2_hc_tx_sock - CCID2 TX half connection
45 * @ccid2hctx_{cwnd,ssthresh,pipe}: as per RFC 4341, section 5 43 * @ccid2hctx_{cwnd,ssthresh,pipe}: as per RFC 4341, section 5
46 * @ccid2hctx_packets_acked - Ack counter for deriving cwnd growth (RFC 3465) 44 * @ccid2hctx_packets_acked - Ack counter for deriving cwnd growth (RFC 3465)
47 * @ccid2hctx_lastrtt -time RTT was last measured 45 * @ccid2hctx_lastrtt -time RTT was last measured
48 * @ccid2hctx_rpseq - last consecutive seqno 46 * @ccid2hctx_rpseq - last consecutive seqno
49 * @ccid2hctx_rpdupack - dupacks since rpseq 47 * @ccid2hctx_rpdupack - dupacks since rpseq
50*/ 48 */
51struct ccid2_hc_tx_sock { 49struct ccid2_hc_tx_sock {
52 u32 ccid2hctx_cwnd; 50 u32 ccid2hctx_cwnd;
53 u32 ccid2hctx_ssthresh; 51 u32 ccid2hctx_ssthresh;
diff --git a/net/dccp/ccids/ccid3.c b/net/dccp/ccids/ccid3.c
index f596ce149c3c..34dcc798c457 100644
--- a/net/dccp/ccids/ccid3.c
+++ b/net/dccp/ccids/ccid3.c
@@ -1,6 +1,4 @@
1/* 1/*
2 * net/dccp/ccids/ccid3.c
3 *
4 * Copyright (c) 2007 The University of Aberdeen, Scotland, UK 2 * Copyright (c) 2007 The University of Aberdeen, Scotland, UK
5 * Copyright (c) 2005-7 The University of Waikato, Hamilton, New Zealand. 3 * Copyright (c) 2005-7 The University of Waikato, Hamilton, New Zealand.
6 * Copyright (c) 2005-7 Ian McDonald <ian.mcdonald@jandi.co.nz> 4 * Copyright (c) 2005-7 Ian McDonald <ian.mcdonald@jandi.co.nz>
@@ -750,7 +748,8 @@ static int ccid3_hc_rx_insert_options(struct sock *sk, struct sk_buff *skb)
750 return 0; 748 return 0;
751} 749}
752 750
753/** ccid3_first_li - Implements [RFC 3448, 6.3.1] 751/**
752 * ccid3_first_li - Implements [RFC 5348, 6.3.1]
754 * 753 *
755 * Determine the length of the first loss interval via inverse lookup. 754 * Determine the length of the first loss interval via inverse lookup.
756 * Assume that X_recv can be computed by the throughput equation 755 * Assume that X_recv can be computed by the throughput equation
diff --git a/net/dccp/ccids/ccid3.h b/net/dccp/ccids/ccid3.h
index 49ca32bd7e79..e5a244143846 100644
--- a/net/dccp/ccids/ccid3.h
+++ b/net/dccp/ccids/ccid3.h
@@ -1,6 +1,4 @@
1/* 1/*
2 * net/dccp/ccids/ccid3.h
3 *
4 * Copyright (c) 2005-7 The University of Waikato, Hamilton, New Zealand. 2 * Copyright (c) 2005-7 The University of Waikato, Hamilton, New Zealand.
5 * Copyright (c) 2007 The University of Aberdeen, Scotland, UK 3 * Copyright (c) 2007 The University of Aberdeen, Scotland, UK
6 * 4 *
@@ -75,8 +73,8 @@ enum ccid3_hc_tx_states {
75 TFRC_SSTATE_TERM, 73 TFRC_SSTATE_TERM,
76}; 74};
77 75
78/** struct ccid3_hc_tx_sock - CCID3 sender half-connection socket 76/**
79 * 77 * struct ccid3_hc_tx_sock - CCID3 sender half-connection socket
80 * @ccid3hctx_x - Current sending rate in 64 * bytes per second 78 * @ccid3hctx_x - Current sending rate in 64 * bytes per second
81 * @ccid3hctx_x_recv - Receive rate in 64 * bytes per second 79 * @ccid3hctx_x_recv - Receive rate in 64 * bytes per second
82 * @ccid3hctx_x_calc - Calculated rate in bytes per second 80 * @ccid3hctx_x_calc - Calculated rate in bytes per second
@@ -119,9 +117,9 @@ struct ccid3_hc_tx_sock {
119 117
120static inline struct ccid3_hc_tx_sock *ccid3_hc_tx_sk(const struct sock *sk) 118static inline struct ccid3_hc_tx_sock *ccid3_hc_tx_sk(const struct sock *sk)
121{ 119{
122 struct ccid3_hc_tx_sock *hctx = ccid_priv(dccp_sk(sk)->dccps_hc_tx_ccid); 120 struct ccid3_hc_tx_sock *hctx = ccid_priv(dccp_sk(sk)->dccps_hc_tx_ccid);
123 BUG_ON(hctx == NULL); 121 BUG_ON(hctx == NULL);
124 return hctx; 122 return hctx;
125} 123}
126 124
127/* TFRC receiver states */ 125/* TFRC receiver states */
@@ -131,22 +129,22 @@ enum ccid3_hc_rx_states {
131 TFRC_RSTATE_TERM = 127, 129 TFRC_RSTATE_TERM = 127,
132}; 130};
133 131
134/** struct ccid3_hc_rx_sock - CCID3 receiver half-connection socket 132/**
135 * 133 * struct ccid3_hc_rx_sock - CCID3 receiver half-connection socket
136 * @ccid3hcrx_x_recv - Receiver estimate of send rate (RFC 3448 4.3) 134 * @ccid3hcrx_x_recv - Receiver estimate of send rate (RFC 3448 4.3)
137 * @ccid3hcrx_rtt - Receiver estimate of rtt (non-standard) 135 * @ccid3hcrx_rtt - Receiver estimate of rtt (non-standard)
138 * @ccid3hcrx_p - Current loss event rate (RFC 3448 5.4) 136 * @ccid3hcrx_p - Current loss event rate (RFC 3448 5.4)
139 * @ccid3hcrx_last_counter - Tracks window counter (RFC 4342, 8.1) 137 * @ccid3hcrx_last_counter - Tracks window counter (RFC 4342, 8.1)
140 * @ccid3hcrx_state - Receiver state, one of %ccid3_hc_rx_states 138 * @ccid3hcrx_state - Receiver state, one of %ccid3_hc_rx_states
141 * @ccid3hcrx_bytes_recv - Total sum of DCCP payload bytes 139 * @ccid3hcrx_bytes_recv - Total sum of DCCP payload bytes
142 * @ccid3hcrx_x_recv - Receiver estimate of send rate (RFC 3448, sec. 4.3) 140 * @ccid3hcrx_x_recv - Receiver estimate of send rate (RFC 3448, sec. 4.3)
143 * @ccid3hcrx_rtt - Receiver estimate of RTT 141 * @ccid3hcrx_rtt - Receiver estimate of RTT
144 * @ccid3hcrx_tstamp_last_feedback - Time at which last feedback was sent 142 * @ccid3hcrx_tstamp_last_feedback - Time at which last feedback was sent
145 * @ccid3hcrx_tstamp_last_ack - Time at which last feedback was sent 143 * @ccid3hcrx_tstamp_last_ack - Time at which last feedback was sent
146 * @ccid3hcrx_hist - Packet history (loss detection + RTT sampling) 144 * @ccid3hcrx_hist - Packet history (loss detection + RTT sampling)
147 * @ccid3hcrx_li_hist - Loss Interval database 145 * @ccid3hcrx_li_hist - Loss Interval database
148 * @ccid3hcrx_s - Received packet size in bytes 146 * @ccid3hcrx_s - Received packet size in bytes
149 * @ccid3hcrx_pinv - Inverse of Loss Event Rate (RFC 4342, sec. 8.5) 147 * @ccid3hcrx_pinv - Inverse of Loss Event Rate (RFC 4342, sec. 8.5)
150 */ 148 */
151struct ccid3_hc_rx_sock { 149struct ccid3_hc_rx_sock {
152 u8 ccid3hcrx_last_counter:4; 150 u8 ccid3hcrx_last_counter:4;
@@ -163,9 +161,9 @@ struct ccid3_hc_rx_sock {
163 161
164static inline struct ccid3_hc_rx_sock *ccid3_hc_rx_sk(const struct sock *sk) 162static inline struct ccid3_hc_rx_sock *ccid3_hc_rx_sk(const struct sock *sk)
165{ 163{
166 struct ccid3_hc_rx_sock *hcrx = ccid_priv(dccp_sk(sk)->dccps_hc_rx_ccid); 164 struct ccid3_hc_rx_sock *hcrx = ccid_priv(dccp_sk(sk)->dccps_hc_rx_ccid);
167 BUG_ON(hcrx == NULL); 165 BUG_ON(hcrx == NULL);
168 return hcrx; 166 return hcrx;
169} 167}
170 168
171#endif /* _DCCP_CCID3_H_ */ 169#endif /* _DCCP_CCID3_H_ */
diff --git a/net/dccp/ccids/lib/loss_interval.c b/net/dccp/ccids/lib/loss_interval.c
index 4d1e40127264..8fc3cbf79071 100644
--- a/net/dccp/ccids/lib/loss_interval.c
+++ b/net/dccp/ccids/lib/loss_interval.c
@@ -1,6 +1,4 @@
1/* 1/*
2 * net/dccp/ccids/lib/loss_interval.c
3 *
4 * Copyright (c) 2007 The University of Aberdeen, Scotland, UK 2 * Copyright (c) 2007 The University of Aberdeen, Scotland, UK
5 * Copyright (c) 2005-7 The University of Waikato, Hamilton, New Zealand. 3 * Copyright (c) 2005-7 The University of Waikato, Hamilton, New Zealand.
6 * Copyright (c) 2005-7 Ian McDonald <ian.mcdonald@jandi.co.nz> 4 * Copyright (c) 2005-7 Ian McDonald <ian.mcdonald@jandi.co.nz>
@@ -21,7 +19,7 @@ static const int tfrc_lh_weights[NINTERVAL] = { 10, 10, 10, 10, 8, 6, 4, 2 };
21/* implements LIFO semantics on the array */ 19/* implements LIFO semantics on the array */
22static inline u8 LIH_INDEX(const u8 ctr) 20static inline u8 LIH_INDEX(const u8 ctr)
23{ 21{
24 return (LIH_SIZE - 1 - (ctr % LIH_SIZE)); 22 return LIH_SIZE - 1 - (ctr % LIH_SIZE);
25} 23}
26 24
27/* the `counter' index always points at the next entry to be populated */ 25/* the `counter' index always points at the next entry to be populated */
@@ -129,7 +127,8 @@ static inline u8 tfrc_lh_is_new_loss(struct tfrc_loss_interval *cur,
129 (cur->li_is_closed || SUB16(new_loss->tfrchrx_ccval, cur->li_ccval) > 4); 127 (cur->li_is_closed || SUB16(new_loss->tfrchrx_ccval, cur->li_ccval) > 4);
130} 128}
131 129
132/** tfrc_lh_interval_add - Insert new record into the Loss Interval database 130/**
131 * tfrc_lh_interval_add - Insert new record into the Loss Interval database
133 * @lh: Loss Interval database 132 * @lh: Loss Interval database
134 * @rh: Receive history containing a fresh loss event 133 * @rh: Receive history containing a fresh loss event
135 * @calc_first_li: Caller-dependent routine to compute length of first interval 134 * @calc_first_li: Caller-dependent routine to compute length of first interval
diff --git a/net/dccp/ccids/lib/loss_interval.h b/net/dccp/ccids/lib/loss_interval.h
index 246018a3b269..d1d2f5383b7d 100644
--- a/net/dccp/ccids/lib/loss_interval.h
+++ b/net/dccp/ccids/lib/loss_interval.h
@@ -1,8 +1,6 @@
1#ifndef _DCCP_LI_HIST_ 1#ifndef _DCCP_LI_HIST_
2#define _DCCP_LI_HIST_ 2#define _DCCP_LI_HIST_
3/* 3/*
4 * net/dccp/ccids/lib/loss_interval.h
5 *
6 * Copyright (c) 2007 The University of Aberdeen, Scotland, UK 4 * Copyright (c) 2007 The University of Aberdeen, Scotland, UK
7 * Copyright (c) 2005-7 The University of Waikato, Hamilton, New Zealand. 5 * Copyright (c) 2005-7 The University of Waikato, Hamilton, New Zealand.
8 * Copyright (c) 2005-7 Ian McDonald <ian.mcdonald@jandi.co.nz> 6 * Copyright (c) 2005-7 Ian McDonald <ian.mcdonald@jandi.co.nz>
diff --git a/net/dccp/ccids/lib/packet_history.c b/net/dccp/ccids/lib/packet_history.c
index b7785b3581ec..3a4f414e94a0 100644
--- a/net/dccp/ccids/lib/packet_history.c
+++ b/net/dccp/ccids/lib/packet_history.c
@@ -1,6 +1,4 @@
1/* 1/*
2 * net/dccp/packet_history.c
3 *
4 * Copyright (c) 2007 The University of Aberdeen, Scotland, UK 2 * Copyright (c) 2007 The University of Aberdeen, Scotland, UK
5 * Copyright (c) 2005-7 The University of Waikato, Hamilton, New Zealand. 3 * Copyright (c) 2005-7 The University of Waikato, Hamilton, New Zealand.
6 * 4 *
@@ -128,7 +126,7 @@ u32 tfrc_tx_hist_rtt(struct tfrc_tx_hist_entry *head, const u64 seqno,
128 126
129 127
130/* 128/*
131 * Receiver History Routines 129 * Receiver History Routines
132 */ 130 */
133static struct kmem_cache *tfrc_rx_hist_slab; 131static struct kmem_cache *tfrc_rx_hist_slab;
134 132
diff --git a/net/dccp/ccids/lib/packet_history.h b/net/dccp/ccids/lib/packet_history.h
index 461cc91cce88..7df6c5299999 100644
--- a/net/dccp/ccids/lib/packet_history.h
+++ b/net/dccp/ccids/lib/packet_history.h
@@ -70,7 +70,6 @@ struct tfrc_rx_hist_entry {
70 70
71/** 71/**
72 * tfrc_rx_hist - RX history structure for TFRC-based protocols 72 * tfrc_rx_hist - RX history structure for TFRC-based protocols
73 *
74 * @ring: Packet history for RTT sampling and loss detection 73 * @ring: Packet history for RTT sampling and loss detection
75 * @loss_count: Number of entries in circular history 74 * @loss_count: Number of entries in circular history
76 * @loss_start: Movable index (for loss detection) 75 * @loss_start: Movable index (for loss detection)
diff --git a/net/dccp/ccids/lib/tfrc.h b/net/dccp/ccids/lib/tfrc.h
index e9720b143275..01bb48e96c2e 100644
--- a/net/dccp/ccids/lib/tfrc.h
+++ b/net/dccp/ccids/lib/tfrc.h
@@ -1,8 +1,6 @@
1#ifndef _TFRC_H_ 1#ifndef _TFRC_H_
2#define _TFRC_H_ 2#define _TFRC_H_
3/* 3/*
4 * net/dccp/ccids/lib/tfrc.h
5 *
6 * Copyright (c) 2007 The University of Aberdeen, Scotland, UK 4 * Copyright (c) 2007 The University of Aberdeen, Scotland, UK
7 * Copyright (c) 2005-6 The University of Waikato, Hamilton, New Zealand. 5 * Copyright (c) 2005-6 The University of Waikato, Hamilton, New Zealand.
8 * Copyright (c) 2005-6 Ian McDonald <ian.mcdonald@jandi.co.nz> 6 * Copyright (c) 2005-6 Ian McDonald <ian.mcdonald@jandi.co.nz>
@@ -32,7 +30,7 @@ extern int tfrc_debug;
32/* integer-arithmetic divisions of type (a * 1000000)/b */ 30/* integer-arithmetic divisions of type (a * 1000000)/b */
33static inline u64 scaled_div(u64 a, u64 b) 31static inline u64 scaled_div(u64 a, u64 b)
34{ 32{
35 BUG_ON(b==0); 33 BUG_ON(b == 0);
36 return div64_u64(a * 1000000, b); 34 return div64_u64(a * 1000000, b);
37} 35}
38 36
diff --git a/net/dccp/ccids/lib/tfrc_equation.c b/net/dccp/ccids/lib/tfrc_equation.c
index c5d3a9e5a5a4..22ca1cf0eb55 100644
--- a/net/dccp/ccids/lib/tfrc_equation.c
+++ b/net/dccp/ccids/lib/tfrc_equation.c
@@ -1,6 +1,4 @@
1/* 1/*
2 * net/dccp/ccids/lib/tfrc_equation.c
3 *
4 * Copyright (c) 2005 The University of Waikato, Hamilton, New Zealand. 2 * Copyright (c) 2005 The University of Waikato, Hamilton, New Zealand.
5 * Copyright (c) 2005 Ian McDonald <ian.mcdonald@jandi.co.nz> 3 * Copyright (c) 2005 Ian McDonald <ian.mcdonald@jandi.co.nz>
6 * Copyright (c) 2005 Arnaldo Carvalho de Melo <acme@conectiva.com.br> 4 * Copyright (c) 2005 Arnaldo Carvalho de Melo <acme@conectiva.com.br>
@@ -79,10 +77,10 @@
79 } 77 }
80 78
81 With the given configuration, we have, with M = TFRC_CALC_X_ARRSIZE-1, 79 With the given configuration, we have, with M = TFRC_CALC_X_ARRSIZE-1,
82 lookup[0][0] = g(1000000/(M+1)) = 1000000 * f(0.2%) 80 lookup[0][0] = g(1000000/(M+1)) = 1000000 * f(0.2%)
83 lookup[M][0] = g(1000000) = 1000000 * f(100%) 81 lookup[M][0] = g(1000000) = 1000000 * f(100%)
84 lookup[0][1] = g(TFRC_SMALLEST_P) = 1000000 * f(0.01%) 82 lookup[0][1] = g(TFRC_SMALLEST_P) = 1000000 * f(0.01%)
85 lookup[M][1] = g(TFRC_CALC_X_SPLIT) = 1000000 * f(5%) 83 lookup[M][1] = g(TFRC_CALC_X_SPLIT) = 1000000 * f(5%)
86 84
87 In summary, the two columns represent f(p) for the following ranges: 85 In summary, the two columns represent f(p) for the following ranges:
88 * The first column is for 0.002 <= p <= 1.0 86 * The first column is for 0.002 <= p <= 1.0
@@ -610,11 +608,10 @@ static inline u32 tfrc_binsearch(u32 fval, u8 small)
610 608
611/** 609/**
612 * tfrc_calc_x - Calculate the send rate as per section 3.1 of RFC3448 610 * tfrc_calc_x - Calculate the send rate as per section 3.1 of RFC3448
613 * 611 * @s: packet size in bytes
614 * @s: packet size in bytes 612 * @R: RTT scaled by 1000000 (i.e., microseconds)
615 * @R: RTT scaled by 1000000 (i.e., microseconds) 613 * @p: loss ratio estimate scaled by 1000000
616 * @p: loss ratio estimate scaled by 1000000 614 * Returns X_calc in bytes per second (not scaled).
617 * Returns X_calc in bytes per second (not scaled).
618 */ 615 */
619u32 tfrc_calc_x(u16 s, u32 R, u32 p) 616u32 tfrc_calc_x(u16 s, u32 R, u32 p)
620{ 617{
@@ -630,17 +627,17 @@ u32 tfrc_calc_x(u16 s, u32 R, u32 p)
630 return ~0U; 627 return ~0U;
631 } 628 }
632 629
633 if (p <= TFRC_CALC_X_SPLIT) { /* 0.0000 < p <= 0.05 */ 630 if (p <= TFRC_CALC_X_SPLIT) { /* 0.0000 < p <= 0.05 */
634 if (p < TFRC_SMALLEST_P) { /* 0.0000 < p < 0.0001 */ 631 if (p < TFRC_SMALLEST_P) { /* 0.0000 < p < 0.0001 */
635 DCCP_WARN("Value of p (%d) below resolution. " 632 DCCP_WARN("Value of p (%d) below resolution. "
636 "Substituting %d\n", p, TFRC_SMALLEST_P); 633 "Substituting %d\n", p, TFRC_SMALLEST_P);
637 index = 0; 634 index = 0;
638 } else /* 0.0001 <= p <= 0.05 */ 635 } else /* 0.0001 <= p <= 0.05 */
639 index = p/TFRC_SMALLEST_P - 1; 636 index = p/TFRC_SMALLEST_P - 1;
640 637
641 f = tfrc_calc_x_lookup[index][1]; 638 f = tfrc_calc_x_lookup[index][1];
642 639
643 } else { /* 0.05 < p <= 1.00 */ 640 } else { /* 0.05 < p <= 1.00 */
644 index = p/(1000000/TFRC_CALC_X_ARRSIZE) - 1; 641 index = p/(1000000/TFRC_CALC_X_ARRSIZE) - 1;
645 642
646 f = tfrc_calc_x_lookup[index][0]; 643 f = tfrc_calc_x_lookup[index][0];
@@ -661,7 +658,6 @@ u32 tfrc_calc_x(u16 s, u32 R, u32 p)
661 658
662/** 659/**
663 * tfrc_calc_x_reverse_lookup - try to find p given f(p) 660 * tfrc_calc_x_reverse_lookup - try to find p given f(p)
664 *
665 * @fvalue: function value to match, scaled by 1000000 661 * @fvalue: function value to match, scaled by 1000000
666 * Returns closest match for p, also scaled by 1000000 662 * Returns closest match for p, also scaled by 1000000
667 */ 663 */
diff --git a/net/dccp/dccp.h b/net/dccp/dccp.h
index d6bc47363b1c..5ef32c2f0d6a 100644
--- a/net/dccp/dccp.h
+++ b/net/dccp/dccp.h
@@ -290,14 +290,14 @@ extern int dccp_disconnect(struct sock *sk, int flags);
290extern int dccp_getsockopt(struct sock *sk, int level, int optname, 290extern int dccp_getsockopt(struct sock *sk, int level, int optname,
291 char __user *optval, int __user *optlen); 291 char __user *optval, int __user *optlen);
292extern int dccp_setsockopt(struct sock *sk, int level, int optname, 292extern int dccp_setsockopt(struct sock *sk, int level, int optname,
293 char __user *optval, int optlen); 293 char __user *optval, unsigned int optlen);
294#ifdef CONFIG_COMPAT 294#ifdef CONFIG_COMPAT
295extern int compat_dccp_getsockopt(struct sock *sk, 295extern int compat_dccp_getsockopt(struct sock *sk,
296 int level, int optname, 296 int level, int optname,
297 char __user *optval, int __user *optlen); 297 char __user *optval, int __user *optlen);
298extern int compat_dccp_setsockopt(struct sock *sk, 298extern int compat_dccp_setsockopt(struct sock *sk,
299 int level, int optname, 299 int level, int optname,
300 char __user *optval, int optlen); 300 char __user *optval, unsigned int optlen);
301#endif 301#endif
302extern int dccp_ioctl(struct sock *sk, int cmd, unsigned long arg); 302extern int dccp_ioctl(struct sock *sk, int cmd, unsigned long arg);
303extern int dccp_sendmsg(struct kiocb *iocb, struct sock *sk, 303extern int dccp_sendmsg(struct kiocb *iocb, struct sock *sk,
diff --git a/net/dccp/ipv4.c b/net/dccp/ipv4.c
index d01c00de1ad0..7302e1498d46 100644
--- a/net/dccp/ipv4.c
+++ b/net/dccp/ipv4.c
@@ -948,7 +948,7 @@ static struct proto dccp_v4_prot = {
948#endif 948#endif
949}; 949};
950 950
951static struct net_protocol dccp_v4_protocol = { 951static const struct net_protocol dccp_v4_protocol = {
952 .handler = dccp_v4_rcv, 952 .handler = dccp_v4_rcv,
953 .err_handler = dccp_v4_err, 953 .err_handler = dccp_v4_err,
954 .no_policy = 1, 954 .no_policy = 1,
diff --git a/net/dccp/ipv6.c b/net/dccp/ipv6.c
index 64f011cc4491..e48ca5d45658 100644
--- a/net/dccp/ipv6.c
+++ b/net/dccp/ipv6.c
@@ -1152,13 +1152,13 @@ static struct proto dccp_v6_prot = {
1152#endif 1152#endif
1153}; 1153};
1154 1154
1155static struct inet6_protocol dccp_v6_protocol = { 1155static const struct inet6_protocol dccp_v6_protocol = {
1156 .handler = dccp_v6_rcv, 1156 .handler = dccp_v6_rcv,
1157 .err_handler = dccp_v6_err, 1157 .err_handler = dccp_v6_err,
1158 .flags = INET6_PROTO_NOPOLICY | INET6_PROTO_FINAL, 1158 .flags = INET6_PROTO_NOPOLICY | INET6_PROTO_FINAL,
1159}; 1159};
1160 1160
1161static struct proto_ops inet6_dccp_ops = { 1161static const struct proto_ops inet6_dccp_ops = {
1162 .family = PF_INET6, 1162 .family = PF_INET6,
1163 .owner = THIS_MODULE, 1163 .owner = THIS_MODULE,
1164 .release = inet6_release, 1164 .release = inet6_release,
diff --git a/net/dccp/proto.c b/net/dccp/proto.c
index 923db06c7e55..a156319fd0ac 100644
--- a/net/dccp/proto.c
+++ b/net/dccp/proto.c
@@ -393,7 +393,7 @@ out:
393EXPORT_SYMBOL_GPL(dccp_ioctl); 393EXPORT_SYMBOL_GPL(dccp_ioctl);
394 394
395static int dccp_setsockopt_service(struct sock *sk, const __be32 service, 395static int dccp_setsockopt_service(struct sock *sk, const __be32 service,
396 char __user *optval, int optlen) 396 char __user *optval, unsigned int optlen)
397{ 397{
398 struct dccp_sock *dp = dccp_sk(sk); 398 struct dccp_sock *dp = dccp_sk(sk);
399 struct dccp_service_list *sl = NULL; 399 struct dccp_service_list *sl = NULL;
@@ -464,7 +464,7 @@ static int dccp_setsockopt_cscov(struct sock *sk, int cscov, bool rx)
464} 464}
465 465
466static int dccp_setsockopt_ccid(struct sock *sk, int type, 466static int dccp_setsockopt_ccid(struct sock *sk, int type,
467 char __user *optval, int optlen) 467 char __user *optval, unsigned int optlen)
468{ 468{
469 u8 *val; 469 u8 *val;
470 int rc = 0; 470 int rc = 0;
@@ -494,7 +494,7 @@ static int dccp_setsockopt_ccid(struct sock *sk, int type,
494} 494}
495 495
496static int do_dccp_setsockopt(struct sock *sk, int level, int optname, 496static int do_dccp_setsockopt(struct sock *sk, int level, int optname,
497 char __user *optval, int optlen) 497 char __user *optval, unsigned int optlen)
498{ 498{
499 struct dccp_sock *dp = dccp_sk(sk); 499 struct dccp_sock *dp = dccp_sk(sk);
500 int val, err = 0; 500 int val, err = 0;
@@ -546,7 +546,7 @@ static int do_dccp_setsockopt(struct sock *sk, int level, int optname,
546} 546}
547 547
548int dccp_setsockopt(struct sock *sk, int level, int optname, 548int dccp_setsockopt(struct sock *sk, int level, int optname,
549 char __user *optval, int optlen) 549 char __user *optval, unsigned int optlen)
550{ 550{
551 if (level != SOL_DCCP) 551 if (level != SOL_DCCP)
552 return inet_csk(sk)->icsk_af_ops->setsockopt(sk, level, 552 return inet_csk(sk)->icsk_af_ops->setsockopt(sk, level,
@@ -559,7 +559,7 @@ EXPORT_SYMBOL_GPL(dccp_setsockopt);
559 559
560#ifdef CONFIG_COMPAT 560#ifdef CONFIG_COMPAT
561int compat_dccp_setsockopt(struct sock *sk, int level, int optname, 561int compat_dccp_setsockopt(struct sock *sk, int level, int optname,
562 char __user *optval, int optlen) 562 char __user *optval, unsigned int optlen)
563{ 563{
564 if (level != SOL_DCCP) 564 if (level != SOL_DCCP)
565 return inet_csk_compat_setsockopt(sk, level, optname, 565 return inet_csk_compat_setsockopt(sk, level, optname,
@@ -1049,10 +1049,10 @@ static int __init dccp_init(void)
1049 * 1049 *
1050 * The methodology is similar to that of the buffer cache. 1050 * The methodology is similar to that of the buffer cache.
1051 */ 1051 */
1052 if (num_physpages >= (128 * 1024)) 1052 if (totalram_pages >= (128 * 1024))
1053 goal = num_physpages >> (21 - PAGE_SHIFT); 1053 goal = totalram_pages >> (21 - PAGE_SHIFT);
1054 else 1054 else
1055 goal = num_physpages >> (23 - PAGE_SHIFT); 1055 goal = totalram_pages >> (23 - PAGE_SHIFT);
1056 1056
1057 if (thash_entries) 1057 if (thash_entries)
1058 goal = (thash_entries * 1058 goal = (thash_entries *
diff --git a/net/decnet/af_decnet.c b/net/decnet/af_decnet.c
index 77d40289653c..7a58c87baf17 100644
--- a/net/decnet/af_decnet.c
+++ b/net/decnet/af_decnet.c
@@ -157,7 +157,7 @@ static struct hlist_head dn_sk_hash[DN_SK_HASH_SIZE];
157static struct hlist_head dn_wild_sk; 157static struct hlist_head dn_wild_sk;
158static atomic_t decnet_memory_allocated; 158static atomic_t decnet_memory_allocated;
159 159
160static int __dn_setsockopt(struct socket *sock, int level, int optname, char __user *optval, int optlen, int flags); 160static int __dn_setsockopt(struct socket *sock, int level, int optname, char __user *optval, unsigned int optlen, int flags);
161static int __dn_getsockopt(struct socket *sock, int level, int optname, char __user *optval, int __user *optlen, int flags); 161static int __dn_getsockopt(struct socket *sock, int level, int optname, char __user *optval, int __user *optlen, int flags);
162 162
163static struct hlist_head *dn_find_list(struct sock *sk) 163static struct hlist_head *dn_find_list(struct sock *sk)
@@ -1325,7 +1325,7 @@ out:
1325 return err; 1325 return err;
1326} 1326}
1327 1327
1328static int dn_setsockopt(struct socket *sock, int level, int optname, char __user *optval, int optlen) 1328static int dn_setsockopt(struct socket *sock, int level, int optname, char __user *optval, unsigned int optlen)
1329{ 1329{
1330 struct sock *sk = sock->sk; 1330 struct sock *sk = sock->sk;
1331 int err; 1331 int err;
@@ -1337,7 +1337,7 @@ static int dn_setsockopt(struct socket *sock, int level, int optname, char __use
1337 return err; 1337 return err;
1338} 1338}
1339 1339
1340static int __dn_setsockopt(struct socket *sock, int level,int optname, char __user *optval, int optlen, int flags) 1340static int __dn_setsockopt(struct socket *sock, int level,int optname, char __user *optval, unsigned int optlen, int flags)
1341{ 1341{
1342 struct sock *sk = sock->sk; 1342 struct sock *sk = sock->sk;
1343 struct dn_scp *scp = DN_SK(sk); 1343 struct dn_scp *scp = DN_SK(sk);
diff --git a/net/decnet/dn_dev.c b/net/decnet/dn_dev.c
index 1c6a5bb6f0c8..6e1f085db06a 100644
--- a/net/decnet/dn_dev.c
+++ b/net/decnet/dn_dev.c
@@ -164,7 +164,7 @@ static int max_t3[] = { 8191 }; /* Must fit in 16 bits when multiplied by BCT3MU
164static int min_priority[1]; 164static int min_priority[1];
165static int max_priority[] = { 127 }; /* From DECnet spec */ 165static int max_priority[] = { 127 }; /* From DECnet spec */
166 166
167static int dn_forwarding_proc(ctl_table *, int, struct file *, 167static int dn_forwarding_proc(ctl_table *, int,
168 void __user *, size_t *, loff_t *); 168 void __user *, size_t *, loff_t *);
169static int dn_forwarding_sysctl(ctl_table *table, 169static int dn_forwarding_sysctl(ctl_table *table,
170 void __user *oldval, size_t __user *oldlenp, 170 void __user *oldval, size_t __user *oldlenp,
@@ -274,7 +274,6 @@ static void dn_dev_sysctl_unregister(struct dn_dev_parms *parms)
274} 274}
275 275
276static int dn_forwarding_proc(ctl_table *table, int write, 276static int dn_forwarding_proc(ctl_table *table, int write,
277 struct file *filep,
278 void __user *buffer, 277 void __user *buffer,
279 size_t *lenp, loff_t *ppos) 278 size_t *lenp, loff_t *ppos)
280{ 279{
@@ -290,7 +289,7 @@ static int dn_forwarding_proc(ctl_table *table, int write,
290 dn_db = dev->dn_ptr; 289 dn_db = dev->dn_ptr;
291 old = dn_db->parms.forwarding; 290 old = dn_db->parms.forwarding;
292 291
293 err = proc_dointvec(table, write, filep, buffer, lenp, ppos); 292 err = proc_dointvec(table, write, buffer, lenp, ppos);
294 293
295 if ((err >= 0) && write) { 294 if ((err >= 0) && write) {
296 if (dn_db->parms.forwarding < 0) 295 if (dn_db->parms.forwarding < 0)
diff --git a/net/decnet/dn_route.c b/net/decnet/dn_route.c
index 9383d3e5a1ab..57662cabaf9b 100644
--- a/net/decnet/dn_route.c
+++ b/net/decnet/dn_route.c
@@ -1750,7 +1750,7 @@ void __init dn_route_init(void)
1750 dn_route_timer.expires = jiffies + decnet_dst_gc_interval * HZ; 1750 dn_route_timer.expires = jiffies + decnet_dst_gc_interval * HZ;
1751 add_timer(&dn_route_timer); 1751 add_timer(&dn_route_timer);
1752 1752
1753 goal = num_physpages >> (26 - PAGE_SHIFT); 1753 goal = totalram_pages >> (26 - PAGE_SHIFT);
1754 1754
1755 for(order = 0; (1UL << order) < goal; order++) 1755 for(order = 0; (1UL << order) < goal; order++)
1756 /* NOTHING */; 1756 /* NOTHING */;
diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
index 5bcd592ae6dd..26b0ab1e9f56 100644
--- a/net/decnet/sysctl_net_decnet.c
+++ b/net/decnet/sysctl_net_decnet.c
@@ -165,7 +165,6 @@ static int dn_node_address_strategy(ctl_table *table,
165} 165}
166 166
167static int dn_node_address_handler(ctl_table *table, int write, 167static int dn_node_address_handler(ctl_table *table, int write,
168 struct file *filp,
169 void __user *buffer, 168 void __user *buffer,
170 size_t *lenp, loff_t *ppos) 169 size_t *lenp, loff_t *ppos)
171{ 170{
@@ -276,7 +275,6 @@ static int dn_def_dev_strategy(ctl_table *table,
276 275
277 276
278static int dn_def_dev_handler(ctl_table *table, int write, 277static int dn_def_dev_handler(ctl_table *table, int write,
279 struct file * filp,
280 void __user *buffer, 278 void __user *buffer,
281 size_t *lenp, loff_t *ppos) 279 size_t *lenp, loff_t *ppos)
282{ 280{
diff --git a/net/ieee802154/dgram.c b/net/ieee802154/dgram.c
index 77ae6852b93d..a413b1bf4465 100644
--- a/net/ieee802154/dgram.c
+++ b/net/ieee802154/dgram.c
@@ -414,7 +414,7 @@ static int dgram_getsockopt(struct sock *sk, int level, int optname,
414} 414}
415 415
416static int dgram_setsockopt(struct sock *sk, int level, int optname, 416static int dgram_setsockopt(struct sock *sk, int level, int optname,
417 char __user *optval, int __user optlen) 417 char __user *optval, unsigned int optlen)
418{ 418{
419 struct dgram_sock *ro = dgram_sk(sk); 419 struct dgram_sock *ro = dgram_sk(sk);
420 int val; 420 int val;
diff --git a/net/ieee802154/netlink.c b/net/ieee802154/netlink.c
index 2106ecbf0308..ca767bde17a4 100644
--- a/net/ieee802154/netlink.c
+++ b/net/ieee802154/netlink.c
@@ -35,6 +35,7 @@
35#include <net/ieee802154_netdev.h> 35#include <net/ieee802154_netdev.h>
36 36
37static unsigned int ieee802154_seq_num; 37static unsigned int ieee802154_seq_num;
38static DEFINE_SPINLOCK(ieee802154_seq_lock);
38 39
39static struct genl_family ieee802154_coordinator_family = { 40static struct genl_family ieee802154_coordinator_family = {
40 .id = GENL_ID_GENERATE, 41 .id = GENL_ID_GENERATE,
@@ -57,12 +58,15 @@ static struct sk_buff *ieee802154_nl_create(int flags, u8 req)
57{ 58{
58 void *hdr; 59 void *hdr;
59 struct sk_buff *msg = nlmsg_new(NLMSG_GOODSIZE, GFP_ATOMIC); 60 struct sk_buff *msg = nlmsg_new(NLMSG_GOODSIZE, GFP_ATOMIC);
61 unsigned long f;
60 62
61 if (!msg) 63 if (!msg)
62 return NULL; 64 return NULL;
63 65
66 spin_lock_irqsave(&ieee802154_seq_lock, f);
64 hdr = genlmsg_put(msg, 0, ieee802154_seq_num++, 67 hdr = genlmsg_put(msg, 0, ieee802154_seq_num++,
65 &ieee802154_coordinator_family, flags, req); 68 &ieee802154_coordinator_family, flags, req);
69 spin_unlock_irqrestore(&ieee802154_seq_lock, f);
66 if (!hdr) { 70 if (!hdr) {
67 nlmsg_free(msg); 71 nlmsg_free(msg);
68 return NULL; 72 return NULL;
diff --git a/net/ieee802154/raw.c b/net/ieee802154/raw.c
index 4681501aae93..30e74eee07d6 100644
--- a/net/ieee802154/raw.c
+++ b/net/ieee802154/raw.c
@@ -244,7 +244,7 @@ static int raw_getsockopt(struct sock *sk, int level, int optname,
244} 244}
245 245
246static int raw_setsockopt(struct sock *sk, int level, int optname, 246static int raw_setsockopt(struct sock *sk, int level, int optname,
247 char __user *optval, int __user optlen) 247 char __user *optval, unsigned int optlen)
248{ 248{
249 return -EOPNOTSUPP; 249 return -EOPNOTSUPP;
250} 250}
diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
index 6c30a73f03f5..57737b8d1711 100644
--- a/net/ipv4/af_inet.c
+++ b/net/ipv4/af_inet.c
@@ -244,7 +244,7 @@ EXPORT_SYMBOL(build_ehash_secret);
244static inline int inet_netns_ok(struct net *net, int protocol) 244static inline int inet_netns_ok(struct net *net, int protocol)
245{ 245{
246 int hash; 246 int hash;
247 struct net_protocol *ipprot; 247 const struct net_protocol *ipprot;
248 248
249 if (net_eq(net, &init_net)) 249 if (net_eq(net, &init_net))
250 return 1; 250 return 1;
@@ -1119,6 +1119,7 @@ int inet_sk_rebuild_header(struct sock *sk)
1119{ 1119{
1120 struct flowi fl = { 1120 struct flowi fl = {
1121 .oif = sk->sk_bound_dev_if, 1121 .oif = sk->sk_bound_dev_if,
1122 .mark = sk->sk_mark,
1122 .nl_u = { 1123 .nl_u = {
1123 .ip4_u = { 1124 .ip4_u = {
1124 .daddr = daddr, 1125 .daddr = daddr,
@@ -1162,7 +1163,7 @@ EXPORT_SYMBOL(inet_sk_rebuild_header);
1162static int inet_gso_send_check(struct sk_buff *skb) 1163static int inet_gso_send_check(struct sk_buff *skb)
1163{ 1164{
1164 struct iphdr *iph; 1165 struct iphdr *iph;
1165 struct net_protocol *ops; 1166 const struct net_protocol *ops;
1166 int proto; 1167 int proto;
1167 int ihl; 1168 int ihl;
1168 int err = -EINVAL; 1169 int err = -EINVAL;
@@ -1198,7 +1199,7 @@ static struct sk_buff *inet_gso_segment(struct sk_buff *skb, int features)
1198{ 1199{
1199 struct sk_buff *segs = ERR_PTR(-EINVAL); 1200 struct sk_buff *segs = ERR_PTR(-EINVAL);
1200 struct iphdr *iph; 1201 struct iphdr *iph;
1201 struct net_protocol *ops; 1202 const struct net_protocol *ops;
1202 int proto; 1203 int proto;
1203 int ihl; 1204 int ihl;
1204 int id; 1205 int id;
@@ -1265,7 +1266,7 @@ out:
1265static struct sk_buff **inet_gro_receive(struct sk_buff **head, 1266static struct sk_buff **inet_gro_receive(struct sk_buff **head,
1266 struct sk_buff *skb) 1267 struct sk_buff *skb)
1267{ 1268{
1268 struct net_protocol *ops; 1269 const struct net_protocol *ops;
1269 struct sk_buff **pp = NULL; 1270 struct sk_buff **pp = NULL;
1270 struct sk_buff *p; 1271 struct sk_buff *p;
1271 struct iphdr *iph; 1272 struct iphdr *iph;
@@ -1342,7 +1343,7 @@ out:
1342 1343
1343static int inet_gro_complete(struct sk_buff *skb) 1344static int inet_gro_complete(struct sk_buff *skb)
1344{ 1345{
1345 struct net_protocol *ops; 1346 const struct net_protocol *ops;
1346 struct iphdr *iph = ip_hdr(skb); 1347 struct iphdr *iph = ip_hdr(skb);
1347 int proto = iph->protocol & (MAX_INET_PROTOS - 1); 1348 int proto = iph->protocol & (MAX_INET_PROTOS - 1);
1348 int err = -ENOSYS; 1349 int err = -ENOSYS;
@@ -1427,13 +1428,13 @@ void snmp_mib_free(void *ptr[2])
1427EXPORT_SYMBOL_GPL(snmp_mib_free); 1428EXPORT_SYMBOL_GPL(snmp_mib_free);
1428 1429
1429#ifdef CONFIG_IP_MULTICAST 1430#ifdef CONFIG_IP_MULTICAST
1430static struct net_protocol igmp_protocol = { 1431static const struct net_protocol igmp_protocol = {
1431 .handler = igmp_rcv, 1432 .handler = igmp_rcv,
1432 .netns_ok = 1, 1433 .netns_ok = 1,
1433}; 1434};
1434#endif 1435#endif
1435 1436
1436static struct net_protocol tcp_protocol = { 1437static const struct net_protocol tcp_protocol = {
1437 .handler = tcp_v4_rcv, 1438 .handler = tcp_v4_rcv,
1438 .err_handler = tcp_v4_err, 1439 .err_handler = tcp_v4_err,
1439 .gso_send_check = tcp_v4_gso_send_check, 1440 .gso_send_check = tcp_v4_gso_send_check,
@@ -1444,7 +1445,7 @@ static struct net_protocol tcp_protocol = {
1444 .netns_ok = 1, 1445 .netns_ok = 1,
1445}; 1446};
1446 1447
1447static struct net_protocol udp_protocol = { 1448static const struct net_protocol udp_protocol = {
1448 .handler = udp_rcv, 1449 .handler = udp_rcv,
1449 .err_handler = udp_err, 1450 .err_handler = udp_err,
1450 .gso_send_check = udp4_ufo_send_check, 1451 .gso_send_check = udp4_ufo_send_check,
@@ -1453,7 +1454,7 @@ static struct net_protocol udp_protocol = {
1453 .netns_ok = 1, 1454 .netns_ok = 1,
1454}; 1455};
1455 1456
1456static struct net_protocol icmp_protocol = { 1457static const struct net_protocol icmp_protocol = {
1457 .handler = icmp_rcv, 1458 .handler = icmp_rcv,
1458 .no_policy = 1, 1459 .no_policy = 1,
1459 .netns_ok = 1, 1460 .netns_ok = 1,
diff --git a/net/ipv4/ah4.c b/net/ipv4/ah4.c
index e878e494296e..5c662703eb1e 100644
--- a/net/ipv4/ah4.c
+++ b/net/ipv4/ah4.c
@@ -311,7 +311,7 @@ static const struct xfrm_type ah_type =
311 .output = ah_output 311 .output = ah_output
312}; 312};
313 313
314static struct net_protocol ah4_protocol = { 314static const struct net_protocol ah4_protocol = {
315 .handler = xfrm4_rcv, 315 .handler = xfrm4_rcv,
316 .err_handler = ah4_err, 316 .err_handler = ah4_err,
317 .no_policy = 1, 317 .no_policy = 1,
diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
index 3863c3a4223f..5df2f6a0b0f0 100644
--- a/net/ipv4/devinet.c
+++ b/net/ipv4/devinet.c
@@ -1077,16 +1077,26 @@ static int inetdev_event(struct notifier_block *this, unsigned long event,
1077 ip_mc_up(in_dev); 1077 ip_mc_up(in_dev);
1078 /* fall through */ 1078 /* fall through */
1079 case NETDEV_CHANGEADDR: 1079 case NETDEV_CHANGEADDR:
1080 if (IN_DEV_ARP_NOTIFY(in_dev)) 1080 /* Send gratuitous ARP to notify of link change */
1081 arp_send(ARPOP_REQUEST, ETH_P_ARP, 1081 if (IN_DEV_ARP_NOTIFY(in_dev)) {
1082 in_dev->ifa_list->ifa_address, 1082 struct in_ifaddr *ifa = in_dev->ifa_list;
1083 dev, 1083
1084 in_dev->ifa_list->ifa_address, 1084 if (ifa)
1085 NULL, dev->dev_addr, NULL); 1085 arp_send(ARPOP_REQUEST, ETH_P_ARP,
1086 ifa->ifa_address, dev,
1087 ifa->ifa_address, NULL,
1088 dev->dev_addr, NULL);
1089 }
1086 break; 1090 break;
1087 case NETDEV_DOWN: 1091 case NETDEV_DOWN:
1088 ip_mc_down(in_dev); 1092 ip_mc_down(in_dev);
1089 break; 1093 break;
1094 case NETDEV_BONDING_OLDTYPE:
1095 ip_mc_unmap(in_dev);
1096 break;
1097 case NETDEV_BONDING_NEWTYPE:
1098 ip_mc_remap(in_dev);
1099 break;
1090 case NETDEV_CHANGEMTU: 1100 case NETDEV_CHANGEMTU:
1091 if (inetdev_valid_mtu(dev->mtu)) 1101 if (inetdev_valid_mtu(dev->mtu))
1092 break; 1102 break;
@@ -1264,10 +1274,10 @@ static void inet_forward_change(struct net *net)
1264} 1274}
1265 1275
1266static int devinet_conf_proc(ctl_table *ctl, int write, 1276static int devinet_conf_proc(ctl_table *ctl, int write,
1267 struct file *filp, void __user *buffer, 1277 void __user *buffer,
1268 size_t *lenp, loff_t *ppos) 1278 size_t *lenp, loff_t *ppos)
1269{ 1279{
1270 int ret = proc_dointvec(ctl, write, filp, buffer, lenp, ppos); 1280 int ret = proc_dointvec(ctl, write, buffer, lenp, ppos);
1271 1281
1272 if (write) { 1282 if (write) {
1273 struct ipv4_devconf *cnf = ctl->extra1; 1283 struct ipv4_devconf *cnf = ctl->extra1;
@@ -1336,12 +1346,12 @@ static int devinet_conf_sysctl(ctl_table *table,
1336} 1346}
1337 1347
1338static int devinet_sysctl_forward(ctl_table *ctl, int write, 1348static int devinet_sysctl_forward(ctl_table *ctl, int write,
1339 struct file *filp, void __user *buffer, 1349 void __user *buffer,
1340 size_t *lenp, loff_t *ppos) 1350 size_t *lenp, loff_t *ppos)
1341{ 1351{
1342 int *valp = ctl->data; 1352 int *valp = ctl->data;
1343 int val = *valp; 1353 int val = *valp;
1344 int ret = proc_dointvec(ctl, write, filp, buffer, lenp, ppos); 1354 int ret = proc_dointvec(ctl, write, buffer, lenp, ppos);
1345 1355
1346 if (write && *valp != val) { 1356 if (write && *valp != val) {
1347 struct net *net = ctl->extra2; 1357 struct net *net = ctl->extra2;
@@ -1366,12 +1376,12 @@ static int devinet_sysctl_forward(ctl_table *ctl, int write,
1366} 1376}
1367 1377
1368int ipv4_doint_and_flush(ctl_table *ctl, int write, 1378int ipv4_doint_and_flush(ctl_table *ctl, int write,
1369 struct file *filp, void __user *buffer, 1379 void __user *buffer,
1370 size_t *lenp, loff_t *ppos) 1380 size_t *lenp, loff_t *ppos)
1371{ 1381{
1372 int *valp = ctl->data; 1382 int *valp = ctl->data;
1373 int val = *valp; 1383 int val = *valp;
1374 int ret = proc_dointvec(ctl, write, filp, buffer, lenp, ppos); 1384 int ret = proc_dointvec(ctl, write, buffer, lenp, ppos);
1375 struct net *net = ctl->extra2; 1385 struct net *net = ctl->extra2;
1376 1386
1377 if (write && *valp != val) 1387 if (write && *valp != val)
diff --git a/net/ipv4/esp4.c b/net/ipv4/esp4.c
index 18bb383ea393..12f7287e902d 100644
--- a/net/ipv4/esp4.c
+++ b/net/ipv4/esp4.c
@@ -615,7 +615,7 @@ static const struct xfrm_type esp_type =
615 .output = esp_output 615 .output = esp_output
616}; 616};
617 617
618static struct net_protocol esp4_protocol = { 618static const struct net_protocol esp4_protocol = {
619 .handler = xfrm4_rcv, 619 .handler = xfrm4_rcv,
620 .err_handler = esp4_err, 620 .err_handler = esp4_err,
621 .no_policy = 1, 621 .no_policy = 1,
diff --git a/net/ipv4/icmp.c b/net/ipv4/icmp.c
index 97c410e84388..5bc13fe816d1 100644
--- a/net/ipv4/icmp.c
+++ b/net/ipv4/icmp.c
@@ -655,7 +655,7 @@ static void icmp_unreach(struct sk_buff *skb)
655 struct iphdr *iph; 655 struct iphdr *iph;
656 struct icmphdr *icmph; 656 struct icmphdr *icmph;
657 int hash, protocol; 657 int hash, protocol;
658 struct net_protocol *ipprot; 658 const struct net_protocol *ipprot;
659 u32 info = 0; 659 u32 info = 0;
660 struct net *net; 660 struct net *net;
661 661
diff --git a/net/ipv4/igmp.c b/net/ipv4/igmp.c
index 01b4284ed694..d41e5de79a82 100644
--- a/net/ipv4/igmp.c
+++ b/net/ipv4/igmp.c
@@ -1298,6 +1298,28 @@ void ip_mc_dec_group(struct in_device *in_dev, __be32 addr)
1298 } 1298 }
1299} 1299}
1300 1300
1301/* Device changing type */
1302
1303void ip_mc_unmap(struct in_device *in_dev)
1304{
1305 struct ip_mc_list *i;
1306
1307 ASSERT_RTNL();
1308
1309 for (i = in_dev->mc_list; i; i = i->next)
1310 igmp_group_dropped(i);
1311}
1312
1313void ip_mc_remap(struct in_device *in_dev)
1314{
1315 struct ip_mc_list *i;
1316
1317 ASSERT_RTNL();
1318
1319 for (i = in_dev->mc_list; i; i = i->next)
1320 igmp_group_added(i);
1321}
1322
1301/* Device going down */ 1323/* Device going down */
1302 1324
1303void ip_mc_down(struct in_device *in_dev) 1325void ip_mc_down(struct in_device *in_dev)
diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
index 22cd19ee44e5..4351ca2cf0b8 100644
--- a/net/ipv4/inet_connection_sock.c
+++ b/net/ipv4/inet_connection_sock.c
@@ -714,7 +714,7 @@ int inet_csk_compat_getsockopt(struct sock *sk, int level, int optname,
714EXPORT_SYMBOL_GPL(inet_csk_compat_getsockopt); 714EXPORT_SYMBOL_GPL(inet_csk_compat_getsockopt);
715 715
716int inet_csk_compat_setsockopt(struct sock *sk, int level, int optname, 716int inet_csk_compat_setsockopt(struct sock *sk, int level, int optname,
717 char __user *optval, int optlen) 717 char __user *optval, unsigned int optlen)
718{ 718{
719 const struct inet_connection_sock *icsk = inet_csk(sk); 719 const struct inet_connection_sock *icsk = inet_csk(sk);
720 720
diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
index 533afaadefd4..41ada9904d31 100644
--- a/net/ipv4/ip_gre.c
+++ b/net/ipv4/ip_gre.c
@@ -66,10 +66,7 @@
66 solution, but it supposes maintaing new variable in ALL 66 solution, but it supposes maintaing new variable in ALL
67 skb, even if no tunneling is used. 67 skb, even if no tunneling is used.
68 68
69 Current solution: t->recursion lock breaks dead loops. It looks 69 Current solution: HARD_TX_LOCK lock breaks dead loops.
70 like dev->tbusy flag, but I preferred new variable, because
71 the semantics is different. One day, when hard_start_xmit
72 will be multithreaded we will have to use skb->encapsulation.
73 70
74 71
75 72
@@ -678,11 +675,6 @@ static netdev_tx_t ipgre_tunnel_xmit(struct sk_buff *skb, struct net_device *dev
678 __be32 dst; 675 __be32 dst;
679 int mtu; 676 int mtu;
680 677
681 if (tunnel->recursion++) {
682 stats->collisions++;
683 goto tx_error;
684 }
685
686 if (dev->type == ARPHRD_ETHER) 678 if (dev->type == ARPHRD_ETHER)
687 IPCB(skb)->flags = 0; 679 IPCB(skb)->flags = 0;
688 680
@@ -820,7 +812,6 @@ static netdev_tx_t ipgre_tunnel_xmit(struct sk_buff *skb, struct net_device *dev
820 ip_rt_put(rt); 812 ip_rt_put(rt);
821 stats->tx_dropped++; 813 stats->tx_dropped++;
822 dev_kfree_skb(skb); 814 dev_kfree_skb(skb);
823 tunnel->recursion--;
824 return NETDEV_TX_OK; 815 return NETDEV_TX_OK;
825 } 816 }
826 if (skb->sk) 817 if (skb->sk)
@@ -888,7 +879,6 @@ static netdev_tx_t ipgre_tunnel_xmit(struct sk_buff *skb, struct net_device *dev
888 nf_reset(skb); 879 nf_reset(skb);
889 880
890 IPTUNNEL_XMIT(); 881 IPTUNNEL_XMIT();
891 tunnel->recursion--;
892 return NETDEV_TX_OK; 882 return NETDEV_TX_OK;
893 883
894tx_error_icmp: 884tx_error_icmp:
@@ -897,7 +887,6 @@ tx_error_icmp:
897tx_error: 887tx_error:
898 stats->tx_errors++; 888 stats->tx_errors++;
899 dev_kfree_skb(skb); 889 dev_kfree_skb(skb);
900 tunnel->recursion--;
901 return NETDEV_TX_OK; 890 return NETDEV_TX_OK;
902} 891}
903 892
@@ -1288,7 +1277,7 @@ static void ipgre_fb_tunnel_init(struct net_device *dev)
1288} 1277}
1289 1278
1290 1279
1291static struct net_protocol ipgre_protocol = { 1280static const struct net_protocol ipgre_protocol = {
1292 .handler = ipgre_rcv, 1281 .handler = ipgre_rcv,
1293 .err_handler = ipgre_err, 1282 .err_handler = ipgre_err,
1294 .netns_ok = 1, 1283 .netns_ok = 1,
diff --git a/net/ipv4/ip_input.c b/net/ipv4/ip_input.c
index db46b4b5b2b9..6c98b43badf4 100644
--- a/net/ipv4/ip_input.c
+++ b/net/ipv4/ip_input.c
@@ -202,7 +202,7 @@ static int ip_local_deliver_finish(struct sk_buff *skb)
202 { 202 {
203 int protocol = ip_hdr(skb)->protocol; 203 int protocol = ip_hdr(skb)->protocol;
204 int hash, raw; 204 int hash, raw;
205 struct net_protocol *ipprot; 205 const struct net_protocol *ipprot;
206 206
207 resubmit: 207 resubmit:
208 raw = raw_local_deliver(skb, protocol); 208 raw = raw_local_deliver(skb, protocol);
diff --git a/net/ipv4/ip_output.c b/net/ipv4/ip_output.c
index 9fe5d7b81580..f9895180f481 100644
--- a/net/ipv4/ip_output.c
+++ b/net/ipv4/ip_output.c
@@ -335,6 +335,7 @@ int ip_queue_xmit(struct sk_buff *skb, int ipfragok)
335 335
336 { 336 {
337 struct flowi fl = { .oif = sk->sk_bound_dev_if, 337 struct flowi fl = { .oif = sk->sk_bound_dev_if,
338 .mark = sk->sk_mark,
338 .nl_u = { .ip4_u = 339 .nl_u = { .ip4_u =
339 { .daddr = daddr, 340 { .daddr = daddr,
340 .saddr = inet->saddr, 341 .saddr = inet->saddr,
diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
index fc7993e9061f..0c0b6e363a20 100644
--- a/net/ipv4/ip_sockglue.c
+++ b/net/ipv4/ip_sockglue.c
@@ -440,7 +440,7 @@ out:
440 */ 440 */
441 441
442static int do_ip_setsockopt(struct sock *sk, int level, 442static int do_ip_setsockopt(struct sock *sk, int level,
443 int optname, char __user *optval, int optlen) 443 int optname, char __user *optval, unsigned int optlen)
444{ 444{
445 struct inet_sock *inet = inet_sk(sk); 445 struct inet_sock *inet = inet_sk(sk);
446 int val = 0, err; 446 int val = 0, err;
@@ -611,6 +611,9 @@ static int do_ip_setsockopt(struct sock *sk, int level,
611 * Check the arguments are allowable 611 * Check the arguments are allowable
612 */ 612 */
613 613
614 if (optlen < sizeof(struct in_addr))
615 goto e_inval;
616
614 err = -EFAULT; 617 err = -EFAULT;
615 if (optlen >= sizeof(struct ip_mreqn)) { 618 if (optlen >= sizeof(struct ip_mreqn)) {
616 if (copy_from_user(&mreq, optval, sizeof(mreq))) 619 if (copy_from_user(&mreq, optval, sizeof(mreq)))
@@ -947,7 +950,7 @@ e_inval:
947} 950}
948 951
949int ip_setsockopt(struct sock *sk, int level, 952int ip_setsockopt(struct sock *sk, int level,
950 int optname, char __user *optval, int optlen) 953 int optname, char __user *optval, unsigned int optlen)
951{ 954{
952 int err; 955 int err;
953 956
@@ -972,7 +975,7 @@ EXPORT_SYMBOL(ip_setsockopt);
972 975
973#ifdef CONFIG_COMPAT 976#ifdef CONFIG_COMPAT
974int compat_ip_setsockopt(struct sock *sk, int level, int optname, 977int compat_ip_setsockopt(struct sock *sk, int level, int optname,
975 char __user *optval, int optlen) 978 char __user *optval, unsigned int optlen)
976{ 979{
977 int err; 980 int err;
978 981
diff --git a/net/ipv4/ipcomp.c b/net/ipv4/ipcomp.c
index 3262ce06294c..38fbf04150ae 100644
--- a/net/ipv4/ipcomp.c
+++ b/net/ipv4/ipcomp.c
@@ -146,7 +146,7 @@ static const struct xfrm_type ipcomp_type = {
146 .output = ipcomp_output 146 .output = ipcomp_output
147}; 147};
148 148
149static struct net_protocol ipcomp4_protocol = { 149static const struct net_protocol ipcomp4_protocol = {
150 .handler = xfrm4_rcv, 150 .handler = xfrm4_rcv,
151 .err_handler = ipcomp4_err, 151 .err_handler = ipcomp4_err,
152 .no_policy = 1, 152 .no_policy = 1,
diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c
index 62548cb0923c..08ccd344de7a 100644
--- a/net/ipv4/ipip.c
+++ b/net/ipv4/ipip.c
@@ -402,11 +402,6 @@ static netdev_tx_t ipip_tunnel_xmit(struct sk_buff *skb, struct net_device *dev)
402 __be32 dst = tiph->daddr; 402 __be32 dst = tiph->daddr;
403 int mtu; 403 int mtu;
404 404
405 if (tunnel->recursion++) {
406 stats->collisions++;
407 goto tx_error;
408 }
409
410 if (skb->protocol != htons(ETH_P_IP)) 405 if (skb->protocol != htons(ETH_P_IP))
411 goto tx_error; 406 goto tx_error;
412 407
@@ -485,7 +480,6 @@ static netdev_tx_t ipip_tunnel_xmit(struct sk_buff *skb, struct net_device *dev)
485 ip_rt_put(rt); 480 ip_rt_put(rt);
486 stats->tx_dropped++; 481 stats->tx_dropped++;
487 dev_kfree_skb(skb); 482 dev_kfree_skb(skb);
488 tunnel->recursion--;
489 return NETDEV_TX_OK; 483 return NETDEV_TX_OK;
490 } 484 }
491 if (skb->sk) 485 if (skb->sk)
@@ -523,7 +517,6 @@ static netdev_tx_t ipip_tunnel_xmit(struct sk_buff *skb, struct net_device *dev)
523 nf_reset(skb); 517 nf_reset(skb);
524 518
525 IPTUNNEL_XMIT(); 519 IPTUNNEL_XMIT();
526 tunnel->recursion--;
527 return NETDEV_TX_OK; 520 return NETDEV_TX_OK;
528 521
529tx_error_icmp: 522tx_error_icmp:
@@ -531,7 +524,6 @@ tx_error_icmp:
531tx_error: 524tx_error:
532 stats->tx_errors++; 525 stats->tx_errors++;
533 dev_kfree_skb(skb); 526 dev_kfree_skb(skb);
534 tunnel->recursion--;
535 return NETDEV_TX_OK; 527 return NETDEV_TX_OK;
536} 528}
537 529
diff --git a/net/ipv4/ipmr.c b/net/ipv4/ipmr.c
index 65d421cf5bc7..630a56df7b47 100644
--- a/net/ipv4/ipmr.c
+++ b/net/ipv4/ipmr.c
@@ -99,10 +99,6 @@ static int ipmr_cache_report(struct net *net,
99 struct sk_buff *pkt, vifi_t vifi, int assert); 99 struct sk_buff *pkt, vifi_t vifi, int assert);
100static int ipmr_fill_mroute(struct sk_buff *skb, struct mfc_cache *c, struct rtmsg *rtm); 100static int ipmr_fill_mroute(struct sk_buff *skb, struct mfc_cache *c, struct rtmsg *rtm);
101 101
102#ifdef CONFIG_IP_PIMSM_V2
103static struct net_protocol pim_protocol;
104#endif
105
106static struct timer_list ipmr_expire_timer; 102static struct timer_list ipmr_expire_timer;
107 103
108/* Service routines creating virtual interfaces: DVMRP tunnels and PIMREG */ 104/* Service routines creating virtual interfaces: DVMRP tunnels and PIMREG */
@@ -935,7 +931,7 @@ static void mrtsock_destruct(struct sock *sk)
935 * MOSPF/PIM router set up we can clean this up. 931 * MOSPF/PIM router set up we can clean this up.
936 */ 932 */
937 933
938int ip_mroute_setsockopt(struct sock *sk, int optname, char __user *optval, int optlen) 934int ip_mroute_setsockopt(struct sock *sk, int optname, char __user *optval, unsigned int optlen)
939{ 935{
940 int ret; 936 int ret;
941 struct vifctl vif; 937 struct vifctl vif;
@@ -1945,7 +1941,7 @@ static const struct file_operations ipmr_mfc_fops = {
1945#endif 1941#endif
1946 1942
1947#ifdef CONFIG_IP_PIMSM_V2 1943#ifdef CONFIG_IP_PIMSM_V2
1948static struct net_protocol pim_protocol = { 1944static const struct net_protocol pim_protocol = {
1949 .handler = pim_rcv, 1945 .handler = pim_rcv,
1950 .netns_ok = 1, 1946 .netns_ok = 1,
1951}; 1947};
diff --git a/net/ipv4/protocol.c b/net/ipv4/protocol.c
index a2e5fc0a15e1..542f22fc98b3 100644
--- a/net/ipv4/protocol.c
+++ b/net/ipv4/protocol.c
@@ -28,14 +28,14 @@
28#include <linux/spinlock.h> 28#include <linux/spinlock.h>
29#include <net/protocol.h> 29#include <net/protocol.h>
30 30
31struct net_protocol *inet_protos[MAX_INET_PROTOS] ____cacheline_aligned_in_smp; 31const struct net_protocol *inet_protos[MAX_INET_PROTOS] ____cacheline_aligned_in_smp;
32static DEFINE_SPINLOCK(inet_proto_lock); 32static DEFINE_SPINLOCK(inet_proto_lock);
33 33
34/* 34/*
35 * Add a protocol handler to the hash tables 35 * Add a protocol handler to the hash tables
36 */ 36 */
37 37
38int inet_add_protocol(struct net_protocol *prot, unsigned char protocol) 38int inet_add_protocol(const struct net_protocol *prot, unsigned char protocol)
39{ 39{
40 int hash, ret; 40 int hash, ret;
41 41
@@ -57,7 +57,7 @@ int inet_add_protocol(struct net_protocol *prot, unsigned char protocol)
57 * Remove a protocol from the hash tables. 57 * Remove a protocol from the hash tables.
58 */ 58 */
59 59
60int inet_del_protocol(struct net_protocol *prot, unsigned char protocol) 60int inet_del_protocol(const struct net_protocol *prot, unsigned char protocol)
61{ 61{
62 int hash, ret; 62 int hash, ret;
63 63
diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
index ebb1e5848bc6..757c9171e7c2 100644
--- a/net/ipv4/raw.c
+++ b/net/ipv4/raw.c
@@ -741,7 +741,7 @@ out: return ret;
741} 741}
742 742
743static int do_raw_setsockopt(struct sock *sk, int level, int optname, 743static int do_raw_setsockopt(struct sock *sk, int level, int optname,
744 char __user *optval, int optlen) 744 char __user *optval, unsigned int optlen)
745{ 745{
746 if (optname == ICMP_FILTER) { 746 if (optname == ICMP_FILTER) {
747 if (inet_sk(sk)->num != IPPROTO_ICMP) 747 if (inet_sk(sk)->num != IPPROTO_ICMP)
@@ -753,7 +753,7 @@ static int do_raw_setsockopt(struct sock *sk, int level, int optname,
753} 753}
754 754
755static int raw_setsockopt(struct sock *sk, int level, int optname, 755static int raw_setsockopt(struct sock *sk, int level, int optname,
756 char __user *optval, int optlen) 756 char __user *optval, unsigned int optlen)
757{ 757{
758 if (level != SOL_RAW) 758 if (level != SOL_RAW)
759 return ip_setsockopt(sk, level, optname, optval, optlen); 759 return ip_setsockopt(sk, level, optname, optval, optlen);
@@ -762,7 +762,7 @@ static int raw_setsockopt(struct sock *sk, int level, int optname,
762 762
763#ifdef CONFIG_COMPAT 763#ifdef CONFIG_COMPAT
764static int compat_raw_setsockopt(struct sock *sk, int level, int optname, 764static int compat_raw_setsockopt(struct sock *sk, int level, int optname,
765 char __user *optval, int optlen) 765 char __user *optval, unsigned int optlen)
766{ 766{
767 if (level != SOL_RAW) 767 if (level != SOL_RAW)
768 return compat_ip_setsockopt(sk, level, optname, optval, optlen); 768 return compat_ip_setsockopt(sk, level, optname, optval, optlen);
diff --git a/net/ipv4/route.c b/net/ipv4/route.c
index 91867d3e6328..bb4199252026 100644
--- a/net/ipv4/route.c
+++ b/net/ipv4/route.c
@@ -3036,7 +3036,7 @@ void ip_rt_multicast_event(struct in_device *in_dev)
3036 3036
3037#ifdef CONFIG_SYSCTL 3037#ifdef CONFIG_SYSCTL
3038static int ipv4_sysctl_rtcache_flush(ctl_table *__ctl, int write, 3038static int ipv4_sysctl_rtcache_flush(ctl_table *__ctl, int write,
3039 struct file *filp, void __user *buffer, 3039 void __user *buffer,
3040 size_t *lenp, loff_t *ppos) 3040 size_t *lenp, loff_t *ppos)
3041{ 3041{
3042 if (write) { 3042 if (write) {
@@ -3046,7 +3046,7 @@ static int ipv4_sysctl_rtcache_flush(ctl_table *__ctl, int write,
3046 3046
3047 memcpy(&ctl, __ctl, sizeof(ctl)); 3047 memcpy(&ctl, __ctl, sizeof(ctl));
3048 ctl.data = &flush_delay; 3048 ctl.data = &flush_delay;
3049 proc_dointvec(&ctl, write, filp, buffer, lenp, ppos); 3049 proc_dointvec(&ctl, write, buffer, lenp, ppos);
3050 3050
3051 net = (struct net *)__ctl->extra1; 3051 net = (struct net *)__ctl->extra1;
3052 rt_cache_flush(net, flush_delay); 3052 rt_cache_flush(net, flush_delay);
@@ -3106,12 +3106,11 @@ static void rt_secret_reschedule(int old)
3106} 3106}
3107 3107
3108static int ipv4_sysctl_rt_secret_interval(ctl_table *ctl, int write, 3108static int ipv4_sysctl_rt_secret_interval(ctl_table *ctl, int write,
3109 struct file *filp,
3110 void __user *buffer, size_t *lenp, 3109 void __user *buffer, size_t *lenp,
3111 loff_t *ppos) 3110 loff_t *ppos)
3112{ 3111{
3113 int old = ip_rt_secret_interval; 3112 int old = ip_rt_secret_interval;
3114 int ret = proc_dointvec_jiffies(ctl, write, filp, buffer, lenp, ppos); 3113 int ret = proc_dointvec_jiffies(ctl, write, buffer, lenp, ppos);
3115 3114
3116 rt_secret_reschedule(old); 3115 rt_secret_reschedule(old);
3117 3116
@@ -3414,7 +3413,7 @@ int __init ip_rt_init(void)
3414 alloc_large_system_hash("IP route cache", 3413 alloc_large_system_hash("IP route cache",
3415 sizeof(struct rt_hash_bucket), 3414 sizeof(struct rt_hash_bucket),
3416 rhash_entries, 3415 rhash_entries,
3417 (num_physpages >= 128 * 1024) ? 3416 (totalram_pages >= 128 * 1024) ?
3418 15 : 17, 3417 15 : 17,
3419 0, 3418 0,
3420 &rt_hash_log, 3419 &rt_hash_log,
diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
index 4710d219f06a..2dcf04d9b005 100644
--- a/net/ipv4/sysctl_net_ipv4.c
+++ b/net/ipv4/sysctl_net_ipv4.c
@@ -36,7 +36,7 @@ static void set_local_port_range(int range[2])
36} 36}
37 37
38/* Validate changes from /proc interface. */ 38/* Validate changes from /proc interface. */
39static int ipv4_local_port_range(ctl_table *table, int write, struct file *filp, 39static int ipv4_local_port_range(ctl_table *table, int write,
40 void __user *buffer, 40 void __user *buffer,
41 size_t *lenp, loff_t *ppos) 41 size_t *lenp, loff_t *ppos)
42{ 42{
@@ -51,7 +51,7 @@ static int ipv4_local_port_range(ctl_table *table, int write, struct file *filp,
51 }; 51 };
52 52
53 inet_get_local_port_range(range, range + 1); 53 inet_get_local_port_range(range, range + 1);
54 ret = proc_dointvec_minmax(&tmp, write, filp, buffer, lenp, ppos); 54 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
55 55
56 if (write && ret == 0) { 56 if (write && ret == 0) {
57 if (range[1] < range[0]) 57 if (range[1] < range[0])
@@ -91,7 +91,7 @@ static int ipv4_sysctl_local_port_range(ctl_table *table,
91} 91}
92 92
93 93
94static int proc_tcp_congestion_control(ctl_table *ctl, int write, struct file * filp, 94static int proc_tcp_congestion_control(ctl_table *ctl, int write,
95 void __user *buffer, size_t *lenp, loff_t *ppos) 95 void __user *buffer, size_t *lenp, loff_t *ppos)
96{ 96{
97 char val[TCP_CA_NAME_MAX]; 97 char val[TCP_CA_NAME_MAX];
@@ -103,7 +103,7 @@ static int proc_tcp_congestion_control(ctl_table *ctl, int write, struct file *
103 103
104 tcp_get_default_congestion_control(val); 104 tcp_get_default_congestion_control(val);
105 105
106 ret = proc_dostring(&tbl, write, filp, buffer, lenp, ppos); 106 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
107 if (write && ret == 0) 107 if (write && ret == 0)
108 ret = tcp_set_default_congestion_control(val); 108 ret = tcp_set_default_congestion_control(val);
109 return ret; 109 return ret;
@@ -129,7 +129,7 @@ static int sysctl_tcp_congestion_control(ctl_table *table,
129} 129}
130 130
131static int proc_tcp_available_congestion_control(ctl_table *ctl, 131static int proc_tcp_available_congestion_control(ctl_table *ctl,
132 int write, struct file * filp, 132 int write,
133 void __user *buffer, size_t *lenp, 133 void __user *buffer, size_t *lenp,
134 loff_t *ppos) 134 loff_t *ppos)
135{ 135{
@@ -140,13 +140,13 @@ static int proc_tcp_available_congestion_control(ctl_table *ctl,
140 if (!tbl.data) 140 if (!tbl.data)
141 return -ENOMEM; 141 return -ENOMEM;
142 tcp_get_available_congestion_control(tbl.data, TCP_CA_BUF_MAX); 142 tcp_get_available_congestion_control(tbl.data, TCP_CA_BUF_MAX);
143 ret = proc_dostring(&tbl, write, filp, buffer, lenp, ppos); 143 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
144 kfree(tbl.data); 144 kfree(tbl.data);
145 return ret; 145 return ret;
146} 146}
147 147
148static int proc_allowed_congestion_control(ctl_table *ctl, 148static int proc_allowed_congestion_control(ctl_table *ctl,
149 int write, struct file * filp, 149 int write,
150 void __user *buffer, size_t *lenp, 150 void __user *buffer, size_t *lenp,
151 loff_t *ppos) 151 loff_t *ppos)
152{ 152{
@@ -158,7 +158,7 @@ static int proc_allowed_congestion_control(ctl_table *ctl,
158 return -ENOMEM; 158 return -ENOMEM;
159 159
160 tcp_get_allowed_congestion_control(tbl.data, tbl.maxlen); 160 tcp_get_allowed_congestion_control(tbl.data, tbl.maxlen);
161 ret = proc_dostring(&tbl, write, filp, buffer, lenp, ppos); 161 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
162 if (write && ret == 0) 162 if (write && ret == 0)
163 ret = tcp_set_allowed_congestion_control(tbl.data); 163 ret = tcp_set_allowed_congestion_control(tbl.data);
164 kfree(tbl.data); 164 kfree(tbl.data);
diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
index edeea060db44..64d0af675823 100644
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ -580,7 +580,7 @@ ssize_t tcp_splice_read(struct socket *sock, loff_t *ppos,
580 580
581 lock_sock(sk); 581 lock_sock(sk);
582 582
583 timeo = sock_rcvtimeo(sk, flags & SPLICE_F_NONBLOCK); 583 timeo = sock_rcvtimeo(sk, sock->file->f_flags & O_NONBLOCK);
584 while (tss.len) { 584 while (tss.len) {
585 ret = __tcp_splice_read(sk, &tss); 585 ret = __tcp_splice_read(sk, &tss);
586 if (ret < 0) 586 if (ret < 0)
@@ -2012,7 +2012,7 @@ int tcp_disconnect(struct sock *sk, int flags)
2012 tp->snd_cwnd = 2; 2012 tp->snd_cwnd = 2;
2013 icsk->icsk_probes_out = 0; 2013 icsk->icsk_probes_out = 0;
2014 tp->packets_out = 0; 2014 tp->packets_out = 0;
2015 tp->snd_ssthresh = 0x7fffffff; 2015 tp->snd_ssthresh = TCP_INFINITE_SSTHRESH;
2016 tp->snd_cwnd_cnt = 0; 2016 tp->snd_cwnd_cnt = 0;
2017 tp->bytes_acked = 0; 2017 tp->bytes_acked = 0;
2018 tcp_set_ca_state(sk, TCP_CA_Open); 2018 tcp_set_ca_state(sk, TCP_CA_Open);
@@ -2032,7 +2032,7 @@ int tcp_disconnect(struct sock *sk, int flags)
2032 * Socket option code for TCP. 2032 * Socket option code for TCP.
2033 */ 2033 */
2034static int do_tcp_setsockopt(struct sock *sk, int level, 2034static int do_tcp_setsockopt(struct sock *sk, int level,
2035 int optname, char __user *optval, int optlen) 2035 int optname, char __user *optval, unsigned int optlen)
2036{ 2036{
2037 struct tcp_sock *tp = tcp_sk(sk); 2037 struct tcp_sock *tp = tcp_sk(sk);
2038 struct inet_connection_sock *icsk = inet_csk(sk); 2038 struct inet_connection_sock *icsk = inet_csk(sk);
@@ -2047,7 +2047,7 @@ static int do_tcp_setsockopt(struct sock *sk, int level,
2047 return -EINVAL; 2047 return -EINVAL;
2048 2048
2049 val = strncpy_from_user(name, optval, 2049 val = strncpy_from_user(name, optval,
2050 min(TCP_CA_NAME_MAX-1, optlen)); 2050 min_t(long, TCP_CA_NAME_MAX-1, optlen));
2051 if (val < 0) 2051 if (val < 0)
2052 return -EFAULT; 2052 return -EFAULT;
2053 name[val] = 0; 2053 name[val] = 0;
@@ -2220,7 +2220,7 @@ static int do_tcp_setsockopt(struct sock *sk, int level,
2220} 2220}
2221 2221
2222int tcp_setsockopt(struct sock *sk, int level, int optname, char __user *optval, 2222int tcp_setsockopt(struct sock *sk, int level, int optname, char __user *optval,
2223 int optlen) 2223 unsigned int optlen)
2224{ 2224{
2225 struct inet_connection_sock *icsk = inet_csk(sk); 2225 struct inet_connection_sock *icsk = inet_csk(sk);
2226 2226
@@ -2232,7 +2232,7 @@ int tcp_setsockopt(struct sock *sk, int level, int optname, char __user *optval,
2232 2232
2233#ifdef CONFIG_COMPAT 2233#ifdef CONFIG_COMPAT
2234int compat_tcp_setsockopt(struct sock *sk, int level, int optname, 2234int compat_tcp_setsockopt(struct sock *sk, int level, int optname,
2235 char __user *optval, int optlen) 2235 char __user *optval, unsigned int optlen)
2236{ 2236{
2237 if (level != SOL_TCP) 2237 if (level != SOL_TCP)
2238 return inet_csk_compat_setsockopt(sk, level, optname, 2238 return inet_csk_compat_setsockopt(sk, level, optname,
@@ -2862,7 +2862,7 @@ void __init tcp_init(void)
2862 alloc_large_system_hash("TCP established", 2862 alloc_large_system_hash("TCP established",
2863 sizeof(struct inet_ehash_bucket), 2863 sizeof(struct inet_ehash_bucket),
2864 thash_entries, 2864 thash_entries,
2865 (num_physpages >= 128 * 1024) ? 2865 (totalram_pages >= 128 * 1024) ?
2866 13 : 15, 2866 13 : 15,
2867 0, 2867 0,
2868 &tcp_hashinfo.ehash_size, 2868 &tcp_hashinfo.ehash_size,
@@ -2879,7 +2879,7 @@ void __init tcp_init(void)
2879 alloc_large_system_hash("TCP bind", 2879 alloc_large_system_hash("TCP bind",
2880 sizeof(struct inet_bind_hashbucket), 2880 sizeof(struct inet_bind_hashbucket),
2881 tcp_hashinfo.ehash_size, 2881 tcp_hashinfo.ehash_size,
2882 (num_physpages >= 128 * 1024) ? 2882 (totalram_pages >= 128 * 1024) ?
2883 13 : 15, 2883 13 : 15,
2884 0, 2884 0,
2885 &tcp_hashinfo.bhash_size, 2885 &tcp_hashinfo.bhash_size,
diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
index af6d6fa00db1..d86784be7ab3 100644
--- a/net/ipv4/tcp_input.c
+++ b/net/ipv4/tcp_input.c
@@ -761,7 +761,7 @@ void tcp_update_metrics(struct sock *sk)
761 set_dst_metric_rtt(dst, RTAX_RTTVAR, var); 761 set_dst_metric_rtt(dst, RTAX_RTTVAR, var);
762 } 762 }
763 763
764 if (tp->snd_ssthresh >= 0xFFFF) { 764 if (tcp_in_initial_slowstart(tp)) {
765 /* Slow start still did not finish. */ 765 /* Slow start still did not finish. */
766 if (dst_metric(dst, RTAX_SSTHRESH) && 766 if (dst_metric(dst, RTAX_SSTHRESH) &&
767 !dst_metric_locked(dst, RTAX_SSTHRESH) && 767 !dst_metric_locked(dst, RTAX_SSTHRESH) &&
diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
index 0543561da999..7cda24b53f61 100644
--- a/net/ipv4/tcp_ipv4.c
+++ b/net/ipv4/tcp_ipv4.c
@@ -1808,7 +1808,7 @@ static int tcp_v4_init_sock(struct sock *sk)
1808 /* See draft-stevens-tcpca-spec-01 for discussion of the 1808 /* See draft-stevens-tcpca-spec-01 for discussion of the
1809 * initialization of these values. 1809 * initialization of these values.
1810 */ 1810 */
1811 tp->snd_ssthresh = 0x7fffffff; /* Infinity */ 1811 tp->snd_ssthresh = TCP_INFINITE_SSTHRESH;
1812 tp->snd_cwnd_clamp = ~0; 1812 tp->snd_cwnd_clamp = ~0;
1813 tp->mss_cache = 536; 1813 tp->mss_cache = 536;
1814 1814
@@ -2284,7 +2284,7 @@ static void get_tcp4_sock(struct sock *sk, struct seq_file *f, int i, int *len)
2284 jiffies_to_clock_t(icsk->icsk_ack.ato), 2284 jiffies_to_clock_t(icsk->icsk_ack.ato),
2285 (icsk->icsk_ack.quick << 1) | icsk->icsk_ack.pingpong, 2285 (icsk->icsk_ack.quick << 1) | icsk->icsk_ack.pingpong,
2286 tp->snd_cwnd, 2286 tp->snd_cwnd,
2287 tp->snd_ssthresh >= 0xFFFF ? -1 : tp->snd_ssthresh, 2287 tcp_in_initial_slowstart(tp) ? -1 : tp->snd_ssthresh,
2288 len); 2288 len);
2289} 2289}
2290 2290
diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
index e48c37d74d77..e320afea07fc 100644
--- a/net/ipv4/tcp_minisocks.c
+++ b/net/ipv4/tcp_minisocks.c
@@ -363,7 +363,7 @@ void tcp_twsk_destructor(struct sock *sk)
363#ifdef CONFIG_TCP_MD5SIG 363#ifdef CONFIG_TCP_MD5SIG
364 struct tcp_timewait_sock *twsk = tcp_twsk(sk); 364 struct tcp_timewait_sock *twsk = tcp_twsk(sk);
365 if (twsk->tw_md5_keylen) 365 if (twsk->tw_md5_keylen)
366 tcp_put_md5sig_pool(); 366 tcp_free_md5sig_pool();
367#endif 367#endif
368} 368}
369 369
@@ -410,7 +410,7 @@ struct sock *tcp_create_openreq_child(struct sock *sk, struct request_sock *req,
410 newtp->retrans_out = 0; 410 newtp->retrans_out = 0;
411 newtp->sacked_out = 0; 411 newtp->sacked_out = 0;
412 newtp->fackets_out = 0; 412 newtp->fackets_out = 0;
413 newtp->snd_ssthresh = 0x7fffffff; 413 newtp->snd_ssthresh = TCP_INFINITE_SSTHRESH;
414 414
415 /* So many TCP implementations out there (incorrectly) count the 415 /* So many TCP implementations out there (incorrectly) count the
416 * initial SYN frame in their delayed-ACK and congestion control 416 * initial SYN frame in their delayed-ACK and congestion control
@@ -644,6 +644,7 @@ struct sock *tcp_check_req(struct sock *sk, struct sk_buff *skb,
644 /* If TCP_DEFER_ACCEPT is set, drop bare ACK. */ 644 /* If TCP_DEFER_ACCEPT is set, drop bare ACK. */
645 if (inet_csk(sk)->icsk_accept_queue.rskq_defer_accept && 645 if (inet_csk(sk)->icsk_accept_queue.rskq_defer_accept &&
646 TCP_SKB_CB(skb)->end_seq == tcp_rsk(req)->rcv_isn + 1) { 646 TCP_SKB_CB(skb)->end_seq == tcp_rsk(req)->rcv_isn + 1) {
647 inet_csk(sk)->icsk_accept_queue.rskq_defer_accept--;
647 inet_rsk(req)->acked = 1; 648 inet_rsk(req)->acked = 1;
648 return NULL; 649 return NULL;
649 } 650 }
diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c
index 5200aab0ca97..fcd278a7080e 100644
--- a/net/ipv4/tcp_output.c
+++ b/net/ipv4/tcp_output.c
@@ -361,6 +361,7 @@ static inline int tcp_urg_mode(const struct tcp_sock *tp)
361#define OPTION_SACK_ADVERTISE (1 << 0) 361#define OPTION_SACK_ADVERTISE (1 << 0)
362#define OPTION_TS (1 << 1) 362#define OPTION_TS (1 << 1)
363#define OPTION_MD5 (1 << 2) 363#define OPTION_MD5 (1 << 2)
364#define OPTION_WSCALE (1 << 3)
364 365
365struct tcp_out_options { 366struct tcp_out_options {
366 u8 options; /* bit field of OPTION_* */ 367 u8 options; /* bit field of OPTION_* */
@@ -427,7 +428,7 @@ static void tcp_options_write(__be32 *ptr, struct tcp_sock *tp,
427 TCPOLEN_SACK_PERM); 428 TCPOLEN_SACK_PERM);
428 } 429 }
429 430
430 if (unlikely(opts->ws)) { 431 if (unlikely(OPTION_WSCALE & opts->options)) {
431 *ptr++ = htonl((TCPOPT_NOP << 24) | 432 *ptr++ = htonl((TCPOPT_NOP << 24) |
432 (TCPOPT_WINDOW << 16) | 433 (TCPOPT_WINDOW << 16) |
433 (TCPOLEN_WINDOW << 8) | 434 (TCPOLEN_WINDOW << 8) |
@@ -494,8 +495,8 @@ static unsigned tcp_syn_options(struct sock *sk, struct sk_buff *skb,
494 } 495 }
495 if (likely(sysctl_tcp_window_scaling)) { 496 if (likely(sysctl_tcp_window_scaling)) {
496 opts->ws = tp->rx_opt.rcv_wscale; 497 opts->ws = tp->rx_opt.rcv_wscale;
497 if (likely(opts->ws)) 498 opts->options |= OPTION_WSCALE;
498 size += TCPOLEN_WSCALE_ALIGNED; 499 size += TCPOLEN_WSCALE_ALIGNED;
499 } 500 }
500 if (likely(sysctl_tcp_sack)) { 501 if (likely(sysctl_tcp_sack)) {
501 opts->options |= OPTION_SACK_ADVERTISE; 502 opts->options |= OPTION_SACK_ADVERTISE;
@@ -537,8 +538,8 @@ static unsigned tcp_synack_options(struct sock *sk,
537 538
538 if (likely(ireq->wscale_ok)) { 539 if (likely(ireq->wscale_ok)) {
539 opts->ws = ireq->rcv_wscale; 540 opts->ws = ireq->rcv_wscale;
540 if (likely(opts->ws)) 541 opts->options |= OPTION_WSCALE;
541 size += TCPOLEN_WSCALE_ALIGNED; 542 size += TCPOLEN_WSCALE_ALIGNED;
542 } 543 }
543 if (likely(doing_ts)) { 544 if (likely(doing_ts)) {
544 opts->options |= OPTION_TS; 545 opts->options |= OPTION_TS;
diff --git a/net/ipv4/tunnel4.c b/net/ipv4/tunnel4.c
index cb1f0e83830b..3959e0ca456a 100644
--- a/net/ipv4/tunnel4.c
+++ b/net/ipv4/tunnel4.c
@@ -132,7 +132,7 @@ static void tunnel64_err(struct sk_buff *skb, u32 info)
132} 132}
133#endif 133#endif
134 134
135static struct net_protocol tunnel4_protocol = { 135static const struct net_protocol tunnel4_protocol = {
136 .handler = tunnel4_rcv, 136 .handler = tunnel4_rcv,
137 .err_handler = tunnel4_err, 137 .err_handler = tunnel4_err,
138 .no_policy = 1, 138 .no_policy = 1,
@@ -140,7 +140,7 @@ static struct net_protocol tunnel4_protocol = {
140}; 140};
141 141
142#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) 142#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
143static struct net_protocol tunnel64_protocol = { 143static const struct net_protocol tunnel64_protocol = {
144 .handler = tunnel64_rcv, 144 .handler = tunnel64_rcv,
145 .err_handler = tunnel64_err, 145 .err_handler = tunnel64_err,
146 .no_policy = 1, 146 .no_policy = 1,
diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
index ebaaa7f973d7..d0d436d6216c 100644
--- a/net/ipv4/udp.c
+++ b/net/ipv4/udp.c
@@ -696,6 +696,7 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
696 696
697 if (rt == NULL) { 697 if (rt == NULL) {
698 struct flowi fl = { .oif = ipc.oif, 698 struct flowi fl = { .oif = ipc.oif,
699 .mark = sk->sk_mark,
699 .nl_u = { .ip4_u = 700 .nl_u = { .ip4_u =
700 { .daddr = faddr, 701 { .daddr = faddr,
701 .saddr = saddr, 702 .saddr = saddr,
@@ -840,6 +841,42 @@ out:
840 return ret; 841 return ret;
841} 842}
842 843
844
845/**
846 * first_packet_length - return length of first packet in receive queue
847 * @sk: socket
848 *
849 * Drops all bad checksum frames, until a valid one is found.
850 * Returns the length of found skb, or 0 if none is found.
851 */
852static unsigned int first_packet_length(struct sock *sk)
853{
854 struct sk_buff_head list_kill, *rcvq = &sk->sk_receive_queue;
855 struct sk_buff *skb;
856 unsigned int res;
857
858 __skb_queue_head_init(&list_kill);
859
860 spin_lock_bh(&rcvq->lock);
861 while ((skb = skb_peek(rcvq)) != NULL &&
862 udp_lib_checksum_complete(skb)) {
863 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
864 IS_UDPLITE(sk));
865 __skb_unlink(skb, rcvq);
866 __skb_queue_tail(&list_kill, skb);
867 }
868 res = skb ? skb->len : 0;
869 spin_unlock_bh(&rcvq->lock);
870
871 if (!skb_queue_empty(&list_kill)) {
872 lock_sock(sk);
873 __skb_queue_purge(&list_kill);
874 sk_mem_reclaim_partial(sk);
875 release_sock(sk);
876 }
877 return res;
878}
879
843/* 880/*
844 * IOCTL requests applicable to the UDP protocol 881 * IOCTL requests applicable to the UDP protocol
845 */ 882 */
@@ -856,21 +893,16 @@ int udp_ioctl(struct sock *sk, int cmd, unsigned long arg)
856 893
857 case SIOCINQ: 894 case SIOCINQ:
858 { 895 {
859 struct sk_buff *skb; 896 unsigned int amount = first_packet_length(sk);
860 unsigned long amount;
861 897
862 amount = 0; 898 if (amount)
863 spin_lock_bh(&sk->sk_receive_queue.lock);
864 skb = skb_peek(&sk->sk_receive_queue);
865 if (skb != NULL) {
866 /* 899 /*
867 * We will only return the amount 900 * We will only return the amount
868 * of this packet since that is all 901 * of this packet since that is all
869 * that will be read. 902 * that will be read.
870 */ 903 */
871 amount = skb->len - sizeof(struct udphdr); 904 amount -= sizeof(struct udphdr);
872 } 905
873 spin_unlock_bh(&sk->sk_receive_queue.lock);
874 return put_user(amount, (int __user *)arg); 906 return put_user(amount, (int __user *)arg);
875 } 907 }
876 908
@@ -1359,7 +1391,7 @@ void udp_destroy_sock(struct sock *sk)
1359 * Socket option code for UDP 1391 * Socket option code for UDP
1360 */ 1392 */
1361int udp_lib_setsockopt(struct sock *sk, int level, int optname, 1393int udp_lib_setsockopt(struct sock *sk, int level, int optname,
1362 char __user *optval, int optlen, 1394 char __user *optval, unsigned int optlen,
1363 int (*push_pending_frames)(struct sock *)) 1395 int (*push_pending_frames)(struct sock *))
1364{ 1396{
1365 struct udp_sock *up = udp_sk(sk); 1397 struct udp_sock *up = udp_sk(sk);
@@ -1441,7 +1473,7 @@ int udp_lib_setsockopt(struct sock *sk, int level, int optname,
1441EXPORT_SYMBOL(udp_lib_setsockopt); 1473EXPORT_SYMBOL(udp_lib_setsockopt);
1442 1474
1443int udp_setsockopt(struct sock *sk, int level, int optname, 1475int udp_setsockopt(struct sock *sk, int level, int optname,
1444 char __user *optval, int optlen) 1476 char __user *optval, unsigned int optlen)
1445{ 1477{
1446 if (level == SOL_UDP || level == SOL_UDPLITE) 1478 if (level == SOL_UDP || level == SOL_UDPLITE)
1447 return udp_lib_setsockopt(sk, level, optname, optval, optlen, 1479 return udp_lib_setsockopt(sk, level, optname, optval, optlen,
@@ -1451,7 +1483,7 @@ int udp_setsockopt(struct sock *sk, int level, int optname,
1451 1483
1452#ifdef CONFIG_COMPAT 1484#ifdef CONFIG_COMPAT
1453int compat_udp_setsockopt(struct sock *sk, int level, int optname, 1485int compat_udp_setsockopt(struct sock *sk, int level, int optname,
1454 char __user *optval, int optlen) 1486 char __user *optval, unsigned int optlen)
1455{ 1487{
1456 if (level == SOL_UDP || level == SOL_UDPLITE) 1488 if (level == SOL_UDP || level == SOL_UDPLITE)
1457 return udp_lib_setsockopt(sk, level, optname, optval, optlen, 1489 return udp_lib_setsockopt(sk, level, optname, optval, optlen,
@@ -1539,29 +1571,11 @@ unsigned int udp_poll(struct file *file, struct socket *sock, poll_table *wait)
1539{ 1571{
1540 unsigned int mask = datagram_poll(file, sock, wait); 1572 unsigned int mask = datagram_poll(file, sock, wait);
1541 struct sock *sk = sock->sk; 1573 struct sock *sk = sock->sk;
1542 int is_lite = IS_UDPLITE(sk);
1543 1574
1544 /* Check for false positives due to checksum errors */ 1575 /* Check for false positives due to checksum errors */
1545 if ((mask & POLLRDNORM) && 1576 if ((mask & POLLRDNORM) && !(file->f_flags & O_NONBLOCK) &&
1546 !(file->f_flags & O_NONBLOCK) && 1577 !(sk->sk_shutdown & RCV_SHUTDOWN) && !first_packet_length(sk))
1547 !(sk->sk_shutdown & RCV_SHUTDOWN)) { 1578 mask &= ~(POLLIN | POLLRDNORM);
1548 struct sk_buff_head *rcvq = &sk->sk_receive_queue;
1549 struct sk_buff *skb;
1550
1551 spin_lock_bh(&rcvq->lock);
1552 while ((skb = skb_peek(rcvq)) != NULL &&
1553 udp_lib_checksum_complete(skb)) {
1554 UDP_INC_STATS_BH(sock_net(sk),
1555 UDP_MIB_INERRORS, is_lite);
1556 __skb_unlink(skb, rcvq);
1557 kfree_skb(skb);
1558 }
1559 spin_unlock_bh(&rcvq->lock);
1560
1561 /* nothing to see, move along */
1562 if (skb == NULL)
1563 mask &= ~(POLLIN | POLLRDNORM);
1564 }
1565 1579
1566 return mask; 1580 return mask;
1567 1581
diff --git a/net/ipv4/udp_impl.h b/net/ipv4/udp_impl.h
index 9f4a6165f722..aaad650d47d9 100644
--- a/net/ipv4/udp_impl.h
+++ b/net/ipv4/udp_impl.h
@@ -11,13 +11,13 @@ extern void __udp4_lib_err(struct sk_buff *, u32, struct udp_table *);
11extern int udp_v4_get_port(struct sock *sk, unsigned short snum); 11extern int udp_v4_get_port(struct sock *sk, unsigned short snum);
12 12
13extern int udp_setsockopt(struct sock *sk, int level, int optname, 13extern int udp_setsockopt(struct sock *sk, int level, int optname,
14 char __user *optval, int optlen); 14 char __user *optval, unsigned int optlen);
15extern int udp_getsockopt(struct sock *sk, int level, int optname, 15extern int udp_getsockopt(struct sock *sk, int level, int optname,
16 char __user *optval, int __user *optlen); 16 char __user *optval, int __user *optlen);
17 17
18#ifdef CONFIG_COMPAT 18#ifdef CONFIG_COMPAT
19extern int compat_udp_setsockopt(struct sock *sk, int level, int optname, 19extern int compat_udp_setsockopt(struct sock *sk, int level, int optname,
20 char __user *optval, int optlen); 20 char __user *optval, unsigned int optlen);
21extern int compat_udp_getsockopt(struct sock *sk, int level, int optname, 21extern int compat_udp_getsockopt(struct sock *sk, int level, int optname,
22 char __user *optval, int __user *optlen); 22 char __user *optval, int __user *optlen);
23#endif 23#endif
diff --git a/net/ipv4/udplite.c b/net/ipv4/udplite.c
index c784891cb7e5..95248d7f75ec 100644
--- a/net/ipv4/udplite.c
+++ b/net/ipv4/udplite.c
@@ -25,7 +25,7 @@ static void udplite_err(struct sk_buff *skb, u32 info)
25 __udp4_lib_err(skb, info, &udplite_table); 25 __udp4_lib_err(skb, info, &udplite_table);
26} 26}
27 27
28static struct net_protocol udplite_protocol = { 28static const struct net_protocol udplite_protocol = {
29 .handler = udplite_rcv, 29 .handler = udplite_rcv,
30 .err_handler = udplite_err, 30 .err_handler = udplite_err,
31 .no_policy = 1, 31 .no_policy = 1,
diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
index c9b369034a40..1fd0a3d775d2 100644
--- a/net/ipv6/addrconf.c
+++ b/net/ipv6/addrconf.c
@@ -137,6 +137,8 @@ static DEFINE_SPINLOCK(addrconf_verify_lock);
137static void addrconf_join_anycast(struct inet6_ifaddr *ifp); 137static void addrconf_join_anycast(struct inet6_ifaddr *ifp);
138static void addrconf_leave_anycast(struct inet6_ifaddr *ifp); 138static void addrconf_leave_anycast(struct inet6_ifaddr *ifp);
139 139
140static void addrconf_bonding_change(struct net_device *dev,
141 unsigned long event);
140static int addrconf_ifdown(struct net_device *dev, int how); 142static int addrconf_ifdown(struct net_device *dev, int how);
141 143
142static void addrconf_dad_start(struct inet6_ifaddr *ifp, u32 flags); 144static void addrconf_dad_start(struct inet6_ifaddr *ifp, u32 flags);
@@ -1405,8 +1407,8 @@ void addrconf_dad_failure(struct inet6_ifaddr *ifp)
1405 struct inet6_dev *idev = ifp->idev; 1407 struct inet6_dev *idev = ifp->idev;
1406 1408
1407 if (net_ratelimit()) 1409 if (net_ratelimit())
1408 printk(KERN_INFO "%s: IPv6 duplicate address detected!\n", 1410 printk(KERN_INFO "%s: IPv6 duplicate address %pI6c detected!\n",
1409 ifp->idev->dev->name); 1411 ifp->idev->dev->name, &ifp->addr);
1410 1412
1411 if (idev->cnf.accept_dad > 1 && !idev->cnf.disable_ipv6) { 1413 if (idev->cnf.accept_dad > 1 && !idev->cnf.disable_ipv6) {
1412 struct in6_addr addr; 1414 struct in6_addr addr;
@@ -2582,6 +2584,10 @@ static int addrconf_notify(struct notifier_block *this, unsigned long event,
2582 return notifier_from_errno(err); 2584 return notifier_from_errno(err);
2583 } 2585 }
2584 break; 2586 break;
2587 case NETDEV_BONDING_OLDTYPE:
2588 case NETDEV_BONDING_NEWTYPE:
2589 addrconf_bonding_change(dev, event);
2590 break;
2585 } 2591 }
2586 2592
2587 return NOTIFY_OK; 2593 return NOTIFY_OK;
@@ -2595,6 +2601,19 @@ static struct notifier_block ipv6_dev_notf = {
2595 .priority = 0 2601 .priority = 0
2596}; 2602};
2597 2603
2604static void addrconf_bonding_change(struct net_device *dev, unsigned long event)
2605{
2606 struct inet6_dev *idev;
2607 ASSERT_RTNL();
2608
2609 idev = __in6_dev_get(dev);
2610
2611 if (event == NETDEV_BONDING_NEWTYPE)
2612 ipv6_mc_remap(idev);
2613 else if (event == NETDEV_BONDING_OLDTYPE)
2614 ipv6_mc_unmap(idev);
2615}
2616
2598static int addrconf_ifdown(struct net_device *dev, int how) 2617static int addrconf_ifdown(struct net_device *dev, int how)
2599{ 2618{
2600 struct inet6_dev *idev; 2619 struct inet6_dev *idev;
@@ -3967,14 +3986,14 @@ static void ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
3967#ifdef CONFIG_SYSCTL 3986#ifdef CONFIG_SYSCTL
3968 3987
3969static 3988static
3970int addrconf_sysctl_forward(ctl_table *ctl, int write, struct file * filp, 3989int addrconf_sysctl_forward(ctl_table *ctl, int write,
3971 void __user *buffer, size_t *lenp, loff_t *ppos) 3990 void __user *buffer, size_t *lenp, loff_t *ppos)
3972{ 3991{
3973 int *valp = ctl->data; 3992 int *valp = ctl->data;
3974 int val = *valp; 3993 int val = *valp;
3975 int ret; 3994 int ret;
3976 3995
3977 ret = proc_dointvec(ctl, write, filp, buffer, lenp, ppos); 3996 ret = proc_dointvec(ctl, write, buffer, lenp, ppos);
3978 3997
3979 if (write) 3998 if (write)
3980 ret = addrconf_fixup_forwarding(ctl, valp, val); 3999 ret = addrconf_fixup_forwarding(ctl, valp, val);
@@ -4071,14 +4090,14 @@ static int addrconf_disable_ipv6(struct ctl_table *table, int *p, int old)
4071} 4090}
4072 4091
4073static 4092static
4074int addrconf_sysctl_disable(ctl_table *ctl, int write, struct file * filp, 4093int addrconf_sysctl_disable(ctl_table *ctl, int write,
4075 void __user *buffer, size_t *lenp, loff_t *ppos) 4094 void __user *buffer, size_t *lenp, loff_t *ppos)
4076{ 4095{
4077 int *valp = ctl->data; 4096 int *valp = ctl->data;
4078 int val = *valp; 4097 int val = *valp;
4079 int ret; 4098 int ret;
4080 4099
4081 ret = proc_dointvec(ctl, write, filp, buffer, lenp, ppos); 4100 ret = proc_dointvec(ctl, write, buffer, lenp, ppos);
4082 4101
4083 if (write) 4102 if (write)
4084 ret = addrconf_disable_ipv6(ctl, valp, val); 4103 ret = addrconf_disable_ipv6(ctl, valp, val);
diff --git a/net/ipv6/af_inet6.c b/net/ipv6/af_inet6.c
index a123a328aeb3..e127a32f9540 100644
--- a/net/ipv6/af_inet6.c
+++ b/net/ipv6/af_inet6.c
@@ -710,7 +710,7 @@ EXPORT_SYMBOL_GPL(ipv6_opt_accepted);
710 710
711static int ipv6_gso_pull_exthdrs(struct sk_buff *skb, int proto) 711static int ipv6_gso_pull_exthdrs(struct sk_buff *skb, int proto)
712{ 712{
713 struct inet6_protocol *ops = NULL; 713 const struct inet6_protocol *ops = NULL;
714 714
715 for (;;) { 715 for (;;) {
716 struct ipv6_opt_hdr *opth; 716 struct ipv6_opt_hdr *opth;
@@ -745,7 +745,7 @@ static int ipv6_gso_pull_exthdrs(struct sk_buff *skb, int proto)
745static int ipv6_gso_send_check(struct sk_buff *skb) 745static int ipv6_gso_send_check(struct sk_buff *skb)
746{ 746{
747 struct ipv6hdr *ipv6h; 747 struct ipv6hdr *ipv6h;
748 struct inet6_protocol *ops; 748 const struct inet6_protocol *ops;
749 int err = -EINVAL; 749 int err = -EINVAL;
750 750
751 if (unlikely(!pskb_may_pull(skb, sizeof(*ipv6h)))) 751 if (unlikely(!pskb_may_pull(skb, sizeof(*ipv6h))))
@@ -773,7 +773,7 @@ static struct sk_buff *ipv6_gso_segment(struct sk_buff *skb, int features)
773{ 773{
774 struct sk_buff *segs = ERR_PTR(-EINVAL); 774 struct sk_buff *segs = ERR_PTR(-EINVAL);
775 struct ipv6hdr *ipv6h; 775 struct ipv6hdr *ipv6h;
776 struct inet6_protocol *ops; 776 const struct inet6_protocol *ops;
777 int proto; 777 int proto;
778 struct frag_hdr *fptr; 778 struct frag_hdr *fptr;
779 unsigned int unfrag_ip6hlen; 779 unsigned int unfrag_ip6hlen;
@@ -840,7 +840,7 @@ struct ipv6_gro_cb {
840static struct sk_buff **ipv6_gro_receive(struct sk_buff **head, 840static struct sk_buff **ipv6_gro_receive(struct sk_buff **head,
841 struct sk_buff *skb) 841 struct sk_buff *skb)
842{ 842{
843 struct inet6_protocol *ops; 843 const struct inet6_protocol *ops;
844 struct sk_buff **pp = NULL; 844 struct sk_buff **pp = NULL;
845 struct sk_buff *p; 845 struct sk_buff *p;
846 struct ipv6hdr *iph; 846 struct ipv6hdr *iph;
@@ -926,7 +926,7 @@ out:
926 926
927static int ipv6_gro_complete(struct sk_buff *skb) 927static int ipv6_gro_complete(struct sk_buff *skb)
928{ 928{
929 struct inet6_protocol *ops; 929 const struct inet6_protocol *ops;
930 struct ipv6hdr *iph = ipv6_hdr(skb); 930 struct ipv6hdr *iph = ipv6_hdr(skb);
931 int err = -ENOSYS; 931 int err = -ENOSYS;
932 932
diff --git a/net/ipv6/ah6.c b/net/ipv6/ah6.c
index 86f42a288c4b..c1589e2f1dc9 100644
--- a/net/ipv6/ah6.c
+++ b/net/ipv6/ah6.c
@@ -527,7 +527,7 @@ static const struct xfrm_type ah6_type =
527 .hdr_offset = xfrm6_find_1stfragopt, 527 .hdr_offset = xfrm6_find_1stfragopt,
528}; 528};
529 529
530static struct inet6_protocol ah6_protocol = { 530static const struct inet6_protocol ah6_protocol = {
531 .handler = xfrm6_rcv, 531 .handler = xfrm6_rcv,
532 .err_handler = ah6_err, 532 .err_handler = ah6_err,
533 .flags = INET6_PROTO_NOPOLICY, 533 .flags = INET6_PROTO_NOPOLICY,
diff --git a/net/ipv6/esp6.c b/net/ipv6/esp6.c
index 678bb95b1525..af597c73ebe9 100644
--- a/net/ipv6/esp6.c
+++ b/net/ipv6/esp6.c
@@ -558,7 +558,7 @@ static const struct xfrm_type esp6_type =
558 .hdr_offset = xfrm6_find_1stfragopt, 558 .hdr_offset = xfrm6_find_1stfragopt,
559}; 559};
560 560
561static struct inet6_protocol esp6_protocol = { 561static const struct inet6_protocol esp6_protocol = {
562 .handler = xfrm6_rcv, 562 .handler = xfrm6_rcv,
563 .err_handler = esp6_err, 563 .err_handler = esp6_err,
564 .flags = INET6_PROTO_NOPOLICY, 564 .flags = INET6_PROTO_NOPOLICY,
diff --git a/net/ipv6/exthdrs.c b/net/ipv6/exthdrs.c
index 4aae658e5501..df159fffe4bc 100644
--- a/net/ipv6/exthdrs.c
+++ b/net/ipv6/exthdrs.c
@@ -500,17 +500,17 @@ unknown_rh:
500 return -1; 500 return -1;
501} 501}
502 502
503static struct inet6_protocol rthdr_protocol = { 503static const struct inet6_protocol rthdr_protocol = {
504 .handler = ipv6_rthdr_rcv, 504 .handler = ipv6_rthdr_rcv,
505 .flags = INET6_PROTO_NOPOLICY | INET6_PROTO_GSO_EXTHDR, 505 .flags = INET6_PROTO_NOPOLICY | INET6_PROTO_GSO_EXTHDR,
506}; 506};
507 507
508static struct inet6_protocol destopt_protocol = { 508static const struct inet6_protocol destopt_protocol = {
509 .handler = ipv6_destopt_rcv, 509 .handler = ipv6_destopt_rcv,
510 .flags = INET6_PROTO_NOPOLICY | INET6_PROTO_GSO_EXTHDR, 510 .flags = INET6_PROTO_NOPOLICY | INET6_PROTO_GSO_EXTHDR,
511}; 511};
512 512
513static struct inet6_protocol nodata_protocol = { 513static const struct inet6_protocol nodata_protocol = {
514 .handler = dst_discard, 514 .handler = dst_discard,
515 .flags = INET6_PROTO_NOPOLICY, 515 .flags = INET6_PROTO_NOPOLICY,
516}; 516};
diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c
index e2325f6a05fb..f23ebbec0631 100644
--- a/net/ipv6/icmp.c
+++ b/net/ipv6/icmp.c
@@ -86,7 +86,7 @@ static inline struct sock *icmpv6_sk(struct net *net)
86 86
87static int icmpv6_rcv(struct sk_buff *skb); 87static int icmpv6_rcv(struct sk_buff *skb);
88 88
89static struct inet6_protocol icmpv6_protocol = { 89static const struct inet6_protocol icmpv6_protocol = {
90 .handler = icmpv6_rcv, 90 .handler = icmpv6_rcv,
91 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL, 91 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
92}; 92};
@@ -583,7 +583,7 @@ out:
583 583
584static void icmpv6_notify(struct sk_buff *skb, u8 type, u8 code, __be32 info) 584static void icmpv6_notify(struct sk_buff *skb, u8 type, u8 code, __be32 info)
585{ 585{
586 struct inet6_protocol *ipprot; 586 const struct inet6_protocol *ipprot;
587 int inner_offset; 587 int inner_offset;
588 int hash; 588 int hash;
589 u8 nexthdr; 589 u8 nexthdr;
diff --git a/net/ipv6/ip6_input.c b/net/ipv6/ip6_input.c
index 2d9cbaa67edb..237e2dba6e94 100644
--- a/net/ipv6/ip6_input.c
+++ b/net/ipv6/ip6_input.c
@@ -159,7 +159,7 @@ drop:
159 159
160static int ip6_input_finish(struct sk_buff *skb) 160static int ip6_input_finish(struct sk_buff *skb)
161{ 161{
162 struct inet6_protocol *ipprot; 162 const struct inet6_protocol *ipprot;
163 unsigned int nhoff; 163 unsigned int nhoff;
164 int nexthdr, raw; 164 int nexthdr, raw;
165 u8 hash; 165 u8 hash;
diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
index 7d25bbe32110..c595bbe1ed99 100644
--- a/net/ipv6/ip6_tunnel.c
+++ b/net/ipv6/ip6_tunnel.c
@@ -1043,11 +1043,6 @@ ip6_tnl_xmit(struct sk_buff *skb, struct net_device *dev)
1043 struct net_device_stats *stats = &t->dev->stats; 1043 struct net_device_stats *stats = &t->dev->stats;
1044 int ret; 1044 int ret;
1045 1045
1046 if (t->recursion++) {
1047 stats->collisions++;
1048 goto tx_err;
1049 }
1050
1051 switch (skb->protocol) { 1046 switch (skb->protocol) {
1052 case htons(ETH_P_IP): 1047 case htons(ETH_P_IP):
1053 ret = ip4ip6_tnl_xmit(skb, dev); 1048 ret = ip4ip6_tnl_xmit(skb, dev);
@@ -1062,14 +1057,12 @@ ip6_tnl_xmit(struct sk_buff *skb, struct net_device *dev)
1062 if (ret < 0) 1057 if (ret < 0)
1063 goto tx_err; 1058 goto tx_err;
1064 1059
1065 t->recursion--;
1066 return NETDEV_TX_OK; 1060 return NETDEV_TX_OK;
1067 1061
1068tx_err: 1062tx_err:
1069 stats->tx_errors++; 1063 stats->tx_errors++;
1070 stats->tx_dropped++; 1064 stats->tx_dropped++;
1071 kfree_skb(skb); 1065 kfree_skb(skb);
1072 t->recursion--;
1073 return NETDEV_TX_OK; 1066 return NETDEV_TX_OK;
1074} 1067}
1075 1068
diff --git a/net/ipv6/ip6mr.c b/net/ipv6/ip6mr.c
index 5c8d73730c75..716153941fc4 100644
--- a/net/ipv6/ip6mr.c
+++ b/net/ipv6/ip6mr.c
@@ -83,10 +83,6 @@ static int ip6mr_cache_report(struct net *net, struct sk_buff *pkt,
83static int ip6mr_fill_mroute(struct sk_buff *skb, struct mfc6_cache *c, struct rtmsg *rtm); 83static int ip6mr_fill_mroute(struct sk_buff *skb, struct mfc6_cache *c, struct rtmsg *rtm);
84static void mroute_clean_tables(struct net *net); 84static void mroute_clean_tables(struct net *net);
85 85
86#ifdef CONFIG_IPV6_PIMSM_V2
87static struct inet6_protocol pim6_protocol;
88#endif
89
90static struct timer_list ipmr_expire_timer; 86static struct timer_list ipmr_expire_timer;
91 87
92 88
@@ -328,7 +324,7 @@ static int ipmr_mfc_seq_show(struct seq_file *seq, void *v)
328 return 0; 324 return 0;
329} 325}
330 326
331static struct seq_operations ipmr_mfc_seq_ops = { 327static const struct seq_operations ipmr_mfc_seq_ops = {
332 .start = ipmr_mfc_seq_start, 328 .start = ipmr_mfc_seq_start,
333 .next = ipmr_mfc_seq_next, 329 .next = ipmr_mfc_seq_next,
334 .stop = ipmr_mfc_seq_stop, 330 .stop = ipmr_mfc_seq_stop,
@@ -410,7 +406,7 @@ static int pim6_rcv(struct sk_buff *skb)
410 return 0; 406 return 0;
411} 407}
412 408
413static struct inet6_protocol pim6_protocol = { 409static const struct inet6_protocol pim6_protocol = {
414 .handler = pim6_rcv, 410 .handler = pim6_rcv,
415}; 411};
416 412
@@ -1285,7 +1281,7 @@ int ip6mr_sk_done(struct sock *sk)
1285 * MOSPF/PIM router set up we can clean this up. 1281 * MOSPF/PIM router set up we can clean this up.
1286 */ 1282 */
1287 1283
1288int ip6_mroute_setsockopt(struct sock *sk, int optname, char __user *optval, int optlen) 1284int ip6_mroute_setsockopt(struct sock *sk, int optname, char __user *optval, unsigned int optlen)
1289{ 1285{
1290 int ret; 1286 int ret;
1291 struct mif6ctl vif; 1287 struct mif6ctl vif;
diff --git a/net/ipv6/ipcomp6.c b/net/ipv6/ipcomp6.c
index 79c172f1ff01..2f2a5ca2c878 100644
--- a/net/ipv6/ipcomp6.c
+++ b/net/ipv6/ipcomp6.c
@@ -178,7 +178,7 @@ static const struct xfrm_type ipcomp6_type =
178 .hdr_offset = xfrm6_find_1stfragopt, 178 .hdr_offset = xfrm6_find_1stfragopt,
179}; 179};
180 180
181static struct inet6_protocol ipcomp6_protocol = 181static const struct inet6_protocol ipcomp6_protocol =
182{ 182{
183 .handler = xfrm6_rcv, 183 .handler = xfrm6_rcv,
184 .err_handler = ipcomp6_err, 184 .err_handler = ipcomp6_err,
diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
index f5e0682b402d..14f54eb5a7fc 100644
--- a/net/ipv6/ipv6_sockglue.c
+++ b/net/ipv6/ipv6_sockglue.c
@@ -123,7 +123,7 @@ struct ipv6_txoptions *ipv6_update_options(struct sock *sk,
123} 123}
124 124
125static int do_ipv6_setsockopt(struct sock *sk, int level, int optname, 125static int do_ipv6_setsockopt(struct sock *sk, int level, int optname,
126 char __user *optval, int optlen) 126 char __user *optval, unsigned int optlen)
127{ 127{
128 struct ipv6_pinfo *np = inet6_sk(sk); 128 struct ipv6_pinfo *np = inet6_sk(sk);
129 struct net *net = sock_net(sk); 129 struct net *net = sock_net(sk);
@@ -773,7 +773,7 @@ e_inval:
773} 773}
774 774
775int ipv6_setsockopt(struct sock *sk, int level, int optname, 775int ipv6_setsockopt(struct sock *sk, int level, int optname,
776 char __user *optval, int optlen) 776 char __user *optval, unsigned int optlen)
777{ 777{
778 int err; 778 int err;
779 779
@@ -801,7 +801,7 @@ EXPORT_SYMBOL(ipv6_setsockopt);
801 801
802#ifdef CONFIG_COMPAT 802#ifdef CONFIG_COMPAT
803int compat_ipv6_setsockopt(struct sock *sk, int level, int optname, 803int compat_ipv6_setsockopt(struct sock *sk, int level, int optname,
804 char __user *optval, int optlen) 804 char __user *optval, unsigned int optlen)
805{ 805{
806 int err; 806 int err;
807 807
diff --git a/net/ipv6/mcast.c b/net/ipv6/mcast.c
index 71c3dacec1ed..f9fcf690bd5d 100644
--- a/net/ipv6/mcast.c
+++ b/net/ipv6/mcast.c
@@ -2249,6 +2249,25 @@ static void igmp6_timer_handler(unsigned long data)
2249 ma_put(ma); 2249 ma_put(ma);
2250} 2250}
2251 2251
2252/* Device changing type */
2253
2254void ipv6_mc_unmap(struct inet6_dev *idev)
2255{
2256 struct ifmcaddr6 *i;
2257
2258 /* Install multicast list, except for all-nodes (already installed) */
2259
2260 read_lock_bh(&idev->lock);
2261 for (i = idev->mc_list; i; i = i->next)
2262 igmp6_group_dropped(i);
2263 read_unlock_bh(&idev->lock);
2264}
2265
2266void ipv6_mc_remap(struct inet6_dev *idev)
2267{
2268 ipv6_mc_up(idev);
2269}
2270
2252/* Device going down */ 2271/* Device going down */
2253 2272
2254void ipv6_mc_down(struct inet6_dev *idev) 2273void ipv6_mc_down(struct inet6_dev *idev)
diff --git a/net/ipv6/ndisc.c b/net/ipv6/ndisc.c
index 7015478797f6..f74e4e2cdd06 100644
--- a/net/ipv6/ndisc.c
+++ b/net/ipv6/ndisc.c
@@ -658,7 +658,6 @@ void ndisc_send_rs(struct net_device *dev, const struct in6_addr *saddr,
658 &icmp6h, NULL, 658 &icmp6h, NULL,
659 send_sllao ? ND_OPT_SOURCE_LL_ADDR : 0); 659 send_sllao ? ND_OPT_SOURCE_LL_ADDR : 0);
660} 660}
661EXPORT_SYMBOL(ndisc_send_rs);
662 661
663 662
664static void ndisc_error_report(struct neighbour *neigh, struct sk_buff *skb) 663static void ndisc_error_report(struct neighbour *neigh, struct sk_buff *skb)
@@ -1735,7 +1734,7 @@ static void ndisc_warn_deprecated_sysctl(struct ctl_table *ctl,
1735 } 1734 }
1736} 1735}
1737 1736
1738int ndisc_ifinfo_sysctl_change(struct ctl_table *ctl, int write, struct file * filp, void __user *buffer, size_t *lenp, loff_t *ppos) 1737int ndisc_ifinfo_sysctl_change(struct ctl_table *ctl, int write, void __user *buffer, size_t *lenp, loff_t *ppos)
1739{ 1738{
1740 struct net_device *dev = ctl->extra1; 1739 struct net_device *dev = ctl->extra1;
1741 struct inet6_dev *idev; 1740 struct inet6_dev *idev;
@@ -1746,16 +1745,16 @@ int ndisc_ifinfo_sysctl_change(struct ctl_table *ctl, int write, struct file * f
1746 ndisc_warn_deprecated_sysctl(ctl, "syscall", dev ? dev->name : "default"); 1745 ndisc_warn_deprecated_sysctl(ctl, "syscall", dev ? dev->name : "default");
1747 1746
1748 if (strcmp(ctl->procname, "retrans_time") == 0) 1747 if (strcmp(ctl->procname, "retrans_time") == 0)
1749 ret = proc_dointvec(ctl, write, filp, buffer, lenp, ppos); 1748 ret = proc_dointvec(ctl, write, buffer, lenp, ppos);
1750 1749
1751 else if (strcmp(ctl->procname, "base_reachable_time") == 0) 1750 else if (strcmp(ctl->procname, "base_reachable_time") == 0)
1752 ret = proc_dointvec_jiffies(ctl, write, 1751 ret = proc_dointvec_jiffies(ctl, write,
1753 filp, buffer, lenp, ppos); 1752 buffer, lenp, ppos);
1754 1753
1755 else if ((strcmp(ctl->procname, "retrans_time_ms") == 0) || 1754 else if ((strcmp(ctl->procname, "retrans_time_ms") == 0) ||
1756 (strcmp(ctl->procname, "base_reachable_time_ms") == 0)) 1755 (strcmp(ctl->procname, "base_reachable_time_ms") == 0))
1757 ret = proc_dointvec_ms_jiffies(ctl, write, 1756 ret = proc_dointvec_ms_jiffies(ctl, write,
1758 filp, buffer, lenp, ppos); 1757 buffer, lenp, ppos);
1759 else 1758 else
1760 ret = -1; 1759 ret = -1;
1761 1760
diff --git a/net/ipv6/protocol.c b/net/ipv6/protocol.c
index 568864f722ca..1fa3468f0f32 100644
--- a/net/ipv6/protocol.c
+++ b/net/ipv6/protocol.c
@@ -25,11 +25,11 @@
25#include <linux/spinlock.h> 25#include <linux/spinlock.h>
26#include <net/protocol.h> 26#include <net/protocol.h>
27 27
28struct inet6_protocol *inet6_protos[MAX_INET_PROTOS]; 28const struct inet6_protocol *inet6_protos[MAX_INET_PROTOS];
29static DEFINE_SPINLOCK(inet6_proto_lock); 29static DEFINE_SPINLOCK(inet6_proto_lock);
30 30
31 31
32int inet6_add_protocol(struct inet6_protocol *prot, unsigned char protocol) 32int inet6_add_protocol(const struct inet6_protocol *prot, unsigned char protocol)
33{ 33{
34 int ret, hash = protocol & (MAX_INET_PROTOS - 1); 34 int ret, hash = protocol & (MAX_INET_PROTOS - 1);
35 35
@@ -53,7 +53,7 @@ EXPORT_SYMBOL(inet6_add_protocol);
53 * Remove a protocol from the hash tables. 53 * Remove a protocol from the hash tables.
54 */ 54 */
55 55
56int inet6_del_protocol(struct inet6_protocol *prot, unsigned char protocol) 56int inet6_del_protocol(const struct inet6_protocol *prot, unsigned char protocol)
57{ 57{
58 int ret, hash = protocol & (MAX_INET_PROTOS - 1); 58 int ret, hash = protocol & (MAX_INET_PROTOS - 1);
59 59
diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
index 7d675b8d82d3..4f24570b0869 100644
--- a/net/ipv6/raw.c
+++ b/net/ipv6/raw.c
@@ -957,7 +957,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
957 957
958 958
959static int do_rawv6_setsockopt(struct sock *sk, int level, int optname, 959static int do_rawv6_setsockopt(struct sock *sk, int level, int optname,
960 char __user *optval, int optlen) 960 char __user *optval, unsigned int optlen)
961{ 961{
962 struct raw6_sock *rp = raw6_sk(sk); 962 struct raw6_sock *rp = raw6_sk(sk);
963 int val; 963 int val;
@@ -1000,7 +1000,7 @@ static int do_rawv6_setsockopt(struct sock *sk, int level, int optname,
1000} 1000}
1001 1001
1002static int rawv6_setsockopt(struct sock *sk, int level, int optname, 1002static int rawv6_setsockopt(struct sock *sk, int level, int optname,
1003 char __user *optval, int optlen) 1003 char __user *optval, unsigned int optlen)
1004{ 1004{
1005 switch(level) { 1005 switch(level) {
1006 case SOL_RAW: 1006 case SOL_RAW:
@@ -1024,7 +1024,7 @@ static int rawv6_setsockopt(struct sock *sk, int level, int optname,
1024 1024
1025#ifdef CONFIG_COMPAT 1025#ifdef CONFIG_COMPAT
1026static int compat_rawv6_setsockopt(struct sock *sk, int level, int optname, 1026static int compat_rawv6_setsockopt(struct sock *sk, int level, int optname,
1027 char __user *optval, int optlen) 1027 char __user *optval, unsigned int optlen)
1028{ 1028{
1029 switch (level) { 1029 switch (level) {
1030 case SOL_RAW: 1030 case SOL_RAW:
diff --git a/net/ipv6/reassembly.c b/net/ipv6/reassembly.c
index 2642a41a8535..da5bd0ed83df 100644
--- a/net/ipv6/reassembly.c
+++ b/net/ipv6/reassembly.c
@@ -627,7 +627,7 @@ fail_hdr:
627 return -1; 627 return -1;
628} 628}
629 629
630static struct inet6_protocol frag_protocol = 630static const struct inet6_protocol frag_protocol =
631{ 631{
632 .handler = ipv6_frag_rcv, 632 .handler = ipv6_frag_rcv,
633 .flags = INET6_PROTO_NOPOLICY, 633 .flags = INET6_PROTO_NOPOLICY,
diff --git a/net/ipv6/route.c b/net/ipv6/route.c
index 9ccfef345560..d6fe7646a8ff 100644
--- a/net/ipv6/route.c
+++ b/net/ipv6/route.c
@@ -481,7 +481,7 @@ int rt6_route_rcv(struct net_device *dev, u8 *opt, int len,
481 481
482 pref = rinfo->route_pref; 482 pref = rinfo->route_pref;
483 if (pref == ICMPV6_ROUTER_PREF_INVALID) 483 if (pref == ICMPV6_ROUTER_PREF_INVALID)
484 pref = ICMPV6_ROUTER_PREF_MEDIUM; 484 return -EINVAL;
485 485
486 lifetime = addrconf_timeout_fixup(ntohl(rinfo->lifetime), HZ); 486 lifetime = addrconf_timeout_fixup(ntohl(rinfo->lifetime), HZ);
487 487
@@ -2524,13 +2524,13 @@ static const struct file_operations rt6_stats_seq_fops = {
2524#ifdef CONFIG_SYSCTL 2524#ifdef CONFIG_SYSCTL
2525 2525
2526static 2526static
2527int ipv6_sysctl_rtcache_flush(ctl_table *ctl, int write, struct file * filp, 2527int ipv6_sysctl_rtcache_flush(ctl_table *ctl, int write,
2528 void __user *buffer, size_t *lenp, loff_t *ppos) 2528 void __user *buffer, size_t *lenp, loff_t *ppos)
2529{ 2529{
2530 struct net *net = current->nsproxy->net_ns; 2530 struct net *net = current->nsproxy->net_ns;
2531 int delay = net->ipv6.sysctl.flush_delay; 2531 int delay = net->ipv6.sysctl.flush_delay;
2532 if (write) { 2532 if (write) {
2533 proc_dointvec(ctl, write, filp, buffer, lenp, ppos); 2533 proc_dointvec(ctl, write, buffer, lenp, ppos);
2534 fib6_run_gc(delay <= 0 ? ~0UL : (unsigned long)delay, net); 2534 fib6_run_gc(delay <= 0 ? ~0UL : (unsigned long)delay, net);
2535 return 0; 2535 return 0;
2536 } else 2536 } else
diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
index 0ae4f6448187..dbd19a78ca73 100644
--- a/net/ipv6/sit.c
+++ b/net/ipv6/sit.c
@@ -15,7 +15,6 @@
15 * Roger Venning <r.venning@telstra.com>: 6to4 support 15 * Roger Venning <r.venning@telstra.com>: 6to4 support
16 * Nate Thompson <nate@thebog.net>: 6to4 support 16 * Nate Thompson <nate@thebog.net>: 6to4 support
17 * Fred Templin <fred.l.templin@boeing.com>: isatap support 17 * Fred Templin <fred.l.templin@boeing.com>: isatap support
18 * Sascha Hlusiak <mail@saschahlusiak.de>: stateless autoconf for isatap
19 */ 18 */
20 19
21#include <linux/module.h> 20#include <linux/module.h>
@@ -223,44 +222,6 @@ failed:
223 return NULL; 222 return NULL;
224} 223}
225 224
226static void ipip6_tunnel_rs_timer(unsigned long data)
227{
228 struct ip_tunnel_prl_entry *p = (struct ip_tunnel_prl_entry *) data;
229 struct inet6_dev *ifp;
230 struct inet6_ifaddr *addr;
231
232 spin_lock(&p->lock);
233 ifp = __in6_dev_get(p->tunnel->dev);
234
235 read_lock_bh(&ifp->lock);
236 for (addr = ifp->addr_list; addr; addr = addr->if_next) {
237 struct in6_addr rtr;
238
239 if (!(ipv6_addr_type(&addr->addr) & IPV6_ADDR_LINKLOCAL))
240 continue;
241
242 /* Send RS to guessed linklocal address of router
243 *
244 * Better: send to ff02::2 encapsuled in unicast directly
245 * to router-v4 instead of guessing the v6 address.
246 *
247 * Cisco/Windows seem to not set the u/l bit correctly,
248 * so we won't guess right.
249 */
250 ipv6_addr_set(&rtr, htonl(0xFE800000), 0, 0, 0);
251 if (!__ipv6_isatap_ifid(rtr.s6_addr + 8,
252 p->addr)) {
253 ndisc_send_rs(p->tunnel->dev, &addr->addr, &rtr);
254 }
255 }
256 read_unlock_bh(&ifp->lock);
257
258 mod_timer(&p->rs_timer, jiffies + HZ * p->rs_delay);
259 spin_unlock(&p->lock);
260
261 return;
262}
263
264static struct ip_tunnel_prl_entry * 225static struct ip_tunnel_prl_entry *
265__ipip6_tunnel_locate_prl(struct ip_tunnel *t, __be32 addr) 226__ipip6_tunnel_locate_prl(struct ip_tunnel *t, __be32 addr)
266{ 227{
@@ -313,13 +274,12 @@ static int ipip6_tunnel_get_prl(struct ip_tunnel *t,
313 274
314 c = 0; 275 c = 0;
315 for (prl = t->prl; prl; prl = prl->next) { 276 for (prl = t->prl; prl; prl = prl->next) {
316 if (c > cmax) 277 if (c >= cmax)
317 break; 278 break;
318 if (kprl.addr != htonl(INADDR_ANY) && prl->addr != kprl.addr) 279 if (kprl.addr != htonl(INADDR_ANY) && prl->addr != kprl.addr)
319 continue; 280 continue;
320 kp[c].addr = prl->addr; 281 kp[c].addr = prl->addr;
321 kp[c].flags = prl->flags; 282 kp[c].flags = prl->flags;
322 kp[c].rs_delay = prl->rs_delay;
323 c++; 283 c++;
324 if (kprl.addr != htonl(INADDR_ANY)) 284 if (kprl.addr != htonl(INADDR_ANY))
325 break; 285 break;
@@ -369,23 +329,11 @@ ipip6_tunnel_add_prl(struct ip_tunnel *t, struct ip_tunnel_prl *a, int chg)
369 } 329 }
370 330
371 p->next = t->prl; 331 p->next = t->prl;
372 p->tunnel = t;
373 t->prl = p; 332 t->prl = p;
374 t->prl_count++; 333 t->prl_count++;
375
376 spin_lock_init(&p->lock);
377 setup_timer(&p->rs_timer, ipip6_tunnel_rs_timer, (unsigned long) p);
378update: 334update:
379 p->addr = a->addr; 335 p->addr = a->addr;
380 p->flags = a->flags; 336 p->flags = a->flags;
381 p->rs_delay = a->rs_delay;
382 if (p->rs_delay == 0)
383 p->rs_delay = IPTUNNEL_RS_DEFAULT_DELAY;
384 spin_lock(&p->lock);
385 del_timer(&p->rs_timer);
386 if (p->flags & PRL_DEFAULT)
387 mod_timer(&p->rs_timer, jiffies + 1);
388 spin_unlock(&p->lock);
389out: 337out:
390 write_unlock(&ipip6_lock); 338 write_unlock(&ipip6_lock);
391 return err; 339 return err;
@@ -404,9 +352,6 @@ ipip6_tunnel_del_prl(struct ip_tunnel *t, struct ip_tunnel_prl *a)
404 if ((*p)->addr == a->addr) { 352 if ((*p)->addr == a->addr) {
405 x = *p; 353 x = *p;
406 *p = x->next; 354 *p = x->next;
407 spin_lock(&x->lock);
408 del_timer(&x->rs_timer);
409 spin_unlock(&x->lock);
410 kfree(x); 355 kfree(x);
411 t->prl_count--; 356 t->prl_count--;
412 goto out; 357 goto out;
@@ -417,9 +362,6 @@ ipip6_tunnel_del_prl(struct ip_tunnel *t, struct ip_tunnel_prl *a)
417 while (t->prl) { 362 while (t->prl) {
418 x = t->prl; 363 x = t->prl;
419 t->prl = t->prl->next; 364 t->prl = t->prl->next;
420 spin_lock(&x->lock);
421 del_timer(&x->rs_timer);
422 spin_unlock(&x->lock);
423 kfree(x); 365 kfree(x);
424 t->prl_count--; 366 t->prl_count--;
425 } 367 }
@@ -626,11 +568,6 @@ static netdev_tx_t ipip6_tunnel_xmit(struct sk_buff *skb,
626 struct in6_addr *addr6; 568 struct in6_addr *addr6;
627 int addr_type; 569 int addr_type;
628 570
629 if (tunnel->recursion++) {
630 stats->collisions++;
631 goto tx_error;
632 }
633
634 if (skb->protocol != htons(ETH_P_IPV6)) 571 if (skb->protocol != htons(ETH_P_IPV6))
635 goto tx_error; 572 goto tx_error;
636 573
@@ -753,7 +690,6 @@ static netdev_tx_t ipip6_tunnel_xmit(struct sk_buff *skb,
753 ip_rt_put(rt); 690 ip_rt_put(rt);
754 stats->tx_dropped++; 691 stats->tx_dropped++;
755 dev_kfree_skb(skb); 692 dev_kfree_skb(skb);
756 tunnel->recursion--;
757 return NETDEV_TX_OK; 693 return NETDEV_TX_OK;
758 } 694 }
759 if (skb->sk) 695 if (skb->sk)
@@ -794,7 +730,6 @@ static netdev_tx_t ipip6_tunnel_xmit(struct sk_buff *skb,
794 nf_reset(skb); 730 nf_reset(skb);
795 731
796 IPTUNNEL_XMIT(); 732 IPTUNNEL_XMIT();
797 tunnel->recursion--;
798 return NETDEV_TX_OK; 733 return NETDEV_TX_OK;
799 734
800tx_error_icmp: 735tx_error_icmp:
@@ -802,7 +737,6 @@ tx_error_icmp:
802tx_error: 737tx_error:
803 stats->tx_errors++; 738 stats->tx_errors++;
804 dev_kfree_skb(skb); 739 dev_kfree_skb(skb);
805 tunnel->recursion--;
806 return NETDEV_TX_OK; 740 return NETDEV_TX_OK;
807} 741}
808 742
diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
index 3aae0f217d61..21d100b68b19 100644
--- a/net/ipv6/tcp_ipv6.c
+++ b/net/ipv6/tcp_ipv6.c
@@ -1846,7 +1846,7 @@ static int tcp_v6_init_sock(struct sock *sk)
1846 /* See draft-stevens-tcpca-spec-01 for discussion of the 1846 /* See draft-stevens-tcpca-spec-01 for discussion of the
1847 * initialization of these values. 1847 * initialization of these values.
1848 */ 1848 */
1849 tp->snd_ssthresh = 0x7fffffff; 1849 tp->snd_ssthresh = TCP_INFINITE_SSTHRESH;
1850 tp->snd_cwnd_clamp = ~0; 1850 tp->snd_cwnd_clamp = ~0;
1851 tp->mss_cache = 536; 1851 tp->mss_cache = 536;
1852 1852
@@ -1969,7 +1969,8 @@ static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
1969 jiffies_to_clock_t(icsk->icsk_rto), 1969 jiffies_to_clock_t(icsk->icsk_rto),
1970 jiffies_to_clock_t(icsk->icsk_ack.ato), 1970 jiffies_to_clock_t(icsk->icsk_ack.ato),
1971 (icsk->icsk_ack.quick << 1 ) | icsk->icsk_ack.pingpong, 1971 (icsk->icsk_ack.quick << 1 ) | icsk->icsk_ack.pingpong,
1972 tp->snd_cwnd, tp->snd_ssthresh>=0xFFFF?-1:tp->snd_ssthresh 1972 tp->snd_cwnd,
1973 tcp_in_initial_slowstart(tp) ? -1 : tp->snd_ssthresh
1973 ); 1974 );
1974} 1975}
1975 1976
@@ -2093,7 +2094,7 @@ struct proto tcpv6_prot = {
2093#endif 2094#endif
2094}; 2095};
2095 2096
2096static struct inet6_protocol tcpv6_protocol = { 2097static const struct inet6_protocol tcpv6_protocol = {
2097 .handler = tcp_v6_rcv, 2098 .handler = tcp_v6_rcv,
2098 .err_handler = tcp_v6_err, 2099 .err_handler = tcp_v6_err,
2099 .gso_send_check = tcp_v6_gso_send_check, 2100 .gso_send_check = tcp_v6_gso_send_check,
diff --git a/net/ipv6/tunnel6.c b/net/ipv6/tunnel6.c
index 633ad789effc..51e2832d13a6 100644
--- a/net/ipv6/tunnel6.c
+++ b/net/ipv6/tunnel6.c
@@ -133,13 +133,13 @@ static void tunnel6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
133 break; 133 break;
134} 134}
135 135
136static struct inet6_protocol tunnel6_protocol = { 136static const struct inet6_protocol tunnel6_protocol = {
137 .handler = tunnel6_rcv, 137 .handler = tunnel6_rcv,
138 .err_handler = tunnel6_err, 138 .err_handler = tunnel6_err,
139 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL, 139 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
140}; 140};
141 141
142static struct inet6_protocol tunnel46_protocol = { 142static const struct inet6_protocol tunnel46_protocol = {
143 .handler = tunnel46_rcv, 143 .handler = tunnel46_rcv,
144 .err_handler = tunnel6_err, 144 .err_handler = tunnel6_err,
145 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL, 145 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
index 164040613c2e..3a60f12b34ed 100644
--- a/net/ipv6/udp.c
+++ b/net/ipv6/udp.c
@@ -1044,7 +1044,7 @@ void udpv6_destroy_sock(struct sock *sk)
1044 * Socket option code for UDP 1044 * Socket option code for UDP
1045 */ 1045 */
1046int udpv6_setsockopt(struct sock *sk, int level, int optname, 1046int udpv6_setsockopt(struct sock *sk, int level, int optname,
1047 char __user *optval, int optlen) 1047 char __user *optval, unsigned int optlen)
1048{ 1048{
1049 if (level == SOL_UDP || level == SOL_UDPLITE) 1049 if (level == SOL_UDP || level == SOL_UDPLITE)
1050 return udp_lib_setsockopt(sk, level, optname, optval, optlen, 1050 return udp_lib_setsockopt(sk, level, optname, optval, optlen,
@@ -1054,7 +1054,7 @@ int udpv6_setsockopt(struct sock *sk, int level, int optname,
1054 1054
1055#ifdef CONFIG_COMPAT 1055#ifdef CONFIG_COMPAT
1056int compat_udpv6_setsockopt(struct sock *sk, int level, int optname, 1056int compat_udpv6_setsockopt(struct sock *sk, int level, int optname,
1057 char __user *optval, int optlen) 1057 char __user *optval, unsigned int optlen)
1058{ 1058{
1059 if (level == SOL_UDP || level == SOL_UDPLITE) 1059 if (level == SOL_UDP || level == SOL_UDPLITE)
1060 return udp_lib_setsockopt(sk, level, optname, optval, optlen, 1060 return udp_lib_setsockopt(sk, level, optname, optval, optlen,
@@ -1172,7 +1172,7 @@ out:
1172 return segs; 1172 return segs;
1173} 1173}
1174 1174
1175static struct inet6_protocol udpv6_protocol = { 1175static const struct inet6_protocol udpv6_protocol = {
1176 .handler = udpv6_rcv, 1176 .handler = udpv6_rcv,
1177 .err_handler = udpv6_err, 1177 .err_handler = udpv6_err,
1178 .gso_send_check = udp6_ufo_send_check, 1178 .gso_send_check = udp6_ufo_send_check,
diff --git a/net/ipv6/udp_impl.h b/net/ipv6/udp_impl.h
index 6bb303471e20..d7571046bfc4 100644
--- a/net/ipv6/udp_impl.h
+++ b/net/ipv6/udp_impl.h
@@ -16,10 +16,10 @@ extern int udp_v6_get_port(struct sock *sk, unsigned short snum);
16extern int udpv6_getsockopt(struct sock *sk, int level, int optname, 16extern int udpv6_getsockopt(struct sock *sk, int level, int optname,
17 char __user *optval, int __user *optlen); 17 char __user *optval, int __user *optlen);
18extern int udpv6_setsockopt(struct sock *sk, int level, int optname, 18extern int udpv6_setsockopt(struct sock *sk, int level, int optname,
19 char __user *optval, int optlen); 19 char __user *optval, unsigned int optlen);
20#ifdef CONFIG_COMPAT 20#ifdef CONFIG_COMPAT
21extern int compat_udpv6_setsockopt(struct sock *sk, int level, int optname, 21extern int compat_udpv6_setsockopt(struct sock *sk, int level, int optname,
22 char __user *optval, int optlen); 22 char __user *optval, unsigned int optlen);
23extern int compat_udpv6_getsockopt(struct sock *sk, int level, int optname, 23extern int compat_udpv6_getsockopt(struct sock *sk, int level, int optname,
24 char __user *optval, int __user *optlen); 24 char __user *optval, int __user *optlen);
25#endif 25#endif
diff --git a/net/ipv6/udplite.c b/net/ipv6/udplite.c
index 4818c48688f2..d737a27ee010 100644
--- a/net/ipv6/udplite.c
+++ b/net/ipv6/udplite.c
@@ -25,7 +25,7 @@ static void udplitev6_err(struct sk_buff *skb,
25 __udp6_lib_err(skb, opt, type, code, offset, info, &udplite_table); 25 __udp6_lib_err(skb, opt, type, code, offset, info, &udplite_table);
26} 26}
27 27
28static struct inet6_protocol udplitev6_protocol = { 28static const struct inet6_protocol udplitev6_protocol = {
29 .handler = udplitev6_rcv, 29 .handler = udplitev6_rcv,
30 .err_handler = udplitev6_err, 30 .err_handler = udplitev6_err,
31 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL, 31 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
diff --git a/net/ipx/af_ipx.c b/net/ipx/af_ipx.c
index f1118d92a191..66c7a20011f3 100644
--- a/net/ipx/af_ipx.c
+++ b/net/ipx/af_ipx.c
@@ -1292,7 +1292,7 @@ const char *ipx_device_name(struct ipx_interface *intrfc)
1292 * socket object. */ 1292 * socket object. */
1293 1293
1294static int ipx_setsockopt(struct socket *sock, int level, int optname, 1294static int ipx_setsockopt(struct socket *sock, int level, int optname,
1295 char __user *optval, int optlen) 1295 char __user *optval, unsigned int optlen)
1296{ 1296{
1297 struct sock *sk = sock->sk; 1297 struct sock *sk = sock->sk;
1298 int opt; 1298 int opt;
diff --git a/net/irda/af_irda.c b/net/irda/af_irda.c
index 50b43c57d5d8..dd35641835f4 100644
--- a/net/irda/af_irda.c
+++ b/net/irda/af_irda.c
@@ -1826,7 +1826,7 @@ static int irda_compat_ioctl(struct socket *sock, unsigned int cmd, unsigned lon
1826 * 1826 *
1827 */ 1827 */
1828static int irda_setsockopt(struct socket *sock, int level, int optname, 1828static int irda_setsockopt(struct socket *sock, int level, int optname,
1829 char __user *optval, int optlen) 1829 char __user *optval, unsigned int optlen)
1830{ 1830{
1831 struct sock *sk = sock->sk; 1831 struct sock *sk = sock->sk;
1832 struct irda_sock *self = irda_sk(sk); 1832 struct irda_sock *self = irda_sk(sk);
diff --git a/net/irda/ircomm/ircomm_tty_attach.c b/net/irda/ircomm/ircomm_tty_attach.c
index eafc010907c2..3c1754023022 100644
--- a/net/irda/ircomm/ircomm_tty_attach.c
+++ b/net/irda/ircomm/ircomm_tty_attach.c
@@ -30,6 +30,7 @@
30 ********************************************************************/ 30 ********************************************************************/
31 31
32#include <linux/init.h> 32#include <linux/init.h>
33#include <linux/sched.h>
33 34
34#include <net/irda/irda.h> 35#include <net/irda/irda.h>
35#include <net/irda/irlmp.h> 36#include <net/irda/irlmp.h>
diff --git a/net/irda/irlan/irlan_common.c b/net/irda/irlan/irlan_common.c
index 62116829b817..315ead3cb926 100644
--- a/net/irda/irlan/irlan_common.c
+++ b/net/irda/irlan/irlan_common.c
@@ -30,6 +30,7 @@
30#include <linux/init.h> 30#include <linux/init.h>
31#include <linux/errno.h> 31#include <linux/errno.h>
32#include <linux/proc_fs.h> 32#include <linux/proc_fs.h>
33#include <linux/sched.h>
33#include <linux/seq_file.h> 34#include <linux/seq_file.h>
34#include <linux/random.h> 35#include <linux/random.h>
35#include <linux/netdevice.h> 36#include <linux/netdevice.h>
diff --git a/net/irda/irlan/irlan_eth.c b/net/irda/irlan/irlan_eth.c
index 7b6b631f647f..d340110f5c0c 100644
--- a/net/irda/irlan/irlan_eth.c
+++ b/net/irda/irlan/irlan_eth.c
@@ -30,6 +30,7 @@
30#include <linux/inetdevice.h> 30#include <linux/inetdevice.h>
31#include <linux/if_arp.h> 31#include <linux/if_arp.h>
32#include <linux/module.h> 32#include <linux/module.h>
33#include <linux/sched.h>
33#include <net/arp.h> 34#include <net/arp.h>
34 35
35#include <net/irda/irda.h> 36#include <net/irda/irda.h>
diff --git a/net/irda/irnet/irnet_irda.c b/net/irda/irnet/irnet_irda.c
index cf9a4b531a98..cccc2e93234f 100644
--- a/net/irda/irnet/irnet_irda.c
+++ b/net/irda/irnet/irnet_irda.c
@@ -9,6 +9,7 @@
9 */ 9 */
10 10
11#include "irnet_irda.h" /* Private header */ 11#include "irnet_irda.h" /* Private header */
12#include <linux/sched.h>
12#include <linux/seq_file.h> 13#include <linux/seq_file.h>
13#include <asm/unaligned.h> 14#include <asm/unaligned.h>
14 15
diff --git a/net/irda/irnet/irnet_ppp.c b/net/irda/irnet/irnet_ppp.c
index 68cbcb19cbd8..7dea882dbb75 100644
--- a/net/irda/irnet/irnet_ppp.c
+++ b/net/irda/irnet/irnet_ppp.c
@@ -13,6 +13,7 @@
13 * 2) as a control channel (write commands, read events) 13 * 2) as a control channel (write commands, read events)
14 */ 14 */
15 15
16#include <linux/sched.h>
16#include <linux/smp_lock.h> 17#include <linux/smp_lock.h>
17#include "irnet_ppp.h" /* Private header */ 18#include "irnet_ppp.h" /* Private header */
18/* Please put other headers in irnet.h - Thanks */ 19/* Please put other headers in irnet.h - Thanks */
diff --git a/net/irda/irsysctl.c b/net/irda/irsysctl.c
index 57f8817c3979..5c86567e5a78 100644
--- a/net/irda/irsysctl.c
+++ b/net/irda/irsysctl.c
@@ -73,12 +73,12 @@ static int min_lap_keepalive_time = 100; /* 100us */
73/* For other sysctl, I've no idea of the range. Maybe Dag could help 73/* For other sysctl, I've no idea of the range. Maybe Dag could help
74 * us on that - Jean II */ 74 * us on that - Jean II */
75 75
76static int do_devname(ctl_table *table, int write, struct file *filp, 76static int do_devname(ctl_table *table, int write,
77 void __user *buffer, size_t *lenp, loff_t *ppos) 77 void __user *buffer, size_t *lenp, loff_t *ppos)
78{ 78{
79 int ret; 79 int ret;
80 80
81 ret = proc_dostring(table, write, filp, buffer, lenp, ppos); 81 ret = proc_dostring(table, write, buffer, lenp, ppos);
82 if (ret == 0 && write) { 82 if (ret == 0 && write) {
83 struct ias_value *val; 83 struct ias_value *val;
84 84
@@ -90,12 +90,12 @@ static int do_devname(ctl_table *table, int write, struct file *filp,
90} 90}
91 91
92 92
93static int do_discovery(ctl_table *table, int write, struct file *filp, 93static int do_discovery(ctl_table *table, int write,
94 void __user *buffer, size_t *lenp, loff_t *ppos) 94 void __user *buffer, size_t *lenp, loff_t *ppos)
95{ 95{
96 int ret; 96 int ret;
97 97
98 ret = proc_dointvec(table, write, filp, buffer, lenp, ppos); 98 ret = proc_dointvec(table, write, buffer, lenp, ppos);
99 if (ret) 99 if (ret)
100 return ret; 100 return ret;
101 101
diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
index 49c15b48408e..bada1b9c670b 100644
--- a/net/iucv/af_iucv.c
+++ b/net/iucv/af_iucv.c
@@ -34,7 +34,7 @@
34 34
35static char iucv_userid[80]; 35static char iucv_userid[80];
36 36
37static struct proto_ops iucv_sock_ops; 37static const struct proto_ops iucv_sock_ops;
38 38
39static struct proto iucv_proto = { 39static struct proto iucv_proto = {
40 .name = "AF_IUCV", 40 .name = "AF_IUCV",
@@ -59,8 +59,8 @@ do { \
59 DEFINE_WAIT(__wait); \ 59 DEFINE_WAIT(__wait); \
60 long __timeo = timeo; \ 60 long __timeo = timeo; \
61 ret = 0; \ 61 ret = 0; \
62 prepare_to_wait(sk->sk_sleep, &__wait, TASK_INTERRUPTIBLE); \
62 while (!(condition)) { \ 63 while (!(condition)) { \
63 prepare_to_wait(sk->sk_sleep, &__wait, TASK_INTERRUPTIBLE); \
64 if (!__timeo) { \ 64 if (!__timeo) { \
65 ret = -EAGAIN; \ 65 ret = -EAGAIN; \
66 break; \ 66 break; \
@@ -361,10 +361,9 @@ static void iucv_sock_cleanup_listen(struct sock *parent)
361 } 361 }
362 362
363 parent->sk_state = IUCV_CLOSED; 363 parent->sk_state = IUCV_CLOSED;
364 sock_set_flag(parent, SOCK_ZAPPED);
365} 364}
366 365
367/* Kill socket */ 366/* Kill socket (only if zapped and orphaned) */
368static void iucv_sock_kill(struct sock *sk) 367static void iucv_sock_kill(struct sock *sk)
369{ 368{
370 if (!sock_flag(sk, SOCK_ZAPPED) || sk->sk_socket) 369 if (!sock_flag(sk, SOCK_ZAPPED) || sk->sk_socket)
@@ -426,17 +425,18 @@ static void iucv_sock_close(struct sock *sk)
426 425
427 skb_queue_purge(&iucv->send_skb_q); 426 skb_queue_purge(&iucv->send_skb_q);
428 skb_queue_purge(&iucv->backlog_skb_q); 427 skb_queue_purge(&iucv->backlog_skb_q);
429
430 sock_set_flag(sk, SOCK_ZAPPED);
431 break; 428 break;
432 429
433 default: 430 default:
434 sock_set_flag(sk, SOCK_ZAPPED); 431 sock_set_flag(sk, SOCK_ZAPPED);
432 /* nothing to do here */
435 break; 433 break;
436 } 434 }
437 435
436 /* mark socket for deletion by iucv_sock_kill() */
437 sock_set_flag(sk, SOCK_ZAPPED);
438
438 release_sock(sk); 439 release_sock(sk);
439 iucv_sock_kill(sk);
440} 440}
441 441
442static void iucv_sock_init(struct sock *sk, struct sock *parent) 442static void iucv_sock_init(struct sock *sk, struct sock *parent)
@@ -569,6 +569,7 @@ struct sock *iucv_accept_dequeue(struct sock *parent, struct socket *newsock)
569 569
570 if (sk->sk_state == IUCV_CONNECTED || 570 if (sk->sk_state == IUCV_CONNECTED ||
571 sk->sk_state == IUCV_SEVERED || 571 sk->sk_state == IUCV_SEVERED ||
572 sk->sk_state == IUCV_DISCONN || /* due to PM restore */
572 !newsock) { 573 !newsock) {
573 iucv_accept_unlink(sk); 574 iucv_accept_unlink(sk);
574 if (newsock) 575 if (newsock)
@@ -1035,6 +1036,10 @@ out:
1035 return err; 1036 return err;
1036} 1037}
1037 1038
1039/* iucv_fragment_skb() - Fragment a single IUCV message into multiple skb's
1040 *
1041 * Locking: must be called with message_q.lock held
1042 */
1038static int iucv_fragment_skb(struct sock *sk, struct sk_buff *skb, int len) 1043static int iucv_fragment_skb(struct sock *sk, struct sk_buff *skb, int len)
1039{ 1044{
1040 int dataleft, size, copied = 0; 1045 int dataleft, size, copied = 0;
@@ -1069,6 +1074,10 @@ static int iucv_fragment_skb(struct sock *sk, struct sk_buff *skb, int len)
1069 return 0; 1074 return 0;
1070} 1075}
1071 1076
1077/* iucv_process_message() - Receive a single outstanding IUCV message
1078 *
1079 * Locking: must be called with message_q.lock held
1080 */
1072static void iucv_process_message(struct sock *sk, struct sk_buff *skb, 1081static void iucv_process_message(struct sock *sk, struct sk_buff *skb,
1073 struct iucv_path *path, 1082 struct iucv_path *path,
1074 struct iucv_message *msg) 1083 struct iucv_message *msg)
@@ -1119,6 +1128,10 @@ static void iucv_process_message(struct sock *sk, struct sk_buff *skb,
1119 skb_queue_head(&iucv_sk(sk)->backlog_skb_q, skb); 1128 skb_queue_head(&iucv_sk(sk)->backlog_skb_q, skb);
1120} 1129}
1121 1130
1131/* iucv_process_message_q() - Process outstanding IUCV messages
1132 *
1133 * Locking: must be called with message_q.lock held
1134 */
1122static void iucv_process_message_q(struct sock *sk) 1135static void iucv_process_message_q(struct sock *sk)
1123{ 1136{
1124 struct iucv_sock *iucv = iucv_sk(sk); 1137 struct iucv_sock *iucv = iucv_sk(sk);
@@ -1209,6 +1222,7 @@ static int iucv_sock_recvmsg(struct kiocb *iocb, struct socket *sock,
1209 kfree_skb(skb); 1222 kfree_skb(skb);
1210 1223
1211 /* Queue backlog skbs */ 1224 /* Queue backlog skbs */
1225 spin_lock_bh(&iucv->message_q.lock);
1212 rskb = skb_dequeue(&iucv->backlog_skb_q); 1226 rskb = skb_dequeue(&iucv->backlog_skb_q);
1213 while (rskb) { 1227 while (rskb) {
1214 if (sock_queue_rcv_skb(sk, rskb)) { 1228 if (sock_queue_rcv_skb(sk, rskb)) {
@@ -1220,11 +1234,10 @@ static int iucv_sock_recvmsg(struct kiocb *iocb, struct socket *sock,
1220 } 1234 }
1221 } 1235 }
1222 if (skb_queue_empty(&iucv->backlog_skb_q)) { 1236 if (skb_queue_empty(&iucv->backlog_skb_q)) {
1223 spin_lock_bh(&iucv->message_q.lock);
1224 if (!list_empty(&iucv->message_q.list)) 1237 if (!list_empty(&iucv->message_q.list))
1225 iucv_process_message_q(sk); 1238 iucv_process_message_q(sk);
1226 spin_unlock_bh(&iucv->message_q.lock);
1227 } 1239 }
1240 spin_unlock_bh(&iucv->message_q.lock);
1228 } 1241 }
1229 1242
1230done: 1243done:
@@ -1374,7 +1387,7 @@ static int iucv_sock_release(struct socket *sock)
1374 1387
1375/* getsockopt and setsockopt */ 1388/* getsockopt and setsockopt */
1376static int iucv_sock_setsockopt(struct socket *sock, int level, int optname, 1389static int iucv_sock_setsockopt(struct socket *sock, int level, int optname,
1377 char __user *optval, int optlen) 1390 char __user *optval, unsigned int optlen)
1378{ 1391{
1379 struct sock *sk = sock->sk; 1392 struct sock *sk = sock->sk;
1380 struct iucv_sock *iucv = iucv_sk(sk); 1393 struct iucv_sock *iucv = iucv_sk(sk);
@@ -1682,7 +1695,7 @@ static void iucv_callback_shutdown(struct iucv_path *path, u8 ipuser[16])
1682 bh_unlock_sock(sk); 1695 bh_unlock_sock(sk);
1683} 1696}
1684 1697
1685static struct proto_ops iucv_sock_ops = { 1698static const struct proto_ops iucv_sock_ops = {
1686 .family = PF_IUCV, 1699 .family = PF_IUCV,
1687 .owner = THIS_MODULE, 1700 .owner = THIS_MODULE,
1688 .release = iucv_sock_release, 1701 .release = iucv_sock_release,
diff --git a/net/iucv/iucv.c b/net/iucv/iucv.c
index c833481d32e3..3973d0e61e56 100644
--- a/net/iucv/iucv.c
+++ b/net/iucv/iucv.c
@@ -79,6 +79,14 @@ static int iucv_bus_match(struct device *dev, struct device_driver *drv)
79 return 0; 79 return 0;
80} 80}
81 81
82enum iucv_pm_states {
83 IUCV_PM_INITIAL = 0,
84 IUCV_PM_FREEZING = 1,
85 IUCV_PM_THAWING = 2,
86 IUCV_PM_RESTORING = 3,
87};
88static enum iucv_pm_states iucv_pm_state;
89
82static int iucv_pm_prepare(struct device *); 90static int iucv_pm_prepare(struct device *);
83static void iucv_pm_complete(struct device *); 91static void iucv_pm_complete(struct device *);
84static int iucv_pm_freeze(struct device *); 92static int iucv_pm_freeze(struct device *);
@@ -354,7 +362,7 @@ static int iucv_query_maxconn(void)
354 " srl %0,28\n" 362 " srl %0,28\n"
355 : "=d" (ccode), "+d" (reg0), "+d" (reg1) : : "cc"); 363 : "=d" (ccode), "+d" (reg0), "+d" (reg1) : : "cc");
356 if (ccode == 0) 364 if (ccode == 0)
357 iucv_max_pathid = reg0; 365 iucv_max_pathid = reg1;
358 kfree(param); 366 kfree(param);
359 return ccode ? -EPERM : 0; 367 return ccode ? -EPERM : 0;
360} 368}
@@ -856,7 +864,7 @@ int iucv_path_accept(struct iucv_path *path, struct iucv_handler *handler,
856 int rc; 864 int rc;
857 865
858 local_bh_disable(); 866 local_bh_disable();
859 if (!cpu_isset(smp_processor_id(), iucv_buffer_cpumask)) { 867 if (cpus_empty(iucv_buffer_cpumask)) {
860 rc = -EIO; 868 rc = -EIO;
861 goto out; 869 goto out;
862 } 870 }
@@ -905,7 +913,7 @@ int iucv_path_connect(struct iucv_path *path, struct iucv_handler *handler,
905 913
906 spin_lock_bh(&iucv_table_lock); 914 spin_lock_bh(&iucv_table_lock);
907 iucv_cleanup_queue(); 915 iucv_cleanup_queue();
908 if (!cpu_isset(smp_processor_id(), iucv_buffer_cpumask)) { 916 if (cpus_empty(iucv_buffer_cpumask)) {
909 rc = -EIO; 917 rc = -EIO;
910 goto out; 918 goto out;
911 } 919 }
@@ -965,7 +973,7 @@ int iucv_path_quiesce(struct iucv_path *path, u8 userdata[16])
965 int rc; 973 int rc;
966 974
967 local_bh_disable(); 975 local_bh_disable();
968 if (!cpu_isset(smp_processor_id(), iucv_buffer_cpumask)) { 976 if (cpus_empty(iucv_buffer_cpumask)) {
969 rc = -EIO; 977 rc = -EIO;
970 goto out; 978 goto out;
971 } 979 }
@@ -997,7 +1005,7 @@ int iucv_path_resume(struct iucv_path *path, u8 userdata[16])
997 int rc; 1005 int rc;
998 1006
999 local_bh_disable(); 1007 local_bh_disable();
1000 if (!cpu_isset(smp_processor_id(), iucv_buffer_cpumask)) { 1008 if (cpus_empty(iucv_buffer_cpumask)) {
1001 rc = -EIO; 1009 rc = -EIO;
1002 goto out; 1010 goto out;
1003 } 1011 }
@@ -1026,7 +1034,7 @@ int iucv_path_sever(struct iucv_path *path, u8 userdata[16])
1026 int rc; 1034 int rc;
1027 1035
1028 preempt_disable(); 1036 preempt_disable();
1029 if (!cpu_isset(smp_processor_id(), iucv_buffer_cpumask)) { 1037 if (cpus_empty(iucv_buffer_cpumask)) {
1030 rc = -EIO; 1038 rc = -EIO;
1031 goto out; 1039 goto out;
1032 } 1040 }
@@ -1060,7 +1068,7 @@ int iucv_message_purge(struct iucv_path *path, struct iucv_message *msg,
1060 int rc; 1068 int rc;
1061 1069
1062 local_bh_disable(); 1070 local_bh_disable();
1063 if (!cpu_isset(smp_processor_id(), iucv_buffer_cpumask)) { 1071 if (cpus_empty(iucv_buffer_cpumask)) {
1064 rc = -EIO; 1072 rc = -EIO;
1065 goto out; 1073 goto out;
1066 } 1074 }
@@ -1152,7 +1160,7 @@ int __iucv_message_receive(struct iucv_path *path, struct iucv_message *msg,
1152 if (msg->flags & IUCV_IPRMDATA) 1160 if (msg->flags & IUCV_IPRMDATA)
1153 return iucv_message_receive_iprmdata(path, msg, flags, 1161 return iucv_message_receive_iprmdata(path, msg, flags,
1154 buffer, size, residual); 1162 buffer, size, residual);
1155 if (!cpu_isset(smp_processor_id(), iucv_buffer_cpumask)) { 1163 if (cpus_empty(iucv_buffer_cpumask)) {
1156 rc = -EIO; 1164 rc = -EIO;
1157 goto out; 1165 goto out;
1158 } 1166 }
@@ -1225,7 +1233,7 @@ int iucv_message_reject(struct iucv_path *path, struct iucv_message *msg)
1225 int rc; 1233 int rc;
1226 1234
1227 local_bh_disable(); 1235 local_bh_disable();
1228 if (!cpu_isset(smp_processor_id(), iucv_buffer_cpumask)) { 1236 if (cpus_empty(iucv_buffer_cpumask)) {
1229 rc = -EIO; 1237 rc = -EIO;
1230 goto out; 1238 goto out;
1231 } 1239 }
@@ -1264,7 +1272,7 @@ int iucv_message_reply(struct iucv_path *path, struct iucv_message *msg,
1264 int rc; 1272 int rc;
1265 1273
1266 local_bh_disable(); 1274 local_bh_disable();
1267 if (!cpu_isset(smp_processor_id(), iucv_buffer_cpumask)) { 1275 if (cpus_empty(iucv_buffer_cpumask)) {
1268 rc = -EIO; 1276 rc = -EIO;
1269 goto out; 1277 goto out;
1270 } 1278 }
@@ -1314,7 +1322,7 @@ int __iucv_message_send(struct iucv_path *path, struct iucv_message *msg,
1314 union iucv_param *parm; 1322 union iucv_param *parm;
1315 int rc; 1323 int rc;
1316 1324
1317 if (!cpu_isset(smp_processor_id(), iucv_buffer_cpumask)) { 1325 if (cpus_empty(iucv_buffer_cpumask)) {
1318 rc = -EIO; 1326 rc = -EIO;
1319 goto out; 1327 goto out;
1320 } 1328 }
@@ -1401,7 +1409,7 @@ int iucv_message_send2way(struct iucv_path *path, struct iucv_message *msg,
1401 int rc; 1409 int rc;
1402 1410
1403 local_bh_disable(); 1411 local_bh_disable();
1404 if (!cpu_isset(smp_processor_id(), iucv_buffer_cpumask)) { 1412 if (cpus_empty(iucv_buffer_cpumask)) {
1405 rc = -EIO; 1413 rc = -EIO;
1406 goto out; 1414 goto out;
1407 } 1415 }
@@ -1875,6 +1883,7 @@ static int iucv_pm_freeze(struct device *dev)
1875#ifdef CONFIG_PM_DEBUG 1883#ifdef CONFIG_PM_DEBUG
1876 printk(KERN_WARNING "iucv_pm_freeze\n"); 1884 printk(KERN_WARNING "iucv_pm_freeze\n");
1877#endif 1885#endif
1886 iucv_pm_state = IUCV_PM_FREEZING;
1878 for_each_cpu_mask_nr(cpu, iucv_irq_cpumask) 1887 for_each_cpu_mask_nr(cpu, iucv_irq_cpumask)
1879 smp_call_function_single(cpu, iucv_block_cpu_almost, NULL, 1); 1888 smp_call_function_single(cpu, iucv_block_cpu_almost, NULL, 1);
1880 if (dev->driver && dev->driver->pm && dev->driver->pm->freeze) 1889 if (dev->driver && dev->driver->pm && dev->driver->pm->freeze)
@@ -1899,6 +1908,7 @@ static int iucv_pm_thaw(struct device *dev)
1899#ifdef CONFIG_PM_DEBUG 1908#ifdef CONFIG_PM_DEBUG
1900 printk(KERN_WARNING "iucv_pm_thaw\n"); 1909 printk(KERN_WARNING "iucv_pm_thaw\n");
1901#endif 1910#endif
1911 iucv_pm_state = IUCV_PM_THAWING;
1902 if (!iucv_path_table) { 1912 if (!iucv_path_table) {
1903 rc = iucv_enable(); 1913 rc = iucv_enable();
1904 if (rc) 1914 if (rc)
@@ -1933,6 +1943,10 @@ static int iucv_pm_restore(struct device *dev)
1933#ifdef CONFIG_PM_DEBUG 1943#ifdef CONFIG_PM_DEBUG
1934 printk(KERN_WARNING "iucv_pm_restore %p\n", iucv_path_table); 1944 printk(KERN_WARNING "iucv_pm_restore %p\n", iucv_path_table);
1935#endif 1945#endif
1946 if ((iucv_pm_state != IUCV_PM_RESTORING) && iucv_path_table)
1947 pr_warning("Suspending Linux did not completely close all IUCV "
1948 "connections\n");
1949 iucv_pm_state = IUCV_PM_RESTORING;
1936 if (cpus_empty(iucv_irq_cpumask)) { 1950 if (cpus_empty(iucv_irq_cpumask)) {
1937 rc = iucv_query_maxconn(); 1951 rc = iucv_query_maxconn();
1938 rc = iucv_enable(); 1952 rc = iucv_enable();
diff --git a/net/llc/af_llc.c b/net/llc/af_llc.c
index c45eee1c0e8d..7aa4fd170104 100644
--- a/net/llc/af_llc.c
+++ b/net/llc/af_llc.c
@@ -973,7 +973,7 @@ static int llc_ui_ioctl(struct socket *sock, unsigned int cmd,
973 * Set various connection specific parameters. 973 * Set various connection specific parameters.
974 */ 974 */
975static int llc_ui_setsockopt(struct socket *sock, int level, int optname, 975static int llc_ui_setsockopt(struct socket *sock, int level, int optname,
976 char __user *optval, int optlen) 976 char __user *optval, unsigned int optlen)
977{ 977{
978 struct sock *sk = sock->sk; 978 struct sock *sk = sock->sk;
979 struct llc_sock *llc = llc_sk(sk); 979 struct llc_sock *llc = llc_sk(sk);
diff --git a/net/mac80211/ibss.c b/net/mac80211/ibss.c
index 920ec8792f4b..6eaf69823439 100644
--- a/net/mac80211/ibss.c
+++ b/net/mac80211/ibss.c
@@ -544,7 +544,7 @@ static void ieee80211_sta_find_ibss(struct ieee80211_sub_if_data *sdata)
544 "%pM\n", bss->cbss.bssid, ifibss->bssid); 544 "%pM\n", bss->cbss.bssid, ifibss->bssid);
545#endif /* CONFIG_MAC80211_IBSS_DEBUG */ 545#endif /* CONFIG_MAC80211_IBSS_DEBUG */
546 546
547 if (bss && memcmp(ifibss->bssid, bss->cbss.bssid, ETH_ALEN)) { 547 if (bss && !memcmp(ifibss->bssid, bss->cbss.bssid, ETH_ALEN)) {
548 printk(KERN_DEBUG "%s: Selected IBSS BSSID %pM" 548 printk(KERN_DEBUG "%s: Selected IBSS BSSID %pM"
549 " based on configured SSID\n", 549 " based on configured SSID\n",
550 sdata->dev->name, bss->cbss.bssid); 550 sdata->dev->name, bss->cbss.bssid);
@@ -829,7 +829,7 @@ void ieee80211_ibss_notify_scan_completed(struct ieee80211_local *local)
829 if (!sdata->u.ibss.ssid_len) 829 if (!sdata->u.ibss.ssid_len)
830 continue; 830 continue;
831 sdata->u.ibss.last_scan_completed = jiffies; 831 sdata->u.ibss.last_scan_completed = jiffies;
832 ieee80211_sta_find_ibss(sdata); 832 mod_timer(&sdata->u.ibss.timer, 0);
833 } 833 }
834 mutex_unlock(&local->iflist_mtx); 834 mutex_unlock(&local->iflist_mtx);
835} 835}
diff --git a/net/mac80211/mlme.c b/net/mac80211/mlme.c
index 97a278a2f48e..8d26e9bf8964 100644
--- a/net/mac80211/mlme.c
+++ b/net/mac80211/mlme.c
@@ -1388,8 +1388,8 @@ ieee80211_rx_mgmt_disassoc(struct ieee80211_sub_if_data *sdata,
1388 1388
1389 reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code); 1389 reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code);
1390 1390
1391 printk(KERN_DEBUG "%s: disassociated (Reason: %u)\n", 1391 printk(KERN_DEBUG "%s: disassociated from %pM (Reason: %u)\n",
1392 sdata->dev->name, reason_code); 1392 sdata->dev->name, mgmt->sa, reason_code);
1393 1393
1394 ieee80211_set_disassoc(sdata, false); 1394 ieee80211_set_disassoc(sdata, false);
1395 return RX_MGMT_CFG80211_DISASSOC; 1395 return RX_MGMT_CFG80211_DISASSOC;
@@ -1675,7 +1675,7 @@ static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_sub_if_data *sdata,
1675 1675
1676 /* direct probe may be part of the association flow */ 1676 /* direct probe may be part of the association flow */
1677 if (wk && wk->state == IEEE80211_MGD_STATE_PROBE) { 1677 if (wk && wk->state == IEEE80211_MGD_STATE_PROBE) {
1678 printk(KERN_DEBUG "%s direct probe responded\n", 1678 printk(KERN_DEBUG "%s: direct probe responded\n",
1679 sdata->dev->name); 1679 sdata->dev->name);
1680 wk->tries = 0; 1680 wk->tries = 0;
1681 wk->state = IEEE80211_MGD_STATE_AUTH; 1681 wk->state = IEEE80211_MGD_STATE_AUTH;
@@ -2502,9 +2502,6 @@ int ieee80211_mgd_deauth(struct ieee80211_sub_if_data *sdata,
2502 struct ieee80211_mgd_work *wk; 2502 struct ieee80211_mgd_work *wk;
2503 const u8 *bssid = NULL; 2503 const u8 *bssid = NULL;
2504 2504
2505 printk(KERN_DEBUG "%s: deauthenticating by local choice (reason=%d)\n",
2506 sdata->dev->name, req->reason_code);
2507
2508 mutex_lock(&ifmgd->mtx); 2505 mutex_lock(&ifmgd->mtx);
2509 2506
2510 if (ifmgd->associated && &ifmgd->associated->cbss == req->bss) { 2507 if (ifmgd->associated && &ifmgd->associated->cbss == req->bss) {
@@ -2532,6 +2529,9 @@ int ieee80211_mgd_deauth(struct ieee80211_sub_if_data *sdata,
2532 2529
2533 mutex_unlock(&ifmgd->mtx); 2530 mutex_unlock(&ifmgd->mtx);
2534 2531
2532 printk(KERN_DEBUG "%s: deauthenticating from %pM by local choice (reason=%d)\n",
2533 sdata->dev->name, bssid, req->reason_code);
2534
2535 ieee80211_send_deauth_disassoc(sdata, bssid, 2535 ieee80211_send_deauth_disassoc(sdata, bssid,
2536 IEEE80211_STYPE_DEAUTH, req->reason_code, 2536 IEEE80211_STYPE_DEAUTH, req->reason_code,
2537 cookie); 2537 cookie);
@@ -2545,9 +2545,6 @@ int ieee80211_mgd_disassoc(struct ieee80211_sub_if_data *sdata,
2545{ 2545{
2546 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 2546 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2547 2547
2548 printk(KERN_DEBUG "%s: disassociating by local choice (reason=%d)\n",
2549 sdata->dev->name, req->reason_code);
2550
2551 mutex_lock(&ifmgd->mtx); 2548 mutex_lock(&ifmgd->mtx);
2552 2549
2553 /* 2550 /*
@@ -2561,6 +2558,9 @@ int ieee80211_mgd_disassoc(struct ieee80211_sub_if_data *sdata,
2561 return -ENOLINK; 2558 return -ENOLINK;
2562 } 2559 }
2563 2560
2561 printk(KERN_DEBUG "%s: disassociating from %pM by local choice (reason=%d)\n",
2562 sdata->dev->name, req->bss->bssid, req->reason_code);
2563
2564 ieee80211_set_disassoc(sdata, false); 2564 ieee80211_set_disassoc(sdata, false);
2565 2565
2566 mutex_unlock(&ifmgd->mtx); 2566 mutex_unlock(&ifmgd->mtx);
diff --git a/net/mac80211/rc80211_minstrel.c b/net/mac80211/rc80211_minstrel.c
index 7c5142988bbb..6e5d68b4e427 100644
--- a/net/mac80211/rc80211_minstrel.c
+++ b/net/mac80211/rc80211_minstrel.c
@@ -418,7 +418,7 @@ minstrel_rate_init(void *priv, struct ieee80211_supported_band *sband,
418 418
419 /* contention window */ 419 /* contention window */
420 tx_time_single += t_slot + min(cw, mp->cw_max); 420 tx_time_single += t_slot + min(cw, mp->cw_max);
421 cw = (cw + 1) << 1; 421 cw = (cw << 1) | 1;
422 422
423 tx_time += tx_time_single; 423 tx_time += tx_time_single;
424 tx_time_cts += tx_time_single + mi->sp_ack_dur; 424 tx_time_cts += tx_time_single + mi->sp_ack_dur;
diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
index a59043fbb0ff..45667054a5f3 100644
--- a/net/mac80211/rc80211_pid_debugfs.c
+++ b/net/mac80211/rc80211_pid_debugfs.c
@@ -6,6 +6,7 @@
6 * published by the Free Software Foundation. 6 * published by the Free Software Foundation.
7 */ 7 */
8 8
9#include <linux/sched.h>
9#include <linux/spinlock.h> 10#include <linux/spinlock.h>
10#include <linux/poll.h> 11#include <linux/poll.h>
11#include <linux/netdevice.h> 12#include <linux/netdevice.h>
diff --git a/net/mac80211/rx.c b/net/mac80211/rx.c
index c01588f9d453..7170bf4565a8 100644
--- a/net/mac80211/rx.c
+++ b/net/mac80211/rx.c
@@ -2164,11 +2164,17 @@ static void __ieee80211_rx_handle_packet(struct ieee80211_hw *hw,
2164 2164
2165 skb = rx.skb; 2165 skb = rx.skb;
2166 2166
2167 list_for_each_entry_rcu(sdata, &local->interfaces, list) { 2167 if (rx.sdata && ieee80211_is_data(hdr->frame_control)) {
2168 rx.flags |= IEEE80211_RX_RA_MATCH;
2169 prepares = prepare_for_handlers(rx.sdata, &rx, hdr);
2170 if (prepares)
2171 prev = rx.sdata;
2172 } else list_for_each_entry_rcu(sdata, &local->interfaces, list) {
2168 if (!netif_running(sdata->dev)) 2173 if (!netif_running(sdata->dev))
2169 continue; 2174 continue;
2170 2175
2171 if (sdata->vif.type == NL80211_IFTYPE_MONITOR) 2176 if (sdata->vif.type == NL80211_IFTYPE_MONITOR ||
2177 sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
2172 continue; 2178 continue;
2173 2179
2174 rx.flags |= IEEE80211_RX_RA_MATCH; 2180 rx.flags |= IEEE80211_RX_RA_MATCH;
@@ -2447,6 +2453,8 @@ void ieee80211_rx(struct ieee80211_hw *hw, struct sk_buff *skb)
2447 struct ieee80211_supported_band *sband; 2453 struct ieee80211_supported_band *sband;
2448 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb); 2454 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
2449 2455
2456 WARN_ON_ONCE(softirq_count() == 0);
2457
2450 if (WARN_ON(status->band < 0 || 2458 if (WARN_ON(status->band < 0 ||
2451 status->band >= IEEE80211_NUM_BANDS)) 2459 status->band >= IEEE80211_NUM_BANDS))
2452 goto drop; 2460 goto drop;
diff --git a/net/mac80211/scan.c b/net/mac80211/scan.c
index 039901109fa1..71e10cabf811 100644
--- a/net/mac80211/scan.c
+++ b/net/mac80211/scan.c
@@ -90,8 +90,8 @@ ieee80211_bss_info_update(struct ieee80211_local *local,
90 bss->dtim_period = tim_ie->dtim_period; 90 bss->dtim_period = tim_ie->dtim_period;
91 } 91 }
92 92
93 /* set default value for buggy APs */ 93 /* set default value for buggy AP/no TIM element */
94 if (!elems->tim || bss->dtim_period == 0) 94 if (bss->dtim_period == 0)
95 bss->dtim_period = 1; 95 bss->dtim_period = 1;
96 96
97 bss->supp_rates_len = 0; 97 bss->supp_rates_len = 0;
diff --git a/net/mac80211/sta_info.c b/net/mac80211/sta_info.c
index eec001491e66..594f2318c3d8 100644
--- a/net/mac80211/sta_info.c
+++ b/net/mac80211/sta_info.c
@@ -361,6 +361,7 @@ int sta_info_insert(struct sta_info *sta)
361 u.ap); 361 u.ap);
362 362
363 drv_sta_notify(local, &sdata->vif, STA_NOTIFY_ADD, &sta->sta); 363 drv_sta_notify(local, &sdata->vif, STA_NOTIFY_ADD, &sta->sta);
364 sdata = sta->sdata;
364 } 365 }
365 366
366#ifdef CONFIG_MAC80211_VERBOSE_DEBUG 367#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
@@ -496,6 +497,7 @@ static void __sta_info_unlink(struct sta_info **sta)
496 497
497 drv_sta_notify(local, &sdata->vif, STA_NOTIFY_REMOVE, 498 drv_sta_notify(local, &sdata->vif, STA_NOTIFY_REMOVE,
498 &(*sta)->sta); 499 &(*sta)->sta);
500 sdata = (*sta)->sdata;
499 } 501 }
500 502
501 if (ieee80211_vif_is_mesh(&sdata->vif)) { 503 if (ieee80211_vif_is_mesh(&sdata->vif)) {
diff --git a/net/mac80211/tx.c b/net/mac80211/tx.c
index 5143d203256b..db4bda681ec9 100644
--- a/net/mac80211/tx.c
+++ b/net/mac80211/tx.c
@@ -367,7 +367,10 @@ ieee80211_tx_h_unicast_ps_buf(struct ieee80211_tx_data *tx)
367 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data; 367 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data;
368 u32 staflags; 368 u32 staflags;
369 369
370 if (unlikely(!sta || ieee80211_is_probe_resp(hdr->frame_control))) 370 if (unlikely(!sta || ieee80211_is_probe_resp(hdr->frame_control)
371 || ieee80211_is_auth(hdr->frame_control)
372 || ieee80211_is_assoc_resp(hdr->frame_control)
373 || ieee80211_is_reassoc_resp(hdr->frame_control)))
371 return TX_CONTINUE; 374 return TX_CONTINUE;
372 375
373 staflags = get_sta_flags(sta); 376 staflags = get_sta_flags(sta);
@@ -1701,7 +1704,8 @@ netdev_tx_t ieee80211_subif_start_xmit(struct sk_buff *skb,
1701 if (!is_multicast_ether_addr(hdr.addr1)) { 1704 if (!is_multicast_ether_addr(hdr.addr1)) {
1702 rcu_read_lock(); 1705 rcu_read_lock();
1703 sta = sta_info_get(local, hdr.addr1); 1706 sta = sta_info_get(local, hdr.addr1);
1704 if (sta) 1707 /* XXX: in the future, use sdata to look up the sta */
1708 if (sta && sta->sdata == sdata)
1705 sta_flags = get_sta_flags(sta); 1709 sta_flags = get_sta_flags(sta);
1706 rcu_read_unlock(); 1710 rcu_read_unlock();
1707 } 1711 }
diff --git a/net/mac80211/util.c b/net/mac80211/util.c
index dd6564321369..aeb65b3d2295 100644
--- a/net/mac80211/util.c
+++ b/net/mac80211/util.c
@@ -339,7 +339,7 @@ void ieee80211_add_pending_skb(struct ieee80211_local *local,
339 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); 339 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
340 340
341 if (WARN_ON(!info->control.vif)) { 341 if (WARN_ON(!info->control.vif)) {
342 kfree(skb); 342 kfree_skb(skb);
343 return; 343 return;
344 } 344 }
345 345
@@ -367,7 +367,7 @@ int ieee80211_add_pending_skbs(struct ieee80211_local *local,
367 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); 367 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
368 368
369 if (WARN_ON(!info->control.vif)) { 369 if (WARN_ON(!info->control.vif)) {
370 kfree(skb); 370 kfree_skb(skb);
371 continue; 371 continue;
372 } 372 }
373 373
diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
index fba2892b99e1..446e9bd4b4bc 100644
--- a/net/netfilter/ipvs/ip_vs_ctl.c
+++ b/net/netfilter/ipvs/ip_vs_ctl.c
@@ -1496,14 +1496,14 @@ static int ip_vs_zero_all(void)
1496 1496
1497 1497
1498static int 1498static int
1499proc_do_defense_mode(ctl_table *table, int write, struct file * filp, 1499proc_do_defense_mode(ctl_table *table, int write,
1500 void __user *buffer, size_t *lenp, loff_t *ppos) 1500 void __user *buffer, size_t *lenp, loff_t *ppos)
1501{ 1501{
1502 int *valp = table->data; 1502 int *valp = table->data;
1503 int val = *valp; 1503 int val = *valp;
1504 int rc; 1504 int rc;
1505 1505
1506 rc = proc_dointvec(table, write, filp, buffer, lenp, ppos); 1506 rc = proc_dointvec(table, write, buffer, lenp, ppos);
1507 if (write && (*valp != val)) { 1507 if (write && (*valp != val)) {
1508 if ((*valp < 0) || (*valp > 3)) { 1508 if ((*valp < 0) || (*valp > 3)) {
1509 /* Restore the correct value */ 1509 /* Restore the correct value */
@@ -1517,7 +1517,7 @@ proc_do_defense_mode(ctl_table *table, int write, struct file * filp,
1517 1517
1518 1518
1519static int 1519static int
1520proc_do_sync_threshold(ctl_table *table, int write, struct file *filp, 1520proc_do_sync_threshold(ctl_table *table, int write,
1521 void __user *buffer, size_t *lenp, loff_t *ppos) 1521 void __user *buffer, size_t *lenp, loff_t *ppos)
1522{ 1522{
1523 int *valp = table->data; 1523 int *valp = table->data;
@@ -1527,7 +1527,7 @@ proc_do_sync_threshold(ctl_table *table, int write, struct file *filp,
1527 /* backup the value first */ 1527 /* backup the value first */
1528 memcpy(val, valp, sizeof(val)); 1528 memcpy(val, valp, sizeof(val));
1529 1529
1530 rc = proc_dointvec(table, write, filp, buffer, lenp, ppos); 1530 rc = proc_dointvec(table, write, buffer, lenp, ppos);
1531 if (write && (valp[0] < 0 || valp[1] < 0 || valp[0] >= valp[1])) { 1531 if (write && (valp[0] < 0 || valp[1] < 0 || valp[0] >= valp[1])) {
1532 /* Restore the correct value */ 1532 /* Restore the correct value */
1533 memcpy(valp, val, sizeof(val)); 1533 memcpy(valp, val, sizeof(val));
diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
index b37109817a98..ca6e68dcd8a8 100644
--- a/net/netfilter/nf_conntrack_core.c
+++ b/net/netfilter/nf_conntrack_core.c
@@ -14,6 +14,7 @@
14#include <linux/types.h> 14#include <linux/types.h>
15#include <linux/netfilter.h> 15#include <linux/netfilter.h>
16#include <linux/module.h> 16#include <linux/module.h>
17#include <linux/sched.h>
17#include <linux/skbuff.h> 18#include <linux/skbuff.h>
18#include <linux/proc_fs.h> 19#include <linux/proc_fs.h>
19#include <linux/vmalloc.h> 20#include <linux/vmalloc.h>
@@ -1245,9 +1246,9 @@ static int nf_conntrack_init_init_net(void)
1245 * machine has 512 buckets. >= 1GB machines have 16384 buckets. */ 1246 * machine has 512 buckets. >= 1GB machines have 16384 buckets. */
1246 if (!nf_conntrack_htable_size) { 1247 if (!nf_conntrack_htable_size) {
1247 nf_conntrack_htable_size 1248 nf_conntrack_htable_size
1248 = (((num_physpages << PAGE_SHIFT) / 16384) 1249 = (((totalram_pages << PAGE_SHIFT) / 16384)
1249 / sizeof(struct hlist_head)); 1250 / sizeof(struct hlist_head));
1250 if (num_physpages > (1024 * 1024 * 1024 / PAGE_SIZE)) 1251 if (totalram_pages > (1024 * 1024 * 1024 / PAGE_SIZE))
1251 nf_conntrack_htable_size = 16384; 1252 nf_conntrack_htable_size = 16384;
1252 if (nf_conntrack_htable_size < 32) 1253 if (nf_conntrack_htable_size < 32)
1253 nf_conntrack_htable_size = 32; 1254 nf_conntrack_htable_size = 32;
diff --git a/net/netfilter/nf_log.c b/net/netfilter/nf_log.c
index 4e620305f28c..c93494fef8ef 100644
--- a/net/netfilter/nf_log.c
+++ b/net/netfilter/nf_log.c
@@ -226,7 +226,7 @@ static char nf_log_sysctl_fnames[NFPROTO_NUMPROTO-NFPROTO_UNSPEC][3];
226static struct ctl_table nf_log_sysctl_table[NFPROTO_NUMPROTO+1]; 226static struct ctl_table nf_log_sysctl_table[NFPROTO_NUMPROTO+1];
227static struct ctl_table_header *nf_log_dir_header; 227static struct ctl_table_header *nf_log_dir_header;
228 228
229static int nf_log_proc_dostring(ctl_table *table, int write, struct file *filp, 229static int nf_log_proc_dostring(ctl_table *table, int write,
230 void __user *buffer, size_t *lenp, loff_t *ppos) 230 void __user *buffer, size_t *lenp, loff_t *ppos)
231{ 231{
232 const struct nf_logger *logger; 232 const struct nf_logger *logger;
@@ -260,7 +260,7 @@ static int nf_log_proc_dostring(ctl_table *table, int write, struct file *filp,
260 table->data = "NONE"; 260 table->data = "NONE";
261 else 261 else
262 table->data = logger->name; 262 table->data = logger->name;
263 r = proc_dostring(table, write, filp, buffer, lenp, ppos); 263 r = proc_dostring(table, write, buffer, lenp, ppos);
264 mutex_unlock(&nf_log_mutex); 264 mutex_unlock(&nf_log_mutex);
265 } 265 }
266 266
diff --git a/net/netfilter/nf_sockopt.c b/net/netfilter/nf_sockopt.c
index 8ab829f86574..f042ae521557 100644
--- a/net/netfilter/nf_sockopt.c
+++ b/net/netfilter/nf_sockopt.c
@@ -113,7 +113,7 @@ static int nf_sockopt(struct sock *sk, u_int8_t pf, int val,
113} 113}
114 114
115int nf_setsockopt(struct sock *sk, u_int8_t pf, int val, char __user *opt, 115int nf_setsockopt(struct sock *sk, u_int8_t pf, int val, char __user *opt,
116 int len) 116 unsigned int len)
117{ 117{
118 return nf_sockopt(sk, pf, val, opt, &len, 0); 118 return nf_sockopt(sk, pf, val, opt, &len, 0);
119} 119}
@@ -154,7 +154,7 @@ static int compat_nf_sockopt(struct sock *sk, u_int8_t pf, int val,
154} 154}
155 155
156int compat_nf_setsockopt(struct sock *sk, u_int8_t pf, 156int compat_nf_setsockopt(struct sock *sk, u_int8_t pf,
157 int val, char __user *opt, int len) 157 int val, char __user *opt, unsigned int len)
158{ 158{
159 return compat_nf_sockopt(sk, pf, val, opt, &len, 0); 159 return compat_nf_sockopt(sk, pf, val, opt, &len, 0);
160} 160}
diff --git a/net/netfilter/x_tables.c b/net/netfilter/x_tables.c
index a6ac83a93348..f01955cce314 100644
--- a/net/netfilter/x_tables.c
+++ b/net/netfilter/x_tables.c
@@ -617,7 +617,7 @@ struct xt_table_info *xt_alloc_table_info(unsigned int size)
617 int cpu; 617 int cpu;
618 618
619 /* Pedantry: prevent them from hitting BUG() in vmalloc.c --RR */ 619 /* Pedantry: prevent them from hitting BUG() in vmalloc.c --RR */
620 if ((SMP_ALIGN(size) >> PAGE_SHIFT) + 2 > num_physpages) 620 if ((SMP_ALIGN(size) >> PAGE_SHIFT) + 2 > totalram_pages)
621 return NULL; 621 return NULL;
622 622
623 newinfo = kzalloc(XT_TABLE_INFO_SZ, GFP_KERNEL); 623 newinfo = kzalloc(XT_TABLE_INFO_SZ, GFP_KERNEL);
diff --git a/net/netfilter/xt_hashlimit.c b/net/netfilter/xt_hashlimit.c
index 219dcdbe388c..dd16e404424f 100644
--- a/net/netfilter/xt_hashlimit.c
+++ b/net/netfilter/xt_hashlimit.c
@@ -194,9 +194,9 @@ static int htable_create_v0(struct xt_hashlimit_info *minfo, u_int8_t family)
194 if (minfo->cfg.size) 194 if (minfo->cfg.size)
195 size = minfo->cfg.size; 195 size = minfo->cfg.size;
196 else { 196 else {
197 size = ((num_physpages << PAGE_SHIFT) / 16384) / 197 size = ((totalram_pages << PAGE_SHIFT) / 16384) /
198 sizeof(struct list_head); 198 sizeof(struct list_head);
199 if (num_physpages > (1024 * 1024 * 1024 / PAGE_SIZE)) 199 if (totalram_pages > (1024 * 1024 * 1024 / PAGE_SIZE))
200 size = 8192; 200 size = 8192;
201 if (size < 16) 201 if (size < 16)
202 size = 16; 202 size = 16;
@@ -266,9 +266,9 @@ static int htable_create(struct xt_hashlimit_mtinfo1 *minfo, u_int8_t family)
266 if (minfo->cfg.size) { 266 if (minfo->cfg.size) {
267 size = minfo->cfg.size; 267 size = minfo->cfg.size;
268 } else { 268 } else {
269 size = (num_physpages << PAGE_SHIFT) / 16384 / 269 size = (totalram_pages << PAGE_SHIFT) / 16384 /
270 sizeof(struct list_head); 270 sizeof(struct list_head);
271 if (num_physpages > 1024 * 1024 * 1024 / PAGE_SIZE) 271 if (totalram_pages > 1024 * 1024 * 1024 / PAGE_SIZE)
272 size = 8192; 272 size = 8192;
273 if (size < 16) 273 if (size < 16)
274 size = 16; 274 size = 16;
diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
index d0ff382c40ca..19e98007691c 100644
--- a/net/netlink/af_netlink.c
+++ b/net/netlink/af_netlink.c
@@ -177,9 +177,11 @@ static void netlink_sock_destruct(struct sock *sk)
177 * this, _but_ remember, it adds useless work on UP machines. 177 * this, _but_ remember, it adds useless work on UP machines.
178 */ 178 */
179 179
180static void netlink_table_grab(void) 180void netlink_table_grab(void)
181 __acquires(nl_table_lock) 181 __acquires(nl_table_lock)
182{ 182{
183 might_sleep();
184
183 write_lock_irq(&nl_table_lock); 185 write_lock_irq(&nl_table_lock);
184 186
185 if (atomic_read(&nl_table_users)) { 187 if (atomic_read(&nl_table_users)) {
@@ -200,7 +202,7 @@ static void netlink_table_grab(void)
200 } 202 }
201} 203}
202 204
203static void netlink_table_ungrab(void) 205void netlink_table_ungrab(void)
204 __releases(nl_table_lock) 206 __releases(nl_table_lock)
205{ 207{
206 write_unlock_irq(&nl_table_lock); 208 write_unlock_irq(&nl_table_lock);
@@ -1148,7 +1150,7 @@ static void netlink_update_socket_mc(struct netlink_sock *nlk,
1148} 1150}
1149 1151
1150static int netlink_setsockopt(struct socket *sock, int level, int optname, 1152static int netlink_setsockopt(struct socket *sock, int level, int optname,
1151 char __user *optval, int optlen) 1153 char __user *optval, unsigned int optlen)
1152{ 1154{
1153 struct sock *sk = sock->sk; 1155 struct sock *sk = sock->sk;
1154 struct netlink_sock *nlk = nlk_sk(sk); 1156 struct netlink_sock *nlk = nlk_sk(sk);
@@ -1549,37 +1551,21 @@ static void netlink_free_old_listeners(struct rcu_head *rcu_head)
1549 kfree(lrh->ptr); 1551 kfree(lrh->ptr);
1550} 1552}
1551 1553
1552/** 1554int __netlink_change_ngroups(struct sock *sk, unsigned int groups)
1553 * netlink_change_ngroups - change number of multicast groups
1554 *
1555 * This changes the number of multicast groups that are available
1556 * on a certain netlink family. Note that it is not possible to
1557 * change the number of groups to below 32. Also note that it does
1558 * not implicitly call netlink_clear_multicast_users() when the
1559 * number of groups is reduced.
1560 *
1561 * @sk: The kernel netlink socket, as returned by netlink_kernel_create().
1562 * @groups: The new number of groups.
1563 */
1564int netlink_change_ngroups(struct sock *sk, unsigned int groups)
1565{ 1555{
1566 unsigned long *listeners, *old = NULL; 1556 unsigned long *listeners, *old = NULL;
1567 struct listeners_rcu_head *old_rcu_head; 1557 struct listeners_rcu_head *old_rcu_head;
1568 struct netlink_table *tbl = &nl_table[sk->sk_protocol]; 1558 struct netlink_table *tbl = &nl_table[sk->sk_protocol];
1569 int err = 0;
1570 1559
1571 if (groups < 32) 1560 if (groups < 32)
1572 groups = 32; 1561 groups = 32;
1573 1562
1574 netlink_table_grab();
1575 if (NLGRPSZ(tbl->groups) < NLGRPSZ(groups)) { 1563 if (NLGRPSZ(tbl->groups) < NLGRPSZ(groups)) {
1576 listeners = kzalloc(NLGRPSZ(groups) + 1564 listeners = kzalloc(NLGRPSZ(groups) +
1577 sizeof(struct listeners_rcu_head), 1565 sizeof(struct listeners_rcu_head),
1578 GFP_ATOMIC); 1566 GFP_ATOMIC);
1579 if (!listeners) { 1567 if (!listeners)
1580 err = -ENOMEM; 1568 return -ENOMEM;
1581 goto out_ungrab;
1582 }
1583 old = tbl->listeners; 1569 old = tbl->listeners;
1584 memcpy(listeners, old, NLGRPSZ(tbl->groups)); 1570 memcpy(listeners, old, NLGRPSZ(tbl->groups));
1585 rcu_assign_pointer(tbl->listeners, listeners); 1571 rcu_assign_pointer(tbl->listeners, listeners);
@@ -1597,11 +1583,42 @@ int netlink_change_ngroups(struct sock *sk, unsigned int groups)
1597 } 1583 }
1598 tbl->groups = groups; 1584 tbl->groups = groups;
1599 1585
1600 out_ungrab: 1586 return 0;
1587}
1588
1589/**
1590 * netlink_change_ngroups - change number of multicast groups
1591 *
1592 * This changes the number of multicast groups that are available
1593 * on a certain netlink family. Note that it is not possible to
1594 * change the number of groups to below 32. Also note that it does
1595 * not implicitly call netlink_clear_multicast_users() when the
1596 * number of groups is reduced.
1597 *
1598 * @sk: The kernel netlink socket, as returned by netlink_kernel_create().
1599 * @groups: The new number of groups.
1600 */
1601int netlink_change_ngroups(struct sock *sk, unsigned int groups)
1602{
1603 int err;
1604
1605 netlink_table_grab();
1606 err = __netlink_change_ngroups(sk, groups);
1601 netlink_table_ungrab(); 1607 netlink_table_ungrab();
1608
1602 return err; 1609 return err;
1603} 1610}
1604 1611
1612void __netlink_clear_multicast_users(struct sock *ksk, unsigned int group)
1613{
1614 struct sock *sk;
1615 struct hlist_node *node;
1616 struct netlink_table *tbl = &nl_table[ksk->sk_protocol];
1617
1618 sk_for_each_bound(sk, node, &tbl->mc_list)
1619 netlink_update_socket_mc(nlk_sk(sk), group, 0);
1620}
1621
1605/** 1622/**
1606 * netlink_clear_multicast_users - kick off multicast listeners 1623 * netlink_clear_multicast_users - kick off multicast listeners
1607 * 1624 *
@@ -1612,15 +1629,8 @@ int netlink_change_ngroups(struct sock *sk, unsigned int groups)
1612 */ 1629 */
1613void netlink_clear_multicast_users(struct sock *ksk, unsigned int group) 1630void netlink_clear_multicast_users(struct sock *ksk, unsigned int group)
1614{ 1631{
1615 struct sock *sk;
1616 struct hlist_node *node;
1617 struct netlink_table *tbl = &nl_table[ksk->sk_protocol];
1618
1619 netlink_table_grab(); 1632 netlink_table_grab();
1620 1633 __netlink_clear_multicast_users(ksk, group);
1621 sk_for_each_bound(sk, node, &tbl->mc_list)
1622 netlink_update_socket_mc(nlk_sk(sk), group, 0);
1623
1624 netlink_table_ungrab(); 1634 netlink_table_ungrab();
1625} 1635}
1626 1636
@@ -1778,7 +1788,7 @@ void netlink_ack(struct sk_buff *in_skb, struct nlmsghdr *nlh, int err)
1778 } 1788 }
1779 1789
1780 rep = __nlmsg_put(skb, NETLINK_CB(in_skb).pid, nlh->nlmsg_seq, 1790 rep = __nlmsg_put(skb, NETLINK_CB(in_skb).pid, nlh->nlmsg_seq,
1781 NLMSG_ERROR, sizeof(struct nlmsgerr), 0); 1791 NLMSG_ERROR, payload, 0);
1782 errmsg = nlmsg_data(rep); 1792 errmsg = nlmsg_data(rep);
1783 errmsg->error = err; 1793 errmsg->error = err;
1784 memcpy(&errmsg->msg, nlh, err ? nlh->nlmsg_len : sizeof(*nlh)); 1794 memcpy(&errmsg->msg, nlh, err ? nlh->nlmsg_len : sizeof(*nlh));
@@ -2084,10 +2094,10 @@ static int __init netlink_proto_init(void)
2084 if (!nl_table) 2094 if (!nl_table)
2085 goto panic; 2095 goto panic;
2086 2096
2087 if (num_physpages >= (128 * 1024)) 2097 if (totalram_pages >= (128 * 1024))
2088 limit = num_physpages >> (21 - PAGE_SHIFT); 2098 limit = totalram_pages >> (21 - PAGE_SHIFT);
2089 else 2099 else
2090 limit = num_physpages >> (23 - PAGE_SHIFT); 2100 limit = totalram_pages >> (23 - PAGE_SHIFT);
2091 2101
2092 order = get_bitmask_order(limit) - 1 + PAGE_SHIFT; 2102 order = get_bitmask_order(limit) - 1 + PAGE_SHIFT;
2093 limit = (1UL << order) / sizeof(struct hlist_head); 2103 limit = (1UL << order) / sizeof(struct hlist_head);
diff --git a/net/netlink/genetlink.c b/net/netlink/genetlink.c
index 66f6ba0bab11..44ff3f3810fa 100644
--- a/net/netlink/genetlink.c
+++ b/net/netlink/genetlink.c
@@ -176,9 +176,10 @@ int genl_register_mc_group(struct genl_family *family,
176 if (family->netnsok) { 176 if (family->netnsok) {
177 struct net *net; 177 struct net *net;
178 178
179 netlink_table_grab();
179 rcu_read_lock(); 180 rcu_read_lock();
180 for_each_net_rcu(net) { 181 for_each_net_rcu(net) {
181 err = netlink_change_ngroups(net->genl_sock, 182 err = __netlink_change_ngroups(net->genl_sock,
182 mc_groups_longs * BITS_PER_LONG); 183 mc_groups_longs * BITS_PER_LONG);
183 if (err) { 184 if (err) {
184 /* 185 /*
@@ -188,10 +189,12 @@ int genl_register_mc_group(struct genl_family *family,
188 * increased on some sockets which is ok. 189 * increased on some sockets which is ok.
189 */ 190 */
190 rcu_read_unlock(); 191 rcu_read_unlock();
192 netlink_table_ungrab();
191 goto out; 193 goto out;
192 } 194 }
193 } 195 }
194 rcu_read_unlock(); 196 rcu_read_unlock();
197 netlink_table_ungrab();
195 } else { 198 } else {
196 err = netlink_change_ngroups(init_net.genl_sock, 199 err = netlink_change_ngroups(init_net.genl_sock,
197 mc_groups_longs * BITS_PER_LONG); 200 mc_groups_longs * BITS_PER_LONG);
@@ -217,10 +220,12 @@ static void __genl_unregister_mc_group(struct genl_family *family,
217 struct net *net; 220 struct net *net;
218 BUG_ON(grp->family != family); 221 BUG_ON(grp->family != family);
219 222
223 netlink_table_grab();
220 rcu_read_lock(); 224 rcu_read_lock();
221 for_each_net_rcu(net) 225 for_each_net_rcu(net)
222 netlink_clear_multicast_users(net->genl_sock, grp->id); 226 __netlink_clear_multicast_users(net->genl_sock, grp->id);
223 rcu_read_unlock(); 227 rcu_read_unlock();
228 netlink_table_ungrab();
224 229
225 clear_bit(grp->id, mc_groups); 230 clear_bit(grp->id, mc_groups);
226 list_del(&grp->list); 231 list_del(&grp->list);
diff --git a/net/netrom/af_netrom.c b/net/netrom/af_netrom.c
index ce1a34b99c23..7a834952f67f 100644
--- a/net/netrom/af_netrom.c
+++ b/net/netrom/af_netrom.c
@@ -301,7 +301,7 @@ void nr_destroy_socket(struct sock *sk)
301 */ 301 */
302 302
303static int nr_setsockopt(struct socket *sock, int level, int optname, 303static int nr_setsockopt(struct socket *sock, int level, int optname,
304 char __user *optval, int optlen) 304 char __user *optval, unsigned int optlen)
305{ 305{
306 struct sock *sk = sock->sk; 306 struct sock *sk = sock->sk;
307 struct nr_sock *nr = nr_sk(sk); 307 struct nr_sock *nr = nr_sk(sk);
diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
index d3d52c66cdc2..d7ecca0a0c07 100644
--- a/net/packet/af_packet.c
+++ b/net/packet/af_packet.c
@@ -1701,7 +1701,7 @@ static void packet_flush_mclist(struct sock *sk)
1701} 1701}
1702 1702
1703static int 1703static int
1704packet_setsockopt(struct socket *sock, int level, int optname, char __user *optval, int optlen) 1704packet_setsockopt(struct socket *sock, int level, int optname, char __user *optval, unsigned int optlen)
1705{ 1705{
1706 struct sock *sk = sock->sk; 1706 struct sock *sk = sock->sk;
1707 struct packet_sock *po = pkt_sk(sk); 1707 struct packet_sock *po = pkt_sk(sk);
@@ -2084,7 +2084,7 @@ static void packet_mm_close(struct vm_area_struct *vma)
2084 atomic_dec(&pkt_sk(sk)->mapped); 2084 atomic_dec(&pkt_sk(sk)->mapped);
2085} 2085}
2086 2086
2087static struct vm_operations_struct packet_mmap_ops = { 2087static const struct vm_operations_struct packet_mmap_ops = {
2088 .open = packet_mm_open, 2088 .open = packet_mm_open,
2089 .close = packet_mm_close, 2089 .close = packet_mm_close,
2090}; 2090};
diff --git a/net/phonet/af_phonet.c b/net/phonet/af_phonet.c
index a662e62a99cf..f60c0c2aacba 100644
--- a/net/phonet/af_phonet.c
+++ b/net/phonet/af_phonet.c
@@ -168,6 +168,12 @@ static int pn_send(struct sk_buff *skb, struct net_device *dev,
168 goto drop; 168 goto drop;
169 } 169 }
170 170
171 /* Broadcast sending is not implemented */
172 if (pn_addr(dst) == PNADDR_BROADCAST) {
173 err = -EOPNOTSUPP;
174 goto drop;
175 }
176
171 skb_reset_transport_header(skb); 177 skb_reset_transport_header(skb);
172 WARN_ON(skb_headroom(skb) & 1); /* HW assumes word alignment */ 178 WARN_ON(skb_headroom(skb) & 1); /* HW assumes word alignment */
173 skb_push(skb, sizeof(struct phonethdr)); 179 skb_push(skb, sizeof(struct phonethdr));
diff --git a/net/phonet/pep.c b/net/phonet/pep.c
index b8252d289cd7..5f32d217535b 100644
--- a/net/phonet/pep.c
+++ b/net/phonet/pep.c
@@ -742,7 +742,7 @@ static int pep_init(struct sock *sk)
742} 742}
743 743
744static int pep_setsockopt(struct sock *sk, int level, int optname, 744static int pep_setsockopt(struct sock *sk, int level, int optname,
745 char __user *optval, int optlen) 745 char __user *optval, unsigned int optlen)
746{ 746{
747 struct pep_sock *pn = pep_sk(sk); 747 struct pep_sock *pn = pep_sk(sk);
748 int val = 0, err = 0; 748 int val = 0, err = 0;
diff --git a/net/phonet/pn_dev.c b/net/phonet/pn_dev.c
index 2f65dcaed2fb..5f42f30dd168 100644
--- a/net/phonet/pn_dev.c
+++ b/net/phonet/pn_dev.c
@@ -209,7 +209,14 @@ static int phonet_device_autoconf(struct net_device *dev)
209 SIOCPNGAUTOCONF); 209 SIOCPNGAUTOCONF);
210 if (ret < 0) 210 if (ret < 0)
211 return ret; 211 return ret;
212 return phonet_address_add(dev, req.ifr_phonet_autoconf.device); 212
213 ASSERT_RTNL();
214 ret = phonet_address_add(dev, req.ifr_phonet_autoconf.device);
215 if (ret)
216 return ret;
217 phonet_address_notify(RTM_NEWADDR, dev,
218 req.ifr_phonet_autoconf.device);
219 return 0;
213} 220}
214 221
215/* notify Phonet of device events */ 222/* notify Phonet of device events */
diff --git a/net/phonet/socket.c b/net/phonet/socket.c
index 7a4ee397d2f7..aa5b5a972bff 100644
--- a/net/phonet/socket.c
+++ b/net/phonet/socket.c
@@ -113,6 +113,8 @@ void pn_sock_unhash(struct sock *sk)
113} 113}
114EXPORT_SYMBOL(pn_sock_unhash); 114EXPORT_SYMBOL(pn_sock_unhash);
115 115
116static DEFINE_MUTEX(port_mutex);
117
116static int pn_socket_bind(struct socket *sock, struct sockaddr *addr, int len) 118static int pn_socket_bind(struct socket *sock, struct sockaddr *addr, int len)
117{ 119{
118 struct sock *sk = sock->sk; 120 struct sock *sk = sock->sk;
@@ -140,9 +142,11 @@ static int pn_socket_bind(struct socket *sock, struct sockaddr *addr, int len)
140 err = -EINVAL; /* attempt to rebind */ 142 err = -EINVAL; /* attempt to rebind */
141 goto out; 143 goto out;
142 } 144 }
145 WARN_ON(sk_hashed(sk));
146 mutex_lock(&port_mutex);
143 err = sk->sk_prot->get_port(sk, pn_port(handle)); 147 err = sk->sk_prot->get_port(sk, pn_port(handle));
144 if (err) 148 if (err)
145 goto out; 149 goto out_port;
146 150
147 /* get_port() sets the port, bind() sets the address if applicable */ 151 /* get_port() sets the port, bind() sets the address if applicable */
148 pn->sobject = pn_object(saddr, pn_port(pn->sobject)); 152 pn->sobject = pn_object(saddr, pn_port(pn->sobject));
@@ -150,6 +154,8 @@ static int pn_socket_bind(struct socket *sock, struct sockaddr *addr, int len)
150 154
151 /* Enable RX on the socket */ 155 /* Enable RX on the socket */
152 sk->sk_prot->hash(sk); 156 sk->sk_prot->hash(sk);
157out_port:
158 mutex_unlock(&port_mutex);
153out: 159out:
154 release_sock(sk); 160 release_sock(sk);
155 return err; 161 return err;
@@ -357,8 +363,6 @@ const struct proto_ops phonet_stream_ops = {
357}; 363};
358EXPORT_SYMBOL(phonet_stream_ops); 364EXPORT_SYMBOL(phonet_stream_ops);
359 365
360static DEFINE_MUTEX(port_mutex);
361
362/* allocate port for a socket */ 366/* allocate port for a socket */
363int pn_sock_get_port(struct sock *sk, unsigned short sport) 367int pn_sock_get_port(struct sock *sk, unsigned short sport)
364{ 368{
@@ -370,9 +374,7 @@ int pn_sock_get_port(struct sock *sk, unsigned short sport)
370 374
371 memset(&try_sa, 0, sizeof(struct sockaddr_pn)); 375 memset(&try_sa, 0, sizeof(struct sockaddr_pn));
372 try_sa.spn_family = AF_PHONET; 376 try_sa.spn_family = AF_PHONET;
373 377 WARN_ON(!mutex_is_locked(&port_mutex));
374 mutex_lock(&port_mutex);
375
376 if (!sport) { 378 if (!sport) {
377 /* search free port */ 379 /* search free port */
378 int port, pmin, pmax; 380 int port, pmin, pmax;
@@ -401,13 +403,10 @@ int pn_sock_get_port(struct sock *sk, unsigned short sport)
401 else 403 else
402 sock_put(tmpsk); 404 sock_put(tmpsk);
403 } 405 }
404 mutex_unlock(&port_mutex);
405
406 /* the port must be in use already */ 406 /* the port must be in use already */
407 return -EADDRINUSE; 407 return -EADDRINUSE;
408 408
409found: 409found:
410 mutex_unlock(&port_mutex);
411 pn->sobject = pn_object(pn_addr(pn->sobject), sport); 410 pn->sobject = pn_object(pn_addr(pn->sobject), sport);
412 return 0; 411 return 0;
413} 412}
diff --git a/net/phonet/sysctl.c b/net/phonet/sysctl.c
index 7b5749ee2765..2220f3322326 100644
--- a/net/phonet/sysctl.c
+++ b/net/phonet/sysctl.c
@@ -56,7 +56,7 @@ void phonet_get_local_port_range(int *min, int *max)
56 } while (read_seqretry(&local_port_range_lock, seq)); 56 } while (read_seqretry(&local_port_range_lock, seq));
57} 57}
58 58
59static int proc_local_port_range(ctl_table *table, int write, struct file *filp, 59static int proc_local_port_range(ctl_table *table, int write,
60 void __user *buffer, 60 void __user *buffer,
61 size_t *lenp, loff_t *ppos) 61 size_t *lenp, loff_t *ppos)
62{ 62{
@@ -70,7 +70,7 @@ static int proc_local_port_range(ctl_table *table, int write, struct file *filp,
70 .extra2 = &local_port_range_max, 70 .extra2 = &local_port_range_max,
71 }; 71 };
72 72
73 ret = proc_dointvec_minmax(&tmp, write, filp, buffer, lenp, ppos); 73 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
74 74
75 if (write && ret == 0) { 75 if (write && ret == 0) {
76 if (range[1] < range[0]) 76 if (range[1] < range[0])
diff --git a/net/rds/af_rds.c b/net/rds/af_rds.c
index 108ed2e671c5..98e05382fd3c 100644
--- a/net/rds/af_rds.c
+++ b/net/rds/af_rds.c
@@ -248,7 +248,7 @@ static int rds_cong_monitor(struct rds_sock *rs, char __user *optval,
248} 248}
249 249
250static int rds_setsockopt(struct socket *sock, int level, int optname, 250static int rds_setsockopt(struct socket *sock, int level, int optname,
251 char __user *optval, int optlen) 251 char __user *optval, unsigned int optlen)
252{ 252{
253 struct rds_sock *rs = rds_sk_to_rs(sock->sk); 253 struct rds_sock *rs = rds_sk_to_rs(sock->sk);
254 int ret; 254 int ret;
@@ -359,7 +359,7 @@ static struct proto rds_proto = {
359 .obj_size = sizeof(struct rds_sock), 359 .obj_size = sizeof(struct rds_sock),
360}; 360};
361 361
362static struct proto_ops rds_proto_ops = { 362static const struct proto_ops rds_proto_ops = {
363 .family = AF_RDS, 363 .family = AF_RDS,
364 .owner = THIS_MODULE, 364 .owner = THIS_MODULE,
365 .release = rds_release, 365 .release = rds_release,
diff --git a/net/rfkill/core.c b/net/rfkill/core.c
index dbeaf2983822..ba2efb960c60 100644
--- a/net/rfkill/core.c
+++ b/net/rfkill/core.c
@@ -27,6 +27,7 @@
27#include <linux/list.h> 27#include <linux/list.h>
28#include <linux/mutex.h> 28#include <linux/mutex.h>
29#include <linux/rfkill.h> 29#include <linux/rfkill.h>
30#include <linux/sched.h>
30#include <linux/spinlock.h> 31#include <linux/spinlock.h>
31#include <linux/miscdevice.h> 32#include <linux/miscdevice.h>
32#include <linux/wait.h> 33#include <linux/wait.h>
diff --git a/net/rose/af_rose.c b/net/rose/af_rose.c
index e5f478ca3d61..502cce76621d 100644
--- a/net/rose/af_rose.c
+++ b/net/rose/af_rose.c
@@ -63,7 +63,7 @@ int sysctl_rose_window_size = ROSE_DEFAULT_WINDOW_SIZE;
63static HLIST_HEAD(rose_list); 63static HLIST_HEAD(rose_list);
64static DEFINE_SPINLOCK(rose_list_lock); 64static DEFINE_SPINLOCK(rose_list_lock);
65 65
66static struct proto_ops rose_proto_ops; 66static const struct proto_ops rose_proto_ops;
67 67
68ax25_address rose_callsign; 68ax25_address rose_callsign;
69 69
@@ -370,7 +370,7 @@ void rose_destroy_socket(struct sock *sk)
370 */ 370 */
371 371
372static int rose_setsockopt(struct socket *sock, int level, int optname, 372static int rose_setsockopt(struct socket *sock, int level, int optname,
373 char __user *optval, int optlen) 373 char __user *optval, unsigned int optlen)
374{ 374{
375 struct sock *sk = sock->sk; 375 struct sock *sk = sock->sk;
376 struct rose_sock *rose = rose_sk(sk); 376 struct rose_sock *rose = rose_sk(sk);
@@ -1515,7 +1515,7 @@ static struct net_proto_family rose_family_ops = {
1515 .owner = THIS_MODULE, 1515 .owner = THIS_MODULE,
1516}; 1516};
1517 1517
1518static struct proto_ops rose_proto_ops = { 1518static const struct proto_ops rose_proto_ops = {
1519 .family = PF_ROSE, 1519 .family = PF_ROSE,
1520 .owner = THIS_MODULE, 1520 .owner = THIS_MODULE,
1521 .release = rose_release, 1521 .release = rose_release,
diff --git a/net/rxrpc/af_rxrpc.c b/net/rxrpc/af_rxrpc.c
index bfe493ebf27c..a86afceaa94f 100644
--- a/net/rxrpc/af_rxrpc.c
+++ b/net/rxrpc/af_rxrpc.c
@@ -507,7 +507,7 @@ out:
507 * set RxRPC socket options 507 * set RxRPC socket options
508 */ 508 */
509static int rxrpc_setsockopt(struct socket *sock, int level, int optname, 509static int rxrpc_setsockopt(struct socket *sock, int level, int optname,
510 char __user *optval, int optlen) 510 char __user *optval, unsigned int optlen)
511{ 511{
512 struct rxrpc_sock *rx = rxrpc_sk(sock->sk); 512 struct rxrpc_sock *rx = rxrpc_sk(sock->sk);
513 unsigned min_sec_level; 513 unsigned min_sec_level;
diff --git a/net/rxrpc/ar-ack.c b/net/rxrpc/ar-ack.c
index c9f1f0a3a2ff..b4a220977031 100644
--- a/net/rxrpc/ar-ack.c
+++ b/net/rxrpc/ar-ack.c
@@ -40,7 +40,7 @@ static const s8 rxrpc_ack_priority[] = {
40/* 40/*
41 * propose an ACK be sent 41 * propose an ACK be sent
42 */ 42 */
43void __rxrpc_propose_ACK(struct rxrpc_call *call, uint8_t ack_reason, 43void __rxrpc_propose_ACK(struct rxrpc_call *call, u8 ack_reason,
44 __be32 serial, bool immediate) 44 __be32 serial, bool immediate)
45{ 45{
46 unsigned long expiry; 46 unsigned long expiry;
@@ -120,7 +120,7 @@ cancel_timer:
120/* 120/*
121 * propose an ACK be sent, locking the call structure 121 * propose an ACK be sent, locking the call structure
122 */ 122 */
123void rxrpc_propose_ACK(struct rxrpc_call *call, uint8_t ack_reason, 123void rxrpc_propose_ACK(struct rxrpc_call *call, u8 ack_reason,
124 __be32 serial, bool immediate) 124 __be32 serial, bool immediate)
125{ 125{
126 s8 prior = rxrpc_ack_priority[ack_reason]; 126 s8 prior = rxrpc_ack_priority[ack_reason];
@@ -520,7 +520,7 @@ static void rxrpc_zap_tx_window(struct rxrpc_call *call)
520 struct rxrpc_skb_priv *sp; 520 struct rxrpc_skb_priv *sp;
521 struct sk_buff *skb; 521 struct sk_buff *skb;
522 unsigned long _skb, *acks_window; 522 unsigned long _skb, *acks_window;
523 uint8_t winsz = call->acks_winsz; 523 u8 winsz = call->acks_winsz;
524 int tail; 524 int tail;
525 525
526 acks_window = call->acks_window; 526 acks_window = call->acks_window;
diff --git a/net/rxrpc/ar-call.c b/net/rxrpc/ar-call.c
index d9231245a79a..bc0019f704fe 100644
--- a/net/rxrpc/ar-call.c
+++ b/net/rxrpc/ar-call.c
@@ -96,7 +96,7 @@ static struct rxrpc_call *rxrpc_alloc_call(gfp_t gfp)
96} 96}
97 97
98/* 98/*
99 * allocate a new client call and attempt to to get a connection slot for it 99 * allocate a new client call and attempt to get a connection slot for it
100 */ 100 */
101static struct rxrpc_call *rxrpc_alloc_client_call( 101static struct rxrpc_call *rxrpc_alloc_client_call(
102 struct rxrpc_sock *rx, 102 struct rxrpc_sock *rx,
diff --git a/net/rxrpc/ar-internal.h b/net/rxrpc/ar-internal.h
index 3e7318c1343c..7043b294bb67 100644
--- a/net/rxrpc/ar-internal.h
+++ b/net/rxrpc/ar-internal.h
@@ -229,7 +229,7 @@ struct rxrpc_conn_bundle {
229 int debug_id; /* debug ID for printks */ 229 int debug_id; /* debug ID for printks */
230 unsigned short num_conns; /* number of connections in this bundle */ 230 unsigned short num_conns; /* number of connections in this bundle */
231 __be16 service_id; /* service ID */ 231 __be16 service_id; /* service ID */
232 uint8_t security_ix; /* security type */ 232 u8 security_ix; /* security type */
233}; 233};
234 234
235/* 235/*
@@ -370,10 +370,10 @@ struct rxrpc_call {
370 u8 channel; /* connection channel occupied by this call */ 370 u8 channel; /* connection channel occupied by this call */
371 371
372 /* transmission-phase ACK management */ 372 /* transmission-phase ACK management */
373 uint8_t acks_head; /* offset into window of first entry */ 373 u8 acks_head; /* offset into window of first entry */
374 uint8_t acks_tail; /* offset into window of last entry */ 374 u8 acks_tail; /* offset into window of last entry */
375 uint8_t acks_winsz; /* size of un-ACK'd window */ 375 u8 acks_winsz; /* size of un-ACK'd window */
376 uint8_t acks_unacked; /* lowest unacked packet in last ACK received */ 376 u8 acks_unacked; /* lowest unacked packet in last ACK received */
377 int acks_latest; /* serial number of latest ACK received */ 377 int acks_latest; /* serial number of latest ACK received */
378 rxrpc_seq_t acks_hard; /* highest definitively ACK'd msg seq */ 378 rxrpc_seq_t acks_hard; /* highest definitively ACK'd msg seq */
379 unsigned long *acks_window; /* sent packet window 379 unsigned long *acks_window; /* sent packet window
@@ -388,7 +388,7 @@ struct rxrpc_call {
388 rxrpc_seq_t rx_first_oos; /* first packet in rx_oos_queue (or 0) */ 388 rxrpc_seq_t rx_first_oos; /* first packet in rx_oos_queue (or 0) */
389 rxrpc_seq_t ackr_win_top; /* top of ACK window (rx_data_eaten is bottom) */ 389 rxrpc_seq_t ackr_win_top; /* top of ACK window (rx_data_eaten is bottom) */
390 rxrpc_seq_net_t ackr_prev_seq; /* previous sequence number received */ 390 rxrpc_seq_net_t ackr_prev_seq; /* previous sequence number received */
391 uint8_t ackr_reason; /* reason to ACK */ 391 u8 ackr_reason; /* reason to ACK */
392 __be32 ackr_serial; /* serial of packet being ACK'd */ 392 __be32 ackr_serial; /* serial of packet being ACK'd */
393 atomic_t ackr_not_idle; /* number of packets in Rx queue */ 393 atomic_t ackr_not_idle; /* number of packets in Rx queue */
394 394
@@ -402,22 +402,6 @@ struct rxrpc_call {
402}; 402};
403 403
404/* 404/*
405 * RxRPC key for Kerberos (type-2 security)
406 */
407struct rxkad_key {
408 u16 security_index; /* RxRPC header security index */
409 u16 ticket_len; /* length of ticket[] */
410 u32 expiry; /* time at which expires */
411 u32 kvno; /* key version number */
412 u8 session_key[8]; /* DES session key */
413 u8 ticket[0]; /* the encrypted ticket */
414};
415
416struct rxrpc_key_payload {
417 struct rxkad_key k;
418};
419
420/*
421 * locally abort an RxRPC call 405 * locally abort an RxRPC call
422 */ 406 */
423static inline void rxrpc_abort_call(struct rxrpc_call *call, u32 abort_code) 407static inline void rxrpc_abort_call(struct rxrpc_call *call, u32 abort_code)
@@ -450,8 +434,8 @@ extern int rxrpc_reject_call(struct rxrpc_sock *);
450/* 434/*
451 * ar-ack.c 435 * ar-ack.c
452 */ 436 */
453extern void __rxrpc_propose_ACK(struct rxrpc_call *, uint8_t, __be32, bool); 437extern void __rxrpc_propose_ACK(struct rxrpc_call *, u8, __be32, bool);
454extern void rxrpc_propose_ACK(struct rxrpc_call *, uint8_t, __be32, bool); 438extern void rxrpc_propose_ACK(struct rxrpc_call *, u8, __be32, bool);
455extern void rxrpc_process_call(struct work_struct *); 439extern void rxrpc_process_call(struct work_struct *);
456 440
457/* 441/*
diff --git a/net/rxrpc/ar-key.c b/net/rxrpc/ar-key.c
index ad8c7a782da1..74697b200496 100644
--- a/net/rxrpc/ar-key.c
+++ b/net/rxrpc/ar-key.c
@@ -17,6 +17,7 @@
17#include <linux/skbuff.h> 17#include <linux/skbuff.h>
18#include <linux/key-type.h> 18#include <linux/key-type.h>
19#include <linux/crypto.h> 19#include <linux/crypto.h>
20#include <linux/ctype.h>
20#include <net/sock.h> 21#include <net/sock.h>
21#include <net/af_rxrpc.h> 22#include <net/af_rxrpc.h>
22#include <keys/rxrpc-type.h> 23#include <keys/rxrpc-type.h>
@@ -28,6 +29,7 @@ static int rxrpc_instantiate_s(struct key *, const void *, size_t);
28static void rxrpc_destroy(struct key *); 29static void rxrpc_destroy(struct key *);
29static void rxrpc_destroy_s(struct key *); 30static void rxrpc_destroy_s(struct key *);
30static void rxrpc_describe(const struct key *, struct seq_file *); 31static void rxrpc_describe(const struct key *, struct seq_file *);
32static long rxrpc_read(const struct key *, char __user *, size_t);
31 33
32/* 34/*
33 * rxrpc defined keys take an arbitrary string as the description and an 35 * rxrpc defined keys take an arbitrary string as the description and an
@@ -39,6 +41,7 @@ struct key_type key_type_rxrpc = {
39 .match = user_match, 41 .match = user_match,
40 .destroy = rxrpc_destroy, 42 .destroy = rxrpc_destroy,
41 .describe = rxrpc_describe, 43 .describe = rxrpc_describe,
44 .read = rxrpc_read,
42}; 45};
43EXPORT_SYMBOL(key_type_rxrpc); 46EXPORT_SYMBOL(key_type_rxrpc);
44 47
@@ -55,6 +58,595 @@ struct key_type key_type_rxrpc_s = {
55}; 58};
56 59
57/* 60/*
61 * parse an RxKAD type XDR format token
62 * - the caller guarantees we have at least 4 words
63 */
64static int rxrpc_instantiate_xdr_rxkad(struct key *key, const __be32 *xdr,
65 unsigned toklen)
66{
67 struct rxrpc_key_token *token, **pptoken;
68 size_t plen;
69 u32 tktlen;
70 int ret;
71
72 _enter(",{%x,%x,%x,%x},%u",
73 ntohl(xdr[0]), ntohl(xdr[1]), ntohl(xdr[2]), ntohl(xdr[3]),
74 toklen);
75
76 if (toklen <= 8 * 4)
77 return -EKEYREJECTED;
78 tktlen = ntohl(xdr[7]);
79 _debug("tktlen: %x", tktlen);
80 if (tktlen > AFSTOKEN_RK_TIX_MAX)
81 return -EKEYREJECTED;
82 if (8 * 4 + tktlen != toklen)
83 return -EKEYREJECTED;
84
85 plen = sizeof(*token) + sizeof(*token->kad) + tktlen;
86 ret = key_payload_reserve(key, key->datalen + plen);
87 if (ret < 0)
88 return ret;
89
90 plen -= sizeof(*token);
91 token = kmalloc(sizeof(*token), GFP_KERNEL);
92 if (!token)
93 return -ENOMEM;
94
95 token->kad = kmalloc(plen, GFP_KERNEL);
96 if (!token->kad) {
97 kfree(token);
98 return -ENOMEM;
99 }
100
101 token->security_index = RXRPC_SECURITY_RXKAD;
102 token->kad->ticket_len = tktlen;
103 token->kad->vice_id = ntohl(xdr[0]);
104 token->kad->kvno = ntohl(xdr[1]);
105 token->kad->start = ntohl(xdr[4]);
106 token->kad->expiry = ntohl(xdr[5]);
107 token->kad->primary_flag = ntohl(xdr[6]);
108 memcpy(&token->kad->session_key, &xdr[2], 8);
109 memcpy(&token->kad->ticket, &xdr[8], tktlen);
110
111 _debug("SCIX: %u", token->security_index);
112 _debug("TLEN: %u", token->kad->ticket_len);
113 _debug("EXPY: %x", token->kad->expiry);
114 _debug("KVNO: %u", token->kad->kvno);
115 _debug("PRIM: %u", token->kad->primary_flag);
116 _debug("SKEY: %02x%02x%02x%02x%02x%02x%02x%02x",
117 token->kad->session_key[0], token->kad->session_key[1],
118 token->kad->session_key[2], token->kad->session_key[3],
119 token->kad->session_key[4], token->kad->session_key[5],
120 token->kad->session_key[6], token->kad->session_key[7]);
121 if (token->kad->ticket_len >= 8)
122 _debug("TCKT: %02x%02x%02x%02x%02x%02x%02x%02x",
123 token->kad->ticket[0], token->kad->ticket[1],
124 token->kad->ticket[2], token->kad->ticket[3],
125 token->kad->ticket[4], token->kad->ticket[5],
126 token->kad->ticket[6], token->kad->ticket[7]);
127
128 /* count the number of tokens attached */
129 key->type_data.x[0]++;
130
131 /* attach the data */
132 for (pptoken = (struct rxrpc_key_token **)&key->payload.data;
133 *pptoken;
134 pptoken = &(*pptoken)->next)
135 continue;
136 *pptoken = token;
137 if (token->kad->expiry < key->expiry)
138 key->expiry = token->kad->expiry;
139
140 _leave(" = 0");
141 return 0;
142}
143
144static void rxrpc_free_krb5_principal(struct krb5_principal *princ)
145{
146 int loop;
147
148 if (princ->name_parts) {
149 for (loop = princ->n_name_parts - 1; loop >= 0; loop--)
150 kfree(princ->name_parts[loop]);
151 kfree(princ->name_parts);
152 }
153 kfree(princ->realm);
154}
155
156static void rxrpc_free_krb5_tagged(struct krb5_tagged_data *td)
157{
158 kfree(td->data);
159}
160
161/*
162 * free up an RxK5 token
163 */
164static void rxrpc_rxk5_free(struct rxk5_key *rxk5)
165{
166 int loop;
167
168 rxrpc_free_krb5_principal(&rxk5->client);
169 rxrpc_free_krb5_principal(&rxk5->server);
170 rxrpc_free_krb5_tagged(&rxk5->session);
171
172 if (rxk5->addresses) {
173 for (loop = rxk5->n_addresses - 1; loop >= 0; loop--)
174 rxrpc_free_krb5_tagged(&rxk5->addresses[loop]);
175 kfree(rxk5->addresses);
176 }
177 if (rxk5->authdata) {
178 for (loop = rxk5->n_authdata - 1; loop >= 0; loop--)
179 rxrpc_free_krb5_tagged(&rxk5->authdata[loop]);
180 kfree(rxk5->authdata);
181 }
182
183 kfree(rxk5->ticket);
184 kfree(rxk5->ticket2);
185 kfree(rxk5);
186}
187
188/*
189 * extract a krb5 principal
190 */
191static int rxrpc_krb5_decode_principal(struct krb5_principal *princ,
192 const __be32 **_xdr,
193 unsigned *_toklen)
194{
195 const __be32 *xdr = *_xdr;
196 unsigned toklen = *_toklen, n_parts, loop, tmp;
197
198 /* there must be at least one name, and at least #names+1 length
199 * words */
200 if (toklen <= 12)
201 return -EINVAL;
202
203 _enter(",{%x,%x,%x},%u",
204 ntohl(xdr[0]), ntohl(xdr[1]), ntohl(xdr[2]), toklen);
205
206 n_parts = ntohl(*xdr++);
207 toklen -= 4;
208 if (n_parts <= 0 || n_parts > AFSTOKEN_K5_COMPONENTS_MAX)
209 return -EINVAL;
210 princ->n_name_parts = n_parts;
211
212 if (toklen <= (n_parts + 1) * 4)
213 return -EINVAL;
214
215 princ->name_parts = kcalloc(sizeof(char *), n_parts, GFP_KERNEL);
216 if (!princ->name_parts)
217 return -ENOMEM;
218
219 for (loop = 0; loop < n_parts; loop++) {
220 if (toklen < 4)
221 return -EINVAL;
222 tmp = ntohl(*xdr++);
223 toklen -= 4;
224 if (tmp <= 0 || tmp > AFSTOKEN_STRING_MAX)
225 return -EINVAL;
226 if (tmp > toklen)
227 return -EINVAL;
228 princ->name_parts[loop] = kmalloc(tmp + 1, GFP_KERNEL);
229 if (!princ->name_parts[loop])
230 return -ENOMEM;
231 memcpy(princ->name_parts[loop], xdr, tmp);
232 princ->name_parts[loop][tmp] = 0;
233 tmp = (tmp + 3) & ~3;
234 toklen -= tmp;
235 xdr += tmp >> 2;
236 }
237
238 if (toklen < 4)
239 return -EINVAL;
240 tmp = ntohl(*xdr++);
241 toklen -= 4;
242 if (tmp <= 0 || tmp > AFSTOKEN_K5_REALM_MAX)
243 return -EINVAL;
244 if (tmp > toklen)
245 return -EINVAL;
246 princ->realm = kmalloc(tmp + 1, GFP_KERNEL);
247 if (!princ->realm)
248 return -ENOMEM;
249 memcpy(princ->realm, xdr, tmp);
250 princ->realm[tmp] = 0;
251 tmp = (tmp + 3) & ~3;
252 toklen -= tmp;
253 xdr += tmp >> 2;
254
255 _debug("%s/...@%s", princ->name_parts[0], princ->realm);
256
257 *_xdr = xdr;
258 *_toklen = toklen;
259 _leave(" = 0 [toklen=%u]", toklen);
260 return 0;
261}
262
263/*
264 * extract a piece of krb5 tagged data
265 */
266static int rxrpc_krb5_decode_tagged_data(struct krb5_tagged_data *td,
267 size_t max_data_size,
268 const __be32 **_xdr,
269 unsigned *_toklen)
270{
271 const __be32 *xdr = *_xdr;
272 unsigned toklen = *_toklen, len;
273
274 /* there must be at least one tag and one length word */
275 if (toklen <= 8)
276 return -EINVAL;
277
278 _enter(",%zu,{%x,%x},%u",
279 max_data_size, ntohl(xdr[0]), ntohl(xdr[1]), toklen);
280
281 td->tag = ntohl(*xdr++);
282 len = ntohl(*xdr++);
283 toklen -= 8;
284 if (len > max_data_size)
285 return -EINVAL;
286 td->data_len = len;
287
288 if (len > 0) {
289 td->data = kmalloc(len, GFP_KERNEL);
290 if (!td->data)
291 return -ENOMEM;
292 memcpy(td->data, xdr, len);
293 len = (len + 3) & ~3;
294 toklen -= len;
295 xdr += len >> 2;
296 }
297
298 _debug("tag %x len %x", td->tag, td->data_len);
299
300 *_xdr = xdr;
301 *_toklen = toklen;
302 _leave(" = 0 [toklen=%u]", toklen);
303 return 0;
304}
305
306/*
307 * extract an array of tagged data
308 */
309static int rxrpc_krb5_decode_tagged_array(struct krb5_tagged_data **_td,
310 u8 *_n_elem,
311 u8 max_n_elem,
312 size_t max_elem_size,
313 const __be32 **_xdr,
314 unsigned *_toklen)
315{
316 struct krb5_tagged_data *td;
317 const __be32 *xdr = *_xdr;
318 unsigned toklen = *_toklen, n_elem, loop;
319 int ret;
320
321 /* there must be at least one count */
322 if (toklen < 4)
323 return -EINVAL;
324
325 _enter(",,%u,%zu,{%x},%u",
326 max_n_elem, max_elem_size, ntohl(xdr[0]), toklen);
327
328 n_elem = ntohl(*xdr++);
329 toklen -= 4;
330 if (n_elem < 0 || n_elem > max_n_elem)
331 return -EINVAL;
332 *_n_elem = n_elem;
333 if (n_elem > 0) {
334 if (toklen <= (n_elem + 1) * 4)
335 return -EINVAL;
336
337 _debug("n_elem %d", n_elem);
338
339 td = kcalloc(sizeof(struct krb5_tagged_data), n_elem,
340 GFP_KERNEL);
341 if (!td)
342 return -ENOMEM;
343 *_td = td;
344
345 for (loop = 0; loop < n_elem; loop++) {
346 ret = rxrpc_krb5_decode_tagged_data(&td[loop],
347 max_elem_size,
348 &xdr, &toklen);
349 if (ret < 0)
350 return ret;
351 }
352 }
353
354 *_xdr = xdr;
355 *_toklen = toklen;
356 _leave(" = 0 [toklen=%u]", toklen);
357 return 0;
358}
359
360/*
361 * extract a krb5 ticket
362 */
363static int rxrpc_krb5_decode_ticket(u8 **_ticket, u16 *_tktlen,
364 const __be32 **_xdr, unsigned *_toklen)
365{
366 const __be32 *xdr = *_xdr;
367 unsigned toklen = *_toklen, len;
368
369 /* there must be at least one length word */
370 if (toklen <= 4)
371 return -EINVAL;
372
373 _enter(",{%x},%u", ntohl(xdr[0]), toklen);
374
375 len = ntohl(*xdr++);
376 toklen -= 4;
377 if (len > AFSTOKEN_K5_TIX_MAX)
378 return -EINVAL;
379 *_tktlen = len;
380
381 _debug("ticket len %u", len);
382
383 if (len > 0) {
384 *_ticket = kmalloc(len, GFP_KERNEL);
385 if (!*_ticket)
386 return -ENOMEM;
387 memcpy(*_ticket, xdr, len);
388 len = (len + 3) & ~3;
389 toklen -= len;
390 xdr += len >> 2;
391 }
392
393 *_xdr = xdr;
394 *_toklen = toklen;
395 _leave(" = 0 [toklen=%u]", toklen);
396 return 0;
397}
398
399/*
400 * parse an RxK5 type XDR format token
401 * - the caller guarantees we have at least 4 words
402 */
403static int rxrpc_instantiate_xdr_rxk5(struct key *key, const __be32 *xdr,
404 unsigned toklen)
405{
406 struct rxrpc_key_token *token, **pptoken;
407 struct rxk5_key *rxk5;
408 const __be32 *end_xdr = xdr + (toklen >> 2);
409 int ret;
410
411 _enter(",{%x,%x,%x,%x},%u",
412 ntohl(xdr[0]), ntohl(xdr[1]), ntohl(xdr[2]), ntohl(xdr[3]),
413 toklen);
414
415 /* reserve some payload space for this subkey - the length of the token
416 * is a reasonable approximation */
417 ret = key_payload_reserve(key, key->datalen + toklen);
418 if (ret < 0)
419 return ret;
420
421 token = kzalloc(sizeof(*token), GFP_KERNEL);
422 if (!token)
423 return -ENOMEM;
424
425 rxk5 = kzalloc(sizeof(*rxk5), GFP_KERNEL);
426 if (!rxk5) {
427 kfree(token);
428 return -ENOMEM;
429 }
430
431 token->security_index = RXRPC_SECURITY_RXK5;
432 token->k5 = rxk5;
433
434 /* extract the principals */
435 ret = rxrpc_krb5_decode_principal(&rxk5->client, &xdr, &toklen);
436 if (ret < 0)
437 goto error;
438 ret = rxrpc_krb5_decode_principal(&rxk5->server, &xdr, &toklen);
439 if (ret < 0)
440 goto error;
441
442 /* extract the session key and the encoding type (the tag field ->
443 * ENCTYPE_xxx) */
444 ret = rxrpc_krb5_decode_tagged_data(&rxk5->session, AFSTOKEN_DATA_MAX,
445 &xdr, &toklen);
446 if (ret < 0)
447 goto error;
448
449 if (toklen < 4 * 8 + 2 * 4)
450 goto inval;
451 rxk5->authtime = be64_to_cpup((const __be64 *) xdr);
452 xdr += 2;
453 rxk5->starttime = be64_to_cpup((const __be64 *) xdr);
454 xdr += 2;
455 rxk5->endtime = be64_to_cpup((const __be64 *) xdr);
456 xdr += 2;
457 rxk5->renew_till = be64_to_cpup((const __be64 *) xdr);
458 xdr += 2;
459 rxk5->is_skey = ntohl(*xdr++);
460 rxk5->flags = ntohl(*xdr++);
461 toklen -= 4 * 8 + 2 * 4;
462
463 _debug("times: a=%llx s=%llx e=%llx rt=%llx",
464 rxk5->authtime, rxk5->starttime, rxk5->endtime,
465 rxk5->renew_till);
466 _debug("is_skey=%x flags=%x", rxk5->is_skey, rxk5->flags);
467
468 /* extract the permitted client addresses */
469 ret = rxrpc_krb5_decode_tagged_array(&rxk5->addresses,
470 &rxk5->n_addresses,
471 AFSTOKEN_K5_ADDRESSES_MAX,
472 AFSTOKEN_DATA_MAX,
473 &xdr, &toklen);
474 if (ret < 0)
475 goto error;
476
477 ASSERTCMP((end_xdr - xdr) << 2, ==, toklen);
478
479 /* extract the tickets */
480 ret = rxrpc_krb5_decode_ticket(&rxk5->ticket, &rxk5->ticket_len,
481 &xdr, &toklen);
482 if (ret < 0)
483 goto error;
484 ret = rxrpc_krb5_decode_ticket(&rxk5->ticket2, &rxk5->ticket2_len,
485 &xdr, &toklen);
486 if (ret < 0)
487 goto error;
488
489 ASSERTCMP((end_xdr - xdr) << 2, ==, toklen);
490
491 /* extract the typed auth data */
492 ret = rxrpc_krb5_decode_tagged_array(&rxk5->authdata,
493 &rxk5->n_authdata,
494 AFSTOKEN_K5_AUTHDATA_MAX,
495 AFSTOKEN_BDATALN_MAX,
496 &xdr, &toklen);
497 if (ret < 0)
498 goto error;
499
500 ASSERTCMP((end_xdr - xdr) << 2, ==, toklen);
501
502 if (toklen != 0)
503 goto inval;
504
505 /* attach the payload to the key */
506 for (pptoken = (struct rxrpc_key_token **)&key->payload.data;
507 *pptoken;
508 pptoken = &(*pptoken)->next)
509 continue;
510 *pptoken = token;
511 if (token->kad->expiry < key->expiry)
512 key->expiry = token->kad->expiry;
513
514 _leave(" = 0");
515 return 0;
516
517inval:
518 ret = -EINVAL;
519error:
520 rxrpc_rxk5_free(rxk5);
521 kfree(token);
522 _leave(" = %d", ret);
523 return ret;
524}
525
526/*
527 * attempt to parse the data as the XDR format
528 * - the caller guarantees we have more than 7 words
529 */
530static int rxrpc_instantiate_xdr(struct key *key, const void *data, size_t datalen)
531{
532 const __be32 *xdr = data, *token;
533 const char *cp;
534 unsigned len, tmp, loop, ntoken, toklen, sec_ix;
535 int ret;
536
537 _enter(",{%x,%x,%x,%x},%zu",
538 ntohl(xdr[0]), ntohl(xdr[1]), ntohl(xdr[2]), ntohl(xdr[3]),
539 datalen);
540
541 if (datalen > AFSTOKEN_LENGTH_MAX)
542 goto not_xdr;
543
544 /* XDR is an array of __be32's */
545 if (datalen & 3)
546 goto not_xdr;
547
548 /* the flags should be 0 (the setpag bit must be handled by
549 * userspace) */
550 if (ntohl(*xdr++) != 0)
551 goto not_xdr;
552 datalen -= 4;
553
554 /* check the cell name */
555 len = ntohl(*xdr++);
556 if (len < 1 || len > AFSTOKEN_CELL_MAX)
557 goto not_xdr;
558 datalen -= 4;
559 tmp = (len + 3) & ~3;
560 if (tmp > datalen)
561 goto not_xdr;
562
563 cp = (const char *) xdr;
564 for (loop = 0; loop < len; loop++)
565 if (!isprint(cp[loop]))
566 goto not_xdr;
567 if (len < tmp)
568 for (; loop < tmp; loop++)
569 if (cp[loop])
570 goto not_xdr;
571 _debug("cellname: [%u/%u] '%*.*s'",
572 len, tmp, len, len, (const char *) xdr);
573 datalen -= tmp;
574 xdr += tmp >> 2;
575
576 /* get the token count */
577 if (datalen < 12)
578 goto not_xdr;
579 ntoken = ntohl(*xdr++);
580 datalen -= 4;
581 _debug("ntoken: %x", ntoken);
582 if (ntoken < 1 || ntoken > AFSTOKEN_MAX)
583 goto not_xdr;
584
585 /* check each token wrapper */
586 token = xdr;
587 loop = ntoken;
588 do {
589 if (datalen < 8)
590 goto not_xdr;
591 toklen = ntohl(*xdr++);
592 sec_ix = ntohl(*xdr);
593 datalen -= 4;
594 _debug("token: [%x/%zx] %x", toklen, datalen, sec_ix);
595 if (toklen < 20 || toklen > datalen)
596 goto not_xdr;
597 datalen -= (toklen + 3) & ~3;
598 xdr += (toklen + 3) >> 2;
599
600 } while (--loop > 0);
601
602 _debug("remainder: %zu", datalen);
603 if (datalen != 0)
604 goto not_xdr;
605
606 /* okay: we're going to assume it's valid XDR format
607 * - we ignore the cellname, relying on the key to be correctly named
608 */
609 do {
610 xdr = token;
611 toklen = ntohl(*xdr++);
612 token = xdr + ((toklen + 3) >> 2);
613 sec_ix = ntohl(*xdr++);
614 toklen -= 4;
615
616 _debug("TOKEN type=%u [%p-%p]", sec_ix, xdr, token);
617
618 switch (sec_ix) {
619 case RXRPC_SECURITY_RXKAD:
620 ret = rxrpc_instantiate_xdr_rxkad(key, xdr, toklen);
621 if (ret != 0)
622 goto error;
623 break;
624
625 case RXRPC_SECURITY_RXK5:
626 ret = rxrpc_instantiate_xdr_rxk5(key, xdr, toklen);
627 if (ret != 0)
628 goto error;
629 break;
630
631 default:
632 ret = -EPROTONOSUPPORT;
633 goto error;
634 }
635
636 } while (--ntoken > 0);
637
638 _leave(" = 0");
639 return 0;
640
641not_xdr:
642 _leave(" = -EPROTO");
643 return -EPROTO;
644error:
645 _leave(" = %d", ret);
646 return ret;
647}
648
649/*
58 * instantiate an rxrpc defined key 650 * instantiate an rxrpc defined key
59 * data should be of the form: 651 * data should be of the form:
60 * OFFSET LEN CONTENT 652 * OFFSET LEN CONTENT
@@ -70,8 +662,8 @@ struct key_type key_type_rxrpc_s = {
70 */ 662 */
71static int rxrpc_instantiate(struct key *key, const void *data, size_t datalen) 663static int rxrpc_instantiate(struct key *key, const void *data, size_t datalen)
72{ 664{
73 const struct rxkad_key *tsec; 665 const struct rxrpc_key_data_v1 *v1;
74 struct rxrpc_key_payload *upayload; 666 struct rxrpc_key_token *token, **pp;
75 size_t plen; 667 size_t plen;
76 u32 kver; 668 u32 kver;
77 int ret; 669 int ret;
@@ -82,6 +674,13 @@ static int rxrpc_instantiate(struct key *key, const void *data, size_t datalen)
82 if (!data && datalen == 0) 674 if (!data && datalen == 0)
83 return 0; 675 return 0;
84 676
677 /* determine if the XDR payload format is being used */
678 if (datalen > 7 * 4) {
679 ret = rxrpc_instantiate_xdr(key, data, datalen);
680 if (ret != -EPROTO)
681 return ret;
682 }
683
85 /* get the key interface version number */ 684 /* get the key interface version number */
86 ret = -EINVAL; 685 ret = -EINVAL;
87 if (datalen <= 4 || !data) 686 if (datalen <= 4 || !data)
@@ -98,53 +697,67 @@ static int rxrpc_instantiate(struct key *key, const void *data, size_t datalen)
98 697
99 /* deal with a version 1 key */ 698 /* deal with a version 1 key */
100 ret = -EINVAL; 699 ret = -EINVAL;
101 if (datalen < sizeof(*tsec)) 700 if (datalen < sizeof(*v1))
102 goto error; 701 goto error;
103 702
104 tsec = data; 703 v1 = data;
105 if (datalen != sizeof(*tsec) + tsec->ticket_len) 704 if (datalen != sizeof(*v1) + v1->ticket_length)
106 goto error; 705 goto error;
107 706
108 _debug("SCIX: %u", tsec->security_index); 707 _debug("SCIX: %u", v1->security_index);
109 _debug("TLEN: %u", tsec->ticket_len); 708 _debug("TLEN: %u", v1->ticket_length);
110 _debug("EXPY: %x", tsec->expiry); 709 _debug("EXPY: %x", v1->expiry);
111 _debug("KVNO: %u", tsec->kvno); 710 _debug("KVNO: %u", v1->kvno);
112 _debug("SKEY: %02x%02x%02x%02x%02x%02x%02x%02x", 711 _debug("SKEY: %02x%02x%02x%02x%02x%02x%02x%02x",
113 tsec->session_key[0], tsec->session_key[1], 712 v1->session_key[0], v1->session_key[1],
114 tsec->session_key[2], tsec->session_key[3], 713 v1->session_key[2], v1->session_key[3],
115 tsec->session_key[4], tsec->session_key[5], 714 v1->session_key[4], v1->session_key[5],
116 tsec->session_key[6], tsec->session_key[7]); 715 v1->session_key[6], v1->session_key[7]);
117 if (tsec->ticket_len >= 8) 716 if (v1->ticket_length >= 8)
118 _debug("TCKT: %02x%02x%02x%02x%02x%02x%02x%02x", 717 _debug("TCKT: %02x%02x%02x%02x%02x%02x%02x%02x",
119 tsec->ticket[0], tsec->ticket[1], 718 v1->ticket[0], v1->ticket[1],
120 tsec->ticket[2], tsec->ticket[3], 719 v1->ticket[2], v1->ticket[3],
121 tsec->ticket[4], tsec->ticket[5], 720 v1->ticket[4], v1->ticket[5],
122 tsec->ticket[6], tsec->ticket[7]); 721 v1->ticket[6], v1->ticket[7]);
123 722
124 ret = -EPROTONOSUPPORT; 723 ret = -EPROTONOSUPPORT;
125 if (tsec->security_index != 2) 724 if (v1->security_index != RXRPC_SECURITY_RXKAD)
126 goto error; 725 goto error;
127 726
128 key->type_data.x[0] = tsec->security_index; 727 plen = sizeof(*token->kad) + v1->ticket_length;
129 728 ret = key_payload_reserve(key, plen + sizeof(*token));
130 plen = sizeof(*upayload) + tsec->ticket_len;
131 ret = key_payload_reserve(key, plen);
132 if (ret < 0) 729 if (ret < 0)
133 goto error; 730 goto error;
134 731
135 ret = -ENOMEM; 732 ret = -ENOMEM;
136 upayload = kmalloc(plen, GFP_KERNEL); 733 token = kmalloc(sizeof(*token), GFP_KERNEL);
137 if (!upayload) 734 if (!token)
138 goto error; 735 goto error;
736 token->kad = kmalloc(plen, GFP_KERNEL);
737 if (!token->kad)
738 goto error_free;
739
740 token->security_index = RXRPC_SECURITY_RXKAD;
741 token->kad->ticket_len = v1->ticket_length;
742 token->kad->expiry = v1->expiry;
743 token->kad->kvno = v1->kvno;
744 memcpy(&token->kad->session_key, &v1->session_key, 8);
745 memcpy(&token->kad->ticket, v1->ticket, v1->ticket_length);
139 746
140 /* attach the data */ 747 /* attach the data */
141 memcpy(&upayload->k, tsec, sizeof(*tsec)); 748 key->type_data.x[0]++;
142 memcpy(&upayload->k.ticket, (void *)tsec + sizeof(*tsec), 749
143 tsec->ticket_len); 750 pp = (struct rxrpc_key_token **)&key->payload.data;
144 key->payload.data = upayload; 751 while (*pp)
145 key->expiry = tsec->expiry; 752 pp = &(*pp)->next;
753 *pp = token;
754 if (token->kad->expiry < key->expiry)
755 key->expiry = token->kad->expiry;
756 token = NULL;
146 ret = 0; 757 ret = 0;
147 758
759error_free:
760 kfree(token);
148error: 761error:
149 return ret; 762 return ret;
150} 763}
@@ -184,7 +797,26 @@ static int rxrpc_instantiate_s(struct key *key, const void *data,
184 */ 797 */
185static void rxrpc_destroy(struct key *key) 798static void rxrpc_destroy(struct key *key)
186{ 799{
187 kfree(key->payload.data); 800 struct rxrpc_key_token *token;
801
802 while ((token = key->payload.data)) {
803 key->payload.data = token->next;
804 switch (token->security_index) {
805 case RXRPC_SECURITY_RXKAD:
806 kfree(token->kad);
807 break;
808 case RXRPC_SECURITY_RXK5:
809 if (token->k5)
810 rxrpc_rxk5_free(token->k5);
811 break;
812 default:
813 printk(KERN_ERR "Unknown token type %x on rxrpc key\n",
814 token->security_index);
815 BUG();
816 }
817
818 kfree(token);
819 }
188} 820}
189 821
190/* 822/*
@@ -293,7 +925,7 @@ int rxrpc_get_server_data_key(struct rxrpc_connection *conn,
293 925
294 struct { 926 struct {
295 u32 kver; 927 u32 kver;
296 struct rxkad_key tsec; 928 struct rxrpc_key_data_v1 v1;
297 } data; 929 } data;
298 930
299 _enter(""); 931 _enter("");
@@ -308,13 +940,12 @@ int rxrpc_get_server_data_key(struct rxrpc_connection *conn,
308 _debug("key %d", key_serial(key)); 940 _debug("key %d", key_serial(key));
309 941
310 data.kver = 1; 942 data.kver = 1;
311 data.tsec.security_index = 2; 943 data.v1.security_index = RXRPC_SECURITY_RXKAD;
312 data.tsec.ticket_len = 0; 944 data.v1.ticket_length = 0;
313 data.tsec.expiry = expiry; 945 data.v1.expiry = expiry;
314 data.tsec.kvno = 0; 946 data.v1.kvno = 0;
315 947
316 memcpy(&data.tsec.session_key, session_key, 948 memcpy(&data.v1.session_key, session_key, sizeof(data.v1.session_key));
317 sizeof(data.tsec.session_key));
318 949
319 ret = key_instantiate_and_link(key, &data, sizeof(data), NULL, NULL); 950 ret = key_instantiate_and_link(key, &data, sizeof(data), NULL, NULL);
320 if (ret < 0) 951 if (ret < 0)
@@ -360,3 +991,210 @@ struct key *rxrpc_get_null_key(const char *keyname)
360 return key; 991 return key;
361} 992}
362EXPORT_SYMBOL(rxrpc_get_null_key); 993EXPORT_SYMBOL(rxrpc_get_null_key);
994
995/*
996 * read the contents of an rxrpc key
997 * - this returns the result in XDR form
998 */
999static long rxrpc_read(const struct key *key,
1000 char __user *buffer, size_t buflen)
1001{
1002 const struct rxrpc_key_token *token;
1003 const struct krb5_principal *princ;
1004 size_t size;
1005 __be32 __user *xdr, *oldxdr;
1006 u32 cnlen, toksize, ntoks, tok, zero;
1007 u16 toksizes[AFSTOKEN_MAX];
1008 int loop;
1009
1010 _enter("");
1011
1012 /* we don't know what form we should return non-AFS keys in */
1013 if (memcmp(key->description, "afs@", 4) != 0)
1014 return -EOPNOTSUPP;
1015 cnlen = strlen(key->description + 4);
1016
1017#define RND(X) (((X) + 3) & ~3)
1018
1019 /* AFS keys we return in XDR form, so we need to work out the size of
1020 * the XDR */
1021 size = 2 * 4; /* flags, cellname len */
1022 size += RND(cnlen); /* cellname */
1023 size += 1 * 4; /* token count */
1024
1025 ntoks = 0;
1026 for (token = key->payload.data; token; token = token->next) {
1027 toksize = 4; /* sec index */
1028
1029 switch (token->security_index) {
1030 case RXRPC_SECURITY_RXKAD:
1031 toksize += 8 * 4; /* viceid, kvno, key*2, begin,
1032 * end, primary, tktlen */
1033 toksize += RND(token->kad->ticket_len);
1034 break;
1035
1036 case RXRPC_SECURITY_RXK5:
1037 princ = &token->k5->client;
1038 toksize += 4 + princ->n_name_parts * 4;
1039 for (loop = 0; loop < princ->n_name_parts; loop++)
1040 toksize += RND(strlen(princ->name_parts[loop]));
1041 toksize += 4 + RND(strlen(princ->realm));
1042
1043 princ = &token->k5->server;
1044 toksize += 4 + princ->n_name_parts * 4;
1045 for (loop = 0; loop < princ->n_name_parts; loop++)
1046 toksize += RND(strlen(princ->name_parts[loop]));
1047 toksize += 4 + RND(strlen(princ->realm));
1048
1049 toksize += 8 + RND(token->k5->session.data_len);
1050
1051 toksize += 4 * 8 + 2 * 4;
1052
1053 toksize += 4 + token->k5->n_addresses * 8;
1054 for (loop = 0; loop < token->k5->n_addresses; loop++)
1055 toksize += RND(token->k5->addresses[loop].data_len);
1056
1057 toksize += 4 + RND(token->k5->ticket_len);
1058 toksize += 4 + RND(token->k5->ticket2_len);
1059
1060 toksize += 4 + token->k5->n_authdata * 8;
1061 for (loop = 0; loop < token->k5->n_authdata; loop++)
1062 toksize += RND(token->k5->authdata[loop].data_len);
1063 break;
1064
1065 default: /* we have a ticket we can't encode */
1066 BUG();
1067 continue;
1068 }
1069
1070 _debug("token[%u]: toksize=%u", ntoks, toksize);
1071 ASSERTCMP(toksize, <=, AFSTOKEN_LENGTH_MAX);
1072
1073 toksizes[ntoks++] = toksize;
1074 size += toksize + 4; /* each token has a length word */
1075 }
1076
1077#undef RND
1078
1079 if (!buffer || buflen < size)
1080 return size;
1081
1082 xdr = (__be32 __user *) buffer;
1083 zero = 0;
1084#define ENCODE(x) \
1085 do { \
1086 __be32 y = htonl(x); \
1087 if (put_user(y, xdr++) < 0) \
1088 goto fault; \
1089 } while(0)
1090#define ENCODE_DATA(l, s) \
1091 do { \
1092 u32 _l = (l); \
1093 ENCODE(l); \
1094 if (copy_to_user(xdr, (s), _l) != 0) \
1095 goto fault; \
1096 if (_l & 3 && \
1097 copy_to_user((u8 *)xdr + _l, &zero, 4 - (_l & 3)) != 0) \
1098 goto fault; \
1099 xdr += (_l + 3) >> 2; \
1100 } while(0)
1101#define ENCODE64(x) \
1102 do { \
1103 __be64 y = cpu_to_be64(x); \
1104 if (copy_to_user(xdr, &y, 8) != 0) \
1105 goto fault; \
1106 xdr += 8 >> 2; \
1107 } while(0)
1108#define ENCODE_STR(s) \
1109 do { \
1110 const char *_s = (s); \
1111 ENCODE_DATA(strlen(_s), _s); \
1112 } while(0)
1113
1114 ENCODE(0); /* flags */
1115 ENCODE_DATA(cnlen, key->description + 4); /* cellname */
1116 ENCODE(ntoks);
1117
1118 tok = 0;
1119 for (token = key->payload.data; token; token = token->next) {
1120 toksize = toksizes[tok++];
1121 ENCODE(toksize);
1122 oldxdr = xdr;
1123 ENCODE(token->security_index);
1124
1125 switch (token->security_index) {
1126 case RXRPC_SECURITY_RXKAD:
1127 ENCODE(token->kad->vice_id);
1128 ENCODE(token->kad->kvno);
1129 ENCODE_DATA(8, token->kad->session_key);
1130 ENCODE(token->kad->start);
1131 ENCODE(token->kad->expiry);
1132 ENCODE(token->kad->primary_flag);
1133 ENCODE_DATA(token->kad->ticket_len, token->kad->ticket);
1134 break;
1135
1136 case RXRPC_SECURITY_RXK5:
1137 princ = &token->k5->client;
1138 ENCODE(princ->n_name_parts);
1139 for (loop = 0; loop < princ->n_name_parts; loop++)
1140 ENCODE_STR(princ->name_parts[loop]);
1141 ENCODE_STR(princ->realm);
1142
1143 princ = &token->k5->server;
1144 ENCODE(princ->n_name_parts);
1145 for (loop = 0; loop < princ->n_name_parts; loop++)
1146 ENCODE_STR(princ->name_parts[loop]);
1147 ENCODE_STR(princ->realm);
1148
1149 ENCODE(token->k5->session.tag);
1150 ENCODE_DATA(token->k5->session.data_len,
1151 token->k5->session.data);
1152
1153 ENCODE64(token->k5->authtime);
1154 ENCODE64(token->k5->starttime);
1155 ENCODE64(token->k5->endtime);
1156 ENCODE64(token->k5->renew_till);
1157 ENCODE(token->k5->is_skey);
1158 ENCODE(token->k5->flags);
1159
1160 ENCODE(token->k5->n_addresses);
1161 for (loop = 0; loop < token->k5->n_addresses; loop++) {
1162 ENCODE(token->k5->addresses[loop].tag);
1163 ENCODE_DATA(token->k5->addresses[loop].data_len,
1164 token->k5->addresses[loop].data);
1165 }
1166
1167 ENCODE_DATA(token->k5->ticket_len, token->k5->ticket);
1168 ENCODE_DATA(token->k5->ticket2_len, token->k5->ticket2);
1169
1170 ENCODE(token->k5->n_authdata);
1171 for (loop = 0; loop < token->k5->n_authdata; loop++) {
1172 ENCODE(token->k5->authdata[loop].tag);
1173 ENCODE_DATA(token->k5->authdata[loop].data_len,
1174 token->k5->authdata[loop].data);
1175 }
1176 break;
1177
1178 default:
1179 BUG();
1180 break;
1181 }
1182
1183 ASSERTCMP((unsigned long)xdr - (unsigned long)oldxdr, ==,
1184 toksize);
1185 }
1186
1187#undef ENCODE_STR
1188#undef ENCODE_DATA
1189#undef ENCODE64
1190#undef ENCODE
1191
1192 ASSERTCMP(tok, ==, ntoks);
1193 ASSERTCMP((char __user *) xdr - buffer, ==, size);
1194 _leave(" = %zu", size);
1195 return size;
1196
1197fault:
1198 _leave(" = -EFAULT");
1199 return -EFAULT;
1200}
diff --git a/net/rxrpc/ar-security.c b/net/rxrpc/ar-security.c
index dc62920ee19a..49b3cc31ee1f 100644
--- a/net/rxrpc/ar-security.c
+++ b/net/rxrpc/ar-security.c
@@ -16,6 +16,7 @@
16#include <linux/crypto.h> 16#include <linux/crypto.h>
17#include <net/sock.h> 17#include <net/sock.h>
18#include <net/af_rxrpc.h> 18#include <net/af_rxrpc.h>
19#include <keys/rxrpc-type.h>
19#include "ar-internal.h" 20#include "ar-internal.h"
20 21
21static LIST_HEAD(rxrpc_security_methods); 22static LIST_HEAD(rxrpc_security_methods);
@@ -122,6 +123,7 @@ EXPORT_SYMBOL_GPL(rxrpc_unregister_security);
122 */ 123 */
123int rxrpc_init_client_conn_security(struct rxrpc_connection *conn) 124int rxrpc_init_client_conn_security(struct rxrpc_connection *conn)
124{ 125{
126 struct rxrpc_key_token *token;
125 struct rxrpc_security *sec; 127 struct rxrpc_security *sec;
126 struct key *key = conn->key; 128 struct key *key = conn->key;
127 int ret; 129 int ret;
@@ -135,7 +137,11 @@ int rxrpc_init_client_conn_security(struct rxrpc_connection *conn)
135 if (ret < 0) 137 if (ret < 0)
136 return ret; 138 return ret;
137 139
138 sec = rxrpc_security_lookup(key->type_data.x[0]); 140 if (!key->payload.data)
141 return -EKEYREJECTED;
142 token = key->payload.data;
143
144 sec = rxrpc_security_lookup(token->security_index);
139 if (!sec) 145 if (!sec)
140 return -EKEYREJECTED; 146 return -EKEYREJECTED;
141 conn->security = sec; 147 conn->security = sec;
diff --git a/net/rxrpc/rxkad.c b/net/rxrpc/rxkad.c
index ef8f91030a15..713ac593e2e9 100644
--- a/net/rxrpc/rxkad.c
+++ b/net/rxrpc/rxkad.c
@@ -18,6 +18,7 @@
18#include <linux/ctype.h> 18#include <linux/ctype.h>
19#include <net/sock.h> 19#include <net/sock.h>
20#include <net/af_rxrpc.h> 20#include <net/af_rxrpc.h>
21#include <keys/rxrpc-type.h>
21#define rxrpc_debug rxkad_debug 22#define rxrpc_debug rxkad_debug
22#include "ar-internal.h" 23#include "ar-internal.h"
23 24
@@ -42,7 +43,7 @@ struct rxkad_level2_hdr {
42 __be32 checksum; /* decrypted data checksum */ 43 __be32 checksum; /* decrypted data checksum */
43}; 44};
44 45
45MODULE_DESCRIPTION("RxRPC network protocol type-2 security (Kerberos)"); 46MODULE_DESCRIPTION("RxRPC network protocol type-2 security (Kerberos 4)");
46MODULE_AUTHOR("Red Hat, Inc."); 47MODULE_AUTHOR("Red Hat, Inc.");
47MODULE_LICENSE("GPL"); 48MODULE_LICENSE("GPL");
48 49
@@ -59,14 +60,14 @@ static DEFINE_MUTEX(rxkad_ci_mutex);
59 */ 60 */
60static int rxkad_init_connection_security(struct rxrpc_connection *conn) 61static int rxkad_init_connection_security(struct rxrpc_connection *conn)
61{ 62{
62 struct rxrpc_key_payload *payload;
63 struct crypto_blkcipher *ci; 63 struct crypto_blkcipher *ci;
64 struct rxrpc_key_token *token;
64 int ret; 65 int ret;
65 66
66 _enter("{%d},{%x}", conn->debug_id, key_serial(conn->key)); 67 _enter("{%d},{%x}", conn->debug_id, key_serial(conn->key));
67 68
68 payload = conn->key->payload.data; 69 token = conn->key->payload.data;
69 conn->security_ix = payload->k.security_index; 70 conn->security_ix = token->security_index;
70 71
71 ci = crypto_alloc_blkcipher("pcbc(fcrypt)", 0, CRYPTO_ALG_ASYNC); 72 ci = crypto_alloc_blkcipher("pcbc(fcrypt)", 0, CRYPTO_ALG_ASYNC);
72 if (IS_ERR(ci)) { 73 if (IS_ERR(ci)) {
@@ -75,8 +76,8 @@ static int rxkad_init_connection_security(struct rxrpc_connection *conn)
75 goto error; 76 goto error;
76 } 77 }
77 78
78 if (crypto_blkcipher_setkey(ci, payload->k.session_key, 79 if (crypto_blkcipher_setkey(ci, token->kad->session_key,
79 sizeof(payload->k.session_key)) < 0) 80 sizeof(token->kad->session_key)) < 0)
80 BUG(); 81 BUG();
81 82
82 switch (conn->security_level) { 83 switch (conn->security_level) {
@@ -110,7 +111,7 @@ error:
110 */ 111 */
111static void rxkad_prime_packet_security(struct rxrpc_connection *conn) 112static void rxkad_prime_packet_security(struct rxrpc_connection *conn)
112{ 113{
113 struct rxrpc_key_payload *payload; 114 struct rxrpc_key_token *token;
114 struct blkcipher_desc desc; 115 struct blkcipher_desc desc;
115 struct scatterlist sg[2]; 116 struct scatterlist sg[2];
116 struct rxrpc_crypt iv; 117 struct rxrpc_crypt iv;
@@ -123,8 +124,8 @@ static void rxkad_prime_packet_security(struct rxrpc_connection *conn)
123 if (!conn->key) 124 if (!conn->key)
124 return; 125 return;
125 126
126 payload = conn->key->payload.data; 127 token = conn->key->payload.data;
127 memcpy(&iv, payload->k.session_key, sizeof(iv)); 128 memcpy(&iv, token->kad->session_key, sizeof(iv));
128 129
129 desc.tfm = conn->cipher; 130 desc.tfm = conn->cipher;
130 desc.info = iv.x; 131 desc.info = iv.x;
@@ -197,7 +198,7 @@ static int rxkad_secure_packet_encrypt(const struct rxrpc_call *call,
197 u32 data_size, 198 u32 data_size,
198 void *sechdr) 199 void *sechdr)
199{ 200{
200 const struct rxrpc_key_payload *payload; 201 const struct rxrpc_key_token *token;
201 struct rxkad_level2_hdr rxkhdr 202 struct rxkad_level2_hdr rxkhdr
202 __attribute__((aligned(8))); /* must be all on one page */ 203 __attribute__((aligned(8))); /* must be all on one page */
203 struct rxrpc_skb_priv *sp; 204 struct rxrpc_skb_priv *sp;
@@ -219,8 +220,8 @@ static int rxkad_secure_packet_encrypt(const struct rxrpc_call *call,
219 rxkhdr.checksum = 0; 220 rxkhdr.checksum = 0;
220 221
221 /* encrypt from the session key */ 222 /* encrypt from the session key */
222 payload = call->conn->key->payload.data; 223 token = call->conn->key->payload.data;
223 memcpy(&iv, payload->k.session_key, sizeof(iv)); 224 memcpy(&iv, token->kad->session_key, sizeof(iv));
224 desc.tfm = call->conn->cipher; 225 desc.tfm = call->conn->cipher;
225 desc.info = iv.x; 226 desc.info = iv.x;
226 desc.flags = 0; 227 desc.flags = 0;
@@ -400,7 +401,7 @@ static int rxkad_verify_packet_encrypt(const struct rxrpc_call *call,
400 struct sk_buff *skb, 401 struct sk_buff *skb,
401 u32 *_abort_code) 402 u32 *_abort_code)
402{ 403{
403 const struct rxrpc_key_payload *payload; 404 const struct rxrpc_key_token *token;
404 struct rxkad_level2_hdr sechdr; 405 struct rxkad_level2_hdr sechdr;
405 struct rxrpc_skb_priv *sp; 406 struct rxrpc_skb_priv *sp;
406 struct blkcipher_desc desc; 407 struct blkcipher_desc desc;
@@ -431,8 +432,8 @@ static int rxkad_verify_packet_encrypt(const struct rxrpc_call *call,
431 skb_to_sgvec(skb, sg, 0, skb->len); 432 skb_to_sgvec(skb, sg, 0, skb->len);
432 433
433 /* decrypt from the session key */ 434 /* decrypt from the session key */
434 payload = call->conn->key->payload.data; 435 token = call->conn->key->payload.data;
435 memcpy(&iv, payload->k.session_key, sizeof(iv)); 436 memcpy(&iv, token->kad->session_key, sizeof(iv));
436 desc.tfm = call->conn->cipher; 437 desc.tfm = call->conn->cipher;
437 desc.info = iv.x; 438 desc.info = iv.x;
438 desc.flags = 0; 439 desc.flags = 0;
@@ -506,7 +507,7 @@ static int rxkad_verify_packet(const struct rxrpc_call *call,
506 if (!call->conn->cipher) 507 if (!call->conn->cipher)
507 return 0; 508 return 0;
508 509
509 if (sp->hdr.securityIndex != 2) { 510 if (sp->hdr.securityIndex != RXRPC_SECURITY_RXKAD) {
510 *_abort_code = RXKADINCONSISTENCY; 511 *_abort_code = RXKADINCONSISTENCY;
511 _leave(" = -EPROTO [not rxkad]"); 512 _leave(" = -EPROTO [not rxkad]");
512 return -EPROTO; 513 return -EPROTO;
@@ -737,7 +738,7 @@ static int rxkad_respond_to_challenge(struct rxrpc_connection *conn,
737 struct sk_buff *skb, 738 struct sk_buff *skb,
738 u32 *_abort_code) 739 u32 *_abort_code)
739{ 740{
740 const struct rxrpc_key_payload *payload; 741 const struct rxrpc_key_token *token;
741 struct rxkad_challenge challenge; 742 struct rxkad_challenge challenge;
742 struct rxkad_response resp 743 struct rxkad_response resp
743 __attribute__((aligned(8))); /* must be aligned for crypto */ 744 __attribute__((aligned(8))); /* must be aligned for crypto */
@@ -778,7 +779,7 @@ static int rxkad_respond_to_challenge(struct rxrpc_connection *conn,
778 if (conn->security_level < min_level) 779 if (conn->security_level < min_level)
779 goto protocol_error; 780 goto protocol_error;
780 781
781 payload = conn->key->payload.data; 782 token = conn->key->payload.data;
782 783
783 /* build the response packet */ 784 /* build the response packet */
784 memset(&resp, 0, sizeof(resp)); 785 memset(&resp, 0, sizeof(resp));
@@ -797,13 +798,13 @@ static int rxkad_respond_to_challenge(struct rxrpc_connection *conn,
797 (conn->channels[3] ? conn->channels[3]->call_id : 0); 798 (conn->channels[3] ? conn->channels[3]->call_id : 0);
798 resp.encrypted.inc_nonce = htonl(nonce + 1); 799 resp.encrypted.inc_nonce = htonl(nonce + 1);
799 resp.encrypted.level = htonl(conn->security_level); 800 resp.encrypted.level = htonl(conn->security_level);
800 resp.kvno = htonl(payload->k.kvno); 801 resp.kvno = htonl(token->kad->kvno);
801 resp.ticket_len = htonl(payload->k.ticket_len); 802 resp.ticket_len = htonl(token->kad->ticket_len);
802 803
803 /* calculate the response checksum and then do the encryption */ 804 /* calculate the response checksum and then do the encryption */
804 rxkad_calc_response_checksum(&resp); 805 rxkad_calc_response_checksum(&resp);
805 rxkad_encrypt_response(conn, &resp, &payload->k); 806 rxkad_encrypt_response(conn, &resp, token->kad);
806 return rxkad_send_response(conn, &sp->hdr, &resp, &payload->k); 807 return rxkad_send_response(conn, &sp->hdr, &resp, token->kad);
807 808
808protocol_error: 809protocol_error:
809 *_abort_code = abort_code; 810 *_abort_code = abort_code;
@@ -1122,7 +1123,7 @@ static void rxkad_clear(struct rxrpc_connection *conn)
1122static struct rxrpc_security rxkad = { 1123static struct rxrpc_security rxkad = {
1123 .owner = THIS_MODULE, 1124 .owner = THIS_MODULE,
1124 .name = "rxkad", 1125 .name = "rxkad",
1125 .security_index = RXKAD_VERSION, 1126 .security_index = RXRPC_SECURITY_RXKAD,
1126 .init_connection_security = rxkad_init_connection_security, 1127 .init_connection_security = rxkad_init_connection_security,
1127 .prime_packet_security = rxkad_prime_packet_security, 1128 .prime_packet_security = rxkad_prime_packet_security,
1128 .secure_packet = rxkad_secure_packet, 1129 .secure_packet = rxkad_secure_packet,
diff --git a/net/sched/act_pedit.c b/net/sched/act_pedit.c
index 96c0ed115e2a..6b0359a500e6 100644
--- a/net/sched/act_pedit.c
+++ b/net/sched/act_pedit.c
@@ -34,7 +34,7 @@ static struct tcf_hashinfo pedit_hash_info = {
34}; 34};
35 35
36static const struct nla_policy pedit_policy[TCA_PEDIT_MAX + 1] = { 36static const struct nla_policy pedit_policy[TCA_PEDIT_MAX + 1] = {
37 [TCA_PEDIT_PARMS] = { .len = sizeof(struct tcf_pedit) }, 37 [TCA_PEDIT_PARMS] = { .len = sizeof(struct tc_pedit) },
38}; 38};
39 39
40static int tcf_pedit_init(struct nlattr *nla, struct nlattr *est, 40static int tcf_pedit_init(struct nlattr *nla, struct nlattr *est,
diff --git a/net/sched/cls_api.c b/net/sched/cls_api.c
index 6a536949cdc0..7cf6c0fbc7a6 100644
--- a/net/sched/cls_api.c
+++ b/net/sched/cls_api.c
@@ -350,7 +350,7 @@ static int tcf_fill_node(struct sk_buff *skb, struct tcf_proto *tp,
350 tcm = NLMSG_DATA(nlh); 350 tcm = NLMSG_DATA(nlh);
351 tcm->tcm_family = AF_UNSPEC; 351 tcm->tcm_family = AF_UNSPEC;
352 tcm->tcm__pad1 = 0; 352 tcm->tcm__pad1 = 0;
353 tcm->tcm__pad1 = 0; 353 tcm->tcm__pad2 = 0;
354 tcm->tcm_ifindex = qdisc_dev(tp->q)->ifindex; 354 tcm->tcm_ifindex = qdisc_dev(tp->q)->ifindex;
355 tcm->tcm_parent = tp->classid; 355 tcm->tcm_parent = tp->classid;
356 tcm->tcm_info = TC_H_MAKE(tp->prio, tp->protocol); 356 tcm->tcm_info = TC_H_MAKE(tp->prio, tp->protocol);
diff --git a/net/sched/sch_api.c b/net/sched/sch_api.c
index 692d9a41cd23..903e4188b6ca 100644
--- a/net/sched/sch_api.c
+++ b/net/sched/sch_api.c
@@ -693,13 +693,18 @@ static int qdisc_graft(struct net_device *dev, struct Qdisc *parent,
693 if (new && i > 0) 693 if (new && i > 0)
694 atomic_inc(&new->refcnt); 694 atomic_inc(&new->refcnt);
695 695
696 qdisc_destroy(old); 696 if (!ingress)
697 qdisc_destroy(old);
697 } 698 }
698 699
699 notify_and_destroy(skb, n, classid, dev->qdisc, new); 700 if (!ingress) {
700 if (new && !new->ops->attach) 701 notify_and_destroy(skb, n, classid, dev->qdisc, new);
701 atomic_inc(&new->refcnt); 702 if (new && !new->ops->attach)
702 dev->qdisc = new ? : &noop_qdisc; 703 atomic_inc(&new->refcnt);
704 dev->qdisc = new ? : &noop_qdisc;
705 } else {
706 notify_and_destroy(skb, n, classid, old, new);
707 }
703 708
704 if (dev->flags & IFF_UP) 709 if (dev->flags & IFF_UP)
705 dev_activate(dev); 710 dev_activate(dev);
@@ -804,7 +809,7 @@ qdisc_create(struct net_device *dev, struct netdev_queue *dev_queue,
804 stab = qdisc_get_stab(tca[TCA_STAB]); 809 stab = qdisc_get_stab(tca[TCA_STAB]);
805 if (IS_ERR(stab)) { 810 if (IS_ERR(stab)) {
806 err = PTR_ERR(stab); 811 err = PTR_ERR(stab);
807 goto err_out3; 812 goto err_out4;
808 } 813 }
809 sch->stab = stab; 814 sch->stab = stab;
810 } 815 }
@@ -833,7 +838,6 @@ qdisc_create(struct net_device *dev, struct netdev_queue *dev_queue,
833 return sch; 838 return sch;
834 } 839 }
835err_out3: 840err_out3:
836 qdisc_put_stab(sch->stab);
837 dev_put(dev); 841 dev_put(dev);
838 kfree((char *) sch - sch->padded); 842 kfree((char *) sch - sch->padded);
839err_out2: 843err_out2:
@@ -847,6 +851,7 @@ err_out4:
847 * Any broken qdiscs that would require a ops->reset() here? 851 * Any broken qdiscs that would require a ops->reset() here?
848 * The qdisc was never in action so it shouldn't be necessary. 852 * The qdisc was never in action so it shouldn't be necessary.
849 */ 853 */
854 qdisc_put_stab(sch->stab);
850 if (ops->destroy) 855 if (ops->destroy)
851 ops->destroy(sch); 856 ops->destroy(sch);
852 goto err_out3; 857 goto err_out3;
@@ -1111,12 +1116,16 @@ create_n_graft:
1111 tcm->tcm_parent, tcm->tcm_parent, 1116 tcm->tcm_parent, tcm->tcm_parent,
1112 tca, &err); 1117 tca, &err);
1113 else { 1118 else {
1114 unsigned int ntx = 0; 1119 struct netdev_queue *dev_queue;
1115 1120
1116 if (p && p->ops->cl_ops && p->ops->cl_ops->select_queue) 1121 if (p && p->ops->cl_ops && p->ops->cl_ops->select_queue)
1117 ntx = p->ops->cl_ops->select_queue(p, tcm); 1122 dev_queue = p->ops->cl_ops->select_queue(p, tcm);
1123 else if (p)
1124 dev_queue = p->dev_queue;
1125 else
1126 dev_queue = netdev_get_tx_queue(dev, 0);
1118 1127
1119 q = qdisc_create(dev, netdev_get_tx_queue(dev, ntx), p, 1128 q = qdisc_create(dev, dev_queue, p,
1120 tcm->tcm_parent, tcm->tcm_handle, 1129 tcm->tcm_parent, tcm->tcm_handle,
1121 tca, &err); 1130 tca, &err);
1122 } 1131 }
diff --git a/net/sched/sch_drr.c b/net/sched/sch_drr.c
index 12b2fb04b29b..5a888af7e5da 100644
--- a/net/sched/sch_drr.c
+++ b/net/sched/sch_drr.c
@@ -274,8 +274,10 @@ static int drr_dump_class_stats(struct Qdisc *sch, unsigned long arg,
274 struct tc_drr_stats xstats; 274 struct tc_drr_stats xstats;
275 275
276 memset(&xstats, 0, sizeof(xstats)); 276 memset(&xstats, 0, sizeof(xstats));
277 if (cl->qdisc->q.qlen) 277 if (cl->qdisc->q.qlen) {
278 xstats.deficit = cl->deficit; 278 xstats.deficit = cl->deficit;
279 cl->qdisc->qstats.qlen = cl->qdisc->q.qlen;
280 }
279 281
280 if (gnet_stats_copy_basic(d, &cl->bstats) < 0 || 282 if (gnet_stats_copy_basic(d, &cl->bstats) < 0 ||
281 gnet_stats_copy_rate_est(d, &cl->rate_est) < 0 || 283 gnet_stats_copy_rate_est(d, &cl->rate_est) < 0 ||
diff --git a/net/sched/sch_hfsc.c b/net/sched/sch_hfsc.c
index 375d64cb1a3d..2c5c76be18f8 100644
--- a/net/sched/sch_hfsc.c
+++ b/net/sched/sch_hfsc.c
@@ -77,7 +77,7 @@
77 * The service curve parameters are converted to the internal 77 * The service curve parameters are converted to the internal
78 * representation. The slope values are scaled to avoid overflow. 78 * representation. The slope values are scaled to avoid overflow.
79 * the inverse slope values as well as the y-projection of the 1st 79 * the inverse slope values as well as the y-projection of the 1st
80 * segment are kept in order to to avoid 64-bit divide operations 80 * segment are kept in order to avoid 64-bit divide operations
81 * that are expensive on 32-bit architectures. 81 * that are expensive on 32-bit architectures.
82 */ 82 */
83 83
diff --git a/net/sched/sch_mq.c b/net/sched/sch_mq.c
index dd5ee022f1f7..d1dea3d5dc92 100644
--- a/net/sched/sch_mq.c
+++ b/net/sched/sch_mq.c
@@ -125,13 +125,18 @@ static struct netdev_queue *mq_queue_get(struct Qdisc *sch, unsigned long cl)
125 return netdev_get_tx_queue(dev, ntx); 125 return netdev_get_tx_queue(dev, ntx);
126} 126}
127 127
128static unsigned int mq_select_queue(struct Qdisc *sch, struct tcmsg *tcm) 128static struct netdev_queue *mq_select_queue(struct Qdisc *sch,
129 struct tcmsg *tcm)
129{ 130{
130 unsigned int ntx = TC_H_MIN(tcm->tcm_parent); 131 unsigned int ntx = TC_H_MIN(tcm->tcm_parent);
132 struct netdev_queue *dev_queue = mq_queue_get(sch, ntx);
131 133
132 if (!mq_queue_get(sch, ntx)) 134 if (!dev_queue) {
133 return 0; 135 struct net_device *dev = qdisc_dev(sch);
134 return ntx - 1; 136
137 return netdev_get_tx_queue(dev, 0);
138 }
139 return dev_queue;
135} 140}
136 141
137static int mq_graft(struct Qdisc *sch, unsigned long cl, struct Qdisc *new, 142static int mq_graft(struct Qdisc *sch, unsigned long cl, struct Qdisc *new,
@@ -188,6 +193,7 @@ static int mq_dump_class_stats(struct Qdisc *sch, unsigned long cl,
188 struct netdev_queue *dev_queue = mq_queue_get(sch, cl); 193 struct netdev_queue *dev_queue = mq_queue_get(sch, cl);
189 194
190 sch = dev_queue->qdisc_sleeping; 195 sch = dev_queue->qdisc_sleeping;
196 sch->qstats.qlen = sch->q.qlen;
191 if (gnet_stats_copy_basic(d, &sch->bstats) < 0 || 197 if (gnet_stats_copy_basic(d, &sch->bstats) < 0 ||
192 gnet_stats_copy_queue(d, &sch->qstats) < 0) 198 gnet_stats_copy_queue(d, &sch->qstats) < 0)
193 return -1; 199 return -1;
diff --git a/net/sched/sch_multiq.c b/net/sched/sch_multiq.c
index 069f81c97277..7db2c88ce585 100644
--- a/net/sched/sch_multiq.c
+++ b/net/sched/sch_multiq.c
@@ -359,6 +359,7 @@ static int multiq_dump_class_stats(struct Qdisc *sch, unsigned long cl,
359 struct Qdisc *cl_q; 359 struct Qdisc *cl_q;
360 360
361 cl_q = q->queues[cl - 1]; 361 cl_q = q->queues[cl - 1];
362 cl_q->qstats.qlen = cl_q->q.qlen;
362 if (gnet_stats_copy_basic(d, &cl_q->bstats) < 0 || 363 if (gnet_stats_copy_basic(d, &cl_q->bstats) < 0 ||
363 gnet_stats_copy_queue(d, &cl_q->qstats) < 0) 364 gnet_stats_copy_queue(d, &cl_q->qstats) < 0)
364 return -1; 365 return -1;
diff --git a/net/sched/sch_prio.c b/net/sched/sch_prio.c
index 0f73c412d04b..93285cecb246 100644
--- a/net/sched/sch_prio.c
+++ b/net/sched/sch_prio.c
@@ -322,6 +322,7 @@ static int prio_dump_class_stats(struct Qdisc *sch, unsigned long cl,
322 struct Qdisc *cl_q; 322 struct Qdisc *cl_q;
323 323
324 cl_q = q->queues[cl - 1]; 324 cl_q = q->queues[cl - 1];
325 cl_q->qstats.qlen = cl_q->q.qlen;
325 if (gnet_stats_copy_basic(d, &cl_q->bstats) < 0 || 326 if (gnet_stats_copy_basic(d, &cl_q->bstats) < 0 ||
326 gnet_stats_copy_queue(d, &cl_q->qstats) < 0) 327 gnet_stats_copy_queue(d, &cl_q->qstats) < 0)
327 return -1; 328 return -1;
diff --git a/net/sctp/ipv6.c b/net/sctp/ipv6.c
index 6a4b19094143..bb280e60e00a 100644
--- a/net/sctp/ipv6.c
+++ b/net/sctp/ipv6.c
@@ -949,7 +949,7 @@ static int sctp6_rcv(struct sk_buff *skb)
949 return sctp_rcv(skb) ? -1 : 0; 949 return sctp_rcv(skb) ? -1 : 0;
950} 950}
951 951
952static struct inet6_protocol sctpv6_protocol = { 952static const struct inet6_protocol sctpv6_protocol = {
953 .handler = sctp6_rcv, 953 .handler = sctp6_rcv,
954 .err_handler = sctp_v6_err, 954 .err_handler = sctp_v6_err,
955 .flags = INET6_PROTO_NOPOLICY | INET6_PROTO_FINAL, 955 .flags = INET6_PROTO_NOPOLICY | INET6_PROTO_FINAL,
diff --git a/net/sctp/protocol.c b/net/sctp/protocol.c
index 60093be8385d..612dc878e05c 100644
--- a/net/sctp/protocol.c
+++ b/net/sctp/protocol.c
@@ -924,7 +924,7 @@ static struct inet_protosw sctp_stream_protosw = {
924}; 924};
925 925
926/* Register with IP layer. */ 926/* Register with IP layer. */
927static struct net_protocol sctp_protocol = { 927static const struct net_protocol sctp_protocol = {
928 .handler = sctp_rcv, 928 .handler = sctp_rcv,
929 .err_handler = sctp_v4_err, 929 .err_handler = sctp_v4_err,
930 .no_policy = 1, 930 .no_policy = 1,
@@ -1184,10 +1184,10 @@ SCTP_STATIC __init int sctp_init(void)
1184 /* Size and allocate the association hash table. 1184 /* Size and allocate the association hash table.
1185 * The methodology is similar to that of the tcp hash tables. 1185 * The methodology is similar to that of the tcp hash tables.
1186 */ 1186 */
1187 if (num_physpages >= (128 * 1024)) 1187 if (totalram_pages >= (128 * 1024))
1188 goal = num_physpages >> (22 - PAGE_SHIFT); 1188 goal = totalram_pages >> (22 - PAGE_SHIFT);
1189 else 1189 else
1190 goal = num_physpages >> (24 - PAGE_SHIFT); 1190 goal = totalram_pages >> (24 - PAGE_SHIFT);
1191 1191
1192 for (order = 0; (1UL << order) < goal; order++) 1192 for (order = 0; (1UL << order) < goal; order++)
1193 ; 1193 ;
diff --git a/net/sctp/socket.c b/net/sctp/socket.c
index 89af37a6c871..c8d05758661d 100644
--- a/net/sctp/socket.c
+++ b/net/sctp/socket.c
@@ -2027,7 +2027,8 @@ out:
2027 * instead a error will be indicated to the user. 2027 * instead a error will be indicated to the user.
2028 */ 2028 */
2029static int sctp_setsockopt_disable_fragments(struct sock *sk, 2029static int sctp_setsockopt_disable_fragments(struct sock *sk,
2030 char __user *optval, int optlen) 2030 char __user *optval,
2031 unsigned int optlen)
2031{ 2032{
2032 int val; 2033 int val;
2033 2034
@@ -2043,7 +2044,7 @@ static int sctp_setsockopt_disable_fragments(struct sock *sk,
2043} 2044}
2044 2045
2045static int sctp_setsockopt_events(struct sock *sk, char __user *optval, 2046static int sctp_setsockopt_events(struct sock *sk, char __user *optval,
2046 int optlen) 2047 unsigned int optlen)
2047{ 2048{
2048 if (optlen > sizeof(struct sctp_event_subscribe)) 2049 if (optlen > sizeof(struct sctp_event_subscribe))
2049 return -EINVAL; 2050 return -EINVAL;
@@ -2064,7 +2065,7 @@ static int sctp_setsockopt_events(struct sock *sk, char __user *optval,
2064 * association is closed. 2065 * association is closed.
2065 */ 2066 */
2066static int sctp_setsockopt_autoclose(struct sock *sk, char __user *optval, 2067static int sctp_setsockopt_autoclose(struct sock *sk, char __user *optval,
2067 int optlen) 2068 unsigned int optlen)
2068{ 2069{
2069 struct sctp_sock *sp = sctp_sk(sk); 2070 struct sctp_sock *sp = sctp_sk(sk);
2070 2071
@@ -2318,7 +2319,8 @@ static int sctp_apply_peer_addr_params(struct sctp_paddrparams *params,
2318} 2319}
2319 2320
2320static int sctp_setsockopt_peer_addr_params(struct sock *sk, 2321static int sctp_setsockopt_peer_addr_params(struct sock *sk,
2321 char __user *optval, int optlen) 2322 char __user *optval,
2323 unsigned int optlen)
2322{ 2324{
2323 struct sctp_paddrparams params; 2325 struct sctp_paddrparams params;
2324 struct sctp_transport *trans = NULL; 2326 struct sctp_transport *trans = NULL;
@@ -2430,7 +2432,7 @@ static int sctp_setsockopt_peer_addr_params(struct sock *sk,
2430 */ 2432 */
2431 2433
2432static int sctp_setsockopt_delayed_ack(struct sock *sk, 2434static int sctp_setsockopt_delayed_ack(struct sock *sk,
2433 char __user *optval, int optlen) 2435 char __user *optval, unsigned int optlen)
2434{ 2436{
2435 struct sctp_sack_info params; 2437 struct sctp_sack_info params;
2436 struct sctp_transport *trans = NULL; 2438 struct sctp_transport *trans = NULL;
@@ -2546,7 +2548,7 @@ static int sctp_setsockopt_delayed_ack(struct sock *sk,
2546 * by the change). With TCP-style sockets, this option is inherited by 2548 * by the change). With TCP-style sockets, this option is inherited by
2547 * sockets derived from a listener socket. 2549 * sockets derived from a listener socket.
2548 */ 2550 */
2549static int sctp_setsockopt_initmsg(struct sock *sk, char __user *optval, int optlen) 2551static int sctp_setsockopt_initmsg(struct sock *sk, char __user *optval, unsigned int optlen)
2550{ 2552{
2551 struct sctp_initmsg sinit; 2553 struct sctp_initmsg sinit;
2552 struct sctp_sock *sp = sctp_sk(sk); 2554 struct sctp_sock *sp = sctp_sk(sk);
@@ -2583,7 +2585,8 @@ static int sctp_setsockopt_initmsg(struct sock *sk, char __user *optval, int opt
2583 * to this call if the caller is using the UDP model. 2585 * to this call if the caller is using the UDP model.
2584 */ 2586 */
2585static int sctp_setsockopt_default_send_param(struct sock *sk, 2587static int sctp_setsockopt_default_send_param(struct sock *sk,
2586 char __user *optval, int optlen) 2588 char __user *optval,
2589 unsigned int optlen)
2587{ 2590{
2588 struct sctp_sndrcvinfo info; 2591 struct sctp_sndrcvinfo info;
2589 struct sctp_association *asoc; 2592 struct sctp_association *asoc;
@@ -2622,7 +2625,7 @@ static int sctp_setsockopt_default_send_param(struct sock *sk,
2622 * association peer's addresses. 2625 * association peer's addresses.
2623 */ 2626 */
2624static int sctp_setsockopt_primary_addr(struct sock *sk, char __user *optval, 2627static int sctp_setsockopt_primary_addr(struct sock *sk, char __user *optval,
2625 int optlen) 2628 unsigned int optlen)
2626{ 2629{
2627 struct sctp_prim prim; 2630 struct sctp_prim prim;
2628 struct sctp_transport *trans; 2631 struct sctp_transport *trans;
@@ -2651,7 +2654,7 @@ static int sctp_setsockopt_primary_addr(struct sock *sk, char __user *optval,
2651 * integer boolean flag. 2654 * integer boolean flag.
2652 */ 2655 */
2653static int sctp_setsockopt_nodelay(struct sock *sk, char __user *optval, 2656static int sctp_setsockopt_nodelay(struct sock *sk, char __user *optval,
2654 int optlen) 2657 unsigned int optlen)
2655{ 2658{
2656 int val; 2659 int val;
2657 2660
@@ -2676,7 +2679,8 @@ static int sctp_setsockopt_nodelay(struct sock *sk, char __user *optval,
2676 * be changed. 2679 * be changed.
2677 * 2680 *
2678 */ 2681 */
2679static int sctp_setsockopt_rtoinfo(struct sock *sk, char __user *optval, int optlen) { 2682static int sctp_setsockopt_rtoinfo(struct sock *sk, char __user *optval, unsigned int optlen)
2683{
2680 struct sctp_rtoinfo rtoinfo; 2684 struct sctp_rtoinfo rtoinfo;
2681 struct sctp_association *asoc; 2685 struct sctp_association *asoc;
2682 2686
@@ -2728,7 +2732,7 @@ static int sctp_setsockopt_rtoinfo(struct sock *sk, char __user *optval, int opt
2728 * See [SCTP] for more information. 2732 * See [SCTP] for more information.
2729 * 2733 *
2730 */ 2734 */
2731static int sctp_setsockopt_associnfo(struct sock *sk, char __user *optval, int optlen) 2735static int sctp_setsockopt_associnfo(struct sock *sk, char __user *optval, unsigned int optlen)
2732{ 2736{
2733 2737
2734 struct sctp_assocparams assocparams; 2738 struct sctp_assocparams assocparams;
@@ -2800,7 +2804,7 @@ static int sctp_setsockopt_associnfo(struct sock *sk, char __user *optval, int o
2800 * addresses and a user will receive both PF_INET6 and PF_INET type 2804 * addresses and a user will receive both PF_INET6 and PF_INET type
2801 * addresses on the socket. 2805 * addresses on the socket.
2802 */ 2806 */
2803static int sctp_setsockopt_mappedv4(struct sock *sk, char __user *optval, int optlen) 2807static int sctp_setsockopt_mappedv4(struct sock *sk, char __user *optval, unsigned int optlen)
2804{ 2808{
2805 int val; 2809 int val;
2806 struct sctp_sock *sp = sctp_sk(sk); 2810 struct sctp_sock *sp = sctp_sk(sk);
@@ -2844,7 +2848,7 @@ static int sctp_setsockopt_mappedv4(struct sock *sk, char __user *optval, int op
2844 * changed (effecting future associations only). 2848 * changed (effecting future associations only).
2845 * assoc_value: This parameter specifies the maximum size in bytes. 2849 * assoc_value: This parameter specifies the maximum size in bytes.
2846 */ 2850 */
2847static int sctp_setsockopt_maxseg(struct sock *sk, char __user *optval, int optlen) 2851static int sctp_setsockopt_maxseg(struct sock *sk, char __user *optval, unsigned int optlen)
2848{ 2852{
2849 struct sctp_assoc_value params; 2853 struct sctp_assoc_value params;
2850 struct sctp_association *asoc; 2854 struct sctp_association *asoc;
@@ -2899,7 +2903,7 @@ static int sctp_setsockopt_maxseg(struct sock *sk, char __user *optval, int optl
2899 * set primary request: 2903 * set primary request:
2900 */ 2904 */
2901static int sctp_setsockopt_peer_primary_addr(struct sock *sk, char __user *optval, 2905static int sctp_setsockopt_peer_primary_addr(struct sock *sk, char __user *optval,
2902 int optlen) 2906 unsigned int optlen)
2903{ 2907{
2904 struct sctp_sock *sp; 2908 struct sctp_sock *sp;
2905 struct sctp_endpoint *ep; 2909 struct sctp_endpoint *ep;
@@ -2950,7 +2954,7 @@ static int sctp_setsockopt_peer_primary_addr(struct sock *sk, char __user *optva
2950} 2954}
2951 2955
2952static int sctp_setsockopt_adaptation_layer(struct sock *sk, char __user *optval, 2956static int sctp_setsockopt_adaptation_layer(struct sock *sk, char __user *optval,
2953 int optlen) 2957 unsigned int optlen)
2954{ 2958{
2955 struct sctp_setadaptation adaptation; 2959 struct sctp_setadaptation adaptation;
2956 2960
@@ -2979,7 +2983,7 @@ static int sctp_setsockopt_adaptation_layer(struct sock *sk, char __user *optval
2979 * saved with outbound messages. 2983 * saved with outbound messages.
2980 */ 2984 */
2981static int sctp_setsockopt_context(struct sock *sk, char __user *optval, 2985static int sctp_setsockopt_context(struct sock *sk, char __user *optval,
2982 int optlen) 2986 unsigned int optlen)
2983{ 2987{
2984 struct sctp_assoc_value params; 2988 struct sctp_assoc_value params;
2985 struct sctp_sock *sp; 2989 struct sctp_sock *sp;
@@ -3030,7 +3034,7 @@ static int sctp_setsockopt_context(struct sock *sk, char __user *optval,
3030 */ 3034 */
3031static int sctp_setsockopt_fragment_interleave(struct sock *sk, 3035static int sctp_setsockopt_fragment_interleave(struct sock *sk,
3032 char __user *optval, 3036 char __user *optval,
3033 int optlen) 3037 unsigned int optlen)
3034{ 3038{
3035 int val; 3039 int val;
3036 3040
@@ -3063,7 +3067,7 @@ static int sctp_setsockopt_fragment_interleave(struct sock *sk,
3063 */ 3067 */
3064static int sctp_setsockopt_partial_delivery_point(struct sock *sk, 3068static int sctp_setsockopt_partial_delivery_point(struct sock *sk,
3065 char __user *optval, 3069 char __user *optval,
3066 int optlen) 3070 unsigned int optlen)
3067{ 3071{
3068 u32 val; 3072 u32 val;
3069 3073
@@ -3096,7 +3100,7 @@ static int sctp_setsockopt_partial_delivery_point(struct sock *sk,
3096 */ 3100 */
3097static int sctp_setsockopt_maxburst(struct sock *sk, 3101static int sctp_setsockopt_maxburst(struct sock *sk,
3098 char __user *optval, 3102 char __user *optval,
3099 int optlen) 3103 unsigned int optlen)
3100{ 3104{
3101 struct sctp_assoc_value params; 3105 struct sctp_assoc_value params;
3102 struct sctp_sock *sp; 3106 struct sctp_sock *sp;
@@ -3140,8 +3144,8 @@ static int sctp_setsockopt_maxburst(struct sock *sk,
3140 * will only effect future associations on the socket. 3144 * will only effect future associations on the socket.
3141 */ 3145 */
3142static int sctp_setsockopt_auth_chunk(struct sock *sk, 3146static int sctp_setsockopt_auth_chunk(struct sock *sk,
3143 char __user *optval, 3147 char __user *optval,
3144 int optlen) 3148 unsigned int optlen)
3145{ 3149{
3146 struct sctp_authchunk val; 3150 struct sctp_authchunk val;
3147 3151
@@ -3172,8 +3176,8 @@ static int sctp_setsockopt_auth_chunk(struct sock *sk,
3172 * endpoint requires the peer to use. 3176 * endpoint requires the peer to use.
3173 */ 3177 */
3174static int sctp_setsockopt_hmac_ident(struct sock *sk, 3178static int sctp_setsockopt_hmac_ident(struct sock *sk,
3175 char __user *optval, 3179 char __user *optval,
3176 int optlen) 3180 unsigned int optlen)
3177{ 3181{
3178 struct sctp_hmacalgo *hmacs; 3182 struct sctp_hmacalgo *hmacs;
3179 u32 idents; 3183 u32 idents;
@@ -3215,7 +3219,7 @@ out:
3215 */ 3219 */
3216static int sctp_setsockopt_auth_key(struct sock *sk, 3220static int sctp_setsockopt_auth_key(struct sock *sk,
3217 char __user *optval, 3221 char __user *optval,
3218 int optlen) 3222 unsigned int optlen)
3219{ 3223{
3220 struct sctp_authkey *authkey; 3224 struct sctp_authkey *authkey;
3221 struct sctp_association *asoc; 3225 struct sctp_association *asoc;
@@ -3260,8 +3264,8 @@ out:
3260 * the association shared key. 3264 * the association shared key.
3261 */ 3265 */
3262static int sctp_setsockopt_active_key(struct sock *sk, 3266static int sctp_setsockopt_active_key(struct sock *sk,
3263 char __user *optval, 3267 char __user *optval,
3264 int optlen) 3268 unsigned int optlen)
3265{ 3269{
3266 struct sctp_authkeyid val; 3270 struct sctp_authkeyid val;
3267 struct sctp_association *asoc; 3271 struct sctp_association *asoc;
@@ -3288,8 +3292,8 @@ static int sctp_setsockopt_active_key(struct sock *sk,
3288 * This set option will delete a shared secret key from use. 3292 * This set option will delete a shared secret key from use.
3289 */ 3293 */
3290static int sctp_setsockopt_del_key(struct sock *sk, 3294static int sctp_setsockopt_del_key(struct sock *sk,
3291 char __user *optval, 3295 char __user *optval,
3292 int optlen) 3296 unsigned int optlen)
3293{ 3297{
3294 struct sctp_authkeyid val; 3298 struct sctp_authkeyid val;
3295 struct sctp_association *asoc; 3299 struct sctp_association *asoc;
@@ -3332,7 +3336,7 @@ static int sctp_setsockopt_del_key(struct sock *sk,
3332 * optlen - the size of the buffer. 3336 * optlen - the size of the buffer.
3333 */ 3337 */
3334SCTP_STATIC int sctp_setsockopt(struct sock *sk, int level, int optname, 3338SCTP_STATIC int sctp_setsockopt(struct sock *sk, int level, int optname,
3335 char __user *optval, int optlen) 3339 char __user *optval, unsigned int optlen)
3336{ 3340{
3337 int retval = 0; 3341 int retval = 0;
3338 3342
diff --git a/net/socket.c b/net/socket.c
index 6d4716559047..75655365b5fd 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -86,6 +86,7 @@
86#include <linux/audit.h> 86#include <linux/audit.h>
87#include <linux/wireless.h> 87#include <linux/wireless.h>
88#include <linux/nsproxy.h> 88#include <linux/nsproxy.h>
89#include <linux/magic.h>
89 90
90#include <asm/uaccess.h> 91#include <asm/uaccess.h>
91#include <asm/unistd.h> 92#include <asm/unistd.h>
@@ -235,8 +236,6 @@ int move_addr_to_user(struct sockaddr *kaddr, int klen, void __user *uaddr,
235 return __put_user(klen, ulen); 236 return __put_user(klen, ulen);
236} 237}
237 238
238#define SOCKFS_MAGIC 0x534F434B
239
240static struct kmem_cache *sock_inode_cachep __read_mostly; 239static struct kmem_cache *sock_inode_cachep __read_mostly;
241 240
242static struct inode *sock_alloc_inode(struct super_block *sb) 241static struct inode *sock_alloc_inode(struct super_block *sb)
@@ -285,7 +284,7 @@ static int init_inodecache(void)
285 return 0; 284 return 0;
286} 285}
287 286
288static struct super_operations sockfs_ops = { 287static const struct super_operations sockfs_ops = {
289 .alloc_inode = sock_alloc_inode, 288 .alloc_inode = sock_alloc_inode,
290 .destroy_inode =sock_destroy_inode, 289 .destroy_inode =sock_destroy_inode,
291 .statfs = simple_statfs, 290 .statfs = simple_statfs,
@@ -489,6 +488,7 @@ static struct socket *sock_alloc(void)
489 488
490 sock = SOCKET_I(inode); 489 sock = SOCKET_I(inode);
491 490
491 kmemcheck_annotate_bitfield(sock, type);
492 inode->i_mode = S_IFSOCK | S_IRWXUGO; 492 inode->i_mode = S_IFSOCK | S_IRWXUGO;
493 inode->i_uid = current_fsuid(); 493 inode->i_uid = current_fsuid();
494 inode->i_gid = current_fsgid(); 494 inode->i_gid = current_fsgid();
@@ -2098,12 +2098,17 @@ SYSCALL_DEFINE2(socketcall, int, call, unsigned long __user *, args)
2098 unsigned long a[6]; 2098 unsigned long a[6];
2099 unsigned long a0, a1; 2099 unsigned long a0, a1;
2100 int err; 2100 int err;
2101 unsigned int len;
2101 2102
2102 if (call < 1 || call > SYS_ACCEPT4) 2103 if (call < 1 || call > SYS_ACCEPT4)
2103 return -EINVAL; 2104 return -EINVAL;
2104 2105
2106 len = nargs[call];
2107 if (len > sizeof(a))
2108 return -EINVAL;
2109
2105 /* copy_from_user should be SMP safe. */ 2110 /* copy_from_user should be SMP safe. */
2106 if (copy_from_user(a, args, nargs[call])) 2111 if (copy_from_user(a, args, len))
2107 return -EFAULT; 2112 return -EFAULT;
2108 2113
2109 audit_socketcall(nargs[call] / sizeof(unsigned long), a); 2114 audit_socketcall(nargs[call] / sizeof(unsigned long), a);
@@ -2386,7 +2391,7 @@ int kernel_getsockopt(struct socket *sock, int level, int optname,
2386} 2391}
2387 2392
2388int kernel_setsockopt(struct socket *sock, int level, int optname, 2393int kernel_setsockopt(struct socket *sock, int level, int optname,
2389 char *optval, int optlen) 2394 char *optval, unsigned int optlen)
2390{ 2395{
2391 mm_segment_t oldfs = get_fs(); 2396 mm_segment_t oldfs = get_fs();
2392 int err; 2397 int err;
diff --git a/net/sunrpc/auth.c b/net/sunrpc/auth.c
index 0c431c277af5..54a4e042f104 100644
--- a/net/sunrpc/auth.c
+++ b/net/sunrpc/auth.c
@@ -385,7 +385,7 @@ rpcauth_init_cred(struct rpc_cred *cred, const struct auth_cred *acred,
385EXPORT_SYMBOL_GPL(rpcauth_init_cred); 385EXPORT_SYMBOL_GPL(rpcauth_init_cred);
386 386
387void 387void
388rpcauth_generic_bind_cred(struct rpc_task *task, struct rpc_cred *cred) 388rpcauth_generic_bind_cred(struct rpc_task *task, struct rpc_cred *cred, int lookupflags)
389{ 389{
390 task->tk_msg.rpc_cred = get_rpccred(cred); 390 task->tk_msg.rpc_cred = get_rpccred(cred);
391 dprintk("RPC: %5u holding %s cred %p\n", task->tk_pid, 391 dprintk("RPC: %5u holding %s cred %p\n", task->tk_pid,
@@ -394,7 +394,7 @@ rpcauth_generic_bind_cred(struct rpc_task *task, struct rpc_cred *cred)
394EXPORT_SYMBOL_GPL(rpcauth_generic_bind_cred); 394EXPORT_SYMBOL_GPL(rpcauth_generic_bind_cred);
395 395
396static void 396static void
397rpcauth_bind_root_cred(struct rpc_task *task) 397rpcauth_bind_root_cred(struct rpc_task *task, int lookupflags)
398{ 398{
399 struct rpc_auth *auth = task->tk_client->cl_auth; 399 struct rpc_auth *auth = task->tk_client->cl_auth;
400 struct auth_cred acred = { 400 struct auth_cred acred = {
@@ -405,7 +405,7 @@ rpcauth_bind_root_cred(struct rpc_task *task)
405 405
406 dprintk("RPC: %5u looking up %s cred\n", 406 dprintk("RPC: %5u looking up %s cred\n",
407 task->tk_pid, task->tk_client->cl_auth->au_ops->au_name); 407 task->tk_pid, task->tk_client->cl_auth->au_ops->au_name);
408 ret = auth->au_ops->lookup_cred(auth, &acred, 0); 408 ret = auth->au_ops->lookup_cred(auth, &acred, lookupflags);
409 if (!IS_ERR(ret)) 409 if (!IS_ERR(ret))
410 task->tk_msg.rpc_cred = ret; 410 task->tk_msg.rpc_cred = ret;
411 else 411 else
@@ -413,14 +413,14 @@ rpcauth_bind_root_cred(struct rpc_task *task)
413} 413}
414 414
415static void 415static void
416rpcauth_bind_new_cred(struct rpc_task *task) 416rpcauth_bind_new_cred(struct rpc_task *task, int lookupflags)
417{ 417{
418 struct rpc_auth *auth = task->tk_client->cl_auth; 418 struct rpc_auth *auth = task->tk_client->cl_auth;
419 struct rpc_cred *ret; 419 struct rpc_cred *ret;
420 420
421 dprintk("RPC: %5u looking up %s cred\n", 421 dprintk("RPC: %5u looking up %s cred\n",
422 task->tk_pid, auth->au_ops->au_name); 422 task->tk_pid, auth->au_ops->au_name);
423 ret = rpcauth_lookupcred(auth, 0); 423 ret = rpcauth_lookupcred(auth, lookupflags);
424 if (!IS_ERR(ret)) 424 if (!IS_ERR(ret))
425 task->tk_msg.rpc_cred = ret; 425 task->tk_msg.rpc_cred = ret;
426 else 426 else
@@ -430,12 +430,16 @@ rpcauth_bind_new_cred(struct rpc_task *task)
430void 430void
431rpcauth_bindcred(struct rpc_task *task, struct rpc_cred *cred, int flags) 431rpcauth_bindcred(struct rpc_task *task, struct rpc_cred *cred, int flags)
432{ 432{
433 int lookupflags = 0;
434
435 if (flags & RPC_TASK_ASYNC)
436 lookupflags |= RPCAUTH_LOOKUP_NEW;
433 if (cred != NULL) 437 if (cred != NULL)
434 cred->cr_ops->crbind(task, cred); 438 cred->cr_ops->crbind(task, cred, lookupflags);
435 else if (flags & RPC_TASK_ROOTCREDS) 439 else if (flags & RPC_TASK_ROOTCREDS)
436 rpcauth_bind_root_cred(task); 440 rpcauth_bind_root_cred(task, lookupflags);
437 else 441 else
438 rpcauth_bind_new_cred(task); 442 rpcauth_bind_new_cred(task, lookupflags);
439} 443}
440 444
441void 445void
diff --git a/net/sunrpc/auth_generic.c b/net/sunrpc/auth_generic.c
index 4028502f0528..bf88bf8e9365 100644
--- a/net/sunrpc/auth_generic.c
+++ b/net/sunrpc/auth_generic.c
@@ -55,13 +55,13 @@ struct rpc_cred *rpc_lookup_machine_cred(void)
55EXPORT_SYMBOL_GPL(rpc_lookup_machine_cred); 55EXPORT_SYMBOL_GPL(rpc_lookup_machine_cred);
56 56
57static void 57static void
58generic_bind_cred(struct rpc_task *task, struct rpc_cred *cred) 58generic_bind_cred(struct rpc_task *task, struct rpc_cred *cred, int lookupflags)
59{ 59{
60 struct rpc_auth *auth = task->tk_client->cl_auth; 60 struct rpc_auth *auth = task->tk_client->cl_auth;
61 struct auth_cred *acred = &container_of(cred, struct generic_cred, gc_base)->acred; 61 struct auth_cred *acred = &container_of(cred, struct generic_cred, gc_base)->acred;
62 struct rpc_cred *ret; 62 struct rpc_cred *ret;
63 63
64 ret = auth->au_ops->lookup_cred(auth, acred, 0); 64 ret = auth->au_ops->lookup_cred(auth, acred, lookupflags);
65 if (!IS_ERR(ret)) 65 if (!IS_ERR(ret))
66 task->tk_msg.rpc_cred = ret; 66 task->tk_msg.rpc_cred = ret;
67 else 67 else
diff --git a/net/sunrpc/auth_gss/svcauth_gss.c b/net/sunrpc/auth_gss/svcauth_gss.c
index 2e6a148d277c..f6c51e562a02 100644
--- a/net/sunrpc/auth_gss/svcauth_gss.c
+++ b/net/sunrpc/auth_gss/svcauth_gss.c
@@ -1374,8 +1374,10 @@ svcauth_gss_release(struct svc_rqst *rqstp)
1374 if (stat) 1374 if (stat)
1375 goto out_err; 1375 goto out_err;
1376 break; 1376 break;
1377 default: 1377 /*
1378 goto out_err; 1378 * For any other gc_svc value, svcauth_gss_accept() already set
1379 * the auth_error appropriately; just fall through:
1380 */
1379 } 1381 }
1380 1382
1381out: 1383out:
diff --git a/net/sunrpc/auth_null.c b/net/sunrpc/auth_null.c
index c70dd7f5258e..1db618f56ecb 100644
--- a/net/sunrpc/auth_null.c
+++ b/net/sunrpc/auth_null.c
@@ -8,7 +8,6 @@
8 8
9#include <linux/types.h> 9#include <linux/types.h>
10#include <linux/module.h> 10#include <linux/module.h>
11#include <linux/utsname.h>
12#include <linux/sunrpc/clnt.h> 11#include <linux/sunrpc/clnt.h>
13 12
14#ifdef RPC_DEBUG 13#ifdef RPC_DEBUG
diff --git a/net/sunrpc/cache.c b/net/sunrpc/cache.c
index 45cdaff9b361..d6eee291a0e2 100644
--- a/net/sunrpc/cache.c
+++ b/net/sunrpc/cache.c
@@ -103,23 +103,21 @@ struct cache_head *sunrpc_cache_lookup(struct cache_detail *detail,
103EXPORT_SYMBOL_GPL(sunrpc_cache_lookup); 103EXPORT_SYMBOL_GPL(sunrpc_cache_lookup);
104 104
105 105
106static void queue_loose(struct cache_detail *detail, struct cache_head *ch); 106static void cache_dequeue(struct cache_detail *detail, struct cache_head *ch);
107 107
108static int cache_fresh_locked(struct cache_head *head, time_t expiry) 108static void cache_fresh_locked(struct cache_head *head, time_t expiry)
109{ 109{
110 head->expiry_time = expiry; 110 head->expiry_time = expiry;
111 head->last_refresh = get_seconds(); 111 head->last_refresh = get_seconds();
112 return !test_and_set_bit(CACHE_VALID, &head->flags); 112 set_bit(CACHE_VALID, &head->flags);
113} 113}
114 114
115static void cache_fresh_unlocked(struct cache_head *head, 115static void cache_fresh_unlocked(struct cache_head *head,
116 struct cache_detail *detail, int new) 116 struct cache_detail *detail)
117{ 117{
118 if (new)
119 cache_revisit_request(head);
120 if (test_and_clear_bit(CACHE_PENDING, &head->flags)) { 118 if (test_and_clear_bit(CACHE_PENDING, &head->flags)) {
121 cache_revisit_request(head); 119 cache_revisit_request(head);
122 queue_loose(detail, head); 120 cache_dequeue(detail, head);
123 } 121 }
124} 122}
125 123
@@ -132,7 +130,6 @@ struct cache_head *sunrpc_cache_update(struct cache_detail *detail,
132 */ 130 */
133 struct cache_head **head; 131 struct cache_head **head;
134 struct cache_head *tmp; 132 struct cache_head *tmp;
135 int is_new;
136 133
137 if (!test_bit(CACHE_VALID, &old->flags)) { 134 if (!test_bit(CACHE_VALID, &old->flags)) {
138 write_lock(&detail->hash_lock); 135 write_lock(&detail->hash_lock);
@@ -141,9 +138,9 @@ struct cache_head *sunrpc_cache_update(struct cache_detail *detail,
141 set_bit(CACHE_NEGATIVE, &old->flags); 138 set_bit(CACHE_NEGATIVE, &old->flags);
142 else 139 else
143 detail->update(old, new); 140 detail->update(old, new);
144 is_new = cache_fresh_locked(old, new->expiry_time); 141 cache_fresh_locked(old, new->expiry_time);
145 write_unlock(&detail->hash_lock); 142 write_unlock(&detail->hash_lock);
146 cache_fresh_unlocked(old, detail, is_new); 143 cache_fresh_unlocked(old, detail);
147 return old; 144 return old;
148 } 145 }
149 write_unlock(&detail->hash_lock); 146 write_unlock(&detail->hash_lock);
@@ -167,11 +164,11 @@ struct cache_head *sunrpc_cache_update(struct cache_detail *detail,
167 *head = tmp; 164 *head = tmp;
168 detail->entries++; 165 detail->entries++;
169 cache_get(tmp); 166 cache_get(tmp);
170 is_new = cache_fresh_locked(tmp, new->expiry_time); 167 cache_fresh_locked(tmp, new->expiry_time);
171 cache_fresh_locked(old, 0); 168 cache_fresh_locked(old, 0);
172 write_unlock(&detail->hash_lock); 169 write_unlock(&detail->hash_lock);
173 cache_fresh_unlocked(tmp, detail, is_new); 170 cache_fresh_unlocked(tmp, detail);
174 cache_fresh_unlocked(old, detail, 0); 171 cache_fresh_unlocked(old, detail);
175 cache_put(old, detail); 172 cache_put(old, detail);
176 return tmp; 173 return tmp;
177} 174}
@@ -184,6 +181,22 @@ static int cache_make_upcall(struct cache_detail *cd, struct cache_head *h)
184 return cd->cache_upcall(cd, h); 181 return cd->cache_upcall(cd, h);
185} 182}
186 183
184static inline int cache_is_valid(struct cache_detail *detail, struct cache_head *h)
185{
186 if (!test_bit(CACHE_VALID, &h->flags) ||
187 h->expiry_time < get_seconds())
188 return -EAGAIN;
189 else if (detail->flush_time > h->last_refresh)
190 return -EAGAIN;
191 else {
192 /* entry is valid */
193 if (test_bit(CACHE_NEGATIVE, &h->flags))
194 return -ENOENT;
195 else
196 return 0;
197 }
198}
199
187/* 200/*
188 * This is the generic cache management routine for all 201 * This is the generic cache management routine for all
189 * the authentication caches. 202 * the authentication caches.
@@ -192,8 +205,10 @@ static int cache_make_upcall(struct cache_detail *cd, struct cache_head *h)
192 * 205 *
193 * 206 *
194 * Returns 0 if the cache_head can be used, or cache_puts it and returns 207 * Returns 0 if the cache_head can be used, or cache_puts it and returns
195 * -EAGAIN if upcall is pending, 208 * -EAGAIN if upcall is pending and request has been queued
196 * -ETIMEDOUT if upcall failed and should be retried, 209 * -ETIMEDOUT if upcall failed or request could not be queue or
210 * upcall completed but item is still invalid (implying that
211 * the cache item has been replaced with a newer one).
197 * -ENOENT if cache entry was negative 212 * -ENOENT if cache entry was negative
198 */ 213 */
199int cache_check(struct cache_detail *detail, 214int cache_check(struct cache_detail *detail,
@@ -203,17 +218,7 @@ int cache_check(struct cache_detail *detail,
203 long refresh_age, age; 218 long refresh_age, age;
204 219
205 /* First decide return status as best we can */ 220 /* First decide return status as best we can */
206 if (!test_bit(CACHE_VALID, &h->flags) || 221 rv = cache_is_valid(detail, h);
207 h->expiry_time < get_seconds())
208 rv = -EAGAIN;
209 else if (detail->flush_time > h->last_refresh)
210 rv = -EAGAIN;
211 else {
212 /* entry is valid */
213 if (test_bit(CACHE_NEGATIVE, &h->flags))
214 rv = -ENOENT;
215 else rv = 0;
216 }
217 222
218 /* now see if we want to start an upcall */ 223 /* now see if we want to start an upcall */
219 refresh_age = (h->expiry_time - h->last_refresh); 224 refresh_age = (h->expiry_time - h->last_refresh);
@@ -229,10 +234,11 @@ int cache_check(struct cache_detail *detail,
229 switch (cache_make_upcall(detail, h)) { 234 switch (cache_make_upcall(detail, h)) {
230 case -EINVAL: 235 case -EINVAL:
231 clear_bit(CACHE_PENDING, &h->flags); 236 clear_bit(CACHE_PENDING, &h->flags);
237 cache_revisit_request(h);
232 if (rv == -EAGAIN) { 238 if (rv == -EAGAIN) {
233 set_bit(CACHE_NEGATIVE, &h->flags); 239 set_bit(CACHE_NEGATIVE, &h->flags);
234 cache_fresh_unlocked(h, detail, 240 cache_fresh_locked(h, get_seconds()+CACHE_NEW_EXPIRY);
235 cache_fresh_locked(h, get_seconds()+CACHE_NEW_EXPIRY)); 241 cache_fresh_unlocked(h, detail);
236 rv = -ENOENT; 242 rv = -ENOENT;
237 } 243 }
238 break; 244 break;
@@ -245,10 +251,14 @@ int cache_check(struct cache_detail *detail,
245 } 251 }
246 } 252 }
247 253
248 if (rv == -EAGAIN) 254 if (rv == -EAGAIN) {
249 if (cache_defer_req(rqstp, h) != 0) 255 if (cache_defer_req(rqstp, h) < 0) {
250 rv = -ETIMEDOUT; 256 /* Request is not deferred */
251 257 rv = cache_is_valid(detail, h);
258 if (rv == -EAGAIN)
259 rv = -ETIMEDOUT;
260 }
261 }
252 if (rv) 262 if (rv)
253 cache_put(h, detail); 263 cache_put(h, detail);
254 return rv; 264 return rv;
@@ -396,7 +406,7 @@ static int cache_clean(void)
396 ) 406 )
397 continue; 407 continue;
398 if (test_and_clear_bit(CACHE_PENDING, &ch->flags)) 408 if (test_and_clear_bit(CACHE_PENDING, &ch->flags))
399 queue_loose(current_detail, ch); 409 cache_dequeue(current_detail, ch);
400 410
401 if (atomic_read(&ch->ref.refcount) == 1) 411 if (atomic_read(&ch->ref.refcount) == 1)
402 break; 412 break;
@@ -412,8 +422,10 @@ static int cache_clean(void)
412 if (!ch) 422 if (!ch)
413 current_index ++; 423 current_index ++;
414 spin_unlock(&cache_list_lock); 424 spin_unlock(&cache_list_lock);
415 if (ch) 425 if (ch) {
426 cache_revisit_request(ch);
416 cache_put(ch, d); 427 cache_put(ch, d);
428 }
417 } else 429 } else
418 spin_unlock(&cache_list_lock); 430 spin_unlock(&cache_list_lock);
419 431
@@ -488,7 +500,7 @@ static int cache_defer_cnt;
488 500
489static int cache_defer_req(struct cache_req *req, struct cache_head *item) 501static int cache_defer_req(struct cache_req *req, struct cache_head *item)
490{ 502{
491 struct cache_deferred_req *dreq; 503 struct cache_deferred_req *dreq, *discard;
492 int hash = DFR_HASH(item); 504 int hash = DFR_HASH(item);
493 505
494 if (cache_defer_cnt >= DFR_MAX) { 506 if (cache_defer_cnt >= DFR_MAX) {
@@ -496,11 +508,11 @@ static int cache_defer_req(struct cache_req *req, struct cache_head *item)
496 * or continue and drop the oldest below 508 * or continue and drop the oldest below
497 */ 509 */
498 if (net_random()&1) 510 if (net_random()&1)
499 return -ETIMEDOUT; 511 return -ENOMEM;
500 } 512 }
501 dreq = req->defer(req); 513 dreq = req->defer(req);
502 if (dreq == NULL) 514 if (dreq == NULL)
503 return -ETIMEDOUT; 515 return -ENOMEM;
504 516
505 dreq->item = item; 517 dreq->item = item;
506 518
@@ -513,23 +525,24 @@ static int cache_defer_req(struct cache_req *req, struct cache_head *item)
513 list_add(&dreq->hash, &cache_defer_hash[hash]); 525 list_add(&dreq->hash, &cache_defer_hash[hash]);
514 526
515 /* it is in, now maybe clean up */ 527 /* it is in, now maybe clean up */
516 dreq = NULL; 528 discard = NULL;
517 if (++cache_defer_cnt > DFR_MAX) { 529 if (++cache_defer_cnt > DFR_MAX) {
518 dreq = list_entry(cache_defer_list.prev, 530 discard = list_entry(cache_defer_list.prev,
519 struct cache_deferred_req, recent); 531 struct cache_deferred_req, recent);
520 list_del(&dreq->recent); 532 list_del_init(&discard->recent);
521 list_del(&dreq->hash); 533 list_del_init(&discard->hash);
522 cache_defer_cnt--; 534 cache_defer_cnt--;
523 } 535 }
524 spin_unlock(&cache_defer_lock); 536 spin_unlock(&cache_defer_lock);
525 537
526 if (dreq) { 538 if (discard)
527 /* there was one too many */ 539 /* there was one too many */
528 dreq->revisit(dreq, 1); 540 discard->revisit(discard, 1);
529 } 541
530 if (!test_bit(CACHE_PENDING, &item->flags)) { 542 if (!test_bit(CACHE_PENDING, &item->flags)) {
531 /* must have just been validated... */ 543 /* must have just been validated... */
532 cache_revisit_request(item); 544 cache_revisit_request(item);
545 return -EAGAIN;
533 } 546 }
534 return 0; 547 return 0;
535} 548}
@@ -551,7 +564,7 @@ static void cache_revisit_request(struct cache_head *item)
551 dreq = list_entry(lp, struct cache_deferred_req, hash); 564 dreq = list_entry(lp, struct cache_deferred_req, hash);
552 lp = lp->next; 565 lp = lp->next;
553 if (dreq->item == item) { 566 if (dreq->item == item) {
554 list_del(&dreq->hash); 567 list_del_init(&dreq->hash);
555 list_move(&dreq->recent, &pending); 568 list_move(&dreq->recent, &pending);
556 cache_defer_cnt--; 569 cache_defer_cnt--;
557 } 570 }
@@ -577,7 +590,7 @@ void cache_clean_deferred(void *owner)
577 590
578 list_for_each_entry_safe(dreq, tmp, &cache_defer_list, recent) { 591 list_for_each_entry_safe(dreq, tmp, &cache_defer_list, recent) {
579 if (dreq->owner == owner) { 592 if (dreq->owner == owner) {
580 list_del(&dreq->hash); 593 list_del_init(&dreq->hash);
581 list_move(&dreq->recent, &pending); 594 list_move(&dreq->recent, &pending);
582 cache_defer_cnt--; 595 cache_defer_cnt--;
583 } 596 }
@@ -887,7 +900,7 @@ static int cache_release(struct inode *inode, struct file *filp,
887 900
888 901
889 902
890static void queue_loose(struct cache_detail *detail, struct cache_head *ch) 903static void cache_dequeue(struct cache_detail *detail, struct cache_head *ch)
891{ 904{
892 struct cache_queue *cq; 905 struct cache_queue *cq;
893 spin_lock(&queue_lock); 906 spin_lock(&queue_lock);
diff --git a/net/sunrpc/clnt.c b/net/sunrpc/clnt.c
index fac0ca93f06b..38829e20500b 100644
--- a/net/sunrpc/clnt.c
+++ b/net/sunrpc/clnt.c
@@ -288,6 +288,7 @@ struct rpc_clnt *rpc_create(struct rpc_create_args *args)
288 .srcaddr = args->saddress, 288 .srcaddr = args->saddress,
289 .dstaddr = args->address, 289 .dstaddr = args->address,
290 .addrlen = args->addrsize, 290 .addrlen = args->addrsize,
291 .bc_xprt = args->bc_xprt,
291 }; 292 };
292 char servername[48]; 293 char servername[48];
293 294
@@ -639,10 +640,11 @@ EXPORT_SYMBOL_GPL(rpc_call_async);
639/** 640/**
640 * rpc_run_bc_task - Allocate a new RPC task for backchannel use, then run 641 * rpc_run_bc_task - Allocate a new RPC task for backchannel use, then run
641 * rpc_execute against it 642 * rpc_execute against it
642 * @ops: RPC call ops 643 * @req: RPC request
644 * @tk_ops: RPC call ops
643 */ 645 */
644struct rpc_task *rpc_run_bc_task(struct rpc_rqst *req, 646struct rpc_task *rpc_run_bc_task(struct rpc_rqst *req,
645 const struct rpc_call_ops *tk_ops) 647 const struct rpc_call_ops *tk_ops)
646{ 648{
647 struct rpc_task *task; 649 struct rpc_task *task;
648 struct xdr_buf *xbufp = &req->rq_snd_buf; 650 struct xdr_buf *xbufp = &req->rq_snd_buf;
diff --git a/net/sunrpc/rpc_pipe.c b/net/sunrpc/rpc_pipe.c
index 7f676bdf70d3..49278f830367 100644
--- a/net/sunrpc/rpc_pipe.c
+++ b/net/sunrpc/rpc_pipe.c
@@ -860,7 +860,8 @@ static void rpc_clntdir_depopulate(struct dentry *dentry)
860 860
861/** 861/**
862 * rpc_create_client_dir - Create a new rpc_client directory in rpc_pipefs 862 * rpc_create_client_dir - Create a new rpc_client directory in rpc_pipefs
863 * @path: path from the rpc_pipefs root to the new directory 863 * @dentry: dentry from the rpc_pipefs root to the new directory
864 * @name: &struct qstr for the name
864 * @rpc_client: rpc client to associate with this directory 865 * @rpc_client: rpc client to associate with this directory
865 * 866 *
866 * This creates a directory at the given @path associated with 867 * This creates a directory at the given @path associated with
@@ -930,7 +931,7 @@ void rpc_remove_cache_dir(struct dentry *dentry)
930/* 931/*
931 * populate the filesystem 932 * populate the filesystem
932 */ 933 */
933static struct super_operations s_ops = { 934static const struct super_operations s_ops = {
934 .alloc_inode = rpc_alloc_inode, 935 .alloc_inode = rpc_alloc_inode,
935 .destroy_inode = rpc_destroy_inode, 936 .destroy_inode = rpc_destroy_inode,
936 .statfs = simple_statfs, 937 .statfs = simple_statfs,
diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c
index 8f459abe97cf..cef74ba0666c 100644
--- a/net/sunrpc/sched.c
+++ b/net/sunrpc/sched.c
@@ -21,6 +21,8 @@
21 21
22#include <linux/sunrpc/clnt.h> 22#include <linux/sunrpc/clnt.h>
23 23
24#include "sunrpc.h"
25
24#ifdef RPC_DEBUG 26#ifdef RPC_DEBUG
25#define RPCDBG_FACILITY RPCDBG_SCHED 27#define RPCDBG_FACILITY RPCDBG_SCHED
26#define RPC_TASK_MAGIC_ID 0xf00baa 28#define RPC_TASK_MAGIC_ID 0xf00baa
@@ -711,11 +713,6 @@ static void rpc_async_schedule(struct work_struct *work)
711 __rpc_execute(container_of(work, struct rpc_task, u.tk_work)); 713 __rpc_execute(container_of(work, struct rpc_task, u.tk_work));
712} 714}
713 715
714struct rpc_buffer {
715 size_t len;
716 char data[];
717};
718
719/** 716/**
720 * rpc_malloc - allocate an RPC buffer 717 * rpc_malloc - allocate an RPC buffer
721 * @task: RPC task that will use this buffer 718 * @task: RPC task that will use this buffer
diff --git a/net/sunrpc/sunrpc.h b/net/sunrpc/sunrpc.h
index 5d9dd742264b..90c292e2738b 100644
--- a/net/sunrpc/sunrpc.h
+++ b/net/sunrpc/sunrpc.h
@@ -27,11 +27,25 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27#ifndef _NET_SUNRPC_SUNRPC_H 27#ifndef _NET_SUNRPC_SUNRPC_H
28#define _NET_SUNRPC_SUNRPC_H 28#define _NET_SUNRPC_SUNRPC_H
29 29
30#include <linux/net.h>
31
32/*
33 * Header for dynamically allocated rpc buffers.
34 */
35struct rpc_buffer {
36 size_t len;
37 char data[];
38};
39
30static inline int rpc_reply_expected(struct rpc_task *task) 40static inline int rpc_reply_expected(struct rpc_task *task)
31{ 41{
32 return (task->tk_msg.rpc_proc != NULL) && 42 return (task->tk_msg.rpc_proc != NULL) &&
33 (task->tk_msg.rpc_proc->p_decode != NULL); 43 (task->tk_msg.rpc_proc->p_decode != NULL);
34} 44}
35 45
46int svc_send_common(struct socket *sock, struct xdr_buf *xdr,
47 struct page *headpage, unsigned long headoffset,
48 struct page *tailpage, unsigned long tailoffset);
49
36#endif /* _NET_SUNRPC_SUNRPC_H */ 50#endif /* _NET_SUNRPC_SUNRPC_H */
37 51
diff --git a/net/sunrpc/svc_xprt.c b/net/sunrpc/svc_xprt.c
index 27d44332f017..df124f78ee48 100644
--- a/net/sunrpc/svc_xprt.c
+++ b/net/sunrpc/svc_xprt.c
@@ -160,6 +160,7 @@ void svc_xprt_init(struct svc_xprt_class *xcl, struct svc_xprt *xprt,
160 mutex_init(&xprt->xpt_mutex); 160 mutex_init(&xprt->xpt_mutex);
161 spin_lock_init(&xprt->xpt_lock); 161 spin_lock_init(&xprt->xpt_lock);
162 set_bit(XPT_BUSY, &xprt->xpt_flags); 162 set_bit(XPT_BUSY, &xprt->xpt_flags);
163 rpc_init_wait_queue(&xprt->xpt_bc_pending, "xpt_bc_pending");
163} 164}
164EXPORT_SYMBOL_GPL(svc_xprt_init); 165EXPORT_SYMBOL_GPL(svc_xprt_init);
165 166
@@ -710,10 +711,7 @@ int svc_recv(struct svc_rqst *rqstp, long timeout)
710 spin_unlock_bh(&pool->sp_lock); 711 spin_unlock_bh(&pool->sp_lock);
711 712
712 len = 0; 713 len = 0;
713 if (test_bit(XPT_CLOSE, &xprt->xpt_flags)) { 714 if (test_bit(XPT_LISTENER, &xprt->xpt_flags)) {
714 dprintk("svc_recv: found XPT_CLOSE\n");
715 svc_delete_xprt(xprt);
716 } else if (test_bit(XPT_LISTENER, &xprt->xpt_flags)) {
717 struct svc_xprt *newxpt; 715 struct svc_xprt *newxpt;
718 newxpt = xprt->xpt_ops->xpo_accept(xprt); 716 newxpt = xprt->xpt_ops->xpo_accept(xprt);
719 if (newxpt) { 717 if (newxpt) {
@@ -739,7 +737,7 @@ int svc_recv(struct svc_rqst *rqstp, long timeout)
739 svc_xprt_received(newxpt); 737 svc_xprt_received(newxpt);
740 } 738 }
741 svc_xprt_received(xprt); 739 svc_xprt_received(xprt);
742 } else { 740 } else if (!test_bit(XPT_CLOSE, &xprt->xpt_flags)) {
743 dprintk("svc: server %p, pool %u, transport %p, inuse=%d\n", 741 dprintk("svc: server %p, pool %u, transport %p, inuse=%d\n",
744 rqstp, pool->sp_id, xprt, 742 rqstp, pool->sp_id, xprt,
745 atomic_read(&xprt->xpt_ref.refcount)); 743 atomic_read(&xprt->xpt_ref.refcount));
@@ -752,6 +750,11 @@ int svc_recv(struct svc_rqst *rqstp, long timeout)
752 dprintk("svc: got len=%d\n", len); 750 dprintk("svc: got len=%d\n", len);
753 } 751 }
754 752
753 if (test_bit(XPT_CLOSE, &xprt->xpt_flags)) {
754 dprintk("svc_recv: found XPT_CLOSE\n");
755 svc_delete_xprt(xprt);
756 }
757
755 /* No data, incomplete (TCP) read, or accept() */ 758 /* No data, incomplete (TCP) read, or accept() */
756 if (len == 0 || len == -EAGAIN) { 759 if (len == 0 || len == -EAGAIN) {
757 rqstp->rq_res.len = 0; 760 rqstp->rq_res.len = 0;
@@ -808,6 +811,7 @@ int svc_send(struct svc_rqst *rqstp)
808 else 811 else
809 len = xprt->xpt_ops->xpo_sendto(rqstp); 812 len = xprt->xpt_ops->xpo_sendto(rqstp);
810 mutex_unlock(&xprt->xpt_mutex); 813 mutex_unlock(&xprt->xpt_mutex);
814 rpc_wake_up(&xprt->xpt_bc_pending);
811 svc_xprt_release(rqstp); 815 svc_xprt_release(rqstp);
812 816
813 if (len == -ECONNREFUSED || len == -ENOTCONN || len == -EAGAIN) 817 if (len == -ECONNREFUSED || len == -ENOTCONN || len == -EAGAIN)
@@ -1166,11 +1170,6 @@ static void *svc_pool_stats_start(struct seq_file *m, loff_t *pos)
1166 1170
1167 dprintk("svc_pool_stats_start, *pidx=%u\n", pidx); 1171 dprintk("svc_pool_stats_start, *pidx=%u\n", pidx);
1168 1172
1169 lock_kernel();
1170 /* bump up the pseudo refcount while traversing */
1171 svc_get(serv);
1172 unlock_kernel();
1173
1174 if (!pidx) 1173 if (!pidx)
1175 return SEQ_START_TOKEN; 1174 return SEQ_START_TOKEN;
1176 return (pidx > serv->sv_nrpools ? NULL : &serv->sv_pools[pidx-1]); 1175 return (pidx > serv->sv_nrpools ? NULL : &serv->sv_pools[pidx-1]);
@@ -1198,12 +1197,6 @@ static void *svc_pool_stats_next(struct seq_file *m, void *p, loff_t *pos)
1198 1197
1199static void svc_pool_stats_stop(struct seq_file *m, void *p) 1198static void svc_pool_stats_stop(struct seq_file *m, void *p)
1200{ 1199{
1201 struct svc_serv *serv = m->private;
1202
1203 lock_kernel();
1204 /* this function really, really should have been called svc_put() */
1205 svc_destroy(serv);
1206 unlock_kernel();
1207} 1200}
1208 1201
1209static int svc_pool_stats_show(struct seq_file *m, void *p) 1202static int svc_pool_stats_show(struct seq_file *m, void *p)
diff --git a/net/sunrpc/svcauth_unix.c b/net/sunrpc/svcauth_unix.c
index 6caffa34ac01..117f68a8aa40 100644
--- a/net/sunrpc/svcauth_unix.c
+++ b/net/sunrpc/svcauth_unix.c
@@ -668,6 +668,7 @@ static int unix_gid_find(uid_t uid, struct group_info **gip,
668 case 0: 668 case 0:
669 *gip = ug->gi; 669 *gip = ug->gi;
670 get_group_info(*gip); 670 get_group_info(*gip);
671 cache_put(&ug->h, &unix_gid_cache);
671 return 0; 672 return 0;
672 default: 673 default:
673 return -EAGAIN; 674 return -EAGAIN;
diff --git a/net/sunrpc/svcsock.c b/net/sunrpc/svcsock.c
index 23128ee191ae..ccc5e83cae5d 100644
--- a/net/sunrpc/svcsock.c
+++ b/net/sunrpc/svcsock.c
@@ -49,6 +49,7 @@
49#include <linux/sunrpc/msg_prot.h> 49#include <linux/sunrpc/msg_prot.h>
50#include <linux/sunrpc/svcsock.h> 50#include <linux/sunrpc/svcsock.h>
51#include <linux/sunrpc/stats.h> 51#include <linux/sunrpc/stats.h>
52#include <linux/sunrpc/xprt.h>
52 53
53#define RPCDBG_FACILITY RPCDBG_SVCXPRT 54#define RPCDBG_FACILITY RPCDBG_SVCXPRT
54 55
@@ -153,49 +154,27 @@ static void svc_set_cmsg_data(struct svc_rqst *rqstp, struct cmsghdr *cmh)
153} 154}
154 155
155/* 156/*
156 * Generic sendto routine 157 * send routine intended to be shared by the fore- and back-channel
157 */ 158 */
158static int svc_sendto(struct svc_rqst *rqstp, struct xdr_buf *xdr) 159int svc_send_common(struct socket *sock, struct xdr_buf *xdr,
160 struct page *headpage, unsigned long headoffset,
161 struct page *tailpage, unsigned long tailoffset)
159{ 162{
160 struct svc_sock *svsk =
161 container_of(rqstp->rq_xprt, struct svc_sock, sk_xprt);
162 struct socket *sock = svsk->sk_sock;
163 int slen;
164 union {
165 struct cmsghdr hdr;
166 long all[SVC_PKTINFO_SPACE / sizeof(long)];
167 } buffer;
168 struct cmsghdr *cmh = &buffer.hdr;
169 int len = 0;
170 int result; 163 int result;
171 int size; 164 int size;
172 struct page **ppage = xdr->pages; 165 struct page **ppage = xdr->pages;
173 size_t base = xdr->page_base; 166 size_t base = xdr->page_base;
174 unsigned int pglen = xdr->page_len; 167 unsigned int pglen = xdr->page_len;
175 unsigned int flags = MSG_MORE; 168 unsigned int flags = MSG_MORE;
176 RPC_IFDEBUG(char buf[RPC_MAX_ADDRBUFLEN]); 169 int slen;
170 int len = 0;
177 171
178 slen = xdr->len; 172 slen = xdr->len;
179 173
180 if (rqstp->rq_prot == IPPROTO_UDP) {
181 struct msghdr msg = {
182 .msg_name = &rqstp->rq_addr,
183 .msg_namelen = rqstp->rq_addrlen,
184 .msg_control = cmh,
185 .msg_controllen = sizeof(buffer),
186 .msg_flags = MSG_MORE,
187 };
188
189 svc_set_cmsg_data(rqstp, cmh);
190
191 if (sock_sendmsg(sock, &msg, 0) < 0)
192 goto out;
193 }
194
195 /* send head */ 174 /* send head */
196 if (slen == xdr->head[0].iov_len) 175 if (slen == xdr->head[0].iov_len)
197 flags = 0; 176 flags = 0;
198 len = kernel_sendpage(sock, rqstp->rq_respages[0], 0, 177 len = kernel_sendpage(sock, headpage, headoffset,
199 xdr->head[0].iov_len, flags); 178 xdr->head[0].iov_len, flags);
200 if (len != xdr->head[0].iov_len) 179 if (len != xdr->head[0].iov_len)
201 goto out; 180 goto out;
@@ -219,16 +198,58 @@ static int svc_sendto(struct svc_rqst *rqstp, struct xdr_buf *xdr)
219 base = 0; 198 base = 0;
220 ppage++; 199 ppage++;
221 } 200 }
201
222 /* send tail */ 202 /* send tail */
223 if (xdr->tail[0].iov_len) { 203 if (xdr->tail[0].iov_len) {
224 result = kernel_sendpage(sock, rqstp->rq_respages[0], 204 result = kernel_sendpage(sock, tailpage, tailoffset,
225 ((unsigned long)xdr->tail[0].iov_base) 205 xdr->tail[0].iov_len, 0);
226 & (PAGE_SIZE-1),
227 xdr->tail[0].iov_len, 0);
228
229 if (result > 0) 206 if (result > 0)
230 len += result; 207 len += result;
231 } 208 }
209
210out:
211 return len;
212}
213
214
215/*
216 * Generic sendto routine
217 */
218static int svc_sendto(struct svc_rqst *rqstp, struct xdr_buf *xdr)
219{
220 struct svc_sock *svsk =
221 container_of(rqstp->rq_xprt, struct svc_sock, sk_xprt);
222 struct socket *sock = svsk->sk_sock;
223 union {
224 struct cmsghdr hdr;
225 long all[SVC_PKTINFO_SPACE / sizeof(long)];
226 } buffer;
227 struct cmsghdr *cmh = &buffer.hdr;
228 int len = 0;
229 unsigned long tailoff;
230 unsigned long headoff;
231 RPC_IFDEBUG(char buf[RPC_MAX_ADDRBUFLEN]);
232
233 if (rqstp->rq_prot == IPPROTO_UDP) {
234 struct msghdr msg = {
235 .msg_name = &rqstp->rq_addr,
236 .msg_namelen = rqstp->rq_addrlen,
237 .msg_control = cmh,
238 .msg_controllen = sizeof(buffer),
239 .msg_flags = MSG_MORE,
240 };
241
242 svc_set_cmsg_data(rqstp, cmh);
243
244 if (sock_sendmsg(sock, &msg, 0) < 0)
245 goto out;
246 }
247
248 tailoff = ((unsigned long)xdr->tail[0].iov_base) & (PAGE_SIZE-1);
249 headoff = 0;
250 len = svc_send_common(sock, xdr, rqstp->rq_respages[0], headoff,
251 rqstp->rq_respages[0], tailoff);
252
232out: 253out:
233 dprintk("svc: socket %p sendto([%p %Zu... ], %d) = %d (addr %s)\n", 254 dprintk("svc: socket %p sendto([%p %Zu... ], %d) = %d (addr %s)\n",
234 svsk, xdr->head[0].iov_base, xdr->head[0].iov_len, 255 svsk, xdr->head[0].iov_base, xdr->head[0].iov_len,
@@ -432,29 +453,49 @@ static void svc_tcp_write_space(struct sock *sk)
432} 453}
433 454
434/* 455/*
456 * See net/ipv6/ip_sockglue.c : ip_cmsg_recv_pktinfo
457 */
458static int svc_udp_get_dest_address4(struct svc_rqst *rqstp,
459 struct cmsghdr *cmh)
460{
461 struct in_pktinfo *pki = CMSG_DATA(cmh);
462 if (cmh->cmsg_type != IP_PKTINFO)
463 return 0;
464 rqstp->rq_daddr.addr.s_addr = pki->ipi_spec_dst.s_addr;
465 return 1;
466}
467
468/*
469 * See net/ipv6/datagram.c : datagram_recv_ctl
470 */
471static int svc_udp_get_dest_address6(struct svc_rqst *rqstp,
472 struct cmsghdr *cmh)
473{
474 struct in6_pktinfo *pki = CMSG_DATA(cmh);
475 if (cmh->cmsg_type != IPV6_PKTINFO)
476 return 0;
477 ipv6_addr_copy(&rqstp->rq_daddr.addr6, &pki->ipi6_addr);
478 return 1;
479}
480
481/*
435 * Copy the UDP datagram's destination address to the rqstp structure. 482 * Copy the UDP datagram's destination address to the rqstp structure.
436 * The 'destination' address in this case is the address to which the 483 * The 'destination' address in this case is the address to which the
437 * peer sent the datagram, i.e. our local address. For multihomed 484 * peer sent the datagram, i.e. our local address. For multihomed
438 * hosts, this can change from msg to msg. Note that only the IP 485 * hosts, this can change from msg to msg. Note that only the IP
439 * address changes, the port number should remain the same. 486 * address changes, the port number should remain the same.
440 */ 487 */
441static void svc_udp_get_dest_address(struct svc_rqst *rqstp, 488static int svc_udp_get_dest_address(struct svc_rqst *rqstp,
442 struct cmsghdr *cmh) 489 struct cmsghdr *cmh)
443{ 490{
444 struct svc_sock *svsk = 491 switch (cmh->cmsg_level) {
445 container_of(rqstp->rq_xprt, struct svc_sock, sk_xprt); 492 case SOL_IP:
446 switch (svsk->sk_sk->sk_family) { 493 return svc_udp_get_dest_address4(rqstp, cmh);
447 case AF_INET: { 494 case SOL_IPV6:
448 struct in_pktinfo *pki = CMSG_DATA(cmh); 495 return svc_udp_get_dest_address6(rqstp, cmh);
449 rqstp->rq_daddr.addr.s_addr = pki->ipi_spec_dst.s_addr;
450 break;
451 }
452 case AF_INET6: {
453 struct in6_pktinfo *pki = CMSG_DATA(cmh);
454 ipv6_addr_copy(&rqstp->rq_daddr.addr6, &pki->ipi6_addr);
455 break;
456 }
457 } 496 }
497
498 return 0;
458} 499}
459 500
460/* 501/*
@@ -531,16 +572,15 @@ static int svc_udp_recvfrom(struct svc_rqst *rqstp)
531 572
532 rqstp->rq_prot = IPPROTO_UDP; 573 rqstp->rq_prot = IPPROTO_UDP;
533 574
534 if (cmh->cmsg_level != IPPROTO_IP || 575 if (!svc_udp_get_dest_address(rqstp, cmh)) {
535 cmh->cmsg_type != IP_PKTINFO) {
536 if (net_ratelimit()) 576 if (net_ratelimit())
537 printk("rpcsvc: received unknown control message:" 577 printk(KERN_WARNING
538 "%d/%d\n", 578 "svc: received unknown control message %d/%d; "
539 cmh->cmsg_level, cmh->cmsg_type); 579 "dropping RPC reply datagram\n",
580 cmh->cmsg_level, cmh->cmsg_type);
540 skb_free_datagram(svsk->sk_sk, skb); 581 skb_free_datagram(svsk->sk_sk, skb);
541 return 0; 582 return 0;
542 } 583 }
543 svc_udp_get_dest_address(rqstp, cmh);
544 584
545 if (skb_is_nonlinear(skb)) { 585 if (skb_is_nonlinear(skb)) {
546 /* we have to copy */ 586 /* we have to copy */
@@ -651,8 +691,7 @@ static struct svc_xprt_class svc_udp_class = {
651 691
652static void svc_udp_init(struct svc_sock *svsk, struct svc_serv *serv) 692static void svc_udp_init(struct svc_sock *svsk, struct svc_serv *serv)
653{ 693{
654 int one = 1; 694 int err, level, optname, one = 1;
655 mm_segment_t oldfs;
656 695
657 svc_xprt_init(&svc_udp_class, &svsk->sk_xprt, serv); 696 svc_xprt_init(&svc_udp_class, &svsk->sk_xprt, serv);
658 clear_bit(XPT_CACHE_AUTH, &svsk->sk_xprt.xpt_flags); 697 clear_bit(XPT_CACHE_AUTH, &svsk->sk_xprt.xpt_flags);
@@ -671,12 +710,22 @@ static void svc_udp_init(struct svc_sock *svsk, struct svc_serv *serv)
671 set_bit(XPT_DATA, &svsk->sk_xprt.xpt_flags); 710 set_bit(XPT_DATA, &svsk->sk_xprt.xpt_flags);
672 set_bit(XPT_CHNGBUF, &svsk->sk_xprt.xpt_flags); 711 set_bit(XPT_CHNGBUF, &svsk->sk_xprt.xpt_flags);
673 712
674 oldfs = get_fs();
675 set_fs(KERNEL_DS);
676 /* make sure we get destination address info */ 713 /* make sure we get destination address info */
677 svsk->sk_sock->ops->setsockopt(svsk->sk_sock, IPPROTO_IP, IP_PKTINFO, 714 switch (svsk->sk_sk->sk_family) {
678 (char __user *)&one, sizeof(one)); 715 case AF_INET:
679 set_fs(oldfs); 716 level = SOL_IP;
717 optname = IP_PKTINFO;
718 break;
719 case AF_INET6:
720 level = SOL_IPV6;
721 optname = IPV6_RECVPKTINFO;
722 break;
723 default:
724 BUG();
725 }
726 err = kernel_setsockopt(svsk->sk_sock, level, optname,
727 (char *)&one, sizeof(one));
728 dprintk("svc: kernel_setsockopt returned %d\n", err);
680} 729}
681 730
682/* 731/*
@@ -826,21 +875,15 @@ failed:
826} 875}
827 876
828/* 877/*
829 * Receive data from a TCP socket. 878 * Receive data.
879 * If we haven't gotten the record length yet, get the next four bytes.
880 * Otherwise try to gobble up as much as possible up to the complete
881 * record length.
830 */ 882 */
831static int svc_tcp_recvfrom(struct svc_rqst *rqstp) 883static int svc_tcp_recv_record(struct svc_sock *svsk, struct svc_rqst *rqstp)
832{ 884{
833 struct svc_sock *svsk =
834 container_of(rqstp->rq_xprt, struct svc_sock, sk_xprt);
835 struct svc_serv *serv = svsk->sk_xprt.xpt_server; 885 struct svc_serv *serv = svsk->sk_xprt.xpt_server;
836 int len; 886 int len;
837 struct kvec *vec;
838 int pnum, vlen;
839
840 dprintk("svc: tcp_recv %p data %d conn %d close %d\n",
841 svsk, test_bit(XPT_DATA, &svsk->sk_xprt.xpt_flags),
842 test_bit(XPT_CONN, &svsk->sk_xprt.xpt_flags),
843 test_bit(XPT_CLOSE, &svsk->sk_xprt.xpt_flags));
844 887
845 if (test_and_clear_bit(XPT_CHNGBUF, &svsk->sk_xprt.xpt_flags)) 888 if (test_and_clear_bit(XPT_CHNGBUF, &svsk->sk_xprt.xpt_flags))
846 /* sndbuf needs to have room for one request 889 /* sndbuf needs to have room for one request
@@ -861,10 +904,6 @@ static int svc_tcp_recvfrom(struct svc_rqst *rqstp)
861 904
862 clear_bit(XPT_DATA, &svsk->sk_xprt.xpt_flags); 905 clear_bit(XPT_DATA, &svsk->sk_xprt.xpt_flags);
863 906
864 /* Receive data. If we haven't got the record length yet, get
865 * the next four bytes. Otherwise try to gobble up as much as
866 * possible up to the complete record length.
867 */
868 if (svsk->sk_tcplen < sizeof(rpc_fraghdr)) { 907 if (svsk->sk_tcplen < sizeof(rpc_fraghdr)) {
869 int want = sizeof(rpc_fraghdr) - svsk->sk_tcplen; 908 int want = sizeof(rpc_fraghdr) - svsk->sk_tcplen;
870 struct kvec iov; 909 struct kvec iov;
@@ -879,7 +918,7 @@ static int svc_tcp_recvfrom(struct svc_rqst *rqstp)
879 dprintk("svc: short recvfrom while reading record " 918 dprintk("svc: short recvfrom while reading record "
880 "length (%d of %d)\n", len, want); 919 "length (%d of %d)\n", len, want);
881 svc_xprt_received(&svsk->sk_xprt); 920 svc_xprt_received(&svsk->sk_xprt);
882 return -EAGAIN; /* record header not complete */ 921 goto err_again; /* record header not complete */
883 } 922 }
884 923
885 svsk->sk_reclen = ntohl(svsk->sk_reclen); 924 svsk->sk_reclen = ntohl(svsk->sk_reclen);
@@ -894,6 +933,7 @@ static int svc_tcp_recvfrom(struct svc_rqst *rqstp)
894 "per record not supported\n"); 933 "per record not supported\n");
895 goto err_delete; 934 goto err_delete;
896 } 935 }
936
897 svsk->sk_reclen &= RPC_FRAGMENT_SIZE_MASK; 937 svsk->sk_reclen &= RPC_FRAGMENT_SIZE_MASK;
898 dprintk("svc: TCP record, %d bytes\n", svsk->sk_reclen); 938 dprintk("svc: TCP record, %d bytes\n", svsk->sk_reclen);
899 if (svsk->sk_reclen > serv->sv_max_mesg) { 939 if (svsk->sk_reclen > serv->sv_max_mesg) {
@@ -914,17 +954,121 @@ static int svc_tcp_recvfrom(struct svc_rqst *rqstp)
914 dprintk("svc: incomplete TCP record (%d of %d)\n", 954 dprintk("svc: incomplete TCP record (%d of %d)\n",
915 len, svsk->sk_reclen); 955 len, svsk->sk_reclen);
916 svc_xprt_received(&svsk->sk_xprt); 956 svc_xprt_received(&svsk->sk_xprt);
917 return -EAGAIN; /* record not complete */ 957 goto err_again; /* record not complete */
918 } 958 }
919 len = svsk->sk_reclen; 959 len = svsk->sk_reclen;
920 set_bit(XPT_DATA, &svsk->sk_xprt.xpt_flags); 960 set_bit(XPT_DATA, &svsk->sk_xprt.xpt_flags);
921 961
962 return len;
963 error:
964 if (len == -EAGAIN) {
965 dprintk("RPC: TCP recv_record got EAGAIN\n");
966 svc_xprt_received(&svsk->sk_xprt);
967 }
968 return len;
969 err_delete:
970 set_bit(XPT_CLOSE, &svsk->sk_xprt.xpt_flags);
971 err_again:
972 return -EAGAIN;
973}
974
975static int svc_process_calldir(struct svc_sock *svsk, struct svc_rqst *rqstp,
976 struct rpc_rqst **reqpp, struct kvec *vec)
977{
978 struct rpc_rqst *req = NULL;
979 u32 *p;
980 u32 xid;
981 u32 calldir;
982 int len;
983
984 len = svc_recvfrom(rqstp, vec, 1, 8);
985 if (len < 0)
986 goto error;
987
988 p = (u32 *)rqstp->rq_arg.head[0].iov_base;
989 xid = *p++;
990 calldir = *p;
991
992 if (calldir == 0) {
993 /* REQUEST is the most common case */
994 vec[0] = rqstp->rq_arg.head[0];
995 } else {
996 /* REPLY */
997 if (svsk->sk_bc_xprt)
998 req = xprt_lookup_rqst(svsk->sk_bc_xprt, xid);
999
1000 if (!req) {
1001 printk(KERN_NOTICE
1002 "%s: Got unrecognized reply: "
1003 "calldir 0x%x sk_bc_xprt %p xid %08x\n",
1004 __func__, ntohl(calldir),
1005 svsk->sk_bc_xprt, xid);
1006 vec[0] = rqstp->rq_arg.head[0];
1007 goto out;
1008 }
1009
1010 memcpy(&req->rq_private_buf, &req->rq_rcv_buf,
1011 sizeof(struct xdr_buf));
1012 /* copy the xid and call direction */
1013 memcpy(req->rq_private_buf.head[0].iov_base,
1014 rqstp->rq_arg.head[0].iov_base, 8);
1015 vec[0] = req->rq_private_buf.head[0];
1016 }
1017 out:
1018 vec[0].iov_base += 8;
1019 vec[0].iov_len -= 8;
1020 len = svsk->sk_reclen - 8;
1021 error:
1022 *reqpp = req;
1023 return len;
1024}
1025
1026/*
1027 * Receive data from a TCP socket.
1028 */
1029static int svc_tcp_recvfrom(struct svc_rqst *rqstp)
1030{
1031 struct svc_sock *svsk =
1032 container_of(rqstp->rq_xprt, struct svc_sock, sk_xprt);
1033 struct svc_serv *serv = svsk->sk_xprt.xpt_server;
1034 int len;
1035 struct kvec *vec;
1036 int pnum, vlen;
1037 struct rpc_rqst *req = NULL;
1038
1039 dprintk("svc: tcp_recv %p data %d conn %d close %d\n",
1040 svsk, test_bit(XPT_DATA, &svsk->sk_xprt.xpt_flags),
1041 test_bit(XPT_CONN, &svsk->sk_xprt.xpt_flags),
1042 test_bit(XPT_CLOSE, &svsk->sk_xprt.xpt_flags));
1043
1044 len = svc_tcp_recv_record(svsk, rqstp);
1045 if (len < 0)
1046 goto error;
1047
922 vec = rqstp->rq_vec; 1048 vec = rqstp->rq_vec;
923 vec[0] = rqstp->rq_arg.head[0]; 1049 vec[0] = rqstp->rq_arg.head[0];
924 vlen = PAGE_SIZE; 1050 vlen = PAGE_SIZE;
1051
1052 /*
1053 * We have enough data for the whole tcp record. Let's try and read the
1054 * first 8 bytes to get the xid and the call direction. We can use this
1055 * to figure out if this is a call or a reply to a callback. If
1056 * sk_reclen is < 8 (xid and calldir), then this is a malformed packet.
1057 * In that case, don't bother with the calldir and just read the data.
1058 * It will be rejected in svc_process.
1059 */
1060 if (len >= 8) {
1061 len = svc_process_calldir(svsk, rqstp, &req, vec);
1062 if (len < 0)
1063 goto err_again;
1064 vlen -= 8;
1065 }
1066
925 pnum = 1; 1067 pnum = 1;
926 while (vlen < len) { 1068 while (vlen < len) {
927 vec[pnum].iov_base = page_address(rqstp->rq_pages[pnum]); 1069 vec[pnum].iov_base = (req) ?
1070 page_address(req->rq_private_buf.pages[pnum - 1]) :
1071 page_address(rqstp->rq_pages[pnum]);
928 vec[pnum].iov_len = PAGE_SIZE; 1072 vec[pnum].iov_len = PAGE_SIZE;
929 pnum++; 1073 pnum++;
930 vlen += PAGE_SIZE; 1074 vlen += PAGE_SIZE;
@@ -934,8 +1078,18 @@ static int svc_tcp_recvfrom(struct svc_rqst *rqstp)
934 /* Now receive data */ 1078 /* Now receive data */
935 len = svc_recvfrom(rqstp, vec, pnum, len); 1079 len = svc_recvfrom(rqstp, vec, pnum, len);
936 if (len < 0) 1080 if (len < 0)
937 goto error; 1081 goto err_again;
938 1082
1083 /*
1084 * Account for the 8 bytes we read earlier
1085 */
1086 len += 8;
1087
1088 if (req) {
1089 xprt_complete_rqst(req->rq_task, len);
1090 len = 0;
1091 goto out;
1092 }
939 dprintk("svc: TCP complete record (%d bytes)\n", len); 1093 dprintk("svc: TCP complete record (%d bytes)\n", len);
940 rqstp->rq_arg.len = len; 1094 rqstp->rq_arg.len = len;
941 rqstp->rq_arg.page_base = 0; 1095 rqstp->rq_arg.page_base = 0;
@@ -949,6 +1103,7 @@ static int svc_tcp_recvfrom(struct svc_rqst *rqstp)
949 rqstp->rq_xprt_ctxt = NULL; 1103 rqstp->rq_xprt_ctxt = NULL;
950 rqstp->rq_prot = IPPROTO_TCP; 1104 rqstp->rq_prot = IPPROTO_TCP;
951 1105
1106out:
952 /* Reset TCP read info */ 1107 /* Reset TCP read info */
953 svsk->sk_reclen = 0; 1108 svsk->sk_reclen = 0;
954 svsk->sk_tcplen = 0; 1109 svsk->sk_tcplen = 0;
@@ -960,21 +1115,19 @@ static int svc_tcp_recvfrom(struct svc_rqst *rqstp)
960 1115
961 return len; 1116 return len;
962 1117
963 err_delete: 1118err_again:
964 set_bit(XPT_CLOSE, &svsk->sk_xprt.xpt_flags);
965 return -EAGAIN;
966
967 error:
968 if (len == -EAGAIN) { 1119 if (len == -EAGAIN) {
969 dprintk("RPC: TCP recvfrom got EAGAIN\n"); 1120 dprintk("RPC: TCP recvfrom got EAGAIN\n");
970 svc_xprt_received(&svsk->sk_xprt); 1121 svc_xprt_received(&svsk->sk_xprt);
971 } else { 1122 return len;
1123 }
1124error:
1125 if (len != -EAGAIN) {
972 printk(KERN_NOTICE "%s: recvfrom returned errno %d\n", 1126 printk(KERN_NOTICE "%s: recvfrom returned errno %d\n",
973 svsk->sk_xprt.xpt_server->sv_name, -len); 1127 svsk->sk_xprt.xpt_server->sv_name, -len);
974 goto err_delete; 1128 set_bit(XPT_CLOSE, &svsk->sk_xprt.xpt_flags);
975 } 1129 }
976 1130 return -EAGAIN;
977 return len;
978} 1131}
979 1132
980/* 1133/*
diff --git a/net/sunrpc/sysctl.c b/net/sunrpc/sysctl.c
index 5231f7aaac0e..42f9748ae093 100644
--- a/net/sunrpc/sysctl.c
+++ b/net/sunrpc/sysctl.c
@@ -56,7 +56,7 @@ rpc_unregister_sysctl(void)
56 } 56 }
57} 57}
58 58
59static int proc_do_xprt(ctl_table *table, int write, struct file *file, 59static int proc_do_xprt(ctl_table *table, int write,
60 void __user *buffer, size_t *lenp, loff_t *ppos) 60 void __user *buffer, size_t *lenp, loff_t *ppos)
61{ 61{
62 char tmpbuf[256]; 62 char tmpbuf[256];
@@ -71,7 +71,7 @@ static int proc_do_xprt(ctl_table *table, int write, struct file *file,
71} 71}
72 72
73static int 73static int
74proc_dodebug(ctl_table *table, int write, struct file *file, 74proc_dodebug(ctl_table *table, int write,
75 void __user *buffer, size_t *lenp, loff_t *ppos) 75 void __user *buffer, size_t *lenp, loff_t *ppos)
76{ 76{
77 char tmpbuf[20], c, *s; 77 char tmpbuf[20], c, *s;
diff --git a/net/sunrpc/xprt.c b/net/sunrpc/xprt.c
index f412a852bc73..fd46d42afa89 100644
--- a/net/sunrpc/xprt.c
+++ b/net/sunrpc/xprt.c
@@ -832,6 +832,11 @@ static void xprt_timer(struct rpc_task *task)
832 spin_unlock_bh(&xprt->transport_lock); 832 spin_unlock_bh(&xprt->transport_lock);
833} 833}
834 834
835static inline int xprt_has_timer(struct rpc_xprt *xprt)
836{
837 return xprt->idle_timeout != 0;
838}
839
835/** 840/**
836 * xprt_prepare_transmit - reserve the transport before sending a request 841 * xprt_prepare_transmit - reserve the transport before sending a request
837 * @task: RPC task about to send a request 842 * @task: RPC task about to send a request
@@ -1013,7 +1018,7 @@ void xprt_release(struct rpc_task *task)
1013 if (!list_empty(&req->rq_list)) 1018 if (!list_empty(&req->rq_list))
1014 list_del(&req->rq_list); 1019 list_del(&req->rq_list);
1015 xprt->last_used = jiffies; 1020 xprt->last_used = jiffies;
1016 if (list_empty(&xprt->recv)) 1021 if (list_empty(&xprt->recv) && xprt_has_timer(xprt))
1017 mod_timer(&xprt->timer, 1022 mod_timer(&xprt->timer,
1018 xprt->last_used + xprt->idle_timeout); 1023 xprt->last_used + xprt->idle_timeout);
1019 spin_unlock_bh(&xprt->transport_lock); 1024 spin_unlock_bh(&xprt->transport_lock);
@@ -1082,8 +1087,11 @@ found:
1082#endif /* CONFIG_NFS_V4_1 */ 1087#endif /* CONFIG_NFS_V4_1 */
1083 1088
1084 INIT_WORK(&xprt->task_cleanup, xprt_autoclose); 1089 INIT_WORK(&xprt->task_cleanup, xprt_autoclose);
1085 setup_timer(&xprt->timer, xprt_init_autodisconnect, 1090 if (xprt_has_timer(xprt))
1086 (unsigned long)xprt); 1091 setup_timer(&xprt->timer, xprt_init_autodisconnect,
1092 (unsigned long)xprt);
1093 else
1094 init_timer(&xprt->timer);
1087 xprt->last_used = jiffies; 1095 xprt->last_used = jiffies;
1088 xprt->cwnd = RPC_INITCWND; 1096 xprt->cwnd = RPC_INITCWND;
1089 xprt->bind_index = 0; 1097 xprt->bind_index = 0;
@@ -1102,7 +1110,6 @@ found:
1102 1110
1103 dprintk("RPC: created transport %p with %u slots\n", xprt, 1111 dprintk("RPC: created transport %p with %u slots\n", xprt,
1104 xprt->max_reqs); 1112 xprt->max_reqs);
1105
1106 return xprt; 1113 return xprt;
1107} 1114}
1108 1115
diff --git a/net/sunrpc/xprtrdma/svc_rdma.c b/net/sunrpc/xprtrdma/svc_rdma.c
index 87101177825b..35fb68b9c8ec 100644
--- a/net/sunrpc/xprtrdma/svc_rdma.c
+++ b/net/sunrpc/xprtrdma/svc_rdma.c
@@ -80,7 +80,7 @@ struct kmem_cache *svc_rdma_ctxt_cachep;
80 * current value. 80 * current value.
81 */ 81 */
82static int read_reset_stat(ctl_table *table, int write, 82static int read_reset_stat(ctl_table *table, int write,
83 struct file *filp, void __user *buffer, size_t *lenp, 83 void __user *buffer, size_t *lenp,
84 loff_t *ppos) 84 loff_t *ppos)
85{ 85{
86 atomic_t *stat = (atomic_t *)table->data; 86 atomic_t *stat = (atomic_t *)table->data;
diff --git a/net/sunrpc/xprtrdma/svc_rdma_transport.c b/net/sunrpc/xprtrdma/svc_rdma_transport.c
index 5151f9f6c573..3fa5751af0ec 100644
--- a/net/sunrpc/xprtrdma/svc_rdma_transport.c
+++ b/net/sunrpc/xprtrdma/svc_rdma_transport.c
@@ -42,6 +42,7 @@
42#include <linux/sunrpc/svc_xprt.h> 42#include <linux/sunrpc/svc_xprt.h>
43#include <linux/sunrpc/debug.h> 43#include <linux/sunrpc/debug.h>
44#include <linux/sunrpc/rpc_rdma.h> 44#include <linux/sunrpc/rpc_rdma.h>
45#include <linux/sched.h>
45#include <linux/spinlock.h> 46#include <linux/spinlock.h>
46#include <rdma/ib_verbs.h> 47#include <rdma/ib_verbs.h>
47#include <rdma/rdma_cm.h> 48#include <rdma/rdma_cm.h>
@@ -730,12 +731,12 @@ static struct svc_rdma_fastreg_mr *rdma_alloc_frmr(struct svcxprt_rdma *xprt)
730 goto err; 731 goto err;
731 732
732 mr = ib_alloc_fast_reg_mr(xprt->sc_pd, RPCSVC_MAXPAGES); 733 mr = ib_alloc_fast_reg_mr(xprt->sc_pd, RPCSVC_MAXPAGES);
733 if (!mr) 734 if (IS_ERR(mr))
734 goto err_free_frmr; 735 goto err_free_frmr;
735 736
736 pl = ib_alloc_fast_reg_page_list(xprt->sc_cm_id->device, 737 pl = ib_alloc_fast_reg_page_list(xprt->sc_cm_id->device,
737 RPCSVC_MAXPAGES); 738 RPCSVC_MAXPAGES);
738 if (!pl) 739 if (IS_ERR(pl))
739 goto err_free_mr; 740 goto err_free_mr;
740 741
741 frmr->mr = mr; 742 frmr->mr = mr;
diff --git a/net/sunrpc/xprtsock.c b/net/sunrpc/xprtsock.c
index 62438f3a914d..37c5475ba258 100644
--- a/net/sunrpc/xprtsock.c
+++ b/net/sunrpc/xprtsock.c
@@ -32,6 +32,7 @@
32#include <linux/tcp.h> 32#include <linux/tcp.h>
33#include <linux/sunrpc/clnt.h> 33#include <linux/sunrpc/clnt.h>
34#include <linux/sunrpc/sched.h> 34#include <linux/sunrpc/sched.h>
35#include <linux/sunrpc/svcsock.h>
35#include <linux/sunrpc/xprtsock.h> 36#include <linux/sunrpc/xprtsock.h>
36#include <linux/file.h> 37#include <linux/file.h>
37#ifdef CONFIG_NFS_V4_1 38#ifdef CONFIG_NFS_V4_1
@@ -43,6 +44,7 @@
43#include <net/udp.h> 44#include <net/udp.h>
44#include <net/tcp.h> 45#include <net/tcp.h>
45 46
47#include "sunrpc.h"
46/* 48/*
47 * xprtsock tunables 49 * xprtsock tunables
48 */ 50 */
@@ -771,6 +773,7 @@ static void xs_close(struct rpc_xprt *xprt)
771 dprintk("RPC: xs_close xprt %p\n", xprt); 773 dprintk("RPC: xs_close xprt %p\n", xprt);
772 774
773 xs_reset_transport(transport); 775 xs_reset_transport(transport);
776 xprt->reestablish_timeout = 0;
774 777
775 smp_mb__before_clear_bit(); 778 smp_mb__before_clear_bit();
776 clear_bit(XPRT_CONNECTION_ABORT, &xprt->state); 779 clear_bit(XPRT_CONNECTION_ABORT, &xprt->state);
@@ -1262,6 +1265,12 @@ static void xs_tcp_data_ready(struct sock *sk, int bytes)
1262 if (xprt->shutdown) 1265 if (xprt->shutdown)
1263 goto out; 1266 goto out;
1264 1267
1268 /* Any data means we had a useful conversation, so
1269 * the we don't need to delay the next reconnect
1270 */
1271 if (xprt->reestablish_timeout)
1272 xprt->reestablish_timeout = 0;
1273
1265 /* We use rd_desc to pass struct xprt to xs_tcp_data_recv */ 1274 /* We use rd_desc to pass struct xprt to xs_tcp_data_recv */
1266 rd_desc.arg.data = xprt; 1275 rd_desc.arg.data = xprt;
1267 do { 1276 do {
@@ -2032,6 +2041,8 @@ static void xs_connect(struct rpc_task *task)
2032 &transport->connect_worker, 2041 &transport->connect_worker,
2033 xprt->reestablish_timeout); 2042 xprt->reestablish_timeout);
2034 xprt->reestablish_timeout <<= 1; 2043 xprt->reestablish_timeout <<= 1;
2044 if (xprt->reestablish_timeout < XS_TCP_INIT_REEST_TO)
2045 xprt->reestablish_timeout = XS_TCP_INIT_REEST_TO;
2035 if (xprt->reestablish_timeout > XS_TCP_MAX_REEST_TO) 2046 if (xprt->reestablish_timeout > XS_TCP_MAX_REEST_TO)
2036 xprt->reestablish_timeout = XS_TCP_MAX_REEST_TO; 2047 xprt->reestablish_timeout = XS_TCP_MAX_REEST_TO;
2037 } else { 2048 } else {
@@ -2098,6 +2109,134 @@ static void xs_tcp_print_stats(struct rpc_xprt *xprt, struct seq_file *seq)
2098 xprt->stat.bklog_u); 2109 xprt->stat.bklog_u);
2099} 2110}
2100 2111
2112/*
2113 * Allocate a bunch of pages for a scratch buffer for the rpc code. The reason
2114 * we allocate pages instead doing a kmalloc like rpc_malloc is because we want
2115 * to use the server side send routines.
2116 */
2117void *bc_malloc(struct rpc_task *task, size_t size)
2118{
2119 struct page *page;
2120 struct rpc_buffer *buf;
2121
2122 BUG_ON(size > PAGE_SIZE - sizeof(struct rpc_buffer));
2123 page = alloc_page(GFP_KERNEL);
2124
2125 if (!page)
2126 return NULL;
2127
2128 buf = page_address(page);
2129 buf->len = PAGE_SIZE;
2130
2131 return buf->data;
2132}
2133
2134/*
2135 * Free the space allocated in the bc_alloc routine
2136 */
2137void bc_free(void *buffer)
2138{
2139 struct rpc_buffer *buf;
2140
2141 if (!buffer)
2142 return;
2143
2144 buf = container_of(buffer, struct rpc_buffer, data);
2145 free_page((unsigned long)buf);
2146}
2147
2148/*
2149 * Use the svc_sock to send the callback. Must be called with svsk->sk_mutex
2150 * held. Borrows heavily from svc_tcp_sendto and xs_tcp_send_request.
2151 */
2152static int bc_sendto(struct rpc_rqst *req)
2153{
2154 int len;
2155 struct xdr_buf *xbufp = &req->rq_snd_buf;
2156 struct rpc_xprt *xprt = req->rq_xprt;
2157 struct sock_xprt *transport =
2158 container_of(xprt, struct sock_xprt, xprt);
2159 struct socket *sock = transport->sock;
2160 unsigned long headoff;
2161 unsigned long tailoff;
2162
2163 /*
2164 * Set up the rpc header and record marker stuff
2165 */
2166 xs_encode_tcp_record_marker(xbufp);
2167
2168 tailoff = (unsigned long)xbufp->tail[0].iov_base & ~PAGE_MASK;
2169 headoff = (unsigned long)xbufp->head[0].iov_base & ~PAGE_MASK;
2170 len = svc_send_common(sock, xbufp,
2171 virt_to_page(xbufp->head[0].iov_base), headoff,
2172 xbufp->tail[0].iov_base, tailoff);
2173
2174 if (len != xbufp->len) {
2175 printk(KERN_NOTICE "Error sending entire callback!\n");
2176 len = -EAGAIN;
2177 }
2178
2179 return len;
2180}
2181
2182/*
2183 * The send routine. Borrows from svc_send
2184 */
2185static int bc_send_request(struct rpc_task *task)
2186{
2187 struct rpc_rqst *req = task->tk_rqstp;
2188 struct svc_xprt *xprt;
2189 struct svc_sock *svsk;
2190 u32 len;
2191
2192 dprintk("sending request with xid: %08x\n", ntohl(req->rq_xid));
2193 /*
2194 * Get the server socket associated with this callback xprt
2195 */
2196 xprt = req->rq_xprt->bc_xprt;
2197 svsk = container_of(xprt, struct svc_sock, sk_xprt);
2198
2199 /*
2200 * Grab the mutex to serialize data as the connection is shared
2201 * with the fore channel
2202 */
2203 if (!mutex_trylock(&xprt->xpt_mutex)) {
2204 rpc_sleep_on(&xprt->xpt_bc_pending, task, NULL);
2205 if (!mutex_trylock(&xprt->xpt_mutex))
2206 return -EAGAIN;
2207 rpc_wake_up_queued_task(&xprt->xpt_bc_pending, task);
2208 }
2209 if (test_bit(XPT_DEAD, &xprt->xpt_flags))
2210 len = -ENOTCONN;
2211 else
2212 len = bc_sendto(req);
2213 mutex_unlock(&xprt->xpt_mutex);
2214
2215 if (len > 0)
2216 len = 0;
2217
2218 return len;
2219}
2220
2221/*
2222 * The close routine. Since this is client initiated, we do nothing
2223 */
2224
2225static void bc_close(struct rpc_xprt *xprt)
2226{
2227 return;
2228}
2229
2230/*
2231 * The xprt destroy routine. Again, because this connection is client
2232 * initiated, we do nothing
2233 */
2234
2235static void bc_destroy(struct rpc_xprt *xprt)
2236{
2237 return;
2238}
2239
2101static struct rpc_xprt_ops xs_udp_ops = { 2240static struct rpc_xprt_ops xs_udp_ops = {
2102 .set_buffer_size = xs_udp_set_buffer_size, 2241 .set_buffer_size = xs_udp_set_buffer_size,
2103 .reserve_xprt = xprt_reserve_xprt_cong, 2242 .reserve_xprt = xprt_reserve_xprt_cong,
@@ -2134,6 +2273,22 @@ static struct rpc_xprt_ops xs_tcp_ops = {
2134 .print_stats = xs_tcp_print_stats, 2273 .print_stats = xs_tcp_print_stats,
2135}; 2274};
2136 2275
2276/*
2277 * The rpc_xprt_ops for the server backchannel
2278 */
2279
2280static struct rpc_xprt_ops bc_tcp_ops = {
2281 .reserve_xprt = xprt_reserve_xprt,
2282 .release_xprt = xprt_release_xprt,
2283 .buf_alloc = bc_malloc,
2284 .buf_free = bc_free,
2285 .send_request = bc_send_request,
2286 .set_retrans_timeout = xprt_set_retrans_timeout_def,
2287 .close = bc_close,
2288 .destroy = bc_destroy,
2289 .print_stats = xs_tcp_print_stats,
2290};
2291
2137static struct rpc_xprt *xs_setup_xprt(struct xprt_create *args, 2292static struct rpc_xprt *xs_setup_xprt(struct xprt_create *args,
2138 unsigned int slot_table_size) 2293 unsigned int slot_table_size)
2139{ 2294{
@@ -2322,11 +2477,93 @@ static struct rpc_xprt *xs_setup_tcp(struct xprt_create *args)
2322 return ERR_PTR(-EINVAL); 2477 return ERR_PTR(-EINVAL);
2323} 2478}
2324 2479
2480/**
2481 * xs_setup_bc_tcp - Set up transport to use a TCP backchannel socket
2482 * @args: rpc transport creation arguments
2483 *
2484 */
2485static struct rpc_xprt *xs_setup_bc_tcp(struct xprt_create *args)
2486{
2487 struct sockaddr *addr = args->dstaddr;
2488 struct rpc_xprt *xprt;
2489 struct sock_xprt *transport;
2490 struct svc_sock *bc_sock;
2491
2492 if (!args->bc_xprt)
2493 ERR_PTR(-EINVAL);
2494
2495 xprt = xs_setup_xprt(args, xprt_tcp_slot_table_entries);
2496 if (IS_ERR(xprt))
2497 return xprt;
2498 transport = container_of(xprt, struct sock_xprt, xprt);
2499
2500 xprt->prot = IPPROTO_TCP;
2501 xprt->tsh_size = sizeof(rpc_fraghdr) / sizeof(u32);
2502 xprt->max_payload = RPC_MAX_FRAGMENT_SIZE;
2503 xprt->timeout = &xs_tcp_default_timeout;
2504
2505 /* backchannel */
2506 xprt_set_bound(xprt);
2507 xprt->bind_timeout = 0;
2508 xprt->connect_timeout = 0;
2509 xprt->reestablish_timeout = 0;
2510 xprt->idle_timeout = 0;
2511
2512 /*
2513 * The backchannel uses the same socket connection as the
2514 * forechannel
2515 */
2516 xprt->bc_xprt = args->bc_xprt;
2517 bc_sock = container_of(args->bc_xprt, struct svc_sock, sk_xprt);
2518 bc_sock->sk_bc_xprt = xprt;
2519 transport->sock = bc_sock->sk_sock;
2520 transport->inet = bc_sock->sk_sk;
2521
2522 xprt->ops = &bc_tcp_ops;
2523
2524 switch (addr->sa_family) {
2525 case AF_INET:
2526 xs_format_peer_addresses(xprt, "tcp",
2527 RPCBIND_NETID_TCP);
2528 break;
2529 case AF_INET6:
2530 xs_format_peer_addresses(xprt, "tcp",
2531 RPCBIND_NETID_TCP6);
2532 break;
2533 default:
2534 kfree(xprt);
2535 return ERR_PTR(-EAFNOSUPPORT);
2536 }
2537
2538 if (xprt_bound(xprt))
2539 dprintk("RPC: set up xprt to %s (port %s) via %s\n",
2540 xprt->address_strings[RPC_DISPLAY_ADDR],
2541 xprt->address_strings[RPC_DISPLAY_PORT],
2542 xprt->address_strings[RPC_DISPLAY_PROTO]);
2543 else
2544 dprintk("RPC: set up xprt to %s (autobind) via %s\n",
2545 xprt->address_strings[RPC_DISPLAY_ADDR],
2546 xprt->address_strings[RPC_DISPLAY_PROTO]);
2547
2548 /*
2549 * Since we don't want connections for the backchannel, we set
2550 * the xprt status to connected
2551 */
2552 xprt_set_connected(xprt);
2553
2554
2555 if (try_module_get(THIS_MODULE))
2556 return xprt;
2557 kfree(xprt->slot);
2558 kfree(xprt);
2559 return ERR_PTR(-EINVAL);
2560}
2561
2325static struct xprt_class xs_udp_transport = { 2562static struct xprt_class xs_udp_transport = {
2326 .list = LIST_HEAD_INIT(xs_udp_transport.list), 2563 .list = LIST_HEAD_INIT(xs_udp_transport.list),
2327 .name = "udp", 2564 .name = "udp",
2328 .owner = THIS_MODULE, 2565 .owner = THIS_MODULE,
2329 .ident = IPPROTO_UDP, 2566 .ident = XPRT_TRANSPORT_UDP,
2330 .setup = xs_setup_udp, 2567 .setup = xs_setup_udp,
2331}; 2568};
2332 2569
@@ -2334,10 +2571,18 @@ static struct xprt_class xs_tcp_transport = {
2334 .list = LIST_HEAD_INIT(xs_tcp_transport.list), 2571 .list = LIST_HEAD_INIT(xs_tcp_transport.list),
2335 .name = "tcp", 2572 .name = "tcp",
2336 .owner = THIS_MODULE, 2573 .owner = THIS_MODULE,
2337 .ident = IPPROTO_TCP, 2574 .ident = XPRT_TRANSPORT_TCP,
2338 .setup = xs_setup_tcp, 2575 .setup = xs_setup_tcp,
2339}; 2576};
2340 2577
2578static struct xprt_class xs_bc_tcp_transport = {
2579 .list = LIST_HEAD_INIT(xs_bc_tcp_transport.list),
2580 .name = "tcp NFSv4.1 backchannel",
2581 .owner = THIS_MODULE,
2582 .ident = XPRT_TRANSPORT_BC_TCP,
2583 .setup = xs_setup_bc_tcp,
2584};
2585
2341/** 2586/**
2342 * init_socket_xprt - set up xprtsock's sysctls, register with RPC client 2587 * init_socket_xprt - set up xprtsock's sysctls, register with RPC client
2343 * 2588 *
@@ -2351,6 +2596,7 @@ int init_socket_xprt(void)
2351 2596
2352 xprt_register_transport(&xs_udp_transport); 2597 xprt_register_transport(&xs_udp_transport);
2353 xprt_register_transport(&xs_tcp_transport); 2598 xprt_register_transport(&xs_tcp_transport);
2599 xprt_register_transport(&xs_bc_tcp_transport);
2354 2600
2355 return 0; 2601 return 0;
2356} 2602}
@@ -2370,6 +2616,7 @@ void cleanup_socket_xprt(void)
2370 2616
2371 xprt_unregister_transport(&xs_udp_transport); 2617 xprt_unregister_transport(&xs_udp_transport);
2372 xprt_unregister_transport(&xs_tcp_transport); 2618 xprt_unregister_transport(&xs_tcp_transport);
2619 xprt_unregister_transport(&xs_bc_tcp_transport);
2373} 2620}
2374 2621
2375static int param_set_uint_minmax(const char *val, struct kernel_param *kp, 2622static int param_set_uint_minmax(const char *val, struct kernel_param *kp,
diff --git a/net/tipc/socket.c b/net/tipc/socket.c
index e8254e809b79..e6d9abf7440e 100644
--- a/net/tipc/socket.c
+++ b/net/tipc/socket.c
@@ -1658,7 +1658,7 @@ restart:
1658 */ 1658 */
1659 1659
1660static int setsockopt(struct socket *sock, 1660static int setsockopt(struct socket *sock,
1661 int lvl, int opt, char __user *ov, int ol) 1661 int lvl, int opt, char __user *ov, unsigned int ol)
1662{ 1662{
1663 struct sock *sk = sock->sk; 1663 struct sock *sk = sock->sk;
1664 struct tipc_port *tport = tipc_sk_port(sk); 1664 struct tipc_port *tport = tipc_sk_port(sk);
diff --git a/net/wireless/core.c b/net/wireless/core.c
index 45b2be3274db..a595f712b5bf 100644
--- a/net/wireless/core.c
+++ b/net/wireless/core.c
@@ -14,6 +14,7 @@
14#include <linux/device.h> 14#include <linux/device.h>
15#include <linux/etherdevice.h> 15#include <linux/etherdevice.h>
16#include <linux/rtnetlink.h> 16#include <linux/rtnetlink.h>
17#include <linux/sched.h>
17#include <net/genetlink.h> 18#include <net/genetlink.h>
18#include <net/cfg80211.h> 19#include <net/cfg80211.h>
19#include "nl80211.h" 20#include "nl80211.h"
diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c
index eddab097435c..ca3c92a0a14f 100644
--- a/net/wireless/nl80211.c
+++ b/net/wireless/nl80211.c
@@ -4029,7 +4029,7 @@ static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
4029 rdev = cfg80211_get_dev_from_info(info); 4029 rdev = cfg80211_get_dev_from_info(info);
4030 if (IS_ERR(rdev)) { 4030 if (IS_ERR(rdev)) {
4031 err = PTR_ERR(rdev); 4031 err = PTR_ERR(rdev);
4032 goto out; 4032 goto out_rtnl;
4033 } 4033 }
4034 4034
4035 net = get_net_ns_by_pid(pid); 4035 net = get_net_ns_by_pid(pid);
@@ -4049,6 +4049,7 @@ static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
4049 put_net(net); 4049 put_net(net);
4050 out: 4050 out:
4051 cfg80211_unlock_rdev(rdev); 4051 cfg80211_unlock_rdev(rdev);
4052 out_rtnl:
4052 rtnl_unlock(); 4053 rtnl_unlock();
4053 return err; 4054 return err;
4054} 4055}
diff --git a/net/wireless/scan.c b/net/wireless/scan.c
index 4c210c2debc6..e5f92ee758f4 100644
--- a/net/wireless/scan.c
+++ b/net/wireless/scan.c
@@ -662,7 +662,7 @@ int cfg80211_wext_siwscan(struct net_device *dev,
662 int k; 662 int k;
663 int wiphy_freq = wiphy->bands[band]->channels[j].center_freq; 663 int wiphy_freq = wiphy->bands[band]->channels[j].center_freq;
664 for (k = 0; k < wreq->num_channels; k++) { 664 for (k = 0; k < wreq->num_channels; k++) {
665 int wext_freq = wreq->channel_list[k].m / 100000; 665 int wext_freq = cfg80211_wext_freq(wiphy, &wreq->channel_list[k]);
666 if (wext_freq == wiphy_freq) 666 if (wext_freq == wiphy_freq)
667 goto wext_freq_found; 667 goto wext_freq_found;
668 } 668 }
@@ -675,6 +675,11 @@ int cfg80211_wext_siwscan(struct net_device *dev,
675 wext_freq_not_found: ; 675 wext_freq_not_found: ;
676 } 676 }
677 } 677 }
678 /* No channels found? */
679 if (!i) {
680 err = -EINVAL;
681 goto out;
682 }
678 683
679 /* Set real number of channels specified in creq->channels[] */ 684 /* Set real number of channels specified in creq->channels[] */
680 creq->n_channels = i; 685 creq->n_channels = i;
diff --git a/net/wireless/sme.c b/net/wireless/sme.c
index 68307883ec87..93c3ed329204 100644
--- a/net/wireless/sme.c
+++ b/net/wireless/sme.c
@@ -188,7 +188,7 @@ void cfg80211_conn_work(struct work_struct *work)
188 rtnl_unlock(); 188 rtnl_unlock();
189} 189}
190 190
191static bool cfg80211_get_conn_bss(struct wireless_dev *wdev) 191static struct cfg80211_bss *cfg80211_get_conn_bss(struct wireless_dev *wdev)
192{ 192{
193 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); 193 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
194 struct cfg80211_bss *bss; 194 struct cfg80211_bss *bss;
@@ -205,7 +205,7 @@ static bool cfg80211_get_conn_bss(struct wireless_dev *wdev)
205 WLAN_CAPABILITY_ESS | WLAN_CAPABILITY_PRIVACY, 205 WLAN_CAPABILITY_ESS | WLAN_CAPABILITY_PRIVACY,
206 capa); 206 capa);
207 if (!bss) 207 if (!bss)
208 return false; 208 return NULL;
209 209
210 memcpy(wdev->conn->bssid, bss->bssid, ETH_ALEN); 210 memcpy(wdev->conn->bssid, bss->bssid, ETH_ALEN);
211 wdev->conn->params.bssid = wdev->conn->bssid; 211 wdev->conn->params.bssid = wdev->conn->bssid;
@@ -213,14 +213,14 @@ static bool cfg80211_get_conn_bss(struct wireless_dev *wdev)
213 wdev->conn->state = CFG80211_CONN_AUTHENTICATE_NEXT; 213 wdev->conn->state = CFG80211_CONN_AUTHENTICATE_NEXT;
214 schedule_work(&rdev->conn_work); 214 schedule_work(&rdev->conn_work);
215 215
216 cfg80211_put_bss(bss); 216 return bss;
217 return true;
218} 217}
219 218
220static void __cfg80211_sme_scan_done(struct net_device *dev) 219static void __cfg80211_sme_scan_done(struct net_device *dev)
221{ 220{
222 struct wireless_dev *wdev = dev->ieee80211_ptr; 221 struct wireless_dev *wdev = dev->ieee80211_ptr;
223 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); 222 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
223 struct cfg80211_bss *bss;
224 224
225 ASSERT_WDEV_LOCK(wdev); 225 ASSERT_WDEV_LOCK(wdev);
226 226
@@ -234,7 +234,10 @@ static void __cfg80211_sme_scan_done(struct net_device *dev)
234 wdev->conn->state != CFG80211_CONN_SCAN_AGAIN) 234 wdev->conn->state != CFG80211_CONN_SCAN_AGAIN)
235 return; 235 return;
236 236
237 if (!cfg80211_get_conn_bss(wdev)) { 237 bss = cfg80211_get_conn_bss(wdev);
238 if (bss) {
239 cfg80211_put_bss(bss);
240 } else {
238 /* not found */ 241 /* not found */
239 if (wdev->conn->state == CFG80211_CONN_SCAN_AGAIN) 242 if (wdev->conn->state == CFG80211_CONN_SCAN_AGAIN)
240 schedule_work(&rdev->conn_work); 243 schedule_work(&rdev->conn_work);
@@ -670,6 +673,7 @@ int __cfg80211_connect(struct cfg80211_registered_device *rdev,
670{ 673{
671 struct wireless_dev *wdev = dev->ieee80211_ptr; 674 struct wireless_dev *wdev = dev->ieee80211_ptr;
672 struct ieee80211_channel *chan; 675 struct ieee80211_channel *chan;
676 struct cfg80211_bss *bss = NULL;
673 int err; 677 int err;
674 678
675 ASSERT_WDEV_LOCK(wdev); 679 ASSERT_WDEV_LOCK(wdev);
@@ -758,9 +762,8 @@ int __cfg80211_connect(struct cfg80211_registered_device *rdev,
758 wdev->conn->params.ssid = wdev->ssid; 762 wdev->conn->params.ssid = wdev->ssid;
759 wdev->conn->params.ssid_len = connect->ssid_len; 763 wdev->conn->params.ssid_len = connect->ssid_len;
760 764
761 /* don't care about result -- but fill bssid & channel */ 765 /* see if we have the bss already */
762 if (!wdev->conn->params.bssid || !wdev->conn->params.channel) 766 bss = cfg80211_get_conn_bss(wdev);
763 cfg80211_get_conn_bss(wdev);
764 767
765 wdev->sme_state = CFG80211_SME_CONNECTING; 768 wdev->sme_state = CFG80211_SME_CONNECTING;
766 wdev->connect_keys = connkeys; 769 wdev->connect_keys = connkeys;
@@ -770,10 +773,11 @@ int __cfg80211_connect(struct cfg80211_registered_device *rdev,
770 wdev->conn->prev_bssid_valid = true; 773 wdev->conn->prev_bssid_valid = true;
771 } 774 }
772 775
773 /* we're good if we have both BSSID and channel */ 776 /* we're good if we have a matching bss struct */
774 if (wdev->conn->params.bssid && wdev->conn->params.channel) { 777 if (bss) {
775 wdev->conn->state = CFG80211_CONN_AUTHENTICATE_NEXT; 778 wdev->conn->state = CFG80211_CONN_AUTHENTICATE_NEXT;
776 err = cfg80211_conn_do_work(wdev); 779 err = cfg80211_conn_do_work(wdev);
780 cfg80211_put_bss(bss);
777 } else { 781 } else {
778 /* otherwise we'll need to scan for the AP first */ 782 /* otherwise we'll need to scan for the AP first */
779 err = cfg80211_conn_scan(wdev); 783 err = cfg80211_conn_scan(wdev);
diff --git a/net/wireless/wext-compat.c b/net/wireless/wext-compat.c
index 429dd06a4ecc..561a45cf2a6a 100644
--- a/net/wireless/wext-compat.c
+++ b/net/wireless/wext-compat.c
@@ -834,7 +834,7 @@ int cfg80211_wext_siwtxpower(struct net_device *dev,
834 return 0; 834 return 0;
835 } 835 }
836 836
837 return rdev->ops->set_tx_power(wdev->wiphy, type, dbm);; 837 return rdev->ops->set_tx_power(wdev->wiphy, type, dbm);
838} 838}
839EXPORT_SYMBOL_GPL(cfg80211_wext_siwtxpower); 839EXPORT_SYMBOL_GPL(cfg80211_wext_siwtxpower);
840 840
diff --git a/net/wireless/wext-sme.c b/net/wireless/wext-sme.c
index d16cd9ea4d00..5615a8802536 100644
--- a/net/wireless/wext-sme.c
+++ b/net/wireless/wext-sme.c
@@ -26,11 +26,12 @@ int cfg80211_mgd_wext_connect(struct cfg80211_registered_device *rdev,
26 26
27 wdev->wext.connect.ie = wdev->wext.ie; 27 wdev->wext.connect.ie = wdev->wext.ie;
28 wdev->wext.connect.ie_len = wdev->wext.ie_len; 28 wdev->wext.connect.ie_len = wdev->wext.ie_len;
29 wdev->wext.connect.privacy = wdev->wext.default_key != -1;
30 29
31 if (wdev->wext.keys) { 30 if (wdev->wext.keys) {
32 wdev->wext.keys->def = wdev->wext.default_key; 31 wdev->wext.keys->def = wdev->wext.default_key;
33 wdev->wext.keys->defmgmt = wdev->wext.default_mgmt_key; 32 wdev->wext.keys->defmgmt = wdev->wext.default_mgmt_key;
33 if (wdev->wext.default_key != -1)
34 wdev->wext.connect.privacy = true;
34 } 35 }
35 36
36 if (!wdev->wext.connect.ssid_len) 37 if (!wdev->wext.connect.ssid_len)
@@ -229,8 +230,7 @@ int cfg80211_mgd_wext_giwessid(struct net_device *dev,
229 data->flags = 1; 230 data->flags = 1;
230 data->length = wdev->wext.connect.ssid_len; 231 data->length = wdev->wext.connect.ssid_len;
231 memcpy(ssid, wdev->wext.connect.ssid, data->length); 232 memcpy(ssid, wdev->wext.connect.ssid, data->length);
232 } else 233 }
233 data->flags = 0;
234 wdev_unlock(wdev); 234 wdev_unlock(wdev);
235 235
236 return 0; 236 return 0;
@@ -306,8 +306,6 @@ int cfg80211_mgd_wext_giwap(struct net_device *dev,
306 wdev_lock(wdev); 306 wdev_lock(wdev);
307 if (wdev->current_bss) 307 if (wdev->current_bss)
308 memcpy(ap_addr->sa_data, wdev->current_bss->pub.bssid, ETH_ALEN); 308 memcpy(ap_addr->sa_data, wdev->current_bss->pub.bssid, ETH_ALEN);
309 else if (wdev->wext.connect.bssid)
310 memcpy(ap_addr->sa_data, wdev->wext.connect.bssid, ETH_ALEN);
311 else 309 else
312 memset(ap_addr->sa_data, 0, ETH_ALEN); 310 memset(ap_addr->sa_data, 0, ETH_ALEN);
313 wdev_unlock(wdev); 311 wdev_unlock(wdev);
diff --git a/net/wireless/wext.c b/net/wireless/wext.c
index 5b4a0cee4418..60fe57761ca9 100644
--- a/net/wireless/wext.c
+++ b/net/wireless/wext.c
@@ -470,7 +470,7 @@ static iw_handler get_handler(struct net_device *dev, unsigned int cmd)
470/* 470/*
471 * Get statistics out of the driver 471 * Get statistics out of the driver
472 */ 472 */
473static struct iw_statistics *get_wireless_stats(struct net_device *dev) 473struct iw_statistics *get_wireless_stats(struct net_device *dev)
474{ 474{
475 /* New location */ 475 /* New location */
476 if ((dev->wireless_handlers != NULL) && 476 if ((dev->wireless_handlers != NULL) &&
@@ -773,10 +773,13 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
773 essid_compat = 1; 773 essid_compat = 1;
774 else if (IW_IS_SET(cmd) && (iwp->length != 0)) { 774 else if (IW_IS_SET(cmd) && (iwp->length != 0)) {
775 char essid[IW_ESSID_MAX_SIZE + 1]; 775 char essid[IW_ESSID_MAX_SIZE + 1];
776 unsigned int len;
777 len = iwp->length * descr->token_size;
776 778
777 err = copy_from_user(essid, iwp->pointer, 779 if (len > IW_ESSID_MAX_SIZE)
778 iwp->length * 780 return -EFAULT;
779 descr->token_size); 781
782 err = copy_from_user(essid, iwp->pointer, len);
780 if (err) 783 if (err)
781 return -EFAULT; 784 return -EFAULT;
782 785
diff --git a/net/x25/af_x25.c b/net/x25/af_x25.c
index 5e6c072c64d3..7fa9c7ad3d3b 100644
--- a/net/x25/af_x25.c
+++ b/net/x25/af_x25.c
@@ -409,7 +409,7 @@ static void x25_destroy_socket(struct sock *sk)
409 */ 409 */
410 410
411static int x25_setsockopt(struct socket *sock, int level, int optname, 411static int x25_setsockopt(struct socket *sock, int level, int optname,
412 char __user *optval, int optlen) 412 char __user *optval, unsigned int optlen)
413{ 413{
414 int opt; 414 int opt;
415 struct sock *sk = sock->sk; 415 struct sock *sk = sock->sk;