aboutsummaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2008-12-28 15:49:40 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2008-12-28 15:49:40 -0500
commit0191b625ca5a46206d2fb862bb08f36f2fcb3b31 (patch)
tree454d1842b1833d976da62abcbd5c47521ebe9bd7 /net
parent54a696bd07c14d3b1192d03ce7269bc59b45209a (diff)
parenteb56092fc168bf5af199d47af50c0d84a96db898 (diff)
Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next-2.6
* git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next-2.6: (1429 commits) net: Allow dependancies of FDDI & Tokenring to be modular. igb: Fix build warning when DCA is disabled. net: Fix warning fallout from recent NAPI interface changes. gro: Fix potential use after free sfc: If AN is enabled, always read speed/duplex from the AN advertising bits sfc: When disabling the NIC, close the device rather than unregistering it sfc: SFT9001: Add cable diagnostics sfc: Add support for multiple PHY self-tests sfc: Merge top-level functions for self-tests sfc: Clean up PHY mode management in loopback self-test sfc: Fix unreliable link detection in some loopback modes sfc: Generate unique names for per-NIC workqueues 802.3ad: use standard ethhdr instead of ad_header 802.3ad: generalize out mac address initializer 802.3ad: initialize ports LACPDU from const initializer 802.3ad: remove typedef around ad_system 802.3ad: turn ports is_individual into a bool 802.3ad: turn ports is_enabled into a bool 802.3ad: make ntt bool ixgbe: Fix set_ringparam in ixgbe to use the same memory pools. ... Fixed trivial IPv4/6 address printing conflicts in fs/cifs/connect.c due to the conversion to %pI (in this networking merge) and the addition of doing IPv6 addresses (from the earlier merge of CIFS).
Diffstat (limited to 'net')
-rw-r--r--net/802/fddi.c8
-rw-r--r--net/802/hippi.c14
-rw-r--r--net/802/tr.c24
-rw-r--r--net/8021q/vlan.c26
-rw-r--r--net/8021q/vlan.h6
-rw-r--r--net/8021q/vlan_core.c2
-rw-r--r--net/8021q/vlan_dev.c76
-rw-r--r--net/9p/trans_rdma.c2
-rw-r--r--net/Kconfig7
-rw-r--r--net/Makefile4
-rw-r--r--net/appletalk/aarp.c3
-rw-r--r--net/appletalk/ddp.c5
-rw-r--r--net/appletalk/sysctl_net_atalk.c14
-rw-r--r--net/atm/atm_sysfs.c2
-rw-r--r--net/atm/br2684.c7
-rw-r--r--net/atm/clip.c4
-rw-r--r--net/atm/common.h1
-rw-r--r--net/atm/ioctl.c49
-rw-r--r--net/atm/lec.c60
-rw-r--r--net/atm/mpc.c40
-rw-r--r--net/atm/mpoa_caches.c18
-rw-r--r--net/atm/pvc.c3
-rw-r--r--net/atm/resources.c88
-rw-r--r--net/atm/resources.h2
-rw-r--r--net/atm/svc.c19
-rw-r--r--net/ax25/ax25_in.c41
-rw-r--r--net/ax25/sysctl_net_ax25.c58
-rw-r--r--net/bluetooth/af_bluetooth.c50
-rw-r--r--net/bluetooth/bnep/bnep.h2
-rw-r--r--net/bluetooth/bnep/core.c8
-rw-r--r--net/bluetooth/bnep/netdev.c11
-rw-r--r--net/bluetooth/bnep/sock.c5
-rw-r--r--net/bluetooth/cmtp/capi.c5
-rw-r--r--net/bluetooth/cmtp/core.c5
-rw-r--r--net/bluetooth/cmtp/sock.c5
-rw-r--r--net/bluetooth/hci_conn.c5
-rw-r--r--net/bluetooth/hci_core.c11
-rw-r--r--net/bluetooth/hci_event.c5
-rw-r--r--net/bluetooth/hci_sock.c5
-rw-r--r--net/bluetooth/hci_sysfs.c12
-rw-r--r--net/bluetooth/hidp/core.c5
-rw-r--r--net/bluetooth/hidp/sock.c5
-rw-r--r--net/bluetooth/l2cap.c5
-rw-r--r--net/bluetooth/rfcomm/core.c5
-rw-r--r--net/bluetooth/rfcomm/sock.c9
-rw-r--r--net/bluetooth/rfcomm/tty.c48
-rw-r--r--net/bluetooth/sco.c5
-rw-r--r--net/bridge/br_device.c20
-rw-r--r--net/bridge/br_if.c4
-rw-r--r--net/bridge/br_netfilter.c13
-rw-r--r--net/bridge/br_sysfs_br.c2
-rw-r--r--net/bridge/netfilter/ebt_log.c18
-rw-r--r--net/bridge/netfilter/ebtable_broute.c26
-rw-r--r--net/bridge/netfilter/ebtable_filter.c41
-rw-r--r--net/bridge/netfilter/ebtable_nat.c38
-rw-r--r--net/bridge/netfilter/ebtables.c52
-rw-r--r--net/can/raw.c22
-rw-r--r--net/core/datagram.c5
-rw-r--r--net/core/dev.c458
-rw-r--r--net/core/dst.c6
-rw-r--r--net/core/ethtool.c53
-rw-r--r--net/core/fib_rules.c7
-rw-r--r--net/core/filter.c19
-rw-r--r--net/core/flow.c6
-rw-r--r--net/core/gen_estimator.c97
-rw-r--r--net/core/neighbour.c73
-rw-r--r--net/core/net-sysfs.c15
-rw-r--r--net/core/net_namespace.c2
-rw-r--r--net/core/netpoll.c20
-rw-r--r--net/core/pktgen.c42
-rw-r--r--net/core/rtnetlink.c15
-rw-r--r--net/core/skbuff.c277
-rw-r--r--net/core/sock.c46
-rw-r--r--net/core/sysctl_net_core.c68
-rw-r--r--net/dcb/Kconfig22
-rw-r--r--net/dcb/Makefile1
-rw-r--r--net/dcb/dcbnl.c1122
-rw-r--r--net/dccp/ackvec.c9
-rw-r--r--net/dccp/ackvec.h5
-rw-r--r--net/dccp/ccid.c62
-rw-r--r--net/dccp/ccid.h26
-rw-r--r--net/dccp/ccids/ccid2.c6
-rw-r--r--net/dccp/dccp.h17
-rw-r--r--net/dccp/diag.c11
-rw-r--r--net/dccp/feat.c1458
-rw-r--r--net/dccp/feat.h130
-rw-r--r--net/dccp/input.c44
-rw-r--r--net/dccp/ipv4.c13
-rw-r--r--net/dccp/ipv6.c15
-rw-r--r--net/dccp/minisocks.c54
-rw-r--r--net/dccp/options.c229
-rw-r--r--net/dccp/output.c19
-rw-r--r--net/dccp/probe.c19
-rw-r--r--net/dccp/proto.c224
-rw-r--r--net/dccp/sysctl.c21
-rw-r--r--net/dccp/timer.c12
-rw-r--r--net/decnet/af_decnet.c62
-rw-r--r--net/decnet/dn_dev.c22
-rw-r--r--net/decnet/dn_neigh.c18
-rw-r--r--net/decnet/dn_nsp_in.c28
-rw-r--r--net/decnet/dn_nsp_out.c23
-rw-r--r--net/decnet/dn_route.c29
-rw-r--r--net/decnet/dn_table.c2
-rw-r--r--net/decnet/sysctl_net_decnet.c48
-rw-r--r--net/dsa/mv88e6060.c6
-rw-r--r--net/dsa/mv88e6123_61_65.c4
-rw-r--r--net/dsa/mv88e6131.c4
-rw-r--r--net/dsa/mv88e6xxx.c2
-rw-r--r--net/dsa/slave.c2
-rw-r--r--net/dsa/tag_dsa.c1
-rw-r--r--net/dsa/tag_edsa.c1
-rw-r--r--net/dsa/tag_trailer.c1
-rw-r--r--net/ethernet/eth.c19
-rw-r--r--net/ieee80211/Kconfig73
-rw-r--r--net/ieee80211/Makefile12
-rw-r--r--net/ieee80211/ieee80211_crypt.c206
-rw-r--r--net/ieee80211/ieee80211_geo.c195
-rw-r--r--net/ieee80211/ieee80211_module.c338
-rw-r--r--net/ieee80211/ieee80211_rx.c1831
-rw-r--r--net/ieee80211/ieee80211_tx.c545
-rw-r--r--net/ieee80211/ieee80211_wx.c760
-rw-r--r--net/ipv4/af_inet.c116
-rw-r--r--net/ipv4/ah4.c10
-rw-r--r--net/ipv4/arp.c36
-rw-r--r--net/ipv4/cipso_ipv4.c1
-rw-r--r--net/ipv4/devinet.c19
-rw-r--r--net/ipv4/esp4.c8
-rw-r--r--net/ipv4/fib_frontend.c10
-rw-r--r--net/ipv4/fib_hash.c12
-rw-r--r--net/ipv4/fib_semantics.c8
-rw-r--r--net/ipv4/fib_trie.c6
-rw-r--r--net/ipv4/icmp.c39
-rw-r--r--net/ipv4/igmp.c95
-rw-r--r--net/ipv4/inet_connection_sock.c31
-rw-r--r--net/ipv4/inet_diag.c31
-rw-r--r--net/ipv4/inet_hashtables.c277
-rw-r--r--net/ipv4/inet_lro.c4
-rw-r--r--net/ipv4/inet_timewait_sock.c48
-rw-r--r--net/ipv4/inetpeer.c2
-rw-r--r--net/ipv4/ip_forward.c2
-rw-r--r--net/ipv4/ip_fragment.c21
-rw-r--r--net/ipv4/ip_gre.c58
-rw-r--r--net/ipv4/ip_input.c10
-rw-r--r--net/ipv4/ip_output.c24
-rw-r--r--net/ipv4/ip_sockglue.c72
-rw-r--r--net/ipv4/ipcomp.c10
-rw-r--r--net/ipv4/ipconfig.c40
-rw-r--r--net/ipv4/ipip.c37
-rw-r--r--net/ipv4/ipmr.c280
-rw-r--r--net/ipv4/netfilter.c7
-rw-r--r--net/ipv4/netfilter/arp_tables.c16
-rw-r--r--net/ipv4/netfilter/arptable_filter.c12
-rw-r--r--net/ipv4/netfilter/ip_tables.c12
-rw-r--r--net/ipv4/netfilter/ipt_CLUSTERIP.c9
-rw-r--r--net/ipv4/netfilter/ipt_LOG.c7
-rw-r--r--net/ipv4/netfilter/ipt_addrtype.c16
-rw-r--r--net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c27
-rw-r--r--net/ipv4/netfilter/nf_conntrack_proto_icmp.c4
-rw-r--r--net/ipv4/netfilter/nf_nat_h323.c58
-rw-r--r--net/ipv4/netfilter/nf_nat_irc.c4
-rw-r--r--net/ipv4/netfilter/nf_nat_rule.c27
-rw-r--r--net/ipv4/netfilter/nf_nat_sip.c18
-rw-r--r--net/ipv4/netfilter/nf_nat_snmp_basic.c9
-rw-r--r--net/ipv4/proc.c8
-rw-r--r--net/ipv4/raw.c10
-rw-r--r--net/ipv4/route.c227
-rw-r--r--net/ipv4/sysctl_net_ipv4.c188
-rw-r--r--net/ipv4/tcp.c130
-rw-r--r--net/ipv4/tcp_cubic.c120
-rw-r--r--net/ipv4/tcp_diag.c2
-rw-r--r--net/ipv4/tcp_input.c511
-rw-r--r--net/ipv4/tcp_ipv4.c137
-rw-r--r--net/ipv4/tcp_minisocks.c2
-rw-r--r--net/ipv4/tcp_output.c219
-rw-r--r--net/ipv4/tcp_probe.c7
-rw-r--r--net/ipv4/tcp_timer.c14
-rw-r--r--net/ipv4/tcp_yeah.c4
-rw-r--r--net/ipv4/udp.c271
-rw-r--r--net/ipv4/udp_impl.h4
-rw-r--r--net/ipv4/udplite.c14
-rw-r--r--net/ipv4/xfrm4_input.c4
-rw-r--r--net/ipv4/xfrm4_policy.c15
-rw-r--r--net/ipv4/xfrm4_state.c2
-rw-r--r--net/ipv6/addrconf.c80
-rw-r--r--net/ipv6/addrlabel.c34
-rw-r--r--net/ipv6/af_inet6.c2
-rw-r--r--net/ipv6/ah6.c9
-rw-r--r--net/ipv6/anycast.c6
-rw-r--r--net/ipv6/datagram.c3
-rw-r--r--net/ipv6/esp6.c7
-rw-r--r--net/ipv6/exthdrs.c2
-rw-r--r--net/ipv6/icmp.c21
-rw-r--r--net/ipv6/inet6_connection_sock.c2
-rw-r--r--net/ipv6/inet6_hashtables.c182
-rw-r--r--net/ipv6/ip6_flowlabel.c6
-rw-r--r--net/ipv6/ip6_output.c5
-rw-r--r--net/ipv6/ip6_tunnel.c37
-rw-r--r--net/ipv6/ip6mr.c490
-rw-r--r--net/ipv6/ipcomp6.c10
-rw-r--r--net/ipv6/ipv6_sockglue.c34
-rw-r--r--net/ipv6/mcast.c41
-rw-r--r--net/ipv6/mip6.c3
-rw-r--r--net/ipv6/ndisc.c105
-rw-r--r--net/ipv6/netfilter.c7
-rw-r--r--net/ipv6/netfilter/ip6t_LOG.c7
-rw-r--r--net/ipv6/netfilter/ip6t_REJECT.c2
-rw-r--r--net/ipv6/netfilter/ip6table_filter.c17
-rw-r--r--net/ipv6/netfilter/nf_conntrack_l3proto_ipv6.c5
-rw-r--r--net/ipv6/netfilter/nf_conntrack_proto_icmpv6.c2
-rw-r--r--net/ipv6/netfilter/nf_conntrack_reasm.c6
-rw-r--r--net/ipv6/raw.c3
-rw-r--r--net/ipv6/reassembly.c12
-rw-r--r--net/ipv6/route.c47
-rw-r--r--net/ipv6/sit.c35
-rw-r--r--net/ipv6/syncookies.c2
-rw-r--r--net/ipv6/sysctl_net_ipv6.c4
-rw-r--r--net/ipv6/tcp_ipv6.c28
-rw-r--r--net/ipv6/udp.c151
-rw-r--r--net/ipv6/udp_impl.h4
-rw-r--r--net/ipv6/udplite.c9
-rw-r--r--net/ipv6/xfrm6_input.c9
-rw-r--r--net/ipv6/xfrm6_policy.c22
-rw-r--r--net/ipv6/xfrm6_state.c2
-rw-r--r--net/ipv6/xfrm6_tunnel.c33
-rw-r--r--net/ipx/sysctl_net_ipx.c2
-rw-r--r--net/irda/irlan/irlan_client.c4
-rw-r--r--net/irda/irlan/irlan_common.c2
-rw-r--r--net/irda/irlap_frame.c17
-rw-r--r--net/irda/irsysctl.c50
-rw-r--r--net/irda/irttp.c14
-rw-r--r--net/irda/timer.c2
-rw-r--r--net/key/af_key.c217
-rw-r--r--net/llc/af_llc.c1
-rw-r--r--net/llc/llc_proc.c3
-rw-r--r--net/llc/sysctl_net_llc.c20
-rw-r--r--net/mac80211/Kconfig8
-rw-r--r--net/mac80211/Makefile2
-rw-r--r--net/mac80211/cfg.c194
-rw-r--r--net/mac80211/debugfs.c12
-rw-r--r--net/mac80211/debugfs_key.c4
-rw-r--r--net/mac80211/debugfs_netdev.c117
-rw-r--r--net/mac80211/debugfs_sta.c84
-rw-r--r--net/mac80211/event.c5
-rw-r--r--net/mac80211/ht.c265
-rw-r--r--net/mac80211/ieee80211_i.h90
-rw-r--r--net/mac80211/iface.c54
-rw-r--r--net/mac80211/key.c10
-rw-r--r--net/mac80211/main.c284
-rw-r--r--net/mac80211/mesh.c4
-rw-r--r--net/mac80211/mesh.h5
-rw-r--r--net/mac80211/mesh_hwmp.c7
-rw-r--r--net/mac80211/mesh_plink.c49
-rw-r--r--net/mac80211/mlme.c606
-rw-r--r--net/mac80211/rate.c52
-rw-r--r--net/mac80211/rate.h11
-rw-r--r--net/mac80211/rc80211_minstrel.c109
-rw-r--r--net/mac80211/rc80211_minstrel.h2
-rw-r--r--net/mac80211/rc80211_pid.h3
-rw-r--r--net/mac80211/rc80211_pid_algo.c38
-rw-r--r--net/mac80211/rc80211_pid_debugfs.c5
-rw-r--r--net/mac80211/rx.c174
-rw-r--r--net/mac80211/scan.c24
-rw-r--r--net/mac80211/sta_info.c37
-rw-r--r--net/mac80211/sta_info.h45
-rw-r--r--net/mac80211/tkip.c10
-rw-r--r--net/mac80211/tx.c462
-rw-r--r--net/mac80211/util.c107
-rw-r--r--net/mac80211/wep.c33
-rw-r--r--net/mac80211/wep.h2
-rw-r--r--net/mac80211/wext.c257
-rw-r--r--net/mac80211/wme.c32
-rw-r--r--net/mac80211/wpa.c32
-rw-r--r--net/netfilter/Kconfig5
-rw-r--r--net/netfilter/ipvs/ip_vs_conn.c20
-rw-r--r--net/netfilter/ipvs/ip_vs_core.c20
-rw-r--r--net/netfilter/ipvs/ip_vs_ctl.c82
-rw-r--r--net/netfilter/ipvs/ip_vs_dh.c34
-rw-r--r--net/netfilter/ipvs/ip_vs_ftp.c13
-rw-r--r--net/netfilter/ipvs/ip_vs_lblc.c69
-rw-r--r--net/netfilter/ipvs/ip_vs_lblcr.c96
-rw-r--r--net/netfilter/ipvs/ip_vs_lc.c3
-rw-r--r--net/netfilter/ipvs/ip_vs_nq.c3
-rw-r--r--net/netfilter/ipvs/ip_vs_proto.c38
-rw-r--r--net/netfilter/ipvs/ip_vs_proto_ah_esp.c10
-rw-r--r--net/netfilter/ipvs/ip_vs_proto_tcp.c8
-rw-r--r--net/netfilter/ipvs/ip_vs_proto_udp.c8
-rw-r--r--net/netfilter/ipvs/ip_vs_rr.c3
-rw-r--r--net/netfilter/ipvs/ip_vs_sed.c3
-rw-r--r--net/netfilter/ipvs/ip_vs_sh.c34
-rw-r--r--net/netfilter/ipvs/ip_vs_sync.c4
-rw-r--r--net/netfilter/ipvs/ip_vs_wlc.c3
-rw-r--r--net/netfilter/ipvs/ip_vs_wrr.c3
-rw-r--r--net/netfilter/ipvs/ip_vs_xmit.c34
-rw-r--r--net/netfilter/nf_conntrack_acct.c2
-rw-r--r--net/netfilter/nf_conntrack_amanda.c1
-rw-r--r--net/netfilter/nf_conntrack_core.c61
-rw-r--r--net/netfilter/nf_conntrack_ecache.c14
-rw-r--r--net/netfilter/nf_conntrack_expect.c43
-rw-r--r--net/netfilter/nf_conntrack_ftp.c24
-rw-r--r--net/netfilter/nf_conntrack_h323_main.c13
-rw-r--r--net/netfilter/nf_conntrack_helper.c32
-rw-r--r--net/netfilter/nf_conntrack_irc.c14
-rw-r--r--net/netfilter/nf_conntrack_netbios_ns.c1
-rw-r--r--net/netfilter/nf_conntrack_netlink.c201
-rw-r--r--net/netfilter/nf_conntrack_pptp.c1
-rw-r--r--net/netfilter/nf_conntrack_proto_generic.c4
-rw-r--r--net/netfilter/nf_conntrack_proto_gre.c2
-rw-r--r--net/netfilter/nf_conntrack_proto_sctp.c30
-rw-r--r--net/netfilter/nf_conntrack_proto_tcp.c50
-rw-r--r--net/netfilter/nf_conntrack_proto_udp.c8
-rw-r--r--net/netfilter/nf_conntrack_proto_udplite.c4
-rw-r--r--net/netfilter/nf_conntrack_sane.c1
-rw-r--r--net/netfilter/nf_conntrack_sip.c1
-rw-r--r--net/netfilter/nf_conntrack_standalone.c16
-rw-r--r--net/netfilter/nf_conntrack_tftp.c1
-rw-r--r--net/netfilter/nfnetlink_log.c4
-rw-r--r--net/netfilter/xt_NFLOG.c5
-rw-r--r--net/netfilter/xt_dccp.c16
-rw-r--r--net/netfilter/xt_hashlimit.c14
-rw-r--r--net/netfilter/xt_iprange.c36
-rw-r--r--net/netfilter/xt_recent.c32
-rw-r--r--net/netlabel/netlabel_addrlist.c4
-rw-r--r--net/netlabel/netlabel_mgmt.c1
-rw-r--r--net/netlink/af_netlink.c7
-rw-r--r--net/netlink/attr.c8
-rw-r--r--net/netrom/sysctl_net_netrom.c48
-rw-r--r--net/packet/af_packet.c2
-rw-r--r--net/phonet/af_phonet.c8
-rw-r--r--net/phonet/pep-gprs.c218
-rw-r--r--net/phonet/pep.c38
-rw-r--r--net/phonet/pn_dev.c6
-rw-r--r--net/phonet/socket.c13
-rw-r--r--net/phonet/sysctl.c4
-rw-r--r--net/rfkill/rfkill-input.c337
-rw-r--r--net/rfkill/rfkill-input.h3
-rw-r--r--net/rfkill/rfkill.c183
-rw-r--r--net/rose/sysctl_net_rose.c40
-rw-r--r--net/rxrpc/af_rxrpc.c4
-rw-r--r--net/rxrpc/ar-connection.c2
-rw-r--r--net/rxrpc/ar-connevent.c2
-rw-r--r--net/rxrpc/ar-error.c3
-rw-r--r--net/rxrpc/ar-local.c16
-rw-r--r--net/rxrpc/ar-peer.c8
-rw-r--r--net/rxrpc/ar-proc.c16
-rw-r--r--net/rxrpc/ar-security.c2
-rw-r--r--net/rxrpc/ar-transport.c12
-rw-r--r--net/rxrpc/rxkad.c2
-rw-r--r--net/sched/Kconfig22
-rw-r--r--net/sched/Makefile2
-rw-r--r--net/sched/act_api.c18
-rw-r--r--net/sched/act_gact.c4
-rw-r--r--net/sched/act_ipt.c4
-rw-r--r--net/sched/act_mirred.c4
-rw-r--r--net/sched/act_nat.c4
-rw-r--r--net/sched/act_pedit.c4
-rw-r--r--net/sched/act_police.c33
-rw-r--r--net/sched/act_simple.c4
-rw-r--r--net/sched/act_skbedit.c4
-rw-r--r--net/sched/cls_api.c3
-rw-r--r--net/sched/cls_basic.c2
-rw-r--r--net/sched/cls_cgroup.c288
-rw-r--r--net/sched/cls_fw.c2
-rw-r--r--net/sched/cls_route.c2
-rw-r--r--net/sched/cls_tcindex.c6
-rw-r--r--net/sched/cls_u32.c11
-rw-r--r--net/sched/ematch.c18
-rw-r--r--net/sched/sch_api.c50
-rw-r--r--net/sched/sch_atm.c36
-rw-r--r--net/sched/sch_blackhole.c1
-rw-r--r--net/sched/sch_cbq.c76
-rw-r--r--net/sched/sch_drr.c519
-rw-r--r--net/sched/sch_dsmark.c22
-rw-r--r--net/sched/sch_fifo.c4
-rw-r--r--net/sched/sch_generic.c40
-rw-r--r--net/sched/sch_gred.c22
-rw-r--r--net/sched/sch_hfsc.c64
-rw-r--r--net/sched/sch_htb.c171
-rw-r--r--net/sched/sch_multiq.c82
-rw-r--r--net/sched/sch_netem.c160
-rw-r--r--net/sched/sch_prio.c50
-rw-r--r--net/sched/sch_red.c33
-rw-r--r--net/sched/sch_sfq.c71
-rw-r--r--net/sched/sch_tbf.c44
-rw-r--r--net/sched/sch_teql.c19
-rw-r--r--net/sctp/ipv6.c35
-rw-r--r--net/sctp/protocol.c29
-rw-r--r--net/sctp/sm_statefuns.c24
-rw-r--r--net/sctp/socket.c206
-rw-r--r--net/sctp/sysctl.c82
-rw-r--r--net/socket.c1
-rw-r--r--net/sunrpc/clnt.c8
-rw-r--r--net/sunrpc/rpcb_clnt.c17
-rw-r--r--net/sunrpc/svcauth_unix.c24
-rw-r--r--net/sunrpc/svcsock.c6
-rw-r--r--net/sunrpc/xprtrdma/svc_rdma_recvfrom.c4
-rw-r--r--net/sunrpc/xprtrdma/svc_rdma_sendto.c2
-rw-r--r--net/sunrpc/xprtrdma/svc_rdma_transport.c16
-rw-r--r--net/sunrpc/xprtrdma/transport.c14
-rw-r--r--net/sunrpc/xprtrdma/verbs.c16
-rw-r--r--net/sunrpc/xprtsock.c41
-rw-r--r--net/tipc/eth_media.c3
-rw-r--r--net/tipc/name_table.c2
-rw-r--r--net/unix/af_unix.c200
-rw-r--r--net/unix/garbage.c12
-rw-r--r--net/unix/sysctl_net_unix.c3
-rw-r--r--net/wanrouter/wanmain.c36
-rw-r--r--net/wireless/Kconfig30
-rw-r--r--net/wireless/Makefile7
-rw-r--r--net/wireless/core.c14
-rw-r--r--net/wireless/core.h13
-rw-r--r--net/wireless/lib80211.c284
-rw-r--r--net/wireless/lib80211_crypt_ccmp.c (renamed from net/ieee80211/ieee80211_crypt_ccmp.c)129
-rw-r--r--net/wireless/lib80211_crypt_tkip.c (renamed from net/ieee80211/ieee80211_crypt_tkip.c)181
-rw-r--r--net/wireless/lib80211_crypt_wep.c (renamed from net/ieee80211/ieee80211_crypt_wep.c)79
-rw-r--r--net/wireless/nl80211.c417
-rw-r--r--net/wireless/reg.c1005
-rw-r--r--net/wireless/reg.h33
-rw-r--r--net/wireless/sysfs.c25
-rw-r--r--net/wireless/util.c19
-rw-r--r--net/wireless/wext-compat.c139
-rw-r--r--net/wireless/wext.c2
-rw-r--r--net/x25/sysctl_net_x25.c22
-rw-r--r--net/xfrm/Makefile4
-rw-r--r--net/xfrm/xfrm_input.c25
-rw-r--r--net/xfrm/xfrm_output.c18
-rw-r--r--net/xfrm/xfrm_policy.c511
-rw-r--r--net/xfrm/xfrm_proc.c26
-rw-r--r--net/xfrm/xfrm_state.c407
-rw-r--r--net/xfrm/xfrm_sysctl.c85
-rw-r--r--net/xfrm/xfrm_user.c249
430 files changed, 14763 insertions, 12217 deletions
diff --git a/net/802/fddi.c b/net/802/fddi.c
index 0549317b9356..f1611a1e06a7 100644
--- a/net/802/fddi.c
+++ b/net/802/fddi.c
@@ -167,23 +167,27 @@ __be16 fddi_type_trans(struct sk_buff *skb, struct net_device *dev)
167 167
168EXPORT_SYMBOL(fddi_type_trans); 168EXPORT_SYMBOL(fddi_type_trans);
169 169
170static int fddi_change_mtu(struct net_device *dev, int new_mtu) 170int fddi_change_mtu(struct net_device *dev, int new_mtu)
171{ 171{
172 if ((new_mtu < FDDI_K_SNAP_HLEN) || (new_mtu > FDDI_K_SNAP_DLEN)) 172 if ((new_mtu < FDDI_K_SNAP_HLEN) || (new_mtu > FDDI_K_SNAP_DLEN))
173 return(-EINVAL); 173 return(-EINVAL);
174 dev->mtu = new_mtu; 174 dev->mtu = new_mtu;
175 return(0); 175 return(0);
176} 176}
177EXPORT_SYMBOL(fddi_change_mtu);
177 178
178static const struct header_ops fddi_header_ops = { 179static const struct header_ops fddi_header_ops = {
179 .create = fddi_header, 180 .create = fddi_header,
180 .rebuild = fddi_rebuild_header, 181 .rebuild = fddi_rebuild_header,
181}; 182};
182 183
184
183static void fddi_setup(struct net_device *dev) 185static void fddi_setup(struct net_device *dev)
184{ 186{
185 dev->change_mtu = fddi_change_mtu;
186 dev->header_ops = &fddi_header_ops; 187 dev->header_ops = &fddi_header_ops;
188#ifdef CONFIG_COMPAT_NET_DEV_OPS
189 dev->change_mtu = fddi_change_mtu,
190#endif
187 191
188 dev->type = ARPHRD_FDDI; 192 dev->type = ARPHRD_FDDI;
189 dev->hard_header_len = FDDI_K_SNAP_HLEN+3; /* Assume 802.2 SNAP hdr len + 3 pad bytes */ 193 dev->hard_header_len = FDDI_K_SNAP_HLEN+3; /* Assume 802.2 SNAP hdr len + 3 pad bytes */
diff --git a/net/802/hippi.c b/net/802/hippi.c
index e35dc1e0915d..313b9ebf92ee 100644
--- a/net/802/hippi.c
+++ b/net/802/hippi.c
@@ -144,7 +144,7 @@ __be16 hippi_type_trans(struct sk_buff *skb, struct net_device *dev)
144 144
145EXPORT_SYMBOL(hippi_type_trans); 145EXPORT_SYMBOL(hippi_type_trans);
146 146
147static int hippi_change_mtu(struct net_device *dev, int new_mtu) 147int hippi_change_mtu(struct net_device *dev, int new_mtu)
148{ 148{
149 /* 149 /*
150 * HIPPI's got these nice large MTUs. 150 * HIPPI's got these nice large MTUs.
@@ -154,12 +154,13 @@ static int hippi_change_mtu(struct net_device *dev, int new_mtu)
154 dev->mtu = new_mtu; 154 dev->mtu = new_mtu;
155 return(0); 155 return(0);
156} 156}
157EXPORT_SYMBOL(hippi_change_mtu);
157 158
158/* 159/*
159 * For HIPPI we will actually use the lower 4 bytes of the hardware 160 * For HIPPI we will actually use the lower 4 bytes of the hardware
160 * address as the I-FIELD rather than the actual hardware address. 161 * address as the I-FIELD rather than the actual hardware address.
161 */ 162 */
162static int hippi_mac_addr(struct net_device *dev, void *p) 163int hippi_mac_addr(struct net_device *dev, void *p)
163{ 164{
164 struct sockaddr *addr = p; 165 struct sockaddr *addr = p;
165 if (netif_running(dev)) 166 if (netif_running(dev))
@@ -167,8 +168,9 @@ static int hippi_mac_addr(struct net_device *dev, void *p)
167 memcpy(dev->dev_addr, addr->sa_data, dev->addr_len); 168 memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
168 return 0; 169 return 0;
169} 170}
171EXPORT_SYMBOL(hippi_mac_addr);
170 172
171static int hippi_neigh_setup_dev(struct net_device *dev, struct neigh_parms *p) 173int hippi_neigh_setup_dev(struct net_device *dev, struct neigh_parms *p)
172{ 174{
173 /* Never send broadcast/multicast ARP messages */ 175 /* Never send broadcast/multicast ARP messages */
174 p->mcast_probes = 0; 176 p->mcast_probes = 0;
@@ -181,6 +183,7 @@ static int hippi_neigh_setup_dev(struct net_device *dev, struct neigh_parms *p)
181 p->ucast_probes = 0; 183 p->ucast_probes = 0;
182 return 0; 184 return 0;
183} 185}
186EXPORT_SYMBOL(hippi_neigh_setup_dev);
184 187
185static const struct header_ops hippi_header_ops = { 188static const struct header_ops hippi_header_ops = {
186 .create = hippi_header, 189 .create = hippi_header,
@@ -190,11 +193,12 @@ static const struct header_ops hippi_header_ops = {
190 193
191static void hippi_setup(struct net_device *dev) 194static void hippi_setup(struct net_device *dev)
192{ 195{
193 dev->set_multicast_list = NULL; 196#ifdef CONFIG_COMPAT_NET_DEV_OPS
194 dev->change_mtu = hippi_change_mtu; 197 dev->change_mtu = hippi_change_mtu;
195 dev->header_ops = &hippi_header_ops;
196 dev->set_mac_address = hippi_mac_addr; 198 dev->set_mac_address = hippi_mac_addr;
197 dev->neigh_setup = hippi_neigh_setup_dev; 199 dev->neigh_setup = hippi_neigh_setup_dev;
200#endif
201 dev->header_ops = &hippi_header_ops;
198 202
199 /* 203 /*
200 * We don't support HIPPI `ARP' for the time being, and probably 204 * We don't support HIPPI `ARP' for the time being, and probably
diff --git a/net/802/tr.c b/net/802/tr.c
index 18c66475d8c3..158150fee462 100644
--- a/net/802/tr.c
+++ b/net/802/tr.c
@@ -285,10 +285,7 @@ void tr_source_route(struct sk_buff *skb,struct trh_hdr *trh,
285 if(entry) 285 if(entry)
286 { 286 {
287#if TR_SR_DEBUG 287#if TR_SR_DEBUG
288{ 288printk("source routing for %pM\n", trh->daddr);
289DECLARE_MAC_BUF(mac);
290printk("source routing for %s\n",print_mac(mac, trh->daddr));
291}
292#endif 289#endif
293 if(!entry->local_ring && (ntohs(entry->rcf) & TR_RCF_LEN_MASK) >> 8) 290 if(!entry->local_ring && (ntohs(entry->rcf) & TR_RCF_LEN_MASK) >> 8)
294 { 291 {
@@ -370,9 +367,8 @@ static void tr_add_rif_info(struct trh_hdr *trh, struct net_device *dev)
370 if(entry==NULL) 367 if(entry==NULL)
371 { 368 {
372#if TR_SR_DEBUG 369#if TR_SR_DEBUG
373 DECLARE_MAC_BUF(mac); 370 printk("adding rif_entry: addr:%pM rcf:%04X\n",
374 printk("adding rif_entry: addr:%s rcf:%04X\n", 371 trh->saddr, ntohs(trh->rcf));
375 print_mac(mac, trh->saddr), ntohs(trh->rcf));
376#endif 372#endif
377 /* 373 /*
378 * Allocate our new entry. A failure to allocate loses 374 * Allocate our new entry. A failure to allocate loses
@@ -417,11 +413,8 @@ static void tr_add_rif_info(struct trh_hdr *trh, struct net_device *dev)
417 !(trh->rcf & htons(TR_RCF_BROADCAST_MASK))) 413 !(trh->rcf & htons(TR_RCF_BROADCAST_MASK)))
418 { 414 {
419#if TR_SR_DEBUG 415#if TR_SR_DEBUG
420{ 416printk("updating rif_entry: addr:%pM rcf:%04X\n",
421DECLARE_MAC_BUF(mac); 417 trh->saddr, ntohs(trh->rcf));
422printk("updating rif_entry: addr:%s rcf:%04X\n",
423 print_mac(mac, trh->saddr), ntohs(trh->rcf));
424}
425#endif 418#endif
426 entry->rcf = trh->rcf & htons((unsigned short)~TR_RCF_BROADCAST_MASK); 419 entry->rcf = trh->rcf & htons((unsigned short)~TR_RCF_BROADCAST_MASK);
427 memcpy(&(entry->rseg[0]),&(trh->rseg[0]),8*sizeof(unsigned short)); 420 memcpy(&(entry->rseg[0]),&(trh->rseg[0]),8*sizeof(unsigned short));
@@ -532,7 +525,6 @@ static int rif_seq_show(struct seq_file *seq, void *v)
532{ 525{
533 int j, rcf_len, segment, brdgnmb; 526 int j, rcf_len, segment, brdgnmb;
534 struct rif_cache *entry = v; 527 struct rif_cache *entry = v;
535 DECLARE_MAC_BUF(mac);
536 528
537 if (v == SEQ_START_TOKEN) 529 if (v == SEQ_START_TOKEN)
538 seq_puts(seq, 530 seq_puts(seq,
@@ -542,9 +534,9 @@ static int rif_seq_show(struct seq_file *seq, void *v)
542 long ttl = (long) (entry->last_used + sysctl_tr_rif_timeout) 534 long ttl = (long) (entry->last_used + sysctl_tr_rif_timeout)
543 - (long) jiffies; 535 - (long) jiffies;
544 536
545 seq_printf(seq, "%s %s %7li ", 537 seq_printf(seq, "%s %pM %7li ",
546 dev?dev->name:"?", 538 dev?dev->name:"?",
547 print_mac(mac, entry->addr), 539 entry->addr,
548 ttl/HZ); 540 ttl/HZ);
549 541
550 if (entry->local_ring) 542 if (entry->local_ring)
@@ -643,7 +635,7 @@ static struct ctl_table tr_table[] = {
643 .data = &sysctl_tr_rif_timeout, 635 .data = &sysctl_tr_rif_timeout,
644 .maxlen = sizeof(int), 636 .maxlen = sizeof(int),
645 .mode = 0644, 637 .mode = 0644,
646 .proc_handler = &proc_dointvec 638 .proc_handler = proc_dointvec
647 }, 639 },
648 { 0 }, 640 { 0 },
649}; 641};
diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
index f0e335aa20df..41e8f65bd3f0 100644
--- a/net/8021q/vlan.c
+++ b/net/8021q/vlan.c
@@ -46,10 +46,10 @@ int vlan_net_id;
46/* Our listing of VLAN group(s) */ 46/* Our listing of VLAN group(s) */
47static struct hlist_head vlan_group_hash[VLAN_GRP_HASH_SIZE]; 47static struct hlist_head vlan_group_hash[VLAN_GRP_HASH_SIZE];
48 48
49static char vlan_fullname[] = "802.1Q VLAN Support"; 49const char vlan_fullname[] = "802.1Q VLAN Support";
50static char vlan_version[] = DRV_VERSION; 50const char vlan_version[] = DRV_VERSION;
51static char vlan_copyright[] = "Ben Greear <greearb@candelatech.com>"; 51static const char vlan_copyright[] = "Ben Greear <greearb@candelatech.com>";
52static char vlan_buggyright[] = "David S. Miller <davem@redhat.com>"; 52static const char vlan_buggyright[] = "David S. Miller <davem@redhat.com>";
53 53
54static struct packet_type vlan_packet_type = { 54static struct packet_type vlan_packet_type = {
55 .type = __constant_htons(ETH_P_8021Q), 55 .type = __constant_htons(ETH_P_8021Q),
@@ -144,6 +144,7 @@ void unregister_vlan_dev(struct net_device *dev)
144{ 144{
145 struct vlan_dev_info *vlan = vlan_dev_info(dev); 145 struct vlan_dev_info *vlan = vlan_dev_info(dev);
146 struct net_device *real_dev = vlan->real_dev; 146 struct net_device *real_dev = vlan->real_dev;
147 const struct net_device_ops *ops = real_dev->netdev_ops;
147 struct vlan_group *grp; 148 struct vlan_group *grp;
148 u16 vlan_id = vlan->vlan_id; 149 u16 vlan_id = vlan->vlan_id;
149 150
@@ -156,7 +157,7 @@ void unregister_vlan_dev(struct net_device *dev)
156 * HW accelerating devices or SW vlan input packet processing. 157 * HW accelerating devices or SW vlan input packet processing.
157 */ 158 */
158 if (real_dev->features & NETIF_F_HW_VLAN_FILTER) 159 if (real_dev->features & NETIF_F_HW_VLAN_FILTER)
159 real_dev->vlan_rx_kill_vid(real_dev, vlan_id); 160 ops->ndo_vlan_rx_kill_vid(real_dev, vlan_id);
160 161
161 vlan_group_set_device(grp, vlan_id, NULL); 162 vlan_group_set_device(grp, vlan_id, NULL);
162 grp->nr_vlans--; 163 grp->nr_vlans--;
@@ -170,7 +171,7 @@ void unregister_vlan_dev(struct net_device *dev)
170 vlan_gvrp_uninit_applicant(real_dev); 171 vlan_gvrp_uninit_applicant(real_dev);
171 172
172 if (real_dev->features & NETIF_F_HW_VLAN_RX) 173 if (real_dev->features & NETIF_F_HW_VLAN_RX)
173 real_dev->vlan_rx_register(real_dev, NULL); 174 ops->ndo_vlan_rx_register(real_dev, NULL);
174 175
175 hlist_del_rcu(&grp->hlist); 176 hlist_del_rcu(&grp->hlist);
176 177
@@ -205,21 +206,21 @@ static void vlan_transfer_operstate(const struct net_device *dev,
205 206
206int vlan_check_real_dev(struct net_device *real_dev, u16 vlan_id) 207int vlan_check_real_dev(struct net_device *real_dev, u16 vlan_id)
207{ 208{
208 char *name = real_dev->name; 209 const char *name = real_dev->name;
210 const struct net_device_ops *ops = real_dev->netdev_ops;
209 211
210 if (real_dev->features & NETIF_F_VLAN_CHALLENGED) { 212 if (real_dev->features & NETIF_F_VLAN_CHALLENGED) {
211 pr_info("8021q: VLANs not supported on %s\n", name); 213 pr_info("8021q: VLANs not supported on %s\n", name);
212 return -EOPNOTSUPP; 214 return -EOPNOTSUPP;
213 } 215 }
214 216
215 if ((real_dev->features & NETIF_F_HW_VLAN_RX) && 217 if ((real_dev->features & NETIF_F_HW_VLAN_RX) && !ops->ndo_vlan_rx_register) {
216 !real_dev->vlan_rx_register) {
217 pr_info("8021q: device %s has buggy VLAN hw accel\n", name); 218 pr_info("8021q: device %s has buggy VLAN hw accel\n", name);
218 return -EOPNOTSUPP; 219 return -EOPNOTSUPP;
219 } 220 }
220 221
221 if ((real_dev->features & NETIF_F_HW_VLAN_FILTER) && 222 if ((real_dev->features & NETIF_F_HW_VLAN_FILTER) &&
222 (!real_dev->vlan_rx_add_vid || !real_dev->vlan_rx_kill_vid)) { 223 (!ops->ndo_vlan_rx_add_vid || !ops->ndo_vlan_rx_kill_vid)) {
223 pr_info("8021q: Device %s has buggy VLAN hw accel\n", name); 224 pr_info("8021q: Device %s has buggy VLAN hw accel\n", name);
224 return -EOPNOTSUPP; 225 return -EOPNOTSUPP;
225 } 226 }
@@ -240,6 +241,7 @@ int register_vlan_dev(struct net_device *dev)
240{ 241{
241 struct vlan_dev_info *vlan = vlan_dev_info(dev); 242 struct vlan_dev_info *vlan = vlan_dev_info(dev);
242 struct net_device *real_dev = vlan->real_dev; 243 struct net_device *real_dev = vlan->real_dev;
244 const struct net_device_ops *ops = real_dev->netdev_ops;
243 u16 vlan_id = vlan->vlan_id; 245 u16 vlan_id = vlan->vlan_id;
244 struct vlan_group *grp, *ngrp = NULL; 246 struct vlan_group *grp, *ngrp = NULL;
245 int err; 247 int err;
@@ -275,9 +277,9 @@ int register_vlan_dev(struct net_device *dev)
275 grp->nr_vlans++; 277 grp->nr_vlans++;
276 278
277 if (ngrp && real_dev->features & NETIF_F_HW_VLAN_RX) 279 if (ngrp && real_dev->features & NETIF_F_HW_VLAN_RX)
278 real_dev->vlan_rx_register(real_dev, ngrp); 280 ops->ndo_vlan_rx_register(real_dev, ngrp);
279 if (real_dev->features & NETIF_F_HW_VLAN_FILTER) 281 if (real_dev->features & NETIF_F_HW_VLAN_FILTER)
280 real_dev->vlan_rx_add_vid(real_dev, vlan_id); 282 ops->ndo_vlan_rx_add_vid(real_dev, vlan_id);
281 283
282 return 0; 284 return 0;
283 285
diff --git a/net/8021q/vlan.h b/net/8021q/vlan.h
index a6603a4d917f..82570bc2a180 100644
--- a/net/8021q/vlan.h
+++ b/net/8021q/vlan.h
@@ -108,8 +108,10 @@ static inline int vlan_gvrp_init(void) { return 0; }
108static inline void vlan_gvrp_uninit(void) {} 108static inline void vlan_gvrp_uninit(void) {}
109#endif 109#endif
110 110
111int vlan_netlink_init(void); 111extern const char vlan_fullname[];
112void vlan_netlink_fini(void); 112extern const char vlan_version[];
113extern int vlan_netlink_init(void);
114extern void vlan_netlink_fini(void);
113 115
114extern struct rtnl_link_ops vlan_link_ops; 116extern struct rtnl_link_ops vlan_link_ops;
115 117
diff --git a/net/8021q/vlan_core.c b/net/8021q/vlan_core.c
index 68ced4bf158c..dd86a1dc4cd0 100644
--- a/net/8021q/vlan_core.c
+++ b/net/8021q/vlan_core.c
@@ -47,8 +47,6 @@ int vlan_hwaccel_do_receive(struct sk_buff *skb)
47 skb->priority = vlan_get_ingress_priority(dev, skb->vlan_tci); 47 skb->priority = vlan_get_ingress_priority(dev, skb->vlan_tci);
48 skb->vlan_tci = 0; 48 skb->vlan_tci = 0;
49 49
50 dev->last_rx = jiffies;
51
52 stats = &dev->stats; 50 stats = &dev->stats;
53 stats->rx_packets++; 51 stats->rx_packets++;
54 stats->rx_bytes += skb->len; 52 stats->rx_bytes += skb->len;
diff --git a/net/8021q/vlan_dev.c b/net/8021q/vlan_dev.c
index 8883e9c8a223..89a3bbdfca3f 100644
--- a/net/8021q/vlan_dev.c
+++ b/net/8021q/vlan_dev.c
@@ -163,8 +163,6 @@ int vlan_skb_recv(struct sk_buff *skb, struct net_device *dev,
163 goto err_unlock; 163 goto err_unlock;
164 } 164 }
165 165
166 skb->dev->last_rx = jiffies;
167
168 stats = &skb->dev->stats; 166 stats = &skb->dev->stats;
169 stats->rx_packets++; 167 stats->rx_packets++;
170 stats->rx_bytes += skb->len; 168 stats->rx_bytes += skb->len;
@@ -526,6 +524,7 @@ out:
526static int vlan_dev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) 524static int vlan_dev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
527{ 525{
528 struct net_device *real_dev = vlan_dev_info(dev)->real_dev; 526 struct net_device *real_dev = vlan_dev_info(dev)->real_dev;
527 const struct net_device_ops *ops = real_dev->netdev_ops;
529 struct ifreq ifrr; 528 struct ifreq ifrr;
530 int err = -EOPNOTSUPP; 529 int err = -EOPNOTSUPP;
531 530
@@ -536,8 +535,8 @@ static int vlan_dev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
536 case SIOCGMIIPHY: 535 case SIOCGMIIPHY:
537 case SIOCGMIIREG: 536 case SIOCGMIIREG:
538 case SIOCSMIIREG: 537 case SIOCSMIIREG:
539 if (real_dev->do_ioctl && netif_device_present(real_dev)) 538 if (netif_device_present(real_dev) && ops->ndo_do_ioctl)
540 err = real_dev->do_ioctl(real_dev, &ifrr, cmd); 539 err = ops->ndo_do_ioctl(real_dev, &ifrr, cmd);
541 break; 540 break;
542 } 541 }
543 542
@@ -594,6 +593,8 @@ static const struct header_ops vlan_header_ops = {
594 .parse = eth_header_parse, 593 .parse = eth_header_parse,
595}; 594};
596 595
596static const struct net_device_ops vlan_netdev_ops, vlan_netdev_accel_ops;
597
597static int vlan_dev_init(struct net_device *dev) 598static int vlan_dev_init(struct net_device *dev)
598{ 599{
599 struct net_device *real_dev = vlan_dev_info(dev)->real_dev; 600 struct net_device *real_dev = vlan_dev_info(dev)->real_dev;
@@ -620,11 +621,11 @@ static int vlan_dev_init(struct net_device *dev)
620 if (real_dev->features & NETIF_F_HW_VLAN_TX) { 621 if (real_dev->features & NETIF_F_HW_VLAN_TX) {
621 dev->header_ops = real_dev->header_ops; 622 dev->header_ops = real_dev->header_ops;
622 dev->hard_header_len = real_dev->hard_header_len; 623 dev->hard_header_len = real_dev->hard_header_len;
623 dev->hard_start_xmit = vlan_dev_hwaccel_hard_start_xmit; 624 dev->netdev_ops = &vlan_netdev_accel_ops;
624 } else { 625 } else {
625 dev->header_ops = &vlan_header_ops; 626 dev->header_ops = &vlan_header_ops;
626 dev->hard_header_len = real_dev->hard_header_len + VLAN_HLEN; 627 dev->hard_header_len = real_dev->hard_header_len + VLAN_HLEN;
627 dev->hard_start_xmit = vlan_dev_hard_start_xmit; 628 dev->netdev_ops = &vlan_netdev_ops;
628 } 629 }
629 630
630 if (is_vlan_dev(real_dev)) 631 if (is_vlan_dev(real_dev))
@@ -648,6 +649,26 @@ static void vlan_dev_uninit(struct net_device *dev)
648 } 649 }
649} 650}
650 651
652static int vlan_ethtool_get_settings(struct net_device *dev,
653 struct ethtool_cmd *cmd)
654{
655 const struct vlan_dev_info *vlan = vlan_dev_info(dev);
656 struct net_device *real_dev = vlan->real_dev;
657
658 if (!real_dev->ethtool_ops->get_settings)
659 return -EOPNOTSUPP;
660
661 return real_dev->ethtool_ops->get_settings(real_dev, cmd);
662}
663
664static void vlan_ethtool_get_drvinfo(struct net_device *dev,
665 struct ethtool_drvinfo *info)
666{
667 strcpy(info->driver, vlan_fullname);
668 strcpy(info->version, vlan_version);
669 strcpy(info->fw_version, "N/A");
670}
671
651static u32 vlan_ethtool_get_rx_csum(struct net_device *dev) 672static u32 vlan_ethtool_get_rx_csum(struct net_device *dev)
652{ 673{
653 const struct vlan_dev_info *vlan = vlan_dev_info(dev); 674 const struct vlan_dev_info *vlan = vlan_dev_info(dev);
@@ -672,11 +693,43 @@ static u32 vlan_ethtool_get_flags(struct net_device *dev)
672} 693}
673 694
674static const struct ethtool_ops vlan_ethtool_ops = { 695static const struct ethtool_ops vlan_ethtool_ops = {
696 .get_settings = vlan_ethtool_get_settings,
697 .get_drvinfo = vlan_ethtool_get_drvinfo,
675 .get_link = ethtool_op_get_link, 698 .get_link = ethtool_op_get_link,
676 .get_rx_csum = vlan_ethtool_get_rx_csum, 699 .get_rx_csum = vlan_ethtool_get_rx_csum,
677 .get_flags = vlan_ethtool_get_flags, 700 .get_flags = vlan_ethtool_get_flags,
678}; 701};
679 702
703static const struct net_device_ops vlan_netdev_ops = {
704 .ndo_change_mtu = vlan_dev_change_mtu,
705 .ndo_init = vlan_dev_init,
706 .ndo_uninit = vlan_dev_uninit,
707 .ndo_open = vlan_dev_open,
708 .ndo_stop = vlan_dev_stop,
709 .ndo_start_xmit = vlan_dev_hard_start_xmit,
710 .ndo_validate_addr = eth_validate_addr,
711 .ndo_set_mac_address = vlan_dev_set_mac_address,
712 .ndo_set_rx_mode = vlan_dev_set_rx_mode,
713 .ndo_set_multicast_list = vlan_dev_set_rx_mode,
714 .ndo_change_rx_flags = vlan_dev_change_rx_flags,
715 .ndo_do_ioctl = vlan_dev_ioctl,
716};
717
718static const struct net_device_ops vlan_netdev_accel_ops = {
719 .ndo_change_mtu = vlan_dev_change_mtu,
720 .ndo_init = vlan_dev_init,
721 .ndo_uninit = vlan_dev_uninit,
722 .ndo_open = vlan_dev_open,
723 .ndo_stop = vlan_dev_stop,
724 .ndo_start_xmit = vlan_dev_hwaccel_hard_start_xmit,
725 .ndo_validate_addr = eth_validate_addr,
726 .ndo_set_mac_address = vlan_dev_set_mac_address,
727 .ndo_set_rx_mode = vlan_dev_set_rx_mode,
728 .ndo_set_multicast_list = vlan_dev_set_rx_mode,
729 .ndo_change_rx_flags = vlan_dev_change_rx_flags,
730 .ndo_do_ioctl = vlan_dev_ioctl,
731};
732
680void vlan_setup(struct net_device *dev) 733void vlan_setup(struct net_device *dev)
681{ 734{
682 ether_setup(dev); 735 ether_setup(dev);
@@ -684,16 +737,7 @@ void vlan_setup(struct net_device *dev)
684 dev->priv_flags |= IFF_802_1Q_VLAN; 737 dev->priv_flags |= IFF_802_1Q_VLAN;
685 dev->tx_queue_len = 0; 738 dev->tx_queue_len = 0;
686 739
687 dev->change_mtu = vlan_dev_change_mtu; 740 dev->netdev_ops = &vlan_netdev_ops;
688 dev->init = vlan_dev_init;
689 dev->uninit = vlan_dev_uninit;
690 dev->open = vlan_dev_open;
691 dev->stop = vlan_dev_stop;
692 dev->set_mac_address = vlan_dev_set_mac_address;
693 dev->set_rx_mode = vlan_dev_set_rx_mode;
694 dev->set_multicast_list = vlan_dev_set_rx_mode;
695 dev->change_rx_flags = vlan_dev_change_rx_flags;
696 dev->do_ioctl = vlan_dev_ioctl;
697 dev->destructor = free_netdev; 741 dev->destructor = free_netdev;
698 dev->ethtool_ops = &vlan_ethtool_ops; 742 dev->ethtool_ops = &vlan_ethtool_ops;
699 743
diff --git a/net/9p/trans_rdma.c b/net/9p/trans_rdma.c
index 2f1fe5fc1228..7fa0eb20b2f6 100644
--- a/net/9p/trans_rdma.c
+++ b/net/9p/trans_rdma.c
@@ -528,8 +528,6 @@ static void rdma_close(struct p9_client *client)
528 528
529/** 529/**
530 * alloc_rdma - Allocate and initialize the rdma transport structure 530 * alloc_rdma - Allocate and initialize the rdma transport structure
531 * @msize: MTU
532 * @dotu: Extension attribute
533 * @opts: Mount options structure 531 * @opts: Mount options structure
534 */ 532 */
535static struct p9_trans_rdma *alloc_rdma(struct p9_rdma_opts *opts) 533static struct p9_trans_rdma *alloc_rdma(struct p9_rdma_opts *opts)
diff --git a/net/Kconfig b/net/Kconfig
index d789d79551ae..6ec2cce7c167 100644
--- a/net/Kconfig
+++ b/net/Kconfig
@@ -27,11 +27,14 @@ menu "Networking options"
27config NET_NS 27config NET_NS
28 bool "Network namespace support" 28 bool "Network namespace support"
29 default n 29 default n
30 depends on EXPERIMENTAL && !SYSFS && NAMESPACES 30 depends on EXPERIMENTAL && NAMESPACES
31 help 31 help
32 Allow user space to create what appear to be multiple instances 32 Allow user space to create what appear to be multiple instances
33 of the network stack. 33 of the network stack.
34 34
35config COMPAT_NET_DEV_OPS
36 def_bool y
37
35source "net/packet/Kconfig" 38source "net/packet/Kconfig"
36source "net/unix/Kconfig" 39source "net/unix/Kconfig"
37source "net/xfrm/Kconfig" 40source "net/xfrm/Kconfig"
@@ -191,6 +194,7 @@ source "net/lapb/Kconfig"
191source "net/econet/Kconfig" 194source "net/econet/Kconfig"
192source "net/wanrouter/Kconfig" 195source "net/wanrouter/Kconfig"
193source "net/sched/Kconfig" 196source "net/sched/Kconfig"
197source "net/dcb/Kconfig"
194 198
195menu "Network testing" 199menu "Network testing"
196 200
@@ -247,7 +251,6 @@ if WIRELESS
247 251
248source "net/wireless/Kconfig" 252source "net/wireless/Kconfig"
249source "net/mac80211/Kconfig" 253source "net/mac80211/Kconfig"
250source "net/ieee80211/Kconfig"
251 254
252endif # WIRELESS 255endif # WIRELESS
253 256
diff --git a/net/Makefile b/net/Makefile
index 27d1f10dc0e0..ba4460432b7c 100644
--- a/net/Makefile
+++ b/net/Makefile
@@ -51,12 +51,14 @@ obj-$(CONFIG_IP_DCCP) += dccp/
51obj-$(CONFIG_IP_SCTP) += sctp/ 51obj-$(CONFIG_IP_SCTP) += sctp/
52obj-y += wireless/ 52obj-y += wireless/
53obj-$(CONFIG_MAC80211) += mac80211/ 53obj-$(CONFIG_MAC80211) += mac80211/
54obj-$(CONFIG_IEEE80211) += ieee80211/
55obj-$(CONFIG_TIPC) += tipc/ 54obj-$(CONFIG_TIPC) += tipc/
56obj-$(CONFIG_NETLABEL) += netlabel/ 55obj-$(CONFIG_NETLABEL) += netlabel/
57obj-$(CONFIG_IUCV) += iucv/ 56obj-$(CONFIG_IUCV) += iucv/
58obj-$(CONFIG_RFKILL) += rfkill/ 57obj-$(CONFIG_RFKILL) += rfkill/
59obj-$(CONFIG_NET_9P) += 9p/ 58obj-$(CONFIG_NET_9P) += 9p/
59ifneq ($(CONFIG_DCB),)
60obj-y += dcb/
61endif
60 62
61ifeq ($(CONFIG_NET),y) 63ifeq ($(CONFIG_NET),y)
62obj-$(CONFIG_SYSCTL) += sysctl_net.o 64obj-$(CONFIG_SYSCTL) += sysctl_net.o
diff --git a/net/appletalk/aarp.c b/net/appletalk/aarp.c
index b25c1e909d14..b03ff58e9308 100644
--- a/net/appletalk/aarp.c
+++ b/net/appletalk/aarp.c
@@ -995,7 +995,6 @@ static int aarp_seq_show(struct seq_file *seq, void *v)
995 struct aarp_iter_state *iter = seq->private; 995 struct aarp_iter_state *iter = seq->private;
996 struct aarp_entry *entry = v; 996 struct aarp_entry *entry = v;
997 unsigned long now = jiffies; 997 unsigned long now = jiffies;
998 DECLARE_MAC_BUF(mac);
999 998
1000 if (v == SEQ_START_TOKEN) 999 if (v == SEQ_START_TOKEN)
1001 seq_puts(seq, 1000 seq_puts(seq,
@@ -1006,7 +1005,7 @@ static int aarp_seq_show(struct seq_file *seq, void *v)
1006 ntohs(entry->target_addr.s_net), 1005 ntohs(entry->target_addr.s_net),
1007 (unsigned int) entry->target_addr.s_node, 1006 (unsigned int) entry->target_addr.s_node,
1008 entry->dev ? entry->dev->name : "????"); 1007 entry->dev ? entry->dev->name : "????");
1009 seq_printf(seq, "%s", print_mac(mac, entry->hwaddr)); 1008 seq_printf(seq, "%pM", entry->hwaddr);
1010 seq_printf(seq, " %8s", 1009 seq_printf(seq, " %8s",
1011 dt2str((long)entry->expires_at - (long)now)); 1010 dt2str((long)entry->expires_at - (long)now));
1012 if (iter->table == unresolved) 1011 if (iter->table == unresolved)
diff --git a/net/appletalk/ddp.c b/net/appletalk/ddp.c
index d3134e7e6ee8..5abce07fb50a 100644
--- a/net/appletalk/ddp.c
+++ b/net/appletalk/ddp.c
@@ -815,9 +815,6 @@ static int atif_ioctl(int cmd, void __user *arg)
815 return -EPERM; 815 return -EPERM;
816 if (sa->sat_family != AF_APPLETALK) 816 if (sa->sat_family != AF_APPLETALK)
817 return -EINVAL; 817 return -EINVAL;
818 if (!atif)
819 return -EADDRNOTAVAIL;
820
821 /* 818 /*
822 * for now, we only support proxy AARP on ELAP; 819 * for now, we only support proxy AARP on ELAP;
823 * we should be able to do it for LocalTalk, too. 820 * we should be able to do it for LocalTalk, too.
@@ -1284,7 +1281,7 @@ static int handle_ip_over_ddp(struct sk_buff *skb)
1284 skb->dev = dev; 1281 skb->dev = dev;
1285 skb_reset_transport_header(skb); 1282 skb_reset_transport_header(skb);
1286 1283
1287 stats = dev->priv; 1284 stats = netdev_priv(dev);
1288 stats->rx_packets++; 1285 stats->rx_packets++;
1289 stats->rx_bytes += skb->len + 13; 1286 stats->rx_bytes += skb->len + 13;
1290 netif_rx(skb); /* Send the SKB up to a higher place. */ 1287 netif_rx(skb); /* Send the SKB up to a higher place. */
diff --git a/net/appletalk/sysctl_net_atalk.c b/net/appletalk/sysctl_net_atalk.c
index 621805dfa2f4..8d237b15183b 100644
--- a/net/appletalk/sysctl_net_atalk.c
+++ b/net/appletalk/sysctl_net_atalk.c
@@ -17,8 +17,8 @@ static struct ctl_table atalk_table[] = {
17 .data = &sysctl_aarp_expiry_time, 17 .data = &sysctl_aarp_expiry_time,
18 .maxlen = sizeof(int), 18 .maxlen = sizeof(int),
19 .mode = 0644, 19 .mode = 0644,
20 .proc_handler = &proc_dointvec_jiffies, 20 .proc_handler = proc_dointvec_jiffies,
21 .strategy = &sysctl_jiffies, 21 .strategy = sysctl_jiffies,
22 }, 22 },
23 { 23 {
24 .ctl_name = NET_ATALK_AARP_TICK_TIME, 24 .ctl_name = NET_ATALK_AARP_TICK_TIME,
@@ -26,8 +26,8 @@ static struct ctl_table atalk_table[] = {
26 .data = &sysctl_aarp_tick_time, 26 .data = &sysctl_aarp_tick_time,
27 .maxlen = sizeof(int), 27 .maxlen = sizeof(int),
28 .mode = 0644, 28 .mode = 0644,
29 .proc_handler = &proc_dointvec_jiffies, 29 .proc_handler = proc_dointvec_jiffies,
30 .strategy = &sysctl_jiffies, 30 .strategy = sysctl_jiffies,
31 }, 31 },
32 { 32 {
33 .ctl_name = NET_ATALK_AARP_RETRANSMIT_LIMIT, 33 .ctl_name = NET_ATALK_AARP_RETRANSMIT_LIMIT,
@@ -35,7 +35,7 @@ static struct ctl_table atalk_table[] = {
35 .data = &sysctl_aarp_retransmit_limit, 35 .data = &sysctl_aarp_retransmit_limit,
36 .maxlen = sizeof(int), 36 .maxlen = sizeof(int),
37 .mode = 0644, 37 .mode = 0644,
38 .proc_handler = &proc_dointvec, 38 .proc_handler = proc_dointvec,
39 }, 39 },
40 { 40 {
41 .ctl_name = NET_ATALK_AARP_RESOLVE_TIME, 41 .ctl_name = NET_ATALK_AARP_RESOLVE_TIME,
@@ -43,8 +43,8 @@ static struct ctl_table atalk_table[] = {
43 .data = &sysctl_aarp_resolve_time, 43 .data = &sysctl_aarp_resolve_time,
44 .maxlen = sizeof(int), 44 .maxlen = sizeof(int),
45 .mode = 0644, 45 .mode = 0644,
46 .proc_handler = &proc_dointvec_jiffies, 46 .proc_handler = proc_dointvec_jiffies,
47 .strategy = &sysctl_jiffies, 47 .strategy = sysctl_jiffies,
48 }, 48 },
49 { 0 }, 49 { 0 },
50}; 50};
diff --git a/net/atm/atm_sysfs.c b/net/atm/atm_sysfs.c
index 1b88311f2130..b5674dc2083d 100644
--- a/net/atm/atm_sysfs.c
+++ b/net/atm/atm_sysfs.c
@@ -149,7 +149,7 @@ int atm_register_sysfs(struct atm_dev *adev)
149 cdev->class = &atm_class; 149 cdev->class = &atm_class;
150 dev_set_drvdata(cdev, adev); 150 dev_set_drvdata(cdev, adev);
151 151
152 snprintf(cdev->bus_id, BUS_ID_SIZE, "%s%d", adev->type, adev->number); 152 dev_set_name(cdev, "%s%d", adev->type, adev->number);
153 err = device_register(cdev); 153 err = device_register(cdev);
154 if (err < 0) 154 if (err < 0)
155 return err; 155 return err;
diff --git a/net/atm/br2684.c b/net/atm/br2684.c
index 280de481edc7..ea9438fc6855 100644
--- a/net/atm/br2684.c
+++ b/net/atm/br2684.c
@@ -101,7 +101,7 @@ static LIST_HEAD(br2684_devs);
101 101
102static inline struct br2684_dev *BRPRIV(const struct net_device *net_dev) 102static inline struct br2684_dev *BRPRIV(const struct net_device *net_dev)
103{ 103{
104 return (struct br2684_dev *)net_dev->priv; 104 return (struct br2684_dev *)netdev_priv(net_dev);
105} 105}
106 106
107static inline struct net_device *list_entry_brdev(const struct list_head *le) 107static inline struct net_device *list_entry_brdev(const struct list_head *le)
@@ -698,12 +698,11 @@ static int br2684_seq_show(struct seq_file *seq, void *v)
698 br2684_devs); 698 br2684_devs);
699 const struct net_device *net_dev = brdev->net_dev; 699 const struct net_device *net_dev = brdev->net_dev;
700 const struct br2684_vcc *brvcc; 700 const struct br2684_vcc *brvcc;
701 DECLARE_MAC_BUF(mac);
702 701
703 seq_printf(seq, "dev %.16s: num=%d, mac=%s (%s)\n", 702 seq_printf(seq, "dev %.16s: num=%d, mac=%pM (%s)\n",
704 net_dev->name, 703 net_dev->name,
705 brdev->number, 704 brdev->number,
706 print_mac(mac, net_dev->dev_addr), 705 net_dev->dev_addr,
707 brdev->mac_was_set ? "set" : "auto"); 706 brdev->mac_was_set ? "set" : "auto");
708 707
709 list_for_each_entry(brvcc, &brdev->brvccs, brvccs) { 708 list_for_each_entry(brvcc, &brdev->brvccs, brvccs) {
diff --git a/net/atm/clip.c b/net/atm/clip.c
index 5b5b96344ce6..2d33a83be799 100644
--- a/net/atm/clip.c
+++ b/net/atm/clip.c
@@ -822,8 +822,8 @@ static void atmarp_info(struct seq_file *seq, struct net_device *dev,
822 seq_printf(seq, "%-6s%-4s%-4s%5ld ", 822 seq_printf(seq, "%-6s%-4s%-4s%5ld ",
823 dev->name, svc ? "SVC" : "PVC", llc ? "LLC" : "NULL", exp); 823 dev->name, svc ? "SVC" : "PVC", llc ? "LLC" : "NULL", exp);
824 824
825 off = scnprintf(buf, sizeof(buf) - 1, "%d.%d.%d.%d", 825 off = scnprintf(buf, sizeof(buf) - 1, "%pI4",
826 NIPQUAD(entry->ip)); 826 &entry->ip);
827 while (off < 16) 827 while (off < 16)
828 buf[off++] = ' '; 828 buf[off++] = ' ';
829 buf[off] = '\0'; 829 buf[off] = '\0';
diff --git a/net/atm/common.h b/net/atm/common.h
index 16f32c1fa1c9..92e2981f479f 100644
--- a/net/atm/common.h
+++ b/net/atm/common.h
@@ -19,6 +19,7 @@ int vcc_sendmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *m,
19 size_t total_len); 19 size_t total_len);
20unsigned int vcc_poll(struct file *file, struct socket *sock, poll_table *wait); 20unsigned 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_setsockopt(struct socket *sock, int level, int optname, 23int vcc_setsockopt(struct socket *sock, int level, int optname,
23 char __user *optval, int optlen); 24 char __user *optval, int optlen);
24int vcc_getsockopt(struct socket *sock, int level, int optname, 25int vcc_getsockopt(struct socket *sock, int level, int optname,
diff --git a/net/atm/ioctl.c b/net/atm/ioctl.c
index 7afd8e7754fd..76ed3c8d26e6 100644
--- a/net/atm/ioctl.c
+++ b/net/atm/ioctl.c
@@ -19,6 +19,7 @@
19#include <linux/atmlec.h> 19#include <linux/atmlec.h>
20#include <linux/mutex.h> 20#include <linux/mutex.h>
21#include <asm/ioctls.h> 21#include <asm/ioctls.h>
22#include <net/compat.h>
22 23
23#include "resources.h" 24#include "resources.h"
24#include "signaling.h" /* for WAITING and sigd_attach */ 25#include "signaling.h" /* for WAITING and sigd_attach */
@@ -46,7 +47,7 @@ void deregister_atm_ioctl(struct atm_ioctl *ioctl)
46EXPORT_SYMBOL(register_atm_ioctl); 47EXPORT_SYMBOL(register_atm_ioctl);
47EXPORT_SYMBOL(deregister_atm_ioctl); 48EXPORT_SYMBOL(deregister_atm_ioctl);
48 49
49int vcc_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg) 50static int do_vcc_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg, int compat)
50{ 51{
51 struct sock *sk = sock->sk; 52 struct sock *sk = sock->sk;
52 struct atm_vcc *vcc; 53 struct atm_vcc *vcc;
@@ -80,13 +81,25 @@ int vcc_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
80 goto done; 81 goto done;
81 } 82 }
82 case SIOCGSTAMP: /* borrowed from IP */ 83 case SIOCGSTAMP: /* borrowed from IP */
83 error = sock_get_timestamp(sk, argp); 84#ifdef CONFIG_COMPAT
85 if (compat)
86 error = compat_sock_get_timestamp(sk, argp);
87 else
88#endif
89 error = sock_get_timestamp(sk, argp);
84 goto done; 90 goto done;
85 case SIOCGSTAMPNS: /* borrowed from IP */ 91 case SIOCGSTAMPNS: /* borrowed from IP */
86 error = sock_get_timestampns(sk, argp); 92#ifdef CONFIG_COMPAT
93 if (compat)
94 error = compat_sock_get_timestampns(sk, argp);
95 else
96#endif
97 error = sock_get_timestampns(sk, argp);
87 goto done; 98 goto done;
88 case ATM_SETSC: 99 case ATM_SETSC:
89 printk(KERN_WARNING "ATM_SETSC is obsolete\n"); 100 if (net_ratelimit())
101 printk(KERN_WARNING "ATM_SETSC is obsolete; used by %s:%d\n",
102 current->comm, task_pid_nr(current));
90 error = 0; 103 error = 0;
91 goto done; 104 goto done;
92 case ATMSIGD_CTRL: 105 case ATMSIGD_CTRL:
@@ -99,12 +112,23 @@ int vcc_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
99 * info uses kernel pointers as opaque references, 112 * info uses kernel pointers as opaque references,
100 * so the holder of the file descriptor can scribble 113 * so the holder of the file descriptor can scribble
101 * on the kernel... so we should make sure that we 114 * on the kernel... so we should make sure that we
102 * have the same privledges that /proc/kcore needs 115 * have the same privileges that /proc/kcore needs
103 */ 116 */
104 if (!capable(CAP_SYS_RAWIO)) { 117 if (!capable(CAP_SYS_RAWIO)) {
105 error = -EPERM; 118 error = -EPERM;
106 goto done; 119 goto done;
107 } 120 }
121#ifdef CONFIG_COMPAT
122 /* WTF? I don't even want to _think_ about making this
123 work for 32-bit userspace. TBH I don't really want
124 to think about it at all. dwmw2. */
125 if (compat) {
126 if (net_ratelimit())
127 printk(KERN_WARNING "32-bit task cannot be atmsigd\n");
128 error = -EINVAL;
129 goto done;
130 }
131#endif
108 error = sigd_attach(vcc); 132 error = sigd_attach(vcc);
109 if (!error) 133 if (!error)
110 sock->state = SS_CONNECTED; 134 sock->state = SS_CONNECTED;
@@ -155,8 +179,21 @@ int vcc_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
155 if (error != -ENOIOCTLCMD) 179 if (error != -ENOIOCTLCMD)
156 goto done; 180 goto done;
157 181
158 error = atm_dev_ioctl(cmd, argp); 182 error = atm_dev_ioctl(cmd, argp, compat);
159 183
160done: 184done:
161 return error; 185 return error;
162} 186}
187
188
189int vcc_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
190{
191 return do_vcc_ioctl(sock, cmd, arg, 0);
192}
193
194#ifdef CONFIG_COMPAT
195int vcc_compat_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
196{
197 return do_vcc_ioctl(sock, cmd, arg, 1);
198}
199#endif
diff --git a/net/atm/lec.c b/net/atm/lec.c
index 8f701cde5945..e5e301550e8a 100644
--- a/net/atm/lec.c
+++ b/net/atm/lec.c
@@ -152,7 +152,7 @@ static void lec_handle_bridge(struct sk_buff *skb, struct net_device *dev)
152 buff += 4; 152 buff += 4;
153 mesg->content.normal.flag = *buff & 0x01; /* 0x01 is topology change */ 153 mesg->content.normal.flag = *buff & 0x01; /* 0x01 is topology change */
154 154
155 priv = (struct lec_priv *)dev->priv; 155 priv = netdev_priv(dev);
156 atm_force_charge(priv->lecd, skb2->truesize); 156 atm_force_charge(priv->lecd, skb2->truesize);
157 sk = sk_atm(priv->lecd); 157 sk = sk_atm(priv->lecd);
158 skb_queue_tail(&sk->sk_receive_queue, skb2); 158 skb_queue_tail(&sk->sk_receive_queue, skb2);
@@ -218,7 +218,7 @@ static unsigned char *get_tr_dst(unsigned char *packet, unsigned char *rdesc)
218 218
219static int lec_open(struct net_device *dev) 219static int lec_open(struct net_device *dev)
220{ 220{
221 struct lec_priv *priv = (struct lec_priv *)dev->priv; 221 struct lec_priv *priv = netdev_priv(dev);
222 222
223 netif_start_queue(dev); 223 netif_start_queue(dev);
224 memset(&priv->stats, 0, sizeof(struct net_device_stats)); 224 memset(&priv->stats, 0, sizeof(struct net_device_stats));
@@ -252,7 +252,7 @@ static void lec_tx_timeout(struct net_device *dev)
252static int lec_start_xmit(struct sk_buff *skb, struct net_device *dev) 252static int lec_start_xmit(struct sk_buff *skb, struct net_device *dev)
253{ 253{
254 struct sk_buff *skb2; 254 struct sk_buff *skb2;
255 struct lec_priv *priv = (struct lec_priv *)dev->priv; 255 struct lec_priv *priv = netdev_priv(dev);
256 struct lecdatahdr_8023 *lec_h; 256 struct lecdatahdr_8023 *lec_h;
257 struct atm_vcc *vcc; 257 struct atm_vcc *vcc;
258 struct lec_arp_table *entry; 258 struct lec_arp_table *entry;
@@ -373,19 +373,13 @@ static int lec_start_xmit(struct sk_buff *skb, struct net_device *dev)
373 if (entry && (entry->tx_wait.qlen < LEC_UNRES_QUE_LEN)) { 373 if (entry && (entry->tx_wait.qlen < LEC_UNRES_QUE_LEN)) {
374 pr_debug("%s:lec_start_xmit: queuing packet, ", 374 pr_debug("%s:lec_start_xmit: queuing packet, ",
375 dev->name); 375 dev->name);
376 pr_debug("MAC address " MAC_FMT "\n", 376 pr_debug("MAC address %pM\n", lec_h->h_dest);
377 lec_h->h_dest[0], lec_h->h_dest[1],
378 lec_h->h_dest[2], lec_h->h_dest[3],
379 lec_h->h_dest[4], lec_h->h_dest[5]);
380 skb_queue_tail(&entry->tx_wait, skb); 377 skb_queue_tail(&entry->tx_wait, skb);
381 } else { 378 } else {
382 pr_debug 379 pr_debug
383 ("%s:lec_start_xmit: tx queue full or no arp entry, dropping, ", 380 ("%s:lec_start_xmit: tx queue full or no arp entry, dropping, ",
384 dev->name); 381 dev->name);
385 pr_debug("MAC address " MAC_FMT "\n", 382 pr_debug("MAC address %pM\n", lec_h->h_dest);
386 lec_h->h_dest[0], lec_h->h_dest[1],
387 lec_h->h_dest[2], lec_h->h_dest[3],
388 lec_h->h_dest[4], lec_h->h_dest[5]);
389 priv->stats.tx_dropped++; 383 priv->stats.tx_dropped++;
390 dev_kfree_skb(skb); 384 dev_kfree_skb(skb);
391 } 385 }
@@ -397,10 +391,7 @@ static int lec_start_xmit(struct sk_buff *skb, struct net_device *dev)
397 391
398 while (entry && (skb2 = skb_dequeue(&entry->tx_wait))) { 392 while (entry && (skb2 = skb_dequeue(&entry->tx_wait))) {
399 pr_debug("lec.c: emptying tx queue, "); 393 pr_debug("lec.c: emptying tx queue, ");
400 pr_debug("MAC address " MAC_FMT "\n", 394 pr_debug("MAC address %pM\n", lec_h->h_dest);
401 lec_h->h_dest[0], lec_h->h_dest[1],
402 lec_h->h_dest[2], lec_h->h_dest[3],
403 lec_h->h_dest[4], lec_h->h_dest[5]);
404 lec_send(vcc, skb2, priv); 395 lec_send(vcc, skb2, priv);
405 } 396 }
406 397
@@ -442,14 +433,14 @@ static int lec_close(struct net_device *dev)
442 */ 433 */
443static struct net_device_stats *lec_get_stats(struct net_device *dev) 434static struct net_device_stats *lec_get_stats(struct net_device *dev)
444{ 435{
445 return &((struct lec_priv *)dev->priv)->stats; 436 return &((struct lec_priv *)netdev_priv(dev))->stats;
446} 437}
447 438
448static int lec_atm_send(struct atm_vcc *vcc, struct sk_buff *skb) 439static int lec_atm_send(struct atm_vcc *vcc, struct sk_buff *skb)
449{ 440{
450 unsigned long flags; 441 unsigned long flags;
451 struct net_device *dev = (struct net_device *)vcc->proto_data; 442 struct net_device *dev = (struct net_device *)vcc->proto_data;
452 struct lec_priv *priv = (struct lec_priv *)dev->priv; 443 struct lec_priv *priv = netdev_priv(dev);
453 struct atmlec_msg *mesg; 444 struct atmlec_msg *mesg;
454 struct lec_arp_table *entry; 445 struct lec_arp_table *entry;
455 int i; 446 int i;
@@ -539,15 +530,8 @@ static int lec_atm_send(struct atm_vcc *vcc, struct sk_buff *skb)
539 { 530 {
540 struct net_bridge_fdb_entry *f; 531 struct net_bridge_fdb_entry *f;
541 532
542 pr_debug 533 pr_debug("%s: bridge zeppelin asks about %pM\n",
543 ("%s: bridge zeppelin asks about " MAC_FMT "\n", 534 dev->name, mesg->content.proxy.mac_addr);
544 dev->name,
545 mesg->content.proxy.mac_addr[0],
546 mesg->content.proxy.mac_addr[1],
547 mesg->content.proxy.mac_addr[2],
548 mesg->content.proxy.mac_addr[3],
549 mesg->content.proxy.mac_addr[4],
550 mesg->content.proxy.mac_addr[5]);
551 535
552 if (br_fdb_get_hook == NULL || dev->br_port == NULL) 536 if (br_fdb_get_hook == NULL || dev->br_port == NULL)
553 break; 537 break;
@@ -596,7 +580,7 @@ static void lec_atm_close(struct atm_vcc *vcc)
596{ 580{
597 struct sk_buff *skb; 581 struct sk_buff *skb;
598 struct net_device *dev = (struct net_device *)vcc->proto_data; 582 struct net_device *dev = (struct net_device *)vcc->proto_data;
599 struct lec_priv *priv = (struct lec_priv *)dev->priv; 583 struct lec_priv *priv = netdev_priv(dev);
600 584
601 priv->lecd = NULL; 585 priv->lecd = NULL;
602 /* Do something needful? */ 586 /* Do something needful? */
@@ -727,7 +711,7 @@ static void lec_push(struct atm_vcc *vcc, struct sk_buff *skb)
727{ 711{
728 unsigned long flags; 712 unsigned long flags;
729 struct net_device *dev = (struct net_device *)vcc->proto_data; 713 struct net_device *dev = (struct net_device *)vcc->proto_data;
730 struct lec_priv *priv = (struct lec_priv *)dev->priv; 714 struct lec_priv *priv = netdev_priv(dev);
731 715
732#if DUMP_PACKETS >0 716#if DUMP_PACKETS >0
733 int i = 0; 717 int i = 0;
@@ -874,7 +858,7 @@ static int lec_vcc_attach(struct atm_vcc *vcc, void __user *arg)
874 vpriv->old_pop = vcc->pop; 858 vpriv->old_pop = vcc->pop;
875 vcc->user_back = vpriv; 859 vcc->user_back = vpriv;
876 vcc->pop = lec_pop; 860 vcc->pop = lec_pop;
877 lec_vcc_added(dev_lec[ioc_data.dev_num]->priv, 861 lec_vcc_added(netdev_priv(dev_lec[ioc_data.dev_num]),
878 &ioc_data, vcc, vcc->push); 862 &ioc_data, vcc, vcc->push);
879 vcc->proto_data = dev_lec[ioc_data.dev_num]; 863 vcc->proto_data = dev_lec[ioc_data.dev_num];
880 vcc->push = lec_push; 864 vcc->push = lec_push;
@@ -886,7 +870,8 @@ static int lec_mcast_attach(struct atm_vcc *vcc, int arg)
886 if (arg < 0 || arg >= MAX_LEC_ITF || !dev_lec[arg]) 870 if (arg < 0 || arg >= MAX_LEC_ITF || !dev_lec[arg])
887 return -EINVAL; 871 return -EINVAL;
888 vcc->proto_data = dev_lec[arg]; 872 vcc->proto_data = dev_lec[arg];
889 return (lec_mcast_make((struct lec_priv *)dev_lec[arg]->priv, vcc)); 873 return lec_mcast_make((struct lec_priv *)netdev_priv(dev_lec[arg]),
874 vcc);
890} 875}
891 876
892/* Initialize device. */ 877/* Initialize device. */
@@ -928,11 +913,11 @@ static int lecd_attach(struct atm_vcc *vcc, int arg)
928 return -EINVAL; 913 return -EINVAL;
929 } 914 }
930 915
931 priv = dev_lec[i]->priv; 916 priv = netdev_priv(dev_lec[i]);
932 priv->is_trdev = is_trdev; 917 priv->is_trdev = is_trdev;
933 lec_init(dev_lec[i]); 918 lec_init(dev_lec[i]);
934 } else { 919 } else {
935 priv = dev_lec[i]->priv; 920 priv = netdev_priv(dev_lec[i]);
936 if (priv->lecd) 921 if (priv->lecd)
937 return -EADDRINUSE; 922 return -EADDRINUSE;
938 } 923 }
@@ -1093,7 +1078,8 @@ static void *lec_itf_walk(struct lec_state *state, loff_t *l)
1093 void *v; 1078 void *v;
1094 1079
1095 dev = state->dev ? state->dev : dev_lec[state->itf]; 1080 dev = state->dev ? state->dev : dev_lec[state->itf];
1096 v = (dev && dev->priv) ? lec_priv_walk(state, l, dev->priv) : NULL; 1081 v = (dev && netdev_priv(dev)) ?
1082 lec_priv_walk(state, l, netdev_priv(dev)) : NULL;
1097 if (!v && dev) { 1083 if (!v && dev) {
1098 dev_put(dev); 1084 dev_put(dev);
1099 /* Partial state reset for the next time we get called */ 1085 /* Partial state reset for the next time we get called */
@@ -1255,7 +1241,7 @@ static void __exit lane_module_cleanup(void)
1255 1241
1256 for (i = 0; i < MAX_LEC_ITF; i++) { 1242 for (i = 0; i < MAX_LEC_ITF; i++) {
1257 if (dev_lec[i] != NULL) { 1243 if (dev_lec[i] != NULL) {
1258 priv = (struct lec_priv *)dev_lec[i]->priv; 1244 priv = netdev_priv(dev_lec[i]);
1259 unregister_netdev(dev_lec[i]); 1245 unregister_netdev(dev_lec[i]);
1260 free_netdev(dev_lec[i]); 1246 free_netdev(dev_lec[i]);
1261 dev_lec[i] = NULL; 1247 dev_lec[i] = NULL;
@@ -1279,7 +1265,7 @@ static int lane2_resolve(struct net_device *dev, const u8 *dst_mac, int force,
1279 u8 **tlvs, u32 *sizeoftlvs) 1265 u8 **tlvs, u32 *sizeoftlvs)
1280{ 1266{
1281 unsigned long flags; 1267 unsigned long flags;
1282 struct lec_priv *priv = (struct lec_priv *)dev->priv; 1268 struct lec_priv *priv = netdev_priv(dev);
1283 struct lec_arp_table *table; 1269 struct lec_arp_table *table;
1284 struct sk_buff *skb; 1270 struct sk_buff *skb;
1285 int retval; 1271 int retval;
@@ -1326,7 +1312,7 @@ static int lane2_associate_req(struct net_device *dev, const u8 *lan_dst,
1326{ 1312{
1327 int retval; 1313 int retval;
1328 struct sk_buff *skb; 1314 struct sk_buff *skb;
1329 struct lec_priv *priv = (struct lec_priv *)dev->priv; 1315 struct lec_priv *priv = netdev_priv(dev);
1330 1316
1331 if (compare_ether_addr(lan_dst, dev->dev_addr)) 1317 if (compare_ether_addr(lan_dst, dev->dev_addr))
1332 return (0); /* not our mac address */ 1318 return (0); /* not our mac address */
@@ -1363,7 +1349,7 @@ static void lane2_associate_ind(struct net_device *dev, const u8 *mac_addr,
1363#if 0 1349#if 0
1364 int i = 0; 1350 int i = 0;
1365#endif 1351#endif
1366 struct lec_priv *priv = (struct lec_priv *)dev->priv; 1352 struct lec_priv *priv = netdev_priv(dev);
1367#if 0 /* 1353#if 0 /*
1368 * Why have the TLVs in LE_ARP entries 1354 * Why have the TLVs in LE_ARP entries
1369 * since we do not use them? When you 1355 * since we do not use them? When you
diff --git a/net/atm/mpc.c b/net/atm/mpc.c
index 11b16d16661c..039d5cc72c3d 100644
--- a/net/atm/mpc.c
+++ b/net/atm/mpc.c
@@ -232,8 +232,8 @@ void atm_mpoa_disp_qos(struct seq_file *m)
232 seq_printf(m, "IP address\n TX:max_pcr pcr min_pcr max_cdv max_sdu\n RX:max_pcr pcr min_pcr max_cdv max_sdu\n"); 232 seq_printf(m, "IP address\n TX:max_pcr pcr min_pcr max_cdv max_sdu\n RX:max_pcr pcr min_pcr max_cdv max_sdu\n");
233 233
234 while (qos != NULL) { 234 while (qos != NULL) {
235 seq_printf(m, "%u.%u.%u.%u\n %-7d %-7d %-7d %-7d %-7d\n %-7d %-7d %-7d %-7d %-7d\n", 235 seq_printf(m, "%pI4\n %-7d %-7d %-7d %-7d %-7d\n %-7d %-7d %-7d %-7d %-7d\n",
236 NIPQUAD(qos->ipaddr), 236 &qos->ipaddr,
237 qos->qos.txtp.max_pcr, qos->qos.txtp.pcr, qos->qos.txtp.min_pcr, qos->qos.txtp.max_cdv, qos->qos.txtp.max_sdu, 237 qos->qos.txtp.max_pcr, qos->qos.txtp.pcr, qos->qos.txtp.min_pcr, qos->qos.txtp.max_cdv, qos->qos.txtp.max_sdu,
238 qos->qos.rxtp.max_pcr, qos->qos.rxtp.pcr, qos->qos.rxtp.min_pcr, qos->qos.rxtp.max_cdv, qos->qos.rxtp.max_sdu); 238 qos->qos.rxtp.max_pcr, qos->qos.rxtp.pcr, qos->qos.rxtp.min_pcr, qos->qos.rxtp.max_cdv, qos->qos.rxtp.max_sdu);
239 qos = qos->next; 239 qos = qos->next;
@@ -341,8 +341,8 @@ static const char *mpoa_device_type_string(char type)
341} 341}
342 342
343/* 343/*
344 * lec device calls this via its dev->priv->lane2_ops->associate_indicator() 344 * lec device calls this via its netdev_priv(dev)->lane2_ops
345 * when it sees a TLV in LE_ARP packet. 345 * ->associate_indicator() when it sees a TLV in LE_ARP packet.
346 * We fill in the pointer above when we see a LANE2 lec initializing 346 * We fill in the pointer above when we see a LANE2 lec initializing
347 * See LANE2 spec 3.1.5 347 * See LANE2 spec 3.1.5
348 * 348 *
@@ -595,8 +595,8 @@ static int atm_mpoa_vcc_attach(struct atm_vcc *vcc, void __user *arg)
595 if (in_entry != NULL) mpc->in_ops->put(in_entry); 595 if (in_entry != NULL) mpc->in_ops->put(in_entry);
596 return -EINVAL; 596 return -EINVAL;
597 } 597 }
598 printk("mpoa: (%s) mpc_vcc_attach: attaching ingress SVC, entry = %u.%u.%u.%u\n", 598 printk("mpoa: (%s) mpc_vcc_attach: attaching ingress SVC, entry = %pI4\n",
599 mpc->dev->name, NIPQUAD(in_entry->ctrl_info.in_dst_ip)); 599 mpc->dev->name, &in_entry->ctrl_info.in_dst_ip);
600 in_entry->shortcut = vcc; 600 in_entry->shortcut = vcc;
601 mpc->in_ops->put(in_entry); 601 mpc->in_ops->put(in_entry);
602 } else { 602 } else {
@@ -627,8 +627,8 @@ static void mpc_vcc_close(struct atm_vcc *vcc, struct net_device *dev)
627 dprintk("mpoa: (%s) mpc_vcc_close:\n", dev->name); 627 dprintk("mpoa: (%s) mpc_vcc_close:\n", dev->name);
628 in_entry = mpc->in_ops->get_by_vcc(vcc, mpc); 628 in_entry = mpc->in_ops->get_by_vcc(vcc, mpc);
629 if (in_entry) { 629 if (in_entry) {
630 dprintk("mpoa: (%s) mpc_vcc_close: ingress SVC closed ip = %u.%u.%u.%u\n", 630 dprintk("mpoa: (%s) mpc_vcc_close: ingress SVC closed ip = %pI4\n",
631 mpc->dev->name, NIPQUAD(in_entry->ctrl_info.in_dst_ip)); 631 mpc->dev->name, &in_entry->ctrl_info.in_dst_ip);
632 in_entry->shortcut = NULL; 632 in_entry->shortcut = NULL;
633 mpc->in_ops->put(in_entry); 633 mpc->in_ops->put(in_entry);
634 } 634 }
@@ -785,7 +785,7 @@ static int atm_mpoa_mpoad_attach (struct atm_vcc *vcc, int arg)
785 } 785 }
786 786
787 if (mpc->dev) { /* check if the lec is LANE2 capable */ 787 if (mpc->dev) { /* check if the lec is LANE2 capable */
788 priv = (struct lec_priv *)mpc->dev->priv; 788 priv = netdev_priv(mpc->dev);
789 if (priv->lane_version < 2) { 789 if (priv->lane_version < 2) {
790 dev_put(mpc->dev); 790 dev_put(mpc->dev);
791 mpc->dev = NULL; 791 mpc->dev = NULL;
@@ -845,7 +845,7 @@ static void mpoad_close(struct atm_vcc *vcc)
845 845
846 mpc->mpoad_vcc = NULL; 846 mpc->mpoad_vcc = NULL;
847 if (mpc->dev) { 847 if (mpc->dev) {
848 struct lec_priv *priv = (struct lec_priv *)mpc->dev->priv; 848 struct lec_priv *priv = netdev_priv(mpc->dev);
849 priv->lane2_ops->associate_indicator = NULL; 849 priv->lane2_ops->associate_indicator = NULL;
850 stop_mpc(mpc); 850 stop_mpc(mpc);
851 dev_put(mpc->dev); 851 dev_put(mpc->dev);
@@ -976,7 +976,7 @@ static int mpoa_event_listener(struct notifier_block *mpoa_notifier, unsigned lo
976 976
977 switch (event) { 977 switch (event) {
978 case NETDEV_REGISTER: /* a new lec device was allocated */ 978 case NETDEV_REGISTER: /* a new lec device was allocated */
979 priv = (struct lec_priv *)dev->priv; 979 priv = netdev_priv(dev);
980 if (priv->lane_version < 2) 980 if (priv->lane_version < 2)
981 break; 981 break;
982 priv->lane2_ops->associate_indicator = lane2_assoc_ind; 982 priv->lane2_ops->associate_indicator = lane2_assoc_ind;
@@ -1098,7 +1098,8 @@ static void check_qos_and_open_shortcut(struct k_message *msg, struct mpoa_clien
1098 entry->shortcut = eg_entry->shortcut; 1098 entry->shortcut = eg_entry->shortcut;
1099 } 1099 }
1100 if(entry->shortcut){ 1100 if(entry->shortcut){
1101 dprintk("mpoa: (%s) using egress SVC to reach %u.%u.%u.%u\n",client->dev->name, NIPQUAD(dst_ip)); 1101 dprintk("mpoa: (%s) using egress SVC to reach %pI4\n",
1102 client->dev->name, &dst_ip);
1102 client->eg_ops->put(eg_entry); 1103 client->eg_ops->put(eg_entry);
1103 return; 1104 return;
1104 } 1105 }
@@ -1123,7 +1124,8 @@ static void MPOA_res_reply_rcvd(struct k_message *msg, struct mpoa_client *mpc)
1123 __be32 dst_ip = msg->content.in_info.in_dst_ip; 1124 __be32 dst_ip = msg->content.in_info.in_dst_ip;
1124 in_cache_entry *entry = mpc->in_ops->get(dst_ip, mpc); 1125 in_cache_entry *entry = mpc->in_ops->get(dst_ip, mpc);
1125 1126
1126 dprintk("mpoa: (%s) MPOA_res_reply_rcvd: ip %u.%u.%u.%u\n", mpc->dev->name, NIPQUAD(dst_ip)); 1127 dprintk("mpoa: (%s) MPOA_res_reply_rcvd: ip %pI4\n",
1128 mpc->dev->name, &dst_ip);
1127 ddprintk("mpoa: (%s) MPOA_res_reply_rcvd() entry = %p", mpc->dev->name, entry); 1129 ddprintk("mpoa: (%s) MPOA_res_reply_rcvd() entry = %p", mpc->dev->name, entry);
1128 if(entry == NULL){ 1130 if(entry == NULL){
1129 printk("\nmpoa: (%s) ARGH, received res. reply for an entry that doesn't exist.\n", mpc->dev->name); 1131 printk("\nmpoa: (%s) ARGH, received res. reply for an entry that doesn't exist.\n", mpc->dev->name);
@@ -1171,14 +1173,14 @@ static void ingress_purge_rcvd(struct k_message *msg, struct mpoa_client *mpc)
1171 in_cache_entry *entry = mpc->in_ops->get_with_mask(dst_ip, mpc, mask); 1173 in_cache_entry *entry = mpc->in_ops->get_with_mask(dst_ip, mpc, mask);
1172 1174
1173 if(entry == NULL){ 1175 if(entry == NULL){
1174 printk("mpoa: (%s) ingress_purge_rcvd: purge for a non-existing entry, ", mpc->dev->name); 1176 printk("mpoa: (%s) ingress_purge_rcvd: purge for a non-existing entry, ip = %pI4\n",
1175 printk("ip = %u.%u.%u.%u\n", NIPQUAD(dst_ip)); 1177 mpc->dev->name, &dst_ip);
1176 return; 1178 return;
1177 } 1179 }
1178 1180
1179 do { 1181 do {
1180 dprintk("mpoa: (%s) ingress_purge_rcvd: removing an ingress entry, ip = %u.%u.%u.%u\n" , 1182 dprintk("mpoa: (%s) ingress_purge_rcvd: removing an ingress entry, ip = %pI4\n",
1181 mpc->dev->name, NIPQUAD(dst_ip)); 1183 mpc->dev->name, &dst_ip);
1182 write_lock_bh(&mpc->ingress_lock); 1184 write_lock_bh(&mpc->ingress_lock);
1183 mpc->in_ops->remove_entry(entry, mpc); 1185 mpc->in_ops->remove_entry(entry, mpc);
1184 write_unlock_bh(&mpc->ingress_lock); 1186 write_unlock_bh(&mpc->ingress_lock);
@@ -1322,7 +1324,7 @@ static void set_mpc_ctrl_addr_rcvd(struct k_message *mesg, struct mpoa_client *m
1322 dprintk("\n"); 1324 dprintk("\n");
1323 1325
1324 if (mpc->dev) { 1326 if (mpc->dev) {
1325 priv = (struct lec_priv *)mpc->dev->priv; 1327 priv = netdev_priv(mpc->dev);
1326 retval = priv->lane2_ops->associate_req(mpc->dev, mpc->dev->dev_addr, tlv, sizeof(tlv)); 1328 retval = priv->lane2_ops->associate_req(mpc->dev, mpc->dev->dev_addr, tlv, sizeof(tlv));
1327 if (retval == 0) 1329 if (retval == 0)
1328 printk("mpoa: (%s) MPOA device type TLV association failed\n", mpc->dev->name); 1330 printk("mpoa: (%s) MPOA device type TLV association failed\n", mpc->dev->name);
@@ -1472,7 +1474,7 @@ static void __exit atm_mpoa_cleanup(void)
1472 tmp = mpc->next; 1474 tmp = mpc->next;
1473 if (mpc->dev != NULL) { 1475 if (mpc->dev != NULL) {
1474 stop_mpc(mpc); 1476 stop_mpc(mpc);
1475 priv = (struct lec_priv *)mpc->dev->priv; 1477 priv = netdev_priv(mpc->dev);
1476 if (priv->lane2_ops != NULL) 1478 if (priv->lane2_ops != NULL)
1477 priv->lane2_ops->associate_indicator = NULL; 1479 priv->lane2_ops->associate_indicator = NULL;
1478 } 1480 }
diff --git a/net/atm/mpoa_caches.c b/net/atm/mpoa_caches.c
index 24799e3e78f7..4504a4b339bb 100644
--- a/net/atm/mpoa_caches.c
+++ b/net/atm/mpoa_caches.c
@@ -94,7 +94,7 @@ static in_cache_entry *in_cache_add_entry(__be32 dst_ip,
94 return NULL; 94 return NULL;
95 } 95 }
96 96
97 dprintk("mpoa: mpoa_caches.c: adding an ingress entry, ip = %u.%u.%u.%u\n", NIPQUAD(dst_ip)); 97 dprintk("mpoa: mpoa_caches.c: adding an ingress entry, ip = %pI4\n", &dst_ip);
98 98
99 atomic_set(&entry->use, 1); 99 atomic_set(&entry->use, 1);
100 dprintk("mpoa: mpoa_caches.c: new_in_cache_entry: about to lock\n"); 100 dprintk("mpoa: mpoa_caches.c: new_in_cache_entry: about to lock\n");
@@ -150,7 +150,8 @@ static int cache_hit(in_cache_entry *entry, struct mpoa_client *mpc)
150 150
151 if( entry->count > mpc->parameters.mpc_p1 && 151 if( entry->count > mpc->parameters.mpc_p1 &&
152 entry->entry_state == INGRESS_INVALID){ 152 entry->entry_state == INGRESS_INVALID){
153 dprintk("mpoa: (%s) mpoa_caches.c: threshold exceeded for ip %u.%u.%u.%u, sending MPOA res req\n", mpc->dev->name, NIPQUAD(entry->ctrl_info.in_dst_ip)); 153 dprintk("mpoa: (%s) mpoa_caches.c: threshold exceeded for ip %pI4, sending MPOA res req\n",
154 mpc->dev->name, &entry->ctrl_info.in_dst_ip);
154 entry->entry_state = INGRESS_RESOLVING; 155 entry->entry_state = INGRESS_RESOLVING;
155 msg.type = SND_MPOA_RES_RQST; 156 msg.type = SND_MPOA_RES_RQST;
156 memcpy(msg.MPS_ctrl, mpc->mps_ctrl_addr, ATM_ESA_LEN ); 157 memcpy(msg.MPS_ctrl, mpc->mps_ctrl_addr, ATM_ESA_LEN );
@@ -184,7 +185,8 @@ static void in_cache_remove_entry(in_cache_entry *entry,
184 struct k_message msg; 185 struct k_message msg;
185 186
186 vcc = entry->shortcut; 187 vcc = entry->shortcut;
187 dprintk("mpoa: mpoa_caches.c: removing an ingress entry, ip = %u.%u.%u.%u\n",NIPQUAD(entry->ctrl_info.in_dst_ip)); 188 dprintk("mpoa: mpoa_caches.c: removing an ingress entry, ip = %pI4\n",
189 &entry->ctrl_info.in_dst_ip);
188 190
189 if (entry->prev != NULL) 191 if (entry->prev != NULL)
190 entry->prev->next = entry->next; 192 entry->prev->next = entry->next;
@@ -228,7 +230,8 @@ static void clear_count_and_expired(struct mpoa_client *client)
228 next_entry = entry->next; 230 next_entry = entry->next;
229 if((now.tv_sec - entry->tv.tv_sec) 231 if((now.tv_sec - entry->tv.tv_sec)
230 > entry->ctrl_info.holding_time){ 232 > entry->ctrl_info.holding_time){
231 dprintk("mpoa: mpoa_caches.c: holding time expired, ip = %u.%u.%u.%u\n", NIPQUAD(entry->ctrl_info.in_dst_ip)); 233 dprintk("mpoa: mpoa_caches.c: holding time expired, ip = %pI4\n",
234 &entry->ctrl_info.in_dst_ip);
232 client->in_ops->remove_entry(entry, client); 235 client->in_ops->remove_entry(entry, client);
233 } 236 }
234 entry = next_entry; 237 entry = next_entry;
@@ -453,7 +456,8 @@ static eg_cache_entry *eg_cache_add_entry(struct k_message *msg, struct mpoa_cli
453 return NULL; 456 return NULL;
454 } 457 }
455 458
456 dprintk("mpoa: mpoa_caches.c: adding an egress entry, ip = %u.%u.%u.%u, this should be our IP\n", NIPQUAD(msg->content.eg_info.eg_dst_ip)); 459 dprintk("mpoa: mpoa_caches.c: adding an egress entry, ip = %pI4, this should be our IP\n",
460 &msg->content.eg_info.eg_dst_ip);
457 461
458 atomic_set(&entry->use, 1); 462 atomic_set(&entry->use, 1);
459 dprintk("mpoa: mpoa_caches.c: new_eg_cache_entry: about to lock\n"); 463 dprintk("mpoa: mpoa_caches.c: new_eg_cache_entry: about to lock\n");
@@ -469,8 +473,8 @@ static eg_cache_entry *eg_cache_add_entry(struct k_message *msg, struct mpoa_cli
469 do_gettimeofday(&(entry->tv)); 473 do_gettimeofday(&(entry->tv));
470 entry->entry_state = EGRESS_RESOLVED; 474 entry->entry_state = EGRESS_RESOLVED;
471 dprintk("mpoa: mpoa_caches.c: new_eg_cache_entry cache_id %lu\n", ntohl(entry->ctrl_info.cache_id)); 475 dprintk("mpoa: mpoa_caches.c: new_eg_cache_entry cache_id %lu\n", ntohl(entry->ctrl_info.cache_id));
472 dprintk("mpoa: mpoa_caches.c: mps_ip = %u.%u.%u.%u\n", 476 dprintk("mpoa: mpoa_caches.c: mps_ip = %pI4\n",
473 NIPQUAD(entry->ctrl_info.mps_ip)); 477 &entry->ctrl_info.mps_ip);
474 atomic_inc(&entry->use); 478 atomic_inc(&entry->use);
475 479
476 write_unlock_irq(&client->egress_lock); 480 write_unlock_irq(&client->egress_lock);
diff --git a/net/atm/pvc.c b/net/atm/pvc.c
index 43e8bf5ed001..e1d22d9430dd 100644
--- a/net/atm/pvc.c
+++ b/net/atm/pvc.c
@@ -113,6 +113,9 @@ static const struct proto_ops pvc_proto_ops = {
113 .getname = pvc_getname, 113 .getname = pvc_getname,
114 .poll = vcc_poll, 114 .poll = vcc_poll,
115 .ioctl = vcc_ioctl, 115 .ioctl = vcc_ioctl,
116#ifdef CONFIG_COMPAT
117 .compat_ioctl = vcc_compat_ioctl,
118#endif
116 .listen = sock_no_listen, 119 .listen = sock_no_listen,
117 .shutdown = pvc_shutdown, 120 .shutdown = pvc_shutdown,
118 .setsockopt = pvc_setsockopt, 121 .setsockopt = pvc_setsockopt,
diff --git a/net/atm/resources.c b/net/atm/resources.c
index a34ba948af96..56b7322ff461 100644
--- a/net/atm/resources.c
+++ b/net/atm/resources.c
@@ -195,20 +195,39 @@ static int fetch_stats(struct atm_dev *dev, struct atm_dev_stats __user *arg, in
195} 195}
196 196
197 197
198int atm_dev_ioctl(unsigned int cmd, void __user *arg) 198int atm_dev_ioctl(unsigned int cmd, void __user *arg, int compat)
199{ 199{
200 void __user *buf; 200 void __user *buf;
201 int error, len, number, size = 0; 201 int error, len, number, size = 0;
202 struct atm_dev *dev; 202 struct atm_dev *dev;
203 struct list_head *p; 203 struct list_head *p;
204 int *tmp_buf, *tmp_p; 204 int *tmp_buf, *tmp_p;
205 struct atm_iobuf __user *iobuf = arg; 205 int __user *sioc_len;
206 struct atmif_sioc __user *sioc = arg; 206 int __user *iobuf_len;
207
208#ifndef CONFIG_COMPAT
209 compat = 0; /* Just so the compiler _knows_ */
210#endif
211
207 switch (cmd) { 212 switch (cmd) {
208 case ATM_GETNAMES: 213 case ATM_GETNAMES:
209 if (get_user(buf, &iobuf->buffer)) 214
210 return -EFAULT; 215 if (compat) {
211 if (get_user(len, &iobuf->length)) 216#ifdef CONFIG_COMPAT
217 struct compat_atm_iobuf __user *ciobuf = arg;
218 compat_uptr_t cbuf;
219 iobuf_len = &ciobuf->length;
220 if (get_user(cbuf, &ciobuf->buffer))
221 return -EFAULT;
222 buf = compat_ptr(cbuf);
223#endif
224 } else {
225 struct atm_iobuf __user *iobuf = arg;
226 iobuf_len = &iobuf->length;
227 if (get_user(buf, &iobuf->buffer))
228 return -EFAULT;
229 }
230 if (get_user(len, iobuf_len))
212 return -EFAULT; 231 return -EFAULT;
213 mutex_lock(&atm_dev_mutex); 232 mutex_lock(&atm_dev_mutex);
214 list_for_each(p, &atm_devs) 233 list_for_each(p, &atm_devs)
@@ -229,7 +248,7 @@ int atm_dev_ioctl(unsigned int cmd, void __user *arg)
229 } 248 }
230 mutex_unlock(&atm_dev_mutex); 249 mutex_unlock(&atm_dev_mutex);
231 error = ((copy_to_user(buf, tmp_buf, size)) || 250 error = ((copy_to_user(buf, tmp_buf, size)) ||
232 put_user(size, &iobuf->length)) 251 put_user(size, iobuf_len))
233 ? -EFAULT : 0; 252 ? -EFAULT : 0;
234 kfree(tmp_buf); 253 kfree(tmp_buf);
235 return error; 254 return error;
@@ -237,13 +256,32 @@ int atm_dev_ioctl(unsigned int cmd, void __user *arg)
237 break; 256 break;
238 } 257 }
239 258
240 if (get_user(buf, &sioc->arg)) 259 if (compat) {
241 return -EFAULT; 260#ifdef CONFIG_COMPAT
242 if (get_user(len, &sioc->length)) 261 struct compat_atmif_sioc __user *csioc = arg;
243 return -EFAULT; 262 compat_uptr_t carg;
244 if (get_user(number, &sioc->number)) 263
245 return -EFAULT; 264 sioc_len = &csioc->length;
246 265 if (get_user(carg, &csioc->arg))
266 return -EFAULT;
267 buf = compat_ptr(carg);
268
269 if (get_user(len, &csioc->length))
270 return -EFAULT;
271 if (get_user(number, &csioc->number))
272 return -EFAULT;
273#endif
274 } else {
275 struct atmif_sioc __user *sioc = arg;
276
277 sioc_len = &sioc->length;
278 if (get_user(buf, &sioc->arg))
279 return -EFAULT;
280 if (get_user(len, &sioc->length))
281 return -EFAULT;
282 if (get_user(number, &sioc->number))
283 return -EFAULT;
284 }
247 if (!(dev = try_then_request_module(atm_dev_lookup(number), 285 if (!(dev = try_then_request_module(atm_dev_lookup(number),
248 "atm-device-%d", number))) 286 "atm-device-%d", number)))
249 return -ENODEV; 287 return -ENODEV;
@@ -358,7 +396,7 @@ int atm_dev_ioctl(unsigned int cmd, void __user *arg)
358 size = error; 396 size = error;
359 /* may return 0, but later on size == 0 means "don't 397 /* may return 0, but later on size == 0 means "don't
360 write the length" */ 398 write the length" */
361 error = put_user(size, &sioc->length) 399 error = put_user(size, sioc_len)
362 ? -EFAULT : 0; 400 ? -EFAULT : 0;
363 goto done; 401 goto done;
364 case ATM_SETLOOP: 402 case ATM_SETLOOP:
@@ -380,11 +418,21 @@ int atm_dev_ioctl(unsigned int cmd, void __user *arg)
380 } 418 }
381 /* fall through */ 419 /* fall through */
382 default: 420 default:
383 if (!dev->ops->ioctl) { 421 if (compat) {
384 error = -EINVAL; 422#ifdef CONFIG_COMPAT
385 goto done; 423 if (!dev->ops->compat_ioctl) {
424 error = -EINVAL;
425 goto done;
426 }
427 size = dev->ops->compat_ioctl(dev, cmd, buf);
428#endif
429 } else {
430 if (!dev->ops->ioctl) {
431 error = -EINVAL;
432 goto done;
433 }
434 size = dev->ops->ioctl(dev, cmd, buf);
386 } 435 }
387 size = dev->ops->ioctl(dev, cmd, buf);
388 if (size < 0) { 436 if (size < 0) {
389 error = (size == -ENOIOCTLCMD ? -EINVAL : size); 437 error = (size == -ENOIOCTLCMD ? -EINVAL : size);
390 goto done; 438 goto done;
@@ -392,7 +440,7 @@ int atm_dev_ioctl(unsigned int cmd, void __user *arg)
392 } 440 }
393 441
394 if (size) 442 if (size)
395 error = put_user(size, &sioc->length) 443 error = put_user(size, sioc_len)
396 ? -EFAULT : 0; 444 ? -EFAULT : 0;
397 else 445 else
398 error = 0; 446 error = 0;
diff --git a/net/atm/resources.h b/net/atm/resources.h
index 1d004aaaeec1..126fb1840dfb 100644
--- a/net/atm/resources.h
+++ b/net/atm/resources.h
@@ -13,7 +13,7 @@
13extern struct list_head atm_devs; 13extern struct list_head atm_devs;
14extern struct mutex atm_dev_mutex; 14extern struct mutex atm_dev_mutex;
15 15
16int atm_dev_ioctl(unsigned int cmd, void __user *arg); 16int atm_dev_ioctl(unsigned int cmd, void __user *arg, int compat);
17 17
18 18
19#ifdef CONFIG_PROC_FS 19#ifdef CONFIG_PROC_FS
diff --git a/net/atm/svc.c b/net/atm/svc.c
index 8fb54dc870b3..7b831b526d0b 100644
--- a/net/atm/svc.c
+++ b/net/atm/svc.c
@@ -608,6 +608,22 @@ static int svc_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
608 return error; 608 return error;
609} 609}
610 610
611#ifdef CONFIG_COMPAT
612static int svc_compat_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
613{
614 /* The definition of ATM_ADDPARTY uses the size of struct atm_iobuf.
615 But actually it takes a struct sockaddr_atmsvc, which doesn't need
616 compat handling. So all we have to do is fix up cmd... */
617 if (cmd == COMPAT_ATM_ADDPARTY)
618 cmd = ATM_ADDPARTY;
619
620 if (cmd == ATM_ADDPARTY || cmd == ATM_DROPPARTY)
621 return svc_ioctl(sock, cmd, arg);
622 else
623 return vcc_compat_ioctl(sock, cmd, arg);
624}
625#endif /* CONFIG_COMPAT */
626
611static const struct proto_ops svc_proto_ops = { 627static const struct proto_ops svc_proto_ops = {
612 .family = PF_ATMSVC, 628 .family = PF_ATMSVC,
613 .owner = THIS_MODULE, 629 .owner = THIS_MODULE,
@@ -620,6 +636,9 @@ static const struct proto_ops svc_proto_ops = {
620 .getname = svc_getname, 636 .getname = svc_getname,
621 .poll = vcc_poll, 637 .poll = vcc_poll,
622 .ioctl = svc_ioctl, 638 .ioctl = svc_ioctl,
639#ifdef CONFIG_COMPAT
640 .compat_ioctl = svc_compat_ioctl,
641#endif
623 .listen = svc_listen, 642 .listen = svc_listen,
624 .shutdown = svc_shutdown, 643 .shutdown = svc_shutdown,
625 .setsockopt = svc_setsockopt, 644 .setsockopt = svc_setsockopt,
diff --git a/net/ax25/ax25_in.c b/net/ax25/ax25_in.c
index 4a5ba978a804..5f1d2107a1dd 100644
--- a/net/ax25/ax25_in.c
+++ b/net/ax25/ax25_in.c
@@ -200,19 +200,15 @@ static int ax25_rcv(struct sk_buff *skb, struct net_device *dev,
200 200
201 skb_reset_transport_header(skb); 201 skb_reset_transport_header(skb);
202 202
203 if ((ax25_dev = ax25_dev_ax25dev(dev)) == NULL) { 203 if ((ax25_dev = ax25_dev_ax25dev(dev)) == NULL)
204 kfree_skb(skb); 204 goto free;
205 return 0;
206 }
207 205
208 /* 206 /*
209 * Parse the address header. 207 * Parse the address header.
210 */ 208 */
211 209
212 if (ax25_addr_parse(skb->data, skb->len, &src, &dest, &dp, &type, &dama) == NULL) { 210 if (ax25_addr_parse(skb->data, skb->len, &src, &dest, &dp, &type, &dama) == NULL)
213 kfree_skb(skb); 211 goto free;
214 return 0;
215 }
216 212
217 /* 213 /*
218 * Ours perhaps ? 214 * Ours perhaps ?
@@ -239,10 +235,8 @@ static int ax25_rcv(struct sk_buff *skb, struct net_device *dev,
239 235
240 ax25_send_to_raw(&dest, skb, skb->data[1]); 236 ax25_send_to_raw(&dest, skb, skb->data[1]);
241 237
242 if (!mine && ax25cmp(&dest, (ax25_address *)dev->broadcast) != 0) { 238 if (!mine && ax25cmp(&dest, (ax25_address *)dev->broadcast) != 0)
243 kfree_skb(skb); 239 goto free;
244 return 0;
245 }
246 240
247 /* Now we are pointing at the pid byte */ 241 /* Now we are pointing at the pid byte */
248 switch (skb->data[1]) { 242 switch (skb->data[1]) {
@@ -301,10 +295,8 @@ static int ax25_rcv(struct sk_buff *skb, struct net_device *dev,
301 * If not, should we DM the incoming frame (except DMs) or 295 * If not, should we DM the incoming frame (except DMs) or
302 * silently ignore them. For now we stay quiet. 296 * silently ignore them. For now we stay quiet.
303 */ 297 */
304 if (ax25_dev->values[AX25_VALUES_CONMODE] == 0) { 298 if (ax25_dev->values[AX25_VALUES_CONMODE] == 0)
305 kfree_skb(skb); 299 goto free;
306 return 0;
307 }
308 300
309 /* LAPB */ 301 /* LAPB */
310 302
@@ -339,8 +331,7 @@ static int ax25_rcv(struct sk_buff *skb, struct net_device *dev,
339 if ((*skb->data & ~AX25_PF) != AX25_DM && mine) 331 if ((*skb->data & ~AX25_PF) != AX25_DM && mine)
340 ax25_return_dm(dev, &src, &dest, &dp); 332 ax25_return_dm(dev, &src, &dest, &dp);
341 333
342 kfree_skb(skb); 334 goto free;
343 return 0;
344 } 335 }
345 336
346 /* b) received SABM(E) */ 337 /* b) received SABM(E) */
@@ -372,15 +363,12 @@ static int ax25_rcv(struct sk_buff *skb, struct net_device *dev,
372 sk->sk_ack_backlog++; 363 sk->sk_ack_backlog++;
373 bh_unlock_sock(sk); 364 bh_unlock_sock(sk);
374 } else { 365 } else {
375 if (!mine) { 366 if (!mine)
376 kfree_skb(skb); 367 goto free;
377 return 0;
378 }
379 368
380 if ((ax25 = ax25_create_cb()) == NULL) { 369 if ((ax25 = ax25_create_cb()) == NULL) {
381 ax25_return_dm(dev, &src, &dest, &dp); 370 ax25_return_dm(dev, &src, &dest, &dp);
382 kfree_skb(skb); 371 goto free;
383 return 0;
384 } 372 }
385 373
386 ax25_fillin_cb(ax25, ax25_dev); 374 ax25_fillin_cb(ax25, ax25_dev);
@@ -436,9 +424,10 @@ static int ax25_rcv(struct sk_buff *skb, struct net_device *dev,
436 if (!sock_flag(sk, SOCK_DEAD)) 424 if (!sock_flag(sk, SOCK_DEAD))
437 sk->sk_data_ready(sk, skb->len); 425 sk->sk_data_ready(sk, skb->len);
438 sock_put(sk); 426 sock_put(sk);
439 } else 427 } else {
428free:
440 kfree_skb(skb); 429 kfree_skb(skb);
441 430 }
442 return 0; 431 return 0;
443} 432}
444 433
diff --git a/net/ax25/sysctl_net_ax25.c b/net/ax25/sysctl_net_ax25.c
index f288fc4aef9b..62ee3fb34732 100644
--- a/net/ax25/sysctl_net_ax25.c
+++ b/net/ax25/sysctl_net_ax25.c
@@ -24,7 +24,9 @@ static int min_idle[1], max_idle[] = {65535000};
24static int min_n2[] = {1}, max_n2[] = {31}; 24static int min_n2[] = {1}, max_n2[] = {31};
25static int min_paclen[] = {1}, max_paclen[] = {512}; 25static int min_paclen[] = {1}, max_paclen[] = {512};
26static int min_proto[1], max_proto[] = { AX25_PROTO_MAX }; 26static int min_proto[1], max_proto[] = { AX25_PROTO_MAX };
27#ifdef CONFIG_AX25_DAMA_SLAVE
27static int min_ds_timeout[1], max_ds_timeout[] = {65535000}; 28static int min_ds_timeout[1], max_ds_timeout[] = {65535000};
29#endif
28 30
29static struct ctl_table_header *ax25_table_header; 31static struct ctl_table_header *ax25_table_header;
30 32
@@ -43,8 +45,8 @@ static const ctl_table ax25_param_table[] = {
43 .procname = "ip_default_mode", 45 .procname = "ip_default_mode",
44 .maxlen = sizeof(int), 46 .maxlen = sizeof(int),
45 .mode = 0644, 47 .mode = 0644,
46 .proc_handler = &proc_dointvec_minmax, 48 .proc_handler = proc_dointvec_minmax,
47 .strategy = &sysctl_intvec, 49 .strategy = sysctl_intvec,
48 .extra1 = &min_ipdefmode, 50 .extra1 = &min_ipdefmode,
49 .extra2 = &max_ipdefmode 51 .extra2 = &max_ipdefmode
50 }, 52 },
@@ -53,8 +55,8 @@ static const ctl_table ax25_param_table[] = {
53 .procname = "ax25_default_mode", 55 .procname = "ax25_default_mode",
54 .maxlen = sizeof(int), 56 .maxlen = sizeof(int),
55 .mode = 0644, 57 .mode = 0644,
56 .proc_handler = &proc_dointvec_minmax, 58 .proc_handler = proc_dointvec_minmax,
57 .strategy = &sysctl_intvec, 59 .strategy = sysctl_intvec,
58 .extra1 = &min_axdefmode, 60 .extra1 = &min_axdefmode,
59 .extra2 = &max_axdefmode 61 .extra2 = &max_axdefmode
60 }, 62 },
@@ -63,8 +65,8 @@ static const ctl_table ax25_param_table[] = {
63 .procname = "backoff_type", 65 .procname = "backoff_type",
64 .maxlen = sizeof(int), 66 .maxlen = sizeof(int),
65 .mode = 0644, 67 .mode = 0644,
66 .proc_handler = &proc_dointvec_minmax, 68 .proc_handler = proc_dointvec_minmax,
67 .strategy = &sysctl_intvec, 69 .strategy = sysctl_intvec,
68 .extra1 = &min_backoff, 70 .extra1 = &min_backoff,
69 .extra2 = &max_backoff 71 .extra2 = &max_backoff
70 }, 72 },
@@ -73,8 +75,8 @@ static const ctl_table ax25_param_table[] = {
73 .procname = "connect_mode", 75 .procname = "connect_mode",
74 .maxlen = sizeof(int), 76 .maxlen = sizeof(int),
75 .mode = 0644, 77 .mode = 0644,
76 .proc_handler = &proc_dointvec_minmax, 78 .proc_handler = proc_dointvec_minmax,
77 .strategy = &sysctl_intvec, 79 .strategy = sysctl_intvec,
78 .extra1 = &min_conmode, 80 .extra1 = &min_conmode,
79 .extra2 = &max_conmode 81 .extra2 = &max_conmode
80 }, 82 },
@@ -83,8 +85,8 @@ static const ctl_table ax25_param_table[] = {
83 .procname = "standard_window_size", 85 .procname = "standard_window_size",
84 .maxlen = sizeof(int), 86 .maxlen = sizeof(int),
85 .mode = 0644, 87 .mode = 0644,
86 .proc_handler = &proc_dointvec_minmax, 88 .proc_handler = proc_dointvec_minmax,
87 .strategy = &sysctl_intvec, 89 .strategy = sysctl_intvec,
88 .extra1 = &min_window, 90 .extra1 = &min_window,
89 .extra2 = &max_window 91 .extra2 = &max_window
90 }, 92 },
@@ -93,8 +95,8 @@ static const ctl_table ax25_param_table[] = {
93 .procname = "extended_window_size", 95 .procname = "extended_window_size",
94 .maxlen = sizeof(int), 96 .maxlen = sizeof(int),
95 .mode = 0644, 97 .mode = 0644,
96 .proc_handler = &proc_dointvec_minmax, 98 .proc_handler = proc_dointvec_minmax,
97 .strategy = &sysctl_intvec, 99 .strategy = sysctl_intvec,
98 .extra1 = &min_ewindow, 100 .extra1 = &min_ewindow,
99 .extra2 = &max_ewindow 101 .extra2 = &max_ewindow
100 }, 102 },
@@ -103,8 +105,8 @@ static const ctl_table ax25_param_table[] = {
103 .procname = "t1_timeout", 105 .procname = "t1_timeout",
104 .maxlen = sizeof(int), 106 .maxlen = sizeof(int),
105 .mode = 0644, 107 .mode = 0644,
106 .proc_handler = &proc_dointvec_minmax, 108 .proc_handler = proc_dointvec_minmax,
107 .strategy = &sysctl_intvec, 109 .strategy = sysctl_intvec,
108 .extra1 = &min_t1, 110 .extra1 = &min_t1,
109 .extra2 = &max_t1 111 .extra2 = &max_t1
110 }, 112 },
@@ -113,8 +115,8 @@ static const ctl_table ax25_param_table[] = {
113 .procname = "t2_timeout", 115 .procname = "t2_timeout",
114 .maxlen = sizeof(int), 116 .maxlen = sizeof(int),
115 .mode = 0644, 117 .mode = 0644,
116 .proc_handler = &proc_dointvec_minmax, 118 .proc_handler = proc_dointvec_minmax,
117 .strategy = &sysctl_intvec, 119 .strategy = sysctl_intvec,
118 .extra1 = &min_t2, 120 .extra1 = &min_t2,
119 .extra2 = &max_t2 121 .extra2 = &max_t2
120 }, 122 },
@@ -123,8 +125,8 @@ static const ctl_table ax25_param_table[] = {
123 .procname = "t3_timeout", 125 .procname = "t3_timeout",
124 .maxlen = sizeof(int), 126 .maxlen = sizeof(int),
125 .mode = 0644, 127 .mode = 0644,
126 .proc_handler = &proc_dointvec_minmax, 128 .proc_handler = proc_dointvec_minmax,
127 .strategy = &sysctl_intvec, 129 .strategy = sysctl_intvec,
128 .extra1 = &min_t3, 130 .extra1 = &min_t3,
129 .extra2 = &max_t3 131 .extra2 = &max_t3
130 }, 132 },
@@ -133,8 +135,8 @@ static const ctl_table ax25_param_table[] = {
133 .procname = "idle_timeout", 135 .procname = "idle_timeout",
134 .maxlen = sizeof(int), 136 .maxlen = sizeof(int),
135 .mode = 0644, 137 .mode = 0644,
136 .proc_handler = &proc_dointvec_minmax, 138 .proc_handler = proc_dointvec_minmax,
137 .strategy = &sysctl_intvec, 139 .strategy = sysctl_intvec,
138 .extra1 = &min_idle, 140 .extra1 = &min_idle,
139 .extra2 = &max_idle 141 .extra2 = &max_idle
140 }, 142 },
@@ -143,8 +145,8 @@ static const ctl_table ax25_param_table[] = {
143 .procname = "maximum_retry_count", 145 .procname = "maximum_retry_count",
144 .maxlen = sizeof(int), 146 .maxlen = sizeof(int),
145 .mode = 0644, 147 .mode = 0644,
146 .proc_handler = &proc_dointvec_minmax, 148 .proc_handler = proc_dointvec_minmax,
147 .strategy = &sysctl_intvec, 149 .strategy = sysctl_intvec,
148 .extra1 = &min_n2, 150 .extra1 = &min_n2,
149 .extra2 = &max_n2 151 .extra2 = &max_n2
150 }, 152 },
@@ -153,8 +155,8 @@ static const ctl_table ax25_param_table[] = {
153 .procname = "maximum_packet_length", 155 .procname = "maximum_packet_length",
154 .maxlen = sizeof(int), 156 .maxlen = sizeof(int),
155 .mode = 0644, 157 .mode = 0644,
156 .proc_handler = &proc_dointvec_minmax, 158 .proc_handler = proc_dointvec_minmax,
157 .strategy = &sysctl_intvec, 159 .strategy = sysctl_intvec,
158 .extra1 = &min_paclen, 160 .extra1 = &min_paclen,
159 .extra2 = &max_paclen 161 .extra2 = &max_paclen
160 }, 162 },
@@ -163,8 +165,8 @@ static const ctl_table ax25_param_table[] = {
163 .procname = "protocol", 165 .procname = "protocol",
164 .maxlen = sizeof(int), 166 .maxlen = sizeof(int),
165 .mode = 0644, 167 .mode = 0644,
166 .proc_handler = &proc_dointvec_minmax, 168 .proc_handler = proc_dointvec_minmax,
167 .strategy = &sysctl_intvec, 169 .strategy = sysctl_intvec,
168 .extra1 = &min_proto, 170 .extra1 = &min_proto,
169 .extra2 = &max_proto 171 .extra2 = &max_proto
170 }, 172 },
@@ -174,8 +176,8 @@ static const ctl_table ax25_param_table[] = {
174 .procname = "dama_slave_timeout", 176 .procname = "dama_slave_timeout",
175 .maxlen = sizeof(int), 177 .maxlen = sizeof(int),
176 .mode = 0644, 178 .mode = 0644,
177 .proc_handler = &proc_dointvec_minmax, 179 .proc_handler = proc_dointvec_minmax,
178 .strategy = &sysctl_intvec, 180 .strategy = sysctl_intvec,
179 .extra1 = &min_ds_timeout, 181 .extra1 = &min_ds_timeout,
180 .extra2 = &max_ds_timeout 182 .extra2 = &max_ds_timeout
181 }, 183 },
diff --git a/net/bluetooth/af_bluetooth.c b/net/bluetooth/af_bluetooth.c
index 8f9431a12c6f..744ed3f07ef3 100644
--- a/net/bluetooth/af_bluetooth.c
+++ b/net/bluetooth/af_bluetooth.c
@@ -41,18 +41,14 @@
41 41
42#include <net/bluetooth/bluetooth.h> 42#include <net/bluetooth/bluetooth.h>
43 43
44#ifndef CONFIG_BT_SOCK_DEBUG 44#define VERSION "2.14"
45#undef BT_DBG
46#define BT_DBG(D...)
47#endif
48
49#define VERSION "2.13"
50 45
51/* Bluetooth sockets */ 46/* Bluetooth sockets */
52#define BT_MAX_PROTO 8 47#define BT_MAX_PROTO 8
53static struct net_proto_family *bt_proto[BT_MAX_PROTO]; 48static struct net_proto_family *bt_proto[BT_MAX_PROTO];
49static DEFINE_RWLOCK(bt_proto_lock);
54 50
55static struct lock_class_key bt_slock_key[BT_MAX_PROTO]; 51#ifdef CONFIG_DEBUG_LOCK_ALLOC
56static struct lock_class_key bt_lock_key[BT_MAX_PROTO]; 52static struct lock_class_key bt_lock_key[BT_MAX_PROTO];
57static const char *bt_key_strings[BT_MAX_PROTO] = { 53static const char *bt_key_strings[BT_MAX_PROTO] = {
58 "sk_lock-AF_BLUETOOTH-BTPROTO_L2CAP", 54 "sk_lock-AF_BLUETOOTH-BTPROTO_L2CAP",
@@ -65,6 +61,7 @@ static const char *bt_key_strings[BT_MAX_PROTO] = {
65 "sk_lock-AF_BLUETOOTH-BTPROTO_AVDTP", 61 "sk_lock-AF_BLUETOOTH-BTPROTO_AVDTP",
66}; 62};
67 63
64static struct lock_class_key bt_slock_key[BT_MAX_PROTO];
68static const char *bt_slock_key_strings[BT_MAX_PROTO] = { 65static const char *bt_slock_key_strings[BT_MAX_PROTO] = {
69 "slock-AF_BLUETOOTH-BTPROTO_L2CAP", 66 "slock-AF_BLUETOOTH-BTPROTO_L2CAP",
70 "slock-AF_BLUETOOTH-BTPROTO_HCI", 67 "slock-AF_BLUETOOTH-BTPROTO_HCI",
@@ -75,7 +72,25 @@ static const char *bt_slock_key_strings[BT_MAX_PROTO] = {
75 "slock-AF_BLUETOOTH-BTPROTO_HIDP", 72 "slock-AF_BLUETOOTH-BTPROTO_HIDP",
76 "slock-AF_BLUETOOTH-BTPROTO_AVDTP", 73 "slock-AF_BLUETOOTH-BTPROTO_AVDTP",
77}; 74};
78static DEFINE_RWLOCK(bt_proto_lock); 75
76static inline void bt_sock_reclassify_lock(struct socket *sock, int proto)
77{
78 struct sock *sk = sock->sk;
79
80 if (!sk)
81 return;
82
83 BUG_ON(sock_owned_by_user(sk));
84
85 sock_lock_init_class_and_name(sk,
86 bt_slock_key_strings[proto], &bt_slock_key[proto],
87 bt_key_strings[proto], &bt_lock_key[proto]);
88}
89#else
90static inline void bt_sock_reclassify_lock(struct socket *sock, int proto)
91{
92}
93#endif
79 94
80int bt_sock_register(int proto, struct net_proto_family *ops) 95int bt_sock_register(int proto, struct net_proto_family *ops)
81{ 96{
@@ -117,21 +132,6 @@ int bt_sock_unregister(int proto)
117} 132}
118EXPORT_SYMBOL(bt_sock_unregister); 133EXPORT_SYMBOL(bt_sock_unregister);
119 134
120static void bt_reclassify_sock_lock(struct socket *sock, int proto)
121{
122 struct sock *sk = sock->sk;
123
124 if (!sk)
125 return;
126 BUG_ON(sock_owned_by_user(sk));
127
128 sock_lock_init_class_and_name(sk,
129 bt_slock_key_strings[proto],
130 &bt_slock_key[proto],
131 bt_key_strings[proto],
132 &bt_lock_key[proto]);
133}
134
135static int bt_sock_create(struct net *net, struct socket *sock, int proto) 135static int bt_sock_create(struct net *net, struct socket *sock, int proto)
136{ 136{
137 int err; 137 int err;
@@ -151,7 +151,7 @@ static int bt_sock_create(struct net *net, struct socket *sock, int proto)
151 151
152 if (bt_proto[proto] && try_module_get(bt_proto[proto]->owner)) { 152 if (bt_proto[proto] && try_module_get(bt_proto[proto]->owner)) {
153 err = bt_proto[proto]->create(net, sock, proto); 153 err = bt_proto[proto]->create(net, sock, proto);
154 bt_reclassify_sock_lock(sock, proto); 154 bt_sock_reclassify_lock(sock, proto);
155 module_put(bt_proto[proto]->owner); 155 module_put(bt_proto[proto]->owner);
156 } 156 }
157 157
@@ -240,7 +240,7 @@ int bt_sock_recvmsg(struct kiocb *iocb, struct socket *sock,
240 size_t copied; 240 size_t copied;
241 int err; 241 int err;
242 242
243 BT_DBG("sock %p sk %p len %d", sock, sk, len); 243 BT_DBG("sock %p sk %p len %zu", sock, sk, len);
244 244
245 if (flags & (MSG_OOB)) 245 if (flags & (MSG_OOB))
246 return -EOPNOTSUPP; 246 return -EOPNOTSUPP;
diff --git a/net/bluetooth/bnep/bnep.h b/net/bluetooth/bnep/bnep.h
index b69bf4e7c48b..d20f8a40f36e 100644
--- a/net/bluetooth/bnep/bnep.h
+++ b/net/bluetooth/bnep/bnep.h
@@ -161,7 +161,7 @@ struct bnep_session {
161 struct msghdr msg; 161 struct msghdr msg;
162 162
163 struct bnep_proto_filter proto_filter[BNEP_MAX_PROTO_FILTERS]; 163 struct bnep_proto_filter proto_filter[BNEP_MAX_PROTO_FILTERS];
164 u64 mc_filter; 164 unsigned long long mc_filter;
165 165
166 struct socket *sock; 166 struct socket *sock;
167 struct net_device *dev; 167 struct net_device *dev;
diff --git a/net/bluetooth/bnep/core.c b/net/bluetooth/bnep/core.c
index 80ba30cf4b68..70fea8bdb4e5 100644
--- a/net/bluetooth/bnep/core.c
+++ b/net/bluetooth/bnep/core.c
@@ -52,11 +52,6 @@
52 52
53#include "bnep.h" 53#include "bnep.h"
54 54
55#ifndef CONFIG_BT_BNEP_DEBUG
56#undef BT_DBG
57#define BT_DBG(D...)
58#endif
59
60#define VERSION "1.3" 55#define VERSION "1.3"
61 56
62static int compress_src = 1; 57static int compress_src = 1;
@@ -311,7 +306,6 @@ static inline int bnep_rx_frame(struct bnep_session *s, struct sk_buff *skb)
311 struct sk_buff *nskb; 306 struct sk_buff *nskb;
312 u8 type; 307 u8 type;
313 308
314 dev->last_rx = jiffies;
315 s->stats.rx_bytes += skb->len; 309 s->stats.rx_bytes += skb->len;
316 310
317 type = *(u8 *) skb->data; skb_pull(skb, 1); 311 type = *(u8 *) skb->data; skb_pull(skb, 1);
@@ -566,7 +560,7 @@ int bnep_add_connection(struct bnep_connadd_req *req, struct socket *sock)
566 goto failed; 560 goto failed;
567 } 561 }
568 562
569 s = dev->priv; 563 s = netdev_priv(dev);
570 564
571 /* This is rx header therefore addresses are swapped. 565 /* This is rx header therefore addresses are swapped.
572 * ie eh.h_dest is our local address. */ 566 * ie eh.h_dest is our local address. */
diff --git a/net/bluetooth/bnep/netdev.c b/net/bluetooth/bnep/netdev.c
index d9fa0ab2c87f..f897da6e0444 100644
--- a/net/bluetooth/bnep/netdev.c
+++ b/net/bluetooth/bnep/netdev.c
@@ -41,11 +41,6 @@
41 41
42#include "bnep.h" 42#include "bnep.h"
43 43
44#ifndef CONFIG_BT_BNEP_DEBUG
45#undef BT_DBG
46#define BT_DBG( A... )
47#endif
48
49#define BNEP_TX_QUEUE_LEN 20 44#define BNEP_TX_QUEUE_LEN 20
50 45
51static int bnep_net_open(struct net_device *dev) 46static int bnep_net_open(struct net_device *dev)
@@ -62,14 +57,14 @@ static int bnep_net_close(struct net_device *dev)
62 57
63static struct net_device_stats *bnep_net_get_stats(struct net_device *dev) 58static struct net_device_stats *bnep_net_get_stats(struct net_device *dev)
64{ 59{
65 struct bnep_session *s = dev->priv; 60 struct bnep_session *s = netdev_priv(dev);
66 return &s->stats; 61 return &s->stats;
67} 62}
68 63
69static void bnep_net_set_mc_list(struct net_device *dev) 64static void bnep_net_set_mc_list(struct net_device *dev)
70{ 65{
71#ifdef CONFIG_BT_BNEP_MC_FILTER 66#ifdef CONFIG_BT_BNEP_MC_FILTER
72 struct bnep_session *s = dev->priv; 67 struct bnep_session *s = netdev_priv(dev);
73 struct sock *sk = s->sock->sk; 68 struct sock *sk = s->sock->sk;
74 struct bnep_set_filter_req *r; 69 struct bnep_set_filter_req *r;
75 struct sk_buff *skb; 70 struct sk_buff *skb;
@@ -183,7 +178,7 @@ static inline int bnep_net_proto_filter(struct sk_buff *skb, struct bnep_session
183 178
184static int bnep_net_xmit(struct sk_buff *skb, struct net_device *dev) 179static int bnep_net_xmit(struct sk_buff *skb, struct net_device *dev)
185{ 180{
186 struct bnep_session *s = dev->priv; 181 struct bnep_session *s = netdev_priv(dev);
187 struct sock *sk = s->sock->sk; 182 struct sock *sk = s->sock->sk;
188 183
189 BT_DBG("skb %p, dev %p", skb, dev); 184 BT_DBG("skb %p, dev %p", skb, dev);
diff --git a/net/bluetooth/bnep/sock.c b/net/bluetooth/bnep/sock.c
index 8ffb57f2303a..e857628b0b27 100644
--- a/net/bluetooth/bnep/sock.c
+++ b/net/bluetooth/bnep/sock.c
@@ -46,11 +46,6 @@
46 46
47#include "bnep.h" 47#include "bnep.h"
48 48
49#ifndef CONFIG_BT_BNEP_DEBUG
50#undef BT_DBG
51#define BT_DBG( A... )
52#endif
53
54static int bnep_sock_release(struct socket *sock) 49static int bnep_sock_release(struct socket *sock)
55{ 50{
56 struct sock *sk = sock->sk; 51 struct sock *sk = sock->sk;
diff --git a/net/bluetooth/cmtp/capi.c b/net/bluetooth/cmtp/capi.c
index 3e9d5bb3fefb..78958c0f9a40 100644
--- a/net/bluetooth/cmtp/capi.c
+++ b/net/bluetooth/cmtp/capi.c
@@ -42,11 +42,6 @@
42 42
43#include "cmtp.h" 43#include "cmtp.h"
44 44
45#ifndef CONFIG_BT_CMTP_DEBUG
46#undef BT_DBG
47#define BT_DBG(D...)
48#endif
49
50#define CAPI_INTEROPERABILITY 0x20 45#define CAPI_INTEROPERABILITY 0x20
51 46
52#define CAPI_INTEROPERABILITY_REQ CAPICMD(CAPI_INTEROPERABILITY, CAPI_REQ) 47#define CAPI_INTEROPERABILITY_REQ CAPICMD(CAPI_INTEROPERABILITY, CAPI_REQ)
diff --git a/net/bluetooth/cmtp/core.c b/net/bluetooth/cmtp/core.c
index ca60a4517fd3..c9cac7719efe 100644
--- a/net/bluetooth/cmtp/core.c
+++ b/net/bluetooth/cmtp/core.c
@@ -44,11 +44,6 @@
44 44
45#include "cmtp.h" 45#include "cmtp.h"
46 46
47#ifndef CONFIG_BT_CMTP_DEBUG
48#undef BT_DBG
49#define BT_DBG(D...)
50#endif
51
52#define VERSION "1.0" 47#define VERSION "1.0"
53 48
54static DECLARE_RWSEM(cmtp_session_sem); 49static DECLARE_RWSEM(cmtp_session_sem);
diff --git a/net/bluetooth/cmtp/sock.c b/net/bluetooth/cmtp/sock.c
index 8c7f7bc4e0ba..16b0fad74f6e 100644
--- a/net/bluetooth/cmtp/sock.c
+++ b/net/bluetooth/cmtp/sock.c
@@ -43,11 +43,6 @@
43 43
44#include "cmtp.h" 44#include "cmtp.h"
45 45
46#ifndef CONFIG_BT_CMTP_DEBUG
47#undef BT_DBG
48#define BT_DBG(D...)
49#endif
50
51static int cmtp_sock_release(struct socket *sock) 46static int cmtp_sock_release(struct socket *sock)
52{ 47{
53 struct sock *sk = sock->sk; 48 struct sock *sk = sock->sk;
diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c
index b7002429f152..a4a789f24c8d 100644
--- a/net/bluetooth/hci_conn.c
+++ b/net/bluetooth/hci_conn.c
@@ -45,11 +45,6 @@
45#include <net/bluetooth/bluetooth.h> 45#include <net/bluetooth/bluetooth.h>
46#include <net/bluetooth/hci_core.h> 46#include <net/bluetooth/hci_core.h>
47 47
48#ifndef CONFIG_BT_HCI_CORE_DEBUG
49#undef BT_DBG
50#define BT_DBG(D...)
51#endif
52
53void hci_acl_connect(struct hci_conn *conn) 48void hci_acl_connect(struct hci_conn *conn)
54{ 49{
55 struct hci_dev *hdev = conn->hdev; 50 struct hci_dev *hdev = conn->hdev;
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index 278a3ace14f6..ba78cc1eb8d9 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -48,11 +48,6 @@
48#include <net/bluetooth/bluetooth.h> 48#include <net/bluetooth/bluetooth.h>
49#include <net/bluetooth/hci_core.h> 49#include <net/bluetooth/hci_core.h>
50 50
51#ifndef CONFIG_BT_HCI_CORE_DEBUG
52#undef BT_DBG
53#define BT_DBG(D...)
54#endif
55
56static void hci_cmd_task(unsigned long arg); 51static void hci_cmd_task(unsigned long arg);
57static void hci_rx_task(unsigned long arg); 52static void hci_rx_task(unsigned long arg);
58static void hci_tx_task(unsigned long arg); 53static void hci_tx_task(unsigned long arg);
@@ -205,7 +200,7 @@ static void hci_init_req(struct hci_dev *hdev, unsigned long opt)
205 /* Mandatory initialization */ 200 /* Mandatory initialization */
206 201
207 /* Reset */ 202 /* Reset */
208 if (test_bit(HCI_QUIRK_RESET_ON_INIT, &hdev->quirks)) 203 if (!test_bit(HCI_QUIRK_NO_RESET, &hdev->quirks))
209 hci_send_cmd(hdev, HCI_OP_RESET, 0, NULL); 204 hci_send_cmd(hdev, HCI_OP_RESET, 0, NULL);
210 205
211 /* Read Local Supported Features */ 206 /* Read Local Supported Features */
@@ -290,7 +285,7 @@ static void hci_linkpol_req(struct hci_dev *hdev, unsigned long opt)
290{ 285{
291 __le16 policy = cpu_to_le16(opt); 286 __le16 policy = cpu_to_le16(opt);
292 287
293 BT_DBG("%s %x", hdev->name, opt); 288 BT_DBG("%s %x", hdev->name, policy);
294 289
295 /* Default link policy */ 290 /* Default link policy */
296 hci_send_cmd(hdev, HCI_OP_WRITE_DEF_LINK_POLICY, 2, &policy); 291 hci_send_cmd(hdev, HCI_OP_WRITE_DEF_LINK_POLICY, 2, &policy);
@@ -756,7 +751,7 @@ int hci_get_dev_list(void __user *arg)
756 751
757 size = sizeof(*dl) + dev_num * sizeof(*dr); 752 size = sizeof(*dl) + dev_num * sizeof(*dr);
758 753
759 if (!(dl = kmalloc(size, GFP_KERNEL))) 754 if (!(dl = kzalloc(size, GFP_KERNEL)))
760 return -ENOMEM; 755 return -ENOMEM;
761 756
762 dr = dl->dev_req; 757 dr = dl->dev_req;
diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index ad7a553d7713..f91ba690f5d2 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -45,11 +45,6 @@
45#include <net/bluetooth/bluetooth.h> 45#include <net/bluetooth/bluetooth.h>
46#include <net/bluetooth/hci_core.h> 46#include <net/bluetooth/hci_core.h>
47 47
48#ifndef CONFIG_BT_HCI_CORE_DEBUG
49#undef BT_DBG
50#define BT_DBG(D...)
51#endif
52
53/* Handle HCI Event packets */ 48/* Handle HCI Event packets */
54 49
55static void hci_cc_inquiry_cancel(struct hci_dev *hdev, struct sk_buff *skb) 50static void hci_cc_inquiry_cancel(struct hci_dev *hdev, struct sk_buff *skb)
diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
index d62579b67959..4f9621f759a0 100644
--- a/net/bluetooth/hci_sock.c
+++ b/net/bluetooth/hci_sock.c
@@ -49,11 +49,6 @@
49#include <net/bluetooth/bluetooth.h> 49#include <net/bluetooth/bluetooth.h>
50#include <net/bluetooth/hci_core.h> 50#include <net/bluetooth/hci_core.h>
51 51
52#ifndef CONFIG_BT_HCI_SOCK_DEBUG
53#undef BT_DBG
54#define BT_DBG(D...)
55#endif
56
57/* ----- HCI socket interface ----- */ 52/* ----- HCI socket interface ----- */
58 53
59static inline int hci_test_bit(int nr, void *addr) 54static inline int hci_test_bit(int nr, void *addr)
diff --git a/net/bluetooth/hci_sysfs.c b/net/bluetooth/hci_sysfs.c
index f4f6615cad9f..1a1f916be44e 100644
--- a/net/bluetooth/hci_sysfs.c
+++ b/net/bluetooth/hci_sysfs.c
@@ -6,11 +6,6 @@
6#include <net/bluetooth/bluetooth.h> 6#include <net/bluetooth/bluetooth.h>
7#include <net/bluetooth/hci_core.h> 7#include <net/bluetooth/hci_core.h>
8 8
9#ifndef CONFIG_BT_HCI_CORE_DEBUG
10#undef BT_DBG
11#define BT_DBG(D...)
12#endif
13
14struct class *bt_class = NULL; 9struct class *bt_class = NULL;
15EXPORT_SYMBOL_GPL(bt_class); 10EXPORT_SYMBOL_GPL(bt_class);
16 11
@@ -113,8 +108,7 @@ void hci_conn_add_sysfs(struct hci_conn *conn)
113 conn->dev.class = bt_class; 108 conn->dev.class = bt_class;
114 conn->dev.parent = &hdev->dev; 109 conn->dev.parent = &hdev->dev;
115 110
116 snprintf(conn->dev.bus_id, BUS_ID_SIZE, "%s:%d", 111 dev_set_name(&conn->dev, "%s:%d", hdev->name, conn->handle);
117 hdev->name, conn->handle);
118 112
119 dev_set_drvdata(&conn->dev, conn); 113 dev_set_drvdata(&conn->dev, conn);
120 114
@@ -132,7 +126,7 @@ void hci_conn_add_sysfs(struct hci_conn *conn)
132 */ 126 */
133static int __match_tty(struct device *dev, void *data) 127static int __match_tty(struct device *dev, void *data)
134{ 128{
135 return !strncmp(dev->bus_id, "rfcomm", 6); 129 return !strncmp(dev_name(dev), "rfcomm", 6);
136} 130}
137 131
138static void del_conn(struct work_struct *work) 132static void del_conn(struct work_struct *work)
@@ -421,7 +415,7 @@ int hci_register_sysfs(struct hci_dev *hdev)
421 dev->class = bt_class; 415 dev->class = bt_class;
422 dev->parent = hdev->parent; 416 dev->parent = hdev->parent;
423 417
424 strlcpy(dev->bus_id, hdev->name, BUS_ID_SIZE); 418 dev_set_name(dev, "%s", hdev->name);
425 419
426 dev_set_drvdata(dev, hdev); 420 dev_set_drvdata(dev, hdev);
427 421
diff --git a/net/bluetooth/hidp/core.c b/net/bluetooth/hidp/core.c
index acdeab3d9807..b18676870d55 100644
--- a/net/bluetooth/hidp/core.c
+++ b/net/bluetooth/hidp/core.c
@@ -47,11 +47,6 @@
47 47
48#include "hidp.h" 48#include "hidp.h"
49 49
50#ifndef CONFIG_BT_HIDP_DEBUG
51#undef BT_DBG
52#define BT_DBG(D...)
53#endif
54
55#define VERSION "1.2" 50#define VERSION "1.2"
56 51
57static DECLARE_RWSEM(hidp_session_sem); 52static DECLARE_RWSEM(hidp_session_sem);
diff --git a/net/bluetooth/hidp/sock.c b/net/bluetooth/hidp/sock.c
index f4dd02ca9a96..37c9d7d2e688 100644
--- a/net/bluetooth/hidp/sock.c
+++ b/net/bluetooth/hidp/sock.c
@@ -39,11 +39,6 @@
39 39
40#include "hidp.h" 40#include "hidp.h"
41 41
42#ifndef CONFIG_BT_HIDP_DEBUG
43#undef BT_DBG
44#define BT_DBG(D...)
45#endif
46
47static int hidp_sock_release(struct socket *sock) 42static int hidp_sock_release(struct socket *sock)
48{ 43{
49 struct sock *sk = sock->sk; 44 struct sock *sk = sock->sk;
diff --git a/net/bluetooth/l2cap.c b/net/bluetooth/l2cap.c
index 9610a9c85b98..b93748e224ff 100644
--- a/net/bluetooth/l2cap.c
+++ b/net/bluetooth/l2cap.c
@@ -50,11 +50,6 @@
50#include <net/bluetooth/hci_core.h> 50#include <net/bluetooth/hci_core.h>
51#include <net/bluetooth/l2cap.h> 51#include <net/bluetooth/l2cap.h>
52 52
53#ifndef CONFIG_BT_L2CAP_DEBUG
54#undef BT_DBG
55#define BT_DBG(D...)
56#endif
57
58#define VERSION "2.11" 53#define VERSION "2.11"
59 54
60static u32 l2cap_feat_mask = 0x0000; 55static u32 l2cap_feat_mask = 0x0000;
diff --git a/net/bluetooth/rfcomm/core.c b/net/bluetooth/rfcomm/core.c
index ce68e046d963..acd84fd524b8 100644
--- a/net/bluetooth/rfcomm/core.c
+++ b/net/bluetooth/rfcomm/core.c
@@ -46,11 +46,6 @@
46#include <net/bluetooth/l2cap.h> 46#include <net/bluetooth/l2cap.h>
47#include <net/bluetooth/rfcomm.h> 47#include <net/bluetooth/rfcomm.h>
48 48
49#ifndef CONFIG_BT_RFCOMM_DEBUG
50#undef BT_DBG
51#define BT_DBG(D...)
52#endif
53
54#define VERSION "1.10" 49#define VERSION "1.10"
55 50
56static int disable_cfc = 0; 51static int disable_cfc = 0;
diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
index 8a972b6ba85f..d3fc6fca38d0 100644
--- a/net/bluetooth/rfcomm/sock.c
+++ b/net/bluetooth/rfcomm/sock.c
@@ -50,11 +50,6 @@
50#include <net/bluetooth/l2cap.h> 50#include <net/bluetooth/l2cap.h>
51#include <net/bluetooth/rfcomm.h> 51#include <net/bluetooth/rfcomm.h>
52 52
53#ifndef CONFIG_BT_RFCOMM_DEBUG
54#undef BT_DBG
55#define BT_DBG(D...)
56#endif
57
58static const struct proto_ops rfcomm_sock_ops; 53static const struct proto_ops rfcomm_sock_ops;
59 54
60static struct bt_sock_list rfcomm_sk_list = { 55static struct bt_sock_list rfcomm_sk_list = {
@@ -644,7 +639,7 @@ static int rfcomm_sock_recvmsg(struct kiocb *iocb, struct socket *sock,
644 639
645 msg->msg_namelen = 0; 640 msg->msg_namelen = 0;
646 641
647 BT_DBG("sk %p size %d", sk, size); 642 BT_DBG("sk %p size %zu", sk, size);
648 643
649 lock_sock(sk); 644 lock_sock(sk);
650 645
@@ -792,7 +787,7 @@ static int rfcomm_sock_getsockopt(struct socket *sock, int level, int optname, c
792 787
793static int rfcomm_sock_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg) 788static int rfcomm_sock_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
794{ 789{
795 struct sock *sk = sock->sk; 790 struct sock *sk __maybe_unused = sock->sk;
796 int err; 791 int err;
797 792
798 BT_DBG("sk %p cmd %x arg %lx", sk, cmd, arg); 793 BT_DBG("sk %p cmd %x arg %lx", sk, cmd, arg);
diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
index d3340dd52bcf..d030c69cb5a3 100644
--- a/net/bluetooth/rfcomm/tty.c
+++ b/net/bluetooth/rfcomm/tty.c
@@ -39,11 +39,6 @@
39#include <net/bluetooth/hci_core.h> 39#include <net/bluetooth/hci_core.h>
40#include <net/bluetooth/rfcomm.h> 40#include <net/bluetooth/rfcomm.h>
41 41
42#ifndef CONFIG_BT_RFCOMM_DEBUG
43#undef BT_DBG
44#define BT_DBG(D...)
45#endif
46
47#define RFCOMM_TTY_MAGIC 0x6d02 /* magic number for rfcomm struct */ 42#define RFCOMM_TTY_MAGIC 0x6d02 /* magic number for rfcomm struct */
48#define RFCOMM_TTY_PORTS RFCOMM_MAX_DEV /* whole lotta rfcomm devices */ 43#define RFCOMM_TTY_PORTS RFCOMM_MAX_DEV /* whole lotta rfcomm devices */
49#define RFCOMM_TTY_MAJOR 216 /* device node major id of the usb/bluetooth.c driver */ 44#define RFCOMM_TTY_MAJOR 216 /* device node major id of the usb/bluetooth.c driver */
@@ -58,7 +53,7 @@ struct rfcomm_dev {
58 char name[12]; 53 char name[12];
59 int id; 54 int id;
60 unsigned long flags; 55 unsigned long flags;
61 int opened; 56 atomic_t opened;
62 int err; 57 int err;
63 58
64 bdaddr_t src; 59 bdaddr_t src;
@@ -261,6 +256,8 @@ static int rfcomm_dev_add(struct rfcomm_dev_req *req, struct rfcomm_dlc *dlc)
261 dev->flags = req->flags & 256 dev->flags = req->flags &
262 ((1 << RFCOMM_RELEASE_ONHUP) | (1 << RFCOMM_REUSE_DLC)); 257 ((1 << RFCOMM_RELEASE_ONHUP) | (1 << RFCOMM_REUSE_DLC));
263 258
259 atomic_set(&dev->opened, 0);
260
264 init_waitqueue_head(&dev->wait); 261 init_waitqueue_head(&dev->wait);
265 tasklet_init(&dev->wakeup_task, rfcomm_tty_wakeup, (unsigned long) dev); 262 tasklet_init(&dev->wakeup_task, rfcomm_tty_wakeup, (unsigned long) dev);
266 263
@@ -301,18 +298,15 @@ static int rfcomm_dev_add(struct rfcomm_dev_req *req, struct rfcomm_dlc *dlc)
301out: 298out:
302 write_unlock_bh(&rfcomm_dev_lock); 299 write_unlock_bh(&rfcomm_dev_lock);
303 300
304 if (err < 0) { 301 if (err < 0)
305 kfree(dev); 302 goto free;
306 return err;
307 }
308 303
309 dev->tty_dev = tty_register_device(rfcomm_tty_driver, dev->id, NULL); 304 dev->tty_dev = tty_register_device(rfcomm_tty_driver, dev->id, NULL);
310 305
311 if (IS_ERR(dev->tty_dev)) { 306 if (IS_ERR(dev->tty_dev)) {
312 err = PTR_ERR(dev->tty_dev); 307 err = PTR_ERR(dev->tty_dev);
313 list_del(&dev->list); 308 list_del(&dev->list);
314 kfree(dev); 309 goto free;
315 return err;
316 } 310 }
317 311
318 dev_set_drvdata(dev->tty_dev, dev); 312 dev_set_drvdata(dev->tty_dev, dev);
@@ -324,16 +318,20 @@ out:
324 BT_ERR("Failed to create channel attribute"); 318 BT_ERR("Failed to create channel attribute");
325 319
326 return dev->id; 320 return dev->id;
321
322free:
323 kfree(dev);
324 return err;
327} 325}
328 326
329static void rfcomm_dev_del(struct rfcomm_dev *dev) 327static void rfcomm_dev_del(struct rfcomm_dev *dev)
330{ 328{
331 BT_DBG("dev %p", dev); 329 BT_DBG("dev %p", dev);
332 330
333 if (test_bit(RFCOMM_TTY_RELEASED, &dev->flags)) 331 BUG_ON(test_and_set_bit(RFCOMM_TTY_RELEASED, &dev->flags));
334 BUG_ON(1); 332
335 else 333 if (atomic_read(&dev->opened) > 0)
336 set_bit(RFCOMM_TTY_RELEASED, &dev->flags); 334 return;
337 335
338 write_lock_bh(&rfcomm_dev_lock); 336 write_lock_bh(&rfcomm_dev_lock);
339 list_del_init(&dev->list); 337 list_del_init(&dev->list);
@@ -689,9 +687,10 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
689 if (!dev) 687 if (!dev)
690 return -ENODEV; 688 return -ENODEV;
691 689
692 BT_DBG("dev %p dst %s channel %d opened %d", dev, batostr(&dev->dst), dev->channel, dev->opened); 690 BT_DBG("dev %p dst %s channel %d opened %d", dev, batostr(&dev->dst),
691 dev->channel, atomic_read(&dev->opened));
693 692
694 if (dev->opened++ != 0) 693 if (atomic_inc_return(&dev->opened) > 1)
695 return 0; 694 return 0;
696 695
697 dlc = dev->dlc; 696 dlc = dev->dlc;
@@ -747,9 +746,10 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
747 if (!dev) 746 if (!dev)
748 return; 747 return;
749 748
750 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc, dev->opened); 749 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
750 atomic_read(&dev->opened));
751 751
752 if (--dev->opened == 0) { 752 if (atomic_dec_and_test(&dev->opened)) {
753 if (dev->tty_dev->parent) 753 if (dev->tty_dev->parent)
754 device_move(dev->tty_dev, NULL); 754 device_move(dev->tty_dev, NULL);
755 755
@@ -763,6 +763,14 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
763 tty->driver_data = NULL; 763 tty->driver_data = NULL;
764 dev->tty = NULL; 764 dev->tty = NULL;
765 rfcomm_dlc_unlock(dev->dlc); 765 rfcomm_dlc_unlock(dev->dlc);
766
767 if (test_bit(RFCOMM_TTY_RELEASED, &dev->flags)) {
768 write_lock_bh(&rfcomm_dev_lock);
769 list_del_init(&dev->list);
770 write_unlock_bh(&rfcomm_dev_lock);
771
772 rfcomm_dev_put(dev);
773 }
766 } 774 }
767 775
768 rfcomm_dev_put(dev); 776 rfcomm_dev_put(dev);
diff --git a/net/bluetooth/sco.c b/net/bluetooth/sco.c
index 0cc91e6da76d..46fd8bf9a690 100644
--- a/net/bluetooth/sco.c
+++ b/net/bluetooth/sco.c
@@ -48,11 +48,6 @@
48#include <net/bluetooth/hci_core.h> 48#include <net/bluetooth/hci_core.h>
49#include <net/bluetooth/sco.h> 49#include <net/bluetooth/sco.h>
50 50
51#ifndef CONFIG_BT_SCO_DEBUG
52#undef BT_DBG
53#define BT_DBG(D...)
54#endif
55
56#define VERSION "0.6" 51#define VERSION "0.6"
57 52
58static int disable_esco = 0; 53static int disable_esco = 0;
diff --git a/net/bridge/br_device.c b/net/bridge/br_device.c
index 6c023f0f8252..18538d7460d7 100644
--- a/net/bridge/br_device.c
+++ b/net/bridge/br_device.c
@@ -147,7 +147,7 @@ static int br_set_tx_csum(struct net_device *dev, u32 data)
147 return 0; 147 return 0;
148} 148}
149 149
150static struct ethtool_ops br_ethtool_ops = { 150static const struct ethtool_ops br_ethtool_ops = {
151 .get_drvinfo = br_getinfo, 151 .get_drvinfo = br_getinfo,
152 .get_link = ethtool_op_get_link, 152 .get_link = ethtool_op_get_link,
153 .get_tx_csum = ethtool_op_get_tx_csum, 153 .get_tx_csum = ethtool_op_get_tx_csum,
@@ -160,21 +160,25 @@ static struct ethtool_ops br_ethtool_ops = {
160 .get_flags = ethtool_op_get_flags, 160 .get_flags = ethtool_op_get_flags,
161}; 161};
162 162
163static const struct net_device_ops br_netdev_ops = {
164 .ndo_open = br_dev_open,
165 .ndo_stop = br_dev_stop,
166 .ndo_start_xmit = br_dev_xmit,
167 .ndo_set_mac_address = br_set_mac_address,
168 .ndo_set_multicast_list = br_dev_set_multicast_list,
169 .ndo_change_mtu = br_change_mtu,
170 .ndo_do_ioctl = br_dev_ioctl,
171};
172
163void br_dev_setup(struct net_device *dev) 173void br_dev_setup(struct net_device *dev)
164{ 174{
165 random_ether_addr(dev->dev_addr); 175 random_ether_addr(dev->dev_addr);
166 ether_setup(dev); 176 ether_setup(dev);
167 177
168 dev->do_ioctl = br_dev_ioctl; 178 dev->netdev_ops = &br_netdev_ops;
169 dev->hard_start_xmit = br_dev_xmit;
170 dev->open = br_dev_open;
171 dev->set_multicast_list = br_dev_set_multicast_list;
172 dev->change_mtu = br_change_mtu;
173 dev->destructor = free_netdev; 179 dev->destructor = free_netdev;
174 SET_ETHTOOL_OPS(dev, &br_ethtool_ops); 180 SET_ETHTOOL_OPS(dev, &br_ethtool_ops);
175 dev->stop = br_dev_stop;
176 dev->tx_queue_len = 0; 181 dev->tx_queue_len = 0;
177 dev->set_mac_address = br_set_mac_address;
178 dev->priv_flags = IFF_EBRIDGE; 182 dev->priv_flags = IFF_EBRIDGE;
179 183
180 dev->features = NETIF_F_SG | NETIF_F_FRAGLIST | NETIF_F_HIGHDMA | 184 dev->features = NETIF_F_SG | NETIF_F_FRAGLIST | NETIF_F_HIGHDMA |
diff --git a/net/bridge/br_if.c b/net/bridge/br_if.c
index 0a09ccf68c1c..727c5c510a60 100644
--- a/net/bridge/br_if.c
+++ b/net/bridge/br_if.c
@@ -373,7 +373,7 @@ int br_add_if(struct net_bridge *br, struct net_device *dev)
373 if (dev->flags & IFF_LOOPBACK || dev->type != ARPHRD_ETHER) 373 if (dev->flags & IFF_LOOPBACK || dev->type != ARPHRD_ETHER)
374 return -EINVAL; 374 return -EINVAL;
375 375
376 if (dev->hard_start_xmit == br_dev_xmit) 376 if (dev->netdev_ops->ndo_start_xmit == br_dev_xmit)
377 return -ELOOP; 377 return -ELOOP;
378 378
379 if (dev->br_port != NULL) 379 if (dev->br_port != NULL)
@@ -460,7 +460,7 @@ void br_net_exit(struct net *net)
460restart: 460restart:
461 for_each_netdev(net, dev) { 461 for_each_netdev(net, dev) {
462 if (dev->priv_flags & IFF_EBRIDGE) { 462 if (dev->priv_flags & IFF_EBRIDGE) {
463 del_br(dev->priv); 463 del_br(netdev_priv(dev));
464 goto restart; 464 goto restart;
465 } 465 }
466 } 466 }
diff --git a/net/bridge/br_netfilter.c b/net/bridge/br_netfilter.c
index 45f61c348e36..a65e43a17fbb 100644
--- a/net/bridge/br_netfilter.c
+++ b/net/bridge/br_netfilter.c
@@ -109,7 +109,6 @@ static struct dst_ops fake_dst_ops = {
109 .family = AF_INET, 109 .family = AF_INET,
110 .protocol = __constant_htons(ETH_P_IP), 110 .protocol = __constant_htons(ETH_P_IP),
111 .update_pmtu = fake_update_pmtu, 111 .update_pmtu = fake_update_pmtu,
112 .entry_size = sizeof(struct rtable),
113 .entries = ATOMIC_INIT(0), 112 .entries = ATOMIC_INIT(0),
114}; 113};
115 114
@@ -370,7 +369,7 @@ static int br_nf_pre_routing_finish(struct sk_buff *skb)
370 if (err != -EHOSTUNREACH || !in_dev || IN_DEV_FORWARD(in_dev)) 369 if (err != -EHOSTUNREACH || !in_dev || IN_DEV_FORWARD(in_dev))
371 goto free_skb; 370 goto free_skb;
372 371
373 if (!ip_route_output_key(&init_net, &rt, &fl)) { 372 if (!ip_route_output_key(dev_net(dev), &rt, &fl)) {
374 /* - Bridged-and-DNAT'ed traffic doesn't 373 /* - Bridged-and-DNAT'ed traffic doesn't
375 * require ip_forwarding. */ 374 * require ip_forwarding. */
376 if (((struct dst_entry *)rt)->dev == dev) { 375 if (((struct dst_entry *)rt)->dev == dev) {
@@ -951,35 +950,35 @@ static ctl_table brnf_table[] = {
951 .data = &brnf_call_arptables, 950 .data = &brnf_call_arptables,
952 .maxlen = sizeof(int), 951 .maxlen = sizeof(int),
953 .mode = 0644, 952 .mode = 0644,
954 .proc_handler = &brnf_sysctl_call_tables, 953 .proc_handler = brnf_sysctl_call_tables,
955 }, 954 },
956 { 955 {
957 .procname = "bridge-nf-call-iptables", 956 .procname = "bridge-nf-call-iptables",
958 .data = &brnf_call_iptables, 957 .data = &brnf_call_iptables,
959 .maxlen = sizeof(int), 958 .maxlen = sizeof(int),
960 .mode = 0644, 959 .mode = 0644,
961 .proc_handler = &brnf_sysctl_call_tables, 960 .proc_handler = brnf_sysctl_call_tables,
962 }, 961 },
963 { 962 {
964 .procname = "bridge-nf-call-ip6tables", 963 .procname = "bridge-nf-call-ip6tables",
965 .data = &brnf_call_ip6tables, 964 .data = &brnf_call_ip6tables,
966 .maxlen = sizeof(int), 965 .maxlen = sizeof(int),
967 .mode = 0644, 966 .mode = 0644,
968 .proc_handler = &brnf_sysctl_call_tables, 967 .proc_handler = brnf_sysctl_call_tables,
969 }, 968 },
970 { 969 {
971 .procname = "bridge-nf-filter-vlan-tagged", 970 .procname = "bridge-nf-filter-vlan-tagged",
972 .data = &brnf_filter_vlan_tagged, 971 .data = &brnf_filter_vlan_tagged,
973 .maxlen = sizeof(int), 972 .maxlen = sizeof(int),
974 .mode = 0644, 973 .mode = 0644,
975 .proc_handler = &brnf_sysctl_call_tables, 974 .proc_handler = brnf_sysctl_call_tables,
976 }, 975 },
977 { 976 {
978 .procname = "bridge-nf-filter-pppoe-tagged", 977 .procname = "bridge-nf-filter-pppoe-tagged",
979 .data = &brnf_filter_pppoe_tagged, 978 .data = &brnf_filter_pppoe_tagged,
980 .maxlen = sizeof(int), 979 .maxlen = sizeof(int),
981 .mode = 0644, 980 .mode = 0644,
982 .proc_handler = &brnf_sysctl_call_tables, 981 .proc_handler = brnf_sysctl_call_tables,
983 }, 982 },
984 { .ctl_name = 0 } 983 { .ctl_name = 0 }
985}; 984};
diff --git a/net/bridge/br_sysfs_br.c b/net/bridge/br_sysfs_br.c
index 158dee8b4965..603d89248e71 100644
--- a/net/bridge/br_sysfs_br.c
+++ b/net/bridge/br_sysfs_br.c
@@ -22,7 +22,7 @@
22#include "br_private.h" 22#include "br_private.h"
23 23
24#define to_dev(obj) container_of(obj, struct device, kobj) 24#define to_dev(obj) container_of(obj, struct device, kobj)
25#define to_bridge(cd) ((struct net_bridge *)(to_net_dev(cd)->priv)) 25#define to_bridge(cd) ((struct net_bridge *)netdev_priv(to_net_dev(cd)))
26 26
27/* 27/*
28 * Common code for storing bridge parameters. 28 * Common code for storing bridge parameters.
diff --git a/net/bridge/netfilter/ebt_log.c b/net/bridge/netfilter/ebt_log.c
index 3d33c608906a..d44cbf8c374a 100644
--- a/net/bridge/netfilter/ebt_log.c
+++ b/net/bridge/netfilter/ebt_log.c
@@ -79,7 +79,6 @@ print_ports(const struct sk_buff *skb, uint8_t protocol, int offset)
79 } 79 }
80} 80}
81 81
82#define myNIPQUAD(a) a[0], a[1], a[2], a[3]
83static void 82static void
84ebt_log_packet(u_int8_t pf, unsigned int hooknum, 83ebt_log_packet(u_int8_t pf, unsigned int hooknum,
85 const struct sk_buff *skb, const struct net_device *in, 84 const struct sk_buff *skb, const struct net_device *in,
@@ -113,9 +112,8 @@ ebt_log_packet(u_int8_t pf, unsigned int hooknum,
113 printk(" INCOMPLETE IP header"); 112 printk(" INCOMPLETE IP header");
114 goto out; 113 goto out;
115 } 114 }
116 printk(" IP SRC=%u.%u.%u.%u IP DST=%u.%u.%u.%u, IP " 115 printk(" IP SRC=%pI4 IP DST=%pI4, IP tos=0x%02X, IP proto=%d",
117 "tos=0x%02X, IP proto=%d", NIPQUAD(ih->saddr), 116 &ih->saddr, &ih->daddr, ih->tos, ih->protocol);
118 NIPQUAD(ih->daddr), ih->tos, ih->protocol);
119 print_ports(skb, ih->protocol, ih->ihl*4); 117 print_ports(skb, ih->protocol, ih->ihl*4);
120 goto out; 118 goto out;
121 } 119 }
@@ -133,10 +131,8 @@ ebt_log_packet(u_int8_t pf, unsigned int hooknum,
133 printk(" INCOMPLETE IPv6 header"); 131 printk(" INCOMPLETE IPv6 header");
134 goto out; 132 goto out;
135 } 133 }
136 printk(" IPv6 SRC=%x:%x:%x:%x:%x:%x:%x:%x " 134 printk(" IPv6 SRC=%pI6 IPv6 DST=%pI6, IPv6 priority=0x%01X, Next Header=%d",
137 "IPv6 DST=%x:%x:%x:%x:%x:%x:%x:%x, IPv6 " 135 &ih->saddr, &ih->daddr, ih->priority, ih->nexthdr);
138 "priority=0x%01X, Next Header=%d", NIP6(ih->saddr),
139 NIP6(ih->daddr), ih->priority, ih->nexthdr);
140 nexthdr = ih->nexthdr; 136 nexthdr = ih->nexthdr;
141 offset_ph = ipv6_skip_exthdr(skb, sizeof(_iph), &nexthdr); 137 offset_ph = ipv6_skip_exthdr(skb, sizeof(_iph), &nexthdr);
142 if (offset_ph == -1) 138 if (offset_ph == -1)
@@ -177,12 +173,10 @@ ebt_log_packet(u_int8_t pf, unsigned int hooknum,
177 } 173 }
178 printk(" ARP MAC SRC="); 174 printk(" ARP MAC SRC=");
179 print_MAC(ap->mac_src); 175 print_MAC(ap->mac_src);
180 printk(" ARP IP SRC=%u.%u.%u.%u", 176 printk(" ARP IP SRC=%pI4", ap->ip_src);
181 myNIPQUAD(ap->ip_src));
182 printk(" ARP MAC DST="); 177 printk(" ARP MAC DST=");
183 print_MAC(ap->mac_dst); 178 print_MAC(ap->mac_dst);
184 printk(" ARP IP DST=%u.%u.%u.%u", 179 printk(" ARP IP DST=%pI4", ap->ip_dst);
185 myNIPQUAD(ap->ip_dst));
186 } 180 }
187 } 181 }
188out: 182out:
diff --git a/net/bridge/netfilter/ebtable_broute.c b/net/bridge/netfilter/ebtable_broute.c
index 246626bb0c87..8604dfc1fc3b 100644
--- a/net/bridge/netfilter/ebtable_broute.c
+++ b/net/bridge/netfilter/ebtable_broute.c
@@ -56,29 +56,47 @@ static int ebt_broute(struct sk_buff *skb)
56 int ret; 56 int ret;
57 57
58 ret = ebt_do_table(NF_BR_BROUTING, skb, skb->dev, NULL, 58 ret = ebt_do_table(NF_BR_BROUTING, skb, skb->dev, NULL,
59 &broute_table); 59 dev_net(skb->dev)->xt.broute_table);
60 if (ret == NF_DROP) 60 if (ret == NF_DROP)
61 return 1; /* route it */ 61 return 1; /* route it */
62 return 0; /* bridge it */ 62 return 0; /* bridge it */
63} 63}
64 64
65static int __net_init broute_net_init(struct net *net)
66{
67 net->xt.broute_table = ebt_register_table(net, &broute_table);
68 if (IS_ERR(net->xt.broute_table))
69 return PTR_ERR(net->xt.broute_table);
70 return 0;
71}
72
73static void __net_exit broute_net_exit(struct net *net)
74{
75 ebt_unregister_table(net->xt.broute_table);
76}
77
78static struct pernet_operations broute_net_ops = {
79 .init = broute_net_init,
80 .exit = broute_net_exit,
81};
82
65static int __init ebtable_broute_init(void) 83static int __init ebtable_broute_init(void)
66{ 84{
67 int ret; 85 int ret;
68 86
69 ret = ebt_register_table(&broute_table); 87 ret = register_pernet_subsys(&broute_net_ops);
70 if (ret < 0) 88 if (ret < 0)
71 return ret; 89 return ret;
72 /* see br_input.c */ 90 /* see br_input.c */
73 rcu_assign_pointer(br_should_route_hook, ebt_broute); 91 rcu_assign_pointer(br_should_route_hook, ebt_broute);
74 return ret; 92 return 0;
75} 93}
76 94
77static void __exit ebtable_broute_fini(void) 95static void __exit ebtable_broute_fini(void)
78{ 96{
79 rcu_assign_pointer(br_should_route_hook, NULL); 97 rcu_assign_pointer(br_should_route_hook, NULL);
80 synchronize_net(); 98 synchronize_net();
81 ebt_unregister_table(&broute_table); 99 unregister_pernet_subsys(&broute_net_ops);
82} 100}
83 101
84module_init(ebtable_broute_init); 102module_init(ebtable_broute_init);
diff --git a/net/bridge/netfilter/ebtable_filter.c b/net/bridge/netfilter/ebtable_filter.c
index 1a58af51a2e2..2b2e8040a9c6 100644
--- a/net/bridge/netfilter/ebtable_filter.c
+++ b/net/bridge/netfilter/ebtable_filter.c
@@ -61,29 +61,36 @@ static struct ebt_table frame_filter =
61}; 61};
62 62
63static unsigned int 63static unsigned int
64ebt_hook(unsigned int hook, struct sk_buff *skb, const struct net_device *in, 64ebt_in_hook(unsigned int hook, struct sk_buff *skb, const struct net_device *in,
65 const struct net_device *out, int (*okfn)(struct sk_buff *)) 65 const struct net_device *out, int (*okfn)(struct sk_buff *))
66{ 66{
67 return ebt_do_table(hook, skb, in, out, &frame_filter); 67 return ebt_do_table(hook, skb, in, out, dev_net(in)->xt.frame_filter);
68}
69
70static unsigned int
71ebt_out_hook(unsigned int hook, struct sk_buff *skb, const struct net_device *in,
72 const struct net_device *out, int (*okfn)(struct sk_buff *))
73{
74 return ebt_do_table(hook, skb, in, out, dev_net(out)->xt.frame_filter);
68} 75}
69 76
70static struct nf_hook_ops ebt_ops_filter[] __read_mostly = { 77static struct nf_hook_ops ebt_ops_filter[] __read_mostly = {
71 { 78 {
72 .hook = ebt_hook, 79 .hook = ebt_in_hook,
73 .owner = THIS_MODULE, 80 .owner = THIS_MODULE,
74 .pf = PF_BRIDGE, 81 .pf = PF_BRIDGE,
75 .hooknum = NF_BR_LOCAL_IN, 82 .hooknum = NF_BR_LOCAL_IN,
76 .priority = NF_BR_PRI_FILTER_BRIDGED, 83 .priority = NF_BR_PRI_FILTER_BRIDGED,
77 }, 84 },
78 { 85 {
79 .hook = ebt_hook, 86 .hook = ebt_in_hook,
80 .owner = THIS_MODULE, 87 .owner = THIS_MODULE,
81 .pf = PF_BRIDGE, 88 .pf = PF_BRIDGE,
82 .hooknum = NF_BR_FORWARD, 89 .hooknum = NF_BR_FORWARD,
83 .priority = NF_BR_PRI_FILTER_BRIDGED, 90 .priority = NF_BR_PRI_FILTER_BRIDGED,
84 }, 91 },
85 { 92 {
86 .hook = ebt_hook, 93 .hook = ebt_out_hook,
87 .owner = THIS_MODULE, 94 .owner = THIS_MODULE,
88 .pf = PF_BRIDGE, 95 .pf = PF_BRIDGE,
89 .hooknum = NF_BR_LOCAL_OUT, 96 .hooknum = NF_BR_LOCAL_OUT,
@@ -91,23 +98,41 @@ static struct nf_hook_ops ebt_ops_filter[] __read_mostly = {
91 }, 98 },
92}; 99};
93 100
101static int __net_init frame_filter_net_init(struct net *net)
102{
103 net->xt.frame_filter = ebt_register_table(net, &frame_filter);
104 if (IS_ERR(net->xt.frame_filter))
105 return PTR_ERR(net->xt.frame_filter);
106 return 0;
107}
108
109static void __net_exit frame_filter_net_exit(struct net *net)
110{
111 ebt_unregister_table(net->xt.frame_filter);
112}
113
114static struct pernet_operations frame_filter_net_ops = {
115 .init = frame_filter_net_init,
116 .exit = frame_filter_net_exit,
117};
118
94static int __init ebtable_filter_init(void) 119static int __init ebtable_filter_init(void)
95{ 120{
96 int ret; 121 int ret;
97 122
98 ret = ebt_register_table(&frame_filter); 123 ret = register_pernet_subsys(&frame_filter_net_ops);
99 if (ret < 0) 124 if (ret < 0)
100 return ret; 125 return ret;
101 ret = nf_register_hooks(ebt_ops_filter, ARRAY_SIZE(ebt_ops_filter)); 126 ret = nf_register_hooks(ebt_ops_filter, ARRAY_SIZE(ebt_ops_filter));
102 if (ret < 0) 127 if (ret < 0)
103 ebt_unregister_table(&frame_filter); 128 unregister_pernet_subsys(&frame_filter_net_ops);
104 return ret; 129 return ret;
105} 130}
106 131
107static void __exit ebtable_filter_fini(void) 132static void __exit ebtable_filter_fini(void)
108{ 133{
109 nf_unregister_hooks(ebt_ops_filter, ARRAY_SIZE(ebt_ops_filter)); 134 nf_unregister_hooks(ebt_ops_filter, ARRAY_SIZE(ebt_ops_filter));
110 ebt_unregister_table(&frame_filter); 135 unregister_pernet_subsys(&frame_filter_net_ops);
111} 136}
112 137
113module_init(ebtable_filter_init); 138module_init(ebtable_filter_init);
diff --git a/net/bridge/netfilter/ebtable_nat.c b/net/bridge/netfilter/ebtable_nat.c
index f60c1e78e575..3fe1ae87e35f 100644
--- a/net/bridge/netfilter/ebtable_nat.c
+++ b/net/bridge/netfilter/ebtable_nat.c
@@ -61,36 +61,36 @@ static struct ebt_table frame_nat =
61}; 61};
62 62
63static unsigned int 63static unsigned int
64ebt_nat_dst(unsigned int hook, struct sk_buff *skb, const struct net_device *in 64ebt_nat_in(unsigned int hook, struct sk_buff *skb, const struct net_device *in
65 , const struct net_device *out, int (*okfn)(struct sk_buff *)) 65 , const struct net_device *out, int (*okfn)(struct sk_buff *))
66{ 66{
67 return ebt_do_table(hook, skb, in, out, &frame_nat); 67 return ebt_do_table(hook, skb, in, out, dev_net(in)->xt.frame_nat);
68} 68}
69 69
70static unsigned int 70static unsigned int
71ebt_nat_src(unsigned int hook, struct sk_buff *skb, const struct net_device *in 71ebt_nat_out(unsigned int hook, struct sk_buff *skb, const struct net_device *in
72 , const struct net_device *out, int (*okfn)(struct sk_buff *)) 72 , const struct net_device *out, int (*okfn)(struct sk_buff *))
73{ 73{
74 return ebt_do_table(hook, skb, in, out, &frame_nat); 74 return ebt_do_table(hook, skb, in, out, dev_net(out)->xt.frame_nat);
75} 75}
76 76
77static struct nf_hook_ops ebt_ops_nat[] __read_mostly = { 77static struct nf_hook_ops ebt_ops_nat[] __read_mostly = {
78 { 78 {
79 .hook = ebt_nat_dst, 79 .hook = ebt_nat_out,
80 .owner = THIS_MODULE, 80 .owner = THIS_MODULE,
81 .pf = PF_BRIDGE, 81 .pf = PF_BRIDGE,
82 .hooknum = NF_BR_LOCAL_OUT, 82 .hooknum = NF_BR_LOCAL_OUT,
83 .priority = NF_BR_PRI_NAT_DST_OTHER, 83 .priority = NF_BR_PRI_NAT_DST_OTHER,
84 }, 84 },
85 { 85 {
86 .hook = ebt_nat_src, 86 .hook = ebt_nat_out,
87 .owner = THIS_MODULE, 87 .owner = THIS_MODULE,
88 .pf = PF_BRIDGE, 88 .pf = PF_BRIDGE,
89 .hooknum = NF_BR_POST_ROUTING, 89 .hooknum = NF_BR_POST_ROUTING,
90 .priority = NF_BR_PRI_NAT_SRC, 90 .priority = NF_BR_PRI_NAT_SRC,
91 }, 91 },
92 { 92 {
93 .hook = ebt_nat_dst, 93 .hook = ebt_nat_in,
94 .owner = THIS_MODULE, 94 .owner = THIS_MODULE,
95 .pf = PF_BRIDGE, 95 .pf = PF_BRIDGE,
96 .hooknum = NF_BR_PRE_ROUTING, 96 .hooknum = NF_BR_PRE_ROUTING,
@@ -98,23 +98,41 @@ static struct nf_hook_ops ebt_ops_nat[] __read_mostly = {
98 }, 98 },
99}; 99};
100 100
101static int __net_init frame_nat_net_init(struct net *net)
102{
103 net->xt.frame_nat = ebt_register_table(net, &frame_nat);
104 if (IS_ERR(net->xt.frame_nat))
105 return PTR_ERR(net->xt.frame_nat);
106 return 0;
107}
108
109static void __net_exit frame_nat_net_exit(struct net *net)
110{
111 ebt_unregister_table(net->xt.frame_nat);
112}
113
114static struct pernet_operations frame_nat_net_ops = {
115 .init = frame_nat_net_init,
116 .exit = frame_nat_net_exit,
117};
118
101static int __init ebtable_nat_init(void) 119static int __init ebtable_nat_init(void)
102{ 120{
103 int ret; 121 int ret;
104 122
105 ret = ebt_register_table(&frame_nat); 123 ret = register_pernet_subsys(&frame_nat_net_ops);
106 if (ret < 0) 124 if (ret < 0)
107 return ret; 125 return ret;
108 ret = nf_register_hooks(ebt_ops_nat, ARRAY_SIZE(ebt_ops_nat)); 126 ret = nf_register_hooks(ebt_ops_nat, ARRAY_SIZE(ebt_ops_nat));
109 if (ret < 0) 127 if (ret < 0)
110 ebt_unregister_table(&frame_nat); 128 unregister_pernet_subsys(&frame_nat_net_ops);
111 return ret; 129 return ret;
112} 130}
113 131
114static void __exit ebtable_nat_fini(void) 132static void __exit ebtable_nat_fini(void)
115{ 133{
116 nf_unregister_hooks(ebt_ops_nat, ARRAY_SIZE(ebt_ops_nat)); 134 nf_unregister_hooks(ebt_ops_nat, ARRAY_SIZE(ebt_ops_nat));
117 ebt_unregister_table(&frame_nat); 135 unregister_pernet_subsys(&frame_nat_net_ops);
118} 136}
119 137
120module_init(ebtable_nat_init); 138module_init(ebtable_nat_init);
diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
index 0fa208e86405..fa108c46e851 100644
--- a/net/bridge/netfilter/ebtables.c
+++ b/net/bridge/netfilter/ebtables.c
@@ -55,7 +55,6 @@
55 55
56 56
57static DEFINE_MUTEX(ebt_mutex); 57static DEFINE_MUTEX(ebt_mutex);
58static LIST_HEAD(ebt_tables);
59 58
60static struct xt_target ebt_standard_target = { 59static struct xt_target ebt_standard_target = {
61 .name = "standard", 60 .name = "standard",
@@ -315,9 +314,11 @@ find_inlist_lock(struct list_head *head, const char *name, const char *prefix,
315} 314}
316 315
317static inline struct ebt_table * 316static inline struct ebt_table *
318find_table_lock(const char *name, int *error, struct mutex *mutex) 317find_table_lock(struct net *net, const char *name, int *error,
318 struct mutex *mutex)
319{ 319{
320 return find_inlist_lock(&ebt_tables, name, "ebtable_", error, mutex); 320 return find_inlist_lock(&net->xt.tables[NFPROTO_BRIDGE], name,
321 "ebtable_", error, mutex);
321} 322}
322 323
323static inline int 324static inline int
@@ -944,7 +945,7 @@ static void get_counters(struct ebt_counter *oldcounters,
944} 945}
945 946
946/* replace the table */ 947/* replace the table */
947static int do_replace(void __user *user, unsigned int len) 948static int do_replace(struct net *net, void __user *user, unsigned int len)
948{ 949{
949 int ret, i, countersize; 950 int ret, i, countersize;
950 struct ebt_table_info *newinfo; 951 struct ebt_table_info *newinfo;
@@ -1016,7 +1017,7 @@ static int do_replace(void __user *user, unsigned int len)
1016 if (ret != 0) 1017 if (ret != 0)
1017 goto free_counterstmp; 1018 goto free_counterstmp;
1018 1019
1019 t = find_table_lock(tmp.name, &ret, &ebt_mutex); 1020 t = find_table_lock(net, tmp.name, &ret, &ebt_mutex);
1020 if (!t) { 1021 if (!t) {
1021 ret = -ENOENT; 1022 ret = -ENOENT;
1022 goto free_iterate; 1023 goto free_iterate;
@@ -1097,7 +1098,7 @@ free_newinfo:
1097 return ret; 1098 return ret;
1098} 1099}
1099 1100
1100int ebt_register_table(struct ebt_table *table) 1101struct ebt_table *ebt_register_table(struct net *net, struct ebt_table *table)
1101{ 1102{
1102 struct ebt_table_info *newinfo; 1103 struct ebt_table_info *newinfo;
1103 struct ebt_table *t; 1104 struct ebt_table *t;
@@ -1109,14 +1110,21 @@ int ebt_register_table(struct ebt_table *table)
1109 repl->entries_size == 0 || 1110 repl->entries_size == 0 ||
1110 repl->counters || table->private) { 1111 repl->counters || table->private) {
1111 BUGPRINT("Bad table data for ebt_register_table!!!\n"); 1112 BUGPRINT("Bad table data for ebt_register_table!!!\n");
1112 return -EINVAL; 1113 return ERR_PTR(-EINVAL);
1114 }
1115
1116 /* Don't add one table to multiple lists. */
1117 table = kmemdup(table, sizeof(struct ebt_table), GFP_KERNEL);
1118 if (!table) {
1119 ret = -ENOMEM;
1120 goto out;
1113 } 1121 }
1114 1122
1115 countersize = COUNTER_OFFSET(repl->nentries) * nr_cpu_ids; 1123 countersize = COUNTER_OFFSET(repl->nentries) * nr_cpu_ids;
1116 newinfo = vmalloc(sizeof(*newinfo) + countersize); 1124 newinfo = vmalloc(sizeof(*newinfo) + countersize);
1117 ret = -ENOMEM; 1125 ret = -ENOMEM;
1118 if (!newinfo) 1126 if (!newinfo)
1119 return -ENOMEM; 1127 goto free_table;
1120 1128
1121 p = vmalloc(repl->entries_size); 1129 p = vmalloc(repl->entries_size);
1122 if (!p) 1130 if (!p)
@@ -1148,7 +1156,7 @@ int ebt_register_table(struct ebt_table *table)
1148 1156
1149 if (table->check && table->check(newinfo, table->valid_hooks)) { 1157 if (table->check && table->check(newinfo, table->valid_hooks)) {
1150 BUGPRINT("The table doesn't like its own initial data, lol\n"); 1158 BUGPRINT("The table doesn't like its own initial data, lol\n");
1151 return -EINVAL; 1159 return ERR_PTR(-EINVAL);
1152 } 1160 }
1153 1161
1154 table->private = newinfo; 1162 table->private = newinfo;
@@ -1157,7 +1165,7 @@ int ebt_register_table(struct ebt_table *table)
1157 if (ret != 0) 1165 if (ret != 0)
1158 goto free_chainstack; 1166 goto free_chainstack;
1159 1167
1160 list_for_each_entry(t, &ebt_tables, list) { 1168 list_for_each_entry(t, &net->xt.tables[NFPROTO_BRIDGE], list) {
1161 if (strcmp(t->name, table->name) == 0) { 1169 if (strcmp(t->name, table->name) == 0) {
1162 ret = -EEXIST; 1170 ret = -EEXIST;
1163 BUGPRINT("Table name already exists\n"); 1171 BUGPRINT("Table name already exists\n");
@@ -1170,9 +1178,9 @@ int ebt_register_table(struct ebt_table *table)
1170 ret = -ENOENT; 1178 ret = -ENOENT;
1171 goto free_unlock; 1179 goto free_unlock;
1172 } 1180 }
1173 list_add(&table->list, &ebt_tables); 1181 list_add(&table->list, &net->xt.tables[NFPROTO_BRIDGE]);
1174 mutex_unlock(&ebt_mutex); 1182 mutex_unlock(&ebt_mutex);
1175 return 0; 1183 return table;
1176free_unlock: 1184free_unlock:
1177 mutex_unlock(&ebt_mutex); 1185 mutex_unlock(&ebt_mutex);
1178free_chainstack: 1186free_chainstack:
@@ -1184,7 +1192,10 @@ free_chainstack:
1184 vfree(newinfo->entries); 1192 vfree(newinfo->entries);
1185free_newinfo: 1193free_newinfo:
1186 vfree(newinfo); 1194 vfree(newinfo);
1187 return ret; 1195free_table:
1196 kfree(table);
1197out:
1198 return ERR_PTR(ret);
1188} 1199}
1189 1200
1190void ebt_unregister_table(struct ebt_table *table) 1201void ebt_unregister_table(struct ebt_table *table)
@@ -1198,6 +1209,10 @@ void ebt_unregister_table(struct ebt_table *table)
1198 mutex_lock(&ebt_mutex); 1209 mutex_lock(&ebt_mutex);
1199 list_del(&table->list); 1210 list_del(&table->list);
1200 mutex_unlock(&ebt_mutex); 1211 mutex_unlock(&ebt_mutex);
1212 EBT_ENTRY_ITERATE(table->private->entries, table->private->entries_size,
1213 ebt_cleanup_entry, NULL);
1214 if (table->private->nentries)
1215 module_put(table->me);
1201 vfree(table->private->entries); 1216 vfree(table->private->entries);
1202 if (table->private->chainstack) { 1217 if (table->private->chainstack) {
1203 for_each_possible_cpu(i) 1218 for_each_possible_cpu(i)
@@ -1205,10 +1220,11 @@ void ebt_unregister_table(struct ebt_table *table)
1205 vfree(table->private->chainstack); 1220 vfree(table->private->chainstack);
1206 } 1221 }
1207 vfree(table->private); 1222 vfree(table->private);
1223 kfree(table);
1208} 1224}
1209 1225
1210/* userspace just supplied us with counters */ 1226/* userspace just supplied us with counters */
1211static int update_counters(void __user *user, unsigned int len) 1227static int update_counters(struct net *net, void __user *user, unsigned int len)
1212{ 1228{
1213 int i, ret; 1229 int i, ret;
1214 struct ebt_counter *tmp; 1230 struct ebt_counter *tmp;
@@ -1228,7 +1244,7 @@ static int update_counters(void __user *user, unsigned int len)
1228 return -ENOMEM; 1244 return -ENOMEM;
1229 } 1245 }
1230 1246
1231 t = find_table_lock(hlp.name, &ret, &ebt_mutex); 1247 t = find_table_lock(net, hlp.name, &ret, &ebt_mutex);
1232 if (!t) 1248 if (!t)
1233 goto free_tmp; 1249 goto free_tmp;
1234 1250
@@ -1386,10 +1402,10 @@ static int do_ebt_set_ctl(struct sock *sk,
1386 1402
1387 switch(cmd) { 1403 switch(cmd) {
1388 case EBT_SO_SET_ENTRIES: 1404 case EBT_SO_SET_ENTRIES:
1389 ret = do_replace(user, len); 1405 ret = do_replace(sock_net(sk), user, len);
1390 break; 1406 break;
1391 case EBT_SO_SET_COUNTERS: 1407 case EBT_SO_SET_COUNTERS:
1392 ret = update_counters(user, len); 1408 ret = update_counters(sock_net(sk), user, len);
1393 break; 1409 break;
1394 default: 1410 default:
1395 ret = -EINVAL; 1411 ret = -EINVAL;
@@ -1406,7 +1422,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
1406 if (copy_from_user(&tmp, user, sizeof(tmp))) 1422 if (copy_from_user(&tmp, user, sizeof(tmp)))
1407 return -EFAULT; 1423 return -EFAULT;
1408 1424
1409 t = find_table_lock(tmp.name, &ret, &ebt_mutex); 1425 t = find_table_lock(sock_net(sk), tmp.name, &ret, &ebt_mutex);
1410 if (!t) 1426 if (!t)
1411 return ret; 1427 return ret;
1412 1428
diff --git a/net/can/raw.c b/net/can/raw.c
index 6e0663faaf9f..27aab63df467 100644
--- a/net/can/raw.c
+++ b/net/can/raw.c
@@ -641,17 +641,12 @@ static int raw_sendmsg(struct kiocb *iocb, struct socket *sock,
641 641
642 skb = sock_alloc_send_skb(sk, size, msg->msg_flags & MSG_DONTWAIT, 642 skb = sock_alloc_send_skb(sk, size, msg->msg_flags & MSG_DONTWAIT,
643 &err); 643 &err);
644 if (!skb) { 644 if (!skb)
645 dev_put(dev); 645 goto put_dev;
646 return err;
647 }
648 646
649 err = memcpy_fromiovec(skb_put(skb, size), msg->msg_iov, size); 647 err = memcpy_fromiovec(skb_put(skb, size), msg->msg_iov, size);
650 if (err < 0) { 648 if (err < 0)
651 kfree_skb(skb); 649 goto free_skb;
652 dev_put(dev);
653 return err;
654 }
655 skb->dev = dev; 650 skb->dev = dev;
656 skb->sk = sk; 651 skb->sk = sk;
657 652
@@ -660,9 +655,16 @@ static int raw_sendmsg(struct kiocb *iocb, struct socket *sock,
660 dev_put(dev); 655 dev_put(dev);
661 656
662 if (err) 657 if (err)
663 return err; 658 goto send_failed;
664 659
665 return size; 660 return size;
661
662free_skb:
663 kfree_skb(skb);
664put_dev:
665 dev_put(dev);
666send_failed:
667 return err;
666} 668}
667 669
668static int raw_recvmsg(struct kiocb *iocb, struct socket *sock, 670static int raw_recvmsg(struct kiocb *iocb, struct socket *sock,
diff --git a/net/core/datagram.c b/net/core/datagram.c
index ee631843c2f5..5e2ac0c4b07c 100644
--- a/net/core/datagram.c
+++ b/net/core/datagram.c
@@ -209,7 +209,7 @@ struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags,
209void skb_free_datagram(struct sock *sk, struct sk_buff *skb) 209void skb_free_datagram(struct sock *sk, struct sk_buff *skb)
210{ 210{
211 kfree_skb(skb); 211 kfree_skb(skb);
212 sk_mem_reclaim(sk); 212 sk_mem_reclaim_partial(sk);
213} 213}
214 214
215/** 215/**
@@ -248,8 +248,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
248 spin_unlock_bh(&sk->sk_receive_queue.lock); 248 spin_unlock_bh(&sk->sk_receive_queue.lock);
249 } 249 }
250 250
251 kfree_skb(skb); 251 skb_free_datagram(sk, skb);
252 sk_mem_reclaim(sk);
253 return err; 252 return err;
254} 253}
255 254
diff --git a/net/core/dev.c b/net/core/dev.c
index 89912ae6de65..446424027d24 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -108,7 +108,6 @@
108#include <linux/init.h> 108#include <linux/init.h>
109#include <linux/kmod.h> 109#include <linux/kmod.h>
110#include <linux/module.h> 110#include <linux/module.h>
111#include <linux/kallsyms.h>
112#include <linux/netpoll.h> 111#include <linux/netpoll.h>
113#include <linux/rcupdate.h> 112#include <linux/rcupdate.h>
114#include <linux/delay.h> 113#include <linux/delay.h>
@@ -130,6 +129,9 @@
130 129
131#include "net-sysfs.h" 130#include "net-sysfs.h"
132 131
132/* Instead of increasing this, you should create a hash table. */
133#define MAX_GRO_SKBS 8
134
133/* 135/*
134 * The list of packet types we will receive (as opposed to discard) 136 * The list of packet types we will receive (as opposed to discard)
135 * and the routines to invoke. 137 * and the routines to invoke.
@@ -281,8 +283,8 @@ static const unsigned short netdev_lock_type[] =
281 ARPHRD_PIMREG, ARPHRD_HIPPI, ARPHRD_ASH, ARPHRD_ECONET, 283 ARPHRD_PIMREG, ARPHRD_HIPPI, ARPHRD_ASH, ARPHRD_ECONET,
282 ARPHRD_IRDA, ARPHRD_FCPP, ARPHRD_FCAL, ARPHRD_FCPL, 284 ARPHRD_IRDA, ARPHRD_FCPP, ARPHRD_FCAL, ARPHRD_FCPL,
283 ARPHRD_FCFABRIC, ARPHRD_IEEE802_TR, ARPHRD_IEEE80211, 285 ARPHRD_FCFABRIC, ARPHRD_IEEE802_TR, ARPHRD_IEEE80211,
284 ARPHRD_IEEE80211_PRISM, ARPHRD_IEEE80211_RADIOTAP, ARPHRD_VOID, 286 ARPHRD_IEEE80211_PRISM, ARPHRD_IEEE80211_RADIOTAP, ARPHRD_PHONET,
285 ARPHRD_NONE}; 287 ARPHRD_PHONET_PIPE, ARPHRD_VOID, ARPHRD_NONE};
286 288
287static const char *netdev_lock_name[] = 289static const char *netdev_lock_name[] =
288 {"_xmit_NETROM", "_xmit_ETHER", "_xmit_EETHER", "_xmit_AX25", 290 {"_xmit_NETROM", "_xmit_ETHER", "_xmit_EETHER", "_xmit_AX25",
@@ -298,8 +300,8 @@ static const char *netdev_lock_name[] =
298 "_xmit_PIMREG", "_xmit_HIPPI", "_xmit_ASH", "_xmit_ECONET", 300 "_xmit_PIMREG", "_xmit_HIPPI", "_xmit_ASH", "_xmit_ECONET",
299 "_xmit_IRDA", "_xmit_FCPP", "_xmit_FCAL", "_xmit_FCPL", 301 "_xmit_IRDA", "_xmit_FCPP", "_xmit_FCAL", "_xmit_FCPL",
300 "_xmit_FCFABRIC", "_xmit_IEEE802_TR", "_xmit_IEEE80211", 302 "_xmit_FCFABRIC", "_xmit_IEEE802_TR", "_xmit_IEEE80211",
301 "_xmit_IEEE80211_PRISM", "_xmit_IEEE80211_RADIOTAP", "_xmit_VOID", 303 "_xmit_IEEE80211_PRISM", "_xmit_IEEE80211_RADIOTAP", "_xmit_PHONET",
302 "_xmit_NONE"}; 304 "_xmit_PHONET_PIPE", "_xmit_VOID", "_xmit_NONE"};
303 305
304static struct lock_class_key netdev_xmit_lock_key[ARRAY_SIZE(netdev_lock_type)]; 306static struct lock_class_key netdev_xmit_lock_key[ARRAY_SIZE(netdev_lock_type)];
305static struct lock_class_key netdev_addr_lock_key[ARRAY_SIZE(netdev_lock_type)]; 307static struct lock_class_key netdev_addr_lock_key[ARRAY_SIZE(netdev_lock_type)];
@@ -924,10 +926,15 @@ int dev_change_name(struct net_device *dev, const char *newname)
924 strlcpy(dev->name, newname, IFNAMSIZ); 926 strlcpy(dev->name, newname, IFNAMSIZ);
925 927
926rollback: 928rollback:
927 ret = device_rename(&dev->dev, dev->name); 929 /* For now only devices in the initial network namespace
928 if (ret) { 930 * are in sysfs.
929 memcpy(dev->name, oldname, IFNAMSIZ); 931 */
930 return ret; 932 if (net == &init_net) {
933 ret = device_rename(&dev->dev, dev->name);
934 if (ret) {
935 memcpy(dev->name, oldname, IFNAMSIZ);
936 return ret;
937 }
931 } 938 }
932 939
933 write_lock_bh(&dev_base_lock); 940 write_lock_bh(&dev_base_lock);
@@ -1055,6 +1062,7 @@ void dev_load(struct net *net, const char *name)
1055 */ 1062 */
1056int dev_open(struct net_device *dev) 1063int dev_open(struct net_device *dev)
1057{ 1064{
1065 const struct net_device_ops *ops = dev->netdev_ops;
1058 int ret = 0; 1066 int ret = 0;
1059 1067
1060 ASSERT_RTNL(); 1068 ASSERT_RTNL();
@@ -1077,11 +1085,11 @@ int dev_open(struct net_device *dev)
1077 */ 1085 */
1078 set_bit(__LINK_STATE_START, &dev->state); 1086 set_bit(__LINK_STATE_START, &dev->state);
1079 1087
1080 if (dev->validate_addr) 1088 if (ops->ndo_validate_addr)
1081 ret = dev->validate_addr(dev); 1089 ret = ops->ndo_validate_addr(dev);
1082 1090
1083 if (!ret && dev->open) 1091 if (!ret && ops->ndo_open)
1084 ret = dev->open(dev); 1092 ret = ops->ndo_open(dev);
1085 1093
1086 /* 1094 /*
1087 * If it went open OK then: 1095 * If it went open OK then:
@@ -1125,6 +1133,7 @@ int dev_open(struct net_device *dev)
1125 */ 1133 */
1126int dev_close(struct net_device *dev) 1134int dev_close(struct net_device *dev)
1127{ 1135{
1136 const struct net_device_ops *ops = dev->netdev_ops;
1128 ASSERT_RTNL(); 1137 ASSERT_RTNL();
1129 1138
1130 might_sleep(); 1139 might_sleep();
@@ -1157,8 +1166,8 @@ int dev_close(struct net_device *dev)
1157 * We allow it to be called even after a DETACH hot-plug 1166 * We allow it to be called even after a DETACH hot-plug
1158 * event. 1167 * event.
1159 */ 1168 */
1160 if (dev->stop) 1169 if (ops->ndo_stop)
1161 dev->stop(dev); 1170 ops->ndo_stop(dev);
1162 1171
1163 /* 1172 /*
1164 * Device is now down. 1173 * Device is now down.
@@ -1527,8 +1536,6 @@ struct sk_buff *skb_gso_segment(struct sk_buff *skb, int features)
1527 __be16 type = skb->protocol; 1536 __be16 type = skb->protocol;
1528 int err; 1537 int err;
1529 1538
1530 BUG_ON(skb_shinfo(skb)->frag_list);
1531
1532 skb_reset_mac_header(skb); 1539 skb_reset_mac_header(skb);
1533 skb->mac_len = skb->network_header - skb->mac_header; 1540 skb->mac_len = skb->network_header - skb->mac_header;
1534 __skb_pull(skb, skb->mac_len); 1541 __skb_pull(skb, skb->mac_len);
@@ -1654,6 +1661,9 @@ static int dev_gso_segment(struct sk_buff *skb)
1654int dev_hard_start_xmit(struct sk_buff *skb, struct net_device *dev, 1661int dev_hard_start_xmit(struct sk_buff *skb, struct net_device *dev,
1655 struct netdev_queue *txq) 1662 struct netdev_queue *txq)
1656{ 1663{
1664 const struct net_device_ops *ops = dev->netdev_ops;
1665
1666 prefetch(&dev->netdev_ops->ndo_start_xmit);
1657 if (likely(!skb->next)) { 1667 if (likely(!skb->next)) {
1658 if (!list_empty(&ptype_all)) 1668 if (!list_empty(&ptype_all))
1659 dev_queue_xmit_nit(skb, dev); 1669 dev_queue_xmit_nit(skb, dev);
@@ -1665,7 +1675,7 @@ int dev_hard_start_xmit(struct sk_buff *skb, struct net_device *dev,
1665 goto gso; 1675 goto gso;
1666 } 1676 }
1667 1677
1668 return dev->hard_start_xmit(skb, dev); 1678 return ops->ndo_start_xmit(skb, dev);
1669 } 1679 }
1670 1680
1671gso: 1681gso:
@@ -1675,7 +1685,7 @@ gso:
1675 1685
1676 skb->next = nskb->next; 1686 skb->next = nskb->next;
1677 nskb->next = NULL; 1687 nskb->next = NULL;
1678 rc = dev->hard_start_xmit(nskb, dev); 1688 rc = ops->ndo_start_xmit(nskb, dev);
1679 if (unlikely(rc)) { 1689 if (unlikely(rc)) {
1680 nskb->next = skb->next; 1690 nskb->next = skb->next;
1681 skb->next = nskb; 1691 skb->next = nskb;
@@ -1749,10 +1759,11 @@ static u16 simple_tx_hash(struct net_device *dev, struct sk_buff *skb)
1749static struct netdev_queue *dev_pick_tx(struct net_device *dev, 1759static struct netdev_queue *dev_pick_tx(struct net_device *dev,
1750 struct sk_buff *skb) 1760 struct sk_buff *skb)
1751{ 1761{
1762 const struct net_device_ops *ops = dev->netdev_ops;
1752 u16 queue_index = 0; 1763 u16 queue_index = 0;
1753 1764
1754 if (dev->select_queue) 1765 if (ops->ndo_select_queue)
1755 queue_index = dev->select_queue(dev, skb); 1766 queue_index = ops->ndo_select_queue(dev, skb);
1756 else if (dev->real_num_tx_queues > 1) 1767 else if (dev->real_num_tx_queues > 1)
1757 queue_index = simple_tx_hash(dev, skb); 1768 queue_index = simple_tx_hash(dev, skb);
1758 1769
@@ -2251,8 +2262,10 @@ int netif_receive_skb(struct sk_buff *skb)
2251 rcu_read_lock(); 2262 rcu_read_lock();
2252 2263
2253 /* Don't receive packets in an exiting network namespace */ 2264 /* Don't receive packets in an exiting network namespace */
2254 if (!net_alive(dev_net(skb->dev))) 2265 if (!net_alive(dev_net(skb->dev))) {
2266 kfree_skb(skb);
2255 goto out; 2267 goto out;
2268 }
2256 2269
2257#ifdef CONFIG_NET_CLS_ACT 2270#ifdef CONFIG_NET_CLS_ACT
2258 if (skb->tc_verd & TC_NCLS) { 2271 if (skb->tc_verd & TC_NCLS) {
@@ -2325,6 +2338,125 @@ static void flush_backlog(void *arg)
2325 } 2338 }
2326} 2339}
2327 2340
2341static int napi_gro_complete(struct sk_buff *skb)
2342{
2343 struct packet_type *ptype;
2344 __be16 type = skb->protocol;
2345 struct list_head *head = &ptype_base[ntohs(type) & PTYPE_HASH_MASK];
2346 int err = -ENOENT;
2347
2348 if (!skb_shinfo(skb)->frag_list)
2349 goto out;
2350
2351 rcu_read_lock();
2352 list_for_each_entry_rcu(ptype, head, list) {
2353 if (ptype->type != type || ptype->dev || !ptype->gro_complete)
2354 continue;
2355
2356 err = ptype->gro_complete(skb);
2357 break;
2358 }
2359 rcu_read_unlock();
2360
2361 if (err) {
2362 WARN_ON(&ptype->list == head);
2363 kfree_skb(skb);
2364 return NET_RX_SUCCESS;
2365 }
2366
2367out:
2368 __skb_push(skb, -skb_network_offset(skb));
2369 return netif_receive_skb(skb);
2370}
2371
2372void napi_gro_flush(struct napi_struct *napi)
2373{
2374 struct sk_buff *skb, *next;
2375
2376 for (skb = napi->gro_list; skb; skb = next) {
2377 next = skb->next;
2378 skb->next = NULL;
2379 napi_gro_complete(skb);
2380 }
2381
2382 napi->gro_list = NULL;
2383}
2384EXPORT_SYMBOL(napi_gro_flush);
2385
2386int napi_gro_receive(struct napi_struct *napi, struct sk_buff *skb)
2387{
2388 struct sk_buff **pp = NULL;
2389 struct packet_type *ptype;
2390 __be16 type = skb->protocol;
2391 struct list_head *head = &ptype_base[ntohs(type) & PTYPE_HASH_MASK];
2392 int count = 0;
2393 int same_flow;
2394 int mac_len;
2395
2396 if (!(skb->dev->features & NETIF_F_GRO))
2397 goto normal;
2398
2399 rcu_read_lock();
2400 list_for_each_entry_rcu(ptype, head, list) {
2401 struct sk_buff *p;
2402
2403 if (ptype->type != type || ptype->dev || !ptype->gro_receive)
2404 continue;
2405
2406 skb_reset_network_header(skb);
2407 mac_len = skb->network_header - skb->mac_header;
2408 skb->mac_len = mac_len;
2409 NAPI_GRO_CB(skb)->same_flow = 0;
2410 NAPI_GRO_CB(skb)->flush = 0;
2411
2412 for (p = napi->gro_list; p; p = p->next) {
2413 count++;
2414 NAPI_GRO_CB(p)->same_flow =
2415 p->mac_len == mac_len &&
2416 !memcmp(skb_mac_header(p), skb_mac_header(skb),
2417 mac_len);
2418 NAPI_GRO_CB(p)->flush = 0;
2419 }
2420
2421 pp = ptype->gro_receive(&napi->gro_list, skb);
2422 break;
2423 }
2424 rcu_read_unlock();
2425
2426 if (&ptype->list == head)
2427 goto normal;
2428
2429 same_flow = NAPI_GRO_CB(skb)->same_flow;
2430
2431 if (pp) {
2432 struct sk_buff *nskb = *pp;
2433
2434 *pp = nskb->next;
2435 nskb->next = NULL;
2436 napi_gro_complete(nskb);
2437 count--;
2438 }
2439
2440 if (same_flow)
2441 goto ok;
2442
2443 if (NAPI_GRO_CB(skb)->flush || count >= MAX_GRO_SKBS) {
2444 __skb_push(skb, -skb_network_offset(skb));
2445 goto normal;
2446 }
2447
2448 NAPI_GRO_CB(skb)->count = 1;
2449 skb->next = napi->gro_list;
2450 napi->gro_list = skb;
2451
2452ok:
2453 return NET_RX_SUCCESS;
2454
2455normal:
2456 return netif_receive_skb(skb);
2457}
2458EXPORT_SYMBOL(napi_gro_receive);
2459
2328static int process_backlog(struct napi_struct *napi, int quota) 2460static int process_backlog(struct napi_struct *napi, int quota)
2329{ 2461{
2330 int work = 0; 2462 int work = 0;
@@ -2344,9 +2476,11 @@ static int process_backlog(struct napi_struct *napi, int quota)
2344 } 2476 }
2345 local_irq_enable(); 2477 local_irq_enable();
2346 2478
2347 netif_receive_skb(skb); 2479 napi_gro_receive(napi, skb);
2348 } while (++work < quota && jiffies == start_time); 2480 } while (++work < quota && jiffies == start_time);
2349 2481
2482 napi_gro_flush(napi);
2483
2350 return work; 2484 return work;
2351} 2485}
2352 2486
@@ -2367,11 +2501,73 @@ void __napi_schedule(struct napi_struct *n)
2367} 2501}
2368EXPORT_SYMBOL(__napi_schedule); 2502EXPORT_SYMBOL(__napi_schedule);
2369 2503
2504void __napi_complete(struct napi_struct *n)
2505{
2506 BUG_ON(!test_bit(NAPI_STATE_SCHED, &n->state));
2507 BUG_ON(n->gro_list);
2508
2509 list_del(&n->poll_list);
2510 smp_mb__before_clear_bit();
2511 clear_bit(NAPI_STATE_SCHED, &n->state);
2512}
2513EXPORT_SYMBOL(__napi_complete);
2514
2515void napi_complete(struct napi_struct *n)
2516{
2517 unsigned long flags;
2518
2519 /*
2520 * don't let napi dequeue from the cpu poll list
2521 * just in case its running on a different cpu
2522 */
2523 if (unlikely(test_bit(NAPI_STATE_NPSVC, &n->state)))
2524 return;
2525
2526 napi_gro_flush(n);
2527 local_irq_save(flags);
2528 __napi_complete(n);
2529 local_irq_restore(flags);
2530}
2531EXPORT_SYMBOL(napi_complete);
2532
2533void netif_napi_add(struct net_device *dev, struct napi_struct *napi,
2534 int (*poll)(struct napi_struct *, int), int weight)
2535{
2536 INIT_LIST_HEAD(&napi->poll_list);
2537 napi->gro_list = NULL;
2538 napi->poll = poll;
2539 napi->weight = weight;
2540 list_add(&napi->dev_list, &dev->napi_list);
2541#ifdef CONFIG_NETPOLL
2542 napi->dev = dev;
2543 spin_lock_init(&napi->poll_lock);
2544 napi->poll_owner = -1;
2545#endif
2546 set_bit(NAPI_STATE_SCHED, &napi->state);
2547}
2548EXPORT_SYMBOL(netif_napi_add);
2549
2550void netif_napi_del(struct napi_struct *napi)
2551{
2552 struct sk_buff *skb, *next;
2553
2554 list_del_init(&napi->dev_list);
2555
2556 for (skb = napi->gro_list; skb; skb = next) {
2557 next = skb->next;
2558 skb->next = NULL;
2559 kfree_skb(skb);
2560 }
2561
2562 napi->gro_list = NULL;
2563}
2564EXPORT_SYMBOL(netif_napi_del);
2565
2370 2566
2371static void net_rx_action(struct softirq_action *h) 2567static void net_rx_action(struct softirq_action *h)
2372{ 2568{
2373 struct list_head *list = &__get_cpu_var(softnet_data).poll_list; 2569 struct list_head *list = &__get_cpu_var(softnet_data).poll_list;
2374 unsigned long start_time = jiffies; 2570 unsigned long time_limit = jiffies + 2;
2375 int budget = netdev_budget; 2571 int budget = netdev_budget;
2376 void *have; 2572 void *have;
2377 2573
@@ -2382,13 +2578,10 @@ static void net_rx_action(struct softirq_action *h)
2382 int work, weight; 2578 int work, weight;
2383 2579
2384 /* If softirq window is exhuasted then punt. 2580 /* If softirq window is exhuasted then punt.
2385 * 2581 * Allow this to run for 2 jiffies since which will allow
2386 * Note that this is a slight policy change from the 2582 * an average latency of 1.5/HZ.
2387 * previous NAPI code, which would allow up to 2
2388 * jiffies to pass before breaking out. The test
2389 * used to be "jiffies - start_time > 1".
2390 */ 2583 */
2391 if (unlikely(budget <= 0 || jiffies != start_time)) 2584 if (unlikely(budget <= 0 || time_after(jiffies, time_limit)))
2392 goto softnet_break; 2585 goto softnet_break;
2393 2586
2394 local_irq_enable(); 2587 local_irq_enable();
@@ -2615,7 +2808,7 @@ void dev_seq_stop(struct seq_file *seq, void *v)
2615 2808
2616static void dev_seq_printf_stats(struct seq_file *seq, struct net_device *dev) 2809static void dev_seq_printf_stats(struct seq_file *seq, struct net_device *dev)
2617{ 2810{
2618 struct net_device_stats *stats = dev->get_stats(dev); 2811 const struct net_device_stats *stats = dev_get_stats(dev);
2619 2812
2620 seq_printf(seq, "%6s:%8lu %7lu %4lu %4lu %4lu %5lu %10lu %9lu " 2813 seq_printf(seq, "%6s:%8lu %7lu %4lu %4lu %4lu %5lu %10lu %9lu "
2621 "%8lu %7lu %4lu %4lu %4lu %5lu %7lu %10lu\n", 2814 "%8lu %7lu %4lu %4lu %4lu %5lu %7lu %10lu\n",
@@ -2797,31 +2990,6 @@ static void ptype_seq_stop(struct seq_file *seq, void *v)
2797 rcu_read_unlock(); 2990 rcu_read_unlock();
2798} 2991}
2799 2992
2800static void ptype_seq_decode(struct seq_file *seq, void *sym)
2801{
2802#ifdef CONFIG_KALLSYMS
2803 unsigned long offset = 0, symsize;
2804 const char *symname;
2805 char *modname;
2806 char namebuf[128];
2807
2808 symname = kallsyms_lookup((unsigned long)sym, &symsize, &offset,
2809 &modname, namebuf);
2810
2811 if (symname) {
2812 char *delim = ":";
2813
2814 if (!modname)
2815 modname = delim = "";
2816 seq_printf(seq, "%s%s%s%s+0x%lx", delim, modname, delim,
2817 symname, offset);
2818 return;
2819 }
2820#endif
2821
2822 seq_printf(seq, "[%p]", sym);
2823}
2824
2825static int ptype_seq_show(struct seq_file *seq, void *v) 2993static int ptype_seq_show(struct seq_file *seq, void *v)
2826{ 2994{
2827 struct packet_type *pt = v; 2995 struct packet_type *pt = v;
@@ -2834,10 +3002,8 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
2834 else 3002 else
2835 seq_printf(seq, "%04x", ntohs(pt->type)); 3003 seq_printf(seq, "%04x", ntohs(pt->type));
2836 3004
2837 seq_printf(seq, " %-8s ", 3005 seq_printf(seq, " %-8s %pF\n",
2838 pt->dev ? pt->dev->name : ""); 3006 pt->dev ? pt->dev->name : "", pt->func);
2839 ptype_seq_decode(seq, pt->func);
2840 seq_putc(seq, '\n');
2841 } 3007 }
2842 3008
2843 return 0; 3009 return 0;
@@ -2954,8 +3120,10 @@ int netdev_set_master(struct net_device *slave, struct net_device *master)
2954 3120
2955static void dev_change_rx_flags(struct net_device *dev, int flags) 3121static void dev_change_rx_flags(struct net_device *dev, int flags)
2956{ 3122{
2957 if (dev->flags & IFF_UP && dev->change_rx_flags) 3123 const struct net_device_ops *ops = dev->netdev_ops;
2958 dev->change_rx_flags(dev, flags); 3124
3125 if ((dev->flags & IFF_UP) && ops->ndo_change_rx_flags)
3126 ops->ndo_change_rx_flags(dev, flags);
2959} 3127}
2960 3128
2961static int __dev_set_promiscuity(struct net_device *dev, int inc) 3129static int __dev_set_promiscuity(struct net_device *dev, int inc)
@@ -3079,6 +3247,8 @@ int dev_set_allmulti(struct net_device *dev, int inc)
3079 */ 3247 */
3080void __dev_set_rx_mode(struct net_device *dev) 3248void __dev_set_rx_mode(struct net_device *dev)
3081{ 3249{
3250 const struct net_device_ops *ops = dev->netdev_ops;
3251
3082 /* dev_open will call this function so the list will stay sane. */ 3252 /* dev_open will call this function so the list will stay sane. */
3083 if (!(dev->flags&IFF_UP)) 3253 if (!(dev->flags&IFF_UP))
3084 return; 3254 return;
@@ -3086,8 +3256,8 @@ void __dev_set_rx_mode(struct net_device *dev)
3086 if (!netif_device_present(dev)) 3256 if (!netif_device_present(dev))
3087 return; 3257 return;
3088 3258
3089 if (dev->set_rx_mode) 3259 if (ops->ndo_set_rx_mode)
3090 dev->set_rx_mode(dev); 3260 ops->ndo_set_rx_mode(dev);
3091 else { 3261 else {
3092 /* Unicast addresses changes may only happen under the rtnl, 3262 /* Unicast addresses changes may only happen under the rtnl,
3093 * therefore calling __dev_set_promiscuity here is safe. 3263 * therefore calling __dev_set_promiscuity here is safe.
@@ -3100,8 +3270,8 @@ void __dev_set_rx_mode(struct net_device *dev)
3100 dev->uc_promisc = 0; 3270 dev->uc_promisc = 0;
3101 } 3271 }
3102 3272
3103 if (dev->set_multicast_list) 3273 if (ops->ndo_set_multicast_list)
3104 dev->set_multicast_list(dev); 3274 ops->ndo_set_multicast_list(dev);
3105 } 3275 }
3106} 3276}
3107 3277
@@ -3460,6 +3630,7 @@ int dev_change_flags(struct net_device *dev, unsigned flags)
3460 */ 3630 */
3461int dev_set_mtu(struct net_device *dev, int new_mtu) 3631int dev_set_mtu(struct net_device *dev, int new_mtu)
3462{ 3632{
3633 const struct net_device_ops *ops = dev->netdev_ops;
3463 int err; 3634 int err;
3464 3635
3465 if (new_mtu == dev->mtu) 3636 if (new_mtu == dev->mtu)
@@ -3473,10 +3644,11 @@ int dev_set_mtu(struct net_device *dev, int new_mtu)
3473 return -ENODEV; 3644 return -ENODEV;
3474 3645
3475 err = 0; 3646 err = 0;
3476 if (dev->change_mtu) 3647 if (ops->ndo_change_mtu)
3477 err = dev->change_mtu(dev, new_mtu); 3648 err = ops->ndo_change_mtu(dev, new_mtu);
3478 else 3649 else
3479 dev->mtu = new_mtu; 3650 dev->mtu = new_mtu;
3651
3480 if (!err && dev->flags & IFF_UP) 3652 if (!err && dev->flags & IFF_UP)
3481 call_netdevice_notifiers(NETDEV_CHANGEMTU, dev); 3653 call_netdevice_notifiers(NETDEV_CHANGEMTU, dev);
3482 return err; 3654 return err;
@@ -3491,15 +3663,16 @@ int dev_set_mtu(struct net_device *dev, int new_mtu)
3491 */ 3663 */
3492int dev_set_mac_address(struct net_device *dev, struct sockaddr *sa) 3664int dev_set_mac_address(struct net_device *dev, struct sockaddr *sa)
3493{ 3665{
3666 const struct net_device_ops *ops = dev->netdev_ops;
3494 int err; 3667 int err;
3495 3668
3496 if (!dev->set_mac_address) 3669 if (!ops->ndo_set_mac_address)
3497 return -EOPNOTSUPP; 3670 return -EOPNOTSUPP;
3498 if (sa->sa_family != dev->type) 3671 if (sa->sa_family != dev->type)
3499 return -EINVAL; 3672 return -EINVAL;
3500 if (!netif_device_present(dev)) 3673 if (!netif_device_present(dev))
3501 return -ENODEV; 3674 return -ENODEV;
3502 err = dev->set_mac_address(dev, sa); 3675 err = ops->ndo_set_mac_address(dev, sa);
3503 if (!err) 3676 if (!err)
3504 call_netdevice_notifiers(NETDEV_CHANGEADDR, dev); 3677 call_netdevice_notifiers(NETDEV_CHANGEADDR, dev);
3505 return err; 3678 return err;
@@ -3579,10 +3752,13 @@ static int dev_ifsioc(struct net *net, struct ifreq *ifr, unsigned int cmd)
3579{ 3752{
3580 int err; 3753 int err;
3581 struct net_device *dev = __dev_get_by_name(net, ifr->ifr_name); 3754 struct net_device *dev = __dev_get_by_name(net, ifr->ifr_name);
3755 const struct net_device_ops *ops;
3582 3756
3583 if (!dev) 3757 if (!dev)
3584 return -ENODEV; 3758 return -ENODEV;
3585 3759
3760 ops = dev->netdev_ops;
3761
3586 switch (cmd) { 3762 switch (cmd) {
3587 case SIOCSIFFLAGS: /* Set interface flags */ 3763 case SIOCSIFFLAGS: /* Set interface flags */
3588 return dev_change_flags(dev, ifr->ifr_flags); 3764 return dev_change_flags(dev, ifr->ifr_flags);
@@ -3606,15 +3782,15 @@ static int dev_ifsioc(struct net *net, struct ifreq *ifr, unsigned int cmd)
3606 return 0; 3782 return 0;
3607 3783
3608 case SIOCSIFMAP: 3784 case SIOCSIFMAP:
3609 if (dev->set_config) { 3785 if (ops->ndo_set_config) {
3610 if (!netif_device_present(dev)) 3786 if (!netif_device_present(dev))
3611 return -ENODEV; 3787 return -ENODEV;
3612 return dev->set_config(dev, &ifr->ifr_map); 3788 return ops->ndo_set_config(dev, &ifr->ifr_map);
3613 } 3789 }
3614 return -EOPNOTSUPP; 3790 return -EOPNOTSUPP;
3615 3791
3616 case SIOCADDMULTI: 3792 case SIOCADDMULTI:
3617 if ((!dev->set_multicast_list && !dev->set_rx_mode) || 3793 if ((!ops->ndo_set_multicast_list && !ops->ndo_set_rx_mode) ||
3618 ifr->ifr_hwaddr.sa_family != AF_UNSPEC) 3794 ifr->ifr_hwaddr.sa_family != AF_UNSPEC)
3619 return -EINVAL; 3795 return -EINVAL;
3620 if (!netif_device_present(dev)) 3796 if (!netif_device_present(dev))
@@ -3623,7 +3799,7 @@ static int dev_ifsioc(struct net *net, struct ifreq *ifr, unsigned int cmd)
3623 dev->addr_len, 1); 3799 dev->addr_len, 1);
3624 3800
3625 case SIOCDELMULTI: 3801 case SIOCDELMULTI:
3626 if ((!dev->set_multicast_list && !dev->set_rx_mode) || 3802 if ((!ops->ndo_set_multicast_list && !ops->ndo_set_rx_mode) ||
3627 ifr->ifr_hwaddr.sa_family != AF_UNSPEC) 3803 ifr->ifr_hwaddr.sa_family != AF_UNSPEC)
3628 return -EINVAL; 3804 return -EINVAL;
3629 if (!netif_device_present(dev)) 3805 if (!netif_device_present(dev))
@@ -3661,10 +3837,9 @@ static int dev_ifsioc(struct net *net, struct ifreq *ifr, unsigned int cmd)
3661 cmd == SIOCBRDELIF || 3837 cmd == SIOCBRDELIF ||
3662 cmd == SIOCWANDEV) { 3838 cmd == SIOCWANDEV) {
3663 err = -EOPNOTSUPP; 3839 err = -EOPNOTSUPP;
3664 if (dev->do_ioctl) { 3840 if (ops->ndo_do_ioctl) {
3665 if (netif_device_present(dev)) 3841 if (netif_device_present(dev))
3666 err = dev->do_ioctl(dev, ifr, 3842 err = ops->ndo_do_ioctl(dev, ifr, cmd);
3667 cmd);
3668 else 3843 else
3669 err = -ENODEV; 3844 err = -ENODEV;
3670 } 3845 }
@@ -3925,8 +4100,8 @@ static void rollback_registered(struct net_device *dev)
3925 */ 4100 */
3926 dev_addr_discard(dev); 4101 dev_addr_discard(dev);
3927 4102
3928 if (dev->uninit) 4103 if (dev->netdev_ops->ndo_uninit)
3929 dev->uninit(dev); 4104 dev->netdev_ops->ndo_uninit(dev);
3930 4105
3931 /* Notifier chain MUST detach us from master device. */ 4106 /* Notifier chain MUST detach us from master device. */
3932 WARN_ON(dev->master); 4107 WARN_ON(dev->master);
@@ -4016,7 +4191,7 @@ int register_netdevice(struct net_device *dev)
4016 struct hlist_head *head; 4191 struct hlist_head *head;
4017 struct hlist_node *p; 4192 struct hlist_node *p;
4018 int ret; 4193 int ret;
4019 struct net *net; 4194 struct net *net = dev_net(dev);
4020 4195
4021 BUG_ON(dev_boot_phase); 4196 BUG_ON(dev_boot_phase);
4022 ASSERT_RTNL(); 4197 ASSERT_RTNL();
@@ -4025,8 +4200,7 @@ int register_netdevice(struct net_device *dev)
4025 4200
4026 /* When net_device's are persistent, this will be fatal. */ 4201 /* When net_device's are persistent, this will be fatal. */
4027 BUG_ON(dev->reg_state != NETREG_UNINITIALIZED); 4202 BUG_ON(dev->reg_state != NETREG_UNINITIALIZED);
4028 BUG_ON(!dev_net(dev)); 4203 BUG_ON(!net);
4029 net = dev_net(dev);
4030 4204
4031 spin_lock_init(&dev->addr_list_lock); 4205 spin_lock_init(&dev->addr_list_lock);
4032 netdev_set_addr_lockdep_class(dev); 4206 netdev_set_addr_lockdep_class(dev);
@@ -4034,9 +4208,46 @@ int register_netdevice(struct net_device *dev)
4034 4208
4035 dev->iflink = -1; 4209 dev->iflink = -1;
4036 4210
4211#ifdef CONFIG_COMPAT_NET_DEV_OPS
4212 /* Netdevice_ops API compatiability support.
4213 * This is temporary until all network devices are converted.
4214 */
4215 if (dev->netdev_ops) {
4216 const struct net_device_ops *ops = dev->netdev_ops;
4217
4218 dev->init = ops->ndo_init;
4219 dev->uninit = ops->ndo_uninit;
4220 dev->open = ops->ndo_open;
4221 dev->change_rx_flags = ops->ndo_change_rx_flags;
4222 dev->set_rx_mode = ops->ndo_set_rx_mode;
4223 dev->set_multicast_list = ops->ndo_set_multicast_list;
4224 dev->set_mac_address = ops->ndo_set_mac_address;
4225 dev->validate_addr = ops->ndo_validate_addr;
4226 dev->do_ioctl = ops->ndo_do_ioctl;
4227 dev->set_config = ops->ndo_set_config;
4228 dev->change_mtu = ops->ndo_change_mtu;
4229 dev->tx_timeout = ops->ndo_tx_timeout;
4230 dev->get_stats = ops->ndo_get_stats;
4231 dev->vlan_rx_register = ops->ndo_vlan_rx_register;
4232 dev->vlan_rx_add_vid = ops->ndo_vlan_rx_add_vid;
4233 dev->vlan_rx_kill_vid = ops->ndo_vlan_rx_kill_vid;
4234#ifdef CONFIG_NET_POLL_CONTROLLER
4235 dev->poll_controller = ops->ndo_poll_controller;
4236#endif
4237 } else {
4238 char drivername[64];
4239 pr_info("%s (%s): not using net_device_ops yet\n",
4240 dev->name, netdev_drivername(dev, drivername, 64));
4241
4242 /* This works only because net_device_ops and the
4243 compatiablity structure are the same. */
4244 dev->netdev_ops = (void *) &(dev->init);
4245 }
4246#endif
4247
4037 /* Init, if this function is available */ 4248 /* Init, if this function is available */
4038 if (dev->init) { 4249 if (dev->netdev_ops->ndo_init) {
4039 ret = dev->init(dev); 4250 ret = dev->netdev_ops->ndo_init(dev);
4040 if (ret) { 4251 if (ret) {
4041 if (ret > 0) 4252 if (ret > 0)
4042 ret = -EIO; 4253 ret = -EIO;
@@ -4114,8 +4325,8 @@ out:
4114 return ret; 4325 return ret;
4115 4326
4116err_uninit: 4327err_uninit:
4117 if (dev->uninit) 4328 if (dev->netdev_ops->ndo_uninit)
4118 dev->uninit(dev); 4329 dev->netdev_ops->ndo_uninit(dev);
4119 goto out; 4330 goto out;
4120} 4331}
4121 4332
@@ -4271,10 +4482,24 @@ void netdev_run_todo(void)
4271 } 4482 }
4272} 4483}
4273 4484
4274static struct net_device_stats *internal_stats(struct net_device *dev) 4485/**
4275{ 4486 * dev_get_stats - get network device statistics
4276 return &dev->stats; 4487 * @dev: device to get statistics from
4488 *
4489 * Get network statistics from device. The device driver may provide
4490 * its own method by setting dev->netdev_ops->get_stats; otherwise
4491 * the internal statistics structure is used.
4492 */
4493const struct net_device_stats *dev_get_stats(struct net_device *dev)
4494 {
4495 const struct net_device_ops *ops = dev->netdev_ops;
4496
4497 if (ops->ndo_get_stats)
4498 return ops->ndo_get_stats(dev);
4499 else
4500 return &dev->stats;
4277} 4501}
4502EXPORT_SYMBOL(dev_get_stats);
4278 4503
4279static void netdev_init_one_queue(struct net_device *dev, 4504static void netdev_init_one_queue(struct net_device *dev,
4280 struct netdev_queue *queue, 4505 struct netdev_queue *queue,
@@ -4343,18 +4568,11 @@ struct net_device *alloc_netdev_mq(int sizeof_priv, const char *name,
4343 dev->num_tx_queues = queue_count; 4568 dev->num_tx_queues = queue_count;
4344 dev->real_num_tx_queues = queue_count; 4569 dev->real_num_tx_queues = queue_count;
4345 4570
4346 if (sizeof_priv) {
4347 dev->priv = ((char *)dev +
4348 ((sizeof(struct net_device) + NETDEV_ALIGN_CONST)
4349 & ~NETDEV_ALIGN_CONST));
4350 }
4351
4352 dev->gso_max_size = GSO_MAX_SIZE; 4571 dev->gso_max_size = GSO_MAX_SIZE;
4353 4572
4354 netdev_init_queues(dev); 4573 netdev_init_queues(dev);
4355 4574
4356 dev->get_stats = internal_stats; 4575 INIT_LIST_HEAD(&dev->napi_list);
4357 netpoll_netdev_init(dev);
4358 setup(dev); 4576 setup(dev);
4359 strcpy(dev->name, name); 4577 strcpy(dev->name, name);
4360 return dev; 4578 return dev;
@@ -4371,10 +4589,15 @@ EXPORT_SYMBOL(alloc_netdev_mq);
4371 */ 4589 */
4372void free_netdev(struct net_device *dev) 4590void free_netdev(struct net_device *dev)
4373{ 4591{
4592 struct napi_struct *p, *n;
4593
4374 release_net(dev_net(dev)); 4594 release_net(dev_net(dev));
4375 4595
4376 kfree(dev->_tx); 4596 kfree(dev->_tx);
4377 4597
4598 list_for_each_entry_safe(p, n, &dev->napi_list, dev_list)
4599 netif_napi_del(p);
4600
4378 /* Compatibility with error handling in drivers */ 4601 /* Compatibility with error handling in drivers */
4379 if (dev->reg_state == NETREG_UNINITIALIZED) { 4602 if (dev->reg_state == NETREG_UNINITIALIZED) {
4380 kfree((char *)dev - dev->padded); 4603 kfree((char *)dev - dev->padded);
@@ -4467,6 +4690,15 @@ int dev_change_net_namespace(struct net_device *dev, struct net *net, const char
4467 if (dev->features & NETIF_F_NETNS_LOCAL) 4690 if (dev->features & NETIF_F_NETNS_LOCAL)
4468 goto out; 4691 goto out;
4469 4692
4693#ifdef CONFIG_SYSFS
4694 /* Don't allow real devices to be moved when sysfs
4695 * is enabled.
4696 */
4697 err = -EINVAL;
4698 if (dev->dev.parent)
4699 goto out;
4700#endif
4701
4470 /* Ensure the device has been registrered */ 4702 /* Ensure the device has been registrered */
4471 err = -EINVAL; 4703 err = -EINVAL;
4472 if (dev->reg_state != NETREG_REGISTERED) 4704 if (dev->reg_state != NETREG_REGISTERED)
@@ -4524,6 +4756,8 @@ int dev_change_net_namespace(struct net_device *dev, struct net *net, const char
4524 */ 4756 */
4525 dev_addr_discard(dev); 4757 dev_addr_discard(dev);
4526 4758
4759 netdev_unregister_kobject(dev);
4760
4527 /* Actually switch the network namespace */ 4761 /* Actually switch the network namespace */
4528 dev_net_set(dev, net); 4762 dev_net_set(dev, net);
4529 4763
@@ -4540,7 +4774,6 @@ int dev_change_net_namespace(struct net_device *dev, struct net *net, const char
4540 } 4774 }
4541 4775
4542 /* Fixup kobjects */ 4776 /* Fixup kobjects */
4543 netdev_unregister_kobject(dev);
4544 err = netdev_register_kobject(dev); 4777 err = netdev_register_kobject(dev);
4545 WARN_ON(err); 4778 WARN_ON(err);
4546 4779
@@ -4847,6 +5080,12 @@ static void __net_exit default_device_exit(struct net *net)
4847 if (dev->features & NETIF_F_NETNS_LOCAL) 5080 if (dev->features & NETIF_F_NETNS_LOCAL)
4848 continue; 5081 continue;
4849 5082
5083 /* Delete virtual devices */
5084 if (dev->rtnl_link_ops && dev->rtnl_link_ops->dellink) {
5085 dev->rtnl_link_ops->dellink(dev);
5086 continue;
5087 }
5088
4850 /* Push remaing network devices to init_net */ 5089 /* Push remaing network devices to init_net */
4851 snprintf(fb_name, IFNAMSIZ, "dev%d", dev->ifindex); 5090 snprintf(fb_name, IFNAMSIZ, "dev%d", dev->ifindex);
4852 err = dev_change_net_namespace(dev, &init_net, fb_name); 5091 err = dev_change_net_namespace(dev, &init_net, fb_name);
@@ -4893,9 +5132,6 @@ static int __init net_dev_init(void)
4893 if (register_pernet_subsys(&netdev_net_ops)) 5132 if (register_pernet_subsys(&netdev_net_ops))
4894 goto out; 5133 goto out;
4895 5134
4896 if (register_pernet_device(&default_device_ops))
4897 goto out;
4898
4899 /* 5135 /*
4900 * Initialise the packet receive queues. 5136 * Initialise the packet receive queues.
4901 */ 5137 */
@@ -4910,12 +5146,28 @@ static int __init net_dev_init(void)
4910 5146
4911 queue->backlog.poll = process_backlog; 5147 queue->backlog.poll = process_backlog;
4912 queue->backlog.weight = weight_p; 5148 queue->backlog.weight = weight_p;
5149 queue->backlog.gro_list = NULL;
4913 } 5150 }
4914 5151
4915 netdev_dma_register();
4916
4917 dev_boot_phase = 0; 5152 dev_boot_phase = 0;
4918 5153
5154 /* The loopback device is special if any other network devices
5155 * is present in a network namespace the loopback device must
5156 * be present. Since we now dynamically allocate and free the
5157 * loopback device ensure this invariant is maintained by
5158 * keeping the loopback device as the first device on the
5159 * list of network devices. Ensuring the loopback devices
5160 * is the first device that appears and the last network device
5161 * that disappears.
5162 */
5163 if (register_pernet_device(&loopback_net_ops))
5164 goto out;
5165
5166 if (register_pernet_device(&default_device_ops))
5167 goto out;
5168
5169 netdev_dma_register();
5170
4919 open_softirq(NET_TX_SOFTIRQ, net_tx_action); 5171 open_softirq(NET_TX_SOFTIRQ, net_tx_action);
4920 open_softirq(NET_RX_SOFTIRQ, net_rx_action); 5172 open_softirq(NET_RX_SOFTIRQ, net_rx_action);
4921 5173
diff --git a/net/core/dst.c b/net/core/dst.c
index 09c1530f4681..57bc4d5b8d08 100644
--- a/net/core/dst.c
+++ b/net/core/dst.c
@@ -263,9 +263,11 @@ again:
263void dst_release(struct dst_entry *dst) 263void dst_release(struct dst_entry *dst)
264{ 264{
265 if (dst) { 265 if (dst) {
266 WARN_ON(atomic_read(&dst->__refcnt) < 1); 266 int newrefcnt;
267
267 smp_mb__before_atomic_dec(); 268 smp_mb__before_atomic_dec();
268 atomic_dec(&dst->__refcnt); 269 newrefcnt = atomic_dec_return(&dst->__refcnt);
270 WARN_ON(newrefcnt < 0);
269 } 271 }
270} 272}
271EXPORT_SYMBOL(dst_release); 273EXPORT_SYMBOL(dst_release);
diff --git a/net/core/ethtool.c b/net/core/ethtool.c
index 14ada537f895..947710a36ced 100644
--- a/net/core/ethtool.c
+++ b/net/core/ethtool.c
@@ -528,6 +528,22 @@ static int ethtool_set_tx_csum(struct net_device *dev, char __user *useraddr)
528 return dev->ethtool_ops->set_tx_csum(dev, edata.data); 528 return dev->ethtool_ops->set_tx_csum(dev, edata.data);
529} 529}
530 530
531static int ethtool_set_rx_csum(struct net_device *dev, char __user *useraddr)
532{
533 struct ethtool_value edata;
534
535 if (!dev->ethtool_ops->set_rx_csum)
536 return -EOPNOTSUPP;
537
538 if (copy_from_user(&edata, useraddr, sizeof(edata)))
539 return -EFAULT;
540
541 if (!edata.data && dev->ethtool_ops->set_sg)
542 dev->features &= ~NETIF_F_GRO;
543
544 return dev->ethtool_ops->set_rx_csum(dev, edata.data);
545}
546
531static int ethtool_set_sg(struct net_device *dev, char __user *useraddr) 547static int ethtool_set_sg(struct net_device *dev, char __user *useraddr)
532{ 548{
533 struct ethtool_value edata; 549 struct ethtool_value edata;
@@ -599,6 +615,34 @@ static int ethtool_set_gso(struct net_device *dev, char __user *useraddr)
599 return 0; 615 return 0;
600} 616}
601 617
618static int ethtool_get_gro(struct net_device *dev, char __user *useraddr)
619{
620 struct ethtool_value edata = { ETHTOOL_GGRO };
621
622 edata.data = dev->features & NETIF_F_GRO;
623 if (copy_to_user(useraddr, &edata, sizeof(edata)))
624 return -EFAULT;
625 return 0;
626}
627
628static int ethtool_set_gro(struct net_device *dev, char __user *useraddr)
629{
630 struct ethtool_value edata;
631
632 if (copy_from_user(&edata, useraddr, sizeof(edata)))
633 return -EFAULT;
634
635 if (edata.data) {
636 if (!dev->ethtool_ops->get_rx_csum ||
637 !dev->ethtool_ops->get_rx_csum(dev))
638 return -EINVAL;
639 dev->features |= NETIF_F_GRO;
640 } else
641 dev->features &= ~NETIF_F_GRO;
642
643 return 0;
644}
645
602static int ethtool_self_test(struct net_device *dev, char __user *useraddr) 646static int ethtool_self_test(struct net_device *dev, char __user *useraddr)
603{ 647{
604 struct ethtool_test test; 648 struct ethtool_test test;
@@ -932,8 +976,7 @@ int dev_ethtool(struct net *net, struct ifreq *ifr)
932 dev->ethtool_ops->get_rx_csum); 976 dev->ethtool_ops->get_rx_csum);
933 break; 977 break;
934 case ETHTOOL_SRXCSUM: 978 case ETHTOOL_SRXCSUM:
935 rc = ethtool_set_value(dev, useraddr, 979 rc = ethtool_set_rx_csum(dev, useraddr);
936 dev->ethtool_ops->set_rx_csum);
937 break; 980 break;
938 case ETHTOOL_GTXCSUM: 981 case ETHTOOL_GTXCSUM:
939 rc = ethtool_get_value(dev, useraddr, ethcmd, 982 rc = ethtool_get_value(dev, useraddr, ethcmd,
@@ -1014,6 +1057,12 @@ int dev_ethtool(struct net *net, struct ifreq *ifr)
1014 case ETHTOOL_SRXFH: 1057 case ETHTOOL_SRXFH:
1015 rc = ethtool_set_rxhash(dev, useraddr); 1058 rc = ethtool_set_rxhash(dev, useraddr);
1016 break; 1059 break;
1060 case ETHTOOL_GGRO:
1061 rc = ethtool_get_gro(dev, useraddr);
1062 break;
1063 case ETHTOOL_SGRO:
1064 rc = ethtool_set_gro(dev, useraddr);
1065 break;
1017 default: 1066 default:
1018 rc = -EOPNOTSUPP; 1067 rc = -EOPNOTSUPP;
1019 } 1068 }
diff --git a/net/core/fib_rules.c b/net/core/fib_rules.c
index 79de3b14a8d1..32b3a0152d7a 100644
--- a/net/core/fib_rules.c
+++ b/net/core/fib_rules.c
@@ -664,17 +664,18 @@ static int __init fib_rules_init(void)
664 rtnl_register(PF_UNSPEC, RTM_DELRULE, fib_nl_delrule, NULL); 664 rtnl_register(PF_UNSPEC, RTM_DELRULE, fib_nl_delrule, NULL);
665 rtnl_register(PF_UNSPEC, RTM_GETRULE, NULL, fib_nl_dumprule); 665 rtnl_register(PF_UNSPEC, RTM_GETRULE, NULL, fib_nl_dumprule);
666 666
667 err = register_netdevice_notifier(&fib_rules_notifier); 667 err = register_pernet_subsys(&fib_rules_net_ops);
668 if (err < 0) 668 if (err < 0)
669 goto fail; 669 goto fail;
670 670
671 err = register_pernet_subsys(&fib_rules_net_ops); 671 err = register_netdevice_notifier(&fib_rules_notifier);
672 if (err < 0) 672 if (err < 0)
673 goto fail_unregister; 673 goto fail_unregister;
674
674 return 0; 675 return 0;
675 676
676fail_unregister: 677fail_unregister:
677 unregister_netdevice_notifier(&fib_rules_notifier); 678 unregister_pernet_subsys(&fib_rules_net_ops);
678fail: 679fail:
679 rtnl_unregister(PF_UNSPEC, RTM_NEWRULE); 680 rtnl_unregister(PF_UNSPEC, RTM_NEWRULE);
680 rtnl_unregister(PF_UNSPEC, RTM_DELRULE); 681 rtnl_unregister(PF_UNSPEC, RTM_DELRULE);
diff --git a/net/core/filter.c b/net/core/filter.c
index df3744355839..d1d779ca096d 100644
--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ -319,6 +319,25 @@ load_b:
319 A = 0; 319 A = 0;
320 continue; 320 continue;
321 } 321 }
322 case SKF_AD_NLATTR_NEST: {
323 struct nlattr *nla;
324
325 if (skb_is_nonlinear(skb))
326 return 0;
327 if (A > skb->len - sizeof(struct nlattr))
328 return 0;
329
330 nla = (struct nlattr *)&skb->data[A];
331 if (nla->nla_len > A - skb->len)
332 return 0;
333
334 nla = nla_find_nested(nla, X);
335 if (nla)
336 A = (void *)nla - (void *)skb->data;
337 else
338 A = 0;
339 continue;
340 }
322 default: 341 default:
323 return 0; 342 return 0;
324 } 343 }
diff --git a/net/core/flow.c b/net/core/flow.c
index 5cf81052d044..96015871ecea 100644
--- a/net/core/flow.c
+++ b/net/core/flow.c
@@ -165,7 +165,7 @@ static int flow_key_compare(struct flowi *key1, struct flowi *key2)
165 return 0; 165 return 0;
166} 166}
167 167
168void *flow_cache_lookup(struct flowi *key, u16 family, u8 dir, 168void *flow_cache_lookup(struct net *net, struct flowi *key, u16 family, u8 dir,
169 flow_resolve_t resolver) 169 flow_resolve_t resolver)
170{ 170{
171 struct flow_cache_entry *fle, **head; 171 struct flow_cache_entry *fle, **head;
@@ -225,7 +225,7 @@ nocache:
225 void *obj; 225 void *obj;
226 atomic_t *obj_ref; 226 atomic_t *obj_ref;
227 227
228 err = resolver(key, family, dir, &obj, &obj_ref); 228 err = resolver(net, key, family, dir, &obj, &obj_ref);
229 229
230 if (fle && !err) { 230 if (fle && !err) {
231 fle->genid = atomic_read(&flow_cache_genid); 231 fle->genid = atomic_read(&flow_cache_genid);
@@ -307,7 +307,7 @@ void flow_cache_flush(void)
307 put_online_cpus(); 307 put_online_cpus();
308} 308}
309 309
310static void __devinit flow_cache_cpu_prepare(int cpu) 310static void __init flow_cache_cpu_prepare(int cpu)
311{ 311{
312 struct tasklet_struct *tasklet; 312 struct tasklet_struct *tasklet;
313 unsigned long order; 313 unsigned long order;
diff --git a/net/core/gen_estimator.c b/net/core/gen_estimator.c
index 57abe8266be1..9cc9f95b109e 100644
--- a/net/core/gen_estimator.c
+++ b/net/core/gen_estimator.c
@@ -31,6 +31,7 @@
31#include <linux/skbuff.h> 31#include <linux/skbuff.h>
32#include <linux/rtnetlink.h> 32#include <linux/rtnetlink.h>
33#include <linux/init.h> 33#include <linux/init.h>
34#include <linux/rbtree.h>
34#include <net/sock.h> 35#include <net/sock.h>
35#include <net/gen_stats.h> 36#include <net/gen_stats.h>
36 37
@@ -89,6 +90,7 @@ struct gen_estimator
89 u32 avpps; 90 u32 avpps;
90 u32 avbps; 91 u32 avbps;
91 struct rcu_head e_rcu; 92 struct rcu_head e_rcu;
93 struct rb_node node;
92}; 94};
93 95
94struct gen_estimator_head 96struct gen_estimator_head
@@ -102,6 +104,9 @@ static struct gen_estimator_head elist[EST_MAX_INTERVAL+1];
102/* Protects against NULL dereference */ 104/* Protects against NULL dereference */
103static DEFINE_RWLOCK(est_lock); 105static DEFINE_RWLOCK(est_lock);
104 106
107/* Protects against soft lockup during large deletion */
108static struct rb_root est_root = RB_ROOT;
109
105static void est_timer(unsigned long arg) 110static void est_timer(unsigned long arg)
106{ 111{
107 int idx = (int)arg; 112 int idx = (int)arg;
@@ -139,6 +144,46 @@ skip:
139 rcu_read_unlock(); 144 rcu_read_unlock();
140} 145}
141 146
147static void gen_add_node(struct gen_estimator *est)
148{
149 struct rb_node **p = &est_root.rb_node, *parent = NULL;
150
151 while (*p) {
152 struct gen_estimator *e;
153
154 parent = *p;
155 e = rb_entry(parent, struct gen_estimator, node);
156
157 if (est->bstats > e->bstats)
158 p = &parent->rb_right;
159 else
160 p = &parent->rb_left;
161 }
162 rb_link_node(&est->node, parent, p);
163 rb_insert_color(&est->node, &est_root);
164}
165
166static
167struct gen_estimator *gen_find_node(const struct gnet_stats_basic *bstats,
168 const struct gnet_stats_rate_est *rate_est)
169{
170 struct rb_node *p = est_root.rb_node;
171
172 while (p) {
173 struct gen_estimator *e;
174
175 e = rb_entry(p, struct gen_estimator, node);
176
177 if (bstats > e->bstats)
178 p = p->rb_right;
179 else if (bstats < e->bstats || rate_est != e->rate_est)
180 p = p->rb_left;
181 else
182 return e;
183 }
184 return NULL;
185}
186
142/** 187/**
143 * gen_new_estimator - create a new rate estimator 188 * gen_new_estimator - create a new rate estimator
144 * @bstats: basic statistics 189 * @bstats: basic statistics
@@ -194,8 +239,11 @@ int gen_new_estimator(struct gnet_stats_basic *bstats,
194 mod_timer(&elist[idx].timer, jiffies + ((HZ/4) << idx)); 239 mod_timer(&elist[idx].timer, jiffies + ((HZ/4) << idx));
195 240
196 list_add_rcu(&est->list, &elist[idx].list); 241 list_add_rcu(&est->list, &elist[idx].list);
242 gen_add_node(est);
243
197 return 0; 244 return 0;
198} 245}
246EXPORT_SYMBOL(gen_new_estimator);
199 247
200static void __gen_kill_estimator(struct rcu_head *head) 248static void __gen_kill_estimator(struct rcu_head *head)
201{ 249{
@@ -209,36 +257,27 @@ static void __gen_kill_estimator(struct rcu_head *head)
209 * @bstats: basic statistics 257 * @bstats: basic statistics
210 * @rate_est: rate estimator statistics 258 * @rate_est: rate estimator statistics
211 * 259 *
212 * Removes the rate estimator specified by &bstats and &rate_est 260 * Removes the rate estimator specified by &bstats and &rate_est.
213 * and deletes the timer.
214 * 261 *
215 * NOTE: Called under rtnl_mutex 262 * NOTE: Called under rtnl_mutex
216 */ 263 */
217void gen_kill_estimator(struct gnet_stats_basic *bstats, 264void gen_kill_estimator(struct gnet_stats_basic *bstats,
218 struct gnet_stats_rate_est *rate_est) 265 struct gnet_stats_rate_est *rate_est)
219{ 266{
220 int idx; 267 struct gen_estimator *e;
221 struct gen_estimator *e, *n;
222
223 for (idx=0; idx <= EST_MAX_INTERVAL; idx++) {
224
225 /* Skip non initialized indexes */
226 if (!elist[idx].timer.function)
227 continue;
228 268
229 list_for_each_entry_safe(e, n, &elist[idx].list, list) { 269 while ((e = gen_find_node(bstats, rate_est))) {
230 if (e->rate_est != rate_est || e->bstats != bstats) 270 rb_erase(&e->node, &est_root);
231 continue;
232 271
233 write_lock_bh(&est_lock); 272 write_lock_bh(&est_lock);
234 e->bstats = NULL; 273 e->bstats = NULL;
235 write_unlock_bh(&est_lock); 274 write_unlock_bh(&est_lock);
236 275
237 list_del_rcu(&e->list); 276 list_del_rcu(&e->list);
238 call_rcu(&e->e_rcu, __gen_kill_estimator); 277 call_rcu(&e->e_rcu, __gen_kill_estimator);
239 }
240 } 278 }
241} 279}
280EXPORT_SYMBOL(gen_kill_estimator);
242 281
243/** 282/**
244 * gen_replace_estimator - replace rate estimator configuration 283 * gen_replace_estimator - replace rate estimator configuration
@@ -259,8 +298,20 @@ int gen_replace_estimator(struct gnet_stats_basic *bstats,
259 gen_kill_estimator(bstats, rate_est); 298 gen_kill_estimator(bstats, rate_est);
260 return gen_new_estimator(bstats, rate_est, stats_lock, opt); 299 return gen_new_estimator(bstats, rate_est, stats_lock, opt);
261} 300}
301EXPORT_SYMBOL(gen_replace_estimator);
262 302
303/**
304 * gen_estimator_active - test if estimator is currently in use
305 * @bstats: basic statistics
306 * @rate_est: rate estimator statistics
307 *
308 * Returns true if estimator is active, and false if not.
309 */
310bool gen_estimator_active(const struct gnet_stats_basic *bstats,
311 const struct gnet_stats_rate_est *rate_est)
312{
313 ASSERT_RTNL();
263 314
264EXPORT_SYMBOL(gen_kill_estimator); 315 return gen_find_node(bstats, rate_est) != NULL;
265EXPORT_SYMBOL(gen_new_estimator); 316}
266EXPORT_SYMBOL(gen_replace_estimator); 317EXPORT_SYMBOL(gen_estimator_active);
diff --git a/net/core/neighbour.c b/net/core/neighbour.c
index 1dc728b38589..9c3717a23cf7 100644
--- a/net/core/neighbour.c
+++ b/net/core/neighbour.c
@@ -531,9 +531,7 @@ struct pneigh_entry * pneigh_lookup(struct neigh_table *tbl,
531 if (!n) 531 if (!n)
532 goto out; 532 goto out;
533 533
534#ifdef CONFIG_NET_NS 534 write_pnet(&n->net, hold_net(net));
535 n->net = hold_net(net);
536#endif
537 memcpy(n->key, pkey, key_len); 535 memcpy(n->key, pkey, key_len);
538 n->dev = dev; 536 n->dev = dev;
539 if (dev) 537 if (dev)
@@ -1329,9 +1327,9 @@ struct neigh_parms *neigh_parms_alloc(struct net_device *dev,
1329 struct neigh_table *tbl) 1327 struct neigh_table *tbl)
1330{ 1328{
1331 struct neigh_parms *p, *ref; 1329 struct neigh_parms *p, *ref;
1332 struct net *net; 1330 struct net *net = dev_net(dev);
1331 const struct net_device_ops *ops = dev->netdev_ops;
1333 1332
1334 net = dev_net(dev);
1335 ref = lookup_neigh_params(tbl, net, 0); 1333 ref = lookup_neigh_params(tbl, net, 0);
1336 if (!ref) 1334 if (!ref)
1337 return NULL; 1335 return NULL;
@@ -1340,20 +1338,17 @@ struct neigh_parms *neigh_parms_alloc(struct net_device *dev,
1340 if (p) { 1338 if (p) {
1341 p->tbl = tbl; 1339 p->tbl = tbl;
1342 atomic_set(&p->refcnt, 1); 1340 atomic_set(&p->refcnt, 1);
1343 INIT_RCU_HEAD(&p->rcu_head);
1344 p->reachable_time = 1341 p->reachable_time =
1345 neigh_rand_reach_time(p->base_reachable_time); 1342 neigh_rand_reach_time(p->base_reachable_time);
1346 1343
1347 if (dev->neigh_setup && dev->neigh_setup(dev, p)) { 1344 if (ops->ndo_neigh_setup && ops->ndo_neigh_setup(dev, p)) {
1348 kfree(p); 1345 kfree(p);
1349 return NULL; 1346 return NULL;
1350 } 1347 }
1351 1348
1352 dev_hold(dev); 1349 dev_hold(dev);
1353 p->dev = dev; 1350 p->dev = dev;
1354#ifdef CONFIG_NET_NS 1351 write_pnet(&p->net, hold_net(net));
1355 p->net = hold_net(net);
1356#endif
1357 p->sysctl_table = NULL; 1352 p->sysctl_table = NULL;
1358 write_lock_bh(&tbl->lock); 1353 write_lock_bh(&tbl->lock);
1359 p->next = tbl->parms.next; 1354 p->next = tbl->parms.next;
@@ -1408,11 +1403,8 @@ void neigh_table_init_no_netlink(struct neigh_table *tbl)
1408 unsigned long now = jiffies; 1403 unsigned long now = jiffies;
1409 unsigned long phsize; 1404 unsigned long phsize;
1410 1405
1411#ifdef CONFIG_NET_NS 1406 write_pnet(&tbl->parms.net, &init_net);
1412 tbl->parms.net = &init_net;
1413#endif
1414 atomic_set(&tbl->parms.refcnt, 1); 1407 atomic_set(&tbl->parms.refcnt, 1);
1415 INIT_RCU_HEAD(&tbl->parms.rcu_head);
1416 tbl->parms.reachable_time = 1408 tbl->parms.reachable_time =
1417 neigh_rand_reach_time(tbl->parms.base_reachable_time); 1409 neigh_rand_reach_time(tbl->parms.base_reachable_time);
1418 1410
@@ -1426,9 +1418,8 @@ void neigh_table_init_no_netlink(struct neigh_table *tbl)
1426 panic("cannot create neighbour cache statistics"); 1418 panic("cannot create neighbour cache statistics");
1427 1419
1428#ifdef CONFIG_PROC_FS 1420#ifdef CONFIG_PROC_FS
1429 tbl->pde = proc_create_data(tbl->id, 0, init_net.proc_net_stat, 1421 if (!proc_create_data(tbl->id, 0, init_net.proc_net_stat,
1430 &neigh_stat_seq_fops, tbl); 1422 &neigh_stat_seq_fops, tbl))
1431 if (!tbl->pde)
1432 panic("cannot create neighbour proc dir entry"); 1423 panic("cannot create neighbour proc dir entry");
1433#endif 1424#endif
1434 1425
@@ -2568,128 +2559,128 @@ static struct neigh_sysctl_table {
2568 .procname = "mcast_solicit", 2559 .procname = "mcast_solicit",
2569 .maxlen = sizeof(int), 2560 .maxlen = sizeof(int),
2570 .mode = 0644, 2561 .mode = 0644,
2571 .proc_handler = &proc_dointvec, 2562 .proc_handler = proc_dointvec,
2572 }, 2563 },
2573 { 2564 {
2574 .ctl_name = NET_NEIGH_UCAST_SOLICIT, 2565 .ctl_name = NET_NEIGH_UCAST_SOLICIT,
2575 .procname = "ucast_solicit", 2566 .procname = "ucast_solicit",
2576 .maxlen = sizeof(int), 2567 .maxlen = sizeof(int),
2577 .mode = 0644, 2568 .mode = 0644,
2578 .proc_handler = &proc_dointvec, 2569 .proc_handler = proc_dointvec,
2579 }, 2570 },
2580 { 2571 {
2581 .ctl_name = NET_NEIGH_APP_SOLICIT, 2572 .ctl_name = NET_NEIGH_APP_SOLICIT,
2582 .procname = "app_solicit", 2573 .procname = "app_solicit",
2583 .maxlen = sizeof(int), 2574 .maxlen = sizeof(int),
2584 .mode = 0644, 2575 .mode = 0644,
2585 .proc_handler = &proc_dointvec, 2576 .proc_handler = proc_dointvec,
2586 }, 2577 },
2587 { 2578 {
2588 .procname = "retrans_time", 2579 .procname = "retrans_time",
2589 .maxlen = sizeof(int), 2580 .maxlen = sizeof(int),
2590 .mode = 0644, 2581 .mode = 0644,
2591 .proc_handler = &proc_dointvec_userhz_jiffies, 2582 .proc_handler = proc_dointvec_userhz_jiffies,
2592 }, 2583 },
2593 { 2584 {
2594 .ctl_name = NET_NEIGH_REACHABLE_TIME, 2585 .ctl_name = NET_NEIGH_REACHABLE_TIME,
2595 .procname = "base_reachable_time", 2586 .procname = "base_reachable_time",
2596 .maxlen = sizeof(int), 2587 .maxlen = sizeof(int),
2597 .mode = 0644, 2588 .mode = 0644,
2598 .proc_handler = &proc_dointvec_jiffies, 2589 .proc_handler = proc_dointvec_jiffies,
2599 .strategy = &sysctl_jiffies, 2590 .strategy = sysctl_jiffies,
2600 }, 2591 },
2601 { 2592 {
2602 .ctl_name = NET_NEIGH_DELAY_PROBE_TIME, 2593 .ctl_name = NET_NEIGH_DELAY_PROBE_TIME,
2603 .procname = "delay_first_probe_time", 2594 .procname = "delay_first_probe_time",
2604 .maxlen = sizeof(int), 2595 .maxlen = sizeof(int),
2605 .mode = 0644, 2596 .mode = 0644,
2606 .proc_handler = &proc_dointvec_jiffies, 2597 .proc_handler = proc_dointvec_jiffies,
2607 .strategy = &sysctl_jiffies, 2598 .strategy = sysctl_jiffies,
2608 }, 2599 },
2609 { 2600 {
2610 .ctl_name = NET_NEIGH_GC_STALE_TIME, 2601 .ctl_name = NET_NEIGH_GC_STALE_TIME,
2611 .procname = "gc_stale_time", 2602 .procname = "gc_stale_time",
2612 .maxlen = sizeof(int), 2603 .maxlen = sizeof(int),
2613 .mode = 0644, 2604 .mode = 0644,
2614 .proc_handler = &proc_dointvec_jiffies, 2605 .proc_handler = proc_dointvec_jiffies,
2615 .strategy = &sysctl_jiffies, 2606 .strategy = sysctl_jiffies,
2616 }, 2607 },
2617 { 2608 {
2618 .ctl_name = NET_NEIGH_UNRES_QLEN, 2609 .ctl_name = NET_NEIGH_UNRES_QLEN,
2619 .procname = "unres_qlen", 2610 .procname = "unres_qlen",
2620 .maxlen = sizeof(int), 2611 .maxlen = sizeof(int),
2621 .mode = 0644, 2612 .mode = 0644,
2622 .proc_handler = &proc_dointvec, 2613 .proc_handler = proc_dointvec,
2623 }, 2614 },
2624 { 2615 {
2625 .ctl_name = NET_NEIGH_PROXY_QLEN, 2616 .ctl_name = NET_NEIGH_PROXY_QLEN,
2626 .procname = "proxy_qlen", 2617 .procname = "proxy_qlen",
2627 .maxlen = sizeof(int), 2618 .maxlen = sizeof(int),
2628 .mode = 0644, 2619 .mode = 0644,
2629 .proc_handler = &proc_dointvec, 2620 .proc_handler = proc_dointvec,
2630 }, 2621 },
2631 { 2622 {
2632 .procname = "anycast_delay", 2623 .procname = "anycast_delay",
2633 .maxlen = sizeof(int), 2624 .maxlen = sizeof(int),
2634 .mode = 0644, 2625 .mode = 0644,
2635 .proc_handler = &proc_dointvec_userhz_jiffies, 2626 .proc_handler = proc_dointvec_userhz_jiffies,
2636 }, 2627 },
2637 { 2628 {
2638 .procname = "proxy_delay", 2629 .procname = "proxy_delay",
2639 .maxlen = sizeof(int), 2630 .maxlen = sizeof(int),
2640 .mode = 0644, 2631 .mode = 0644,
2641 .proc_handler = &proc_dointvec_userhz_jiffies, 2632 .proc_handler = proc_dointvec_userhz_jiffies,
2642 }, 2633 },
2643 { 2634 {
2644 .procname = "locktime", 2635 .procname = "locktime",
2645 .maxlen = sizeof(int), 2636 .maxlen = sizeof(int),
2646 .mode = 0644, 2637 .mode = 0644,
2647 .proc_handler = &proc_dointvec_userhz_jiffies, 2638 .proc_handler = proc_dointvec_userhz_jiffies,
2648 }, 2639 },
2649 { 2640 {
2650 .ctl_name = NET_NEIGH_RETRANS_TIME_MS, 2641 .ctl_name = NET_NEIGH_RETRANS_TIME_MS,
2651 .procname = "retrans_time_ms", 2642 .procname = "retrans_time_ms",
2652 .maxlen = sizeof(int), 2643 .maxlen = sizeof(int),
2653 .mode = 0644, 2644 .mode = 0644,
2654 .proc_handler = &proc_dointvec_ms_jiffies, 2645 .proc_handler = proc_dointvec_ms_jiffies,
2655 .strategy = &sysctl_ms_jiffies, 2646 .strategy = sysctl_ms_jiffies,
2656 }, 2647 },
2657 { 2648 {
2658 .ctl_name = NET_NEIGH_REACHABLE_TIME_MS, 2649 .ctl_name = NET_NEIGH_REACHABLE_TIME_MS,
2659 .procname = "base_reachable_time_ms", 2650 .procname = "base_reachable_time_ms",
2660 .maxlen = sizeof(int), 2651 .maxlen = sizeof(int),
2661 .mode = 0644, 2652 .mode = 0644,
2662 .proc_handler = &proc_dointvec_ms_jiffies, 2653 .proc_handler = proc_dointvec_ms_jiffies,
2663 .strategy = &sysctl_ms_jiffies, 2654 .strategy = sysctl_ms_jiffies,
2664 }, 2655 },
2665 { 2656 {
2666 .ctl_name = NET_NEIGH_GC_INTERVAL, 2657 .ctl_name = NET_NEIGH_GC_INTERVAL,
2667 .procname = "gc_interval", 2658 .procname = "gc_interval",
2668 .maxlen = sizeof(int), 2659 .maxlen = sizeof(int),
2669 .mode = 0644, 2660 .mode = 0644,
2670 .proc_handler = &proc_dointvec_jiffies, 2661 .proc_handler = proc_dointvec_jiffies,
2671 .strategy = &sysctl_jiffies, 2662 .strategy = sysctl_jiffies,
2672 }, 2663 },
2673 { 2664 {
2674 .ctl_name = NET_NEIGH_GC_THRESH1, 2665 .ctl_name = NET_NEIGH_GC_THRESH1,
2675 .procname = "gc_thresh1", 2666 .procname = "gc_thresh1",
2676 .maxlen = sizeof(int), 2667 .maxlen = sizeof(int),
2677 .mode = 0644, 2668 .mode = 0644,
2678 .proc_handler = &proc_dointvec, 2669 .proc_handler = proc_dointvec,
2679 }, 2670 },
2680 { 2671 {
2681 .ctl_name = NET_NEIGH_GC_THRESH2, 2672 .ctl_name = NET_NEIGH_GC_THRESH2,
2682 .procname = "gc_thresh2", 2673 .procname = "gc_thresh2",
2683 .maxlen = sizeof(int), 2674 .maxlen = sizeof(int),
2684 .mode = 0644, 2675 .mode = 0644,
2685 .proc_handler = &proc_dointvec, 2676 .proc_handler = proc_dointvec,
2686 }, 2677 },
2687 { 2678 {
2688 .ctl_name = NET_NEIGH_GC_THRESH3, 2679 .ctl_name = NET_NEIGH_GC_THRESH3,
2689 .procname = "gc_thresh3", 2680 .procname = "gc_thresh3",
2690 .maxlen = sizeof(int), 2681 .maxlen = sizeof(int),
2691 .mode = 0644, 2682 .mode = 0644,
2692 .proc_handler = &proc_dointvec, 2683 .proc_handler = proc_dointvec,
2693 }, 2684 },
2694 {}, 2685 {},
2695 }, 2686 },
diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
index 92d6b9467314..6ac29a46e23e 100644
--- a/net/core/net-sysfs.c
+++ b/net/core/net-sysfs.c
@@ -270,7 +270,6 @@ static ssize_t netstat_show(const struct device *d,
270 unsigned long offset) 270 unsigned long offset)
271{ 271{
272 struct net_device *dev = to_net_dev(d); 272 struct net_device *dev = to_net_dev(d);
273 struct net_device_stats *stats;
274 ssize_t ret = -EINVAL; 273 ssize_t ret = -EINVAL;
275 274
276 WARN_ON(offset > sizeof(struct net_device_stats) || 275 WARN_ON(offset > sizeof(struct net_device_stats) ||
@@ -278,7 +277,7 @@ static ssize_t netstat_show(const struct device *d,
278 277
279 read_lock(&dev_base_lock); 278 read_lock(&dev_base_lock);
280 if (dev_isalive(dev)) { 279 if (dev_isalive(dev)) {
281 stats = dev->get_stats(dev); 280 const struct net_device_stats *stats = dev_get_stats(dev);
282 ret = sprintf(buf, fmt_ulong, 281 ret = sprintf(buf, fmt_ulong,
283 *(unsigned long *)(((u8 *) stats) + offset)); 282 *(unsigned long *)(((u8 *) stats) + offset));
284 } 283 }
@@ -428,6 +427,9 @@ static int netdev_uevent(struct device *d, struct kobj_uevent_env *env)
428 struct net_device *dev = to_net_dev(d); 427 struct net_device *dev = to_net_dev(d);
429 int retval; 428 int retval;
430 429
430 if (!net_eq(dev_net(dev), &init_net))
431 return 0;
432
431 /* pass interface to uevent. */ 433 /* pass interface to uevent. */
432 retval = add_uevent_var(env, "INTERFACE=%s", dev->name); 434 retval = add_uevent_var(env, "INTERFACE=%s", dev->name);
433 if (retval) 435 if (retval)
@@ -476,6 +478,10 @@ void netdev_unregister_kobject(struct net_device * net)
476 struct device *dev = &(net->dev); 478 struct device *dev = &(net->dev);
477 479
478 kobject_get(&dev->kobj); 480 kobject_get(&dev->kobj);
481
482 if (dev_net(net) != &init_net)
483 return;
484
479 device_del(dev); 485 device_del(dev);
480} 486}
481 487
@@ -490,7 +496,7 @@ int netdev_register_kobject(struct net_device *net)
490 dev->groups = groups; 496 dev->groups = groups;
491 497
492 BUILD_BUG_ON(BUS_ID_SIZE < IFNAMSIZ); 498 BUILD_BUG_ON(BUS_ID_SIZE < IFNAMSIZ);
493 strlcpy(dev->bus_id, net->name, BUS_ID_SIZE); 499 dev_set_name(dev, net->name);
494 500
495#ifdef CONFIG_SYSFS 501#ifdef CONFIG_SYSFS
496 *groups++ = &netstat_group; 502 *groups++ = &netstat_group;
@@ -501,6 +507,9 @@ int netdev_register_kobject(struct net_device *net)
501#endif 507#endif
502#endif /* CONFIG_SYSFS */ 508#endif /* CONFIG_SYSFS */
503 509
510 if (dev_net(net) != &init_net)
511 return 0;
512
504 return device_add(dev); 513 return device_add(dev);
505} 514}
506 515
diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
index 1895a4ca9c4f..55cffad2f328 100644
--- a/net/core/net_namespace.c
+++ b/net/core/net_namespace.c
@@ -47,7 +47,6 @@ static __net_init int setup_net(struct net *net)
47 goto out; 47 goto out;
48 48
49 ng->len = INITIAL_NET_GEN_PTRS; 49 ng->len = INITIAL_NET_GEN_PTRS;
50 INIT_RCU_HEAD(&ng->rcu);
51 rcu_assign_pointer(net->gen, ng); 50 rcu_assign_pointer(net->gen, ng);
52 51
53 error = 0; 52 error = 0;
@@ -478,7 +477,6 @@ int net_assign_generic(struct net *net, int id, void *data)
478 */ 477 */
479 478
480 ng->len = id; 479 ng->len = id;
481 INIT_RCU_HEAD(&ng->rcu);
482 memcpy(&ng->ptr, &old_ng->ptr, old_ng->len); 480 memcpy(&ng->ptr, &old_ng->ptr, old_ng->len);
483 481
484 rcu_assign_pointer(net->gen, ng); 482 rcu_assign_pointer(net->gen, ng);
diff --git a/net/core/netpoll.c b/net/core/netpoll.c
index dadac6281f20..755414cd49d1 100644
--- a/net/core/netpoll.c
+++ b/net/core/netpoll.c
@@ -58,6 +58,7 @@ static void queue_process(struct work_struct *work)
58 58
59 while ((skb = skb_dequeue(&npinfo->txq))) { 59 while ((skb = skb_dequeue(&npinfo->txq))) {
60 struct net_device *dev = skb->dev; 60 struct net_device *dev = skb->dev;
61 const struct net_device_ops *ops = dev->netdev_ops;
61 struct netdev_queue *txq; 62 struct netdev_queue *txq;
62 63
63 if (!netif_device_present(dev) || !netif_running(dev)) { 64 if (!netif_device_present(dev) || !netif_running(dev)) {
@@ -71,7 +72,7 @@ static void queue_process(struct work_struct *work)
71 __netif_tx_lock(txq, smp_processor_id()); 72 __netif_tx_lock(txq, smp_processor_id());
72 if (netif_tx_queue_stopped(txq) || 73 if (netif_tx_queue_stopped(txq) ||
73 netif_tx_queue_frozen(txq) || 74 netif_tx_queue_frozen(txq) ||
74 dev->hard_start_xmit(skb, dev) != NETDEV_TX_OK) { 75 ops->ndo_start_xmit(skb, dev) != NETDEV_TX_OK) {
75 skb_queue_head(&npinfo->txq, skb); 76 skb_queue_head(&npinfo->txq, skb);
76 __netif_tx_unlock(txq); 77 __netif_tx_unlock(txq);
77 local_irq_restore(flags); 78 local_irq_restore(flags);
@@ -174,12 +175,13 @@ static void service_arp_queue(struct netpoll_info *npi)
174void netpoll_poll(struct netpoll *np) 175void netpoll_poll(struct netpoll *np)
175{ 176{
176 struct net_device *dev = np->dev; 177 struct net_device *dev = np->dev;
178 const struct net_device_ops *ops = dev->netdev_ops;
177 179
178 if (!dev || !netif_running(dev) || !dev->poll_controller) 180 if (!dev || !netif_running(dev) || !ops->ndo_poll_controller)
179 return; 181 return;
180 182
181 /* Process pending work on NIC */ 183 /* Process pending work on NIC */
182 dev->poll_controller(dev); 184 ops->ndo_poll_controller(dev);
183 185
184 poll_napi(dev); 186 poll_napi(dev);
185 187
@@ -274,6 +276,7 @@ static void netpoll_send_skb(struct netpoll *np, struct sk_buff *skb)
274 int status = NETDEV_TX_BUSY; 276 int status = NETDEV_TX_BUSY;
275 unsigned long tries; 277 unsigned long tries;
276 struct net_device *dev = np->dev; 278 struct net_device *dev = np->dev;
279 const struct net_device_ops *ops = dev->netdev_ops;
277 struct netpoll_info *npinfo = np->dev->npinfo; 280 struct netpoll_info *npinfo = np->dev->npinfo;
278 281
279 if (!npinfo || !netif_running(dev) || !netif_device_present(dev)) { 282 if (!npinfo || !netif_running(dev) || !netif_device_present(dev)) {
@@ -294,7 +297,7 @@ static void netpoll_send_skb(struct netpoll *np, struct sk_buff *skb)
294 tries > 0; --tries) { 297 tries > 0; --tries) {
295 if (__netif_tx_trylock(txq)) { 298 if (__netif_tx_trylock(txq)) {
296 if (!netif_tx_queue_stopped(txq)) 299 if (!netif_tx_queue_stopped(txq))
297 status = dev->hard_start_xmit(skb, dev); 300 status = ops->ndo_start_xmit(skb, dev);
298 __netif_tx_unlock(txq); 301 __netif_tx_unlock(txq);
299 302
300 if (status == NETDEV_TX_OK) 303 if (status == NETDEV_TX_OK)
@@ -345,7 +348,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
345 udph->check = csum_tcpudp_magic(htonl(np->local_ip), 348 udph->check = csum_tcpudp_magic(htonl(np->local_ip),
346 htonl(np->remote_ip), 349 htonl(np->remote_ip),
347 udp_len, IPPROTO_UDP, 350 udp_len, IPPROTO_UDP,
348 csum_partial((unsigned char *)udph, udp_len, 0)); 351 csum_partial(udph, udp_len, 0));
349 if (udph->check == 0) 352 if (udph->check == 0)
350 udph->check = CSUM_MANGLED_0; 353 udph->check = CSUM_MANGLED_0;
351 354
@@ -555,7 +558,6 @@ out:
555 558
556void netpoll_print_options(struct netpoll *np) 559void netpoll_print_options(struct netpoll *np)
557{ 560{
558 DECLARE_MAC_BUF(mac);
559 printk(KERN_INFO "%s: local port %d\n", 561 printk(KERN_INFO "%s: local port %d\n",
560 np->name, np->local_port); 562 np->name, np->local_port);
561 printk(KERN_INFO "%s: local IP %d.%d.%d.%d\n", 563 printk(KERN_INFO "%s: local IP %d.%d.%d.%d\n",
@@ -566,8 +568,8 @@ void netpoll_print_options(struct netpoll *np)
566 np->name, np->remote_port); 568 np->name, np->remote_port);
567 printk(KERN_INFO "%s: remote IP %d.%d.%d.%d\n", 569 printk(KERN_INFO "%s: remote IP %d.%d.%d.%d\n",
568 np->name, HIPQUAD(np->remote_ip)); 570 np->name, HIPQUAD(np->remote_ip));
569 printk(KERN_INFO "%s: remote ethernet address %s\n", 571 printk(KERN_INFO "%s: remote ethernet address %pM\n",
570 np->name, print_mac(mac, np->remote_mac)); 572 np->name, np->remote_mac);
571} 573}
572 574
573int netpoll_parse_options(struct netpoll *np, char *opt) 575int netpoll_parse_options(struct netpoll *np, char *opt)
@@ -697,7 +699,7 @@ int netpoll_setup(struct netpoll *np)
697 atomic_inc(&npinfo->refcnt); 699 atomic_inc(&npinfo->refcnt);
698 } 700 }
699 701
700 if (!ndev->poll_controller) { 702 if (!ndev->netdev_ops->ndo_poll_controller) {
701 printk(KERN_ERR "%s: %s doesn't support polling, aborting.\n", 703 printk(KERN_ERR "%s: %s doesn't support polling, aborting.\n",
702 np->name, np->dev_name); 704 np->name, np->dev_name);
703 err = -ENOTSUPP; 705 err = -ENOTSUPP;
diff --git a/net/core/pktgen.c b/net/core/pktgen.c
index 8997e912aaaf..65498483325a 100644
--- a/net/core/pktgen.c
+++ b/net/core/pktgen.c
@@ -422,6 +422,7 @@ static struct pktgen_dev *pktgen_find_dev(struct pktgen_thread *t,
422 const char *ifname); 422 const char *ifname);
423static int pktgen_device_event(struct notifier_block *, unsigned long, void *); 423static int pktgen_device_event(struct notifier_block *, unsigned long, void *);
424static void pktgen_run_all_threads(void); 424static void pktgen_run_all_threads(void);
425static void pktgen_reset_all_threads(void);
425static void pktgen_stop_all_threads_ifs(void); 426static void pktgen_stop_all_threads_ifs(void);
426static int pktgen_stop_device(struct pktgen_dev *pkt_dev); 427static int pktgen_stop_device(struct pktgen_dev *pkt_dev);
427static void pktgen_stop(struct pktgen_thread *t); 428static void pktgen_stop(struct pktgen_thread *t);
@@ -480,6 +481,9 @@ static ssize_t pgctrl_write(struct file *file, const char __user * buf,
480 else if (!strcmp(data, "start")) 481 else if (!strcmp(data, "start"))
481 pktgen_run_all_threads(); 482 pktgen_run_all_threads();
482 483
484 else if (!strcmp(data, "reset"))
485 pktgen_reset_all_threads();
486
483 else 487 else
484 printk(KERN_WARNING "pktgen: Unknown command: %s\n", data); 488 printk(KERN_WARNING "pktgen: Unknown command: %s\n", data);
485 489
@@ -509,7 +513,6 @@ static int pktgen_if_show(struct seq_file *seq, void *v)
509 __u64 sa; 513 __u64 sa;
510 __u64 stopped; 514 __u64 stopped;
511 __u64 now = getCurUs(); 515 __u64 now = getCurUs();
512 DECLARE_MAC_BUF(mac);
513 516
514 seq_printf(seq, 517 seq_printf(seq,
515 "Params: count %llu min_pkt_size: %u max_pkt_size: %u\n", 518 "Params: count %llu min_pkt_size: %u max_pkt_size: %u\n",
@@ -554,12 +557,12 @@ static int pktgen_if_show(struct seq_file *seq, void *v)
554 557
555 seq_puts(seq, " src_mac: "); 558 seq_puts(seq, " src_mac: ");
556 559
557 seq_printf(seq, "%s ", 560 seq_printf(seq, "%pM ",
558 print_mac(mac, is_zero_ether_addr(pkt_dev->src_mac) ? 561 is_zero_ether_addr(pkt_dev->src_mac) ?
559 pkt_dev->odev->dev_addr : pkt_dev->src_mac)); 562 pkt_dev->odev->dev_addr : pkt_dev->src_mac);
560 563
561 seq_printf(seq, "dst_mac: "); 564 seq_printf(seq, "dst_mac: ");
562 seq_printf(seq, "%s\n", print_mac(mac, pkt_dev->dst_mac)); 565 seq_printf(seq, "%pM\n", pkt_dev->dst_mac);
563 566
564 seq_printf(seq, 567 seq_printf(seq,
565 " udp_src_min: %d udp_src_max: %d udp_dst_min: %d udp_dst_max: %d\n", 568 " udp_src_min: %d udp_src_max: %d udp_dst_min: %d udp_dst_max: %d\n",
@@ -2162,7 +2165,8 @@ static void get_ipsec_sa(struct pktgen_dev *pkt_dev, int flow)
2162 struct xfrm_state *x = pkt_dev->flows[flow].x; 2165 struct xfrm_state *x = pkt_dev->flows[flow].x;
2163 if (!x) { 2166 if (!x) {
2164 /*slow path: we dont already have xfrm_state*/ 2167 /*slow path: we dont already have xfrm_state*/
2165 x = xfrm_stateonly_find((xfrm_address_t *)&pkt_dev->cur_daddr, 2168 x = xfrm_stateonly_find(&init_net,
2169 (xfrm_address_t *)&pkt_dev->cur_daddr,
2166 (xfrm_address_t *)&pkt_dev->cur_saddr, 2170 (xfrm_address_t *)&pkt_dev->cur_saddr,
2167 AF_INET, 2171 AF_INET,
2168 pkt_dev->ipsmode, 2172 pkt_dev->ipsmode,
@@ -3169,6 +3173,24 @@ static void pktgen_run_all_threads(void)
3169 pktgen_wait_all_threads_run(); 3173 pktgen_wait_all_threads_run();
3170} 3174}
3171 3175
3176static void pktgen_reset_all_threads(void)
3177{
3178 struct pktgen_thread *t;
3179
3180 pr_debug("pktgen: entering pktgen_reset_all_threads.\n");
3181
3182 mutex_lock(&pktgen_thread_lock);
3183
3184 list_for_each_entry(t, &pktgen_threads, th_list)
3185 t->control |= (T_REMDEVALL);
3186
3187 mutex_unlock(&pktgen_thread_lock);
3188
3189 schedule_timeout_interruptible(msecs_to_jiffies(125)); /* Propagate thread->control */
3190
3191 pktgen_wait_all_threads_run();
3192}
3193
3172static void show_results(struct pktgen_dev *pkt_dev, int nr_frags) 3194static void show_results(struct pktgen_dev *pkt_dev, int nr_frags)
3173{ 3195{
3174 __u64 total_us, bps, mbps, pps, idle; 3196 __u64 total_us, bps, mbps, pps, idle;
@@ -3331,14 +3353,14 @@ static void pktgen_rem_thread(struct pktgen_thread *t)
3331 3353
3332static __inline__ void pktgen_xmit(struct pktgen_dev *pkt_dev) 3354static __inline__ void pktgen_xmit(struct pktgen_dev *pkt_dev)
3333{ 3355{
3334 struct net_device *odev = NULL; 3356 struct net_device *odev = pkt_dev->odev;
3357 int (*xmit)(struct sk_buff *, struct net_device *)
3358 = odev->netdev_ops->ndo_start_xmit;
3335 struct netdev_queue *txq; 3359 struct netdev_queue *txq;
3336 __u64 idle_start = 0; 3360 __u64 idle_start = 0;
3337 u16 queue_map; 3361 u16 queue_map;
3338 int ret; 3362 int ret;
3339 3363
3340 odev = pkt_dev->odev;
3341
3342 if (pkt_dev->delay_us || pkt_dev->delay_ns) { 3364 if (pkt_dev->delay_us || pkt_dev->delay_ns) {
3343 u64 now; 3365 u64 now;
3344 3366
@@ -3419,7 +3441,7 @@ static __inline__ void pktgen_xmit(struct pktgen_dev *pkt_dev)
3419 3441
3420 atomic_inc(&(pkt_dev->skb->users)); 3442 atomic_inc(&(pkt_dev->skb->users));
3421 retry_now: 3443 retry_now:
3422 ret = odev->hard_start_xmit(pkt_dev->skb, odev); 3444 ret = (*xmit)(pkt_dev->skb, odev);
3423 if (likely(ret == NETDEV_TX_OK)) { 3445 if (likely(ret == NETDEV_TX_OK)) {
3424 pkt_dev->last_ok = 1; 3446 pkt_dev->last_ok = 1;
3425 pkt_dev->sofar++; 3447 pkt_dev->sofar++;
diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
index 4dfb6b4d4559..790dd205bb5d 100644
--- a/net/core/rtnetlink.c
+++ b/net/core/rtnetlink.c
@@ -551,7 +551,7 @@ static void set_operstate(struct net_device *dev, unsigned char transition)
551} 551}
552 552
553static void copy_rtnl_link_stats(struct rtnl_link_stats *a, 553static void copy_rtnl_link_stats(struct rtnl_link_stats *a,
554 struct net_device_stats *b) 554 const struct net_device_stats *b)
555{ 555{
556 a->rx_packets = b->rx_packets; 556 a->rx_packets = b->rx_packets;
557 a->tx_packets = b->tx_packets; 557 a->tx_packets = b->tx_packets;
@@ -609,7 +609,7 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb, struct net_device *dev,
609 struct netdev_queue *txq; 609 struct netdev_queue *txq;
610 struct ifinfomsg *ifm; 610 struct ifinfomsg *ifm;
611 struct nlmsghdr *nlh; 611 struct nlmsghdr *nlh;
612 struct net_device_stats *stats; 612 const struct net_device_stats *stats;
613 struct nlattr *attr; 613 struct nlattr *attr;
614 614
615 nlh = nlmsg_put(skb, pid, seq, type, sizeof(*ifm), flags); 615 nlh = nlmsg_put(skb, pid, seq, type, sizeof(*ifm), flags);
@@ -666,7 +666,7 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb, struct net_device *dev,
666 if (attr == NULL) 666 if (attr == NULL)
667 goto nla_put_failure; 667 goto nla_put_failure;
668 668
669 stats = dev->get_stats(dev); 669 stats = dev_get_stats(dev);
670 copy_rtnl_link_stats(nla_data(attr), stats); 670 copy_rtnl_link_stats(nla_data(attr), stats);
671 671
672 if (dev->rtnl_link_ops) { 672 if (dev->rtnl_link_ops) {
@@ -762,6 +762,7 @@ static int validate_linkmsg(struct net_device *dev, struct nlattr *tb[])
762static int do_setlink(struct net_device *dev, struct ifinfomsg *ifm, 762static int do_setlink(struct net_device *dev, struct ifinfomsg *ifm,
763 struct nlattr **tb, char *ifname, int modified) 763 struct nlattr **tb, char *ifname, int modified)
764{ 764{
765 const struct net_device_ops *ops = dev->netdev_ops;
765 int send_addr_notify = 0; 766 int send_addr_notify = 0;
766 int err; 767 int err;
767 768
@@ -783,7 +784,7 @@ static int do_setlink(struct net_device *dev, struct ifinfomsg *ifm,
783 struct rtnl_link_ifmap *u_map; 784 struct rtnl_link_ifmap *u_map;
784 struct ifmap k_map; 785 struct ifmap k_map;
785 786
786 if (!dev->set_config) { 787 if (!ops->ndo_set_config) {
787 err = -EOPNOTSUPP; 788 err = -EOPNOTSUPP;
788 goto errout; 789 goto errout;
789 } 790 }
@@ -801,7 +802,7 @@ static int do_setlink(struct net_device *dev, struct ifinfomsg *ifm,
801 k_map.dma = (unsigned char) u_map->dma; 802 k_map.dma = (unsigned char) u_map->dma;
802 k_map.port = (unsigned char) u_map->port; 803 k_map.port = (unsigned char) u_map->port;
803 804
804 err = dev->set_config(dev, &k_map); 805 err = ops->ndo_set_config(dev, &k_map);
805 if (err < 0) 806 if (err < 0)
806 goto errout; 807 goto errout;
807 808
@@ -812,7 +813,7 @@ static int do_setlink(struct net_device *dev, struct ifinfomsg *ifm,
812 struct sockaddr *sa; 813 struct sockaddr *sa;
813 int len; 814 int len;
814 815
815 if (!dev->set_mac_address) { 816 if (!ops->ndo_set_mac_address) {
816 err = -EOPNOTSUPP; 817 err = -EOPNOTSUPP;
817 goto errout; 818 goto errout;
818 } 819 }
@@ -831,7 +832,7 @@ static int do_setlink(struct net_device *dev, struct ifinfomsg *ifm,
831 sa->sa_family = dev->type; 832 sa->sa_family = dev->type;
832 memcpy(sa->sa_data, nla_data(tb[IFLA_ADDRESS]), 833 memcpy(sa->sa_data, nla_data(tb[IFLA_ADDRESS]),
833 dev->addr_len); 834 dev->addr_len);
834 err = dev->set_mac_address(dev, sa); 835 err = ops->ndo_set_mac_address(dev, sa);
835 kfree(sa); 836 kfree(sa);
836 if (err) 837 if (err)
837 goto errout; 838 goto errout;
diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index 65f7757465bd..b8d0abb26433 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -501,7 +501,7 @@ static void __copy_skb_header(struct sk_buff *new, const struct sk_buff *old)
501 new->network_header = old->network_header; 501 new->network_header = old->network_header;
502 new->mac_header = old->mac_header; 502 new->mac_header = old->mac_header;
503 new->dst = dst_clone(old->dst); 503 new->dst = dst_clone(old->dst);
504#ifdef CONFIG_INET 504#ifdef CONFIG_XFRM
505 new->sp = secpath_get(old->sp); 505 new->sp = secpath_get(old->sp);
506#endif 506#endif
507 memcpy(new->cb, old->cb, sizeof(old->cb)); 507 memcpy(new->cb, old->cb, sizeof(old->cb));
@@ -556,6 +556,7 @@ static struct sk_buff *__skb_clone(struct sk_buff *n, struct sk_buff *skb)
556 C(truesize); 556 C(truesize);
557#if defined(CONFIG_MAC80211) || defined(CONFIG_MAC80211_MODULE) 557#if defined(CONFIG_MAC80211) || defined(CONFIG_MAC80211_MODULE)
558 C(do_not_encrypt); 558 C(do_not_encrypt);
559 C(requeue);
559#endif 560#endif
560 atomic_set(&n->users, 1); 561 atomic_set(&n->users, 1);
561 562
@@ -2017,6 +2018,148 @@ void skb_split(struct sk_buff *skb, struct sk_buff *skb1, const u32 len)
2017 skb_split_no_header(skb, skb1, len, pos); 2018 skb_split_no_header(skb, skb1, len, pos);
2018} 2019}
2019 2020
2021/* Shifting from/to a cloned skb is a no-go.
2022 *
2023 * Caller cannot keep skb_shinfo related pointers past calling here!
2024 */
2025static int skb_prepare_for_shift(struct sk_buff *skb)
2026{
2027 return skb_cloned(skb) && pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
2028}
2029
2030/**
2031 * skb_shift - Shifts paged data partially from skb to another
2032 * @tgt: buffer into which tail data gets added
2033 * @skb: buffer from which the paged data comes from
2034 * @shiftlen: shift up to this many bytes
2035 *
2036 * Attempts to shift up to shiftlen worth of bytes, which may be less than
2037 * the length of the skb, from tgt to skb. Returns number bytes shifted.
2038 * It's up to caller to free skb if everything was shifted.
2039 *
2040 * If @tgt runs out of frags, the whole operation is aborted.
2041 *
2042 * Skb cannot include anything else but paged data while tgt is allowed
2043 * to have non-paged data as well.
2044 *
2045 * TODO: full sized shift could be optimized but that would need
2046 * specialized skb free'er to handle frags without up-to-date nr_frags.
2047 */
2048int skb_shift(struct sk_buff *tgt, struct sk_buff *skb, int shiftlen)
2049{
2050 int from, to, merge, todo;
2051 struct skb_frag_struct *fragfrom, *fragto;
2052
2053 BUG_ON(shiftlen > skb->len);
2054 BUG_ON(skb_headlen(skb)); /* Would corrupt stream */
2055
2056 todo = shiftlen;
2057 from = 0;
2058 to = skb_shinfo(tgt)->nr_frags;
2059 fragfrom = &skb_shinfo(skb)->frags[from];
2060
2061 /* Actual merge is delayed until the point when we know we can
2062 * commit all, so that we don't have to undo partial changes
2063 */
2064 if (!to ||
2065 !skb_can_coalesce(tgt, to, fragfrom->page, fragfrom->page_offset)) {
2066 merge = -1;
2067 } else {
2068 merge = to - 1;
2069
2070 todo -= fragfrom->size;
2071 if (todo < 0) {
2072 if (skb_prepare_for_shift(skb) ||
2073 skb_prepare_for_shift(tgt))
2074 return 0;
2075
2076 /* All previous frag pointers might be stale! */
2077 fragfrom = &skb_shinfo(skb)->frags[from];
2078 fragto = &skb_shinfo(tgt)->frags[merge];
2079
2080 fragto->size += shiftlen;
2081 fragfrom->size -= shiftlen;
2082 fragfrom->page_offset += shiftlen;
2083
2084 goto onlymerged;
2085 }
2086
2087 from++;
2088 }
2089
2090 /* Skip full, not-fitting skb to avoid expensive operations */
2091 if ((shiftlen == skb->len) &&
2092 (skb_shinfo(skb)->nr_frags - from) > (MAX_SKB_FRAGS - to))
2093 return 0;
2094
2095 if (skb_prepare_for_shift(skb) || skb_prepare_for_shift(tgt))
2096 return 0;
2097
2098 while ((todo > 0) && (from < skb_shinfo(skb)->nr_frags)) {
2099 if (to == MAX_SKB_FRAGS)
2100 return 0;
2101
2102 fragfrom = &skb_shinfo(skb)->frags[from];
2103 fragto = &skb_shinfo(tgt)->frags[to];
2104
2105 if (todo >= fragfrom->size) {
2106 *fragto = *fragfrom;
2107 todo -= fragfrom->size;
2108 from++;
2109 to++;
2110
2111 } else {
2112 get_page(fragfrom->page);
2113 fragto->page = fragfrom->page;
2114 fragto->page_offset = fragfrom->page_offset;
2115 fragto->size = todo;
2116
2117 fragfrom->page_offset += todo;
2118 fragfrom->size -= todo;
2119 todo = 0;
2120
2121 to++;
2122 break;
2123 }
2124 }
2125
2126 /* Ready to "commit" this state change to tgt */
2127 skb_shinfo(tgt)->nr_frags = to;
2128
2129 if (merge >= 0) {
2130 fragfrom = &skb_shinfo(skb)->frags[0];
2131 fragto = &skb_shinfo(tgt)->frags[merge];
2132
2133 fragto->size += fragfrom->size;
2134 put_page(fragfrom->page);
2135 }
2136
2137 /* Reposition in the original skb */
2138 to = 0;
2139 while (from < skb_shinfo(skb)->nr_frags)
2140 skb_shinfo(skb)->frags[to++] = skb_shinfo(skb)->frags[from++];
2141 skb_shinfo(skb)->nr_frags = to;
2142
2143 BUG_ON(todo > 0 && !skb_shinfo(skb)->nr_frags);
2144
2145onlymerged:
2146 /* Most likely the tgt won't ever need its checksum anymore, skb on
2147 * the other hand might need it if it needs to be resent
2148 */
2149 tgt->ip_summed = CHECKSUM_PARTIAL;
2150 skb->ip_summed = CHECKSUM_PARTIAL;
2151
2152 /* Yak, is it really working this way? Some helper please? */
2153 skb->len -= shiftlen;
2154 skb->data_len -= shiftlen;
2155 skb->truesize -= shiftlen;
2156 tgt->len += shiftlen;
2157 tgt->data_len += shiftlen;
2158 tgt->truesize += shiftlen;
2159
2160 return shiftlen;
2161}
2162
2020/** 2163/**
2021 * skb_prepare_seq_read - Prepare a sequential read of skb data 2164 * skb_prepare_seq_read - Prepare a sequential read of skb data
2022 * @skb: the buffer to read 2165 * @skb: the buffer to read
@@ -2285,6 +2428,7 @@ struct sk_buff *skb_segment(struct sk_buff *skb, int features)
2285{ 2428{
2286 struct sk_buff *segs = NULL; 2429 struct sk_buff *segs = NULL;
2287 struct sk_buff *tail = NULL; 2430 struct sk_buff *tail = NULL;
2431 struct sk_buff *fskb = skb_shinfo(skb)->frag_list;
2288 unsigned int mss = skb_shinfo(skb)->gso_size; 2432 unsigned int mss = skb_shinfo(skb)->gso_size;
2289 unsigned int doffset = skb->data - skb_mac_header(skb); 2433 unsigned int doffset = skb->data - skb_mac_header(skb);
2290 unsigned int offset = doffset; 2434 unsigned int offset = doffset;
@@ -2304,7 +2448,6 @@ struct sk_buff *skb_segment(struct sk_buff *skb, int features)
2304 struct sk_buff *nskb; 2448 struct sk_buff *nskb;
2305 skb_frag_t *frag; 2449 skb_frag_t *frag;
2306 int hsize; 2450 int hsize;
2307 int k;
2308 int size; 2451 int size;
2309 2452
2310 len = skb->len - offset; 2453 len = skb->len - offset;
@@ -2317,9 +2460,36 @@ struct sk_buff *skb_segment(struct sk_buff *skb, int features)
2317 if (hsize > len || !sg) 2460 if (hsize > len || !sg)
2318 hsize = len; 2461 hsize = len;
2319 2462
2320 nskb = alloc_skb(hsize + doffset + headroom, GFP_ATOMIC); 2463 if (!hsize && i >= nfrags) {
2321 if (unlikely(!nskb)) 2464 BUG_ON(fskb->len != len);
2322 goto err; 2465
2466 pos += len;
2467 nskb = skb_clone(fskb, GFP_ATOMIC);
2468 fskb = fskb->next;
2469
2470 if (unlikely(!nskb))
2471 goto err;
2472
2473 hsize = skb_end_pointer(nskb) - nskb->head;
2474 if (skb_cow_head(nskb, doffset + headroom)) {
2475 kfree_skb(nskb);
2476 goto err;
2477 }
2478
2479 nskb->truesize += skb_end_pointer(nskb) - nskb->head -
2480 hsize;
2481 skb_release_head_state(nskb);
2482 __skb_push(nskb, doffset);
2483 } else {
2484 nskb = alloc_skb(hsize + doffset + headroom,
2485 GFP_ATOMIC);
2486
2487 if (unlikely(!nskb))
2488 goto err;
2489
2490 skb_reserve(nskb, headroom);
2491 __skb_put(nskb, doffset);
2492 }
2323 2493
2324 if (segs) 2494 if (segs)
2325 tail->next = nskb; 2495 tail->next = nskb;
@@ -2330,13 +2500,15 @@ struct sk_buff *skb_segment(struct sk_buff *skb, int features)
2330 __copy_skb_header(nskb, skb); 2500 __copy_skb_header(nskb, skb);
2331 nskb->mac_len = skb->mac_len; 2501 nskb->mac_len = skb->mac_len;
2332 2502
2333 skb_reserve(nskb, headroom);
2334 skb_reset_mac_header(nskb); 2503 skb_reset_mac_header(nskb);
2335 skb_set_network_header(nskb, skb->mac_len); 2504 skb_set_network_header(nskb, skb->mac_len);
2336 nskb->transport_header = (nskb->network_header + 2505 nskb->transport_header = (nskb->network_header +
2337 skb_network_header_len(skb)); 2506 skb_network_header_len(skb));
2338 skb_copy_from_linear_data(skb, skb_put(nskb, doffset), 2507 skb_copy_from_linear_data(skb, nskb->data, doffset);
2339 doffset); 2508
2509 if (pos >= offset + len)
2510 continue;
2511
2340 if (!sg) { 2512 if (!sg) {
2341 nskb->ip_summed = CHECKSUM_NONE; 2513 nskb->ip_summed = CHECKSUM_NONE;
2342 nskb->csum = skb_copy_and_csum_bits(skb, offset, 2514 nskb->csum = skb_copy_and_csum_bits(skb, offset,
@@ -2346,14 +2518,11 @@ struct sk_buff *skb_segment(struct sk_buff *skb, int features)
2346 } 2518 }
2347 2519
2348 frag = skb_shinfo(nskb)->frags; 2520 frag = skb_shinfo(nskb)->frags;
2349 k = 0;
2350 2521
2351 skb_copy_from_linear_data_offset(skb, offset, 2522 skb_copy_from_linear_data_offset(skb, offset,
2352 skb_put(nskb, hsize), hsize); 2523 skb_put(nskb, hsize), hsize);
2353 2524
2354 while (pos < offset + len) { 2525 while (pos < offset + len && i < nfrags) {
2355 BUG_ON(i >= nfrags);
2356
2357 *frag = skb_shinfo(skb)->frags[i]; 2526 *frag = skb_shinfo(skb)->frags[i];
2358 get_page(frag->page); 2527 get_page(frag->page);
2359 size = frag->size; 2528 size = frag->size;
@@ -2363,20 +2532,39 @@ struct sk_buff *skb_segment(struct sk_buff *skb, int features)
2363 frag->size -= offset - pos; 2532 frag->size -= offset - pos;
2364 } 2533 }
2365 2534
2366 k++; 2535 skb_shinfo(nskb)->nr_frags++;
2367 2536
2368 if (pos + size <= offset + len) { 2537 if (pos + size <= offset + len) {
2369 i++; 2538 i++;
2370 pos += size; 2539 pos += size;
2371 } else { 2540 } else {
2372 frag->size -= pos + size - (offset + len); 2541 frag->size -= pos + size - (offset + len);
2373 break; 2542 goto skip_fraglist;
2374 } 2543 }
2375 2544
2376 frag++; 2545 frag++;
2377 } 2546 }
2378 2547
2379 skb_shinfo(nskb)->nr_frags = k; 2548 if (pos < offset + len) {
2549 struct sk_buff *fskb2 = fskb;
2550
2551 BUG_ON(pos + fskb->len != offset + len);
2552
2553 pos += fskb->len;
2554 fskb = fskb->next;
2555
2556 if (fskb2->next) {
2557 fskb2 = skb_clone(fskb2, GFP_ATOMIC);
2558 if (!fskb2)
2559 goto err;
2560 } else
2561 skb_get(fskb2);
2562
2563 BUG_ON(skb_shinfo(nskb)->frag_list);
2564 skb_shinfo(nskb)->frag_list = fskb2;
2565 }
2566
2567skip_fraglist:
2380 nskb->data_len = len - hsize; 2568 nskb->data_len = len - hsize;
2381 nskb->len += nskb->data_len; 2569 nskb->len += nskb->data_len;
2382 nskb->truesize += nskb->data_len; 2570 nskb->truesize += nskb->data_len;
@@ -2394,6 +2582,65 @@ err:
2394 2582
2395EXPORT_SYMBOL_GPL(skb_segment); 2583EXPORT_SYMBOL_GPL(skb_segment);
2396 2584
2585int skb_gro_receive(struct sk_buff **head, struct sk_buff *skb)
2586{
2587 struct sk_buff *p = *head;
2588 struct sk_buff *nskb;
2589 unsigned int headroom;
2590 unsigned int hlen = p->data - skb_mac_header(p);
2591
2592 if (hlen + p->len + skb->len >= 65536)
2593 return -E2BIG;
2594
2595 if (skb_shinfo(p)->frag_list)
2596 goto merge;
2597
2598 headroom = skb_headroom(p);
2599 nskb = netdev_alloc_skb(p->dev, headroom);
2600 if (unlikely(!nskb))
2601 return -ENOMEM;
2602
2603 __copy_skb_header(nskb, p);
2604 nskb->mac_len = p->mac_len;
2605
2606 skb_reserve(nskb, headroom);
2607
2608 skb_set_mac_header(nskb, -hlen);
2609 skb_set_network_header(nskb, skb_network_offset(p));
2610 skb_set_transport_header(nskb, skb_transport_offset(p));
2611
2612 memcpy(skb_mac_header(nskb), skb_mac_header(p), hlen);
2613
2614 *NAPI_GRO_CB(nskb) = *NAPI_GRO_CB(p);
2615 skb_shinfo(nskb)->frag_list = p;
2616 skb_header_release(p);
2617 nskb->prev = p;
2618
2619 nskb->data_len += p->len;
2620 nskb->truesize += p->len;
2621 nskb->len += p->len;
2622
2623 *head = nskb;
2624 nskb->next = p->next;
2625 p->next = NULL;
2626
2627 p = nskb;
2628
2629merge:
2630 NAPI_GRO_CB(p)->count++;
2631 p->prev->next = skb;
2632 p->prev = skb;
2633 skb_header_release(skb);
2634
2635 p->data_len += skb->len;
2636 p->truesize += skb->len;
2637 p->len += skb->len;
2638
2639 NAPI_GRO_CB(skb)->same_flow = 1;
2640 return 0;
2641}
2642EXPORT_SYMBOL_GPL(skb_gro_receive);
2643
2397void __init skb_init(void) 2644void __init skb_init(void)
2398{ 2645{
2399 skbuff_head_cache = kmem_cache_create("skbuff_head_cache", 2646 skbuff_head_cache = kmem_cache_create("skbuff_head_cache",
diff --git a/net/core/sock.c b/net/core/sock.c
index edf7220889a4..f3a0d08cbb48 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -1071,7 +1071,7 @@ struct sock *sk_clone(const struct sock *sk, const gfp_t priority)
1071 newsk->sk_sleep = NULL; 1071 newsk->sk_sleep = NULL;
1072 1072
1073 if (newsk->sk_prot->sockets_allocated) 1073 if (newsk->sk_prot->sockets_allocated)
1074 atomic_inc(newsk->sk_prot->sockets_allocated); 1074 percpu_counter_inc(newsk->sk_prot->sockets_allocated);
1075 } 1075 }
1076out: 1076out:
1077 return newsk; 1077 return newsk;
@@ -1463,8 +1463,12 @@ int __sk_mem_schedule(struct sock *sk, int size, int kind)
1463 } 1463 }
1464 1464
1465 if (prot->memory_pressure) { 1465 if (prot->memory_pressure) {
1466 if (!*prot->memory_pressure || 1466 int alloc;
1467 prot->sysctl_mem[2] > atomic_read(prot->sockets_allocated) * 1467
1468 if (!*prot->memory_pressure)
1469 return 1;
1470 alloc = percpu_counter_read_positive(prot->sockets_allocated);
1471 if (prot->sysctl_mem[2] > alloc *
1468 sk_mem_pages(sk->sk_wmem_queued + 1472 sk_mem_pages(sk->sk_wmem_queued +
1469 atomic_read(&sk->sk_rmem_alloc) + 1473 atomic_read(&sk->sk_rmem_alloc) +
1470 sk->sk_forward_alloc)) 1474 sk->sk_forward_alloc))
@@ -2037,7 +2041,8 @@ int proto_register(struct proto *prot, int alloc_slab)
2037{ 2041{
2038 if (alloc_slab) { 2042 if (alloc_slab) {
2039 prot->slab = kmem_cache_create(prot->name, prot->obj_size, 0, 2043 prot->slab = kmem_cache_create(prot->name, prot->obj_size, 0,
2040 SLAB_HWCACHE_ALIGN, NULL); 2044 SLAB_HWCACHE_ALIGN | prot->slab_flags,
2045 NULL);
2041 2046
2042 if (prot->slab == NULL) { 2047 if (prot->slab == NULL) {
2043 printk(KERN_CRIT "%s: Can't create sock SLAB cache!\n", 2048 printk(KERN_CRIT "%s: Can't create sock SLAB cache!\n",
@@ -2076,7 +2081,9 @@ int proto_register(struct proto *prot, int alloc_slab)
2076 prot->twsk_prot->twsk_slab = 2081 prot->twsk_prot->twsk_slab =
2077 kmem_cache_create(prot->twsk_prot->twsk_slab_name, 2082 kmem_cache_create(prot->twsk_prot->twsk_slab_name,
2078 prot->twsk_prot->twsk_obj_size, 2083 prot->twsk_prot->twsk_obj_size,
2079 0, SLAB_HWCACHE_ALIGN, 2084 0,
2085 SLAB_HWCACHE_ALIGN |
2086 prot->slab_flags,
2080 NULL); 2087 NULL);
2081 if (prot->twsk_prot->twsk_slab == NULL) 2088 if (prot->twsk_prot->twsk_slab == NULL)
2082 goto out_free_timewait_sock_slab_name; 2089 goto out_free_timewait_sock_slab_name;
@@ -2164,7 +2171,7 @@ static void proto_seq_printf(struct seq_file *seq, struct proto *proto)
2164 "%2c %2c %2c %2c %2c %2c %2c %2c %2c %2c %2c %2c %2c %2c %2c %2c %2c %2c %2c\n", 2171 "%2c %2c %2c %2c %2c %2c %2c %2c %2c %2c %2c %2c %2c %2c %2c %2c %2c %2c %2c\n",
2165 proto->name, 2172 proto->name,
2166 proto->obj_size, 2173 proto->obj_size,
2167 proto->sockets_allocated != NULL ? atomic_read(proto->sockets_allocated) : -1, 2174 sock_prot_inuse_get(seq_file_net(seq), proto),
2168 proto->memory_allocated != NULL ? atomic_read(proto->memory_allocated) : -1, 2175 proto->memory_allocated != NULL ? atomic_read(proto->memory_allocated) : -1,
2169 proto->memory_pressure != NULL ? *proto->memory_pressure ? "yes" : "no" : "NI", 2176 proto->memory_pressure != NULL ? *proto->memory_pressure ? "yes" : "no" : "NI",
2170 proto->max_header, 2177 proto->max_header,
@@ -2218,7 +2225,8 @@ static const struct seq_operations proto_seq_ops = {
2218 2225
2219static int proto_seq_open(struct inode *inode, struct file *file) 2226static int proto_seq_open(struct inode *inode, struct file *file)
2220{ 2227{
2221 return seq_open(file, &proto_seq_ops); 2228 return seq_open_net(inode, file, &proto_seq_ops,
2229 sizeof(struct seq_net_private));
2222} 2230}
2223 2231
2224static const struct file_operations proto_seq_fops = { 2232static const struct file_operations proto_seq_fops = {
@@ -2226,13 +2234,31 @@ static const struct file_operations proto_seq_fops = {
2226 .open = proto_seq_open, 2234 .open = proto_seq_open,
2227 .read = seq_read, 2235 .read = seq_read,
2228 .llseek = seq_lseek, 2236 .llseek = seq_lseek,
2229 .release = seq_release, 2237 .release = seq_release_net,
2238};
2239
2240static __net_init int proto_init_net(struct net *net)
2241{
2242 if (!proc_net_fops_create(net, "protocols", S_IRUGO, &proto_seq_fops))
2243 return -ENOMEM;
2244
2245 return 0;
2246}
2247
2248static __net_exit void proto_exit_net(struct net *net)
2249{
2250 proc_net_remove(net, "protocols");
2251}
2252
2253
2254static __net_initdata struct pernet_operations proto_net_ops = {
2255 .init = proto_init_net,
2256 .exit = proto_exit_net,
2230}; 2257};
2231 2258
2232static int __init proto_init(void) 2259static int __init proto_init(void)
2233{ 2260{
2234 /* register /proc/net/protocols */ 2261 return register_pernet_subsys(&proto_net_ops);
2235 return proc_net_fops_create(&init_net, "protocols", S_IRUGO, &proto_seq_fops) == NULL ? -ENOBUFS : 0;
2236} 2262}
2237 2263
2238subsys_initcall(proto_init); 2264subsys_initcall(proto_init);
diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
index f686467ff12b..83d3398559ea 100644
--- a/net/core/sysctl_net_core.c
+++ b/net/core/sysctl_net_core.c
@@ -12,7 +12,6 @@
12#include <linux/netdevice.h> 12#include <linux/netdevice.h>
13#include <linux/init.h> 13#include <linux/init.h>
14#include <net/sock.h> 14#include <net/sock.h>
15#include <net/xfrm.h>
16 15
17static struct ctl_table net_core_table[] = { 16static struct ctl_table net_core_table[] = {
18#ifdef CONFIG_NET 17#ifdef CONFIG_NET
@@ -22,7 +21,7 @@ static struct ctl_table net_core_table[] = {
22 .data = &sysctl_wmem_max, 21 .data = &sysctl_wmem_max,
23 .maxlen = sizeof(int), 22 .maxlen = sizeof(int),
24 .mode = 0644, 23 .mode = 0644,
25 .proc_handler = &proc_dointvec 24 .proc_handler = proc_dointvec
26 }, 25 },
27 { 26 {
28 .ctl_name = NET_CORE_RMEM_MAX, 27 .ctl_name = NET_CORE_RMEM_MAX,
@@ -30,7 +29,7 @@ static struct ctl_table net_core_table[] = {
30 .data = &sysctl_rmem_max, 29 .data = &sysctl_rmem_max,
31 .maxlen = sizeof(int), 30 .maxlen = sizeof(int),
32 .mode = 0644, 31 .mode = 0644,
33 .proc_handler = &proc_dointvec 32 .proc_handler = proc_dointvec
34 }, 33 },
35 { 34 {
36 .ctl_name = NET_CORE_WMEM_DEFAULT, 35 .ctl_name = NET_CORE_WMEM_DEFAULT,
@@ -38,7 +37,7 @@ static struct ctl_table net_core_table[] = {
38 .data = &sysctl_wmem_default, 37 .data = &sysctl_wmem_default,
39 .maxlen = sizeof(int), 38 .maxlen = sizeof(int),
40 .mode = 0644, 39 .mode = 0644,
41 .proc_handler = &proc_dointvec 40 .proc_handler = proc_dointvec
42 }, 41 },
43 { 42 {
44 .ctl_name = NET_CORE_RMEM_DEFAULT, 43 .ctl_name = NET_CORE_RMEM_DEFAULT,
@@ -46,7 +45,7 @@ static struct ctl_table net_core_table[] = {
46 .data = &sysctl_rmem_default, 45 .data = &sysctl_rmem_default,
47 .maxlen = sizeof(int), 46 .maxlen = sizeof(int),
48 .mode = 0644, 47 .mode = 0644,
49 .proc_handler = &proc_dointvec 48 .proc_handler = proc_dointvec
50 }, 49 },
51 { 50 {
52 .ctl_name = NET_CORE_DEV_WEIGHT, 51 .ctl_name = NET_CORE_DEV_WEIGHT,
@@ -54,7 +53,7 @@ static struct ctl_table net_core_table[] = {
54 .data = &weight_p, 53 .data = &weight_p,
55 .maxlen = sizeof(int), 54 .maxlen = sizeof(int),
56 .mode = 0644, 55 .mode = 0644,
57 .proc_handler = &proc_dointvec 56 .proc_handler = proc_dointvec
58 }, 57 },
59 { 58 {
60 .ctl_name = NET_CORE_MAX_BACKLOG, 59 .ctl_name = NET_CORE_MAX_BACKLOG,
@@ -62,7 +61,7 @@ static struct ctl_table net_core_table[] = {
62 .data = &netdev_max_backlog, 61 .data = &netdev_max_backlog,
63 .maxlen = sizeof(int), 62 .maxlen = sizeof(int),
64 .mode = 0644, 63 .mode = 0644,
65 .proc_handler = &proc_dointvec 64 .proc_handler = proc_dointvec
66 }, 65 },
67 { 66 {
68 .ctl_name = NET_CORE_MSG_COST, 67 .ctl_name = NET_CORE_MSG_COST,
@@ -70,8 +69,8 @@ static struct ctl_table net_core_table[] = {
70 .data = &net_ratelimit_state.interval, 69 .data = &net_ratelimit_state.interval,
71 .maxlen = sizeof(int), 70 .maxlen = sizeof(int),
72 .mode = 0644, 71 .mode = 0644,
73 .proc_handler = &proc_dointvec_jiffies, 72 .proc_handler = proc_dointvec_jiffies,
74 .strategy = &sysctl_jiffies, 73 .strategy = sysctl_jiffies,
75 }, 74 },
76 { 75 {
77 .ctl_name = NET_CORE_MSG_BURST, 76 .ctl_name = NET_CORE_MSG_BURST,
@@ -79,7 +78,7 @@ static struct ctl_table net_core_table[] = {
79 .data = &net_ratelimit_state.burst, 78 .data = &net_ratelimit_state.burst,
80 .maxlen = sizeof(int), 79 .maxlen = sizeof(int),
81 .mode = 0644, 80 .mode = 0644,
82 .proc_handler = &proc_dointvec, 81 .proc_handler = proc_dointvec,
83 }, 82 },
84 { 83 {
85 .ctl_name = NET_CORE_OPTMEM_MAX, 84 .ctl_name = NET_CORE_OPTMEM_MAX,
@@ -87,42 +86,8 @@ static struct ctl_table net_core_table[] = {
87 .data = &sysctl_optmem_max, 86 .data = &sysctl_optmem_max,
88 .maxlen = sizeof(int), 87 .maxlen = sizeof(int),
89 .mode = 0644, 88 .mode = 0644,
90 .proc_handler = &proc_dointvec 89 .proc_handler = proc_dointvec
91 }, 90 },
92#ifdef CONFIG_XFRM
93 {
94 .ctl_name = NET_CORE_AEVENT_ETIME,
95 .procname = "xfrm_aevent_etime",
96 .data = &sysctl_xfrm_aevent_etime,
97 .maxlen = sizeof(u32),
98 .mode = 0644,
99 .proc_handler = &proc_dointvec
100 },
101 {
102 .ctl_name = NET_CORE_AEVENT_RSEQTH,
103 .procname = "xfrm_aevent_rseqth",
104 .data = &sysctl_xfrm_aevent_rseqth,
105 .maxlen = sizeof(u32),
106 .mode = 0644,
107 .proc_handler = &proc_dointvec
108 },
109 {
110 .ctl_name = CTL_UNNUMBERED,
111 .procname = "xfrm_larval_drop",
112 .data = &sysctl_xfrm_larval_drop,
113 .maxlen = sizeof(int),
114 .mode = 0644,
115 .proc_handler = &proc_dointvec
116 },
117 {
118 .ctl_name = CTL_UNNUMBERED,
119 .procname = "xfrm_acq_expires",
120 .data = &sysctl_xfrm_acq_expires,
121 .maxlen = sizeof(int),
122 .mode = 0644,
123 .proc_handler = &proc_dointvec
124 },
125#endif /* CONFIG_XFRM */
126#endif /* CONFIG_NET */ 91#endif /* CONFIG_NET */
127 { 92 {
128 .ctl_name = NET_CORE_BUDGET, 93 .ctl_name = NET_CORE_BUDGET,
@@ -130,7 +95,7 @@ static struct ctl_table net_core_table[] = {
130 .data = &netdev_budget, 95 .data = &netdev_budget,
131 .maxlen = sizeof(int), 96 .maxlen = sizeof(int),
132 .mode = 0644, 97 .mode = 0644,
133 .proc_handler = &proc_dointvec 98 .proc_handler = proc_dointvec
134 }, 99 },
135 { 100 {
136 .ctl_name = NET_CORE_WARNINGS, 101 .ctl_name = NET_CORE_WARNINGS,
@@ -138,7 +103,7 @@ static struct ctl_table net_core_table[] = {
138 .data = &net_msg_warn, 103 .data = &net_msg_warn,
139 .maxlen = sizeof(int), 104 .maxlen = sizeof(int),
140 .mode = 0644, 105 .mode = 0644,
141 .proc_handler = &proc_dointvec 106 .proc_handler = proc_dointvec
142 }, 107 },
143 { .ctl_name = 0 } 108 { .ctl_name = 0 }
144}; 109};
@@ -150,12 +115,12 @@ static struct ctl_table netns_core_table[] = {
150 .data = &init_net.core.sysctl_somaxconn, 115 .data = &init_net.core.sysctl_somaxconn,
151 .maxlen = sizeof(int), 116 .maxlen = sizeof(int),
152 .mode = 0644, 117 .mode = 0644,
153 .proc_handler = &proc_dointvec 118 .proc_handler = proc_dointvec
154 }, 119 },
155 { .ctl_name = 0 } 120 { .ctl_name = 0 }
156}; 121};
157 122
158static __net_initdata struct ctl_path net_core_path[] = { 123__net_initdata struct ctl_path net_core_path[] = {
159 { .procname = "net", .ctl_name = CTL_NET, }, 124 { .procname = "net", .ctl_name = CTL_NET, },
160 { .procname = "core", .ctl_name = NET_CORE, }, 125 { .procname = "core", .ctl_name = NET_CORE, },
161 { }, 126 { },
@@ -207,8 +172,11 @@ static __net_initdata struct pernet_operations sysctl_core_ops = {
207 172
208static __init int sysctl_core_init(void) 173static __init int sysctl_core_init(void)
209{ 174{
175 static struct ctl_table empty[1];
176
177 register_sysctl_paths(net_core_path, empty);
210 register_net_sysctl_rotable(net_core_path, net_core_table); 178 register_net_sysctl_rotable(net_core_path, net_core_table);
211 return register_pernet_subsys(&sysctl_core_ops); 179 return register_pernet_subsys(&sysctl_core_ops);
212} 180}
213 181
214__initcall(sysctl_core_init); 182fs_initcall(sysctl_core_init);
diff --git a/net/dcb/Kconfig b/net/dcb/Kconfig
new file mode 100644
index 000000000000..4066d59c8de5
--- /dev/null
+++ b/net/dcb/Kconfig
@@ -0,0 +1,22 @@
1config DCB
2 bool "Data Center Bridging support"
3 default n
4 ---help---
5 This enables support for configuring Data Center Bridging (DCB)
6 features on DCB capable Ethernet adapters via rtnetlink. Say 'Y'
7 if you have a DCB capable Ethernet adapter which supports this
8 interface and you are connected to a DCB capable switch.
9
10 DCB is a collection of Ethernet enhancements which allow DCB capable
11 NICs and switches to support network traffic with differing
12 requirements (highly reliable, no drops vs. best effort vs. low
13 latency) to co-exist on Ethernet.
14
15 DCB features include:
16 Enhanced Transmission Selection (aka Priority Grouping) - provides a
17 framework for assigning bandwidth guarantees to traffic classes.
18 Priority-based Flow Control (PFC) - a MAC control pause frame which
19 works at the granularity of the 802.1p priority instead of the
20 link (802.3x).
21
22 If unsure, say N.
diff --git a/net/dcb/Makefile b/net/dcb/Makefile
new file mode 100644
index 000000000000..9930f4cde818
--- /dev/null
+++ b/net/dcb/Makefile
@@ -0,0 +1 @@
obj-$(CONFIG_DCB) += dcbnl.o
diff --git a/net/dcb/dcbnl.c b/net/dcb/dcbnl.c
new file mode 100644
index 000000000000..5dbfe5fdc0d6
--- /dev/null
+++ b/net/dcb/dcbnl.c
@@ -0,0 +1,1122 @@
1/*
2 * Copyright (c) 2008, Intel Corporation.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License,
6 * version 2, as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 * more details.
12 *
13 * You should have received a copy of the GNU General Public License along with
14 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
15 * Place - Suite 330, Boston, MA 02111-1307 USA.
16 *
17 * Author: Lucy Liu <lucy.liu@intel.com>
18 */
19
20#include <linux/netdevice.h>
21#include <linux/netlink.h>
22#include <net/netlink.h>
23#include <net/rtnetlink.h>
24#include <linux/dcbnl.h>
25#include <linux/rtnetlink.h>
26#include <net/sock.h>
27
28/**
29 * Data Center Bridging (DCB) is a collection of Ethernet enhancements
30 * intended to allow network traffic with differing requirements
31 * (highly reliable, no drops vs. best effort vs. low latency) to operate
32 * and co-exist on Ethernet. Current DCB features are:
33 *
34 * Enhanced Transmission Selection (aka Priority Grouping [PG]) - provides a
35 * framework for assigning bandwidth guarantees to traffic classes.
36 *
37 * Priority-based Flow Control (PFC) - provides a flow control mechanism which
38 * can work independently for each 802.1p priority.
39 *
40 * Congestion Notification - provides a mechanism for end-to-end congestion
41 * control for protocols which do not have built-in congestion management.
42 *
43 * More information about the emerging standards for these Ethernet features
44 * can be found at: http://www.ieee802.org/1/pages/dcbridges.html
45 *
46 * This file implements an rtnetlink interface to allow configuration of DCB
47 * features for capable devices.
48 */
49
50MODULE_AUTHOR("Lucy Liu, <lucy.liu@intel.com>");
51MODULE_DESCRIPTION("Data Center Bridging netlink interface");
52MODULE_LICENSE("GPL");
53
54/**************** DCB attribute policies *************************************/
55
56/* DCB netlink attributes policy */
57static struct nla_policy dcbnl_rtnl_policy[DCB_ATTR_MAX + 1] = {
58 [DCB_ATTR_IFNAME] = {.type = NLA_NUL_STRING, .len = IFNAMSIZ - 1},
59 [DCB_ATTR_STATE] = {.type = NLA_U8},
60 [DCB_ATTR_PFC_CFG] = {.type = NLA_NESTED},
61 [DCB_ATTR_PG_CFG] = {.type = NLA_NESTED},
62 [DCB_ATTR_SET_ALL] = {.type = NLA_U8},
63 [DCB_ATTR_PERM_HWADDR] = {.type = NLA_FLAG},
64 [DCB_ATTR_CAP] = {.type = NLA_NESTED},
65 [DCB_ATTR_PFC_STATE] = {.type = NLA_U8},
66 [DCB_ATTR_BCN] = {.type = NLA_NESTED},
67};
68
69/* DCB priority flow control to User Priority nested attributes */
70static struct nla_policy dcbnl_pfc_up_nest[DCB_PFC_UP_ATTR_MAX + 1] = {
71 [DCB_PFC_UP_ATTR_0] = {.type = NLA_U8},
72 [DCB_PFC_UP_ATTR_1] = {.type = NLA_U8},
73 [DCB_PFC_UP_ATTR_2] = {.type = NLA_U8},
74 [DCB_PFC_UP_ATTR_3] = {.type = NLA_U8},
75 [DCB_PFC_UP_ATTR_4] = {.type = NLA_U8},
76 [DCB_PFC_UP_ATTR_5] = {.type = NLA_U8},
77 [DCB_PFC_UP_ATTR_6] = {.type = NLA_U8},
78 [DCB_PFC_UP_ATTR_7] = {.type = NLA_U8},
79 [DCB_PFC_UP_ATTR_ALL] = {.type = NLA_FLAG},
80};
81
82/* DCB priority grouping nested attributes */
83static struct nla_policy dcbnl_pg_nest[DCB_PG_ATTR_MAX + 1] = {
84 [DCB_PG_ATTR_TC_0] = {.type = NLA_NESTED},
85 [DCB_PG_ATTR_TC_1] = {.type = NLA_NESTED},
86 [DCB_PG_ATTR_TC_2] = {.type = NLA_NESTED},
87 [DCB_PG_ATTR_TC_3] = {.type = NLA_NESTED},
88 [DCB_PG_ATTR_TC_4] = {.type = NLA_NESTED},
89 [DCB_PG_ATTR_TC_5] = {.type = NLA_NESTED},
90 [DCB_PG_ATTR_TC_6] = {.type = NLA_NESTED},
91 [DCB_PG_ATTR_TC_7] = {.type = NLA_NESTED},
92 [DCB_PG_ATTR_TC_ALL] = {.type = NLA_NESTED},
93 [DCB_PG_ATTR_BW_ID_0] = {.type = NLA_U8},
94 [DCB_PG_ATTR_BW_ID_1] = {.type = NLA_U8},
95 [DCB_PG_ATTR_BW_ID_2] = {.type = NLA_U8},
96 [DCB_PG_ATTR_BW_ID_3] = {.type = NLA_U8},
97 [DCB_PG_ATTR_BW_ID_4] = {.type = NLA_U8},
98 [DCB_PG_ATTR_BW_ID_5] = {.type = NLA_U8},
99 [DCB_PG_ATTR_BW_ID_6] = {.type = NLA_U8},
100 [DCB_PG_ATTR_BW_ID_7] = {.type = NLA_U8},
101 [DCB_PG_ATTR_BW_ID_ALL] = {.type = NLA_FLAG},
102};
103
104/* DCB traffic class nested attributes. */
105static struct nla_policy dcbnl_tc_param_nest[DCB_TC_ATTR_PARAM_MAX + 1] = {
106 [DCB_TC_ATTR_PARAM_PGID] = {.type = NLA_U8},
107 [DCB_TC_ATTR_PARAM_UP_MAPPING] = {.type = NLA_U8},
108 [DCB_TC_ATTR_PARAM_STRICT_PRIO] = {.type = NLA_U8},
109 [DCB_TC_ATTR_PARAM_BW_PCT] = {.type = NLA_U8},
110 [DCB_TC_ATTR_PARAM_ALL] = {.type = NLA_FLAG},
111};
112
113/* DCB capabilities nested attributes. */
114static struct nla_policy dcbnl_cap_nest[DCB_CAP_ATTR_MAX + 1] = {
115 [DCB_CAP_ATTR_ALL] = {.type = NLA_FLAG},
116 [DCB_CAP_ATTR_PG] = {.type = NLA_U8},
117 [DCB_CAP_ATTR_PFC] = {.type = NLA_U8},
118 [DCB_CAP_ATTR_UP2TC] = {.type = NLA_U8},
119 [DCB_CAP_ATTR_PG_TCS] = {.type = NLA_U8},
120 [DCB_CAP_ATTR_PFC_TCS] = {.type = NLA_U8},
121 [DCB_CAP_ATTR_GSP] = {.type = NLA_U8},
122 [DCB_CAP_ATTR_BCN] = {.type = NLA_U8},
123};
124
125/* DCB capabilities nested attributes. */
126static struct nla_policy dcbnl_numtcs_nest[DCB_NUMTCS_ATTR_MAX + 1] = {
127 [DCB_NUMTCS_ATTR_ALL] = {.type = NLA_FLAG},
128 [DCB_NUMTCS_ATTR_PG] = {.type = NLA_U8},
129 [DCB_NUMTCS_ATTR_PFC] = {.type = NLA_U8},
130};
131
132/* DCB BCN nested attributes. */
133static struct nla_policy dcbnl_bcn_nest[DCB_BCN_ATTR_MAX + 1] = {
134 [DCB_BCN_ATTR_RP_0] = {.type = NLA_U8},
135 [DCB_BCN_ATTR_RP_1] = {.type = NLA_U8},
136 [DCB_BCN_ATTR_RP_2] = {.type = NLA_U8},
137 [DCB_BCN_ATTR_RP_3] = {.type = NLA_U8},
138 [DCB_BCN_ATTR_RP_4] = {.type = NLA_U8},
139 [DCB_BCN_ATTR_RP_5] = {.type = NLA_U8},
140 [DCB_BCN_ATTR_RP_6] = {.type = NLA_U8},
141 [DCB_BCN_ATTR_RP_7] = {.type = NLA_U8},
142 [DCB_BCN_ATTR_RP_ALL] = {.type = NLA_FLAG},
143 [DCB_BCN_ATTR_BCNA_0] = {.type = NLA_U32},
144 [DCB_BCN_ATTR_BCNA_1] = {.type = NLA_U32},
145 [DCB_BCN_ATTR_ALPHA] = {.type = NLA_U32},
146 [DCB_BCN_ATTR_BETA] = {.type = NLA_U32},
147 [DCB_BCN_ATTR_GD] = {.type = NLA_U32},
148 [DCB_BCN_ATTR_GI] = {.type = NLA_U32},
149 [DCB_BCN_ATTR_TMAX] = {.type = NLA_U32},
150 [DCB_BCN_ATTR_TD] = {.type = NLA_U32},
151 [DCB_BCN_ATTR_RMIN] = {.type = NLA_U32},
152 [DCB_BCN_ATTR_W] = {.type = NLA_U32},
153 [DCB_BCN_ATTR_RD] = {.type = NLA_U32},
154 [DCB_BCN_ATTR_RU] = {.type = NLA_U32},
155 [DCB_BCN_ATTR_WRTT] = {.type = NLA_U32},
156 [DCB_BCN_ATTR_RI] = {.type = NLA_U32},
157 [DCB_BCN_ATTR_C] = {.type = NLA_U32},
158 [DCB_BCN_ATTR_ALL] = {.type = NLA_FLAG},
159};
160
161/* standard netlink reply call */
162static int dcbnl_reply(u8 value, u8 event, u8 cmd, u8 attr, u32 pid,
163 u32 seq, u16 flags)
164{
165 struct sk_buff *dcbnl_skb;
166 struct dcbmsg *dcb;
167 struct nlmsghdr *nlh;
168 int ret = -EINVAL;
169
170 dcbnl_skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
171 if (!dcbnl_skb)
172 return ret;
173
174 nlh = NLMSG_NEW(dcbnl_skb, pid, seq, event, sizeof(*dcb), flags);
175
176 dcb = NLMSG_DATA(nlh);
177 dcb->dcb_family = AF_UNSPEC;
178 dcb->cmd = cmd;
179 dcb->dcb_pad = 0;
180
181 ret = nla_put_u8(dcbnl_skb, attr, value);
182 if (ret)
183 goto err;
184
185 /* end the message, assign the nlmsg_len. */
186 nlmsg_end(dcbnl_skb, nlh);
187 ret = rtnl_unicast(dcbnl_skb, &init_net, pid);
188 if (ret)
189 goto err;
190
191 return 0;
192nlmsg_failure:
193err:
194 kfree(dcbnl_skb);
195 return ret;
196}
197
198static int dcbnl_getstate(struct net_device *netdev, struct nlattr **tb,
199 u32 pid, u32 seq, u16 flags)
200{
201 int ret = -EINVAL;
202
203 /* if (!tb[DCB_ATTR_STATE] || !netdev->dcbnl_ops->getstate) */
204 if (!netdev->dcbnl_ops->getstate)
205 return ret;
206
207 ret = dcbnl_reply(netdev->dcbnl_ops->getstate(netdev), RTM_GETDCB,
208 DCB_CMD_GSTATE, DCB_ATTR_STATE, pid, seq, flags);
209
210 return ret;
211}
212
213static int dcbnl_getpfccfg(struct net_device *netdev, struct nlattr **tb,
214 u32 pid, u32 seq, u16 flags)
215{
216 struct sk_buff *dcbnl_skb;
217 struct nlmsghdr *nlh;
218 struct dcbmsg *dcb;
219 struct nlattr *data[DCB_PFC_UP_ATTR_MAX + 1], *nest;
220 u8 value;
221 int ret = -EINVAL;
222 int i;
223 int getall = 0;
224
225 if (!tb[DCB_ATTR_PFC_CFG] || !netdev->dcbnl_ops->getpfccfg)
226 return ret;
227
228 ret = nla_parse_nested(data, DCB_PFC_UP_ATTR_MAX,
229 tb[DCB_ATTR_PFC_CFG],
230 dcbnl_pfc_up_nest);
231 if (ret)
232 goto err_out;
233
234 dcbnl_skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
235 if (!dcbnl_skb)
236 goto err_out;
237
238 nlh = NLMSG_NEW(dcbnl_skb, pid, seq, RTM_GETDCB, sizeof(*dcb), flags);
239
240 dcb = NLMSG_DATA(nlh);
241 dcb->dcb_family = AF_UNSPEC;
242 dcb->cmd = DCB_CMD_PFC_GCFG;
243
244 nest = nla_nest_start(dcbnl_skb, DCB_ATTR_PFC_CFG);
245 if (!nest)
246 goto err;
247
248 if (data[DCB_PFC_UP_ATTR_ALL])
249 getall = 1;
250
251 for (i = DCB_PFC_UP_ATTR_0; i <= DCB_PFC_UP_ATTR_7; i++) {
252 if (!getall && !data[i])
253 continue;
254
255 netdev->dcbnl_ops->getpfccfg(netdev, i - DCB_PFC_UP_ATTR_0,
256 &value);
257 ret = nla_put_u8(dcbnl_skb, i, value);
258
259 if (ret) {
260 nla_nest_cancel(dcbnl_skb, nest);
261 goto err;
262 }
263 }
264 nla_nest_end(dcbnl_skb, nest);
265
266 nlmsg_end(dcbnl_skb, nlh);
267
268 ret = rtnl_unicast(dcbnl_skb, &init_net, pid);
269 if (ret)
270 goto err;
271
272 return 0;
273nlmsg_failure:
274err:
275 kfree(dcbnl_skb);
276err_out:
277 return -EINVAL;
278}
279
280static int dcbnl_getperm_hwaddr(struct net_device *netdev, struct nlattr **tb,
281 u32 pid, u32 seq, u16 flags)
282{
283 struct sk_buff *dcbnl_skb;
284 struct nlmsghdr *nlh;
285 struct dcbmsg *dcb;
286 u8 perm_addr[MAX_ADDR_LEN];
287 int ret = -EINVAL;
288
289 if (!netdev->dcbnl_ops->getpermhwaddr)
290 return ret;
291
292 dcbnl_skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
293 if (!dcbnl_skb)
294 goto err_out;
295
296 nlh = NLMSG_NEW(dcbnl_skb, pid, seq, RTM_GETDCB, sizeof(*dcb), flags);
297
298 dcb = NLMSG_DATA(nlh);
299 dcb->dcb_family = AF_UNSPEC;
300 dcb->cmd = DCB_CMD_GPERM_HWADDR;
301
302 netdev->dcbnl_ops->getpermhwaddr(netdev, perm_addr);
303
304 ret = nla_put(dcbnl_skb, DCB_ATTR_PERM_HWADDR, sizeof(perm_addr),
305 perm_addr);
306
307 nlmsg_end(dcbnl_skb, nlh);
308
309 ret = rtnl_unicast(dcbnl_skb, &init_net, pid);
310 if (ret)
311 goto err;
312
313 return 0;
314
315nlmsg_failure:
316err:
317 kfree(dcbnl_skb);
318err_out:
319 return -EINVAL;
320}
321
322static int dcbnl_getcap(struct net_device *netdev, struct nlattr **tb,
323 u32 pid, u32 seq, u16 flags)
324{
325 struct sk_buff *dcbnl_skb;
326 struct nlmsghdr *nlh;
327 struct dcbmsg *dcb;
328 struct nlattr *data[DCB_CAP_ATTR_MAX + 1], *nest;
329 u8 value;
330 int ret = -EINVAL;
331 int i;
332 int getall = 0;
333
334 if (!tb[DCB_ATTR_CAP] || !netdev->dcbnl_ops->getcap)
335 return ret;
336
337 ret = nla_parse_nested(data, DCB_CAP_ATTR_MAX, tb[DCB_ATTR_CAP],
338 dcbnl_cap_nest);
339 if (ret)
340 goto err_out;
341
342 dcbnl_skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
343 if (!dcbnl_skb)
344 goto err_out;
345
346 nlh = NLMSG_NEW(dcbnl_skb, pid, seq, RTM_GETDCB, sizeof(*dcb), flags);
347
348 dcb = NLMSG_DATA(nlh);
349 dcb->dcb_family = AF_UNSPEC;
350 dcb->cmd = DCB_CMD_GCAP;
351
352 nest = nla_nest_start(dcbnl_skb, DCB_ATTR_CAP);
353 if (!nest)
354 goto err;
355
356 if (data[DCB_CAP_ATTR_ALL])
357 getall = 1;
358
359 for (i = DCB_CAP_ATTR_ALL+1; i <= DCB_CAP_ATTR_MAX; i++) {
360 if (!getall && !data[i])
361 continue;
362
363 if (!netdev->dcbnl_ops->getcap(netdev, i, &value)) {
364 ret = nla_put_u8(dcbnl_skb, i, value);
365
366 if (ret) {
367 nla_nest_cancel(dcbnl_skb, nest);
368 goto err;
369 }
370 }
371 }
372 nla_nest_end(dcbnl_skb, nest);
373
374 nlmsg_end(dcbnl_skb, nlh);
375
376 ret = rtnl_unicast(dcbnl_skb, &init_net, pid);
377 if (ret)
378 goto err;
379
380 return 0;
381nlmsg_failure:
382err:
383 kfree(dcbnl_skb);
384err_out:
385 return -EINVAL;
386}
387
388static int dcbnl_getnumtcs(struct net_device *netdev, struct nlattr **tb,
389 u32 pid, u32 seq, u16 flags)
390{
391 struct sk_buff *dcbnl_skb;
392 struct nlmsghdr *nlh;
393 struct dcbmsg *dcb;
394 struct nlattr *data[DCB_NUMTCS_ATTR_MAX + 1], *nest;
395 u8 value;
396 int ret = -EINVAL;
397 int i;
398 int getall = 0;
399
400 if (!tb[DCB_ATTR_NUMTCS] || !netdev->dcbnl_ops->getnumtcs)
401 return ret;
402
403 ret = nla_parse_nested(data, DCB_NUMTCS_ATTR_MAX, tb[DCB_ATTR_NUMTCS],
404 dcbnl_numtcs_nest);
405 if (ret) {
406 ret = -EINVAL;
407 goto err_out;
408 }
409
410 dcbnl_skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
411 if (!dcbnl_skb) {
412 ret = -EINVAL;
413 goto err_out;
414 }
415
416 nlh = NLMSG_NEW(dcbnl_skb, pid, seq, RTM_GETDCB, sizeof(*dcb), flags);
417
418 dcb = NLMSG_DATA(nlh);
419 dcb->dcb_family = AF_UNSPEC;
420 dcb->cmd = DCB_CMD_GNUMTCS;
421
422 nest = nla_nest_start(dcbnl_skb, DCB_ATTR_NUMTCS);
423 if (!nest) {
424 ret = -EINVAL;
425 goto err;
426 }
427
428 if (data[DCB_NUMTCS_ATTR_ALL])
429 getall = 1;
430
431 for (i = DCB_NUMTCS_ATTR_ALL+1; i <= DCB_NUMTCS_ATTR_MAX; i++) {
432 if (!getall && !data[i])
433 continue;
434
435 ret = netdev->dcbnl_ops->getnumtcs(netdev, i, &value);
436 if (!ret) {
437 ret = nla_put_u8(dcbnl_skb, i, value);
438
439 if (ret) {
440 nla_nest_cancel(dcbnl_skb, nest);
441 ret = -EINVAL;
442 goto err;
443 }
444 } else {
445 goto err;
446 }
447 }
448 nla_nest_end(dcbnl_skb, nest);
449
450 nlmsg_end(dcbnl_skb, nlh);
451
452 ret = rtnl_unicast(dcbnl_skb, &init_net, pid);
453 if (ret) {
454 ret = -EINVAL;
455 goto err;
456 }
457
458 return 0;
459nlmsg_failure:
460err:
461 kfree(dcbnl_skb);
462err_out:
463 return ret;
464}
465
466static int dcbnl_setnumtcs(struct net_device *netdev, struct nlattr **tb,
467 u32 pid, u32 seq, u16 flags)
468{
469 struct nlattr *data[DCB_NUMTCS_ATTR_MAX + 1];
470 int ret = -EINVAL;
471 u8 value;
472 int i;
473
474 if (!tb[DCB_ATTR_NUMTCS] || !netdev->dcbnl_ops->setnumtcs)
475 return ret;
476
477 ret = nla_parse_nested(data, DCB_NUMTCS_ATTR_MAX, tb[DCB_ATTR_NUMTCS],
478 dcbnl_numtcs_nest);
479
480 if (ret) {
481 ret = -EINVAL;
482 goto err;
483 }
484
485 for (i = DCB_NUMTCS_ATTR_ALL+1; i <= DCB_NUMTCS_ATTR_MAX; i++) {
486 if (data[i] == NULL)
487 continue;
488
489 value = nla_get_u8(data[i]);
490
491 ret = netdev->dcbnl_ops->setnumtcs(netdev, i, value);
492
493 if (ret)
494 goto operr;
495 }
496
497operr:
498 ret = dcbnl_reply(!!ret, RTM_SETDCB, DCB_CMD_SNUMTCS,
499 DCB_ATTR_NUMTCS, pid, seq, flags);
500
501err:
502 return ret;
503}
504
505static int dcbnl_getpfcstate(struct net_device *netdev, struct nlattr **tb,
506 u32 pid, u32 seq, u16 flags)
507{
508 int ret = -EINVAL;
509
510 if (!netdev->dcbnl_ops->getpfcstate)
511 return ret;
512
513 ret = dcbnl_reply(netdev->dcbnl_ops->getpfcstate(netdev), RTM_GETDCB,
514 DCB_CMD_PFC_GSTATE, DCB_ATTR_PFC_STATE,
515 pid, seq, flags);
516
517 return ret;
518}
519
520static int dcbnl_setpfcstate(struct net_device *netdev, struct nlattr **tb,
521 u32 pid, u32 seq, u16 flags)
522{
523 int ret = -EINVAL;
524 u8 value;
525
526 if (!tb[DCB_ATTR_PFC_STATE] || !netdev->dcbnl_ops->setpfcstate)
527 return ret;
528
529 value = nla_get_u8(tb[DCB_ATTR_PFC_STATE]);
530
531 netdev->dcbnl_ops->setpfcstate(netdev, value);
532
533 ret = dcbnl_reply(0, RTM_SETDCB, DCB_CMD_PFC_SSTATE, DCB_ATTR_PFC_STATE,
534 pid, seq, flags);
535
536 return ret;
537}
538
539static int __dcbnl_pg_getcfg(struct net_device *netdev, struct nlattr **tb,
540 u32 pid, u32 seq, u16 flags, int dir)
541{
542 struct sk_buff *dcbnl_skb;
543 struct nlmsghdr *nlh;
544 struct dcbmsg *dcb;
545 struct nlattr *pg_nest, *param_nest, *data;
546 struct nlattr *pg_tb[DCB_PG_ATTR_MAX + 1];
547 struct nlattr *param_tb[DCB_TC_ATTR_PARAM_MAX + 1];
548 u8 prio, pgid, tc_pct, up_map;
549 int ret = -EINVAL;
550 int getall = 0;
551 int i;
552
553 if (!tb[DCB_ATTR_PG_CFG] ||
554 !netdev->dcbnl_ops->getpgtccfgtx ||
555 !netdev->dcbnl_ops->getpgtccfgrx ||
556 !netdev->dcbnl_ops->getpgbwgcfgtx ||
557 !netdev->dcbnl_ops->getpgbwgcfgrx)
558 return ret;
559
560 ret = nla_parse_nested(pg_tb, DCB_PG_ATTR_MAX,
561 tb[DCB_ATTR_PG_CFG], dcbnl_pg_nest);
562
563 if (ret)
564 goto err_out;
565
566 dcbnl_skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
567 if (!dcbnl_skb)
568 goto err_out;
569
570 nlh = NLMSG_NEW(dcbnl_skb, pid, seq, RTM_GETDCB, sizeof(*dcb), flags);
571
572 dcb = NLMSG_DATA(nlh);
573 dcb->dcb_family = AF_UNSPEC;
574 dcb->cmd = (dir) ? DCB_CMD_PGRX_GCFG : DCB_CMD_PGTX_GCFG;
575
576 pg_nest = nla_nest_start(dcbnl_skb, DCB_ATTR_PG_CFG);
577 if (!pg_nest)
578 goto err;
579
580 if (pg_tb[DCB_PG_ATTR_TC_ALL])
581 getall = 1;
582
583 for (i = DCB_PG_ATTR_TC_0; i <= DCB_PG_ATTR_TC_7; i++) {
584 if (!getall && !pg_tb[i])
585 continue;
586
587 if (pg_tb[DCB_PG_ATTR_TC_ALL])
588 data = pg_tb[DCB_PG_ATTR_TC_ALL];
589 else
590 data = pg_tb[i];
591 ret = nla_parse_nested(param_tb, DCB_TC_ATTR_PARAM_MAX,
592 data, dcbnl_tc_param_nest);
593 if (ret)
594 goto err_pg;
595
596 param_nest = nla_nest_start(dcbnl_skb, i);
597 if (!param_nest)
598 goto err_pg;
599
600 pgid = DCB_ATTR_VALUE_UNDEFINED;
601 prio = DCB_ATTR_VALUE_UNDEFINED;
602 tc_pct = DCB_ATTR_VALUE_UNDEFINED;
603 up_map = DCB_ATTR_VALUE_UNDEFINED;
604
605 if (dir) {
606 /* Rx */
607 netdev->dcbnl_ops->getpgtccfgrx(netdev,
608 i - DCB_PG_ATTR_TC_0, &prio,
609 &pgid, &tc_pct, &up_map);
610 } else {
611 /* Tx */
612 netdev->dcbnl_ops->getpgtccfgtx(netdev,
613 i - DCB_PG_ATTR_TC_0, &prio,
614 &pgid, &tc_pct, &up_map);
615 }
616
617 if (param_tb[DCB_TC_ATTR_PARAM_PGID] ||
618 param_tb[DCB_TC_ATTR_PARAM_ALL]) {
619 ret = nla_put_u8(dcbnl_skb,
620 DCB_TC_ATTR_PARAM_PGID, pgid);
621 if (ret)
622 goto err_param;
623 }
624 if (param_tb[DCB_TC_ATTR_PARAM_UP_MAPPING] ||
625 param_tb[DCB_TC_ATTR_PARAM_ALL]) {
626 ret = nla_put_u8(dcbnl_skb,
627 DCB_TC_ATTR_PARAM_UP_MAPPING, up_map);
628 if (ret)
629 goto err_param;
630 }
631 if (param_tb[DCB_TC_ATTR_PARAM_STRICT_PRIO] ||
632 param_tb[DCB_TC_ATTR_PARAM_ALL]) {
633 ret = nla_put_u8(dcbnl_skb,
634 DCB_TC_ATTR_PARAM_STRICT_PRIO, prio);
635 if (ret)
636 goto err_param;
637 }
638 if (param_tb[DCB_TC_ATTR_PARAM_BW_PCT] ||
639 param_tb[DCB_TC_ATTR_PARAM_ALL]) {
640 ret = nla_put_u8(dcbnl_skb, DCB_TC_ATTR_PARAM_BW_PCT,
641 tc_pct);
642 if (ret)
643 goto err_param;
644 }
645 nla_nest_end(dcbnl_skb, param_nest);
646 }
647
648 if (pg_tb[DCB_PG_ATTR_BW_ID_ALL])
649 getall = 1;
650 else
651 getall = 0;
652
653 for (i = DCB_PG_ATTR_BW_ID_0; i <= DCB_PG_ATTR_BW_ID_7; i++) {
654 if (!getall && !pg_tb[i])
655 continue;
656
657 tc_pct = DCB_ATTR_VALUE_UNDEFINED;
658
659 if (dir) {
660 /* Rx */
661 netdev->dcbnl_ops->getpgbwgcfgrx(netdev,
662 i - DCB_PG_ATTR_BW_ID_0, &tc_pct);
663 } else {
664 /* Tx */
665 netdev->dcbnl_ops->getpgbwgcfgtx(netdev,
666 i - DCB_PG_ATTR_BW_ID_0, &tc_pct);
667 }
668 ret = nla_put_u8(dcbnl_skb, i, tc_pct);
669
670 if (ret)
671 goto err_pg;
672 }
673
674 nla_nest_end(dcbnl_skb, pg_nest);
675
676 nlmsg_end(dcbnl_skb, nlh);
677
678 ret = rtnl_unicast(dcbnl_skb, &init_net, pid);
679 if (ret)
680 goto err;
681
682 return 0;
683
684err_param:
685 nla_nest_cancel(dcbnl_skb, param_nest);
686err_pg:
687 nla_nest_cancel(dcbnl_skb, pg_nest);
688nlmsg_failure:
689err:
690 kfree(dcbnl_skb);
691err_out:
692 ret = -EINVAL;
693 return ret;
694}
695
696static int dcbnl_pgtx_getcfg(struct net_device *netdev, struct nlattr **tb,
697 u32 pid, u32 seq, u16 flags)
698{
699 return __dcbnl_pg_getcfg(netdev, tb, pid, seq, flags, 0);
700}
701
702static int dcbnl_pgrx_getcfg(struct net_device *netdev, struct nlattr **tb,
703 u32 pid, u32 seq, u16 flags)
704{
705 return __dcbnl_pg_getcfg(netdev, tb, pid, seq, flags, 1);
706}
707
708static int dcbnl_setstate(struct net_device *netdev, struct nlattr **tb,
709 u32 pid, u32 seq, u16 flags)
710{
711 int ret = -EINVAL;
712 u8 value;
713
714 if (!tb[DCB_ATTR_STATE] || !netdev->dcbnl_ops->setstate)
715 return ret;
716
717 value = nla_get_u8(tb[DCB_ATTR_STATE]);
718
719 ret = dcbnl_reply(netdev->dcbnl_ops->setstate(netdev, value),
720 RTM_SETDCB, DCB_CMD_SSTATE, DCB_ATTR_STATE,
721 pid, seq, flags);
722
723 return ret;
724}
725
726static int dcbnl_setpfccfg(struct net_device *netdev, struct nlattr **tb,
727 u32 pid, u32 seq, u16 flags)
728{
729 struct nlattr *data[DCB_PFC_UP_ATTR_MAX + 1];
730 int i;
731 int ret = -EINVAL;
732 u8 value;
733
734 if (!tb[DCB_ATTR_PFC_CFG] || !netdev->dcbnl_ops->setpfccfg)
735 return ret;
736
737 ret = nla_parse_nested(data, DCB_PFC_UP_ATTR_MAX,
738 tb[DCB_ATTR_PFC_CFG],
739 dcbnl_pfc_up_nest);
740 if (ret)
741 goto err;
742
743 for (i = DCB_PFC_UP_ATTR_0; i <= DCB_PFC_UP_ATTR_7; i++) {
744 if (data[i] == NULL)
745 continue;
746 value = nla_get_u8(data[i]);
747 netdev->dcbnl_ops->setpfccfg(netdev,
748 data[i]->nla_type - DCB_PFC_UP_ATTR_0, value);
749 }
750
751 ret = dcbnl_reply(0, RTM_SETDCB, DCB_CMD_PFC_SCFG, DCB_ATTR_PFC_CFG,
752 pid, seq, flags);
753err:
754 return ret;
755}
756
757static int dcbnl_setall(struct net_device *netdev, struct nlattr **tb,
758 u32 pid, u32 seq, u16 flags)
759{
760 int ret = -EINVAL;
761
762 if (!tb[DCB_ATTR_SET_ALL] || !netdev->dcbnl_ops->setall)
763 return ret;
764
765 ret = dcbnl_reply(netdev->dcbnl_ops->setall(netdev), RTM_SETDCB,
766 DCB_CMD_SET_ALL, DCB_ATTR_SET_ALL, pid, seq, flags);
767
768 return ret;
769}
770
771static int __dcbnl_pg_setcfg(struct net_device *netdev, struct nlattr **tb,
772 u32 pid, u32 seq, u16 flags, int dir)
773{
774 struct nlattr *pg_tb[DCB_PG_ATTR_MAX + 1];
775 struct nlattr *param_tb[DCB_TC_ATTR_PARAM_MAX + 1];
776 int ret = -EINVAL;
777 int i;
778 u8 pgid;
779 u8 up_map;
780 u8 prio;
781 u8 tc_pct;
782
783 if (!tb[DCB_ATTR_PG_CFG] ||
784 !netdev->dcbnl_ops->setpgtccfgtx ||
785 !netdev->dcbnl_ops->setpgtccfgrx ||
786 !netdev->dcbnl_ops->setpgbwgcfgtx ||
787 !netdev->dcbnl_ops->setpgbwgcfgrx)
788 return ret;
789
790 ret = nla_parse_nested(pg_tb, DCB_PG_ATTR_MAX,
791 tb[DCB_ATTR_PG_CFG], dcbnl_pg_nest);
792 if (ret)
793 goto err;
794
795 for (i = DCB_PG_ATTR_TC_0; i <= DCB_PG_ATTR_TC_7; i++) {
796 if (!pg_tb[i])
797 continue;
798
799 ret = nla_parse_nested(param_tb, DCB_TC_ATTR_PARAM_MAX,
800 pg_tb[i], dcbnl_tc_param_nest);
801 if (ret)
802 goto err;
803
804 pgid = DCB_ATTR_VALUE_UNDEFINED;
805 prio = DCB_ATTR_VALUE_UNDEFINED;
806 tc_pct = DCB_ATTR_VALUE_UNDEFINED;
807 up_map = DCB_ATTR_VALUE_UNDEFINED;
808
809 if (param_tb[DCB_TC_ATTR_PARAM_STRICT_PRIO])
810 prio =
811 nla_get_u8(param_tb[DCB_TC_ATTR_PARAM_STRICT_PRIO]);
812
813 if (param_tb[DCB_TC_ATTR_PARAM_PGID])
814 pgid = nla_get_u8(param_tb[DCB_TC_ATTR_PARAM_PGID]);
815
816 if (param_tb[DCB_TC_ATTR_PARAM_BW_PCT])
817 tc_pct = nla_get_u8(param_tb[DCB_TC_ATTR_PARAM_BW_PCT]);
818
819 if (param_tb[DCB_TC_ATTR_PARAM_UP_MAPPING])
820 up_map =
821 nla_get_u8(param_tb[DCB_TC_ATTR_PARAM_UP_MAPPING]);
822
823 /* dir: Tx = 0, Rx = 1 */
824 if (dir) {
825 /* Rx */
826 netdev->dcbnl_ops->setpgtccfgrx(netdev,
827 i - DCB_PG_ATTR_TC_0,
828 prio, pgid, tc_pct, up_map);
829 } else {
830 /* Tx */
831 netdev->dcbnl_ops->setpgtccfgtx(netdev,
832 i - DCB_PG_ATTR_TC_0,
833 prio, pgid, tc_pct, up_map);
834 }
835 }
836
837 for (i = DCB_PG_ATTR_BW_ID_0; i <= DCB_PG_ATTR_BW_ID_7; i++) {
838 if (!pg_tb[i])
839 continue;
840
841 tc_pct = nla_get_u8(pg_tb[i]);
842
843 /* dir: Tx = 0, Rx = 1 */
844 if (dir) {
845 /* Rx */
846 netdev->dcbnl_ops->setpgbwgcfgrx(netdev,
847 i - DCB_PG_ATTR_BW_ID_0, tc_pct);
848 } else {
849 /* Tx */
850 netdev->dcbnl_ops->setpgbwgcfgtx(netdev,
851 i - DCB_PG_ATTR_BW_ID_0, tc_pct);
852 }
853 }
854
855 ret = dcbnl_reply(0, RTM_SETDCB,
856 (dir ? DCB_CMD_PGRX_SCFG : DCB_CMD_PGTX_SCFG),
857 DCB_ATTR_PG_CFG, pid, seq, flags);
858
859err:
860 return ret;
861}
862
863static int dcbnl_pgtx_setcfg(struct net_device *netdev, struct nlattr **tb,
864 u32 pid, u32 seq, u16 flags)
865{
866 return __dcbnl_pg_setcfg(netdev, tb, pid, seq, flags, 0);
867}
868
869static int dcbnl_pgrx_setcfg(struct net_device *netdev, struct nlattr **tb,
870 u32 pid, u32 seq, u16 flags)
871{
872 return __dcbnl_pg_setcfg(netdev, tb, pid, seq, flags, 1);
873}
874
875static int dcbnl_bcn_getcfg(struct net_device *netdev, struct nlattr **tb,
876 u32 pid, u32 seq, u16 flags)
877{
878 struct sk_buff *dcbnl_skb;
879 struct nlmsghdr *nlh;
880 struct dcbmsg *dcb;
881 struct nlattr *bcn_nest;
882 struct nlattr *bcn_tb[DCB_BCN_ATTR_MAX + 1];
883 u8 value_byte;
884 u32 value_integer;
885 int ret = -EINVAL;
886 bool getall = false;
887 int i;
888
889 if (!tb[DCB_ATTR_BCN] || !netdev->dcbnl_ops->getbcnrp ||
890 !netdev->dcbnl_ops->getbcncfg)
891 return ret;
892
893 ret = nla_parse_nested(bcn_tb, DCB_BCN_ATTR_MAX,
894 tb[DCB_ATTR_BCN], dcbnl_bcn_nest);
895
896 if (ret)
897 goto err_out;
898
899 dcbnl_skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
900 if (!dcbnl_skb)
901 goto err_out;
902
903 nlh = NLMSG_NEW(dcbnl_skb, pid, seq, RTM_GETDCB, sizeof(*dcb), flags);
904
905 dcb = NLMSG_DATA(nlh);
906 dcb->dcb_family = AF_UNSPEC;
907 dcb->cmd = DCB_CMD_BCN_GCFG;
908
909 bcn_nest = nla_nest_start(dcbnl_skb, DCB_ATTR_BCN);
910 if (!bcn_nest)
911 goto err;
912
913 if (bcn_tb[DCB_BCN_ATTR_ALL])
914 getall = true;
915
916 for (i = DCB_BCN_ATTR_RP_0; i <= DCB_BCN_ATTR_RP_7; i++) {
917 if (!getall && !bcn_tb[i])
918 continue;
919
920 netdev->dcbnl_ops->getbcnrp(netdev, i - DCB_BCN_ATTR_RP_0,
921 &value_byte);
922 ret = nla_put_u8(dcbnl_skb, i, value_byte);
923 if (ret)
924 goto err_bcn;
925 }
926
927 for (i = DCB_BCN_ATTR_BCNA_0; i <= DCB_BCN_ATTR_RI; i++) {
928 if (!getall && !bcn_tb[i])
929 continue;
930
931 netdev->dcbnl_ops->getbcncfg(netdev, i,
932 &value_integer);
933 ret = nla_put_u32(dcbnl_skb, i, value_integer);
934 if (ret)
935 goto err_bcn;
936 }
937
938 nla_nest_end(dcbnl_skb, bcn_nest);
939
940 nlmsg_end(dcbnl_skb, nlh);
941
942 ret = rtnl_unicast(dcbnl_skb, &init_net, pid);
943 if (ret)
944 goto err;
945
946 return 0;
947
948err_bcn:
949 nla_nest_cancel(dcbnl_skb, bcn_nest);
950nlmsg_failure:
951err:
952 kfree(dcbnl_skb);
953err_out:
954 ret = -EINVAL;
955 return ret;
956}
957
958static int dcbnl_bcn_setcfg(struct net_device *netdev, struct nlattr **tb,
959 u32 pid, u32 seq, u16 flags)
960{
961 struct nlattr *data[DCB_BCN_ATTR_MAX + 1];
962 int i;
963 int ret = -EINVAL;
964 u8 value_byte;
965 u32 value_int;
966
967 if (!tb[DCB_ATTR_BCN] || !netdev->dcbnl_ops->setbcncfg
968 || !netdev->dcbnl_ops->setbcnrp)
969 return ret;
970
971 ret = nla_parse_nested(data, DCB_BCN_ATTR_MAX,
972 tb[DCB_ATTR_BCN],
973 dcbnl_pfc_up_nest);
974 if (ret)
975 goto err;
976
977 for (i = DCB_BCN_ATTR_RP_0; i <= DCB_BCN_ATTR_RP_7; i++) {
978 if (data[i] == NULL)
979 continue;
980 value_byte = nla_get_u8(data[i]);
981 netdev->dcbnl_ops->setbcnrp(netdev,
982 data[i]->nla_type - DCB_BCN_ATTR_RP_0, value_byte);
983 }
984
985 for (i = DCB_BCN_ATTR_BCNA_0; i <= DCB_BCN_ATTR_RI; i++) {
986 if (data[i] == NULL)
987 continue;
988 value_int = nla_get_u32(data[i]);
989 netdev->dcbnl_ops->setbcncfg(netdev,
990 i, value_int);
991 }
992
993 ret = dcbnl_reply(0, RTM_SETDCB, DCB_CMD_BCN_SCFG, DCB_ATTR_BCN,
994 pid, seq, flags);
995err:
996 return ret;
997}
998
999static int dcb_doit(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
1000{
1001 struct net *net = sock_net(skb->sk);
1002 struct net_device *netdev;
1003 struct dcbmsg *dcb = (struct dcbmsg *)NLMSG_DATA(nlh);
1004 struct nlattr *tb[DCB_ATTR_MAX + 1];
1005 u32 pid = skb ? NETLINK_CB(skb).pid : 0;
1006 int ret = -EINVAL;
1007
1008 if (net != &init_net)
1009 return -EINVAL;
1010
1011 ret = nlmsg_parse(nlh, sizeof(*dcb), tb, DCB_ATTR_MAX,
1012 dcbnl_rtnl_policy);
1013 if (ret < 0)
1014 return ret;
1015
1016 if (!tb[DCB_ATTR_IFNAME])
1017 return -EINVAL;
1018
1019 netdev = dev_get_by_name(&init_net, nla_data(tb[DCB_ATTR_IFNAME]));
1020 if (!netdev)
1021 return -EINVAL;
1022
1023 if (!netdev->dcbnl_ops)
1024 goto errout;
1025
1026 switch (dcb->cmd) {
1027 case DCB_CMD_GSTATE:
1028 ret = dcbnl_getstate(netdev, tb, pid, nlh->nlmsg_seq,
1029 nlh->nlmsg_flags);
1030 goto out;
1031 case DCB_CMD_PFC_GCFG:
1032 ret = dcbnl_getpfccfg(netdev, tb, pid, nlh->nlmsg_seq,
1033 nlh->nlmsg_flags);
1034 goto out;
1035 case DCB_CMD_GPERM_HWADDR:
1036 ret = dcbnl_getperm_hwaddr(netdev, tb, pid, nlh->nlmsg_seq,
1037 nlh->nlmsg_flags);
1038 goto out;
1039 case DCB_CMD_PGTX_GCFG:
1040 ret = dcbnl_pgtx_getcfg(netdev, tb, pid, nlh->nlmsg_seq,
1041 nlh->nlmsg_flags);
1042 goto out;
1043 case DCB_CMD_PGRX_GCFG:
1044 ret = dcbnl_pgrx_getcfg(netdev, tb, pid, nlh->nlmsg_seq,
1045 nlh->nlmsg_flags);
1046 goto out;
1047 case DCB_CMD_BCN_GCFG:
1048 ret = dcbnl_bcn_getcfg(netdev, tb, pid, nlh->nlmsg_seq,
1049 nlh->nlmsg_flags);
1050 goto out;
1051 case DCB_CMD_SSTATE:
1052 ret = dcbnl_setstate(netdev, tb, pid, nlh->nlmsg_seq,
1053 nlh->nlmsg_flags);
1054 goto out;
1055 case DCB_CMD_PFC_SCFG:
1056 ret = dcbnl_setpfccfg(netdev, tb, pid, nlh->nlmsg_seq,
1057 nlh->nlmsg_flags);
1058 goto out;
1059
1060 case DCB_CMD_SET_ALL:
1061 ret = dcbnl_setall(netdev, tb, pid, nlh->nlmsg_seq,
1062 nlh->nlmsg_flags);
1063 goto out;
1064 case DCB_CMD_PGTX_SCFG:
1065 ret = dcbnl_pgtx_setcfg(netdev, tb, pid, nlh->nlmsg_seq,
1066 nlh->nlmsg_flags);
1067 goto out;
1068 case DCB_CMD_PGRX_SCFG:
1069 ret = dcbnl_pgrx_setcfg(netdev, tb, pid, nlh->nlmsg_seq,
1070 nlh->nlmsg_flags);
1071 goto out;
1072 case DCB_CMD_GCAP:
1073 ret = dcbnl_getcap(netdev, tb, pid, nlh->nlmsg_seq,
1074 nlh->nlmsg_flags);
1075 goto out;
1076 case DCB_CMD_GNUMTCS:
1077 ret = dcbnl_getnumtcs(netdev, tb, pid, nlh->nlmsg_seq,
1078 nlh->nlmsg_flags);
1079 goto out;
1080 case DCB_CMD_SNUMTCS:
1081 ret = dcbnl_setnumtcs(netdev, tb, pid, nlh->nlmsg_seq,
1082 nlh->nlmsg_flags);
1083 goto out;
1084 case DCB_CMD_PFC_GSTATE:
1085 ret = dcbnl_getpfcstate(netdev, tb, pid, nlh->nlmsg_seq,
1086 nlh->nlmsg_flags);
1087 goto out;
1088 case DCB_CMD_PFC_SSTATE:
1089 ret = dcbnl_setpfcstate(netdev, tb, pid, nlh->nlmsg_seq,
1090 nlh->nlmsg_flags);
1091 goto out;
1092 case DCB_CMD_BCN_SCFG:
1093 ret = dcbnl_bcn_setcfg(netdev, tb, pid, nlh->nlmsg_seq,
1094 nlh->nlmsg_flags);
1095 goto out;
1096 default:
1097 goto errout;
1098 }
1099errout:
1100 ret = -EINVAL;
1101out:
1102 dev_put(netdev);
1103 return ret;
1104}
1105
1106static int __init dcbnl_init(void)
1107{
1108 rtnl_register(PF_UNSPEC, RTM_GETDCB, dcb_doit, NULL);
1109 rtnl_register(PF_UNSPEC, RTM_SETDCB, dcb_doit, NULL);
1110
1111 return 0;
1112}
1113module_init(dcbnl_init);
1114
1115static void __exit dcbnl_exit(void)
1116{
1117 rtnl_unregister(PF_UNSPEC, RTM_GETDCB);
1118 rtnl_unregister(PF_UNSPEC, RTM_SETDCB);
1119}
1120module_exit(dcbnl_exit);
1121
1122
diff --git a/net/dccp/ackvec.c b/net/dccp/ackvec.c
index 1e8be246ad15..01e4d39fa232 100644
--- a/net/dccp/ackvec.c
+++ b/net/dccp/ackvec.c
@@ -12,7 +12,6 @@
12#include "ackvec.h" 12#include "ackvec.h"
13#include "dccp.h" 13#include "dccp.h"
14 14
15#include <linux/dccp.h>
16#include <linux/init.h> 15#include <linux/init.h>
17#include <linux/errno.h> 16#include <linux/errno.h>
18#include <linux/kernel.h> 17#include <linux/kernel.h>
@@ -68,7 +67,7 @@ int dccp_insert_option_ackvec(struct sock *sk, struct sk_buff *skb)
68 struct dccp_sock *dp = dccp_sk(sk); 67 struct dccp_sock *dp = dccp_sk(sk);
69 struct dccp_ackvec *av = dp->dccps_hc_rx_ackvec; 68 struct dccp_ackvec *av = dp->dccps_hc_rx_ackvec;
70 /* Figure out how many options do we need to represent the ackvec */ 69 /* Figure out how many options do we need to represent the ackvec */
71 const u16 nr_opts = DIV_ROUND_UP(av->av_vec_len, DCCP_MAX_ACKVEC_OPT_LEN); 70 const u8 nr_opts = DIV_ROUND_UP(av->av_vec_len, DCCP_SINGLE_OPT_MAXLEN);
72 u16 len = av->av_vec_len + 2 * nr_opts, i; 71 u16 len = av->av_vec_len + 2 * nr_opts, i;
73 u32 elapsed_time; 72 u32 elapsed_time;
74 const unsigned char *tail, *from; 73 const unsigned char *tail, *from;
@@ -100,8 +99,8 @@ int dccp_insert_option_ackvec(struct sock *sk, struct sk_buff *skb)
100 for (i = 0; i < nr_opts; ++i) { 99 for (i = 0; i < nr_opts; ++i) {
101 int copylen = len; 100 int copylen = len;
102 101
103 if (len > DCCP_MAX_ACKVEC_OPT_LEN) 102 if (len > DCCP_SINGLE_OPT_MAXLEN)
104 copylen = DCCP_MAX_ACKVEC_OPT_LEN; 103 copylen = DCCP_SINGLE_OPT_MAXLEN;
105 104
106 *to++ = DCCPO_ACK_VECTOR_0; 105 *to++ = DCCPO_ACK_VECTOR_0;
107 *to++ = copylen + 2; 106 *to++ = copylen + 2;
@@ -432,7 +431,7 @@ found:
432int dccp_ackvec_parse(struct sock *sk, const struct sk_buff *skb, 431int dccp_ackvec_parse(struct sock *sk, const struct sk_buff *skb,
433 u64 *ackno, const u8 opt, const u8 *value, const u8 len) 432 u64 *ackno, const u8 opt, const u8 *value, const u8 len)
434{ 433{
435 if (len > DCCP_MAX_ACKVEC_OPT_LEN) 434 if (len > DCCP_SINGLE_OPT_MAXLEN)
436 return -1; 435 return -1;
437 436
438 /* dccp_ackvector_print(DCCP_SKB_CB(skb)->dccpd_ack_seq, value, len); */ 437 /* dccp_ackvector_print(DCCP_SKB_CB(skb)->dccpd_ack_seq, value, len); */
diff --git a/net/dccp/ackvec.h b/net/dccp/ackvec.h
index bcb64fb4acef..4ccee030524e 100644
--- a/net/dccp/ackvec.h
+++ b/net/dccp/ackvec.h
@@ -11,15 +11,14 @@
11 * published by the Free Software Foundation. 11 * published by the Free Software Foundation.
12 */ 12 */
13 13
14#include <linux/dccp.h>
14#include <linux/compiler.h> 15#include <linux/compiler.h>
15#include <linux/ktime.h> 16#include <linux/ktime.h>
16#include <linux/list.h> 17#include <linux/list.h>
17#include <linux/types.h> 18#include <linux/types.h>
18 19
19/* Read about the ECN nonce to see why it is 253 */
20#define DCCP_MAX_ACKVEC_OPT_LEN 253
21/* We can spread an ack vector across multiple options */ 20/* We can spread an ack vector across multiple options */
22#define DCCP_MAX_ACKVEC_LEN (DCCP_MAX_ACKVEC_OPT_LEN * 2) 21#define DCCP_MAX_ACKVEC_LEN (DCCP_SINGLE_OPT_MAXLEN * 2)
23 22
24#define DCCP_ACKVEC_STATE_RECEIVED 0 23#define DCCP_ACKVEC_STATE_RECEIVED 0
25#define DCCP_ACKVEC_STATE_ECN_MARKED (1 << 6) 24#define DCCP_ACKVEC_STATE_ECN_MARKED (1 << 6)
diff --git a/net/dccp/ccid.c b/net/dccp/ccid.c
index 8fe931a3d7a1..bcc643f992ae 100644
--- a/net/dccp/ccid.c
+++ b/net/dccp/ccid.c
@@ -13,6 +13,13 @@
13 13
14#include "ccid.h" 14#include "ccid.h"
15 15
16static u8 builtin_ccids[] = {
17 DCCPC_CCID2, /* CCID2 is supported by default */
18#if defined(CONFIG_IP_DCCP_CCID3) || defined(CONFIG_IP_DCCP_CCID3_MODULE)
19 DCCPC_CCID3,
20#endif
21};
22
16static struct ccid_operations *ccids[CCID_MAX]; 23static struct ccid_operations *ccids[CCID_MAX];
17#if defined(CONFIG_SMP) || defined(CONFIG_PREEMPT) 24#if defined(CONFIG_SMP) || defined(CONFIG_PREEMPT)
18static atomic_t ccids_lockct = ATOMIC_INIT(0); 25static atomic_t ccids_lockct = ATOMIC_INIT(0);
@@ -86,6 +93,47 @@ static void ccid_kmem_cache_destroy(struct kmem_cache *slab)
86 } 93 }
87} 94}
88 95
96/* check that up to @array_len members in @ccid_array are supported */
97bool ccid_support_check(u8 const *ccid_array, u8 array_len)
98{
99 u8 i, j, found;
100
101 for (i = 0, found = 0; i < array_len; i++, found = 0) {
102 for (j = 0; !found && j < ARRAY_SIZE(builtin_ccids); j++)
103 found = (ccid_array[i] == builtin_ccids[j]);
104 if (!found)
105 return false;
106 }
107 return true;
108}
109
110/**
111 * ccid_get_builtin_ccids - Provide copy of `builtin' CCID array
112 * @ccid_array: pointer to copy into
113 * @array_len: value to return length into
114 * This function allocates memory - caller must see that it is freed after use.
115 */
116int ccid_get_builtin_ccids(u8 **ccid_array, u8 *array_len)
117{
118 *ccid_array = kmemdup(builtin_ccids, sizeof(builtin_ccids), gfp_any());
119 if (*ccid_array == NULL)
120 return -ENOBUFS;
121 *array_len = ARRAY_SIZE(builtin_ccids);
122 return 0;
123}
124
125int ccid_getsockopt_builtin_ccids(struct sock *sk, int len,
126 char __user *optval, int __user *optlen)
127{
128 if (len < sizeof(builtin_ccids))
129 return -EINVAL;
130
131 if (put_user(sizeof(builtin_ccids), optlen) ||
132 copy_to_user(optval, builtin_ccids, sizeof(builtin_ccids)))
133 return -EFAULT;
134 return 0;
135}
136
89int ccid_register(struct ccid_operations *ccid_ops) 137int ccid_register(struct ccid_operations *ccid_ops)
90{ 138{
91 int err = -ENOBUFS; 139 int err = -ENOBUFS;
@@ -205,20 +253,6 @@ out_module_put:
205 253
206EXPORT_SYMBOL_GPL(ccid_new); 254EXPORT_SYMBOL_GPL(ccid_new);
207 255
208struct ccid *ccid_hc_rx_new(unsigned char id, struct sock *sk, gfp_t gfp)
209{
210 return ccid_new(id, sk, 1, gfp);
211}
212
213EXPORT_SYMBOL_GPL(ccid_hc_rx_new);
214
215struct ccid *ccid_hc_tx_new(unsigned char id,struct sock *sk, gfp_t gfp)
216{
217 return ccid_new(id, sk, 0, gfp);
218}
219
220EXPORT_SYMBOL_GPL(ccid_hc_tx_new);
221
222static void ccid_delete(struct ccid *ccid, struct sock *sk, int rx) 256static void ccid_delete(struct ccid *ccid, struct sock *sk, int rx)
223{ 257{
224 struct ccid_operations *ccid_ops; 258 struct ccid_operations *ccid_ops;
diff --git a/net/dccp/ccid.h b/net/dccp/ccid.h
index fdeae7b57319..18f69423a708 100644
--- a/net/dccp/ccid.h
+++ b/net/dccp/ccid.h
@@ -103,13 +103,31 @@ static inline void *ccid_priv(const struct ccid *ccid)
103 return (void *)ccid->ccid_priv; 103 return (void *)ccid->ccid_priv;
104} 104}
105 105
106extern bool ccid_support_check(u8 const *ccid_array, u8 array_len);
107extern int ccid_get_builtin_ccids(u8 **ccid_array, u8 *array_len);
108extern int ccid_getsockopt_builtin_ccids(struct sock *sk, int len,
109 char __user *, int __user *);
110
106extern struct ccid *ccid_new(unsigned char id, struct sock *sk, int rx, 111extern struct ccid *ccid_new(unsigned char id, struct sock *sk, int rx,
107 gfp_t gfp); 112 gfp_t gfp);
108 113
109extern struct ccid *ccid_hc_rx_new(unsigned char id, struct sock *sk, 114static inline int ccid_get_current_rx_ccid(struct dccp_sock *dp)
110 gfp_t gfp); 115{
111extern struct ccid *ccid_hc_tx_new(unsigned char id, struct sock *sk, 116 struct ccid *ccid = dp->dccps_hc_rx_ccid;
112 gfp_t gfp); 117
118 if (ccid == NULL || ccid->ccid_ops == NULL)
119 return -1;
120 return ccid->ccid_ops->ccid_id;
121}
122
123static inline int ccid_get_current_tx_ccid(struct dccp_sock *dp)
124{
125 struct ccid *ccid = dp->dccps_hc_tx_ccid;
126
127 if (ccid == NULL || ccid->ccid_ops == NULL)
128 return -1;
129 return ccid->ccid_ops->ccid_id;
130}
113 131
114extern void ccid_hc_rx_delete(struct ccid *ccid, struct sock *sk); 132extern void ccid_hc_rx_delete(struct ccid *ccid, struct sock *sk);
115extern void ccid_hc_tx_delete(struct ccid *ccid, struct sock *sk); 133extern void ccid_hc_tx_delete(struct ccid *ccid, struct sock *sk);
diff --git a/net/dccp/ccids/ccid2.c b/net/dccp/ccids/ccid2.c
index 9a430734530c..c9ea19a4d85e 100644
--- a/net/dccp/ccids/ccid2.c
+++ b/net/dccp/ccids/ccid2.c
@@ -25,7 +25,7 @@
25/* 25/*
26 * This implementation should follow RFC 4341 26 * This implementation should follow RFC 4341
27 */ 27 */
28 28#include "../feat.h"
29#include "../ccid.h" 29#include "../ccid.h"
30#include "../dccp.h" 30#include "../dccp.h"
31#include "ccid2.h" 31#include "ccid2.h"
@@ -147,8 +147,8 @@ static void ccid2_change_l_ack_ratio(struct sock *sk, u32 val)
147 DCCP_WARN("Limiting Ack Ratio (%u) to %u\n", val, max_ratio); 147 DCCP_WARN("Limiting Ack Ratio (%u) to %u\n", val, max_ratio);
148 val = max_ratio; 148 val = max_ratio;
149 } 149 }
150 if (val > 0xFFFF) /* RFC 4340, 11.3 */ 150 if (val > DCCPF_ACK_RATIO_MAX)
151 val = 0xFFFF; 151 val = DCCPF_ACK_RATIO_MAX;
152 152
153 if (val == dp->dccps_l_ack_ratio) 153 if (val == dp->dccps_l_ack_ratio)
154 return; 154 return;
diff --git a/net/dccp/dccp.h b/net/dccp/dccp.h
index b4bc6e095a0e..0bc4c9a02e19 100644
--- a/net/dccp/dccp.h
+++ b/net/dccp/dccp.h
@@ -49,7 +49,7 @@ extern int dccp_debug;
49 49
50extern struct inet_hashinfo dccp_hashinfo; 50extern struct inet_hashinfo dccp_hashinfo;
51 51
52extern atomic_t dccp_orphan_count; 52extern struct percpu_counter dccp_orphan_count;
53 53
54extern void dccp_time_wait(struct sock *sk, int state, int timeo); 54extern void dccp_time_wait(struct sock *sk, int state, int timeo);
55 55
@@ -98,9 +98,6 @@ extern int sysctl_dccp_retries2;
98extern int sysctl_dccp_feat_sequence_window; 98extern int sysctl_dccp_feat_sequence_window;
99extern int sysctl_dccp_feat_rx_ccid; 99extern int sysctl_dccp_feat_rx_ccid;
100extern int sysctl_dccp_feat_tx_ccid; 100extern int sysctl_dccp_feat_tx_ccid;
101extern int sysctl_dccp_feat_ack_ratio;
102extern int sysctl_dccp_feat_send_ack_vector;
103extern int sysctl_dccp_feat_send_ndp_count;
104extern int sysctl_dccp_tx_qlen; 101extern int sysctl_dccp_tx_qlen;
105extern int sysctl_dccp_sync_ratelimit; 102extern int sysctl_dccp_sync_ratelimit;
106 103
@@ -252,7 +249,8 @@ extern const char *dccp_state_name(const int state);
252extern void dccp_set_state(struct sock *sk, const int state); 249extern void dccp_set_state(struct sock *sk, const int state);
253extern void dccp_done(struct sock *sk); 250extern void dccp_done(struct sock *sk);
254 251
255extern void dccp_reqsk_init(struct request_sock *req, struct sk_buff *skb); 252extern int dccp_reqsk_init(struct request_sock *rq, struct dccp_sock const *dp,
253 struct sk_buff const *skb);
256 254
257extern int dccp_v4_conn_request(struct sock *sk, struct sk_buff *skb); 255extern int dccp_v4_conn_request(struct sock *sk, struct sk_buff *skb);
258 256
@@ -435,12 +433,19 @@ static inline int dccp_ack_pending(const struct sock *sk)
435 const struct dccp_sock *dp = dccp_sk(sk); 433 const struct dccp_sock *dp = dccp_sk(sk);
436 return dp->dccps_timestamp_echo != 0 || 434 return dp->dccps_timestamp_echo != 0 ||
437#ifdef CONFIG_IP_DCCP_ACKVEC 435#ifdef CONFIG_IP_DCCP_ACKVEC
438 (dccp_msk(sk)->dccpms_send_ack_vector && 436 (dp->dccps_hc_rx_ackvec != NULL &&
439 dccp_ackvec_pending(dp->dccps_hc_rx_ackvec)) || 437 dccp_ackvec_pending(dp->dccps_hc_rx_ackvec)) ||
440#endif 438#endif
441 inet_csk_ack_scheduled(sk); 439 inet_csk_ack_scheduled(sk);
442} 440}
443 441
442extern int dccp_feat_finalise_settings(struct dccp_sock *dp);
443extern int dccp_feat_server_ccid_dependencies(struct dccp_request_sock *dreq);
444extern int dccp_feat_insert_opts(struct dccp_sock*, struct dccp_request_sock*,
445 struct sk_buff *skb);
446extern int dccp_feat_activate_values(struct sock *sk, struct list_head *fn);
447extern void dccp_feat_list_purge(struct list_head *fn_list);
448
444extern int dccp_insert_options(struct sock *sk, struct sk_buff *skb); 449extern int dccp_insert_options(struct sock *sk, struct sk_buff *skb);
445extern int dccp_insert_options_rsk(struct dccp_request_sock*, struct sk_buff*); 450extern int dccp_insert_options_rsk(struct dccp_request_sock*, struct sk_buff*);
446extern int dccp_insert_option_elapsed_time(struct sock *sk, 451extern int dccp_insert_option_elapsed_time(struct sock *sk,
diff --git a/net/dccp/diag.c b/net/dccp/diag.c
index d8a3509b26f6..b21f261da75e 100644
--- a/net/dccp/diag.c
+++ b/net/dccp/diag.c
@@ -29,11 +29,14 @@ static void dccp_get_info(struct sock *sk, struct tcp_info *info)
29 info->tcpi_backoff = icsk->icsk_backoff; 29 info->tcpi_backoff = icsk->icsk_backoff;
30 info->tcpi_pmtu = icsk->icsk_pmtu_cookie; 30 info->tcpi_pmtu = icsk->icsk_pmtu_cookie;
31 31
32 if (dccp_msk(sk)->dccpms_send_ack_vector) 32 if (dp->dccps_hc_rx_ackvec != NULL)
33 info->tcpi_options |= TCPI_OPT_SACK; 33 info->tcpi_options |= TCPI_OPT_SACK;
34 34
35 ccid_hc_rx_get_info(dp->dccps_hc_rx_ccid, sk, info); 35 if (dp->dccps_hc_rx_ccid != NULL)
36 ccid_hc_tx_get_info(dp->dccps_hc_tx_ccid, sk, info); 36 ccid_hc_rx_get_info(dp->dccps_hc_rx_ccid, sk, info);
37
38 if (dp->dccps_hc_tx_ccid != NULL)
39 ccid_hc_tx_get_info(dp->dccps_hc_tx_ccid, sk, info);
37} 40}
38 41
39static void dccp_diag_get_info(struct sock *sk, struct inet_diag_msg *r, 42static void dccp_diag_get_info(struct sock *sk, struct inet_diag_msg *r,
@@ -45,7 +48,7 @@ static void dccp_diag_get_info(struct sock *sk, struct inet_diag_msg *r,
45 dccp_get_info(sk, _info); 48 dccp_get_info(sk, _info);
46} 49}
47 50
48static struct inet_diag_handler dccp_diag_handler = { 51static const struct inet_diag_handler dccp_diag_handler = {
49 .idiag_hashinfo = &dccp_hashinfo, 52 .idiag_hashinfo = &dccp_hashinfo,
50 .idiag_get_info = dccp_diag_get_info, 53 .idiag_get_info = dccp_diag_get_info,
51 .idiag_type = DCCPDIAG_GETSOCK, 54 .idiag_type = DCCPDIAG_GETSOCK,
diff --git a/net/dccp/feat.c b/net/dccp/feat.c
index 933a0ecf8d46..30f9fb76b921 100644
--- a/net/dccp/feat.c
+++ b/net/dccp/feat.c
@@ -1,11 +1,17 @@
1/* 1/*
2 * net/dccp/feat.c 2 * net/dccp/feat.c
3 * 3 *
4 * An implementation of the DCCP protocol 4 * Feature negotiation for the DCCP protocol (RFC 4340, section 6)
5 * Andrea Bittau <a.bittau@cs.ucl.ac.uk> 5 *
6 * Copyright (c) 2008 Gerrit Renker <gerrit@erg.abdn.ac.uk>
7 * Rewrote from scratch, some bits from earlier code by
8 * Copyright (c) 2005 Andrea Bittau <a.bittau@cs.ucl.ac.uk>
9 *
6 * 10 *
7 * ASSUMPTIONS 11 * ASSUMPTIONS
8 * ----------- 12 * -----------
13 * o Feature negotiation is coordinated with connection setup (as in TCP), wild
14 * changes of parameters of an established connection are not supported.
9 * o All currently known SP features have 1-byte quantities. If in the future 15 * o All currently known SP features have 1-byte quantities. If in the future
10 * extensions of RFCs 4340..42 define features with item lengths larger than 16 * extensions of RFCs 4340..42 define features with item lengths larger than
11 * one byte, a feature-specific extension of the code will be required. 17 * one byte, a feature-specific extension of the code will be required.
@@ -15,597 +21,1185 @@
15 * as published by the Free Software Foundation; either version 21 * as published by the Free Software Foundation; either version
16 * 2 of the License, or (at your option) any later version. 22 * 2 of the License, or (at your option) any later version.
17 */ 23 */
18
19#include <linux/module.h> 24#include <linux/module.h>
20
21#include "ccid.h" 25#include "ccid.h"
22#include "feat.h" 26#include "feat.h"
23 27
24#define DCCP_FEAT_SP_NOAGREE (-123) 28/*
25 29 * Feature activation handlers.
26int dccp_feat_change(struct dccp_minisock *dmsk, u8 type, u8 feature, 30 *
27 u8 *val, u8 len, gfp_t gfp) 31 * These all use an u64 argument, to provide enough room for NN/SP features. At
28{ 32 * this stage the negotiated values have been checked to be within their range.
29 struct dccp_opt_pend *opt; 33 */
30 34static int dccp_hdlr_ccid(struct sock *sk, u64 ccid, bool rx)
31 dccp_feat_debug(type, feature, *val);
32
33 if (len > 3) {
34 DCCP_WARN("invalid length %d\n", len);
35 return -EINVAL;
36 }
37 /* XXX add further sanity checks */
38
39 /* check if that feature is already being negotiated */
40 list_for_each_entry(opt, &dmsk->dccpms_pending, dccpop_node) {
41 /* ok we found a negotiation for this option already */
42 if (opt->dccpop_feat == feature && opt->dccpop_type == type) {
43 dccp_pr_debug("Replacing old\n");
44 /* replace */
45 BUG_ON(opt->dccpop_val == NULL);
46 kfree(opt->dccpop_val);
47 opt->dccpop_val = val;
48 opt->dccpop_len = len;
49 opt->dccpop_conf = 0;
50 return 0;
51 }
52 }
53
54 /* negotiation for a new feature */
55 opt = kmalloc(sizeof(*opt), gfp);
56 if (opt == NULL)
57 return -ENOMEM;
58
59 opt->dccpop_type = type;
60 opt->dccpop_feat = feature;
61 opt->dccpop_len = len;
62 opt->dccpop_val = val;
63 opt->dccpop_conf = 0;
64 opt->dccpop_sc = NULL;
65
66 BUG_ON(opt->dccpop_val == NULL);
67
68 list_add_tail(&opt->dccpop_node, &dmsk->dccpms_pending);
69 return 0;
70}
71
72EXPORT_SYMBOL_GPL(dccp_feat_change);
73
74static int dccp_feat_update_ccid(struct sock *sk, u8 type, u8 new_ccid_nr)
75{ 35{
76 struct dccp_sock *dp = dccp_sk(sk); 36 struct dccp_sock *dp = dccp_sk(sk);
77 struct dccp_minisock *dmsk = dccp_msk(sk); 37 struct ccid *new_ccid = ccid_new(ccid, sk, rx, gfp_any());
78 /* figure out if we are changing our CCID or the peer's */
79 const int rx = type == DCCPO_CHANGE_R;
80 const u8 ccid_nr = rx ? dmsk->dccpms_rx_ccid : dmsk->dccpms_tx_ccid;
81 struct ccid *new_ccid;
82 38
83 /* Check if nothing is being changed. */
84 if (ccid_nr == new_ccid_nr)
85 return 0;
86
87 new_ccid = ccid_new(new_ccid_nr, sk, rx, GFP_ATOMIC);
88 if (new_ccid == NULL) 39 if (new_ccid == NULL)
89 return -ENOMEM; 40 return -ENOMEM;
90 41
91 if (rx) { 42 if (rx) {
92 ccid_hc_rx_delete(dp->dccps_hc_rx_ccid, sk); 43 ccid_hc_rx_delete(dp->dccps_hc_rx_ccid, sk);
93 dp->dccps_hc_rx_ccid = new_ccid; 44 dp->dccps_hc_rx_ccid = new_ccid;
94 dmsk->dccpms_rx_ccid = new_ccid_nr;
95 } else { 45 } else {
96 ccid_hc_tx_delete(dp->dccps_hc_tx_ccid, sk); 46 ccid_hc_tx_delete(dp->dccps_hc_tx_ccid, sk);
97 dp->dccps_hc_tx_ccid = new_ccid; 47 dp->dccps_hc_tx_ccid = new_ccid;
98 dmsk->dccpms_tx_ccid = new_ccid_nr;
99 } 48 }
49 return 0;
50}
100 51
52static int dccp_hdlr_seq_win(struct sock *sk, u64 seq_win, bool rx)
53{
54 if (!rx)
55 dccp_msk(sk)->dccpms_sequence_window = seq_win;
101 return 0; 56 return 0;
102} 57}
103 58
104static int dccp_feat_update(struct sock *sk, u8 type, u8 feat, u8 val) 59static int dccp_hdlr_ack_ratio(struct sock *sk, u64 ratio, bool rx)
105{ 60{
106 dccp_feat_debug(type, feat, val); 61 if (rx)
62 dccp_sk(sk)->dccps_r_ack_ratio = ratio;
63 else
64 dccp_sk(sk)->dccps_l_ack_ratio = ratio;
65 return 0;
66}
107 67
108 switch (feat) { 68static int dccp_hdlr_ackvec(struct sock *sk, u64 enable, bool rx)
109 case DCCPF_CCID: 69{
110 return dccp_feat_update_ccid(sk, type, val); 70 struct dccp_sock *dp = dccp_sk(sk);
111 default: 71
112 dccp_pr_debug("UNIMPLEMENTED: %s(%d, ...)\n", 72 if (rx) {
113 dccp_feat_typename(type), feat); 73 if (enable && dp->dccps_hc_rx_ackvec == NULL) {
114 break; 74 dp->dccps_hc_rx_ackvec = dccp_ackvec_alloc(gfp_any());
75 if (dp->dccps_hc_rx_ackvec == NULL)
76 return -ENOMEM;
77 } else if (!enable) {
78 dccp_ackvec_free(dp->dccps_hc_rx_ackvec);
79 dp->dccps_hc_rx_ackvec = NULL;
80 }
115 } 81 }
116 return 0; 82 return 0;
117} 83}
118 84
119static int dccp_feat_reconcile(struct sock *sk, struct dccp_opt_pend *opt, 85static int dccp_hdlr_ndp(struct sock *sk, u64 enable, bool rx)
120 u8 *rpref, u8 rlen)
121{ 86{
122 struct dccp_sock *dp = dccp_sk(sk); 87 if (!rx)
123 u8 *spref, slen, *res = NULL; 88 dccp_sk(sk)->dccps_send_ndp_count = (enable > 0);
124 int i, j, rc, agree = 1; 89 return 0;
90}
125 91
126 BUG_ON(rpref == NULL); 92/*
93 * Minimum Checksum Coverage is located at the RX side (9.2.1). This means that
94 * `rx' holds when the sending peer informs about his partial coverage via a
95 * ChangeR() option. In the other case, we are the sender and the receiver
96 * announces its coverage via ChangeL() options. The policy here is to honour
97 * such communication by enabling the corresponding partial coverage - but only
98 * if it has not been set manually before; the warning here means that all
99 * packets will be dropped.
100 */
101static int dccp_hdlr_min_cscov(struct sock *sk, u64 cscov, bool rx)
102{
103 struct dccp_sock *dp = dccp_sk(sk);
127 104
128 /* check if we are the black sheep */ 105 if (rx)
129 if (dp->dccps_role == DCCP_ROLE_CLIENT) { 106 dp->dccps_pcrlen = cscov;
130 spref = rpref; 107 else {
131 slen = rlen; 108 if (dp->dccps_pcslen == 0)
132 rpref = opt->dccpop_val; 109 dp->dccps_pcslen = cscov;
133 rlen = opt->dccpop_len; 110 else if (cscov > dp->dccps_pcslen)
134 } else { 111 DCCP_WARN("CsCov %u too small, peer requires >= %u\n",
135 spref = opt->dccpop_val; 112 dp->dccps_pcslen, (u8)cscov);
136 slen = opt->dccpop_len;
137 } 113 }
138 /* 114 return 0;
139 * Now we have server preference list in spref and client preference in 115}
140 * rpref
141 */
142 BUG_ON(spref == NULL);
143 BUG_ON(rpref == NULL);
144 116
145 /* FIXME sanity check vals */ 117static const struct {
118 u8 feat_num; /* DCCPF_xxx */
119 enum dccp_feat_type rxtx; /* RX or TX */
120 enum dccp_feat_type reconciliation; /* SP or NN */
121 u8 default_value; /* as in 6.4 */
122 int (*activation_hdlr)(struct sock *sk, u64 val, bool rx);
123/*
124 * Lookup table for location and type of features (from RFC 4340/4342)
125 * +--------------------------+----+-----+----+----+---------+-----------+
126 * | Feature | Location | Reconc. | Initial | Section |
127 * | | RX | TX | SP | NN | Value | Reference |
128 * +--------------------------+----+-----+----+----+---------+-----------+
129 * | DCCPF_CCID | | X | X | | 2 | 10 |
130 * | DCCPF_SHORT_SEQNOS | | X | X | | 0 | 7.6.1 |
131 * | DCCPF_SEQUENCE_WINDOW | | X | | X | 100 | 7.5.2 |
132 * | DCCPF_ECN_INCAPABLE | X | | X | | 0 | 12.1 |
133 * | DCCPF_ACK_RATIO | | X | | X | 2 | 11.3 |
134 * | DCCPF_SEND_ACK_VECTOR | X | | X | | 0 | 11.5 |
135 * | DCCPF_SEND_NDP_COUNT | | X | X | | 0 | 7.7.2 |
136 * | DCCPF_MIN_CSUM_COVER | X | | X | | 0 | 9.2.1 |
137 * | DCCPF_DATA_CHECKSUM | X | | X | | 0 | 9.3.1 |
138 * | DCCPF_SEND_LEV_RATE | X | | X | | 0 | 4342/8.4 |
139 * +--------------------------+----+-----+----+----+---------+-----------+
140 */
141} dccp_feat_table[] = {
142 { DCCPF_CCID, FEAT_AT_TX, FEAT_SP, 2, dccp_hdlr_ccid },
143 { DCCPF_SHORT_SEQNOS, FEAT_AT_TX, FEAT_SP, 0, NULL },
144 { DCCPF_SEQUENCE_WINDOW, FEAT_AT_TX, FEAT_NN, 100, dccp_hdlr_seq_win },
145 { DCCPF_ECN_INCAPABLE, FEAT_AT_RX, FEAT_SP, 0, NULL },
146 { DCCPF_ACK_RATIO, FEAT_AT_TX, FEAT_NN, 2, dccp_hdlr_ack_ratio},
147 { DCCPF_SEND_ACK_VECTOR, FEAT_AT_RX, FEAT_SP, 0, dccp_hdlr_ackvec },
148 { DCCPF_SEND_NDP_COUNT, FEAT_AT_TX, FEAT_SP, 0, dccp_hdlr_ndp },
149 { DCCPF_MIN_CSUM_COVER, FEAT_AT_RX, FEAT_SP, 0, dccp_hdlr_min_cscov},
150 { DCCPF_DATA_CHECKSUM, FEAT_AT_RX, FEAT_SP, 0, NULL },
151 { DCCPF_SEND_LEV_RATE, FEAT_AT_RX, FEAT_SP, 0, NULL },
152};
153#define DCCP_FEAT_SUPPORTED_MAX ARRAY_SIZE(dccp_feat_table)
154
155/**
156 * dccp_feat_index - Hash function to map feature number into array position
157 * Returns consecutive array index or -1 if the feature is not understood.
158 */
159static int dccp_feat_index(u8 feat_num)
160{
161 /* The first 9 entries are occupied by the types from RFC 4340, 6.4 */
162 if (feat_num > DCCPF_RESERVED && feat_num <= DCCPF_DATA_CHECKSUM)
163 return feat_num - 1;
146 164
147 /* Are values in any order? XXX Lame "algorithm" here */ 165 /*
148 for (i = 0; i < slen; i++) { 166 * Other features: add cases for new feature types here after adding
149 for (j = 0; j < rlen; j++) { 167 * them to the above table.
150 if (spref[i] == rpref[j]) { 168 */
151 res = &spref[i]; 169 switch (feat_num) {
152 break; 170 case DCCPF_SEND_LEV_RATE:
153 } 171 return DCCP_FEAT_SUPPORTED_MAX - 1;
154 }
155 if (res)
156 break;
157 } 172 }
173 return -1;
174}
158 175
159 /* we didn't agree on anything */ 176static u8 dccp_feat_type(u8 feat_num)
160 if (res == NULL) { 177{
161 /* confirm previous value */ 178 int idx = dccp_feat_index(feat_num);
162 switch (opt->dccpop_feat) {
163 case DCCPF_CCID:
164 /* XXX did i get this right? =P */
165 if (opt->dccpop_type == DCCPO_CHANGE_L)
166 res = &dccp_msk(sk)->dccpms_tx_ccid;
167 else
168 res = &dccp_msk(sk)->dccpms_rx_ccid;
169 break;
170 179
171 default: 180 if (idx < 0)
172 DCCP_BUG("Fell through, feat=%d", opt->dccpop_feat); 181 return FEAT_UNKNOWN;
173 /* XXX implement res */ 182 return dccp_feat_table[idx].reconciliation;
174 return -EFAULT; 183}
175 }
176 184
177 dccp_pr_debug("Don't agree... reconfirming %d\n", *res); 185static int dccp_feat_default_value(u8 feat_num)
178 agree = 0; /* this is used for mandatory options... */ 186{
179 } 187 int idx = dccp_feat_index(feat_num);
188 /*
189 * There are no default values for unknown features, so encountering a
190 * negative index here indicates a serious problem somewhere else.
191 */
192 DCCP_BUG_ON(idx < 0);
180 193
181 /* need to put result and our preference list */ 194 return idx < 0 ? 0 : dccp_feat_table[idx].default_value;
182 rlen = 1 + opt->dccpop_len; 195}
183 rpref = kmalloc(rlen, GFP_ATOMIC);
184 if (rpref == NULL)
185 return -ENOMEM;
186 196
187 *rpref = *res; 197static int __dccp_feat_activate(struct sock *sk, const int idx,
188 memcpy(&rpref[1], opt->dccpop_val, opt->dccpop_len); 198 const bool is_local, dccp_feat_val const *fval)
199{
200 bool rx;
201 u64 val;
189 202
190 /* put it in the "confirm queue" */ 203 if (idx < 0 || idx >= DCCP_FEAT_SUPPORTED_MAX)
191 if (opt->dccpop_sc == NULL) { 204 return -1;
192 opt->dccpop_sc = kmalloc(sizeof(*opt->dccpop_sc), GFP_ATOMIC); 205 if (dccp_feat_table[idx].activation_hdlr == NULL)
193 if (opt->dccpop_sc == NULL) { 206 return 0;
194 kfree(rpref); 207
195 return -ENOMEM; 208 if (fval == NULL) {
209 val = dccp_feat_table[idx].default_value;
210 } else if (dccp_feat_table[idx].reconciliation == FEAT_SP) {
211 if (fval->sp.vec == NULL) {
212 /*
213 * This can happen when an empty Confirm is sent
214 * for an SP (i.e. known) feature. In this case
215 * we would be using the default anyway.
216 */
217 DCCP_CRIT("Feature #%d undefined: using default", idx);
218 val = dccp_feat_table[idx].default_value;
219 } else {
220 val = fval->sp.vec[0];
196 } 221 }
197 } else { 222 } else {
198 /* recycle the confirm slot */ 223 val = fval->nn;
199 BUG_ON(opt->dccpop_sc->dccpoc_val == NULL);
200 kfree(opt->dccpop_sc->dccpoc_val);
201 dccp_pr_debug("recycling confirm slot\n");
202 } 224 }
203 memset(opt->dccpop_sc, 0, sizeof(*opt->dccpop_sc));
204 225
205 opt->dccpop_sc->dccpoc_val = rpref; 226 /* Location is RX if this is a local-RX or remote-TX feature */
206 opt->dccpop_sc->dccpoc_len = rlen; 227 rx = (is_local == (dccp_feat_table[idx].rxtx == FEAT_AT_RX));
207 228
208 /* update the option on our side [we are about to send the confirm] */ 229 return dccp_feat_table[idx].activation_hdlr(sk, val, rx);
209 rc = dccp_feat_update(sk, opt->dccpop_type, opt->dccpop_feat, *res); 230}
210 if (rc) {
211 kfree(opt->dccpop_sc->dccpoc_val);
212 kfree(opt->dccpop_sc);
213 opt->dccpop_sc = NULL;
214 return rc;
215 }
216 231
217 dccp_pr_debug("Will confirm %d\n", *rpref); 232/* Test for "Req'd" feature (RFC 4340, 6.4) */
233static inline int dccp_feat_must_be_understood(u8 feat_num)
234{
235 return feat_num == DCCPF_CCID || feat_num == DCCPF_SHORT_SEQNOS ||
236 feat_num == DCCPF_SEQUENCE_WINDOW;
237}
218 238
219 /* say we want to change to X but we just got a confirm X, suppress our 239/* copy constructor, fval must not already contain allocated memory */
220 * change 240static int dccp_feat_clone_sp_val(dccp_feat_val *fval, u8 const *val, u8 len)
221 */ 241{
222 if (!opt->dccpop_conf) { 242 fval->sp.len = len;
223 if (*opt->dccpop_val == *res) 243 if (fval->sp.len > 0) {
224 opt->dccpop_conf = 1; 244 fval->sp.vec = kmemdup(val, len, gfp_any());
225 dccp_pr_debug("won't ask for change of same feature\n"); 245 if (fval->sp.vec == NULL) {
246 fval->sp.len = 0;
247 return -ENOBUFS;
248 }
226 } 249 }
250 return 0;
251}
227 252
228 return agree ? 0 : DCCP_FEAT_SP_NOAGREE; /* used for mandatory opts */ 253static void dccp_feat_val_destructor(u8 feat_num, dccp_feat_val *val)
254{
255 if (unlikely(val == NULL))
256 return;
257 if (dccp_feat_type(feat_num) == FEAT_SP)
258 kfree(val->sp.vec);
259 memset(val, 0, sizeof(*val));
229} 260}
230 261
231static int dccp_feat_sp(struct sock *sk, u8 type, u8 feature, u8 *val, u8 len) 262static struct dccp_feat_entry *
263 dccp_feat_clone_entry(struct dccp_feat_entry const *original)
232{ 264{
233 struct dccp_minisock *dmsk = dccp_msk(sk); 265 struct dccp_feat_entry *new;
234 struct dccp_opt_pend *opt; 266 u8 type = dccp_feat_type(original->feat_num);
235 int rc = 1;
236 u8 t;
237 267
238 /* 268 if (type == FEAT_UNKNOWN)
239 * We received a CHANGE. We gotta match it against our own preference 269 return NULL;
240 * list. If we got a CHANGE_R it means it's a change for us, so we need
241 * to compare our CHANGE_L list.
242 */
243 if (type == DCCPO_CHANGE_L)
244 t = DCCPO_CHANGE_R;
245 else
246 t = DCCPO_CHANGE_L;
247 270
248 /* find our preference list for this feature */ 271 new = kmemdup(original, sizeof(struct dccp_feat_entry), gfp_any());
249 list_for_each_entry(opt, &dmsk->dccpms_pending, dccpop_node) { 272 if (new == NULL)
250 if (opt->dccpop_type != t || opt->dccpop_feat != feature) 273 return NULL;
251 continue;
252 274
253 /* find the winner from the two preference lists */ 275 if (type == FEAT_SP && dccp_feat_clone_sp_val(&new->val,
254 rc = dccp_feat_reconcile(sk, opt, val, len); 276 original->val.sp.vec,
255 break; 277 original->val.sp.len)) {
278 kfree(new);
279 return NULL;
256 } 280 }
281 return new;
282}
257 283
258 /* We didn't deal with the change. This can happen if we have no 284static void dccp_feat_entry_destructor(struct dccp_feat_entry *entry)
259 * preference list for the feature. In fact, it just shouldn't 285{
260 * happen---if we understand a feature, we should have a preference list 286 if (entry != NULL) {
261 * with at least the default value. 287 dccp_feat_val_destructor(entry->feat_num, &entry->val);
262 */ 288 kfree(entry);
263 BUG_ON(rc == 1); 289 }
290}
264 291
265 return rc; 292/*
293 * List management functions
294 *
295 * Feature negotiation lists rely on and maintain the following invariants:
296 * - each feat_num in the list is known, i.e. we know its type and default value
297 * - each feat_num/is_local combination is unique (old entries are overwritten)
298 * - SP values are always freshly allocated
299 * - list is sorted in increasing order of feature number (faster lookup)
300 */
301static struct dccp_feat_entry *dccp_feat_list_lookup(struct list_head *fn_list,
302 u8 feat_num, bool is_local)
303{
304 struct dccp_feat_entry *entry;
305
306 list_for_each_entry(entry, fn_list, node) {
307 if (entry->feat_num == feat_num && entry->is_local == is_local)
308 return entry;
309 else if (entry->feat_num > feat_num)
310 break;
311 }
312 return NULL;
266} 313}
267 314
268static int dccp_feat_nn(struct sock *sk, u8 type, u8 feature, u8 *val, u8 len) 315/**
316 * dccp_feat_entry_new - Central list update routine (called by all others)
317 * @head: list to add to
318 * @feat: feature number
319 * @local: whether the local (1) or remote feature with number @feat is meant
320 * This is the only constructor and serves to ensure the above invariants.
321 */
322static struct dccp_feat_entry *
323 dccp_feat_entry_new(struct list_head *head, u8 feat, bool local)
269{ 324{
270 struct dccp_opt_pend *opt; 325 struct dccp_feat_entry *entry;
271 struct dccp_minisock *dmsk = dccp_msk(sk); 326
272 u8 *copy; 327 list_for_each_entry(entry, head, node)
273 int rc; 328 if (entry->feat_num == feat && entry->is_local == local) {
329 dccp_feat_val_destructor(entry->feat_num, &entry->val);
330 return entry;
331 } else if (entry->feat_num > feat) {
332 head = &entry->node;
333 break;
334 }
274 335
275 /* NN features must be Change L (sec. 6.3.2) */ 336 entry = kmalloc(sizeof(*entry), gfp_any());
276 if (type != DCCPO_CHANGE_L) { 337 if (entry != NULL) {
277 dccp_pr_debug("received %s for NN feature %d\n", 338 entry->feat_num = feat;
278 dccp_feat_typename(type), feature); 339 entry->is_local = local;
279 return -EFAULT; 340 list_add_tail(&entry->node, head);
280 } 341 }
342 return entry;
343}
281 344
282 /* XXX sanity check opt val */ 345/**
346 * dccp_feat_push_change - Add/overwrite a Change option in the list
347 * @fn_list: feature-negotiation list to update
348 * @feat: one of %dccp_feature_numbers
349 * @local: whether local (1) or remote (0) @feat_num is meant
350 * @needs_mandatory: whether to use Mandatory feature negotiation options
351 * @fval: pointer to NN/SP value to be inserted (will be copied)
352 */
353static int dccp_feat_push_change(struct list_head *fn_list, u8 feat, u8 local,
354 u8 mandatory, dccp_feat_val *fval)
355{
356 struct dccp_feat_entry *new = dccp_feat_entry_new(fn_list, feat, local);
283 357
284 /* copy option so we can confirm it */ 358 if (new == NULL)
285 opt = kzalloc(sizeof(*opt), GFP_ATOMIC);
286 if (opt == NULL)
287 return -ENOMEM; 359 return -ENOMEM;
288 360
289 copy = kmemdup(val, len, GFP_ATOMIC); 361 new->feat_num = feat;
290 if (copy == NULL) { 362 new->is_local = local;
291 kfree(opt); 363 new->state = FEAT_INITIALISING;
292 return -ENOMEM; 364 new->needs_confirm = 0;
293 } 365 new->empty_confirm = 0;
366 new->val = *fval;
367 new->needs_mandatory = mandatory;
294 368
295 opt->dccpop_type = DCCPO_CONFIRM_R; /* NN can only confirm R */ 369 return 0;
296 opt->dccpop_feat = feature; 370}
297 opt->dccpop_val = copy;
298 opt->dccpop_len = len;
299 371
300 /* change feature */ 372/**
301 rc = dccp_feat_update(sk, type, feature, *val); 373 * dccp_feat_push_confirm - Add a Confirm entry to the FN list
302 if (rc) { 374 * @fn_list: feature-negotiation list to add to
303 kfree(opt->dccpop_val); 375 * @feat: one of %dccp_feature_numbers
304 kfree(opt); 376 * @local: whether local (1) or remote (0) @feat_num is being confirmed
305 return rc; 377 * @fval: pointer to NN/SP value to be inserted or NULL
306 } 378 * Returns 0 on success, a Reset code for further processing otherwise.
379 */
380static int dccp_feat_push_confirm(struct list_head *fn_list, u8 feat, u8 local,
381 dccp_feat_val *fval)
382{
383 struct dccp_feat_entry *new = dccp_feat_entry_new(fn_list, feat, local);
307 384
308 dccp_feat_debug(type, feature, *copy); 385 if (new == NULL)
386 return DCCP_RESET_CODE_TOO_BUSY;
309 387
310 list_add_tail(&opt->dccpop_node, &dmsk->dccpms_conf); 388 new->feat_num = feat;
389 new->is_local = local;
390 new->state = FEAT_STABLE; /* transition in 6.6.2 */
391 new->needs_confirm = 1;
392 new->empty_confirm = (fval == NULL);
393 new->val.nn = 0; /* zeroes the whole structure */
394 if (!new->empty_confirm)
395 new->val = *fval;
396 new->needs_mandatory = 0;
311 397
312 return 0; 398 return 0;
313} 399}
314 400
315static void dccp_feat_empty_confirm(struct dccp_minisock *dmsk, 401static int dccp_push_empty_confirm(struct list_head *fn_list, u8 feat, u8 local)
316 u8 type, u8 feature)
317{ 402{
318 /* XXX check if other confirms for that are queued and recycle slot */ 403 return dccp_feat_push_confirm(fn_list, feat, local, NULL);
319 struct dccp_opt_pend *opt = kzalloc(sizeof(*opt), GFP_ATOMIC); 404}
320 405
321 if (opt == NULL) { 406static inline void dccp_feat_list_pop(struct dccp_feat_entry *entry)
322 /* XXX what do we do? Ignoring should be fine. It's a change 407{
323 * after all =P 408 list_del(&entry->node);
324 */ 409 dccp_feat_entry_destructor(entry);
325 return; 410}
326 }
327 411
328 switch (type) { 412void dccp_feat_list_purge(struct list_head *fn_list)
329 case DCCPO_CHANGE_L: 413{
330 opt->dccpop_type = DCCPO_CONFIRM_R; 414 struct dccp_feat_entry *entry, *next;
331 break; 415
332 case DCCPO_CHANGE_R: 416 list_for_each_entry_safe(entry, next, fn_list, node)
333 opt->dccpop_type = DCCPO_CONFIRM_L; 417 dccp_feat_entry_destructor(entry);
334 break; 418 INIT_LIST_HEAD(fn_list);
335 default: 419}
336 DCCP_WARN("invalid type %d\n", type); 420EXPORT_SYMBOL_GPL(dccp_feat_list_purge);
337 kfree(opt); 421
338 return; 422/* generate @to as full clone of @from - @to must not contain any nodes */
423int dccp_feat_clone_list(struct list_head const *from, struct list_head *to)
424{
425 struct dccp_feat_entry *entry, *new;
426
427 INIT_LIST_HEAD(to);
428 list_for_each_entry(entry, from, node) {
429 new = dccp_feat_clone_entry(entry);
430 if (new == NULL)
431 goto cloning_failed;
432 list_add_tail(&new->node, to);
339 } 433 }
340 opt->dccpop_feat = feature; 434 return 0;
341 opt->dccpop_val = NULL; 435
342 opt->dccpop_len = 0; 436cloning_failed:
437 dccp_feat_list_purge(to);
438 return -ENOMEM;
439}
343 440
344 /* change feature */ 441/**
345 dccp_pr_debug("Empty %s(%d)\n", dccp_feat_typename(type), feature); 442 * dccp_feat_valid_nn_length - Enforce length constraints on NN options
443 * Length is between 0 and %DCCP_OPTVAL_MAXLEN. Used for outgoing packets only,
444 * incoming options are accepted as long as their values are valid.
445 */
446static u8 dccp_feat_valid_nn_length(u8 feat_num)
447{
448 if (feat_num == DCCPF_ACK_RATIO) /* RFC 4340, 11.3 and 6.6.8 */
449 return 2;
450 if (feat_num == DCCPF_SEQUENCE_WINDOW) /* RFC 4340, 7.5.2 and 6.5 */
451 return 6;
452 return 0;
453}
346 454
347 list_add_tail(&opt->dccpop_node, &dmsk->dccpms_conf); 455static u8 dccp_feat_is_valid_nn_val(u8 feat_num, u64 val)
456{
457 switch (feat_num) {
458 case DCCPF_ACK_RATIO:
459 return val <= DCCPF_ACK_RATIO_MAX;
460 case DCCPF_SEQUENCE_WINDOW:
461 return val >= DCCPF_SEQ_WMIN && val <= DCCPF_SEQ_WMAX;
462 }
463 return 0; /* feature unknown - so we can't tell */
348} 464}
349 465
350static void dccp_feat_flush_confirm(struct sock *sk) 466/* check that SP values are within the ranges defined in RFC 4340 */
467static u8 dccp_feat_is_valid_sp_val(u8 feat_num, u8 val)
351{ 468{
352 struct dccp_minisock *dmsk = dccp_msk(sk); 469 switch (feat_num) {
353 /* Check if there is anything to confirm in the first place */ 470 case DCCPF_CCID:
354 int yes = !list_empty(&dmsk->dccpms_conf); 471 return val == DCCPC_CCID2 || val == DCCPC_CCID3;
472 /* Type-check Boolean feature values: */
473 case DCCPF_SHORT_SEQNOS:
474 case DCCPF_ECN_INCAPABLE:
475 case DCCPF_SEND_ACK_VECTOR:
476 case DCCPF_SEND_NDP_COUNT:
477 case DCCPF_DATA_CHECKSUM:
478 case DCCPF_SEND_LEV_RATE:
479 return val < 2;
480 case DCCPF_MIN_CSUM_COVER:
481 return val < 16;
482 }
483 return 0; /* feature unknown */
484}
355 485
356 if (!yes) { 486static u8 dccp_feat_sp_list_ok(u8 feat_num, u8 const *sp_list, u8 sp_len)
357 struct dccp_opt_pend *opt; 487{
488 if (sp_list == NULL || sp_len < 1)
489 return 0;
490 while (sp_len--)
491 if (!dccp_feat_is_valid_sp_val(feat_num, *sp_list++))
492 return 0;
493 return 1;
494}
358 495
359 list_for_each_entry(opt, &dmsk->dccpms_pending, dccpop_node) { 496/**
360 if (opt->dccpop_conf) { 497 * dccp_feat_insert_opts - Generate FN options from current list state
361 yes = 1; 498 * @skb: next sk_buff to be sent to the peer
362 break; 499 * @dp: for client during handshake and general negotiation
500 * @dreq: used by the server only (all Changes/Confirms in LISTEN/RESPOND)
501 */
502int dccp_feat_insert_opts(struct dccp_sock *dp, struct dccp_request_sock *dreq,
503 struct sk_buff *skb)
504{
505 struct list_head *fn = dreq ? &dreq->dreq_featneg : &dp->dccps_featneg;
506 struct dccp_feat_entry *pos, *next;
507 u8 opt, type, len, *ptr, nn_in_nbo[DCCP_OPTVAL_MAXLEN];
508 bool rpt;
509
510 /* put entries into @skb in the order they appear in the list */
511 list_for_each_entry_safe_reverse(pos, next, fn, node) {
512 opt = dccp_feat_genopt(pos);
513 type = dccp_feat_type(pos->feat_num);
514 rpt = false;
515
516 if (pos->empty_confirm) {
517 len = 0;
518 ptr = NULL;
519 } else {
520 if (type == FEAT_SP) {
521 len = pos->val.sp.len;
522 ptr = pos->val.sp.vec;
523 rpt = pos->needs_confirm;
524 } else if (type == FEAT_NN) {
525 len = dccp_feat_valid_nn_length(pos->feat_num);
526 ptr = nn_in_nbo;
527 dccp_encode_value_var(pos->val.nn, ptr, len);
528 } else {
529 DCCP_BUG("unknown feature %u", pos->feat_num);
530 return -1;
363 } 531 }
364 } 532 }
533
534 if (dccp_insert_fn_opt(skb, opt, pos->feat_num, ptr, len, rpt))
535 return -1;
536 if (pos->needs_mandatory && dccp_insert_option_mandatory(skb))
537 return -1;
538 /*
539 * Enter CHANGING after transmitting the Change option (6.6.2).
540 */
541 if (pos->state == FEAT_INITIALISING)
542 pos->state = FEAT_CHANGING;
365 } 543 }
544 return 0;
545}
366 546
367 if (!yes) 547/**
368 return; 548 * __feat_register_nn - Register new NN value on socket
549 * @fn: feature-negotiation list to register with
550 * @feat: an NN feature from %dccp_feature_numbers
551 * @mandatory: use Mandatory option if 1
552 * @nn_val: value to register (restricted to 4 bytes)
553 * Note that NN features are local by definition (RFC 4340, 6.3.2).
554 */
555static int __feat_register_nn(struct list_head *fn, u8 feat,
556 u8 mandatory, u64 nn_val)
557{
558 dccp_feat_val fval = { .nn = nn_val };
369 559
370 /* OK there is something to confirm... */ 560 if (dccp_feat_type(feat) != FEAT_NN ||
371 /* XXX check if packet is in flight? Send delayed ack?? */ 561 !dccp_feat_is_valid_nn_val(feat, nn_val))
372 if (sk->sk_state == DCCP_OPEN) 562 return -EINVAL;
373 dccp_send_ack(sk); 563
564 /* Don't bother with default values, they will be activated anyway. */
565 if (nn_val - (u64)dccp_feat_default_value(feat) == 0)
566 return 0;
567
568 return dccp_feat_push_change(fn, feat, 1, mandatory, &fval);
374} 569}
375 570
376int dccp_feat_change_recv(struct sock *sk, u8 type, u8 feature, u8 *val, u8 len) 571/**
572 * __feat_register_sp - Register new SP value/list on socket
573 * @fn: feature-negotiation list to register with
574 * @feat: an SP feature from %dccp_feature_numbers
575 * @is_local: whether the local (1) or the remote (0) @feat is meant
576 * @mandatory: use Mandatory option if 1
577 * @sp_val: SP value followed by optional preference list
578 * @sp_len: length of @sp_val in bytes
579 */
580static int __feat_register_sp(struct list_head *fn, u8 feat, u8 is_local,
581 u8 mandatory, u8 const *sp_val, u8 sp_len)
377{ 582{
378 int rc; 583 dccp_feat_val fval;
379 584
380 dccp_feat_debug(type, feature, *val); 585 if (dccp_feat_type(feat) != FEAT_SP ||
586 !dccp_feat_sp_list_ok(feat, sp_val, sp_len))
587 return -EINVAL;
381 588
382 /* figure out if it's SP or NN feature */ 589 /* Avoid negotiating alien CCIDs by only advertising supported ones */
383 switch (feature) { 590 if (feat == DCCPF_CCID && !ccid_support_check(sp_val, sp_len))
384 /* deal with SP features */ 591 return -EOPNOTSUPP;
385 case DCCPF_CCID:
386 rc = dccp_feat_sp(sk, type, feature, val, len);
387 break;
388 592
389 /* deal with NN features */ 593 if (dccp_feat_clone_sp_val(&fval, sp_val, sp_len))
390 case DCCPF_ACK_RATIO: 594 return -ENOMEM;
391 rc = dccp_feat_nn(sk, type, feature, val, len);
392 break;
393 595
394 /* XXX implement other features */ 596 return dccp_feat_push_change(fn, feat, is_local, mandatory, &fval);
395 default: 597}
396 dccp_pr_debug("UNIMPLEMENTED: not handling %s(%d, ...)\n",
397 dccp_feat_typename(type), feature);
398 rc = -EFAULT;
399 break;
400 }
401 598
402 /* check if there were problems changing features */ 599/**
403 if (rc) { 600 * dccp_feat_register_sp - Register requests to change SP feature values
404 /* If we don't agree on SP, we sent a confirm for old value. 601 * @sk: client or listening socket
405 * However we propagate rc to caller in case option was 602 * @feat: one of %dccp_feature_numbers
406 * mandatory 603 * @is_local: whether the local (1) or remote (0) @feat is meant
604 * @list: array of preferred values, in descending order of preference
605 * @len: length of @list in bytes
606 */
607int dccp_feat_register_sp(struct sock *sk, u8 feat, u8 is_local,
608 u8 const *list, u8 len)
609{ /* any changes must be registered before establishing the connection */
610 if (sk->sk_state != DCCP_CLOSED)
611 return -EISCONN;
612 if (dccp_feat_type(feat) != FEAT_SP)
613 return -EINVAL;
614 return __feat_register_sp(&dccp_sk(sk)->dccps_featneg, feat, is_local,
615 0, list, len);
616}
617
618/* Analogous to dccp_feat_register_sp(), but for non-negotiable values */
619int dccp_feat_register_nn(struct sock *sk, u8 feat, u64 val)
620{
621 /* any changes must be registered before establishing the connection */
622 if (sk->sk_state != DCCP_CLOSED)
623 return -EISCONN;
624 if (dccp_feat_type(feat) != FEAT_NN)
625 return -EINVAL;
626 return __feat_register_nn(&dccp_sk(sk)->dccps_featneg, feat, 0, val);
627}
628
629/*
630 * Tracking features whose value depend on the choice of CCID
631 *
632 * This is designed with an extension in mind so that a list walk could be done
633 * before activating any features. However, the existing framework was found to
634 * work satisfactorily up until now, the automatic verification is left open.
635 * When adding new CCIDs, add a corresponding dependency table here.
636 */
637static const struct ccid_dependency *dccp_feat_ccid_deps(u8 ccid, bool is_local)
638{
639 static const struct ccid_dependency ccid2_dependencies[2][2] = {
640 /*
641 * CCID2 mandates Ack Vectors (RFC 4341, 4.): as CCID is a TX
642 * feature and Send Ack Vector is an RX feature, `is_local'
643 * needs to be reversed.
407 */ 644 */
408 if (rc != DCCP_FEAT_SP_NOAGREE) 645 { /* Dependencies of the receiver-side (remote) CCID2 */
409 dccp_feat_empty_confirm(dccp_msk(sk), type, feature); 646 {
647 .dependent_feat = DCCPF_SEND_ACK_VECTOR,
648 .is_local = true,
649 .is_mandatory = true,
650 .val = 1
651 },
652 { 0, 0, 0, 0 }
653 },
654 { /* Dependencies of the sender-side (local) CCID2 */
655 {
656 .dependent_feat = DCCPF_SEND_ACK_VECTOR,
657 .is_local = false,
658 .is_mandatory = true,
659 .val = 1
660 },
661 { 0, 0, 0, 0 }
662 }
663 };
664 static const struct ccid_dependency ccid3_dependencies[2][5] = {
665 { /*
666 * Dependencies of the receiver-side CCID3
667 */
668 { /* locally disable Ack Vectors */
669 .dependent_feat = DCCPF_SEND_ACK_VECTOR,
670 .is_local = true,
671 .is_mandatory = false,
672 .val = 0
673 },
674 { /* see below why Send Loss Event Rate is on */
675 .dependent_feat = DCCPF_SEND_LEV_RATE,
676 .is_local = true,
677 .is_mandatory = true,
678 .val = 1
679 },
680 { /* NDP Count is needed as per RFC 4342, 6.1.1 */
681 .dependent_feat = DCCPF_SEND_NDP_COUNT,
682 .is_local = false,
683 .is_mandatory = true,
684 .val = 1
685 },
686 { 0, 0, 0, 0 },
687 },
688 { /*
689 * CCID3 at the TX side: we request that the HC-receiver
690 * will not send Ack Vectors (they will be ignored, so
691 * Mandatory is not set); we enable Send Loss Event Rate
692 * (Mandatory since the implementation does not support
693 * the Loss Intervals option of RFC 4342, 8.6).
694 * The last two options are for peer's information only.
695 */
696 {
697 .dependent_feat = DCCPF_SEND_ACK_VECTOR,
698 .is_local = false,
699 .is_mandatory = false,
700 .val = 0
701 },
702 {
703 .dependent_feat = DCCPF_SEND_LEV_RATE,
704 .is_local = false,
705 .is_mandatory = true,
706 .val = 1
707 },
708 { /* this CCID does not support Ack Ratio */
709 .dependent_feat = DCCPF_ACK_RATIO,
710 .is_local = true,
711 .is_mandatory = false,
712 .val = 0
713 },
714 { /* tell receiver we are sending NDP counts */
715 .dependent_feat = DCCPF_SEND_NDP_COUNT,
716 .is_local = true,
717 .is_mandatory = false,
718 .val = 1
719 },
720 { 0, 0, 0, 0 }
721 }
722 };
723 switch (ccid) {
724 case DCCPC_CCID2:
725 return ccid2_dependencies[is_local];
726 case DCCPC_CCID3:
727 return ccid3_dependencies[is_local];
728 default:
729 return NULL;
410 } 730 }
731}
411 732
412 /* generate the confirm [if required] */ 733/**
413 dccp_feat_flush_confirm(sk); 734 * dccp_feat_propagate_ccid - Resolve dependencies of features on choice of CCID
414 735 * @fn: feature-negotiation list to update
736 * @id: CCID number to track
737 * @is_local: whether TX CCID (1) or RX CCID (0) is meant
738 * This function needs to be called after registering all other features.
739 */
740static int dccp_feat_propagate_ccid(struct list_head *fn, u8 id, bool is_local)
741{
742 const struct ccid_dependency *table = dccp_feat_ccid_deps(id, is_local);
743 int i, rc = (table == NULL);
744
745 for (i = 0; rc == 0 && table[i].dependent_feat != DCCPF_RESERVED; i++)
746 if (dccp_feat_type(table[i].dependent_feat) == FEAT_SP)
747 rc = __feat_register_sp(fn, table[i].dependent_feat,
748 table[i].is_local,
749 table[i].is_mandatory,
750 &table[i].val, 1);
751 else
752 rc = __feat_register_nn(fn, table[i].dependent_feat,
753 table[i].is_mandatory,
754 table[i].val);
415 return rc; 755 return rc;
416} 756}
417 757
418EXPORT_SYMBOL_GPL(dccp_feat_change_recv); 758/**
759 * dccp_feat_finalise_settings - Finalise settings before starting negotiation
760 * @dp: client or listening socket (settings will be inherited)
761 * This is called after all registrations (socket initialisation, sysctls, and
762 * sockopt calls), and before sending the first packet containing Change options
763 * (ie. client-Request or server-Response), to ensure internal consistency.
764 */
765int dccp_feat_finalise_settings(struct dccp_sock *dp)
766{
767 struct list_head *fn = &dp->dccps_featneg;
768 struct dccp_feat_entry *entry;
769 int i = 2, ccids[2] = { -1, -1 };
419 770
420int dccp_feat_confirm_recv(struct sock *sk, u8 type, u8 feature, 771 /*
421 u8 *val, u8 len) 772 * Propagating CCIDs:
773 * 1) not useful to propagate CCID settings if this host advertises more
774 * than one CCID: the choice of CCID may still change - if this is
775 * the client, or if this is the server and the client sends
776 * singleton CCID values.
777 * 2) since is that propagate_ccid changes the list, we defer changing
778 * the sorted list until after the traversal.
779 */
780 list_for_each_entry(entry, fn, node)
781 if (entry->feat_num == DCCPF_CCID && entry->val.sp.len == 1)
782 ccids[entry->is_local] = entry->val.sp.vec[0];
783 while (i--)
784 if (ccids[i] > 0 && dccp_feat_propagate_ccid(fn, ccids[i], i))
785 return -1;
786 return 0;
787}
788
789/**
790 * dccp_feat_server_ccid_dependencies - Resolve CCID-dependent features
791 * It is the server which resolves the dependencies once the CCID has been
792 * fully negotiated. If no CCID has been negotiated, it uses the default CCID.
793 */
794int dccp_feat_server_ccid_dependencies(struct dccp_request_sock *dreq)
422{ 795{
423 u8 t; 796 struct list_head *fn = &dreq->dreq_featneg;
424 struct dccp_opt_pend *opt; 797 struct dccp_feat_entry *entry;
425 struct dccp_minisock *dmsk = dccp_msk(sk); 798 u8 is_local, ccid;
426 int found = 0;
427 int all_confirmed = 1;
428 799
429 dccp_feat_debug(type, feature, *val); 800 for (is_local = 0; is_local <= 1; is_local++) {
801 entry = dccp_feat_list_lookup(fn, DCCPF_CCID, is_local);
430 802
431 /* locate our change request */ 803 if (entry != NULL && !entry->empty_confirm)
432 switch (type) { 804 ccid = entry->val.sp.vec[0];
433 case DCCPO_CONFIRM_L: t = DCCPO_CHANGE_R; break; 805 else
434 case DCCPO_CONFIRM_R: t = DCCPO_CHANGE_L; break; 806 ccid = dccp_feat_default_value(DCCPF_CCID);
435 default: DCCP_WARN("invalid type %d\n", type);
436 return 1;
437 807
808 if (dccp_feat_propagate_ccid(fn, ccid, is_local))
809 return -1;
438 } 810 }
439 /* XXX sanity check feature value */ 811 return 0;
812}
440 813
441 list_for_each_entry(opt, &dmsk->dccpms_pending, dccpop_node) { 814/* Select the first entry in @servlist that also occurs in @clilist (6.3.1) */
442 if (!opt->dccpop_conf && opt->dccpop_type == t && 815static int dccp_feat_preflist_match(u8 *servlist, u8 slen, u8 *clilist, u8 clen)
443 opt->dccpop_feat == feature) { 816{
444 found = 1; 817 u8 c, s;
445 dccp_pr_debug("feature %d found\n", opt->dccpop_feat);
446 818
447 /* XXX do sanity check */ 819 for (s = 0; s < slen; s++)
820 for (c = 0; c < clen; c++)
821 if (servlist[s] == clilist[c])
822 return servlist[s];
823 return -1;
824}
448 825
449 opt->dccpop_conf = 1; 826/**
827 * dccp_feat_prefer - Move preferred entry to the start of array
828 * Reorder the @array_len elements in @array so that @preferred_value comes
829 * first. Returns >0 to indicate that @preferred_value does occur in @array.
830 */
831static u8 dccp_feat_prefer(u8 preferred_value, u8 *array, u8 array_len)
832{
833 u8 i, does_occur = 0;
450 834
451 /* We got a confirmation---change the option */ 835 if (array != NULL) {
452 dccp_feat_update(sk, opt->dccpop_type, 836 for (i = 0; i < array_len; i++)
453 opt->dccpop_feat, *val); 837 if (array[i] == preferred_value) {
838 array[i] = array[0];
839 does_occur++;
840 }
841 if (does_occur)
842 array[0] = preferred_value;
843 }
844 return does_occur;
845}
454 846
455 /* XXX check the return value of dccp_feat_update */ 847/**
456 break; 848 * dccp_feat_reconcile - Reconcile SP preference lists
457 } 849 * @fval: SP list to reconcile into
850 * @arr: received SP preference list
851 * @len: length of @arr in bytes
852 * @is_server: whether this side is the server (and @fv is the server's list)
853 * @reorder: whether to reorder the list in @fv after reconciling with @arr
854 * When successful, > 0 is returned and the reconciled list is in @fval.
855 * A value of 0 means that negotiation failed (no shared entry).
856 */
857static int dccp_feat_reconcile(dccp_feat_val *fv, u8 *arr, u8 len,
858 bool is_server, bool reorder)
859{
860 int rc;
458 861
459 if (!opt->dccpop_conf) 862 if (!fv->sp.vec || !arr) {
460 all_confirmed = 0; 863 DCCP_CRIT("NULL feature value or array");
864 return 0;
461 } 865 }
462 866
463 /* fix re-transmit timer */ 867 if (is_server)
464 /* XXX gotta make sure that no option negotiation occurs during 868 rc = dccp_feat_preflist_match(fv->sp.vec, fv->sp.len, arr, len);
465 * connection shutdown. Consider that the CLOSEREQ is sent and timer is 869 else
466 * on. if all options are confirmed it might kill timer which should 870 rc = dccp_feat_preflist_match(arr, len, fv->sp.vec, fv->sp.len);
467 * remain alive until close is received.
468 */
469 if (all_confirmed) {
470 dccp_pr_debug("clear feat negotiation timer %p\n", sk);
471 inet_csk_clear_xmit_timer(sk, ICSK_TIME_RETRANS);
472 }
473 871
474 if (!found) 872 if (!reorder)
475 dccp_pr_debug("%s(%d, ...) never requested\n", 873 return rc;
476 dccp_feat_typename(type), feature); 874 if (rc < 0)
477 return 0; 875 return 0;
478}
479 876
480EXPORT_SYMBOL_GPL(dccp_feat_confirm_recv); 877 /*
878 * Reorder list: used for activating features and in dccp_insert_fn_opt.
879 */
880 return dccp_feat_prefer(rc, fv->sp.vec, fv->sp.len);
881}
481 882
482void dccp_feat_clean(struct dccp_minisock *dmsk) 883/**
884 * dccp_feat_change_recv - Process incoming ChangeL/R options
885 * @fn: feature-negotiation list to update
886 * @is_mandatory: whether the Change was preceded by a Mandatory option
887 * @opt: %DCCPO_CHANGE_L or %DCCPO_CHANGE_R
888 * @feat: one of %dccp_feature_numbers
889 * @val: NN value or SP value/preference list
890 * @len: length of @val in bytes
891 * @server: whether this node is the server (1) or the client (0)
892 */
893static u8 dccp_feat_change_recv(struct list_head *fn, u8 is_mandatory, u8 opt,
894 u8 feat, u8 *val, u8 len, const bool server)
483{ 895{
484 struct dccp_opt_pend *opt, *next; 896 u8 defval, type = dccp_feat_type(feat);
897 const bool local = (opt == DCCPO_CHANGE_R);
898 struct dccp_feat_entry *entry;
899 dccp_feat_val fval;
485 900
486 list_for_each_entry_safe(opt, next, &dmsk->dccpms_pending, 901 if (len == 0 || type == FEAT_UNKNOWN) /* 6.1 and 6.6.8 */
487 dccpop_node) { 902 goto unknown_feature_or_value;
488 BUG_ON(opt->dccpop_val == NULL); 903
489 kfree(opt->dccpop_val); 904 /*
905 * Negotiation of NN features: Change R is invalid, so there is no
906 * simultaneous negotiation; hence we do not look up in the list.
907 */
908 if (type == FEAT_NN) {
909 if (local || len > sizeof(fval.nn))
910 goto unknown_feature_or_value;
911
912 /* 6.3.2: "The feature remote MUST accept any valid value..." */
913 fval.nn = dccp_decode_value_var(val, len);
914 if (!dccp_feat_is_valid_nn_val(feat, fval.nn))
915 goto unknown_feature_or_value;
916
917 return dccp_feat_push_confirm(fn, feat, local, &fval);
918 }
919
920 /*
921 * Unidirectional/simultaneous negotiation of SP features (6.3.1)
922 */
923 entry = dccp_feat_list_lookup(fn, feat, local);
924 if (entry == NULL) {
925 /*
926 * No particular preferences have been registered. We deal with
927 * this situation by assuming that all valid values are equally
928 * acceptable, and apply the following checks:
929 * - if the peer's list is a singleton, we accept a valid value;
930 * - if we are the server, we first try to see if the peer (the
931 * client) advertises the default value. If yes, we use it,
932 * otherwise we accept the preferred value;
933 * - else if we are the client, we use the first list element.
934 */
935 if (dccp_feat_clone_sp_val(&fval, val, 1))
936 return DCCP_RESET_CODE_TOO_BUSY;
937
938 if (len > 1 && server) {
939 defval = dccp_feat_default_value(feat);
940 if (dccp_feat_preflist_match(&defval, 1, val, len) > -1)
941 fval.sp.vec[0] = defval;
942 } else if (!dccp_feat_is_valid_sp_val(feat, fval.sp.vec[0])) {
943 kfree(fval.sp.vec);
944 goto unknown_feature_or_value;
945 }
490 946
491 if (opt->dccpop_sc != NULL) { 947 /* Treat unsupported CCIDs like invalid values */
492 BUG_ON(opt->dccpop_sc->dccpoc_val == NULL); 948 if (feat == DCCPF_CCID && !ccid_support_check(fval.sp.vec, 1)) {
493 kfree(opt->dccpop_sc->dccpoc_val); 949 kfree(fval.sp.vec);
494 kfree(opt->dccpop_sc); 950 goto not_valid_or_not_known;
495 } 951 }
496 952
497 kfree(opt); 953 return dccp_feat_push_confirm(fn, feat, local, &fval);
954
955 } else if (entry->state == FEAT_UNSTABLE) { /* 6.6.2 */
956 return 0;
498 } 957 }
499 INIT_LIST_HEAD(&dmsk->dccpms_pending);
500 958
501 list_for_each_entry_safe(opt, next, &dmsk->dccpms_conf, dccpop_node) { 959 if (dccp_feat_reconcile(&entry->val, val, len, server, true)) {
502 BUG_ON(opt == NULL); 960 entry->empty_confirm = 0;
503 if (opt->dccpop_val != NULL) 961 } else if (is_mandatory) {
504 kfree(opt->dccpop_val); 962 return DCCP_RESET_CODE_MANDATORY_ERROR;
505 kfree(opt); 963 } else if (entry->state == FEAT_INITIALISING) {
964 /*
965 * Failed simultaneous negotiation (server only): try to `save'
966 * the connection by checking whether entry contains the default
967 * value for @feat. If yes, send an empty Confirm to signal that
968 * the received Change was not understood - which implies using
969 * the default value.
970 * If this also fails, we use Reset as the last resort.
971 */
972 WARN_ON(!server);
973 defval = dccp_feat_default_value(feat);
974 if (!dccp_feat_reconcile(&entry->val, &defval, 1, server, true))
975 return DCCP_RESET_CODE_OPTION_ERROR;
976 entry->empty_confirm = 1;
506 } 977 }
507 INIT_LIST_HEAD(&dmsk->dccpms_conf); 978 entry->needs_confirm = 1;
508} 979 entry->needs_mandatory = 0;
980 entry->state = FEAT_STABLE;
981 return 0;
509 982
510EXPORT_SYMBOL_GPL(dccp_feat_clean); 983unknown_feature_or_value:
984 if (!is_mandatory)
985 return dccp_push_empty_confirm(fn, feat, local);
511 986
512/* this is to be called only when a listening sock creates its child. It is 987not_valid_or_not_known:
513 * assumed by the function---the confirm is not duplicated, but rather it is 988 return is_mandatory ? DCCP_RESET_CODE_MANDATORY_ERROR
514 * "passed on". 989 : DCCP_RESET_CODE_OPTION_ERROR;
990}
991
992/**
993 * dccp_feat_confirm_recv - Process received Confirm options
994 * @fn: feature-negotiation list to update
995 * @is_mandatory: whether @opt was preceded by a Mandatory option
996 * @opt: %DCCPO_CONFIRM_L or %DCCPO_CONFIRM_R
997 * @feat: one of %dccp_feature_numbers
998 * @val: NN value or SP value/preference list
999 * @len: length of @val in bytes
1000 * @server: whether this node is server (1) or client (0)
515 */ 1001 */
516int dccp_feat_clone(struct sock *oldsk, struct sock *newsk) 1002static u8 dccp_feat_confirm_recv(struct list_head *fn, u8 is_mandatory, u8 opt,
1003 u8 feat, u8 *val, u8 len, const bool server)
517{ 1004{
518 struct dccp_minisock *olddmsk = dccp_msk(oldsk); 1005 u8 *plist, plen, type = dccp_feat_type(feat);
519 struct dccp_minisock *newdmsk = dccp_msk(newsk); 1006 const bool local = (opt == DCCPO_CONFIRM_R);
520 struct dccp_opt_pend *opt; 1007 struct dccp_feat_entry *entry = dccp_feat_list_lookup(fn, feat, local);
521 int rc = 0;
522 1008
523 INIT_LIST_HEAD(&newdmsk->dccpms_pending); 1009 if (entry == NULL) { /* nothing queued: ignore or handle error */
524 INIT_LIST_HEAD(&newdmsk->dccpms_conf); 1010 if (is_mandatory && type == FEAT_UNKNOWN)
1011 return DCCP_RESET_CODE_MANDATORY_ERROR;
1012
1013 if (!local && type == FEAT_NN) /* 6.3.2 */
1014 goto confirmation_failed;
1015 return 0;
1016 }
525 1017
526 list_for_each_entry(opt, &olddmsk->dccpms_pending, dccpop_node) { 1018 if (entry->state != FEAT_CHANGING) /* 6.6.2 */
527 struct dccp_opt_pend *newopt; 1019 return 0;
528 /* copy the value of the option */
529 u8 *val = kmemdup(opt->dccpop_val, opt->dccpop_len, GFP_ATOMIC);
530 1020
531 if (val == NULL) 1021 if (len == 0) {
532 goto out_clean; 1022 if (dccp_feat_must_be_understood(feat)) /* 6.6.7 */
1023 goto confirmation_failed;
1024 /*
1025 * Empty Confirm during connection setup: this means reverting
1026 * to the `old' value, which in this case is the default. Since
1027 * we handle default values automatically when no other values
1028 * have been set, we revert to the old value by removing this
1029 * entry from the list.
1030 */
1031 dccp_feat_list_pop(entry);
1032 return 0;
1033 }
533 1034
534 newopt = kmemdup(opt, sizeof(*newopt), GFP_ATOMIC); 1035 if (type == FEAT_NN) {
535 if (newopt == NULL) { 1036 if (len > sizeof(entry->val.nn))
536 kfree(val); 1037 goto confirmation_failed;
537 goto out_clean;
538 }
539 1038
540 /* insert the option */ 1039 if (entry->val.nn == dccp_decode_value_var(val, len))
541 newopt->dccpop_val = val; 1040 goto confirmation_succeeded;
542 list_add_tail(&newopt->dccpop_node, &newdmsk->dccpms_pending);
543 1041
544 /* XXX what happens with backlogs and multiple connections at 1042 DCCP_WARN("Bogus Confirm for non-existing value\n");
545 * once... 1043 goto confirmation_failed;
546 */ 1044 }
547 /* the master socket no longer needs to worry about confirms */
548 opt->dccpop_sc = NULL; /* it's not a memleak---new socket has it */
549 1045
550 /* reset state for a new socket */ 1046 /*
551 opt->dccpop_conf = 0; 1047 * Parsing SP Confirms: the first element of @val is the preferred
1048 * SP value which the peer confirms, the remainder depends on @len.
1049 * Note that only the confirmed value need to be a valid SP value.
1050 */
1051 if (!dccp_feat_is_valid_sp_val(feat, *val))
1052 goto confirmation_failed;
1053
1054 if (len == 1) { /* peer didn't supply a preference list */
1055 plist = val;
1056 plen = len;
1057 } else { /* preferred value + preference list */
1058 plist = val + 1;
1059 plen = len - 1;
552 } 1060 }
553 1061
554 /* XXX not doing anything about the conf queue */ 1062 /* Check whether the peer got the reconciliation right (6.6.8) */
1063 if (dccp_feat_reconcile(&entry->val, plist, plen, server, 0) != *val) {
1064 DCCP_WARN("Confirm selected the wrong value %u\n", *val);
1065 return DCCP_RESET_CODE_OPTION_ERROR;
1066 }
1067 entry->val.sp.vec[0] = *val;
555 1068
556out: 1069confirmation_succeeded:
557 return rc; 1070 entry->state = FEAT_STABLE;
1071 return 0;
558 1072
559out_clean: 1073confirmation_failed:
560 dccp_feat_clean(newdmsk); 1074 DCCP_WARN("Confirmation failed\n");
561 rc = -ENOMEM; 1075 return is_mandatory ? DCCP_RESET_CODE_MANDATORY_ERROR
562 goto out; 1076 : DCCP_RESET_CODE_OPTION_ERROR;
563} 1077}
564 1078
565EXPORT_SYMBOL_GPL(dccp_feat_clone); 1079/**
566 1080 * dccp_feat_parse_options - Process Feature-Negotiation Options
567static int __dccp_feat_init(struct dccp_minisock *dmsk, u8 type, u8 feat, 1081 * @sk: for general use and used by the client during connection setup
568 u8 *val, u8 len) 1082 * @dreq: used by the server during connection setup
1083 * @mandatory: whether @opt was preceded by a Mandatory option
1084 * @opt: %DCCPO_CHANGE_L | %DCCPO_CHANGE_R | %DCCPO_CONFIRM_L | %DCCPO_CONFIRM_R
1085 * @feat: one of %dccp_feature_numbers
1086 * @val: value contents of @opt
1087 * @len: length of @val in bytes
1088 * Returns 0 on success, a Reset code for ending the connection otherwise.
1089 */
1090int dccp_feat_parse_options(struct sock *sk, struct dccp_request_sock *dreq,
1091 u8 mandatory, u8 opt, u8 feat, u8 *val, u8 len)
569{ 1092{
570 int rc = -ENOMEM; 1093 struct dccp_sock *dp = dccp_sk(sk);
571 u8 *copy = kmemdup(val, len, GFP_KERNEL); 1094 struct list_head *fn = dreq ? &dreq->dreq_featneg : &dp->dccps_featneg;
1095 bool server = false;
572 1096
573 if (copy != NULL) { 1097 switch (sk->sk_state) {
574 rc = dccp_feat_change(dmsk, type, feat, copy, len, GFP_KERNEL); 1098 /*
575 if (rc) 1099 * Negotiation during connection setup
576 kfree(copy); 1100 */
1101 case DCCP_LISTEN:
1102 server = true; /* fall through */
1103 case DCCP_REQUESTING:
1104 switch (opt) {
1105 case DCCPO_CHANGE_L:
1106 case DCCPO_CHANGE_R:
1107 return dccp_feat_change_recv(fn, mandatory, opt, feat,
1108 val, len, server);
1109 case DCCPO_CONFIRM_R:
1110 case DCCPO_CONFIRM_L:
1111 return dccp_feat_confirm_recv(fn, mandatory, opt, feat,
1112 val, len, server);
1113 }
577 } 1114 }
578 return rc; 1115 return 0; /* ignore FN options in all other states */
579} 1116}
580 1117
581int dccp_feat_init(struct dccp_minisock *dmsk) 1118int dccp_feat_init(struct sock *sk)
582{ 1119{
1120 struct dccp_sock *dp = dccp_sk(sk);
1121 struct dccp_minisock *dmsk = dccp_msk(sk);
583 int rc; 1122 int rc;
584 1123
585 INIT_LIST_HEAD(&dmsk->dccpms_pending); 1124 INIT_LIST_HEAD(&dmsk->dccpms_pending); /* XXX no longer used */
586 INIT_LIST_HEAD(&dmsk->dccpms_conf); 1125 INIT_LIST_HEAD(&dmsk->dccpms_conf); /* XXX no longer used */
587
588 /* CCID L */
589 rc = __dccp_feat_init(dmsk, DCCPO_CHANGE_L, DCCPF_CCID,
590 &dmsk->dccpms_tx_ccid, 1);
591 if (rc)
592 goto out;
593
594 /* CCID R */
595 rc = __dccp_feat_init(dmsk, DCCPO_CHANGE_R, DCCPF_CCID,
596 &dmsk->dccpms_rx_ccid, 1);
597 if (rc)
598 goto out;
599 1126
600 /* Ack ratio */ 1127 /* Ack ratio */
601 rc = __dccp_feat_init(dmsk, DCCPO_CHANGE_L, DCCPF_ACK_RATIO, 1128 rc = __feat_register_nn(&dp->dccps_featneg, DCCPF_ACK_RATIO, 0,
602 &dmsk->dccpms_ack_ratio, 1); 1129 dp->dccps_l_ack_ratio);
603out:
604 return rc; 1130 return rc;
605} 1131}
606 1132
607EXPORT_SYMBOL_GPL(dccp_feat_init); 1133EXPORT_SYMBOL_GPL(dccp_feat_init);
608 1134
1135int dccp_feat_activate_values(struct sock *sk, struct list_head *fn_list)
1136{
1137 struct dccp_sock *dp = dccp_sk(sk);
1138 struct dccp_feat_entry *cur, *next;
1139 int idx;
1140 dccp_feat_val *fvals[DCCP_FEAT_SUPPORTED_MAX][2] = {
1141 [0 ... DCCP_FEAT_SUPPORTED_MAX-1] = { NULL, NULL }
1142 };
1143
1144 list_for_each_entry(cur, fn_list, node) {
1145 /*
1146 * An empty Confirm means that either an unknown feature type
1147 * or an invalid value was present. In the first case there is
1148 * nothing to activate, in the other the default value is used.
1149 */
1150 if (cur->empty_confirm)
1151 continue;
1152
1153 idx = dccp_feat_index(cur->feat_num);
1154 if (idx < 0) {
1155 DCCP_BUG("Unknown feature %u", cur->feat_num);
1156 goto activation_failed;
1157 }
1158 if (cur->state != FEAT_STABLE) {
1159 DCCP_CRIT("Negotiation of %s %u failed in state %u",
1160 cur->is_local ? "local" : "remote",
1161 cur->feat_num, cur->state);
1162 goto activation_failed;
1163 }
1164 fvals[idx][cur->is_local] = &cur->val;
1165 }
1166
1167 /*
1168 * Activate in decreasing order of index, so that the CCIDs are always
1169 * activated as the last feature. This avoids the case where a CCID
1170 * relies on the initialisation of one or more features that it depends
1171 * on (e.g. Send NDP Count, Send Ack Vector, and Ack Ratio features).
1172 */
1173 for (idx = DCCP_FEAT_SUPPORTED_MAX; --idx >= 0;)
1174 if (__dccp_feat_activate(sk, idx, 0, fvals[idx][0]) ||
1175 __dccp_feat_activate(sk, idx, 1, fvals[idx][1])) {
1176 DCCP_CRIT("Could not activate %d", idx);
1177 goto activation_failed;
1178 }
1179
1180 /* Clean up Change options which have been confirmed already */
1181 list_for_each_entry_safe(cur, next, fn_list, node)
1182 if (!cur->needs_confirm)
1183 dccp_feat_list_pop(cur);
1184
1185 dccp_pr_debug("Activation OK\n");
1186 return 0;
1187
1188activation_failed:
1189 /*
1190 * We clean up everything that may have been allocated, since
1191 * it is difficult to track at which stage negotiation failed.
1192 * This is ok, since all allocation functions below are robust
1193 * against NULL arguments.
1194 */
1195 ccid_hc_rx_delete(dp->dccps_hc_rx_ccid, sk);
1196 ccid_hc_tx_delete(dp->dccps_hc_tx_ccid, sk);
1197 dp->dccps_hc_rx_ccid = dp->dccps_hc_tx_ccid = NULL;
1198 dccp_ackvec_free(dp->dccps_hc_rx_ackvec);
1199 dp->dccps_hc_rx_ackvec = NULL;
1200 return -1;
1201}
1202
609#ifdef CONFIG_IP_DCCP_DEBUG 1203#ifdef CONFIG_IP_DCCP_DEBUG
610const char *dccp_feat_typename(const u8 type) 1204const char *dccp_feat_typename(const u8 type)
611{ 1205{
@@ -639,6 +1233,8 @@ const char *dccp_feat_name(const u8 feat)
639 if (feat > DCCPF_DATA_CHECKSUM && feat < DCCPF_MIN_CCID_SPECIFIC) 1233 if (feat > DCCPF_DATA_CHECKSUM && feat < DCCPF_MIN_CCID_SPECIFIC)
640 return feature_names[DCCPF_RESERVED]; 1234 return feature_names[DCCPF_RESERVED];
641 1235
1236 if (feat == DCCPF_SEND_LEV_RATE)
1237 return "Send Loss Event Rate";
642 if (feat >= DCCPF_MIN_CCID_SPECIFIC) 1238 if (feat >= DCCPF_MIN_CCID_SPECIFIC)
643 return "CCID-specific"; 1239 return "CCID-specific";
644 1240
diff --git a/net/dccp/feat.h b/net/dccp/feat.h
index e272222c7ace..9b46e2a7866e 100644
--- a/net/dccp/feat.h
+++ b/net/dccp/feat.h
@@ -3,17 +3,103 @@
3/* 3/*
4 * net/dccp/feat.h 4 * net/dccp/feat.h
5 * 5 *
6 * An implementation of the DCCP protocol 6 * Feature negotiation for the DCCP protocol (RFC 4340, section 6)
7 * Copyright (c) 2008 Gerrit Renker <gerrit@erg.abdn.ac.uk>
7 * Copyright (c) 2005 Andrea Bittau <a.bittau@cs.ucl.ac.uk> 8 * Copyright (c) 2005 Andrea Bittau <a.bittau@cs.ucl.ac.uk>
8 * 9 *
9 * This program is free software; you can redistribute it and/or modify it 10 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License version 2 as 11 * under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation. 12 * published by the Free Software Foundation.
12 */ 13 */
13
14#include <linux/types.h> 14#include <linux/types.h>
15#include "dccp.h" 15#include "dccp.h"
16 16
17/*
18 * Known limit values
19 */
20/* Ack Ratio takes 2-byte integer values (11.3) */
21#define DCCPF_ACK_RATIO_MAX 0xFFFF
22/* Wmin=32 and Wmax=2^46-1 from 7.5.2 */
23#define DCCPF_SEQ_WMIN 32
24#define DCCPF_SEQ_WMAX 0x3FFFFFFFFFFFull
25/* Maximum number of SP values that fit in a single (Confirm) option */
26#define DCCP_FEAT_MAX_SP_VALS (DCCP_SINGLE_OPT_MAXLEN - 2)
27
28enum dccp_feat_type {
29 FEAT_AT_RX = 1, /* located at RX side of half-connection */
30 FEAT_AT_TX = 2, /* located at TX side of half-connection */
31 FEAT_SP = 4, /* server-priority reconciliation (6.3.1) */
32 FEAT_NN = 8, /* non-negotiable reconciliation (6.3.2) */
33 FEAT_UNKNOWN = 0xFF /* not understood or invalid feature */
34};
35
36enum dccp_feat_state {
37 FEAT_DEFAULT = 0, /* using default values from 6.4 */
38 FEAT_INITIALISING, /* feature is being initialised */
39 FEAT_CHANGING, /* Change sent but not confirmed yet */
40 FEAT_UNSTABLE, /* local modification in state CHANGING */
41 FEAT_STABLE /* both ends (think they) agree */
42};
43
44/**
45 * dccp_feat_val - Container for SP or NN feature values
46 * @nn: single NN value
47 * @sp.vec: single SP value plus optional preference list
48 * @sp.len: length of @sp.vec in bytes
49 */
50typedef union {
51 u64 nn;
52 struct {
53 u8 *vec;
54 u8 len;
55 } sp;
56} dccp_feat_val;
57
58/**
59 * struct feat_entry - Data structure to perform feature negotiation
60 * @val: feature's current value (SP features may have preference list)
61 * @state: feature's current state
62 * @feat_num: one of %dccp_feature_numbers
63 * @needs_mandatory: whether Mandatory options should be sent
64 * @needs_confirm: whether to send a Confirm instead of a Change
65 * @empty_confirm: whether to send an empty Confirm (depends on @needs_confirm)
66 * @is_local: feature location (1) or feature-remote (0)
67 * @node: list pointers, entries arranged in FIFO order
68 */
69struct dccp_feat_entry {
70 dccp_feat_val val;
71 enum dccp_feat_state state:8;
72 u8 feat_num;
73
74 bool needs_mandatory,
75 needs_confirm,
76 empty_confirm,
77 is_local;
78
79 struct list_head node;
80};
81
82static inline u8 dccp_feat_genopt(struct dccp_feat_entry *entry)
83{
84 if (entry->needs_confirm)
85 return entry->is_local ? DCCPO_CONFIRM_L : DCCPO_CONFIRM_R;
86 return entry->is_local ? DCCPO_CHANGE_L : DCCPO_CHANGE_R;
87}
88
89/**
90 * struct ccid_dependency - Track changes resulting from choosing a CCID
91 * @dependent_feat: one of %dccp_feature_numbers
92 * @is_local: local (1) or remote (0) @dependent_feat
93 * @is_mandatory: whether presence of @dependent_feat is mission-critical or not
94 * @val: corresponding default value for @dependent_feat (u8 is sufficient here)
95 */
96struct ccid_dependency {
97 u8 dependent_feat;
98 bool is_local:1,
99 is_mandatory:1;
100 u8 val;
101};
102
17#ifdef CONFIG_IP_DCCP_DEBUG 103#ifdef CONFIG_IP_DCCP_DEBUG
18extern const char *dccp_feat_typename(const u8 type); 104extern const char *dccp_feat_typename(const u8 type);
19extern const char *dccp_feat_name(const u8 feat); 105extern const char *dccp_feat_name(const u8 feat);
@@ -27,14 +113,30 @@ static inline void dccp_feat_debug(const u8 type, const u8 feat, const u8 val)
27#define dccp_feat_debug(type, feat, val) 113#define dccp_feat_debug(type, feat, val)
28#endif /* CONFIG_IP_DCCP_DEBUG */ 114#endif /* CONFIG_IP_DCCP_DEBUG */
29 115
30extern int dccp_feat_change(struct dccp_minisock *dmsk, u8 type, u8 feature, 116extern int dccp_feat_register_sp(struct sock *sk, u8 feat, u8 is_local,
31 u8 *val, u8 len, gfp_t gfp); 117 u8 const *list, u8 len);
32extern int dccp_feat_change_recv(struct sock *sk, u8 type, u8 feature, 118extern int dccp_feat_register_nn(struct sock *sk, u8 feat, u64 val);
33 u8 *val, u8 len); 119extern int dccp_feat_parse_options(struct sock *, struct dccp_request_sock *,
34extern int dccp_feat_confirm_recv(struct sock *sk, u8 type, u8 feature, 120 u8 mand, u8 opt, u8 feat, u8 *val, u8 len);
35 u8 *val, u8 len); 121extern int dccp_feat_clone_list(struct list_head const *, struct list_head *);
36extern void dccp_feat_clean(struct dccp_minisock *dmsk); 122extern int dccp_feat_init(struct sock *sk);
37extern int dccp_feat_clone(struct sock *oldsk, struct sock *newsk); 123
38extern int dccp_feat_init(struct dccp_minisock *dmsk); 124/*
125 * Encoding variable-length options and their maximum length.
126 *
127 * This affects NN options (SP options are all u8) and other variable-length
128 * options (see table 3 in RFC 4340). The limit is currently given the Sequence
129 * Window NN value (sec. 7.5.2) and the NDP count (sec. 7.7) option, all other
130 * options consume less than 6 bytes (timestamps are 4 bytes).
131 * When updating this constant (e.g. due to new internet drafts / RFCs), make
132 * sure that you also update all code which refers to it.
133 */
134#define DCCP_OPTVAL_MAXLEN 6
135
136extern void dccp_encode_value_var(const u64 value, u8 *to, const u8 len);
137extern u64 dccp_decode_value_var(const u8 *bf, const u8 len);
39 138
139extern int dccp_insert_option_mandatory(struct sk_buff *skb);
140extern int dccp_insert_fn_opt(struct sk_buff *skb, u8 type, u8 feat,
141 u8 *val, u8 len, bool repeat_first);
40#endif /* _DCCP_FEAT_H */ 142#endif /* _DCCP_FEAT_H */
diff --git a/net/dccp/input.c b/net/dccp/input.c
index 779d0ed9ae94..5eb443f656c1 100644
--- a/net/dccp/input.c
+++ b/net/dccp/input.c
@@ -163,7 +163,7 @@ static void dccp_event_ack_recv(struct sock *sk, struct sk_buff *skb)
163{ 163{
164 struct dccp_sock *dp = dccp_sk(sk); 164 struct dccp_sock *dp = dccp_sk(sk);
165 165
166 if (dccp_msk(sk)->dccpms_send_ack_vector) 166 if (dp->dccps_hc_rx_ackvec != NULL)
167 dccp_ackvec_check_rcv_ackno(dp->dccps_hc_rx_ackvec, sk, 167 dccp_ackvec_check_rcv_ackno(dp->dccps_hc_rx_ackvec, sk,
168 DCCP_SKB_CB(skb)->dccpd_ack_seq); 168 DCCP_SKB_CB(skb)->dccpd_ack_seq);
169} 169}
@@ -375,7 +375,7 @@ int dccp_rcv_established(struct sock *sk, struct sk_buff *skb,
375 if (DCCP_SKB_CB(skb)->dccpd_ack_seq != DCCP_PKT_WITHOUT_ACK_SEQ) 375 if (DCCP_SKB_CB(skb)->dccpd_ack_seq != DCCP_PKT_WITHOUT_ACK_SEQ)
376 dccp_event_ack_recv(sk, skb); 376 dccp_event_ack_recv(sk, skb);
377 377
378 if (dccp_msk(sk)->dccpms_send_ack_vector && 378 if (dp->dccps_hc_rx_ackvec != NULL &&
379 dccp_ackvec_add(dp->dccps_hc_rx_ackvec, sk, 379 dccp_ackvec_add(dp->dccps_hc_rx_ackvec, sk,
380 DCCP_SKB_CB(skb)->dccpd_seq, 380 DCCP_SKB_CB(skb)->dccpd_seq,
381 DCCP_ACKVEC_STATE_RECEIVED)) 381 DCCP_ACKVEC_STATE_RECEIVED))
@@ -421,20 +421,19 @@ static int dccp_rcv_request_sent_state_process(struct sock *sk,
421 goto out_invalid_packet; 421 goto out_invalid_packet;
422 } 422 }
423 423
424 /*
425 * If option processing (Step 8) failed, return 1 here so that
426 * dccp_v4_do_rcv() sends a Reset. The Reset code depends on
427 * the option type and is set in dccp_parse_options().
428 */
424 if (dccp_parse_options(sk, NULL, skb)) 429 if (dccp_parse_options(sk, NULL, skb))
425 goto out_invalid_packet; 430 return 1;
426 431
427 /* Obtain usec RTT sample from SYN exchange (used by CCID 3) */ 432 /* Obtain usec RTT sample from SYN exchange (used by CCID 3) */
428 if (likely(dp->dccps_options_received.dccpor_timestamp_echo)) 433 if (likely(dp->dccps_options_received.dccpor_timestamp_echo))
429 dp->dccps_syn_rtt = dccp_sample_rtt(sk, 10 * (tstamp - 434 dp->dccps_syn_rtt = dccp_sample_rtt(sk, 10 * (tstamp -
430 dp->dccps_options_received.dccpor_timestamp_echo)); 435 dp->dccps_options_received.dccpor_timestamp_echo));
431 436
432 if (dccp_msk(sk)->dccpms_send_ack_vector &&
433 dccp_ackvec_add(dp->dccps_hc_rx_ackvec, sk,
434 DCCP_SKB_CB(skb)->dccpd_seq,
435 DCCP_ACKVEC_STATE_RECEIVED))
436 goto out_invalid_packet; /* FIXME: change error code */
437
438 /* Stop the REQUEST timer */ 437 /* Stop the REQUEST timer */
439 inet_csk_clear_xmit_timer(sk, ICSK_TIME_RETRANS); 438 inet_csk_clear_xmit_timer(sk, ICSK_TIME_RETRANS);
440 WARN_ON(sk->sk_send_head == NULL); 439 WARN_ON(sk->sk_send_head == NULL);
@@ -475,6 +474,15 @@ static int dccp_rcv_request_sent_state_process(struct sock *sk,
475 */ 474 */
476 dccp_set_state(sk, DCCP_PARTOPEN); 475 dccp_set_state(sk, DCCP_PARTOPEN);
477 476
477 /*
478 * If feature negotiation was successful, activate features now;
479 * an activation failure means that this host could not activate
480 * one ore more features (e.g. insufficient memory), which would
481 * leave at least one feature in an undefined state.
482 */
483 if (dccp_feat_activate_values(sk, &dp->dccps_featneg))
484 goto unable_to_proceed;
485
478 /* Make sure socket is routed, for correct metrics. */ 486 /* Make sure socket is routed, for correct metrics. */
479 icsk->icsk_af_ops->rebuild_header(sk); 487 icsk->icsk_af_ops->rebuild_header(sk);
480 488
@@ -509,6 +517,16 @@ out_invalid_packet:
509 /* dccp_v4_do_rcv will send a reset */ 517 /* dccp_v4_do_rcv will send a reset */
510 DCCP_SKB_CB(skb)->dccpd_reset_code = DCCP_RESET_CODE_PACKET_ERROR; 518 DCCP_SKB_CB(skb)->dccpd_reset_code = DCCP_RESET_CODE_PACKET_ERROR;
511 return 1; 519 return 1;
520
521unable_to_proceed:
522 DCCP_SKB_CB(skb)->dccpd_reset_code = DCCP_RESET_CODE_ABORTED;
523 /*
524 * We mark this socket as no longer usable, so that the loop in
525 * dccp_sendmsg() terminates and the application gets notified.
526 */
527 dccp_set_state(sk, DCCP_CLOSED);
528 sk->sk_err = ECOMM;
529 return 1;
512} 530}
513 531
514static int dccp_rcv_respond_partopen_state_process(struct sock *sk, 532static int dccp_rcv_respond_partopen_state_process(struct sock *sk,
@@ -590,8 +608,6 @@ int dccp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
590 if (inet_csk(sk)->icsk_af_ops->conn_request(sk, 608 if (inet_csk(sk)->icsk_af_ops->conn_request(sk,
591 skb) < 0) 609 skb) < 0)
592 return 1; 610 return 1;
593
594 /* FIXME: do congestion control initialization */
595 goto discard; 611 goto discard;
596 } 612 }
597 if (dh->dccph_type == DCCP_PKT_RESET) 613 if (dh->dccph_type == DCCP_PKT_RESET)
@@ -602,7 +618,7 @@ int dccp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
602 return 1; 618 return 1;
603 } 619 }
604 620
605 if (sk->sk_state != DCCP_REQUESTING) { 621 if (sk->sk_state != DCCP_REQUESTING && sk->sk_state != DCCP_RESPOND) {
606 if (dccp_check_seqno(sk, skb)) 622 if (dccp_check_seqno(sk, skb))
607 goto discard; 623 goto discard;
608 624
@@ -615,7 +631,7 @@ int dccp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
615 if (dcb->dccpd_ack_seq != DCCP_PKT_WITHOUT_ACK_SEQ) 631 if (dcb->dccpd_ack_seq != DCCP_PKT_WITHOUT_ACK_SEQ)
616 dccp_event_ack_recv(sk, skb); 632 dccp_event_ack_recv(sk, skb);
617 633
618 if (dccp_msk(sk)->dccpms_send_ack_vector && 634 if (dp->dccps_hc_rx_ackvec != NULL &&
619 dccp_ackvec_add(dp->dccps_hc_rx_ackvec, sk, 635 dccp_ackvec_add(dp->dccps_hc_rx_ackvec, sk,
620 DCCP_SKB_CB(skb)->dccpd_seq, 636 DCCP_SKB_CB(skb)->dccpd_seq,
621 DCCP_ACKVEC_STATE_RECEIVED)) 637 DCCP_ACKVEC_STATE_RECEIVED))
@@ -667,8 +683,6 @@ int dccp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
667 return 1; 683 return 1;
668 684
669 case DCCP_REQUESTING: 685 case DCCP_REQUESTING:
670 /* FIXME: do congestion control initialization */
671
672 queued = dccp_rcv_request_sent_state_process(sk, skb, dh, len); 686 queued = dccp_rcv_request_sent_state_process(sk, skb, dh, len);
673 if (queued >= 0) 687 if (queued >= 0)
674 return queued; 688 return queued;
diff --git a/net/dccp/ipv4.c b/net/dccp/ipv4.c
index e3dfddab21cc..d1dd95289b89 100644
--- a/net/dccp/ipv4.c
+++ b/net/dccp/ipv4.c
@@ -545,6 +545,7 @@ out:
545 545
546static void dccp_v4_reqsk_destructor(struct request_sock *req) 546static void dccp_v4_reqsk_destructor(struct request_sock *req)
547{ 547{
548 dccp_feat_list_purge(&dccp_rsk(req)->dreq_featneg);
548 kfree(inet_rsk(req)->opt); 549 kfree(inet_rsk(req)->opt);
549} 550}
550 551
@@ -595,7 +596,8 @@ int dccp_v4_conn_request(struct sock *sk, struct sk_buff *skb)
595 if (req == NULL) 596 if (req == NULL)
596 goto drop; 597 goto drop;
597 598
598 dccp_reqsk_init(req, skb); 599 if (dccp_reqsk_init(req, dccp_sk(sk), skb))
600 goto drop_and_free;
599 601
600 dreq = dccp_rsk(req); 602 dreq = dccp_rsk(req);
601 if (dccp_parse_options(sk, dreq, skb)) 603 if (dccp_parse_options(sk, dreq, skb))
@@ -792,12 +794,10 @@ static int dccp_v4_rcv(struct sk_buff *skb)
792 DCCP_SKB_CB(skb)->dccpd_seq = dccp_hdr_seq(dh); 794 DCCP_SKB_CB(skb)->dccpd_seq = dccp_hdr_seq(dh);
793 DCCP_SKB_CB(skb)->dccpd_type = dh->dccph_type; 795 DCCP_SKB_CB(skb)->dccpd_type = dh->dccph_type;
794 796
795 dccp_pr_debug("%8.8s " 797 dccp_pr_debug("%8.8s src=%pI4@%-5d dst=%pI4@%-5d seq=%llu",
796 "src=%u.%u.%u.%u@%-5d "
797 "dst=%u.%u.%u.%u@%-5d seq=%llu",
798 dccp_packet_name(dh->dccph_type), 798 dccp_packet_name(dh->dccph_type),
799 NIPQUAD(iph->saddr), ntohs(dh->dccph_sport), 799 &iph->saddr, ntohs(dh->dccph_sport),
800 NIPQUAD(iph->daddr), ntohs(dh->dccph_dport), 800 &iph->daddr, ntohs(dh->dccph_dport),
801 (unsigned long long) DCCP_SKB_CB(skb)->dccpd_seq); 801 (unsigned long long) DCCP_SKB_CB(skb)->dccpd_seq);
802 802
803 if (dccp_packet_without_ack(skb)) { 803 if (dccp_packet_without_ack(skb)) {
@@ -938,6 +938,7 @@ static struct proto dccp_v4_prot = {
938 .orphan_count = &dccp_orphan_count, 938 .orphan_count = &dccp_orphan_count,
939 .max_header = MAX_DCCP_HEADER, 939 .max_header = MAX_DCCP_HEADER,
940 .obj_size = sizeof(struct dccp_sock), 940 .obj_size = sizeof(struct dccp_sock),
941 .slab_flags = SLAB_DESTROY_BY_RCU,
941 .rsk_prot = &dccp_request_sock_ops, 942 .rsk_prot = &dccp_request_sock_ops,
942 .twsk_prot = &dccp_timewait_sock_ops, 943 .twsk_prot = &dccp_timewait_sock_ops,
943 .h.hashinfo = &dccp_hashinfo, 944 .h.hashinfo = &dccp_hashinfo,
diff --git a/net/dccp/ipv6.c b/net/dccp/ipv6.c
index d4ce1224e008..b963f35c65f6 100644
--- a/net/dccp/ipv6.c
+++ b/net/dccp/ipv6.c
@@ -168,7 +168,7 @@ static void dccp_v6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
168 goto out; 168 goto out;
169 } 169 }
170 170
171 err = xfrm_lookup(&dst, &fl, sk, 0); 171 err = xfrm_lookup(net, &dst, &fl, sk, 0);
172 if (err < 0) { 172 if (err < 0) {
173 sk->sk_err_soft = -err; 173 sk->sk_err_soft = -err;
174 goto out; 174 goto out;
@@ -279,7 +279,7 @@ static int dccp_v6_send_response(struct sock *sk, struct request_sock *req)
279 if (final_p) 279 if (final_p)
280 ipv6_addr_copy(&fl.fl6_dst, final_p); 280 ipv6_addr_copy(&fl.fl6_dst, final_p);
281 281
282 err = xfrm_lookup(&dst, &fl, sk, 0); 282 err = xfrm_lookup(sock_net(sk), &dst, &fl, sk, 0);
283 if (err < 0) 283 if (err < 0)
284 goto done; 284 goto done;
285 285
@@ -304,6 +304,7 @@ done:
304 304
305static void dccp_v6_reqsk_destructor(struct request_sock *req) 305static void dccp_v6_reqsk_destructor(struct request_sock *req)
306{ 306{
307 dccp_feat_list_purge(&dccp_rsk(req)->dreq_featneg);
307 if (inet6_rsk(req)->pktopts != NULL) 308 if (inet6_rsk(req)->pktopts != NULL)
308 kfree_skb(inet6_rsk(req)->pktopts); 309 kfree_skb(inet6_rsk(req)->pktopts);
309} 310}
@@ -342,7 +343,7 @@ static void dccp_v6_ctl_send_reset(struct sock *sk, struct sk_buff *rxskb)
342 343
343 /* sk = NULL, but it is safe for now. RST socket required. */ 344 /* sk = NULL, but it is safe for now. RST socket required. */
344 if (!ip6_dst_lookup(ctl_sk, &skb->dst, &fl)) { 345 if (!ip6_dst_lookup(ctl_sk, &skb->dst, &fl)) {
345 if (xfrm_lookup(&skb->dst, &fl, NULL, 0) >= 0) { 346 if (xfrm_lookup(net, &skb->dst, &fl, NULL, 0) >= 0) {
346 ip6_xmit(ctl_sk, skb, &fl, NULL, 0); 347 ip6_xmit(ctl_sk, skb, &fl, NULL, 0);
347 DCCP_INC_STATS_BH(DCCP_MIB_OUTSEGS); 348 DCCP_INC_STATS_BH(DCCP_MIB_OUTSEGS);
348 DCCP_INC_STATS_BH(DCCP_MIB_OUTRSTS); 349 DCCP_INC_STATS_BH(DCCP_MIB_OUTRSTS);
@@ -426,7 +427,8 @@ static int dccp_v6_conn_request(struct sock *sk, struct sk_buff *skb)
426 if (req == NULL) 427 if (req == NULL)
427 goto drop; 428 goto drop;
428 429
429 dccp_reqsk_init(req, skb); 430 if (dccp_reqsk_init(req, dccp_sk(sk), skb))
431 goto drop_and_free;
430 432
431 dreq = dccp_rsk(req); 433 dreq = dccp_rsk(req);
432 if (dccp_parse_options(sk, dreq, skb)) 434 if (dccp_parse_options(sk, dreq, skb))
@@ -567,7 +569,7 @@ static struct sock *dccp_v6_request_recv_sock(struct sock *sk,
567 if (final_p) 569 if (final_p)
568 ipv6_addr_copy(&fl.fl6_dst, final_p); 570 ipv6_addr_copy(&fl.fl6_dst, final_p);
569 571
570 if ((xfrm_lookup(&dst, &fl, sk, 0)) < 0) 572 if ((xfrm_lookup(sock_net(sk), &dst, &fl, sk, 0)) < 0)
571 goto out; 573 goto out;
572 } 574 }
573 575
@@ -1002,7 +1004,7 @@ static int dccp_v6_connect(struct sock *sk, struct sockaddr *uaddr,
1002 if (final_p) 1004 if (final_p)
1003 ipv6_addr_copy(&fl.fl6_dst, final_p); 1005 ipv6_addr_copy(&fl.fl6_dst, final_p);
1004 1006
1005 err = __xfrm_lookup(&dst, &fl, sk, XFRM_LOOKUP_WAIT); 1007 err = __xfrm_lookup(sock_net(sk), &dst, &fl, sk, XFRM_LOOKUP_WAIT);
1006 if (err < 0) { 1008 if (err < 0) {
1007 if (err == -EREMOTE) 1009 if (err == -EREMOTE)
1008 err = ip6_dst_blackhole(sk, &dst, &fl); 1010 err = ip6_dst_blackhole(sk, &dst, &fl);
@@ -1138,6 +1140,7 @@ static struct proto dccp_v6_prot = {
1138 .orphan_count = &dccp_orphan_count, 1140 .orphan_count = &dccp_orphan_count,
1139 .max_header = MAX_DCCP_HEADER, 1141 .max_header = MAX_DCCP_HEADER,
1140 .obj_size = sizeof(struct dccp6_sock), 1142 .obj_size = sizeof(struct dccp6_sock),
1143 .slab_flags = SLAB_DESTROY_BY_RCU,
1141 .rsk_prot = &dccp6_request_sock_ops, 1144 .rsk_prot = &dccp6_request_sock_ops,
1142 .twsk_prot = &dccp6_timewait_sock_ops, 1145 .twsk_prot = &dccp6_timewait_sock_ops,
1143 .h.hashinfo = &dccp_hashinfo, 1146 .h.hashinfo = &dccp_hashinfo,
diff --git a/net/dccp/minisocks.c b/net/dccp/minisocks.c
index e6bf99e3e41a..6821ae33dd37 100644
--- a/net/dccp/minisocks.c
+++ b/net/dccp/minisocks.c
@@ -45,11 +45,6 @@ EXPORT_SYMBOL_GPL(dccp_death_row);
45void dccp_minisock_init(struct dccp_minisock *dmsk) 45void dccp_minisock_init(struct dccp_minisock *dmsk)
46{ 46{
47 dmsk->dccpms_sequence_window = sysctl_dccp_feat_sequence_window; 47 dmsk->dccpms_sequence_window = sysctl_dccp_feat_sequence_window;
48 dmsk->dccpms_rx_ccid = sysctl_dccp_feat_rx_ccid;
49 dmsk->dccpms_tx_ccid = sysctl_dccp_feat_tx_ccid;
50 dmsk->dccpms_ack_ratio = sysctl_dccp_feat_ack_ratio;
51 dmsk->dccpms_send_ack_vector = sysctl_dccp_feat_send_ack_vector;
52 dmsk->dccpms_send_ndp_count = sysctl_dccp_feat_send_ndp_count;
53} 48}
54 49
55void dccp_time_wait(struct sock *sk, int state, int timeo) 50void dccp_time_wait(struct sock *sk, int state, int timeo)
@@ -112,7 +107,7 @@ struct sock *dccp_create_openreq_child(struct sock *sk,
112 struct sock *newsk = inet_csk_clone(sk, req, GFP_ATOMIC); 107 struct sock *newsk = inet_csk_clone(sk, req, GFP_ATOMIC);
113 108
114 if (newsk != NULL) { 109 if (newsk != NULL) {
115 const struct dccp_request_sock *dreq = dccp_rsk(req); 110 struct dccp_request_sock *dreq = dccp_rsk(req);
116 struct inet_connection_sock *newicsk = inet_csk(newsk); 111 struct inet_connection_sock *newicsk = inet_csk(newsk);
117 struct dccp_sock *newdp = dccp_sk(newsk); 112 struct dccp_sock *newdp = dccp_sk(newsk);
118 struct dccp_minisock *newdmsk = dccp_msk(newsk); 113 struct dccp_minisock *newdmsk = dccp_msk(newsk);
@@ -125,35 +120,7 @@ struct sock *dccp_create_openreq_child(struct sock *sk,
125 newdp->dccps_timestamp_time = dreq->dreq_timestamp_time; 120 newdp->dccps_timestamp_time = dreq->dreq_timestamp_time;
126 newicsk->icsk_rto = DCCP_TIMEOUT_INIT; 121 newicsk->icsk_rto = DCCP_TIMEOUT_INIT;
127 122
128 if (dccp_feat_clone(sk, newsk)) 123 INIT_LIST_HEAD(&newdp->dccps_featneg);
129 goto out_free;
130
131 if (newdmsk->dccpms_send_ack_vector) {
132 newdp->dccps_hc_rx_ackvec =
133 dccp_ackvec_alloc(GFP_ATOMIC);
134 if (unlikely(newdp->dccps_hc_rx_ackvec == NULL))
135 goto out_free;
136 }
137
138 newdp->dccps_hc_rx_ccid =
139 ccid_hc_rx_new(newdmsk->dccpms_rx_ccid,
140 newsk, GFP_ATOMIC);
141 newdp->dccps_hc_tx_ccid =
142 ccid_hc_tx_new(newdmsk->dccpms_tx_ccid,
143 newsk, GFP_ATOMIC);
144 if (unlikely(newdp->dccps_hc_rx_ccid == NULL ||
145 newdp->dccps_hc_tx_ccid == NULL)) {
146 dccp_ackvec_free(newdp->dccps_hc_rx_ackvec);
147 ccid_hc_rx_delete(newdp->dccps_hc_rx_ccid, newsk);
148 ccid_hc_tx_delete(newdp->dccps_hc_tx_ccid, newsk);
149out_free:
150 /* It is still raw copy of parent, so invalidate
151 * destructor and make plain sk_free() */
152 newsk->sk_destruct = NULL;
153 sk_free(newsk);
154 return NULL;
155 }
156
157 /* 124 /*
158 * Step 3: Process LISTEN state 125 * Step 3: Process LISTEN state
159 * 126 *
@@ -184,6 +151,17 @@ out_free:
184 dccp_set_seqno(&newdp->dccps_awl, 151 dccp_set_seqno(&newdp->dccps_awl,
185 max48(newdp->dccps_awl, newdp->dccps_iss)); 152 max48(newdp->dccps_awl, newdp->dccps_iss));
186 153
154 /*
155 * Activate features after initialising the sequence numbers,
156 * since CCID initialisation may depend on GSS, ISR, ISS etc.
157 */
158 if (dccp_feat_activate_values(newsk, &dreq->dreq_featneg)) {
159 /* It is still raw copy of parent, so invalidate
160 * destructor and make plain sk_free() */
161 newsk->sk_destruct = NULL;
162 sk_free(newsk);
163 return NULL;
164 }
187 dccp_init_xmit_timers(newsk); 165 dccp_init_xmit_timers(newsk);
188 166
189 DCCP_INC_STATS_BH(DCCP_MIB_PASSIVEOPENS); 167 DCCP_INC_STATS_BH(DCCP_MIB_PASSIVEOPENS);
@@ -304,7 +282,8 @@ void dccp_reqsk_send_ack(struct sock *sk, struct sk_buff *skb,
304 282
305EXPORT_SYMBOL_GPL(dccp_reqsk_send_ack); 283EXPORT_SYMBOL_GPL(dccp_reqsk_send_ack);
306 284
307void dccp_reqsk_init(struct request_sock *req, struct sk_buff *skb) 285int dccp_reqsk_init(struct request_sock *req,
286 struct dccp_sock const *dp, struct sk_buff const *skb)
308{ 287{
309 struct dccp_request_sock *dreq = dccp_rsk(req); 288 struct dccp_request_sock *dreq = dccp_rsk(req);
310 289
@@ -313,6 +292,9 @@ void dccp_reqsk_init(struct request_sock *req, struct sk_buff *skb)
313 inet_rsk(req)->acked = 0; 292 inet_rsk(req)->acked = 0;
314 req->rcv_wnd = sysctl_dccp_feat_sequence_window; 293 req->rcv_wnd = sysctl_dccp_feat_sequence_window;
315 dreq->dreq_timestamp_echo = 0; 294 dreq->dreq_timestamp_echo = 0;
295
296 /* inherit feature negotiation options from listening socket */
297 return dccp_feat_clone_list(&dp->dccps_featneg, &dreq->dreq_featneg);
316} 298}
317 299
318EXPORT_SYMBOL_GPL(dccp_reqsk_init); 300EXPORT_SYMBOL_GPL(dccp_reqsk_init);
diff --git a/net/dccp/options.c b/net/dccp/options.c
index 0809b63cb055..7b1165c21f51 100644
--- a/net/dccp/options.c
+++ b/net/dccp/options.c
@@ -26,20 +26,21 @@
26int sysctl_dccp_feat_sequence_window = DCCPF_INITIAL_SEQUENCE_WINDOW; 26int sysctl_dccp_feat_sequence_window = DCCPF_INITIAL_SEQUENCE_WINDOW;
27int sysctl_dccp_feat_rx_ccid = DCCPF_INITIAL_CCID; 27int sysctl_dccp_feat_rx_ccid = DCCPF_INITIAL_CCID;
28int sysctl_dccp_feat_tx_ccid = DCCPF_INITIAL_CCID; 28int sysctl_dccp_feat_tx_ccid = DCCPF_INITIAL_CCID;
29int sysctl_dccp_feat_ack_ratio = DCCPF_INITIAL_ACK_RATIO;
30int sysctl_dccp_feat_send_ack_vector = DCCPF_INITIAL_SEND_ACK_VECTOR;
31int sysctl_dccp_feat_send_ndp_count = DCCPF_INITIAL_SEND_NDP_COUNT;
32 29
33static u32 dccp_decode_value_var(const unsigned char *bf, const u8 len) 30u64 dccp_decode_value_var(const u8 *bf, const u8 len)
34{ 31{
35 u32 value = 0; 32 u64 value = 0;
36 33
34 if (len >= DCCP_OPTVAL_MAXLEN)
35 value += ((u64)*bf++) << 40;
36 if (len > 4)
37 value += ((u64)*bf++) << 32;
37 if (len > 3) 38 if (len > 3)
38 value += *bf++ << 24; 39 value += ((u64)*bf++) << 24;
39 if (len > 2) 40 if (len > 2)
40 value += *bf++ << 16; 41 value += ((u64)*bf++) << 16;
41 if (len > 1) 42 if (len > 1)
42 value += *bf++ << 8; 43 value += ((u64)*bf++) << 8;
43 if (len > 0) 44 if (len > 0)
44 value += *bf; 45 value += *bf;
45 46
@@ -64,7 +65,7 @@ int dccp_parse_options(struct sock *sk, struct dccp_request_sock *dreq,
64 (dh->dccph_doff * 4); 65 (dh->dccph_doff * 4);
65 struct dccp_options_received *opt_recv = &dp->dccps_options_received; 66 struct dccp_options_received *opt_recv = &dp->dccps_options_received;
66 unsigned char opt, len; 67 unsigned char opt, len;
67 unsigned char *value; 68 unsigned char *uninitialized_var(value);
68 u32 elapsed_time; 69 u32 elapsed_time;
69 __be32 opt_val; 70 __be32 opt_val;
70 int rc; 71 int rc;
@@ -131,41 +132,19 @@ int dccp_parse_options(struct sock *sk, struct dccp_request_sock *dreq,
131 dccp_pr_debug("%s opt: NDP count=%llu\n", dccp_role(sk), 132 dccp_pr_debug("%s opt: NDP count=%llu\n", dccp_role(sk),
132 (unsigned long long)opt_recv->dccpor_ndp); 133 (unsigned long long)opt_recv->dccpor_ndp);
133 break; 134 break;
134 case DCCPO_CHANGE_L: 135 case DCCPO_CHANGE_L ... DCCPO_CONFIRM_R:
135 /* fall through */ 136 if (pkt_type == DCCP_PKT_DATA) /* RFC 4340, 6 */
136 case DCCPO_CHANGE_R:
137 if (pkt_type == DCCP_PKT_DATA)
138 break; 137 break;
139 if (len < 2) 138 rc = dccp_feat_parse_options(sk, dreq, mandatory, opt,
140 goto out_invalid_option; 139 *value, value + 1, len - 1);
141 rc = dccp_feat_change_recv(sk, opt, *value, value + 1, 140 if (rc)
142 len - 1); 141 goto out_featneg_failed;
143 /*
144 * When there is a change error, change_recv is
145 * responsible for dealing with it. i.e. reply with an
146 * empty confirm.
147 * If the change was mandatory, then we need to die.
148 */
149 if (rc && mandatory)
150 goto out_invalid_option;
151 break;
152 case DCCPO_CONFIRM_L:
153 /* fall through */
154 case DCCPO_CONFIRM_R:
155 if (pkt_type == DCCP_PKT_DATA)
156 break;
157 if (len < 2) /* FIXME this disallows empty confirm */
158 goto out_invalid_option;
159 if (dccp_feat_confirm_recv(sk, opt, *value,
160 value + 1, len - 1))
161 goto out_invalid_option;
162 break; 142 break;
163 case DCCPO_ACK_VECTOR_0: 143 case DCCPO_ACK_VECTOR_0:
164 case DCCPO_ACK_VECTOR_1: 144 case DCCPO_ACK_VECTOR_1:
165 if (dccp_packet_without_ack(skb)) /* RFC 4340, 11.4 */ 145 if (dccp_packet_without_ack(skb)) /* RFC 4340, 11.4 */
166 break; 146 break;
167 147 if (dp->dccps_hc_rx_ackvec != NULL &&
168 if (dccp_msk(sk)->dccpms_send_ack_vector &&
169 dccp_ackvec_parse(sk, skb, &ackno, opt, value, len)) 148 dccp_ackvec_parse(sk, skb, &ackno, opt, value, len))
170 goto out_invalid_option; 149 goto out_invalid_option;
171 break; 150 break;
@@ -289,8 +268,10 @@ out_nonsensical_length:
289 268
290out_invalid_option: 269out_invalid_option:
291 DCCP_INC_STATS_BH(DCCP_MIB_INVALIDOPT); 270 DCCP_INC_STATS_BH(DCCP_MIB_INVALIDOPT);
292 DCCP_SKB_CB(skb)->dccpd_reset_code = DCCP_RESET_CODE_OPTION_ERROR; 271 rc = DCCP_RESET_CODE_OPTION_ERROR;
293 DCCP_WARN("DCCP(%p): invalid option %d, len=%d", sk, opt, len); 272out_featneg_failed:
273 DCCP_WARN("DCCP(%p): Option %d (len=%d) error=%u\n", sk, opt, len, rc);
274 DCCP_SKB_CB(skb)->dccpd_reset_code = rc;
294 DCCP_SKB_CB(skb)->dccpd_reset_data[0] = opt; 275 DCCP_SKB_CB(skb)->dccpd_reset_data[0] = opt;
295 DCCP_SKB_CB(skb)->dccpd_reset_data[1] = len > 0 ? value[0] : 0; 276 DCCP_SKB_CB(skb)->dccpd_reset_data[1] = len > 0 ? value[0] : 0;
296 DCCP_SKB_CB(skb)->dccpd_reset_data[2] = len > 1 ? value[1] : 0; 277 DCCP_SKB_CB(skb)->dccpd_reset_data[2] = len > 1 ? value[1] : 0;
@@ -299,9 +280,12 @@ out_invalid_option:
299 280
300EXPORT_SYMBOL_GPL(dccp_parse_options); 281EXPORT_SYMBOL_GPL(dccp_parse_options);
301 282
302static void dccp_encode_value_var(const u32 value, unsigned char *to, 283void dccp_encode_value_var(const u64 value, u8 *to, const u8 len)
303 const unsigned int len)
304{ 284{
285 if (len >= DCCP_OPTVAL_MAXLEN)
286 *to++ = (value & 0xFF0000000000ull) >> 40;
287 if (len > 4)
288 *to++ = (value & 0xFF00000000ull) >> 32;
305 if (len > 3) 289 if (len > 3)
306 *to++ = (value & 0xFF000000) >> 24; 290 *to++ = (value & 0xFF000000) >> 24;
307 if (len > 2) 291 if (len > 2)
@@ -461,23 +445,61 @@ static int dccp_insert_option_timestamp_echo(struct dccp_sock *dp,
461 return 0; 445 return 0;
462} 446}
463 447
464static int dccp_insert_feat_opt(struct sk_buff *skb, u8 type, u8 feat, 448/**
465 u8 *val, u8 len) 449 * dccp_insert_option_mandatory - Mandatory option (5.8.2)
450 * Note that since we are using skb_push, this function needs to be called
451 * _after_ inserting the option it is supposed to influence (stack order).
452 */
453int dccp_insert_option_mandatory(struct sk_buff *skb)
454{
455 if (DCCP_SKB_CB(skb)->dccpd_opt_len >= DCCP_MAX_OPT_LEN)
456 return -1;
457
458 DCCP_SKB_CB(skb)->dccpd_opt_len++;
459 *skb_push(skb, 1) = DCCPO_MANDATORY;
460 return 0;
461}
462
463/**
464 * dccp_insert_fn_opt - Insert single Feature-Negotiation option into @skb
465 * @type: %DCCPO_CHANGE_L, %DCCPO_CHANGE_R, %DCCPO_CONFIRM_L, %DCCPO_CONFIRM_R
466 * @feat: one out of %dccp_feature_numbers
467 * @val: NN value or SP array (preferred element first) to copy
468 * @len: true length of @val in bytes (excluding first element repetition)
469 * @repeat_first: whether to copy the first element of @val twice
470 * The last argument is used to construct Confirm options, where the preferred
471 * value and the preference list appear separately (RFC 4340, 6.3.1). Preference
472 * lists are kept such that the preferred entry is always first, so we only need
473 * to copy twice, and avoid the overhead of cloning into a bigger array.
474 */
475int dccp_insert_fn_opt(struct sk_buff *skb, u8 type, u8 feat,
476 u8 *val, u8 len, bool repeat_first)
466{ 477{
467 u8 *to; 478 u8 tot_len, *to;
468 479
469 if (DCCP_SKB_CB(skb)->dccpd_opt_len + len + 3 > DCCP_MAX_OPT_LEN) { 480 /* take the `Feature' field and possible repetition into account */
470 DCCP_WARN("packet too small for feature %d option!\n", feat); 481 if (len > (DCCP_SINGLE_OPT_MAXLEN - 2)) {
482 DCCP_WARN("length %u for feature %u too large\n", len, feat);
471 return -1; 483 return -1;
472 } 484 }
473 485
474 DCCP_SKB_CB(skb)->dccpd_opt_len += len + 3; 486 if (unlikely(val == NULL || len == 0))
487 len = repeat_first = 0;
488 tot_len = 3 + repeat_first + len;
489
490 if (DCCP_SKB_CB(skb)->dccpd_opt_len + tot_len > DCCP_MAX_OPT_LEN) {
491 DCCP_WARN("packet too small for feature %d option!\n", feat);
492 return -1;
493 }
494 DCCP_SKB_CB(skb)->dccpd_opt_len += tot_len;
475 495
476 to = skb_push(skb, len + 3); 496 to = skb_push(skb, tot_len);
477 *to++ = type; 497 *to++ = type;
478 *to++ = len + 3; 498 *to++ = tot_len;
479 *to++ = feat; 499 *to++ = feat;
480 500
501 if (repeat_first)
502 *to++ = *val;
481 if (len) 503 if (len)
482 memcpy(to, val, len); 504 memcpy(to, val, len);
483 505
@@ -487,69 +509,6 @@ static int dccp_insert_feat_opt(struct sk_buff *skb, u8 type, u8 feat,
487 return 0; 509 return 0;
488} 510}
489 511
490static int dccp_insert_options_feat(struct sock *sk, struct sk_buff *skb)
491{
492 struct dccp_sock *dp = dccp_sk(sk);
493 struct dccp_minisock *dmsk = dccp_msk(sk);
494 struct dccp_opt_pend *opt, *next;
495 int change = 0;
496
497 /* confirm any options [NN opts] */
498 list_for_each_entry_safe(opt, next, &dmsk->dccpms_conf, dccpop_node) {
499 dccp_insert_feat_opt(skb, opt->dccpop_type,
500 opt->dccpop_feat, opt->dccpop_val,
501 opt->dccpop_len);
502 /* fear empty confirms */
503 if (opt->dccpop_val)
504 kfree(opt->dccpop_val);
505 kfree(opt);
506 }
507 INIT_LIST_HEAD(&dmsk->dccpms_conf);
508
509 /* see which features we need to send */
510 list_for_each_entry(opt, &dmsk->dccpms_pending, dccpop_node) {
511 /* see if we need to send any confirm */
512 if (opt->dccpop_sc) {
513 dccp_insert_feat_opt(skb, opt->dccpop_type + 1,
514 opt->dccpop_feat,
515 opt->dccpop_sc->dccpoc_val,
516 opt->dccpop_sc->dccpoc_len);
517
518 BUG_ON(!opt->dccpop_sc->dccpoc_val);
519 kfree(opt->dccpop_sc->dccpoc_val);
520 kfree(opt->dccpop_sc);
521 opt->dccpop_sc = NULL;
522 }
523
524 /* any option not confirmed, re-send it */
525 if (!opt->dccpop_conf) {
526 dccp_insert_feat_opt(skb, opt->dccpop_type,
527 opt->dccpop_feat, opt->dccpop_val,
528 opt->dccpop_len);
529 change++;
530 }
531 }
532
533 /* Retransmit timer.
534 * If this is the master listening sock, we don't set a timer on it. It
535 * should be fine because if the dude doesn't receive our RESPONSE
536 * [which will contain the CHANGE] he will send another REQUEST which
537 * will "retrnasmit" the change.
538 */
539 if (change && dp->dccps_role != DCCP_ROLE_LISTEN) {
540 dccp_pr_debug("reset feat negotiation timer %p\n", sk);
541
542 /* XXX don't reset the timer on re-transmissions. I.e. reset it
543 * only when sending new stuff i guess. Currently the timer
544 * never backs off because on re-transmission it just resets it!
545 */
546 inet_csk_reset_xmit_timer(sk, ICSK_TIME_RETRANS,
547 inet_csk(sk)->icsk_rto, DCCP_RTO_MAX);
548 }
549
550 return 0;
551}
552
553/* The length of all options needs to be a multiple of 4 (5.8) */ 512/* The length of all options needs to be a multiple of 4 (5.8) */
554static void dccp_insert_option_padding(struct sk_buff *skb) 513static void dccp_insert_option_padding(struct sk_buff *skb)
555{ 514{
@@ -565,19 +524,31 @@ static void dccp_insert_option_padding(struct sk_buff *skb)
565int dccp_insert_options(struct sock *sk, struct sk_buff *skb) 524int dccp_insert_options(struct sock *sk, struct sk_buff *skb)
566{ 525{
567 struct dccp_sock *dp = dccp_sk(sk); 526 struct dccp_sock *dp = dccp_sk(sk);
568 struct dccp_minisock *dmsk = dccp_msk(sk);
569 527
570 DCCP_SKB_CB(skb)->dccpd_opt_len = 0; 528 DCCP_SKB_CB(skb)->dccpd_opt_len = 0;
571 529
572 if (dmsk->dccpms_send_ndp_count && 530 if (dp->dccps_send_ndp_count && dccp_insert_option_ndp(sk, skb))
573 dccp_insert_option_ndp(sk, skb))
574 return -1; 531 return -1;
575 532
576 if (!dccp_packet_without_ack(skb)) { 533 if (DCCP_SKB_CB(skb)->dccpd_type != DCCP_PKT_DATA) {
577 if (dmsk->dccpms_send_ack_vector && 534
578 dccp_ackvec_pending(dp->dccps_hc_rx_ackvec) && 535 /* Feature Negotiation */
579 dccp_insert_option_ackvec(sk, skb)) 536 if (dccp_feat_insert_opts(dp, NULL, skb))
580 return -1; 537 return -1;
538
539 if (DCCP_SKB_CB(skb)->dccpd_type == DCCP_PKT_REQUEST) {
540 /*
541 * Obtain RTT sample from Request/Response exchange.
542 * This is currently used in CCID 3 initialisation.
543 */
544 if (dccp_insert_option_timestamp(sk, skb))
545 return -1;
546
547 } else if (dp->dccps_hc_rx_ackvec != NULL &&
548 dccp_ackvec_pending(dp->dccps_hc_rx_ackvec) &&
549 dccp_insert_option_ackvec(sk, skb)) {
550 return -1;
551 }
581 } 552 }
582 553
583 if (dp->dccps_hc_rx_insert_options) { 554 if (dp->dccps_hc_rx_insert_options) {
@@ -586,21 +557,6 @@ int dccp_insert_options(struct sock *sk, struct sk_buff *skb)
586 dp->dccps_hc_rx_insert_options = 0; 557 dp->dccps_hc_rx_insert_options = 0;
587 } 558 }
588 559
589 /* Feature negotiation */
590 /* Data packets can't do feat negotiation */
591 if (DCCP_SKB_CB(skb)->dccpd_type != DCCP_PKT_DATA &&
592 DCCP_SKB_CB(skb)->dccpd_type != DCCP_PKT_DATAACK &&
593 dccp_insert_options_feat(sk, skb))
594 return -1;
595
596 /*
597 * Obtain RTT sample from Request/Response exchange.
598 * This is currently used in CCID 3 initialisation.
599 */
600 if (DCCP_SKB_CB(skb)->dccpd_type == DCCP_PKT_REQUEST &&
601 dccp_insert_option_timestamp(sk, skb))
602 return -1;
603
604 if (dp->dccps_timestamp_echo != 0 && 560 if (dp->dccps_timestamp_echo != 0 &&
605 dccp_insert_option_timestamp_echo(dp, NULL, skb)) 561 dccp_insert_option_timestamp_echo(dp, NULL, skb))
606 return -1; 562 return -1;
@@ -613,6 +569,9 @@ int dccp_insert_options_rsk(struct dccp_request_sock *dreq, struct sk_buff *skb)
613{ 569{
614 DCCP_SKB_CB(skb)->dccpd_opt_len = 0; 570 DCCP_SKB_CB(skb)->dccpd_opt_len = 0;
615 571
572 if (dccp_feat_insert_opts(NULL, dreq, skb))
573 return -1;
574
616 if (dreq->dreq_timestamp_echo != 0 && 575 if (dreq->dreq_timestamp_echo != 0 &&
617 dccp_insert_option_timestamp_echo(NULL, dreq, skb)) 576 dccp_insert_option_timestamp_echo(NULL, dreq, skb))
618 return -1; 577 return -1;
diff --git a/net/dccp/output.c b/net/dccp/output.c
index 809d803d5006..22a618af4893 100644
--- a/net/dccp/output.c
+++ b/net/dccp/output.c
@@ -175,7 +175,7 @@ unsigned int dccp_sync_mss(struct sock *sk, u32 pmtu)
175 * make it a multiple of 4 175 * make it a multiple of 4
176 */ 176 */
177 177
178 cur_mps -= ((5 + 6 + 10 + 6 + 6 + 6 + 3) / 4) * 4; 178 cur_mps -= roundup(5 + 6 + 10 + 6 + 6 + 6, 4);
179 179
180 /* And store cached results */ 180 /* And store cached results */
181 icsk->icsk_pmtu_cookie = pmtu; 181 icsk->icsk_pmtu_cookie = pmtu;
@@ -339,10 +339,12 @@ struct sk_buff *dccp_make_response(struct sock *sk, struct dst_entry *dst,
339 DCCP_SKB_CB(skb)->dccpd_type = DCCP_PKT_RESPONSE; 339 DCCP_SKB_CB(skb)->dccpd_type = DCCP_PKT_RESPONSE;
340 DCCP_SKB_CB(skb)->dccpd_seq = dreq->dreq_iss; 340 DCCP_SKB_CB(skb)->dccpd_seq = dreq->dreq_iss;
341 341
342 if (dccp_insert_options_rsk(dreq, skb)) { 342 /* Resolve feature dependencies resulting from choice of CCID */
343 kfree_skb(skb); 343 if (dccp_feat_server_ccid_dependencies(dreq))
344 return NULL; 344 goto response_failed;
345 } 345
346 if (dccp_insert_options_rsk(dreq, skb))
347 goto response_failed;
346 348
347 /* Build and checksum header */ 349 /* Build and checksum header */
348 dh = dccp_zeroed_hdr(skb, dccp_header_size); 350 dh = dccp_zeroed_hdr(skb, dccp_header_size);
@@ -363,6 +365,9 @@ struct sk_buff *dccp_make_response(struct sock *sk, struct dst_entry *dst,
363 inet_rsk(req)->acked = 1; 365 inet_rsk(req)->acked = 1;
364 DCCP_INC_STATS(DCCP_MIB_OUTSEGS); 366 DCCP_INC_STATS(DCCP_MIB_OUTSEGS);
365 return skb; 367 return skb;
368response_failed:
369 kfree_skb(skb);
370 return NULL;
366} 371}
367 372
368EXPORT_SYMBOL_GPL(dccp_make_response); 373EXPORT_SYMBOL_GPL(dccp_make_response);
@@ -469,6 +474,10 @@ int dccp_connect(struct sock *sk)
469 struct sk_buff *skb; 474 struct sk_buff *skb;
470 struct inet_connection_sock *icsk = inet_csk(sk); 475 struct inet_connection_sock *icsk = inet_csk(sk);
471 476
477 /* do not connect if feature negotiation setup fails */
478 if (dccp_feat_finalise_settings(dccp_sk(sk)))
479 return -EPROTO;
480
472 dccp_connect_init(sk); 481 dccp_connect_init(sk);
473 482
474 skb = alloc_skb(sk->sk_prot->max_header, sk->sk_allocation); 483 skb = alloc_skb(sk->sk_prot->max_header, sk->sk_allocation);
diff --git a/net/dccp/probe.c b/net/dccp/probe.c
index 81368a7f5379..37731da41481 100644
--- a/net/dccp/probe.c
+++ b/net/dccp/probe.c
@@ -74,30 +74,27 @@ static void printl(const char *fmt, ...)
74static int jdccp_sendmsg(struct kiocb *iocb, struct sock *sk, 74static int jdccp_sendmsg(struct kiocb *iocb, struct sock *sk,
75 struct msghdr *msg, size_t size) 75 struct msghdr *msg, size_t size)
76{ 76{
77 const struct dccp_minisock *dmsk = dccp_msk(sk);
78 const struct inet_sock *inet = inet_sk(sk); 77 const struct inet_sock *inet = inet_sk(sk);
79 const struct ccid3_hc_tx_sock *hctx; 78 struct ccid3_hc_tx_sock *hctx = NULL;
80 79
81 if (dmsk->dccpms_tx_ccid == DCCPC_CCID3) 80 if (ccid_get_current_tx_ccid(dccp_sk(sk)) == DCCPC_CCID3)
82 hctx = ccid3_hc_tx_sk(sk); 81 hctx = ccid3_hc_tx_sk(sk);
83 else
84 hctx = NULL;
85 82
86 if (port == 0 || ntohs(inet->dport) == port || 83 if (port == 0 || ntohs(inet->dport) == port ||
87 ntohs(inet->sport) == port) { 84 ntohs(inet->sport) == port) {
88 if (hctx) 85 if (hctx)
89 printl("%d.%d.%d.%d:%u %d.%d.%d.%d:%u %d %d %d %d %u " 86 printl("%pI4:%u %pI4:%u %d %d %d %d %u "
90 "%llu %llu %d\n", 87 "%llu %llu %d\n",
91 NIPQUAD(inet->saddr), ntohs(inet->sport), 88 &inet->saddr, ntohs(inet->sport),
92 NIPQUAD(inet->daddr), ntohs(inet->dport), size, 89 &inet->daddr, ntohs(inet->dport), size,
93 hctx->ccid3hctx_s, hctx->ccid3hctx_rtt, 90 hctx->ccid3hctx_s, hctx->ccid3hctx_rtt,
94 hctx->ccid3hctx_p, hctx->ccid3hctx_x_calc, 91 hctx->ccid3hctx_p, hctx->ccid3hctx_x_calc,
95 hctx->ccid3hctx_x_recv >> 6, 92 hctx->ccid3hctx_x_recv >> 6,
96 hctx->ccid3hctx_x >> 6, hctx->ccid3hctx_t_ipi); 93 hctx->ccid3hctx_x >> 6, hctx->ccid3hctx_t_ipi);
97 else 94 else
98 printl("%d.%d.%d.%d:%u %d.%d.%d.%d:%u %d\n", 95 printl("%pI4:%u %pI4:%u %d\n",
99 NIPQUAD(inet->saddr), ntohs(inet->sport), 96 &inet->saddr, ntohs(inet->sport),
100 NIPQUAD(inet->daddr), ntohs(inet->dport), size); 97 &inet->daddr, ntohs(inet->dport), size);
101 } 98 }
102 99
103 jprobe_return(); 100 jprobe_return();
diff --git a/net/dccp/proto.c b/net/dccp/proto.c
index d0bd34819761..d5c2bacb713c 100644
--- a/net/dccp/proto.c
+++ b/net/dccp/proto.c
@@ -40,16 +40,10 @@ DEFINE_SNMP_STAT(struct dccp_mib, dccp_statistics) __read_mostly;
40 40
41EXPORT_SYMBOL_GPL(dccp_statistics); 41EXPORT_SYMBOL_GPL(dccp_statistics);
42 42
43atomic_t dccp_orphan_count = ATOMIC_INIT(0); 43struct percpu_counter dccp_orphan_count;
44
45EXPORT_SYMBOL_GPL(dccp_orphan_count); 44EXPORT_SYMBOL_GPL(dccp_orphan_count);
46 45
47struct inet_hashinfo __cacheline_aligned dccp_hashinfo = { 46struct inet_hashinfo dccp_hashinfo;
48 .lhash_lock = RW_LOCK_UNLOCKED,
49 .lhash_users = ATOMIC_INIT(0),
50 .lhash_wait = __WAIT_QUEUE_HEAD_INITIALIZER(dccp_hashinfo.lhash_wait),
51};
52
53EXPORT_SYMBOL_GPL(dccp_hashinfo); 47EXPORT_SYMBOL_GPL(dccp_hashinfo);
54 48
55/* the maximum queue length for tx in packets. 0 is no limit */ 49/* the maximum queue length for tx in packets. 0 is no limit */
@@ -67,6 +61,9 @@ void dccp_set_state(struct sock *sk, const int state)
67 case DCCP_OPEN: 61 case DCCP_OPEN:
68 if (oldstate != DCCP_OPEN) 62 if (oldstate != DCCP_OPEN)
69 DCCP_INC_STATS(DCCP_MIB_CURRESTAB); 63 DCCP_INC_STATS(DCCP_MIB_CURRESTAB);
64 /* Client retransmits all Confirm options until entering OPEN */
65 if (oldstate == DCCP_PARTOPEN)
66 dccp_feat_list_purge(&dccp_sk(sk)->dccps_featneg);
70 break; 67 break;
71 68
72 case DCCP_CLOSED: 69 case DCCP_CLOSED:
@@ -175,7 +172,6 @@ EXPORT_SYMBOL_GPL(dccp_state_name);
175int dccp_init_sock(struct sock *sk, const __u8 ctl_sock_initialized) 172int dccp_init_sock(struct sock *sk, const __u8 ctl_sock_initialized)
176{ 173{
177 struct dccp_sock *dp = dccp_sk(sk); 174 struct dccp_sock *dp = dccp_sk(sk);
178 struct dccp_minisock *dmsk = dccp_msk(sk);
179 struct inet_connection_sock *icsk = inet_csk(sk); 175 struct inet_connection_sock *icsk = inet_csk(sk);
180 176
181 dccp_minisock_init(&dp->dccps_minisock); 177 dccp_minisock_init(&dp->dccps_minisock);
@@ -193,45 +189,10 @@ int dccp_init_sock(struct sock *sk, const __u8 ctl_sock_initialized)
193 189
194 dccp_init_xmit_timers(sk); 190 dccp_init_xmit_timers(sk);
195 191
196 /* 192 INIT_LIST_HEAD(&dp->dccps_featneg);
197 * FIXME: We're hardcoding the CCID, and doing this at this point makes 193 /* control socket doesn't need feat nego */
198 * the listening (master) sock get CCID control blocks, which is not 194 if (likely(ctl_sock_initialized))
199 * necessary, but for now, to not mess with the test userspace apps, 195 return dccp_feat_init(sk);
200 * lets leave it here, later the real solution is to do this in a
201 * setsockopt(CCIDs-I-want/accept). -acme
202 */
203 if (likely(ctl_sock_initialized)) {
204 int rc = dccp_feat_init(dmsk);
205
206 if (rc)
207 return rc;
208
209 if (dmsk->dccpms_send_ack_vector) {
210 dp->dccps_hc_rx_ackvec = dccp_ackvec_alloc(GFP_KERNEL);
211 if (dp->dccps_hc_rx_ackvec == NULL)
212 return -ENOMEM;
213 }
214 dp->dccps_hc_rx_ccid = ccid_hc_rx_new(dmsk->dccpms_rx_ccid,
215 sk, GFP_KERNEL);
216 dp->dccps_hc_tx_ccid = ccid_hc_tx_new(dmsk->dccpms_tx_ccid,
217 sk, GFP_KERNEL);
218 if (unlikely(dp->dccps_hc_rx_ccid == NULL ||
219 dp->dccps_hc_tx_ccid == NULL)) {
220 ccid_hc_rx_delete(dp->dccps_hc_rx_ccid, sk);
221 ccid_hc_tx_delete(dp->dccps_hc_tx_ccid, sk);
222 if (dmsk->dccpms_send_ack_vector) {
223 dccp_ackvec_free(dp->dccps_hc_rx_ackvec);
224 dp->dccps_hc_rx_ackvec = NULL;
225 }
226 dp->dccps_hc_rx_ccid = dp->dccps_hc_tx_ccid = NULL;
227 return -ENOMEM;
228 }
229 } else {
230 /* control socket doesn't need feat nego */
231 INIT_LIST_HEAD(&dmsk->dccpms_pending);
232 INIT_LIST_HEAD(&dmsk->dccpms_conf);
233 }
234
235 return 0; 196 return 0;
236} 197}
237 198
@@ -240,7 +201,6 @@ EXPORT_SYMBOL_GPL(dccp_init_sock);
240void dccp_destroy_sock(struct sock *sk) 201void dccp_destroy_sock(struct sock *sk)
241{ 202{
242 struct dccp_sock *dp = dccp_sk(sk); 203 struct dccp_sock *dp = dccp_sk(sk);
243 struct dccp_minisock *dmsk = dccp_msk(sk);
244 204
245 /* 205 /*
246 * DCCP doesn't use sk_write_queue, just sk_send_head 206 * DCCP doesn't use sk_write_queue, just sk_send_head
@@ -258,7 +218,7 @@ void dccp_destroy_sock(struct sock *sk)
258 kfree(dp->dccps_service_list); 218 kfree(dp->dccps_service_list);
259 dp->dccps_service_list = NULL; 219 dp->dccps_service_list = NULL;
260 220
261 if (dmsk->dccpms_send_ack_vector) { 221 if (dp->dccps_hc_rx_ackvec != NULL) {
262 dccp_ackvec_free(dp->dccps_hc_rx_ackvec); 222 dccp_ackvec_free(dp->dccps_hc_rx_ackvec);
263 dp->dccps_hc_rx_ackvec = NULL; 223 dp->dccps_hc_rx_ackvec = NULL;
264 } 224 }
@@ -267,7 +227,7 @@ void dccp_destroy_sock(struct sock *sk)
267 dp->dccps_hc_rx_ccid = dp->dccps_hc_tx_ccid = NULL; 227 dp->dccps_hc_rx_ccid = dp->dccps_hc_tx_ccid = NULL;
268 228
269 /* clean up feature negotiation state */ 229 /* clean up feature negotiation state */
270 dccp_feat_clean(dmsk); 230 dccp_feat_list_purge(&dp->dccps_featneg);
271} 231}
272 232
273EXPORT_SYMBOL_GPL(dccp_destroy_sock); 233EXPORT_SYMBOL_GPL(dccp_destroy_sock);
@@ -277,6 +237,9 @@ static inline int dccp_listen_start(struct sock *sk, int backlog)
277 struct dccp_sock *dp = dccp_sk(sk); 237 struct dccp_sock *dp = dccp_sk(sk);
278 238
279 dp->dccps_role = DCCP_ROLE_LISTEN; 239 dp->dccps_role = DCCP_ROLE_LISTEN;
240 /* do not start to listen if feature negotiation setup fails */
241 if (dccp_feat_finalise_settings(dp))
242 return -EPROTO;
280 return inet_csk_listen_start(sk, backlog); 243 return inet_csk_listen_start(sk, backlog);
281} 244}
282 245
@@ -466,42 +429,70 @@ static int dccp_setsockopt_service(struct sock *sk, const __be32 service,
466 return 0; 429 return 0;
467} 430}
468 431
469/* byte 1 is feature. the rest is the preference list */ 432static int dccp_setsockopt_cscov(struct sock *sk, int cscov, bool rx)
470static int dccp_setsockopt_change(struct sock *sk, int type,
471 struct dccp_so_feat __user *optval)
472{ 433{
473 struct dccp_so_feat opt; 434 u8 *list, len;
474 u8 *val; 435 int i, rc;
475 int rc;
476 436
477 if (copy_from_user(&opt, optval, sizeof(opt))) 437 if (cscov < 0 || cscov > 15)
478 return -EFAULT; 438 return -EINVAL;
479 /* 439 /*
480 * rfc4340: 6.1. Change Options 440 * Populate a list of permissible values, in the range cscov...15. This
441 * is necessary since feature negotiation of single values only works if
442 * both sides incidentally choose the same value. Since the list starts
443 * lowest-value first, negotiation will pick the smallest shared value.
481 */ 444 */
482 if (opt.dccpsf_len < 1) 445 if (cscov == 0)
446 return 0;
447 len = 16 - cscov;
448
449 list = kmalloc(len, GFP_KERNEL);
450 if (list == NULL)
451 return -ENOBUFS;
452
453 for (i = 0; i < len; i++)
454 list[i] = cscov++;
455
456 rc = dccp_feat_register_sp(sk, DCCPF_MIN_CSUM_COVER, rx, list, len);
457
458 if (rc == 0) {
459 if (rx)
460 dccp_sk(sk)->dccps_pcrlen = cscov;
461 else
462 dccp_sk(sk)->dccps_pcslen = cscov;
463 }
464 kfree(list);
465 return rc;
466}
467
468static int dccp_setsockopt_ccid(struct sock *sk, int type,
469 char __user *optval, int optlen)
470{
471 u8 *val;
472 int rc = 0;
473
474 if (optlen < 1 || optlen > DCCP_FEAT_MAX_SP_VALS)
483 return -EINVAL; 475 return -EINVAL;
484 476
485 val = kmalloc(opt.dccpsf_len, GFP_KERNEL); 477 val = kmalloc(optlen, GFP_KERNEL);
486 if (!val) 478 if (val == NULL)
487 return -ENOMEM; 479 return -ENOMEM;
488 480
489 if (copy_from_user(val, opt.dccpsf_val, opt.dccpsf_len)) { 481 if (copy_from_user(val, optval, optlen)) {
490 rc = -EFAULT; 482 kfree(val);
491 goto out_free_val; 483 return -EFAULT;
492 } 484 }
493 485
494 rc = dccp_feat_change(dccp_msk(sk), type, opt.dccpsf_feat, 486 lock_sock(sk);
495 val, opt.dccpsf_len, GFP_KERNEL); 487 if (type == DCCP_SOCKOPT_TX_CCID || type == DCCP_SOCKOPT_CCID)
496 if (rc) 488 rc = dccp_feat_register_sp(sk, DCCPF_CCID, 1, val, optlen);
497 goto out_free_val;
498 489
499out: 490 if (!rc && (type == DCCP_SOCKOPT_RX_CCID || type == DCCP_SOCKOPT_CCID))
500 return rc; 491 rc = dccp_feat_register_sp(sk, DCCPF_CCID, 0, val, optlen);
492 release_sock(sk);
501 493
502out_free_val:
503 kfree(val); 494 kfree(val);
504 goto out; 495 return rc;
505} 496}
506 497
507static int do_dccp_setsockopt(struct sock *sk, int level, int optname, 498static int do_dccp_setsockopt(struct sock *sk, int level, int optname,
@@ -510,7 +501,21 @@ static int do_dccp_setsockopt(struct sock *sk, int level, int optname,
510 struct dccp_sock *dp = dccp_sk(sk); 501 struct dccp_sock *dp = dccp_sk(sk);
511 int val, err = 0; 502 int val, err = 0;
512 503
513 if (optlen < sizeof(int)) 504 switch (optname) {
505 case DCCP_SOCKOPT_PACKET_SIZE:
506 DCCP_WARN("sockopt(PACKET_SIZE) is deprecated: fix your app\n");
507 return 0;
508 case DCCP_SOCKOPT_CHANGE_L:
509 case DCCP_SOCKOPT_CHANGE_R:
510 DCCP_WARN("sockopt(CHANGE_L/R) is deprecated: fix your app\n");
511 return 0;
512 case DCCP_SOCKOPT_CCID:
513 case DCCP_SOCKOPT_RX_CCID:
514 case DCCP_SOCKOPT_TX_CCID:
515 return dccp_setsockopt_ccid(sk, optname, optval, optlen);
516 }
517
518 if (optlen < (int)sizeof(int))
514 return -EINVAL; 519 return -EINVAL;
515 520
516 if (get_user(val, (int __user *)optval)) 521 if (get_user(val, (int __user *)optval))
@@ -521,53 +526,24 @@ static int do_dccp_setsockopt(struct sock *sk, int level, int optname,
521 526
522 lock_sock(sk); 527 lock_sock(sk);
523 switch (optname) { 528 switch (optname) {
524 case DCCP_SOCKOPT_PACKET_SIZE:
525 DCCP_WARN("sockopt(PACKET_SIZE) is deprecated: fix your app\n");
526 err = 0;
527 break;
528 case DCCP_SOCKOPT_CHANGE_L:
529 if (optlen != sizeof(struct dccp_so_feat))
530 err = -EINVAL;
531 else
532 err = dccp_setsockopt_change(sk, DCCPO_CHANGE_L,
533 (struct dccp_so_feat __user *)
534 optval);
535 break;
536 case DCCP_SOCKOPT_CHANGE_R:
537 if (optlen != sizeof(struct dccp_so_feat))
538 err = -EINVAL;
539 else
540 err = dccp_setsockopt_change(sk, DCCPO_CHANGE_R,
541 (struct dccp_so_feat __user *)
542 optval);
543 break;
544 case DCCP_SOCKOPT_SERVER_TIMEWAIT: 529 case DCCP_SOCKOPT_SERVER_TIMEWAIT:
545 if (dp->dccps_role != DCCP_ROLE_SERVER) 530 if (dp->dccps_role != DCCP_ROLE_SERVER)
546 err = -EOPNOTSUPP; 531 err = -EOPNOTSUPP;
547 else 532 else
548 dp->dccps_server_timewait = (val != 0); 533 dp->dccps_server_timewait = (val != 0);
549 break; 534 break;
550 case DCCP_SOCKOPT_SEND_CSCOV: /* sender side, RFC 4340, sec. 9.2 */ 535 case DCCP_SOCKOPT_SEND_CSCOV:
551 if (val < 0 || val > 15) 536 err = dccp_setsockopt_cscov(sk, val, false);
552 err = -EINVAL;
553 else
554 dp->dccps_pcslen = val;
555 break; 537 break;
556 case DCCP_SOCKOPT_RECV_CSCOV: /* receiver side, RFC 4340 sec. 9.2.1 */ 538 case DCCP_SOCKOPT_RECV_CSCOV:
557 if (val < 0 || val > 15) 539 err = dccp_setsockopt_cscov(sk, val, true);
558 err = -EINVAL;
559 else {
560 dp->dccps_pcrlen = val;
561 /* FIXME: add feature negotiation,
562 * ChangeL(MinimumChecksumCoverage, val) */
563 }
564 break; 540 break;
565 default: 541 default:
566 err = -ENOPROTOOPT; 542 err = -ENOPROTOOPT;
567 break; 543 break;
568 } 544 }
569
570 release_sock(sk); 545 release_sock(sk);
546
571 return err; 547 return err;
572} 548}
573 549
@@ -648,6 +624,18 @@ static int do_dccp_getsockopt(struct sock *sk, int level, int optname,
648 case DCCP_SOCKOPT_GET_CUR_MPS: 624 case DCCP_SOCKOPT_GET_CUR_MPS:
649 val = dp->dccps_mss_cache; 625 val = dp->dccps_mss_cache;
650 break; 626 break;
627 case DCCP_SOCKOPT_AVAILABLE_CCIDS:
628 return ccid_getsockopt_builtin_ccids(sk, len, optval, optlen);
629 case DCCP_SOCKOPT_TX_CCID:
630 val = ccid_get_current_tx_ccid(dp);
631 if (val < 0)
632 return -ENOPROTOOPT;
633 break;
634 case DCCP_SOCKOPT_RX_CCID:
635 val = ccid_get_current_rx_ccid(dp);
636 if (val < 0)
637 return -ENOPROTOOPT;
638 break;
651 case DCCP_SOCKOPT_SERVER_TIMEWAIT: 639 case DCCP_SOCKOPT_SERVER_TIMEWAIT:
652 val = dp->dccps_server_timewait; 640 val = dp->dccps_server_timewait;
653 break; 641 break;
@@ -976,7 +964,7 @@ adjudge_to_death:
976 state = sk->sk_state; 964 state = sk->sk_state;
977 sock_hold(sk); 965 sock_hold(sk);
978 sock_orphan(sk); 966 sock_orphan(sk);
979 atomic_inc(sk->sk_prot->orphan_count); 967 percpu_counter_inc(sk->sk_prot->orphan_count);
980 968
981 /* 969 /*
982 * It is the last release_sock in its life. It will remove backlog. 970 * It is the last release_sock in its life. It will remove backlog.
@@ -1040,17 +1028,21 @@ static int __init dccp_init(void)
1040{ 1028{
1041 unsigned long goal; 1029 unsigned long goal;
1042 int ehash_order, bhash_order, i; 1030 int ehash_order, bhash_order, i;
1043 int rc = -ENOBUFS; 1031 int rc;
1044 1032
1045 BUILD_BUG_ON(sizeof(struct dccp_skb_cb) > 1033 BUILD_BUG_ON(sizeof(struct dccp_skb_cb) >
1046 FIELD_SIZEOF(struct sk_buff, cb)); 1034 FIELD_SIZEOF(struct sk_buff, cb));
1047 1035 rc = percpu_counter_init(&dccp_orphan_count, 0);
1036 if (rc)
1037 goto out;
1038 rc = -ENOBUFS;
1039 inet_hashinfo_init(&dccp_hashinfo);
1048 dccp_hashinfo.bind_bucket_cachep = 1040 dccp_hashinfo.bind_bucket_cachep =
1049 kmem_cache_create("dccp_bind_bucket", 1041 kmem_cache_create("dccp_bind_bucket",
1050 sizeof(struct inet_bind_bucket), 0, 1042 sizeof(struct inet_bind_bucket), 0,
1051 SLAB_HWCACHE_ALIGN, NULL); 1043 SLAB_HWCACHE_ALIGN, NULL);
1052 if (!dccp_hashinfo.bind_bucket_cachep) 1044 if (!dccp_hashinfo.bind_bucket_cachep)
1053 goto out; 1045 goto out_free_percpu;
1054 1046
1055 /* 1047 /*
1056 * Size and allocate the main established and bind bucket 1048 * Size and allocate the main established and bind bucket
@@ -1084,8 +1076,8 @@ static int __init dccp_init(void)
1084 } 1076 }
1085 1077
1086 for (i = 0; i < dccp_hashinfo.ehash_size; i++) { 1078 for (i = 0; i < dccp_hashinfo.ehash_size; i++) {
1087 INIT_HLIST_HEAD(&dccp_hashinfo.ehash[i].chain); 1079 INIT_HLIST_NULLS_HEAD(&dccp_hashinfo.ehash[i].chain, i);
1088 INIT_HLIST_HEAD(&dccp_hashinfo.ehash[i].twchain); 1080 INIT_HLIST_NULLS_HEAD(&dccp_hashinfo.ehash[i].twchain, i);
1089 } 1081 }
1090 1082
1091 if (inet_ehash_locks_alloc(&dccp_hashinfo)) 1083 if (inet_ehash_locks_alloc(&dccp_hashinfo))
@@ -1143,6 +1135,8 @@ out_free_dccp_ehash:
1143out_free_bind_bucket_cachep: 1135out_free_bind_bucket_cachep:
1144 kmem_cache_destroy(dccp_hashinfo.bind_bucket_cachep); 1136 kmem_cache_destroy(dccp_hashinfo.bind_bucket_cachep);
1145 dccp_hashinfo.bind_bucket_cachep = NULL; 1137 dccp_hashinfo.bind_bucket_cachep = NULL;
1138out_free_percpu:
1139 percpu_counter_destroy(&dccp_orphan_count);
1146 goto out; 1140 goto out;
1147} 1141}
1148 1142
diff --git a/net/dccp/sysctl.c b/net/dccp/sysctl.c
index 21295993fdb8..018e210875e1 100644
--- a/net/dccp/sysctl.c
+++ b/net/dccp/sysctl.c
@@ -41,27 +41,6 @@ static struct ctl_table dccp_default_table[] = {
41 .proc_handler = proc_dointvec, 41 .proc_handler = proc_dointvec,
42 }, 42 },
43 { 43 {
44 .procname = "ack_ratio",
45 .data = &sysctl_dccp_feat_ack_ratio,
46 .maxlen = sizeof(sysctl_dccp_feat_ack_ratio),
47 .mode = 0644,
48 .proc_handler = proc_dointvec,
49 },
50 {
51 .procname = "send_ackvec",
52 .data = &sysctl_dccp_feat_send_ack_vector,
53 .maxlen = sizeof(sysctl_dccp_feat_send_ack_vector),
54 .mode = 0644,
55 .proc_handler = proc_dointvec,
56 },
57 {
58 .procname = "send_ndp",
59 .data = &sysctl_dccp_feat_send_ndp_count,
60 .maxlen = sizeof(sysctl_dccp_feat_send_ndp_count),
61 .mode = 0644,
62 .proc_handler = proc_dointvec,
63 },
64 {
65 .procname = "request_retries", 44 .procname = "request_retries",
66 .data = &sysctl_dccp_request_retries, 45 .data = &sysctl_dccp_request_retries,
67 .maxlen = sizeof(sysctl_dccp_request_retries), 46 .maxlen = sizeof(sysctl_dccp_request_retries),
diff --git a/net/dccp/timer.c b/net/dccp/timer.c
index 54b3c7e9e016..162d1e683c39 100644
--- a/net/dccp/timer.c
+++ b/net/dccp/timer.c
@@ -87,17 +87,6 @@ static void dccp_retransmit_timer(struct sock *sk)
87{ 87{
88 struct inet_connection_sock *icsk = inet_csk(sk); 88 struct inet_connection_sock *icsk = inet_csk(sk);
89 89
90 /* retransmit timer is used for feature negotiation throughout
91 * connection. In this case, no packet is re-transmitted, but rather an
92 * ack is generated and pending changes are placed into its options.
93 */
94 if (sk->sk_send_head == NULL) {
95 dccp_pr_debug("feat negotiation retransmit timeout %p\n", sk);
96 if (sk->sk_state == DCCP_OPEN)
97 dccp_send_ack(sk);
98 goto backoff;
99 }
100
101 /* 90 /*
102 * More than than 4MSL (8 minutes) has passed, a RESET(aborted) was 91 * More than than 4MSL (8 minutes) has passed, a RESET(aborted) was
103 * sent, no need to retransmit, this sock is dead. 92 * sent, no need to retransmit, this sock is dead.
@@ -126,7 +115,6 @@ static void dccp_retransmit_timer(struct sock *sk)
126 return; 115 return;
127 } 116 }
128 117
129backoff:
130 icsk->icsk_backoff++; 118 icsk->icsk_backoff++;
131 119
132 icsk->icsk_rto = min(icsk->icsk_rto << 1, DCCP_RTO_MAX); 120 icsk->icsk_rto = min(icsk->icsk_rto << 1, DCCP_RTO_MAX);
diff --git a/net/decnet/af_decnet.c b/net/decnet/af_decnet.c
index 3c23ab33dbc0..cf0e18499297 100644
--- a/net/decnet/af_decnet.c
+++ b/net/decnet/af_decnet.c
@@ -167,7 +167,7 @@ static struct hlist_head *dn_find_list(struct sock *sk)
167 if (scp->addr.sdn_flags & SDF_WILD) 167 if (scp->addr.sdn_flags & SDF_WILD)
168 return hlist_empty(&dn_wild_sk) ? &dn_wild_sk : NULL; 168 return hlist_empty(&dn_wild_sk) ? &dn_wild_sk : NULL;
169 169
170 return &dn_sk_hash[dn_ntohs(scp->addrloc) & DN_SK_HASH_MASK]; 170 return &dn_sk_hash[le16_to_cpu(scp->addrloc) & DN_SK_HASH_MASK];
171} 171}
172 172
173/* 173/*
@@ -181,7 +181,7 @@ static int check_port(__le16 port)
181 if (port == 0) 181 if (port == 0)
182 return -1; 182 return -1;
183 183
184 sk_for_each(sk, node, &dn_sk_hash[dn_ntohs(port) & DN_SK_HASH_MASK]) { 184 sk_for_each(sk, node, &dn_sk_hash[le16_to_cpu(port) & DN_SK_HASH_MASK]) {
185 struct dn_scp *scp = DN_SK(sk); 185 struct dn_scp *scp = DN_SK(sk);
186 if (scp->addrloc == port) 186 if (scp->addrloc == port)
187 return -1; 187 return -1;
@@ -195,12 +195,12 @@ static unsigned short port_alloc(struct sock *sk)
195static unsigned short port = 0x2000; 195static unsigned short port = 0x2000;
196 unsigned short i_port = port; 196 unsigned short i_port = port;
197 197
198 while(check_port(dn_htons(++port)) != 0) { 198 while(check_port(cpu_to_le16(++port)) != 0) {
199 if (port == i_port) 199 if (port == i_port)
200 return 0; 200 return 0;
201 } 201 }
202 202
203 scp->addrloc = dn_htons(port); 203 scp->addrloc = cpu_to_le16(port);
204 204
205 return 1; 205 return 1;
206} 206}
@@ -255,7 +255,7 @@ static struct hlist_head *listen_hash(struct sockaddr_dn *addr)
255 255
256 if (hash == 0) { 256 if (hash == 0) {
257 hash = addr->sdn_objnamel; 257 hash = addr->sdn_objnamel;
258 for(i = 0; i < dn_ntohs(addr->sdn_objnamel); i++) { 258 for(i = 0; i < le16_to_cpu(addr->sdn_objnamel); i++) {
259 hash ^= addr->sdn_objname[i]; 259 hash ^= addr->sdn_objname[i];
260 hash ^= (hash << 3); 260 hash ^= (hash << 3);
261 } 261 }
@@ -297,16 +297,16 @@ int dn_sockaddr2username(struct sockaddr_dn *sdn, unsigned char *buf, unsigned c
297 break; 297 break;
298 case 1: 298 case 1:
299 *buf++ = 0; 299 *buf++ = 0;
300 *buf++ = dn_ntohs(sdn->sdn_objnamel); 300 *buf++ = le16_to_cpu(sdn->sdn_objnamel);
301 memcpy(buf, sdn->sdn_objname, dn_ntohs(sdn->sdn_objnamel)); 301 memcpy(buf, sdn->sdn_objname, le16_to_cpu(sdn->sdn_objnamel));
302 len = 3 + dn_ntohs(sdn->sdn_objnamel); 302 len = 3 + le16_to_cpu(sdn->sdn_objnamel);
303 break; 303 break;
304 case 2: 304 case 2:
305 memset(buf, 0, 5); 305 memset(buf, 0, 5);
306 buf += 5; 306 buf += 5;
307 *buf++ = dn_ntohs(sdn->sdn_objnamel); 307 *buf++ = le16_to_cpu(sdn->sdn_objnamel);
308 memcpy(buf, sdn->sdn_objname, dn_ntohs(sdn->sdn_objnamel)); 308 memcpy(buf, sdn->sdn_objname, le16_to_cpu(sdn->sdn_objnamel));
309 len = 7 + dn_ntohs(sdn->sdn_objnamel); 309 len = 7 + le16_to_cpu(sdn->sdn_objnamel);
310 break; 310 break;
311 } 311 }
312 312
@@ -327,7 +327,7 @@ int dn_username2sockaddr(unsigned char *data, int len, struct sockaddr_dn *sdn,
327 int namel = 12; 327 int namel = 12;
328 328
329 sdn->sdn_objnum = 0; 329 sdn->sdn_objnum = 0;
330 sdn->sdn_objnamel = dn_htons(0); 330 sdn->sdn_objnamel = cpu_to_le16(0);
331 memset(sdn->sdn_objname, 0, DN_MAXOBJL); 331 memset(sdn->sdn_objname, 0, DN_MAXOBJL);
332 332
333 if (len < 2) 333 if (len < 2)
@@ -361,13 +361,13 @@ int dn_username2sockaddr(unsigned char *data, int len, struct sockaddr_dn *sdn,
361 if (len < 0) 361 if (len < 0)
362 return -1; 362 return -1;
363 363
364 sdn->sdn_objnamel = dn_htons(*data++); 364 sdn->sdn_objnamel = cpu_to_le16(*data++);
365 len -= dn_ntohs(sdn->sdn_objnamel); 365 len -= le16_to_cpu(sdn->sdn_objnamel);
366 366
367 if ((len < 0) || (dn_ntohs(sdn->sdn_objnamel) > namel)) 367 if ((len < 0) || (le16_to_cpu(sdn->sdn_objnamel) > namel))
368 return -1; 368 return -1;
369 369
370 memcpy(sdn->sdn_objname, data, dn_ntohs(sdn->sdn_objnamel)); 370 memcpy(sdn->sdn_objname, data, le16_to_cpu(sdn->sdn_objnamel));
371 371
372 return size - len; 372 return size - len;
373} 373}
@@ -391,7 +391,7 @@ struct sock *dn_sklist_find_listener(struct sockaddr_dn *addr)
391 continue; 391 continue;
392 if (scp->addr.sdn_objnamel != addr->sdn_objnamel) 392 if (scp->addr.sdn_objnamel != addr->sdn_objnamel)
393 continue; 393 continue;
394 if (memcmp(scp->addr.sdn_objname, addr->sdn_objname, dn_ntohs(addr->sdn_objnamel)) != 0) 394 if (memcmp(scp->addr.sdn_objname, addr->sdn_objname, le16_to_cpu(addr->sdn_objnamel)) != 0)
395 continue; 395 continue;
396 } 396 }
397 sock_hold(sk); 397 sock_hold(sk);
@@ -419,7 +419,7 @@ struct sock *dn_find_by_skb(struct sk_buff *skb)
419 struct dn_scp *scp; 419 struct dn_scp *scp;
420 420
421 read_lock(&dn_hash_lock); 421 read_lock(&dn_hash_lock);
422 sk_for_each(sk, node, &dn_sk_hash[dn_ntohs(cb->dst_port) & DN_SK_HASH_MASK]) { 422 sk_for_each(sk, node, &dn_sk_hash[le16_to_cpu(cb->dst_port) & DN_SK_HASH_MASK]) {
423 scp = DN_SK(sk); 423 scp = DN_SK(sk);
424 if (cb->src != dn_saddr2dn(&scp->peer)) 424 if (cb->src != dn_saddr2dn(&scp->peer))
425 continue; 425 continue;
@@ -734,10 +734,10 @@ static int dn_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
734 if (saddr->sdn_family != AF_DECnet) 734 if (saddr->sdn_family != AF_DECnet)
735 return -EINVAL; 735 return -EINVAL;
736 736
737 if (dn_ntohs(saddr->sdn_nodeaddrl) && (dn_ntohs(saddr->sdn_nodeaddrl) != 2)) 737 if (le16_to_cpu(saddr->sdn_nodeaddrl) && (le16_to_cpu(saddr->sdn_nodeaddrl) != 2))
738 return -EINVAL; 738 return -EINVAL;
739 739
740 if (dn_ntohs(saddr->sdn_objnamel) > DN_MAXOBJL) 740 if (le16_to_cpu(saddr->sdn_objnamel) > DN_MAXOBJL)
741 return -EINVAL; 741 return -EINVAL;
742 742
743 if (saddr->sdn_flags & ~SDF_WILD) 743 if (saddr->sdn_flags & ~SDF_WILD)
@@ -748,7 +748,7 @@ static int dn_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
748 return -EACCES; 748 return -EACCES;
749 749
750 if (!(saddr->sdn_flags & SDF_WILD)) { 750 if (!(saddr->sdn_flags & SDF_WILD)) {
751 if (dn_ntohs(saddr->sdn_nodeaddrl)) { 751 if (le16_to_cpu(saddr->sdn_nodeaddrl)) {
752 read_lock(&dev_base_lock); 752 read_lock(&dev_base_lock);
753 ldev = NULL; 753 ldev = NULL;
754 for_each_netdev(&init_net, dev) { 754 for_each_netdev(&init_net, dev) {
@@ -799,15 +799,15 @@ static int dn_auto_bind(struct socket *sock)
799 if ((scp->accessdata.acc_accl != 0) && 799 if ((scp->accessdata.acc_accl != 0) &&
800 (scp->accessdata.acc_accl <= 12)) { 800 (scp->accessdata.acc_accl <= 12)) {
801 801
802 scp->addr.sdn_objnamel = dn_htons(scp->accessdata.acc_accl); 802 scp->addr.sdn_objnamel = cpu_to_le16(scp->accessdata.acc_accl);
803 memcpy(scp->addr.sdn_objname, scp->accessdata.acc_acc, dn_ntohs(scp->addr.sdn_objnamel)); 803 memcpy(scp->addr.sdn_objname, scp->accessdata.acc_acc, le16_to_cpu(scp->addr.sdn_objnamel));
804 804
805 scp->accessdata.acc_accl = 0; 805 scp->accessdata.acc_accl = 0;
806 memset(scp->accessdata.acc_acc, 0, 40); 806 memset(scp->accessdata.acc_acc, 0, 40);
807 } 807 }
808 /* End of compatibility stuff */ 808 /* End of compatibility stuff */
809 809
810 scp->addr.sdn_add.a_len = dn_htons(2); 810 scp->addr.sdn_add.a_len = cpu_to_le16(2);
811 rv = dn_dev_bind_default((__le16 *)scp->addr.sdn_add.a_addr); 811 rv = dn_dev_bind_default((__le16 *)scp->addr.sdn_add.a_addr);
812 if (rv == 0) { 812 if (rv == 0) {
813 rv = dn_hash_sock(sk); 813 rv = dn_hash_sock(sk);
@@ -1027,7 +1027,7 @@ static void dn_user_copy(struct sk_buff *skb, struct optdata_dn *opt)
1027 u16 len = *ptr++; /* yes, it's 8bit on the wire */ 1027 u16 len = *ptr++; /* yes, it's 8bit on the wire */
1028 1028
1029 BUG_ON(len > 16); /* we've checked the contents earlier */ 1029 BUG_ON(len > 16); /* we've checked the contents earlier */
1030 opt->opt_optl = dn_htons(len); 1030 opt->opt_optl = cpu_to_le16(len);
1031 opt->opt_status = 0; 1031 opt->opt_status = 0;
1032 memcpy(opt->opt_data, ptr, len); 1032 memcpy(opt->opt_data, ptr, len);
1033 skb_pull(skb, len + 1); 1033 skb_pull(skb, len + 1);
@@ -1375,7 +1375,7 @@ static int __dn_setsockopt(struct socket *sock, int level,int optname, char __us
1375 if (optlen != sizeof(struct optdata_dn)) 1375 if (optlen != sizeof(struct optdata_dn))
1376 return -EINVAL; 1376 return -EINVAL;
1377 1377
1378 if (dn_ntohs(u.opt.opt_optl) > 16) 1378 if (le16_to_cpu(u.opt.opt_optl) > 16)
1379 return -EINVAL; 1379 return -EINVAL;
1380 1380
1381 memcpy(&scp->conndata_out, &u.opt, optlen); 1381 memcpy(&scp->conndata_out, &u.opt, optlen);
@@ -1388,7 +1388,7 @@ static int __dn_setsockopt(struct socket *sock, int level,int optname, char __us
1388 if (optlen != sizeof(struct optdata_dn)) 1388 if (optlen != sizeof(struct optdata_dn))
1389 return -EINVAL; 1389 return -EINVAL;
1390 1390
1391 if (dn_ntohs(u.opt.opt_optl) > 16) 1391 if (le16_to_cpu(u.opt.opt_optl) > 16)
1392 return -EINVAL; 1392 return -EINVAL;
1393 1393
1394 memcpy(&scp->discdata_out, &u.opt, optlen); 1394 memcpy(&scp->discdata_out, &u.opt, optlen);
@@ -2213,12 +2213,12 @@ static void dn_printable_object(struct sockaddr_dn *dn, unsigned char *buf)
2213{ 2213{
2214 int i; 2214 int i;
2215 2215
2216 switch (dn_ntohs(dn->sdn_objnamel)) { 2216 switch (le16_to_cpu(dn->sdn_objnamel)) {
2217 case 0: 2217 case 0:
2218 sprintf(buf, "%d", dn->sdn_objnum); 2218 sprintf(buf, "%d", dn->sdn_objnum);
2219 break; 2219 break;
2220 default: 2220 default:
2221 for (i = 0; i < dn_ntohs(dn->sdn_objnamel); i++) { 2221 for (i = 0; i < le16_to_cpu(dn->sdn_objnamel); i++) {
2222 buf[i] = dn->sdn_objname[i]; 2222 buf[i] = dn->sdn_objname[i];
2223 if (IS_NOT_PRINTABLE(buf[i])) 2223 if (IS_NOT_PRINTABLE(buf[i]))
2224 buf[i] = '.'; 2224 buf[i] = '.';
@@ -2281,7 +2281,7 @@ static inline void dn_socket_format_entry(struct seq_file *seq, struct sock *sk)
2281 seq_printf(seq, 2281 seq_printf(seq,
2282 "%6s/%04X %04d:%04d %04d:%04d %01d %-16s " 2282 "%6s/%04X %04d:%04d %04d:%04d %01d %-16s "
2283 "%6s/%04X %04d:%04d %04d:%04d %01d %-16s %4s %s\n", 2283 "%6s/%04X %04d:%04d %04d:%04d %01d %-16s %4s %s\n",
2284 dn_addr2asc(dn_ntohs(dn_saddr2dn(&scp->addr)), buf1), 2284 dn_addr2asc(le16_to_cpu(dn_saddr2dn(&scp->addr)), buf1),
2285 scp->addrloc, 2285 scp->addrloc,
2286 scp->numdat, 2286 scp->numdat,
2287 scp->numoth, 2287 scp->numoth,
@@ -2289,7 +2289,7 @@ static inline void dn_socket_format_entry(struct seq_file *seq, struct sock *sk)
2289 scp->ackxmt_oth, 2289 scp->ackxmt_oth,
2290 scp->flowloc_sw, 2290 scp->flowloc_sw,
2291 local_object, 2291 local_object,
2292 dn_addr2asc(dn_ntohs(dn_saddr2dn(&scp->peer)), buf2), 2292 dn_addr2asc(le16_to_cpu(dn_saddr2dn(&scp->peer)), buf2),
2293 scp->addrrem, 2293 scp->addrrem,
2294 scp->numdat_rcv, 2294 scp->numdat_rcv,
2295 scp->numoth_rcv, 2295 scp->numoth_rcv,
diff --git a/net/decnet/dn_dev.c b/net/decnet/dn_dev.c
index 28e26bd08e24..daf2b98b15fe 100644
--- a/net/decnet/dn_dev.c
+++ b/net/decnet/dn_dev.c
@@ -885,7 +885,7 @@ static void dn_send_endnode_hello(struct net_device *dev, struct dn_ifaddr *ifa)
885 memcpy(msg->tiver, dn_eco_version, 3); 885 memcpy(msg->tiver, dn_eco_version, 3);
886 dn_dn2eth(msg->id, ifa->ifa_local); 886 dn_dn2eth(msg->id, ifa->ifa_local);
887 msg->iinfo = DN_RT_INFO_ENDN; 887 msg->iinfo = DN_RT_INFO_ENDN;
888 msg->blksize = dn_htons(mtu2blksize(dev)); 888 msg->blksize = cpu_to_le16(mtu2blksize(dev));
889 msg->area = 0x00; 889 msg->area = 0x00;
890 memset(msg->seed, 0, 8); 890 memset(msg->seed, 0, 8);
891 memcpy(msg->neighbor, dn_hiord, ETH_ALEN); 891 memcpy(msg->neighbor, dn_hiord, ETH_ALEN);
@@ -895,13 +895,13 @@ static void dn_send_endnode_hello(struct net_device *dev, struct dn_ifaddr *ifa)
895 dn_dn2eth(msg->neighbor, dn->addr); 895 dn_dn2eth(msg->neighbor, dn->addr);
896 } 896 }
897 897
898 msg->timer = dn_htons((unsigned short)dn_db->parms.t3); 898 msg->timer = cpu_to_le16((unsigned short)dn_db->parms.t3);
899 msg->mpd = 0x00; 899 msg->mpd = 0x00;
900 msg->datalen = 0x02; 900 msg->datalen = 0x02;
901 memset(msg->data, 0xAA, 2); 901 memset(msg->data, 0xAA, 2);
902 902
903 pktlen = (__le16 *)skb_push(skb,2); 903 pktlen = (__le16 *)skb_push(skb,2);
904 *pktlen = dn_htons(skb->len - 2); 904 *pktlen = cpu_to_le16(skb->len - 2);
905 905
906 skb_reset_network_header(skb); 906 skb_reset_network_header(skb);
907 907
@@ -929,7 +929,7 @@ static int dn_am_i_a_router(struct dn_neigh *dn, struct dn_dev *dn_db, struct dn
929 if (dn->priority != dn_db->parms.priority) 929 if (dn->priority != dn_db->parms.priority)
930 return 0; 930 return 0;
931 931
932 if (dn_ntohs(dn->addr) < dn_ntohs(ifa->ifa_local)) 932 if (le16_to_cpu(dn->addr) < le16_to_cpu(ifa->ifa_local))
933 return 1; 933 return 1;
934 934
935 return 0; 935 return 0;
@@ -973,11 +973,11 @@ static void dn_send_router_hello(struct net_device *dev, struct dn_ifaddr *ifa)
973 ptr += ETH_ALEN; 973 ptr += ETH_ALEN;
974 *ptr++ = dn_db->parms.forwarding == 1 ? 974 *ptr++ = dn_db->parms.forwarding == 1 ?
975 DN_RT_INFO_L1RT : DN_RT_INFO_L2RT; 975 DN_RT_INFO_L1RT : DN_RT_INFO_L2RT;
976 *((__le16 *)ptr) = dn_htons(mtu2blksize(dev)); 976 *((__le16 *)ptr) = cpu_to_le16(mtu2blksize(dev));
977 ptr += 2; 977 ptr += 2;
978 *ptr++ = dn_db->parms.priority; /* Priority */ 978 *ptr++ = dn_db->parms.priority; /* Priority */
979 *ptr++ = 0; /* Area: Reserved */ 979 *ptr++ = 0; /* Area: Reserved */
980 *((__le16 *)ptr) = dn_htons((unsigned short)dn_db->parms.t3); 980 *((__le16 *)ptr) = cpu_to_le16((unsigned short)dn_db->parms.t3);
981 ptr += 2; 981 ptr += 2;
982 *ptr++ = 0; /* MPD: Reserved */ 982 *ptr++ = 0; /* MPD: Reserved */
983 i1 = ptr++; 983 i1 = ptr++;
@@ -993,7 +993,7 @@ static void dn_send_router_hello(struct net_device *dev, struct dn_ifaddr *ifa)
993 skb_trim(skb, (27 + *i2)); 993 skb_trim(skb, (27 + *i2));
994 994
995 pktlen = (__le16 *)skb_push(skb, 2); 995 pktlen = (__le16 *)skb_push(skb, 2);
996 *pktlen = dn_htons(skb->len - 2); 996 *pktlen = cpu_to_le16(skb->len - 2);
997 997
998 skb_reset_network_header(skb); 998 skb_reset_network_header(skb);
999 999
@@ -1106,7 +1106,7 @@ static void dn_dev_set_timer(struct net_device *dev)
1106 add_timer(&dn_db->timer); 1106 add_timer(&dn_db->timer);
1107} 1107}
1108 1108
1109struct dn_dev *dn_dev_create(struct net_device *dev, int *err) 1109static struct dn_dev *dn_dev_create(struct net_device *dev, int *err)
1110{ 1110{
1111 int i; 1111 int i;
1112 struct dn_dev_parms *p = dn_dev_list; 1112 struct dn_dev_parms *p = dn_dev_list;
@@ -1401,8 +1401,8 @@ static int dn_dev_seq_show(struct seq_file *seq, void *v)
1401 mtu2blksize(dev), 1401 mtu2blksize(dev),
1402 dn_db->parms.priority, 1402 dn_db->parms.priority,
1403 dn_db->parms.state, dn_db->parms.name, 1403 dn_db->parms.state, dn_db->parms.name,
1404 dn_db->router ? dn_addr2asc(dn_ntohs(*(__le16 *)dn_db->router->primary_key), router_buf) : "", 1404 dn_db->router ? dn_addr2asc(le16_to_cpu(*(__le16 *)dn_db->router->primary_key), router_buf) : "",
1405 dn_db->peer ? dn_addr2asc(dn_ntohs(*(__le16 *)dn_db->peer->primary_key), peer_buf) : ""); 1405 dn_db->peer ? dn_addr2asc(le16_to_cpu(*(__le16 *)dn_db->peer->primary_key), peer_buf) : "");
1406 } 1406 }
1407 return 0; 1407 return 0;
1408} 1408}
@@ -1445,7 +1445,7 @@ void __init dn_dev_init(void)
1445 return; 1445 return;
1446 } 1446 }
1447 1447
1448 decnet_address = dn_htons((addr[0] << 10) | addr[1]); 1448 decnet_address = cpu_to_le16((addr[0] << 10) | addr[1]);
1449 1449
1450 dn_dev_devices_on(); 1450 dn_dev_devices_on();
1451 1451
diff --git a/net/decnet/dn_neigh.c b/net/decnet/dn_neigh.c
index 1ca13b17974d..05b5aa05e50e 100644
--- a/net/decnet/dn_neigh.c
+++ b/net/decnet/dn_neigh.c
@@ -250,7 +250,7 @@ static int dn_long_output(struct sk_buff *skb)
250 data = skb_push(skb, sizeof(struct dn_long_packet) + 3); 250 data = skb_push(skb, sizeof(struct dn_long_packet) + 3);
251 lp = (struct dn_long_packet *)(data+3); 251 lp = (struct dn_long_packet *)(data+3);
252 252
253 *((__le16 *)data) = dn_htons(skb->len - 2); 253 *((__le16 *)data) = cpu_to_le16(skb->len - 2);
254 *(data + 2) = 1 | DN_RT_F_PF; /* Padding */ 254 *(data + 2) = 1 | DN_RT_F_PF; /* Padding */
255 255
256 lp->msgflg = DN_RT_PKT_LONG|(cb->rt_flags&(DN_RT_F_IE|DN_RT_F_RQR|DN_RT_F_RTS)); 256 lp->msgflg = DN_RT_PKT_LONG|(cb->rt_flags&(DN_RT_F_IE|DN_RT_F_RQR|DN_RT_F_RTS));
@@ -294,7 +294,7 @@ static int dn_short_output(struct sk_buff *skb)
294 } 294 }
295 295
296 data = skb_push(skb, sizeof(struct dn_short_packet) + 2); 296 data = skb_push(skb, sizeof(struct dn_short_packet) + 2);
297 *((__le16 *)data) = dn_htons(skb->len - 2); 297 *((__le16 *)data) = cpu_to_le16(skb->len - 2);
298 sp = (struct dn_short_packet *)(data+2); 298 sp = (struct dn_short_packet *)(data+2);
299 299
300 sp->msgflg = DN_RT_PKT_SHORT|(cb->rt_flags&(DN_RT_F_RQR|DN_RT_F_RTS)); 300 sp->msgflg = DN_RT_PKT_SHORT|(cb->rt_flags&(DN_RT_F_RQR|DN_RT_F_RTS));
@@ -336,12 +336,12 @@ static int dn_phase3_output(struct sk_buff *skb)
336 } 336 }
337 337
338 data = skb_push(skb, sizeof(struct dn_short_packet) + 2); 338 data = skb_push(skb, sizeof(struct dn_short_packet) + 2);
339 *((__le16 *)data) = dn_htons(skb->len - 2); 339 *((__le16 *)data) = cpu_to_le16(skb->len - 2);
340 sp = (struct dn_short_packet *)(data + 2); 340 sp = (struct dn_short_packet *)(data + 2);
341 341
342 sp->msgflg = DN_RT_PKT_SHORT|(cb->rt_flags&(DN_RT_F_RQR|DN_RT_F_RTS)); 342 sp->msgflg = DN_RT_PKT_SHORT|(cb->rt_flags&(DN_RT_F_RQR|DN_RT_F_RTS));
343 sp->dstnode = cb->dst & dn_htons(0x03ff); 343 sp->dstnode = cb->dst & cpu_to_le16(0x03ff);
344 sp->srcnode = cb->src & dn_htons(0x03ff); 344 sp->srcnode = cb->src & cpu_to_le16(0x03ff);
345 sp->forward = cb->hops & 0x3f; 345 sp->forward = cb->hops & 0x3f;
346 346
347 skb_reset_network_header(skb); 347 skb_reset_network_header(skb);
@@ -394,7 +394,7 @@ int dn_neigh_router_hello(struct sk_buff *skb)
394 if (neigh->dev->type == ARPHRD_ETHER) 394 if (neigh->dev->type == ARPHRD_ETHER)
395 memcpy(neigh->ha, &eth_hdr(skb)->h_source, ETH_ALEN); 395 memcpy(neigh->ha, &eth_hdr(skb)->h_source, ETH_ALEN);
396 396
397 dn->blksize = dn_ntohs(msg->blksize); 397 dn->blksize = le16_to_cpu(msg->blksize);
398 dn->priority = msg->priority; 398 dn->priority = msg->priority;
399 399
400 dn->flags &= ~DN_NDFLAG_P3; 400 dn->flags &= ~DN_NDFLAG_P3;
@@ -410,7 +410,7 @@ int dn_neigh_router_hello(struct sk_buff *skb)
410 } 410 }
411 411
412 /* Only use routers in our area */ 412 /* Only use routers in our area */
413 if ((dn_ntohs(src)>>10) == (dn_ntohs((decnet_address))>>10)) { 413 if ((le16_to_cpu(src)>>10) == (le16_to_cpu((decnet_address))>>10)) {
414 if (!dn_db->router) { 414 if (!dn_db->router) {
415 dn_db->router = neigh_clone(neigh); 415 dn_db->router = neigh_clone(neigh);
416 } else { 416 } else {
@@ -453,7 +453,7 @@ int dn_neigh_endnode_hello(struct sk_buff *skb)
453 if (neigh->dev->type == ARPHRD_ETHER) 453 if (neigh->dev->type == ARPHRD_ETHER)
454 memcpy(neigh->ha, &eth_hdr(skb)->h_source, ETH_ALEN); 454 memcpy(neigh->ha, &eth_hdr(skb)->h_source, ETH_ALEN);
455 dn->flags &= ~(DN_NDFLAG_R1 | DN_NDFLAG_R2); 455 dn->flags &= ~(DN_NDFLAG_R1 | DN_NDFLAG_R2);
456 dn->blksize = dn_ntohs(msg->blksize); 456 dn->blksize = le16_to_cpu(msg->blksize);
457 dn->priority = 0; 457 dn->priority = 0;
458 } 458 }
459 459
@@ -543,7 +543,7 @@ static inline void dn_neigh_format_entry(struct seq_file *seq,
543 543
544 read_lock(&n->lock); 544 read_lock(&n->lock);
545 seq_printf(seq, "%-7s %s%s%s %02x %02d %07ld %-8s\n", 545 seq_printf(seq, "%-7s %s%s%s %02x %02d %07ld %-8s\n",
546 dn_addr2asc(dn_ntohs(dn->addr), buf), 546 dn_addr2asc(le16_to_cpu(dn->addr), buf),
547 (dn->flags&DN_NDFLAG_R1) ? "1" : "-", 547 (dn->flags&DN_NDFLAG_R1) ? "1" : "-",
548 (dn->flags&DN_NDFLAG_R2) ? "2" : "-", 548 (dn->flags&DN_NDFLAG_R2) ? "2" : "-",
549 (dn->flags&DN_NDFLAG_P3) ? "3" : "-", 549 (dn->flags&DN_NDFLAG_P3) ? "3" : "-",
diff --git a/net/decnet/dn_nsp_in.c b/net/decnet/dn_nsp_in.c
index 4074a6e5d0de..5d8a2a56fd39 100644
--- a/net/decnet/dn_nsp_in.c
+++ b/net/decnet/dn_nsp_in.c
@@ -83,7 +83,9 @@ static void dn_log_martian(struct sk_buff *skb, const char *msg)
83 if (decnet_log_martians && net_ratelimit()) { 83 if (decnet_log_martians && net_ratelimit()) {
84 char *devname = skb->dev ? skb->dev->name : "???"; 84 char *devname = skb->dev ? skb->dev->name : "???";
85 struct dn_skb_cb *cb = DN_SKB_CB(skb); 85 struct dn_skb_cb *cb = DN_SKB_CB(skb);
86 printk(KERN_INFO "DECnet: Martian packet (%s) dev=%s src=0x%04hx dst=0x%04hx srcport=0x%04hx dstport=0x%04hx\n", msg, devname, dn_ntohs(cb->src), dn_ntohs(cb->dst), dn_ntohs(cb->src_port), dn_ntohs(cb->dst_port)); 86 printk(KERN_INFO "DECnet: Martian packet (%s) dev=%s src=0x%04hx dst=0x%04hx srcport=0x%04hx dstport=0x%04hx\n",
87 msg, devname, le16_to_cpu(cb->src), le16_to_cpu(cb->dst),
88 le16_to_cpu(cb->src_port), le16_to_cpu(cb->dst_port));
87 } 89 }
88} 90}
89 91
@@ -133,7 +135,7 @@ static int dn_process_ack(struct sock *sk, struct sk_buff *skb, int oth)
133 if (skb->len < 2) 135 if (skb->len < 2)
134 return len; 136 return len;
135 137
136 if ((ack = dn_ntohs(*ptr)) & 0x8000) { 138 if ((ack = le16_to_cpu(*ptr)) & 0x8000) {
137 skb_pull(skb, 2); 139 skb_pull(skb, 2);
138 ptr++; 140 ptr++;
139 len += 2; 141 len += 2;
@@ -147,7 +149,7 @@ static int dn_process_ack(struct sock *sk, struct sk_buff *skb, int oth)
147 if (skb->len < 2) 149 if (skb->len < 2)
148 return len; 150 return len;
149 151
150 if ((ack = dn_ntohs(*ptr)) & 0x8000) { 152 if ((ack = le16_to_cpu(*ptr)) & 0x8000) {
151 skb_pull(skb, 2); 153 skb_pull(skb, 2);
152 len += 2; 154 len += 2;
153 if ((ack & 0x4000) == 0) { 155 if ((ack & 0x4000) == 0) {
@@ -237,7 +239,7 @@ static struct sock *dn_find_listener(struct sk_buff *skb, unsigned short *reason
237 cb->dst_port = msg->dstaddr; 239 cb->dst_port = msg->dstaddr;
238 cb->services = msg->services; 240 cb->services = msg->services;
239 cb->info = msg->info; 241 cb->info = msg->info;
240 cb->segsize = dn_ntohs(msg->segsize); 242 cb->segsize = le16_to_cpu(msg->segsize);
241 243
242 if (!pskb_may_pull(skb, sizeof(*msg))) 244 if (!pskb_may_pull(skb, sizeof(*msg)))
243 goto err_out; 245 goto err_out;
@@ -344,7 +346,7 @@ static void dn_nsp_conn_conf(struct sock *sk, struct sk_buff *skb)
344 ptr = skb->data; 346 ptr = skb->data;
345 cb->services = *ptr++; 347 cb->services = *ptr++;
346 cb->info = *ptr++; 348 cb->info = *ptr++;
347 cb->segsize = dn_ntohs(*(__le16 *)ptr); 349 cb->segsize = le16_to_cpu(*(__le16 *)ptr);
348 350
349 if ((scp->state == DN_CI) || (scp->state == DN_CD)) { 351 if ((scp->state == DN_CI) || (scp->state == DN_CD)) {
350 scp->persist = 0; 352 scp->persist = 0;
@@ -361,7 +363,7 @@ static void dn_nsp_conn_conf(struct sock *sk, struct sk_buff *skb)
361 if (skb->len > 0) { 363 if (skb->len > 0) {
362 u16 dlen = *skb->data; 364 u16 dlen = *skb->data;
363 if ((dlen <= 16) && (dlen <= skb->len)) { 365 if ((dlen <= 16) && (dlen <= skb->len)) {
364 scp->conndata_in.opt_optl = dn_htons(dlen); 366 scp->conndata_in.opt_optl = cpu_to_le16(dlen);
365 skb_copy_from_linear_data_offset(skb, 1, 367 skb_copy_from_linear_data_offset(skb, 1,
366 scp->conndata_in.opt_data, dlen); 368 scp->conndata_in.opt_data, dlen);
367 } 369 }
@@ -396,17 +398,17 @@ static void dn_nsp_disc_init(struct sock *sk, struct sk_buff *skb)
396 if (skb->len < 2) 398 if (skb->len < 2)
397 goto out; 399 goto out;
398 400
399 reason = dn_ntohs(*(__le16 *)skb->data); 401 reason = le16_to_cpu(*(__le16 *)skb->data);
400 skb_pull(skb, 2); 402 skb_pull(skb, 2);
401 403
402 scp->discdata_in.opt_status = dn_htons(reason); 404 scp->discdata_in.opt_status = cpu_to_le16(reason);
403 scp->discdata_in.opt_optl = 0; 405 scp->discdata_in.opt_optl = 0;
404 memset(scp->discdata_in.opt_data, 0, 16); 406 memset(scp->discdata_in.opt_data, 0, 16);
405 407
406 if (skb->len > 0) { 408 if (skb->len > 0) {
407 u16 dlen = *skb->data; 409 u16 dlen = *skb->data;
408 if ((dlen <= 16) && (dlen <= skb->len)) { 410 if ((dlen <= 16) && (dlen <= skb->len)) {
409 scp->discdata_in.opt_optl = dn_htons(dlen); 411 scp->discdata_in.opt_optl = cpu_to_le16(dlen);
410 skb_copy_from_linear_data_offset(skb, 1, scp->discdata_in.opt_data, dlen); 412 skb_copy_from_linear_data_offset(skb, 1, scp->discdata_in.opt_data, dlen);
411 } 413 }
412 } 414 }
@@ -463,7 +465,7 @@ static void dn_nsp_disc_conf(struct sock *sk, struct sk_buff *skb)
463 if (skb->len != 2) 465 if (skb->len != 2)
464 goto out; 466 goto out;
465 467
466 reason = dn_ntohs(*(__le16 *)skb->data); 468 reason = le16_to_cpu(*(__le16 *)skb->data);
467 469
468 sk->sk_state = TCP_CLOSE; 470 sk->sk_state = TCP_CLOSE;
469 471
@@ -512,7 +514,7 @@ static void dn_nsp_linkservice(struct sock *sk, struct sk_buff *skb)
512 if (skb->len != 4) 514 if (skb->len != 4)
513 goto out; 515 goto out;
514 516
515 segnum = dn_ntohs(*(__le16 *)ptr); 517 segnum = le16_to_cpu(*(__le16 *)ptr);
516 ptr += 2; 518 ptr += 2;
517 lsflags = *(unsigned char *)ptr++; 519 lsflags = *(unsigned char *)ptr++;
518 fcval = *ptr; 520 fcval = *ptr;
@@ -620,7 +622,7 @@ static void dn_nsp_otherdata(struct sock *sk, struct sk_buff *skb)
620 if (skb->len < 2) 622 if (skb->len < 2)
621 goto out; 623 goto out;
622 624
623 cb->segnum = segnum = dn_ntohs(*(__le16 *)skb->data); 625 cb->segnum = segnum = le16_to_cpu(*(__le16 *)skb->data);
624 skb_pull(skb, 2); 626 skb_pull(skb, 2);
625 627
626 if (seq_next(scp->numoth_rcv, segnum)) { 628 if (seq_next(scp->numoth_rcv, segnum)) {
@@ -648,7 +650,7 @@ static void dn_nsp_data(struct sock *sk, struct sk_buff *skb)
648 if (skb->len < 2) 650 if (skb->len < 2)
649 goto out; 651 goto out;
650 652
651 cb->segnum = segnum = dn_ntohs(*(__le16 *)skb->data); 653 cb->segnum = segnum = le16_to_cpu(*(__le16 *)skb->data);
652 skb_pull(skb, 2); 654 skb_pull(skb, 2);
653 655
654 if (seq_next(scp->numdat_rcv, segnum)) { 656 if (seq_next(scp->numdat_rcv, segnum)) {
diff --git a/net/decnet/dn_nsp_out.c b/net/decnet/dn_nsp_out.c
index 1964faf203e4..2013c25b7f5a 100644
--- a/net/decnet/dn_nsp_out.c
+++ b/net/decnet/dn_nsp_out.c
@@ -230,7 +230,6 @@ static inline unsigned dn_nsp_clone_and_send(struct sk_buff *skb,
230/** 230/**
231 * dn_nsp_output - Try and send something from socket queues 231 * dn_nsp_output - Try and send something from socket queues
232 * @sk: The socket whose queues are to be investigated 232 * @sk: The socket whose queues are to be investigated
233 * @gfp: The memory allocation flags
234 * 233 *
235 * Try and send the packet on the end of the data and other data queues. 234 * Try and send the packet on the end of the data and other data queues.
236 * Other data gets priority over data, and if we retransmit a packet we 235 * Other data gets priority over data, and if we retransmit a packet we
@@ -326,8 +325,8 @@ static __le16 *dn_mk_ack_header(struct sock *sk, struct sk_buff *skb, unsigned c
326 325
327 ptr = (__le16 *)dn_mk_common_header(scp, skb, msgflag, hlen); 326 ptr = (__le16 *)dn_mk_common_header(scp, skb, msgflag, hlen);
328 327
329 *ptr++ = dn_htons(acknum); 328 *ptr++ = cpu_to_le16(acknum);
330 *ptr++ = dn_htons(ackcrs); 329 *ptr++ = cpu_to_le16(ackcrs);
331 330
332 return ptr; 331 return ptr;
333} 332}
@@ -345,7 +344,7 @@ static __le16 *dn_nsp_mk_data_header(struct sock *sk, struct sk_buff *skb, int o
345 cb->segnum = scp->numdat; 344 cb->segnum = scp->numdat;
346 seq_add(&scp->numdat, 1); 345 seq_add(&scp->numdat, 1);
347 } 346 }
348 *(ptr++) = dn_htons(cb->segnum); 347 *(ptr++) = cpu_to_le16(cb->segnum);
349 348
350 return ptr; 349 return ptr;
351} 350}
@@ -523,7 +522,7 @@ void dn_send_conn_conf(struct sock *sk, gfp_t gfp)
523 struct dn_scp *scp = DN_SK(sk); 522 struct dn_scp *scp = DN_SK(sk);
524 struct sk_buff *skb = NULL; 523 struct sk_buff *skb = NULL;
525 struct nsp_conn_init_msg *msg; 524 struct nsp_conn_init_msg *msg;
526 __u8 len = (__u8)dn_ntohs(scp->conndata_out.opt_optl); 525 __u8 len = (__u8)le16_to_cpu(scp->conndata_out.opt_optl);
527 526
528 if ((skb = dn_alloc_skb(sk, 50 + len, gfp)) == NULL) 527 if ((skb = dn_alloc_skb(sk, 50 + len, gfp)) == NULL)
529 return; 528 return;
@@ -534,7 +533,7 @@ void dn_send_conn_conf(struct sock *sk, gfp_t gfp)
534 msg->srcaddr = scp->addrloc; 533 msg->srcaddr = scp->addrloc;
535 msg->services = scp->services_loc; 534 msg->services = scp->services_loc;
536 msg->info = scp->info_loc; 535 msg->info = scp->info_loc;
537 msg->segsize = dn_htons(scp->segsize_loc); 536 msg->segsize = cpu_to_le16(scp->segsize_loc);
538 537
539 *skb_put(skb,1) = len; 538 *skb_put(skb,1) = len;
540 539
@@ -560,7 +559,7 @@ static __inline__ void dn_nsp_do_disc(struct sock *sk, unsigned char msgflg,
560 559
561 if ((dst == NULL) || (rem == 0)) { 560 if ((dst == NULL) || (rem == 0)) {
562 if (net_ratelimit()) 561 if (net_ratelimit())
563 printk(KERN_DEBUG "DECnet: dn_nsp_do_disc: BUG! Please report this to SteveW@ACM.org rem=%u dst=%p\n", dn_ntohs(rem), dst); 562 printk(KERN_DEBUG "DECnet: dn_nsp_do_disc: BUG! Please report this to SteveW@ACM.org rem=%u dst=%p\n", le16_to_cpu(rem), dst);
564 return; 563 return;
565 } 564 }
566 565
@@ -573,7 +572,7 @@ static __inline__ void dn_nsp_do_disc(struct sock *sk, unsigned char msgflg,
573 msg += 2; 572 msg += 2;
574 *(__le16 *)msg = loc; 573 *(__le16 *)msg = loc;
575 msg += 2; 574 msg += 2;
576 *(__le16 *)msg = dn_htons(reason); 575 *(__le16 *)msg = cpu_to_le16(reason);
577 msg += 2; 576 msg += 2;
578 if (msgflg == NSP_DISCINIT) 577 if (msgflg == NSP_DISCINIT)
579 *msg++ = ddl; 578 *msg++ = ddl;
@@ -599,10 +598,10 @@ void dn_nsp_send_disc(struct sock *sk, unsigned char msgflg,
599 int ddl = 0; 598 int ddl = 0;
600 599
601 if (msgflg == NSP_DISCINIT) 600 if (msgflg == NSP_DISCINIT)
602 ddl = dn_ntohs(scp->discdata_out.opt_optl); 601 ddl = le16_to_cpu(scp->discdata_out.opt_optl);
603 602
604 if (reason == 0) 603 if (reason == 0)
605 reason = dn_ntohs(scp->discdata_out.opt_status); 604 reason = le16_to_cpu(scp->discdata_out.opt_status);
606 605
607 dn_nsp_do_disc(sk, msgflg, reason, gfp, sk->sk_dst_cache, ddl, 606 dn_nsp_do_disc(sk, msgflg, reason, gfp, sk->sk_dst_cache, ddl,
608 scp->discdata_out.opt_data, scp->addrrem, scp->addrloc); 607 scp->discdata_out.opt_data, scp->addrrem, scp->addrloc);
@@ -676,7 +675,7 @@ void dn_nsp_send_conninit(struct sock *sk, unsigned char msgflg)
676 msg->srcaddr = scp->addrloc; 675 msg->srcaddr = scp->addrloc;
677 msg->services = scp->services_loc; /* Requested flow control */ 676 msg->services = scp->services_loc; /* Requested flow control */
678 msg->info = scp->info_loc; /* Version Number */ 677 msg->info = scp->info_loc; /* Version Number */
679 msg->segsize = dn_htons(scp->segsize_loc); /* Max segment size */ 678 msg->segsize = cpu_to_le16(scp->segsize_loc); /* Max segment size */
680 679
681 if (scp->peer.sdn_objnum) 680 if (scp->peer.sdn_objnum)
682 type = 0; 681 type = 0;
@@ -709,7 +708,7 @@ void dn_nsp_send_conninit(struct sock *sk, unsigned char msgflg)
709 if (aux > 0) 708 if (aux > 0)
710 memcpy(skb_put(skb, aux), scp->accessdata.acc_acc, aux); 709 memcpy(skb_put(skb, aux), scp->accessdata.acc_acc, aux);
711 710
712 aux = (__u8)dn_ntohs(scp->conndata_out.opt_optl); 711 aux = (__u8)le16_to_cpu(scp->conndata_out.opt_optl);
713 *skb_put(skb, 1) = aux; 712 *skb_put(skb, 1) = aux;
714 if (aux > 0) 713 if (aux > 0)
715 memcpy(skb_put(skb,aux), scp->conndata_out.opt_data, aux); 714 memcpy(skb_put(skb,aux), scp->conndata_out.opt_data, aux);
diff --git a/net/decnet/dn_route.c b/net/decnet/dn_route.c
index 821bd1cdec04..c754670b7fca 100644
--- a/net/decnet/dn_route.c
+++ b/net/decnet/dn_route.c
@@ -131,7 +131,6 @@ static struct dst_ops dn_dst_ops = {
131 .negative_advice = dn_dst_negative_advice, 131 .negative_advice = dn_dst_negative_advice,
132 .link_failure = dn_dst_link_failure, 132 .link_failure = dn_dst_link_failure,
133 .update_pmtu = dn_dst_update_pmtu, 133 .update_pmtu = dn_dst_update_pmtu,
134 .entry_size = sizeof(struct dn_route),
135 .entries = ATOMIC_INIT(0), 134 .entries = ATOMIC_INIT(0),
136}; 135};
137 136
@@ -312,7 +311,7 @@ static int dn_insert_route(struct dn_route *rt, unsigned hash, struct dn_route *
312 return 0; 311 return 0;
313} 312}
314 313
315void dn_run_flush(unsigned long dummy) 314static void dn_run_flush(unsigned long dummy)
316{ 315{
317 int i; 316 int i;
318 struct dn_route *rt, *next; 317 struct dn_route *rt, *next;
@@ -476,7 +475,7 @@ static int dn_route_rx_packet(struct sk_buff *skb)
476 printk(KERN_DEBUG 475 printk(KERN_DEBUG
477 "DECnet: dn_route_rx_packet: rt_flags=0x%02x dev=%s len=%d src=0x%04hx dst=0x%04hx err=%d type=%d\n", 476 "DECnet: dn_route_rx_packet: rt_flags=0x%02x dev=%s len=%d src=0x%04hx dst=0x%04hx err=%d type=%d\n",
478 (int)cb->rt_flags, devname, skb->len, 477 (int)cb->rt_flags, devname, skb->len,
479 dn_ntohs(cb->src), dn_ntohs(cb->dst), 478 le16_to_cpu(cb->src), le16_to_cpu(cb->dst),
480 err, skb->pkt_type); 479 err, skb->pkt_type);
481 } 480 }
482 481
@@ -576,7 +575,7 @@ int dn_route_rcv(struct sk_buff *skb, struct net_device *dev, struct packet_type
576{ 575{
577 struct dn_skb_cb *cb; 576 struct dn_skb_cb *cb;
578 unsigned char flags = 0; 577 unsigned char flags = 0;
579 __u16 len = dn_ntohs(*(__le16 *)skb->data); 578 __u16 len = le16_to_cpu(*(__le16 *)skb->data);
580 struct dn_dev *dn = (struct dn_dev *)dev->dn_ptr; 579 struct dn_dev *dn = (struct dn_dev *)dev->dn_ptr;
581 unsigned char padlen = 0; 580 unsigned char padlen = 0;
582 581
@@ -774,7 +773,7 @@ static int dn_rt_bug(struct sk_buff *skb)
774 struct dn_skb_cb *cb = DN_SKB_CB(skb); 773 struct dn_skb_cb *cb = DN_SKB_CB(skb);
775 774
776 printk(KERN_DEBUG "dn_rt_bug: skb from:%04x to:%04x\n", 775 printk(KERN_DEBUG "dn_rt_bug: skb from:%04x to:%04x\n",
777 dn_ntohs(cb->src), dn_ntohs(cb->dst)); 776 le16_to_cpu(cb->src), le16_to_cpu(cb->dst));
778 } 777 }
779 778
780 kfree_skb(skb); 779 kfree_skb(skb);
@@ -817,7 +816,7 @@ static int dn_rt_set_next_hop(struct dn_route *rt, struct dn_fib_res *res)
817 816
818static inline int dn_match_addr(__le16 addr1, __le16 addr2) 817static inline int dn_match_addr(__le16 addr1, __le16 addr2)
819{ 818{
820 __u16 tmp = dn_ntohs(addr1) ^ dn_ntohs(addr2); 819 __u16 tmp = le16_to_cpu(addr1) ^ le16_to_cpu(addr2);
821 int match = 16; 820 int match = 16;
822 while(tmp) { 821 while(tmp) {
823 tmp >>= 1; 822 tmp >>= 1;
@@ -887,8 +886,8 @@ static int dn_route_output_slow(struct dst_entry **pprt, const struct flowi *old
887 if (decnet_debug_level & 16) 886 if (decnet_debug_level & 16)
888 printk(KERN_DEBUG 887 printk(KERN_DEBUG
889 "dn_route_output_slow: dst=%04x src=%04x mark=%d" 888 "dn_route_output_slow: dst=%04x src=%04x mark=%d"
890 " iif=%d oif=%d\n", dn_ntohs(oldflp->fld_dst), 889 " iif=%d oif=%d\n", le16_to_cpu(oldflp->fld_dst),
891 dn_ntohs(oldflp->fld_src), 890 le16_to_cpu(oldflp->fld_src),
892 oldflp->mark, init_net.loopback_dev->ifindex, oldflp->oif); 891 oldflp->mark, init_net.loopback_dev->ifindex, oldflp->oif);
893 892
894 /* If we have an output interface, verify its a DECnet device */ 893 /* If we have an output interface, verify its a DECnet device */
@@ -960,7 +959,7 @@ source_ok:
960 printk(KERN_DEBUG 959 printk(KERN_DEBUG
961 "dn_route_output_slow: initial checks complete." 960 "dn_route_output_slow: initial checks complete."
962 " dst=%o4x src=%04x oif=%d try_hard=%d\n", 961 " dst=%o4x src=%04x oif=%d try_hard=%d\n",
963 dn_ntohs(fl.fld_dst), dn_ntohs(fl.fld_src), 962 le16_to_cpu(fl.fld_dst), le16_to_cpu(fl.fld_src),
964 fl.oif, try_hard); 963 fl.oif, try_hard);
965 964
966 /* 965 /*
@@ -1185,7 +1184,7 @@ static int dn_route_output_key(struct dst_entry **pprt, struct flowi *flp, int f
1185 1184
1186 err = __dn_route_output_key(pprt, flp, flags); 1185 err = __dn_route_output_key(pprt, flp, flags);
1187 if (err == 0 && flp->proto) { 1186 if (err == 0 && flp->proto) {
1188 err = xfrm_lookup(pprt, flp, NULL, 0); 1187 err = xfrm_lookup(&init_net, pprt, flp, NULL, 0);
1189 } 1188 }
1190 return err; 1189 return err;
1191} 1190}
@@ -1196,8 +1195,8 @@ int dn_route_output_sock(struct dst_entry **pprt, struct flowi *fl, struct sock
1196 1195
1197 err = __dn_route_output_key(pprt, fl, flags & MSG_TRYHARD); 1196 err = __dn_route_output_key(pprt, fl, flags & MSG_TRYHARD);
1198 if (err == 0 && fl->proto) { 1197 if (err == 0 && fl->proto) {
1199 err = xfrm_lookup(pprt, fl, sk, (flags & MSG_DONTWAIT) ? 1198 err = xfrm_lookup(&init_net, pprt, fl, sk,
1200 0 : XFRM_LOOKUP_WAIT); 1199 (flags & MSG_DONTWAIT) ? 0 : XFRM_LOOKUP_WAIT);
1201 } 1200 }
1202 return err; 1201 return err;
1203} 1202}
@@ -1423,7 +1422,7 @@ e_neighbour:
1423 goto done; 1422 goto done;
1424} 1423}
1425 1424
1426int dn_route_input(struct sk_buff *skb) 1425static int dn_route_input(struct sk_buff *skb)
1427{ 1426{
1428 struct dn_route *rt; 1427 struct dn_route *rt;
1429 struct dn_skb_cb *cb = DN_SKB_CB(skb); 1428 struct dn_skb_cb *cb = DN_SKB_CB(skb);
@@ -1712,8 +1711,8 @@ static int dn_rt_cache_seq_show(struct seq_file *seq, void *v)
1712 1711
1713 seq_printf(seq, "%-8s %-7s %-7s %04d %04d %04d\n", 1712 seq_printf(seq, "%-8s %-7s %-7s %04d %04d %04d\n",
1714 rt->u.dst.dev ? rt->u.dst.dev->name : "*", 1713 rt->u.dst.dev ? rt->u.dst.dev->name : "*",
1715 dn_addr2asc(dn_ntohs(rt->rt_daddr), buf1), 1714 dn_addr2asc(le16_to_cpu(rt->rt_daddr), buf1),
1716 dn_addr2asc(dn_ntohs(rt->rt_saddr), buf2), 1715 dn_addr2asc(le16_to_cpu(rt->rt_saddr), buf2),
1717 atomic_read(&rt->u.dst.__refcnt), 1716 atomic_read(&rt->u.dst.__refcnt),
1718 rt->u.dst.__use, 1717 rt->u.dst.__use,
1719 (int) dst_metric(&rt->u.dst, RTAX_RTT)); 1718 (int) dst_metric(&rt->u.dst, RTAX_RTT));
diff --git a/net/decnet/dn_table.c b/net/decnet/dn_table.c
index 3a2830ac89c2..69ad9280c693 100644
--- a/net/decnet/dn_table.c
+++ b/net/decnet/dn_table.c
@@ -85,7 +85,7 @@ static int dn_fib_hash_zombies;
85 85
86static inline dn_fib_idx_t dn_hash(dn_fib_key_t key, struct dn_zone *dz) 86static inline dn_fib_idx_t dn_hash(dn_fib_key_t key, struct dn_zone *dz)
87{ 87{
88 u16 h = dn_ntohs(key.datum)>>(16 - dz->dz_order); 88 u16 h = le16_to_cpu(key.datum)>>(16 - dz->dz_order);
89 h ^= (h >> 10); 89 h ^= (h >> 10);
90 h ^= (h >> 6); 90 h ^= (h >> 6);
91 h &= DZ_HASHMASK(dz); 91 h &= DZ_HASHMASK(dz);
diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
index 36400b266896..965397af9a80 100644
--- a/net/decnet/sysctl_net_decnet.c
+++ b/net/decnet/sysctl_net_decnet.c
@@ -126,7 +126,7 @@ static int parse_addr(__le16 *addr, char *str)
126 if (INVALID_END_CHAR(*str)) 126 if (INVALID_END_CHAR(*str))
127 return -1; 127 return -1;
128 128
129 *addr = dn_htons((area << 10) | node); 129 *addr = cpu_to_le16((area << 10) | node);
130 130
131 return 0; 131 return 0;
132} 132}
@@ -201,7 +201,7 @@ static int dn_node_address_handler(ctl_table *table, int write,
201 return 0; 201 return 0;
202 } 202 }
203 203
204 dn_addr2asc(dn_ntohs(decnet_address), addr); 204 dn_addr2asc(le16_to_cpu(decnet_address), addr);
205 len = strlen(addr); 205 len = strlen(addr);
206 addr[len++] = '\n'; 206 addr[len++] = '\n';
207 207
@@ -354,8 +354,8 @@ static ctl_table dn_table[] = {
354 .data = node_name, 354 .data = node_name,
355 .maxlen = 7, 355 .maxlen = 7,
356 .mode = 0644, 356 .mode = 0644,
357 .proc_handler = &proc_dostring, 357 .proc_handler = proc_dostring,
358 .strategy = &sysctl_string, 358 .strategy = sysctl_string,
359 }, 359 },
360 { 360 {
361 .ctl_name = NET_DECNET_DEFAULT_DEVICE, 361 .ctl_name = NET_DECNET_DEFAULT_DEVICE,
@@ -371,8 +371,8 @@ static ctl_table dn_table[] = {
371 .data = &decnet_time_wait, 371 .data = &decnet_time_wait,
372 .maxlen = sizeof(int), 372 .maxlen = sizeof(int),
373 .mode = 0644, 373 .mode = 0644,
374 .proc_handler = &proc_dointvec_minmax, 374 .proc_handler = proc_dointvec_minmax,
375 .strategy = &sysctl_intvec, 375 .strategy = sysctl_intvec,
376 .extra1 = &min_decnet_time_wait, 376 .extra1 = &min_decnet_time_wait,
377 .extra2 = &max_decnet_time_wait 377 .extra2 = &max_decnet_time_wait
378 }, 378 },
@@ -382,8 +382,8 @@ static ctl_table dn_table[] = {
382 .data = &decnet_dn_count, 382 .data = &decnet_dn_count,
383 .maxlen = sizeof(int), 383 .maxlen = sizeof(int),
384 .mode = 0644, 384 .mode = 0644,
385 .proc_handler = &proc_dointvec_minmax, 385 .proc_handler = proc_dointvec_minmax,
386 .strategy = &sysctl_intvec, 386 .strategy = sysctl_intvec,
387 .extra1 = &min_state_count, 387 .extra1 = &min_state_count,
388 .extra2 = &max_state_count 388 .extra2 = &max_state_count
389 }, 389 },
@@ -393,8 +393,8 @@ static ctl_table dn_table[] = {
393 .data = &decnet_di_count, 393 .data = &decnet_di_count,
394 .maxlen = sizeof(int), 394 .maxlen = sizeof(int),
395 .mode = 0644, 395 .mode = 0644,
396 .proc_handler = &proc_dointvec_minmax, 396 .proc_handler = proc_dointvec_minmax,
397 .strategy = &sysctl_intvec, 397 .strategy = sysctl_intvec,
398 .extra1 = &min_state_count, 398 .extra1 = &min_state_count,
399 .extra2 = &max_state_count 399 .extra2 = &max_state_count
400 }, 400 },
@@ -404,8 +404,8 @@ static ctl_table dn_table[] = {
404 .data = &decnet_dr_count, 404 .data = &decnet_dr_count,
405 .maxlen = sizeof(int), 405 .maxlen = sizeof(int),
406 .mode = 0644, 406 .mode = 0644,
407 .proc_handler = &proc_dointvec_minmax, 407 .proc_handler = proc_dointvec_minmax,
408 .strategy = &sysctl_intvec, 408 .strategy = sysctl_intvec,
409 .extra1 = &min_state_count, 409 .extra1 = &min_state_count,
410 .extra2 = &max_state_count 410 .extra2 = &max_state_count
411 }, 411 },
@@ -415,8 +415,8 @@ static ctl_table dn_table[] = {
415 .data = &decnet_dst_gc_interval, 415 .data = &decnet_dst_gc_interval,
416 .maxlen = sizeof(int), 416 .maxlen = sizeof(int),
417 .mode = 0644, 417 .mode = 0644,
418 .proc_handler = &proc_dointvec_minmax, 418 .proc_handler = proc_dointvec_minmax,
419 .strategy = &sysctl_intvec, 419 .strategy = sysctl_intvec,
420 .extra1 = &min_decnet_dst_gc_interval, 420 .extra1 = &min_decnet_dst_gc_interval,
421 .extra2 = &max_decnet_dst_gc_interval 421 .extra2 = &max_decnet_dst_gc_interval
422 }, 422 },
@@ -426,8 +426,8 @@ static ctl_table dn_table[] = {
426 .data = &decnet_no_fc_max_cwnd, 426 .data = &decnet_no_fc_max_cwnd,
427 .maxlen = sizeof(int), 427 .maxlen = sizeof(int),
428 .mode = 0644, 428 .mode = 0644,
429 .proc_handler = &proc_dointvec_minmax, 429 .proc_handler = proc_dointvec_minmax,
430 .strategy = &sysctl_intvec, 430 .strategy = sysctl_intvec,
431 .extra1 = &min_decnet_no_fc_max_cwnd, 431 .extra1 = &min_decnet_no_fc_max_cwnd,
432 .extra2 = &max_decnet_no_fc_max_cwnd 432 .extra2 = &max_decnet_no_fc_max_cwnd
433 }, 433 },
@@ -437,8 +437,8 @@ static ctl_table dn_table[] = {
437 .data = &sysctl_decnet_mem, 437 .data = &sysctl_decnet_mem,
438 .maxlen = sizeof(sysctl_decnet_mem), 438 .maxlen = sizeof(sysctl_decnet_mem),
439 .mode = 0644, 439 .mode = 0644,
440 .proc_handler = &proc_dointvec, 440 .proc_handler = proc_dointvec,
441 .strategy = &sysctl_intvec, 441 .strategy = sysctl_intvec,
442 }, 442 },
443 { 443 {
444 .ctl_name = NET_DECNET_RMEM, 444 .ctl_name = NET_DECNET_RMEM,
@@ -446,8 +446,8 @@ static ctl_table dn_table[] = {
446 .data = &sysctl_decnet_rmem, 446 .data = &sysctl_decnet_rmem,
447 .maxlen = sizeof(sysctl_decnet_rmem), 447 .maxlen = sizeof(sysctl_decnet_rmem),
448 .mode = 0644, 448 .mode = 0644,
449 .proc_handler = &proc_dointvec, 449 .proc_handler = proc_dointvec,
450 .strategy = &sysctl_intvec, 450 .strategy = sysctl_intvec,
451 }, 451 },
452 { 452 {
453 .ctl_name = NET_DECNET_WMEM, 453 .ctl_name = NET_DECNET_WMEM,
@@ -455,8 +455,8 @@ static ctl_table dn_table[] = {
455 .data = &sysctl_decnet_wmem, 455 .data = &sysctl_decnet_wmem,
456 .maxlen = sizeof(sysctl_decnet_wmem), 456 .maxlen = sizeof(sysctl_decnet_wmem),
457 .mode = 0644, 457 .mode = 0644,
458 .proc_handler = &proc_dointvec, 458 .proc_handler = proc_dointvec,
459 .strategy = &sysctl_intvec, 459 .strategy = sysctl_intvec,
460 }, 460 },
461 { 461 {
462 .ctl_name = NET_DECNET_DEBUG_LEVEL, 462 .ctl_name = NET_DECNET_DEBUG_LEVEL,
@@ -464,8 +464,8 @@ static ctl_table dn_table[] = {
464 .data = &decnet_debug_level, 464 .data = &decnet_debug_level,
465 .maxlen = sizeof(int), 465 .maxlen = sizeof(int),
466 .mode = 0644, 466 .mode = 0644,
467 .proc_handler = &proc_dointvec, 467 .proc_handler = proc_dointvec,
468 .strategy = &sysctl_intvec, 468 .strategy = sysctl_intvec,
469 }, 469 },
470 {0} 470 {0}
471}; 471};
diff --git a/net/dsa/mv88e6060.c b/net/dsa/mv88e6060.c
index 54068ef251e8..85081ae9fe89 100644
--- a/net/dsa/mv88e6060.c
+++ b/net/dsa/mv88e6060.c
@@ -222,7 +222,7 @@ static void mv88e6060_poll_link(struct dsa_switch *ds)
222 222
223 for (i = 0; i < DSA_MAX_PORTS; i++) { 223 for (i = 0; i < DSA_MAX_PORTS; i++) {
224 struct net_device *dev; 224 struct net_device *dev;
225 int port_status; 225 int uninitialized_var(port_status);
226 int link; 226 int link;
227 int speed; 227 int speed;
228 int duplex; 228 int duplex;
@@ -273,14 +273,14 @@ static struct dsa_switch_driver mv88e6060_switch_driver = {
273 .poll_link = mv88e6060_poll_link, 273 .poll_link = mv88e6060_poll_link,
274}; 274};
275 275
276int __init mv88e6060_init(void) 276static int __init mv88e6060_init(void)
277{ 277{
278 register_switch_driver(&mv88e6060_switch_driver); 278 register_switch_driver(&mv88e6060_switch_driver);
279 return 0; 279 return 0;
280} 280}
281module_init(mv88e6060_init); 281module_init(mv88e6060_init);
282 282
283void __exit mv88e6060_cleanup(void) 283static void __exit mv88e6060_cleanup(void)
284{ 284{
285 unregister_switch_driver(&mv88e6060_switch_driver); 285 unregister_switch_driver(&mv88e6060_switch_driver);
286} 286}
diff --git a/net/dsa/mv88e6123_61_65.c b/net/dsa/mv88e6123_61_65.c
index 555b164082fc..ec8c6a0482d3 100644
--- a/net/dsa/mv88e6123_61_65.c
+++ b/net/dsa/mv88e6123_61_65.c
@@ -407,14 +407,14 @@ static struct dsa_switch_driver mv88e6123_61_65_switch_driver = {
407 .get_sset_count = mv88e6123_61_65_get_sset_count, 407 .get_sset_count = mv88e6123_61_65_get_sset_count,
408}; 408};
409 409
410int __init mv88e6123_61_65_init(void) 410static int __init mv88e6123_61_65_init(void)
411{ 411{
412 register_switch_driver(&mv88e6123_61_65_switch_driver); 412 register_switch_driver(&mv88e6123_61_65_switch_driver);
413 return 0; 413 return 0;
414} 414}
415module_init(mv88e6123_61_65_init); 415module_init(mv88e6123_61_65_init);
416 416
417void __exit mv88e6123_61_65_cleanup(void) 417static void __exit mv88e6123_61_65_cleanup(void)
418{ 418{
419 unregister_switch_driver(&mv88e6123_61_65_switch_driver); 419 unregister_switch_driver(&mv88e6123_61_65_switch_driver);
420} 420}
diff --git a/net/dsa/mv88e6131.c b/net/dsa/mv88e6131.c
index 36e01eb863a0..374d46a01265 100644
--- a/net/dsa/mv88e6131.c
+++ b/net/dsa/mv88e6131.c
@@ -366,14 +366,14 @@ static struct dsa_switch_driver mv88e6131_switch_driver = {
366 .get_sset_count = mv88e6131_get_sset_count, 366 .get_sset_count = mv88e6131_get_sset_count,
367}; 367};
368 368
369int __init mv88e6131_init(void) 369static int __init mv88e6131_init(void)
370{ 370{
371 register_switch_driver(&mv88e6131_switch_driver); 371 register_switch_driver(&mv88e6131_switch_driver);
372 return 0; 372 return 0;
373} 373}
374module_init(mv88e6131_init); 374module_init(mv88e6131_init);
375 375
376void __exit mv88e6131_cleanup(void) 376static void __exit mv88e6131_cleanup(void)
377{ 377{
378 unregister_switch_driver(&mv88e6131_switch_driver); 378 unregister_switch_driver(&mv88e6131_switch_driver);
379} 379}
diff --git a/net/dsa/mv88e6xxx.c b/net/dsa/mv88e6xxx.c
index aa6c609c59f2..4e4d8b5ad03d 100644
--- a/net/dsa/mv88e6xxx.c
+++ b/net/dsa/mv88e6xxx.c
@@ -358,7 +358,7 @@ void mv88e6xxx_poll_link(struct dsa_switch *ds)
358 358
359 for (i = 0; i < DSA_MAX_PORTS; i++) { 359 for (i = 0; i < DSA_MAX_PORTS; i++) {
360 struct net_device *dev; 360 struct net_device *dev;
361 int port_status; 361 int uninitialized_var(port_status);
362 int link; 362 int link;
363 int speed; 363 int speed;
364 int duplex; 364 int duplex;
diff --git a/net/dsa/slave.c b/net/dsa/slave.c
index 1af5a79309e9..a3a410d20da0 100644
--- a/net/dsa/slave.c
+++ b/net/dsa/slave.c
@@ -352,7 +352,7 @@ dsa_slave_create(struct dsa_switch *ds, struct device *parent,
352 netif_carrier_off(slave_dev); 352 netif_carrier_off(slave_dev);
353 353
354 if (p->phy != NULL) { 354 if (p->phy != NULL) {
355 phy_attach(slave_dev, p->phy->dev.bus_id, 355 phy_attach(slave_dev, dev_name(&p->phy->dev),
356 0, PHY_INTERFACE_MODE_GMII); 356 0, PHY_INTERFACE_MODE_GMII);
357 357
358 p->phy->autoneg = AUTONEG_ENABLE; 358 p->phy->autoneg = AUTONEG_ENABLE;
diff --git a/net/dsa/tag_dsa.c b/net/dsa/tag_dsa.c
index 31866543332e..f99a019b939e 100644
--- a/net/dsa/tag_dsa.c
+++ b/net/dsa/tag_dsa.c
@@ -162,7 +162,6 @@ static int dsa_rcv(struct sk_buff *skb, struct net_device *dev,
162 skb->pkt_type = PACKET_HOST; 162 skb->pkt_type = PACKET_HOST;
163 skb->protocol = eth_type_trans(skb, skb->dev); 163 skb->protocol = eth_type_trans(skb, skb->dev);
164 164
165 skb->dev->last_rx = jiffies;
166 skb->dev->stats.rx_packets++; 165 skb->dev->stats.rx_packets++;
167 skb->dev->stats.rx_bytes += skb->len; 166 skb->dev->stats.rx_bytes += skb->len;
168 167
diff --git a/net/dsa/tag_edsa.c b/net/dsa/tag_edsa.c
index 9f4ce55eae59..328ec957f786 100644
--- a/net/dsa/tag_edsa.c
+++ b/net/dsa/tag_edsa.c
@@ -181,7 +181,6 @@ static int edsa_rcv(struct sk_buff *skb, struct net_device *dev,
181 skb->pkt_type = PACKET_HOST; 181 skb->pkt_type = PACKET_HOST;
182 skb->protocol = eth_type_trans(skb, skb->dev); 182 skb->protocol = eth_type_trans(skb, skb->dev);
183 183
184 skb->dev->last_rx = jiffies;
185 skb->dev->stats.rx_packets++; 184 skb->dev->stats.rx_packets++;
186 skb->dev->stats.rx_bytes += skb->len; 185 skb->dev->stats.rx_bytes += skb->len;
187 186
diff --git a/net/dsa/tag_trailer.c b/net/dsa/tag_trailer.c
index efd26697e716..b59132878ad1 100644
--- a/net/dsa/tag_trailer.c
+++ b/net/dsa/tag_trailer.c
@@ -98,7 +98,6 @@ static int trailer_rcv(struct sk_buff *skb, struct net_device *dev,
98 skb->pkt_type = PACKET_HOST; 98 skb->pkt_type = PACKET_HOST;
99 skb->protocol = eth_type_trans(skb, skb->dev); 99 skb->protocol = eth_type_trans(skb, skb->dev);
100 100
101 skb->dev->last_rx = jiffies;
102 skb->dev->stats.rx_packets++; 101 skb->dev->stats.rx_packets++;
103 skb->dev->stats.rx_bytes += skb->len; 102 skb->dev->stats.rx_bytes += skb->len;
104 103
diff --git a/net/ethernet/eth.c b/net/ethernet/eth.c
index b9d85af2dd31..280352aba403 100644
--- a/net/ethernet/eth.c
+++ b/net/ethernet/eth.c
@@ -165,8 +165,8 @@ __be16 eth_type_trans(struct sk_buff *skb, struct net_device *dev)
165 skb_pull(skb, ETH_HLEN); 165 skb_pull(skb, ETH_HLEN);
166 eth = eth_hdr(skb); 166 eth = eth_hdr(skb);
167 167
168 if (is_multicast_ether_addr(eth->h_dest)) { 168 if (unlikely(is_multicast_ether_addr(eth->h_dest))) {
169 if (!compare_ether_addr(eth->h_dest, dev->broadcast)) 169 if (!compare_ether_addr_64bits(eth->h_dest, dev->broadcast))
170 skb->pkt_type = PACKET_BROADCAST; 170 skb->pkt_type = PACKET_BROADCAST;
171 else 171 else
172 skb->pkt_type = PACKET_MULTICAST; 172 skb->pkt_type = PACKET_MULTICAST;
@@ -181,7 +181,7 @@ __be16 eth_type_trans(struct sk_buff *skb, struct net_device *dev)
181 */ 181 */
182 182
183 else if (1 /*dev->flags&IFF_PROMISC */ ) { 183 else if (1 /*dev->flags&IFF_PROMISC */ ) {
184 if (unlikely(compare_ether_addr(eth->h_dest, dev->dev_addr))) 184 if (unlikely(compare_ether_addr_64bits(eth->h_dest, dev->dev_addr)))
185 skb->pkt_type = PACKET_OTHERHOST; 185 skb->pkt_type = PACKET_OTHERHOST;
186 } 186 }
187 187
@@ -282,7 +282,7 @@ EXPORT_SYMBOL(eth_header_cache_update);
282 * This doesn't change hardware matching, so needs to be overridden 282 * This doesn't change hardware matching, so needs to be overridden
283 * for most real devices. 283 * for most real devices.
284 */ 284 */
285static int eth_mac_addr(struct net_device *dev, void *p) 285int eth_mac_addr(struct net_device *dev, void *p)
286{ 286{
287 struct sockaddr *addr = p; 287 struct sockaddr *addr = p;
288 288
@@ -293,6 +293,7 @@ static int eth_mac_addr(struct net_device *dev, void *p)
293 memcpy(dev->dev_addr, addr->sa_data, ETH_ALEN); 293 memcpy(dev->dev_addr, addr->sa_data, ETH_ALEN);
294 return 0; 294 return 0;
295} 295}
296EXPORT_SYMBOL(eth_mac_addr);
296 297
297/** 298/**
298 * eth_change_mtu - set new MTU size 299 * eth_change_mtu - set new MTU size
@@ -302,21 +303,23 @@ static int eth_mac_addr(struct net_device *dev, void *p)
302 * Allow changing MTU size. Needs to be overridden for devices 303 * Allow changing MTU size. Needs to be overridden for devices
303 * supporting jumbo frames. 304 * supporting jumbo frames.
304 */ 305 */
305static int eth_change_mtu(struct net_device *dev, int new_mtu) 306int eth_change_mtu(struct net_device *dev, int new_mtu)
306{ 307{
307 if (new_mtu < 68 || new_mtu > ETH_DATA_LEN) 308 if (new_mtu < 68 || new_mtu > ETH_DATA_LEN)
308 return -EINVAL; 309 return -EINVAL;
309 dev->mtu = new_mtu; 310 dev->mtu = new_mtu;
310 return 0; 311 return 0;
311} 312}
313EXPORT_SYMBOL(eth_change_mtu);
312 314
313static int eth_validate_addr(struct net_device *dev) 315int eth_validate_addr(struct net_device *dev)
314{ 316{
315 if (!is_valid_ether_addr(dev->dev_addr)) 317 if (!is_valid_ether_addr(dev->dev_addr))
316 return -EADDRNOTAVAIL; 318 return -EADDRNOTAVAIL;
317 319
318 return 0; 320 return 0;
319} 321}
322EXPORT_SYMBOL(eth_validate_addr);
320 323
321const struct header_ops eth_header_ops ____cacheline_aligned = { 324const struct header_ops eth_header_ops ____cacheline_aligned = {
322 .create = eth_header, 325 .create = eth_header,
@@ -334,11 +337,11 @@ const struct header_ops eth_header_ops ____cacheline_aligned = {
334void ether_setup(struct net_device *dev) 337void ether_setup(struct net_device *dev)
335{ 338{
336 dev->header_ops = &eth_header_ops; 339 dev->header_ops = &eth_header_ops;
337 340#ifdef CONFIG_COMPAT_NET_DEV_OPS
338 dev->change_mtu = eth_change_mtu; 341 dev->change_mtu = eth_change_mtu;
339 dev->set_mac_address = eth_mac_addr; 342 dev->set_mac_address = eth_mac_addr;
340 dev->validate_addr = eth_validate_addr; 343 dev->validate_addr = eth_validate_addr;
341 344#endif
342 dev->type = ARPHRD_ETHER; 345 dev->type = ARPHRD_ETHER;
343 dev->hard_header_len = ETH_HLEN; 346 dev->hard_header_len = ETH_HLEN;
344 dev->mtu = ETH_DATA_LEN; 347 dev->mtu = ETH_DATA_LEN;
diff --git a/net/ieee80211/Kconfig b/net/ieee80211/Kconfig
deleted file mode 100644
index 94ed7d3cd9da..000000000000
--- a/net/ieee80211/Kconfig
+++ /dev/null
@@ -1,73 +0,0 @@
1config IEEE80211
2 tristate "Generic IEEE 802.11 Networking Stack (DEPRECATED)"
3 ---help---
4 This option enables the hardware independent IEEE 802.11
5 networking stack. This component is deprecated in favor of the
6 mac80211 component.
7
8config IEEE80211_DEBUG
9 bool "Enable full debugging output"
10 depends on IEEE80211
11 ---help---
12 This option will enable debug tracing output for the
13 ieee80211 network stack.
14
15 This will result in the kernel module being ~70k larger. You
16 can control which debug output is sent to the kernel log by
17 setting the value in
18
19 /proc/net/ieee80211/debug_level
20
21 For example:
22
23 % echo 0x00000FFO > /proc/net/ieee80211/debug_level
24
25 For a list of values you can assign to debug_level, you
26 can look at the bit mask values in <net/ieee80211.h>
27
28 If you are not trying to debug or develop the ieee80211
29 subsystem, you most likely want to say N here.
30
31config IEEE80211_CRYPT_WEP
32 tristate "IEEE 802.11 WEP encryption (802.1x)"
33 depends on IEEE80211
34 select CRYPTO
35 select CRYPTO_ARC4
36 select CRYPTO_ECB
37 select CRC32
38 ---help---
39 Include software based cipher suites in support of IEEE
40 802.11's WEP. This is needed for WEP as well as 802.1x.
41
42 This can be compiled as a module and it will be called
43 "ieee80211_crypt_wep".
44
45config IEEE80211_CRYPT_CCMP
46 tristate "IEEE 802.11i CCMP support"
47 depends on IEEE80211
48 select CRYPTO
49 select CRYPTO_AES
50 ---help---
51 Include software based cipher suites in support of IEEE 802.11i
52 (aka TGi, WPA, WPA2, WPA-PSK, etc.) for use with CCMP enabled
53 networks.
54
55 This can be compiled as a module and it will be called
56 "ieee80211_crypt_ccmp".
57
58config IEEE80211_CRYPT_TKIP
59 tristate "IEEE 802.11i TKIP encryption"
60 depends on IEEE80211
61 select WIRELESS_EXT
62 select CRYPTO
63 select CRYPTO_MICHAEL_MIC
64 select CRYPTO_ECB
65 select CRC32
66 ---help---
67 Include software based cipher suites in support of IEEE 802.11i
68 (aka TGi, WPA, WPA2, WPA-PSK, etc.) for use with TKIP enabled
69 networks.
70
71 This can be compiled as a module and it will be called
72 "ieee80211_crypt_tkip".
73
diff --git a/net/ieee80211/Makefile b/net/ieee80211/Makefile
deleted file mode 100644
index f988417121da..000000000000
--- a/net/ieee80211/Makefile
+++ /dev/null
@@ -1,12 +0,0 @@
1obj-$(CONFIG_IEEE80211) += ieee80211.o
2obj-$(CONFIG_IEEE80211) += ieee80211_crypt.o
3obj-$(CONFIG_IEEE80211_CRYPT_WEP) += ieee80211_crypt_wep.o
4obj-$(CONFIG_IEEE80211_CRYPT_CCMP) += ieee80211_crypt_ccmp.o
5obj-$(CONFIG_IEEE80211_CRYPT_TKIP) += ieee80211_crypt_tkip.o
6ieee80211-objs := \
7 ieee80211_module.o \
8 ieee80211_tx.o \
9 ieee80211_rx.o \
10 ieee80211_wx.o \
11 ieee80211_geo.o
12
diff --git a/net/ieee80211/ieee80211_crypt.c b/net/ieee80211/ieee80211_crypt.c
deleted file mode 100644
index df5592c9339f..000000000000
--- a/net/ieee80211/ieee80211_crypt.c
+++ /dev/null
@@ -1,206 +0,0 @@
1/*
2 * Host AP crypto routines
3 *
4 * Copyright (c) 2002-2003, Jouni Malinen <j@w1.fi>
5 * Portions Copyright (C) 2004, Intel Corporation <jketreno@linux.intel.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation. See README and COPYING for
10 * more details.
11 *
12 */
13
14#include <linux/errno.h>
15#include <linux/module.h>
16#include <linux/init.h>
17#include <linux/slab.h>
18#include <linux/string.h>
19#include <net/ieee80211.h>
20
21MODULE_AUTHOR("Jouni Malinen");
22MODULE_DESCRIPTION("HostAP crypto");
23MODULE_LICENSE("GPL");
24
25struct ieee80211_crypto_alg {
26 struct list_head list;
27 struct ieee80211_crypto_ops *ops;
28};
29
30static LIST_HEAD(ieee80211_crypto_algs);
31static DEFINE_SPINLOCK(ieee80211_crypto_lock);
32
33void ieee80211_crypt_deinit_entries(struct ieee80211_device *ieee, int force)
34{
35 struct ieee80211_crypt_data *entry, *next;
36 unsigned long flags;
37
38 spin_lock_irqsave(&ieee->lock, flags);
39 list_for_each_entry_safe(entry, next, &ieee->crypt_deinit_list, list) {
40 if (atomic_read(&entry->refcnt) != 0 && !force)
41 continue;
42
43 list_del(&entry->list);
44
45 if (entry->ops) {
46 entry->ops->deinit(entry->priv);
47 module_put(entry->ops->owner);
48 }
49 kfree(entry);
50 }
51 spin_unlock_irqrestore(&ieee->lock, flags);
52}
53
54/* After this, crypt_deinit_list won't accept new members */
55void ieee80211_crypt_quiescing(struct ieee80211_device *ieee)
56{
57 unsigned long flags;
58
59 spin_lock_irqsave(&ieee->lock, flags);
60 ieee->crypt_quiesced = 1;
61 spin_unlock_irqrestore(&ieee->lock, flags);
62}
63
64void ieee80211_crypt_deinit_handler(unsigned long data)
65{
66 struct ieee80211_device *ieee = (struct ieee80211_device *)data;
67 unsigned long flags;
68
69 ieee80211_crypt_deinit_entries(ieee, 0);
70
71 spin_lock_irqsave(&ieee->lock, flags);
72 if (!list_empty(&ieee->crypt_deinit_list) && !ieee->crypt_quiesced) {
73 printk(KERN_DEBUG "%s: entries remaining in delayed crypt "
74 "deletion list\n", ieee->dev->name);
75 ieee->crypt_deinit_timer.expires = jiffies + HZ;
76 add_timer(&ieee->crypt_deinit_timer);
77 }
78 spin_unlock_irqrestore(&ieee->lock, flags);
79}
80
81void ieee80211_crypt_delayed_deinit(struct ieee80211_device *ieee,
82 struct ieee80211_crypt_data **crypt)
83{
84 struct ieee80211_crypt_data *tmp;
85 unsigned long flags;
86
87 if (*crypt == NULL)
88 return;
89
90 tmp = *crypt;
91 *crypt = NULL;
92
93 /* must not run ops->deinit() while there may be pending encrypt or
94 * decrypt operations. Use a list of delayed deinits to avoid needing
95 * locking. */
96
97 spin_lock_irqsave(&ieee->lock, flags);
98 if (!ieee->crypt_quiesced) {
99 list_add(&tmp->list, &ieee->crypt_deinit_list);
100 if (!timer_pending(&ieee->crypt_deinit_timer)) {
101 ieee->crypt_deinit_timer.expires = jiffies + HZ;
102 add_timer(&ieee->crypt_deinit_timer);
103 }
104 }
105 spin_unlock_irqrestore(&ieee->lock, flags);
106}
107
108int ieee80211_register_crypto_ops(struct ieee80211_crypto_ops *ops)
109{
110 unsigned long flags;
111 struct ieee80211_crypto_alg *alg;
112
113 alg = kzalloc(sizeof(*alg), GFP_KERNEL);
114 if (alg == NULL)
115 return -ENOMEM;
116
117 alg->ops = ops;
118
119 spin_lock_irqsave(&ieee80211_crypto_lock, flags);
120 list_add(&alg->list, &ieee80211_crypto_algs);
121 spin_unlock_irqrestore(&ieee80211_crypto_lock, flags);
122
123 printk(KERN_DEBUG "ieee80211_crypt: registered algorithm '%s'\n",
124 ops->name);
125
126 return 0;
127}
128
129int ieee80211_unregister_crypto_ops(struct ieee80211_crypto_ops *ops)
130{
131 struct ieee80211_crypto_alg *alg;
132 unsigned long flags;
133
134 spin_lock_irqsave(&ieee80211_crypto_lock, flags);
135 list_for_each_entry(alg, &ieee80211_crypto_algs, list) {
136 if (alg->ops == ops)
137 goto found;
138 }
139 spin_unlock_irqrestore(&ieee80211_crypto_lock, flags);
140 return -EINVAL;
141
142 found:
143 printk(KERN_DEBUG "ieee80211_crypt: unregistered algorithm "
144 "'%s'\n", ops->name);
145 list_del(&alg->list);
146 spin_unlock_irqrestore(&ieee80211_crypto_lock, flags);
147 kfree(alg);
148 return 0;
149}
150
151struct ieee80211_crypto_ops *ieee80211_get_crypto_ops(const char *name)
152{
153 struct ieee80211_crypto_alg *alg;
154 unsigned long flags;
155
156 spin_lock_irqsave(&ieee80211_crypto_lock, flags);
157 list_for_each_entry(alg, &ieee80211_crypto_algs, list) {
158 if (strcmp(alg->ops->name, name) == 0)
159 goto found;
160 }
161 spin_unlock_irqrestore(&ieee80211_crypto_lock, flags);
162 return NULL;
163
164 found:
165 spin_unlock_irqrestore(&ieee80211_crypto_lock, flags);
166 return alg->ops;
167}
168
169static void *ieee80211_crypt_null_init(int keyidx)
170{
171 return (void *)1;
172}
173
174static void ieee80211_crypt_null_deinit(void *priv)
175{
176}
177
178static struct ieee80211_crypto_ops ieee80211_crypt_null = {
179 .name = "NULL",
180 .init = ieee80211_crypt_null_init,
181 .deinit = ieee80211_crypt_null_deinit,
182 .owner = THIS_MODULE,
183};
184
185static int __init ieee80211_crypto_init(void)
186{
187 return ieee80211_register_crypto_ops(&ieee80211_crypt_null);
188}
189
190static void __exit ieee80211_crypto_deinit(void)
191{
192 ieee80211_unregister_crypto_ops(&ieee80211_crypt_null);
193 BUG_ON(!list_empty(&ieee80211_crypto_algs));
194}
195
196EXPORT_SYMBOL(ieee80211_crypt_deinit_entries);
197EXPORT_SYMBOL(ieee80211_crypt_deinit_handler);
198EXPORT_SYMBOL(ieee80211_crypt_delayed_deinit);
199EXPORT_SYMBOL(ieee80211_crypt_quiescing);
200
201EXPORT_SYMBOL(ieee80211_register_crypto_ops);
202EXPORT_SYMBOL(ieee80211_unregister_crypto_ops);
203EXPORT_SYMBOL(ieee80211_get_crypto_ops);
204
205module_init(ieee80211_crypto_init);
206module_exit(ieee80211_crypto_deinit);
diff --git a/net/ieee80211/ieee80211_geo.c b/net/ieee80211/ieee80211_geo.c
deleted file mode 100644
index 960ad13f5e9f..000000000000
--- a/net/ieee80211/ieee80211_geo.c
+++ /dev/null
@@ -1,195 +0,0 @@
1/******************************************************************************
2
3 Copyright(c) 2005 Intel Corporation. All rights reserved.
4
5 This program is free software; you can redistribute it and/or modify it
6 under the terms of version 2 of the GNU General Public License as
7 published by the Free Software Foundation.
8
9 This program is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 more details.
13
14 You should have received a copy of the GNU General Public License along with
15 this program; if not, write to the Free Software Foundation, Inc., 59
16 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
18 The full GNU General Public License is included in this distribution in the
19 file called LICENSE.
20
21 Contact Information:
22 James P. Ketrenos <ipw2100-admin@linux.intel.com>
23 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
24
25******************************************************************************/
26#include <linux/compiler.h>
27#include <linux/errno.h>
28#include <linux/if_arp.h>
29#include <linux/in6.h>
30#include <linux/in.h>
31#include <linux/ip.h>
32#include <linux/kernel.h>
33#include <linux/module.h>
34#include <linux/netdevice.h>
35#include <linux/proc_fs.h>
36#include <linux/skbuff.h>
37#include <linux/slab.h>
38#include <linux/tcp.h>
39#include <linux/types.h>
40#include <linux/wireless.h>
41#include <linux/etherdevice.h>
42#include <asm/uaccess.h>
43
44#include <net/ieee80211.h>
45
46int ieee80211_is_valid_channel(struct ieee80211_device *ieee, u8 channel)
47{
48 int i;
49
50 /* Driver needs to initialize the geography map before using
51 * these helper functions */
52 if (ieee->geo.bg_channels == 0 && ieee->geo.a_channels == 0)
53 return 0;
54
55 if (ieee->freq_band & IEEE80211_24GHZ_BAND)
56 for (i = 0; i < ieee->geo.bg_channels; i++)
57 /* NOTE: If G mode is currently supported but
58 * this is a B only channel, we don't see it
59 * as valid. */
60 if ((ieee->geo.bg[i].channel == channel) &&
61 !(ieee->geo.bg[i].flags & IEEE80211_CH_INVALID) &&
62 (!(ieee->mode & IEEE_G) ||
63 !(ieee->geo.bg[i].flags & IEEE80211_CH_B_ONLY)))
64 return IEEE80211_24GHZ_BAND;
65
66 if (ieee->freq_band & IEEE80211_52GHZ_BAND)
67 for (i = 0; i < ieee->geo.a_channels; i++)
68 if ((ieee->geo.a[i].channel == channel) &&
69 !(ieee->geo.a[i].flags & IEEE80211_CH_INVALID))
70 return IEEE80211_52GHZ_BAND;
71
72 return 0;
73}
74
75int ieee80211_channel_to_index(struct ieee80211_device *ieee, u8 channel)
76{
77 int i;
78
79 /* Driver needs to initialize the geography map before using
80 * these helper functions */
81 if (ieee->geo.bg_channels == 0 && ieee->geo.a_channels == 0)
82 return -1;
83
84 if (ieee->freq_band & IEEE80211_24GHZ_BAND)
85 for (i = 0; i < ieee->geo.bg_channels; i++)
86 if (ieee->geo.bg[i].channel == channel)
87 return i;
88
89 if (ieee->freq_band & IEEE80211_52GHZ_BAND)
90 for (i = 0; i < ieee->geo.a_channels; i++)
91 if (ieee->geo.a[i].channel == channel)
92 return i;
93
94 return -1;
95}
96
97u32 ieee80211_channel_to_freq(struct ieee80211_device * ieee, u8 channel)
98{
99 const struct ieee80211_channel * ch;
100
101 /* Driver needs to initialize the geography map before using
102 * these helper functions */
103 if (ieee->geo.bg_channels == 0 && ieee->geo.a_channels == 0)
104 return 0;
105
106 ch = ieee80211_get_channel(ieee, channel);
107 if (!ch->channel)
108 return 0;
109 return ch->freq;
110}
111
112u8 ieee80211_freq_to_channel(struct ieee80211_device * ieee, u32 freq)
113{
114 int i;
115
116 /* Driver needs to initialize the geography map before using
117 * these helper functions */
118 if (ieee->geo.bg_channels == 0 && ieee->geo.a_channels == 0)
119 return 0;
120
121 freq /= 100000;
122
123 if (ieee->freq_band & IEEE80211_24GHZ_BAND)
124 for (i = 0; i < ieee->geo.bg_channels; i++)
125 if (ieee->geo.bg[i].freq == freq)
126 return ieee->geo.bg[i].channel;
127
128 if (ieee->freq_band & IEEE80211_52GHZ_BAND)
129 for (i = 0; i < ieee->geo.a_channels; i++)
130 if (ieee->geo.a[i].freq == freq)
131 return ieee->geo.a[i].channel;
132
133 return 0;
134}
135
136int ieee80211_set_geo(struct ieee80211_device *ieee,
137 const struct ieee80211_geo *geo)
138{
139 memcpy(ieee->geo.name, geo->name, 3);
140 ieee->geo.name[3] = '\0';
141 ieee->geo.bg_channels = geo->bg_channels;
142 ieee->geo.a_channels = geo->a_channels;
143 memcpy(ieee->geo.bg, geo->bg, geo->bg_channels *
144 sizeof(struct ieee80211_channel));
145 memcpy(ieee->geo.a, geo->a, ieee->geo.a_channels *
146 sizeof(struct ieee80211_channel));
147 return 0;
148}
149
150const struct ieee80211_geo *ieee80211_get_geo(struct ieee80211_device *ieee)
151{
152 return &ieee->geo;
153}
154
155u8 ieee80211_get_channel_flags(struct ieee80211_device * ieee, u8 channel)
156{
157 int index = ieee80211_channel_to_index(ieee, channel);
158
159 if (index == -1)
160 return IEEE80211_CH_INVALID;
161
162 if (channel <= IEEE80211_24GHZ_CHANNELS)
163 return ieee->geo.bg[index].flags;
164
165 return ieee->geo.a[index].flags;
166}
167
168static const struct ieee80211_channel bad_channel = {
169 .channel = 0,
170 .flags = IEEE80211_CH_INVALID,
171 .max_power = 0,
172};
173
174const struct ieee80211_channel *ieee80211_get_channel(struct ieee80211_device
175 *ieee, u8 channel)
176{
177 int index = ieee80211_channel_to_index(ieee, channel);
178
179 if (index == -1)
180 return &bad_channel;
181
182 if (channel <= IEEE80211_24GHZ_CHANNELS)
183 return &ieee->geo.bg[index];
184
185 return &ieee->geo.a[index];
186}
187
188EXPORT_SYMBOL(ieee80211_get_channel);
189EXPORT_SYMBOL(ieee80211_get_channel_flags);
190EXPORT_SYMBOL(ieee80211_is_valid_channel);
191EXPORT_SYMBOL(ieee80211_freq_to_channel);
192EXPORT_SYMBOL(ieee80211_channel_to_freq);
193EXPORT_SYMBOL(ieee80211_channel_to_index);
194EXPORT_SYMBOL(ieee80211_set_geo);
195EXPORT_SYMBOL(ieee80211_get_geo);
diff --git a/net/ieee80211/ieee80211_module.c b/net/ieee80211/ieee80211_module.c
deleted file mode 100644
index 949772a5a7dc..000000000000
--- a/net/ieee80211/ieee80211_module.c
+++ /dev/null
@@ -1,338 +0,0 @@
1/*******************************************************************************
2
3 Copyright(c) 2004-2005 Intel Corporation. All rights reserved.
4
5 Portions of this file are based on the WEP enablement code provided by the
6 Host AP project hostap-drivers v0.1.3
7 Copyright (c) 2001-2002, SSH Communications Security Corp and Jouni Malinen
8 <j@w1.fi>
9 Copyright (c) 2002-2003, Jouni Malinen <j@w1.fi>
10
11 This program is free software; you can redistribute it and/or modify it
12 under the terms of version 2 of the GNU General Public License as
13 published by the Free Software Foundation.
14
15 This program is distributed in the hope that it will be useful, but WITHOUT
16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
18 more details.
19
20 You should have received a copy of the GNU General Public License along with
21 this program; if not, write to the Free Software Foundation, Inc., 59
22 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23
24 The full GNU General Public License is included in this distribution in the
25 file called LICENSE.
26
27 Contact Information:
28 James P. Ketrenos <ipw2100-admin@linux.intel.com>
29 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
30
31*******************************************************************************/
32
33#include <linux/compiler.h>
34#include <linux/errno.h>
35#include <linux/if_arp.h>
36#include <linux/in6.h>
37#include <linux/in.h>
38#include <linux/ip.h>
39#include <linux/kernel.h>
40#include <linux/module.h>
41#include <linux/netdevice.h>
42#include <linux/proc_fs.h>
43#include <linux/skbuff.h>
44#include <linux/slab.h>
45#include <linux/tcp.h>
46#include <linux/types.h>
47#include <linux/wireless.h>
48#include <linux/etherdevice.h>
49#include <asm/uaccess.h>
50#include <net/net_namespace.h>
51#include <net/arp.h>
52
53#include <net/ieee80211.h>
54
55#define DRV_DESCRIPTION "802.11 data/management/control stack"
56#define DRV_NAME "ieee80211"
57#define DRV_VERSION IEEE80211_VERSION
58#define DRV_COPYRIGHT "Copyright (C) 2004-2005 Intel Corporation <jketreno@linux.intel.com>"
59
60MODULE_VERSION(DRV_VERSION);
61MODULE_DESCRIPTION(DRV_DESCRIPTION);
62MODULE_AUTHOR(DRV_COPYRIGHT);
63MODULE_LICENSE("GPL");
64
65static int ieee80211_networks_allocate(struct ieee80211_device *ieee)
66{
67 if (ieee->networks)
68 return 0;
69
70 ieee->networks =
71 kzalloc(MAX_NETWORK_COUNT * sizeof(struct ieee80211_network),
72 GFP_KERNEL);
73 if (!ieee->networks) {
74 printk(KERN_WARNING "%s: Out of memory allocating beacons\n",
75 ieee->dev->name);
76 return -ENOMEM;
77 }
78
79 return 0;
80}
81
82void ieee80211_network_reset(struct ieee80211_network *network)
83{
84 if (!network)
85 return;
86
87 if (network->ibss_dfs) {
88 kfree(network->ibss_dfs);
89 network->ibss_dfs = NULL;
90 }
91}
92
93static inline void ieee80211_networks_free(struct ieee80211_device *ieee)
94{
95 int i;
96
97 if (!ieee->networks)
98 return;
99
100 for (i = 0; i < MAX_NETWORK_COUNT; i++)
101 if (ieee->networks[i].ibss_dfs)
102 kfree(ieee->networks[i].ibss_dfs);
103
104 kfree(ieee->networks);
105 ieee->networks = NULL;
106}
107
108static void ieee80211_networks_initialize(struct ieee80211_device *ieee)
109{
110 int i;
111
112 INIT_LIST_HEAD(&ieee->network_free_list);
113 INIT_LIST_HEAD(&ieee->network_list);
114 for (i = 0; i < MAX_NETWORK_COUNT; i++)
115 list_add_tail(&ieee->networks[i].list,
116 &ieee->network_free_list);
117}
118
119static int ieee80211_change_mtu(struct net_device *dev, int new_mtu)
120{
121 if ((new_mtu < 68) || (new_mtu > IEEE80211_DATA_LEN))
122 return -EINVAL;
123 dev->mtu = new_mtu;
124 return 0;
125}
126
127static struct net_device_stats *ieee80211_generic_get_stats(
128 struct net_device *dev)
129{
130 struct ieee80211_device *ieee = netdev_priv(dev);
131 return &ieee->stats;
132}
133
134struct net_device *alloc_ieee80211(int sizeof_priv)
135{
136 struct ieee80211_device *ieee;
137 struct net_device *dev;
138 int err;
139
140 IEEE80211_DEBUG_INFO("Initializing...\n");
141
142 dev = alloc_etherdev(sizeof(struct ieee80211_device) + sizeof_priv);
143 if (!dev) {
144 IEEE80211_ERROR("Unable to allocate network device.\n");
145 goto failed;
146 }
147 ieee = netdev_priv(dev);
148 dev->hard_start_xmit = ieee80211_xmit;
149 dev->change_mtu = ieee80211_change_mtu;
150
151 /* Drivers are free to override this if the generic implementation
152 * does not meet their needs. */
153 dev->get_stats = ieee80211_generic_get_stats;
154
155 ieee->dev = dev;
156
157 err = ieee80211_networks_allocate(ieee);
158 if (err) {
159 IEEE80211_ERROR("Unable to allocate beacon storage: %d\n", err);
160 goto failed_free_netdev;
161 }
162 ieee80211_networks_initialize(ieee);
163
164 /* Default fragmentation threshold is maximum payload size */
165 ieee->fts = DEFAULT_FTS;
166 ieee->rts = DEFAULT_FTS;
167 ieee->scan_age = DEFAULT_MAX_SCAN_AGE;
168 ieee->open_wep = 1;
169
170 /* Default to enabling full open WEP with host based encrypt/decrypt */
171 ieee->host_encrypt = 1;
172 ieee->host_decrypt = 1;
173 ieee->host_mc_decrypt = 1;
174
175 /* Host fragementation in Open mode. Default is enabled.
176 * Note: host fragmentation is always enabled if host encryption
177 * is enabled. For cards can do hardware encryption, they must do
178 * hardware fragmentation as well. So we don't need a variable
179 * like host_enc_frag. */
180 ieee->host_open_frag = 1;
181 ieee->ieee802_1x = 1; /* Default to supporting 802.1x */
182
183 INIT_LIST_HEAD(&ieee->crypt_deinit_list);
184 setup_timer(&ieee->crypt_deinit_timer, ieee80211_crypt_deinit_handler,
185 (unsigned long)ieee);
186 ieee->crypt_quiesced = 0;
187
188 spin_lock_init(&ieee->lock);
189
190 ieee->wpa_enabled = 0;
191 ieee->drop_unencrypted = 0;
192 ieee->privacy_invoked = 0;
193
194 return dev;
195
196failed_free_netdev:
197 free_netdev(dev);
198failed:
199 return NULL;
200}
201
202void free_ieee80211(struct net_device *dev)
203{
204 struct ieee80211_device *ieee = netdev_priv(dev);
205
206 int i;
207
208 ieee80211_crypt_quiescing(ieee);
209 del_timer_sync(&ieee->crypt_deinit_timer);
210 ieee80211_crypt_deinit_entries(ieee, 1);
211
212 for (i = 0; i < WEP_KEYS; i++) {
213 struct ieee80211_crypt_data *crypt = ieee->crypt[i];
214 if (crypt) {
215 if (crypt->ops) {
216 crypt->ops->deinit(crypt->priv);
217 module_put(crypt->ops->owner);
218 }
219 kfree(crypt);
220 ieee->crypt[i] = NULL;
221 }
222 }
223
224 ieee80211_networks_free(ieee);
225 free_netdev(dev);
226}
227
228#ifdef CONFIG_IEEE80211_DEBUG
229
230static int debug = 0;
231u32 ieee80211_debug_level = 0;
232EXPORT_SYMBOL_GPL(ieee80211_debug_level);
233static struct proc_dir_entry *ieee80211_proc = NULL;
234
235static int show_debug_level(char *page, char **start, off_t offset,
236 int count, int *eof, void *data)
237{
238 return snprintf(page, count, "0x%08X\n", ieee80211_debug_level);
239}
240
241static int store_debug_level(struct file *file, const char __user * buffer,
242 unsigned long count, void *data)
243{
244 char buf[] = "0x00000000\n";
245 unsigned long len = min((unsigned long)sizeof(buf) - 1, count);
246 unsigned long val;
247
248 if (copy_from_user(buf, buffer, len))
249 return count;
250 buf[len] = 0;
251 if (sscanf(buf, "%li", &val) != 1)
252 printk(KERN_INFO DRV_NAME
253 ": %s is not in hex or decimal form.\n", buf);
254 else
255 ieee80211_debug_level = val;
256
257 return strnlen(buf, len);
258}
259#endif /* CONFIG_IEEE80211_DEBUG */
260
261static int __init ieee80211_init(void)
262{
263#ifdef CONFIG_IEEE80211_DEBUG
264 struct proc_dir_entry *e;
265
266 ieee80211_debug_level = debug;
267 ieee80211_proc = proc_mkdir(DRV_NAME, init_net.proc_net);
268 if (ieee80211_proc == NULL) {
269 IEEE80211_ERROR("Unable to create " DRV_NAME
270 " proc directory\n");
271 return -EIO;
272 }
273 e = create_proc_entry("debug_level", S_IFREG | S_IRUGO | S_IWUSR,
274 ieee80211_proc);
275 if (!e) {
276 remove_proc_entry(DRV_NAME, init_net.proc_net);
277 ieee80211_proc = NULL;
278 return -EIO;
279 }
280 e->read_proc = show_debug_level;
281 e->write_proc = store_debug_level;
282 e->data = NULL;
283#endif /* CONFIG_IEEE80211_DEBUG */
284
285 printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n");
286 printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n");
287
288 return 0;
289}
290
291static void __exit ieee80211_exit(void)
292{
293#ifdef CONFIG_IEEE80211_DEBUG
294 if (ieee80211_proc) {
295 remove_proc_entry("debug_level", ieee80211_proc);
296 remove_proc_entry(DRV_NAME, init_net.proc_net);
297 ieee80211_proc = NULL;
298 }
299#endif /* CONFIG_IEEE80211_DEBUG */
300}
301
302#ifdef CONFIG_IEEE80211_DEBUG
303#include <linux/moduleparam.h>
304module_param(debug, int, 0444);
305MODULE_PARM_DESC(debug, "debug output mask");
306#endif /* CONFIG_IEEE80211_DEBUG */
307
308module_exit(ieee80211_exit);
309module_init(ieee80211_init);
310
311const char *escape_essid(const char *essid, u8 essid_len)
312{
313 static char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
314 const char *s = essid;
315 char *d = escaped;
316
317 if (ieee80211_is_empty_essid(essid, essid_len)) {
318 memcpy(escaped, "<hidden>", sizeof("<hidden>"));
319 return escaped;
320 }
321
322 essid_len = min(essid_len, (u8) IW_ESSID_MAX_SIZE);
323 while (essid_len--) {
324 if (*s == '\0') {
325 *d++ = '\\';
326 *d++ = '0';
327 s++;
328 } else {
329 *d++ = *s++;
330 }
331 }
332 *d = '\0';
333 return escaped;
334}
335
336EXPORT_SYMBOL(alloc_ieee80211);
337EXPORT_SYMBOL(free_ieee80211);
338EXPORT_SYMBOL(escape_essid);
diff --git a/net/ieee80211/ieee80211_rx.c b/net/ieee80211/ieee80211_rx.c
deleted file mode 100644
index 69dbc342a464..000000000000
--- a/net/ieee80211/ieee80211_rx.c
+++ /dev/null
@@ -1,1831 +0,0 @@
1/*
2 * Original code based Host AP (software wireless LAN access point) driver
3 * for Intersil Prism2/2.5/3 - hostap.o module, common routines
4 *
5 * Copyright (c) 2001-2002, SSH Communications Security Corp and Jouni Malinen
6 * <j@w1.fi>
7 * Copyright (c) 2002-2003, Jouni Malinen <j@w1.fi>
8 * Copyright (c) 2004-2005, Intel Corporation
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation. See README and COPYING for
13 * more details.
14 */
15
16#include <linux/compiler.h>
17#include <linux/errno.h>
18#include <linux/if_arp.h>
19#include <linux/in6.h>
20#include <linux/in.h>
21#include <linux/ip.h>
22#include <linux/kernel.h>
23#include <linux/module.h>
24#include <linux/netdevice.h>
25#include <linux/proc_fs.h>
26#include <linux/skbuff.h>
27#include <linux/slab.h>
28#include <linux/tcp.h>
29#include <linux/types.h>
30#include <linux/wireless.h>
31#include <linux/etherdevice.h>
32#include <asm/uaccess.h>
33#include <linux/ctype.h>
34
35#include <net/ieee80211.h>
36
37static void ieee80211_monitor_rx(struct ieee80211_device *ieee,
38 struct sk_buff *skb,
39 struct ieee80211_rx_stats *rx_stats)
40{
41 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
42 u16 fc = le16_to_cpu(hdr->frame_ctl);
43
44 skb->dev = ieee->dev;
45 skb_reset_mac_header(skb);
46 skb_pull(skb, ieee80211_get_hdrlen(fc));
47 skb->pkt_type = PACKET_OTHERHOST;
48 skb->protocol = htons(ETH_P_80211_RAW);
49 memset(skb->cb, 0, sizeof(skb->cb));
50 netif_rx(skb);
51}
52
53/* Called only as a tasklet (software IRQ) */
54static struct ieee80211_frag_entry *ieee80211_frag_cache_find(struct
55 ieee80211_device
56 *ieee,
57 unsigned int seq,
58 unsigned int frag,
59 u8 * src,
60 u8 * dst)
61{
62 struct ieee80211_frag_entry *entry;
63 int i;
64
65 for (i = 0; i < IEEE80211_FRAG_CACHE_LEN; i++) {
66 entry = &ieee->frag_cache[i];
67 if (entry->skb != NULL &&
68 time_after(jiffies, entry->first_frag_time + 2 * HZ)) {
69 IEEE80211_DEBUG_FRAG("expiring fragment cache entry "
70 "seq=%u last_frag=%u\n",
71 entry->seq, entry->last_frag);
72 dev_kfree_skb_any(entry->skb);
73 entry->skb = NULL;
74 }
75
76 if (entry->skb != NULL && entry->seq == seq &&
77 (entry->last_frag + 1 == frag || frag == -1) &&
78 !compare_ether_addr(entry->src_addr, src) &&
79 !compare_ether_addr(entry->dst_addr, dst))
80 return entry;
81 }
82
83 return NULL;
84}
85
86/* Called only as a tasklet (software IRQ) */
87static struct sk_buff *ieee80211_frag_cache_get(struct ieee80211_device *ieee,
88 struct ieee80211_hdr_4addr *hdr)
89{
90 struct sk_buff *skb = NULL;
91 u16 sc;
92 unsigned int frag, seq;
93 struct ieee80211_frag_entry *entry;
94
95 sc = le16_to_cpu(hdr->seq_ctl);
96 frag = WLAN_GET_SEQ_FRAG(sc);
97 seq = WLAN_GET_SEQ_SEQ(sc);
98
99 if (frag == 0) {
100 /* Reserve enough space to fit maximum frame length */
101 skb = dev_alloc_skb(ieee->dev->mtu +
102 sizeof(struct ieee80211_hdr_4addr) +
103 8 /* LLC */ +
104 2 /* alignment */ +
105 8 /* WEP */ + ETH_ALEN /* WDS */ );
106 if (skb == NULL)
107 return NULL;
108
109 entry = &ieee->frag_cache[ieee->frag_next_idx];
110 ieee->frag_next_idx++;
111 if (ieee->frag_next_idx >= IEEE80211_FRAG_CACHE_LEN)
112 ieee->frag_next_idx = 0;
113
114 if (entry->skb != NULL)
115 dev_kfree_skb_any(entry->skb);
116
117 entry->first_frag_time = jiffies;
118 entry->seq = seq;
119 entry->last_frag = frag;
120 entry->skb = skb;
121 memcpy(entry->src_addr, hdr->addr2, ETH_ALEN);
122 memcpy(entry->dst_addr, hdr->addr1, ETH_ALEN);
123 } else {
124 /* received a fragment of a frame for which the head fragment
125 * should have already been received */
126 entry = ieee80211_frag_cache_find(ieee, seq, frag, hdr->addr2,
127 hdr->addr1);
128 if (entry != NULL) {
129 entry->last_frag = frag;
130 skb = entry->skb;
131 }
132 }
133
134 return skb;
135}
136
137/* Called only as a tasklet (software IRQ) */
138static int ieee80211_frag_cache_invalidate(struct ieee80211_device *ieee,
139 struct ieee80211_hdr_4addr *hdr)
140{
141 u16 sc;
142 unsigned int seq;
143 struct ieee80211_frag_entry *entry;
144
145 sc = le16_to_cpu(hdr->seq_ctl);
146 seq = WLAN_GET_SEQ_SEQ(sc);
147
148 entry = ieee80211_frag_cache_find(ieee, seq, -1, hdr->addr2,
149 hdr->addr1);
150
151 if (entry == NULL) {
152 IEEE80211_DEBUG_FRAG("could not invalidate fragment cache "
153 "entry (seq=%u)\n", seq);
154 return -1;
155 }
156
157 entry->skb = NULL;
158 return 0;
159}
160
161#ifdef NOT_YET
162/* ieee80211_rx_frame_mgtmt
163 *
164 * Responsible for handling management control frames
165 *
166 * Called by ieee80211_rx */
167static int
168ieee80211_rx_frame_mgmt(struct ieee80211_device *ieee, struct sk_buff *skb,
169 struct ieee80211_rx_stats *rx_stats, u16 type,
170 u16 stype)
171{
172 if (ieee->iw_mode == IW_MODE_MASTER) {
173 printk(KERN_DEBUG "%s: Master mode not yet suppported.\n",
174 ieee->dev->name);
175 return 0;
176/*
177 hostap_update_sta_ps(ieee, (struct hostap_ieee80211_hdr_4addr *)
178 skb->data);*/
179 }
180
181 if (ieee->hostapd && type == WLAN_FC_TYPE_MGMT) {
182 if (stype == WLAN_FC_STYPE_BEACON &&
183 ieee->iw_mode == IW_MODE_MASTER) {
184 struct sk_buff *skb2;
185 /* Process beacon frames also in kernel driver to
186 * update STA(AP) table statistics */
187 skb2 = skb_clone(skb, GFP_ATOMIC);
188 if (skb2)
189 hostap_rx(skb2->dev, skb2, rx_stats);
190 }
191
192 /* send management frames to the user space daemon for
193 * processing */
194 ieee->apdevstats.rx_packets++;
195 ieee->apdevstats.rx_bytes += skb->len;
196 prism2_rx_80211(ieee->apdev, skb, rx_stats, PRISM2_RX_MGMT);
197 return 0;
198 }
199
200 if (ieee->iw_mode == IW_MODE_MASTER) {
201 if (type != WLAN_FC_TYPE_MGMT && type != WLAN_FC_TYPE_CTRL) {
202 printk(KERN_DEBUG "%s: unknown management frame "
203 "(type=0x%02x, stype=0x%02x) dropped\n",
204 skb->dev->name, type, stype);
205 return -1;
206 }
207
208 hostap_rx(skb->dev, skb, rx_stats);
209 return 0;
210 }
211
212 printk(KERN_DEBUG "%s: hostap_rx_frame_mgmt: management frame "
213 "received in non-Host AP mode\n", skb->dev->name);
214 return -1;
215}
216#endif
217
218/* See IEEE 802.1H for LLC/SNAP encapsulation/decapsulation */
219/* Ethernet-II snap header (RFC1042 for most EtherTypes) */
220static unsigned char rfc1042_header[] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
221
222/* Bridge-Tunnel header (for EtherTypes ETH_P_AARP and ETH_P_IPX) */
223static unsigned char bridge_tunnel_header[] =
224 { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8 };
225/* No encapsulation header if EtherType < 0x600 (=length) */
226
227/* Called by ieee80211_rx_frame_decrypt */
228static int ieee80211_is_eapol_frame(struct ieee80211_device *ieee,
229 struct sk_buff *skb)
230{
231 struct net_device *dev = ieee->dev;
232 u16 fc, ethertype;
233 struct ieee80211_hdr_3addr *hdr;
234 u8 *pos;
235
236 if (skb->len < 24)
237 return 0;
238
239 hdr = (struct ieee80211_hdr_3addr *)skb->data;
240 fc = le16_to_cpu(hdr->frame_ctl);
241
242 /* check that the frame is unicast frame to us */
243 if ((fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) ==
244 IEEE80211_FCTL_TODS &&
245 !compare_ether_addr(hdr->addr1, dev->dev_addr) &&
246 !compare_ether_addr(hdr->addr3, dev->dev_addr)) {
247 /* ToDS frame with own addr BSSID and DA */
248 } else if ((fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) ==
249 IEEE80211_FCTL_FROMDS &&
250 !compare_ether_addr(hdr->addr1, dev->dev_addr)) {
251 /* FromDS frame with own addr as DA */
252 } else
253 return 0;
254
255 if (skb->len < 24 + 8)
256 return 0;
257
258 /* check for port access entity Ethernet type */
259 pos = skb->data + 24;
260 ethertype = (pos[6] << 8) | pos[7];
261 if (ethertype == ETH_P_PAE)
262 return 1;
263
264 return 0;
265}
266
267/* Called only as a tasklet (software IRQ), by ieee80211_rx */
268static int
269ieee80211_rx_frame_decrypt(struct ieee80211_device *ieee, struct sk_buff *skb,
270 struct ieee80211_crypt_data *crypt)
271{
272 struct ieee80211_hdr_3addr *hdr;
273 int res, hdrlen;
274
275 if (crypt == NULL || crypt->ops->decrypt_mpdu == NULL)
276 return 0;
277
278 hdr = (struct ieee80211_hdr_3addr *)skb->data;
279 hdrlen = ieee80211_get_hdrlen(le16_to_cpu(hdr->frame_ctl));
280
281 atomic_inc(&crypt->refcnt);
282 res = crypt->ops->decrypt_mpdu(skb, hdrlen, crypt->priv);
283 atomic_dec(&crypt->refcnt);
284 if (res < 0) {
285 IEEE80211_DEBUG_DROP("decryption failed (SA=" MAC_FMT
286 ") res=%d\n",
287 hdr->addr2[0], hdr->addr2[1],
288 hdr->addr2[2], hdr->addr2[3],
289 hdr->addr2[4], hdr->addr2[5],
290 res);
291 if (res == -2)
292 IEEE80211_DEBUG_DROP("Decryption failed ICV "
293 "mismatch (key %d)\n",
294 skb->data[hdrlen + 3] >> 6);
295 ieee->ieee_stats.rx_discards_undecryptable++;
296 return -1;
297 }
298
299 return res;
300}
301
302/* Called only as a tasklet (software IRQ), by ieee80211_rx */
303static int
304ieee80211_rx_frame_decrypt_msdu(struct ieee80211_device *ieee,
305 struct sk_buff *skb, int keyidx,
306 struct ieee80211_crypt_data *crypt)
307{
308 struct ieee80211_hdr_3addr *hdr;
309 int res, hdrlen;
310
311 if (crypt == NULL || crypt->ops->decrypt_msdu == NULL)
312 return 0;
313
314 hdr = (struct ieee80211_hdr_3addr *)skb->data;
315 hdrlen = ieee80211_get_hdrlen(le16_to_cpu(hdr->frame_ctl));
316
317 atomic_inc(&crypt->refcnt);
318 res = crypt->ops->decrypt_msdu(skb, keyidx, hdrlen, crypt->priv);
319 atomic_dec(&crypt->refcnt);
320 if (res < 0) {
321 printk(KERN_DEBUG "%s: MSDU decryption/MIC verification failed"
322 " (SA=" MAC_FMT " keyidx=%d)\n",
323 ieee->dev->name,
324 hdr->addr2[0], hdr->addr2[1],
325 hdr->addr2[2], hdr->addr2[3],
326 hdr->addr2[4], hdr->addr2[5],
327 keyidx);
328 return -1;
329 }
330
331 return 0;
332}
333
334/* All received frames are sent to this function. @skb contains the frame in
335 * IEEE 802.11 format, i.e., in the format it was sent over air.
336 * This function is called only as a tasklet (software IRQ). */
337int ieee80211_rx(struct ieee80211_device *ieee, struct sk_buff *skb,
338 struct ieee80211_rx_stats *rx_stats)
339{
340 struct net_device *dev = ieee->dev;
341 struct ieee80211_hdr_4addr *hdr;
342 size_t hdrlen;
343 u16 fc, type, stype, sc;
344 struct net_device_stats *stats;
345 unsigned int frag;
346 u8 *payload;
347 u16 ethertype;
348#ifdef NOT_YET
349 struct net_device *wds = NULL;
350 struct sk_buff *skb2 = NULL;
351 struct net_device *wds = NULL;
352 int frame_authorized = 0;
353 int from_assoc_ap = 0;
354 void *sta = NULL;
355#endif
356 u8 dst[ETH_ALEN];
357 u8 src[ETH_ALEN];
358 struct ieee80211_crypt_data *crypt = NULL;
359 int keyidx = 0;
360 int can_be_decrypted = 0;
361 DECLARE_MAC_BUF(mac);
362
363 hdr = (struct ieee80211_hdr_4addr *)skb->data;
364 stats = &ieee->stats;
365
366 if (skb->len < 10) {
367 printk(KERN_INFO "%s: SKB length < 10\n", dev->name);
368 goto rx_dropped;
369 }
370
371 fc = le16_to_cpu(hdr->frame_ctl);
372 type = WLAN_FC_GET_TYPE(fc);
373 stype = WLAN_FC_GET_STYPE(fc);
374 sc = le16_to_cpu(hdr->seq_ctl);
375 frag = WLAN_GET_SEQ_FRAG(sc);
376 hdrlen = ieee80211_get_hdrlen(fc);
377
378 if (skb->len < hdrlen) {
379 printk(KERN_INFO "%s: invalid SKB length %d\n",
380 dev->name, skb->len);
381 goto rx_dropped;
382 }
383
384 /* Put this code here so that we avoid duplicating it in all
385 * Rx paths. - Jean II */
386#ifdef CONFIG_WIRELESS_EXT
387#ifdef IW_WIRELESS_SPY /* defined in iw_handler.h */
388 /* If spy monitoring on */
389 if (ieee->spy_data.spy_number > 0) {
390 struct iw_quality wstats;
391
392 wstats.updated = 0;
393 if (rx_stats->mask & IEEE80211_STATMASK_RSSI) {
394 wstats.level = rx_stats->signal;
395 wstats.updated |= IW_QUAL_LEVEL_UPDATED;
396 } else
397 wstats.updated |= IW_QUAL_LEVEL_INVALID;
398
399 if (rx_stats->mask & IEEE80211_STATMASK_NOISE) {
400 wstats.noise = rx_stats->noise;
401 wstats.updated |= IW_QUAL_NOISE_UPDATED;
402 } else
403 wstats.updated |= IW_QUAL_NOISE_INVALID;
404
405 if (rx_stats->mask & IEEE80211_STATMASK_SIGNAL) {
406 wstats.qual = rx_stats->signal;
407 wstats.updated |= IW_QUAL_QUAL_UPDATED;
408 } else
409 wstats.updated |= IW_QUAL_QUAL_INVALID;
410
411 /* Update spy records */
412 wireless_spy_update(ieee->dev, hdr->addr2, &wstats);
413 }
414#endif /* IW_WIRELESS_SPY */
415#endif /* CONFIG_WIRELESS_EXT */
416
417#ifdef NOT_YET
418 hostap_update_rx_stats(local->ap, hdr, rx_stats);
419#endif
420
421 if (ieee->iw_mode == IW_MODE_MONITOR) {
422 stats->rx_packets++;
423 stats->rx_bytes += skb->len;
424 ieee80211_monitor_rx(ieee, skb, rx_stats);
425 return 1;
426 }
427
428 can_be_decrypted = (is_multicast_ether_addr(hdr->addr1) ||
429 is_broadcast_ether_addr(hdr->addr2)) ?
430 ieee->host_mc_decrypt : ieee->host_decrypt;
431
432 if (can_be_decrypted) {
433 if (skb->len >= hdrlen + 3) {
434 /* Top two-bits of byte 3 are the key index */
435 keyidx = skb->data[hdrlen + 3] >> 6;
436 }
437
438 /* ieee->crypt[] is WEP_KEY (4) in length. Given that keyidx
439 * is only allowed 2-bits of storage, no value of keyidx can
440 * be provided via above code that would result in keyidx
441 * being out of range */
442 crypt = ieee->crypt[keyidx];
443
444#ifdef NOT_YET
445 sta = NULL;
446
447 /* Use station specific key to override default keys if the
448 * receiver address is a unicast address ("individual RA"). If
449 * bcrx_sta_key parameter is set, station specific key is used
450 * even with broad/multicast targets (this is against IEEE
451 * 802.11, but makes it easier to use different keys with
452 * stations that do not support WEP key mapping). */
453
454 if (!(hdr->addr1[0] & 0x01) || local->bcrx_sta_key)
455 (void)hostap_handle_sta_crypto(local, hdr, &crypt,
456 &sta);
457#endif
458
459 /* allow NULL decrypt to indicate an station specific override
460 * for default encryption */
461 if (crypt && (crypt->ops == NULL ||
462 crypt->ops->decrypt_mpdu == NULL))
463 crypt = NULL;
464
465 if (!crypt && (fc & IEEE80211_FCTL_PROTECTED)) {
466 /* This seems to be triggered by some (multicast?)
467 * frames from other than current BSS, so just drop the
468 * frames silently instead of filling system log with
469 * these reports. */
470 IEEE80211_DEBUG_DROP("Decryption failed (not set)"
471 " (SA=" MAC_FMT ")\n",
472 hdr->addr2[0], hdr->addr2[1],
473 hdr->addr2[2], hdr->addr2[3],
474 hdr->addr2[4], hdr->addr2[5]);
475 ieee->ieee_stats.rx_discards_undecryptable++;
476 goto rx_dropped;
477 }
478 }
479#ifdef NOT_YET
480 if (type != WLAN_FC_TYPE_DATA) {
481 if (type == WLAN_FC_TYPE_MGMT && stype == WLAN_FC_STYPE_AUTH &&
482 fc & IEEE80211_FCTL_PROTECTED && ieee->host_decrypt &&
483 (keyidx = hostap_rx_frame_decrypt(ieee, skb, crypt)) < 0) {
484 printk(KERN_DEBUG "%s: failed to decrypt mgmt::auth "
485 "from " MAC_FMT "\n", dev->name,
486 hdr->addr2[0], hdr->addr2[1],
487 hdr->addr2[2], hdr->addr2[3],
488 hdr->addr2[4], hdr->addr2[5]);
489 /* TODO: could inform hostapd about this so that it
490 * could send auth failure report */
491 goto rx_dropped;
492 }
493
494 if (ieee80211_rx_frame_mgmt(ieee, skb, rx_stats, type, stype))
495 goto rx_dropped;
496 else
497 goto rx_exit;
498 }
499#endif
500 /* drop duplicate 802.11 retransmissions (IEEE 802.11 Chap. 9.29) */
501 if (sc == ieee->prev_seq_ctl)
502 goto rx_dropped;
503 else
504 ieee->prev_seq_ctl = sc;
505
506 /* Data frame - extract src/dst addresses */
507 if (skb->len < IEEE80211_3ADDR_LEN)
508 goto rx_dropped;
509
510 switch (fc & (IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS)) {
511 case IEEE80211_FCTL_FROMDS:
512 memcpy(dst, hdr->addr1, ETH_ALEN);
513 memcpy(src, hdr->addr3, ETH_ALEN);
514 break;
515 case IEEE80211_FCTL_TODS:
516 memcpy(dst, hdr->addr3, ETH_ALEN);
517 memcpy(src, hdr->addr2, ETH_ALEN);
518 break;
519 case IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS:
520 if (skb->len < IEEE80211_4ADDR_LEN)
521 goto rx_dropped;
522 memcpy(dst, hdr->addr3, ETH_ALEN);
523 memcpy(src, hdr->addr4, ETH_ALEN);
524 break;
525 case 0:
526 memcpy(dst, hdr->addr1, ETH_ALEN);
527 memcpy(src, hdr->addr2, ETH_ALEN);
528 break;
529 }
530
531#ifdef NOT_YET
532 if (hostap_rx_frame_wds(ieee, hdr, fc, &wds))
533 goto rx_dropped;
534 if (wds) {
535 skb->dev = dev = wds;
536 stats = hostap_get_stats(dev);
537 }
538
539 if (ieee->iw_mode == IW_MODE_MASTER && !wds &&
540 (fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) ==
541 IEEE80211_FCTL_FROMDS && ieee->stadev
542 && !compare_ether_addr(hdr->addr2, ieee->assoc_ap_addr)) {
543 /* Frame from BSSID of the AP for which we are a client */
544 skb->dev = dev = ieee->stadev;
545 stats = hostap_get_stats(dev);
546 from_assoc_ap = 1;
547 }
548#endif
549
550 dev->last_rx = jiffies;
551
552#ifdef NOT_YET
553 if ((ieee->iw_mode == IW_MODE_MASTER ||
554 ieee->iw_mode == IW_MODE_REPEAT) && !from_assoc_ap) {
555 switch (hostap_handle_sta_rx(ieee, dev, skb, rx_stats,
556 wds != NULL)) {
557 case AP_RX_CONTINUE_NOT_AUTHORIZED:
558 frame_authorized = 0;
559 break;
560 case AP_RX_CONTINUE:
561 frame_authorized = 1;
562 break;
563 case AP_RX_DROP:
564 goto rx_dropped;
565 case AP_RX_EXIT:
566 goto rx_exit;
567 }
568 }
569#endif
570
571 /* Nullfunc frames may have PS-bit set, so they must be passed to
572 * hostap_handle_sta_rx() before being dropped here. */
573
574 stype &= ~IEEE80211_STYPE_QOS_DATA;
575
576 if (stype != IEEE80211_STYPE_DATA &&
577 stype != IEEE80211_STYPE_DATA_CFACK &&
578 stype != IEEE80211_STYPE_DATA_CFPOLL &&
579 stype != IEEE80211_STYPE_DATA_CFACKPOLL) {
580 if (stype != IEEE80211_STYPE_NULLFUNC)
581 IEEE80211_DEBUG_DROP("RX: dropped data frame "
582 "with no data (type=0x%02x, "
583 "subtype=0x%02x, len=%d)\n",
584 type, stype, skb->len);
585 goto rx_dropped;
586 }
587
588 /* skb: hdr + (possibly fragmented, possibly encrypted) payload */
589
590 if ((fc & IEEE80211_FCTL_PROTECTED) && can_be_decrypted &&
591 (keyidx = ieee80211_rx_frame_decrypt(ieee, skb, crypt)) < 0)
592 goto rx_dropped;
593
594 hdr = (struct ieee80211_hdr_4addr *)skb->data;
595
596 /* skb: hdr + (possibly fragmented) plaintext payload */
597 // PR: FIXME: hostap has additional conditions in the "if" below:
598 // ieee->host_decrypt && (fc & IEEE80211_FCTL_PROTECTED) &&
599 if ((frag != 0) || (fc & IEEE80211_FCTL_MOREFRAGS)) {
600 int flen;
601 struct sk_buff *frag_skb = ieee80211_frag_cache_get(ieee, hdr);
602 IEEE80211_DEBUG_FRAG("Rx Fragment received (%u)\n", frag);
603
604 if (!frag_skb) {
605 IEEE80211_DEBUG(IEEE80211_DL_RX | IEEE80211_DL_FRAG,
606 "Rx cannot get skb from fragment "
607 "cache (morefrag=%d seq=%u frag=%u)\n",
608 (fc & IEEE80211_FCTL_MOREFRAGS) != 0,
609 WLAN_GET_SEQ_SEQ(sc), frag);
610 goto rx_dropped;
611 }
612
613 flen = skb->len;
614 if (frag != 0)
615 flen -= hdrlen;
616
617 if (frag_skb->tail + flen > frag_skb->end) {
618 printk(KERN_WARNING "%s: host decrypted and "
619 "reassembled frame did not fit skb\n",
620 dev->name);
621 ieee80211_frag_cache_invalidate(ieee, hdr);
622 goto rx_dropped;
623 }
624
625 if (frag == 0) {
626 /* copy first fragment (including full headers) into
627 * beginning of the fragment cache skb */
628 skb_copy_from_linear_data(skb, skb_put(frag_skb, flen), flen);
629 } else {
630 /* append frame payload to the end of the fragment
631 * cache skb */
632 skb_copy_from_linear_data_offset(skb, hdrlen,
633 skb_put(frag_skb, flen), flen);
634 }
635 dev_kfree_skb_any(skb);
636 skb = NULL;
637
638 if (fc & IEEE80211_FCTL_MOREFRAGS) {
639 /* more fragments expected - leave the skb in fragment
640 * cache for now; it will be delivered to upper layers
641 * after all fragments have been received */
642 goto rx_exit;
643 }
644
645 /* this was the last fragment and the frame will be
646 * delivered, so remove skb from fragment cache */
647 skb = frag_skb;
648 hdr = (struct ieee80211_hdr_4addr *)skb->data;
649 ieee80211_frag_cache_invalidate(ieee, hdr);
650 }
651
652 /* skb: hdr + (possible reassembled) full MSDU payload; possibly still
653 * encrypted/authenticated */
654 if ((fc & IEEE80211_FCTL_PROTECTED) && can_be_decrypted &&
655 ieee80211_rx_frame_decrypt_msdu(ieee, skb, keyidx, crypt))
656 goto rx_dropped;
657
658 hdr = (struct ieee80211_hdr_4addr *)skb->data;
659 if (crypt && !(fc & IEEE80211_FCTL_PROTECTED) && !ieee->open_wep) {
660 if ( /*ieee->ieee802_1x && */
661 ieee80211_is_eapol_frame(ieee, skb)) {
662 /* pass unencrypted EAPOL frames even if encryption is
663 * configured */
664 } else {
665 IEEE80211_DEBUG_DROP("encryption configured, but RX "
666 "frame not encrypted (SA="
667 MAC_FMT ")\n",
668 hdr->addr2[0], hdr->addr2[1],
669 hdr->addr2[2], hdr->addr2[3],
670 hdr->addr2[4], hdr->addr2[5]);
671 goto rx_dropped;
672 }
673 }
674
675 if (crypt && !(fc & IEEE80211_FCTL_PROTECTED) && !ieee->open_wep &&
676 !ieee80211_is_eapol_frame(ieee, skb)) {
677 IEEE80211_DEBUG_DROP("dropped unencrypted RX data "
678 "frame from " MAC_FMT
679 " (drop_unencrypted=1)\n",
680 hdr->addr2[0], hdr->addr2[1],
681 hdr->addr2[2], hdr->addr2[3],
682 hdr->addr2[4], hdr->addr2[5]);
683 goto rx_dropped;
684 }
685
686 /* If the frame was decrypted in hardware, we may need to strip off
687 * any security data (IV, ICV, etc) that was left behind */
688 if (!can_be_decrypted && (fc & IEEE80211_FCTL_PROTECTED) &&
689 ieee->host_strip_iv_icv) {
690 int trimlen = 0;
691
692 /* Top two-bits of byte 3 are the key index */
693 if (skb->len >= hdrlen + 3)
694 keyidx = skb->data[hdrlen + 3] >> 6;
695
696 /* To strip off any security data which appears before the
697 * payload, we simply increase hdrlen (as the header gets
698 * chopped off immediately below). For the security data which
699 * appears after the payload, we use skb_trim. */
700
701 switch (ieee->sec.encode_alg[keyidx]) {
702 case SEC_ALG_WEP:
703 /* 4 byte IV */
704 hdrlen += 4;
705 /* 4 byte ICV */
706 trimlen = 4;
707 break;
708 case SEC_ALG_TKIP:
709 /* 4 byte IV, 4 byte ExtIV */
710 hdrlen += 8;
711 /* 8 byte MIC, 4 byte ICV */
712 trimlen = 12;
713 break;
714 case SEC_ALG_CCMP:
715 /* 8 byte CCMP header */
716 hdrlen += 8;
717 /* 8 byte MIC */
718 trimlen = 8;
719 break;
720 }
721
722 if (skb->len < trimlen)
723 goto rx_dropped;
724
725 __skb_trim(skb, skb->len - trimlen);
726
727 if (skb->len < hdrlen)
728 goto rx_dropped;
729 }
730
731 /* skb: hdr + (possible reassembled) full plaintext payload */
732
733 payload = skb->data + hdrlen;
734 ethertype = (payload[6] << 8) | payload[7];
735
736#ifdef NOT_YET
737 /* If IEEE 802.1X is used, check whether the port is authorized to send
738 * the received frame. */
739 if (ieee->ieee802_1x && ieee->iw_mode == IW_MODE_MASTER) {
740 if (ethertype == ETH_P_PAE) {
741 printk(KERN_DEBUG "%s: RX: IEEE 802.1X frame\n",
742 dev->name);
743 if (ieee->hostapd && ieee->apdev) {
744 /* Send IEEE 802.1X frames to the user
745 * space daemon for processing */
746 prism2_rx_80211(ieee->apdev, skb, rx_stats,
747 PRISM2_RX_MGMT);
748 ieee->apdevstats.rx_packets++;
749 ieee->apdevstats.rx_bytes += skb->len;
750 goto rx_exit;
751 }
752 } else if (!frame_authorized) {
753 printk(KERN_DEBUG "%s: dropped frame from "
754 "unauthorized port (IEEE 802.1X): "
755 "ethertype=0x%04x\n", dev->name, ethertype);
756 goto rx_dropped;
757 }
758 }
759#endif
760
761 /* convert hdr + possible LLC headers into Ethernet header */
762 if (skb->len - hdrlen >= 8 &&
763 ((memcmp(payload, rfc1042_header, SNAP_SIZE) == 0 &&
764 ethertype != ETH_P_AARP && ethertype != ETH_P_IPX) ||
765 memcmp(payload, bridge_tunnel_header, SNAP_SIZE) == 0)) {
766 /* remove RFC1042 or Bridge-Tunnel encapsulation and
767 * replace EtherType */
768 skb_pull(skb, hdrlen + SNAP_SIZE);
769 memcpy(skb_push(skb, ETH_ALEN), src, ETH_ALEN);
770 memcpy(skb_push(skb, ETH_ALEN), dst, ETH_ALEN);
771 } else {
772 __be16 len;
773 /* Leave Ethernet header part of hdr and full payload */
774 skb_pull(skb, hdrlen);
775 len = htons(skb->len);
776 memcpy(skb_push(skb, 2), &len, 2);
777 memcpy(skb_push(skb, ETH_ALEN), src, ETH_ALEN);
778 memcpy(skb_push(skb, ETH_ALEN), dst, ETH_ALEN);
779 }
780
781#ifdef NOT_YET
782 if (wds && ((fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) ==
783 IEEE80211_FCTL_TODS) && skb->len >= ETH_HLEN + ETH_ALEN) {
784 /* Non-standard frame: get addr4 from its bogus location after
785 * the payload */
786 skb_copy_to_linear_data_offset(skb, ETH_ALEN,
787 skb->data + skb->len - ETH_ALEN,
788 ETH_ALEN);
789 skb_trim(skb, skb->len - ETH_ALEN);
790 }
791#endif
792
793 stats->rx_packets++;
794 stats->rx_bytes += skb->len;
795
796#ifdef NOT_YET
797 if (ieee->iw_mode == IW_MODE_MASTER && !wds && ieee->ap->bridge_packets) {
798 if (dst[0] & 0x01) {
799 /* copy multicast frame both to the higher layers and
800 * to the wireless media */
801 ieee->ap->bridged_multicast++;
802 skb2 = skb_clone(skb, GFP_ATOMIC);
803 if (skb2 == NULL)
804 printk(KERN_DEBUG "%s: skb_clone failed for "
805 "multicast frame\n", dev->name);
806 } else if (hostap_is_sta_assoc(ieee->ap, dst)) {
807 /* send frame directly to the associated STA using
808 * wireless media and not passing to higher layers */
809 ieee->ap->bridged_unicast++;
810 skb2 = skb;
811 skb = NULL;
812 }
813 }
814
815 if (skb2 != NULL) {
816 /* send to wireless media */
817 skb2->dev = dev;
818 skb2->protocol = htons(ETH_P_802_3);
819 skb_reset_mac_header(skb2);
820 skb_reset_network_header(skb2);
821 /* skb2->network_header += ETH_HLEN; */
822 dev_queue_xmit(skb2);
823 }
824#endif
825
826 if (skb) {
827 skb->protocol = eth_type_trans(skb, dev);
828 memset(skb->cb, 0, sizeof(skb->cb));
829 skb->ip_summed = CHECKSUM_NONE; /* 802.11 crc not sufficient */
830 if (netif_rx(skb) == NET_RX_DROP) {
831 /* netif_rx always succeeds, but it might drop
832 * the packet. If it drops the packet, we log that
833 * in our stats. */
834 IEEE80211_DEBUG_DROP
835 ("RX: netif_rx dropped the packet\n");
836 stats->rx_dropped++;
837 }
838 }
839
840 rx_exit:
841#ifdef NOT_YET
842 if (sta)
843 hostap_handle_sta_release(sta);
844#endif
845 return 1;
846
847 rx_dropped:
848 stats->rx_dropped++;
849
850 /* Returning 0 indicates to caller that we have not handled the SKB--
851 * so it is still allocated and can be used again by underlying
852 * hardware as a DMA target */
853 return 0;
854}
855
856/* Filter out unrelated packets, call ieee80211_rx[_mgt]
857 * This function takes over the skb, it should not be used again after calling
858 * this function. */
859void ieee80211_rx_any(struct ieee80211_device *ieee,
860 struct sk_buff *skb, struct ieee80211_rx_stats *stats)
861{
862 struct ieee80211_hdr_4addr *hdr;
863 int is_packet_for_us;
864 u16 fc;
865
866 if (ieee->iw_mode == IW_MODE_MONITOR) {
867 if (!ieee80211_rx(ieee, skb, stats))
868 dev_kfree_skb_irq(skb);
869 return;
870 }
871
872 if (skb->len < sizeof(struct ieee80211_hdr))
873 goto drop_free;
874
875 hdr = (struct ieee80211_hdr_4addr *)skb->data;
876 fc = le16_to_cpu(hdr->frame_ctl);
877
878 if ((fc & IEEE80211_FCTL_VERS) != 0)
879 goto drop_free;
880
881 switch (fc & IEEE80211_FCTL_FTYPE) {
882 case IEEE80211_FTYPE_MGMT:
883 if (skb->len < sizeof(struct ieee80211_hdr_3addr))
884 goto drop_free;
885 ieee80211_rx_mgt(ieee, hdr, stats);
886 dev_kfree_skb_irq(skb);
887 return;
888 case IEEE80211_FTYPE_DATA:
889 break;
890 case IEEE80211_FTYPE_CTL:
891 return;
892 default:
893 return;
894 }
895
896 is_packet_for_us = 0;
897 switch (ieee->iw_mode) {
898 case IW_MODE_ADHOC:
899 /* our BSS and not from/to DS */
900 if (memcmp(hdr->addr3, ieee->bssid, ETH_ALEN) == 0)
901 if ((fc & (IEEE80211_FCTL_TODS+IEEE80211_FCTL_FROMDS)) == 0) {
902 /* promisc: get all */
903 if (ieee->dev->flags & IFF_PROMISC)
904 is_packet_for_us = 1;
905 /* to us */
906 else if (memcmp(hdr->addr1, ieee->dev->dev_addr, ETH_ALEN) == 0)
907 is_packet_for_us = 1;
908 /* mcast */
909 else if (is_multicast_ether_addr(hdr->addr1))
910 is_packet_for_us = 1;
911 }
912 break;
913 case IW_MODE_INFRA:
914 /* our BSS (== from our AP) and from DS */
915 if (memcmp(hdr->addr2, ieee->bssid, ETH_ALEN) == 0)
916 if ((fc & (IEEE80211_FCTL_TODS+IEEE80211_FCTL_FROMDS)) == IEEE80211_FCTL_FROMDS) {
917 /* promisc: get all */
918 if (ieee->dev->flags & IFF_PROMISC)
919 is_packet_for_us = 1;
920 /* to us */
921 else if (memcmp(hdr->addr1, ieee->dev->dev_addr, ETH_ALEN) == 0)
922 is_packet_for_us = 1;
923 /* mcast */
924 else if (is_multicast_ether_addr(hdr->addr1)) {
925 /* not our own packet bcasted from AP */
926 if (memcmp(hdr->addr3, ieee->dev->dev_addr, ETH_ALEN))
927 is_packet_for_us = 1;
928 }
929 }
930 break;
931 default:
932 /* ? */
933 break;
934 }
935
936 if (is_packet_for_us)
937 if (!ieee80211_rx(ieee, skb, stats))
938 dev_kfree_skb_irq(skb);
939 return;
940
941drop_free:
942 dev_kfree_skb_irq(skb);
943 ieee->stats.rx_dropped++;
944 return;
945}
946
947#define MGMT_FRAME_FIXED_PART_LENGTH 0x24
948
949static u8 qos_oui[QOS_OUI_LEN] = { 0x00, 0x50, 0xF2 };
950
951/*
952* Make ther structure we read from the beacon packet has
953* the right values
954*/
955static int ieee80211_verify_qos_info(struct ieee80211_qos_information_element
956 *info_element, int sub_type)
957{
958
959 if (info_element->qui_subtype != sub_type)
960 return -1;
961 if (memcmp(info_element->qui, qos_oui, QOS_OUI_LEN))
962 return -1;
963 if (info_element->qui_type != QOS_OUI_TYPE)
964 return -1;
965 if (info_element->version != QOS_VERSION_1)
966 return -1;
967
968 return 0;
969}
970
971/*
972 * Parse a QoS parameter element
973 */
974static int ieee80211_read_qos_param_element(struct ieee80211_qos_parameter_info
975 *element_param, struct ieee80211_info_element
976 *info_element)
977{
978 int ret = 0;
979 u16 size = sizeof(struct ieee80211_qos_parameter_info) - 2;
980
981 if ((info_element == NULL) || (element_param == NULL))
982 return -1;
983
984 if (info_element->id == QOS_ELEMENT_ID && info_element->len == size) {
985 memcpy(element_param->info_element.qui, info_element->data,
986 info_element->len);
987 element_param->info_element.elementID = info_element->id;
988 element_param->info_element.length = info_element->len;
989 } else
990 ret = -1;
991 if (ret == 0)
992 ret = ieee80211_verify_qos_info(&element_param->info_element,
993 QOS_OUI_PARAM_SUB_TYPE);
994 return ret;
995}
996
997/*
998 * Parse a QoS information element
999 */
1000static int ieee80211_read_qos_info_element(struct
1001 ieee80211_qos_information_element
1002 *element_info, struct ieee80211_info_element
1003 *info_element)
1004{
1005 int ret = 0;
1006 u16 size = sizeof(struct ieee80211_qos_information_element) - 2;
1007
1008 if (element_info == NULL)
1009 return -1;
1010 if (info_element == NULL)
1011 return -1;
1012
1013 if ((info_element->id == QOS_ELEMENT_ID) && (info_element->len == size)) {
1014 memcpy(element_info->qui, info_element->data,
1015 info_element->len);
1016 element_info->elementID = info_element->id;
1017 element_info->length = info_element->len;
1018 } else
1019 ret = -1;
1020
1021 if (ret == 0)
1022 ret = ieee80211_verify_qos_info(element_info,
1023 QOS_OUI_INFO_SUB_TYPE);
1024 return ret;
1025}
1026
1027/*
1028 * Write QoS parameters from the ac parameters.
1029 */
1030static int ieee80211_qos_convert_ac_to_parameters(struct
1031 ieee80211_qos_parameter_info
1032 *param_elm, struct
1033 ieee80211_qos_parameters
1034 *qos_param)
1035{
1036 int rc = 0;
1037 int i;
1038 struct ieee80211_qos_ac_parameter *ac_params;
1039 u32 txop;
1040 u8 cw_min;
1041 u8 cw_max;
1042
1043 for (i = 0; i < QOS_QUEUE_NUM; i++) {
1044 ac_params = &(param_elm->ac_params_record[i]);
1045
1046 qos_param->aifs[i] = (ac_params->aci_aifsn) & 0x0F;
1047 qos_param->aifs[i] -= (qos_param->aifs[i] < 2) ? 0 : 2;
1048
1049 cw_min = ac_params->ecw_min_max & 0x0F;
1050 qos_param->cw_min[i] = cpu_to_le16((1 << cw_min) - 1);
1051
1052 cw_max = (ac_params->ecw_min_max & 0xF0) >> 4;
1053 qos_param->cw_max[i] = cpu_to_le16((1 << cw_max) - 1);
1054
1055 qos_param->flag[i] =
1056 (ac_params->aci_aifsn & 0x10) ? 0x01 : 0x00;
1057
1058 txop = le16_to_cpu(ac_params->tx_op_limit) * 32;
1059 qos_param->tx_op_limit[i] = cpu_to_le16(txop);
1060 }
1061 return rc;
1062}
1063
1064/*
1065 * we have a generic data element which it may contain QoS information or
1066 * parameters element. check the information element length to decide
1067 * which type to read
1068 */
1069static int ieee80211_parse_qos_info_param_IE(struct ieee80211_info_element
1070 *info_element,
1071 struct ieee80211_network *network)
1072{
1073 int rc = 0;
1074 struct ieee80211_qos_parameters *qos_param = NULL;
1075 struct ieee80211_qos_information_element qos_info_element;
1076
1077 rc = ieee80211_read_qos_info_element(&qos_info_element, info_element);
1078
1079 if (rc == 0) {
1080 network->qos_data.param_count = qos_info_element.ac_info & 0x0F;
1081 network->flags |= NETWORK_HAS_QOS_INFORMATION;
1082 } else {
1083 struct ieee80211_qos_parameter_info param_element;
1084
1085 rc = ieee80211_read_qos_param_element(&param_element,
1086 info_element);
1087 if (rc == 0) {
1088 qos_param = &(network->qos_data.parameters);
1089 ieee80211_qos_convert_ac_to_parameters(&param_element,
1090 qos_param);
1091 network->flags |= NETWORK_HAS_QOS_PARAMETERS;
1092 network->qos_data.param_count =
1093 param_element.info_element.ac_info & 0x0F;
1094 }
1095 }
1096
1097 if (rc == 0) {
1098 IEEE80211_DEBUG_QOS("QoS is supported\n");
1099 network->qos_data.supported = 1;
1100 }
1101 return rc;
1102}
1103
1104#ifdef CONFIG_IEEE80211_DEBUG
1105#define MFIE_STRING(x) case MFIE_TYPE_ ##x: return #x
1106
1107static const char *get_info_element_string(u16 id)
1108{
1109 switch (id) {
1110 MFIE_STRING(SSID);
1111 MFIE_STRING(RATES);
1112 MFIE_STRING(FH_SET);
1113 MFIE_STRING(DS_SET);
1114 MFIE_STRING(CF_SET);
1115 MFIE_STRING(TIM);
1116 MFIE_STRING(IBSS_SET);
1117 MFIE_STRING(COUNTRY);
1118 MFIE_STRING(HOP_PARAMS);
1119 MFIE_STRING(HOP_TABLE);
1120 MFIE_STRING(REQUEST);
1121 MFIE_STRING(CHALLENGE);
1122 MFIE_STRING(POWER_CONSTRAINT);
1123 MFIE_STRING(POWER_CAPABILITY);
1124 MFIE_STRING(TPC_REQUEST);
1125 MFIE_STRING(TPC_REPORT);
1126 MFIE_STRING(SUPP_CHANNELS);
1127 MFIE_STRING(CSA);
1128 MFIE_STRING(MEASURE_REQUEST);
1129 MFIE_STRING(MEASURE_REPORT);
1130 MFIE_STRING(QUIET);
1131 MFIE_STRING(IBSS_DFS);
1132 MFIE_STRING(ERP_INFO);
1133 MFIE_STRING(RSN);
1134 MFIE_STRING(RATES_EX);
1135 MFIE_STRING(GENERIC);
1136 MFIE_STRING(QOS_PARAMETER);
1137 default:
1138 return "UNKNOWN";
1139 }
1140}
1141#endif
1142
1143static int ieee80211_parse_info_param(struct ieee80211_info_element
1144 *info_element, u16 length,
1145 struct ieee80211_network *network)
1146{
1147 u8 i;
1148#ifdef CONFIG_IEEE80211_DEBUG
1149 char rates_str[64];
1150 char *p;
1151#endif
1152
1153 while (length >= sizeof(*info_element)) {
1154 if (sizeof(*info_element) + info_element->len > length) {
1155 IEEE80211_DEBUG_MGMT("Info elem: parse failed: "
1156 "info_element->len + 2 > left : "
1157 "info_element->len+2=%zd left=%d, id=%d.\n",
1158 info_element->len +
1159 sizeof(*info_element),
1160 length, info_element->id);
1161 /* We stop processing but don't return an error here
1162 * because some misbehaviour APs break this rule. ie.
1163 * Orinoco AP1000. */
1164 break;
1165 }
1166
1167 switch (info_element->id) {
1168 case MFIE_TYPE_SSID:
1169 if (ieee80211_is_empty_essid(info_element->data,
1170 info_element->len)) {
1171 network->flags |= NETWORK_EMPTY_ESSID;
1172 break;
1173 }
1174
1175 network->ssid_len = min(info_element->len,
1176 (u8) IW_ESSID_MAX_SIZE);
1177 memcpy(network->ssid, info_element->data,
1178 network->ssid_len);
1179 if (network->ssid_len < IW_ESSID_MAX_SIZE)
1180 memset(network->ssid + network->ssid_len, 0,
1181 IW_ESSID_MAX_SIZE - network->ssid_len);
1182
1183 IEEE80211_DEBUG_MGMT("MFIE_TYPE_SSID: '%s' len=%d.\n",
1184 network->ssid, network->ssid_len);
1185 break;
1186
1187 case MFIE_TYPE_RATES:
1188#ifdef CONFIG_IEEE80211_DEBUG
1189 p = rates_str;
1190#endif
1191 network->rates_len = min(info_element->len,
1192 MAX_RATES_LENGTH);
1193 for (i = 0; i < network->rates_len; i++) {
1194 network->rates[i] = info_element->data[i];
1195#ifdef CONFIG_IEEE80211_DEBUG
1196 p += snprintf(p, sizeof(rates_str) -
1197 (p - rates_str), "%02X ",
1198 network->rates[i]);
1199#endif
1200 if (ieee80211_is_ofdm_rate
1201 (info_element->data[i])) {
1202 network->flags |= NETWORK_HAS_OFDM;
1203 if (info_element->data[i] &
1204 IEEE80211_BASIC_RATE_MASK)
1205 network->flags &=
1206 ~NETWORK_HAS_CCK;
1207 }
1208 }
1209
1210 IEEE80211_DEBUG_MGMT("MFIE_TYPE_RATES: '%s' (%d)\n",
1211 rates_str, network->rates_len);
1212 break;
1213
1214 case MFIE_TYPE_RATES_EX:
1215#ifdef CONFIG_IEEE80211_DEBUG
1216 p = rates_str;
1217#endif
1218 network->rates_ex_len = min(info_element->len,
1219 MAX_RATES_EX_LENGTH);
1220 for (i = 0; i < network->rates_ex_len; i++) {
1221 network->rates_ex[i] = info_element->data[i];
1222#ifdef CONFIG_IEEE80211_DEBUG
1223 p += snprintf(p, sizeof(rates_str) -
1224 (p - rates_str), "%02X ",
1225 network->rates[i]);
1226#endif
1227 if (ieee80211_is_ofdm_rate
1228 (info_element->data[i])) {
1229 network->flags |= NETWORK_HAS_OFDM;
1230 if (info_element->data[i] &
1231 IEEE80211_BASIC_RATE_MASK)
1232 network->flags &=
1233 ~NETWORK_HAS_CCK;
1234 }
1235 }
1236
1237 IEEE80211_DEBUG_MGMT("MFIE_TYPE_RATES_EX: '%s' (%d)\n",
1238 rates_str, network->rates_ex_len);
1239 break;
1240
1241 case MFIE_TYPE_DS_SET:
1242 IEEE80211_DEBUG_MGMT("MFIE_TYPE_DS_SET: %d\n",
1243 info_element->data[0]);
1244 network->channel = info_element->data[0];
1245 break;
1246
1247 case MFIE_TYPE_FH_SET:
1248 IEEE80211_DEBUG_MGMT("MFIE_TYPE_FH_SET: ignored\n");
1249 break;
1250
1251 case MFIE_TYPE_CF_SET:
1252 IEEE80211_DEBUG_MGMT("MFIE_TYPE_CF_SET: ignored\n");
1253 break;
1254
1255 case MFIE_TYPE_TIM:
1256 network->tim.tim_count = info_element->data[0];
1257 network->tim.tim_period = info_element->data[1];
1258 IEEE80211_DEBUG_MGMT("MFIE_TYPE_TIM: partially ignored\n");
1259 break;
1260
1261 case MFIE_TYPE_ERP_INFO:
1262 network->erp_value = info_element->data[0];
1263 network->flags |= NETWORK_HAS_ERP_VALUE;
1264 IEEE80211_DEBUG_MGMT("MFIE_TYPE_ERP_SET: %d\n",
1265 network->erp_value);
1266 break;
1267
1268 case MFIE_TYPE_IBSS_SET:
1269 network->atim_window = info_element->data[0];
1270 IEEE80211_DEBUG_MGMT("MFIE_TYPE_IBSS_SET: %d\n",
1271 network->atim_window);
1272 break;
1273
1274 case MFIE_TYPE_CHALLENGE:
1275 IEEE80211_DEBUG_MGMT("MFIE_TYPE_CHALLENGE: ignored\n");
1276 break;
1277
1278 case MFIE_TYPE_GENERIC:
1279 IEEE80211_DEBUG_MGMT("MFIE_TYPE_GENERIC: %d bytes\n",
1280 info_element->len);
1281 if (!ieee80211_parse_qos_info_param_IE(info_element,
1282 network))
1283 break;
1284
1285 if (info_element->len >= 4 &&
1286 info_element->data[0] == 0x00 &&
1287 info_element->data[1] == 0x50 &&
1288 info_element->data[2] == 0xf2 &&
1289 info_element->data[3] == 0x01) {
1290 network->wpa_ie_len = min(info_element->len + 2,
1291 MAX_WPA_IE_LEN);
1292 memcpy(network->wpa_ie, info_element,
1293 network->wpa_ie_len);
1294 }
1295 break;
1296
1297 case MFIE_TYPE_RSN:
1298 IEEE80211_DEBUG_MGMT("MFIE_TYPE_RSN: %d bytes\n",
1299 info_element->len);
1300 network->rsn_ie_len = min(info_element->len + 2,
1301 MAX_WPA_IE_LEN);
1302 memcpy(network->rsn_ie, info_element,
1303 network->rsn_ie_len);
1304 break;
1305
1306 case MFIE_TYPE_QOS_PARAMETER:
1307 printk(KERN_ERR
1308 "QoS Error need to parse QOS_PARAMETER IE\n");
1309 break;
1310 /* 802.11h */
1311 case MFIE_TYPE_POWER_CONSTRAINT:
1312 network->power_constraint = info_element->data[0];
1313 network->flags |= NETWORK_HAS_POWER_CONSTRAINT;
1314 break;
1315
1316 case MFIE_TYPE_CSA:
1317 network->power_constraint = info_element->data[0];
1318 network->flags |= NETWORK_HAS_CSA;
1319 break;
1320
1321 case MFIE_TYPE_QUIET:
1322 network->quiet.count = info_element->data[0];
1323 network->quiet.period = info_element->data[1];
1324 network->quiet.duration = info_element->data[2];
1325 network->quiet.offset = info_element->data[3];
1326 network->flags |= NETWORK_HAS_QUIET;
1327 break;
1328
1329 case MFIE_TYPE_IBSS_DFS:
1330 if (network->ibss_dfs)
1331 break;
1332 network->ibss_dfs = kmemdup(info_element->data,
1333 info_element->len,
1334 GFP_ATOMIC);
1335 if (!network->ibss_dfs)
1336 return 1;
1337 network->flags |= NETWORK_HAS_IBSS_DFS;
1338 break;
1339
1340 case MFIE_TYPE_TPC_REPORT:
1341 network->tpc_report.transmit_power =
1342 info_element->data[0];
1343 network->tpc_report.link_margin = info_element->data[1];
1344 network->flags |= NETWORK_HAS_TPC_REPORT;
1345 break;
1346
1347 default:
1348 IEEE80211_DEBUG_MGMT
1349 ("Unsupported info element: %s (%d)\n",
1350 get_info_element_string(info_element->id),
1351 info_element->id);
1352 break;
1353 }
1354
1355 length -= sizeof(*info_element) + info_element->len;
1356 info_element =
1357 (struct ieee80211_info_element *)&info_element->
1358 data[info_element->len];
1359 }
1360
1361 return 0;
1362}
1363
1364static int ieee80211_handle_assoc_resp(struct ieee80211_device *ieee, struct ieee80211_assoc_response
1365 *frame, struct ieee80211_rx_stats *stats)
1366{
1367 struct ieee80211_network network_resp = {
1368 .ibss_dfs = NULL,
1369 };
1370 struct ieee80211_network *network = &network_resp;
1371 struct net_device *dev = ieee->dev;
1372
1373 network->flags = 0;
1374 network->qos_data.active = 0;
1375 network->qos_data.supported = 0;
1376 network->qos_data.param_count = 0;
1377 network->qos_data.old_param_count = 0;
1378
1379 //network->atim_window = le16_to_cpu(frame->aid) & (0x3FFF);
1380 network->atim_window = le16_to_cpu(frame->aid);
1381 network->listen_interval = le16_to_cpu(frame->status);
1382 memcpy(network->bssid, frame->header.addr3, ETH_ALEN);
1383 network->capability = le16_to_cpu(frame->capability);
1384 network->last_scanned = jiffies;
1385 network->rates_len = network->rates_ex_len = 0;
1386 network->last_associate = 0;
1387 network->ssid_len = 0;
1388 network->erp_value =
1389 (network->capability & WLAN_CAPABILITY_IBSS) ? 0x3 : 0x0;
1390
1391 if (stats->freq == IEEE80211_52GHZ_BAND) {
1392 /* for A band (No DS info) */
1393 network->channel = stats->received_channel;
1394 } else
1395 network->flags |= NETWORK_HAS_CCK;
1396
1397 network->wpa_ie_len = 0;
1398 network->rsn_ie_len = 0;
1399
1400 if (ieee80211_parse_info_param
1401 (frame->info_element, stats->len - sizeof(*frame), network))
1402 return 1;
1403
1404 network->mode = 0;
1405 if (stats->freq == IEEE80211_52GHZ_BAND)
1406 network->mode = IEEE_A;
1407 else {
1408 if (network->flags & NETWORK_HAS_OFDM)
1409 network->mode |= IEEE_G;
1410 if (network->flags & NETWORK_HAS_CCK)
1411 network->mode |= IEEE_B;
1412 }
1413
1414 if (ieee80211_is_empty_essid(network->ssid, network->ssid_len))
1415 network->flags |= NETWORK_EMPTY_ESSID;
1416
1417 memcpy(&network->stats, stats, sizeof(network->stats));
1418
1419 if (ieee->handle_assoc_response != NULL)
1420 ieee->handle_assoc_response(dev, frame, network);
1421
1422 return 0;
1423}
1424
1425/***************************************************/
1426
1427static int ieee80211_network_init(struct ieee80211_device *ieee, struct ieee80211_probe_response
1428 *beacon,
1429 struct ieee80211_network *network,
1430 struct ieee80211_rx_stats *stats)
1431{
1432 DECLARE_MAC_BUF(mac);
1433
1434 network->qos_data.active = 0;
1435 network->qos_data.supported = 0;
1436 network->qos_data.param_count = 0;
1437 network->qos_data.old_param_count = 0;
1438
1439 /* Pull out fixed field data */
1440 memcpy(network->bssid, beacon->header.addr3, ETH_ALEN);
1441 network->capability = le16_to_cpu(beacon->capability);
1442 network->last_scanned = jiffies;
1443 network->time_stamp[0] = le32_to_cpu(beacon->time_stamp[0]);
1444 network->time_stamp[1] = le32_to_cpu(beacon->time_stamp[1]);
1445 network->beacon_interval = le16_to_cpu(beacon->beacon_interval);
1446 /* Where to pull this? beacon->listen_interval; */
1447 network->listen_interval = 0x0A;
1448 network->rates_len = network->rates_ex_len = 0;
1449 network->last_associate = 0;
1450 network->ssid_len = 0;
1451 network->flags = 0;
1452 network->atim_window = 0;
1453 network->erp_value = (network->capability & WLAN_CAPABILITY_IBSS) ?
1454 0x3 : 0x0;
1455
1456 if (stats->freq == IEEE80211_52GHZ_BAND) {
1457 /* for A band (No DS info) */
1458 network->channel = stats->received_channel;
1459 } else
1460 network->flags |= NETWORK_HAS_CCK;
1461
1462 network->wpa_ie_len = 0;
1463 network->rsn_ie_len = 0;
1464
1465 if (ieee80211_parse_info_param
1466 (beacon->info_element, stats->len - sizeof(*beacon), network))
1467 return 1;
1468
1469 network->mode = 0;
1470 if (stats->freq == IEEE80211_52GHZ_BAND)
1471 network->mode = IEEE_A;
1472 else {
1473 if (network->flags & NETWORK_HAS_OFDM)
1474 network->mode |= IEEE_G;
1475 if (network->flags & NETWORK_HAS_CCK)
1476 network->mode |= IEEE_B;
1477 }
1478
1479 if (network->mode == 0) {
1480 IEEE80211_DEBUG_SCAN("Filtered out '%s (%s)' "
1481 "network.\n",
1482 escape_essid(network->ssid,
1483 network->ssid_len),
1484 print_mac(mac, network->bssid));
1485 return 1;
1486 }
1487
1488 if (ieee80211_is_empty_essid(network->ssid, network->ssid_len))
1489 network->flags |= NETWORK_EMPTY_ESSID;
1490
1491 memcpy(&network->stats, stats, sizeof(network->stats));
1492
1493 return 0;
1494}
1495
1496static inline int is_same_network(struct ieee80211_network *src,
1497 struct ieee80211_network *dst)
1498{
1499 /* A network is only a duplicate if the channel, BSSID, and ESSID
1500 * all match. We treat all <hidden> with the same BSSID and channel
1501 * as one network */
1502 return ((src->ssid_len == dst->ssid_len) &&
1503 (src->channel == dst->channel) &&
1504 !compare_ether_addr(src->bssid, dst->bssid) &&
1505 !memcmp(src->ssid, dst->ssid, src->ssid_len));
1506}
1507
1508static void update_network(struct ieee80211_network *dst,
1509 struct ieee80211_network *src)
1510{
1511 int qos_active;
1512 u8 old_param;
1513 DECLARE_MAC_BUF(mac);
1514
1515 ieee80211_network_reset(dst);
1516 dst->ibss_dfs = src->ibss_dfs;
1517
1518 /* We only update the statistics if they were created by receiving
1519 * the network information on the actual channel the network is on.
1520 *
1521 * This keeps beacons received on neighbor channels from bringing
1522 * down the signal level of an AP. */
1523 if (dst->channel == src->stats.received_channel)
1524 memcpy(&dst->stats, &src->stats,
1525 sizeof(struct ieee80211_rx_stats));
1526 else
1527 IEEE80211_DEBUG_SCAN("Network %s info received "
1528 "off channel (%d vs. %d)\n", print_mac(mac, src->bssid),
1529 dst->channel, src->stats.received_channel);
1530
1531 dst->capability = src->capability;
1532 memcpy(dst->rates, src->rates, src->rates_len);
1533 dst->rates_len = src->rates_len;
1534 memcpy(dst->rates_ex, src->rates_ex, src->rates_ex_len);
1535 dst->rates_ex_len = src->rates_ex_len;
1536
1537 dst->mode = src->mode;
1538 dst->flags = src->flags;
1539 dst->time_stamp[0] = src->time_stamp[0];
1540 dst->time_stamp[1] = src->time_stamp[1];
1541
1542 dst->beacon_interval = src->beacon_interval;
1543 dst->listen_interval = src->listen_interval;
1544 dst->atim_window = src->atim_window;
1545 dst->erp_value = src->erp_value;
1546 dst->tim = src->tim;
1547
1548 memcpy(dst->wpa_ie, src->wpa_ie, src->wpa_ie_len);
1549 dst->wpa_ie_len = src->wpa_ie_len;
1550 memcpy(dst->rsn_ie, src->rsn_ie, src->rsn_ie_len);
1551 dst->rsn_ie_len = src->rsn_ie_len;
1552
1553 dst->last_scanned = jiffies;
1554 qos_active = src->qos_data.active;
1555 old_param = dst->qos_data.old_param_count;
1556 if (dst->flags & NETWORK_HAS_QOS_MASK)
1557 memcpy(&dst->qos_data, &src->qos_data,
1558 sizeof(struct ieee80211_qos_data));
1559 else {
1560 dst->qos_data.supported = src->qos_data.supported;
1561 dst->qos_data.param_count = src->qos_data.param_count;
1562 }
1563
1564 if (dst->qos_data.supported == 1) {
1565 if (dst->ssid_len)
1566 IEEE80211_DEBUG_QOS
1567 ("QoS the network %s is QoS supported\n",
1568 dst->ssid);
1569 else
1570 IEEE80211_DEBUG_QOS
1571 ("QoS the network is QoS supported\n");
1572 }
1573 dst->qos_data.active = qos_active;
1574 dst->qos_data.old_param_count = old_param;
1575
1576 /* dst->last_associate is not overwritten */
1577}
1578
1579static inline int is_beacon(__le16 fc)
1580{
1581 return (WLAN_FC_GET_STYPE(le16_to_cpu(fc)) == IEEE80211_STYPE_BEACON);
1582}
1583
1584static void ieee80211_process_probe_response(struct ieee80211_device
1585 *ieee, struct
1586 ieee80211_probe_response
1587 *beacon, struct ieee80211_rx_stats
1588 *stats)
1589{
1590 struct net_device *dev = ieee->dev;
1591 struct ieee80211_network network = {
1592 .ibss_dfs = NULL,
1593 };
1594 struct ieee80211_network *target;
1595 struct ieee80211_network *oldest = NULL;
1596#ifdef CONFIG_IEEE80211_DEBUG
1597 struct ieee80211_info_element *info_element = beacon->info_element;
1598#endif
1599 unsigned long flags;
1600 DECLARE_MAC_BUF(mac);
1601
1602 IEEE80211_DEBUG_SCAN("'%s' (%s"
1603 "): %c%c%c%c %c%c%c%c-%c%c%c%c %c%c%c%c\n",
1604 escape_essid(info_element->data, info_element->len),
1605 print_mac(mac, beacon->header.addr3),
1606 (beacon->capability & cpu_to_le16(1 << 0xf)) ? '1' : '0',
1607 (beacon->capability & cpu_to_le16(1 << 0xe)) ? '1' : '0',
1608 (beacon->capability & cpu_to_le16(1 << 0xd)) ? '1' : '0',
1609 (beacon->capability & cpu_to_le16(1 << 0xc)) ? '1' : '0',
1610 (beacon->capability & cpu_to_le16(1 << 0xb)) ? '1' : '0',
1611 (beacon->capability & cpu_to_le16(1 << 0xa)) ? '1' : '0',
1612 (beacon->capability & cpu_to_le16(1 << 0x9)) ? '1' : '0',
1613 (beacon->capability & cpu_to_le16(1 << 0x8)) ? '1' : '0',
1614 (beacon->capability & cpu_to_le16(1 << 0x7)) ? '1' : '0',
1615 (beacon->capability & cpu_to_le16(1 << 0x6)) ? '1' : '0',
1616 (beacon->capability & cpu_to_le16(1 << 0x5)) ? '1' : '0',
1617 (beacon->capability & cpu_to_le16(1 << 0x4)) ? '1' : '0',
1618 (beacon->capability & cpu_to_le16(1 << 0x3)) ? '1' : '0',
1619 (beacon->capability & cpu_to_le16(1 << 0x2)) ? '1' : '0',
1620 (beacon->capability & cpu_to_le16(1 << 0x1)) ? '1' : '0',
1621 (beacon->capability & cpu_to_le16(1 << 0x0)) ? '1' : '0');
1622
1623 if (ieee80211_network_init(ieee, beacon, &network, stats)) {
1624 IEEE80211_DEBUG_SCAN("Dropped '%s' (%s) via %s.\n",
1625 escape_essid(info_element->data,
1626 info_element->len),
1627 print_mac(mac, beacon->header.addr3),
1628 is_beacon(beacon->header.frame_ctl) ?
1629 "BEACON" : "PROBE RESPONSE");
1630 return;
1631 }
1632
1633 /* The network parsed correctly -- so now we scan our known networks
1634 * to see if we can find it in our list.
1635 *
1636 * NOTE: This search is definitely not optimized. Once its doing
1637 * the "right thing" we'll optimize it for efficiency if
1638 * necessary */
1639
1640 /* Search for this entry in the list and update it if it is
1641 * already there. */
1642
1643 spin_lock_irqsave(&ieee->lock, flags);
1644
1645 list_for_each_entry(target, &ieee->network_list, list) {
1646 if (is_same_network(target, &network))
1647 break;
1648
1649 if ((oldest == NULL) ||
1650 (target->last_scanned < oldest->last_scanned))
1651 oldest = target;
1652 }
1653
1654 /* If we didn't find a match, then get a new network slot to initialize
1655 * with this beacon's information */
1656 if (&target->list == &ieee->network_list) {
1657 if (list_empty(&ieee->network_free_list)) {
1658 /* If there are no more slots, expire the oldest */
1659 list_del(&oldest->list);
1660 target = oldest;
1661 IEEE80211_DEBUG_SCAN("Expired '%s' (%s) from "
1662 "network list.\n",
1663 escape_essid(target->ssid,
1664 target->ssid_len),
1665 print_mac(mac, target->bssid));
1666 ieee80211_network_reset(target);
1667 } else {
1668 /* Otherwise just pull from the free list */
1669 target = list_entry(ieee->network_free_list.next,
1670 struct ieee80211_network, list);
1671 list_del(ieee->network_free_list.next);
1672 }
1673
1674#ifdef CONFIG_IEEE80211_DEBUG
1675 IEEE80211_DEBUG_SCAN("Adding '%s' (%s) via %s.\n",
1676 escape_essid(network.ssid,
1677 network.ssid_len),
1678 print_mac(mac, network.bssid),
1679 is_beacon(beacon->header.frame_ctl) ?
1680 "BEACON" : "PROBE RESPONSE");
1681#endif
1682 memcpy(target, &network, sizeof(*target));
1683 network.ibss_dfs = NULL;
1684 list_add_tail(&target->list, &ieee->network_list);
1685 } else {
1686 IEEE80211_DEBUG_SCAN("Updating '%s' (%s) via %s.\n",
1687 escape_essid(target->ssid,
1688 target->ssid_len),
1689 print_mac(mac, target->bssid),
1690 is_beacon(beacon->header.frame_ctl) ?
1691 "BEACON" : "PROBE RESPONSE");
1692 update_network(target, &network);
1693 network.ibss_dfs = NULL;
1694 }
1695
1696 spin_unlock_irqrestore(&ieee->lock, flags);
1697
1698 if (is_beacon(beacon->header.frame_ctl)) {
1699 if (ieee->handle_beacon != NULL)
1700 ieee->handle_beacon(dev, beacon, target);
1701 } else {
1702 if (ieee->handle_probe_response != NULL)
1703 ieee->handle_probe_response(dev, beacon, target);
1704 }
1705}
1706
1707void ieee80211_rx_mgt(struct ieee80211_device *ieee,
1708 struct ieee80211_hdr_4addr *header,
1709 struct ieee80211_rx_stats *stats)
1710{
1711 switch (WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl))) {
1712 case IEEE80211_STYPE_ASSOC_RESP:
1713 IEEE80211_DEBUG_MGMT("received ASSOCIATION RESPONSE (%d)\n",
1714 WLAN_FC_GET_STYPE(le16_to_cpu
1715 (header->frame_ctl)));
1716 ieee80211_handle_assoc_resp(ieee,
1717 (struct ieee80211_assoc_response *)
1718 header, stats);
1719 break;
1720
1721 case IEEE80211_STYPE_REASSOC_RESP:
1722 IEEE80211_DEBUG_MGMT("received REASSOCIATION RESPONSE (%d)\n",
1723 WLAN_FC_GET_STYPE(le16_to_cpu
1724 (header->frame_ctl)));
1725 break;
1726
1727 case IEEE80211_STYPE_PROBE_REQ:
1728 IEEE80211_DEBUG_MGMT("received auth (%d)\n",
1729 WLAN_FC_GET_STYPE(le16_to_cpu
1730 (header->frame_ctl)));
1731
1732 if (ieee->handle_probe_request != NULL)
1733 ieee->handle_probe_request(ieee->dev,
1734 (struct
1735 ieee80211_probe_request *)
1736 header, stats);
1737 break;
1738
1739 case IEEE80211_STYPE_PROBE_RESP:
1740 IEEE80211_DEBUG_MGMT("received PROBE RESPONSE (%d)\n",
1741 WLAN_FC_GET_STYPE(le16_to_cpu
1742 (header->frame_ctl)));
1743 IEEE80211_DEBUG_SCAN("Probe response\n");
1744 ieee80211_process_probe_response(ieee,
1745 (struct
1746 ieee80211_probe_response *)
1747 header, stats);
1748 break;
1749
1750 case IEEE80211_STYPE_BEACON:
1751 IEEE80211_DEBUG_MGMT("received BEACON (%d)\n",
1752 WLAN_FC_GET_STYPE(le16_to_cpu
1753 (header->frame_ctl)));
1754 IEEE80211_DEBUG_SCAN("Beacon\n");
1755 ieee80211_process_probe_response(ieee,
1756 (struct
1757 ieee80211_probe_response *)
1758 header, stats);
1759 break;
1760 case IEEE80211_STYPE_AUTH:
1761
1762 IEEE80211_DEBUG_MGMT("received auth (%d)\n",
1763 WLAN_FC_GET_STYPE(le16_to_cpu
1764 (header->frame_ctl)));
1765
1766 if (ieee->handle_auth != NULL)
1767 ieee->handle_auth(ieee->dev,
1768 (struct ieee80211_auth *)header);
1769 break;
1770
1771 case IEEE80211_STYPE_DISASSOC:
1772 if (ieee->handle_disassoc != NULL)
1773 ieee->handle_disassoc(ieee->dev,
1774 (struct ieee80211_disassoc *)
1775 header);
1776 break;
1777
1778 case IEEE80211_STYPE_ACTION:
1779 IEEE80211_DEBUG_MGMT("ACTION\n");
1780 if (ieee->handle_action)
1781 ieee->handle_action(ieee->dev,
1782 (struct ieee80211_action *)
1783 header, stats);
1784 break;
1785
1786 case IEEE80211_STYPE_REASSOC_REQ:
1787 IEEE80211_DEBUG_MGMT("received reassoc (%d)\n",
1788 WLAN_FC_GET_STYPE(le16_to_cpu
1789 (header->frame_ctl)));
1790
1791 IEEE80211_DEBUG_MGMT("%s: IEEE80211_REASSOC_REQ received\n",
1792 ieee->dev->name);
1793 if (ieee->handle_reassoc_request != NULL)
1794 ieee->handle_reassoc_request(ieee->dev,
1795 (struct ieee80211_reassoc_request *)
1796 header);
1797 break;
1798
1799 case IEEE80211_STYPE_ASSOC_REQ:
1800 IEEE80211_DEBUG_MGMT("received assoc (%d)\n",
1801 WLAN_FC_GET_STYPE(le16_to_cpu
1802 (header->frame_ctl)));
1803
1804 IEEE80211_DEBUG_MGMT("%s: IEEE80211_ASSOC_REQ received\n",
1805 ieee->dev->name);
1806 if (ieee->handle_assoc_request != NULL)
1807 ieee->handle_assoc_request(ieee->dev);
1808 break;
1809
1810 case IEEE80211_STYPE_DEAUTH:
1811 IEEE80211_DEBUG_MGMT("DEAUTH\n");
1812 if (ieee->handle_deauth != NULL)
1813 ieee->handle_deauth(ieee->dev,
1814 (struct ieee80211_deauth *)
1815 header);
1816 break;
1817 default:
1818 IEEE80211_DEBUG_MGMT("received UNKNOWN (%d)\n",
1819 WLAN_FC_GET_STYPE(le16_to_cpu
1820 (header->frame_ctl)));
1821 IEEE80211_DEBUG_MGMT("%s: Unknown management packet: %d\n",
1822 ieee->dev->name,
1823 WLAN_FC_GET_STYPE(le16_to_cpu
1824 (header->frame_ctl)));
1825 break;
1826 }
1827}
1828
1829EXPORT_SYMBOL_GPL(ieee80211_rx_any);
1830EXPORT_SYMBOL(ieee80211_rx_mgt);
1831EXPORT_SYMBOL(ieee80211_rx);
diff --git a/net/ieee80211/ieee80211_tx.c b/net/ieee80211/ieee80211_tx.c
deleted file mode 100644
index d996547f7a62..000000000000
--- a/net/ieee80211/ieee80211_tx.c
+++ /dev/null
@@ -1,545 +0,0 @@
1/******************************************************************************
2
3 Copyright(c) 2003 - 2005 Intel Corporation. All rights reserved.
4
5 This program is free software; you can redistribute it and/or modify it
6 under the terms of version 2 of the GNU General Public License as
7 published by the Free Software Foundation.
8
9 This program is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 more details.
13
14 You should have received a copy of the GNU General Public License along with
15 this program; if not, write to the Free Software Foundation, Inc., 59
16 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
18 The full GNU General Public License is included in this distribution in the
19 file called LICENSE.
20
21 Contact Information:
22 James P. Ketrenos <ipw2100-admin@linux.intel.com>
23 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
24
25******************************************************************************/
26#include <linux/compiler.h>
27#include <linux/errno.h>
28#include <linux/if_arp.h>
29#include <linux/in6.h>
30#include <linux/in.h>
31#include <linux/ip.h>
32#include <linux/kernel.h>
33#include <linux/module.h>
34#include <linux/netdevice.h>
35#include <linux/proc_fs.h>
36#include <linux/skbuff.h>
37#include <linux/slab.h>
38#include <linux/tcp.h>
39#include <linux/types.h>
40#include <linux/wireless.h>
41#include <linux/etherdevice.h>
42#include <asm/uaccess.h>
43
44#include <net/ieee80211.h>
45
46/*
47
48802.11 Data Frame
49
50 ,-------------------------------------------------------------------.
51Bytes | 2 | 2 | 6 | 6 | 6 | 2 | 0..2312 | 4 |
52 |------|------|---------|---------|---------|------|---------|------|
53Desc. | ctrl | dura | DA/RA | TA | SA | Sequ | Frame | fcs |
54 | | tion | (BSSID) | | | ence | data | |
55 `--------------------------------------------------| |------'
56Total: 28 non-data bytes `----.----'
57 |
58 .- 'Frame data' expands, if WEP enabled, to <----------'
59 |
60 V
61 ,-----------------------.
62Bytes | 4 | 0-2296 | 4 |
63 |-----|-----------|-----|
64Desc. | IV | Encrypted | ICV |
65 | | Packet | |
66 `-----| |-----'
67 `-----.-----'
68 |
69 .- 'Encrypted Packet' expands to
70 |
71 V
72 ,---------------------------------------------------.
73Bytes | 1 | 1 | 1 | 3 | 2 | 0-2304 |
74 |------|------|---------|----------|------|---------|
75Desc. | SNAP | SNAP | Control |Eth Tunnel| Type | IP |
76 | DSAP | SSAP | | | | Packet |
77 | 0xAA | 0xAA |0x03 (UI)|0x00-00-F8| | |
78 `----------------------------------------------------
79Total: 8 non-data bytes
80
81802.3 Ethernet Data Frame
82
83 ,-----------------------------------------.
84Bytes | 6 | 6 | 2 | Variable | 4 |
85 |-------|-------|------|-----------|------|
86Desc. | Dest. | Source| Type | IP Packet | fcs |
87 | MAC | MAC | | | |
88 `-----------------------------------------'
89Total: 18 non-data bytes
90
91In the event that fragmentation is required, the incoming payload is split into
92N parts of size ieee->fts. The first fragment contains the SNAP header and the
93remaining packets are just data.
94
95If encryption is enabled, each fragment payload size is reduced by enough space
96to add the prefix and postfix (IV and ICV totalling 8 bytes in the case of WEP)
97So if you have 1500 bytes of payload with ieee->fts set to 500 without
98encryption it will take 3 frames. With WEP it will take 4 frames as the
99payload of each frame is reduced to 492 bytes.
100
101* SKB visualization
102*
103* ,- skb->data
104* |
105* | ETHERNET HEADER ,-<-- PAYLOAD
106* | | 14 bytes from skb->data
107* | 2 bytes for Type --> ,T. | (sizeof ethhdr)
108* | | | |
109* |,-Dest.--. ,--Src.---. | | |
110* | 6 bytes| | 6 bytes | | | |
111* v | | | | | |
112* 0 | v 1 | v | v 2
113* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
114* ^ | ^ | ^ |
115* | | | | | |
116* | | | | `T' <---- 2 bytes for Type
117* | | | |
118* | | '---SNAP--' <-------- 6 bytes for SNAP
119* | |
120* `-IV--' <-------------------- 4 bytes for IV (WEP)
121*
122* SNAP HEADER
123*
124*/
125
126static u8 P802_1H_OUI[P80211_OUI_LEN] = { 0x00, 0x00, 0xf8 };
127static u8 RFC1042_OUI[P80211_OUI_LEN] = { 0x00, 0x00, 0x00 };
128
129static int ieee80211_copy_snap(u8 * data, __be16 h_proto)
130{
131 struct ieee80211_snap_hdr *snap;
132 u8 *oui;
133
134 snap = (struct ieee80211_snap_hdr *)data;
135 snap->dsap = 0xaa;
136 snap->ssap = 0xaa;
137 snap->ctrl = 0x03;
138
139 if (h_proto == htons(ETH_P_AARP) || h_proto == htons(ETH_P_IPX))
140 oui = P802_1H_OUI;
141 else
142 oui = RFC1042_OUI;
143 snap->oui[0] = oui[0];
144 snap->oui[1] = oui[1];
145 snap->oui[2] = oui[2];
146
147 memcpy(data + SNAP_SIZE, &h_proto, sizeof(u16));
148
149 return SNAP_SIZE + sizeof(u16);
150}
151
152static int ieee80211_encrypt_fragment(struct ieee80211_device *ieee,
153 struct sk_buff *frag, int hdr_len)
154{
155 struct ieee80211_crypt_data *crypt = ieee->crypt[ieee->tx_keyidx];
156 int res;
157
158 if (crypt == NULL)
159 return -1;
160
161 /* To encrypt, frame format is:
162 * IV (4 bytes), clear payload (including SNAP), ICV (4 bytes) */
163 atomic_inc(&crypt->refcnt);
164 res = 0;
165 if (crypt->ops && crypt->ops->encrypt_mpdu)
166 res = crypt->ops->encrypt_mpdu(frag, hdr_len, crypt->priv);
167
168 atomic_dec(&crypt->refcnt);
169 if (res < 0) {
170 printk(KERN_INFO "%s: Encryption failed: len=%d.\n",
171 ieee->dev->name, frag->len);
172 ieee->ieee_stats.tx_discards++;
173 return -1;
174 }
175
176 return 0;
177}
178
179void ieee80211_txb_free(struct ieee80211_txb *txb)
180{
181 int i;
182 if (unlikely(!txb))
183 return;
184 for (i = 0; i < txb->nr_frags; i++)
185 if (txb->fragments[i])
186 dev_kfree_skb_any(txb->fragments[i]);
187 kfree(txb);
188}
189
190static struct ieee80211_txb *ieee80211_alloc_txb(int nr_frags, int txb_size,
191 int headroom, gfp_t gfp_mask)
192{
193 struct ieee80211_txb *txb;
194 int i;
195 txb = kmalloc(sizeof(struct ieee80211_txb) + (sizeof(u8 *) * nr_frags),
196 gfp_mask);
197 if (!txb)
198 return NULL;
199
200 memset(txb, 0, sizeof(struct ieee80211_txb));
201 txb->nr_frags = nr_frags;
202 txb->frag_size = txb_size;
203
204 for (i = 0; i < nr_frags; i++) {
205 txb->fragments[i] = __dev_alloc_skb(txb_size + headroom,
206 gfp_mask);
207 if (unlikely(!txb->fragments[i])) {
208 i--;
209 break;
210 }
211 skb_reserve(txb->fragments[i], headroom);
212 }
213 if (unlikely(i != nr_frags)) {
214 while (i >= 0)
215 dev_kfree_skb_any(txb->fragments[i--]);
216 kfree(txb);
217 return NULL;
218 }
219 return txb;
220}
221
222static int ieee80211_classify(struct sk_buff *skb)
223{
224 struct ethhdr *eth;
225 struct iphdr *ip;
226
227 eth = (struct ethhdr *)skb->data;
228 if (eth->h_proto != htons(ETH_P_IP))
229 return 0;
230
231 ip = ip_hdr(skb);
232 switch (ip->tos & 0xfc) {
233 case 0x20:
234 return 2;
235 case 0x40:
236 return 1;
237 case 0x60:
238 return 3;
239 case 0x80:
240 return 4;
241 case 0xa0:
242 return 5;
243 case 0xc0:
244 return 6;
245 case 0xe0:
246 return 7;
247 default:
248 return 0;
249 }
250}
251
252/* Incoming skb is converted to a txb which consists of
253 * a block of 802.11 fragment packets (stored as skbs) */
254int ieee80211_xmit(struct sk_buff *skb, struct net_device *dev)
255{
256 struct ieee80211_device *ieee = netdev_priv(dev);
257 struct ieee80211_txb *txb = NULL;
258 struct ieee80211_hdr_3addrqos *frag_hdr;
259 int i, bytes_per_frag, nr_frags, bytes_last_frag, frag_size,
260 rts_required;
261 unsigned long flags;
262 struct net_device_stats *stats = &ieee->stats;
263 int encrypt, host_encrypt, host_encrypt_msdu, host_build_iv;
264 __be16 ether_type;
265 int bytes, fc, hdr_len;
266 struct sk_buff *skb_frag;
267 struct ieee80211_hdr_3addrqos header = {/* Ensure zero initialized */
268 .duration_id = 0,
269 .seq_ctl = 0,
270 .qos_ctl = 0
271 };
272 u8 dest[ETH_ALEN], src[ETH_ALEN];
273 struct ieee80211_crypt_data *crypt;
274 int priority = skb->priority;
275 int snapped = 0;
276
277 if (ieee->is_queue_full && (*ieee->is_queue_full) (dev, priority))
278 return NETDEV_TX_BUSY;
279
280 spin_lock_irqsave(&ieee->lock, flags);
281
282 /* If there is no driver handler to take the TXB, dont' bother
283 * creating it... */
284 if (!ieee->hard_start_xmit) {
285 printk(KERN_WARNING "%s: No xmit handler.\n", ieee->dev->name);
286 goto success;
287 }
288
289 if (unlikely(skb->len < SNAP_SIZE + sizeof(u16))) {
290 printk(KERN_WARNING "%s: skb too small (%d).\n",
291 ieee->dev->name, skb->len);
292 goto success;
293 }
294
295 ether_type = ((struct ethhdr *)skb->data)->h_proto;
296
297 crypt = ieee->crypt[ieee->tx_keyidx];
298
299 encrypt = !(ether_type == htons(ETH_P_PAE) && ieee->ieee802_1x) &&
300 ieee->sec.encrypt;
301
302 host_encrypt = ieee->host_encrypt && encrypt && crypt;
303 host_encrypt_msdu = ieee->host_encrypt_msdu && encrypt && crypt;
304 host_build_iv = ieee->host_build_iv && encrypt && crypt;
305
306 if (!encrypt && ieee->ieee802_1x &&
307 ieee->drop_unencrypted && ether_type != htons(ETH_P_PAE)) {
308 stats->tx_dropped++;
309 goto success;
310 }
311
312 /* Save source and destination addresses */
313 skb_copy_from_linear_data(skb, dest, ETH_ALEN);
314 skb_copy_from_linear_data_offset(skb, ETH_ALEN, src, ETH_ALEN);
315
316 if (host_encrypt || host_build_iv)
317 fc = IEEE80211_FTYPE_DATA | IEEE80211_STYPE_DATA |
318 IEEE80211_FCTL_PROTECTED;
319 else
320 fc = IEEE80211_FTYPE_DATA | IEEE80211_STYPE_DATA;
321
322 if (ieee->iw_mode == IW_MODE_INFRA) {
323 fc |= IEEE80211_FCTL_TODS;
324 /* To DS: Addr1 = BSSID, Addr2 = SA, Addr3 = DA */
325 memcpy(header.addr1, ieee->bssid, ETH_ALEN);
326 memcpy(header.addr2, src, ETH_ALEN);
327 memcpy(header.addr3, dest, ETH_ALEN);
328 } else if (ieee->iw_mode == IW_MODE_ADHOC) {
329 /* not From/To DS: Addr1 = DA, Addr2 = SA, Addr3 = BSSID */
330 memcpy(header.addr1, dest, ETH_ALEN);
331 memcpy(header.addr2, src, ETH_ALEN);
332 memcpy(header.addr3, ieee->bssid, ETH_ALEN);
333 }
334 hdr_len = IEEE80211_3ADDR_LEN;
335
336 if (ieee->is_qos_active && ieee->is_qos_active(dev, skb)) {
337 fc |= IEEE80211_STYPE_QOS_DATA;
338 hdr_len += 2;
339
340 skb->priority = ieee80211_classify(skb);
341 header.qos_ctl |= cpu_to_le16(skb->priority & IEEE80211_QCTL_TID);
342 }
343 header.frame_ctl = cpu_to_le16(fc);
344
345 /* Advance the SKB to the start of the payload */
346 skb_pull(skb, sizeof(struct ethhdr));
347
348 /* Determine total amount of storage required for TXB packets */
349 bytes = skb->len + SNAP_SIZE + sizeof(u16);
350
351 /* Encrypt msdu first on the whole data packet. */
352 if ((host_encrypt || host_encrypt_msdu) &&
353 crypt && crypt->ops && crypt->ops->encrypt_msdu) {
354 int res = 0;
355 int len = bytes + hdr_len + crypt->ops->extra_msdu_prefix_len +
356 crypt->ops->extra_msdu_postfix_len;
357 struct sk_buff *skb_new = dev_alloc_skb(len);
358
359 if (unlikely(!skb_new))
360 goto failed;
361
362 skb_reserve(skb_new, crypt->ops->extra_msdu_prefix_len);
363 memcpy(skb_put(skb_new, hdr_len), &header, hdr_len);
364 snapped = 1;
365 ieee80211_copy_snap(skb_put(skb_new, SNAP_SIZE + sizeof(u16)),
366 ether_type);
367 skb_copy_from_linear_data(skb, skb_put(skb_new, skb->len), skb->len);
368 res = crypt->ops->encrypt_msdu(skb_new, hdr_len, crypt->priv);
369 if (res < 0) {
370 IEEE80211_ERROR("msdu encryption failed\n");
371 dev_kfree_skb_any(skb_new);
372 goto failed;
373 }
374 dev_kfree_skb_any(skb);
375 skb = skb_new;
376 bytes += crypt->ops->extra_msdu_prefix_len +
377 crypt->ops->extra_msdu_postfix_len;
378 skb_pull(skb, hdr_len);
379 }
380
381 if (host_encrypt || ieee->host_open_frag) {
382 /* Determine fragmentation size based on destination (multicast
383 * and broadcast are not fragmented) */
384 if (is_multicast_ether_addr(dest) ||
385 is_broadcast_ether_addr(dest))
386 frag_size = MAX_FRAG_THRESHOLD;
387 else
388 frag_size = ieee->fts;
389
390 /* Determine amount of payload per fragment. Regardless of if
391 * this stack is providing the full 802.11 header, one will
392 * eventually be affixed to this fragment -- so we must account
393 * for it when determining the amount of payload space. */
394 bytes_per_frag = frag_size - hdr_len;
395 if (ieee->config &
396 (CFG_IEEE80211_COMPUTE_FCS | CFG_IEEE80211_RESERVE_FCS))
397 bytes_per_frag -= IEEE80211_FCS_LEN;
398
399 /* Each fragment may need to have room for encryptiong
400 * pre/postfix */
401 if (host_encrypt)
402 bytes_per_frag -= crypt->ops->extra_mpdu_prefix_len +
403 crypt->ops->extra_mpdu_postfix_len;
404
405 /* Number of fragments is the total
406 * bytes_per_frag / payload_per_fragment */
407 nr_frags = bytes / bytes_per_frag;
408 bytes_last_frag = bytes % bytes_per_frag;
409 if (bytes_last_frag)
410 nr_frags++;
411 else
412 bytes_last_frag = bytes_per_frag;
413 } else {
414 nr_frags = 1;
415 bytes_per_frag = bytes_last_frag = bytes;
416 frag_size = bytes + hdr_len;
417 }
418
419 rts_required = (frag_size > ieee->rts
420 && ieee->config & CFG_IEEE80211_RTS);
421 if (rts_required)
422 nr_frags++;
423
424 /* When we allocate the TXB we allocate enough space for the reserve
425 * and full fragment bytes (bytes_per_frag doesn't include prefix,
426 * postfix, header, FCS, etc.) */
427 txb = ieee80211_alloc_txb(nr_frags, frag_size,
428 ieee->tx_headroom, GFP_ATOMIC);
429 if (unlikely(!txb)) {
430 printk(KERN_WARNING "%s: Could not allocate TXB\n",
431 ieee->dev->name);
432 goto failed;
433 }
434 txb->encrypted = encrypt;
435 if (host_encrypt)
436 txb->payload_size = frag_size * (nr_frags - 1) +
437 bytes_last_frag;
438 else
439 txb->payload_size = bytes;
440
441 if (rts_required) {
442 skb_frag = txb->fragments[0];
443 frag_hdr =
444 (struct ieee80211_hdr_3addrqos *)skb_put(skb_frag, hdr_len);
445
446 /*
447 * Set header frame_ctl to the RTS.
448 */
449 header.frame_ctl =
450 cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_RTS);
451 memcpy(frag_hdr, &header, hdr_len);
452
453 /*
454 * Restore header frame_ctl to the original data setting.
455 */
456 header.frame_ctl = cpu_to_le16(fc);
457
458 if (ieee->config &
459 (CFG_IEEE80211_COMPUTE_FCS | CFG_IEEE80211_RESERVE_FCS))
460 skb_put(skb_frag, 4);
461
462 txb->rts_included = 1;
463 i = 1;
464 } else
465 i = 0;
466
467 for (; i < nr_frags; i++) {
468 skb_frag = txb->fragments[i];
469
470 if (host_encrypt || host_build_iv)
471 skb_reserve(skb_frag,
472 crypt->ops->extra_mpdu_prefix_len);
473
474 frag_hdr =
475 (struct ieee80211_hdr_3addrqos *)skb_put(skb_frag, hdr_len);
476 memcpy(frag_hdr, &header, hdr_len);
477
478 /* If this is not the last fragment, then add the MOREFRAGS
479 * bit to the frame control */
480 if (i != nr_frags - 1) {
481 frag_hdr->frame_ctl =
482 cpu_to_le16(fc | IEEE80211_FCTL_MOREFRAGS);
483 bytes = bytes_per_frag;
484 } else {
485 /* The last fragment takes the remaining length */
486 bytes = bytes_last_frag;
487 }
488
489 if (i == 0 && !snapped) {
490 ieee80211_copy_snap(skb_put
491 (skb_frag, SNAP_SIZE + sizeof(u16)),
492 ether_type);
493 bytes -= SNAP_SIZE + sizeof(u16);
494 }
495
496 skb_copy_from_linear_data(skb, skb_put(skb_frag, bytes), bytes);
497
498 /* Advance the SKB... */
499 skb_pull(skb, bytes);
500
501 /* Encryption routine will move the header forward in order
502 * to insert the IV between the header and the payload */
503 if (host_encrypt)
504 ieee80211_encrypt_fragment(ieee, skb_frag, hdr_len);
505 else if (host_build_iv) {
506 atomic_inc(&crypt->refcnt);
507 if (crypt->ops->build_iv)
508 crypt->ops->build_iv(skb_frag, hdr_len,
509 ieee->sec.keys[ieee->sec.active_key],
510 ieee->sec.key_sizes[ieee->sec.active_key],
511 crypt->priv);
512 atomic_dec(&crypt->refcnt);
513 }
514
515 if (ieee->config &
516 (CFG_IEEE80211_COMPUTE_FCS | CFG_IEEE80211_RESERVE_FCS))
517 skb_put(skb_frag, 4);
518 }
519
520 success:
521 spin_unlock_irqrestore(&ieee->lock, flags);
522
523 dev_kfree_skb_any(skb);
524
525 if (txb) {
526 int ret = (*ieee->hard_start_xmit) (txb, dev, priority);
527 if (ret == 0) {
528 stats->tx_packets++;
529 stats->tx_bytes += txb->payload_size;
530 return 0;
531 }
532
533 ieee80211_txb_free(txb);
534 }
535
536 return 0;
537
538 failed:
539 spin_unlock_irqrestore(&ieee->lock, flags);
540 netif_stop_queue(dev);
541 stats->tx_errors++;
542 return 1;
543}
544
545EXPORT_SYMBOL(ieee80211_txb_free);
diff --git a/net/ieee80211/ieee80211_wx.c b/net/ieee80211/ieee80211_wx.c
deleted file mode 100644
index 973832dd7faf..000000000000
--- a/net/ieee80211/ieee80211_wx.c
+++ /dev/null
@@ -1,760 +0,0 @@
1/******************************************************************************
2
3 Copyright(c) 2004-2005 Intel Corporation. All rights reserved.
4
5 Portions of this file are based on the WEP enablement code provided by the
6 Host AP project hostap-drivers v0.1.3
7 Copyright (c) 2001-2002, SSH Communications Security Corp and Jouni Malinen
8 <j@w1.fi>
9 Copyright (c) 2002-2003, Jouni Malinen <j@w1.fi>
10
11 This program is free software; you can redistribute it and/or modify it
12 under the terms of version 2 of the GNU General Public License as
13 published by the Free Software Foundation.
14
15 This program is distributed in the hope that it will be useful, but WITHOUT
16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
18 more details.
19
20 You should have received a copy of the GNU General Public License along with
21 this program; if not, write to the Free Software Foundation, Inc., 59
22 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23
24 The full GNU General Public License is included in this distribution in the
25 file called LICENSE.
26
27 Contact Information:
28 James P. Ketrenos <ipw2100-admin@linux.intel.com>
29 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
30
31******************************************************************************/
32
33#include <linux/kmod.h>
34#include <linux/module.h>
35#include <linux/jiffies.h>
36
37#include <net/ieee80211.h>
38#include <linux/wireless.h>
39
40static const char *ieee80211_modes[] = {
41 "?", "a", "b", "ab", "g", "ag", "bg", "abg"
42};
43
44#define MAX_CUSTOM_LEN 64
45static char *ieee80211_translate_scan(struct ieee80211_device *ieee,
46 char *start, char *stop,
47 struct ieee80211_network *network,
48 struct iw_request_info *info)
49{
50 char custom[MAX_CUSTOM_LEN];
51 char *p;
52 struct iw_event iwe;
53 int i, j;
54 char *current_val; /* For rates */
55 u8 rate;
56
57 /* First entry *MUST* be the AP MAC address */
58 iwe.cmd = SIOCGIWAP;
59 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
60 memcpy(iwe.u.ap_addr.sa_data, network->bssid, ETH_ALEN);
61 start = iwe_stream_add_event(info, start, stop, &iwe, IW_EV_ADDR_LEN);
62
63 /* Remaining entries will be displayed in the order we provide them */
64
65 /* Add the ESSID */
66 iwe.cmd = SIOCGIWESSID;
67 iwe.u.data.flags = 1;
68 if (network->flags & NETWORK_EMPTY_ESSID) {
69 iwe.u.data.length = sizeof("<hidden>");
70 start = iwe_stream_add_point(info, start, stop,
71 &iwe, "<hidden>");
72 } else {
73 iwe.u.data.length = min(network->ssid_len, (u8) 32);
74 start = iwe_stream_add_point(info, start, stop,
75 &iwe, network->ssid);
76 }
77
78 /* Add the protocol name */
79 iwe.cmd = SIOCGIWNAME;
80 snprintf(iwe.u.name, IFNAMSIZ, "IEEE 802.11%s",
81 ieee80211_modes[network->mode]);
82 start = iwe_stream_add_event(info, start, stop, &iwe, IW_EV_CHAR_LEN);
83
84 /* Add mode */
85 iwe.cmd = SIOCGIWMODE;
86 if (network->capability & (WLAN_CAPABILITY_ESS | WLAN_CAPABILITY_IBSS)) {
87 if (network->capability & WLAN_CAPABILITY_ESS)
88 iwe.u.mode = IW_MODE_MASTER;
89 else
90 iwe.u.mode = IW_MODE_ADHOC;
91
92 start = iwe_stream_add_event(info, start, stop,
93 &iwe, IW_EV_UINT_LEN);
94 }
95
96 /* Add channel and frequency */
97 /* Note : userspace automatically computes channel using iwrange */
98 iwe.cmd = SIOCGIWFREQ;
99 iwe.u.freq.m = ieee80211_channel_to_freq(ieee, network->channel);
100 iwe.u.freq.e = 6;
101 iwe.u.freq.i = 0;
102 start = iwe_stream_add_event(info, start, stop, &iwe, IW_EV_FREQ_LEN);
103
104 /* Add encryption capability */
105 iwe.cmd = SIOCGIWENCODE;
106 if (network->capability & WLAN_CAPABILITY_PRIVACY)
107 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
108 else
109 iwe.u.data.flags = IW_ENCODE_DISABLED;
110 iwe.u.data.length = 0;
111 start = iwe_stream_add_point(info, start, stop,
112 &iwe, network->ssid);
113
114 /* Add basic and extended rates */
115 /* Rate : stuffing multiple values in a single event require a bit
116 * more of magic - Jean II */
117 current_val = start + iwe_stream_lcp_len(info);
118 iwe.cmd = SIOCGIWRATE;
119 /* Those two flags are ignored... */
120 iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
121
122 for (i = 0, j = 0; i < network->rates_len;) {
123 if (j < network->rates_ex_len &&
124 ((network->rates_ex[j] & 0x7F) <
125 (network->rates[i] & 0x7F)))
126 rate = network->rates_ex[j++] & 0x7F;
127 else
128 rate = network->rates[i++] & 0x7F;
129 /* Bit rate given in 500 kb/s units (+ 0x80) */
130 iwe.u.bitrate.value = ((rate & 0x7f) * 500000);
131 /* Add new value to event */
132 current_val = iwe_stream_add_value(info, start, current_val,
133 stop, &iwe, IW_EV_PARAM_LEN);
134 }
135 for (; j < network->rates_ex_len; j++) {
136 rate = network->rates_ex[j] & 0x7F;
137 /* Bit rate given in 500 kb/s units (+ 0x80) */
138 iwe.u.bitrate.value = ((rate & 0x7f) * 500000);
139 /* Add new value to event */
140 current_val = iwe_stream_add_value(info, start, current_val,
141 stop, &iwe, IW_EV_PARAM_LEN);
142 }
143 /* Check if we added any rate */
144 if ((current_val - start) > iwe_stream_lcp_len(info))
145 start = current_val;
146
147 /* Add quality statistics */
148 iwe.cmd = IWEVQUAL;
149 iwe.u.qual.updated = IW_QUAL_QUAL_UPDATED | IW_QUAL_LEVEL_UPDATED |
150 IW_QUAL_NOISE_UPDATED;
151
152 if (!(network->stats.mask & IEEE80211_STATMASK_RSSI)) {
153 iwe.u.qual.updated |= IW_QUAL_QUAL_INVALID |
154 IW_QUAL_LEVEL_INVALID;
155 iwe.u.qual.qual = 0;
156 } else {
157 if (ieee->perfect_rssi == ieee->worst_rssi)
158 iwe.u.qual.qual = 100;
159 else
160 iwe.u.qual.qual =
161 (100 *
162 (ieee->perfect_rssi - ieee->worst_rssi) *
163 (ieee->perfect_rssi - ieee->worst_rssi) -
164 (ieee->perfect_rssi - network->stats.rssi) *
165 (15 * (ieee->perfect_rssi - ieee->worst_rssi) +
166 62 * (ieee->perfect_rssi -
167 network->stats.rssi))) /
168 ((ieee->perfect_rssi -
169 ieee->worst_rssi) * (ieee->perfect_rssi -
170 ieee->worst_rssi));
171 if (iwe.u.qual.qual > 100)
172 iwe.u.qual.qual = 100;
173 else if (iwe.u.qual.qual < 1)
174 iwe.u.qual.qual = 0;
175 }
176
177 if (!(network->stats.mask & IEEE80211_STATMASK_NOISE)) {
178 iwe.u.qual.updated |= IW_QUAL_NOISE_INVALID;
179 iwe.u.qual.noise = 0;
180 } else {
181 iwe.u.qual.noise = network->stats.noise;
182 }
183
184 if (!(network->stats.mask & IEEE80211_STATMASK_SIGNAL)) {
185 iwe.u.qual.updated |= IW_QUAL_LEVEL_INVALID;
186 iwe.u.qual.level = 0;
187 } else {
188 iwe.u.qual.level = network->stats.signal;
189 }
190
191 start = iwe_stream_add_event(info, start, stop, &iwe, IW_EV_QUAL_LEN);
192
193 iwe.cmd = IWEVCUSTOM;
194 p = custom;
195
196 iwe.u.data.length = p - custom;
197 if (iwe.u.data.length)
198 start = iwe_stream_add_point(info, start, stop, &iwe, custom);
199
200 memset(&iwe, 0, sizeof(iwe));
201 if (network->wpa_ie_len) {
202 char buf[MAX_WPA_IE_LEN];
203 memcpy(buf, network->wpa_ie, network->wpa_ie_len);
204 iwe.cmd = IWEVGENIE;
205 iwe.u.data.length = network->wpa_ie_len;
206 start = iwe_stream_add_point(info, start, stop, &iwe, buf);
207 }
208
209 memset(&iwe, 0, sizeof(iwe));
210 if (network->rsn_ie_len) {
211 char buf[MAX_WPA_IE_LEN];
212 memcpy(buf, network->rsn_ie, network->rsn_ie_len);
213 iwe.cmd = IWEVGENIE;
214 iwe.u.data.length = network->rsn_ie_len;
215 start = iwe_stream_add_point(info, start, stop, &iwe, buf);
216 }
217
218 /* Add EXTRA: Age to display seconds since last beacon/probe response
219 * for given network. */
220 iwe.cmd = IWEVCUSTOM;
221 p = custom;
222 p += snprintf(p, MAX_CUSTOM_LEN - (p - custom),
223 " Last beacon: %dms ago",
224 jiffies_to_msecs(jiffies - network->last_scanned));
225 iwe.u.data.length = p - custom;
226 if (iwe.u.data.length)
227 start = iwe_stream_add_point(info, start, stop, &iwe, custom);
228
229 /* Add spectrum management information */
230 iwe.cmd = -1;
231 p = custom;
232 p += snprintf(p, MAX_CUSTOM_LEN - (p - custom), " Channel flags: ");
233
234 if (ieee80211_get_channel_flags(ieee, network->channel) &
235 IEEE80211_CH_INVALID) {
236 iwe.cmd = IWEVCUSTOM;
237 p += snprintf(p, MAX_CUSTOM_LEN - (p - custom), "INVALID ");
238 }
239
240 if (ieee80211_get_channel_flags(ieee, network->channel) &
241 IEEE80211_CH_RADAR_DETECT) {
242 iwe.cmd = IWEVCUSTOM;
243 p += snprintf(p, MAX_CUSTOM_LEN - (p - custom), "DFS ");
244 }
245
246 if (iwe.cmd == IWEVCUSTOM) {
247 iwe.u.data.length = p - custom;
248 start = iwe_stream_add_point(info, start, stop, &iwe, custom);
249 }
250
251 return start;
252}
253
254#define SCAN_ITEM_SIZE 128
255
256int ieee80211_wx_get_scan(struct ieee80211_device *ieee,
257 struct iw_request_info *info,
258 union iwreq_data *wrqu, char *extra)
259{
260 struct ieee80211_network *network;
261 unsigned long flags;
262 int err = 0;
263
264 char *ev = extra;
265 char *stop = ev + wrqu->data.length;
266 int i = 0;
267 DECLARE_MAC_BUF(mac);
268
269 IEEE80211_DEBUG_WX("Getting scan\n");
270
271 spin_lock_irqsave(&ieee->lock, flags);
272
273 list_for_each_entry(network, &ieee->network_list, list) {
274 i++;
275 if (stop - ev < SCAN_ITEM_SIZE) {
276 err = -E2BIG;
277 break;
278 }
279
280 if (ieee->scan_age == 0 ||
281 time_after(network->last_scanned + ieee->scan_age, jiffies))
282 ev = ieee80211_translate_scan(ieee, ev, stop, network,
283 info);
284 else
285 IEEE80211_DEBUG_SCAN("Not showing network '%s ("
286 "%s)' due to age (%dms).\n",
287 escape_essid(network->ssid,
288 network->ssid_len),
289 print_mac(mac, network->bssid),
290 jiffies_to_msecs(jiffies -
291 network->
292 last_scanned));
293 }
294
295 spin_unlock_irqrestore(&ieee->lock, flags);
296
297 wrqu->data.length = ev - extra;
298 wrqu->data.flags = 0;
299
300 IEEE80211_DEBUG_WX("exit: %d networks returned.\n", i);
301
302 return err;
303}
304
305int ieee80211_wx_set_encode(struct ieee80211_device *ieee,
306 struct iw_request_info *info,
307 union iwreq_data *wrqu, char *keybuf)
308{
309 struct iw_point *erq = &(wrqu->encoding);
310 struct net_device *dev = ieee->dev;
311 struct ieee80211_security sec = {
312 .flags = 0
313 };
314 int i, key, key_provided, len;
315 struct ieee80211_crypt_data **crypt;
316 int host_crypto = ieee->host_encrypt || ieee->host_decrypt || ieee->host_build_iv;
317
318 IEEE80211_DEBUG_WX("SET_ENCODE\n");
319
320 key = erq->flags & IW_ENCODE_INDEX;
321 if (key) {
322 if (key > WEP_KEYS)
323 return -EINVAL;
324 key--;
325 key_provided = 1;
326 } else {
327 key_provided = 0;
328 key = ieee->tx_keyidx;
329 }
330
331 IEEE80211_DEBUG_WX("Key: %d [%s]\n", key, key_provided ?
332 "provided" : "default");
333
334 crypt = &ieee->crypt[key];
335
336 if (erq->flags & IW_ENCODE_DISABLED) {
337 if (key_provided && *crypt) {
338 IEEE80211_DEBUG_WX("Disabling encryption on key %d.\n",
339 key);
340 ieee80211_crypt_delayed_deinit(ieee, crypt);
341 } else
342 IEEE80211_DEBUG_WX("Disabling encryption.\n");
343
344 /* Check all the keys to see if any are still configured,
345 * and if no key index was provided, de-init them all */
346 for (i = 0; i < WEP_KEYS; i++) {
347 if (ieee->crypt[i] != NULL) {
348 if (key_provided)
349 break;
350 ieee80211_crypt_delayed_deinit(ieee,
351 &ieee->crypt[i]);
352 }
353 }
354
355 if (i == WEP_KEYS) {
356 sec.enabled = 0;
357 sec.encrypt = 0;
358 sec.level = SEC_LEVEL_0;
359 sec.flags |= SEC_ENABLED | SEC_LEVEL | SEC_ENCRYPT;
360 }
361
362 goto done;
363 }
364
365 sec.enabled = 1;
366 sec.encrypt = 1;
367 sec.flags |= SEC_ENABLED | SEC_ENCRYPT;
368
369 if (*crypt != NULL && (*crypt)->ops != NULL &&
370 strcmp((*crypt)->ops->name, "WEP") != 0) {
371 /* changing to use WEP; deinit previously used algorithm
372 * on this key */
373 ieee80211_crypt_delayed_deinit(ieee, crypt);
374 }
375
376 if (*crypt == NULL && host_crypto) {
377 struct ieee80211_crypt_data *new_crypt;
378
379 /* take WEP into use */
380 new_crypt = kzalloc(sizeof(struct ieee80211_crypt_data),
381 GFP_KERNEL);
382 if (new_crypt == NULL)
383 return -ENOMEM;
384 new_crypt->ops = ieee80211_get_crypto_ops("WEP");
385 if (!new_crypt->ops) {
386 request_module("ieee80211_crypt_wep");
387 new_crypt->ops = ieee80211_get_crypto_ops("WEP");
388 }
389
390 if (new_crypt->ops && try_module_get(new_crypt->ops->owner))
391 new_crypt->priv = new_crypt->ops->init(key);
392
393 if (!new_crypt->ops || !new_crypt->priv) {
394 kfree(new_crypt);
395 new_crypt = NULL;
396
397 printk(KERN_WARNING "%s: could not initialize WEP: "
398 "load module ieee80211_crypt_wep\n", dev->name);
399 return -EOPNOTSUPP;
400 }
401 *crypt = new_crypt;
402 }
403
404 /* If a new key was provided, set it up */
405 if (erq->length > 0) {
406 len = erq->length <= 5 ? 5 : 13;
407 memcpy(sec.keys[key], keybuf, erq->length);
408 if (len > erq->length)
409 memset(sec.keys[key] + erq->length, 0,
410 len - erq->length);
411 IEEE80211_DEBUG_WX("Setting key %d to '%s' (%d:%d bytes)\n",
412 key, escape_essid(sec.keys[key], len),
413 erq->length, len);
414 sec.key_sizes[key] = len;
415 if (*crypt)
416 (*crypt)->ops->set_key(sec.keys[key], len, NULL,
417 (*crypt)->priv);
418 sec.flags |= (1 << key);
419 /* This ensures a key will be activated if no key is
420 * explicitly set */
421 if (key == sec.active_key)
422 sec.flags |= SEC_ACTIVE_KEY;
423
424 } else {
425 if (host_crypto) {
426 len = (*crypt)->ops->get_key(sec.keys[key], WEP_KEY_LEN,
427 NULL, (*crypt)->priv);
428 if (len == 0) {
429 /* Set a default key of all 0 */
430 IEEE80211_DEBUG_WX("Setting key %d to all "
431 "zero.\n", key);
432 memset(sec.keys[key], 0, 13);
433 (*crypt)->ops->set_key(sec.keys[key], 13, NULL,
434 (*crypt)->priv);
435 sec.key_sizes[key] = 13;
436 sec.flags |= (1 << key);
437 }
438 }
439 /* No key data - just set the default TX key index */
440 if (key_provided) {
441 IEEE80211_DEBUG_WX("Setting key %d to default Tx "
442 "key.\n", key);
443 ieee->tx_keyidx = key;
444 sec.active_key = key;
445 sec.flags |= SEC_ACTIVE_KEY;
446 }
447 }
448 if (erq->flags & (IW_ENCODE_OPEN | IW_ENCODE_RESTRICTED)) {
449 ieee->open_wep = !(erq->flags & IW_ENCODE_RESTRICTED);
450 sec.auth_mode = ieee->open_wep ? WLAN_AUTH_OPEN :
451 WLAN_AUTH_SHARED_KEY;
452 sec.flags |= SEC_AUTH_MODE;
453 IEEE80211_DEBUG_WX("Auth: %s\n",
454 sec.auth_mode == WLAN_AUTH_OPEN ?
455 "OPEN" : "SHARED KEY");
456 }
457
458 /* For now we just support WEP, so only set that security level...
459 * TODO: When WPA is added this is one place that needs to change */
460 sec.flags |= SEC_LEVEL;
461 sec.level = SEC_LEVEL_1; /* 40 and 104 bit WEP */
462 sec.encode_alg[key] = SEC_ALG_WEP;
463
464 done:
465 if (ieee->set_security)
466 ieee->set_security(dev, &sec);
467
468 /* Do not reset port if card is in Managed mode since resetting will
469 * generate new IEEE 802.11 authentication which may end up in looping
470 * with IEEE 802.1X. If your hardware requires a reset after WEP
471 * configuration (for example... Prism2), implement the reset_port in
472 * the callbacks structures used to initialize the 802.11 stack. */
473 if (ieee->reset_on_keychange &&
474 ieee->iw_mode != IW_MODE_INFRA &&
475 ieee->reset_port && ieee->reset_port(dev)) {
476 printk(KERN_DEBUG "%s: reset_port failed\n", dev->name);
477 return -EINVAL;
478 }
479 return 0;
480}
481
482int ieee80211_wx_get_encode(struct ieee80211_device *ieee,
483 struct iw_request_info *info,
484 union iwreq_data *wrqu, char *keybuf)
485{
486 struct iw_point *erq = &(wrqu->encoding);
487 int len, key;
488 struct ieee80211_crypt_data *crypt;
489 struct ieee80211_security *sec = &ieee->sec;
490
491 IEEE80211_DEBUG_WX("GET_ENCODE\n");
492
493 key = erq->flags & IW_ENCODE_INDEX;
494 if (key) {
495 if (key > WEP_KEYS)
496 return -EINVAL;
497 key--;
498 } else
499 key = ieee->tx_keyidx;
500
501 crypt = ieee->crypt[key];
502 erq->flags = key + 1;
503
504 if (!sec->enabled) {
505 erq->length = 0;
506 erq->flags |= IW_ENCODE_DISABLED;
507 return 0;
508 }
509
510 len = sec->key_sizes[key];
511 memcpy(keybuf, sec->keys[key], len);
512
513 erq->length = len;
514 erq->flags |= IW_ENCODE_ENABLED;
515
516 if (ieee->open_wep)
517 erq->flags |= IW_ENCODE_OPEN;
518 else
519 erq->flags |= IW_ENCODE_RESTRICTED;
520
521 return 0;
522}
523
524int ieee80211_wx_set_encodeext(struct ieee80211_device *ieee,
525 struct iw_request_info *info,
526 union iwreq_data *wrqu, char *extra)
527{
528 struct net_device *dev = ieee->dev;
529 struct iw_point *encoding = &wrqu->encoding;
530 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
531 int i, idx, ret = 0;
532 int group_key = 0;
533 const char *alg, *module;
534 struct ieee80211_crypto_ops *ops;
535 struct ieee80211_crypt_data **crypt;
536
537 struct ieee80211_security sec = {
538 .flags = 0,
539 };
540
541 idx = encoding->flags & IW_ENCODE_INDEX;
542 if (idx) {
543 if (idx < 1 || idx > WEP_KEYS)
544 return -EINVAL;
545 idx--;
546 } else
547 idx = ieee->tx_keyidx;
548
549 if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) {
550 crypt = &ieee->crypt[idx];
551 group_key = 1;
552 } else {
553 /* some Cisco APs use idx>0 for unicast in dynamic WEP */
554 if (idx != 0 && ext->alg != IW_ENCODE_ALG_WEP)
555 return -EINVAL;
556 if (ieee->iw_mode == IW_MODE_INFRA)
557 crypt = &ieee->crypt[idx];
558 else
559 return -EINVAL;
560 }
561
562 sec.flags |= SEC_ENABLED | SEC_ENCRYPT;
563 if ((encoding->flags & IW_ENCODE_DISABLED) ||
564 ext->alg == IW_ENCODE_ALG_NONE) {
565 if (*crypt)
566 ieee80211_crypt_delayed_deinit(ieee, crypt);
567
568 for (i = 0; i < WEP_KEYS; i++)
569 if (ieee->crypt[i] != NULL)
570 break;
571
572 if (i == WEP_KEYS) {
573 sec.enabled = 0;
574 sec.encrypt = 0;
575 sec.level = SEC_LEVEL_0;
576 sec.flags |= SEC_LEVEL;
577 }
578 goto done;
579 }
580
581 sec.enabled = 1;
582 sec.encrypt = 1;
583
584 if (group_key ? !ieee->host_mc_decrypt :
585 !(ieee->host_encrypt || ieee->host_decrypt ||
586 ieee->host_encrypt_msdu))
587 goto skip_host_crypt;
588
589 switch (ext->alg) {
590 case IW_ENCODE_ALG_WEP:
591 alg = "WEP";
592 module = "ieee80211_crypt_wep";
593 break;
594 case IW_ENCODE_ALG_TKIP:
595 alg = "TKIP";
596 module = "ieee80211_crypt_tkip";
597 break;
598 case IW_ENCODE_ALG_CCMP:
599 alg = "CCMP";
600 module = "ieee80211_crypt_ccmp";
601 break;
602 default:
603 IEEE80211_DEBUG_WX("%s: unknown crypto alg %d\n",
604 dev->name, ext->alg);
605 ret = -EINVAL;
606 goto done;
607 }
608
609 ops = ieee80211_get_crypto_ops(alg);
610 if (ops == NULL) {
611 request_module(module);
612 ops = ieee80211_get_crypto_ops(alg);
613 }
614 if (ops == NULL) {
615 IEEE80211_DEBUG_WX("%s: unknown crypto alg %d\n",
616 dev->name, ext->alg);
617 ret = -EINVAL;
618 goto done;
619 }
620
621 if (*crypt == NULL || (*crypt)->ops != ops) {
622 struct ieee80211_crypt_data *new_crypt;
623
624 ieee80211_crypt_delayed_deinit(ieee, crypt);
625
626 new_crypt = kzalloc(sizeof(*new_crypt), GFP_KERNEL);
627 if (new_crypt == NULL) {
628 ret = -ENOMEM;
629 goto done;
630 }
631 new_crypt->ops = ops;
632 if (new_crypt->ops && try_module_get(new_crypt->ops->owner))
633 new_crypt->priv = new_crypt->ops->init(idx);
634 if (new_crypt->priv == NULL) {
635 kfree(new_crypt);
636 ret = -EINVAL;
637 goto done;
638 }
639 *crypt = new_crypt;
640 }
641
642 if (ext->key_len > 0 && (*crypt)->ops->set_key &&
643 (*crypt)->ops->set_key(ext->key, ext->key_len, ext->rx_seq,
644 (*crypt)->priv) < 0) {
645 IEEE80211_DEBUG_WX("%s: key setting failed\n", dev->name);
646 ret = -EINVAL;
647 goto done;
648 }
649
650 skip_host_crypt:
651 if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) {
652 ieee->tx_keyidx = idx;
653 sec.active_key = idx;
654 sec.flags |= SEC_ACTIVE_KEY;
655 }
656
657 if (ext->alg != IW_ENCODE_ALG_NONE) {
658 memcpy(sec.keys[idx], ext->key, ext->key_len);
659 sec.key_sizes[idx] = ext->key_len;
660 sec.flags |= (1 << idx);
661 if (ext->alg == IW_ENCODE_ALG_WEP) {
662 sec.encode_alg[idx] = SEC_ALG_WEP;
663 sec.flags |= SEC_LEVEL;
664 sec.level = SEC_LEVEL_1;
665 } else if (ext->alg == IW_ENCODE_ALG_TKIP) {
666 sec.encode_alg[idx] = SEC_ALG_TKIP;
667 sec.flags |= SEC_LEVEL;
668 sec.level = SEC_LEVEL_2;
669 } else if (ext->alg == IW_ENCODE_ALG_CCMP) {
670 sec.encode_alg[idx] = SEC_ALG_CCMP;
671 sec.flags |= SEC_LEVEL;
672 sec.level = SEC_LEVEL_3;
673 }
674 /* Don't set sec level for group keys. */
675 if (group_key)
676 sec.flags &= ~SEC_LEVEL;
677 }
678 done:
679 if (ieee->set_security)
680 ieee->set_security(ieee->dev, &sec);
681
682 /*
683 * Do not reset port if card is in Managed mode since resetting will
684 * generate new IEEE 802.11 authentication which may end up in looping
685 * with IEEE 802.1X. If your hardware requires a reset after WEP
686 * configuration (for example... Prism2), implement the reset_port in
687 * the callbacks structures used to initialize the 802.11 stack.
688 */
689 if (ieee->reset_on_keychange &&
690 ieee->iw_mode != IW_MODE_INFRA &&
691 ieee->reset_port && ieee->reset_port(dev)) {
692 IEEE80211_DEBUG_WX("%s: reset_port failed\n", dev->name);
693 return -EINVAL;
694 }
695
696 return ret;
697}
698
699int ieee80211_wx_get_encodeext(struct ieee80211_device *ieee,
700 struct iw_request_info *info,
701 union iwreq_data *wrqu, char *extra)
702{
703 struct iw_point *encoding = &wrqu->encoding;
704 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
705 struct ieee80211_security *sec = &ieee->sec;
706 int idx, max_key_len;
707
708 max_key_len = encoding->length - sizeof(*ext);
709 if (max_key_len < 0)
710 return -EINVAL;
711
712 idx = encoding->flags & IW_ENCODE_INDEX;
713 if (idx) {
714 if (idx < 1 || idx > WEP_KEYS)
715 return -EINVAL;
716 idx--;
717 } else
718 idx = ieee->tx_keyidx;
719
720 if (!(ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) &&
721 ext->alg != IW_ENCODE_ALG_WEP)
722 if (idx != 0 || ieee->iw_mode != IW_MODE_INFRA)
723 return -EINVAL;
724
725 encoding->flags = idx + 1;
726 memset(ext, 0, sizeof(*ext));
727
728 if (!sec->enabled) {
729 ext->alg = IW_ENCODE_ALG_NONE;
730 ext->key_len = 0;
731 encoding->flags |= IW_ENCODE_DISABLED;
732 } else {
733 if (sec->encode_alg[idx] == SEC_ALG_WEP)
734 ext->alg = IW_ENCODE_ALG_WEP;
735 else if (sec->encode_alg[idx] == SEC_ALG_TKIP)
736 ext->alg = IW_ENCODE_ALG_TKIP;
737 else if (sec->encode_alg[idx] == SEC_ALG_CCMP)
738 ext->alg = IW_ENCODE_ALG_CCMP;
739 else
740 return -EINVAL;
741
742 ext->key_len = sec->key_sizes[idx];
743 memcpy(ext->key, sec->keys[idx], ext->key_len);
744 encoding->flags |= IW_ENCODE_ENABLED;
745 if (ext->key_len &&
746 (ext->alg == IW_ENCODE_ALG_TKIP ||
747 ext->alg == IW_ENCODE_ALG_CCMP))
748 ext->ext_flags |= IW_ENCODE_EXT_TX_SEQ_VALID;
749
750 }
751
752 return 0;
753}
754
755EXPORT_SYMBOL(ieee80211_wx_set_encodeext);
756EXPORT_SYMBOL(ieee80211_wx_get_encodeext);
757
758EXPORT_SYMBOL(ieee80211_wx_get_scan);
759EXPORT_SYMBOL(ieee80211_wx_set_encode);
760EXPORT_SYMBOL(ieee80211_wx_get_encode);
diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
index 1aa2dc9e380e..743f5542d65a 100644
--- a/net/ipv4/af_inet.c
+++ b/net/ipv4/af_inet.c
@@ -94,6 +94,7 @@
94#include <linux/igmp.h> 94#include <linux/igmp.h>
95#include <linux/inetdevice.h> 95#include <linux/inetdevice.h>
96#include <linux/netdevice.h> 96#include <linux/netdevice.h>
97#include <net/checksum.h>
97#include <net/ip.h> 98#include <net/ip.h>
98#include <net/protocol.h> 99#include <net/protocol.h>
99#include <net/arp.h> 100#include <net/arp.h>
@@ -245,7 +246,7 @@ static inline int inet_netns_ok(struct net *net, int protocol)
245 int hash; 246 int hash;
246 struct net_protocol *ipprot; 247 struct net_protocol *ipprot;
247 248
248 if (net == &init_net) 249 if (net_eq(net, &init_net))
249 return 1; 250 return 1;
250 251
251 hash = protocol & (MAX_INET_PROTOS - 1); 252 hash = protocol & (MAX_INET_PROTOS - 1);
@@ -272,10 +273,9 @@ static int inet_create(struct net *net, struct socket *sock, int protocol)
272 int try_loading_module = 0; 273 int try_loading_module = 0;
273 int err; 274 int err;
274 275
275 if (sock->type != SOCK_RAW && 276 if (unlikely(!inet_ehash_secret))
276 sock->type != SOCK_DGRAM && 277 if (sock->type != SOCK_RAW && sock->type != SOCK_DGRAM)
277 !inet_ehash_secret) 278 build_ehash_secret();
278 build_ehash_secret();
279 279
280 sock->state = SS_UNCONNECTED; 280 sock->state = SS_UNCONNECTED;
281 281
@@ -1070,11 +1070,8 @@ static int inet_sk_reselect_saddr(struct sock *sk)
1070 return 0; 1070 return 0;
1071 1071
1072 if (sysctl_ip_dynaddr > 1) { 1072 if (sysctl_ip_dynaddr > 1) {
1073 printk(KERN_INFO "%s(): shifting inet->" 1073 printk(KERN_INFO "%s(): shifting inet->saddr from %pI4 to %pI4\n",
1074 "saddr from " NIPQUAD_FMT " to " NIPQUAD_FMT "\n", 1074 __func__, &old_saddr, &new_saddr);
1075 __func__,
1076 NIPQUAD(old_saddr),
1077 NIPQUAD(new_saddr));
1078 } 1075 }
1079 1076
1080 inet->saddr = inet->rcv_saddr = new_saddr; 1077 inet->saddr = inet->rcv_saddr = new_saddr;
@@ -1245,6 +1242,100 @@ out:
1245 return segs; 1242 return segs;
1246} 1243}
1247 1244
1245static struct sk_buff **inet_gro_receive(struct sk_buff **head,
1246 struct sk_buff *skb)
1247{
1248 struct net_protocol *ops;
1249 struct sk_buff **pp = NULL;
1250 struct sk_buff *p;
1251 struct iphdr *iph;
1252 int flush = 1;
1253 int proto;
1254 int id;
1255
1256 if (unlikely(!pskb_may_pull(skb, sizeof(*iph))))
1257 goto out;
1258
1259 iph = ip_hdr(skb);
1260 proto = iph->protocol & (MAX_INET_PROTOS - 1);
1261
1262 rcu_read_lock();
1263 ops = rcu_dereference(inet_protos[proto]);
1264 if (!ops || !ops->gro_receive)
1265 goto out_unlock;
1266
1267 if (iph->version != 4 || iph->ihl != 5)
1268 goto out_unlock;
1269
1270 if (unlikely(ip_fast_csum((u8 *)iph, iph->ihl)))
1271 goto out_unlock;
1272
1273 flush = ntohs(iph->tot_len) != skb->len ||
1274 iph->frag_off != htons(IP_DF);
1275 id = ntohs(iph->id);
1276
1277 for (p = *head; p; p = p->next) {
1278 struct iphdr *iph2;
1279
1280 if (!NAPI_GRO_CB(p)->same_flow)
1281 continue;
1282
1283 iph2 = ip_hdr(p);
1284
1285 if (iph->protocol != iph2->protocol ||
1286 iph->tos != iph2->tos ||
1287 memcmp(&iph->saddr, &iph2->saddr, 8)) {
1288 NAPI_GRO_CB(p)->same_flow = 0;
1289 continue;
1290 }
1291
1292 /* All fields must match except length and checksum. */
1293 NAPI_GRO_CB(p)->flush |=
1294 memcmp(&iph->frag_off, &iph2->frag_off, 4) ||
1295 (u16)(ntohs(iph2->id) + NAPI_GRO_CB(p)->count) != id;
1296
1297 NAPI_GRO_CB(p)->flush |= flush;
1298 }
1299
1300 NAPI_GRO_CB(skb)->flush |= flush;
1301 __skb_pull(skb, sizeof(*iph));
1302 skb_reset_transport_header(skb);
1303
1304 pp = ops->gro_receive(head, skb);
1305
1306out_unlock:
1307 rcu_read_unlock();
1308
1309out:
1310 NAPI_GRO_CB(skb)->flush |= flush;
1311
1312 return pp;
1313}
1314
1315static int inet_gro_complete(struct sk_buff *skb)
1316{
1317 struct net_protocol *ops;
1318 struct iphdr *iph = ip_hdr(skb);
1319 int proto = iph->protocol & (MAX_INET_PROTOS - 1);
1320 int err = -ENOSYS;
1321 __be16 newlen = htons(skb->len - skb_network_offset(skb));
1322
1323 csum_replace2(&iph->check, iph->tot_len, newlen);
1324 iph->tot_len = newlen;
1325
1326 rcu_read_lock();
1327 ops = rcu_dereference(inet_protos[proto]);
1328 if (WARN_ON(!ops || !ops->gro_complete))
1329 goto out_unlock;
1330
1331 err = ops->gro_complete(skb);
1332
1333out_unlock:
1334 rcu_read_unlock();
1335
1336 return err;
1337}
1338
1248int inet_ctl_sock_create(struct sock **sk, unsigned short family, 1339int inet_ctl_sock_create(struct sock **sk, unsigned short family,
1249 unsigned short type, unsigned char protocol, 1340 unsigned short type, unsigned char protocol,
1250 struct net *net) 1341 struct net *net)
@@ -1311,6 +1402,7 @@ EXPORT_SYMBOL_GPL(snmp_mib_free);
1311#ifdef CONFIG_IP_MULTICAST 1402#ifdef CONFIG_IP_MULTICAST
1312static struct net_protocol igmp_protocol = { 1403static struct net_protocol igmp_protocol = {
1313 .handler = igmp_rcv, 1404 .handler = igmp_rcv,
1405 .netns_ok = 1,
1314}; 1406};
1315#endif 1407#endif
1316 1408
@@ -1319,6 +1411,8 @@ static struct net_protocol tcp_protocol = {
1319 .err_handler = tcp_v4_err, 1411 .err_handler = tcp_v4_err,
1320 .gso_send_check = tcp_v4_gso_send_check, 1412 .gso_send_check = tcp_v4_gso_send_check,
1321 .gso_segment = tcp_tso_segment, 1413 .gso_segment = tcp_tso_segment,
1414 .gro_receive = tcp4_gro_receive,
1415 .gro_complete = tcp4_gro_complete,
1322 .no_policy = 1, 1416 .no_policy = 1,
1323 .netns_ok = 1, 1417 .netns_ok = 1,
1324}; 1418};
@@ -1411,6 +1505,8 @@ static struct packet_type ip_packet_type = {
1411 .func = ip_rcv, 1505 .func = ip_rcv,
1412 .gso_send_check = inet_gso_send_check, 1506 .gso_send_check = inet_gso_send_check,
1413 .gso_segment = inet_gso_segment, 1507 .gso_segment = inet_gso_segment,
1508 .gro_receive = inet_gro_receive,
1509 .gro_complete = inet_gro_complete,
1414}; 1510};
1415 1511
1416static int __init inet_init(void) 1512static int __init inet_init(void)
diff --git a/net/ipv4/ah4.c b/net/ipv4/ah4.c
index 8219b7e0968d..e878e494296e 100644
--- a/net/ipv4/ah4.c
+++ b/net/ipv4/ah4.c
@@ -201,15 +201,16 @@ out:
201 201
202static void ah4_err(struct sk_buff *skb, u32 info) 202static void ah4_err(struct sk_buff *skb, u32 info)
203{ 203{
204 struct iphdr *iph = (struct iphdr*)skb->data; 204 struct net *net = dev_net(skb->dev);
205 struct ip_auth_hdr *ah = (struct ip_auth_hdr*)(skb->data+(iph->ihl<<2)); 205 struct iphdr *iph = (struct iphdr *)skb->data;
206 struct ip_auth_hdr *ah = (struct ip_auth_hdr *)(skb->data+(iph->ihl<<2));
206 struct xfrm_state *x; 207 struct xfrm_state *x;
207 208
208 if (icmp_hdr(skb)->type != ICMP_DEST_UNREACH || 209 if (icmp_hdr(skb)->type != ICMP_DEST_UNREACH ||
209 icmp_hdr(skb)->code != ICMP_FRAG_NEEDED) 210 icmp_hdr(skb)->code != ICMP_FRAG_NEEDED)
210 return; 211 return;
211 212
212 x = xfrm_state_lookup((xfrm_address_t *)&iph->daddr, ah->spi, IPPROTO_AH, AF_INET); 213 x = xfrm_state_lookup(net, (xfrm_address_t *)&iph->daddr, ah->spi, IPPROTO_AH, AF_INET);
213 if (!x) 214 if (!x)
214 return; 215 return;
215 printk(KERN_DEBUG "pmtu discovery on SA AH/%08x/%08x\n", 216 printk(KERN_DEBUG "pmtu discovery on SA AH/%08x/%08x\n",
@@ -293,9 +294,7 @@ static void ah_destroy(struct xfrm_state *x)
293 return; 294 return;
294 295
295 kfree(ahp->work_icv); 296 kfree(ahp->work_icv);
296 ahp->work_icv = NULL;
297 crypto_free_hash(ahp->tfm); 297 crypto_free_hash(ahp->tfm);
298 ahp->tfm = NULL;
299 kfree(ahp); 298 kfree(ahp);
300} 299}
301 300
@@ -316,6 +315,7 @@ static struct net_protocol ah4_protocol = {
316 .handler = xfrm4_rcv, 315 .handler = xfrm4_rcv,
317 .err_handler = ah4_err, 316 .err_handler = ah4_err,
318 .no_policy = 1, 317 .no_policy = 1,
318 .netns_ok = 1,
319}; 319};
320 320
321static int __init ah4_init(void) 321static int __init ah4_init(void)
diff --git a/net/ipv4/arp.c b/net/ipv4/arp.c
index 1a9dd66511fc..29a74c01d8de 100644
--- a/net/ipv4/arp.c
+++ b/net/ipv4/arp.c
@@ -506,7 +506,7 @@ int arp_bind_neighbour(struct dst_entry *dst)
506 if (dev == NULL) 506 if (dev == NULL)
507 return -EINVAL; 507 return -EINVAL;
508 if (n == NULL) { 508 if (n == NULL) {
509 __be32 nexthop = ((struct rtable*)dst)->rt_gateway; 509 __be32 nexthop = ((struct rtable *)dst)->rt_gateway;
510 if (dev->flags&(IFF_LOOPBACK|IFF_POINTOPOINT)) 510 if (dev->flags&(IFF_LOOPBACK|IFF_POINTOPOINT))
511 nexthop = 0; 511 nexthop = 0;
512 n = __neigh_lookup_errno( 512 n = __neigh_lookup_errno(
@@ -640,14 +640,14 @@ struct sk_buff *arp_create(int type, int ptype, __be32 dest_ip,
640 arp_ptr=(unsigned char *)(arp+1); 640 arp_ptr=(unsigned char *)(arp+1);
641 641
642 memcpy(arp_ptr, src_hw, dev->addr_len); 642 memcpy(arp_ptr, src_hw, dev->addr_len);
643 arp_ptr+=dev->addr_len; 643 arp_ptr += dev->addr_len;
644 memcpy(arp_ptr, &src_ip,4); 644 memcpy(arp_ptr, &src_ip, 4);
645 arp_ptr+=4; 645 arp_ptr += 4;
646 if (target_hw != NULL) 646 if (target_hw != NULL)
647 memcpy(arp_ptr, target_hw, dev->addr_len); 647 memcpy(arp_ptr, target_hw, dev->addr_len);
648 else 648 else
649 memset(arp_ptr, 0, dev->addr_len); 649 memset(arp_ptr, 0, dev->addr_len);
650 arp_ptr+=dev->addr_len; 650 arp_ptr += dev->addr_len;
651 memcpy(arp_ptr, &dest_ip, 4); 651 memcpy(arp_ptr, &dest_ip, 4);
652 652
653 return skb; 653 return skb;
@@ -818,18 +818,18 @@ static int arp_process(struct sk_buff *skb)
818 addr_type = rt->rt_type; 818 addr_type = rt->rt_type;
819 819
820 if (addr_type == RTN_LOCAL) { 820 if (addr_type == RTN_LOCAL) {
821 n = neigh_event_ns(&arp_tbl, sha, &sip, dev); 821 int dont_send = 0;
822 if (n) {
823 int dont_send = 0;
824
825 if (!dont_send)
826 dont_send |= arp_ignore(in_dev,sip,tip);
827 if (!dont_send && IN_DEV_ARPFILTER(in_dev))
828 dont_send |= arp_filter(sip,tip,dev);
829 if (!dont_send)
830 arp_send(ARPOP_REPLY,ETH_P_ARP,sip,dev,tip,sha,dev->dev_addr,sha);
831 822
832 neigh_release(n); 823 if (!dont_send)
824 dont_send |= arp_ignore(in_dev,sip,tip);
825 if (!dont_send && IN_DEV_ARPFILTER(in_dev))
826 dont_send |= arp_filter(sip,tip,dev);
827 if (!dont_send) {
828 n = neigh_event_ns(&arp_tbl, sha, &sip, dev);
829 if (n) {
830 arp_send(ARPOP_REPLY,ETH_P_ARP,sip,dev,tip,sha,dev->dev_addr,sha);
831 neigh_release(n);
832 }
833 } 833 }
834 goto out; 834 goto out;
835 } else if (IN_DEV_FORWARD(in_dev)) { 835 } else if (IN_DEV_FORWARD(in_dev)) {
@@ -1308,7 +1308,7 @@ static void arp_format_neigh_entry(struct seq_file *seq,
1308#if defined(CONFIG_AX25) || defined(CONFIG_AX25_MODULE) 1308#if defined(CONFIG_AX25) || defined(CONFIG_AX25_MODULE)
1309 } 1309 }
1310#endif 1310#endif
1311 sprintf(tbuf, NIPQUAD_FMT, NIPQUAD(*(u32*)n->primary_key)); 1311 sprintf(tbuf, "%pI4", n->primary_key);
1312 seq_printf(seq, "%-16s 0x%-10x0x%-10x%s * %s\n", 1312 seq_printf(seq, "%-16s 0x%-10x0x%-10x%s * %s\n",
1313 tbuf, hatype, arp_state_to_flags(n), hbuffer, dev->name); 1313 tbuf, hatype, arp_state_to_flags(n), hbuffer, dev->name);
1314 read_unlock(&n->lock); 1314 read_unlock(&n->lock);
@@ -1321,7 +1321,7 @@ static void arp_format_pneigh_entry(struct seq_file *seq,
1321 int hatype = dev ? dev->type : 0; 1321 int hatype = dev ? dev->type : 0;
1322 char tbuf[16]; 1322 char tbuf[16];
1323 1323
1324 sprintf(tbuf, NIPQUAD_FMT, NIPQUAD(*(u32*)n->key)); 1324 sprintf(tbuf, "%pI4", n->key);
1325 seq_printf(seq, "%-16s 0x%-10x0x%-10x%s * %s\n", 1325 seq_printf(seq, "%-16s 0x%-10x0x%-10x%s * %s\n",
1326 tbuf, hatype, ATF_PUBL | ATF_PERM, "00:00:00:00:00:00", 1326 tbuf, hatype, ATF_PUBL | ATF_PERM, "00:00:00:00:00:00",
1327 dev ? dev->name : "*"); 1327 dev ? dev->name : "*");
diff --git a/net/ipv4/cipso_ipv4.c b/net/ipv4/cipso_ipv4.c
index 2e78f6bd9775..e52799047a5f 100644
--- a/net/ipv4/cipso_ipv4.c
+++ b/net/ipv4/cipso_ipv4.c
@@ -490,7 +490,6 @@ int cipso_v4_doi_add(struct cipso_v4_doi *doi_def)
490 } 490 }
491 491
492 atomic_set(&doi_def->refcount, 1); 492 atomic_set(&doi_def->refcount, 1);
493 INIT_RCU_HEAD(&doi_def->rcu);
494 493
495 spin_lock(&cipso_v4_doi_list_lock); 494 spin_lock(&cipso_v4_doi_list_lock);
496 if (cipso_v4_doi_search(doi_def->doi) != NULL) 495 if (cipso_v4_doi_search(doi_def->doi) != NULL)
diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
index 56fce3ab6c55..309997edc8a5 100644
--- a/net/ipv4/devinet.c
+++ b/net/ipv4/devinet.c
@@ -112,13 +112,7 @@ static inline void devinet_sysctl_unregister(struct in_device *idev)
112 112
113static struct in_ifaddr *inet_alloc_ifa(void) 113static struct in_ifaddr *inet_alloc_ifa(void)
114{ 114{
115 struct in_ifaddr *ifa = kzalloc(sizeof(*ifa), GFP_KERNEL); 115 return kzalloc(sizeof(struct in_ifaddr), GFP_KERNEL);
116
117 if (ifa) {
118 INIT_RCU_HEAD(&ifa->rcu_head);
119 }
120
121 return ifa;
122} 116}
123 117
124static void inet_rcu_free_ifa(struct rcu_head *head) 118static void inet_rcu_free_ifa(struct rcu_head *head)
@@ -161,7 +155,6 @@ static struct in_device *inetdev_init(struct net_device *dev)
161 in_dev = kzalloc(sizeof(*in_dev), GFP_KERNEL); 155 in_dev = kzalloc(sizeof(*in_dev), GFP_KERNEL);
162 if (!in_dev) 156 if (!in_dev)
163 goto out; 157 goto out;
164 INIT_RCU_HEAD(&in_dev->rcu_head);
165 memcpy(&in_dev->cnf, dev_net(dev)->ipv4.devconf_dflt, 158 memcpy(&in_dev->cnf, dev_net(dev)->ipv4.devconf_dflt,
166 sizeof(in_dev->cnf)); 159 sizeof(in_dev->cnf));
167 in_dev->cnf.sysctl = NULL; 160 in_dev->cnf.sysctl = NULL;
@@ -1108,7 +1101,7 @@ out:
1108} 1101}
1109 1102
1110static struct notifier_block ip_netdev_notifier = { 1103static struct notifier_block ip_netdev_notifier = {
1111 .notifier_call =inetdev_event, 1104 .notifier_call = inetdev_event,
1112}; 1105};
1113 1106
1114static inline size_t inet_nlmsg_size(void) 1107static inline size_t inet_nlmsg_size(void)
@@ -1195,7 +1188,7 @@ done:
1195 return skb->len; 1188 return skb->len;
1196} 1189}
1197 1190
1198static void rtmsg_ifa(int event, struct in_ifaddr* ifa, struct nlmsghdr *nlh, 1191static void rtmsg_ifa(int event, struct in_ifaddr *ifa, struct nlmsghdr *nlh,
1199 u32 pid) 1192 u32 pid)
1200{ 1193{
1201 struct sk_buff *skb; 1194 struct sk_buff *skb;
@@ -1262,7 +1255,7 @@ static void inet_forward_change(struct net *net)
1262} 1255}
1263 1256
1264static int devinet_conf_proc(ctl_table *ctl, int write, 1257static int devinet_conf_proc(ctl_table *ctl, int write,
1265 struct file* filp, void __user *buffer, 1258 struct file *filp, void __user *buffer,
1266 size_t *lenp, loff_t *ppos) 1259 size_t *lenp, loff_t *ppos)
1267{ 1260{
1268 int ret = proc_dointvec(ctl, write, filp, buffer, lenp, ppos); 1261 int ret = proc_dointvec(ctl, write, filp, buffer, lenp, ppos);
@@ -1334,7 +1327,7 @@ static int devinet_conf_sysctl(ctl_table *table,
1334} 1327}
1335 1328
1336static int devinet_sysctl_forward(ctl_table *ctl, int write, 1329static int devinet_sysctl_forward(ctl_table *ctl, int write,
1337 struct file* filp, void __user *buffer, 1330 struct file *filp, void __user *buffer,
1338 size_t *lenp, loff_t *ppos) 1331 size_t *lenp, loff_t *ppos)
1339{ 1332{
1340 int *valp = ctl->data; 1333 int *valp = ctl->data;
@@ -1363,7 +1356,7 @@ static int devinet_sysctl_forward(ctl_table *ctl, int write,
1363} 1356}
1364 1357
1365int ipv4_doint_and_flush(ctl_table *ctl, int write, 1358int ipv4_doint_and_flush(ctl_table *ctl, int write,
1366 struct file* filp, void __user *buffer, 1359 struct file *filp, void __user *buffer,
1367 size_t *lenp, loff_t *ppos) 1360 size_t *lenp, loff_t *ppos)
1368{ 1361{
1369 int *valp = ctl->data; 1362 int *valp = ctl->data;
diff --git a/net/ipv4/esp4.c b/net/ipv4/esp4.c
index 21515d4c49eb..18bb383ea393 100644
--- a/net/ipv4/esp4.c
+++ b/net/ipv4/esp4.c
@@ -413,15 +413,16 @@ static u32 esp4_get_mtu(struct xfrm_state *x, int mtu)
413 413
414static void esp4_err(struct sk_buff *skb, u32 info) 414static void esp4_err(struct sk_buff *skb, u32 info)
415{ 415{
416 struct iphdr *iph = (struct iphdr*)skb->data; 416 struct net *net = dev_net(skb->dev);
417 struct ip_esp_hdr *esph = (struct ip_esp_hdr*)(skb->data+(iph->ihl<<2)); 417 struct iphdr *iph = (struct iphdr *)skb->data;
418 struct ip_esp_hdr *esph = (struct ip_esp_hdr *)(skb->data+(iph->ihl<<2));
418 struct xfrm_state *x; 419 struct xfrm_state *x;
419 420
420 if (icmp_hdr(skb)->type != ICMP_DEST_UNREACH || 421 if (icmp_hdr(skb)->type != ICMP_DEST_UNREACH ||
421 icmp_hdr(skb)->code != ICMP_FRAG_NEEDED) 422 icmp_hdr(skb)->code != ICMP_FRAG_NEEDED)
422 return; 423 return;
423 424
424 x = xfrm_state_lookup((xfrm_address_t *)&iph->daddr, esph->spi, IPPROTO_ESP, AF_INET); 425 x = xfrm_state_lookup(net, (xfrm_address_t *)&iph->daddr, esph->spi, IPPROTO_ESP, AF_INET);
425 if (!x) 426 if (!x)
426 return; 427 return;
427 NETDEBUG(KERN_DEBUG "pmtu discovery on SA ESP/%08x/%08x\n", 428 NETDEBUG(KERN_DEBUG "pmtu discovery on SA ESP/%08x/%08x\n",
@@ -618,6 +619,7 @@ static struct net_protocol esp4_protocol = {
618 .handler = xfrm4_rcv, 619 .handler = xfrm4_rcv,
619 .err_handler = esp4_err, 620 .err_handler = esp4_err,
620 .no_policy = 1, 621 .no_policy = 1,
622 .netns_ok = 1,
621}; 623};
622 624
623static int __init esp4_init(void) 625static int __init esp4_init(void)
diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
index 65c1503f8cc8..741e4fa3e474 100644
--- a/net/ipv4/fib_frontend.c
+++ b/net/ipv4/fib_frontend.c
@@ -578,7 +578,7 @@ errout:
578 return err; 578 return err;
579} 579}
580 580
581static int inet_rtm_delroute(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg) 581static int inet_rtm_delroute(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
582{ 582{
583 struct net *net = sock_net(skb->sk); 583 struct net *net = sock_net(skb->sk);
584 struct fib_config cfg; 584 struct fib_config cfg;
@@ -600,7 +600,7 @@ errout:
600 return err; 600 return err;
601} 601}
602 602
603static int inet_rtm_newroute(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg) 603static int inet_rtm_newroute(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
604{ 604{
605 struct net *net = sock_net(skb->sk); 605 struct net *net = sock_net(skb->sk);
606 struct fib_config cfg; 606 struct fib_config cfg;
@@ -903,7 +903,7 @@ static void fib_disable_ip(struct net_device *dev, int force)
903 903
904static int fib_inetaddr_event(struct notifier_block *this, unsigned long event, void *ptr) 904static int fib_inetaddr_event(struct notifier_block *this, unsigned long event, void *ptr)
905{ 905{
906 struct in_ifaddr *ifa = (struct in_ifaddr*)ptr; 906 struct in_ifaddr *ifa = (struct in_ifaddr *)ptr;
907 struct net_device *dev = ifa->ifa_dev->dev; 907 struct net_device *dev = ifa->ifa_dev->dev;
908 908
909 switch (event) { 909 switch (event) {
@@ -964,11 +964,11 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
964} 964}
965 965
966static struct notifier_block fib_inetaddr_notifier = { 966static struct notifier_block fib_inetaddr_notifier = {
967 .notifier_call =fib_inetaddr_event, 967 .notifier_call = fib_inetaddr_event,
968}; 968};
969 969
970static struct notifier_block fib_netdev_notifier = { 970static struct notifier_block fib_netdev_notifier = {
971 .notifier_call =fib_netdev_event, 971 .notifier_call = fib_netdev_event,
972}; 972};
973 973
974static int __net_init ip_fib_net_init(struct net *net) 974static int __net_init ip_fib_net_init(struct net *net)
diff --git a/net/ipv4/fib_hash.c b/net/ipv4/fib_hash.c
index c8cac6c7f881..ded8c44fb848 100644
--- a/net/ipv4/fib_hash.c
+++ b/net/ipv4/fib_hash.c
@@ -247,7 +247,7 @@ fn_hash_lookup(struct fib_table *tb, const struct flowi *flp, struct fib_result
247{ 247{
248 int err; 248 int err;
249 struct fn_zone *fz; 249 struct fn_zone *fz;
250 struct fn_hash *t = (struct fn_hash*)tb->tb_data; 250 struct fn_hash *t = (struct fn_hash *)tb->tb_data;
251 251
252 read_lock(&fib_hash_lock); 252 read_lock(&fib_hash_lock);
253 for (fz = t->fn_zone_list; fz; fz = fz->fz_next) { 253 for (fz = t->fn_zone_list; fz; fz = fz->fz_next) {
@@ -283,7 +283,7 @@ fn_hash_select_default(struct fib_table *tb, const struct flowi *flp, struct fib
283 struct fib_node *f; 283 struct fib_node *f;
284 struct fib_info *fi = NULL; 284 struct fib_info *fi = NULL;
285 struct fib_info *last_resort; 285 struct fib_info *last_resort;
286 struct fn_hash *t = (struct fn_hash*)tb->tb_data; 286 struct fn_hash *t = (struct fn_hash *)tb->tb_data;
287 struct fn_zone *fz = t->fn_zones[0]; 287 struct fn_zone *fz = t->fn_zones[0];
288 288
289 if (fz == NULL) 289 if (fz == NULL)
@@ -548,7 +548,7 @@ out:
548 548
549static int fn_hash_delete(struct fib_table *tb, struct fib_config *cfg) 549static int fn_hash_delete(struct fib_table *tb, struct fib_config *cfg)
550{ 550{
551 struct fn_hash *table = (struct fn_hash*)tb->tb_data; 551 struct fn_hash *table = (struct fn_hash *)tb->tb_data;
552 struct fib_node *f; 552 struct fib_node *f;
553 struct fib_alias *fa, *fa_to_delete; 553 struct fib_alias *fa, *fa_to_delete;
554 struct fn_zone *fz; 554 struct fn_zone *fz;
@@ -748,7 +748,7 @@ static int fn_hash_dump(struct fib_table *tb, struct sk_buff *skb, struct netlin
748{ 748{
749 int m, s_m; 749 int m, s_m;
750 struct fn_zone *fz; 750 struct fn_zone *fz;
751 struct fn_hash *table = (struct fn_hash*)tb->tb_data; 751 struct fn_hash *table = (struct fn_hash *)tb->tb_data;
752 752
753 s_m = cb->args[2]; 753 s_m = cb->args[2];
754 read_lock(&fib_hash_lock); 754 read_lock(&fib_hash_lock);
@@ -845,10 +845,10 @@ static struct fib_alias *fib_get_first(struct seq_file *seq)
845 struct hlist_node *node; 845 struct hlist_node *node;
846 struct fib_node *fn; 846 struct fib_node *fn;
847 847
848 hlist_for_each_entry(fn,node,iter->hash_head,fn_hash) { 848 hlist_for_each_entry(fn, node, iter->hash_head, fn_hash) {
849 struct fib_alias *fa; 849 struct fib_alias *fa;
850 850
851 list_for_each_entry(fa,&fn->fn_alias,fa_list) { 851 list_for_each_entry(fa, &fn->fn_alias, fa_list) {
852 iter->fn = fn; 852 iter->fn = fn;
853 iter->fa = fa; 853 iter->fa = fa;
854 goto out; 854 goto out;
diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
index ded2ae34eab1..4817dea3bc73 100644
--- a/net/ipv4/fib_semantics.c
+++ b/net/ipv4/fib_semantics.c
@@ -63,16 +63,16 @@ static DEFINE_SPINLOCK(fib_multipath_lock);
63for (nhsel=0, nh = (fi)->fib_nh; nhsel < (fi)->fib_nhs; nh++, nhsel++) 63for (nhsel=0, nh = (fi)->fib_nh; nhsel < (fi)->fib_nhs; nh++, nhsel++)
64 64
65#define change_nexthops(fi) { int nhsel; struct fib_nh * nh; \ 65#define change_nexthops(fi) { int nhsel; struct fib_nh * nh; \
66for (nhsel=0, nh = (struct fib_nh*)((fi)->fib_nh); nhsel < (fi)->fib_nhs; nh++, nhsel++) 66for (nhsel=0, nh = (struct fib_nh *)((fi)->fib_nh); nhsel < (fi)->fib_nhs; nh++, nhsel++)
67 67
68#else /* CONFIG_IP_ROUTE_MULTIPATH */ 68#else /* CONFIG_IP_ROUTE_MULTIPATH */
69 69
70/* Hope, that gcc will optimize it to get rid of dummy loop */ 70/* Hope, that gcc will optimize it to get rid of dummy loop */
71 71
72#define for_nexthops(fi) { int nhsel=0; const struct fib_nh * nh = (fi)->fib_nh; \ 72#define for_nexthops(fi) { int nhsel = 0; const struct fib_nh * nh = (fi)->fib_nh; \
73for (nhsel=0; nhsel < 1; nhsel++) 73for (nhsel=0; nhsel < 1; nhsel++)
74 74
75#define change_nexthops(fi) { int nhsel=0; struct fib_nh * nh = (struct fib_nh*)((fi)->fib_nh); \ 75#define change_nexthops(fi) { int nhsel = 0; struct fib_nh * nh = (struct fib_nh *)((fi)->fib_nh); \
76for (nhsel=0; nhsel < 1; nhsel++) 76for (nhsel=0; nhsel < 1; nhsel++)
77 77
78#endif /* CONFIG_IP_ROUTE_MULTIPATH */ 78#endif /* CONFIG_IP_ROUTE_MULTIPATH */
@@ -358,7 +358,7 @@ int fib_detect_death(struct fib_info *fi, int order,
358 state = n->nud_state; 358 state = n->nud_state;
359 neigh_release(n); 359 neigh_release(n);
360 } 360 }
361 if (state==NUD_REACHABLE) 361 if (state == NUD_REACHABLE)
362 return 0; 362 return 0;
363 if ((state&NUD_VALID) && order != dflt) 363 if ((state&NUD_VALID) && order != dflt)
364 return 0; 364 return 0;
diff --git a/net/ipv4/fib_trie.c b/net/ipv4/fib_trie.c
index 5cb72786a8af..ec0ae490f0b6 100644
--- a/net/ipv4/fib_trie.c
+++ b/net/ipv4/fib_trie.c
@@ -2399,8 +2399,8 @@ static int fib_trie_seq_show(struct seq_file *seq, void *v)
2399 __be32 prf = htonl(mask_pfx(tn->key, tn->pos)); 2399 __be32 prf = htonl(mask_pfx(tn->key, tn->pos));
2400 2400
2401 seq_indent(seq, iter->depth-1); 2401 seq_indent(seq, iter->depth-1);
2402 seq_printf(seq, " +-- " NIPQUAD_FMT "/%d %d %d %d\n", 2402 seq_printf(seq, " +-- %pI4/%d %d %d %d\n",
2403 NIPQUAD(prf), tn->pos, tn->bits, tn->full_children, 2403 &prf, tn->pos, tn->bits, tn->full_children,
2404 tn->empty_children); 2404 tn->empty_children);
2405 2405
2406 } else { 2406 } else {
@@ -2410,7 +2410,7 @@ static int fib_trie_seq_show(struct seq_file *seq, void *v)
2410 __be32 val = htonl(l->key); 2410 __be32 val = htonl(l->key);
2411 2411
2412 seq_indent(seq, iter->depth); 2412 seq_indent(seq, iter->depth);
2413 seq_printf(seq, " |-- " NIPQUAD_FMT "\n", NIPQUAD(val)); 2413 seq_printf(seq, " |-- %pI4\n", &val);
2414 2414
2415 hlist_for_each_entry_rcu(li, node, &l->list, hlist) { 2415 hlist_for_each_entry_rcu(li, node, &l->list, hlist) {
2416 struct fib_alias *fa; 2416 struct fib_alias *fa;
diff --git a/net/ipv4/icmp.c b/net/ipv4/icmp.c
index 72b2de76f1cd..705b33b184a3 100644
--- a/net/ipv4/icmp.c
+++ b/net/ipv4/icmp.c
@@ -321,12 +321,12 @@ static int icmp_glue_bits(void *from, char *to, int offset, int len, int odd,
321} 321}
322 322
323static void icmp_push_reply(struct icmp_bxm *icmp_param, 323static void icmp_push_reply(struct icmp_bxm *icmp_param,
324 struct ipcm_cookie *ipc, struct rtable *rt) 324 struct ipcm_cookie *ipc, struct rtable **rt)
325{ 325{
326 struct sock *sk; 326 struct sock *sk;
327 struct sk_buff *skb; 327 struct sk_buff *skb;
328 328
329 sk = icmp_sk(dev_net(rt->u.dst.dev)); 329 sk = icmp_sk(dev_net((*rt)->u.dst.dev));
330 if (ip_append_data(sk, icmp_glue_bits, icmp_param, 330 if (ip_append_data(sk, icmp_glue_bits, icmp_param,
331 icmp_param->data_len+icmp_param->head_len, 331 icmp_param->data_len+icmp_param->head_len,
332 icmp_param->head_len, 332 icmp_param->head_len,
@@ -392,7 +392,7 @@ static void icmp_reply(struct icmp_bxm *icmp_param, struct sk_buff *skb)
392 } 392 }
393 if (icmpv4_xrlim_allow(net, rt, icmp_param->data.icmph.type, 393 if (icmpv4_xrlim_allow(net, rt, icmp_param->data.icmph.type,
394 icmp_param->data.icmph.code)) 394 icmp_param->data.icmph.code))
395 icmp_push_reply(icmp_param, &ipc, rt); 395 icmp_push_reply(icmp_param, &ipc, &rt);
396 ip_rt_put(rt); 396 ip_rt_put(rt);
397out_unlock: 397out_unlock:
398 icmp_xmit_unlock(sk); 398 icmp_xmit_unlock(sk);
@@ -562,7 +562,7 @@ void icmp_send(struct sk_buff *skb_in, int type, int code, __be32 info)
562 /* No need to clone since we're just using its address. */ 562 /* No need to clone since we're just using its address. */
563 rt2 = rt; 563 rt2 = rt;
564 564
565 err = xfrm_lookup((struct dst_entry **)&rt, &fl, NULL, 0); 565 err = xfrm_lookup(net, (struct dst_entry **)&rt, &fl, NULL, 0);
566 switch (err) { 566 switch (err) {
567 case 0: 567 case 0:
568 if (rt != rt2) 568 if (rt != rt2)
@@ -601,7 +601,7 @@ void icmp_send(struct sk_buff *skb_in, int type, int code, __be32 info)
601 if (err) 601 if (err)
602 goto relookup_failed; 602 goto relookup_failed;
603 603
604 err = xfrm_lookup((struct dst_entry **)&rt2, &fl, NULL, 604 err = xfrm_lookup(net, (struct dst_entry **)&rt2, &fl, NULL,
605 XFRM_LOOKUP_ICMP); 605 XFRM_LOOKUP_ICMP);
606 switch (err) { 606 switch (err) {
607 case 0: 607 case 0:
@@ -635,7 +635,7 @@ route_done:
635 icmp_param.data_len = room; 635 icmp_param.data_len = room;
636 icmp_param.head_len = sizeof(struct icmphdr); 636 icmp_param.head_len = sizeof(struct icmphdr);
637 637
638 icmp_push_reply(&icmp_param, &ipc, rt); 638 icmp_push_reply(&icmp_param, &ipc, &rt);
639ende: 639ende:
640 ip_rt_put(rt); 640 ip_rt_put(rt);
641out_unlock: 641out_unlock:
@@ -683,10 +683,8 @@ static void icmp_unreach(struct sk_buff *skb)
683 break; 683 break;
684 case ICMP_FRAG_NEEDED: 684 case ICMP_FRAG_NEEDED:
685 if (ipv4_config.no_pmtu_disc) { 685 if (ipv4_config.no_pmtu_disc) {
686 LIMIT_NETDEBUG(KERN_INFO "ICMP: " NIPQUAD_FMT ": " 686 LIMIT_NETDEBUG(KERN_INFO "ICMP: %pI4: fragmentation needed and DF set.\n",
687 "fragmentation needed " 687 &iph->daddr);
688 "and DF set.\n",
689 NIPQUAD(iph->daddr));
690 } else { 688 } else {
691 info = ip_rt_frag_needed(net, iph, 689 info = ip_rt_frag_needed(net, iph,
692 ntohs(icmph->un.frag.mtu), 690 ntohs(icmph->un.frag.mtu),
@@ -696,9 +694,8 @@ static void icmp_unreach(struct sk_buff *skb)
696 } 694 }
697 break; 695 break;
698 case ICMP_SR_FAILED: 696 case ICMP_SR_FAILED:
699 LIMIT_NETDEBUG(KERN_INFO "ICMP: " NIPQUAD_FMT ": Source " 697 LIMIT_NETDEBUG(KERN_INFO "ICMP: %pI4: Source Route Failed.\n",
700 "Route Failed.\n", 698 &iph->daddr);
701 NIPQUAD(iph->daddr));
702 break; 699 break;
703 default: 700 default:
704 break; 701 break;
@@ -729,12 +726,12 @@ static void icmp_unreach(struct sk_buff *skb)
729 if (!net->ipv4.sysctl_icmp_ignore_bogus_error_responses && 726 if (!net->ipv4.sysctl_icmp_ignore_bogus_error_responses &&
730 inet_addr_type(net, iph->daddr) == RTN_BROADCAST) { 727 inet_addr_type(net, iph->daddr) == RTN_BROADCAST) {
731 if (net_ratelimit()) 728 if (net_ratelimit())
732 printk(KERN_WARNING NIPQUAD_FMT " sent an invalid ICMP " 729 printk(KERN_WARNING "%pI4 sent an invalid ICMP "
733 "type %u, code %u " 730 "type %u, code %u "
734 "error to a broadcast: " NIPQUAD_FMT " on %s\n", 731 "error to a broadcast: %pI4 on %s\n",
735 NIPQUAD(ip_hdr(skb)->saddr), 732 &ip_hdr(skb)->saddr,
736 icmph->type, icmph->code, 733 icmph->type, icmph->code,
737 NIPQUAD(iph->daddr), 734 &iph->daddr,
738 skb->dev->name); 735 skb->dev->name);
739 goto out; 736 goto out;
740 } 737 }
@@ -952,9 +949,8 @@ static void icmp_address_reply(struct sk_buff *skb)
952 break; 949 break;
953 } 950 }
954 if (!ifa && net_ratelimit()) { 951 if (!ifa && net_ratelimit()) {
955 printk(KERN_INFO "Wrong address mask " NIPQUAD_FMT " from " 952 printk(KERN_INFO "Wrong address mask %pI4 from %s/%pI4\n",
956 "%s/" NIPQUAD_FMT "\n", 953 mp, dev->name, &rt->rt_src);
957 NIPQUAD(*mp), dev->name, NIPQUAD(rt->rt_src));
958 } 954 }
959 } 955 }
960 rcu_read_unlock(); 956 rcu_read_unlock();
@@ -976,9 +972,10 @@ int icmp_rcv(struct sk_buff *skb)
976 struct net *net = dev_net(rt->u.dst.dev); 972 struct net *net = dev_net(rt->u.dst.dev);
977 973
978 if (!xfrm4_policy_check(NULL, XFRM_POLICY_IN, skb)) { 974 if (!xfrm4_policy_check(NULL, XFRM_POLICY_IN, skb)) {
975 struct sec_path *sp = skb_sec_path(skb);
979 int nh; 976 int nh;
980 977
981 if (!(skb->sp && skb->sp->xvec[skb->sp->len - 1]->props.flags & 978 if (!(sp && sp->xvec[sp->len - 1]->props.flags &
982 XFRM_STATE_ICMP)) 979 XFRM_STATE_ICMP))
983 goto drop; 980 goto drop;
984 981
diff --git a/net/ipv4/igmp.c b/net/ipv4/igmp.c
index a0d86455c53e..9eb6219af615 100644
--- a/net/ipv4/igmp.c
+++ b/net/ipv4/igmp.c
@@ -167,7 +167,7 @@ static __inline__ void igmp_stop_timer(struct ip_mc_list *im)
167 spin_lock_bh(&im->lock); 167 spin_lock_bh(&im->lock);
168 if (del_timer(&im->timer)) 168 if (del_timer(&im->timer))
169 atomic_dec(&im->refcnt); 169 atomic_dec(&im->refcnt);
170 im->tm_running=0; 170 im->tm_running = 0;
171 im->reporter = 0; 171 im->reporter = 0;
172 im->unsolicit_count = 0; 172 im->unsolicit_count = 0;
173 spin_unlock_bh(&im->lock); 173 spin_unlock_bh(&im->lock);
@@ -176,9 +176,9 @@ static __inline__ void igmp_stop_timer(struct ip_mc_list *im)
176/* It must be called with locked im->lock */ 176/* It must be called with locked im->lock */
177static void igmp_start_timer(struct ip_mc_list *im, int max_delay) 177static void igmp_start_timer(struct ip_mc_list *im, int max_delay)
178{ 178{
179 int tv=net_random() % max_delay; 179 int tv = net_random() % max_delay;
180 180
181 im->tm_running=1; 181 im->tm_running = 1;
182 if (!mod_timer(&im->timer, jiffies+tv+2)) 182 if (!mod_timer(&im->timer, jiffies+tv+2))
183 atomic_inc(&im->refcnt); 183 atomic_inc(&im->refcnt);
184} 184}
@@ -207,7 +207,7 @@ static void igmp_mod_timer(struct ip_mc_list *im, int max_delay)
207 if (del_timer(&im->timer)) { 207 if (del_timer(&im->timer)) {
208 if ((long)(im->timer.expires-jiffies) < max_delay) { 208 if ((long)(im->timer.expires-jiffies) < max_delay) {
209 add_timer(&im->timer); 209 add_timer(&im->timer);
210 im->tm_running=1; 210 im->tm_running = 1;
211 spin_unlock_bh(&im->lock); 211 spin_unlock_bh(&im->lock);
212 return; 212 return;
213 } 213 }
@@ -358,7 +358,7 @@ static int igmpv3_sendpack(struct sk_buff *skb)
358 358
359static int grec_size(struct ip_mc_list *pmc, int type, int gdel, int sdel) 359static int grec_size(struct ip_mc_list *pmc, int type, int gdel, int sdel)
360{ 360{
361 return sizeof(struct igmpv3_grec) + 4*igmp_scount(pmc,type,gdel,sdel); 361 return sizeof(struct igmpv3_grec) + 4*igmp_scount(pmc, type, gdel, sdel);
362} 362}
363 363
364static struct sk_buff *add_grhead(struct sk_buff *skb, struct ip_mc_list *pmc, 364static struct sk_buff *add_grhead(struct sk_buff *skb, struct ip_mc_list *pmc,
@@ -653,7 +653,7 @@ static int igmp_send_report(struct in_device *in_dev, struct ip_mc_list *pmc,
653 return -1; 653 return -1;
654 } 654 }
655 655
656 skb=alloc_skb(IGMP_SIZE+LL_ALLOCATED_SPACE(dev), GFP_ATOMIC); 656 skb = alloc_skb(IGMP_SIZE+LL_ALLOCATED_SPACE(dev), GFP_ATOMIC);
657 if (skb == NULL) { 657 if (skb == NULL) {
658 ip_rt_put(rt); 658 ip_rt_put(rt);
659 return -1; 659 return -1;
@@ -682,11 +682,11 @@ static int igmp_send_report(struct in_device *in_dev, struct ip_mc_list *pmc,
682 ((u8*)&iph[1])[3] = 0; 682 ((u8*)&iph[1])[3] = 0;
683 683
684 ih = (struct igmphdr *)skb_put(skb, sizeof(struct igmphdr)); 684 ih = (struct igmphdr *)skb_put(skb, sizeof(struct igmphdr));
685 ih->type=type; 685 ih->type = type;
686 ih->code=0; 686 ih->code = 0;
687 ih->csum=0; 687 ih->csum = 0;
688 ih->group=group; 688 ih->group = group;
689 ih->csum=ip_compute_csum((void *)ih, sizeof(struct igmphdr)); 689 ih->csum = ip_compute_csum((void *)ih, sizeof(struct igmphdr));
690 690
691 return ip_local_out(skb); 691 return ip_local_out(skb);
692} 692}
@@ -728,7 +728,7 @@ static void igmp_timer_expire(unsigned long data)
728 struct in_device *in_dev = im->interface; 728 struct in_device *in_dev = im->interface;
729 729
730 spin_lock(&im->lock); 730 spin_lock(&im->lock);
731 im->tm_running=0; 731 im->tm_running = 0;
732 732
733 if (im->unsolicit_count) { 733 if (im->unsolicit_count) {
734 im->unsolicit_count--; 734 im->unsolicit_count--;
@@ -997,7 +997,7 @@ static void ip_mc_filter_add(struct in_device *in_dev, __be32 addr)
997 --ANK 997 --ANK
998 */ 998 */
999 if (arp_mc_map(addr, buf, dev, 0) == 0) 999 if (arp_mc_map(addr, buf, dev, 0) == 0)
1000 dev_mc_add(dev,buf,dev->addr_len,0); 1000 dev_mc_add(dev, buf, dev->addr_len, 0);
1001} 1001}
1002 1002
1003/* 1003/*
@@ -1010,7 +1010,7 @@ static void ip_mc_filter_del(struct in_device *in_dev, __be32 addr)
1010 struct net_device *dev = in_dev->dev; 1010 struct net_device *dev = in_dev->dev;
1011 1011
1012 if (arp_mc_map(addr, buf, dev, 0) == 0) 1012 if (arp_mc_map(addr, buf, dev, 0) == 0)
1013 dev_mc_delete(dev,buf,dev->addr_len,0); 1013 dev_mc_delete(dev, buf, dev->addr_len, 0);
1014} 1014}
1015 1015
1016#ifdef CONFIG_IP_MULTICAST 1016#ifdef CONFIG_IP_MULTICAST
@@ -1210,10 +1210,10 @@ void ip_mc_inc_group(struct in_device *in_dev, __be32 addr)
1210 if (!im) 1210 if (!im)
1211 goto out; 1211 goto out;
1212 1212
1213 im->users=1; 1213 im->users = 1;
1214 im->interface=in_dev; 1214 im->interface = in_dev;
1215 in_dev_hold(in_dev); 1215 in_dev_hold(in_dev);
1216 im->multiaddr=addr; 1216 im->multiaddr = addr;
1217 /* initial mode is (EX, empty) */ 1217 /* initial mode is (EX, empty) */
1218 im->sfmode = MCAST_EXCLUDE; 1218 im->sfmode = MCAST_EXCLUDE;
1219 im->sfcount[MCAST_INCLUDE] = 0; 1219 im->sfcount[MCAST_INCLUDE] = 0;
@@ -1224,7 +1224,7 @@ void ip_mc_inc_group(struct in_device *in_dev, __be32 addr)
1224 atomic_set(&im->refcnt, 1); 1224 atomic_set(&im->refcnt, 1);
1225 spin_lock_init(&im->lock); 1225 spin_lock_init(&im->lock);
1226#ifdef CONFIG_IP_MULTICAST 1226#ifdef CONFIG_IP_MULTICAST
1227 im->tm_running=0; 1227 im->tm_running = 0;
1228 setup_timer(&im->timer, &igmp_timer_expire, (unsigned long)im); 1228 setup_timer(&im->timer, &igmp_timer_expire, (unsigned long)im);
1229 im->unsolicit_count = IGMP_Unsolicited_Report_Count; 1229 im->unsolicit_count = IGMP_Unsolicited_Report_Count;
1230 im->reporter = 0; 1230 im->reporter = 0;
@@ -1232,8 +1232,8 @@ void ip_mc_inc_group(struct in_device *in_dev, __be32 addr)
1232#endif 1232#endif
1233 im->loaded = 0; 1233 im->loaded = 0;
1234 write_lock_bh(&in_dev->mc_list_lock); 1234 write_lock_bh(&in_dev->mc_list_lock);
1235 im->next=in_dev->mc_list; 1235 im->next = in_dev->mc_list;
1236 in_dev->mc_list=im; 1236 in_dev->mc_list = im;
1237 in_dev->mc_count++; 1237 in_dev->mc_count++;
1238 write_unlock_bh(&in_dev->mc_list_lock); 1238 write_unlock_bh(&in_dev->mc_list_lock);
1239#ifdef CONFIG_IP_MULTICAST 1239#ifdef CONFIG_IP_MULTICAST
@@ -1279,7 +1279,7 @@ void ip_mc_dec_group(struct in_device *in_dev, __be32 addr)
1279 ASSERT_RTNL(); 1279 ASSERT_RTNL();
1280 1280
1281 for (ip=&in_dev->mc_list; (i=*ip)!=NULL; ip=&i->next) { 1281 for (ip=&in_dev->mc_list; (i=*ip)!=NULL; ip=&i->next) {
1282 if (i->multiaddr==addr) { 1282 if (i->multiaddr == addr) {
1283 if (--i->users == 0) { 1283 if (--i->users == 0) {
1284 write_lock_bh(&in_dev->mc_list_lock); 1284 write_lock_bh(&in_dev->mc_list_lock);
1285 *ip = i->next; 1285 *ip = i->next;
@@ -1738,7 +1738,7 @@ int ip_mc_join_group(struct sock *sk , struct ip_mreqn *imr)
1738{ 1738{
1739 int err; 1739 int err;
1740 __be32 addr = imr->imr_multiaddr.s_addr; 1740 __be32 addr = imr->imr_multiaddr.s_addr;
1741 struct ip_mc_socklist *iml=NULL, *i; 1741 struct ip_mc_socklist *iml = NULL, *i;
1742 struct in_device *in_dev; 1742 struct in_device *in_dev;
1743 struct inet_sock *inet = inet_sk(sk); 1743 struct inet_sock *inet = inet_sk(sk);
1744 struct net *net = sock_net(sk); 1744 struct net *net = sock_net(sk);
@@ -1769,7 +1769,7 @@ int ip_mc_join_group(struct sock *sk , struct ip_mreqn *imr)
1769 err = -ENOBUFS; 1769 err = -ENOBUFS;
1770 if (count >= sysctl_igmp_max_memberships) 1770 if (count >= sysctl_igmp_max_memberships)
1771 goto done; 1771 goto done;
1772 iml = sock_kmalloc(sk,sizeof(*iml),GFP_KERNEL); 1772 iml = sock_kmalloc(sk, sizeof(*iml), GFP_KERNEL);
1773 if (iml == NULL) 1773 if (iml == NULL)
1774 goto done; 1774 goto done;
1775 1775
@@ -2275,6 +2275,7 @@ int ip_check_mc(struct in_device *in_dev, __be32 mc_addr, __be32 src_addr, u16 p
2275 2275
2276#if defined(CONFIG_PROC_FS) 2276#if defined(CONFIG_PROC_FS)
2277struct igmp_mc_iter_state { 2277struct igmp_mc_iter_state {
2278 struct seq_net_private p;
2278 struct net_device *dev; 2279 struct net_device *dev;
2279 struct in_device *in_dev; 2280 struct in_device *in_dev;
2280}; 2281};
@@ -2283,11 +2284,12 @@ struct igmp_mc_iter_state {
2283 2284
2284static inline struct ip_mc_list *igmp_mc_get_first(struct seq_file *seq) 2285static inline struct ip_mc_list *igmp_mc_get_first(struct seq_file *seq)
2285{ 2286{
2287 struct net *net = seq_file_net(seq);
2286 struct ip_mc_list *im = NULL; 2288 struct ip_mc_list *im = NULL;
2287 struct igmp_mc_iter_state *state = igmp_mc_seq_private(seq); 2289 struct igmp_mc_iter_state *state = igmp_mc_seq_private(seq);
2288 2290
2289 state->in_dev = NULL; 2291 state->in_dev = NULL;
2290 for_each_netdev(&init_net, state->dev) { 2292 for_each_netdev(net, state->dev) {
2291 struct in_device *in_dev; 2293 struct in_device *in_dev;
2292 in_dev = in_dev_get(state->dev); 2294 in_dev = in_dev_get(state->dev);
2293 if (!in_dev) 2295 if (!in_dev)
@@ -2408,7 +2410,7 @@ static const struct seq_operations igmp_mc_seq_ops = {
2408 2410
2409static int igmp_mc_seq_open(struct inode *inode, struct file *file) 2411static int igmp_mc_seq_open(struct inode *inode, struct file *file)
2410{ 2412{
2411 return seq_open_private(file, &igmp_mc_seq_ops, 2413 return seq_open_net(inode, file, &igmp_mc_seq_ops,
2412 sizeof(struct igmp_mc_iter_state)); 2414 sizeof(struct igmp_mc_iter_state));
2413} 2415}
2414 2416
@@ -2417,10 +2419,11 @@ static const struct file_operations igmp_mc_seq_fops = {
2417 .open = igmp_mc_seq_open, 2419 .open = igmp_mc_seq_open,
2418 .read = seq_read, 2420 .read = seq_read,
2419 .llseek = seq_lseek, 2421 .llseek = seq_lseek,
2420 .release = seq_release_private, 2422 .release = seq_release_net,
2421}; 2423};
2422 2424
2423struct igmp_mcf_iter_state { 2425struct igmp_mcf_iter_state {
2426 struct seq_net_private p;
2424 struct net_device *dev; 2427 struct net_device *dev;
2425 struct in_device *idev; 2428 struct in_device *idev;
2426 struct ip_mc_list *im; 2429 struct ip_mc_list *im;
@@ -2430,13 +2433,14 @@ struct igmp_mcf_iter_state {
2430 2433
2431static inline struct ip_sf_list *igmp_mcf_get_first(struct seq_file *seq) 2434static inline struct ip_sf_list *igmp_mcf_get_first(struct seq_file *seq)
2432{ 2435{
2436 struct net *net = seq_file_net(seq);
2433 struct ip_sf_list *psf = NULL; 2437 struct ip_sf_list *psf = NULL;
2434 struct ip_mc_list *im = NULL; 2438 struct ip_mc_list *im = NULL;
2435 struct igmp_mcf_iter_state *state = igmp_mcf_seq_private(seq); 2439 struct igmp_mcf_iter_state *state = igmp_mcf_seq_private(seq);
2436 2440
2437 state->idev = NULL; 2441 state->idev = NULL;
2438 state->im = NULL; 2442 state->im = NULL;
2439 for_each_netdev(&init_net, state->dev) { 2443 for_each_netdev(net, state->dev) {
2440 struct in_device *idev; 2444 struct in_device *idev;
2441 idev = in_dev_get(state->dev); 2445 idev = in_dev_get(state->dev);
2442 if (unlikely(idev == NULL)) 2446 if (unlikely(idev == NULL))
@@ -2567,7 +2571,7 @@ static const struct seq_operations igmp_mcf_seq_ops = {
2567 2571
2568static int igmp_mcf_seq_open(struct inode *inode, struct file *file) 2572static int igmp_mcf_seq_open(struct inode *inode, struct file *file)
2569{ 2573{
2570 return seq_open_private(file, &igmp_mcf_seq_ops, 2574 return seq_open_net(inode, file, &igmp_mcf_seq_ops,
2571 sizeof(struct igmp_mcf_iter_state)); 2575 sizeof(struct igmp_mcf_iter_state));
2572} 2576}
2573 2577
@@ -2576,14 +2580,41 @@ static const struct file_operations igmp_mcf_seq_fops = {
2576 .open = igmp_mcf_seq_open, 2580 .open = igmp_mcf_seq_open,
2577 .read = seq_read, 2581 .read = seq_read,
2578 .llseek = seq_lseek, 2582 .llseek = seq_lseek,
2579 .release = seq_release_private, 2583 .release = seq_release_net,
2580}; 2584};
2581 2585
2582int __init igmp_mc_proc_init(void) 2586static int igmp_net_init(struct net *net)
2583{ 2587{
2584 proc_net_fops_create(&init_net, "igmp", S_IRUGO, &igmp_mc_seq_fops); 2588 struct proc_dir_entry *pde;
2585 proc_net_fops_create(&init_net, "mcfilter", S_IRUGO, &igmp_mcf_seq_fops); 2589
2590 pde = proc_net_fops_create(net, "igmp", S_IRUGO, &igmp_mc_seq_fops);
2591 if (!pde)
2592 goto out_igmp;
2593 pde = proc_net_fops_create(net, "mcfilter", S_IRUGO, &igmp_mcf_seq_fops);
2594 if (!pde)
2595 goto out_mcfilter;
2586 return 0; 2596 return 0;
2597
2598out_mcfilter:
2599 proc_net_remove(net, "igmp");
2600out_igmp:
2601 return -ENOMEM;
2602}
2603
2604static void igmp_net_exit(struct net *net)
2605{
2606 proc_net_remove(net, "mcfilter");
2607 proc_net_remove(net, "igmp");
2608}
2609
2610static struct pernet_operations igmp_net_ops = {
2611 .init = igmp_net_init,
2612 .exit = igmp_net_exit,
2613};
2614
2615int __init igmp_mc_proc_init(void)
2616{
2617 return register_pernet_subsys(&igmp_net_ops);
2587} 2618}
2588#endif 2619#endif
2589 2620
diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
index bd1278a2d828..c7cda1ca8e65 100644
--- a/net/ipv4/inet_connection_sock.c
+++ b/net/ipv4/inet_connection_sock.c
@@ -109,7 +109,7 @@ int inet_csk_get_port(struct sock *sk, unsigned short snum)
109 hashinfo->bhash_size)]; 109 hashinfo->bhash_size)];
110 spin_lock(&head->lock); 110 spin_lock(&head->lock);
111 inet_bind_bucket_for_each(tb, node, &head->chain) 111 inet_bind_bucket_for_each(tb, node, &head->chain)
112 if (tb->ib_net == net && tb->port == rover) 112 if (ib_net(tb) == net && tb->port == rover)
113 goto next; 113 goto next;
114 break; 114 break;
115 next: 115 next:
@@ -137,7 +137,7 @@ int inet_csk_get_port(struct sock *sk, unsigned short snum)
137 hashinfo->bhash_size)]; 137 hashinfo->bhash_size)];
138 spin_lock(&head->lock); 138 spin_lock(&head->lock);
139 inet_bind_bucket_for_each(tb, node, &head->chain) 139 inet_bind_bucket_for_each(tb, node, &head->chain)
140 if (tb->ib_net == net && tb->port == snum) 140 if (ib_net(tb) == net && tb->port == snum)
141 goto tb_found; 141 goto tb_found;
142 } 142 }
143 tb = NULL; 143 tb = NULL;
@@ -323,7 +323,7 @@ void inet_csk_reset_keepalive_timer(struct sock *sk, unsigned long len)
323 323
324EXPORT_SYMBOL(inet_csk_reset_keepalive_timer); 324EXPORT_SYMBOL(inet_csk_reset_keepalive_timer);
325 325
326struct dst_entry* inet_csk_route_req(struct sock *sk, 326struct dst_entry *inet_csk_route_req(struct sock *sk,
327 const struct request_sock *req) 327 const struct request_sock *req)
328{ 328{
329 struct rtable *rt; 329 struct rtable *rt;
@@ -344,16 +344,17 @@ struct dst_entry* inet_csk_route_req(struct sock *sk,
344 struct net *net = sock_net(sk); 344 struct net *net = sock_net(sk);
345 345
346 security_req_classify_flow(req, &fl); 346 security_req_classify_flow(req, &fl);
347 if (ip_route_output_flow(net, &rt, &fl, sk, 0)) { 347 if (ip_route_output_flow(net, &rt, &fl, sk, 0))
348 IP_INC_STATS_BH(net, IPSTATS_MIB_OUTNOROUTES); 348 goto no_route;
349 return NULL; 349 if (opt && opt->is_strictroute && rt->rt_dst != rt->rt_gateway)
350 } 350 goto route_err;
351 if (opt && opt->is_strictroute && rt->rt_dst != rt->rt_gateway) {
352 ip_rt_put(rt);
353 IP_INC_STATS_BH(net, IPSTATS_MIB_OUTNOROUTES);
354 return NULL;
355 }
356 return &rt->u.dst; 351 return &rt->u.dst;
352
353route_err:
354 ip_rt_put(rt);
355no_route:
356 IP_INC_STATS_BH(net, IPSTATS_MIB_OUTNOROUTES);
357 return NULL;
357} 358}
358 359
359EXPORT_SYMBOL_GPL(inet_csk_route_req); 360EXPORT_SYMBOL_GPL(inet_csk_route_req);
@@ -561,7 +562,7 @@ void inet_csk_destroy_sock(struct sock *sk)
561 562
562 sk_refcnt_debug_release(sk); 563 sk_refcnt_debug_release(sk);
563 564
564 atomic_dec(sk->sk_prot->orphan_count); 565 percpu_counter_dec(sk->sk_prot->orphan_count);
565 sock_put(sk); 566 sock_put(sk);
566} 567}
567 568
@@ -632,6 +633,8 @@ void inet_csk_listen_stop(struct sock *sk)
632 633
633 acc_req = req->dl_next; 634 acc_req = req->dl_next;
634 635
636 percpu_counter_inc(sk->sk_prot->orphan_count);
637
635 local_bh_disable(); 638 local_bh_disable();
636 bh_lock_sock(child); 639 bh_lock_sock(child);
637 WARN_ON(sock_owned_by_user(child)); 640 WARN_ON(sock_owned_by_user(child));
@@ -641,8 +644,6 @@ void inet_csk_listen_stop(struct sock *sk)
641 644
642 sock_orphan(child); 645 sock_orphan(child);
643 646
644 atomic_inc(sk->sk_prot->orphan_count);
645
646 inet_csk_destroy_sock(child); 647 inet_csk_destroy_sock(child);
647 648
648 bh_unlock_sock(child); 649 bh_unlock_sock(child);
diff --git a/net/ipv4/inet_diag.c b/net/ipv4/inet_diag.c
index 564230dabcb8..588a7796e3e3 100644
--- a/net/ipv4/inet_diag.c
+++ b/net/ipv4/inet_diag.c
@@ -718,13 +718,15 @@ static int inet_diag_dump(struct sk_buff *skb, struct netlink_callback *cb)
718 if (!(r->idiag_states & (TCPF_LISTEN | TCPF_SYN_RECV))) 718 if (!(r->idiag_states & (TCPF_LISTEN | TCPF_SYN_RECV)))
719 goto skip_listen_ht; 719 goto skip_listen_ht;
720 720
721 inet_listen_lock(hashinfo);
722 for (i = s_i; i < INET_LHTABLE_SIZE; i++) { 721 for (i = s_i; i < INET_LHTABLE_SIZE; i++) {
723 struct sock *sk; 722 struct sock *sk;
724 struct hlist_node *node; 723 struct hlist_nulls_node *node;
724 struct inet_listen_hashbucket *ilb;
725 725
726 num = 0; 726 num = 0;
727 sk_for_each(sk, node, &hashinfo->listening_hash[i]) { 727 ilb = &hashinfo->listening_hash[i];
728 spin_lock_bh(&ilb->lock);
729 sk_nulls_for_each(sk, node, &ilb->head) {
728 struct inet_sock *inet = inet_sk(sk); 730 struct inet_sock *inet = inet_sk(sk);
729 731
730 if (num < s_num) { 732 if (num < s_num) {
@@ -742,7 +744,7 @@ static int inet_diag_dump(struct sk_buff *skb, struct netlink_callback *cb)
742 goto syn_recv; 744 goto syn_recv;
743 745
744 if (inet_csk_diag_dump(sk, skb, cb) < 0) { 746 if (inet_csk_diag_dump(sk, skb, cb) < 0) {
745 inet_listen_unlock(hashinfo); 747 spin_unlock_bh(&ilb->lock);
746 goto done; 748 goto done;
747 } 749 }
748 750
@@ -751,7 +753,7 @@ syn_recv:
751 goto next_listen; 753 goto next_listen;
752 754
753 if (inet_diag_dump_reqs(skb, sk, cb) < 0) { 755 if (inet_diag_dump_reqs(skb, sk, cb) < 0) {
754 inet_listen_unlock(hashinfo); 756 spin_unlock_bh(&ilb->lock);
755 goto done; 757 goto done;
756 } 758 }
757 759
@@ -760,12 +762,12 @@ next_listen:
760 cb->args[4] = 0; 762 cb->args[4] = 0;
761 ++num; 763 ++num;
762 } 764 }
765 spin_unlock_bh(&ilb->lock);
763 766
764 s_num = 0; 767 s_num = 0;
765 cb->args[3] = 0; 768 cb->args[3] = 0;
766 cb->args[4] = 0; 769 cb->args[4] = 0;
767 } 770 }
768 inet_listen_unlock(hashinfo);
769skip_listen_ht: 771skip_listen_ht:
770 cb->args[0] = 1; 772 cb->args[0] = 1;
771 s_i = num = s_num = 0; 773 s_i = num = s_num = 0;
@@ -776,20 +778,21 @@ skip_listen_ht:
776 778
777 for (i = s_i; i < hashinfo->ehash_size; i++) { 779 for (i = s_i; i < hashinfo->ehash_size; i++) {
778 struct inet_ehash_bucket *head = &hashinfo->ehash[i]; 780 struct inet_ehash_bucket *head = &hashinfo->ehash[i];
779 rwlock_t *lock = inet_ehash_lockp(hashinfo, i); 781 spinlock_t *lock = inet_ehash_lockp(hashinfo, i);
780 struct sock *sk; 782 struct sock *sk;
781 struct hlist_node *node; 783 struct hlist_nulls_node *node;
782 784
783 num = 0; 785 num = 0;
784 786
785 if (hlist_empty(&head->chain) && hlist_empty(&head->twchain)) 787 if (hlist_nulls_empty(&head->chain) &&
788 hlist_nulls_empty(&head->twchain))
786 continue; 789 continue;
787 790
788 if (i > s_i) 791 if (i > s_i)
789 s_num = 0; 792 s_num = 0;
790 793
791 read_lock_bh(lock); 794 spin_lock_bh(lock);
792 sk_for_each(sk, node, &head->chain) { 795 sk_nulls_for_each(sk, node, &head->chain) {
793 struct inet_sock *inet = inet_sk(sk); 796 struct inet_sock *inet = inet_sk(sk);
794 797
795 if (num < s_num) 798 if (num < s_num)
@@ -803,7 +806,7 @@ skip_listen_ht:
803 r->id.idiag_dport) 806 r->id.idiag_dport)
804 goto next_normal; 807 goto next_normal;
805 if (inet_csk_diag_dump(sk, skb, cb) < 0) { 808 if (inet_csk_diag_dump(sk, skb, cb) < 0) {
806 read_unlock_bh(lock); 809 spin_unlock_bh(lock);
807 goto done; 810 goto done;
808 } 811 }
809next_normal: 812next_normal:
@@ -825,14 +828,14 @@ next_normal:
825 r->id.idiag_dport) 828 r->id.idiag_dport)
826 goto next_dying; 829 goto next_dying;
827 if (inet_twsk_diag_dump(tw, skb, cb) < 0) { 830 if (inet_twsk_diag_dump(tw, skb, cb) < 0) {
828 read_unlock_bh(lock); 831 spin_unlock_bh(lock);
829 goto done; 832 goto done;
830 } 833 }
831next_dying: 834next_dying:
832 ++num; 835 ++num;
833 } 836 }
834 } 837 }
835 read_unlock_bh(lock); 838 spin_unlock_bh(lock);
836 } 839 }
837 840
838done: 841done:
diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
index 44981906fb91..6a1045da48d2 100644
--- a/net/ipv4/inet_hashtables.c
+++ b/net/ipv4/inet_hashtables.c
@@ -35,7 +35,7 @@ struct inet_bind_bucket *inet_bind_bucket_create(struct kmem_cache *cachep,
35 struct inet_bind_bucket *tb = kmem_cache_alloc(cachep, GFP_ATOMIC); 35 struct inet_bind_bucket *tb = kmem_cache_alloc(cachep, GFP_ATOMIC);
36 36
37 if (tb != NULL) { 37 if (tb != NULL) {
38 tb->ib_net = hold_net(net); 38 write_pnet(&tb->ib_net, hold_net(net));
39 tb->port = snum; 39 tb->port = snum;
40 tb->fastreuse = 0; 40 tb->fastreuse = 0;
41 INIT_HLIST_HEAD(&tb->owners); 41 INIT_HLIST_HEAD(&tb->owners);
@@ -51,7 +51,7 @@ void inet_bind_bucket_destroy(struct kmem_cache *cachep, struct inet_bind_bucket
51{ 51{
52 if (hlist_empty(&tb->owners)) { 52 if (hlist_empty(&tb->owners)) {
53 __hlist_del(&tb->node); 53 __hlist_del(&tb->node);
54 release_net(tb->ib_net); 54 release_net(ib_net(tb));
55 kmem_cache_free(cachep, tb); 55 kmem_cache_free(cachep, tb);
56 } 56 }
57} 57}
@@ -110,33 +110,29 @@ void __inet_inherit_port(struct sock *sk, struct sock *child)
110 110
111EXPORT_SYMBOL_GPL(__inet_inherit_port); 111EXPORT_SYMBOL_GPL(__inet_inherit_port);
112 112
113/* 113static inline int compute_score(struct sock *sk, struct net *net,
114 * This lock without WQ_FLAG_EXCLUSIVE is good on UP and it can be very bad on SMP. 114 const unsigned short hnum, const __be32 daddr,
115 * Look, when several writers sleep and reader wakes them up, all but one 115 const int dif)
116 * immediately hit write lock and grab all the cpus. Exclusive sleep solves
117 * this, _but_ remember, it adds useless work on UP machines (wake up each
118 * exclusive lock release). It should be ifdefed really.
119 */
120void inet_listen_wlock(struct inet_hashinfo *hashinfo)
121 __acquires(hashinfo->lhash_lock)
122{ 116{
123 write_lock(&hashinfo->lhash_lock); 117 int score = -1;
124 118 struct inet_sock *inet = inet_sk(sk);
125 if (atomic_read(&hashinfo->lhash_users)) {
126 DEFINE_WAIT(wait);
127 119
128 for (;;) { 120 if (net_eq(sock_net(sk), net) && inet->num == hnum &&
129 prepare_to_wait_exclusive(&hashinfo->lhash_wait, 121 !ipv6_only_sock(sk)) {
130 &wait, TASK_UNINTERRUPTIBLE); 122 __be32 rcv_saddr = inet->rcv_saddr;
131 if (!atomic_read(&hashinfo->lhash_users)) 123 score = sk->sk_family == PF_INET ? 1 : 0;
132 break; 124 if (rcv_saddr) {
133 write_unlock_bh(&hashinfo->lhash_lock); 125 if (rcv_saddr != daddr)
134 schedule(); 126 return -1;
135 write_lock_bh(&hashinfo->lhash_lock); 127 score += 2;
128 }
129 if (sk->sk_bound_dev_if) {
130 if (sk->sk_bound_dev_if != dif)
131 return -1;
132 score += 2;
136 } 133 }
137
138 finish_wait(&hashinfo->lhash_wait, &wait);
139 } 134 }
135 return score;
140} 136}
141 137
142/* 138/*
@@ -145,72 +141,48 @@ void inet_listen_wlock(struct inet_hashinfo *hashinfo)
145 * remote address for the connection. So always assume those are both 141 * remote address for the connection. So always assume those are both
146 * wildcarded during the search since they can never be otherwise. 142 * wildcarded during the search since they can never be otherwise.
147 */ 143 */
148static struct sock *inet_lookup_listener_slow(struct net *net,
149 const struct hlist_head *head,
150 const __be32 daddr,
151 const unsigned short hnum,
152 const int dif)
153{
154 struct sock *result = NULL, *sk;
155 const struct hlist_node *node;
156 int hiscore = -1;
157
158 sk_for_each(sk, node, head) {
159 const struct inet_sock *inet = inet_sk(sk);
160
161 if (net_eq(sock_net(sk), net) && inet->num == hnum &&
162 !ipv6_only_sock(sk)) {
163 const __be32 rcv_saddr = inet->rcv_saddr;
164 int score = sk->sk_family == PF_INET ? 1 : 0;
165
166 if (rcv_saddr) {
167 if (rcv_saddr != daddr)
168 continue;
169 score += 2;
170 }
171 if (sk->sk_bound_dev_if) {
172 if (sk->sk_bound_dev_if != dif)
173 continue;
174 score += 2;
175 }
176 if (score == 5)
177 return sk;
178 if (score > hiscore) {
179 hiscore = score;
180 result = sk;
181 }
182 }
183 }
184 return result;
185}
186 144
187/* Optimize the common listener case. */ 145
188struct sock *__inet_lookup_listener(struct net *net, 146struct sock *__inet_lookup_listener(struct net *net,
189 struct inet_hashinfo *hashinfo, 147 struct inet_hashinfo *hashinfo,
190 const __be32 daddr, const unsigned short hnum, 148 const __be32 daddr, const unsigned short hnum,
191 const int dif) 149 const int dif)
192{ 150{
193 struct sock *sk = NULL; 151 struct sock *sk, *result;
194 const struct hlist_head *head; 152 struct hlist_nulls_node *node;
195 153 unsigned int hash = inet_lhashfn(net, hnum);
196 read_lock(&hashinfo->lhash_lock); 154 struct inet_listen_hashbucket *ilb = &hashinfo->listening_hash[hash];
197 head = &hashinfo->listening_hash[inet_lhashfn(net, hnum)]; 155 int score, hiscore;
198 if (!hlist_empty(head)) { 156
199 const struct inet_sock *inet = inet_sk((sk = __sk_head(head))); 157 rcu_read_lock();
200 158begin:
201 if (inet->num == hnum && !sk->sk_node.next && 159 result = NULL;
202 (!inet->rcv_saddr || inet->rcv_saddr == daddr) && 160 hiscore = -1;
203 (sk->sk_family == PF_INET || !ipv6_only_sock(sk)) && 161 sk_nulls_for_each_rcu(sk, node, &ilb->head) {
204 !sk->sk_bound_dev_if && net_eq(sock_net(sk), net)) 162 score = compute_score(sk, net, hnum, daddr, dif);
205 goto sherry_cache; 163 if (score > hiscore) {
206 sk = inet_lookup_listener_slow(net, head, daddr, hnum, dif); 164 result = sk;
165 hiscore = score;
166 }
207 } 167 }
208 if (sk) { 168 /*
209sherry_cache: 169 * if the nulls value we got at the end of this lookup is
210 sock_hold(sk); 170 * not the expected one, we must restart lookup.
171 * We probably met an item that was moved to another chain.
172 */
173 if (get_nulls_value(node) != hash + LISTENING_NULLS_BASE)
174 goto begin;
175 if (result) {
176 if (unlikely(!atomic_inc_not_zero(&result->sk_refcnt)))
177 result = NULL;
178 else if (unlikely(compute_score(result, net, hnum, daddr,
179 dif) < hiscore)) {
180 sock_put(result);
181 goto begin;
182 }
211 } 183 }
212 read_unlock(&hashinfo->lhash_lock); 184 rcu_read_unlock();
213 return sk; 185 return result;
214} 186}
215EXPORT_SYMBOL_GPL(__inet_lookup_listener); 187EXPORT_SYMBOL_GPL(__inet_lookup_listener);
216 188
@@ -223,35 +195,65 @@ struct sock * __inet_lookup_established(struct net *net,
223 INET_ADDR_COOKIE(acookie, saddr, daddr) 195 INET_ADDR_COOKIE(acookie, saddr, daddr)
224 const __portpair ports = INET_COMBINED_PORTS(sport, hnum); 196 const __portpair ports = INET_COMBINED_PORTS(sport, hnum);
225 struct sock *sk; 197 struct sock *sk;
226 const struct hlist_node *node; 198 const struct hlist_nulls_node *node;
227 /* Optimize here for direct hit, only listening connections can 199 /* Optimize here for direct hit, only listening connections can
228 * have wildcards anyways. 200 * have wildcards anyways.
229 */ 201 */
230 unsigned int hash = inet_ehashfn(net, daddr, hnum, saddr, sport); 202 unsigned int hash = inet_ehashfn(net, daddr, hnum, saddr, sport);
231 struct inet_ehash_bucket *head = inet_ehash_bucket(hashinfo, hash); 203 unsigned int slot = hash & (hashinfo->ehash_size - 1);
232 rwlock_t *lock = inet_ehash_lockp(hashinfo, hash); 204 struct inet_ehash_bucket *head = &hashinfo->ehash[slot];
233 205
234 prefetch(head->chain.first); 206 rcu_read_lock();
235 read_lock(lock); 207begin:
236 sk_for_each(sk, node, &head->chain) { 208 sk_nulls_for_each_rcu(sk, node, &head->chain) {
237 if (INET_MATCH(sk, net, hash, acookie, 209 if (INET_MATCH(sk, net, hash, acookie,
238 saddr, daddr, ports, dif)) 210 saddr, daddr, ports, dif)) {
239 goto hit; /* You sunk my battleship! */ 211 if (unlikely(!atomic_inc_not_zero(&sk->sk_refcnt)))
212 goto begintw;
213 if (unlikely(!INET_MATCH(sk, net, hash, acookie,
214 saddr, daddr, ports, dif))) {
215 sock_put(sk);
216 goto begin;
217 }
218 goto out;
219 }
240 } 220 }
221 /*
222 * if the nulls value we got at the end of this lookup is
223 * not the expected one, we must restart lookup.
224 * We probably met an item that was moved to another chain.
225 */
226 if (get_nulls_value(node) != slot)
227 goto begin;
241 228
229begintw:
242 /* Must check for a TIME_WAIT'er before going to listener hash. */ 230 /* Must check for a TIME_WAIT'er before going to listener hash. */
243 sk_for_each(sk, node, &head->twchain) { 231 sk_nulls_for_each_rcu(sk, node, &head->twchain) {
244 if (INET_TW_MATCH(sk, net, hash, acookie, 232 if (INET_TW_MATCH(sk, net, hash, acookie,
245 saddr, daddr, ports, dif)) 233 saddr, daddr, ports, dif)) {
246 goto hit; 234 if (unlikely(!atomic_inc_not_zero(&sk->sk_refcnt))) {
235 sk = NULL;
236 goto out;
237 }
238 if (unlikely(!INET_TW_MATCH(sk, net, hash, acookie,
239 saddr, daddr, ports, dif))) {
240 sock_put(sk);
241 goto begintw;
242 }
243 goto out;
244 }
247 } 245 }
246 /*
247 * if the nulls value we got at the end of this lookup is
248 * not the expected one, we must restart lookup.
249 * We probably met an item that was moved to another chain.
250 */
251 if (get_nulls_value(node) != slot)
252 goto begintw;
248 sk = NULL; 253 sk = NULL;
249out: 254out:
250 read_unlock(lock); 255 rcu_read_unlock();
251 return sk; 256 return sk;
252hit:
253 sock_hold(sk);
254 goto out;
255} 257}
256EXPORT_SYMBOL_GPL(__inet_lookup_established); 258EXPORT_SYMBOL_GPL(__inet_lookup_established);
257 259
@@ -270,16 +272,15 @@ static int __inet_check_established(struct inet_timewait_death_row *death_row,
270 struct net *net = sock_net(sk); 272 struct net *net = sock_net(sk);
271 unsigned int hash = inet_ehashfn(net, daddr, lport, saddr, inet->dport); 273 unsigned int hash = inet_ehashfn(net, daddr, lport, saddr, inet->dport);
272 struct inet_ehash_bucket *head = inet_ehash_bucket(hinfo, hash); 274 struct inet_ehash_bucket *head = inet_ehash_bucket(hinfo, hash);
273 rwlock_t *lock = inet_ehash_lockp(hinfo, hash); 275 spinlock_t *lock = inet_ehash_lockp(hinfo, hash);
274 struct sock *sk2; 276 struct sock *sk2;
275 const struct hlist_node *node; 277 const struct hlist_nulls_node *node;
276 struct inet_timewait_sock *tw; 278 struct inet_timewait_sock *tw;
277 279
278 prefetch(head->chain.first); 280 spin_lock(lock);
279 write_lock(lock);
280 281
281 /* Check TIME-WAIT sockets first. */ 282 /* Check TIME-WAIT sockets first. */
282 sk_for_each(sk2, node, &head->twchain) { 283 sk_nulls_for_each(sk2, node, &head->twchain) {
283 tw = inet_twsk(sk2); 284 tw = inet_twsk(sk2);
284 285
285 if (INET_TW_MATCH(sk2, net, hash, acookie, 286 if (INET_TW_MATCH(sk2, net, hash, acookie,
@@ -293,7 +294,7 @@ static int __inet_check_established(struct inet_timewait_death_row *death_row,
293 tw = NULL; 294 tw = NULL;
294 295
295 /* And established part... */ 296 /* And established part... */
296 sk_for_each(sk2, node, &head->chain) { 297 sk_nulls_for_each(sk2, node, &head->chain) {
297 if (INET_MATCH(sk2, net, hash, acookie, 298 if (INET_MATCH(sk2, net, hash, acookie,
298 saddr, daddr, ports, dif)) 299 saddr, daddr, ports, dif))
299 goto not_unique; 300 goto not_unique;
@@ -306,9 +307,9 @@ unique:
306 inet->sport = htons(lport); 307 inet->sport = htons(lport);
307 sk->sk_hash = hash; 308 sk->sk_hash = hash;
308 WARN_ON(!sk_unhashed(sk)); 309 WARN_ON(!sk_unhashed(sk));
309 __sk_add_node(sk, &head->chain); 310 __sk_nulls_add_node_rcu(sk, &head->chain);
311 spin_unlock(lock);
310 sock_prot_inuse_add(sock_net(sk), sk->sk_prot, 1); 312 sock_prot_inuse_add(sock_net(sk), sk->sk_prot, 1);
311 write_unlock(lock);
312 313
313 if (twp) { 314 if (twp) {
314 *twp = tw; 315 *twp = tw;
@@ -324,7 +325,7 @@ unique:
324 return 0; 325 return 0;
325 326
326not_unique: 327not_unique:
327 write_unlock(lock); 328 spin_unlock(lock);
328 return -EADDRNOTAVAIL; 329 return -EADDRNOTAVAIL;
329} 330}
330 331
@@ -338,8 +339,8 @@ static inline u32 inet_sk_port_offset(const struct sock *sk)
338void __inet_hash_nolisten(struct sock *sk) 339void __inet_hash_nolisten(struct sock *sk)
339{ 340{
340 struct inet_hashinfo *hashinfo = sk->sk_prot->h.hashinfo; 341 struct inet_hashinfo *hashinfo = sk->sk_prot->h.hashinfo;
341 struct hlist_head *list; 342 struct hlist_nulls_head *list;
342 rwlock_t *lock; 343 spinlock_t *lock;
343 struct inet_ehash_bucket *head; 344 struct inet_ehash_bucket *head;
344 345
345 WARN_ON(!sk_unhashed(sk)); 346 WARN_ON(!sk_unhashed(sk));
@@ -349,18 +350,17 @@ void __inet_hash_nolisten(struct sock *sk)
349 list = &head->chain; 350 list = &head->chain;
350 lock = inet_ehash_lockp(hashinfo, sk->sk_hash); 351 lock = inet_ehash_lockp(hashinfo, sk->sk_hash);
351 352
352 write_lock(lock); 353 spin_lock(lock);
353 __sk_add_node(sk, list); 354 __sk_nulls_add_node_rcu(sk, list);
355 spin_unlock(lock);
354 sock_prot_inuse_add(sock_net(sk), sk->sk_prot, 1); 356 sock_prot_inuse_add(sock_net(sk), sk->sk_prot, 1);
355 write_unlock(lock);
356} 357}
357EXPORT_SYMBOL_GPL(__inet_hash_nolisten); 358EXPORT_SYMBOL_GPL(__inet_hash_nolisten);
358 359
359static void __inet_hash(struct sock *sk) 360static void __inet_hash(struct sock *sk)
360{ 361{
361 struct inet_hashinfo *hashinfo = sk->sk_prot->h.hashinfo; 362 struct inet_hashinfo *hashinfo = sk->sk_prot->h.hashinfo;
362 struct hlist_head *list; 363 struct inet_listen_hashbucket *ilb;
363 rwlock_t *lock;
364 364
365 if (sk->sk_state != TCP_LISTEN) { 365 if (sk->sk_state != TCP_LISTEN) {
366 __inet_hash_nolisten(sk); 366 __inet_hash_nolisten(sk);
@@ -368,14 +368,12 @@ static void __inet_hash(struct sock *sk)
368 } 368 }
369 369
370 WARN_ON(!sk_unhashed(sk)); 370 WARN_ON(!sk_unhashed(sk));
371 list = &hashinfo->listening_hash[inet_sk_listen_hashfn(sk)]; 371 ilb = &hashinfo->listening_hash[inet_sk_listen_hashfn(sk)];
372 lock = &hashinfo->lhash_lock;
373 372
374 inet_listen_wlock(hashinfo); 373 spin_lock(&ilb->lock);
375 __sk_add_node(sk, list); 374 __sk_nulls_add_node_rcu(sk, &ilb->head);
376 sock_prot_inuse_add(sock_net(sk), sk->sk_prot, 1); 375 sock_prot_inuse_add(sock_net(sk), sk->sk_prot, 1);
377 write_unlock(lock); 376 spin_unlock(&ilb->lock);
378 wake_up(&hashinfo->lhash_wait);
379} 377}
380 378
381void inet_hash(struct sock *sk) 379void inet_hash(struct sock *sk)
@@ -390,27 +388,23 @@ EXPORT_SYMBOL_GPL(inet_hash);
390 388
391void inet_unhash(struct sock *sk) 389void inet_unhash(struct sock *sk)
392{ 390{
393 rwlock_t *lock;
394 struct inet_hashinfo *hashinfo = sk->sk_prot->h.hashinfo; 391 struct inet_hashinfo *hashinfo = sk->sk_prot->h.hashinfo;
392 spinlock_t *lock;
393 int done;
395 394
396 if (sk_unhashed(sk)) 395 if (sk_unhashed(sk))
397 goto out; 396 return;
398 397
399 if (sk->sk_state == TCP_LISTEN) { 398 if (sk->sk_state == TCP_LISTEN)
400 local_bh_disable(); 399 lock = &hashinfo->listening_hash[inet_sk_listen_hashfn(sk)].lock;
401 inet_listen_wlock(hashinfo); 400 else
402 lock = &hashinfo->lhash_lock;
403 } else {
404 lock = inet_ehash_lockp(hashinfo, sk->sk_hash); 401 lock = inet_ehash_lockp(hashinfo, sk->sk_hash);
405 write_lock_bh(lock);
406 }
407 402
408 if (__sk_del_node_init(sk)) 403 spin_lock_bh(lock);
404 done =__sk_nulls_del_node_init_rcu(sk);
405 if (done)
409 sock_prot_inuse_add(sock_net(sk), sk->sk_prot, -1); 406 sock_prot_inuse_add(sock_net(sk), sk->sk_prot, -1);
410 write_unlock_bh(lock); 407 spin_unlock_bh(lock);
411out:
412 if (sk->sk_state == TCP_LISTEN)
413 wake_up(&hashinfo->lhash_wait);
414} 408}
415EXPORT_SYMBOL_GPL(inet_unhash); 409EXPORT_SYMBOL_GPL(inet_unhash);
416 410
@@ -449,7 +443,7 @@ int __inet_hash_connect(struct inet_timewait_death_row *death_row,
449 * unique enough. 443 * unique enough.
450 */ 444 */
451 inet_bind_bucket_for_each(tb, node, &head->chain) { 445 inet_bind_bucket_for_each(tb, node, &head->chain) {
452 if (tb->ib_net == net && tb->port == port) { 446 if (ib_net(tb) == net && tb->port == port) {
453 WARN_ON(hlist_empty(&tb->owners)); 447 WARN_ON(hlist_empty(&tb->owners));
454 if (tb->fastreuse >= 0) 448 if (tb->fastreuse >= 0)
455 goto next_port; 449 goto next_port;
@@ -524,3 +518,16 @@ int inet_hash_connect(struct inet_timewait_death_row *death_row,
524} 518}
525 519
526EXPORT_SYMBOL_GPL(inet_hash_connect); 520EXPORT_SYMBOL_GPL(inet_hash_connect);
521
522void inet_hashinfo_init(struct inet_hashinfo *h)
523{
524 int i;
525
526 for (i = 0; i < INET_LHTABLE_SIZE; i++) {
527 spin_lock_init(&h->listening_hash[i].lock);
528 INIT_HLIST_NULLS_HEAD(&h->listening_hash[i].head,
529 i + LISTENING_NULLS_BASE);
530 }
531}
532
533EXPORT_SYMBOL_GPL(inet_hashinfo_init);
diff --git a/net/ipv4/inet_lro.c b/net/ipv4/inet_lro.c
index cfd034a2b96e..6a667dae315e 100644
--- a/net/ipv4/inet_lro.c
+++ b/net/ipv4/inet_lro.c
@@ -120,7 +120,7 @@ static void lro_update_tcp_ip_header(struct net_lro_desc *lro_desc)
120 iph->check = ip_fast_csum((u8 *)lro_desc->iph, iph->ihl); 120 iph->check = ip_fast_csum((u8 *)lro_desc->iph, iph->ihl);
121 121
122 tcph->check = 0; 122 tcph->check = 0;
123 tcp_hdr_csum = csum_partial((u8 *)tcph, TCP_HDR_LEN(tcph), 0); 123 tcp_hdr_csum = csum_partial(tcph, TCP_HDR_LEN(tcph), 0);
124 lro_desc->data_csum = csum_add(lro_desc->data_csum, tcp_hdr_csum); 124 lro_desc->data_csum = csum_add(lro_desc->data_csum, tcp_hdr_csum);
125 tcph->check = csum_tcpudp_magic(iph->saddr, iph->daddr, 125 tcph->check = csum_tcpudp_magic(iph->saddr, iph->daddr,
126 lro_desc->ip_tot_len - 126 lro_desc->ip_tot_len -
@@ -135,7 +135,7 @@ static __wsum lro_tcp_data_csum(struct iphdr *iph, struct tcphdr *tcph, int len)
135 __wsum tcp_ps_hdr_csum; 135 __wsum tcp_ps_hdr_csum;
136 136
137 tcp_csum = ~csum_unfold(tcph->check); 137 tcp_csum = ~csum_unfold(tcph->check);
138 tcp_hdr_csum = csum_partial((u8 *)tcph, TCP_HDR_LEN(tcph), tcp_csum); 138 tcp_hdr_csum = csum_partial(tcph, TCP_HDR_LEN(tcph), tcp_csum);
139 139
140 tcp_ps_hdr_csum = csum_tcpudp_nofold(iph->saddr, iph->daddr, 140 tcp_ps_hdr_csum = csum_tcpudp_nofold(iph->saddr, iph->daddr,
141 len + TCP_HDR_LEN(tcph), 141 len + TCP_HDR_LEN(tcph),
diff --git a/net/ipv4/inet_timewait_sock.c b/net/ipv4/inet_timewait_sock.c
index 1c5fd38f8824..8554d0ea1719 100644
--- a/net/ipv4/inet_timewait_sock.c
+++ b/net/ipv4/inet_timewait_sock.c
@@ -20,16 +20,16 @@ static void __inet_twsk_kill(struct inet_timewait_sock *tw,
20 struct inet_bind_hashbucket *bhead; 20 struct inet_bind_hashbucket *bhead;
21 struct inet_bind_bucket *tb; 21 struct inet_bind_bucket *tb;
22 /* Unlink from established hashes. */ 22 /* Unlink from established hashes. */
23 rwlock_t *lock = inet_ehash_lockp(hashinfo, tw->tw_hash); 23 spinlock_t *lock = inet_ehash_lockp(hashinfo, tw->tw_hash);
24 24
25 write_lock(lock); 25 spin_lock(lock);
26 if (hlist_unhashed(&tw->tw_node)) { 26 if (hlist_nulls_unhashed(&tw->tw_node)) {
27 write_unlock(lock); 27 spin_unlock(lock);
28 return; 28 return;
29 } 29 }
30 __hlist_del(&tw->tw_node); 30 hlist_nulls_del_rcu(&tw->tw_node);
31 sk_node_init(&tw->tw_node); 31 sk_nulls_node_init(&tw->tw_node);
32 write_unlock(lock); 32 spin_unlock(lock);
33 33
34 /* Disassociate with bind bucket. */ 34 /* Disassociate with bind bucket. */
35 bhead = &hashinfo->bhash[inet_bhashfn(twsk_net(tw), tw->tw_num, 35 bhead = &hashinfo->bhash[inet_bhashfn(twsk_net(tw), tw->tw_num,
@@ -76,7 +76,7 @@ void __inet_twsk_hashdance(struct inet_timewait_sock *tw, struct sock *sk,
76 const struct inet_sock *inet = inet_sk(sk); 76 const struct inet_sock *inet = inet_sk(sk);
77 const struct inet_connection_sock *icsk = inet_csk(sk); 77 const struct inet_connection_sock *icsk = inet_csk(sk);
78 struct inet_ehash_bucket *ehead = inet_ehash_bucket(hashinfo, sk->sk_hash); 78 struct inet_ehash_bucket *ehead = inet_ehash_bucket(hashinfo, sk->sk_hash);
79 rwlock_t *lock = inet_ehash_lockp(hashinfo, sk->sk_hash); 79 spinlock_t *lock = inet_ehash_lockp(hashinfo, sk->sk_hash);
80 struct inet_bind_hashbucket *bhead; 80 struct inet_bind_hashbucket *bhead;
81 /* Step 1: Put TW into bind hash. Original socket stays there too. 81 /* Step 1: Put TW into bind hash. Original socket stays there too.
82 Note, that any socket with inet->num != 0 MUST be bound in 82 Note, that any socket with inet->num != 0 MUST be bound in
@@ -90,17 +90,21 @@ void __inet_twsk_hashdance(struct inet_timewait_sock *tw, struct sock *sk,
90 inet_twsk_add_bind_node(tw, &tw->tw_tb->owners); 90 inet_twsk_add_bind_node(tw, &tw->tw_tb->owners);
91 spin_unlock(&bhead->lock); 91 spin_unlock(&bhead->lock);
92 92
93 write_lock(lock); 93 spin_lock(lock);
94 94
95 /* Step 2: Remove SK from established hash. */ 95 /*
96 if (__sk_del_node_init(sk)) 96 * Step 2: Hash TW into TIMEWAIT chain.
97 sock_prot_inuse_add(sock_net(sk), sk->sk_prot, -1); 97 * Should be done before removing sk from established chain
98 98 * because readers are lockless and search established first.
99 /* Step 3: Hash TW into TIMEWAIT chain. */ 99 */
100 inet_twsk_add_node(tw, &ehead->twchain);
101 atomic_inc(&tw->tw_refcnt); 100 atomic_inc(&tw->tw_refcnt);
101 inet_twsk_add_node_rcu(tw, &ehead->twchain);
102 102
103 write_unlock(lock); 103 /* Step 3: Remove SK from established hash. */
104 if (__sk_nulls_del_node_init_rcu(sk))
105 sock_prot_inuse_add(sock_net(sk), sk->sk_prot, -1);
106
107 spin_unlock(lock);
104} 108}
105 109
106EXPORT_SYMBOL_GPL(__inet_twsk_hashdance); 110EXPORT_SYMBOL_GPL(__inet_twsk_hashdance);
@@ -416,17 +420,17 @@ void inet_twsk_purge(struct net *net, struct inet_hashinfo *hashinfo,
416{ 420{
417 struct inet_timewait_sock *tw; 421 struct inet_timewait_sock *tw;
418 struct sock *sk; 422 struct sock *sk;
419 struct hlist_node *node; 423 struct hlist_nulls_node *node;
420 int h; 424 int h;
421 425
422 local_bh_disable(); 426 local_bh_disable();
423 for (h = 0; h < (hashinfo->ehash_size); h++) { 427 for (h = 0; h < (hashinfo->ehash_size); h++) {
424 struct inet_ehash_bucket *head = 428 struct inet_ehash_bucket *head =
425 inet_ehash_bucket(hashinfo, h); 429 inet_ehash_bucket(hashinfo, h);
426 rwlock_t *lock = inet_ehash_lockp(hashinfo, h); 430 spinlock_t *lock = inet_ehash_lockp(hashinfo, h);
427restart: 431restart:
428 write_lock(lock); 432 spin_lock(lock);
429 sk_for_each(sk, node, &head->twchain) { 433 sk_nulls_for_each(sk, node, &head->twchain) {
430 434
431 tw = inet_twsk(sk); 435 tw = inet_twsk(sk);
432 if (!net_eq(twsk_net(tw), net) || 436 if (!net_eq(twsk_net(tw), net) ||
@@ -434,13 +438,13 @@ restart:
434 continue; 438 continue;
435 439
436 atomic_inc(&tw->tw_refcnt); 440 atomic_inc(&tw->tw_refcnt);
437 write_unlock(lock); 441 spin_unlock(lock);
438 inet_twsk_deschedule(tw, twdr); 442 inet_twsk_deschedule(tw, twdr);
439 inet_twsk_put(tw); 443 inet_twsk_put(tw);
440 444
441 goto restart; 445 goto restart;
442 } 446 }
443 write_unlock(lock); 447 spin_unlock(lock);
444 } 448 }
445 local_bh_enable(); 449 local_bh_enable();
446} 450}
diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
index a456ceeac3f2..b1fbe18feb5a 100644
--- a/net/ipv4/inetpeer.c
+++ b/net/ipv4/inetpeer.c
@@ -144,7 +144,7 @@ static void unlink_from_unused(struct inet_peer *p)
144 * _stack is known to be NULL or not at compile time, 144 * _stack is known to be NULL or not at compile time,
145 * so compiler will optimize the if (_stack) tests. 145 * so compiler will optimize the if (_stack) tests.
146 */ 146 */
147#define lookup(_daddr,_stack) \ 147#define lookup(_daddr, _stack) \
148({ \ 148({ \
149 struct inet_peer *u, **v; \ 149 struct inet_peer *u, **v; \
150 if (_stack != NULL) { \ 150 if (_stack != NULL) { \
diff --git a/net/ipv4/ip_forward.c b/net/ipv4/ip_forward.c
index 450016b89a18..df3fe50bbf0d 100644
--- a/net/ipv4/ip_forward.c
+++ b/net/ipv4/ip_forward.c
@@ -106,7 +106,7 @@ int ip_forward(struct sk_buff *skb)
106 * We now generate an ICMP HOST REDIRECT giving the route 106 * We now generate an ICMP HOST REDIRECT giving the route
107 * we calculated. 107 * we calculated.
108 */ 108 */
109 if (rt->rt_flags&RTCF_DOREDIRECT && !opt->srr && !skb->sp) 109 if (rt->rt_flags&RTCF_DOREDIRECT && !opt->srr && !skb_sec_path(skb))
110 ip_rt_send_redirect(skb); 110 ip_rt_send_redirect(skb);
111 111
112 skb->priority = rt_tos2priority(iph->tos); 112 skb->priority = rt_tos2priority(iph->tos);
diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
index e4f81f54befe..6659ac000eeb 100644
--- a/net/ipv4/ip_fragment.c
+++ b/net/ipv4/ip_fragment.c
@@ -56,7 +56,7 @@ struct ipfrag_skb_cb
56 int offset; 56 int offset;
57}; 57};
58 58
59#define FRAG_CB(skb) ((struct ipfrag_skb_cb*)((skb)->cb)) 59#define FRAG_CB(skb) ((struct ipfrag_skb_cb *)((skb)->cb))
60 60
61/* Describe an entry in the "incomplete datagrams" queue. */ 61/* Describe an entry in the "incomplete datagrams" queue. */
62struct ipq { 62struct ipq {
@@ -559,9 +559,8 @@ out_nomem:
559 goto out_fail; 559 goto out_fail;
560out_oversize: 560out_oversize:
561 if (net_ratelimit()) 561 if (net_ratelimit())
562 printk(KERN_INFO 562 printk(KERN_INFO "Oversized IP packet from %pI4.\n",
563 "Oversized IP packet from " NIPQUAD_FMT ".\n", 563 &qp->saddr);
564 NIPQUAD(qp->saddr));
565out_fail: 564out_fail:
566 IP_INC_STATS_BH(dev_net(dev), IPSTATS_MIB_REASMFAILS); 565 IP_INC_STATS_BH(dev_net(dev), IPSTATS_MIB_REASMFAILS);
567 return err; 566 return err;
@@ -608,7 +607,7 @@ static struct ctl_table ip4_frags_ns_ctl_table[] = {
608 .data = &init_net.ipv4.frags.high_thresh, 607 .data = &init_net.ipv4.frags.high_thresh,
609 .maxlen = sizeof(int), 608 .maxlen = sizeof(int),
610 .mode = 0644, 609 .mode = 0644,
611 .proc_handler = &proc_dointvec 610 .proc_handler = proc_dointvec
612 }, 611 },
613 { 612 {
614 .ctl_name = NET_IPV4_IPFRAG_LOW_THRESH, 613 .ctl_name = NET_IPV4_IPFRAG_LOW_THRESH,
@@ -616,7 +615,7 @@ static struct ctl_table ip4_frags_ns_ctl_table[] = {
616 .data = &init_net.ipv4.frags.low_thresh, 615 .data = &init_net.ipv4.frags.low_thresh,
617 .maxlen = sizeof(int), 616 .maxlen = sizeof(int),
618 .mode = 0644, 617 .mode = 0644,
619 .proc_handler = &proc_dointvec 618 .proc_handler = proc_dointvec
620 }, 619 },
621 { 620 {
622 .ctl_name = NET_IPV4_IPFRAG_TIME, 621 .ctl_name = NET_IPV4_IPFRAG_TIME,
@@ -624,8 +623,8 @@ static struct ctl_table ip4_frags_ns_ctl_table[] = {
624 .data = &init_net.ipv4.frags.timeout, 623 .data = &init_net.ipv4.frags.timeout,
625 .maxlen = sizeof(int), 624 .maxlen = sizeof(int),
626 .mode = 0644, 625 .mode = 0644,
627 .proc_handler = &proc_dointvec_jiffies, 626 .proc_handler = proc_dointvec_jiffies,
628 .strategy = &sysctl_jiffies 627 .strategy = sysctl_jiffies
629 }, 628 },
630 { } 629 { }
631}; 630};
@@ -637,15 +636,15 @@ static struct ctl_table ip4_frags_ctl_table[] = {
637 .data = &ip4_frags.secret_interval, 636 .data = &ip4_frags.secret_interval,
638 .maxlen = sizeof(int), 637 .maxlen = sizeof(int),
639 .mode = 0644, 638 .mode = 0644,
640 .proc_handler = &proc_dointvec_jiffies, 639 .proc_handler = proc_dointvec_jiffies,
641 .strategy = &sysctl_jiffies 640 .strategy = sysctl_jiffies
642 }, 641 },
643 { 642 {
644 .procname = "ipfrag_max_dist", 643 .procname = "ipfrag_max_dist",
645 .data = &sysctl_ipfrag_max_dist, 644 .data = &sysctl_ipfrag_max_dist,
646 .maxlen = sizeof(int), 645 .maxlen = sizeof(int),
647 .mode = 0644, 646 .mode = 0644,
648 .proc_handler = &proc_dointvec_minmax, 647 .proc_handler = proc_dointvec_minmax,
649 .extra1 = &zero 648 .extra1 = &zero
650 }, 649 },
651 { } 650 { }
diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
index 85c487b8572b..0101521f366b 100644
--- a/net/ipv4/ip_gre.c
+++ b/net/ipv4/ip_gre.c
@@ -126,8 +126,6 @@ static int ipgre_tunnel_bind_dev(struct net_device *dev);
126 126
127/* Fallback tunnel: no source, no destination, no key, no options */ 127/* Fallback tunnel: no source, no destination, no key, no options */
128 128
129static int ipgre_fb_tunnel_init(struct net_device *dev);
130
131#define HASH_SIZE 16 129#define HASH_SIZE 16
132 130
133static int ipgre_net_id; 131static int ipgre_net_id;
@@ -371,7 +369,7 @@ static void ipgre_err(struct sk_buff *skb, u32 info)
371 by themself??? 369 by themself???
372 */ 370 */
373 371
374 struct iphdr *iph = (struct iphdr*)skb->data; 372 struct iphdr *iph = (struct iphdr *)skb->data;
375 __be16 *p = (__be16*)(skb->data+(iph->ihl<<2)); 373 __be16 *p = (__be16*)(skb->data+(iph->ihl<<2));
376 int grehlen = (iph->ihl<<2) + 4; 374 int grehlen = (iph->ihl<<2) + 4;
377 const int type = icmp_hdr(skb)->type; 375 const int type = icmp_hdr(skb)->type;
@@ -632,7 +630,7 @@ static int ipgre_tunnel_xmit(struct sk_buff *skb, struct net_device *dev)
632 630
633 if (dev->header_ops && dev->type == ARPHRD_IPGRE) { 631 if (dev->header_ops && dev->type == ARPHRD_IPGRE) {
634 gre_hlen = 0; 632 gre_hlen = 0;
635 tiph = (struct iphdr*)skb->data; 633 tiph = (struct iphdr *)skb->data;
636 } else { 634 } else {
637 gre_hlen = tunnel->hlen; 635 gre_hlen = tunnel->hlen;
638 tiph = &tunnel->parms.iph; 636 tiph = &tunnel->parms.iph;
@@ -660,7 +658,7 @@ static int ipgre_tunnel_xmit(struct sk_buff *skb, struct net_device *dev)
660 if (neigh == NULL) 658 if (neigh == NULL)
661 goto tx_error; 659 goto tx_error;
662 660
663 addr6 = (struct in6_addr*)&neigh->primary_key; 661 addr6 = (struct in6_addr *)&neigh->primary_key;
664 addr_type = ipv6_addr_type(addr6); 662 addr_type = ipv6_addr_type(addr6);
665 663
666 if (addr_type == IPV6_ADDR_ANY) { 664 if (addr_type == IPV6_ADDR_ANY) {
@@ -726,7 +724,7 @@ static int ipgre_tunnel_xmit(struct sk_buff *skb, struct net_device *dev)
726 } 724 }
727#ifdef CONFIG_IPV6 725#ifdef CONFIG_IPV6
728 else if (skb->protocol == htons(ETH_P_IPV6)) { 726 else if (skb->protocol == htons(ETH_P_IPV6)) {
729 struct rt6_info *rt6 = (struct rt6_info*)skb->dst; 727 struct rt6_info *rt6 = (struct rt6_info *)skb->dst;
730 728
731 if (rt6 && mtu < dst_mtu(skb->dst) && mtu >= IPV6_MIN_MTU) { 729 if (rt6 && mtu < dst_mtu(skb->dst) && mtu >= IPV6_MIN_MTU) {
732 if ((tunnel->parms.iph.daddr && 730 if ((tunnel->parms.iph.daddr &&
@@ -800,7 +798,7 @@ static int ipgre_tunnel_xmit(struct sk_buff *skb, struct net_device *dev)
800 iph->ttl = old_iph->ttl; 798 iph->ttl = old_iph->ttl;
801#ifdef CONFIG_IPV6 799#ifdef CONFIG_IPV6
802 else if (skb->protocol == htons(ETH_P_IPV6)) 800 else if (skb->protocol == htons(ETH_P_IPV6))
803 iph->ttl = ((struct ipv6hdr*)old_iph)->hop_limit; 801 iph->ttl = ((struct ipv6hdr *)old_iph)->hop_limit;
804#endif 802#endif
805 else 803 else
806 iph->ttl = dst_metric(&rt->u.dst, RTAX_HOPLIMIT); 804 iph->ttl = dst_metric(&rt->u.dst, RTAX_HOPLIMIT);
@@ -962,7 +960,7 @@ ipgre_tunnel_ioctl (struct net_device *dev, struct ifreq *ifr, int cmd)
962 break; 960 break;
963 } 961 }
964 } else { 962 } else {
965 unsigned nflags=0; 963 unsigned nflags = 0;
966 964
967 t = netdev_priv(dev); 965 t = netdev_priv(dev);
968 966
@@ -1104,7 +1102,7 @@ static int ipgre_header(struct sk_buff *skb, struct net_device *dev,
1104 1102
1105static int ipgre_header_parse(const struct sk_buff *skb, unsigned char *haddr) 1103static int ipgre_header_parse(const struct sk_buff *skb, unsigned char *haddr)
1106{ 1104{
1107 struct iphdr *iph = (struct iphdr*) skb_mac_header(skb); 1105 struct iphdr *iph = (struct iphdr *) skb_mac_header(skb);
1108 memcpy(haddr, &iph->saddr, 4); 1106 memcpy(haddr, &iph->saddr, 4);
1109 return 4; 1107 return 4;
1110} 1108}
@@ -1142,6 +1140,7 @@ static int ipgre_open(struct net_device *dev)
1142static int ipgre_close(struct net_device *dev) 1140static int ipgre_close(struct net_device *dev)
1143{ 1141{
1144 struct ip_tunnel *t = netdev_priv(dev); 1142 struct ip_tunnel *t = netdev_priv(dev);
1143
1145 if (ipv4_is_multicast(t->parms.iph.daddr) && t->mlink) { 1144 if (ipv4_is_multicast(t->parms.iph.daddr) && t->mlink) {
1146 struct in_device *in_dev; 1145 struct in_device *in_dev;
1147 in_dev = inetdev_by_index(dev_net(dev), t->mlink); 1146 in_dev = inetdev_by_index(dev_net(dev), t->mlink);
@@ -1155,14 +1154,22 @@ static int ipgre_close(struct net_device *dev)
1155 1154
1156#endif 1155#endif
1157 1156
1157static const struct net_device_ops ipgre_netdev_ops = {
1158 .ndo_init = ipgre_tunnel_init,
1159 .ndo_uninit = ipgre_tunnel_uninit,
1160#ifdef CONFIG_NET_IPGRE_BROADCAST
1161 .ndo_open = ipgre_open,
1162 .ndo_stop = ipgre_close,
1163#endif
1164 .ndo_start_xmit = ipgre_tunnel_xmit,
1165 .ndo_do_ioctl = ipgre_tunnel_ioctl,
1166 .ndo_change_mtu = ipgre_tunnel_change_mtu,
1167};
1168
1158static void ipgre_tunnel_setup(struct net_device *dev) 1169static void ipgre_tunnel_setup(struct net_device *dev)
1159{ 1170{
1160 dev->init = ipgre_tunnel_init; 1171 dev->netdev_ops = &ipgre_netdev_ops;
1161 dev->uninit = ipgre_tunnel_uninit;
1162 dev->destructor = free_netdev; 1172 dev->destructor = free_netdev;
1163 dev->hard_start_xmit = ipgre_tunnel_xmit;
1164 dev->do_ioctl = ipgre_tunnel_ioctl;
1165 dev->change_mtu = ipgre_tunnel_change_mtu;
1166 1173
1167 dev->type = ARPHRD_IPGRE; 1174 dev->type = ARPHRD_IPGRE;
1168 dev->needed_headroom = LL_MAX_HEADER + sizeof(struct iphdr) + 4; 1175 dev->needed_headroom = LL_MAX_HEADER + sizeof(struct iphdr) + 4;
@@ -1194,8 +1201,6 @@ static int ipgre_tunnel_init(struct net_device *dev)
1194 return -EINVAL; 1201 return -EINVAL;
1195 dev->flags = IFF_BROADCAST; 1202 dev->flags = IFF_BROADCAST;
1196 dev->header_ops = &ipgre_header_ops; 1203 dev->header_ops = &ipgre_header_ops;
1197 dev->open = ipgre_open;
1198 dev->stop = ipgre_close;
1199 } 1204 }
1200#endif 1205#endif
1201 } else 1206 } else
@@ -1204,7 +1209,7 @@ static int ipgre_tunnel_init(struct net_device *dev)
1204 return 0; 1209 return 0;
1205} 1210}
1206 1211
1207static int ipgre_fb_tunnel_init(struct net_device *dev) 1212static void ipgre_fb_tunnel_init(struct net_device *dev)
1208{ 1213{
1209 struct ip_tunnel *tunnel = netdev_priv(dev); 1214 struct ip_tunnel *tunnel = netdev_priv(dev);
1210 struct iphdr *iph = &tunnel->parms.iph; 1215 struct iphdr *iph = &tunnel->parms.iph;
@@ -1220,7 +1225,6 @@ static int ipgre_fb_tunnel_init(struct net_device *dev)
1220 1225
1221 dev_hold(dev); 1226 dev_hold(dev);
1222 ign->tunnels_wc[0] = tunnel; 1227 ign->tunnels_wc[0] = tunnel;
1223 return 0;
1224} 1228}
1225 1229
1226 1230
@@ -1264,9 +1268,9 @@ static int ipgre_init_net(struct net *net)
1264 err = -ENOMEM; 1268 err = -ENOMEM;
1265 goto err_alloc_dev; 1269 goto err_alloc_dev;
1266 } 1270 }
1267
1268 ign->fb_tunnel_dev->init = ipgre_fb_tunnel_init;
1269 dev_net_set(ign->fb_tunnel_dev, net); 1271 dev_net_set(ign->fb_tunnel_dev, net);
1272
1273 ipgre_fb_tunnel_init(ign->fb_tunnel_dev);
1270 ign->fb_tunnel_dev->rtnl_link_ops = &ipgre_link_ops; 1274 ign->fb_tunnel_dev->rtnl_link_ops = &ipgre_link_ops;
1271 1275
1272 if ((err = register_netdev(ign->fb_tunnel_dev))) 1276 if ((err = register_netdev(ign->fb_tunnel_dev)))
@@ -1397,16 +1401,22 @@ static int ipgre_tap_init(struct net_device *dev)
1397 return 0; 1401 return 0;
1398} 1402}
1399 1403
1404static const struct net_device_ops ipgre_tap_netdev_ops = {
1405 .ndo_init = ipgre_tap_init,
1406 .ndo_uninit = ipgre_tunnel_uninit,
1407 .ndo_start_xmit = ipgre_tunnel_xmit,
1408 .ndo_set_mac_address = eth_mac_addr,
1409 .ndo_validate_addr = eth_validate_addr,
1410 .ndo_change_mtu = ipgre_tunnel_change_mtu,
1411};
1412
1400static void ipgre_tap_setup(struct net_device *dev) 1413static void ipgre_tap_setup(struct net_device *dev)
1401{ 1414{
1402 1415
1403 ether_setup(dev); 1416 ether_setup(dev);
1404 1417
1405 dev->init = ipgre_tap_init; 1418 dev->netdev_ops = &ipgre_netdev_ops;
1406 dev->uninit = ipgre_tunnel_uninit;
1407 dev->destructor = free_netdev; 1419 dev->destructor = free_netdev;
1408 dev->hard_start_xmit = ipgre_tunnel_xmit;
1409 dev->change_mtu = ipgre_tunnel_change_mtu;
1410 1420
1411 dev->iflink = 0; 1421 dev->iflink = 0;
1412 dev->features |= NETIF_F_NETNS_LOCAL; 1422 dev->features |= NETIF_F_NETNS_LOCAL;
diff --git a/net/ipv4/ip_input.c b/net/ipv4/ip_input.c
index cfb38ac9d698..1a58a6fa1dc0 100644
--- a/net/ipv4/ip_input.c
+++ b/net/ipv4/ip_input.c
@@ -302,10 +302,8 @@ static inline int ip_rcv_options(struct sk_buff *skb)
302 if (!IN_DEV_SOURCE_ROUTE(in_dev)) { 302 if (!IN_DEV_SOURCE_ROUTE(in_dev)) {
303 if (IN_DEV_LOG_MARTIANS(in_dev) && 303 if (IN_DEV_LOG_MARTIANS(in_dev) &&
304 net_ratelimit()) 304 net_ratelimit())
305 printk(KERN_INFO "source route option " 305 printk(KERN_INFO "source route option %pI4 -> %pI4\n",
306 NIPQUAD_FMT " -> " NIPQUAD_FMT "\n", 306 &iph->saddr, &iph->daddr);
307 NIPQUAD(iph->saddr),
308 NIPQUAD(iph->daddr));
309 in_dev_put(in_dev); 307 in_dev_put(in_dev);
310 goto drop; 308 goto drop;
311 } 309 }
@@ -350,9 +348,9 @@ static int ip_rcv_finish(struct sk_buff *skb)
350 struct ip_rt_acct *st = per_cpu_ptr(ip_rt_acct, smp_processor_id()); 348 struct ip_rt_acct *st = per_cpu_ptr(ip_rt_acct, smp_processor_id());
351 u32 idx = skb->dst->tclassid; 349 u32 idx = skb->dst->tclassid;
352 st[idx&0xFF].o_packets++; 350 st[idx&0xFF].o_packets++;
353 st[idx&0xFF].o_bytes+=skb->len; 351 st[idx&0xFF].o_bytes += skb->len;
354 st[(idx>>16)&0xFF].i_packets++; 352 st[(idx>>16)&0xFF].i_packets++;
355 st[(idx>>16)&0xFF].i_bytes+=skb->len; 353 st[(idx>>16)&0xFF].i_bytes += skb->len;
356 } 354 }
357#endif 355#endif
358 356
diff --git a/net/ipv4/ip_output.c b/net/ipv4/ip_output.c
index d2a8f8bb78a6..8ebe86dd72af 100644
--- a/net/ipv4/ip_output.c
+++ b/net/ipv4/ip_output.c
@@ -430,7 +430,7 @@ static void ip_copy_metadata(struct sk_buff *to, struct sk_buff *from)
430 * single device frame, and queue such a frame for sending. 430 * single device frame, and queue such a frame for sending.
431 */ 431 */
432 432
433int ip_fragment(struct sk_buff *skb, int (*output)(struct sk_buff*)) 433int ip_fragment(struct sk_buff *skb, int (*output)(struct sk_buff *))
434{ 434{
435 struct iphdr *iph; 435 struct iphdr *iph;
436 int raw = 0; 436 int raw = 0;
@@ -720,7 +720,7 @@ static inline int ip_ufo_append_data(struct sock *sk,
720 int getfrag(void *from, char *to, int offset, int len, 720 int getfrag(void *from, char *to, int offset, int len,
721 int odd, struct sk_buff *skb), 721 int odd, struct sk_buff *skb),
722 void *from, int length, int hh_len, int fragheaderlen, 722 void *from, int length, int hh_len, int fragheaderlen,
723 int transhdrlen, int mtu,unsigned int flags) 723 int transhdrlen, int mtu, unsigned int flags)
724{ 724{
725 struct sk_buff *skb; 725 struct sk_buff *skb;
726 int err; 726 int err;
@@ -741,7 +741,7 @@ static inline int ip_ufo_append_data(struct sock *sk,
741 skb_reserve(skb, hh_len); 741 skb_reserve(skb, hh_len);
742 742
743 /* create space for UDP/IP header */ 743 /* create space for UDP/IP header */
744 skb_put(skb,fragheaderlen + transhdrlen); 744 skb_put(skb, fragheaderlen + transhdrlen);
745 745
746 /* initialize network header pointer */ 746 /* initialize network header pointer */
747 skb_reset_network_header(skb); 747 skb_reset_network_header(skb);
@@ -778,7 +778,7 @@ int ip_append_data(struct sock *sk,
778 int getfrag(void *from, char *to, int offset, int len, 778 int getfrag(void *from, char *to, int offset, int len,
779 int odd, struct sk_buff *skb), 779 int odd, struct sk_buff *skb),
780 void *from, int length, int transhdrlen, 780 void *from, int length, int transhdrlen,
781 struct ipcm_cookie *ipc, struct rtable *rt, 781 struct ipcm_cookie *ipc, struct rtable **rtp,
782 unsigned int flags) 782 unsigned int flags)
783{ 783{
784 struct inet_sock *inet = inet_sk(sk); 784 struct inet_sock *inet = inet_sk(sk);
@@ -793,6 +793,7 @@ int ip_append_data(struct sock *sk,
793 int offset = 0; 793 int offset = 0;
794 unsigned int maxfraglen, fragheaderlen; 794 unsigned int maxfraglen, fragheaderlen;
795 int csummode = CHECKSUM_NONE; 795 int csummode = CHECKSUM_NONE;
796 struct rtable *rt;
796 797
797 if (flags&MSG_PROBE) 798 if (flags&MSG_PROBE)
798 return 0; 799 return 0;
@@ -812,7 +813,11 @@ int ip_append_data(struct sock *sk,
812 inet->cork.flags |= IPCORK_OPT; 813 inet->cork.flags |= IPCORK_OPT;
813 inet->cork.addr = ipc->addr; 814 inet->cork.addr = ipc->addr;
814 } 815 }
815 dst_hold(&rt->u.dst); 816 rt = *rtp;
817 /*
818 * We steal reference to this route, caller should not release it
819 */
820 *rtp = NULL;
816 inet->cork.fragsize = mtu = inet->pmtudisc == IP_PMTUDISC_PROBE ? 821 inet->cork.fragsize = mtu = inet->pmtudisc == IP_PMTUDISC_PROBE ?
817 rt->u.dst.dev->mtu : 822 rt->u.dst.dev->mtu :
818 dst_mtu(rt->u.dst.path); 823 dst_mtu(rt->u.dst.path);
@@ -1279,7 +1284,12 @@ int ip_push_pending_frames(struct sock *sk)
1279 1284
1280 skb->priority = sk->sk_priority; 1285 skb->priority = sk->sk_priority;
1281 skb->mark = sk->sk_mark; 1286 skb->mark = sk->sk_mark;
1282 skb->dst = dst_clone(&rt->u.dst); 1287 /*
1288 * Steal rt from cork.dst to avoid a pair of atomic_inc/atomic_dec
1289 * on dst refcount
1290 */
1291 inet->cork.dst = NULL;
1292 skb->dst = &rt->u.dst;
1283 1293
1284 if (iph->protocol == IPPROTO_ICMP) 1294 if (iph->protocol == IPPROTO_ICMP)
1285 icmp_out_count(net, ((struct icmphdr *) 1295 icmp_out_count(net, ((struct icmphdr *)
@@ -1391,7 +1401,7 @@ void ip_send_reply(struct sock *sk, struct sk_buff *skb, struct ip_reply_arg *ar
1391 sk->sk_protocol = ip_hdr(skb)->protocol; 1401 sk->sk_protocol = ip_hdr(skb)->protocol;
1392 sk->sk_bound_dev_if = arg->bound_dev_if; 1402 sk->sk_bound_dev_if = arg->bound_dev_if;
1393 ip_append_data(sk, ip_reply_glue_bits, arg->iov->iov_base, len, 0, 1403 ip_append_data(sk, ip_reply_glue_bits, arg->iov->iov_base, len, 0,
1394 &ipc, rt, MSG_DONTWAIT); 1404 &ipc, &rt, MSG_DONTWAIT);
1395 if ((skb = skb_peek(&sk->sk_write_queue)) != NULL) { 1405 if ((skb = skb_peek(&sk->sk_write_queue)) != NULL) {
1396 if (arg->csumoffset >= 0) 1406 if (arg->csumoffset >= 0)
1397 *((__sum16 *)skb_transport_header(skb) + 1407 *((__sum16 *)skb_transport_header(skb) +
diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
index 465abf0a9869..43c05854d752 100644
--- a/net/ipv4/ip_sockglue.c
+++ b/net/ipv4/ip_sockglue.c
@@ -48,6 +48,7 @@
48#define IP_CMSG_RECVOPTS 8 48#define IP_CMSG_RECVOPTS 8
49#define IP_CMSG_RETOPTS 16 49#define IP_CMSG_RETOPTS 16
50#define IP_CMSG_PASSSEC 32 50#define IP_CMSG_PASSSEC 32
51#define IP_CMSG_ORIGDSTADDR 64
51 52
52/* 53/*
53 * SOL_IP control messages. 54 * SOL_IP control messages.
@@ -94,7 +95,7 @@ static void ip_cmsg_recv_opts(struct msghdr *msg, struct sk_buff *skb)
94static void ip_cmsg_recv_retopts(struct msghdr *msg, struct sk_buff *skb) 95static void ip_cmsg_recv_retopts(struct msghdr *msg, struct sk_buff *skb)
95{ 96{
96 unsigned char optbuf[sizeof(struct ip_options) + 40]; 97 unsigned char optbuf[sizeof(struct ip_options) + 40];
97 struct ip_options * opt = (struct ip_options*)optbuf; 98 struct ip_options * opt = (struct ip_options *)optbuf;
98 99
99 if (IPCB(skb)->opt.optlen == 0) 100 if (IPCB(skb)->opt.optlen == 0)
100 return; 101 return;
@@ -126,6 +127,27 @@ static void ip_cmsg_recv_security(struct msghdr *msg, struct sk_buff *skb)
126 security_release_secctx(secdata, seclen); 127 security_release_secctx(secdata, seclen);
127} 128}
128 129
130static void ip_cmsg_recv_dstaddr(struct msghdr *msg, struct sk_buff *skb)
131{
132 struct sockaddr_in sin;
133 struct iphdr *iph = ip_hdr(skb);
134 __be16 *ports = (__be16 *)skb_transport_header(skb);
135
136 if (skb_transport_offset(skb) + 4 > skb->len)
137 return;
138
139 /* All current transport protocols have the port numbers in the
140 * first four bytes of the transport header and this function is
141 * written with this assumption in mind.
142 */
143
144 sin.sin_family = AF_INET;
145 sin.sin_addr.s_addr = iph->daddr;
146 sin.sin_port = ports[1];
147 memset(sin.sin_zero, 0, sizeof(sin.sin_zero));
148
149 put_cmsg(msg, SOL_IP, IP_ORIGDSTADDR, sizeof(sin), &sin);
150}
129 151
130void ip_cmsg_recv(struct msghdr *msg, struct sk_buff *skb) 152void ip_cmsg_recv(struct msghdr *msg, struct sk_buff *skb)
131{ 153{
@@ -160,6 +182,12 @@ void ip_cmsg_recv(struct msghdr *msg, struct sk_buff *skb)
160 182
161 if (flags & 1) 183 if (flags & 1)
162 ip_cmsg_recv_security(msg, skb); 184 ip_cmsg_recv_security(msg, skb);
185
186 if ((flags>>=1) == 0)
187 return;
188 if (flags & 1)
189 ip_cmsg_recv_dstaddr(msg, skb);
190
163} 191}
164 192
165int ip_cmsg_send(struct net *net, struct msghdr *msg, struct ipcm_cookie *ipc) 193int ip_cmsg_send(struct net *net, struct msghdr *msg, struct ipcm_cookie *ipc)
@@ -411,7 +439,7 @@ static int do_ip_setsockopt(struct sock *sk, int level,
411 int optname, char __user *optval, int optlen) 439 int optname, char __user *optval, int optlen)
412{ 440{
413 struct inet_sock *inet = inet_sk(sk); 441 struct inet_sock *inet = inet_sk(sk);
414 int val=0,err; 442 int val = 0, err;
415 443
416 if (((1<<optname) & ((1<<IP_PKTINFO) | (1<<IP_RECVTTL) | 444 if (((1<<optname) & ((1<<IP_PKTINFO) | (1<<IP_RECVTTL) |
417 (1<<IP_RECVOPTS) | (1<<IP_RECVTOS) | 445 (1<<IP_RECVOPTS) | (1<<IP_RECVTOS) |
@@ -421,7 +449,8 @@ static int do_ip_setsockopt(struct sock *sk, int level,
421 (1<<IP_ROUTER_ALERT) | (1<<IP_FREEBIND) | 449 (1<<IP_ROUTER_ALERT) | (1<<IP_FREEBIND) |
422 (1<<IP_PASSSEC) | (1<<IP_TRANSPARENT))) || 450 (1<<IP_PASSSEC) | (1<<IP_TRANSPARENT))) ||
423 optname == IP_MULTICAST_TTL || 451 optname == IP_MULTICAST_TTL ||
424 optname == IP_MULTICAST_LOOP) { 452 optname == IP_MULTICAST_LOOP ||
453 optname == IP_RECVORIGDSTADDR) {
425 if (optlen >= sizeof(int)) { 454 if (optlen >= sizeof(int)) {
426 if (get_user(val, (int __user *) optval)) 455 if (get_user(val, (int __user *) optval))
427 return -EFAULT; 456 return -EFAULT;
@@ -437,7 +466,7 @@ static int do_ip_setsockopt(struct sock *sk, int level,
437 /* If optlen==0, it is equivalent to val == 0 */ 466 /* If optlen==0, it is equivalent to val == 0 */
438 467
439 if (ip_mroute_opt(optname)) 468 if (ip_mroute_opt(optname))
440 return ip_mroute_setsockopt(sk,optname,optval,optlen); 469 return ip_mroute_setsockopt(sk, optname, optval, optlen);
441 470
442 err = 0; 471 err = 0;
443 lock_sock(sk); 472 lock_sock(sk);
@@ -509,6 +538,12 @@ static int do_ip_setsockopt(struct sock *sk, int level,
509 else 538 else
510 inet->cmsg_flags &= ~IP_CMSG_PASSSEC; 539 inet->cmsg_flags &= ~IP_CMSG_PASSSEC;
511 break; 540 break;
541 case IP_RECVORIGDSTADDR:
542 if (val)
543 inet->cmsg_flags |= IP_CMSG_ORIGDSTADDR;
544 else
545 inet->cmsg_flags &= ~IP_CMSG_ORIGDSTADDR;
546 break;
512 case IP_TOS: /* This sets both TOS and Precedence */ 547 case IP_TOS: /* This sets both TOS and Precedence */
513 if (sk->sk_type == SOCK_STREAM) { 548 if (sk->sk_type == SOCK_STREAM) {
514 val &= ~3; 549 val &= ~3;
@@ -549,7 +584,7 @@ static int do_ip_setsockopt(struct sock *sk, int level,
549 goto e_inval; 584 goto e_inval;
550 if (optlen<1) 585 if (optlen<1)
551 goto e_inval; 586 goto e_inval;
552 if (val==-1) 587 if (val == -1)
553 val = 1; 588 val = 1;
554 if (val < 0 || val > 255) 589 if (val < 0 || val > 255)
555 goto e_inval; 590 goto e_inval;
@@ -573,12 +608,12 @@ static int do_ip_setsockopt(struct sock *sk, int level,
573 608
574 err = -EFAULT; 609 err = -EFAULT;
575 if (optlen >= sizeof(struct ip_mreqn)) { 610 if (optlen >= sizeof(struct ip_mreqn)) {
576 if (copy_from_user(&mreq,optval,sizeof(mreq))) 611 if (copy_from_user(&mreq, optval, sizeof(mreq)))
577 break; 612 break;
578 } else { 613 } else {
579 memset(&mreq, 0, sizeof(mreq)); 614 memset(&mreq, 0, sizeof(mreq));
580 if (optlen >= sizeof(struct in_addr) && 615 if (optlen >= sizeof(struct in_addr) &&
581 copy_from_user(&mreq.imr_address,optval,sizeof(struct in_addr))) 616 copy_from_user(&mreq.imr_address, optval, sizeof(struct in_addr)))
582 break; 617 break;
583 } 618 }
584 619
@@ -626,11 +661,11 @@ static int do_ip_setsockopt(struct sock *sk, int level,
626 goto e_inval; 661 goto e_inval;
627 err = -EFAULT; 662 err = -EFAULT;
628 if (optlen >= sizeof(struct ip_mreqn)) { 663 if (optlen >= sizeof(struct ip_mreqn)) {
629 if (copy_from_user(&mreq,optval,sizeof(mreq))) 664 if (copy_from_user(&mreq, optval, sizeof(mreq)))
630 break; 665 break;
631 } else { 666 } else {
632 memset(&mreq, 0, sizeof(mreq)); 667 memset(&mreq, 0, sizeof(mreq));
633 if (copy_from_user(&mreq,optval,sizeof(struct ip_mreq))) 668 if (copy_from_user(&mreq, optval, sizeof(struct ip_mreq)))
634 break; 669 break;
635 } 670 }
636 671
@@ -808,7 +843,7 @@ static int do_ip_setsockopt(struct sock *sk, int level,
808 err = -ENOBUFS; 843 err = -ENOBUFS;
809 break; 844 break;
810 } 845 }
811 gsf = kmalloc(optlen,GFP_KERNEL); 846 gsf = kmalloc(optlen, GFP_KERNEL);
812 if (!gsf) { 847 if (!gsf) {
813 err = -ENOBUFS; 848 err = -ENOBUFS;
814 break; 849 break;
@@ -828,7 +863,7 @@ static int do_ip_setsockopt(struct sock *sk, int level,
828 goto mc_msf_out; 863 goto mc_msf_out;
829 } 864 }
830 msize = IP_MSFILTER_SIZE(gsf->gf_numsrc); 865 msize = IP_MSFILTER_SIZE(gsf->gf_numsrc);
831 msf = kmalloc(msize,GFP_KERNEL); 866 msf = kmalloc(msize, GFP_KERNEL);
832 if (!msf) { 867 if (!msf) {
833 err = -ENOBUFS; 868 err = -ENOBUFS;
834 goto mc_msf_out; 869 goto mc_msf_out;
@@ -971,9 +1006,9 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
971 return -EOPNOTSUPP; 1006 return -EOPNOTSUPP;
972 1007
973 if (ip_mroute_opt(optname)) 1008 if (ip_mroute_opt(optname))
974 return ip_mroute_getsockopt(sk,optname,optval,optlen); 1009 return ip_mroute_getsockopt(sk, optname, optval, optlen);
975 1010
976 if (get_user(len,optlen)) 1011 if (get_user(len, optlen))
977 return -EFAULT; 1012 return -EFAULT;
978 if (len < 0) 1013 if (len < 0)
979 return -EINVAL; 1014 return -EINVAL;
@@ -984,7 +1019,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
984 case IP_OPTIONS: 1019 case IP_OPTIONS:
985 { 1020 {
986 unsigned char optbuf[sizeof(struct ip_options)+40]; 1021 unsigned char optbuf[sizeof(struct ip_options)+40];
987 struct ip_options * opt = (struct ip_options*)optbuf; 1022 struct ip_options * opt = (struct ip_options *)optbuf;
988 opt->optlen = 0; 1023 opt->optlen = 0;
989 if (inet->opt) 1024 if (inet->opt)
990 memcpy(optbuf, inet->opt, 1025 memcpy(optbuf, inet->opt,
@@ -1022,6 +1057,9 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
1022 case IP_PASSSEC: 1057 case IP_PASSSEC:
1023 val = (inet->cmsg_flags & IP_CMSG_PASSSEC) != 0; 1058 val = (inet->cmsg_flags & IP_CMSG_PASSSEC) != 0;
1024 break; 1059 break;
1060 case IP_RECVORIGDSTADDR:
1061 val = (inet->cmsg_flags & IP_CMSG_ORIGDSTADDR) != 0;
1062 break;
1025 case IP_TOS: 1063 case IP_TOS:
1026 val = inet->tos; 1064 val = inet->tos;
1027 break; 1065 break;
@@ -1154,13 +1192,13 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
1154 len = 1; 1192 len = 1;
1155 if (put_user(len, optlen)) 1193 if (put_user(len, optlen))
1156 return -EFAULT; 1194 return -EFAULT;
1157 if (copy_to_user(optval,&ucval,1)) 1195 if (copy_to_user(optval, &ucval, 1))
1158 return -EFAULT; 1196 return -EFAULT;
1159 } else { 1197 } else {
1160 len = min_t(unsigned int, sizeof(int), len); 1198 len = min_t(unsigned int, sizeof(int), len);
1161 if (put_user(len, optlen)) 1199 if (put_user(len, optlen))
1162 return -EFAULT; 1200 return -EFAULT;
1163 if (copy_to_user(optval,&val,len)) 1201 if (copy_to_user(optval, &val, len))
1164 return -EFAULT; 1202 return -EFAULT;
1165 } 1203 }
1166 return 0; 1204 return 0;
@@ -1178,7 +1216,7 @@ int ip_getsockopt(struct sock *sk, int level,
1178 !ip_mroute_opt(optname)) { 1216 !ip_mroute_opt(optname)) {
1179 int len; 1217 int len;
1180 1218
1181 if (get_user(len,optlen)) 1219 if (get_user(len, optlen))
1182 return -EFAULT; 1220 return -EFAULT;
1183 1221
1184 lock_sock(sk); 1222 lock_sock(sk);
diff --git a/net/ipv4/ipcomp.c b/net/ipv4/ipcomp.c
index 38ccb6dfb02e..3262ce06294c 100644
--- a/net/ipv4/ipcomp.c
+++ b/net/ipv4/ipcomp.c
@@ -35,12 +35,12 @@ static void ipcomp4_err(struct sk_buff *skb, u32 info)
35 return; 35 return;
36 36
37 spi = htonl(ntohs(ipch->cpi)); 37 spi = htonl(ntohs(ipch->cpi));
38 x = xfrm_state_lookup((xfrm_address_t *)&iph->daddr, 38 x = xfrm_state_lookup(&init_net, (xfrm_address_t *)&iph->daddr,
39 spi, IPPROTO_COMP, AF_INET); 39 spi, IPPROTO_COMP, AF_INET);
40 if (!x) 40 if (!x)
41 return; 41 return;
42 NETDEBUG(KERN_DEBUG "pmtu discovery on SA IPCOMP/%08x/" NIPQUAD_FMT "\n", 42 NETDEBUG(KERN_DEBUG "pmtu discovery on SA IPCOMP/%08x/%pI4\n",
43 spi, NIPQUAD(iph->daddr)); 43 spi, &iph->daddr);
44 xfrm_state_put(x); 44 xfrm_state_put(x);
45} 45}
46 46
@@ -49,7 +49,7 @@ static struct xfrm_state *ipcomp_tunnel_create(struct xfrm_state *x)
49{ 49{
50 struct xfrm_state *t; 50 struct xfrm_state *t;
51 51
52 t = xfrm_state_alloc(); 52 t = xfrm_state_alloc(&init_net);
53 if (t == NULL) 53 if (t == NULL)
54 goto out; 54 goto out;
55 55
@@ -85,7 +85,7 @@ static int ipcomp_tunnel_attach(struct xfrm_state *x)
85 int err = 0; 85 int err = 0;
86 struct xfrm_state *t; 86 struct xfrm_state *t;
87 87
88 t = xfrm_state_lookup((xfrm_address_t *)&x->id.daddr.a4, 88 t = xfrm_state_lookup(&init_net, (xfrm_address_t *)&x->id.daddr.a4,
89 x->props.saddr.a4, IPPROTO_IPIP, AF_INET); 89 x->props.saddr.a4, IPPROTO_IPIP, AF_INET);
90 if (!t) { 90 if (!t) {
91 t = ipcomp_tunnel_create(x); 91 t = ipcomp_tunnel_create(x);
diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
index 42065fff46c4..42a0f3dd3fd6 100644
--- a/net/ipv4/ipconfig.c
+++ b/net/ipv4/ipconfig.c
@@ -374,7 +374,7 @@ static int __init ic_defaults(void)
374 */ 374 */
375 375
376 if (!ic_host_name_set) 376 if (!ic_host_name_set)
377 sprintf(init_utsname()->nodename, NIPQUAD_FMT, NIPQUAD(ic_myaddr)); 377 sprintf(init_utsname()->nodename, "%pI4", &ic_myaddr);
378 378
379 if (root_server_addr == NONE) 379 if (root_server_addr == NONE)
380 root_server_addr = ic_servaddr; 380 root_server_addr = ic_servaddr;
@@ -387,11 +387,11 @@ static int __init ic_defaults(void)
387 else if (IN_CLASSC(ntohl(ic_myaddr))) 387 else if (IN_CLASSC(ntohl(ic_myaddr)))
388 ic_netmask = htonl(IN_CLASSC_NET); 388 ic_netmask = htonl(IN_CLASSC_NET);
389 else { 389 else {
390 printk(KERN_ERR "IP-Config: Unable to guess netmask for address " NIPQUAD_FMT "\n", 390 printk(KERN_ERR "IP-Config: Unable to guess netmask for address %pI4\n",
391 NIPQUAD(ic_myaddr)); 391 &ic_myaddr);
392 return -1; 392 return -1;
393 } 393 }
394 printk("IP-Config: Guessing netmask " NIPQUAD_FMT "\n", NIPQUAD(ic_netmask)); 394 printk("IP-Config: Guessing netmask %pI4\n", &ic_netmask);
395 } 395 }
396 396
397 return 0; 397 return 0;
@@ -979,10 +979,8 @@ static int __init ic_bootp_recv(struct sk_buff *skb, struct net_device *dev, str
979 ic_myaddr = b->your_ip; 979 ic_myaddr = b->your_ip;
980 ic_servaddr = server_id; 980 ic_servaddr = server_id;
981#ifdef IPCONFIG_DEBUG 981#ifdef IPCONFIG_DEBUG
982 printk("DHCP: Offered address " NIPQUAD_FMT, 982 printk("DHCP: Offered address %pI4 by server %pI4\n",
983 NIPQUAD(ic_myaddr)); 983 &ic_myaddr, &ic_servaddr);
984 printk(" by server " NIPQUAD_FMT "\n",
985 NIPQUAD(ic_servaddr));
986#endif 984#endif
987 /* The DHCP indicated server address takes 985 /* The DHCP indicated server address takes
988 * precedence over the bootp header one if 986 * precedence over the bootp header one if
@@ -1177,11 +1175,11 @@ static int __init ic_dynamic(void)
1177 return -1; 1175 return -1;
1178 } 1176 }
1179 1177
1180 printk("IP-Config: Got %s answer from " NIPQUAD_FMT ", ", 1178 printk("IP-Config: Got %s answer from %pI4, ",
1181 ((ic_got_reply & IC_RARP) ? "RARP" 1179 ((ic_got_reply & IC_RARP) ? "RARP"
1182 : (ic_proto_enabled & IC_USE_DHCP) ? "DHCP" : "BOOTP"), 1180 : (ic_proto_enabled & IC_USE_DHCP) ? "DHCP" : "BOOTP"),
1183 NIPQUAD(ic_servaddr)); 1181 &ic_servaddr);
1184 printk("my address is " NIPQUAD_FMT "\n", NIPQUAD(ic_myaddr)); 1182 printk("my address is %pI4\n", &ic_myaddr);
1185 1183
1186 return 0; 1184 return 0;
1187} 1185}
@@ -1206,14 +1204,12 @@ static int pnp_seq_show(struct seq_file *seq, void *v)
1206 "domain %s\n", ic_domain); 1204 "domain %s\n", ic_domain);
1207 for (i = 0; i < CONF_NAMESERVERS_MAX; i++) { 1205 for (i = 0; i < CONF_NAMESERVERS_MAX; i++) {
1208 if (ic_nameservers[i] != NONE) 1206 if (ic_nameservers[i] != NONE)
1209 seq_printf(seq, 1207 seq_printf(seq, "nameserver %pI4\n",
1210 "nameserver " NIPQUAD_FMT "\n", 1208 &ic_nameservers[i]);
1211 NIPQUAD(ic_nameservers[i]));
1212 } 1209 }
1213 if (ic_servaddr != NONE) 1210 if (ic_servaddr != NONE)
1214 seq_printf(seq, 1211 seq_printf(seq, "bootserver %pI4\n",
1215 "bootserver " NIPQUAD_FMT "\n", 1212 &ic_servaddr);
1216 NIPQUAD(ic_servaddr));
1217 return 0; 1213 return 0;
1218} 1214}
1219 1215
@@ -1387,13 +1383,13 @@ static int __init ip_auto_config(void)
1387 */ 1383 */
1388 printk("IP-Config: Complete:"); 1384 printk("IP-Config: Complete:");
1389 printk("\n device=%s", ic_dev->name); 1385 printk("\n device=%s", ic_dev->name);
1390 printk(", addr=" NIPQUAD_FMT, NIPQUAD(ic_myaddr)); 1386 printk(", addr=%pI4", &ic_myaddr);
1391 printk(", mask=" NIPQUAD_FMT, NIPQUAD(ic_netmask)); 1387 printk(", mask=%pI4", &ic_netmask);
1392 printk(", gw=" NIPQUAD_FMT, NIPQUAD(ic_gateway)); 1388 printk(", gw=%pI4", &ic_gateway);
1393 printk(",\n host=%s, domain=%s, nis-domain=%s", 1389 printk(",\n host=%s, domain=%s, nis-domain=%s",
1394 utsname()->nodename, ic_domain, utsname()->domainname); 1390 utsname()->nodename, ic_domain, utsname()->domainname);
1395 printk(",\n bootserver=" NIPQUAD_FMT, NIPQUAD(ic_servaddr)); 1391 printk(",\n bootserver=%pI4", &ic_servaddr);
1396 printk(", rootserver=" NIPQUAD_FMT, NIPQUAD(root_server_addr)); 1392 printk(", rootserver=%pI4", &root_server_addr);
1397 printk(", rootpath=%s", root_server_path); 1393 printk(", rootpath=%s", root_server_path);
1398 printk("\n"); 1394 printk("\n");
1399#endif /* !SILENT */ 1395#endif /* !SILENT */
diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c
index 29609d29df76..5079dfbc6f38 100644
--- a/net/ipv4/ipip.c
+++ b/net/ipv4/ipip.c
@@ -130,8 +130,8 @@ struct ipip_net {
130 struct net_device *fb_tunnel_dev; 130 struct net_device *fb_tunnel_dev;
131}; 131};
132 132
133static int ipip_fb_tunnel_init(struct net_device *dev); 133static void ipip_fb_tunnel_init(struct net_device *dev);
134static int ipip_tunnel_init(struct net_device *dev); 134static void ipip_tunnel_init(struct net_device *dev);
135static void ipip_tunnel_setup(struct net_device *dev); 135static void ipip_tunnel_setup(struct net_device *dev);
136 136
137static DEFINE_RWLOCK(ipip_lock); 137static DEFINE_RWLOCK(ipip_lock);
@@ -245,9 +245,10 @@ static struct ip_tunnel * ipip_tunnel_locate(struct net *net,
245 } 245 }
246 246
247 nt = netdev_priv(dev); 247 nt = netdev_priv(dev);
248 dev->init = ipip_tunnel_init;
249 nt->parms = *parms; 248 nt->parms = *parms;
250 249
250 ipip_tunnel_init(dev);
251
251 if (register_netdevice(dev) < 0) 252 if (register_netdevice(dev) < 0)
252 goto failed_free; 253 goto failed_free;
253 254
@@ -281,7 +282,7 @@ static int ipip_err(struct sk_buff *skb, u32 info)
281 8 bytes of packet payload. It means, that precise relaying of 282 8 bytes of packet payload. It means, that precise relaying of
282 ICMP in the real Internet is absolutely infeasible. 283 ICMP in the real Internet is absolutely infeasible.
283 */ 284 */
284 struct iphdr *iph = (struct iphdr*)skb->data; 285 struct iphdr *iph = (struct iphdr *)skb->data;
285 const int type = icmp_hdr(skb)->type; 286 const int type = icmp_hdr(skb)->type;
286 const int code = icmp_hdr(skb)->code; 287 const int code = icmp_hdr(skb)->code;
287 struct ip_tunnel *t; 288 struct ip_tunnel *t;
@@ -691,12 +692,17 @@ static int ipip_tunnel_change_mtu(struct net_device *dev, int new_mtu)
691 return 0; 692 return 0;
692} 693}
693 694
695static const struct net_device_ops ipip_netdev_ops = {
696 .ndo_uninit = ipip_tunnel_uninit,
697 .ndo_start_xmit = ipip_tunnel_xmit,
698 .ndo_do_ioctl = ipip_tunnel_ioctl,
699 .ndo_change_mtu = ipip_tunnel_change_mtu,
700
701};
702
694static void ipip_tunnel_setup(struct net_device *dev) 703static void ipip_tunnel_setup(struct net_device *dev)
695{ 704{
696 dev->uninit = ipip_tunnel_uninit; 705 dev->netdev_ops = &ipip_netdev_ops;
697 dev->hard_start_xmit = ipip_tunnel_xmit;
698 dev->do_ioctl = ipip_tunnel_ioctl;
699 dev->change_mtu = ipip_tunnel_change_mtu;
700 dev->destructor = free_netdev; 706 dev->destructor = free_netdev;
701 707
702 dev->type = ARPHRD_TUNNEL; 708 dev->type = ARPHRD_TUNNEL;
@@ -708,11 +714,9 @@ static void ipip_tunnel_setup(struct net_device *dev)
708 dev->features |= NETIF_F_NETNS_LOCAL; 714 dev->features |= NETIF_F_NETNS_LOCAL;
709} 715}
710 716
711static int ipip_tunnel_init(struct net_device *dev) 717static void ipip_tunnel_init(struct net_device *dev)
712{ 718{
713 struct ip_tunnel *tunnel; 719 struct ip_tunnel *tunnel = netdev_priv(dev);
714
715 tunnel = netdev_priv(dev);
716 720
717 tunnel->dev = dev; 721 tunnel->dev = dev;
718 strcpy(tunnel->parms.name, dev->name); 722 strcpy(tunnel->parms.name, dev->name);
@@ -721,11 +725,9 @@ static int ipip_tunnel_init(struct net_device *dev)
721 memcpy(dev->broadcast, &tunnel->parms.iph.daddr, 4); 725 memcpy(dev->broadcast, &tunnel->parms.iph.daddr, 4);
722 726
723 ipip_tunnel_bind_dev(dev); 727 ipip_tunnel_bind_dev(dev);
724
725 return 0;
726} 728}
727 729
728static int ipip_fb_tunnel_init(struct net_device *dev) 730static void ipip_fb_tunnel_init(struct net_device *dev)
729{ 731{
730 struct ip_tunnel *tunnel = netdev_priv(dev); 732 struct ip_tunnel *tunnel = netdev_priv(dev);
731 struct iphdr *iph = &tunnel->parms.iph; 733 struct iphdr *iph = &tunnel->parms.iph;
@@ -740,7 +742,6 @@ static int ipip_fb_tunnel_init(struct net_device *dev)
740 742
741 dev_hold(dev); 743 dev_hold(dev);
742 ipn->tunnels_wc[0] = tunnel; 744 ipn->tunnels_wc[0] = tunnel;
743 return 0;
744} 745}
745 746
746static struct xfrm_tunnel ipip_handler = { 747static struct xfrm_tunnel ipip_handler = {
@@ -792,10 +793,10 @@ static int ipip_init_net(struct net *net)
792 err = -ENOMEM; 793 err = -ENOMEM;
793 goto err_alloc_dev; 794 goto err_alloc_dev;
794 } 795 }
795
796 ipn->fb_tunnel_dev->init = ipip_fb_tunnel_init;
797 dev_net_set(ipn->fb_tunnel_dev, net); 796 dev_net_set(ipn->fb_tunnel_dev, net);
798 797
798 ipip_fb_tunnel_init(ipn->fb_tunnel_dev);
799
799 if ((err = register_netdev(ipn->fb_tunnel_dev))) 800 if ((err = register_netdev(ipn->fb_tunnel_dev)))
800 goto err_reg_dev; 801 goto err_reg_dev;
801 802
diff --git a/net/ipv4/ipmr.c b/net/ipv4/ipmr.c
index 25924b1eb2ef..14666449dc1c 100644
--- a/net/ipv4/ipmr.c
+++ b/net/ipv4/ipmr.c
@@ -124,8 +124,8 @@ static void ipmr_del_tunnel(struct net_device *dev, struct vifctl *v)
124 124
125 dev = __dev_get_by_name(&init_net, "tunl0"); 125 dev = __dev_get_by_name(&init_net, "tunl0");
126 if (dev) { 126 if (dev) {
127 const struct net_device_ops *ops = dev->netdev_ops;
127 struct ifreq ifr; 128 struct ifreq ifr;
128 mm_segment_t oldfs;
129 struct ip_tunnel_parm p; 129 struct ip_tunnel_parm p;
130 130
131 memset(&p, 0, sizeof(p)); 131 memset(&p, 0, sizeof(p));
@@ -137,9 +137,13 @@ static void ipmr_del_tunnel(struct net_device *dev, struct vifctl *v)
137 sprintf(p.name, "dvmrp%d", v->vifc_vifi); 137 sprintf(p.name, "dvmrp%d", v->vifc_vifi);
138 ifr.ifr_ifru.ifru_data = (__force void __user *)&p; 138 ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
139 139
140 oldfs = get_fs(); set_fs(KERNEL_DS); 140 if (ops->ndo_do_ioctl) {
141 dev->do_ioctl(dev, &ifr, SIOCDELTUNNEL); 141 mm_segment_t oldfs = get_fs();
142 set_fs(oldfs); 142
143 set_fs(KERNEL_DS);
144 ops->ndo_do_ioctl(dev, &ifr, SIOCDELTUNNEL);
145 set_fs(oldfs);
146 }
143 } 147 }
144} 148}
145 149
@@ -151,9 +155,9 @@ struct net_device *ipmr_new_tunnel(struct vifctl *v)
151 dev = __dev_get_by_name(&init_net, "tunl0"); 155 dev = __dev_get_by_name(&init_net, "tunl0");
152 156
153 if (dev) { 157 if (dev) {
158 const struct net_device_ops *ops = dev->netdev_ops;
154 int err; 159 int err;
155 struct ifreq ifr; 160 struct ifreq ifr;
156 mm_segment_t oldfs;
157 struct ip_tunnel_parm p; 161 struct ip_tunnel_parm p;
158 struct in_device *in_dev; 162 struct in_device *in_dev;
159 163
@@ -166,9 +170,14 @@ struct net_device *ipmr_new_tunnel(struct vifctl *v)
166 sprintf(p.name, "dvmrp%d", v->vifc_vifi); 170 sprintf(p.name, "dvmrp%d", v->vifc_vifi);
167 ifr.ifr_ifru.ifru_data = (__force void __user *)&p; 171 ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
168 172
169 oldfs = get_fs(); set_fs(KERNEL_DS); 173 if (ops->ndo_do_ioctl) {
170 err = dev->do_ioctl(dev, &ifr, SIOCADDTUNNEL); 174 mm_segment_t oldfs = get_fs();
171 set_fs(oldfs); 175
176 set_fs(KERNEL_DS);
177 err = ops->ndo_do_ioctl(dev, &ifr, SIOCADDTUNNEL);
178 set_fs(oldfs);
179 } else
180 err = -EOPNOTSUPP;
172 181
173 dev = NULL; 182 dev = NULL;
174 183
@@ -213,12 +222,16 @@ static int reg_vif_xmit(struct sk_buff *skb, struct net_device *dev)
213 return 0; 222 return 0;
214} 223}
215 224
225static const struct net_device_ops reg_vif_netdev_ops = {
226 .ndo_start_xmit = reg_vif_xmit,
227};
228
216static void reg_vif_setup(struct net_device *dev) 229static void reg_vif_setup(struct net_device *dev)
217{ 230{
218 dev->type = ARPHRD_PIMREG; 231 dev->type = ARPHRD_PIMREG;
219 dev->mtu = ETH_DATA_LEN - sizeof(struct iphdr) - 8; 232 dev->mtu = ETH_DATA_LEN - sizeof(struct iphdr) - 8;
220 dev->flags = IFF_NOARP; 233 dev->flags = IFF_NOARP;
221 dev->hard_start_xmit = reg_vif_xmit; 234 dev->netdev_ops = &reg_vif_netdev_ops,
222 dev->destructor = free_netdev; 235 dev->destructor = free_netdev;
223} 236}
224 237
@@ -331,7 +344,7 @@ static void ipmr_destroy_unres(struct mfc_cache *c)
331 344
332 atomic_dec(&cache_resolve_queue_len); 345 atomic_dec(&cache_resolve_queue_len);
333 346
334 while ((skb=skb_dequeue(&c->mfc_un.unres.unresolved))) { 347 while ((skb = skb_dequeue(&c->mfc_un.unres.unresolved))) {
335 if (ip_hdr(skb)->version == 0) { 348 if (ip_hdr(skb)->version == 0) {
336 struct nlmsghdr *nlh = (struct nlmsghdr *)skb_pull(skb, sizeof(struct iphdr)); 349 struct nlmsghdr *nlh = (struct nlmsghdr *)skb_pull(skb, sizeof(struct iphdr));
337 nlh->nlmsg_type = NLMSG_ERROR; 350 nlh->nlmsg_type = NLMSG_ERROR;
@@ -477,13 +490,13 @@ static int vif_add(struct vifctl *vifc, int mrtsock)
477 /* 490 /*
478 * Fill in the VIF structures 491 * Fill in the VIF structures
479 */ 492 */
480 v->rate_limit=vifc->vifc_rate_limit; 493 v->rate_limit = vifc->vifc_rate_limit;
481 v->local=vifc->vifc_lcl_addr.s_addr; 494 v->local = vifc->vifc_lcl_addr.s_addr;
482 v->remote=vifc->vifc_rmt_addr.s_addr; 495 v->remote = vifc->vifc_rmt_addr.s_addr;
483 v->flags=vifc->vifc_flags; 496 v->flags = vifc->vifc_flags;
484 if (!mrtsock) 497 if (!mrtsock)
485 v->flags |= VIFF_STATIC; 498 v->flags |= VIFF_STATIC;
486 v->threshold=vifc->vifc_threshold; 499 v->threshold = vifc->vifc_threshold;
487 v->bytes_in = 0; 500 v->bytes_in = 0;
488 v->bytes_out = 0; 501 v->bytes_out = 0;
489 v->pkt_in = 0; 502 v->pkt_in = 0;
@@ -494,7 +507,7 @@ static int vif_add(struct vifctl *vifc, int mrtsock)
494 507
495 /* And finish update writing critical data */ 508 /* And finish update writing critical data */
496 write_lock_bh(&mrt_lock); 509 write_lock_bh(&mrt_lock);
497 v->dev=dev; 510 v->dev = dev;
498#ifdef CONFIG_IP_PIMSM 511#ifdef CONFIG_IP_PIMSM
499 if (v->flags&VIFF_REGISTER) 512 if (v->flags&VIFF_REGISTER)
500 reg_vif_num = vifi; 513 reg_vif_num = vifi;
@@ -507,7 +520,7 @@ static int vif_add(struct vifctl *vifc, int mrtsock)
507 520
508static struct mfc_cache *ipmr_cache_find(__be32 origin, __be32 mcastgrp) 521static struct mfc_cache *ipmr_cache_find(__be32 origin, __be32 mcastgrp)
509{ 522{
510 int line=MFC_HASH(mcastgrp,origin); 523 int line = MFC_HASH(mcastgrp, origin);
511 struct mfc_cache *c; 524 struct mfc_cache *c;
512 525
513 for (c=mfc_cache_array[line]; c; c = c->next) { 526 for (c=mfc_cache_array[line]; c; c = c->next) {
@@ -522,8 +535,8 @@ static struct mfc_cache *ipmr_cache_find(__be32 origin, __be32 mcastgrp)
522 */ 535 */
523static struct mfc_cache *ipmr_cache_alloc(void) 536static struct mfc_cache *ipmr_cache_alloc(void)
524{ 537{
525 struct mfc_cache *c=kmem_cache_zalloc(mrt_cachep, GFP_KERNEL); 538 struct mfc_cache *c = kmem_cache_zalloc(mrt_cachep, GFP_KERNEL);
526 if (c==NULL) 539 if (c == NULL)
527 return NULL; 540 return NULL;
528 c->mfc_un.res.minvif = MAXVIFS; 541 c->mfc_un.res.minvif = MAXVIFS;
529 return c; 542 return c;
@@ -531,8 +544,8 @@ static struct mfc_cache *ipmr_cache_alloc(void)
531 544
532static struct mfc_cache *ipmr_cache_alloc_unres(void) 545static struct mfc_cache *ipmr_cache_alloc_unres(void)
533{ 546{
534 struct mfc_cache *c=kmem_cache_zalloc(mrt_cachep, GFP_ATOMIC); 547 struct mfc_cache *c = kmem_cache_zalloc(mrt_cachep, GFP_ATOMIC);
535 if (c==NULL) 548 if (c == NULL)
536 return NULL; 549 return NULL;
537 skb_queue_head_init(&c->mfc_un.unres.unresolved); 550 skb_queue_head_init(&c->mfc_un.unres.unresolved);
538 c->mfc_un.unres.expires = jiffies + 10*HZ; 551 c->mfc_un.unres.expires = jiffies + 10*HZ;
@@ -552,7 +565,7 @@ static void ipmr_cache_resolve(struct mfc_cache *uc, struct mfc_cache *c)
552 * Play the pending entries through our router 565 * Play the pending entries through our router
553 */ 566 */
554 567
555 while ((skb=__skb_dequeue(&uc->mfc_un.unres.unresolved))) { 568 while ((skb = __skb_dequeue(&uc->mfc_un.unres.unresolved))) {
556 if (ip_hdr(skb)->version == 0) { 569 if (ip_hdr(skb)->version == 0) {
557 struct nlmsghdr *nlh = (struct nlmsghdr *)skb_pull(skb, sizeof(struct iphdr)); 570 struct nlmsghdr *nlh = (struct nlmsghdr *)skb_pull(skb, sizeof(struct iphdr));
558 571
@@ -637,7 +650,7 @@ static int ipmr_cache_report(struct sk_buff *pkt, vifi_t vifi, int assert)
637 * Add our header 650 * Add our header
638 */ 651 */
639 652
640 igmp=(struct igmphdr *)skb_put(skb,sizeof(struct igmphdr)); 653 igmp=(struct igmphdr *)skb_put(skb, sizeof(struct igmphdr));
641 igmp->type = 654 igmp->type =
642 msg->im_msgtype = assert; 655 msg->im_msgtype = assert;
643 igmp->code = 0; 656 igmp->code = 0;
@@ -653,7 +666,7 @@ static int ipmr_cache_report(struct sk_buff *pkt, vifi_t vifi, int assert)
653 /* 666 /*
654 * Deliver to mrouted 667 * Deliver to mrouted
655 */ 668 */
656 if ((ret=sock_queue_rcv_skb(mroute_socket,skb))<0) { 669 if ((ret = sock_queue_rcv_skb(mroute_socket, skb))<0) {
657 if (net_ratelimit()) 670 if (net_ratelimit())
658 printk(KERN_WARNING "mroute: pending queue full, dropping entries.\n"); 671 printk(KERN_WARNING "mroute: pending queue full, dropping entries.\n");
659 kfree_skb(skb); 672 kfree_skb(skb);
@@ -685,7 +698,7 @@ ipmr_cache_unresolved(vifi_t vifi, struct sk_buff *skb)
685 * Create a new entry if allowable 698 * Create a new entry if allowable
686 */ 699 */
687 700
688 if (atomic_read(&cache_resolve_queue_len)>=10 || 701 if (atomic_read(&cache_resolve_queue_len) >= 10 ||
689 (c=ipmr_cache_alloc_unres())==NULL) { 702 (c=ipmr_cache_alloc_unres())==NULL) {
690 spin_unlock_bh(&mfc_unres_lock); 703 spin_unlock_bh(&mfc_unres_lock);
691 704
@@ -728,7 +741,7 @@ ipmr_cache_unresolved(vifi_t vifi, struct sk_buff *skb)
728 kfree_skb(skb); 741 kfree_skb(skb);
729 err = -ENOBUFS; 742 err = -ENOBUFS;
730 } else { 743 } else {
731 skb_queue_tail(&c->mfc_un.unres.unresolved,skb); 744 skb_queue_tail(&c->mfc_un.unres.unresolved, skb);
732 err = 0; 745 err = 0;
733 } 746 }
734 747
@@ -745,7 +758,7 @@ static int ipmr_mfc_delete(struct mfcctl *mfc)
745 int line; 758 int line;
746 struct mfc_cache *c, **cp; 759 struct mfc_cache *c, **cp;
747 760
748 line=MFC_HASH(mfc->mfcc_mcastgrp.s_addr, mfc->mfcc_origin.s_addr); 761 line = MFC_HASH(mfc->mfcc_mcastgrp.s_addr, mfc->mfcc_origin.s_addr);
749 762
750 for (cp=&mfc_cache_array[line]; (c=*cp) != NULL; cp = &c->next) { 763 for (cp=&mfc_cache_array[line]; (c=*cp) != NULL; cp = &c->next) {
751 if (c->mfc_origin == mfc->mfcc_origin.s_addr && 764 if (c->mfc_origin == mfc->mfcc_origin.s_addr &&
@@ -766,7 +779,7 @@ static int ipmr_mfc_add(struct mfcctl *mfc, int mrtsock)
766 int line; 779 int line;
767 struct mfc_cache *uc, *c, **cp; 780 struct mfc_cache *uc, *c, **cp;
768 781
769 line=MFC_HASH(mfc->mfcc_mcastgrp.s_addr, mfc->mfcc_origin.s_addr); 782 line = MFC_HASH(mfc->mfcc_mcastgrp.s_addr, mfc->mfcc_origin.s_addr);
770 783
771 for (cp=&mfc_cache_array[line]; (c=*cp) != NULL; cp = &c->next) { 784 for (cp=&mfc_cache_array[line]; (c=*cp) != NULL; cp = &c->next) {
772 if (c->mfc_origin == mfc->mfcc_origin.s_addr && 785 if (c->mfc_origin == mfc->mfcc_origin.s_addr &&
@@ -787,13 +800,13 @@ static int ipmr_mfc_add(struct mfcctl *mfc, int mrtsock)
787 if (!ipv4_is_multicast(mfc->mfcc_mcastgrp.s_addr)) 800 if (!ipv4_is_multicast(mfc->mfcc_mcastgrp.s_addr))
788 return -EINVAL; 801 return -EINVAL;
789 802
790 c=ipmr_cache_alloc(); 803 c = ipmr_cache_alloc();
791 if (c==NULL) 804 if (c == NULL)
792 return -ENOMEM; 805 return -ENOMEM;
793 806
794 c->mfc_origin=mfc->mfcc_origin.s_addr; 807 c->mfc_origin = mfc->mfcc_origin.s_addr;
795 c->mfc_mcastgrp=mfc->mfcc_mcastgrp.s_addr; 808 c->mfc_mcastgrp = mfc->mfcc_mcastgrp.s_addr;
796 c->mfc_parent=mfc->mfcc_parent; 809 c->mfc_parent = mfc->mfcc_parent;
797 ipmr_update_thresholds(c, mfc->mfcc_ttls); 810 ipmr_update_thresholds(c, mfc->mfcc_ttls);
798 if (!mrtsock) 811 if (!mrtsock)
799 c->mfc_flags |= MFC_STATIC; 812 c->mfc_flags |= MFC_STATIC;
@@ -846,7 +859,7 @@ static void mroute_clean_tables(struct sock *sk)
846 /* 859 /*
847 * Wipe the cache 860 * Wipe the cache
848 */ 861 */
849 for (i=0;i<MFC_LINES;i++) { 862 for (i=0; i<MFC_LINES; i++) {
850 struct mfc_cache *c, **cp; 863 struct mfc_cache *c, **cp;
851 864
852 cp = &mfc_cache_array[i]; 865 cp = &mfc_cache_array[i];
@@ -887,7 +900,7 @@ static void mrtsock_destruct(struct sock *sk)
887 IPV4_DEVCONF_ALL(sock_net(sk), MC_FORWARDING)--; 900 IPV4_DEVCONF_ALL(sock_net(sk), MC_FORWARDING)--;
888 901
889 write_lock_bh(&mrt_lock); 902 write_lock_bh(&mrt_lock);
890 mroute_socket=NULL; 903 mroute_socket = NULL;
891 write_unlock_bh(&mrt_lock); 904 write_unlock_bh(&mrt_lock);
892 905
893 mroute_clean_tables(sk); 906 mroute_clean_tables(sk);
@@ -902,7 +915,7 @@ static void mrtsock_destruct(struct sock *sk)
902 * MOSPF/PIM router set up we can clean this up. 915 * MOSPF/PIM router set up we can clean this up.
903 */ 916 */
904 917
905int ip_mroute_setsockopt(struct sock *sk,int optname,char __user *optval,int optlen) 918int ip_mroute_setsockopt(struct sock *sk, int optname, char __user *optval, int optlen)
906{ 919{
907 int ret; 920 int ret;
908 struct vifctl vif; 921 struct vifctl vif;
@@ -918,7 +931,7 @@ int ip_mroute_setsockopt(struct sock *sk,int optname,char __user *optval,int opt
918 if (sk->sk_type != SOCK_RAW || 931 if (sk->sk_type != SOCK_RAW ||
919 inet_sk(sk)->num != IPPROTO_IGMP) 932 inet_sk(sk)->num != IPPROTO_IGMP)
920 return -EOPNOTSUPP; 933 return -EOPNOTSUPP;
921 if (optlen!=sizeof(int)) 934 if (optlen != sizeof(int))
922 return -ENOPROTOOPT; 935 return -ENOPROTOOPT;
923 936
924 rtnl_lock(); 937 rtnl_lock();
@@ -930,7 +943,7 @@ int ip_mroute_setsockopt(struct sock *sk,int optname,char __user *optval,int opt
930 ret = ip_ra_control(sk, 1, mrtsock_destruct); 943 ret = ip_ra_control(sk, 1, mrtsock_destruct);
931 if (ret == 0) { 944 if (ret == 0) {
932 write_lock_bh(&mrt_lock); 945 write_lock_bh(&mrt_lock);
933 mroute_socket=sk; 946 mroute_socket = sk;
934 write_unlock_bh(&mrt_lock); 947 write_unlock_bh(&mrt_lock);
935 948
936 IPV4_DEVCONF_ALL(sock_net(sk), MC_FORWARDING)++; 949 IPV4_DEVCONF_ALL(sock_net(sk), MC_FORWARDING)++;
@@ -938,19 +951,19 @@ int ip_mroute_setsockopt(struct sock *sk,int optname,char __user *optval,int opt
938 rtnl_unlock(); 951 rtnl_unlock();
939 return ret; 952 return ret;
940 case MRT_DONE: 953 case MRT_DONE:
941 if (sk!=mroute_socket) 954 if (sk != mroute_socket)
942 return -EACCES; 955 return -EACCES;
943 return ip_ra_control(sk, 0, NULL); 956 return ip_ra_control(sk, 0, NULL);
944 case MRT_ADD_VIF: 957 case MRT_ADD_VIF:
945 case MRT_DEL_VIF: 958 case MRT_DEL_VIF:
946 if (optlen!=sizeof(vif)) 959 if (optlen != sizeof(vif))
947 return -EINVAL; 960 return -EINVAL;
948 if (copy_from_user(&vif,optval,sizeof(vif))) 961 if (copy_from_user(&vif, optval, sizeof(vif)))
949 return -EFAULT; 962 return -EFAULT;
950 if (vif.vifc_vifi >= MAXVIFS) 963 if (vif.vifc_vifi >= MAXVIFS)
951 return -ENFILE; 964 return -ENFILE;
952 rtnl_lock(); 965 rtnl_lock();
953 if (optname==MRT_ADD_VIF) { 966 if (optname == MRT_ADD_VIF) {
954 ret = vif_add(&vif, sk==mroute_socket); 967 ret = vif_add(&vif, sk==mroute_socket);
955 } else { 968 } else {
956 ret = vif_delete(vif.vifc_vifi, 0); 969 ret = vif_delete(vif.vifc_vifi, 0);
@@ -964,12 +977,12 @@ int ip_mroute_setsockopt(struct sock *sk,int optname,char __user *optval,int opt
964 */ 977 */
965 case MRT_ADD_MFC: 978 case MRT_ADD_MFC:
966 case MRT_DEL_MFC: 979 case MRT_DEL_MFC:
967 if (optlen!=sizeof(mfc)) 980 if (optlen != sizeof(mfc))
968 return -EINVAL; 981 return -EINVAL;
969 if (copy_from_user(&mfc,optval, sizeof(mfc))) 982 if (copy_from_user(&mfc, optval, sizeof(mfc)))
970 return -EFAULT; 983 return -EFAULT;
971 rtnl_lock(); 984 rtnl_lock();
972 if (optname==MRT_DEL_MFC) 985 if (optname == MRT_DEL_MFC)
973 ret = ipmr_mfc_delete(&mfc); 986 ret = ipmr_mfc_delete(&mfc);
974 else 987 else
975 ret = ipmr_mfc_add(&mfc, sk==mroute_socket); 988 ret = ipmr_mfc_add(&mfc, sk==mroute_socket);
@@ -1028,12 +1041,12 @@ int ip_mroute_setsockopt(struct sock *sk,int optname,char __user *optval,int opt
1028 * Getsock opt support for the multicast routing system. 1041 * Getsock opt support for the multicast routing system.
1029 */ 1042 */
1030 1043
1031int ip_mroute_getsockopt(struct sock *sk,int optname,char __user *optval,int __user *optlen) 1044int ip_mroute_getsockopt(struct sock *sk, int optname, char __user *optval, int __user *optlen)
1032{ 1045{
1033 int olr; 1046 int olr;
1034 int val; 1047 int val;
1035 1048
1036 if (optname!=MRT_VERSION && 1049 if (optname != MRT_VERSION &&
1037#ifdef CONFIG_IP_PIMSM 1050#ifdef CONFIG_IP_PIMSM
1038 optname!=MRT_PIM && 1051 optname!=MRT_PIM &&
1039#endif 1052#endif
@@ -1047,17 +1060,17 @@ int ip_mroute_getsockopt(struct sock *sk,int optname,char __user *optval,int __u
1047 if (olr < 0) 1060 if (olr < 0)
1048 return -EINVAL; 1061 return -EINVAL;
1049 1062
1050 if (put_user(olr,optlen)) 1063 if (put_user(olr, optlen))
1051 return -EFAULT; 1064 return -EFAULT;
1052 if (optname==MRT_VERSION) 1065 if (optname == MRT_VERSION)
1053 val=0x0305; 1066 val = 0x0305;
1054#ifdef CONFIG_IP_PIMSM 1067#ifdef CONFIG_IP_PIMSM
1055 else if (optname==MRT_PIM) 1068 else if (optname == MRT_PIM)
1056 val=mroute_do_pim; 1069 val = mroute_do_pim;
1057#endif 1070#endif
1058 else 1071 else
1059 val=mroute_do_assert; 1072 val = mroute_do_assert;
1060 if (copy_to_user(optval,&val,olr)) 1073 if (copy_to_user(optval, &val, olr))
1061 return -EFAULT; 1074 return -EFAULT;
1062 return 0; 1075 return 0;
1063} 1076}
@@ -1075,27 +1088,27 @@ int ipmr_ioctl(struct sock *sk, int cmd, void __user *arg)
1075 1088
1076 switch (cmd) { 1089 switch (cmd) {
1077 case SIOCGETVIFCNT: 1090 case SIOCGETVIFCNT:
1078 if (copy_from_user(&vr,arg,sizeof(vr))) 1091 if (copy_from_user(&vr, arg, sizeof(vr)))
1079 return -EFAULT; 1092 return -EFAULT;
1080 if (vr.vifi>=maxvif) 1093 if (vr.vifi >= maxvif)
1081 return -EINVAL; 1094 return -EINVAL;
1082 read_lock(&mrt_lock); 1095 read_lock(&mrt_lock);
1083 vif=&vif_table[vr.vifi]; 1096 vif=&vif_table[vr.vifi];
1084 if (VIF_EXISTS(vr.vifi)) { 1097 if (VIF_EXISTS(vr.vifi)) {
1085 vr.icount=vif->pkt_in; 1098 vr.icount = vif->pkt_in;
1086 vr.ocount=vif->pkt_out; 1099 vr.ocount = vif->pkt_out;
1087 vr.ibytes=vif->bytes_in; 1100 vr.ibytes = vif->bytes_in;
1088 vr.obytes=vif->bytes_out; 1101 vr.obytes = vif->bytes_out;
1089 read_unlock(&mrt_lock); 1102 read_unlock(&mrt_lock);
1090 1103
1091 if (copy_to_user(arg,&vr,sizeof(vr))) 1104 if (copy_to_user(arg, &vr, sizeof(vr)))
1092 return -EFAULT; 1105 return -EFAULT;
1093 return 0; 1106 return 0;
1094 } 1107 }
1095 read_unlock(&mrt_lock); 1108 read_unlock(&mrt_lock);
1096 return -EADDRNOTAVAIL; 1109 return -EADDRNOTAVAIL;
1097 case SIOCGETSGCNT: 1110 case SIOCGETSGCNT:
1098 if (copy_from_user(&sr,arg,sizeof(sr))) 1111 if (copy_from_user(&sr, arg, sizeof(sr)))
1099 return -EFAULT; 1112 return -EFAULT;
1100 1113
1101 read_lock(&mrt_lock); 1114 read_lock(&mrt_lock);
@@ -1106,7 +1119,7 @@ int ipmr_ioctl(struct sock *sk, int cmd, void __user *arg)
1106 sr.wrong_if = c->mfc_un.res.wrong_if; 1119 sr.wrong_if = c->mfc_un.res.wrong_if;
1107 read_unlock(&mrt_lock); 1120 read_unlock(&mrt_lock);
1108 1121
1109 if (copy_to_user(arg,&sr,sizeof(sr))) 1122 if (copy_to_user(arg, &sr, sizeof(sr)))
1110 return -EFAULT; 1123 return -EFAULT;
1111 return 0; 1124 return 0;
1112 } 1125 }
@@ -1130,15 +1143,15 @@ static int ipmr_device_event(struct notifier_block *this, unsigned long event, v
1130 if (event != NETDEV_UNREGISTER) 1143 if (event != NETDEV_UNREGISTER)
1131 return NOTIFY_DONE; 1144 return NOTIFY_DONE;
1132 v=&vif_table[0]; 1145 v=&vif_table[0];
1133 for (ct=0;ct<maxvif;ct++,v++) { 1146 for (ct=0; ct<maxvif; ct++,v++) {
1134 if (v->dev==dev) 1147 if (v->dev == dev)
1135 vif_delete(ct, 1); 1148 vif_delete(ct, 1);
1136 } 1149 }
1137 return NOTIFY_DONE; 1150 return NOTIFY_DONE;
1138} 1151}
1139 1152
1140 1153
1141static struct notifier_block ip_mr_notifier={ 1154static struct notifier_block ip_mr_notifier = {
1142 .notifier_call = ipmr_device_event, 1155 .notifier_call = ipmr_device_event,
1143}; 1156};
1144 1157
@@ -1204,7 +1217,7 @@ static void ipmr_queue_xmit(struct sk_buff *skb, struct mfc_cache *c, int vifi)
1204#ifdef CONFIG_IP_PIMSM 1217#ifdef CONFIG_IP_PIMSM
1205 if (vif->flags & VIFF_REGISTER) { 1218 if (vif->flags & VIFF_REGISTER) {
1206 vif->pkt_out++; 1219 vif->pkt_out++;
1207 vif->bytes_out+=skb->len; 1220 vif->bytes_out += skb->len;
1208 vif->dev->stats.tx_bytes += skb->len; 1221 vif->dev->stats.tx_bytes += skb->len;
1209 vif->dev->stats.tx_packets++; 1222 vif->dev->stats.tx_packets++;
1210 ipmr_cache_report(skb, vifi, IGMPMSG_WHOLEPKT); 1223 ipmr_cache_report(skb, vifi, IGMPMSG_WHOLEPKT);
@@ -1254,7 +1267,7 @@ static void ipmr_queue_xmit(struct sk_buff *skb, struct mfc_cache *c, int vifi)
1254 } 1267 }
1255 1268
1256 vif->pkt_out++; 1269 vif->pkt_out++;
1257 vif->bytes_out+=skb->len; 1270 vif->bytes_out += skb->len;
1258 1271
1259 dst_release(skb->dst); 1272 dst_release(skb->dst);
1260 skb->dst = &rt->u.dst; 1273 skb->dst = &rt->u.dst;
@@ -1352,7 +1365,7 @@ static int ip_mr_forward(struct sk_buff *skb, struct mfc_cache *cache, int local
1352 } 1365 }
1353 1366
1354 vif_table[vif].pkt_in++; 1367 vif_table[vif].pkt_in++;
1355 vif_table[vif].bytes_in+=skb->len; 1368 vif_table[vif].bytes_in += skb->len;
1356 1369
1357 /* 1370 /*
1358 * Forward the frame 1371 * Forward the frame
@@ -1364,7 +1377,7 @@ static int ip_mr_forward(struct sk_buff *skb, struct mfc_cache *cache, int local
1364 if (skb2) 1377 if (skb2)
1365 ipmr_queue_xmit(skb2, cache, psend); 1378 ipmr_queue_xmit(skb2, cache, psend);
1366 } 1379 }
1367 psend=ct; 1380 psend = ct;
1368 } 1381 }
1369 } 1382 }
1370 if (psend != -1) { 1383 if (psend != -1) {
@@ -1428,7 +1441,7 @@ int ip_mr_input(struct sk_buff *skb)
1428 /* 1441 /*
1429 * No usable cache entry 1442 * No usable cache entry
1430 */ 1443 */
1431 if (cache==NULL) { 1444 if (cache == NULL) {
1432 int vif; 1445 int vif;
1433 1446
1434 if (local) { 1447 if (local) {
@@ -1469,29 +1482,13 @@ dont_forward:
1469 return 0; 1482 return 0;
1470} 1483}
1471 1484
1472#ifdef CONFIG_IP_PIMSM_V1 1485#ifdef CONFIG_IP_PIMSM
1473/* 1486static int __pim_rcv(struct sk_buff *skb, unsigned int pimlen)
1474 * Handle IGMP messages of PIMv1
1475 */
1476
1477int pim_rcv_v1(struct sk_buff * skb)
1478{ 1487{
1479 struct igmphdr *pim; 1488 struct net_device *reg_dev = NULL;
1480 struct iphdr *encap; 1489 struct iphdr *encap;
1481 struct net_device *reg_dev = NULL;
1482
1483 if (!pskb_may_pull(skb, sizeof(*pim) + sizeof(*encap)))
1484 goto drop;
1485 1490
1486 pim = igmp_hdr(skb); 1491 encap = (struct iphdr *)(skb_transport_header(skb) + pimlen);
1487
1488 if (!mroute_do_pim ||
1489 skb->len < sizeof(*pim) + sizeof(*encap) ||
1490 pim->group != PIM_V1_VERSION || pim->code != PIM_V1_REGISTER)
1491 goto drop;
1492
1493 encap = (struct iphdr *)(skb_transport_header(skb) +
1494 sizeof(struct igmphdr));
1495 /* 1492 /*
1496 Check that: 1493 Check that:
1497 a. packet is really destinted to a multicast group 1494 a. packet is really destinted to a multicast group
@@ -1500,8 +1497,8 @@ int pim_rcv_v1(struct sk_buff * skb)
1500 */ 1497 */
1501 if (!ipv4_is_multicast(encap->daddr) || 1498 if (!ipv4_is_multicast(encap->daddr) ||
1502 encap->tot_len == 0 || 1499 encap->tot_len == 0 ||
1503 ntohs(encap->tot_len) + sizeof(*pim) > skb->len) 1500 ntohs(encap->tot_len) + pimlen > skb->len)
1504 goto drop; 1501 return 1;
1505 1502
1506 read_lock(&mrt_lock); 1503 read_lock(&mrt_lock);
1507 if (reg_vif_num >= 0) 1504 if (reg_vif_num >= 0)
@@ -1511,7 +1508,7 @@ int pim_rcv_v1(struct sk_buff * skb)
1511 read_unlock(&mrt_lock); 1508 read_unlock(&mrt_lock);
1512 1509
1513 if (reg_dev == NULL) 1510 if (reg_dev == NULL)
1514 goto drop; 1511 return 1;
1515 1512
1516 skb->mac_header = skb->network_header; 1513 skb->mac_header = skb->network_header;
1517 skb_pull(skb, (u8*)encap - skb->data); 1514 skb_pull(skb, (u8*)encap - skb->data);
@@ -1527,9 +1524,33 @@ int pim_rcv_v1(struct sk_buff * skb)
1527 nf_reset(skb); 1524 nf_reset(skb);
1528 netif_rx(skb); 1525 netif_rx(skb);
1529 dev_put(reg_dev); 1526 dev_put(reg_dev);
1527
1530 return 0; 1528 return 0;
1531 drop: 1529}
1532 kfree_skb(skb); 1530#endif
1531
1532#ifdef CONFIG_IP_PIMSM_V1
1533/*
1534 * Handle IGMP messages of PIMv1
1535 */
1536
1537int pim_rcv_v1(struct sk_buff * skb)
1538{
1539 struct igmphdr *pim;
1540
1541 if (!pskb_may_pull(skb, sizeof(*pim) + sizeof(struct iphdr)))
1542 goto drop;
1543
1544 pim = igmp_hdr(skb);
1545
1546 if (!mroute_do_pim ||
1547 pim->group != PIM_V1_VERSION || pim->code != PIM_V1_REGISTER)
1548 goto drop;
1549
1550 if (__pim_rcv(skb, sizeof(*pim))) {
1551drop:
1552 kfree_skb(skb);
1553 }
1533 return 0; 1554 return 0;
1534} 1555}
1535#endif 1556#endif
@@ -1538,10 +1559,8 @@ int pim_rcv_v1(struct sk_buff * skb)
1538static int pim_rcv(struct sk_buff * skb) 1559static int pim_rcv(struct sk_buff * skb)
1539{ 1560{
1540 struct pimreghdr *pim; 1561 struct pimreghdr *pim;
1541 struct iphdr *encap;
1542 struct net_device *reg_dev = NULL;
1543 1562
1544 if (!pskb_may_pull(skb, sizeof(*pim) + sizeof(*encap))) 1563 if (!pskb_may_pull(skb, sizeof(*pim) + sizeof(struct iphdr)))
1545 goto drop; 1564 goto drop;
1546 1565
1547 pim = (struct pimreghdr *)skb_transport_header(skb); 1566 pim = (struct pimreghdr *)skb_transport_header(skb);
@@ -1551,41 +1570,10 @@ static int pim_rcv(struct sk_buff * skb)
1551 csum_fold(skb_checksum(skb, 0, skb->len, 0)))) 1570 csum_fold(skb_checksum(skb, 0, skb->len, 0))))
1552 goto drop; 1571 goto drop;
1553 1572
1554 /* check if the inner packet is destined to mcast group */ 1573 if (__pim_rcv(skb, sizeof(*pim))) {
1555 encap = (struct iphdr *)(skb_transport_header(skb) + 1574drop:
1556 sizeof(struct pimreghdr)); 1575 kfree_skb(skb);
1557 if (!ipv4_is_multicast(encap->daddr) || 1576 }
1558 encap->tot_len == 0 ||
1559 ntohs(encap->tot_len) + sizeof(*pim) > skb->len)
1560 goto drop;
1561
1562 read_lock(&mrt_lock);
1563 if (reg_vif_num >= 0)
1564 reg_dev = vif_table[reg_vif_num].dev;
1565 if (reg_dev)
1566 dev_hold(reg_dev);
1567 read_unlock(&mrt_lock);
1568
1569 if (reg_dev == NULL)
1570 goto drop;
1571
1572 skb->mac_header = skb->network_header;
1573 skb_pull(skb, (u8*)encap - skb->data);
1574 skb_reset_network_header(skb);
1575 skb->dev = reg_dev;
1576 skb->protocol = htons(ETH_P_IP);
1577 skb->ip_summed = 0;
1578 skb->pkt_type = PACKET_HOST;
1579 dst_release(skb->dst);
1580 reg_dev->stats.rx_bytes += skb->len;
1581 reg_dev->stats.rx_packets++;
1582 skb->dst = NULL;
1583 nf_reset(skb);
1584 netif_rx(skb);
1585 dev_put(reg_dev);
1586 return 0;
1587 drop:
1588 kfree_skb(skb);
1589 return 0; 1577 return 0;
1590} 1578}
1591#endif 1579#endif
@@ -1602,13 +1590,13 @@ ipmr_fill_mroute(struct sk_buff *skb, struct mfc_cache *c, struct rtmsg *rtm)
1602 if (dev) 1590 if (dev)
1603 RTA_PUT(skb, RTA_IIF, 4, &dev->ifindex); 1591 RTA_PUT(skb, RTA_IIF, 4, &dev->ifindex);
1604 1592
1605 mp_head = (struct rtattr*)skb_put(skb, RTA_LENGTH(0)); 1593 mp_head = (struct rtattr *)skb_put(skb, RTA_LENGTH(0));
1606 1594
1607 for (ct = c->mfc_un.res.minvif; ct < c->mfc_un.res.maxvif; ct++) { 1595 for (ct = c->mfc_un.res.minvif; ct < c->mfc_un.res.maxvif; ct++) {
1608 if (c->mfc_un.res.ttls[ct] < 255) { 1596 if (c->mfc_un.res.ttls[ct] < 255) {
1609 if (skb_tailroom(skb) < RTA_ALIGN(RTA_ALIGN(sizeof(*nhp)) + 4)) 1597 if (skb_tailroom(skb) < RTA_ALIGN(RTA_ALIGN(sizeof(*nhp)) + 4))
1610 goto rtattr_failure; 1598 goto rtattr_failure;
1611 nhp = (struct rtnexthop*)skb_put(skb, RTA_ALIGN(sizeof(*nhp))); 1599 nhp = (struct rtnexthop *)skb_put(skb, RTA_ALIGN(sizeof(*nhp)));
1612 nhp->rtnh_flags = 0; 1600 nhp->rtnh_flags = 0;
1613 nhp->rtnh_hops = c->mfc_un.res.ttls[ct]; 1601 nhp->rtnh_hops = c->mfc_un.res.ttls[ct];
1614 nhp->rtnh_ifindex = vif_table[ct].dev->ifindex; 1602 nhp->rtnh_ifindex = vif_table[ct].dev->ifindex;
@@ -1634,7 +1622,7 @@ int ipmr_get_route(struct sk_buff *skb, struct rtmsg *rtm, int nowait)
1634 read_lock(&mrt_lock); 1622 read_lock(&mrt_lock);
1635 cache = ipmr_cache_find(rt->rt_src, rt->rt_dst); 1623 cache = ipmr_cache_find(rt->rt_src, rt->rt_dst);
1636 1624
1637 if (cache==NULL) { 1625 if (cache == NULL) {
1638 struct sk_buff *skb2; 1626 struct sk_buff *skb2;
1639 struct iphdr *iph; 1627 struct iphdr *iph;
1640 struct net_device *dev; 1628 struct net_device *dev;
@@ -1866,15 +1854,16 @@ static int ipmr_mfc_seq_show(struct seq_file *seq, void *v)
1866 const struct mfc_cache *mfc = v; 1854 const struct mfc_cache *mfc = v;
1867 const struct ipmr_mfc_iter *it = seq->private; 1855 const struct ipmr_mfc_iter *it = seq->private;
1868 1856
1869 seq_printf(seq, "%08lX %08lX %-3d %8ld %8ld %8ld", 1857 seq_printf(seq, "%08lX %08lX %-3hd",
1870 (unsigned long) mfc->mfc_mcastgrp, 1858 (unsigned long) mfc->mfc_mcastgrp,
1871 (unsigned long) mfc->mfc_origin, 1859 (unsigned long) mfc->mfc_origin,
1872 mfc->mfc_parent, 1860 mfc->mfc_parent);
1873 mfc->mfc_un.res.pkt,
1874 mfc->mfc_un.res.bytes,
1875 mfc->mfc_un.res.wrong_if);
1876 1861
1877 if (it->cache != &mfc_unres_queue) { 1862 if (it->cache != &mfc_unres_queue) {
1863 seq_printf(seq, " %8lu %8lu %8lu",
1864 mfc->mfc_un.res.pkt,
1865 mfc->mfc_un.res.bytes,
1866 mfc->mfc_un.res.wrong_if);
1878 for (n = mfc->mfc_un.res.minvif; 1867 for (n = mfc->mfc_un.res.minvif;
1879 n < mfc->mfc_un.res.maxvif; n++ ) { 1868 n < mfc->mfc_un.res.maxvif; n++ ) {
1880 if (VIF_EXISTS(n) 1869 if (VIF_EXISTS(n)
@@ -1883,6 +1872,11 @@ static int ipmr_mfc_seq_show(struct seq_file *seq, void *v)
1883 " %2d:%-3d", 1872 " %2d:%-3d",
1884 n, mfc->mfc_un.res.ttls[n]); 1873 n, mfc->mfc_un.res.ttls[n]);
1885 } 1874 }
1875 } else {
1876 /* unresolved mfc_caches don't contain
1877 * pkt, bytes and wrong_if values
1878 */
1879 seq_printf(seq, " %8lu %8lu %8lu", 0ul, 0ul, 0ul);
1886 } 1880 }
1887 seq_putc(seq, '\n'); 1881 seq_putc(seq, '\n');
1888 } 1882 }
diff --git a/net/ipv4/netfilter.c b/net/ipv4/netfilter.c
index 6efdb70b3eb2..fdf6811c31a2 100644
--- a/net/ipv4/netfilter.c
+++ b/net/ipv4/netfilter.c
@@ -66,7 +66,7 @@ int ip_route_me_harder(struct sk_buff *skb, unsigned addr_type)
66#ifdef CONFIG_XFRM 66#ifdef CONFIG_XFRM
67 if (!(IPCB(skb)->flags & IPSKB_XFRM_TRANSFORMED) && 67 if (!(IPCB(skb)->flags & IPSKB_XFRM_TRANSFORMED) &&
68 xfrm_decode_session(skb, &fl, AF_INET) == 0) 68 xfrm_decode_session(skb, &fl, AF_INET) == 0)
69 if (xfrm_lookup(&skb->dst, &fl, skb->sk, 0)) 69 if (xfrm_lookup(net, &skb->dst, &fl, skb->sk, 0))
70 return -1; 70 return -1;
71#endif 71#endif
72 72
@@ -97,7 +97,7 @@ int ip_xfrm_me_harder(struct sk_buff *skb)
97 dst = ((struct xfrm_dst *)dst)->route; 97 dst = ((struct xfrm_dst *)dst)->route;
98 dst_hold(dst); 98 dst_hold(dst);
99 99
100 if (xfrm_lookup(&dst, &fl, skb->sk, 0) < 0) 100 if (xfrm_lookup(dev_net(dst->dev), &dst, &fl, skb->sk, 0) < 0)
101 return -1; 101 return -1;
102 102
103 dst_release(skb->dst); 103 dst_release(skb->dst);
@@ -125,6 +125,7 @@ struct ip_rt_info {
125 __be32 daddr; 125 __be32 daddr;
126 __be32 saddr; 126 __be32 saddr;
127 u_int8_t tos; 127 u_int8_t tos;
128 u_int32_t mark;
128}; 129};
129 130
130static void nf_ip_saveroute(const struct sk_buff *skb, 131static void nf_ip_saveroute(const struct sk_buff *skb,
@@ -138,6 +139,7 @@ static void nf_ip_saveroute(const struct sk_buff *skb,
138 rt_info->tos = iph->tos; 139 rt_info->tos = iph->tos;
139 rt_info->daddr = iph->daddr; 140 rt_info->daddr = iph->daddr;
140 rt_info->saddr = iph->saddr; 141 rt_info->saddr = iph->saddr;
142 rt_info->mark = skb->mark;
141 } 143 }
142} 144}
143 145
@@ -150,6 +152,7 @@ static int nf_ip_reroute(struct sk_buff *skb,
150 const struct iphdr *iph = ip_hdr(skb); 152 const struct iphdr *iph = ip_hdr(skb);
151 153
152 if (!(iph->tos == rt_info->tos 154 if (!(iph->tos == rt_info->tos
155 && skb->mark == rt_info->mark
153 && iph->daddr == rt_info->daddr 156 && iph->daddr == rt_info->daddr
154 && iph->saddr == rt_info->saddr)) 157 && iph->saddr == rt_info->saddr))
155 return ip_route_me_harder(skb, RTN_UNSPEC); 158 return ip_route_me_harder(skb, RTN_UNSPEC);
diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
index 8d70d29f1ccf..7ea88b61cb0d 100644
--- a/net/ipv4/netfilter/arp_tables.c
+++ b/net/ipv4/netfilter/arp_tables.c
@@ -142,15 +142,15 @@ static inline int arp_packet_match(const struct arphdr *arphdr,
142 ARPT_INV_TGTIP)) { 142 ARPT_INV_TGTIP)) {
143 dprintf("Source or target IP address mismatch.\n"); 143 dprintf("Source or target IP address mismatch.\n");
144 144
145 dprintf("SRC: %u.%u.%u.%u. Mask: %u.%u.%u.%u. Target: %u.%u.%u.%u.%s\n", 145 dprintf("SRC: %pI4. Mask: %pI4. Target: %pI4.%s\n",
146 NIPQUAD(src_ipaddr), 146 &src_ipaddr,
147 NIPQUAD(arpinfo->smsk.s_addr), 147 &arpinfo->smsk.s_addr,
148 NIPQUAD(arpinfo->src.s_addr), 148 &arpinfo->src.s_addr,
149 arpinfo->invflags & ARPT_INV_SRCIP ? " (INV)" : ""); 149 arpinfo->invflags & ARPT_INV_SRCIP ? " (INV)" : "");
150 dprintf("TGT: %u.%u.%u.%u Mask: %u.%u.%u.%u Target: %u.%u.%u.%u.%s\n", 150 dprintf("TGT: %pI4 Mask: %pI4 Target: %pI4.%s\n",
151 NIPQUAD(tgt_ipaddr), 151 &tgt_ipaddr,
152 NIPQUAD(arpinfo->tmsk.s_addr), 152 &arpinfo->tmsk.s_addr,
153 NIPQUAD(arpinfo->tgt.s_addr), 153 &arpinfo->tgt.s_addr,
154 arpinfo->invflags & ARPT_INV_TGTIP ? " (INV)" : ""); 154 arpinfo->invflags & ARPT_INV_TGTIP ? " (INV)" : "");
155 return 0; 155 return 0;
156 } 156 }
diff --git a/net/ipv4/netfilter/arptable_filter.c b/net/ipv4/netfilter/arptable_filter.c
index bee3d117661a..e091187e864f 100644
--- a/net/ipv4/netfilter/arptable_filter.c
+++ b/net/ipv4/netfilter/arptable_filter.c
@@ -75,16 +75,6 @@ static unsigned int arpt_out_hook(unsigned int hook,
75 dev_net(out)->ipv4.arptable_filter); 75 dev_net(out)->ipv4.arptable_filter);
76} 76}
77 77
78static unsigned int arpt_forward_hook(unsigned int hook,
79 struct sk_buff *skb,
80 const struct net_device *in,
81 const struct net_device *out,
82 int (*okfn)(struct sk_buff *))
83{
84 return arpt_do_table(skb, hook, in, out,
85 dev_net(in)->ipv4.arptable_filter);
86}
87
88static struct nf_hook_ops arpt_ops[] __read_mostly = { 78static struct nf_hook_ops arpt_ops[] __read_mostly = {
89 { 79 {
90 .hook = arpt_in_hook, 80 .hook = arpt_in_hook,
@@ -101,7 +91,7 @@ static struct nf_hook_ops arpt_ops[] __read_mostly = {
101 .priority = NF_IP_PRI_FILTER, 91 .priority = NF_IP_PRI_FILTER,
102 }, 92 },
103 { 93 {
104 .hook = arpt_forward_hook, 94 .hook = arpt_in_hook,
105 .owner = THIS_MODULE, 95 .owner = THIS_MODULE,
106 .pf = NFPROTO_ARP, 96 .pf = NFPROTO_ARP,
107 .hooknum = NF_ARP_FORWARD, 97 .hooknum = NF_ARP_FORWARD,
diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
index 213fb27debc1..ef8b6ca068b2 100644
--- a/net/ipv4/netfilter/ip_tables.c
+++ b/net/ipv4/netfilter/ip_tables.c
@@ -94,15 +94,11 @@ ip_packet_match(const struct iphdr *ip,
94 IPT_INV_DSTIP)) { 94 IPT_INV_DSTIP)) {
95 dprintf("Source or dest mismatch.\n"); 95 dprintf("Source or dest mismatch.\n");
96 96
97 dprintf("SRC: %u.%u.%u.%u. Mask: %u.%u.%u.%u. Target: %u.%u.%u.%u.%s\n", 97 dprintf("SRC: %pI4. Mask: %pI4. Target: %pI4.%s\n",
98 NIPQUAD(ip->saddr), 98 &ip->saddr, &ipinfo->smsk.s_addr, &ipinfo->src.s_addr,
99 NIPQUAD(ipinfo->smsk.s_addr),
100 NIPQUAD(ipinfo->src.s_addr),
101 ipinfo->invflags & IPT_INV_SRCIP ? " (INV)" : ""); 99 ipinfo->invflags & IPT_INV_SRCIP ? " (INV)" : "");
102 dprintf("DST: %u.%u.%u.%u Mask: %u.%u.%u.%u Target: %u.%u.%u.%u.%s\n", 100 dprintf("DST: %pI4 Mask: %pI4 Target: %pI4.%s\n",
103 NIPQUAD(ip->daddr), 101 &ip->daddr, &ipinfo->dmsk.s_addr, &ipinfo->dst.s_addr,
104 NIPQUAD(ipinfo->dmsk.s_addr),
105 NIPQUAD(ipinfo->dst.s_addr),
106 ipinfo->invflags & IPT_INV_DSTIP ? " (INV)" : ""); 102 ipinfo->invflags & IPT_INV_DSTIP ? " (INV)" : "");
107 return false; 103 return false;
108 } 104 }
diff --git a/net/ipv4/netfilter/ipt_CLUSTERIP.c b/net/ipv4/netfilter/ipt_CLUSTERIP.c
index 7ac1677419a9..2e4f98b85524 100644
--- a/net/ipv4/netfilter/ipt_CLUSTERIP.c
+++ b/net/ipv4/netfilter/ipt_CLUSTERIP.c
@@ -168,7 +168,7 @@ clusterip_config_init(const struct ipt_clusterip_tgt_info *i, __be32 ip,
168 char buffer[16]; 168 char buffer[16];
169 169
170 /* create proc dir entry */ 170 /* create proc dir entry */
171 sprintf(buffer, "%u.%u.%u.%u", NIPQUAD(ip)); 171 sprintf(buffer, "%pI4", &ip);
172 c->pde = proc_create_data(buffer, S_IWUSR|S_IRUSR, 172 c->pde = proc_create_data(buffer, S_IWUSR|S_IRUSR,
173 clusterip_procdir, 173 clusterip_procdir,
174 &clusterip_proc_fops, c); 174 &clusterip_proc_fops, c);
@@ -373,7 +373,7 @@ static bool clusterip_tg_check(const struct xt_tgchk_param *par)
373 config = clusterip_config_find_get(e->ip.dst.s_addr, 1); 373 config = clusterip_config_find_get(e->ip.dst.s_addr, 1);
374 if (!config) { 374 if (!config) {
375 if (!(cipinfo->flags & CLUSTERIP_FLAG_NEW)) { 375 if (!(cipinfo->flags & CLUSTERIP_FLAG_NEW)) {
376 printk(KERN_WARNING "CLUSTERIP: no config found for %u.%u.%u.%u, need 'new'\n", NIPQUAD(e->ip.dst.s_addr)); 376 printk(KERN_WARNING "CLUSTERIP: no config found for %pI4, need 'new'\n", &e->ip.dst.s_addr);
377 return false; 377 return false;
378 } else { 378 } else {
379 struct net_device *dev; 379 struct net_device *dev;
@@ -478,9 +478,8 @@ static void arp_print(struct arp_payload *payload)
478 } 478 }
479 hbuffer[--k]='\0'; 479 hbuffer[--k]='\0';
480 480
481 printk("src %u.%u.%u.%u@%s, dst %u.%u.%u.%u\n", 481 printk("src %pI4@%s, dst %pI4\n",
482 NIPQUAD(payload->src_ip), hbuffer, 482 &payload->src_ip, hbuffer, &payload->dst_ip);
483 NIPQUAD(payload->dst_ip));
484} 483}
485#endif 484#endif
486 485
diff --git a/net/ipv4/netfilter/ipt_LOG.c b/net/ipv4/netfilter/ipt_LOG.c
index 7b5dbe118c09..27a78fbbd92b 100644
--- a/net/ipv4/netfilter/ipt_LOG.c
+++ b/net/ipv4/netfilter/ipt_LOG.c
@@ -54,8 +54,8 @@ static void dump_packet(const struct nf_loginfo *info,
54 /* Important fields: 54 /* Important fields:
55 * TOS, len, DF/MF, fragment offset, TTL, src, dst, options. */ 55 * TOS, len, DF/MF, fragment offset, TTL, src, dst, options. */
56 /* Max length: 40 "SRC=255.255.255.255 DST=255.255.255.255 " */ 56 /* Max length: 40 "SRC=255.255.255.255 DST=255.255.255.255 " */
57 printk("SRC=%u.%u.%u.%u DST=%u.%u.%u.%u ", 57 printk("SRC=%pI4 DST=%pI4 ",
58 NIPQUAD(ih->saddr), NIPQUAD(ih->daddr)); 58 &ih->saddr, &ih->daddr);
59 59
60 /* Max length: 46 "LEN=65535 TOS=0xFF PREC=0xFF TTL=255 ID=65535 " */ 60 /* Max length: 46 "LEN=65535 TOS=0xFF PREC=0xFF TTL=255 ID=65535 " */
61 printk("LEN=%u TOS=0x%02X PREC=0x%02X TTL=%u ID=%u ", 61 printk("LEN=%u TOS=0x%02X PREC=0x%02X TTL=%u ID=%u ",
@@ -262,8 +262,7 @@ static void dump_packet(const struct nf_loginfo *info,
262 break; 262 break;
263 case ICMP_REDIRECT: 263 case ICMP_REDIRECT:
264 /* Max length: 24 "GATEWAY=255.255.255.255 " */ 264 /* Max length: 24 "GATEWAY=255.255.255.255 " */
265 printk("GATEWAY=%u.%u.%u.%u ", 265 printk("GATEWAY=%pI4 ", &ich->un.gateway);
266 NIPQUAD(ich->un.gateway));
267 /* Fall through */ 266 /* Fall through */
268 case ICMP_DEST_UNREACH: 267 case ICMP_DEST_UNREACH:
269 case ICMP_SOURCE_QUENCH: 268 case ICMP_SOURCE_QUENCH:
diff --git a/net/ipv4/netfilter/ipt_addrtype.c b/net/ipv4/netfilter/ipt_addrtype.c
index 88762f02779d..3b216be3bc9f 100644
--- a/net/ipv4/netfilter/ipt_addrtype.c
+++ b/net/ipv4/netfilter/ipt_addrtype.c
@@ -23,24 +23,25 @@ MODULE_LICENSE("GPL");
23MODULE_AUTHOR("Patrick McHardy <kaber@trash.net>"); 23MODULE_AUTHOR("Patrick McHardy <kaber@trash.net>");
24MODULE_DESCRIPTION("Xtables: address type match for IPv4"); 24MODULE_DESCRIPTION("Xtables: address type match for IPv4");
25 25
26static inline bool match_type(const struct net_device *dev, __be32 addr, 26static inline bool match_type(struct net *net, const struct net_device *dev,
27 u_int16_t mask) 27 __be32 addr, u_int16_t mask)
28{ 28{
29 return !!(mask & (1 << inet_dev_addr_type(&init_net, dev, addr))); 29 return !!(mask & (1 << inet_dev_addr_type(net, dev, addr)));
30} 30}
31 31
32static bool 32static bool
33addrtype_mt_v0(const struct sk_buff *skb, const struct xt_match_param *par) 33addrtype_mt_v0(const struct sk_buff *skb, const struct xt_match_param *par)
34{ 34{
35 struct net *net = dev_net(par->in ? par->in : par->out);
35 const struct ipt_addrtype_info *info = par->matchinfo; 36 const struct ipt_addrtype_info *info = par->matchinfo;
36 const struct iphdr *iph = ip_hdr(skb); 37 const struct iphdr *iph = ip_hdr(skb);
37 bool ret = true; 38 bool ret = true;
38 39
39 if (info->source) 40 if (info->source)
40 ret &= match_type(NULL, iph->saddr, info->source) ^ 41 ret &= match_type(net, NULL, iph->saddr, info->source) ^
41 info->invert_source; 42 info->invert_source;
42 if (info->dest) 43 if (info->dest)
43 ret &= match_type(NULL, iph->daddr, info->dest) ^ 44 ret &= match_type(net, NULL, iph->daddr, info->dest) ^
44 info->invert_dest; 45 info->invert_dest;
45 46
46 return ret; 47 return ret;
@@ -49,6 +50,7 @@ addrtype_mt_v0(const struct sk_buff *skb, const struct xt_match_param *par)
49static bool 50static bool
50addrtype_mt_v1(const struct sk_buff *skb, const struct xt_match_param *par) 51addrtype_mt_v1(const struct sk_buff *skb, const struct xt_match_param *par)
51{ 52{
53 struct net *net = dev_net(par->in ? par->in : par->out);
52 const struct ipt_addrtype_info_v1 *info = par->matchinfo; 54 const struct ipt_addrtype_info_v1 *info = par->matchinfo;
53 const struct iphdr *iph = ip_hdr(skb); 55 const struct iphdr *iph = ip_hdr(skb);
54 const struct net_device *dev = NULL; 56 const struct net_device *dev = NULL;
@@ -60,10 +62,10 @@ addrtype_mt_v1(const struct sk_buff *skb, const struct xt_match_param *par)
60 dev = par->out; 62 dev = par->out;
61 63
62 if (info->source) 64 if (info->source)
63 ret &= match_type(dev, iph->saddr, info->source) ^ 65 ret &= match_type(net, dev, iph->saddr, info->source) ^
64 (info->flags & IPT_ADDRTYPE_INVERT_SOURCE); 66 (info->flags & IPT_ADDRTYPE_INVERT_SOURCE);
65 if (ret && info->dest) 67 if (ret && info->dest)
66 ret &= match_type(dev, iph->daddr, info->dest) ^ 68 ret &= match_type(net, dev, iph->daddr, info->dest) ^
67 !!(info->flags & IPT_ADDRTYPE_INVERT_DEST); 69 !!(info->flags & IPT_ADDRTYPE_INVERT_DEST);
68 return ret; 70 return ret;
69} 71}
diff --git a/net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c b/net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c
index 4a7c35275396..b2141e11575e 100644
--- a/net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c
+++ b/net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c
@@ -60,9 +60,8 @@ static bool ipv4_invert_tuple(struct nf_conntrack_tuple *tuple,
60static int ipv4_print_tuple(struct seq_file *s, 60static int ipv4_print_tuple(struct seq_file *s,
61 const struct nf_conntrack_tuple *tuple) 61 const struct nf_conntrack_tuple *tuple)
62{ 62{
63 return seq_printf(s, "src=%u.%u.%u.%u dst=%u.%u.%u.%u ", 63 return seq_printf(s, "src=%pI4 dst=%pI4 ",
64 NIPQUAD(tuple->src.u3.ip), 64 &tuple->src.u3.ip, &tuple->dst.u3.ip);
65 NIPQUAD(tuple->dst.u3.ip));
66} 65}
67 66
68static int ipv4_get_l4proto(const struct sk_buff *skb, unsigned int nhoff, 67static int ipv4_get_l4proto(const struct sk_buff *skb, unsigned int nhoff,
@@ -198,7 +197,7 @@ static ctl_table ip_ct_sysctl_table[] = {
198 .data = &nf_conntrack_max, 197 .data = &nf_conntrack_max,
199 .maxlen = sizeof(int), 198 .maxlen = sizeof(int),
200 .mode = 0644, 199 .mode = 0644,
201 .proc_handler = &proc_dointvec, 200 .proc_handler = proc_dointvec,
202 }, 201 },
203 { 202 {
204 .ctl_name = NET_IPV4_NF_CONNTRACK_COUNT, 203 .ctl_name = NET_IPV4_NF_CONNTRACK_COUNT,
@@ -206,7 +205,7 @@ static ctl_table ip_ct_sysctl_table[] = {
206 .data = &init_net.ct.count, 205 .data = &init_net.ct.count,
207 .maxlen = sizeof(int), 206 .maxlen = sizeof(int),
208 .mode = 0444, 207 .mode = 0444,
209 .proc_handler = &proc_dointvec, 208 .proc_handler = proc_dointvec,
210 }, 209 },
211 { 210 {
212 .ctl_name = NET_IPV4_NF_CONNTRACK_BUCKETS, 211 .ctl_name = NET_IPV4_NF_CONNTRACK_BUCKETS,
@@ -214,7 +213,7 @@ static ctl_table ip_ct_sysctl_table[] = {
214 .data = &nf_conntrack_htable_size, 213 .data = &nf_conntrack_htable_size,
215 .maxlen = sizeof(unsigned int), 214 .maxlen = sizeof(unsigned int),
216 .mode = 0444, 215 .mode = 0444,
217 .proc_handler = &proc_dointvec, 216 .proc_handler = proc_dointvec,
218 }, 217 },
219 { 218 {
220 .ctl_name = NET_IPV4_NF_CONNTRACK_CHECKSUM, 219 .ctl_name = NET_IPV4_NF_CONNTRACK_CHECKSUM,
@@ -222,7 +221,7 @@ static ctl_table ip_ct_sysctl_table[] = {
222 .data = &init_net.ct.sysctl_checksum, 221 .data = &init_net.ct.sysctl_checksum,
223 .maxlen = sizeof(int), 222 .maxlen = sizeof(int),
224 .mode = 0644, 223 .mode = 0644,
225 .proc_handler = &proc_dointvec, 224 .proc_handler = proc_dointvec,
226 }, 225 },
227 { 226 {
228 .ctl_name = NET_IPV4_NF_CONNTRACK_LOG_INVALID, 227 .ctl_name = NET_IPV4_NF_CONNTRACK_LOG_INVALID,
@@ -230,8 +229,8 @@ static ctl_table ip_ct_sysctl_table[] = {
230 .data = &init_net.ct.sysctl_log_invalid, 229 .data = &init_net.ct.sysctl_log_invalid,
231 .maxlen = sizeof(unsigned int), 230 .maxlen = sizeof(unsigned int),
232 .mode = 0644, 231 .mode = 0644,
233 .proc_handler = &proc_dointvec_minmax, 232 .proc_handler = proc_dointvec_minmax,
234 .strategy = &sysctl_intvec, 233 .strategy = sysctl_intvec,
235 .extra1 = &log_invalid_proto_min, 234 .extra1 = &log_invalid_proto_min,
236 .extra2 = &log_invalid_proto_max, 235 .extra2 = &log_invalid_proto_max,
237 }, 236 },
@@ -284,17 +283,17 @@ getorigdst(struct sock *sk, int optval, void __user *user, int *len)
284 .tuple.dst.u3.ip; 283 .tuple.dst.u3.ip;
285 memset(sin.sin_zero, 0, sizeof(sin.sin_zero)); 284 memset(sin.sin_zero, 0, sizeof(sin.sin_zero));
286 285
287 pr_debug("SO_ORIGINAL_DST: %u.%u.%u.%u %u\n", 286 pr_debug("SO_ORIGINAL_DST: %pI4 %u\n",
288 NIPQUAD(sin.sin_addr.s_addr), ntohs(sin.sin_port)); 287 &sin.sin_addr.s_addr, ntohs(sin.sin_port));
289 nf_ct_put(ct); 288 nf_ct_put(ct);
290 if (copy_to_user(user, &sin, sizeof(sin)) != 0) 289 if (copy_to_user(user, &sin, sizeof(sin)) != 0)
291 return -EFAULT; 290 return -EFAULT;
292 else 291 else
293 return 0; 292 return 0;
294 } 293 }
295 pr_debug("SO_ORIGINAL_DST: Can't find %u.%u.%u.%u/%u-%u.%u.%u.%u/%u.\n", 294 pr_debug("SO_ORIGINAL_DST: Can't find %pI4/%u-%pI4/%u.\n",
296 NIPQUAD(tuple.src.u3.ip), ntohs(tuple.src.u.tcp.port), 295 &tuple.src.u3.ip, ntohs(tuple.src.u.tcp.port),
297 NIPQUAD(tuple.dst.u3.ip), ntohs(tuple.dst.u.tcp.port)); 296 &tuple.dst.u3.ip, ntohs(tuple.dst.u.tcp.port));
298 return -ENOENT; 297 return -ENOENT;
299} 298}
300 299
diff --git a/net/ipv4/netfilter/nf_conntrack_proto_icmp.c b/net/ipv4/netfilter/nf_conntrack_proto_icmp.c
index 4e8879220222..1fd3ef7718b6 100644
--- a/net/ipv4/netfilter/nf_conntrack_proto_icmp.c
+++ b/net/ipv4/netfilter/nf_conntrack_proto_icmp.c
@@ -272,7 +272,7 @@ static struct ctl_table icmp_sysctl_table[] = {
272 .data = &nf_ct_icmp_timeout, 272 .data = &nf_ct_icmp_timeout,
273 .maxlen = sizeof(unsigned int), 273 .maxlen = sizeof(unsigned int),
274 .mode = 0644, 274 .mode = 0644,
275 .proc_handler = &proc_dointvec_jiffies, 275 .proc_handler = proc_dointvec_jiffies,
276 }, 276 },
277 { 277 {
278 .ctl_name = 0 278 .ctl_name = 0
@@ -285,7 +285,7 @@ static struct ctl_table icmp_compat_sysctl_table[] = {
285 .data = &nf_ct_icmp_timeout, 285 .data = &nf_ct_icmp_timeout,
286 .maxlen = sizeof(unsigned int), 286 .maxlen = sizeof(unsigned int),
287 .mode = 0644, 287 .mode = 0644,
288 .proc_handler = &proc_dointvec_jiffies, 288 .proc_handler = proc_dointvec_jiffies,
289 }, 289 },
290 { 290 {
291 .ctl_name = 0 291 .ctl_name = 0
diff --git a/net/ipv4/netfilter/nf_nat_h323.c b/net/ipv4/netfilter/nf_nat_h323.c
index ee47bf28c825..7e8e6fc75413 100644
--- a/net/ipv4/netfilter/nf_nat_h323.c
+++ b/net/ipv4/netfilter/nf_nat_h323.c
@@ -119,10 +119,9 @@ static int set_sig_addr(struct sk_buff *skb, struct nf_conn *ct,
119 (ntohl(addr.ip) & 0xff000000) == 0x7f000000) 119 (ntohl(addr.ip) & 0xff000000) == 0x7f000000)
120 i = 0; 120 i = 0;
121 121
122 pr_debug("nf_nat_ras: set signal address " 122 pr_debug("nf_nat_ras: set signal address %pI4:%hu->%pI4:%hu\n",
123 "%u.%u.%u.%u:%hu->%u.%u.%u.%u:%hu\n", 123 &addr.ip, port,
124 NIPQUAD(addr.ip), port, 124 &ct->tuplehash[!dir].tuple.dst.u3.ip,
125 NIPQUAD(ct->tuplehash[!dir].tuple.dst.u3.ip),
126 info->sig_port[!dir]); 125 info->sig_port[!dir]);
127 return set_h225_addr(skb, data, 0, &taddr[i], 126 return set_h225_addr(skb, data, 0, &taddr[i],
128 &ct->tuplehash[!dir]. 127 &ct->tuplehash[!dir].
@@ -131,10 +130,9 @@ static int set_sig_addr(struct sk_buff *skb, struct nf_conn *ct,
131 } else if (addr.ip == ct->tuplehash[dir].tuple.dst.u3.ip && 130 } else if (addr.ip == ct->tuplehash[dir].tuple.dst.u3.ip &&
132 port == info->sig_port[dir]) { 131 port == info->sig_port[dir]) {
133 /* GK->GW */ 132 /* GK->GW */
134 pr_debug("nf_nat_ras: set signal address " 133 pr_debug("nf_nat_ras: set signal address %pI4:%hu->%pI4:%hu\n",
135 "%u.%u.%u.%u:%hu->%u.%u.%u.%u:%hu\n", 134 &addr.ip, port,
136 NIPQUAD(addr.ip), port, 135 &ct->tuplehash[!dir].tuple.src.u3.ip,
137 NIPQUAD(ct->tuplehash[!dir].tuple.src.u3.ip),
138 info->sig_port[!dir]); 136 info->sig_port[!dir]);
139 return set_h225_addr(skb, data, 0, &taddr[i], 137 return set_h225_addr(skb, data, 0, &taddr[i],
140 &ct->tuplehash[!dir]. 138 &ct->tuplehash[!dir].
@@ -162,10 +160,9 @@ static int set_ras_addr(struct sk_buff *skb, struct nf_conn *ct,
162 if (get_h225_addr(ct, *data, &taddr[i], &addr, &port) && 160 if (get_h225_addr(ct, *data, &taddr[i], &addr, &port) &&
163 addr.ip == ct->tuplehash[dir].tuple.src.u3.ip && 161 addr.ip == ct->tuplehash[dir].tuple.src.u3.ip &&
164 port == ct->tuplehash[dir].tuple.src.u.udp.port) { 162 port == ct->tuplehash[dir].tuple.src.u.udp.port) {
165 pr_debug("nf_nat_ras: set rasAddress " 163 pr_debug("nf_nat_ras: set rasAddress %pI4:%hu->%pI4:%hu\n",
166 "%u.%u.%u.%u:%hu->%u.%u.%u.%u:%hu\n", 164 &addr.ip, ntohs(port),
167 NIPQUAD(addr.ip), ntohs(port), 165 &ct->tuplehash[!dir].tuple.dst.u3.ip,
168 NIPQUAD(ct->tuplehash[!dir].tuple.dst.u3.ip),
169 ntohs(ct->tuplehash[!dir].tuple.dst.u.udp.port)); 166 ntohs(ct->tuplehash[!dir].tuple.dst.u.udp.port));
170 return set_h225_addr(skb, data, 0, &taddr[i], 167 return set_h225_addr(skb, data, 0, &taddr[i],
171 &ct->tuplehash[!dir].tuple.dst.u3, 168 &ct->tuplehash[!dir].tuple.dst.u3,
@@ -257,15 +254,15 @@ static int nat_rtp_rtcp(struct sk_buff *skb, struct nf_conn *ct,
257 } 254 }
258 255
259 /* Success */ 256 /* Success */
260 pr_debug("nf_nat_h323: expect RTP %u.%u.%u.%u:%hu->%u.%u.%u.%u:%hu\n", 257 pr_debug("nf_nat_h323: expect RTP %pI4:%hu->%pI4:%hu\n",
261 NIPQUAD(rtp_exp->tuple.src.u3.ip), 258 &rtp_exp->tuple.src.u3.ip,
262 ntohs(rtp_exp->tuple.src.u.udp.port), 259 ntohs(rtp_exp->tuple.src.u.udp.port),
263 NIPQUAD(rtp_exp->tuple.dst.u3.ip), 260 &rtp_exp->tuple.dst.u3.ip,
264 ntohs(rtp_exp->tuple.dst.u.udp.port)); 261 ntohs(rtp_exp->tuple.dst.u.udp.port));
265 pr_debug("nf_nat_h323: expect RTCP %u.%u.%u.%u:%hu->%u.%u.%u.%u:%hu\n", 262 pr_debug("nf_nat_h323: expect RTCP %pI4:%hu->%pI4:%hu\n",
266 NIPQUAD(rtcp_exp->tuple.src.u3.ip), 263 &rtcp_exp->tuple.src.u3.ip,
267 ntohs(rtcp_exp->tuple.src.u.udp.port), 264 ntohs(rtcp_exp->tuple.src.u.udp.port),
268 NIPQUAD(rtcp_exp->tuple.dst.u3.ip), 265 &rtcp_exp->tuple.dst.u3.ip,
269 ntohs(rtcp_exp->tuple.dst.u.udp.port)); 266 ntohs(rtcp_exp->tuple.dst.u.udp.port));
270 267
271 return 0; 268 return 0;
@@ -307,10 +304,10 @@ static int nat_t120(struct sk_buff *skb, struct nf_conn *ct,
307 return -1; 304 return -1;
308 } 305 }
309 306
310 pr_debug("nf_nat_h323: expect T.120 %u.%u.%u.%u:%hu->%u.%u.%u.%u:%hu\n", 307 pr_debug("nf_nat_h323: expect T.120 %pI4:%hu->%pI4:%hu\n",
311 NIPQUAD(exp->tuple.src.u3.ip), 308 &exp->tuple.src.u3.ip,
312 ntohs(exp->tuple.src.u.tcp.port), 309 ntohs(exp->tuple.src.u.tcp.port),
313 NIPQUAD(exp->tuple.dst.u3.ip), 310 &exp->tuple.dst.u3.ip,
314 ntohs(exp->tuple.dst.u.tcp.port)); 311 ntohs(exp->tuple.dst.u.tcp.port));
315 312
316 return 0; 313 return 0;
@@ -361,10 +358,10 @@ static int nat_h245(struct sk_buff *skb, struct nf_conn *ct,
361 return -1; 358 return -1;
362 } 359 }
363 360
364 pr_debug("nf_nat_q931: expect H.245 %u.%u.%u.%u:%hu->%u.%u.%u.%u:%hu\n", 361 pr_debug("nf_nat_q931: expect H.245 %pI4:%hu->%pI4:%hu\n",
365 NIPQUAD(exp->tuple.src.u3.ip), 362 &exp->tuple.src.u3.ip,
366 ntohs(exp->tuple.src.u.tcp.port), 363 ntohs(exp->tuple.src.u.tcp.port),
367 NIPQUAD(exp->tuple.dst.u3.ip), 364 &exp->tuple.dst.u3.ip,
368 ntohs(exp->tuple.dst.u.tcp.port)); 365 ntohs(exp->tuple.dst.u.tcp.port));
369 366
370 return 0; 367 return 0;
@@ -455,10 +452,10 @@ static int nat_q931(struct sk_buff *skb, struct nf_conn *ct,
455 } 452 }
456 453
457 /* Success */ 454 /* Success */
458 pr_debug("nf_nat_ras: expect Q.931 %u.%u.%u.%u:%hu->%u.%u.%u.%u:%hu\n", 455 pr_debug("nf_nat_ras: expect Q.931 %pI4:%hu->%pI4:%hu\n",
459 NIPQUAD(exp->tuple.src.u3.ip), 456 &exp->tuple.src.u3.ip,
460 ntohs(exp->tuple.src.u.tcp.port), 457 ntohs(exp->tuple.src.u.tcp.port),
461 NIPQUAD(exp->tuple.dst.u3.ip), 458 &exp->tuple.dst.u3.ip,
462 ntohs(exp->tuple.dst.u.tcp.port)); 459 ntohs(exp->tuple.dst.u.tcp.port));
463 460
464 return 0; 461 return 0;
@@ -524,11 +521,10 @@ static int nat_callforwarding(struct sk_buff *skb, struct nf_conn *ct,
524 } 521 }
525 522
526 /* Success */ 523 /* Success */
527 pr_debug("nf_nat_q931: expect Call Forwarding " 524 pr_debug("nf_nat_q931: expect Call Forwarding %pI4:%hu->%pI4:%hu\n",
528 "%u.%u.%u.%u:%hu->%u.%u.%u.%u:%hu\n", 525 &exp->tuple.src.u3.ip,
529 NIPQUAD(exp->tuple.src.u3.ip),
530 ntohs(exp->tuple.src.u.tcp.port), 526 ntohs(exp->tuple.src.u.tcp.port),
531 NIPQUAD(exp->tuple.dst.u3.ip), 527 &exp->tuple.dst.u3.ip,
532 ntohs(exp->tuple.dst.u.tcp.port)); 528 ntohs(exp->tuple.dst.u.tcp.port));
533 529
534 return 0; 530 return 0;
diff --git a/net/ipv4/netfilter/nf_nat_irc.c b/net/ipv4/netfilter/nf_nat_irc.c
index fe6f9cef6c85..ea83a886b03e 100644
--- a/net/ipv4/netfilter/nf_nat_irc.c
+++ b/net/ipv4/netfilter/nf_nat_irc.c
@@ -55,8 +55,8 @@ static unsigned int help(struct sk_buff *skb,
55 55
56 ip = ntohl(exp->master->tuplehash[IP_CT_DIR_REPLY].tuple.dst.u3.ip); 56 ip = ntohl(exp->master->tuplehash[IP_CT_DIR_REPLY].tuple.dst.u3.ip);
57 sprintf(buffer, "%u %u", ip, port); 57 sprintf(buffer, "%u %u", ip, port);
58 pr_debug("nf_nat_irc: inserting '%s' == %u.%u.%u.%u, port %u\n", 58 pr_debug("nf_nat_irc: inserting '%s' == %pI4, port %u\n",
59 buffer, NIPQUAD(ip), port); 59 buffer, &ip, port);
60 60
61 ret = nf_nat_mangle_tcp_packet(skb, exp->master, ctinfo, 61 ret = nf_nat_mangle_tcp_packet(skb, exp->master, ctinfo,
62 matchoff, matchlen, buffer, 62 matchoff, matchlen, buffer,
diff --git a/net/ipv4/netfilter/nf_nat_rule.c b/net/ipv4/netfilter/nf_nat_rule.c
index 8d489e746b21..a7eb04719044 100644
--- a/net/ipv4/netfilter/nf_nat_rule.c
+++ b/net/ipv4/netfilter/nf_nat_rule.c
@@ -86,25 +86,6 @@ ipt_snat_target(struct sk_buff *skb, const struct xt_target_param *par)
86 return nf_nat_setup_info(ct, &mr->range[0], IP_NAT_MANIP_SRC); 86 return nf_nat_setup_info(ct, &mr->range[0], IP_NAT_MANIP_SRC);
87} 87}
88 88
89/* Before 2.6.11 we did implicit source NAT if required. Warn about change. */
90static void warn_if_extra_mangle(struct net *net, __be32 dstip, __be32 srcip)
91{
92 static int warned = 0;
93 struct flowi fl = { .nl_u = { .ip4_u = { .daddr = dstip } } };
94 struct rtable *rt;
95
96 if (ip_route_output_key(net, &rt, &fl) != 0)
97 return;
98
99 if (rt->rt_src != srcip && !warned) {
100 printk("NAT: no longer support implicit source local NAT\n");
101 printk("NAT: packet src %u.%u.%u.%u -> dst %u.%u.%u.%u\n",
102 NIPQUAD(srcip), NIPQUAD(dstip));
103 warned = 1;
104 }
105 ip_rt_put(rt);
106}
107
108static unsigned int 89static unsigned int
109ipt_dnat_target(struct sk_buff *skb, const struct xt_target_param *par) 90ipt_dnat_target(struct sk_buff *skb, const struct xt_target_param *par)
110{ 91{
@@ -120,11 +101,6 @@ ipt_dnat_target(struct sk_buff *skb, const struct xt_target_param *par)
120 /* Connection must be valid and new. */ 101 /* Connection must be valid and new. */
121 NF_CT_ASSERT(ct && (ctinfo == IP_CT_NEW || ctinfo == IP_CT_RELATED)); 102 NF_CT_ASSERT(ct && (ctinfo == IP_CT_NEW || ctinfo == IP_CT_RELATED));
122 103
123 if (par->hooknum == NF_INET_LOCAL_OUT &&
124 mr->range[0].flags & IP_NAT_RANGE_MAP_IPS)
125 warn_if_extra_mangle(dev_net(par->out), ip_hdr(skb)->daddr,
126 mr->range[0].min_ip);
127
128 return nf_nat_setup_info(ct, &mr->range[0], IP_NAT_MANIP_DST); 104 return nf_nat_setup_info(ct, &mr->range[0], IP_NAT_MANIP_DST);
129} 105}
130 106
@@ -166,8 +142,7 @@ alloc_null_binding(struct nf_conn *ct, unsigned int hooknum)
166 struct nf_nat_range range 142 struct nf_nat_range range
167 = { IP_NAT_RANGE_MAP_IPS, ip, ip, { 0 }, { 0 } }; 143 = { IP_NAT_RANGE_MAP_IPS, ip, ip, { 0 }, { 0 } };
168 144
169 pr_debug("Allocating NULL binding for %p (%u.%u.%u.%u)\n", 145 pr_debug("Allocating NULL binding for %p (%pI4)\n", ct, &ip);
170 ct, NIPQUAD(ip));
171 return nf_nat_setup_info(ct, &range, HOOK2MANIP(hooknum)); 146 return nf_nat_setup_info(ct, &range, HOOK2MANIP(hooknum));
172} 147}
173 148
diff --git a/net/ipv4/netfilter/nf_nat_sip.c b/net/ipv4/netfilter/nf_nat_sip.c
index 14544320c545..07d61a57613c 100644
--- a/net/ipv4/netfilter/nf_nat_sip.c
+++ b/net/ipv4/netfilter/nf_nat_sip.c
@@ -74,8 +74,7 @@ static int map_addr(struct sk_buff *skb,
74 if (newaddr == addr->ip && newport == port) 74 if (newaddr == addr->ip && newport == port)
75 return 1; 75 return 1;
76 76
77 buflen = sprintf(buffer, "%u.%u.%u.%u:%u", 77 buflen = sprintf(buffer, "%pI4:%u", &newaddr, ntohs(newport));
78 NIPQUAD(newaddr), ntohs(newport));
79 78
80 return mangle_packet(skb, dptr, datalen, matchoff, matchlen, 79 return mangle_packet(skb, dptr, datalen, matchoff, matchlen,
81 buffer, buflen); 80 buffer, buflen);
@@ -152,8 +151,8 @@ static unsigned int ip_nat_sip(struct sk_buff *skb,
152 &addr) > 0 && 151 &addr) > 0 &&
153 addr.ip == ct->tuplehash[dir].tuple.src.u3.ip && 152 addr.ip == ct->tuplehash[dir].tuple.src.u3.ip &&
154 addr.ip != ct->tuplehash[!dir].tuple.dst.u3.ip) { 153 addr.ip != ct->tuplehash[!dir].tuple.dst.u3.ip) {
155 __be32 ip = ct->tuplehash[!dir].tuple.dst.u3.ip; 154 buflen = sprintf(buffer, "%pI4",
156 buflen = sprintf(buffer, "%u.%u.%u.%u", NIPQUAD(ip)); 155 &ct->tuplehash[!dir].tuple.dst.u3.ip);
157 if (!mangle_packet(skb, dptr, datalen, poff, plen, 156 if (!mangle_packet(skb, dptr, datalen, poff, plen,
158 buffer, buflen)) 157 buffer, buflen))
159 return NF_DROP; 158 return NF_DROP;
@@ -166,8 +165,8 @@ static unsigned int ip_nat_sip(struct sk_buff *skb,
166 &addr) > 0 && 165 &addr) > 0 &&
167 addr.ip == ct->tuplehash[dir].tuple.dst.u3.ip && 166 addr.ip == ct->tuplehash[dir].tuple.dst.u3.ip &&
168 addr.ip != ct->tuplehash[!dir].tuple.src.u3.ip) { 167 addr.ip != ct->tuplehash[!dir].tuple.src.u3.ip) {
169 __be32 ip = ct->tuplehash[!dir].tuple.src.u3.ip; 168 buflen = sprintf(buffer, "%pI4",
170 buflen = sprintf(buffer, "%u.%u.%u.%u", NIPQUAD(ip)); 169 &ct->tuplehash[!dir].tuple.src.u3.ip);
171 if (!mangle_packet(skb, dptr, datalen, poff, plen, 170 if (!mangle_packet(skb, dptr, datalen, poff, plen,
172 buffer, buflen)) 171 buffer, buflen))
173 return NF_DROP; 172 return NF_DROP;
@@ -279,8 +278,7 @@ static unsigned int ip_nat_sip_expect(struct sk_buff *skb,
279 278
280 if (exp->tuple.dst.u3.ip != exp->saved_ip || 279 if (exp->tuple.dst.u3.ip != exp->saved_ip ||
281 exp->tuple.dst.u.udp.port != exp->saved_proto.udp.port) { 280 exp->tuple.dst.u.udp.port != exp->saved_proto.udp.port) {
282 buflen = sprintf(buffer, "%u.%u.%u.%u:%u", 281 buflen = sprintf(buffer, "%pI4:%u", &newip, port);
283 NIPQUAD(newip), port);
284 if (!mangle_packet(skb, dptr, datalen, matchoff, matchlen, 282 if (!mangle_packet(skb, dptr, datalen, matchoff, matchlen,
285 buffer, buflen)) 283 buffer, buflen))
286 goto err; 284 goto err;
@@ -345,7 +343,7 @@ static unsigned int ip_nat_sdp_addr(struct sk_buff *skb, const char **dptr,
345 char buffer[sizeof("nnn.nnn.nnn.nnn")]; 343 char buffer[sizeof("nnn.nnn.nnn.nnn")];
346 unsigned int buflen; 344 unsigned int buflen;
347 345
348 buflen = sprintf(buffer, NIPQUAD_FMT, NIPQUAD(addr->ip)); 346 buflen = sprintf(buffer, "%pI4", &addr->ip);
349 if (mangle_sdp_packet(skb, dptr, dataoff, datalen, type, term, 347 if (mangle_sdp_packet(skb, dptr, dataoff, datalen, type, term,
350 buffer, buflen)) 348 buffer, buflen))
351 return 0; 349 return 0;
@@ -380,7 +378,7 @@ static unsigned int ip_nat_sdp_session(struct sk_buff *skb, const char **dptr,
380 unsigned int buflen; 378 unsigned int buflen;
381 379
382 /* Mangle session description owner and contact addresses */ 380 /* Mangle session description owner and contact addresses */
383 buflen = sprintf(buffer, "%u.%u.%u.%u", NIPQUAD(addr->ip)); 381 buflen = sprintf(buffer, "%pI4", &addr->ip);
384 if (mangle_sdp_packet(skb, dptr, dataoff, datalen, 382 if (mangle_sdp_packet(skb, dptr, dataoff, datalen,
385 SDP_HDR_OWNER_IP4, SDP_HDR_MEDIA, 383 SDP_HDR_OWNER_IP4, SDP_HDR_MEDIA,
386 buffer, buflen)) 384 buffer, buflen))
diff --git a/net/ipv4/netfilter/nf_nat_snmp_basic.c b/net/ipv4/netfilter/nf_nat_snmp_basic.c
index 8303e4b406c0..182f845de92f 100644
--- a/net/ipv4/netfilter/nf_nat_snmp_basic.c
+++ b/net/ipv4/netfilter/nf_nat_snmp_basic.c
@@ -930,8 +930,8 @@ static inline void mangle_address(unsigned char *begin,
930 } 930 }
931 931
932 if (debug) 932 if (debug)
933 printk(KERN_DEBUG "bsalg: mapped %u.%u.%u.%u to " 933 printk(KERN_DEBUG "bsalg: mapped %pI4 to %pI4\n",
934 "%u.%u.%u.%u\n", NIPQUAD(old), NIPQUAD(*addr)); 934 &old, addr);
935 } 935 }
936} 936}
937 937
@@ -1267,9 +1267,8 @@ static int help(struct sk_buff *skb, unsigned int protoff,
1267 */ 1267 */
1268 if (ntohs(udph->len) != skb->len - (iph->ihl << 2)) { 1268 if (ntohs(udph->len) != skb->len - (iph->ihl << 2)) {
1269 if (net_ratelimit()) 1269 if (net_ratelimit())
1270 printk(KERN_WARNING "SNMP: dropping malformed packet " 1270 printk(KERN_WARNING "SNMP: dropping malformed packet src=%pI4 dst=%pI4\n",
1271 "src=%u.%u.%u.%u dst=%u.%u.%u.%u\n", 1271 &iph->saddr, &iph->daddr);
1272 NIPQUAD(iph->saddr), NIPQUAD(iph->daddr));
1273 return NF_DROP; 1272 return NF_DROP;
1274 } 1273 }
1275 1274
diff --git a/net/ipv4/proc.c b/net/ipv4/proc.c
index a631a1f110ca..614958b7c276 100644
--- a/net/ipv4/proc.c
+++ b/net/ipv4/proc.c
@@ -54,8 +54,9 @@ static int sockstat_seq_show(struct seq_file *seq, void *v)
54 socket_seq_show(seq); 54 socket_seq_show(seq);
55 seq_printf(seq, "TCP: inuse %d orphan %d tw %d alloc %d mem %d\n", 55 seq_printf(seq, "TCP: inuse %d orphan %d tw %d alloc %d mem %d\n",
56 sock_prot_inuse_get(net, &tcp_prot), 56 sock_prot_inuse_get(net, &tcp_prot),
57 atomic_read(&tcp_orphan_count), 57 (int)percpu_counter_sum_positive(&tcp_orphan_count),
58 tcp_death_row.tw_count, atomic_read(&tcp_sockets_allocated), 58 tcp_death_row.tw_count,
59 (int)percpu_counter_sum_positive(&tcp_sockets_allocated),
59 atomic_read(&tcp_memory_allocated)); 60 atomic_read(&tcp_memory_allocated));
60 seq_printf(seq, "UDP: inuse %d mem %d\n", 61 seq_printf(seq, "UDP: inuse %d mem %d\n",
61 sock_prot_inuse_get(net, &udp_prot), 62 sock_prot_inuse_get(net, &udp_prot),
@@ -234,6 +235,9 @@ static const struct snmp_mib snmp4_net_list[] = {
234 SNMP_MIB_ITEM("TCPSpuriousRTOs", LINUX_MIB_TCPSPURIOUSRTOS), 235 SNMP_MIB_ITEM("TCPSpuriousRTOs", LINUX_MIB_TCPSPURIOUSRTOS),
235 SNMP_MIB_ITEM("TCPMD5NotFound", LINUX_MIB_TCPMD5NOTFOUND), 236 SNMP_MIB_ITEM("TCPMD5NotFound", LINUX_MIB_TCPMD5NOTFOUND),
236 SNMP_MIB_ITEM("TCPMD5Unexpected", LINUX_MIB_TCPMD5UNEXPECTED), 237 SNMP_MIB_ITEM("TCPMD5Unexpected", LINUX_MIB_TCPMD5UNEXPECTED),
238 SNMP_MIB_ITEM("TCPSackShifted", LINUX_MIB_SACKSHIFTED),
239 SNMP_MIB_ITEM("TCPSackMerged", LINUX_MIB_SACKMERGED),
240 SNMP_MIB_ITEM("TCPSackShiftFallback", LINUX_MIB_SACKSHIFTFALLBACK),
237 SNMP_MIB_SENTINEL 241 SNMP_MIB_SENTINEL
238}; 242};
239 243
diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
index cd975743bcd2..dff8bc4e0fac 100644
--- a/net/ipv4/raw.c
+++ b/net/ipv4/raw.c
@@ -247,7 +247,7 @@ static void raw_err(struct sock *sk, struct sk_buff *skb, u32 info)
247 } 247 }
248 248
249 if (inet->recverr) { 249 if (inet->recverr) {
250 struct iphdr *iph = (struct iphdr*)skb->data; 250 struct iphdr *iph = (struct iphdr *)skb->data;
251 u8 *payload = skb->data + (iph->ihl << 2); 251 u8 *payload = skb->data + (iph->ihl << 2);
252 252
253 if (inet->hdrincl) 253 if (inet->hdrincl)
@@ -465,7 +465,7 @@ static int raw_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
465 */ 465 */
466 466
467 if (msg->msg_namelen) { 467 if (msg->msg_namelen) {
468 struct sockaddr_in *usin = (struct sockaddr_in*)msg->msg_name; 468 struct sockaddr_in *usin = (struct sockaddr_in *)msg->msg_name;
469 err = -EINVAL; 469 err = -EINVAL;
470 if (msg->msg_namelen < sizeof(*usin)) 470 if (msg->msg_namelen < sizeof(*usin))
471 goto out; 471 goto out;
@@ -572,7 +572,7 @@ back_from_confirm:
572 ipc.addr = rt->rt_dst; 572 ipc.addr = rt->rt_dst;
573 lock_sock(sk); 573 lock_sock(sk);
574 err = ip_append_data(sk, ip_generic_getfrag, msg->msg_iov, len, 0, 574 err = ip_append_data(sk, ip_generic_getfrag, msg->msg_iov, len, 0,
575 &ipc, rt, msg->msg_flags); 575 &ipc, &rt, msg->msg_flags);
576 if (err) 576 if (err)
577 ip_flush_pending_frames(sk); 577 ip_flush_pending_frames(sk);
578 else if (!(msg->msg_flags & MSG_MORE)) 578 else if (!(msg->msg_flags & MSG_MORE))
@@ -851,7 +851,7 @@ struct proto raw_prot = {
851static struct sock *raw_get_first(struct seq_file *seq) 851static struct sock *raw_get_first(struct seq_file *seq)
852{ 852{
853 struct sock *sk; 853 struct sock *sk;
854 struct raw_iter_state* state = raw_seq_private(seq); 854 struct raw_iter_state *state = raw_seq_private(seq);
855 855
856 for (state->bucket = 0; state->bucket < RAW_HTABLE_SIZE; 856 for (state->bucket = 0; state->bucket < RAW_HTABLE_SIZE;
857 ++state->bucket) { 857 ++state->bucket) {
@@ -868,7 +868,7 @@ found:
868 868
869static struct sock *raw_get_next(struct seq_file *seq, struct sock *sk) 869static struct sock *raw_get_next(struct seq_file *seq, struct sock *sk)
870{ 870{
871 struct raw_iter_state* state = raw_seq_private(seq); 871 struct raw_iter_state *state = raw_seq_private(seq);
872 872
873 do { 873 do {
874 sk = sk_next(sk); 874 sk = sk_next(sk);
diff --git a/net/ipv4/route.c b/net/ipv4/route.c
index 2ea6dcc3e2cc..77bfba975959 100644
--- a/net/ipv4/route.c
+++ b/net/ipv4/route.c
@@ -129,6 +129,7 @@ static int ip_rt_mtu_expires __read_mostly = 10 * 60 * HZ;
129static int ip_rt_min_pmtu __read_mostly = 512 + 20 + 20; 129static int ip_rt_min_pmtu __read_mostly = 512 + 20 + 20;
130static int ip_rt_min_advmss __read_mostly = 256; 130static int ip_rt_min_advmss __read_mostly = 256;
131static int ip_rt_secret_interval __read_mostly = 10 * 60 * HZ; 131static int ip_rt_secret_interval __read_mostly = 10 * 60 * HZ;
132static int rt_chain_length_max __read_mostly = 20;
132 133
133static void rt_worker_func(struct work_struct *work); 134static void rt_worker_func(struct work_struct *work);
134static DECLARE_DELAYED_WORK(expires_work, rt_worker_func); 135static DECLARE_DELAYED_WORK(expires_work, rt_worker_func);
@@ -145,6 +146,7 @@ static struct dst_entry *ipv4_negative_advice(struct dst_entry *dst);
145static void ipv4_link_failure(struct sk_buff *skb); 146static void ipv4_link_failure(struct sk_buff *skb);
146static void ip_rt_update_pmtu(struct dst_entry *dst, u32 mtu); 147static void ip_rt_update_pmtu(struct dst_entry *dst, u32 mtu);
147static int rt_garbage_collect(struct dst_ops *ops); 148static int rt_garbage_collect(struct dst_ops *ops);
149static void rt_emergency_hash_rebuild(struct net *net);
148 150
149 151
150static struct dst_ops ipv4_dst_ops = { 152static struct dst_ops ipv4_dst_ops = {
@@ -158,7 +160,6 @@ static struct dst_ops ipv4_dst_ops = {
158 .link_failure = ipv4_link_failure, 160 .link_failure = ipv4_link_failure,
159 .update_pmtu = ip_rt_update_pmtu, 161 .update_pmtu = ip_rt_update_pmtu,
160 .local_out = __ip_local_out, 162 .local_out = __ip_local_out,
161 .entry_size = sizeof(struct rtable),
162 .entries = ATOMIC_INIT(0), 163 .entries = ATOMIC_INIT(0),
163}; 164};
164 165
@@ -201,6 +202,7 @@ const __u8 ip_tos2prio[16] = {
201struct rt_hash_bucket { 202struct rt_hash_bucket {
202 struct rtable *chain; 203 struct rtable *chain;
203}; 204};
205
204#if defined(CONFIG_SMP) || defined(CONFIG_DEBUG_SPINLOCK) || \ 206#if defined(CONFIG_SMP) || defined(CONFIG_DEBUG_SPINLOCK) || \
205 defined(CONFIG_PROVE_LOCKING) 207 defined(CONFIG_PROVE_LOCKING)
206/* 208/*
@@ -674,6 +676,20 @@ static inline u32 rt_score(struct rtable *rt)
674 return score; 676 return score;
675} 677}
676 678
679static inline bool rt_caching(const struct net *net)
680{
681 return net->ipv4.current_rt_cache_rebuild_count <=
682 net->ipv4.sysctl_rt_cache_rebuild_count;
683}
684
685static inline bool compare_hash_inputs(const struct flowi *fl1,
686 const struct flowi *fl2)
687{
688 return (__force u32)(((fl1->nl_u.ip4_u.daddr ^ fl2->nl_u.ip4_u.daddr) |
689 (fl1->nl_u.ip4_u.saddr ^ fl2->nl_u.ip4_u.saddr) |
690 (fl1->iif ^ fl2->iif)) == 0);
691}
692
677static inline int compare_keys(struct flowi *fl1, struct flowi *fl2) 693static inline int compare_keys(struct flowi *fl1, struct flowi *fl2)
678{ 694{
679 return ((__force u32)((fl1->nl_u.ip4_u.daddr ^ fl2->nl_u.ip4_u.daddr) | 695 return ((__force u32)((fl1->nl_u.ip4_u.daddr ^ fl2->nl_u.ip4_u.daddr) |
@@ -753,11 +769,24 @@ static void rt_do_flush(int process_context)
753 } 769 }
754} 770}
755 771
772/*
773 * While freeing expired entries, we compute average chain length
774 * and standard deviation, using fixed-point arithmetic.
775 * This to have an estimation of rt_chain_length_max
776 * rt_chain_length_max = max(elasticity, AVG + 4*SD)
777 * We use 3 bits for frational part, and 29 (or 61) for magnitude.
778 */
779
780#define FRACT_BITS 3
781#define ONE (1UL << FRACT_BITS)
782
756static void rt_check_expire(void) 783static void rt_check_expire(void)
757{ 784{
758 static unsigned int rover; 785 static unsigned int rover;
759 unsigned int i = rover, goal; 786 unsigned int i = rover, goal;
760 struct rtable *rth, **rthp; 787 struct rtable *rth, **rthp;
788 unsigned long length = 0, samples = 0;
789 unsigned long sum = 0, sum2 = 0;
761 u64 mult; 790 u64 mult;
762 791
763 mult = ((u64)ip_rt_gc_interval) << rt_hash_log; 792 mult = ((u64)ip_rt_gc_interval) << rt_hash_log;
@@ -766,6 +795,7 @@ static void rt_check_expire(void)
766 goal = (unsigned int)mult; 795 goal = (unsigned int)mult;
767 if (goal > rt_hash_mask) 796 if (goal > rt_hash_mask)
768 goal = rt_hash_mask + 1; 797 goal = rt_hash_mask + 1;
798 length = 0;
769 for (; goal > 0; goal--) { 799 for (; goal > 0; goal--) {
770 unsigned long tmo = ip_rt_gc_timeout; 800 unsigned long tmo = ip_rt_gc_timeout;
771 801
@@ -775,6 +805,8 @@ static void rt_check_expire(void)
775 if (need_resched()) 805 if (need_resched())
776 cond_resched(); 806 cond_resched();
777 807
808 samples++;
809
778 if (*rthp == NULL) 810 if (*rthp == NULL)
779 continue; 811 continue;
780 spin_lock_bh(rt_hash_lock_addr(i)); 812 spin_lock_bh(rt_hash_lock_addr(i));
@@ -789,11 +821,29 @@ static void rt_check_expire(void)
789 if (time_before_eq(jiffies, rth->u.dst.expires)) { 821 if (time_before_eq(jiffies, rth->u.dst.expires)) {
790 tmo >>= 1; 822 tmo >>= 1;
791 rthp = &rth->u.dst.rt_next; 823 rthp = &rth->u.dst.rt_next;
824 /*
825 * Only bump our length if the hash
826 * inputs on entries n and n+1 are not
827 * the same, we only count entries on
828 * a chain with equal hash inputs once
829 * so that entries for different QOS
830 * levels, and other non-hash input
831 * attributes don't unfairly skew
832 * the length computation
833 */
834 if ((*rthp == NULL) ||
835 !compare_hash_inputs(&(*rthp)->fl,
836 &rth->fl))
837 length += ONE;
792 continue; 838 continue;
793 } 839 }
794 } else if (!rt_may_expire(rth, tmo, ip_rt_gc_timeout)) { 840 } else if (!rt_may_expire(rth, tmo, ip_rt_gc_timeout)) {
795 tmo >>= 1; 841 tmo >>= 1;
796 rthp = &rth->u.dst.rt_next; 842 rthp = &rth->u.dst.rt_next;
843 if ((*rthp == NULL) ||
844 !compare_hash_inputs(&(*rthp)->fl,
845 &rth->fl))
846 length += ONE;
797 continue; 847 continue;
798 } 848 }
799 849
@@ -802,6 +852,15 @@ static void rt_check_expire(void)
802 rt_free(rth); 852 rt_free(rth);
803 } 853 }
804 spin_unlock_bh(rt_hash_lock_addr(i)); 854 spin_unlock_bh(rt_hash_lock_addr(i));
855 sum += length;
856 sum2 += length*length;
857 }
858 if (samples) {
859 unsigned long avg = sum / samples;
860 unsigned long sd = int_sqrt(sum2 / samples - avg*avg);
861 rt_chain_length_max = max_t(unsigned long,
862 ip_rt_gc_elasticity,
863 (avg + 4*sd) >> FRACT_BITS);
805 } 864 }
806 rover = i; 865 rover = i;
807} 866}
@@ -851,6 +910,26 @@ static void rt_secret_rebuild(unsigned long __net)
851 mod_timer(&net->ipv4.rt_secret_timer, jiffies + ip_rt_secret_interval); 910 mod_timer(&net->ipv4.rt_secret_timer, jiffies + ip_rt_secret_interval);
852} 911}
853 912
913static void rt_secret_rebuild_oneshot(struct net *net)
914{
915 del_timer_sync(&net->ipv4.rt_secret_timer);
916 rt_cache_invalidate(net);
917 if (ip_rt_secret_interval) {
918 net->ipv4.rt_secret_timer.expires += ip_rt_secret_interval;
919 add_timer(&net->ipv4.rt_secret_timer);
920 }
921}
922
923static void rt_emergency_hash_rebuild(struct net *net)
924{
925 if (net_ratelimit()) {
926 printk(KERN_WARNING "Route hash chain too long!\n");
927 printk(KERN_WARNING "Adjust your secret_interval!\n");
928 }
929
930 rt_secret_rebuild_oneshot(net);
931}
932
854/* 933/*
855 Short description of GC goals. 934 Short description of GC goals.
856 935
@@ -989,6 +1068,7 @@ out: return 0;
989static int rt_intern_hash(unsigned hash, struct rtable *rt, struct rtable **rp) 1068static int rt_intern_hash(unsigned hash, struct rtable *rt, struct rtable **rp)
990{ 1069{
991 struct rtable *rth, **rthp; 1070 struct rtable *rth, **rthp;
1071 struct rtable *rthi;
992 unsigned long now; 1072 unsigned long now;
993 struct rtable *cand, **candp; 1073 struct rtable *cand, **candp;
994 u32 min_score; 1074 u32 min_score;
@@ -1002,7 +1082,13 @@ restart:
1002 candp = NULL; 1082 candp = NULL;
1003 now = jiffies; 1083 now = jiffies;
1004 1084
1085 if (!rt_caching(dev_net(rt->u.dst.dev))) {
1086 rt_drop(rt);
1087 return 0;
1088 }
1089
1005 rthp = &rt_hash_table[hash].chain; 1090 rthp = &rt_hash_table[hash].chain;
1091 rthi = NULL;
1006 1092
1007 spin_lock_bh(rt_hash_lock_addr(hash)); 1093 spin_lock_bh(rt_hash_lock_addr(hash));
1008 while ((rth = *rthp) != NULL) { 1094 while ((rth = *rthp) != NULL) {
@@ -1048,6 +1134,17 @@ restart:
1048 chain_length++; 1134 chain_length++;
1049 1135
1050 rthp = &rth->u.dst.rt_next; 1136 rthp = &rth->u.dst.rt_next;
1137
1138 /*
1139 * check to see if the next entry in the chain
1140 * contains the same hash input values as rt. If it does
1141 * This is where we will insert into the list, instead of
1142 * at the head. This groups entries that differ by aspects not
1143 * relvant to the hash function together, which we use to adjust
1144 * our chain length
1145 */
1146 if (*rthp && compare_hash_inputs(&(*rthp)->fl, &rt->fl))
1147 rthi = rth;
1051 } 1148 }
1052 1149
1053 if (cand) { 1150 if (cand) {
@@ -1061,6 +1158,16 @@ restart:
1061 *candp = cand->u.dst.rt_next; 1158 *candp = cand->u.dst.rt_next;
1062 rt_free(cand); 1159 rt_free(cand);
1063 } 1160 }
1161 } else {
1162 if (chain_length > rt_chain_length_max) {
1163 struct net *net = dev_net(rt->u.dst.dev);
1164 int num = ++net->ipv4.current_rt_cache_rebuild_count;
1165 if (!rt_caching(dev_net(rt->u.dst.dev))) {
1166 printk(KERN_WARNING "%s: %d rebuilds is over limit, route caching disabled\n",
1167 rt->u.dst.dev->name, num);
1168 }
1169 rt_emergency_hash_rebuild(dev_net(rt->u.dst.dev));
1170 }
1064 } 1171 }
1065 1172
1066 /* Try to bind route to arp only if it is output 1173 /* Try to bind route to arp only if it is output
@@ -1098,14 +1205,17 @@ restart:
1098 } 1205 }
1099 } 1206 }
1100 1207
1101 rt->u.dst.rt_next = rt_hash_table[hash].chain; 1208 if (rthi)
1209 rt->u.dst.rt_next = rthi->u.dst.rt_next;
1210 else
1211 rt->u.dst.rt_next = rt_hash_table[hash].chain;
1212
1102#if RT_CACHE_DEBUG >= 2 1213#if RT_CACHE_DEBUG >= 2
1103 if (rt->u.dst.rt_next) { 1214 if (rt->u.dst.rt_next) {
1104 struct rtable *trt; 1215 struct rtable *trt;
1105 printk(KERN_DEBUG "rt_cache @%02x: " NIPQUAD_FMT, hash, 1216 printk(KERN_DEBUG "rt_cache @%02x: %pI4", hash, &rt->rt_dst);
1106 NIPQUAD(rt->rt_dst));
1107 for (trt = rt->u.dst.rt_next; trt; trt = trt->u.dst.rt_next) 1217 for (trt = rt->u.dst.rt_next; trt; trt = trt->u.dst.rt_next)
1108 printk(" . " NIPQUAD_FMT, NIPQUAD(trt->rt_dst)); 1218 printk(" . %pI4", &trt->rt_dst);
1109 printk("\n"); 1219 printk("\n");
1110 } 1220 }
1111#endif 1221#endif
@@ -1114,7 +1224,11 @@ restart:
1114 * previous writes to rt are comitted to memory 1224 * previous writes to rt are comitted to memory
1115 * before making rt visible to other CPUS. 1225 * before making rt visible to other CPUS.
1116 */ 1226 */
1117 rcu_assign_pointer(rt_hash_table[hash].chain, rt); 1227 if (rthi)
1228 rcu_assign_pointer(rthi->u.dst.rt_next, rt);
1229 else
1230 rcu_assign_pointer(rt_hash_table[hash].chain, rt);
1231
1118 spin_unlock_bh(rt_hash_lock_addr(hash)); 1232 spin_unlock_bh(rt_hash_lock_addr(hash));
1119 *rp = rt; 1233 *rp = rt;
1120 return 0; 1234 return 0;
@@ -1217,6 +1331,9 @@ void ip_rt_redirect(__be32 old_gw, __be32 daddr, __be32 new_gw,
1217 || ipv4_is_zeronet(new_gw)) 1331 || ipv4_is_zeronet(new_gw))
1218 goto reject_redirect; 1332 goto reject_redirect;
1219 1333
1334 if (!rt_caching(net))
1335 goto reject_redirect;
1336
1220 if (!IN_DEV_SHARED_MEDIA(in_dev)) { 1337 if (!IN_DEV_SHARED_MEDIA(in_dev)) {
1221 if (!inet_addr_onlink(in_dev, new_gw, old_gw)) 1338 if (!inet_addr_onlink(in_dev, new_gw, old_gw))
1222 goto reject_redirect; 1339 goto reject_redirect;
@@ -1267,7 +1384,6 @@ void ip_rt_redirect(__be32 old_gw, __be32 daddr, __be32 new_gw,
1267 1384
1268 /* Copy all the information. */ 1385 /* Copy all the information. */
1269 *rt = *rth; 1386 *rt = *rth;
1270 INIT_RCU_HEAD(&rt->u.dst.rcu_head);
1271 rt->u.dst.__use = 1; 1387 rt->u.dst.__use = 1;
1272 atomic_set(&rt->u.dst.__refcnt, 1); 1388 atomic_set(&rt->u.dst.__refcnt, 1);
1273 rt->u.dst.child = NULL; 1389 rt->u.dst.child = NULL;
@@ -1280,7 +1396,9 @@ void ip_rt_redirect(__be32 old_gw, __be32 daddr, __be32 new_gw,
1280 rt->u.dst.path = &rt->u.dst; 1396 rt->u.dst.path = &rt->u.dst;
1281 rt->u.dst.neighbour = NULL; 1397 rt->u.dst.neighbour = NULL;
1282 rt->u.dst.hh = NULL; 1398 rt->u.dst.hh = NULL;
1399#ifdef CONFIG_XFRM
1283 rt->u.dst.xfrm = NULL; 1400 rt->u.dst.xfrm = NULL;
1401#endif
1284 rt->rt_genid = rt_genid(net); 1402 rt->rt_genid = rt_genid(net);
1285 rt->rt_flags |= RTCF_REDIRECTED; 1403 rt->rt_flags |= RTCF_REDIRECTED;
1286 1404
@@ -1324,11 +1442,10 @@ void ip_rt_redirect(__be32 old_gw, __be32 daddr, __be32 new_gw,
1324reject_redirect: 1442reject_redirect:
1325#ifdef CONFIG_IP_ROUTE_VERBOSE 1443#ifdef CONFIG_IP_ROUTE_VERBOSE
1326 if (IN_DEV_LOG_MARTIANS(in_dev) && net_ratelimit()) 1444 if (IN_DEV_LOG_MARTIANS(in_dev) && net_ratelimit())
1327 printk(KERN_INFO "Redirect from " NIPQUAD_FMT " on %s about " 1445 printk(KERN_INFO "Redirect from %pI4 on %s about %pI4 ignored.\n"
1328 NIPQUAD_FMT " ignored.\n" 1446 " Advised path = %pI4 -> %pI4\n",
1329 " Advised path = " NIPQUAD_FMT " -> " NIPQUAD_FMT "\n", 1447 &old_gw, dev->name, &new_gw,
1330 NIPQUAD(old_gw), dev->name, NIPQUAD(new_gw), 1448 &saddr, &daddr);
1331 NIPQUAD(saddr), NIPQUAD(daddr));
1332#endif 1449#endif
1333 in_dev_put(in_dev); 1450 in_dev_put(in_dev);
1334} 1451}
@@ -1348,9 +1465,8 @@ static struct dst_entry *ipv4_negative_advice(struct dst_entry *dst)
1348 rt->fl.oif, 1465 rt->fl.oif,
1349 rt_genid(dev_net(dst->dev))); 1466 rt_genid(dev_net(dst->dev)));
1350#if RT_CACHE_DEBUG >= 1 1467#if RT_CACHE_DEBUG >= 1
1351 printk(KERN_DEBUG "ipv4_negative_advice: redirect to " 1468 printk(KERN_DEBUG "ipv4_negative_advice: redirect to %pI4/%02x dropped\n",
1352 NIPQUAD_FMT "/%02x dropped\n", 1469 &rt->rt_dst, rt->fl.fl4_tos);
1353 NIPQUAD(rt->rt_dst), rt->fl.fl4_tos);
1354#endif 1470#endif
1355 rt_del(hash, rt); 1471 rt_del(hash, rt);
1356 ret = NULL; 1472 ret = NULL;
@@ -1414,10 +1530,9 @@ void ip_rt_send_redirect(struct sk_buff *skb)
1414 if (IN_DEV_LOG_MARTIANS(in_dev) && 1530 if (IN_DEV_LOG_MARTIANS(in_dev) &&
1415 rt->u.dst.rate_tokens == ip_rt_redirect_number && 1531 rt->u.dst.rate_tokens == ip_rt_redirect_number &&
1416 net_ratelimit()) 1532 net_ratelimit())
1417 printk(KERN_WARNING "host " NIPQUAD_FMT "/if%d ignores " 1533 printk(KERN_WARNING "host %pI4/if%d ignores redirects for %pI4 to %pI4.\n",
1418 "redirects for " NIPQUAD_FMT " to " NIPQUAD_FMT ".\n", 1534 &rt->rt_src, rt->rt_iif,
1419 NIPQUAD(rt->rt_src), rt->rt_iif, 1535 &rt->rt_dst, &rt->rt_gateway);
1420 NIPQUAD(rt->rt_dst), NIPQUAD(rt->rt_gateway));
1421#endif 1536#endif
1422 } 1537 }
1423out: 1538out:
@@ -1610,8 +1725,8 @@ static void ipv4_link_failure(struct sk_buff *skb)
1610 1725
1611static int ip_rt_bug(struct sk_buff *skb) 1726static int ip_rt_bug(struct sk_buff *skb)
1612{ 1727{
1613 printk(KERN_DEBUG "ip_rt_bug: " NIPQUAD_FMT " -> " NIPQUAD_FMT ", %s\n", 1728 printk(KERN_DEBUG "ip_rt_bug: %pI4 -> %pI4, %s\n",
1614 NIPQUAD(ip_hdr(skb)->saddr), NIPQUAD(ip_hdr(skb)->daddr), 1729 &ip_hdr(skb)->saddr, &ip_hdr(skb)->daddr,
1615 skb->dev ? skb->dev->name : "?"); 1730 skb->dev ? skb->dev->name : "?");
1616 kfree_skb(skb); 1731 kfree_skb(skb);
1617 return 0; 1732 return 0;
@@ -1788,9 +1903,8 @@ static void ip_handle_martian_source(struct net_device *dev,
1788 * RFC1812 recommendation, if source is martian, 1903 * RFC1812 recommendation, if source is martian,
1789 * the only hint is MAC header. 1904 * the only hint is MAC header.
1790 */ 1905 */
1791 printk(KERN_WARNING "martian source " NIPQUAD_FMT " from " 1906 printk(KERN_WARNING "martian source %pI4 from %pI4, on dev %s\n",
1792 NIPQUAD_FMT", on dev %s\n", 1907 &daddr, &saddr, dev->name);
1793 NIPQUAD(daddr), NIPQUAD(saddr), dev->name);
1794 if (dev->hard_header_len && skb_mac_header_was_set(skb)) { 1908 if (dev->hard_header_len && skb_mac_header_was_set(skb)) {
1795 int i; 1909 int i;
1796 const unsigned char *p = skb_mac_header(skb); 1910 const unsigned char *p = skb_mac_header(skb);
@@ -2099,9 +2213,8 @@ martian_destination:
2099 RT_CACHE_STAT_INC(in_martian_dst); 2213 RT_CACHE_STAT_INC(in_martian_dst);
2100#ifdef CONFIG_IP_ROUTE_VERBOSE 2214#ifdef CONFIG_IP_ROUTE_VERBOSE
2101 if (IN_DEV_LOG_MARTIANS(in_dev) && net_ratelimit()) 2215 if (IN_DEV_LOG_MARTIANS(in_dev) && net_ratelimit())
2102 printk(KERN_WARNING "martian destination " NIPQUAD_FMT " from " 2216 printk(KERN_WARNING "martian destination %pI4 from %pI4, dev %s\n",
2103 NIPQUAD_FMT ", dev %s\n", 2217 &daddr, &saddr, dev->name);
2104 NIPQUAD(daddr), NIPQUAD(saddr), dev->name);
2105#endif 2218#endif
2106 2219
2107e_hostunreach: 2220e_hostunreach:
@@ -2130,6 +2243,10 @@ int ip_route_input(struct sk_buff *skb, __be32 daddr, __be32 saddr,
2130 struct net *net; 2243 struct net *net;
2131 2244
2132 net = dev_net(dev); 2245 net = dev_net(dev);
2246
2247 if (!rt_caching(net))
2248 goto skip_cache;
2249
2133 tos &= IPTOS_RT_MASK; 2250 tos &= IPTOS_RT_MASK;
2134 hash = rt_hash(daddr, saddr, iif, rt_genid(net)); 2251 hash = rt_hash(daddr, saddr, iif, rt_genid(net));
2135 2252
@@ -2154,6 +2271,7 @@ int ip_route_input(struct sk_buff *skb, __be32 daddr, __be32 saddr,
2154 } 2271 }
2155 rcu_read_unlock(); 2272 rcu_read_unlock();
2156 2273
2274skip_cache:
2157 /* Multicast recognition logic is moved from route cache to here. 2275 /* Multicast recognition logic is moved from route cache to here.
2158 The problem was that too many Ethernet cards have broken/missing 2276 The problem was that too many Ethernet cards have broken/missing
2159 hardware multicast filters :-( As result the host on multicasting 2277 hardware multicast filters :-( As result the host on multicasting
@@ -2539,6 +2657,9 @@ int __ip_route_output_key(struct net *net, struct rtable **rp,
2539 unsigned hash; 2657 unsigned hash;
2540 struct rtable *rth; 2658 struct rtable *rth;
2541 2659
2660 if (!rt_caching(net))
2661 goto slow_output;
2662
2542 hash = rt_hash(flp->fl4_dst, flp->fl4_src, flp->oif, rt_genid(net)); 2663 hash = rt_hash(flp->fl4_dst, flp->fl4_src, flp->oif, rt_genid(net));
2543 2664
2544 rcu_read_lock_bh(); 2665 rcu_read_lock_bh();
@@ -2563,6 +2684,7 @@ int __ip_route_output_key(struct net *net, struct rtable **rp,
2563 } 2684 }
2564 rcu_read_unlock_bh(); 2685 rcu_read_unlock_bh();
2565 2686
2687slow_output:
2566 return ip_route_output_slow(net, rp, flp); 2688 return ip_route_output_slow(net, rp, flp);
2567} 2689}
2568 2690
@@ -2578,7 +2700,6 @@ static struct dst_ops ipv4_dst_blackhole_ops = {
2578 .destroy = ipv4_dst_destroy, 2700 .destroy = ipv4_dst_destroy,
2579 .check = ipv4_dst_check, 2701 .check = ipv4_dst_check,
2580 .update_pmtu = ipv4_rt_blackhole_update_pmtu, 2702 .update_pmtu = ipv4_rt_blackhole_update_pmtu,
2581 .entry_size = sizeof(struct rtable),
2582 .entries = ATOMIC_INIT(0), 2703 .entries = ATOMIC_INIT(0),
2583}; 2704};
2584 2705
@@ -2640,7 +2761,7 @@ int ip_route_output_flow(struct net *net, struct rtable **rp, struct flowi *flp,
2640 flp->fl4_src = (*rp)->rt_src; 2761 flp->fl4_src = (*rp)->rt_src;
2641 if (!flp->fl4_dst) 2762 if (!flp->fl4_dst)
2642 flp->fl4_dst = (*rp)->rt_dst; 2763 flp->fl4_dst = (*rp)->rt_dst;
2643 err = __xfrm_lookup((struct dst_entry **)rp, flp, sk, 2764 err = __xfrm_lookup(net, (struct dst_entry **)rp, flp, sk,
2644 flags ? XFRM_LOOKUP_WAIT : 0); 2765 flags ? XFRM_LOOKUP_WAIT : 0);
2645 if (err == -EREMOTE) 2766 if (err == -EREMOTE)
2646 err = ipv4_dst_blackhole(net, rp, flp); 2767 err = ipv4_dst_blackhole(net, rp, flp);
@@ -2995,7 +3116,7 @@ static ctl_table ipv4_route_table[] = {
2995 .data = &ipv4_dst_ops.gc_thresh, 3116 .data = &ipv4_dst_ops.gc_thresh,
2996 .maxlen = sizeof(int), 3117 .maxlen = sizeof(int),
2997 .mode = 0644, 3118 .mode = 0644,
2998 .proc_handler = &proc_dointvec, 3119 .proc_handler = proc_dointvec,
2999 }, 3120 },
3000 { 3121 {
3001 .ctl_name = NET_IPV4_ROUTE_MAX_SIZE, 3122 .ctl_name = NET_IPV4_ROUTE_MAX_SIZE,
@@ -3003,7 +3124,7 @@ static ctl_table ipv4_route_table[] = {
3003 .data = &ip_rt_max_size, 3124 .data = &ip_rt_max_size,
3004 .maxlen = sizeof(int), 3125 .maxlen = sizeof(int),
3005 .mode = 0644, 3126 .mode = 0644,
3006 .proc_handler = &proc_dointvec, 3127 .proc_handler = proc_dointvec,
3007 }, 3128 },
3008 { 3129 {
3009 /* Deprecated. Use gc_min_interval_ms */ 3130 /* Deprecated. Use gc_min_interval_ms */
@@ -3013,8 +3134,8 @@ static ctl_table ipv4_route_table[] = {
3013 .data = &ip_rt_gc_min_interval, 3134 .data = &ip_rt_gc_min_interval,
3014 .maxlen = sizeof(int), 3135 .maxlen = sizeof(int),
3015 .mode = 0644, 3136 .mode = 0644,
3016 .proc_handler = &proc_dointvec_jiffies, 3137 .proc_handler = proc_dointvec_jiffies,
3017 .strategy = &sysctl_jiffies, 3138 .strategy = sysctl_jiffies,
3018 }, 3139 },
3019 { 3140 {
3020 .ctl_name = NET_IPV4_ROUTE_GC_MIN_INTERVAL_MS, 3141 .ctl_name = NET_IPV4_ROUTE_GC_MIN_INTERVAL_MS,
@@ -3022,8 +3143,8 @@ static ctl_table ipv4_route_table[] = {
3022 .data = &ip_rt_gc_min_interval, 3143 .data = &ip_rt_gc_min_interval,
3023 .maxlen = sizeof(int), 3144 .maxlen = sizeof(int),
3024 .mode = 0644, 3145 .mode = 0644,
3025 .proc_handler = &proc_dointvec_ms_jiffies, 3146 .proc_handler = proc_dointvec_ms_jiffies,
3026 .strategy = &sysctl_ms_jiffies, 3147 .strategy = sysctl_ms_jiffies,
3027 }, 3148 },
3028 { 3149 {
3029 .ctl_name = NET_IPV4_ROUTE_GC_TIMEOUT, 3150 .ctl_name = NET_IPV4_ROUTE_GC_TIMEOUT,
@@ -3031,8 +3152,8 @@ static ctl_table ipv4_route_table[] = {
3031 .data = &ip_rt_gc_timeout, 3152 .data = &ip_rt_gc_timeout,
3032 .maxlen = sizeof(int), 3153 .maxlen = sizeof(int),
3033 .mode = 0644, 3154 .mode = 0644,
3034 .proc_handler = &proc_dointvec_jiffies, 3155 .proc_handler = proc_dointvec_jiffies,
3035 .strategy = &sysctl_jiffies, 3156 .strategy = sysctl_jiffies,
3036 }, 3157 },
3037 { 3158 {
3038 .ctl_name = NET_IPV4_ROUTE_GC_INTERVAL, 3159 .ctl_name = NET_IPV4_ROUTE_GC_INTERVAL,
@@ -3040,8 +3161,8 @@ static ctl_table ipv4_route_table[] = {
3040 .data = &ip_rt_gc_interval, 3161 .data = &ip_rt_gc_interval,
3041 .maxlen = sizeof(int), 3162 .maxlen = sizeof(int),
3042 .mode = 0644, 3163 .mode = 0644,
3043 .proc_handler = &proc_dointvec_jiffies, 3164 .proc_handler = proc_dointvec_jiffies,
3044 .strategy = &sysctl_jiffies, 3165 .strategy = sysctl_jiffies,
3045 }, 3166 },
3046 { 3167 {
3047 .ctl_name = NET_IPV4_ROUTE_REDIRECT_LOAD, 3168 .ctl_name = NET_IPV4_ROUTE_REDIRECT_LOAD,
@@ -3049,7 +3170,7 @@ static ctl_table ipv4_route_table[] = {
3049 .data = &ip_rt_redirect_load, 3170 .data = &ip_rt_redirect_load,
3050 .maxlen = sizeof(int), 3171 .maxlen = sizeof(int),
3051 .mode = 0644, 3172 .mode = 0644,
3052 .proc_handler = &proc_dointvec, 3173 .proc_handler = proc_dointvec,
3053 }, 3174 },
3054 { 3175 {
3055 .ctl_name = NET_IPV4_ROUTE_REDIRECT_NUMBER, 3176 .ctl_name = NET_IPV4_ROUTE_REDIRECT_NUMBER,
@@ -3057,7 +3178,7 @@ static ctl_table ipv4_route_table[] = {
3057 .data = &ip_rt_redirect_number, 3178 .data = &ip_rt_redirect_number,
3058 .maxlen = sizeof(int), 3179 .maxlen = sizeof(int),
3059 .mode = 0644, 3180 .mode = 0644,
3060 .proc_handler = &proc_dointvec, 3181 .proc_handler = proc_dointvec,
3061 }, 3182 },
3062 { 3183 {
3063 .ctl_name = NET_IPV4_ROUTE_REDIRECT_SILENCE, 3184 .ctl_name = NET_IPV4_ROUTE_REDIRECT_SILENCE,
@@ -3065,7 +3186,7 @@ static ctl_table ipv4_route_table[] = {
3065 .data = &ip_rt_redirect_silence, 3186 .data = &ip_rt_redirect_silence,
3066 .maxlen = sizeof(int), 3187 .maxlen = sizeof(int),
3067 .mode = 0644, 3188 .mode = 0644,
3068 .proc_handler = &proc_dointvec, 3189 .proc_handler = proc_dointvec,
3069 }, 3190 },
3070 { 3191 {
3071 .ctl_name = NET_IPV4_ROUTE_ERROR_COST, 3192 .ctl_name = NET_IPV4_ROUTE_ERROR_COST,
@@ -3073,7 +3194,7 @@ static ctl_table ipv4_route_table[] = {
3073 .data = &ip_rt_error_cost, 3194 .data = &ip_rt_error_cost,
3074 .maxlen = sizeof(int), 3195 .maxlen = sizeof(int),
3075 .mode = 0644, 3196 .mode = 0644,
3076 .proc_handler = &proc_dointvec, 3197 .proc_handler = proc_dointvec,
3077 }, 3198 },
3078 { 3199 {
3079 .ctl_name = NET_IPV4_ROUTE_ERROR_BURST, 3200 .ctl_name = NET_IPV4_ROUTE_ERROR_BURST,
@@ -3081,7 +3202,7 @@ static ctl_table ipv4_route_table[] = {
3081 .data = &ip_rt_error_burst, 3202 .data = &ip_rt_error_burst,
3082 .maxlen = sizeof(int), 3203 .maxlen = sizeof(int),
3083 .mode = 0644, 3204 .mode = 0644,
3084 .proc_handler = &proc_dointvec, 3205 .proc_handler = proc_dointvec,
3085 }, 3206 },
3086 { 3207 {
3087 .ctl_name = NET_IPV4_ROUTE_GC_ELASTICITY, 3208 .ctl_name = NET_IPV4_ROUTE_GC_ELASTICITY,
@@ -3089,7 +3210,7 @@ static ctl_table ipv4_route_table[] = {
3089 .data = &ip_rt_gc_elasticity, 3210 .data = &ip_rt_gc_elasticity,
3090 .maxlen = sizeof(int), 3211 .maxlen = sizeof(int),
3091 .mode = 0644, 3212 .mode = 0644,
3092 .proc_handler = &proc_dointvec, 3213 .proc_handler = proc_dointvec,
3093 }, 3214 },
3094 { 3215 {
3095 .ctl_name = NET_IPV4_ROUTE_MTU_EXPIRES, 3216 .ctl_name = NET_IPV4_ROUTE_MTU_EXPIRES,
@@ -3097,8 +3218,8 @@ static ctl_table ipv4_route_table[] = {
3097 .data = &ip_rt_mtu_expires, 3218 .data = &ip_rt_mtu_expires,
3098 .maxlen = sizeof(int), 3219 .maxlen = sizeof(int),
3099 .mode = 0644, 3220 .mode = 0644,
3100 .proc_handler = &proc_dointvec_jiffies, 3221 .proc_handler = proc_dointvec_jiffies,
3101 .strategy = &sysctl_jiffies, 3222 .strategy = sysctl_jiffies,
3102 }, 3223 },
3103 { 3224 {
3104 .ctl_name = NET_IPV4_ROUTE_MIN_PMTU, 3225 .ctl_name = NET_IPV4_ROUTE_MIN_PMTU,
@@ -3106,7 +3227,7 @@ static ctl_table ipv4_route_table[] = {
3106 .data = &ip_rt_min_pmtu, 3227 .data = &ip_rt_min_pmtu,
3107 .maxlen = sizeof(int), 3228 .maxlen = sizeof(int),
3108 .mode = 0644, 3229 .mode = 0644,
3109 .proc_handler = &proc_dointvec, 3230 .proc_handler = proc_dointvec,
3110 }, 3231 },
3111 { 3232 {
3112 .ctl_name = NET_IPV4_ROUTE_MIN_ADVMSS, 3233 .ctl_name = NET_IPV4_ROUTE_MIN_ADVMSS,
@@ -3114,7 +3235,7 @@ static ctl_table ipv4_route_table[] = {
3114 .data = &ip_rt_min_advmss, 3235 .data = &ip_rt_min_advmss,
3115 .maxlen = sizeof(int), 3236 .maxlen = sizeof(int),
3116 .mode = 0644, 3237 .mode = 0644,
3117 .proc_handler = &proc_dointvec, 3238 .proc_handler = proc_dointvec,
3118 }, 3239 },
3119 { 3240 {
3120 .ctl_name = NET_IPV4_ROUTE_SECRET_INTERVAL, 3241 .ctl_name = NET_IPV4_ROUTE_SECRET_INTERVAL,
@@ -3122,8 +3243,8 @@ static ctl_table ipv4_route_table[] = {
3122 .data = &ip_rt_secret_interval, 3243 .data = &ip_rt_secret_interval,
3123 .maxlen = sizeof(int), 3244 .maxlen = sizeof(int),
3124 .mode = 0644, 3245 .mode = 0644,
3125 .proc_handler = &ipv4_sysctl_rt_secret_interval, 3246 .proc_handler = ipv4_sysctl_rt_secret_interval,
3126 .strategy = &ipv4_sysctl_rt_secret_interval_strategy, 3247 .strategy = ipv4_sysctl_rt_secret_interval_strategy,
3127 }, 3248 },
3128 { .ctl_name = 0 } 3249 { .ctl_name = 0 }
3129}; 3250};
@@ -3151,8 +3272,8 @@ static struct ctl_table ipv4_route_flush_table[] = {
3151 .procname = "flush", 3272 .procname = "flush",
3152 .maxlen = sizeof(int), 3273 .maxlen = sizeof(int),
3153 .mode = 0200, 3274 .mode = 0200,
3154 .proc_handler = &ipv4_sysctl_rtcache_flush, 3275 .proc_handler = ipv4_sysctl_rtcache_flush,
3155 .strategy = &ipv4_sysctl_rtcache_flush_strategy, 3276 .strategy = ipv4_sysctl_rtcache_flush_strategy,
3156 }, 3277 },
3157 { .ctl_name = 0 }, 3278 { .ctl_name = 0 },
3158}; 3279};
diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
index 1bb10df8ce7d..4710d219f06a 100644
--- a/net/ipv4/sysctl_net_ipv4.c
+++ b/net/ipv4/sysctl_net_ipv4.c
@@ -195,7 +195,7 @@ static struct ctl_table ipv4_table[] = {
195 .data = &sysctl_tcp_timestamps, 195 .data = &sysctl_tcp_timestamps,
196 .maxlen = sizeof(int), 196 .maxlen = sizeof(int),
197 .mode = 0644, 197 .mode = 0644,
198 .proc_handler = &proc_dointvec 198 .proc_handler = proc_dointvec
199 }, 199 },
200 { 200 {
201 .ctl_name = NET_IPV4_TCP_WINDOW_SCALING, 201 .ctl_name = NET_IPV4_TCP_WINDOW_SCALING,
@@ -203,7 +203,7 @@ static struct ctl_table ipv4_table[] = {
203 .data = &sysctl_tcp_window_scaling, 203 .data = &sysctl_tcp_window_scaling,
204 .maxlen = sizeof(int), 204 .maxlen = sizeof(int),
205 .mode = 0644, 205 .mode = 0644,
206 .proc_handler = &proc_dointvec 206 .proc_handler = proc_dointvec
207 }, 207 },
208 { 208 {
209 .ctl_name = NET_IPV4_TCP_SACK, 209 .ctl_name = NET_IPV4_TCP_SACK,
@@ -211,7 +211,7 @@ static struct ctl_table ipv4_table[] = {
211 .data = &sysctl_tcp_sack, 211 .data = &sysctl_tcp_sack,
212 .maxlen = sizeof(int), 212 .maxlen = sizeof(int),
213 .mode = 0644, 213 .mode = 0644,
214 .proc_handler = &proc_dointvec 214 .proc_handler = proc_dointvec
215 }, 215 },
216 { 216 {
217 .ctl_name = NET_IPV4_TCP_RETRANS_COLLAPSE, 217 .ctl_name = NET_IPV4_TCP_RETRANS_COLLAPSE,
@@ -219,7 +219,7 @@ static struct ctl_table ipv4_table[] = {
219 .data = &sysctl_tcp_retrans_collapse, 219 .data = &sysctl_tcp_retrans_collapse,
220 .maxlen = sizeof(int), 220 .maxlen = sizeof(int),
221 .mode = 0644, 221 .mode = 0644,
222 .proc_handler = &proc_dointvec 222 .proc_handler = proc_dointvec
223 }, 223 },
224 { 224 {
225 .ctl_name = NET_IPV4_DEFAULT_TTL, 225 .ctl_name = NET_IPV4_DEFAULT_TTL,
@@ -227,8 +227,8 @@ static struct ctl_table ipv4_table[] = {
227 .data = &sysctl_ip_default_ttl, 227 .data = &sysctl_ip_default_ttl,
228 .maxlen = sizeof(int), 228 .maxlen = sizeof(int),
229 .mode = 0644, 229 .mode = 0644,
230 .proc_handler = &ipv4_doint_and_flush, 230 .proc_handler = ipv4_doint_and_flush,
231 .strategy = &ipv4_doint_and_flush_strategy, 231 .strategy = ipv4_doint_and_flush_strategy,
232 .extra2 = &init_net, 232 .extra2 = &init_net,
233 }, 233 },
234 { 234 {
@@ -237,7 +237,7 @@ static struct ctl_table ipv4_table[] = {
237 .data = &ipv4_config.no_pmtu_disc, 237 .data = &ipv4_config.no_pmtu_disc,
238 .maxlen = sizeof(int), 238 .maxlen = sizeof(int),
239 .mode = 0644, 239 .mode = 0644,
240 .proc_handler = &proc_dointvec 240 .proc_handler = proc_dointvec
241 }, 241 },
242 { 242 {
243 .ctl_name = NET_IPV4_NONLOCAL_BIND, 243 .ctl_name = NET_IPV4_NONLOCAL_BIND,
@@ -245,7 +245,7 @@ static struct ctl_table ipv4_table[] = {
245 .data = &sysctl_ip_nonlocal_bind, 245 .data = &sysctl_ip_nonlocal_bind,
246 .maxlen = sizeof(int), 246 .maxlen = sizeof(int),
247 .mode = 0644, 247 .mode = 0644,
248 .proc_handler = &proc_dointvec 248 .proc_handler = proc_dointvec
249 }, 249 },
250 { 250 {
251 .ctl_name = NET_IPV4_TCP_SYN_RETRIES, 251 .ctl_name = NET_IPV4_TCP_SYN_RETRIES,
@@ -253,7 +253,7 @@ static struct ctl_table ipv4_table[] = {
253 .data = &sysctl_tcp_syn_retries, 253 .data = &sysctl_tcp_syn_retries,
254 .maxlen = sizeof(int), 254 .maxlen = sizeof(int),
255 .mode = 0644, 255 .mode = 0644,
256 .proc_handler = &proc_dointvec 256 .proc_handler = proc_dointvec
257 }, 257 },
258 { 258 {
259 .ctl_name = NET_TCP_SYNACK_RETRIES, 259 .ctl_name = NET_TCP_SYNACK_RETRIES,
@@ -261,7 +261,7 @@ static struct ctl_table ipv4_table[] = {
261 .data = &sysctl_tcp_synack_retries, 261 .data = &sysctl_tcp_synack_retries,
262 .maxlen = sizeof(int), 262 .maxlen = sizeof(int),
263 .mode = 0644, 263 .mode = 0644,
264 .proc_handler = &proc_dointvec 264 .proc_handler = proc_dointvec
265 }, 265 },
266 { 266 {
267 .ctl_name = NET_TCP_MAX_ORPHANS, 267 .ctl_name = NET_TCP_MAX_ORPHANS,
@@ -269,7 +269,7 @@ static struct ctl_table ipv4_table[] = {
269 .data = &sysctl_tcp_max_orphans, 269 .data = &sysctl_tcp_max_orphans,
270 .maxlen = sizeof(int), 270 .maxlen = sizeof(int),
271 .mode = 0644, 271 .mode = 0644,
272 .proc_handler = &proc_dointvec 272 .proc_handler = proc_dointvec
273 }, 273 },
274 { 274 {
275 .ctl_name = NET_TCP_MAX_TW_BUCKETS, 275 .ctl_name = NET_TCP_MAX_TW_BUCKETS,
@@ -277,7 +277,7 @@ static struct ctl_table ipv4_table[] = {
277 .data = &tcp_death_row.sysctl_max_tw_buckets, 277 .data = &tcp_death_row.sysctl_max_tw_buckets,
278 .maxlen = sizeof(int), 278 .maxlen = sizeof(int),
279 .mode = 0644, 279 .mode = 0644,
280 .proc_handler = &proc_dointvec 280 .proc_handler = proc_dointvec
281 }, 281 },
282 { 282 {
283 .ctl_name = NET_IPV4_DYNADDR, 283 .ctl_name = NET_IPV4_DYNADDR,
@@ -285,7 +285,7 @@ static struct ctl_table ipv4_table[] = {
285 .data = &sysctl_ip_dynaddr, 285 .data = &sysctl_ip_dynaddr,
286 .maxlen = sizeof(int), 286 .maxlen = sizeof(int),
287 .mode = 0644, 287 .mode = 0644,
288 .proc_handler = &proc_dointvec 288 .proc_handler = proc_dointvec
289 }, 289 },
290 { 290 {
291 .ctl_name = NET_IPV4_TCP_KEEPALIVE_TIME, 291 .ctl_name = NET_IPV4_TCP_KEEPALIVE_TIME,
@@ -293,8 +293,8 @@ static struct ctl_table ipv4_table[] = {
293 .data = &sysctl_tcp_keepalive_time, 293 .data = &sysctl_tcp_keepalive_time,
294 .maxlen = sizeof(int), 294 .maxlen = sizeof(int),
295 .mode = 0644, 295 .mode = 0644,
296 .proc_handler = &proc_dointvec_jiffies, 296 .proc_handler = proc_dointvec_jiffies,
297 .strategy = &sysctl_jiffies 297 .strategy = sysctl_jiffies
298 }, 298 },
299 { 299 {
300 .ctl_name = NET_IPV4_TCP_KEEPALIVE_PROBES, 300 .ctl_name = NET_IPV4_TCP_KEEPALIVE_PROBES,
@@ -302,7 +302,7 @@ static struct ctl_table ipv4_table[] = {
302 .data = &sysctl_tcp_keepalive_probes, 302 .data = &sysctl_tcp_keepalive_probes,
303 .maxlen = sizeof(int), 303 .maxlen = sizeof(int),
304 .mode = 0644, 304 .mode = 0644,
305 .proc_handler = &proc_dointvec 305 .proc_handler = proc_dointvec
306 }, 306 },
307 { 307 {
308 .ctl_name = NET_IPV4_TCP_KEEPALIVE_INTVL, 308 .ctl_name = NET_IPV4_TCP_KEEPALIVE_INTVL,
@@ -310,8 +310,8 @@ static struct ctl_table ipv4_table[] = {
310 .data = &sysctl_tcp_keepalive_intvl, 310 .data = &sysctl_tcp_keepalive_intvl,
311 .maxlen = sizeof(int), 311 .maxlen = sizeof(int),
312 .mode = 0644, 312 .mode = 0644,
313 .proc_handler = &proc_dointvec_jiffies, 313 .proc_handler = proc_dointvec_jiffies,
314 .strategy = &sysctl_jiffies 314 .strategy = sysctl_jiffies
315 }, 315 },
316 { 316 {
317 .ctl_name = NET_IPV4_TCP_RETRIES1, 317 .ctl_name = NET_IPV4_TCP_RETRIES1,
@@ -319,8 +319,8 @@ static struct ctl_table ipv4_table[] = {
319 .data = &sysctl_tcp_retries1, 319 .data = &sysctl_tcp_retries1,
320 .maxlen = sizeof(int), 320 .maxlen = sizeof(int),
321 .mode = 0644, 321 .mode = 0644,
322 .proc_handler = &proc_dointvec_minmax, 322 .proc_handler = proc_dointvec_minmax,
323 .strategy = &sysctl_intvec, 323 .strategy = sysctl_intvec,
324 .extra2 = &tcp_retr1_max 324 .extra2 = &tcp_retr1_max
325 }, 325 },
326 { 326 {
@@ -329,7 +329,7 @@ static struct ctl_table ipv4_table[] = {
329 .data = &sysctl_tcp_retries2, 329 .data = &sysctl_tcp_retries2,
330 .maxlen = sizeof(int), 330 .maxlen = sizeof(int),
331 .mode = 0644, 331 .mode = 0644,
332 .proc_handler = &proc_dointvec 332 .proc_handler = proc_dointvec
333 }, 333 },
334 { 334 {
335 .ctl_name = NET_IPV4_TCP_FIN_TIMEOUT, 335 .ctl_name = NET_IPV4_TCP_FIN_TIMEOUT,
@@ -337,8 +337,8 @@ static struct ctl_table ipv4_table[] = {
337 .data = &sysctl_tcp_fin_timeout, 337 .data = &sysctl_tcp_fin_timeout,
338 .maxlen = sizeof(int), 338 .maxlen = sizeof(int),
339 .mode = 0644, 339 .mode = 0644,
340 .proc_handler = &proc_dointvec_jiffies, 340 .proc_handler = proc_dointvec_jiffies,
341 .strategy = &sysctl_jiffies 341 .strategy = sysctl_jiffies
342 }, 342 },
343#ifdef CONFIG_SYN_COOKIES 343#ifdef CONFIG_SYN_COOKIES
344 { 344 {
@@ -347,7 +347,7 @@ static struct ctl_table ipv4_table[] = {
347 .data = &sysctl_tcp_syncookies, 347 .data = &sysctl_tcp_syncookies,
348 .maxlen = sizeof(int), 348 .maxlen = sizeof(int),
349 .mode = 0644, 349 .mode = 0644,
350 .proc_handler = &proc_dointvec 350 .proc_handler = proc_dointvec
351 }, 351 },
352#endif 352#endif
353 { 353 {
@@ -356,7 +356,7 @@ static struct ctl_table ipv4_table[] = {
356 .data = &tcp_death_row.sysctl_tw_recycle, 356 .data = &tcp_death_row.sysctl_tw_recycle,
357 .maxlen = sizeof(int), 357 .maxlen = sizeof(int),
358 .mode = 0644, 358 .mode = 0644,
359 .proc_handler = &proc_dointvec 359 .proc_handler = proc_dointvec
360 }, 360 },
361 { 361 {
362 .ctl_name = NET_TCP_ABORT_ON_OVERFLOW, 362 .ctl_name = NET_TCP_ABORT_ON_OVERFLOW,
@@ -364,7 +364,7 @@ static struct ctl_table ipv4_table[] = {
364 .data = &sysctl_tcp_abort_on_overflow, 364 .data = &sysctl_tcp_abort_on_overflow,
365 .maxlen = sizeof(int), 365 .maxlen = sizeof(int),
366 .mode = 0644, 366 .mode = 0644,
367 .proc_handler = &proc_dointvec 367 .proc_handler = proc_dointvec
368 }, 368 },
369 { 369 {
370 .ctl_name = NET_TCP_STDURG, 370 .ctl_name = NET_TCP_STDURG,
@@ -372,7 +372,7 @@ static struct ctl_table ipv4_table[] = {
372 .data = &sysctl_tcp_stdurg, 372 .data = &sysctl_tcp_stdurg,
373 .maxlen = sizeof(int), 373 .maxlen = sizeof(int),
374 .mode = 0644, 374 .mode = 0644,
375 .proc_handler = &proc_dointvec 375 .proc_handler = proc_dointvec
376 }, 376 },
377 { 377 {
378 .ctl_name = NET_TCP_RFC1337, 378 .ctl_name = NET_TCP_RFC1337,
@@ -380,7 +380,7 @@ static struct ctl_table ipv4_table[] = {
380 .data = &sysctl_tcp_rfc1337, 380 .data = &sysctl_tcp_rfc1337,
381 .maxlen = sizeof(int), 381 .maxlen = sizeof(int),
382 .mode = 0644, 382 .mode = 0644,
383 .proc_handler = &proc_dointvec 383 .proc_handler = proc_dointvec
384 }, 384 },
385 { 385 {
386 .ctl_name = NET_TCP_MAX_SYN_BACKLOG, 386 .ctl_name = NET_TCP_MAX_SYN_BACKLOG,
@@ -388,7 +388,7 @@ static struct ctl_table ipv4_table[] = {
388 .data = &sysctl_max_syn_backlog, 388 .data = &sysctl_max_syn_backlog,
389 .maxlen = sizeof(int), 389 .maxlen = sizeof(int),
390 .mode = 0644, 390 .mode = 0644,
391 .proc_handler = &proc_dointvec 391 .proc_handler = proc_dointvec
392 }, 392 },
393 { 393 {
394 .ctl_name = NET_IPV4_LOCAL_PORT_RANGE, 394 .ctl_name = NET_IPV4_LOCAL_PORT_RANGE,
@@ -396,8 +396,8 @@ static struct ctl_table ipv4_table[] = {
396 .data = &sysctl_local_ports.range, 396 .data = &sysctl_local_ports.range,
397 .maxlen = sizeof(sysctl_local_ports.range), 397 .maxlen = sizeof(sysctl_local_ports.range),
398 .mode = 0644, 398 .mode = 0644,
399 .proc_handler = &ipv4_local_port_range, 399 .proc_handler = ipv4_local_port_range,
400 .strategy = &ipv4_sysctl_local_port_range, 400 .strategy = ipv4_sysctl_local_port_range,
401 }, 401 },
402#ifdef CONFIG_IP_MULTICAST 402#ifdef CONFIG_IP_MULTICAST
403 { 403 {
@@ -406,7 +406,7 @@ static struct ctl_table ipv4_table[] = {
406 .data = &sysctl_igmp_max_memberships, 406 .data = &sysctl_igmp_max_memberships,
407 .maxlen = sizeof(int), 407 .maxlen = sizeof(int),
408 .mode = 0644, 408 .mode = 0644,
409 .proc_handler = &proc_dointvec 409 .proc_handler = proc_dointvec
410 }, 410 },
411 411
412#endif 412#endif
@@ -416,7 +416,7 @@ static struct ctl_table ipv4_table[] = {
416 .data = &sysctl_igmp_max_msf, 416 .data = &sysctl_igmp_max_msf,
417 .maxlen = sizeof(int), 417 .maxlen = sizeof(int),
418 .mode = 0644, 418 .mode = 0644,
419 .proc_handler = &proc_dointvec 419 .proc_handler = proc_dointvec
420 }, 420 },
421 { 421 {
422 .ctl_name = NET_IPV4_INET_PEER_THRESHOLD, 422 .ctl_name = NET_IPV4_INET_PEER_THRESHOLD,
@@ -424,7 +424,7 @@ static struct ctl_table ipv4_table[] = {
424 .data = &inet_peer_threshold, 424 .data = &inet_peer_threshold,
425 .maxlen = sizeof(int), 425 .maxlen = sizeof(int),
426 .mode = 0644, 426 .mode = 0644,
427 .proc_handler = &proc_dointvec 427 .proc_handler = proc_dointvec
428 }, 428 },
429 { 429 {
430 .ctl_name = NET_IPV4_INET_PEER_MINTTL, 430 .ctl_name = NET_IPV4_INET_PEER_MINTTL,
@@ -432,8 +432,8 @@ static struct ctl_table ipv4_table[] = {
432 .data = &inet_peer_minttl, 432 .data = &inet_peer_minttl,
433 .maxlen = sizeof(int), 433 .maxlen = sizeof(int),
434 .mode = 0644, 434 .mode = 0644,
435 .proc_handler = &proc_dointvec_jiffies, 435 .proc_handler = proc_dointvec_jiffies,
436 .strategy = &sysctl_jiffies 436 .strategy = sysctl_jiffies
437 }, 437 },
438 { 438 {
439 .ctl_name = NET_IPV4_INET_PEER_MAXTTL, 439 .ctl_name = NET_IPV4_INET_PEER_MAXTTL,
@@ -441,8 +441,8 @@ static struct ctl_table ipv4_table[] = {
441 .data = &inet_peer_maxttl, 441 .data = &inet_peer_maxttl,
442 .maxlen = sizeof(int), 442 .maxlen = sizeof(int),
443 .mode = 0644, 443 .mode = 0644,
444 .proc_handler = &proc_dointvec_jiffies, 444 .proc_handler = proc_dointvec_jiffies,
445 .strategy = &sysctl_jiffies 445 .strategy = sysctl_jiffies
446 }, 446 },
447 { 447 {
448 .ctl_name = NET_IPV4_INET_PEER_GC_MINTIME, 448 .ctl_name = NET_IPV4_INET_PEER_GC_MINTIME,
@@ -450,8 +450,8 @@ static struct ctl_table ipv4_table[] = {
450 .data = &inet_peer_gc_mintime, 450 .data = &inet_peer_gc_mintime,
451 .maxlen = sizeof(int), 451 .maxlen = sizeof(int),
452 .mode = 0644, 452 .mode = 0644,
453 .proc_handler = &proc_dointvec_jiffies, 453 .proc_handler = proc_dointvec_jiffies,
454 .strategy = &sysctl_jiffies 454 .strategy = sysctl_jiffies
455 }, 455 },
456 { 456 {
457 .ctl_name = NET_IPV4_INET_PEER_GC_MAXTIME, 457 .ctl_name = NET_IPV4_INET_PEER_GC_MAXTIME,
@@ -459,8 +459,8 @@ static struct ctl_table ipv4_table[] = {
459 .data = &inet_peer_gc_maxtime, 459 .data = &inet_peer_gc_maxtime,
460 .maxlen = sizeof(int), 460 .maxlen = sizeof(int),
461 .mode = 0644, 461 .mode = 0644,
462 .proc_handler = &proc_dointvec_jiffies, 462 .proc_handler = proc_dointvec_jiffies,
463 .strategy = &sysctl_jiffies 463 .strategy = sysctl_jiffies
464 }, 464 },
465 { 465 {
466 .ctl_name = NET_TCP_ORPHAN_RETRIES, 466 .ctl_name = NET_TCP_ORPHAN_RETRIES,
@@ -468,7 +468,7 @@ static struct ctl_table ipv4_table[] = {
468 .data = &sysctl_tcp_orphan_retries, 468 .data = &sysctl_tcp_orphan_retries,
469 .maxlen = sizeof(int), 469 .maxlen = sizeof(int),
470 .mode = 0644, 470 .mode = 0644,
471 .proc_handler = &proc_dointvec 471 .proc_handler = proc_dointvec
472 }, 472 },
473 { 473 {
474 .ctl_name = NET_TCP_FACK, 474 .ctl_name = NET_TCP_FACK,
@@ -476,7 +476,7 @@ static struct ctl_table ipv4_table[] = {
476 .data = &sysctl_tcp_fack, 476 .data = &sysctl_tcp_fack,
477 .maxlen = sizeof(int), 477 .maxlen = sizeof(int),
478 .mode = 0644, 478 .mode = 0644,
479 .proc_handler = &proc_dointvec 479 .proc_handler = proc_dointvec
480 }, 480 },
481 { 481 {
482 .ctl_name = NET_TCP_REORDERING, 482 .ctl_name = NET_TCP_REORDERING,
@@ -484,7 +484,7 @@ static struct ctl_table ipv4_table[] = {
484 .data = &sysctl_tcp_reordering, 484 .data = &sysctl_tcp_reordering,
485 .maxlen = sizeof(int), 485 .maxlen = sizeof(int),
486 .mode = 0644, 486 .mode = 0644,
487 .proc_handler = &proc_dointvec 487 .proc_handler = proc_dointvec
488 }, 488 },
489 { 489 {
490 .ctl_name = NET_TCP_ECN, 490 .ctl_name = NET_TCP_ECN,
@@ -492,7 +492,7 @@ static struct ctl_table ipv4_table[] = {
492 .data = &sysctl_tcp_ecn, 492 .data = &sysctl_tcp_ecn,
493 .maxlen = sizeof(int), 493 .maxlen = sizeof(int),
494 .mode = 0644, 494 .mode = 0644,
495 .proc_handler = &proc_dointvec 495 .proc_handler = proc_dointvec
496 }, 496 },
497 { 497 {
498 .ctl_name = NET_TCP_DSACK, 498 .ctl_name = NET_TCP_DSACK,
@@ -500,7 +500,7 @@ static struct ctl_table ipv4_table[] = {
500 .data = &sysctl_tcp_dsack, 500 .data = &sysctl_tcp_dsack,
501 .maxlen = sizeof(int), 501 .maxlen = sizeof(int),
502 .mode = 0644, 502 .mode = 0644,
503 .proc_handler = &proc_dointvec 503 .proc_handler = proc_dointvec
504 }, 504 },
505 { 505 {
506 .ctl_name = NET_TCP_MEM, 506 .ctl_name = NET_TCP_MEM,
@@ -508,7 +508,7 @@ static struct ctl_table ipv4_table[] = {
508 .data = &sysctl_tcp_mem, 508 .data = &sysctl_tcp_mem,
509 .maxlen = sizeof(sysctl_tcp_mem), 509 .maxlen = sizeof(sysctl_tcp_mem),
510 .mode = 0644, 510 .mode = 0644,
511 .proc_handler = &proc_dointvec 511 .proc_handler = proc_dointvec
512 }, 512 },
513 { 513 {
514 .ctl_name = NET_TCP_WMEM, 514 .ctl_name = NET_TCP_WMEM,
@@ -516,7 +516,7 @@ static struct ctl_table ipv4_table[] = {
516 .data = &sysctl_tcp_wmem, 516 .data = &sysctl_tcp_wmem,
517 .maxlen = sizeof(sysctl_tcp_wmem), 517 .maxlen = sizeof(sysctl_tcp_wmem),
518 .mode = 0644, 518 .mode = 0644,
519 .proc_handler = &proc_dointvec 519 .proc_handler = proc_dointvec
520 }, 520 },
521 { 521 {
522 .ctl_name = NET_TCP_RMEM, 522 .ctl_name = NET_TCP_RMEM,
@@ -524,7 +524,7 @@ static struct ctl_table ipv4_table[] = {
524 .data = &sysctl_tcp_rmem, 524 .data = &sysctl_tcp_rmem,
525 .maxlen = sizeof(sysctl_tcp_rmem), 525 .maxlen = sizeof(sysctl_tcp_rmem),
526 .mode = 0644, 526 .mode = 0644,
527 .proc_handler = &proc_dointvec 527 .proc_handler = proc_dointvec
528 }, 528 },
529 { 529 {
530 .ctl_name = NET_TCP_APP_WIN, 530 .ctl_name = NET_TCP_APP_WIN,
@@ -532,7 +532,7 @@ static struct ctl_table ipv4_table[] = {
532 .data = &sysctl_tcp_app_win, 532 .data = &sysctl_tcp_app_win,
533 .maxlen = sizeof(int), 533 .maxlen = sizeof(int),
534 .mode = 0644, 534 .mode = 0644,
535 .proc_handler = &proc_dointvec 535 .proc_handler = proc_dointvec
536 }, 536 },
537 { 537 {
538 .ctl_name = NET_TCP_ADV_WIN_SCALE, 538 .ctl_name = NET_TCP_ADV_WIN_SCALE,
@@ -540,7 +540,7 @@ static struct ctl_table ipv4_table[] = {
540 .data = &sysctl_tcp_adv_win_scale, 540 .data = &sysctl_tcp_adv_win_scale,
541 .maxlen = sizeof(int), 541 .maxlen = sizeof(int),
542 .mode = 0644, 542 .mode = 0644,
543 .proc_handler = &proc_dointvec 543 .proc_handler = proc_dointvec
544 }, 544 },
545 { 545 {
546 .ctl_name = NET_TCP_TW_REUSE, 546 .ctl_name = NET_TCP_TW_REUSE,
@@ -548,7 +548,7 @@ static struct ctl_table ipv4_table[] = {
548 .data = &sysctl_tcp_tw_reuse, 548 .data = &sysctl_tcp_tw_reuse,
549 .maxlen = sizeof(int), 549 .maxlen = sizeof(int),
550 .mode = 0644, 550 .mode = 0644,
551 .proc_handler = &proc_dointvec 551 .proc_handler = proc_dointvec
552 }, 552 },
553 { 553 {
554 .ctl_name = NET_TCP_FRTO, 554 .ctl_name = NET_TCP_FRTO,
@@ -556,7 +556,7 @@ static struct ctl_table ipv4_table[] = {
556 .data = &sysctl_tcp_frto, 556 .data = &sysctl_tcp_frto,
557 .maxlen = sizeof(int), 557 .maxlen = sizeof(int),
558 .mode = 0644, 558 .mode = 0644,
559 .proc_handler = &proc_dointvec 559 .proc_handler = proc_dointvec
560 }, 560 },
561 { 561 {
562 .ctl_name = NET_TCP_FRTO_RESPONSE, 562 .ctl_name = NET_TCP_FRTO_RESPONSE,
@@ -564,7 +564,7 @@ static struct ctl_table ipv4_table[] = {
564 .data = &sysctl_tcp_frto_response, 564 .data = &sysctl_tcp_frto_response,
565 .maxlen = sizeof(int), 565 .maxlen = sizeof(int),
566 .mode = 0644, 566 .mode = 0644,
567 .proc_handler = &proc_dointvec 567 .proc_handler = proc_dointvec
568 }, 568 },
569 { 569 {
570 .ctl_name = NET_TCP_LOW_LATENCY, 570 .ctl_name = NET_TCP_LOW_LATENCY,
@@ -572,7 +572,7 @@ static struct ctl_table ipv4_table[] = {
572 .data = &sysctl_tcp_low_latency, 572 .data = &sysctl_tcp_low_latency,
573 .maxlen = sizeof(int), 573 .maxlen = sizeof(int),
574 .mode = 0644, 574 .mode = 0644,
575 .proc_handler = &proc_dointvec 575 .proc_handler = proc_dointvec
576 }, 576 },
577 { 577 {
578 .ctl_name = NET_TCP_NO_METRICS_SAVE, 578 .ctl_name = NET_TCP_NO_METRICS_SAVE,
@@ -580,7 +580,7 @@ static struct ctl_table ipv4_table[] = {
580 .data = &sysctl_tcp_nometrics_save, 580 .data = &sysctl_tcp_nometrics_save,
581 .maxlen = sizeof(int), 581 .maxlen = sizeof(int),
582 .mode = 0644, 582 .mode = 0644,
583 .proc_handler = &proc_dointvec, 583 .proc_handler = proc_dointvec,
584 }, 584 },
585 { 585 {
586 .ctl_name = NET_TCP_MODERATE_RCVBUF, 586 .ctl_name = NET_TCP_MODERATE_RCVBUF,
@@ -588,7 +588,7 @@ static struct ctl_table ipv4_table[] = {
588 .data = &sysctl_tcp_moderate_rcvbuf, 588 .data = &sysctl_tcp_moderate_rcvbuf,
589 .maxlen = sizeof(int), 589 .maxlen = sizeof(int),
590 .mode = 0644, 590 .mode = 0644,
591 .proc_handler = &proc_dointvec, 591 .proc_handler = proc_dointvec,
592 }, 592 },
593 { 593 {
594 .ctl_name = NET_TCP_TSO_WIN_DIVISOR, 594 .ctl_name = NET_TCP_TSO_WIN_DIVISOR,
@@ -596,15 +596,15 @@ static struct ctl_table ipv4_table[] = {
596 .data = &sysctl_tcp_tso_win_divisor, 596 .data = &sysctl_tcp_tso_win_divisor,
597 .maxlen = sizeof(int), 597 .maxlen = sizeof(int),
598 .mode = 0644, 598 .mode = 0644,
599 .proc_handler = &proc_dointvec, 599 .proc_handler = proc_dointvec,
600 }, 600 },
601 { 601 {
602 .ctl_name = NET_TCP_CONG_CONTROL, 602 .ctl_name = NET_TCP_CONG_CONTROL,
603 .procname = "tcp_congestion_control", 603 .procname = "tcp_congestion_control",
604 .mode = 0644, 604 .mode = 0644,
605 .maxlen = TCP_CA_NAME_MAX, 605 .maxlen = TCP_CA_NAME_MAX,
606 .proc_handler = &proc_tcp_congestion_control, 606 .proc_handler = proc_tcp_congestion_control,
607 .strategy = &sysctl_tcp_congestion_control, 607 .strategy = sysctl_tcp_congestion_control,
608 }, 608 },
609 { 609 {
610 .ctl_name = NET_TCP_ABC, 610 .ctl_name = NET_TCP_ABC,
@@ -612,7 +612,7 @@ static struct ctl_table ipv4_table[] = {
612 .data = &sysctl_tcp_abc, 612 .data = &sysctl_tcp_abc,
613 .maxlen = sizeof(int), 613 .maxlen = sizeof(int),
614 .mode = 0644, 614 .mode = 0644,
615 .proc_handler = &proc_dointvec, 615 .proc_handler = proc_dointvec,
616 }, 616 },
617 { 617 {
618 .ctl_name = NET_TCP_MTU_PROBING, 618 .ctl_name = NET_TCP_MTU_PROBING,
@@ -620,7 +620,7 @@ static struct ctl_table ipv4_table[] = {
620 .data = &sysctl_tcp_mtu_probing, 620 .data = &sysctl_tcp_mtu_probing,
621 .maxlen = sizeof(int), 621 .maxlen = sizeof(int),
622 .mode = 0644, 622 .mode = 0644,
623 .proc_handler = &proc_dointvec, 623 .proc_handler = proc_dointvec,
624 }, 624 },
625 { 625 {
626 .ctl_name = NET_TCP_BASE_MSS, 626 .ctl_name = NET_TCP_BASE_MSS,
@@ -628,7 +628,7 @@ static struct ctl_table ipv4_table[] = {
628 .data = &sysctl_tcp_base_mss, 628 .data = &sysctl_tcp_base_mss,
629 .maxlen = sizeof(int), 629 .maxlen = sizeof(int),
630 .mode = 0644, 630 .mode = 0644,
631 .proc_handler = &proc_dointvec, 631 .proc_handler = proc_dointvec,
632 }, 632 },
633 { 633 {
634 .ctl_name = NET_IPV4_TCP_WORKAROUND_SIGNED_WINDOWS, 634 .ctl_name = NET_IPV4_TCP_WORKAROUND_SIGNED_WINDOWS,
@@ -636,7 +636,7 @@ static struct ctl_table ipv4_table[] = {
636 .data = &sysctl_tcp_workaround_signed_windows, 636 .data = &sysctl_tcp_workaround_signed_windows,
637 .maxlen = sizeof(int), 637 .maxlen = sizeof(int),
638 .mode = 0644, 638 .mode = 0644,
639 .proc_handler = &proc_dointvec 639 .proc_handler = proc_dointvec
640 }, 640 },
641#ifdef CONFIG_NET_DMA 641#ifdef CONFIG_NET_DMA
642 { 642 {
@@ -645,7 +645,7 @@ static struct ctl_table ipv4_table[] = {
645 .data = &sysctl_tcp_dma_copybreak, 645 .data = &sysctl_tcp_dma_copybreak,
646 .maxlen = sizeof(int), 646 .maxlen = sizeof(int),
647 .mode = 0644, 647 .mode = 0644,
648 .proc_handler = &proc_dointvec 648 .proc_handler = proc_dointvec
649 }, 649 },
650#endif 650#endif
651 { 651 {
@@ -654,7 +654,7 @@ static struct ctl_table ipv4_table[] = {
654 .data = &sysctl_tcp_slow_start_after_idle, 654 .data = &sysctl_tcp_slow_start_after_idle,
655 .maxlen = sizeof(int), 655 .maxlen = sizeof(int),
656 .mode = 0644, 656 .mode = 0644,
657 .proc_handler = &proc_dointvec 657 .proc_handler = proc_dointvec
658 }, 658 },
659#ifdef CONFIG_NETLABEL 659#ifdef CONFIG_NETLABEL
660 { 660 {
@@ -663,7 +663,7 @@ static struct ctl_table ipv4_table[] = {
663 .data = &cipso_v4_cache_enabled, 663 .data = &cipso_v4_cache_enabled,
664 .maxlen = sizeof(int), 664 .maxlen = sizeof(int),
665 .mode = 0644, 665 .mode = 0644,
666 .proc_handler = &proc_dointvec, 666 .proc_handler = proc_dointvec,
667 }, 667 },
668 { 668 {
669 .ctl_name = NET_CIPSOV4_CACHE_BUCKET_SIZE, 669 .ctl_name = NET_CIPSOV4_CACHE_BUCKET_SIZE,
@@ -671,7 +671,7 @@ static struct ctl_table ipv4_table[] = {
671 .data = &cipso_v4_cache_bucketsize, 671 .data = &cipso_v4_cache_bucketsize,
672 .maxlen = sizeof(int), 672 .maxlen = sizeof(int),
673 .mode = 0644, 673 .mode = 0644,
674 .proc_handler = &proc_dointvec, 674 .proc_handler = proc_dointvec,
675 }, 675 },
676 { 676 {
677 .ctl_name = NET_CIPSOV4_RBM_OPTFMT, 677 .ctl_name = NET_CIPSOV4_RBM_OPTFMT,
@@ -679,7 +679,7 @@ static struct ctl_table ipv4_table[] = {
679 .data = &cipso_v4_rbm_optfmt, 679 .data = &cipso_v4_rbm_optfmt,
680 .maxlen = sizeof(int), 680 .maxlen = sizeof(int),
681 .mode = 0644, 681 .mode = 0644,
682 .proc_handler = &proc_dointvec, 682 .proc_handler = proc_dointvec,
683 }, 683 },
684 { 684 {
685 .ctl_name = NET_CIPSOV4_RBM_STRICTVALID, 685 .ctl_name = NET_CIPSOV4_RBM_STRICTVALID,
@@ -687,22 +687,22 @@ static struct ctl_table ipv4_table[] = {
687 .data = &cipso_v4_rbm_strictvalid, 687 .data = &cipso_v4_rbm_strictvalid,
688 .maxlen = sizeof(int), 688 .maxlen = sizeof(int),
689 .mode = 0644, 689 .mode = 0644,
690 .proc_handler = &proc_dointvec, 690 .proc_handler = proc_dointvec,
691 }, 691 },
692#endif /* CONFIG_NETLABEL */ 692#endif /* CONFIG_NETLABEL */
693 { 693 {
694 .procname = "tcp_available_congestion_control", 694 .procname = "tcp_available_congestion_control",
695 .maxlen = TCP_CA_BUF_MAX, 695 .maxlen = TCP_CA_BUF_MAX,
696 .mode = 0444, 696 .mode = 0444,
697 .proc_handler = &proc_tcp_available_congestion_control, 697 .proc_handler = proc_tcp_available_congestion_control,
698 }, 698 },
699 { 699 {
700 .ctl_name = NET_TCP_ALLOWED_CONG_CONTROL, 700 .ctl_name = NET_TCP_ALLOWED_CONG_CONTROL,
701 .procname = "tcp_allowed_congestion_control", 701 .procname = "tcp_allowed_congestion_control",
702 .maxlen = TCP_CA_BUF_MAX, 702 .maxlen = TCP_CA_BUF_MAX,
703 .mode = 0644, 703 .mode = 0644,
704 .proc_handler = &proc_allowed_congestion_control, 704 .proc_handler = proc_allowed_congestion_control,
705 .strategy = &strategy_allowed_congestion_control, 705 .strategy = strategy_allowed_congestion_control,
706 }, 706 },
707 { 707 {
708 .ctl_name = NET_TCP_MAX_SSTHRESH, 708 .ctl_name = NET_TCP_MAX_SSTHRESH,
@@ -710,7 +710,7 @@ static struct ctl_table ipv4_table[] = {
710 .data = &sysctl_tcp_max_ssthresh, 710 .data = &sysctl_tcp_max_ssthresh,
711 .maxlen = sizeof(int), 711 .maxlen = sizeof(int),
712 .mode = 0644, 712 .mode = 0644,
713 .proc_handler = &proc_dointvec, 713 .proc_handler = proc_dointvec,
714 }, 714 },
715 { 715 {
716 .ctl_name = CTL_UNNUMBERED, 716 .ctl_name = CTL_UNNUMBERED,
@@ -718,8 +718,8 @@ static struct ctl_table ipv4_table[] = {
718 .data = &sysctl_udp_mem, 718 .data = &sysctl_udp_mem,
719 .maxlen = sizeof(sysctl_udp_mem), 719 .maxlen = sizeof(sysctl_udp_mem),
720 .mode = 0644, 720 .mode = 0644,
721 .proc_handler = &proc_dointvec_minmax, 721 .proc_handler = proc_dointvec_minmax,
722 .strategy = &sysctl_intvec, 722 .strategy = sysctl_intvec,
723 .extra1 = &zero 723 .extra1 = &zero
724 }, 724 },
725 { 725 {
@@ -728,8 +728,8 @@ static struct ctl_table ipv4_table[] = {
728 .data = &sysctl_udp_rmem_min, 728 .data = &sysctl_udp_rmem_min,
729 .maxlen = sizeof(sysctl_udp_rmem_min), 729 .maxlen = sizeof(sysctl_udp_rmem_min),
730 .mode = 0644, 730 .mode = 0644,
731 .proc_handler = &proc_dointvec_minmax, 731 .proc_handler = proc_dointvec_minmax,
732 .strategy = &sysctl_intvec, 732 .strategy = sysctl_intvec,
733 .extra1 = &zero 733 .extra1 = &zero
734 }, 734 },
735 { 735 {
@@ -738,8 +738,8 @@ static struct ctl_table ipv4_table[] = {
738 .data = &sysctl_udp_wmem_min, 738 .data = &sysctl_udp_wmem_min,
739 .maxlen = sizeof(sysctl_udp_wmem_min), 739 .maxlen = sizeof(sysctl_udp_wmem_min),
740 .mode = 0644, 740 .mode = 0644,
741 .proc_handler = &proc_dointvec_minmax, 741 .proc_handler = proc_dointvec_minmax,
742 .strategy = &sysctl_intvec, 742 .strategy = sysctl_intvec,
743 .extra1 = &zero 743 .extra1 = &zero
744 }, 744 },
745 { .ctl_name = 0 } 745 { .ctl_name = 0 }
@@ -752,7 +752,7 @@ static struct ctl_table ipv4_net_table[] = {
752 .data = &init_net.ipv4.sysctl_icmp_echo_ignore_all, 752 .data = &init_net.ipv4.sysctl_icmp_echo_ignore_all,
753 .maxlen = sizeof(int), 753 .maxlen = sizeof(int),
754 .mode = 0644, 754 .mode = 0644,
755 .proc_handler = &proc_dointvec 755 .proc_handler = proc_dointvec
756 }, 756 },
757 { 757 {
758 .ctl_name = NET_IPV4_ICMP_ECHO_IGNORE_BROADCASTS, 758 .ctl_name = NET_IPV4_ICMP_ECHO_IGNORE_BROADCASTS,
@@ -760,7 +760,7 @@ static struct ctl_table ipv4_net_table[] = {
760 .data = &init_net.ipv4.sysctl_icmp_echo_ignore_broadcasts, 760 .data = &init_net.ipv4.sysctl_icmp_echo_ignore_broadcasts,
761 .maxlen = sizeof(int), 761 .maxlen = sizeof(int),
762 .mode = 0644, 762 .mode = 0644,
763 .proc_handler = &proc_dointvec 763 .proc_handler = proc_dointvec
764 }, 764 },
765 { 765 {
766 .ctl_name = NET_IPV4_ICMP_IGNORE_BOGUS_ERROR_RESPONSES, 766 .ctl_name = NET_IPV4_ICMP_IGNORE_BOGUS_ERROR_RESPONSES,
@@ -768,7 +768,7 @@ static struct ctl_table ipv4_net_table[] = {
768 .data = &init_net.ipv4.sysctl_icmp_ignore_bogus_error_responses, 768 .data = &init_net.ipv4.sysctl_icmp_ignore_bogus_error_responses,
769 .maxlen = sizeof(int), 769 .maxlen = sizeof(int),
770 .mode = 0644, 770 .mode = 0644,
771 .proc_handler = &proc_dointvec 771 .proc_handler = proc_dointvec
772 }, 772 },
773 { 773 {
774 .ctl_name = NET_IPV4_ICMP_ERRORS_USE_INBOUND_IFADDR, 774 .ctl_name = NET_IPV4_ICMP_ERRORS_USE_INBOUND_IFADDR,
@@ -776,7 +776,7 @@ static struct ctl_table ipv4_net_table[] = {
776 .data = &init_net.ipv4.sysctl_icmp_errors_use_inbound_ifaddr, 776 .data = &init_net.ipv4.sysctl_icmp_errors_use_inbound_ifaddr,
777 .maxlen = sizeof(int), 777 .maxlen = sizeof(int),
778 .mode = 0644, 778 .mode = 0644,
779 .proc_handler = &proc_dointvec 779 .proc_handler = proc_dointvec
780 }, 780 },
781 { 781 {
782 .ctl_name = NET_IPV4_ICMP_RATELIMIT, 782 .ctl_name = NET_IPV4_ICMP_RATELIMIT,
@@ -784,8 +784,8 @@ static struct ctl_table ipv4_net_table[] = {
784 .data = &init_net.ipv4.sysctl_icmp_ratelimit, 784 .data = &init_net.ipv4.sysctl_icmp_ratelimit,
785 .maxlen = sizeof(int), 785 .maxlen = sizeof(int),
786 .mode = 0644, 786 .mode = 0644,
787 .proc_handler = &proc_dointvec_ms_jiffies, 787 .proc_handler = proc_dointvec_ms_jiffies,
788 .strategy = &sysctl_ms_jiffies 788 .strategy = sysctl_ms_jiffies
789 }, 789 },
790 { 790 {
791 .ctl_name = NET_IPV4_ICMP_RATEMASK, 791 .ctl_name = NET_IPV4_ICMP_RATEMASK,
@@ -793,7 +793,15 @@ static struct ctl_table ipv4_net_table[] = {
793 .data = &init_net.ipv4.sysctl_icmp_ratemask, 793 .data = &init_net.ipv4.sysctl_icmp_ratemask,
794 .maxlen = sizeof(int), 794 .maxlen = sizeof(int),
795 .mode = 0644, 795 .mode = 0644,
796 .proc_handler = &proc_dointvec 796 .proc_handler = proc_dointvec
797 },
798 {
799 .ctl_name = CTL_UNNUMBERED,
800 .procname = "rt_cache_rebuild_count",
801 .data = &init_net.ipv4.sysctl_rt_cache_rebuild_count,
802 .maxlen = sizeof(int),
803 .mode = 0644,
804 .proc_handler = proc_dointvec
797 }, 805 },
798 { } 806 { }
799}; 807};
@@ -827,8 +835,12 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)
827 &net->ipv4.sysctl_icmp_ratelimit; 835 &net->ipv4.sysctl_icmp_ratelimit;
828 table[5].data = 836 table[5].data =
829 &net->ipv4.sysctl_icmp_ratemask; 837 &net->ipv4.sysctl_icmp_ratemask;
838 table[6].data =
839 &net->ipv4.sysctl_rt_cache_rebuild_count;
830 } 840 }
831 841
842 net->ipv4.sysctl_rt_cache_rebuild_count = 4;
843
832 net->ipv4.ipv4_hdr = register_net_sysctl_table(net, 844 net->ipv4.ipv4_hdr = register_net_sysctl_table(net,
833 net_ipv4_ctl_path, table); 845 net_ipv4_ctl_path, table);
834 if (net->ipv4.ipv4_hdr == NULL) 846 if (net->ipv4.ipv4_hdr == NULL)
diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
index c5aca0bb116a..1f3d52946b3b 100644
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ -277,8 +277,7 @@
277 277
278int sysctl_tcp_fin_timeout __read_mostly = TCP_FIN_TIMEOUT; 278int sysctl_tcp_fin_timeout __read_mostly = TCP_FIN_TIMEOUT;
279 279
280atomic_t tcp_orphan_count = ATOMIC_INIT(0); 280struct percpu_counter tcp_orphan_count;
281
282EXPORT_SYMBOL_GPL(tcp_orphan_count); 281EXPORT_SYMBOL_GPL(tcp_orphan_count);
283 282
284int sysctl_tcp_mem[3] __read_mostly; 283int sysctl_tcp_mem[3] __read_mostly;
@@ -290,9 +289,12 @@ EXPORT_SYMBOL(sysctl_tcp_rmem);
290EXPORT_SYMBOL(sysctl_tcp_wmem); 289EXPORT_SYMBOL(sysctl_tcp_wmem);
291 290
292atomic_t tcp_memory_allocated; /* Current allocated memory. */ 291atomic_t tcp_memory_allocated; /* Current allocated memory. */
293atomic_t tcp_sockets_allocated; /* Current number of TCP sockets. */
294
295EXPORT_SYMBOL(tcp_memory_allocated); 292EXPORT_SYMBOL(tcp_memory_allocated);
293
294/*
295 * Current number of TCP sockets.
296 */
297struct percpu_counter tcp_sockets_allocated;
296EXPORT_SYMBOL(tcp_sockets_allocated); 298EXPORT_SYMBOL(tcp_sockets_allocated);
297 299
298/* 300/*
@@ -1680,7 +1682,7 @@ void tcp_set_state(struct sock *sk, int state)
1680 inet_put_port(sk); 1682 inet_put_port(sk);
1681 /* fall through */ 1683 /* fall through */
1682 default: 1684 default:
1683 if (oldstate==TCP_ESTABLISHED) 1685 if (oldstate == TCP_ESTABLISHED)
1684 TCP_DEC_STATS(sock_net(sk), TCP_MIB_CURRESTAB); 1686 TCP_DEC_STATS(sock_net(sk), TCP_MIB_CURRESTAB);
1685 } 1687 }
1686 1688
@@ -1690,7 +1692,7 @@ void tcp_set_state(struct sock *sk, int state)
1690 sk->sk_state = state; 1692 sk->sk_state = state;
1691 1693
1692#ifdef STATE_TRACE 1694#ifdef STATE_TRACE
1693 SOCK_DEBUG(sk, "TCP sk=%p, State %s -> %s\n",sk, statename[oldstate],statename[state]); 1695 SOCK_DEBUG(sk, "TCP sk=%p, State %s -> %s\n", sk, statename[oldstate], statename[state]);
1694#endif 1696#endif
1695} 1697}
1696EXPORT_SYMBOL_GPL(tcp_set_state); 1698EXPORT_SYMBOL_GPL(tcp_set_state);
@@ -1834,7 +1836,7 @@ adjudge_to_death:
1834 state = sk->sk_state; 1836 state = sk->sk_state;
1835 sock_hold(sk); 1837 sock_hold(sk);
1836 sock_orphan(sk); 1838 sock_orphan(sk);
1837 atomic_inc(sk->sk_prot->orphan_count); 1839 percpu_counter_inc(sk->sk_prot->orphan_count);
1838 1840
1839 /* It is the last release_sock in its life. It will remove backlog. */ 1841 /* It is the last release_sock in its life. It will remove backlog. */
1840 release_sock(sk); 1842 release_sock(sk);
@@ -1885,9 +1887,11 @@ adjudge_to_death:
1885 } 1887 }
1886 } 1888 }
1887 if (sk->sk_state != TCP_CLOSE) { 1889 if (sk->sk_state != TCP_CLOSE) {
1890 int orphan_count = percpu_counter_read_positive(
1891 sk->sk_prot->orphan_count);
1892
1888 sk_mem_reclaim(sk); 1893 sk_mem_reclaim(sk);
1889 if (tcp_too_many_orphans(sk, 1894 if (tcp_too_many_orphans(sk, orphan_count)) {
1890 atomic_read(sk->sk_prot->orphan_count))) {
1891 if (net_ratelimit()) 1895 if (net_ratelimit())
1892 printk(KERN_INFO "TCP: too many of orphaned " 1896 printk(KERN_INFO "TCP: too many of orphaned "
1893 "sockets\n"); 1897 "sockets\n");
@@ -2461,6 +2465,106 @@ out:
2461} 2465}
2462EXPORT_SYMBOL(tcp_tso_segment); 2466EXPORT_SYMBOL(tcp_tso_segment);
2463 2467
2468struct sk_buff **tcp_gro_receive(struct sk_buff **head, struct sk_buff *skb)
2469{
2470 struct sk_buff **pp = NULL;
2471 struct sk_buff *p;
2472 struct tcphdr *th;
2473 struct tcphdr *th2;
2474 unsigned int thlen;
2475 unsigned int flags;
2476 unsigned int total;
2477 unsigned int mss = 1;
2478 int flush = 1;
2479
2480 if (!pskb_may_pull(skb, sizeof(*th)))
2481 goto out;
2482
2483 th = tcp_hdr(skb);
2484 thlen = th->doff * 4;
2485 if (thlen < sizeof(*th))
2486 goto out;
2487
2488 if (!pskb_may_pull(skb, thlen))
2489 goto out;
2490
2491 th = tcp_hdr(skb);
2492 __skb_pull(skb, thlen);
2493
2494 flags = tcp_flag_word(th);
2495
2496 for (; (p = *head); head = &p->next) {
2497 if (!NAPI_GRO_CB(p)->same_flow)
2498 continue;
2499
2500 th2 = tcp_hdr(p);
2501
2502 if (th->source != th2->source || th->dest != th2->dest) {
2503 NAPI_GRO_CB(p)->same_flow = 0;
2504 continue;
2505 }
2506
2507 goto found;
2508 }
2509
2510 goto out_check_final;
2511
2512found:
2513 flush = NAPI_GRO_CB(p)->flush;
2514 flush |= flags & TCP_FLAG_CWR;
2515 flush |= (flags ^ tcp_flag_word(th2)) &
2516 ~(TCP_FLAG_CWR | TCP_FLAG_FIN | TCP_FLAG_PSH);
2517 flush |= th->ack_seq != th2->ack_seq || th->window != th2->window;
2518 flush |= memcmp(th + 1, th2 + 1, thlen - sizeof(*th));
2519
2520 total = p->len;
2521 mss = total;
2522 if (skb_shinfo(p)->frag_list)
2523 mss = skb_shinfo(p)->frag_list->len;
2524
2525 flush |= skb->len > mss || skb->len <= 0;
2526 flush |= ntohl(th2->seq) + total != ntohl(th->seq);
2527
2528 if (flush || skb_gro_receive(head, skb)) {
2529 mss = 1;
2530 goto out_check_final;
2531 }
2532
2533 p = *head;
2534 th2 = tcp_hdr(p);
2535 tcp_flag_word(th2) |= flags & (TCP_FLAG_FIN | TCP_FLAG_PSH);
2536
2537out_check_final:
2538 flush = skb->len < mss;
2539 flush |= flags & (TCP_FLAG_URG | TCP_FLAG_PSH | TCP_FLAG_RST |
2540 TCP_FLAG_SYN | TCP_FLAG_FIN);
2541
2542 if (p && (!NAPI_GRO_CB(skb)->same_flow || flush))
2543 pp = head;
2544
2545out:
2546 NAPI_GRO_CB(skb)->flush |= flush;
2547
2548 return pp;
2549}
2550
2551int tcp_gro_complete(struct sk_buff *skb)
2552{
2553 struct tcphdr *th = tcp_hdr(skb);
2554
2555 skb->csum_start = skb_transport_header(skb) - skb->head;
2556 skb->csum_offset = offsetof(struct tcphdr, check);
2557 skb->ip_summed = CHECKSUM_PARTIAL;
2558
2559 skb_shinfo(skb)->gso_size = skb_shinfo(skb)->frag_list->len;
2560 skb_shinfo(skb)->gso_segs = NAPI_GRO_CB(skb)->count;
2561
2562 if (th->cwr)
2563 skb_shinfo(skb)->gso_type |= SKB_GSO_TCP_ECN;
2564
2565 return 0;
2566}
2567
2464#ifdef CONFIG_TCP_MD5SIG 2568#ifdef CONFIG_TCP_MD5SIG
2465static unsigned long tcp_md5sig_users; 2569static unsigned long tcp_md5sig_users;
2466static struct tcp_md5sig_pool **tcp_md5sig_pool; 2570static struct tcp_md5sig_pool **tcp_md5sig_pool;
@@ -2650,7 +2754,7 @@ EXPORT_SYMBOL(tcp_md5_hash_key);
2650 2754
2651void tcp_done(struct sock *sk) 2755void tcp_done(struct sock *sk)
2652{ 2756{
2653 if(sk->sk_state == TCP_SYN_SENT || sk->sk_state == TCP_SYN_RECV) 2757 if (sk->sk_state == TCP_SYN_SENT || sk->sk_state == TCP_SYN_RECV)
2654 TCP_INC_STATS_BH(sock_net(sk), TCP_MIB_ATTEMPTFAILS); 2758 TCP_INC_STATS_BH(sock_net(sk), TCP_MIB_ATTEMPTFAILS);
2655 2759
2656 tcp_set_state(sk, TCP_CLOSE); 2760 tcp_set_state(sk, TCP_CLOSE);
@@ -2685,6 +2789,8 @@ void __init tcp_init(void)
2685 2789
2686 BUILD_BUG_ON(sizeof(struct tcp_skb_cb) > sizeof(skb->cb)); 2790 BUILD_BUG_ON(sizeof(struct tcp_skb_cb) > sizeof(skb->cb));
2687 2791
2792 percpu_counter_init(&tcp_sockets_allocated, 0);
2793 percpu_counter_init(&tcp_orphan_count, 0);
2688 tcp_hashinfo.bind_bucket_cachep = 2794 tcp_hashinfo.bind_bucket_cachep =
2689 kmem_cache_create("tcp_bind_bucket", 2795 kmem_cache_create("tcp_bind_bucket",
2690 sizeof(struct inet_bind_bucket), 0, 2796 sizeof(struct inet_bind_bucket), 0,
@@ -2707,8 +2813,8 @@ void __init tcp_init(void)
2707 thash_entries ? 0 : 512 * 1024); 2813 thash_entries ? 0 : 512 * 1024);
2708 tcp_hashinfo.ehash_size = 1 << tcp_hashinfo.ehash_size; 2814 tcp_hashinfo.ehash_size = 1 << tcp_hashinfo.ehash_size;
2709 for (i = 0; i < tcp_hashinfo.ehash_size; i++) { 2815 for (i = 0; i < tcp_hashinfo.ehash_size; i++) {
2710 INIT_HLIST_HEAD(&tcp_hashinfo.ehash[i].chain); 2816 INIT_HLIST_NULLS_HEAD(&tcp_hashinfo.ehash[i].chain, i);
2711 INIT_HLIST_HEAD(&tcp_hashinfo.ehash[i].twchain); 2817 INIT_HLIST_NULLS_HEAD(&tcp_hashinfo.ehash[i].twchain, i);
2712 } 2818 }
2713 if (inet_ehash_locks_alloc(&tcp_hashinfo)) 2819 if (inet_ehash_locks_alloc(&tcp_hashinfo))
2714 panic("TCP: failed to alloc ehash_locks"); 2820 panic("TCP: failed to alloc ehash_locks");
diff --git a/net/ipv4/tcp_cubic.c b/net/ipv4/tcp_cubic.c
index 4a1221e5e8ee..ee467ec40c4f 100644
--- a/net/ipv4/tcp_cubic.c
+++ b/net/ipv4/tcp_cubic.c
@@ -1,13 +1,23 @@
1/* 1/*
2 * TCP CUBIC: Binary Increase Congestion control for TCP v2.2 2 * TCP CUBIC: Binary Increase Congestion control for TCP v2.3
3 * Home page: 3 * Home page:
4 * http://netsrv.csc.ncsu.edu/twiki/bin/view/Main/BIC 4 * http://netsrv.csc.ncsu.edu/twiki/bin/view/Main/BIC
5 * This is from the implementation of CUBIC TCP in 5 * This is from the implementation of CUBIC TCP in
6 * Injong Rhee, Lisong Xu. 6 * Sangtae Ha, Injong Rhee and Lisong Xu,
7 * "CUBIC: A New TCP-Friendly High-Speed TCP Variant 7 * "CUBIC: A New TCP-Friendly High-Speed TCP Variant"
8 * in PFLDnet 2005 8 * in ACM SIGOPS Operating System Review, July 2008.
9 * Available from: 9 * Available from:
10 * http://netsrv.csc.ncsu.edu/export/cubic-paper.pdf 10 * http://netsrv.csc.ncsu.edu/export/cubic_a_new_tcp_2008.pdf
11 *
12 * CUBIC integrates a new slow start algorithm, called HyStart.
13 * The details of HyStart are presented in
14 * Sangtae Ha and Injong Rhee,
15 * "Taming the Elephants: New TCP Slow Start", NCSU TechReport 2008.
16 * Available from:
17 * http://netsrv.csc.ncsu.edu/export/hystart_techreport_2008.pdf
18 *
19 * All testing results are available from:
20 * http://netsrv.csc.ncsu.edu/wiki/index.php/TCP_Testing
11 * 21 *
12 * Unless CUBIC is enabled and congestion window is large 22 * Unless CUBIC is enabled and congestion window is large
13 * this behaves the same as the original Reno. 23 * this behaves the same as the original Reno.
@@ -23,12 +33,26 @@
23 */ 33 */
24#define BICTCP_HZ 10 /* BIC HZ 2^10 = 1024 */ 34#define BICTCP_HZ 10 /* BIC HZ 2^10 = 1024 */
25 35
36/* Two methods of hybrid slow start */
37#define HYSTART_ACK_TRAIN 0x1
38#define HYSTART_DELAY 0x2
39
40/* Number of delay samples for detecting the increase of delay */
41#define HYSTART_MIN_SAMPLES 8
42#define HYSTART_DELAY_MIN (2U<<3)
43#define HYSTART_DELAY_MAX (16U<<3)
44#define HYSTART_DELAY_THRESH(x) clamp(x, HYSTART_DELAY_MIN, HYSTART_DELAY_MAX)
45
26static int fast_convergence __read_mostly = 1; 46static int fast_convergence __read_mostly = 1;
27static int beta __read_mostly = 717; /* = 717/1024 (BICTCP_BETA_SCALE) */ 47static int beta __read_mostly = 717; /* = 717/1024 (BICTCP_BETA_SCALE) */
28static int initial_ssthresh __read_mostly; 48static int initial_ssthresh __read_mostly;
29static int bic_scale __read_mostly = 41; 49static int bic_scale __read_mostly = 41;
30static int tcp_friendliness __read_mostly = 1; 50static int tcp_friendliness __read_mostly = 1;
31 51
52static int hystart __read_mostly = 1;
53static int hystart_detect __read_mostly = HYSTART_ACK_TRAIN | HYSTART_DELAY;
54static int hystart_low_window __read_mostly = 16;
55
32static u32 cube_rtt_scale __read_mostly; 56static u32 cube_rtt_scale __read_mostly;
33static u32 beta_scale __read_mostly; 57static u32 beta_scale __read_mostly;
34static u64 cube_factor __read_mostly; 58static u64 cube_factor __read_mostly;
@@ -44,6 +68,13 @@ module_param(bic_scale, int, 0444);
44MODULE_PARM_DESC(bic_scale, "scale (scaled by 1024) value for bic function (bic_scale/1024)"); 68MODULE_PARM_DESC(bic_scale, "scale (scaled by 1024) value for bic function (bic_scale/1024)");
45module_param(tcp_friendliness, int, 0644); 69module_param(tcp_friendliness, int, 0644);
46MODULE_PARM_DESC(tcp_friendliness, "turn on/off tcp friendliness"); 70MODULE_PARM_DESC(tcp_friendliness, "turn on/off tcp friendliness");
71module_param(hystart, int, 0644);
72MODULE_PARM_DESC(hystart, "turn on/off hybrid slow start algorithm");
73module_param(hystart_detect, int, 0644);
74MODULE_PARM_DESC(hystart_detect, "hyrbrid slow start detection mechanisms"
75 " 1: packet-train 2: delay 3: both packet-train and delay");
76module_param(hystart_low_window, int, 0644);
77MODULE_PARM_DESC(hystart_low_window, "lower bound cwnd for hybrid slow start");
47 78
48/* BIC TCP Parameters */ 79/* BIC TCP Parameters */
49struct bictcp { 80struct bictcp {
@@ -59,7 +90,13 @@ struct bictcp {
59 u32 ack_cnt; /* number of acks */ 90 u32 ack_cnt; /* number of acks */
60 u32 tcp_cwnd; /* estimated tcp cwnd */ 91 u32 tcp_cwnd; /* estimated tcp cwnd */
61#define ACK_RATIO_SHIFT 4 92#define ACK_RATIO_SHIFT 4
62 u32 delayed_ack; /* estimate the ratio of Packets/ACKs << 4 */ 93 u16 delayed_ack; /* estimate the ratio of Packets/ACKs << 4 */
94 u8 sample_cnt; /* number of samples to decide curr_rtt */
95 u8 found; /* the exit point is found? */
96 u32 round_start; /* beginning of each round */
97 u32 end_seq; /* end_seq of the round */
98 u32 last_jiffies; /* last time when the ACK spacing is close */
99 u32 curr_rtt; /* the minimum rtt of current round */
63}; 100};
64 101
65static inline void bictcp_reset(struct bictcp *ca) 102static inline void bictcp_reset(struct bictcp *ca)
@@ -76,12 +113,28 @@ static inline void bictcp_reset(struct bictcp *ca)
76 ca->delayed_ack = 2 << ACK_RATIO_SHIFT; 113 ca->delayed_ack = 2 << ACK_RATIO_SHIFT;
77 ca->ack_cnt = 0; 114 ca->ack_cnt = 0;
78 ca->tcp_cwnd = 0; 115 ca->tcp_cwnd = 0;
116 ca->found = 0;
117}
118
119static inline void bictcp_hystart_reset(struct sock *sk)
120{
121 struct tcp_sock *tp = tcp_sk(sk);
122 struct bictcp *ca = inet_csk_ca(sk);
123
124 ca->round_start = ca->last_jiffies = jiffies;
125 ca->end_seq = tp->snd_nxt;
126 ca->curr_rtt = 0;
127 ca->sample_cnt = 0;
79} 128}
80 129
81static void bictcp_init(struct sock *sk) 130static void bictcp_init(struct sock *sk)
82{ 131{
83 bictcp_reset(inet_csk_ca(sk)); 132 bictcp_reset(inet_csk_ca(sk));
84 if (initial_ssthresh) 133
134 if (hystart)
135 bictcp_hystart_reset(sk);
136
137 if (!hystart && initial_ssthresh)
85 tcp_sk(sk)->snd_ssthresh = initial_ssthresh; 138 tcp_sk(sk)->snd_ssthresh = initial_ssthresh;
86} 139}
87 140
@@ -235,9 +288,11 @@ static void bictcp_cong_avoid(struct sock *sk, u32 ack, u32 in_flight)
235 if (!tcp_is_cwnd_limited(sk, in_flight)) 288 if (!tcp_is_cwnd_limited(sk, in_flight))
236 return; 289 return;
237 290
238 if (tp->snd_cwnd <= tp->snd_ssthresh) 291 if (tp->snd_cwnd <= tp->snd_ssthresh) {
292 if (hystart && after(ack, ca->end_seq))
293 bictcp_hystart_reset(sk);
239 tcp_slow_start(tp); 294 tcp_slow_start(tp);
240 else { 295 } else {
241 bictcp_update(ca, tp->snd_cwnd); 296 bictcp_update(ca, tp->snd_cwnd);
242 297
243 /* In dangerous area, increase slowly. 298 /* In dangerous area, increase slowly.
@@ -281,8 +336,45 @@ static u32 bictcp_undo_cwnd(struct sock *sk)
281 336
282static void bictcp_state(struct sock *sk, u8 new_state) 337static void bictcp_state(struct sock *sk, u8 new_state)
283{ 338{
284 if (new_state == TCP_CA_Loss) 339 if (new_state == TCP_CA_Loss) {
285 bictcp_reset(inet_csk_ca(sk)); 340 bictcp_reset(inet_csk_ca(sk));
341 bictcp_hystart_reset(sk);
342 }
343}
344
345static void hystart_update(struct sock *sk, u32 delay)
346{
347 struct tcp_sock *tp = tcp_sk(sk);
348 struct bictcp *ca = inet_csk_ca(sk);
349
350 if (!(ca->found & hystart_detect)) {
351 u32 curr_jiffies = jiffies;
352
353 /* first detection parameter - ack-train detection */
354 if (curr_jiffies - ca->last_jiffies <= msecs_to_jiffies(2)) {
355 ca->last_jiffies = curr_jiffies;
356 if (curr_jiffies - ca->round_start >= ca->delay_min>>4)
357 ca->found |= HYSTART_ACK_TRAIN;
358 }
359
360 /* obtain the minimum delay of more than sampling packets */
361 if (ca->sample_cnt < HYSTART_MIN_SAMPLES) {
362 if (ca->curr_rtt == 0 || ca->curr_rtt > delay)
363 ca->curr_rtt = delay;
364
365 ca->sample_cnt++;
366 } else {
367 if (ca->curr_rtt > ca->delay_min +
368 HYSTART_DELAY_THRESH(ca->delay_min>>4))
369 ca->found |= HYSTART_DELAY;
370 }
371 /*
372 * Either one of two conditions are met,
373 * we exit from slow start immediately.
374 */
375 if (ca->found & hystart_detect)
376 tp->snd_ssthresh = tp->snd_cwnd;
377 }
286} 378}
287 379
288/* Track delayed acknowledgment ratio using sliding window 380/* Track delayed acknowledgment ratio using sliding window
@@ -291,6 +383,7 @@ static void bictcp_state(struct sock *sk, u8 new_state)
291static void bictcp_acked(struct sock *sk, u32 cnt, s32 rtt_us) 383static void bictcp_acked(struct sock *sk, u32 cnt, s32 rtt_us)
292{ 384{
293 const struct inet_connection_sock *icsk = inet_csk(sk); 385 const struct inet_connection_sock *icsk = inet_csk(sk);
386 const struct tcp_sock *tp = tcp_sk(sk);
294 struct bictcp *ca = inet_csk_ca(sk); 387 struct bictcp *ca = inet_csk_ca(sk);
295 u32 delay; 388 u32 delay;
296 389
@@ -314,6 +407,11 @@ static void bictcp_acked(struct sock *sk, u32 cnt, s32 rtt_us)
314 /* first time call or link delay decreases */ 407 /* first time call or link delay decreases */
315 if (ca->delay_min == 0 || ca->delay_min > delay) 408 if (ca->delay_min == 0 || ca->delay_min > delay)
316 ca->delay_min = delay; 409 ca->delay_min = delay;
410
411 /* hystart triggers when cwnd is larger than some threshold */
412 if (hystart && tp->snd_cwnd <= tp->snd_ssthresh &&
413 tp->snd_cwnd >= hystart_low_window)
414 hystart_update(sk, delay);
317} 415}
318 416
319static struct tcp_congestion_ops cubictcp = { 417static struct tcp_congestion_ops cubictcp = {
@@ -372,4 +470,4 @@ module_exit(cubictcp_unregister);
372MODULE_AUTHOR("Sangtae Ha, Stephen Hemminger"); 470MODULE_AUTHOR("Sangtae Ha, Stephen Hemminger");
373MODULE_LICENSE("GPL"); 471MODULE_LICENSE("GPL");
374MODULE_DESCRIPTION("CUBIC TCP"); 472MODULE_DESCRIPTION("CUBIC TCP");
375MODULE_VERSION("2.2"); 473MODULE_VERSION("2.3");
diff --git a/net/ipv4/tcp_diag.c b/net/ipv4/tcp_diag.c
index 838d491dfda7..fcbcd4ff6c5f 100644
--- a/net/ipv4/tcp_diag.c
+++ b/net/ipv4/tcp_diag.c
@@ -34,7 +34,7 @@ static void tcp_diag_get_info(struct sock *sk, struct inet_diag_msg *r,
34 tcp_get_info(sk, info); 34 tcp_get_info(sk, info);
35} 35}
36 36
37static struct inet_diag_handler tcp_diag_handler = { 37static const struct inet_diag_handler tcp_diag_handler = {
38 .idiag_hashinfo = &tcp_hashinfo, 38 .idiag_hashinfo = &tcp_hashinfo,
39 .idiag_get_info = tcp_diag_get_info, 39 .idiag_get_info = tcp_diag_get_info,
40 .idiag_type = TCPDIAG_GETSOCK, 40 .idiag_type = TCPDIAG_GETSOCK,
diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
index d77c0d29e239..99b7ecbe8893 100644
--- a/net/ipv4/tcp_input.c
+++ b/net/ipv4/tcp_input.c
@@ -701,13 +701,10 @@ static inline void tcp_set_rto(struct sock *sk)
701 * all the algo is pure shit and should be replaced 701 * all the algo is pure shit and should be replaced
702 * with correct one. It is exactly, which we pretend to do. 702 * with correct one. It is exactly, which we pretend to do.
703 */ 703 */
704}
705 704
706/* NOTE: clamping at TCP_RTO_MIN is not required, current algo 705 /* NOTE: clamping at TCP_RTO_MIN is not required, current algo
707 * guarantees that rto is higher. 706 * guarantees that rto is higher.
708 */ 707 */
709static inline void tcp_bound_rto(struct sock *sk)
710{
711 if (inet_csk(sk)->icsk_rto > TCP_RTO_MAX) 708 if (inet_csk(sk)->icsk_rto > TCP_RTO_MAX)
712 inet_csk(sk)->icsk_rto = TCP_RTO_MAX; 709 inet_csk(sk)->icsk_rto = TCP_RTO_MAX;
713} 710}
@@ -928,7 +925,6 @@ static void tcp_init_metrics(struct sock *sk)
928 tp->mdev_max = tp->rttvar = max(tp->mdev, tcp_rto_min(sk)); 925 tp->mdev_max = tp->rttvar = max(tp->mdev, tcp_rto_min(sk));
929 } 926 }
930 tcp_set_rto(sk); 927 tcp_set_rto(sk);
931 tcp_bound_rto(sk);
932 if (inet_csk(sk)->icsk_rto < TCP_TIMEOUT_INIT && !tp->rx_opt.saw_tstamp) 928 if (inet_csk(sk)->icsk_rto < TCP_TIMEOUT_INIT && !tp->rx_opt.saw_tstamp)
933 goto reset; 929 goto reset;
934 tp->snd_cwnd = tcp_init_cwnd(tp, dst); 930 tp->snd_cwnd = tcp_init_cwnd(tp, dst);
@@ -1002,7 +998,8 @@ static void tcp_skb_mark_lost(struct tcp_sock *tp, struct sk_buff *skb)
1002 } 998 }
1003} 999}
1004 1000
1005void tcp_skb_mark_lost_uncond_verify(struct tcp_sock *tp, struct sk_buff *skb) 1001static void tcp_skb_mark_lost_uncond_verify(struct tcp_sock *tp,
1002 struct sk_buff *skb)
1006{ 1003{
1007 tcp_verify_retransmit_hint(tp, skb); 1004 tcp_verify_retransmit_hint(tp, skb);
1008 1005
@@ -1236,31 +1233,58 @@ static int tcp_check_dsack(struct sock *sk, struct sk_buff *ack_skb,
1236 return dup_sack; 1233 return dup_sack;
1237} 1234}
1238 1235
1236struct tcp_sacktag_state {
1237 int reord;
1238 int fack_count;
1239 int flag;
1240};
1241
1239/* Check if skb is fully within the SACK block. In presence of GSO skbs, 1242/* Check if skb is fully within the SACK block. In presence of GSO skbs,
1240 * the incoming SACK may not exactly match but we can find smaller MSS 1243 * the incoming SACK may not exactly match but we can find smaller MSS
1241 * aligned portion of it that matches. Therefore we might need to fragment 1244 * aligned portion of it that matches. Therefore we might need to fragment
1242 * which may fail and creates some hassle (caller must handle error case 1245 * which may fail and creates some hassle (caller must handle error case
1243 * returns). 1246 * returns).
1247 *
1248 * FIXME: this could be merged to shift decision code
1244 */ 1249 */
1245static int tcp_match_skb_to_sack(struct sock *sk, struct sk_buff *skb, 1250static int tcp_match_skb_to_sack(struct sock *sk, struct sk_buff *skb,
1246 u32 start_seq, u32 end_seq) 1251 u32 start_seq, u32 end_seq)
1247{ 1252{
1248 int in_sack, err; 1253 int in_sack, err;
1249 unsigned int pkt_len; 1254 unsigned int pkt_len;
1255 unsigned int mss;
1250 1256
1251 in_sack = !after(start_seq, TCP_SKB_CB(skb)->seq) && 1257 in_sack = !after(start_seq, TCP_SKB_CB(skb)->seq) &&
1252 !before(end_seq, TCP_SKB_CB(skb)->end_seq); 1258 !before(end_seq, TCP_SKB_CB(skb)->end_seq);
1253 1259
1254 if (tcp_skb_pcount(skb) > 1 && !in_sack && 1260 if (tcp_skb_pcount(skb) > 1 && !in_sack &&
1255 after(TCP_SKB_CB(skb)->end_seq, start_seq)) { 1261 after(TCP_SKB_CB(skb)->end_seq, start_seq)) {
1256 1262 mss = tcp_skb_mss(skb);
1257 in_sack = !after(start_seq, TCP_SKB_CB(skb)->seq); 1263 in_sack = !after(start_seq, TCP_SKB_CB(skb)->seq);
1258 1264
1259 if (!in_sack) 1265 if (!in_sack) {
1260 pkt_len = start_seq - TCP_SKB_CB(skb)->seq; 1266 pkt_len = start_seq - TCP_SKB_CB(skb)->seq;
1261 else 1267 if (pkt_len < mss)
1268 pkt_len = mss;
1269 } else {
1262 pkt_len = end_seq - TCP_SKB_CB(skb)->seq; 1270 pkt_len = end_seq - TCP_SKB_CB(skb)->seq;
1263 err = tcp_fragment(sk, skb, pkt_len, skb_shinfo(skb)->gso_size); 1271 if (pkt_len < mss)
1272 return -EINVAL;
1273 }
1274
1275 /* Round if necessary so that SACKs cover only full MSSes
1276 * and/or the remaining small portion (if present)
1277 */
1278 if (pkt_len > mss) {
1279 unsigned int new_len = (pkt_len / mss) * mss;
1280 if (!in_sack && new_len < pkt_len) {
1281 new_len += mss;
1282 if (new_len > skb->len)
1283 return 0;
1284 }
1285 pkt_len = new_len;
1286 }
1287 err = tcp_fragment(sk, skb, pkt_len, mss);
1264 if (err < 0) 1288 if (err < 0)
1265 return err; 1289 return err;
1266 } 1290 }
@@ -1268,24 +1292,25 @@ static int tcp_match_skb_to_sack(struct sock *sk, struct sk_buff *skb,
1268 return in_sack; 1292 return in_sack;
1269} 1293}
1270 1294
1271static int tcp_sacktag_one(struct sk_buff *skb, struct sock *sk, 1295static u8 tcp_sacktag_one(struct sk_buff *skb, struct sock *sk,
1272 int *reord, int dup_sack, int fack_count) 1296 struct tcp_sacktag_state *state,
1297 int dup_sack, int pcount)
1273{ 1298{
1274 struct tcp_sock *tp = tcp_sk(sk); 1299 struct tcp_sock *tp = tcp_sk(sk);
1275 u8 sacked = TCP_SKB_CB(skb)->sacked; 1300 u8 sacked = TCP_SKB_CB(skb)->sacked;
1276 int flag = 0; 1301 int fack_count = state->fack_count;
1277 1302
1278 /* Account D-SACK for retransmitted packet. */ 1303 /* Account D-SACK for retransmitted packet. */
1279 if (dup_sack && (sacked & TCPCB_RETRANS)) { 1304 if (dup_sack && (sacked & TCPCB_RETRANS)) {
1280 if (after(TCP_SKB_CB(skb)->end_seq, tp->undo_marker)) 1305 if (after(TCP_SKB_CB(skb)->end_seq, tp->undo_marker))
1281 tp->undo_retrans--; 1306 tp->undo_retrans--;
1282 if (sacked & TCPCB_SACKED_ACKED) 1307 if (sacked & TCPCB_SACKED_ACKED)
1283 *reord = min(fack_count, *reord); 1308 state->reord = min(fack_count, state->reord);
1284 } 1309 }
1285 1310
1286 /* Nothing to do; acked frame is about to be dropped (was ACKed). */ 1311 /* Nothing to do; acked frame is about to be dropped (was ACKed). */
1287 if (!after(TCP_SKB_CB(skb)->end_seq, tp->snd_una)) 1312 if (!after(TCP_SKB_CB(skb)->end_seq, tp->snd_una))
1288 return flag; 1313 return sacked;
1289 1314
1290 if (!(sacked & TCPCB_SACKED_ACKED)) { 1315 if (!(sacked & TCPCB_SACKED_ACKED)) {
1291 if (sacked & TCPCB_SACKED_RETRANS) { 1316 if (sacked & TCPCB_SACKED_RETRANS) {
@@ -1294,10 +1319,9 @@ static int tcp_sacktag_one(struct sk_buff *skb, struct sock *sk,
1294 * that retransmission is still in flight. 1319 * that retransmission is still in flight.
1295 */ 1320 */
1296 if (sacked & TCPCB_LOST) { 1321 if (sacked & TCPCB_LOST) {
1297 TCP_SKB_CB(skb)->sacked &= 1322 sacked &= ~(TCPCB_LOST|TCPCB_SACKED_RETRANS);
1298 ~(TCPCB_LOST|TCPCB_SACKED_RETRANS); 1323 tp->lost_out -= pcount;
1299 tp->lost_out -= tcp_skb_pcount(skb); 1324 tp->retrans_out -= pcount;
1300 tp->retrans_out -= tcp_skb_pcount(skb);
1301 } 1325 }
1302 } else { 1326 } else {
1303 if (!(sacked & TCPCB_RETRANS)) { 1327 if (!(sacked & TCPCB_RETRANS)) {
@@ -1306,56 +1330,280 @@ static int tcp_sacktag_one(struct sk_buff *skb, struct sock *sk,
1306 */ 1330 */
1307 if (before(TCP_SKB_CB(skb)->seq, 1331 if (before(TCP_SKB_CB(skb)->seq,
1308 tcp_highest_sack_seq(tp))) 1332 tcp_highest_sack_seq(tp)))
1309 *reord = min(fack_count, *reord); 1333 state->reord = min(fack_count,
1334 state->reord);
1310 1335
1311 /* SACK enhanced F-RTO (RFC4138; Appendix B) */ 1336 /* SACK enhanced F-RTO (RFC4138; Appendix B) */
1312 if (!after(TCP_SKB_CB(skb)->end_seq, tp->frto_highmark)) 1337 if (!after(TCP_SKB_CB(skb)->end_seq, tp->frto_highmark))
1313 flag |= FLAG_ONLY_ORIG_SACKED; 1338 state->flag |= FLAG_ONLY_ORIG_SACKED;
1314 } 1339 }
1315 1340
1316 if (sacked & TCPCB_LOST) { 1341 if (sacked & TCPCB_LOST) {
1317 TCP_SKB_CB(skb)->sacked &= ~TCPCB_LOST; 1342 sacked &= ~TCPCB_LOST;
1318 tp->lost_out -= tcp_skb_pcount(skb); 1343 tp->lost_out -= pcount;
1319 } 1344 }
1320 } 1345 }
1321 1346
1322 TCP_SKB_CB(skb)->sacked |= TCPCB_SACKED_ACKED; 1347 sacked |= TCPCB_SACKED_ACKED;
1323 flag |= FLAG_DATA_SACKED; 1348 state->flag |= FLAG_DATA_SACKED;
1324 tp->sacked_out += tcp_skb_pcount(skb); 1349 tp->sacked_out += pcount;
1325 1350
1326 fack_count += tcp_skb_pcount(skb); 1351 fack_count += pcount;
1327 1352
1328 /* Lost marker hint past SACKed? Tweak RFC3517 cnt */ 1353 /* Lost marker hint past SACKed? Tweak RFC3517 cnt */
1329 if (!tcp_is_fack(tp) && (tp->lost_skb_hint != NULL) && 1354 if (!tcp_is_fack(tp) && (tp->lost_skb_hint != NULL) &&
1330 before(TCP_SKB_CB(skb)->seq, 1355 before(TCP_SKB_CB(skb)->seq,
1331 TCP_SKB_CB(tp->lost_skb_hint)->seq)) 1356 TCP_SKB_CB(tp->lost_skb_hint)->seq))
1332 tp->lost_cnt_hint += tcp_skb_pcount(skb); 1357 tp->lost_cnt_hint += pcount;
1333 1358
1334 if (fack_count > tp->fackets_out) 1359 if (fack_count > tp->fackets_out)
1335 tp->fackets_out = fack_count; 1360 tp->fackets_out = fack_count;
1336
1337 if (!before(TCP_SKB_CB(skb)->seq, tcp_highest_sack_seq(tp)))
1338 tcp_advance_highest_sack(sk, skb);
1339 } 1361 }
1340 1362
1341 /* D-SACK. We can detect redundant retransmission in S|R and plain R 1363 /* D-SACK. We can detect redundant retransmission in S|R and plain R
1342 * frames and clear it. undo_retrans is decreased above, L|R frames 1364 * frames and clear it. undo_retrans is decreased above, L|R frames
1343 * are accounted above as well. 1365 * are accounted above as well.
1344 */ 1366 */
1345 if (dup_sack && (TCP_SKB_CB(skb)->sacked & TCPCB_SACKED_RETRANS)) { 1367 if (dup_sack && (sacked & TCPCB_SACKED_RETRANS)) {
1346 TCP_SKB_CB(skb)->sacked &= ~TCPCB_SACKED_RETRANS; 1368 sacked &= ~TCPCB_SACKED_RETRANS;
1347 tp->retrans_out -= tcp_skb_pcount(skb); 1369 tp->retrans_out -= pcount;
1348 } 1370 }
1349 1371
1350 return flag; 1372 return sacked;
1373}
1374
1375static int tcp_shifted_skb(struct sock *sk, struct sk_buff *skb,
1376 struct tcp_sacktag_state *state,
1377 unsigned int pcount, int shifted, int mss)
1378{
1379 struct tcp_sock *tp = tcp_sk(sk);
1380 struct sk_buff *prev = tcp_write_queue_prev(sk, skb);
1381
1382 BUG_ON(!pcount);
1383
1384 /* Tweak before seqno plays */
1385 if (!tcp_is_fack(tp) && tcp_is_sack(tp) && tp->lost_skb_hint &&
1386 !before(TCP_SKB_CB(tp->lost_skb_hint)->seq, TCP_SKB_CB(skb)->seq))
1387 tp->lost_cnt_hint += pcount;
1388
1389 TCP_SKB_CB(prev)->end_seq += shifted;
1390 TCP_SKB_CB(skb)->seq += shifted;
1391
1392 skb_shinfo(prev)->gso_segs += pcount;
1393 BUG_ON(skb_shinfo(skb)->gso_segs < pcount);
1394 skb_shinfo(skb)->gso_segs -= pcount;
1395
1396 /* When we're adding to gso_segs == 1, gso_size will be zero,
1397 * in theory this shouldn't be necessary but as long as DSACK
1398 * code can come after this skb later on it's better to keep
1399 * setting gso_size to something.
1400 */
1401 if (!skb_shinfo(prev)->gso_size) {
1402 skb_shinfo(prev)->gso_size = mss;
1403 skb_shinfo(prev)->gso_type = sk->sk_gso_type;
1404 }
1405
1406 /* CHECKME: To clear or not to clear? Mimics normal skb currently */
1407 if (skb_shinfo(skb)->gso_segs <= 1) {
1408 skb_shinfo(skb)->gso_size = 0;
1409 skb_shinfo(skb)->gso_type = 0;
1410 }
1411
1412 /* We discard results */
1413 tcp_sacktag_one(skb, sk, state, 0, pcount);
1414
1415 /* Difference in this won't matter, both ACKed by the same cumul. ACK */
1416 TCP_SKB_CB(prev)->sacked |= (TCP_SKB_CB(skb)->sacked & TCPCB_EVER_RETRANS);
1417
1418 if (skb->len > 0) {
1419 BUG_ON(!tcp_skb_pcount(skb));
1420 NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_SACKSHIFTED);
1421 return 0;
1422 }
1423
1424 /* Whole SKB was eaten :-) */
1425
1426 if (skb == tp->retransmit_skb_hint)
1427 tp->retransmit_skb_hint = prev;
1428 if (skb == tp->scoreboard_skb_hint)
1429 tp->scoreboard_skb_hint = prev;
1430 if (skb == tp->lost_skb_hint) {
1431 tp->lost_skb_hint = prev;
1432 tp->lost_cnt_hint -= tcp_skb_pcount(prev);
1433 }
1434
1435 TCP_SKB_CB(skb)->flags |= TCP_SKB_CB(prev)->flags;
1436 if (skb == tcp_highest_sack(sk))
1437 tcp_advance_highest_sack(sk, skb);
1438
1439 tcp_unlink_write_queue(skb, sk);
1440 sk_wmem_free_skb(sk, skb);
1441
1442 NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_SACKMERGED);
1443
1444 return 1;
1445}
1446
1447/* I wish gso_size would have a bit more sane initialization than
1448 * something-or-zero which complicates things
1449 */
1450static int tcp_skb_seglen(struct sk_buff *skb)
1451{
1452 return tcp_skb_pcount(skb) == 1 ? skb->len : tcp_skb_mss(skb);
1453}
1454
1455/* Shifting pages past head area doesn't work */
1456static int skb_can_shift(struct sk_buff *skb)
1457{
1458 return !skb_headlen(skb) && skb_is_nonlinear(skb);
1459}
1460
1461/* Try collapsing SACK blocks spanning across multiple skbs to a single
1462 * skb.
1463 */
1464static struct sk_buff *tcp_shift_skb_data(struct sock *sk, struct sk_buff *skb,
1465 struct tcp_sacktag_state *state,
1466 u32 start_seq, u32 end_seq,
1467 int dup_sack)
1468{
1469 struct tcp_sock *tp = tcp_sk(sk);
1470 struct sk_buff *prev;
1471 int mss;
1472 int pcount = 0;
1473 int len;
1474 int in_sack;
1475
1476 if (!sk_can_gso(sk))
1477 goto fallback;
1478
1479 /* Normally R but no L won't result in plain S */
1480 if (!dup_sack &&
1481 (TCP_SKB_CB(skb)->sacked & (TCPCB_LOST|TCPCB_SACKED_RETRANS)) == TCPCB_SACKED_RETRANS)
1482 goto fallback;
1483 if (!skb_can_shift(skb))
1484 goto fallback;
1485 /* This frame is about to be dropped (was ACKed). */
1486 if (!after(TCP_SKB_CB(skb)->end_seq, tp->snd_una))
1487 goto fallback;
1488
1489 /* Can only happen with delayed DSACK + discard craziness */
1490 if (unlikely(skb == tcp_write_queue_head(sk)))
1491 goto fallback;
1492 prev = tcp_write_queue_prev(sk, skb);
1493
1494 if ((TCP_SKB_CB(prev)->sacked & TCPCB_TAGBITS) != TCPCB_SACKED_ACKED)
1495 goto fallback;
1496
1497 in_sack = !after(start_seq, TCP_SKB_CB(skb)->seq) &&
1498 !before(end_seq, TCP_SKB_CB(skb)->end_seq);
1499
1500 if (in_sack) {
1501 len = skb->len;
1502 pcount = tcp_skb_pcount(skb);
1503 mss = tcp_skb_seglen(skb);
1504
1505 /* TODO: Fix DSACKs to not fragment already SACKed and we can
1506 * drop this restriction as unnecessary
1507 */
1508 if (mss != tcp_skb_seglen(prev))
1509 goto fallback;
1510 } else {
1511 if (!after(TCP_SKB_CB(skb)->end_seq, start_seq))
1512 goto noop;
1513 /* CHECKME: This is non-MSS split case only?, this will
1514 * cause skipped skbs due to advancing loop btw, original
1515 * has that feature too
1516 */
1517 if (tcp_skb_pcount(skb) <= 1)
1518 goto noop;
1519
1520 in_sack = !after(start_seq, TCP_SKB_CB(skb)->seq);
1521 if (!in_sack) {
1522 /* TODO: head merge to next could be attempted here
1523 * if (!after(TCP_SKB_CB(skb)->end_seq, end_seq)),
1524 * though it might not be worth of the additional hassle
1525 *
1526 * ...we can probably just fallback to what was done
1527 * previously. We could try merging non-SACKed ones
1528 * as well but it probably isn't going to buy off
1529 * because later SACKs might again split them, and
1530 * it would make skb timestamp tracking considerably
1531 * harder problem.
1532 */
1533 goto fallback;
1534 }
1535
1536 len = end_seq - TCP_SKB_CB(skb)->seq;
1537 BUG_ON(len < 0);
1538 BUG_ON(len > skb->len);
1539
1540 /* MSS boundaries should be honoured or else pcount will
1541 * severely break even though it makes things bit trickier.
1542 * Optimize common case to avoid most of the divides
1543 */
1544 mss = tcp_skb_mss(skb);
1545
1546 /* TODO: Fix DSACKs to not fragment already SACKed and we can
1547 * drop this restriction as unnecessary
1548 */
1549 if (mss != tcp_skb_seglen(prev))
1550 goto fallback;
1551
1552 if (len == mss) {
1553 pcount = 1;
1554 } else if (len < mss) {
1555 goto noop;
1556 } else {
1557 pcount = len / mss;
1558 len = pcount * mss;
1559 }
1560 }
1561
1562 if (!skb_shift(prev, skb, len))
1563 goto fallback;
1564 if (!tcp_shifted_skb(sk, skb, state, pcount, len, mss))
1565 goto out;
1566
1567 /* Hole filled allows collapsing with the next as well, this is very
1568 * useful when hole on every nth skb pattern happens
1569 */
1570 if (prev == tcp_write_queue_tail(sk))
1571 goto out;
1572 skb = tcp_write_queue_next(sk, prev);
1573
1574 if (!skb_can_shift(skb) ||
1575 (skb == tcp_send_head(sk)) ||
1576 ((TCP_SKB_CB(skb)->sacked & TCPCB_TAGBITS) != TCPCB_SACKED_ACKED) ||
1577 (mss != tcp_skb_seglen(skb)))
1578 goto out;
1579
1580 len = skb->len;
1581 if (skb_shift(prev, skb, len)) {
1582 pcount += tcp_skb_pcount(skb);
1583 tcp_shifted_skb(sk, skb, state, tcp_skb_pcount(skb), len, mss);
1584 }
1585
1586out:
1587 state->fack_count += pcount;
1588 return prev;
1589
1590noop:
1591 return skb;
1592
1593fallback:
1594 NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_SACKSHIFTFALLBACK);
1595 return NULL;
1351} 1596}
1352 1597
1353static struct sk_buff *tcp_sacktag_walk(struct sk_buff *skb, struct sock *sk, 1598static struct sk_buff *tcp_sacktag_walk(struct sk_buff *skb, struct sock *sk,
1354 struct tcp_sack_block *next_dup, 1599 struct tcp_sack_block *next_dup,
1600 struct tcp_sacktag_state *state,
1355 u32 start_seq, u32 end_seq, 1601 u32 start_seq, u32 end_seq,
1356 int dup_sack_in, int *fack_count, 1602 int dup_sack_in)
1357 int *reord, int *flag)
1358{ 1603{
1604 struct tcp_sock *tp = tcp_sk(sk);
1605 struct sk_buff *tmp;
1606
1359 tcp_for_write_queue_from(skb, sk) { 1607 tcp_for_write_queue_from(skb, sk) {
1360 int in_sack = 0; 1608 int in_sack = 0;
1361 int dup_sack = dup_sack_in; 1609 int dup_sack = dup_sack_in;
@@ -1376,17 +1624,42 @@ static struct sk_buff *tcp_sacktag_walk(struct sk_buff *skb, struct sock *sk,
1376 dup_sack = 1; 1624 dup_sack = 1;
1377 } 1625 }
1378 1626
1379 if (in_sack <= 0) 1627 /* skb reference here is a bit tricky to get right, since
1380 in_sack = tcp_match_skb_to_sack(sk, skb, start_seq, 1628 * shifting can eat and free both this skb and the next,
1381 end_seq); 1629 * so not even _safe variant of the loop is enough.
1630 */
1631 if (in_sack <= 0) {
1632 tmp = tcp_shift_skb_data(sk, skb, state,
1633 start_seq, end_seq, dup_sack);
1634 if (tmp != NULL) {
1635 if (tmp != skb) {
1636 skb = tmp;
1637 continue;
1638 }
1639
1640 in_sack = 0;
1641 } else {
1642 in_sack = tcp_match_skb_to_sack(sk, skb,
1643 start_seq,
1644 end_seq);
1645 }
1646 }
1647
1382 if (unlikely(in_sack < 0)) 1648 if (unlikely(in_sack < 0))
1383 break; 1649 break;
1384 1650
1385 if (in_sack) 1651 if (in_sack) {
1386 *flag |= tcp_sacktag_one(skb, sk, reord, dup_sack, 1652 TCP_SKB_CB(skb)->sacked = tcp_sacktag_one(skb, sk,
1387 *fack_count); 1653 state,
1654 dup_sack,
1655 tcp_skb_pcount(skb));
1656
1657 if (!before(TCP_SKB_CB(skb)->seq,
1658 tcp_highest_sack_seq(tp)))
1659 tcp_advance_highest_sack(sk, skb);
1660 }
1388 1661
1389 *fack_count += tcp_skb_pcount(skb); 1662 state->fack_count += tcp_skb_pcount(skb);
1390 } 1663 }
1391 return skb; 1664 return skb;
1392} 1665}
@@ -1395,16 +1668,17 @@ static struct sk_buff *tcp_sacktag_walk(struct sk_buff *skb, struct sock *sk,
1395 * a normal way 1668 * a normal way
1396 */ 1669 */
1397static struct sk_buff *tcp_sacktag_skip(struct sk_buff *skb, struct sock *sk, 1670static struct sk_buff *tcp_sacktag_skip(struct sk_buff *skb, struct sock *sk,
1398 u32 skip_to_seq, int *fack_count) 1671 struct tcp_sacktag_state *state,
1672 u32 skip_to_seq)
1399{ 1673{
1400 tcp_for_write_queue_from(skb, sk) { 1674 tcp_for_write_queue_from(skb, sk) {
1401 if (skb == tcp_send_head(sk)) 1675 if (skb == tcp_send_head(sk))
1402 break; 1676 break;
1403 1677
1404 if (!before(TCP_SKB_CB(skb)->end_seq, skip_to_seq)) 1678 if (after(TCP_SKB_CB(skb)->end_seq, skip_to_seq))
1405 break; 1679 break;
1406 1680
1407 *fack_count += tcp_skb_pcount(skb); 1681 state->fack_count += tcp_skb_pcount(skb);
1408 } 1682 }
1409 return skb; 1683 return skb;
1410} 1684}
@@ -1412,18 +1686,17 @@ static struct sk_buff *tcp_sacktag_skip(struct sk_buff *skb, struct sock *sk,
1412static struct sk_buff *tcp_maybe_skipping_dsack(struct sk_buff *skb, 1686static struct sk_buff *tcp_maybe_skipping_dsack(struct sk_buff *skb,
1413 struct sock *sk, 1687 struct sock *sk,
1414 struct tcp_sack_block *next_dup, 1688 struct tcp_sack_block *next_dup,
1415 u32 skip_to_seq, 1689 struct tcp_sacktag_state *state,
1416 int *fack_count, int *reord, 1690 u32 skip_to_seq)
1417 int *flag)
1418{ 1691{
1419 if (next_dup == NULL) 1692 if (next_dup == NULL)
1420 return skb; 1693 return skb;
1421 1694
1422 if (before(next_dup->start_seq, skip_to_seq)) { 1695 if (before(next_dup->start_seq, skip_to_seq)) {
1423 skb = tcp_sacktag_skip(skb, sk, next_dup->start_seq, fack_count); 1696 skb = tcp_sacktag_skip(skb, sk, state, next_dup->start_seq);
1424 skb = tcp_sacktag_walk(skb, sk, NULL, 1697 skb = tcp_sacktag_walk(skb, sk, NULL, state,
1425 next_dup->start_seq, next_dup->end_seq, 1698 next_dup->start_seq, next_dup->end_seq,
1426 1, fack_count, reord, flag); 1699 1);
1427 } 1700 }
1428 1701
1429 return skb; 1702 return skb;
@@ -1445,16 +1718,17 @@ tcp_sacktag_write_queue(struct sock *sk, struct sk_buff *ack_skb,
1445 struct tcp_sack_block_wire *sp_wire = (struct tcp_sack_block_wire *)(ptr+2); 1718 struct tcp_sack_block_wire *sp_wire = (struct tcp_sack_block_wire *)(ptr+2);
1446 struct tcp_sack_block sp[TCP_NUM_SACKS]; 1719 struct tcp_sack_block sp[TCP_NUM_SACKS];
1447 struct tcp_sack_block *cache; 1720 struct tcp_sack_block *cache;
1721 struct tcp_sacktag_state state;
1448 struct sk_buff *skb; 1722 struct sk_buff *skb;
1449 int num_sacks = min(TCP_NUM_SACKS, (ptr[1] - TCPOLEN_SACK_BASE) >> 3); 1723 int num_sacks = min(TCP_NUM_SACKS, (ptr[1] - TCPOLEN_SACK_BASE) >> 3);
1450 int used_sacks; 1724 int used_sacks;
1451 int reord = tp->packets_out;
1452 int flag = 0;
1453 int found_dup_sack = 0; 1725 int found_dup_sack = 0;
1454 int fack_count;
1455 int i, j; 1726 int i, j;
1456 int first_sack_index; 1727 int first_sack_index;
1457 1728
1729 state.flag = 0;
1730 state.reord = tp->packets_out;
1731
1458 if (!tp->sacked_out) { 1732 if (!tp->sacked_out) {
1459 if (WARN_ON(tp->fackets_out)) 1733 if (WARN_ON(tp->fackets_out))
1460 tp->fackets_out = 0; 1734 tp->fackets_out = 0;
@@ -1464,7 +1738,7 @@ tcp_sacktag_write_queue(struct sock *sk, struct sk_buff *ack_skb,
1464 found_dup_sack = tcp_check_dsack(sk, ack_skb, sp_wire, 1738 found_dup_sack = tcp_check_dsack(sk, ack_skb, sp_wire,
1465 num_sacks, prior_snd_una); 1739 num_sacks, prior_snd_una);
1466 if (found_dup_sack) 1740 if (found_dup_sack)
1467 flag |= FLAG_DSACKING_ACK; 1741 state.flag |= FLAG_DSACKING_ACK;
1468 1742
1469 /* Eliminate too old ACKs, but take into 1743 /* Eliminate too old ACKs, but take into
1470 * account more or less fresh ones, they can 1744 * account more or less fresh ones, they can
@@ -1533,7 +1807,7 @@ tcp_sacktag_write_queue(struct sock *sk, struct sk_buff *ack_skb,
1533 } 1807 }
1534 1808
1535 skb = tcp_write_queue_head(sk); 1809 skb = tcp_write_queue_head(sk);
1536 fack_count = 0; 1810 state.fack_count = 0;
1537 i = 0; 1811 i = 0;
1538 1812
1539 if (!tp->sacked_out) { 1813 if (!tp->sacked_out) {
@@ -1558,7 +1832,7 @@ tcp_sacktag_write_queue(struct sock *sk, struct sk_buff *ack_skb,
1558 1832
1559 /* Event "B" in the comment above. */ 1833 /* Event "B" in the comment above. */
1560 if (after(end_seq, tp->high_seq)) 1834 if (after(end_seq, tp->high_seq))
1561 flag |= FLAG_DATA_LOST; 1835 state.flag |= FLAG_DATA_LOST;
1562 1836
1563 /* Skip too early cached blocks */ 1837 /* Skip too early cached blocks */
1564 while (tcp_sack_cache_ok(tp, cache) && 1838 while (tcp_sack_cache_ok(tp, cache) &&
@@ -1571,13 +1845,13 @@ tcp_sacktag_write_queue(struct sock *sk, struct sk_buff *ack_skb,
1571 1845
1572 /* Head todo? */ 1846 /* Head todo? */
1573 if (before(start_seq, cache->start_seq)) { 1847 if (before(start_seq, cache->start_seq)) {
1574 skb = tcp_sacktag_skip(skb, sk, start_seq, 1848 skb = tcp_sacktag_skip(skb, sk, &state,
1575 &fack_count); 1849 start_seq);
1576 skb = tcp_sacktag_walk(skb, sk, next_dup, 1850 skb = tcp_sacktag_walk(skb, sk, next_dup,
1851 &state,
1577 start_seq, 1852 start_seq,
1578 cache->start_seq, 1853 cache->start_seq,
1579 dup_sack, &fack_count, 1854 dup_sack);
1580 &reord, &flag);
1581 } 1855 }
1582 1856
1583 /* Rest of the block already fully processed? */ 1857 /* Rest of the block already fully processed? */
@@ -1585,9 +1859,8 @@ tcp_sacktag_write_queue(struct sock *sk, struct sk_buff *ack_skb,
1585 goto advance_sp; 1859 goto advance_sp;
1586 1860
1587 skb = tcp_maybe_skipping_dsack(skb, sk, next_dup, 1861 skb = tcp_maybe_skipping_dsack(skb, sk, next_dup,
1588 cache->end_seq, 1862 &state,
1589 &fack_count, &reord, 1863 cache->end_seq);
1590 &flag);
1591 1864
1592 /* ...tail remains todo... */ 1865 /* ...tail remains todo... */
1593 if (tcp_highest_sack_seq(tp) == cache->end_seq) { 1866 if (tcp_highest_sack_seq(tp) == cache->end_seq) {
@@ -1595,13 +1868,12 @@ tcp_sacktag_write_queue(struct sock *sk, struct sk_buff *ack_skb,
1595 skb = tcp_highest_sack(sk); 1868 skb = tcp_highest_sack(sk);
1596 if (skb == NULL) 1869 if (skb == NULL)
1597 break; 1870 break;
1598 fack_count = tp->fackets_out; 1871 state.fack_count = tp->fackets_out;
1599 cache++; 1872 cache++;
1600 goto walk; 1873 goto walk;
1601 } 1874 }
1602 1875
1603 skb = tcp_sacktag_skip(skb, sk, cache->end_seq, 1876 skb = tcp_sacktag_skip(skb, sk, &state, cache->end_seq);
1604 &fack_count);
1605 /* Check overlap against next cached too (past this one already) */ 1877 /* Check overlap against next cached too (past this one already) */
1606 cache++; 1878 cache++;
1607 continue; 1879 continue;
@@ -1611,20 +1883,20 @@ tcp_sacktag_write_queue(struct sock *sk, struct sk_buff *ack_skb,
1611 skb = tcp_highest_sack(sk); 1883 skb = tcp_highest_sack(sk);
1612 if (skb == NULL) 1884 if (skb == NULL)
1613 break; 1885 break;
1614 fack_count = tp->fackets_out; 1886 state.fack_count = tp->fackets_out;
1615 } 1887 }
1616 skb = tcp_sacktag_skip(skb, sk, start_seq, &fack_count); 1888 skb = tcp_sacktag_skip(skb, sk, &state, start_seq);
1617 1889
1618walk: 1890walk:
1619 skb = tcp_sacktag_walk(skb, sk, next_dup, start_seq, end_seq, 1891 skb = tcp_sacktag_walk(skb, sk, next_dup, &state,
1620 dup_sack, &fack_count, &reord, &flag); 1892 start_seq, end_seq, dup_sack);
1621 1893
1622advance_sp: 1894advance_sp:
1623 /* SACK enhanced FRTO (RFC4138, Appendix B): Clearing correct 1895 /* SACK enhanced FRTO (RFC4138, Appendix B): Clearing correct
1624 * due to in-order walk 1896 * due to in-order walk
1625 */ 1897 */
1626 if (after(end_seq, tp->frto_highmark)) 1898 if (after(end_seq, tp->frto_highmark))
1627 flag &= ~FLAG_ONLY_ORIG_SACKED; 1899 state.flag &= ~FLAG_ONLY_ORIG_SACKED;
1628 1900
1629 i++; 1901 i++;
1630 } 1902 }
@@ -1641,10 +1913,10 @@ advance_sp:
1641 1913
1642 tcp_verify_left_out(tp); 1914 tcp_verify_left_out(tp);
1643 1915
1644 if ((reord < tp->fackets_out) && 1916 if ((state.reord < tp->fackets_out) &&
1645 ((icsk->icsk_ca_state != TCP_CA_Loss) || tp->undo_marker) && 1917 ((icsk->icsk_ca_state != TCP_CA_Loss) || tp->undo_marker) &&
1646 (!tp->frto_highmark || after(tp->snd_una, tp->frto_highmark))) 1918 (!tp->frto_highmark || after(tp->snd_una, tp->frto_highmark)))
1647 tcp_update_reordering(sk, tp->fackets_out - reord, 0); 1919 tcp_update_reordering(sk, tp->fackets_out - state.reord, 0);
1648 1920
1649out: 1921out:
1650 1922
@@ -1654,13 +1926,13 @@ out:
1654 WARN_ON((int)tp->retrans_out < 0); 1926 WARN_ON((int)tp->retrans_out < 0);
1655 WARN_ON((int)tcp_packets_in_flight(tp) < 0); 1927 WARN_ON((int)tcp_packets_in_flight(tp) < 0);
1656#endif 1928#endif
1657 return flag; 1929 return state.flag;
1658} 1930}
1659 1931
1660/* Limits sacked_out so that sum with lost_out isn't ever larger than 1932/* Limits sacked_out so that sum with lost_out isn't ever larger than
1661 * packets_out. Returns zero if sacked_out adjustement wasn't necessary. 1933 * packets_out. Returns zero if sacked_out adjustement wasn't necessary.
1662 */ 1934 */
1663int tcp_limit_reno_sacked(struct tcp_sock *tp) 1935static int tcp_limit_reno_sacked(struct tcp_sock *tp)
1664{ 1936{
1665 u32 holes; 1937 u32 holes;
1666 1938
@@ -2336,9 +2608,9 @@ static void DBGUNDO(struct sock *sk, const char *msg)
2336 struct inet_sock *inet = inet_sk(sk); 2608 struct inet_sock *inet = inet_sk(sk);
2337 2609
2338 if (sk->sk_family == AF_INET) { 2610 if (sk->sk_family == AF_INET) {
2339 printk(KERN_DEBUG "Undo %s " NIPQUAD_FMT "/%u c%u l%u ss%u/%u p%u\n", 2611 printk(KERN_DEBUG "Undo %s %pI4/%u c%u l%u ss%u/%u p%u\n",
2340 msg, 2612 msg,
2341 NIPQUAD(inet->daddr), ntohs(inet->dport), 2613 &inet->daddr, ntohs(inet->dport),
2342 tp->snd_cwnd, tcp_left_out(tp), 2614 tp->snd_cwnd, tcp_left_out(tp),
2343 tp->snd_ssthresh, tp->prior_ssthresh, 2615 tp->snd_ssthresh, tp->prior_ssthresh,
2344 tp->packets_out); 2616 tp->packets_out);
@@ -2346,9 +2618,9 @@ static void DBGUNDO(struct sock *sk, const char *msg)
2346#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) 2618#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
2347 else if (sk->sk_family == AF_INET6) { 2619 else if (sk->sk_family == AF_INET6) {
2348 struct ipv6_pinfo *np = inet6_sk(sk); 2620 struct ipv6_pinfo *np = inet6_sk(sk);
2349 printk(KERN_DEBUG "Undo %s " NIP6_FMT "/%u c%u l%u ss%u/%u p%u\n", 2621 printk(KERN_DEBUG "Undo %s %pI6/%u c%u l%u ss%u/%u p%u\n",
2350 msg, 2622 msg,
2351 NIP6(np->daddr), ntohs(inet->dport), 2623 &np->daddr, ntohs(inet->dport),
2352 tp->snd_cwnd, tcp_left_out(tp), 2624 tp->snd_cwnd, tcp_left_out(tp),
2353 tp->snd_ssthresh, tp->prior_ssthresh, 2625 tp->snd_ssthresh, tp->prior_ssthresh,
2354 tp->packets_out); 2626 tp->packets_out);
@@ -2559,6 +2831,56 @@ static void tcp_mtup_probe_success(struct sock *sk, struct sk_buff *skb)
2559 tcp_sync_mss(sk, icsk->icsk_pmtu_cookie); 2831 tcp_sync_mss(sk, icsk->icsk_pmtu_cookie);
2560} 2832}
2561 2833
2834/* Do a simple retransmit without using the backoff mechanisms in
2835 * tcp_timer. This is used for path mtu discovery.
2836 * The socket is already locked here.
2837 */
2838void tcp_simple_retransmit(struct sock *sk)
2839{
2840 const struct inet_connection_sock *icsk = inet_csk(sk);
2841 struct tcp_sock *tp = tcp_sk(sk);
2842 struct sk_buff *skb;
2843 unsigned int mss = tcp_current_mss(sk, 0);
2844 u32 prior_lost = tp->lost_out;
2845
2846 tcp_for_write_queue(skb, sk) {
2847 if (skb == tcp_send_head(sk))
2848 break;
2849 if (tcp_skb_seglen(skb) > mss &&
2850 !(TCP_SKB_CB(skb)->sacked & TCPCB_SACKED_ACKED)) {
2851 if (TCP_SKB_CB(skb)->sacked & TCPCB_SACKED_RETRANS) {
2852 TCP_SKB_CB(skb)->sacked &= ~TCPCB_SACKED_RETRANS;
2853 tp->retrans_out -= tcp_skb_pcount(skb);
2854 }
2855 tcp_skb_mark_lost_uncond_verify(tp, skb);
2856 }
2857 }
2858
2859 tcp_clear_retrans_hints_partial(tp);
2860
2861 if (prior_lost == tp->lost_out)
2862 return;
2863
2864 if (tcp_is_reno(tp))
2865 tcp_limit_reno_sacked(tp);
2866
2867 tcp_verify_left_out(tp);
2868
2869 /* Don't muck with the congestion window here.
2870 * Reason is that we do not increase amount of _data_
2871 * in network, but units changed and effective
2872 * cwnd/ssthresh really reduced now.
2873 */
2874 if (icsk->icsk_ca_state != TCP_CA_Loss) {
2875 tp->high_seq = tp->snd_nxt;
2876 tp->snd_ssthresh = tcp_current_ssthresh(sk);
2877 tp->prior_ssthresh = 0;
2878 tp->undo_marker = 0;
2879 tcp_set_ca_state(sk, TCP_CA_Loss);
2880 }
2881 tcp_xmit_retransmit_queue(sk);
2882}
2883
2562/* Process an event, which can update packets-in-flight not trivially. 2884/* Process an event, which can update packets-in-flight not trivially.
2563 * Main goal of this function is to calculate new estimate for left_out, 2885 * Main goal of this function is to calculate new estimate for left_out,
2564 * taking into account both packets sitting in receiver's buffer and 2886 * taking into account both packets sitting in receiver's buffer and
@@ -2730,6 +3052,13 @@ static void tcp_fastretrans_alert(struct sock *sk, int pkts_acked, int flag)
2730 tcp_xmit_retransmit_queue(sk); 3052 tcp_xmit_retransmit_queue(sk);
2731} 3053}
2732 3054
3055static void tcp_valid_rtt_meas(struct sock *sk, u32 seq_rtt)
3056{
3057 tcp_rtt_estimator(sk, seq_rtt);
3058 tcp_set_rto(sk);
3059 inet_csk(sk)->icsk_backoff = 0;
3060}
3061
2733/* Read draft-ietf-tcplw-high-performance before mucking 3062/* Read draft-ietf-tcplw-high-performance before mucking
2734 * with this code. (Supersedes RFC1323) 3063 * with this code. (Supersedes RFC1323)
2735 */ 3064 */
@@ -2751,11 +3080,8 @@ static void tcp_ack_saw_tstamp(struct sock *sk, int flag)
2751 * in window is lost... Voila. --ANK (010210) 3080 * in window is lost... Voila. --ANK (010210)
2752 */ 3081 */
2753 struct tcp_sock *tp = tcp_sk(sk); 3082 struct tcp_sock *tp = tcp_sk(sk);
2754 const __u32 seq_rtt = tcp_time_stamp - tp->rx_opt.rcv_tsecr; 3083
2755 tcp_rtt_estimator(sk, seq_rtt); 3084 tcp_valid_rtt_meas(sk, tcp_time_stamp - tp->rx_opt.rcv_tsecr);
2756 tcp_set_rto(sk);
2757 inet_csk(sk)->icsk_backoff = 0;
2758 tcp_bound_rto(sk);
2759} 3085}
2760 3086
2761static void tcp_ack_no_tstamp(struct sock *sk, u32 seq_rtt, int flag) 3087static void tcp_ack_no_tstamp(struct sock *sk, u32 seq_rtt, int flag)
@@ -2772,10 +3098,7 @@ static void tcp_ack_no_tstamp(struct sock *sk, u32 seq_rtt, int flag)
2772 if (flag & FLAG_RETRANS_DATA_ACKED) 3098 if (flag & FLAG_RETRANS_DATA_ACKED)
2773 return; 3099 return;
2774 3100
2775 tcp_rtt_estimator(sk, seq_rtt); 3101 tcp_valid_rtt_meas(sk, seq_rtt);
2776 tcp_set_rto(sk);
2777 inet_csk(sk)->icsk_backoff = 0;
2778 tcp_bound_rto(sk);
2779} 3102}
2780 3103
2781static inline void tcp_ack_update_rtt(struct sock *sk, const int flag, 3104static inline void tcp_ack_update_rtt(struct sock *sk, const int flag,
diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
index 5c8fa7f1e327..10172487921b 100644
--- a/net/ipv4/tcp_ipv4.c
+++ b/net/ipv4/tcp_ipv4.c
@@ -97,11 +97,7 @@ struct tcp_md5sig_key *tcp_v4_md5_do_lookup(struct sock *sk, __be32 addr)
97} 97}
98#endif 98#endif
99 99
100struct inet_hashinfo __cacheline_aligned tcp_hashinfo = { 100struct inet_hashinfo tcp_hashinfo;
101 .lhash_lock = __RW_LOCK_UNLOCKED(tcp_hashinfo.lhash_lock),
102 .lhash_users = ATOMIC_INIT(0),
103 .lhash_wait = __WAIT_QUEUE_HEAD_INITIALIZER(tcp_hashinfo.lhash_wait),
104};
105 101
106static inline __u32 tcp_v4_init_sequence(struct sk_buff *skb) 102static inline __u32 tcp_v4_init_sequence(struct sk_buff *skb)
107{ 103{
@@ -492,7 +488,7 @@ void tcp_v4_send_check(struct sock *sk, int len, struct sk_buff *skb)
492 skb->csum_offset = offsetof(struct tcphdr, check); 488 skb->csum_offset = offsetof(struct tcphdr, check);
493 } else { 489 } else {
494 th->check = tcp_v4_check(len, inet->saddr, inet->daddr, 490 th->check = tcp_v4_check(len, inet->saddr, inet->daddr,
495 csum_partial((char *)th, 491 csum_partial(th,
496 th->doff << 2, 492 th->doff << 2,
497 skb->csum)); 493 skb->csum));
498 } 494 }
@@ -726,7 +722,7 @@ static int __tcp_v4_send_synack(struct sock *sk, struct request_sock *req,
726 th->check = tcp_v4_check(skb->len, 722 th->check = tcp_v4_check(skb->len,
727 ireq->loc_addr, 723 ireq->loc_addr,
728 ireq->rmt_addr, 724 ireq->rmt_addr,
729 csum_partial((char *)th, skb->len, 725 csum_partial(th, skb->len,
730 skb->csum)); 726 skb->csum));
731 727
732 err = ip_build_and_send_pkt(skb, sk, ireq->loc_addr, 728 err = ip_build_and_send_pkt(skb, sk, ireq->loc_addr,
@@ -1139,10 +1135,9 @@ static int tcp_v4_inbound_md5_hash(struct sock *sk, struct sk_buff *skb)
1139 1135
1140 if (genhash || memcmp(hash_location, newhash, 16) != 0) { 1136 if (genhash || memcmp(hash_location, newhash, 16) != 0) {
1141 if (net_ratelimit()) { 1137 if (net_ratelimit()) {
1142 printk(KERN_INFO "MD5 Hash failed for " 1138 printk(KERN_INFO "MD5 Hash failed for (%pI4, %d)->(%pI4, %d)%s\n",
1143 "(" NIPQUAD_FMT ", %d)->(" NIPQUAD_FMT ", %d)%s\n", 1139 &iph->saddr, ntohs(th->source),
1144 NIPQUAD(iph->saddr), ntohs(th->source), 1140 &iph->daddr, ntohs(th->dest),
1145 NIPQUAD(iph->daddr), ntohs(th->dest),
1146 genhash ? " tcp_v4_calc_md5_hash failed" : ""); 1141 genhash ? " tcp_v4_calc_md5_hash failed" : "");
1147 } 1142 }
1148 return 1; 1143 return 1;
@@ -1297,10 +1292,8 @@ int tcp_v4_conn_request(struct sock *sk, struct sk_buff *skb)
1297 * to destinations, already remembered 1292 * to destinations, already remembered
1298 * to the moment of synflood. 1293 * to the moment of synflood.
1299 */ 1294 */
1300 LIMIT_NETDEBUG(KERN_DEBUG "TCP: drop open " 1295 LIMIT_NETDEBUG(KERN_DEBUG "TCP: drop open request from %pI4/%u\n",
1301 "request from " NIPQUAD_FMT "/%u\n", 1296 &saddr, ntohs(tcp_hdr(skb)->source));
1302 NIPQUAD(saddr),
1303 ntohs(tcp_hdr(skb)->source));
1304 goto drop_and_release; 1297 goto drop_and_release;
1305 } 1298 }
1306 1299
@@ -1804,7 +1797,7 @@ static int tcp_v4_init_sock(struct sock *sk)
1804 sk->sk_sndbuf = sysctl_tcp_wmem[1]; 1797 sk->sk_sndbuf = sysctl_tcp_wmem[1];
1805 sk->sk_rcvbuf = sysctl_tcp_rmem[1]; 1798 sk->sk_rcvbuf = sysctl_tcp_rmem[1];
1806 1799
1807 atomic_inc(&tcp_sockets_allocated); 1800 percpu_counter_inc(&tcp_sockets_allocated);
1808 1801
1809 return 0; 1802 return 0;
1810} 1803}
@@ -1852,7 +1845,7 @@ void tcp_v4_destroy_sock(struct sock *sk)
1852 sk->sk_sndmsg_page = NULL; 1845 sk->sk_sndmsg_page = NULL;
1853 } 1846 }
1854 1847
1855 atomic_dec(&tcp_sockets_allocated); 1848 percpu_counter_dec(&tcp_sockets_allocated);
1856} 1849}
1857 1850
1858EXPORT_SYMBOL(tcp_v4_destroy_sock); 1851EXPORT_SYMBOL(tcp_v4_destroy_sock);
@@ -1860,32 +1853,35 @@ EXPORT_SYMBOL(tcp_v4_destroy_sock);
1860#ifdef CONFIG_PROC_FS 1853#ifdef CONFIG_PROC_FS
1861/* Proc filesystem TCP sock list dumping. */ 1854/* Proc filesystem TCP sock list dumping. */
1862 1855
1863static inline struct inet_timewait_sock *tw_head(struct hlist_head *head) 1856static inline struct inet_timewait_sock *tw_head(struct hlist_nulls_head *head)
1864{ 1857{
1865 return hlist_empty(head) ? NULL : 1858 return hlist_nulls_empty(head) ? NULL :
1866 list_entry(head->first, struct inet_timewait_sock, tw_node); 1859 list_entry(head->first, struct inet_timewait_sock, tw_node);
1867} 1860}
1868 1861
1869static inline struct inet_timewait_sock *tw_next(struct inet_timewait_sock *tw) 1862static inline struct inet_timewait_sock *tw_next(struct inet_timewait_sock *tw)
1870{ 1863{
1871 return tw->tw_node.next ? 1864 return !is_a_nulls(tw->tw_node.next) ?
1872 hlist_entry(tw->tw_node.next, typeof(*tw), tw_node) : NULL; 1865 hlist_nulls_entry(tw->tw_node.next, typeof(*tw), tw_node) : NULL;
1873} 1866}
1874 1867
1875static void *listening_get_next(struct seq_file *seq, void *cur) 1868static void *listening_get_next(struct seq_file *seq, void *cur)
1876{ 1869{
1877 struct inet_connection_sock *icsk; 1870 struct inet_connection_sock *icsk;
1878 struct hlist_node *node; 1871 struct hlist_nulls_node *node;
1879 struct sock *sk = cur; 1872 struct sock *sk = cur;
1880 struct tcp_iter_state* st = seq->private; 1873 struct inet_listen_hashbucket *ilb;
1874 struct tcp_iter_state *st = seq->private;
1881 struct net *net = seq_file_net(seq); 1875 struct net *net = seq_file_net(seq);
1882 1876
1883 if (!sk) { 1877 if (!sk) {
1884 st->bucket = 0; 1878 st->bucket = 0;
1885 sk = sk_head(&tcp_hashinfo.listening_hash[0]); 1879 ilb = &tcp_hashinfo.listening_hash[0];
1880 spin_lock_bh(&ilb->lock);
1881 sk = sk_nulls_head(&ilb->head);
1886 goto get_sk; 1882 goto get_sk;
1887 } 1883 }
1888 1884 ilb = &tcp_hashinfo.listening_hash[st->bucket];
1889 ++st->num; 1885 ++st->num;
1890 1886
1891 if (st->state == TCP_SEQ_STATE_OPENREQ) { 1887 if (st->state == TCP_SEQ_STATE_OPENREQ) {
@@ -1918,7 +1914,7 @@ get_req:
1918 sk = sk_next(sk); 1914 sk = sk_next(sk);
1919 } 1915 }
1920get_sk: 1916get_sk:
1921 sk_for_each_from(sk, node) { 1917 sk_nulls_for_each_from(sk, node) {
1922 if (sk->sk_family == st->family && net_eq(sock_net(sk), net)) { 1918 if (sk->sk_family == st->family && net_eq(sock_net(sk), net)) {
1923 cur = sk; 1919 cur = sk;
1924 goto out; 1920 goto out;
@@ -1935,8 +1931,11 @@ start_req:
1935 } 1931 }
1936 read_unlock_bh(&icsk->icsk_accept_queue.syn_wait_lock); 1932 read_unlock_bh(&icsk->icsk_accept_queue.syn_wait_lock);
1937 } 1933 }
1934 spin_unlock_bh(&ilb->lock);
1938 if (++st->bucket < INET_LHTABLE_SIZE) { 1935 if (++st->bucket < INET_LHTABLE_SIZE) {
1939 sk = sk_head(&tcp_hashinfo.listening_hash[st->bucket]); 1936 ilb = &tcp_hashinfo.listening_hash[st->bucket];
1937 spin_lock_bh(&ilb->lock);
1938 sk = sk_nulls_head(&ilb->head);
1940 goto get_sk; 1939 goto get_sk;
1941 } 1940 }
1942 cur = NULL; 1941 cur = NULL;
@@ -1957,28 +1956,28 @@ static void *listening_get_idx(struct seq_file *seq, loff_t *pos)
1957 1956
1958static inline int empty_bucket(struct tcp_iter_state *st) 1957static inline int empty_bucket(struct tcp_iter_state *st)
1959{ 1958{
1960 return hlist_empty(&tcp_hashinfo.ehash[st->bucket].chain) && 1959 return hlist_nulls_empty(&tcp_hashinfo.ehash[st->bucket].chain) &&
1961 hlist_empty(&tcp_hashinfo.ehash[st->bucket].twchain); 1960 hlist_nulls_empty(&tcp_hashinfo.ehash[st->bucket].twchain);
1962} 1961}
1963 1962
1964static void *established_get_first(struct seq_file *seq) 1963static void *established_get_first(struct seq_file *seq)
1965{ 1964{
1966 struct tcp_iter_state* st = seq->private; 1965 struct tcp_iter_state *st = seq->private;
1967 struct net *net = seq_file_net(seq); 1966 struct net *net = seq_file_net(seq);
1968 void *rc = NULL; 1967 void *rc = NULL;
1969 1968
1970 for (st->bucket = 0; st->bucket < tcp_hashinfo.ehash_size; ++st->bucket) { 1969 for (st->bucket = 0; st->bucket < tcp_hashinfo.ehash_size; ++st->bucket) {
1971 struct sock *sk; 1970 struct sock *sk;
1972 struct hlist_node *node; 1971 struct hlist_nulls_node *node;
1973 struct inet_timewait_sock *tw; 1972 struct inet_timewait_sock *tw;
1974 rwlock_t *lock = inet_ehash_lockp(&tcp_hashinfo, st->bucket); 1973 spinlock_t *lock = inet_ehash_lockp(&tcp_hashinfo, st->bucket);
1975 1974
1976 /* Lockless fast path for the common case of empty buckets */ 1975 /* Lockless fast path for the common case of empty buckets */
1977 if (empty_bucket(st)) 1976 if (empty_bucket(st))
1978 continue; 1977 continue;
1979 1978
1980 read_lock_bh(lock); 1979 spin_lock_bh(lock);
1981 sk_for_each(sk, node, &tcp_hashinfo.ehash[st->bucket].chain) { 1980 sk_nulls_for_each(sk, node, &tcp_hashinfo.ehash[st->bucket].chain) {
1982 if (sk->sk_family != st->family || 1981 if (sk->sk_family != st->family ||
1983 !net_eq(sock_net(sk), net)) { 1982 !net_eq(sock_net(sk), net)) {
1984 continue; 1983 continue;
@@ -1996,7 +1995,7 @@ static void *established_get_first(struct seq_file *seq)
1996 rc = tw; 1995 rc = tw;
1997 goto out; 1996 goto out;
1998 } 1997 }
1999 read_unlock_bh(lock); 1998 spin_unlock_bh(lock);
2000 st->state = TCP_SEQ_STATE_ESTABLISHED; 1999 st->state = TCP_SEQ_STATE_ESTABLISHED;
2001 } 2000 }
2002out: 2001out:
@@ -2007,8 +2006,8 @@ static void *established_get_next(struct seq_file *seq, void *cur)
2007{ 2006{
2008 struct sock *sk = cur; 2007 struct sock *sk = cur;
2009 struct inet_timewait_sock *tw; 2008 struct inet_timewait_sock *tw;
2010 struct hlist_node *node; 2009 struct hlist_nulls_node *node;
2011 struct tcp_iter_state* st = seq->private; 2010 struct tcp_iter_state *st = seq->private;
2012 struct net *net = seq_file_net(seq); 2011 struct net *net = seq_file_net(seq);
2013 2012
2014 ++st->num; 2013 ++st->num;
@@ -2024,7 +2023,7 @@ get_tw:
2024 cur = tw; 2023 cur = tw;
2025 goto out; 2024 goto out;
2026 } 2025 }
2027 read_unlock_bh(inet_ehash_lockp(&tcp_hashinfo, st->bucket)); 2026 spin_unlock_bh(inet_ehash_lockp(&tcp_hashinfo, st->bucket));
2028 st->state = TCP_SEQ_STATE_ESTABLISHED; 2027 st->state = TCP_SEQ_STATE_ESTABLISHED;
2029 2028
2030 /* Look for next non empty bucket */ 2029 /* Look for next non empty bucket */
@@ -2034,12 +2033,12 @@ get_tw:
2034 if (st->bucket >= tcp_hashinfo.ehash_size) 2033 if (st->bucket >= tcp_hashinfo.ehash_size)
2035 return NULL; 2034 return NULL;
2036 2035
2037 read_lock_bh(inet_ehash_lockp(&tcp_hashinfo, st->bucket)); 2036 spin_lock_bh(inet_ehash_lockp(&tcp_hashinfo, st->bucket));
2038 sk = sk_head(&tcp_hashinfo.ehash[st->bucket].chain); 2037 sk = sk_nulls_head(&tcp_hashinfo.ehash[st->bucket].chain);
2039 } else 2038 } else
2040 sk = sk_next(sk); 2039 sk = sk_nulls_next(sk);
2041 2040
2042 sk_for_each_from(sk, node) { 2041 sk_nulls_for_each_from(sk, node) {
2043 if (sk->sk_family == st->family && net_eq(sock_net(sk), net)) 2042 if (sk->sk_family == st->family && net_eq(sock_net(sk), net))
2044 goto found; 2043 goto found;
2045 } 2044 }
@@ -2067,14 +2066,12 @@ static void *established_get_idx(struct seq_file *seq, loff_t pos)
2067static void *tcp_get_idx(struct seq_file *seq, loff_t pos) 2066static void *tcp_get_idx(struct seq_file *seq, loff_t pos)
2068{ 2067{
2069 void *rc; 2068 void *rc;
2070 struct tcp_iter_state* st = seq->private; 2069 struct tcp_iter_state *st = seq->private;
2071 2070
2072 inet_listen_lock(&tcp_hashinfo);
2073 st->state = TCP_SEQ_STATE_LISTENING; 2071 st->state = TCP_SEQ_STATE_LISTENING;
2074 rc = listening_get_idx(seq, &pos); 2072 rc = listening_get_idx(seq, &pos);
2075 2073
2076 if (!rc) { 2074 if (!rc) {
2077 inet_listen_unlock(&tcp_hashinfo);
2078 st->state = TCP_SEQ_STATE_ESTABLISHED; 2075 st->state = TCP_SEQ_STATE_ESTABLISHED;
2079 rc = established_get_idx(seq, pos); 2076 rc = established_get_idx(seq, pos);
2080 } 2077 }
@@ -2084,7 +2081,7 @@ static void *tcp_get_idx(struct seq_file *seq, loff_t pos)
2084 2081
2085static void *tcp_seq_start(struct seq_file *seq, loff_t *pos) 2082static void *tcp_seq_start(struct seq_file *seq, loff_t *pos)
2086{ 2083{
2087 struct tcp_iter_state* st = seq->private; 2084 struct tcp_iter_state *st = seq->private;
2088 st->state = TCP_SEQ_STATE_LISTENING; 2085 st->state = TCP_SEQ_STATE_LISTENING;
2089 st->num = 0; 2086 st->num = 0;
2090 return *pos ? tcp_get_idx(seq, *pos - 1) : SEQ_START_TOKEN; 2087 return *pos ? tcp_get_idx(seq, *pos - 1) : SEQ_START_TOKEN;
@@ -2093,7 +2090,7 @@ static void *tcp_seq_start(struct seq_file *seq, loff_t *pos)
2093static void *tcp_seq_next(struct seq_file *seq, void *v, loff_t *pos) 2090static void *tcp_seq_next(struct seq_file *seq, void *v, loff_t *pos)
2094{ 2091{
2095 void *rc = NULL; 2092 void *rc = NULL;
2096 struct tcp_iter_state* st; 2093 struct tcp_iter_state *st;
2097 2094
2098 if (v == SEQ_START_TOKEN) { 2095 if (v == SEQ_START_TOKEN) {
2099 rc = tcp_get_idx(seq, 0); 2096 rc = tcp_get_idx(seq, 0);
@@ -2106,7 +2103,6 @@ static void *tcp_seq_next(struct seq_file *seq, void *v, loff_t *pos)
2106 case TCP_SEQ_STATE_LISTENING: 2103 case TCP_SEQ_STATE_LISTENING:
2107 rc = listening_get_next(seq, v); 2104 rc = listening_get_next(seq, v);
2108 if (!rc) { 2105 if (!rc) {
2109 inet_listen_unlock(&tcp_hashinfo);
2110 st->state = TCP_SEQ_STATE_ESTABLISHED; 2106 st->state = TCP_SEQ_STATE_ESTABLISHED;
2111 rc = established_get_first(seq); 2107 rc = established_get_first(seq);
2112 } 2108 }
@@ -2123,7 +2119,7 @@ out:
2123 2119
2124static void tcp_seq_stop(struct seq_file *seq, void *v) 2120static void tcp_seq_stop(struct seq_file *seq, void *v)
2125{ 2121{
2126 struct tcp_iter_state* st = seq->private; 2122 struct tcp_iter_state *st = seq->private;
2127 2123
2128 switch (st->state) { 2124 switch (st->state) {
2129 case TCP_SEQ_STATE_OPENREQ: 2125 case TCP_SEQ_STATE_OPENREQ:
@@ -2133,12 +2129,12 @@ static void tcp_seq_stop(struct seq_file *seq, void *v)
2133 } 2129 }
2134 case TCP_SEQ_STATE_LISTENING: 2130 case TCP_SEQ_STATE_LISTENING:
2135 if (v != SEQ_START_TOKEN) 2131 if (v != SEQ_START_TOKEN)
2136 inet_listen_unlock(&tcp_hashinfo); 2132 spin_unlock_bh(&tcp_hashinfo.listening_hash[st->bucket].lock);
2137 break; 2133 break;
2138 case TCP_SEQ_STATE_TIME_WAIT: 2134 case TCP_SEQ_STATE_TIME_WAIT:
2139 case TCP_SEQ_STATE_ESTABLISHED: 2135 case TCP_SEQ_STATE_ESTABLISHED:
2140 if (v) 2136 if (v)
2141 read_unlock_bh(inet_ehash_lockp(&tcp_hashinfo, st->bucket)); 2137 spin_unlock_bh(inet_ehash_lockp(&tcp_hashinfo, st->bucket));
2142 break; 2138 break;
2143 } 2139 }
2144} 2140}
@@ -2284,7 +2280,7 @@ static void get_timewait4_sock(struct inet_timewait_sock *tw,
2284 2280
2285static int tcp4_seq_show(struct seq_file *seq, void *v) 2281static int tcp4_seq_show(struct seq_file *seq, void *v)
2286{ 2282{
2287 struct tcp_iter_state* st; 2283 struct tcp_iter_state *st;
2288 int len; 2284 int len;
2289 2285
2290 if (v == SEQ_START_TOKEN) { 2286 if (v == SEQ_START_TOKEN) {
@@ -2350,6 +2346,41 @@ void tcp4_proc_exit(void)
2350} 2346}
2351#endif /* CONFIG_PROC_FS */ 2347#endif /* CONFIG_PROC_FS */
2352 2348
2349struct sk_buff **tcp4_gro_receive(struct sk_buff **head, struct sk_buff *skb)
2350{
2351 struct iphdr *iph = ip_hdr(skb);
2352
2353 switch (skb->ip_summed) {
2354 case CHECKSUM_COMPLETE:
2355 if (!tcp_v4_check(skb->len, iph->saddr, iph->daddr,
2356 skb->csum)) {
2357 skb->ip_summed = CHECKSUM_UNNECESSARY;
2358 break;
2359 }
2360
2361 /* fall through */
2362 case CHECKSUM_NONE:
2363 NAPI_GRO_CB(skb)->flush = 1;
2364 return NULL;
2365 }
2366
2367 return tcp_gro_receive(head, skb);
2368}
2369EXPORT_SYMBOL(tcp4_gro_receive);
2370
2371int tcp4_gro_complete(struct sk_buff *skb)
2372{
2373 struct iphdr *iph = ip_hdr(skb);
2374 struct tcphdr *th = tcp_hdr(skb);
2375
2376 th->check = ~tcp_v4_check(skb->len - skb_transport_offset(skb),
2377 iph->saddr, iph->daddr, 0);
2378 skb_shinfo(skb)->gso_type = SKB_GSO_TCPV4;
2379
2380 return tcp_gro_complete(skb);
2381}
2382EXPORT_SYMBOL(tcp4_gro_complete);
2383
2353struct proto tcp_prot = { 2384struct proto tcp_prot = {
2354 .name = "TCP", 2385 .name = "TCP",
2355 .owner = THIS_MODULE, 2386 .owner = THIS_MODULE,
@@ -2378,6 +2409,7 @@ struct proto tcp_prot = {
2378 .sysctl_rmem = sysctl_tcp_rmem, 2409 .sysctl_rmem = sysctl_tcp_rmem,
2379 .max_header = MAX_TCP_HEADER, 2410 .max_header = MAX_TCP_HEADER,
2380 .obj_size = sizeof(struct tcp_sock), 2411 .obj_size = sizeof(struct tcp_sock),
2412 .slab_flags = SLAB_DESTROY_BY_RCU,
2381 .twsk_prot = &tcp_timewait_sock_ops, 2413 .twsk_prot = &tcp_timewait_sock_ops,
2382 .rsk_prot = &tcp_request_sock_ops, 2414 .rsk_prot = &tcp_request_sock_ops,
2383 .h.hashinfo = &tcp_hashinfo, 2415 .h.hashinfo = &tcp_hashinfo,
@@ -2407,6 +2439,7 @@ static struct pernet_operations __net_initdata tcp_sk_ops = {
2407 2439
2408void __init tcp_v4_init(void) 2440void __init tcp_v4_init(void)
2409{ 2441{
2442 inet_hashinfo_init(&tcp_hashinfo);
2410 if (register_pernet_device(&tcp_sk_ops)) 2443 if (register_pernet_device(&tcp_sk_ops))
2411 panic("Failed to create the TCP control socket.\n"); 2444 panic("Failed to create the TCP control socket.\n");
2412} 2445}
diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
index 779f2e9d0689..f67effbb102b 100644
--- a/net/ipv4/tcp_minisocks.c
+++ b/net/ipv4/tcp_minisocks.c
@@ -491,7 +491,7 @@ struct sock *tcp_create_openreq_child(struct sock *sk, struct request_sock *req,
491 * as a request_sock. 491 * as a request_sock.
492 */ 492 */
493 493
494struct sock *tcp_check_req(struct sock *sk,struct sk_buff *skb, 494struct sock *tcp_check_req(struct sock *sk, struct sk_buff *skb,
495 struct request_sock *req, 495 struct request_sock *req,
496 struct request_sock **prev) 496 struct request_sock **prev)
497{ 497{
diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c
index fe3b4bdfd251..557fe16cbfb0 100644
--- a/net/ipv4/tcp_output.c
+++ b/net/ipv4/tcp_output.c
@@ -42,7 +42,7 @@
42/* People can turn this off for buggy TCP's found in printers etc. */ 42/* People can turn this off for buggy TCP's found in printers etc. */
43int sysctl_tcp_retrans_collapse __read_mostly = 1; 43int sysctl_tcp_retrans_collapse __read_mostly = 1;
44 44
45/* People can turn this on to work with those rare, broken TCPs that 45/* People can turn this on to work with those rare, broken TCPs that
46 * interpret the window field as a signed quantity. 46 * interpret the window field as a signed quantity.
47 */ 47 */
48int sysctl_tcp_workaround_signed_windows __read_mostly = 0; 48int sysctl_tcp_workaround_signed_windows __read_mostly = 0;
@@ -484,7 +484,7 @@ static unsigned tcp_syn_options(struct sock *sk, struct sk_buff *skb,
484 } 484 }
485 if (likely(sysctl_tcp_window_scaling)) { 485 if (likely(sysctl_tcp_window_scaling)) {
486 opts->ws = tp->rx_opt.rcv_wscale; 486 opts->ws = tp->rx_opt.rcv_wscale;
487 if(likely(opts->ws)) 487 if (likely(opts->ws))
488 size += TCPOLEN_WSCALE_ALIGNED; 488 size += TCPOLEN_WSCALE_ALIGNED;
489 } 489 }
490 if (likely(sysctl_tcp_sack)) { 490 if (likely(sysctl_tcp_sack)) {
@@ -526,7 +526,7 @@ static unsigned tcp_synack_options(struct sock *sk,
526 526
527 if (likely(ireq->wscale_ok)) { 527 if (likely(ireq->wscale_ok)) {
528 opts->ws = ireq->rcv_wscale; 528 opts->ws = ireq->rcv_wscale;
529 if(likely(opts->ws)) 529 if (likely(opts->ws))
530 size += TCPOLEN_WSCALE_ALIGNED; 530 size += TCPOLEN_WSCALE_ALIGNED;
531 } 531 }
532 if (likely(doing_ts)) { 532 if (likely(doing_ts)) {
@@ -663,10 +663,14 @@ static int tcp_transmit_skb(struct sock *sk, struct sk_buff *skb, int clone_it,
663 th->urg_ptr = 0; 663 th->urg_ptr = 0;
664 664
665 /* The urg_mode check is necessary during a below snd_una win probe */ 665 /* The urg_mode check is necessary during a below snd_una win probe */
666 if (unlikely(tcp_urg_mode(tp) && 666 if (unlikely(tcp_urg_mode(tp))) {
667 between(tp->snd_up, tcb->seq + 1, tcb->seq + 0xFFFF))) { 667 if (between(tp->snd_up, tcb->seq + 1, tcb->seq + 0xFFFF)) {
668 th->urg_ptr = htons(tp->snd_up - tcb->seq); 668 th->urg_ptr = htons(tp->snd_up - tcb->seq);
669 th->urg = 1; 669 th->urg = 1;
670 } else if (after(tcb->seq + 0xFFFF, tp->snd_nxt)) {
671 th->urg_ptr = 0xFFFF;
672 th->urg = 1;
673 }
670 } 674 }
671 675
672 tcp_options_write((__be32 *)(th + 1), tp, &opts, &md5_hash_location); 676 tcp_options_write((__be32 *)(th + 1), tp, &opts, &md5_hash_location);
@@ -1168,7 +1172,7 @@ static int tcp_init_tso_segs(struct sock *sk, struct sk_buff *skb,
1168 1172
1169static inline int tcp_minshall_check(const struct tcp_sock *tp) 1173static inline int tcp_minshall_check(const struct tcp_sock *tp)
1170{ 1174{
1171 return after(tp->snd_sml,tp->snd_una) && 1175 return after(tp->snd_sml, tp->snd_una) &&
1172 !after(tp->snd_sml, tp->snd_nxt); 1176 !after(tp->snd_sml, tp->snd_nxt);
1173} 1177}
1174 1178
@@ -1334,7 +1338,7 @@ static int tcp_tso_should_defer(struct sock *sk, struct sk_buff *skb)
1334 1338
1335 /* Defer for less than two clock ticks. */ 1339 /* Defer for less than two clock ticks. */
1336 if (tp->tso_deferred && 1340 if (tp->tso_deferred &&
1337 ((jiffies << 1) >> 1) - (tp->tso_deferred >> 1) > 1) 1341 (((u32)jiffies << 1) >> 1) - (tp->tso_deferred >> 1) > 1)
1338 goto send_now; 1342 goto send_now;
1339 1343
1340 in_flight = tcp_packets_in_flight(tp); 1344 in_flight = tcp_packets_in_flight(tp);
@@ -1519,7 +1523,8 @@ static int tcp_mtu_probe(struct sock *sk)
1519 * Returns 1, if no segments are in flight and we have queued segments, but 1523 * Returns 1, if no segments are in flight and we have queued segments, but
1520 * cannot send anything now because of SWS or another problem. 1524 * cannot send anything now because of SWS or another problem.
1521 */ 1525 */
1522static int tcp_write_xmit(struct sock *sk, unsigned int mss_now, int nonagle) 1526static int tcp_write_xmit(struct sock *sk, unsigned int mss_now, int nonagle,
1527 int push_one, gfp_t gfp)
1523{ 1528{
1524 struct tcp_sock *tp = tcp_sk(sk); 1529 struct tcp_sock *tp = tcp_sk(sk);
1525 struct sk_buff *skb; 1530 struct sk_buff *skb;
@@ -1527,20 +1532,16 @@ static int tcp_write_xmit(struct sock *sk, unsigned int mss_now, int nonagle)
1527 int cwnd_quota; 1532 int cwnd_quota;
1528 int result; 1533 int result;
1529 1534
1530 /* If we are closed, the bytes will have to remain here.
1531 * In time closedown will finish, we empty the write queue and all
1532 * will be happy.
1533 */
1534 if (unlikely(sk->sk_state == TCP_CLOSE))
1535 return 0;
1536
1537 sent_pkts = 0; 1535 sent_pkts = 0;
1538 1536
1539 /* Do MTU probing. */ 1537 if (!push_one) {
1540 if ((result = tcp_mtu_probe(sk)) == 0) { 1538 /* Do MTU probing. */
1541 return 0; 1539 result = tcp_mtu_probe(sk);
1542 } else if (result > 0) { 1540 if (!result) {
1543 sent_pkts = 1; 1541 return 0;
1542 } else if (result > 0) {
1543 sent_pkts = 1;
1544 }
1544 } 1545 }
1545 1546
1546 while ((skb = tcp_send_head(sk))) { 1547 while ((skb = tcp_send_head(sk))) {
@@ -1562,7 +1563,7 @@ static int tcp_write_xmit(struct sock *sk, unsigned int mss_now, int nonagle)
1562 nonagle : TCP_NAGLE_PUSH)))) 1563 nonagle : TCP_NAGLE_PUSH))))
1563 break; 1564 break;
1564 } else { 1565 } else {
1565 if (tcp_tso_should_defer(sk, skb)) 1566 if (!push_one && tcp_tso_should_defer(sk, skb))
1566 break; 1567 break;
1567 } 1568 }
1568 1569
@@ -1577,7 +1578,7 @@ static int tcp_write_xmit(struct sock *sk, unsigned int mss_now, int nonagle)
1577 1578
1578 TCP_SKB_CB(skb)->when = tcp_time_stamp; 1579 TCP_SKB_CB(skb)->when = tcp_time_stamp;
1579 1580
1580 if (unlikely(tcp_transmit_skb(sk, skb, 1, GFP_ATOMIC))) 1581 if (unlikely(tcp_transmit_skb(sk, skb, 1, gfp)))
1581 break; 1582 break;
1582 1583
1583 /* Advance the send_head. This one is sent out. 1584 /* Advance the send_head. This one is sent out.
@@ -1587,6 +1588,9 @@ static int tcp_write_xmit(struct sock *sk, unsigned int mss_now, int nonagle)
1587 1588
1588 tcp_minshall_update(tp, mss_now, skb); 1589 tcp_minshall_update(tp, mss_now, skb);
1589 sent_pkts++; 1590 sent_pkts++;
1591
1592 if (push_one)
1593 break;
1590 } 1594 }
1591 1595
1592 if (likely(sent_pkts)) { 1596 if (likely(sent_pkts)) {
@@ -1605,10 +1609,18 @@ void __tcp_push_pending_frames(struct sock *sk, unsigned int cur_mss,
1605{ 1609{
1606 struct sk_buff *skb = tcp_send_head(sk); 1610 struct sk_buff *skb = tcp_send_head(sk);
1607 1611
1608 if (skb) { 1612 if (!skb)
1609 if (tcp_write_xmit(sk, cur_mss, nonagle)) 1613 return;
1610 tcp_check_probe_timer(sk); 1614
1611 } 1615 /* If we are closed, the bytes will have to remain here.
1616 * In time closedown will finish, we empty the write queue and
1617 * all will be happy.
1618 */
1619 if (unlikely(sk->sk_state == TCP_CLOSE))
1620 return;
1621
1622 if (tcp_write_xmit(sk, cur_mss, nonagle, 0, GFP_ATOMIC))
1623 tcp_check_probe_timer(sk);
1612} 1624}
1613 1625
1614/* Send _single_ skb sitting at the send head. This function requires 1626/* Send _single_ skb sitting at the send head. This function requires
@@ -1616,38 +1628,11 @@ void __tcp_push_pending_frames(struct sock *sk, unsigned int cur_mss,
1616 */ 1628 */
1617void tcp_push_one(struct sock *sk, unsigned int mss_now) 1629void tcp_push_one(struct sock *sk, unsigned int mss_now)
1618{ 1630{
1619 struct tcp_sock *tp = tcp_sk(sk);
1620 struct sk_buff *skb = tcp_send_head(sk); 1631 struct sk_buff *skb = tcp_send_head(sk);
1621 unsigned int tso_segs, cwnd_quota;
1622 1632
1623 BUG_ON(!skb || skb->len < mss_now); 1633 BUG_ON(!skb || skb->len < mss_now);
1624 1634
1625 tso_segs = tcp_init_tso_segs(sk, skb, mss_now); 1635 tcp_write_xmit(sk, mss_now, TCP_NAGLE_PUSH, 1, sk->sk_allocation);
1626 cwnd_quota = tcp_snd_test(sk, skb, mss_now, TCP_NAGLE_PUSH);
1627
1628 if (likely(cwnd_quota)) {
1629 unsigned int limit;
1630
1631 BUG_ON(!tso_segs);
1632
1633 limit = mss_now;
1634 if (tso_segs > 1 && !tcp_urg_mode(tp))
1635 limit = tcp_mss_split_point(sk, skb, mss_now,
1636 cwnd_quota);
1637
1638 if (skb->len > limit &&
1639 unlikely(tso_fragment(sk, skb, limit, mss_now)))
1640 return;
1641
1642 /* Send it out now. */
1643 TCP_SKB_CB(skb)->when = tcp_time_stamp;
1644
1645 if (likely(!tcp_transmit_skb(sk, skb, 1, sk->sk_allocation))) {
1646 tcp_event_new_data_sent(sk, skb);
1647 tcp_cwnd_validate(sk);
1648 return;
1649 }
1650 }
1651} 1636}
1652 1637
1653/* This function returns the amount that we can raise the 1638/* This function returns the amount that we can raise the
@@ -1767,46 +1752,22 @@ u32 __tcp_select_window(struct sock *sk)
1767 return window; 1752 return window;
1768} 1753}
1769 1754
1770/* Attempt to collapse two adjacent SKB's during retransmission. */ 1755/* Collapses two adjacent SKB's during retransmission. */
1771static void tcp_retrans_try_collapse(struct sock *sk, struct sk_buff *skb, 1756static void tcp_collapse_retrans(struct sock *sk, struct sk_buff *skb)
1772 int mss_now)
1773{ 1757{
1774 struct tcp_sock *tp = tcp_sk(sk); 1758 struct tcp_sock *tp = tcp_sk(sk);
1775 struct sk_buff *next_skb = tcp_write_queue_next(sk, skb); 1759 struct sk_buff *next_skb = tcp_write_queue_next(sk, skb);
1776 int skb_size, next_skb_size; 1760 int skb_size, next_skb_size;
1777 u16 flags; 1761 u16 flags;
1778 1762
1779 /* The first test we must make is that neither of these two
1780 * SKB's are still referenced by someone else.
1781 */
1782 if (skb_cloned(skb) || skb_cloned(next_skb))
1783 return;
1784
1785 skb_size = skb->len; 1763 skb_size = skb->len;
1786 next_skb_size = next_skb->len; 1764 next_skb_size = next_skb->len;
1787 flags = TCP_SKB_CB(skb)->flags; 1765 flags = TCP_SKB_CB(skb)->flags;
1788 1766
1789 /* Also punt if next skb has been SACK'd. */
1790 if (TCP_SKB_CB(next_skb)->sacked & TCPCB_SACKED_ACKED)
1791 return;
1792
1793 /* Next skb is out of window. */
1794 if (after(TCP_SKB_CB(next_skb)->end_seq, tcp_wnd_end(tp)))
1795 return;
1796
1797 /* Punt if not enough space exists in the first SKB for
1798 * the data in the second, or the total combined payload
1799 * would exceed the MSS.
1800 */
1801 if ((next_skb_size > skb_tailroom(skb)) ||
1802 ((skb_size + next_skb_size) > mss_now))
1803 return;
1804
1805 BUG_ON(tcp_skb_pcount(skb) != 1 || tcp_skb_pcount(next_skb) != 1); 1767 BUG_ON(tcp_skb_pcount(skb) != 1 || tcp_skb_pcount(next_skb) != 1);
1806 1768
1807 tcp_highest_sack_combine(sk, next_skb, skb); 1769 tcp_highest_sack_combine(sk, next_skb, skb);
1808 1770
1809 /* Ok. We will be able to collapse the packet. */
1810 tcp_unlink_write_queue(next_skb, sk); 1771 tcp_unlink_write_queue(next_skb, sk);
1811 1772
1812 skb_copy_from_linear_data(next_skb, skb_put(skb, next_skb_size), 1773 skb_copy_from_linear_data(next_skb, skb_put(skb, next_skb_size),
@@ -1848,54 +1809,60 @@ static void tcp_retrans_try_collapse(struct sock *sk, struct sk_buff *skb,
1848 sk_wmem_free_skb(sk, next_skb); 1809 sk_wmem_free_skb(sk, next_skb);
1849} 1810}
1850 1811
1851/* Do a simple retransmit without using the backoff mechanisms in 1812static int tcp_can_collapse(struct sock *sk, struct sk_buff *skb)
1852 * tcp_timer. This is used for path mtu discovery. 1813{
1853 * The socket is already locked here. 1814 if (tcp_skb_pcount(skb) > 1)
1854 */ 1815 return 0;
1855void tcp_simple_retransmit(struct sock *sk) 1816 /* TODO: SACK collapsing could be used to remove this condition */
1817 if (skb_shinfo(skb)->nr_frags != 0)
1818 return 0;
1819 if (skb_cloned(skb))
1820 return 0;
1821 if (skb == tcp_send_head(sk))
1822 return 0;
1823 /* Some heurestics for collapsing over SACK'd could be invented */
1824 if (TCP_SKB_CB(skb)->sacked & TCPCB_SACKED_ACKED)
1825 return 0;
1826
1827 return 1;
1828}
1829
1830static void tcp_retrans_try_collapse(struct sock *sk, struct sk_buff *to,
1831 int space)
1856{ 1832{
1857 const struct inet_connection_sock *icsk = inet_csk(sk);
1858 struct tcp_sock *tp = tcp_sk(sk); 1833 struct tcp_sock *tp = tcp_sk(sk);
1859 struct sk_buff *skb; 1834 struct sk_buff *skb = to, *tmp;
1860 unsigned int mss = tcp_current_mss(sk, 0); 1835 int first = 1;
1861 u32 prior_lost = tp->lost_out;
1862 1836
1863 tcp_for_write_queue(skb, sk) { 1837 if (!sysctl_tcp_retrans_collapse)
1864 if (skb == tcp_send_head(sk)) 1838 return;
1839 if (TCP_SKB_CB(skb)->flags & TCPCB_FLAG_SYN)
1840 return;
1841
1842 tcp_for_write_queue_from_safe(skb, tmp, sk) {
1843 if (!tcp_can_collapse(sk, skb))
1865 break; 1844 break;
1866 if (skb->len > mss &&
1867 !(TCP_SKB_CB(skb)->sacked & TCPCB_SACKED_ACKED)) {
1868 if (TCP_SKB_CB(skb)->sacked & TCPCB_SACKED_RETRANS) {
1869 TCP_SKB_CB(skb)->sacked &= ~TCPCB_SACKED_RETRANS;
1870 tp->retrans_out -= tcp_skb_pcount(skb);
1871 }
1872 tcp_skb_mark_lost_uncond_verify(tp, skb);
1873 }
1874 }
1875 1845
1876 tcp_clear_retrans_hints_partial(tp); 1846 space -= skb->len;
1877 1847
1878 if (prior_lost == tp->lost_out) 1848 if (first) {
1879 return; 1849 first = 0;
1850 continue;
1851 }
1880 1852
1881 if (tcp_is_reno(tp)) 1853 if (space < 0)
1882 tcp_limit_reno_sacked(tp); 1854 break;
1855 /* Punt if not enough space exists in the first SKB for
1856 * the data in the second
1857 */
1858 if (skb->len > skb_tailroom(to))
1859 break;
1883 1860
1884 tcp_verify_left_out(tp); 1861 if (after(TCP_SKB_CB(skb)->end_seq, tcp_wnd_end(tp)))
1862 break;
1885 1863
1886 /* Don't muck with the congestion window here. 1864 tcp_collapse_retrans(sk, to);
1887 * Reason is that we do not increase amount of _data_
1888 * in network, but units changed and effective
1889 * cwnd/ssthresh really reduced now.
1890 */
1891 if (icsk->icsk_ca_state != TCP_CA_Loss) {
1892 tp->high_seq = tp->snd_nxt;
1893 tp->snd_ssthresh = tcp_current_ssthresh(sk);
1894 tp->prior_ssthresh = 0;
1895 tp->undo_marker = 0;
1896 tcp_set_ca_state(sk, TCP_CA_Loss);
1897 } 1865 }
1898 tcp_xmit_retransmit_queue(sk);
1899} 1866}
1900 1867
1901/* This retransmits one SKB. Policy decisions and retransmit queue 1868/* This retransmits one SKB. Policy decisions and retransmit queue
@@ -1947,17 +1914,7 @@ int tcp_retransmit_skb(struct sock *sk, struct sk_buff *skb)
1947 return -ENOMEM; /* We'll try again later. */ 1914 return -ENOMEM; /* We'll try again later. */
1948 } 1915 }
1949 1916
1950 /* Collapse two adjacent packets if worthwhile and we can. */ 1917 tcp_retrans_try_collapse(sk, skb, cur_mss);
1951 if (!(TCP_SKB_CB(skb)->flags & TCPCB_FLAG_SYN) &&
1952 (skb->len < (cur_mss >> 1)) &&
1953 (!tcp_skb_is_last(sk, skb)) &&
1954 (tcp_write_queue_next(sk, skb) != tcp_send_head(sk)) &&
1955 (skb_shinfo(skb)->nr_frags == 0 &&
1956 skb_shinfo(tcp_write_queue_next(sk, skb))->nr_frags == 0) &&
1957 (tcp_skb_pcount(skb) == 1 &&
1958 tcp_skb_pcount(tcp_write_queue_next(sk, skb)) == 1) &&
1959 (sysctl_tcp_retrans_collapse != 0))
1960 tcp_retrans_try_collapse(sk, skb, cur_mss);
1961 1918
1962 /* Some Solaris stacks overoptimize and ignore the FIN on a 1919 /* Some Solaris stacks overoptimize and ignore the FIN on a
1963 * retransmit when old data is attached. So strip it off 1920 * retransmit when old data is attached. So strip it off
diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
index 7ddc30f0744f..25524d4e372a 100644
--- a/net/ipv4/tcp_probe.c
+++ b/net/ipv4/tcp_probe.c
@@ -153,12 +153,11 @@ static int tcpprobe_sprint(char *tbuf, int n)
153 = ktime_to_timespec(ktime_sub(p->tstamp, tcp_probe.start)); 153 = ktime_to_timespec(ktime_sub(p->tstamp, tcp_probe.start));
154 154
155 return snprintf(tbuf, n, 155 return snprintf(tbuf, n,
156 "%lu.%09lu " NIPQUAD_FMT ":%u " NIPQUAD_FMT ":%u" 156 "%lu.%09lu %pI4:%u %pI4:%u %d %#x %#x %u %u %u %u\n",
157 " %d %#x %#x %u %u %u %u\n",
158 (unsigned long) tv.tv_sec, 157 (unsigned long) tv.tv_sec,
159 (unsigned long) tv.tv_nsec, 158 (unsigned long) tv.tv_nsec,
160 NIPQUAD(p->saddr), ntohs(p->sport), 159 &p->saddr, ntohs(p->sport),
161 NIPQUAD(p->daddr), ntohs(p->dport), 160 &p->daddr, ntohs(p->dport),
162 p->length, p->snd_nxt, p->snd_una, 161 p->length, p->snd_nxt, p->snd_una,
163 p->snd_cwnd, p->ssthresh, p->snd_wnd, p->srtt); 162 p->snd_cwnd, p->ssthresh, p->snd_wnd, p->srtt);
164} 163}
diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
index 6b6dff1164b9..0170e914f1b0 100644
--- a/net/ipv4/tcp_timer.c
+++ b/net/ipv4/tcp_timer.c
@@ -65,7 +65,7 @@ static void tcp_write_err(struct sock *sk)
65static int tcp_out_of_resources(struct sock *sk, int do_reset) 65static int tcp_out_of_resources(struct sock *sk, int do_reset)
66{ 66{
67 struct tcp_sock *tp = tcp_sk(sk); 67 struct tcp_sock *tp = tcp_sk(sk);
68 int orphans = atomic_read(&tcp_orphan_count); 68 int orphans = percpu_counter_read_positive(&tcp_orphan_count);
69 69
70 /* If peer does not open window for long time, or did not transmit 70 /* If peer does not open window for long time, or did not transmit
71 * anything for long time, penalize it. */ 71 * anything for long time, penalize it. */
@@ -171,7 +171,7 @@ static int tcp_write_timeout(struct sock *sk)
171 171
172static void tcp_delack_timer(unsigned long data) 172static void tcp_delack_timer(unsigned long data)
173{ 173{
174 struct sock *sk = (struct sock*)data; 174 struct sock *sk = (struct sock *)data;
175 struct tcp_sock *tp = tcp_sk(sk); 175 struct tcp_sock *tp = tcp_sk(sk);
176 struct inet_connection_sock *icsk = inet_csk(sk); 176 struct inet_connection_sock *icsk = inet_csk(sk);
177 177
@@ -299,15 +299,15 @@ static void tcp_retransmit_timer(struct sock *sk)
299#ifdef TCP_DEBUG 299#ifdef TCP_DEBUG
300 struct inet_sock *inet = inet_sk(sk); 300 struct inet_sock *inet = inet_sk(sk);
301 if (sk->sk_family == AF_INET) { 301 if (sk->sk_family == AF_INET) {
302 LIMIT_NETDEBUG(KERN_DEBUG "TCP: Treason uncloaked! Peer " NIPQUAD_FMT ":%u/%u shrinks window %u:%u. Repaired.\n", 302 LIMIT_NETDEBUG(KERN_DEBUG "TCP: Peer %pI4:%u/%u unexpectedly shrunk window %u:%u (repaired)\n",
303 NIPQUAD(inet->daddr), ntohs(inet->dport), 303 &inet->daddr, ntohs(inet->dport),
304 inet->num, tp->snd_una, tp->snd_nxt); 304 inet->num, tp->snd_una, tp->snd_nxt);
305 } 305 }
306#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) 306#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
307 else if (sk->sk_family == AF_INET6) { 307 else if (sk->sk_family == AF_INET6) {
308 struct ipv6_pinfo *np = inet6_sk(sk); 308 struct ipv6_pinfo *np = inet6_sk(sk);
309 LIMIT_NETDEBUG(KERN_DEBUG "TCP: Treason uncloaked! Peer " NIP6_FMT ":%u/%u shrinks window %u:%u. Repaired.\n", 309 LIMIT_NETDEBUG(KERN_DEBUG "TCP: Peer %pI6:%u/%u unexpectedly shrunk window %u:%u (repaired)\n",
310 NIP6(np->daddr), ntohs(inet->dport), 310 &np->daddr, ntohs(inet->dport),
311 inet->num, tp->snd_una, tp->snd_nxt); 311 inet->num, tp->snd_una, tp->snd_nxt);
312 } 312 }
313#endif 313#endif
@@ -396,7 +396,7 @@ out:;
396 396
397static void tcp_write_timer(unsigned long data) 397static void tcp_write_timer(unsigned long data)
398{ 398{
399 struct sock *sk = (struct sock*)data; 399 struct sock *sk = (struct sock *)data;
400 struct inet_connection_sock *icsk = inet_csk(sk); 400 struct inet_connection_sock *icsk = inet_csk(sk);
401 int event; 401 int event;
402 402
diff --git a/net/ipv4/tcp_yeah.c b/net/ipv4/tcp_yeah.c
index e03b10183a8b..9ec843a9bbb2 100644
--- a/net/ipv4/tcp_yeah.c
+++ b/net/ipv4/tcp_yeah.c
@@ -83,7 +83,7 @@ static void tcp_yeah_cong_avoid(struct sock *sk, u32 ack, u32 in_flight)
83 else if (!yeah->doing_reno_now) { 83 else if (!yeah->doing_reno_now) {
84 /* Scalable */ 84 /* Scalable */
85 85
86 tp->snd_cwnd_cnt+=yeah->pkts_acked; 86 tp->snd_cwnd_cnt += yeah->pkts_acked;
87 if (tp->snd_cwnd_cnt > min(tp->snd_cwnd, TCP_SCALABLE_AI_CNT)){ 87 if (tp->snd_cwnd_cnt > min(tp->snd_cwnd, TCP_SCALABLE_AI_CNT)){
88 if (tp->snd_cwnd < tp->snd_cwnd_clamp) 88 if (tp->snd_cwnd < tp->snd_cwnd_clamp)
89 tp->snd_cwnd++; 89 tp->snd_cwnd++;
@@ -224,7 +224,7 @@ static u32 tcp_yeah_ssthresh(struct sock *sk) {
224 224
225 reduction = max( reduction, tp->snd_cwnd >> TCP_YEAH_DELTA); 225 reduction = max( reduction, tp->snd_cwnd >> TCP_YEAH_DELTA);
226 } else 226 } else
227 reduction = max(tp->snd_cwnd>>1,2U); 227 reduction = max(tp->snd_cwnd>>1, 2U);
228 228
229 yeah->fast_count = 0; 229 yeah->fast_count = 0;
230 yeah->reno_count = max(yeah->reno_count>>1, 2U); 230 yeah->reno_count = max(yeah->reno_count>>1, 2U);
diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
index 98c1fd09be88..cf5ab0581eba 100644
--- a/net/ipv4/udp.c
+++ b/net/ipv4/udp.c
@@ -81,6 +81,8 @@
81#include <asm/uaccess.h> 81#include <asm/uaccess.h>
82#include <asm/ioctls.h> 82#include <asm/ioctls.h>
83#include <linux/bootmem.h> 83#include <linux/bootmem.h>
84#include <linux/highmem.h>
85#include <linux/swap.h>
84#include <linux/types.h> 86#include <linux/types.h>
85#include <linux/fcntl.h> 87#include <linux/fcntl.h>
86#include <linux/module.h> 88#include <linux/module.h>
@@ -104,12 +106,8 @@
104#include <net/xfrm.h> 106#include <net/xfrm.h>
105#include "udp_impl.h" 107#include "udp_impl.h"
106 108
107/* 109struct udp_table udp_table;
108 * Snmp MIB for the UDP layer 110EXPORT_SYMBOL(udp_table);
109 */
110
111struct hlist_head udp_hash[UDP_HTABLE_SIZE];
112DEFINE_RWLOCK(udp_hash_lock);
113 111
114int sysctl_udp_mem[3] __read_mostly; 112int sysctl_udp_mem[3] __read_mostly;
115int sysctl_udp_rmem_min __read_mostly; 113int sysctl_udp_rmem_min __read_mostly;
@@ -123,15 +121,15 @@ atomic_t udp_memory_allocated;
123EXPORT_SYMBOL(udp_memory_allocated); 121EXPORT_SYMBOL(udp_memory_allocated);
124 122
125static int udp_lib_lport_inuse(struct net *net, __u16 num, 123static int udp_lib_lport_inuse(struct net *net, __u16 num,
126 const struct hlist_head udptable[], 124 const struct udp_hslot *hslot,
127 struct sock *sk, 125 struct sock *sk,
128 int (*saddr_comp)(const struct sock *sk1, 126 int (*saddr_comp)(const struct sock *sk1,
129 const struct sock *sk2)) 127 const struct sock *sk2))
130{ 128{
131 struct sock *sk2; 129 struct sock *sk2;
132 struct hlist_node *node; 130 struct hlist_nulls_node *node;
133 131
134 sk_for_each(sk2, node, &udptable[udp_hashfn(net, num)]) 132 sk_nulls_for_each(sk2, node, &hslot->head)
135 if (net_eq(sock_net(sk2), net) && 133 if (net_eq(sock_net(sk2), net) &&
136 sk2 != sk && 134 sk2 != sk &&
137 sk2->sk_hash == num && 135 sk2->sk_hash == num &&
@@ -154,12 +152,11 @@ int udp_lib_get_port(struct sock *sk, unsigned short snum,
154 int (*saddr_comp)(const struct sock *sk1, 152 int (*saddr_comp)(const struct sock *sk1,
155 const struct sock *sk2 ) ) 153 const struct sock *sk2 ) )
156{ 154{
157 struct hlist_head *udptable = sk->sk_prot->h.udp_hash; 155 struct udp_hslot *hslot;
156 struct udp_table *udptable = sk->sk_prot->h.udp_table;
158 int error = 1; 157 int error = 1;
159 struct net *net = sock_net(sk); 158 struct net *net = sock_net(sk);
160 159
161 write_lock_bh(&udp_hash_lock);
162
163 if (!snum) { 160 if (!snum) {
164 int low, high, remaining; 161 int low, high, remaining;
165 unsigned rand; 162 unsigned rand;
@@ -171,26 +168,34 @@ int udp_lib_get_port(struct sock *sk, unsigned short snum,
171 rand = net_random(); 168 rand = net_random();
172 snum = first = rand % remaining + low; 169 snum = first = rand % remaining + low;
173 rand |= 1; 170 rand |= 1;
174 while (udp_lib_lport_inuse(net, snum, udptable, sk, 171 for (;;) {
175 saddr_comp)) { 172 hslot = &udptable->hash[udp_hashfn(net, snum)];
173 spin_lock_bh(&hslot->lock);
174 if (!udp_lib_lport_inuse(net, snum, hslot, sk, saddr_comp))
175 break;
176 spin_unlock_bh(&hslot->lock);
176 do { 177 do {
177 snum = snum + rand; 178 snum = snum + rand;
178 } while (snum < low || snum > high); 179 } while (snum < low || snum > high);
179 if (snum == first) 180 if (snum == first)
180 goto fail; 181 goto fail;
181 } 182 }
182 } else if (udp_lib_lport_inuse(net, snum, udptable, sk, saddr_comp)) 183 } else {
183 goto fail; 184 hslot = &udptable->hash[udp_hashfn(net, snum)];
184 185 spin_lock_bh(&hslot->lock);
186 if (udp_lib_lport_inuse(net, snum, hslot, sk, saddr_comp))
187 goto fail_unlock;
188 }
185 inet_sk(sk)->num = snum; 189 inet_sk(sk)->num = snum;
186 sk->sk_hash = snum; 190 sk->sk_hash = snum;
187 if (sk_unhashed(sk)) { 191 if (sk_unhashed(sk)) {
188 sk_add_node(sk, &udptable[udp_hashfn(net, snum)]); 192 sk_nulls_add_node_rcu(sk, &hslot->head);
189 sock_prot_inuse_add(sock_net(sk), sk->sk_prot, 1); 193 sock_prot_inuse_add(sock_net(sk), sk->sk_prot, 1);
190 } 194 }
191 error = 0; 195 error = 0;
196fail_unlock:
197 spin_unlock_bh(&hslot->lock);
192fail: 198fail:
193 write_unlock_bh(&udp_hash_lock);
194 return error; 199 return error;
195} 200}
196 201
@@ -208,63 +213,91 @@ int udp_v4_get_port(struct sock *sk, unsigned short snum)
208 return udp_lib_get_port(sk, snum, ipv4_rcv_saddr_equal); 213 return udp_lib_get_port(sk, snum, ipv4_rcv_saddr_equal);
209} 214}
210 215
216static inline int compute_score(struct sock *sk, struct net *net, __be32 saddr,
217 unsigned short hnum,
218 __be16 sport, __be32 daddr, __be16 dport, int dif)
219{
220 int score = -1;
221
222 if (net_eq(sock_net(sk), net) && sk->sk_hash == hnum &&
223 !ipv6_only_sock(sk)) {
224 struct inet_sock *inet = inet_sk(sk);
225
226 score = (sk->sk_family == PF_INET ? 1 : 0);
227 if (inet->rcv_saddr) {
228 if (inet->rcv_saddr != daddr)
229 return -1;
230 score += 2;
231 }
232 if (inet->daddr) {
233 if (inet->daddr != saddr)
234 return -1;
235 score += 2;
236 }
237 if (inet->dport) {
238 if (inet->dport != sport)
239 return -1;
240 score += 2;
241 }
242 if (sk->sk_bound_dev_if) {
243 if (sk->sk_bound_dev_if != dif)
244 return -1;
245 score += 2;
246 }
247 }
248 return score;
249}
250
211/* UDP is nearly always wildcards out the wazoo, it makes no sense to try 251/* UDP is nearly always wildcards out the wazoo, it makes no sense to try
212 * harder than this. -DaveM 252 * harder than this. -DaveM
213 */ 253 */
214static struct sock *__udp4_lib_lookup(struct net *net, __be32 saddr, 254static struct sock *__udp4_lib_lookup(struct net *net, __be32 saddr,
215 __be16 sport, __be32 daddr, __be16 dport, 255 __be16 sport, __be32 daddr, __be16 dport,
216 int dif, struct hlist_head udptable[]) 256 int dif, struct udp_table *udptable)
217{ 257{
218 struct sock *sk, *result = NULL; 258 struct sock *sk, *result;
219 struct hlist_node *node; 259 struct hlist_nulls_node *node;
220 unsigned short hnum = ntohs(dport); 260 unsigned short hnum = ntohs(dport);
221 int badness = -1; 261 unsigned int hash = udp_hashfn(net, hnum);
222 262 struct udp_hslot *hslot = &udptable->hash[hash];
223 read_lock(&udp_hash_lock); 263 int score, badness;
224 sk_for_each(sk, node, &udptable[udp_hashfn(net, hnum)]) { 264
225 struct inet_sock *inet = inet_sk(sk); 265 rcu_read_lock();
226 266begin:
227 if (net_eq(sock_net(sk), net) && sk->sk_hash == hnum && 267 result = NULL;
228 !ipv6_only_sock(sk)) { 268 badness = -1;
229 int score = (sk->sk_family == PF_INET ? 1 : 0); 269 sk_nulls_for_each_rcu(sk, node, &hslot->head) {
230 if (inet->rcv_saddr) { 270 score = compute_score(sk, net, saddr, hnum, sport,
231 if (inet->rcv_saddr != daddr) 271 daddr, dport, dif);
232 continue; 272 if (score > badness) {
233 score+=2; 273 result = sk;
234 } 274 badness = score;
235 if (inet->daddr) {
236 if (inet->daddr != saddr)
237 continue;
238 score+=2;
239 }
240 if (inet->dport) {
241 if (inet->dport != sport)
242 continue;
243 score+=2;
244 }
245 if (sk->sk_bound_dev_if) {
246 if (sk->sk_bound_dev_if != dif)
247 continue;
248 score+=2;
249 }
250 if (score == 9) {
251 result = sk;
252 break;
253 } else if (score > badness) {
254 result = sk;
255 badness = score;
256 }
257 } 275 }
258 } 276 }
259 if (result) 277 /*
260 sock_hold(result); 278 * if the nulls value we got at the end of this lookup is
261 read_unlock(&udp_hash_lock); 279 * not the expected one, we must restart lookup.
280 * We probably met an item that was moved to another chain.
281 */
282 if (get_nulls_value(node) != hash)
283 goto begin;
284
285 if (result) {
286 if (unlikely(!atomic_inc_not_zero(&result->sk_refcnt)))
287 result = NULL;
288 else if (unlikely(compute_score(result, net, saddr, hnum, sport,
289 daddr, dport, dif) < badness)) {
290 sock_put(result);
291 goto begin;
292 }
293 }
294 rcu_read_unlock();
262 return result; 295 return result;
263} 296}
264 297
265static inline struct sock *__udp4_lib_lookup_skb(struct sk_buff *skb, 298static inline struct sock *__udp4_lib_lookup_skb(struct sk_buff *skb,
266 __be16 sport, __be16 dport, 299 __be16 sport, __be16 dport,
267 struct hlist_head udptable[]) 300 struct udp_table *udptable)
268{ 301{
269 struct sock *sk; 302 struct sock *sk;
270 const struct iphdr *iph = ip_hdr(skb); 303 const struct iphdr *iph = ip_hdr(skb);
@@ -280,7 +313,7 @@ static inline struct sock *__udp4_lib_lookup_skb(struct sk_buff *skb,
280struct sock *udp4_lib_lookup(struct net *net, __be32 saddr, __be16 sport, 313struct sock *udp4_lib_lookup(struct net *net, __be32 saddr, __be16 sport,
281 __be32 daddr, __be16 dport, int dif) 314 __be32 daddr, __be16 dport, int dif)
282{ 315{
283 return __udp4_lib_lookup(net, saddr, sport, daddr, dport, dif, udp_hash); 316 return __udp4_lib_lookup(net, saddr, sport, daddr, dport, dif, &udp_table);
284} 317}
285EXPORT_SYMBOL_GPL(udp4_lib_lookup); 318EXPORT_SYMBOL_GPL(udp4_lib_lookup);
286 319
@@ -289,11 +322,11 @@ static inline struct sock *udp_v4_mcast_next(struct net *net, struct sock *sk,
289 __be16 rmt_port, __be32 rmt_addr, 322 __be16 rmt_port, __be32 rmt_addr,
290 int dif) 323 int dif)
291{ 324{
292 struct hlist_node *node; 325 struct hlist_nulls_node *node;
293 struct sock *s = sk; 326 struct sock *s = sk;
294 unsigned short hnum = ntohs(loc_port); 327 unsigned short hnum = ntohs(loc_port);
295 328
296 sk_for_each_from(s, node) { 329 sk_nulls_for_each_from(s, node) {
297 struct inet_sock *inet = inet_sk(s); 330 struct inet_sock *inet = inet_sk(s);
298 331
299 if (!net_eq(sock_net(s), net) || 332 if (!net_eq(sock_net(s), net) ||
@@ -324,7 +357,7 @@ found:
324 * to find the appropriate port. 357 * to find the appropriate port.
325 */ 358 */
326 359
327void __udp4_lib_err(struct sk_buff *skb, u32 info, struct hlist_head udptable[]) 360void __udp4_lib_err(struct sk_buff *skb, u32 info, struct udp_table *udptable)
328{ 361{
329 struct inet_sock *inet; 362 struct inet_sock *inet;
330 struct iphdr *iph = (struct iphdr*)skb->data; 363 struct iphdr *iph = (struct iphdr*)skb->data;
@@ -393,7 +426,7 @@ out:
393 426
394void udp_err(struct sk_buff *skb, u32 info) 427void udp_err(struct sk_buff *skb, u32 info)
395{ 428{
396 __udp4_lib_err(skb, info, udp_hash); 429 __udp4_lib_err(skb, info, &udp_table);
397} 430}
398 431
399/* 432/*
@@ -686,7 +719,7 @@ do_append_data:
686 up->len += ulen; 719 up->len += ulen;
687 getfrag = is_udplite ? udplite_getfrag : ip_generic_getfrag; 720 getfrag = is_udplite ? udplite_getfrag : ip_generic_getfrag;
688 err = ip_append_data(sk, getfrag, msg->msg_iov, ulen, 721 err = ip_append_data(sk, getfrag, msg->msg_iov, ulen,
689 sizeof(struct udphdr), &ipc, rt, 722 sizeof(struct udphdr), &ipc, &rt,
690 corkreq ? msg->msg_flags|MSG_MORE : msg->msg_flags); 723 corkreq ? msg->msg_flags|MSG_MORE : msg->msg_flags);
691 if (err) 724 if (err)
692 udp_flush_pending_frames(sk); 725 udp_flush_pending_frames(sk);
@@ -935,6 +968,23 @@ int udp_disconnect(struct sock *sk, int flags)
935 return 0; 968 return 0;
936} 969}
937 970
971void udp_lib_unhash(struct sock *sk)
972{
973 if (sk_hashed(sk)) {
974 struct udp_table *udptable = sk->sk_prot->h.udp_table;
975 unsigned int hash = udp_hashfn(sock_net(sk), sk->sk_hash);
976 struct udp_hslot *hslot = &udptable->hash[hash];
977
978 spin_lock_bh(&hslot->lock);
979 if (sk_nulls_del_node_init_rcu(sk)) {
980 inet_sk(sk)->num = 0;
981 sock_prot_inuse_add(sock_net(sk), sk->sk_prot, -1);
982 }
983 spin_unlock_bh(&hslot->lock);
984 }
985}
986EXPORT_SYMBOL(udp_lib_unhash);
987
938static int __udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb) 988static int __udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
939{ 989{
940 int is_udplite = IS_UDPLITE(sk); 990 int is_udplite = IS_UDPLITE(sk);
@@ -1073,13 +1123,14 @@ drop:
1073static int __udp4_lib_mcast_deliver(struct net *net, struct sk_buff *skb, 1123static int __udp4_lib_mcast_deliver(struct net *net, struct sk_buff *skb,
1074 struct udphdr *uh, 1124 struct udphdr *uh,
1075 __be32 saddr, __be32 daddr, 1125 __be32 saddr, __be32 daddr,
1076 struct hlist_head udptable[]) 1126 struct udp_table *udptable)
1077{ 1127{
1078 struct sock *sk; 1128 struct sock *sk;
1129 struct udp_hslot *hslot = &udptable->hash[udp_hashfn(net, ntohs(uh->dest))];
1079 int dif; 1130 int dif;
1080 1131
1081 read_lock(&udp_hash_lock); 1132 spin_lock(&hslot->lock);
1082 sk = sk_head(&udptable[udp_hashfn(net, ntohs(uh->dest))]); 1133 sk = sk_nulls_head(&hslot->head);
1083 dif = skb->dev->ifindex; 1134 dif = skb->dev->ifindex;
1084 sk = udp_v4_mcast_next(net, sk, uh->dest, daddr, uh->source, saddr, dif); 1135 sk = udp_v4_mcast_next(net, sk, uh->dest, daddr, uh->source, saddr, dif);
1085 if (sk) { 1136 if (sk) {
@@ -1088,7 +1139,7 @@ static int __udp4_lib_mcast_deliver(struct net *net, struct sk_buff *skb,
1088 do { 1139 do {
1089 struct sk_buff *skb1 = skb; 1140 struct sk_buff *skb1 = skb;
1090 1141
1091 sknext = udp_v4_mcast_next(net, sk_next(sk), uh->dest, 1142 sknext = udp_v4_mcast_next(net, sk_nulls_next(sk), uh->dest,
1092 daddr, uh->source, saddr, 1143 daddr, uh->source, saddr,
1093 dif); 1144 dif);
1094 if (sknext) 1145 if (sknext)
@@ -1105,7 +1156,7 @@ static int __udp4_lib_mcast_deliver(struct net *net, struct sk_buff *skb,
1105 } while (sknext); 1156 } while (sknext);
1106 } else 1157 } else
1107 kfree_skb(skb); 1158 kfree_skb(skb);
1108 read_unlock(&udp_hash_lock); 1159 spin_unlock(&hslot->lock);
1109 return 0; 1160 return 0;
1110} 1161}
1111 1162
@@ -1151,7 +1202,7 @@ static inline int udp4_csum_init(struct sk_buff *skb, struct udphdr *uh,
1151 * All we need to do is get the socket, and then do a checksum. 1202 * All we need to do is get the socket, and then do a checksum.
1152 */ 1203 */
1153 1204
1154int __udp4_lib_rcv(struct sk_buff *skb, struct hlist_head udptable[], 1205int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
1155 int proto) 1206 int proto)
1156{ 1207{
1157 struct sock *sk; 1208 struct sock *sk;
@@ -1219,13 +1270,13 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct hlist_head udptable[],
1219 return 0; 1270 return 0;
1220 1271
1221short_packet: 1272short_packet:
1222 LIMIT_NETDEBUG(KERN_DEBUG "UDP%s: short packet: From " NIPQUAD_FMT ":%u %d/%d to " NIPQUAD_FMT ":%u\n", 1273 LIMIT_NETDEBUG(KERN_DEBUG "UDP%s: short packet: From %pI4:%u %d/%d to %pI4:%u\n",
1223 proto == IPPROTO_UDPLITE ? "-Lite" : "", 1274 proto == IPPROTO_UDPLITE ? "-Lite" : "",
1224 NIPQUAD(saddr), 1275 &saddr,
1225 ntohs(uh->source), 1276 ntohs(uh->source),
1226 ulen, 1277 ulen,
1227 skb->len, 1278 skb->len,
1228 NIPQUAD(daddr), 1279 &daddr,
1229 ntohs(uh->dest)); 1280 ntohs(uh->dest));
1230 goto drop; 1281 goto drop;
1231 1282
@@ -1234,11 +1285,11 @@ csum_error:
1234 * RFC1122: OK. Discards the bad packet silently (as far as 1285 * RFC1122: OK. Discards the bad packet silently (as far as
1235 * the network is concerned, anyway) as per 4.1.3.4 (MUST). 1286 * the network is concerned, anyway) as per 4.1.3.4 (MUST).
1236 */ 1287 */
1237 LIMIT_NETDEBUG(KERN_DEBUG "UDP%s: bad checksum. From " NIPQUAD_FMT ":%u to " NIPQUAD_FMT ":%u ulen %d\n", 1288 LIMIT_NETDEBUG(KERN_DEBUG "UDP%s: bad checksum. From %pI4:%u to %pI4:%u ulen %d\n",
1238 proto == IPPROTO_UDPLITE ? "-Lite" : "", 1289 proto == IPPROTO_UDPLITE ? "-Lite" : "",
1239 NIPQUAD(saddr), 1290 &saddr,
1240 ntohs(uh->source), 1291 ntohs(uh->source),
1241 NIPQUAD(daddr), 1292 &daddr,
1242 ntohs(uh->dest), 1293 ntohs(uh->dest),
1243 ulen); 1294 ulen);
1244drop: 1295drop:
@@ -1249,7 +1300,7 @@ drop:
1249 1300
1250int udp_rcv(struct sk_buff *skb) 1301int udp_rcv(struct sk_buff *skb)
1251{ 1302{
1252 return __udp4_lib_rcv(skb, udp_hash, IPPROTO_UDP); 1303 return __udp4_lib_rcv(skb, &udp_table, IPPROTO_UDP);
1253} 1304}
1254 1305
1255void udp_destroy_sock(struct sock *sk) 1306void udp_destroy_sock(struct sock *sk)
@@ -1491,7 +1542,8 @@ struct proto udp_prot = {
1491 .sysctl_wmem = &sysctl_udp_wmem_min, 1542 .sysctl_wmem = &sysctl_udp_wmem_min,
1492 .sysctl_rmem = &sysctl_udp_rmem_min, 1543 .sysctl_rmem = &sysctl_udp_rmem_min,
1493 .obj_size = sizeof(struct udp_sock), 1544 .obj_size = sizeof(struct udp_sock),
1494 .h.udp_hash = udp_hash, 1545 .slab_flags = SLAB_DESTROY_BY_RCU,
1546 .h.udp_table = &udp_table,
1495#ifdef CONFIG_COMPAT 1547#ifdef CONFIG_COMPAT
1496 .compat_setsockopt = compat_udp_setsockopt, 1548 .compat_setsockopt = compat_udp_setsockopt,
1497 .compat_getsockopt = compat_udp_getsockopt, 1549 .compat_getsockopt = compat_udp_getsockopt,
@@ -1501,20 +1553,23 @@ struct proto udp_prot = {
1501/* ------------------------------------------------------------------------ */ 1553/* ------------------------------------------------------------------------ */
1502#ifdef CONFIG_PROC_FS 1554#ifdef CONFIG_PROC_FS
1503 1555
1504static struct sock *udp_get_first(struct seq_file *seq) 1556static struct sock *udp_get_first(struct seq_file *seq, int start)
1505{ 1557{
1506 struct sock *sk; 1558 struct sock *sk;
1507 struct udp_iter_state *state = seq->private; 1559 struct udp_iter_state *state = seq->private;
1508 struct net *net = seq_file_net(seq); 1560 struct net *net = seq_file_net(seq);
1509 1561
1510 for (state->bucket = 0; state->bucket < UDP_HTABLE_SIZE; ++state->bucket) { 1562 for (state->bucket = start; state->bucket < UDP_HTABLE_SIZE; ++state->bucket) {
1511 struct hlist_node *node; 1563 struct hlist_nulls_node *node;
1512 sk_for_each(sk, node, state->hashtable + state->bucket) { 1564 struct udp_hslot *hslot = &state->udp_table->hash[state->bucket];
1565 spin_lock_bh(&hslot->lock);
1566 sk_nulls_for_each(sk, node, &hslot->head) {
1513 if (!net_eq(sock_net(sk), net)) 1567 if (!net_eq(sock_net(sk), net))
1514 continue; 1568 continue;
1515 if (sk->sk_family == state->family) 1569 if (sk->sk_family == state->family)
1516 goto found; 1570 goto found;
1517 } 1571 }
1572 spin_unlock_bh(&hslot->lock);
1518 } 1573 }
1519 sk = NULL; 1574 sk = NULL;
1520found: 1575found:
@@ -1527,21 +1582,19 @@ static struct sock *udp_get_next(struct seq_file *seq, struct sock *sk)
1527 struct net *net = seq_file_net(seq); 1582 struct net *net = seq_file_net(seq);
1528 1583
1529 do { 1584 do {
1530 sk = sk_next(sk); 1585 sk = sk_nulls_next(sk);
1531try_again:
1532 ;
1533 } while (sk && (!net_eq(sock_net(sk), net) || sk->sk_family != state->family)); 1586 } while (sk && (!net_eq(sock_net(sk), net) || sk->sk_family != state->family));
1534 1587
1535 if (!sk && ++state->bucket < UDP_HTABLE_SIZE) { 1588 if (!sk) {
1536 sk = sk_head(state->hashtable + state->bucket); 1589 spin_unlock_bh(&state->udp_table->hash[state->bucket].lock);
1537 goto try_again; 1590 return udp_get_first(seq, state->bucket + 1);
1538 } 1591 }
1539 return sk; 1592 return sk;
1540} 1593}
1541 1594
1542static struct sock *udp_get_idx(struct seq_file *seq, loff_t pos) 1595static struct sock *udp_get_idx(struct seq_file *seq, loff_t pos)
1543{ 1596{
1544 struct sock *sk = udp_get_first(seq); 1597 struct sock *sk = udp_get_first(seq, 0);
1545 1598
1546 if (sk) 1599 if (sk)
1547 while (pos && (sk = udp_get_next(seq, sk)) != NULL) 1600 while (pos && (sk = udp_get_next(seq, sk)) != NULL)
@@ -1550,9 +1603,7 @@ static struct sock *udp_get_idx(struct seq_file *seq, loff_t pos)
1550} 1603}
1551 1604
1552static void *udp_seq_start(struct seq_file *seq, loff_t *pos) 1605static void *udp_seq_start(struct seq_file *seq, loff_t *pos)
1553 __acquires(udp_hash_lock)
1554{ 1606{
1555 read_lock(&udp_hash_lock);
1556 return *pos ? udp_get_idx(seq, *pos-1) : SEQ_START_TOKEN; 1607 return *pos ? udp_get_idx(seq, *pos-1) : SEQ_START_TOKEN;
1557} 1608}
1558 1609
@@ -1570,9 +1621,11 @@ static void *udp_seq_next(struct seq_file *seq, void *v, loff_t *pos)
1570} 1621}
1571 1622
1572static void udp_seq_stop(struct seq_file *seq, void *v) 1623static void udp_seq_stop(struct seq_file *seq, void *v)
1573 __releases(udp_hash_lock)
1574{ 1624{
1575 read_unlock(&udp_hash_lock); 1625 struct udp_iter_state *state = seq->private;
1626
1627 if (state->bucket < UDP_HTABLE_SIZE)
1628 spin_unlock_bh(&state->udp_table->hash[state->bucket].lock);
1576} 1629}
1577 1630
1578static int udp_seq_open(struct inode *inode, struct file *file) 1631static int udp_seq_open(struct inode *inode, struct file *file)
@@ -1588,7 +1641,7 @@ static int udp_seq_open(struct inode *inode, struct file *file)
1588 1641
1589 s = ((struct seq_file *)file->private_data)->private; 1642 s = ((struct seq_file *)file->private_data)->private;
1590 s->family = afinfo->family; 1643 s->family = afinfo->family;
1591 s->hashtable = afinfo->hashtable; 1644 s->udp_table = afinfo->udp_table;
1592 return err; 1645 return err;
1593} 1646}
1594 1647
@@ -1660,7 +1713,7 @@ int udp4_seq_show(struct seq_file *seq, void *v)
1660static struct udp_seq_afinfo udp4_seq_afinfo = { 1713static struct udp_seq_afinfo udp4_seq_afinfo = {
1661 .name = "udp", 1714 .name = "udp",
1662 .family = AF_INET, 1715 .family = AF_INET,
1663 .hashtable = udp_hash, 1716 .udp_table = &udp_table,
1664 .seq_fops = { 1717 .seq_fops = {
1665 .owner = THIS_MODULE, 1718 .owner = THIS_MODULE,
1666 }, 1719 },
@@ -1695,16 +1748,28 @@ void udp4_proc_exit(void)
1695} 1748}
1696#endif /* CONFIG_PROC_FS */ 1749#endif /* CONFIG_PROC_FS */
1697 1750
1751void __init udp_table_init(struct udp_table *table)
1752{
1753 int i;
1754
1755 for (i = 0; i < UDP_HTABLE_SIZE; i++) {
1756 INIT_HLIST_NULLS_HEAD(&table->hash[i].head, i);
1757 spin_lock_init(&table->hash[i].lock);
1758 }
1759}
1760
1698void __init udp_init(void) 1761void __init udp_init(void)
1699{ 1762{
1700 unsigned long limit; 1763 unsigned long nr_pages, limit;
1701 1764
1765 udp_table_init(&udp_table);
1702 /* Set the pressure threshold up by the same strategy of TCP. It is a 1766 /* Set the pressure threshold up by the same strategy of TCP. It is a
1703 * fraction of global memory that is up to 1/2 at 256 MB, decreasing 1767 * fraction of global memory that is up to 1/2 at 256 MB, decreasing
1704 * toward zero with the amount of memory, with a floor of 128 pages. 1768 * toward zero with the amount of memory, with a floor of 128 pages.
1705 */ 1769 */
1706 limit = min(nr_all_pages, 1UL<<(28-PAGE_SHIFT)) >> (20-PAGE_SHIFT); 1770 nr_pages = totalram_pages - totalhigh_pages;
1707 limit = (limit * (nr_all_pages >> (20-PAGE_SHIFT))) >> (PAGE_SHIFT-11); 1771 limit = min(nr_pages, 1UL<<(28-PAGE_SHIFT)) >> (20-PAGE_SHIFT);
1772 limit = (limit * (nr_pages >> (20-PAGE_SHIFT))) >> (PAGE_SHIFT-11);
1708 limit = max(limit, 128UL); 1773 limit = max(limit, 128UL);
1709 sysctl_udp_mem[0] = limit / 4 * 3; 1774 sysctl_udp_mem[0] = limit / 4 * 3;
1710 sysctl_udp_mem[1] = limit; 1775 sysctl_udp_mem[1] = limit;
@@ -1715,8 +1780,6 @@ void __init udp_init(void)
1715} 1780}
1716 1781
1717EXPORT_SYMBOL(udp_disconnect); 1782EXPORT_SYMBOL(udp_disconnect);
1718EXPORT_SYMBOL(udp_hash);
1719EXPORT_SYMBOL(udp_hash_lock);
1720EXPORT_SYMBOL(udp_ioctl); 1783EXPORT_SYMBOL(udp_ioctl);
1721EXPORT_SYMBOL(udp_prot); 1784EXPORT_SYMBOL(udp_prot);
1722EXPORT_SYMBOL(udp_sendmsg); 1785EXPORT_SYMBOL(udp_sendmsg);
diff --git a/net/ipv4/udp_impl.h b/net/ipv4/udp_impl.h
index 2e9bad2fa1bc..9f4a6165f722 100644
--- a/net/ipv4/udp_impl.h
+++ b/net/ipv4/udp_impl.h
@@ -5,8 +5,8 @@
5#include <net/protocol.h> 5#include <net/protocol.h>
6#include <net/inet_common.h> 6#include <net/inet_common.h>
7 7
8extern int __udp4_lib_rcv(struct sk_buff *, struct hlist_head [], int ); 8extern int __udp4_lib_rcv(struct sk_buff *, struct udp_table *, int );
9extern void __udp4_lib_err(struct sk_buff *, u32, struct hlist_head []); 9extern void __udp4_lib_err(struct sk_buff *, u32, struct udp_table *);
10 10
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
diff --git a/net/ipv4/udplite.c b/net/ipv4/udplite.c
index 3c807964da96..c784891cb7e5 100644
--- a/net/ipv4/udplite.c
+++ b/net/ipv4/udplite.c
@@ -12,16 +12,17 @@
12 */ 12 */
13#include "udp_impl.h" 13#include "udp_impl.h"
14 14
15struct hlist_head udplite_hash[UDP_HTABLE_SIZE]; 15struct udp_table udplite_table;
16EXPORT_SYMBOL(udplite_table);
16 17
17static int udplite_rcv(struct sk_buff *skb) 18static int udplite_rcv(struct sk_buff *skb)
18{ 19{
19 return __udp4_lib_rcv(skb, udplite_hash, IPPROTO_UDPLITE); 20 return __udp4_lib_rcv(skb, &udplite_table, IPPROTO_UDPLITE);
20} 21}
21 22
22static void udplite_err(struct sk_buff *skb, u32 info) 23static void udplite_err(struct sk_buff *skb, u32 info)
23{ 24{
24 __udp4_lib_err(skb, info, udplite_hash); 25 __udp4_lib_err(skb, info, &udplite_table);
25} 26}
26 27
27static struct net_protocol udplite_protocol = { 28static struct net_protocol udplite_protocol = {
@@ -50,7 +51,8 @@ struct proto udplite_prot = {
50 .unhash = udp_lib_unhash, 51 .unhash = udp_lib_unhash,
51 .get_port = udp_v4_get_port, 52 .get_port = udp_v4_get_port,
52 .obj_size = sizeof(struct udp_sock), 53 .obj_size = sizeof(struct udp_sock),
53 .h.udp_hash = udplite_hash, 54 .slab_flags = SLAB_DESTROY_BY_RCU,
55 .h.udp_table = &udplite_table,
54#ifdef CONFIG_COMPAT 56#ifdef CONFIG_COMPAT
55 .compat_setsockopt = compat_udp_setsockopt, 57 .compat_setsockopt = compat_udp_setsockopt,
56 .compat_getsockopt = compat_udp_getsockopt, 58 .compat_getsockopt = compat_udp_getsockopt,
@@ -71,7 +73,7 @@ static struct inet_protosw udplite4_protosw = {
71static struct udp_seq_afinfo udplite4_seq_afinfo = { 73static struct udp_seq_afinfo udplite4_seq_afinfo = {
72 .name = "udplite", 74 .name = "udplite",
73 .family = AF_INET, 75 .family = AF_INET,
74 .hashtable = udplite_hash, 76 .udp_table = &udplite_table,
75 .seq_fops = { 77 .seq_fops = {
76 .owner = THIS_MODULE, 78 .owner = THIS_MODULE,
77 }, 79 },
@@ -108,6 +110,7 @@ static inline int udplite4_proc_init(void)
108 110
109void __init udplite4_register(void) 111void __init udplite4_register(void)
110{ 112{
113 udp_table_init(&udplite_table);
111 if (proto_register(&udplite_prot, 1)) 114 if (proto_register(&udplite_prot, 1))
112 goto out_register_err; 115 goto out_register_err;
113 116
@@ -126,5 +129,4 @@ out_register_err:
126 printk(KERN_CRIT "%s: Cannot add UDP-Lite protocol.\n", __func__); 129 printk(KERN_CRIT "%s: Cannot add UDP-Lite protocol.\n", __func__);
127} 130}
128 131
129EXPORT_SYMBOL(udplite_hash);
130EXPORT_SYMBOL(udplite_prot); 132EXPORT_SYMBOL(udplite_prot);
diff --git a/net/ipv4/xfrm4_input.c b/net/ipv4/xfrm4_input.c
index 390dcb1354a5..4ec2162a437e 100644
--- a/net/ipv4/xfrm4_input.c
+++ b/net/ipv4/xfrm4_input.c
@@ -78,7 +78,6 @@ int xfrm4_udp_encap_rcv(struct sock *sk, struct sk_buff *skb)
78 struct udphdr *uh; 78 struct udphdr *uh;
79 struct iphdr *iph; 79 struct iphdr *iph;
80 int iphlen, len; 80 int iphlen, len;
81 int ret;
82 81
83 __u8 *udpdata; 82 __u8 *udpdata;
84 __be32 *udpdata32; 83 __be32 *udpdata32;
@@ -152,8 +151,7 @@ int xfrm4_udp_encap_rcv(struct sock *sk, struct sk_buff *skb)
152 skb_reset_transport_header(skb); 151 skb_reset_transport_header(skb);
153 152
154 /* process ESP */ 153 /* process ESP */
155 ret = xfrm4_rcv_encap(skb, IPPROTO_ESP, 0, encap_type); 154 return xfrm4_rcv_encap(skb, IPPROTO_ESP, 0, encap_type);
156 return ret;
157 155
158drop: 156drop:
159 kfree_skb(skb); 157 kfree_skb(skb);
diff --git a/net/ipv4/xfrm4_policy.c b/net/ipv4/xfrm4_policy.c
index c63de0a72aba..2ad24ba31f9d 100644
--- a/net/ipv4/xfrm4_policy.c
+++ b/net/ipv4/xfrm4_policy.c
@@ -18,7 +18,8 @@
18static struct dst_ops xfrm4_dst_ops; 18static struct dst_ops xfrm4_dst_ops;
19static struct xfrm_policy_afinfo xfrm4_policy_afinfo; 19static struct xfrm_policy_afinfo xfrm4_policy_afinfo;
20 20
21static struct dst_entry *xfrm4_dst_lookup(int tos, xfrm_address_t *saddr, 21static struct dst_entry *xfrm4_dst_lookup(struct net *net, int tos,
22 xfrm_address_t *saddr,
22 xfrm_address_t *daddr) 23 xfrm_address_t *daddr)
23{ 24{
24 struct flowi fl = { 25 struct flowi fl = {
@@ -36,19 +37,20 @@ static struct dst_entry *xfrm4_dst_lookup(int tos, xfrm_address_t *saddr,
36 if (saddr) 37 if (saddr)
37 fl.fl4_src = saddr->a4; 38 fl.fl4_src = saddr->a4;
38 39
39 err = __ip_route_output_key(&init_net, &rt, &fl); 40 err = __ip_route_output_key(net, &rt, &fl);
40 dst = &rt->u.dst; 41 dst = &rt->u.dst;
41 if (err) 42 if (err)
42 dst = ERR_PTR(err); 43 dst = ERR_PTR(err);
43 return dst; 44 return dst;
44} 45}
45 46
46static int xfrm4_get_saddr(xfrm_address_t *saddr, xfrm_address_t *daddr) 47static int xfrm4_get_saddr(struct net *net,
48 xfrm_address_t *saddr, xfrm_address_t *daddr)
47{ 49{
48 struct dst_entry *dst; 50 struct dst_entry *dst;
49 struct rtable *rt; 51 struct rtable *rt;
50 52
51 dst = xfrm4_dst_lookup(0, NULL, daddr); 53 dst = xfrm4_dst_lookup(net, 0, NULL, daddr);
52 if (IS_ERR(dst)) 54 if (IS_ERR(dst))
53 return -EHOSTUNREACH; 55 return -EHOSTUNREACH;
54 56
@@ -65,7 +67,7 @@ __xfrm4_find_bundle(struct flowi *fl, struct xfrm_policy *policy)
65 67
66 read_lock_bh(&policy->lock); 68 read_lock_bh(&policy->lock);
67 for (dst = policy->bundles; dst; dst = dst->next) { 69 for (dst = policy->bundles; dst; dst = dst->next) {
68 struct xfrm_dst *xdst = (struct xfrm_dst*)dst; 70 struct xfrm_dst *xdst = (struct xfrm_dst *)dst;
69 if (xdst->u.rt.fl.oif == fl->oif && /*XXX*/ 71 if (xdst->u.rt.fl.oif == fl->oif && /*XXX*/
70 xdst->u.rt.fl.fl4_dst == fl->fl4_dst && 72 xdst->u.rt.fl.fl4_dst == fl->fl4_dst &&
71 xdst->u.rt.fl.fl4_src == fl->fl4_src && 73 xdst->u.rt.fl.fl4_src == fl->fl4_src &&
@@ -187,7 +189,7 @@ _decode_session4(struct sk_buff *skb, struct flowi *fl, int reverse)
187 189
188static inline int xfrm4_garbage_collect(struct dst_ops *ops) 190static inline int xfrm4_garbage_collect(struct dst_ops *ops)
189{ 191{
190 xfrm4_policy_afinfo.garbage_collect(); 192 xfrm4_policy_afinfo.garbage_collect(&init_net);
191 return (atomic_read(&xfrm4_dst_ops.entries) > xfrm4_dst_ops.gc_thresh*2); 193 return (atomic_read(&xfrm4_dst_ops.entries) > xfrm4_dst_ops.gc_thresh*2);
192} 194}
193 195
@@ -246,7 +248,6 @@ static struct dst_ops xfrm4_dst_ops = {
246 .ifdown = xfrm4_dst_ifdown, 248 .ifdown = xfrm4_dst_ifdown,
247 .local_out = __ip_local_out, 249 .local_out = __ip_local_out,
248 .gc_thresh = 1024, 250 .gc_thresh = 1024,
249 .entry_size = sizeof(struct xfrm_dst),
250 .entries = ATOMIC_INIT(0), 251 .entries = ATOMIC_INIT(0),
251}; 252};
252 253
diff --git a/net/ipv4/xfrm4_state.c b/net/ipv4/xfrm4_state.c
index 55dc6beab9aa..1ef1366a0a03 100644
--- a/net/ipv4/xfrm4_state.c
+++ b/net/ipv4/xfrm4_state.c
@@ -13,8 +13,6 @@
13#include <linux/ipsec.h> 13#include <linux/ipsec.h>
14#include <linux/netfilter_ipv4.h> 14#include <linux/netfilter_ipv4.h>
15 15
16static struct xfrm_state_afinfo xfrm4_state_afinfo;
17
18static int xfrm4_init_flags(struct xfrm_state *x) 16static int xfrm4_init_flags(struct xfrm_state *x)
19{ 17{
20 if (ipv4_config.no_pmtu_disc) 18 if (ipv4_config.no_pmtu_disc)
diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
index d9da5eb9dcb2..e92ad8455c63 100644
--- a/net/ipv6/addrconf.c
+++ b/net/ipv6/addrconf.c
@@ -2031,8 +2031,8 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
2031 2031
2032#if defined(CONFIG_IPV6_SIT) || defined(CONFIG_IPV6_SIT_MODULE) 2032#if defined(CONFIG_IPV6_SIT) || defined(CONFIG_IPV6_SIT_MODULE)
2033 if (dev->type == ARPHRD_SIT) { 2033 if (dev->type == ARPHRD_SIT) {
2034 const struct net_device_ops *ops = dev->netdev_ops;
2034 struct ifreq ifr; 2035 struct ifreq ifr;
2035 mm_segment_t oldfs;
2036 struct ip_tunnel_parm p; 2036 struct ip_tunnel_parm p;
2037 2037
2038 err = -EADDRNOTAVAIL; 2038 err = -EADDRNOTAVAIL;
@@ -2048,9 +2048,14 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
2048 p.iph.ttl = 64; 2048 p.iph.ttl = 64;
2049 ifr.ifr_ifru.ifru_data = (__force void __user *)&p; 2049 ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
2050 2050
2051 oldfs = get_fs(); set_fs(KERNEL_DS); 2051 if (ops->ndo_do_ioctl) {
2052 err = dev->do_ioctl(dev, &ifr, SIOCADDTUNNEL); 2052 mm_segment_t oldfs = get_fs();
2053 set_fs(oldfs); 2053
2054 set_fs(KERNEL_DS);
2055 err = ops->ndo_do_ioctl(dev, &ifr, SIOCADDTUNNEL);
2056 set_fs(oldfs);
2057 } else
2058 err = -EOPNOTSUPP;
2054 2059
2055 if (err == 0) { 2060 if (err == 0) {
2056 err = -ENOBUFS; 2061 err = -ENOBUFS;
@@ -2988,9 +2993,8 @@ static void if6_seq_stop(struct seq_file *seq, void *v)
2988static int if6_seq_show(struct seq_file *seq, void *v) 2993static int if6_seq_show(struct seq_file *seq, void *v)
2989{ 2994{
2990 struct inet6_ifaddr *ifp = (struct inet6_ifaddr *)v; 2995 struct inet6_ifaddr *ifp = (struct inet6_ifaddr *)v;
2991 seq_printf(seq, 2996 seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
2992 NIP6_SEQFMT " %02x %02x %02x %02x %8s\n", 2997 &ifp->addr,
2993 NIP6(ifp->addr),
2994 ifp->idev->dev->ifindex, 2998 ifp->idev->dev->ifindex,
2995 ifp->prefix_len, 2999 ifp->prefix_len,
2996 ifp->scope, 3000 ifp->scope,
@@ -4033,8 +4037,8 @@ static struct addrconf_sysctl_table
4033 .data = &ipv6_devconf.forwarding, 4037 .data = &ipv6_devconf.forwarding,
4034 .maxlen = sizeof(int), 4038 .maxlen = sizeof(int),
4035 .mode = 0644, 4039 .mode = 0644,
4036 .proc_handler = &addrconf_sysctl_forward, 4040 .proc_handler = addrconf_sysctl_forward,
4037 .strategy = &addrconf_sysctl_forward_strategy, 4041 .strategy = addrconf_sysctl_forward_strategy,
4038 }, 4042 },
4039 { 4043 {
4040 .ctl_name = NET_IPV6_HOP_LIMIT, 4044 .ctl_name = NET_IPV6_HOP_LIMIT,
@@ -4050,7 +4054,7 @@ static struct addrconf_sysctl_table
4050 .data = &ipv6_devconf.mtu6, 4054 .data = &ipv6_devconf.mtu6,
4051 .maxlen = sizeof(int), 4055 .maxlen = sizeof(int),
4052 .mode = 0644, 4056 .mode = 0644,
4053 .proc_handler = &proc_dointvec, 4057 .proc_handler = proc_dointvec,
4054 }, 4058 },
4055 { 4059 {
4056 .ctl_name = NET_IPV6_ACCEPT_RA, 4060 .ctl_name = NET_IPV6_ACCEPT_RA,
@@ -4058,7 +4062,7 @@ static struct addrconf_sysctl_table
4058 .data = &ipv6_devconf.accept_ra, 4062 .data = &ipv6_devconf.accept_ra,
4059 .maxlen = sizeof(int), 4063 .maxlen = sizeof(int),
4060 .mode = 0644, 4064 .mode = 0644,
4061 .proc_handler = &proc_dointvec, 4065 .proc_handler = proc_dointvec,
4062 }, 4066 },
4063 { 4067 {
4064 .ctl_name = NET_IPV6_ACCEPT_REDIRECTS, 4068 .ctl_name = NET_IPV6_ACCEPT_REDIRECTS,
@@ -4066,7 +4070,7 @@ static struct addrconf_sysctl_table
4066 .data = &ipv6_devconf.accept_redirects, 4070 .data = &ipv6_devconf.accept_redirects,
4067 .maxlen = sizeof(int), 4071 .maxlen = sizeof(int),
4068 .mode = 0644, 4072 .mode = 0644,
4069 .proc_handler = &proc_dointvec, 4073 .proc_handler = proc_dointvec,
4070 }, 4074 },
4071 { 4075 {
4072 .ctl_name = NET_IPV6_AUTOCONF, 4076 .ctl_name = NET_IPV6_AUTOCONF,
@@ -4074,7 +4078,7 @@ static struct addrconf_sysctl_table
4074 .data = &ipv6_devconf.autoconf, 4078 .data = &ipv6_devconf.autoconf,
4075 .maxlen = sizeof(int), 4079 .maxlen = sizeof(int),
4076 .mode = 0644, 4080 .mode = 0644,
4077 .proc_handler = &proc_dointvec, 4081 .proc_handler = proc_dointvec,
4078 }, 4082 },
4079 { 4083 {
4080 .ctl_name = NET_IPV6_DAD_TRANSMITS, 4084 .ctl_name = NET_IPV6_DAD_TRANSMITS,
@@ -4082,7 +4086,7 @@ static struct addrconf_sysctl_table
4082 .data = &ipv6_devconf.dad_transmits, 4086 .data = &ipv6_devconf.dad_transmits,
4083 .maxlen = sizeof(int), 4087 .maxlen = sizeof(int),
4084 .mode = 0644, 4088 .mode = 0644,
4085 .proc_handler = &proc_dointvec, 4089 .proc_handler = proc_dointvec,
4086 }, 4090 },
4087 { 4091 {
4088 .ctl_name = NET_IPV6_RTR_SOLICITS, 4092 .ctl_name = NET_IPV6_RTR_SOLICITS,
@@ -4090,7 +4094,7 @@ static struct addrconf_sysctl_table
4090 .data = &ipv6_devconf.rtr_solicits, 4094 .data = &ipv6_devconf.rtr_solicits,
4091 .maxlen = sizeof(int), 4095 .maxlen = sizeof(int),
4092 .mode = 0644, 4096 .mode = 0644,
4093 .proc_handler = &proc_dointvec, 4097 .proc_handler = proc_dointvec,
4094 }, 4098 },
4095 { 4099 {
4096 .ctl_name = NET_IPV6_RTR_SOLICIT_INTERVAL, 4100 .ctl_name = NET_IPV6_RTR_SOLICIT_INTERVAL,
@@ -4098,8 +4102,8 @@ static struct addrconf_sysctl_table
4098 .data = &ipv6_devconf.rtr_solicit_interval, 4102 .data = &ipv6_devconf.rtr_solicit_interval,
4099 .maxlen = sizeof(int), 4103 .maxlen = sizeof(int),
4100 .mode = 0644, 4104 .mode = 0644,
4101 .proc_handler = &proc_dointvec_jiffies, 4105 .proc_handler = proc_dointvec_jiffies,
4102 .strategy = &sysctl_jiffies, 4106 .strategy = sysctl_jiffies,
4103 }, 4107 },
4104 { 4108 {
4105 .ctl_name = NET_IPV6_RTR_SOLICIT_DELAY, 4109 .ctl_name = NET_IPV6_RTR_SOLICIT_DELAY,
@@ -4107,8 +4111,8 @@ static struct addrconf_sysctl_table
4107 .data = &ipv6_devconf.rtr_solicit_delay, 4111 .data = &ipv6_devconf.rtr_solicit_delay,
4108 .maxlen = sizeof(int), 4112 .maxlen = sizeof(int),
4109 .mode = 0644, 4113 .mode = 0644,
4110 .proc_handler = &proc_dointvec_jiffies, 4114 .proc_handler = proc_dointvec_jiffies,
4111 .strategy = &sysctl_jiffies, 4115 .strategy = sysctl_jiffies,
4112 }, 4116 },
4113 { 4117 {
4114 .ctl_name = NET_IPV6_FORCE_MLD_VERSION, 4118 .ctl_name = NET_IPV6_FORCE_MLD_VERSION,
@@ -4116,7 +4120,7 @@ static struct addrconf_sysctl_table
4116 .data = &ipv6_devconf.force_mld_version, 4120 .data = &ipv6_devconf.force_mld_version,
4117 .maxlen = sizeof(int), 4121 .maxlen = sizeof(int),
4118 .mode = 0644, 4122 .mode = 0644,
4119 .proc_handler = &proc_dointvec, 4123 .proc_handler = proc_dointvec,
4120 }, 4124 },
4121#ifdef CONFIG_IPV6_PRIVACY 4125#ifdef CONFIG_IPV6_PRIVACY
4122 { 4126 {
@@ -4125,7 +4129,7 @@ static struct addrconf_sysctl_table
4125 .data = &ipv6_devconf.use_tempaddr, 4129 .data = &ipv6_devconf.use_tempaddr,
4126 .maxlen = sizeof(int), 4130 .maxlen = sizeof(int),
4127 .mode = 0644, 4131 .mode = 0644,
4128 .proc_handler = &proc_dointvec, 4132 .proc_handler = proc_dointvec,
4129 }, 4133 },
4130 { 4134 {
4131 .ctl_name = NET_IPV6_TEMP_VALID_LFT, 4135 .ctl_name = NET_IPV6_TEMP_VALID_LFT,
@@ -4133,7 +4137,7 @@ static struct addrconf_sysctl_table
4133 .data = &ipv6_devconf.temp_valid_lft, 4137 .data = &ipv6_devconf.temp_valid_lft,
4134 .maxlen = sizeof(int), 4138 .maxlen = sizeof(int),
4135 .mode = 0644, 4139 .mode = 0644,
4136 .proc_handler = &proc_dointvec, 4140 .proc_handler = proc_dointvec,
4137 }, 4141 },
4138 { 4142 {
4139 .ctl_name = NET_IPV6_TEMP_PREFERED_LFT, 4143 .ctl_name = NET_IPV6_TEMP_PREFERED_LFT,
@@ -4141,7 +4145,7 @@ static struct addrconf_sysctl_table
4141 .data = &ipv6_devconf.temp_prefered_lft, 4145 .data = &ipv6_devconf.temp_prefered_lft,
4142 .maxlen = sizeof(int), 4146 .maxlen = sizeof(int),
4143 .mode = 0644, 4147 .mode = 0644,
4144 .proc_handler = &proc_dointvec, 4148 .proc_handler = proc_dointvec,
4145 }, 4149 },
4146 { 4150 {
4147 .ctl_name = NET_IPV6_REGEN_MAX_RETRY, 4151 .ctl_name = NET_IPV6_REGEN_MAX_RETRY,
@@ -4149,7 +4153,7 @@ static struct addrconf_sysctl_table
4149 .data = &ipv6_devconf.regen_max_retry, 4153 .data = &ipv6_devconf.regen_max_retry,
4150 .maxlen = sizeof(int), 4154 .maxlen = sizeof(int),
4151 .mode = 0644, 4155 .mode = 0644,
4152 .proc_handler = &proc_dointvec, 4156 .proc_handler = proc_dointvec,
4153 }, 4157 },
4154 { 4158 {
4155 .ctl_name = NET_IPV6_MAX_DESYNC_FACTOR, 4159 .ctl_name = NET_IPV6_MAX_DESYNC_FACTOR,
@@ -4157,7 +4161,7 @@ static struct addrconf_sysctl_table
4157 .data = &ipv6_devconf.max_desync_factor, 4161 .data = &ipv6_devconf.max_desync_factor,
4158 .maxlen = sizeof(int), 4162 .maxlen = sizeof(int),
4159 .mode = 0644, 4163 .mode = 0644,
4160 .proc_handler = &proc_dointvec, 4164 .proc_handler = proc_dointvec,
4161 }, 4165 },
4162#endif 4166#endif
4163 { 4167 {
@@ -4166,7 +4170,7 @@ static struct addrconf_sysctl_table
4166 .data = &ipv6_devconf.max_addresses, 4170 .data = &ipv6_devconf.max_addresses,
4167 .maxlen = sizeof(int), 4171 .maxlen = sizeof(int),
4168 .mode = 0644, 4172 .mode = 0644,
4169 .proc_handler = &proc_dointvec, 4173 .proc_handler = proc_dointvec,
4170 }, 4174 },
4171 { 4175 {
4172 .ctl_name = NET_IPV6_ACCEPT_RA_DEFRTR, 4176 .ctl_name = NET_IPV6_ACCEPT_RA_DEFRTR,
@@ -4174,7 +4178,7 @@ static struct addrconf_sysctl_table
4174 .data = &ipv6_devconf.accept_ra_defrtr, 4178 .data = &ipv6_devconf.accept_ra_defrtr,
4175 .maxlen = sizeof(int), 4179 .maxlen = sizeof(int),
4176 .mode = 0644, 4180 .mode = 0644,
4177 .proc_handler = &proc_dointvec, 4181 .proc_handler = proc_dointvec,
4178 }, 4182 },
4179 { 4183 {
4180 .ctl_name = NET_IPV6_ACCEPT_RA_PINFO, 4184 .ctl_name = NET_IPV6_ACCEPT_RA_PINFO,
@@ -4182,7 +4186,7 @@ static struct addrconf_sysctl_table
4182 .data = &ipv6_devconf.accept_ra_pinfo, 4186 .data = &ipv6_devconf.accept_ra_pinfo,
4183 .maxlen = sizeof(int), 4187 .maxlen = sizeof(int),
4184 .mode = 0644, 4188 .mode = 0644,
4185 .proc_handler = &proc_dointvec, 4189 .proc_handler = proc_dointvec,
4186 }, 4190 },
4187#ifdef CONFIG_IPV6_ROUTER_PREF 4191#ifdef CONFIG_IPV6_ROUTER_PREF
4188 { 4192 {
@@ -4191,7 +4195,7 @@ static struct addrconf_sysctl_table
4191 .data = &ipv6_devconf.accept_ra_rtr_pref, 4195 .data = &ipv6_devconf.accept_ra_rtr_pref,
4192 .maxlen = sizeof(int), 4196 .maxlen = sizeof(int),
4193 .mode = 0644, 4197 .mode = 0644,
4194 .proc_handler = &proc_dointvec, 4198 .proc_handler = proc_dointvec,
4195 }, 4199 },
4196 { 4200 {
4197 .ctl_name = NET_IPV6_RTR_PROBE_INTERVAL, 4201 .ctl_name = NET_IPV6_RTR_PROBE_INTERVAL,
@@ -4199,8 +4203,8 @@ static struct addrconf_sysctl_table
4199 .data = &ipv6_devconf.rtr_probe_interval, 4203 .data = &ipv6_devconf.rtr_probe_interval,
4200 .maxlen = sizeof(int), 4204 .maxlen = sizeof(int),
4201 .mode = 0644, 4205 .mode = 0644,
4202 .proc_handler = &proc_dointvec_jiffies, 4206 .proc_handler = proc_dointvec_jiffies,
4203 .strategy = &sysctl_jiffies, 4207 .strategy = sysctl_jiffies,
4204 }, 4208 },
4205#ifdef CONFIG_IPV6_ROUTE_INFO 4209#ifdef CONFIG_IPV6_ROUTE_INFO
4206 { 4210 {
@@ -4209,7 +4213,7 @@ static struct addrconf_sysctl_table
4209 .data = &ipv6_devconf.accept_ra_rt_info_max_plen, 4213 .data = &ipv6_devconf.accept_ra_rt_info_max_plen,
4210 .maxlen = sizeof(int), 4214 .maxlen = sizeof(int),
4211 .mode = 0644, 4215 .mode = 0644,
4212 .proc_handler = &proc_dointvec, 4216 .proc_handler = proc_dointvec,
4213 }, 4217 },
4214#endif 4218#endif
4215#endif 4219#endif
@@ -4219,7 +4223,7 @@ static struct addrconf_sysctl_table
4219 .data = &ipv6_devconf.proxy_ndp, 4223 .data = &ipv6_devconf.proxy_ndp,
4220 .maxlen = sizeof(int), 4224 .maxlen = sizeof(int),
4221 .mode = 0644, 4225 .mode = 0644,
4222 .proc_handler = &proc_dointvec, 4226 .proc_handler = proc_dointvec,
4223 }, 4227 },
4224 { 4228 {
4225 .ctl_name = NET_IPV6_ACCEPT_SOURCE_ROUTE, 4229 .ctl_name = NET_IPV6_ACCEPT_SOURCE_ROUTE,
@@ -4227,7 +4231,7 @@ static struct addrconf_sysctl_table
4227 .data = &ipv6_devconf.accept_source_route, 4231 .data = &ipv6_devconf.accept_source_route,
4228 .maxlen = sizeof(int), 4232 .maxlen = sizeof(int),
4229 .mode = 0644, 4233 .mode = 0644,
4230 .proc_handler = &proc_dointvec, 4234 .proc_handler = proc_dointvec,
4231 }, 4235 },
4232#ifdef CONFIG_IPV6_OPTIMISTIC_DAD 4236#ifdef CONFIG_IPV6_OPTIMISTIC_DAD
4233 { 4237 {
@@ -4236,7 +4240,7 @@ static struct addrconf_sysctl_table
4236 .data = &ipv6_devconf.optimistic_dad, 4240 .data = &ipv6_devconf.optimistic_dad,
4237 .maxlen = sizeof(int), 4241 .maxlen = sizeof(int),
4238 .mode = 0644, 4242 .mode = 0644,
4239 .proc_handler = &proc_dointvec, 4243 .proc_handler = proc_dointvec,
4240 4244
4241 }, 4245 },
4242#endif 4246#endif
@@ -4247,7 +4251,7 @@ static struct addrconf_sysctl_table
4247 .data = &ipv6_devconf.mc_forwarding, 4251 .data = &ipv6_devconf.mc_forwarding,
4248 .maxlen = sizeof(int), 4252 .maxlen = sizeof(int),
4249 .mode = 0644, 4253 .mode = 0644,
4250 .proc_handler = &proc_dointvec, 4254 .proc_handler = proc_dointvec,
4251 }, 4255 },
4252#endif 4256#endif
4253 { 4257 {
@@ -4256,7 +4260,7 @@ static struct addrconf_sysctl_table
4256 .data = &ipv6_devconf.disable_ipv6, 4260 .data = &ipv6_devconf.disable_ipv6,
4257 .maxlen = sizeof(int), 4261 .maxlen = sizeof(int),
4258 .mode = 0644, 4262 .mode = 0644,
4259 .proc_handler = &proc_dointvec, 4263 .proc_handler = proc_dointvec,
4260 }, 4264 },
4261 { 4265 {
4262 .ctl_name = CTL_UNNUMBERED, 4266 .ctl_name = CTL_UNNUMBERED,
@@ -4264,7 +4268,7 @@ static struct addrconf_sysctl_table
4264 .data = &ipv6_devconf.accept_dad, 4268 .data = &ipv6_devconf.accept_dad,
4265 .maxlen = sizeof(int), 4269 .maxlen = sizeof(int),
4266 .mode = 0644, 4270 .mode = 0644,
4267 .proc_handler = &proc_dointvec, 4271 .proc_handler = proc_dointvec,
4268 }, 4272 },
4269 { 4273 {
4270 .ctl_name = 0, /* sentinel */ 4274 .ctl_name = 0, /* sentinel */
diff --git a/net/ipv6/addrlabel.c b/net/ipv6/addrlabel.c
index 08909039d87b..6ff73c4c126a 100644
--- a/net/ipv6/addrlabel.c
+++ b/net/ipv6/addrlabel.c
@@ -186,10 +186,8 @@ u32 ipv6_addr_label(struct net *net,
186 label = p ? p->label : IPV6_ADDR_LABEL_DEFAULT; 186 label = p ? p->label : IPV6_ADDR_LABEL_DEFAULT;
187 rcu_read_unlock(); 187 rcu_read_unlock();
188 188
189 ADDRLABEL(KERN_DEBUG "%s(addr=" NIP6_FMT ", type=%d, ifindex=%d) => %08x\n", 189 ADDRLABEL(KERN_DEBUG "%s(addr=%pI6, type=%d, ifindex=%d) => %08x\n",
190 __func__, 190 __func__, addr, type, ifindex, label);
191 NIP6(*addr), type, ifindex,
192 label);
193 191
194 return label; 192 return label;
195} 193}
@@ -203,11 +201,8 @@ static struct ip6addrlbl_entry *ip6addrlbl_alloc(struct net *net,
203 struct ip6addrlbl_entry *newp; 201 struct ip6addrlbl_entry *newp;
204 int addrtype; 202 int addrtype;
205 203
206 ADDRLABEL(KERN_DEBUG "%s(prefix=" NIP6_FMT ", prefixlen=%d, ifindex=%d, label=%u)\n", 204 ADDRLABEL(KERN_DEBUG "%s(prefix=%pI6, prefixlen=%d, ifindex=%d, label=%u)\n",
207 __func__, 205 __func__, prefix, prefixlen, ifindex, (unsigned int)label);
208 NIP6(*prefix), prefixlen,
209 ifindex,
210 (unsigned int)label);
211 206
212 addrtype = ipv6_addr_type(prefix) & (IPV6_ADDR_MAPPED | IPV6_ADDR_COMPATv4 | IPV6_ADDR_LOOPBACK); 207 addrtype = ipv6_addr_type(prefix) & (IPV6_ADDR_MAPPED | IPV6_ADDR_COMPATv4 | IPV6_ADDR_LOOPBACK);
213 208
@@ -294,12 +289,9 @@ static int ip6addrlbl_add(struct net *net,
294 struct ip6addrlbl_entry *newp; 289 struct ip6addrlbl_entry *newp;
295 int ret = 0; 290 int ret = 0;
296 291
297 ADDRLABEL(KERN_DEBUG "%s(prefix=" NIP6_FMT ", prefixlen=%d, ifindex=%d, label=%u, replace=%d)\n", 292 ADDRLABEL(KERN_DEBUG "%s(prefix=%pI6, prefixlen=%d, ifindex=%d, label=%u, replace=%d)\n",
298 __func__, 293 __func__, prefix, prefixlen, ifindex, (unsigned int)label,
299 NIP6(*prefix), prefixlen, 294 replace);
300 ifindex,
301 (unsigned int)label,
302 replace);
303 295
304 newp = ip6addrlbl_alloc(net, prefix, prefixlen, ifindex, label); 296 newp = ip6addrlbl_alloc(net, prefix, prefixlen, ifindex, label);
305 if (IS_ERR(newp)) 297 if (IS_ERR(newp))
@@ -321,10 +313,8 @@ static int __ip6addrlbl_del(struct net *net,
321 struct hlist_node *pos, *n; 313 struct hlist_node *pos, *n;
322 int ret = -ESRCH; 314 int ret = -ESRCH;
323 315
324 ADDRLABEL(KERN_DEBUG "%s(prefix=" NIP6_FMT ", prefixlen=%d, ifindex=%d)\n", 316 ADDRLABEL(KERN_DEBUG "%s(prefix=%pI6, prefixlen=%d, ifindex=%d)\n",
325 __func__, 317 __func__, prefix, prefixlen, ifindex);
326 NIP6(*prefix), prefixlen,
327 ifindex);
328 318
329 hlist_for_each_entry_safe(p, pos, n, &ip6addrlbl_table.head, list) { 319 hlist_for_each_entry_safe(p, pos, n, &ip6addrlbl_table.head, list) {
330 if (p->prefixlen == prefixlen && 320 if (p->prefixlen == prefixlen &&
@@ -347,10 +337,8 @@ static int ip6addrlbl_del(struct net *net,
347 struct in6_addr prefix_buf; 337 struct in6_addr prefix_buf;
348 int ret; 338 int ret;
349 339
350 ADDRLABEL(KERN_DEBUG "%s(prefix=" NIP6_FMT ", prefixlen=%d, ifindex=%d)\n", 340 ADDRLABEL(KERN_DEBUG "%s(prefix=%pI6, prefixlen=%d, ifindex=%d)\n",
351 __func__, 341 __func__, prefix, prefixlen, ifindex);
352 NIP6(*prefix), prefixlen,
353 ifindex);
354 342
355 ipv6_addr_prefix(&prefix_buf, prefix, prefixlen); 343 ipv6_addr_prefix(&prefix_buf, prefix, prefixlen);
356 spin_lock(&ip6addrlbl_table.lock); 344 spin_lock(&ip6addrlbl_table.lock);
diff --git a/net/ipv6/af_inet6.c b/net/ipv6/af_inet6.c
index 01edac888510..437b750b98fd 100644
--- a/net/ipv6/af_inet6.c
+++ b/net/ipv6/af_inet6.c
@@ -637,7 +637,7 @@ int inet6_sk_rebuild_header(struct sock *sk)
637 if (final_p) 637 if (final_p)
638 ipv6_addr_copy(&fl.fl6_dst, final_p); 638 ipv6_addr_copy(&fl.fl6_dst, final_p);
639 639
640 if ((err = xfrm_lookup(&dst, &fl, sk, 0)) < 0) { 640 if ((err = xfrm_lookup(sock_net(sk), &dst, &fl, sk, 0)) < 0) {
641 sk->sk_err_soft = -err; 641 sk->sk_err_soft = -err;
642 return err; 642 return err;
643 } 643 }
diff --git a/net/ipv6/ah6.c b/net/ipv6/ah6.c
index 2ff0c8233e47..52449f7a1b71 100644
--- a/net/ipv6/ah6.c
+++ b/net/ipv6/ah6.c
@@ -407,6 +407,7 @@ out:
407static void ah6_err(struct sk_buff *skb, struct inet6_skb_parm *opt, 407static void ah6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
408 int type, int code, int offset, __be32 info) 408 int type, int code, int offset, __be32 info)
409{ 409{
410 struct net *net = dev_net(skb->dev);
410 struct ipv6hdr *iph = (struct ipv6hdr*)skb->data; 411 struct ipv6hdr *iph = (struct ipv6hdr*)skb->data;
411 struct ip_auth_hdr *ah = (struct ip_auth_hdr*)(skb->data+offset); 412 struct ip_auth_hdr *ah = (struct ip_auth_hdr*)(skb->data+offset);
412 struct xfrm_state *x; 413 struct xfrm_state *x;
@@ -415,12 +416,12 @@ static void ah6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
415 type != ICMPV6_PKT_TOOBIG) 416 type != ICMPV6_PKT_TOOBIG)
416 return; 417 return;
417 418
418 x = xfrm_state_lookup((xfrm_address_t *)&iph->daddr, ah->spi, IPPROTO_AH, AF_INET6); 419 x = xfrm_state_lookup(net, (xfrm_address_t *)&iph->daddr, ah->spi, IPPROTO_AH, AF_INET6);
419 if (!x) 420 if (!x)
420 return; 421 return;
421 422
422 NETDEBUG(KERN_DEBUG "pmtu discovery on SA AH/%08x/" NIP6_FMT "\n", 423 NETDEBUG(KERN_DEBUG "pmtu discovery on SA AH/%08x/%pI6\n",
423 ntohl(ah->spi), NIP6(iph->daddr)); 424 ntohl(ah->spi), &iph->daddr);
424 425
425 xfrm_state_put(x); 426 xfrm_state_put(x);
426} 427}
@@ -509,9 +510,7 @@ static void ah6_destroy(struct xfrm_state *x)
509 return; 510 return;
510 511
511 kfree(ahp->work_icv); 512 kfree(ahp->work_icv);
512 ahp->work_icv = NULL;
513 crypto_free_hash(ahp->tfm); 513 crypto_free_hash(ahp->tfm);
514 ahp->tfm = NULL;
515 kfree(ahp); 514 kfree(ahp);
516} 515}
517 516
diff --git a/net/ipv6/anycast.c b/net/ipv6/anycast.c
index 8336cd81cb4f..1ae58bec1de0 100644
--- a/net/ipv6/anycast.c
+++ b/net/ipv6/anycast.c
@@ -512,11 +512,9 @@ static int ac6_seq_show(struct seq_file *seq, void *v)
512 struct ifacaddr6 *im = (struct ifacaddr6 *)v; 512 struct ifacaddr6 *im = (struct ifacaddr6 *)v;
513 struct ac6_iter_state *state = ac6_seq_private(seq); 513 struct ac6_iter_state *state = ac6_seq_private(seq);
514 514
515 seq_printf(seq, 515 seq_printf(seq, "%-4d %-15s %pi6 %5d\n",
516 "%-4d %-15s " NIP6_SEQFMT " %5d\n",
517 state->dev->ifindex, state->dev->name, 516 state->dev->ifindex, state->dev->name,
518 NIP6(im->aca_addr), 517 &im->aca_addr, im->aca_users);
519 im->aca_users);
520 return 0; 518 return 0;
521} 519}
522 520
diff --git a/net/ipv6/datagram.c b/net/ipv6/datagram.c
index e44deb8d4df2..e2bdc6d83a43 100644
--- a/net/ipv6/datagram.c
+++ b/net/ipv6/datagram.c
@@ -175,7 +175,8 @@ ipv4_connected:
175 if (final_p) 175 if (final_p)
176 ipv6_addr_copy(&fl.fl6_dst, final_p); 176 ipv6_addr_copy(&fl.fl6_dst, final_p);
177 177
178 if ((err = __xfrm_lookup(&dst, &fl, sk, XFRM_LOOKUP_WAIT)) < 0) { 178 err = __xfrm_lookup(sock_net(sk), &dst, &fl, sk, XFRM_LOOKUP_WAIT);
179 if (err < 0) {
179 if (err == -EREMOTE) 180 if (err == -EREMOTE)
180 err = ip6_dst_blackhole(sk, &dst, &fl); 181 err = ip6_dst_blackhole(sk, &dst, &fl);
181 if (err < 0) 182 if (err < 0)
diff --git a/net/ipv6/esp6.c b/net/ipv6/esp6.c
index b181b08fb761..c2f250150db1 100644
--- a/net/ipv6/esp6.c
+++ b/net/ipv6/esp6.c
@@ -356,6 +356,7 @@ static u32 esp6_get_mtu(struct xfrm_state *x, int mtu)
356static void esp6_err(struct sk_buff *skb, struct inet6_skb_parm *opt, 356static void esp6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
357 int type, int code, int offset, __be32 info) 357 int type, int code, int offset, __be32 info)
358{ 358{
359 struct net *net = dev_net(skb->dev);
359 struct ipv6hdr *iph = (struct ipv6hdr*)skb->data; 360 struct ipv6hdr *iph = (struct ipv6hdr*)skb->data;
360 struct ip_esp_hdr *esph = (struct ip_esp_hdr *)(skb->data + offset); 361 struct ip_esp_hdr *esph = (struct ip_esp_hdr *)(skb->data + offset);
361 struct xfrm_state *x; 362 struct xfrm_state *x;
@@ -364,11 +365,11 @@ static void esp6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
364 type != ICMPV6_PKT_TOOBIG) 365 type != ICMPV6_PKT_TOOBIG)
365 return; 366 return;
366 367
367 x = xfrm_state_lookup((xfrm_address_t *)&iph->daddr, esph->spi, IPPROTO_ESP, AF_INET6); 368 x = xfrm_state_lookup(net, (xfrm_address_t *)&iph->daddr, esph->spi, IPPROTO_ESP, AF_INET6);
368 if (!x) 369 if (!x)
369 return; 370 return;
370 printk(KERN_DEBUG "pmtu discovery on SA ESP/%08x/" NIP6_FMT "\n", 371 printk(KERN_DEBUG "pmtu discovery on SA ESP/%08x/%pI6\n",
371 ntohl(esph->spi), NIP6(iph->daddr)); 372 ntohl(esph->spi), &iph->daddr);
372 xfrm_state_put(x); 373 xfrm_state_put(x);
373} 374}
374 375
diff --git a/net/ipv6/exthdrs.c b/net/ipv6/exthdrs.c
index 6bfffec2371c..1c7f400a3cfe 100644
--- a/net/ipv6/exthdrs.c
+++ b/net/ipv6/exthdrs.c
@@ -219,7 +219,7 @@ static int ipv6_dest_hao(struct sk_buff *skb, int optoff)
219 219
220 if (!(ipv6_addr_type(&hao->addr) & IPV6_ADDR_UNICAST)) { 220 if (!(ipv6_addr_type(&hao->addr) & IPV6_ADDR_UNICAST)) {
221 LIMIT_NETDEBUG( 221 LIMIT_NETDEBUG(
222 KERN_DEBUG "hao is not an unicast addr: " NIP6_FMT "\n", NIP6(hao->addr)); 222 KERN_DEBUG "hao is not an unicast addr: %pI6\n", &hao->addr);
223 goto discard; 223 goto discard;
224 } 224 }
225 225
diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c
index 9b7d19ae5ced..4f433847d95f 100644
--- a/net/ipv6/icmp.c
+++ b/net/ipv6/icmp.c
@@ -233,7 +233,7 @@ static int icmpv6_push_pending_frames(struct sock *sk, struct flowi *fl, struct
233 icmp6h->icmp6_cksum = 0; 233 icmp6h->icmp6_cksum = 0;
234 234
235 if (skb_queue_len(&sk->sk_write_queue) == 1) { 235 if (skb_queue_len(&sk->sk_write_queue) == 1) {
236 skb->csum = csum_partial((char *)icmp6h, 236 skb->csum = csum_partial(icmp6h,
237 sizeof(struct icmp6hdr), skb->csum); 237 sizeof(struct icmp6hdr), skb->csum);
238 icmp6h->icmp6_cksum = csum_ipv6_magic(&fl->fl6_src, 238 icmp6h->icmp6_cksum = csum_ipv6_magic(&fl->fl6_src,
239 &fl->fl6_dst, 239 &fl->fl6_dst,
@@ -246,7 +246,7 @@ static int icmpv6_push_pending_frames(struct sock *sk, struct flowi *fl, struct
246 tmp_csum = csum_add(tmp_csum, skb->csum); 246 tmp_csum = csum_add(tmp_csum, skb->csum);
247 } 247 }
248 248
249 tmp_csum = csum_partial((char *)icmp6h, 249 tmp_csum = csum_partial(icmp6h,
250 sizeof(struct icmp6hdr), tmp_csum); 250 sizeof(struct icmp6hdr), tmp_csum);
251 icmp6h->icmp6_cksum = csum_ipv6_magic(&fl->fl6_src, 251 icmp6h->icmp6_cksum = csum_ipv6_magic(&fl->fl6_src,
252 &fl->fl6_dst, 252 &fl->fl6_dst,
@@ -427,7 +427,7 @@ void icmpv6_send(struct sk_buff *skb, int type, int code, __u32 info,
427 /* No need to clone since we're just using its address. */ 427 /* No need to clone since we're just using its address. */
428 dst2 = dst; 428 dst2 = dst;
429 429
430 err = xfrm_lookup(&dst, &fl, sk, 0); 430 err = xfrm_lookup(net, &dst, &fl, sk, 0);
431 switch (err) { 431 switch (err) {
432 case 0: 432 case 0:
433 if (dst != dst2) 433 if (dst != dst2)
@@ -446,7 +446,7 @@ void icmpv6_send(struct sk_buff *skb, int type, int code, __u32 info,
446 if (ip6_dst_lookup(sk, &dst2, &fl)) 446 if (ip6_dst_lookup(sk, &dst2, &fl))
447 goto relookup_failed; 447 goto relookup_failed;
448 448
449 err = xfrm_lookup(&dst2, &fl, sk, XFRM_LOOKUP_ICMP); 449 err = xfrm_lookup(net, &dst2, &fl, sk, XFRM_LOOKUP_ICMP);
450 switch (err) { 450 switch (err) {
451 case 0: 451 case 0:
452 dst_release(dst); 452 dst_release(dst);
@@ -552,7 +552,7 @@ static void icmpv6_echo_reply(struct sk_buff *skb)
552 err = ip6_dst_lookup(sk, &dst, &fl); 552 err = ip6_dst_lookup(sk, &dst, &fl);
553 if (err) 553 if (err)
554 goto out; 554 goto out;
555 if ((err = xfrm_lookup(&dst, &fl, sk, 0)) < 0) 555 if ((err = xfrm_lookup(net, &dst, &fl, sk, 0)) < 0)
556 goto out; 556 goto out;
557 557
558 if (ipv6_addr_is_multicast(&fl.fl6_dst)) 558 if (ipv6_addr_is_multicast(&fl.fl6_dst))
@@ -646,9 +646,10 @@ static int icmpv6_rcv(struct sk_buff *skb)
646 int type; 646 int type;
647 647
648 if (!xfrm6_policy_check(NULL, XFRM_POLICY_IN, skb)) { 648 if (!xfrm6_policy_check(NULL, XFRM_POLICY_IN, skb)) {
649 struct sec_path *sp = skb_sec_path(skb);
649 int nh; 650 int nh;
650 651
651 if (!(skb->sp && skb->sp->xvec[skb->sp->len - 1]->props.flags & 652 if (!(sp && sp->xvec[sp->len - 1]->props.flags &
652 XFRM_STATE_ICMP)) 653 XFRM_STATE_ICMP))
653 goto drop_no_count; 654 goto drop_no_count;
654 655
@@ -680,8 +681,8 @@ static int icmpv6_rcv(struct sk_buff *skb)
680 skb->csum = ~csum_unfold(csum_ipv6_magic(saddr, daddr, skb->len, 681 skb->csum = ~csum_unfold(csum_ipv6_magic(saddr, daddr, skb->len,
681 IPPROTO_ICMPV6, 0)); 682 IPPROTO_ICMPV6, 0));
682 if (__skb_checksum_complete(skb)) { 683 if (__skb_checksum_complete(skb)) {
683 LIMIT_NETDEBUG(KERN_DEBUG "ICMPv6 checksum failed [" NIP6_FMT " > " NIP6_FMT "]\n", 684 LIMIT_NETDEBUG(KERN_DEBUG "ICMPv6 checksum failed [%pI6 > %pI6]\n",
684 NIP6(*saddr), NIP6(*daddr)); 685 saddr, daddr);
685 goto discard_it; 686 goto discard_it;
686 } 687 }
687 } 688 }
@@ -955,8 +956,8 @@ ctl_table ipv6_icmp_table_template[] = {
955 .data = &init_net.ipv6.sysctl.icmpv6_time, 956 .data = &init_net.ipv6.sysctl.icmpv6_time,
956 .maxlen = sizeof(int), 957 .maxlen = sizeof(int),
957 .mode = 0644, 958 .mode = 0644,
958 .proc_handler = &proc_dointvec_ms_jiffies, 959 .proc_handler = proc_dointvec_ms_jiffies,
959 .strategy = &sysctl_ms_jiffies 960 .strategy = sysctl_ms_jiffies
960 }, 961 },
961 { .ctl_name = 0 }, 962 { .ctl_name = 0 },
962}; 963};
diff --git a/net/ipv6/inet6_connection_sock.c b/net/ipv6/inet6_connection_sock.c
index 16d43f20b32f..3c3732d50c1a 100644
--- a/net/ipv6/inet6_connection_sock.c
+++ b/net/ipv6/inet6_connection_sock.c
@@ -219,7 +219,7 @@ int inet6_csk_xmit(struct sk_buff *skb, int ipfragok)
219 if (final_p) 219 if (final_p)
220 ipv6_addr_copy(&fl.fl6_dst, final_p); 220 ipv6_addr_copy(&fl.fl6_dst, final_p);
221 221
222 if ((err = xfrm_lookup(&dst, &fl, sk, 0)) < 0) { 222 if ((err = xfrm_lookup(sock_net(sk), &dst, &fl, sk, 0)) < 0) {
223 sk->sk_route_caps = 0; 223 sk->sk_route_caps = 0;
224 kfree_skb(skb); 224 kfree_skb(skb);
225 return err; 225 return err;
diff --git a/net/ipv6/inet6_hashtables.c b/net/ipv6/inet6_hashtables.c
index 1646a5658255..8fe267feb81e 100644
--- a/net/ipv6/inet6_hashtables.c
+++ b/net/ipv6/inet6_hashtables.c
@@ -25,26 +25,30 @@
25void __inet6_hash(struct sock *sk) 25void __inet6_hash(struct sock *sk)
26{ 26{
27 struct inet_hashinfo *hashinfo = sk->sk_prot->h.hashinfo; 27 struct inet_hashinfo *hashinfo = sk->sk_prot->h.hashinfo;
28 struct hlist_head *list;
29 rwlock_t *lock;
30 28
31 WARN_ON(!sk_unhashed(sk)); 29 WARN_ON(!sk_unhashed(sk));
32 30
33 if (sk->sk_state == TCP_LISTEN) { 31 if (sk->sk_state == TCP_LISTEN) {
34 list = &hashinfo->listening_hash[inet_sk_listen_hashfn(sk)]; 32 struct inet_listen_hashbucket *ilb;
35 lock = &hashinfo->lhash_lock; 33
36 inet_listen_wlock(hashinfo); 34 ilb = &hashinfo->listening_hash[inet_sk_listen_hashfn(sk)];
35 spin_lock(&ilb->lock);
36 __sk_nulls_add_node_rcu(sk, &ilb->head);
37 spin_unlock(&ilb->lock);
37 } else { 38 } else {
38 unsigned int hash; 39 unsigned int hash;
40 struct hlist_nulls_head *list;
41 spinlock_t *lock;
42
39 sk->sk_hash = hash = inet6_sk_ehashfn(sk); 43 sk->sk_hash = hash = inet6_sk_ehashfn(sk);
40 list = &inet_ehash_bucket(hashinfo, hash)->chain; 44 list = &inet_ehash_bucket(hashinfo, hash)->chain;
41 lock = inet_ehash_lockp(hashinfo, hash); 45 lock = inet_ehash_lockp(hashinfo, hash);
42 write_lock(lock); 46 spin_lock(lock);
47 __sk_nulls_add_node_rcu(sk, list);
48 spin_unlock(lock);
43 } 49 }
44 50
45 __sk_add_node(sk, list);
46 sock_prot_inuse_add(sock_net(sk), sk->sk_prot, 1); 51 sock_prot_inuse_add(sock_net(sk), sk->sk_prot, 1);
47 write_unlock(lock);
48} 52}
49EXPORT_SYMBOL(__inet6_hash); 53EXPORT_SYMBOL(__inet6_hash);
50 54
@@ -63,77 +67,122 @@ struct sock *__inet6_lookup_established(struct net *net,
63 const int dif) 67 const int dif)
64{ 68{
65 struct sock *sk; 69 struct sock *sk;
66 const struct hlist_node *node; 70 const struct hlist_nulls_node *node;
67 const __portpair ports = INET_COMBINED_PORTS(sport, hnum); 71 const __portpair ports = INET_COMBINED_PORTS(sport, hnum);
68 /* Optimize here for direct hit, only listening connections can 72 /* Optimize here for direct hit, only listening connections can
69 * have wildcards anyways. 73 * have wildcards anyways.
70 */ 74 */
71 unsigned int hash = inet6_ehashfn(net, daddr, hnum, saddr, sport); 75 unsigned int hash = inet6_ehashfn(net, daddr, hnum, saddr, sport);
72 struct inet_ehash_bucket *head = inet_ehash_bucket(hashinfo, hash); 76 unsigned int slot = hash & (hashinfo->ehash_size - 1);
73 rwlock_t *lock = inet_ehash_lockp(hashinfo, hash); 77 struct inet_ehash_bucket *head = &hashinfo->ehash[slot];
74 78
75 prefetch(head->chain.first); 79
76 read_lock(lock); 80 rcu_read_lock();
77 sk_for_each(sk, node, &head->chain) { 81begin:
82 sk_nulls_for_each_rcu(sk, node, &head->chain) {
78 /* For IPV6 do the cheaper port and family tests first. */ 83 /* For IPV6 do the cheaper port and family tests first. */
79 if (INET6_MATCH(sk, net, hash, saddr, daddr, ports, dif)) 84 if (INET6_MATCH(sk, net, hash, saddr, daddr, ports, dif)) {
80 goto hit; /* You sunk my battleship! */ 85 if (unlikely(!atomic_inc_not_zero(&sk->sk_refcnt)))
86 goto begintw;
87 if (!INET6_MATCH(sk, net, hash, saddr, daddr, ports, dif)) {
88 sock_put(sk);
89 goto begin;
90 }
91 goto out;
92 }
81 } 93 }
94 if (get_nulls_value(node) != slot)
95 goto begin;
96
97begintw:
82 /* Must check for a TIME_WAIT'er before going to listener hash. */ 98 /* Must check for a TIME_WAIT'er before going to listener hash. */
83 sk_for_each(sk, node, &head->twchain) { 99 sk_nulls_for_each_rcu(sk, node, &head->twchain) {
84 if (INET6_TW_MATCH(sk, net, hash, saddr, daddr, ports, dif)) 100 if (INET6_TW_MATCH(sk, net, hash, saddr, daddr, ports, dif)) {
85 goto hit; 101 if (unlikely(!atomic_inc_not_zero(&sk->sk_refcnt))) {
102 sk = NULL;
103 goto out;
104 }
105 if (!INET6_TW_MATCH(sk, net, hash, saddr, daddr, ports, dif)) {
106 sock_put(sk);
107 goto begintw;
108 }
109 goto out;
110 }
86 } 111 }
87 read_unlock(lock); 112 if (get_nulls_value(node) != slot)
88 return NULL; 113 goto begintw;
89 114 sk = NULL;
90hit: 115out:
91 sock_hold(sk); 116 rcu_read_unlock();
92 read_unlock(lock);
93 return sk; 117 return sk;
94} 118}
95EXPORT_SYMBOL(__inet6_lookup_established); 119EXPORT_SYMBOL(__inet6_lookup_established);
96 120
121static int inline compute_score(struct sock *sk, struct net *net,
122 const unsigned short hnum,
123 const struct in6_addr *daddr,
124 const int dif)
125{
126 int score = -1;
127
128 if (net_eq(sock_net(sk), net) && inet_sk(sk)->num == hnum &&
129 sk->sk_family == PF_INET6) {
130 const struct ipv6_pinfo *np = inet6_sk(sk);
131
132 score = 1;
133 if (!ipv6_addr_any(&np->rcv_saddr)) {
134 if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
135 return -1;
136 score++;
137 }
138 if (sk->sk_bound_dev_if) {
139 if (sk->sk_bound_dev_if != dif)
140 return -1;
141 score++;
142 }
143 }
144 return score;
145}
146
97struct sock *inet6_lookup_listener(struct net *net, 147struct sock *inet6_lookup_listener(struct net *net,
98 struct inet_hashinfo *hashinfo, const struct in6_addr *daddr, 148 struct inet_hashinfo *hashinfo, const struct in6_addr *daddr,
99 const unsigned short hnum, const int dif) 149 const unsigned short hnum, const int dif)
100{ 150{
101 struct sock *sk; 151 struct sock *sk;
102 const struct hlist_node *node; 152 const struct hlist_nulls_node *node;
103 struct sock *result = NULL; 153 struct sock *result;
104 int score, hiscore = 0; 154 int score, hiscore;
105 155 unsigned int hash = inet_lhashfn(net, hnum);
106 read_lock(&hashinfo->lhash_lock); 156 struct inet_listen_hashbucket *ilb = &hashinfo->listening_hash[hash];
107 sk_for_each(sk, node, 157
108 &hashinfo->listening_hash[inet_lhashfn(net, hnum)]) { 158 rcu_read_lock();
109 if (net_eq(sock_net(sk), net) && inet_sk(sk)->num == hnum && 159begin:
110 sk->sk_family == PF_INET6) { 160 result = NULL;
111 const struct ipv6_pinfo *np = inet6_sk(sk); 161 hiscore = -1;
112 162 sk_nulls_for_each(sk, node, &ilb->head) {
113 score = 1; 163 score = compute_score(sk, net, hnum, daddr, dif);
114 if (!ipv6_addr_any(&np->rcv_saddr)) { 164 if (score > hiscore) {
115 if (!ipv6_addr_equal(&np->rcv_saddr, daddr)) 165 hiscore = score;
116 continue; 166 result = sk;
117 score++; 167 }
118 } 168 }
119 if (sk->sk_bound_dev_if) { 169 /*
120 if (sk->sk_bound_dev_if != dif) 170 * if the nulls value we got at the end of this lookup is
121 continue; 171 * not the expected one, we must restart lookup.
122 score++; 172 * We probably met an item that was moved to another chain.
123 } 173 */
124 if (score == 3) { 174 if (get_nulls_value(node) != hash + LISTENING_NULLS_BASE)
125 result = sk; 175 goto begin;
126 break; 176 if (result) {
127 } 177 if (unlikely(!atomic_inc_not_zero(&result->sk_refcnt)))
128 if (score > hiscore) { 178 result = NULL;
129 hiscore = score; 179 else if (unlikely(compute_score(result, net, hnum, daddr,
130 result = sk; 180 dif) < hiscore)) {
131 } 181 sock_put(result);
182 goto begin;
132 } 183 }
133 } 184 }
134 if (result) 185 rcu_read_unlock();
135 sock_hold(result);
136 read_unlock(&hashinfo->lhash_lock);
137 return result; 186 return result;
138} 187}
139 188
@@ -170,16 +219,15 @@ static int __inet6_check_established(struct inet_timewait_death_row *death_row,
170 const unsigned int hash = inet6_ehashfn(net, daddr, lport, saddr, 219 const unsigned int hash = inet6_ehashfn(net, daddr, lport, saddr,
171 inet->dport); 220 inet->dport);
172 struct inet_ehash_bucket *head = inet_ehash_bucket(hinfo, hash); 221 struct inet_ehash_bucket *head = inet_ehash_bucket(hinfo, hash);
173 rwlock_t *lock = inet_ehash_lockp(hinfo, hash); 222 spinlock_t *lock = inet_ehash_lockp(hinfo, hash);
174 struct sock *sk2; 223 struct sock *sk2;
175 const struct hlist_node *node; 224 const struct hlist_nulls_node *node;
176 struct inet_timewait_sock *tw; 225 struct inet_timewait_sock *tw;
177 226
178 prefetch(head->chain.first); 227 spin_lock(lock);
179 write_lock(lock);
180 228
181 /* Check TIME-WAIT sockets first. */ 229 /* Check TIME-WAIT sockets first. */
182 sk_for_each(sk2, node, &head->twchain) { 230 sk_nulls_for_each(sk2, node, &head->twchain) {
183 tw = inet_twsk(sk2); 231 tw = inet_twsk(sk2);
184 232
185 if (INET6_TW_MATCH(sk2, net, hash, saddr, daddr, ports, dif)) { 233 if (INET6_TW_MATCH(sk2, net, hash, saddr, daddr, ports, dif)) {
@@ -192,7 +240,7 @@ static int __inet6_check_established(struct inet_timewait_death_row *death_row,
192 tw = NULL; 240 tw = NULL;
193 241
194 /* And established part... */ 242 /* And established part... */
195 sk_for_each(sk2, node, &head->chain) { 243 sk_nulls_for_each(sk2, node, &head->chain) {
196 if (INET6_MATCH(sk2, net, hash, saddr, daddr, ports, dif)) 244 if (INET6_MATCH(sk2, net, hash, saddr, daddr, ports, dif))
197 goto not_unique; 245 goto not_unique;
198 } 246 }
@@ -203,10 +251,10 @@ unique:
203 inet->num = lport; 251 inet->num = lport;
204 inet->sport = htons(lport); 252 inet->sport = htons(lport);
205 WARN_ON(!sk_unhashed(sk)); 253 WARN_ON(!sk_unhashed(sk));
206 __sk_add_node(sk, &head->chain); 254 __sk_nulls_add_node_rcu(sk, &head->chain);
207 sk->sk_hash = hash; 255 sk->sk_hash = hash;
256 spin_unlock(lock);
208 sock_prot_inuse_add(sock_net(sk), sk->sk_prot, 1); 257 sock_prot_inuse_add(sock_net(sk), sk->sk_prot, 1);
209 write_unlock(lock);
210 258
211 if (twp != NULL) { 259 if (twp != NULL) {
212 *twp = tw; 260 *twp = tw;
@@ -221,7 +269,7 @@ unique:
221 return 0; 269 return 0;
222 270
223not_unique: 271not_unique:
224 write_unlock(lock); 272 spin_unlock(lock);
225 return -EADDRNOTAVAIL; 273 return -EADDRNOTAVAIL;
226} 274}
227 275
diff --git a/net/ipv6/ip6_flowlabel.c b/net/ipv6/ip6_flowlabel.c
index bd3c7b96bbaa..c62dd247774f 100644
--- a/net/ipv6/ip6_flowlabel.c
+++ b/net/ipv6/ip6_flowlabel.c
@@ -464,7 +464,7 @@ static inline void fl_link(struct ipv6_pinfo *np, struct ipv6_fl_socklist *sfl,
464 464
465int ipv6_flowlabel_opt(struct sock *sk, char __user *optval, int optlen) 465int ipv6_flowlabel_opt(struct sock *sk, char __user *optval, int optlen)
466{ 466{
467 int err; 467 int uninitialized_var(err);
468 struct net *net = sock_net(sk); 468 struct net *net = sock_net(sk);
469 struct ipv6_pinfo *np = inet6_sk(sk); 469 struct ipv6_pinfo *np = inet6_sk(sk);
470 struct in6_flowlabel_req freq; 470 struct in6_flowlabel_req freq;
@@ -696,14 +696,14 @@ static int ip6fl_seq_show(struct seq_file *seq, void *v)
696 else { 696 else {
697 struct ip6_flowlabel *fl = v; 697 struct ip6_flowlabel *fl = v;
698 seq_printf(seq, 698 seq_printf(seq,
699 "%05X %-1d %-6d %-6d %-6ld %-8ld " NIP6_SEQFMT " %-4d\n", 699 "%05X %-1d %-6d %-6d %-6ld %-8ld %pi6 %-4d\n",
700 (unsigned)ntohl(fl->label), 700 (unsigned)ntohl(fl->label),
701 fl->share, 701 fl->share,
702 (unsigned)fl->owner, 702 (unsigned)fl->owner,
703 atomic_read(&fl->users), 703 atomic_read(&fl->users),
704 fl->linger/HZ, 704 fl->linger/HZ,
705 (long)(fl->expires - jiffies)/HZ, 705 (long)(fl->expires - jiffies)/HZ,
706 NIP6(fl->dst), 706 &fl->dst,
707 fl->opt ? fl->opt->opt_nflen : 0); 707 fl->opt ? fl->opt->opt_nflen : 0);
708 } 708 }
709 return 0; 709 return 0;
diff --git a/net/ipv6/ip6_output.c b/net/ipv6/ip6_output.c
index c77db0b95e26..4b15938bef4d 100644
--- a/net/ipv6/ip6_output.c
+++ b/net/ipv6/ip6_output.c
@@ -137,7 +137,8 @@ static int ip6_output2(struct sk_buff *skb)
137 struct inet6_dev *idev = ip6_dst_idev(skb->dst); 137 struct inet6_dev *idev = ip6_dst_idev(skb->dst);
138 138
139 if (!(dev->flags & IFF_LOOPBACK) && (!np || np->mc_loop) && 139 if (!(dev->flags & IFF_LOOPBACK) && (!np || np->mc_loop) &&
140 ((mroute6_socket && !(IP6CB(skb)->flags & IP6SKB_FORWARDED)) || 140 ((mroute6_socket(dev_net(dev)) &&
141 !(IP6CB(skb)->flags & IP6SKB_FORWARDED)) ||
141 ipv6_chk_mcast_addr(dev, &ipv6_hdr(skb)->daddr, 142 ipv6_chk_mcast_addr(dev, &ipv6_hdr(skb)->daddr,
142 &ipv6_hdr(skb)->saddr))) { 143 &ipv6_hdr(skb)->saddr))) {
143 struct sk_buff *newskb = skb_clone(skb, GFP_ATOMIC); 144 struct sk_buff *newskb = skb_clone(skb, GFP_ATOMIC);
@@ -490,7 +491,7 @@ int ip6_forward(struct sk_buff *skb)
490 We don't send redirects to frames decapsulated from IPsec. 491 We don't send redirects to frames decapsulated from IPsec.
491 */ 492 */
492 if (skb->dev == dst->dev && dst->neighbour && opt->srcrt == 0 && 493 if (skb->dev == dst->dev && dst->neighbour && opt->srcrt == 0 &&
493 !skb->sp) { 494 !skb_sec_path(skb)) {
494 struct in6_addr *target = NULL; 495 struct in6_addr *target = NULL;
495 struct rt6_info *rt; 496 struct rt6_info *rt;
496 struct neighbour *n = dst->neighbour; 497 struct neighbour *n = dst->neighbour;
diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
index 64ce3d33d9c6..58e2b0d93758 100644
--- a/net/ipv6/ip6_tunnel.c
+++ b/net/ipv6/ip6_tunnel.c
@@ -74,8 +74,8 @@ MODULE_LICENSE("GPL");
74 (addr)->s6_addr32[2] ^ (addr)->s6_addr32[3]) & \ 74 (addr)->s6_addr32[2] ^ (addr)->s6_addr32[3]) & \
75 (HASH_SIZE - 1)) 75 (HASH_SIZE - 1))
76 76
77static int ip6_fb_tnl_dev_init(struct net_device *dev); 77static void ip6_fb_tnl_dev_init(struct net_device *dev);
78static int ip6_tnl_dev_init(struct net_device *dev); 78static void ip6_tnl_dev_init(struct net_device *dev);
79static void ip6_tnl_dev_setup(struct net_device *dev); 79static void ip6_tnl_dev_setup(struct net_device *dev);
80 80
81static int ip6_tnl_net_id; 81static int ip6_tnl_net_id;
@@ -249,7 +249,7 @@ static struct ip6_tnl *ip6_tnl_create(struct net *net, struct ip6_tnl_parm *p)
249 } 249 }
250 250
251 t = netdev_priv(dev); 251 t = netdev_priv(dev);
252 dev->init = ip6_tnl_dev_init; 252 ip6_tnl_dev_init(dev);
253 t->parms = *p; 253 t->parms = *p;
254 254
255 if ((err = register_netdevice(dev)) < 0) 255 if ((err = register_netdevice(dev)) < 0)
@@ -846,6 +846,7 @@ static int ip6_tnl_xmit2(struct sk_buff *skb,
846 int encap_limit, 846 int encap_limit,
847 __u32 *pmtu) 847 __u32 *pmtu)
848{ 848{
849 struct net *net = dev_net(dev);
849 struct ip6_tnl *t = netdev_priv(dev); 850 struct ip6_tnl *t = netdev_priv(dev);
850 struct net_device_stats *stats = &t->dev->stats; 851 struct net_device_stats *stats = &t->dev->stats;
851 struct ipv6hdr *ipv6h = ipv6_hdr(skb); 852 struct ipv6hdr *ipv6h = ipv6_hdr(skb);
@@ -861,9 +862,9 @@ static int ip6_tnl_xmit2(struct sk_buff *skb,
861 if ((dst = ip6_tnl_dst_check(t)) != NULL) 862 if ((dst = ip6_tnl_dst_check(t)) != NULL)
862 dst_hold(dst); 863 dst_hold(dst);
863 else { 864 else {
864 dst = ip6_route_output(dev_net(dev), NULL, fl); 865 dst = ip6_route_output(net, NULL, fl);
865 866
866 if (dst->error || xfrm_lookup(&dst, fl, NULL, 0) < 0) 867 if (dst->error || xfrm_lookup(net, &dst, fl, NULL, 0) < 0)
867 goto tx_err_link_failure; 868 goto tx_err_link_failure;
868 } 869 }
869 870
@@ -1150,7 +1151,6 @@ static void ip6_tnl_link_config(struct ip6_tnl *t)
1150 * ip6_tnl_change - update the tunnel parameters 1151 * ip6_tnl_change - update the tunnel parameters
1151 * @t: tunnel to be changed 1152 * @t: tunnel to be changed
1152 * @p: tunnel configuration parameters 1153 * @p: tunnel configuration parameters
1153 * @active: != 0 if tunnel is ready for use
1154 * 1154 *
1155 * Description: 1155 * Description:
1156 * ip6_tnl_change() updates the tunnel parameters 1156 * ip6_tnl_change() updates the tunnel parameters
@@ -1306,6 +1306,14 @@ ip6_tnl_change_mtu(struct net_device *dev, int new_mtu)
1306 return 0; 1306 return 0;
1307} 1307}
1308 1308
1309
1310static const struct net_device_ops ip6_tnl_netdev_ops = {
1311 .ndo_uninit = ip6_tnl_dev_uninit,
1312 .ndo_start_xmit = ip6_tnl_xmit,
1313 .ndo_do_ioctl = ip6_tnl_ioctl,
1314 .ndo_change_mtu = ip6_tnl_change_mtu,
1315};
1316
1309/** 1317/**
1310 * ip6_tnl_dev_setup - setup virtual tunnel device 1318 * ip6_tnl_dev_setup - setup virtual tunnel device
1311 * @dev: virtual device associated with tunnel 1319 * @dev: virtual device associated with tunnel
@@ -1316,11 +1324,8 @@ ip6_tnl_change_mtu(struct net_device *dev, int new_mtu)
1316 1324
1317static void ip6_tnl_dev_setup(struct net_device *dev) 1325static void ip6_tnl_dev_setup(struct net_device *dev)
1318{ 1326{
1319 dev->uninit = ip6_tnl_dev_uninit; 1327 dev->netdev_ops = &ip6_tnl_netdev_ops;
1320 dev->destructor = free_netdev; 1328 dev->destructor = free_netdev;
1321 dev->hard_start_xmit = ip6_tnl_xmit;
1322 dev->do_ioctl = ip6_tnl_ioctl;
1323 dev->change_mtu = ip6_tnl_change_mtu;
1324 1329
1325 dev->type = ARPHRD_TUNNEL6; 1330 dev->type = ARPHRD_TUNNEL6;
1326 dev->hard_header_len = LL_MAX_HEADER + sizeof (struct ipv6hdr); 1331 dev->hard_header_len = LL_MAX_HEADER + sizeof (struct ipv6hdr);
@@ -1349,13 +1354,11 @@ ip6_tnl_dev_init_gen(struct net_device *dev)
1349 * @dev: virtual device associated with tunnel 1354 * @dev: virtual device associated with tunnel
1350 **/ 1355 **/
1351 1356
1352static int 1357static void ip6_tnl_dev_init(struct net_device *dev)
1353ip6_tnl_dev_init(struct net_device *dev)
1354{ 1358{
1355 struct ip6_tnl *t = netdev_priv(dev); 1359 struct ip6_tnl *t = netdev_priv(dev);
1356 ip6_tnl_dev_init_gen(dev); 1360 ip6_tnl_dev_init_gen(dev);
1357 ip6_tnl_link_config(t); 1361 ip6_tnl_link_config(t);
1358 return 0;
1359} 1362}
1360 1363
1361/** 1364/**
@@ -1365,8 +1368,7 @@ ip6_tnl_dev_init(struct net_device *dev)
1365 * Return: 0 1368 * Return: 0
1366 **/ 1369 **/
1367 1370
1368static int 1371static void ip6_fb_tnl_dev_init(struct net_device *dev)
1369ip6_fb_tnl_dev_init(struct net_device *dev)
1370{ 1372{
1371 struct ip6_tnl *t = netdev_priv(dev); 1373 struct ip6_tnl *t = netdev_priv(dev);
1372 struct net *net = dev_net(dev); 1374 struct net *net = dev_net(dev);
@@ -1376,7 +1378,6 @@ ip6_fb_tnl_dev_init(struct net_device *dev)
1376 t->parms.proto = IPPROTO_IPV6; 1378 t->parms.proto = IPPROTO_IPV6;
1377 dev_hold(dev); 1379 dev_hold(dev);
1378 ip6n->tnls_wc[0] = t; 1380 ip6n->tnls_wc[0] = t;
1379 return 0;
1380} 1381}
1381 1382
1382static struct xfrm6_tunnel ip4ip6_handler = { 1383static struct xfrm6_tunnel ip4ip6_handler = {
@@ -1428,10 +1429,10 @@ static int ip6_tnl_init_net(struct net *net)
1428 1429
1429 if (!ip6n->fb_tnl_dev) 1430 if (!ip6n->fb_tnl_dev)
1430 goto err_alloc_dev; 1431 goto err_alloc_dev;
1431
1432 ip6n->fb_tnl_dev->init = ip6_fb_tnl_dev_init;
1433 dev_net_set(ip6n->fb_tnl_dev, net); 1432 dev_net_set(ip6n->fb_tnl_dev, net);
1434 1433
1434 ip6_fb_tnl_dev_init(ip6n->fb_tnl_dev);
1435
1435 err = register_netdev(ip6n->fb_tnl_dev); 1436 err = register_netdev(ip6n->fb_tnl_dev);
1436 if (err < 0) 1437 if (err < 0)
1437 goto err_register; 1438 goto err_register;
diff --git a/net/ipv6/ip6mr.c b/net/ipv6/ip6mr.c
index 0524769632e7..3c51b2d827f4 100644
--- a/net/ipv6/ip6mr.c
+++ b/net/ipv6/ip6mr.c
@@ -49,9 +49,6 @@
49#include <net/addrconf.h> 49#include <net/addrconf.h>
50#include <linux/netfilter_ipv6.h> 50#include <linux/netfilter_ipv6.h>
51 51
52struct sock *mroute6_socket;
53
54
55/* Big lock, protecting vif table, mrt cache and mroute socket state. 52/* Big lock, protecting vif table, mrt cache and mroute socket state.
56 Note that the changes are semaphored via rtnl_lock. 53 Note that the changes are semaphored via rtnl_lock.
57 */ 54 */
@@ -62,22 +59,9 @@ static DEFINE_RWLOCK(mrt_lock);
62 * Multicast router control variables 59 * Multicast router control variables
63 */ 60 */
64 61
65static struct mif_device vif6_table[MAXMIFS]; /* Devices */ 62#define MIF_EXISTS(_net, _idx) ((_net)->ipv6.vif6_table[_idx].dev != NULL)
66static int maxvif;
67
68#define MIF_EXISTS(idx) (vif6_table[idx].dev != NULL)
69
70static int mroute_do_assert; /* Set in PIM assert */
71#ifdef CONFIG_IPV6_PIMSM_V2
72static int mroute_do_pim;
73#else
74#define mroute_do_pim 0
75#endif
76
77static struct mfc6_cache *mfc6_cache_array[MFC6_LINES]; /* Forwarding cache */
78 63
79static struct mfc6_cache *mfc_unres_queue; /* Queue of unresolved entries */ 64static struct mfc6_cache *mfc_unres_queue; /* Queue of unresolved entries */
80static atomic_t cache_resolve_queue_len; /* Size of unresolved */
81 65
82/* Special spinlock for queue of unresolved entries */ 66/* Special spinlock for queue of unresolved entries */
83static DEFINE_SPINLOCK(mfc_unres_lock); 67static DEFINE_SPINLOCK(mfc_unres_lock);
@@ -93,8 +77,10 @@ static DEFINE_SPINLOCK(mfc_unres_lock);
93static struct kmem_cache *mrt_cachep __read_mostly; 77static struct kmem_cache *mrt_cachep __read_mostly;
94 78
95static int ip6_mr_forward(struct sk_buff *skb, struct mfc6_cache *cache); 79static int ip6_mr_forward(struct sk_buff *skb, struct mfc6_cache *cache);
96static int ip6mr_cache_report(struct sk_buff *pkt, mifi_t mifi, int assert); 80static int ip6mr_cache_report(struct net *net, struct sk_buff *pkt,
81 mifi_t mifi, int assert);
97static int ip6mr_fill_mroute(struct sk_buff *skb, struct mfc6_cache *c, struct rtmsg *rtm); 82static int ip6mr_fill_mroute(struct sk_buff *skb, struct mfc6_cache *c, struct rtmsg *rtm);
83static void mroute_clean_tables(struct net *net);
98 84
99#ifdef CONFIG_IPV6_PIMSM_V2 85#ifdef CONFIG_IPV6_PIMSM_V2
100static struct inet6_protocol pim6_protocol; 86static struct inet6_protocol pim6_protocol;
@@ -106,19 +92,22 @@ static struct timer_list ipmr_expire_timer;
106#ifdef CONFIG_PROC_FS 92#ifdef CONFIG_PROC_FS
107 93
108struct ipmr_mfc_iter { 94struct ipmr_mfc_iter {
95 struct seq_net_private p;
109 struct mfc6_cache **cache; 96 struct mfc6_cache **cache;
110 int ct; 97 int ct;
111}; 98};
112 99
113 100
114static struct mfc6_cache *ipmr_mfc_seq_idx(struct ipmr_mfc_iter *it, loff_t pos) 101static struct mfc6_cache *ipmr_mfc_seq_idx(struct net *net,
102 struct ipmr_mfc_iter *it, loff_t pos)
115{ 103{
116 struct mfc6_cache *mfc; 104 struct mfc6_cache *mfc;
117 105
118 it->cache = mfc6_cache_array; 106 it->cache = net->ipv6.mfc6_cache_array;
119 read_lock(&mrt_lock); 107 read_lock(&mrt_lock);
120 for (it->ct = 0; it->ct < ARRAY_SIZE(mfc6_cache_array); it->ct++) 108 for (it->ct = 0; it->ct < MFC6_LINES; it->ct++)
121 for (mfc = mfc6_cache_array[it->ct]; mfc; mfc = mfc->next) 109 for (mfc = net->ipv6.mfc6_cache_array[it->ct];
110 mfc; mfc = mfc->next)
122 if (pos-- == 0) 111 if (pos-- == 0)
123 return mfc; 112 return mfc;
124 read_unlock(&mrt_lock); 113 read_unlock(&mrt_lock);
@@ -126,7 +115,8 @@ static struct mfc6_cache *ipmr_mfc_seq_idx(struct ipmr_mfc_iter *it, loff_t pos)
126 it->cache = &mfc_unres_queue; 115 it->cache = &mfc_unres_queue;
127 spin_lock_bh(&mfc_unres_lock); 116 spin_lock_bh(&mfc_unres_lock);
128 for (mfc = mfc_unres_queue; mfc; mfc = mfc->next) 117 for (mfc = mfc_unres_queue; mfc; mfc = mfc->next)
129 if (pos-- == 0) 118 if (net_eq(mfc6_net(mfc), net) &&
119 pos-- == 0)
130 return mfc; 120 return mfc;
131 spin_unlock_bh(&mfc_unres_lock); 121 spin_unlock_bh(&mfc_unres_lock);
132 122
@@ -142,17 +132,19 @@ static struct mfc6_cache *ipmr_mfc_seq_idx(struct ipmr_mfc_iter *it, loff_t pos)
142 */ 132 */
143 133
144struct ipmr_vif_iter { 134struct ipmr_vif_iter {
135 struct seq_net_private p;
145 int ct; 136 int ct;
146}; 137};
147 138
148static struct mif_device *ip6mr_vif_seq_idx(struct ipmr_vif_iter *iter, 139static struct mif_device *ip6mr_vif_seq_idx(struct net *net,
140 struct ipmr_vif_iter *iter,
149 loff_t pos) 141 loff_t pos)
150{ 142{
151 for (iter->ct = 0; iter->ct < maxvif; ++iter->ct) { 143 for (iter->ct = 0; iter->ct < net->ipv6.maxvif; ++iter->ct) {
152 if (!MIF_EXISTS(iter->ct)) 144 if (!MIF_EXISTS(net, iter->ct))
153 continue; 145 continue;
154 if (pos-- == 0) 146 if (pos-- == 0)
155 return &vif6_table[iter->ct]; 147 return &net->ipv6.vif6_table[iter->ct];
156 } 148 }
157 return NULL; 149 return NULL;
158} 150}
@@ -160,23 +152,26 @@ static struct mif_device *ip6mr_vif_seq_idx(struct ipmr_vif_iter *iter,
160static void *ip6mr_vif_seq_start(struct seq_file *seq, loff_t *pos) 152static void *ip6mr_vif_seq_start(struct seq_file *seq, loff_t *pos)
161 __acquires(mrt_lock) 153 __acquires(mrt_lock)
162{ 154{
155 struct net *net = seq_file_net(seq);
156
163 read_lock(&mrt_lock); 157 read_lock(&mrt_lock);
164 return (*pos ? ip6mr_vif_seq_idx(seq->private, *pos - 1) 158 return *pos ? ip6mr_vif_seq_idx(net, seq->private, *pos - 1)
165 : SEQ_START_TOKEN); 159 : SEQ_START_TOKEN;
166} 160}
167 161
168static void *ip6mr_vif_seq_next(struct seq_file *seq, void *v, loff_t *pos) 162static void *ip6mr_vif_seq_next(struct seq_file *seq, void *v, loff_t *pos)
169{ 163{
170 struct ipmr_vif_iter *iter = seq->private; 164 struct ipmr_vif_iter *iter = seq->private;
165 struct net *net = seq_file_net(seq);
171 166
172 ++*pos; 167 ++*pos;
173 if (v == SEQ_START_TOKEN) 168 if (v == SEQ_START_TOKEN)
174 return ip6mr_vif_seq_idx(iter, 0); 169 return ip6mr_vif_seq_idx(net, iter, 0);
175 170
176 while (++iter->ct < maxvif) { 171 while (++iter->ct < net->ipv6.maxvif) {
177 if (!MIF_EXISTS(iter->ct)) 172 if (!MIF_EXISTS(net, iter->ct))
178 continue; 173 continue;
179 return &vif6_table[iter->ct]; 174 return &net->ipv6.vif6_table[iter->ct];
180 } 175 }
181 return NULL; 176 return NULL;
182} 177}
@@ -189,6 +184,8 @@ static void ip6mr_vif_seq_stop(struct seq_file *seq, void *v)
189 184
190static int ip6mr_vif_seq_show(struct seq_file *seq, void *v) 185static int ip6mr_vif_seq_show(struct seq_file *seq, void *v)
191{ 186{
187 struct net *net = seq_file_net(seq);
188
192 if (v == SEQ_START_TOKEN) { 189 if (v == SEQ_START_TOKEN) {
193 seq_puts(seq, 190 seq_puts(seq,
194 "Interface BytesIn PktsIn BytesOut PktsOut Flags\n"); 191 "Interface BytesIn PktsIn BytesOut PktsOut Flags\n");
@@ -198,7 +195,7 @@ static int ip6mr_vif_seq_show(struct seq_file *seq, void *v)
198 195
199 seq_printf(seq, 196 seq_printf(seq,
200 "%2td %-10s %8ld %7ld %8ld %7ld %05X\n", 197 "%2td %-10s %8ld %7ld %8ld %7ld %05X\n",
201 vif - vif6_table, 198 vif - net->ipv6.vif6_table,
202 name, vif->bytes_in, vif->pkt_in, 199 name, vif->bytes_in, vif->pkt_in,
203 vif->bytes_out, vif->pkt_out, 200 vif->bytes_out, vif->pkt_out,
204 vif->flags); 201 vif->flags);
@@ -215,8 +212,8 @@ static struct seq_operations ip6mr_vif_seq_ops = {
215 212
216static int ip6mr_vif_open(struct inode *inode, struct file *file) 213static int ip6mr_vif_open(struct inode *inode, struct file *file)
217{ 214{
218 return seq_open_private(file, &ip6mr_vif_seq_ops, 215 return seq_open_net(inode, file, &ip6mr_vif_seq_ops,
219 sizeof(struct ipmr_vif_iter)); 216 sizeof(struct ipmr_vif_iter));
220} 217}
221 218
222static struct file_operations ip6mr_vif_fops = { 219static struct file_operations ip6mr_vif_fops = {
@@ -224,24 +221,27 @@ static struct file_operations ip6mr_vif_fops = {
224 .open = ip6mr_vif_open, 221 .open = ip6mr_vif_open,
225 .read = seq_read, 222 .read = seq_read,
226 .llseek = seq_lseek, 223 .llseek = seq_lseek,
227 .release = seq_release_private, 224 .release = seq_release_net,
228}; 225};
229 226
230static void *ipmr_mfc_seq_start(struct seq_file *seq, loff_t *pos) 227static void *ipmr_mfc_seq_start(struct seq_file *seq, loff_t *pos)
231{ 228{
232 return (*pos ? ipmr_mfc_seq_idx(seq->private, *pos - 1) 229 struct net *net = seq_file_net(seq);
233 : SEQ_START_TOKEN); 230
231 return *pos ? ipmr_mfc_seq_idx(net, seq->private, *pos - 1)
232 : SEQ_START_TOKEN;
234} 233}
235 234
236static void *ipmr_mfc_seq_next(struct seq_file *seq, void *v, loff_t *pos) 235static void *ipmr_mfc_seq_next(struct seq_file *seq, void *v, loff_t *pos)
237{ 236{
238 struct mfc6_cache *mfc = v; 237 struct mfc6_cache *mfc = v;
239 struct ipmr_mfc_iter *it = seq->private; 238 struct ipmr_mfc_iter *it = seq->private;
239 struct net *net = seq_file_net(seq);
240 240
241 ++*pos; 241 ++*pos;
242 242
243 if (v == SEQ_START_TOKEN) 243 if (v == SEQ_START_TOKEN)
244 return ipmr_mfc_seq_idx(seq->private, 0); 244 return ipmr_mfc_seq_idx(net, seq->private, 0);
245 245
246 if (mfc->next) 246 if (mfc->next)
247 return mfc->next; 247 return mfc->next;
@@ -249,10 +249,10 @@ static void *ipmr_mfc_seq_next(struct seq_file *seq, void *v, loff_t *pos)
249 if (it->cache == &mfc_unres_queue) 249 if (it->cache == &mfc_unres_queue)
250 goto end_of_list; 250 goto end_of_list;
251 251
252 BUG_ON(it->cache != mfc6_cache_array); 252 BUG_ON(it->cache != net->ipv6.mfc6_cache_array);
253 253
254 while (++it->ct < ARRAY_SIZE(mfc6_cache_array)) { 254 while (++it->ct < MFC6_LINES) {
255 mfc = mfc6_cache_array[it->ct]; 255 mfc = net->ipv6.mfc6_cache_array[it->ct];
256 if (mfc) 256 if (mfc)
257 return mfc; 257 return mfc;
258 } 258 }
@@ -277,16 +277,18 @@ static void *ipmr_mfc_seq_next(struct seq_file *seq, void *v, loff_t *pos)
277static void ipmr_mfc_seq_stop(struct seq_file *seq, void *v) 277static void ipmr_mfc_seq_stop(struct seq_file *seq, void *v)
278{ 278{
279 struct ipmr_mfc_iter *it = seq->private; 279 struct ipmr_mfc_iter *it = seq->private;
280 struct net *net = seq_file_net(seq);
280 281
281 if (it->cache == &mfc_unres_queue) 282 if (it->cache == &mfc_unres_queue)
282 spin_unlock_bh(&mfc_unres_lock); 283 spin_unlock_bh(&mfc_unres_lock);
283 else if (it->cache == mfc6_cache_array) 284 else if (it->cache == net->ipv6.mfc6_cache_array)
284 read_unlock(&mrt_lock); 285 read_unlock(&mrt_lock);
285} 286}
286 287
287static int ipmr_mfc_seq_show(struct seq_file *seq, void *v) 288static int ipmr_mfc_seq_show(struct seq_file *seq, void *v)
288{ 289{
289 int n; 290 int n;
291 struct net *net = seq_file_net(seq);
290 292
291 if (v == SEQ_START_TOKEN) { 293 if (v == SEQ_START_TOKEN) {
292 seq_puts(seq, 294 seq_puts(seq,
@@ -297,23 +299,28 @@ static int ipmr_mfc_seq_show(struct seq_file *seq, void *v)
297 const struct mfc6_cache *mfc = v; 299 const struct mfc6_cache *mfc = v;
298 const struct ipmr_mfc_iter *it = seq->private; 300 const struct ipmr_mfc_iter *it = seq->private;
299 301
300 seq_printf(seq, 302 seq_printf(seq, "%pI6 %pI6 %-3hd",
301 NIP6_FMT " " NIP6_FMT " %-3d %8ld %8ld %8ld", 303 &mfc->mf6c_mcastgrp, &mfc->mf6c_origin,
302 NIP6(mfc->mf6c_mcastgrp), NIP6(mfc->mf6c_origin), 304 mfc->mf6c_parent);
303 mfc->mf6c_parent,
304 mfc->mfc_un.res.pkt,
305 mfc->mfc_un.res.bytes,
306 mfc->mfc_un.res.wrong_if);
307 305
308 if (it->cache != &mfc_unres_queue) { 306 if (it->cache != &mfc_unres_queue) {
307 seq_printf(seq, " %8lu %8lu %8lu",
308 mfc->mfc_un.res.pkt,
309 mfc->mfc_un.res.bytes,
310 mfc->mfc_un.res.wrong_if);
309 for (n = mfc->mfc_un.res.minvif; 311 for (n = mfc->mfc_un.res.minvif;
310 n < mfc->mfc_un.res.maxvif; n++) { 312 n < mfc->mfc_un.res.maxvif; n++) {
311 if (MIF_EXISTS(n) && 313 if (MIF_EXISTS(net, n) &&
312 mfc->mfc_un.res.ttls[n] < 255) 314 mfc->mfc_un.res.ttls[n] < 255)
313 seq_printf(seq, 315 seq_printf(seq,
314 " %2d:%-3d", 316 " %2d:%-3d",
315 n, mfc->mfc_un.res.ttls[n]); 317 n, mfc->mfc_un.res.ttls[n]);
316 } 318 }
319 } else {
320 /* unresolved mfc_caches don't contain
321 * pkt, bytes and wrong_if values
322 */
323 seq_printf(seq, " %8lu %8lu %8lu", 0ul, 0ul, 0ul);
317 } 324 }
318 seq_putc(seq, '\n'); 325 seq_putc(seq, '\n');
319 } 326 }
@@ -329,8 +336,8 @@ static struct seq_operations ipmr_mfc_seq_ops = {
329 336
330static int ipmr_mfc_open(struct inode *inode, struct file *file) 337static int ipmr_mfc_open(struct inode *inode, struct file *file)
331{ 338{
332 return seq_open_private(file, &ipmr_mfc_seq_ops, 339 return seq_open_net(inode, file, &ipmr_mfc_seq_ops,
333 sizeof(struct ipmr_mfc_iter)); 340 sizeof(struct ipmr_mfc_iter));
334} 341}
335 342
336static struct file_operations ip6mr_mfc_fops = { 343static struct file_operations ip6mr_mfc_fops = {
@@ -338,18 +345,19 @@ static struct file_operations ip6mr_mfc_fops = {
338 .open = ipmr_mfc_open, 345 .open = ipmr_mfc_open,
339 .read = seq_read, 346 .read = seq_read,
340 .llseek = seq_lseek, 347 .llseek = seq_lseek,
341 .release = seq_release_private, 348 .release = seq_release_net,
342}; 349};
343#endif 350#endif
344 351
345#ifdef CONFIG_IPV6_PIMSM_V2 352#ifdef CONFIG_IPV6_PIMSM_V2
346static int reg_vif_num = -1;
347 353
348static int pim6_rcv(struct sk_buff *skb) 354static int pim6_rcv(struct sk_buff *skb)
349{ 355{
350 struct pimreghdr *pim; 356 struct pimreghdr *pim;
351 struct ipv6hdr *encap; 357 struct ipv6hdr *encap;
352 struct net_device *reg_dev = NULL; 358 struct net_device *reg_dev = NULL;
359 struct net *net = dev_net(skb->dev);
360 int reg_vif_num = net->ipv6.mroute_reg_vif_num;
353 361
354 if (!pskb_may_pull(skb, sizeof(*pim) + sizeof(*encap))) 362 if (!pskb_may_pull(skb, sizeof(*pim) + sizeof(*encap)))
355 goto drop; 363 goto drop;
@@ -372,7 +380,7 @@ static int pim6_rcv(struct sk_buff *skb)
372 380
373 read_lock(&mrt_lock); 381 read_lock(&mrt_lock);
374 if (reg_vif_num >= 0) 382 if (reg_vif_num >= 0)
375 reg_dev = vif6_table[reg_vif_num].dev; 383 reg_dev = net->ipv6.vif6_table[reg_vif_num].dev;
376 if (reg_dev) 384 if (reg_dev)
377 dev_hold(reg_dev); 385 dev_hold(reg_dev);
378 read_unlock(&mrt_lock); 386 read_unlock(&mrt_lock);
@@ -408,25 +416,32 @@ static struct inet6_protocol pim6_protocol = {
408 416
409static int reg_vif_xmit(struct sk_buff *skb, struct net_device *dev) 417static int reg_vif_xmit(struct sk_buff *skb, struct net_device *dev)
410{ 418{
419 struct net *net = dev_net(dev);
420
411 read_lock(&mrt_lock); 421 read_lock(&mrt_lock);
412 dev->stats.tx_bytes += skb->len; 422 dev->stats.tx_bytes += skb->len;
413 dev->stats.tx_packets++; 423 dev->stats.tx_packets++;
414 ip6mr_cache_report(skb, reg_vif_num, MRT6MSG_WHOLEPKT); 424 ip6mr_cache_report(net, skb, net->ipv6.mroute_reg_vif_num,
425 MRT6MSG_WHOLEPKT);
415 read_unlock(&mrt_lock); 426 read_unlock(&mrt_lock);
416 kfree_skb(skb); 427 kfree_skb(skb);
417 return 0; 428 return 0;
418} 429}
419 430
431static const struct net_device_ops reg_vif_netdev_ops = {
432 .ndo_start_xmit = reg_vif_xmit,
433};
434
420static void reg_vif_setup(struct net_device *dev) 435static void reg_vif_setup(struct net_device *dev)
421{ 436{
422 dev->type = ARPHRD_PIMREG; 437 dev->type = ARPHRD_PIMREG;
423 dev->mtu = 1500 - sizeof(struct ipv6hdr) - 8; 438 dev->mtu = 1500 - sizeof(struct ipv6hdr) - 8;
424 dev->flags = IFF_NOARP; 439 dev->flags = IFF_NOARP;
425 dev->hard_start_xmit = reg_vif_xmit; 440 dev->netdev_ops = &reg_vif_netdev_ops;
426 dev->destructor = free_netdev; 441 dev->destructor = free_netdev;
427} 442}
428 443
429static struct net_device *ip6mr_reg_vif(void) 444static struct net_device *ip6mr_reg_vif(struct net *net)
430{ 445{
431 struct net_device *dev; 446 struct net_device *dev;
432 447
@@ -434,6 +449,8 @@ static struct net_device *ip6mr_reg_vif(void)
434 if (dev == NULL) 449 if (dev == NULL)
435 return NULL; 450 return NULL;
436 451
452 dev_net_set(dev, net);
453
437 if (register_netdevice(dev)) { 454 if (register_netdevice(dev)) {
438 free_netdev(dev); 455 free_netdev(dev);
439 return NULL; 456 return NULL;
@@ -460,14 +477,14 @@ failure:
460 * Delete a VIF entry 477 * Delete a VIF entry
461 */ 478 */
462 479
463static int mif6_delete(int vifi) 480static int mif6_delete(struct net *net, int vifi)
464{ 481{
465 struct mif_device *v; 482 struct mif_device *v;
466 struct net_device *dev; 483 struct net_device *dev;
467 if (vifi < 0 || vifi >= maxvif) 484 if (vifi < 0 || vifi >= net->ipv6.maxvif)
468 return -EADDRNOTAVAIL; 485 return -EADDRNOTAVAIL;
469 486
470 v = &vif6_table[vifi]; 487 v = &net->ipv6.vif6_table[vifi];
471 488
472 write_lock_bh(&mrt_lock); 489 write_lock_bh(&mrt_lock);
473 dev = v->dev; 490 dev = v->dev;
@@ -479,17 +496,17 @@ static int mif6_delete(int vifi)
479 } 496 }
480 497
481#ifdef CONFIG_IPV6_PIMSM_V2 498#ifdef CONFIG_IPV6_PIMSM_V2
482 if (vifi == reg_vif_num) 499 if (vifi == net->ipv6.mroute_reg_vif_num)
483 reg_vif_num = -1; 500 net->ipv6.mroute_reg_vif_num = -1;
484#endif 501#endif
485 502
486 if (vifi + 1 == maxvif) { 503 if (vifi + 1 == net->ipv6.maxvif) {
487 int tmp; 504 int tmp;
488 for (tmp = vifi - 1; tmp >= 0; tmp--) { 505 for (tmp = vifi - 1; tmp >= 0; tmp--) {
489 if (MIF_EXISTS(tmp)) 506 if (MIF_EXISTS(net, tmp))
490 break; 507 break;
491 } 508 }
492 maxvif = tmp + 1; 509 net->ipv6.maxvif = tmp + 1;
493 } 510 }
494 511
495 write_unlock_bh(&mrt_lock); 512 write_unlock_bh(&mrt_lock);
@@ -503,6 +520,12 @@ static int mif6_delete(int vifi)
503 return 0; 520 return 0;
504} 521}
505 522
523static inline void ip6mr_cache_free(struct mfc6_cache *c)
524{
525 release_net(mfc6_net(c));
526 kmem_cache_free(mrt_cachep, c);
527}
528
506/* Destroy an unresolved cache entry, killing queued skbs 529/* Destroy an unresolved cache entry, killing queued skbs
507 and reporting error to netlink readers. 530 and reporting error to netlink readers.
508 */ 531 */
@@ -510,8 +533,9 @@ static int mif6_delete(int vifi)
510static void ip6mr_destroy_unres(struct mfc6_cache *c) 533static void ip6mr_destroy_unres(struct mfc6_cache *c)
511{ 534{
512 struct sk_buff *skb; 535 struct sk_buff *skb;
536 struct net *net = mfc6_net(c);
513 537
514 atomic_dec(&cache_resolve_queue_len); 538 atomic_dec(&net->ipv6.cache_resolve_queue_len);
515 539
516 while((skb = skb_dequeue(&c->mfc_un.unres.unresolved)) != NULL) { 540 while((skb = skb_dequeue(&c->mfc_un.unres.unresolved)) != NULL) {
517 if (ipv6_hdr(skb)->version == 0) { 541 if (ipv6_hdr(skb)->version == 0) {
@@ -520,12 +544,12 @@ static void ip6mr_destroy_unres(struct mfc6_cache *c)
520 nlh->nlmsg_len = NLMSG_LENGTH(sizeof(struct nlmsgerr)); 544 nlh->nlmsg_len = NLMSG_LENGTH(sizeof(struct nlmsgerr));
521 skb_trim(skb, nlh->nlmsg_len); 545 skb_trim(skb, nlh->nlmsg_len);
522 ((struct nlmsgerr *)NLMSG_DATA(nlh))->error = -ETIMEDOUT; 546 ((struct nlmsgerr *)NLMSG_DATA(nlh))->error = -ETIMEDOUT;
523 rtnl_unicast(skb, &init_net, NETLINK_CB(skb).pid); 547 rtnl_unicast(skb, net, NETLINK_CB(skb).pid);
524 } else 548 } else
525 kfree_skb(skb); 549 kfree_skb(skb);
526 } 550 }
527 551
528 kmem_cache_free(mrt_cachep, c); 552 ip6mr_cache_free(c);
529} 553}
530 554
531 555
@@ -553,7 +577,7 @@ static void ipmr_do_expire_process(unsigned long dummy)
553 ip6mr_destroy_unres(c); 577 ip6mr_destroy_unres(c);
554 } 578 }
555 579
556 if (atomic_read(&cache_resolve_queue_len)) 580 if (mfc_unres_queue != NULL)
557 mod_timer(&ipmr_expire_timer, jiffies + expires); 581 mod_timer(&ipmr_expire_timer, jiffies + expires);
558} 582}
559 583
@@ -564,7 +588,7 @@ static void ipmr_expire_process(unsigned long dummy)
564 return; 588 return;
565 } 589 }
566 590
567 if (atomic_read(&cache_resolve_queue_len)) 591 if (mfc_unres_queue != NULL)
568 ipmr_do_expire_process(dummy); 592 ipmr_do_expire_process(dummy);
569 593
570 spin_unlock(&mfc_unres_lock); 594 spin_unlock(&mfc_unres_lock);
@@ -575,13 +599,15 @@ static void ipmr_expire_process(unsigned long dummy)
575static void ip6mr_update_thresholds(struct mfc6_cache *cache, unsigned char *ttls) 599static void ip6mr_update_thresholds(struct mfc6_cache *cache, unsigned char *ttls)
576{ 600{
577 int vifi; 601 int vifi;
602 struct net *net = mfc6_net(cache);
578 603
579 cache->mfc_un.res.minvif = MAXMIFS; 604 cache->mfc_un.res.minvif = MAXMIFS;
580 cache->mfc_un.res.maxvif = 0; 605 cache->mfc_un.res.maxvif = 0;
581 memset(cache->mfc_un.res.ttls, 255, MAXMIFS); 606 memset(cache->mfc_un.res.ttls, 255, MAXMIFS);
582 607
583 for (vifi = 0; vifi < maxvif; vifi++) { 608 for (vifi = 0; vifi < net->ipv6.maxvif; vifi++) {
584 if (MIF_EXISTS(vifi) && ttls[vifi] && ttls[vifi] < 255) { 609 if (MIF_EXISTS(net, vifi) &&
610 ttls[vifi] && ttls[vifi] < 255) {
585 cache->mfc_un.res.ttls[vifi] = ttls[vifi]; 611 cache->mfc_un.res.ttls[vifi] = ttls[vifi];
586 if (cache->mfc_un.res.minvif > vifi) 612 if (cache->mfc_un.res.minvif > vifi)
587 cache->mfc_un.res.minvif = vifi; 613 cache->mfc_un.res.minvif = vifi;
@@ -591,15 +617,15 @@ static void ip6mr_update_thresholds(struct mfc6_cache *cache, unsigned char *ttl
591 } 617 }
592} 618}
593 619
594static int mif6_add(struct mif6ctl *vifc, int mrtsock) 620static int mif6_add(struct net *net, struct mif6ctl *vifc, int mrtsock)
595{ 621{
596 int vifi = vifc->mif6c_mifi; 622 int vifi = vifc->mif6c_mifi;
597 struct mif_device *v = &vif6_table[vifi]; 623 struct mif_device *v = &net->ipv6.vif6_table[vifi];
598 struct net_device *dev; 624 struct net_device *dev;
599 int err; 625 int err;
600 626
601 /* Is vif busy ? */ 627 /* Is vif busy ? */
602 if (MIF_EXISTS(vifi)) 628 if (MIF_EXISTS(net, vifi))
603 return -EADDRINUSE; 629 return -EADDRINUSE;
604 630
605 switch (vifc->mif6c_flags) { 631 switch (vifc->mif6c_flags) {
@@ -609,9 +635,9 @@ static int mif6_add(struct mif6ctl *vifc, int mrtsock)
609 * Special Purpose VIF in PIM 635 * Special Purpose VIF in PIM
610 * All the packets will be sent to the daemon 636 * All the packets will be sent to the daemon
611 */ 637 */
612 if (reg_vif_num >= 0) 638 if (net->ipv6.mroute_reg_vif_num >= 0)
613 return -EADDRINUSE; 639 return -EADDRINUSE;
614 dev = ip6mr_reg_vif(); 640 dev = ip6mr_reg_vif(net);
615 if (!dev) 641 if (!dev)
616 return -ENOBUFS; 642 return -ENOBUFS;
617 err = dev_set_allmulti(dev, 1); 643 err = dev_set_allmulti(dev, 1);
@@ -623,7 +649,7 @@ static int mif6_add(struct mif6ctl *vifc, int mrtsock)
623 break; 649 break;
624#endif 650#endif
625 case 0: 651 case 0:
626 dev = dev_get_by_index(&init_net, vifc->mif6c_pifi); 652 dev = dev_get_by_index(net, vifc->mif6c_pifi);
627 if (!dev) 653 if (!dev)
628 return -EADDRNOTAVAIL; 654 return -EADDRNOTAVAIL;
629 err = dev_set_allmulti(dev, 1); 655 err = dev_set_allmulti(dev, 1);
@@ -657,20 +683,22 @@ static int mif6_add(struct mif6ctl *vifc, int mrtsock)
657 v->dev = dev; 683 v->dev = dev;
658#ifdef CONFIG_IPV6_PIMSM_V2 684#ifdef CONFIG_IPV6_PIMSM_V2
659 if (v->flags & MIFF_REGISTER) 685 if (v->flags & MIFF_REGISTER)
660 reg_vif_num = vifi; 686 net->ipv6.mroute_reg_vif_num = vifi;
661#endif 687#endif
662 if (vifi + 1 > maxvif) 688 if (vifi + 1 > net->ipv6.maxvif)
663 maxvif = vifi + 1; 689 net->ipv6.maxvif = vifi + 1;
664 write_unlock_bh(&mrt_lock); 690 write_unlock_bh(&mrt_lock);
665 return 0; 691 return 0;
666} 692}
667 693
668static struct mfc6_cache *ip6mr_cache_find(struct in6_addr *origin, struct in6_addr *mcastgrp) 694static struct mfc6_cache *ip6mr_cache_find(struct net *net,
695 struct in6_addr *origin,
696 struct in6_addr *mcastgrp)
669{ 697{
670 int line = MFC6_HASH(mcastgrp, origin); 698 int line = MFC6_HASH(mcastgrp, origin);
671 struct mfc6_cache *c; 699 struct mfc6_cache *c;
672 700
673 for (c = mfc6_cache_array[line]; c; c = c->next) { 701 for (c = net->ipv6.mfc6_cache_array[line]; c; c = c->next) {
674 if (ipv6_addr_equal(&c->mf6c_origin, origin) && 702 if (ipv6_addr_equal(&c->mf6c_origin, origin) &&
675 ipv6_addr_equal(&c->mf6c_mcastgrp, mcastgrp)) 703 ipv6_addr_equal(&c->mf6c_mcastgrp, mcastgrp))
676 break; 704 break;
@@ -681,24 +709,24 @@ static struct mfc6_cache *ip6mr_cache_find(struct in6_addr *origin, struct in6_a
681/* 709/*
682 * Allocate a multicast cache entry 710 * Allocate a multicast cache entry
683 */ 711 */
684static struct mfc6_cache *ip6mr_cache_alloc(void) 712static struct mfc6_cache *ip6mr_cache_alloc(struct net *net)
685{ 713{
686 struct mfc6_cache *c = kmem_cache_alloc(mrt_cachep, GFP_KERNEL); 714 struct mfc6_cache *c = kmem_cache_zalloc(mrt_cachep, GFP_KERNEL);
687 if (c == NULL) 715 if (c == NULL)
688 return NULL; 716 return NULL;
689 memset(c, 0, sizeof(*c));
690 c->mfc_un.res.minvif = MAXMIFS; 717 c->mfc_un.res.minvif = MAXMIFS;
718 mfc6_net_set(c, net);
691 return c; 719 return c;
692} 720}
693 721
694static struct mfc6_cache *ip6mr_cache_alloc_unres(void) 722static struct mfc6_cache *ip6mr_cache_alloc_unres(struct net *net)
695{ 723{
696 struct mfc6_cache *c = kmem_cache_alloc(mrt_cachep, GFP_ATOMIC); 724 struct mfc6_cache *c = kmem_cache_zalloc(mrt_cachep, GFP_ATOMIC);
697 if (c == NULL) 725 if (c == NULL)
698 return NULL; 726 return NULL;
699 memset(c, 0, sizeof(*c));
700 skb_queue_head_init(&c->mfc_un.unres.unresolved); 727 skb_queue_head_init(&c->mfc_un.unres.unresolved);
701 c->mfc_un.unres.expires = jiffies + 10 * HZ; 728 c->mfc_un.unres.expires = jiffies + 10 * HZ;
729 mfc6_net_set(c, net);
702 return c; 730 return c;
703} 731}
704 732
@@ -727,7 +755,7 @@ static void ip6mr_cache_resolve(struct mfc6_cache *uc, struct mfc6_cache *c)
727 skb_trim(skb, nlh->nlmsg_len); 755 skb_trim(skb, nlh->nlmsg_len);
728 ((struct nlmsgerr *)NLMSG_DATA(nlh))->error = -EMSGSIZE; 756 ((struct nlmsgerr *)NLMSG_DATA(nlh))->error = -EMSGSIZE;
729 } 757 }
730 err = rtnl_unicast(skb, &init_net, NETLINK_CB(skb).pid); 758 err = rtnl_unicast(skb, mfc6_net(uc), NETLINK_CB(skb).pid);
731 } else 759 } else
732 ip6_mr_forward(skb, c); 760 ip6_mr_forward(skb, c);
733 } 761 }
@@ -740,7 +768,8 @@ static void ip6mr_cache_resolve(struct mfc6_cache *uc, struct mfc6_cache *c)
740 * Called under mrt_lock. 768 * Called under mrt_lock.
741 */ 769 */
742 770
743static int ip6mr_cache_report(struct sk_buff *pkt, mifi_t mifi, int assert) 771static int ip6mr_cache_report(struct net *net, struct sk_buff *pkt, mifi_t mifi,
772 int assert)
744{ 773{
745 struct sk_buff *skb; 774 struct sk_buff *skb;
746 struct mrt6msg *msg; 775 struct mrt6msg *msg;
@@ -776,7 +805,7 @@ static int ip6mr_cache_report(struct sk_buff *pkt, mifi_t mifi, int assert)
776 msg = (struct mrt6msg *)skb_transport_header(skb); 805 msg = (struct mrt6msg *)skb_transport_header(skb);
777 msg->im6_mbz = 0; 806 msg->im6_mbz = 0;
778 msg->im6_msgtype = MRT6MSG_WHOLEPKT; 807 msg->im6_msgtype = MRT6MSG_WHOLEPKT;
779 msg->im6_mif = reg_vif_num; 808 msg->im6_mif = net->ipv6.mroute_reg_vif_num;
780 msg->im6_pad = 0; 809 msg->im6_pad = 0;
781 ipv6_addr_copy(&msg->im6_src, &ipv6_hdr(pkt)->saddr); 810 ipv6_addr_copy(&msg->im6_src, &ipv6_hdr(pkt)->saddr);
782 ipv6_addr_copy(&msg->im6_dst, &ipv6_hdr(pkt)->daddr); 811 ipv6_addr_copy(&msg->im6_dst, &ipv6_hdr(pkt)->daddr);
@@ -813,7 +842,7 @@ static int ip6mr_cache_report(struct sk_buff *pkt, mifi_t mifi, int assert)
813 skb_pull(skb, sizeof(struct ipv6hdr)); 842 skb_pull(skb, sizeof(struct ipv6hdr));
814 } 843 }
815 844
816 if (mroute6_socket == NULL) { 845 if (net->ipv6.mroute6_sk == NULL) {
817 kfree_skb(skb); 846 kfree_skb(skb);
818 return -EINVAL; 847 return -EINVAL;
819 } 848 }
@@ -821,7 +850,8 @@ static int ip6mr_cache_report(struct sk_buff *pkt, mifi_t mifi, int assert)
821 /* 850 /*
822 * Deliver to user space multicast routing algorithms 851 * Deliver to user space multicast routing algorithms
823 */ 852 */
824 if ((ret = sock_queue_rcv_skb(mroute6_socket, skb)) < 0) { 853 ret = sock_queue_rcv_skb(net->ipv6.mroute6_sk, skb);
854 if (ret < 0) {
825 if (net_ratelimit()) 855 if (net_ratelimit())
826 printk(KERN_WARNING "mroute6: pending queue full, dropping entries.\n"); 856 printk(KERN_WARNING "mroute6: pending queue full, dropping entries.\n");
827 kfree_skb(skb); 857 kfree_skb(skb);
@@ -835,14 +865,15 @@ static int ip6mr_cache_report(struct sk_buff *pkt, mifi_t mifi, int assert)
835 */ 865 */
836 866
837static int 867static int
838ip6mr_cache_unresolved(mifi_t mifi, struct sk_buff *skb) 868ip6mr_cache_unresolved(struct net *net, mifi_t mifi, struct sk_buff *skb)
839{ 869{
840 int err; 870 int err;
841 struct mfc6_cache *c; 871 struct mfc6_cache *c;
842 872
843 spin_lock_bh(&mfc_unres_lock); 873 spin_lock_bh(&mfc_unres_lock);
844 for (c = mfc_unres_queue; c; c = c->next) { 874 for (c = mfc_unres_queue; c; c = c->next) {
845 if (ipv6_addr_equal(&c->mf6c_mcastgrp, &ipv6_hdr(skb)->daddr) && 875 if (net_eq(mfc6_net(c), net) &&
876 ipv6_addr_equal(&c->mf6c_mcastgrp, &ipv6_hdr(skb)->daddr) &&
846 ipv6_addr_equal(&c->mf6c_origin, &ipv6_hdr(skb)->saddr)) 877 ipv6_addr_equal(&c->mf6c_origin, &ipv6_hdr(skb)->saddr))
847 break; 878 break;
848 } 879 }
@@ -852,8 +883,8 @@ ip6mr_cache_unresolved(mifi_t mifi, struct sk_buff *skb)
852 * Create a new entry if allowable 883 * Create a new entry if allowable
853 */ 884 */
854 885
855 if (atomic_read(&cache_resolve_queue_len) >= 10 || 886 if (atomic_read(&net->ipv6.cache_resolve_queue_len) >= 10 ||
856 (c = ip6mr_cache_alloc_unres()) == NULL) { 887 (c = ip6mr_cache_alloc_unres(net)) == NULL) {
857 spin_unlock_bh(&mfc_unres_lock); 888 spin_unlock_bh(&mfc_unres_lock);
858 889
859 kfree_skb(skb); 890 kfree_skb(skb);
@@ -870,18 +901,19 @@ ip6mr_cache_unresolved(mifi_t mifi, struct sk_buff *skb)
870 /* 901 /*
871 * Reflect first query at pim6sd 902 * Reflect first query at pim6sd
872 */ 903 */
873 if ((err = ip6mr_cache_report(skb, mifi, MRT6MSG_NOCACHE)) < 0) { 904 err = ip6mr_cache_report(net, skb, mifi, MRT6MSG_NOCACHE);
905 if (err < 0) {
874 /* If the report failed throw the cache entry 906 /* If the report failed throw the cache entry
875 out - Brad Parker 907 out - Brad Parker
876 */ 908 */
877 spin_unlock_bh(&mfc_unres_lock); 909 spin_unlock_bh(&mfc_unres_lock);
878 910
879 kmem_cache_free(mrt_cachep, c); 911 ip6mr_cache_free(c);
880 kfree_skb(skb); 912 kfree_skb(skb);
881 return err; 913 return err;
882 } 914 }
883 915
884 atomic_inc(&cache_resolve_queue_len); 916 atomic_inc(&net->ipv6.cache_resolve_queue_len);
885 c->next = mfc_unres_queue; 917 c->next = mfc_unres_queue;
886 mfc_unres_queue = c; 918 mfc_unres_queue = c;
887 919
@@ -907,21 +939,22 @@ ip6mr_cache_unresolved(mifi_t mifi, struct sk_buff *skb)
907 * MFC6 cache manipulation by user space 939 * MFC6 cache manipulation by user space
908 */ 940 */
909 941
910static int ip6mr_mfc_delete(struct mf6cctl *mfc) 942static int ip6mr_mfc_delete(struct net *net, struct mf6cctl *mfc)
911{ 943{
912 int line; 944 int line;
913 struct mfc6_cache *c, **cp; 945 struct mfc6_cache *c, **cp;
914 946
915 line = MFC6_HASH(&mfc->mf6cc_mcastgrp.sin6_addr, &mfc->mf6cc_origin.sin6_addr); 947 line = MFC6_HASH(&mfc->mf6cc_mcastgrp.sin6_addr, &mfc->mf6cc_origin.sin6_addr);
916 948
917 for (cp = &mfc6_cache_array[line]; (c = *cp) != NULL; cp = &c->next) { 949 for (cp = &net->ipv6.mfc6_cache_array[line];
950 (c = *cp) != NULL; cp = &c->next) {
918 if (ipv6_addr_equal(&c->mf6c_origin, &mfc->mf6cc_origin.sin6_addr) && 951 if (ipv6_addr_equal(&c->mf6c_origin, &mfc->mf6cc_origin.sin6_addr) &&
919 ipv6_addr_equal(&c->mf6c_mcastgrp, &mfc->mf6cc_mcastgrp.sin6_addr)) { 952 ipv6_addr_equal(&c->mf6c_mcastgrp, &mfc->mf6cc_mcastgrp.sin6_addr)) {
920 write_lock_bh(&mrt_lock); 953 write_lock_bh(&mrt_lock);
921 *cp = c->next; 954 *cp = c->next;
922 write_unlock_bh(&mrt_lock); 955 write_unlock_bh(&mrt_lock);
923 956
924 kmem_cache_free(mrt_cachep, c); 957 ip6mr_cache_free(c);
925 return 0; 958 return 0;
926 } 959 }
927 } 960 }
@@ -932,19 +965,17 @@ static int ip6mr_device_event(struct notifier_block *this,
932 unsigned long event, void *ptr) 965 unsigned long event, void *ptr)
933{ 966{
934 struct net_device *dev = ptr; 967 struct net_device *dev = ptr;
968 struct net *net = dev_net(dev);
935 struct mif_device *v; 969 struct mif_device *v;
936 int ct; 970 int ct;
937 971
938 if (!net_eq(dev_net(dev), &init_net))
939 return NOTIFY_DONE;
940
941 if (event != NETDEV_UNREGISTER) 972 if (event != NETDEV_UNREGISTER)
942 return NOTIFY_DONE; 973 return NOTIFY_DONE;
943 974
944 v = &vif6_table[0]; 975 v = &net->ipv6.vif6_table[0];
945 for (ct = 0; ct < maxvif; ct++, v++) { 976 for (ct = 0; ct < net->ipv6.maxvif; ct++, v++) {
946 if (v->dev == dev) 977 if (v->dev == dev)
947 mif6_delete(ct); 978 mif6_delete(net, ct);
948 } 979 }
949 return NOTIFY_DONE; 980 return NOTIFY_DONE;
950} 981}
@@ -957,6 +988,66 @@ static struct notifier_block ip6_mr_notifier = {
957 * Setup for IP multicast routing 988 * Setup for IP multicast routing
958 */ 989 */
959 990
991static int __net_init ip6mr_net_init(struct net *net)
992{
993 int err = 0;
994 net->ipv6.vif6_table = kcalloc(MAXMIFS, sizeof(struct mif_device),
995 GFP_KERNEL);
996 if (!net->ipv6.vif6_table) {
997 err = -ENOMEM;
998 goto fail;
999 }
1000
1001 /* Forwarding cache */
1002 net->ipv6.mfc6_cache_array = kcalloc(MFC6_LINES,
1003 sizeof(struct mfc6_cache *),
1004 GFP_KERNEL);
1005 if (!net->ipv6.mfc6_cache_array) {
1006 err = -ENOMEM;
1007 goto fail_mfc6_cache;
1008 }
1009
1010#ifdef CONFIG_IPV6_PIMSM_V2
1011 net->ipv6.mroute_reg_vif_num = -1;
1012#endif
1013
1014#ifdef CONFIG_PROC_FS
1015 err = -ENOMEM;
1016 if (!proc_net_fops_create(net, "ip6_mr_vif", 0, &ip6mr_vif_fops))
1017 goto proc_vif_fail;
1018 if (!proc_net_fops_create(net, "ip6_mr_cache", 0, &ip6mr_mfc_fops))
1019 goto proc_cache_fail;
1020#endif
1021 return 0;
1022
1023#ifdef CONFIG_PROC_FS
1024proc_cache_fail:
1025 proc_net_remove(net, "ip6_mr_vif");
1026proc_vif_fail:
1027 kfree(net->ipv6.mfc6_cache_array);
1028#endif
1029fail_mfc6_cache:
1030 kfree(net->ipv6.vif6_table);
1031fail:
1032 return err;
1033}
1034
1035static void __net_exit ip6mr_net_exit(struct net *net)
1036{
1037#ifdef CONFIG_PROC_FS
1038 proc_net_remove(net, "ip6_mr_cache");
1039 proc_net_remove(net, "ip6_mr_vif");
1040#endif
1041 mroute_clean_tables(net);
1042 kfree(net->ipv6.mfc6_cache_array);
1043 kfree(net->ipv6.vif6_table);
1044}
1045
1046static struct pernet_operations ip6mr_net_ops = {
1047 .init = ip6mr_net_init,
1048 .exit = ip6mr_net_exit,
1049};
1050
960int __init ip6_mr_init(void) 1051int __init ip6_mr_init(void)
961{ 1052{
962 int err; 1053 int err;
@@ -968,43 +1059,32 @@ int __init ip6_mr_init(void)
968 if (!mrt_cachep) 1059 if (!mrt_cachep)
969 return -ENOMEM; 1060 return -ENOMEM;
970 1061
1062 err = register_pernet_subsys(&ip6mr_net_ops);
1063 if (err)
1064 goto reg_pernet_fail;
1065
971 setup_timer(&ipmr_expire_timer, ipmr_expire_process, 0); 1066 setup_timer(&ipmr_expire_timer, ipmr_expire_process, 0);
972 err = register_netdevice_notifier(&ip6_mr_notifier); 1067 err = register_netdevice_notifier(&ip6_mr_notifier);
973 if (err) 1068 if (err)
974 goto reg_notif_fail; 1069 goto reg_notif_fail;
975#ifdef CONFIG_PROC_FS
976 err = -ENOMEM;
977 if (!proc_net_fops_create(&init_net, "ip6_mr_vif", 0, &ip6mr_vif_fops))
978 goto proc_vif_fail;
979 if (!proc_net_fops_create(&init_net, "ip6_mr_cache",
980 0, &ip6mr_mfc_fops))
981 goto proc_cache_fail;
982#endif
983 return 0; 1070 return 0;
984#ifdef CONFIG_PROC_FS
985proc_cache_fail:
986 proc_net_remove(&init_net, "ip6_mr_vif");
987proc_vif_fail:
988 unregister_netdevice_notifier(&ip6_mr_notifier);
989#endif
990reg_notif_fail: 1071reg_notif_fail:
991 del_timer(&ipmr_expire_timer); 1072 del_timer(&ipmr_expire_timer);
1073 unregister_pernet_subsys(&ip6mr_net_ops);
1074reg_pernet_fail:
992 kmem_cache_destroy(mrt_cachep); 1075 kmem_cache_destroy(mrt_cachep);
993 return err; 1076 return err;
994} 1077}
995 1078
996void ip6_mr_cleanup(void) 1079void ip6_mr_cleanup(void)
997{ 1080{
998#ifdef CONFIG_PROC_FS
999 proc_net_remove(&init_net, "ip6_mr_cache");
1000 proc_net_remove(&init_net, "ip6_mr_vif");
1001#endif
1002 unregister_netdevice_notifier(&ip6_mr_notifier); 1081 unregister_netdevice_notifier(&ip6_mr_notifier);
1003 del_timer(&ipmr_expire_timer); 1082 del_timer(&ipmr_expire_timer);
1083 unregister_pernet_subsys(&ip6mr_net_ops);
1004 kmem_cache_destroy(mrt_cachep); 1084 kmem_cache_destroy(mrt_cachep);
1005} 1085}
1006 1086
1007static int ip6mr_mfc_add(struct mf6cctl *mfc, int mrtsock) 1087static int ip6mr_mfc_add(struct net *net, struct mf6cctl *mfc, int mrtsock)
1008{ 1088{
1009 int line; 1089 int line;
1010 struct mfc6_cache *uc, *c, **cp; 1090 struct mfc6_cache *uc, *c, **cp;
@@ -1020,7 +1100,8 @@ static int ip6mr_mfc_add(struct mf6cctl *mfc, int mrtsock)
1020 1100
1021 line = MFC6_HASH(&mfc->mf6cc_mcastgrp.sin6_addr, &mfc->mf6cc_origin.sin6_addr); 1101 line = MFC6_HASH(&mfc->mf6cc_mcastgrp.sin6_addr, &mfc->mf6cc_origin.sin6_addr);
1022 1102
1023 for (cp = &mfc6_cache_array[line]; (c = *cp) != NULL; cp = &c->next) { 1103 for (cp = &net->ipv6.mfc6_cache_array[line];
1104 (c = *cp) != NULL; cp = &c->next) {
1024 if (ipv6_addr_equal(&c->mf6c_origin, &mfc->mf6cc_origin.sin6_addr) && 1105 if (ipv6_addr_equal(&c->mf6c_origin, &mfc->mf6cc_origin.sin6_addr) &&
1025 ipv6_addr_equal(&c->mf6c_mcastgrp, &mfc->mf6cc_mcastgrp.sin6_addr)) 1106 ipv6_addr_equal(&c->mf6c_mcastgrp, &mfc->mf6cc_mcastgrp.sin6_addr))
1026 break; 1107 break;
@@ -1039,7 +1120,7 @@ static int ip6mr_mfc_add(struct mf6cctl *mfc, int mrtsock)
1039 if (!ipv6_addr_is_multicast(&mfc->mf6cc_mcastgrp.sin6_addr)) 1120 if (!ipv6_addr_is_multicast(&mfc->mf6cc_mcastgrp.sin6_addr))
1040 return -EINVAL; 1121 return -EINVAL;
1041 1122
1042 c = ip6mr_cache_alloc(); 1123 c = ip6mr_cache_alloc(net);
1043 if (c == NULL) 1124 if (c == NULL)
1044 return -ENOMEM; 1125 return -ENOMEM;
1045 1126
@@ -1051,8 +1132,8 @@ static int ip6mr_mfc_add(struct mf6cctl *mfc, int mrtsock)
1051 c->mfc_flags |= MFC_STATIC; 1132 c->mfc_flags |= MFC_STATIC;
1052 1133
1053 write_lock_bh(&mrt_lock); 1134 write_lock_bh(&mrt_lock);
1054 c->next = mfc6_cache_array[line]; 1135 c->next = net->ipv6.mfc6_cache_array[line];
1055 mfc6_cache_array[line] = c; 1136 net->ipv6.mfc6_cache_array[line] = c;
1056 write_unlock_bh(&mrt_lock); 1137 write_unlock_bh(&mrt_lock);
1057 1138
1058 /* 1139 /*
@@ -1062,19 +1143,21 @@ static int ip6mr_mfc_add(struct mf6cctl *mfc, int mrtsock)
1062 spin_lock_bh(&mfc_unres_lock); 1143 spin_lock_bh(&mfc_unres_lock);
1063 for (cp = &mfc_unres_queue; (uc = *cp) != NULL; 1144 for (cp = &mfc_unres_queue; (uc = *cp) != NULL;
1064 cp = &uc->next) { 1145 cp = &uc->next) {
1065 if (ipv6_addr_equal(&uc->mf6c_origin, &c->mf6c_origin) && 1146 if (net_eq(mfc6_net(uc), net) &&
1147 ipv6_addr_equal(&uc->mf6c_origin, &c->mf6c_origin) &&
1066 ipv6_addr_equal(&uc->mf6c_mcastgrp, &c->mf6c_mcastgrp)) { 1148 ipv6_addr_equal(&uc->mf6c_mcastgrp, &c->mf6c_mcastgrp)) {
1067 *cp = uc->next; 1149 *cp = uc->next;
1068 if (atomic_dec_and_test(&cache_resolve_queue_len)) 1150 atomic_dec(&net->ipv6.cache_resolve_queue_len);
1069 del_timer(&ipmr_expire_timer);
1070 break; 1151 break;
1071 } 1152 }
1072 } 1153 }
1154 if (mfc_unres_queue == NULL)
1155 del_timer(&ipmr_expire_timer);
1073 spin_unlock_bh(&mfc_unres_lock); 1156 spin_unlock_bh(&mfc_unres_lock);
1074 1157
1075 if (uc) { 1158 if (uc) {
1076 ip6mr_cache_resolve(uc, c); 1159 ip6mr_cache_resolve(uc, c);
1077 kmem_cache_free(mrt_cachep, uc); 1160 ip6mr_cache_free(uc);
1078 } 1161 }
1079 return 0; 1162 return 0;
1080} 1163}
@@ -1083,25 +1166,25 @@ static int ip6mr_mfc_add(struct mf6cctl *mfc, int mrtsock)
1083 * Close the multicast socket, and clear the vif tables etc 1166 * Close the multicast socket, and clear the vif tables etc
1084 */ 1167 */
1085 1168
1086static void mroute_clean_tables(struct sock *sk) 1169static void mroute_clean_tables(struct net *net)
1087{ 1170{
1088 int i; 1171 int i;
1089 1172
1090 /* 1173 /*
1091 * Shut down all active vif entries 1174 * Shut down all active vif entries
1092 */ 1175 */
1093 for (i = 0; i < maxvif; i++) { 1176 for (i = 0; i < net->ipv6.maxvif; i++) {
1094 if (!(vif6_table[i].flags & VIFF_STATIC)) 1177 if (!(net->ipv6.vif6_table[i].flags & VIFF_STATIC))
1095 mif6_delete(i); 1178 mif6_delete(net, i);
1096 } 1179 }
1097 1180
1098 /* 1181 /*
1099 * Wipe the cache 1182 * Wipe the cache
1100 */ 1183 */
1101 for (i = 0; i < ARRAY_SIZE(mfc6_cache_array); i++) { 1184 for (i = 0; i < MFC6_LINES; i++) {
1102 struct mfc6_cache *c, **cp; 1185 struct mfc6_cache *c, **cp;
1103 1186
1104 cp = &mfc6_cache_array[i]; 1187 cp = &net->ipv6.mfc6_cache_array[i];
1105 while ((c = *cp) != NULL) { 1188 while ((c = *cp) != NULL) {
1106 if (c->mfc_flags & MFC_STATIC) { 1189 if (c->mfc_flags & MFC_STATIC) {
1107 cp = &c->next; 1190 cp = &c->next;
@@ -1111,22 +1194,22 @@ static void mroute_clean_tables(struct sock *sk)
1111 *cp = c->next; 1194 *cp = c->next;
1112 write_unlock_bh(&mrt_lock); 1195 write_unlock_bh(&mrt_lock);
1113 1196
1114 kmem_cache_free(mrt_cachep, c); 1197 ip6mr_cache_free(c);
1115 } 1198 }
1116 } 1199 }
1117 1200
1118 if (atomic_read(&cache_resolve_queue_len) != 0) { 1201 if (atomic_read(&net->ipv6.cache_resolve_queue_len) != 0) {
1119 struct mfc6_cache *c; 1202 struct mfc6_cache *c, **cp;
1120 1203
1121 spin_lock_bh(&mfc_unres_lock); 1204 spin_lock_bh(&mfc_unres_lock);
1122 while (mfc_unres_queue != NULL) { 1205 cp = &mfc_unres_queue;
1123 c = mfc_unres_queue; 1206 while ((c = *cp) != NULL) {
1124 mfc_unres_queue = c->next; 1207 if (!net_eq(mfc6_net(c), net)) {
1125 spin_unlock_bh(&mfc_unres_lock); 1208 cp = &c->next;
1126 1209 continue;
1210 }
1211 *cp = c->next;
1127 ip6mr_destroy_unres(c); 1212 ip6mr_destroy_unres(c);
1128
1129 spin_lock_bh(&mfc_unres_lock);
1130 } 1213 }
1131 spin_unlock_bh(&mfc_unres_lock); 1214 spin_unlock_bh(&mfc_unres_lock);
1132 } 1215 }
@@ -1135,11 +1218,12 @@ static void mroute_clean_tables(struct sock *sk)
1135static int ip6mr_sk_init(struct sock *sk) 1218static int ip6mr_sk_init(struct sock *sk)
1136{ 1219{
1137 int err = 0; 1220 int err = 0;
1221 struct net *net = sock_net(sk);
1138 1222
1139 rtnl_lock(); 1223 rtnl_lock();
1140 write_lock_bh(&mrt_lock); 1224 write_lock_bh(&mrt_lock);
1141 if (likely(mroute6_socket == NULL)) 1225 if (likely(net->ipv6.mroute6_sk == NULL))
1142 mroute6_socket = sk; 1226 net->ipv6.mroute6_sk = sk;
1143 else 1227 else
1144 err = -EADDRINUSE; 1228 err = -EADDRINUSE;
1145 write_unlock_bh(&mrt_lock); 1229 write_unlock_bh(&mrt_lock);
@@ -1152,14 +1236,15 @@ static int ip6mr_sk_init(struct sock *sk)
1152int ip6mr_sk_done(struct sock *sk) 1236int ip6mr_sk_done(struct sock *sk)
1153{ 1237{
1154 int err = 0; 1238 int err = 0;
1239 struct net *net = sock_net(sk);
1155 1240
1156 rtnl_lock(); 1241 rtnl_lock();
1157 if (sk == mroute6_socket) { 1242 if (sk == net->ipv6.mroute6_sk) {
1158 write_lock_bh(&mrt_lock); 1243 write_lock_bh(&mrt_lock);
1159 mroute6_socket = NULL; 1244 net->ipv6.mroute6_sk = NULL;
1160 write_unlock_bh(&mrt_lock); 1245 write_unlock_bh(&mrt_lock);
1161 1246
1162 mroute_clean_tables(sk); 1247 mroute_clean_tables(net);
1163 } else 1248 } else
1164 err = -EACCES; 1249 err = -EACCES;
1165 rtnl_unlock(); 1250 rtnl_unlock();
@@ -1180,9 +1265,10 @@ int ip6_mroute_setsockopt(struct sock *sk, int optname, char __user *optval, int
1180 struct mif6ctl vif; 1265 struct mif6ctl vif;
1181 struct mf6cctl mfc; 1266 struct mf6cctl mfc;
1182 mifi_t mifi; 1267 mifi_t mifi;
1268 struct net *net = sock_net(sk);
1183 1269
1184 if (optname != MRT6_INIT) { 1270 if (optname != MRT6_INIT) {
1185 if (sk != mroute6_socket && !capable(CAP_NET_ADMIN)) 1271 if (sk != net->ipv6.mroute6_sk && !capable(CAP_NET_ADMIN))
1186 return -EACCES; 1272 return -EACCES;
1187 } 1273 }
1188 1274
@@ -1207,7 +1293,7 @@ int ip6_mroute_setsockopt(struct sock *sk, int optname, char __user *optval, int
1207 if (vif.mif6c_mifi >= MAXMIFS) 1293 if (vif.mif6c_mifi >= MAXMIFS)
1208 return -ENFILE; 1294 return -ENFILE;
1209 rtnl_lock(); 1295 rtnl_lock();
1210 ret = mif6_add(&vif, sk == mroute6_socket); 1296 ret = mif6_add(net, &vif, sk == net->ipv6.mroute6_sk);
1211 rtnl_unlock(); 1297 rtnl_unlock();
1212 return ret; 1298 return ret;
1213 1299
@@ -1217,7 +1303,7 @@ int ip6_mroute_setsockopt(struct sock *sk, int optname, char __user *optval, int
1217 if (copy_from_user(&mifi, optval, sizeof(mifi_t))) 1303 if (copy_from_user(&mifi, optval, sizeof(mifi_t)))
1218 return -EFAULT; 1304 return -EFAULT;
1219 rtnl_lock(); 1305 rtnl_lock();
1220 ret = mif6_delete(mifi); 1306 ret = mif6_delete(net, mifi);
1221 rtnl_unlock(); 1307 rtnl_unlock();
1222 return ret; 1308 return ret;
1223 1309
@@ -1233,9 +1319,10 @@ int ip6_mroute_setsockopt(struct sock *sk, int optname, char __user *optval, int
1233 return -EFAULT; 1319 return -EFAULT;
1234 rtnl_lock(); 1320 rtnl_lock();
1235 if (optname == MRT6_DEL_MFC) 1321 if (optname == MRT6_DEL_MFC)
1236 ret = ip6mr_mfc_delete(&mfc); 1322 ret = ip6mr_mfc_delete(net, &mfc);
1237 else 1323 else
1238 ret = ip6mr_mfc_add(&mfc, sk == mroute6_socket); 1324 ret = ip6mr_mfc_add(net, &mfc,
1325 sk == net->ipv6.mroute6_sk);
1239 rtnl_unlock(); 1326 rtnl_unlock();
1240 return ret; 1327 return ret;
1241 1328
@@ -1247,7 +1334,7 @@ int ip6_mroute_setsockopt(struct sock *sk, int optname, char __user *optval, int
1247 int v; 1334 int v;
1248 if (get_user(v, (int __user *)optval)) 1335 if (get_user(v, (int __user *)optval))
1249 return -EFAULT; 1336 return -EFAULT;
1250 mroute_do_assert = !!v; 1337 net->ipv6.mroute_do_assert = !!v;
1251 return 0; 1338 return 0;
1252 } 1339 }
1253 1340
@@ -1260,10 +1347,10 @@ int ip6_mroute_setsockopt(struct sock *sk, int optname, char __user *optval, int
1260 v = !!v; 1347 v = !!v;
1261 rtnl_lock(); 1348 rtnl_lock();
1262 ret = 0; 1349 ret = 0;
1263 if (v != mroute_do_pim) { 1350 if (v != net->ipv6.mroute_do_pim) {
1264 mroute_do_pim = v; 1351 net->ipv6.mroute_do_pim = v;
1265 mroute_do_assert = v; 1352 net->ipv6.mroute_do_assert = v;
1266 if (mroute_do_pim) 1353 if (net->ipv6.mroute_do_pim)
1267 ret = inet6_add_protocol(&pim6_protocol, 1354 ret = inet6_add_protocol(&pim6_protocol,
1268 IPPROTO_PIM); 1355 IPPROTO_PIM);
1269 else 1356 else
@@ -1295,6 +1382,7 @@ int ip6_mroute_getsockopt(struct sock *sk, int optname, char __user *optval,
1295{ 1382{
1296 int olr; 1383 int olr;
1297 int val; 1384 int val;
1385 struct net *net = sock_net(sk);
1298 1386
1299 switch (optname) { 1387 switch (optname) {
1300 case MRT6_VERSION: 1388 case MRT6_VERSION:
@@ -1302,11 +1390,11 @@ int ip6_mroute_getsockopt(struct sock *sk, int optname, char __user *optval,
1302 break; 1390 break;
1303#ifdef CONFIG_IPV6_PIMSM_V2 1391#ifdef CONFIG_IPV6_PIMSM_V2
1304 case MRT6_PIM: 1392 case MRT6_PIM:
1305 val = mroute_do_pim; 1393 val = net->ipv6.mroute_do_pim;
1306 break; 1394 break;
1307#endif 1395#endif
1308 case MRT6_ASSERT: 1396 case MRT6_ASSERT:
1309 val = mroute_do_assert; 1397 val = net->ipv6.mroute_do_assert;
1310 break; 1398 break;
1311 default: 1399 default:
1312 return -ENOPROTOOPT; 1400 return -ENOPROTOOPT;
@@ -1336,16 +1424,17 @@ int ip6mr_ioctl(struct sock *sk, int cmd, void __user *arg)
1336 struct sioc_mif_req6 vr; 1424 struct sioc_mif_req6 vr;
1337 struct mif_device *vif; 1425 struct mif_device *vif;
1338 struct mfc6_cache *c; 1426 struct mfc6_cache *c;
1427 struct net *net = sock_net(sk);
1339 1428
1340 switch (cmd) { 1429 switch (cmd) {
1341 case SIOCGETMIFCNT_IN6: 1430 case SIOCGETMIFCNT_IN6:
1342 if (copy_from_user(&vr, arg, sizeof(vr))) 1431 if (copy_from_user(&vr, arg, sizeof(vr)))
1343 return -EFAULT; 1432 return -EFAULT;
1344 if (vr.mifi >= maxvif) 1433 if (vr.mifi >= net->ipv6.maxvif)
1345 return -EINVAL; 1434 return -EINVAL;
1346 read_lock(&mrt_lock); 1435 read_lock(&mrt_lock);
1347 vif = &vif6_table[vr.mifi]; 1436 vif = &net->ipv6.vif6_table[vr.mifi];
1348 if (MIF_EXISTS(vr.mifi)) { 1437 if (MIF_EXISTS(net, vr.mifi)) {
1349 vr.icount = vif->pkt_in; 1438 vr.icount = vif->pkt_in;
1350 vr.ocount = vif->pkt_out; 1439 vr.ocount = vif->pkt_out;
1351 vr.ibytes = vif->bytes_in; 1440 vr.ibytes = vif->bytes_in;
@@ -1363,7 +1452,7 @@ int ip6mr_ioctl(struct sock *sk, int cmd, void __user *arg)
1363 return -EFAULT; 1452 return -EFAULT;
1364 1453
1365 read_lock(&mrt_lock); 1454 read_lock(&mrt_lock);
1366 c = ip6mr_cache_find(&sr.src.sin6_addr, &sr.grp.sin6_addr); 1455 c = ip6mr_cache_find(net, &sr.src.sin6_addr, &sr.grp.sin6_addr);
1367 if (c) { 1456 if (c) {
1368 sr.pktcnt = c->mfc_un.res.pkt; 1457 sr.pktcnt = c->mfc_un.res.pkt;
1369 sr.bytecnt = c->mfc_un.res.bytes; 1458 sr.bytecnt = c->mfc_un.res.bytes;
@@ -1396,7 +1485,8 @@ static inline int ip6mr_forward2_finish(struct sk_buff *skb)
1396static int ip6mr_forward2(struct sk_buff *skb, struct mfc6_cache *c, int vifi) 1485static int ip6mr_forward2(struct sk_buff *skb, struct mfc6_cache *c, int vifi)
1397{ 1486{
1398 struct ipv6hdr *ipv6h; 1487 struct ipv6hdr *ipv6h;
1399 struct mif_device *vif = &vif6_table[vifi]; 1488 struct net *net = mfc6_net(c);
1489 struct mif_device *vif = &net->ipv6.vif6_table[vifi];
1400 struct net_device *dev; 1490 struct net_device *dev;
1401 struct dst_entry *dst; 1491 struct dst_entry *dst;
1402 struct flowi fl; 1492 struct flowi fl;
@@ -1410,9 +1500,8 @@ static int ip6mr_forward2(struct sk_buff *skb, struct mfc6_cache *c, int vifi)
1410 vif->bytes_out += skb->len; 1500 vif->bytes_out += skb->len;
1411 vif->dev->stats.tx_bytes += skb->len; 1501 vif->dev->stats.tx_bytes += skb->len;
1412 vif->dev->stats.tx_packets++; 1502 vif->dev->stats.tx_packets++;
1413 ip6mr_cache_report(skb, vifi, MRT6MSG_WHOLEPKT); 1503 ip6mr_cache_report(net, skb, vifi, MRT6MSG_WHOLEPKT);
1414 kfree_skb(skb); 1504 goto out_free;
1415 return 0;
1416 } 1505 }
1417#endif 1506#endif
1418 1507
@@ -1425,7 +1514,7 @@ static int ip6mr_forward2(struct sk_buff *skb, struct mfc6_cache *c, int vifi)
1425 } 1514 }
1426 }; 1515 };
1427 1516
1428 dst = ip6_route_output(&init_net, NULL, &fl); 1517 dst = ip6_route_output(net, NULL, &fl);
1429 if (!dst) 1518 if (!dst)
1430 goto out_free; 1519 goto out_free;
1431 1520
@@ -1468,9 +1557,10 @@ out_free:
1468 1557
1469static int ip6mr_find_vif(struct net_device *dev) 1558static int ip6mr_find_vif(struct net_device *dev)
1470{ 1559{
1560 struct net *net = dev_net(dev);
1471 int ct; 1561 int ct;
1472 for (ct = maxvif - 1; ct >= 0; ct--) { 1562 for (ct = net->ipv6.maxvif - 1; ct >= 0; ct--) {
1473 if (vif6_table[ct].dev == dev) 1563 if (net->ipv6.vif6_table[ct].dev == dev)
1474 break; 1564 break;
1475 } 1565 }
1476 return ct; 1566 return ct;
@@ -1480,6 +1570,7 @@ static int ip6_mr_forward(struct sk_buff *skb, struct mfc6_cache *cache)
1480{ 1570{
1481 int psend = -1; 1571 int psend = -1;
1482 int vif, ct; 1572 int vif, ct;
1573 struct net *net = mfc6_net(cache);
1483 1574
1484 vif = cache->mf6c_parent; 1575 vif = cache->mf6c_parent;
1485 cache->mfc_un.res.pkt++; 1576 cache->mfc_un.res.pkt++;
@@ -1488,29 +1579,30 @@ static int ip6_mr_forward(struct sk_buff *skb, struct mfc6_cache *cache)
1488 /* 1579 /*
1489 * Wrong interface: drop packet and (maybe) send PIM assert. 1580 * Wrong interface: drop packet and (maybe) send PIM assert.
1490 */ 1581 */
1491 if (vif6_table[vif].dev != skb->dev) { 1582 if (net->ipv6.vif6_table[vif].dev != skb->dev) {
1492 int true_vifi; 1583 int true_vifi;
1493 1584
1494 cache->mfc_un.res.wrong_if++; 1585 cache->mfc_un.res.wrong_if++;
1495 true_vifi = ip6mr_find_vif(skb->dev); 1586 true_vifi = ip6mr_find_vif(skb->dev);
1496 1587
1497 if (true_vifi >= 0 && mroute_do_assert && 1588 if (true_vifi >= 0 && net->ipv6.mroute_do_assert &&
1498 /* pimsm uses asserts, when switching from RPT to SPT, 1589 /* pimsm uses asserts, when switching from RPT to SPT,
1499 so that we cannot check that packet arrived on an oif. 1590 so that we cannot check that packet arrived on an oif.
1500 It is bad, but otherwise we would need to move pretty 1591 It is bad, but otherwise we would need to move pretty
1501 large chunk of pimd to kernel. Ough... --ANK 1592 large chunk of pimd to kernel. Ough... --ANK
1502 */ 1593 */
1503 (mroute_do_pim || cache->mfc_un.res.ttls[true_vifi] < 255) && 1594 (net->ipv6.mroute_do_pim ||
1595 cache->mfc_un.res.ttls[true_vifi] < 255) &&
1504 time_after(jiffies, 1596 time_after(jiffies,
1505 cache->mfc_un.res.last_assert + MFC_ASSERT_THRESH)) { 1597 cache->mfc_un.res.last_assert + MFC_ASSERT_THRESH)) {
1506 cache->mfc_un.res.last_assert = jiffies; 1598 cache->mfc_un.res.last_assert = jiffies;
1507 ip6mr_cache_report(skb, true_vifi, MRT6MSG_WRONGMIF); 1599 ip6mr_cache_report(net, skb, true_vifi, MRT6MSG_WRONGMIF);
1508 } 1600 }
1509 goto dont_forward; 1601 goto dont_forward;
1510 } 1602 }
1511 1603
1512 vif6_table[vif].pkt_in++; 1604 net->ipv6.vif6_table[vif].pkt_in++;
1513 vif6_table[vif].bytes_in += skb->len; 1605 net->ipv6.vif6_table[vif].bytes_in += skb->len;
1514 1606
1515 /* 1607 /*
1516 * Forward the frame 1608 * Forward the frame
@@ -1543,9 +1635,11 @@ dont_forward:
1543int ip6_mr_input(struct sk_buff *skb) 1635int ip6_mr_input(struct sk_buff *skb)
1544{ 1636{
1545 struct mfc6_cache *cache; 1637 struct mfc6_cache *cache;
1638 struct net *net = dev_net(skb->dev);
1546 1639
1547 read_lock(&mrt_lock); 1640 read_lock(&mrt_lock);
1548 cache = ip6mr_cache_find(&ipv6_hdr(skb)->saddr, &ipv6_hdr(skb)->daddr); 1641 cache = ip6mr_cache_find(net,
1642 &ipv6_hdr(skb)->saddr, &ipv6_hdr(skb)->daddr);
1549 1643
1550 /* 1644 /*
1551 * No usable cache entry 1645 * No usable cache entry
@@ -1555,7 +1649,7 @@ int ip6_mr_input(struct sk_buff *skb)
1555 1649
1556 vif = ip6mr_find_vif(skb->dev); 1650 vif = ip6mr_find_vif(skb->dev);
1557 if (vif >= 0) { 1651 if (vif >= 0) {
1558 int err = ip6mr_cache_unresolved(vif, skb); 1652 int err = ip6mr_cache_unresolved(net, vif, skb);
1559 read_unlock(&mrt_lock); 1653 read_unlock(&mrt_lock);
1560 1654
1561 return err; 1655 return err;
@@ -1578,7 +1672,8 @@ ip6mr_fill_mroute(struct sk_buff *skb, struct mfc6_cache *c, struct rtmsg *rtm)
1578{ 1672{
1579 int ct; 1673 int ct;
1580 struct rtnexthop *nhp; 1674 struct rtnexthop *nhp;
1581 struct net_device *dev = vif6_table[c->mf6c_parent].dev; 1675 struct net *net = mfc6_net(c);
1676 struct net_device *dev = net->ipv6.vif6_table[c->mf6c_parent].dev;
1582 u8 *b = skb_tail_pointer(skb); 1677 u8 *b = skb_tail_pointer(skb);
1583 struct rtattr *mp_head; 1678 struct rtattr *mp_head;
1584 1679
@@ -1594,7 +1689,7 @@ ip6mr_fill_mroute(struct sk_buff *skb, struct mfc6_cache *c, struct rtmsg *rtm)
1594 nhp = (struct rtnexthop *)skb_put(skb, RTA_ALIGN(sizeof(*nhp))); 1689 nhp = (struct rtnexthop *)skb_put(skb, RTA_ALIGN(sizeof(*nhp)));
1595 nhp->rtnh_flags = 0; 1690 nhp->rtnh_flags = 0;
1596 nhp->rtnh_hops = c->mfc_un.res.ttls[ct]; 1691 nhp->rtnh_hops = c->mfc_un.res.ttls[ct];
1597 nhp->rtnh_ifindex = vif6_table[ct].dev->ifindex; 1692 nhp->rtnh_ifindex = net->ipv6.vif6_table[ct].dev->ifindex;
1598 nhp->rtnh_len = sizeof(*nhp); 1693 nhp->rtnh_len = sizeof(*nhp);
1599 } 1694 }
1600 } 1695 }
@@ -1608,14 +1703,15 @@ rtattr_failure:
1608 return -EMSGSIZE; 1703 return -EMSGSIZE;
1609} 1704}
1610 1705
1611int ip6mr_get_route(struct sk_buff *skb, struct rtmsg *rtm, int nowait) 1706int ip6mr_get_route(struct net *net,
1707 struct sk_buff *skb, struct rtmsg *rtm, int nowait)
1612{ 1708{
1613 int err; 1709 int err;
1614 struct mfc6_cache *cache; 1710 struct mfc6_cache *cache;
1615 struct rt6_info *rt = (struct rt6_info *)skb->dst; 1711 struct rt6_info *rt = (struct rt6_info *)skb->dst;
1616 1712
1617 read_lock(&mrt_lock); 1713 read_lock(&mrt_lock);
1618 cache = ip6mr_cache_find(&rt->rt6i_src.addr, &rt->rt6i_dst.addr); 1714 cache = ip6mr_cache_find(net, &rt->rt6i_src.addr, &rt->rt6i_dst.addr);
1619 1715
1620 if (!cache) { 1716 if (!cache) {
1621 struct sk_buff *skb2; 1717 struct sk_buff *skb2;
@@ -1658,7 +1754,7 @@ int ip6mr_get_route(struct sk_buff *skb, struct rtmsg *rtm, int nowait)
1658 ipv6_addr_copy(&iph->saddr, &rt->rt6i_src.addr); 1754 ipv6_addr_copy(&iph->saddr, &rt->rt6i_src.addr);
1659 ipv6_addr_copy(&iph->daddr, &rt->rt6i_dst.addr); 1755 ipv6_addr_copy(&iph->daddr, &rt->rt6i_dst.addr);
1660 1756
1661 err = ip6mr_cache_unresolved(vif, skb2); 1757 err = ip6mr_cache_unresolved(net, vif, skb2);
1662 read_unlock(&mrt_lock); 1758 read_unlock(&mrt_lock);
1663 1759
1664 return err; 1760 return err;
diff --git a/net/ipv6/ipcomp6.c b/net/ipv6/ipcomp6.c
index 4545e4306862..3a0b3be7ece5 100644
--- a/net/ipv6/ipcomp6.c
+++ b/net/ipv6/ipcomp6.c
@@ -63,12 +63,12 @@ static void ipcomp6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
63 return; 63 return;
64 64
65 spi = htonl(ntohs(ipcomph->cpi)); 65 spi = htonl(ntohs(ipcomph->cpi));
66 x = xfrm_state_lookup((xfrm_address_t *)&iph->daddr, spi, IPPROTO_COMP, AF_INET6); 66 x = xfrm_state_lookup(&init_net, (xfrm_address_t *)&iph->daddr, spi, IPPROTO_COMP, AF_INET6);
67 if (!x) 67 if (!x)
68 return; 68 return;
69 69
70 printk(KERN_DEBUG "pmtu discovery on SA IPCOMP/%08x/" NIP6_FMT "\n", 70 printk(KERN_DEBUG "pmtu discovery on SA IPCOMP/%08x/%pI6\n",
71 spi, NIP6(iph->daddr)); 71 spi, &iph->daddr);
72 xfrm_state_put(x); 72 xfrm_state_put(x);
73} 73}
74 74
@@ -76,7 +76,7 @@ static struct xfrm_state *ipcomp6_tunnel_create(struct xfrm_state *x)
76{ 76{
77 struct xfrm_state *t = NULL; 77 struct xfrm_state *t = NULL;
78 78
79 t = xfrm_state_alloc(); 79 t = xfrm_state_alloc(&init_net);
80 if (!t) 80 if (!t)
81 goto out; 81 goto out;
82 82
@@ -114,7 +114,7 @@ static int ipcomp6_tunnel_attach(struct xfrm_state *x)
114 114
115 spi = xfrm6_tunnel_spi_lookup((xfrm_address_t *)&x->props.saddr); 115 spi = xfrm6_tunnel_spi_lookup((xfrm_address_t *)&x->props.saddr);
116 if (spi) 116 if (spi)
117 t = xfrm_state_lookup((xfrm_address_t *)&x->id.daddr, 117 t = xfrm_state_lookup(&init_net, (xfrm_address_t *)&x->id.daddr,
118 spi, IPPROTO_IPV6, AF_INET6); 118 spi, IPPROTO_IPV6, AF_INET6);
119 if (!t) { 119 if (!t) {
120 t = ipcomp6_tunnel_create(x); 120 t = ipcomp6_tunnel_create(x);
diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
index 2aa294be0c79..eeeaad2e8b5c 100644
--- a/net/ipv6/ipv6_sockglue.c
+++ b/net/ipv6/ipv6_sockglue.c
@@ -395,6 +395,28 @@ sticky_done:
395 break; 395 break;
396 } 396 }
397 397
398 case IPV6_PKTINFO:
399 {
400 struct in6_pktinfo pkt;
401
402 if (optlen == 0)
403 goto e_inval;
404 else if (optlen < sizeof(struct in6_pktinfo) || optval == NULL)
405 goto e_inval;
406
407 if (copy_from_user(&pkt, optval, optlen)) {
408 retv = -EFAULT;
409 break;
410 }
411 if (sk->sk_bound_dev_if && pkt.ipi6_ifindex != sk->sk_bound_dev_if)
412 goto e_inval;
413
414 np->sticky_pktinfo.ipi6_ifindex = pkt.ipi6_ifindex;
415 ipv6_addr_copy(&np->sticky_pktinfo.ipi6_addr, &pkt.ipi6_addr);
416 retv = 0;
417 break;
418 }
419
398 case IPV6_2292PKTOPTIONS: 420 case IPV6_2292PKTOPTIONS:
399 { 421 {
400 struct ipv6_txoptions *opt = NULL; 422 struct ipv6_txoptions *opt = NULL;
@@ -916,8 +938,10 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
916 } else { 938 } else {
917 if (np->rxopt.bits.rxinfo) { 939 if (np->rxopt.bits.rxinfo) {
918 struct in6_pktinfo src_info; 940 struct in6_pktinfo src_info;
919 src_info.ipi6_ifindex = np->mcast_oif ? np->mcast_oif : sk->sk_bound_dev_if; 941 src_info.ipi6_ifindex = np->mcast_oif ? np->mcast_oif :
920 ipv6_addr_copy(&src_info.ipi6_addr, &np->daddr); 942 np->sticky_pktinfo.ipi6_ifindex;
943 np->mcast_oif? ipv6_addr_copy(&src_info.ipi6_addr, &np->daddr) :
944 ipv6_addr_copy(&src_info.ipi6_addr, &(np->sticky_pktinfo.ipi6_addr));
921 put_cmsg(&msg, SOL_IPV6, IPV6_PKTINFO, sizeof(src_info), &src_info); 945 put_cmsg(&msg, SOL_IPV6, IPV6_PKTINFO, sizeof(src_info), &src_info);
922 } 946 }
923 if (np->rxopt.bits.rxhlim) { 947 if (np->rxopt.bits.rxhlim) {
@@ -926,8 +950,10 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
926 } 950 }
927 if (np->rxopt.bits.rxoinfo) { 951 if (np->rxopt.bits.rxoinfo) {
928 struct in6_pktinfo src_info; 952 struct in6_pktinfo src_info;
929 src_info.ipi6_ifindex = np->mcast_oif ? np->mcast_oif : sk->sk_bound_dev_if; 953 src_info.ipi6_ifindex = np->mcast_oif ? np->mcast_oif :
930 ipv6_addr_copy(&src_info.ipi6_addr, &np->daddr); 954 np->sticky_pktinfo.ipi6_ifindex;
955 np->mcast_oif? ipv6_addr_copy(&src_info.ipi6_addr, &np->daddr) :
956 ipv6_addr_copy(&src_info.ipi6_addr, &(np->sticky_pktinfo.ipi6_addr));
931 put_cmsg(&msg, SOL_IPV6, IPV6_2292PKTINFO, sizeof(src_info), &src_info); 957 put_cmsg(&msg, SOL_IPV6, IPV6_2292PKTINFO, sizeof(src_info), &src_info);
932 } 958 }
933 if (np->rxopt.bits.rxohlim) { 959 if (np->rxopt.bits.rxohlim) {
diff --git a/net/ipv6/mcast.c b/net/ipv6/mcast.c
index d7b3c6d398ae..a51fb33e6864 100644
--- a/net/ipv6/mcast.c
+++ b/net/ipv6/mcast.c
@@ -303,20 +303,23 @@ static struct inet6_dev *ip6_mc_find_dev(struct net *net,
303 dev = dev_get_by_index(net, ifindex); 303 dev = dev_get_by_index(net, ifindex);
304 304
305 if (!dev) 305 if (!dev)
306 return NULL; 306 goto nodev;
307 idev = in6_dev_get(dev); 307 idev = in6_dev_get(dev);
308 if (!idev) { 308 if (!idev)
309 dev_put(dev); 309 goto release;
310 return NULL;
311 }
312 read_lock_bh(&idev->lock); 310 read_lock_bh(&idev->lock);
313 if (idev->dead) { 311 if (idev->dead)
314 read_unlock_bh(&idev->lock); 312 goto unlock_release;
315 in6_dev_put(idev); 313
316 dev_put(dev);
317 return NULL;
318 }
319 return idev; 314 return idev;
315
316unlock_release:
317 read_unlock_bh(&idev->lock);
318 in6_dev_put(idev);
319release:
320 dev_put(dev);
321nodev:
322 return NULL;
320} 323}
321 324
322void ipv6_sock_mc_close(struct sock *sk) 325void ipv6_sock_mc_close(struct sock *sk)
@@ -1466,7 +1469,7 @@ static void mld_sendpack(struct sk_buff *skb)
1466 &ipv6_hdr(skb)->saddr, &ipv6_hdr(skb)->daddr, 1469 &ipv6_hdr(skb)->saddr, &ipv6_hdr(skb)->daddr,
1467 skb->dev->ifindex); 1470 skb->dev->ifindex);
1468 1471
1469 err = xfrm_lookup(&skb->dst, &fl, NULL, 0); 1472 err = xfrm_lookup(net, &skb->dst, &fl, NULL, 0);
1470 if (err) 1473 if (err)
1471 goto err_out; 1474 goto err_out;
1472 1475
@@ -1817,7 +1820,7 @@ static void igmp6_send(struct in6_addr *addr, struct net_device *dev, int type)
1817 1820
1818 hdr->icmp6_cksum = csum_ipv6_magic(saddr, snd_addr, len, 1821 hdr->icmp6_cksum = csum_ipv6_magic(saddr, snd_addr, len,
1819 IPPROTO_ICMPV6, 1822 IPPROTO_ICMPV6,
1820 csum_partial((__u8 *) hdr, len, 0)); 1823 csum_partial(hdr, len, 0));
1821 1824
1822 idev = in6_dev_get(skb->dev); 1825 idev = in6_dev_get(skb->dev);
1823 1826
@@ -1831,7 +1834,7 @@ static void igmp6_send(struct in6_addr *addr, struct net_device *dev, int type)
1831 &ipv6_hdr(skb)->saddr, &ipv6_hdr(skb)->daddr, 1834 &ipv6_hdr(skb)->saddr, &ipv6_hdr(skb)->daddr,
1832 skb->dev->ifindex); 1835 skb->dev->ifindex);
1833 1836
1834 err = xfrm_lookup(&skb->dst, &fl, NULL, 0); 1837 err = xfrm_lookup(net, &skb->dst, &fl, NULL, 0);
1835 if (err) 1838 if (err)
1836 goto err_out; 1839 goto err_out;
1837 1840
@@ -2430,9 +2433,9 @@ static int igmp6_mc_seq_show(struct seq_file *seq, void *v)
2430 struct igmp6_mc_iter_state *state = igmp6_mc_seq_private(seq); 2433 struct igmp6_mc_iter_state *state = igmp6_mc_seq_private(seq);
2431 2434
2432 seq_printf(seq, 2435 seq_printf(seq,
2433 "%-4d %-15s " NIP6_SEQFMT " %5d %08X %ld\n", 2436 "%-4d %-15s %pi6 %5d %08X %ld\n",
2434 state->dev->ifindex, state->dev->name, 2437 state->dev->ifindex, state->dev->name,
2435 NIP6(im->mca_addr), 2438 &im->mca_addr,
2436 im->mca_users, im->mca_flags, 2439 im->mca_users, im->mca_flags,
2437 (im->mca_flags&MAF_TIMER_RUNNING) ? 2440 (im->mca_flags&MAF_TIMER_RUNNING) ?
2438 jiffies_to_clock_t(im->mca_timer.expires-jiffies) : 0); 2441 jiffies_to_clock_t(im->mca_timer.expires-jiffies) : 0);
@@ -2591,10 +2594,10 @@ static int igmp6_mcf_seq_show(struct seq_file *seq, void *v)
2591 "Source Address", "INC", "EXC"); 2594 "Source Address", "INC", "EXC");
2592 } else { 2595 } else {
2593 seq_printf(seq, 2596 seq_printf(seq,
2594 "%3d %6.6s " NIP6_SEQFMT " " NIP6_SEQFMT " %6lu %6lu\n", 2597 "%3d %6.6s %pi6 %pi6 %6lu %6lu\n",
2595 state->dev->ifindex, state->dev->name, 2598 state->dev->ifindex, state->dev->name,
2596 NIP6(state->im->mca_addr), 2599 &state->im->mca_addr,
2597 NIP6(psf->sf_addr), 2600 &psf->sf_addr,
2598 psf->sf_count[MCAST_INCLUDE], 2601 psf->sf_count[MCAST_INCLUDE],
2599 psf->sf_count[MCAST_EXCLUDE]); 2602 psf->sf_count[MCAST_EXCLUDE]);
2600 } 2603 }
diff --git a/net/ipv6/mip6.c b/net/ipv6/mip6.c
index 31295c8f6196..f995e19c87a9 100644
--- a/net/ipv6/mip6.c
+++ b/net/ipv6/mip6.c
@@ -205,6 +205,7 @@ static inline int mip6_report_rl_allow(struct timeval *stamp,
205 205
206static int mip6_destopt_reject(struct xfrm_state *x, struct sk_buff *skb, struct flowi *fl) 206static int mip6_destopt_reject(struct xfrm_state *x, struct sk_buff *skb, struct flowi *fl)
207{ 207{
208 struct net *net = xs_net(x);
208 struct inet6_skb_parm *opt = (struct inet6_skb_parm *)skb->cb; 209 struct inet6_skb_parm *opt = (struct inet6_skb_parm *)skb->cb;
209 struct ipv6_destopt_hao *hao = NULL; 210 struct ipv6_destopt_hao *hao = NULL;
210 struct xfrm_selector sel; 211 struct xfrm_selector sel;
@@ -247,7 +248,7 @@ static int mip6_destopt_reject(struct xfrm_state *x, struct sk_buff *skb, struct
247 sel.sport_mask = htons(~0); 248 sel.sport_mask = htons(~0);
248 sel.ifindex = fl->oif; 249 sel.ifindex = fl->oif;
249 250
250 err = km_report(IPPROTO_DSTOPTS, &sel, 251 err = km_report(net, IPPROTO_DSTOPTS, &sel,
251 (hao ? (xfrm_address_t *)&hao->addr : NULL)); 252 (hao ? (xfrm_address_t *)&hao->addr : NULL));
252 253
253 out: 254 out:
diff --git a/net/ipv6/ndisc.c b/net/ipv6/ndisc.c
index d0f54d18e19b..3e2970841bd8 100644
--- a/net/ipv6/ndisc.c
+++ b/net/ipv6/ndisc.c
@@ -437,38 +437,20 @@ static void pndisc_destructor(struct pneigh_entry *n)
437 ipv6_dev_mc_dec(dev, &maddr); 437 ipv6_dev_mc_dec(dev, &maddr);
438} 438}
439 439
440/* 440struct sk_buff *ndisc_build_skb(struct net_device *dev,
441 * Send a Neighbour Advertisement 441 const struct in6_addr *daddr,
442 */ 442 const struct in6_addr *saddr,
443static void __ndisc_send(struct net_device *dev, 443 struct icmp6hdr *icmp6h,
444 struct neighbour *neigh, 444 const struct in6_addr *target,
445 const struct in6_addr *daddr, 445 int llinfo)
446 const struct in6_addr *saddr,
447 struct icmp6hdr *icmp6h, const struct in6_addr *target,
448 int llinfo)
449{ 446{
450 struct flowi fl;
451 struct dst_entry *dst;
452 struct net *net = dev_net(dev); 447 struct net *net = dev_net(dev);
453 struct sock *sk = net->ipv6.ndisc_sk; 448 struct sock *sk = net->ipv6.ndisc_sk;
454 struct sk_buff *skb; 449 struct sk_buff *skb;
455 struct icmp6hdr *hdr; 450 struct icmp6hdr *hdr;
456 struct inet6_dev *idev;
457 int len; 451 int len;
458 int err; 452 int err;
459 u8 *opt, type; 453 u8 *opt;
460
461 type = icmp6h->icmp6_type;
462
463 icmpv6_flow_init(sk, &fl, type, saddr, daddr, dev->ifindex);
464
465 dst = icmp6_dst_alloc(dev, neigh, daddr);
466 if (!dst)
467 return;
468
469 err = xfrm_lookup(&dst, &fl, NULL, 0);
470 if (err < 0)
471 return;
472 454
473 if (!dev->addr_len) 455 if (!dev->addr_len)
474 llinfo = 0; 456 llinfo = 0;
@@ -485,8 +467,7 @@ static void __ndisc_send(struct net_device *dev,
485 ND_PRINTK0(KERN_ERR 467 ND_PRINTK0(KERN_ERR
486 "ICMPv6 ND: %s() failed to allocate an skb.\n", 468 "ICMPv6 ND: %s() failed to allocate an skb.\n",
487 __func__); 469 __func__);
488 dst_release(dst); 470 return NULL;
489 return;
490 } 471 }
491 472
492 skb_reserve(skb, LL_RESERVED_SPACE(dev)); 473 skb_reserve(skb, LL_RESERVED_SPACE(dev));
@@ -510,9 +491,45 @@ static void __ndisc_send(struct net_device *dev,
510 491
511 hdr->icmp6_cksum = csum_ipv6_magic(saddr, daddr, len, 492 hdr->icmp6_cksum = csum_ipv6_magic(saddr, daddr, len,
512 IPPROTO_ICMPV6, 493 IPPROTO_ICMPV6,
513 csum_partial((__u8 *) hdr, 494 csum_partial(hdr,
514 len, 0)); 495 len, 0));
515 496
497 return skb;
498}
499
500EXPORT_SYMBOL(ndisc_build_skb);
501
502void ndisc_send_skb(struct sk_buff *skb,
503 struct net_device *dev,
504 struct neighbour *neigh,
505 const struct in6_addr *daddr,
506 const struct in6_addr *saddr,
507 struct icmp6hdr *icmp6h)
508{
509 struct flowi fl;
510 struct dst_entry *dst;
511 struct net *net = dev_net(dev);
512 struct sock *sk = net->ipv6.ndisc_sk;
513 struct inet6_dev *idev;
514 int err;
515 u8 type;
516
517 type = icmp6h->icmp6_type;
518
519 icmpv6_flow_init(sk, &fl, type, saddr, daddr, dev->ifindex);
520
521 dst = icmp6_dst_alloc(dev, neigh, daddr);
522 if (!dst) {
523 kfree_skb(skb);
524 return;
525 }
526
527 err = xfrm_lookup(net, &dst, &fl, NULL, 0);
528 if (err < 0) {
529 kfree_skb(skb);
530 return;
531 }
532
516 skb->dst = dst; 533 skb->dst = dst;
517 534
518 idev = in6_dev_get(dst->dev); 535 idev = in6_dev_get(dst->dev);
@@ -529,6 +546,27 @@ static void __ndisc_send(struct net_device *dev,
529 in6_dev_put(idev); 546 in6_dev_put(idev);
530} 547}
531 548
549EXPORT_SYMBOL(ndisc_send_skb);
550
551/*
552 * Send a Neighbour Discover packet
553 */
554static void __ndisc_send(struct net_device *dev,
555 struct neighbour *neigh,
556 const struct in6_addr *daddr,
557 const struct in6_addr *saddr,
558 struct icmp6hdr *icmp6h, const struct in6_addr *target,
559 int llinfo)
560{
561 struct sk_buff *skb;
562
563 skb = ndisc_build_skb(dev, daddr, saddr, icmp6h, target, llinfo);
564 if (!skb)
565 return;
566
567 ndisc_send_skb(skb, dev, neigh, daddr, saddr, icmp6h);
568}
569
532static void ndisc_send_na(struct net_device *dev, struct neighbour *neigh, 570static void ndisc_send_na(struct net_device *dev, struct neighbour *neigh,
533 const struct in6_addr *daddr, 571 const struct in6_addr *daddr,
534 const struct in6_addr *solicited_addr, 572 const struct in6_addr *solicited_addr,
@@ -647,11 +685,8 @@ static void ndisc_solicit(struct neighbour *neigh, struct sk_buff *skb)
647 685
648 if ((probes -= neigh->parms->ucast_probes) < 0) { 686 if ((probes -= neigh->parms->ucast_probes) < 0) {
649 if (!(neigh->nud_state & NUD_VALID)) { 687 if (!(neigh->nud_state & NUD_VALID)) {
650 ND_PRINTK1(KERN_DEBUG 688 ND_PRINTK1(KERN_DEBUG "%s(): trying to ucast probe in NUD_INVALID: %pI6\n",
651 "%s(): trying to ucast probe in NUD_INVALID: " 689 __func__, target);
652 NIP6_FMT "\n",
653 __func__,
654 NIP6(*target));
655 } 690 }
656 ndisc_send_ns(dev, neigh, target, target, saddr); 691 ndisc_send_ns(dev, neigh, target, target, saddr);
657 } else if ((probes -= neigh->parms->app_probes) < 0) { 692 } else if ((probes -= neigh->parms->app_probes) < 0) {
@@ -1494,7 +1529,7 @@ void ndisc_send_redirect(struct sk_buff *skb, struct neighbour *neigh,
1494 if (dst == NULL) 1529 if (dst == NULL)
1495 return; 1530 return;
1496 1531
1497 err = xfrm_lookup(&dst, &fl, NULL, 0); 1532 err = xfrm_lookup(net, &dst, &fl, NULL, 0);
1498 if (err) 1533 if (err)
1499 return; 1534 return;
1500 1535
@@ -1582,7 +1617,7 @@ void ndisc_send_redirect(struct sk_buff *skb, struct neighbour *neigh,
1582 1617
1583 icmph->icmp6_cksum = csum_ipv6_magic(&saddr_buf, &ipv6_hdr(skb)->saddr, 1618 icmph->icmp6_cksum = csum_ipv6_magic(&saddr_buf, &ipv6_hdr(skb)->saddr,
1584 len, IPPROTO_ICMPV6, 1619 len, IPPROTO_ICMPV6,
1585 csum_partial((u8 *) icmph, len, 0)); 1620 csum_partial(icmph, len, 0));
1586 1621
1587 buff->dst = dst; 1622 buff->dst = dst;
1588 idev = in6_dev_get(dst->dev); 1623 idev = in6_dev_get(dst->dev);
diff --git a/net/ipv6/netfilter.c b/net/ipv6/netfilter.c
index fd5b3a4e3329..834cea69fb53 100644
--- a/net/ipv6/netfilter.c
+++ b/net/ipv6/netfilter.c
@@ -29,7 +29,7 @@ int ip6_route_me_harder(struct sk_buff *skb)
29#ifdef CONFIG_XFRM 29#ifdef CONFIG_XFRM
30 if (!(IP6CB(skb)->flags & IP6SKB_XFRM_TRANSFORMED) && 30 if (!(IP6CB(skb)->flags & IP6SKB_XFRM_TRANSFORMED) &&
31 xfrm_decode_session(skb, &fl, AF_INET6) == 0) 31 xfrm_decode_session(skb, &fl, AF_INET6) == 0)
32 if (xfrm_lookup(&skb->dst, &fl, skb->sk, 0)) 32 if (xfrm_lookup(net, &skb->dst, &fl, skb->sk, 0))
33 return -1; 33 return -1;
34#endif 34#endif
35 35
@@ -56,6 +56,7 @@ EXPORT_SYMBOL(ip6_route_me_harder);
56struct ip6_rt_info { 56struct ip6_rt_info {
57 struct in6_addr daddr; 57 struct in6_addr daddr;
58 struct in6_addr saddr; 58 struct in6_addr saddr;
59 u_int32_t mark;
59}; 60};
60 61
61static void nf_ip6_saveroute(const struct sk_buff *skb, 62static void nf_ip6_saveroute(const struct sk_buff *skb,
@@ -68,6 +69,7 @@ static void nf_ip6_saveroute(const struct sk_buff *skb,
68 69
69 rt_info->daddr = iph->daddr; 70 rt_info->daddr = iph->daddr;
70 rt_info->saddr = iph->saddr; 71 rt_info->saddr = iph->saddr;
72 rt_info->mark = skb->mark;
71 } 73 }
72} 74}
73 75
@@ -79,7 +81,8 @@ static int nf_ip6_reroute(struct sk_buff *skb,
79 if (entry->hook == NF_INET_LOCAL_OUT) { 81 if (entry->hook == NF_INET_LOCAL_OUT) {
80 struct ipv6hdr *iph = ipv6_hdr(skb); 82 struct ipv6hdr *iph = ipv6_hdr(skb);
81 if (!ipv6_addr_equal(&iph->daddr, &rt_info->daddr) || 83 if (!ipv6_addr_equal(&iph->daddr, &rt_info->daddr) ||
82 !ipv6_addr_equal(&iph->saddr, &rt_info->saddr)) 84 !ipv6_addr_equal(&iph->saddr, &rt_info->saddr) ||
85 skb->mark != rt_info->mark)
83 return ip6_route_me_harder(skb); 86 return ip6_route_me_harder(skb);
84 } 87 }
85 return 0; 88 return 0;
diff --git a/net/ipv6/netfilter/ip6t_LOG.c b/net/ipv6/netfilter/ip6t_LOG.c
index 871d157cec4e..37adf5abc51e 100644
--- a/net/ipv6/netfilter/ip6t_LOG.c
+++ b/net/ipv6/netfilter/ip6t_LOG.c
@@ -61,7 +61,7 @@ static void dump_packet(const struct nf_loginfo *info,
61 } 61 }
62 62
63 /* Max length: 88 "SRC=0000.0000.0000.0000.0000.0000.0000.0000 DST=0000.0000.0000.0000.0000.0000.0000.0000 " */ 63 /* Max length: 88 "SRC=0000.0000.0000.0000.0000.0000.0000.0000 DST=0000.0000.0000.0000.0000.0000.0000.0000 " */
64 printk("SRC=" NIP6_FMT " DST=" NIP6_FMT " ", NIP6(ih->saddr), NIP6(ih->daddr)); 64 printk("SRC=%pI6 DST=%pI6 ", &ih->saddr, &ih->daddr);
65 65
66 /* Max length: 44 "LEN=65535 TC=255 HOPLIMIT=255 FLOWLBL=FFFFF " */ 66 /* Max length: 44 "LEN=65535 TC=255 HOPLIMIT=255 FLOWLBL=FFFFF " */
67 printk("LEN=%Zu TC=%u HOPLIMIT=%u FLOWLBL=%u ", 67 printk("LEN=%Zu TC=%u HOPLIMIT=%u FLOWLBL=%u ",
@@ -424,9 +424,8 @@ ip6t_log_packet(u_int8_t pf,
424 if (skb->dev->type == ARPHRD_SIT) { 424 if (skb->dev->type == ARPHRD_SIT) {
425 const struct iphdr *iph = 425 const struct iphdr *iph =
426 (struct iphdr *)skb_mac_header(skb); 426 (struct iphdr *)skb_mac_header(skb);
427 printk("TUNNEL=%u.%u.%u.%u->%u.%u.%u.%u ", 427 printk("TUNNEL=%pI4->%pI4 ",
428 NIPQUAD(iph->saddr), 428 &iph->saddr, &iph->daddr);
429 NIPQUAD(iph->daddr));
430 } 429 }
431 } else 430 } else
432 printk(" "); 431 printk(" ");
diff --git a/net/ipv6/netfilter/ip6t_REJECT.c b/net/ipv6/netfilter/ip6t_REJECT.c
index 0981b4ccb8b1..5a2d0a41694a 100644
--- a/net/ipv6/netfilter/ip6t_REJECT.c
+++ b/net/ipv6/netfilter/ip6t_REJECT.c
@@ -97,7 +97,7 @@ static void send_reset(struct net *net, struct sk_buff *oldskb)
97 dst = ip6_route_output(net, NULL, &fl); 97 dst = ip6_route_output(net, NULL, &fl);
98 if (dst == NULL) 98 if (dst == NULL)
99 return; 99 return;
100 if (dst->error || xfrm_lookup(&dst, &fl, NULL, 0)) 100 if (dst->error || xfrm_lookup(net, &dst, &fl, NULL, 0))
101 return; 101 return;
102 102
103 hh_len = (dst->dev->hard_header_len + 15)&~15; 103 hh_len = (dst->dev->hard_header_len + 15)&~15;
diff --git a/net/ipv6/netfilter/ip6table_filter.c b/net/ipv6/netfilter/ip6table_filter.c
index b110a8a85a14..40d2e36d8fac 100644
--- a/net/ipv6/netfilter/ip6table_filter.c
+++ b/net/ipv6/netfilter/ip6table_filter.c
@@ -61,7 +61,7 @@ static struct xt_table packet_filter = {
61 61
62/* The work comes in here from netfilter.c. */ 62/* The work comes in here from netfilter.c. */
63static unsigned int 63static unsigned int
64ip6t_local_in_hook(unsigned int hook, 64ip6t_in_hook(unsigned int hook,
65 struct sk_buff *skb, 65 struct sk_buff *skb,
66 const struct net_device *in, 66 const struct net_device *in,
67 const struct net_device *out, 67 const struct net_device *out,
@@ -72,17 +72,6 @@ ip6t_local_in_hook(unsigned int hook,
72} 72}
73 73
74static unsigned int 74static unsigned int
75ip6t_forward_hook(unsigned int hook,
76 struct sk_buff *skb,
77 const struct net_device *in,
78 const struct net_device *out,
79 int (*okfn)(struct sk_buff *))
80{
81 return ip6t_do_table(skb, hook, in, out,
82 dev_net(in)->ipv6.ip6table_filter);
83}
84
85static unsigned int
86ip6t_local_out_hook(unsigned int hook, 75ip6t_local_out_hook(unsigned int hook,
87 struct sk_buff *skb, 76 struct sk_buff *skb,
88 const struct net_device *in, 77 const struct net_device *in,
@@ -105,14 +94,14 @@ ip6t_local_out_hook(unsigned int hook,
105 94
106static struct nf_hook_ops ip6t_ops[] __read_mostly = { 95static struct nf_hook_ops ip6t_ops[] __read_mostly = {
107 { 96 {
108 .hook = ip6t_local_in_hook, 97 .hook = ip6t_in_hook,
109 .owner = THIS_MODULE, 98 .owner = THIS_MODULE,
110 .pf = PF_INET6, 99 .pf = PF_INET6,
111 .hooknum = NF_INET_LOCAL_IN, 100 .hooknum = NF_INET_LOCAL_IN,
112 .priority = NF_IP6_PRI_FILTER, 101 .priority = NF_IP6_PRI_FILTER,
113 }, 102 },
114 { 103 {
115 .hook = ip6t_forward_hook, 104 .hook = ip6t_in_hook,
116 .owner = THIS_MODULE, 105 .owner = THIS_MODULE,
117 .pf = PF_INET6, 106 .pf = PF_INET6,
118 .hooknum = NF_INET_FORWARD, 107 .hooknum = NF_INET_FORWARD,
diff --git a/net/ipv6/netfilter/nf_conntrack_l3proto_ipv6.c b/net/ipv6/netfilter/nf_conntrack_l3proto_ipv6.c
index e91db16611d9..727b9530448a 100644
--- a/net/ipv6/netfilter/nf_conntrack_l3proto_ipv6.c
+++ b/net/ipv6/netfilter/nf_conntrack_l3proto_ipv6.c
@@ -56,9 +56,8 @@ static bool ipv6_invert_tuple(struct nf_conntrack_tuple *tuple,
56static int ipv6_print_tuple(struct seq_file *s, 56static int ipv6_print_tuple(struct seq_file *s,
57 const struct nf_conntrack_tuple *tuple) 57 const struct nf_conntrack_tuple *tuple)
58{ 58{
59 return seq_printf(s, "src=" NIP6_FMT " dst=" NIP6_FMT " ", 59 return seq_printf(s, "src=%pI6 dst=%pI6 ",
60 NIP6(*((struct in6_addr *)tuple->src.u3.ip6)), 60 tuple->src.u3.ip6, tuple->dst.u3.ip6);
61 NIP6(*((struct in6_addr *)tuple->dst.u3.ip6)));
62} 61}
63 62
64/* 63/*
diff --git a/net/ipv6/netfilter/nf_conntrack_proto_icmpv6.c b/net/ipv6/netfilter/nf_conntrack_proto_icmpv6.c
index 05726177903f..bd52151d31e9 100644
--- a/net/ipv6/netfilter/nf_conntrack_proto_icmpv6.c
+++ b/net/ipv6/netfilter/nf_conntrack_proto_icmpv6.c
@@ -253,7 +253,7 @@ static struct ctl_table icmpv6_sysctl_table[] = {
253 .data = &nf_ct_icmpv6_timeout, 253 .data = &nf_ct_icmpv6_timeout,
254 .maxlen = sizeof(unsigned int), 254 .maxlen = sizeof(unsigned int),
255 .mode = 0644, 255 .mode = 0644,
256 .proc_handler = &proc_dointvec_jiffies, 256 .proc_handler = proc_dointvec_jiffies,
257 }, 257 },
258 { 258 {
259 .ctl_name = 0 259 .ctl_name = 0
diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/nf_conntrack_reasm.c
index 9967ac7a01a8..ed4d79a9e4a6 100644
--- a/net/ipv6/netfilter/nf_conntrack_reasm.c
+++ b/net/ipv6/netfilter/nf_conntrack_reasm.c
@@ -80,7 +80,7 @@ struct ctl_table nf_ct_ipv6_sysctl_table[] = {
80 .data = &nf_init_frags.timeout, 80 .data = &nf_init_frags.timeout,
81 .maxlen = sizeof(unsigned int), 81 .maxlen = sizeof(unsigned int),
82 .mode = 0644, 82 .mode = 0644,
83 .proc_handler = &proc_dointvec_jiffies, 83 .proc_handler = proc_dointvec_jiffies,
84 }, 84 },
85 { 85 {
86 .ctl_name = NET_NF_CONNTRACK_FRAG6_LOW_THRESH, 86 .ctl_name = NET_NF_CONNTRACK_FRAG6_LOW_THRESH,
@@ -88,7 +88,7 @@ struct ctl_table nf_ct_ipv6_sysctl_table[] = {
88 .data = &nf_init_frags.low_thresh, 88 .data = &nf_init_frags.low_thresh,
89 .maxlen = sizeof(unsigned int), 89 .maxlen = sizeof(unsigned int),
90 .mode = 0644, 90 .mode = 0644,
91 .proc_handler = &proc_dointvec, 91 .proc_handler = proc_dointvec,
92 }, 92 },
93 { 93 {
94 .ctl_name = NET_NF_CONNTRACK_FRAG6_HIGH_THRESH, 94 .ctl_name = NET_NF_CONNTRACK_FRAG6_HIGH_THRESH,
@@ -96,7 +96,7 @@ struct ctl_table nf_ct_ipv6_sysctl_table[] = {
96 .data = &nf_init_frags.high_thresh, 96 .data = &nf_init_frags.high_thresh,
97 .maxlen = sizeof(unsigned int), 97 .maxlen = sizeof(unsigned int),
98 .mode = 0644, 98 .mode = 0644,
99 .proc_handler = &proc_dointvec, 99 .proc_handler = proc_dointvec,
100 }, 100 },
101 { .ctl_name = 0 } 101 { .ctl_name = 0 }
102}; 102};
diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
index 2ba04d41dc25..61f6827e5906 100644
--- a/net/ipv6/raw.c
+++ b/net/ipv6/raw.c
@@ -860,7 +860,8 @@ static int rawv6_sendmsg(struct kiocb *iocb, struct sock *sk,
860 if (final_p) 860 if (final_p)
861 ipv6_addr_copy(&fl.fl6_dst, final_p); 861 ipv6_addr_copy(&fl.fl6_dst, final_p);
862 862
863 if ((err = __xfrm_lookup(&dst, &fl, sk, XFRM_LOOKUP_WAIT)) < 0) { 863 err = __xfrm_lookup(sock_net(sk), &dst, &fl, sk, XFRM_LOOKUP_WAIT);
864 if (err < 0) {
864 if (err == -EREMOTE) 865 if (err == -EREMOTE)
865 err = ip6_dst_blackhole(sk, &dst, &fl); 866 err = ip6_dst_blackhole(sk, &dst, &fl);
866 if (err < 0) 867 if (err < 0)
diff --git a/net/ipv6/reassembly.c b/net/ipv6/reassembly.c
index af12de071f4c..3c575118fca5 100644
--- a/net/ipv6/reassembly.c
+++ b/net/ipv6/reassembly.c
@@ -642,7 +642,7 @@ static struct ctl_table ip6_frags_ns_ctl_table[] = {
642 .data = &init_net.ipv6.frags.high_thresh, 642 .data = &init_net.ipv6.frags.high_thresh,
643 .maxlen = sizeof(int), 643 .maxlen = sizeof(int),
644 .mode = 0644, 644 .mode = 0644,
645 .proc_handler = &proc_dointvec 645 .proc_handler = proc_dointvec
646 }, 646 },
647 { 647 {
648 .ctl_name = NET_IPV6_IP6FRAG_LOW_THRESH, 648 .ctl_name = NET_IPV6_IP6FRAG_LOW_THRESH,
@@ -650,7 +650,7 @@ static struct ctl_table ip6_frags_ns_ctl_table[] = {
650 .data = &init_net.ipv6.frags.low_thresh, 650 .data = &init_net.ipv6.frags.low_thresh,
651 .maxlen = sizeof(int), 651 .maxlen = sizeof(int),
652 .mode = 0644, 652 .mode = 0644,
653 .proc_handler = &proc_dointvec 653 .proc_handler = proc_dointvec
654 }, 654 },
655 { 655 {
656 .ctl_name = NET_IPV6_IP6FRAG_TIME, 656 .ctl_name = NET_IPV6_IP6FRAG_TIME,
@@ -658,8 +658,8 @@ static struct ctl_table ip6_frags_ns_ctl_table[] = {
658 .data = &init_net.ipv6.frags.timeout, 658 .data = &init_net.ipv6.frags.timeout,
659 .maxlen = sizeof(int), 659 .maxlen = sizeof(int),
660 .mode = 0644, 660 .mode = 0644,
661 .proc_handler = &proc_dointvec_jiffies, 661 .proc_handler = proc_dointvec_jiffies,
662 .strategy = &sysctl_jiffies, 662 .strategy = sysctl_jiffies,
663 }, 663 },
664 { } 664 { }
665}; 665};
@@ -671,8 +671,8 @@ static struct ctl_table ip6_frags_ctl_table[] = {
671 .data = &ip6_frags.secret_interval, 671 .data = &ip6_frags.secret_interval,
672 .maxlen = sizeof(int), 672 .maxlen = sizeof(int),
673 .mode = 0644, 673 .mode = 0644,
674 .proc_handler = &proc_dointvec_jiffies, 674 .proc_handler = proc_dointvec_jiffies,
675 .strategy = &sysctl_jiffies 675 .strategy = sysctl_jiffies
676 }, 676 },
677 { } 677 { }
678}; 678};
diff --git a/net/ipv6/route.c b/net/ipv6/route.c
index 89dc69924340..18c486cf4987 100644
--- a/net/ipv6/route.c
+++ b/net/ipv6/route.c
@@ -108,7 +108,6 @@ static struct dst_ops ip6_dst_ops_template = {
108 .link_failure = ip6_link_failure, 108 .link_failure = ip6_link_failure,
109 .update_pmtu = ip6_rt_update_pmtu, 109 .update_pmtu = ip6_rt_update_pmtu,
110 .local_out = __ip6_local_out, 110 .local_out = __ip6_local_out,
111 .entry_size = sizeof(struct rt6_info),
112 .entries = ATOMIC_INIT(0), 111 .entries = ATOMIC_INIT(0),
113}; 112};
114 113
@@ -122,7 +121,6 @@ static struct dst_ops ip6_dst_blackhole_ops = {
122 .destroy = ip6_dst_destroy, 121 .destroy = ip6_dst_destroy,
123 .check = ip6_dst_check, 122 .check = ip6_dst_check,
124 .update_pmtu = ip6_rt_blackhole_update_pmtu, 123 .update_pmtu = ip6_rt_blackhole_update_pmtu,
125 .entry_size = sizeof(struct rt6_info),
126 .entries = ATOMIC_INIT(0), 124 .entries = ATOMIC_INIT(0),
127}; 125};
128 126
@@ -2196,7 +2194,7 @@ static int rt6_fill_node(struct net *net,
2196 if (iif) { 2194 if (iif) {
2197#ifdef CONFIG_IPV6_MROUTE 2195#ifdef CONFIG_IPV6_MROUTE
2198 if (ipv6_addr_is_multicast(&rt->rt6i_dst.addr)) { 2196 if (ipv6_addr_is_multicast(&rt->rt6i_dst.addr)) {
2199 int err = ip6mr_get_route(skb, rtm, nowait); 2197 int err = ip6mr_get_route(net, skb, rtm, nowait);
2200 if (err <= 0) { 2198 if (err <= 0) {
2201 if (!nowait) { 2199 if (!nowait) {
2202 if (err == 0) 2200 if (err == 0)
@@ -2408,19 +2406,16 @@ static int rt6_info_route(struct rt6_info *rt, void *p_arg)
2408{ 2406{
2409 struct seq_file *m = p_arg; 2407 struct seq_file *m = p_arg;
2410 2408
2411 seq_printf(m, NIP6_SEQFMT " %02x ", NIP6(rt->rt6i_dst.addr), 2409 seq_printf(m, "%pi6 %02x ", &rt->rt6i_dst.addr, rt->rt6i_dst.plen);
2412 rt->rt6i_dst.plen);
2413 2410
2414#ifdef CONFIG_IPV6_SUBTREES 2411#ifdef CONFIG_IPV6_SUBTREES
2415 seq_printf(m, NIP6_SEQFMT " %02x ", NIP6(rt->rt6i_src.addr), 2412 seq_printf(m, "%pi6 %02x ", &rt->rt6i_src.addr, rt->rt6i_src.plen);
2416 rt->rt6i_src.plen);
2417#else 2413#else
2418 seq_puts(m, "00000000000000000000000000000000 00 "); 2414 seq_puts(m, "00000000000000000000000000000000 00 ");
2419#endif 2415#endif
2420 2416
2421 if (rt->rt6i_nexthop) { 2417 if (rt->rt6i_nexthop) {
2422 seq_printf(m, NIP6_SEQFMT, 2418 seq_printf(m, "%pi6", rt->rt6i_nexthop->primary_key);
2423 NIP6(*((struct in6_addr *)rt->rt6i_nexthop->primary_key)));
2424 } else { 2419 } else {
2425 seq_puts(m, "00000000000000000000000000000000"); 2420 seq_puts(m, "00000000000000000000000000000000");
2426 } 2421 }
@@ -2502,7 +2497,7 @@ ctl_table ipv6_route_table_template[] = {
2502 .data = &init_net.ipv6.sysctl.flush_delay, 2497 .data = &init_net.ipv6.sysctl.flush_delay,
2503 .maxlen = sizeof(int), 2498 .maxlen = sizeof(int),
2504 .mode = 0200, 2499 .mode = 0200,
2505 .proc_handler = &ipv6_sysctl_rtcache_flush 2500 .proc_handler = ipv6_sysctl_rtcache_flush
2506 }, 2501 },
2507 { 2502 {
2508 .ctl_name = NET_IPV6_ROUTE_GC_THRESH, 2503 .ctl_name = NET_IPV6_ROUTE_GC_THRESH,
@@ -2510,7 +2505,7 @@ ctl_table ipv6_route_table_template[] = {
2510 .data = &ip6_dst_ops_template.gc_thresh, 2505 .data = &ip6_dst_ops_template.gc_thresh,
2511 .maxlen = sizeof(int), 2506 .maxlen = sizeof(int),
2512 .mode = 0644, 2507 .mode = 0644,
2513 .proc_handler = &proc_dointvec, 2508 .proc_handler = proc_dointvec,
2514 }, 2509 },
2515 { 2510 {
2516 .ctl_name = NET_IPV6_ROUTE_MAX_SIZE, 2511 .ctl_name = NET_IPV6_ROUTE_MAX_SIZE,
@@ -2518,7 +2513,7 @@ ctl_table ipv6_route_table_template[] = {
2518 .data = &init_net.ipv6.sysctl.ip6_rt_max_size, 2513 .data = &init_net.ipv6.sysctl.ip6_rt_max_size,
2519 .maxlen = sizeof(int), 2514 .maxlen = sizeof(int),
2520 .mode = 0644, 2515 .mode = 0644,
2521 .proc_handler = &proc_dointvec, 2516 .proc_handler = proc_dointvec,
2522 }, 2517 },
2523 { 2518 {
2524 .ctl_name = NET_IPV6_ROUTE_GC_MIN_INTERVAL, 2519 .ctl_name = NET_IPV6_ROUTE_GC_MIN_INTERVAL,
@@ -2526,8 +2521,8 @@ ctl_table ipv6_route_table_template[] = {
2526 .data = &init_net.ipv6.sysctl.ip6_rt_gc_min_interval, 2521 .data = &init_net.ipv6.sysctl.ip6_rt_gc_min_interval,
2527 .maxlen = sizeof(int), 2522 .maxlen = sizeof(int),
2528 .mode = 0644, 2523 .mode = 0644,
2529 .proc_handler = &proc_dointvec_jiffies, 2524 .proc_handler = proc_dointvec_jiffies,
2530 .strategy = &sysctl_jiffies, 2525 .strategy = sysctl_jiffies,
2531 }, 2526 },
2532 { 2527 {
2533 .ctl_name = NET_IPV6_ROUTE_GC_TIMEOUT, 2528 .ctl_name = NET_IPV6_ROUTE_GC_TIMEOUT,
@@ -2535,8 +2530,8 @@ ctl_table ipv6_route_table_template[] = {
2535 .data = &init_net.ipv6.sysctl.ip6_rt_gc_timeout, 2530 .data = &init_net.ipv6.sysctl.ip6_rt_gc_timeout,
2536 .maxlen = sizeof(int), 2531 .maxlen = sizeof(int),
2537 .mode = 0644, 2532 .mode = 0644,
2538 .proc_handler = &proc_dointvec_jiffies, 2533 .proc_handler = proc_dointvec_jiffies,
2539 .strategy = &sysctl_jiffies, 2534 .strategy = sysctl_jiffies,
2540 }, 2535 },
2541 { 2536 {
2542 .ctl_name = NET_IPV6_ROUTE_GC_INTERVAL, 2537 .ctl_name = NET_IPV6_ROUTE_GC_INTERVAL,
@@ -2544,8 +2539,8 @@ ctl_table ipv6_route_table_template[] = {
2544 .data = &init_net.ipv6.sysctl.ip6_rt_gc_interval, 2539 .data = &init_net.ipv6.sysctl.ip6_rt_gc_interval,
2545 .maxlen = sizeof(int), 2540 .maxlen = sizeof(int),
2546 .mode = 0644, 2541 .mode = 0644,
2547 .proc_handler = &proc_dointvec_jiffies, 2542 .proc_handler = proc_dointvec_jiffies,
2548 .strategy = &sysctl_jiffies, 2543 .strategy = sysctl_jiffies,
2549 }, 2544 },
2550 { 2545 {
2551 .ctl_name = NET_IPV6_ROUTE_GC_ELASTICITY, 2546 .ctl_name = NET_IPV6_ROUTE_GC_ELASTICITY,
@@ -2553,8 +2548,8 @@ ctl_table ipv6_route_table_template[] = {
2553 .data = &init_net.ipv6.sysctl.ip6_rt_gc_elasticity, 2548 .data = &init_net.ipv6.sysctl.ip6_rt_gc_elasticity,
2554 .maxlen = sizeof(int), 2549 .maxlen = sizeof(int),
2555 .mode = 0644, 2550 .mode = 0644,
2556 .proc_handler = &proc_dointvec_jiffies, 2551 .proc_handler = proc_dointvec_jiffies,
2557 .strategy = &sysctl_jiffies, 2552 .strategy = sysctl_jiffies,
2558 }, 2553 },
2559 { 2554 {
2560 .ctl_name = NET_IPV6_ROUTE_MTU_EXPIRES, 2555 .ctl_name = NET_IPV6_ROUTE_MTU_EXPIRES,
@@ -2562,8 +2557,8 @@ ctl_table ipv6_route_table_template[] = {
2562 .data = &init_net.ipv6.sysctl.ip6_rt_mtu_expires, 2557 .data = &init_net.ipv6.sysctl.ip6_rt_mtu_expires,
2563 .maxlen = sizeof(int), 2558 .maxlen = sizeof(int),
2564 .mode = 0644, 2559 .mode = 0644,
2565 .proc_handler = &proc_dointvec_jiffies, 2560 .proc_handler = proc_dointvec_jiffies,
2566 .strategy = &sysctl_jiffies, 2561 .strategy = sysctl_jiffies,
2567 }, 2562 },
2568 { 2563 {
2569 .ctl_name = NET_IPV6_ROUTE_MIN_ADVMSS, 2564 .ctl_name = NET_IPV6_ROUTE_MIN_ADVMSS,
@@ -2571,8 +2566,8 @@ ctl_table ipv6_route_table_template[] = {
2571 .data = &init_net.ipv6.sysctl.ip6_rt_min_advmss, 2566 .data = &init_net.ipv6.sysctl.ip6_rt_min_advmss,
2572 .maxlen = sizeof(int), 2567 .maxlen = sizeof(int),
2573 .mode = 0644, 2568 .mode = 0644,
2574 .proc_handler = &proc_dointvec_jiffies, 2569 .proc_handler = proc_dointvec_jiffies,
2575 .strategy = &sysctl_jiffies, 2570 .strategy = sysctl_jiffies,
2576 }, 2571 },
2577 { 2572 {
2578 .ctl_name = NET_IPV6_ROUTE_GC_MIN_INTERVAL_MS, 2573 .ctl_name = NET_IPV6_ROUTE_GC_MIN_INTERVAL_MS,
@@ -2580,8 +2575,8 @@ ctl_table ipv6_route_table_template[] = {
2580 .data = &init_net.ipv6.sysctl.ip6_rt_gc_min_interval, 2575 .data = &init_net.ipv6.sysctl.ip6_rt_gc_min_interval,
2581 .maxlen = sizeof(int), 2576 .maxlen = sizeof(int),
2582 .mode = 0644, 2577 .mode = 0644,
2583 .proc_handler = &proc_dointvec_ms_jiffies, 2578 .proc_handler = proc_dointvec_ms_jiffies,
2584 .strategy = &sysctl_ms_jiffies, 2579 .strategy = sysctl_ms_jiffies,
2585 }, 2580 },
2586 { .ctl_name = 0 } 2581 { .ctl_name = 0 }
2587}; 2582};
diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
index b7a50e968506..d3467e563f02 100644
--- a/net/ipv6/sit.c
+++ b/net/ipv6/sit.c
@@ -62,8 +62,8 @@
62#define HASH_SIZE 16 62#define HASH_SIZE 16
63#define HASH(addr) (((__force u32)addr^((__force u32)addr>>4))&0xF) 63#define HASH(addr) (((__force u32)addr^((__force u32)addr>>4))&0xF)
64 64
65static int ipip6_fb_tunnel_init(struct net_device *dev); 65static void ipip6_fb_tunnel_init(struct net_device *dev);
66static int ipip6_tunnel_init(struct net_device *dev); 66static void ipip6_tunnel_init(struct net_device *dev);
67static void ipip6_tunnel_setup(struct net_device *dev); 67static void ipip6_tunnel_setup(struct net_device *dev);
68 68
69static int sit_net_id; 69static int sit_net_id;
@@ -188,7 +188,8 @@ static struct ip_tunnel * ipip6_tunnel_locate(struct net *net,
188 } 188 }
189 189
190 nt = netdev_priv(dev); 190 nt = netdev_priv(dev);
191 dev->init = ipip6_tunnel_init; 191 ipip6_tunnel_init(dev);
192
192 nt->parms = *parms; 193 nt->parms = *parms;
193 194
194 if (parms->i_flags & SIT_ISATAP) 195 if (parms->i_flags & SIT_ISATAP)
@@ -926,13 +927,17 @@ static int ipip6_tunnel_change_mtu(struct net_device *dev, int new_mtu)
926 return 0; 927 return 0;
927} 928}
928 929
930static const struct net_device_ops ipip6_netdev_ops = {
931 .ndo_uninit = ipip6_tunnel_uninit,
932 .ndo_start_xmit = ipip6_tunnel_xmit,
933 .ndo_do_ioctl = ipip6_tunnel_ioctl,
934 .ndo_change_mtu = ipip6_tunnel_change_mtu,
935};
936
929static void ipip6_tunnel_setup(struct net_device *dev) 937static void ipip6_tunnel_setup(struct net_device *dev)
930{ 938{
931 dev->uninit = ipip6_tunnel_uninit; 939 dev->netdev_ops = &ipip6_netdev_ops;
932 dev->destructor = free_netdev; 940 dev->destructor = free_netdev;
933 dev->hard_start_xmit = ipip6_tunnel_xmit;
934 dev->do_ioctl = ipip6_tunnel_ioctl;
935 dev->change_mtu = ipip6_tunnel_change_mtu;
936 941
937 dev->type = ARPHRD_SIT; 942 dev->type = ARPHRD_SIT;
938 dev->hard_header_len = LL_MAX_HEADER + sizeof(struct iphdr); 943 dev->hard_header_len = LL_MAX_HEADER + sizeof(struct iphdr);
@@ -943,11 +948,9 @@ static void ipip6_tunnel_setup(struct net_device *dev)
943 dev->features |= NETIF_F_NETNS_LOCAL; 948 dev->features |= NETIF_F_NETNS_LOCAL;
944} 949}
945 950
946static int ipip6_tunnel_init(struct net_device *dev) 951static void ipip6_tunnel_init(struct net_device *dev)
947{ 952{
948 struct ip_tunnel *tunnel; 953 struct ip_tunnel *tunnel = netdev_priv(dev);
949
950 tunnel = netdev_priv(dev);
951 954
952 tunnel->dev = dev; 955 tunnel->dev = dev;
953 strcpy(tunnel->parms.name, dev->name); 956 strcpy(tunnel->parms.name, dev->name);
@@ -956,11 +959,9 @@ static int ipip6_tunnel_init(struct net_device *dev)
956 memcpy(dev->broadcast, &tunnel->parms.iph.daddr, 4); 959 memcpy(dev->broadcast, &tunnel->parms.iph.daddr, 4);
957 960
958 ipip6_tunnel_bind_dev(dev); 961 ipip6_tunnel_bind_dev(dev);
959
960 return 0;
961} 962}
962 963
963static int ipip6_fb_tunnel_init(struct net_device *dev) 964static void ipip6_fb_tunnel_init(struct net_device *dev)
964{ 965{
965 struct ip_tunnel *tunnel = netdev_priv(dev); 966 struct ip_tunnel *tunnel = netdev_priv(dev);
966 struct iphdr *iph = &tunnel->parms.iph; 967 struct iphdr *iph = &tunnel->parms.iph;
@@ -977,7 +978,6 @@ static int ipip6_fb_tunnel_init(struct net_device *dev)
977 978
978 dev_hold(dev); 979 dev_hold(dev);
979 sitn->tunnels_wc[0] = tunnel; 980 sitn->tunnels_wc[0] = tunnel;
980 return 0;
981} 981}
982 982
983static struct xfrm_tunnel sit_handler = { 983static struct xfrm_tunnel sit_handler = {
@@ -1025,16 +1025,17 @@ static int sit_init_net(struct net *net)
1025 err = -ENOMEM; 1025 err = -ENOMEM;
1026 goto err_alloc_dev; 1026 goto err_alloc_dev;
1027 } 1027 }
1028
1029 sitn->fb_tunnel_dev->init = ipip6_fb_tunnel_init;
1030 dev_net_set(sitn->fb_tunnel_dev, net); 1028 dev_net_set(sitn->fb_tunnel_dev, net);
1031 1029
1030 ipip6_fb_tunnel_init(sitn->fb_tunnel_dev);
1031
1032 if ((err = register_netdev(sitn->fb_tunnel_dev))) 1032 if ((err = register_netdev(sitn->fb_tunnel_dev)))
1033 goto err_reg_dev; 1033 goto err_reg_dev;
1034 1034
1035 return 0; 1035 return 0;
1036 1036
1037err_reg_dev: 1037err_reg_dev:
1038 dev_put(sitn->fb_tunnel_dev);
1038 free_netdev(sitn->fb_tunnel_dev); 1039 free_netdev(sitn->fb_tunnel_dev);
1039err_alloc_dev: 1040err_alloc_dev:
1040 /* nothing */ 1041 /* nothing */
diff --git a/net/ipv6/syncookies.c b/net/ipv6/syncookies.c
index 676c80b5b14b..711175e0571f 100644
--- a/net/ipv6/syncookies.c
+++ b/net/ipv6/syncookies.c
@@ -259,7 +259,7 @@ struct sock *cookie_v6_check(struct sock *sk, struct sk_buff *skb)
259 259
260 if (final_p) 260 if (final_p)
261 ipv6_addr_copy(&fl.fl6_dst, final_p); 261 ipv6_addr_copy(&fl.fl6_dst, final_p);
262 if ((xfrm_lookup(&dst, &fl, sk, 0)) < 0) 262 if ((xfrm_lookup(sock_net(sk), &dst, &fl, sk, 0)) < 0)
263 goto out_free; 263 goto out_free;
264 } 264 }
265 265
diff --git a/net/ipv6/sysctl_net_ipv6.c b/net/ipv6/sysctl_net_ipv6.c
index 587f8f60c489..9048fe7e7ea7 100644
--- a/net/ipv6/sysctl_net_ipv6.c
+++ b/net/ipv6/sysctl_net_ipv6.c
@@ -35,7 +35,7 @@ static ctl_table ipv6_table_template[] = {
35 .data = &init_net.ipv6.sysctl.bindv6only, 35 .data = &init_net.ipv6.sysctl.bindv6only,
36 .maxlen = sizeof(int), 36 .maxlen = sizeof(int),
37 .mode = 0644, 37 .mode = 0644,
38 .proc_handler = &proc_dointvec 38 .proc_handler = proc_dointvec
39 }, 39 },
40 { .ctl_name = 0 } 40 { .ctl_name = 0 }
41}; 41};
@@ -47,7 +47,7 @@ static ctl_table ipv6_table[] = {
47 .data = &sysctl_mld_max_msf, 47 .data = &sysctl_mld_max_msf,
48 .maxlen = sizeof(int), 48 .maxlen = sizeof(int),
49 .mode = 0644, 49 .mode = 0644,
50 .proc_handler = &proc_dointvec 50 .proc_handler = proc_dointvec
51 }, 51 },
52 { .ctl_name = 0 } 52 { .ctl_name = 0 }
53}; 53};
diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
index b6b356b7912a..8702b06cb60a 100644
--- a/net/ipv6/tcp_ipv6.c
+++ b/net/ipv6/tcp_ipv6.c
@@ -260,7 +260,8 @@ static int tcp_v6_connect(struct sock *sk, struct sockaddr *uaddr,
260 if (final_p) 260 if (final_p)
261 ipv6_addr_copy(&fl.fl6_dst, final_p); 261 ipv6_addr_copy(&fl.fl6_dst, final_p);
262 262
263 if ((err = __xfrm_lookup(&dst, &fl, sk, XFRM_LOOKUP_WAIT)) < 0) { 263 err = __xfrm_lookup(sock_net(sk), &dst, &fl, sk, XFRM_LOOKUP_WAIT);
264 if (err < 0) {
264 if (err == -EREMOTE) 265 if (err == -EREMOTE)
265 err = ip6_dst_blackhole(sk, &dst, &fl); 266 err = ip6_dst_blackhole(sk, &dst, &fl);
266 if (err < 0) 267 if (err < 0)
@@ -390,7 +391,7 @@ static void tcp_v6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
390 goto out; 391 goto out;
391 } 392 }
392 393
393 if ((err = xfrm_lookup(&dst, &fl, sk, 0)) < 0) { 394 if ((err = xfrm_lookup(net, &dst, &fl, sk, 0)) < 0) {
394 sk->sk_err_soft = -err; 395 sk->sk_err_soft = -err;
395 goto out; 396 goto out;
396 } 397 }
@@ -492,7 +493,7 @@ static int tcp_v6_send_synack(struct sock *sk, struct request_sock *req)
492 goto done; 493 goto done;
493 if (final_p) 494 if (final_p)
494 ipv6_addr_copy(&fl.fl6_dst, final_p); 495 ipv6_addr_copy(&fl.fl6_dst, final_p);
495 if ((err = xfrm_lookup(&dst, &fl, sk, 0)) < 0) 496 if ((err = xfrm_lookup(sock_net(sk), &dst, &fl, sk, 0)) < 0)
496 goto done; 497 goto done;
497 498
498 skb = tcp_make_synack(sk, dst, req); 499 skb = tcp_make_synack(sk, dst, req);
@@ -501,7 +502,7 @@ static int tcp_v6_send_synack(struct sock *sk, struct request_sock *req)
501 502
502 th->check = tcp_v6_check(th, skb->len, 503 th->check = tcp_v6_check(th, skb->len,
503 &treq->loc_addr, &treq->rmt_addr, 504 &treq->loc_addr, &treq->rmt_addr,
504 csum_partial((char *)th, skb->len, skb->csum)); 505 csum_partial(th, skb->len, skb->csum));
505 506
506 ipv6_addr_copy(&fl.fl6_dst, &treq->rmt_addr); 507 ipv6_addr_copy(&fl.fl6_dst, &treq->rmt_addr);
507 err = ip6_xmit(sk, skb, &fl, opt, 0); 508 err = ip6_xmit(sk, skb, &fl, opt, 0);
@@ -872,12 +873,10 @@ static int tcp_v6_inbound_md5_hash (struct sock *sk, struct sk_buff *skb)
872 873
873 if (genhash || memcmp(hash_location, newhash, 16) != 0) { 874 if (genhash || memcmp(hash_location, newhash, 16) != 0) {
874 if (net_ratelimit()) { 875 if (net_ratelimit()) {
875 printk(KERN_INFO "MD5 Hash %s for " 876 printk(KERN_INFO "MD5 Hash %s for (%pI6, %u)->(%pI6, %u)\n",
876 "(" NIP6_FMT ", %u)->"
877 "(" NIP6_FMT ", %u)\n",
878 genhash ? "failed" : "mismatch", 877 genhash ? "failed" : "mismatch",
879 NIP6(ip6h->saddr), ntohs(th->source), 878 &ip6h->saddr, ntohs(th->source),
880 NIP6(ip6h->daddr), ntohs(th->dest)); 879 &ip6h->daddr, ntohs(th->dest));
881 } 880 }
882 return 1; 881 return 1;
883 } 882 }
@@ -917,7 +916,7 @@ static void tcp_v6_send_check(struct sock *sk, int len, struct sk_buff *skb)
917 skb->csum_offset = offsetof(struct tcphdr, check); 916 skb->csum_offset = offsetof(struct tcphdr, check);
918 } else { 917 } else {
919 th->check = csum_ipv6_magic(&np->saddr, &np->daddr, len, IPPROTO_TCP, 918 th->check = csum_ipv6_magic(&np->saddr, &np->daddr, len, IPPROTO_TCP,
920 csum_partial((char *)th, th->doff<<2, 919 csum_partial(th, th->doff<<2,
921 skb->csum)); 920 skb->csum));
922 } 921 }
923} 922}
@@ -999,7 +998,7 @@ static void tcp_v6_send_response(struct sk_buff *skb, u32 seq, u32 ack, u32 win,
999 } 998 }
1000#endif 999#endif
1001 1000
1002 buff->csum = csum_partial((char *)t1, tot_len, 0); 1001 buff->csum = csum_partial(t1, tot_len, 0);
1003 1002
1004 memset(&fl, 0, sizeof(fl)); 1003 memset(&fl, 0, sizeof(fl));
1005 ipv6_addr_copy(&fl.fl6_dst, &ipv6_hdr(skb)->saddr); 1004 ipv6_addr_copy(&fl.fl6_dst, &ipv6_hdr(skb)->saddr);
@@ -1020,7 +1019,7 @@ static void tcp_v6_send_response(struct sk_buff *skb, u32 seq, u32 ack, u32 win,
1020 * namespace 1019 * namespace
1021 */ 1020 */
1022 if (!ip6_dst_lookup(ctl_sk, &buff->dst, &fl)) { 1021 if (!ip6_dst_lookup(ctl_sk, &buff->dst, &fl)) {
1023 if (xfrm_lookup(&buff->dst, &fl, NULL, 0) >= 0) { 1022 if (xfrm_lookup(net, &buff->dst, &fl, NULL, 0) >= 0) {
1024 ip6_xmit(ctl_sk, buff, &fl, NULL, 0); 1023 ip6_xmit(ctl_sk, buff, &fl, NULL, 0);
1025 TCP_INC_STATS_BH(net, TCP_MIB_OUTSEGS); 1024 TCP_INC_STATS_BH(net, TCP_MIB_OUTSEGS);
1026 if (rst) 1025 if (rst)
@@ -1318,7 +1317,7 @@ static struct sock * tcp_v6_syn_recv_sock(struct sock *sk, struct sk_buff *skb,
1318 if (final_p) 1317 if (final_p)
1319 ipv6_addr_copy(&fl.fl6_dst, final_p); 1318 ipv6_addr_copy(&fl.fl6_dst, final_p);
1320 1319
1321 if ((xfrm_lookup(&dst, &fl, sk, 0)) < 0) 1320 if ((xfrm_lookup(sock_net(sk), &dst, &fl, sk, 0)) < 0)
1322 goto out; 1321 goto out;
1323 } 1322 }
1324 1323
@@ -1831,7 +1830,7 @@ static int tcp_v6_init_sock(struct sock *sk)
1831 sk->sk_sndbuf = sysctl_tcp_wmem[1]; 1830 sk->sk_sndbuf = sysctl_tcp_wmem[1];
1832 sk->sk_rcvbuf = sysctl_tcp_rmem[1]; 1831 sk->sk_rcvbuf = sysctl_tcp_rmem[1];
1833 1832
1834 atomic_inc(&tcp_sockets_allocated); 1833 percpu_counter_inc(&tcp_sockets_allocated);
1835 1834
1836 return 0; 1835 return 0;
1837} 1836}
@@ -2045,6 +2044,7 @@ struct proto tcpv6_prot = {
2045 .sysctl_rmem = sysctl_tcp_rmem, 2044 .sysctl_rmem = sysctl_tcp_rmem,
2046 .max_header = MAX_TCP_HEADER, 2045 .max_header = MAX_TCP_HEADER,
2047 .obj_size = sizeof(struct tcp6_sock), 2046 .obj_size = sizeof(struct tcp6_sock),
2047 .slab_flags = SLAB_DESTROY_BY_RCU,
2048 .twsk_prot = &tcp6_timewait_sock_ops, 2048 .twsk_prot = &tcp6_timewait_sock_ops,
2049 .rsk_prot = &tcp6_request_sock_ops, 2049 .rsk_prot = &tcp6_request_sock_ops,
2050 .h.hashinfo = &tcp_hashinfo, 2050 .h.hashinfo = &tcp_hashinfo,
diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
index 8b48512ebf6a..84b1a296eecb 100644
--- a/net/ipv6/udp.c
+++ b/net/ipv6/udp.c
@@ -54,62 +54,91 @@ int udp_v6_get_port(struct sock *sk, unsigned short snum)
54 return udp_lib_get_port(sk, snum, ipv6_rcv_saddr_equal); 54 return udp_lib_get_port(sk, snum, ipv6_rcv_saddr_equal);
55} 55}
56 56
57static inline int compute_score(struct sock *sk, struct net *net,
58 unsigned short hnum,
59 struct in6_addr *saddr, __be16 sport,
60 struct in6_addr *daddr, __be16 dport,
61 int dif)
62{
63 int score = -1;
64
65 if (net_eq(sock_net(sk), net) && sk->sk_hash == hnum &&
66 sk->sk_family == PF_INET6) {
67 struct ipv6_pinfo *np = inet6_sk(sk);
68 struct inet_sock *inet = inet_sk(sk);
69
70 score = 0;
71 if (inet->dport) {
72 if (inet->dport != sport)
73 return -1;
74 score++;
75 }
76 if (!ipv6_addr_any(&np->rcv_saddr)) {
77 if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
78 return -1;
79 score++;
80 }
81 if (!ipv6_addr_any(&np->daddr)) {
82 if (!ipv6_addr_equal(&np->daddr, saddr))
83 return -1;
84 score++;
85 }
86 if (sk->sk_bound_dev_if) {
87 if (sk->sk_bound_dev_if != dif)
88 return -1;
89 score++;
90 }
91 }
92 return score;
93}
94
57static struct sock *__udp6_lib_lookup(struct net *net, 95static struct sock *__udp6_lib_lookup(struct net *net,
58 struct in6_addr *saddr, __be16 sport, 96 struct in6_addr *saddr, __be16 sport,
59 struct in6_addr *daddr, __be16 dport, 97 struct in6_addr *daddr, __be16 dport,
60 int dif, struct hlist_head udptable[]) 98 int dif, struct udp_table *udptable)
61{ 99{
62 struct sock *sk, *result = NULL; 100 struct sock *sk, *result;
63 struct hlist_node *node; 101 struct hlist_nulls_node *node;
64 unsigned short hnum = ntohs(dport); 102 unsigned short hnum = ntohs(dport);
65 int badness = -1; 103 unsigned int hash = udp_hashfn(net, hnum);
66 104 struct udp_hslot *hslot = &udptable->hash[hash];
67 read_lock(&udp_hash_lock); 105 int score, badness;
68 sk_for_each(sk, node, &udptable[udp_hashfn(net, hnum)]) { 106
69 struct inet_sock *inet = inet_sk(sk); 107 rcu_read_lock();
70 108begin:
71 if (net_eq(sock_net(sk), net) && sk->sk_hash == hnum && 109 result = NULL;
72 sk->sk_family == PF_INET6) { 110 badness = -1;
73 struct ipv6_pinfo *np = inet6_sk(sk); 111 sk_nulls_for_each_rcu(sk, node, &hslot->head) {
74 int score = 0; 112 score = compute_score(sk, net, hnum, saddr, sport, daddr, dport, dif);
75 if (inet->dport) { 113 if (score > badness) {
76 if (inet->dport != sport) 114 result = sk;
77 continue; 115 badness = score;
78 score++;
79 }
80 if (!ipv6_addr_any(&np->rcv_saddr)) {
81 if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
82 continue;
83 score++;
84 }
85 if (!ipv6_addr_any(&np->daddr)) {
86 if (!ipv6_addr_equal(&np->daddr, saddr))
87 continue;
88 score++;
89 }
90 if (sk->sk_bound_dev_if) {
91 if (sk->sk_bound_dev_if != dif)
92 continue;
93 score++;
94 }
95 if (score == 4) {
96 result = sk;
97 break;
98 } else if (score > badness) {
99 result = sk;
100 badness = score;
101 }
102 } 116 }
103 } 117 }
104 if (result) 118 /*
105 sock_hold(result); 119 * if the nulls value we got at the end of this lookup is
106 read_unlock(&udp_hash_lock); 120 * not the expected one, we must restart lookup.
121 * We probably met an item that was moved to another chain.
122 */
123 if (get_nulls_value(node) != hash)
124 goto begin;
125
126 if (result) {
127 if (unlikely(!atomic_inc_not_zero(&result->sk_refcnt)))
128 result = NULL;
129 else if (unlikely(compute_score(result, net, hnum, saddr, sport,
130 daddr, dport, dif) < badness)) {
131 sock_put(result);
132 goto begin;
133 }
134 }
135 rcu_read_unlock();
107 return result; 136 return result;
108} 137}
109 138
110static struct sock *__udp6_lib_lookup_skb(struct sk_buff *skb, 139static struct sock *__udp6_lib_lookup_skb(struct sk_buff *skb,
111 __be16 sport, __be16 dport, 140 __be16 sport, __be16 dport,
112 struct hlist_head udptable[]) 141 struct udp_table *udptable)
113{ 142{
114 struct sock *sk; 143 struct sock *sk;
115 struct ipv6hdr *iph = ipv6_hdr(skb); 144 struct ipv6hdr *iph = ipv6_hdr(skb);
@@ -253,7 +282,7 @@ csum_copy_err:
253 282
254void __udp6_lib_err(struct sk_buff *skb, struct inet6_skb_parm *opt, 283void __udp6_lib_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
255 int type, int code, int offset, __be32 info, 284 int type, int code, int offset, __be32 info,
256 struct hlist_head udptable[] ) 285 struct udp_table *udptable)
257{ 286{
258 struct ipv6_pinfo *np; 287 struct ipv6_pinfo *np;
259 struct ipv6hdr *hdr = (struct ipv6hdr*)skb->data; 288 struct ipv6hdr *hdr = (struct ipv6hdr*)skb->data;
@@ -289,7 +318,7 @@ static __inline__ void udpv6_err(struct sk_buff *skb,
289 struct inet6_skb_parm *opt, int type, 318 struct inet6_skb_parm *opt, int type,
290 int code, int offset, __be32 info ) 319 int code, int offset, __be32 info )
291{ 320{
292 __udp6_lib_err(skb, opt, type, code, offset, info, udp_hash); 321 __udp6_lib_err(skb, opt, type, code, offset, info, &udp_table);
293} 322}
294 323
295int udpv6_queue_rcv_skb(struct sock * sk, struct sk_buff *skb) 324int udpv6_queue_rcv_skb(struct sock * sk, struct sk_buff *skb)
@@ -347,11 +376,11 @@ static struct sock *udp_v6_mcast_next(struct net *net, struct sock *sk,
347 __be16 rmt_port, struct in6_addr *rmt_addr, 376 __be16 rmt_port, struct in6_addr *rmt_addr,
348 int dif) 377 int dif)
349{ 378{
350 struct hlist_node *node; 379 struct hlist_nulls_node *node;
351 struct sock *s = sk; 380 struct sock *s = sk;
352 unsigned short num = ntohs(loc_port); 381 unsigned short num = ntohs(loc_port);
353 382
354 sk_for_each_from(s, node) { 383 sk_nulls_for_each_from(s, node) {
355 struct inet_sock *inet = inet_sk(s); 384 struct inet_sock *inet = inet_sk(s);
356 385
357 if (!net_eq(sock_net(s), net)) 386 if (!net_eq(sock_net(s), net))
@@ -388,14 +417,15 @@ static struct sock *udp_v6_mcast_next(struct net *net, struct sock *sk,
388 */ 417 */
389static int __udp6_lib_mcast_deliver(struct net *net, struct sk_buff *skb, 418static int __udp6_lib_mcast_deliver(struct net *net, struct sk_buff *skb,
390 struct in6_addr *saddr, struct in6_addr *daddr, 419 struct in6_addr *saddr, struct in6_addr *daddr,
391 struct hlist_head udptable[]) 420 struct udp_table *udptable)
392{ 421{
393 struct sock *sk, *sk2; 422 struct sock *sk, *sk2;
394 const struct udphdr *uh = udp_hdr(skb); 423 const struct udphdr *uh = udp_hdr(skb);
424 struct udp_hslot *hslot = &udptable->hash[udp_hashfn(net, ntohs(uh->dest))];
395 int dif; 425 int dif;
396 426
397 read_lock(&udp_hash_lock); 427 spin_lock(&hslot->lock);
398 sk = sk_head(&udptable[udp_hashfn(net, ntohs(uh->dest))]); 428 sk = sk_nulls_head(&hslot->head);
399 dif = inet6_iif(skb); 429 dif = inet6_iif(skb);
400 sk = udp_v6_mcast_next(net, sk, uh->dest, daddr, uh->source, saddr, dif); 430 sk = udp_v6_mcast_next(net, sk, uh->dest, daddr, uh->source, saddr, dif);
401 if (!sk) { 431 if (!sk) {
@@ -404,7 +434,7 @@ static int __udp6_lib_mcast_deliver(struct net *net, struct sk_buff *skb,
404 } 434 }
405 435
406 sk2 = sk; 436 sk2 = sk;
407 while ((sk2 = udp_v6_mcast_next(net, sk_next(sk2), uh->dest, daddr, 437 while ((sk2 = udp_v6_mcast_next(net, sk_nulls_next(sk2), uh->dest, daddr,
408 uh->source, saddr, dif))) { 438 uh->source, saddr, dif))) {
409 struct sk_buff *buff = skb_clone(skb, GFP_ATOMIC); 439 struct sk_buff *buff = skb_clone(skb, GFP_ATOMIC);
410 if (buff) { 440 if (buff) {
@@ -423,7 +453,7 @@ static int __udp6_lib_mcast_deliver(struct net *net, struct sk_buff *skb,
423 sk_add_backlog(sk, skb); 453 sk_add_backlog(sk, skb);
424 bh_unlock_sock(sk); 454 bh_unlock_sock(sk);
425out: 455out:
426 read_unlock(&udp_hash_lock); 456 spin_unlock(&hslot->lock);
427 return 0; 457 return 0;
428} 458}
429 459
@@ -461,7 +491,7 @@ static inline int udp6_csum_init(struct sk_buff *skb, struct udphdr *uh,
461 return 0; 491 return 0;
462} 492}
463 493
464int __udp6_lib_rcv(struct sk_buff *skb, struct hlist_head udptable[], 494int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
465 int proto) 495 int proto)
466{ 496{
467 struct sock *sk; 497 struct sock *sk;
@@ -558,7 +588,7 @@ discard:
558 588
559static __inline__ int udpv6_rcv(struct sk_buff *skb) 589static __inline__ int udpv6_rcv(struct sk_buff *skb)
560{ 590{
561 return __udp6_lib_rcv(skb, udp_hash, IPPROTO_UDP); 591 return __udp6_lib_rcv(skb, &udp_table, IPPROTO_UDP);
562} 592}
563 593
564/* 594/*
@@ -763,6 +793,9 @@ do_udp_sendmsg:
763 if (!fl.oif) 793 if (!fl.oif)
764 fl.oif = sk->sk_bound_dev_if; 794 fl.oif = sk->sk_bound_dev_if;
765 795
796 if (!fl.oif)
797 fl.oif = np->sticky_pktinfo.ipi6_ifindex;
798
766 if (msg->msg_controllen) { 799 if (msg->msg_controllen) {
767 opt = &opt_space; 800 opt = &opt_space;
768 memset(opt, 0, sizeof(struct ipv6_txoptions)); 801 memset(opt, 0, sizeof(struct ipv6_txoptions));
@@ -819,7 +852,8 @@ do_udp_sendmsg:
819 if (final_p) 852 if (final_p)
820 ipv6_addr_copy(&fl.fl6_dst, final_p); 853 ipv6_addr_copy(&fl.fl6_dst, final_p);
821 854
822 if ((err = __xfrm_lookup(&dst, &fl, sk, XFRM_LOOKUP_WAIT)) < 0) { 855 err = __xfrm_lookup(sock_net(sk), &dst, &fl, sk, XFRM_LOOKUP_WAIT);
856 if (err < 0) {
823 if (err == -EREMOTE) 857 if (err == -EREMOTE)
824 err = ip6_dst_blackhole(sk, &dst, &fl); 858 err = ip6_dst_blackhole(sk, &dst, &fl);
825 if (err < 0) 859 if (err < 0)
@@ -1022,7 +1056,7 @@ int udp6_seq_show(struct seq_file *seq, void *v)
1022static struct udp_seq_afinfo udp6_seq_afinfo = { 1056static struct udp_seq_afinfo udp6_seq_afinfo = {
1023 .name = "udp6", 1057 .name = "udp6",
1024 .family = AF_INET6, 1058 .family = AF_INET6,
1025 .hashtable = udp_hash, 1059 .udp_table = &udp_table,
1026 .seq_fops = { 1060 .seq_fops = {
1027 .owner = THIS_MODULE, 1061 .owner = THIS_MODULE,
1028 }, 1062 },
@@ -1064,7 +1098,8 @@ struct proto udpv6_prot = {
1064 .sysctl_wmem = &sysctl_udp_wmem_min, 1098 .sysctl_wmem = &sysctl_udp_wmem_min,
1065 .sysctl_rmem = &sysctl_udp_rmem_min, 1099 .sysctl_rmem = &sysctl_udp_rmem_min,
1066 .obj_size = sizeof(struct udp6_sock), 1100 .obj_size = sizeof(struct udp6_sock),
1067 .h.udp_hash = udp_hash, 1101 .slab_flags = SLAB_DESTROY_BY_RCU,
1102 .h.udp_table = &udp_table,
1068#ifdef CONFIG_COMPAT 1103#ifdef CONFIG_COMPAT
1069 .compat_setsockopt = compat_udpv6_setsockopt, 1104 .compat_setsockopt = compat_udpv6_setsockopt,
1070 .compat_getsockopt = compat_udpv6_getsockopt, 1105 .compat_getsockopt = compat_udpv6_getsockopt,
diff --git a/net/ipv6/udp_impl.h b/net/ipv6/udp_impl.h
index 92dd7da766d8..23779208c334 100644
--- a/net/ipv6/udp_impl.h
+++ b/net/ipv6/udp_impl.h
@@ -7,9 +7,9 @@
7#include <net/inet_common.h> 7#include <net/inet_common.h>
8#include <net/transp_v6.h> 8#include <net/transp_v6.h>
9 9
10extern int __udp6_lib_rcv(struct sk_buff *, struct hlist_head [], int ); 10extern int __udp6_lib_rcv(struct sk_buff *, struct udp_table *, int );
11extern void __udp6_lib_err(struct sk_buff *, struct inet6_skb_parm *, 11extern void __udp6_lib_err(struct sk_buff *, struct inet6_skb_parm *,
12 int , int , int , __be32 , struct hlist_head []); 12 int , int , int , __be32 , struct udp_table *);
13 13
14extern int udp_v6_get_port(struct sock *sk, unsigned short snum); 14extern int udp_v6_get_port(struct sock *sk, unsigned short snum);
15 15
diff --git a/net/ipv6/udplite.c b/net/ipv6/udplite.c
index 3cd1a1ac3d6c..ba162a824585 100644
--- a/net/ipv6/udplite.c
+++ b/net/ipv6/udplite.c
@@ -15,14 +15,14 @@
15 15
16static int udplitev6_rcv(struct sk_buff *skb) 16static int udplitev6_rcv(struct sk_buff *skb)
17{ 17{
18 return __udp6_lib_rcv(skb, udplite_hash, IPPROTO_UDPLITE); 18 return __udp6_lib_rcv(skb, &udplite_table, IPPROTO_UDPLITE);
19} 19}
20 20
21static void udplitev6_err(struct sk_buff *skb, 21static void udplitev6_err(struct sk_buff *skb,
22 struct inet6_skb_parm *opt, 22 struct inet6_skb_parm *opt,
23 int type, int code, int offset, __be32 info) 23 int type, int code, int offset, __be32 info)
24{ 24{
25 __udp6_lib_err(skb, opt, type, code, offset, info, udplite_hash); 25 __udp6_lib_err(skb, opt, type, code, offset, info, &udplite_table);
26} 26}
27 27
28static struct inet6_protocol udplitev6_protocol = { 28static struct inet6_protocol udplitev6_protocol = {
@@ -49,7 +49,8 @@ struct proto udplitev6_prot = {
49 .unhash = udp_lib_unhash, 49 .unhash = udp_lib_unhash,
50 .get_port = udp_v6_get_port, 50 .get_port = udp_v6_get_port,
51 .obj_size = sizeof(struct udp6_sock), 51 .obj_size = sizeof(struct udp6_sock),
52 .h.udp_hash = udplite_hash, 52 .slab_flags = SLAB_DESTROY_BY_RCU,
53 .h.udp_table = &udplite_table,
53#ifdef CONFIG_COMPAT 54#ifdef CONFIG_COMPAT
54 .compat_setsockopt = compat_udpv6_setsockopt, 55 .compat_setsockopt = compat_udpv6_setsockopt,
55 .compat_getsockopt = compat_udpv6_getsockopt, 56 .compat_getsockopt = compat_udpv6_getsockopt,
@@ -95,7 +96,7 @@ void udplitev6_exit(void)
95static struct udp_seq_afinfo udplite6_seq_afinfo = { 96static struct udp_seq_afinfo udplite6_seq_afinfo = {
96 .name = "udplite6", 97 .name = "udplite6",
97 .family = AF_INET6, 98 .family = AF_INET6,
98 .hashtable = udplite_hash, 99 .udp_table = &udplite_table,
99 .seq_fops = { 100 .seq_fops = {
100 .owner = THIS_MODULE, 101 .owner = THIS_MODULE,
101 }, 102 },
diff --git a/net/ipv6/xfrm6_input.c b/net/ipv6/xfrm6_input.c
index a71c7ddcb41e..9084582d236b 100644
--- a/net/ipv6/xfrm6_input.c
+++ b/net/ipv6/xfrm6_input.c
@@ -58,6 +58,7 @@ EXPORT_SYMBOL(xfrm6_rcv);
58int xfrm6_input_addr(struct sk_buff *skb, xfrm_address_t *daddr, 58int xfrm6_input_addr(struct sk_buff *skb, xfrm_address_t *daddr,
59 xfrm_address_t *saddr, u8 proto) 59 xfrm_address_t *saddr, u8 proto)
60{ 60{
61 struct net *net = dev_net(skb->dev);
61 struct xfrm_state *x = NULL; 62 struct xfrm_state *x = NULL;
62 int i = 0; 63 int i = 0;
63 64
@@ -67,7 +68,7 @@ int xfrm6_input_addr(struct sk_buff *skb, xfrm_address_t *daddr,
67 68
68 sp = secpath_dup(skb->sp); 69 sp = secpath_dup(skb->sp);
69 if (!sp) { 70 if (!sp) {
70 XFRM_INC_STATS(LINUX_MIB_XFRMINERROR); 71 XFRM_INC_STATS(net, LINUX_MIB_XFRMINERROR);
71 goto drop; 72 goto drop;
72 } 73 }
73 if (skb->sp) 74 if (skb->sp)
@@ -76,7 +77,7 @@ int xfrm6_input_addr(struct sk_buff *skb, xfrm_address_t *daddr,
76 } 77 }
77 78
78 if (1 + skb->sp->len == XFRM_MAX_DEPTH) { 79 if (1 + skb->sp->len == XFRM_MAX_DEPTH) {
79 XFRM_INC_STATS(LINUX_MIB_XFRMINBUFFERERROR); 80 XFRM_INC_STATS(net, LINUX_MIB_XFRMINBUFFERERROR);
80 goto drop; 81 goto drop;
81 } 82 }
82 83
@@ -100,7 +101,7 @@ int xfrm6_input_addr(struct sk_buff *skb, xfrm_address_t *daddr,
100 break; 101 break;
101 } 102 }
102 103
103 x = xfrm_state_lookup_byaddr(dst, src, proto, AF_INET6); 104 x = xfrm_state_lookup_byaddr(net, dst, src, proto, AF_INET6);
104 if (!x) 105 if (!x)
105 continue; 106 continue;
106 107
@@ -122,7 +123,7 @@ int xfrm6_input_addr(struct sk_buff *skb, xfrm_address_t *daddr,
122 } 123 }
123 124
124 if (!x) { 125 if (!x) {
125 XFRM_INC_STATS(LINUX_MIB_XFRMINNOSTATES); 126 XFRM_INC_STATS(net, LINUX_MIB_XFRMINNOSTATES);
126 xfrm_audit_state_notfound_simple(skb, AF_INET6); 127 xfrm_audit_state_notfound_simple(skb, AF_INET6);
127 goto drop; 128 goto drop;
128 } 129 }
diff --git a/net/ipv6/xfrm6_policy.c b/net/ipv6/xfrm6_policy.c
index 08e4cbbe3f04..97ab068e8ccc 100644
--- a/net/ipv6/xfrm6_policy.c
+++ b/net/ipv6/xfrm6_policy.c
@@ -27,7 +27,8 @@
27static struct dst_ops xfrm6_dst_ops; 27static struct dst_ops xfrm6_dst_ops;
28static struct xfrm_policy_afinfo xfrm6_policy_afinfo; 28static struct xfrm_policy_afinfo xfrm6_policy_afinfo;
29 29
30static struct dst_entry *xfrm6_dst_lookup(int tos, xfrm_address_t *saddr, 30static struct dst_entry *xfrm6_dst_lookup(struct net *net, int tos,
31 xfrm_address_t *saddr,
31 xfrm_address_t *daddr) 32 xfrm_address_t *daddr)
32{ 33{
33 struct flowi fl = {}; 34 struct flowi fl = {};
@@ -38,7 +39,7 @@ static struct dst_entry *xfrm6_dst_lookup(int tos, xfrm_address_t *saddr,
38 if (saddr) 39 if (saddr)
39 memcpy(&fl.fl6_src, saddr, sizeof(fl.fl6_src)); 40 memcpy(&fl.fl6_src, saddr, sizeof(fl.fl6_src));
40 41
41 dst = ip6_route_output(&init_net, NULL, &fl); 42 dst = ip6_route_output(net, NULL, &fl);
42 43
43 err = dst->error; 44 err = dst->error;
44 if (dst->error) { 45 if (dst->error) {
@@ -49,12 +50,13 @@ static struct dst_entry *xfrm6_dst_lookup(int tos, xfrm_address_t *saddr,
49 return dst; 50 return dst;
50} 51}
51 52
52static int xfrm6_get_saddr(xfrm_address_t *saddr, xfrm_address_t *daddr) 53static int xfrm6_get_saddr(struct net *net,
54 xfrm_address_t *saddr, xfrm_address_t *daddr)
53{ 55{
54 struct dst_entry *dst; 56 struct dst_entry *dst;
55 struct net_device *dev; 57 struct net_device *dev;
56 58
57 dst = xfrm6_dst_lookup(0, NULL, daddr); 59 dst = xfrm6_dst_lookup(net, 0, NULL, daddr);
58 if (IS_ERR(dst)) 60 if (IS_ERR(dst))
59 return -EHOSTUNREACH; 61 return -EHOSTUNREACH;
60 62
@@ -144,6 +146,7 @@ static int xfrm6_fill_dst(struct xfrm_dst *xdst, struct net_device *dev)
144static inline void 146static inline void
145_decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse) 147_decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
146{ 148{
149 int onlyproto = 0;
147 u16 offset = skb_network_header_len(skb); 150 u16 offset = skb_network_header_len(skb);
148 struct ipv6hdr *hdr = ipv6_hdr(skb); 151 struct ipv6hdr *hdr = ipv6_hdr(skb);
149 struct ipv6_opt_hdr *exthdr; 152 struct ipv6_opt_hdr *exthdr;
@@ -159,6 +162,8 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
159 exthdr = (struct ipv6_opt_hdr *)(nh + offset); 162 exthdr = (struct ipv6_opt_hdr *)(nh + offset);
160 163
161 switch (nexthdr) { 164 switch (nexthdr) {
165 case NEXTHDR_FRAGMENT:
166 onlyproto = 1;
162 case NEXTHDR_ROUTING: 167 case NEXTHDR_ROUTING:
163 case NEXTHDR_HOP: 168 case NEXTHDR_HOP:
164 case NEXTHDR_DEST: 169 case NEXTHDR_DEST:
@@ -172,7 +177,7 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
172 case IPPROTO_TCP: 177 case IPPROTO_TCP:
173 case IPPROTO_SCTP: 178 case IPPROTO_SCTP:
174 case IPPROTO_DCCP: 179 case IPPROTO_DCCP:
175 if (pskb_may_pull(skb, nh + offset + 4 - skb->data)) { 180 if (!onlyproto && pskb_may_pull(skb, nh + offset + 4 - skb->data)) {
176 __be16 *ports = (__be16 *)exthdr; 181 __be16 *ports = (__be16 *)exthdr;
177 182
178 fl->fl_ip_sport = ports[!!reverse]; 183 fl->fl_ip_sport = ports[!!reverse];
@@ -182,7 +187,7 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
182 return; 187 return;
183 188
184 case IPPROTO_ICMPV6: 189 case IPPROTO_ICMPV6:
185 if (pskb_may_pull(skb, nh + offset + 2 - skb->data)) { 190 if (!onlyproto && pskb_may_pull(skb, nh + offset + 2 - skb->data)) {
186 u8 *icmp = (u8 *)exthdr; 191 u8 *icmp = (u8 *)exthdr;
187 192
188 fl->fl_icmp_type = icmp[0]; 193 fl->fl_icmp_type = icmp[0];
@@ -193,7 +198,7 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
193 198
194#if defined(CONFIG_IPV6_MIP6) || defined(CONFIG_IPV6_MIP6_MODULE) 199#if defined(CONFIG_IPV6_MIP6) || defined(CONFIG_IPV6_MIP6_MODULE)
195 case IPPROTO_MH: 200 case IPPROTO_MH:
196 if (pskb_may_pull(skb, nh + offset + 3 - skb->data)) { 201 if (!onlyproto && pskb_may_pull(skb, nh + offset + 3 - skb->data)) {
197 struct ip6_mh *mh; 202 struct ip6_mh *mh;
198 mh = (struct ip6_mh *)exthdr; 203 mh = (struct ip6_mh *)exthdr;
199 204
@@ -217,7 +222,7 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
217 222
218static inline int xfrm6_garbage_collect(struct dst_ops *ops) 223static inline int xfrm6_garbage_collect(struct dst_ops *ops)
219{ 224{
220 xfrm6_policy_afinfo.garbage_collect(); 225 xfrm6_policy_afinfo.garbage_collect(&init_net);
221 return (atomic_read(&xfrm6_dst_ops.entries) > xfrm6_dst_ops.gc_thresh*2); 226 return (atomic_read(&xfrm6_dst_ops.entries) > xfrm6_dst_ops.gc_thresh*2);
222} 227}
223 228
@@ -274,7 +279,6 @@ static struct dst_ops xfrm6_dst_ops = {
274 .ifdown = xfrm6_dst_ifdown, 279 .ifdown = xfrm6_dst_ifdown,
275 .local_out = __ip6_local_out, 280 .local_out = __ip6_local_out,
276 .gc_thresh = 1024, 281 .gc_thresh = 1024,
277 .entry_size = sizeof(struct xfrm_dst),
278 .entries = ATOMIC_INIT(0), 282 .entries = ATOMIC_INIT(0),
279}; 283};
280 284
diff --git a/net/ipv6/xfrm6_state.c b/net/ipv6/xfrm6_state.c
index 60c78cfc2737..0e685b05496e 100644
--- a/net/ipv6/xfrm6_state.c
+++ b/net/ipv6/xfrm6_state.c
@@ -19,8 +19,6 @@
19#include <net/ipv6.h> 19#include <net/ipv6.h>
20#include <net/addrconf.h> 20#include <net/addrconf.h>
21 21
22static struct xfrm_state_afinfo xfrm6_state_afinfo;
23
24static void 22static void
25__xfrm6_init_tempsel(struct xfrm_state *x, struct flowi *fl, 23__xfrm6_init_tempsel(struct xfrm_state *x, struct flowi *fl,
26 struct xfrm_tmpl *tmpl, 24 struct xfrm_tmpl *tmpl,
diff --git a/net/ipv6/xfrm6_tunnel.c b/net/ipv6/xfrm6_tunnel.c
index c2b278138604..80193db224d9 100644
--- a/net/ipv6/xfrm6_tunnel.c
+++ b/net/ipv6/xfrm6_tunnel.c
@@ -345,24 +345,23 @@ static struct xfrm6_tunnel xfrm46_tunnel_handler = {
345static int __init xfrm6_tunnel_init(void) 345static int __init xfrm6_tunnel_init(void)
346{ 346{
347 if (xfrm_register_type(&xfrm6_tunnel_type, AF_INET6) < 0) 347 if (xfrm_register_type(&xfrm6_tunnel_type, AF_INET6) < 0)
348 return -EAGAIN; 348 goto err;
349 349 if (xfrm6_tunnel_register(&xfrm6_tunnel_handler, AF_INET6))
350 if (xfrm6_tunnel_register(&xfrm6_tunnel_handler, AF_INET6)) { 350 goto unreg;
351 xfrm_unregister_type(&xfrm6_tunnel_type, AF_INET6); 351 if (xfrm6_tunnel_register(&xfrm46_tunnel_handler, AF_INET))
352 return -EAGAIN; 352 goto dereg6;
353 } 353 if (xfrm6_tunnel_spi_init() < 0)
354 if (xfrm6_tunnel_register(&xfrm46_tunnel_handler, AF_INET)) { 354 goto dereg46;
355 xfrm6_tunnel_deregister(&xfrm6_tunnel_handler, AF_INET6);
356 xfrm_unregister_type(&xfrm6_tunnel_type, AF_INET6);
357 return -EAGAIN;
358 }
359 if (xfrm6_tunnel_spi_init() < 0) {
360 xfrm6_tunnel_deregister(&xfrm46_tunnel_handler, AF_INET);
361 xfrm6_tunnel_deregister(&xfrm6_tunnel_handler, AF_INET6);
362 xfrm_unregister_type(&xfrm6_tunnel_type, AF_INET6);
363 return -EAGAIN;
364 }
365 return 0; 355 return 0;
356
357dereg46:
358 xfrm6_tunnel_deregister(&xfrm46_tunnel_handler, AF_INET);
359dereg6:
360 xfrm6_tunnel_deregister(&xfrm6_tunnel_handler, AF_INET6);
361unreg:
362 xfrm_unregister_type(&xfrm6_tunnel_type, AF_INET6);
363err:
364 return -EAGAIN;
366} 365}
367 366
368static void __exit xfrm6_tunnel_fini(void) 367static void __exit xfrm6_tunnel_fini(void)
diff --git a/net/ipx/sysctl_net_ipx.c b/net/ipx/sysctl_net_ipx.c
index 92fef864e852..633fcab35580 100644
--- a/net/ipx/sysctl_net_ipx.c
+++ b/net/ipx/sysctl_net_ipx.c
@@ -23,7 +23,7 @@ static struct ctl_table ipx_table[] = {
23 .data = &sysctl_ipx_pprop_broadcasting, 23 .data = &sysctl_ipx_pprop_broadcasting,
24 .maxlen = sizeof(int), 24 .maxlen = sizeof(int),
25 .mode = 0644, 25 .mode = 0644,
26 .proc_handler = &proc_dointvec, 26 .proc_handler = proc_dointvec,
27 }, 27 },
28 { 0 }, 28 { 0 },
29}; 29};
diff --git a/net/irda/irlan/irlan_client.c b/net/irda/irlan/irlan_client.c
index 6be1ec26b30c..42f7d960d055 100644
--- a/net/irda/irlan/irlan_client.c
+++ b/net/irda/irlan/irlan_client.c
@@ -436,7 +436,6 @@ static void irlan_check_response_param(struct irlan_cb *self, char *param,
436 __u16 tmp_cpu; /* Temporary value in host order */ 436 __u16 tmp_cpu; /* Temporary value in host order */
437 __u8 *bytes; 437 __u8 *bytes;
438 int i; 438 int i;
439 DECLARE_MAC_BUF(mac);
440 439
441 IRDA_DEBUG(4, "%s(), parm=%s\n", __func__ , param); 440 IRDA_DEBUG(4, "%s(), parm=%s\n", __func__ , param);
442 441
@@ -521,8 +520,7 @@ static void irlan_check_response_param(struct irlan_cb *self, char *param,
521 /* FILTER_ENTRY, have we got an ethernet address? */ 520 /* FILTER_ENTRY, have we got an ethernet address? */
522 if (strcmp(param, "FILTER_ENTRY") == 0) { 521 if (strcmp(param, "FILTER_ENTRY") == 0) {
523 bytes = value; 522 bytes = value;
524 IRDA_DEBUG(4, "Ethernet address = %s\n", 523 IRDA_DEBUG(4, "Ethernet address = %pM\n", bytes);
525 print_mac(mac, bytes));
526 for (i = 0; i < 6; i++) 524 for (i = 0; i < 6; i++)
527 self->dev->dev_addr[i] = bytes[i]; 525 self->dev->dev_addr[i] = bytes[i];
528 } 526 }
diff --git a/net/irda/irlan/irlan_common.c b/net/irda/irlan/irlan_common.c
index 9a1cd87e7142..774d73a76852 100644
--- a/net/irda/irlan/irlan_common.c
+++ b/net/irda/irlan/irlan_common.c
@@ -207,7 +207,7 @@ static struct irlan_cb *irlan_open(__u32 saddr, __u32 daddr)
207 if (!dev) 207 if (!dev)
208 return NULL; 208 return NULL;
209 209
210 self = dev->priv; 210 self = netdev_priv(dev);
211 self->dev = dev; 211 self->dev = dev;
212 212
213 /* 213 /*
diff --git a/net/irda/irlap_frame.c b/net/irda/irlap_frame.c
index f17b65af9c9b..2562ebc1b22c 100644
--- a/net/irda/irlap_frame.c
+++ b/net/irda/irlap_frame.c
@@ -1325,6 +1325,7 @@ int irlap_driver_rcv(struct sk_buff *skb, struct net_device *dev,
1325 struct irlap_cb *self; 1325 struct irlap_cb *self;
1326 int command; 1326 int command;
1327 __u8 control; 1327 __u8 control;
1328 int ret = -1;
1328 1329
1329 if (!net_eq(dev_net(dev), &init_net)) 1330 if (!net_eq(dev_net(dev), &init_net))
1330 goto out; 1331 goto out;
@@ -1333,25 +1334,21 @@ int irlap_driver_rcv(struct sk_buff *skb, struct net_device *dev,
1333 self = (struct irlap_cb *) dev->atalk_ptr; 1334 self = (struct irlap_cb *) dev->atalk_ptr;
1334 1335
1335 /* If the net device is down, then IrLAP is gone! */ 1336 /* If the net device is down, then IrLAP is gone! */
1336 if (!self || self->magic != LAP_MAGIC) { 1337 if (!self || self->magic != LAP_MAGIC)
1337 dev_kfree_skb(skb); 1338 goto err;
1338 return -1;
1339 }
1340 1339
1341 /* We are no longer an "old" protocol, so we need to handle 1340 /* We are no longer an "old" protocol, so we need to handle
1342 * share and non linear skbs. This should never happen, so 1341 * share and non linear skbs. This should never happen, so
1343 * we don't need to be clever about it. Jean II */ 1342 * we don't need to be clever about it. Jean II */
1344 if ((skb = skb_share_check(skb, GFP_ATOMIC)) == NULL) { 1343 if ((skb = skb_share_check(skb, GFP_ATOMIC)) == NULL) {
1345 IRDA_ERROR("%s: can't clone shared skb!\n", __func__); 1344 IRDA_ERROR("%s: can't clone shared skb!\n", __func__);
1346 dev_kfree_skb(skb); 1345 goto err;
1347 return -1;
1348 } 1346 }
1349 1347
1350 /* Check if frame is large enough for parsing */ 1348 /* Check if frame is large enough for parsing */
1351 if (!pskb_may_pull(skb, 2)) { 1349 if (!pskb_may_pull(skb, 2)) {
1352 IRDA_ERROR("%s: frame too short!\n", __func__); 1350 IRDA_ERROR("%s: frame too short!\n", __func__);
1353 dev_kfree_skb(skb); 1351 goto err;
1354 return -1;
1355 } 1352 }
1356 1353
1357 command = skb->data[0] & CMD_FRAME; 1354 command = skb->data[0] & CMD_FRAME;
@@ -1442,7 +1439,9 @@ int irlap_driver_rcv(struct sk_buff *skb, struct net_device *dev,
1442 break; 1439 break;
1443 } 1440 }
1444out: 1441out:
1442 ret = 0;
1443err:
1445 /* Always drop our reference on the skb */ 1444 /* Always drop our reference on the skb */
1446 dev_kfree_skb(skb); 1445 dev_kfree_skb(skb);
1447 return 0; 1446 return ret;
1448} 1447}
diff --git a/net/irda/irsysctl.c b/net/irda/irsysctl.c
index 9ab3df15425d..57f8817c3979 100644
--- a/net/irda/irsysctl.c
+++ b/net/irda/irsysctl.c
@@ -118,8 +118,8 @@ static ctl_table irda_table[] = {
118 .data = &sysctl_discovery, 118 .data = &sysctl_discovery,
119 .maxlen = sizeof(int), 119 .maxlen = sizeof(int),
120 .mode = 0644, 120 .mode = 0644,
121 .proc_handler = &do_discovery, 121 .proc_handler = do_discovery,
122 .strategy = &sysctl_intvec 122 .strategy = sysctl_intvec
123 }, 123 },
124 { 124 {
125 .ctl_name = NET_IRDA_DEVNAME, 125 .ctl_name = NET_IRDA_DEVNAME,
@@ -127,8 +127,8 @@ static ctl_table irda_table[] = {
127 .data = sysctl_devname, 127 .data = sysctl_devname,
128 .maxlen = 65, 128 .maxlen = 65,
129 .mode = 0644, 129 .mode = 0644,
130 .proc_handler = &do_devname, 130 .proc_handler = do_devname,
131 .strategy = &sysctl_string 131 .strategy = sysctl_string
132 }, 132 },
133#ifdef CONFIG_IRDA_DEBUG 133#ifdef CONFIG_IRDA_DEBUG
134 { 134 {
@@ -137,7 +137,7 @@ static ctl_table irda_table[] = {
137 .data = &irda_debug, 137 .data = &irda_debug,
138 .maxlen = sizeof(int), 138 .maxlen = sizeof(int),
139 .mode = 0644, 139 .mode = 0644,
140 .proc_handler = &proc_dointvec 140 .proc_handler = proc_dointvec
141 }, 141 },
142#endif 142#endif
143#ifdef CONFIG_IRDA_FAST_RR 143#ifdef CONFIG_IRDA_FAST_RR
@@ -147,7 +147,7 @@ static ctl_table irda_table[] = {
147 .data = &sysctl_fast_poll_increase, 147 .data = &sysctl_fast_poll_increase,
148 .maxlen = sizeof(int), 148 .maxlen = sizeof(int),
149 .mode = 0644, 149 .mode = 0644,
150 .proc_handler = &proc_dointvec 150 .proc_handler = proc_dointvec
151 }, 151 },
152#endif 152#endif
153 { 153 {
@@ -156,8 +156,8 @@ static ctl_table irda_table[] = {
156 .data = &sysctl_discovery_slots, 156 .data = &sysctl_discovery_slots,
157 .maxlen = sizeof(int), 157 .maxlen = sizeof(int),
158 .mode = 0644, 158 .mode = 0644,
159 .proc_handler = &proc_dointvec_minmax, 159 .proc_handler = proc_dointvec_minmax,
160 .strategy = &sysctl_intvec, 160 .strategy = sysctl_intvec,
161 .extra1 = &min_discovery_slots, 161 .extra1 = &min_discovery_slots,
162 .extra2 = &max_discovery_slots 162 .extra2 = &max_discovery_slots
163 }, 163 },
@@ -167,7 +167,7 @@ static ctl_table irda_table[] = {
167 .data = &sysctl_discovery_timeout, 167 .data = &sysctl_discovery_timeout,
168 .maxlen = sizeof(int), 168 .maxlen = sizeof(int),
169 .mode = 0644, 169 .mode = 0644,
170 .proc_handler = &proc_dointvec 170 .proc_handler = proc_dointvec
171 }, 171 },
172 { 172 {
173 .ctl_name = NET_IRDA_SLOT_TIMEOUT, 173 .ctl_name = NET_IRDA_SLOT_TIMEOUT,
@@ -175,8 +175,8 @@ static ctl_table irda_table[] = {
175 .data = &sysctl_slot_timeout, 175 .data = &sysctl_slot_timeout,
176 .maxlen = sizeof(int), 176 .maxlen = sizeof(int),
177 .mode = 0644, 177 .mode = 0644,
178 .proc_handler = &proc_dointvec_minmax, 178 .proc_handler = proc_dointvec_minmax,
179 .strategy = &sysctl_intvec, 179 .strategy = sysctl_intvec,
180 .extra1 = &min_slot_timeout, 180 .extra1 = &min_slot_timeout,
181 .extra2 = &max_slot_timeout 181 .extra2 = &max_slot_timeout
182 }, 182 },
@@ -186,8 +186,8 @@ static ctl_table irda_table[] = {
186 .data = &sysctl_max_baud_rate, 186 .data = &sysctl_max_baud_rate,
187 .maxlen = sizeof(int), 187 .maxlen = sizeof(int),
188 .mode = 0644, 188 .mode = 0644,
189 .proc_handler = &proc_dointvec_minmax, 189 .proc_handler = proc_dointvec_minmax,
190 .strategy = &sysctl_intvec, 190 .strategy = sysctl_intvec,
191 .extra1 = &min_max_baud_rate, 191 .extra1 = &min_max_baud_rate,
192 .extra2 = &max_max_baud_rate 192 .extra2 = &max_max_baud_rate
193 }, 193 },
@@ -197,8 +197,8 @@ static ctl_table irda_table[] = {
197 .data = &sysctl_min_tx_turn_time, 197 .data = &sysctl_min_tx_turn_time,
198 .maxlen = sizeof(int), 198 .maxlen = sizeof(int),
199 .mode = 0644, 199 .mode = 0644,
200 .proc_handler = &proc_dointvec_minmax, 200 .proc_handler = proc_dointvec_minmax,
201 .strategy = &sysctl_intvec, 201 .strategy = sysctl_intvec,
202 .extra1 = &min_min_tx_turn_time, 202 .extra1 = &min_min_tx_turn_time,
203 .extra2 = &max_min_tx_turn_time 203 .extra2 = &max_min_tx_turn_time
204 }, 204 },
@@ -208,8 +208,8 @@ static ctl_table irda_table[] = {
208 .data = &sysctl_max_tx_data_size, 208 .data = &sysctl_max_tx_data_size,
209 .maxlen = sizeof(int), 209 .maxlen = sizeof(int),
210 .mode = 0644, 210 .mode = 0644,
211 .proc_handler = &proc_dointvec_minmax, 211 .proc_handler = proc_dointvec_minmax,
212 .strategy = &sysctl_intvec, 212 .strategy = sysctl_intvec,
213 .extra1 = &min_max_tx_data_size, 213 .extra1 = &min_max_tx_data_size,
214 .extra2 = &max_max_tx_data_size 214 .extra2 = &max_max_tx_data_size
215 }, 215 },
@@ -219,8 +219,8 @@ static ctl_table irda_table[] = {
219 .data = &sysctl_max_tx_window, 219 .data = &sysctl_max_tx_window,
220 .maxlen = sizeof(int), 220 .maxlen = sizeof(int),
221 .mode = 0644, 221 .mode = 0644,
222 .proc_handler = &proc_dointvec_minmax, 222 .proc_handler = proc_dointvec_minmax,
223 .strategy = &sysctl_intvec, 223 .strategy = sysctl_intvec,
224 .extra1 = &min_max_tx_window, 224 .extra1 = &min_max_tx_window,
225 .extra2 = &max_max_tx_window 225 .extra2 = &max_max_tx_window
226 }, 226 },
@@ -230,8 +230,8 @@ static ctl_table irda_table[] = {
230 .data = &sysctl_max_noreply_time, 230 .data = &sysctl_max_noreply_time,
231 .maxlen = sizeof(int), 231 .maxlen = sizeof(int),
232 .mode = 0644, 232 .mode = 0644,
233 .proc_handler = &proc_dointvec_minmax, 233 .proc_handler = proc_dointvec_minmax,
234 .strategy = &sysctl_intvec, 234 .strategy = sysctl_intvec,
235 .extra1 = &min_max_noreply_time, 235 .extra1 = &min_max_noreply_time,
236 .extra2 = &max_max_noreply_time 236 .extra2 = &max_max_noreply_time
237 }, 237 },
@@ -241,8 +241,8 @@ static ctl_table irda_table[] = {
241 .data = &sysctl_warn_noreply_time, 241 .data = &sysctl_warn_noreply_time,
242 .maxlen = sizeof(int), 242 .maxlen = sizeof(int),
243 .mode = 0644, 243 .mode = 0644,
244 .proc_handler = &proc_dointvec_minmax, 244 .proc_handler = proc_dointvec_minmax,
245 .strategy = &sysctl_intvec, 245 .strategy = sysctl_intvec,
246 .extra1 = &min_warn_noreply_time, 246 .extra1 = &min_warn_noreply_time,
247 .extra2 = &max_warn_noreply_time 247 .extra2 = &max_warn_noreply_time
248 }, 248 },
@@ -252,8 +252,8 @@ static ctl_table irda_table[] = {
252 .data = &sysctl_lap_keepalive_time, 252 .data = &sysctl_lap_keepalive_time,
253 .maxlen = sizeof(int), 253 .maxlen = sizeof(int),
254 .mode = 0644, 254 .mode = 0644,
255 .proc_handler = &proc_dointvec_minmax, 255 .proc_handler = proc_dointvec_minmax,
256 .strategy = &sysctl_intvec, 256 .strategy = sysctl_intvec,
257 .extra1 = &min_lap_keepalive_time, 257 .extra1 = &min_lap_keepalive_time,
258 .extra2 = &max_lap_keepalive_time 258 .extra2 = &max_lap_keepalive_time
259 }, 259 },
diff --git a/net/irda/irttp.c b/net/irda/irttp.c
index 74e439e80823..ecf4eb2717cb 100644
--- a/net/irda/irttp.c
+++ b/net/irda/irttp.c
@@ -201,7 +201,7 @@ static void irttp_todo_expired(unsigned long data)
201 * 201 *
202 * Flushes (removes all frames) in transitt-buffer (tx_list) 202 * Flushes (removes all frames) in transitt-buffer (tx_list)
203 */ 203 */
204void irttp_flush_queues(struct tsap_cb *self) 204static void irttp_flush_queues(struct tsap_cb *self)
205{ 205{
206 struct sk_buff* skb; 206 struct sk_buff* skb;
207 207
@@ -1266,9 +1266,9 @@ static void irttp_connect_confirm(void *instance, void *sap,
1266 * Some other device is connecting to this TSAP 1266 * Some other device is connecting to this TSAP
1267 * 1267 *
1268 */ 1268 */
1269void irttp_connect_indication(void *instance, void *sap, struct qos_info *qos, 1269static void irttp_connect_indication(void *instance, void *sap,
1270 __u32 max_seg_size, __u8 max_header_size, 1270 struct qos_info *qos, __u32 max_seg_size, __u8 max_header_size,
1271 struct sk_buff *skb) 1271 struct sk_buff *skb)
1272{ 1272{
1273 struct tsap_cb *self; 1273 struct tsap_cb *self;
1274 struct lsap_cb *lsap; 1274 struct lsap_cb *lsap;
@@ -1579,8 +1579,8 @@ EXPORT_SYMBOL(irttp_disconnect_request);
1579 * Disconnect indication, TSAP disconnected by peer? 1579 * Disconnect indication, TSAP disconnected by peer?
1580 * 1580 *
1581 */ 1581 */
1582void irttp_disconnect_indication(void *instance, void *sap, LM_REASON reason, 1582static void irttp_disconnect_indication(void *instance, void *sap,
1583 struct sk_buff *skb) 1583 LM_REASON reason, struct sk_buff *skb)
1584{ 1584{
1585 struct tsap_cb *self; 1585 struct tsap_cb *self;
1586 1586
@@ -1664,7 +1664,7 @@ static void irttp_do_data_indication(struct tsap_cb *self, struct sk_buff *skb)
1664 * Check if we have any frames to be transmitted, or if we have any 1664 * Check if we have any frames to be transmitted, or if we have any
1665 * available credit to give away. 1665 * available credit to give away.
1666 */ 1666 */
1667void irttp_run_rx_queue(struct tsap_cb *self) 1667static void irttp_run_rx_queue(struct tsap_cb *self)
1668{ 1668{
1669 struct sk_buff *skb; 1669 struct sk_buff *skb;
1670 int more = 0; 1670 int more = 0;
diff --git a/net/irda/timer.c b/net/irda/timer.c
index d730099080a2..0335ba0cc593 100644
--- a/net/irda/timer.c
+++ b/net/irda/timer.c
@@ -219,7 +219,7 @@ static void irlap_backoff_timer_expired(void *data)
219 * 219 *
220 * 220 *
221 */ 221 */
222void irlap_media_busy_expired(void* data) 222static void irlap_media_busy_expired(void *data)
223{ 223{
224 struct irlap_cb *self = (struct irlap_cb *) data; 224 struct irlap_cb *self = (struct irlap_cb *) data;
225 225
diff --git a/net/key/af_key.c b/net/key/af_key.c
index 5b22e011653b..f8bd8df5e257 100644
--- a/net/key/af_key.c
+++ b/net/key/af_key.c
@@ -27,6 +27,7 @@
27#include <linux/proc_fs.h> 27#include <linux/proc_fs.h>
28#include <linux/init.h> 28#include <linux/init.h>
29#include <net/net_namespace.h> 29#include <net/net_namespace.h>
30#include <net/netns/generic.h>
30#include <net/xfrm.h> 31#include <net/xfrm.h>
31 32
32#include <net/sock.h> 33#include <net/sock.h>
@@ -34,15 +35,16 @@
34#define _X2KEY(x) ((x) == XFRM_INF ? 0 : (x)) 35#define _X2KEY(x) ((x) == XFRM_INF ? 0 : (x))
35#define _KEY2X(x) ((x) == 0 ? XFRM_INF : (x)) 36#define _KEY2X(x) ((x) == 0 ? XFRM_INF : (x))
36 37
37 38static int pfkey_net_id;
38/* List of all pfkey sockets. */ 39struct netns_pfkey {
39static HLIST_HEAD(pfkey_table); 40 /* List of all pfkey sockets. */
41 struct hlist_head table;
42 atomic_t socks_nr;
43};
40static DECLARE_WAIT_QUEUE_HEAD(pfkey_table_wait); 44static DECLARE_WAIT_QUEUE_HEAD(pfkey_table_wait);
41static DEFINE_RWLOCK(pfkey_table_lock); 45static DEFINE_RWLOCK(pfkey_table_lock);
42static atomic_t pfkey_table_users = ATOMIC_INIT(0); 46static atomic_t pfkey_table_users = ATOMIC_INIT(0);
43 47
44static atomic_t pfkey_socks_nr = ATOMIC_INIT(0);
45
46struct pfkey_sock { 48struct pfkey_sock {
47 /* struct sock must be the first member of struct pfkey_sock */ 49 /* struct sock must be the first member of struct pfkey_sock */
48 struct sock sk; 50 struct sock sk;
@@ -89,6 +91,9 @@ static void pfkey_terminate_dump(struct pfkey_sock *pfk)
89 91
90static void pfkey_sock_destruct(struct sock *sk) 92static void pfkey_sock_destruct(struct sock *sk)
91{ 93{
94 struct net *net = sock_net(sk);
95 struct netns_pfkey *net_pfkey = net_generic(net, pfkey_net_id);
96
92 pfkey_terminate_dump(pfkey_sk(sk)); 97 pfkey_terminate_dump(pfkey_sk(sk));
93 skb_queue_purge(&sk->sk_receive_queue); 98 skb_queue_purge(&sk->sk_receive_queue);
94 99
@@ -100,7 +105,7 @@ static void pfkey_sock_destruct(struct sock *sk)
100 WARN_ON(atomic_read(&sk->sk_rmem_alloc)); 105 WARN_ON(atomic_read(&sk->sk_rmem_alloc));
101 WARN_ON(atomic_read(&sk->sk_wmem_alloc)); 106 WARN_ON(atomic_read(&sk->sk_wmem_alloc));
102 107
103 atomic_dec(&pfkey_socks_nr); 108 atomic_dec(&net_pfkey->socks_nr);
104} 109}
105 110
106static void pfkey_table_grab(void) 111static void pfkey_table_grab(void)
@@ -151,8 +156,11 @@ static const struct proto_ops pfkey_ops;
151 156
152static void pfkey_insert(struct sock *sk) 157static void pfkey_insert(struct sock *sk)
153{ 158{
159 struct net *net = sock_net(sk);
160 struct netns_pfkey *net_pfkey = net_generic(net, pfkey_net_id);
161
154 pfkey_table_grab(); 162 pfkey_table_grab();
155 sk_add_node(sk, &pfkey_table); 163 sk_add_node(sk, &net_pfkey->table);
156 pfkey_table_ungrab(); 164 pfkey_table_ungrab();
157} 165}
158 166
@@ -171,12 +179,10 @@ static struct proto key_proto = {
171 179
172static int pfkey_create(struct net *net, struct socket *sock, int protocol) 180static int pfkey_create(struct net *net, struct socket *sock, int protocol)
173{ 181{
182 struct netns_pfkey *net_pfkey = net_generic(net, pfkey_net_id);
174 struct sock *sk; 183 struct sock *sk;
175 int err; 184 int err;
176 185
177 if (net != &init_net)
178 return -EAFNOSUPPORT;
179
180 if (!capable(CAP_NET_ADMIN)) 186 if (!capable(CAP_NET_ADMIN))
181 return -EPERM; 187 return -EPERM;
182 if (sock->type != SOCK_RAW) 188 if (sock->type != SOCK_RAW)
@@ -195,7 +201,7 @@ static int pfkey_create(struct net *net, struct socket *sock, int protocol)
195 sk->sk_family = PF_KEY; 201 sk->sk_family = PF_KEY;
196 sk->sk_destruct = pfkey_sock_destruct; 202 sk->sk_destruct = pfkey_sock_destruct;
197 203
198 atomic_inc(&pfkey_socks_nr); 204 atomic_inc(&net_pfkey->socks_nr);
199 205
200 pfkey_insert(sk); 206 pfkey_insert(sk);
201 207
@@ -255,8 +261,10 @@ static int pfkey_broadcast_one(struct sk_buff *skb, struct sk_buff **skb2,
255#define BROADCAST_REGISTERED 2 261#define BROADCAST_REGISTERED 2
256#define BROADCAST_PROMISC_ONLY 4 262#define BROADCAST_PROMISC_ONLY 4
257static int pfkey_broadcast(struct sk_buff *skb, gfp_t allocation, 263static int pfkey_broadcast(struct sk_buff *skb, gfp_t allocation,
258 int broadcast_flags, struct sock *one_sk) 264 int broadcast_flags, struct sock *one_sk,
265 struct net *net)
259{ 266{
267 struct netns_pfkey *net_pfkey = net_generic(net, pfkey_net_id);
260 struct sock *sk; 268 struct sock *sk;
261 struct hlist_node *node; 269 struct hlist_node *node;
262 struct sk_buff *skb2 = NULL; 270 struct sk_buff *skb2 = NULL;
@@ -269,7 +277,7 @@ static int pfkey_broadcast(struct sk_buff *skb, gfp_t allocation,
269 return -ENOMEM; 277 return -ENOMEM;
270 278
271 pfkey_lock_table(); 279 pfkey_lock_table();
272 sk_for_each(sk, node, &pfkey_table) { 280 sk_for_each(sk, node, &net_pfkey->table) {
273 struct pfkey_sock *pfk = pfkey_sk(sk); 281 struct pfkey_sock *pfk = pfkey_sk(sk);
274 int err2; 282 int err2;
275 283
@@ -328,7 +336,7 @@ static int pfkey_do_dump(struct pfkey_sock *pfk)
328 hdr->sadb_msg_seq = 0; 336 hdr->sadb_msg_seq = 0;
329 hdr->sadb_msg_errno = rc; 337 hdr->sadb_msg_errno = rc;
330 pfkey_broadcast(pfk->dump.skb, GFP_ATOMIC, BROADCAST_ONE, 338 pfkey_broadcast(pfk->dump.skb, GFP_ATOMIC, BROADCAST_ONE,
331 &pfk->sk); 339 &pfk->sk, sock_net(&pfk->sk));
332 pfk->dump.skb = NULL; 340 pfk->dump.skb = NULL;
333 } 341 }
334 342
@@ -367,7 +375,7 @@ static int pfkey_error(struct sadb_msg *orig, int err, struct sock *sk)
367 hdr->sadb_msg_len = (sizeof(struct sadb_msg) / 375 hdr->sadb_msg_len = (sizeof(struct sadb_msg) /
368 sizeof(uint64_t)); 376 sizeof(uint64_t));
369 377
370 pfkey_broadcast(skb, GFP_KERNEL, BROADCAST_ONE, sk); 378 pfkey_broadcast(skb, GFP_KERNEL, BROADCAST_ONE, sk, sock_net(sk));
371 379
372 return 0; 380 return 0;
373} 381}
@@ -645,7 +653,7 @@ int pfkey_sadb_addr2xfrm_addr(struct sadb_address *addr, xfrm_address_t *xaddr)
645 xaddr); 653 xaddr);
646} 654}
647 655
648static struct xfrm_state *pfkey_xfrm_state_lookup(struct sadb_msg *hdr, void **ext_hdrs) 656static struct xfrm_state *pfkey_xfrm_state_lookup(struct net *net, struct sadb_msg *hdr, void **ext_hdrs)
649{ 657{
650 struct sadb_sa *sa; 658 struct sadb_sa *sa;
651 struct sadb_address *addr; 659 struct sadb_address *addr;
@@ -683,7 +691,7 @@ static struct xfrm_state *pfkey_xfrm_state_lookup(struct sadb_msg *hdr, void **
683 if (!xaddr) 691 if (!xaddr)
684 return NULL; 692 return NULL;
685 693
686 return xfrm_state_lookup(xaddr, sa->sadb_sa_spi, proto, family); 694 return xfrm_state_lookup(net, xaddr, sa->sadb_sa_spi, proto, family);
687} 695}
688 696
689#define PFKEY_ALIGN8(a) (1 + (((a) - 1) | (8 - 1))) 697#define PFKEY_ALIGN8(a) (1 + (((a) - 1) | (8 - 1)))
@@ -1058,7 +1066,8 @@ static inline struct sk_buff *pfkey_xfrm_state2msg_expire(struct xfrm_state *x,
1058 return __pfkey_xfrm_state2msg(x, 0, hsc); 1066 return __pfkey_xfrm_state2msg(x, 0, hsc);
1059} 1067}
1060 1068
1061static struct xfrm_state * pfkey_msg2xfrm_state(struct sadb_msg *hdr, 1069static struct xfrm_state * pfkey_msg2xfrm_state(struct net *net,
1070 struct sadb_msg *hdr,
1062 void **ext_hdrs) 1071 void **ext_hdrs)
1063{ 1072{
1064 struct xfrm_state *x; 1073 struct xfrm_state *x;
@@ -1122,7 +1131,7 @@ static struct xfrm_state * pfkey_msg2xfrm_state(struct sadb_msg *hdr,
1122 (key->sadb_key_bits+7) / 8 > key->sadb_key_len * sizeof(uint64_t))) 1131 (key->sadb_key_bits+7) / 8 > key->sadb_key_len * sizeof(uint64_t)))
1123 return ERR_PTR(-EINVAL); 1132 return ERR_PTR(-EINVAL);
1124 1133
1125 x = xfrm_state_alloc(); 1134 x = xfrm_state_alloc(net);
1126 if (x == NULL) 1135 if (x == NULL)
1127 return ERR_PTR(-ENOBUFS); 1136 return ERR_PTR(-ENOBUFS);
1128 1137
@@ -1298,6 +1307,7 @@ static int pfkey_reserved(struct sock *sk, struct sk_buff *skb, struct sadb_msg
1298 1307
1299static int pfkey_getspi(struct sock *sk, struct sk_buff *skb, struct sadb_msg *hdr, void **ext_hdrs) 1308static int pfkey_getspi(struct sock *sk, struct sk_buff *skb, struct sadb_msg *hdr, void **ext_hdrs)
1300{ 1309{
1310 struct net *net = sock_net(sk);
1301 struct sk_buff *resp_skb; 1311 struct sk_buff *resp_skb;
1302 struct sadb_x_sa2 *sa2; 1312 struct sadb_x_sa2 *sa2;
1303 struct sadb_address *saddr, *daddr; 1313 struct sadb_address *saddr, *daddr;
@@ -1348,7 +1358,7 @@ static int pfkey_getspi(struct sock *sk, struct sk_buff *skb, struct sadb_msg *h
1348 } 1358 }
1349 1359
1350 if (hdr->sadb_msg_seq) { 1360 if (hdr->sadb_msg_seq) {
1351 x = xfrm_find_acq_byseq(hdr->sadb_msg_seq); 1361 x = xfrm_find_acq_byseq(net, hdr->sadb_msg_seq);
1352 if (x && xfrm_addr_cmp(&x->id.daddr, xdaddr, family)) { 1362 if (x && xfrm_addr_cmp(&x->id.daddr, xdaddr, family)) {
1353 xfrm_state_put(x); 1363 xfrm_state_put(x);
1354 x = NULL; 1364 x = NULL;
@@ -1356,7 +1366,7 @@ static int pfkey_getspi(struct sock *sk, struct sk_buff *skb, struct sadb_msg *h
1356 } 1366 }
1357 1367
1358 if (!x) 1368 if (!x)
1359 x = xfrm_find_acq(mode, reqid, proto, xdaddr, xsaddr, 1, family); 1369 x = xfrm_find_acq(net, mode, reqid, proto, xdaddr, xsaddr, 1, family);
1360 1370
1361 if (x == NULL) 1371 if (x == NULL)
1362 return -ENOENT; 1372 return -ENOENT;
@@ -1389,13 +1399,14 @@ static int pfkey_getspi(struct sock *sk, struct sk_buff *skb, struct sadb_msg *h
1389 1399
1390 xfrm_state_put(x); 1400 xfrm_state_put(x);
1391 1401
1392 pfkey_broadcast(resp_skb, GFP_KERNEL, BROADCAST_ONE, sk); 1402 pfkey_broadcast(resp_skb, GFP_KERNEL, BROADCAST_ONE, sk, net);
1393 1403
1394 return 0; 1404 return 0;
1395} 1405}
1396 1406
1397static int pfkey_acquire(struct sock *sk, struct sk_buff *skb, struct sadb_msg *hdr, void **ext_hdrs) 1407static int pfkey_acquire(struct sock *sk, struct sk_buff *skb, struct sadb_msg *hdr, void **ext_hdrs)
1398{ 1408{
1409 struct net *net = sock_net(sk);
1399 struct xfrm_state *x; 1410 struct xfrm_state *x;
1400 1411
1401 if (hdr->sadb_msg_len != sizeof(struct sadb_msg)/8) 1412 if (hdr->sadb_msg_len != sizeof(struct sadb_msg)/8)
@@ -1404,14 +1415,14 @@ static int pfkey_acquire(struct sock *sk, struct sk_buff *skb, struct sadb_msg *
1404 if (hdr->sadb_msg_seq == 0 || hdr->sadb_msg_errno == 0) 1415 if (hdr->sadb_msg_seq == 0 || hdr->sadb_msg_errno == 0)
1405 return 0; 1416 return 0;
1406 1417
1407 x = xfrm_find_acq_byseq(hdr->sadb_msg_seq); 1418 x = xfrm_find_acq_byseq(net, hdr->sadb_msg_seq);
1408 if (x == NULL) 1419 if (x == NULL)
1409 return 0; 1420 return 0;
1410 1421
1411 spin_lock_bh(&x->lock); 1422 spin_lock_bh(&x->lock);
1412 if (x->km.state == XFRM_STATE_ACQ) { 1423 if (x->km.state == XFRM_STATE_ACQ) {
1413 x->km.state = XFRM_STATE_ERROR; 1424 x->km.state = XFRM_STATE_ERROR;
1414 wake_up(&km_waitq); 1425 wake_up(&net->xfrm.km_waitq);
1415 } 1426 }
1416 spin_unlock_bh(&x->lock); 1427 spin_unlock_bh(&x->lock);
1417 xfrm_state_put(x); 1428 xfrm_state_put(x);
@@ -1476,18 +1487,19 @@ static int key_notify_sa(struct xfrm_state *x, struct km_event *c)
1476 hdr->sadb_msg_seq = c->seq; 1487 hdr->sadb_msg_seq = c->seq;
1477 hdr->sadb_msg_pid = c->pid; 1488 hdr->sadb_msg_pid = c->pid;
1478 1489
1479 pfkey_broadcast(skb, GFP_ATOMIC, BROADCAST_ALL, NULL); 1490 pfkey_broadcast(skb, GFP_ATOMIC, BROADCAST_ALL, NULL, xs_net(x));
1480 1491
1481 return 0; 1492 return 0;
1482} 1493}
1483 1494
1484static int pfkey_add(struct sock *sk, struct sk_buff *skb, struct sadb_msg *hdr, void **ext_hdrs) 1495static int pfkey_add(struct sock *sk, struct sk_buff *skb, struct sadb_msg *hdr, void **ext_hdrs)
1485{ 1496{
1497 struct net *net = sock_net(sk);
1486 struct xfrm_state *x; 1498 struct xfrm_state *x;
1487 int err; 1499 int err;
1488 struct km_event c; 1500 struct km_event c;
1489 1501
1490 x = pfkey_msg2xfrm_state(hdr, ext_hdrs); 1502 x = pfkey_msg2xfrm_state(net, hdr, ext_hdrs);
1491 if (IS_ERR(x)) 1503 if (IS_ERR(x))
1492 return PTR_ERR(x); 1504 return PTR_ERR(x);
1493 1505
@@ -1521,6 +1533,7 @@ out:
1521 1533
1522static int pfkey_delete(struct sock *sk, struct sk_buff *skb, struct sadb_msg *hdr, void **ext_hdrs) 1534static int pfkey_delete(struct sock *sk, struct sk_buff *skb, struct sadb_msg *hdr, void **ext_hdrs)
1523{ 1535{
1536 struct net *net = sock_net(sk);
1524 struct xfrm_state *x; 1537 struct xfrm_state *x;
1525 struct km_event c; 1538 struct km_event c;
1526 int err; 1539 int err;
@@ -1530,7 +1543,7 @@ static int pfkey_delete(struct sock *sk, struct sk_buff *skb, struct sadb_msg *h
1530 ext_hdrs[SADB_EXT_ADDRESS_DST-1])) 1543 ext_hdrs[SADB_EXT_ADDRESS_DST-1]))
1531 return -EINVAL; 1544 return -EINVAL;
1532 1545
1533 x = pfkey_xfrm_state_lookup(hdr, ext_hdrs); 1546 x = pfkey_xfrm_state_lookup(net, hdr, ext_hdrs);
1534 if (x == NULL) 1547 if (x == NULL)
1535 return -ESRCH; 1548 return -ESRCH;
1536 1549
@@ -1562,6 +1575,7 @@ out:
1562 1575
1563static int pfkey_get(struct sock *sk, struct sk_buff *skb, struct sadb_msg *hdr, void **ext_hdrs) 1576static int pfkey_get(struct sock *sk, struct sk_buff *skb, struct sadb_msg *hdr, void **ext_hdrs)
1564{ 1577{
1578 struct net *net = sock_net(sk);
1565 __u8 proto; 1579 __u8 proto;
1566 struct sk_buff *out_skb; 1580 struct sk_buff *out_skb;
1567 struct sadb_msg *out_hdr; 1581 struct sadb_msg *out_hdr;
@@ -1572,7 +1586,7 @@ static int pfkey_get(struct sock *sk, struct sk_buff *skb, struct sadb_msg *hdr,
1572 ext_hdrs[SADB_EXT_ADDRESS_DST-1])) 1586 ext_hdrs[SADB_EXT_ADDRESS_DST-1]))
1573 return -EINVAL; 1587 return -EINVAL;
1574 1588
1575 x = pfkey_xfrm_state_lookup(hdr, ext_hdrs); 1589 x = pfkey_xfrm_state_lookup(net, hdr, ext_hdrs);
1576 if (x == NULL) 1590 if (x == NULL)
1577 return -ESRCH; 1591 return -ESRCH;
1578 1592
@@ -1590,7 +1604,7 @@ static int pfkey_get(struct sock *sk, struct sk_buff *skb, struct sadb_msg *hdr,
1590 out_hdr->sadb_msg_reserved = 0; 1604 out_hdr->sadb_msg_reserved = 0;
1591 out_hdr->sadb_msg_seq = hdr->sadb_msg_seq; 1605 out_hdr->sadb_msg_seq = hdr->sadb_msg_seq;
1592 out_hdr->sadb_msg_pid = hdr->sadb_msg_pid; 1606 out_hdr->sadb_msg_pid = hdr->sadb_msg_pid;
1593 pfkey_broadcast(out_skb, GFP_ATOMIC, BROADCAST_ONE, sk); 1607 pfkey_broadcast(out_skb, GFP_ATOMIC, BROADCAST_ONE, sk, sock_net(sk));
1594 1608
1595 return 0; 1609 return 0;
1596} 1610}
@@ -1691,7 +1705,7 @@ static int pfkey_register(struct sock *sk, struct sk_buff *skb, struct sadb_msg
1691 return -ENOBUFS; 1705 return -ENOBUFS;
1692 } 1706 }
1693 1707
1694 pfkey_broadcast(supp_skb, GFP_KERNEL, BROADCAST_REGISTERED, sk); 1708 pfkey_broadcast(supp_skb, GFP_KERNEL, BROADCAST_REGISTERED, sk, sock_net(sk));
1695 1709
1696 return 0; 1710 return 0;
1697} 1711}
@@ -1713,13 +1727,14 @@ static int key_notify_sa_flush(struct km_event *c)
1713 hdr->sadb_msg_errno = (uint8_t) 0; 1727 hdr->sadb_msg_errno = (uint8_t) 0;
1714 hdr->sadb_msg_len = (sizeof(struct sadb_msg) / sizeof(uint64_t)); 1728 hdr->sadb_msg_len = (sizeof(struct sadb_msg) / sizeof(uint64_t));
1715 1729
1716 pfkey_broadcast(skb, GFP_ATOMIC, BROADCAST_ALL, NULL); 1730 pfkey_broadcast(skb, GFP_ATOMIC, BROADCAST_ALL, NULL, c->net);
1717 1731
1718 return 0; 1732 return 0;
1719} 1733}
1720 1734
1721static int pfkey_flush(struct sock *sk, struct sk_buff *skb, struct sadb_msg *hdr, void **ext_hdrs) 1735static int pfkey_flush(struct sock *sk, struct sk_buff *skb, struct sadb_msg *hdr, void **ext_hdrs)
1722{ 1736{
1737 struct net *net = sock_net(sk);
1723 unsigned proto; 1738 unsigned proto;
1724 struct km_event c; 1739 struct km_event c;
1725 struct xfrm_audit audit_info; 1740 struct xfrm_audit audit_info;
@@ -1732,13 +1747,14 @@ static int pfkey_flush(struct sock *sk, struct sk_buff *skb, struct sadb_msg *hd
1732 audit_info.loginuid = audit_get_loginuid(current); 1747 audit_info.loginuid = audit_get_loginuid(current);
1733 audit_info.sessionid = audit_get_sessionid(current); 1748 audit_info.sessionid = audit_get_sessionid(current);
1734 audit_info.secid = 0; 1749 audit_info.secid = 0;
1735 err = xfrm_state_flush(proto, &audit_info); 1750 err = xfrm_state_flush(net, proto, &audit_info);
1736 if (err) 1751 if (err)
1737 return err; 1752 return err;
1738 c.data.proto = proto; 1753 c.data.proto = proto;
1739 c.seq = hdr->sadb_msg_seq; 1754 c.seq = hdr->sadb_msg_seq;
1740 c.pid = hdr->sadb_msg_pid; 1755 c.pid = hdr->sadb_msg_pid;
1741 c.event = XFRM_MSG_FLUSHSA; 1756 c.event = XFRM_MSG_FLUSHSA;
1757 c.net = net;
1742 km_state_notify(NULL, &c); 1758 km_state_notify(NULL, &c);
1743 1759
1744 return 0; 1760 return 0;
@@ -1768,7 +1784,7 @@ static int dump_sa(struct xfrm_state *x, int count, void *ptr)
1768 1784
1769 if (pfk->dump.skb) 1785 if (pfk->dump.skb)
1770 pfkey_broadcast(pfk->dump.skb, GFP_ATOMIC, BROADCAST_ONE, 1786 pfkey_broadcast(pfk->dump.skb, GFP_ATOMIC, BROADCAST_ONE,
1771 &pfk->sk); 1787 &pfk->sk, sock_net(&pfk->sk));
1772 pfk->dump.skb = out_skb; 1788 pfk->dump.skb = out_skb;
1773 1789
1774 return 0; 1790 return 0;
@@ -1776,7 +1792,8 @@ static int dump_sa(struct xfrm_state *x, int count, void *ptr)
1776 1792
1777static int pfkey_dump_sa(struct pfkey_sock *pfk) 1793static int pfkey_dump_sa(struct pfkey_sock *pfk)
1778{ 1794{
1779 return xfrm_state_walk(&pfk->dump.u.state, dump_sa, (void *) pfk); 1795 struct net *net = sock_net(&pfk->sk);
1796 return xfrm_state_walk(net, &pfk->dump.u.state, dump_sa, (void *) pfk);
1780} 1797}
1781 1798
1782static void pfkey_dump_sa_done(struct pfkey_sock *pfk) 1799static void pfkey_dump_sa_done(struct pfkey_sock *pfk)
@@ -1817,7 +1834,7 @@ static int pfkey_promisc(struct sock *sk, struct sk_buff *skb, struct sadb_msg *
1817 return -EINVAL; 1834 return -EINVAL;
1818 pfk->promisc = satype; 1835 pfk->promisc = satype;
1819 } 1836 }
1820 pfkey_broadcast(skb_clone(skb, GFP_KERNEL), GFP_KERNEL, BROADCAST_ALL, NULL); 1837 pfkey_broadcast(skb_clone(skb, GFP_KERNEL), GFP_KERNEL, BROADCAST_ALL, NULL, sock_net(sk));
1821 return 0; 1838 return 0;
1822} 1839}
1823 1840
@@ -1833,7 +1850,7 @@ static int check_reqid(struct xfrm_policy *xp, int dir, int count, void *ptr)
1833 return 0; 1850 return 0;
1834} 1851}
1835 1852
1836static u32 gen_reqid(void) 1853static u32 gen_reqid(struct net *net)
1837{ 1854{
1838 struct xfrm_policy_walk walk; 1855 struct xfrm_policy_walk walk;
1839 u32 start; 1856 u32 start;
@@ -1846,7 +1863,7 @@ static u32 gen_reqid(void)
1846 if (reqid == 0) 1863 if (reqid == 0)
1847 reqid = IPSEC_MANUAL_REQID_MAX+1; 1864 reqid = IPSEC_MANUAL_REQID_MAX+1;
1848 xfrm_policy_walk_init(&walk, XFRM_POLICY_TYPE_MAIN); 1865 xfrm_policy_walk_init(&walk, XFRM_POLICY_TYPE_MAIN);
1849 rc = xfrm_policy_walk(&walk, check_reqid, (void*)&reqid); 1866 rc = xfrm_policy_walk(net, &walk, check_reqid, (void*)&reqid);
1850 xfrm_policy_walk_done(&walk); 1867 xfrm_policy_walk_done(&walk);
1851 if (rc != -EEXIST) 1868 if (rc != -EEXIST)
1852 return reqid; 1869 return reqid;
@@ -1857,6 +1874,7 @@ static u32 gen_reqid(void)
1857static int 1874static int
1858parse_ipsecrequest(struct xfrm_policy *xp, struct sadb_x_ipsecrequest *rq) 1875parse_ipsecrequest(struct xfrm_policy *xp, struct sadb_x_ipsecrequest *rq)
1859{ 1876{
1877 struct net *net = xp_net(xp);
1860 struct xfrm_tmpl *t = xp->xfrm_vec + xp->xfrm_nr; 1878 struct xfrm_tmpl *t = xp->xfrm_vec + xp->xfrm_nr;
1861 int mode; 1879 int mode;
1862 1880
@@ -1876,7 +1894,7 @@ parse_ipsecrequest(struct xfrm_policy *xp, struct sadb_x_ipsecrequest *rq)
1876 t->reqid = rq->sadb_x_ipsecrequest_reqid; 1894 t->reqid = rq->sadb_x_ipsecrequest_reqid;
1877 if (t->reqid > IPSEC_MANUAL_REQID_MAX) 1895 if (t->reqid > IPSEC_MANUAL_REQID_MAX)
1878 t->reqid = 0; 1896 t->reqid = 0;
1879 if (!t->reqid && !(t->reqid = gen_reqid())) 1897 if (!t->reqid && !(t->reqid = gen_reqid(net)))
1880 return -ENOBUFS; 1898 return -ENOBUFS;
1881 } 1899 }
1882 1900
@@ -2147,7 +2165,7 @@ static int key_notify_policy(struct xfrm_policy *xp, int dir, struct km_event *c
2147 out_hdr->sadb_msg_errno = 0; 2165 out_hdr->sadb_msg_errno = 0;
2148 out_hdr->sadb_msg_seq = c->seq; 2166 out_hdr->sadb_msg_seq = c->seq;
2149 out_hdr->sadb_msg_pid = c->pid; 2167 out_hdr->sadb_msg_pid = c->pid;
2150 pfkey_broadcast(out_skb, GFP_ATOMIC, BROADCAST_ALL, NULL); 2168 pfkey_broadcast(out_skb, GFP_ATOMIC, BROADCAST_ALL, NULL, xp_net(xp));
2151out: 2169out:
2152 return 0; 2170 return 0;
2153 2171
@@ -2155,6 +2173,7 @@ out:
2155 2173
2156static int pfkey_spdadd(struct sock *sk, struct sk_buff *skb, struct sadb_msg *hdr, void **ext_hdrs) 2174static int pfkey_spdadd(struct sock *sk, struct sk_buff *skb, struct sadb_msg *hdr, void **ext_hdrs)
2157{ 2175{
2176 struct net *net = sock_net(sk);
2158 int err = 0; 2177 int err = 0;
2159 struct sadb_lifetime *lifetime; 2178 struct sadb_lifetime *lifetime;
2160 struct sadb_address *sa; 2179 struct sadb_address *sa;
@@ -2174,7 +2193,7 @@ static int pfkey_spdadd(struct sock *sk, struct sk_buff *skb, struct sadb_msg *h
2174 if (!pol->sadb_x_policy_dir || pol->sadb_x_policy_dir >= IPSEC_DIR_MAX) 2193 if (!pol->sadb_x_policy_dir || pol->sadb_x_policy_dir >= IPSEC_DIR_MAX)
2175 return -EINVAL; 2194 return -EINVAL;
2176 2195
2177 xp = xfrm_policy_alloc(GFP_KERNEL); 2196 xp = xfrm_policy_alloc(net, GFP_KERNEL);
2178 if (xp == NULL) 2197 if (xp == NULL)
2179 return -ENOBUFS; 2198 return -ENOBUFS;
2180 2199
@@ -2275,6 +2294,7 @@ out:
2275 2294
2276static int pfkey_spddelete(struct sock *sk, struct sk_buff *skb, struct sadb_msg *hdr, void **ext_hdrs) 2295static int pfkey_spddelete(struct sock *sk, struct sk_buff *skb, struct sadb_msg *hdr, void **ext_hdrs)
2277{ 2296{
2297 struct net *net = sock_net(sk);
2278 int err; 2298 int err;
2279 struct sadb_address *sa; 2299 struct sadb_address *sa;
2280 struct sadb_x_policy *pol; 2300 struct sadb_x_policy *pol;
@@ -2324,7 +2344,7 @@ static int pfkey_spddelete(struct sock *sk, struct sk_buff *skb, struct sadb_msg
2324 return err; 2344 return err;
2325 } 2345 }
2326 2346
2327 xp = xfrm_policy_bysel_ctx(XFRM_POLICY_TYPE_MAIN, 2347 xp = xfrm_policy_bysel_ctx(net, XFRM_POLICY_TYPE_MAIN,
2328 pol->sadb_x_policy_dir - 1, &sel, pol_ctx, 2348 pol->sadb_x_policy_dir - 1, &sel, pol_ctx,
2329 1, &err); 2349 1, &err);
2330 security_xfrm_policy_free(pol_ctx); 2350 security_xfrm_policy_free(pol_ctx);
@@ -2372,7 +2392,7 @@ static int key_pol_get_resp(struct sock *sk, struct xfrm_policy *xp, struct sadb
2372 out_hdr->sadb_msg_errno = 0; 2392 out_hdr->sadb_msg_errno = 0;
2373 out_hdr->sadb_msg_seq = hdr->sadb_msg_seq; 2393 out_hdr->sadb_msg_seq = hdr->sadb_msg_seq;
2374 out_hdr->sadb_msg_pid = hdr->sadb_msg_pid; 2394 out_hdr->sadb_msg_pid = hdr->sadb_msg_pid;
2375 pfkey_broadcast(out_skb, GFP_ATOMIC, BROADCAST_ONE, sk); 2395 pfkey_broadcast(out_skb, GFP_ATOMIC, BROADCAST_ONE, sk, xp_net(xp));
2376 err = 0; 2396 err = 0;
2377 2397
2378out: 2398out:
@@ -2557,6 +2577,7 @@ static int pfkey_migrate(struct sock *sk, struct sk_buff *skb,
2557 2577
2558static int pfkey_spdget(struct sock *sk, struct sk_buff *skb, struct sadb_msg *hdr, void **ext_hdrs) 2578static int pfkey_spdget(struct sock *sk, struct sk_buff *skb, struct sadb_msg *hdr, void **ext_hdrs)
2559{ 2579{
2580 struct net *net = sock_net(sk);
2560 unsigned int dir; 2581 unsigned int dir;
2561 int err = 0, delete; 2582 int err = 0, delete;
2562 struct sadb_x_policy *pol; 2583 struct sadb_x_policy *pol;
@@ -2571,8 +2592,8 @@ static int pfkey_spdget(struct sock *sk, struct sk_buff *skb, struct sadb_msg *h
2571 return -EINVAL; 2592 return -EINVAL;
2572 2593
2573 delete = (hdr->sadb_msg_type == SADB_X_SPDDELETE2); 2594 delete = (hdr->sadb_msg_type == SADB_X_SPDDELETE2);
2574 xp = xfrm_policy_byid(XFRM_POLICY_TYPE_MAIN, dir, pol->sadb_x_policy_id, 2595 xp = xfrm_policy_byid(net, XFRM_POLICY_TYPE_MAIN, dir,
2575 delete, &err); 2596 pol->sadb_x_policy_id, delete, &err);
2576 if (xp == NULL) 2597 if (xp == NULL)
2577 return -ENOENT; 2598 return -ENOENT;
2578 2599
@@ -2625,7 +2646,7 @@ static int dump_sp(struct xfrm_policy *xp, int dir, int count, void *ptr)
2625 2646
2626 if (pfk->dump.skb) 2647 if (pfk->dump.skb)
2627 pfkey_broadcast(pfk->dump.skb, GFP_ATOMIC, BROADCAST_ONE, 2648 pfkey_broadcast(pfk->dump.skb, GFP_ATOMIC, BROADCAST_ONE,
2628 &pfk->sk); 2649 &pfk->sk, sock_net(&pfk->sk));
2629 pfk->dump.skb = out_skb; 2650 pfk->dump.skb = out_skb;
2630 2651
2631 return 0; 2652 return 0;
@@ -2633,7 +2654,8 @@ static int dump_sp(struct xfrm_policy *xp, int dir, int count, void *ptr)
2633 2654
2634static int pfkey_dump_sp(struct pfkey_sock *pfk) 2655static int pfkey_dump_sp(struct pfkey_sock *pfk)
2635{ 2656{
2636 return xfrm_policy_walk(&pfk->dump.u.policy, dump_sp, (void *) pfk); 2657 struct net *net = sock_net(&pfk->sk);
2658 return xfrm_policy_walk(net, &pfk->dump.u.policy, dump_sp, (void *) pfk);
2637} 2659}
2638 2660
2639static void pfkey_dump_sp_done(struct pfkey_sock *pfk) 2661static void pfkey_dump_sp_done(struct pfkey_sock *pfk)
@@ -2672,13 +2694,14 @@ static int key_notify_policy_flush(struct km_event *c)
2672 hdr->sadb_msg_version = PF_KEY_V2; 2694 hdr->sadb_msg_version = PF_KEY_V2;
2673 hdr->sadb_msg_errno = (uint8_t) 0; 2695 hdr->sadb_msg_errno = (uint8_t) 0;
2674 hdr->sadb_msg_len = (sizeof(struct sadb_msg) / sizeof(uint64_t)); 2696 hdr->sadb_msg_len = (sizeof(struct sadb_msg) / sizeof(uint64_t));
2675 pfkey_broadcast(skb_out, GFP_ATOMIC, BROADCAST_ALL, NULL); 2697 pfkey_broadcast(skb_out, GFP_ATOMIC, BROADCAST_ALL, NULL, c->net);
2676 return 0; 2698 return 0;
2677 2699
2678} 2700}
2679 2701
2680static int pfkey_spdflush(struct sock *sk, struct sk_buff *skb, struct sadb_msg *hdr, void **ext_hdrs) 2702static int pfkey_spdflush(struct sock *sk, struct sk_buff *skb, struct sadb_msg *hdr, void **ext_hdrs)
2681{ 2703{
2704 struct net *net = sock_net(sk);
2682 struct km_event c; 2705 struct km_event c;
2683 struct xfrm_audit audit_info; 2706 struct xfrm_audit audit_info;
2684 int err; 2707 int err;
@@ -2686,13 +2709,14 @@ static int pfkey_spdflush(struct sock *sk, struct sk_buff *skb, struct sadb_msg
2686 audit_info.loginuid = audit_get_loginuid(current); 2709 audit_info.loginuid = audit_get_loginuid(current);
2687 audit_info.sessionid = audit_get_sessionid(current); 2710 audit_info.sessionid = audit_get_sessionid(current);
2688 audit_info.secid = 0; 2711 audit_info.secid = 0;
2689 err = xfrm_policy_flush(XFRM_POLICY_TYPE_MAIN, &audit_info); 2712 err = xfrm_policy_flush(net, XFRM_POLICY_TYPE_MAIN, &audit_info);
2690 if (err) 2713 if (err)
2691 return err; 2714 return err;
2692 c.data.type = XFRM_POLICY_TYPE_MAIN; 2715 c.data.type = XFRM_POLICY_TYPE_MAIN;
2693 c.event = XFRM_MSG_FLUSHPOLICY; 2716 c.event = XFRM_MSG_FLUSHPOLICY;
2694 c.pid = hdr->sadb_msg_pid; 2717 c.pid = hdr->sadb_msg_pid;
2695 c.seq = hdr->sadb_msg_seq; 2718 c.seq = hdr->sadb_msg_seq;
2719 c.net = net;
2696 km_policy_notify(NULL, 0, &c); 2720 km_policy_notify(NULL, 0, &c);
2697 2721
2698 return 0; 2722 return 0;
@@ -2732,7 +2756,7 @@ static int pfkey_process(struct sock *sk, struct sk_buff *skb, struct sadb_msg *
2732 int err; 2756 int err;
2733 2757
2734 pfkey_broadcast(skb_clone(skb, GFP_KERNEL), GFP_KERNEL, 2758 pfkey_broadcast(skb_clone(skb, GFP_KERNEL), GFP_KERNEL,
2735 BROADCAST_PROMISC_ONLY, NULL); 2759 BROADCAST_PROMISC_ONLY, NULL, sock_net(sk));
2736 2760
2737 memset(ext_hdrs, 0, sizeof(ext_hdrs)); 2761 memset(ext_hdrs, 0, sizeof(ext_hdrs));
2738 err = parse_exthdrs(skb, hdr, ext_hdrs); 2762 err = parse_exthdrs(skb, hdr, ext_hdrs);
@@ -2935,13 +2959,16 @@ static int key_notify_sa_expire(struct xfrm_state *x, struct km_event *c)
2935 out_hdr->sadb_msg_seq = 0; 2959 out_hdr->sadb_msg_seq = 0;
2936 out_hdr->sadb_msg_pid = 0; 2960 out_hdr->sadb_msg_pid = 0;
2937 2961
2938 pfkey_broadcast(out_skb, GFP_ATOMIC, BROADCAST_REGISTERED, NULL); 2962 pfkey_broadcast(out_skb, GFP_ATOMIC, BROADCAST_REGISTERED, NULL, xs_net(x));
2939 return 0; 2963 return 0;
2940} 2964}
2941 2965
2942static int pfkey_send_notify(struct xfrm_state *x, struct km_event *c) 2966static int pfkey_send_notify(struct xfrm_state *x, struct km_event *c)
2943{ 2967{
2944 if (atomic_read(&pfkey_socks_nr) == 0) 2968 struct net *net = x ? xs_net(x) : c->net;
2969 struct netns_pfkey *net_pfkey = net_generic(net, pfkey_net_id);
2970
2971 if (atomic_read(&net_pfkey->socks_nr) == 0)
2945 return 0; 2972 return 0;
2946 2973
2947 switch (c->event) { 2974 switch (c->event) {
@@ -3103,12 +3130,13 @@ static int pfkey_send_acquire(struct xfrm_state *x, struct xfrm_tmpl *t, struct
3103 xfrm_ctx->ctx_len); 3130 xfrm_ctx->ctx_len);
3104 } 3131 }
3105 3132
3106 return pfkey_broadcast(skb, GFP_ATOMIC, BROADCAST_REGISTERED, NULL); 3133 return pfkey_broadcast(skb, GFP_ATOMIC, BROADCAST_REGISTERED, NULL, xs_net(x));
3107} 3134}
3108 3135
3109static struct xfrm_policy *pfkey_compile_policy(struct sock *sk, int opt, 3136static struct xfrm_policy *pfkey_compile_policy(struct sock *sk, int opt,
3110 u8 *data, int len, int *dir) 3137 u8 *data, int len, int *dir)
3111{ 3138{
3139 struct net *net = sock_net(sk);
3112 struct xfrm_policy *xp; 3140 struct xfrm_policy *xp;
3113 struct sadb_x_policy *pol = (struct sadb_x_policy*)data; 3141 struct sadb_x_policy *pol = (struct sadb_x_policy*)data;
3114 struct sadb_x_sec_ctx *sec_ctx; 3142 struct sadb_x_sec_ctx *sec_ctx;
@@ -3141,7 +3169,7 @@ static struct xfrm_policy *pfkey_compile_policy(struct sock *sk, int opt,
3141 (!pol->sadb_x_policy_dir || pol->sadb_x_policy_dir > IPSEC_DIR_OUTBOUND)) 3169 (!pol->sadb_x_policy_dir || pol->sadb_x_policy_dir > IPSEC_DIR_OUTBOUND))
3142 return NULL; 3170 return NULL;
3143 3171
3144 xp = xfrm_policy_alloc(GFP_ATOMIC); 3172 xp = xfrm_policy_alloc(net, GFP_ATOMIC);
3145 if (xp == NULL) { 3173 if (xp == NULL) {
3146 *dir = -ENOBUFS; 3174 *dir = -ENOBUFS;
3147 return NULL; 3175 return NULL;
@@ -3300,7 +3328,7 @@ static int pfkey_send_new_mapping(struct xfrm_state *x, xfrm_address_t *ipaddr,
3300 n_port->sadb_x_nat_t_port_port = sport; 3328 n_port->sadb_x_nat_t_port_port = sport;
3301 n_port->sadb_x_nat_t_port_reserved = 0; 3329 n_port->sadb_x_nat_t_port_reserved = 0;
3302 3330
3303 return pfkey_broadcast(skb, GFP_ATOMIC, BROADCAST_REGISTERED, NULL); 3331 return pfkey_broadcast(skb, GFP_ATOMIC, BROADCAST_REGISTERED, NULL, xs_net(x));
3304} 3332}
3305 3333
3306#ifdef CONFIG_NET_KEY_MIGRATE 3334#ifdef CONFIG_NET_KEY_MIGRATE
@@ -3491,7 +3519,7 @@ static int pfkey_send_migrate(struct xfrm_selector *sel, u8 dir, u8 type,
3491 } 3519 }
3492 3520
3493 /* broadcast migrate message to sockets */ 3521 /* broadcast migrate message to sockets */
3494 pfkey_broadcast(skb, GFP_ATOMIC, BROADCAST_ALL, NULL); 3522 pfkey_broadcast(skb, GFP_ATOMIC, BROADCAST_ALL, NULL, &init_net);
3495 3523
3496 return 0; 3524 return 0;
3497 3525
@@ -3645,6 +3673,8 @@ static int pfkey_seq_show(struct seq_file *f, void *v)
3645 3673
3646static void *pfkey_seq_start(struct seq_file *f, loff_t *ppos) 3674static void *pfkey_seq_start(struct seq_file *f, loff_t *ppos)
3647{ 3675{
3676 struct net *net = seq_file_net(f);
3677 struct netns_pfkey *net_pfkey = net_generic(net, pfkey_net_id);
3648 struct sock *s; 3678 struct sock *s;
3649 struct hlist_node *node; 3679 struct hlist_node *node;
3650 loff_t pos = *ppos; 3680 loff_t pos = *ppos;
@@ -3653,7 +3683,7 @@ static void *pfkey_seq_start(struct seq_file *f, loff_t *ppos)
3653 if (pos == 0) 3683 if (pos == 0)
3654 return SEQ_START_TOKEN; 3684 return SEQ_START_TOKEN;
3655 3685
3656 sk_for_each(s, node, &pfkey_table) 3686 sk_for_each(s, node, &net_pfkey->table)
3657 if (pos-- == 1) 3687 if (pos-- == 1)
3658 return s; 3688 return s;
3659 3689
@@ -3662,9 +3692,12 @@ static void *pfkey_seq_start(struct seq_file *f, loff_t *ppos)
3662 3692
3663static void *pfkey_seq_next(struct seq_file *f, void *v, loff_t *ppos) 3693static void *pfkey_seq_next(struct seq_file *f, void *v, loff_t *ppos)
3664{ 3694{
3695 struct net *net = seq_file_net(f);
3696 struct netns_pfkey *net_pfkey = net_generic(net, pfkey_net_id);
3697
3665 ++*ppos; 3698 ++*ppos;
3666 return (v == SEQ_START_TOKEN) ? 3699 return (v == SEQ_START_TOKEN) ?
3667 sk_head(&pfkey_table) : 3700 sk_head(&net_pfkey->table) :
3668 sk_next((struct sock *)v); 3701 sk_next((struct sock *)v);
3669} 3702}
3670 3703
@@ -3682,38 +3715,39 @@ static struct seq_operations pfkey_seq_ops = {
3682 3715
3683static int pfkey_seq_open(struct inode *inode, struct file *file) 3716static int pfkey_seq_open(struct inode *inode, struct file *file)
3684{ 3717{
3685 return seq_open(file, &pfkey_seq_ops); 3718 return seq_open_net(inode, file, &pfkey_seq_ops,
3719 sizeof(struct seq_net_private));
3686} 3720}
3687 3721
3688static struct file_operations pfkey_proc_ops = { 3722static struct file_operations pfkey_proc_ops = {
3689 .open = pfkey_seq_open, 3723 .open = pfkey_seq_open,
3690 .read = seq_read, 3724 .read = seq_read,
3691 .llseek = seq_lseek, 3725 .llseek = seq_lseek,
3692 .release = seq_release, 3726 .release = seq_release_net,
3693}; 3727};
3694 3728
3695static int pfkey_init_proc(void) 3729static int __net_init pfkey_init_proc(struct net *net)
3696{ 3730{
3697 struct proc_dir_entry *e; 3731 struct proc_dir_entry *e;
3698 3732
3699 e = proc_net_fops_create(&init_net, "pfkey", 0, &pfkey_proc_ops); 3733 e = proc_net_fops_create(net, "pfkey", 0, &pfkey_proc_ops);
3700 if (e == NULL) 3734 if (e == NULL)
3701 return -ENOMEM; 3735 return -ENOMEM;
3702 3736
3703 return 0; 3737 return 0;
3704} 3738}
3705 3739
3706static void pfkey_exit_proc(void) 3740static void pfkey_exit_proc(struct net *net)
3707{ 3741{
3708 proc_net_remove(&init_net, "pfkey"); 3742 proc_net_remove(net, "pfkey");
3709} 3743}
3710#else 3744#else
3711static inline int pfkey_init_proc(void) 3745static int __net_init pfkey_init_proc(struct net *net)
3712{ 3746{
3713 return 0; 3747 return 0;
3714} 3748}
3715 3749
3716static inline void pfkey_exit_proc(void) 3750static void pfkey_exit_proc(struct net *net)
3717{ 3751{
3718} 3752}
3719#endif 3753#endif
@@ -3729,10 +3763,51 @@ static struct xfrm_mgr pfkeyv2_mgr =
3729 .migrate = pfkey_send_migrate, 3763 .migrate = pfkey_send_migrate,
3730}; 3764};
3731 3765
3766static int __net_init pfkey_net_init(struct net *net)
3767{
3768 struct netns_pfkey *net_pfkey;
3769 int rv;
3770
3771 net_pfkey = kmalloc(sizeof(struct netns_pfkey), GFP_KERNEL);
3772 if (!net_pfkey) {
3773 rv = -ENOMEM;
3774 goto out_kmalloc;
3775 }
3776 INIT_HLIST_HEAD(&net_pfkey->table);
3777 atomic_set(&net_pfkey->socks_nr, 0);
3778 rv = net_assign_generic(net, pfkey_net_id, net_pfkey);
3779 if (rv < 0)
3780 goto out_assign;
3781 rv = pfkey_init_proc(net);
3782 if (rv < 0)
3783 goto out_proc;
3784 return 0;
3785
3786out_proc:
3787out_assign:
3788 kfree(net_pfkey);
3789out_kmalloc:
3790 return rv;
3791}
3792
3793static void __net_exit pfkey_net_exit(struct net *net)
3794{
3795 struct netns_pfkey *net_pfkey = net_generic(net, pfkey_net_id);
3796
3797 pfkey_exit_proc(net);
3798 BUG_ON(!hlist_empty(&net_pfkey->table));
3799 kfree(net_pfkey);
3800}
3801
3802static struct pernet_operations pfkey_net_ops = {
3803 .init = pfkey_net_init,
3804 .exit = pfkey_net_exit,
3805};
3806
3732static void __exit ipsec_pfkey_exit(void) 3807static void __exit ipsec_pfkey_exit(void)
3733{ 3808{
3809 unregister_pernet_gen_subsys(pfkey_net_id, &pfkey_net_ops);
3734 xfrm_unregister_km(&pfkeyv2_mgr); 3810 xfrm_unregister_km(&pfkeyv2_mgr);
3735 pfkey_exit_proc();
3736 sock_unregister(PF_KEY); 3811 sock_unregister(PF_KEY);
3737 proto_unregister(&key_proto); 3812 proto_unregister(&key_proto);
3738} 3813}
@@ -3747,16 +3822,16 @@ static int __init ipsec_pfkey_init(void)
3747 err = sock_register(&pfkey_family_ops); 3822 err = sock_register(&pfkey_family_ops);
3748 if (err != 0) 3823 if (err != 0)
3749 goto out_unregister_key_proto; 3824 goto out_unregister_key_proto;
3750 err = pfkey_init_proc(); 3825 err = xfrm_register_km(&pfkeyv2_mgr);
3751 if (err != 0) 3826 if (err != 0)
3752 goto out_sock_unregister; 3827 goto out_sock_unregister;
3753 err = xfrm_register_km(&pfkeyv2_mgr); 3828 err = register_pernet_gen_subsys(&pfkey_net_id, &pfkey_net_ops);
3754 if (err != 0) 3829 if (err != 0)
3755 goto out_remove_proc_entry; 3830 goto out_xfrm_unregister_km;
3756out: 3831out:
3757 return err; 3832 return err;
3758out_remove_proc_entry: 3833out_xfrm_unregister_km:
3759 pfkey_exit_proc(); 3834 xfrm_unregister_km(&pfkeyv2_mgr);
3760out_sock_unregister: 3835out_sock_unregister:
3761 sock_unregister(PF_KEY); 3836 sock_unregister(PF_KEY);
3762out_unregister_key_proto: 3837out_unregister_key_proto:
diff --git a/net/llc/af_llc.c b/net/llc/af_llc.c
index 5bcc452a247f..56fd85ab358e 100644
--- a/net/llc/af_llc.c
+++ b/net/llc/af_llc.c
@@ -103,7 +103,6 @@ static inline u8 llc_ui_header_len(struct sock *sk, struct sockaddr_llc *addr)
103 * llc_ui_send_data - send data via reliable llc2 connection 103 * llc_ui_send_data - send data via reliable llc2 connection
104 * @sk: Connection the socket is using. 104 * @sk: Connection the socket is using.
105 * @skb: Data the user wishes to send. 105 * @skb: Data the user wishes to send.
106 * @addr: Source and destination fields provided by the user.
107 * @noblock: can we block waiting for data? 106 * @noblock: can we block waiting for data?
108 * 107 *
109 * Send data via reliable llc2 connection. 108 * Send data via reliable llc2 connection.
diff --git a/net/llc/llc_proc.c b/net/llc/llc_proc.c
index 48212c0a961c..b58bd7c6cdf8 100644
--- a/net/llc/llc_proc.c
+++ b/net/llc/llc_proc.c
@@ -27,8 +27,7 @@
27 27
28static void llc_ui_format_mac(struct seq_file *seq, u8 *addr) 28static void llc_ui_format_mac(struct seq_file *seq, u8 *addr)
29{ 29{
30 DECLARE_MAC_BUF(mac); 30 seq_printf(seq, "%pM", addr);
31 seq_printf(seq, "%s", print_mac(mac, addr));
32} 31}
33 32
34static struct sock *llc_get_sk_idx(loff_t pos) 33static struct sock *llc_get_sk_idx(loff_t pos)
diff --git a/net/llc/sysctl_net_llc.c b/net/llc/sysctl_net_llc.c
index 5bef1dcf18e3..57b9304d444c 100644
--- a/net/llc/sysctl_net_llc.c
+++ b/net/llc/sysctl_net_llc.c
@@ -20,8 +20,8 @@ static struct ctl_table llc2_timeout_table[] = {
20 .data = &sysctl_llc2_ack_timeout, 20 .data = &sysctl_llc2_ack_timeout,
21 .maxlen = sizeof(long), 21 .maxlen = sizeof(long),
22 .mode = 0644, 22 .mode = 0644,
23 .proc_handler = &proc_dointvec_jiffies, 23 .proc_handler = proc_dointvec_jiffies,
24 .strategy = &sysctl_jiffies, 24 .strategy = sysctl_jiffies,
25 }, 25 },
26 { 26 {
27 .ctl_name = NET_LLC2_BUSY_TIMEOUT, 27 .ctl_name = NET_LLC2_BUSY_TIMEOUT,
@@ -29,8 +29,8 @@ static struct ctl_table llc2_timeout_table[] = {
29 .data = &sysctl_llc2_busy_timeout, 29 .data = &sysctl_llc2_busy_timeout,
30 .maxlen = sizeof(long), 30 .maxlen = sizeof(long),
31 .mode = 0644, 31 .mode = 0644,
32 .proc_handler = &proc_dointvec_jiffies, 32 .proc_handler = proc_dointvec_jiffies,
33 .strategy = &sysctl_jiffies, 33 .strategy = sysctl_jiffies,
34 }, 34 },
35 { 35 {
36 .ctl_name = NET_LLC2_P_TIMEOUT, 36 .ctl_name = NET_LLC2_P_TIMEOUT,
@@ -38,8 +38,8 @@ static struct ctl_table llc2_timeout_table[] = {
38 .data = &sysctl_llc2_p_timeout, 38 .data = &sysctl_llc2_p_timeout,
39 .maxlen = sizeof(long), 39 .maxlen = sizeof(long),
40 .mode = 0644, 40 .mode = 0644,
41 .proc_handler = &proc_dointvec_jiffies, 41 .proc_handler = proc_dointvec_jiffies,
42 .strategy = &sysctl_jiffies, 42 .strategy = sysctl_jiffies,
43 }, 43 },
44 { 44 {
45 .ctl_name = NET_LLC2_REJ_TIMEOUT, 45 .ctl_name = NET_LLC2_REJ_TIMEOUT,
@@ -47,8 +47,8 @@ static struct ctl_table llc2_timeout_table[] = {
47 .data = &sysctl_llc2_rej_timeout, 47 .data = &sysctl_llc2_rej_timeout,
48 .maxlen = sizeof(long), 48 .maxlen = sizeof(long),
49 .mode = 0644, 49 .mode = 0644,
50 .proc_handler = &proc_dointvec_jiffies, 50 .proc_handler = proc_dointvec_jiffies,
51 .strategy = &sysctl_jiffies, 51 .strategy = sysctl_jiffies,
52 }, 52 },
53 { 0 }, 53 { 0 },
54}; 54};
@@ -60,8 +60,8 @@ static struct ctl_table llc_station_table[] = {
60 .data = &sysctl_llc_station_ack_timeout, 60 .data = &sysctl_llc_station_ack_timeout,
61 .maxlen = sizeof(long), 61 .maxlen = sizeof(long),
62 .mode = 0644, 62 .mode = 0644,
63 .proc_handler = &proc_dointvec_jiffies, 63 .proc_handler = proc_dointvec_jiffies,
64 .strategy = &sysctl_jiffies, 64 .strategy = sysctl_jiffies,
65 }, 65 },
66 { 0 }, 66 { 0 },
67}; 67};
diff --git a/net/mac80211/Kconfig b/net/mac80211/Kconfig
index 7f710a27e91c..60c16162474c 100644
--- a/net/mac80211/Kconfig
+++ b/net/mac80211/Kconfig
@@ -16,20 +16,20 @@ menu "Rate control algorithm selection"
16 16
17config MAC80211_RC_PID 17config MAC80211_RC_PID
18 bool "PID controller based rate control algorithm" if EMBEDDED 18 bool "PID controller based rate control algorithm" if EMBEDDED
19 default y
20 ---help--- 19 ---help---
21 This option enables a TX rate control algorithm for 20 This option enables a TX rate control algorithm for
22 mac80211 that uses a PID controller to select the TX 21 mac80211 that uses a PID controller to select the TX
23 rate. 22 rate.
24 23
25config MAC80211_RC_MINSTREL 24config MAC80211_RC_MINSTREL
26 bool "Minstrel" 25 bool "Minstrel" if EMBEDDED
26 default y
27 ---help--- 27 ---help---
28 This option enables the 'minstrel' TX rate control algorithm 28 This option enables the 'minstrel' TX rate control algorithm
29 29
30choice 30choice
31 prompt "Default rate control algorithm" 31 prompt "Default rate control algorithm"
32 default MAC80211_RC_DEFAULT_PID 32 default MAC80211_RC_DEFAULT_MINSTREL
33 ---help--- 33 ---help---
34 This option selects the default rate control algorithm 34 This option selects the default rate control algorithm
35 mac80211 will use. Note that this default can still be 35 mac80211 will use. Note that this default can still be
@@ -55,8 +55,8 @@ endchoice
55 55
56config MAC80211_RC_DEFAULT 56config MAC80211_RC_DEFAULT
57 string 57 string
58 default "pid" if MAC80211_RC_DEFAULT_PID
59 default "minstrel" if MAC80211_RC_DEFAULT_MINSTREL 58 default "minstrel" if MAC80211_RC_DEFAULT_MINSTREL
59 default "pid" if MAC80211_RC_DEFAULT_PID
60 default "" 60 default ""
61 61
62endmenu 62endmenu
diff --git a/net/mac80211/Makefile b/net/mac80211/Makefile
index 31cfd1f89a72..7d4971aa443f 100644
--- a/net/mac80211/Makefile
+++ b/net/mac80211/Makefile
@@ -46,3 +46,5 @@ rc80211_minstrel-$(CONFIG_MAC80211_DEBUGFS) += rc80211_minstrel_debugfs.o
46 46
47mac80211-$(CONFIG_MAC80211_RC_PID) += $(rc80211_pid-y) 47mac80211-$(CONFIG_MAC80211_RC_PID) += $(rc80211_pid-y)
48mac80211-$(CONFIG_MAC80211_RC_MINSTREL) += $(rc80211_minstrel-y) 48mac80211-$(CONFIG_MAC80211_RC_MINSTREL) += $(rc80211_minstrel-y)
49
50ccflags-y += -D__CHECK_ENDIAN__
diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
index 855126a3039d..9d4e4d846ec1 100644
--- a/net/mac80211/cfg.c
+++ b/net/mac80211/cfg.c
@@ -17,13 +17,6 @@
17#include "rate.h" 17#include "rate.h"
18#include "mesh.h" 18#include "mesh.h"
19 19
20struct ieee80211_hw *wiphy_to_hw(struct wiphy *wiphy)
21{
22 struct ieee80211_local *local = wiphy_priv(wiphy);
23 return &local->hw;
24}
25EXPORT_SYMBOL(wiphy_to_hw);
26
27static bool nl80211_type_check(enum nl80211_iftype type) 20static bool nl80211_type_check(enum nl80211_iftype type)
28{ 21{
29 switch (type) { 22 switch (type) {
@@ -33,6 +26,8 @@ static bool nl80211_type_check(enum nl80211_iftype type)
33#ifdef CONFIG_MAC80211_MESH 26#ifdef CONFIG_MAC80211_MESH
34 case NL80211_IFTYPE_MESH_POINT: 27 case NL80211_IFTYPE_MESH_POINT:
35#endif 28#endif
29 case NL80211_IFTYPE_AP:
30 case NL80211_IFTYPE_AP_VLAN:
36 case NL80211_IFTYPE_WDS: 31 case NL80211_IFTYPE_WDS:
37 return true; 32 return true;
38 default: 33 default:
@@ -315,12 +310,35 @@ static void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo)
315 310
316 sinfo->filled = STATION_INFO_INACTIVE_TIME | 311 sinfo->filled = STATION_INFO_INACTIVE_TIME |
317 STATION_INFO_RX_BYTES | 312 STATION_INFO_RX_BYTES |
318 STATION_INFO_TX_BYTES; 313 STATION_INFO_TX_BYTES |
314 STATION_INFO_TX_BITRATE;
319 315
320 sinfo->inactive_time = jiffies_to_msecs(jiffies - sta->last_rx); 316 sinfo->inactive_time = jiffies_to_msecs(jiffies - sta->last_rx);
321 sinfo->rx_bytes = sta->rx_bytes; 317 sinfo->rx_bytes = sta->rx_bytes;
322 sinfo->tx_bytes = sta->tx_bytes; 318 sinfo->tx_bytes = sta->tx_bytes;
323 319
320 if (sta->local->hw.flags & IEEE80211_HW_SIGNAL_DBM) {
321 sinfo->filled |= STATION_INFO_SIGNAL;
322 sinfo->signal = (s8)sta->last_signal;
323 }
324
325 sinfo->txrate.flags = 0;
326 if (sta->last_tx_rate.flags & IEEE80211_TX_RC_MCS)
327 sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS;
328 if (sta->last_tx_rate.flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
329 sinfo->txrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
330 if (sta->last_tx_rate.flags & IEEE80211_TX_RC_SHORT_GI)
331 sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
332
333 if (!(sta->last_tx_rate.flags & IEEE80211_TX_RC_MCS)) {
334 struct ieee80211_supported_band *sband;
335 sband = sta->local->hw.wiphy->bands[
336 sta->local->hw.conf.channel->band];
337 sinfo->txrate.legacy =
338 sband->bitrates[sta->last_tx_rate.idx].bitrate;
339 } else
340 sinfo->txrate.mcs = sta->last_tx_rate.idx;
341
324 if (ieee80211_vif_is_mesh(&sdata->vif)) { 342 if (ieee80211_vif_is_mesh(&sdata->vif)) {
325#ifdef CONFIG_MAC80211_MESH 343#ifdef CONFIG_MAC80211_MESH
326 sinfo->filled |= STATION_INFO_LLID | 344 sinfo->filled |= STATION_INFO_LLID |
@@ -401,8 +419,10 @@ static int ieee80211_config_beacon(struct ieee80211_sub_if_data *sdata,
401 */ 419 */
402 if (params->interval) { 420 if (params->interval) {
403 sdata->local->hw.conf.beacon_int = params->interval; 421 sdata->local->hw.conf.beacon_int = params->interval;
404 if (ieee80211_hw_config(sdata->local)) 422 err = ieee80211_hw_config(sdata->local,
405 return -EINVAL; 423 IEEE80211_CONF_CHANGE_BEACON_INTERVAL);
424 if (err < 0)
425 return err;
406 /* 426 /*
407 * We updated some parameter so if below bails out 427 * We updated some parameter so if below bails out
408 * it's not an error. 428 * it's not an error.
@@ -589,6 +609,8 @@ static void sta_apply_parameters(struct ieee80211_local *local,
589 struct ieee80211_supported_band *sband; 609 struct ieee80211_supported_band *sband;
590 struct ieee80211_sub_if_data *sdata = sta->sdata; 610 struct ieee80211_sub_if_data *sdata = sta->sdata;
591 611
612 sband = local->hw.wiphy->bands[local->oper_channel->band];
613
592 /* 614 /*
593 * FIXME: updating the flags is racy when this function is 615 * FIXME: updating the flags is racy when this function is
594 * called from ieee80211_change_station(), this will 616 * called from ieee80211_change_station(), this will
@@ -629,7 +651,6 @@ static void sta_apply_parameters(struct ieee80211_local *local,
629 651
630 if (params->supported_rates) { 652 if (params->supported_rates) {
631 rates = 0; 653 rates = 0;
632 sband = local->hw.wiphy->bands[local->oper_channel->band];
633 654
634 for (i = 0; i < params->supported_rates_len; i++) { 655 for (i = 0; i < params->supported_rates_len; i++) {
635 int rate = (params->supported_rates[i] & 0x7f) * 5; 656 int rate = (params->supported_rates[i] & 0x7f) * 5;
@@ -641,10 +662,10 @@ static void sta_apply_parameters(struct ieee80211_local *local,
641 sta->sta.supp_rates[local->oper_channel->band] = rates; 662 sta->sta.supp_rates[local->oper_channel->band] = rates;
642 } 663 }
643 664
644 if (params->ht_capa) { 665 if (params->ht_capa)
645 ieee80211_ht_cap_ie_to_ht_info(params->ht_capa, 666 ieee80211_ht_cap_ie_to_sta_ht_cap(sband,
646 &sta->sta.ht_info); 667 params->ht_capa,
647 } 668 &sta->sta.ht_cap);
648 669
649 if (ieee80211_vif_is_mesh(&sdata->vif) && params->plink_action) { 670 if (ieee80211_vif_is_mesh(&sdata->vif) && params->plink_action) {
650 switch (params->plink_action) { 671 switch (params->plink_action) {
@@ -665,6 +686,7 @@ static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
665 struct sta_info *sta; 686 struct sta_info *sta;
666 struct ieee80211_sub_if_data *sdata; 687 struct ieee80211_sub_if_data *sdata;
667 int err; 688 int err;
689 int layer2_update;
668 690
669 /* Prevent a race with changing the rate control algorithm */ 691 /* Prevent a race with changing the rate control algorithm */
670 if (!netif_running(dev)) 692 if (!netif_running(dev))
@@ -695,17 +717,25 @@ static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
695 717
696 rate_control_rate_init(sta); 718 rate_control_rate_init(sta);
697 719
720 layer2_update = sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
721 sdata->vif.type == NL80211_IFTYPE_AP;
722
698 rcu_read_lock(); 723 rcu_read_lock();
699 724
700 err = sta_info_insert(sta); 725 err = sta_info_insert(sta);
701 if (err) { 726 if (err) {
702 /* STA has been freed */ 727 /* STA has been freed */
728 if (err == -EEXIST && layer2_update) {
729 /* Need to update layer 2 devices on reassociation */
730 sta = sta_info_get(local, mac);
731 if (sta)
732 ieee80211_send_layer2_update(sta);
733 }
703 rcu_read_unlock(); 734 rcu_read_unlock();
704 return err; 735 return err;
705 } 736 }
706 737
707 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN || 738 if (layer2_update)
708 sdata->vif.type == NL80211_IFTYPE_AP)
709 ieee80211_send_layer2_update(sta); 739 ieee80211_send_layer2_update(sta);
710 740
711 rcu_read_unlock(); 741 rcu_read_unlock();
@@ -957,6 +987,72 @@ static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev,
957 rcu_read_unlock(); 987 rcu_read_unlock();
958 return 0; 988 return 0;
959} 989}
990
991static int ieee80211_get_mesh_params(struct wiphy *wiphy,
992 struct net_device *dev,
993 struct mesh_config *conf)
994{
995 struct ieee80211_sub_if_data *sdata;
996 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
997
998 if (sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
999 return -ENOTSUPP;
1000 memcpy(conf, &(sdata->u.mesh.mshcfg), sizeof(struct mesh_config));
1001 return 0;
1002}
1003
1004static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm, u32 mask)
1005{
1006 return (mask >> (parm-1)) & 0x1;
1007}
1008
1009static int ieee80211_set_mesh_params(struct wiphy *wiphy,
1010 struct net_device *dev,
1011 const struct mesh_config *nconf, u32 mask)
1012{
1013 struct mesh_config *conf;
1014 struct ieee80211_sub_if_data *sdata;
1015 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1016
1017 if (sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
1018 return -ENOTSUPP;
1019
1020 /* Set the config options which we are interested in setting */
1021 conf = &(sdata->u.mesh.mshcfg);
1022 if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT, mask))
1023 conf->dot11MeshRetryTimeout = nconf->dot11MeshRetryTimeout;
1024 if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT, mask))
1025 conf->dot11MeshConfirmTimeout = nconf->dot11MeshConfirmTimeout;
1026 if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT, mask))
1027 conf->dot11MeshHoldingTimeout = nconf->dot11MeshHoldingTimeout;
1028 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS, mask))
1029 conf->dot11MeshMaxPeerLinks = nconf->dot11MeshMaxPeerLinks;
1030 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES, mask))
1031 conf->dot11MeshMaxRetries = nconf->dot11MeshMaxRetries;
1032 if (_chg_mesh_attr(NL80211_MESHCONF_TTL, mask))
1033 conf->dot11MeshTTL = nconf->dot11MeshTTL;
1034 if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS, mask))
1035 conf->auto_open_plinks = nconf->auto_open_plinks;
1036 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, mask))
1037 conf->dot11MeshHWMPmaxPREQretries =
1038 nconf->dot11MeshHWMPmaxPREQretries;
1039 if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME, mask))
1040 conf->path_refresh_time = nconf->path_refresh_time;
1041 if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, mask))
1042 conf->min_discovery_timeout = nconf->min_discovery_timeout;
1043 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, mask))
1044 conf->dot11MeshHWMPactivePathTimeout =
1045 nconf->dot11MeshHWMPactivePathTimeout;
1046 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, mask))
1047 conf->dot11MeshHWMPpreqMinInterval =
1048 nconf->dot11MeshHWMPpreqMinInterval;
1049 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
1050 mask))
1051 conf->dot11MeshHWMPnetDiameterTraversalTime =
1052 nconf->dot11MeshHWMPnetDiameterTraversalTime;
1053 return 0;
1054}
1055
960#endif 1056#endif
961 1057
962static int ieee80211_change_bss(struct wiphy *wiphy, 1058static int ieee80211_change_bss(struct wiphy *wiphy,
@@ -972,25 +1068,79 @@ static int ieee80211_change_bss(struct wiphy *wiphy,
972 return -EINVAL; 1068 return -EINVAL;
973 1069
974 if (params->use_cts_prot >= 0) { 1070 if (params->use_cts_prot >= 0) {
975 sdata->bss_conf.use_cts_prot = params->use_cts_prot; 1071 sdata->vif.bss_conf.use_cts_prot = params->use_cts_prot;
976 changed |= BSS_CHANGED_ERP_CTS_PROT; 1072 changed |= BSS_CHANGED_ERP_CTS_PROT;
977 } 1073 }
978 if (params->use_short_preamble >= 0) { 1074 if (params->use_short_preamble >= 0) {
979 sdata->bss_conf.use_short_preamble = 1075 sdata->vif.bss_conf.use_short_preamble =
980 params->use_short_preamble; 1076 params->use_short_preamble;
981 changed |= BSS_CHANGED_ERP_PREAMBLE; 1077 changed |= BSS_CHANGED_ERP_PREAMBLE;
982 } 1078 }
983 if (params->use_short_slot_time >= 0) { 1079 if (params->use_short_slot_time >= 0) {
984 sdata->bss_conf.use_short_slot = 1080 sdata->vif.bss_conf.use_short_slot =
985 params->use_short_slot_time; 1081 params->use_short_slot_time;
986 changed |= BSS_CHANGED_ERP_SLOT; 1082 changed |= BSS_CHANGED_ERP_SLOT;
987 } 1083 }
988 1084
1085 if (params->basic_rates) {
1086 int i, j;
1087 u32 rates = 0;
1088 struct ieee80211_local *local = wiphy_priv(wiphy);
1089 struct ieee80211_supported_band *sband =
1090 wiphy->bands[local->oper_channel->band];
1091
1092 for (i = 0; i < params->basic_rates_len; i++) {
1093 int rate = (params->basic_rates[i] & 0x7f) * 5;
1094 for (j = 0; j < sband->n_bitrates; j++) {
1095 if (sband->bitrates[j].bitrate == rate)
1096 rates |= BIT(j);
1097 }
1098 }
1099 sdata->vif.bss_conf.basic_rates = rates;
1100 changed |= BSS_CHANGED_BASIC_RATES;
1101 }
1102
989 ieee80211_bss_info_change_notify(sdata, changed); 1103 ieee80211_bss_info_change_notify(sdata, changed);
990 1104
991 return 0; 1105 return 0;
992} 1106}
993 1107
1108static int ieee80211_set_txq_params(struct wiphy *wiphy,
1109 struct ieee80211_txq_params *params)
1110{
1111 struct ieee80211_local *local = wiphy_priv(wiphy);
1112 struct ieee80211_tx_queue_params p;
1113
1114 if (!local->ops->conf_tx)
1115 return -EOPNOTSUPP;
1116
1117 memset(&p, 0, sizeof(p));
1118 p.aifs = params->aifs;
1119 p.cw_max = params->cwmax;
1120 p.cw_min = params->cwmin;
1121 p.txop = params->txop;
1122 if (local->ops->conf_tx(local_to_hw(local), params->queue, &p)) {
1123 printk(KERN_DEBUG "%s: failed to set TX queue "
1124 "parameters for queue %d\n", local->mdev->name,
1125 params->queue);
1126 return -EINVAL;
1127 }
1128
1129 return 0;
1130}
1131
1132static int ieee80211_set_channel(struct wiphy *wiphy,
1133 struct ieee80211_channel *chan,
1134 enum nl80211_channel_type channel_type)
1135{
1136 struct ieee80211_local *local = wiphy_priv(wiphy);
1137
1138 local->oper_channel = chan;
1139 local->oper_channel_type = channel_type;
1140
1141 return ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL);
1142}
1143
994struct cfg80211_ops mac80211_config_ops = { 1144struct cfg80211_ops mac80211_config_ops = {
995 .add_virtual_intf = ieee80211_add_iface, 1145 .add_virtual_intf = ieee80211_add_iface,
996 .del_virtual_intf = ieee80211_del_iface, 1146 .del_virtual_intf = ieee80211_del_iface,
@@ -1013,6 +1163,10 @@ struct cfg80211_ops mac80211_config_ops = {
1013 .change_mpath = ieee80211_change_mpath, 1163 .change_mpath = ieee80211_change_mpath,
1014 .get_mpath = ieee80211_get_mpath, 1164 .get_mpath = ieee80211_get_mpath,
1015 .dump_mpath = ieee80211_dump_mpath, 1165 .dump_mpath = ieee80211_dump_mpath,
1166 .set_mesh_params = ieee80211_set_mesh_params,
1167 .get_mesh_params = ieee80211_get_mesh_params,
1016#endif 1168#endif
1017 .change_bss = ieee80211_change_bss, 1169 .change_bss = ieee80211_change_bss,
1170 .set_txq_params = ieee80211_set_txq_params,
1171 .set_channel = ieee80211_set_channel,
1018}; 1172};
diff --git a/net/mac80211/debugfs.c b/net/mac80211/debugfs.c
index 24ce54463310..2697a2fe608f 100644
--- a/net/mac80211/debugfs.c
+++ b/net/mac80211/debugfs.c
@@ -47,18 +47,14 @@ static const struct file_operations name## _ops = { \
47 47
48DEBUGFS_READONLY_FILE(frequency, 20, "%d", 48DEBUGFS_READONLY_FILE(frequency, 20, "%d",
49 local->hw.conf.channel->center_freq); 49 local->hw.conf.channel->center_freq);
50DEBUGFS_READONLY_FILE(antenna_sel_tx, 20, "%d",
51 local->hw.conf.antenna_sel_tx);
52DEBUGFS_READONLY_FILE(antenna_sel_rx, 20, "%d",
53 local->hw.conf.antenna_sel_rx);
54DEBUGFS_READONLY_FILE(rts_threshold, 20, "%d", 50DEBUGFS_READONLY_FILE(rts_threshold, 20, "%d",
55 local->rts_threshold); 51 local->rts_threshold);
56DEBUGFS_READONLY_FILE(fragmentation_threshold, 20, "%d", 52DEBUGFS_READONLY_FILE(fragmentation_threshold, 20, "%d",
57 local->fragmentation_threshold); 53 local->fragmentation_threshold);
58DEBUGFS_READONLY_FILE(short_retry_limit, 20, "%d", 54DEBUGFS_READONLY_FILE(short_retry_limit, 20, "%d",
59 local->short_retry_limit); 55 local->hw.conf.short_frame_max_tx_count);
60DEBUGFS_READONLY_FILE(long_retry_limit, 20, "%d", 56DEBUGFS_READONLY_FILE(long_retry_limit, 20, "%d",
61 local->long_retry_limit); 57 local->hw.conf.long_frame_max_tx_count);
62DEBUGFS_READONLY_FILE(total_ps_buffered, 20, "%d", 58DEBUGFS_READONLY_FILE(total_ps_buffered, 20, "%d",
63 local->total_ps_buffered); 59 local->total_ps_buffered);
64DEBUGFS_READONLY_FILE(wep_iv, 20, "%#06x", 60DEBUGFS_READONLY_FILE(wep_iv, 20, "%#06x",
@@ -202,8 +198,6 @@ void debugfs_hw_add(struct ieee80211_local *local)
202 local->debugfs.keys = debugfs_create_dir("keys", phyd); 198 local->debugfs.keys = debugfs_create_dir("keys", phyd);
203 199
204 DEBUGFS_ADD(frequency); 200 DEBUGFS_ADD(frequency);
205 DEBUGFS_ADD(antenna_sel_tx);
206 DEBUGFS_ADD(antenna_sel_rx);
207 DEBUGFS_ADD(rts_threshold); 201 DEBUGFS_ADD(rts_threshold);
208 DEBUGFS_ADD(fragmentation_threshold); 202 DEBUGFS_ADD(fragmentation_threshold);
209 DEBUGFS_ADD(short_retry_limit); 203 DEBUGFS_ADD(short_retry_limit);
@@ -258,8 +252,6 @@ void debugfs_hw_add(struct ieee80211_local *local)
258void debugfs_hw_del(struct ieee80211_local *local) 252void debugfs_hw_del(struct ieee80211_local *local)
259{ 253{
260 DEBUGFS_DEL(frequency); 254 DEBUGFS_DEL(frequency);
261 DEBUGFS_DEL(antenna_sel_tx);
262 DEBUGFS_DEL(antenna_sel_rx);
263 DEBUGFS_DEL(rts_threshold); 255 DEBUGFS_DEL(rts_threshold);
264 DEBUGFS_DEL(fragmentation_threshold); 256 DEBUGFS_DEL(fragmentation_threshold);
265 DEBUGFS_DEL(short_retry_limit); 257 DEBUGFS_DEL(short_retry_limit);
diff --git a/net/mac80211/debugfs_key.c b/net/mac80211/debugfs_key.c
index a3294d109322..6424ac565ae0 100644
--- a/net/mac80211/debugfs_key.c
+++ b/net/mac80211/debugfs_key.c
@@ -188,7 +188,6 @@ void ieee80211_debugfs_key_add(struct ieee80211_key *key)
188 { 188 {
189 static int keycount; 189 static int keycount;
190 char buf[50]; 190 char buf[50];
191 DECLARE_MAC_BUF(mac);
192 struct sta_info *sta; 191 struct sta_info *sta;
193 192
194 if (!key->local->debugfs.keys) 193 if (!key->local->debugfs.keys)
@@ -206,8 +205,7 @@ void ieee80211_debugfs_key_add(struct ieee80211_key *key)
206 rcu_read_lock(); 205 rcu_read_lock();
207 sta = rcu_dereference(key->sta); 206 sta = rcu_dereference(key->sta);
208 if (sta) 207 if (sta)
209 sprintf(buf, "../../stations/%s", 208 sprintf(buf, "../../stations/%pM", sta->sta.addr);
210 print_mac(mac, sta->sta.addr));
211 rcu_read_unlock(); 209 rcu_read_unlock();
212 210
213 /* using sta as a boolean is fine outside RCU lock */ 211 /* using sta as a boolean is fine outside RCU lock */
diff --git a/net/mac80211/debugfs_netdev.c b/net/mac80211/debugfs_netdev.c
index 2ad504fc3414..c54219301724 100644
--- a/net/mac80211/debugfs_netdev.c
+++ b/net/mac80211/debugfs_netdev.c
@@ -41,29 +41,6 @@ static ssize_t ieee80211_if_read(
41 return ret; 41 return ret;
42} 42}
43 43
44#ifdef CONFIG_MAC80211_MESH
45static ssize_t ieee80211_if_write(
46 struct ieee80211_sub_if_data *sdata,
47 char const __user *userbuf,
48 size_t count, loff_t *ppos,
49 int (*format)(struct ieee80211_sub_if_data *, char *))
50{
51 char buf[10];
52 int buf_size;
53
54 memset(buf, 0x00, sizeof(buf));
55 buf_size = min(count, (sizeof(buf)-1));
56 if (copy_from_user(buf, userbuf, buf_size))
57 return count;
58 read_lock(&dev_base_lock);
59 if (sdata->dev->reg_state == NETREG_REGISTERED)
60 (*format)(sdata, buf);
61 read_unlock(&dev_base_lock);
62
63 return count;
64}
65#endif
66
67#define IEEE80211_IF_FMT(name, field, format_string) \ 44#define IEEE80211_IF_FMT(name, field, format_string) \
68static ssize_t ieee80211_if_fmt_##name( \ 45static ssize_t ieee80211_if_fmt_##name( \
69 const struct ieee80211_sub_if_data *sdata, char *buf, \ 46 const struct ieee80211_sub_if_data *sdata, char *buf, \
@@ -71,19 +48,6 @@ static ssize_t ieee80211_if_fmt_##name( \
71{ \ 48{ \
72 return scnprintf(buf, buflen, format_string, sdata->field); \ 49 return scnprintf(buf, buflen, format_string, sdata->field); \
73} 50}
74#define IEEE80211_IF_WFMT(name, field, type) \
75static int ieee80211_if_wfmt_##name( \
76 struct ieee80211_sub_if_data *sdata, char *buf) \
77{ \
78 unsigned long tmp; \
79 char *endp; \
80 \
81 tmp = simple_strtoul(buf, &endp, 0); \
82 if ((endp == buf) || ((type)tmp != tmp)) \
83 return -EINVAL; \
84 sdata->field = tmp; \
85 return 0; \
86}
87#define IEEE80211_IF_FMT_DEC(name, field) \ 51#define IEEE80211_IF_FMT_DEC(name, field) \
88 IEEE80211_IF_FMT(name, field, "%d\n") 52 IEEE80211_IF_FMT(name, field, "%d\n")
89#define IEEE80211_IF_FMT_HEX(name, field) \ 53#define IEEE80211_IF_FMT_HEX(name, field) \
@@ -104,8 +68,7 @@ static ssize_t ieee80211_if_fmt_##name( \
104 const struct ieee80211_sub_if_data *sdata, char *buf, \ 68 const struct ieee80211_sub_if_data *sdata, char *buf, \
105 int buflen) \ 69 int buflen) \
106{ \ 70{ \
107 DECLARE_MAC_BUF(mac); \ 71 return scnprintf(buf, buflen, "%pM\n", sdata->field); \
108 return scnprintf(buf, buflen, "%s\n", print_mac(mac, sdata->field));\
109} 72}
110 73
111#define __IEEE80211_IF_FILE(name) \ 74#define __IEEE80211_IF_FILE(name) \
@@ -126,34 +89,6 @@ static const struct file_operations name##_ops = { \
126 IEEE80211_IF_FMT_##format(name, field) \ 89 IEEE80211_IF_FMT_##format(name, field) \
127 __IEEE80211_IF_FILE(name) 90 __IEEE80211_IF_FILE(name)
128 91
129#define __IEEE80211_IF_WFILE(name) \
130static ssize_t ieee80211_if_read_##name(struct file *file, \
131 char __user *userbuf, \
132 size_t count, loff_t *ppos) \
133{ \
134 return ieee80211_if_read(file->private_data, \
135 userbuf, count, ppos, \
136 ieee80211_if_fmt_##name); \
137} \
138static ssize_t ieee80211_if_write_##name(struct file *file, \
139 const char __user *userbuf, \
140 size_t count, loff_t *ppos) \
141{ \
142 return ieee80211_if_write(file->private_data, \
143 userbuf, count, ppos, \
144 ieee80211_if_wfmt_##name); \
145} \
146static const struct file_operations name##_ops = { \
147 .read = ieee80211_if_read_##name, \
148 .write = ieee80211_if_write_##name, \
149 .open = mac80211_open_file_generic, \
150}
151
152#define IEEE80211_IF_WFILE(name, field, format, type) \
153 IEEE80211_IF_FMT_##format(name, field) \
154 IEEE80211_IF_WFMT(name, field, type) \
155 __IEEE80211_IF_WFILE(name)
156
157/* common attributes */ 92/* common attributes */
158IEEE80211_IF_FILE(drop_unencrypted, drop_unencrypted, DEC); 93IEEE80211_IF_FILE(drop_unencrypted, drop_unencrypted, DEC);
159IEEE80211_IF_FILE(force_unicast_rateidx, force_unicast_rateidx, DEC); 94IEEE80211_IF_FILE(force_unicast_rateidx, force_unicast_rateidx, DEC);
@@ -184,7 +119,7 @@ static ssize_t ieee80211_if_fmt_flags(
184 sdata->u.sta.flags & IEEE80211_STA_AUTHENTICATED ? "AUTH\n" : "", 119 sdata->u.sta.flags & IEEE80211_STA_AUTHENTICATED ? "AUTH\n" : "",
185 sdata->u.sta.flags & IEEE80211_STA_ASSOCIATED ? "ASSOC\n" : "", 120 sdata->u.sta.flags & IEEE80211_STA_ASSOCIATED ? "ASSOC\n" : "",
186 sdata->u.sta.flags & IEEE80211_STA_PROBEREQ_POLL ? "PROBEREQ POLL\n" : "", 121 sdata->u.sta.flags & IEEE80211_STA_PROBEREQ_POLL ? "PROBEREQ POLL\n" : "",
187 sdata->bss_conf.use_cts_prot ? "CTS prot\n" : ""); 122 sdata->vif.bss_conf.use_cts_prot ? "CTS prot\n" : "");
188} 123}
189__IEEE80211_IF_FILE(flags); 124__IEEE80211_IF_FILE(flags);
190 125
@@ -212,30 +147,30 @@ IEEE80211_IF_FILE(dropped_frames_no_route,
212IEEE80211_IF_FILE(estab_plinks, u.mesh.mshstats.estab_plinks, ATOMIC); 147IEEE80211_IF_FILE(estab_plinks, u.mesh.mshstats.estab_plinks, ATOMIC);
213 148
214/* Mesh parameters */ 149/* Mesh parameters */
215IEEE80211_IF_WFILE(dot11MeshMaxRetries, 150IEEE80211_IF_FILE(dot11MeshMaxRetries,
216 u.mesh.mshcfg.dot11MeshMaxRetries, DEC, u8); 151 u.mesh.mshcfg.dot11MeshMaxRetries, DEC);
217IEEE80211_IF_WFILE(dot11MeshRetryTimeout, 152IEEE80211_IF_FILE(dot11MeshRetryTimeout,
218 u.mesh.mshcfg.dot11MeshRetryTimeout, DEC, u16); 153 u.mesh.mshcfg.dot11MeshRetryTimeout, DEC);
219IEEE80211_IF_WFILE(dot11MeshConfirmTimeout, 154IEEE80211_IF_FILE(dot11MeshConfirmTimeout,
220 u.mesh.mshcfg.dot11MeshConfirmTimeout, DEC, u16); 155 u.mesh.mshcfg.dot11MeshConfirmTimeout, DEC);
221IEEE80211_IF_WFILE(dot11MeshHoldingTimeout, 156IEEE80211_IF_FILE(dot11MeshHoldingTimeout,
222 u.mesh.mshcfg.dot11MeshHoldingTimeout, DEC, u16); 157 u.mesh.mshcfg.dot11MeshHoldingTimeout, DEC);
223IEEE80211_IF_WFILE(dot11MeshTTL, u.mesh.mshcfg.dot11MeshTTL, DEC, u8); 158IEEE80211_IF_FILE(dot11MeshTTL, u.mesh.mshcfg.dot11MeshTTL, DEC);
224IEEE80211_IF_WFILE(auto_open_plinks, u.mesh.mshcfg.auto_open_plinks, DEC, u8); 159IEEE80211_IF_FILE(auto_open_plinks, u.mesh.mshcfg.auto_open_plinks, DEC);
225IEEE80211_IF_WFILE(dot11MeshMaxPeerLinks, 160IEEE80211_IF_FILE(dot11MeshMaxPeerLinks,
226 u.mesh.mshcfg.dot11MeshMaxPeerLinks, DEC, u16); 161 u.mesh.mshcfg.dot11MeshMaxPeerLinks, DEC);
227IEEE80211_IF_WFILE(dot11MeshHWMPactivePathTimeout, 162IEEE80211_IF_FILE(dot11MeshHWMPactivePathTimeout,
228 u.mesh.mshcfg.dot11MeshHWMPactivePathTimeout, DEC, u32); 163 u.mesh.mshcfg.dot11MeshHWMPactivePathTimeout, DEC);
229IEEE80211_IF_WFILE(dot11MeshHWMPpreqMinInterval, 164IEEE80211_IF_FILE(dot11MeshHWMPpreqMinInterval,
230 u.mesh.mshcfg.dot11MeshHWMPpreqMinInterval, DEC, u16); 165 u.mesh.mshcfg.dot11MeshHWMPpreqMinInterval, DEC);
231IEEE80211_IF_WFILE(dot11MeshHWMPnetDiameterTraversalTime, 166IEEE80211_IF_FILE(dot11MeshHWMPnetDiameterTraversalTime,
232 u.mesh.mshcfg.dot11MeshHWMPnetDiameterTraversalTime, DEC, u16); 167 u.mesh.mshcfg.dot11MeshHWMPnetDiameterTraversalTime, DEC);
233IEEE80211_IF_WFILE(dot11MeshHWMPmaxPREQretries, 168IEEE80211_IF_FILE(dot11MeshHWMPmaxPREQretries,
234 u.mesh.mshcfg.dot11MeshHWMPmaxPREQretries, DEC, u8); 169 u.mesh.mshcfg.dot11MeshHWMPmaxPREQretries, DEC);
235IEEE80211_IF_WFILE(path_refresh_time, 170IEEE80211_IF_FILE(path_refresh_time,
236 u.mesh.mshcfg.path_refresh_time, DEC, u32); 171 u.mesh.mshcfg.path_refresh_time, DEC);
237IEEE80211_IF_WFILE(min_discovery_timeout, 172IEEE80211_IF_FILE(min_discovery_timeout,
238 u.mesh.mshcfg.min_discovery_timeout, DEC, u16); 173 u.mesh.mshcfg.min_discovery_timeout, DEC);
239#endif 174#endif
240 175
241 176
diff --git a/net/mac80211/debugfs_sta.c b/net/mac80211/debugfs_sta.c
index b85c4f27b361..a2fbe0131312 100644
--- a/net/mac80211/debugfs_sta.c
+++ b/net/mac80211/debugfs_sta.c
@@ -39,13 +39,6 @@ static const struct file_operations sta_ ##name## _ops = { \
39 .open = mac80211_open_file_generic, \ 39 .open = mac80211_open_file_generic, \
40} 40}
41 41
42#define STA_OPS_WR(name) \
43static const struct file_operations sta_ ##name## _ops = { \
44 .read = sta_##name##_read, \
45 .write = sta_##name##_write, \
46 .open = mac80211_open_file_generic, \
47}
48
49#define STA_FILE(name, field, format) \ 42#define STA_FILE(name, field, format) \
50 STA_READ_##format(name, field) \ 43 STA_READ_##format(name, field) \
51 STA_OPS(name) 44 STA_OPS(name)
@@ -144,7 +137,7 @@ static ssize_t sta_agg_status_read(struct file *file, char __user *userbuf,
144 p += scnprintf(p, sizeof(buf)+buf-p, "\n DTKN:"); 137 p += scnprintf(p, sizeof(buf)+buf-p, "\n DTKN:");
145 for (i = 0; i < STA_TID_NUM; i++) 138 for (i = 0; i < STA_TID_NUM; i++)
146 p += scnprintf(p, sizeof(buf)+buf-p, "%5d", 139 p += scnprintf(p, sizeof(buf)+buf-p, "%5d",
147 sta->ampdu_mlme.tid_state_rx[i]? 140 sta->ampdu_mlme.tid_state_rx[i] ?
148 sta->ampdu_mlme.tid_rx[i]->dialog_token : 0); 141 sta->ampdu_mlme.tid_rx[i]->dialog_token : 0);
149 142
150 p += scnprintf(p, sizeof(buf)+buf-p, "\n TX :"); 143 p += scnprintf(p, sizeof(buf)+buf-p, "\n TX :");
@@ -155,84 +148,20 @@ static ssize_t sta_agg_status_read(struct file *file, char __user *userbuf,
155 p += scnprintf(p, sizeof(buf)+buf-p, "\n DTKN:"); 148 p += scnprintf(p, sizeof(buf)+buf-p, "\n DTKN:");
156 for (i = 0; i < STA_TID_NUM; i++) 149 for (i = 0; i < STA_TID_NUM; i++)
157 p += scnprintf(p, sizeof(buf)+buf-p, "%5d", 150 p += scnprintf(p, sizeof(buf)+buf-p, "%5d",
158 sta->ampdu_mlme.tid_state_tx[i]? 151 sta->ampdu_mlme.tid_state_tx[i] ?
159 sta->ampdu_mlme.tid_tx[i]->dialog_token : 0); 152 sta->ampdu_mlme.tid_tx[i]->dialog_token : 0);
160 153
161 p += scnprintf(p, sizeof(buf)+buf-p, "\n SSN :"); 154 p += scnprintf(p, sizeof(buf)+buf-p, "\n SSN :");
162 for (i = 0; i < STA_TID_NUM; i++) 155 for (i = 0; i < STA_TID_NUM; i++)
163 p += scnprintf(p, sizeof(buf)+buf-p, "%5d", 156 p += scnprintf(p, sizeof(buf)+buf-p, "%5d",
164 sta->ampdu_mlme.tid_state_tx[i]? 157 sta->ampdu_mlme.tid_state_tx[i] ?
165 sta->ampdu_mlme.tid_tx[i]->ssn : 0); 158 sta->ampdu_mlme.tid_tx[i]->ssn : 0);
166 159
167 p += scnprintf(p, sizeof(buf)+buf-p, "\n"); 160 p += scnprintf(p, sizeof(buf)+buf-p, "\n");
168 161
169 return simple_read_from_buffer(userbuf, count, ppos, buf, p - buf); 162 return simple_read_from_buffer(userbuf, count, ppos, buf, p - buf);
170} 163}
171 164STA_OPS(agg_status);
172static ssize_t sta_agg_status_write(struct file *file,
173 const char __user *user_buf, size_t count, loff_t *ppos)
174{
175 struct sta_info *sta = file->private_data;
176 struct ieee80211_local *local = sta->sdata->local;
177 struct ieee80211_hw *hw = &local->hw;
178 u8 *da = sta->sta.addr;
179 static int tid_static_tx[16] = {0, 0, 0, 0, 0, 0, 0, 0,
180 0, 0, 0, 0, 0, 0, 0, 0};
181 static int tid_static_rx[16] = {1, 1, 1, 1, 1, 1, 1, 1,
182 1, 1, 1, 1, 1, 1, 1, 1};
183 char *endp;
184 char buf[32];
185 int buf_size, rs;
186 unsigned int tid_num;
187 char state[4];
188
189 memset(buf, 0x00, sizeof(buf));
190 buf_size = min(count, (sizeof(buf)-1));
191 if (copy_from_user(buf, user_buf, buf_size))
192 return -EFAULT;
193
194 tid_num = simple_strtoul(buf, &endp, 0);
195 if (endp == buf)
196 return -EINVAL;
197
198 if ((tid_num >= 100) && (tid_num <= 115)) {
199 /* toggle Rx aggregation command */
200 tid_num = tid_num - 100;
201 if (tid_static_rx[tid_num] == 1) {
202 strcpy(state, "off");
203 ieee80211_sta_stop_rx_ba_session(sta->sdata, da, tid_num, 0,
204 WLAN_REASON_QSTA_REQUIRE_SETUP);
205 sta->ampdu_mlme.tid_state_rx[tid_num] |=
206 HT_AGG_STATE_DEBUGFS_CTL;
207 tid_static_rx[tid_num] = 0;
208 } else {
209 strcpy(state, "on ");
210 sta->ampdu_mlme.tid_state_rx[tid_num] &=
211 ~HT_AGG_STATE_DEBUGFS_CTL;
212 tid_static_rx[tid_num] = 1;
213 }
214 printk(KERN_DEBUG "debugfs - try switching tid %u %s\n",
215 tid_num, state);
216 } else if ((tid_num >= 0) && (tid_num <= 15)) {
217 /* toggle Tx aggregation command */
218 if (tid_static_tx[tid_num] == 0) {
219 strcpy(state, "on ");
220 rs = ieee80211_start_tx_ba_session(hw, da, tid_num);
221 if (rs == 0)
222 tid_static_tx[tid_num] = 1;
223 } else {
224 strcpy(state, "off");
225 rs = ieee80211_stop_tx_ba_session(hw, da, tid_num, 1);
226 if (rs == 0)
227 tid_static_tx[tid_num] = 0;
228 }
229 printk(KERN_DEBUG "debugfs - switching tid %u %s, return=%d\n",
230 tid_num, state, rs);
231 }
232
233 return count;
234}
235STA_OPS_WR(agg_status);
236 165
237#define DEBUGFS_ADD(name) \ 166#define DEBUGFS_ADD(name) \
238 sta->debugfs.name = debugfs_create_file(#name, 0400, \ 167 sta->debugfs.name = debugfs_create_file(#name, 0400, \
@@ -246,15 +175,14 @@ STA_OPS_WR(agg_status);
246void ieee80211_sta_debugfs_add(struct sta_info *sta) 175void ieee80211_sta_debugfs_add(struct sta_info *sta)
247{ 176{
248 struct dentry *stations_dir = sta->local->debugfs.stations; 177 struct dentry *stations_dir = sta->local->debugfs.stations;
249 DECLARE_MAC_BUF(mbuf); 178 u8 mac[3*ETH_ALEN];
250 u8 *mac;
251 179
252 sta->debugfs.add_has_run = true; 180 sta->debugfs.add_has_run = true;
253 181
254 if (!stations_dir) 182 if (!stations_dir)
255 return; 183 return;
256 184
257 mac = print_mac(mbuf, sta->sta.addr); 185 snprintf(mac, sizeof(mac), "%pM", sta->sta.addr);
258 186
259 /* 187 /*
260 * This might fail due to a race condition: 188 * This might fail due to a race condition:
diff --git a/net/mac80211/event.c b/net/mac80211/event.c
index 8de60de70bc9..0d95561c0ee0 100644
--- a/net/mac80211/event.c
+++ b/net/mac80211/event.c
@@ -21,14 +21,13 @@ void mac80211_ev_michael_mic_failure(struct ieee80211_sub_if_data *sdata, int ke
21{ 21{
22 union iwreq_data wrqu; 22 union iwreq_data wrqu;
23 char *buf = kmalloc(128, GFP_ATOMIC); 23 char *buf = kmalloc(128, GFP_ATOMIC);
24 DECLARE_MAC_BUF(mac);
25 24
26 if (buf) { 25 if (buf) {
27 /* TODO: needed parameters: count, key type, TSC */ 26 /* TODO: needed parameters: count, key type, TSC */
28 sprintf(buf, "MLME-MICHAELMICFAILURE.indication(" 27 sprintf(buf, "MLME-MICHAELMICFAILURE.indication("
29 "keyid=%d %scast addr=%s)", 28 "keyid=%d %scast addr=%pM)",
30 keyidx, hdr->addr1[0] & 0x01 ? "broad" : "uni", 29 keyidx, hdr->addr1[0] & 0x01 ? "broad" : "uni",
31 print_mac(mac, hdr->addr2)); 30 hdr->addr2);
32 memset(&wrqu, 0, sizeof(wrqu)); 31 memset(&wrqu, 0, sizeof(wrqu));
33 wrqu.data.length = strlen(buf); 32 wrqu.data.length = strlen(buf);
34 wireless_send_event(sdata->dev, IWEVCUSTOM, &wrqu, buf); 33 wireless_send_event(sdata->dev, IWEVCUSTOM, &wrqu, buf);
diff --git a/net/mac80211/ht.c b/net/mac80211/ht.c
index dc7d9a3d70d5..5f510a13b9f0 100644
--- a/net/mac80211/ht.c
+++ b/net/mac80211/ht.c
@@ -20,50 +20,138 @@
20#include "sta_info.h" 20#include "sta_info.h"
21#include "wme.h" 21#include "wme.h"
22 22
23int ieee80211_ht_cap_ie_to_ht_info(struct ieee80211_ht_cap *ht_cap_ie, 23void ieee80211_ht_cap_ie_to_sta_ht_cap(struct ieee80211_supported_band *sband,
24 struct ieee80211_ht_info *ht_info) 24 struct ieee80211_ht_cap *ht_cap_ie,
25 struct ieee80211_sta_ht_cap *ht_cap)
25{ 26{
27 u8 ampdu_info, tx_mcs_set_cap;
28 int i, max_tx_streams;
26 29
27 if (ht_info == NULL) 30 BUG_ON(!ht_cap);
28 return -EINVAL; 31
32 memset(ht_cap, 0, sizeof(*ht_cap));
33
34 if (!ht_cap_ie)
35 return;
36
37 ht_cap->ht_supported = true;
29 38
30 memset(ht_info, 0, sizeof(*ht_info)); 39 ht_cap->cap = le16_to_cpu(ht_cap_ie->cap_info) & sband->ht_cap.cap;
40 ht_cap->cap &= ~IEEE80211_HT_CAP_SM_PS;
41 ht_cap->cap |= sband->ht_cap.cap & IEEE80211_HT_CAP_SM_PS;
31 42
32 if (ht_cap_ie) { 43 ampdu_info = ht_cap_ie->ampdu_params_info;
33 u8 ampdu_info = ht_cap_ie->ampdu_params_info; 44 ht_cap->ampdu_factor =
45 ampdu_info & IEEE80211_HT_AMPDU_PARM_FACTOR;
46 ht_cap->ampdu_density =
47 (ampdu_info & IEEE80211_HT_AMPDU_PARM_DENSITY) >> 2;
34 48
35 ht_info->ht_supported = 1; 49 /* own MCS TX capabilities */
36 ht_info->cap = le16_to_cpu(ht_cap_ie->cap_info); 50 tx_mcs_set_cap = sband->ht_cap.mcs.tx_params;
37 ht_info->ampdu_factor =
38 ampdu_info & IEEE80211_HT_CAP_AMPDU_FACTOR;
39 ht_info->ampdu_density =
40 (ampdu_info & IEEE80211_HT_CAP_AMPDU_DENSITY) >> 2;
41 memcpy(ht_info->supp_mcs_set, ht_cap_ie->supp_mcs_set, 16);
42 } else
43 ht_info->ht_supported = 0;
44 51
45 return 0; 52 /* can we TX with MCS rates? */
53 if (!(tx_mcs_set_cap & IEEE80211_HT_MCS_TX_DEFINED))
54 return;
55
56 /* Counting from 0, therefore +1 */
57 if (tx_mcs_set_cap & IEEE80211_HT_MCS_TX_RX_DIFF)
58 max_tx_streams =
59 ((tx_mcs_set_cap & IEEE80211_HT_MCS_TX_MAX_STREAMS_MASK)
60 >> IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT) + 1;
61 else
62 max_tx_streams = IEEE80211_HT_MCS_TX_MAX_STREAMS;
63
64 /*
65 * 802.11n D5.0 20.3.5 / 20.6 says:
66 * - indices 0 to 7 and 32 are single spatial stream
67 * - 8 to 31 are multiple spatial streams using equal modulation
68 * [8..15 for two streams, 16..23 for three and 24..31 for four]
69 * - remainder are multiple spatial streams using unequal modulation
70 */
71 for (i = 0; i < max_tx_streams; i++)
72 ht_cap->mcs.rx_mask[i] =
73 sband->ht_cap.mcs.rx_mask[i] & ht_cap_ie->mcs.rx_mask[i];
74
75 if (tx_mcs_set_cap & IEEE80211_HT_MCS_TX_UNEQUAL_MODULATION)
76 for (i = IEEE80211_HT_MCS_UNEQUAL_MODULATION_START_BYTE;
77 i < IEEE80211_HT_MCS_MASK_LEN; i++)
78 ht_cap->mcs.rx_mask[i] =
79 sband->ht_cap.mcs.rx_mask[i] &
80 ht_cap_ie->mcs.rx_mask[i];
81
82 /* handle MCS rate 32 too */
83 if (sband->ht_cap.mcs.rx_mask[32/8] & ht_cap_ie->mcs.rx_mask[32/8] & 1)
84 ht_cap->mcs.rx_mask[32/8] |= 1;
46} 85}
47 86
48int ieee80211_ht_addt_info_ie_to_ht_bss_info( 87/*
49 struct ieee80211_ht_addt_info *ht_add_info_ie, 88 * ieee80211_enable_ht should be called only after the operating band
50 struct ieee80211_ht_bss_info *bss_info) 89 * has been determined as ht configuration depends on the hw's
90 * HT abilities for a specific band.
91 */
92u32 ieee80211_enable_ht(struct ieee80211_sub_if_data *sdata,
93 struct ieee80211_ht_info *hti,
94 u16 ap_ht_cap_flags)
51{ 95{
52 if (bss_info == NULL) 96 struct ieee80211_local *local = sdata->local;
53 return -EINVAL; 97 struct ieee80211_supported_band *sband;
98 struct ieee80211_bss_ht_conf ht;
99 u32 changed = 0;
100 bool enable_ht = true, ht_changed;
101 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
102
103 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
104
105 memset(&ht, 0, sizeof(ht));
106
107 /* HT is not supported */
108 if (!sband->ht_cap.ht_supported)
109 enable_ht = false;
110
111 /* check that channel matches the right operating channel */
112 if (local->hw.conf.channel->center_freq !=
113 ieee80211_channel_to_frequency(hti->control_chan))
114 enable_ht = false;
115
116 if (enable_ht) {
117 channel_type = NL80211_CHAN_HT20;
118
119 if (!(ap_ht_cap_flags & IEEE80211_HT_CAP_40MHZ_INTOLERANT) &&
120 (sband->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) &&
121 (hti->ht_param & IEEE80211_HT_PARAM_CHAN_WIDTH_ANY)) {
122 switch(hti->ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) {
123 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
124 channel_type = NL80211_CHAN_HT40PLUS;
125 break;
126 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
127 channel_type = NL80211_CHAN_HT40MINUS;
128 break;
129 }
130 }
131 }
132
133 ht_changed = local->hw.conf.ht.enabled != enable_ht ||
134 channel_type != local->hw.conf.ht.channel_type;
135
136 local->oper_channel_type = channel_type;
137 local->hw.conf.ht.enabled = enable_ht;
54 138
55 memset(bss_info, 0, sizeof(*bss_info)); 139 if (ht_changed)
140 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_HT);
56 141
57 if (ht_add_info_ie) { 142 /* disable HT */
58 u16 op_mode; 143 if (!enable_ht)
59 op_mode = le16_to_cpu(ht_add_info_ie->operation_mode); 144 return 0;
60 145
61 bss_info->primary_channel = ht_add_info_ie->control_chan; 146 ht.operation_mode = le16_to_cpu(hti->operation_mode);
62 bss_info->bss_cap = ht_add_info_ie->ht_param; 147
63 bss_info->bss_op_mode = (u8)(op_mode & 0xff); 148 /* if bss configuration changed store the new one */
149 if (memcmp(&sdata->vif.bss_conf.ht, &ht, sizeof(ht))) {
150 changed |= BSS_CHANGED_HT;
151 sdata->vif.bss_conf.ht = ht;
64 } 152 }
65 153
66 return 0; 154 return changed;
67} 155}
68 156
69static void ieee80211_send_addba_request(struct ieee80211_sub_if_data *sdata, 157static void ieee80211_send_addba_request(struct ieee80211_sub_if_data *sdata,
@@ -241,7 +329,6 @@ void ieee80211_sta_stop_rx_ba_session(struct ieee80211_sub_if_data *sdata, u8 *r
241 struct ieee80211_hw *hw = &local->hw; 329 struct ieee80211_hw *hw = &local->hw;
242 struct sta_info *sta; 330 struct sta_info *sta;
243 int ret, i; 331 int ret, i;
244 DECLARE_MAC_BUF(mac);
245 332
246 rcu_read_lock(); 333 rcu_read_lock();
247 334
@@ -269,8 +356,8 @@ void ieee80211_sta_stop_rx_ba_session(struct ieee80211_sub_if_data *sdata, u8 *r
269 BUG_ON(!local->ops->ampdu_action); 356 BUG_ON(!local->ops->ampdu_action);
270 357
271#ifdef CONFIG_MAC80211_HT_DEBUG 358#ifdef CONFIG_MAC80211_HT_DEBUG
272 printk(KERN_DEBUG "Rx BA session stop requested for %s tid %u\n", 359 printk(KERN_DEBUG "Rx BA session stop requested for %pM tid %u\n",
273 print_mac(mac, ra), tid); 360 ra, tid);
274#endif /* CONFIG_MAC80211_HT_DEBUG */ 361#endif /* CONFIG_MAC80211_HT_DEBUG */
275 362
276 ret = local->ops->ampdu_action(hw, IEEE80211_AMPDU_RX_STOP, 363 ret = local->ops->ampdu_action(hw, IEEE80211_AMPDU_RX_STOP,
@@ -383,14 +470,13 @@ int ieee80211_start_tx_ba_session(struct ieee80211_hw *hw, u8 *ra, u16 tid)
383 u16 start_seq_num; 470 u16 start_seq_num;
384 u8 *state; 471 u8 *state;
385 int ret; 472 int ret;
386 DECLARE_MAC_BUF(mac);
387 473
388 if (tid >= STA_TID_NUM) 474 if ((tid >= STA_TID_NUM) || !(hw->flags & IEEE80211_HW_AMPDU_AGGREGATION))
389 return -EINVAL; 475 return -EINVAL;
390 476
391#ifdef CONFIG_MAC80211_HT_DEBUG 477#ifdef CONFIG_MAC80211_HT_DEBUG
392 printk(KERN_DEBUG "Open BA session requested for %s tid %u\n", 478 printk(KERN_DEBUG "Open BA session requested for %pM tid %u\n",
393 print_mac(mac, ra), tid); 479 ra, tid);
394#endif /* CONFIG_MAC80211_HT_DEBUG */ 480#endif /* CONFIG_MAC80211_HT_DEBUG */
395 481
396 rcu_read_lock(); 482 rcu_read_lock();
@@ -442,17 +528,19 @@ int ieee80211_start_tx_ba_session(struct ieee80211_hw *hw, u8 *ra, u16 tid)
442 (unsigned long)&sta->timer_to_tid[tid]; 528 (unsigned long)&sta->timer_to_tid[tid];
443 init_timer(&sta->ampdu_mlme.tid_tx[tid]->addba_resp_timer); 529 init_timer(&sta->ampdu_mlme.tid_tx[tid]->addba_resp_timer);
444 530
445 /* create a new queue for this aggregation */ 531 if (hw->ampdu_queues) {
446 ret = ieee80211_ht_agg_queue_add(local, sta, tid); 532 /* create a new queue for this aggregation */
533 ret = ieee80211_ht_agg_queue_add(local, sta, tid);
447 534
448 /* case no queue is available to aggregation 535 /* case no queue is available to aggregation
449 * don't switch to aggregation */ 536 * don't switch to aggregation */
450 if (ret) { 537 if (ret) {
451#ifdef CONFIG_MAC80211_HT_DEBUG 538#ifdef CONFIG_MAC80211_HT_DEBUG
452 printk(KERN_DEBUG "BA request denied - queue unavailable for" 539 printk(KERN_DEBUG "BA request denied - "
453 " tid %d\n", tid); 540 "queue unavailable for tid %d\n", tid);
454#endif /* CONFIG_MAC80211_HT_DEBUG */ 541#endif /* CONFIG_MAC80211_HT_DEBUG */
455 goto err_unlock_queue; 542 goto err_unlock_queue;
543 }
456 } 544 }
457 sdata = sta->sdata; 545 sdata = sta->sdata;
458 546
@@ -471,7 +559,8 @@ int ieee80211_start_tx_ba_session(struct ieee80211_hw *hw, u8 *ra, u16 tid)
471 /* No need to requeue the packets in the agg queue, since we 559 /* No need to requeue the packets in the agg queue, since we
472 * held the tx lock: no packet could be enqueued to the newly 560 * held the tx lock: no packet could be enqueued to the newly
473 * allocated queue */ 561 * allocated queue */
474 ieee80211_ht_agg_queue_remove(local, sta, tid, 0); 562 if (hw->ampdu_queues)
563 ieee80211_ht_agg_queue_remove(local, sta, tid, 0);
475#ifdef CONFIG_MAC80211_HT_DEBUG 564#ifdef CONFIG_MAC80211_HT_DEBUG
476 printk(KERN_DEBUG "BA request denied - HW unavailable for" 565 printk(KERN_DEBUG "BA request denied - HW unavailable for"
477 " tid %d\n", tid); 566 " tid %d\n", tid);
@@ -481,7 +570,8 @@ int ieee80211_start_tx_ba_session(struct ieee80211_hw *hw, u8 *ra, u16 tid)
481 } 570 }
482 571
483 /* Will put all the packets in the new SW queue */ 572 /* Will put all the packets in the new SW queue */
484 ieee80211_requeue(local, ieee802_1d_to_ac[tid]); 573 if (hw->ampdu_queues)
574 ieee80211_requeue(local, ieee802_1d_to_ac[tid]);
485 spin_unlock_bh(&sta->lock); 575 spin_unlock_bh(&sta->lock);
486 576
487 /* send an addBA request */ 577 /* send an addBA request */
@@ -524,7 +614,6 @@ int ieee80211_stop_tx_ba_session(struct ieee80211_hw *hw,
524 struct sta_info *sta; 614 struct sta_info *sta;
525 u8 *state; 615 u8 *state;
526 int ret = 0; 616 int ret = 0;
527 DECLARE_MAC_BUF(mac);
528 617
529 if (tid >= STA_TID_NUM) 618 if (tid >= STA_TID_NUM)
530 return -EINVAL; 619 return -EINVAL;
@@ -546,11 +635,12 @@ int ieee80211_stop_tx_ba_session(struct ieee80211_hw *hw,
546 } 635 }
547 636
548#ifdef CONFIG_MAC80211_HT_DEBUG 637#ifdef CONFIG_MAC80211_HT_DEBUG
549 printk(KERN_DEBUG "Tx BA session stop requested for %s tid %u\n", 638 printk(KERN_DEBUG "Tx BA session stop requested for %pM tid %u\n",
550 print_mac(mac, ra), tid); 639 ra, tid);
551#endif /* CONFIG_MAC80211_HT_DEBUG */ 640#endif /* CONFIG_MAC80211_HT_DEBUG */
552 641
553 ieee80211_stop_queue(hw, sta->tid_to_tx_q[tid]); 642 if (hw->ampdu_queues)
643 ieee80211_stop_queue(hw, sta->tid_to_tx_q[tid]);
554 644
555 *state = HT_AGG_STATE_REQ_STOP_BA_MSK | 645 *state = HT_AGG_STATE_REQ_STOP_BA_MSK |
556 (initiator << HT_AGG_STATE_INITIATOR_SHIFT); 646 (initiator << HT_AGG_STATE_INITIATOR_SHIFT);
@@ -563,7 +653,8 @@ int ieee80211_stop_tx_ba_session(struct ieee80211_hw *hw,
563 if (ret) { 653 if (ret) {
564 WARN_ON(ret != -EBUSY); 654 WARN_ON(ret != -EBUSY);
565 *state = HT_AGG_STATE_OPERATIONAL; 655 *state = HT_AGG_STATE_OPERATIONAL;
566 ieee80211_wake_queue(hw, sta->tid_to_tx_q[tid]); 656 if (hw->ampdu_queues)
657 ieee80211_wake_queue(hw, sta->tid_to_tx_q[tid]);
567 goto stop_BA_exit; 658 goto stop_BA_exit;
568 } 659 }
569 660
@@ -579,7 +670,6 @@ void ieee80211_start_tx_ba_cb(struct ieee80211_hw *hw, u8 *ra, u16 tid)
579 struct ieee80211_local *local = hw_to_local(hw); 670 struct ieee80211_local *local = hw_to_local(hw);
580 struct sta_info *sta; 671 struct sta_info *sta;
581 u8 *state; 672 u8 *state;
582 DECLARE_MAC_BUF(mac);
583 673
584 if (tid >= STA_TID_NUM) { 674 if (tid >= STA_TID_NUM) {
585#ifdef CONFIG_MAC80211_HT_DEBUG 675#ifdef CONFIG_MAC80211_HT_DEBUG
@@ -594,8 +684,7 @@ void ieee80211_start_tx_ba_cb(struct ieee80211_hw *hw, u8 *ra, u16 tid)
594 if (!sta) { 684 if (!sta) {
595 rcu_read_unlock(); 685 rcu_read_unlock();
596#ifdef CONFIG_MAC80211_HT_DEBUG 686#ifdef CONFIG_MAC80211_HT_DEBUG
597 printk(KERN_DEBUG "Could not find station: %s\n", 687 printk(KERN_DEBUG "Could not find station: %pM\n", ra);
598 print_mac(mac, ra));
599#endif 688#endif
600 return; 689 return;
601 } 690 }
@@ -621,7 +710,8 @@ void ieee80211_start_tx_ba_cb(struct ieee80211_hw *hw, u8 *ra, u16 tid)
621#ifdef CONFIG_MAC80211_HT_DEBUG 710#ifdef CONFIG_MAC80211_HT_DEBUG
622 printk(KERN_DEBUG "Aggregation is on for tid %d \n", tid); 711 printk(KERN_DEBUG "Aggregation is on for tid %d \n", tid);
623#endif 712#endif
624 ieee80211_wake_queue(hw, sta->tid_to_tx_q[tid]); 713 if (hw->ampdu_queues)
714 ieee80211_wake_queue(hw, sta->tid_to_tx_q[tid]);
625 } 715 }
626 spin_unlock_bh(&sta->lock); 716 spin_unlock_bh(&sta->lock);
627 rcu_read_unlock(); 717 rcu_read_unlock();
@@ -634,7 +724,6 @@ void ieee80211_stop_tx_ba_cb(struct ieee80211_hw *hw, u8 *ra, u8 tid)
634 struct sta_info *sta; 724 struct sta_info *sta;
635 u8 *state; 725 u8 *state;
636 int agg_queue; 726 int agg_queue;
637 DECLARE_MAC_BUF(mac);
638 727
639 if (tid >= STA_TID_NUM) { 728 if (tid >= STA_TID_NUM) {
640#ifdef CONFIG_MAC80211_HT_DEBUG 729#ifdef CONFIG_MAC80211_HT_DEBUG
@@ -645,16 +734,15 @@ void ieee80211_stop_tx_ba_cb(struct ieee80211_hw *hw, u8 *ra, u8 tid)
645 } 734 }
646 735
647#ifdef CONFIG_MAC80211_HT_DEBUG 736#ifdef CONFIG_MAC80211_HT_DEBUG
648 printk(KERN_DEBUG "Stopping Tx BA session for %s tid %d\n", 737 printk(KERN_DEBUG "Stopping Tx BA session for %pM tid %d\n",
649 print_mac(mac, ra), tid); 738 ra, tid);
650#endif /* CONFIG_MAC80211_HT_DEBUG */ 739#endif /* CONFIG_MAC80211_HT_DEBUG */
651 740
652 rcu_read_lock(); 741 rcu_read_lock();
653 sta = sta_info_get(local, ra); 742 sta = sta_info_get(local, ra);
654 if (!sta) { 743 if (!sta) {
655#ifdef CONFIG_MAC80211_HT_DEBUG 744#ifdef CONFIG_MAC80211_HT_DEBUG
656 printk(KERN_DEBUG "Could not find station: %s\n", 745 printk(KERN_DEBUG "Could not find station: %pM\n", ra);
657 print_mac(mac, ra));
658#endif 746#endif
659 rcu_read_unlock(); 747 rcu_read_unlock();
660 return; 748 return;
@@ -677,16 +765,18 @@ void ieee80211_stop_tx_ba_cb(struct ieee80211_hw *hw, u8 *ra, u8 tid)
677 ieee80211_send_delba(sta->sdata, ra, tid, 765 ieee80211_send_delba(sta->sdata, ra, tid,
678 WLAN_BACK_INITIATOR, WLAN_REASON_QSTA_NOT_USE); 766 WLAN_BACK_INITIATOR, WLAN_REASON_QSTA_NOT_USE);
679 767
680 agg_queue = sta->tid_to_tx_q[tid]; 768 if (hw->ampdu_queues) {
681 769 agg_queue = sta->tid_to_tx_q[tid];
682 ieee80211_ht_agg_queue_remove(local, sta, tid, 1); 770 ieee80211_ht_agg_queue_remove(local, sta, tid, 1);
683 771
684 /* We just requeued the all the frames that were in the 772 /* We just requeued the all the frames that were in the
685 * removed queue, and since we might miss a softirq we do 773 * removed queue, and since we might miss a softirq we do
686 * netif_schedule_queue. ieee80211_wake_queue is not used 774 * netif_schedule_queue. ieee80211_wake_queue is not used
687 * here as this queue is not necessarily stopped 775 * here as this queue is not necessarily stopped
688 */ 776 */
689 netif_schedule_queue(netdev_get_tx_queue(local->mdev, agg_queue)); 777 netif_schedule_queue(netdev_get_tx_queue(local->mdev,
778 agg_queue));
779 }
690 spin_lock_bh(&sta->lock); 780 spin_lock_bh(&sta->lock);
691 *state = HT_AGG_STATE_IDLE; 781 *state = HT_AGG_STATE_IDLE;
692 sta->ampdu_mlme.addba_req_num[tid] = 0; 782 sta->ampdu_mlme.addba_req_num[tid] = 0;
@@ -783,7 +873,6 @@ void ieee80211_process_addba_request(struct ieee80211_local *local,
783 u16 capab, tid, timeout, ba_policy, buf_size, start_seq_num, status; 873 u16 capab, tid, timeout, ba_policy, buf_size, start_seq_num, status;
784 u8 dialog_token; 874 u8 dialog_token;
785 int ret = -EOPNOTSUPP; 875 int ret = -EOPNOTSUPP;
786 DECLARE_MAC_BUF(mac);
787 876
788 /* extract session parameters from addba request frame */ 877 /* extract session parameters from addba request frame */
789 dialog_token = mgmt->u.action.u.addba_req.dialog_token; 878 dialog_token = mgmt->u.action.u.addba_req.dialog_token;
@@ -801,15 +890,16 @@ void ieee80211_process_addba_request(struct ieee80211_local *local,
801 /* sanity check for incoming parameters: 890 /* sanity check for incoming parameters:
802 * check if configuration can support the BA policy 891 * check if configuration can support the BA policy
803 * and if buffer size does not exceeds max value */ 892 * and if buffer size does not exceeds max value */
893 /* XXX: check own ht delayed BA capability?? */
804 if (((ba_policy != 1) 894 if (((ba_policy != 1)
805 && (!(conf->ht_conf.cap & IEEE80211_HT_CAP_DELAY_BA))) 895 && (!(sta->sta.ht_cap.cap & IEEE80211_HT_CAP_DELAY_BA)))
806 || (buf_size > IEEE80211_MAX_AMPDU_BUF)) { 896 || (buf_size > IEEE80211_MAX_AMPDU_BUF)) {
807 status = WLAN_STATUS_INVALID_QOS_PARAM; 897 status = WLAN_STATUS_INVALID_QOS_PARAM;
808#ifdef CONFIG_MAC80211_HT_DEBUG 898#ifdef CONFIG_MAC80211_HT_DEBUG
809 if (net_ratelimit()) 899 if (net_ratelimit())
810 printk(KERN_DEBUG "AddBA Req with bad params from " 900 printk(KERN_DEBUG "AddBA Req with bad params from "
811 "%s on tid %u. policy %d, buffer size %d\n", 901 "%pM on tid %u. policy %d, buffer size %d\n",
812 print_mac(mac, mgmt->sa), tid, ba_policy, 902 mgmt->sa, tid, ba_policy,
813 buf_size); 903 buf_size);
814#endif /* CONFIG_MAC80211_HT_DEBUG */ 904#endif /* CONFIG_MAC80211_HT_DEBUG */
815 goto end_no_lock; 905 goto end_no_lock;
@@ -820,7 +910,7 @@ void ieee80211_process_addba_request(struct ieee80211_local *local,
820 910
821 sband = local->hw.wiphy->bands[conf->channel->band]; 911 sband = local->hw.wiphy->bands[conf->channel->band];
822 buf_size = IEEE80211_MIN_AMPDU_BUF; 912 buf_size = IEEE80211_MIN_AMPDU_BUF;
823 buf_size = buf_size << sband->ht_info.ampdu_factor; 913 buf_size = buf_size << sband->ht_cap.ampdu_factor;
824 } 914 }
825 915
826 916
@@ -831,8 +921,8 @@ void ieee80211_process_addba_request(struct ieee80211_local *local,
831#ifdef CONFIG_MAC80211_HT_DEBUG 921#ifdef CONFIG_MAC80211_HT_DEBUG
832 if (net_ratelimit()) 922 if (net_ratelimit())
833 printk(KERN_DEBUG "unexpected AddBA Req from " 923 printk(KERN_DEBUG "unexpected AddBA Req from "
834 "%s on tid %u\n", 924 "%pM on tid %u\n",
835 print_mac(mac, mgmt->sa), tid); 925 mgmt->sa, tid);
836#endif /* CONFIG_MAC80211_HT_DEBUG */ 926#endif /* CONFIG_MAC80211_HT_DEBUG */
837 goto end; 927 goto end;
838 } 928 }
@@ -910,7 +1000,7 @@ void ieee80211_process_addba_resp(struct ieee80211_local *local,
910{ 1000{
911 struct ieee80211_hw *hw = &local->hw; 1001 struct ieee80211_hw *hw = &local->hw;
912 u16 capab; 1002 u16 capab;
913 u16 tid; 1003 u16 tid, start_seq_num;
914 u8 *state; 1004 u8 *state;
915 1005
916 capab = le16_to_cpu(mgmt->u.action.u.addba_resp.capab); 1006 capab = le16_to_cpu(mgmt->u.action.u.addba_resp.capab);
@@ -943,9 +1033,18 @@ void ieee80211_process_addba_resp(struct ieee80211_local *local,
943 *state |= HT_ADDBA_RECEIVED_MSK; 1033 *state |= HT_ADDBA_RECEIVED_MSK;
944 sta->ampdu_mlme.addba_req_num[tid] = 0; 1034 sta->ampdu_mlme.addba_req_num[tid] = 0;
945 1035
946 if (*state == HT_AGG_STATE_OPERATIONAL) 1036 if (*state == HT_AGG_STATE_OPERATIONAL &&
1037 local->hw.ampdu_queues)
947 ieee80211_wake_queue(hw, sta->tid_to_tx_q[tid]); 1038 ieee80211_wake_queue(hw, sta->tid_to_tx_q[tid]);
948 1039
1040 if (local->ops->ampdu_action) {
1041 (void)local->ops->ampdu_action(hw,
1042 IEEE80211_AMPDU_TX_RESUME,
1043 &sta->sta, tid, &start_seq_num);
1044 }
1045#ifdef CONFIG_MAC80211_HT_DEBUG
1046 printk(KERN_DEBUG "Resuming TX aggregation for tid %d\n", tid);
1047#endif /* CONFIG_MAC80211_HT_DEBUG */
949 spin_unlock_bh(&sta->lock); 1048 spin_unlock_bh(&sta->lock);
950 } else { 1049 } else {
951 sta->ampdu_mlme.addba_req_num[tid]++; 1050 sta->ampdu_mlme.addba_req_num[tid]++;
@@ -964,7 +1063,6 @@ void ieee80211_process_delba(struct ieee80211_sub_if_data *sdata,
964 struct ieee80211_local *local = sdata->local; 1063 struct ieee80211_local *local = sdata->local;
965 u16 tid, params; 1064 u16 tid, params;
966 u16 initiator; 1065 u16 initiator;
967 DECLARE_MAC_BUF(mac);
968 1066
969 params = le16_to_cpu(mgmt->u.action.u.delba.params); 1067 params = le16_to_cpu(mgmt->u.action.u.delba.params);
970 tid = (params & IEEE80211_DELBA_PARAM_TID_MASK) >> 12; 1068 tid = (params & IEEE80211_DELBA_PARAM_TID_MASK) >> 12;
@@ -972,9 +1070,8 @@ void ieee80211_process_delba(struct ieee80211_sub_if_data *sdata,
972 1070
973#ifdef CONFIG_MAC80211_HT_DEBUG 1071#ifdef CONFIG_MAC80211_HT_DEBUG
974 if (net_ratelimit()) 1072 if (net_ratelimit())
975 printk(KERN_DEBUG "delba from %s (%s) tid %d reason code %d\n", 1073 printk(KERN_DEBUG "delba from %pM (%s) tid %d reason code %d\n",
976 print_mac(mac, mgmt->sa), 1074 mgmt->sa, initiator ? "initiator" : "recipient", tid,
977 initiator ? "initiator" : "recipient", tid,
978 mgmt->u.action.u.delba.reason_code); 1075 mgmt->u.action.u.delba.reason_code);
979#endif /* CONFIG_MAC80211_HT_DEBUG */ 1076#endif /* CONFIG_MAC80211_HT_DEBUG */
980 1077
diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
index 156e42a003ae..f3eec989662b 100644
--- a/net/mac80211/ieee80211_i.h
+++ b/net/mac80211/ieee80211_i.h
@@ -23,6 +23,7 @@
23#include <linux/types.h> 23#include <linux/types.h>
24#include <linux/spinlock.h> 24#include <linux/spinlock.h>
25#include <linux/etherdevice.h> 25#include <linux/etherdevice.h>
26#include <net/cfg80211.h>
26#include <net/wireless.h> 27#include <net/wireless.h>
27#include <net/iw_handler.h> 28#include <net/iw_handler.h>
28#include <net/mac80211.h> 29#include <net/mac80211.h>
@@ -142,7 +143,6 @@ typedef unsigned __bitwise__ ieee80211_tx_result;
142#define IEEE80211_TX_FRAGMENTED BIT(0) 143#define IEEE80211_TX_FRAGMENTED BIT(0)
143#define IEEE80211_TX_UNICAST BIT(1) 144#define IEEE80211_TX_UNICAST BIT(1)
144#define IEEE80211_TX_PS_BUFFERED BIT(2) 145#define IEEE80211_TX_PS_BUFFERED BIT(2)
145#define IEEE80211_TX_PROBE_LAST_FRAG BIT(3)
146 146
147struct ieee80211_tx_data { 147struct ieee80211_tx_data {
148 struct sk_buff *skb; 148 struct sk_buff *skb;
@@ -153,11 +153,6 @@ struct ieee80211_tx_data {
153 struct ieee80211_key *key; 153 struct ieee80211_key *key;
154 154
155 struct ieee80211_channel *channel; 155 struct ieee80211_channel *channel;
156 s8 rate_idx;
157 /* use this rate (if set) for last fragment; rate can
158 * be set to lower rate for the first fragments, e.g.,
159 * when using CTS protection with IEEE 802.11g. */
160 s8 last_frag_rate_idx;
161 156
162 /* Extra fragments (in addition to the first fragment 157 /* Extra fragments (in addition to the first fragment
163 * in skb) */ 158 * in skb) */
@@ -192,7 +187,6 @@ struct ieee80211_rx_data {
192 struct ieee80211_rx_status *status; 187 struct ieee80211_rx_status *status;
193 struct ieee80211_rate *rate; 188 struct ieee80211_rate *rate;
194 189
195 u16 ethertype;
196 unsigned int flags; 190 unsigned int flags;
197 int sent_ps_buffered; 191 int sent_ps_buffered;
198 int queue; 192 int queue;
@@ -203,9 +197,7 @@ struct ieee80211_rx_data {
203struct ieee80211_tx_stored_packet { 197struct ieee80211_tx_stored_packet {
204 struct sk_buff *skb; 198 struct sk_buff *skb;
205 struct sk_buff **extra_frag; 199 struct sk_buff **extra_frag;
206 s8 last_frag_rate_idx;
207 int num_extra_frag; 200 int num_extra_frag;
208 bool last_frag_rate_ctrl_probe;
209}; 201};
210 202
211struct beacon_data { 203struct beacon_data {
@@ -219,9 +211,6 @@ struct ieee80211_if_ap {
219 211
220 struct list_head vlans; 212 struct list_head vlans;
221 213
222 u8 ssid[IEEE80211_MAX_SSID_LEN];
223 size_t ssid_len;
224
225 /* yes, this looks ugly, but guarantees that we can later use 214 /* yes, this looks ugly, but guarantees that we can later use
226 * bitmap_empty :) 215 * bitmap_empty :)
227 * NB: don't touch this bitmap, use sta_info_{set,clear}_tim_bit */ 216 * NB: don't touch this bitmap, use sta_info_{set,clear}_tim_bit */
@@ -255,26 +244,6 @@ struct mesh_preq_queue {
255 u8 flags; 244 u8 flags;
256}; 245};
257 246
258struct mesh_config {
259 /* Timeouts in ms */
260 /* Mesh plink management parameters */
261 u16 dot11MeshRetryTimeout;
262 u16 dot11MeshConfirmTimeout;
263 u16 dot11MeshHoldingTimeout;
264 u16 dot11MeshMaxPeerLinks;
265 u8 dot11MeshMaxRetries;
266 u8 dot11MeshTTL;
267 bool auto_open_plinks;
268 /* HWMP parameters */
269 u8 dot11MeshHWMPmaxPREQretries;
270 u32 path_refresh_time;
271 u16 min_discovery_timeout;
272 u32 dot11MeshHWMPactivePathTimeout;
273 u16 dot11MeshHWMPpreqMinInterval;
274 u16 dot11MeshHWMPnetDiameterTraversalTime;
275};
276
277
278/* flags used in struct ieee80211_if_sta.flags */ 247/* flags used in struct ieee80211_if_sta.flags */
279#define IEEE80211_STA_SSID_SET BIT(0) 248#define IEEE80211_STA_SSID_SET BIT(0)
280#define IEEE80211_STA_BSSID_SET BIT(1) 249#define IEEE80211_STA_BSSID_SET BIT(1)
@@ -438,8 +407,7 @@ struct ieee80211_sub_if_data {
438 struct ieee80211_key *keys[NUM_DEFAULT_KEYS]; 407 struct ieee80211_key *keys[NUM_DEFAULT_KEYS];
439 struct ieee80211_key *default_key; 408 struct ieee80211_key *default_key;
440 409
441 /* BSS configuration for this interface. */ 410 u16 sequence_number;
442 struct ieee80211_bss_conf bss_conf;
443 411
444 /* 412 /*
445 * AP this belongs to: self in AP mode and 413 * AP this belongs to: self in AP mode and
@@ -570,6 +538,11 @@ enum {
570 IEEE80211_ADDBA_MSG = 4, 538 IEEE80211_ADDBA_MSG = 4,
571}; 539};
572 540
541enum queue_stop_reason {
542 IEEE80211_QUEUE_STOP_REASON_DRIVER,
543 IEEE80211_QUEUE_STOP_REASON_PS,
544};
545
573/* maximum number of hardware queues we support. */ 546/* maximum number of hardware queues we support. */
574#define QD_MAX_QUEUES (IEEE80211_MAX_AMPDU_QUEUES + IEEE80211_MAX_QUEUES) 547#define QD_MAX_QUEUES (IEEE80211_MAX_AMPDU_QUEUES + IEEE80211_MAX_QUEUES)
575 548
@@ -586,7 +559,8 @@ struct ieee80211_local {
586 const struct ieee80211_ops *ops; 559 const struct ieee80211_ops *ops;
587 560
588 unsigned long queue_pool[BITS_TO_LONGS(QD_MAX_QUEUES)]; 561 unsigned long queue_pool[BITS_TO_LONGS(QD_MAX_QUEUES)];
589 562 unsigned long queue_stop_reasons[IEEE80211_MAX_QUEUES];
563 spinlock_t queue_stop_reason_lock;
590 struct net_device *mdev; /* wmaster# - "master" 802.11 device */ 564 struct net_device *mdev; /* wmaster# - "master" 802.11 device */
591 int open_count; 565 int open_count;
592 int monitors, cooked_mntrs; 566 int monitors, cooked_mntrs;
@@ -633,8 +607,6 @@ struct ieee80211_local {
633 607
634 int rts_threshold; 608 int rts_threshold;
635 int fragmentation_threshold; 609 int fragmentation_threshold;
636 int short_retry_limit; /* dot11ShortRetryLimit */
637 int long_retry_limit; /* dot11LongRetryLimit */
638 610
639 struct crypto_blkcipher *wep_tx_tfm; 611 struct crypto_blkcipher *wep_tx_tfm;
640 struct crypto_blkcipher *wep_rx_tfm; 612 struct crypto_blkcipher *wep_rx_tfm;
@@ -659,6 +631,7 @@ struct ieee80211_local {
659 struct delayed_work scan_work; 631 struct delayed_work scan_work;
660 struct ieee80211_sub_if_data *scan_sdata; 632 struct ieee80211_sub_if_data *scan_sdata;
661 struct ieee80211_channel *oper_channel, *scan_channel; 633 struct ieee80211_channel *oper_channel, *scan_channel;
634 enum nl80211_channel_type oper_channel_type;
662 u8 scan_ssid[IEEE80211_MAX_SSID_LEN]; 635 u8 scan_ssid[IEEE80211_MAX_SSID_LEN];
663 size_t scan_ssid_len; 636 size_t scan_ssid_len;
664 struct list_head bss_list; 637 struct list_head bss_list;
@@ -722,13 +695,17 @@ struct ieee80211_local {
722 int wifi_wme_noack_test; 695 int wifi_wme_noack_test;
723 unsigned int wmm_acm; /* bit field of ACM bits (BIT(802.1D tag)) */ 696 unsigned int wmm_acm; /* bit field of ACM bits (BIT(802.1D tag)) */
724 697
698 bool powersave;
699 int dynamic_ps_timeout;
700 struct work_struct dynamic_ps_enable_work;
701 struct work_struct dynamic_ps_disable_work;
702 struct timer_list dynamic_ps_timer;
703
725#ifdef CONFIG_MAC80211_DEBUGFS 704#ifdef CONFIG_MAC80211_DEBUGFS
726 struct local_debugfsdentries { 705 struct local_debugfsdentries {
727 struct dentry *rcdir; 706 struct dentry *rcdir;
728 struct dentry *rcname; 707 struct dentry *rcname;
729 struct dentry *frequency; 708 struct dentry *frequency;
730 struct dentry *antenna_sel_tx;
731 struct dentry *antenna_sel_rx;
732 struct dentry *rts_threshold; 709 struct dentry *rts_threshold;
733 struct dentry *fragmentation_threshold; 710 struct dentry *fragmentation_threshold;
734 struct dentry *short_retry_limit; 711 struct dentry *short_retry_limit;
@@ -817,7 +794,7 @@ struct ieee802_11_elems {
817 u8 *wmm_info; 794 u8 *wmm_info;
818 u8 *wmm_param; 795 u8 *wmm_param;
819 struct ieee80211_ht_cap *ht_cap_elem; 796 struct ieee80211_ht_cap *ht_cap_elem;
820 struct ieee80211_ht_addt_info *ht_info_elem; 797 struct ieee80211_ht_info *ht_info_elem;
821 u8 *mesh_config; 798 u8 *mesh_config;
822 u8 *mesh_id; 799 u8 *mesh_id;
823 u8 *peer_link; 800 u8 *peer_link;
@@ -869,11 +846,6 @@ static inline struct ieee80211_hw *local_to_hw(
869 return &local->hw; 846 return &local->hw;
870} 847}
871 848
872struct sta_attribute {
873 struct attribute attr;
874 ssize_t (*show)(const struct sta_info *, char *buf);
875 ssize_t (*store)(struct sta_info *, const char *buf, size_t count);
876};
877 849
878static inline int ieee80211_bssid_match(const u8 *raddr, const u8 *addr) 850static inline int ieee80211_bssid_match(const u8 *raddr, const u8 *addr)
879{ 851{
@@ -882,12 +854,9 @@ static inline int ieee80211_bssid_match(const u8 *raddr, const u8 *addr)
882} 854}
883 855
884 856
885int ieee80211_hw_config(struct ieee80211_local *local); 857int ieee80211_hw_config(struct ieee80211_local *local, u32 changed);
886int ieee80211_if_config(struct ieee80211_sub_if_data *sdata, u32 changed); 858int ieee80211_if_config(struct ieee80211_sub_if_data *sdata, u32 changed);
887void ieee80211_tx_set_protected(struct ieee80211_tx_data *tx); 859void ieee80211_tx_set_protected(struct ieee80211_tx_data *tx);
888u32 ieee80211_handle_ht(struct ieee80211_local *local, int enable_ht,
889 struct ieee80211_ht_info *req_ht_cap,
890 struct ieee80211_ht_bss_info *req_bss_cap);
891void ieee80211_bss_info_change_notify(struct ieee80211_sub_if_data *sdata, 860void ieee80211_bss_info_change_notify(struct ieee80211_sub_if_data *sdata,
892 u32 changed); 861 u32 changed);
893void ieee80211_configure_filter(struct ieee80211_local *local); 862void ieee80211_configure_filter(struct ieee80211_local *local);
@@ -906,8 +875,7 @@ int ieee80211_sta_set_bssid(struct ieee80211_sub_if_data *sdata, u8 *bssid);
906void ieee80211_sta_req_auth(struct ieee80211_sub_if_data *sdata, 875void ieee80211_sta_req_auth(struct ieee80211_sub_if_data *sdata,
907 struct ieee80211_if_sta *ifsta); 876 struct ieee80211_if_sta *ifsta);
908struct sta_info *ieee80211_ibss_add_sta(struct ieee80211_sub_if_data *sdata, 877struct sta_info *ieee80211_ibss_add_sta(struct ieee80211_sub_if_data *sdata,
909 struct sk_buff *skb, u8 *bssid, 878 u8 *bssid, u8 *addr, u64 supp_rates);
910 u8 *addr, u64 supp_rates);
911int ieee80211_sta_deauthenticate(struct ieee80211_sub_if_data *sdata, u16 reason); 879int ieee80211_sta_deauthenticate(struct ieee80211_sub_if_data *sdata, u16 reason);
912int ieee80211_sta_disassociate(struct ieee80211_sub_if_data *sdata, u16 reason); 880int ieee80211_sta_disassociate(struct ieee80211_sub_if_data *sdata, u16 reason);
913u32 ieee80211_reset_erp_info(struct ieee80211_sub_if_data *sdata); 881u32 ieee80211_reset_erp_info(struct ieee80211_sub_if_data *sdata);
@@ -968,11 +936,12 @@ int ieee80211_monitor_start_xmit(struct sk_buff *skb, struct net_device *dev);
968int ieee80211_subif_start_xmit(struct sk_buff *skb, struct net_device *dev); 936int ieee80211_subif_start_xmit(struct sk_buff *skb, struct net_device *dev);
969 937
970/* HT */ 938/* HT */
971int ieee80211_ht_cap_ie_to_ht_info(struct ieee80211_ht_cap *ht_cap_ie, 939void ieee80211_ht_cap_ie_to_sta_ht_cap(struct ieee80211_supported_band *sband,
972 struct ieee80211_ht_info *ht_info); 940 struct ieee80211_ht_cap *ht_cap_ie,
973int ieee80211_ht_addt_info_ie_to_ht_bss_info( 941 struct ieee80211_sta_ht_cap *ht_cap);
974 struct ieee80211_ht_addt_info *ht_add_info_ie, 942u32 ieee80211_enable_ht(struct ieee80211_sub_if_data *sdata,
975 struct ieee80211_ht_bss_info *bss_info); 943 struct ieee80211_ht_info *hti,
944 u16 ap_ht_cap_flags);
976void ieee80211_send_bar(struct ieee80211_sub_if_data *sdata, u8 *ra, u16 tid, u16 ssn); 945void ieee80211_send_bar(struct ieee80211_sub_if_data *sdata, u8 *ra, u16 tid, u16 ssn);
977 946
978void ieee80211_sta_stop_rx_ba_session(struct ieee80211_sub_if_data *sdata, u8 *da, 947void ieee80211_sta_stop_rx_ba_session(struct ieee80211_sub_if_data *sdata, u8 *da,
@@ -1014,6 +983,15 @@ int ieee80211_set_freq(struct ieee80211_sub_if_data *sdata, int freq);
1014u64 ieee80211_mandatory_rates(struct ieee80211_local *local, 983u64 ieee80211_mandatory_rates(struct ieee80211_local *local,
1015 enum ieee80211_band band); 984 enum ieee80211_band band);
1016 985
986void ieee80211_dynamic_ps_enable_work(struct work_struct *work);
987void ieee80211_dynamic_ps_disable_work(struct work_struct *work);
988void ieee80211_dynamic_ps_timer(unsigned long data);
989
990void ieee80211_wake_queues_by_reason(struct ieee80211_hw *hw,
991 enum queue_stop_reason reason);
992void ieee80211_stop_queues_by_reason(struct ieee80211_hw *hw,
993 enum queue_stop_reason reason);
994
1017#ifdef CONFIG_MAC80211_NOINLINE 995#ifdef CONFIG_MAC80211_NOINLINE
1018#define debug_noinline noinline 996#define debug_noinline noinline
1019#else 997#else
diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
index 8336fee68d3e..5abbc3f07dd6 100644
--- a/net/mac80211/iface.c
+++ b/net/mac80211/iface.c
@@ -65,7 +65,7 @@ static int ieee80211_open(struct net_device *dev)
65 struct ieee80211_if_init_conf conf; 65 struct ieee80211_if_init_conf conf;
66 u32 changed = 0; 66 u32 changed = 0;
67 int res; 67 int res;
68 bool need_hw_reconfig = 0; 68 u32 hw_reconf_flags = 0;
69 u8 null_addr[ETH_ALEN] = {0}; 69 u8 null_addr[ETH_ALEN] = {0};
70 70
71 /* fail early if user set an invalid address */ 71 /* fail early if user set an invalid address */
@@ -152,7 +152,8 @@ static int ieee80211_open(struct net_device *dev)
152 res = local->ops->start(local_to_hw(local)); 152 res = local->ops->start(local_to_hw(local));
153 if (res) 153 if (res)
154 goto err_del_bss; 154 goto err_del_bss;
155 need_hw_reconfig = 1; 155 /* we're brought up, everything changes */
156 hw_reconf_flags = ~0;
156 ieee80211_led_radio(local, local->hw.conf.radio_enabled); 157 ieee80211_led_radio(local, local->hw.conf.radio_enabled);
157 } 158 }
158 159
@@ -198,8 +199,10 @@ static int ieee80211_open(struct net_device *dev)
198 199
199 /* must be before the call to ieee80211_configure_filter */ 200 /* must be before the call to ieee80211_configure_filter */
200 local->monitors++; 201 local->monitors++;
201 if (local->monitors == 1) 202 if (local->monitors == 1) {
202 local->hw.conf.flags |= IEEE80211_CONF_RADIOTAP; 203 local->hw.conf.flags |= IEEE80211_CONF_RADIOTAP;
204 hw_reconf_flags |= IEEE80211_CONF_CHANGE_RADIOTAP;
205 }
203 206
204 if (sdata->u.mntr_flags & MONITOR_FLAG_FCSFAIL) 207 if (sdata->u.mntr_flags & MONITOR_FLAG_FCSFAIL)
205 local->fif_fcsfail++; 208 local->fif_fcsfail++;
@@ -226,8 +229,14 @@ static int ieee80211_open(struct net_device *dev)
226 if (res) 229 if (res)
227 goto err_stop; 230 goto err_stop;
228 231
229 if (ieee80211_vif_is_mesh(&sdata->vif)) 232 if (ieee80211_vif_is_mesh(&sdata->vif)) {
233 local->fif_other_bss++;
234 netif_addr_lock_bh(local->mdev);
235 ieee80211_configure_filter(local);
236 netif_addr_unlock_bh(local->mdev);
237
230 ieee80211_start_mesh(sdata); 238 ieee80211_start_mesh(sdata);
239 }
231 changed |= ieee80211_reset_erp_info(sdata); 240 changed |= ieee80211_reset_erp_info(sdata);
232 ieee80211_bss_info_change_notify(sdata, changed); 241 ieee80211_bss_info_change_notify(sdata, changed);
233 ieee80211_enable_keys(sdata); 242 ieee80211_enable_keys(sdata);
@@ -279,8 +288,8 @@ static int ieee80211_open(struct net_device *dev)
279 atomic_inc(&local->iff_promiscs); 288 atomic_inc(&local->iff_promiscs);
280 289
281 local->open_count++; 290 local->open_count++;
282 if (need_hw_reconfig) { 291 if (hw_reconf_flags) {
283 ieee80211_hw_config(local); 292 ieee80211_hw_config(local, hw_reconf_flags);
284 /* 293 /*
285 * set default queue parameters so drivers don't 294 * set default queue parameters so drivers don't
286 * need to initialise the hardware if the hardware 295 * need to initialise the hardware if the hardware
@@ -322,6 +331,7 @@ static int ieee80211_stop(struct net_device *dev)
322 struct ieee80211_local *local = sdata->local; 331 struct ieee80211_local *local = sdata->local;
323 struct ieee80211_if_init_conf conf; 332 struct ieee80211_if_init_conf conf;
324 struct sta_info *sta; 333 struct sta_info *sta;
334 u32 hw_reconf_flags = 0;
325 335
326 /* 336 /*
327 * Stop TX on this interface first. 337 * Stop TX on this interface first.
@@ -405,8 +415,10 @@ static int ieee80211_stop(struct net_device *dev)
405 } 415 }
406 416
407 local->monitors--; 417 local->monitors--;
408 if (local->monitors == 0) 418 if (local->monitors == 0) {
409 local->hw.conf.flags &= ~IEEE80211_CONF_RADIOTAP; 419 local->hw.conf.flags &= ~IEEE80211_CONF_RADIOTAP;
420 hw_reconf_flags |= IEEE80211_CONF_CHANGE_RADIOTAP;
421 }
410 422
411 if (sdata->u.mntr_flags & MONITOR_FLAG_FCSFAIL) 423 if (sdata->u.mntr_flags & MONITOR_FLAG_FCSFAIL)
412 local->fif_fcsfail--; 424 local->fif_fcsfail--;
@@ -423,7 +435,11 @@ static int ieee80211_stop(struct net_device *dev)
423 break; 435 break;
424 case NL80211_IFTYPE_STATION: 436 case NL80211_IFTYPE_STATION:
425 case NL80211_IFTYPE_ADHOC: 437 case NL80211_IFTYPE_ADHOC:
426 sdata->u.sta.state = IEEE80211_STA_MLME_DISABLED; 438 /* Announce that we are leaving the network. */
439 if (sdata->u.sta.state != IEEE80211_STA_MLME_DISABLED)
440 ieee80211_sta_deauthenticate(sdata,
441 WLAN_REASON_DEAUTH_LEAVING);
442
427 memset(sdata->u.sta.bssid, 0, ETH_ALEN); 443 memset(sdata->u.sta.bssid, 0, ETH_ALEN);
428 del_timer_sync(&sdata->u.sta.timer); 444 del_timer_sync(&sdata->u.sta.timer);
429 /* 445 /*
@@ -450,8 +466,15 @@ static int ieee80211_stop(struct net_device *dev)
450 /* fall through */ 466 /* fall through */
451 case NL80211_IFTYPE_MESH_POINT: 467 case NL80211_IFTYPE_MESH_POINT:
452 if (ieee80211_vif_is_mesh(&sdata->vif)) { 468 if (ieee80211_vif_is_mesh(&sdata->vif)) {
453 /* allmulti is always set on mesh ifaces */ 469 /* other_bss and allmulti are always set on mesh
470 * ifaces */
471 local->fif_other_bss--;
454 atomic_dec(&local->iff_allmultis); 472 atomic_dec(&local->iff_allmultis);
473
474 netif_addr_lock_bh(local->mdev);
475 ieee80211_configure_filter(local);
476 netif_addr_unlock_bh(local->mdev);
477
455 ieee80211_stop_mesh(sdata); 478 ieee80211_stop_mesh(sdata);
456 } 479 }
457 /* fall through */ 480 /* fall through */
@@ -504,8 +527,15 @@ static int ieee80211_stop(struct net_device *dev)
504 527
505 tasklet_disable(&local->tx_pending_tasklet); 528 tasklet_disable(&local->tx_pending_tasklet);
506 tasklet_disable(&local->tasklet); 529 tasklet_disable(&local->tasklet);
530
531 /* no reconfiguring after stop! */
532 hw_reconf_flags = 0;
507 } 533 }
508 534
535 /* do after stop to avoid reconfiguring when we stop anyway */
536 if (hw_reconf_flags)
537 ieee80211_hw_config(local, hw_reconf_flags);
538
509 return 0; 539 return 0;
510} 540}
511 541
@@ -668,6 +698,10 @@ int ieee80211_if_change_type(struct ieee80211_sub_if_data *sdata,
668 if (type == sdata->vif.type) 698 if (type == sdata->vif.type)
669 return 0; 699 return 0;
670 700
701 /* Setting ad-hoc mode on non-IBSS channel is not supported. */
702 if (sdata->local->oper_channel->flags & IEEE80211_CHAN_NO_IBSS)
703 return -EOPNOTSUPP;
704
671 /* 705 /*
672 * We could, here, on changes between IBSS/STA/MESH modes, 706 * We could, here, on changes between IBSS/STA/MESH modes,
673 * invoke an MLME function instead that disassociates etc. 707 * invoke an MLME function instead that disassociates etc.
@@ -682,7 +716,7 @@ int ieee80211_if_change_type(struct ieee80211_sub_if_data *sdata,
682 ieee80211_setup_sdata(sdata, type); 716 ieee80211_setup_sdata(sdata, type);
683 717
684 /* reset some values that shouldn't be kept across type changes */ 718 /* reset some values that shouldn't be kept across type changes */
685 sdata->bss_conf.basic_rates = 719 sdata->vif.bss_conf.basic_rates =
686 ieee80211_mandatory_rates(sdata->local, 720 ieee80211_mandatory_rates(sdata->local,
687 sdata->local->hw.conf.channel->band); 721 sdata->local->hw.conf.channel->band);
688 sdata->drop_unencrypted = 0; 722 sdata->drop_unencrypted = 0;
diff --git a/net/mac80211/key.c b/net/mac80211/key.c
index a5b06fe71980..999f7aa42326 100644
--- a/net/mac80211/key.c
+++ b/net/mac80211/key.c
@@ -132,7 +132,6 @@ static void ieee80211_key_enable_hw_accel(struct ieee80211_key *key)
132{ 132{
133 const u8 *addr; 133 const u8 *addr;
134 int ret; 134 int ret;
135 DECLARE_MAC_BUF(mac);
136 135
137 assert_key_lock(); 136 assert_key_lock();
138 might_sleep(); 137 might_sleep();
@@ -154,16 +153,15 @@ static void ieee80211_key_enable_hw_accel(struct ieee80211_key *key)
154 153
155 if (ret && ret != -ENOSPC && ret != -EOPNOTSUPP) 154 if (ret && ret != -ENOSPC && ret != -EOPNOTSUPP)
156 printk(KERN_ERR "mac80211-%s: failed to set key " 155 printk(KERN_ERR "mac80211-%s: failed to set key "
157 "(%d, %s) to hardware (%d)\n", 156 "(%d, %pM) to hardware (%d)\n",
158 wiphy_name(key->local->hw.wiphy), 157 wiphy_name(key->local->hw.wiphy),
159 key->conf.keyidx, print_mac(mac, addr), ret); 158 key->conf.keyidx, addr, ret);
160} 159}
161 160
162static void ieee80211_key_disable_hw_accel(struct ieee80211_key *key) 161static void ieee80211_key_disable_hw_accel(struct ieee80211_key *key)
163{ 162{
164 const u8 *addr; 163 const u8 *addr;
165 int ret; 164 int ret;
166 DECLARE_MAC_BUF(mac);
167 165
168 assert_key_lock(); 166 assert_key_lock();
169 might_sleep(); 167 might_sleep();
@@ -186,9 +184,9 @@ static void ieee80211_key_disable_hw_accel(struct ieee80211_key *key)
186 184
187 if (ret) 185 if (ret)
188 printk(KERN_ERR "mac80211-%s: failed to remove key " 186 printk(KERN_ERR "mac80211-%s: failed to remove key "
189 "(%d, %s) from hardware (%d)\n", 187 "(%d, %pM) from hardware (%d)\n",
190 wiphy_name(key->local->hw.wiphy), 188 wiphy_name(key->local->hw.wiphy),
191 key->conf.keyidx, print_mac(mac, addr), ret); 189 key->conf.keyidx, addr, ret);
192 190
193 spin_lock(&todo_lock); 191 spin_lock(&todo_lock);
194 key->flags &= ~KEY_FLAG_UPLOADED_TO_HARDWARE; 192 key->flags &= ~KEY_FLAG_UPLOADED_TO_HARDWARE;
diff --git a/net/mac80211/main.c b/net/mac80211/main.c
index ae62ad40ad63..24b14363d6e7 100644
--- a/net/mac80211/main.c
+++ b/net/mac80211/main.c
@@ -41,6 +41,8 @@
41 */ 41 */
42struct ieee80211_tx_status_rtap_hdr { 42struct ieee80211_tx_status_rtap_hdr {
43 struct ieee80211_radiotap_header hdr; 43 struct ieee80211_radiotap_header hdr;
44 u8 rate;
45 u8 padding_for_rate;
44 __le16 tx_flags; 46 __le16 tx_flags;
45 u8 data_retries; 47 u8 data_retries;
46} __attribute__ ((packed)); 48} __attribute__ ((packed));
@@ -169,19 +171,13 @@ int ieee80211_if_config(struct ieee80211_sub_if_data *sdata, u32 changed)
169 conf.changed = changed; 171 conf.changed = changed;
170 172
171 if (sdata->vif.type == NL80211_IFTYPE_STATION || 173 if (sdata->vif.type == NL80211_IFTYPE_STATION ||
172 sdata->vif.type == NL80211_IFTYPE_ADHOC) { 174 sdata->vif.type == NL80211_IFTYPE_ADHOC)
173 conf.bssid = sdata->u.sta.bssid; 175 conf.bssid = sdata->u.sta.bssid;
174 conf.ssid = sdata->u.sta.ssid; 176 else if (sdata->vif.type == NL80211_IFTYPE_AP)
175 conf.ssid_len = sdata->u.sta.ssid_len;
176 } else if (sdata->vif.type == NL80211_IFTYPE_AP) {
177 conf.bssid = sdata->dev->dev_addr; 177 conf.bssid = sdata->dev->dev_addr;
178 conf.ssid = sdata->u.ap.ssid; 178 else if (ieee80211_vif_is_mesh(&sdata->vif)) {
179 conf.ssid_len = sdata->u.ap.ssid_len;
180 } else if (ieee80211_vif_is_mesh(&sdata->vif)) {
181 u8 zero[ETH_ALEN] = { 0 }; 179 u8 zero[ETH_ALEN] = { 0 };
182 conf.bssid = zero; 180 conf.bssid = zero;
183 conf.ssid = zero;
184 conf.ssid_len = 0;
185 } else { 181 } else {
186 WARN_ON(1); 182 WARN_ON(1);
187 return -EINVAL; 183 return -EINVAL;
@@ -190,136 +186,73 @@ int ieee80211_if_config(struct ieee80211_sub_if_data *sdata, u32 changed)
190 if (WARN_ON(!conf.bssid && (changed & IEEE80211_IFCC_BSSID))) 186 if (WARN_ON(!conf.bssid && (changed & IEEE80211_IFCC_BSSID)))
191 return -EINVAL; 187 return -EINVAL;
192 188
193 if (WARN_ON(!conf.ssid && (changed & IEEE80211_IFCC_SSID)))
194 return -EINVAL;
195
196 return local->ops->config_interface(local_to_hw(local), 189 return local->ops->config_interface(local_to_hw(local),
197 &sdata->vif, &conf); 190 &sdata->vif, &conf);
198} 191}
199 192
200int ieee80211_hw_config(struct ieee80211_local *local) 193int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
201{ 194{
202 struct ieee80211_channel *chan; 195 struct ieee80211_channel *chan;
203 int ret = 0; 196 int ret = 0;
197 int power;
198 enum nl80211_channel_type channel_type;
199
200 might_sleep();
204 201
205 if (local->sw_scanning) 202 if (local->sw_scanning) {
206 chan = local->scan_channel; 203 chan = local->scan_channel;
207 else 204 channel_type = NL80211_CHAN_NO_HT;
205 } else {
208 chan = local->oper_channel; 206 chan = local->oper_channel;
207 channel_type = local->oper_channel_type;
208 }
209 209
210 local->hw.conf.channel = chan; 210 if (chan != local->hw.conf.channel ||
211 channel_type != local->hw.conf.ht.channel_type) {
212 local->hw.conf.channel = chan;
213 local->hw.conf.ht.channel_type = channel_type;
214 switch (channel_type) {
215 case NL80211_CHAN_NO_HT:
216 local->hw.conf.ht.enabled = false;
217 break;
218 case NL80211_CHAN_HT20:
219 case NL80211_CHAN_HT40MINUS:
220 case NL80211_CHAN_HT40PLUS:
221 local->hw.conf.ht.enabled = true;
222 break;
223 }
224 changed |= IEEE80211_CONF_CHANGE_CHANNEL;
225 }
211 226
212 if (!local->hw.conf.power_level) 227 if (!local->hw.conf.power_level)
213 local->hw.conf.power_level = chan->max_power; 228 power = chan->max_power;
214 else 229 else
215 local->hw.conf.power_level = min(chan->max_power, 230 power = min(chan->max_power, local->hw.conf.power_level);
216 local->hw.conf.power_level); 231 if (local->hw.conf.power_level != power) {
217 232 changed |= IEEE80211_CONF_CHANGE_POWER;
218 local->hw.conf.max_antenna_gain = chan->max_antenna_gain; 233 local->hw.conf.power_level = power;
219
220#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
221 printk(KERN_DEBUG "%s: HW CONFIG: freq=%d\n",
222 wiphy_name(local->hw.wiphy), chan->center_freq);
223#endif
224
225 if (local->open_count)
226 ret = local->ops->config(local_to_hw(local), &local->hw.conf);
227
228 return ret;
229}
230
231/**
232 * ieee80211_handle_ht should be used only after legacy configuration
233 * has been determined namely band, as ht configuration depends upon
234 * the hardware's HT abilities for a _specific_ band.
235 */
236u32 ieee80211_handle_ht(struct ieee80211_local *local, int enable_ht,
237 struct ieee80211_ht_info *req_ht_cap,
238 struct ieee80211_ht_bss_info *req_bss_cap)
239{
240 struct ieee80211_conf *conf = &local->hw.conf;
241 struct ieee80211_supported_band *sband;
242 struct ieee80211_ht_info ht_conf;
243 struct ieee80211_ht_bss_info ht_bss_conf;
244 u32 changed = 0;
245 int i;
246 u8 max_tx_streams = IEEE80211_HT_CAP_MAX_STREAMS;
247 u8 tx_mcs_set_cap;
248
249 sband = local->hw.wiphy->bands[conf->channel->band];
250
251 memset(&ht_conf, 0, sizeof(struct ieee80211_ht_info));
252 memset(&ht_bss_conf, 0, sizeof(struct ieee80211_ht_bss_info));
253
254 /* HT is not supported */
255 if (!sband->ht_info.ht_supported) {
256 conf->flags &= ~IEEE80211_CONF_SUPPORT_HT_MODE;
257 goto out;
258 } 234 }
259 235
260 /* disable HT */ 236 if (changed && local->open_count) {
261 if (!enable_ht) { 237 ret = local->ops->config(local_to_hw(local), changed);
262 if (conf->flags & IEEE80211_CONF_SUPPORT_HT_MODE) 238 /*
263 changed |= BSS_CHANGED_HT; 239 * Goal:
264 conf->flags &= ~IEEE80211_CONF_SUPPORT_HT_MODE; 240 * HW reconfiguration should never fail, the driver has told
265 conf->ht_conf.ht_supported = 0; 241 * us what it can support so it should live up to that promise.
266 goto out; 242 *
243 * Current status:
244 * rfkill is not integrated with mac80211 and a
245 * configuration command can thus fail if hardware rfkill
246 * is enabled
247 *
248 * FIXME: integrate rfkill with mac80211 and then add this
249 * WARN_ON() back
250 *
251 */
252 /* WARN_ON(ret); */
267 } 253 }
268 254
269 255 return ret;
270 if (!(conf->flags & IEEE80211_CONF_SUPPORT_HT_MODE))
271 changed |= BSS_CHANGED_HT;
272
273 conf->flags |= IEEE80211_CONF_SUPPORT_HT_MODE;
274 ht_conf.ht_supported = 1;
275
276 ht_conf.cap = req_ht_cap->cap & sband->ht_info.cap;
277 ht_conf.cap &= ~(IEEE80211_HT_CAP_SM_PS);
278 ht_conf.cap |= sband->ht_info.cap & IEEE80211_HT_CAP_SM_PS;
279 ht_bss_conf.primary_channel = req_bss_cap->primary_channel;
280 ht_bss_conf.bss_cap = req_bss_cap->bss_cap;
281 ht_bss_conf.bss_op_mode = req_bss_cap->bss_op_mode;
282
283 ht_conf.ampdu_factor = req_ht_cap->ampdu_factor;
284 ht_conf.ampdu_density = req_ht_cap->ampdu_density;
285
286 /* Bits 96-100 */
287 tx_mcs_set_cap = sband->ht_info.supp_mcs_set[12];
288
289 /* configure suppoerted Tx MCS according to requested MCS
290 * (based in most cases on Rx capabilities of peer) and self
291 * Tx MCS capabilities (as defined by low level driver HW
292 * Tx capabilities) */
293 if (!(tx_mcs_set_cap & IEEE80211_HT_CAP_MCS_TX_DEFINED))
294 goto check_changed;
295
296 /* Counting from 0 therfore + 1 */
297 if (tx_mcs_set_cap & IEEE80211_HT_CAP_MCS_TX_RX_DIFF)
298 max_tx_streams = ((tx_mcs_set_cap &
299 IEEE80211_HT_CAP_MCS_TX_STREAMS) >> 2) + 1;
300
301 for (i = 0; i < max_tx_streams; i++)
302 ht_conf.supp_mcs_set[i] =
303 sband->ht_info.supp_mcs_set[i] &
304 req_ht_cap->supp_mcs_set[i];
305
306 if (tx_mcs_set_cap & IEEE80211_HT_CAP_MCS_TX_UEQM)
307 for (i = IEEE80211_SUPP_MCS_SET_UEQM;
308 i < IEEE80211_SUPP_MCS_SET_LEN; i++)
309 ht_conf.supp_mcs_set[i] =
310 sband->ht_info.supp_mcs_set[i] &
311 req_ht_cap->supp_mcs_set[i];
312
313check_changed:
314 /* if bss configuration changed store the new one */
315 if (memcmp(&conf->ht_conf, &ht_conf, sizeof(ht_conf)) ||
316 memcmp(&conf->ht_bss_conf, &ht_bss_conf, sizeof(ht_bss_conf))) {
317 changed |= BSS_CHANGED_HT;
318 memcpy(&conf->ht_conf, &ht_conf, sizeof(ht_conf));
319 memcpy(&conf->ht_bss_conf, &ht_bss_conf, sizeof(ht_bss_conf));
320 }
321out:
322 return changed;
323} 256}
324 257
325void ieee80211_bss_info_change_notify(struct ieee80211_sub_if_data *sdata, 258void ieee80211_bss_info_change_notify(struct ieee80211_sub_if_data *sdata,
@@ -336,15 +269,18 @@ void ieee80211_bss_info_change_notify(struct ieee80211_sub_if_data *sdata,
336 if (local->ops->bss_info_changed) 269 if (local->ops->bss_info_changed)
337 local->ops->bss_info_changed(local_to_hw(local), 270 local->ops->bss_info_changed(local_to_hw(local),
338 &sdata->vif, 271 &sdata->vif,
339 &sdata->bss_conf, 272 &sdata->vif.bss_conf,
340 changed); 273 changed);
341} 274}
342 275
343u32 ieee80211_reset_erp_info(struct ieee80211_sub_if_data *sdata) 276u32 ieee80211_reset_erp_info(struct ieee80211_sub_if_data *sdata)
344{ 277{
345 sdata->bss_conf.use_cts_prot = 0; 278 sdata->vif.bss_conf.use_cts_prot = false;
346 sdata->bss_conf.use_short_preamble = 0; 279 sdata->vif.bss_conf.use_short_preamble = false;
347 return BSS_CHANGED_ERP_CTS_PROT | BSS_CHANGED_ERP_PREAMBLE; 280 sdata->vif.bss_conf.use_short_slot = false;
281 return BSS_CHANGED_ERP_CTS_PROT |
282 BSS_CHANGED_ERP_PREAMBLE |
283 BSS_CHANGED_ERP_SLOT;
348} 284}
349 285
350void ieee80211_tx_status_irqsafe(struct ieee80211_hw *hw, 286void ieee80211_tx_status_irqsafe(struct ieee80211_hw *hw,
@@ -405,7 +341,8 @@ static void ieee80211_tasklet_handler(unsigned long data)
405 dev_kfree_skb(skb); 341 dev_kfree_skb(skb);
406 break ; 342 break ;
407 default: 343 default:
408 WARN_ON(1); 344 WARN(1, "mac80211: Packet is of unknown type %d\n",
345 skb->pkt_type);
409 dev_kfree_skb(skb); 346 dev_kfree_skb(skb);
410 break; 347 break;
411 } 348 }
@@ -466,8 +403,6 @@ static void ieee80211_handle_filtered_frame(struct ieee80211_local *local,
466 struct sta_info *sta, 403 struct sta_info *sta,
467 struct sk_buff *skb) 404 struct sk_buff *skb)
468{ 405{
469 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
470
471 sta->tx_filtered_count++; 406 sta->tx_filtered_count++;
472 407
473 /* 408 /*
@@ -514,10 +449,9 @@ static void ieee80211_handle_filtered_frame(struct ieee80211_local *local,
514 return; 449 return;
515 } 450 }
516 451
517 if (!test_sta_flags(sta, WLAN_STA_PS) && 452 if (!test_sta_flags(sta, WLAN_STA_PS) && !skb->requeue) {
518 !(info->flags & IEEE80211_TX_CTL_REQUEUE)) {
519 /* Software retry the packet once */ 453 /* Software retry the packet once */
520 info->flags |= IEEE80211_TX_CTL_REQUEUE; 454 skb->requeue = 1;
521 ieee80211_remove_tx_extra(local, sta->key, skb); 455 ieee80211_remove_tx_extra(local, sta->key, skb);
522 dev_queue_xmit(skb); 456 dev_queue_xmit(skb);
523 return; 457 return;
@@ -547,13 +481,28 @@ void ieee80211_tx_status(struct ieee80211_hw *hw, struct sk_buff *skb)
547 struct ieee80211_sub_if_data *sdata; 481 struct ieee80211_sub_if_data *sdata;
548 struct net_device *prev_dev = NULL; 482 struct net_device *prev_dev = NULL;
549 struct sta_info *sta; 483 struct sta_info *sta;
484 int retry_count = -1, i;
485
486 for (i = 0; i < IEEE80211_TX_MAX_RATES; i++) {
487 /* the HW cannot have attempted that rate */
488 if (i >= hw->max_rates) {
489 info->status.rates[i].idx = -1;
490 info->status.rates[i].count = 0;
491 }
492
493 retry_count += info->status.rates[i].count;
494 }
495 if (retry_count < 0)
496 retry_count = 0;
550 497
551 rcu_read_lock(); 498 rcu_read_lock();
552 499
500 sband = local->hw.wiphy->bands[info->band];
501
553 sta = sta_info_get(local, hdr->addr1); 502 sta = sta_info_get(local, hdr->addr1);
554 503
555 if (sta) { 504 if (sta) {
556 if (info->status.excessive_retries && 505 if (!(info->flags & IEEE80211_TX_STAT_ACK) &&
557 test_sta_flags(sta, WLAN_STA_PS)) { 506 test_sta_flags(sta, WLAN_STA_PS)) {
558 /* 507 /*
559 * The STA is in power save mode, so assume 508 * The STA is in power save mode, so assume
@@ -584,12 +533,11 @@ void ieee80211_tx_status(struct ieee80211_hw *hw, struct sk_buff *skb)
584 rcu_read_unlock(); 533 rcu_read_unlock();
585 return; 534 return;
586 } else { 535 } else {
587 if (info->status.excessive_retries) 536 if (!(info->flags & IEEE80211_TX_STAT_ACK))
588 sta->tx_retry_failed++; 537 sta->tx_retry_failed++;
589 sta->tx_retry_count += info->status.retry_count; 538 sta->tx_retry_count += retry_count;
590 } 539 }
591 540
592 sband = local->hw.wiphy->bands[info->band];
593 rate_control_tx_status(local, sband, sta, skb); 541 rate_control_tx_status(local, sband, sta, skb);
594 } 542 }
595 543
@@ -610,9 +558,9 @@ void ieee80211_tx_status(struct ieee80211_hw *hw, struct sk_buff *skb)
610 local->dot11TransmittedFrameCount++; 558 local->dot11TransmittedFrameCount++;
611 if (is_multicast_ether_addr(hdr->addr1)) 559 if (is_multicast_ether_addr(hdr->addr1))
612 local->dot11MulticastTransmittedFrameCount++; 560 local->dot11MulticastTransmittedFrameCount++;
613 if (info->status.retry_count > 0) 561 if (retry_count > 0)
614 local->dot11RetryCount++; 562 local->dot11RetryCount++;
615 if (info->status.retry_count > 1) 563 if (retry_count > 1)
616 local->dot11MultipleRetryCount++; 564 local->dot11MultipleRetryCount++;
617 } 565 }
618 566
@@ -656,19 +604,30 @@ void ieee80211_tx_status(struct ieee80211_hw *hw, struct sk_buff *skb)
656 rthdr->hdr.it_len = cpu_to_le16(sizeof(*rthdr)); 604 rthdr->hdr.it_len = cpu_to_le16(sizeof(*rthdr));
657 rthdr->hdr.it_present = 605 rthdr->hdr.it_present =
658 cpu_to_le32((1 << IEEE80211_RADIOTAP_TX_FLAGS) | 606 cpu_to_le32((1 << IEEE80211_RADIOTAP_TX_FLAGS) |
659 (1 << IEEE80211_RADIOTAP_DATA_RETRIES)); 607 (1 << IEEE80211_RADIOTAP_DATA_RETRIES) |
608 (1 << IEEE80211_RADIOTAP_RATE));
660 609
661 if (!(info->flags & IEEE80211_TX_STAT_ACK) && 610 if (!(info->flags & IEEE80211_TX_STAT_ACK) &&
662 !is_multicast_ether_addr(hdr->addr1)) 611 !is_multicast_ether_addr(hdr->addr1))
663 rthdr->tx_flags |= cpu_to_le16(IEEE80211_RADIOTAP_F_TX_FAIL); 612 rthdr->tx_flags |= cpu_to_le16(IEEE80211_RADIOTAP_F_TX_FAIL);
664 613
665 if ((info->flags & IEEE80211_TX_CTL_USE_RTS_CTS) && 614 /*
666 (info->flags & IEEE80211_TX_CTL_USE_CTS_PROTECT)) 615 * XXX: Once radiotap gets the bitmap reset thing the vendor
616 * extensions proposal contains, we can actually report
617 * the whole set of tries we did.
618 */
619 if ((info->status.rates[0].flags & IEEE80211_TX_RC_USE_RTS_CTS) ||
620 (info->status.rates[0].flags & IEEE80211_TX_RC_USE_CTS_PROTECT))
667 rthdr->tx_flags |= cpu_to_le16(IEEE80211_RADIOTAP_F_TX_CTS); 621 rthdr->tx_flags |= cpu_to_le16(IEEE80211_RADIOTAP_F_TX_CTS);
668 else if (info->flags & IEEE80211_TX_CTL_USE_RTS_CTS) 622 else if (info->status.rates[0].flags & IEEE80211_TX_RC_USE_RTS_CTS)
669 rthdr->tx_flags |= cpu_to_le16(IEEE80211_RADIOTAP_F_TX_RTS); 623 rthdr->tx_flags |= cpu_to_le16(IEEE80211_RADIOTAP_F_TX_RTS);
624 if (info->status.rates[0].idx >= 0 &&
625 !(info->status.rates[0].flags & IEEE80211_TX_RC_MCS))
626 rthdr->rate = sband->bitrates[
627 info->status.rates[0].idx].bitrate / 5;
670 628
671 rthdr->data_retries = info->status.retry_count; 629 /* for now report the total retry_count */
630 rthdr->data_retries = retry_count;
672 631
673 /* XXX: is this sufficient for BPF? */ 632 /* XXX: is this sufficient for BPF? */
674 skb_set_mac_header(skb, 0); 633 skb_set_mac_header(skb, 0);
@@ -753,20 +712,30 @@ struct ieee80211_hw *ieee80211_alloc_hw(size_t priv_data_len,
753 BUG_ON(!ops->configure_filter); 712 BUG_ON(!ops->configure_filter);
754 local->ops = ops; 713 local->ops = ops;
755 714
756 local->hw.queues = 1; /* default */ 715 /* set up some defaults */
757 716 local->hw.queues = 1;
717 local->hw.max_rates = 1;
758 local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD; 718 local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
759 local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD; 719 local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD;
760 local->short_retry_limit = 7; 720 local->hw.conf.long_frame_max_tx_count = 4;
761 local->long_retry_limit = 4; 721 local->hw.conf.short_frame_max_tx_count = 7;
762 local->hw.conf.radio_enabled = 1; 722 local->hw.conf.radio_enabled = true;
763 723
764 INIT_LIST_HEAD(&local->interfaces); 724 INIT_LIST_HEAD(&local->interfaces);
765 725
766 spin_lock_init(&local->key_lock); 726 spin_lock_init(&local->key_lock);
767 727
728 spin_lock_init(&local->queue_stop_reason_lock);
729
768 INIT_DELAYED_WORK(&local->scan_work, ieee80211_scan_work); 730 INIT_DELAYED_WORK(&local->scan_work, ieee80211_scan_work);
769 731
732 INIT_WORK(&local->dynamic_ps_enable_work,
733 ieee80211_dynamic_ps_enable_work);
734 INIT_WORK(&local->dynamic_ps_disable_work,
735 ieee80211_dynamic_ps_disable_work);
736 setup_timer(&local->dynamic_ps_timer,
737 ieee80211_dynamic_ps_timer, (unsigned long) local);
738
770 sta_info_init(local); 739 sta_info_init(local);
771 740
772 tasklet_init(&local->tx_pending_tasklet, ieee80211_tx_pending, 741 tasklet_init(&local->tx_pending_tasklet, ieee80211_tx_pending,
@@ -788,7 +757,6 @@ EXPORT_SYMBOL(ieee80211_alloc_hw);
788int ieee80211_register_hw(struct ieee80211_hw *hw) 757int ieee80211_register_hw(struct ieee80211_hw *hw)
789{ 758{
790 struct ieee80211_local *local = hw_to_local(hw); 759 struct ieee80211_local *local = hw_to_local(hw);
791 const char *name;
792 int result; 760 int result;
793 enum ieee80211_band band; 761 enum ieee80211_band band;
794 struct net_device *mdev; 762 struct net_device *mdev;
@@ -853,8 +821,8 @@ int ieee80211_register_hw(struct ieee80211_hw *hw)
853 mdev->header_ops = &ieee80211_header_ops; 821 mdev->header_ops = &ieee80211_header_ops;
854 mdev->set_multicast_list = ieee80211_master_set_multicast_list; 822 mdev->set_multicast_list = ieee80211_master_set_multicast_list;
855 823
856 name = wiphy_dev(local->hw.wiphy)->driver->name; 824 local->hw.workqueue =
857 local->hw.workqueue = create_freezeable_workqueue(name); 825 create_freezeable_workqueue(wiphy_name(local->hw.wiphy));
858 if (!local->hw.workqueue) { 826 if (!local->hw.workqueue) {
859 result = -ENOMEM; 827 result = -ENOMEM;
860 goto fail_workqueue; 828 goto fail_workqueue;
@@ -921,12 +889,14 @@ int ieee80211_register_hw(struct ieee80211_hw *hw)
921 889
922 local->mdev->select_queue = ieee80211_select_queue; 890 local->mdev->select_queue = ieee80211_select_queue;
923 891
924 /* add one default STA interface */ 892 /* add one default STA interface if supported */
925 result = ieee80211_if_add(local, "wlan%d", NULL, 893 if (local->hw.wiphy->interface_modes & BIT(NL80211_IFTYPE_STATION)) {
926 NL80211_IFTYPE_STATION, NULL); 894 result = ieee80211_if_add(local, "wlan%d", NULL,
927 if (result) 895 NL80211_IFTYPE_STATION, NULL);
928 printk(KERN_WARNING "%s: Failed to add default virtual iface\n", 896 if (result)
929 wiphy_name(local->hw.wiphy)); 897 printk(KERN_WARNING "%s: Failed to add default virtual iface\n",
898 wiphy_name(local->hw.wiphy));
899 }
930 900
931 rtnl_unlock(); 901 rtnl_unlock();
932 902
@@ -1013,7 +983,7 @@ static int __init ieee80211_init(void)
1013 983
1014 BUILD_BUG_ON(sizeof(struct ieee80211_tx_info) > sizeof(skb->cb)); 984 BUILD_BUG_ON(sizeof(struct ieee80211_tx_info) > sizeof(skb->cb));
1015 BUILD_BUG_ON(offsetof(struct ieee80211_tx_info, driver_data) + 985 BUILD_BUG_ON(offsetof(struct ieee80211_tx_info, driver_data) +
1016 IEEE80211_TX_INFO_DRIVER_DATA_SIZE > sizeof(skb->cb)); 986 IEEE80211_TX_INFO_DRIVER_DATA_SIZE > sizeof(skb->cb));
1017 987
1018 ret = rc80211_minstrel_init(); 988 ret = rc80211_minstrel_init();
1019 if (ret) 989 if (ret)
diff --git a/net/mac80211/mesh.c b/net/mac80211/mesh.c
index 8013277924f2..82f568e94365 100644
--- a/net/mac80211/mesh.c
+++ b/net/mac80211/mesh.c
@@ -238,7 +238,7 @@ void mesh_mgmt_ies_add(struct sk_buff *skb, struct ieee80211_sub_if_data *sdata)
238 238
239 pos = skb_put(skb, 21); 239 pos = skb_put(skb, 21);
240 *pos++ = WLAN_EID_MESH_CONFIG; 240 *pos++ = WLAN_EID_MESH_CONFIG;
241 *pos++ = MESH_CFG_LEN; 241 *pos++ = IEEE80211_MESH_CONFIG_LEN;
242 /* Version */ 242 /* Version */
243 *pos++ = 1; 243 *pos++ = 1;
244 244
@@ -473,7 +473,7 @@ static void ieee80211_mesh_rx_bcn_presp(struct ieee80211_sub_if_data *sdata,
473 size_t len, 473 size_t len,
474 struct ieee80211_rx_status *rx_status) 474 struct ieee80211_rx_status *rx_status)
475{ 475{
476 struct ieee80211_local *local= sdata->local; 476 struct ieee80211_local *local = sdata->local;
477 struct ieee802_11_elems elems; 477 struct ieee802_11_elems elems;
478 struct ieee80211_channel *channel; 478 struct ieee80211_channel *channel;
479 u64 supp_rates = 0; 479 u64 supp_rates = 0;
diff --git a/net/mac80211/mesh.h b/net/mac80211/mesh.h
index e10471c6ba42..c197ab545e54 100644
--- a/net/mac80211/mesh.h
+++ b/net/mac80211/mesh.h
@@ -145,9 +145,6 @@ struct mesh_rmc {
145}; 145};
146 146
147 147
148/* Mesh IEs constants */
149#define MESH_CFG_LEN 19
150
151/* 148/*
152 * MESH_CFG_COMP_LEN Includes: 149 * MESH_CFG_COMP_LEN Includes:
153 * - Active path selection protocol ID. 150 * - Active path selection protocol ID.
@@ -157,7 +154,7 @@ struct mesh_rmc {
157 * Does not include mesh capabilities, which may vary across nodes in the same 154 * Does not include mesh capabilities, which may vary across nodes in the same
158 * mesh 155 * mesh
159 */ 156 */
160#define MESH_CFG_CMP_LEN 17 157#define MESH_CFG_CMP_LEN (IEEE80211_MESH_CONFIG_LEN - 2)
161 158
162/* Default values, timeouts in ms */ 159/* Default values, timeouts in ms */
163#define MESH_TTL 5 160#define MESH_TTL 5
diff --git a/net/mac80211/mesh_hwmp.c b/net/mac80211/mesh_hwmp.c
index 501c7831adb4..71fe60961230 100644
--- a/net/mac80211/mesh_hwmp.c
+++ b/net/mac80211/mesh_hwmp.c
@@ -218,12 +218,16 @@ static u32 airtime_link_metric_get(struct ieee80211_local *local,
218 218
219 if (sta->fail_avg >= 100) 219 if (sta->fail_avg >= 100)
220 return MAX_METRIC; 220 return MAX_METRIC;
221
222 if (sta->last_tx_rate.flags & IEEE80211_TX_RC_MCS)
223 return MAX_METRIC;
224
221 err = (sta->fail_avg << ARITH_SHIFT) / 100; 225 err = (sta->fail_avg << ARITH_SHIFT) / 100;
222 226
223 /* bitrate is in units of 100 Kbps, while we need rate in units of 227 /* bitrate is in units of 100 Kbps, while we need rate in units of
224 * 1Mbps. This will be corrected on tx_time computation. 228 * 1Mbps. This will be corrected on tx_time computation.
225 */ 229 */
226 rate = sband->bitrates[sta->last_txrate_idx].bitrate; 230 rate = sband->bitrates[sta->last_tx_rate.idx].bitrate;
227 tx_time = (device_constant + 10 * test_frame_len / rate); 231 tx_time = (device_constant + 10 * test_frame_len / rate);
228 estimated_retx = ((1 << (2 * ARITH_SHIFT)) / (s_unit - err)); 232 estimated_retx = ((1 << (2 * ARITH_SHIFT)) / (s_unit - err));
229 result = (tx_time * estimated_retx) >> (2 * ARITH_SHIFT) ; 233 result = (tx_time * estimated_retx) >> (2 * ARITH_SHIFT) ;
@@ -759,7 +763,6 @@ enddiscovery:
759 * 763 *
760 * @skb: 802.11 frame to be sent 764 * @skb: 802.11 frame to be sent
761 * @sdata: network subif the frame will be sent through 765 * @sdata: network subif the frame will be sent through
762 * @fwd_frame: true if this frame was originally from a different host
763 * 766 *
764 * Returns: 0 if the next hop was found. Nonzero otherwise. If no next hop is 767 * Returns: 0 if the next hop was found. Nonzero otherwise. If no next hop is
765 * found, the function will start a path discovery and queue the frame so it is 768 * found, the function will start a path discovery and queue the frame so it is
diff --git a/net/mac80211/mesh_plink.c b/net/mac80211/mesh_plink.c
index faac101c0f85..929ba542fd72 100644
--- a/net/mac80211/mesh_plink.c
+++ b/net/mac80211/mesh_plink.c
@@ -257,9 +257,6 @@ static void mesh_plink_timer(unsigned long data)
257 struct sta_info *sta; 257 struct sta_info *sta;
258 __le16 llid, plid, reason; 258 __le16 llid, plid, reason;
259 struct ieee80211_sub_if_data *sdata; 259 struct ieee80211_sub_if_data *sdata;
260#ifdef CONFIG_MAC80211_VERBOSE_MPL_DEBUG
261 DECLARE_MAC_BUF(mac);
262#endif
263 260
264 /* 261 /*
265 * This STA is valid because sta_info_destroy() will 262 * This STA is valid because sta_info_destroy() will
@@ -274,8 +271,8 @@ static void mesh_plink_timer(unsigned long data)
274 spin_unlock_bh(&sta->lock); 271 spin_unlock_bh(&sta->lock);
275 return; 272 return;
276 } 273 }
277 mpl_dbg("Mesh plink timer for %s fired on state %d\n", 274 mpl_dbg("Mesh plink timer for %pM fired on state %d\n",
278 print_mac(mac, sta->sta.addr), sta->plink_state); 275 sta->sta.addr, sta->plink_state);
279 reason = 0; 276 reason = 0;
280 llid = sta->llid; 277 llid = sta->llid;
281 plid = sta->plid; 278 plid = sta->plid;
@@ -287,9 +284,9 @@ static void mesh_plink_timer(unsigned long data)
287 /* retry timer */ 284 /* retry timer */
288 if (sta->plink_retries < dot11MeshMaxRetries(sdata)) { 285 if (sta->plink_retries < dot11MeshMaxRetries(sdata)) {
289 u32 rand; 286 u32 rand;
290 mpl_dbg("Mesh plink for %s (retry, timeout): %d %d\n", 287 mpl_dbg("Mesh plink for %pM (retry, timeout): %d %d\n",
291 print_mac(mac, sta->sta.addr), 288 sta->sta.addr, sta->plink_retries,
292 sta->plink_retries, sta->plink_timeout); 289 sta->plink_timeout);
293 get_random_bytes(&rand, sizeof(u32)); 290 get_random_bytes(&rand, sizeof(u32));
294 sta->plink_timeout = sta->plink_timeout + 291 sta->plink_timeout = sta->plink_timeout +
295 rand % sta->plink_timeout; 292 rand % sta->plink_timeout;
@@ -337,9 +334,6 @@ int mesh_plink_open(struct sta_info *sta)
337{ 334{
338 __le16 llid; 335 __le16 llid;
339 struct ieee80211_sub_if_data *sdata = sta->sdata; 336 struct ieee80211_sub_if_data *sdata = sta->sdata;
340#ifdef CONFIG_MAC80211_VERBOSE_MPL_DEBUG
341 DECLARE_MAC_BUF(mac);
342#endif
343 337
344 spin_lock_bh(&sta->lock); 338 spin_lock_bh(&sta->lock);
345 get_random_bytes(&llid, 2); 339 get_random_bytes(&llid, 2);
@@ -351,8 +345,8 @@ int mesh_plink_open(struct sta_info *sta)
351 sta->plink_state = PLINK_OPN_SNT; 345 sta->plink_state = PLINK_OPN_SNT;
352 mesh_plink_timer_set(sta, dot11MeshRetryTimeout(sdata)); 346 mesh_plink_timer_set(sta, dot11MeshRetryTimeout(sdata));
353 spin_unlock_bh(&sta->lock); 347 spin_unlock_bh(&sta->lock);
354 mpl_dbg("Mesh plink: starting establishment with %s\n", 348 mpl_dbg("Mesh plink: starting establishment with %pM\n",
355 print_mac(mac, sta->sta.addr)); 349 sta->sta.addr);
356 350
357 return mesh_plink_frame_tx(sdata, PLINK_OPEN, 351 return mesh_plink_frame_tx(sdata, PLINK_OPEN,
358 sta->sta.addr, llid, 0, 0); 352 sta->sta.addr, llid, 0, 0);
@@ -360,10 +354,6 @@ int mesh_plink_open(struct sta_info *sta)
360 354
361void mesh_plink_block(struct sta_info *sta) 355void mesh_plink_block(struct sta_info *sta)
362{ 356{
363#ifdef CONFIG_MAC80211_VERBOSE_MPL_DEBUG
364 DECLARE_MAC_BUF(mac);
365#endif
366
367 spin_lock_bh(&sta->lock); 357 spin_lock_bh(&sta->lock);
368 __mesh_plink_deactivate(sta); 358 __mesh_plink_deactivate(sta);
369 sta->plink_state = PLINK_BLOCKED; 359 sta->plink_state = PLINK_BLOCKED;
@@ -374,12 +364,8 @@ int mesh_plink_close(struct sta_info *sta)
374{ 364{
375 struct ieee80211_sub_if_data *sdata = sta->sdata; 365 struct ieee80211_sub_if_data *sdata = sta->sdata;
376 __le16 llid, plid, reason; 366 __le16 llid, plid, reason;
377#ifdef CONFIG_MAC80211_VERBOSE_MPL_DEBUG
378 DECLARE_MAC_BUF(mac);
379#endif
380 367
381 mpl_dbg("Mesh plink: closing link with %s\n", 368 mpl_dbg("Mesh plink: closing link with %pM\n", sta->sta.addr);
382 print_mac(mac, sta->sta.addr));
383 spin_lock_bh(&sta->lock); 369 spin_lock_bh(&sta->lock);
384 sta->reason = cpu_to_le16(MESH_LINK_CANCELLED); 370 sta->reason = cpu_to_le16(MESH_LINK_CANCELLED);
385 reason = sta->reason; 371 reason = sta->reason;
@@ -417,9 +403,6 @@ void mesh_rx_plink_frame(struct ieee80211_sub_if_data *sdata, struct ieee80211_m
417 u8 ie_len; 403 u8 ie_len;
418 u8 *baseaddr; 404 u8 *baseaddr;
419 __le16 plid, llid, reason; 405 __le16 plid, llid, reason;
420#ifdef CONFIG_MAC80211_VERBOSE_MPL_DEBUG
421 DECLARE_MAC_BUF(mac);
422#endif
423 406
424 /* need action_code, aux */ 407 /* need action_code, aux */
425 if (len < IEEE80211_MIN_ACTION_SIZE + 3) 408 if (len < IEEE80211_MIN_ACTION_SIZE + 3)
@@ -557,10 +540,10 @@ void mesh_rx_plink_frame(struct ieee80211_sub_if_data *sdata, struct ieee80211_m
557 } 540 }
558 } 541 }
559 542
560 mpl_dbg("Mesh plink (peer, state, llid, plid, event): %s %d %d %d %d\n", 543 mpl_dbg("Mesh plink (peer, state, llid, plid, event): %pM %d %d %d %d\n",
561 print_mac(mac, mgmt->sa), sta->plink_state, 544 mgmt->sa, sta->plink_state,
562 le16_to_cpu(sta->llid), le16_to_cpu(sta->plid), 545 le16_to_cpu(sta->llid), le16_to_cpu(sta->plid),
563 event); 546 event);
564 reason = 0; 547 reason = 0;
565 switch (sta->plink_state) { 548 switch (sta->plink_state) {
566 /* spin_unlock as soon as state is updated at each case */ 549 /* spin_unlock as soon as state is updated at each case */
@@ -660,8 +643,8 @@ void mesh_rx_plink_frame(struct ieee80211_sub_if_data *sdata, struct ieee80211_m
660 sta->plink_state = PLINK_ESTAB; 643 sta->plink_state = PLINK_ESTAB;
661 mesh_plink_inc_estab_count(sdata); 644 mesh_plink_inc_estab_count(sdata);
662 spin_unlock_bh(&sta->lock); 645 spin_unlock_bh(&sta->lock);
663 mpl_dbg("Mesh plink with %s ESTABLISHED\n", 646 mpl_dbg("Mesh plink with %pM ESTABLISHED\n",
664 print_mac(mac, sta->sta.addr)); 647 sta->sta.addr);
665 break; 648 break;
666 default: 649 default:
667 spin_unlock_bh(&sta->lock); 650 spin_unlock_bh(&sta->lock);
@@ -693,8 +676,8 @@ void mesh_rx_plink_frame(struct ieee80211_sub_if_data *sdata, struct ieee80211_m
693 sta->plink_state = PLINK_ESTAB; 676 sta->plink_state = PLINK_ESTAB;
694 mesh_plink_inc_estab_count(sdata); 677 mesh_plink_inc_estab_count(sdata);
695 spin_unlock_bh(&sta->lock); 678 spin_unlock_bh(&sta->lock);
696 mpl_dbg("Mesh plink with %s ESTABLISHED\n", 679 mpl_dbg("Mesh plink with %pM ESTABLISHED\n",
697 print_mac(mac, sta->sta.addr)); 680 sta->sta.addr);
698 mesh_plink_frame_tx(sdata, PLINK_CONFIRM, sta->sta.addr, llid, 681 mesh_plink_frame_tx(sdata, PLINK_CONFIRM, sta->sta.addr, llid,
699 plid, 0); 682 plid, 0);
700 break; 683 break;
diff --git a/net/mac80211/mlme.c b/net/mac80211/mlme.c
index 409bb7716236..5ba721b6a399 100644
--- a/net/mac80211/mlme.c
+++ b/net/mac80211/mlme.c
@@ -14,7 +14,6 @@
14#include <linux/delay.h> 14#include <linux/delay.h>
15#include <linux/if_ether.h> 15#include <linux/if_ether.h>
16#include <linux/skbuff.h> 16#include <linux/skbuff.h>
17#include <linux/netdevice.h>
18#include <linux/if_arp.h> 17#include <linux/if_arp.h>
19#include <linux/wireless.h> 18#include <linux/wireless.h>
20#include <linux/random.h> 19#include <linux/random.h>
@@ -236,7 +235,7 @@ static void ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata,
236 struct ieee80211_local *local = sdata->local; 235 struct ieee80211_local *local = sdata->local;
237 struct sk_buff *skb; 236 struct sk_buff *skb;
238 struct ieee80211_mgmt *mgmt; 237 struct ieee80211_mgmt *mgmt;
239 u8 *pos, *ies, *ht_add_ie; 238 u8 *pos, *ies, *ht_ie;
240 int i, len, count, rates_len, supp_rates_len; 239 int i, len, count, rates_len, supp_rates_len;
241 u16 capab; 240 u16 capab;
242 struct ieee80211_bss *bss; 241 struct ieee80211_bss *bss;
@@ -310,7 +309,7 @@ static void ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata,
310 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | 309 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
311 IEEE80211_STYPE_ASSOC_REQ); 310 IEEE80211_STYPE_ASSOC_REQ);
312 mgmt->u.assoc_req.capab_info = cpu_to_le16(capab); 311 mgmt->u.assoc_req.capab_info = cpu_to_le16(capab);
313 mgmt->u.reassoc_req.listen_interval = 312 mgmt->u.assoc_req.listen_interval =
314 cpu_to_le16(local->hw.conf.listen_interval); 313 cpu_to_le16(local->hw.conf.listen_interval);
315 } 314 }
316 315
@@ -393,24 +392,25 @@ static void ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata,
393 392
394 /* wmm support is a must to HT */ 393 /* wmm support is a must to HT */
395 if (wmm && (ifsta->flags & IEEE80211_STA_WMM_ENABLED) && 394 if (wmm && (ifsta->flags & IEEE80211_STA_WMM_ENABLED) &&
396 sband->ht_info.ht_supported && 395 sband->ht_cap.ht_supported &&
397 (ht_add_ie = ieee80211_bss_get_ie(bss, WLAN_EID_HT_EXTRA_INFO))) { 396 (ht_ie = ieee80211_bss_get_ie(bss, WLAN_EID_HT_INFORMATION)) &&
398 struct ieee80211_ht_addt_info *ht_add_info = 397 ht_ie[1] >= sizeof(struct ieee80211_ht_info)) {
399 (struct ieee80211_ht_addt_info *)ht_add_ie; 398 struct ieee80211_ht_info *ht_info =
400 u16 cap = sband->ht_info.cap; 399 (struct ieee80211_ht_info *)(ht_ie + 2);
400 u16 cap = sband->ht_cap.cap;
401 __le16 tmp; 401 __le16 tmp;
402 u32 flags = local->hw.conf.channel->flags; 402 u32 flags = local->hw.conf.channel->flags;
403 403
404 switch (ht_add_info->ht_param & IEEE80211_HT_IE_CHA_SEC_OFFSET) { 404 switch (ht_info->ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) {
405 case IEEE80211_HT_IE_CHA_SEC_ABOVE: 405 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
406 if (flags & IEEE80211_CHAN_NO_FAT_ABOVE) { 406 if (flags & IEEE80211_CHAN_NO_FAT_ABOVE) {
407 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH; 407 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
408 cap &= ~IEEE80211_HT_CAP_SGI_40; 408 cap &= ~IEEE80211_HT_CAP_SGI_40;
409 } 409 }
410 break; 410 break;
411 case IEEE80211_HT_IE_CHA_SEC_BELOW: 411 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
412 if (flags & IEEE80211_CHAN_NO_FAT_BELOW) { 412 if (flags & IEEE80211_CHAN_NO_FAT_BELOW) {
413 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH; 413 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
414 cap &= ~IEEE80211_HT_CAP_SGI_40; 414 cap &= ~IEEE80211_HT_CAP_SGI_40;
415 } 415 }
416 break; 416 break;
@@ -424,9 +424,9 @@ static void ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata,
424 memcpy(pos, &tmp, sizeof(u16)); 424 memcpy(pos, &tmp, sizeof(u16));
425 pos += sizeof(u16); 425 pos += sizeof(u16);
426 /* TODO: needs a define here for << 2 */ 426 /* TODO: needs a define here for << 2 */
427 *pos++ = sband->ht_info.ampdu_factor | 427 *pos++ = sband->ht_cap.ampdu_factor |
428 (sband->ht_info.ampdu_density << 2); 428 (sband->ht_cap.ampdu_density << 2);
429 memcpy(pos, sband->ht_info.supp_mcs_set, 16); 429 memcpy(pos, &sband->ht_cap.mcs, sizeof(sband->ht_cap.mcs));
430 } 430 }
431 431
432 kfree(ifsta->assocreq_ies); 432 kfree(ifsta->assocreq_ies);
@@ -568,25 +568,35 @@ static void ieee80211_sta_wmm_params(struct ieee80211_local *local,
568 } 568 }
569} 569}
570 570
571static u32 ieee80211_handle_protect_preamb(struct ieee80211_sub_if_data *sdata, 571static u32 ieee80211_handle_bss_capability(struct ieee80211_sub_if_data *sdata,
572 bool use_protection, 572 u16 capab, bool erp_valid, u8 erp)
573 bool use_short_preamble)
574{ 573{
575 struct ieee80211_bss_conf *bss_conf = &sdata->bss_conf; 574 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
576#ifdef CONFIG_MAC80211_VERBOSE_DEBUG 575#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
577 struct ieee80211_if_sta *ifsta = &sdata->u.sta; 576 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
578 DECLARE_MAC_BUF(mac);
579#endif 577#endif
580 u32 changed = 0; 578 u32 changed = 0;
579 bool use_protection;
580 bool use_short_preamble;
581 bool use_short_slot;
582
583 if (erp_valid) {
584 use_protection = (erp & WLAN_ERP_USE_PROTECTION) != 0;
585 use_short_preamble = (erp & WLAN_ERP_BARKER_PREAMBLE) == 0;
586 } else {
587 use_protection = false;
588 use_short_preamble = !!(capab & WLAN_CAPABILITY_SHORT_PREAMBLE);
589 }
590
591 use_short_slot = !!(capab & WLAN_CAPABILITY_SHORT_SLOT_TIME);
581 592
582 if (use_protection != bss_conf->use_cts_prot) { 593 if (use_protection != bss_conf->use_cts_prot) {
583#ifdef CONFIG_MAC80211_VERBOSE_DEBUG 594#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
584 if (net_ratelimit()) { 595 if (net_ratelimit()) {
585 printk(KERN_DEBUG "%s: CTS protection %s (BSSID=" 596 printk(KERN_DEBUG "%s: CTS protection %s (BSSID=%pM)\n",
586 "%s)\n",
587 sdata->dev->name, 597 sdata->dev->name,
588 use_protection ? "enabled" : "disabled", 598 use_protection ? "enabled" : "disabled",
589 print_mac(mac, ifsta->bssid)); 599 ifsta->bssid);
590 } 600 }
591#endif 601#endif
592 bss_conf->use_cts_prot = use_protection; 602 bss_conf->use_cts_prot = use_protection;
@@ -597,40 +607,28 @@ static u32 ieee80211_handle_protect_preamb(struct ieee80211_sub_if_data *sdata,
597#ifdef CONFIG_MAC80211_VERBOSE_DEBUG 607#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
598 if (net_ratelimit()) { 608 if (net_ratelimit()) {
599 printk(KERN_DEBUG "%s: switched to %s barker preamble" 609 printk(KERN_DEBUG "%s: switched to %s barker preamble"
600 " (BSSID=%s)\n", 610 " (BSSID=%pM)\n",
601 sdata->dev->name, 611 sdata->dev->name,
602 use_short_preamble ? "short" : "long", 612 use_short_preamble ? "short" : "long",
603 print_mac(mac, ifsta->bssid)); 613 ifsta->bssid);
604 } 614 }
605#endif 615#endif
606 bss_conf->use_short_preamble = use_short_preamble; 616 bss_conf->use_short_preamble = use_short_preamble;
607 changed |= BSS_CHANGED_ERP_PREAMBLE; 617 changed |= BSS_CHANGED_ERP_PREAMBLE;
608 } 618 }
609 619
610 return changed; 620 if (use_short_slot != bss_conf->use_short_slot) {
611} 621#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
612 622 if (net_ratelimit()) {
613static u32 ieee80211_handle_erp_ie(struct ieee80211_sub_if_data *sdata, 623 printk(KERN_DEBUG "%s: switched to %s slot"
614 u8 erp_value) 624 " (BSSID=%s)\n",
615{ 625 sdata->dev->name,
616 bool use_protection = (erp_value & WLAN_ERP_USE_PROTECTION) != 0; 626 use_short_slot ? "short" : "long",
617 bool use_short_preamble = (erp_value & WLAN_ERP_BARKER_PREAMBLE) == 0; 627 ifsta->bssid);
618 628 }
619 return ieee80211_handle_protect_preamb(sdata, 629#endif
620 use_protection, use_short_preamble); 630 bss_conf->use_short_slot = use_short_slot;
621} 631 changed |= BSS_CHANGED_ERP_SLOT;
622
623static u32 ieee80211_handle_bss_capability(struct ieee80211_sub_if_data *sdata,
624 struct ieee80211_bss *bss)
625{
626 u32 changed = 0;
627
628 if (bss->has_erp_value)
629 changed |= ieee80211_handle_erp_ie(sdata, bss->erp_value);
630 else {
631 u16 capab = bss->capability;
632 changed |= ieee80211_handle_protect_preamb(sdata, false,
633 (capab & WLAN_CAPABILITY_SHORT_PREAMBLE) != 0);
634 } 632 }
635 633
636 return changed; 634 return changed;
@@ -701,14 +699,15 @@ static void ieee80211_sta_send_associnfo(struct ieee80211_sub_if_data *sdata,
701 699
702 700
703static void ieee80211_set_associated(struct ieee80211_sub_if_data *sdata, 701static void ieee80211_set_associated(struct ieee80211_sub_if_data *sdata,
704 struct ieee80211_if_sta *ifsta) 702 struct ieee80211_if_sta *ifsta,
703 u32 bss_info_changed)
705{ 704{
706 struct ieee80211_local *local = sdata->local; 705 struct ieee80211_local *local = sdata->local;
707 struct ieee80211_conf *conf = &local_to_hw(local)->conf; 706 struct ieee80211_conf *conf = &local_to_hw(local)->conf;
708 u32 changed = BSS_CHANGED_ASSOC;
709 707
710 struct ieee80211_bss *bss; 708 struct ieee80211_bss *bss;
711 709
710 bss_info_changed |= BSS_CHANGED_ASSOC;
712 ifsta->flags |= IEEE80211_STA_ASSOCIATED; 711 ifsta->flags |= IEEE80211_STA_ASSOCIATED;
713 712
714 if (sdata->vif.type != NL80211_IFTYPE_STATION) 713 if (sdata->vif.type != NL80211_IFTYPE_STATION)
@@ -719,22 +718,16 @@ static void ieee80211_set_associated(struct ieee80211_sub_if_data *sdata,
719 ifsta->ssid, ifsta->ssid_len); 718 ifsta->ssid, ifsta->ssid_len);
720 if (bss) { 719 if (bss) {
721 /* set timing information */ 720 /* set timing information */
722 sdata->bss_conf.beacon_int = bss->beacon_int; 721 sdata->vif.bss_conf.beacon_int = bss->beacon_int;
723 sdata->bss_conf.timestamp = bss->timestamp; 722 sdata->vif.bss_conf.timestamp = bss->timestamp;
724 sdata->bss_conf.dtim_period = bss->dtim_period; 723 sdata->vif.bss_conf.dtim_period = bss->dtim_period;
725 724
726 changed |= ieee80211_handle_bss_capability(sdata, bss); 725 bss_info_changed |= ieee80211_handle_bss_capability(sdata,
726 bss->capability, bss->has_erp_value, bss->erp_value);
727 727
728 ieee80211_rx_bss_put(local, bss); 728 ieee80211_rx_bss_put(local, bss);
729 } 729 }
730 730
731 if (conf->flags & IEEE80211_CONF_SUPPORT_HT_MODE) {
732 changed |= BSS_CHANGED_HT;
733 sdata->bss_conf.assoc_ht = 1;
734 sdata->bss_conf.ht_conf = &conf->ht_conf;
735 sdata->bss_conf.ht_bss_conf = &conf->ht_bss_conf;
736 }
737
738 ifsta->flags |= IEEE80211_STA_PREV_BSSID_SET; 731 ifsta->flags |= IEEE80211_STA_PREV_BSSID_SET;
739 memcpy(ifsta->prev_bssid, sdata->u.sta.bssid, ETH_ALEN); 732 memcpy(ifsta->prev_bssid, sdata->u.sta.bssid, ETH_ALEN);
740 ieee80211_sta_send_associnfo(sdata, ifsta); 733 ieee80211_sta_send_associnfo(sdata, ifsta);
@@ -742,14 +735,25 @@ static void ieee80211_set_associated(struct ieee80211_sub_if_data *sdata,
742 ifsta->last_probe = jiffies; 735 ifsta->last_probe = jiffies;
743 ieee80211_led_assoc(local, 1); 736 ieee80211_led_assoc(local, 1);
744 737
745 sdata->bss_conf.assoc = 1; 738 sdata->vif.bss_conf.assoc = 1;
746 /* 739 /*
747 * For now just always ask the driver to update the basic rateset 740 * For now just always ask the driver to update the basic rateset
748 * when we have associated, we aren't checking whether it actually 741 * when we have associated, we aren't checking whether it actually
749 * changed or not. 742 * changed or not.
750 */ 743 */
751 changed |= BSS_CHANGED_BASIC_RATES; 744 bss_info_changed |= BSS_CHANGED_BASIC_RATES;
752 ieee80211_bss_info_change_notify(sdata, changed); 745 ieee80211_bss_info_change_notify(sdata, bss_info_changed);
746
747 if (local->powersave) {
748 if (local->dynamic_ps_timeout > 0)
749 mod_timer(&local->dynamic_ps_timer, jiffies +
750 msecs_to_jiffies(local->dynamic_ps_timeout));
751 else {
752 conf->flags |= IEEE80211_CONF_PS;
753 ieee80211_hw_config(local,
754 IEEE80211_CONF_CHANGE_PS);
755 }
756 }
753 757
754 netif_tx_start_all_queues(sdata->dev); 758 netif_tx_start_all_queues(sdata->dev);
755 netif_carrier_on(sdata->dev); 759 netif_carrier_on(sdata->dev);
@@ -760,18 +764,17 @@ static void ieee80211_set_associated(struct ieee80211_sub_if_data *sdata,
760static void ieee80211_direct_probe(struct ieee80211_sub_if_data *sdata, 764static void ieee80211_direct_probe(struct ieee80211_sub_if_data *sdata,
761 struct ieee80211_if_sta *ifsta) 765 struct ieee80211_if_sta *ifsta)
762{ 766{
763 DECLARE_MAC_BUF(mac);
764
765 ifsta->direct_probe_tries++; 767 ifsta->direct_probe_tries++;
766 if (ifsta->direct_probe_tries > IEEE80211_AUTH_MAX_TRIES) { 768 if (ifsta->direct_probe_tries > IEEE80211_AUTH_MAX_TRIES) {
767 printk(KERN_DEBUG "%s: direct probe to AP %s timed out\n", 769 printk(KERN_DEBUG "%s: direct probe to AP %pM timed out\n",
768 sdata->dev->name, print_mac(mac, ifsta->bssid)); 770 sdata->dev->name, ifsta->bssid);
769 ifsta->state = IEEE80211_STA_MLME_DISABLED; 771 ifsta->state = IEEE80211_STA_MLME_DISABLED;
772 ieee80211_sta_send_apinfo(sdata, ifsta);
770 return; 773 return;
771 } 774 }
772 775
773 printk(KERN_DEBUG "%s: direct probe to AP %s try %d\n", 776 printk(KERN_DEBUG "%s: direct probe to AP %pM try %d\n",
774 sdata->dev->name, print_mac(mac, ifsta->bssid), 777 sdata->dev->name, ifsta->bssid,
775 ifsta->direct_probe_tries); 778 ifsta->direct_probe_tries);
776 779
777 ifsta->state = IEEE80211_STA_MLME_DIRECT_PROBE; 780 ifsta->state = IEEE80211_STA_MLME_DIRECT_PROBE;
@@ -791,33 +794,36 @@ static void ieee80211_direct_probe(struct ieee80211_sub_if_data *sdata,
791static void ieee80211_authenticate(struct ieee80211_sub_if_data *sdata, 794static void ieee80211_authenticate(struct ieee80211_sub_if_data *sdata,
792 struct ieee80211_if_sta *ifsta) 795 struct ieee80211_if_sta *ifsta)
793{ 796{
794 DECLARE_MAC_BUF(mac);
795
796 ifsta->auth_tries++; 797 ifsta->auth_tries++;
797 if (ifsta->auth_tries > IEEE80211_AUTH_MAX_TRIES) { 798 if (ifsta->auth_tries > IEEE80211_AUTH_MAX_TRIES) {
798 printk(KERN_DEBUG "%s: authentication with AP %s" 799 printk(KERN_DEBUG "%s: authentication with AP %pM"
799 " timed out\n", 800 " timed out\n",
800 sdata->dev->name, print_mac(mac, ifsta->bssid)); 801 sdata->dev->name, ifsta->bssid);
801 ifsta->state = IEEE80211_STA_MLME_DISABLED; 802 ifsta->state = IEEE80211_STA_MLME_DISABLED;
803 ieee80211_sta_send_apinfo(sdata, ifsta);
802 return; 804 return;
803 } 805 }
804 806
805 ifsta->state = IEEE80211_STA_MLME_AUTHENTICATE; 807 ifsta->state = IEEE80211_STA_MLME_AUTHENTICATE;
806 printk(KERN_DEBUG "%s: authenticate with AP %s\n", 808 printk(KERN_DEBUG "%s: authenticate with AP %pM\n",
807 sdata->dev->name, print_mac(mac, ifsta->bssid)); 809 sdata->dev->name, ifsta->bssid);
808 810
809 ieee80211_send_auth(sdata, ifsta, 1, NULL, 0, 0); 811 ieee80211_send_auth(sdata, ifsta, 1, NULL, 0, 0);
810 812
811 mod_timer(&ifsta->timer, jiffies + IEEE80211_AUTH_TIMEOUT); 813 mod_timer(&ifsta->timer, jiffies + IEEE80211_AUTH_TIMEOUT);
812} 814}
813 815
816/*
817 * The disassoc 'reason' argument can be either our own reason
818 * if self disconnected or a reason code from the AP.
819 */
814static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata, 820static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata,
815 struct ieee80211_if_sta *ifsta, bool deauth, 821 struct ieee80211_if_sta *ifsta, bool deauth,
816 bool self_disconnected, u16 reason) 822 bool self_disconnected, u16 reason)
817{ 823{
818 struct ieee80211_local *local = sdata->local; 824 struct ieee80211_local *local = sdata->local;
819 struct sta_info *sta; 825 struct sta_info *sta;
820 u32 changed = BSS_CHANGED_ASSOC; 826 u32 changed = 0, config_changed = 0;
821 827
822 rcu_read_lock(); 828 rcu_read_lock();
823 829
@@ -851,21 +857,40 @@ static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata,
851 ifsta->flags &= ~IEEE80211_STA_ASSOCIATED; 857 ifsta->flags &= ~IEEE80211_STA_ASSOCIATED;
852 changed |= ieee80211_reset_erp_info(sdata); 858 changed |= ieee80211_reset_erp_info(sdata);
853 859
854 if (sdata->bss_conf.assoc_ht)
855 changed |= BSS_CHANGED_HT;
856
857 sdata->bss_conf.assoc_ht = 0;
858 sdata->bss_conf.ht_conf = NULL;
859 sdata->bss_conf.ht_bss_conf = NULL;
860
861 ieee80211_led_assoc(local, 0); 860 ieee80211_led_assoc(local, 0);
862 sdata->bss_conf.assoc = 0; 861 changed |= BSS_CHANGED_ASSOC;
862 sdata->vif.bss_conf.assoc = false;
863 863
864 ieee80211_sta_send_apinfo(sdata, ifsta); 864 ieee80211_sta_send_apinfo(sdata, ifsta);
865 865
866 if (self_disconnected) 866 if (self_disconnected || reason == WLAN_REASON_DISASSOC_STA_HAS_LEFT)
867 ifsta->state = IEEE80211_STA_MLME_DISABLED; 867 ifsta->state = IEEE80211_STA_MLME_DISABLED;
868 868
869 rcu_read_unlock();
870
871 local->hw.conf.ht.enabled = false;
872 local->oper_channel_type = NL80211_CHAN_NO_HT;
873 config_changed |= IEEE80211_CONF_CHANGE_HT;
874
875 del_timer_sync(&local->dynamic_ps_timer);
876 cancel_work_sync(&local->dynamic_ps_enable_work);
877
878 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
879 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
880 config_changed |= IEEE80211_CONF_CHANGE_PS;
881 }
882
883 ieee80211_hw_config(local, config_changed);
884 ieee80211_bss_info_change_notify(sdata, changed);
885
886 rcu_read_lock();
887
888 sta = sta_info_get(local, ifsta->bssid);
889 if (!sta) {
890 rcu_read_unlock();
891 return;
892 }
893
869 sta_info_unlink(&sta); 894 sta_info_unlink(&sta);
870 895
871 rcu_read_unlock(); 896 rcu_read_unlock();
@@ -914,20 +939,19 @@ static int ieee80211_privacy_mismatch(struct ieee80211_sub_if_data *sdata,
914static void ieee80211_associate(struct ieee80211_sub_if_data *sdata, 939static void ieee80211_associate(struct ieee80211_sub_if_data *sdata,
915 struct ieee80211_if_sta *ifsta) 940 struct ieee80211_if_sta *ifsta)
916{ 941{
917 DECLARE_MAC_BUF(mac);
918
919 ifsta->assoc_tries++; 942 ifsta->assoc_tries++;
920 if (ifsta->assoc_tries > IEEE80211_ASSOC_MAX_TRIES) { 943 if (ifsta->assoc_tries > IEEE80211_ASSOC_MAX_TRIES) {
921 printk(KERN_DEBUG "%s: association with AP %s" 944 printk(KERN_DEBUG "%s: association with AP %pM"
922 " timed out\n", 945 " timed out\n",
923 sdata->dev->name, print_mac(mac, ifsta->bssid)); 946 sdata->dev->name, ifsta->bssid);
924 ifsta->state = IEEE80211_STA_MLME_DISABLED; 947 ifsta->state = IEEE80211_STA_MLME_DISABLED;
948 ieee80211_sta_send_apinfo(sdata, ifsta);
925 return; 949 return;
926 } 950 }
927 951
928 ifsta->state = IEEE80211_STA_MLME_ASSOCIATE; 952 ifsta->state = IEEE80211_STA_MLME_ASSOCIATE;
929 printk(KERN_DEBUG "%s: associate with AP %s\n", 953 printk(KERN_DEBUG "%s: associate with AP %pM\n",
930 sdata->dev->name, print_mac(mac, ifsta->bssid)); 954 sdata->dev->name, ifsta->bssid);
931 if (ieee80211_privacy_mismatch(sdata, ifsta)) { 955 if (ieee80211_privacy_mismatch(sdata, ifsta)) {
932 printk(KERN_DEBUG "%s: mismatch in privacy configuration and " 956 printk(KERN_DEBUG "%s: mismatch in privacy configuration and "
933 "mixed-cell disabled - abort association\n", sdata->dev->name); 957 "mixed-cell disabled - abort association\n", sdata->dev->name);
@@ -947,7 +971,6 @@ static void ieee80211_associated(struct ieee80211_sub_if_data *sdata,
947 struct ieee80211_local *local = sdata->local; 971 struct ieee80211_local *local = sdata->local;
948 struct sta_info *sta; 972 struct sta_info *sta;
949 int disassoc; 973 int disassoc;
950 DECLARE_MAC_BUF(mac);
951 974
952 /* TODO: start monitoring current AP signal quality and number of 975 /* TODO: start monitoring current AP signal quality and number of
953 * missed beacons. Scan other channels every now and then and search 976 * missed beacons. Scan other channels every now and then and search
@@ -960,8 +983,8 @@ static void ieee80211_associated(struct ieee80211_sub_if_data *sdata,
960 983
961 sta = sta_info_get(local, ifsta->bssid); 984 sta = sta_info_get(local, ifsta->bssid);
962 if (!sta) { 985 if (!sta) {
963 printk(KERN_DEBUG "%s: No STA entry for own AP %s\n", 986 printk(KERN_DEBUG "%s: No STA entry for own AP %pM\n",
964 sdata->dev->name, print_mac(mac, ifsta->bssid)); 987 sdata->dev->name, ifsta->bssid);
965 disassoc = 1; 988 disassoc = 1;
966 } else { 989 } else {
967 disassoc = 0; 990 disassoc = 0;
@@ -969,9 +992,9 @@ static void ieee80211_associated(struct ieee80211_sub_if_data *sdata,
969 sta->last_rx + IEEE80211_MONITORING_INTERVAL)) { 992 sta->last_rx + IEEE80211_MONITORING_INTERVAL)) {
970 if (ifsta->flags & IEEE80211_STA_PROBEREQ_POLL) { 993 if (ifsta->flags & IEEE80211_STA_PROBEREQ_POLL) {
971 printk(KERN_DEBUG "%s: No ProbeResp from " 994 printk(KERN_DEBUG "%s: No ProbeResp from "
972 "current AP %s - assume out of " 995 "current AP %pM - assume out of "
973 "range\n", 996 "range\n",
974 sdata->dev->name, print_mac(mac, ifsta->bssid)); 997 sdata->dev->name, ifsta->bssid);
975 disassoc = 1; 998 disassoc = 1;
976 } else 999 } else
977 ieee80211_send_probe_req(sdata, ifsta->bssid, 1000 ieee80211_send_probe_req(sdata, ifsta->bssid,
@@ -1032,7 +1055,6 @@ static void ieee80211_rx_mgmt_auth(struct ieee80211_sub_if_data *sdata,
1032 size_t len) 1055 size_t len)
1033{ 1056{
1034 u16 auth_alg, auth_transaction, status_code; 1057 u16 auth_alg, auth_transaction, status_code;
1035 DECLARE_MAC_BUF(mac);
1036 1058
1037 if (ifsta->state != IEEE80211_STA_MLME_AUTHENTICATE && 1059 if (ifsta->state != IEEE80211_STA_MLME_AUTHENTICATE &&
1038 sdata->vif.type != NL80211_IFTYPE_ADHOC) 1060 sdata->vif.type != NL80211_IFTYPE_ADHOC)
@@ -1125,7 +1147,6 @@ static void ieee80211_rx_mgmt_deauth(struct ieee80211_sub_if_data *sdata,
1125 size_t len) 1147 size_t len)
1126{ 1148{
1127 u16 reason_code; 1149 u16 reason_code;
1128 DECLARE_MAC_BUF(mac);
1129 1150
1130 if (len < 24 + 2) 1151 if (len < 24 + 2)
1131 return; 1152 return;
@@ -1136,7 +1157,8 @@ static void ieee80211_rx_mgmt_deauth(struct ieee80211_sub_if_data *sdata,
1136 reason_code = le16_to_cpu(mgmt->u.deauth.reason_code); 1157 reason_code = le16_to_cpu(mgmt->u.deauth.reason_code);
1137 1158
1138 if (ifsta->flags & IEEE80211_STA_AUTHENTICATED) 1159 if (ifsta->flags & IEEE80211_STA_AUTHENTICATED)
1139 printk(KERN_DEBUG "%s: deauthenticated\n", sdata->dev->name); 1160 printk(KERN_DEBUG "%s: deauthenticated (Reason: %u)\n",
1161 sdata->dev->name, reason_code);
1140 1162
1141 if (ifsta->state == IEEE80211_STA_MLME_AUTHENTICATE || 1163 if (ifsta->state == IEEE80211_STA_MLME_AUTHENTICATE ||
1142 ifsta->state == IEEE80211_STA_MLME_ASSOCIATE || 1164 ifsta->state == IEEE80211_STA_MLME_ASSOCIATE ||
@@ -1157,7 +1179,6 @@ static void ieee80211_rx_mgmt_disassoc(struct ieee80211_sub_if_data *sdata,
1157 size_t len) 1179 size_t len)
1158{ 1180{
1159 u16 reason_code; 1181 u16 reason_code;
1160 DECLARE_MAC_BUF(mac);
1161 1182
1162 if (len < 24 + 2) 1183 if (len < 24 + 2)
1163 return; 1184 return;
@@ -1168,7 +1189,8 @@ static void ieee80211_rx_mgmt_disassoc(struct ieee80211_sub_if_data *sdata,
1168 reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code); 1189 reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code);
1169 1190
1170 if (ifsta->flags & IEEE80211_STA_ASSOCIATED) 1191 if (ifsta->flags & IEEE80211_STA_ASSOCIATED)
1171 printk(KERN_DEBUG "%s: disassociated\n", sdata->dev->name); 1192 printk(KERN_DEBUG "%s: disassociated (Reason: %u)\n",
1193 sdata->dev->name, reason_code);
1172 1194
1173 if (ifsta->state == IEEE80211_STA_MLME_ASSOCIATED) { 1195 if (ifsta->state == IEEE80211_STA_MLME_ASSOCIATED) {
1174 ifsta->state = IEEE80211_STA_MLME_ASSOCIATE; 1196 ifsta->state = IEEE80211_STA_MLME_ASSOCIATE;
@@ -1176,7 +1198,7 @@ static void ieee80211_rx_mgmt_disassoc(struct ieee80211_sub_if_data *sdata,
1176 IEEE80211_RETRY_AUTH_INTERVAL); 1198 IEEE80211_RETRY_AUTH_INTERVAL);
1177 } 1199 }
1178 1200
1179 ieee80211_set_disassoc(sdata, ifsta, false, false, 0); 1201 ieee80211_set_disassoc(sdata, ifsta, false, false, reason_code);
1180} 1202}
1181 1203
1182 1204
@@ -1192,11 +1214,12 @@ static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
1192 u64 rates, basic_rates; 1214 u64 rates, basic_rates;
1193 u16 capab_info, status_code, aid; 1215 u16 capab_info, status_code, aid;
1194 struct ieee802_11_elems elems; 1216 struct ieee802_11_elems elems;
1195 struct ieee80211_bss_conf *bss_conf = &sdata->bss_conf; 1217 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
1196 u8 *pos; 1218 u8 *pos;
1219 u32 changed = 0;
1197 int i, j; 1220 int i, j;
1198 DECLARE_MAC_BUF(mac); 1221 bool have_higher_than_11mbit = false, newsta = false;
1199 bool have_higher_than_11mbit = false; 1222 u16 ap_ht_cap_flags;
1200 1223
1201 /* AssocResp and ReassocResp have identical structure, so process both 1224 /* AssocResp and ReassocResp have identical structure, so process both
1202 * of them in this function. */ 1225 * of them in this function. */
@@ -1214,9 +1237,9 @@ static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
1214 status_code = le16_to_cpu(mgmt->u.assoc_resp.status_code); 1237 status_code = le16_to_cpu(mgmt->u.assoc_resp.status_code);
1215 aid = le16_to_cpu(mgmt->u.assoc_resp.aid); 1238 aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
1216 1239
1217 printk(KERN_DEBUG "%s: RX %sssocResp from %s (capab=0x%x " 1240 printk(KERN_DEBUG "%s: RX %sssocResp from %pM (capab=0x%x "
1218 "status=%d aid=%d)\n", 1241 "status=%d aid=%d)\n",
1219 sdata->dev->name, reassoc ? "Rea" : "A", print_mac(mac, mgmt->sa), 1242 sdata->dev->name, reassoc ? "Rea" : "A", mgmt->sa,
1220 capab_info, status_code, (u16)(aid & ~(BIT(15) | BIT(14)))); 1243 capab_info, status_code, (u16)(aid & ~(BIT(15) | BIT(14))));
1221 1244
1222 if (status_code != WLAN_STATUS_SUCCESS) { 1245 if (status_code != WLAN_STATUS_SUCCESS) {
@@ -1259,7 +1282,8 @@ static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
1259 sta = sta_info_get(local, ifsta->bssid); 1282 sta = sta_info_get(local, ifsta->bssid);
1260 if (!sta) { 1283 if (!sta) {
1261 struct ieee80211_bss *bss; 1284 struct ieee80211_bss *bss;
1262 int err; 1285
1286 newsta = true;
1263 1287
1264 sta = sta_info_alloc(sdata, ifsta->bssid, GFP_ATOMIC); 1288 sta = sta_info_alloc(sdata, ifsta->bssid, GFP_ATOMIC);
1265 if (!sta) { 1289 if (!sta) {
@@ -1278,13 +1302,6 @@ static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
1278 ieee80211_rx_bss_put(local, bss); 1302 ieee80211_rx_bss_put(local, bss);
1279 } 1303 }
1280 1304
1281 err = sta_info_insert(sta);
1282 if (err) {
1283 printk(KERN_DEBUG "%s: failed to insert STA entry for"
1284 " the AP (error %d)\n", sdata->dev->name, err);
1285 rcu_read_unlock();
1286 return;
1287 }
1288 /* update new sta with its last rx activity */ 1305 /* update new sta with its last rx activity */
1289 sta->last_rx = jiffies; 1306 sta->last_rx = jiffies;
1290 } 1307 }
@@ -1308,34 +1325,40 @@ static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
1308 1325
1309 for (i = 0; i < elems.supp_rates_len; i++) { 1326 for (i = 0; i < elems.supp_rates_len; i++) {
1310 int rate = (elems.supp_rates[i] & 0x7f) * 5; 1327 int rate = (elems.supp_rates[i] & 0x7f) * 5;
1328 bool is_basic = !!(elems.supp_rates[i] & 0x80);
1311 1329
1312 if (rate > 110) 1330 if (rate > 110)
1313 have_higher_than_11mbit = true; 1331 have_higher_than_11mbit = true;
1314 1332
1315 for (j = 0; j < sband->n_bitrates; j++) { 1333 for (j = 0; j < sband->n_bitrates; j++) {
1316 if (sband->bitrates[j].bitrate == rate) 1334 if (sband->bitrates[j].bitrate == rate) {
1317 rates |= BIT(j); 1335 rates |= BIT(j);
1318 if (elems.supp_rates[i] & 0x80) 1336 if (is_basic)
1319 basic_rates |= BIT(j); 1337 basic_rates |= BIT(j);
1338 break;
1339 }
1320 } 1340 }
1321 } 1341 }
1322 1342
1323 for (i = 0; i < elems.ext_supp_rates_len; i++) { 1343 for (i = 0; i < elems.ext_supp_rates_len; i++) {
1324 int rate = (elems.ext_supp_rates[i] & 0x7f) * 5; 1344 int rate = (elems.ext_supp_rates[i] & 0x7f) * 5;
1345 bool is_basic = !!(elems.supp_rates[i] & 0x80);
1325 1346
1326 if (rate > 110) 1347 if (rate > 110)
1327 have_higher_than_11mbit = true; 1348 have_higher_than_11mbit = true;
1328 1349
1329 for (j = 0; j < sband->n_bitrates; j++) { 1350 for (j = 0; j < sband->n_bitrates; j++) {
1330 if (sband->bitrates[j].bitrate == rate) 1351 if (sband->bitrates[j].bitrate == rate) {
1331 rates |= BIT(j); 1352 rates |= BIT(j);
1332 if (elems.ext_supp_rates[i] & 0x80) 1353 if (is_basic)
1333 basic_rates |= BIT(j); 1354 basic_rates |= BIT(j);
1355 break;
1356 }
1334 } 1357 }
1335 } 1358 }
1336 1359
1337 sta->sta.supp_rates[local->hw.conf.channel->band] = rates; 1360 sta->sta.supp_rates[local->hw.conf.channel->band] = rates;
1338 sdata->bss_conf.basic_rates = basic_rates; 1361 sdata->vif.bss_conf.basic_rates = basic_rates;
1339 1362
1340 /* cf. IEEE 802.11 9.2.12 */ 1363 /* cf. IEEE 802.11 9.2.12 */
1341 if (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ && 1364 if (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ &&
@@ -1344,31 +1367,43 @@ static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
1344 else 1367 else
1345 sdata->flags &= ~IEEE80211_SDATA_OPERATING_GMODE; 1368 sdata->flags &= ~IEEE80211_SDATA_OPERATING_GMODE;
1346 1369
1347 if (elems.ht_cap_elem && elems.ht_info_elem && elems.wmm_param && 1370 if (elems.ht_cap_elem)
1348 (ifsta->flags & IEEE80211_STA_WMM_ENABLED)) { 1371 ieee80211_ht_cap_ie_to_sta_ht_cap(sband,
1349 struct ieee80211_ht_bss_info bss_info; 1372 elems.ht_cap_elem, &sta->sta.ht_cap);
1350 ieee80211_ht_cap_ie_to_ht_info( 1373
1351 elems.ht_cap_elem, &sta->sta.ht_info); 1374 ap_ht_cap_flags = sta->sta.ht_cap.cap;
1352 ieee80211_ht_addt_info_ie_to_ht_bss_info(
1353 elems.ht_info_elem, &bss_info);
1354 ieee80211_handle_ht(local, 1, &sta->sta.ht_info, &bss_info);
1355 }
1356 1375
1357 rate_control_rate_init(sta); 1376 rate_control_rate_init(sta);
1358 1377
1359 if (elems.wmm_param) { 1378 if (elems.wmm_param)
1360 set_sta_flags(sta, WLAN_STA_WME); 1379 set_sta_flags(sta, WLAN_STA_WME);
1361 rcu_read_unlock(); 1380
1381 if (newsta) {
1382 int err = sta_info_insert(sta);
1383 if (err) {
1384 printk(KERN_DEBUG "%s: failed to insert STA entry for"
1385 " the AP (error %d)\n", sdata->dev->name, err);
1386 rcu_read_unlock();
1387 return;
1388 }
1389 }
1390
1391 rcu_read_unlock();
1392
1393 if (elems.wmm_param)
1362 ieee80211_sta_wmm_params(local, ifsta, elems.wmm_param, 1394 ieee80211_sta_wmm_params(local, ifsta, elems.wmm_param,
1363 elems.wmm_param_len); 1395 elems.wmm_param_len);
1364 } else 1396
1365 rcu_read_unlock(); 1397 if (elems.ht_info_elem && elems.wmm_param &&
1398 (ifsta->flags & IEEE80211_STA_WMM_ENABLED))
1399 changed |= ieee80211_enable_ht(sdata, elems.ht_info_elem,
1400 ap_ht_cap_flags);
1366 1401
1367 /* set AID and assoc capability, 1402 /* set AID and assoc capability,
1368 * ieee80211_set_associated() will tell the driver */ 1403 * ieee80211_set_associated() will tell the driver */
1369 bss_conf->aid = aid; 1404 bss_conf->aid = aid;
1370 bss_conf->assoc_capability = capab_info; 1405 bss_conf->assoc_capability = capab_info;
1371 ieee80211_set_associated(sdata, ifsta); 1406 ieee80211_set_associated(sdata, ifsta, changed);
1372 1407
1373 ieee80211_associated(sdata, ifsta); 1408 ieee80211_associated(sdata, ifsta);
1374} 1409}
@@ -1386,6 +1421,13 @@ static int ieee80211_sta_join_ibss(struct ieee80211_sub_if_data *sdata,
1386 struct ieee80211_supported_band *sband; 1421 struct ieee80211_supported_band *sband;
1387 union iwreq_data wrqu; 1422 union iwreq_data wrqu;
1388 1423
1424 skb = dev_alloc_skb(local->hw.extra_tx_headroom + 400);
1425 if (!skb) {
1426 printk(KERN_DEBUG "%s: failed to allocate buffer for probe "
1427 "response\n", sdata->dev->name);
1428 return -ENOMEM;
1429 }
1430
1389 sband = local->hw.wiphy->bands[local->hw.conf.channel->band]; 1431 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
1390 1432
1391 /* Remove possible STA entries from other IBSS networks. */ 1433 /* Remove possible STA entries from other IBSS networks. */
@@ -1411,63 +1453,62 @@ static int ieee80211_sta_join_ibss(struct ieee80211_sub_if_data *sdata,
1411 return res; 1453 return res;
1412 1454
1413 /* Build IBSS probe response */ 1455 /* Build IBSS probe response */
1414 skb = dev_alloc_skb(local->hw.extra_tx_headroom + 400);
1415 if (skb) {
1416 skb_reserve(skb, local->hw.extra_tx_headroom);
1417 1456
1418 mgmt = (struct ieee80211_mgmt *) 1457 skb_reserve(skb, local->hw.extra_tx_headroom);
1419 skb_put(skb, 24 + sizeof(mgmt->u.beacon));
1420 memset(mgmt, 0, 24 + sizeof(mgmt->u.beacon));
1421 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
1422 IEEE80211_STYPE_PROBE_RESP);
1423 memset(mgmt->da, 0xff, ETH_ALEN);
1424 memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN);
1425 memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
1426 mgmt->u.beacon.beacon_int =
1427 cpu_to_le16(local->hw.conf.beacon_int);
1428 mgmt->u.beacon.timestamp = cpu_to_le64(bss->timestamp);
1429 mgmt->u.beacon.capab_info = cpu_to_le16(bss->capability);
1430
1431 pos = skb_put(skb, 2 + ifsta->ssid_len);
1432 *pos++ = WLAN_EID_SSID;
1433 *pos++ = ifsta->ssid_len;
1434 memcpy(pos, ifsta->ssid, ifsta->ssid_len);
1435
1436 rates = bss->supp_rates_len;
1437 if (rates > 8)
1438 rates = 8;
1439 pos = skb_put(skb, 2 + rates);
1440 *pos++ = WLAN_EID_SUPP_RATES;
1441 *pos++ = rates;
1442 memcpy(pos, bss->supp_rates, rates);
1443 1458
1444 if (bss->band == IEEE80211_BAND_2GHZ) { 1459 mgmt = (struct ieee80211_mgmt *)
1445 pos = skb_put(skb, 2 + 1); 1460 skb_put(skb, 24 + sizeof(mgmt->u.beacon));
1446 *pos++ = WLAN_EID_DS_PARAMS; 1461 memset(mgmt, 0, 24 + sizeof(mgmt->u.beacon));
1447 *pos++ = 1; 1462 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
1448 *pos++ = ieee80211_frequency_to_channel(bss->freq); 1463 IEEE80211_STYPE_PROBE_RESP);
1449 } 1464 memset(mgmt->da, 0xff, ETH_ALEN);
1465 memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN);
1466 memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
1467 mgmt->u.beacon.beacon_int =
1468 cpu_to_le16(local->hw.conf.beacon_int);
1469 mgmt->u.beacon.timestamp = cpu_to_le64(bss->timestamp);
1470 mgmt->u.beacon.capab_info = cpu_to_le16(bss->capability);
1450 1471
1451 pos = skb_put(skb, 2 + 2); 1472 pos = skb_put(skb, 2 + ifsta->ssid_len);
1452 *pos++ = WLAN_EID_IBSS_PARAMS; 1473 *pos++ = WLAN_EID_SSID;
1453 *pos++ = 2; 1474 *pos++ = ifsta->ssid_len;
1454 /* FIX: set ATIM window based on scan results */ 1475 memcpy(pos, ifsta->ssid, ifsta->ssid_len);
1455 *pos++ = 0;
1456 *pos++ = 0;
1457 1476
1458 if (bss->supp_rates_len > 8) { 1477 rates = bss->supp_rates_len;
1459 rates = bss->supp_rates_len - 8; 1478 if (rates > 8)
1460 pos = skb_put(skb, 2 + rates); 1479 rates = 8;
1461 *pos++ = WLAN_EID_EXT_SUPP_RATES; 1480 pos = skb_put(skb, 2 + rates);
1462 *pos++ = rates; 1481 *pos++ = WLAN_EID_SUPP_RATES;
1463 memcpy(pos, &bss->supp_rates[8], rates); 1482 *pos++ = rates;
1464 } 1483 memcpy(pos, bss->supp_rates, rates);
1465 1484
1466 ifsta->probe_resp = skb; 1485 if (bss->band == IEEE80211_BAND_2GHZ) {
1486 pos = skb_put(skb, 2 + 1);
1487 *pos++ = WLAN_EID_DS_PARAMS;
1488 *pos++ = 1;
1489 *pos++ = ieee80211_frequency_to_channel(bss->freq);
1490 }
1491
1492 pos = skb_put(skb, 2 + 2);
1493 *pos++ = WLAN_EID_IBSS_PARAMS;
1494 *pos++ = 2;
1495 /* FIX: set ATIM window based on scan results */
1496 *pos++ = 0;
1497 *pos++ = 0;
1467 1498
1468 ieee80211_if_config(sdata, IEEE80211_IFCC_BEACON); 1499 if (bss->supp_rates_len > 8) {
1500 rates = bss->supp_rates_len - 8;
1501 pos = skb_put(skb, 2 + rates);
1502 *pos++ = WLAN_EID_EXT_SUPP_RATES;
1503 *pos++ = rates;
1504 memcpy(pos, &bss->supp_rates[8], rates);
1469 } 1505 }
1470 1506
1507 ifsta->probe_resp = skb;
1508
1509 ieee80211_if_config(sdata, IEEE80211_IFCC_BEACON);
1510
1511
1471 rates = 0; 1512 rates = 0;
1472 sband = local->hw.wiphy->bands[local->hw.conf.channel->band]; 1513 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
1473 for (i = 0; i < bss->supp_rates_len; i++) { 1514 for (i = 0; i < bss->supp_rates_len; i++) {
@@ -1507,8 +1548,6 @@ static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
1507 u64 beacon_timestamp, rx_timestamp; 1548 u64 beacon_timestamp, rx_timestamp;
1508 u64 supp_rates = 0; 1549 u64 supp_rates = 0;
1509 enum ieee80211_band band = rx_status->band; 1550 enum ieee80211_band band = rx_status->band;
1510 DECLARE_MAC_BUF(mac);
1511 DECLARE_MAC_BUF(mac2);
1512 1551
1513 if (elems->ds_params && elems->ds_params_len == 1) 1552 if (elems->ds_params && elems->ds_params_len == 1)
1514 freq = ieee80211_channel_to_frequency(elems->ds_params[0]); 1553 freq = ieee80211_channel_to_frequency(elems->ds_params[0]);
@@ -1538,17 +1577,16 @@ static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
1538#ifdef CONFIG_MAC80211_IBSS_DEBUG 1577#ifdef CONFIG_MAC80211_IBSS_DEBUG
1539 if (sta->sta.supp_rates[band] != prev_rates) 1578 if (sta->sta.supp_rates[band] != prev_rates)
1540 printk(KERN_DEBUG "%s: updated supp_rates set " 1579 printk(KERN_DEBUG "%s: updated supp_rates set "
1541 "for %s based on beacon info (0x%llx | " 1580 "for %pM based on beacon info (0x%llx | "
1542 "0x%llx -> 0x%llx)\n", 1581 "0x%llx -> 0x%llx)\n",
1543 sdata->dev->name, 1582 sdata->dev->name,
1544 print_mac(mac, sta->sta.addr), 1583 sta->sta.addr,
1545 (unsigned long long) prev_rates, 1584 (unsigned long long) prev_rates,
1546 (unsigned long long) supp_rates, 1585 (unsigned long long) supp_rates,
1547 (unsigned long long) sta->sta.supp_rates[band]); 1586 (unsigned long long) sta->sta.supp_rates[band]);
1548#endif 1587#endif
1549 } else { 1588 } else {
1550 ieee80211_ibss_add_sta(sdata, NULL, mgmt->bssid, 1589 ieee80211_ibss_add_sta(sdata, mgmt->bssid, mgmt->sa, supp_rates);
1551 mgmt->sa, supp_rates);
1552 } 1590 }
1553 1591
1554 rcu_read_unlock(); 1592 rcu_read_unlock();
@@ -1595,8 +1633,13 @@ static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
1595 * e.g: at 1 MBit that means mactime is 192 usec earlier 1633 * e.g: at 1 MBit that means mactime is 192 usec earlier
1596 * (=24 bytes * 8 usecs/byte) than the beacon timestamp. 1634 * (=24 bytes * 8 usecs/byte) than the beacon timestamp.
1597 */ 1635 */
1598 int rate = local->hw.wiphy->bands[band]-> 1636 int rate;
1637 if (rx_status->flag & RX_FLAG_HT) {
1638 rate = 65; /* TODO: HT rates */
1639 } else {
1640 rate = local->hw.wiphy->bands[band]->
1599 bitrates[rx_status->rate_idx].bitrate; 1641 bitrates[rx_status->rate_idx].bitrate;
1642 }
1600 rx_timestamp = rx_status->mactime + (24 * 8 * 10 / rate); 1643 rx_timestamp = rx_status->mactime + (24 * 8 * 10 / rate);
1601 } else if (local && local->ops && local->ops->get_tsf) 1644 } else if (local && local->ops && local->ops->get_tsf)
1602 /* second best option: get current TSF */ 1645 /* second best option: get current TSF */
@@ -1605,10 +1648,9 @@ static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
1605 /* can't merge without knowing the TSF */ 1648 /* can't merge without knowing the TSF */
1606 rx_timestamp = -1LLU; 1649 rx_timestamp = -1LLU;
1607#ifdef CONFIG_MAC80211_IBSS_DEBUG 1650#ifdef CONFIG_MAC80211_IBSS_DEBUG
1608 printk(KERN_DEBUG "RX beacon SA=%s BSSID=" 1651 printk(KERN_DEBUG "RX beacon SA=%pM BSSID="
1609 "%s TSF=0x%llx BCN=0x%llx diff=%lld @%lu\n", 1652 "%pM TSF=0x%llx BCN=0x%llx diff=%lld @%lu\n",
1610 print_mac(mac, mgmt->sa), 1653 mgmt->sa, mgmt->bssid,
1611 print_mac(mac2, mgmt->bssid),
1612 (unsigned long long)rx_timestamp, 1654 (unsigned long long)rx_timestamp,
1613 (unsigned long long)beacon_timestamp, 1655 (unsigned long long)beacon_timestamp,
1614 (unsigned long long)(rx_timestamp - beacon_timestamp), 1656 (unsigned long long)(rx_timestamp - beacon_timestamp),
@@ -1617,13 +1659,11 @@ static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
1617 if (beacon_timestamp > rx_timestamp) { 1659 if (beacon_timestamp > rx_timestamp) {
1618#ifdef CONFIG_MAC80211_IBSS_DEBUG 1660#ifdef CONFIG_MAC80211_IBSS_DEBUG
1619 printk(KERN_DEBUG "%s: beacon TSF higher than " 1661 printk(KERN_DEBUG "%s: beacon TSF higher than "
1620 "local TSF - IBSS merge with BSSID %s\n", 1662 "local TSF - IBSS merge with BSSID %pM\n",
1621 sdata->dev->name, print_mac(mac, mgmt->bssid)); 1663 sdata->dev->name, mgmt->bssid);
1622#endif 1664#endif
1623 ieee80211_sta_join_ibss(sdata, &sdata->u.sta, bss); 1665 ieee80211_sta_join_ibss(sdata, &sdata->u.sta, bss);
1624 ieee80211_ibss_add_sta(sdata, NULL, 1666 ieee80211_ibss_add_sta(sdata, mgmt->bssid, mgmt->sa, supp_rates);
1625 mgmt->bssid, mgmt->sa,
1626 supp_rates);
1627 } 1667 }
1628 } 1668 }
1629 1669
@@ -1671,8 +1711,9 @@ static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata,
1671 size_t baselen; 1711 size_t baselen;
1672 struct ieee802_11_elems elems; 1712 struct ieee802_11_elems elems;
1673 struct ieee80211_local *local = sdata->local; 1713 struct ieee80211_local *local = sdata->local;
1674 struct ieee80211_conf *conf = &local->hw.conf;
1675 u32 changed = 0; 1714 u32 changed = 0;
1715 bool erp_valid;
1716 u8 erp_value = 0;
1676 1717
1677 /* Process beacon from the current BSS */ 1718 /* Process beacon from the current BSS */
1678 baselen = (u8 *) mgmt->u.beacon.variable - (u8 *) mgmt; 1719 baselen = (u8 *) mgmt->u.beacon.variable - (u8 *) mgmt;
@@ -1694,22 +1735,49 @@ static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata,
1694 ieee80211_sta_wmm_params(local, ifsta, elems.wmm_param, 1735 ieee80211_sta_wmm_params(local, ifsta, elems.wmm_param,
1695 elems.wmm_param_len); 1736 elems.wmm_param_len);
1696 1737
1697 if (elems.erp_info && elems.erp_info_len >= 1) 1738
1698 changed |= ieee80211_handle_erp_ie(sdata, elems.erp_info[0]); 1739 if (elems.erp_info && elems.erp_info_len >= 1) {
1699 else { 1740 erp_valid = true;
1700 u16 capab = le16_to_cpu(mgmt->u.beacon.capab_info); 1741 erp_value = elems.erp_info[0];
1701 changed |= ieee80211_handle_protect_preamb(sdata, false, 1742 } else {
1702 (capab & WLAN_CAPABILITY_SHORT_PREAMBLE) != 0); 1743 erp_valid = false;
1703 } 1744 }
1745 changed |= ieee80211_handle_bss_capability(sdata,
1746 le16_to_cpu(mgmt->u.beacon.capab_info),
1747 erp_valid, erp_value);
1748
1749
1750 if (elems.ht_cap_elem && elems.ht_info_elem && elems.wmm_param) {
1751 struct sta_info *sta;
1752 struct ieee80211_supported_band *sband;
1753 u16 ap_ht_cap_flags;
1754
1755 rcu_read_lock();
1704 1756
1705 if (elems.ht_cap_elem && elems.ht_info_elem && 1757 sta = sta_info_get(local, ifsta->bssid);
1706 elems.wmm_param && conf->flags & IEEE80211_CONF_SUPPORT_HT_MODE) { 1758 if (!sta) {
1707 struct ieee80211_ht_bss_info bss_info; 1759 rcu_read_unlock();
1760 return;
1761 }
1762
1763 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
1708 1764
1709 ieee80211_ht_addt_info_ie_to_ht_bss_info( 1765 ieee80211_ht_cap_ie_to_sta_ht_cap(sband,
1710 elems.ht_info_elem, &bss_info); 1766 elems.ht_cap_elem, &sta->sta.ht_cap);
1711 changed |= ieee80211_handle_ht(local, 1, &conf->ht_conf, 1767
1712 &bss_info); 1768 ap_ht_cap_flags = sta->sta.ht_cap.cap;
1769
1770 rcu_read_unlock();
1771
1772 changed |= ieee80211_enable_ht(sdata, elems.ht_info_elem,
1773 ap_ht_cap_flags);
1774 }
1775
1776 if (elems.country_elem) {
1777 /* Note we are only reviewing this on beacons
1778 * for the BSSID we are associated to */
1779 regulatory_hint_11d(local->hw.wiphy,
1780 elems.country_elem, elems.country_elem_len);
1713 } 1781 }
1714 1782
1715 ieee80211_bss_info_change_notify(sdata, changed); 1783 ieee80211_bss_info_change_notify(sdata, changed);
@@ -1727,11 +1795,6 @@ static void ieee80211_rx_mgmt_probe_req(struct ieee80211_sub_if_data *sdata,
1727 struct sk_buff *skb; 1795 struct sk_buff *skb;
1728 struct ieee80211_mgmt *resp; 1796 struct ieee80211_mgmt *resp;
1729 u8 *pos, *end; 1797 u8 *pos, *end;
1730 DECLARE_MAC_BUF(mac);
1731#ifdef CONFIG_MAC80211_IBSS_DEBUG
1732 DECLARE_MAC_BUF(mac2);
1733 DECLARE_MAC_BUF(mac3);
1734#endif
1735 1798
1736 if (sdata->vif.type != NL80211_IFTYPE_ADHOC || 1799 if (sdata->vif.type != NL80211_IFTYPE_ADHOC ||
1737 ifsta->state != IEEE80211_STA_MLME_IBSS_JOINED || 1800 ifsta->state != IEEE80211_STA_MLME_IBSS_JOINED ||
@@ -1744,10 +1807,10 @@ static void ieee80211_rx_mgmt_probe_req(struct ieee80211_sub_if_data *sdata,
1744 tx_last_beacon = 1; 1807 tx_last_beacon = 1;
1745 1808
1746#ifdef CONFIG_MAC80211_IBSS_DEBUG 1809#ifdef CONFIG_MAC80211_IBSS_DEBUG
1747 printk(KERN_DEBUG "%s: RX ProbeReq SA=%s DA=%s BSSID=" 1810 printk(KERN_DEBUG "%s: RX ProbeReq SA=%pM DA=%pM BSSID=%pM"
1748 "%s (tx_last_beacon=%d)\n", 1811 " (tx_last_beacon=%d)\n",
1749 sdata->dev->name, print_mac(mac, mgmt->sa), print_mac(mac2, mgmt->da), 1812 sdata->dev->name, mgmt->sa, mgmt->da,
1750 print_mac(mac3, mgmt->bssid), tx_last_beacon); 1813 mgmt->bssid, tx_last_beacon);
1751#endif /* CONFIG_MAC80211_IBSS_DEBUG */ 1814#endif /* CONFIG_MAC80211_IBSS_DEBUG */
1752 1815
1753 if (!tx_last_beacon) 1816 if (!tx_last_beacon)
@@ -1763,8 +1826,8 @@ static void ieee80211_rx_mgmt_probe_req(struct ieee80211_sub_if_data *sdata,
1763 pos + 2 + pos[1] > end) { 1826 pos + 2 + pos[1] > end) {
1764#ifdef CONFIG_MAC80211_IBSS_DEBUG 1827#ifdef CONFIG_MAC80211_IBSS_DEBUG
1765 printk(KERN_DEBUG "%s: Invalid SSID IE in ProbeReq " 1828 printk(KERN_DEBUG "%s: Invalid SSID IE in ProbeReq "
1766 "from %s\n", 1829 "from %pM\n",
1767 sdata->dev->name, print_mac(mac, mgmt->sa)); 1830 sdata->dev->name, mgmt->sa);
1768#endif 1831#endif
1769 return; 1832 return;
1770 } 1833 }
@@ -1783,8 +1846,8 @@ static void ieee80211_rx_mgmt_probe_req(struct ieee80211_sub_if_data *sdata,
1783 resp = (struct ieee80211_mgmt *) skb->data; 1846 resp = (struct ieee80211_mgmt *) skb->data;
1784 memcpy(resp->da, mgmt->sa, ETH_ALEN); 1847 memcpy(resp->da, mgmt->sa, ETH_ALEN);
1785#ifdef CONFIG_MAC80211_IBSS_DEBUG 1848#ifdef CONFIG_MAC80211_IBSS_DEBUG
1786 printk(KERN_DEBUG "%s: Sending ProbeResp to %s\n", 1849 printk(KERN_DEBUG "%s: Sending ProbeResp to %pM\n",
1787 sdata->dev->name, print_mac(mac, resp->da)); 1850 sdata->dev->name, resp->da);
1788#endif /* CONFIG_MAC80211_IBSS_DEBUG */ 1851#endif /* CONFIG_MAC80211_IBSS_DEBUG */
1789 ieee80211_tx_skb(sdata, skb, 0); 1852 ieee80211_tx_skb(sdata, skb, 0);
1790} 1853}
@@ -1972,7 +2035,7 @@ static int ieee80211_sta_match_ssid(struct ieee80211_if_sta *ifsta,
1972 } 2035 }
1973 } 2036 }
1974 2037
1975 if (hidden_ssid && ifsta->ssid_len == ssid_len) 2038 if (hidden_ssid && (ifsta->ssid_len == ssid_len || ssid_len == 0))
1976 return 1; 2039 return 1;
1977 2040
1978 if (ssid_len == 1 && ssid[0] == ' ') 2041 if (ssid_len == 1 && ssid[0] == ' ')
@@ -1990,7 +2053,6 @@ static int ieee80211_sta_create_ibss(struct ieee80211_sub_if_data *sdata,
1990 u8 bssid[ETH_ALEN], *pos; 2053 u8 bssid[ETH_ALEN], *pos;
1991 int i; 2054 int i;
1992 int ret; 2055 int ret;
1993 DECLARE_MAC_BUF(mac);
1994 2056
1995#if 0 2057#if 0
1996 /* Easier testing, use fixed BSSID. */ 2058 /* Easier testing, use fixed BSSID. */
@@ -2006,8 +2068,8 @@ static int ieee80211_sta_create_ibss(struct ieee80211_sub_if_data *sdata,
2006 bssid[0] |= 0x02; 2068 bssid[0] |= 0x02;
2007#endif 2069#endif
2008 2070
2009 printk(KERN_DEBUG "%s: Creating new IBSS network, BSSID %s\n", 2071 printk(KERN_DEBUG "%s: Creating new IBSS network, BSSID %pM\n",
2010 sdata->dev->name, print_mac(mac, bssid)); 2072 sdata->dev->name, bssid);
2011 2073
2012 bss = ieee80211_rx_bss_add(local, bssid, 2074 bss = ieee80211_rx_bss_add(local, bssid,
2013 local->hw.conf.channel->center_freq, 2075 local->hw.conf.channel->center_freq,
@@ -2050,8 +2112,6 @@ static int ieee80211_sta_find_ibss(struct ieee80211_sub_if_data *sdata,
2050 int found = 0; 2112 int found = 0;
2051 u8 bssid[ETH_ALEN]; 2113 u8 bssid[ETH_ALEN];
2052 int active_ibss; 2114 int active_ibss;
2053 DECLARE_MAC_BUF(mac);
2054 DECLARE_MAC_BUF(mac2);
2055 2115
2056 if (ifsta->ssid_len == 0) 2116 if (ifsta->ssid_len == 0)
2057 return -EINVAL; 2117 return -EINVAL;
@@ -2068,8 +2128,7 @@ static int ieee80211_sta_find_ibss(struct ieee80211_sub_if_data *sdata,
2068 || !(bss->capability & WLAN_CAPABILITY_IBSS)) 2128 || !(bss->capability & WLAN_CAPABILITY_IBSS))
2069 continue; 2129 continue;
2070#ifdef CONFIG_MAC80211_IBSS_DEBUG 2130#ifdef CONFIG_MAC80211_IBSS_DEBUG
2071 printk(KERN_DEBUG " bssid=%s found\n", 2131 printk(KERN_DEBUG " bssid=%pM found\n", bss->bssid);
2072 print_mac(mac, bss->bssid));
2073#endif /* CONFIG_MAC80211_IBSS_DEBUG */ 2132#endif /* CONFIG_MAC80211_IBSS_DEBUG */
2074 memcpy(bssid, bss->bssid, ETH_ALEN); 2133 memcpy(bssid, bss->bssid, ETH_ALEN);
2075 found = 1; 2134 found = 1;
@@ -2080,9 +2139,8 @@ static int ieee80211_sta_find_ibss(struct ieee80211_sub_if_data *sdata,
2080 2139
2081#ifdef CONFIG_MAC80211_IBSS_DEBUG 2140#ifdef CONFIG_MAC80211_IBSS_DEBUG
2082 if (found) 2141 if (found)
2083 printk(KERN_DEBUG " sta_find_ibss: selected %s current " 2142 printk(KERN_DEBUG " sta_find_ibss: selected %pM current "
2084 "%s\n", print_mac(mac, bssid), 2143 "%pM\n", bssid, ifsta->bssid);
2085 print_mac(mac2, ifsta->bssid));
2086#endif /* CONFIG_MAC80211_IBSS_DEBUG */ 2144#endif /* CONFIG_MAC80211_IBSS_DEBUG */
2087 2145
2088 if (found && memcmp(ifsta->bssid, bssid, ETH_ALEN) != 0) { 2146 if (found && memcmp(ifsta->bssid, bssid, ETH_ALEN) != 0) {
@@ -2099,9 +2157,9 @@ static int ieee80211_sta_find_ibss(struct ieee80211_sub_if_data *sdata,
2099 if (!bss) 2157 if (!bss)
2100 goto dont_join; 2158 goto dont_join;
2101 2159
2102 printk(KERN_DEBUG "%s: Selected IBSS BSSID %s" 2160 printk(KERN_DEBUG "%s: Selected IBSS BSSID %pM"
2103 " based on configured SSID\n", 2161 " based on configured SSID\n",
2104 sdata->dev->name, print_mac(mac, bssid)); 2162 sdata->dev->name, bssid);
2105 ret = ieee80211_sta_join_ibss(sdata, ifsta, bss); 2163 ret = ieee80211_sta_join_ibss(sdata, ifsta, bss);
2106 ieee80211_rx_bss_put(local, bss); 2164 ieee80211_rx_bss_put(local, bss);
2107 return ret; 2165 return ret;
@@ -2338,12 +2396,10 @@ void ieee80211_sta_setup_sdata(struct ieee80211_sub_if_data *sdata)
2338 * must be callable in atomic context. 2396 * must be callable in atomic context.
2339 */ 2397 */
2340struct sta_info *ieee80211_ibss_add_sta(struct ieee80211_sub_if_data *sdata, 2398struct sta_info *ieee80211_ibss_add_sta(struct ieee80211_sub_if_data *sdata,
2341 struct sk_buff *skb, u8 *bssid, 2399 u8 *bssid,u8 *addr, u64 supp_rates)
2342 u8 *addr, u64 supp_rates)
2343{ 2400{
2344 struct ieee80211_local *local = sdata->local; 2401 struct ieee80211_local *local = sdata->local;
2345 struct sta_info *sta; 2402 struct sta_info *sta;
2346 DECLARE_MAC_BUF(mac);
2347 int band = local->hw.conf.channel->band; 2403 int band = local->hw.conf.channel->band;
2348 2404
2349 /* TODO: Could consider removing the least recently used entry and 2405 /* TODO: Could consider removing the least recently used entry and
@@ -2351,7 +2407,7 @@ struct sta_info *ieee80211_ibss_add_sta(struct ieee80211_sub_if_data *sdata,
2351 if (local->num_sta >= IEEE80211_IBSS_MAX_STA_ENTRIES) { 2407 if (local->num_sta >= IEEE80211_IBSS_MAX_STA_ENTRIES) {
2352 if (net_ratelimit()) { 2408 if (net_ratelimit()) {
2353 printk(KERN_DEBUG "%s: No room for a new IBSS STA " 2409 printk(KERN_DEBUG "%s: No room for a new IBSS STA "
2354 "entry %s\n", sdata->dev->name, print_mac(mac, addr)); 2410 "entry %pM\n", sdata->dev->name, addr);
2355 } 2411 }
2356 return NULL; 2412 return NULL;
2357 } 2413 }
@@ -2360,8 +2416,8 @@ struct sta_info *ieee80211_ibss_add_sta(struct ieee80211_sub_if_data *sdata,
2360 return NULL; 2416 return NULL;
2361 2417
2362#ifdef CONFIG_MAC80211_VERBOSE_DEBUG 2418#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
2363 printk(KERN_DEBUG "%s: Adding new IBSS station %s (dev=%s)\n", 2419 printk(KERN_DEBUG "%s: Adding new IBSS station %pM (dev=%s)\n",
2364 wiphy_name(local->hw.wiphy), print_mac(mac, addr), sdata->dev->name); 2420 wiphy_name(local->hw.wiphy), addr, sdata->dev->name);
2365#endif 2421#endif
2366 2422
2367 sta = sta_info_alloc(sdata, addr, GFP_ATOMIC); 2423 sta = sta_info_alloc(sdata, addr, GFP_ATOMIC);
@@ -2408,7 +2464,6 @@ void ieee80211_sta_req_auth(struct ieee80211_sub_if_data *sdata,
2408int ieee80211_sta_set_ssid(struct ieee80211_sub_if_data *sdata, char *ssid, size_t len) 2464int ieee80211_sta_set_ssid(struct ieee80211_sub_if_data *sdata, char *ssid, size_t len)
2409{ 2465{
2410 struct ieee80211_if_sta *ifsta; 2466 struct ieee80211_if_sta *ifsta;
2411 int res;
2412 2467
2413 if (len > IEEE80211_MAX_SSID_LEN) 2468 if (len > IEEE80211_MAX_SSID_LEN)
2414 return -EINVAL; 2469 return -EINVAL;
@@ -2420,19 +2475,6 @@ int ieee80211_sta_set_ssid(struct ieee80211_sub_if_data *sdata, char *ssid, size
2420 memcpy(ifsta->ssid, ssid, len); 2475 memcpy(ifsta->ssid, ssid, len);
2421 ifsta->ssid_len = len; 2476 ifsta->ssid_len = len;
2422 ifsta->flags &= ~IEEE80211_STA_PREV_BSSID_SET; 2477 ifsta->flags &= ~IEEE80211_STA_PREV_BSSID_SET;
2423
2424 res = 0;
2425 /*
2426 * Hack! MLME code needs to be cleaned up to have different
2427 * entry points for configuration and internal selection change
2428 */
2429 if (netif_running(sdata->dev))
2430 res = ieee80211_if_config(sdata, IEEE80211_IFCC_SSID);
2431 if (res) {
2432 printk(KERN_DEBUG "%s: Failed to config new SSID to "
2433 "the low-level driver\n", sdata->dev->name);
2434 return res;
2435 }
2436 } 2478 }
2437 2479
2438 if (len) 2480 if (len)
@@ -2560,3 +2602,39 @@ void ieee80211_mlme_notify_scan_completed(struct ieee80211_local *local)
2560 ieee80211_restart_sta_timer(sdata); 2602 ieee80211_restart_sta_timer(sdata);
2561 rcu_read_unlock(); 2603 rcu_read_unlock();
2562} 2604}
2605
2606void ieee80211_dynamic_ps_disable_work(struct work_struct *work)
2607{
2608 struct ieee80211_local *local =
2609 container_of(work, struct ieee80211_local,
2610 dynamic_ps_disable_work);
2611
2612 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
2613 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
2614 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
2615 }
2616
2617 ieee80211_wake_queues_by_reason(&local->hw,
2618 IEEE80211_QUEUE_STOP_REASON_PS);
2619}
2620
2621void ieee80211_dynamic_ps_enable_work(struct work_struct *work)
2622{
2623 struct ieee80211_local *local =
2624 container_of(work, struct ieee80211_local,
2625 dynamic_ps_enable_work);
2626
2627 if (local->hw.conf.flags & IEEE80211_CONF_PS)
2628 return;
2629
2630 local->hw.conf.flags |= IEEE80211_CONF_PS;
2631
2632 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
2633}
2634
2635void ieee80211_dynamic_ps_timer(unsigned long data)
2636{
2637 struct ieee80211_local *local = (void *) data;
2638
2639 queue_work(local->hw.workqueue, &local->dynamic_ps_enable_work);
2640}
diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
index 5d786720d935..3fa7ab285066 100644
--- a/net/mac80211/rate.c
+++ b/net/mac80211/rate.c
@@ -199,48 +199,44 @@ static void rate_control_release(struct kref *kref)
199} 199}
200 200
201void rate_control_get_rate(struct ieee80211_sub_if_data *sdata, 201void rate_control_get_rate(struct ieee80211_sub_if_data *sdata,
202 struct ieee80211_supported_band *sband, 202 struct sta_info *sta,
203 struct sta_info *sta, struct sk_buff *skb, 203 struct ieee80211_tx_rate_control *txrc)
204 struct rate_selection *sel)
205{ 204{
206 struct rate_control_ref *ref = sdata->local->rate_ctrl; 205 struct rate_control_ref *ref = sdata->local->rate_ctrl;
207 void *priv_sta = NULL; 206 void *priv_sta = NULL;
208 struct ieee80211_sta *ista = NULL; 207 struct ieee80211_sta *ista = NULL;
208 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(txrc->skb);
209 int i; 209 int i;
210 210
211 sel->rate_idx = -1;
212 sel->nonerp_idx = -1;
213 sel->probe_idx = -1;
214 sel->max_rate_idx = sdata->max_ratectrl_rateidx;
215
216 if (sta) { 211 if (sta) {
217 ista = &sta->sta; 212 ista = &sta->sta;
218 priv_sta = sta->rate_ctrl_priv; 213 priv_sta = sta->rate_ctrl_priv;
219 } 214 }
220 215
216 for (i = 0; i < IEEE80211_TX_MAX_RATES; i++) {
217 info->control.rates[i].idx = -1;
218 info->control.rates[i].flags = 0;
219 info->control.rates[i].count = 1;
220 }
221
221 if (sta && sdata->force_unicast_rateidx > -1) 222 if (sta && sdata->force_unicast_rateidx > -1)
222 sel->rate_idx = sdata->force_unicast_rateidx; 223 info->control.rates[0].idx = sdata->force_unicast_rateidx;
223 else 224 else
224 ref->ops->get_rate(ref->priv, sband, ista, priv_sta, skb, sel); 225 ref->ops->get_rate(ref->priv, ista, priv_sta, txrc);
225 226
226 if (sdata->max_ratectrl_rateidx > -1 && 227 /*
227 sel->rate_idx > sdata->max_ratectrl_rateidx) 228 * try to enforce the maximum rate the user wanted
228 sel->rate_idx = sdata->max_ratectrl_rateidx; 229 */
229 230 if (sdata->max_ratectrl_rateidx > -1)
230 BUG_ON(sel->rate_idx < 0); 231 for (i = 0; i < IEEE80211_TX_MAX_RATES; i++) {
231 232 if (info->control.rates[i].flags & IEEE80211_TX_RC_MCS)
232 /* Select a non-ERP backup rate. */ 233 continue;
233 if (sel->nonerp_idx < 0) { 234 info->control.rates[i].idx =
234 for (i = 0; i < sband->n_bitrates; i++) { 235 min_t(s8, info->control.rates[i].idx,
235 struct ieee80211_rate *rate = &sband->bitrates[i]; 236 sdata->max_ratectrl_rateidx);
236 if (sband->bitrates[sel->rate_idx].bitrate < rate->bitrate)
237 break;
238
239 if (rate_supported(ista, sband->band, i) &&
240 !(rate->flags & IEEE80211_RATE_ERP_G))
241 sel->nonerp_idx = i;
242 }
243 } 237 }
238
239 BUG_ON(info->control.rates[0].idx < 0);
244} 240}
245 241
246struct rate_control_ref *rate_control_get(struct rate_control_ref *ref) 242struct rate_control_ref *rate_control_get(struct rate_control_ref *ref)
diff --git a/net/mac80211/rate.h b/net/mac80211/rate.h
index d0092f847f82..928da625e281 100644
--- a/net/mac80211/rate.h
+++ b/net/mac80211/rate.h
@@ -31,9 +31,8 @@ struct rate_control_ref {
31struct rate_control_ref *rate_control_alloc(const char *name, 31struct rate_control_ref *rate_control_alloc(const char *name,
32 struct ieee80211_local *local); 32 struct ieee80211_local *local);
33void rate_control_get_rate(struct ieee80211_sub_if_data *sdata, 33void rate_control_get_rate(struct ieee80211_sub_if_data *sdata,
34 struct ieee80211_supported_band *sband, 34 struct sta_info *sta,
35 struct sta_info *sta, struct sk_buff *skb, 35 struct ieee80211_tx_rate_control *txrc);
36 struct rate_selection *sel);
37struct rate_control_ref *rate_control_get(struct rate_control_ref *ref); 36struct rate_control_ref *rate_control_get(struct rate_control_ref *ref);
38void rate_control_put(struct rate_control_ref *ref); 37void rate_control_put(struct rate_control_ref *ref);
39 38
@@ -64,12 +63,6 @@ static inline void rate_control_rate_init(struct sta_info *sta)
64} 63}
65 64
66 65
67static inline void rate_control_clear(struct ieee80211_local *local)
68{
69 struct rate_control_ref *ref = local->rate_ctrl;
70 ref->ops->clear(ref->priv);
71}
72
73static inline void *rate_control_alloc_sta(struct rate_control_ref *ref, 66static inline void *rate_control_alloc_sta(struct rate_control_ref *ref,
74 struct ieee80211_sta *sta, 67 struct ieee80211_sta *sta,
75 gfp_t gfp) 68 gfp_t gfp)
diff --git a/net/mac80211/rc80211_minstrel.c b/net/mac80211/rc80211_minstrel.c
index f6d69dab07a3..2b3b490a6073 100644
--- a/net/mac80211/rc80211_minstrel.c
+++ b/net/mac80211/rc80211_minstrel.c
@@ -126,7 +126,9 @@ minstrel_update_stats(struct minstrel_priv *mp, struct minstrel_sta_info *mi)
126 mr->adjusted_retry_count = mr->retry_count >> 1; 126 mr->adjusted_retry_count = mr->retry_count >> 1;
127 if (mr->adjusted_retry_count > 2) 127 if (mr->adjusted_retry_count > 2)
128 mr->adjusted_retry_count = 2; 128 mr->adjusted_retry_count = 2;
129 mr->sample_limit = 4;
129 } else { 130 } else {
131 mr->sample_limit = -1;
130 mr->adjusted_retry_count = mr->retry_count; 132 mr->adjusted_retry_count = mr->retry_count;
131 } 133 }
132 if (!mr->adjusted_retry_count) 134 if (!mr->adjusted_retry_count)
@@ -169,30 +171,20 @@ minstrel_tx_status(void *priv, struct ieee80211_supported_band *sband,
169{ 171{
170 struct minstrel_sta_info *mi = priv_sta; 172 struct minstrel_sta_info *mi = priv_sta;
171 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); 173 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
172 struct ieee80211_tx_altrate *ar = info->status.retries; 174 struct ieee80211_tx_rate *ar = info->status.rates;
173 struct minstrel_priv *mp = priv; 175 int i, ndx;
174 int i, ndx, tries; 176 int success;
175 int success = 0;
176
177 if (!info->status.excessive_retries)
178 success = 1;
179 177
180 if (!mp->has_mrr || (ar[0].rate_idx < 0)) { 178 success = !!(info->flags & IEEE80211_TX_STAT_ACK);
181 ndx = rix_to_ndx(mi, info->tx_rate_idx);
182 tries = info->status.retry_count + 1;
183 mi->r[ndx].success += success;
184 mi->r[ndx].attempts += tries;
185 return;
186 }
187 179
188 for (i = 0; i < 4; i++) { 180 for (i = 0; i < IEEE80211_TX_MAX_RATES; i++) {
189 if (ar[i].rate_idx < 0) 181 if (ar[i].idx < 0)
190 break; 182 break;
191 183
192 ndx = rix_to_ndx(mi, ar[i].rate_idx); 184 ndx = rix_to_ndx(mi, ar[i].idx);
193 mi->r[ndx].attempts += ar[i].limit + 1; 185 mi->r[ndx].attempts += ar[i].count;
194 186
195 if ((i != 3) && (ar[i + 1].rate_idx < 0)) 187 if ((i != IEEE80211_TX_MAX_RATES - 1) && (ar[i + 1].idx < 0))
196 mi->r[ndx].success += success; 188 mi->r[ndx].success += success;
197 } 189 }
198 190
@@ -210,9 +202,9 @@ minstrel_get_retry_count(struct minstrel_rate *mr,
210{ 202{
211 unsigned int retry = mr->adjusted_retry_count; 203 unsigned int retry = mr->adjusted_retry_count;
212 204
213 if (info->flags & IEEE80211_TX_CTL_USE_RTS_CTS) 205 if (info->control.rates[0].flags & IEEE80211_TX_RC_USE_RTS_CTS)
214 retry = max(2U, min(mr->retry_count_rtscts, retry)); 206 retry = max(2U, min(mr->retry_count_rtscts, retry));
215 else if (info->flags & IEEE80211_TX_CTL_USE_CTS_PROTECT) 207 else if (info->control.rates[0].flags & IEEE80211_TX_RC_USE_CTS_PROTECT)
216 retry = max(2U, min(mr->retry_count_cts, retry)); 208 retry = max(2U, min(mr->retry_count_cts, retry));
217 return retry; 209 return retry;
218} 210}
@@ -233,15 +225,16 @@ minstrel_get_next_sample(struct minstrel_sta_info *mi)
233 return sample_ndx; 225 return sample_ndx;
234} 226}
235 227
236void 228static void
237minstrel_get_rate(void *priv, struct ieee80211_supported_band *sband, 229minstrel_get_rate(void *priv, struct ieee80211_sta *sta,
238 struct ieee80211_sta *sta, void *priv_sta, 230 void *priv_sta, struct ieee80211_tx_rate_control *txrc)
239 struct sk_buff *skb, struct rate_selection *sel)
240{ 231{
232 struct sk_buff *skb = txrc->skb;
233 struct ieee80211_supported_band *sband = txrc->sband;
241 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); 234 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
242 struct minstrel_sta_info *mi = priv_sta; 235 struct minstrel_sta_info *mi = priv_sta;
243 struct minstrel_priv *mp = priv; 236 struct minstrel_priv *mp = priv;
244 struct ieee80211_tx_altrate *ar = info->control.retries; 237 struct ieee80211_tx_rate *ar = info->control.rates;
245 unsigned int ndx, sample_ndx = 0; 238 unsigned int ndx, sample_ndx = 0;
246 bool mrr; 239 bool mrr;
247 bool sample_slower = false; 240 bool sample_slower = false;
@@ -251,16 +244,12 @@ minstrel_get_rate(void *priv, struct ieee80211_supported_band *sband,
251 int sample_rate; 244 int sample_rate;
252 245
253 if (!sta || !mi || use_low_rate(skb)) { 246 if (!sta || !mi || use_low_rate(skb)) {
254 sel->rate_idx = rate_lowest_index(sband, sta); 247 ar[0].idx = rate_lowest_index(sband, sta);
248 ar[0].count = mp->max_retry;
255 return; 249 return;
256 } 250 }
257 251
258 mrr = mp->has_mrr; 252 mrr = mp->has_mrr && !txrc->rts && !txrc->bss_conf->use_cts_prot;
259
260 /* mac80211 does not allow mrr for RTS/CTS */
261 if ((info->flags & IEEE80211_TX_CTL_USE_RTS_CTS) ||
262 (info->flags & IEEE80211_TX_CTL_USE_CTS_PROTECT))
263 mrr = false;
264 253
265 if (time_after(jiffies, mi->stats_update + (mp->update_interval * 254 if (time_after(jiffies, mi->stats_update + (mp->update_interval *
266 HZ) / 1000)) 255 HZ) / 1000))
@@ -278,7 +267,8 @@ minstrel_get_rate(void *priv, struct ieee80211_supported_band *sband,
278 (mi->sample_count + mi->sample_deferred / 2); 267 (mi->sample_count + mi->sample_deferred / 2);
279 268
280 /* delta > 0: sampling required */ 269 /* delta > 0: sampling required */
281 if (delta > 0) { 270 if ((delta > 0) && (mrr || !mi->prev_sample)) {
271 struct minstrel_rate *msr;
282 if (mi->packet_count >= 10000) { 272 if (mi->packet_count >= 10000) {
283 mi->sample_deferred = 0; 273 mi->sample_deferred = 0;
284 mi->sample_count = 0; 274 mi->sample_count = 0;
@@ -297,13 +287,20 @@ minstrel_get_rate(void *priv, struct ieee80211_supported_band *sband,
297 } 287 }
298 288
299 sample_ndx = minstrel_get_next_sample(mi); 289 sample_ndx = minstrel_get_next_sample(mi);
290 msr = &mi->r[sample_ndx];
300 sample = true; 291 sample = true;
301 sample_slower = mrr && (mi->r[sample_ndx].perfect_tx_time > 292 sample_slower = mrr && (msr->perfect_tx_time >
302 mi->r[ndx].perfect_tx_time); 293 mi->r[ndx].perfect_tx_time);
303 294
304 if (!sample_slower) { 295 if (!sample_slower) {
305 ndx = sample_ndx; 296 if (msr->sample_limit != 0) {
306 mi->sample_count++; 297 ndx = sample_ndx;
298 mi->sample_count++;
299 if (msr->sample_limit > 0)
300 msr->sample_limit--;
301 } else {
302 sample = false;
303 }
307 } else { 304 } else {
308 /* Only use IEEE80211_TX_CTL_RATE_CTRL_PROBE to mark 305 /* Only use IEEE80211_TX_CTL_RATE_CTRL_PROBE to mark
309 * packets that have the sampling rate deferred to the 306 * packets that have the sampling rate deferred to the
@@ -315,13 +312,22 @@ minstrel_get_rate(void *priv, struct ieee80211_supported_band *sband,
315 mi->sample_deferred++; 312 mi->sample_deferred++;
316 } 313 }
317 } 314 }
318 sel->rate_idx = mi->r[ndx].rix; 315 mi->prev_sample = sample;
319 info->control.retry_limit = minstrel_get_retry_count(&mi->r[ndx], info); 316
317 /* If we're not using MRR and the sampling rate already
318 * has a probability of >95%, we shouldn't be attempting
319 * to use it, as this only wastes precious airtime */
320 if (!mrr && sample && (mi->r[ndx].probability > 17100))
321 ndx = mi->max_tp_rate;
322
323 ar[0].idx = mi->r[ndx].rix;
324 ar[0].count = minstrel_get_retry_count(&mi->r[ndx], info);
320 325
321 if (!mrr) { 326 if (!mrr) {
322 ar[0].rate_idx = mi->lowest_rix; 327 if (!sample)
323 ar[0].limit = mp->max_retry; 328 ar[0].count = mp->max_retry;
324 ar[1].rate_idx = -1; 329 ar[1].idx = mi->lowest_rix;
330 ar[1].count = mp->max_retry;
325 return; 331 return;
326 } 332 }
327 333
@@ -336,9 +342,9 @@ minstrel_get_rate(void *priv, struct ieee80211_supported_band *sband,
336 } 342 }
337 mrr_ndx[1] = mi->max_prob_rate; 343 mrr_ndx[1] = mi->max_prob_rate;
338 mrr_ndx[2] = 0; 344 mrr_ndx[2] = 0;
339 for (i = 0; i < 3; i++) { 345 for (i = 1; i < 4; i++) {
340 ar[i].rate_idx = mi->r[mrr_ndx[i]].rix; 346 ar[i].idx = mi->r[mrr_ndx[i - 1]].rix;
341 ar[i].limit = mi->r[mrr_ndx[i]].adjusted_retry_count; 347 ar[i].count = mi->r[mrr_ndx[i - 1]].adjusted_retry_count;
342 } 348 }
343} 349}
344 350
@@ -415,6 +421,7 @@ minstrel_rate_init(void *priv, struct ieee80211_supported_band *sband,
415 421
416 /* calculate maximum number of retransmissions before 422 /* calculate maximum number of retransmissions before
417 * fallback (based on maximum segment size) */ 423 * fallback (based on maximum segment size) */
424 mr->sample_limit = -1;
418 mr->retry_count = 1; 425 mr->retry_count = 1;
419 mr->retry_count_cts = 1; 426 mr->retry_count_cts = 1;
420 mr->retry_count_rtscts = 1; 427 mr->retry_count_rtscts = 1;
@@ -500,11 +507,6 @@ minstrel_free_sta(void *priv, struct ieee80211_sta *sta, void *priv_sta)
500 kfree(mi); 507 kfree(mi);
501} 508}
502 509
503static void
504minstrel_clear(void *priv)
505{
506}
507
508static void * 510static void *
509minstrel_alloc(struct ieee80211_hw *hw, struct dentry *debugfsdir) 511minstrel_alloc(struct ieee80211_hw *hw, struct dentry *debugfsdir)
510{ 512{
@@ -532,13 +534,13 @@ minstrel_alloc(struct ieee80211_hw *hw, struct dentry *debugfsdir)
532 /* maximum time that the hw is allowed to stay in one MRR segment */ 534 /* maximum time that the hw is allowed to stay in one MRR segment */
533 mp->segment_size = 6000; 535 mp->segment_size = 6000;
534 536
535 if (hw->max_altrate_tries > 0) 537 if (hw->max_rate_tries > 0)
536 mp->max_retry = hw->max_altrate_tries; 538 mp->max_retry = hw->max_rate_tries;
537 else 539 else
538 /* safe default, does not necessarily have to match hw properties */ 540 /* safe default, does not necessarily have to match hw properties */
539 mp->max_retry = 7; 541 mp->max_retry = 7;
540 542
541 if (hw->max_altrates >= 3) 543 if (hw->max_rates >= 4)
542 mp->has_mrr = true; 544 mp->has_mrr = true;
543 545
544 mp->hw = hw; 546 mp->hw = hw;
@@ -558,7 +560,6 @@ static struct rate_control_ops mac80211_minstrel = {
558 .tx_status = minstrel_tx_status, 560 .tx_status = minstrel_tx_status,
559 .get_rate = minstrel_get_rate, 561 .get_rate = minstrel_get_rate,
560 .rate_init = minstrel_rate_init, 562 .rate_init = minstrel_rate_init,
561 .clear = minstrel_clear,
562 .alloc = minstrel_alloc, 563 .alloc = minstrel_alloc,
563 .free = minstrel_free, 564 .free = minstrel_free,
564 .alloc_sta = minstrel_alloc_sta, 565 .alloc_sta = minstrel_alloc_sta,
diff --git a/net/mac80211/rc80211_minstrel.h b/net/mac80211/rc80211_minstrel.h
index 9a90a6aee043..869fe0ef951d 100644
--- a/net/mac80211/rc80211_minstrel.h
+++ b/net/mac80211/rc80211_minstrel.h
@@ -16,6 +16,7 @@ struct minstrel_rate {
16 unsigned int perfect_tx_time; 16 unsigned int perfect_tx_time;
17 unsigned int ack_time; 17 unsigned int ack_time;
18 18
19 int sample_limit;
19 unsigned int retry_count; 20 unsigned int retry_count;
20 unsigned int retry_count_cts; 21 unsigned int retry_count_cts;
21 unsigned int retry_count_rtscts; 22 unsigned int retry_count_rtscts;
@@ -57,6 +58,7 @@ struct minstrel_sta_info {
57 58
58 int n_rates; 59 int n_rates;
59 struct minstrel_rate *r; 60 struct minstrel_rate *r;
61 bool prev_sample;
60 62
61 /* sampling table */ 63 /* sampling table */
62 u8 *sample_table; 64 u8 *sample_table;
diff --git a/net/mac80211/rc80211_pid.h b/net/mac80211/rc80211_pid.h
index 01d64d53f3b9..1a873f00691a 100644
--- a/net/mac80211/rc80211_pid.h
+++ b/net/mac80211/rc80211_pid.h
@@ -49,7 +49,7 @@
49 49
50/* Arithmetic right shift for positive and negative values for ISO C. */ 50/* Arithmetic right shift for positive and negative values for ISO C. */
51#define RC_PID_DO_ARITH_RIGHT_SHIFT(x, y) \ 51#define RC_PID_DO_ARITH_RIGHT_SHIFT(x, y) \
52 (x) < 0 ? -((-(x)) >> (y)) : (x) >> (y) 52 ((x) < 0 ? -((-(x)) >> (y)) : (x) >> (y))
53 53
54enum rc_pid_event_type { 54enum rc_pid_event_type {
55 RC_PID_EVENT_TYPE_TX_STATUS, 55 RC_PID_EVENT_TYPE_TX_STATUS,
@@ -61,6 +61,7 @@ enum rc_pid_event_type {
61union rc_pid_event_data { 61union rc_pid_event_data {
62 /* RC_PID_EVENT_TX_STATUS */ 62 /* RC_PID_EVENT_TX_STATUS */
63 struct { 63 struct {
64 u32 flags;
64 struct ieee80211_tx_info tx_status; 65 struct ieee80211_tx_info tx_status;
65 }; 66 };
66 /* RC_PID_EVENT_TYPE_RATE_CHANGE */ 67 /* RC_PID_EVENT_TYPE_RATE_CHANGE */
diff --git a/net/mac80211/rc80211_pid_algo.c b/net/mac80211/rc80211_pid_algo.c
index 86eb374e3b87..b16801cde06f 100644
--- a/net/mac80211/rc80211_pid_algo.c
+++ b/net/mac80211/rc80211_pid_algo.c
@@ -241,7 +241,7 @@ static void rate_control_pid_tx_status(void *priv, struct ieee80211_supported_ba
241 241
242 /* Ignore all frames that were sent with a different rate than the rate 242 /* Ignore all frames that were sent with a different rate than the rate
243 * we currently advise mac80211 to use. */ 243 * we currently advise mac80211 to use. */
244 if (info->tx_rate_idx != spinfo->txrate_idx) 244 if (info->status.rates[0].idx != spinfo->txrate_idx)
245 return; 245 return;
246 246
247 spinfo->tx_num_xmit++; 247 spinfo->tx_num_xmit++;
@@ -253,10 +253,10 @@ static void rate_control_pid_tx_status(void *priv, struct ieee80211_supported_ba
253 /* We count frames that totally failed to be transmitted as two bad 253 /* We count frames that totally failed to be transmitted as two bad
254 * frames, those that made it out but had some retries as one good and 254 * frames, those that made it out but had some retries as one good and
255 * one bad frame. */ 255 * one bad frame. */
256 if (info->status.excessive_retries) { 256 if (!(info->flags & IEEE80211_TX_STAT_ACK)) {
257 spinfo->tx_num_failed += 2; 257 spinfo->tx_num_failed += 2;
258 spinfo->tx_num_xmit++; 258 spinfo->tx_num_xmit++;
259 } else if (info->status.retry_count) { 259 } else if (info->status.rates[0].count > 1) {
260 spinfo->tx_num_failed++; 260 spinfo->tx_num_failed++;
261 spinfo->tx_num_xmit++; 261 spinfo->tx_num_xmit++;
262 } 262 }
@@ -270,23 +270,32 @@ static void rate_control_pid_tx_status(void *priv, struct ieee80211_supported_ba
270} 270}
271 271
272static void 272static void
273rate_control_pid_get_rate(void *priv, struct ieee80211_supported_band *sband, 273rate_control_pid_get_rate(void *priv, struct ieee80211_sta *sta,
274 struct ieee80211_sta *sta, void *priv_sta, 274 void *priv_sta,
275 struct sk_buff *skb, 275 struct ieee80211_tx_rate_control *txrc)
276 struct rate_selection *sel)
277{ 276{
277 struct sk_buff *skb = txrc->skb;
278 struct ieee80211_supported_band *sband = txrc->sband;
278 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; 279 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
280 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
279 struct rc_pid_sta_info *spinfo = priv_sta; 281 struct rc_pid_sta_info *spinfo = priv_sta;
280 int rateidx; 282 int rateidx;
281 u16 fc; 283 u16 fc;
282 284
285 if (txrc->rts)
286 info->control.rates[0].count =
287 txrc->hw->conf.long_frame_max_tx_count;
288 else
289 info->control.rates[0].count =
290 txrc->hw->conf.short_frame_max_tx_count;
291
283 /* Send management frames and broadcast/multicast data using lowest 292 /* Send management frames and broadcast/multicast data using lowest
284 * rate. */ 293 * rate. */
285 fc = le16_to_cpu(hdr->frame_control); 294 fc = le16_to_cpu(hdr->frame_control);
286 if (!sta || !spinfo || 295 if (!sta || !spinfo ||
287 (fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA || 296 (fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA ||
288 is_multicast_ether_addr(hdr->addr1)) { 297 is_multicast_ether_addr(hdr->addr1)) {
289 sel->rate_idx = rate_lowest_index(sband, sta); 298 info->control.rates[0].idx = rate_lowest_index(sband, sta);
290 return; 299 return;
291 } 300 }
292 301
@@ -295,7 +304,7 @@ rate_control_pid_get_rate(void *priv, struct ieee80211_supported_band *sband,
295 if (rateidx >= sband->n_bitrates) 304 if (rateidx >= sband->n_bitrates)
296 rateidx = sband->n_bitrates - 1; 305 rateidx = sband->n_bitrates - 1;
297 306
298 sel->rate_idx = rateidx; 307 info->control.rates[0].idx = rateidx;
299 308
300#ifdef CONFIG_MAC80211_DEBUGFS 309#ifdef CONFIG_MAC80211_DEBUGFS
301 rate_control_pid_event_tx_rate(&spinfo->events, 310 rate_control_pid_event_tx_rate(&spinfo->events,
@@ -394,11 +403,11 @@ static void *rate_control_pid_alloc(struct ieee80211_hw *hw,
394 S_IRUSR | S_IWUSR, debugfsdir, 403 S_IRUSR | S_IWUSR, debugfsdir,
395 &pinfo->sampling_period); 404 &pinfo->sampling_period);
396 de->coeff_p = debugfs_create_u32("coeff_p", S_IRUSR | S_IWUSR, 405 de->coeff_p = debugfs_create_u32("coeff_p", S_IRUSR | S_IWUSR,
397 debugfsdir, &pinfo->coeff_p); 406 debugfsdir, (u32 *)&pinfo->coeff_p);
398 de->coeff_i = debugfs_create_u32("coeff_i", S_IRUSR | S_IWUSR, 407 de->coeff_i = debugfs_create_u32("coeff_i", S_IRUSR | S_IWUSR,
399 debugfsdir, &pinfo->coeff_i); 408 debugfsdir, (u32 *)&pinfo->coeff_i);
400 de->coeff_d = debugfs_create_u32("coeff_d", S_IRUSR | S_IWUSR, 409 de->coeff_d = debugfs_create_u32("coeff_d", S_IRUSR | S_IWUSR,
401 debugfsdir, &pinfo->coeff_d); 410 debugfsdir, (u32 *)&pinfo->coeff_d);
402 de->smoothing_shift = debugfs_create_u32("smoothing_shift", 411 de->smoothing_shift = debugfs_create_u32("smoothing_shift",
403 S_IRUSR | S_IWUSR, debugfsdir, 412 S_IRUSR | S_IWUSR, debugfsdir,
404 &pinfo->smoothing_shift); 413 &pinfo->smoothing_shift);
@@ -437,10 +446,6 @@ static void rate_control_pid_free(void *priv)
437 kfree(pinfo); 446 kfree(pinfo);
438} 447}
439 448
440static void rate_control_pid_clear(void *priv)
441{
442}
443
444static void *rate_control_pid_alloc_sta(void *priv, struct ieee80211_sta *sta, 449static void *rate_control_pid_alloc_sta(void *priv, struct ieee80211_sta *sta,
445 gfp_t gfp) 450 gfp_t gfp)
446{ 451{
@@ -471,7 +476,6 @@ static struct rate_control_ops mac80211_rcpid = {
471 .tx_status = rate_control_pid_tx_status, 476 .tx_status = rate_control_pid_tx_status,
472 .get_rate = rate_control_pid_get_rate, 477 .get_rate = rate_control_pid_get_rate,
473 .rate_init = rate_control_pid_rate_init, 478 .rate_init = rate_control_pid_rate_init,
474 .clear = rate_control_pid_clear,
475 .alloc = rate_control_pid_alloc, 479 .alloc = rate_control_pid_alloc,
476 .free = rate_control_pid_free, 480 .free = rate_control_pid_free,
477 .alloc_sta = rate_control_pid_alloc_sta, 481 .alloc_sta = rate_control_pid_alloc_sta,
diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
index 8121d3bc6835..a08a9b530347 100644
--- a/net/mac80211/rc80211_pid_debugfs.c
+++ b/net/mac80211/rc80211_pid_debugfs.c
@@ -43,6 +43,7 @@ void rate_control_pid_event_tx_status(struct rc_pid_event_buffer *buf,
43{ 43{
44 union rc_pid_event_data evd; 44 union rc_pid_event_data evd;
45 45
46 evd.flags = stat->flags;
46 memcpy(&evd.tx_status, stat, sizeof(struct ieee80211_tx_info)); 47 memcpy(&evd.tx_status, stat, sizeof(struct ieee80211_tx_info));
47 rate_control_pid_event(buf, RC_PID_EVENT_TYPE_TX_STATUS, &evd); 48 rate_control_pid_event(buf, RC_PID_EVENT_TYPE_TX_STATUS, &evd);
48} 49}
@@ -167,8 +168,8 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
167 switch (ev->type) { 168 switch (ev->type) {
168 case RC_PID_EVENT_TYPE_TX_STATUS: 169 case RC_PID_EVENT_TYPE_TX_STATUS:
169 p += snprintf(pb + p, length - p, "tx_status %u %u", 170 p += snprintf(pb + p, length - p, "tx_status %u %u",
170 ev->data.tx_status.status.excessive_retries, 171 !(ev->data.flags & IEEE80211_TX_STAT_ACK),
171 ev->data.tx_status.status.retry_count); 172 ev->data.tx_status.status.rates[0].idx);
172 break; 173 break;
173 case RC_PID_EVENT_TYPE_RATE_CHANGE: 174 case RC_PID_EVENT_TYPE_RATE_CHANGE:
174 p += snprintf(pb + p, length - p, "rate_change %d %d", 175 p += snprintf(pb + p, length - p, "rate_change %d %d",
diff --git a/net/mac80211/rx.c b/net/mac80211/rx.c
index cf6b121e1bbf..7175ae80c36a 100644
--- a/net/mac80211/rx.c
+++ b/net/mac80211/rx.c
@@ -26,10 +26,11 @@
26#include "tkip.h" 26#include "tkip.h"
27#include "wme.h" 27#include "wme.h"
28 28
29u8 ieee80211_sta_manage_reorder_buf(struct ieee80211_hw *hw, 29static u8 ieee80211_sta_manage_reorder_buf(struct ieee80211_hw *hw,
30 struct tid_ampdu_rx *tid_agg_rx, 30 struct tid_ampdu_rx *tid_agg_rx,
31 struct sk_buff *skb, u16 mpdu_seq_num, 31 struct sk_buff *skb,
32 int bar_req); 32 u16 mpdu_seq_num,
33 int bar_req);
33/* 34/*
34 * monitor mode reception 35 * monitor mode reception
35 * 36 *
@@ -122,7 +123,6 @@ ieee80211_add_rx_radiotap_header(struct ieee80211_local *local,
122 /* radiotap header, set always present flags */ 123 /* radiotap header, set always present flags */
123 rthdr->it_present = 124 rthdr->it_present =
124 cpu_to_le32((1 << IEEE80211_RADIOTAP_FLAGS) | 125 cpu_to_le32((1 << IEEE80211_RADIOTAP_FLAGS) |
125 (1 << IEEE80211_RADIOTAP_RATE) |
126 (1 << IEEE80211_RADIOTAP_CHANNEL) | 126 (1 << IEEE80211_RADIOTAP_CHANNEL) |
127 (1 << IEEE80211_RADIOTAP_ANTENNA) | 127 (1 << IEEE80211_RADIOTAP_ANTENNA) |
128 (1 << IEEE80211_RADIOTAP_RX_FLAGS)); 128 (1 << IEEE80211_RADIOTAP_RX_FLAGS));
@@ -148,7 +148,19 @@ ieee80211_add_rx_radiotap_header(struct ieee80211_local *local,
148 pos++; 148 pos++;
149 149
150 /* IEEE80211_RADIOTAP_RATE */ 150 /* IEEE80211_RADIOTAP_RATE */
151 *pos = rate->bitrate / 5; 151 if (status->flag & RX_FLAG_HT) {
152 /*
153 * TODO: add following information into radiotap header once
154 * suitable fields are defined for it:
155 * - MCS index (status->rate_idx)
156 * - HT40 (status->flag & RX_FLAG_40MHZ)
157 * - short-GI (status->flag & RX_FLAG_SHORT_GI)
158 */
159 *pos = 0;
160 } else {
161 rthdr->it_present |= (1 << IEEE80211_RADIOTAP_RATE);
162 *pos = rate->bitrate / 5;
163 }
152 pos++; 164 pos++;
153 165
154 /* IEEE80211_RADIOTAP_CHANNEL */ 166 /* IEEE80211_RADIOTAP_CHANNEL */
@@ -653,13 +665,16 @@ ieee80211_rx_h_decrypt(struct ieee80211_rx_data *rx)
653static void ap_sta_ps_start(struct sta_info *sta) 665static void ap_sta_ps_start(struct sta_info *sta)
654{ 666{
655 struct ieee80211_sub_if_data *sdata = sta->sdata; 667 struct ieee80211_sub_if_data *sdata = sta->sdata;
656 DECLARE_MAC_BUF(mac); 668 struct ieee80211_local *local = sdata->local;
657 669
658 atomic_inc(&sdata->bss->num_sta_ps); 670 atomic_inc(&sdata->bss->num_sta_ps);
659 set_and_clear_sta_flags(sta, WLAN_STA_PS, WLAN_STA_PSPOLL); 671 set_and_clear_sta_flags(sta, WLAN_STA_PS, WLAN_STA_PSPOLL);
672 if (local->ops->sta_notify)
673 local->ops->sta_notify(local_to_hw(local), &sdata->vif,
674 STA_NOTIFY_SLEEP, &sta->sta);
660#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG 675#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
661 printk(KERN_DEBUG "%s: STA %s aid %d enters power save mode\n", 676 printk(KERN_DEBUG "%s: STA %pM aid %d enters power save mode\n",
662 sdata->dev->name, print_mac(mac, sta->sta.addr), sta->sta.aid); 677 sdata->dev->name, sta->sta.addr, sta->sta.aid);
663#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */ 678#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
664} 679}
665 680
@@ -669,38 +684,37 @@ static int ap_sta_ps_end(struct sta_info *sta)
669 struct ieee80211_local *local = sdata->local; 684 struct ieee80211_local *local = sdata->local;
670 struct sk_buff *skb; 685 struct sk_buff *skb;
671 int sent = 0; 686 int sent = 0;
672 struct ieee80211_tx_info *info;
673 DECLARE_MAC_BUF(mac);
674 687
675 atomic_dec(&sdata->bss->num_sta_ps); 688 atomic_dec(&sdata->bss->num_sta_ps);
676 689
677 clear_sta_flags(sta, WLAN_STA_PS | WLAN_STA_PSPOLL); 690 clear_sta_flags(sta, WLAN_STA_PS | WLAN_STA_PSPOLL);
691 if (local->ops->sta_notify)
692 local->ops->sta_notify(local_to_hw(local), &sdata->vif,
693 STA_NOTIFY_AWAKE, &sta->sta);
678 694
679 if (!skb_queue_empty(&sta->ps_tx_buf)) 695 if (!skb_queue_empty(&sta->ps_tx_buf))
680 sta_info_clear_tim_bit(sta); 696 sta_info_clear_tim_bit(sta);
681 697
682#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG 698#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
683 printk(KERN_DEBUG "%s: STA %s aid %d exits power save mode\n", 699 printk(KERN_DEBUG "%s: STA %pM aid %d exits power save mode\n",
684 sdata->dev->name, print_mac(mac, sta->sta.addr), sta->sta.aid); 700 sdata->dev->name, sta->sta.addr, sta->sta.aid);
685#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */ 701#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
686 702
687 /* Send all buffered frames to the station */ 703 /* Send all buffered frames to the station */
688 while ((skb = skb_dequeue(&sta->tx_filtered)) != NULL) { 704 while ((skb = skb_dequeue(&sta->tx_filtered)) != NULL) {
689 info = IEEE80211_SKB_CB(skb);
690 sent++; 705 sent++;
691 info->flags |= IEEE80211_TX_CTL_REQUEUE; 706 skb->requeue = 1;
692 dev_queue_xmit(skb); 707 dev_queue_xmit(skb);
693 } 708 }
694 while ((skb = skb_dequeue(&sta->ps_tx_buf)) != NULL) { 709 while ((skb = skb_dequeue(&sta->ps_tx_buf)) != NULL) {
695 info = IEEE80211_SKB_CB(skb);
696 local->total_ps_buffered--; 710 local->total_ps_buffered--;
697 sent++; 711 sent++;
698#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG 712#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
699 printk(KERN_DEBUG "%s: STA %s aid %d send PS frame " 713 printk(KERN_DEBUG "%s: STA %pM aid %d send PS frame "
700 "since STA not sleeping anymore\n", sdata->dev->name, 714 "since STA not sleeping anymore\n", sdata->dev->name,
701 print_mac(mac, sta->sta.addr), sta->sta.aid); 715 sta->sta.addr, sta->sta.aid);
702#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */ 716#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
703 info->flags |= IEEE80211_TX_CTL_REQUEUE; 717 skb->requeue = 1;
704 dev_queue_xmit(skb); 718 dev_queue_xmit(skb);
705 } 719 }
706 720
@@ -745,17 +759,29 @@ ieee80211_rx_h_sta_process(struct ieee80211_rx_data *rx)
745 sta->last_qual = rx->status->qual; 759 sta->last_qual = rx->status->qual;
746 sta->last_noise = rx->status->noise; 760 sta->last_noise = rx->status->noise;
747 761
762 /*
763 * Change STA power saving mode only at the end of a frame
764 * exchange sequence.
765 */
748 if (!ieee80211_has_morefrags(hdr->frame_control) && 766 if (!ieee80211_has_morefrags(hdr->frame_control) &&
749 (rx->sdata->vif.type == NL80211_IFTYPE_AP || 767 (rx->sdata->vif.type == NL80211_IFTYPE_AP ||
750 rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN)) { 768 rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN)) {
751 /* Change STA power saving mode only in the end of a frame 769 if (test_sta_flags(sta, WLAN_STA_PS)) {
752 * exchange sequence */ 770 /*
753 if (test_sta_flags(sta, WLAN_STA_PS) && 771 * Ignore doze->wake transitions that are
754 !ieee80211_has_pm(hdr->frame_control)) 772 * indicated by non-data frames, the standard
755 rx->sent_ps_buffered += ap_sta_ps_end(sta); 773 * is unclear here, but for example going to
756 else if (!test_sta_flags(sta, WLAN_STA_PS) && 774 * PS mode and then scanning would cause a
757 ieee80211_has_pm(hdr->frame_control)) 775 * doze->wake transition for the probe request,
758 ap_sta_ps_start(sta); 776 * and that is clearly undesirable.
777 */
778 if (ieee80211_is_data(hdr->frame_control) &&
779 !ieee80211_has_pm(hdr->frame_control))
780 rx->sent_ps_buffered += ap_sta_ps_end(sta);
781 } else {
782 if (ieee80211_has_pm(hdr->frame_control))
783 ap_sta_ps_start(sta);
784 }
759 } 785 }
760 786
761 /* Drop data::nullfunc frames silently, since they are used only to 787 /* Drop data::nullfunc frames silently, since they are used only to
@@ -789,15 +815,12 @@ ieee80211_reassemble_add(struct ieee80211_sub_if_data *sdata,
789#ifdef CONFIG_MAC80211_VERBOSE_DEBUG 815#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
790 struct ieee80211_hdr *hdr = 816 struct ieee80211_hdr *hdr =
791 (struct ieee80211_hdr *) entry->skb_list.next->data; 817 (struct ieee80211_hdr *) entry->skb_list.next->data;
792 DECLARE_MAC_BUF(mac);
793 DECLARE_MAC_BUF(mac2);
794 printk(KERN_DEBUG "%s: RX reassembly removed oldest " 818 printk(KERN_DEBUG "%s: RX reassembly removed oldest "
795 "fragment entry (idx=%d age=%lu seq=%d last_frag=%d " 819 "fragment entry (idx=%d age=%lu seq=%d last_frag=%d "
796 "addr1=%s addr2=%s\n", 820 "addr1=%pM addr2=%pM\n",
797 sdata->dev->name, idx, 821 sdata->dev->name, idx,
798 jiffies - entry->first_frag_time, entry->seq, 822 jiffies - entry->first_frag_time, entry->seq,
799 entry->last_frag, print_mac(mac, hdr->addr1), 823 entry->last_frag, hdr->addr1, hdr->addr2);
800 print_mac(mac2, hdr->addr2));
801#endif 824#endif
802 __skb_queue_purge(&entry->skb_list); 825 __skb_queue_purge(&entry->skb_list);
803 } 826 }
@@ -866,7 +889,6 @@ ieee80211_rx_h_defragment(struct ieee80211_rx_data *rx)
866 unsigned int frag, seq; 889 unsigned int frag, seq;
867 struct ieee80211_fragment_entry *entry; 890 struct ieee80211_fragment_entry *entry;
868 struct sk_buff *skb; 891 struct sk_buff *skb;
869 DECLARE_MAC_BUF(mac);
870 892
871 hdr = (struct ieee80211_hdr *)rx->skb->data; 893 hdr = (struct ieee80211_hdr *)rx->skb->data;
872 fc = hdr->frame_control; 894 fc = hdr->frame_control;
@@ -970,7 +992,6 @@ ieee80211_rx_h_ps_poll(struct ieee80211_rx_data *rx)
970 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(rx->dev); 992 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(rx->dev);
971 struct sk_buff *skb; 993 struct sk_buff *skb;
972 int no_pending_pkts; 994 int no_pending_pkts;
973 DECLARE_MAC_BUF(mac);
974 __le16 fc = ((struct ieee80211_hdr *)rx->skb->data)->frame_control; 995 __le16 fc = ((struct ieee80211_hdr *)rx->skb->data)->frame_control;
975 996
976 if (likely(!rx->sta || !ieee80211_is_pspoll(fc) || 997 if (likely(!rx->sta || !ieee80211_is_pspoll(fc) ||
@@ -1001,8 +1022,8 @@ ieee80211_rx_h_ps_poll(struct ieee80211_rx_data *rx)
1001 set_sta_flags(rx->sta, WLAN_STA_PSPOLL); 1022 set_sta_flags(rx->sta, WLAN_STA_PSPOLL);
1002 1023
1003#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG 1024#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
1004 printk(KERN_DEBUG "STA %s aid %d: PS Poll (entries after %d)\n", 1025 printk(KERN_DEBUG "STA %pM aid %d: PS Poll (entries after %d)\n",
1005 print_mac(mac, rx->sta->sta.addr), rx->sta->sta.aid, 1026 rx->sta->sta.addr, rx->sta->sta.aid,
1006 skb_queue_len(&rx->sta->ps_tx_buf)); 1027 skb_queue_len(&rx->sta->ps_tx_buf));
1007#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */ 1028#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
1008 1029
@@ -1025,9 +1046,9 @@ ieee80211_rx_h_ps_poll(struct ieee80211_rx_data *rx)
1025 * Should we send it a null-func frame indicating we 1046 * Should we send it a null-func frame indicating we
1026 * have nothing buffered for it? 1047 * have nothing buffered for it?
1027 */ 1048 */
1028 printk(KERN_DEBUG "%s: STA %s sent PS Poll even " 1049 printk(KERN_DEBUG "%s: STA %pM sent PS Poll even "
1029 "though there are no buffered frames for it\n", 1050 "though there are no buffered frames for it\n",
1030 rx->dev->name, print_mac(mac, rx->sta->sta.addr)); 1051 rx->dev->name, rx->sta->sta.addr);
1031#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */ 1052#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
1032 } 1053 }
1033 1054
@@ -1097,10 +1118,6 @@ ieee80211_data_to_8023(struct ieee80211_rx_data *rx)
1097 u8 src[ETH_ALEN] __aligned(2); 1118 u8 src[ETH_ALEN] __aligned(2);
1098 struct sk_buff *skb = rx->skb; 1119 struct sk_buff *skb = rx->skb;
1099 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 1120 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1100 DECLARE_MAC_BUF(mac);
1101 DECLARE_MAC_BUF(mac2);
1102 DECLARE_MAC_BUF(mac3);
1103 DECLARE_MAC_BUF(mac4);
1104 1121
1105 if (unlikely(!ieee80211_is_data_present(hdr->frame_control))) 1122 if (unlikely(!ieee80211_is_data_present(hdr->frame_control)))
1106 return -1; 1123 return -1;
@@ -1279,7 +1296,6 @@ ieee80211_rx_h_amsdu(struct ieee80211_rx_data *rx)
1279 int remaining, err; 1296 int remaining, err;
1280 u8 dst[ETH_ALEN]; 1297 u8 dst[ETH_ALEN];
1281 u8 src[ETH_ALEN]; 1298 u8 src[ETH_ALEN];
1282 DECLARE_MAC_BUF(mac);
1283 1299
1284 if (unlikely(!ieee80211_is_data(fc))) 1300 if (unlikely(!ieee80211_is_data(fc)))
1285 return RX_CONTINUE; 1301 return RX_CONTINUE;
@@ -1552,14 +1568,6 @@ ieee80211_rx_h_action(struct ieee80211_rx_data *rx)
1552 if (len < IEEE80211_MIN_ACTION_SIZE + 1) 1568 if (len < IEEE80211_MIN_ACTION_SIZE + 1)
1553 return RX_DROP_MONITOR; 1569 return RX_DROP_MONITOR;
1554 1570
1555 /*
1556 * FIXME: revisit this, I'm sure we should handle most
1557 * of these frames in other modes as well!
1558 */
1559 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
1560 sdata->vif.type != NL80211_IFTYPE_ADHOC)
1561 return RX_CONTINUE;
1562
1563 switch (mgmt->u.action.category) { 1571 switch (mgmt->u.action.category) {
1564 case WLAN_CATEGORY_BACK: 1572 case WLAN_CATEGORY_BACK:
1565 switch (mgmt->u.action.u.addba_req.action_code) { 1573 switch (mgmt->u.action.u.addba_req.action_code) {
@@ -1632,8 +1640,6 @@ static void ieee80211_rx_michael_mic_report(struct net_device *dev,
1632{ 1640{
1633 int keyidx; 1641 int keyidx;
1634 unsigned int hdrlen; 1642 unsigned int hdrlen;
1635 DECLARE_MAC_BUF(mac);
1636 DECLARE_MAC_BUF(mac2);
1637 1643
1638 hdrlen = ieee80211_hdrlen(hdr->frame_control); 1644 hdrlen = ieee80211_hdrlen(hdr->frame_control);
1639 if (rx->skb->len >= hdrlen + 4) 1645 if (rx->skb->len >= hdrlen + 4)
@@ -1854,10 +1860,15 @@ static int prepare_for_handlers(struct ieee80211_sub_if_data *sdata,
1854 if (!(sdata->dev->flags & IFF_PROMISC)) 1860 if (!(sdata->dev->flags & IFF_PROMISC))
1855 return 0; 1861 return 0;
1856 rx->flags &= ~IEEE80211_RX_RA_MATCH; 1862 rx->flags &= ~IEEE80211_RX_RA_MATCH;
1857 } else if (!rx->sta) 1863 } else if (!rx->sta) {
1858 rx->sta = ieee80211_ibss_add_sta(sdata, rx->skb, 1864 int rate_idx;
1859 bssid, hdr->addr2, 1865 if (rx->status->flag & RX_FLAG_HT)
1860 BIT(rx->status->rate_idx)); 1866 rate_idx = 0; /* TODO: HT rates */
1867 else
1868 rate_idx = rx->status->rate_idx;
1869 rx->sta = ieee80211_ibss_add_sta(sdata, bssid, hdr->addr2,
1870 BIT(rate_idx));
1871 }
1861 break; 1872 break;
1862 case NL80211_IFTYPE_MESH_POINT: 1873 case NL80211_IFTYPE_MESH_POINT:
1863 if (!multicast && 1874 if (!multicast &&
@@ -2002,17 +2013,17 @@ static void __ieee80211_rx_handle_packet(struct ieee80211_hw *hw,
2002 2013
2003static inline int seq_less(u16 sq1, u16 sq2) 2014static inline int seq_less(u16 sq1, u16 sq2)
2004{ 2015{
2005 return (((sq1 - sq2) & SEQ_MASK) > (SEQ_MODULO >> 1)); 2016 return ((sq1 - sq2) & SEQ_MASK) > (SEQ_MODULO >> 1);
2006} 2017}
2007 2018
2008static inline u16 seq_inc(u16 sq) 2019static inline u16 seq_inc(u16 sq)
2009{ 2020{
2010 return ((sq + 1) & SEQ_MASK); 2021 return (sq + 1) & SEQ_MASK;
2011} 2022}
2012 2023
2013static inline u16 seq_sub(u16 sq1, u16 sq2) 2024static inline u16 seq_sub(u16 sq1, u16 sq2)
2014{ 2025{
2015 return ((sq1 - sq2) & SEQ_MASK); 2026 return (sq1 - sq2) & SEQ_MASK;
2016} 2027}
2017 2028
2018 2029
@@ -2020,10 +2031,11 @@ static inline u16 seq_sub(u16 sq1, u16 sq2)
2020 * As it function blongs to Rx path it must be called with 2031 * As it function blongs to Rx path it must be called with
2021 * the proper rcu_read_lock protection for its flow. 2032 * the proper rcu_read_lock protection for its flow.
2022 */ 2033 */
2023u8 ieee80211_sta_manage_reorder_buf(struct ieee80211_hw *hw, 2034static u8 ieee80211_sta_manage_reorder_buf(struct ieee80211_hw *hw,
2024 struct tid_ampdu_rx *tid_agg_rx, 2035 struct tid_ampdu_rx *tid_agg_rx,
2025 struct sk_buff *skb, u16 mpdu_seq_num, 2036 struct sk_buff *skb,
2026 int bar_req) 2037 u16 mpdu_seq_num,
2038 int bar_req)
2027{ 2039{
2028 struct ieee80211_local *local = hw_to_local(hw); 2040 struct ieee80211_local *local = hw_to_local(hw);
2029 struct ieee80211_rx_status status; 2041 struct ieee80211_rx_status status;
@@ -2062,7 +2074,13 @@ u8 ieee80211_sta_manage_reorder_buf(struct ieee80211_hw *hw,
2062 tid_agg_rx->reorder_buf[index]->cb, 2074 tid_agg_rx->reorder_buf[index]->cb,
2063 sizeof(status)); 2075 sizeof(status));
2064 sband = local->hw.wiphy->bands[status.band]; 2076 sband = local->hw.wiphy->bands[status.band];
2065 rate = &sband->bitrates[status.rate_idx]; 2077 if (status.flag & RX_FLAG_HT) {
2078 /* TODO: HT rates */
2079 rate = sband->bitrates;
2080 } else {
2081 rate = &sband->bitrates
2082 [status.rate_idx];
2083 }
2066 __ieee80211_rx_handle_packet(hw, 2084 __ieee80211_rx_handle_packet(hw,
2067 tid_agg_rx->reorder_buf[index], 2085 tid_agg_rx->reorder_buf[index],
2068 &status, rate); 2086 &status, rate);
@@ -2106,7 +2124,10 @@ u8 ieee80211_sta_manage_reorder_buf(struct ieee80211_hw *hw,
2106 memcpy(&status, tid_agg_rx->reorder_buf[index]->cb, 2124 memcpy(&status, tid_agg_rx->reorder_buf[index]->cb,
2107 sizeof(status)); 2125 sizeof(status));
2108 sband = local->hw.wiphy->bands[status.band]; 2126 sband = local->hw.wiphy->bands[status.band];
2109 rate = &sband->bitrates[status.rate_idx]; 2127 if (status.flag & RX_FLAG_HT)
2128 rate = sband->bitrates; /* TODO: HT rates */
2129 else
2130 rate = &sband->bitrates[status.rate_idx];
2110 __ieee80211_rx_handle_packet(hw, tid_agg_rx->reorder_buf[index], 2131 __ieee80211_rx_handle_packet(hw, tid_agg_rx->reorder_buf[index],
2111 &status, rate); 2132 &status, rate);
2112 tid_agg_rx->stored_mpdu_num--; 2133 tid_agg_rx->stored_mpdu_num--;
@@ -2194,15 +2215,26 @@ void __ieee80211_rx(struct ieee80211_hw *hw, struct sk_buff *skb,
2194 } 2215 }
2195 2216
2196 sband = local->hw.wiphy->bands[status->band]; 2217 sband = local->hw.wiphy->bands[status->band];
2197 2218 if (!sband) {
2198 if (!sband ||
2199 status->rate_idx < 0 ||
2200 status->rate_idx >= sband->n_bitrates) {
2201 WARN_ON(1); 2219 WARN_ON(1);
2202 return; 2220 return;
2203 } 2221 }
2204 2222
2205 rate = &sband->bitrates[status->rate_idx]; 2223 if (status->flag & RX_FLAG_HT) {
2224 /* rate_idx is MCS index */
2225 if (WARN_ON(status->rate_idx < 0 ||
2226 status->rate_idx >= 76))
2227 return;
2228 /* HT rates are not in the table - use the highest legacy rate
2229 * for now since other parts of mac80211 may not yet be fully
2230 * MCS aware. */
2231 rate = &sband->bitrates[sband->n_bitrates - 1];
2232 } else {
2233 if (WARN_ON(status->rate_idx < 0 ||
2234 status->rate_idx >= sband->n_bitrates))
2235 return;
2236 rate = &sband->bitrates[status->rate_idx];
2237 }
2206 2238
2207 /* 2239 /*
2208 * key references and virtual interfaces are protected using RCU 2240 * key references and virtual interfaces are protected using RCU
diff --git a/net/mac80211/scan.c b/net/mac80211/scan.c
index 416bb41099f3..f5c7c3371929 100644
--- a/net/mac80211/scan.c
+++ b/net/mac80211/scan.c
@@ -159,7 +159,7 @@ ieee80211_rx_mesh_bss_add(struct ieee80211_local *local, u8 *mesh_id, int mesh_i
159{ 159{
160 struct ieee80211_bss *bss; 160 struct ieee80211_bss *bss;
161 161
162 if (mesh_config_len != MESH_CFG_LEN) 162 if (mesh_config_len != IEEE80211_MESH_CONFIG_LEN)
163 return NULL; 163 return NULL;
164 164
165 bss = kzalloc(sizeof(*bss), GFP_ATOMIC); 165 bss = kzalloc(sizeof(*bss), GFP_ATOMIC);
@@ -448,18 +448,17 @@ void ieee80211_scan_completed(struct ieee80211_hw *hw)
448 448
449 if (local->hw_scanning) { 449 if (local->hw_scanning) {
450 local->hw_scanning = false; 450 local->hw_scanning = false;
451 if (ieee80211_hw_config(local)) 451 /*
452 printk(KERN_DEBUG "%s: failed to restore operational " 452 * Somebody might have requested channel change during scan
453 "channel after scan\n", wiphy_name(local->hw.wiphy)); 453 * that we won't have acted upon, try now. ieee80211_hw_config
454 454 * will set the flag based on actual changes.
455 */
456 ieee80211_hw_config(local, 0);
455 goto done; 457 goto done;
456 } 458 }
457 459
458 local->sw_scanning = false; 460 local->sw_scanning = false;
459 if (ieee80211_hw_config(local)) 461 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL);
460 printk(KERN_DEBUG "%s: failed to restore operational "
461 "channel after scan\n", wiphy_name(local->hw.wiphy));
462
463 462
464 netif_tx_lock_bh(local->mdev); 463 netif_tx_lock_bh(local->mdev);
465 netif_addr_lock(local->mdev); 464 netif_addr_lock(local->mdev);
@@ -546,12 +545,9 @@ void ieee80211_scan_work(struct work_struct *work)
546 545
547 if (!skip) { 546 if (!skip) {
548 local->scan_channel = chan; 547 local->scan_channel = chan;
549 if (ieee80211_hw_config(local)) { 548 if (ieee80211_hw_config(local,
550 printk(KERN_DEBUG "%s: failed to set freq to " 549 IEEE80211_CONF_CHANGE_CHANNEL))
551 "%d MHz for scan\n", wiphy_name(local->hw.wiphy),
552 chan->center_freq);
553 skip = 1; 550 skip = 1;
554 }
555 } 551 }
556 552
557 /* advance state machine to next channel/band */ 553 /* advance state machine to next channel/band */
diff --git a/net/mac80211/sta_info.c b/net/mac80211/sta_info.c
index d254446b85b5..10c5539c20ab 100644
--- a/net/mac80211/sta_info.c
+++ b/net/mac80211/sta_info.c
@@ -137,14 +137,12 @@ struct sta_info *sta_info_get_by_idx(struct ieee80211_local *local, int idx,
137static void __sta_info_free(struct ieee80211_local *local, 137static void __sta_info_free(struct ieee80211_local *local,
138 struct sta_info *sta) 138 struct sta_info *sta)
139{ 139{
140 DECLARE_MAC_BUF(mbuf);
141
142 rate_control_free_sta(sta); 140 rate_control_free_sta(sta);
143 rate_control_put(sta->rate_ctrl); 141 rate_control_put(sta->rate_ctrl);
144 142
145#ifdef CONFIG_MAC80211_VERBOSE_DEBUG 143#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
146 printk(KERN_DEBUG "%s: Destroyed STA %s\n", 144 printk(KERN_DEBUG "%s: Destroyed STA %pM\n",
147 wiphy_name(local->hw.wiphy), print_mac(mbuf, sta->sta.addr)); 145 wiphy_name(local->hw.wiphy), sta->sta.addr);
148#endif /* CONFIG_MAC80211_VERBOSE_DEBUG */ 146#endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
149 147
150 kfree(sta); 148 kfree(sta);
@@ -222,7 +220,6 @@ struct sta_info *sta_info_alloc(struct ieee80211_sub_if_data *sdata,
222 struct ieee80211_local *local = sdata->local; 220 struct ieee80211_local *local = sdata->local;
223 struct sta_info *sta; 221 struct sta_info *sta;
224 int i; 222 int i;
225 DECLARE_MAC_BUF(mbuf);
226 223
227 sta = kzalloc(sizeof(*sta) + local->hw.sta_data_size, gfp); 224 sta = kzalloc(sizeof(*sta) + local->hw.sta_data_size, gfp);
228 if (!sta) 225 if (!sta)
@@ -263,8 +260,8 @@ struct sta_info *sta_info_alloc(struct ieee80211_sub_if_data *sdata,
263 skb_queue_head_init(&sta->tx_filtered); 260 skb_queue_head_init(&sta->tx_filtered);
264 261
265#ifdef CONFIG_MAC80211_VERBOSE_DEBUG 262#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
266 printk(KERN_DEBUG "%s: Allocated STA %s\n", 263 printk(KERN_DEBUG "%s: Allocated STA %pM\n",
267 wiphy_name(local->hw.wiphy), print_mac(mbuf, sta->sta.addr)); 264 wiphy_name(local->hw.wiphy), sta->sta.addr);
268#endif /* CONFIG_MAC80211_VERBOSE_DEBUG */ 265#endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
269 266
270#ifdef CONFIG_MAC80211_MESH 267#ifdef CONFIG_MAC80211_MESH
@@ -281,7 +278,6 @@ int sta_info_insert(struct sta_info *sta)
281 struct ieee80211_sub_if_data *sdata = sta->sdata; 278 struct ieee80211_sub_if_data *sdata = sta->sdata;
282 unsigned long flags; 279 unsigned long flags;
283 int err = 0; 280 int err = 0;
284 DECLARE_MAC_BUF(mac);
285 281
286 /* 282 /*
287 * Can't be a WARN_ON because it can be triggered through a race: 283 * Can't be a WARN_ON because it can be triggered through a race:
@@ -294,7 +290,7 @@ int sta_info_insert(struct sta_info *sta)
294 } 290 }
295 291
296 if (WARN_ON(compare_ether_addr(sta->sta.addr, sdata->dev->dev_addr) == 0 || 292 if (WARN_ON(compare_ether_addr(sta->sta.addr, sdata->dev->dev_addr) == 0 ||
297 is_multicast_ether_addr(sta->sta.addr))) { 293 is_multicast_ether_addr(sta->sta.addr))) {
298 err = -EINVAL; 294 err = -EINVAL;
299 goto out_free; 295 goto out_free;
300 } 296 }
@@ -322,8 +318,8 @@ int sta_info_insert(struct sta_info *sta)
322 } 318 }
323 319
324#ifdef CONFIG_MAC80211_VERBOSE_DEBUG 320#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
325 printk(KERN_DEBUG "%s: Inserted STA %s\n", 321 printk(KERN_DEBUG "%s: Inserted STA %pM\n",
326 wiphy_name(local->hw.wiphy), print_mac(mac, sta->sta.addr)); 322 wiphy_name(local->hw.wiphy), sta->sta.addr);
327#endif /* CONFIG_MAC80211_VERBOSE_DEBUG */ 323#endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
328 324
329 spin_unlock_irqrestore(&local->sta_lock, flags); 325 spin_unlock_irqrestore(&local->sta_lock, flags);
@@ -423,9 +419,6 @@ static void __sta_info_unlink(struct sta_info **sta)
423{ 419{
424 struct ieee80211_local *local = (*sta)->local; 420 struct ieee80211_local *local = (*sta)->local;
425 struct ieee80211_sub_if_data *sdata = (*sta)->sdata; 421 struct ieee80211_sub_if_data *sdata = (*sta)->sdata;
426#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
427 DECLARE_MAC_BUF(mbuf);
428#endif
429 /* 422 /*
430 * pull caller's reference if we're already gone. 423 * pull caller's reference if we're already gone.
431 */ 424 */
@@ -468,8 +461,8 @@ static void __sta_info_unlink(struct sta_info **sta)
468 } 461 }
469 462
470#ifdef CONFIG_MAC80211_VERBOSE_DEBUG 463#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
471 printk(KERN_DEBUG "%s: Removed STA %s\n", 464 printk(KERN_DEBUG "%s: Removed STA %pM\n",
472 wiphy_name(local->hw.wiphy), print_mac(mbuf, (*sta)->sta.addr)); 465 wiphy_name(local->hw.wiphy), (*sta)->sta.addr);
473#endif /* CONFIG_MAC80211_VERBOSE_DEBUG */ 466#endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
474 467
475 /* 468 /*
@@ -544,7 +537,6 @@ static void sta_info_cleanup_expire_buffered(struct ieee80211_local *local,
544 unsigned long flags; 537 unsigned long flags;
545 struct sk_buff *skb; 538 struct sk_buff *skb;
546 struct ieee80211_sub_if_data *sdata; 539 struct ieee80211_sub_if_data *sdata;
547 DECLARE_MAC_BUF(mac);
548 540
549 if (skb_queue_empty(&sta->ps_tx_buf)) 541 if (skb_queue_empty(&sta->ps_tx_buf))
550 return; 542 return;
@@ -564,8 +556,8 @@ static void sta_info_cleanup_expire_buffered(struct ieee80211_local *local,
564 sdata = sta->sdata; 556 sdata = sta->sdata;
565 local->total_ps_buffered--; 557 local->total_ps_buffered--;
566#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG 558#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
567 printk(KERN_DEBUG "Buffered frame expired (STA " 559 printk(KERN_DEBUG "Buffered frame expired (STA %pM)\n",
568 "%s)\n", print_mac(mac, sta->sta.addr)); 560 sta->sta.addr);
569#endif 561#endif
570 dev_kfree_skb(skb); 562 dev_kfree_skb(skb);
571 563
@@ -809,15 +801,14 @@ void ieee80211_sta_expire(struct ieee80211_sub_if_data *sdata,
809 struct ieee80211_local *local = sdata->local; 801 struct ieee80211_local *local = sdata->local;
810 struct sta_info *sta, *tmp; 802 struct sta_info *sta, *tmp;
811 LIST_HEAD(tmp_list); 803 LIST_HEAD(tmp_list);
812 DECLARE_MAC_BUF(mac);
813 unsigned long flags; 804 unsigned long flags;
814 805
815 spin_lock_irqsave(&local->sta_lock, flags); 806 spin_lock_irqsave(&local->sta_lock, flags);
816 list_for_each_entry_safe(sta, tmp, &local->sta_list, list) 807 list_for_each_entry_safe(sta, tmp, &local->sta_list, list)
817 if (time_after(jiffies, sta->last_rx + exp_time)) { 808 if (time_after(jiffies, sta->last_rx + exp_time)) {
818#ifdef CONFIG_MAC80211_IBSS_DEBUG 809#ifdef CONFIG_MAC80211_IBSS_DEBUG
819 printk(KERN_DEBUG "%s: expiring inactive STA %s\n", 810 printk(KERN_DEBUG "%s: expiring inactive STA %pM\n",
820 sdata->dev->name, print_mac(mac, sta->sta.addr)); 811 sdata->dev->name, sta->sta.addr);
821#endif 812#endif
822 __sta_info_unlink(&sta); 813 __sta_info_unlink(&sta);
823 if (sta) 814 if (sta)
@@ -830,7 +821,7 @@ void ieee80211_sta_expire(struct ieee80211_sub_if_data *sdata,
830} 821}
831 822
832struct ieee80211_sta *ieee80211_find_sta(struct ieee80211_hw *hw, 823struct ieee80211_sta *ieee80211_find_sta(struct ieee80211_hw *hw,
833 const u8 *addr) 824 const u8 *addr)
834{ 825{
835 struct sta_info *sta = sta_info_get(hw_to_local(hw), addr); 826 struct sta_info *sta = sta_info_get(hw_to_local(hw), addr);
836 827
diff --git a/net/mac80211/sta_info.h b/net/mac80211/sta_info.h
index 168a39a298bd..dc2606d0ae77 100644
--- a/net/mac80211/sta_info.h
+++ b/net/mac80211/sta_info.h
@@ -160,18 +160,17 @@ struct sta_ampdu_mlme {
160 * @list: global linked list entry 160 * @list: global linked list entry
161 * @hnext: hash table linked list pointer 161 * @hnext: hash table linked list pointer
162 * @local: pointer to the global information 162 * @local: pointer to the global information
163 * @sdata: TBD 163 * @sdata: virtual interface this station belongs to
164 * @key: TBD 164 * @key: peer key negotiated with this station, if any
165 * @rate_ctrl: TBD 165 * @rate_ctrl: rate control algorithm reference
166 * @rate_ctrl_priv: TBD 166 * @rate_ctrl_priv: rate control private per-STA pointer
167 * @last_tx_rate: rate used for last transmit, to report to userspace as
168 * "the" transmit rate
167 * @lock: used for locking all fields that require locking, see comments 169 * @lock: used for locking all fields that require locking, see comments
168 * in the header file. 170 * in the header file.
169 * @flaglock: spinlock for flags accesses 171 * @flaglock: spinlock for flags accesses
170 * @addr: MAC address of this STA 172 * @listen_interval: listen interval of this station, when we're acting as AP
171 * @aid: STA's unique AID (1..2007, 0 = not assigned yet), 173 * @pin_status: used internally for pinning a STA struct into memory
172 * only used in AP (and IBSS?) mode
173 * @listen_interval: TBD
174 * @pin_status: TBD
175 * @flags: STA flags, see &enum ieee80211_sta_info_flags 174 * @flags: STA flags, see &enum ieee80211_sta_info_flags
176 * @ps_tx_buf: buffer of frames to transmit to this station 175 * @ps_tx_buf: buffer of frames to transmit to this station
177 * when it leaves power saving state 176 * when it leaves power saving state
@@ -180,8 +179,8 @@ struct sta_ampdu_mlme {
180 * power saving state 179 * power saving state
181 * @rx_packets: Number of MSDUs received from this STA 180 * @rx_packets: Number of MSDUs received from this STA
182 * @rx_bytes: Number of bytes received from this STA 181 * @rx_bytes: Number of bytes received from this STA
183 * @wep_weak_iv_count: TBD 182 * @wep_weak_iv_count: number of weak WEP IVs received from this station
184 * @last_rx: TBD 183 * @last_rx: time (in jiffies) when last frame was received from this STA
185 * @num_duplicates: number of duplicate frames received from this STA 184 * @num_duplicates: number of duplicate frames received from this STA
186 * @rx_fragments: number of received MPDUs 185 * @rx_fragments: number of received MPDUs
187 * @rx_dropped: number of dropped MPDUs from this STA 186 * @rx_dropped: number of dropped MPDUs from this STA
@@ -189,26 +188,26 @@ struct sta_ampdu_mlme {
189 * @last_qual: qual of last received frame from this STA 188 * @last_qual: qual of last received frame from this STA
190 * @last_noise: noise of last received frame from this STA 189 * @last_noise: noise of last received frame from this STA
191 * @last_seq_ctrl: last received seq/frag number from this STA (per RX queue) 190 * @last_seq_ctrl: last received seq/frag number from this STA (per RX queue)
192 * @tx_filtered_count: TBD 191 * @tx_filtered_count: number of frames the hardware filtered for this STA
193 * @tx_retry_failed: TBD 192 * @tx_retry_failed: number of frames that failed retry
194 * @tx_retry_count: TBD 193 * @tx_retry_count: total number of retries for frames to this STA
195 * @fail_avg: moving percentage of failed MSDUs 194 * @fail_avg: moving percentage of failed MSDUs
196 * @tx_packets: number of RX/TX MSDUs 195 * @tx_packets: number of RX/TX MSDUs
197 * @tx_bytes: TBD 196 * @tx_bytes: number of bytes transmitted to this STA
198 * @tx_fragments: number of transmitted MPDUs 197 * @tx_fragments: number of transmitted MPDUs
199 * @last_txrate_idx: Index of the last used transmit rate 198 * @last_txrate: description of the last used transmit rate
200 * @tid_seq: TBD 199 * @tid_seq: per-TID sequence numbers for sending to this STA
201 * @ampdu_mlme: TBD 200 * @ampdu_mlme: A-MPDU state machine state
202 * @timer_to_tid: identity mapping to ID timers 201 * @timer_to_tid: identity mapping to ID timers
203 * @tid_to_tx_q: map tid to tx queue 202 * @tid_to_tx_q: map tid to tx queue
204 * @llid: Local link ID 203 * @llid: Local link ID
205 * @plid: Peer link ID 204 * @plid: Peer link ID
206 * @reason: Cancel reason on PLINK_HOLDING state 205 * @reason: Cancel reason on PLINK_HOLDING state
207 * @plink_retries: Retries in establishment 206 * @plink_retries: Retries in establishment
208 * @ignore_plink_timer: TBD 207 * @ignore_plink_timer: ignore the peer-link timer (used internally)
209 * @plink_state plink_state: TBD 208 * @plink_state: peer link state
210 * @plink_timeout: TBD 209 * @plink_timeout: timeout of peer link
211 * @plink_timer: TBD 210 * @plink_timer: peer link watch timer
212 * @debugfs: debug filesystem info 211 * @debugfs: debug filesystem info
213 * @sta: station information we share with the driver 212 * @sta: station information we share with the driver
214 */ 213 */
@@ -267,7 +266,7 @@ struct sta_info {
267 unsigned long tx_packets; 266 unsigned long tx_packets;
268 unsigned long tx_bytes; 267 unsigned long tx_bytes;
269 unsigned long tx_fragments; 268 unsigned long tx_fragments;
270 unsigned int last_txrate_idx; 269 struct ieee80211_tx_rate last_tx_rate;
271 u16 tid_seq[IEEE80211_QOS_CTL_TID_MASK + 1]; 270 u16 tid_seq[IEEE80211_QOS_CTL_TID_MASK + 1];
272 271
273 /* 272 /*
diff --git a/net/mac80211/tkip.c b/net/mac80211/tkip.c
index 34b32bc8f609..38fa111d2dc6 100644
--- a/net/mac80211/tkip.c
+++ b/net/mac80211/tkip.c
@@ -263,10 +263,9 @@ int ieee80211_tkip_decrypt_data(struct crypto_blkcipher *tfm,
263 (iv32 == key->u.tkip.rx[queue].iv32 && 263 (iv32 == key->u.tkip.rx[queue].iv32 &&
264 iv16 <= key->u.tkip.rx[queue].iv16))) { 264 iv16 <= key->u.tkip.rx[queue].iv16))) {
265#ifdef CONFIG_MAC80211_TKIP_DEBUG 265#ifdef CONFIG_MAC80211_TKIP_DEBUG
266 DECLARE_MAC_BUF(mac);
267 printk(KERN_DEBUG "TKIP replay detected for RX frame from " 266 printk(KERN_DEBUG "TKIP replay detected for RX frame from "
268 "%s (RX IV (%04x,%02x) <= prev. IV (%04x,%02x)\n", 267 "%pM (RX IV (%04x,%02x) <= prev. IV (%04x,%02x)\n",
269 print_mac(mac, ta), 268 ta,
270 iv32, iv16, key->u.tkip.rx[queue].iv32, 269 iv32, iv16, key->u.tkip.rx[queue].iv32,
271 key->u.tkip.rx[queue].iv16); 270 key->u.tkip.rx[queue].iv16);
272#endif 271#endif
@@ -287,9 +286,8 @@ int ieee80211_tkip_decrypt_data(struct crypto_blkcipher *tfm,
287 { 286 {
288 int i; 287 int i;
289 u8 key_offset = NL80211_TKIP_DATA_OFFSET_ENCR_KEY; 288 u8 key_offset = NL80211_TKIP_DATA_OFFSET_ENCR_KEY;
290 DECLARE_MAC_BUF(mac); 289 printk(KERN_DEBUG "TKIP decrypt: Phase1 TA=%pM"
291 printk(KERN_DEBUG "TKIP decrypt: Phase1 TA=%s" 290 " TK=", ta);
292 " TK=", print_mac(mac, ta));
293 for (i = 0; i < 16; i++) 291 for (i = 0; i < 16; i++)
294 printk("%02x ", 292 printk("%02x ",
295 key->conf.key[key_offset + i]); 293 key->conf.key[key_offset + i]);
diff --git a/net/mac80211/tx.c b/net/mac80211/tx.c
index 1460537faf33..a4af3a124cce 100644
--- a/net/mac80211/tx.c
+++ b/net/mac80211/tx.c
@@ -46,13 +46,20 @@ static __le16 ieee80211_duration(struct ieee80211_tx_data *tx, int group_addr,
46 struct ieee80211_local *local = tx->local; 46 struct ieee80211_local *local = tx->local;
47 struct ieee80211_supported_band *sband; 47 struct ieee80211_supported_band *sband;
48 struct ieee80211_hdr *hdr; 48 struct ieee80211_hdr *hdr;
49 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
50
51 /* assume HW handles this */
52 if (info->control.rates[0].flags & IEEE80211_TX_RC_MCS)
53 return 0;
54
55 /* uh huh? */
56 if (WARN_ON_ONCE(info->control.rates[0].idx < 0))
57 return 0;
49 58
50 sband = local->hw.wiphy->bands[tx->channel->band]; 59 sband = local->hw.wiphy->bands[tx->channel->band];
51 txrate = &sband->bitrates[tx->rate_idx]; 60 txrate = &sband->bitrates[info->control.rates[0].idx];
52 61
53 erp = 0; 62 erp = txrate->flags & IEEE80211_RATE_ERP_G;
54 if (tx->sdata->flags & IEEE80211_SDATA_OPERATING_GMODE)
55 erp = txrate->flags & IEEE80211_RATE_ERP_G;
56 63
57 /* 64 /*
58 * data and mgmt (except PS Poll): 65 * data and mgmt (except PS Poll):
@@ -116,7 +123,7 @@ static __le16 ieee80211_duration(struct ieee80211_tx_data *tx, int group_addr,
116 if (r->bitrate > txrate->bitrate) 123 if (r->bitrate > txrate->bitrate)
117 break; 124 break;
118 125
119 if (tx->sdata->bss_conf.basic_rates & BIT(i)) 126 if (tx->sdata->vif.bss_conf.basic_rates & BIT(i))
120 rate = r->bitrate; 127 rate = r->bitrate;
121 128
122 switch (sband->band) { 129 switch (sband->band) {
@@ -150,7 +157,7 @@ static __le16 ieee80211_duration(struct ieee80211_tx_data *tx, int group_addr,
150 * to closest integer */ 157 * to closest integer */
151 158
152 dur = ieee80211_frame_duration(local, 10, rate, erp, 159 dur = ieee80211_frame_duration(local, 10, rate, erp,
153 tx->sdata->bss_conf.use_short_preamble); 160 tx->sdata->vif.bss_conf.use_short_preamble);
154 161
155 if (next_frag_len) { 162 if (next_frag_len) {
156 /* Frame is fragmented: duration increases with time needed to 163 /* Frame is fragmented: duration increases with time needed to
@@ -159,7 +166,7 @@ static __le16 ieee80211_duration(struct ieee80211_tx_data *tx, int group_addr,
159 /* next fragment */ 166 /* next fragment */
160 dur += ieee80211_frame_duration(local, next_frag_len, 167 dur += ieee80211_frame_duration(local, next_frag_len,
161 txrate->bitrate, erp, 168 txrate->bitrate, erp,
162 tx->sdata->bss_conf.use_short_preamble); 169 tx->sdata->vif.bss_conf.use_short_preamble);
163 } 170 }
164 171
165 return cpu_to_le16(dur); 172 return cpu_to_le16(dur);
@@ -201,10 +208,9 @@ ieee80211_tx_h_check_assoc(struct ieee80211_tx_data *tx)
201 tx->sdata->vif.type != NL80211_IFTYPE_ADHOC && 208 tx->sdata->vif.type != NL80211_IFTYPE_ADHOC &&
202 ieee80211_is_data(hdr->frame_control))) { 209 ieee80211_is_data(hdr->frame_control))) {
203#ifdef CONFIG_MAC80211_VERBOSE_DEBUG 210#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
204 DECLARE_MAC_BUF(mac);
205 printk(KERN_DEBUG "%s: dropped data frame to not " 211 printk(KERN_DEBUG "%s: dropped data frame to not "
206 "associated station %s\n", 212 "associated station %pM\n",
207 tx->dev->name, print_mac(mac, hdr->addr1)); 213 tx->dev->name, hdr->addr1);
208#endif /* CONFIG_MAC80211_VERBOSE_DEBUG */ 214#endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
209 I802_DEBUG_INC(tx->local->tx_handlers_drop_not_assoc); 215 I802_DEBUG_INC(tx->local->tx_handlers_drop_not_assoc);
210 return TX_DROP; 216 return TX_DROP;
@@ -331,7 +337,6 @@ ieee80211_tx_h_unicast_ps_buf(struct ieee80211_tx_data *tx)
331 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb); 337 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
332 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data; 338 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data;
333 u32 staflags; 339 u32 staflags;
334 DECLARE_MAC_BUF(mac);
335 340
336 if (unlikely(!sta || ieee80211_is_probe_resp(hdr->frame_control))) 341 if (unlikely(!sta || ieee80211_is_probe_resp(hdr->frame_control)))
337 return TX_CONTINUE; 342 return TX_CONTINUE;
@@ -341,9 +346,9 @@ ieee80211_tx_h_unicast_ps_buf(struct ieee80211_tx_data *tx)
341 if (unlikely((staflags & WLAN_STA_PS) && 346 if (unlikely((staflags & WLAN_STA_PS) &&
342 !(staflags & WLAN_STA_PSPOLL))) { 347 !(staflags & WLAN_STA_PSPOLL))) {
343#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG 348#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
344 printk(KERN_DEBUG "STA %s aid %d: PS buffer (entries " 349 printk(KERN_DEBUG "STA %pM aid %d: PS buffer (entries "
345 "before %d)\n", 350 "before %d)\n",
346 print_mac(mac, sta->sta.addr), sta->sta.aid, 351 sta->sta.addr, sta->sta.aid,
347 skb_queue_len(&sta->ps_tx_buf)); 352 skb_queue_len(&sta->ps_tx_buf));
348#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */ 353#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
349 if (tx->local->total_ps_buffered >= TOTAL_MAX_TX_BUFFER) 354 if (tx->local->total_ps_buffered >= TOTAL_MAX_TX_BUFFER)
@@ -352,9 +357,9 @@ ieee80211_tx_h_unicast_ps_buf(struct ieee80211_tx_data *tx)
352 struct sk_buff *old = skb_dequeue(&sta->ps_tx_buf); 357 struct sk_buff *old = skb_dequeue(&sta->ps_tx_buf);
353#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG 358#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
354 if (net_ratelimit()) { 359 if (net_ratelimit()) {
355 printk(KERN_DEBUG "%s: STA %s TX " 360 printk(KERN_DEBUG "%s: STA %pM TX "
356 "buffer full - dropping oldest frame\n", 361 "buffer full - dropping oldest frame\n",
357 tx->dev->name, print_mac(mac, sta->sta.addr)); 362 tx->dev->name, sta->sta.addr);
358 } 363 }
359#endif 364#endif
360 dev_kfree_skb(old); 365 dev_kfree_skb(old);
@@ -371,9 +376,9 @@ ieee80211_tx_h_unicast_ps_buf(struct ieee80211_tx_data *tx)
371 } 376 }
372#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG 377#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
373 else if (unlikely(test_sta_flags(sta, WLAN_STA_PS))) { 378 else if (unlikely(test_sta_flags(sta, WLAN_STA_PS))) {
374 printk(KERN_DEBUG "%s: STA %s in PS mode, but pspoll " 379 printk(KERN_DEBUG "%s: STA %pM in PS mode, but pspoll "
375 "set -> send frame\n", tx->dev->name, 380 "set -> send frame\n", tx->dev->name,
376 print_mac(mac, sta->sta.addr)); 381 sta->sta.addr);
377 } 382 }
378#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */ 383#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
379 clear_sta_flags(sta, WLAN_STA_PSPOLL); 384 clear_sta_flags(sta, WLAN_STA_PSPOLL);
@@ -439,140 +444,154 @@ ieee80211_tx_h_select_key(struct ieee80211_tx_data *tx)
439static ieee80211_tx_result debug_noinline 444static ieee80211_tx_result debug_noinline
440ieee80211_tx_h_rate_ctrl(struct ieee80211_tx_data *tx) 445ieee80211_tx_h_rate_ctrl(struct ieee80211_tx_data *tx)
441{ 446{
442 struct rate_selection rsel;
443 struct ieee80211_supported_band *sband;
444 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb); 447 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
448 struct ieee80211_hdr *hdr = (void *)tx->skb->data;
449 struct ieee80211_supported_band *sband;
450 struct ieee80211_rate *rate;
451 int i, len;
452 bool inval = false, rts = false, short_preamble = false;
453 struct ieee80211_tx_rate_control txrc;
445 454
446 sband = tx->local->hw.wiphy->bands[tx->channel->band]; 455 memset(&txrc, 0, sizeof(txrc));
447 456
448 if (likely(tx->rate_idx < 0)) { 457 sband = tx->local->hw.wiphy->bands[tx->channel->band];
449 rate_control_get_rate(tx->sdata, sband, tx->sta,
450 tx->skb, &rsel);
451 if (tx->sta)
452 tx->sta->last_txrate_idx = rsel.rate_idx;
453 tx->rate_idx = rsel.rate_idx;
454 if (unlikely(rsel.probe_idx >= 0)) {
455 info->flags |= IEEE80211_TX_CTL_RATE_CTRL_PROBE;
456 tx->flags |= IEEE80211_TX_PROBE_LAST_FRAG;
457 info->control.retries[0].rate_idx = tx->rate_idx;
458 info->control.retries[0].limit = tx->local->hw.max_altrate_tries;
459 tx->rate_idx = rsel.probe_idx;
460 } else if (info->control.retries[0].limit == 0)
461 info->control.retries[0].rate_idx = -1;
462
463 if (unlikely(tx->rate_idx < 0))
464 return TX_DROP;
465 } else
466 info->control.retries[0].rate_idx = -1;
467 458
468 if (tx->sdata->bss_conf.use_cts_prot && 459 len = min_t(int, tx->skb->len + FCS_LEN,
469 (tx->flags & IEEE80211_TX_FRAGMENTED) && (rsel.nonerp_idx >= 0)) { 460 tx->local->fragmentation_threshold);
470 tx->last_frag_rate_idx = tx->rate_idx; 461
471 if (rsel.probe_idx >= 0) 462 /* set up the tx rate control struct we give the RC algo */
472 tx->flags &= ~IEEE80211_TX_PROBE_LAST_FRAG; 463 txrc.hw = local_to_hw(tx->local);
473 else 464 txrc.sband = sband;
474 tx->flags |= IEEE80211_TX_PROBE_LAST_FRAG; 465 txrc.bss_conf = &tx->sdata->vif.bss_conf;
475 tx->rate_idx = rsel.nonerp_idx; 466 txrc.skb = tx->skb;
476 info->tx_rate_idx = rsel.nonerp_idx; 467 txrc.reported_rate.idx = -1;
477 info->flags &= ~IEEE80211_TX_CTL_RATE_CTRL_PROBE; 468 txrc.max_rate_idx = tx->sdata->max_ratectrl_rateidx;
478 } else { 469
479 tx->last_frag_rate_idx = tx->rate_idx; 470 /* set up RTS protection if desired */
480 info->tx_rate_idx = tx->rate_idx; 471 if (tx->local->rts_threshold < IEEE80211_MAX_RTS_THRESHOLD &&
472 len > tx->local->rts_threshold) {
473 txrc.rts = rts = true;
481 } 474 }
482 info->tx_rate_idx = tx->rate_idx;
483 475
484 return TX_CONTINUE; 476 /*
485} 477 * Use short preamble if the BSS can handle it, but not for
478 * management frames unless we know the receiver can handle
479 * that -- the management frame might be to a station that
480 * just wants a probe response.
481 */
482 if (tx->sdata->vif.bss_conf.use_short_preamble &&
483 (ieee80211_is_data(hdr->frame_control) ||
484 (tx->sta && test_sta_flags(tx->sta, WLAN_STA_SHORT_PREAMBLE))))
485 txrc.short_preamble = short_preamble = true;
486 486
487static ieee80211_tx_result debug_noinline
488ieee80211_tx_h_misc(struct ieee80211_tx_data *tx)
489{
490 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data;
491 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
492 struct ieee80211_supported_band *sband;
493 487
494 sband = tx->local->hw.wiphy->bands[tx->channel->band]; 488 rate_control_get_rate(tx->sdata, tx->sta, &txrc);
489
490 if (unlikely(info->control.rates[0].idx < 0))
491 return TX_DROP;
492
493 if (txrc.reported_rate.idx < 0)
494 txrc.reported_rate = info->control.rates[0];
495 495
496 if (tx->sta) 496 if (tx->sta)
497 info->control.sta = &tx->sta->sta; 497 tx->sta->last_tx_rate = txrc.reported_rate;
498 498
499 if (!info->control.retry_limit) { 499 if (unlikely(!info->control.rates[0].count))
500 if (!is_multicast_ether_addr(hdr->addr1)) { 500 info->control.rates[0].count = 1;
501 int len = min_t(int, tx->skb->len + FCS_LEN,
502 tx->local->fragmentation_threshold);
503 if (len > tx->local->rts_threshold
504 && tx->local->rts_threshold <
505 IEEE80211_MAX_RTS_THRESHOLD) {
506 info->flags |= IEEE80211_TX_CTL_USE_RTS_CTS;
507 info->flags |=
508 IEEE80211_TX_CTL_LONG_RETRY_LIMIT;
509 info->control.retry_limit =
510 tx->local->long_retry_limit;
511 } else {
512 info->control.retry_limit =
513 tx->local->short_retry_limit;
514 }
515 } else {
516 info->control.retry_limit = 1;
517 }
518 }
519 501
520 if (tx->flags & IEEE80211_TX_FRAGMENTED) { 502 if (is_multicast_ether_addr(hdr->addr1)) {
521 /* Do not use multiple retry rates when sending fragmented 503 /*
522 * frames. 504 * XXX: verify the rate is in the basic rateset
523 * TODO: The last fragment could still use multiple retry 505 */
524 * rates. */ 506 return TX_CONTINUE;
525 info->control.retries[0].rate_idx = -1;
526 } 507 }
527 508
528 /* Use CTS protection for unicast frames sent using extended rates if 509 /*
529 * there are associated non-ERP stations and RTS/CTS is not configured 510 * set up the RTS/CTS rate as the fastest basic rate
530 * for the frame. */ 511 * that is not faster than the data rate
531 if ((tx->sdata->flags & IEEE80211_SDATA_OPERATING_GMODE) && 512 *
532 (sband->bitrates[tx->rate_idx].flags & IEEE80211_RATE_ERP_G) && 513 * XXX: Should this check all retry rates?
533 (tx->flags & IEEE80211_TX_UNICAST) && 514 */
534 tx->sdata->bss_conf.use_cts_prot && 515 if (!(info->control.rates[0].flags & IEEE80211_TX_RC_MCS)) {
535 !(info->flags & IEEE80211_TX_CTL_USE_RTS_CTS)) 516 s8 baserate = 0;
536 info->flags |= IEEE80211_TX_CTL_USE_CTS_PROTECT; 517
537 518 rate = &sband->bitrates[info->control.rates[0].idx];
538 /* Transmit data frames using short preambles if the driver supports 519
539 * short preambles at the selected rate and short preambles are 520 for (i = 0; i < sband->n_bitrates; i++) {
540 * available on the network at the current point in time. */ 521 /* must be a basic rate */
541 if (ieee80211_is_data(hdr->frame_control) && 522 if (!(tx->sdata->vif.bss_conf.basic_rates & BIT(i)))
542 (sband->bitrates[tx->rate_idx].flags & IEEE80211_RATE_SHORT_PREAMBLE) && 523 continue;
543 tx->sdata->bss_conf.use_short_preamble && 524 /* must not be faster than the data rate */
544 (!tx->sta || test_sta_flags(tx->sta, WLAN_STA_SHORT_PREAMBLE))) { 525 if (sband->bitrates[i].bitrate > rate->bitrate)
545 info->flags |= IEEE80211_TX_CTL_SHORT_PREAMBLE; 526 continue;
527 /* maximum */
528 if (sband->bitrates[baserate].bitrate <
529 sband->bitrates[i].bitrate)
530 baserate = i;
531 }
532
533 info->control.rts_cts_rate_idx = baserate;
546 } 534 }
547 535
548 if ((info->flags & IEEE80211_TX_CTL_USE_RTS_CTS) || 536 for (i = 0; i < IEEE80211_TX_MAX_RATES; i++) {
549 (info->flags & IEEE80211_TX_CTL_USE_CTS_PROTECT)) { 537 /*
550 struct ieee80211_rate *rate; 538 * make sure there's no valid rate following
551 s8 baserate = -1; 539 * an invalid one, just in case drivers don't
552 int idx; 540 * take the API seriously to stop at -1.
541 */
542 if (inval) {
543 info->control.rates[i].idx = -1;
544 continue;
545 }
546 if (info->control.rates[i].idx < 0) {
547 inval = true;
548 continue;
549 }
553 550
554 /* Do not use multiple retry rates when using RTS/CTS */ 551 /*
555 info->control.retries[0].rate_idx = -1; 552 * For now assume MCS is already set up correctly, this
553 * needs to be fixed.
554 */
555 if (info->control.rates[i].flags & IEEE80211_TX_RC_MCS) {
556 WARN_ON(info->control.rates[i].idx > 76);
557 continue;
558 }
556 559
557 /* Use min(data rate, max base rate) as CTS/RTS rate */ 560 /* set up RTS protection if desired */
558 rate = &sband->bitrates[tx->rate_idx]; 561 if (rts)
562 info->control.rates[i].flags |=
563 IEEE80211_TX_RC_USE_RTS_CTS;
559 564
560 for (idx = 0; idx < sband->n_bitrates; idx++) { 565 /* RC is busted */
561 if (sband->bitrates[idx].bitrate > rate->bitrate) 566 if (WARN_ON_ONCE(info->control.rates[i].idx >=
562 continue; 567 sband->n_bitrates)) {
563 if (tx->sdata->bss_conf.basic_rates & BIT(idx) && 568 info->control.rates[i].idx = -1;
564 (baserate < 0 || 569 continue;
565 (sband->bitrates[baserate].bitrate
566 < sband->bitrates[idx].bitrate)))
567 baserate = idx;
568 } 570 }
569 571
570 if (baserate >= 0) 572 rate = &sband->bitrates[info->control.rates[i].idx];
571 info->control.rts_cts_rate_idx = baserate; 573
572 else 574 /* set up short preamble */
573 info->control.rts_cts_rate_idx = 0; 575 if (short_preamble &&
576 rate->flags & IEEE80211_RATE_SHORT_PREAMBLE)
577 info->control.rates[i].flags |=
578 IEEE80211_TX_RC_USE_SHORT_PREAMBLE;
579
580 /* set up G protection */
581 if (!rts && tx->sdata->vif.bss_conf.use_cts_prot &&
582 rate->flags & IEEE80211_RATE_ERP_G)
583 info->control.rates[i].flags |=
584 IEEE80211_TX_RC_USE_CTS_PROTECT;
574 } 585 }
575 586
587 return TX_CONTINUE;
588}
589
590static ieee80211_tx_result debug_noinline
591ieee80211_tx_h_misc(struct ieee80211_tx_data *tx)
592{
593 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
594
576 if (tx->sta) 595 if (tx->sta)
577 info->control.sta = &tx->sta->sta; 596 info->control.sta = &tx->sta->sta;
578 597
@@ -602,8 +621,18 @@ ieee80211_tx_h_sequence(struct ieee80211_tx_data *tx)
602 if (ieee80211_hdrlen(hdr->frame_control) < 24) 621 if (ieee80211_hdrlen(hdr->frame_control) < 24)
603 return TX_CONTINUE; 622 return TX_CONTINUE;
604 623
624 /*
625 * Anything but QoS data that has a sequence number field
626 * (is long enough) gets a sequence number from the global
627 * counter.
628 */
605 if (!ieee80211_is_data_qos(hdr->frame_control)) { 629 if (!ieee80211_is_data_qos(hdr->frame_control)) {
630 /* driver should assign sequence number */
606 info->flags |= IEEE80211_TX_CTL_ASSIGN_SEQ; 631 info->flags |= IEEE80211_TX_CTL_ASSIGN_SEQ;
632 /* for pure STA mode without beacons, we can do it */
633 hdr->seq_ctrl = cpu_to_le16(tx->sdata->sequence_number);
634 tx->sdata->sequence_number += 0x10;
635 tx->sdata->sequence_number &= IEEE80211_SCTL_SEQ;
607 return TX_CONTINUE; 636 return TX_CONTINUE;
608 } 637 }
609 638
@@ -632,6 +661,7 @@ ieee80211_tx_h_sequence(struct ieee80211_tx_data *tx)
632static ieee80211_tx_result debug_noinline 661static ieee80211_tx_result debug_noinline
633ieee80211_tx_h_fragment(struct ieee80211_tx_data *tx) 662ieee80211_tx_h_fragment(struct ieee80211_tx_data *tx)
634{ 663{
664 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
635 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data; 665 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data;
636 size_t hdrlen, per_fragm, num_fragm, payload_len, left; 666 size_t hdrlen, per_fragm, num_fragm, payload_len, left;
637 struct sk_buff **frags, *first, *frag; 667 struct sk_buff **frags, *first, *frag;
@@ -648,9 +678,7 @@ ieee80211_tx_h_fragment(struct ieee80211_tx_data *tx)
648 * This scenario is handled in __ieee80211_tx_prepare but extra 678 * This scenario is handled in __ieee80211_tx_prepare but extra
649 * caution taken here as fragmented ampdu may cause Tx stop. 679 * caution taken here as fragmented ampdu may cause Tx stop.
650 */ 680 */
651 if (WARN_ON(tx->flags & IEEE80211_TX_CTL_AMPDU || 681 if (WARN_ON(info->flags & IEEE80211_TX_CTL_AMPDU))
652 skb_get_queue_mapping(tx->skb) >=
653 ieee80211_num_regular_queues(&tx->local->hw)))
654 return TX_DROP; 682 return TX_DROP;
655 683
656 first = tx->skb; 684 first = tx->skb;
@@ -684,20 +712,45 @@ ieee80211_tx_h_fragment(struct ieee80211_tx_data *tx)
684 IEEE80211_ENCRYPT_TAILROOM); 712 IEEE80211_ENCRYPT_TAILROOM);
685 if (!frag) 713 if (!frag)
686 goto fail; 714 goto fail;
715
687 /* Make sure that all fragments use the same priority so 716 /* Make sure that all fragments use the same priority so
688 * that they end up using the same TX queue */ 717 * that they end up using the same TX queue */
689 frag->priority = first->priority; 718 frag->priority = first->priority;
719
690 skb_reserve(frag, tx->local->tx_headroom + 720 skb_reserve(frag, tx->local->tx_headroom +
691 IEEE80211_ENCRYPT_HEADROOM); 721 IEEE80211_ENCRYPT_HEADROOM);
722
723 /* copy TX information */
724 info = IEEE80211_SKB_CB(frag);
725 memcpy(info, first->cb, sizeof(frag->cb));
726
727 /* copy/fill in 802.11 header */
692 fhdr = (struct ieee80211_hdr *) skb_put(frag, hdrlen); 728 fhdr = (struct ieee80211_hdr *) skb_put(frag, hdrlen);
693 memcpy(fhdr, first->data, hdrlen); 729 memcpy(fhdr, first->data, hdrlen);
694 if (i == num_fragm - 2)
695 fhdr->frame_control &= cpu_to_le16(~IEEE80211_FCTL_MOREFRAGS);
696 fhdr->seq_ctrl = cpu_to_le16(seq | ((i + 1) & IEEE80211_SCTL_FRAG)); 730 fhdr->seq_ctrl = cpu_to_le16(seq | ((i + 1) & IEEE80211_SCTL_FRAG));
731
732 if (i == num_fragm - 2) {
733 /* clear MOREFRAGS bit for the last fragment */
734 fhdr->frame_control &= cpu_to_le16(~IEEE80211_FCTL_MOREFRAGS);
735 } else {
736 /*
737 * No multi-rate retries for fragmented frames, that
738 * would completely throw off the NAV at other STAs.
739 */
740 info->control.rates[1].idx = -1;
741 info->control.rates[2].idx = -1;
742 info->control.rates[3].idx = -1;
743 info->control.rates[4].idx = -1;
744 BUILD_BUG_ON(IEEE80211_TX_MAX_RATES != 5);
745 info->flags &= ~IEEE80211_TX_CTL_RATE_CTRL_PROBE;
746 }
747
748 /* copy data */
697 copylen = left > per_fragm ? per_fragm : left; 749 copylen = left > per_fragm ? per_fragm : left;
698 memcpy(skb_put(frag, copylen), pos, copylen); 750 memcpy(skb_put(frag, copylen), pos, copylen);
699 memcpy(frag->cb, first->cb, sizeof(frag->cb)); 751
700 skb_copy_queue_mapping(frag, first); 752 skb_copy_queue_mapping(frag, first);
753
701 frag->do_not_encrypt = first->do_not_encrypt; 754 frag->do_not_encrypt = first->do_not_encrypt;
702 755
703 pos += copylen; 756 pos += copylen;
@@ -757,12 +810,10 @@ ieee80211_tx_h_calculate_duration(struct ieee80211_tx_data *tx)
757 tx->extra_frag[0]->len); 810 tx->extra_frag[0]->len);
758 811
759 for (i = 0; i < tx->num_extra_frag; i++) { 812 for (i = 0; i < tx->num_extra_frag; i++) {
760 if (i + 1 < tx->num_extra_frag) { 813 if (i + 1 < tx->num_extra_frag)
761 next_len = tx->extra_frag[i + 1]->len; 814 next_len = tx->extra_frag[i + 1]->len;
762 } else { 815 else
763 next_len = 0; 816 next_len = 0;
764 tx->rate_idx = tx->last_frag_rate_idx;
765 }
766 817
767 hdr = (struct ieee80211_hdr *)tx->extra_frag[i]->data; 818 hdr = (struct ieee80211_hdr *)tx->extra_frag[i]->data;
768 hdr->duration_id = ieee80211_duration(tx, 0, next_len); 819 hdr->duration_id = ieee80211_duration(tx, 0, next_len);
@@ -815,7 +866,6 @@ __ieee80211_parse_tx_radiotap(struct ieee80211_tx_data *tx,
815 (struct ieee80211_radiotap_header *) skb->data; 866 (struct ieee80211_radiotap_header *) skb->data;
816 struct ieee80211_supported_band *sband; 867 struct ieee80211_supported_band *sband;
817 int ret = ieee80211_radiotap_iterator_init(&iterator, rthdr, skb->len); 868 int ret = ieee80211_radiotap_iterator_init(&iterator, rthdr, skb->len);
818 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
819 869
820 sband = tx->local->hw.wiphy->bands[tx->channel->band]; 870 sband = tx->local->hw.wiphy->bands[tx->channel->band];
821 871
@@ -829,8 +879,6 @@ __ieee80211_parse_tx_radiotap(struct ieee80211_tx_data *tx,
829 */ 879 */
830 880
831 while (!ret) { 881 while (!ret) {
832 int i, target_rate;
833
834 ret = ieee80211_radiotap_iterator_next(&iterator); 882 ret = ieee80211_radiotap_iterator_next(&iterator);
835 883
836 if (ret) 884 if (ret)
@@ -844,38 +892,6 @@ __ieee80211_parse_tx_radiotap(struct ieee80211_tx_data *tx,
844 * get_unaligned((type *)iterator.this_arg) to dereference 892 * get_unaligned((type *)iterator.this_arg) to dereference
845 * iterator.this_arg for type "type" safely on all arches. 893 * iterator.this_arg for type "type" safely on all arches.
846 */ 894 */
847 case IEEE80211_RADIOTAP_RATE:
848 /*
849 * radiotap rate u8 is in 500kbps units eg, 0x02=1Mbps
850 * ieee80211 rate int is in 100kbps units eg, 0x0a=1Mbps
851 */
852 target_rate = (*iterator.this_arg) * 5;
853 for (i = 0; i < sband->n_bitrates; i++) {
854 struct ieee80211_rate *r;
855
856 r = &sband->bitrates[i];
857
858 if (r->bitrate == target_rate) {
859 tx->rate_idx = i;
860 break;
861 }
862 }
863 break;
864
865 case IEEE80211_RADIOTAP_ANTENNA:
866 /*
867 * radiotap uses 0 for 1st ant, mac80211 is 1 for
868 * 1st ant
869 */
870 info->antenna_sel_tx = (*iterator.this_arg) + 1;
871 break;
872
873#if 0
874 case IEEE80211_RADIOTAP_DBM_TX_POWER:
875 control->power_level = *iterator.this_arg;
876 break;
877#endif
878
879 case IEEE80211_RADIOTAP_FLAGS: 895 case IEEE80211_RADIOTAP_FLAGS:
880 if (*iterator.this_arg & IEEE80211_RADIOTAP_F_FCS) { 896 if (*iterator.this_arg & IEEE80211_RADIOTAP_F_FCS) {
881 /* 897 /*
@@ -933,7 +949,8 @@ __ieee80211_tx_prepare(struct ieee80211_tx_data *tx,
933 struct ieee80211_sub_if_data *sdata; 949 struct ieee80211_sub_if_data *sdata;
934 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); 950 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
935 951
936 int hdrlen; 952 int hdrlen, tid;
953 u8 *qc, *state;
937 954
938 memset(tx, 0, sizeof(*tx)); 955 memset(tx, 0, sizeof(*tx));
939 tx->skb = skb; 956 tx->skb = skb;
@@ -941,8 +958,6 @@ __ieee80211_tx_prepare(struct ieee80211_tx_data *tx,
941 tx->local = local; 958 tx->local = local;
942 tx->sdata = IEEE80211_DEV_TO_SUB_IF(dev); 959 tx->sdata = IEEE80211_DEV_TO_SUB_IF(dev);
943 tx->channel = local->hw.conf.channel; 960 tx->channel = local->hw.conf.channel;
944 tx->rate_idx = -1;
945 tx->last_frag_rate_idx = -1;
946 /* 961 /*
947 * Set this flag (used below to indicate "automatic fragmentation"), 962 * Set this flag (used below to indicate "automatic fragmentation"),
948 * it will be cleared/left by radiotap as desired. 963 * it will be cleared/left by radiotap as desired.
@@ -966,6 +981,15 @@ __ieee80211_tx_prepare(struct ieee80211_tx_data *tx,
966 981
967 tx->sta = sta_info_get(local, hdr->addr1); 982 tx->sta = sta_info_get(local, hdr->addr1);
968 983
984 if (tx->sta && ieee80211_is_data_qos(hdr->frame_control)) {
985 qc = ieee80211_get_qos_ctl(hdr);
986 tid = *qc & IEEE80211_QOS_CTL_TID_MASK;
987
988 state = &tx->sta->ampdu_mlme.tid_state_tx[tid];
989 if (*state == HT_AGG_STATE_OPERATIONAL)
990 info->flags |= IEEE80211_TX_CTL_AMPDU;
991 }
992
969 if (is_multicast_ether_addr(hdr->addr1)) { 993 if (is_multicast_ether_addr(hdr->addr1)) {
970 tx->flags &= ~IEEE80211_TX_UNICAST; 994 tx->flags &= ~IEEE80211_TX_UNICAST;
971 info->flags |= IEEE80211_TX_CTL_NO_ACK; 995 info->flags |= IEEE80211_TX_CTL_NO_ACK;
@@ -977,7 +1001,6 @@ __ieee80211_tx_prepare(struct ieee80211_tx_data *tx,
977 if (tx->flags & IEEE80211_TX_FRAGMENTED) { 1001 if (tx->flags & IEEE80211_TX_FRAGMENTED) {
978 if ((tx->flags & IEEE80211_TX_UNICAST) && 1002 if ((tx->flags & IEEE80211_TX_UNICAST) &&
979 skb->len + FCS_LEN > local->fragmentation_threshold && 1003 skb->len + FCS_LEN > local->fragmentation_threshold &&
980 !local->ops->set_frag_threshold &&
981 !(info->flags & IEEE80211_TX_CTL_AMPDU)) 1004 !(info->flags & IEEE80211_TX_CTL_AMPDU))
982 tx->flags |= IEEE80211_TX_FRAGMENTED; 1005 tx->flags |= IEEE80211_TX_FRAGMENTED;
983 else 1006 else
@@ -1043,23 +1066,11 @@ static int __ieee80211_tx(struct ieee80211_local *local, struct sk_buff *skb,
1043 if (!tx->extra_frag[i]) 1066 if (!tx->extra_frag[i])
1044 continue; 1067 continue;
1045 info = IEEE80211_SKB_CB(tx->extra_frag[i]); 1068 info = IEEE80211_SKB_CB(tx->extra_frag[i]);
1046 info->flags &= ~(IEEE80211_TX_CTL_USE_RTS_CTS | 1069 info->flags &= ~(IEEE80211_TX_CTL_CLEAR_PS_FILT |
1047 IEEE80211_TX_CTL_USE_CTS_PROTECT |
1048 IEEE80211_TX_CTL_CLEAR_PS_FILT |
1049 IEEE80211_TX_CTL_FIRST_FRAGMENT); 1070 IEEE80211_TX_CTL_FIRST_FRAGMENT);
1050 if (netif_subqueue_stopped(local->mdev, 1071 if (netif_subqueue_stopped(local->mdev,
1051 tx->extra_frag[i])) 1072 tx->extra_frag[i]))
1052 return IEEE80211_TX_FRAG_AGAIN; 1073 return IEEE80211_TX_FRAG_AGAIN;
1053 if (i == tx->num_extra_frag) {
1054 info->tx_rate_idx = tx->last_frag_rate_idx;
1055
1056 if (tx->flags & IEEE80211_TX_PROBE_LAST_FRAG)
1057 info->flags |=
1058 IEEE80211_TX_CTL_RATE_CTRL_PROBE;
1059 else
1060 info->flags &=
1061 ~IEEE80211_TX_CTL_RATE_CTRL_PROBE;
1062 }
1063 1074
1064 ret = local->ops->tx(local_to_hw(local), 1075 ret = local->ops->tx(local_to_hw(local),
1065 tx->extra_frag[i]); 1076 tx->extra_frag[i]);
@@ -1168,7 +1179,7 @@ retry:
1168 * queues, there's no reason for a driver to reject 1179 * queues, there's no reason for a driver to reject
1169 * a frame there, warn and drop it. 1180 * a frame there, warn and drop it.
1170 */ 1181 */
1171 if (WARN_ON(queue >= ieee80211_num_regular_queues(&local->hw))) 1182 if (WARN_ON(info->flags & IEEE80211_TX_CTL_AMPDU))
1172 goto drop; 1183 goto drop;
1173 1184
1174 store = &local->pending_packet[queue]; 1185 store = &local->pending_packet[queue];
@@ -1196,9 +1207,6 @@ retry:
1196 store->skb = skb; 1207 store->skb = skb;
1197 store->extra_frag = tx.extra_frag; 1208 store->extra_frag = tx.extra_frag;
1198 store->num_extra_frag = tx.num_extra_frag; 1209 store->num_extra_frag = tx.num_extra_frag;
1199 store->last_frag_rate_idx = tx.last_frag_rate_idx;
1200 store->last_frag_rate_ctrl_probe =
1201 !!(tx.flags & IEEE80211_TX_PROBE_LAST_FRAG);
1202 } 1210 }
1203 out: 1211 out:
1204 rcu_read_unlock(); 1212 rcu_read_unlock();
@@ -1465,6 +1473,19 @@ int ieee80211_subif_start_xmit(struct sk_buff *skb,
1465 goto fail; 1473 goto fail;
1466 } 1474 }
1467 1475
1476 if (!(local->hw.flags & IEEE80211_HW_NO_STACK_DYNAMIC_PS) &&
1477 local->dynamic_ps_timeout > 0) {
1478 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
1479 ieee80211_stop_queues_by_reason(&local->hw,
1480 IEEE80211_QUEUE_STOP_REASON_PS);
1481 queue_work(local->hw.workqueue,
1482 &local->dynamic_ps_disable_work);
1483 }
1484
1485 mod_timer(&local->dynamic_ps_timer, jiffies +
1486 msecs_to_jiffies(local->dynamic_ps_timeout));
1487 }
1488
1468 nh_pos = skb_network_header(skb) - skb->data; 1489 nh_pos = skb_network_header(skb) - skb->data;
1469 h_pos = skb_transport_header(skb) - skb->data; 1490 h_pos = skb_transport_header(skb) - skb->data;
1470 1491
@@ -1593,12 +1614,10 @@ int ieee80211_subif_start_xmit(struct sk_buff *skb,
1593 compare_ether_addr(dev->dev_addr, 1614 compare_ether_addr(dev->dev_addr,
1594 skb->data + ETH_ALEN) == 0))) { 1615 skb->data + ETH_ALEN) == 0))) {
1595#ifdef CONFIG_MAC80211_VERBOSE_DEBUG 1616#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
1596 DECLARE_MAC_BUF(mac);
1597
1598 if (net_ratelimit()) 1617 if (net_ratelimit())
1599 printk(KERN_DEBUG "%s: dropped frame to %s" 1618 printk(KERN_DEBUG "%s: dropped frame to %pM"
1600 " (unauthorized port)\n", dev->name, 1619 " (unauthorized port)\n", dev->name,
1601 print_mac(mac, hdr.addr1)); 1620 hdr.addr1);
1602#endif 1621#endif
1603 1622
1604 I802_DEBUG_INC(local->tx_handlers_drop_unauth_port); 1623 I802_DEBUG_INC(local->tx_handlers_drop_unauth_port);
@@ -1757,10 +1776,7 @@ void ieee80211_tx_pending(unsigned long data)
1757 store = &local->pending_packet[i]; 1776 store = &local->pending_packet[i];
1758 tx.extra_frag = store->extra_frag; 1777 tx.extra_frag = store->extra_frag;
1759 tx.num_extra_frag = store->num_extra_frag; 1778 tx.num_extra_frag = store->num_extra_frag;
1760 tx.last_frag_rate_idx = store->last_frag_rate_idx;
1761 tx.flags = 0; 1779 tx.flags = 0;
1762 if (store->last_frag_rate_ctrl_probe)
1763 tx.flags |= IEEE80211_TX_PROBE_LAST_FRAG;
1764 ret = __ieee80211_tx(local, store->skb, &tx); 1780 ret = __ieee80211_tx(local, store->skb, &tx);
1765 if (ret) { 1781 if (ret) {
1766 if (ret == IEEE80211_TX_FRAG_AGAIN) 1782 if (ret == IEEE80211_TX_FRAG_AGAIN)
@@ -1775,8 +1791,7 @@ void ieee80211_tx_pending(unsigned long data)
1775 1791
1776/* functions for drivers to get certain frames */ 1792/* functions for drivers to get certain frames */
1777 1793
1778static void ieee80211_beacon_add_tim(struct ieee80211_local *local, 1794static void ieee80211_beacon_add_tim(struct ieee80211_if_ap *bss,
1779 struct ieee80211_if_ap *bss,
1780 struct sk_buff *skb, 1795 struct sk_buff *skb,
1781 struct beacon_data *beacon) 1796 struct beacon_data *beacon)
1782{ 1797{
@@ -1844,11 +1859,9 @@ struct sk_buff *ieee80211_beacon_get(struct ieee80211_hw *hw,
1844 struct ieee80211_local *local = hw_to_local(hw); 1859 struct ieee80211_local *local = hw_to_local(hw);
1845 struct sk_buff *skb = NULL; 1860 struct sk_buff *skb = NULL;
1846 struct ieee80211_tx_info *info; 1861 struct ieee80211_tx_info *info;
1847 struct net_device *bdev;
1848 struct ieee80211_sub_if_data *sdata = NULL; 1862 struct ieee80211_sub_if_data *sdata = NULL;
1849 struct ieee80211_if_ap *ap = NULL; 1863 struct ieee80211_if_ap *ap = NULL;
1850 struct ieee80211_if_sta *ifsta = NULL; 1864 struct ieee80211_if_sta *ifsta = NULL;
1851 struct rate_selection rsel;
1852 struct beacon_data *beacon; 1865 struct beacon_data *beacon;
1853 struct ieee80211_supported_band *sband; 1866 struct ieee80211_supported_band *sband;
1854 enum ieee80211_band band = local->hw.conf.channel->band; 1867 enum ieee80211_band band = local->hw.conf.channel->band;
@@ -1858,7 +1871,6 @@ struct sk_buff *ieee80211_beacon_get(struct ieee80211_hw *hw,
1858 rcu_read_lock(); 1871 rcu_read_lock();
1859 1872
1860 sdata = vif_to_sdata(vif); 1873 sdata = vif_to_sdata(vif);
1861 bdev = sdata->dev;
1862 1874
1863 if (sdata->vif.type == NL80211_IFTYPE_AP) { 1875 if (sdata->vif.type == NL80211_IFTYPE_AP) {
1864 ap = &sdata->u.ap; 1876 ap = &sdata->u.ap;
@@ -1886,12 +1898,12 @@ struct sk_buff *ieee80211_beacon_get(struct ieee80211_hw *hw,
1886 * of the tim bitmap in mac80211 and the driver. 1898 * of the tim bitmap in mac80211 and the driver.
1887 */ 1899 */
1888 if (local->tim_in_locked_section) { 1900 if (local->tim_in_locked_section) {
1889 ieee80211_beacon_add_tim(local, ap, skb, beacon); 1901 ieee80211_beacon_add_tim(ap, skb, beacon);
1890 } else { 1902 } else {
1891 unsigned long flags; 1903 unsigned long flags;
1892 1904
1893 spin_lock_irqsave(&local->sta_lock, flags); 1905 spin_lock_irqsave(&local->sta_lock, flags);
1894 ieee80211_beacon_add_tim(local, ap, skb, beacon); 1906 ieee80211_beacon_add_tim(ap, skb, beacon);
1895 spin_unlock_irqrestore(&local->sta_lock, flags); 1907 spin_unlock_irqrestore(&local->sta_lock, flags);
1896 } 1908 }
1897 1909
@@ -1952,33 +1964,23 @@ struct sk_buff *ieee80211_beacon_get(struct ieee80211_hw *hw,
1952 skb->do_not_encrypt = 1; 1964 skb->do_not_encrypt = 1;
1953 1965
1954 info->band = band; 1966 info->band = band;
1955 rate_control_get_rate(sdata, sband, NULL, skb, &rsel); 1967 /*
1956 1968 * XXX: For now, always use the lowest rate
1957 if (unlikely(rsel.rate_idx < 0)) { 1969 */
1958 if (net_ratelimit()) { 1970 info->control.rates[0].idx = 0;
1959 printk(KERN_DEBUG "%s: ieee80211_beacon_get: " 1971 info->control.rates[0].count = 1;
1960 "no rate found\n", 1972 info->control.rates[1].idx = -1;
1961 wiphy_name(local->hw.wiphy)); 1973 info->control.rates[2].idx = -1;
1962 } 1974 info->control.rates[3].idx = -1;
1963 dev_kfree_skb_any(skb); 1975 info->control.rates[4].idx = -1;
1964 skb = NULL; 1976 BUILD_BUG_ON(IEEE80211_TX_MAX_RATES != 5);
1965 goto out;
1966 }
1967 1977
1968 info->control.vif = vif; 1978 info->control.vif = vif;
1969 info->tx_rate_idx = rsel.rate_idx;
1970 1979
1971 info->flags |= IEEE80211_TX_CTL_NO_ACK; 1980 info->flags |= IEEE80211_TX_CTL_NO_ACK;
1972 info->flags |= IEEE80211_TX_CTL_CLEAR_PS_FILT; 1981 info->flags |= IEEE80211_TX_CTL_CLEAR_PS_FILT;
1973 info->flags |= IEEE80211_TX_CTL_ASSIGN_SEQ; 1982 info->flags |= IEEE80211_TX_CTL_ASSIGN_SEQ;
1974 if (sdata->bss_conf.use_short_preamble && 1983 out:
1975 sband->bitrates[rsel.rate_idx].flags & IEEE80211_RATE_SHORT_PREAMBLE)
1976 info->flags |= IEEE80211_TX_CTL_SHORT_PREAMBLE;
1977
1978 info->antenna_sel_tx = local->hw.conf.antenna_sel_tx;
1979 info->control.retry_limit = 1;
1980
1981out:
1982 rcu_read_unlock(); 1984 rcu_read_unlock();
1983 return skb; 1985 return skb;
1984} 1986}
@@ -2023,14 +2025,12 @@ ieee80211_get_buffered_bc(struct ieee80211_hw *hw,
2023 struct sk_buff *skb = NULL; 2025 struct sk_buff *skb = NULL;
2024 struct sta_info *sta; 2026 struct sta_info *sta;
2025 struct ieee80211_tx_data tx; 2027 struct ieee80211_tx_data tx;
2026 struct net_device *bdev;
2027 struct ieee80211_sub_if_data *sdata; 2028 struct ieee80211_sub_if_data *sdata;
2028 struct ieee80211_if_ap *bss = NULL; 2029 struct ieee80211_if_ap *bss = NULL;
2029 struct beacon_data *beacon; 2030 struct beacon_data *beacon;
2030 struct ieee80211_tx_info *info; 2031 struct ieee80211_tx_info *info;
2031 2032
2032 sdata = vif_to_sdata(vif); 2033 sdata = vif_to_sdata(vif);
2033 bdev = sdata->dev;
2034 bss = &sdata->u.ap; 2034 bss = &sdata->u.ap;
2035 2035
2036 if (!bss) 2036 if (!bss)
diff --git a/net/mac80211/util.c b/net/mac80211/util.c
index cee4884b9d06..fb89e1d0aa03 100644
--- a/net/mac80211/util.c
+++ b/net/mac80211/util.c
@@ -239,7 +239,7 @@ __le16 ieee80211_generic_frame_duration(struct ieee80211_hw *hw,
239 erp = 0; 239 erp = 0;
240 if (vif) { 240 if (vif) {
241 sdata = vif_to_sdata(vif); 241 sdata = vif_to_sdata(vif);
242 short_preamble = sdata->bss_conf.use_short_preamble; 242 short_preamble = sdata->vif.bss_conf.use_short_preamble;
243 if (sdata->flags & IEEE80211_SDATA_OPERATING_GMODE) 243 if (sdata->flags & IEEE80211_SDATA_OPERATING_GMODE)
244 erp = rate->flags & IEEE80211_RATE_ERP_G; 244 erp = rate->flags & IEEE80211_RATE_ERP_G;
245 } 245 }
@@ -272,7 +272,7 @@ __le16 ieee80211_rts_duration(struct ieee80211_hw *hw,
272 erp = 0; 272 erp = 0;
273 if (vif) { 273 if (vif) {
274 sdata = vif_to_sdata(vif); 274 sdata = vif_to_sdata(vif);
275 short_preamble = sdata->bss_conf.use_short_preamble; 275 short_preamble = sdata->vif.bss_conf.use_short_preamble;
276 if (sdata->flags & IEEE80211_SDATA_OPERATING_GMODE) 276 if (sdata->flags & IEEE80211_SDATA_OPERATING_GMODE)
277 erp = rate->flags & IEEE80211_RATE_ERP_G; 277 erp = rate->flags & IEEE80211_RATE_ERP_G;
278 } 278 }
@@ -312,7 +312,7 @@ __le16 ieee80211_ctstoself_duration(struct ieee80211_hw *hw,
312 erp = 0; 312 erp = 0;
313 if (vif) { 313 if (vif) {
314 sdata = vif_to_sdata(vif); 314 sdata = vif_to_sdata(vif);
315 short_preamble = sdata->bss_conf.use_short_preamble; 315 short_preamble = sdata->vif.bss_conf.use_short_preamble;
316 if (sdata->flags & IEEE80211_SDATA_OPERATING_GMODE) 316 if (sdata->flags & IEEE80211_SDATA_OPERATING_GMODE)
317 erp = rate->flags & IEEE80211_RATE_ERP_G; 317 erp = rate->flags & IEEE80211_RATE_ERP_G;
318 } 318 }
@@ -330,10 +330,20 @@ __le16 ieee80211_ctstoself_duration(struct ieee80211_hw *hw,
330} 330}
331EXPORT_SYMBOL(ieee80211_ctstoself_duration); 331EXPORT_SYMBOL(ieee80211_ctstoself_duration);
332 332
333void ieee80211_wake_queue(struct ieee80211_hw *hw, int queue) 333static void __ieee80211_wake_queue(struct ieee80211_hw *hw, int queue,
334 enum queue_stop_reason reason)
334{ 335{
335 struct ieee80211_local *local = hw_to_local(hw); 336 struct ieee80211_local *local = hw_to_local(hw);
336 337
338 /* we don't need to track ampdu queues */
339 if (queue < ieee80211_num_regular_queues(hw)) {
340 __clear_bit(reason, &local->queue_stop_reasons[queue]);
341
342 if (local->queue_stop_reasons[queue] != 0)
343 /* someone still has this queue stopped */
344 return;
345 }
346
337 if (test_bit(queue, local->queues_pending)) { 347 if (test_bit(queue, local->queues_pending)) {
338 set_bit(queue, local->queues_pending_run); 348 set_bit(queue, local->queues_pending_run);
339 tasklet_schedule(&local->tx_pending_tasklet); 349 tasklet_schedule(&local->tx_pending_tasklet);
@@ -341,22 +351,74 @@ void ieee80211_wake_queue(struct ieee80211_hw *hw, int queue)
341 netif_wake_subqueue(local->mdev, queue); 351 netif_wake_subqueue(local->mdev, queue);
342 } 352 }
343} 353}
354
355void ieee80211_wake_queue_by_reason(struct ieee80211_hw *hw, int queue,
356 enum queue_stop_reason reason)
357{
358 struct ieee80211_local *local = hw_to_local(hw);
359 unsigned long flags;
360
361 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
362 __ieee80211_wake_queue(hw, queue, reason);
363 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
364}
365
366void ieee80211_wake_queue(struct ieee80211_hw *hw, int queue)
367{
368 ieee80211_wake_queue_by_reason(hw, queue,
369 IEEE80211_QUEUE_STOP_REASON_DRIVER);
370}
344EXPORT_SYMBOL(ieee80211_wake_queue); 371EXPORT_SYMBOL(ieee80211_wake_queue);
345 372
346void ieee80211_stop_queue(struct ieee80211_hw *hw, int queue) 373static void __ieee80211_stop_queue(struct ieee80211_hw *hw, int queue,
374 enum queue_stop_reason reason)
347{ 375{
348 struct ieee80211_local *local = hw_to_local(hw); 376 struct ieee80211_local *local = hw_to_local(hw);
349 377
378 /* we don't need to track ampdu queues */
379 if (queue < ieee80211_num_regular_queues(hw))
380 __set_bit(reason, &local->queue_stop_reasons[queue]);
381
350 netif_stop_subqueue(local->mdev, queue); 382 netif_stop_subqueue(local->mdev, queue);
351} 383}
384
385void ieee80211_stop_queue_by_reason(struct ieee80211_hw *hw, int queue,
386 enum queue_stop_reason reason)
387{
388 struct ieee80211_local *local = hw_to_local(hw);
389 unsigned long flags;
390
391 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
392 __ieee80211_stop_queue(hw, queue, reason);
393 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
394}
395
396void ieee80211_stop_queue(struct ieee80211_hw *hw, int queue)
397{
398 ieee80211_stop_queue_by_reason(hw, queue,
399 IEEE80211_QUEUE_STOP_REASON_DRIVER);
400}
352EXPORT_SYMBOL(ieee80211_stop_queue); 401EXPORT_SYMBOL(ieee80211_stop_queue);
353 402
354void ieee80211_stop_queues(struct ieee80211_hw *hw) 403void ieee80211_stop_queues_by_reason(struct ieee80211_hw *hw,
404 enum queue_stop_reason reason)
355{ 405{
406 struct ieee80211_local *local = hw_to_local(hw);
407 unsigned long flags;
356 int i; 408 int i;
357 409
410 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
411
358 for (i = 0; i < ieee80211_num_queues(hw); i++) 412 for (i = 0; i < ieee80211_num_queues(hw); i++)
359 ieee80211_stop_queue(hw, i); 413 __ieee80211_stop_queue(hw, i, reason);
414
415 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
416}
417
418void ieee80211_stop_queues(struct ieee80211_hw *hw)
419{
420 ieee80211_stop_queues_by_reason(hw,
421 IEEE80211_QUEUE_STOP_REASON_DRIVER);
360} 422}
361EXPORT_SYMBOL(ieee80211_stop_queues); 423EXPORT_SYMBOL(ieee80211_stop_queues);
362 424
@@ -367,12 +429,24 @@ int ieee80211_queue_stopped(struct ieee80211_hw *hw, int queue)
367} 429}
368EXPORT_SYMBOL(ieee80211_queue_stopped); 430EXPORT_SYMBOL(ieee80211_queue_stopped);
369 431
370void ieee80211_wake_queues(struct ieee80211_hw *hw) 432void ieee80211_wake_queues_by_reason(struct ieee80211_hw *hw,
433 enum queue_stop_reason reason)
371{ 434{
435 struct ieee80211_local *local = hw_to_local(hw);
436 unsigned long flags;
372 int i; 437 int i;
373 438
439 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
440
374 for (i = 0; i < hw->queues + hw->ampdu_queues; i++) 441 for (i = 0; i < hw->queues + hw->ampdu_queues; i++)
375 ieee80211_wake_queue(hw, i); 442 __ieee80211_wake_queue(hw, i, reason);
443
444 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
445}
446
447void ieee80211_wake_queues(struct ieee80211_hw *hw)
448{
449 ieee80211_wake_queues_by_reason(hw, IEEE80211_QUEUE_STOP_REASON_DRIVER);
376} 450}
377EXPORT_SYMBOL(ieee80211_wake_queues); 451EXPORT_SYMBOL(ieee80211_wake_queues);
378 452
@@ -532,8 +606,8 @@ void ieee802_11_parse_elems(u8 *start, size_t len,
532 if (elen >= sizeof(struct ieee80211_ht_cap)) 606 if (elen >= sizeof(struct ieee80211_ht_cap))
533 elems->ht_cap_elem = (void *)pos; 607 elems->ht_cap_elem = (void *)pos;
534 break; 608 break;
535 case WLAN_EID_HT_EXTRA_INFO: 609 case WLAN_EID_HT_INFORMATION:
536 if (elen >= sizeof(struct ieee80211_ht_addt_info)) 610 if (elen >= sizeof(struct ieee80211_ht_info))
537 elems->ht_info_elem = (void *)pos; 611 elems->ht_info_elem = (void *)pos;
538 break; 612 break;
539 case WLAN_EID_MESH_ID: 613 case WLAN_EID_MESH_ID:
@@ -638,19 +712,16 @@ int ieee80211_set_freq(struct ieee80211_sub_if_data *sdata, int freqMHz)
638 712
639 if (chan && !(chan->flags & IEEE80211_CHAN_DISABLED)) { 713 if (chan && !(chan->flags & IEEE80211_CHAN_DISABLED)) {
640 if (sdata->vif.type == NL80211_IFTYPE_ADHOC && 714 if (sdata->vif.type == NL80211_IFTYPE_ADHOC &&
641 chan->flags & IEEE80211_CHAN_NO_IBSS) { 715 chan->flags & IEEE80211_CHAN_NO_IBSS)
642 printk(KERN_DEBUG "%s: IBSS not allowed on frequency "
643 "%d MHz\n", sdata->dev->name, chan->center_freq);
644 return ret; 716 return ret;
645 }
646 local->oper_channel = chan; 717 local->oper_channel = chan;
718 local->oper_channel_type = NL80211_CHAN_NO_HT;
647 719
648 if (local->sw_scanning || local->hw_scanning) 720 if (local->sw_scanning || local->hw_scanning)
649 ret = 0; 721 ret = 0;
650 else 722 else
651 ret = ieee80211_hw_config(local); 723 ret = ieee80211_hw_config(
652 724 local, IEEE80211_CONF_CHANGE_CHANNEL);
653 rate_control_clear(local);
654 } 725 }
655 726
656 return ret; 727 return ret;
diff --git a/net/mac80211/wep.c b/net/mac80211/wep.c
index f0e2d3ecb5c4..7043ddc75498 100644
--- a/net/mac80211/wep.c
+++ b/net/mac80211/wep.c
@@ -17,6 +17,7 @@
17#include <linux/err.h> 17#include <linux/err.h>
18#include <linux/mm.h> 18#include <linux/mm.h>
19#include <linux/scatterlist.h> 19#include <linux/scatterlist.h>
20#include <asm/unaligned.h>
20 21
21#include <net/mac80211.h> 22#include <net/mac80211.h>
22#include "ieee80211_i.h" 23#include "ieee80211_i.h"
@@ -49,17 +50,19 @@ void ieee80211_wep_free(struct ieee80211_local *local)
49 crypto_free_blkcipher(local->wep_rx_tfm); 50 crypto_free_blkcipher(local->wep_rx_tfm);
50} 51}
51 52
52static inline int ieee80211_wep_weak_iv(u32 iv, int keylen) 53static inline bool ieee80211_wep_weak_iv(u32 iv, int keylen)
53{ 54{
54 /* Fluhrer, Mantin, and Shamir have reported weaknesses in the 55 /*
56 * Fluhrer, Mantin, and Shamir have reported weaknesses in the
55 * key scheduling algorithm of RC4. At least IVs (KeyByte + 3, 57 * key scheduling algorithm of RC4. At least IVs (KeyByte + 3,
56 * 0xff, N) can be used to speedup attacks, so avoid using them. */ 58 * 0xff, N) can be used to speedup attacks, so avoid using them.
59 */
57 if ((iv & 0xff00) == 0xff00) { 60 if ((iv & 0xff00) == 0xff00) {
58 u8 B = (iv >> 16) & 0xff; 61 u8 B = (iv >> 16) & 0xff;
59 if (B >= 3 && B < 3 + keylen) 62 if (B >= 3 && B < 3 + keylen)
60 return 1; 63 return true;
61 } 64 }
62 return 0; 65 return false;
63} 66}
64 67
65 68
@@ -123,10 +126,10 @@ void ieee80211_wep_encrypt_data(struct crypto_blkcipher *tfm, u8 *rc4key,
123{ 126{
124 struct blkcipher_desc desc = { .tfm = tfm }; 127 struct blkcipher_desc desc = { .tfm = tfm };
125 struct scatterlist sg; 128 struct scatterlist sg;
126 __le32 *icv; 129 __le32 icv;
127 130
128 icv = (__le32 *)(data + data_len); 131 icv = cpu_to_le32(~crc32_le(~0, data, data_len));
129 *icv = cpu_to_le32(~crc32_le(~0, data, data_len)); 132 put_unaligned(icv, (__le32 *)(data + data_len));
130 133
131 crypto_blkcipher_setkey(tfm, rc4key, klen); 134 crypto_blkcipher_setkey(tfm, rc4key, klen);
132 sg_init_one(&sg, data, data_len + WEP_ICV_LEN); 135 sg_init_one(&sg, data, data_len + WEP_ICV_LEN);
@@ -268,7 +271,7 @@ int ieee80211_wep_decrypt(struct ieee80211_local *local, struct sk_buff *skb,
268} 271}
269 272
270 273
271u8 * ieee80211_wep_is_weak_iv(struct sk_buff *skb, struct ieee80211_key *key) 274bool ieee80211_wep_is_weak_iv(struct sk_buff *skb, struct ieee80211_key *key)
272{ 275{
273 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; 276 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
274 unsigned int hdrlen; 277 unsigned int hdrlen;
@@ -276,16 +279,13 @@ u8 * ieee80211_wep_is_weak_iv(struct sk_buff *skb, struct ieee80211_key *key)
276 u32 iv; 279 u32 iv;
277 280
278 if (!ieee80211_has_protected(hdr->frame_control)) 281 if (!ieee80211_has_protected(hdr->frame_control))
279 return NULL; 282 return false;
280 283
281 hdrlen = ieee80211_hdrlen(hdr->frame_control); 284 hdrlen = ieee80211_hdrlen(hdr->frame_control);
282 ivpos = skb->data + hdrlen; 285 ivpos = skb->data + hdrlen;
283 iv = (ivpos[0] << 16) | (ivpos[1] << 8) | ivpos[2]; 286 iv = (ivpos[0] << 16) | (ivpos[1] << 8) | ivpos[2];
284 287
285 if (ieee80211_wep_weak_iv(iv, key->conf.keylen)) 288 return ieee80211_wep_weak_iv(iv, key->conf.keylen);
286 return ivpos;
287
288 return NULL;
289} 289}
290 290
291ieee80211_rx_result 291ieee80211_rx_result
@@ -329,6 +329,8 @@ static int wep_encrypt_skb(struct ieee80211_tx_data *tx, struct sk_buff *skb)
329ieee80211_tx_result 329ieee80211_tx_result
330ieee80211_crypto_wep_encrypt(struct ieee80211_tx_data *tx) 330ieee80211_crypto_wep_encrypt(struct ieee80211_tx_data *tx)
331{ 331{
332 int i;
333
332 ieee80211_tx_set_protected(tx); 334 ieee80211_tx_set_protected(tx);
333 335
334 if (wep_encrypt_skb(tx, tx->skb) < 0) { 336 if (wep_encrypt_skb(tx, tx->skb) < 0) {
@@ -337,9 +339,8 @@ ieee80211_crypto_wep_encrypt(struct ieee80211_tx_data *tx)
337 } 339 }
338 340
339 if (tx->extra_frag) { 341 if (tx->extra_frag) {
340 int i;
341 for (i = 0; i < tx->num_extra_frag; i++) { 342 for (i = 0; i < tx->num_extra_frag; i++) {
342 if (wep_encrypt_skb(tx, tx->extra_frag[i]) < 0) { 343 if (wep_encrypt_skb(tx, tx->extra_frag[i])) {
343 I802_DEBUG_INC(tx->local-> 344 I802_DEBUG_INC(tx->local->
344 tx_handlers_drop_wep); 345 tx_handlers_drop_wep);
345 return TX_DROP; 346 return TX_DROP;
diff --git a/net/mac80211/wep.h b/net/mac80211/wep.h
index e587172115b8..d3f0db48314e 100644
--- a/net/mac80211/wep.h
+++ b/net/mac80211/wep.h
@@ -26,7 +26,7 @@ int ieee80211_wep_encrypt(struct ieee80211_local *local, struct sk_buff *skb,
26 struct ieee80211_key *key); 26 struct ieee80211_key *key);
27int ieee80211_wep_decrypt(struct ieee80211_local *local, struct sk_buff *skb, 27int ieee80211_wep_decrypt(struct ieee80211_local *local, struct sk_buff *skb,
28 struct ieee80211_key *key); 28 struct ieee80211_key *key);
29u8 *ieee80211_wep_is_weak_iv(struct sk_buff *skb, struct ieee80211_key *key); 29bool ieee80211_wep_is_weak_iv(struct sk_buff *skb, struct ieee80211_key *key);
30 30
31ieee80211_rx_result 31ieee80211_rx_result
32ieee80211_crypto_wep_decrypt(struct ieee80211_rx_data *rx); 32ieee80211_crypto_wep_decrypt(struct ieee80211_rx_data *rx);
diff --git a/net/mac80211/wext.c b/net/mac80211/wext.c
index ab4ddba874be..7162d5816f39 100644
--- a/net/mac80211/wext.c
+++ b/net/mac80211/wext.c
@@ -135,48 +135,6 @@ static int ieee80211_ioctl_siwgenie(struct net_device *dev,
135 return -EOPNOTSUPP; 135 return -EOPNOTSUPP;
136} 136}
137 137
138static int ieee80211_ioctl_giwname(struct net_device *dev,
139 struct iw_request_info *info,
140 char *name, char *extra)
141{
142 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
143 struct ieee80211_supported_band *sband;
144 u8 is_ht = 0, is_a = 0, is_b = 0, is_g = 0;
145
146
147 sband = local->hw.wiphy->bands[IEEE80211_BAND_5GHZ];
148 if (sband) {
149 is_a = 1;
150 is_ht |= sband->ht_info.ht_supported;
151 }
152
153 sband = local->hw.wiphy->bands[IEEE80211_BAND_2GHZ];
154 if (sband) {
155 int i;
156 /* Check for mandatory rates */
157 for (i = 0; i < sband->n_bitrates; i++) {
158 if (sband->bitrates[i].bitrate == 10)
159 is_b = 1;
160 if (sband->bitrates[i].bitrate == 60)
161 is_g = 1;
162 }
163 is_ht |= sband->ht_info.ht_supported;
164 }
165
166 strcpy(name, "IEEE 802.11");
167 if (is_a)
168 strcat(name, "a");
169 if (is_b)
170 strcat(name, "b");
171 if (is_g)
172 strcat(name, "g");
173 if (is_ht)
174 strcat(name, "n");
175
176 return 0;
177}
178
179
180static int ieee80211_ioctl_giwrange(struct net_device *dev, 138static int ieee80211_ioctl_giwrange(struct net_device *dev,
181 struct iw_request_info *info, 139 struct iw_request_info *info,
182 struct iw_point *data, char *extra) 140 struct iw_point *data, char *extra)
@@ -266,78 +224,6 @@ static int ieee80211_ioctl_giwrange(struct net_device *dev,
266} 224}
267 225
268 226
269static int ieee80211_ioctl_siwmode(struct net_device *dev,
270 struct iw_request_info *info,
271 __u32 *mode, char *extra)
272{
273 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
274 struct ieee80211_local *local = sdata->local;
275 int type;
276
277 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
278 return -EOPNOTSUPP;
279
280 switch (*mode) {
281 case IW_MODE_INFRA:
282 type = NL80211_IFTYPE_STATION;
283 break;
284 case IW_MODE_ADHOC:
285 /* Setting ad-hoc mode on non ibss channel is not
286 * supported.
287 */
288 if (local->oper_channel &&
289 (local->oper_channel->flags & IEEE80211_CHAN_NO_IBSS))
290 return -EOPNOTSUPP;
291
292 type = NL80211_IFTYPE_ADHOC;
293 break;
294 case IW_MODE_REPEAT:
295 type = NL80211_IFTYPE_WDS;
296 break;
297 case IW_MODE_MONITOR:
298 type = NL80211_IFTYPE_MONITOR;
299 break;
300 default:
301 return -EINVAL;
302 }
303
304 return ieee80211_if_change_type(sdata, type);
305}
306
307
308static int ieee80211_ioctl_giwmode(struct net_device *dev,
309 struct iw_request_info *info,
310 __u32 *mode, char *extra)
311{
312 struct ieee80211_sub_if_data *sdata;
313
314 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
315 switch (sdata->vif.type) {
316 case NL80211_IFTYPE_AP:
317 *mode = IW_MODE_MASTER;
318 break;
319 case NL80211_IFTYPE_STATION:
320 *mode = IW_MODE_INFRA;
321 break;
322 case NL80211_IFTYPE_ADHOC:
323 *mode = IW_MODE_ADHOC;
324 break;
325 case NL80211_IFTYPE_MONITOR:
326 *mode = IW_MODE_MONITOR;
327 break;
328 case NL80211_IFTYPE_WDS:
329 *mode = IW_MODE_REPEAT;
330 break;
331 case NL80211_IFTYPE_AP_VLAN:
332 *mode = IW_MODE_SECOND; /* FIXME */
333 break;
334 default:
335 *mode = IW_MODE_AUTO;
336 break;
337 }
338 return 0;
339}
340
341static int ieee80211_ioctl_siwfreq(struct net_device *dev, 227static int ieee80211_ioctl_siwfreq(struct net_device *dev,
342 struct iw_request_info *info, 228 struct iw_request_info *info,
343 struct iw_freq *freq, char *extra) 229 struct iw_freq *freq, char *extra)
@@ -415,13 +301,6 @@ static int ieee80211_ioctl_siwessid(struct net_device *dev,
415 return 0; 301 return 0;
416 } 302 }
417 303
418 if (sdata->vif.type == NL80211_IFTYPE_AP) {
419 memcpy(sdata->u.ap.ssid, ssid, len);
420 memset(sdata->u.ap.ssid + len, 0,
421 IEEE80211_MAX_SSID_LEN - len);
422 sdata->u.ap.ssid_len = len;
423 return ieee80211_if_config(sdata, IEEE80211_IFCC_SSID);
424 }
425 return -EOPNOTSUPP; 304 return -EOPNOTSUPP;
426} 305}
427 306
@@ -445,15 +324,6 @@ static int ieee80211_ioctl_giwessid(struct net_device *dev,
445 return res; 324 return res;
446 } 325 }
447 326
448 if (sdata->vif.type == NL80211_IFTYPE_AP) {
449 len = sdata->u.ap.ssid_len;
450 if (len > IW_ESSID_MAX_SIZE)
451 len = IW_ESSID_MAX_SIZE;
452 memcpy(ssid, sdata->u.ap.ssid, len);
453 data->length = len;
454 data->flags = 1;
455 return 0;
456 }
457 return -EOPNOTSUPP; 327 return -EOPNOTSUPP;
458} 328}
459 329
@@ -548,8 +418,7 @@ static int ieee80211_ioctl_siwscan(struct net_device *dev,
548 418
549 if (sdata->vif.type != NL80211_IFTYPE_STATION && 419 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
550 sdata->vif.type != NL80211_IFTYPE_ADHOC && 420 sdata->vif.type != NL80211_IFTYPE_ADHOC &&
551 sdata->vif.type != NL80211_IFTYPE_MESH_POINT && 421 sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
552 sdata->vif.type != NL80211_IFTYPE_AP)
553 return -EOPNOTSUPP; 422 return -EOPNOTSUPP;
554 423
555 /* if SSID was specified explicitly then use that */ 424 /* if SSID was specified explicitly then use that */
@@ -644,8 +513,8 @@ static int ieee80211_ioctl_giwrate(struct net_device *dev,
644 513
645 sta = sta_info_get(local, sdata->u.sta.bssid); 514 sta = sta_info_get(local, sdata->u.sta.bssid);
646 515
647 if (sta && sta->last_txrate_idx < sband->n_bitrates) 516 if (sta && !(sta->last_tx_rate.flags & IEEE80211_TX_RC_MCS))
648 rate->value = sband->bitrates[sta->last_txrate_idx].bitrate; 517 rate->value = sband->bitrates[sta->last_tx_rate.idx].bitrate;
649 else 518 else
650 rate->value = 0; 519 rate->value = 0;
651 520
@@ -664,45 +533,35 @@ static int ieee80211_ioctl_siwtxpower(struct net_device *dev,
664 union iwreq_data *data, char *extra) 533 union iwreq_data *data, char *extra)
665{ 534{
666 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); 535 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
667 bool need_reconfig = 0; 536 struct ieee80211_channel* chan = local->hw.conf.channel;
537 u32 reconf_flags = 0;
668 int new_power_level; 538 int new_power_level;
669 539
670 if ((data->txpower.flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM) 540 if ((data->txpower.flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM)
671 return -EINVAL; 541 return -EINVAL;
672 if (data->txpower.flags & IW_TXPOW_RANGE) 542 if (data->txpower.flags & IW_TXPOW_RANGE)
673 return -EINVAL; 543 return -EINVAL;
544 if (!chan)
545 return -EINVAL;
674 546
675 if (data->txpower.fixed) { 547 if (data->txpower.fixed)
676 new_power_level = data->txpower.value; 548 new_power_level = min(data->txpower.value, chan->max_power);
677 } else { 549 else /* Automatic power level setting */
678 /*
679 * Automatic power level. Use maximum power for the current
680 * channel. Should be part of rate control.
681 */
682 struct ieee80211_channel* chan = local->hw.conf.channel;
683 if (!chan)
684 return -EINVAL;
685
686 new_power_level = chan->max_power; 550 new_power_level = chan->max_power;
687 }
688 551
689 if (local->hw.conf.power_level != new_power_level) { 552 if (local->hw.conf.power_level != new_power_level) {
690 local->hw.conf.power_level = new_power_level; 553 local->hw.conf.power_level = new_power_level;
691 need_reconfig = 1; 554 reconf_flags |= IEEE80211_CONF_CHANGE_POWER;
692 } 555 }
693 556
694 if (local->hw.conf.radio_enabled != !(data->txpower.disabled)) { 557 if (local->hw.conf.radio_enabled != !(data->txpower.disabled)) {
695 local->hw.conf.radio_enabled = !(data->txpower.disabled); 558 local->hw.conf.radio_enabled = !(data->txpower.disabled);
696 need_reconfig = 1; 559 reconf_flags |= IEEE80211_CONF_CHANGE_RADIO_ENABLED;
697 ieee80211_led_radio(local, local->hw.conf.radio_enabled); 560 ieee80211_led_radio(local, local->hw.conf.radio_enabled);
698 } 561 }
699 562
700 if (need_reconfig) { 563 if (reconf_flags)
701 ieee80211_hw_config(local); 564 ieee80211_hw_config(local, reconf_flags);
702 /* The return value of hw_config is not of big interest here,
703 * as it doesn't say that it failed because of _this_ config
704 * change or something else. Ignore it. */
705 }
706 565
707 return 0; 566 return 0;
708} 567}
@@ -779,14 +638,6 @@ static int ieee80211_ioctl_siwfrag(struct net_device *dev,
779 local->fragmentation_threshold = frag->value & ~0x1; 638 local->fragmentation_threshold = frag->value & ~0x1;
780 } 639 }
781 640
782 /* If the wlan card performs fragmentation in hardware/firmware,
783 * configure it here */
784
785 if (local->ops->set_frag_threshold)
786 return local->ops->set_frag_threshold(
787 local_to_hw(local),
788 local->fragmentation_threshold);
789
790 return 0; 641 return 0;
791} 642}
792 643
@@ -814,21 +665,16 @@ static int ieee80211_ioctl_siwretry(struct net_device *dev,
814 (retry->flags & IW_RETRY_TYPE) != IW_RETRY_LIMIT) 665 (retry->flags & IW_RETRY_TYPE) != IW_RETRY_LIMIT)
815 return -EINVAL; 666 return -EINVAL;
816 667
817 if (retry->flags & IW_RETRY_MAX) 668 if (retry->flags & IW_RETRY_MAX) {
818 local->long_retry_limit = retry->value; 669 local->hw.conf.long_frame_max_tx_count = retry->value;
819 else if (retry->flags & IW_RETRY_MIN) 670 } else if (retry->flags & IW_RETRY_MIN) {
820 local->short_retry_limit = retry->value; 671 local->hw.conf.short_frame_max_tx_count = retry->value;
821 else { 672 } else {
822 local->long_retry_limit = retry->value; 673 local->hw.conf.long_frame_max_tx_count = retry->value;
823 local->short_retry_limit = retry->value; 674 local->hw.conf.short_frame_max_tx_count = retry->value;
824 } 675 }
825 676
826 if (local->ops->set_retry_limit) { 677 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
827 return local->ops->set_retry_limit(
828 local_to_hw(local),
829 local->short_retry_limit,
830 local->long_retry_limit);
831 }
832 678
833 return 0; 679 return 0;
834} 680}
@@ -845,14 +691,15 @@ static int ieee80211_ioctl_giwretry(struct net_device *dev,
845 /* first return min value, iwconfig will ask max value 691 /* first return min value, iwconfig will ask max value
846 * later if needed */ 692 * later if needed */
847 retry->flags |= IW_RETRY_LIMIT; 693 retry->flags |= IW_RETRY_LIMIT;
848 retry->value = local->short_retry_limit; 694 retry->value = local->hw.conf.short_frame_max_tx_count;
849 if (local->long_retry_limit != local->short_retry_limit) 695 if (local->hw.conf.long_frame_max_tx_count !=
696 local->hw.conf.short_frame_max_tx_count)
850 retry->flags |= IW_RETRY_MIN; 697 retry->flags |= IW_RETRY_MIN;
851 return 0; 698 return 0;
852 } 699 }
853 if (retry->flags & IW_RETRY_MAX) { 700 if (retry->flags & IW_RETRY_MAX) {
854 retry->flags = IW_RETRY_LIMIT | IW_RETRY_MAX; 701 retry->flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
855 retry->value = local->long_retry_limit; 702 retry->value = local->hw.conf.long_frame_max_tx_count;
856 } 703 }
857 704
858 return 0; 705 return 0;
@@ -983,25 +830,56 @@ static int ieee80211_ioctl_siwpower(struct net_device *dev,
983 struct iw_param *wrq, 830 struct iw_param *wrq,
984 char *extra) 831 char *extra)
985{ 832{
833 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
986 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); 834 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
987 struct ieee80211_conf *conf = &local->hw.conf; 835 struct ieee80211_conf *conf = &local->hw.conf;
836 int ret = 0, timeout = 0;
837 bool ps;
838
839 if (sdata->vif.type != NL80211_IFTYPE_STATION)
840 return -EINVAL;
988 841
989 if (wrq->disabled) { 842 if (wrq->disabled) {
990 conf->flags &= ~IEEE80211_CONF_PS; 843 ps = false;
991 return ieee80211_hw_config(local); 844 timeout = 0;
845 goto set;
992 } 846 }
993 847
994 switch (wrq->flags & IW_POWER_MODE) { 848 switch (wrq->flags & IW_POWER_MODE) {
995 case IW_POWER_ON: /* If not specified */ 849 case IW_POWER_ON: /* If not specified */
996 case IW_POWER_MODE: /* If set all mask */ 850 case IW_POWER_MODE: /* If set all mask */
997 case IW_POWER_ALL_R: /* If explicitely state all */ 851 case IW_POWER_ALL_R: /* If explicitely state all */
998 conf->flags |= IEEE80211_CONF_PS; 852 ps = true;
999 break; 853 break;
1000 default: /* Otherwise we don't support it */ 854 default: /* Otherwise we ignore */
1001 return -EINVAL; 855 break;
856 }
857
858 if (wrq->flags & IW_POWER_TIMEOUT)
859 timeout = wrq->value / 1000;
860
861set:
862 if (ps == local->powersave && timeout == local->dynamic_ps_timeout)
863 return ret;
864
865 local->powersave = ps;
866 local->dynamic_ps_timeout = timeout;
867
868 if (sdata->u.sta.flags & IEEE80211_STA_ASSOCIATED) {
869 if (!(local->hw.flags & IEEE80211_HW_NO_STACK_DYNAMIC_PS) &&
870 local->dynamic_ps_timeout > 0)
871 mod_timer(&local->dynamic_ps_timer, jiffies +
872 msecs_to_jiffies(local->dynamic_ps_timeout));
873 else {
874 if (local->powersave)
875 conf->flags |= IEEE80211_CONF_PS;
876 else
877 conf->flags &= ~IEEE80211_CONF_PS;
878 }
879 ret = ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1002 } 880 }
1003 881
1004 return ieee80211_hw_config(local); 882 return ret;
1005} 883}
1006 884
1007static int ieee80211_ioctl_giwpower(struct net_device *dev, 885static int ieee80211_ioctl_giwpower(struct net_device *dev,
@@ -1010,9 +888,8 @@ static int ieee80211_ioctl_giwpower(struct net_device *dev,
1010 char *extra) 888 char *extra)
1011{ 889{
1012 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); 890 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1013 struct ieee80211_conf *conf = &local->hw.conf;
1014 891
1015 wrqu->power.disabled = !(conf->flags & IEEE80211_CONF_PS); 892 wrqu->power.disabled = !local->powersave;
1016 893
1017 return 0; 894 return 0;
1018} 895}
@@ -1176,13 +1053,13 @@ static int ieee80211_ioctl_siwencodeext(struct net_device *dev,
1176static const iw_handler ieee80211_handler[] = 1053static const iw_handler ieee80211_handler[] =
1177{ 1054{
1178 (iw_handler) NULL, /* SIOCSIWCOMMIT */ 1055 (iw_handler) NULL, /* SIOCSIWCOMMIT */
1179 (iw_handler) ieee80211_ioctl_giwname, /* SIOCGIWNAME */ 1056 (iw_handler) cfg80211_wext_giwname, /* SIOCGIWNAME */
1180 (iw_handler) NULL, /* SIOCSIWNWID */ 1057 (iw_handler) NULL, /* SIOCSIWNWID */
1181 (iw_handler) NULL, /* SIOCGIWNWID */ 1058 (iw_handler) NULL, /* SIOCGIWNWID */
1182 (iw_handler) ieee80211_ioctl_siwfreq, /* SIOCSIWFREQ */ 1059 (iw_handler) ieee80211_ioctl_siwfreq, /* SIOCSIWFREQ */
1183 (iw_handler) ieee80211_ioctl_giwfreq, /* SIOCGIWFREQ */ 1060 (iw_handler) ieee80211_ioctl_giwfreq, /* SIOCGIWFREQ */
1184 (iw_handler) ieee80211_ioctl_siwmode, /* SIOCSIWMODE */ 1061 (iw_handler) cfg80211_wext_siwmode, /* SIOCSIWMODE */
1185 (iw_handler) ieee80211_ioctl_giwmode, /* SIOCGIWMODE */ 1062 (iw_handler) cfg80211_wext_giwmode, /* SIOCGIWMODE */
1186 (iw_handler) NULL, /* SIOCSIWSENS */ 1063 (iw_handler) NULL, /* SIOCSIWSENS */
1187 (iw_handler) NULL, /* SIOCGIWSENS */ 1064 (iw_handler) NULL, /* SIOCGIWSENS */
1188 (iw_handler) NULL /* not used */, /* SIOCSIWRANGE */ 1065 (iw_handler) NULL /* not used */, /* SIOCSIWRANGE */
diff --git a/net/mac80211/wme.c b/net/mac80211/wme.c
index 139b5f267b34..ac71b38f7cb5 100644
--- a/net/mac80211/wme.c
+++ b/net/mac80211/wme.c
@@ -114,8 +114,8 @@ u16 ieee80211_select_queue(struct net_device *dev, struct sk_buff *skb)
114{ 114{
115 struct ieee80211_master_priv *mpriv = netdev_priv(dev); 115 struct ieee80211_master_priv *mpriv = netdev_priv(dev);
116 struct ieee80211_local *local = mpriv->local; 116 struct ieee80211_local *local = mpriv->local;
117 struct ieee80211_hw *hw = &local->hw;
117 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; 118 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
118 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
119 struct sta_info *sta; 119 struct sta_info *sta;
120 u16 queue; 120 u16 queue;
121 u8 tid; 121 u8 tid;
@@ -124,21 +124,19 @@ u16 ieee80211_select_queue(struct net_device *dev, struct sk_buff *skb)
124 if (unlikely(queue >= local->hw.queues)) 124 if (unlikely(queue >= local->hw.queues))
125 queue = local->hw.queues - 1; 125 queue = local->hw.queues - 1;
126 126
127 if (info->flags & IEEE80211_TX_CTL_REQUEUE) { 127 if (skb->requeue) {
128 if (!hw->ampdu_queues)
129 return queue;
130
128 rcu_read_lock(); 131 rcu_read_lock();
129 sta = sta_info_get(local, hdr->addr1); 132 sta = sta_info_get(local, hdr->addr1);
130 tid = skb->priority & IEEE80211_QOS_CTL_TAG1D_MASK; 133 tid = skb->priority & IEEE80211_QOS_CTL_TAG1D_MASK;
131 if (sta) { 134 if (sta) {
132 struct ieee80211_hw *hw = &local->hw;
133 int ampdu_queue = sta->tid_to_tx_q[tid]; 135 int ampdu_queue = sta->tid_to_tx_q[tid];
134 136
135 if ((ampdu_queue < ieee80211_num_queues(hw)) && 137 if ((ampdu_queue < ieee80211_num_queues(hw)) &&
136 test_bit(ampdu_queue, local->queue_pool)) { 138 test_bit(ampdu_queue, local->queue_pool))
137 queue = ampdu_queue; 139 queue = ampdu_queue;
138 info->flags |= IEEE80211_TX_CTL_AMPDU;
139 } else {
140 info->flags &= ~IEEE80211_TX_CTL_AMPDU;
141 }
142 } 140 }
143 rcu_read_unlock(); 141 rcu_read_unlock();
144 142
@@ -159,20 +157,18 @@ u16 ieee80211_select_queue(struct net_device *dev, struct sk_buff *skb)
159 *p++ = ack_policy | tid; 157 *p++ = ack_policy | tid;
160 *p = 0; 158 *p = 0;
161 159
160 if (!hw->ampdu_queues)
161 return queue;
162
162 rcu_read_lock(); 163 rcu_read_lock();
163 164
164 sta = sta_info_get(local, hdr->addr1); 165 sta = sta_info_get(local, hdr->addr1);
165 if (sta) { 166 if (sta) {
166 int ampdu_queue = sta->tid_to_tx_q[tid]; 167 int ampdu_queue = sta->tid_to_tx_q[tid];
167 struct ieee80211_hw *hw = &local->hw;
168 168
169 if ((ampdu_queue < ieee80211_num_queues(hw)) && 169 if ((ampdu_queue < ieee80211_num_queues(hw)) &&
170 test_bit(ampdu_queue, local->queue_pool)) { 170 test_bit(ampdu_queue, local->queue_pool))
171 queue = ampdu_queue; 171 queue = ampdu_queue;
172 info->flags |= IEEE80211_TX_CTL_AMPDU;
173 } else {
174 info->flags &= ~IEEE80211_TX_CTL_AMPDU;
175 }
176 } 172 }
177 173
178 rcu_read_unlock(); 174 rcu_read_unlock();
@@ -206,13 +202,11 @@ int ieee80211_ht_agg_queue_add(struct ieee80211_local *local,
206 * on the previous queue 202 * on the previous queue
207 * since HT is strict in order */ 203 * since HT is strict in order */
208#ifdef CONFIG_MAC80211_HT_DEBUG 204#ifdef CONFIG_MAC80211_HT_DEBUG
209 if (net_ratelimit()) { 205 if (net_ratelimit())
210 DECLARE_MAC_BUF(mac);
211 printk(KERN_DEBUG "allocated aggregation queue" 206 printk(KERN_DEBUG "allocated aggregation queue"
212 " %d tid %d addr %s pool=0x%lX\n", 207 " %d tid %d addr %pM pool=0x%lX\n",
213 i, tid, print_mac(mac, sta->sta.addr), 208 i, tid, sta->sta.addr,
214 local->queue_pool[0]); 209 local->queue_pool[0]);
215 }
216#endif /* CONFIG_MAC80211_HT_DEBUG */ 210#endif /* CONFIG_MAC80211_HT_DEBUG */
217 return 0; 211 return 0;
218 } 212 }
diff --git a/net/mac80211/wpa.c b/net/mac80211/wpa.c
index 6db649480e8f..7aa63caf8d50 100644
--- a/net/mac80211/wpa.c
+++ b/net/mac80211/wpa.c
@@ -49,8 +49,7 @@ ieee80211_tx_h_michael_mic_add(struct ieee80211_tx_data *tx)
49 !(tx->flags & IEEE80211_TX_FRAGMENTED) && 49 !(tx->flags & IEEE80211_TX_FRAGMENTED) &&
50 !(tx->key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_MMIC) && 50 !(tx->key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_MMIC) &&
51 !wpa_test) { 51 !wpa_test) {
52 /* hwaccel - with no need for preallocated room for Michael MIC 52 /* hwaccel - with no need for preallocated room for MMIC */
53 */
54 return TX_CONTINUE; 53 return TX_CONTINUE;
55 } 54 }
56 55
@@ -67,8 +66,6 @@ ieee80211_tx_h_michael_mic_add(struct ieee80211_tx_data *tx)
67#else 66#else
68 authenticator = 1; 67 authenticator = 1;
69#endif 68#endif
70 /* At this point we know we're using ALG_TKIP. To get the MIC key
71 * we now will rely on the offset from the ieee80211_key_conf::key */
72 key_offset = authenticator ? 69 key_offset = authenticator ?
73 NL80211_TKIP_DATA_OFFSET_TX_MIC_KEY : 70 NL80211_TKIP_DATA_OFFSET_TX_MIC_KEY :
74 NL80211_TKIP_DATA_OFFSET_RX_MIC_KEY; 71 NL80211_TKIP_DATA_OFFSET_RX_MIC_KEY;
@@ -90,11 +87,8 @@ ieee80211_rx_h_michael_mic_verify(struct ieee80211_rx_data *rx)
90 u8 mic[MICHAEL_MIC_LEN]; 87 u8 mic[MICHAEL_MIC_LEN];
91 struct sk_buff *skb = rx->skb; 88 struct sk_buff *skb = rx->skb;
92 int authenticator = 1, wpa_test = 0; 89 int authenticator = 1, wpa_test = 0;
93 DECLARE_MAC_BUF(mac);
94 90
95 /* 91 /* No way to verify the MIC if the hardware stripped it */
96 * No way to verify the MIC if the hardware stripped it
97 */
98 if (rx->status->flag & RX_FLAG_MMIC_STRIPPED) 92 if (rx->status->flag & RX_FLAG_MMIC_STRIPPED)
99 return RX_CONTINUE; 93 return RX_CONTINUE;
100 94
@@ -116,8 +110,6 @@ ieee80211_rx_h_michael_mic_verify(struct ieee80211_rx_data *rx)
116#else 110#else
117 authenticator = 1; 111 authenticator = 1;
118#endif 112#endif
119 /* At this point we know we're using ALG_TKIP. To get the MIC key
120 * we now will rely on the offset from the ieee80211_key_conf::key */
121 key_offset = authenticator ? 113 key_offset = authenticator ?
122 NL80211_TKIP_DATA_OFFSET_RX_MIC_KEY : 114 NL80211_TKIP_DATA_OFFSET_RX_MIC_KEY :
123 NL80211_TKIP_DATA_OFFSET_TX_MIC_KEY; 115 NL80211_TKIP_DATA_OFFSET_TX_MIC_KEY;
@@ -202,6 +194,7 @@ ieee80211_tx_result
202ieee80211_crypto_tkip_encrypt(struct ieee80211_tx_data *tx) 194ieee80211_crypto_tkip_encrypt(struct ieee80211_tx_data *tx)
203{ 195{
204 struct sk_buff *skb = tx->skb; 196 struct sk_buff *skb = tx->skb;
197 int i;
205 198
206 ieee80211_tx_set_protected(tx); 199 ieee80211_tx_set_protected(tx);
207 200
@@ -209,9 +202,8 @@ ieee80211_crypto_tkip_encrypt(struct ieee80211_tx_data *tx)
209 return TX_DROP; 202 return TX_DROP;
210 203
211 if (tx->extra_frag) { 204 if (tx->extra_frag) {
212 int i;
213 for (i = 0; i < tx->num_extra_frag; i++) { 205 for (i = 0; i < tx->num_extra_frag; i++) {
214 if (tkip_encrypt_skb(tx, tx->extra_frag[i]) < 0) 206 if (tkip_encrypt_skb(tx, tx->extra_frag[i]))
215 return TX_DROP; 207 return TX_DROP;
216 } 208 }
217 } 209 }
@@ -227,7 +219,6 @@ ieee80211_crypto_tkip_decrypt(struct ieee80211_rx_data *rx)
227 int hdrlen, res, hwaccel = 0, wpa_test = 0; 219 int hdrlen, res, hwaccel = 0, wpa_test = 0;
228 struct ieee80211_key *key = rx->key; 220 struct ieee80211_key *key = rx->key;
229 struct sk_buff *skb = rx->skb; 221 struct sk_buff *skb = rx->skb;
230 DECLARE_MAC_BUF(mac);
231 222
232 hdrlen = ieee80211_hdrlen(hdr->frame_control); 223 hdrlen = ieee80211_hdrlen(hdr->frame_control);
233 224
@@ -350,7 +341,7 @@ static inline void ccmp_pn2hdr(u8 *hdr, u8 *pn, int key_id)
350} 341}
351 342
352 343
353static inline int ccmp_hdr2pn(u8 *pn, u8 *hdr) 344static inline void ccmp_hdr2pn(u8 *pn, u8 *hdr)
354{ 345{
355 pn[0] = hdr[7]; 346 pn[0] = hdr[7];
356 pn[1] = hdr[6]; 347 pn[1] = hdr[6];
@@ -358,7 +349,6 @@ static inline int ccmp_hdr2pn(u8 *pn, u8 *hdr)
358 pn[3] = hdr[4]; 349 pn[3] = hdr[4];
359 pn[4] = hdr[1]; 350 pn[4] = hdr[1];
360 pn[5] = hdr[0]; 351 pn[5] = hdr[0];
361 return (hdr[3] >> 6) & 0x03;
362} 352}
363 353
364 354
@@ -373,7 +363,7 @@ static int ccmp_encrypt_skb(struct ieee80211_tx_data *tx, struct sk_buff *skb)
373 363
374 if ((tx->key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE) && 364 if ((tx->key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE) &&
375 !(tx->key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV)) { 365 !(tx->key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV)) {
376 /* hwaccel - with no need for preallocated room for CCMP " 366 /* hwaccel - with no need for preallocated room for CCMP
377 * header or MIC fields */ 367 * header or MIC fields */
378 info->control.hw_key = &tx->key->conf; 368 info->control.hw_key = &tx->key->conf;
379 return 0; 369 return 0;
@@ -426,6 +416,7 @@ ieee80211_tx_result
426ieee80211_crypto_ccmp_encrypt(struct ieee80211_tx_data *tx) 416ieee80211_crypto_ccmp_encrypt(struct ieee80211_tx_data *tx)
427{ 417{
428 struct sk_buff *skb = tx->skb; 418 struct sk_buff *skb = tx->skb;
419 int i;
429 420
430 ieee80211_tx_set_protected(tx); 421 ieee80211_tx_set_protected(tx);
431 422
@@ -433,9 +424,8 @@ ieee80211_crypto_ccmp_encrypt(struct ieee80211_tx_data *tx)
433 return TX_DROP; 424 return TX_DROP;
434 425
435 if (tx->extra_frag) { 426 if (tx->extra_frag) {
436 int i;
437 for (i = 0; i < tx->num_extra_frag; i++) { 427 for (i = 0; i < tx->num_extra_frag; i++) {
438 if (ccmp_encrypt_skb(tx, tx->extra_frag[i]) < 0) 428 if (ccmp_encrypt_skb(tx, tx->extra_frag[i]))
439 return TX_DROP; 429 return TX_DROP;
440 } 430 }
441 } 431 }
@@ -453,7 +443,6 @@ ieee80211_crypto_ccmp_decrypt(struct ieee80211_rx_data *rx)
453 struct sk_buff *skb = rx->skb; 443 struct sk_buff *skb = rx->skb;
454 u8 pn[CCMP_PN_LEN]; 444 u8 pn[CCMP_PN_LEN];
455 int data_len; 445 int data_len;
456 DECLARE_MAC_BUF(mac);
457 446
458 hdrlen = ieee80211_hdrlen(hdr->frame_control); 447 hdrlen = ieee80211_hdrlen(hdr->frame_control);
459 448
@@ -468,7 +457,7 @@ ieee80211_crypto_ccmp_decrypt(struct ieee80211_rx_data *rx)
468 (rx->status->flag & RX_FLAG_IV_STRIPPED)) 457 (rx->status->flag & RX_FLAG_IV_STRIPPED))
469 return RX_CONTINUE; 458 return RX_CONTINUE;
470 459
471 (void) ccmp_hdr2pn(pn, skb->data + hdrlen); 460 ccmp_hdr2pn(pn, skb->data + hdrlen);
472 461
473 if (memcmp(pn, key->u.ccmp.rx_pn[rx->queue], CCMP_PN_LEN) <= 0) { 462 if (memcmp(pn, key->u.ccmp.rx_pn[rx->queue], CCMP_PN_LEN) <= 0) {
474 key->u.ccmp.replays++; 463 key->u.ccmp.replays++;
@@ -483,9 +472,8 @@ ieee80211_crypto_ccmp_decrypt(struct ieee80211_rx_data *rx)
483 key->u.ccmp.tfm, key->u.ccmp.rx_crypto_buf, 472 key->u.ccmp.tfm, key->u.ccmp.rx_crypto_buf,
484 skb->data + hdrlen + CCMP_HDR_LEN, data_len, 473 skb->data + hdrlen + CCMP_HDR_LEN, data_len,
485 skb->data + skb->len - CCMP_MIC_LEN, 474 skb->data + skb->len - CCMP_MIC_LEN,
486 skb->data + hdrlen + CCMP_HDR_LEN)) { 475 skb->data + hdrlen + CCMP_HDR_LEN))
487 return RX_DROP_UNUSABLE; 476 return RX_DROP_UNUSABLE;
488 }
489 } 477 }
490 478
491 memcpy(key->u.ccmp.rx_pn[rx->queue], pn, CCMP_PN_LEN); 479 memcpy(key->u.ccmp.rx_pn[rx->queue], pn, CCMP_PN_LEN);
diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
index 25dcef9f2194..c2bac9cd0caf 100644
--- a/net/netfilter/Kconfig
+++ b/net/netfilter/Kconfig
@@ -373,11 +373,10 @@ config NETFILTER_XT_TARGET_MARK
373config NETFILTER_XT_TARGET_NFLOG 373config NETFILTER_XT_TARGET_NFLOG
374 tristate '"NFLOG" target support' 374 tristate '"NFLOG" target support'
375 default m if NETFILTER_ADVANCED=n 375 default m if NETFILTER_ADVANCED=n
376 select NETFILTER_NETLINK_LOG
376 help 377 help
377 This option enables the NFLOG target, which allows to LOG 378 This option enables the NFLOG target, which allows to LOG
378 messages through the netfilter logging API, which can use 379 messages through nfnetlink_log.
379 either the old LOG target, the old ULOG target or nfnetlink_log
380 as backend.
381 380
382 To compile it as a module, choose M here. If unsure, say N. 381 To compile it as a module, choose M here. If unsure, say N.
383 382
diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
index 9a24332fbed8..60aba45023ff 100644
--- a/net/netfilter/ipvs/ip_vs_conn.c
+++ b/net/netfilter/ipvs/ip_vs_conn.c
@@ -820,13 +820,11 @@ static int ip_vs_conn_seq_show(struct seq_file *seq, void *v)
820 820
821#ifdef CONFIG_IP_VS_IPV6 821#ifdef CONFIG_IP_VS_IPV6
822 if (cp->af == AF_INET6) 822 if (cp->af == AF_INET6)
823 seq_printf(seq, 823 seq_printf(seq, "%-3s %pI6 %04X %pI6 %04X %pI6 %04X %-11s %7lu\n",
824 "%-3s " NIP6_FMT " %04X " NIP6_FMT
825 " %04X " NIP6_FMT " %04X %-11s %7lu\n",
826 ip_vs_proto_name(cp->protocol), 824 ip_vs_proto_name(cp->protocol),
827 NIP6(cp->caddr.in6), ntohs(cp->cport), 825 &cp->caddr.in6, ntohs(cp->cport),
828 NIP6(cp->vaddr.in6), ntohs(cp->vport), 826 &cp->vaddr.in6, ntohs(cp->vport),
829 NIP6(cp->daddr.in6), ntohs(cp->dport), 827 &cp->daddr.in6, ntohs(cp->dport),
830 ip_vs_state_name(cp->protocol, cp->state), 828 ip_vs_state_name(cp->protocol, cp->state),
831 (cp->timer.expires-jiffies)/HZ); 829 (cp->timer.expires-jiffies)/HZ);
832 else 830 else
@@ -883,13 +881,11 @@ static int ip_vs_conn_sync_seq_show(struct seq_file *seq, void *v)
883 881
884#ifdef CONFIG_IP_VS_IPV6 882#ifdef CONFIG_IP_VS_IPV6
885 if (cp->af == AF_INET6) 883 if (cp->af == AF_INET6)
886 seq_printf(seq, 884 seq_printf(seq, "%-3s %pI6 %04X %pI6 %04X %pI6 %04X %-11s %-6s %7lu\n",
887 "%-3s " NIP6_FMT " %04X " NIP6_FMT
888 " %04X " NIP6_FMT " %04X %-11s %-6s %7lu\n",
889 ip_vs_proto_name(cp->protocol), 885 ip_vs_proto_name(cp->protocol),
890 NIP6(cp->caddr.in6), ntohs(cp->cport), 886 &cp->caddr.in6, ntohs(cp->cport),
891 NIP6(cp->vaddr.in6), ntohs(cp->vport), 887 &cp->vaddr.in6, ntohs(cp->vport),
892 NIP6(cp->daddr.in6), ntohs(cp->dport), 888 &cp->daddr.in6, ntohs(cp->dport),
893 ip_vs_state_name(cp->protocol, cp->state), 889 ip_vs_state_name(cp->protocol, cp->state),
894 ip_vs_origin_name(cp->flags), 890 ip_vs_origin_name(cp->flags),
895 (cp->timer.expires-jiffies)/HZ); 891 (cp->timer.expires-jiffies)/HZ);
diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
index 958abf3e5f8c..cb3e031335eb 100644
--- a/net/netfilter/ipvs/ip_vs_core.c
+++ b/net/netfilter/ipvs/ip_vs_core.c
@@ -730,9 +730,9 @@ static int ip_vs_out_icmp(struct sk_buff *skb, int *related)
730 if (ic == NULL) 730 if (ic == NULL)
731 return NF_DROP; 731 return NF_DROP;
732 732
733 IP_VS_DBG(12, "Outgoing ICMP (%d,%d) %u.%u.%u.%u->%u.%u.%u.%u\n", 733 IP_VS_DBG(12, "Outgoing ICMP (%d,%d) %pI4->%pI4\n",
734 ic->type, ntohs(icmp_id(ic)), 734 ic->type, ntohs(icmp_id(ic)),
735 NIPQUAD(iph->saddr), NIPQUAD(iph->daddr)); 735 &iph->saddr, &iph->daddr);
736 736
737 /* 737 /*
738 * Work through seeing if this is for us. 738 * Work through seeing if this is for us.
@@ -805,9 +805,9 @@ static int ip_vs_out_icmp_v6(struct sk_buff *skb, int *related)
805 if (ic == NULL) 805 if (ic == NULL)
806 return NF_DROP; 806 return NF_DROP;
807 807
808 IP_VS_DBG(12, "Outgoing ICMPv6 (%d,%d) " NIP6_FMT "->" NIP6_FMT "\n", 808 IP_VS_DBG(12, "Outgoing ICMPv6 (%d,%d) %pI6->%pI6\n",
809 ic->icmp6_type, ntohs(icmpv6_id(ic)), 809 ic->icmp6_type, ntohs(icmpv6_id(ic)),
810 NIP6(iph->saddr), NIP6(iph->daddr)); 810 &iph->saddr, &iph->daddr);
811 811
812 /* 812 /*
813 * Work through seeing if this is for us. 813 * Work through seeing if this is for us.
@@ -1070,9 +1070,9 @@ ip_vs_in_icmp(struct sk_buff *skb, int *related, unsigned int hooknum)
1070 if (ic == NULL) 1070 if (ic == NULL)
1071 return NF_DROP; 1071 return NF_DROP;
1072 1072
1073 IP_VS_DBG(12, "Incoming ICMP (%d,%d) %u.%u.%u.%u->%u.%u.%u.%u\n", 1073 IP_VS_DBG(12, "Incoming ICMP (%d,%d) %pI4->%pI4\n",
1074 ic->type, ntohs(icmp_id(ic)), 1074 ic->type, ntohs(icmp_id(ic)),
1075 NIPQUAD(iph->saddr), NIPQUAD(iph->daddr)); 1075 &iph->saddr, &iph->daddr);
1076 1076
1077 /* 1077 /*
1078 * Work through seeing if this is for us. 1078 * Work through seeing if this is for us.
@@ -1127,8 +1127,8 @@ ip_vs_in_icmp(struct sk_buff *skb, int *related, unsigned int hooknum)
1127 /* Ensure the checksum is correct */ 1127 /* Ensure the checksum is correct */
1128 if (!skb_csum_unnecessary(skb) && ip_vs_checksum_complete(skb, ihl)) { 1128 if (!skb_csum_unnecessary(skb) && ip_vs_checksum_complete(skb, ihl)) {
1129 /* Failed checksum! */ 1129 /* Failed checksum! */
1130 IP_VS_DBG(1, "Incoming ICMP: failed checksum from %d.%d.%d.%d!\n", 1130 IP_VS_DBG(1, "Incoming ICMP: failed checksum from %pI4!\n",
1131 NIPQUAD(iph->saddr)); 1131 &iph->saddr);
1132 goto out; 1132 goto out;
1133 } 1133 }
1134 1134
@@ -1175,9 +1175,9 @@ ip_vs_in_icmp_v6(struct sk_buff *skb, int *related, unsigned int hooknum)
1175 if (ic == NULL) 1175 if (ic == NULL)
1176 return NF_DROP; 1176 return NF_DROP;
1177 1177
1178 IP_VS_DBG(12, "Incoming ICMPv6 (%d,%d) " NIP6_FMT "->" NIP6_FMT "\n", 1178 IP_VS_DBG(12, "Incoming ICMPv6 (%d,%d) %pI6->%pI6\n",
1179 ic->icmp6_type, ntohs(icmpv6_id(ic)), 1179 ic->icmp6_type, ntohs(icmpv6_id(ic)),
1180 NIP6(iph->saddr), NIP6(iph->daddr)); 1180 &iph->saddr, &iph->daddr);
1181 1181
1182 /* 1182 /*
1183 * Work through seeing if this is for us. 1183 * Work through seeing if this is for us.
diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
index 0302cf3e5039..e01061f49cdc 100644
--- a/net/netfilter/ipvs/ip_vs_ctl.c
+++ b/net/netfilter/ipvs/ip_vs_ctl.c
@@ -1168,15 +1168,9 @@ ip_vs_add_service(struct ip_vs_service_user_kern *u,
1168 } 1168 }
1169 1169
1170#ifdef CONFIG_IP_VS_IPV6 1170#ifdef CONFIG_IP_VS_IPV6
1171 if (u->af == AF_INET6) { 1171 if (u->af == AF_INET6 && (u->netmask < 1 || u->netmask > 128)) {
1172 if (!sched->supports_ipv6) { 1172 ret = -EINVAL;
1173 ret = -EAFNOSUPPORT; 1173 goto out_err;
1174 goto out_err;
1175 }
1176 if ((u->netmask < 1) || (u->netmask > 128)) {
1177 ret = -EINVAL;
1178 goto out_err;
1179 }
1180 } 1174 }
1181#endif 1175#endif
1182 1176
@@ -1272,15 +1266,9 @@ ip_vs_edit_service(struct ip_vs_service *svc, struct ip_vs_service_user_kern *u)
1272 old_sched = sched; 1266 old_sched = sched;
1273 1267
1274#ifdef CONFIG_IP_VS_IPV6 1268#ifdef CONFIG_IP_VS_IPV6
1275 if (u->af == AF_INET6) { 1269 if (u->af == AF_INET6 && (u->netmask < 1 || u->netmask > 128)) {
1276 if (!sched->supports_ipv6) { 1270 ret = -EINVAL;
1277 ret = -EAFNOSUPPORT; 1271 goto out;
1278 goto out;
1279 }
1280 if ((u->netmask < 1) || (u->netmask > 128)) {
1281 ret = -EINVAL;
1282 goto out;
1283 }
1284 } 1272 }
1285#endif 1273#endif
1286 1274
@@ -1557,7 +1545,7 @@ static struct ctl_table vs_vars[] = {
1557 .data = &sysctl_ip_vs_amemthresh, 1545 .data = &sysctl_ip_vs_amemthresh,
1558 .maxlen = sizeof(int), 1546 .maxlen = sizeof(int),
1559 .mode = 0644, 1547 .mode = 0644,
1560 .proc_handler = &proc_dointvec, 1548 .proc_handler = proc_dointvec,
1561 }, 1549 },
1562#ifdef CONFIG_IP_VS_DEBUG 1550#ifdef CONFIG_IP_VS_DEBUG
1563 { 1551 {
@@ -1565,7 +1553,7 @@ static struct ctl_table vs_vars[] = {
1565 .data = &sysctl_ip_vs_debug_level, 1553 .data = &sysctl_ip_vs_debug_level,
1566 .maxlen = sizeof(int), 1554 .maxlen = sizeof(int),
1567 .mode = 0644, 1555 .mode = 0644,
1568 .proc_handler = &proc_dointvec, 1556 .proc_handler = proc_dointvec,
1569 }, 1557 },
1570#endif 1558#endif
1571 { 1559 {
@@ -1573,28 +1561,28 @@ static struct ctl_table vs_vars[] = {
1573 .data = &sysctl_ip_vs_am_droprate, 1561 .data = &sysctl_ip_vs_am_droprate,
1574 .maxlen = sizeof(int), 1562 .maxlen = sizeof(int),
1575 .mode = 0644, 1563 .mode = 0644,
1576 .proc_handler = &proc_dointvec, 1564 .proc_handler = proc_dointvec,
1577 }, 1565 },
1578 { 1566 {
1579 .procname = "drop_entry", 1567 .procname = "drop_entry",
1580 .data = &sysctl_ip_vs_drop_entry, 1568 .data = &sysctl_ip_vs_drop_entry,
1581 .maxlen = sizeof(int), 1569 .maxlen = sizeof(int),
1582 .mode = 0644, 1570 .mode = 0644,
1583 .proc_handler = &proc_do_defense_mode, 1571 .proc_handler = proc_do_defense_mode,
1584 }, 1572 },
1585 { 1573 {
1586 .procname = "drop_packet", 1574 .procname = "drop_packet",
1587 .data = &sysctl_ip_vs_drop_packet, 1575 .data = &sysctl_ip_vs_drop_packet,
1588 .maxlen = sizeof(int), 1576 .maxlen = sizeof(int),
1589 .mode = 0644, 1577 .mode = 0644,
1590 .proc_handler = &proc_do_defense_mode, 1578 .proc_handler = proc_do_defense_mode,
1591 }, 1579 },
1592 { 1580 {
1593 .procname = "secure_tcp", 1581 .procname = "secure_tcp",
1594 .data = &sysctl_ip_vs_secure_tcp, 1582 .data = &sysctl_ip_vs_secure_tcp,
1595 .maxlen = sizeof(int), 1583 .maxlen = sizeof(int),
1596 .mode = 0644, 1584 .mode = 0644,
1597 .proc_handler = &proc_do_defense_mode, 1585 .proc_handler = proc_do_defense_mode,
1598 }, 1586 },
1599#if 0 1587#if 0
1600 { 1588 {
@@ -1602,84 +1590,84 @@ static struct ctl_table vs_vars[] = {
1602 .data = &vs_timeout_table_dos.timeout[IP_VS_S_ESTABLISHED], 1590 .data = &vs_timeout_table_dos.timeout[IP_VS_S_ESTABLISHED],
1603 .maxlen = sizeof(int), 1591 .maxlen = sizeof(int),
1604 .mode = 0644, 1592 .mode = 0644,
1605 .proc_handler = &proc_dointvec_jiffies, 1593 .proc_handler = proc_dointvec_jiffies,
1606 }, 1594 },
1607 { 1595 {
1608 .procname = "timeout_synsent", 1596 .procname = "timeout_synsent",
1609 .data = &vs_timeout_table_dos.timeout[IP_VS_S_SYN_SENT], 1597 .data = &vs_timeout_table_dos.timeout[IP_VS_S_SYN_SENT],
1610 .maxlen = sizeof(int), 1598 .maxlen = sizeof(int),
1611 .mode = 0644, 1599 .mode = 0644,
1612 .proc_handler = &proc_dointvec_jiffies, 1600 .proc_handler = proc_dointvec_jiffies,
1613 }, 1601 },
1614 { 1602 {
1615 .procname = "timeout_synrecv", 1603 .procname = "timeout_synrecv",
1616 .data = &vs_timeout_table_dos.timeout[IP_VS_S_SYN_RECV], 1604 .data = &vs_timeout_table_dos.timeout[IP_VS_S_SYN_RECV],
1617 .maxlen = sizeof(int), 1605 .maxlen = sizeof(int),
1618 .mode = 0644, 1606 .mode = 0644,
1619 .proc_handler = &proc_dointvec_jiffies, 1607 .proc_handler = proc_dointvec_jiffies,
1620 }, 1608 },
1621 { 1609 {
1622 .procname = "timeout_finwait", 1610 .procname = "timeout_finwait",
1623 .data = &vs_timeout_table_dos.timeout[IP_VS_S_FIN_WAIT], 1611 .data = &vs_timeout_table_dos.timeout[IP_VS_S_FIN_WAIT],
1624 .maxlen = sizeof(int), 1612 .maxlen = sizeof(int),
1625 .mode = 0644, 1613 .mode = 0644,
1626 .proc_handler = &proc_dointvec_jiffies, 1614 .proc_handler = proc_dointvec_jiffies,
1627 }, 1615 },
1628 { 1616 {
1629 .procname = "timeout_timewait", 1617 .procname = "timeout_timewait",
1630 .data = &vs_timeout_table_dos.timeout[IP_VS_S_TIME_WAIT], 1618 .data = &vs_timeout_table_dos.timeout[IP_VS_S_TIME_WAIT],
1631 .maxlen = sizeof(int), 1619 .maxlen = sizeof(int),
1632 .mode = 0644, 1620 .mode = 0644,
1633 .proc_handler = &proc_dointvec_jiffies, 1621 .proc_handler = proc_dointvec_jiffies,
1634 }, 1622 },
1635 { 1623 {
1636 .procname = "timeout_close", 1624 .procname = "timeout_close",
1637 .data = &vs_timeout_table_dos.timeout[IP_VS_S_CLOSE], 1625 .data = &vs_timeout_table_dos.timeout[IP_VS_S_CLOSE],
1638 .maxlen = sizeof(int), 1626 .maxlen = sizeof(int),
1639 .mode = 0644, 1627 .mode = 0644,
1640 .proc_handler = &proc_dointvec_jiffies, 1628 .proc_handler = proc_dointvec_jiffies,
1641 }, 1629 },
1642 { 1630 {
1643 .procname = "timeout_closewait", 1631 .procname = "timeout_closewait",
1644 .data = &vs_timeout_table_dos.timeout[IP_VS_S_CLOSE_WAIT], 1632 .data = &vs_timeout_table_dos.timeout[IP_VS_S_CLOSE_WAIT],
1645 .maxlen = sizeof(int), 1633 .maxlen = sizeof(int),
1646 .mode = 0644, 1634 .mode = 0644,
1647 .proc_handler = &proc_dointvec_jiffies, 1635 .proc_handler = proc_dointvec_jiffies,
1648 }, 1636 },
1649 { 1637 {
1650 .procname = "timeout_lastack", 1638 .procname = "timeout_lastack",
1651 .data = &vs_timeout_table_dos.timeout[IP_VS_S_LAST_ACK], 1639 .data = &vs_timeout_table_dos.timeout[IP_VS_S_LAST_ACK],
1652 .maxlen = sizeof(int), 1640 .maxlen = sizeof(int),
1653 .mode = 0644, 1641 .mode = 0644,
1654 .proc_handler = &proc_dointvec_jiffies, 1642 .proc_handler = proc_dointvec_jiffies,
1655 }, 1643 },
1656 { 1644 {
1657 .procname = "timeout_listen", 1645 .procname = "timeout_listen",
1658 .data = &vs_timeout_table_dos.timeout[IP_VS_S_LISTEN], 1646 .data = &vs_timeout_table_dos.timeout[IP_VS_S_LISTEN],
1659 .maxlen = sizeof(int), 1647 .maxlen = sizeof(int),
1660 .mode = 0644, 1648 .mode = 0644,
1661 .proc_handler = &proc_dointvec_jiffies, 1649 .proc_handler = proc_dointvec_jiffies,
1662 }, 1650 },
1663 { 1651 {
1664 .procname = "timeout_synack", 1652 .procname = "timeout_synack",
1665 .data = &vs_timeout_table_dos.timeout[IP_VS_S_SYNACK], 1653 .data = &vs_timeout_table_dos.timeout[IP_VS_S_SYNACK],
1666 .maxlen = sizeof(int), 1654 .maxlen = sizeof(int),
1667 .mode = 0644, 1655 .mode = 0644,
1668 .proc_handler = &proc_dointvec_jiffies, 1656 .proc_handler = proc_dointvec_jiffies,
1669 }, 1657 },
1670 { 1658 {
1671 .procname = "timeout_udp", 1659 .procname = "timeout_udp",
1672 .data = &vs_timeout_table_dos.timeout[IP_VS_S_UDP], 1660 .data = &vs_timeout_table_dos.timeout[IP_VS_S_UDP],
1673 .maxlen = sizeof(int), 1661 .maxlen = sizeof(int),
1674 .mode = 0644, 1662 .mode = 0644,
1675 .proc_handler = &proc_dointvec_jiffies, 1663 .proc_handler = proc_dointvec_jiffies,
1676 }, 1664 },
1677 { 1665 {
1678 .procname = "timeout_icmp", 1666 .procname = "timeout_icmp",
1679 .data = &vs_timeout_table_dos.timeout[IP_VS_S_ICMP], 1667 .data = &vs_timeout_table_dos.timeout[IP_VS_S_ICMP],
1680 .maxlen = sizeof(int), 1668 .maxlen = sizeof(int),
1681 .mode = 0644, 1669 .mode = 0644,
1682 .proc_handler = &proc_dointvec_jiffies, 1670 .proc_handler = proc_dointvec_jiffies,
1683 }, 1671 },
1684#endif 1672#endif
1685 { 1673 {
@@ -1687,35 +1675,35 @@ static struct ctl_table vs_vars[] = {
1687 .data = &sysctl_ip_vs_cache_bypass, 1675 .data = &sysctl_ip_vs_cache_bypass,
1688 .maxlen = sizeof(int), 1676 .maxlen = sizeof(int),
1689 .mode = 0644, 1677 .mode = 0644,
1690 .proc_handler = &proc_dointvec, 1678 .proc_handler = proc_dointvec,
1691 }, 1679 },
1692 { 1680 {
1693 .procname = "expire_nodest_conn", 1681 .procname = "expire_nodest_conn",
1694 .data = &sysctl_ip_vs_expire_nodest_conn, 1682 .data = &sysctl_ip_vs_expire_nodest_conn,
1695 .maxlen = sizeof(int), 1683 .maxlen = sizeof(int),
1696 .mode = 0644, 1684 .mode = 0644,
1697 .proc_handler = &proc_dointvec, 1685 .proc_handler = proc_dointvec,
1698 }, 1686 },
1699 { 1687 {
1700 .procname = "expire_quiescent_template", 1688 .procname = "expire_quiescent_template",
1701 .data = &sysctl_ip_vs_expire_quiescent_template, 1689 .data = &sysctl_ip_vs_expire_quiescent_template,
1702 .maxlen = sizeof(int), 1690 .maxlen = sizeof(int),
1703 .mode = 0644, 1691 .mode = 0644,
1704 .proc_handler = &proc_dointvec, 1692 .proc_handler = proc_dointvec,
1705 }, 1693 },
1706 { 1694 {
1707 .procname = "sync_threshold", 1695 .procname = "sync_threshold",
1708 .data = &sysctl_ip_vs_sync_threshold, 1696 .data = &sysctl_ip_vs_sync_threshold,
1709 .maxlen = sizeof(sysctl_ip_vs_sync_threshold), 1697 .maxlen = sizeof(sysctl_ip_vs_sync_threshold),
1710 .mode = 0644, 1698 .mode = 0644,
1711 .proc_handler = &proc_do_sync_threshold, 1699 .proc_handler = proc_do_sync_threshold,
1712 }, 1700 },
1713 { 1701 {
1714 .procname = "nat_icmp_send", 1702 .procname = "nat_icmp_send",
1715 .data = &sysctl_ip_vs_nat_icmp_send, 1703 .data = &sysctl_ip_vs_nat_icmp_send,
1716 .maxlen = sizeof(int), 1704 .maxlen = sizeof(int),
1717 .mode = 0644, 1705 .mode = 0644,
1718 .proc_handler = &proc_dointvec, 1706 .proc_handler = proc_dointvec,
1719 }, 1707 },
1720 { .ctl_name = 0 } 1708 { .ctl_name = 0 }
1721}; 1709};
@@ -1867,9 +1855,9 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
1867 if (iter->table == ip_vs_svc_table) { 1855 if (iter->table == ip_vs_svc_table) {
1868#ifdef CONFIG_IP_VS_IPV6 1856#ifdef CONFIG_IP_VS_IPV6
1869 if (svc->af == AF_INET6) 1857 if (svc->af == AF_INET6)
1870 seq_printf(seq, "%s [" NIP6_FMT "]:%04X %s ", 1858 seq_printf(seq, "%s [%pI6]:%04X %s ",
1871 ip_vs_proto_name(svc->protocol), 1859 ip_vs_proto_name(svc->protocol),
1872 NIP6(svc->addr.in6), 1860 &svc->addr.in6,
1873 ntohs(svc->port), 1861 ntohs(svc->port),
1874 svc->scheduler->name); 1862 svc->scheduler->name);
1875 else 1863 else
@@ -1895,9 +1883,9 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
1895#ifdef CONFIG_IP_VS_IPV6 1883#ifdef CONFIG_IP_VS_IPV6
1896 if (dest->af == AF_INET6) 1884 if (dest->af == AF_INET6)
1897 seq_printf(seq, 1885 seq_printf(seq,
1898 " -> [" NIP6_FMT "]:%04X" 1886 " -> [%pI6]:%04X"
1899 " %-7s %-6d %-10d %-10d\n", 1887 " %-7s %-6d %-10d %-10d\n",
1900 NIP6(dest->addr.in6), 1888 &dest->addr.in6,
1901 ntohs(dest->port), 1889 ntohs(dest->port),
1902 ip_vs_fwd_name(atomic_read(&dest->conn_flags)), 1890 ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
1903 atomic_read(&dest->weight), 1891 atomic_read(&dest->weight),
@@ -2141,8 +2129,8 @@ do_ip_vs_set_ctl(struct sock *sk, int cmd, void __user *user, unsigned int len)
2141 2129
2142 /* Check for valid protocol: TCP or UDP, even for fwmark!=0 */ 2130 /* Check for valid protocol: TCP or UDP, even for fwmark!=0 */
2143 if (usvc.protocol != IPPROTO_TCP && usvc.protocol != IPPROTO_UDP) { 2131 if (usvc.protocol != IPPROTO_TCP && usvc.protocol != IPPROTO_UDP) {
2144 IP_VS_ERR("set_ctl: invalid protocol: %d %d.%d.%d.%d:%d %s\n", 2132 IP_VS_ERR("set_ctl: invalid protocol: %d %pI4:%d %s\n",
2145 usvc.protocol, NIPQUAD(usvc.addr.ip), 2133 usvc.protocol, &usvc.addr.ip,
2146 ntohs(usvc.port), usvc.sched_name); 2134 ntohs(usvc.port), usvc.sched_name);
2147 ret = -EFAULT; 2135 ret = -EFAULT;
2148 goto out_unlock; 2136 goto out_unlock;
diff --git a/net/netfilter/ipvs/ip_vs_dh.c b/net/netfilter/ipvs/ip_vs_dh.c
index a16943fd72f1..a9dac74bb13f 100644
--- a/net/netfilter/ipvs/ip_vs_dh.c
+++ b/net/netfilter/ipvs/ip_vs_dh.c
@@ -64,9 +64,16 @@ struct ip_vs_dh_bucket {
64/* 64/*
65 * Returns hash value for IPVS DH entry 65 * Returns hash value for IPVS DH entry
66 */ 66 */
67static inline unsigned ip_vs_dh_hashkey(__be32 addr) 67static inline unsigned ip_vs_dh_hashkey(int af, const union nf_inet_addr *addr)
68{ 68{
69 return (ntohl(addr)*2654435761UL) & IP_VS_DH_TAB_MASK; 69 __be32 addr_fold = addr->ip;
70
71#ifdef CONFIG_IP_VS_IPV6
72 if (af == AF_INET6)
73 addr_fold = addr->ip6[0]^addr->ip6[1]^
74 addr->ip6[2]^addr->ip6[3];
75#endif
76 return (ntohl(addr_fold)*2654435761UL) & IP_VS_DH_TAB_MASK;
70} 77}
71 78
72 79
@@ -74,9 +81,10 @@ static inline unsigned ip_vs_dh_hashkey(__be32 addr)
74 * Get ip_vs_dest associated with supplied parameters. 81 * Get ip_vs_dest associated with supplied parameters.
75 */ 82 */
76static inline struct ip_vs_dest * 83static inline struct ip_vs_dest *
77ip_vs_dh_get(struct ip_vs_dh_bucket *tbl, __be32 addr) 84ip_vs_dh_get(int af, struct ip_vs_dh_bucket *tbl,
85 const union nf_inet_addr *addr)
78{ 86{
79 return (tbl[ip_vs_dh_hashkey(addr)]).dest; 87 return (tbl[ip_vs_dh_hashkey(af, addr)]).dest;
80} 88}
81 89
82 90
@@ -202,12 +210,14 @@ ip_vs_dh_schedule(struct ip_vs_service *svc, const struct sk_buff *skb)
202{ 210{
203 struct ip_vs_dest *dest; 211 struct ip_vs_dest *dest;
204 struct ip_vs_dh_bucket *tbl; 212 struct ip_vs_dh_bucket *tbl;
205 struct iphdr *iph = ip_hdr(skb); 213 struct ip_vs_iphdr iph;
214
215 ip_vs_fill_iphdr(svc->af, skb_network_header(skb), &iph);
206 216
207 IP_VS_DBG(6, "ip_vs_dh_schedule(): Scheduling...\n"); 217 IP_VS_DBG(6, "ip_vs_dh_schedule(): Scheduling...\n");
208 218
209 tbl = (struct ip_vs_dh_bucket *)svc->sched_data; 219 tbl = (struct ip_vs_dh_bucket *)svc->sched_data;
210 dest = ip_vs_dh_get(tbl, iph->daddr); 220 dest = ip_vs_dh_get(svc->af, tbl, &iph.daddr);
211 if (!dest 221 if (!dest
212 || !(dest->flags & IP_VS_DEST_F_AVAILABLE) 222 || !(dest->flags & IP_VS_DEST_F_AVAILABLE)
213 || atomic_read(&dest->weight) <= 0 223 || atomic_read(&dest->weight) <= 0
@@ -215,11 +225,10 @@ ip_vs_dh_schedule(struct ip_vs_service *svc, const struct sk_buff *skb)
215 return NULL; 225 return NULL;
216 } 226 }
217 227
218 IP_VS_DBG(6, "DH: destination IP address %u.%u.%u.%u " 228 IP_VS_DBG_BUF(6, "DH: destination IP address %s --> server %s:%d\n",
219 "--> server %u.%u.%u.%u:%d\n", 229 IP_VS_DBG_ADDR(svc->af, &iph.daddr),
220 NIPQUAD(iph->daddr), 230 IP_VS_DBG_ADDR(svc->af, &dest->addr),
221 NIPQUAD(dest->addr.ip), 231 ntohs(dest->port));
222 ntohs(dest->port));
223 232
224 return dest; 233 return dest;
225} 234}
@@ -234,9 +243,6 @@ static struct ip_vs_scheduler ip_vs_dh_scheduler =
234 .refcnt = ATOMIC_INIT(0), 243 .refcnt = ATOMIC_INIT(0),
235 .module = THIS_MODULE, 244 .module = THIS_MODULE,
236 .n_list = LIST_HEAD_INIT(ip_vs_dh_scheduler.n_list), 245 .n_list = LIST_HEAD_INIT(ip_vs_dh_scheduler.n_list),
237#ifdef CONFIG_IP_VS_IPV6
238 .supports_ipv6 = 0,
239#endif
240 .init_service = ip_vs_dh_init_svc, 246 .init_service = ip_vs_dh_init_svc,
241 .done_service = ip_vs_dh_done_svc, 247 .done_service = ip_vs_dh_done_svc,
242 .update_service = ip_vs_dh_update_svc, 248 .update_service = ip_vs_dh_update_svc,
diff --git a/net/netfilter/ipvs/ip_vs_ftp.c b/net/netfilter/ipvs/ip_vs_ftp.c
index 2e7dbd8b73a4..428edbf481cc 100644
--- a/net/netfilter/ipvs/ip_vs_ftp.c
+++ b/net/netfilter/ipvs/ip_vs_ftp.c
@@ -178,10 +178,8 @@ static int ip_vs_ftp_out(struct ip_vs_app *app, struct ip_vs_conn *cp,
178 &start, &end) != 1) 178 &start, &end) != 1)
179 return 1; 179 return 1;
180 180
181 IP_VS_DBG(7, "PASV response (%u.%u.%u.%u:%d) -> " 181 IP_VS_DBG(7, "PASV response (%pI4:%d) -> %pI4:%d detected\n",
182 "%u.%u.%u.%u:%d detected\n", 182 &from.ip, ntohs(port), &cp->caddr.ip, 0);
183 NIPQUAD(from.ip), ntohs(port),
184 NIPQUAD(cp->caddr.ip), 0);
185 183
186 /* 184 /*
187 * Now update or create an connection entry for it 185 * Now update or create an connection entry for it
@@ -312,8 +310,7 @@ static int ip_vs_ftp_in(struct ip_vs_app *app, struct ip_vs_conn *cp,
312 &start, &end) != 1) 310 &start, &end) != 1)
313 return 1; 311 return 1;
314 312
315 IP_VS_DBG(7, "PORT %u.%u.%u.%u:%d detected\n", 313 IP_VS_DBG(7, "PORT %pI4:%d detected\n", &to.ip, ntohs(port));
316 NIPQUAD(to.ip), ntohs(port));
317 314
318 /* Passive mode off */ 315 /* Passive mode off */
319 cp->app_data = NULL; 316 cp->app_data = NULL;
@@ -321,9 +318,9 @@ static int ip_vs_ftp_in(struct ip_vs_app *app, struct ip_vs_conn *cp,
321 /* 318 /*
322 * Now update or create a connection entry for it 319 * Now update or create a connection entry for it
323 */ 320 */
324 IP_VS_DBG(7, "protocol %s %u.%u.%u.%u:%d %u.%u.%u.%u:%d\n", 321 IP_VS_DBG(7, "protocol %s %pI4:%d %pI4:%d\n",
325 ip_vs_proto_name(iph->protocol), 322 ip_vs_proto_name(iph->protocol),
326 NIPQUAD(to.ip), ntohs(port), NIPQUAD(cp->vaddr.ip), 0); 323 &to.ip, ntohs(port), &cp->vaddr.ip, 0);
327 324
328 n_cp = ip_vs_conn_in_get(AF_INET, iph->protocol, 325 n_cp = ip_vs_conn_in_get(AF_INET, iph->protocol,
329 &to, port, 326 &to, port,
diff --git a/net/netfilter/ipvs/ip_vs_lblc.c b/net/netfilter/ipvs/ip_vs_lblc.c
index 6ecef3518cac..9394f539966a 100644
--- a/net/netfilter/ipvs/ip_vs_lblc.c
+++ b/net/netfilter/ipvs/ip_vs_lblc.c
@@ -86,7 +86,8 @@ static int sysctl_ip_vs_lblc_expiration = 24*60*60*HZ;
86 */ 86 */
87struct ip_vs_lblc_entry { 87struct ip_vs_lblc_entry {
88 struct list_head list; 88 struct list_head list;
89 __be32 addr; /* destination IP address */ 89 int af; /* address family */
90 union nf_inet_addr addr; /* destination IP address */
90 struct ip_vs_dest *dest; /* real server (cache) */ 91 struct ip_vs_dest *dest; /* real server (cache) */
91 unsigned long lastuse; /* last used time */ 92 unsigned long lastuse; /* last used time */
92}; 93};
@@ -115,7 +116,7 @@ static ctl_table vs_vars_table[] = {
115 .data = &sysctl_ip_vs_lblc_expiration, 116 .data = &sysctl_ip_vs_lblc_expiration,
116 .maxlen = sizeof(int), 117 .maxlen = sizeof(int),
117 .mode = 0644, 118 .mode = 0644,
118 .proc_handler = &proc_dointvec_jiffies, 119 .proc_handler = proc_dointvec_jiffies,
119 }, 120 },
120 { .ctl_name = 0 } 121 { .ctl_name = 0 }
121}; 122};
@@ -137,9 +138,17 @@ static inline void ip_vs_lblc_free(struct ip_vs_lblc_entry *en)
137/* 138/*
138 * Returns hash value for IPVS LBLC entry 139 * Returns hash value for IPVS LBLC entry
139 */ 140 */
140static inline unsigned ip_vs_lblc_hashkey(__be32 addr) 141static inline unsigned
142ip_vs_lblc_hashkey(int af, const union nf_inet_addr *addr)
141{ 143{
142 return (ntohl(addr)*2654435761UL) & IP_VS_LBLC_TAB_MASK; 144 __be32 addr_fold = addr->ip;
145
146#ifdef CONFIG_IP_VS_IPV6
147 if (af == AF_INET6)
148 addr_fold = addr->ip6[0]^addr->ip6[1]^
149 addr->ip6[2]^addr->ip6[3];
150#endif
151 return (ntohl(addr_fold)*2654435761UL) & IP_VS_LBLC_TAB_MASK;
143} 152}
144 153
145 154
@@ -150,7 +159,7 @@ static inline unsigned ip_vs_lblc_hashkey(__be32 addr)
150static void 159static void
151ip_vs_lblc_hash(struct ip_vs_lblc_table *tbl, struct ip_vs_lblc_entry *en) 160ip_vs_lblc_hash(struct ip_vs_lblc_table *tbl, struct ip_vs_lblc_entry *en)
152{ 161{
153 unsigned hash = ip_vs_lblc_hashkey(en->addr); 162 unsigned hash = ip_vs_lblc_hashkey(en->af, &en->addr);
154 163
155 list_add(&en->list, &tbl->bucket[hash]); 164 list_add(&en->list, &tbl->bucket[hash]);
156 atomic_inc(&tbl->entries); 165 atomic_inc(&tbl->entries);
@@ -162,13 +171,14 @@ ip_vs_lblc_hash(struct ip_vs_lblc_table *tbl, struct ip_vs_lblc_entry *en)
162 * lock 171 * lock
163 */ 172 */
164static inline struct ip_vs_lblc_entry * 173static inline struct ip_vs_lblc_entry *
165ip_vs_lblc_get(struct ip_vs_lblc_table *tbl, __be32 addr) 174ip_vs_lblc_get(int af, struct ip_vs_lblc_table *tbl,
175 const union nf_inet_addr *addr)
166{ 176{
167 unsigned hash = ip_vs_lblc_hashkey(addr); 177 unsigned hash = ip_vs_lblc_hashkey(af, addr);
168 struct ip_vs_lblc_entry *en; 178 struct ip_vs_lblc_entry *en;
169 179
170 list_for_each_entry(en, &tbl->bucket[hash], list) 180 list_for_each_entry(en, &tbl->bucket[hash], list)
171 if (en->addr == addr) 181 if (ip_vs_addr_equal(af, &en->addr, addr))
172 return en; 182 return en;
173 183
174 return NULL; 184 return NULL;
@@ -180,12 +190,12 @@ ip_vs_lblc_get(struct ip_vs_lblc_table *tbl, __be32 addr)
180 * address to a server. Called under write lock. 190 * address to a server. Called under write lock.
181 */ 191 */
182static inline struct ip_vs_lblc_entry * 192static inline struct ip_vs_lblc_entry *
183ip_vs_lblc_new(struct ip_vs_lblc_table *tbl, __be32 daddr, 193ip_vs_lblc_new(struct ip_vs_lblc_table *tbl, const union nf_inet_addr *daddr,
184 struct ip_vs_dest *dest) 194 struct ip_vs_dest *dest)
185{ 195{
186 struct ip_vs_lblc_entry *en; 196 struct ip_vs_lblc_entry *en;
187 197
188 en = ip_vs_lblc_get(tbl, daddr); 198 en = ip_vs_lblc_get(dest->af, tbl, daddr);
189 if (!en) { 199 if (!en) {
190 en = kmalloc(sizeof(*en), GFP_ATOMIC); 200 en = kmalloc(sizeof(*en), GFP_ATOMIC);
191 if (!en) { 201 if (!en) {
@@ -193,7 +203,8 @@ ip_vs_lblc_new(struct ip_vs_lblc_table *tbl, __be32 daddr,
193 return NULL; 203 return NULL;
194 } 204 }
195 205
196 en->addr = daddr; 206 en->af = dest->af;
207 ip_vs_addr_copy(dest->af, &en->addr, daddr);
197 en->lastuse = jiffies; 208 en->lastuse = jiffies;
198 209
199 atomic_inc(&dest->refcnt); 210 atomic_inc(&dest->refcnt);
@@ -369,7 +380,7 @@ static int ip_vs_lblc_done_svc(struct ip_vs_service *svc)
369 380
370 381
371static inline struct ip_vs_dest * 382static inline struct ip_vs_dest *
372__ip_vs_lblc_schedule(struct ip_vs_service *svc, struct iphdr *iph) 383__ip_vs_lblc_schedule(struct ip_vs_service *svc)
373{ 384{
374 struct ip_vs_dest *dest, *least; 385 struct ip_vs_dest *dest, *least;
375 int loh, doh; 386 int loh, doh;
@@ -420,12 +431,13 @@ __ip_vs_lblc_schedule(struct ip_vs_service *svc, struct iphdr *iph)
420 } 431 }
421 } 432 }
422 433
423 IP_VS_DBG(6, "LBLC: server %d.%d.%d.%d:%d " 434 IP_VS_DBG_BUF(6, "LBLC: server %s:%d "
424 "activeconns %d refcnt %d weight %d overhead %d\n", 435 "activeconns %d refcnt %d weight %d overhead %d\n",
425 NIPQUAD(least->addr.ip), ntohs(least->port), 436 IP_VS_DBG_ADDR(least->af, &least->addr),
426 atomic_read(&least->activeconns), 437 ntohs(least->port),
427 atomic_read(&least->refcnt), 438 atomic_read(&least->activeconns),
428 atomic_read(&least->weight), loh); 439 atomic_read(&least->refcnt),
440 atomic_read(&least->weight), loh);
429 441
430 return least; 442 return least;
431} 443}
@@ -459,15 +471,17 @@ static struct ip_vs_dest *
459ip_vs_lblc_schedule(struct ip_vs_service *svc, const struct sk_buff *skb) 471ip_vs_lblc_schedule(struct ip_vs_service *svc, const struct sk_buff *skb)
460{ 472{
461 struct ip_vs_lblc_table *tbl = svc->sched_data; 473 struct ip_vs_lblc_table *tbl = svc->sched_data;
462 struct iphdr *iph = ip_hdr(skb); 474 struct ip_vs_iphdr iph;
463 struct ip_vs_dest *dest = NULL; 475 struct ip_vs_dest *dest = NULL;
464 struct ip_vs_lblc_entry *en; 476 struct ip_vs_lblc_entry *en;
465 477
478 ip_vs_fill_iphdr(svc->af, skb_network_header(skb), &iph);
479
466 IP_VS_DBG(6, "ip_vs_lblc_schedule(): Scheduling...\n"); 480 IP_VS_DBG(6, "ip_vs_lblc_schedule(): Scheduling...\n");
467 481
468 /* First look in our cache */ 482 /* First look in our cache */
469 read_lock(&svc->sched_lock); 483 read_lock(&svc->sched_lock);
470 en = ip_vs_lblc_get(tbl, iph->daddr); 484 en = ip_vs_lblc_get(svc->af, tbl, &iph.daddr);
471 if (en) { 485 if (en) {
472 /* We only hold a read lock, but this is atomic */ 486 /* We only hold a read lock, but this is atomic */
473 en->lastuse = jiffies; 487 en->lastuse = jiffies;
@@ -491,7 +505,7 @@ ip_vs_lblc_schedule(struct ip_vs_service *svc, const struct sk_buff *skb)
491 goto out; 505 goto out;
492 506
493 /* No cache entry or it is invalid, time to schedule */ 507 /* No cache entry or it is invalid, time to schedule */
494 dest = __ip_vs_lblc_schedule(svc, iph); 508 dest = __ip_vs_lblc_schedule(svc);
495 if (!dest) { 509 if (!dest) {
496 IP_VS_DBG(1, "no destination available\n"); 510 IP_VS_DBG(1, "no destination available\n");
497 return NULL; 511 return NULL;
@@ -499,15 +513,13 @@ ip_vs_lblc_schedule(struct ip_vs_service *svc, const struct sk_buff *skb)
499 513
500 /* If we fail to create a cache entry, we'll just use the valid dest */ 514 /* If we fail to create a cache entry, we'll just use the valid dest */
501 write_lock(&svc->sched_lock); 515 write_lock(&svc->sched_lock);
502 ip_vs_lblc_new(tbl, iph->daddr, dest); 516 ip_vs_lblc_new(tbl, &iph.daddr, dest);
503 write_unlock(&svc->sched_lock); 517 write_unlock(&svc->sched_lock);
504 518
505out: 519out:
506 IP_VS_DBG(6, "LBLC: destination IP address %u.%u.%u.%u " 520 IP_VS_DBG_BUF(6, "LBLC: destination IP address %s --> server %s:%d\n",
507 "--> server %u.%u.%u.%u:%d\n", 521 IP_VS_DBG_ADDR(svc->af, &iph.daddr),
508 NIPQUAD(iph->daddr), 522 IP_VS_DBG_ADDR(svc->af, &dest->addr), ntohs(dest->port));
509 NIPQUAD(dest->addr.ip),
510 ntohs(dest->port));
511 523
512 return dest; 524 return dest;
513} 525}
@@ -522,9 +534,6 @@ static struct ip_vs_scheduler ip_vs_lblc_scheduler =
522 .refcnt = ATOMIC_INIT(0), 534 .refcnt = ATOMIC_INIT(0),
523 .module = THIS_MODULE, 535 .module = THIS_MODULE,
524 .n_list = LIST_HEAD_INIT(ip_vs_lblc_scheduler.n_list), 536 .n_list = LIST_HEAD_INIT(ip_vs_lblc_scheduler.n_list),
525#ifdef CONFIG_IP_VS_IPV6
526 .supports_ipv6 = 0,
527#endif
528 .init_service = ip_vs_lblc_init_svc, 537 .init_service = ip_vs_lblc_init_svc,
529 .done_service = ip_vs_lblc_done_svc, 538 .done_service = ip_vs_lblc_done_svc,
530 .schedule = ip_vs_lblc_schedule, 539 .schedule = ip_vs_lblc_schedule,
diff --git a/net/netfilter/ipvs/ip_vs_lblcr.c b/net/netfilter/ipvs/ip_vs_lblcr.c
index 1f75ea83bcf8..92dc76a6842c 100644
--- a/net/netfilter/ipvs/ip_vs_lblcr.c
+++ b/net/netfilter/ipvs/ip_vs_lblcr.c
@@ -202,12 +202,13 @@ static inline struct ip_vs_dest *ip_vs_dest_set_min(struct ip_vs_dest_set *set)
202 } 202 }
203 } 203 }
204 204
205 IP_VS_DBG(6, "ip_vs_dest_set_min: server %d.%d.%d.%d:%d " 205 IP_VS_DBG_BUF(6, "ip_vs_dest_set_min: server %s:%d "
206 "activeconns %d refcnt %d weight %d overhead %d\n", 206 "activeconns %d refcnt %d weight %d overhead %d\n",
207 NIPQUAD(least->addr.ip), ntohs(least->port), 207 IP_VS_DBG_ADDR(least->af, &least->addr),
208 atomic_read(&least->activeconns), 208 ntohs(least->port),
209 atomic_read(&least->refcnt), 209 atomic_read(&least->activeconns),
210 atomic_read(&least->weight), loh); 210 atomic_read(&least->refcnt),
211 atomic_read(&least->weight), loh);
211 return least; 212 return least;
212} 213}
213 214
@@ -248,12 +249,12 @@ static inline struct ip_vs_dest *ip_vs_dest_set_max(struct ip_vs_dest_set *set)
248 } 249 }
249 } 250 }
250 251
251 IP_VS_DBG(6, "ip_vs_dest_set_max: server %d.%d.%d.%d:%d " 252 IP_VS_DBG_BUF(6, "ip_vs_dest_set_max: server %s:%d "
252 "activeconns %d refcnt %d weight %d overhead %d\n", 253 "activeconns %d refcnt %d weight %d overhead %d\n",
253 NIPQUAD(most->addr.ip), ntohs(most->port), 254 IP_VS_DBG_ADDR(most->af, &most->addr), ntohs(most->port),
254 atomic_read(&most->activeconns), 255 atomic_read(&most->activeconns),
255 atomic_read(&most->refcnt), 256 atomic_read(&most->refcnt),
256 atomic_read(&most->weight), moh); 257 atomic_read(&most->weight), moh);
257 return most; 258 return most;
258} 259}
259 260
@@ -264,7 +265,8 @@ static inline struct ip_vs_dest *ip_vs_dest_set_max(struct ip_vs_dest_set *set)
264 */ 265 */
265struct ip_vs_lblcr_entry { 266struct ip_vs_lblcr_entry {
266 struct list_head list; 267 struct list_head list;
267 __be32 addr; /* destination IP address */ 268 int af; /* address family */
269 union nf_inet_addr addr; /* destination IP address */
268 struct ip_vs_dest_set set; /* destination server set */ 270 struct ip_vs_dest_set set; /* destination server set */
269 unsigned long lastuse; /* last used time */ 271 unsigned long lastuse; /* last used time */
270}; 272};
@@ -293,7 +295,7 @@ static ctl_table vs_vars_table[] = {
293 .data = &sysctl_ip_vs_lblcr_expiration, 295 .data = &sysctl_ip_vs_lblcr_expiration,
294 .maxlen = sizeof(int), 296 .maxlen = sizeof(int),
295 .mode = 0644, 297 .mode = 0644,
296 .proc_handler = &proc_dointvec_jiffies, 298 .proc_handler = proc_dointvec_jiffies,
297 }, 299 },
298 { .ctl_name = 0 } 300 { .ctl_name = 0 }
299}; 301};
@@ -311,9 +313,17 @@ static inline void ip_vs_lblcr_free(struct ip_vs_lblcr_entry *en)
311/* 313/*
312 * Returns hash value for IPVS LBLCR entry 314 * Returns hash value for IPVS LBLCR entry
313 */ 315 */
314static inline unsigned ip_vs_lblcr_hashkey(__be32 addr) 316static inline unsigned
317ip_vs_lblcr_hashkey(int af, const union nf_inet_addr *addr)
315{ 318{
316 return (ntohl(addr)*2654435761UL) & IP_VS_LBLCR_TAB_MASK; 319 __be32 addr_fold = addr->ip;
320
321#ifdef CONFIG_IP_VS_IPV6
322 if (af == AF_INET6)
323 addr_fold = addr->ip6[0]^addr->ip6[1]^
324 addr->ip6[2]^addr->ip6[3];
325#endif
326 return (ntohl(addr_fold)*2654435761UL) & IP_VS_LBLCR_TAB_MASK;
317} 327}
318 328
319 329
@@ -324,7 +334,7 @@ static inline unsigned ip_vs_lblcr_hashkey(__be32 addr)
324static void 334static void
325ip_vs_lblcr_hash(struct ip_vs_lblcr_table *tbl, struct ip_vs_lblcr_entry *en) 335ip_vs_lblcr_hash(struct ip_vs_lblcr_table *tbl, struct ip_vs_lblcr_entry *en)
326{ 336{
327 unsigned hash = ip_vs_lblcr_hashkey(en->addr); 337 unsigned hash = ip_vs_lblcr_hashkey(en->af, &en->addr);
328 338
329 list_add(&en->list, &tbl->bucket[hash]); 339 list_add(&en->list, &tbl->bucket[hash]);
330 atomic_inc(&tbl->entries); 340 atomic_inc(&tbl->entries);
@@ -336,13 +346,14 @@ ip_vs_lblcr_hash(struct ip_vs_lblcr_table *tbl, struct ip_vs_lblcr_entry *en)
336 * read lock. 346 * read lock.
337 */ 347 */
338static inline struct ip_vs_lblcr_entry * 348static inline struct ip_vs_lblcr_entry *
339ip_vs_lblcr_get(struct ip_vs_lblcr_table *tbl, __be32 addr) 349ip_vs_lblcr_get(int af, struct ip_vs_lblcr_table *tbl,
350 const union nf_inet_addr *addr)
340{ 351{
341 unsigned hash = ip_vs_lblcr_hashkey(addr); 352 unsigned hash = ip_vs_lblcr_hashkey(af, addr);
342 struct ip_vs_lblcr_entry *en; 353 struct ip_vs_lblcr_entry *en;
343 354
344 list_for_each_entry(en, &tbl->bucket[hash], list) 355 list_for_each_entry(en, &tbl->bucket[hash], list)
345 if (en->addr == addr) 356 if (ip_vs_addr_equal(af, &en->addr, addr))
346 return en; 357 return en;
347 358
348 return NULL; 359 return NULL;
@@ -354,12 +365,12 @@ ip_vs_lblcr_get(struct ip_vs_lblcr_table *tbl, __be32 addr)
354 * IP address to a server. Called under write lock. 365 * IP address to a server. Called under write lock.
355 */ 366 */
356static inline struct ip_vs_lblcr_entry * 367static inline struct ip_vs_lblcr_entry *
357ip_vs_lblcr_new(struct ip_vs_lblcr_table *tbl, __be32 daddr, 368ip_vs_lblcr_new(struct ip_vs_lblcr_table *tbl, const union nf_inet_addr *daddr,
358 struct ip_vs_dest *dest) 369 struct ip_vs_dest *dest)
359{ 370{
360 struct ip_vs_lblcr_entry *en; 371 struct ip_vs_lblcr_entry *en;
361 372
362 en = ip_vs_lblcr_get(tbl, daddr); 373 en = ip_vs_lblcr_get(dest->af, tbl, daddr);
363 if (!en) { 374 if (!en) {
364 en = kmalloc(sizeof(*en), GFP_ATOMIC); 375 en = kmalloc(sizeof(*en), GFP_ATOMIC);
365 if (!en) { 376 if (!en) {
@@ -367,7 +378,8 @@ ip_vs_lblcr_new(struct ip_vs_lblcr_table *tbl, __be32 daddr,
367 return NULL; 378 return NULL;
368 } 379 }
369 380
370 en->addr = daddr; 381 en->af = dest->af;
382 ip_vs_addr_copy(dest->af, &en->addr, daddr);
371 en->lastuse = jiffies; 383 en->lastuse = jiffies;
372 384
373 /* initilize its dest set */ 385 /* initilize its dest set */
@@ -544,7 +556,7 @@ static int ip_vs_lblcr_done_svc(struct ip_vs_service *svc)
544 556
545 557
546static inline struct ip_vs_dest * 558static inline struct ip_vs_dest *
547__ip_vs_lblcr_schedule(struct ip_vs_service *svc, struct iphdr *iph) 559__ip_vs_lblcr_schedule(struct ip_vs_service *svc)
548{ 560{
549 struct ip_vs_dest *dest, *least; 561 struct ip_vs_dest *dest, *least;
550 int loh, doh; 562 int loh, doh;
@@ -596,12 +608,13 @@ __ip_vs_lblcr_schedule(struct ip_vs_service *svc, struct iphdr *iph)
596 } 608 }
597 } 609 }
598 610
599 IP_VS_DBG(6, "LBLCR: server %d.%d.%d.%d:%d " 611 IP_VS_DBG_BUF(6, "LBLCR: server %s:%d "
600 "activeconns %d refcnt %d weight %d overhead %d\n", 612 "activeconns %d refcnt %d weight %d overhead %d\n",
601 NIPQUAD(least->addr.ip), ntohs(least->port), 613 IP_VS_DBG_ADDR(least->af, &least->addr),
602 atomic_read(&least->activeconns), 614 ntohs(least->port),
603 atomic_read(&least->refcnt), 615 atomic_read(&least->activeconns),
604 atomic_read(&least->weight), loh); 616 atomic_read(&least->refcnt),
617 atomic_read(&least->weight), loh);
605 618
606 return least; 619 return least;
607} 620}
@@ -635,15 +648,17 @@ static struct ip_vs_dest *
635ip_vs_lblcr_schedule(struct ip_vs_service *svc, const struct sk_buff *skb) 648ip_vs_lblcr_schedule(struct ip_vs_service *svc, const struct sk_buff *skb)
636{ 649{
637 struct ip_vs_lblcr_table *tbl = svc->sched_data; 650 struct ip_vs_lblcr_table *tbl = svc->sched_data;
638 struct iphdr *iph = ip_hdr(skb); 651 struct ip_vs_iphdr iph;
639 struct ip_vs_dest *dest = NULL; 652 struct ip_vs_dest *dest = NULL;
640 struct ip_vs_lblcr_entry *en; 653 struct ip_vs_lblcr_entry *en;
641 654
655 ip_vs_fill_iphdr(svc->af, skb_network_header(skb), &iph);
656
642 IP_VS_DBG(6, "ip_vs_lblcr_schedule(): Scheduling...\n"); 657 IP_VS_DBG(6, "ip_vs_lblcr_schedule(): Scheduling...\n");
643 658
644 /* First look in our cache */ 659 /* First look in our cache */
645 read_lock(&svc->sched_lock); 660 read_lock(&svc->sched_lock);
646 en = ip_vs_lblcr_get(tbl, iph->daddr); 661 en = ip_vs_lblcr_get(svc->af, tbl, &iph.daddr);
647 if (en) { 662 if (en) {
648 /* We only hold a read lock, but this is atomic */ 663 /* We only hold a read lock, but this is atomic */
649 en->lastuse = jiffies; 664 en->lastuse = jiffies;
@@ -673,7 +688,7 @@ ip_vs_lblcr_schedule(struct ip_vs_service *svc, const struct sk_buff *skb)
673 } 688 }
674 689
675 /* The cache entry is invalid, time to schedule */ 690 /* The cache entry is invalid, time to schedule */
676 dest = __ip_vs_lblcr_schedule(svc, iph); 691 dest = __ip_vs_lblcr_schedule(svc);
677 if (!dest) { 692 if (!dest) {
678 IP_VS_DBG(1, "no destination available\n"); 693 IP_VS_DBG(1, "no destination available\n");
679 read_unlock(&svc->sched_lock); 694 read_unlock(&svc->sched_lock);
@@ -691,7 +706,7 @@ ip_vs_lblcr_schedule(struct ip_vs_service *svc, const struct sk_buff *skb)
691 goto out; 706 goto out;
692 707
693 /* No cache entry, time to schedule */ 708 /* No cache entry, time to schedule */
694 dest = __ip_vs_lblcr_schedule(svc, iph); 709 dest = __ip_vs_lblcr_schedule(svc);
695 if (!dest) { 710 if (!dest) {
696 IP_VS_DBG(1, "no destination available\n"); 711 IP_VS_DBG(1, "no destination available\n");
697 return NULL; 712 return NULL;
@@ -699,15 +714,13 @@ ip_vs_lblcr_schedule(struct ip_vs_service *svc, const struct sk_buff *skb)
699 714
700 /* If we fail to create a cache entry, we'll just use the valid dest */ 715 /* If we fail to create a cache entry, we'll just use the valid dest */
701 write_lock(&svc->sched_lock); 716 write_lock(&svc->sched_lock);
702 ip_vs_lblcr_new(tbl, iph->daddr, dest); 717 ip_vs_lblcr_new(tbl, &iph.daddr, dest);
703 write_unlock(&svc->sched_lock); 718 write_unlock(&svc->sched_lock);
704 719
705out: 720out:
706 IP_VS_DBG(6, "LBLCR: destination IP address %u.%u.%u.%u " 721 IP_VS_DBG_BUF(6, "LBLCR: destination IP address %s --> server %s:%d\n",
707 "--> server %u.%u.%u.%u:%d\n", 722 IP_VS_DBG_ADDR(svc->af, &iph.daddr),
708 NIPQUAD(iph->daddr), 723 IP_VS_DBG_ADDR(svc->af, &dest->addr), ntohs(dest->port));
709 NIPQUAD(dest->addr.ip),
710 ntohs(dest->port));
711 724
712 return dest; 725 return dest;
713} 726}
@@ -722,9 +735,6 @@ static struct ip_vs_scheduler ip_vs_lblcr_scheduler =
722 .refcnt = ATOMIC_INIT(0), 735 .refcnt = ATOMIC_INIT(0),
723 .module = THIS_MODULE, 736 .module = THIS_MODULE,
724 .n_list = LIST_HEAD_INIT(ip_vs_lblcr_scheduler.n_list), 737 .n_list = LIST_HEAD_INIT(ip_vs_lblcr_scheduler.n_list),
725#ifdef CONFIG_IP_VS_IPV6
726 .supports_ipv6 = 0,
727#endif
728 .init_service = ip_vs_lblcr_init_svc, 738 .init_service = ip_vs_lblcr_init_svc,
729 .done_service = ip_vs_lblcr_done_svc, 739 .done_service = ip_vs_lblcr_done_svc,
730 .schedule = ip_vs_lblcr_schedule, 740 .schedule = ip_vs_lblcr_schedule,
diff --git a/net/netfilter/ipvs/ip_vs_lc.c b/net/netfilter/ipvs/ip_vs_lc.c
index b69f808ac461..51912cab777b 100644
--- a/net/netfilter/ipvs/ip_vs_lc.c
+++ b/net/netfilter/ipvs/ip_vs_lc.c
@@ -81,9 +81,6 @@ static struct ip_vs_scheduler ip_vs_lc_scheduler = {
81 .refcnt = ATOMIC_INIT(0), 81 .refcnt = ATOMIC_INIT(0),
82 .module = THIS_MODULE, 82 .module = THIS_MODULE,
83 .n_list = LIST_HEAD_INIT(ip_vs_lc_scheduler.n_list), 83 .n_list = LIST_HEAD_INIT(ip_vs_lc_scheduler.n_list),
84#ifdef CONFIG_IP_VS_IPV6
85 .supports_ipv6 = 1,
86#endif
87 .schedule = ip_vs_lc_schedule, 84 .schedule = ip_vs_lc_schedule,
88}; 85};
89 86
diff --git a/net/netfilter/ipvs/ip_vs_nq.c b/net/netfilter/ipvs/ip_vs_nq.c
index 9a2d8033f08f..6758ad2ceaaf 100644
--- a/net/netfilter/ipvs/ip_vs_nq.c
+++ b/net/netfilter/ipvs/ip_vs_nq.c
@@ -116,9 +116,6 @@ static struct ip_vs_scheduler ip_vs_nq_scheduler =
116 .refcnt = ATOMIC_INIT(0), 116 .refcnt = ATOMIC_INIT(0),
117 .module = THIS_MODULE, 117 .module = THIS_MODULE,
118 .n_list = LIST_HEAD_INIT(ip_vs_nq_scheduler.n_list), 118 .n_list = LIST_HEAD_INIT(ip_vs_nq_scheduler.n_list),
119#ifdef CONFIG_IP_VS_IPV6
120 .supports_ipv6 = 1,
121#endif
122 .schedule = ip_vs_nq_schedule, 119 .schedule = ip_vs_nq_schedule,
123}; 120};
124 121
diff --git a/net/netfilter/ipvs/ip_vs_proto.c b/net/netfilter/ipvs/ip_vs_proto.c
index 0791f9e08feb..a01520e3d6b8 100644
--- a/net/netfilter/ipvs/ip_vs_proto.c
+++ b/net/netfilter/ipvs/ip_vs_proto.c
@@ -164,26 +164,21 @@ ip_vs_tcpudp_debug_packet_v4(struct ip_vs_protocol *pp,
164 if (ih == NULL) 164 if (ih == NULL)
165 sprintf(buf, "%s TRUNCATED", pp->name); 165 sprintf(buf, "%s TRUNCATED", pp->name);
166 else if (ih->frag_off & htons(IP_OFFSET)) 166 else if (ih->frag_off & htons(IP_OFFSET))
167 sprintf(buf, "%s %u.%u.%u.%u->%u.%u.%u.%u frag", 167 sprintf(buf, "%s %pI4->%pI4 frag",
168 pp->name, NIPQUAD(ih->saddr), 168 pp->name, &ih->saddr, &ih->daddr);
169 NIPQUAD(ih->daddr));
170 else { 169 else {
171 __be16 _ports[2], *pptr 170 __be16 _ports[2], *pptr
172; 171;
173 pptr = skb_header_pointer(skb, offset + ih->ihl*4, 172 pptr = skb_header_pointer(skb, offset + ih->ihl*4,
174 sizeof(_ports), _ports); 173 sizeof(_ports), _ports);
175 if (pptr == NULL) 174 if (pptr == NULL)
176 sprintf(buf, "%s TRUNCATED %u.%u.%u.%u->%u.%u.%u.%u", 175 sprintf(buf, "%s TRUNCATED %pI4->%pI4",
177 pp->name, 176 pp->name, &ih->saddr, &ih->daddr);
178 NIPQUAD(ih->saddr),
179 NIPQUAD(ih->daddr));
180 else 177 else
181 sprintf(buf, "%s %u.%u.%u.%u:%u->%u.%u.%u.%u:%u", 178 sprintf(buf, "%s %pI4:%u->%pI4:%u",
182 pp->name, 179 pp->name,
183 NIPQUAD(ih->saddr), 180 &ih->saddr, ntohs(pptr[0]),
184 ntohs(pptr[0]), 181 &ih->daddr, ntohs(pptr[1]));
185 NIPQUAD(ih->daddr),
186 ntohs(pptr[1]));
187 } 182 }
188 183
189 printk(KERN_DEBUG "IPVS: %s: %s\n", msg, buf); 184 printk(KERN_DEBUG "IPVS: %s: %s\n", msg, buf);
@@ -203,26 +198,21 @@ ip_vs_tcpudp_debug_packet_v6(struct ip_vs_protocol *pp,
203 if (ih == NULL) 198 if (ih == NULL)
204 sprintf(buf, "%s TRUNCATED", pp->name); 199 sprintf(buf, "%s TRUNCATED", pp->name);
205 else if (ih->nexthdr == IPPROTO_FRAGMENT) 200 else if (ih->nexthdr == IPPROTO_FRAGMENT)
206 sprintf(buf, "%s " NIP6_FMT "->" NIP6_FMT " frag", 201 sprintf(buf, "%s %pI6->%pI6 frag",
207 pp->name, NIP6(ih->saddr), 202 pp->name, &ih->saddr, &ih->daddr);
208 NIP6(ih->daddr));
209 else { 203 else {
210 __be16 _ports[2], *pptr; 204 __be16 _ports[2], *pptr;
211 205
212 pptr = skb_header_pointer(skb, offset + sizeof(struct ipv6hdr), 206 pptr = skb_header_pointer(skb, offset + sizeof(struct ipv6hdr),
213 sizeof(_ports), _ports); 207 sizeof(_ports), _ports);
214 if (pptr == NULL) 208 if (pptr == NULL)
215 sprintf(buf, "%s TRUNCATED " NIP6_FMT "->" NIP6_FMT, 209 sprintf(buf, "%s TRUNCATED %pI6->%pI6",
216 pp->name, 210 pp->name, &ih->saddr, &ih->daddr);
217 NIP6(ih->saddr),
218 NIP6(ih->daddr));
219 else 211 else
220 sprintf(buf, "%s " NIP6_FMT ":%u->" NIP6_FMT ":%u", 212 sprintf(buf, "%s %pI6:%u->%pI6:%u",
221 pp->name, 213 pp->name,
222 NIP6(ih->saddr), 214 &ih->saddr, ntohs(pptr[0]),
223 ntohs(pptr[0]), 215 &ih->daddr, ntohs(pptr[1]));
224 NIP6(ih->daddr),
225 ntohs(pptr[1]));
226 } 216 }
227 217
228 printk(KERN_DEBUG "IPVS: %s: %s\n", msg, buf); 218 printk(KERN_DEBUG "IPVS: %s: %s\n", msg, buf);
diff --git a/net/netfilter/ipvs/ip_vs_proto_ah_esp.c b/net/netfilter/ipvs/ip_vs_proto_ah_esp.c
index 80ab0c8e5b4a..79f56c1e7c19 100644
--- a/net/netfilter/ipvs/ip_vs_proto_ah_esp.c
+++ b/net/netfilter/ipvs/ip_vs_proto_ah_esp.c
@@ -135,9 +135,8 @@ ah_esp_debug_packet_v4(struct ip_vs_protocol *pp, const struct sk_buff *skb,
135 if (ih == NULL) 135 if (ih == NULL)
136 sprintf(buf, "%s TRUNCATED", pp->name); 136 sprintf(buf, "%s TRUNCATED", pp->name);
137 else 137 else
138 sprintf(buf, "%s %u.%u.%u.%u->%u.%u.%u.%u", 138 sprintf(buf, "%s %pI4->%pI4",
139 pp->name, NIPQUAD(ih->saddr), 139 pp->name, &ih->saddr, &ih->daddr);
140 NIPQUAD(ih->daddr));
141 140
142 printk(KERN_DEBUG "IPVS: %s: %s\n", msg, buf); 141 printk(KERN_DEBUG "IPVS: %s: %s\n", msg, buf);
143} 142}
@@ -154,9 +153,8 @@ ah_esp_debug_packet_v6(struct ip_vs_protocol *pp, const struct sk_buff *skb,
154 if (ih == NULL) 153 if (ih == NULL)
155 sprintf(buf, "%s TRUNCATED", pp->name); 154 sprintf(buf, "%s TRUNCATED", pp->name);
156 else 155 else
157 sprintf(buf, "%s " NIP6_FMT "->" NIP6_FMT, 156 sprintf(buf, "%s %pI6->%pI6",
158 pp->name, NIP6(ih->saddr), 157 pp->name, &ih->saddr, &ih->daddr);
159 NIP6(ih->daddr));
160 158
161 printk(KERN_DEBUG "IPVS: %s: %s\n", msg, buf); 159 printk(KERN_DEBUG "IPVS: %s: %s\n", msg, buf);
162} 160}
diff --git a/net/netfilter/ipvs/ip_vs_proto_tcp.c b/net/netfilter/ipvs/ip_vs_proto_tcp.c
index dd4566ea2bff..8cba41802850 100644
--- a/net/netfilter/ipvs/ip_vs_proto_tcp.c
+++ b/net/netfilter/ipvs/ip_vs_proto_tcp.c
@@ -192,8 +192,8 @@ tcp_snat_handler(struct sk_buff *skb,
192 /* Adjust TCP checksums */ 192 /* Adjust TCP checksums */
193 if (skb->ip_summed == CHECKSUM_PARTIAL) { 193 if (skb->ip_summed == CHECKSUM_PARTIAL) {
194 tcp_partial_csum_update(cp->af, tcph, &cp->daddr, &cp->vaddr, 194 tcp_partial_csum_update(cp->af, tcph, &cp->daddr, &cp->vaddr,
195 htonl(oldlen), 195 htons(oldlen),
196 htonl(skb->len - tcphoff)); 196 htons(skb->len - tcphoff));
197 } else if (!cp->app) { 197 } else if (!cp->app) {
198 /* Only port and addr are changed, do fast csum update */ 198 /* Only port and addr are changed, do fast csum update */
199 tcp_fast_csum_update(cp->af, tcph, &cp->daddr, &cp->vaddr, 199 tcp_fast_csum_update(cp->af, tcph, &cp->daddr, &cp->vaddr,
@@ -267,8 +267,8 @@ tcp_dnat_handler(struct sk_buff *skb,
267 */ 267 */
268 if (skb->ip_summed == CHECKSUM_PARTIAL) { 268 if (skb->ip_summed == CHECKSUM_PARTIAL) {
269 tcp_partial_csum_update(cp->af, tcph, &cp->daddr, &cp->vaddr, 269 tcp_partial_csum_update(cp->af, tcph, &cp->daddr, &cp->vaddr,
270 htonl(oldlen), 270 htons(oldlen),
271 htonl(skb->len - tcphoff)); 271 htons(skb->len - tcphoff));
272 } else if (!cp->app) { 272 } else if (!cp->app) {
273 /* Only port and addr are changed, do fast csum update */ 273 /* Only port and addr are changed, do fast csum update */
274 tcp_fast_csum_update(cp->af, tcph, &cp->vaddr, &cp->daddr, 274 tcp_fast_csum_update(cp->af, tcph, &cp->vaddr, &cp->daddr,
diff --git a/net/netfilter/ipvs/ip_vs_proto_udp.c b/net/netfilter/ipvs/ip_vs_proto_udp.c
index 6eb6039d6343..d2930a71084b 100644
--- a/net/netfilter/ipvs/ip_vs_proto_udp.c
+++ b/net/netfilter/ipvs/ip_vs_proto_udp.c
@@ -203,8 +203,8 @@ udp_snat_handler(struct sk_buff *skb,
203 */ 203 */
204 if (skb->ip_summed == CHECKSUM_PARTIAL) { 204 if (skb->ip_summed == CHECKSUM_PARTIAL) {
205 udp_partial_csum_update(cp->af, udph, &cp->daddr, &cp->vaddr, 205 udp_partial_csum_update(cp->af, udph, &cp->daddr, &cp->vaddr,
206 htonl(oldlen), 206 htons(oldlen),
207 htonl(skb->len - udphoff)); 207 htons(skb->len - udphoff));
208 } else if (!cp->app && (udph->check != 0)) { 208 } else if (!cp->app && (udph->check != 0)) {
209 /* Only port and addr are changed, do fast csum update */ 209 /* Only port and addr are changed, do fast csum update */
210 udp_fast_csum_update(cp->af, udph, &cp->daddr, &cp->vaddr, 210 udp_fast_csum_update(cp->af, udph, &cp->daddr, &cp->vaddr,
@@ -279,8 +279,8 @@ udp_dnat_handler(struct sk_buff *skb,
279 */ 279 */
280 if (skb->ip_summed == CHECKSUM_PARTIAL) { 280 if (skb->ip_summed == CHECKSUM_PARTIAL) {
281 udp_partial_csum_update(cp->af, udph, &cp->daddr, &cp->vaddr, 281 udp_partial_csum_update(cp->af, udph, &cp->daddr, &cp->vaddr,
282 htonl(oldlen), 282 htons(oldlen),
283 htonl(skb->len - udphoff)); 283 htons(skb->len - udphoff));
284 } else if (!cp->app && (udph->check != 0)) { 284 } else if (!cp->app && (udph->check != 0)) {
285 /* Only port and addr are changed, do fast csum update */ 285 /* Only port and addr are changed, do fast csum update */
286 udp_fast_csum_update(cp->af, udph, &cp->vaddr, &cp->daddr, 286 udp_fast_csum_update(cp->af, udph, &cp->vaddr, &cp->daddr,
diff --git a/net/netfilter/ipvs/ip_vs_rr.c b/net/netfilter/ipvs/ip_vs_rr.c
index a22195f68ac4..8fb51c169eb8 100644
--- a/net/netfilter/ipvs/ip_vs_rr.c
+++ b/net/netfilter/ipvs/ip_vs_rr.c
@@ -89,9 +89,6 @@ static struct ip_vs_scheduler ip_vs_rr_scheduler = {
89 .refcnt = ATOMIC_INIT(0), 89 .refcnt = ATOMIC_INIT(0),
90 .module = THIS_MODULE, 90 .module = THIS_MODULE,
91 .n_list = LIST_HEAD_INIT(ip_vs_rr_scheduler.n_list), 91 .n_list = LIST_HEAD_INIT(ip_vs_rr_scheduler.n_list),
92#ifdef CONFIG_IP_VS_IPV6
93 .supports_ipv6 = 1,
94#endif
95 .init_service = ip_vs_rr_init_svc, 92 .init_service = ip_vs_rr_init_svc,
96 .update_service = ip_vs_rr_update_svc, 93 .update_service = ip_vs_rr_update_svc,
97 .schedule = ip_vs_rr_schedule, 94 .schedule = ip_vs_rr_schedule,
diff --git a/net/netfilter/ipvs/ip_vs_sed.c b/net/netfilter/ipvs/ip_vs_sed.c
index 7d2f22f04b83..691a6a0086e1 100644
--- a/net/netfilter/ipvs/ip_vs_sed.c
+++ b/net/netfilter/ipvs/ip_vs_sed.c
@@ -118,9 +118,6 @@ static struct ip_vs_scheduler ip_vs_sed_scheduler =
118 .refcnt = ATOMIC_INIT(0), 118 .refcnt = ATOMIC_INIT(0),
119 .module = THIS_MODULE, 119 .module = THIS_MODULE,
120 .n_list = LIST_HEAD_INIT(ip_vs_sed_scheduler.n_list), 120 .n_list = LIST_HEAD_INIT(ip_vs_sed_scheduler.n_list),
121#ifdef CONFIG_IP_VS_IPV6
122 .supports_ipv6 = 1,
123#endif
124 .schedule = ip_vs_sed_schedule, 121 .schedule = ip_vs_sed_schedule,
125}; 122};
126 123
diff --git a/net/netfilter/ipvs/ip_vs_sh.c b/net/netfilter/ipvs/ip_vs_sh.c
index 1d96de27fefd..0e53955ef139 100644
--- a/net/netfilter/ipvs/ip_vs_sh.c
+++ b/net/netfilter/ipvs/ip_vs_sh.c
@@ -61,9 +61,16 @@ struct ip_vs_sh_bucket {
61/* 61/*
62 * Returns hash value for IPVS SH entry 62 * Returns hash value for IPVS SH entry
63 */ 63 */
64static inline unsigned ip_vs_sh_hashkey(__be32 addr) 64static inline unsigned ip_vs_sh_hashkey(int af, const union nf_inet_addr *addr)
65{ 65{
66 return (ntohl(addr)*2654435761UL) & IP_VS_SH_TAB_MASK; 66 __be32 addr_fold = addr->ip;
67
68#ifdef CONFIG_IP_VS_IPV6
69 if (af == AF_INET6)
70 addr_fold = addr->ip6[0]^addr->ip6[1]^
71 addr->ip6[2]^addr->ip6[3];
72#endif
73 return (ntohl(addr_fold)*2654435761UL) & IP_VS_SH_TAB_MASK;
67} 74}
68 75
69 76
@@ -71,9 +78,10 @@ static inline unsigned ip_vs_sh_hashkey(__be32 addr)
71 * Get ip_vs_dest associated with supplied parameters. 78 * Get ip_vs_dest associated with supplied parameters.
72 */ 79 */
73static inline struct ip_vs_dest * 80static inline struct ip_vs_dest *
74ip_vs_sh_get(struct ip_vs_sh_bucket *tbl, __be32 addr) 81ip_vs_sh_get(int af, struct ip_vs_sh_bucket *tbl,
82 const union nf_inet_addr *addr)
75{ 83{
76 return (tbl[ip_vs_sh_hashkey(addr)]).dest; 84 return (tbl[ip_vs_sh_hashkey(af, addr)]).dest;
77} 85}
78 86
79 87
@@ -199,12 +207,14 @@ ip_vs_sh_schedule(struct ip_vs_service *svc, const struct sk_buff *skb)
199{ 207{
200 struct ip_vs_dest *dest; 208 struct ip_vs_dest *dest;
201 struct ip_vs_sh_bucket *tbl; 209 struct ip_vs_sh_bucket *tbl;
202 struct iphdr *iph = ip_hdr(skb); 210 struct ip_vs_iphdr iph;
211
212 ip_vs_fill_iphdr(svc->af, skb_network_header(skb), &iph);
203 213
204 IP_VS_DBG(6, "ip_vs_sh_schedule(): Scheduling...\n"); 214 IP_VS_DBG(6, "ip_vs_sh_schedule(): Scheduling...\n");
205 215
206 tbl = (struct ip_vs_sh_bucket *)svc->sched_data; 216 tbl = (struct ip_vs_sh_bucket *)svc->sched_data;
207 dest = ip_vs_sh_get(tbl, iph->saddr); 217 dest = ip_vs_sh_get(svc->af, tbl, &iph.saddr);
208 if (!dest 218 if (!dest
209 || !(dest->flags & IP_VS_DEST_F_AVAILABLE) 219 || !(dest->flags & IP_VS_DEST_F_AVAILABLE)
210 || atomic_read(&dest->weight) <= 0 220 || atomic_read(&dest->weight) <= 0
@@ -212,11 +222,10 @@ ip_vs_sh_schedule(struct ip_vs_service *svc, const struct sk_buff *skb)
212 return NULL; 222 return NULL;
213 } 223 }
214 224
215 IP_VS_DBG(6, "SH: source IP address %u.%u.%u.%u " 225 IP_VS_DBG_BUF(6, "SH: source IP address %s --> server %s:%d\n",
216 "--> server %u.%u.%u.%u:%d\n", 226 IP_VS_DBG_ADDR(svc->af, &iph.saddr),
217 NIPQUAD(iph->saddr), 227 IP_VS_DBG_ADDR(svc->af, &dest->addr),
218 NIPQUAD(dest->addr.ip), 228 ntohs(dest->port));
219 ntohs(dest->port));
220 229
221 return dest; 230 return dest;
222} 231}
@@ -231,9 +240,6 @@ static struct ip_vs_scheduler ip_vs_sh_scheduler =
231 .refcnt = ATOMIC_INIT(0), 240 .refcnt = ATOMIC_INIT(0),
232 .module = THIS_MODULE, 241 .module = THIS_MODULE,
233 .n_list = LIST_HEAD_INIT(ip_vs_sh_scheduler.n_list), 242 .n_list = LIST_HEAD_INIT(ip_vs_sh_scheduler.n_list),
234#ifdef CONFIG_IP_VS_IPV6
235 .supports_ipv6 = 0,
236#endif
237 .init_service = ip_vs_sh_init_svc, 243 .init_service = ip_vs_sh_init_svc,
238 .done_service = ip_vs_sh_done_svc, 244 .done_service = ip_vs_sh_done_svc,
239 .update_service = ip_vs_sh_update_svc, 245 .update_service = ip_vs_sh_update_svc,
diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
index de5e7e118eed..6be5d4efa51b 100644
--- a/net/netfilter/ipvs/ip_vs_sync.c
+++ b/net/netfilter/ipvs/ip_vs_sync.c
@@ -580,8 +580,8 @@ static int bind_mcastif_addr(struct socket *sock, char *ifname)
580 IP_VS_ERR("You probably need to specify IP address on " 580 IP_VS_ERR("You probably need to specify IP address on "
581 "multicast interface.\n"); 581 "multicast interface.\n");
582 582
583 IP_VS_DBG(7, "binding socket with (%s) %u.%u.%u.%u\n", 583 IP_VS_DBG(7, "binding socket with (%s) %pI4\n",
584 ifname, NIPQUAD(addr)); 584 ifname, &addr);
585 585
586 /* Now bind the socket with the address of multicast interface */ 586 /* Now bind the socket with the address of multicast interface */
587 sin.sin_family = AF_INET; 587 sin.sin_family = AF_INET;
diff --git a/net/netfilter/ipvs/ip_vs_wlc.c b/net/netfilter/ipvs/ip_vs_wlc.c
index 8c596e712599..57b452bbb4ea 100644
--- a/net/netfilter/ipvs/ip_vs_wlc.c
+++ b/net/netfilter/ipvs/ip_vs_wlc.c
@@ -106,9 +106,6 @@ static struct ip_vs_scheduler ip_vs_wlc_scheduler =
106 .refcnt = ATOMIC_INIT(0), 106 .refcnt = ATOMIC_INIT(0),
107 .module = THIS_MODULE, 107 .module = THIS_MODULE,
108 .n_list = LIST_HEAD_INIT(ip_vs_wlc_scheduler.n_list), 108 .n_list = LIST_HEAD_INIT(ip_vs_wlc_scheduler.n_list),
109#ifdef CONFIG_IP_VS_IPV6
110 .supports_ipv6 = 1,
111#endif
112 .schedule = ip_vs_wlc_schedule, 109 .schedule = ip_vs_wlc_schedule,
113}; 110};
114 111
diff --git a/net/netfilter/ipvs/ip_vs_wrr.c b/net/netfilter/ipvs/ip_vs_wrr.c
index 7ea92fed50bf..2f618dc29c5b 100644
--- a/net/netfilter/ipvs/ip_vs_wrr.c
+++ b/net/netfilter/ipvs/ip_vs_wrr.c
@@ -213,9 +213,6 @@ static struct ip_vs_scheduler ip_vs_wrr_scheduler = {
213 .refcnt = ATOMIC_INIT(0), 213 .refcnt = ATOMIC_INIT(0),
214 .module = THIS_MODULE, 214 .module = THIS_MODULE,
215 .n_list = LIST_HEAD_INIT(ip_vs_wrr_scheduler.n_list), 215 .n_list = LIST_HEAD_INIT(ip_vs_wrr_scheduler.n_list),
216#ifdef CONFIG_IP_VS_IPV6
217 .supports_ipv6 = 1,
218#endif
219 .init_service = ip_vs_wrr_init_svc, 216 .init_service = ip_vs_wrr_init_svc,
220 .done_service = ip_vs_wrr_done_svc, 217 .done_service = ip_vs_wrr_done_svc,
221 .update_service = ip_vs_wrr_update_svc, 218 .update_service = ip_vs_wrr_update_svc,
diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
index e90d52f199bc..425ab144f15d 100644
--- a/net/netfilter/ipvs/ip_vs_xmit.c
+++ b/net/netfilter/ipvs/ip_vs_xmit.c
@@ -82,14 +82,13 @@ __ip_vs_get_out_rt(struct ip_vs_conn *cp, u32 rtos)
82 82
83 if (ip_route_output_key(&init_net, &rt, &fl)) { 83 if (ip_route_output_key(&init_net, &rt, &fl)) {
84 spin_unlock(&dest->dst_lock); 84 spin_unlock(&dest->dst_lock);
85 IP_VS_DBG_RL("ip_route_output error, " 85 IP_VS_DBG_RL("ip_route_output error, dest: %pI4\n",
86 "dest: %u.%u.%u.%u\n", 86 &dest->addr.ip);
87 NIPQUAD(dest->addr.ip));
88 return NULL; 87 return NULL;
89 } 88 }
90 __ip_vs_dst_set(dest, rtos, dst_clone(&rt->u.dst)); 89 __ip_vs_dst_set(dest, rtos, dst_clone(&rt->u.dst));
91 IP_VS_DBG(10, "new dst %u.%u.%u.%u, refcnt=%d, rtos=%X\n", 90 IP_VS_DBG(10, "new dst %pI4, refcnt=%d, rtos=%X\n",
92 NIPQUAD(dest->addr.ip), 91 &dest->addr.ip,
93 atomic_read(&rt->u.dst.__refcnt), rtos); 92 atomic_read(&rt->u.dst.__refcnt), rtos);
94 } 93 }
95 spin_unlock(&dest->dst_lock); 94 spin_unlock(&dest->dst_lock);
@@ -104,8 +103,8 @@ __ip_vs_get_out_rt(struct ip_vs_conn *cp, u32 rtos)
104 }; 103 };
105 104
106 if (ip_route_output_key(&init_net, &rt, &fl)) { 105 if (ip_route_output_key(&init_net, &rt, &fl)) {
107 IP_VS_DBG_RL("ip_route_output error, dest: " 106 IP_VS_DBG_RL("ip_route_output error, dest: %pI4\n",
108 "%u.%u.%u.%u\n", NIPQUAD(cp->daddr.ip)); 107 &cp->daddr.ip);
109 return NULL; 108 return NULL;
110 } 109 }
111 } 110 }
@@ -141,14 +140,13 @@ __ip_vs_get_out_rt_v6(struct ip_vs_conn *cp)
141 NULL, &fl); 140 NULL, &fl);
142 if (!rt) { 141 if (!rt) {
143 spin_unlock(&dest->dst_lock); 142 spin_unlock(&dest->dst_lock);
144 IP_VS_DBG_RL("ip6_route_output error, " 143 IP_VS_DBG_RL("ip6_route_output error, dest: %pI6\n",
145 "dest: " NIP6_FMT "\n", 144 &dest->addr.in6);
146 NIP6(dest->addr.in6));
147 return NULL; 145 return NULL;
148 } 146 }
149 __ip_vs_dst_set(dest, 0, dst_clone(&rt->u.dst)); 147 __ip_vs_dst_set(dest, 0, dst_clone(&rt->u.dst));
150 IP_VS_DBG(10, "new dst " NIP6_FMT ", refcnt=%d\n", 148 IP_VS_DBG(10, "new dst %pI6, refcnt=%d\n",
151 NIP6(dest->addr.in6), 149 &dest->addr.in6,
152 atomic_read(&rt->u.dst.__refcnt)); 150 atomic_read(&rt->u.dst.__refcnt));
153 } 151 }
154 spin_unlock(&dest->dst_lock); 152 spin_unlock(&dest->dst_lock);
@@ -167,8 +165,8 @@ __ip_vs_get_out_rt_v6(struct ip_vs_conn *cp)
167 165
168 rt = (struct rt6_info *)ip6_route_output(&init_net, NULL, &fl); 166 rt = (struct rt6_info *)ip6_route_output(&init_net, NULL, &fl);
169 if (!rt) { 167 if (!rt) {
170 IP_VS_DBG_RL("ip6_route_output error, dest: " 168 IP_VS_DBG_RL("ip6_route_output error, dest: %pI6\n",
171 NIP6_FMT "\n", NIP6(cp->daddr.in6)); 169 &cp->daddr.in6);
172 return NULL; 170 return NULL;
173 } 171 }
174 } 172 }
@@ -237,8 +235,8 @@ ip_vs_bypass_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
237 EnterFunction(10); 235 EnterFunction(10);
238 236
239 if (ip_route_output_key(&init_net, &rt, &fl)) { 237 if (ip_route_output_key(&init_net, &rt, &fl)) {
240 IP_VS_DBG_RL("ip_vs_bypass_xmit(): ip_route_output error, " 238 IP_VS_DBG_RL("ip_vs_bypass_xmit(): ip_route_output error, dest: %pI4\n",
241 "dest: %u.%u.%u.%u\n", NIPQUAD(iph->daddr)); 239 &iph->daddr);
242 goto tx_error_icmp; 240 goto tx_error_icmp;
243 } 241 }
244 242
@@ -301,8 +299,8 @@ ip_vs_bypass_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
301 299
302 rt = (struct rt6_info *)ip6_route_output(&init_net, NULL, &fl); 300 rt = (struct rt6_info *)ip6_route_output(&init_net, NULL, &fl);
303 if (!rt) { 301 if (!rt) {
304 IP_VS_DBG_RL("ip_vs_bypass_xmit_v6(): ip6_route_output error, " 302 IP_VS_DBG_RL("ip_vs_bypass_xmit_v6(): ip6_route_output error, dest: %pI6\n",
305 "dest: " NIP6_FMT "\n", NIP6(iph->daddr)); 303 &iph->daddr);
306 goto tx_error_icmp; 304 goto tx_error_icmp;
307 } 305 }
308 306
diff --git a/net/netfilter/nf_conntrack_acct.c b/net/netfilter/nf_conntrack_acct.c
index b92df5c1dfcf..9fe8982bd7c9 100644
--- a/net/netfilter/nf_conntrack_acct.c
+++ b/net/netfilter/nf_conntrack_acct.c
@@ -35,7 +35,7 @@ static struct ctl_table acct_sysctl_table[] = {
35 .data = &init_net.ct.sysctl_acct, 35 .data = &init_net.ct.sysctl_acct,
36 .maxlen = sizeof(unsigned int), 36 .maxlen = sizeof(unsigned int),
37 .mode = 0644, 37 .mode = 0644,
38 .proc_handler = &proc_dointvec, 38 .proc_handler = proc_dointvec,
39 }, 39 },
40 {} 40 {}
41}; 41};
diff --git a/net/netfilter/nf_conntrack_amanda.c b/net/netfilter/nf_conntrack_amanda.c
index 38aedeeaf4e1..4f8fcf498545 100644
--- a/net/netfilter/nf_conntrack_amanda.c
+++ b/net/netfilter/nf_conntrack_amanda.c
@@ -30,6 +30,7 @@ MODULE_AUTHOR("Brian J. Murrell <netfilter@interlinx.bc.ca>");
30MODULE_DESCRIPTION("Amanda connection tracking module"); 30MODULE_DESCRIPTION("Amanda connection tracking module");
31MODULE_LICENSE("GPL"); 31MODULE_LICENSE("GPL");
32MODULE_ALIAS("ip_conntrack_amanda"); 32MODULE_ALIAS("ip_conntrack_amanda");
33MODULE_ALIAS_NFCT_HELPER("amanda");
33 34
34module_param(master_timeout, uint, 0600); 35module_param(master_timeout, uint, 0600);
35MODULE_PARM_DESC(master_timeout, "timeout for the master connection"); 36MODULE_PARM_DESC(master_timeout, "timeout for the master connection");
diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
index 233fdd2d7d21..7e83f74cd5de 100644
--- a/net/netfilter/nf_conntrack_core.c
+++ b/net/netfilter/nf_conntrack_core.c
@@ -39,13 +39,13 @@
39#include <net/netfilter/nf_conntrack_extend.h> 39#include <net/netfilter/nf_conntrack_extend.h>
40#include <net/netfilter/nf_conntrack_acct.h> 40#include <net/netfilter/nf_conntrack_acct.h>
41#include <net/netfilter/nf_nat.h> 41#include <net/netfilter/nf_nat.h>
42#include <net/netfilter/nf_nat_core.h>
42 43
43#define NF_CONNTRACK_VERSION "0.5.0" 44#define NF_CONNTRACK_VERSION "0.5.0"
44 45
45unsigned int 46int (*nfnetlink_parse_nat_setup_hook)(struct nf_conn *ct,
46(*nfnetlink_parse_nat_setup_hook)(struct nf_conn *ct, 47 enum nf_nat_manip_type manip,
47 enum nf_nat_manip_type manip, 48 struct nlattr *attr) __read_mostly;
48 struct nlattr *attr) __read_mostly;
49EXPORT_SYMBOL_GPL(nfnetlink_parse_nat_setup_hook); 49EXPORT_SYMBOL_GPL(nfnetlink_parse_nat_setup_hook);
50 50
51DEFINE_SPINLOCK(nf_conntrack_lock); 51DEFINE_SPINLOCK(nf_conntrack_lock);
@@ -181,7 +181,8 @@ destroy_conntrack(struct nf_conntrack *nfct)
181 NF_CT_ASSERT(atomic_read(&nfct->use) == 0); 181 NF_CT_ASSERT(atomic_read(&nfct->use) == 0);
182 NF_CT_ASSERT(!timer_pending(&ct->timeout)); 182 NF_CT_ASSERT(!timer_pending(&ct->timeout));
183 183
184 nf_conntrack_event(IPCT_DESTROY, ct); 184 if (!test_bit(IPS_DYING_BIT, &ct->status))
185 nf_conntrack_event(IPCT_DESTROY, ct);
185 set_bit(IPS_DYING_BIT, &ct->status); 186 set_bit(IPS_DYING_BIT, &ct->status);
186 187
187 /* To make sure we don't get any weird locking issues here: 188 /* To make sure we don't get any weird locking issues here:
@@ -586,14 +587,7 @@ init_conntrack(struct net *net,
586 nf_conntrack_get(&ct->master->ct_general); 587 nf_conntrack_get(&ct->master->ct_general);
587 NF_CT_STAT_INC(net, expect_new); 588 NF_CT_STAT_INC(net, expect_new);
588 } else { 589 } else {
589 struct nf_conntrack_helper *helper; 590 __nf_ct_try_assign_helper(ct, GFP_ATOMIC);
590
591 helper = __nf_ct_helper_find(&repl_tuple);
592 if (helper) {
593 help = nf_ct_helper_ext_add(ct, GFP_ATOMIC);
594 if (help)
595 rcu_assign_pointer(help->helper, helper);
596 }
597 NF_CT_STAT_INC(net, new); 591 NF_CT_STAT_INC(net, new);
598 } 592 }
599 593
@@ -770,7 +764,6 @@ void nf_conntrack_alter_reply(struct nf_conn *ct,
770 const struct nf_conntrack_tuple *newreply) 764 const struct nf_conntrack_tuple *newreply)
771{ 765{
772 struct nf_conn_help *help = nfct_help(ct); 766 struct nf_conn_help *help = nfct_help(ct);
773 struct nf_conntrack_helper *helper;
774 767
775 /* Should be unconfirmed, so not in hash table yet */ 768 /* Should be unconfirmed, so not in hash table yet */
776 NF_CT_ASSERT(!nf_ct_is_confirmed(ct)); 769 NF_CT_ASSERT(!nf_ct_is_confirmed(ct));
@@ -783,23 +776,7 @@ void nf_conntrack_alter_reply(struct nf_conn *ct,
783 return; 776 return;
784 777
785 rcu_read_lock(); 778 rcu_read_lock();
786 helper = __nf_ct_helper_find(newreply); 779 __nf_ct_try_assign_helper(ct, GFP_ATOMIC);
787 if (helper == NULL) {
788 if (help)
789 rcu_assign_pointer(help->helper, NULL);
790 goto out;
791 }
792
793 if (help == NULL) {
794 help = nf_ct_helper_ext_add(ct, GFP_ATOMIC);
795 if (help == NULL)
796 goto out;
797 } else {
798 memset(&help->help, 0, sizeof(help->help));
799 }
800
801 rcu_assign_pointer(help->helper, helper);
802out:
803 rcu_read_unlock(); 780 rcu_read_unlock();
804} 781}
805EXPORT_SYMBOL_GPL(nf_conntrack_alter_reply); 782EXPORT_SYMBOL_GPL(nf_conntrack_alter_reply);
@@ -994,8 +971,20 @@ void nf_ct_iterate_cleanup(struct net *net,
994} 971}
995EXPORT_SYMBOL_GPL(nf_ct_iterate_cleanup); 972EXPORT_SYMBOL_GPL(nf_ct_iterate_cleanup);
996 973
974struct __nf_ct_flush_report {
975 u32 pid;
976 int report;
977};
978
997static int kill_all(struct nf_conn *i, void *data) 979static int kill_all(struct nf_conn *i, void *data)
998{ 980{
981 struct __nf_ct_flush_report *fr = (struct __nf_ct_flush_report *)data;
982
983 /* get_next_corpse sets the dying bit for us */
984 nf_conntrack_event_report(IPCT_DESTROY,
985 i,
986 fr->pid,
987 fr->report);
999 return 1; 988 return 1;
1000} 989}
1001 990
@@ -1009,9 +998,13 @@ void nf_ct_free_hashtable(struct hlist_head *hash, int vmalloced, unsigned int s
1009} 998}
1010EXPORT_SYMBOL_GPL(nf_ct_free_hashtable); 999EXPORT_SYMBOL_GPL(nf_ct_free_hashtable);
1011 1000
1012void nf_conntrack_flush(struct net *net) 1001void nf_conntrack_flush(struct net *net, u32 pid, int report)
1013{ 1002{
1014 nf_ct_iterate_cleanup(net, kill_all, NULL); 1003 struct __nf_ct_flush_report fr = {
1004 .pid = pid,
1005 .report = report,
1006 };
1007 nf_ct_iterate_cleanup(net, kill_all, &fr);
1015} 1008}
1016EXPORT_SYMBOL_GPL(nf_conntrack_flush); 1009EXPORT_SYMBOL_GPL(nf_conntrack_flush);
1017 1010
@@ -1027,7 +1020,7 @@ static void nf_conntrack_cleanup_net(struct net *net)
1027 nf_ct_event_cache_flush(net); 1020 nf_ct_event_cache_flush(net);
1028 nf_conntrack_ecache_fini(net); 1021 nf_conntrack_ecache_fini(net);
1029 i_see_dead_people: 1022 i_see_dead_people:
1030 nf_conntrack_flush(net); 1023 nf_conntrack_flush(net, 0, 0);
1031 if (atomic_read(&net->ct.count) != 0) { 1024 if (atomic_read(&net->ct.count) != 0) {
1032 schedule(); 1025 schedule();
1033 goto i_see_dead_people; 1026 goto i_see_dead_people;
diff --git a/net/netfilter/nf_conntrack_ecache.c b/net/netfilter/nf_conntrack_ecache.c
index a5f5e2e65d13..dee4190209cc 100644
--- a/net/netfilter/nf_conntrack_ecache.c
+++ b/net/netfilter/nf_conntrack_ecache.c
@@ -35,9 +35,17 @@ static inline void
35__nf_ct_deliver_cached_events(struct nf_conntrack_ecache *ecache) 35__nf_ct_deliver_cached_events(struct nf_conntrack_ecache *ecache)
36{ 36{
37 if (nf_ct_is_confirmed(ecache->ct) && !nf_ct_is_dying(ecache->ct) 37 if (nf_ct_is_confirmed(ecache->ct) && !nf_ct_is_dying(ecache->ct)
38 && ecache->events) 38 && ecache->events) {
39 atomic_notifier_call_chain(&nf_conntrack_chain, ecache->events, 39 struct nf_ct_event item = {
40 ecache->ct); 40 .ct = ecache->ct,
41 .pid = 0,
42 .report = 0
43 };
44
45 atomic_notifier_call_chain(&nf_conntrack_chain,
46 ecache->events,
47 &item);
48 }
41 49
42 ecache->events = 0; 50 ecache->events = 0;
43 nf_ct_put(ecache->ct); 51 nf_ct_put(ecache->ct);
diff --git a/net/netfilter/nf_conntrack_expect.c b/net/netfilter/nf_conntrack_expect.c
index 37a703bc3b8e..3a8a34a6d37c 100644
--- a/net/netfilter/nf_conntrack_expect.c
+++ b/net/netfilter/nf_conntrack_expect.c
@@ -362,7 +362,7 @@ static inline int refresh_timer(struct nf_conntrack_expect *i)
362 return 1; 362 return 1;
363} 363}
364 364
365int nf_ct_expect_related(struct nf_conntrack_expect *expect) 365static inline int __nf_ct_expect_check(struct nf_conntrack_expect *expect)
366{ 366{
367 const struct nf_conntrack_expect_policy *p; 367 const struct nf_conntrack_expect_policy *p;
368 struct nf_conntrack_expect *i; 368 struct nf_conntrack_expect *i;
@@ -371,11 +371,8 @@ int nf_ct_expect_related(struct nf_conntrack_expect *expect)
371 struct net *net = nf_ct_exp_net(expect); 371 struct net *net = nf_ct_exp_net(expect);
372 struct hlist_node *n; 372 struct hlist_node *n;
373 unsigned int h; 373 unsigned int h;
374 int ret; 374 int ret = 0;
375
376 NF_CT_ASSERT(master_help);
377 375
378 spin_lock_bh(&nf_conntrack_lock);
379 if (!master_help->helper) { 376 if (!master_help->helper) {
380 ret = -ESHUTDOWN; 377 ret = -ESHUTDOWN;
381 goto out; 378 goto out;
@@ -409,18 +406,50 @@ int nf_ct_expect_related(struct nf_conntrack_expect *expect)
409 printk(KERN_WARNING 406 printk(KERN_WARNING
410 "nf_conntrack: expectation table full\n"); 407 "nf_conntrack: expectation table full\n");
411 ret = -EMFILE; 408 ret = -EMFILE;
412 goto out;
413 } 409 }
410out:
411 return ret;
412}
413
414int nf_ct_expect_related(struct nf_conntrack_expect *expect)
415{
416 int ret;
417
418 spin_lock_bh(&nf_conntrack_lock);
419 ret = __nf_ct_expect_check(expect);
420 if (ret < 0)
421 goto out;
414 422
415 nf_ct_expect_insert(expect); 423 nf_ct_expect_insert(expect);
424 atomic_inc(&expect->use);
425 spin_unlock_bh(&nf_conntrack_lock);
416 nf_ct_expect_event(IPEXP_NEW, expect); 426 nf_ct_expect_event(IPEXP_NEW, expect);
417 ret = 0; 427 nf_ct_expect_put(expect);
428 return ret;
418out: 429out:
419 spin_unlock_bh(&nf_conntrack_lock); 430 spin_unlock_bh(&nf_conntrack_lock);
420 return ret; 431 return ret;
421} 432}
422EXPORT_SYMBOL_GPL(nf_ct_expect_related); 433EXPORT_SYMBOL_GPL(nf_ct_expect_related);
423 434
435int nf_ct_expect_related_report(struct nf_conntrack_expect *expect,
436 u32 pid, int report)
437{
438 int ret;
439
440 spin_lock_bh(&nf_conntrack_lock);
441 ret = __nf_ct_expect_check(expect);
442 if (ret < 0)
443 goto out;
444 nf_ct_expect_insert(expect);
445out:
446 spin_unlock_bh(&nf_conntrack_lock);
447 if (ret == 0)
448 nf_ct_expect_event_report(IPEXP_NEW, expect, pid, report);
449 return ret;
450}
451EXPORT_SYMBOL_GPL(nf_ct_expect_related_report);
452
424#ifdef CONFIG_PROC_FS 453#ifdef CONFIG_PROC_FS
425struct ct_expect_iter_state { 454struct ct_expect_iter_state {
426 struct seq_net_private p; 455 struct seq_net_private p;
diff --git a/net/netfilter/nf_conntrack_ftp.c b/net/netfilter/nf_conntrack_ftp.c
index 4f7107107e99..00fecc385f9b 100644
--- a/net/netfilter/nf_conntrack_ftp.c
+++ b/net/netfilter/nf_conntrack_ftp.c
@@ -29,6 +29,7 @@ MODULE_LICENSE("GPL");
29MODULE_AUTHOR("Rusty Russell <rusty@rustcorp.com.au>"); 29MODULE_AUTHOR("Rusty Russell <rusty@rustcorp.com.au>");
30MODULE_DESCRIPTION("ftp connection tracking helper"); 30MODULE_DESCRIPTION("ftp connection tracking helper");
31MODULE_ALIAS("ip_conntrack_ftp"); 31MODULE_ALIAS("ip_conntrack_ftp");
32MODULE_ALIAS_NFCT_HELPER("ftp");
32 33
33/* This is slow, but it's simple. --RR */ 34/* This is slow, but it's simple. --RR */
34static char *ftp_buffer; 35static char *ftp_buffer;
@@ -357,7 +358,7 @@ static int help(struct sk_buff *skb,
357 int ret; 358 int ret;
358 u32 seq; 359 u32 seq;
359 int dir = CTINFO2DIR(ctinfo); 360 int dir = CTINFO2DIR(ctinfo);
360 unsigned int matchlen, matchoff; 361 unsigned int uninitialized_var(matchlen), uninitialized_var(matchoff);
361 struct nf_ct_ftp_master *ct_ftp_info = &nfct_help(ct)->help.ct_ftp_info; 362 struct nf_ct_ftp_master *ct_ftp_info = &nfct_help(ct)->help.ct_ftp_info;
362 struct nf_conntrack_expect *exp; 363 struct nf_conntrack_expect *exp;
363 union nf_inet_addr *daddr; 364 union nf_inet_addr *daddr;
@@ -427,10 +428,8 @@ static int help(struct sk_buff *skb,
427 connection tracking, not packet filtering. 428 connection tracking, not packet filtering.
428 However, it is necessary for accurate tracking in 429 However, it is necessary for accurate tracking in
429 this case. */ 430 this case. */
430 if (net_ratelimit()) 431 pr_debug("conntrack_ftp: partial %s %u+%u\n",
431 printk("conntrack_ftp: partial %s %u+%u\n", 432 search[dir][i].pattern, ntohl(th->seq), datalen);
432 search[dir][i].pattern,
433 ntohl(th->seq), datalen);
434 ret = NF_DROP; 433 ret = NF_DROP;
435 goto out; 434 goto out;
436 } else if (found == 0) { /* No match */ 435 } else if (found == 0) { /* No match */
@@ -462,16 +461,13 @@ static int help(struct sk_buff *skb,
462 different IP address. Simply don't record it for 461 different IP address. Simply don't record it for
463 NAT. */ 462 NAT. */
464 if (cmd.l3num == PF_INET) { 463 if (cmd.l3num == PF_INET) {
465 pr_debug("conntrack_ftp: NOT RECORDING: " NIPQUAD_FMT 464 pr_debug("conntrack_ftp: NOT RECORDING: %pI4 != %pI4\n",
466 " != " NIPQUAD_FMT "\n", 465 &cmd.u3.ip,
467 NIPQUAD(cmd.u3.ip), 466 &ct->tuplehash[dir].tuple.src.u3.ip);
468 NIPQUAD(ct->tuplehash[dir].tuple.src.u3.ip));
469 } else { 467 } else {
470 pr_debug("conntrack_ftp: NOT RECORDING: " NIP6_FMT 468 pr_debug("conntrack_ftp: NOT RECORDING: %pI6 != %pI6\n",
471 " != " NIP6_FMT "\n", 469 cmd.u3.ip6,
472 NIP6(*((struct in6_addr *)cmd.u3.ip6)), 470 ct->tuplehash[dir].tuple.src.u3.ip6);
473 NIP6(*((struct in6_addr *)
474 ct->tuplehash[dir].tuple.src.u3.ip6)));
475 } 471 }
476 472
477 /* Thanks to Cristiano Lincoln Mattos 473 /* Thanks to Cristiano Lincoln Mattos
diff --git a/net/netfilter/nf_conntrack_h323_main.c b/net/netfilter/nf_conntrack_h323_main.c
index c1504f71cdff..687bd633c3d7 100644
--- a/net/netfilter/nf_conntrack_h323_main.c
+++ b/net/netfilter/nf_conntrack_h323_main.c
@@ -850,10 +850,8 @@ static int process_setup(struct sk_buff *skb, struct nf_conn *ct,
850 get_h225_addr(ct, *data, &setup->destCallSignalAddress, 850 get_h225_addr(ct, *data, &setup->destCallSignalAddress,
851 &addr, &port) && 851 &addr, &port) &&
852 memcmp(&addr, &ct->tuplehash[!dir].tuple.src.u3, sizeof(addr))) { 852 memcmp(&addr, &ct->tuplehash[!dir].tuple.src.u3, sizeof(addr))) {
853 pr_debug("nf_ct_q931: set destCallSignalAddress " 853 pr_debug("nf_ct_q931: set destCallSignalAddress %pI6:%hu->%pI6:%hu\n",
854 NIP6_FMT ":%hu->" NIP6_FMT ":%hu\n", 854 &addr, ntohs(port), &ct->tuplehash[!dir].tuple.src.u3,
855 NIP6(*(struct in6_addr *)&addr), ntohs(port),
856 NIP6(*(struct in6_addr *)&ct->tuplehash[!dir].tuple.src.u3),
857 ntohs(ct->tuplehash[!dir].tuple.src.u.tcp.port)); 855 ntohs(ct->tuplehash[!dir].tuple.src.u.tcp.port));
858 ret = set_h225_addr(skb, data, dataoff, 856 ret = set_h225_addr(skb, data, dataoff,
859 &setup->destCallSignalAddress, 857 &setup->destCallSignalAddress,
@@ -868,10 +866,8 @@ static int process_setup(struct sk_buff *skb, struct nf_conn *ct,
868 get_h225_addr(ct, *data, &setup->sourceCallSignalAddress, 866 get_h225_addr(ct, *data, &setup->sourceCallSignalAddress,
869 &addr, &port) && 867 &addr, &port) &&
870 memcmp(&addr, &ct->tuplehash[!dir].tuple.dst.u3, sizeof(addr))) { 868 memcmp(&addr, &ct->tuplehash[!dir].tuple.dst.u3, sizeof(addr))) {
871 pr_debug("nf_ct_q931: set sourceCallSignalAddress " 869 pr_debug("nf_ct_q931: set sourceCallSignalAddress %pI6:%hu->%pI6:%hu\n",
872 NIP6_FMT ":%hu->" NIP6_FMT ":%hu\n", 870 &addr, ntohs(port), &ct->tuplehash[!dir].tuple.dst.u3,
873 NIP6(*(struct in6_addr *)&addr), ntohs(port),
874 NIP6(*(struct in6_addr *)&ct->tuplehash[!dir].tuple.dst.u3),
875 ntohs(ct->tuplehash[!dir].tuple.dst.u.tcp.port)); 871 ntohs(ct->tuplehash[!dir].tuple.dst.u.tcp.port));
876 ret = set_h225_addr(skb, data, dataoff, 872 ret = set_h225_addr(skb, data, dataoff,
877 &setup->sourceCallSignalAddress, 873 &setup->sourceCallSignalAddress,
@@ -1831,3 +1827,4 @@ MODULE_AUTHOR("Jing Min Zhao <zhaojingmin@users.sourceforge.net>");
1831MODULE_DESCRIPTION("H.323 connection tracking helper"); 1827MODULE_DESCRIPTION("H.323 connection tracking helper");
1832MODULE_LICENSE("GPL"); 1828MODULE_LICENSE("GPL");
1833MODULE_ALIAS("ip_conntrack_h323"); 1829MODULE_ALIAS("ip_conntrack_h323");
1830MODULE_ALIAS_NFCT_HELPER("h323");
diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c
index c39b6a994133..a51bdac9f3a0 100644
--- a/net/netfilter/nf_conntrack_helper.c
+++ b/net/netfilter/nf_conntrack_helper.c
@@ -45,7 +45,7 @@ static unsigned int helper_hash(const struct nf_conntrack_tuple *tuple)
45 (__force __u16)tuple->src.u.all) % nf_ct_helper_hsize; 45 (__force __u16)tuple->src.u.all) % nf_ct_helper_hsize;
46} 46}
47 47
48struct nf_conntrack_helper * 48static struct nf_conntrack_helper *
49__nf_ct_helper_find(const struct nf_conntrack_tuple *tuple) 49__nf_ct_helper_find(const struct nf_conntrack_tuple *tuple)
50{ 50{
51 struct nf_conntrack_helper *helper; 51 struct nf_conntrack_helper *helper;
@@ -63,7 +63,6 @@ __nf_ct_helper_find(const struct nf_conntrack_tuple *tuple)
63 } 63 }
64 return NULL; 64 return NULL;
65} 65}
66EXPORT_SYMBOL_GPL(__nf_ct_helper_find);
67 66
68struct nf_conntrack_helper * 67struct nf_conntrack_helper *
69__nf_conntrack_helper_find_byname(const char *name) 68__nf_conntrack_helper_find_byname(const char *name)
@@ -95,6 +94,35 @@ struct nf_conn_help *nf_ct_helper_ext_add(struct nf_conn *ct, gfp_t gfp)
95} 94}
96EXPORT_SYMBOL_GPL(nf_ct_helper_ext_add); 95EXPORT_SYMBOL_GPL(nf_ct_helper_ext_add);
97 96
97int __nf_ct_try_assign_helper(struct nf_conn *ct, gfp_t flags)
98{
99 int ret = 0;
100 struct nf_conntrack_helper *helper;
101 struct nf_conn_help *help = nfct_help(ct);
102
103 helper = __nf_ct_helper_find(&ct->tuplehash[IP_CT_DIR_REPLY].tuple);
104 if (helper == NULL) {
105 if (help)
106 rcu_assign_pointer(help->helper, NULL);
107 goto out;
108 }
109
110 if (help == NULL) {
111 help = nf_ct_helper_ext_add(ct, flags);
112 if (help == NULL) {
113 ret = -ENOMEM;
114 goto out;
115 }
116 } else {
117 memset(&help->help, 0, sizeof(help->help));
118 }
119
120 rcu_assign_pointer(help->helper, helper);
121out:
122 return ret;
123}
124EXPORT_SYMBOL_GPL(__nf_ct_try_assign_helper);
125
98static inline int unhelp(struct nf_conntrack_tuple_hash *i, 126static inline int unhelp(struct nf_conntrack_tuple_hash *i,
99 const struct nf_conntrack_helper *me) 127 const struct nf_conntrack_helper *me)
100{ 128{
diff --git a/net/netfilter/nf_conntrack_irc.c b/net/netfilter/nf_conntrack_irc.c
index 20633fdf7e6b..409c8be58e7c 100644
--- a/net/netfilter/nf_conntrack_irc.c
+++ b/net/netfilter/nf_conntrack_irc.c
@@ -41,6 +41,7 @@ MODULE_AUTHOR("Harald Welte <laforge@netfilter.org>");
41MODULE_DESCRIPTION("IRC (DCC) connection tracking helper"); 41MODULE_DESCRIPTION("IRC (DCC) connection tracking helper");
42MODULE_LICENSE("GPL"); 42MODULE_LICENSE("GPL");
43MODULE_ALIAS("ip_conntrack_irc"); 43MODULE_ALIAS("ip_conntrack_irc");
44MODULE_ALIAS_NFCT_HELPER("irc");
44 45
45module_param_array(ports, ushort, &ports_c, 0400); 46module_param_array(ports, ushort, &ports_c, 0400);
46MODULE_PARM_DESC(ports, "port numbers of IRC servers"); 47MODULE_PARM_DESC(ports, "port numbers of IRC servers");
@@ -156,9 +157,9 @@ static int help(struct sk_buff *skb, unsigned int protoff,
156 /* we have at least (19+MINMATCHLEN)-5 bytes valid data left */ 157 /* we have at least (19+MINMATCHLEN)-5 bytes valid data left */
157 158
158 iph = ip_hdr(skb); 159 iph = ip_hdr(skb);
159 pr_debug("DCC found in master %u.%u.%u.%u:%u %u.%u.%u.%u:%u\n", 160 pr_debug("DCC found in master %pI4:%u %pI4:%u\n",
160 NIPQUAD(iph->saddr), ntohs(th->source), 161 &iph->saddr, ntohs(th->source),
161 NIPQUAD(iph->daddr), ntohs(th->dest)); 162 &iph->daddr, ntohs(th->dest));
162 163
163 for (i = 0; i < ARRAY_SIZE(dccprotos); i++) { 164 for (i = 0; i < ARRAY_SIZE(dccprotos); i++) {
164 if (memcmp(data, dccprotos[i], strlen(dccprotos[i]))) { 165 if (memcmp(data, dccprotos[i], strlen(dccprotos[i]))) {
@@ -185,10 +186,9 @@ static int help(struct sk_buff *skb, unsigned int protoff,
185 tuple->dst.u3.ip != htonl(dcc_ip)) { 186 tuple->dst.u3.ip != htonl(dcc_ip)) {
186 if (net_ratelimit()) 187 if (net_ratelimit())
187 printk(KERN_WARNING 188 printk(KERN_WARNING
188 "Forged DCC command from " 189 "Forged DCC command from %pI4: %pI4:%u\n",
189 "%u.%u.%u.%u: %u.%u.%u.%u:%u\n", 190 &tuple->src.u3.ip,
190 NIPQUAD(tuple->src.u3.ip), 191 &dcc_ip, dcc_port);
191 HIPQUAD(dcc_ip), dcc_port);
192 continue; 192 continue;
193 } 193 }
194 194
diff --git a/net/netfilter/nf_conntrack_netbios_ns.c b/net/netfilter/nf_conntrack_netbios_ns.c
index 08404e6755fb..5af4273b4668 100644
--- a/net/netfilter/nf_conntrack_netbios_ns.c
+++ b/net/netfilter/nf_conntrack_netbios_ns.c
@@ -37,6 +37,7 @@ MODULE_AUTHOR("Patrick McHardy <kaber@trash.net>");
37MODULE_DESCRIPTION("NetBIOS name service broadcast connection tracking helper"); 37MODULE_DESCRIPTION("NetBIOS name service broadcast connection tracking helper");
38MODULE_LICENSE("GPL"); 38MODULE_LICENSE("GPL");
39MODULE_ALIAS("ip_conntrack_netbios_ns"); 39MODULE_ALIAS("ip_conntrack_netbios_ns");
40MODULE_ALIAS_NFCT_HELPER("netbios_ns");
40 41
41static unsigned int timeout __read_mostly = 3; 42static unsigned int timeout __read_mostly = 3;
42module_param(timeout, uint, 0400); 43module_param(timeout, uint, 0400);
diff --git a/net/netfilter/nf_conntrack_netlink.c b/net/netfilter/nf_conntrack_netlink.c
index 5f4a6516b3b6..00e8c27130ff 100644
--- a/net/netfilter/nf_conntrack_netlink.c
+++ b/net/netfilter/nf_conntrack_netlink.c
@@ -105,16 +105,14 @@ ctnetlink_dump_tuples(struct sk_buff *skb,
105 struct nf_conntrack_l3proto *l3proto; 105 struct nf_conntrack_l3proto *l3proto;
106 struct nf_conntrack_l4proto *l4proto; 106 struct nf_conntrack_l4proto *l4proto;
107 107
108 l3proto = nf_ct_l3proto_find_get(tuple->src.l3num); 108 l3proto = __nf_ct_l3proto_find(tuple->src.l3num);
109 ret = ctnetlink_dump_tuples_ip(skb, tuple, l3proto); 109 ret = ctnetlink_dump_tuples_ip(skb, tuple, l3proto);
110 nf_ct_l3proto_put(l3proto);
111 110
112 if (unlikely(ret < 0)) 111 if (unlikely(ret < 0))
113 return ret; 112 return ret;
114 113
115 l4proto = nf_ct_l4proto_find_get(tuple->src.l3num, tuple->dst.protonum); 114 l4proto = __nf_ct_l4proto_find(tuple->src.l3num, tuple->dst.protonum);
116 ret = ctnetlink_dump_tuples_proto(skb, tuple, l4proto); 115 ret = ctnetlink_dump_tuples_proto(skb, tuple, l4proto);
117 nf_ct_l4proto_put(l4proto);
118 116
119 return ret; 117 return ret;
120} 118}
@@ -151,11 +149,9 @@ ctnetlink_dump_protoinfo(struct sk_buff *skb, const struct nf_conn *ct)
151 struct nlattr *nest_proto; 149 struct nlattr *nest_proto;
152 int ret; 150 int ret;
153 151
154 l4proto = nf_ct_l4proto_find_get(nf_ct_l3num(ct), nf_ct_protonum(ct)); 152 l4proto = __nf_ct_l4proto_find(nf_ct_l3num(ct), nf_ct_protonum(ct));
155 if (!l4proto->to_nlattr) { 153 if (!l4proto->to_nlattr)
156 nf_ct_l4proto_put(l4proto);
157 return 0; 154 return 0;
158 }
159 155
160 nest_proto = nla_nest_start(skb, CTA_PROTOINFO | NLA_F_NESTED); 156 nest_proto = nla_nest_start(skb, CTA_PROTOINFO | NLA_F_NESTED);
161 if (!nest_proto) 157 if (!nest_proto)
@@ -163,14 +159,11 @@ ctnetlink_dump_protoinfo(struct sk_buff *skb, const struct nf_conn *ct)
163 159
164 ret = l4proto->to_nlattr(skb, nest_proto, ct); 160 ret = l4proto->to_nlattr(skb, nest_proto, ct);
165 161
166 nf_ct_l4proto_put(l4proto);
167
168 nla_nest_end(skb, nest_proto); 162 nla_nest_end(skb, nest_proto);
169 163
170 return ret; 164 return ret;
171 165
172nla_put_failure: 166nla_put_failure:
173 nf_ct_l4proto_put(l4proto);
174 return -1; 167 return -1;
175} 168}
176 169
@@ -184,7 +177,6 @@ ctnetlink_dump_helpinfo(struct sk_buff *skb, const struct nf_conn *ct)
184 if (!help) 177 if (!help)
185 return 0; 178 return 0;
186 179
187 rcu_read_lock();
188 helper = rcu_dereference(help->helper); 180 helper = rcu_dereference(help->helper);
189 if (!helper) 181 if (!helper)
190 goto out; 182 goto out;
@@ -199,11 +191,9 @@ ctnetlink_dump_helpinfo(struct sk_buff *skb, const struct nf_conn *ct)
199 191
200 nla_nest_end(skb, nest_helper); 192 nla_nest_end(skb, nest_helper);
201out: 193out:
202 rcu_read_unlock();
203 return 0; 194 return 0;
204 195
205nla_put_failure: 196nla_put_failure:
206 rcu_read_unlock();
207 return -1; 197 return -1;
208} 198}
209 199
@@ -420,7 +410,8 @@ static int ctnetlink_conntrack_event(struct notifier_block *this,
420 struct nlmsghdr *nlh; 410 struct nlmsghdr *nlh;
421 struct nfgenmsg *nfmsg; 411 struct nfgenmsg *nfmsg;
422 struct nlattr *nest_parms; 412 struct nlattr *nest_parms;
423 struct nf_conn *ct = (struct nf_conn *)ptr; 413 struct nf_ct_event *item = (struct nf_ct_event *)ptr;
414 struct nf_conn *ct = item->ct;
424 struct sk_buff *skb; 415 struct sk_buff *skb;
425 unsigned int type; 416 unsigned int type;
426 sk_buff_data_t b; 417 sk_buff_data_t b;
@@ -453,7 +444,7 @@ static int ctnetlink_conntrack_event(struct notifier_block *this,
453 b = skb->tail; 444 b = skb->tail;
454 445
455 type |= NFNL_SUBSYS_CTNETLINK << 8; 446 type |= NFNL_SUBSYS_CTNETLINK << 8;
456 nlh = NLMSG_PUT(skb, 0, 0, type, sizeof(struct nfgenmsg)); 447 nlh = NLMSG_PUT(skb, item->pid, 0, type, sizeof(struct nfgenmsg));
457 nfmsg = NLMSG_DATA(nlh); 448 nfmsg = NLMSG_DATA(nlh);
458 449
459 nlh->nlmsg_flags = flags; 450 nlh->nlmsg_flags = flags;
@@ -461,6 +452,7 @@ static int ctnetlink_conntrack_event(struct notifier_block *this,
461 nfmsg->version = NFNETLINK_V0; 452 nfmsg->version = NFNETLINK_V0;
462 nfmsg->res_id = 0; 453 nfmsg->res_id = 0;
463 454
455 rcu_read_lock();
464 nest_parms = nla_nest_start(skb, CTA_TUPLE_ORIG | NLA_F_NESTED); 456 nest_parms = nla_nest_start(skb, CTA_TUPLE_ORIG | NLA_F_NESTED);
465 if (!nest_parms) 457 if (!nest_parms)
466 goto nla_put_failure; 458 goto nla_put_failure;
@@ -517,13 +509,15 @@ static int ctnetlink_conntrack_event(struct notifier_block *this,
517 && ctnetlink_dump_mark(skb, ct) < 0) 509 && ctnetlink_dump_mark(skb, ct) < 0)
518 goto nla_put_failure; 510 goto nla_put_failure;
519#endif 511#endif
512 rcu_read_unlock();
520 513
521 nlh->nlmsg_len = skb->tail - b; 514 nlh->nlmsg_len = skb->tail - b;
522 nfnetlink_send(skb, 0, group, 0); 515 nfnetlink_send(skb, item->pid, group, item->report);
523 return NOTIFY_DONE; 516 return NOTIFY_DONE;
524 517
525nlmsg_failure:
526nla_put_failure: 518nla_put_failure:
519 rcu_read_unlock();
520nlmsg_failure:
527 kfree_skb(skb); 521 kfree_skb(skb);
528 return NOTIFY_DONE; 522 return NOTIFY_DONE;
529} 523}
@@ -729,7 +723,9 @@ ctnetlink_del_conntrack(struct sock *ctnl, struct sk_buff *skb,
729 err = ctnetlink_parse_tuple(cda, &tuple, CTA_TUPLE_REPLY, u3); 723 err = ctnetlink_parse_tuple(cda, &tuple, CTA_TUPLE_REPLY, u3);
730 else { 724 else {
731 /* Flush the whole table */ 725 /* Flush the whole table */
732 nf_conntrack_flush(&init_net); 726 nf_conntrack_flush(&init_net,
727 NETLINK_CB(skb).pid,
728 nlmsg_report(nlh));
733 return 0; 729 return 0;
734 } 730 }
735 731
@@ -750,6 +746,14 @@ ctnetlink_del_conntrack(struct sock *ctnl, struct sk_buff *skb,
750 } 746 }
751 } 747 }
752 748
749 nf_conntrack_event_report(IPCT_DESTROY,
750 ct,
751 NETLINK_CB(skb).pid,
752 nlmsg_report(nlh));
753
754 /* death_by_timeout would report the event again */
755 set_bit(IPS_DYING_BIT, &ct->status);
756
753 nf_ct_kill(ct); 757 nf_ct_kill(ct);
754 nf_ct_put(ct); 758 nf_ct_put(ct);
755 759
@@ -795,8 +799,10 @@ ctnetlink_get_conntrack(struct sock *ctnl, struct sk_buff *skb,
795 return -ENOMEM; 799 return -ENOMEM;
796 } 800 }
797 801
802 rcu_read_lock();
798 err = ctnetlink_fill_info(skb2, NETLINK_CB(skb).pid, nlh->nlmsg_seq, 803 err = ctnetlink_fill_info(skb2, NETLINK_CB(skb).pid, nlh->nlmsg_seq,
799 IPCTNL_MSG_CT_NEW, 1, ct); 804 IPCTNL_MSG_CT_NEW, 1, ct);
805 rcu_read_unlock();
800 nf_ct_put(ct); 806 nf_ct_put(ct);
801 if (err <= 0) 807 if (err <= 0)
802 goto free; 808 goto free;
@@ -922,8 +928,22 @@ ctnetlink_change_helper(struct nf_conn *ct, struct nlattr *cda[])
922 } 928 }
923 929
924 helper = __nf_conntrack_helper_find_byname(helpname); 930 helper = __nf_conntrack_helper_find_byname(helpname);
925 if (helper == NULL) 931 if (helper == NULL) {
932#ifdef CONFIG_MODULES
933 spin_unlock_bh(&nf_conntrack_lock);
934
935 if (request_module("nfct-helper-%s", helpname) < 0) {
936 spin_lock_bh(&nf_conntrack_lock);
937 return -EOPNOTSUPP;
938 }
939
940 spin_lock_bh(&nf_conntrack_lock);
941 helper = __nf_conntrack_helper_find_byname(helpname);
942 if (helper)
943 return -EAGAIN;
944#endif
926 return -EOPNOTSUPP; 945 return -EOPNOTSUPP;
946 }
927 947
928 if (help) { 948 if (help) {
929 if (help->helper == helper) 949 if (help->helper == helper)
@@ -1079,15 +1099,38 @@ ctnetlink_change_conntrack(struct nf_conn *ct, struct nlattr *cda[])
1079 return 0; 1099 return 0;
1080} 1100}
1081 1101
1102static inline void
1103ctnetlink_event_report(struct nf_conn *ct, u32 pid, int report)
1104{
1105 unsigned int events = 0;
1106
1107 if (test_bit(IPS_EXPECTED_BIT, &ct->status))
1108 events |= IPCT_RELATED;
1109 else
1110 events |= IPCT_NEW;
1111
1112 nf_conntrack_event_report(IPCT_STATUS |
1113 IPCT_HELPER |
1114 IPCT_REFRESH |
1115 IPCT_PROTOINFO |
1116 IPCT_NATSEQADJ |
1117 IPCT_MARK |
1118 events,
1119 ct,
1120 pid,
1121 report);
1122}
1123
1082static int 1124static int
1083ctnetlink_create_conntrack(struct nlattr *cda[], 1125ctnetlink_create_conntrack(struct nlattr *cda[],
1084 struct nf_conntrack_tuple *otuple, 1126 struct nf_conntrack_tuple *otuple,
1085 struct nf_conntrack_tuple *rtuple, 1127 struct nf_conntrack_tuple *rtuple,
1086 struct nf_conn *master_ct) 1128 struct nf_conn *master_ct,
1129 u32 pid,
1130 int report)
1087{ 1131{
1088 struct nf_conn *ct; 1132 struct nf_conn *ct;
1089 int err = -EINVAL; 1133 int err = -EINVAL;
1090 struct nf_conn_help *help;
1091 struct nf_conntrack_helper *helper; 1134 struct nf_conntrack_helper *helper;
1092 1135
1093 ct = nf_conntrack_alloc(&init_net, otuple, rtuple, GFP_ATOMIC); 1136 ct = nf_conntrack_alloc(&init_net, otuple, rtuple, GFP_ATOMIC);
@@ -1102,16 +1145,55 @@ ctnetlink_create_conntrack(struct nlattr *cda[],
1102 ct->status |= IPS_CONFIRMED; 1145 ct->status |= IPS_CONFIRMED;
1103 1146
1104 rcu_read_lock(); 1147 rcu_read_lock();
1105 helper = __nf_ct_helper_find(rtuple); 1148 if (cda[CTA_HELP]) {
1106 if (helper) { 1149 char *helpname;
1107 help = nf_ct_helper_ext_add(ct, GFP_ATOMIC); 1150
1108 if (help == NULL) { 1151 err = ctnetlink_parse_help(cda[CTA_HELP], &helpname);
1152 if (err < 0) {
1153 rcu_read_unlock();
1154 goto err;
1155 }
1156
1157 helper = __nf_conntrack_helper_find_byname(helpname);
1158 if (helper == NULL) {
1159 rcu_read_unlock();
1160#ifdef CONFIG_MODULES
1161 if (request_module("nfct-helper-%s", helpname) < 0) {
1162 err = -EOPNOTSUPP;
1163 goto err;
1164 }
1165
1166 rcu_read_lock();
1167 helper = __nf_conntrack_helper_find_byname(helpname);
1168 if (helper) {
1169 rcu_read_unlock();
1170 err = -EAGAIN;
1171 goto err;
1172 }
1173 rcu_read_unlock();
1174#endif
1175 err = -EOPNOTSUPP;
1176 goto err;
1177 } else {
1178 struct nf_conn_help *help;
1179
1180 help = nf_ct_helper_ext_add(ct, GFP_ATOMIC);
1181 if (help == NULL) {
1182 rcu_read_unlock();
1183 err = -ENOMEM;
1184 goto err;
1185 }
1186
1187 /* not in hash table yet so not strictly necessary */
1188 rcu_assign_pointer(help->helper, helper);
1189 }
1190 } else {
1191 /* try an implicit helper assignation */
1192 err = __nf_ct_try_assign_helper(ct, GFP_ATOMIC);
1193 if (err < 0) {
1109 rcu_read_unlock(); 1194 rcu_read_unlock();
1110 err = -ENOMEM;
1111 goto err; 1195 goto err;
1112 } 1196 }
1113 /* not in hash table yet so not strictly necessary */
1114 rcu_assign_pointer(help->helper, helper);
1115 } 1197 }
1116 1198
1117 if (cda[CTA_STATUS]) { 1199 if (cda[CTA_STATUS]) {
@@ -1151,9 +1233,12 @@ ctnetlink_create_conntrack(struct nlattr *cda[],
1151 ct->master = master_ct; 1233 ct->master = master_ct;
1152 } 1234 }
1153 1235
1236 nf_conntrack_get(&ct->ct_general);
1154 add_timer(&ct->timeout); 1237 add_timer(&ct->timeout);
1155 nf_conntrack_hash_insert(ct); 1238 nf_conntrack_hash_insert(ct);
1156 rcu_read_unlock(); 1239 rcu_read_unlock();
1240 ctnetlink_event_report(ct, pid, report);
1241 nf_ct_put(ct);
1157 1242
1158 return 0; 1243 return 0;
1159 1244
@@ -1209,7 +1294,7 @@ ctnetlink_new_conntrack(struct sock *ctnl, struct sk_buff *skb,
1209 goto out_unlock; 1294 goto out_unlock;
1210 } 1295 }
1211 master_ct = nf_ct_tuplehash_to_ctrack(master_h); 1296 master_ct = nf_ct_tuplehash_to_ctrack(master_h);
1212 atomic_inc(&master_ct->ct_general.use); 1297 nf_conntrack_get(&master_ct->ct_general);
1213 } 1298 }
1214 1299
1215 err = -ENOENT; 1300 err = -ENOENT;
@@ -1217,9 +1302,10 @@ ctnetlink_new_conntrack(struct sock *ctnl, struct sk_buff *skb,
1217 err = ctnetlink_create_conntrack(cda, 1302 err = ctnetlink_create_conntrack(cda,
1218 &otuple, 1303 &otuple,
1219 &rtuple, 1304 &rtuple,
1220 master_ct); 1305 master_ct,
1306 NETLINK_CB(skb).pid,
1307 nlmsg_report(nlh));
1221 spin_unlock_bh(&nf_conntrack_lock); 1308 spin_unlock_bh(&nf_conntrack_lock);
1222
1223 if (err < 0 && master_ct) 1309 if (err < 0 && master_ct)
1224 nf_ct_put(master_ct); 1310 nf_ct_put(master_ct);
1225 1311
@@ -1231,6 +1317,8 @@ ctnetlink_new_conntrack(struct sock *ctnl, struct sk_buff *skb,
1231 * so there's no need to increase the refcount */ 1317 * so there's no need to increase the refcount */
1232 err = -EEXIST; 1318 err = -EEXIST;
1233 if (!(nlh->nlmsg_flags & NLM_F_EXCL)) { 1319 if (!(nlh->nlmsg_flags & NLM_F_EXCL)) {
1320 struct nf_conn *ct = nf_ct_tuplehash_to_ctrack(h);
1321
1234 /* we only allow nat config for new conntracks */ 1322 /* we only allow nat config for new conntracks */
1235 if (cda[CTA_NAT_SRC] || cda[CTA_NAT_DST]) { 1323 if (cda[CTA_NAT_SRC] || cda[CTA_NAT_DST]) {
1236 err = -EOPNOTSUPP; 1324 err = -EOPNOTSUPP;
@@ -1241,8 +1329,19 @@ ctnetlink_new_conntrack(struct sock *ctnl, struct sk_buff *skb,
1241 err = -EOPNOTSUPP; 1329 err = -EOPNOTSUPP;
1242 goto out_unlock; 1330 goto out_unlock;
1243 } 1331 }
1244 err = ctnetlink_change_conntrack(nf_ct_tuplehash_to_ctrack(h), 1332
1245 cda); 1333 err = ctnetlink_change_conntrack(ct, cda);
1334 if (err == 0) {
1335 nf_conntrack_get(&ct->ct_general);
1336 spin_unlock_bh(&nf_conntrack_lock);
1337 ctnetlink_event_report(ct,
1338 NETLINK_CB(skb).pid,
1339 nlmsg_report(nlh));
1340 nf_ct_put(ct);
1341 } else
1342 spin_unlock_bh(&nf_conntrack_lock);
1343
1344 return err;
1246 } 1345 }
1247 1346
1248out_unlock: 1347out_unlock:
@@ -1293,16 +1392,14 @@ ctnetlink_exp_dump_mask(struct sk_buff *skb,
1293 if (!nest_parms) 1392 if (!nest_parms)
1294 goto nla_put_failure; 1393 goto nla_put_failure;
1295 1394
1296 l3proto = nf_ct_l3proto_find_get(tuple->src.l3num); 1395 l3proto = __nf_ct_l3proto_find(tuple->src.l3num);
1297 ret = ctnetlink_dump_tuples_ip(skb, &m, l3proto); 1396 ret = ctnetlink_dump_tuples_ip(skb, &m, l3proto);
1298 nf_ct_l3proto_put(l3proto);
1299 1397
1300 if (unlikely(ret < 0)) 1398 if (unlikely(ret < 0))
1301 goto nla_put_failure; 1399 goto nla_put_failure;
1302 1400
1303 l4proto = nf_ct_l4proto_find_get(tuple->src.l3num, tuple->dst.protonum); 1401 l4proto = __nf_ct_l4proto_find(tuple->src.l3num, tuple->dst.protonum);
1304 ret = ctnetlink_dump_tuples_proto(skb, &m, l4proto); 1402 ret = ctnetlink_dump_tuples_proto(skb, &m, l4proto);
1305 nf_ct_l4proto_put(l4proto);
1306 if (unlikely(ret < 0)) 1403 if (unlikely(ret < 0))
1307 goto nla_put_failure; 1404 goto nla_put_failure;
1308 1405
@@ -1379,7 +1476,8 @@ static int ctnetlink_expect_event(struct notifier_block *this,
1379{ 1476{
1380 struct nlmsghdr *nlh; 1477 struct nlmsghdr *nlh;
1381 struct nfgenmsg *nfmsg; 1478 struct nfgenmsg *nfmsg;
1382 struct nf_conntrack_expect *exp = (struct nf_conntrack_expect *)ptr; 1479 struct nf_exp_event *item = (struct nf_exp_event *)ptr;
1480 struct nf_conntrack_expect *exp = item->exp;
1383 struct sk_buff *skb; 1481 struct sk_buff *skb;
1384 unsigned int type; 1482 unsigned int type;
1385 sk_buff_data_t b; 1483 sk_buff_data_t b;
@@ -1401,7 +1499,7 @@ static int ctnetlink_expect_event(struct notifier_block *this,
1401 b = skb->tail; 1499 b = skb->tail;
1402 1500
1403 type |= NFNL_SUBSYS_CTNETLINK_EXP << 8; 1501 type |= NFNL_SUBSYS_CTNETLINK_EXP << 8;
1404 nlh = NLMSG_PUT(skb, 0, 0, type, sizeof(struct nfgenmsg)); 1502 nlh = NLMSG_PUT(skb, item->pid, 0, type, sizeof(struct nfgenmsg));
1405 nfmsg = NLMSG_DATA(nlh); 1503 nfmsg = NLMSG_DATA(nlh);
1406 1504
1407 nlh->nlmsg_flags = flags; 1505 nlh->nlmsg_flags = flags;
@@ -1409,15 +1507,18 @@ static int ctnetlink_expect_event(struct notifier_block *this,
1409 nfmsg->version = NFNETLINK_V0; 1507 nfmsg->version = NFNETLINK_V0;
1410 nfmsg->res_id = 0; 1508 nfmsg->res_id = 0;
1411 1509
1510 rcu_read_lock();
1412 if (ctnetlink_exp_dump_expect(skb, exp) < 0) 1511 if (ctnetlink_exp_dump_expect(skb, exp) < 0)
1413 goto nla_put_failure; 1512 goto nla_put_failure;
1513 rcu_read_unlock();
1414 1514
1415 nlh->nlmsg_len = skb->tail - b; 1515 nlh->nlmsg_len = skb->tail - b;
1416 nfnetlink_send(skb, 0, NFNLGRP_CONNTRACK_EXP_NEW, 0); 1516 nfnetlink_send(skb, item->pid, NFNLGRP_CONNTRACK_EXP_NEW, item->report);
1417 return NOTIFY_DONE; 1517 return NOTIFY_DONE;
1418 1518
1419nlmsg_failure:
1420nla_put_failure: 1519nla_put_failure:
1520 rcu_read_unlock();
1521nlmsg_failure:
1421 kfree_skb(skb); 1522 kfree_skb(skb);
1422 return NOTIFY_DONE; 1523 return NOTIFY_DONE;
1423} 1524}
@@ -1521,9 +1622,11 @@ ctnetlink_get_expect(struct sock *ctnl, struct sk_buff *skb,
1521 if (!skb2) 1622 if (!skb2)
1522 goto out; 1623 goto out;
1523 1624
1625 rcu_read_lock();
1524 err = ctnetlink_exp_fill_info(skb2, NETLINK_CB(skb).pid, 1626 err = ctnetlink_exp_fill_info(skb2, NETLINK_CB(skb).pid,
1525 nlh->nlmsg_seq, IPCTNL_MSG_EXP_NEW, 1627 nlh->nlmsg_seq, IPCTNL_MSG_EXP_NEW,
1526 1, exp); 1628 1, exp);
1629 rcu_read_unlock();
1527 if (err <= 0) 1630 if (err <= 0)
1528 goto free; 1631 goto free;
1529 1632
@@ -1624,7 +1727,7 @@ ctnetlink_change_expect(struct nf_conntrack_expect *x, struct nlattr *cda[])
1624} 1727}
1625 1728
1626static int 1729static int
1627ctnetlink_create_expect(struct nlattr *cda[], u_int8_t u3) 1730ctnetlink_create_expect(struct nlattr *cda[], u_int8_t u3, u32 pid, int report)
1628{ 1731{
1629 struct nf_conntrack_tuple tuple, mask, master_tuple; 1732 struct nf_conntrack_tuple tuple, mask, master_tuple;
1630 struct nf_conntrack_tuple_hash *h = NULL; 1733 struct nf_conntrack_tuple_hash *h = NULL;
@@ -1653,7 +1756,7 @@ ctnetlink_create_expect(struct nlattr *cda[], u_int8_t u3)
1653 1756
1654 if (!help || !help->helper) { 1757 if (!help || !help->helper) {
1655 /* such conntrack hasn't got any helper, abort */ 1758 /* such conntrack hasn't got any helper, abort */
1656 err = -EINVAL; 1759 err = -EOPNOTSUPP;
1657 goto out; 1760 goto out;
1658 } 1761 }
1659 1762
@@ -1671,7 +1774,7 @@ ctnetlink_create_expect(struct nlattr *cda[], u_int8_t u3)
1671 memcpy(&exp->mask.src.u3, &mask.src.u3, sizeof(exp->mask.src.u3)); 1774 memcpy(&exp->mask.src.u3, &mask.src.u3, sizeof(exp->mask.src.u3));
1672 exp->mask.src.u.all = mask.src.u.all; 1775 exp->mask.src.u.all = mask.src.u.all;
1673 1776
1674 err = nf_ct_expect_related(exp); 1777 err = nf_ct_expect_related_report(exp, pid, report);
1675 nf_ct_expect_put(exp); 1778 nf_ct_expect_put(exp);
1676 1779
1677out: 1780out:
@@ -1704,8 +1807,12 @@ ctnetlink_new_expect(struct sock *ctnl, struct sk_buff *skb,
1704 if (!exp) { 1807 if (!exp) {
1705 spin_unlock_bh(&nf_conntrack_lock); 1808 spin_unlock_bh(&nf_conntrack_lock);
1706 err = -ENOENT; 1809 err = -ENOENT;
1707 if (nlh->nlmsg_flags & NLM_F_CREATE) 1810 if (nlh->nlmsg_flags & NLM_F_CREATE) {
1708 err = ctnetlink_create_expect(cda, u3); 1811 err = ctnetlink_create_expect(cda,
1812 u3,
1813 NETLINK_CB(skb).pid,
1814 nlmsg_report(nlh));
1815 }
1709 return err; 1816 return err;
1710 } 1817 }
1711 1818
diff --git a/net/netfilter/nf_conntrack_pptp.c b/net/netfilter/nf_conntrack_pptp.c
index 1bc3001d1827..9e169ef2e854 100644
--- a/net/netfilter/nf_conntrack_pptp.c
+++ b/net/netfilter/nf_conntrack_pptp.c
@@ -37,6 +37,7 @@ MODULE_LICENSE("GPL");
37MODULE_AUTHOR("Harald Welte <laforge@gnumonks.org>"); 37MODULE_AUTHOR("Harald Welte <laforge@gnumonks.org>");
38MODULE_DESCRIPTION("Netfilter connection tracking helper module for PPTP"); 38MODULE_DESCRIPTION("Netfilter connection tracking helper module for PPTP");
39MODULE_ALIAS("ip_conntrack_pptp"); 39MODULE_ALIAS("ip_conntrack_pptp");
40MODULE_ALIAS_NFCT_HELPER("pptp");
40 41
41static DEFINE_SPINLOCK(nf_pptp_lock); 42static DEFINE_SPINLOCK(nf_pptp_lock);
42 43
diff --git a/net/netfilter/nf_conntrack_proto_generic.c b/net/netfilter/nf_conntrack_proto_generic.c
index dbe680af85d2..4be80d7b8795 100644
--- a/net/netfilter/nf_conntrack_proto_generic.c
+++ b/net/netfilter/nf_conntrack_proto_generic.c
@@ -67,7 +67,7 @@ static struct ctl_table generic_sysctl_table[] = {
67 .data = &nf_ct_generic_timeout, 67 .data = &nf_ct_generic_timeout,
68 .maxlen = sizeof(unsigned int), 68 .maxlen = sizeof(unsigned int),
69 .mode = 0644, 69 .mode = 0644,
70 .proc_handler = &proc_dointvec_jiffies, 70 .proc_handler = proc_dointvec_jiffies,
71 }, 71 },
72 { 72 {
73 .ctl_name = 0 73 .ctl_name = 0
@@ -80,7 +80,7 @@ static struct ctl_table generic_compat_sysctl_table[] = {
80 .data = &nf_ct_generic_timeout, 80 .data = &nf_ct_generic_timeout,
81 .maxlen = sizeof(unsigned int), 81 .maxlen = sizeof(unsigned int),
82 .mode = 0644, 82 .mode = 0644,
83 .proc_handler = &proc_dointvec_jiffies, 83 .proc_handler = proc_dointvec_jiffies,
84 }, 84 },
85 { 85 {
86 .ctl_name = 0 86 .ctl_name = 0
diff --git a/net/netfilter/nf_conntrack_proto_gre.c b/net/netfilter/nf_conntrack_proto_gre.c
index 4ab62ad85dd4..1b279f9d6bf3 100644
--- a/net/netfilter/nf_conntrack_proto_gre.c
+++ b/net/netfilter/nf_conntrack_proto_gre.c
@@ -341,7 +341,7 @@ static int __init nf_ct_proto_gre_init(void)
341 return rv; 341 return rv;
342} 342}
343 343
344static void nf_ct_proto_gre_fini(void) 344static void __exit nf_ct_proto_gre_fini(void)
345{ 345{
346 nf_conntrack_l4proto_unregister(&nf_conntrack_l4proto_gre4); 346 nf_conntrack_l4proto_unregister(&nf_conntrack_l4proto_gre4);
347 unregister_pernet_gen_subsys(proto_gre_net_id, &proto_gre_net_ops); 347 unregister_pernet_gen_subsys(proto_gre_net_id, &proto_gre_net_ops);
diff --git a/net/netfilter/nf_conntrack_proto_sctp.c b/net/netfilter/nf_conntrack_proto_sctp.c
index ae8c2609e230..74e037901199 100644
--- a/net/netfilter/nf_conntrack_proto_sctp.c
+++ b/net/netfilter/nf_conntrack_proto_sctp.c
@@ -317,7 +317,7 @@ static int sctp_packet(struct nf_conn *ct,
317 goto out; 317 goto out;
318 } 318 }
319 319
320 old_state = new_state = SCTP_CONNTRACK_MAX; 320 old_state = new_state = SCTP_CONNTRACK_NONE;
321 write_lock_bh(&sctp_lock); 321 write_lock_bh(&sctp_lock);
322 for_each_sctp_chunk (skb, sch, _sch, offset, dataoff, count) { 322 for_each_sctp_chunk (skb, sch, _sch, offset, dataoff, count) {
323 /* Special cases of Verification tag check (Sec 8.5.1) */ 323 /* Special cases of Verification tag check (Sec 8.5.1) */
@@ -548,49 +548,49 @@ static struct ctl_table sctp_sysctl_table[] = {
548 .data = &sctp_timeouts[SCTP_CONNTRACK_CLOSED], 548 .data = &sctp_timeouts[SCTP_CONNTRACK_CLOSED],
549 .maxlen = sizeof(unsigned int), 549 .maxlen = sizeof(unsigned int),
550 .mode = 0644, 550 .mode = 0644,
551 .proc_handler = &proc_dointvec_jiffies, 551 .proc_handler = proc_dointvec_jiffies,
552 }, 552 },
553 { 553 {
554 .procname = "nf_conntrack_sctp_timeout_cookie_wait", 554 .procname = "nf_conntrack_sctp_timeout_cookie_wait",
555 .data = &sctp_timeouts[SCTP_CONNTRACK_COOKIE_WAIT], 555 .data = &sctp_timeouts[SCTP_CONNTRACK_COOKIE_WAIT],
556 .maxlen = sizeof(unsigned int), 556 .maxlen = sizeof(unsigned int),
557 .mode = 0644, 557 .mode = 0644,
558 .proc_handler = &proc_dointvec_jiffies, 558 .proc_handler = proc_dointvec_jiffies,
559 }, 559 },
560 { 560 {
561 .procname = "nf_conntrack_sctp_timeout_cookie_echoed", 561 .procname = "nf_conntrack_sctp_timeout_cookie_echoed",
562 .data = &sctp_timeouts[SCTP_CONNTRACK_COOKIE_ECHOED], 562 .data = &sctp_timeouts[SCTP_CONNTRACK_COOKIE_ECHOED],
563 .maxlen = sizeof(unsigned int), 563 .maxlen = sizeof(unsigned int),
564 .mode = 0644, 564 .mode = 0644,
565 .proc_handler = &proc_dointvec_jiffies, 565 .proc_handler = proc_dointvec_jiffies,
566 }, 566 },
567 { 567 {
568 .procname = "nf_conntrack_sctp_timeout_established", 568 .procname = "nf_conntrack_sctp_timeout_established",
569 .data = &sctp_timeouts[SCTP_CONNTRACK_ESTABLISHED], 569 .data = &sctp_timeouts[SCTP_CONNTRACK_ESTABLISHED],
570 .maxlen = sizeof(unsigned int), 570 .maxlen = sizeof(unsigned int),
571 .mode = 0644, 571 .mode = 0644,
572 .proc_handler = &proc_dointvec_jiffies, 572 .proc_handler = proc_dointvec_jiffies,
573 }, 573 },
574 { 574 {
575 .procname = "nf_conntrack_sctp_timeout_shutdown_sent", 575 .procname = "nf_conntrack_sctp_timeout_shutdown_sent",
576 .data = &sctp_timeouts[SCTP_CONNTRACK_SHUTDOWN_SENT], 576 .data = &sctp_timeouts[SCTP_CONNTRACK_SHUTDOWN_SENT],
577 .maxlen = sizeof(unsigned int), 577 .maxlen = sizeof(unsigned int),
578 .mode = 0644, 578 .mode = 0644,
579 .proc_handler = &proc_dointvec_jiffies, 579 .proc_handler = proc_dointvec_jiffies,
580 }, 580 },
581 { 581 {
582 .procname = "nf_conntrack_sctp_timeout_shutdown_recd", 582 .procname = "nf_conntrack_sctp_timeout_shutdown_recd",
583 .data = &sctp_timeouts[SCTP_CONNTRACK_SHUTDOWN_RECD], 583 .data = &sctp_timeouts[SCTP_CONNTRACK_SHUTDOWN_RECD],
584 .maxlen = sizeof(unsigned int), 584 .maxlen = sizeof(unsigned int),
585 .mode = 0644, 585 .mode = 0644,
586 .proc_handler = &proc_dointvec_jiffies, 586 .proc_handler = proc_dointvec_jiffies,
587 }, 587 },
588 { 588 {
589 .procname = "nf_conntrack_sctp_timeout_shutdown_ack_sent", 589 .procname = "nf_conntrack_sctp_timeout_shutdown_ack_sent",
590 .data = &sctp_timeouts[SCTP_CONNTRACK_SHUTDOWN_ACK_SENT], 590 .data = &sctp_timeouts[SCTP_CONNTRACK_SHUTDOWN_ACK_SENT],
591 .maxlen = sizeof(unsigned int), 591 .maxlen = sizeof(unsigned int),
592 .mode = 0644, 592 .mode = 0644,
593 .proc_handler = &proc_dointvec_jiffies, 593 .proc_handler = proc_dointvec_jiffies,
594 }, 594 },
595 { 595 {
596 .ctl_name = 0 596 .ctl_name = 0
@@ -604,49 +604,49 @@ static struct ctl_table sctp_compat_sysctl_table[] = {
604 .data = &sctp_timeouts[SCTP_CONNTRACK_CLOSED], 604 .data = &sctp_timeouts[SCTP_CONNTRACK_CLOSED],
605 .maxlen = sizeof(unsigned int), 605 .maxlen = sizeof(unsigned int),
606 .mode = 0644, 606 .mode = 0644,
607 .proc_handler = &proc_dointvec_jiffies, 607 .proc_handler = proc_dointvec_jiffies,
608 }, 608 },
609 { 609 {
610 .procname = "ip_conntrack_sctp_timeout_cookie_wait", 610 .procname = "ip_conntrack_sctp_timeout_cookie_wait",
611 .data = &sctp_timeouts[SCTP_CONNTRACK_COOKIE_WAIT], 611 .data = &sctp_timeouts[SCTP_CONNTRACK_COOKIE_WAIT],
612 .maxlen = sizeof(unsigned int), 612 .maxlen = sizeof(unsigned int),
613 .mode = 0644, 613 .mode = 0644,
614 .proc_handler = &proc_dointvec_jiffies, 614 .proc_handler = proc_dointvec_jiffies,
615 }, 615 },
616 { 616 {
617 .procname = "ip_conntrack_sctp_timeout_cookie_echoed", 617 .procname = "ip_conntrack_sctp_timeout_cookie_echoed",
618 .data = &sctp_timeouts[SCTP_CONNTRACK_COOKIE_ECHOED], 618 .data = &sctp_timeouts[SCTP_CONNTRACK_COOKIE_ECHOED],
619 .maxlen = sizeof(unsigned int), 619 .maxlen = sizeof(unsigned int),
620 .mode = 0644, 620 .mode = 0644,
621 .proc_handler = &proc_dointvec_jiffies, 621 .proc_handler = proc_dointvec_jiffies,
622 }, 622 },
623 { 623 {
624 .procname = "ip_conntrack_sctp_timeout_established", 624 .procname = "ip_conntrack_sctp_timeout_established",
625 .data = &sctp_timeouts[SCTP_CONNTRACK_ESTABLISHED], 625 .data = &sctp_timeouts[SCTP_CONNTRACK_ESTABLISHED],
626 .maxlen = sizeof(unsigned int), 626 .maxlen = sizeof(unsigned int),
627 .mode = 0644, 627 .mode = 0644,
628 .proc_handler = &proc_dointvec_jiffies, 628 .proc_handler = proc_dointvec_jiffies,
629 }, 629 },
630 { 630 {
631 .procname = "ip_conntrack_sctp_timeout_shutdown_sent", 631 .procname = "ip_conntrack_sctp_timeout_shutdown_sent",
632 .data = &sctp_timeouts[SCTP_CONNTRACK_SHUTDOWN_SENT], 632 .data = &sctp_timeouts[SCTP_CONNTRACK_SHUTDOWN_SENT],
633 .maxlen = sizeof(unsigned int), 633 .maxlen = sizeof(unsigned int),
634 .mode = 0644, 634 .mode = 0644,
635 .proc_handler = &proc_dointvec_jiffies, 635 .proc_handler = proc_dointvec_jiffies,
636 }, 636 },
637 { 637 {
638 .procname = "ip_conntrack_sctp_timeout_shutdown_recd", 638 .procname = "ip_conntrack_sctp_timeout_shutdown_recd",
639 .data = &sctp_timeouts[SCTP_CONNTRACK_SHUTDOWN_RECD], 639 .data = &sctp_timeouts[SCTP_CONNTRACK_SHUTDOWN_RECD],
640 .maxlen = sizeof(unsigned int), 640 .maxlen = sizeof(unsigned int),
641 .mode = 0644, 641 .mode = 0644,
642 .proc_handler = &proc_dointvec_jiffies, 642 .proc_handler = proc_dointvec_jiffies,
643 }, 643 },
644 { 644 {
645 .procname = "ip_conntrack_sctp_timeout_shutdown_ack_sent", 645 .procname = "ip_conntrack_sctp_timeout_shutdown_ack_sent",
646 .data = &sctp_timeouts[SCTP_CONNTRACK_SHUTDOWN_ACK_SENT], 646 .data = &sctp_timeouts[SCTP_CONNTRACK_SHUTDOWN_ACK_SENT],
647 .maxlen = sizeof(unsigned int), 647 .maxlen = sizeof(unsigned int),
648 .mode = 0644, 648 .mode = 0644,
649 .proc_handler = &proc_dointvec_jiffies, 649 .proc_handler = proc_dointvec_jiffies,
650 }, 650 },
651 { 651 {
652 .ctl_name = 0 652 .ctl_name = 0
diff --git a/net/netfilter/nf_conntrack_proto_tcp.c b/net/netfilter/nf_conntrack_proto_tcp.c
index f947ec41e391..a1edb9c1adee 100644
--- a/net/netfilter/nf_conntrack_proto_tcp.c
+++ b/net/netfilter/nf_conntrack_proto_tcp.c
@@ -1192,70 +1192,70 @@ static struct ctl_table tcp_sysctl_table[] = {
1192 .data = &tcp_timeouts[TCP_CONNTRACK_SYN_SENT], 1192 .data = &tcp_timeouts[TCP_CONNTRACK_SYN_SENT],
1193 .maxlen = sizeof(unsigned int), 1193 .maxlen = sizeof(unsigned int),
1194 .mode = 0644, 1194 .mode = 0644,
1195 .proc_handler = &proc_dointvec_jiffies, 1195 .proc_handler = proc_dointvec_jiffies,
1196 }, 1196 },
1197 { 1197 {
1198 .procname = "nf_conntrack_tcp_timeout_syn_recv", 1198 .procname = "nf_conntrack_tcp_timeout_syn_recv",
1199 .data = &tcp_timeouts[TCP_CONNTRACK_SYN_RECV], 1199 .data = &tcp_timeouts[TCP_CONNTRACK_SYN_RECV],
1200 .maxlen = sizeof(unsigned int), 1200 .maxlen = sizeof(unsigned int),
1201 .mode = 0644, 1201 .mode = 0644,
1202 .proc_handler = &proc_dointvec_jiffies, 1202 .proc_handler = proc_dointvec_jiffies,
1203 }, 1203 },
1204 { 1204 {
1205 .procname = "nf_conntrack_tcp_timeout_established", 1205 .procname = "nf_conntrack_tcp_timeout_established",
1206 .data = &tcp_timeouts[TCP_CONNTRACK_ESTABLISHED], 1206 .data = &tcp_timeouts[TCP_CONNTRACK_ESTABLISHED],
1207 .maxlen = sizeof(unsigned int), 1207 .maxlen = sizeof(unsigned int),
1208 .mode = 0644, 1208 .mode = 0644,
1209 .proc_handler = &proc_dointvec_jiffies, 1209 .proc_handler = proc_dointvec_jiffies,
1210 }, 1210 },
1211 { 1211 {
1212 .procname = "nf_conntrack_tcp_timeout_fin_wait", 1212 .procname = "nf_conntrack_tcp_timeout_fin_wait",
1213 .data = &tcp_timeouts[TCP_CONNTRACK_FIN_WAIT], 1213 .data = &tcp_timeouts[TCP_CONNTRACK_FIN_WAIT],
1214 .maxlen = sizeof(unsigned int), 1214 .maxlen = sizeof(unsigned int),
1215 .mode = 0644, 1215 .mode = 0644,
1216 .proc_handler = &proc_dointvec_jiffies, 1216 .proc_handler = proc_dointvec_jiffies,
1217 }, 1217 },
1218 { 1218 {
1219 .procname = "nf_conntrack_tcp_timeout_close_wait", 1219 .procname = "nf_conntrack_tcp_timeout_close_wait",
1220 .data = &tcp_timeouts[TCP_CONNTRACK_CLOSE_WAIT], 1220 .data = &tcp_timeouts[TCP_CONNTRACK_CLOSE_WAIT],
1221 .maxlen = sizeof(unsigned int), 1221 .maxlen = sizeof(unsigned int),
1222 .mode = 0644, 1222 .mode = 0644,
1223 .proc_handler = &proc_dointvec_jiffies, 1223 .proc_handler = proc_dointvec_jiffies,
1224 }, 1224 },
1225 { 1225 {
1226 .procname = "nf_conntrack_tcp_timeout_last_ack", 1226 .procname = "nf_conntrack_tcp_timeout_last_ack",
1227 .data = &tcp_timeouts[TCP_CONNTRACK_LAST_ACK], 1227 .data = &tcp_timeouts[TCP_CONNTRACK_LAST_ACK],
1228 .maxlen = sizeof(unsigned int), 1228 .maxlen = sizeof(unsigned int),
1229 .mode = 0644, 1229 .mode = 0644,
1230 .proc_handler = &proc_dointvec_jiffies, 1230 .proc_handler = proc_dointvec_jiffies,
1231 }, 1231 },
1232 { 1232 {
1233 .procname = "nf_conntrack_tcp_timeout_time_wait", 1233 .procname = "nf_conntrack_tcp_timeout_time_wait",
1234 .data = &tcp_timeouts[TCP_CONNTRACK_TIME_WAIT], 1234 .data = &tcp_timeouts[TCP_CONNTRACK_TIME_WAIT],
1235 .maxlen = sizeof(unsigned int), 1235 .maxlen = sizeof(unsigned int),
1236 .mode = 0644, 1236 .mode = 0644,
1237 .proc_handler = &proc_dointvec_jiffies, 1237 .proc_handler = proc_dointvec_jiffies,
1238 }, 1238 },
1239 { 1239 {
1240 .procname = "nf_conntrack_tcp_timeout_close", 1240 .procname = "nf_conntrack_tcp_timeout_close",
1241 .data = &tcp_timeouts[TCP_CONNTRACK_CLOSE], 1241 .data = &tcp_timeouts[TCP_CONNTRACK_CLOSE],
1242 .maxlen = sizeof(unsigned int), 1242 .maxlen = sizeof(unsigned int),
1243 .mode = 0644, 1243 .mode = 0644,
1244 .proc_handler = &proc_dointvec_jiffies, 1244 .proc_handler = proc_dointvec_jiffies,
1245 }, 1245 },
1246 { 1246 {
1247 .procname = "nf_conntrack_tcp_timeout_max_retrans", 1247 .procname = "nf_conntrack_tcp_timeout_max_retrans",
1248 .data = &nf_ct_tcp_timeout_max_retrans, 1248 .data = &nf_ct_tcp_timeout_max_retrans,
1249 .maxlen = sizeof(unsigned int), 1249 .maxlen = sizeof(unsigned int),
1250 .mode = 0644, 1250 .mode = 0644,
1251 .proc_handler = &proc_dointvec_jiffies, 1251 .proc_handler = proc_dointvec_jiffies,
1252 }, 1252 },
1253 { 1253 {
1254 .procname = "nf_conntrack_tcp_timeout_unacknowledged", 1254 .procname = "nf_conntrack_tcp_timeout_unacknowledged",
1255 .data = &nf_ct_tcp_timeout_unacknowledged, 1255 .data = &nf_ct_tcp_timeout_unacknowledged,
1256 .maxlen = sizeof(unsigned int), 1256 .maxlen = sizeof(unsigned int),
1257 .mode = 0644, 1257 .mode = 0644,
1258 .proc_handler = &proc_dointvec_jiffies, 1258 .proc_handler = proc_dointvec_jiffies,
1259 }, 1259 },
1260 { 1260 {
1261 .ctl_name = NET_NF_CONNTRACK_TCP_LOOSE, 1261 .ctl_name = NET_NF_CONNTRACK_TCP_LOOSE,
@@ -1263,7 +1263,7 @@ static struct ctl_table tcp_sysctl_table[] = {
1263 .data = &nf_ct_tcp_loose, 1263 .data = &nf_ct_tcp_loose,
1264 .maxlen = sizeof(unsigned int), 1264 .maxlen = sizeof(unsigned int),
1265 .mode = 0644, 1265 .mode = 0644,
1266 .proc_handler = &proc_dointvec, 1266 .proc_handler = proc_dointvec,
1267 }, 1267 },
1268 { 1268 {
1269 .ctl_name = NET_NF_CONNTRACK_TCP_BE_LIBERAL, 1269 .ctl_name = NET_NF_CONNTRACK_TCP_BE_LIBERAL,
@@ -1271,7 +1271,7 @@ static struct ctl_table tcp_sysctl_table[] = {
1271 .data = &nf_ct_tcp_be_liberal, 1271 .data = &nf_ct_tcp_be_liberal,
1272 .maxlen = sizeof(unsigned int), 1272 .maxlen = sizeof(unsigned int),
1273 .mode = 0644, 1273 .mode = 0644,
1274 .proc_handler = &proc_dointvec, 1274 .proc_handler = proc_dointvec,
1275 }, 1275 },
1276 { 1276 {
1277 .ctl_name = NET_NF_CONNTRACK_TCP_MAX_RETRANS, 1277 .ctl_name = NET_NF_CONNTRACK_TCP_MAX_RETRANS,
@@ -1279,7 +1279,7 @@ static struct ctl_table tcp_sysctl_table[] = {
1279 .data = &nf_ct_tcp_max_retrans, 1279 .data = &nf_ct_tcp_max_retrans,
1280 .maxlen = sizeof(unsigned int), 1280 .maxlen = sizeof(unsigned int),
1281 .mode = 0644, 1281 .mode = 0644,
1282 .proc_handler = &proc_dointvec, 1282 .proc_handler = proc_dointvec,
1283 }, 1283 },
1284 { 1284 {
1285 .ctl_name = 0 1285 .ctl_name = 0
@@ -1293,63 +1293,63 @@ static struct ctl_table tcp_compat_sysctl_table[] = {
1293 .data = &tcp_timeouts[TCP_CONNTRACK_SYN_SENT], 1293 .data = &tcp_timeouts[TCP_CONNTRACK_SYN_SENT],
1294 .maxlen = sizeof(unsigned int), 1294 .maxlen = sizeof(unsigned int),
1295 .mode = 0644, 1295 .mode = 0644,
1296 .proc_handler = &proc_dointvec_jiffies, 1296 .proc_handler = proc_dointvec_jiffies,
1297 }, 1297 },
1298 { 1298 {
1299 .procname = "ip_conntrack_tcp_timeout_syn_recv", 1299 .procname = "ip_conntrack_tcp_timeout_syn_recv",
1300 .data = &tcp_timeouts[TCP_CONNTRACK_SYN_RECV], 1300 .data = &tcp_timeouts[TCP_CONNTRACK_SYN_RECV],
1301 .maxlen = sizeof(unsigned int), 1301 .maxlen = sizeof(unsigned int),
1302 .mode = 0644, 1302 .mode = 0644,
1303 .proc_handler = &proc_dointvec_jiffies, 1303 .proc_handler = proc_dointvec_jiffies,
1304 }, 1304 },
1305 { 1305 {
1306 .procname = "ip_conntrack_tcp_timeout_established", 1306 .procname = "ip_conntrack_tcp_timeout_established",
1307 .data = &tcp_timeouts[TCP_CONNTRACK_ESTABLISHED], 1307 .data = &tcp_timeouts[TCP_CONNTRACK_ESTABLISHED],
1308 .maxlen = sizeof(unsigned int), 1308 .maxlen = sizeof(unsigned int),
1309 .mode = 0644, 1309 .mode = 0644,
1310 .proc_handler = &proc_dointvec_jiffies, 1310 .proc_handler = proc_dointvec_jiffies,
1311 }, 1311 },
1312 { 1312 {
1313 .procname = "ip_conntrack_tcp_timeout_fin_wait", 1313 .procname = "ip_conntrack_tcp_timeout_fin_wait",
1314 .data = &tcp_timeouts[TCP_CONNTRACK_FIN_WAIT], 1314 .data = &tcp_timeouts[TCP_CONNTRACK_FIN_WAIT],
1315 .maxlen = sizeof(unsigned int), 1315 .maxlen = sizeof(unsigned int),
1316 .mode = 0644, 1316 .mode = 0644,
1317 .proc_handler = &proc_dointvec_jiffies, 1317 .proc_handler = proc_dointvec_jiffies,
1318 }, 1318 },
1319 { 1319 {
1320 .procname = "ip_conntrack_tcp_timeout_close_wait", 1320 .procname = "ip_conntrack_tcp_timeout_close_wait",
1321 .data = &tcp_timeouts[TCP_CONNTRACK_CLOSE_WAIT], 1321 .data = &tcp_timeouts[TCP_CONNTRACK_CLOSE_WAIT],
1322 .maxlen = sizeof(unsigned int), 1322 .maxlen = sizeof(unsigned int),
1323 .mode = 0644, 1323 .mode = 0644,
1324 .proc_handler = &proc_dointvec_jiffies, 1324 .proc_handler = proc_dointvec_jiffies,
1325 }, 1325 },
1326 { 1326 {
1327 .procname = "ip_conntrack_tcp_timeout_last_ack", 1327 .procname = "ip_conntrack_tcp_timeout_last_ack",
1328 .data = &tcp_timeouts[TCP_CONNTRACK_LAST_ACK], 1328 .data = &tcp_timeouts[TCP_CONNTRACK_LAST_ACK],
1329 .maxlen = sizeof(unsigned int), 1329 .maxlen = sizeof(unsigned int),
1330 .mode = 0644, 1330 .mode = 0644,
1331 .proc_handler = &proc_dointvec_jiffies, 1331 .proc_handler = proc_dointvec_jiffies,
1332 }, 1332 },
1333 { 1333 {
1334 .procname = "ip_conntrack_tcp_timeout_time_wait", 1334 .procname = "ip_conntrack_tcp_timeout_time_wait",
1335 .data = &tcp_timeouts[TCP_CONNTRACK_TIME_WAIT], 1335 .data = &tcp_timeouts[TCP_CONNTRACK_TIME_WAIT],
1336 .maxlen = sizeof(unsigned int), 1336 .maxlen = sizeof(unsigned int),
1337 .mode = 0644, 1337 .mode = 0644,
1338 .proc_handler = &proc_dointvec_jiffies, 1338 .proc_handler = proc_dointvec_jiffies,
1339 }, 1339 },
1340 { 1340 {
1341 .procname = "ip_conntrack_tcp_timeout_close", 1341 .procname = "ip_conntrack_tcp_timeout_close",
1342 .data = &tcp_timeouts[TCP_CONNTRACK_CLOSE], 1342 .data = &tcp_timeouts[TCP_CONNTRACK_CLOSE],
1343 .maxlen = sizeof(unsigned int), 1343 .maxlen = sizeof(unsigned int),
1344 .mode = 0644, 1344 .mode = 0644,
1345 .proc_handler = &proc_dointvec_jiffies, 1345 .proc_handler = proc_dointvec_jiffies,
1346 }, 1346 },
1347 { 1347 {
1348 .procname = "ip_conntrack_tcp_timeout_max_retrans", 1348 .procname = "ip_conntrack_tcp_timeout_max_retrans",
1349 .data = &nf_ct_tcp_timeout_max_retrans, 1349 .data = &nf_ct_tcp_timeout_max_retrans,
1350 .maxlen = sizeof(unsigned int), 1350 .maxlen = sizeof(unsigned int),
1351 .mode = 0644, 1351 .mode = 0644,
1352 .proc_handler = &proc_dointvec_jiffies, 1352 .proc_handler = proc_dointvec_jiffies,
1353 }, 1353 },
1354 { 1354 {
1355 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_LOOSE, 1355 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_LOOSE,
@@ -1357,7 +1357,7 @@ static struct ctl_table tcp_compat_sysctl_table[] = {
1357 .data = &nf_ct_tcp_loose, 1357 .data = &nf_ct_tcp_loose,
1358 .maxlen = sizeof(unsigned int), 1358 .maxlen = sizeof(unsigned int),
1359 .mode = 0644, 1359 .mode = 0644,
1360 .proc_handler = &proc_dointvec, 1360 .proc_handler = proc_dointvec,
1361 }, 1361 },
1362 { 1362 {
1363 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_BE_LIBERAL, 1363 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_BE_LIBERAL,
@@ -1365,7 +1365,7 @@ static struct ctl_table tcp_compat_sysctl_table[] = {
1365 .data = &nf_ct_tcp_be_liberal, 1365 .data = &nf_ct_tcp_be_liberal,
1366 .maxlen = sizeof(unsigned int), 1366 .maxlen = sizeof(unsigned int),
1367 .mode = 0644, 1367 .mode = 0644,
1368 .proc_handler = &proc_dointvec, 1368 .proc_handler = proc_dointvec,
1369 }, 1369 },
1370 { 1370 {
1371 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_MAX_RETRANS, 1371 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_MAX_RETRANS,
@@ -1373,7 +1373,7 @@ static struct ctl_table tcp_compat_sysctl_table[] = {
1373 .data = &nf_ct_tcp_max_retrans, 1373 .data = &nf_ct_tcp_max_retrans,
1374 .maxlen = sizeof(unsigned int), 1374 .maxlen = sizeof(unsigned int),
1375 .mode = 0644, 1375 .mode = 0644,
1376 .proc_handler = &proc_dointvec, 1376 .proc_handler = proc_dointvec,
1377 }, 1377 },
1378 { 1378 {
1379 .ctl_name = 0 1379 .ctl_name = 0
diff --git a/net/netfilter/nf_conntrack_proto_udp.c b/net/netfilter/nf_conntrack_proto_udp.c
index 7c2ca48698be..2b8b1f579f93 100644
--- a/net/netfilter/nf_conntrack_proto_udp.c
+++ b/net/netfilter/nf_conntrack_proto_udp.c
@@ -143,14 +143,14 @@ static struct ctl_table udp_sysctl_table[] = {
143 .data = &nf_ct_udp_timeout, 143 .data = &nf_ct_udp_timeout,
144 .maxlen = sizeof(unsigned int), 144 .maxlen = sizeof(unsigned int),
145 .mode = 0644, 145 .mode = 0644,
146 .proc_handler = &proc_dointvec_jiffies, 146 .proc_handler = proc_dointvec_jiffies,
147 }, 147 },
148 { 148 {
149 .procname = "nf_conntrack_udp_timeout_stream", 149 .procname = "nf_conntrack_udp_timeout_stream",
150 .data = &nf_ct_udp_timeout_stream, 150 .data = &nf_ct_udp_timeout_stream,
151 .maxlen = sizeof(unsigned int), 151 .maxlen = sizeof(unsigned int),
152 .mode = 0644, 152 .mode = 0644,
153 .proc_handler = &proc_dointvec_jiffies, 153 .proc_handler = proc_dointvec_jiffies,
154 }, 154 },
155 { 155 {
156 .ctl_name = 0 156 .ctl_name = 0
@@ -163,14 +163,14 @@ static struct ctl_table udp_compat_sysctl_table[] = {
163 .data = &nf_ct_udp_timeout, 163 .data = &nf_ct_udp_timeout,
164 .maxlen = sizeof(unsigned int), 164 .maxlen = sizeof(unsigned int),
165 .mode = 0644, 165 .mode = 0644,
166 .proc_handler = &proc_dointvec_jiffies, 166 .proc_handler = proc_dointvec_jiffies,
167 }, 167 },
168 { 168 {
169 .procname = "ip_conntrack_udp_timeout_stream", 169 .procname = "ip_conntrack_udp_timeout_stream",
170 .data = &nf_ct_udp_timeout_stream, 170 .data = &nf_ct_udp_timeout_stream,
171 .maxlen = sizeof(unsigned int), 171 .maxlen = sizeof(unsigned int),
172 .mode = 0644, 172 .mode = 0644,
173 .proc_handler = &proc_dointvec_jiffies, 173 .proc_handler = proc_dointvec_jiffies,
174 }, 174 },
175 { 175 {
176 .ctl_name = 0 176 .ctl_name = 0
diff --git a/net/netfilter/nf_conntrack_proto_udplite.c b/net/netfilter/nf_conntrack_proto_udplite.c
index d22d839e4f94..4579d8de13b1 100644
--- a/net/netfilter/nf_conntrack_proto_udplite.c
+++ b/net/netfilter/nf_conntrack_proto_udplite.c
@@ -151,7 +151,7 @@ static struct ctl_table udplite_sysctl_table[] = {
151 .data = &nf_ct_udplite_timeout, 151 .data = &nf_ct_udplite_timeout,
152 .maxlen = sizeof(unsigned int), 152 .maxlen = sizeof(unsigned int),
153 .mode = 0644, 153 .mode = 0644,
154 .proc_handler = &proc_dointvec_jiffies, 154 .proc_handler = proc_dointvec_jiffies,
155 }, 155 },
156 { 156 {
157 .ctl_name = CTL_UNNUMBERED, 157 .ctl_name = CTL_UNNUMBERED,
@@ -159,7 +159,7 @@ static struct ctl_table udplite_sysctl_table[] = {
159 .data = &nf_ct_udplite_timeout_stream, 159 .data = &nf_ct_udplite_timeout_stream,
160 .maxlen = sizeof(unsigned int), 160 .maxlen = sizeof(unsigned int),
161 .mode = 0644, 161 .mode = 0644,
162 .proc_handler = &proc_dointvec_jiffies, 162 .proc_handler = proc_dointvec_jiffies,
163 }, 163 },
164 { 164 {
165 .ctl_name = 0 165 .ctl_name = 0
diff --git a/net/netfilter/nf_conntrack_sane.c b/net/netfilter/nf_conntrack_sane.c
index a94294b2b23c..dcfecbb81c46 100644
--- a/net/netfilter/nf_conntrack_sane.c
+++ b/net/netfilter/nf_conntrack_sane.c
@@ -30,6 +30,7 @@
30MODULE_LICENSE("GPL"); 30MODULE_LICENSE("GPL");
31MODULE_AUTHOR("Michal Schmidt <mschmidt@redhat.com>"); 31MODULE_AUTHOR("Michal Schmidt <mschmidt@redhat.com>");
32MODULE_DESCRIPTION("SANE connection tracking helper"); 32MODULE_DESCRIPTION("SANE connection tracking helper");
33MODULE_ALIAS_NFCT_HELPER("sane");
33 34
34static char *sane_buffer; 35static char *sane_buffer;
35 36
diff --git a/net/netfilter/nf_conntrack_sip.c b/net/netfilter/nf_conntrack_sip.c
index 6813f1c8863f..4b572163784b 100644
--- a/net/netfilter/nf_conntrack_sip.c
+++ b/net/netfilter/nf_conntrack_sip.c
@@ -28,6 +28,7 @@ MODULE_LICENSE("GPL");
28MODULE_AUTHOR("Christian Hentschel <chentschel@arnet.com.ar>"); 28MODULE_AUTHOR("Christian Hentschel <chentschel@arnet.com.ar>");
29MODULE_DESCRIPTION("SIP connection tracking helper"); 29MODULE_DESCRIPTION("SIP connection tracking helper");
30MODULE_ALIAS("ip_conntrack_sip"); 30MODULE_ALIAS("ip_conntrack_sip");
31MODULE_ALIAS_NFCT_HELPER("sip");
31 32
32#define MAX_PORTS 8 33#define MAX_PORTS 8
33static unsigned short ports[MAX_PORTS]; 34static unsigned short ports[MAX_PORTS];
diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c
index 98106d4e89f0..f37b9b74c6a8 100644
--- a/net/netfilter/nf_conntrack_standalone.c
+++ b/net/netfilter/nf_conntrack_standalone.c
@@ -336,7 +336,7 @@ static ctl_table nf_ct_sysctl_table[] = {
336 .data = &nf_conntrack_max, 336 .data = &nf_conntrack_max,
337 .maxlen = sizeof(int), 337 .maxlen = sizeof(int),
338 .mode = 0644, 338 .mode = 0644,
339 .proc_handler = &proc_dointvec, 339 .proc_handler = proc_dointvec,
340 }, 340 },
341 { 341 {
342 .ctl_name = NET_NF_CONNTRACK_COUNT, 342 .ctl_name = NET_NF_CONNTRACK_COUNT,
@@ -344,7 +344,7 @@ static ctl_table nf_ct_sysctl_table[] = {
344 .data = &init_net.ct.count, 344 .data = &init_net.ct.count,
345 .maxlen = sizeof(int), 345 .maxlen = sizeof(int),
346 .mode = 0444, 346 .mode = 0444,
347 .proc_handler = &proc_dointvec, 347 .proc_handler = proc_dointvec,
348 }, 348 },
349 { 349 {
350 .ctl_name = NET_NF_CONNTRACK_BUCKETS, 350 .ctl_name = NET_NF_CONNTRACK_BUCKETS,
@@ -352,7 +352,7 @@ static ctl_table nf_ct_sysctl_table[] = {
352 .data = &nf_conntrack_htable_size, 352 .data = &nf_conntrack_htable_size,
353 .maxlen = sizeof(unsigned int), 353 .maxlen = sizeof(unsigned int),
354 .mode = 0444, 354 .mode = 0444,
355 .proc_handler = &proc_dointvec, 355 .proc_handler = proc_dointvec,
356 }, 356 },
357 { 357 {
358 .ctl_name = NET_NF_CONNTRACK_CHECKSUM, 358 .ctl_name = NET_NF_CONNTRACK_CHECKSUM,
@@ -360,7 +360,7 @@ static ctl_table nf_ct_sysctl_table[] = {
360 .data = &init_net.ct.sysctl_checksum, 360 .data = &init_net.ct.sysctl_checksum,
361 .maxlen = sizeof(unsigned int), 361 .maxlen = sizeof(unsigned int),
362 .mode = 0644, 362 .mode = 0644,
363 .proc_handler = &proc_dointvec, 363 .proc_handler = proc_dointvec,
364 }, 364 },
365 { 365 {
366 .ctl_name = NET_NF_CONNTRACK_LOG_INVALID, 366 .ctl_name = NET_NF_CONNTRACK_LOG_INVALID,
@@ -368,8 +368,8 @@ static ctl_table nf_ct_sysctl_table[] = {
368 .data = &init_net.ct.sysctl_log_invalid, 368 .data = &init_net.ct.sysctl_log_invalid,
369 .maxlen = sizeof(unsigned int), 369 .maxlen = sizeof(unsigned int),
370 .mode = 0644, 370 .mode = 0644,
371 .proc_handler = &proc_dointvec_minmax, 371 .proc_handler = proc_dointvec_minmax,
372 .strategy = &sysctl_intvec, 372 .strategy = sysctl_intvec,
373 .extra1 = &log_invalid_proto_min, 373 .extra1 = &log_invalid_proto_min,
374 .extra2 = &log_invalid_proto_max, 374 .extra2 = &log_invalid_proto_max,
375 }, 375 },
@@ -379,7 +379,7 @@ static ctl_table nf_ct_sysctl_table[] = {
379 .data = &nf_ct_expect_max, 379 .data = &nf_ct_expect_max,
380 .maxlen = sizeof(int), 380 .maxlen = sizeof(int),
381 .mode = 0644, 381 .mode = 0644,
382 .proc_handler = &proc_dointvec, 382 .proc_handler = proc_dointvec,
383 }, 383 },
384 { .ctl_name = 0 } 384 { .ctl_name = 0 }
385}; 385};
@@ -393,7 +393,7 @@ static ctl_table nf_ct_netfilter_table[] = {
393 .data = &nf_conntrack_max, 393 .data = &nf_conntrack_max,
394 .maxlen = sizeof(int), 394 .maxlen = sizeof(int),
395 .mode = 0644, 395 .mode = 0644,
396 .proc_handler = &proc_dointvec, 396 .proc_handler = proc_dointvec,
397 }, 397 },
398 { .ctl_name = 0 } 398 { .ctl_name = 0 }
399}; 399};
diff --git a/net/netfilter/nf_conntrack_tftp.c b/net/netfilter/nf_conntrack_tftp.c
index f57f6e7a71ee..46e646b2e9b9 100644
--- a/net/netfilter/nf_conntrack_tftp.c
+++ b/net/netfilter/nf_conntrack_tftp.c
@@ -22,6 +22,7 @@ MODULE_AUTHOR("Magnus Boden <mb@ozaba.mine.nu>");
22MODULE_DESCRIPTION("TFTP connection tracking helper"); 22MODULE_DESCRIPTION("TFTP connection tracking helper");
23MODULE_LICENSE("GPL"); 23MODULE_LICENSE("GPL");
24MODULE_ALIAS("ip_conntrack_tftp"); 24MODULE_ALIAS("ip_conntrack_tftp");
25MODULE_ALIAS_NFCT_HELPER("tftp");
25 26
26#define MAX_PORTS 8 27#define MAX_PORTS 8
27static unsigned short ports[MAX_PORTS]; 28static unsigned short ports[MAX_PORTS];
diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
index 38f9efd90e8d..fa49dc7fe100 100644
--- a/net/netfilter/nfnetlink_log.c
+++ b/net/netfilter/nfnetlink_log.c
@@ -30,6 +30,7 @@
30#include <linux/random.h> 30#include <linux/random.h>
31#include <net/sock.h> 31#include <net/sock.h>
32#include <net/netfilter/nf_log.h> 32#include <net/netfilter/nf_log.h>
33#include <net/netfilter/nfnetlink_log.h>
33 34
34#include <asm/atomic.h> 35#include <asm/atomic.h>
35 36
@@ -534,7 +535,7 @@ static struct nf_loginfo default_loginfo = {
534}; 535};
535 536
536/* log handler for internal netfilter logging api */ 537/* log handler for internal netfilter logging api */
537static void 538void
538nfulnl_log_packet(u_int8_t pf, 539nfulnl_log_packet(u_int8_t pf,
539 unsigned int hooknum, 540 unsigned int hooknum,
540 const struct sk_buff *skb, 541 const struct sk_buff *skb,
@@ -649,6 +650,7 @@ alloc_failure:
649 /* FIXME: statistics */ 650 /* FIXME: statistics */
650 goto unlock_and_release; 651 goto unlock_and_release;
651} 652}
653EXPORT_SYMBOL_GPL(nfulnl_log_packet);
652 654
653static int 655static int
654nfulnl_rcv_nl_event(struct notifier_block *this, 656nfulnl_rcv_nl_event(struct notifier_block *this,
diff --git a/net/netfilter/xt_NFLOG.c b/net/netfilter/xt_NFLOG.c
index 50e3a52d3b31..a57c5cf018ec 100644
--- a/net/netfilter/xt_NFLOG.c
+++ b/net/netfilter/xt_NFLOG.c
@@ -13,6 +13,7 @@
13#include <linux/netfilter/x_tables.h> 13#include <linux/netfilter/x_tables.h>
14#include <linux/netfilter/xt_NFLOG.h> 14#include <linux/netfilter/xt_NFLOG.h>
15#include <net/netfilter/nf_log.h> 15#include <net/netfilter/nf_log.h>
16#include <net/netfilter/nfnetlink_log.h>
16 17
17MODULE_AUTHOR("Patrick McHardy <kaber@trash.net>"); 18MODULE_AUTHOR("Patrick McHardy <kaber@trash.net>");
18MODULE_DESCRIPTION("Xtables: packet logging to netlink using NFLOG"); 19MODULE_DESCRIPTION("Xtables: packet logging to netlink using NFLOG");
@@ -31,8 +32,8 @@ nflog_tg(struct sk_buff *skb, const struct xt_target_param *par)
31 li.u.ulog.group = info->group; 32 li.u.ulog.group = info->group;
32 li.u.ulog.qthreshold = info->threshold; 33 li.u.ulog.qthreshold = info->threshold;
33 34
34 nf_log_packet(par->family, par->hooknum, skb, par->in, 35 nfulnl_log_packet(par->family, par->hooknum, skb, par->in,
35 par->out, &li, "%s", info->prefix); 36 par->out, &li, info->prefix);
36 return XT_CONTINUE; 37 return XT_CONTINUE;
37} 38}
38 39
diff --git a/net/netfilter/xt_dccp.c b/net/netfilter/xt_dccp.c
index e5d3e8673287..0989f29ade2e 100644
--- a/net/netfilter/xt_dccp.c
+++ b/net/netfilter/xt_dccp.c
@@ -45,10 +45,8 @@ dccp_find_option(u_int8_t option,
45 unsigned int optlen = dh->dccph_doff*4 - __dccp_hdr_len(dh); 45 unsigned int optlen = dh->dccph_doff*4 - __dccp_hdr_len(dh);
46 unsigned int i; 46 unsigned int i;
47 47
48 if (dh->dccph_doff * 4 < __dccp_hdr_len(dh)) { 48 if (dh->dccph_doff * 4 < __dccp_hdr_len(dh))
49 *hotdrop = true; 49 goto invalid;
50 return false;
51 }
52 50
53 if (!optlen) 51 if (!optlen)
54 return false; 52 return false;
@@ -57,9 +55,7 @@ dccp_find_option(u_int8_t option,
57 op = skb_header_pointer(skb, protoff + optoff, optlen, dccp_optbuf); 55 op = skb_header_pointer(skb, protoff + optoff, optlen, dccp_optbuf);
58 if (op == NULL) { 56 if (op == NULL) {
59 /* If we don't have the whole header, drop packet. */ 57 /* If we don't have the whole header, drop packet. */
60 spin_unlock_bh(&dccp_buflock); 58 goto partial;
61 *hotdrop = true;
62 return false;
63 } 59 }
64 60
65 for (i = 0; i < optlen; ) { 61 for (i = 0; i < optlen; ) {
@@ -76,6 +72,12 @@ dccp_find_option(u_int8_t option,
76 72
77 spin_unlock_bh(&dccp_buflock); 73 spin_unlock_bh(&dccp_buflock);
78 return false; 74 return false;
75
76partial:
77 spin_unlock_bh(&dccp_buflock);
78invalid:
79 *hotdrop = true;
80 return false;
79} 81}
80 82
81 83
diff --git a/net/netfilter/xt_hashlimit.c b/net/netfilter/xt_hashlimit.c
index 6fc4292d46e6..f97fded024c4 100644
--- a/net/netfilter/xt_hashlimit.c
+++ b/net/netfilter/xt_hashlimit.c
@@ -893,23 +893,21 @@ static int dl_seq_real_show(struct dsthash_ent *ent, u_int8_t family,
893 893
894 switch (family) { 894 switch (family) {
895 case NFPROTO_IPV4: 895 case NFPROTO_IPV4:
896 return seq_printf(s, "%ld %u.%u.%u.%u:%u->" 896 return seq_printf(s, "%ld %pI4:%u->%pI4:%u %u %u %u\n",
897 "%u.%u.%u.%u:%u %u %u %u\n",
898 (long)(ent->expires - jiffies)/HZ, 897 (long)(ent->expires - jiffies)/HZ,
899 NIPQUAD(ent->dst.ip.src), 898 &ent->dst.ip.src,
900 ntohs(ent->dst.src_port), 899 ntohs(ent->dst.src_port),
901 NIPQUAD(ent->dst.ip.dst), 900 &ent->dst.ip.dst,
902 ntohs(ent->dst.dst_port), 901 ntohs(ent->dst.dst_port),
903 ent->rateinfo.credit, ent->rateinfo.credit_cap, 902 ent->rateinfo.credit, ent->rateinfo.credit_cap,
904 ent->rateinfo.cost); 903 ent->rateinfo.cost);
905#if defined(CONFIG_IP6_NF_IPTABLES) || defined(CONFIG_IP6_NF_IPTABLES_MODULE) 904#if defined(CONFIG_IP6_NF_IPTABLES) || defined(CONFIG_IP6_NF_IPTABLES_MODULE)
906 case NFPROTO_IPV6: 905 case NFPROTO_IPV6:
907 return seq_printf(s, "%ld " NIP6_FMT ":%u->" 906 return seq_printf(s, "%ld %pI6:%u->%pI6:%u %u %u %u\n",
908 NIP6_FMT ":%u %u %u %u\n",
909 (long)(ent->expires - jiffies)/HZ, 907 (long)(ent->expires - jiffies)/HZ,
910 NIP6(*(struct in6_addr *)&ent->dst.ip6.src), 908 &ent->dst.ip6.src,
911 ntohs(ent->dst.src_port), 909 ntohs(ent->dst.src_port),
912 NIP6(*(struct in6_addr *)&ent->dst.ip6.dst), 910 &ent->dst.ip6.dst,
913 ntohs(ent->dst.dst_port), 911 ntohs(ent->dst.dst_port),
914 ent->rateinfo.credit, ent->rateinfo.credit_cap, 912 ent->rateinfo.credit, ent->rateinfo.credit_cap,
915 ent->rateinfo.cost); 913 ent->rateinfo.cost);
diff --git a/net/netfilter/xt_iprange.c b/net/netfilter/xt_iprange.c
index 7ac54eab0b00..501f9b623188 100644
--- a/net/netfilter/xt_iprange.c
+++ b/net/netfilter/xt_iprange.c
@@ -26,12 +26,11 @@ iprange_mt_v0(const struct sk_buff *skb, const struct xt_match_param *par)
26 if ((ntohl(iph->saddr) < ntohl(info->src.min_ip) 26 if ((ntohl(iph->saddr) < ntohl(info->src.min_ip)
27 || ntohl(iph->saddr) > ntohl(info->src.max_ip)) 27 || ntohl(iph->saddr) > ntohl(info->src.max_ip))
28 ^ !!(info->flags & IPRANGE_SRC_INV)) { 28 ^ !!(info->flags & IPRANGE_SRC_INV)) {
29 pr_debug("src IP %u.%u.%u.%u NOT in range %s" 29 pr_debug("src IP %pI4 NOT in range %s%pI4-%pI4\n",
30 "%u.%u.%u.%u-%u.%u.%u.%u\n", 30 &iph->saddr,
31 NIPQUAD(iph->saddr),
32 info->flags & IPRANGE_SRC_INV ? "(INV) " : "", 31 info->flags & IPRANGE_SRC_INV ? "(INV) " : "",
33 NIPQUAD(info->src.min_ip), 32 &info->src.min_ip,
34 NIPQUAD(info->src.max_ip)); 33 &info->src.max_ip);
35 return false; 34 return false;
36 } 35 }
37 } 36 }
@@ -39,12 +38,11 @@ iprange_mt_v0(const struct sk_buff *skb, const struct xt_match_param *par)
39 if ((ntohl(iph->daddr) < ntohl(info->dst.min_ip) 38 if ((ntohl(iph->daddr) < ntohl(info->dst.min_ip)
40 || ntohl(iph->daddr) > ntohl(info->dst.max_ip)) 39 || ntohl(iph->daddr) > ntohl(info->dst.max_ip))
41 ^ !!(info->flags & IPRANGE_DST_INV)) { 40 ^ !!(info->flags & IPRANGE_DST_INV)) {
42 pr_debug("dst IP %u.%u.%u.%u NOT in range %s" 41 pr_debug("dst IP %pI4 NOT in range %s%pI4-%pI4\n",
43 "%u.%u.%u.%u-%u.%u.%u.%u\n", 42 &iph->daddr,
44 NIPQUAD(iph->daddr),
45 info->flags & IPRANGE_DST_INV ? "(INV) " : "", 43 info->flags & IPRANGE_DST_INV ? "(INV) " : "",
46 NIPQUAD(info->dst.min_ip), 44 &info->dst.min_ip,
47 NIPQUAD(info->dst.max_ip)); 45 &info->dst.max_ip);
48 return false; 46 return false;
49 } 47 }
50 } 48 }
@@ -63,12 +61,11 @@ iprange_mt4(const struct sk_buff *skb, const struct xt_match_param *par)
63 m |= ntohl(iph->saddr) > ntohl(info->src_max.ip); 61 m |= ntohl(iph->saddr) > ntohl(info->src_max.ip);
64 m ^= !!(info->flags & IPRANGE_SRC_INV); 62 m ^= !!(info->flags & IPRANGE_SRC_INV);
65 if (m) { 63 if (m) {
66 pr_debug("src IP " NIPQUAD_FMT " NOT in range %s" 64 pr_debug("src IP %pI4 NOT in range %s%pI4-%pI4\n",
67 NIPQUAD_FMT "-" NIPQUAD_FMT "\n", 65 &iph->saddr,
68 NIPQUAD(iph->saddr),
69 (info->flags & IPRANGE_SRC_INV) ? "(INV) " : "", 66 (info->flags & IPRANGE_SRC_INV) ? "(INV) " : "",
70 NIPQUAD(info->src_max.ip), 67 &info->src_max.ip,
71 NIPQUAD(info->src_max.ip)); 68 &info->src_max.ip);
72 return false; 69 return false;
73 } 70 }
74 } 71 }
@@ -77,12 +74,11 @@ iprange_mt4(const struct sk_buff *skb, const struct xt_match_param *par)
77 m |= ntohl(iph->daddr) > ntohl(info->dst_max.ip); 74 m |= ntohl(iph->daddr) > ntohl(info->dst_max.ip);
78 m ^= !!(info->flags & IPRANGE_DST_INV); 75 m ^= !!(info->flags & IPRANGE_DST_INV);
79 if (m) { 76 if (m) {
80 pr_debug("dst IP " NIPQUAD_FMT " NOT in range %s" 77 pr_debug("dst IP %pI4 NOT in range %s%pI4-%pI4\n",
81 NIPQUAD_FMT "-" NIPQUAD_FMT "\n", 78 &iph->daddr,
82 NIPQUAD(iph->daddr),
83 (info->flags & IPRANGE_DST_INV) ? "(INV) " : "", 79 (info->flags & IPRANGE_DST_INV) ? "(INV) " : "",
84 NIPQUAD(info->dst_min.ip), 80 &info->dst_min.ip,
85 NIPQUAD(info->dst_max.ip)); 81 &info->dst_max.ip);
86 return false; 82 return false;
87 } 83 }
88 } 84 }
diff --git a/net/netfilter/xt_recent.c b/net/netfilter/xt_recent.c
index 280c471bcdf4..fe80b614a400 100644
--- a/net/netfilter/xt_recent.c
+++ b/net/netfilter/xt_recent.c
@@ -72,9 +72,6 @@ struct recent_entry {
72struct recent_table { 72struct recent_table {
73 struct list_head list; 73 struct list_head list;
74 char name[XT_RECENT_NAME_LEN]; 74 char name[XT_RECENT_NAME_LEN];
75#ifdef CONFIG_PROC_FS
76 struct proc_dir_entry *proc_old, *proc;
77#endif
78 unsigned int refcnt; 75 unsigned int refcnt;
79 unsigned int entries; 76 unsigned int entries;
80 struct list_head lru_list; 77 struct list_head lru_list;
@@ -284,6 +281,9 @@ static bool recent_mt_check(const struct xt_mtchk_param *par)
284{ 281{
285 const struct xt_recent_mtinfo *info = par->matchinfo; 282 const struct xt_recent_mtinfo *info = par->matchinfo;
286 struct recent_table *t; 283 struct recent_table *t;
284#ifdef CONFIG_PROC_FS
285 struct proc_dir_entry *pde;
286#endif
287 unsigned i; 287 unsigned i;
288 bool ret = false; 288 bool ret = false;
289 289
@@ -318,25 +318,25 @@ static bool recent_mt_check(const struct xt_mtchk_param *par)
318 for (i = 0; i < ip_list_hash_size; i++) 318 for (i = 0; i < ip_list_hash_size; i++)
319 INIT_LIST_HEAD(&t->iphash[i]); 319 INIT_LIST_HEAD(&t->iphash[i]);
320#ifdef CONFIG_PROC_FS 320#ifdef CONFIG_PROC_FS
321 t->proc = proc_create_data(t->name, ip_list_perms, recent_proc_dir, 321 pde = proc_create_data(t->name, ip_list_perms, recent_proc_dir,
322 &recent_mt_fops, t); 322 &recent_mt_fops, t);
323 if (t->proc == NULL) { 323 if (pde == NULL) {
324 kfree(t); 324 kfree(t);
325 goto out; 325 goto out;
326 } 326 }
327 pde->uid = ip_list_uid;
328 pde->gid = ip_list_gid;
327#ifdef CONFIG_NETFILTER_XT_MATCH_RECENT_PROC_COMPAT 329#ifdef CONFIG_NETFILTER_XT_MATCH_RECENT_PROC_COMPAT
328 t->proc_old = proc_create_data(t->name, ip_list_perms, proc_old_dir, 330 pde = proc_create_data(t->name, ip_list_perms, proc_old_dir,
329 &recent_old_fops, t); 331 &recent_old_fops, t);
330 if (t->proc_old == NULL) { 332 if (pde == NULL) {
331 remove_proc_entry(t->name, proc_old_dir); 333 remove_proc_entry(t->name, proc_old_dir);
332 kfree(t); 334 kfree(t);
333 goto out; 335 goto out;
334 } 336 }
335 t->proc_old->uid = ip_list_uid; 337 pde->uid = ip_list_uid;
336 t->proc_old->gid = ip_list_gid; 338 pde->gid = ip_list_gid;
337#endif 339#endif
338 t->proc->uid = ip_list_uid;
339 t->proc->gid = ip_list_gid;
340#endif 340#endif
341 spin_lock_bh(&recent_lock); 341 spin_lock_bh(&recent_lock);
342 list_add_tail(&t->list, &tables); 342 list_add_tail(&t->list, &tables);
@@ -422,13 +422,11 @@ static int recent_seq_show(struct seq_file *seq, void *v)
422 422
423 i = (e->index - 1) % ip_pkt_list_tot; 423 i = (e->index - 1) % ip_pkt_list_tot;
424 if (e->family == NFPROTO_IPV4) 424 if (e->family == NFPROTO_IPV4)
425 seq_printf(seq, "src=" NIPQUAD_FMT " ttl: %u last_seen: %lu " 425 seq_printf(seq, "src=%pI4 ttl: %u last_seen: %lu oldest_pkt: %u",
426 "oldest_pkt: %u", NIPQUAD(e->addr.ip), e->ttl, 426 &e->addr.ip, e->ttl, e->stamps[i], e->index);
427 e->stamps[i], e->index);
428 else 427 else
429 seq_printf(seq, "src=" NIP6_FMT " ttl: %u last_seen: %lu " 428 seq_printf(seq, "src=%pI6 ttl: %u last_seen: %lu oldest_pkt: %u",
430 "oldest_pkt: %u", NIP6(e->addr.in6), e->ttl, 429 &e->addr.in6, e->ttl, e->stamps[i], e->index);
431 e->stamps[i], e->index);
432 for (i = 0; i < e->nstamps; i++) 430 for (i = 0; i < e->nstamps; i++)
433 seq_printf(seq, "%s %lu", i ? "," : "", e->stamps[i]); 431 seq_printf(seq, "%s %lu", i ? "," : "", e->stamps[i]);
434 seq_printf(seq, "\n"); 432 seq_printf(seq, "\n");
diff --git a/net/netlabel/netlabel_addrlist.c b/net/netlabel/netlabel_addrlist.c
index 249f6b92f153..834c6eb7f484 100644
--- a/net/netlabel/netlabel_addrlist.c
+++ b/net/netlabel/netlabel_addrlist.c
@@ -337,7 +337,7 @@ void netlbl_af4list_audit_addr(struct audit_buffer *audit_buf,
337 337
338 if (dev != NULL) 338 if (dev != NULL)
339 audit_log_format(audit_buf, " netif=%s", dev); 339 audit_log_format(audit_buf, " netif=%s", dev);
340 audit_log_format(audit_buf, " %s=" NIPQUAD_FMT, dir, NIPQUAD(addr)); 340 audit_log_format(audit_buf, " %s=%pI4", dir, &addr);
341 if (mask_val != 0xffffffff) { 341 if (mask_val != 0xffffffff) {
342 u32 mask_len = 0; 342 u32 mask_len = 0;
343 while (mask_val > 0) { 343 while (mask_val > 0) {
@@ -371,7 +371,7 @@ void netlbl_af6list_audit_addr(struct audit_buffer *audit_buf,
371 371
372 if (dev != NULL) 372 if (dev != NULL)
373 audit_log_format(audit_buf, " netif=%s", dev); 373 audit_log_format(audit_buf, " netif=%s", dev);
374 audit_log_format(audit_buf, " %s=" NIP6_FMT, dir, NIP6(*addr)); 374 audit_log_format(audit_buf, " %s=%pI6", dir, addr);
375 if (ntohl(mask->s6_addr32[3]) != 0xffffffff) { 375 if (ntohl(mask->s6_addr32[3]) != 0xffffffff) {
376 u32 mask_len = 0; 376 u32 mask_len = 0;
377 u32 mask_val; 377 u32 mask_val;
diff --git a/net/netlabel/netlabel_mgmt.c b/net/netlabel/netlabel_mgmt.c
index 0a0ef17b2a40..1821c5d50fb8 100644
--- a/net/netlabel/netlabel_mgmt.c
+++ b/net/netlabel/netlabel_mgmt.c
@@ -596,7 +596,6 @@ listdef_failure:
596/** 596/**
597 * netlbl_mgmt_protocols_cb - Write an individual PROTOCOL message response 597 * netlbl_mgmt_protocols_cb - Write an individual PROTOCOL message response
598 * @skb: the skb to write to 598 * @skb: the skb to write to
599 * @seq: the NETLINK sequence number
600 * @cb: the NETLINK callback 599 * @cb: the NETLINK callback
601 * @protocol: the NetLabel protocol to use in the message 600 * @protocol: the NetLabel protocol to use in the message
602 * 601 *
diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
index 480184a857d2..9eb895c7a2a9 100644
--- a/net/netlink/af_netlink.c
+++ b/net/netlink/af_netlink.c
@@ -452,6 +452,10 @@ static int netlink_create(struct net *net, struct socket *sock, int protocol)
452 if (err < 0) 452 if (err < 0)
453 goto out_module; 453 goto out_module;
454 454
455 local_bh_disable();
456 sock_prot_inuse_add(net, &netlink_proto, 1);
457 local_bh_enable();
458
455 nlk = nlk_sk(sock->sk); 459 nlk = nlk_sk(sock->sk);
456 nlk->module = module; 460 nlk->module = module;
457out: 461out:
@@ -511,6 +515,9 @@ static int netlink_release(struct socket *sock)
511 kfree(nlk->groups); 515 kfree(nlk->groups);
512 nlk->groups = NULL; 516 nlk->groups = NULL;
513 517
518 local_bh_disable();
519 sock_prot_inuse_add(sock_net(sk), &netlink_proto, -1);
520 local_bh_enable();
514 sock_put(sk); 521 sock_put(sk);
515 return 0; 522 return 0;
516} 523}
diff --git a/net/netlink/attr.c b/net/netlink/attr.c
index 2d106cfe1d27..56c3ce7fe29a 100644
--- a/net/netlink/attr.c
+++ b/net/netlink/attr.c
@@ -83,6 +83,12 @@ static int validate_nla(struct nlattr *nla, int maxtype,
83 if (attrlen < NLA_ALIGN(pt->len) + NLA_HDRLEN + nla_len(nla)) 83 if (attrlen < NLA_ALIGN(pt->len) + NLA_HDRLEN + nla_len(nla))
84 return -ERANGE; 84 return -ERANGE;
85 break; 85 break;
86 case NLA_NESTED:
87 /* a nested attributes is allowed to be empty; if its not,
88 * it must have a size of at least NLA_HDRLEN.
89 */
90 if (attrlen == 0)
91 break;
86 default: 92 default:
87 if (pt->len) 93 if (pt->len)
88 minlen = pt->len; 94 minlen = pt->len;
@@ -233,7 +239,7 @@ size_t nla_strlcpy(char *dst, const struct nlattr *nla, size_t dstsize)
233 * 239 *
234 * Returns the number of bytes copied. 240 * Returns the number of bytes copied.
235 */ 241 */
236int nla_memcpy(void *dest, struct nlattr *src, int count) 242int nla_memcpy(void *dest, const struct nlattr *src, int count)
237{ 243{
238 int minlen = min_t(int, count, nla_len(src)); 244 int minlen = min_t(int, count, nla_len(src));
239 245
diff --git a/net/netrom/sysctl_net_netrom.c b/net/netrom/sysctl_net_netrom.c
index 34c96c9674df..7b49591fe87c 100644
--- a/net/netrom/sysctl_net_netrom.c
+++ b/net/netrom/sysctl_net_netrom.c
@@ -41,8 +41,8 @@ static ctl_table nr_table[] = {
41 .data = &sysctl_netrom_default_path_quality, 41 .data = &sysctl_netrom_default_path_quality,
42 .maxlen = sizeof(int), 42 .maxlen = sizeof(int),
43 .mode = 0644, 43 .mode = 0644,
44 .proc_handler = &proc_dointvec_minmax, 44 .proc_handler = proc_dointvec_minmax,
45 .strategy = &sysctl_intvec, 45 .strategy = sysctl_intvec,
46 .extra1 = &min_quality, 46 .extra1 = &min_quality,
47 .extra2 = &max_quality 47 .extra2 = &max_quality
48 }, 48 },
@@ -52,8 +52,8 @@ static ctl_table nr_table[] = {
52 .data = &sysctl_netrom_obsolescence_count_initialiser, 52 .data = &sysctl_netrom_obsolescence_count_initialiser,
53 .maxlen = sizeof(int), 53 .maxlen = sizeof(int),
54 .mode = 0644, 54 .mode = 0644,
55 .proc_handler = &proc_dointvec_minmax, 55 .proc_handler = proc_dointvec_minmax,
56 .strategy = &sysctl_intvec, 56 .strategy = sysctl_intvec,
57 .extra1 = &min_obs, 57 .extra1 = &min_obs,
58 .extra2 = &max_obs 58 .extra2 = &max_obs
59 }, 59 },
@@ -63,8 +63,8 @@ static ctl_table nr_table[] = {
63 .data = &sysctl_netrom_network_ttl_initialiser, 63 .data = &sysctl_netrom_network_ttl_initialiser,
64 .maxlen = sizeof(int), 64 .maxlen = sizeof(int),
65 .mode = 0644, 65 .mode = 0644,
66 .proc_handler = &proc_dointvec_minmax, 66 .proc_handler = proc_dointvec_minmax,
67 .strategy = &sysctl_intvec, 67 .strategy = sysctl_intvec,
68 .extra1 = &min_ttl, 68 .extra1 = &min_ttl,
69 .extra2 = &max_ttl 69 .extra2 = &max_ttl
70 }, 70 },
@@ -74,8 +74,8 @@ static ctl_table nr_table[] = {
74 .data = &sysctl_netrom_transport_timeout, 74 .data = &sysctl_netrom_transport_timeout,
75 .maxlen = sizeof(int), 75 .maxlen = sizeof(int),
76 .mode = 0644, 76 .mode = 0644,
77 .proc_handler = &proc_dointvec_minmax, 77 .proc_handler = proc_dointvec_minmax,
78 .strategy = &sysctl_intvec, 78 .strategy = sysctl_intvec,
79 .extra1 = &min_t1, 79 .extra1 = &min_t1,
80 .extra2 = &max_t1 80 .extra2 = &max_t1
81 }, 81 },
@@ -85,8 +85,8 @@ static ctl_table nr_table[] = {
85 .data = &sysctl_netrom_transport_maximum_tries, 85 .data = &sysctl_netrom_transport_maximum_tries,
86 .maxlen = sizeof(int), 86 .maxlen = sizeof(int),
87 .mode = 0644, 87 .mode = 0644,
88 .proc_handler = &proc_dointvec_minmax, 88 .proc_handler = proc_dointvec_minmax,
89 .strategy = &sysctl_intvec, 89 .strategy = sysctl_intvec,
90 .extra1 = &min_n2, 90 .extra1 = &min_n2,
91 .extra2 = &max_n2 91 .extra2 = &max_n2
92 }, 92 },
@@ -96,8 +96,8 @@ static ctl_table nr_table[] = {
96 .data = &sysctl_netrom_transport_acknowledge_delay, 96 .data = &sysctl_netrom_transport_acknowledge_delay,
97 .maxlen = sizeof(int), 97 .maxlen = sizeof(int),
98 .mode = 0644, 98 .mode = 0644,
99 .proc_handler = &proc_dointvec_minmax, 99 .proc_handler = proc_dointvec_minmax,
100 .strategy = &sysctl_intvec, 100 .strategy = sysctl_intvec,
101 .extra1 = &min_t2, 101 .extra1 = &min_t2,
102 .extra2 = &max_t2 102 .extra2 = &max_t2
103 }, 103 },
@@ -107,8 +107,8 @@ static ctl_table nr_table[] = {
107 .data = &sysctl_netrom_transport_busy_delay, 107 .data = &sysctl_netrom_transport_busy_delay,
108 .maxlen = sizeof(int), 108 .maxlen = sizeof(int),
109 .mode = 0644, 109 .mode = 0644,
110 .proc_handler = &proc_dointvec_minmax, 110 .proc_handler = proc_dointvec_minmax,
111 .strategy = &sysctl_intvec, 111 .strategy = sysctl_intvec,
112 .extra1 = &min_t4, 112 .extra1 = &min_t4,
113 .extra2 = &max_t4 113 .extra2 = &max_t4
114 }, 114 },
@@ -118,8 +118,8 @@ static ctl_table nr_table[] = {
118 .data = &sysctl_netrom_transport_requested_window_size, 118 .data = &sysctl_netrom_transport_requested_window_size,
119 .maxlen = sizeof(int), 119 .maxlen = sizeof(int),
120 .mode = 0644, 120 .mode = 0644,
121 .proc_handler = &proc_dointvec_minmax, 121 .proc_handler = proc_dointvec_minmax,
122 .strategy = &sysctl_intvec, 122 .strategy = sysctl_intvec,
123 .extra1 = &min_window, 123 .extra1 = &min_window,
124 .extra2 = &max_window 124 .extra2 = &max_window
125 }, 125 },
@@ -129,8 +129,8 @@ static ctl_table nr_table[] = {
129 .data = &sysctl_netrom_transport_no_activity_timeout, 129 .data = &sysctl_netrom_transport_no_activity_timeout,
130 .maxlen = sizeof(int), 130 .maxlen = sizeof(int),
131 .mode = 0644, 131 .mode = 0644,
132 .proc_handler = &proc_dointvec_minmax, 132 .proc_handler = proc_dointvec_minmax,
133 .strategy = &sysctl_intvec, 133 .strategy = sysctl_intvec,
134 .extra1 = &min_idle, 134 .extra1 = &min_idle,
135 .extra2 = &max_idle 135 .extra2 = &max_idle
136 }, 136 },
@@ -140,8 +140,8 @@ static ctl_table nr_table[] = {
140 .data = &sysctl_netrom_routing_control, 140 .data = &sysctl_netrom_routing_control,
141 .maxlen = sizeof(int), 141 .maxlen = sizeof(int),
142 .mode = 0644, 142 .mode = 0644,
143 .proc_handler = &proc_dointvec_minmax, 143 .proc_handler = proc_dointvec_minmax,
144 .strategy = &sysctl_intvec, 144 .strategy = sysctl_intvec,
145 .extra1 = &min_route, 145 .extra1 = &min_route,
146 .extra2 = &max_route 146 .extra2 = &max_route
147 }, 147 },
@@ -151,8 +151,8 @@ static ctl_table nr_table[] = {
151 .data = &sysctl_netrom_link_fails_count, 151 .data = &sysctl_netrom_link_fails_count,
152 .maxlen = sizeof(int), 152 .maxlen = sizeof(int),
153 .mode = 0644, 153 .mode = 0644,
154 .proc_handler = &proc_dointvec_minmax, 154 .proc_handler = proc_dointvec_minmax,
155 .strategy = &sysctl_intvec, 155 .strategy = sysctl_intvec,
156 .extra1 = &min_fails, 156 .extra1 = &min_fails,
157 .extra2 = &max_fails 157 .extra2 = &max_fails
158 }, 158 },
@@ -162,8 +162,8 @@ static ctl_table nr_table[] = {
162 .data = &sysctl_netrom_reset_circuit, 162 .data = &sysctl_netrom_reset_circuit,
163 .maxlen = sizeof(int), 163 .maxlen = sizeof(int),
164 .mode = 0644, 164 .mode = 0644,
165 .proc_handler = &proc_dointvec_minmax, 165 .proc_handler = proc_dointvec_minmax,
166 .strategy = &sysctl_intvec, 166 .strategy = sysctl_intvec,
167 .extra1 = &min_reset, 167 .extra1 = &min_reset,
168 .extra2 = &max_reset 168 .extra2 = &max_reset
169 }, 169 },
diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
index c718e7e3f7de..5f94db2f3e9e 100644
--- a/net/packet/af_packet.c
+++ b/net/packet/af_packet.c
@@ -872,6 +872,7 @@ static int packet_release(struct socket *sock)
872 872
873 write_lock_bh(&net->packet.sklist_lock); 873 write_lock_bh(&net->packet.sklist_lock);
874 sk_del_node_init(sk); 874 sk_del_node_init(sk);
875 sock_prot_inuse_add(net, sk->sk_prot, -1);
875 write_unlock_bh(&net->packet.sklist_lock); 876 write_unlock_bh(&net->packet.sklist_lock);
876 877
877 /* 878 /*
@@ -1084,6 +1085,7 @@ static int packet_create(struct net *net, struct socket *sock, int protocol)
1084 1085
1085 write_lock_bh(&net->packet.sklist_lock); 1086 write_lock_bh(&net->packet.sklist_lock);
1086 sk_add_node(sk, &net->packet.sklist); 1087 sk_add_node(sk, &net->packet.sklist);
1088 sock_prot_inuse_add(net, &packet_proto, 1);
1087 write_unlock_bh(&net->packet.sklist_lock); 1089 write_unlock_bh(&net->packet.sklist_lock);
1088 return(0); 1090 return(0);
1089out: 1091out:
diff --git a/net/phonet/af_phonet.c b/net/phonet/af_phonet.c
index 9d211f12582b..13cb323f8c38 100644
--- a/net/phonet/af_phonet.c
+++ b/net/phonet/af_phonet.c
@@ -67,9 +67,6 @@ static int pn_socket_create(struct net *net, struct socket *sock, int protocol)
67 struct phonet_protocol *pnp; 67 struct phonet_protocol *pnp;
68 int err; 68 int err;
69 69
70 if (net != &init_net)
71 return -EAFNOSUPPORT;
72
73 if (!capable(CAP_SYS_ADMIN)) 70 if (!capable(CAP_SYS_ADMIN))
74 return -EPERM; 71 return -EPERM;
75 72
@@ -352,9 +349,6 @@ static int phonet_rcv(struct sk_buff *skb, struct net_device *dev,
352 struct sockaddr_pn sa; 349 struct sockaddr_pn sa;
353 u16 len; 350 u16 len;
354 351
355 if (dev_net(dev) != &init_net)
356 goto out;
357
358 /* check we have at least a full Phonet header */ 352 /* check we have at least a full Phonet header */
359 if (!pskb_pull(skb, sizeof(struct phonethdr))) 353 if (!pskb_pull(skb, sizeof(struct phonethdr)))
360 goto out; 354 goto out;
@@ -373,7 +367,7 @@ static int phonet_rcv(struct sk_buff *skb, struct net_device *dev,
373 if (pn_sockaddr_get_addr(&sa) == 0) 367 if (pn_sockaddr_get_addr(&sa) == 0)
374 goto out; /* currently, we cannot be device 0 */ 368 goto out; /* currently, we cannot be device 0 */
375 369
376 sk = pn_find_sock_by_sa(&sa); 370 sk = pn_find_sock_by_sa(dev_net(dev), &sa);
377 if (sk == NULL) { 371 if (sk == NULL) {
378 if (can_respond(skb)) { 372 if (can_respond(skb)) {
379 send_obj_unreachable(skb); 373 send_obj_unreachable(skb);
diff --git a/net/phonet/pep-gprs.c b/net/phonet/pep-gprs.c
index 803eeef0aa85..b0ceac2d6cd1 100644
--- a/net/phonet/pep-gprs.c
+++ b/net/phonet/pep-gprs.c
@@ -40,23 +40,17 @@ struct gprs_dev {
40 void (*old_data_ready)(struct sock *, int); 40 void (*old_data_ready)(struct sock *, int);
41 void (*old_write_space)(struct sock *); 41 void (*old_write_space)(struct sock *);
42 42
43 struct net_device *net; 43 struct net_device *dev;
44 struct net_device_stats stats;
45
46 struct sk_buff_head tx_queue;
47 struct work_struct tx_work;
48 spinlock_t tx_lock;
49 unsigned tx_max;
50}; 44};
51 45
52static int gprs_type_trans(struct sk_buff *skb) 46static __be16 gprs_type_trans(struct sk_buff *skb)
53{ 47{
54 const u8 *pvfc; 48 const u8 *pvfc;
55 u8 buf; 49 u8 buf;
56 50
57 pvfc = skb_header_pointer(skb, 0, 1, &buf); 51 pvfc = skb_header_pointer(skb, 0, 1, &buf);
58 if (!pvfc) 52 if (!pvfc)
59 return 0; 53 return htons(0);
60 /* Look at IP version field */ 54 /* Look at IP version field */
61 switch (*pvfc >> 4) { 55 switch (*pvfc >> 4) {
62 case 4: 56 case 4:
@@ -64,7 +58,15 @@ static int gprs_type_trans(struct sk_buff *skb)
64 case 6: 58 case 6:
65 return htons(ETH_P_IPV6); 59 return htons(ETH_P_IPV6);
66 } 60 }
67 return 0; 61 return htons(0);
62}
63
64static void gprs_writeable(struct gprs_dev *gp)
65{
66 struct net_device *dev = gp->dev;
67
68 if (pep_writeable(gp->sk))
69 netif_wake_queue(dev);
68} 70}
69 71
70/* 72/*
@@ -73,18 +75,21 @@ static int gprs_type_trans(struct sk_buff *skb)
73 75
74static void gprs_state_change(struct sock *sk) 76static void gprs_state_change(struct sock *sk)
75{ 77{
76 struct gprs_dev *dev = sk->sk_user_data; 78 struct gprs_dev *gp = sk->sk_user_data;
77 79
78 if (sk->sk_state == TCP_CLOSE_WAIT) { 80 if (sk->sk_state == TCP_CLOSE_WAIT) {
79 netif_stop_queue(dev->net); 81 struct net_device *dev = gp->dev;
80 netif_carrier_off(dev->net); 82
83 netif_stop_queue(dev);
84 netif_carrier_off(dev);
81 } 85 }
82} 86}
83 87
84static int gprs_recv(struct gprs_dev *dev, struct sk_buff *skb) 88static int gprs_recv(struct gprs_dev *gp, struct sk_buff *skb)
85{ 89{
90 struct net_device *dev = gp->dev;
86 int err = 0; 91 int err = 0;
87 u16 protocol = gprs_type_trans(skb); 92 __be16 protocol = gprs_type_trans(skb);
88 93
89 if (!protocol) { 94 if (!protocol) {
90 err = -EINVAL; 95 err = -EINVAL;
@@ -99,7 +104,7 @@ static int gprs_recv(struct gprs_dev *dev, struct sk_buff *skb)
99 * so wrap the IP packet as a single fragment of an head-less 104 * so wrap the IP packet as a single fragment of an head-less
100 * socket buffer. The network stack will pull what it needs, 105 * socket buffer. The network stack will pull what it needs,
101 * but at least, the whole IP payload is not memcpy'd. */ 106 * but at least, the whole IP payload is not memcpy'd. */
102 rskb = netdev_alloc_skb(dev->net, 0); 107 rskb = netdev_alloc_skb(dev, 0);
103 if (!rskb) { 108 if (!rskb) {
104 err = -ENOBUFS; 109 err = -ENOBUFS;
105 goto drop; 110 goto drop;
@@ -123,9 +128,9 @@ static int gprs_recv(struct gprs_dev *dev, struct sk_buff *skb)
123 128
124 skb->protocol = protocol; 129 skb->protocol = protocol;
125 skb_reset_mac_header(skb); 130 skb_reset_mac_header(skb);
126 skb->dev = dev->net; 131 skb->dev = dev;
127 132
128 if (likely(dev->net->flags & IFF_UP)) { 133 if (likely(dev->flags & IFF_UP)) {
129 dev->stats.rx_packets++; 134 dev->stats.rx_packets++;
130 dev->stats.rx_bytes += skb->len; 135 dev->stats.rx_bytes += skb->len;
131 netif_rx(skb); 136 netif_rx(skb);
@@ -143,26 +148,21 @@ drop:
143 148
144static void gprs_data_ready(struct sock *sk, int len) 149static void gprs_data_ready(struct sock *sk, int len)
145{ 150{
146 struct gprs_dev *dev = sk->sk_user_data; 151 struct gprs_dev *gp = sk->sk_user_data;
147 struct sk_buff *skb; 152 struct sk_buff *skb;
148 153
149 while ((skb = pep_read(sk)) != NULL) { 154 while ((skb = pep_read(sk)) != NULL) {
150 skb_orphan(skb); 155 skb_orphan(skb);
151 gprs_recv(dev, skb); 156 gprs_recv(gp, skb);
152 } 157 }
153} 158}
154 159
155static void gprs_write_space(struct sock *sk) 160static void gprs_write_space(struct sock *sk)
156{ 161{
157 struct gprs_dev *dev = sk->sk_user_data; 162 struct gprs_dev *gp = sk->sk_user_data;
158 struct net_device *net = dev->net; 163
159 unsigned credits = pep_writeable(sk); 164 if (netif_running(gp->dev))
160 165 gprs_writeable(gp);
161 spin_lock_bh(&dev->tx_lock);
162 dev->tx_max = credits;
163 if (credits > skb_queue_len(&dev->tx_queue) && netif_running(net))
164 netif_wake_queue(net);
165 spin_unlock_bh(&dev->tx_lock);
166} 166}
167 167
168/* 168/*
@@ -173,22 +173,21 @@ static int gprs_open(struct net_device *dev)
173{ 173{
174 struct gprs_dev *gp = netdev_priv(dev); 174 struct gprs_dev *gp = netdev_priv(dev);
175 175
176 gprs_write_space(gp->sk); 176 gprs_writeable(gp);
177 return 0; 177 return 0;
178} 178}
179 179
180static int gprs_close(struct net_device *dev) 180static int gprs_close(struct net_device *dev)
181{ 181{
182 struct gprs_dev *gp = netdev_priv(dev);
183
184 netif_stop_queue(dev); 182 netif_stop_queue(dev);
185 flush_work(&gp->tx_work);
186 return 0; 183 return 0;
187} 184}
188 185
189static int gprs_xmit(struct sk_buff *skb, struct net_device *net) 186static int gprs_xmit(struct sk_buff *skb, struct net_device *dev)
190{ 187{
191 struct gprs_dev *dev = netdev_priv(net); 188 struct gprs_dev *gp = netdev_priv(dev);
189 struct sock *sk = gp->sk;
190 int len, err;
192 191
193 switch (skb->protocol) { 192 switch (skb->protocol) {
194 case htons(ETH_P_IP): 193 case htons(ETH_P_IP):
@@ -199,84 +198,50 @@ static int gprs_xmit(struct sk_buff *skb, struct net_device *net)
199 return 0; 198 return 0;
200 } 199 }
201 200
202 spin_lock(&dev->tx_lock); 201 skb_orphan(skb);
203 if (likely(skb_queue_len(&dev->tx_queue) < dev->tx_max)) { 202 skb_set_owner_w(skb, sk);
204 skb_queue_tail(&dev->tx_queue, skb); 203 len = skb->len;
205 skb = NULL; 204 err = pep_write(sk, skb);
206 } 205 if (err) {
207 if (skb_queue_len(&dev->tx_queue) >= dev->tx_max) 206 LIMIT_NETDEBUG(KERN_WARNING"%s: TX error (%d)\n",
208 netif_stop_queue(net); 207 dev->name, err);
209 spin_unlock(&dev->tx_lock); 208 dev->stats.tx_aborted_errors++;
210 209 dev->stats.tx_errors++;
211 schedule_work(&dev->tx_work);
212 if (unlikely(skb))
213 dev_kfree_skb(skb); 210 dev_kfree_skb(skb);
214 return 0; 211 } else {
215}
216
217static void gprs_tx(struct work_struct *work)
218{
219 struct gprs_dev *dev = container_of(work, struct gprs_dev, tx_work);
220 struct sock *sk = dev->sk;
221 struct sk_buff *skb;
222
223 while ((skb = skb_dequeue(&dev->tx_queue)) != NULL) {
224 int err;
225
226 dev->stats.tx_bytes += skb->len;
227 dev->stats.tx_packets++; 212 dev->stats.tx_packets++;
228 213 dev->stats.tx_bytes += len;
229 skb_orphan(skb);
230 skb_set_owner_w(skb, sk);
231
232 lock_sock(sk);
233 err = pep_write(sk, skb);
234 if (err) {
235 LIMIT_NETDEBUG(KERN_WARNING"%s: TX error (%d)\n",
236 dev->net->name, err);
237 dev->stats.tx_aborted_errors++;
238 dev->stats.tx_errors++;
239 }
240 release_sock(sk);
241 } 214 }
242 215
243 lock_sock(sk); 216 if (!pep_writeable(sk))
244 gprs_write_space(sk); 217 netif_stop_queue(dev);
245 release_sock(sk); 218 return 0;
246} 219}
247 220
248static int gprs_set_mtu(struct net_device *net, int new_mtu) 221static int gprs_set_mtu(struct net_device *dev, int new_mtu)
249{ 222{
250 if ((new_mtu < 576) || (new_mtu > (PHONET_MAX_MTU - 11))) 223 if ((new_mtu < 576) || (new_mtu > (PHONET_MAX_MTU - 11)))
251 return -EINVAL; 224 return -EINVAL;
252 225
253 net->mtu = new_mtu; 226 dev->mtu = new_mtu;
254 return 0; 227 return 0;
255} 228}
256 229
257static struct net_device_stats *gprs_get_stats(struct net_device *net) 230static void gprs_setup(struct net_device *dev)
258{ 231{
259 struct gprs_dev *dev = netdev_priv(net); 232 dev->features = NETIF_F_FRAGLIST;
260 233 dev->type = ARPHRD_PHONET_PIPE;
261 return &dev->stats; 234 dev->flags = IFF_POINTOPOINT | IFF_NOARP;
262} 235 dev->mtu = GPRS_DEFAULT_MTU;
263 236 dev->hard_header_len = 0;
264static void gprs_setup(struct net_device *net) 237 dev->addr_len = 0;
265{ 238 dev->tx_queue_len = 10;
266 net->features = NETIF_F_FRAGLIST; 239
267 net->type = ARPHRD_NONE; 240 dev->destructor = free_netdev;
268 net->flags = IFF_POINTOPOINT | IFF_NOARP; 241 dev->open = gprs_open;
269 net->mtu = GPRS_DEFAULT_MTU; 242 dev->stop = gprs_close;
270 net->hard_header_len = 0; 243 dev->hard_start_xmit = gprs_xmit; /* mandatory */
271 net->addr_len = 0; 244 dev->change_mtu = gprs_set_mtu;
272 net->tx_queue_len = 10;
273
274 net->destructor = free_netdev;
275 net->open = gprs_open;
276 net->stop = gprs_close;
277 net->hard_start_xmit = gprs_xmit; /* mandatory */
278 net->change_mtu = gprs_set_mtu;
279 net->get_stats = gprs_get_stats;
280} 245}
281 246
282/* 247/*
@@ -290,28 +255,25 @@ static void gprs_setup(struct net_device *net)
290int gprs_attach(struct sock *sk) 255int gprs_attach(struct sock *sk)
291{ 256{
292 static const char ifname[] = "gprs%d"; 257 static const char ifname[] = "gprs%d";
293 struct gprs_dev *dev; 258 struct gprs_dev *gp;
294 struct net_device *net; 259 struct net_device *dev;
295 int err; 260 int err;
296 261
297 if (unlikely(sk->sk_type == SOCK_STREAM)) 262 if (unlikely(sk->sk_type == SOCK_STREAM))
298 return -EINVAL; /* need packet boundaries */ 263 return -EINVAL; /* need packet boundaries */
299 264
300 /* Create net device */ 265 /* Create net device */
301 net = alloc_netdev(sizeof(*dev), ifname, gprs_setup); 266 dev = alloc_netdev(sizeof(*gp), ifname, gprs_setup);
302 if (!net) 267 if (!dev)
303 return -ENOMEM; 268 return -ENOMEM;
304 dev = netdev_priv(net); 269 gp = netdev_priv(dev);
305 dev->net = net; 270 gp->sk = sk;
306 dev->tx_max = 0; 271 gp->dev = dev;
307 spin_lock_init(&dev->tx_lock); 272
308 skb_queue_head_init(&dev->tx_queue); 273 netif_stop_queue(dev);
309 INIT_WORK(&dev->tx_work, gprs_tx); 274 err = register_netdev(dev);
310
311 netif_stop_queue(net);
312 err = register_netdev(net);
313 if (err) { 275 if (err) {
314 free_netdev(net); 276 free_netdev(dev);
315 return err; 277 return err;
316 } 278 }
317 279
@@ -325,40 +287,38 @@ int gprs_attach(struct sock *sk)
325 err = -EINVAL; 287 err = -EINVAL;
326 goto out_rel; 288 goto out_rel;
327 } 289 }
328 sk->sk_user_data = dev; 290 sk->sk_user_data = gp;
329 dev->old_state_change = sk->sk_state_change; 291 gp->old_state_change = sk->sk_state_change;
330 dev->old_data_ready = sk->sk_data_ready; 292 gp->old_data_ready = sk->sk_data_ready;
331 dev->old_write_space = sk->sk_write_space; 293 gp->old_write_space = sk->sk_write_space;
332 sk->sk_state_change = gprs_state_change; 294 sk->sk_state_change = gprs_state_change;
333 sk->sk_data_ready = gprs_data_ready; 295 sk->sk_data_ready = gprs_data_ready;
334 sk->sk_write_space = gprs_write_space; 296 sk->sk_write_space = gprs_write_space;
335 release_sock(sk); 297 release_sock(sk);
336
337 sock_hold(sk); 298 sock_hold(sk);
338 dev->sk = sk;
339 299
340 printk(KERN_DEBUG"%s: attached\n", net->name); 300 printk(KERN_DEBUG"%s: attached\n", dev->name);
341 return net->ifindex; 301 return dev->ifindex;
342 302
343out_rel: 303out_rel:
344 release_sock(sk); 304 release_sock(sk);
345 unregister_netdev(net); 305 unregister_netdev(dev);
346 return err; 306 return err;
347} 307}
348 308
349void gprs_detach(struct sock *sk) 309void gprs_detach(struct sock *sk)
350{ 310{
351 struct gprs_dev *dev = sk->sk_user_data; 311 struct gprs_dev *gp = sk->sk_user_data;
352 struct net_device *net = dev->net; 312 struct net_device *dev = gp->dev;
353 313
354 lock_sock(sk); 314 lock_sock(sk);
355 sk->sk_user_data = NULL; 315 sk->sk_user_data = NULL;
356 sk->sk_state_change = dev->old_state_change; 316 sk->sk_state_change = gp->old_state_change;
357 sk->sk_data_ready = dev->old_data_ready; 317 sk->sk_data_ready = gp->old_data_ready;
358 sk->sk_write_space = dev->old_write_space; 318 sk->sk_write_space = gp->old_write_space;
359 release_sock(sk); 319 release_sock(sk);
360 320
361 printk(KERN_DEBUG"%s: detached\n", net->name); 321 printk(KERN_DEBUG"%s: detached\n", dev->name);
362 unregister_netdev(net); 322 unregister_netdev(dev);
363 sock_put(sk); 323 sock_put(sk);
364} 324}
diff --git a/net/phonet/pep.c b/net/phonet/pep.c
index bc6d50f83249..bb3e67849b38 100644
--- a/net/phonet/pep.c
+++ b/net/phonet/pep.c
@@ -225,6 +225,7 @@ static int pipe_rcv_status(struct sock *sk, struct sk_buff *skb)
225{ 225{
226 struct pep_sock *pn = pep_sk(sk); 226 struct pep_sock *pn = pep_sk(sk);
227 struct pnpipehdr *hdr = pnp_hdr(skb); 227 struct pnpipehdr *hdr = pnp_hdr(skb);
228 int wake = 0;
228 229
229 if (!pskb_may_pull(skb, sizeof(*hdr) + 4)) 230 if (!pskb_may_pull(skb, sizeof(*hdr) + 4))
230 return -EINVAL; 231 return -EINVAL;
@@ -241,16 +242,16 @@ static int pipe_rcv_status(struct sock *sk, struct sk_buff *skb)
241 case PN_LEGACY_FLOW_CONTROL: 242 case PN_LEGACY_FLOW_CONTROL:
242 switch (hdr->data[4]) { 243 switch (hdr->data[4]) {
243 case PEP_IND_BUSY: 244 case PEP_IND_BUSY:
244 pn->tx_credits = 0; 245 atomic_set(&pn->tx_credits, 0);
245 break; 246 break;
246 case PEP_IND_READY: 247 case PEP_IND_READY:
247 pn->tx_credits = 1; 248 atomic_set(&pn->tx_credits, wake = 1);
248 break; 249 break;
249 } 250 }
250 break; 251 break;
251 case PN_ONE_CREDIT_FLOW_CONTROL: 252 case PN_ONE_CREDIT_FLOW_CONTROL:
252 if (hdr->data[4] == PEP_IND_READY) 253 if (hdr->data[4] == PEP_IND_READY)
253 pn->tx_credits = 1; 254 atomic_set(&pn->tx_credits, wake = 1);
254 break; 255 break;
255 } 256 }
256 break; 257 break;
@@ -258,10 +259,7 @@ static int pipe_rcv_status(struct sock *sk, struct sk_buff *skb)
258 case PN_PEP_IND_ID_MCFC_GRANT_CREDITS: 259 case PN_PEP_IND_ID_MCFC_GRANT_CREDITS:
259 if (pn->tx_fc != PN_MULTI_CREDIT_FLOW_CONTROL) 260 if (pn->tx_fc != PN_MULTI_CREDIT_FLOW_CONTROL)
260 break; 261 break;
261 if (pn->tx_credits + hdr->data[4] > 0xff) 262 atomic_add(wake = hdr->data[4], &pn->tx_credits);
262 pn->tx_credits = 0xff;
263 else
264 pn->tx_credits += hdr->data[4];
265 break; 263 break;
266 264
267 default: 265 default:
@@ -269,7 +267,7 @@ static int pipe_rcv_status(struct sock *sk, struct sk_buff *skb)
269 (unsigned)hdr->data[1]); 267 (unsigned)hdr->data[1]);
270 return -EOPNOTSUPP; 268 return -EOPNOTSUPP;
271 } 269 }
272 if (pn->tx_credits) 270 if (wake)
273 sk->sk_write_space(sk); 271 sk->sk_write_space(sk);
274 return 0; 272 return 0;
275} 273}
@@ -343,7 +341,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
343 } 341 }
344 /* fall through */ 342 /* fall through */
345 case PNS_PEP_DISABLE_REQ: 343 case PNS_PEP_DISABLE_REQ:
346 pn->tx_credits = 0; 344 atomic_set(&pn->tx_credits, 0);
347 pep_reply(sk, skb, PN_PIPE_NO_ERROR, NULL, 0, GFP_ATOMIC); 345 pep_reply(sk, skb, PN_PIPE_NO_ERROR, NULL, 0, GFP_ATOMIC);
348 break; 346 break;
349 347
@@ -390,7 +388,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
390 /* fall through */ 388 /* fall through */
391 case PNS_PIPE_ENABLED_IND: 389 case PNS_PIPE_ENABLED_IND:
392 if (!pn_flow_safe(pn->tx_fc)) { 390 if (!pn_flow_safe(pn->tx_fc)) {
393 pn->tx_credits = 1; 391 atomic_set(&pn->tx_credits, 1);
394 sk->sk_write_space(sk); 392 sk->sk_write_space(sk);
395 } 393 }
396 if (sk->sk_state == TCP_ESTABLISHED) 394 if (sk->sk_state == TCP_ESTABLISHED)
@@ -504,8 +502,9 @@ static int pep_connreq_rcv(struct sock *sk, struct sk_buff *skb)
504 newpn->pn_sk.resource = pn->pn_sk.resource; 502 newpn->pn_sk.resource = pn->pn_sk.resource;
505 skb_queue_head_init(&newpn->ctrlreq_queue); 503 skb_queue_head_init(&newpn->ctrlreq_queue);
506 newpn->pipe_handle = pipe_handle; 504 newpn->pipe_handle = pipe_handle;
505 atomic_set(&newpn->tx_credits, 0);
507 newpn->peer_type = peer_type; 506 newpn->peer_type = peer_type;
508 newpn->rx_credits = newpn->tx_credits = 0; 507 newpn->rx_credits = 0;
509 newpn->rx_fc = newpn->tx_fc = PN_LEGACY_FLOW_CONTROL; 508 newpn->rx_fc = newpn->tx_fc = PN_LEGACY_FLOW_CONTROL;
510 newpn->init_enable = enabled; 509 newpn->init_enable = enabled;
511 510
@@ -821,14 +820,18 @@ static int pipe_skb_send(struct sock *sk, struct sk_buff *skb)
821 struct pep_sock *pn = pep_sk(sk); 820 struct pep_sock *pn = pep_sk(sk);
822 struct pnpipehdr *ph; 821 struct pnpipehdr *ph;
823 822
823 if (pn_flow_safe(pn->tx_fc) &&
824 !atomic_add_unless(&pn->tx_credits, -1, 0)) {
825 kfree_skb(skb);
826 return -ENOBUFS;
827 }
828
824 skb_push(skb, 3); 829 skb_push(skb, 3);
825 skb_reset_transport_header(skb); 830 skb_reset_transport_header(skb);
826 ph = pnp_hdr(skb); 831 ph = pnp_hdr(skb);
827 ph->utid = 0; 832 ph->utid = 0;
828 ph->message_id = PNS_PIPE_DATA; 833 ph->message_id = PNS_PIPE_DATA;
829 ph->pipe_handle = pn->pipe_handle; 834 ph->pipe_handle = pn->pipe_handle;
830 if (pn_flow_safe(pn->tx_fc) && pn->tx_credits)
831 pn->tx_credits--;
832 835
833 return pn_skb_send(sk, skb, &pipe_srv); 836 return pn_skb_send(sk, skb, &pipe_srv);
834} 837}
@@ -866,7 +869,7 @@ disabled:
866 BUG_ON(sk->sk_state != TCP_ESTABLISHED); 869 BUG_ON(sk->sk_state != TCP_ESTABLISHED);
867 870
868 /* Wait until flow control allows TX */ 871 /* Wait until flow control allows TX */
869 done = pn->tx_credits > 0; 872 done = atomic_read(&pn->tx_credits);
870 while (!done) { 873 while (!done) {
871 DEFINE_WAIT(wait); 874 DEFINE_WAIT(wait);
872 875
@@ -881,7 +884,7 @@ disabled:
881 884
882 prepare_to_wait(&sk->sk_socket->wait, &wait, 885 prepare_to_wait(&sk->sk_socket->wait, &wait,
883 TASK_INTERRUPTIBLE); 886 TASK_INTERRUPTIBLE);
884 done = sk_wait_event(sk, &timeo, pn->tx_credits > 0); 887 done = sk_wait_event(sk, &timeo, atomic_read(&pn->tx_credits));
885 finish_wait(&sk->sk_socket->wait, &wait); 888 finish_wait(&sk->sk_socket->wait, &wait);
886 889
887 if (sk->sk_state != TCP_ESTABLISHED) 890 if (sk->sk_state != TCP_ESTABLISHED)
@@ -895,7 +898,8 @@ disabled:
895 goto out; 898 goto out;
896 skb_reserve(skb, MAX_PHONET_HEADER + 3); 899 skb_reserve(skb, MAX_PHONET_HEADER + 3);
897 900
898 if (sk->sk_state != TCP_ESTABLISHED || !pn->tx_credits) 901 if (sk->sk_state != TCP_ESTABLISHED ||
902 !atomic_read(&pn->tx_credits))
899 goto disabled; /* sock_alloc_send_skb might sleep */ 903 goto disabled; /* sock_alloc_send_skb might sleep */
900 } 904 }
901 905
@@ -917,7 +921,7 @@ int pep_writeable(struct sock *sk)
917{ 921{
918 struct pep_sock *pn = pep_sk(sk); 922 struct pep_sock *pn = pep_sk(sk);
919 923
920 return (sk->sk_state == TCP_ESTABLISHED) ? pn->tx_credits : 0; 924 return atomic_read(&pn->tx_credits);
921} 925}
922 926
923int pep_write(struct sock *sk, struct sk_buff *skb) 927int pep_write(struct sock *sk, struct sk_buff *skb)
diff --git a/net/phonet/pn_dev.c b/net/phonet/pn_dev.c
index f93ff8ef47d0..5491bf5e354b 100644
--- a/net/phonet/pn_dev.c
+++ b/net/phonet/pn_dev.c
@@ -76,7 +76,7 @@ struct net_device *phonet_device_get(struct net *net)
76 dev = pnd->netdev; 76 dev = pnd->netdev;
77 BUG_ON(!dev); 77 BUG_ON(!dev);
78 78
79 if (dev_net(dev) == net && 79 if (net_eq(dev_net(dev), net) &&
80 (dev->reg_state == NETREG_REGISTERED) && 80 (dev->reg_state == NETREG_REGISTERED) &&
81 ((pnd->netdev->flags & IFF_UP)) == IFF_UP) 81 ((pnd->netdev->flags & IFF_UP)) == IFF_UP)
82 break; 82 break;
@@ -140,12 +140,14 @@ u8 phonet_address_get(struct net_device *dev, u8 addr)
140 return addr; 140 return addr;
141} 141}
142 142
143int phonet_address_lookup(u8 addr) 143int phonet_address_lookup(struct net *net, u8 addr)
144{ 144{
145 struct phonet_device *pnd; 145 struct phonet_device *pnd;
146 146
147 spin_lock_bh(&pndevs.lock); 147 spin_lock_bh(&pndevs.lock);
148 list_for_each_entry(pnd, &pndevs.list, list) { 148 list_for_each_entry(pnd, &pndevs.list, list) {
149 if (!net_eq(dev_net(pnd->netdev), net))
150 continue;
149 /* Don't allow unregistering devices! */ 151 /* Don't allow unregistering devices! */
150 if ((pnd->netdev->reg_state != NETREG_REGISTERED) || 152 if ((pnd->netdev->reg_state != NETREG_REGISTERED) ||
151 ((pnd->netdev->flags & IFF_UP)) != IFF_UP) 153 ((pnd->netdev->flags & IFF_UP)) != IFF_UP)
diff --git a/net/phonet/socket.c b/net/phonet/socket.c
index d81740187fb4..ada2a35bf7a2 100644
--- a/net/phonet/socket.c
+++ b/net/phonet/socket.c
@@ -57,7 +57,7 @@ static struct {
57 * Find address based on socket address, match only certain fields. 57 * Find address based on socket address, match only certain fields.
58 * Also grab sock if it was found. Remember to sock_put it later. 58 * Also grab sock if it was found. Remember to sock_put it later.
59 */ 59 */
60struct sock *pn_find_sock_by_sa(const struct sockaddr_pn *spn) 60struct sock *pn_find_sock_by_sa(struct net *net, const struct sockaddr_pn *spn)
61{ 61{
62 struct hlist_node *node; 62 struct hlist_node *node;
63 struct sock *sknode; 63 struct sock *sknode;
@@ -71,6 +71,8 @@ struct sock *pn_find_sock_by_sa(const struct sockaddr_pn *spn)
71 struct pn_sock *pn = pn_sk(sknode); 71 struct pn_sock *pn = pn_sk(sknode);
72 BUG_ON(!pn->sobject); /* unbound socket */ 72 BUG_ON(!pn->sobject); /* unbound socket */
73 73
74 if (!net_eq(sock_net(sknode), net))
75 continue;
74 if (pn_port(obj)) { 76 if (pn_port(obj)) {
75 /* Look up socket by port */ 77 /* Look up socket by port */
76 if (pn_port(pn->sobject) != pn_port(obj)) 78 if (pn_port(pn->sobject) != pn_port(obj))
@@ -130,7 +132,7 @@ static int pn_socket_bind(struct socket *sock, struct sockaddr *addr, int len)
130 132
131 handle = pn_sockaddr_get_object((struct sockaddr_pn *)addr); 133 handle = pn_sockaddr_get_object((struct sockaddr_pn *)addr);
132 saddr = pn_addr(handle); 134 saddr = pn_addr(handle);
133 if (saddr && phonet_address_lookup(saddr)) 135 if (saddr && phonet_address_lookup(sock_net(sk), saddr))
134 return -EADDRNOTAVAIL; 136 return -EADDRNOTAVAIL;
135 137
136 lock_sock(sk); 138 lock_sock(sk);
@@ -225,7 +227,7 @@ static unsigned int pn_socket_poll(struct file *file, struct socket *sock,
225 if (!mask && sk->sk_state == TCP_CLOSE_WAIT) 227 if (!mask && sk->sk_state == TCP_CLOSE_WAIT)
226 return POLLHUP; 228 return POLLHUP;
227 229
228 if (sk->sk_state == TCP_ESTABLISHED && pn->tx_credits) 230 if (sk->sk_state == TCP_ESTABLISHED && atomic_read(&pn->tx_credits))
229 mask |= POLLOUT | POLLWRNORM | POLLWRBAND; 231 mask |= POLLOUT | POLLWRNORM | POLLWRBAND;
230 232
231 return mask; 233 return mask;
@@ -361,6 +363,7 @@ static DEFINE_MUTEX(port_mutex);
361int pn_sock_get_port(struct sock *sk, unsigned short sport) 363int pn_sock_get_port(struct sock *sk, unsigned short sport)
362{ 364{
363 static int port_cur; 365 static int port_cur;
366 struct net *net = sock_net(sk);
364 struct pn_sock *pn = pn_sk(sk); 367 struct pn_sock *pn = pn_sk(sk);
365 struct sockaddr_pn try_sa; 368 struct sockaddr_pn try_sa;
366 struct sock *tmpsk; 369 struct sock *tmpsk;
@@ -381,7 +384,7 @@ int pn_sock_get_port(struct sock *sk, unsigned short sport)
381 port_cur = pmin; 384 port_cur = pmin;
382 385
383 pn_sockaddr_set_port(&try_sa, port_cur); 386 pn_sockaddr_set_port(&try_sa, port_cur);
384 tmpsk = pn_find_sock_by_sa(&try_sa); 387 tmpsk = pn_find_sock_by_sa(net, &try_sa);
385 if (tmpsk == NULL) { 388 if (tmpsk == NULL) {
386 sport = port_cur; 389 sport = port_cur;
387 goto found; 390 goto found;
@@ -391,7 +394,7 @@ int pn_sock_get_port(struct sock *sk, unsigned short sport)
391 } else { 394 } else {
392 /* try to find specific port */ 395 /* try to find specific port */
393 pn_sockaddr_set_port(&try_sa, sport); 396 pn_sockaddr_set_port(&try_sa, sport);
394 tmpsk = pn_find_sock_by_sa(&try_sa); 397 tmpsk = pn_find_sock_by_sa(net, &try_sa);
395 if (tmpsk == NULL) 398 if (tmpsk == NULL)
396 /* No sock there! We can use that port... */ 399 /* No sock there! We can use that port... */
397 goto found; 400 goto found;
diff --git a/net/phonet/sysctl.c b/net/phonet/sysctl.c
index 600a4309b8c8..7b5749ee2765 100644
--- a/net/phonet/sysctl.c
+++ b/net/phonet/sysctl.c
@@ -89,13 +89,13 @@ static struct ctl_table phonet_table[] = {
89 .data = &local_port_range, 89 .data = &local_port_range,
90 .maxlen = sizeof(local_port_range), 90 .maxlen = sizeof(local_port_range),
91 .mode = 0644, 91 .mode = 0644,
92 .proc_handler = &proc_local_port_range, 92 .proc_handler = proc_local_port_range,
93 .strategy = NULL, 93 .strategy = NULL,
94 }, 94 },
95 { .ctl_name = 0 } 95 { .ctl_name = 0 }
96}; 96};
97 97
98struct ctl_path phonet_ctl_path[] = { 98static struct ctl_path phonet_ctl_path[] = {
99 { .procname = "net", .ctl_name = CTL_NET, }, 99 { .procname = "net", .ctl_name = CTL_NET, },
100 { .procname = "phonet", .ctl_name = CTL_UNNUMBERED, }, 100 { .procname = "phonet", .ctl_name = CTL_UNNUMBERED, },
101 { }, 101 { },
diff --git a/net/rfkill/rfkill-input.c b/net/rfkill/rfkill-input.c
index bfdade72e066..84efde97c5a7 100644
--- a/net/rfkill/rfkill-input.c
+++ b/net/rfkill/rfkill-input.c
@@ -24,138 +24,318 @@ MODULE_AUTHOR("Dmitry Torokhov <dtor@mail.ru>");
24MODULE_DESCRIPTION("Input layer to RF switch connector"); 24MODULE_DESCRIPTION("Input layer to RF switch connector");
25MODULE_LICENSE("GPL"); 25MODULE_LICENSE("GPL");
26 26
27enum rfkill_input_master_mode {
28 RFKILL_INPUT_MASTER_DONOTHING = 0,
29 RFKILL_INPUT_MASTER_RESTORE = 1,
30 RFKILL_INPUT_MASTER_UNBLOCKALL = 2,
31 RFKILL_INPUT_MASTER_MAX, /* marker */
32};
33
34/* Delay (in ms) between consecutive switch ops */
35#define RFKILL_OPS_DELAY 200
36
37static enum rfkill_input_master_mode rfkill_master_switch_mode =
38 RFKILL_INPUT_MASTER_UNBLOCKALL;
39module_param_named(master_switch_mode, rfkill_master_switch_mode, uint, 0);
40MODULE_PARM_DESC(master_switch_mode,
41 "SW_RFKILL_ALL ON should: 0=do nothing; 1=restore; 2=unblock all");
42
43enum rfkill_global_sched_op {
44 RFKILL_GLOBAL_OP_EPO = 0,
45 RFKILL_GLOBAL_OP_RESTORE,
46 RFKILL_GLOBAL_OP_UNLOCK,
47 RFKILL_GLOBAL_OP_UNBLOCK,
48};
49
50/*
51 * Currently, the code marked with RFKILL_NEED_SWSET is inactive.
52 * If handling of EV_SW SW_WLAN/WWAN/BLUETOOTH/etc is needed in the
53 * future, when such events are added, that code will be necessary.
54 */
55
27struct rfkill_task { 56struct rfkill_task {
28 struct work_struct work; 57 struct delayed_work dwork;
29 enum rfkill_type type; 58
30 struct mutex mutex; /* ensures that task is serialized */ 59 /* ensures that task is serialized */
31 spinlock_t lock; /* for accessing last and desired state */ 60 struct mutex mutex;
32 unsigned long last; /* last schedule */ 61
33 enum rfkill_state desired_state; /* on/off */ 62 /* protects everything below */
63 spinlock_t lock;
64
65 /* pending regular switch operations (1=pending) */
66 unsigned long sw_pending[BITS_TO_LONGS(RFKILL_TYPE_MAX)];
67
68#ifdef RFKILL_NEED_SWSET
69 /* set operation pending (1=pending) */
70 unsigned long sw_setpending[BITS_TO_LONGS(RFKILL_TYPE_MAX)];
71
72 /* desired state for pending set operation (1=unblock) */
73 unsigned long sw_newstate[BITS_TO_LONGS(RFKILL_TYPE_MAX)];
74#endif
75
76 /* should the state be complemented (1=yes) */
77 unsigned long sw_togglestate[BITS_TO_LONGS(RFKILL_TYPE_MAX)];
78
79 bool global_op_pending;
80 enum rfkill_global_sched_op op;
81
82 /* last time it was scheduled */
83 unsigned long last_scheduled;
34}; 84};
35 85
86static void __rfkill_handle_global_op(enum rfkill_global_sched_op op)
87{
88 unsigned int i;
89
90 switch (op) {
91 case RFKILL_GLOBAL_OP_EPO:
92 rfkill_epo();
93 break;
94 case RFKILL_GLOBAL_OP_RESTORE:
95 rfkill_restore_states();
96 break;
97 case RFKILL_GLOBAL_OP_UNLOCK:
98 rfkill_remove_epo_lock();
99 break;
100 case RFKILL_GLOBAL_OP_UNBLOCK:
101 rfkill_remove_epo_lock();
102 for (i = 0; i < RFKILL_TYPE_MAX; i++)
103 rfkill_switch_all(i, RFKILL_STATE_UNBLOCKED);
104 break;
105 default:
106 /* memory corruption or bug, fail safely */
107 rfkill_epo();
108 WARN(1, "Unknown requested operation %d! "
109 "rfkill Emergency Power Off activated\n",
110 op);
111 }
112}
113
114#ifdef RFKILL_NEED_SWSET
115static void __rfkill_handle_normal_op(const enum rfkill_type type,
116 const bool sp, const bool s, const bool c)
117{
118 enum rfkill_state state;
119
120 if (sp)
121 state = (s) ? RFKILL_STATE_UNBLOCKED :
122 RFKILL_STATE_SOFT_BLOCKED;
123 else
124 state = rfkill_get_global_state(type);
125
126 if (c)
127 state = rfkill_state_complement(state);
128
129 rfkill_switch_all(type, state);
130}
131#else
132static void __rfkill_handle_normal_op(const enum rfkill_type type,
133 const bool c)
134{
135 enum rfkill_state state;
136
137 state = rfkill_get_global_state(type);
138 if (c)
139 state = rfkill_state_complement(state);
140
141 rfkill_switch_all(type, state);
142}
143#endif
144
36static void rfkill_task_handler(struct work_struct *work) 145static void rfkill_task_handler(struct work_struct *work)
37{ 146{
38 struct rfkill_task *task = container_of(work, struct rfkill_task, work); 147 struct rfkill_task *task = container_of(work,
148 struct rfkill_task, dwork.work);
149 bool doit = true;
39 150
40 mutex_lock(&task->mutex); 151 mutex_lock(&task->mutex);
41 152
42 rfkill_switch_all(task->type, task->desired_state); 153 spin_lock_irq(&task->lock);
154 while (doit) {
155 if (task->global_op_pending) {
156 enum rfkill_global_sched_op op = task->op;
157 task->global_op_pending = false;
158 memset(task->sw_pending, 0, sizeof(task->sw_pending));
159 spin_unlock_irq(&task->lock);
160
161 __rfkill_handle_global_op(op);
162
163 /* make sure we do at least one pass with
164 * !task->global_op_pending */
165 spin_lock_irq(&task->lock);
166 continue;
167 } else if (!rfkill_is_epo_lock_active()) {
168 unsigned int i = 0;
169
170 while (!task->global_op_pending &&
171 i < RFKILL_TYPE_MAX) {
172 if (test_and_clear_bit(i, task->sw_pending)) {
173 bool c;
174#ifdef RFKILL_NEED_SWSET
175 bool sp, s;
176 sp = test_and_clear_bit(i,
177 task->sw_setpending);
178 s = test_bit(i, task->sw_newstate);
179#endif
180 c = test_and_clear_bit(i,
181 task->sw_togglestate);
182 spin_unlock_irq(&task->lock);
183
184#ifdef RFKILL_NEED_SWSET
185 __rfkill_handle_normal_op(i, sp, s, c);
186#else
187 __rfkill_handle_normal_op(i, c);
188#endif
189
190 spin_lock_irq(&task->lock);
191 }
192 i++;
193 }
194 }
195 doit = task->global_op_pending;
196 }
197 spin_unlock_irq(&task->lock);
43 198
44 mutex_unlock(&task->mutex); 199 mutex_unlock(&task->mutex);
45} 200}
46 201
47static void rfkill_task_epo_handler(struct work_struct *work) 202static struct rfkill_task rfkill_task = {
203 .dwork = __DELAYED_WORK_INITIALIZER(rfkill_task.dwork,
204 rfkill_task_handler),
205 .mutex = __MUTEX_INITIALIZER(rfkill_task.mutex),
206 .lock = __SPIN_LOCK_UNLOCKED(rfkill_task.lock),
207};
208
209static unsigned long rfkill_ratelimit(const unsigned long last)
48{ 210{
49 rfkill_epo(); 211 const unsigned long delay = msecs_to_jiffies(RFKILL_OPS_DELAY);
212 return (time_after(jiffies, last + delay)) ? 0 : delay;
50} 213}
51 214
52static DECLARE_WORK(epo_work, rfkill_task_epo_handler); 215static void rfkill_schedule_ratelimited(void)
216{
217 if (!delayed_work_pending(&rfkill_task.dwork)) {
218 schedule_delayed_work(&rfkill_task.dwork,
219 rfkill_ratelimit(rfkill_task.last_scheduled));
220 rfkill_task.last_scheduled = jiffies;
221 }
222}
53 223
54static void rfkill_schedule_epo(void) 224static void rfkill_schedule_global_op(enum rfkill_global_sched_op op)
55{ 225{
56 schedule_work(&epo_work); 226 unsigned long flags;
227
228 spin_lock_irqsave(&rfkill_task.lock, flags);
229 rfkill_task.op = op;
230 rfkill_task.global_op_pending = true;
231 if (op == RFKILL_GLOBAL_OP_EPO && !rfkill_is_epo_lock_active()) {
232 /* bypass the limiter for EPO */
233 cancel_delayed_work(&rfkill_task.dwork);
234 schedule_delayed_work(&rfkill_task.dwork, 0);
235 rfkill_task.last_scheduled = jiffies;
236 } else
237 rfkill_schedule_ratelimited();
238 spin_unlock_irqrestore(&rfkill_task.lock, flags);
57} 239}
58 240
59static void rfkill_schedule_set(struct rfkill_task *task, 241#ifdef RFKILL_NEED_SWSET
242/* Use this if you need to add EV_SW SW_WLAN/WWAN/BLUETOOTH/etc handling */
243
244static void rfkill_schedule_set(enum rfkill_type type,
60 enum rfkill_state desired_state) 245 enum rfkill_state desired_state)
61{ 246{
62 unsigned long flags; 247 unsigned long flags;
63 248
64 if (unlikely(work_pending(&epo_work))) 249 if (rfkill_is_epo_lock_active())
65 return; 250 return;
66 251
67 spin_lock_irqsave(&task->lock, flags); 252 spin_lock_irqsave(&rfkill_task.lock, flags);
68 253 if (!rfkill_task.global_op_pending) {
69 if (time_after(jiffies, task->last + msecs_to_jiffies(200))) { 254 set_bit(type, rfkill_task.sw_pending);
70 task->desired_state = desired_state; 255 set_bit(type, rfkill_task.sw_setpending);
71 task->last = jiffies; 256 clear_bit(type, rfkill_task.sw_togglestate);
72 schedule_work(&task->work); 257 if (desired_state)
258 set_bit(type, rfkill_task.sw_newstate);
259 else
260 clear_bit(type, rfkill_task.sw_newstate);
261 rfkill_schedule_ratelimited();
73 } 262 }
74 263 spin_unlock_irqrestore(&rfkill_task.lock, flags);
75 spin_unlock_irqrestore(&task->lock, flags);
76} 264}
265#endif
77 266
78static void rfkill_schedule_toggle(struct rfkill_task *task) 267static void rfkill_schedule_toggle(enum rfkill_type type)
79{ 268{
80 unsigned long flags; 269 unsigned long flags;
81 270
82 if (unlikely(work_pending(&epo_work))) 271 if (rfkill_is_epo_lock_active())
83 return; 272 return;
84 273
85 spin_lock_irqsave(&task->lock, flags); 274 spin_lock_irqsave(&rfkill_task.lock, flags);
86 275 if (!rfkill_task.global_op_pending) {
87 if (time_after(jiffies, task->last + msecs_to_jiffies(200))) { 276 set_bit(type, rfkill_task.sw_pending);
88 task->desired_state = 277 change_bit(type, rfkill_task.sw_togglestate);
89 rfkill_state_complement(task->desired_state); 278 rfkill_schedule_ratelimited();
90 task->last = jiffies;
91 schedule_work(&task->work);
92 } 279 }
93 280 spin_unlock_irqrestore(&rfkill_task.lock, flags);
94 spin_unlock_irqrestore(&task->lock, flags);
95} 281}
96 282
97#define DEFINE_RFKILL_TASK(n, t) \
98 struct rfkill_task n = { \
99 .work = __WORK_INITIALIZER(n.work, \
100 rfkill_task_handler), \
101 .type = t, \
102 .mutex = __MUTEX_INITIALIZER(n.mutex), \
103 .lock = __SPIN_LOCK_UNLOCKED(n.lock), \
104 .desired_state = RFKILL_STATE_UNBLOCKED, \
105 }
106
107static DEFINE_RFKILL_TASK(rfkill_wlan, RFKILL_TYPE_WLAN);
108static DEFINE_RFKILL_TASK(rfkill_bt, RFKILL_TYPE_BLUETOOTH);
109static DEFINE_RFKILL_TASK(rfkill_uwb, RFKILL_TYPE_UWB);
110static DEFINE_RFKILL_TASK(rfkill_wimax, RFKILL_TYPE_WIMAX);
111static DEFINE_RFKILL_TASK(rfkill_wwan, RFKILL_TYPE_WWAN);
112
113static void rfkill_schedule_evsw_rfkillall(int state) 283static void rfkill_schedule_evsw_rfkillall(int state)
114{ 284{
115 /* EVERY radio type. state != 0 means radios ON */
116 /* handle EPO (emergency power off) through shortcut */
117 if (state) { 285 if (state) {
118 rfkill_schedule_set(&rfkill_wwan, 286 switch (rfkill_master_switch_mode) {
119 RFKILL_STATE_UNBLOCKED); 287 case RFKILL_INPUT_MASTER_UNBLOCKALL:
120 rfkill_schedule_set(&rfkill_wimax, 288 rfkill_schedule_global_op(RFKILL_GLOBAL_OP_UNBLOCK);
121 RFKILL_STATE_UNBLOCKED); 289 break;
122 rfkill_schedule_set(&rfkill_uwb, 290 case RFKILL_INPUT_MASTER_RESTORE:
123 RFKILL_STATE_UNBLOCKED); 291 rfkill_schedule_global_op(RFKILL_GLOBAL_OP_RESTORE);
124 rfkill_schedule_set(&rfkill_bt, 292 break;
125 RFKILL_STATE_UNBLOCKED); 293 case RFKILL_INPUT_MASTER_DONOTHING:
126 rfkill_schedule_set(&rfkill_wlan, 294 rfkill_schedule_global_op(RFKILL_GLOBAL_OP_UNLOCK);
127 RFKILL_STATE_UNBLOCKED); 295 break;
296 default:
297 /* memory corruption or driver bug! fail safely */
298 rfkill_schedule_global_op(RFKILL_GLOBAL_OP_EPO);
299 WARN(1, "Unknown rfkill_master_switch_mode (%d), "
300 "driver bug or memory corruption detected!\n",
301 rfkill_master_switch_mode);
302 break;
303 }
128 } else 304 } else
129 rfkill_schedule_epo(); 305 rfkill_schedule_global_op(RFKILL_GLOBAL_OP_EPO);
130} 306}
131 307
132static void rfkill_event(struct input_handle *handle, unsigned int type, 308static void rfkill_event(struct input_handle *handle, unsigned int type,
133 unsigned int code, int data) 309 unsigned int code, int data)
134{ 310{
135 if (type == EV_KEY && data == 1) { 311 if (type == EV_KEY && data == 1) {
312 enum rfkill_type t;
313
136 switch (code) { 314 switch (code) {
137 case KEY_WLAN: 315 case KEY_WLAN:
138 rfkill_schedule_toggle(&rfkill_wlan); 316 t = RFKILL_TYPE_WLAN;
139 break; 317 break;
140 case KEY_BLUETOOTH: 318 case KEY_BLUETOOTH:
141 rfkill_schedule_toggle(&rfkill_bt); 319 t = RFKILL_TYPE_BLUETOOTH;
142 break; 320 break;
143 case KEY_UWB: 321 case KEY_UWB:
144 rfkill_schedule_toggle(&rfkill_uwb); 322 t = RFKILL_TYPE_UWB;
145 break; 323 break;
146 case KEY_WIMAX: 324 case KEY_WIMAX:
147 rfkill_schedule_toggle(&rfkill_wimax); 325 t = RFKILL_TYPE_WIMAX;
148 break; 326 break;
149 default: 327 default:
150 break; 328 return;
151 } 329 }
330 rfkill_schedule_toggle(t);
331 return;
152 } else if (type == EV_SW) { 332 } else if (type == EV_SW) {
153 switch (code) { 333 switch (code) {
154 case SW_RFKILL_ALL: 334 case SW_RFKILL_ALL:
155 rfkill_schedule_evsw_rfkillall(data); 335 rfkill_schedule_evsw_rfkillall(data);
156 break; 336 return;
157 default: 337 default:
158 break; 338 return;
159 } 339 }
160 } 340 }
161} 341}
@@ -256,18 +436,23 @@ static struct input_handler rfkill_handler = {
256 436
257static int __init rfkill_handler_init(void) 437static int __init rfkill_handler_init(void)
258{ 438{
259 unsigned long last_run = jiffies - msecs_to_jiffies(500); 439 if (rfkill_master_switch_mode >= RFKILL_INPUT_MASTER_MAX)
260 rfkill_wlan.last = last_run; 440 return -EINVAL;
261 rfkill_bt.last = last_run; 441
262 rfkill_uwb.last = last_run; 442 /*
263 rfkill_wimax.last = last_run; 443 * The penalty to not doing this is a possible RFKILL_OPS_DELAY delay
444 * at the first use. Acceptable, but if we can avoid it, why not?
445 */
446 rfkill_task.last_scheduled =
447 jiffies - msecs_to_jiffies(RFKILL_OPS_DELAY) - 1;
264 return input_register_handler(&rfkill_handler); 448 return input_register_handler(&rfkill_handler);
265} 449}
266 450
267static void __exit rfkill_handler_exit(void) 451static void __exit rfkill_handler_exit(void)
268{ 452{
269 input_unregister_handler(&rfkill_handler); 453 input_unregister_handler(&rfkill_handler);
270 flush_scheduled_work(); 454 cancel_delayed_work_sync(&rfkill_task.dwork);
455 rfkill_remove_epo_lock();
271} 456}
272 457
273module_init(rfkill_handler_init); 458module_init(rfkill_handler_init);
diff --git a/net/rfkill/rfkill-input.h b/net/rfkill/rfkill-input.h
index bbfa646157c6..fe8df6b5b935 100644
--- a/net/rfkill/rfkill-input.h
+++ b/net/rfkill/rfkill-input.h
@@ -14,5 +14,8 @@
14void rfkill_switch_all(enum rfkill_type type, enum rfkill_state state); 14void rfkill_switch_all(enum rfkill_type type, enum rfkill_state state);
15void rfkill_epo(void); 15void rfkill_epo(void);
16void rfkill_restore_states(void); 16void rfkill_restore_states(void);
17void rfkill_remove_epo_lock(void);
18bool rfkill_is_epo_lock_active(void);
19enum rfkill_state rfkill_get_global_state(const enum rfkill_type type);
17 20
18#endif /* __RFKILL_INPUT_H */ 21#endif /* __RFKILL_INPUT_H */
diff --git a/net/rfkill/rfkill.c b/net/rfkill/rfkill.c
index 25ba3bd57e66..3c94f76d5525 100644
--- a/net/rfkill/rfkill.c
+++ b/net/rfkill/rfkill.c
@@ -51,51 +51,7 @@ struct rfkill_gsw_state {
51 51
52static struct rfkill_gsw_state rfkill_global_states[RFKILL_TYPE_MAX]; 52static struct rfkill_gsw_state rfkill_global_states[RFKILL_TYPE_MAX];
53static unsigned long rfkill_states_lockdflt[BITS_TO_LONGS(RFKILL_TYPE_MAX)]; 53static unsigned long rfkill_states_lockdflt[BITS_TO_LONGS(RFKILL_TYPE_MAX)];
54 54static bool rfkill_epo_lock_active;
55static BLOCKING_NOTIFIER_HEAD(rfkill_notifier_list);
56
57
58/**
59 * register_rfkill_notifier - Add notifier to rfkill notifier chain
60 * @nb: pointer to the new entry to add to the chain
61 *
62 * See blocking_notifier_chain_register() for return value and further
63 * observations.
64 *
65 * Adds a notifier to the rfkill notifier chain. The chain will be
66 * called with a pointer to the relevant rfkill structure as a parameter,
67 * refer to include/linux/rfkill.h for the possible events.
68 *
69 * Notifiers added to this chain are to always return NOTIFY_DONE. This
70 * chain is a blocking notifier chain: notifiers can sleep.
71 *
72 * Calls to this chain may have been done through a workqueue. One must
73 * assume unordered asynchronous behaviour, there is no way to know if
74 * actions related to the event that generated the notification have been
75 * carried out already.
76 */
77int register_rfkill_notifier(struct notifier_block *nb)
78{
79 BUG_ON(!nb);
80 return blocking_notifier_chain_register(&rfkill_notifier_list, nb);
81}
82EXPORT_SYMBOL_GPL(register_rfkill_notifier);
83
84/**
85 * unregister_rfkill_notifier - remove notifier from rfkill notifier chain
86 * @nb: pointer to the entry to remove from the chain
87 *
88 * See blocking_notifier_chain_unregister() for return value and further
89 * observations.
90 *
91 * Removes a notifier from the rfkill notifier chain.
92 */
93int unregister_rfkill_notifier(struct notifier_block *nb)
94{
95 BUG_ON(!nb);
96 return blocking_notifier_chain_unregister(&rfkill_notifier_list, nb);
97}
98EXPORT_SYMBOL_GPL(unregister_rfkill_notifier);
99 55
100 56
101static void rfkill_led_trigger(struct rfkill *rfkill, 57static void rfkill_led_trigger(struct rfkill *rfkill,
@@ -123,12 +79,9 @@ static void rfkill_led_trigger_activate(struct led_classdev *led)
123} 79}
124#endif /* CONFIG_RFKILL_LEDS */ 80#endif /* CONFIG_RFKILL_LEDS */
125 81
126static void notify_rfkill_state_change(struct rfkill *rfkill) 82static void rfkill_uevent(struct rfkill *rfkill)
127{ 83{
128 rfkill_led_trigger(rfkill, rfkill->state); 84 kobject_uevent(&rfkill->dev.kobj, KOBJ_CHANGE);
129 blocking_notifier_call_chain(&rfkill_notifier_list,
130 RFKILL_STATE_CHANGED,
131 rfkill);
132} 85}
133 86
134static void update_rfkill_state(struct rfkill *rfkill) 87static void update_rfkill_state(struct rfkill *rfkill)
@@ -141,7 +94,7 @@ static void update_rfkill_state(struct rfkill *rfkill)
141 oldstate = rfkill->state; 94 oldstate = rfkill->state;
142 rfkill->state = newstate; 95 rfkill->state = newstate;
143 if (oldstate != newstate) 96 if (oldstate != newstate)
144 notify_rfkill_state_change(rfkill); 97 rfkill_uevent(rfkill);
145 } 98 }
146 mutex_unlock(&rfkill->mutex); 99 mutex_unlock(&rfkill->mutex);
147 } 100 }
@@ -219,7 +172,7 @@ static int rfkill_toggle_radio(struct rfkill *rfkill,
219 } 172 }
220 173
221 if (force || rfkill->state != oldstate) 174 if (force || rfkill->state != oldstate)
222 notify_rfkill_state_change(rfkill); 175 rfkill_uevent(rfkill);
223 176
224 return retval; 177 return retval;
225} 178}
@@ -264,11 +217,14 @@ static void __rfkill_switch_all(const enum rfkill_type type,
264 * 217 *
265 * Acquires rfkill_global_mutex and calls __rfkill_switch_all(@type, @state). 218 * Acquires rfkill_global_mutex and calls __rfkill_switch_all(@type, @state).
266 * Please refer to __rfkill_switch_all() for details. 219 * Please refer to __rfkill_switch_all() for details.
220 *
221 * Does nothing if the EPO lock is active.
267 */ 222 */
268void rfkill_switch_all(enum rfkill_type type, enum rfkill_state state) 223void rfkill_switch_all(enum rfkill_type type, enum rfkill_state state)
269{ 224{
270 mutex_lock(&rfkill_global_mutex); 225 mutex_lock(&rfkill_global_mutex);
271 __rfkill_switch_all(type, state); 226 if (!rfkill_epo_lock_active)
227 __rfkill_switch_all(type, state);
272 mutex_unlock(&rfkill_global_mutex); 228 mutex_unlock(&rfkill_global_mutex);
273} 229}
274EXPORT_SYMBOL(rfkill_switch_all); 230EXPORT_SYMBOL(rfkill_switch_all);
@@ -289,6 +245,7 @@ void rfkill_epo(void)
289 245
290 mutex_lock(&rfkill_global_mutex); 246 mutex_lock(&rfkill_global_mutex);
291 247
248 rfkill_epo_lock_active = true;
292 list_for_each_entry(rfkill, &rfkill_list, node) { 249 list_for_each_entry(rfkill, &rfkill_list, node) {
293 mutex_lock(&rfkill->mutex); 250 mutex_lock(&rfkill->mutex);
294 rfkill_toggle_radio(rfkill, RFKILL_STATE_SOFT_BLOCKED, 1); 251 rfkill_toggle_radio(rfkill, RFKILL_STATE_SOFT_BLOCKED, 1);
@@ -317,6 +274,7 @@ void rfkill_restore_states(void)
317 274
318 mutex_lock(&rfkill_global_mutex); 275 mutex_lock(&rfkill_global_mutex);
319 276
277 rfkill_epo_lock_active = false;
320 for (i = 0; i < RFKILL_TYPE_MAX; i++) 278 for (i = 0; i < RFKILL_TYPE_MAX; i++)
321 __rfkill_switch_all(i, rfkill_global_states[i].default_state); 279 __rfkill_switch_all(i, rfkill_global_states[i].default_state);
322 mutex_unlock(&rfkill_global_mutex); 280 mutex_unlock(&rfkill_global_mutex);
@@ -324,6 +282,48 @@ void rfkill_restore_states(void)
324EXPORT_SYMBOL_GPL(rfkill_restore_states); 282EXPORT_SYMBOL_GPL(rfkill_restore_states);
325 283
326/** 284/**
285 * rfkill_remove_epo_lock - unlock state changes
286 *
287 * Used by rfkill-input manually unlock state changes, when
288 * the EPO switch is deactivated.
289 */
290void rfkill_remove_epo_lock(void)
291{
292 mutex_lock(&rfkill_global_mutex);
293 rfkill_epo_lock_active = false;
294 mutex_unlock(&rfkill_global_mutex);
295}
296EXPORT_SYMBOL_GPL(rfkill_remove_epo_lock);
297
298/**
299 * rfkill_is_epo_lock_active - returns true EPO is active
300 *
301 * Returns 0 (false) if there is NOT an active EPO contidion,
302 * and 1 (true) if there is an active EPO contition, which
303 * locks all radios in one of the BLOCKED states.
304 *
305 * Can be called in atomic context.
306 */
307bool rfkill_is_epo_lock_active(void)
308{
309 return rfkill_epo_lock_active;
310}
311EXPORT_SYMBOL_GPL(rfkill_is_epo_lock_active);
312
313/**
314 * rfkill_get_global_state - returns global state for a type
315 * @type: the type to get the global state of
316 *
317 * Returns the current global state for a given wireless
318 * device type.
319 */
320enum rfkill_state rfkill_get_global_state(const enum rfkill_type type)
321{
322 return rfkill_global_states[type].current_state;
323}
324EXPORT_SYMBOL_GPL(rfkill_get_global_state);
325
326/**
327 * rfkill_force_state - Force the internal rfkill radio state 327 * rfkill_force_state - Force the internal rfkill radio state
328 * @rfkill: pointer to the rfkill class to modify. 328 * @rfkill: pointer to the rfkill class to modify.
329 * @state: the current radio state the class should be forced to. 329 * @state: the current radio state the class should be forced to.
@@ -357,7 +357,7 @@ int rfkill_force_state(struct rfkill *rfkill, enum rfkill_state state)
357 rfkill->state = state; 357 rfkill->state = state;
358 358
359 if (state != oldstate) 359 if (state != oldstate)
360 notify_rfkill_state_change(rfkill); 360 rfkill_uevent(rfkill);
361 361
362 mutex_unlock(&rfkill->mutex); 362 mutex_unlock(&rfkill->mutex);
363 363
@@ -431,9 +431,15 @@ static ssize_t rfkill_state_store(struct device *dev,
431 state != RFKILL_STATE_SOFT_BLOCKED) 431 state != RFKILL_STATE_SOFT_BLOCKED)
432 return -EINVAL; 432 return -EINVAL;
433 433
434 if (mutex_lock_interruptible(&rfkill->mutex)) 434 error = mutex_lock_killable(&rfkill->mutex);
435 return -ERESTARTSYS; 435 if (error)
436 error = rfkill_toggle_radio(rfkill, state, 0); 436 return error;
437
438 if (!rfkill_epo_lock_active)
439 error = rfkill_toggle_radio(rfkill, state, 0);
440 else
441 error = -EPERM;
442
437 mutex_unlock(&rfkill->mutex); 443 mutex_unlock(&rfkill->mutex);
438 444
439 return error ? error : count; 445 return error ? error : count;
@@ -472,12 +478,12 @@ static ssize_t rfkill_claim_store(struct device *dev,
472 * Take the global lock to make sure the kernel is not in 478 * Take the global lock to make sure the kernel is not in
473 * the middle of rfkill_switch_all 479 * the middle of rfkill_switch_all
474 */ 480 */
475 error = mutex_lock_interruptible(&rfkill_global_mutex); 481 error = mutex_lock_killable(&rfkill_global_mutex);
476 if (error) 482 if (error)
477 return error; 483 return error;
478 484
479 if (rfkill->user_claim != claim) { 485 if (rfkill->user_claim != claim) {
480 if (!claim) { 486 if (!claim && !rfkill_epo_lock_active) {
481 mutex_lock(&rfkill->mutex); 487 mutex_lock(&rfkill->mutex);
482 rfkill_toggle_radio(rfkill, 488 rfkill_toggle_radio(rfkill,
483 rfkill_global_states[rfkill->type].current_state, 489 rfkill_global_states[rfkill->type].current_state,
@@ -511,24 +517,48 @@ static void rfkill_release(struct device *dev)
511#ifdef CONFIG_PM 517#ifdef CONFIG_PM
512static int rfkill_suspend(struct device *dev, pm_message_t state) 518static int rfkill_suspend(struct device *dev, pm_message_t state)
513{ 519{
520 struct rfkill *rfkill = to_rfkill(dev);
521
514 /* mark class device as suspended */ 522 /* mark class device as suspended */
515 if (dev->power.power_state.event != state.event) 523 if (dev->power.power_state.event != state.event)
516 dev->power.power_state = state; 524 dev->power.power_state = state;
517 525
526 /* store state for the resume handler */
527 rfkill->state_for_resume = rfkill->state;
528
518 return 0; 529 return 0;
519} 530}
520 531
521static int rfkill_resume(struct device *dev) 532static int rfkill_resume(struct device *dev)
522{ 533{
523 struct rfkill *rfkill = to_rfkill(dev); 534 struct rfkill *rfkill = to_rfkill(dev);
535 enum rfkill_state newstate;
524 536
525 if (dev->power.power_state.event != PM_EVENT_ON) { 537 if (dev->power.power_state.event != PM_EVENT_ON) {
526 mutex_lock(&rfkill->mutex); 538 mutex_lock(&rfkill->mutex);
527 539
528 dev->power.power_state.event = PM_EVENT_ON; 540 dev->power.power_state.event = PM_EVENT_ON;
529 541
530 /* restore radio state AND notify everybody */ 542 /*
531 rfkill_toggle_radio(rfkill, rfkill->state, 1); 543 * rfkill->state could have been modified before we got
544 * called, and won't be updated by rfkill_toggle_radio()
545 * in force mode. Sync it FIRST.
546 */
547 if (rfkill->get_state &&
548 !rfkill->get_state(rfkill->data, &newstate))
549 rfkill->state = newstate;
550
551 /*
552 * If we are under EPO, kick transmitter offline,
553 * otherwise restore to pre-suspend state.
554 *
555 * Issue a notification in any case
556 */
557 rfkill_toggle_radio(rfkill,
558 rfkill_epo_lock_active ?
559 RFKILL_STATE_SOFT_BLOCKED :
560 rfkill->state_for_resume,
561 1);
532 562
533 mutex_unlock(&rfkill->mutex); 563 mutex_unlock(&rfkill->mutex);
534 } 564 }
@@ -540,28 +570,6 @@ static int rfkill_resume(struct device *dev)
540#define rfkill_resume NULL 570#define rfkill_resume NULL
541#endif 571#endif
542 572
543static int rfkill_blocking_uevent_notifier(struct notifier_block *nb,
544 unsigned long eventid,
545 void *data)
546{
547 struct rfkill *rfkill = (struct rfkill *)data;
548
549 switch (eventid) {
550 case RFKILL_STATE_CHANGED:
551 kobject_uevent(&rfkill->dev.kobj, KOBJ_CHANGE);
552 break;
553 default:
554 break;
555 }
556
557 return NOTIFY_DONE;
558}
559
560static struct notifier_block rfkill_blocking_uevent_nb = {
561 .notifier_call = rfkill_blocking_uevent_notifier,
562 .priority = 0,
563};
564
565static int rfkill_dev_uevent(struct device *dev, struct kobj_uevent_env *env) 573static int rfkill_dev_uevent(struct device *dev, struct kobj_uevent_env *env)
566{ 574{
567 struct rfkill *rfkill = to_rfkill(dev); 575 struct rfkill *rfkill = to_rfkill(dev);
@@ -711,7 +719,7 @@ static void rfkill_led_trigger_register(struct rfkill *rfkill)
711 int error; 719 int error;
712 720
713 if (!rfkill->led_trigger.name) 721 if (!rfkill->led_trigger.name)
714 rfkill->led_trigger.name = rfkill->dev.bus_id; 722 rfkill->led_trigger.name = dev_name(&rfkill->dev);
715 if (!rfkill->led_trigger.activate) 723 if (!rfkill->led_trigger.activate)
716 rfkill->led_trigger.activate = rfkill_led_trigger_activate; 724 rfkill->led_trigger.activate = rfkill_led_trigger_activate;
717 error = led_trigger_register(&rfkill->led_trigger); 725 error = led_trigger_register(&rfkill->led_trigger);
@@ -752,8 +760,7 @@ int __must_check rfkill_register(struct rfkill *rfkill)
752 "badly initialized rfkill struct\n")) 760 "badly initialized rfkill struct\n"))
753 return -EINVAL; 761 return -EINVAL;
754 762
755 snprintf(dev->bus_id, sizeof(dev->bus_id), 763 dev_set_name(dev, "rfkill%ld", (long)atomic_inc_return(&rfkill_no) - 1);
756 "rfkill%ld", (long)atomic_inc_return(&rfkill_no) - 1);
757 764
758 rfkill_led_trigger_register(rfkill); 765 rfkill_led_trigger_register(rfkill);
759 766
@@ -833,6 +840,7 @@ int rfkill_set_default(enum rfkill_type type, enum rfkill_state state)
833 840
834 if (!test_and_set_bit(type, rfkill_states_lockdflt)) { 841 if (!test_and_set_bit(type, rfkill_states_lockdflt)) {
835 rfkill_global_states[type].default_state = state; 842 rfkill_global_states[type].default_state = state;
843 rfkill_global_states[type].current_state = state;
836 error = 0; 844 error = 0;
837 } else 845 } else
838 error = -EPERM; 846 error = -EPERM;
@@ -864,14 +872,11 @@ static int __init rfkill_init(void)
864 return error; 872 return error;
865 } 873 }
866 874
867 register_rfkill_notifier(&rfkill_blocking_uevent_nb);
868
869 return 0; 875 return 0;
870} 876}
871 877
872static void __exit rfkill_exit(void) 878static void __exit rfkill_exit(void)
873{ 879{
874 unregister_rfkill_notifier(&rfkill_blocking_uevent_nb);
875 class_unregister(&rfkill_class); 880 class_unregister(&rfkill_class);
876} 881}
877 882
diff --git a/net/rose/sysctl_net_rose.c b/net/rose/sysctl_net_rose.c
index 20be3485a97f..3bfe504faf86 100644
--- a/net/rose/sysctl_net_rose.c
+++ b/net/rose/sysctl_net_rose.c
@@ -31,8 +31,8 @@ static ctl_table rose_table[] = {
31 .data = &sysctl_rose_restart_request_timeout, 31 .data = &sysctl_rose_restart_request_timeout,
32 .maxlen = sizeof(int), 32 .maxlen = sizeof(int),
33 .mode = 0644, 33 .mode = 0644,
34 .proc_handler = &proc_dointvec_minmax, 34 .proc_handler = proc_dointvec_minmax,
35 .strategy = &sysctl_intvec, 35 .strategy = sysctl_intvec,
36 .extra1 = &min_timer, 36 .extra1 = &min_timer,
37 .extra2 = &max_timer 37 .extra2 = &max_timer
38 }, 38 },
@@ -42,8 +42,8 @@ static ctl_table rose_table[] = {
42 .data = &sysctl_rose_call_request_timeout, 42 .data = &sysctl_rose_call_request_timeout,
43 .maxlen = sizeof(int), 43 .maxlen = sizeof(int),
44 .mode = 0644, 44 .mode = 0644,
45 .proc_handler = &proc_dointvec_minmax, 45 .proc_handler = proc_dointvec_minmax,
46 .strategy = &sysctl_intvec, 46 .strategy = sysctl_intvec,
47 .extra1 = &min_timer, 47 .extra1 = &min_timer,
48 .extra2 = &max_timer 48 .extra2 = &max_timer
49 }, 49 },
@@ -53,8 +53,8 @@ static ctl_table rose_table[] = {
53 .data = &sysctl_rose_reset_request_timeout, 53 .data = &sysctl_rose_reset_request_timeout,
54 .maxlen = sizeof(int), 54 .maxlen = sizeof(int),
55 .mode = 0644, 55 .mode = 0644,
56 .proc_handler = &proc_dointvec_minmax, 56 .proc_handler = proc_dointvec_minmax,
57 .strategy = &sysctl_intvec, 57 .strategy = sysctl_intvec,
58 .extra1 = &min_timer, 58 .extra1 = &min_timer,
59 .extra2 = &max_timer 59 .extra2 = &max_timer
60 }, 60 },
@@ -64,8 +64,8 @@ static ctl_table rose_table[] = {
64 .data = &sysctl_rose_clear_request_timeout, 64 .data = &sysctl_rose_clear_request_timeout,
65 .maxlen = sizeof(int), 65 .maxlen = sizeof(int),
66 .mode = 0644, 66 .mode = 0644,
67 .proc_handler = &proc_dointvec_minmax, 67 .proc_handler = proc_dointvec_minmax,
68 .strategy = &sysctl_intvec, 68 .strategy = sysctl_intvec,
69 .extra1 = &min_timer, 69 .extra1 = &min_timer,
70 .extra2 = &max_timer 70 .extra2 = &max_timer
71 }, 71 },
@@ -75,8 +75,8 @@ static ctl_table rose_table[] = {
75 .data = &sysctl_rose_no_activity_timeout, 75 .data = &sysctl_rose_no_activity_timeout,
76 .maxlen = sizeof(int), 76 .maxlen = sizeof(int),
77 .mode = 0644, 77 .mode = 0644,
78 .proc_handler = &proc_dointvec_minmax, 78 .proc_handler = proc_dointvec_minmax,
79 .strategy = &sysctl_intvec, 79 .strategy = sysctl_intvec,
80 .extra1 = &min_idle, 80 .extra1 = &min_idle,
81 .extra2 = &max_idle 81 .extra2 = &max_idle
82 }, 82 },
@@ -86,8 +86,8 @@ static ctl_table rose_table[] = {
86 .data = &sysctl_rose_ack_hold_back_timeout, 86 .data = &sysctl_rose_ack_hold_back_timeout,
87 .maxlen = sizeof(int), 87 .maxlen = sizeof(int),
88 .mode = 0644, 88 .mode = 0644,
89 .proc_handler = &proc_dointvec_minmax, 89 .proc_handler = proc_dointvec_minmax,
90 .strategy = &sysctl_intvec, 90 .strategy = sysctl_intvec,
91 .extra1 = &min_timer, 91 .extra1 = &min_timer,
92 .extra2 = &max_timer 92 .extra2 = &max_timer
93 }, 93 },
@@ -97,8 +97,8 @@ static ctl_table rose_table[] = {
97 .data = &sysctl_rose_routing_control, 97 .data = &sysctl_rose_routing_control,
98 .maxlen = sizeof(int), 98 .maxlen = sizeof(int),
99 .mode = 0644, 99 .mode = 0644,
100 .proc_handler = &proc_dointvec_minmax, 100 .proc_handler = proc_dointvec_minmax,
101 .strategy = &sysctl_intvec, 101 .strategy = sysctl_intvec,
102 .extra1 = &min_route, 102 .extra1 = &min_route,
103 .extra2 = &max_route 103 .extra2 = &max_route
104 }, 104 },
@@ -108,8 +108,8 @@ static ctl_table rose_table[] = {
108 .data = &sysctl_rose_link_fail_timeout, 108 .data = &sysctl_rose_link_fail_timeout,
109 .maxlen = sizeof(int), 109 .maxlen = sizeof(int),
110 .mode = 0644, 110 .mode = 0644,
111 .proc_handler = &proc_dointvec_minmax, 111 .proc_handler = proc_dointvec_minmax,
112 .strategy = &sysctl_intvec, 112 .strategy = sysctl_intvec,
113 .extra1 = &min_ftimer, 113 .extra1 = &min_ftimer,
114 .extra2 = &max_ftimer 114 .extra2 = &max_ftimer
115 }, 115 },
@@ -119,8 +119,8 @@ static ctl_table rose_table[] = {
119 .data = &sysctl_rose_maximum_vcs, 119 .data = &sysctl_rose_maximum_vcs,
120 .maxlen = sizeof(int), 120 .maxlen = sizeof(int),
121 .mode = 0644, 121 .mode = 0644,
122 .proc_handler = &proc_dointvec_minmax, 122 .proc_handler = proc_dointvec_minmax,
123 .strategy = &sysctl_intvec, 123 .strategy = sysctl_intvec,
124 .extra1 = &min_maxvcs, 124 .extra1 = &min_maxvcs,
125 .extra2 = &max_maxvcs 125 .extra2 = &max_maxvcs
126 }, 126 },
@@ -130,8 +130,8 @@ static ctl_table rose_table[] = {
130 .data = &sysctl_rose_window_size, 130 .data = &sysctl_rose_window_size,
131 .maxlen = sizeof(int), 131 .maxlen = sizeof(int),
132 .mode = 0644, 132 .mode = 0644,
133 .proc_handler = &proc_dointvec_minmax, 133 .proc_handler = proc_dointvec_minmax,
134 .strategy = &sysctl_intvec, 134 .strategy = sysctl_intvec,
135 .extra1 = &min_window, 135 .extra1 = &min_window,
136 .extra2 = &max_window 136 .extra2 = &max_window
137 }, 137 },
diff --git a/net/rxrpc/af_rxrpc.c b/net/rxrpc/af_rxrpc.c
index 32e489118beb..d7d2bed7a699 100644
--- a/net/rxrpc/af_rxrpc.c
+++ b/net/rxrpc/af_rxrpc.c
@@ -96,9 +96,9 @@ static int rxrpc_validate_address(struct rxrpc_sock *rx,
96 96
97 switch (srx->transport.family) { 97 switch (srx->transport.family) {
98 case AF_INET: 98 case AF_INET:
99 _debug("INET: %x @ %u.%u.%u.%u", 99 _debug("INET: %x @ %pI4",
100 ntohs(srx->transport.sin.sin_port), 100 ntohs(srx->transport.sin.sin_port),
101 NIPQUAD(srx->transport.sin.sin_addr)); 101 &srx->transport.sin.sin_addr);
102 if (srx->transport_len > 8) 102 if (srx->transport_len > 8)
103 memset((void *)&srx->transport + 8, 0, 103 memset((void *)&srx->transport + 8, 0,
104 srx->transport_len - 8); 104 srx->transport_len - 8);
diff --git a/net/rxrpc/ar-connection.c b/net/rxrpc/ar-connection.c
index 3869a5866752..0f1218b8d289 100644
--- a/net/rxrpc/ar-connection.c
+++ b/net/rxrpc/ar-connection.c
@@ -826,7 +826,7 @@ static void rxrpc_destroy_connection(struct rxrpc_connection *conn)
826/* 826/*
827 * reap dead connections 827 * reap dead connections
828 */ 828 */
829void rxrpc_connection_reaper(struct work_struct *work) 829static void rxrpc_connection_reaper(struct work_struct *work)
830{ 830{
831 struct rxrpc_connection *conn, *_p; 831 struct rxrpc_connection *conn, *_p;
832 unsigned long now, earliest, reap_time; 832 unsigned long now, earliest, reap_time;
diff --git a/net/rxrpc/ar-connevent.c b/net/rxrpc/ar-connevent.c
index 1ada43d51165..dc5cb1e19509 100644
--- a/net/rxrpc/ar-connevent.c
+++ b/net/rxrpc/ar-connevent.c
@@ -126,7 +126,7 @@ static int rxrpc_abort_connection(struct rxrpc_connection *conn,
126 * mark a call as being on a now-secured channel 126 * mark a call as being on a now-secured channel
127 * - must be called with softirqs disabled 127 * - must be called with softirqs disabled
128 */ 128 */
129void rxrpc_call_is_secure(struct rxrpc_call *call) 129static void rxrpc_call_is_secure(struct rxrpc_call *call)
130{ 130{
131 _enter("%p", call); 131 _enter("%p", call);
132 if (call) { 132 if (call) {
diff --git a/net/rxrpc/ar-error.c b/net/rxrpc/ar-error.c
index 6cb3e8890e7e..d4d1ae26d293 100644
--- a/net/rxrpc/ar-error.c
+++ b/net/rxrpc/ar-error.c
@@ -49,8 +49,7 @@ void rxrpc_UDP_error_report(struct sock *sk)
49 addr = *(__be32 *)(skb_network_header(skb) + serr->addr_offset); 49 addr = *(__be32 *)(skb_network_header(skb) + serr->addr_offset);
50 port = serr->port; 50 port = serr->port;
51 51
52 _net("Rx UDP Error from "NIPQUAD_FMT":%hu", 52 _net("Rx UDP Error from %pI4:%hu", &addr, ntohs(port));
53 NIPQUAD(addr), ntohs(port));
54 _debug("Msg l:%d d:%d", skb->len, skb->data_len); 53 _debug("Msg l:%d d:%d", skb->len, skb->data_len);
55 54
56 peer = rxrpc_find_peer(local, addr, port); 55 peer = rxrpc_find_peer(local, addr, port);
diff --git a/net/rxrpc/ar-local.c b/net/rxrpc/ar-local.c
index f3a2bd747a8f..807535ff29b5 100644
--- a/net/rxrpc/ar-local.c
+++ b/net/rxrpc/ar-local.c
@@ -131,10 +131,10 @@ struct rxrpc_local *rxrpc_lookup_local(struct sockaddr_rxrpc *srx)
131 struct rxrpc_local *local; 131 struct rxrpc_local *local;
132 int ret; 132 int ret;
133 133
134 _enter("{%d,%u,%u.%u.%u.%u+%hu}", 134 _enter("{%d,%u,%pI4+%hu}",
135 srx->transport_type, 135 srx->transport_type,
136 srx->transport.family, 136 srx->transport.family,
137 NIPQUAD(srx->transport.sin.sin_addr), 137 &srx->transport.sin.sin_addr,
138 ntohs(srx->transport.sin.sin_port)); 138 ntohs(srx->transport.sin.sin_port));
139 139
140 down_write(&rxrpc_local_sem); 140 down_write(&rxrpc_local_sem);
@@ -143,10 +143,10 @@ struct rxrpc_local *rxrpc_lookup_local(struct sockaddr_rxrpc *srx)
143 read_lock_bh(&rxrpc_local_lock); 143 read_lock_bh(&rxrpc_local_lock);
144 144
145 list_for_each_entry(local, &rxrpc_locals, link) { 145 list_for_each_entry(local, &rxrpc_locals, link) {
146 _debug("CMP {%d,%u,%u.%u.%u.%u+%hu}", 146 _debug("CMP {%d,%u,%pI4+%hu}",
147 local->srx.transport_type, 147 local->srx.transport_type,
148 local->srx.transport.family, 148 local->srx.transport.family,
149 NIPQUAD(local->srx.transport.sin.sin_addr), 149 &local->srx.transport.sin.sin_addr,
150 ntohs(local->srx.transport.sin.sin_port)); 150 ntohs(local->srx.transport.sin.sin_port));
151 151
152 if (local->srx.transport_type != srx->transport_type || 152 if (local->srx.transport_type != srx->transport_type ||
@@ -188,11 +188,11 @@ struct rxrpc_local *rxrpc_lookup_local(struct sockaddr_rxrpc *srx)
188 188
189 up_write(&rxrpc_local_sem); 189 up_write(&rxrpc_local_sem);
190 190
191 _net("LOCAL new %d {%d,%u,%u.%u.%u.%u+%hu}", 191 _net("LOCAL new %d {%d,%u,%pI4+%hu}",
192 local->debug_id, 192 local->debug_id,
193 local->srx.transport_type, 193 local->srx.transport_type,
194 local->srx.transport.family, 194 local->srx.transport.family,
195 NIPQUAD(local->srx.transport.sin.sin_addr), 195 &local->srx.transport.sin.sin_addr,
196 ntohs(local->srx.transport.sin.sin_port)); 196 ntohs(local->srx.transport.sin.sin_port));
197 197
198 _leave(" = %p [new]", local); 198 _leave(" = %p [new]", local);
@@ -203,11 +203,11 @@ found_local:
203 read_unlock_bh(&rxrpc_local_lock); 203 read_unlock_bh(&rxrpc_local_lock);
204 up_write(&rxrpc_local_sem); 204 up_write(&rxrpc_local_sem);
205 205
206 _net("LOCAL old %d {%d,%u,%u.%u.%u.%u+%hu}", 206 _net("LOCAL old %d {%d,%u,%pI4+%hu}",
207 local->debug_id, 207 local->debug_id,
208 local->srx.transport_type, 208 local->srx.transport_type,
209 local->srx.transport.family, 209 local->srx.transport.family,
210 NIPQUAD(local->srx.transport.sin.sin_addr), 210 &local->srx.transport.sin.sin_addr,
211 ntohs(local->srx.transport.sin.sin_port)); 211 ntohs(local->srx.transport.sin.sin_port));
212 212
213 _leave(" = %p [reuse]", local); 213 _leave(" = %p [reuse]", local);
diff --git a/net/rxrpc/ar-peer.c b/net/rxrpc/ar-peer.c
index 2abe2081a5e8..edc026c1eb76 100644
--- a/net/rxrpc/ar-peer.c
+++ b/net/rxrpc/ar-peer.c
@@ -123,10 +123,10 @@ struct rxrpc_peer *rxrpc_get_peer(struct sockaddr_rxrpc *srx, gfp_t gfp)
123 const char *new = "old"; 123 const char *new = "old";
124 int usage; 124 int usage;
125 125
126 _enter("{%d,%d,%u.%u.%u.%u+%hu}", 126 _enter("{%d,%d,%pI4+%hu}",
127 srx->transport_type, 127 srx->transport_type,
128 srx->transport_len, 128 srx->transport_len,
129 NIPQUAD(srx->transport.sin.sin_addr), 129 &srx->transport.sin.sin_addr,
130 ntohs(srx->transport.sin.sin_port)); 130 ntohs(srx->transport.sin.sin_port));
131 131
132 /* search the peer list first */ 132 /* search the peer list first */
@@ -177,12 +177,12 @@ struct rxrpc_peer *rxrpc_get_peer(struct sockaddr_rxrpc *srx, gfp_t gfp)
177 new = "new"; 177 new = "new";
178 178
179success: 179success:
180 _net("PEER %s %d {%d,%u,%u.%u.%u.%u+%hu}", 180 _net("PEER %s %d {%d,%u,%pI4+%hu}",
181 new, 181 new,
182 peer->debug_id, 182 peer->debug_id,
183 peer->srx.transport_type, 183 peer->srx.transport_type,
184 peer->srx.transport.family, 184 peer->srx.transport.family,
185 NIPQUAD(peer->srx.transport.sin.sin_addr), 185 &peer->srx.transport.sin.sin_addr,
186 ntohs(peer->srx.transport.sin.sin_port)); 186 ntohs(peer->srx.transport.sin.sin_port));
187 187
188 _leave(" = %p {u=%d}", peer, atomic_read(&peer->usage)); 188 _leave(" = %p {u=%d}", peer, atomic_read(&peer->usage));
diff --git a/net/rxrpc/ar-proc.c b/net/rxrpc/ar-proc.c
index 017322e2786d..38047f713f2c 100644
--- a/net/rxrpc/ar-proc.c
+++ b/net/rxrpc/ar-proc.c
@@ -61,12 +61,12 @@ static int rxrpc_call_seq_show(struct seq_file *seq, void *v)
61 call = list_entry(v, struct rxrpc_call, link); 61 call = list_entry(v, struct rxrpc_call, link);
62 trans = call->conn->trans; 62 trans = call->conn->trans;
63 63
64 sprintf(lbuff, NIPQUAD_FMT":%u", 64 sprintf(lbuff, "%pI4:%u",
65 NIPQUAD(trans->local->srx.transport.sin.sin_addr), 65 &trans->local->srx.transport.sin.sin_addr,
66 ntohs(trans->local->srx.transport.sin.sin_port)); 66 ntohs(trans->local->srx.transport.sin.sin_port));
67 67
68 sprintf(rbuff, NIPQUAD_FMT":%u", 68 sprintf(rbuff, "%pI4:%u",
69 NIPQUAD(trans->peer->srx.transport.sin.sin_addr), 69 &trans->peer->srx.transport.sin.sin_addr,
70 ntohs(trans->peer->srx.transport.sin.sin_port)); 70 ntohs(trans->peer->srx.transport.sin.sin_port));
71 71
72 seq_printf(seq, 72 seq_printf(seq,
@@ -144,12 +144,12 @@ static int rxrpc_connection_seq_show(struct seq_file *seq, void *v)
144 conn = list_entry(v, struct rxrpc_connection, link); 144 conn = list_entry(v, struct rxrpc_connection, link);
145 trans = conn->trans; 145 trans = conn->trans;
146 146
147 sprintf(lbuff, NIPQUAD_FMT":%u", 147 sprintf(lbuff, "%pI4:%u",
148 NIPQUAD(trans->local->srx.transport.sin.sin_addr), 148 &trans->local->srx.transport.sin.sin_addr,
149 ntohs(trans->local->srx.transport.sin.sin_port)); 149 ntohs(trans->local->srx.transport.sin.sin_port));
150 150
151 sprintf(rbuff, NIPQUAD_FMT":%u", 151 sprintf(rbuff, "%pI4:%u",
152 NIPQUAD(trans->peer->srx.transport.sin.sin_addr), 152 &trans->peer->srx.transport.sin.sin_addr,
153 ntohs(trans->peer->srx.transport.sin.sin_port)); 153 ntohs(trans->peer->srx.transport.sin.sin_port));
154 154
155 seq_printf(seq, 155 seq_printf(seq,
diff --git a/net/rxrpc/ar-security.c b/net/rxrpc/ar-security.c
index 60d1d364430a..dc62920ee19a 100644
--- a/net/rxrpc/ar-security.c
+++ b/net/rxrpc/ar-security.c
@@ -40,7 +40,7 @@ static void rxrpc_security_put(struct rxrpc_security *sec)
40/* 40/*
41 * look up an rxrpc security module 41 * look up an rxrpc security module
42 */ 42 */
43struct rxrpc_security *rxrpc_security_lookup(u8 security_index) 43static struct rxrpc_security *rxrpc_security_lookup(u8 security_index)
44{ 44{
45 struct rxrpc_security *sec = NULL; 45 struct rxrpc_security *sec = NULL;
46 46
diff --git a/net/rxrpc/ar-transport.c b/net/rxrpc/ar-transport.c
index 64069c8769a5..0936e1acc30e 100644
--- a/net/rxrpc/ar-transport.c
+++ b/net/rxrpc/ar-transport.c
@@ -78,10 +78,10 @@ struct rxrpc_transport *rxrpc_get_transport(struct rxrpc_local *local,
78 const char *new = "old"; 78 const char *new = "old";
79 int usage; 79 int usage;
80 80
81 _enter("{%u.%u.%u.%u+%hu},{%u.%u.%u.%u+%hu},", 81 _enter("{%pI4+%hu},{%pI4+%hu},",
82 NIPQUAD(local->srx.transport.sin.sin_addr), 82 &local->srx.transport.sin.sin_addr,
83 ntohs(local->srx.transport.sin.sin_port), 83 ntohs(local->srx.transport.sin.sin_port),
84 NIPQUAD(peer->srx.transport.sin.sin_addr), 84 &peer->srx.transport.sin.sin_addr,
85 ntohs(peer->srx.transport.sin.sin_port)); 85 ntohs(peer->srx.transport.sin.sin_port));
86 86
87 /* search the transport list first */ 87 /* search the transport list first */
@@ -149,10 +149,10 @@ struct rxrpc_transport *rxrpc_find_transport(struct rxrpc_local *local,
149{ 149{
150 struct rxrpc_transport *trans; 150 struct rxrpc_transport *trans;
151 151
152 _enter("{%u.%u.%u.%u+%hu},{%u.%u.%u.%u+%hu},", 152 _enter("{%pI4+%hu},{%pI4+%hu},",
153 NIPQUAD(local->srx.transport.sin.sin_addr), 153 &local->srx.transport.sin.sin_addr,
154 ntohs(local->srx.transport.sin.sin_port), 154 ntohs(local->srx.transport.sin.sin_port),
155 NIPQUAD(peer->srx.transport.sin.sin_addr), 155 &peer->srx.transport.sin.sin_addr,
156 ntohs(peer->srx.transport.sin.sin_port)); 156 ntohs(peer->srx.transport.sin.sin_port));
157 157
158 /* search the transport list */ 158 /* search the transport list */
diff --git a/net/rxrpc/rxkad.c b/net/rxrpc/rxkad.c
index ba3f6e49fddc..ef8f91030a15 100644
--- a/net/rxrpc/rxkad.c
+++ b/net/rxrpc/rxkad.c
@@ -897,7 +897,7 @@ static int rxkad_decrypt_ticket(struct rxrpc_connection *conn,
897 /* get the IPv4 address of the entity that requested the ticket */ 897 /* get the IPv4 address of the entity that requested the ticket */
898 memcpy(&addr, p, sizeof(addr)); 898 memcpy(&addr, p, sizeof(addr));
899 p += 4; 899 p += 4;
900 _debug("KIV ADDR : "NIPQUAD_FMT, NIPQUAD(addr)); 900 _debug("KIV ADDR : %pI4", &addr);
901 901
902 /* get the session key from the ticket */ 902 /* get the session key from the ticket */
903 memcpy(&key, p, sizeof(key)); 903 memcpy(&key, p, sizeof(key));
diff --git a/net/sched/Kconfig b/net/sched/Kconfig
index 6767e54155db..4f7ef0db302b 100644
--- a/net/sched/Kconfig
+++ b/net/sched/Kconfig
@@ -194,6 +194,17 @@ config NET_SCH_NETEM
194 194
195 If unsure, say N. 195 If unsure, say N.
196 196
197config NET_SCH_DRR
198 tristate "Deficit Round Robin scheduler (DRR)"
199 help
200 Say Y here if you want to use the Deficit Round Robin (DRR) packet
201 scheduling algorithm.
202
203 To compile this driver as a module, choose M here: the module
204 will be called sch_drr.
205
206 If unsure, say N.
207
197config NET_SCH_INGRESS 208config NET_SCH_INGRESS
198 tristate "Ingress Qdisc" 209 tristate "Ingress Qdisc"
199 depends on NET_CLS_ACT 210 depends on NET_CLS_ACT
@@ -316,6 +327,17 @@ config NET_CLS_FLOW
316 To compile this code as a module, choose M here: the 327 To compile this code as a module, choose M here: the
317 module will be called cls_flow. 328 module will be called cls_flow.
318 329
330config NET_CLS_CGROUP
331 bool "Control Group Classifier"
332 select NET_CLS
333 depends on CGROUPS
334 ---help---
335 Say Y here if you want to classify packets based on the control
336 cgroup of their process.
337
338 To compile this code as a module, choose M here: the
339 module will be called cls_cgroup.
340
319config NET_EMATCH 341config NET_EMATCH
320 bool "Extended Matches" 342 bool "Extended Matches"
321 select NET_CLS 343 select NET_CLS
diff --git a/net/sched/Makefile b/net/sched/Makefile
index e60c9925b269..54d950cd4b8d 100644
--- a/net/sched/Makefile
+++ b/net/sched/Makefile
@@ -30,6 +30,7 @@ obj-$(CONFIG_NET_SCH_PRIO) += sch_prio.o
30obj-$(CONFIG_NET_SCH_MULTIQ) += sch_multiq.o 30obj-$(CONFIG_NET_SCH_MULTIQ) += sch_multiq.o
31obj-$(CONFIG_NET_SCH_ATM) += sch_atm.o 31obj-$(CONFIG_NET_SCH_ATM) += sch_atm.o
32obj-$(CONFIG_NET_SCH_NETEM) += sch_netem.o 32obj-$(CONFIG_NET_SCH_NETEM) += sch_netem.o
33obj-$(CONFIG_NET_SCH_DRR) += sch_drr.o
33obj-$(CONFIG_NET_CLS_U32) += cls_u32.o 34obj-$(CONFIG_NET_CLS_U32) += cls_u32.o
34obj-$(CONFIG_NET_CLS_ROUTE4) += cls_route.o 35obj-$(CONFIG_NET_CLS_ROUTE4) += cls_route.o
35obj-$(CONFIG_NET_CLS_FW) += cls_fw.o 36obj-$(CONFIG_NET_CLS_FW) += cls_fw.o
@@ -38,6 +39,7 @@ obj-$(CONFIG_NET_CLS_TCINDEX) += cls_tcindex.o
38obj-$(CONFIG_NET_CLS_RSVP6) += cls_rsvp6.o 39obj-$(CONFIG_NET_CLS_RSVP6) += cls_rsvp6.o
39obj-$(CONFIG_NET_CLS_BASIC) += cls_basic.o 40obj-$(CONFIG_NET_CLS_BASIC) += cls_basic.o
40obj-$(CONFIG_NET_CLS_FLOW) += cls_flow.o 41obj-$(CONFIG_NET_CLS_FLOW) += cls_flow.o
42obj-$(CONFIG_NET_CLS_CGROUP) += cls_cgroup.o
41obj-$(CONFIG_NET_EMATCH) += ematch.o 43obj-$(CONFIG_NET_EMATCH) += ematch.o
42obj-$(CONFIG_NET_EMATCH_CMP) += em_cmp.o 44obj-$(CONFIG_NET_EMATCH_CMP) += em_cmp.o
43obj-$(CONFIG_NET_EMATCH_NBYTE) += em_nbyte.o 45obj-$(CONFIG_NET_EMATCH_NBYTE) += em_nbyte.o
diff --git a/net/sched/act_api.c b/net/sched/act_api.c
index 8f457f1e0acf..9d03cc33b6cc 100644
--- a/net/sched/act_api.c
+++ b/net/sched/act_api.c
@@ -214,12 +214,14 @@ struct tcf_common *tcf_hash_check(u32 index, struct tc_action *a, int bind,
214} 214}
215EXPORT_SYMBOL(tcf_hash_check); 215EXPORT_SYMBOL(tcf_hash_check);
216 216
217struct tcf_common *tcf_hash_create(u32 index, struct nlattr *est, struct tc_action *a, int size, int bind, u32 *idx_gen, struct tcf_hashinfo *hinfo) 217struct tcf_common *tcf_hash_create(u32 index, struct nlattr *est,
218 struct tc_action *a, int size, int bind,
219 u32 *idx_gen, struct tcf_hashinfo *hinfo)
218{ 220{
219 struct tcf_common *p = kzalloc(size, GFP_KERNEL); 221 struct tcf_common *p = kzalloc(size, GFP_KERNEL);
220 222
221 if (unlikely(!p)) 223 if (unlikely(!p))
222 return p; 224 return ERR_PTR(-ENOMEM);
223 p->tcfc_refcnt = 1; 225 p->tcfc_refcnt = 1;
224 if (bind) 226 if (bind)
225 p->tcfc_bindcnt = 1; 227 p->tcfc_bindcnt = 1;
@@ -228,9 +230,15 @@ struct tcf_common *tcf_hash_create(u32 index, struct nlattr *est, struct tc_acti
228 p->tcfc_index = index ? index : tcf_hash_new_index(idx_gen, hinfo); 230 p->tcfc_index = index ? index : tcf_hash_new_index(idx_gen, hinfo);
229 p->tcfc_tm.install = jiffies; 231 p->tcfc_tm.install = jiffies;
230 p->tcfc_tm.lastuse = jiffies; 232 p->tcfc_tm.lastuse = jiffies;
231 if (est) 233 if (est) {
232 gen_new_estimator(&p->tcfc_bstats, &p->tcfc_rate_est, 234 int err = gen_new_estimator(&p->tcfc_bstats, &p->tcfc_rate_est,
233 &p->tcfc_lock, est); 235 &p->tcfc_lock, est);
236 if (err) {
237 kfree(p);
238 return ERR_PTR(err);
239 }
240 }
241
234 a->priv = (void *) p; 242 a->priv = (void *) p;
235 return p; 243 return p;
236} 244}
diff --git a/net/sched/act_gact.c b/net/sched/act_gact.c
index ac04289da5d7..e7f796aec657 100644
--- a/net/sched/act_gact.c
+++ b/net/sched/act_gact.c
@@ -88,8 +88,8 @@ static int tcf_gact_init(struct nlattr *nla, struct nlattr *est,
88 if (!pc) { 88 if (!pc) {
89 pc = tcf_hash_create(parm->index, est, a, sizeof(*gact), 89 pc = tcf_hash_create(parm->index, est, a, sizeof(*gact),
90 bind, &gact_idx_gen, &gact_hash_info); 90 bind, &gact_idx_gen, &gact_hash_info);
91 if (unlikely(!pc)) 91 if (IS_ERR(pc))
92 return -ENOMEM; 92 return PTR_ERR(pc);
93 ret = ACT_P_CREATED; 93 ret = ACT_P_CREATED;
94 } else { 94 } else {
95 if (!ovr) { 95 if (!ovr) {
diff --git a/net/sched/act_ipt.c b/net/sched/act_ipt.c
index 0453d79ebf57..082c520b0def 100644
--- a/net/sched/act_ipt.c
+++ b/net/sched/act_ipt.c
@@ -136,8 +136,8 @@ static int tcf_ipt_init(struct nlattr *nla, struct nlattr *est,
136 if (!pc) { 136 if (!pc) {
137 pc = tcf_hash_create(index, est, a, sizeof(*ipt), bind, 137 pc = tcf_hash_create(index, est, a, sizeof(*ipt), bind,
138 &ipt_idx_gen, &ipt_hash_info); 138 &ipt_idx_gen, &ipt_hash_info);
139 if (unlikely(!pc)) 139 if (IS_ERR(pc))
140 return -ENOMEM; 140 return PTR_ERR(pc);
141 ret = ACT_P_CREATED; 141 ret = ACT_P_CREATED;
142 } else { 142 } else {
143 if (!ovr) { 143 if (!ovr) {
diff --git a/net/sched/act_mirred.c b/net/sched/act_mirred.c
index 70341c020b6d..b9aaab4e0354 100644
--- a/net/sched/act_mirred.c
+++ b/net/sched/act_mirred.c
@@ -105,8 +105,8 @@ static int tcf_mirred_init(struct nlattr *nla, struct nlattr *est,
105 return -EINVAL; 105 return -EINVAL;
106 pc = tcf_hash_create(parm->index, est, a, sizeof(*m), bind, 106 pc = tcf_hash_create(parm->index, est, a, sizeof(*m), bind,
107 &mirred_idx_gen, &mirred_hash_info); 107 &mirred_idx_gen, &mirred_hash_info);
108 if (unlikely(!pc)) 108 if (IS_ERR(pc))
109 return -ENOMEM; 109 return PTR_ERR(pc);
110 ret = ACT_P_CREATED; 110 ret = ACT_P_CREATED;
111 } else { 111 } else {
112 if (!ovr) { 112 if (!ovr) {
diff --git a/net/sched/act_nat.c b/net/sched/act_nat.c
index 7b39ed485bca..d885ba311564 100644
--- a/net/sched/act_nat.c
+++ b/net/sched/act_nat.c
@@ -68,8 +68,8 @@ static int tcf_nat_init(struct nlattr *nla, struct nlattr *est,
68 if (!pc) { 68 if (!pc) {
69 pc = tcf_hash_create(parm->index, est, a, sizeof(*p), bind, 69 pc = tcf_hash_create(parm->index, est, a, sizeof(*p), bind,
70 &nat_idx_gen, &nat_hash_info); 70 &nat_idx_gen, &nat_hash_info);
71 if (unlikely(!pc)) 71 if (IS_ERR(pc))
72 return -ENOMEM; 72 return PTR_ERR(pc);
73 p = to_tcf_nat(pc); 73 p = to_tcf_nat(pc);
74 ret = ACT_P_CREATED; 74 ret = ACT_P_CREATED;
75 } else { 75 } else {
diff --git a/net/sched/act_pedit.c b/net/sched/act_pedit.c
index d5f4e3404864..96c0ed115e2a 100644
--- a/net/sched/act_pedit.c
+++ b/net/sched/act_pedit.c
@@ -68,8 +68,8 @@ static int tcf_pedit_init(struct nlattr *nla, struct nlattr *est,
68 return -EINVAL; 68 return -EINVAL;
69 pc = tcf_hash_create(parm->index, est, a, sizeof(*p), bind, 69 pc = tcf_hash_create(parm->index, est, a, sizeof(*p), bind,
70 &pedit_idx_gen, &pedit_hash_info); 70 &pedit_idx_gen, &pedit_hash_info);
71 if (unlikely(!pc)) 71 if (IS_ERR(pc))
72 return -ENOMEM; 72 return PTR_ERR(pc);
73 p = to_pedit(pc); 73 p = to_pedit(pc);
74 keys = kmalloc(ksize, GFP_KERNEL); 74 keys = kmalloc(ksize, GFP_KERNEL);
75 if (keys == NULL) { 75 if (keys == NULL) {
diff --git a/net/sched/act_police.c b/net/sched/act_police.c
index 38015b493947..5c72a116b1a4 100644
--- a/net/sched/act_police.c
+++ b/net/sched/act_police.c
@@ -182,17 +182,32 @@ override:
182 R_tab = qdisc_get_rtab(&parm->rate, tb[TCA_POLICE_RATE]); 182 R_tab = qdisc_get_rtab(&parm->rate, tb[TCA_POLICE_RATE]);
183 if (R_tab == NULL) 183 if (R_tab == NULL)
184 goto failure; 184 goto failure;
185
186 if (!est && (ret == ACT_P_CREATED ||
187 !gen_estimator_active(&police->tcf_bstats,
188 &police->tcf_rate_est))) {
189 err = -EINVAL;
190 goto failure;
191 }
192
185 if (parm->peakrate.rate) { 193 if (parm->peakrate.rate) {
186 P_tab = qdisc_get_rtab(&parm->peakrate, 194 P_tab = qdisc_get_rtab(&parm->peakrate,
187 tb[TCA_POLICE_PEAKRATE]); 195 tb[TCA_POLICE_PEAKRATE]);
188 if (P_tab == NULL) { 196 if (P_tab == NULL)
189 qdisc_put_rtab(R_tab);
190 goto failure; 197 goto failure;
191 }
192 } 198 }
193 } 199 }
194 /* No failure allowed after this point */ 200
195 spin_lock_bh(&police->tcf_lock); 201 spin_lock_bh(&police->tcf_lock);
202 if (est) {
203 err = gen_replace_estimator(&police->tcf_bstats,
204 &police->tcf_rate_est,
205 &police->tcf_lock, est);
206 if (err)
207 goto failure_unlock;
208 }
209
210 /* No failure allowed after this point */
196 if (R_tab != NULL) { 211 if (R_tab != NULL) {
197 qdisc_put_rtab(police->tcfp_R_tab); 212 qdisc_put_rtab(police->tcfp_R_tab);
198 police->tcfp_R_tab = R_tab; 213 police->tcfp_R_tab = R_tab;
@@ -217,10 +232,6 @@ override:
217 232
218 if (tb[TCA_POLICE_AVRATE]) 233 if (tb[TCA_POLICE_AVRATE])
219 police->tcfp_ewma_rate = nla_get_u32(tb[TCA_POLICE_AVRATE]); 234 police->tcfp_ewma_rate = nla_get_u32(tb[TCA_POLICE_AVRATE]);
220 if (est)
221 gen_replace_estimator(&police->tcf_bstats,
222 &police->tcf_rate_est,
223 &police->tcf_lock, est);
224 235
225 spin_unlock_bh(&police->tcf_lock); 236 spin_unlock_bh(&police->tcf_lock);
226 if (ret != ACT_P_CREATED) 237 if (ret != ACT_P_CREATED)
@@ -238,7 +249,13 @@ override:
238 a->priv = police; 249 a->priv = police;
239 return ret; 250 return ret;
240 251
252failure_unlock:
253 spin_unlock_bh(&police->tcf_lock);
241failure: 254failure:
255 if (P_tab)
256 qdisc_put_rtab(P_tab);
257 if (R_tab)
258 qdisc_put_rtab(R_tab);
242 if (ret == ACT_P_CREATED) 259 if (ret == ACT_P_CREATED)
243 kfree(police); 260 kfree(police);
244 return err; 261 return err;
diff --git a/net/sched/act_simple.c b/net/sched/act_simple.c
index e7851ce92cfe..8daa1ebc7413 100644
--- a/net/sched/act_simple.c
+++ b/net/sched/act_simple.c
@@ -124,8 +124,8 @@ static int tcf_simp_init(struct nlattr *nla, struct nlattr *est,
124 if (!pc) { 124 if (!pc) {
125 pc = tcf_hash_create(parm->index, est, a, sizeof(*d), bind, 125 pc = tcf_hash_create(parm->index, est, a, sizeof(*d), bind,
126 &simp_idx_gen, &simp_hash_info); 126 &simp_idx_gen, &simp_hash_info);
127 if (unlikely(!pc)) 127 if (IS_ERR(pc))
128 return -ENOMEM; 128 return PTR_ERR(pc);
129 129
130 d = to_defact(pc); 130 d = to_defact(pc);
131 ret = alloc_defdata(d, defdata); 131 ret = alloc_defdata(d, defdata);
diff --git a/net/sched/act_skbedit.c b/net/sched/act_skbedit.c
index fe9777e77f35..4ab916b8074b 100644
--- a/net/sched/act_skbedit.c
+++ b/net/sched/act_skbedit.c
@@ -104,8 +104,8 @@ static int tcf_skbedit_init(struct nlattr *nla, struct nlattr *est,
104 if (!pc) { 104 if (!pc) {
105 pc = tcf_hash_create(parm->index, est, a, sizeof(*d), bind, 105 pc = tcf_hash_create(parm->index, est, a, sizeof(*d), bind,
106 &skbedit_idx_gen, &skbedit_hash_info); 106 &skbedit_idx_gen, &skbedit_hash_info);
107 if (unlikely(!pc)) 107 if (IS_ERR(pc))
108 return -ENOMEM; 108 return PTR_ERR(pc);
109 109
110 d = to_skbedit(pc); 110 d = to_skbedit(pc);
111 ret = ACT_P_CREATED; 111 ret = ACT_P_CREATED;
diff --git a/net/sched/cls_api.c b/net/sched/cls_api.c
index 16e7ac9774e5..173fcc4b050d 100644
--- a/net/sched/cls_api.c
+++ b/net/sched/cls_api.c
@@ -531,7 +531,8 @@ void tcf_exts_change(struct tcf_proto *tp, struct tcf_exts *dst,
531 if (src->action) { 531 if (src->action) {
532 struct tc_action *act; 532 struct tc_action *act;
533 tcf_tree_lock(tp); 533 tcf_tree_lock(tp);
534 act = xchg(&dst->action, src->action); 534 act = dst->action;
535 dst->action = src->action;
535 tcf_tree_unlock(tp); 536 tcf_tree_unlock(tp);
536 if (act) 537 if (act)
537 tcf_action_destroy(act, TCA_ACT_UNBIND); 538 tcf_action_destroy(act, TCA_ACT_UNBIND);
diff --git a/net/sched/cls_basic.c b/net/sched/cls_basic.c
index 956915c217d6..4e2bda854119 100644
--- a/net/sched/cls_basic.c
+++ b/net/sched/cls_basic.c
@@ -102,7 +102,7 @@ static inline void basic_delete_filter(struct tcf_proto *tp,
102 102
103static void basic_destroy(struct tcf_proto *tp) 103static void basic_destroy(struct tcf_proto *tp)
104{ 104{
105 struct basic_head *head = (struct basic_head *) xchg(&tp->root, NULL); 105 struct basic_head *head = tp->root;
106 struct basic_filter *f, *n; 106 struct basic_filter *f, *n;
107 107
108 list_for_each_entry_safe(f, n, &head->flist, link) { 108 list_for_each_entry_safe(f, n, &head->flist, link) {
diff --git a/net/sched/cls_cgroup.c b/net/sched/cls_cgroup.c
new file mode 100644
index 000000000000..0d68b1975983
--- /dev/null
+++ b/net/sched/cls_cgroup.c
@@ -0,0 +1,288 @@
1/*
2 * net/sched/cls_cgroup.c Control Group Classifier
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version
7 * 2 of the License, or (at your option) any later version.
8 *
9 * Authors: Thomas Graf <tgraf@suug.ch>
10 */
11
12#include <linux/module.h>
13#include <linux/types.h>
14#include <linux/string.h>
15#include <linux/errno.h>
16#include <linux/skbuff.h>
17#include <linux/cgroup.h>
18#include <net/rtnetlink.h>
19#include <net/pkt_cls.h>
20
21struct cgroup_cls_state
22{
23 struct cgroup_subsys_state css;
24 u32 classid;
25};
26
27static inline struct cgroup_cls_state *net_cls_state(struct cgroup *cgrp)
28{
29 return (struct cgroup_cls_state *)
30 cgroup_subsys_state(cgrp, net_cls_subsys_id);
31}
32
33static struct cgroup_subsys_state *cgrp_create(struct cgroup_subsys *ss,
34 struct cgroup *cgrp)
35{
36 struct cgroup_cls_state *cs;
37
38 if (!(cs = kzalloc(sizeof(*cs), GFP_KERNEL)))
39 return ERR_PTR(-ENOMEM);
40
41 if (cgrp->parent)
42 cs->classid = net_cls_state(cgrp->parent)->classid;
43
44 return &cs->css;
45}
46
47static void cgrp_destroy(struct cgroup_subsys *ss, struct cgroup *cgrp)
48{
49 kfree(ss);
50}
51
52static u64 read_classid(struct cgroup *cgrp, struct cftype *cft)
53{
54 return net_cls_state(cgrp)->classid;
55}
56
57static int write_classid(struct cgroup *cgrp, struct cftype *cft, u64 value)
58{
59 if (!cgroup_lock_live_group(cgrp))
60 return -ENODEV;
61
62 net_cls_state(cgrp)->classid = (u32) value;
63
64 cgroup_unlock();
65
66 return 0;
67}
68
69static struct cftype ss_files[] = {
70 {
71 .name = "classid",
72 .read_u64 = read_classid,
73 .write_u64 = write_classid,
74 },
75};
76
77static int cgrp_populate(struct cgroup_subsys *ss, struct cgroup *cgrp)
78{
79 return cgroup_add_files(cgrp, ss, ss_files, ARRAY_SIZE(ss_files));
80}
81
82struct cgroup_subsys net_cls_subsys = {
83 .name = "net_cls",
84 .create = cgrp_create,
85 .destroy = cgrp_destroy,
86 .populate = cgrp_populate,
87 .subsys_id = net_cls_subsys_id,
88};
89
90struct cls_cgroup_head
91{
92 u32 handle;
93 struct tcf_exts exts;
94 struct tcf_ematch_tree ematches;
95};
96
97static int cls_cgroup_classify(struct sk_buff *skb, struct tcf_proto *tp,
98 struct tcf_result *res)
99{
100 struct cls_cgroup_head *head = tp->root;
101 struct cgroup_cls_state *cs;
102 int ret = 0;
103
104 /*
105 * Due to the nature of the classifier it is required to ignore all
106 * packets originating from softirq context as accessing `current'
107 * would lead to false results.
108 *
109 * This test assumes that all callers of dev_queue_xmit() explicitely
110 * disable bh. Knowing this, it is possible to detect softirq based
111 * calls by looking at the number of nested bh disable calls because
112 * softirqs always disables bh.
113 */
114 if (softirq_count() != SOFTIRQ_OFFSET)
115 return -1;
116
117 rcu_read_lock();
118 cs = (struct cgroup_cls_state *) task_subsys_state(current,
119 net_cls_subsys_id);
120 if (cs->classid && tcf_em_tree_match(skb, &head->ematches, NULL)) {
121 res->classid = cs->classid;
122 res->class = 0;
123 ret = tcf_exts_exec(skb, &head->exts, res);
124 } else
125 ret = -1;
126
127 rcu_read_unlock();
128
129 return ret;
130}
131
132static unsigned long cls_cgroup_get(struct tcf_proto *tp, u32 handle)
133{
134 return 0UL;
135}
136
137static void cls_cgroup_put(struct tcf_proto *tp, unsigned long f)
138{
139}
140
141static int cls_cgroup_init(struct tcf_proto *tp)
142{
143 return 0;
144}
145
146static const struct tcf_ext_map cgroup_ext_map = {
147 .action = TCA_CGROUP_ACT,
148 .police = TCA_CGROUP_POLICE,
149};
150
151static const struct nla_policy cgroup_policy[TCA_CGROUP_MAX + 1] = {
152 [TCA_CGROUP_EMATCHES] = { .type = NLA_NESTED },
153};
154
155static int cls_cgroup_change(struct tcf_proto *tp, unsigned long base,
156 u32 handle, struct nlattr **tca,
157 unsigned long *arg)
158{
159 struct nlattr *tb[TCA_CGROUP_MAX+1];
160 struct cls_cgroup_head *head = tp->root;
161 struct tcf_ematch_tree t;
162 struct tcf_exts e;
163 int err;
164
165 if (head == NULL) {
166 if (!handle)
167 return -EINVAL;
168
169 head = kzalloc(sizeof(*head), GFP_KERNEL);
170 if (head == NULL)
171 return -ENOBUFS;
172
173 head->handle = handle;
174
175 tcf_tree_lock(tp);
176 tp->root = head;
177 tcf_tree_unlock(tp);
178 }
179
180 if (handle != head->handle)
181 return -ENOENT;
182
183 err = nla_parse_nested(tb, TCA_CGROUP_MAX, tca[TCA_OPTIONS],
184 cgroup_policy);
185 if (err < 0)
186 return err;
187
188 err = tcf_exts_validate(tp, tb, tca[TCA_RATE], &e, &cgroup_ext_map);
189 if (err < 0)
190 return err;
191
192 err = tcf_em_tree_validate(tp, tb[TCA_CGROUP_EMATCHES], &t);
193 if (err < 0)
194 return err;
195
196 tcf_exts_change(tp, &head->exts, &e);
197 tcf_em_tree_change(tp, &head->ematches, &t);
198
199 return 0;
200}
201
202static void cls_cgroup_destroy(struct tcf_proto *tp)
203{
204 struct cls_cgroup_head *head = tp->root;
205
206 if (head) {
207 tcf_exts_destroy(tp, &head->exts);
208 tcf_em_tree_destroy(tp, &head->ematches);
209 kfree(head);
210 }
211}
212
213static int cls_cgroup_delete(struct tcf_proto *tp, unsigned long arg)
214{
215 return -EOPNOTSUPP;
216}
217
218static void cls_cgroup_walk(struct tcf_proto *tp, struct tcf_walker *arg)
219{
220 struct cls_cgroup_head *head = tp->root;
221
222 if (arg->count < arg->skip)
223 goto skip;
224
225 if (arg->fn(tp, (unsigned long) head, arg) < 0) {
226 arg->stop = 1;
227 return;
228 }
229skip:
230 arg->count++;
231}
232
233static int cls_cgroup_dump(struct tcf_proto *tp, unsigned long fh,
234 struct sk_buff *skb, struct tcmsg *t)
235{
236 struct cls_cgroup_head *head = tp->root;
237 unsigned char *b = skb_tail_pointer(skb);
238 struct nlattr *nest;
239
240 t->tcm_handle = head->handle;
241
242 nest = nla_nest_start(skb, TCA_OPTIONS);
243 if (nest == NULL)
244 goto nla_put_failure;
245
246 if (tcf_exts_dump(skb, &head->exts, &cgroup_ext_map) < 0 ||
247 tcf_em_tree_dump(skb, &head->ematches, TCA_CGROUP_EMATCHES) < 0)
248 goto nla_put_failure;
249
250 nla_nest_end(skb, nest);
251
252 if (tcf_exts_dump_stats(skb, &head->exts, &cgroup_ext_map) < 0)
253 goto nla_put_failure;
254
255 return skb->len;
256
257nla_put_failure:
258 nlmsg_trim(skb, b);
259 return -1;
260}
261
262static struct tcf_proto_ops cls_cgroup_ops __read_mostly = {
263 .kind = "cgroup",
264 .init = cls_cgroup_init,
265 .change = cls_cgroup_change,
266 .classify = cls_cgroup_classify,
267 .destroy = cls_cgroup_destroy,
268 .get = cls_cgroup_get,
269 .put = cls_cgroup_put,
270 .delete = cls_cgroup_delete,
271 .walk = cls_cgroup_walk,
272 .dump = cls_cgroup_dump,
273 .owner = THIS_MODULE,
274};
275
276static int __init init_cgroup_cls(void)
277{
278 return register_tcf_proto_ops(&cls_cgroup_ops);
279}
280
281static void __exit exit_cgroup_cls(void)
282{
283 unregister_tcf_proto_ops(&cls_cgroup_ops);
284}
285
286module_init(init_cgroup_cls);
287module_exit(exit_cgroup_cls);
288MODULE_LICENSE("GPL");
diff --git a/net/sched/cls_fw.c b/net/sched/cls_fw.c
index b0f90e593af0..6d6e87585fb1 100644
--- a/net/sched/cls_fw.c
+++ b/net/sched/cls_fw.c
@@ -148,7 +148,7 @@ fw_delete_filter(struct tcf_proto *tp, struct fw_filter *f)
148 148
149static void fw_destroy(struct tcf_proto *tp) 149static void fw_destroy(struct tcf_proto *tp)
150{ 150{
151 struct fw_head *head = (struct fw_head*)xchg(&tp->root, NULL); 151 struct fw_head *head = tp->root;
152 struct fw_filter *f; 152 struct fw_filter *f;
153 int h; 153 int h;
154 154
diff --git a/net/sched/cls_route.c b/net/sched/cls_route.c
index e3d8455eebc2..bdf1f4172eef 100644
--- a/net/sched/cls_route.c
+++ b/net/sched/cls_route.c
@@ -260,7 +260,7 @@ route4_delete_filter(struct tcf_proto *tp, struct route4_filter *f)
260 260
261static void route4_destroy(struct tcf_proto *tp) 261static void route4_destroy(struct tcf_proto *tp)
262{ 262{
263 struct route4_head *head = xchg(&tp->root, NULL); 263 struct route4_head *head = tp->root;
264 int h1, h2; 264 int h1, h2;
265 265
266 if (head == NULL) 266 if (head == NULL)
diff --git a/net/sched/cls_tcindex.c b/net/sched/cls_tcindex.c
index 7a7bff5ded24..e806f2314b5e 100644
--- a/net/sched/cls_tcindex.c
+++ b/net/sched/cls_tcindex.c
@@ -13,12 +13,6 @@
13#include <net/netlink.h> 13#include <net/netlink.h>
14#include <net/pkt_cls.h> 14#include <net/pkt_cls.h>
15 15
16
17/*
18 * Not quite sure if we need all the xchgs Alexey uses when accessing things.
19 * Can always add them later ... :)
20 */
21
22/* 16/*
23 * Passing parameters to the root seems to be done more awkwardly than really 17 * Passing parameters to the root seems to be done more awkwardly than really
24 * necessary. At least, u32 doesn't seem to use such dirty hacks. To be 18 * necessary. At least, u32 doesn't seem to use such dirty hacks. To be
diff --git a/net/sched/cls_u32.c b/net/sched/cls_u32.c
index 246f9065ce34..05d178008cbc 100644
--- a/net/sched/cls_u32.c
+++ b/net/sched/cls_u32.c
@@ -387,7 +387,7 @@ static int u32_destroy_hnode(struct tcf_proto *tp, struct tc_u_hnode *ht)
387static void u32_destroy(struct tcf_proto *tp) 387static void u32_destroy(struct tcf_proto *tp)
388{ 388{
389 struct tc_u_common *tp_c = tp->data; 389 struct tc_u_common *tp_c = tp->data;
390 struct tc_u_hnode *root_ht = xchg(&tp->root, NULL); 390 struct tc_u_hnode *root_ht = tp->root;
391 391
392 WARN_ON(root_ht == NULL); 392 WARN_ON(root_ht == NULL);
393 393
@@ -479,7 +479,7 @@ static int u32_set_parms(struct tcf_proto *tp, unsigned long base,
479 err = -EINVAL; 479 err = -EINVAL;
480 if (tb[TCA_U32_LINK]) { 480 if (tb[TCA_U32_LINK]) {
481 u32 handle = nla_get_u32(tb[TCA_U32_LINK]); 481 u32 handle = nla_get_u32(tb[TCA_U32_LINK]);
482 struct tc_u_hnode *ht_down = NULL; 482 struct tc_u_hnode *ht_down = NULL, *ht_old;
483 483
484 if (TC_U32_KEY(handle)) 484 if (TC_U32_KEY(handle))
485 goto errout; 485 goto errout;
@@ -493,11 +493,12 @@ static int u32_set_parms(struct tcf_proto *tp, unsigned long base,
493 } 493 }
494 494
495 tcf_tree_lock(tp); 495 tcf_tree_lock(tp);
496 ht_down = xchg(&n->ht_down, ht_down); 496 ht_old = n->ht_down;
497 n->ht_down = ht_down;
497 tcf_tree_unlock(tp); 498 tcf_tree_unlock(tp);
498 499
499 if (ht_down) 500 if (ht_old)
500 ht_down->refcnt--; 501 ht_old->refcnt--;
501 } 502 }
502 if (tb[TCA_U32_CLASSID]) { 503 if (tb[TCA_U32_CLASSID]) {
503 n->res.classid = nla_get_u32(tb[TCA_U32_CLASSID]); 504 n->res.classid = nla_get_u32(tb[TCA_U32_CLASSID]);
diff --git a/net/sched/ematch.c b/net/sched/ematch.c
index e82519e548d7..aab59409728b 100644
--- a/net/sched/ematch.c
+++ b/net/sched/ematch.c
@@ -71,7 +71,7 @@
71 * 71 *
72 * static void __exit exit_my_ematch(void) 72 * static void __exit exit_my_ematch(void)
73 * { 73 * {
74 * return tcf_em_unregister(&my_ops); 74 * tcf_em_unregister(&my_ops);
75 * } 75 * }
76 * 76 *
77 * module_init(init_my_ematch); 77 * module_init(init_my_ematch);
@@ -154,23 +154,11 @@ EXPORT_SYMBOL(tcf_em_register);
154 * 154 *
155 * Returns -ENOENT if no matching ematch was found. 155 * Returns -ENOENT if no matching ematch was found.
156 */ 156 */
157int tcf_em_unregister(struct tcf_ematch_ops *ops) 157void tcf_em_unregister(struct tcf_ematch_ops *ops)
158{ 158{
159 int err = 0;
160 struct tcf_ematch_ops *e;
161
162 write_lock(&ematch_mod_lock); 159 write_lock(&ematch_mod_lock);
163 list_for_each_entry(e, &ematch_ops, link) { 160 list_del(&ops->link);
164 if (e == ops) {
165 list_del(&e->link);
166 goto out;
167 }
168 }
169
170 err = -ENOENT;
171out:
172 write_unlock(&ematch_mod_lock); 161 write_unlock(&ematch_mod_lock);
173 return err;
174} 162}
175EXPORT_SYMBOL(tcf_em_unregister); 163EXPORT_SYMBOL(tcf_em_unregister);
176 164
diff --git a/net/sched/sch_api.c b/net/sched/sch_api.c
index 6ab4a2f92ca0..0fc4a18fd96f 100644
--- a/net/sched/sch_api.c
+++ b/net/sched/sch_api.c
@@ -97,10 +97,9 @@ static int tclass_notify(struct sk_buff *oskb, struct nlmsghdr *n,
97 97
98 Auxiliary routines: 98 Auxiliary routines:
99 99
100 ---requeue 100 ---peek
101 101
102 requeues once dequeued packet. It is used for non-standard or 102 like dequeue but without removing a packet from the queue
103 just buggy devices, which can defer output even if netif_queue_stopped()=0.
104 103
105 ---reset 104 ---reset
106 105
@@ -147,8 +146,14 @@ int register_qdisc(struct Qdisc_ops *qops)
147 146
148 if (qops->enqueue == NULL) 147 if (qops->enqueue == NULL)
149 qops->enqueue = noop_qdisc_ops.enqueue; 148 qops->enqueue = noop_qdisc_ops.enqueue;
150 if (qops->requeue == NULL) 149 if (qops->peek == NULL) {
151 qops->requeue = noop_qdisc_ops.requeue; 150 if (qops->dequeue == NULL) {
151 qops->peek = noop_qdisc_ops.peek;
152 } else {
153 rc = -EINVAL;
154 goto out;
155 }
156 }
152 if (qops->dequeue == NULL) 157 if (qops->dequeue == NULL)
153 qops->dequeue = noop_qdisc_ops.dequeue; 158 qops->dequeue = noop_qdisc_ops.dequeue;
154 159
@@ -184,7 +189,7 @@ EXPORT_SYMBOL(unregister_qdisc);
184 (root qdisc, all its children, children of children etc.) 189 (root qdisc, all its children, children of children etc.)
185 */ 190 */
186 191
187struct Qdisc *qdisc_match_from_root(struct Qdisc *root, u32 handle) 192static struct Qdisc *qdisc_match_from_root(struct Qdisc *root, u32 handle)
188{ 193{
189 struct Qdisc *q; 194 struct Qdisc *q;
190 195
@@ -199,28 +204,16 @@ struct Qdisc *qdisc_match_from_root(struct Qdisc *root, u32 handle)
199 return NULL; 204 return NULL;
200} 205}
201 206
202/*
203 * This lock is needed until some qdiscs stop calling qdisc_tree_decrease_qlen()
204 * without rtnl_lock(); currently hfsc_dequeue(), netem_dequeue(), tbf_dequeue()
205 */
206static DEFINE_SPINLOCK(qdisc_list_lock);
207
208static void qdisc_list_add(struct Qdisc *q) 207static void qdisc_list_add(struct Qdisc *q)
209{ 208{
210 if ((q->parent != TC_H_ROOT) && !(q->flags & TCQ_F_INGRESS)) { 209 if ((q->parent != TC_H_ROOT) && !(q->flags & TCQ_F_INGRESS))
211 spin_lock_bh(&qdisc_list_lock);
212 list_add_tail(&q->list, &qdisc_root_sleeping(q)->list); 210 list_add_tail(&q->list, &qdisc_root_sleeping(q)->list);
213 spin_unlock_bh(&qdisc_list_lock);
214 }
215} 211}
216 212
217void qdisc_list_del(struct Qdisc *q) 213void qdisc_list_del(struct Qdisc *q)
218{ 214{
219 if ((q->parent != TC_H_ROOT) && !(q->flags & TCQ_F_INGRESS)) { 215 if ((q->parent != TC_H_ROOT) && !(q->flags & TCQ_F_INGRESS))
220 spin_lock_bh(&qdisc_list_lock);
221 list_del(&q->list); 216 list_del(&q->list);
222 spin_unlock_bh(&qdisc_list_lock);
223 }
224} 217}
225EXPORT_SYMBOL(qdisc_list_del); 218EXPORT_SYMBOL(qdisc_list_del);
226 219
@@ -229,22 +222,17 @@ struct Qdisc *qdisc_lookup(struct net_device *dev, u32 handle)
229 unsigned int i; 222 unsigned int i;
230 struct Qdisc *q; 223 struct Qdisc *q;
231 224
232 spin_lock_bh(&qdisc_list_lock);
233
234 for (i = 0; i < dev->num_tx_queues; i++) { 225 for (i = 0; i < dev->num_tx_queues; i++) {
235 struct netdev_queue *txq = netdev_get_tx_queue(dev, i); 226 struct netdev_queue *txq = netdev_get_tx_queue(dev, i);
236 struct Qdisc *txq_root = txq->qdisc_sleeping; 227 struct Qdisc *txq_root = txq->qdisc_sleeping;
237 228
238 q = qdisc_match_from_root(txq_root, handle); 229 q = qdisc_match_from_root(txq_root, handle);
239 if (q) 230 if (q)
240 goto unlock; 231 goto out;
241 } 232 }
242 233
243 q = qdisc_match_from_root(dev->rx_queue.qdisc_sleeping, handle); 234 q = qdisc_match_from_root(dev->rx_queue.qdisc_sleeping, handle);
244 235out:
245unlock:
246 spin_unlock_bh(&qdisc_list_lock);
247
248 return q; 236 return q;
249} 237}
250 238
@@ -462,7 +450,6 @@ static enum hrtimer_restart qdisc_watchdog(struct hrtimer *timer)
462 timer); 450 timer);
463 451
464 wd->qdisc->flags &= ~TCQ_F_THROTTLED; 452 wd->qdisc->flags &= ~TCQ_F_THROTTLED;
465 smp_wmb();
466 __netif_schedule(qdisc_root(wd->qdisc)); 453 __netif_schedule(qdisc_root(wd->qdisc));
467 454
468 return HRTIMER_NORESTART; 455 return HRTIMER_NORESTART;
@@ -892,9 +879,12 @@ static int qdisc_change(struct Qdisc *sch, struct nlattr **tca)
892 sch->stab = stab; 879 sch->stab = stab;
893 880
894 if (tca[TCA_RATE]) 881 if (tca[TCA_RATE])
882 /* NB: ignores errors from replace_estimator
883 because change can't be undone. */
895 gen_replace_estimator(&sch->bstats, &sch->rate_est, 884 gen_replace_estimator(&sch->bstats, &sch->rate_est,
896 qdisc_root_sleeping_lock(sch), 885 qdisc_root_sleeping_lock(sch),
897 tca[TCA_RATE]); 886 tca[TCA_RATE]);
887
898 return 0; 888 return 0;
899} 889}
900 890
diff --git a/net/sched/sch_atm.c b/net/sched/sch_atm.c
index 43d37256c15e..2a8b83af7c47 100644
--- a/net/sched/sch_atm.c
+++ b/net/sched/sch_atm.c
@@ -62,7 +62,7 @@ struct atm_qdisc_data {
62 struct atm_flow_data link; /* unclassified skbs go here */ 62 struct atm_flow_data link; /* unclassified skbs go here */
63 struct atm_flow_data *flows; /* NB: "link" is also on this 63 struct atm_flow_data *flows; /* NB: "link" is also on this
64 list */ 64 list */
65 struct tasklet_struct task; /* requeue tasklet */ 65 struct tasklet_struct task; /* dequeue tasklet */
66}; 66};
67 67
68/* ------------------------- Class/flow operations ------------------------- */ 68/* ------------------------- Class/flow operations ------------------------- */
@@ -102,7 +102,8 @@ static int atm_tc_graft(struct Qdisc *sch, unsigned long arg,
102 return -EINVAL; 102 return -EINVAL;
103 if (!new) 103 if (!new)
104 new = &noop_qdisc; 104 new = &noop_qdisc;
105 *old = xchg(&flow->q, new); 105 *old = flow->q;
106 flow->q = new;
106 if (*old) 107 if (*old)
107 qdisc_reset(*old); 108 qdisc_reset(*old);
108 return 0; 109 return 0;
@@ -480,11 +481,14 @@ static void sch_atm_dequeue(unsigned long data)
480 * If traffic is properly shaped, this won't generate nasty 481 * If traffic is properly shaped, this won't generate nasty
481 * little bursts. Otherwise, it may ... (but that's okay) 482 * little bursts. Otherwise, it may ... (but that's okay)
482 */ 483 */
483 while ((skb = flow->q->dequeue(flow->q))) { 484 while ((skb = flow->q->ops->peek(flow->q))) {
484 if (!atm_may_send(flow->vcc, skb->truesize)) { 485 if (!atm_may_send(flow->vcc, skb->truesize))
485 (void)flow->q->ops->requeue(skb, flow->q);
486 break; 486 break;
487 } 487
488 skb = qdisc_dequeue_peeked(flow->q);
489 if (unlikely(!skb))
490 break;
491
488 pr_debug("atm_tc_dequeue: sending on class %p\n", flow); 492 pr_debug("atm_tc_dequeue: sending on class %p\n", flow);
489 /* remove any LL header somebody else has attached */ 493 /* remove any LL header somebody else has attached */
490 skb_pull(skb, skb_network_offset(skb)); 494 skb_pull(skb, skb_network_offset(skb));
@@ -516,27 +520,19 @@ static struct sk_buff *atm_tc_dequeue(struct Qdisc *sch)
516 520
517 pr_debug("atm_tc_dequeue(sch %p,[qdisc %p])\n", sch, p); 521 pr_debug("atm_tc_dequeue(sch %p,[qdisc %p])\n", sch, p);
518 tasklet_schedule(&p->task); 522 tasklet_schedule(&p->task);
519 skb = p->link.q->dequeue(p->link.q); 523 skb = qdisc_dequeue_peeked(p->link.q);
520 if (skb) 524 if (skb)
521 sch->q.qlen--; 525 sch->q.qlen--;
522 return skb; 526 return skb;
523} 527}
524 528
525static int atm_tc_requeue(struct sk_buff *skb, struct Qdisc *sch) 529static struct sk_buff *atm_tc_peek(struct Qdisc *sch)
526{ 530{
527 struct atm_qdisc_data *p = qdisc_priv(sch); 531 struct atm_qdisc_data *p = qdisc_priv(sch);
528 int ret;
529 532
530 pr_debug("atm_tc_requeue(skb %p,sch %p,[qdisc %p])\n", skb, sch, p); 533 pr_debug("atm_tc_peek(sch %p,[qdisc %p])\n", sch, p);
531 ret = p->link.q->ops->requeue(skb, p->link.q); 534
532 if (!ret) { 535 return p->link.q->ops->peek(p->link.q);
533 sch->q.qlen++;
534 sch->qstats.requeues++;
535 } else if (net_xmit_drop_count(ret)) {
536 sch->qstats.drops++;
537 p->link.qstats.drops++;
538 }
539 return ret;
540} 536}
541 537
542static unsigned int atm_tc_drop(struct Qdisc *sch) 538static unsigned int atm_tc_drop(struct Qdisc *sch)
@@ -694,7 +690,7 @@ static struct Qdisc_ops atm_qdisc_ops __read_mostly = {
694 .priv_size = sizeof(struct atm_qdisc_data), 690 .priv_size = sizeof(struct atm_qdisc_data),
695 .enqueue = atm_tc_enqueue, 691 .enqueue = atm_tc_enqueue,
696 .dequeue = atm_tc_dequeue, 692 .dequeue = atm_tc_dequeue,
697 .requeue = atm_tc_requeue, 693 .peek = atm_tc_peek,
698 .drop = atm_tc_drop, 694 .drop = atm_tc_drop,
699 .init = atm_tc_init, 695 .init = atm_tc_init,
700 .reset = atm_tc_reset, 696 .reset = atm_tc_reset,
diff --git a/net/sched/sch_blackhole.c b/net/sched/sch_blackhole.c
index 507fb488bc98..094a874b48bc 100644
--- a/net/sched/sch_blackhole.c
+++ b/net/sched/sch_blackhole.c
@@ -33,6 +33,7 @@ static struct Qdisc_ops blackhole_qdisc_ops __read_mostly = {
33 .priv_size = 0, 33 .priv_size = 0,
34 .enqueue = blackhole_enqueue, 34 .enqueue = blackhole_enqueue,
35 .dequeue = blackhole_dequeue, 35 .dequeue = blackhole_dequeue,
36 .peek = blackhole_dequeue,
36 .owner = THIS_MODULE, 37 .owner = THIS_MODULE,
37}; 38};
38 39
diff --git a/net/sched/sch_cbq.c b/net/sched/sch_cbq.c
index 03e389e8d945..9e43ed949167 100644
--- a/net/sched/sch_cbq.c
+++ b/net/sched/sch_cbq.c
@@ -405,40 +405,6 @@ cbq_enqueue(struct sk_buff *skb, struct Qdisc *sch)
405 return ret; 405 return ret;
406} 406}
407 407
408static int
409cbq_requeue(struct sk_buff *skb, struct Qdisc *sch)
410{
411 struct cbq_sched_data *q = qdisc_priv(sch);
412 struct cbq_class *cl;
413 int ret;
414
415 if ((cl = q->tx_class) == NULL) {
416 kfree_skb(skb);
417 sch->qstats.drops++;
418 return NET_XMIT_CN;
419 }
420 q->tx_class = NULL;
421
422 cbq_mark_toplevel(q, cl);
423
424#ifdef CONFIG_NET_CLS_ACT
425 q->rx_class = cl;
426 cl->q->__parent = sch;
427#endif
428 if ((ret = cl->q->ops->requeue(skb, cl->q)) == 0) {
429 sch->q.qlen++;
430 sch->qstats.requeues++;
431 if (!cl->next_alive)
432 cbq_activate_class(cl);
433 return 0;
434 }
435 if (net_xmit_drop_count(ret)) {
436 sch->qstats.drops++;
437 cl->qstats.drops++;
438 }
439 return ret;
440}
441
442/* Overlimit actions */ 408/* Overlimit actions */
443 409
444/* TC_CBQ_OVL_CLASSIC: (default) penalize leaf class by adding offtime */ 410/* TC_CBQ_OVL_CLASSIC: (default) penalize leaf class by adding offtime */
@@ -1669,7 +1635,8 @@ static int cbq_graft(struct Qdisc *sch, unsigned long arg, struct Qdisc *new,
1669#endif 1635#endif
1670 } 1636 }
1671 sch_tree_lock(sch); 1637 sch_tree_lock(sch);
1672 *old = xchg(&cl->q, new); 1638 *old = cl->q;
1639 cl->q = new;
1673 qdisc_tree_decrease_qlen(*old, (*old)->q.qlen); 1640 qdisc_tree_decrease_qlen(*old, (*old)->q.qlen);
1674 qdisc_reset(*old); 1641 qdisc_reset(*old);
1675 sch_tree_unlock(sch); 1642 sch_tree_unlock(sch);
@@ -1798,11 +1765,23 @@ cbq_change_class(struct Qdisc *sch, u32 classid, u32 parentid, struct nlattr **t
1798 } 1765 }
1799 1766
1800 if (tb[TCA_CBQ_RATE]) { 1767 if (tb[TCA_CBQ_RATE]) {
1801 rtab = qdisc_get_rtab(nla_data(tb[TCA_CBQ_RATE]), tb[TCA_CBQ_RTAB]); 1768 rtab = qdisc_get_rtab(nla_data(tb[TCA_CBQ_RATE]),
1769 tb[TCA_CBQ_RTAB]);
1802 if (rtab == NULL) 1770 if (rtab == NULL)
1803 return -EINVAL; 1771 return -EINVAL;
1804 } 1772 }
1805 1773
1774 if (tca[TCA_RATE]) {
1775 err = gen_replace_estimator(&cl->bstats, &cl->rate_est,
1776 qdisc_root_sleeping_lock(sch),
1777 tca[TCA_RATE]);
1778 if (err) {
1779 if (rtab)
1780 qdisc_put_rtab(rtab);
1781 return err;
1782 }
1783 }
1784
1806 /* Change class parameters */ 1785 /* Change class parameters */
1807 sch_tree_lock(sch); 1786 sch_tree_lock(sch);
1808 1787
@@ -1810,8 +1789,8 @@ cbq_change_class(struct Qdisc *sch, u32 classid, u32 parentid, struct nlattr **t
1810 cbq_deactivate_class(cl); 1789 cbq_deactivate_class(cl);
1811 1790
1812 if (rtab) { 1791 if (rtab) {
1813 rtab = xchg(&cl->R_tab, rtab); 1792 qdisc_put_rtab(cl->R_tab);
1814 qdisc_put_rtab(rtab); 1793 cl->R_tab = rtab;
1815 } 1794 }
1816 1795
1817 if (tb[TCA_CBQ_LSSOPT]) 1796 if (tb[TCA_CBQ_LSSOPT])
@@ -1838,10 +1817,6 @@ cbq_change_class(struct Qdisc *sch, u32 classid, u32 parentid, struct nlattr **t
1838 1817
1839 sch_tree_unlock(sch); 1818 sch_tree_unlock(sch);
1840 1819
1841 if (tca[TCA_RATE])
1842 gen_replace_estimator(&cl->bstats, &cl->rate_est,
1843 qdisc_root_sleeping_lock(sch),
1844 tca[TCA_RATE]);
1845 return 0; 1820 return 0;
1846 } 1821 }
1847 1822
@@ -1888,6 +1863,17 @@ cbq_change_class(struct Qdisc *sch, u32 classid, u32 parentid, struct nlattr **t
1888 cl = kzalloc(sizeof(*cl), GFP_KERNEL); 1863 cl = kzalloc(sizeof(*cl), GFP_KERNEL);
1889 if (cl == NULL) 1864 if (cl == NULL)
1890 goto failure; 1865 goto failure;
1866
1867 if (tca[TCA_RATE]) {
1868 err = gen_new_estimator(&cl->bstats, &cl->rate_est,
1869 qdisc_root_sleeping_lock(sch),
1870 tca[TCA_RATE]);
1871 if (err) {
1872 kfree(cl);
1873 goto failure;
1874 }
1875 }
1876
1891 cl->R_tab = rtab; 1877 cl->R_tab = rtab;
1892 rtab = NULL; 1878 rtab = NULL;
1893 cl->refcnt = 1; 1879 cl->refcnt = 1;
@@ -1929,10 +1915,6 @@ cbq_change_class(struct Qdisc *sch, u32 classid, u32 parentid, struct nlattr **t
1929 1915
1930 qdisc_class_hash_grow(sch, &q->clhash); 1916 qdisc_class_hash_grow(sch, &q->clhash);
1931 1917
1932 if (tca[TCA_RATE])
1933 gen_new_estimator(&cl->bstats, &cl->rate_est,
1934 qdisc_root_sleeping_lock(sch), tca[TCA_RATE]);
1935
1936 *arg = (unsigned long)cl; 1918 *arg = (unsigned long)cl;
1937 return 0; 1919 return 0;
1938 1920
@@ -2066,7 +2048,7 @@ static struct Qdisc_ops cbq_qdisc_ops __read_mostly = {
2066 .priv_size = sizeof(struct cbq_sched_data), 2048 .priv_size = sizeof(struct cbq_sched_data),
2067 .enqueue = cbq_enqueue, 2049 .enqueue = cbq_enqueue,
2068 .dequeue = cbq_dequeue, 2050 .dequeue = cbq_dequeue,
2069 .requeue = cbq_requeue, 2051 .peek = qdisc_peek_dequeued,
2070 .drop = cbq_drop, 2052 .drop = cbq_drop,
2071 .init = cbq_init, 2053 .init = cbq_init,
2072 .reset = cbq_reset, 2054 .reset = cbq_reset,
diff --git a/net/sched/sch_drr.c b/net/sched/sch_drr.c
new file mode 100644
index 000000000000..f6b4fa97df70
--- /dev/null
+++ b/net/sched/sch_drr.c
@@ -0,0 +1,519 @@
1/*
2 * net/sched/sch_drr.c Deficit Round Robin scheduler
3 *
4 * Copyright (c) 2008 Patrick McHardy <kaber@trash.net>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * version 2 as published by the Free Software Foundation.
9 */
10
11#include <linux/module.h>
12#include <linux/init.h>
13#include <linux/errno.h>
14#include <linux/netdevice.h>
15#include <linux/pkt_sched.h>
16#include <net/sch_generic.h>
17#include <net/pkt_sched.h>
18#include <net/pkt_cls.h>
19
20struct drr_class {
21 struct Qdisc_class_common common;
22 unsigned int refcnt;
23 unsigned int filter_cnt;
24
25 struct gnet_stats_basic bstats;
26 struct gnet_stats_queue qstats;
27 struct gnet_stats_rate_est rate_est;
28 struct list_head alist;
29 struct Qdisc *qdisc;
30
31 u32 quantum;
32 u32 deficit;
33};
34
35struct drr_sched {
36 struct list_head active;
37 struct tcf_proto *filter_list;
38 struct Qdisc_class_hash clhash;
39};
40
41static struct drr_class *drr_find_class(struct Qdisc *sch, u32 classid)
42{
43 struct drr_sched *q = qdisc_priv(sch);
44 struct Qdisc_class_common *clc;
45
46 clc = qdisc_class_find(&q->clhash, classid);
47 if (clc == NULL)
48 return NULL;
49 return container_of(clc, struct drr_class, common);
50}
51
52static void drr_purge_queue(struct drr_class *cl)
53{
54 unsigned int len = cl->qdisc->q.qlen;
55
56 qdisc_reset(cl->qdisc);
57 qdisc_tree_decrease_qlen(cl->qdisc, len);
58}
59
60static const struct nla_policy drr_policy[TCA_DRR_MAX + 1] = {
61 [TCA_DRR_QUANTUM] = { .type = NLA_U32 },
62};
63
64static int drr_change_class(struct Qdisc *sch, u32 classid, u32 parentid,
65 struct nlattr **tca, unsigned long *arg)
66{
67 struct drr_sched *q = qdisc_priv(sch);
68 struct drr_class *cl = (struct drr_class *)*arg;
69 struct nlattr *tb[TCA_DRR_MAX + 1];
70 u32 quantum;
71 int err;
72
73 err = nla_parse_nested(tb, TCA_DRR_MAX, tca[TCA_OPTIONS], drr_policy);
74 if (err < 0)
75 return err;
76
77 if (tb[TCA_DRR_QUANTUM]) {
78 quantum = nla_get_u32(tb[TCA_DRR_QUANTUM]);
79 if (quantum == 0)
80 return -EINVAL;
81 } else
82 quantum = psched_mtu(qdisc_dev(sch));
83
84 if (cl != NULL) {
85 if (tca[TCA_RATE]) {
86 err = gen_replace_estimator(&cl->bstats, &cl->rate_est,
87 qdisc_root_sleeping_lock(sch),
88 tca[TCA_RATE]);
89 if (err)
90 return err;
91 }
92
93 sch_tree_lock(sch);
94 if (tb[TCA_DRR_QUANTUM])
95 cl->quantum = quantum;
96 sch_tree_unlock(sch);
97
98 return 0;
99 }
100
101 cl = kzalloc(sizeof(struct drr_class), GFP_KERNEL);
102 if (cl == NULL)
103 return -ENOBUFS;
104
105 cl->refcnt = 1;
106 cl->common.classid = classid;
107 cl->quantum = quantum;
108 cl->qdisc = qdisc_create_dflt(qdisc_dev(sch), sch->dev_queue,
109 &pfifo_qdisc_ops, classid);
110 if (cl->qdisc == NULL)
111 cl->qdisc = &noop_qdisc;
112
113 if (tca[TCA_RATE]) {
114 err = gen_replace_estimator(&cl->bstats, &cl->rate_est,
115 qdisc_root_sleeping_lock(sch),
116 tca[TCA_RATE]);
117 if (err) {
118 qdisc_destroy(cl->qdisc);
119 kfree(cl);
120 return err;
121 }
122 }
123
124 sch_tree_lock(sch);
125 qdisc_class_hash_insert(&q->clhash, &cl->common);
126 sch_tree_unlock(sch);
127
128 qdisc_class_hash_grow(sch, &q->clhash);
129
130 *arg = (unsigned long)cl;
131 return 0;
132}
133
134static void drr_destroy_class(struct Qdisc *sch, struct drr_class *cl)
135{
136 gen_kill_estimator(&cl->bstats, &cl->rate_est);
137 qdisc_destroy(cl->qdisc);
138 kfree(cl);
139}
140
141static int drr_delete_class(struct Qdisc *sch, unsigned long arg)
142{
143 struct drr_sched *q = qdisc_priv(sch);
144 struct drr_class *cl = (struct drr_class *)arg;
145
146 if (cl->filter_cnt > 0)
147 return -EBUSY;
148
149 sch_tree_lock(sch);
150
151 drr_purge_queue(cl);
152 qdisc_class_hash_remove(&q->clhash, &cl->common);
153
154 if (--cl->refcnt == 0)
155 drr_destroy_class(sch, cl);
156
157 sch_tree_unlock(sch);
158 return 0;
159}
160
161static unsigned long drr_get_class(struct Qdisc *sch, u32 classid)
162{
163 struct drr_class *cl = drr_find_class(sch, classid);
164
165 if (cl != NULL)
166 cl->refcnt++;
167
168 return (unsigned long)cl;
169}
170
171static void drr_put_class(struct Qdisc *sch, unsigned long arg)
172{
173 struct drr_class *cl = (struct drr_class *)arg;
174
175 if (--cl->refcnt == 0)
176 drr_destroy_class(sch, cl);
177}
178
179static struct tcf_proto **drr_tcf_chain(struct Qdisc *sch, unsigned long cl)
180{
181 struct drr_sched *q = qdisc_priv(sch);
182
183 if (cl)
184 return NULL;
185
186 return &q->filter_list;
187}
188
189static unsigned long drr_bind_tcf(struct Qdisc *sch, unsigned long parent,
190 u32 classid)
191{
192 struct drr_class *cl = drr_find_class(sch, classid);
193
194 if (cl != NULL)
195 cl->filter_cnt++;
196
197 return (unsigned long)cl;
198}
199
200static void drr_unbind_tcf(struct Qdisc *sch, unsigned long arg)
201{
202 struct drr_class *cl = (struct drr_class *)arg;
203
204 cl->filter_cnt--;
205}
206
207static int drr_graft_class(struct Qdisc *sch, unsigned long arg,
208 struct Qdisc *new, struct Qdisc **old)
209{
210 struct drr_class *cl = (struct drr_class *)arg;
211
212 if (new == NULL) {
213 new = qdisc_create_dflt(qdisc_dev(sch), sch->dev_queue,
214 &pfifo_qdisc_ops, cl->common.classid);
215 if (new == NULL)
216 new = &noop_qdisc;
217 }
218
219 sch_tree_lock(sch);
220 drr_purge_queue(cl);
221 *old = cl->qdisc;
222 cl->qdisc = new;
223 sch_tree_unlock(sch);
224 return 0;
225}
226
227static struct Qdisc *drr_class_leaf(struct Qdisc *sch, unsigned long arg)
228{
229 struct drr_class *cl = (struct drr_class *)arg;
230
231 return cl->qdisc;
232}
233
234static void drr_qlen_notify(struct Qdisc *csh, unsigned long arg)
235{
236 struct drr_class *cl = (struct drr_class *)arg;
237
238 if (cl->qdisc->q.qlen == 0)
239 list_del(&cl->alist);
240}
241
242static int drr_dump_class(struct Qdisc *sch, unsigned long arg,
243 struct sk_buff *skb, struct tcmsg *tcm)
244{
245 struct drr_class *cl = (struct drr_class *)arg;
246 struct nlattr *nest;
247
248 tcm->tcm_parent = TC_H_ROOT;
249 tcm->tcm_handle = cl->common.classid;
250 tcm->tcm_info = cl->qdisc->handle;
251
252 nest = nla_nest_start(skb, TCA_OPTIONS);
253 if (nest == NULL)
254 goto nla_put_failure;
255 NLA_PUT_U32(skb, TCA_DRR_QUANTUM, cl->quantum);
256 return nla_nest_end(skb, nest);
257
258nla_put_failure:
259 nla_nest_cancel(skb, nest);
260 return -EMSGSIZE;
261}
262
263static int drr_dump_class_stats(struct Qdisc *sch, unsigned long arg,
264 struct gnet_dump *d)
265{
266 struct drr_class *cl = (struct drr_class *)arg;
267 struct tc_drr_stats xstats;
268
269 memset(&xstats, 0, sizeof(xstats));
270 if (cl->qdisc->q.qlen)
271 xstats.deficit = cl->deficit;
272
273 if (gnet_stats_copy_basic(d, &cl->bstats) < 0 ||
274 gnet_stats_copy_rate_est(d, &cl->rate_est) < 0 ||
275 gnet_stats_copy_queue(d, &cl->qdisc->qstats) < 0)
276 return -1;
277
278 return gnet_stats_copy_app(d, &xstats, sizeof(xstats));
279}
280
281static void drr_walk(struct Qdisc *sch, struct qdisc_walker *arg)
282{
283 struct drr_sched *q = qdisc_priv(sch);
284 struct drr_class *cl;
285 struct hlist_node *n;
286 unsigned int i;
287
288 if (arg->stop)
289 return;
290
291 for (i = 0; i < q->clhash.hashsize; i++) {
292 hlist_for_each_entry(cl, n, &q->clhash.hash[i], common.hnode) {
293 if (arg->count < arg->skip) {
294 arg->count++;
295 continue;
296 }
297 if (arg->fn(sch, (unsigned long)cl, arg) < 0) {
298 arg->stop = 1;
299 return;
300 }
301 arg->count++;
302 }
303 }
304}
305
306static struct drr_class *drr_classify(struct sk_buff *skb, struct Qdisc *sch,
307 int *qerr)
308{
309 struct drr_sched *q = qdisc_priv(sch);
310 struct drr_class *cl;
311 struct tcf_result res;
312 int result;
313
314 if (TC_H_MAJ(skb->priority ^ sch->handle) == 0) {
315 cl = drr_find_class(sch, skb->priority);
316 if (cl != NULL)
317 return cl;
318 }
319
320 *qerr = NET_XMIT_SUCCESS | __NET_XMIT_BYPASS;
321 result = tc_classify(skb, q->filter_list, &res);
322 if (result >= 0) {
323#ifdef CONFIG_NET_CLS_ACT
324 switch (result) {
325 case TC_ACT_QUEUED:
326 case TC_ACT_STOLEN:
327 *qerr = NET_XMIT_SUCCESS | __NET_XMIT_STOLEN;
328 case TC_ACT_SHOT:
329 return NULL;
330 }
331#endif
332 cl = (struct drr_class *)res.class;
333 if (cl == NULL)
334 cl = drr_find_class(sch, res.classid);
335 return cl;
336 }
337 return NULL;
338}
339
340static int drr_enqueue(struct sk_buff *skb, struct Qdisc *sch)
341{
342 struct drr_sched *q = qdisc_priv(sch);
343 struct drr_class *cl;
344 unsigned int len;
345 int err;
346
347 cl = drr_classify(skb, sch, &err);
348 if (cl == NULL) {
349 if (err & __NET_XMIT_BYPASS)
350 sch->qstats.drops++;
351 kfree_skb(skb);
352 return err;
353 }
354
355 len = qdisc_pkt_len(skb);
356 err = qdisc_enqueue(skb, cl->qdisc);
357 if (unlikely(err != NET_XMIT_SUCCESS)) {
358 if (net_xmit_drop_count(err)) {
359 cl->qstats.drops++;
360 sch->qstats.drops++;
361 }
362 return err;
363 }
364
365 if (cl->qdisc->q.qlen == 1) {
366 list_add_tail(&cl->alist, &q->active);
367 cl->deficit = cl->quantum;
368 }
369
370 cl->bstats.packets++;
371 cl->bstats.bytes += len;
372 sch->bstats.packets++;
373 sch->bstats.bytes += len;
374
375 sch->q.qlen++;
376 return err;
377}
378
379static struct sk_buff *drr_dequeue(struct Qdisc *sch)
380{
381 struct drr_sched *q = qdisc_priv(sch);
382 struct drr_class *cl;
383 struct sk_buff *skb;
384 unsigned int len;
385
386 if (list_empty(&q->active))
387 goto out;
388 while (1) {
389 cl = list_first_entry(&q->active, struct drr_class, alist);
390 skb = cl->qdisc->ops->peek(cl->qdisc);
391 if (skb == NULL)
392 goto out;
393
394 len = qdisc_pkt_len(skb);
395 if (len <= cl->deficit) {
396 cl->deficit -= len;
397 skb = qdisc_dequeue_peeked(cl->qdisc);
398 if (cl->qdisc->q.qlen == 0)
399 list_del(&cl->alist);
400 sch->q.qlen--;
401 return skb;
402 }
403
404 cl->deficit += cl->quantum;
405 list_move_tail(&cl->alist, &q->active);
406 }
407out:
408 return NULL;
409}
410
411static unsigned int drr_drop(struct Qdisc *sch)
412{
413 struct drr_sched *q = qdisc_priv(sch);
414 struct drr_class *cl;
415 unsigned int len;
416
417 list_for_each_entry(cl, &q->active, alist) {
418 if (cl->qdisc->ops->drop) {
419 len = cl->qdisc->ops->drop(cl->qdisc);
420 if (len > 0) {
421 sch->q.qlen--;
422 if (cl->qdisc->q.qlen == 0)
423 list_del(&cl->alist);
424 return len;
425 }
426 }
427 }
428 return 0;
429}
430
431static int drr_init_qdisc(struct Qdisc *sch, struct nlattr *opt)
432{
433 struct drr_sched *q = qdisc_priv(sch);
434 int err;
435
436 err = qdisc_class_hash_init(&q->clhash);
437 if (err < 0)
438 return err;
439 INIT_LIST_HEAD(&q->active);
440 return 0;
441}
442
443static void drr_reset_qdisc(struct Qdisc *sch)
444{
445 struct drr_sched *q = qdisc_priv(sch);
446 struct drr_class *cl;
447 struct hlist_node *n;
448 unsigned int i;
449
450 for (i = 0; i < q->clhash.hashsize; i++) {
451 hlist_for_each_entry(cl, n, &q->clhash.hash[i], common.hnode) {
452 if (cl->qdisc->q.qlen)
453 list_del(&cl->alist);
454 qdisc_reset(cl->qdisc);
455 }
456 }
457 sch->q.qlen = 0;
458}
459
460static void drr_destroy_qdisc(struct Qdisc *sch)
461{
462 struct drr_sched *q = qdisc_priv(sch);
463 struct drr_class *cl;
464 struct hlist_node *n, *next;
465 unsigned int i;
466
467 tcf_destroy_chain(&q->filter_list);
468
469 for (i = 0; i < q->clhash.hashsize; i++) {
470 hlist_for_each_entry_safe(cl, n, next, &q->clhash.hash[i],
471 common.hnode)
472 drr_destroy_class(sch, cl);
473 }
474 qdisc_class_hash_destroy(&q->clhash);
475}
476
477static const struct Qdisc_class_ops drr_class_ops = {
478 .change = drr_change_class,
479 .delete = drr_delete_class,
480 .get = drr_get_class,
481 .put = drr_put_class,
482 .tcf_chain = drr_tcf_chain,
483 .bind_tcf = drr_bind_tcf,
484 .unbind_tcf = drr_unbind_tcf,
485 .graft = drr_graft_class,
486 .leaf = drr_class_leaf,
487 .qlen_notify = drr_qlen_notify,
488 .dump = drr_dump_class,
489 .dump_stats = drr_dump_class_stats,
490 .walk = drr_walk,
491};
492
493static struct Qdisc_ops drr_qdisc_ops __read_mostly = {
494 .cl_ops = &drr_class_ops,
495 .id = "drr",
496 .priv_size = sizeof(struct drr_sched),
497 .enqueue = drr_enqueue,
498 .dequeue = drr_dequeue,
499 .peek = qdisc_peek_dequeued,
500 .drop = drr_drop,
501 .init = drr_init_qdisc,
502 .reset = drr_reset_qdisc,
503 .destroy = drr_destroy_qdisc,
504 .owner = THIS_MODULE,
505};
506
507static int __init drr_init(void)
508{
509 return register_qdisc(&drr_qdisc_ops);
510}
511
512static void __exit drr_exit(void)
513{
514 unregister_qdisc(&drr_qdisc_ops);
515}
516
517module_init(drr_init);
518module_exit(drr_exit);
519MODULE_LICENSE("GPL");
diff --git a/net/sched/sch_dsmark.c b/net/sched/sch_dsmark.c
index ba43aab3a851..d303daa45d49 100644
--- a/net/sched/sch_dsmark.c
+++ b/net/sched/sch_dsmark.c
@@ -68,7 +68,8 @@ static int dsmark_graft(struct Qdisc *sch, unsigned long arg,
68 } 68 }
69 69
70 sch_tree_lock(sch); 70 sch_tree_lock(sch);
71 *old = xchg(&p->q, new); 71 *old = p->q;
72 p->q = new;
72 qdisc_tree_decrease_qlen(*old, (*old)->q.qlen); 73 qdisc_tree_decrease_qlen(*old, (*old)->q.qlen);
73 qdisc_reset(*old); 74 qdisc_reset(*old);
74 sch_tree_unlock(sch); 75 sch_tree_unlock(sch);
@@ -313,24 +314,13 @@ static struct sk_buff *dsmark_dequeue(struct Qdisc *sch)
313 return skb; 314 return skb;
314} 315}
315 316
316static int dsmark_requeue(struct sk_buff *skb, struct Qdisc *sch) 317static struct sk_buff *dsmark_peek(struct Qdisc *sch)
317{ 318{
318 struct dsmark_qdisc_data *p = qdisc_priv(sch); 319 struct dsmark_qdisc_data *p = qdisc_priv(sch);
319 int err;
320
321 pr_debug("dsmark_requeue(skb %p,sch %p,[qdisc %p])\n", skb, sch, p);
322
323 err = p->q->ops->requeue(skb, p->q);
324 if (err != NET_XMIT_SUCCESS) {
325 if (net_xmit_drop_count(err))
326 sch->qstats.drops++;
327 return err;
328 }
329 320
330 sch->q.qlen++; 321 pr_debug("dsmark_peek(sch %p,[qdisc %p])\n", sch, p);
331 sch->qstats.requeues++;
332 322
333 return NET_XMIT_SUCCESS; 323 return p->q->ops->peek(p->q);
334} 324}
335 325
336static unsigned int dsmark_drop(struct Qdisc *sch) 326static unsigned int dsmark_drop(struct Qdisc *sch)
@@ -496,7 +486,7 @@ static struct Qdisc_ops dsmark_qdisc_ops __read_mostly = {
496 .priv_size = sizeof(struct dsmark_qdisc_data), 486 .priv_size = sizeof(struct dsmark_qdisc_data),
497 .enqueue = dsmark_enqueue, 487 .enqueue = dsmark_enqueue,
498 .dequeue = dsmark_dequeue, 488 .dequeue = dsmark_dequeue,
499 .requeue = dsmark_requeue, 489 .peek = dsmark_peek,
500 .drop = dsmark_drop, 490 .drop = dsmark_drop,
501 .init = dsmark_init, 491 .init = dsmark_init,
502 .reset = dsmark_reset, 492 .reset = dsmark_reset,
diff --git a/net/sched/sch_fifo.c b/net/sched/sch_fifo.c
index 23d258bfe8ac..92cfc9d7e3b9 100644
--- a/net/sched/sch_fifo.c
+++ b/net/sched/sch_fifo.c
@@ -83,7 +83,7 @@ struct Qdisc_ops pfifo_qdisc_ops __read_mostly = {
83 .priv_size = sizeof(struct fifo_sched_data), 83 .priv_size = sizeof(struct fifo_sched_data),
84 .enqueue = pfifo_enqueue, 84 .enqueue = pfifo_enqueue,
85 .dequeue = qdisc_dequeue_head, 85 .dequeue = qdisc_dequeue_head,
86 .requeue = qdisc_requeue, 86 .peek = qdisc_peek_head,
87 .drop = qdisc_queue_drop, 87 .drop = qdisc_queue_drop,
88 .init = fifo_init, 88 .init = fifo_init,
89 .reset = qdisc_reset_queue, 89 .reset = qdisc_reset_queue,
@@ -98,7 +98,7 @@ struct Qdisc_ops bfifo_qdisc_ops __read_mostly = {
98 .priv_size = sizeof(struct fifo_sched_data), 98 .priv_size = sizeof(struct fifo_sched_data),
99 .enqueue = bfifo_enqueue, 99 .enqueue = bfifo_enqueue,
100 .dequeue = qdisc_dequeue_head, 100 .dequeue = qdisc_dequeue_head,
101 .requeue = qdisc_requeue, 101 .peek = qdisc_peek_head,
102 .drop = qdisc_queue_drop, 102 .drop = qdisc_queue_drop,
103 .init = fifo_init, 103 .init = fifo_init,
104 .reset = qdisc_reset_queue, 104 .reset = qdisc_reset_queue,
diff --git a/net/sched/sch_generic.c b/net/sched/sch_generic.c
index cdcd16fcfeda..5f5efe4e6072 100644
--- a/net/sched/sch_generic.c
+++ b/net/sched/sch_generic.c
@@ -224,7 +224,7 @@ static void dev_watchdog(unsigned long arg)
224 char drivername[64]; 224 char drivername[64];
225 WARN_ONCE(1, KERN_INFO "NETDEV WATCHDOG: %s (%s): transmit timed out\n", 225 WARN_ONCE(1, KERN_INFO "NETDEV WATCHDOG: %s (%s): transmit timed out\n",
226 dev->name, netdev_drivername(dev, drivername, 64)); 226 dev->name, netdev_drivername(dev, drivername, 64));
227 dev->tx_timeout(dev); 227 dev->netdev_ops->ndo_tx_timeout(dev);
228 } 228 }
229 if (!mod_timer(&dev->watchdog_timer, 229 if (!mod_timer(&dev->watchdog_timer,
230 round_jiffies(jiffies + 230 round_jiffies(jiffies +
@@ -239,7 +239,7 @@ static void dev_watchdog(unsigned long arg)
239 239
240void __netdev_watchdog_up(struct net_device *dev) 240void __netdev_watchdog_up(struct net_device *dev)
241{ 241{
242 if (dev->tx_timeout) { 242 if (dev->netdev_ops->ndo_tx_timeout) {
243 if (dev->watchdog_timeo <= 0) 243 if (dev->watchdog_timeo <= 0)
244 dev->watchdog_timeo = 5*HZ; 244 dev->watchdog_timeo = 5*HZ;
245 if (!mod_timer(&dev->watchdog_timer, 245 if (!mod_timer(&dev->watchdog_timer,
@@ -311,21 +311,12 @@ static struct sk_buff *noop_dequeue(struct Qdisc * qdisc)
311 return NULL; 311 return NULL;
312} 312}
313 313
314static int noop_requeue(struct sk_buff *skb, struct Qdisc* qdisc)
315{
316 if (net_ratelimit())
317 printk(KERN_DEBUG "%s deferred output. It is buggy.\n",
318 skb->dev->name);
319 kfree_skb(skb);
320 return NET_XMIT_CN;
321}
322
323struct Qdisc_ops noop_qdisc_ops __read_mostly = { 314struct Qdisc_ops noop_qdisc_ops __read_mostly = {
324 .id = "noop", 315 .id = "noop",
325 .priv_size = 0, 316 .priv_size = 0,
326 .enqueue = noop_enqueue, 317 .enqueue = noop_enqueue,
327 .dequeue = noop_dequeue, 318 .dequeue = noop_dequeue,
328 .requeue = noop_requeue, 319 .peek = noop_dequeue,
329 .owner = THIS_MODULE, 320 .owner = THIS_MODULE,
330}; 321};
331 322
@@ -340,7 +331,6 @@ struct Qdisc noop_qdisc = {
340 .flags = TCQ_F_BUILTIN, 331 .flags = TCQ_F_BUILTIN,
341 .ops = &noop_qdisc_ops, 332 .ops = &noop_qdisc_ops,
342 .list = LIST_HEAD_INIT(noop_qdisc.list), 333 .list = LIST_HEAD_INIT(noop_qdisc.list),
343 .requeue.lock = __SPIN_LOCK_UNLOCKED(noop_qdisc.q.lock),
344 .q.lock = __SPIN_LOCK_UNLOCKED(noop_qdisc.q.lock), 334 .q.lock = __SPIN_LOCK_UNLOCKED(noop_qdisc.q.lock),
345 .dev_queue = &noop_netdev_queue, 335 .dev_queue = &noop_netdev_queue,
346}; 336};
@@ -351,7 +341,7 @@ static struct Qdisc_ops noqueue_qdisc_ops __read_mostly = {
351 .priv_size = 0, 341 .priv_size = 0,
352 .enqueue = noop_enqueue, 342 .enqueue = noop_enqueue,
353 .dequeue = noop_dequeue, 343 .dequeue = noop_dequeue,
354 .requeue = noop_requeue, 344 .peek = noop_dequeue,
355 .owner = THIS_MODULE, 345 .owner = THIS_MODULE,
356}; 346};
357 347
@@ -367,7 +357,6 @@ static struct Qdisc noqueue_qdisc = {
367 .flags = TCQ_F_BUILTIN, 357 .flags = TCQ_F_BUILTIN,
368 .ops = &noqueue_qdisc_ops, 358 .ops = &noqueue_qdisc_ops,
369 .list = LIST_HEAD_INIT(noqueue_qdisc.list), 359 .list = LIST_HEAD_INIT(noqueue_qdisc.list),
370 .requeue.lock = __SPIN_LOCK_UNLOCKED(noqueue_qdisc.q.lock),
371 .q.lock = __SPIN_LOCK_UNLOCKED(noqueue_qdisc.q.lock), 360 .q.lock = __SPIN_LOCK_UNLOCKED(noqueue_qdisc.q.lock),
372 .dev_queue = &noqueue_netdev_queue, 361 .dev_queue = &noqueue_netdev_queue,
373}; 362};
@@ -416,10 +405,17 @@ static struct sk_buff *pfifo_fast_dequeue(struct Qdisc* qdisc)
416 return NULL; 405 return NULL;
417} 406}
418 407
419static int pfifo_fast_requeue(struct sk_buff *skb, struct Qdisc* qdisc) 408static struct sk_buff *pfifo_fast_peek(struct Qdisc* qdisc)
420{ 409{
421 qdisc->q.qlen++; 410 int prio;
422 return __qdisc_requeue(skb, qdisc, prio2list(skb, qdisc)); 411 struct sk_buff_head *list = qdisc_priv(qdisc);
412
413 for (prio = 0; prio < PFIFO_FAST_BANDS; prio++) {
414 if (!skb_queue_empty(list + prio))
415 return skb_peek(list + prio);
416 }
417
418 return NULL;
423} 419}
424 420
425static void pfifo_fast_reset(struct Qdisc* qdisc) 421static void pfifo_fast_reset(struct Qdisc* qdisc)
@@ -462,7 +458,7 @@ static struct Qdisc_ops pfifo_fast_ops __read_mostly = {
462 .priv_size = PFIFO_FAST_BANDS * sizeof(struct sk_buff_head), 458 .priv_size = PFIFO_FAST_BANDS * sizeof(struct sk_buff_head),
463 .enqueue = pfifo_fast_enqueue, 459 .enqueue = pfifo_fast_enqueue,
464 .dequeue = pfifo_fast_dequeue, 460 .dequeue = pfifo_fast_dequeue,
465 .requeue = pfifo_fast_requeue, 461 .peek = pfifo_fast_peek,
466 .init = pfifo_fast_init, 462 .init = pfifo_fast_init,
467 .reset = pfifo_fast_reset, 463 .reset = pfifo_fast_reset,
468 .dump = pfifo_fast_dump, 464 .dump = pfifo_fast_dump,
@@ -488,7 +484,6 @@ struct Qdisc *qdisc_alloc(struct netdev_queue *dev_queue,
488 sch->padded = (char *) sch - (char *) p; 484 sch->padded = (char *) sch - (char *) p;
489 485
490 INIT_LIST_HEAD(&sch->list); 486 INIT_LIST_HEAD(&sch->list);
491 skb_queue_head_init(&sch->requeue);
492 skb_queue_head_init(&sch->q); 487 skb_queue_head_init(&sch->q);
493 sch->ops = ops; 488 sch->ops = ops;
494 sch->enqueue = ops->enqueue; 489 sch->enqueue = ops->enqueue;
@@ -531,6 +526,9 @@ void qdisc_reset(struct Qdisc *qdisc)
531 526
532 if (ops->reset) 527 if (ops->reset)
533 ops->reset(qdisc); 528 ops->reset(qdisc);
529
530 kfree_skb(qdisc->gso_skb);
531 qdisc->gso_skb = NULL;
534} 532}
535EXPORT_SYMBOL(qdisc_reset); 533EXPORT_SYMBOL(qdisc_reset);
536 534
@@ -557,8 +555,6 @@ void qdisc_destroy(struct Qdisc *qdisc)
557 dev_put(qdisc_dev(qdisc)); 555 dev_put(qdisc_dev(qdisc));
558 556
559 kfree_skb(qdisc->gso_skb); 557 kfree_skb(qdisc->gso_skb);
560 __skb_queue_purge(&qdisc->requeue);
561
562 kfree((char *) qdisc - qdisc->padded); 558 kfree((char *) qdisc - qdisc->padded);
563} 559}
564EXPORT_SYMBOL(qdisc_destroy); 560EXPORT_SYMBOL(qdisc_destroy);
diff --git a/net/sched/sch_gred.c b/net/sched/sch_gred.c
index c1ad6b8de105..40408d595c08 100644
--- a/net/sched/sch_gred.c
+++ b/net/sched/sch_gred.c
@@ -240,26 +240,6 @@ congestion_drop:
240 return NET_XMIT_CN; 240 return NET_XMIT_CN;
241} 241}
242 242
243static int gred_requeue(struct sk_buff *skb, struct Qdisc* sch)
244{
245 struct gred_sched *t = qdisc_priv(sch);
246 struct gred_sched_data *q;
247 u16 dp = tc_index_to_dp(skb);
248
249 if (dp >= t->DPs || (q = t->tab[dp]) == NULL) {
250 if (net_ratelimit())
251 printk(KERN_WARNING "GRED: Unable to relocate VQ 0x%x "
252 "for requeue, screwing up backlog.\n",
253 tc_index_to_dp(skb));
254 } else {
255 if (red_is_idling(&q->parms))
256 red_end_of_idle_period(&q->parms);
257 q->backlog += qdisc_pkt_len(skb);
258 }
259
260 return qdisc_requeue(skb, sch);
261}
262
263static struct sk_buff *gred_dequeue(struct Qdisc* sch) 243static struct sk_buff *gred_dequeue(struct Qdisc* sch)
264{ 244{
265 struct sk_buff *skb; 245 struct sk_buff *skb;
@@ -602,7 +582,7 @@ static struct Qdisc_ops gred_qdisc_ops __read_mostly = {
602 .priv_size = sizeof(struct gred_sched), 582 .priv_size = sizeof(struct gred_sched),
603 .enqueue = gred_enqueue, 583 .enqueue = gred_enqueue,
604 .dequeue = gred_dequeue, 584 .dequeue = gred_dequeue,
605 .requeue = gred_requeue, 585 .peek = qdisc_peek_head,
606 .drop = gred_drop, 586 .drop = gred_drop,
607 .init = gred_init, 587 .init = gred_init,
608 .reset = gred_reset, 588 .reset = gred_reset,
diff --git a/net/sched/sch_hfsc.c b/net/sched/sch_hfsc.c
index c1e77da8cd09..45c31b1a4e1d 100644
--- a/net/sched/sch_hfsc.c
+++ b/net/sched/sch_hfsc.c
@@ -184,7 +184,6 @@ struct hfsc_sched
184 struct rb_root eligible; /* eligible tree */ 184 struct rb_root eligible; /* eligible tree */
185 struct list_head droplist; /* active leaf class list (for 185 struct list_head droplist; /* active leaf class list (for
186 dropping) */ 186 dropping) */
187 struct sk_buff_head requeue; /* requeued packet */
188 struct qdisc_watchdog watchdog; /* watchdog timer */ 187 struct qdisc_watchdog watchdog; /* watchdog timer */
189}; 188};
190 189
@@ -880,28 +879,20 @@ set_passive(struct hfsc_class *cl)
880 */ 879 */
881} 880}
882 881
883/*
884 * hack to get length of first packet in queue.
885 */
886static unsigned int 882static unsigned int
887qdisc_peek_len(struct Qdisc *sch) 883qdisc_peek_len(struct Qdisc *sch)
888{ 884{
889 struct sk_buff *skb; 885 struct sk_buff *skb;
890 unsigned int len; 886 unsigned int len;
891 887
892 skb = sch->dequeue(sch); 888 skb = sch->ops->peek(sch);
893 if (skb == NULL) { 889 if (skb == NULL) {
894 if (net_ratelimit()) 890 if (net_ratelimit())
895 printk("qdisc_peek_len: non work-conserving qdisc ?\n"); 891 printk("qdisc_peek_len: non work-conserving qdisc ?\n");
896 return 0; 892 return 0;
897 } 893 }
898 len = qdisc_pkt_len(skb); 894 len = qdisc_pkt_len(skb);
899 if (unlikely(sch->ops->requeue(skb, sch) != NET_XMIT_SUCCESS)) { 895
900 if (net_ratelimit())
901 printk("qdisc_peek_len: failed to requeue\n");
902 qdisc_tree_decrease_qlen(sch, 1);
903 return 0;
904 }
905 return len; 896 return len;
906} 897}
907 898
@@ -1027,6 +1018,14 @@ hfsc_change_class(struct Qdisc *sch, u32 classid, u32 parentid,
1027 } 1018 }
1028 cur_time = psched_get_time(); 1019 cur_time = psched_get_time();
1029 1020
1021 if (tca[TCA_RATE]) {
1022 err = gen_replace_estimator(&cl->bstats, &cl->rate_est,
1023 qdisc_root_sleeping_lock(sch),
1024 tca[TCA_RATE]);
1025 if (err)
1026 return err;
1027 }
1028
1030 sch_tree_lock(sch); 1029 sch_tree_lock(sch);
1031 if (rsc != NULL) 1030 if (rsc != NULL)
1032 hfsc_change_rsc(cl, rsc, cur_time); 1031 hfsc_change_rsc(cl, rsc, cur_time);
@@ -1043,10 +1042,6 @@ hfsc_change_class(struct Qdisc *sch, u32 classid, u32 parentid,
1043 } 1042 }
1044 sch_tree_unlock(sch); 1043 sch_tree_unlock(sch);
1045 1044
1046 if (tca[TCA_RATE])
1047 gen_replace_estimator(&cl->bstats, &cl->rate_est,
1048 qdisc_root_sleeping_lock(sch),
1049 tca[TCA_RATE]);
1050 return 0; 1045 return 0;
1051 } 1046 }
1052 1047
@@ -1072,6 +1067,16 @@ hfsc_change_class(struct Qdisc *sch, u32 classid, u32 parentid,
1072 if (cl == NULL) 1067 if (cl == NULL)
1073 return -ENOBUFS; 1068 return -ENOBUFS;
1074 1069
1070 if (tca[TCA_RATE]) {
1071 err = gen_new_estimator(&cl->bstats, &cl->rate_est,
1072 qdisc_root_sleeping_lock(sch),
1073 tca[TCA_RATE]);
1074 if (err) {
1075 kfree(cl);
1076 return err;
1077 }
1078 }
1079
1075 if (rsc != NULL) 1080 if (rsc != NULL)
1076 hfsc_change_rsc(cl, rsc, 0); 1081 hfsc_change_rsc(cl, rsc, 0);
1077 if (fsc != NULL) 1082 if (fsc != NULL)
@@ -1102,9 +1107,6 @@ hfsc_change_class(struct Qdisc *sch, u32 classid, u32 parentid,
1102 1107
1103 qdisc_class_hash_grow(sch, &q->clhash); 1108 qdisc_class_hash_grow(sch, &q->clhash);
1104 1109
1105 if (tca[TCA_RATE])
1106 gen_new_estimator(&cl->bstats, &cl->rate_est,
1107 qdisc_root_sleeping_lock(sch), tca[TCA_RATE]);
1108 *arg = (unsigned long)cl; 1110 *arg = (unsigned long)cl;
1109 return 0; 1111 return 0;
1110} 1112}
@@ -1211,7 +1213,8 @@ hfsc_graft_class(struct Qdisc *sch, unsigned long arg, struct Qdisc *new,
1211 1213
1212 sch_tree_lock(sch); 1214 sch_tree_lock(sch);
1213 hfsc_purge_queue(sch, cl); 1215 hfsc_purge_queue(sch, cl);
1214 *old = xchg(&cl->qdisc, new); 1216 *old = cl->qdisc;
1217 cl->qdisc = new;
1215 sch_tree_unlock(sch); 1218 sch_tree_unlock(sch);
1216 return 0; 1219 return 0;
1217} 1220}
@@ -1440,7 +1443,6 @@ hfsc_init_qdisc(struct Qdisc *sch, struct nlattr *opt)
1440 return err; 1443 return err;
1441 q->eligible = RB_ROOT; 1444 q->eligible = RB_ROOT;
1442 INIT_LIST_HEAD(&q->droplist); 1445 INIT_LIST_HEAD(&q->droplist);
1443 skb_queue_head_init(&q->requeue);
1444 1446
1445 q->root.cl_common.classid = sch->handle; 1447 q->root.cl_common.classid = sch->handle;
1446 q->root.refcnt = 1; 1448 q->root.refcnt = 1;
@@ -1525,7 +1527,6 @@ hfsc_reset_qdisc(struct Qdisc *sch)
1525 hlist_for_each_entry(cl, n, &q->clhash.hash[i], cl_common.hnode) 1527 hlist_for_each_entry(cl, n, &q->clhash.hash[i], cl_common.hnode)
1526 hfsc_reset_class(cl); 1528 hfsc_reset_class(cl);
1527 } 1529 }
1528 __skb_queue_purge(&q->requeue);
1529 q->eligible = RB_ROOT; 1530 q->eligible = RB_ROOT;
1530 INIT_LIST_HEAD(&q->droplist); 1531 INIT_LIST_HEAD(&q->droplist);
1531 qdisc_watchdog_cancel(&q->watchdog); 1532 qdisc_watchdog_cancel(&q->watchdog);
@@ -1550,7 +1551,6 @@ hfsc_destroy_qdisc(struct Qdisc *sch)
1550 hfsc_destroy_class(sch, cl); 1551 hfsc_destroy_class(sch, cl);
1551 } 1552 }
1552 qdisc_class_hash_destroy(&q->clhash); 1553 qdisc_class_hash_destroy(&q->clhash);
1553 __skb_queue_purge(&q->requeue);
1554 qdisc_watchdog_cancel(&q->watchdog); 1554 qdisc_watchdog_cancel(&q->watchdog);
1555} 1555}
1556 1556
@@ -1574,7 +1574,7 @@ static int
1574hfsc_enqueue(struct sk_buff *skb, struct Qdisc *sch) 1574hfsc_enqueue(struct sk_buff *skb, struct Qdisc *sch)
1575{ 1575{
1576 struct hfsc_class *cl; 1576 struct hfsc_class *cl;
1577 int err; 1577 int uninitialized_var(err);
1578 1578
1579 cl = hfsc_classify(skb, sch, &err); 1579 cl = hfsc_classify(skb, sch, &err);
1580 if (cl == NULL) { 1580 if (cl == NULL) {
@@ -1617,8 +1617,6 @@ hfsc_dequeue(struct Qdisc *sch)
1617 1617
1618 if (sch->q.qlen == 0) 1618 if (sch->q.qlen == 0)
1619 return NULL; 1619 return NULL;
1620 if ((skb = __skb_dequeue(&q->requeue)))
1621 goto out;
1622 1620
1623 cur_time = psched_get_time(); 1621 cur_time = psched_get_time();
1624 1622
@@ -1642,7 +1640,7 @@ hfsc_dequeue(struct Qdisc *sch)
1642 } 1640 }
1643 } 1641 }
1644 1642
1645 skb = cl->qdisc->dequeue(cl->qdisc); 1643 skb = qdisc_dequeue_peeked(cl->qdisc);
1646 if (skb == NULL) { 1644 if (skb == NULL) {
1647 if (net_ratelimit()) 1645 if (net_ratelimit())
1648 printk("HFSC: Non-work-conserving qdisc ?\n"); 1646 printk("HFSC: Non-work-conserving qdisc ?\n");
@@ -1667,24 +1665,12 @@ hfsc_dequeue(struct Qdisc *sch)
1667 set_passive(cl); 1665 set_passive(cl);
1668 } 1666 }
1669 1667
1670 out:
1671 sch->flags &= ~TCQ_F_THROTTLED; 1668 sch->flags &= ~TCQ_F_THROTTLED;
1672 sch->q.qlen--; 1669 sch->q.qlen--;
1673 1670
1674 return skb; 1671 return skb;
1675} 1672}
1676 1673
1677static int
1678hfsc_requeue(struct sk_buff *skb, struct Qdisc *sch)
1679{
1680 struct hfsc_sched *q = qdisc_priv(sch);
1681
1682 __skb_queue_head(&q->requeue, skb);
1683 sch->q.qlen++;
1684 sch->qstats.requeues++;
1685 return NET_XMIT_SUCCESS;
1686}
1687
1688static unsigned int 1674static unsigned int
1689hfsc_drop(struct Qdisc *sch) 1675hfsc_drop(struct Qdisc *sch)
1690{ 1676{
@@ -1735,7 +1721,7 @@ static struct Qdisc_ops hfsc_qdisc_ops __read_mostly = {
1735 .dump = hfsc_dump_qdisc, 1721 .dump = hfsc_dump_qdisc,
1736 .enqueue = hfsc_enqueue, 1722 .enqueue = hfsc_enqueue,
1737 .dequeue = hfsc_dequeue, 1723 .dequeue = hfsc_dequeue,
1738 .requeue = hfsc_requeue, 1724 .peek = qdisc_peek_dequeued,
1739 .drop = hfsc_drop, 1725 .drop = hfsc_drop,
1740 .cl_ops = &hfsc_class_ops, 1726 .cl_ops = &hfsc_class_ops,
1741 .priv_size = sizeof(struct hfsc_sched), 1727 .priv_size = sizeof(struct hfsc_sched),
diff --git a/net/sched/sch_htb.c b/net/sched/sch_htb.c
index d14f02056ae6..5070643ce534 100644
--- a/net/sched/sch_htb.c
+++ b/net/sched/sch_htb.c
@@ -84,12 +84,12 @@ struct htb_class {
84 unsigned int children; 84 unsigned int children;
85 struct htb_class *parent; /* parent class */ 85 struct htb_class *parent; /* parent class */
86 86
87 int prio; /* these two are used only by leaves... */
88 int quantum; /* but stored for parent-to-leaf return */
89
87 union { 90 union {
88 struct htb_class_leaf { 91 struct htb_class_leaf {
89 struct Qdisc *q; 92 struct Qdisc *q;
90 int prio;
91 int aprio;
92 int quantum;
93 int deficit[TC_HTB_MAXDEPTH]; 93 int deficit[TC_HTB_MAXDEPTH];
94 struct list_head drop_list; 94 struct list_head drop_list;
95 } leaf; 95 } leaf;
@@ -123,19 +123,8 @@ struct htb_class {
123 psched_tdiff_t mbuffer; /* max wait time */ 123 psched_tdiff_t mbuffer; /* max wait time */
124 long tokens, ctokens; /* current number of tokens */ 124 long tokens, ctokens; /* current number of tokens */
125 psched_time_t t_c; /* checkpoint time */ 125 psched_time_t t_c; /* checkpoint time */
126
127 int prio; /* For parent to leaf return possible here */
128 int quantum; /* we do backup. Finally full replacement */
129 /* of un.leaf originals should be done. */
130}; 126};
131 127
132static inline long L2T(struct htb_class *cl, struct qdisc_rate_table *rate,
133 int size)
134{
135 long result = qdisc_l2t(rate, size);
136 return result;
137}
138
139struct htb_sched { 128struct htb_sched {
140 struct Qdisc_class_hash clhash; 129 struct Qdisc_class_hash clhash;
141 struct list_head drops[TC_HTB_NUMPRIO];/* active leaves (for drops) */ 130 struct list_head drops[TC_HTB_NUMPRIO];/* active leaves (for drops) */
@@ -152,9 +141,6 @@ struct htb_sched {
152 /* time of nearest event per level (row) */ 141 /* time of nearest event per level (row) */
153 psched_time_t near_ev_cache[TC_HTB_MAXDEPTH]; 142 psched_time_t near_ev_cache[TC_HTB_MAXDEPTH];
154 143
155 /* whether we hit non-work conserving class during this dequeue; we use */
156 int nwc_hit; /* this to disable mindelay complaint in dequeue */
157
158 int defcls; /* class where unclassified flows go to */ 144 int defcls; /* class where unclassified flows go to */
159 145
160 /* filters for qdisc itself */ 146 /* filters for qdisc itself */
@@ -527,10 +513,10 @@ static inline void htb_activate(struct htb_sched *q, struct htb_class *cl)
527 WARN_ON(cl->level || !cl->un.leaf.q || !cl->un.leaf.q->q.qlen); 513 WARN_ON(cl->level || !cl->un.leaf.q || !cl->un.leaf.q->q.qlen);
528 514
529 if (!cl->prio_activity) { 515 if (!cl->prio_activity) {
530 cl->prio_activity = 1 << (cl->un.leaf.aprio = cl->un.leaf.prio); 516 cl->prio_activity = 1 << cl->prio;
531 htb_activate_prios(q, cl); 517 htb_activate_prios(q, cl);
532 list_add_tail(&cl->un.leaf.drop_list, 518 list_add_tail(&cl->un.leaf.drop_list,
533 q->drops + cl->un.leaf.aprio); 519 q->drops + cl->prio);
534 } 520 }
535} 521}
536 522
@@ -551,7 +537,7 @@ static inline void htb_deactivate(struct htb_sched *q, struct htb_class *cl)
551 537
552static int htb_enqueue(struct sk_buff *skb, struct Qdisc *sch) 538static int htb_enqueue(struct sk_buff *skb, struct Qdisc *sch)
553{ 539{
554 int ret; 540 int uninitialized_var(ret);
555 struct htb_sched *q = qdisc_priv(sch); 541 struct htb_sched *q = qdisc_priv(sch);
556 struct htb_class *cl = htb_classify(skb, sch, &ret); 542 struct htb_class *cl = htb_classify(skb, sch, &ret);
557 543
@@ -591,45 +577,30 @@ static int htb_enqueue(struct sk_buff *skb, struct Qdisc *sch)
591 return NET_XMIT_SUCCESS; 577 return NET_XMIT_SUCCESS;
592} 578}
593 579
594/* TODO: requeuing packet charges it to policers again !! */ 580static inline void htb_accnt_tokens(struct htb_class *cl, int bytes, long diff)
595static int htb_requeue(struct sk_buff *skb, struct Qdisc *sch)
596{ 581{
597 int ret; 582 long toks = diff + cl->tokens;
598 struct htb_sched *q = qdisc_priv(sch);
599 struct htb_class *cl = htb_classify(skb, sch, &ret);
600 struct sk_buff *tskb;
601 583
602 if (cl == HTB_DIRECT) { 584 if (toks > cl->buffer)
603 /* enqueue to helper queue */ 585 toks = cl->buffer;
604 if (q->direct_queue.qlen < q->direct_qlen) { 586 toks -= (long) qdisc_l2t(cl->rate, bytes);
605 __skb_queue_head(&q->direct_queue, skb); 587 if (toks <= -cl->mbuffer)
606 } else { 588 toks = 1 - cl->mbuffer;
607 __skb_queue_head(&q->direct_queue, skb);
608 tskb = __skb_dequeue_tail(&q->direct_queue);
609 kfree_skb(tskb);
610 sch->qstats.drops++;
611 return NET_XMIT_CN;
612 }
613#ifdef CONFIG_NET_CLS_ACT
614 } else if (!cl) {
615 if (ret & __NET_XMIT_BYPASS)
616 sch->qstats.drops++;
617 kfree_skb(skb);
618 return ret;
619#endif
620 } else if ((ret = cl->un.leaf.q->ops->requeue(skb, cl->un.leaf.q)) !=
621 NET_XMIT_SUCCESS) {
622 if (net_xmit_drop_count(ret)) {
623 sch->qstats.drops++;
624 cl->qstats.drops++;
625 }
626 return ret;
627 } else
628 htb_activate(q, cl);
629 589
630 sch->q.qlen++; 590 cl->tokens = toks;
631 sch->qstats.requeues++; 591}
632 return NET_XMIT_SUCCESS; 592
593static inline void htb_accnt_ctokens(struct htb_class *cl, int bytes, long diff)
594{
595 long toks = diff + cl->ctokens;
596
597 if (toks > cl->cbuffer)
598 toks = cl->cbuffer;
599 toks -= (long) qdisc_l2t(cl->ceil, bytes);
600 if (toks <= -cl->mbuffer)
601 toks = 1 - cl->mbuffer;
602
603 cl->ctokens = toks;
633} 604}
634 605
635/** 606/**
@@ -647,26 +618,20 @@ static void htb_charge_class(struct htb_sched *q, struct htb_class *cl,
647 int level, struct sk_buff *skb) 618 int level, struct sk_buff *skb)
648{ 619{
649 int bytes = qdisc_pkt_len(skb); 620 int bytes = qdisc_pkt_len(skb);
650 long toks, diff;
651 enum htb_cmode old_mode; 621 enum htb_cmode old_mode;
652 622 long diff;
653#define HTB_ACCNT(T,B,R) toks = diff + cl->T; \
654 if (toks > cl->B) toks = cl->B; \
655 toks -= L2T(cl, cl->R, bytes); \
656 if (toks <= -cl->mbuffer) toks = 1-cl->mbuffer; \
657 cl->T = toks
658 623
659 while (cl) { 624 while (cl) {
660 diff = psched_tdiff_bounded(q->now, cl->t_c, cl->mbuffer); 625 diff = psched_tdiff_bounded(q->now, cl->t_c, cl->mbuffer);
661 if (cl->level >= level) { 626 if (cl->level >= level) {
662 if (cl->level == level) 627 if (cl->level == level)
663 cl->xstats.lends++; 628 cl->xstats.lends++;
664 HTB_ACCNT(tokens, buffer, rate); 629 htb_accnt_tokens(cl, bytes, diff);
665 } else { 630 } else {
666 cl->xstats.borrows++; 631 cl->xstats.borrows++;
667 cl->tokens += diff; /* we moved t_c; update tokens */ 632 cl->tokens += diff; /* we moved t_c; update tokens */
668 } 633 }
669 HTB_ACCNT(ctokens, cbuffer, ceil); 634 htb_accnt_ctokens(cl, bytes, diff);
670 cl->t_c = q->now; 635 cl->t_c = q->now;
671 636
672 old_mode = cl->cmode; 637 old_mode = cl->cmode;
@@ -733,14 +698,14 @@ static struct rb_node *htb_id_find_next_upper(int prio, struct rb_node *n,
733 while (n) { 698 while (n) {
734 struct htb_class *cl = 699 struct htb_class *cl =
735 rb_entry(n, struct htb_class, node[prio]); 700 rb_entry(n, struct htb_class, node[prio]);
736 if (id == cl->common.classid)
737 return n;
738 701
739 if (id > cl->common.classid) { 702 if (id > cl->common.classid) {
740 n = n->rb_right; 703 n = n->rb_right;
741 } else { 704 } else if (id < cl->common.classid) {
742 r = n; 705 r = n;
743 n = n->rb_left; 706 n = n->rb_left;
707 } else {
708 return n;
744 } 709 }
745 } 710 }
746 return r; 711 return r;
@@ -761,7 +726,7 @@ static struct htb_class *htb_lookup_leaf(struct rb_root *tree, int prio,
761 u32 *pid; 726 u32 *pid;
762 } stk[TC_HTB_MAXDEPTH], *sp = stk; 727 } stk[TC_HTB_MAXDEPTH], *sp = stk;
763 728
764 WARN_ON(!tree->rb_node); 729 BUG_ON(!tree->rb_node);
765 sp->root = tree->rb_node; 730 sp->root = tree->rb_node;
766 sp->pptr = pptr; 731 sp->pptr = pptr;
767 sp->pid = pid; 732 sp->pid = pid;
@@ -781,9 +746,10 @@ static struct htb_class *htb_lookup_leaf(struct rb_root *tree, int prio,
781 *sp->pptr = (*sp->pptr)->rb_left; 746 *sp->pptr = (*sp->pptr)->rb_left;
782 if (sp > stk) { 747 if (sp > stk) {
783 sp--; 748 sp--;
784 WARN_ON(!*sp->pptr); 749 if (!*sp->pptr) {
785 if (!*sp->pptr) 750 WARN_ON(1);
786 return NULL; 751 return NULL;
752 }
787 htb_next_rb_node(sp->pptr); 753 htb_next_rb_node(sp->pptr);
788 } 754 }
789 } else { 755 } else {
@@ -814,8 +780,7 @@ static struct sk_buff *htb_dequeue_tree(struct htb_sched *q, int prio,
814 780
815 do { 781 do {
816next: 782next:
817 WARN_ON(!cl); 783 if (unlikely(!cl))
818 if (!cl)
819 return NULL; 784 return NULL;
820 785
821 /* class can be empty - it is unlikely but can be true if leaf 786 /* class can be empty - it is unlikely but can be true if leaf
@@ -849,7 +814,7 @@ next:
849 cl->common.classid); 814 cl->common.classid);
850 cl->warned = 1; 815 cl->warned = 1;
851 } 816 }
852 q->nwc_hit++; 817
853 htb_next_rb_node((level ? cl->parent->un.inner.ptr : q-> 818 htb_next_rb_node((level ? cl->parent->un.inner.ptr : q->
854 ptr[0]) + prio); 819 ptr[0]) + prio);
855 cl = htb_lookup_leaf(q->row[level] + prio, prio, 820 cl = htb_lookup_leaf(q->row[level] + prio, prio,
@@ -861,7 +826,7 @@ next:
861 if (likely(skb != NULL)) { 826 if (likely(skb != NULL)) {
862 cl->un.leaf.deficit[level] -= qdisc_pkt_len(skb); 827 cl->un.leaf.deficit[level] -= qdisc_pkt_len(skb);
863 if (cl->un.leaf.deficit[level] < 0) { 828 if (cl->un.leaf.deficit[level] < 0) {
864 cl->un.leaf.deficit[level] += cl->un.leaf.quantum; 829 cl->un.leaf.deficit[level] += cl->quantum;
865 htb_next_rb_node((level ? cl->parent->un.inner.ptr : q-> 830 htb_next_rb_node((level ? cl->parent->un.inner.ptr : q->
866 ptr[0]) + prio); 831 ptr[0]) + prio);
867 } 832 }
@@ -894,7 +859,7 @@ static struct sk_buff *htb_dequeue(struct Qdisc *sch)
894 q->now = psched_get_time(); 859 q->now = psched_get_time();
895 860
896 next_event = q->now + 5 * PSCHED_TICKS_PER_SEC; 861 next_event = q->now + 5 * PSCHED_TICKS_PER_SEC;
897 q->nwc_hit = 0; 862
898 for (level = 0; level < TC_HTB_MAXDEPTH; level++) { 863 for (level = 0; level < TC_HTB_MAXDEPTH; level++) {
899 /* common case optimization - skip event handler quickly */ 864 /* common case optimization - skip event handler quickly */
900 int m; 865 int m;
@@ -1095,8 +1060,8 @@ static int htb_dump_class(struct Qdisc *sch, unsigned long arg,
1095 opt.buffer = cl->buffer; 1060 opt.buffer = cl->buffer;
1096 opt.ceil = cl->ceil->rate; 1061 opt.ceil = cl->ceil->rate;
1097 opt.cbuffer = cl->cbuffer; 1062 opt.cbuffer = cl->cbuffer;
1098 opt.quantum = cl->un.leaf.quantum; 1063 opt.quantum = cl->quantum;
1099 opt.prio = cl->un.leaf.prio; 1064 opt.prio = cl->prio;
1100 opt.level = cl->level; 1065 opt.level = cl->level;
1101 NLA_PUT(skb, TCA_HTB_PARMS, sizeof(opt), &opt); 1066 NLA_PUT(skb, TCA_HTB_PARMS, sizeof(opt), &opt);
1102 1067
@@ -1141,7 +1106,9 @@ static int htb_graft(struct Qdisc *sch, unsigned long arg, struct Qdisc *new,
1141 == NULL) 1106 == NULL)
1142 return -ENOBUFS; 1107 return -ENOBUFS;
1143 sch_tree_lock(sch); 1108 sch_tree_lock(sch);
1144 if ((*old = xchg(&cl->un.leaf.q, new)) != NULL) { 1109 *old = cl->un.leaf.q;
1110 cl->un.leaf.q = new;
1111 if (*old != NULL) {
1145 qdisc_tree_decrease_qlen(*old, (*old)->q.qlen); 1112 qdisc_tree_decrease_qlen(*old, (*old)->q.qlen);
1146 qdisc_reset(*old); 1113 qdisc_reset(*old);
1147 } 1114 }
@@ -1198,8 +1165,6 @@ static void htb_parent_to_leaf(struct htb_sched *q, struct htb_class *cl,
1198 memset(&parent->un.inner, 0, sizeof(parent->un.inner)); 1165 memset(&parent->un.inner, 0, sizeof(parent->un.inner));
1199 INIT_LIST_HEAD(&parent->un.leaf.drop_list); 1166 INIT_LIST_HEAD(&parent->un.leaf.drop_list);
1200 parent->un.leaf.q = new_q ? new_q : &noop_qdisc; 1167 parent->un.leaf.q = new_q ? new_q : &noop_qdisc;
1201 parent->un.leaf.quantum = parent->quantum;
1202 parent->un.leaf.prio = parent->prio;
1203 parent->tokens = parent->buffer; 1168 parent->tokens = parent->buffer;
1204 parent->ctokens = parent->cbuffer; 1169 parent->ctokens = parent->cbuffer;
1205 parent->t_c = psched_get_time(); 1170 parent->t_c = psched_get_time();
@@ -1371,9 +1336,14 @@ static int htb_change_class(struct Qdisc *sch, u32 classid,
1371 if ((cl = kzalloc(sizeof(*cl), GFP_KERNEL)) == NULL) 1336 if ((cl = kzalloc(sizeof(*cl), GFP_KERNEL)) == NULL)
1372 goto failure; 1337 goto failure;
1373 1338
1374 gen_new_estimator(&cl->bstats, &cl->rate_est, 1339 err = gen_new_estimator(&cl->bstats, &cl->rate_est,
1375 qdisc_root_sleeping_lock(sch), 1340 qdisc_root_sleeping_lock(sch),
1376 tca[TCA_RATE] ? : &est.nla); 1341 tca[TCA_RATE] ? : &est.nla);
1342 if (err) {
1343 kfree(cl);
1344 goto failure;
1345 }
1346
1377 cl->refcnt = 1; 1347 cl->refcnt = 1;
1378 cl->children = 0; 1348 cl->children = 0;
1379 INIT_LIST_HEAD(&cl->un.leaf.drop_list); 1349 INIT_LIST_HEAD(&cl->un.leaf.drop_list);
@@ -1425,37 +1395,36 @@ static int htb_change_class(struct Qdisc *sch, u32 classid,
1425 if (parent) 1395 if (parent)
1426 parent->children++; 1396 parent->children++;
1427 } else { 1397 } else {
1428 if (tca[TCA_RATE]) 1398 if (tca[TCA_RATE]) {
1429 gen_replace_estimator(&cl->bstats, &cl->rate_est, 1399 err = gen_replace_estimator(&cl->bstats, &cl->rate_est,
1430 qdisc_root_sleeping_lock(sch), 1400 qdisc_root_sleeping_lock(sch),
1431 tca[TCA_RATE]); 1401 tca[TCA_RATE]);
1402 if (err)
1403 return err;
1404 }
1432 sch_tree_lock(sch); 1405 sch_tree_lock(sch);
1433 } 1406 }
1434 1407
1435 /* it used to be a nasty bug here, we have to check that node 1408 /* it used to be a nasty bug here, we have to check that node
1436 is really leaf before changing cl->un.leaf ! */ 1409 is really leaf before changing cl->un.leaf ! */
1437 if (!cl->level) { 1410 if (!cl->level) {
1438 cl->un.leaf.quantum = rtab->rate.rate / q->rate2quantum; 1411 cl->quantum = rtab->rate.rate / q->rate2quantum;
1439 if (!hopt->quantum && cl->un.leaf.quantum < 1000) { 1412 if (!hopt->quantum && cl->quantum < 1000) {
1440 printk(KERN_WARNING 1413 printk(KERN_WARNING
1441 "HTB: quantum of class %X is small. Consider r2q change.\n", 1414 "HTB: quantum of class %X is small. Consider r2q change.\n",
1442 cl->common.classid); 1415 cl->common.classid);
1443 cl->un.leaf.quantum = 1000; 1416 cl->quantum = 1000;
1444 } 1417 }
1445 if (!hopt->quantum && cl->un.leaf.quantum > 200000) { 1418 if (!hopt->quantum && cl->quantum > 200000) {
1446 printk(KERN_WARNING 1419 printk(KERN_WARNING
1447 "HTB: quantum of class %X is big. Consider r2q change.\n", 1420 "HTB: quantum of class %X is big. Consider r2q change.\n",
1448 cl->common.classid); 1421 cl->common.classid);
1449 cl->un.leaf.quantum = 200000; 1422 cl->quantum = 200000;
1450 } 1423 }
1451 if (hopt->quantum) 1424 if (hopt->quantum)
1452 cl->un.leaf.quantum = hopt->quantum; 1425 cl->quantum = hopt->quantum;
1453 if ((cl->un.leaf.prio = hopt->prio) >= TC_HTB_NUMPRIO) 1426 if ((cl->prio = hopt->prio) >= TC_HTB_NUMPRIO)
1454 cl->un.leaf.prio = TC_HTB_NUMPRIO - 1; 1427 cl->prio = TC_HTB_NUMPRIO - 1;
1455
1456 /* backup for htb_parent_to_leaf */
1457 cl->quantum = cl->un.leaf.quantum;
1458 cl->prio = cl->un.leaf.prio;
1459 } 1428 }
1460 1429
1461 cl->buffer = hopt->buffer; 1430 cl->buffer = hopt->buffer;
@@ -1565,7 +1534,7 @@ static struct Qdisc_ops htb_qdisc_ops __read_mostly = {
1565 .priv_size = sizeof(struct htb_sched), 1534 .priv_size = sizeof(struct htb_sched),
1566 .enqueue = htb_enqueue, 1535 .enqueue = htb_enqueue,
1567 .dequeue = htb_dequeue, 1536 .dequeue = htb_dequeue,
1568 .requeue = htb_requeue, 1537 .peek = qdisc_peek_dequeued,
1569 .drop = htb_drop, 1538 .drop = htb_drop,
1570 .init = htb_init, 1539 .init = htb_init,
1571 .reset = htb_reset, 1540 .reset = htb_reset,
diff --git a/net/sched/sch_multiq.c b/net/sched/sch_multiq.c
index 915f3149dde2..7e151861794b 100644
--- a/net/sched/sch_multiq.c
+++ b/net/sched/sch_multiq.c
@@ -92,40 +92,6 @@ multiq_enqueue(struct sk_buff *skb, struct Qdisc *sch)
92 return ret; 92 return ret;
93} 93}
94 94
95
96static int
97multiq_requeue(struct sk_buff *skb, struct Qdisc *sch)
98{
99 struct Qdisc *qdisc;
100 struct multiq_sched_data *q = qdisc_priv(sch);
101 int ret;
102
103 qdisc = multiq_classify(skb, sch, &ret);
104#ifdef CONFIG_NET_CLS_ACT
105 if (qdisc == NULL) {
106 if (ret & __NET_XMIT_BYPASS)
107 sch->qstats.drops++;
108 kfree_skb(skb);
109 return ret;
110 }
111#endif
112
113 ret = qdisc->ops->requeue(skb, qdisc);
114 if (ret == NET_XMIT_SUCCESS) {
115 sch->q.qlen++;
116 sch->qstats.requeues++;
117 if (q->curband)
118 q->curband--;
119 else
120 q->curband = q->bands - 1;
121 return NET_XMIT_SUCCESS;
122 }
123 if (net_xmit_drop_count(ret))
124 sch->qstats.drops++;
125 return ret;
126}
127
128
129static struct sk_buff *multiq_dequeue(struct Qdisc *sch) 95static struct sk_buff *multiq_dequeue(struct Qdisc *sch)
130{ 96{
131 struct multiq_sched_data *q = qdisc_priv(sch); 97 struct multiq_sched_data *q = qdisc_priv(sch);
@@ -140,7 +106,7 @@ static struct sk_buff *multiq_dequeue(struct Qdisc *sch)
140 q->curband = 0; 106 q->curband = 0;
141 107
142 /* Check that target subqueue is available before 108 /* Check that target subqueue is available before
143 * pulling an skb to avoid excessive requeues 109 * pulling an skb to avoid head-of-line blocking.
144 */ 110 */
145 if (!__netif_subqueue_stopped(qdisc_dev(sch), q->curband)) { 111 if (!__netif_subqueue_stopped(qdisc_dev(sch), q->curband)) {
146 qdisc = q->queues[q->curband]; 112 qdisc = q->queues[q->curband];
@@ -155,6 +121,34 @@ static struct sk_buff *multiq_dequeue(struct Qdisc *sch)
155 121
156} 122}
157 123
124static struct sk_buff *multiq_peek(struct Qdisc *sch)
125{
126 struct multiq_sched_data *q = qdisc_priv(sch);
127 unsigned int curband = q->curband;
128 struct Qdisc *qdisc;
129 struct sk_buff *skb;
130 int band;
131
132 for (band = 0; band < q->bands; band++) {
133 /* cycle through bands to ensure fairness */
134 curband++;
135 if (curband >= q->bands)
136 curband = 0;
137
138 /* Check that target subqueue is available before
139 * pulling an skb to avoid head-of-line blocking.
140 */
141 if (!__netif_subqueue_stopped(qdisc_dev(sch), curband)) {
142 qdisc = q->queues[curband];
143 skb = qdisc->ops->peek(qdisc);
144 if (skb)
145 return skb;
146 }
147 }
148 return NULL;
149
150}
151
158static unsigned int multiq_drop(struct Qdisc *sch) 152static unsigned int multiq_drop(struct Qdisc *sch)
159{ 153{
160 struct multiq_sched_data *q = qdisc_priv(sch); 154 struct multiq_sched_data *q = qdisc_priv(sch);
@@ -220,7 +214,8 @@ static int multiq_tune(struct Qdisc *sch, struct nlattr *opt)
220 q->bands = qopt->bands; 214 q->bands = qopt->bands;
221 for (i = q->bands; i < q->max_bands; i++) { 215 for (i = q->bands; i < q->max_bands; i++) {
222 if (q->queues[i] != &noop_qdisc) { 216 if (q->queues[i] != &noop_qdisc) {
223 struct Qdisc *child = xchg(&q->queues[i], &noop_qdisc); 217 struct Qdisc *child = q->queues[i];
218 q->queues[i] = &noop_qdisc;
224 qdisc_tree_decrease_qlen(child, child->q.qlen); 219 qdisc_tree_decrease_qlen(child, child->q.qlen);
225 qdisc_destroy(child); 220 qdisc_destroy(child);
226 } 221 }
@@ -230,7 +225,7 @@ static int multiq_tune(struct Qdisc *sch, struct nlattr *opt)
230 225
231 for (i = 0; i < q->bands; i++) { 226 for (i = 0; i < q->bands; i++) {
232 if (q->queues[i] == &noop_qdisc) { 227 if (q->queues[i] == &noop_qdisc) {
233 struct Qdisc *child; 228 struct Qdisc *child, *old;
234 child = qdisc_create_dflt(qdisc_dev(sch), 229 child = qdisc_create_dflt(qdisc_dev(sch),
235 sch->dev_queue, 230 sch->dev_queue,
236 &pfifo_qdisc_ops, 231 &pfifo_qdisc_ops,
@@ -238,12 +233,13 @@ static int multiq_tune(struct Qdisc *sch, struct nlattr *opt)
238 i + 1)); 233 i + 1));
239 if (child) { 234 if (child) {
240 sch_tree_lock(sch); 235 sch_tree_lock(sch);
241 child = xchg(&q->queues[i], child); 236 old = q->queues[i];
237 q->queues[i] = child;
242 238
243 if (child != &noop_qdisc) { 239 if (old != &noop_qdisc) {
244 qdisc_tree_decrease_qlen(child, 240 qdisc_tree_decrease_qlen(old,
245 child->q.qlen); 241 old->q.qlen);
246 qdisc_destroy(child); 242 qdisc_destroy(old);
247 } 243 }
248 sch_tree_unlock(sch); 244 sch_tree_unlock(sch);
249 } 245 }
@@ -451,7 +447,7 @@ static struct Qdisc_ops multiq_qdisc_ops __read_mostly = {
451 .priv_size = sizeof(struct multiq_sched_data), 447 .priv_size = sizeof(struct multiq_sched_data),
452 .enqueue = multiq_enqueue, 448 .enqueue = multiq_enqueue,
453 .dequeue = multiq_dequeue, 449 .dequeue = multiq_dequeue,
454 .requeue = multiq_requeue, 450 .peek = multiq_peek,
455 .drop = multiq_drop, 451 .drop = multiq_drop,
456 .init = multiq_init, 452 .init = multiq_init,
457 .reset = multiq_reset, 453 .reset = multiq_reset,
diff --git a/net/sched/sch_netem.c b/net/sched/sch_netem.c
index 98402f0efa47..d876b8734848 100644
--- a/net/sched/sch_netem.c
+++ b/net/sched/sch_netem.c
@@ -230,7 +230,11 @@ static int netem_enqueue(struct sk_buff *skb, struct Qdisc *sch)
230 */ 230 */
231 cb->time_to_send = psched_get_time(); 231 cb->time_to_send = psched_get_time();
232 q->counter = 0; 232 q->counter = 0;
233 ret = q->qdisc->ops->requeue(skb, q->qdisc); 233
234 __skb_queue_head(&q->qdisc->q, skb);
235 q->qdisc->qstats.backlog += qdisc_pkt_len(skb);
236 q->qdisc->qstats.requeues++;
237 ret = NET_XMIT_SUCCESS;
234 } 238 }
235 239
236 if (likely(ret == NET_XMIT_SUCCESS)) { 240 if (likely(ret == NET_XMIT_SUCCESS)) {
@@ -245,20 +249,6 @@ static int netem_enqueue(struct sk_buff *skb, struct Qdisc *sch)
245 return ret; 249 return ret;
246} 250}
247 251
248/* Requeue packets but don't change time stamp */
249static int netem_requeue(struct sk_buff *skb, struct Qdisc *sch)
250{
251 struct netem_sched_data *q = qdisc_priv(sch);
252 int ret;
253
254 if ((ret = q->qdisc->ops->requeue(skb, q->qdisc)) == 0) {
255 sch->q.qlen++;
256 sch->qstats.requeues++;
257 }
258
259 return ret;
260}
261
262static unsigned int netem_drop(struct Qdisc* sch) 252static unsigned int netem_drop(struct Qdisc* sch)
263{ 253{
264 struct netem_sched_data *q = qdisc_priv(sch); 254 struct netem_sched_data *q = qdisc_priv(sch);
@@ -276,29 +266,25 @@ static struct sk_buff *netem_dequeue(struct Qdisc *sch)
276 struct netem_sched_data *q = qdisc_priv(sch); 266 struct netem_sched_data *q = qdisc_priv(sch);
277 struct sk_buff *skb; 267 struct sk_buff *skb;
278 268
279 smp_mb();
280 if (sch->flags & TCQ_F_THROTTLED) 269 if (sch->flags & TCQ_F_THROTTLED)
281 return NULL; 270 return NULL;
282 271
283 skb = q->qdisc->dequeue(q->qdisc); 272 skb = q->qdisc->ops->peek(q->qdisc);
284 if (skb) { 273 if (skb) {
285 const struct netem_skb_cb *cb = netem_skb_cb(skb); 274 const struct netem_skb_cb *cb = netem_skb_cb(skb);
286 psched_time_t now = psched_get_time(); 275 psched_time_t now = psched_get_time();
287 276
288 /* if more time remaining? */ 277 /* if more time remaining? */
289 if (cb->time_to_send <= now) { 278 if (cb->time_to_send <= now) {
279 skb = qdisc_dequeue_peeked(q->qdisc);
280 if (unlikely(!skb))
281 return NULL;
282
290 pr_debug("netem_dequeue: return skb=%p\n", skb); 283 pr_debug("netem_dequeue: return skb=%p\n", skb);
291 sch->q.qlen--; 284 sch->q.qlen--;
292 return skb; 285 return skb;
293 } 286 }
294 287
295 if (unlikely(q->qdisc->ops->requeue(skb, q->qdisc) != NET_XMIT_SUCCESS)) {
296 qdisc_tree_decrease_qlen(q->qdisc, 1);
297 sch->qstats.drops++;
298 printk(KERN_ERR "netem: %s could not requeue\n",
299 q->qdisc->ops->id);
300 }
301
302 qdisc_watchdog_schedule(&q->watchdog, cb->time_to_send); 288 qdisc_watchdog_schedule(&q->watchdog, cb->time_to_send);
303 } 289 }
304 290
@@ -341,14 +327,13 @@ static int get_dist_table(struct Qdisc *sch, const struct nlattr *attr)
341 root_lock = qdisc_root_sleeping_lock(sch); 327 root_lock = qdisc_root_sleeping_lock(sch);
342 328
343 spin_lock_bh(root_lock); 329 spin_lock_bh(root_lock);
344 d = xchg(&q->delay_dist, d); 330 kfree(q->delay_dist);
331 q->delay_dist = d;
345 spin_unlock_bh(root_lock); 332 spin_unlock_bh(root_lock);
346
347 kfree(d);
348 return 0; 333 return 0;
349} 334}
350 335
351static int get_correlation(struct Qdisc *sch, const struct nlattr *attr) 336static void get_correlation(struct Qdisc *sch, const struct nlattr *attr)
352{ 337{
353 struct netem_sched_data *q = qdisc_priv(sch); 338 struct netem_sched_data *q = qdisc_priv(sch);
354 const struct tc_netem_corr *c = nla_data(attr); 339 const struct tc_netem_corr *c = nla_data(attr);
@@ -356,27 +341,24 @@ static int get_correlation(struct Qdisc *sch, const struct nlattr *attr)
356 init_crandom(&q->delay_cor, c->delay_corr); 341 init_crandom(&q->delay_cor, c->delay_corr);
357 init_crandom(&q->loss_cor, c->loss_corr); 342 init_crandom(&q->loss_cor, c->loss_corr);
358 init_crandom(&q->dup_cor, c->dup_corr); 343 init_crandom(&q->dup_cor, c->dup_corr);
359 return 0;
360} 344}
361 345
362static int get_reorder(struct Qdisc *sch, const struct nlattr *attr) 346static void get_reorder(struct Qdisc *sch, const struct nlattr *attr)
363{ 347{
364 struct netem_sched_data *q = qdisc_priv(sch); 348 struct netem_sched_data *q = qdisc_priv(sch);
365 const struct tc_netem_reorder *r = nla_data(attr); 349 const struct tc_netem_reorder *r = nla_data(attr);
366 350
367 q->reorder = r->probability; 351 q->reorder = r->probability;
368 init_crandom(&q->reorder_cor, r->correlation); 352 init_crandom(&q->reorder_cor, r->correlation);
369 return 0;
370} 353}
371 354
372static int get_corrupt(struct Qdisc *sch, const struct nlattr *attr) 355static void get_corrupt(struct Qdisc *sch, const struct nlattr *attr)
373{ 356{
374 struct netem_sched_data *q = qdisc_priv(sch); 357 struct netem_sched_data *q = qdisc_priv(sch);
375 const struct tc_netem_corrupt *r = nla_data(attr); 358 const struct tc_netem_corrupt *r = nla_data(attr);
376 359
377 q->corrupt = r->probability; 360 q->corrupt = r->probability;
378 init_crandom(&q->corrupt_cor, r->correlation); 361 init_crandom(&q->corrupt_cor, r->correlation);
379 return 0;
380} 362}
381 363
382static const struct nla_policy netem_policy[TCA_NETEM_MAX + 1] = { 364static const struct nla_policy netem_policy[TCA_NETEM_MAX + 1] = {
@@ -435,11 +417,8 @@ static int netem_change(struct Qdisc *sch, struct nlattr *opt)
435 if (q->gap) 417 if (q->gap)
436 q->reorder = ~0; 418 q->reorder = ~0;
437 419
438 if (tb[TCA_NETEM_CORR]) { 420 if (tb[TCA_NETEM_CORR])
439 ret = get_correlation(sch, tb[TCA_NETEM_CORR]); 421 get_correlation(sch, tb[TCA_NETEM_CORR]);
440 if (ret)
441 return ret;
442 }
443 422
444 if (tb[TCA_NETEM_DELAY_DIST]) { 423 if (tb[TCA_NETEM_DELAY_DIST]) {
445 ret = get_dist_table(sch, tb[TCA_NETEM_DELAY_DIST]); 424 ret = get_dist_table(sch, tb[TCA_NETEM_DELAY_DIST]);
@@ -447,17 +426,11 @@ static int netem_change(struct Qdisc *sch, struct nlattr *opt)
447 return ret; 426 return ret;
448 } 427 }
449 428
450 if (tb[TCA_NETEM_REORDER]) { 429 if (tb[TCA_NETEM_REORDER])
451 ret = get_reorder(sch, tb[TCA_NETEM_REORDER]); 430 get_reorder(sch, tb[TCA_NETEM_REORDER]);
452 if (ret)
453 return ret;
454 }
455 431
456 if (tb[TCA_NETEM_CORRUPT]) { 432 if (tb[TCA_NETEM_CORRUPT])
457 ret = get_corrupt(sch, tb[TCA_NETEM_CORRUPT]); 433 get_corrupt(sch, tb[TCA_NETEM_CORRUPT]);
458 if (ret)
459 return ret;
460 }
461 434
462 return 0; 435 return 0;
463} 436}
@@ -538,7 +511,7 @@ static struct Qdisc_ops tfifo_qdisc_ops __read_mostly = {
538 .priv_size = sizeof(struct fifo_sched_data), 511 .priv_size = sizeof(struct fifo_sched_data),
539 .enqueue = tfifo_enqueue, 512 .enqueue = tfifo_enqueue,
540 .dequeue = qdisc_dequeue_head, 513 .dequeue = qdisc_dequeue_head,
541 .requeue = qdisc_requeue, 514 .peek = qdisc_peek_head,
542 .drop = qdisc_queue_drop, 515 .drop = qdisc_queue_drop,
543 .init = tfifo_init, 516 .init = tfifo_init,
544 .reset = qdisc_reset_queue, 517 .reset = qdisc_reset_queue,
@@ -621,99 +594,12 @@ nla_put_failure:
621 return -1; 594 return -1;
622} 595}
623 596
624static int netem_dump_class(struct Qdisc *sch, unsigned long cl,
625 struct sk_buff *skb, struct tcmsg *tcm)
626{
627 struct netem_sched_data *q = qdisc_priv(sch);
628
629 if (cl != 1) /* only one class */
630 return -ENOENT;
631
632 tcm->tcm_handle |= TC_H_MIN(1);
633 tcm->tcm_info = q->qdisc->handle;
634
635 return 0;
636}
637
638static int netem_graft(struct Qdisc *sch, unsigned long arg, struct Qdisc *new,
639 struct Qdisc **old)
640{
641 struct netem_sched_data *q = qdisc_priv(sch);
642
643 if (new == NULL)
644 new = &noop_qdisc;
645
646 sch_tree_lock(sch);
647 *old = xchg(&q->qdisc, new);
648 qdisc_tree_decrease_qlen(*old, (*old)->q.qlen);
649 qdisc_reset(*old);
650 sch_tree_unlock(sch);
651
652 return 0;
653}
654
655static struct Qdisc *netem_leaf(struct Qdisc *sch, unsigned long arg)
656{
657 struct netem_sched_data *q = qdisc_priv(sch);
658 return q->qdisc;
659}
660
661static unsigned long netem_get(struct Qdisc *sch, u32 classid)
662{
663 return 1;
664}
665
666static void netem_put(struct Qdisc *sch, unsigned long arg)
667{
668}
669
670static int netem_change_class(struct Qdisc *sch, u32 classid, u32 parentid,
671 struct nlattr **tca, unsigned long *arg)
672{
673 return -ENOSYS;
674}
675
676static int netem_delete(struct Qdisc *sch, unsigned long arg)
677{
678 return -ENOSYS;
679}
680
681static void netem_walk(struct Qdisc *sch, struct qdisc_walker *walker)
682{
683 if (!walker->stop) {
684 if (walker->count >= walker->skip)
685 if (walker->fn(sch, 1, walker) < 0) {
686 walker->stop = 1;
687 return;
688 }
689 walker->count++;
690 }
691}
692
693static struct tcf_proto **netem_find_tcf(struct Qdisc *sch, unsigned long cl)
694{
695 return NULL;
696}
697
698static const struct Qdisc_class_ops netem_class_ops = {
699 .graft = netem_graft,
700 .leaf = netem_leaf,
701 .get = netem_get,
702 .put = netem_put,
703 .change = netem_change_class,
704 .delete = netem_delete,
705 .walk = netem_walk,
706 .tcf_chain = netem_find_tcf,
707 .dump = netem_dump_class,
708};
709
710static struct Qdisc_ops netem_qdisc_ops __read_mostly = { 597static struct Qdisc_ops netem_qdisc_ops __read_mostly = {
711 .id = "netem", 598 .id = "netem",
712 .cl_ops = &netem_class_ops,
713 .priv_size = sizeof(struct netem_sched_data), 599 .priv_size = sizeof(struct netem_sched_data),
714 .enqueue = netem_enqueue, 600 .enqueue = netem_enqueue,
715 .dequeue = netem_dequeue, 601 .dequeue = netem_dequeue,
716 .requeue = netem_requeue, 602 .peek = qdisc_peek_dequeued,
717 .drop = netem_drop, 603 .drop = netem_drop,
718 .init = netem_init, 604 .init = netem_init,
719 .reset = netem_reset, 605 .reset = netem_reset,
diff --git a/net/sched/sch_prio.c b/net/sched/sch_prio.c
index 504a78cdb718..94cecef70145 100644
--- a/net/sched/sch_prio.c
+++ b/net/sched/sch_prio.c
@@ -93,34 +93,20 @@ prio_enqueue(struct sk_buff *skb, struct Qdisc *sch)
93 return ret; 93 return ret;
94} 94}
95 95
96 96static struct sk_buff *prio_peek(struct Qdisc *sch)
97static int
98prio_requeue(struct sk_buff *skb, struct Qdisc* sch)
99{ 97{
100 struct Qdisc *qdisc; 98 struct prio_sched_data *q = qdisc_priv(sch);
101 int ret; 99 int prio;
102
103 qdisc = prio_classify(skb, sch, &ret);
104#ifdef CONFIG_NET_CLS_ACT
105 if (qdisc == NULL) {
106 if (ret & __NET_XMIT_BYPASS)
107 sch->qstats.drops++;
108 kfree_skb(skb);
109 return ret;
110 }
111#endif
112 100
113 if ((ret = qdisc->ops->requeue(skb, qdisc)) == NET_XMIT_SUCCESS) { 101 for (prio = 0; prio < q->bands; prio++) {
114 sch->q.qlen++; 102 struct Qdisc *qdisc = q->queues[prio];
115 sch->qstats.requeues++; 103 struct sk_buff *skb = qdisc->ops->peek(qdisc);
116 return NET_XMIT_SUCCESS; 104 if (skb)
105 return skb;
117 } 106 }
118 if (net_xmit_drop_count(ret)) 107 return NULL;
119 sch->qstats.drops++;
120 return ret;
121} 108}
122 109
123
124static struct sk_buff *prio_dequeue(struct Qdisc* sch) 110static struct sk_buff *prio_dequeue(struct Qdisc* sch)
125{ 111{
126 struct prio_sched_data *q = qdisc_priv(sch); 112 struct prio_sched_data *q = qdisc_priv(sch);
@@ -201,7 +187,8 @@ static int prio_tune(struct Qdisc *sch, struct nlattr *opt)
201 memcpy(q->prio2band, qopt->priomap, TC_PRIO_MAX+1); 187 memcpy(q->prio2band, qopt->priomap, TC_PRIO_MAX+1);
202 188
203 for (i=q->bands; i<TCQ_PRIO_BANDS; i++) { 189 for (i=q->bands; i<TCQ_PRIO_BANDS; i++) {
204 struct Qdisc *child = xchg(&q->queues[i], &noop_qdisc); 190 struct Qdisc *child = q->queues[i];
191 q->queues[i] = &noop_qdisc;
205 if (child != &noop_qdisc) { 192 if (child != &noop_qdisc) {
206 qdisc_tree_decrease_qlen(child, child->q.qlen); 193 qdisc_tree_decrease_qlen(child, child->q.qlen);
207 qdisc_destroy(child); 194 qdisc_destroy(child);
@@ -211,18 +198,19 @@ static int prio_tune(struct Qdisc *sch, struct nlattr *opt)
211 198
212 for (i=0; i<q->bands; i++) { 199 for (i=0; i<q->bands; i++) {
213 if (q->queues[i] == &noop_qdisc) { 200 if (q->queues[i] == &noop_qdisc) {
214 struct Qdisc *child; 201 struct Qdisc *child, *old;
215 child = qdisc_create_dflt(qdisc_dev(sch), sch->dev_queue, 202 child = qdisc_create_dflt(qdisc_dev(sch), sch->dev_queue,
216 &pfifo_qdisc_ops, 203 &pfifo_qdisc_ops,
217 TC_H_MAKE(sch->handle, i + 1)); 204 TC_H_MAKE(sch->handle, i + 1));
218 if (child) { 205 if (child) {
219 sch_tree_lock(sch); 206 sch_tree_lock(sch);
220 child = xchg(&q->queues[i], child); 207 old = q->queues[i];
208 q->queues[i] = child;
221 209
222 if (child != &noop_qdisc) { 210 if (old != &noop_qdisc) {
223 qdisc_tree_decrease_qlen(child, 211 qdisc_tree_decrease_qlen(old,
224 child->q.qlen); 212 old->q.qlen);
225 qdisc_destroy(child); 213 qdisc_destroy(old);
226 } 214 }
227 sch_tree_unlock(sch); 215 sch_tree_unlock(sch);
228 } 216 }
@@ -421,7 +409,7 @@ static struct Qdisc_ops prio_qdisc_ops __read_mostly = {
421 .priv_size = sizeof(struct prio_sched_data), 409 .priv_size = sizeof(struct prio_sched_data),
422 .enqueue = prio_enqueue, 410 .enqueue = prio_enqueue,
423 .dequeue = prio_dequeue, 411 .dequeue = prio_dequeue,
424 .requeue = prio_requeue, 412 .peek = prio_peek,
425 .drop = prio_drop, 413 .drop = prio_drop,
426 .init = prio_init, 414 .init = prio_init,
427 .reset = prio_reset, 415 .reset = prio_reset,
diff --git a/net/sched/sch_red.c b/net/sched/sch_red.c
index 5da05839e225..2bdf241f6315 100644
--- a/net/sched/sch_red.c
+++ b/net/sched/sch_red.c
@@ -108,23 +108,6 @@ congestion_drop:
108 return NET_XMIT_CN; 108 return NET_XMIT_CN;
109} 109}
110 110
111static int red_requeue(struct sk_buff *skb, struct Qdisc* sch)
112{
113 struct red_sched_data *q = qdisc_priv(sch);
114 struct Qdisc *child = q->qdisc;
115 int ret;
116
117 if (red_is_idling(&q->parms))
118 red_end_of_idle_period(&q->parms);
119
120 ret = child->ops->requeue(skb, child);
121 if (likely(ret == NET_XMIT_SUCCESS)) {
122 sch->qstats.requeues++;
123 sch->q.qlen++;
124 }
125 return ret;
126}
127
128static struct sk_buff * red_dequeue(struct Qdisc* sch) 111static struct sk_buff * red_dequeue(struct Qdisc* sch)
129{ 112{
130 struct sk_buff *skb; 113 struct sk_buff *skb;
@@ -140,6 +123,14 @@ static struct sk_buff * red_dequeue(struct Qdisc* sch)
140 return skb; 123 return skb;
141} 124}
142 125
126static struct sk_buff * red_peek(struct Qdisc* sch)
127{
128 struct red_sched_data *q = qdisc_priv(sch);
129 struct Qdisc *child = q->qdisc;
130
131 return child->ops->peek(child);
132}
133
143static unsigned int red_drop(struct Qdisc* sch) 134static unsigned int red_drop(struct Qdisc* sch)
144{ 135{
145 struct red_sched_data *q = qdisc_priv(sch); 136 struct red_sched_data *q = qdisc_priv(sch);
@@ -211,7 +202,8 @@ static int red_change(struct Qdisc *sch, struct nlattr *opt)
211 q->limit = ctl->limit; 202 q->limit = ctl->limit;
212 if (child) { 203 if (child) {
213 qdisc_tree_decrease_qlen(q->qdisc, q->qdisc->q.qlen); 204 qdisc_tree_decrease_qlen(q->qdisc, q->qdisc->q.qlen);
214 qdisc_destroy(xchg(&q->qdisc, child)); 205 qdisc_destroy(q->qdisc);
206 q->qdisc = child;
215 } 207 }
216 208
217 red_set_parms(&q->parms, ctl->qth_min, ctl->qth_max, ctl->Wlog, 209 red_set_parms(&q->parms, ctl->qth_min, ctl->qth_max, ctl->Wlog,
@@ -292,7 +284,8 @@ static int red_graft(struct Qdisc *sch, unsigned long arg, struct Qdisc *new,
292 new = &noop_qdisc; 284 new = &noop_qdisc;
293 285
294 sch_tree_lock(sch); 286 sch_tree_lock(sch);
295 *old = xchg(&q->qdisc, new); 287 *old = q->qdisc;
288 q->qdisc = new;
296 qdisc_tree_decrease_qlen(*old, (*old)->q.qlen); 289 qdisc_tree_decrease_qlen(*old, (*old)->q.qlen);
297 qdisc_reset(*old); 290 qdisc_reset(*old);
298 sch_tree_unlock(sch); 291 sch_tree_unlock(sch);
@@ -361,7 +354,7 @@ static struct Qdisc_ops red_qdisc_ops __read_mostly = {
361 .cl_ops = &red_class_ops, 354 .cl_ops = &red_class_ops,
362 .enqueue = red_enqueue, 355 .enqueue = red_enqueue,
363 .dequeue = red_dequeue, 356 .dequeue = red_dequeue,
364 .requeue = red_requeue, 357 .peek = red_peek,
365 .drop = red_drop, 358 .drop = red_drop,
366 .init = red_init, 359 .init = red_init,
367 .reset = red_reset, 360 .reset = red_reset,
diff --git a/net/sched/sch_sfq.c b/net/sched/sch_sfq.c
index fe1508ef0d3d..f3965df00559 100644
--- a/net/sched/sch_sfq.c
+++ b/net/sched/sch_sfq.c
@@ -281,7 +281,7 @@ sfq_enqueue(struct sk_buff *skb, struct Qdisc *sch)
281 struct sfq_sched_data *q = qdisc_priv(sch); 281 struct sfq_sched_data *q = qdisc_priv(sch);
282 unsigned int hash; 282 unsigned int hash;
283 sfq_index x; 283 sfq_index x;
284 int ret; 284 int uninitialized_var(ret);
285 285
286 hash = sfq_classify(skb, sch, &ret); 286 hash = sfq_classify(skb, sch, &ret);
287 if (hash == 0) { 287 if (hash == 0) {
@@ -329,71 +329,20 @@ sfq_enqueue(struct sk_buff *skb, struct Qdisc *sch)
329 return NET_XMIT_CN; 329 return NET_XMIT_CN;
330} 330}
331 331
332static int 332static struct sk_buff *
333sfq_requeue(struct sk_buff *skb, struct Qdisc *sch) 333sfq_peek(struct Qdisc *sch)
334{ 334{
335 struct sfq_sched_data *q = qdisc_priv(sch); 335 struct sfq_sched_data *q = qdisc_priv(sch);
336 unsigned int hash; 336 sfq_index a;
337 sfq_index x;
338 int ret;
339
340 hash = sfq_classify(skb, sch, &ret);
341 if (hash == 0) {
342 if (ret & __NET_XMIT_BYPASS)
343 sch->qstats.drops++;
344 kfree_skb(skb);
345 return ret;
346 }
347 hash--;
348 337
349 x = q->ht[hash]; 338 /* No active slots */
350 if (x == SFQ_DEPTH) { 339 if (q->tail == SFQ_DEPTH)
351 q->ht[hash] = x = q->dep[SFQ_DEPTH].next; 340 return NULL;
352 q->hash[x] = hash;
353 }
354
355 sch->qstats.backlog += qdisc_pkt_len(skb);
356 __skb_queue_head(&q->qs[x], skb);
357 /* If selected queue has length q->limit+1, this means that
358 * all another queues are empty and we do simple tail drop.
359 * This packet is still requeued at head of queue, tail packet
360 * is dropped.
361 */
362 if (q->qs[x].qlen > q->limit) {
363 skb = q->qs[x].prev;
364 __skb_unlink(skb, &q->qs[x]);
365 sch->qstats.drops++;
366 sch->qstats.backlog -= qdisc_pkt_len(skb);
367 kfree_skb(skb);
368 return NET_XMIT_CN;
369 }
370
371 sfq_inc(q, x);
372 if (q->qs[x].qlen == 1) { /* The flow is new */
373 if (q->tail == SFQ_DEPTH) { /* It is the first flow */
374 q->tail = x;
375 q->next[x] = x;
376 q->allot[x] = q->quantum;
377 } else {
378 q->next[x] = q->next[q->tail];
379 q->next[q->tail] = x;
380 q->tail = x;
381 }
382 }
383
384 if (++sch->q.qlen <= q->limit) {
385 sch->qstats.requeues++;
386 return 0;
387 }
388 341
389 sch->qstats.drops++; 342 a = q->next[q->tail];
390 sfq_drop(sch); 343 return skb_peek(&q->qs[a]);
391 return NET_XMIT_CN;
392} 344}
393 345
394
395
396
397static struct sk_buff * 346static struct sk_buff *
398sfq_dequeue(struct Qdisc *sch) 347sfq_dequeue(struct Qdisc *sch)
399{ 348{
@@ -624,7 +573,7 @@ static struct Qdisc_ops sfq_qdisc_ops __read_mostly = {
624 .priv_size = sizeof(struct sfq_sched_data), 573 .priv_size = sizeof(struct sfq_sched_data),
625 .enqueue = sfq_enqueue, 574 .enqueue = sfq_enqueue,
626 .dequeue = sfq_dequeue, 575 .dequeue = sfq_dequeue,
627 .requeue = sfq_requeue, 576 .peek = sfq_peek,
628 .drop = sfq_drop, 577 .drop = sfq_drop,
629 .init = sfq_init, 578 .init = sfq_init,
630 .reset = sfq_reset, 579 .reset = sfq_reset,
diff --git a/net/sched/sch_tbf.c b/net/sched/sch_tbf.c
index 94c61598b86a..a2f93c09f3cc 100644
--- a/net/sched/sch_tbf.c
+++ b/net/sched/sch_tbf.c
@@ -139,19 +139,6 @@ static int tbf_enqueue(struct sk_buff *skb, struct Qdisc* sch)
139 return 0; 139 return 0;
140} 140}
141 141
142static int tbf_requeue(struct sk_buff *skb, struct Qdisc* sch)
143{
144 struct tbf_sched_data *q = qdisc_priv(sch);
145 int ret;
146
147 if ((ret = q->qdisc->ops->requeue(skb, q->qdisc)) == 0) {
148 sch->q.qlen++;
149 sch->qstats.requeues++;
150 }
151
152 return ret;
153}
154
155static unsigned int tbf_drop(struct Qdisc* sch) 142static unsigned int tbf_drop(struct Qdisc* sch)
156{ 143{
157 struct tbf_sched_data *q = qdisc_priv(sch); 144 struct tbf_sched_data *q = qdisc_priv(sch);
@@ -169,7 +156,7 @@ static struct sk_buff *tbf_dequeue(struct Qdisc* sch)
169 struct tbf_sched_data *q = qdisc_priv(sch); 156 struct tbf_sched_data *q = qdisc_priv(sch);
170 struct sk_buff *skb; 157 struct sk_buff *skb;
171 158
172 skb = q->qdisc->dequeue(q->qdisc); 159 skb = q->qdisc->ops->peek(q->qdisc);
173 160
174 if (skb) { 161 if (skb) {
175 psched_time_t now; 162 psched_time_t now;
@@ -192,6 +179,10 @@ static struct sk_buff *tbf_dequeue(struct Qdisc* sch)
192 toks -= L2T(q, len); 179 toks -= L2T(q, len);
193 180
194 if ((toks|ptoks) >= 0) { 181 if ((toks|ptoks) >= 0) {
182 skb = qdisc_dequeue_peeked(q->qdisc);
183 if (unlikely(!skb))
184 return NULL;
185
195 q->t_c = now; 186 q->t_c = now;
196 q->tokens = toks; 187 q->tokens = toks;
197 q->ptokens = ptoks; 188 q->ptokens = ptoks;
@@ -214,12 +205,6 @@ static struct sk_buff *tbf_dequeue(struct Qdisc* sch)
214 (cf. CSZ, HPFQ, HFSC) 205 (cf. CSZ, HPFQ, HFSC)
215 */ 206 */
216 207
217 if (q->qdisc->ops->requeue(skb, q->qdisc) != NET_XMIT_SUCCESS) {
218 /* When requeue fails skb is dropped */
219 qdisc_tree_decrease_qlen(q->qdisc, 1);
220 sch->qstats.drops++;
221 }
222
223 sch->qstats.overlimits++; 208 sch->qstats.overlimits++;
224 } 209 }
225 return NULL; 210 return NULL;
@@ -251,6 +236,7 @@ static int tbf_change(struct Qdisc* sch, struct nlattr *opt)
251 struct tc_tbf_qopt *qopt; 236 struct tc_tbf_qopt *qopt;
252 struct qdisc_rate_table *rtab = NULL; 237 struct qdisc_rate_table *rtab = NULL;
253 struct qdisc_rate_table *ptab = NULL; 238 struct qdisc_rate_table *ptab = NULL;
239 struct qdisc_rate_table *tmp;
254 struct Qdisc *child = NULL; 240 struct Qdisc *child = NULL;
255 int max_size,n; 241 int max_size,n;
256 242
@@ -299,7 +285,8 @@ static int tbf_change(struct Qdisc* sch, struct nlattr *opt)
299 sch_tree_lock(sch); 285 sch_tree_lock(sch);
300 if (child) { 286 if (child) {
301 qdisc_tree_decrease_qlen(q->qdisc, q->qdisc->q.qlen); 287 qdisc_tree_decrease_qlen(q->qdisc, q->qdisc->q.qlen);
302 qdisc_destroy(xchg(&q->qdisc, child)); 288 qdisc_destroy(q->qdisc);
289 q->qdisc = child;
303 } 290 }
304 q->limit = qopt->limit; 291 q->limit = qopt->limit;
305 q->mtu = qopt->mtu; 292 q->mtu = qopt->mtu;
@@ -307,8 +294,14 @@ static int tbf_change(struct Qdisc* sch, struct nlattr *opt)
307 q->buffer = qopt->buffer; 294 q->buffer = qopt->buffer;
308 q->tokens = q->buffer; 295 q->tokens = q->buffer;
309 q->ptokens = q->mtu; 296 q->ptokens = q->mtu;
310 rtab = xchg(&q->R_tab, rtab); 297
311 ptab = xchg(&q->P_tab, ptab); 298 tmp = q->R_tab;
299 q->R_tab = rtab;
300 rtab = tmp;
301
302 tmp = q->P_tab;
303 q->P_tab = ptab;
304 ptab = tmp;
312 sch_tree_unlock(sch); 305 sch_tree_unlock(sch);
313 err = 0; 306 err = 0;
314done: 307done:
@@ -398,7 +391,8 @@ static int tbf_graft(struct Qdisc *sch, unsigned long arg, struct Qdisc *new,
398 new = &noop_qdisc; 391 new = &noop_qdisc;
399 392
400 sch_tree_lock(sch); 393 sch_tree_lock(sch);
401 *old = xchg(&q->qdisc, new); 394 *old = q->qdisc;
395 q->qdisc = new;
402 qdisc_tree_decrease_qlen(*old, (*old)->q.qlen); 396 qdisc_tree_decrease_qlen(*old, (*old)->q.qlen);
403 qdisc_reset(*old); 397 qdisc_reset(*old);
404 sch_tree_unlock(sch); 398 sch_tree_unlock(sch);
@@ -469,7 +463,7 @@ static struct Qdisc_ops tbf_qdisc_ops __read_mostly = {
469 .priv_size = sizeof(struct tbf_sched_data), 463 .priv_size = sizeof(struct tbf_sched_data),
470 .enqueue = tbf_enqueue, 464 .enqueue = tbf_enqueue,
471 .dequeue = tbf_dequeue, 465 .dequeue = tbf_dequeue,
472 .requeue = tbf_requeue, 466 .peek = qdisc_peek_dequeued,
473 .drop = tbf_drop, 467 .drop = tbf_drop,
474 .init = tbf_init, 468 .init = tbf_init,
475 .reset = tbf_reset, 469 .reset = tbf_reset,
diff --git a/net/sched/sch_teql.c b/net/sched/sch_teql.c
index d35ef059abb1..cfc8e7caba62 100644
--- a/net/sched/sch_teql.c
+++ b/net/sched/sch_teql.c
@@ -93,16 +93,6 @@ teql_enqueue(struct sk_buff *skb, struct Qdisc* sch)
93 return NET_XMIT_DROP; 93 return NET_XMIT_DROP;
94} 94}
95 95
96static int
97teql_requeue(struct sk_buff *skb, struct Qdisc* sch)
98{
99 struct teql_sched_data *q = qdisc_priv(sch);
100
101 __skb_queue_head(&q->q, skb);
102 sch->qstats.requeues++;
103 return 0;
104}
105
106static struct sk_buff * 96static struct sk_buff *
107teql_dequeue(struct Qdisc* sch) 97teql_dequeue(struct Qdisc* sch)
108{ 98{
@@ -123,6 +113,13 @@ teql_dequeue(struct Qdisc* sch)
123 return skb; 113 return skb;
124} 114}
125 115
116static struct sk_buff *
117teql_peek(struct Qdisc* sch)
118{
119 /* teql is meant to be used as root qdisc */
120 return NULL;
121}
122
126static __inline__ void 123static __inline__ void
127teql_neigh_release(struct neighbour *n) 124teql_neigh_release(struct neighbour *n)
128{ 125{
@@ -433,7 +430,7 @@ static __init void teql_master_setup(struct net_device *dev)
433 430
434 ops->enqueue = teql_enqueue; 431 ops->enqueue = teql_enqueue;
435 ops->dequeue = teql_dequeue; 432 ops->dequeue = teql_dequeue;
436 ops->requeue = teql_requeue; 433 ops->peek = teql_peek;
437 ops->init = teql_qdisc_init; 434 ops->init = teql_qdisc_init;
438 ops->reset = teql_reset; 435 ops->reset = teql_reset;
439 ops->destroy = teql_destroy; 436 ops->destroy = teql_destroy;
diff --git a/net/sctp/ipv6.c b/net/sctp/ipv6.c
index 4124bbb99947..ceaa4aa066ea 100644
--- a/net/sctp/ipv6.c
+++ b/net/sctp/ipv6.c
@@ -223,10 +223,9 @@ static int sctp_v6_xmit(struct sk_buff *skb, struct sctp_transport *transport)
223 ipv6_addr_copy(&fl.fl6_dst, rt0->addr); 223 ipv6_addr_copy(&fl.fl6_dst, rt0->addr);
224 } 224 }
225 225
226 SCTP_DEBUG_PRINTK("%s: skb:%p, len:%d, " 226 SCTP_DEBUG_PRINTK("%s: skb:%p, len:%d, src:%pI6 dst:%pI6\n",
227 "src:" NIP6_FMT " dst:" NIP6_FMT "\n",
228 __func__, skb, skb->len, 227 __func__, skb, skb->len,
229 NIP6(fl.fl6_src), NIP6(fl.fl6_dst)); 228 &fl.fl6_src, &fl.fl6_dst);
230 229
231 SCTP_INC_STATS(SCTP_MIB_OUTSCTPPACKS); 230 SCTP_INC_STATS(SCTP_MIB_OUTSCTPPACKS);
232 231
@@ -252,23 +251,19 @@ static struct dst_entry *sctp_v6_get_dst(struct sctp_association *asoc,
252 fl.oif = daddr->v6.sin6_scope_id; 251 fl.oif = daddr->v6.sin6_scope_id;
253 252
254 253
255 SCTP_DEBUG_PRINTK("%s: DST=" NIP6_FMT " ", 254 SCTP_DEBUG_PRINTK("%s: DST=%pI6 ", __func__, &fl.fl6_dst);
256 __func__, NIP6(fl.fl6_dst));
257 255
258 if (saddr) { 256 if (saddr) {
259 ipv6_addr_copy(&fl.fl6_src, &saddr->v6.sin6_addr); 257 ipv6_addr_copy(&fl.fl6_src, &saddr->v6.sin6_addr);
260 SCTP_DEBUG_PRINTK( 258 SCTP_DEBUG_PRINTK("SRC=%pI6 - ", &fl.fl6_src);
261 "SRC=" NIP6_FMT " - ",
262 NIP6(fl.fl6_src));
263 } 259 }
264 260
265 dst = ip6_route_output(&init_net, NULL, &fl); 261 dst = ip6_route_output(&init_net, NULL, &fl);
266 if (!dst->error) { 262 if (!dst->error) {
267 struct rt6_info *rt; 263 struct rt6_info *rt;
268 rt = (struct rt6_info *)dst; 264 rt = (struct rt6_info *)dst;
269 SCTP_DEBUG_PRINTK( 265 SCTP_DEBUG_PRINTK("rt6_dst:%pI6 rt6_src:%pI6\n",
270 "rt6_dst:" NIP6_FMT " rt6_src:" NIP6_FMT "\n", 266 &rt->rt6i_dst.addr, &rt->rt6i_src.addr);
271 NIP6(rt->rt6i_dst.addr), NIP6(rt->rt6i_src.addr));
272 return dst; 267 return dst;
273 } 268 }
274 SCTP_DEBUG_PRINTK("NO ROUTE\n"); 269 SCTP_DEBUG_PRINTK("NO ROUTE\n");
@@ -314,9 +309,8 @@ static void sctp_v6_get_saddr(struct sctp_sock *sk,
314 __u8 matchlen = 0; 309 __u8 matchlen = 0;
315 __u8 bmatchlen; 310 __u8 bmatchlen;
316 311
317 SCTP_DEBUG_PRINTK("%s: asoc:%p dst:%p " 312 SCTP_DEBUG_PRINTK("%s: asoc:%p dst:%p daddr:%pI6 ",
318 "daddr:" NIP6_FMT " ", 313 __func__, asoc, dst, &daddr->v6.sin6_addr);
319 __func__, asoc, dst, NIP6(daddr->v6.sin6_addr));
320 314
321 if (!asoc) { 315 if (!asoc) {
322 ipv6_dev_get_saddr(sock_net(sctp_opt2sk(sk)), 316 ipv6_dev_get_saddr(sock_net(sctp_opt2sk(sk)),
@@ -324,8 +318,8 @@ static void sctp_v6_get_saddr(struct sctp_sock *sk,
324 &daddr->v6.sin6_addr, 318 &daddr->v6.sin6_addr,
325 inet6_sk(&sk->inet.sk)->srcprefs, 319 inet6_sk(&sk->inet.sk)->srcprefs,
326 &saddr->v6.sin6_addr); 320 &saddr->v6.sin6_addr);
327 SCTP_DEBUG_PRINTK("saddr from ipv6_get_saddr: " NIP6_FMT "\n", 321 SCTP_DEBUG_PRINTK("saddr from ipv6_get_saddr: %pI6\n",
328 NIP6(saddr->v6.sin6_addr)); 322 &saddr->v6.sin6_addr);
329 return; 323 return;
330 } 324 }
331 325
@@ -353,12 +347,11 @@ static void sctp_v6_get_saddr(struct sctp_sock *sk,
353 347
354 if (baddr) { 348 if (baddr) {
355 memcpy(saddr, baddr, sizeof(union sctp_addr)); 349 memcpy(saddr, baddr, sizeof(union sctp_addr));
356 SCTP_DEBUG_PRINTK("saddr: " NIP6_FMT "\n", 350 SCTP_DEBUG_PRINTK("saddr: %pI6\n", &saddr->v6.sin6_addr);
357 NIP6(saddr->v6.sin6_addr));
358 } else { 351 } else {
359 printk(KERN_ERR "%s: asoc:%p Could not find a valid source " 352 printk(KERN_ERR "%s: asoc:%p Could not find a valid source "
360 "address for the dest:" NIP6_FMT "\n", 353 "address for the dest:%pI6\n",
361 __func__, asoc, NIP6(daddr->v6.sin6_addr)); 354 __func__, asoc, &daddr->v6.sin6_addr);
362 } 355 }
363 356
364 rcu_read_unlock(); 357 rcu_read_unlock();
@@ -727,7 +720,7 @@ static int sctp_v6_is_ce(const struct sk_buff *skb)
727/* Dump the v6 addr to the seq file. */ 720/* Dump the v6 addr to the seq file. */
728static void sctp_v6_seq_dump_addr(struct seq_file *seq, union sctp_addr *addr) 721static void sctp_v6_seq_dump_addr(struct seq_file *seq, union sctp_addr *addr)
729{ 722{
730 seq_printf(seq, NIP6_FMT " ", NIP6(addr->v6.sin6_addr)); 723 seq_printf(seq, "%pI6 ", &addr->v6.sin6_addr);
731} 724}
732 725
733static void sctp_v6_ecn_capable(struct sock *sk) 726static void sctp_v6_ecn_capable(struct sock *sk)
diff --git a/net/sctp/protocol.c b/net/sctp/protocol.c
index 0b65354aaf64..b78e3be69013 100644
--- a/net/sctp/protocol.c
+++ b/net/sctp/protocol.c
@@ -102,6 +102,8 @@ struct sock *sctp_get_ctl_sock(void)
102/* Set up the proc fs entry for the SCTP protocol. */ 102/* Set up the proc fs entry for the SCTP protocol. */
103static __init int sctp_proc_init(void) 103static __init int sctp_proc_init(void)
104{ 104{
105 if (percpu_counter_init(&sctp_sockets_allocated, 0))
106 goto out_nomem;
105#ifdef CONFIG_PROC_FS 107#ifdef CONFIG_PROC_FS
106 if (!proc_net_sctp) { 108 if (!proc_net_sctp) {
107 struct proc_dir_entry *ent; 109 struct proc_dir_entry *ent;
@@ -110,7 +112,7 @@ static __init int sctp_proc_init(void)
110 ent->owner = THIS_MODULE; 112 ent->owner = THIS_MODULE;
111 proc_net_sctp = ent; 113 proc_net_sctp = ent;
112 } else 114 } else
113 goto out_nomem; 115 goto out_free_percpu;
114 } 116 }
115 117
116 if (sctp_snmp_proc_init()) 118 if (sctp_snmp_proc_init())
@@ -135,11 +137,14 @@ out_snmp_proc_init:
135 proc_net_sctp = NULL; 137 proc_net_sctp = NULL;
136 remove_proc_entry("sctp", init_net.proc_net); 138 remove_proc_entry("sctp", init_net.proc_net);
137 } 139 }
138out_nomem: 140out_free_percpu:
139 return -ENOMEM; 141 percpu_counter_destroy(&sctp_sockets_allocated);
140#else 142#else
141 return 0; 143 return 0;
142#endif /* CONFIG_PROC_FS */ 144#endif /* CONFIG_PROC_FS */
145
146out_nomem:
147 return -ENOMEM;
143} 148}
144 149
145/* Clean up the proc fs entry for the SCTP protocol. 150/* Clean up the proc fs entry for the SCTP protocol.
@@ -482,9 +487,8 @@ static struct dst_entry *sctp_v4_get_dst(struct sctp_association *asoc,
482 if (saddr) 487 if (saddr)
483 fl.fl4_src = saddr->v4.sin_addr.s_addr; 488 fl.fl4_src = saddr->v4.sin_addr.s_addr;
484 489
485 SCTP_DEBUG_PRINTK("%s: DST:%u.%u.%u.%u, SRC:%u.%u.%u.%u - ", 490 SCTP_DEBUG_PRINTK("%s: DST:%pI4, SRC:%pI4 - ",
486 __func__, NIPQUAD(fl.fl4_dst), 491 __func__, &fl.fl4_dst, &fl.fl4_src);
487 NIPQUAD(fl.fl4_src));
488 492
489 if (!ip_route_output_key(&init_net, &rt, &fl)) { 493 if (!ip_route_output_key(&init_net, &rt, &fl)) {
490 dst = &rt->u.dst; 494 dst = &rt->u.dst;
@@ -540,8 +544,8 @@ out_unlock:
540 rcu_read_unlock(); 544 rcu_read_unlock();
541out: 545out:
542 if (dst) 546 if (dst)
543 SCTP_DEBUG_PRINTK("rt_dst:%u.%u.%u.%u, rt_src:%u.%u.%u.%u\n", 547 SCTP_DEBUG_PRINTK("rt_dst:%pI4, rt_src:%pI4\n",
544 NIPQUAD(rt->rt_dst), NIPQUAD(rt->rt_src)); 548 &rt->rt_dst, &rt->rt_src);
545 else 549 else
546 SCTP_DEBUG_PRINTK("NO ROUTE\n"); 550 SCTP_DEBUG_PRINTK("NO ROUTE\n");
547 551
@@ -646,7 +650,7 @@ static void sctp_v4_addr_v4map(struct sctp_sock *sp, union sctp_addr *addr)
646/* Dump the v4 addr to the seq file. */ 650/* Dump the v4 addr to the seq file. */
647static void sctp_v4_seq_dump_addr(struct seq_file *seq, union sctp_addr *addr) 651static void sctp_v4_seq_dump_addr(struct seq_file *seq, union sctp_addr *addr)
648{ 652{
649 seq_printf(seq, "%d.%d.%d.%d ", NIPQUAD(addr->v4.sin_addr)); 653 seq_printf(seq, "%pI4 ", &addr->v4.sin_addr);
650} 654}
651 655
652static void sctp_v4_ecn_capable(struct sock *sk) 656static void sctp_v4_ecn_capable(struct sock *sk)
@@ -866,11 +870,10 @@ static inline int sctp_v4_xmit(struct sk_buff *skb,
866{ 870{
867 struct inet_sock *inet = inet_sk(skb->sk); 871 struct inet_sock *inet = inet_sk(skb->sk);
868 872
869 SCTP_DEBUG_PRINTK("%s: skb:%p, len:%d, " 873 SCTP_DEBUG_PRINTK("%s: skb:%p, len:%d, src:%pI4, dst:%pI4\n",
870 "src:%u.%u.%u.%u, dst:%u.%u.%u.%u\n",
871 __func__, skb, skb->len, 874 __func__, skb, skb->len,
872 NIPQUAD(skb->rtable->rt_src), 875 &skb->rtable->rt_src,
873 NIPQUAD(skb->rtable->rt_dst)); 876 &skb->rtable->rt_dst);
874 877
875 inet->pmtudisc = transport->param_flags & SPP_PMTUD_ENABLE ? 878 inet->pmtudisc = transport->param_flags & SPP_PMTUD_ENABLE ?
876 IP_PMTUDISC_DO : IP_PMTUDISC_DONT; 879 IP_PMTUDISC_DO : IP_PMTUDISC_DONT;
diff --git a/net/sctp/sm_statefuns.c b/net/sctp/sm_statefuns.c
index a6a0ea71ae93..1c4e5d6c29c0 100644
--- a/net/sctp/sm_statefuns.c
+++ b/net/sctp/sm_statefuns.c
@@ -1123,19 +1123,17 @@ sctp_disposition_t sctp_sf_backbeat_8_3(const struct sctp_endpoint *ep,
1123 if (from_addr.sa.sa_family == AF_INET6) { 1123 if (from_addr.sa.sa_family == AF_INET6) {
1124 if (net_ratelimit()) 1124 if (net_ratelimit())
1125 printk(KERN_WARNING 1125 printk(KERN_WARNING
1126 "%s association %p could not find address " 1126 "%s association %p could not find address %pI6\n",
1127 NIP6_FMT "\n",
1128 __func__, 1127 __func__,
1129 asoc, 1128 asoc,
1130 NIP6(from_addr.v6.sin6_addr)); 1129 &from_addr.v6.sin6_addr);
1131 } else { 1130 } else {
1132 if (net_ratelimit()) 1131 if (net_ratelimit())
1133 printk(KERN_WARNING 1132 printk(KERN_WARNING
1134 "%s association %p could not find address " 1133 "%s association %p could not find address %pI4\n",
1135 NIPQUAD_FMT "\n",
1136 __func__, 1134 __func__,
1137 asoc, 1135 asoc,
1138 NIPQUAD(from_addr.v4.sin_addr.s_addr)); 1136 &from_addr.v4.sin_addr.s_addr);
1139 } 1137 }
1140 return SCTP_DISPOSITION_DISCARD; 1138 return SCTP_DISPOSITION_DISCARD;
1141 } 1139 }
@@ -3691,6 +3689,7 @@ sctp_disposition_t sctp_sf_eat_fwd_tsn(const struct sctp_endpoint *ep,
3691{ 3689{
3692 struct sctp_chunk *chunk = arg; 3690 struct sctp_chunk *chunk = arg;
3693 struct sctp_fwdtsn_hdr *fwdtsn_hdr; 3691 struct sctp_fwdtsn_hdr *fwdtsn_hdr;
3692 struct sctp_fwdtsn_skip *skip;
3694 __u16 len; 3693 __u16 len;
3695 __u32 tsn; 3694 __u32 tsn;
3696 3695
@@ -3720,6 +3719,12 @@ sctp_disposition_t sctp_sf_eat_fwd_tsn(const struct sctp_endpoint *ep,
3720 if (sctp_tsnmap_check(&asoc->peer.tsn_map, tsn) < 0) 3719 if (sctp_tsnmap_check(&asoc->peer.tsn_map, tsn) < 0)
3721 goto discard_noforce; 3720 goto discard_noforce;
3722 3721
3722 /* Silently discard the chunk if stream-id is not valid */
3723 sctp_walk_fwdtsn(skip, chunk) {
3724 if (ntohs(skip->stream) >= asoc->c.sinit_max_instreams)
3725 goto discard_noforce;
3726 }
3727
3723 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_FWDTSN, SCTP_U32(tsn)); 3728 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_FWDTSN, SCTP_U32(tsn));
3724 if (len > sizeof(struct sctp_fwdtsn_hdr)) 3729 if (len > sizeof(struct sctp_fwdtsn_hdr))
3725 sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_FWDTSN, 3730 sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_FWDTSN,
@@ -3751,6 +3756,7 @@ sctp_disposition_t sctp_sf_eat_fwd_tsn_fast(
3751{ 3756{
3752 struct sctp_chunk *chunk = arg; 3757 struct sctp_chunk *chunk = arg;
3753 struct sctp_fwdtsn_hdr *fwdtsn_hdr; 3758 struct sctp_fwdtsn_hdr *fwdtsn_hdr;
3759 struct sctp_fwdtsn_skip *skip;
3754 __u16 len; 3760 __u16 len;
3755 __u32 tsn; 3761 __u32 tsn;
3756 3762
@@ -3780,6 +3786,12 @@ sctp_disposition_t sctp_sf_eat_fwd_tsn_fast(
3780 if (sctp_tsnmap_check(&asoc->peer.tsn_map, tsn) < 0) 3786 if (sctp_tsnmap_check(&asoc->peer.tsn_map, tsn) < 0)
3781 goto gen_shutdown; 3787 goto gen_shutdown;
3782 3788
3789 /* Silently discard the chunk if stream-id is not valid */
3790 sctp_walk_fwdtsn(skip, chunk) {
3791 if (ntohs(skip->stream) >= asoc->c.sinit_max_instreams)
3792 goto gen_shutdown;
3793 }
3794
3783 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_FWDTSN, SCTP_U32(tsn)); 3795 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_FWDTSN, SCTP_U32(tsn));
3784 if (len > sizeof(struct sctp_fwdtsn_hdr)) 3796 if (len > sizeof(struct sctp_fwdtsn_hdr))
3785 sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_FWDTSN, 3797 sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_FWDTSN,
diff --git a/net/sctp/socket.c b/net/sctp/socket.c
index a1b904529d5e..b14a8f33e42d 100644
--- a/net/sctp/socket.c
+++ b/net/sctp/socket.c
@@ -114,7 +114,7 @@ extern int sysctl_sctp_wmem[3];
114 114
115static int sctp_memory_pressure; 115static int sctp_memory_pressure;
116static atomic_t sctp_memory_allocated; 116static atomic_t sctp_memory_allocated;
117static atomic_t sctp_sockets_allocated; 117struct percpu_counter sctp_sockets_allocated;
118 118
119static void sctp_enter_memory_pressure(struct sock *sk) 119static void sctp_enter_memory_pressure(struct sock *sk)
120{ 120{
@@ -2404,9 +2404,9 @@ static int sctp_setsockopt_delayed_ack(struct sock *sk,
2404 if (params.sack_delay == 0 && params.sack_freq == 0) 2404 if (params.sack_delay == 0 && params.sack_freq == 0)
2405 return 0; 2405 return 0;
2406 } else if (optlen == sizeof(struct sctp_assoc_value)) { 2406 } else if (optlen == sizeof(struct sctp_assoc_value)) {
2407 printk(KERN_WARNING "SCTP: Use of struct sctp_sack_info " 2407 printk(KERN_WARNING "SCTP: Use of struct sctp_assoc_value "
2408 "in delayed_ack socket option deprecated\n"); 2408 "in delayed_ack socket option deprecated\n");
2409 printk(KERN_WARNING "SCTP: struct sctp_sack_info instead\n"); 2409 printk(KERN_WARNING "SCTP: Use struct sctp_sack_info instead\n");
2410 if (copy_from_user(&params, optval, optlen)) 2410 if (copy_from_user(&params, optval, optlen))
2411 return -EFAULT; 2411 return -EFAULT;
2412 2412
@@ -2778,32 +2778,77 @@ static int sctp_setsockopt_mappedv4(struct sock *sk, char __user *optval, int op
2778} 2778}
2779 2779
2780/* 2780/*
2781 * 7.1.17 Set the maximum fragrmentation size (SCTP_MAXSEG) 2781 * 8.1.16. Get or Set the Maximum Fragmentation Size (SCTP_MAXSEG)
2782 * 2782 * This option will get or set the maximum size to put in any outgoing
2783 * This socket option specifies the maximum size to put in any outgoing 2783 * SCTP DATA chunk. If a message is larger than this size it will be
2784 * SCTP chunk. If a message is larger than this size it will be
2785 * fragmented by SCTP into the specified size. Note that the underlying 2784 * fragmented by SCTP into the specified size. Note that the underlying
2786 * SCTP implementation may fragment into smaller sized chunks when the 2785 * SCTP implementation may fragment into smaller sized chunks when the
2787 * PMTU of the underlying association is smaller than the value set by 2786 * PMTU of the underlying association is smaller than the value set by
2788 * the user. 2787 * the user. The default value for this option is '0' which indicates
2788 * the user is NOT limiting fragmentation and only the PMTU will effect
2789 * SCTP's choice of DATA chunk size. Note also that values set larger
2790 * than the maximum size of an IP datagram will effectively let SCTP
2791 * control fragmentation (i.e. the same as setting this option to 0).
2792 *
2793 * The following structure is used to access and modify this parameter:
2794 *
2795 * struct sctp_assoc_value {
2796 * sctp_assoc_t assoc_id;
2797 * uint32_t assoc_value;
2798 * };
2799 *
2800 * assoc_id: This parameter is ignored for one-to-one style sockets.
2801 * For one-to-many style sockets this parameter indicates which
2802 * association the user is performing an action upon. Note that if
2803 * this field's value is zero then the endpoints default value is
2804 * changed (effecting future associations only).
2805 * assoc_value: This parameter specifies the maximum size in bytes.
2789 */ 2806 */
2790static int sctp_setsockopt_maxseg(struct sock *sk, char __user *optval, int optlen) 2807static int sctp_setsockopt_maxseg(struct sock *sk, char __user *optval, int optlen)
2791{ 2808{
2809 struct sctp_assoc_value params;
2792 struct sctp_association *asoc; 2810 struct sctp_association *asoc;
2793 struct sctp_sock *sp = sctp_sk(sk); 2811 struct sctp_sock *sp = sctp_sk(sk);
2794 int val; 2812 int val;
2795 2813
2796 if (optlen < sizeof(int)) 2814 if (optlen == sizeof(int)) {
2815 printk(KERN_WARNING
2816 "SCTP: Use of int in maxseg socket option deprecated\n");
2817 printk(KERN_WARNING
2818 "SCTP: Use struct sctp_assoc_value instead\n");
2819 if (copy_from_user(&val, optval, optlen))
2820 return -EFAULT;
2821 params.assoc_id = 0;
2822 } else if (optlen == sizeof(struct sctp_assoc_value)) {
2823 if (copy_from_user(&params, optval, optlen))
2824 return -EFAULT;
2825 val = params.assoc_value;
2826 } else
2797 return -EINVAL; 2827 return -EINVAL;
2798 if (get_user(val, (int __user *)optval)) 2828
2799 return -EFAULT;
2800 if ((val != 0) && ((val < 8) || (val > SCTP_MAX_CHUNK_LEN))) 2829 if ((val != 0) && ((val < 8) || (val > SCTP_MAX_CHUNK_LEN)))
2801 return -EINVAL; 2830 return -EINVAL;
2802 sp->user_frag = val;
2803 2831
2804 /* Update the frag_point of the existing associations. */ 2832 asoc = sctp_id2assoc(sk, params.assoc_id);
2805 list_for_each_entry(asoc, &(sp->ep->asocs), asocs) { 2833 if (!asoc && params.assoc_id && sctp_style(sk, UDP))
2806 asoc->frag_point = sctp_frag_point(sp, asoc->pathmtu); 2834 return -EINVAL;
2835
2836 if (asoc) {
2837 if (val == 0) {
2838 val = asoc->pathmtu;
2839 val -= sp->pf->af->net_header_len;
2840 val -= sizeof(struct sctphdr) +
2841 sizeof(struct sctp_data_chunk);
2842 }
2843
2844 asoc->frag_point = val;
2845 } else {
2846 sp->user_frag = val;
2847
2848 /* Update the frag_point of the existing associations. */
2849 list_for_each_entry(asoc, &(sp->ep->asocs), asocs) {
2850 asoc->frag_point = sctp_frag_point(sp, asoc->pathmtu);
2851 }
2807 } 2852 }
2808 2853
2809 return 0; 2854 return 0;
@@ -2965,14 +3010,21 @@ static int sctp_setsockopt_fragment_interleave(struct sock *sk,
2965} 3010}
2966 3011
2967/* 3012/*
2968 * 7.1.25. Set or Get the sctp partial delivery point 3013 * 8.1.21. Set or Get the SCTP Partial Delivery Point
2969 * (SCTP_PARTIAL_DELIVERY_POINT) 3014 * (SCTP_PARTIAL_DELIVERY_POINT)
3015 *
2970 * This option will set or get the SCTP partial delivery point. This 3016 * This option will set or get the SCTP partial delivery point. This
2971 * point is the size of a message where the partial delivery API will be 3017 * point is the size of a message where the partial delivery API will be
2972 * invoked to help free up rwnd space for the peer. Setting this to a 3018 * invoked to help free up rwnd space for the peer. Setting this to a
2973 * lower value will cause partial delivery's to happen more often. The 3019 * lower value will cause partial deliveries to happen more often. The
2974 * calls argument is an integer that sets or gets the partial delivery 3020 * calls argument is an integer that sets or gets the partial delivery
2975 * point. 3021 * point. Note also that the call will fail if the user attempts to set
3022 * this value larger than the socket receive buffer size.
3023 *
3024 * Note that any single message having a length smaller than or equal to
3025 * the SCTP partial delivery point will be delivered in one single read
3026 * call as long as the user provided buffer is large enough to hold the
3027 * message.
2976 */ 3028 */
2977static int sctp_setsockopt_partial_delivery_point(struct sock *sk, 3029static int sctp_setsockopt_partial_delivery_point(struct sock *sk,
2978 char __user *optval, 3030 char __user *optval,
@@ -2985,6 +3037,12 @@ static int sctp_setsockopt_partial_delivery_point(struct sock *sk,
2985 if (get_user(val, (int __user *)optval)) 3037 if (get_user(val, (int __user *)optval))
2986 return -EFAULT; 3038 return -EFAULT;
2987 3039
3040 /* Note: We double the receive buffer from what the user sets
3041 * it to be, also initial rwnd is based on rcvbuf/2.
3042 */
3043 if (val > (sk->sk_rcvbuf >> 1))
3044 return -EINVAL;
3045
2988 sctp_sk(sk)->pd_point = val; 3046 sctp_sk(sk)->pd_point = val;
2989 3047
2990 return 0; /* is this the right error code? */ 3048 return 0; /* is this the right error code? */
@@ -3613,7 +3671,12 @@ SCTP_STATIC int sctp_init_sock(struct sock *sk)
3613 sp->hmac = NULL; 3671 sp->hmac = NULL;
3614 3672
3615 SCTP_DBG_OBJCNT_INC(sock); 3673 SCTP_DBG_OBJCNT_INC(sock);
3616 atomic_inc(&sctp_sockets_allocated); 3674 percpu_counter_inc(&sctp_sockets_allocated);
3675
3676 local_bh_disable();
3677 sock_prot_inuse_add(sock_net(sk), sk->sk_prot, 1);
3678 local_bh_enable();
3679
3617 return 0; 3680 return 0;
3618} 3681}
3619 3682
@@ -3627,7 +3690,10 @@ SCTP_STATIC void sctp_destroy_sock(struct sock *sk)
3627 /* Release our hold on the endpoint. */ 3690 /* Release our hold on the endpoint. */
3628 ep = sctp_sk(sk)->ep; 3691 ep = sctp_sk(sk)->ep;
3629 sctp_endpoint_free(ep); 3692 sctp_endpoint_free(ep);
3630 atomic_dec(&sctp_sockets_allocated); 3693 percpu_counter_dec(&sctp_sockets_allocated);
3694 local_bh_disable();
3695 sock_prot_inuse_add(sock_net(sk), sk->sk_prot, -1);
3696 local_bh_enable();
3631} 3697}
3632 3698
3633/* API 4.1.7 shutdown() - TCP Style Syntax 3699/* API 4.1.7 shutdown() - TCP Style Syntax
@@ -4168,9 +4234,9 @@ static int sctp_getsockopt_delayed_ack(struct sock *sk, int len,
4168 if (copy_from_user(&params, optval, len)) 4234 if (copy_from_user(&params, optval, len))
4169 return -EFAULT; 4235 return -EFAULT;
4170 } else if (len == sizeof(struct sctp_assoc_value)) { 4236 } else if (len == sizeof(struct sctp_assoc_value)) {
4171 printk(KERN_WARNING "SCTP: Use of struct sctp_sack_info " 4237 printk(KERN_WARNING "SCTP: Use of struct sctp_assoc_value "
4172 "in delayed_ack socket option deprecated\n"); 4238 "in delayed_ack socket option deprecated\n");
4173 printk(KERN_WARNING "SCTP: struct sctp_sack_info instead\n"); 4239 printk(KERN_WARNING "SCTP: Use struct sctp_sack_info instead\n");
4174 if (copy_from_user(&params, optval, len)) 4240 if (copy_from_user(&params, optval, len))
4175 return -EFAULT; 4241 return -EFAULT;
4176 } else 4242 } else
@@ -5092,30 +5158,69 @@ static int sctp_getsockopt_context(struct sock *sk, int len,
5092} 5158}
5093 5159
5094/* 5160/*
5095 * 7.1.17 Set the maximum fragrmentation size (SCTP_MAXSEG) 5161 * 8.1.16. Get or Set the Maximum Fragmentation Size (SCTP_MAXSEG)
5096 * 5162 * This option will get or set the maximum size to put in any outgoing
5097 * This socket option specifies the maximum size to put in any outgoing 5163 * SCTP DATA chunk. If a message is larger than this size it will be
5098 * SCTP chunk. If a message is larger than this size it will be
5099 * fragmented by SCTP into the specified size. Note that the underlying 5164 * fragmented by SCTP into the specified size. Note that the underlying
5100 * SCTP implementation may fragment into smaller sized chunks when the 5165 * SCTP implementation may fragment into smaller sized chunks when the
5101 * PMTU of the underlying association is smaller than the value set by 5166 * PMTU of the underlying association is smaller than the value set by
5102 * the user. 5167 * the user. The default value for this option is '0' which indicates
5168 * the user is NOT limiting fragmentation and only the PMTU will effect
5169 * SCTP's choice of DATA chunk size. Note also that values set larger
5170 * than the maximum size of an IP datagram will effectively let SCTP
5171 * control fragmentation (i.e. the same as setting this option to 0).
5172 *
5173 * The following structure is used to access and modify this parameter:
5174 *
5175 * struct sctp_assoc_value {
5176 * sctp_assoc_t assoc_id;
5177 * uint32_t assoc_value;
5178 * };
5179 *
5180 * assoc_id: This parameter is ignored for one-to-one style sockets.
5181 * For one-to-many style sockets this parameter indicates which
5182 * association the user is performing an action upon. Note that if
5183 * this field's value is zero then the endpoints default value is
5184 * changed (effecting future associations only).
5185 * assoc_value: This parameter specifies the maximum size in bytes.
5103 */ 5186 */
5104static int sctp_getsockopt_maxseg(struct sock *sk, int len, 5187static int sctp_getsockopt_maxseg(struct sock *sk, int len,
5105 char __user *optval, int __user *optlen) 5188 char __user *optval, int __user *optlen)
5106{ 5189{
5107 int val; 5190 struct sctp_assoc_value params;
5191 struct sctp_association *asoc;
5108 5192
5109 if (len < sizeof(int)) 5193 if (len == sizeof(int)) {
5194 printk(KERN_WARNING
5195 "SCTP: Use of int in maxseg socket option deprecated\n");
5196 printk(KERN_WARNING
5197 "SCTP: Use struct sctp_assoc_value instead\n");
5198 params.assoc_id = 0;
5199 } else if (len >= sizeof(struct sctp_assoc_value)) {
5200 len = sizeof(struct sctp_assoc_value);
5201 if (copy_from_user(&params, optval, sizeof(params)))
5202 return -EFAULT;
5203 } else
5110 return -EINVAL; 5204 return -EINVAL;
5111 5205
5112 len = sizeof(int); 5206 asoc = sctp_id2assoc(sk, params.assoc_id);
5207 if (!asoc && params.assoc_id && sctp_style(sk, UDP))
5208 return -EINVAL;
5209
5210 if (asoc)
5211 params.assoc_value = asoc->frag_point;
5212 else
5213 params.assoc_value = sctp_sk(sk)->user_frag;
5113 5214
5114 val = sctp_sk(sk)->user_frag;
5115 if (put_user(len, optlen)) 5215 if (put_user(len, optlen))
5116 return -EFAULT; 5216 return -EFAULT;
5117 if (copy_to_user(optval, &val, len)) 5217 if (len == sizeof(int)) {
5118 return -EFAULT; 5218 if (copy_to_user(optval, &params.assoc_value, len))
5219 return -EFAULT;
5220 } else {
5221 if (copy_to_user(optval, &params, len))
5222 return -EFAULT;
5223 }
5119 5224
5120 return 0; 5225 return 0;
5121} 5226}
@@ -5368,6 +5473,38 @@ num:
5368 return 0; 5473 return 0;
5369} 5474}
5370 5475
5476/*
5477 * 8.2.5. Get the Current Number of Associations (SCTP_GET_ASSOC_NUMBER)
5478 * This option gets the current number of associations that are attached
5479 * to a one-to-many style socket. The option value is an uint32_t.
5480 */
5481static int sctp_getsockopt_assoc_number(struct sock *sk, int len,
5482 char __user *optval, int __user *optlen)
5483{
5484 struct sctp_sock *sp = sctp_sk(sk);
5485 struct sctp_association *asoc;
5486 u32 val = 0;
5487
5488 if (sctp_style(sk, TCP))
5489 return -EOPNOTSUPP;
5490
5491 if (len < sizeof(u32))
5492 return -EINVAL;
5493
5494 len = sizeof(u32);
5495
5496 list_for_each_entry(asoc, &(sp->ep->asocs), asocs) {
5497 val++;
5498 }
5499
5500 if (put_user(len, optlen))
5501 return -EFAULT;
5502 if (copy_to_user(optval, &val, len))
5503 return -EFAULT;
5504
5505 return 0;
5506}
5507
5371SCTP_STATIC int sctp_getsockopt(struct sock *sk, int level, int optname, 5508SCTP_STATIC int sctp_getsockopt(struct sock *sk, int level, int optname,
5372 char __user *optval, int __user *optlen) 5509 char __user *optval, int __user *optlen)
5373{ 5510{
@@ -5510,6 +5647,9 @@ SCTP_STATIC int sctp_getsockopt(struct sock *sk, int level, int optname,
5510 retval = sctp_getsockopt_local_auth_chunks(sk, len, optval, 5647 retval = sctp_getsockopt_local_auth_chunks(sk, len, optval,
5511 optlen); 5648 optlen);
5512 break; 5649 break;
5650 case SCTP_GET_ASSOC_NUMBER:
5651 retval = sctp_getsockopt_assoc_number(sk, len, optval, optlen);
5652 break;
5513 default: 5653 default:
5514 retval = -ENOPROTOOPT; 5654 retval = -ENOPROTOOPT;
5515 break; 5655 break;
diff --git a/net/sctp/sysctl.c b/net/sctp/sysctl.c
index 52910697e104..f58e994e6852 100644
--- a/net/sctp/sysctl.c
+++ b/net/sctp/sysctl.c
@@ -63,8 +63,8 @@ static ctl_table sctp_table[] = {
63 .data = &sctp_rto_initial, 63 .data = &sctp_rto_initial,
64 .maxlen = sizeof(unsigned int), 64 .maxlen = sizeof(unsigned int),
65 .mode = 0644, 65 .mode = 0644,
66 .proc_handler = &proc_dointvec_minmax, 66 .proc_handler = proc_dointvec_minmax,
67 .strategy = &sysctl_intvec, 67 .strategy = sysctl_intvec,
68 .extra1 = &one, 68 .extra1 = &one,
69 .extra2 = &timer_max 69 .extra2 = &timer_max
70 }, 70 },
@@ -74,8 +74,8 @@ static ctl_table sctp_table[] = {
74 .data = &sctp_rto_min, 74 .data = &sctp_rto_min,
75 .maxlen = sizeof(unsigned int), 75 .maxlen = sizeof(unsigned int),
76 .mode = 0644, 76 .mode = 0644,
77 .proc_handler = &proc_dointvec_minmax, 77 .proc_handler = proc_dointvec_minmax,
78 .strategy = &sysctl_intvec, 78 .strategy = sysctl_intvec,
79 .extra1 = &one, 79 .extra1 = &one,
80 .extra2 = &timer_max 80 .extra2 = &timer_max
81 }, 81 },
@@ -85,8 +85,8 @@ static ctl_table sctp_table[] = {
85 .data = &sctp_rto_max, 85 .data = &sctp_rto_max,
86 .maxlen = sizeof(unsigned int), 86 .maxlen = sizeof(unsigned int),
87 .mode = 0644, 87 .mode = 0644,
88 .proc_handler = &proc_dointvec_minmax, 88 .proc_handler = proc_dointvec_minmax,
89 .strategy = &sysctl_intvec, 89 .strategy = sysctl_intvec,
90 .extra1 = &one, 90 .extra1 = &one,
91 .extra2 = &timer_max 91 .extra2 = &timer_max
92 }, 92 },
@@ -96,8 +96,8 @@ static ctl_table sctp_table[] = {
96 .data = &sctp_valid_cookie_life, 96 .data = &sctp_valid_cookie_life,
97 .maxlen = sizeof(unsigned int), 97 .maxlen = sizeof(unsigned int),
98 .mode = 0644, 98 .mode = 0644,
99 .proc_handler = &proc_dointvec_minmax, 99 .proc_handler = proc_dointvec_minmax,
100 .strategy = &sysctl_intvec, 100 .strategy = sysctl_intvec,
101 .extra1 = &one, 101 .extra1 = &one,
102 .extra2 = &timer_max 102 .extra2 = &timer_max
103 }, 103 },
@@ -107,8 +107,8 @@ static ctl_table sctp_table[] = {
107 .data = &sctp_max_burst, 107 .data = &sctp_max_burst,
108 .maxlen = sizeof(int), 108 .maxlen = sizeof(int),
109 .mode = 0644, 109 .mode = 0644,
110 .proc_handler = &proc_dointvec_minmax, 110 .proc_handler = proc_dointvec_minmax,
111 .strategy = &sysctl_intvec, 111 .strategy = sysctl_intvec,
112 .extra1 = &zero, 112 .extra1 = &zero,
113 .extra2 = &int_max 113 .extra2 = &int_max
114 }, 114 },
@@ -118,8 +118,8 @@ static ctl_table sctp_table[] = {
118 .data = &sctp_max_retrans_association, 118 .data = &sctp_max_retrans_association,
119 .maxlen = sizeof(int), 119 .maxlen = sizeof(int),
120 .mode = 0644, 120 .mode = 0644,
121 .proc_handler = &proc_dointvec_minmax, 121 .proc_handler = proc_dointvec_minmax,
122 .strategy = &sysctl_intvec, 122 .strategy = sysctl_intvec,
123 .extra1 = &one, 123 .extra1 = &one,
124 .extra2 = &int_max 124 .extra2 = &int_max
125 }, 125 },
@@ -129,8 +129,8 @@ static ctl_table sctp_table[] = {
129 .data = &sctp_sndbuf_policy, 129 .data = &sctp_sndbuf_policy,
130 .maxlen = sizeof(int), 130 .maxlen = sizeof(int),
131 .mode = 0644, 131 .mode = 0644,
132 .proc_handler = &proc_dointvec, 132 .proc_handler = proc_dointvec,
133 .strategy = &sysctl_intvec 133 .strategy = sysctl_intvec
134 }, 134 },
135 { 135 {
136 .ctl_name = NET_SCTP_RCVBUF_POLICY, 136 .ctl_name = NET_SCTP_RCVBUF_POLICY,
@@ -138,8 +138,8 @@ static ctl_table sctp_table[] = {
138 .data = &sctp_rcvbuf_policy, 138 .data = &sctp_rcvbuf_policy,
139 .maxlen = sizeof(int), 139 .maxlen = sizeof(int),
140 .mode = 0644, 140 .mode = 0644,
141 .proc_handler = &proc_dointvec, 141 .proc_handler = proc_dointvec,
142 .strategy = &sysctl_intvec 142 .strategy = sysctl_intvec
143 }, 143 },
144 { 144 {
145 .ctl_name = NET_SCTP_PATH_MAX_RETRANS, 145 .ctl_name = NET_SCTP_PATH_MAX_RETRANS,
@@ -147,8 +147,8 @@ static ctl_table sctp_table[] = {
147 .data = &sctp_max_retrans_path, 147 .data = &sctp_max_retrans_path,
148 .maxlen = sizeof(int), 148 .maxlen = sizeof(int),
149 .mode = 0644, 149 .mode = 0644,
150 .proc_handler = &proc_dointvec_minmax, 150 .proc_handler = proc_dointvec_minmax,
151 .strategy = &sysctl_intvec, 151 .strategy = sysctl_intvec,
152 .extra1 = &one, 152 .extra1 = &one,
153 .extra2 = &int_max 153 .extra2 = &int_max
154 }, 154 },
@@ -158,8 +158,8 @@ static ctl_table sctp_table[] = {
158 .data = &sctp_max_retrans_init, 158 .data = &sctp_max_retrans_init,
159 .maxlen = sizeof(int), 159 .maxlen = sizeof(int),
160 .mode = 0644, 160 .mode = 0644,
161 .proc_handler = &proc_dointvec_minmax, 161 .proc_handler = proc_dointvec_minmax,
162 .strategy = &sysctl_intvec, 162 .strategy = sysctl_intvec,
163 .extra1 = &one, 163 .extra1 = &one,
164 .extra2 = &int_max 164 .extra2 = &int_max
165 }, 165 },
@@ -169,8 +169,8 @@ static ctl_table sctp_table[] = {
169 .data = &sctp_hb_interval, 169 .data = &sctp_hb_interval,
170 .maxlen = sizeof(unsigned int), 170 .maxlen = sizeof(unsigned int),
171 .mode = 0644, 171 .mode = 0644,
172 .proc_handler = &proc_dointvec_minmax, 172 .proc_handler = proc_dointvec_minmax,
173 .strategy = &sysctl_intvec, 173 .strategy = sysctl_intvec,
174 .extra1 = &one, 174 .extra1 = &one,
175 .extra2 = &timer_max 175 .extra2 = &timer_max
176 }, 176 },
@@ -180,8 +180,8 @@ static ctl_table sctp_table[] = {
180 .data = &sctp_cookie_preserve_enable, 180 .data = &sctp_cookie_preserve_enable,
181 .maxlen = sizeof(int), 181 .maxlen = sizeof(int),
182 .mode = 0644, 182 .mode = 0644,
183 .proc_handler = &proc_dointvec, 183 .proc_handler = proc_dointvec,
184 .strategy = &sysctl_intvec 184 .strategy = sysctl_intvec
185 }, 185 },
186 { 186 {
187 .ctl_name = NET_SCTP_RTO_ALPHA, 187 .ctl_name = NET_SCTP_RTO_ALPHA,
@@ -189,8 +189,8 @@ static ctl_table sctp_table[] = {
189 .data = &sctp_rto_alpha, 189 .data = &sctp_rto_alpha,
190 .maxlen = sizeof(int), 190 .maxlen = sizeof(int),
191 .mode = 0444, 191 .mode = 0444,
192 .proc_handler = &proc_dointvec, 192 .proc_handler = proc_dointvec,
193 .strategy = &sysctl_intvec 193 .strategy = sysctl_intvec
194 }, 194 },
195 { 195 {
196 .ctl_name = NET_SCTP_RTO_BETA, 196 .ctl_name = NET_SCTP_RTO_BETA,
@@ -198,8 +198,8 @@ static ctl_table sctp_table[] = {
198 .data = &sctp_rto_beta, 198 .data = &sctp_rto_beta,
199 .maxlen = sizeof(int), 199 .maxlen = sizeof(int),
200 .mode = 0444, 200 .mode = 0444,
201 .proc_handler = &proc_dointvec, 201 .proc_handler = proc_dointvec,
202 .strategy = &sysctl_intvec 202 .strategy = sysctl_intvec
203 }, 203 },
204 { 204 {
205 .ctl_name = NET_SCTP_ADDIP_ENABLE, 205 .ctl_name = NET_SCTP_ADDIP_ENABLE,
@@ -207,8 +207,8 @@ static ctl_table sctp_table[] = {
207 .data = &sctp_addip_enable, 207 .data = &sctp_addip_enable,
208 .maxlen = sizeof(int), 208 .maxlen = sizeof(int),
209 .mode = 0644, 209 .mode = 0644,
210 .proc_handler = &proc_dointvec, 210 .proc_handler = proc_dointvec,
211 .strategy = &sysctl_intvec 211 .strategy = sysctl_intvec
212 }, 212 },
213 { 213 {
214 .ctl_name = NET_SCTP_PRSCTP_ENABLE, 214 .ctl_name = NET_SCTP_PRSCTP_ENABLE,
@@ -216,8 +216,8 @@ static ctl_table sctp_table[] = {
216 .data = &sctp_prsctp_enable, 216 .data = &sctp_prsctp_enable,
217 .maxlen = sizeof(int), 217 .maxlen = sizeof(int),
218 .mode = 0644, 218 .mode = 0644,
219 .proc_handler = &proc_dointvec, 219 .proc_handler = proc_dointvec,
220 .strategy = &sysctl_intvec 220 .strategy = sysctl_intvec
221 }, 221 },
222 { 222 {
223 .ctl_name = NET_SCTP_SACK_TIMEOUT, 223 .ctl_name = NET_SCTP_SACK_TIMEOUT,
@@ -225,8 +225,8 @@ static ctl_table sctp_table[] = {
225 .data = &sctp_sack_timeout, 225 .data = &sctp_sack_timeout,
226 .maxlen = sizeof(long), 226 .maxlen = sizeof(long),
227 .mode = 0644, 227 .mode = 0644,
228 .proc_handler = &proc_dointvec_minmax, 228 .proc_handler = proc_dointvec_minmax,
229 .strategy = &sysctl_intvec, 229 .strategy = sysctl_intvec,
230 .extra1 = &sack_timer_min, 230 .extra1 = &sack_timer_min,
231 .extra2 = &sack_timer_max, 231 .extra2 = &sack_timer_max,
232 }, 232 },
@@ -236,7 +236,7 @@ static ctl_table sctp_table[] = {
236 .data = &sysctl_sctp_mem, 236 .data = &sysctl_sctp_mem,
237 .maxlen = sizeof(sysctl_sctp_mem), 237 .maxlen = sizeof(sysctl_sctp_mem),
238 .mode = 0644, 238 .mode = 0644,
239 .proc_handler = &proc_dointvec, 239 .proc_handler = proc_dointvec,
240 }, 240 },
241 { 241 {
242 .ctl_name = CTL_UNNUMBERED, 242 .ctl_name = CTL_UNNUMBERED,
@@ -244,7 +244,7 @@ static ctl_table sctp_table[] = {
244 .data = &sysctl_sctp_rmem, 244 .data = &sysctl_sctp_rmem,
245 .maxlen = sizeof(sysctl_sctp_rmem), 245 .maxlen = sizeof(sysctl_sctp_rmem),
246 .mode = 0644, 246 .mode = 0644,
247 .proc_handler = &proc_dointvec, 247 .proc_handler = proc_dointvec,
248 }, 248 },
249 { 249 {
250 .ctl_name = CTL_UNNUMBERED, 250 .ctl_name = CTL_UNNUMBERED,
@@ -252,7 +252,7 @@ static ctl_table sctp_table[] = {
252 .data = &sysctl_sctp_wmem, 252 .data = &sysctl_sctp_wmem,
253 .maxlen = sizeof(sysctl_sctp_wmem), 253 .maxlen = sizeof(sysctl_sctp_wmem),
254 .mode = 0644, 254 .mode = 0644,
255 .proc_handler = &proc_dointvec, 255 .proc_handler = proc_dointvec,
256 }, 256 },
257 { 257 {
258 .ctl_name = CTL_UNNUMBERED, 258 .ctl_name = CTL_UNNUMBERED,
@@ -260,8 +260,8 @@ static ctl_table sctp_table[] = {
260 .data = &sctp_auth_enable, 260 .data = &sctp_auth_enable,
261 .maxlen = sizeof(int), 261 .maxlen = sizeof(int),
262 .mode = 0644, 262 .mode = 0644,
263 .proc_handler = &proc_dointvec, 263 .proc_handler = proc_dointvec,
264 .strategy = &sysctl_intvec 264 .strategy = sysctl_intvec
265 }, 265 },
266 { 266 {
267 .ctl_name = CTL_UNNUMBERED, 267 .ctl_name = CTL_UNNUMBERED,
@@ -269,8 +269,8 @@ static ctl_table sctp_table[] = {
269 .data = &sctp_addip_noauth, 269 .data = &sctp_addip_noauth,
270 .maxlen = sizeof(int), 270 .maxlen = sizeof(int),
271 .mode = 0644, 271 .mode = 0644,
272 .proc_handler = &proc_dointvec, 272 .proc_handler = proc_dointvec,
273 .strategy = &sysctl_intvec 273 .strategy = sysctl_intvec
274 }, 274 },
275 { .ctl_name = 0 } 275 { .ctl_name = 0 }
276}; 276};
diff --git a/net/socket.c b/net/socket.c
index 072e2e525ae6..2c730fc718ab 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -69,7 +69,6 @@
69#include <linux/proc_fs.h> 69#include <linux/proc_fs.h>
70#include <linux/seq_file.h> 70#include <linux/seq_file.h>
71#include <linux/mutex.h> 71#include <linux/mutex.h>
72#include <linux/thread_info.h>
73#include <linux/wanrouter.h> 72#include <linux/wanrouter.h>
74#include <linux/if_bridge.h> 73#include <linux/if_bridge.h>
75#include <linux/if_frad.h> 74#include <linux/if_frad.h>
diff --git a/net/sunrpc/clnt.c b/net/sunrpc/clnt.c
index 4895c341e46d..3ca518386d15 100644
--- a/net/sunrpc/clnt.c
+++ b/net/sunrpc/clnt.c
@@ -271,15 +271,15 @@ struct rpc_clnt *rpc_create(struct rpc_create_args *args)
271 case AF_INET: { 271 case AF_INET: {
272 struct sockaddr_in *sin = 272 struct sockaddr_in *sin =
273 (struct sockaddr_in *)args->address; 273 (struct sockaddr_in *)args->address;
274 snprintf(servername, sizeof(servername), NIPQUAD_FMT, 274 snprintf(servername, sizeof(servername), "%pI4",
275 NIPQUAD(sin->sin_addr.s_addr)); 275 &sin->sin_addr.s_addr);
276 break; 276 break;
277 } 277 }
278 case AF_INET6: { 278 case AF_INET6: {
279 struct sockaddr_in6 *sin = 279 struct sockaddr_in6 *sin =
280 (struct sockaddr_in6 *)args->address; 280 (struct sockaddr_in6 *)args->address;
281 snprintf(servername, sizeof(servername), NIP6_FMT, 281 snprintf(servername, sizeof(servername), "%pI6",
282 NIP6(sin->sin6_addr)); 282 &sin->sin6_addr);
283 break; 283 break;
284 } 284 }
285 default: 285 default:
diff --git a/net/sunrpc/rpcb_clnt.c b/net/sunrpc/rpcb_clnt.c
index 41013dd66ac3..03ae007641e4 100644
--- a/net/sunrpc/rpcb_clnt.c
+++ b/net/sunrpc/rpcb_clnt.c
@@ -270,10 +270,9 @@ static int rpcb_register_netid4(struct sockaddr_in *address_to_register,
270 char buf[32]; 270 char buf[32];
271 271
272 /* Construct AF_INET universal address */ 272 /* Construct AF_INET universal address */
273 snprintf(buf, sizeof(buf), 273 snprintf(buf, sizeof(buf), "%pI4.%u.%u",
274 NIPQUAD_FMT".%u.%u", 274 &address_to_register->sin_addr.s_addr,
275 NIPQUAD(address_to_register->sin_addr.s_addr), 275 port >> 8, port & 0xff);
276 port >> 8, port & 0xff);
277 map->r_addr = buf; 276 map->r_addr = buf;
278 277
279 dprintk("RPC: %sregistering [%u, %u, %s, '%s'] with " 278 dprintk("RPC: %sregistering [%u, %u, %s, '%s'] with "
@@ -305,9 +304,9 @@ static int rpcb_register_netid6(struct sockaddr_in6 *address_to_register,
305 snprintf(buf, sizeof(buf), "::.%u.%u", 304 snprintf(buf, sizeof(buf), "::.%u.%u",
306 port >> 8, port & 0xff); 305 port >> 8, port & 0xff);
307 else 306 else
308 snprintf(buf, sizeof(buf), NIP6_FMT".%u.%u", 307 snprintf(buf, sizeof(buf), "%pI6.%u.%u",
309 NIP6(address_to_register->sin6_addr), 308 &address_to_register->sin6_addr,
310 port >> 8, port & 0xff); 309 port >> 8, port & 0xff);
311 map->r_addr = buf; 310 map->r_addr = buf;
312 311
313 dprintk("RPC: %sregistering [%u, %u, %s, '%s'] with " 312 dprintk("RPC: %sregistering [%u, %u, %s, '%s'] with "
@@ -422,8 +421,8 @@ int rpcb_getport_sync(struct sockaddr_in *sin, u32 prog, u32 vers, int prot)
422 struct rpc_clnt *rpcb_clnt; 421 struct rpc_clnt *rpcb_clnt;
423 int status; 422 int status;
424 423
425 dprintk("RPC: %s(" NIPQUAD_FMT ", %u, %u, %d)\n", 424 dprintk("RPC: %s(%pI4, %u, %u, %d)\n",
426 __func__, NIPQUAD(sin->sin_addr.s_addr), prog, vers, prot); 425 __func__, &sin->sin_addr.s_addr, prog, vers, prot);
427 426
428 rpcb_clnt = rpcb_create(NULL, (struct sockaddr *)sin, 427 rpcb_clnt = rpcb_create(NULL, (struct sockaddr *)sin,
429 sizeof(*sin), prot, RPCBVERS_2); 428 sizeof(*sin), prot, RPCBVERS_2);
diff --git a/net/sunrpc/svcauth_unix.c b/net/sunrpc/svcauth_unix.c
index f24800f2c098..82240e6127b2 100644
--- a/net/sunrpc/svcauth_unix.c
+++ b/net/sunrpc/svcauth_unix.c
@@ -162,13 +162,9 @@ static void ip_map_request(struct cache_detail *cd,
162 struct ip_map *im = container_of(h, struct ip_map, h); 162 struct ip_map *im = container_of(h, struct ip_map, h);
163 163
164 if (ipv6_addr_v4mapped(&(im->m_addr))) { 164 if (ipv6_addr_v4mapped(&(im->m_addr))) {
165 snprintf(text_addr, 20, NIPQUAD_FMT, 165 snprintf(text_addr, 20, "%pI4", &im->m_addr.s6_addr32[3]);
166 ntohl(im->m_addr.s6_addr32[3]) >> 24 & 0xff,
167 ntohl(im->m_addr.s6_addr32[3]) >> 16 & 0xff,
168 ntohl(im->m_addr.s6_addr32[3]) >> 8 & 0xff,
169 ntohl(im->m_addr.s6_addr32[3]) >> 0 & 0xff);
170 } else { 166 } else {
171 snprintf(text_addr, 40, NIP6_FMT, NIP6(im->m_addr)); 167 snprintf(text_addr, 40, "%pI6", &im->m_addr);
172 } 168 }
173 qword_add(bpp, blen, im->m_class); 169 qword_add(bpp, blen, im->m_class);
174 qword_add(bpp, blen, text_addr); 170 qword_add(bpp, blen, text_addr);
@@ -208,13 +204,13 @@ static int ip_map_parse(struct cache_detail *cd,
208 len = qword_get(&mesg, buf, mlen); 204 len = qword_get(&mesg, buf, mlen);
209 if (len <= 0) return -EINVAL; 205 if (len <= 0) return -EINVAL;
210 206
211 if (sscanf(buf, NIPQUAD_FMT "%c", &b1, &b2, &b3, &b4, &c) == 4) { 207 if (sscanf(buf, "%u.%u.%u.%u%c", &b1, &b2, &b3, &b4, &c) == 4) {
212 addr.s6_addr32[0] = 0; 208 addr.s6_addr32[0] = 0;
213 addr.s6_addr32[1] = 0; 209 addr.s6_addr32[1] = 0;
214 addr.s6_addr32[2] = htonl(0xffff); 210 addr.s6_addr32[2] = htonl(0xffff);
215 addr.s6_addr32[3] = 211 addr.s6_addr32[3] =
216 htonl((((((b1<<8)|b2)<<8)|b3)<<8)|b4); 212 htonl((((((b1<<8)|b2)<<8)|b3)<<8)|b4);
217 } else if (sscanf(buf, NIP6_FMT "%c", 213 } else if (sscanf(buf, "%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x%c",
218 &b1, &b2, &b3, &b4, &b5, &b6, &b7, &b8, &c) == 8) { 214 &b1, &b2, &b3, &b4, &b5, &b6, &b7, &b8, &c) == 8) {
219 addr.s6_addr16[0] = htons(b1); 215 addr.s6_addr16[0] = htons(b1);
220 addr.s6_addr16[1] = htons(b2); 216 addr.s6_addr16[1] = htons(b2);
@@ -278,16 +274,10 @@ static int ip_map_show(struct seq_file *m,
278 dom = im->m_client->h.name; 274 dom = im->m_client->h.name;
279 275
280 if (ipv6_addr_v4mapped(&addr)) { 276 if (ipv6_addr_v4mapped(&addr)) {
281 seq_printf(m, "%s " NIPQUAD_FMT " %s\n", 277 seq_printf(m, "%s %pI4 %s\n",
282 im->m_class, 278 im->m_class, &addr.s6_addr32[3], dom);
283 ntohl(addr.s6_addr32[3]) >> 24 & 0xff,
284 ntohl(addr.s6_addr32[3]) >> 16 & 0xff,
285 ntohl(addr.s6_addr32[3]) >> 8 & 0xff,
286 ntohl(addr.s6_addr32[3]) >> 0 & 0xff,
287 dom);
288 } else { 279 } else {
289 seq_printf(m, "%s " NIP6_FMT " %s\n", 280 seq_printf(m, "%s %pI6 %s\n", im->m_class, &addr, dom);
290 im->m_class, NIP6(addr), dom);
291 } 281 }
292 return 0; 282 return 0;
293} 283}
diff --git a/net/sunrpc/svcsock.c b/net/sunrpc/svcsock.c
index a1951dcc5776..ef3238d665ee 100644
--- a/net/sunrpc/svcsock.c
+++ b/net/sunrpc/svcsock.c
@@ -250,10 +250,10 @@ static int one_sock_name(char *buf, struct svc_sock *svsk)
250 250
251 switch(svsk->sk_sk->sk_family) { 251 switch(svsk->sk_sk->sk_family) {
252 case AF_INET: 252 case AF_INET:
253 len = sprintf(buf, "ipv4 %s %u.%u.%u.%u %d\n", 253 len = sprintf(buf, "ipv4 %s %pI4 %d\n",
254 svsk->sk_sk->sk_protocol==IPPROTO_UDP? 254 svsk->sk_sk->sk_protocol == IPPROTO_UDP ?
255 "udp" : "tcp", 255 "udp" : "tcp",
256 NIPQUAD(inet_sk(svsk->sk_sk)->rcv_saddr), 256 &inet_sk(svsk->sk_sk)->rcv_saddr,
257 inet_sk(svsk->sk_sk)->num); 257 inet_sk(svsk->sk_sk)->num);
258 break; 258 break;
259 default: 259 default:
diff --git a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
index a4756576d687..629a28764da9 100644
--- a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
+++ b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
@@ -646,8 +646,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
646 ret = rdma_read_xdr(rdma_xprt, rmsgp, rqstp, ctxt); 646 ret = rdma_read_xdr(rdma_xprt, rmsgp, rqstp, ctxt);
647 if (ret > 0) { 647 if (ret > 0) {
648 /* read-list posted, defer until data received from client. */ 648 /* read-list posted, defer until data received from client. */
649 svc_xprt_received(xprt); 649 goto defer;
650 return 0;
651 } 650 }
652 if (ret < 0) { 651 if (ret < 0) {
653 /* Post of read-list failed, free context. */ 652 /* Post of read-list failed, free context. */
@@ -679,6 +678,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
679 * close bit and call svc_xprt_delete 678 * close bit and call svc_xprt_delete
680 */ 679 */
681 set_bit(XPT_CLOSE, &xprt->xpt_flags); 680 set_bit(XPT_CLOSE, &xprt->xpt_flags);
681defer:
682 svc_xprt_received(xprt); 682 svc_xprt_received(xprt);
683 return 0; 683 return 0;
684} 684}
diff --git a/net/sunrpc/xprtrdma/svc_rdma_sendto.c b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
index 9a7a8e7ae038..a3334e3b73cc 100644
--- a/net/sunrpc/xprtrdma/svc_rdma_sendto.c
+++ b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
@@ -69,7 +69,7 @@
69 * array is only concerned with the reply we are assured that we have 69 * array is only concerned with the reply we are assured that we have
70 * on extra page for the RPCRMDA header. 70 * on extra page for the RPCRMDA header.
71 */ 71 */
72int fast_reg_xdr(struct svcxprt_rdma *xprt, 72static int fast_reg_xdr(struct svcxprt_rdma *xprt,
73 struct xdr_buf *xdr, 73 struct xdr_buf *xdr,
74 struct svc_rdma_req_map *vec) 74 struct svc_rdma_req_map *vec)
75{ 75{
diff --git a/net/sunrpc/xprtrdma/svc_rdma_transport.c b/net/sunrpc/xprtrdma/svc_rdma_transport.c
index 6fb493cbd29f..3d810e7df3fb 100644
--- a/net/sunrpc/xprtrdma/svc_rdma_transport.c
+++ b/net/sunrpc/xprtrdma/svc_rdma_transport.c
@@ -61,7 +61,7 @@ static int svc_rdma_has_wspace(struct svc_xprt *xprt);
61static void rq_cq_reap(struct svcxprt_rdma *xprt); 61static void rq_cq_reap(struct svcxprt_rdma *xprt);
62static void sq_cq_reap(struct svcxprt_rdma *xprt); 62static void sq_cq_reap(struct svcxprt_rdma *xprt);
63 63
64DECLARE_TASKLET(dto_tasklet, dto_tasklet_func, 0UL); 64static DECLARE_TASKLET(dto_tasklet, dto_tasklet_func, 0UL);
65static DEFINE_SPINLOCK(dto_lock); 65static DEFINE_SPINLOCK(dto_lock);
66static LIST_HEAD(dto_xprt_q); 66static LIST_HEAD(dto_xprt_q);
67 67
@@ -827,7 +827,7 @@ static struct svc_xprt *svc_rdma_accept(struct svc_xprt *xprt)
827 struct rdma_conn_param conn_param; 827 struct rdma_conn_param conn_param;
828 struct ib_qp_init_attr qp_attr; 828 struct ib_qp_init_attr qp_attr;
829 struct ib_device_attr devattr; 829 struct ib_device_attr devattr;
830 int dma_mr_acc; 830 int uninitialized_var(dma_mr_acc);
831 int need_dma_mr; 831 int need_dma_mr;
832 int ret; 832 int ret;
833 int i; 833 int i;
@@ -1048,21 +1048,21 @@ static struct svc_xprt *svc_rdma_accept(struct svc_xprt *xprt)
1048 1048
1049 dprintk("svcrdma: new connection %p accepted with the following " 1049 dprintk("svcrdma: new connection %p accepted with the following "
1050 "attributes:\n" 1050 "attributes:\n"
1051 " local_ip : %d.%d.%d.%d\n" 1051 " local_ip : %pI4\n"
1052 " local_port : %d\n" 1052 " local_port : %d\n"
1053 " remote_ip : %d.%d.%d.%d\n" 1053 " remote_ip : %pI4\n"
1054 " remote_port : %d\n" 1054 " remote_port : %d\n"
1055 " max_sge : %d\n" 1055 " max_sge : %d\n"
1056 " sq_depth : %d\n" 1056 " sq_depth : %d\n"
1057 " max_requests : %d\n" 1057 " max_requests : %d\n"
1058 " ord : %d\n", 1058 " ord : %d\n",
1059 newxprt, 1059 newxprt,
1060 NIPQUAD(((struct sockaddr_in *)&newxprt->sc_cm_id-> 1060 &((struct sockaddr_in *)&newxprt->sc_cm_id->
1061 route.addr.src_addr)->sin_addr.s_addr), 1061 route.addr.src_addr)->sin_addr.s_addr,
1062 ntohs(((struct sockaddr_in *)&newxprt->sc_cm_id-> 1062 ntohs(((struct sockaddr_in *)&newxprt->sc_cm_id->
1063 route.addr.src_addr)->sin_port), 1063 route.addr.src_addr)->sin_port),
1064 NIPQUAD(((struct sockaddr_in *)&newxprt->sc_cm_id-> 1064 &((struct sockaddr_in *)&newxprt->sc_cm_id->
1065 route.addr.dst_addr)->sin_addr.s_addr), 1065 route.addr.dst_addr)->sin_addr.s_addr,
1066 ntohs(((struct sockaddr_in *)&newxprt->sc_cm_id-> 1066 ntohs(((struct sockaddr_in *)&newxprt->sc_cm_id->
1067 route.addr.dst_addr)->sin_port), 1067 route.addr.dst_addr)->sin_port),
1068 newxprt->sc_max_sge, 1068 newxprt->sc_max_sge,
diff --git a/net/sunrpc/xprtrdma/transport.c b/net/sunrpc/xprtrdma/transport.c
index 9839c3d94145..1dd6123070e9 100644
--- a/net/sunrpc/xprtrdma/transport.c
+++ b/net/sunrpc/xprtrdma/transport.c
@@ -174,7 +174,7 @@ xprt_rdma_format_addresses(struct rpc_xprt *xprt)
174 174
175 buf = kzalloc(20, GFP_KERNEL); 175 buf = kzalloc(20, GFP_KERNEL);
176 if (buf) 176 if (buf)
177 snprintf(buf, 20, NIPQUAD_FMT, NIPQUAD(addr->sin_addr.s_addr)); 177 snprintf(buf, 20, "%pI4", &addr->sin_addr.s_addr);
178 xprt->address_strings[RPC_DISPLAY_ADDR] = buf; 178 xprt->address_strings[RPC_DISPLAY_ADDR] = buf;
179 179
180 buf = kzalloc(8, GFP_KERNEL); 180 buf = kzalloc(8, GFP_KERNEL);
@@ -186,8 +186,8 @@ xprt_rdma_format_addresses(struct rpc_xprt *xprt)
186 186
187 buf = kzalloc(48, GFP_KERNEL); 187 buf = kzalloc(48, GFP_KERNEL);
188 if (buf) 188 if (buf)
189 snprintf(buf, 48, "addr="NIPQUAD_FMT" port=%u proto=%s", 189 snprintf(buf, 48, "addr=%pI4 port=%u proto=%s",
190 NIPQUAD(addr->sin_addr.s_addr), 190 &addr->sin_addr.s_addr,
191 ntohs(addr->sin_port), "rdma"); 191 ntohs(addr->sin_port), "rdma");
192 xprt->address_strings[RPC_DISPLAY_ALL] = buf; 192 xprt->address_strings[RPC_DISPLAY_ALL] = buf;
193 193
@@ -204,8 +204,8 @@ xprt_rdma_format_addresses(struct rpc_xprt *xprt)
204 204
205 buf = kzalloc(30, GFP_KERNEL); 205 buf = kzalloc(30, GFP_KERNEL);
206 if (buf) 206 if (buf)
207 snprintf(buf, 30, NIPQUAD_FMT".%u.%u", 207 snprintf(buf, 30, "%pI4.%u.%u",
208 NIPQUAD(addr->sin_addr.s_addr), 208 &addr->sin_addr.s_addr,
209 ntohs(addr->sin_port) >> 8, 209 ntohs(addr->sin_port) >> 8,
210 ntohs(addr->sin_port) & 0xff); 210 ntohs(addr->sin_port) & 0xff);
211 xprt->address_strings[RPC_DISPLAY_UNIVERSAL_ADDR] = buf; 211 xprt->address_strings[RPC_DISPLAY_UNIVERSAL_ADDR] = buf;
@@ -369,8 +369,8 @@ xprt_setup_rdma(struct xprt_create *args)
369 if (ntohs(sin->sin_port) != 0) 369 if (ntohs(sin->sin_port) != 0)
370 xprt_set_bound(xprt); 370 xprt_set_bound(xprt);
371 371
372 dprintk("RPC: %s: %u.%u.%u.%u:%u\n", __func__, 372 dprintk("RPC: %s: %pI4:%u\n",
373 NIPQUAD(sin->sin_addr.s_addr), ntohs(sin->sin_port)); 373 __func__, &sin->sin_addr.s_addr, ntohs(sin->sin_port));
374 374
375 /* Set max requests */ 375 /* Set max requests */
376 cdata.max_requests = xprt->max_reqs; 376 cdata.max_requests = xprt->max_reqs;
diff --git a/net/sunrpc/xprtrdma/verbs.c b/net/sunrpc/xprtrdma/verbs.c
index a5fef5e6c323..3b21e0cc5e69 100644
--- a/net/sunrpc/xprtrdma/verbs.c
+++ b/net/sunrpc/xprtrdma/verbs.c
@@ -276,7 +276,9 @@ rpcrdma_conn_upcall(struct rdma_cm_id *id, struct rdma_cm_event *event)
276 struct rpcrdma_xprt *xprt = id->context; 276 struct rpcrdma_xprt *xprt = id->context;
277 struct rpcrdma_ia *ia = &xprt->rx_ia; 277 struct rpcrdma_ia *ia = &xprt->rx_ia;
278 struct rpcrdma_ep *ep = &xprt->rx_ep; 278 struct rpcrdma_ep *ep = &xprt->rx_ep;
279#ifdef RPC_DEBUG
279 struct sockaddr_in *addr = (struct sockaddr_in *) &ep->rep_remote_addr; 280 struct sockaddr_in *addr = (struct sockaddr_in *) &ep->rep_remote_addr;
281#endif
280 struct ib_qp_attr attr; 282 struct ib_qp_attr attr;
281 struct ib_qp_init_attr iattr; 283 struct ib_qp_init_attr iattr;
282 int connstate = 0; 284 int connstate = 0;
@@ -323,12 +325,11 @@ rpcrdma_conn_upcall(struct rdma_cm_id *id, struct rdma_cm_event *event)
323 case RDMA_CM_EVENT_DEVICE_REMOVAL: 325 case RDMA_CM_EVENT_DEVICE_REMOVAL:
324 connstate = -ENODEV; 326 connstate = -ENODEV;
325connected: 327connected:
326 dprintk("RPC: %s: %s: %u.%u.%u.%u:%u" 328 dprintk("RPC: %s: %s: %pI4:%u (ep 0x%p event 0x%x)\n",
327 " (ep 0x%p event 0x%x)\n",
328 __func__, 329 __func__,
329 (event->event <= 11) ? conn[event->event] : 330 (event->event <= 11) ? conn[event->event] :
330 "unknown connection error", 331 "unknown connection error",
331 NIPQUAD(addr->sin_addr.s_addr), 332 &addr->sin_addr.s_addr,
332 ntohs(addr->sin_port), 333 ntohs(addr->sin_port),
333 ep, event->event); 334 ep, event->event);
334 atomic_set(&rpcx_to_rdmax(ep->rep_xprt)->rx_buf.rb_credits, 1); 335 atomic_set(&rpcx_to_rdmax(ep->rep_xprt)->rx_buf.rb_credits, 1);
@@ -348,18 +349,17 @@ connected:
348 if (connstate == 1) { 349 if (connstate == 1) {
349 int ird = attr.max_dest_rd_atomic; 350 int ird = attr.max_dest_rd_atomic;
350 int tird = ep->rep_remote_cma.responder_resources; 351 int tird = ep->rep_remote_cma.responder_resources;
351 printk(KERN_INFO "rpcrdma: connection to %u.%u.%u.%u:%u " 352 printk(KERN_INFO "rpcrdma: connection to %pI4:%u "
352 "on %s, memreg %d slots %d ird %d%s\n", 353 "on %s, memreg %d slots %d ird %d%s\n",
353 NIPQUAD(addr->sin_addr.s_addr), 354 &addr->sin_addr.s_addr,
354 ntohs(addr->sin_port), 355 ntohs(addr->sin_port),
355 ia->ri_id->device->name, 356 ia->ri_id->device->name,
356 ia->ri_memreg_strategy, 357 ia->ri_memreg_strategy,
357 xprt->rx_buf.rb_max_requests, 358 xprt->rx_buf.rb_max_requests,
358 ird, ird < 4 && ird < tird / 2 ? " (low!)" : ""); 359 ird, ird < 4 && ird < tird / 2 ? " (low!)" : "");
359 } else if (connstate < 0) { 360 } else if (connstate < 0) {
360 printk(KERN_INFO "rpcrdma: connection to %u.%u.%u.%u:%u " 361 printk(KERN_INFO "rpcrdma: connection to %pI4:%u closed (%d)\n",
361 "closed (%d)\n", 362 &addr->sin_addr.s_addr,
362 NIPQUAD(addr->sin_addr.s_addr),
363 ntohs(addr->sin_port), 363 ntohs(addr->sin_port),
364 connstate); 364 connstate);
365 } 365 }
diff --git a/net/sunrpc/xprtsock.c b/net/sunrpc/xprtsock.c
index 0a50361e3d83..5cbb404c4cdf 100644
--- a/net/sunrpc/xprtsock.c
+++ b/net/sunrpc/xprtsock.c
@@ -284,8 +284,7 @@ static void xs_format_ipv4_peer_addresses(struct rpc_xprt *xprt,
284 284
285 buf = kzalloc(20, GFP_KERNEL); 285 buf = kzalloc(20, GFP_KERNEL);
286 if (buf) { 286 if (buf) {
287 snprintf(buf, 20, NIPQUAD_FMT, 287 snprintf(buf, 20, "%pI4", &addr->sin_addr.s_addr);
288 NIPQUAD(addr->sin_addr.s_addr));
289 } 288 }
290 xprt->address_strings[RPC_DISPLAY_ADDR] = buf; 289 xprt->address_strings[RPC_DISPLAY_ADDR] = buf;
291 290
@@ -300,8 +299,8 @@ static void xs_format_ipv4_peer_addresses(struct rpc_xprt *xprt,
300 299
301 buf = kzalloc(48, GFP_KERNEL); 300 buf = kzalloc(48, GFP_KERNEL);
302 if (buf) { 301 if (buf) {
303 snprintf(buf, 48, "addr="NIPQUAD_FMT" port=%u proto=%s", 302 snprintf(buf, 48, "addr=%pI4 port=%u proto=%s",
304 NIPQUAD(addr->sin_addr.s_addr), 303 &addr->sin_addr.s_addr,
305 ntohs(addr->sin_port), 304 ntohs(addr->sin_port),
306 protocol); 305 protocol);
307 } 306 }
@@ -323,8 +322,8 @@ static void xs_format_ipv4_peer_addresses(struct rpc_xprt *xprt,
323 322
324 buf = kzalloc(30, GFP_KERNEL); 323 buf = kzalloc(30, GFP_KERNEL);
325 if (buf) { 324 if (buf) {
326 snprintf(buf, 30, NIPQUAD_FMT".%u.%u", 325 snprintf(buf, 30, "%pI4.%u.%u",
327 NIPQUAD(addr->sin_addr.s_addr), 326 &addr->sin_addr.s_addr,
328 ntohs(addr->sin_port) >> 8, 327 ntohs(addr->sin_port) >> 8,
329 ntohs(addr->sin_port) & 0xff); 328 ntohs(addr->sin_port) & 0xff);
330 } 329 }
@@ -342,8 +341,7 @@ static void xs_format_ipv6_peer_addresses(struct rpc_xprt *xprt,
342 341
343 buf = kzalloc(40, GFP_KERNEL); 342 buf = kzalloc(40, GFP_KERNEL);
344 if (buf) { 343 if (buf) {
345 snprintf(buf, 40, NIP6_FMT, 344 snprintf(buf, 40, "%pI6",&addr->sin6_addr);
346 NIP6(addr->sin6_addr));
347 } 345 }
348 xprt->address_strings[RPC_DISPLAY_ADDR] = buf; 346 xprt->address_strings[RPC_DISPLAY_ADDR] = buf;
349 347
@@ -358,18 +356,17 @@ static void xs_format_ipv6_peer_addresses(struct rpc_xprt *xprt,
358 356
359 buf = kzalloc(64, GFP_KERNEL); 357 buf = kzalloc(64, GFP_KERNEL);
360 if (buf) { 358 if (buf) {
361 snprintf(buf, 64, "addr="NIP6_FMT" port=%u proto=%s", 359 snprintf(buf, 64, "addr=%pI6 port=%u proto=%s",
362 NIP6(addr->sin6_addr), 360 &addr->sin6_addr,
363 ntohs(addr->sin6_port), 361 ntohs(addr->sin6_port),
364 protocol); 362 protocol);
365 } 363 }
366 xprt->address_strings[RPC_DISPLAY_ALL] = buf; 364 xprt->address_strings[RPC_DISPLAY_ALL] = buf;
367 365
368 buf = kzalloc(36, GFP_KERNEL); 366 buf = kzalloc(36, GFP_KERNEL);
369 if (buf) { 367 if (buf)
370 snprintf(buf, 36, NIP6_SEQFMT, 368 snprintf(buf, 36, "%pi6", &addr->sin6_addr);
371 NIP6(addr->sin6_addr)); 369
372 }
373 xprt->address_strings[RPC_DISPLAY_HEX_ADDR] = buf; 370 xprt->address_strings[RPC_DISPLAY_HEX_ADDR] = buf;
374 371
375 buf = kzalloc(8, GFP_KERNEL); 372 buf = kzalloc(8, GFP_KERNEL);
@@ -381,10 +378,10 @@ static void xs_format_ipv6_peer_addresses(struct rpc_xprt *xprt,
381 378
382 buf = kzalloc(50, GFP_KERNEL); 379 buf = kzalloc(50, GFP_KERNEL);
383 if (buf) { 380 if (buf) {
384 snprintf(buf, 50, NIP6_FMT".%u.%u", 381 snprintf(buf, 50, "%pI6.%u.%u",
385 NIP6(addr->sin6_addr), 382 &addr->sin6_addr,
386 ntohs(addr->sin6_port) >> 8, 383 ntohs(addr->sin6_port) >> 8,
387 ntohs(addr->sin6_port) & 0xff); 384 ntohs(addr->sin6_port) & 0xff);
388 } 385 }
389 xprt->address_strings[RPC_DISPLAY_UNIVERSAL_ADDR] = buf; 386 xprt->address_strings[RPC_DISPLAY_UNIVERSAL_ADDR] = buf;
390 387
@@ -1415,8 +1412,8 @@ static int xs_bind4(struct sock_xprt *transport, struct socket *sock)
1415 if (port > last) 1412 if (port > last)
1416 nloop++; 1413 nloop++;
1417 } while (err == -EADDRINUSE && nloop != 2); 1414 } while (err == -EADDRINUSE && nloop != 2);
1418 dprintk("RPC: %s "NIPQUAD_FMT":%u: %s (%d)\n", 1415 dprintk("RPC: %s %pI4:%u: %s (%d)\n",
1419 __func__, NIPQUAD(myaddr.sin_addr), 1416 __func__, &myaddr.sin_addr,
1420 port, err ? "failed" : "ok", err); 1417 port, err ? "failed" : "ok", err);
1421 return err; 1418 return err;
1422} 1419}
@@ -1448,8 +1445,8 @@ static int xs_bind6(struct sock_xprt *transport, struct socket *sock)
1448 if (port > last) 1445 if (port > last)
1449 nloop++; 1446 nloop++;
1450 } while (err == -EADDRINUSE && nloop != 2); 1447 } while (err == -EADDRINUSE && nloop != 2);
1451 dprintk("RPC: xs_bind6 "NIP6_FMT":%u: %s (%d)\n", 1448 dprintk("RPC: xs_bind6 %pI6:%u: %s (%d)\n",
1452 NIP6(myaddr.sin6_addr), port, err ? "failed" : "ok", err); 1449 &myaddr.sin6_addr, port, err ? "failed" : "ok", err);
1453 return err; 1450 return err;
1454} 1451}
1455 1452
diff --git a/net/tipc/eth_media.c b/net/tipc/eth_media.c
index fe43ef7dd7e3..f72ba774c246 100644
--- a/net/tipc/eth_media.c
+++ b/net/tipc/eth_media.c
@@ -243,12 +243,11 @@ static int recv_notification(struct notifier_block *nb, unsigned long evt,
243static char *eth_addr2str(struct tipc_media_addr *a, char *str_buf, int str_size) 243static char *eth_addr2str(struct tipc_media_addr *a, char *str_buf, int str_size)
244{ 244{
245 unchar *addr = (unchar *)&a->dev_addr; 245 unchar *addr = (unchar *)&a->dev_addr;
246 DECLARE_MAC_BUF(mac);
247 246
248 if (str_size < 18) 247 if (str_size < 18)
249 *str_buf = '\0'; 248 *str_buf = '\0';
250 else 249 else
251 sprintf(str_buf, "%s", print_mac(mac, addr)); 250 sprintf(str_buf, "%pM", addr);
252 return str_buf; 251 return str_buf;
253} 252}
254 253
diff --git a/net/tipc/name_table.c b/net/tipc/name_table.c
index cd72e22b132b..acab41a48d67 100644
--- a/net/tipc/name_table.c
+++ b/net/tipc/name_table.c
@@ -555,7 +555,7 @@ static struct name_seq *nametbl_find_seq(u32 type)
555 struct name_seq *ns; 555 struct name_seq *ns;
556 556
557 dbg("find_seq %u,(%u,0x%x) table = %p, hash[type] = %u\n", 557 dbg("find_seq %u,(%u,0x%x) table = %p, hash[type] = %u\n",
558 type, ntohl(type), type, table.types, hash(type)); 558 type, htonl(type), type, table.types, hash(type));
559 559
560 seq_head = &table.types[hash(type)]; 560 seq_head = &table.types[hash(type)];
561 hlist_for_each_entry(ns, seq_node, seq_head, ns_list) { 561 hlist_for_each_entry(ns, seq_node, seq_head, ns_list) {
diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
index b152e2b9b988..c6250d0055d2 100644
--- a/net/unix/af_unix.c
+++ b/net/unix/af_unix.c
@@ -164,7 +164,7 @@ static inline int unix_our_peer(struct sock *sk, struct sock *osk)
164 164
165static inline int unix_may_send(struct sock *sk, struct sock *osk) 165static inline int unix_may_send(struct sock *sk, struct sock *osk)
166{ 166{
167 return (unix_peer(osk) == NULL || unix_our_peer(sk, osk)); 167 return unix_peer(osk) == NULL || unix_our_peer(sk, osk);
168} 168}
169 169
170static inline int unix_recvq_full(struct sock const *sk) 170static inline int unix_recvq_full(struct sock const *sk)
@@ -197,7 +197,7 @@ static inline void unix_release_addr(struct unix_address *addr)
197 * - if started by zero, it is abstract name. 197 * - if started by zero, it is abstract name.
198 */ 198 */
199 199
200static int unix_mkname(struct sockaddr_un * sunaddr, int len, unsigned *hashp) 200static int unix_mkname(struct sockaddr_un *sunaddr, int len, unsigned *hashp)
201{ 201{
202 if (len <= sizeof(short) || len > sizeof(*sunaddr)) 202 if (len <= sizeof(short) || len > sizeof(*sunaddr))
203 return -EINVAL; 203 return -EINVAL;
@@ -211,12 +211,12 @@ static int unix_mkname(struct sockaddr_un * sunaddr, int len, unsigned *hashp)
211 * we are guaranteed that it is a valid memory location in our 211 * we are guaranteed that it is a valid memory location in our
212 * kernel address buffer. 212 * kernel address buffer.
213 */ 213 */
214 ((char *)sunaddr)[len]=0; 214 ((char *)sunaddr)[len] = 0;
215 len = strlen(sunaddr->sun_path)+1+sizeof(short); 215 len = strlen(sunaddr->sun_path)+1+sizeof(short);
216 return len; 216 return len;
217 } 217 }
218 218
219 *hashp = unix_hash_fold(csum_partial((char*)sunaddr, len, 0)); 219 *hashp = unix_hash_fold(csum_partial(sunaddr, len, 0));
220 return len; 220 return len;
221} 221}
222 222
@@ -295,8 +295,7 @@ static struct sock *unix_find_socket_byinode(struct net *net, struct inode *i)
295 if (!net_eq(sock_net(s), net)) 295 if (!net_eq(sock_net(s), net))
296 continue; 296 continue;
297 297
298 if(dentry && dentry->d_inode == i) 298 if (dentry && dentry->d_inode == i) {
299 {
300 sock_hold(s); 299 sock_hold(s);
301 goto found; 300 goto found;
302 } 301 }
@@ -354,7 +353,7 @@ static void unix_sock_destructor(struct sock *sk)
354 WARN_ON(!sk_unhashed(sk)); 353 WARN_ON(!sk_unhashed(sk));
355 WARN_ON(sk->sk_socket); 354 WARN_ON(sk->sk_socket);
356 if (!sock_flag(sk, SOCK_DEAD)) { 355 if (!sock_flag(sk, SOCK_DEAD)) {
357 printk("Attempt to release alive unix socket: %p\n", sk); 356 printk(KERN_INFO "Attempt to release alive unix socket: %p\n", sk);
358 return; 357 return;
359 } 358 }
360 359
@@ -362,12 +361,16 @@ static void unix_sock_destructor(struct sock *sk)
362 unix_release_addr(u->addr); 361 unix_release_addr(u->addr);
363 362
364 atomic_dec(&unix_nr_socks); 363 atomic_dec(&unix_nr_socks);
364 local_bh_disable();
365 sock_prot_inuse_add(sock_net(sk), sk->sk_prot, -1);
366 local_bh_enable();
365#ifdef UNIX_REFCNT_DEBUG 367#ifdef UNIX_REFCNT_DEBUG
366 printk(KERN_DEBUG "UNIX %p is destroyed, %d are still alive.\n", sk, atomic_read(&unix_nr_socks)); 368 printk(KERN_DEBUG "UNIX %p is destroyed, %d are still alive.\n", sk,
369 atomic_read(&unix_nr_socks));
367#endif 370#endif
368} 371}
369 372
370static int unix_release_sock (struct sock *sk, int embrion) 373static int unix_release_sock(struct sock *sk, int embrion)
371{ 374{
372 struct unix_sock *u = unix_sk(sk); 375 struct unix_sock *u = unix_sk(sk);
373 struct dentry *dentry; 376 struct dentry *dentry;
@@ -392,9 +395,9 @@ static int unix_release_sock (struct sock *sk, int embrion)
392 395
393 wake_up_interruptible_all(&u->peer_wait); 396 wake_up_interruptible_all(&u->peer_wait);
394 397
395 skpair=unix_peer(sk); 398 skpair = unix_peer(sk);
396 399
397 if (skpair!=NULL) { 400 if (skpair != NULL) {
398 if (sk->sk_type == SOCK_STREAM || sk->sk_type == SOCK_SEQPACKET) { 401 if (sk->sk_type == SOCK_STREAM || sk->sk_type == SOCK_SEQPACKET) {
399 unix_state_lock(skpair); 402 unix_state_lock(skpair);
400 /* No more writes */ 403 /* No more writes */
@@ -414,7 +417,7 @@ static int unix_release_sock (struct sock *sk, int embrion)
414 /* Try to flush out this socket. Throw out buffers at least */ 417 /* Try to flush out this socket. Throw out buffers at least */
415 418
416 while ((skb = skb_dequeue(&sk->sk_receive_queue)) != NULL) { 419 while ((skb = skb_dequeue(&sk->sk_receive_queue)) != NULL) {
417 if (state==TCP_LISTEN) 420 if (state == TCP_LISTEN)
418 unix_release_sock(skb->sk, 1); 421 unix_release_sock(skb->sk, 1);
419 /* passed fds are erased in the kfree_skb hook */ 422 /* passed fds are erased in the kfree_skb hook */
420 kfree_skb(skb); 423 kfree_skb(skb);
@@ -453,11 +456,11 @@ static int unix_listen(struct socket *sock, int backlog)
453 struct unix_sock *u = unix_sk(sk); 456 struct unix_sock *u = unix_sk(sk);
454 457
455 err = -EOPNOTSUPP; 458 err = -EOPNOTSUPP;
456 if (sock->type!=SOCK_STREAM && sock->type!=SOCK_SEQPACKET) 459 if (sock->type != SOCK_STREAM && sock->type != SOCK_SEQPACKET)
457 goto out; /* Only stream/seqpacket sockets accept */ 460 goto out; /* Only stream/seqpacket sockets accept */
458 err = -EINVAL; 461 err = -EINVAL;
459 if (!u->addr) 462 if (!u->addr)
460 goto out; /* No listens on an unbound socket */ 463 goto out; /* No listens on an unbound socket */
461 unix_state_lock(sk); 464 unix_state_lock(sk);
462 if (sk->sk_state != TCP_CLOSE && sk->sk_state != TCP_LISTEN) 465 if (sk->sk_state != TCP_CLOSE && sk->sk_state != TCP_LISTEN)
463 goto out_unlock; 466 goto out_unlock;
@@ -565,9 +568,9 @@ static const struct proto_ops unix_seqpacket_ops = {
565}; 568};
566 569
567static struct proto unix_proto = { 570static struct proto unix_proto = {
568 .name = "UNIX", 571 .name = "UNIX",
569 .owner = THIS_MODULE, 572 .owner = THIS_MODULE,
570 .obj_size = sizeof(struct unix_sock), 573 .obj_size = sizeof(struct unix_sock),
571}; 574};
572 575
573/* 576/*
@@ -578,7 +581,7 @@ static struct proto unix_proto = {
578 */ 581 */
579static struct lock_class_key af_unix_sk_receive_queue_lock_key; 582static struct lock_class_key af_unix_sk_receive_queue_lock_key;
580 583
581static struct sock * unix_create1(struct net *net, struct socket *sock) 584static struct sock *unix_create1(struct net *net, struct socket *sock)
582{ 585{
583 struct sock *sk = NULL; 586 struct sock *sk = NULL;
584 struct unix_sock *u; 587 struct unix_sock *u;
@@ -591,7 +594,7 @@ static struct sock * unix_create1(struct net *net, struct socket *sock)
591 if (!sk) 594 if (!sk)
592 goto out; 595 goto out;
593 596
594 sock_init_data(sock,sk); 597 sock_init_data(sock, sk);
595 lockdep_set_class(&sk->sk_receive_queue.lock, 598 lockdep_set_class(&sk->sk_receive_queue.lock,
596 &af_unix_sk_receive_queue_lock_key); 599 &af_unix_sk_receive_queue_lock_key);
597 600
@@ -610,6 +613,11 @@ static struct sock * unix_create1(struct net *net, struct socket *sock)
610out: 613out:
611 if (sk == NULL) 614 if (sk == NULL)
612 atomic_dec(&unix_nr_socks); 615 atomic_dec(&unix_nr_socks);
616 else {
617 local_bh_disable();
618 sock_prot_inuse_add(sock_net(sk), sk->sk_prot, 1);
619 local_bh_enable();
620 }
613 return sk; 621 return sk;
614} 622}
615 623
@@ -629,7 +637,7 @@ static int unix_create(struct net *net, struct socket *sock, int protocol)
629 * nothing uses it. 637 * nothing uses it.
630 */ 638 */
631 case SOCK_RAW: 639 case SOCK_RAW:
632 sock->type=SOCK_DGRAM; 640 sock->type = SOCK_DGRAM;
633 case SOCK_DGRAM: 641 case SOCK_DGRAM:
634 sock->ops = &unix_dgram_ops; 642 sock->ops = &unix_dgram_ops;
635 break; 643 break;
@@ -652,7 +660,7 @@ static int unix_release(struct socket *sock)
652 660
653 sock->sk = NULL; 661 sock->sk = NULL;
654 662
655 return unix_release_sock (sk, 0); 663 return unix_release_sock(sk, 0);
656} 664}
657 665
658static int unix_autobind(struct socket *sock) 666static int unix_autobind(struct socket *sock)
@@ -661,7 +669,7 @@ static int unix_autobind(struct socket *sock)
661 struct net *net = sock_net(sk); 669 struct net *net = sock_net(sk);
662 struct unix_sock *u = unix_sk(sk); 670 struct unix_sock *u = unix_sk(sk);
663 static u32 ordernum = 1; 671 static u32 ordernum = 1;
664 struct unix_address * addr; 672 struct unix_address *addr;
665 int err; 673 int err;
666 674
667 mutex_lock(&u->readlock); 675 mutex_lock(&u->readlock);
@@ -680,7 +688,7 @@ static int unix_autobind(struct socket *sock)
680 688
681retry: 689retry:
682 addr->len = sprintf(addr->name->sun_path+1, "%05x", ordernum) + 1 + sizeof(short); 690 addr->len = sprintf(addr->name->sun_path+1, "%05x", ordernum) + 1 + sizeof(short);
683 addr->hash = unix_hash_fold(csum_partial((void*)addr->name, addr->len, 0)); 691 addr->hash = unix_hash_fold(csum_partial(addr->name, addr->len, 0));
684 692
685 spin_lock(&unix_table_lock); 693 spin_lock(&unix_table_lock);
686 ordernum = (ordernum+1)&0xFFFFF; 694 ordernum = (ordernum+1)&0xFFFFF;
@@ -735,14 +743,14 @@ static struct sock *unix_find_other(struct net *net,
735 743
736 path_put(&path); 744 path_put(&path);
737 745
738 err=-EPROTOTYPE; 746 err = -EPROTOTYPE;
739 if (u->sk_type != type) { 747 if (u->sk_type != type) {
740 sock_put(u); 748 sock_put(u);
741 goto fail; 749 goto fail;
742 } 750 }
743 } else { 751 } else {
744 err = -ECONNREFUSED; 752 err = -ECONNREFUSED;
745 u=unix_find_socket_byname(net, sunname, len, type, hash); 753 u = unix_find_socket_byname(net, sunname, len, type, hash);
746 if (u) { 754 if (u) {
747 struct dentry *dentry; 755 struct dentry *dentry;
748 dentry = unix_sk(u)->dentry; 756 dentry = unix_sk(u)->dentry;
@@ -756,7 +764,7 @@ static struct sock *unix_find_other(struct net *net,
756put_fail: 764put_fail:
757 path_put(&path); 765 path_put(&path);
758fail: 766fail:
759 *error=err; 767 *error = err;
760 return NULL; 768 return NULL;
761} 769}
762 770
@@ -766,8 +774,8 @@ static int unix_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
766 struct sock *sk = sock->sk; 774 struct sock *sk = sock->sk;
767 struct net *net = sock_net(sk); 775 struct net *net = sock_net(sk);
768 struct unix_sock *u = unix_sk(sk); 776 struct unix_sock *u = unix_sk(sk);
769 struct sockaddr_un *sunaddr=(struct sockaddr_un *)uaddr; 777 struct sockaddr_un *sunaddr = (struct sockaddr_un *)uaddr;
770 struct dentry * dentry = NULL; 778 struct dentry *dentry = NULL;
771 struct nameidata nd; 779 struct nameidata nd;
772 int err; 780 int err;
773 unsigned hash; 781 unsigned hash;
@@ -778,7 +786,7 @@ static int unix_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
778 if (sunaddr->sun_family != AF_UNIX) 786 if (sunaddr->sun_family != AF_UNIX)
779 goto out; 787 goto out;
780 788
781 if (addr_len==sizeof(short)) { 789 if (addr_len == sizeof(short)) {
782 err = unix_autobind(sock); 790 err = unix_autobind(sock);
783 goto out; 791 goto out;
784 } 792 }
@@ -874,8 +882,8 @@ out_mknod_unlock:
874 mutex_unlock(&nd.path.dentry->d_inode->i_mutex); 882 mutex_unlock(&nd.path.dentry->d_inode->i_mutex);
875 path_put(&nd.path); 883 path_put(&nd.path);
876out_mknod_parent: 884out_mknod_parent:
877 if (err==-EEXIST) 885 if (err == -EEXIST)
878 err=-EADDRINUSE; 886 err = -EADDRINUSE;
879 unix_release_addr(addr); 887 unix_release_addr(addr);
880 goto out_up; 888 goto out_up;
881} 889}
@@ -910,7 +918,7 @@ static int unix_dgram_connect(struct socket *sock, struct sockaddr *addr,
910{ 918{
911 struct sock *sk = sock->sk; 919 struct sock *sk = sock->sk;
912 struct net *net = sock_net(sk); 920 struct net *net = sock_net(sk);
913 struct sockaddr_un *sunaddr=(struct sockaddr_un*)addr; 921 struct sockaddr_un *sunaddr = (struct sockaddr_un *)addr;
914 struct sock *other; 922 struct sock *other;
915 unsigned hash; 923 unsigned hash;
916 int err; 924 int err;
@@ -926,7 +934,7 @@ static int unix_dgram_connect(struct socket *sock, struct sockaddr *addr,
926 goto out; 934 goto out;
927 935
928restart: 936restart:
929 other=unix_find_other(net, sunaddr, alen, sock->type, hash, &err); 937 other = unix_find_other(net, sunaddr, alen, sock->type, hash, &err);
930 if (!other) 938 if (!other)
931 goto out; 939 goto out;
932 940
@@ -960,14 +968,14 @@ restart:
960 */ 968 */
961 if (unix_peer(sk)) { 969 if (unix_peer(sk)) {
962 struct sock *old_peer = unix_peer(sk); 970 struct sock *old_peer = unix_peer(sk);
963 unix_peer(sk)=other; 971 unix_peer(sk) = other;
964 unix_state_double_unlock(sk, other); 972 unix_state_double_unlock(sk, other);
965 973
966 if (other != old_peer) 974 if (other != old_peer)
967 unix_dgram_disconnected(sk, old_peer); 975 unix_dgram_disconnected(sk, old_peer);
968 sock_put(old_peer); 976 sock_put(old_peer);
969 } else { 977 } else {
970 unix_peer(sk)=other; 978 unix_peer(sk) = other;
971 unix_state_double_unlock(sk, other); 979 unix_state_double_unlock(sk, other);
972 } 980 }
973 return 0; 981 return 0;
@@ -1003,7 +1011,7 @@ static long unix_wait_for_peer(struct sock *other, long timeo)
1003static int unix_stream_connect(struct socket *sock, struct sockaddr *uaddr, 1011static int unix_stream_connect(struct socket *sock, struct sockaddr *uaddr,
1004 int addr_len, int flags) 1012 int addr_len, int flags)
1005{ 1013{
1006 struct sockaddr_un *sunaddr=(struct sockaddr_un *)uaddr; 1014 struct sockaddr_un *sunaddr = (struct sockaddr_un *)uaddr;
1007 struct sock *sk = sock->sk; 1015 struct sock *sk = sock->sk;
1008 struct net *net = sock_net(sk); 1016 struct net *net = sock_net(sk);
1009 struct unix_sock *u = unix_sk(sk), *newu, *otheru; 1017 struct unix_sock *u = unix_sk(sk), *newu, *otheru;
@@ -1177,13 +1185,13 @@ out:
1177 1185
1178static int unix_socketpair(struct socket *socka, struct socket *sockb) 1186static int unix_socketpair(struct socket *socka, struct socket *sockb)
1179{ 1187{
1180 struct sock *ska=socka->sk, *skb = sockb->sk; 1188 struct sock *ska = socka->sk, *skb = sockb->sk;
1181 1189
1182 /* Join our sockets back to back */ 1190 /* Join our sockets back to back */
1183 sock_hold(ska); 1191 sock_hold(ska);
1184 sock_hold(skb); 1192 sock_hold(skb);
1185 unix_peer(ska)=skb; 1193 unix_peer(ska) = skb;
1186 unix_peer(skb)=ska; 1194 unix_peer(skb) = ska;
1187 ska->sk_peercred.pid = skb->sk_peercred.pid = task_tgid_vnr(current); 1195 ska->sk_peercred.pid = skb->sk_peercred.pid = task_tgid_vnr(current);
1188 current_euid_egid(&skb->sk_peercred.uid, &skb->sk_peercred.gid); 1196 current_euid_egid(&skb->sk_peercred.uid, &skb->sk_peercred.gid);
1189 ska->sk_peercred.uid = skb->sk_peercred.uid; 1197 ska->sk_peercred.uid = skb->sk_peercred.uid;
@@ -1206,7 +1214,7 @@ static int unix_accept(struct socket *sock, struct socket *newsock, int flags)
1206 int err; 1214 int err;
1207 1215
1208 err = -EOPNOTSUPP; 1216 err = -EOPNOTSUPP;
1209 if (sock->type!=SOCK_STREAM && sock->type!=SOCK_SEQPACKET) 1217 if (sock->type != SOCK_STREAM && sock->type != SOCK_SEQPACKET)
1210 goto out; 1218 goto out;
1211 1219
1212 err = -EINVAL; 1220 err = -EINVAL;
@@ -1245,7 +1253,7 @@ static int unix_getname(struct socket *sock, struct sockaddr *uaddr, int *uaddr_
1245{ 1253{
1246 struct sock *sk = sock->sk; 1254 struct sock *sk = sock->sk;
1247 struct unix_sock *u; 1255 struct unix_sock *u;
1248 struct sockaddr_un *sunaddr=(struct sockaddr_un *)uaddr; 1256 struct sockaddr_un *sunaddr = (struct sockaddr_un *)uaddr;
1249 int err = 0; 1257 int err = 0;
1250 1258
1251 if (peer) { 1259 if (peer) {
@@ -1285,7 +1293,7 @@ static void unix_detach_fds(struct scm_cookie *scm, struct sk_buff *skb)
1285 skb->destructor = sock_wfree; 1293 skb->destructor = sock_wfree;
1286 UNIXCB(skb).fp = NULL; 1294 UNIXCB(skb).fp = NULL;
1287 1295
1288 for (i=scm->fp->count-1; i>=0; i--) 1296 for (i = scm->fp->count-1; i >= 0; i--)
1289 unix_notinflight(scm->fp->fp[i]); 1297 unix_notinflight(scm->fp->fp[i]);
1290} 1298}
1291 1299
@@ -1314,7 +1322,7 @@ static int unix_attach_fds(struct scm_cookie *scm, struct sk_buff *skb)
1314 if (!UNIXCB(skb).fp) 1322 if (!UNIXCB(skb).fp)
1315 return -ENOMEM; 1323 return -ENOMEM;
1316 1324
1317 for (i=scm->fp->count-1; i>=0; i--) 1325 for (i = scm->fp->count-1; i >= 0; i--)
1318 unix_inflight(scm->fp->fp[i]); 1326 unix_inflight(scm->fp->fp[i]);
1319 skb->destructor = unix_destruct_fds; 1327 skb->destructor = unix_destruct_fds;
1320 return 0; 1328 return 0;
@@ -1331,7 +1339,7 @@ static int unix_dgram_sendmsg(struct kiocb *kiocb, struct socket *sock,
1331 struct sock *sk = sock->sk; 1339 struct sock *sk = sock->sk;
1332 struct net *net = sock_net(sk); 1340 struct net *net = sock_net(sk);
1333 struct unix_sock *u = unix_sk(sk); 1341 struct unix_sock *u = unix_sk(sk);
1334 struct sockaddr_un *sunaddr=msg->msg_name; 1342 struct sockaddr_un *sunaddr = msg->msg_name;
1335 struct sock *other = NULL; 1343 struct sock *other = NULL;
1336 int namelen = 0; /* fake GCC */ 1344 int namelen = 0; /* fake GCC */
1337 int err; 1345 int err;
@@ -1373,7 +1381,7 @@ static int unix_dgram_sendmsg(struct kiocb *kiocb, struct socket *sock,
1373 goto out; 1381 goto out;
1374 1382
1375 skb = sock_alloc_send_skb(sk, len, msg->msg_flags&MSG_DONTWAIT, &err); 1383 skb = sock_alloc_send_skb(sk, len, msg->msg_flags&MSG_DONTWAIT, &err);
1376 if (skb==NULL) 1384 if (skb == NULL)
1377 goto out; 1385 goto out;
1378 1386
1379 memcpy(UNIXCREDS(skb), &siocb->scm->creds, sizeof(struct ucred)); 1387 memcpy(UNIXCREDS(skb), &siocb->scm->creds, sizeof(struct ucred));
@@ -1385,7 +1393,7 @@ static int unix_dgram_sendmsg(struct kiocb *kiocb, struct socket *sock,
1385 unix_get_secdata(siocb->scm, skb); 1393 unix_get_secdata(siocb->scm, skb);
1386 1394
1387 skb_reset_transport_header(skb); 1395 skb_reset_transport_header(skb);
1388 err = memcpy_fromiovec(skb_put(skb,len), msg->msg_iov, len); 1396 err = memcpy_fromiovec(skb_put(skb, len), msg->msg_iov, len);
1389 if (err) 1397 if (err)
1390 goto out_free; 1398 goto out_free;
1391 1399
@@ -1399,7 +1407,7 @@ restart:
1399 1407
1400 other = unix_find_other(net, sunaddr, namelen, sk->sk_type, 1408 other = unix_find_other(net, sunaddr, namelen, sk->sk_type,
1401 hash, &err); 1409 hash, &err);
1402 if (other==NULL) 1410 if (other == NULL)
1403 goto out_free; 1411 goto out_free;
1404 } 1412 }
1405 1413
@@ -1419,7 +1427,7 @@ restart:
1419 err = 0; 1427 err = 0;
1420 unix_state_lock(sk); 1428 unix_state_lock(sk);
1421 if (unix_peer(sk) == other) { 1429 if (unix_peer(sk) == other) {
1422 unix_peer(sk)=NULL; 1430 unix_peer(sk) = NULL;
1423 unix_state_unlock(sk); 1431 unix_state_unlock(sk);
1424 1432
1425 unix_dgram_disconnected(sk, other); 1433 unix_dgram_disconnected(sk, other);
@@ -1485,10 +1493,10 @@ static int unix_stream_sendmsg(struct kiocb *kiocb, struct socket *sock,
1485 struct sock_iocb *siocb = kiocb_to_siocb(kiocb); 1493 struct sock_iocb *siocb = kiocb_to_siocb(kiocb);
1486 struct sock *sk = sock->sk; 1494 struct sock *sk = sock->sk;
1487 struct sock *other = NULL; 1495 struct sock *other = NULL;
1488 struct sockaddr_un *sunaddr=msg->msg_name; 1496 struct sockaddr_un *sunaddr = msg->msg_name;
1489 int err,size; 1497 int err, size;
1490 struct sk_buff *skb; 1498 struct sk_buff *skb;
1491 int sent=0; 1499 int sent = 0;
1492 struct scm_cookie tmp_scm; 1500 struct scm_cookie tmp_scm;
1493 1501
1494 if (NULL == siocb->scm) 1502 if (NULL == siocb->scm)
@@ -1516,8 +1524,7 @@ static int unix_stream_sendmsg(struct kiocb *kiocb, struct socket *sock,
1516 if (sk->sk_shutdown & SEND_SHUTDOWN) 1524 if (sk->sk_shutdown & SEND_SHUTDOWN)
1517 goto pipe_err; 1525 goto pipe_err;
1518 1526
1519 while(sent < len) 1527 while (sent < len) {
1520 {
1521 /* 1528 /*
1522 * Optimisation for the fact that under 0.01% of X 1529 * Optimisation for the fact that under 0.01% of X
1523 * messages typically need breaking up. 1530 * messages typically need breaking up.
@@ -1536,9 +1543,10 @@ static int unix_stream_sendmsg(struct kiocb *kiocb, struct socket *sock,
1536 * Grab a buffer 1543 * Grab a buffer
1537 */ 1544 */
1538 1545
1539 skb=sock_alloc_send_skb(sk,size,msg->msg_flags&MSG_DONTWAIT, &err); 1546 skb = sock_alloc_send_skb(sk, size, msg->msg_flags&MSG_DONTWAIT,
1547 &err);
1540 1548
1541 if (skb==NULL) 1549 if (skb == NULL)
1542 goto out_err; 1550 goto out_err;
1543 1551
1544 /* 1552 /*
@@ -1559,7 +1567,8 @@ static int unix_stream_sendmsg(struct kiocb *kiocb, struct socket *sock,
1559 } 1567 }
1560 } 1568 }
1561 1569
1562 if ((err = memcpy_fromiovec(skb_put(skb,size), msg->msg_iov, size)) != 0) { 1570 err = memcpy_fromiovec(skb_put(skb, size), msg->msg_iov, size);
1571 if (err) {
1563 kfree_skb(skb); 1572 kfree_skb(skb);
1564 goto out_err; 1573 goto out_err;
1565 } 1574 }
@@ -1573,7 +1582,7 @@ static int unix_stream_sendmsg(struct kiocb *kiocb, struct socket *sock,
1573 skb_queue_tail(&other->sk_receive_queue, skb); 1582 skb_queue_tail(&other->sk_receive_queue, skb);
1574 unix_state_unlock(other); 1583 unix_state_unlock(other);
1575 other->sk_data_ready(other, size); 1584 other->sk_data_ready(other, size);
1576 sent+=size; 1585 sent += size;
1577 } 1586 }
1578 1587
1579 scm_destroy(siocb->scm); 1588 scm_destroy(siocb->scm);
@@ -1585,8 +1594,8 @@ pipe_err_free:
1585 unix_state_unlock(other); 1594 unix_state_unlock(other);
1586 kfree_skb(skb); 1595 kfree_skb(skb);
1587pipe_err: 1596pipe_err:
1588 if (sent==0 && !(msg->msg_flags&MSG_NOSIGNAL)) 1597 if (sent == 0 && !(msg->msg_flags&MSG_NOSIGNAL))
1589 send_sig(SIGPIPE,current,0); 1598 send_sig(SIGPIPE, current, 0);
1590 err = -EPIPE; 1599 err = -EPIPE;
1591out_err: 1600out_err:
1592 scm_destroy(siocb->scm); 1601 scm_destroy(siocb->scm);
@@ -1676,13 +1685,10 @@ static int unix_dgram_recvmsg(struct kiocb *iocb, struct socket *sock,
1676 siocb->scm->creds = *UNIXCREDS(skb); 1685 siocb->scm->creds = *UNIXCREDS(skb);
1677 unix_set_secdata(siocb->scm, skb); 1686 unix_set_secdata(siocb->scm, skb);
1678 1687
1679 if (!(flags & MSG_PEEK)) 1688 if (!(flags & MSG_PEEK)) {
1680 {
1681 if (UNIXCB(skb).fp) 1689 if (UNIXCB(skb).fp)
1682 unix_detach_fds(siocb->scm, skb); 1690 unix_detach_fds(siocb->scm, skb);
1683 } 1691 } else {
1684 else
1685 {
1686 /* It is questionable: on PEEK we could: 1692 /* It is questionable: on PEEK we could:
1687 - do not return fds - good, but too simple 8) 1693 - do not return fds - good, but too simple 8)
1688 - return fds, and do not return them on read (old strategy, 1694 - return fds, and do not return them on read (old strategy,
@@ -1703,7 +1709,7 @@ static int unix_dgram_recvmsg(struct kiocb *iocb, struct socket *sock,
1703 scm_recv(sock, msg, siocb->scm, flags); 1709 scm_recv(sock, msg, siocb->scm, flags);
1704 1710
1705out_free: 1711out_free:
1706 skb_free_datagram(sk,skb); 1712 skb_free_datagram(sk, skb);
1707out_unlock: 1713out_unlock:
1708 mutex_unlock(&u->readlock); 1714 mutex_unlock(&u->readlock);
1709out: 1715out:
@@ -1714,7 +1720,7 @@ out:
1714 * Sleep until data has arrive. But check for races.. 1720 * Sleep until data has arrive. But check for races..
1715 */ 1721 */
1716 1722
1717static long unix_stream_data_wait(struct sock * sk, long timeo) 1723static long unix_stream_data_wait(struct sock *sk, long timeo)
1718{ 1724{
1719 DEFINE_WAIT(wait); 1725 DEFINE_WAIT(wait);
1720 1726
@@ -1752,7 +1758,7 @@ static int unix_stream_recvmsg(struct kiocb *iocb, struct socket *sock,
1752 struct scm_cookie tmp_scm; 1758 struct scm_cookie tmp_scm;
1753 struct sock *sk = sock->sk; 1759 struct sock *sk = sock->sk;
1754 struct unix_sock *u = unix_sk(sk); 1760 struct unix_sock *u = unix_sk(sk);
1755 struct sockaddr_un *sunaddr=msg->msg_name; 1761 struct sockaddr_un *sunaddr = msg->msg_name;
1756 int copied = 0; 1762 int copied = 0;
1757 int check_creds = 0; 1763 int check_creds = 0;
1758 int target; 1764 int target;
@@ -1783,15 +1789,13 @@ static int unix_stream_recvmsg(struct kiocb *iocb, struct socket *sock,
1783 1789
1784 mutex_lock(&u->readlock); 1790 mutex_lock(&u->readlock);
1785 1791
1786 do 1792 do {
1787 {
1788 int chunk; 1793 int chunk;
1789 struct sk_buff *skb; 1794 struct sk_buff *skb;
1790 1795
1791 unix_state_lock(sk); 1796 unix_state_lock(sk);
1792 skb = skb_dequeue(&sk->sk_receive_queue); 1797 skb = skb_dequeue(&sk->sk_receive_queue);
1793 if (skb==NULL) 1798 if (skb == NULL) {
1794 {
1795 if (copied >= target) 1799 if (copied >= target)
1796 goto unlock; 1800 goto unlock;
1797 1801
@@ -1799,7 +1803,8 @@ static int unix_stream_recvmsg(struct kiocb *iocb, struct socket *sock,
1799 * POSIX 1003.1g mandates this order. 1803 * POSIX 1003.1g mandates this order.
1800 */ 1804 */
1801 1805
1802 if ((err = sock_error(sk)) != 0) 1806 err = sock_error(sk);
1807 if (err)
1803 goto unlock; 1808 goto unlock;
1804 if (sk->sk_shutdown & RCV_SHUTDOWN) 1809 if (sk->sk_shutdown & RCV_SHUTDOWN)
1805 goto unlock; 1810 goto unlock;
@@ -1826,7 +1831,8 @@ static int unix_stream_recvmsg(struct kiocb *iocb, struct socket *sock,
1826 1831
1827 if (check_creds) { 1832 if (check_creds) {
1828 /* Never glue messages from different writers */ 1833 /* Never glue messages from different writers */
1829 if (memcmp(UNIXCREDS(skb), &siocb->scm->creds, sizeof(siocb->scm->creds)) != 0) { 1834 if (memcmp(UNIXCREDS(skb), &siocb->scm->creds,
1835 sizeof(siocb->scm->creds)) != 0) {
1830 skb_queue_head(&sk->sk_receive_queue, skb); 1836 skb_queue_head(&sk->sk_receive_queue, skb);
1831 break; 1837 break;
1832 } 1838 }
@@ -1837,8 +1843,7 @@ static int unix_stream_recvmsg(struct kiocb *iocb, struct socket *sock,
1837 } 1843 }
1838 1844
1839 /* Copy address just once */ 1845 /* Copy address just once */
1840 if (sunaddr) 1846 if (sunaddr) {
1841 {
1842 unix_copy_addr(msg, skb->sk); 1847 unix_copy_addr(msg, skb->sk);
1843 sunaddr = NULL; 1848 sunaddr = NULL;
1844 } 1849 }
@@ -1854,16 +1859,14 @@ static int unix_stream_recvmsg(struct kiocb *iocb, struct socket *sock,
1854 size -= chunk; 1859 size -= chunk;
1855 1860
1856 /* Mark read part of skb as used */ 1861 /* Mark read part of skb as used */
1857 if (!(flags & MSG_PEEK)) 1862 if (!(flags & MSG_PEEK)) {
1858 {
1859 skb_pull(skb, chunk); 1863 skb_pull(skb, chunk);
1860 1864
1861 if (UNIXCB(skb).fp) 1865 if (UNIXCB(skb).fp)
1862 unix_detach_fds(siocb->scm, skb); 1866 unix_detach_fds(siocb->scm, skb);
1863 1867
1864 /* put the skb back if we didn't use it up.. */ 1868 /* put the skb back if we didn't use it up.. */
1865 if (skb->len) 1869 if (skb->len) {
1866 {
1867 skb_queue_head(&sk->sk_receive_queue, skb); 1870 skb_queue_head(&sk->sk_receive_queue, skb);
1868 break; 1871 break;
1869 } 1872 }
@@ -1872,9 +1875,7 @@ static int unix_stream_recvmsg(struct kiocb *iocb, struct socket *sock,
1872 1875
1873 if (siocb->scm->fp) 1876 if (siocb->scm->fp)
1874 break; 1877 break;
1875 } 1878 } else {
1876 else
1877 {
1878 /* It is questionable, see note in unix_dgram_recvmsg. 1879 /* It is questionable, see note in unix_dgram_recvmsg.
1879 */ 1880 */
1880 if (UNIXCB(skb).fp) 1881 if (UNIXCB(skb).fp)
@@ -1902,7 +1903,7 @@ static int unix_shutdown(struct socket *sock, int mode)
1902 if (mode) { 1903 if (mode) {
1903 unix_state_lock(sk); 1904 unix_state_lock(sk);
1904 sk->sk_shutdown |= mode; 1905 sk->sk_shutdown |= mode;
1905 other=unix_peer(sk); 1906 other = unix_peer(sk);
1906 if (other) 1907 if (other)
1907 sock_hold(other); 1908 sock_hold(other);
1908 unix_state_unlock(sk); 1909 unix_state_unlock(sk);
@@ -1937,16 +1938,15 @@ static int unix_shutdown(struct socket *sock, int mode)
1937static int unix_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg) 1938static int unix_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
1938{ 1939{
1939 struct sock *sk = sock->sk; 1940 struct sock *sk = sock->sk;
1940 long amount=0; 1941 long amount = 0;
1941 int err; 1942 int err;
1942 1943
1943 switch(cmd) 1944 switch (cmd) {
1944 { 1945 case SIOCOUTQ:
1945 case SIOCOUTQ: 1946 amount = atomic_read(&sk->sk_wmem_alloc);
1946 amount = atomic_read(&sk->sk_wmem_alloc); 1947 err = put_user(amount, (int __user *)arg);
1947 err = put_user(amount, (int __user *)arg); 1948 break;
1948 break; 1949 case SIOCINQ:
1949 case SIOCINQ:
1950 { 1950 {
1951 struct sk_buff *skb; 1951 struct sk_buff *skb;
1952 1952
@@ -1963,21 +1963,21 @@ static int unix_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
1963 } else { 1963 } else {
1964 skb = skb_peek(&sk->sk_receive_queue); 1964 skb = skb_peek(&sk->sk_receive_queue);
1965 if (skb) 1965 if (skb)
1966 amount=skb->len; 1966 amount = skb->len;
1967 } 1967 }
1968 spin_unlock(&sk->sk_receive_queue.lock); 1968 spin_unlock(&sk->sk_receive_queue.lock);
1969 err = put_user(amount, (int __user *)arg); 1969 err = put_user(amount, (int __user *)arg);
1970 break; 1970 break;
1971 } 1971 }
1972 1972
1973 default: 1973 default:
1974 err = -ENOIOCTLCMD; 1974 err = -ENOIOCTLCMD;
1975 break; 1975 break;
1976 } 1976 }
1977 return err; 1977 return err;
1978} 1978}
1979 1979
1980static unsigned int unix_poll(struct file * file, struct socket *sock, poll_table *wait) 1980static unsigned int unix_poll(struct file *file, struct socket *sock, poll_table *wait)
1981{ 1981{
1982 struct sock *sk = sock->sk; 1982 struct sock *sk = sock->sk;
1983 unsigned int mask; 1983 unsigned int mask;
@@ -1999,7 +1999,8 @@ static unsigned int unix_poll(struct file * file, struct socket *sock, poll_tabl
1999 mask |= POLLIN | POLLRDNORM; 1999 mask |= POLLIN | POLLRDNORM;
2000 2000
2001 /* Connection-based need to check for termination and startup */ 2001 /* Connection-based need to check for termination and startup */
2002 if ((sk->sk_type == SOCK_STREAM || sk->sk_type == SOCK_SEQPACKET) && sk->sk_state == TCP_CLOSE) 2002 if ((sk->sk_type == SOCK_STREAM || sk->sk_type == SOCK_SEQPACKET) &&
2003 sk->sk_state == TCP_CLOSE)
2003 mask |= POLLHUP; 2004 mask |= POLLHUP;
2004 2005
2005 /* 2006 /*
@@ -2095,6 +2096,7 @@ struct unix_iter_state {
2095 struct seq_net_private p; 2096 struct seq_net_private p;
2096 int i; 2097 int i;
2097}; 2098};
2099
2098static struct sock *unix_seq_idx(struct seq_file *seq, loff_t pos) 2100static struct sock *unix_seq_idx(struct seq_file *seq, loff_t pos)
2099{ 2101{
2100 struct unix_iter_state *iter = seq->private; 2102 struct unix_iter_state *iter = seq->private;
@@ -2111,7 +2113,6 @@ static struct sock *unix_seq_idx(struct seq_file *seq, loff_t pos)
2111 return NULL; 2113 return NULL;
2112} 2114}
2113 2115
2114
2115static void *unix_seq_start(struct seq_file *seq, loff_t *pos) 2116static void *unix_seq_start(struct seq_file *seq, loff_t *pos)
2116 __acquires(unix_table_lock) 2117 __acquires(unix_table_lock)
2117{ 2118{
@@ -2191,7 +2192,6 @@ static const struct seq_operations unix_seq_ops = {
2191 .show = unix_seq_show, 2192 .show = unix_seq_show,
2192}; 2193};
2193 2194
2194
2195static int unix_seq_open(struct inode *inode, struct file *file) 2195static int unix_seq_open(struct inode *inode, struct file *file)
2196{ 2196{
2197 return seq_open_net(inode, file, &unix_seq_ops, 2197 return seq_open_net(inode, file, &unix_seq_ops,
diff --git a/net/unix/garbage.c b/net/unix/garbage.c
index abb3ab34cb1e..19c17e4a0c8b 100644
--- a/net/unix/garbage.c
+++ b/net/unix/garbage.c
@@ -106,8 +106,8 @@ static struct sock *unix_get_socket(struct file *filp)
106 * Socket ? 106 * Socket ?
107 */ 107 */
108 if (S_ISSOCK(inode->i_mode)) { 108 if (S_ISSOCK(inode->i_mode)) {
109 struct socket * sock = SOCKET_I(inode); 109 struct socket *sock = SOCKET_I(inode);
110 struct sock * s = sock->sk; 110 struct sock *s = sock->sk;
111 111
112 /* 112 /*
113 * PF_UNIX ? 113 * PF_UNIX ?
@@ -126,7 +126,7 @@ static struct sock *unix_get_socket(struct file *filp)
126void unix_inflight(struct file *fp) 126void unix_inflight(struct file *fp)
127{ 127{
128 struct sock *s = unix_get_socket(fp); 128 struct sock *s = unix_get_socket(fp);
129 if(s) { 129 if (s) {
130 struct unix_sock *u = unix_sk(s); 130 struct unix_sock *u = unix_sk(s);
131 spin_lock(&unix_gc_lock); 131 spin_lock(&unix_gc_lock);
132 if (atomic_long_inc_return(&u->inflight) == 1) { 132 if (atomic_long_inc_return(&u->inflight) == 1) {
@@ -143,7 +143,7 @@ void unix_inflight(struct file *fp)
143void unix_notinflight(struct file *fp) 143void unix_notinflight(struct file *fp)
144{ 144{
145 struct sock *s = unix_get_socket(fp); 145 struct sock *s = unix_get_socket(fp);
146 if(s) { 146 if (s) {
147 struct unix_sock *u = unix_sk(s); 147 struct unix_sock *u = unix_sk(s);
148 spin_lock(&unix_gc_lock); 148 spin_lock(&unix_gc_lock);
149 BUG_ON(list_empty(&u->link)); 149 BUG_ON(list_empty(&u->link));
@@ -156,7 +156,7 @@ void unix_notinflight(struct file *fp)
156 156
157static inline struct sk_buff *sock_queue_head(struct sock *sk) 157static inline struct sk_buff *sock_queue_head(struct sock *sk)
158{ 158{
159 return (struct sk_buff *) &sk->sk_receive_queue; 159 return (struct sk_buff *)&sk->sk_receive_queue;
160} 160}
161 161
162#define receive_queue_for_each_skb(sk, next, skb) \ 162#define receive_queue_for_each_skb(sk, next, skb) \
@@ -370,7 +370,7 @@ void unix_gc(void)
370 */ 370 */
371 skb_queue_head_init(&hitlist); 371 skb_queue_head_init(&hitlist);
372 list_for_each_entry(u, &gc_candidates, link) 372 list_for_each_entry(u, &gc_candidates, link)
373 scan_children(&u->sk, inc_inflight, &hitlist); 373 scan_children(&u->sk, inc_inflight, &hitlist);
374 374
375 spin_unlock(&unix_gc_lock); 375 spin_unlock(&unix_gc_lock);
376 376
diff --git a/net/unix/sysctl_net_unix.c b/net/unix/sysctl_net_unix.c
index 77513d7e35f2..83c093077ebc 100644
--- a/net/unix/sysctl_net_unix.c
+++ b/net/unix/sysctl_net_unix.c
@@ -21,7 +21,7 @@ static ctl_table unix_table[] = {
21 .data = &init_net.unx.sysctl_max_dgram_qlen, 21 .data = &init_net.unx.sysctl_max_dgram_qlen,
22 .maxlen = sizeof(int), 22 .maxlen = sizeof(int),
23 .mode = 0644, 23 .mode = 0644,
24 .proc_handler = &proc_dointvec 24 .proc_handler = proc_dointvec
25 }, 25 },
26 { .ctl_name = 0 } 26 { .ctl_name = 0 }
27}; 27};
@@ -61,4 +61,3 @@ void unix_sysctl_unregister(struct net *net)
61 unregister_sysctl_table(net->unx.ctl); 61 unregister_sysctl_table(net->unx.ctl);
62 kfree(table); 62 kfree(table);
63} 63}
64
diff --git a/net/wanrouter/wanmain.c b/net/wanrouter/wanmain.c
index 7f07152bc109..39701dec1dba 100644
--- a/net/wanrouter/wanmain.c
+++ b/net/wanrouter/wanmain.c
@@ -60,6 +60,8 @@
60 60
61#define KMEM_SAFETYZONE 8 61#define KMEM_SAFETYZONE 8
62 62
63#define DEV_TO_SLAVE(dev) (*((struct net_device **)netdev_priv(dev)))
64
63/* 65/*
64 * Function Prototypes 66 * Function Prototypes
65 */ 67 */
@@ -511,7 +513,7 @@ static int wanrouter_device_shutdown(struct wan_device *wandev)
511 if (err) 513 if (err)
512 return err; 514 return err;
513 /* The above function deallocates the current dev 515 /* The above function deallocates the current dev
514 * structure. Therefore, we cannot use dev->priv 516 * structure. Therefore, we cannot use netdev_priv(dev)
515 * as the next element: wandev->dev points to the 517 * as the next element: wandev->dev points to the
516 * next element */ 518 * next element */
517 dev = wandev->dev; 519 dev = wandev->dev;
@@ -589,10 +591,6 @@ static int wanrouter_device_new_if(struct wan_device *wandev,
589 err = -EPROTONOSUPPORT; 591 err = -EPROTONOSUPPORT;
590 goto out; 592 goto out;
591 } else { 593 } else {
592 dev = kzalloc(sizeof(struct net_device), GFP_KERNEL);
593 err = -ENOBUFS;
594 if (dev == NULL)
595 goto out;
596 err = wandev->new_if(wandev, dev, cnf); 594 err = wandev->new_if(wandev, dev, cnf);
597 } 595 }
598 596
@@ -622,10 +620,9 @@ static int wanrouter_device_new_if(struct wan_device *wandev,
622 wandev->dev = dev; 620 wandev->dev = dev;
623 } else { 621 } else {
624 for (slave=wandev->dev; 622 for (slave=wandev->dev;
625 *((struct net_device **)slave->priv); 623 DEV_TO_SLAVE(slave);
626 slave = *((struct net_device **)slave->priv)); 624 slave = DEV_TO_SLAVE(slave))
627 625 DEV_TO_SLAVE(slave) = dev;
628 *((struct net_device **)slave->priv) = dev;
629 } 626 }
630 ++wandev->ndev; 627 ++wandev->ndev;
631 628
@@ -636,15 +633,9 @@ static int wanrouter_device_new_if(struct wan_device *wandev,
636 } 633 }
637 if (wandev->del_if) 634 if (wandev->del_if)
638 wandev->del_if(wandev, dev); 635 wandev->del_if(wandev, dev);
636 free_netdev(dev);
639 } 637 }
640 638
641 /* This code has moved from del_if() function */
642 kfree(dev->priv);
643 dev->priv = NULL;
644
645 /* Sync PPP is disabled */
646 if (cnf->config_id != WANCONFIG_MPPP)
647 kfree(dev);
648out: 639out:
649 kfree(cnf); 640 kfree(cnf);
650 return err; 641 return err;
@@ -734,7 +725,7 @@ static int wanrouter_delete_interface(struct wan_device *wandev, char *name)
734 dev = wandev->dev; 725 dev = wandev->dev;
735 prev = NULL; 726 prev = NULL;
736 while (dev && strcmp(name, dev->name)) { 727 while (dev && strcmp(name, dev->name)) {
737 struct net_device **slave = dev->priv; 728 struct net_device **slave = netdev_priv(dev);
738 prev = dev; 729 prev = dev;
739 dev = *slave; 730 dev = *slave;
740 } 731 }
@@ -751,12 +742,12 @@ static int wanrouter_delete_interface(struct wan_device *wandev, char *name)
751 742
752 lock_adapter_irq(&wandev->lock, &smp_flags); 743 lock_adapter_irq(&wandev->lock, &smp_flags);
753 if (prev) { 744 if (prev) {
754 struct net_device **prev_slave = prev->priv; 745 struct net_device **prev_slave = netdev_priv(prev);
755 struct net_device **slave = dev->priv; 746 struct net_device **slave = netdev_priv(dev);
756 747
757 *prev_slave = *slave; 748 *prev_slave = *slave;
758 } else { 749 } else {
759 struct net_device **slave = dev->priv; 750 struct net_device **slave = netdev_priv(dev);
760 wandev->dev = *slave; 751 wandev->dev = *slave;
761 } 752 }
762 --wandev->ndev; 753 --wandev->ndev;
@@ -764,11 +755,6 @@ static int wanrouter_delete_interface(struct wan_device *wandev, char *name)
764 755
765 printk(KERN_INFO "%s: unregistering '%s'\n", wandev->name, dev->name); 756 printk(KERN_INFO "%s: unregistering '%s'\n", wandev->name, dev->name);
766 757
767 /* Due to new interface linking method using dev->priv,
768 * this code has moved from del_if() function.*/
769 kfree(dev->priv);
770 dev->priv=NULL;
771
772 unregister_netdev(dev); 758 unregister_netdev(dev);
773 759
774 free_netdev(dev); 760 free_netdev(dev);
diff --git a/net/wireless/Kconfig b/net/wireless/Kconfig
index 646c7121dbc0..e28e2b8fa436 100644
--- a/net/wireless/Kconfig
+++ b/net/wireless/Kconfig
@@ -1,6 +1,15 @@
1config CFG80211 1config CFG80211
2 tristate "Improved wireless configuration API" 2 tristate "Improved wireless configuration API"
3 3
4config CFG80211_REG_DEBUG
5 bool "cfg80211 regulatory debugging"
6 depends on CFG80211
7 default n
8 ---help---
9 You can enable this if you want to debug regulatory changes.
10
11 If unsure, say N.
12
4config NL80211 13config NL80211
5 bool "nl80211 new netlink interface support" 14 bool "nl80211 new netlink interface support"
6 depends on CFG80211 15 depends on CFG80211
@@ -40,6 +49,8 @@ config WIRELESS_OLD_REGULATORY
40 ieee80211_regdom module parameter. This is being phased out and you 49 ieee80211_regdom module parameter. This is being phased out and you
41 should stop using them ASAP. 50 should stop using them ASAP.
42 51
52 Note: You will need CRDA if you want 802.11d support
53
43 Say Y unless you have installed a new userspace application. 54 Say Y unless you have installed a new userspace application.
44 Also say Y if have one currently depending on the ieee80211_regdom 55 Also say Y if have one currently depending on the ieee80211_regdom
45 module parameter and cannot port it to use the new userspace 56 module parameter and cannot port it to use the new userspace
@@ -72,3 +83,22 @@ config WIRELESS_EXT_SYSFS
72 83
73 Say Y if you have programs using it, like old versions of 84 Say Y if you have programs using it, like old versions of
74 hal. 85 hal.
86
87config LIB80211
88 tristate "Common routines for IEEE802.11 drivers"
89 default n
90 help
91 This options enables a library of common routines used
92 by IEEE802.11 wireless LAN drivers.
93
94 Drivers should select this themselves if needed. Say Y if
95 you want this built into your kernel.
96
97config LIB80211_CRYPT_WEP
98 tristate
99
100config LIB80211_CRYPT_CCMP
101 tristate
102
103config LIB80211_CRYPT_TKIP
104 tristate
diff --git a/net/wireless/Makefile b/net/wireless/Makefile
index b9f943c45f3b..938a334c8dbc 100644
--- a/net/wireless/Makefile
+++ b/net/wireless/Makefile
@@ -1,5 +1,12 @@
1obj-$(CONFIG_WIRELESS_EXT) += wext.o 1obj-$(CONFIG_WIRELESS_EXT) += wext.o
2obj-$(CONFIG_CFG80211) += cfg80211.o 2obj-$(CONFIG_CFG80211) += cfg80211.o
3obj-$(CONFIG_LIB80211) += lib80211.o
4obj-$(CONFIG_LIB80211_CRYPT_WEP) += lib80211_crypt_wep.o
5obj-$(CONFIG_LIB80211_CRYPT_CCMP) += lib80211_crypt_ccmp.o
6obj-$(CONFIG_LIB80211_CRYPT_TKIP) += lib80211_crypt_tkip.o
3 7
4cfg80211-y += core.o sysfs.o radiotap.o util.o reg.o 8cfg80211-y += core.o sysfs.o radiotap.o util.o reg.o
9cfg80211-$(CONFIG_WIRELESS_EXT) += wext-compat.o
5cfg80211-$(CONFIG_NL80211) += nl80211.o 10cfg80211-$(CONFIG_NL80211) += nl80211.o
11
12ccflags-y += -D__CHECK_ENDIAN__
diff --git a/net/wireless/core.c b/net/wireless/core.c
index 5031db7b275b..b96fc0c3f1c4 100644
--- a/net/wireless/core.c
+++ b/net/wireless/core.c
@@ -19,7 +19,6 @@
19#include "nl80211.h" 19#include "nl80211.h"
20#include "core.h" 20#include "core.h"
21#include "sysfs.h" 21#include "sysfs.h"
22#include "reg.h"
23 22
24/* name for sysfs, %d is appended */ 23/* name for sysfs, %d is appended */
25#define PHY_NAME "phy" 24#define PHY_NAME "phy"
@@ -236,8 +235,7 @@ struct wiphy *wiphy_new(struct cfg80211_ops *ops, int sizeof_priv)
236 mutex_unlock(&cfg80211_drv_mutex); 235 mutex_unlock(&cfg80211_drv_mutex);
237 236
238 /* give it a proper name */ 237 /* give it a proper name */
239 snprintf(drv->wiphy.dev.bus_id, BUS_ID_SIZE, 238 dev_set_name(&drv->wiphy.dev, PHY_NAME "%d", drv->idx);
240 PHY_NAME "%d", drv->idx);
241 239
242 mutex_init(&drv->mtx); 240 mutex_init(&drv->mtx);
243 mutex_init(&drv->devlist_mtx); 241 mutex_init(&drv->devlist_mtx);
@@ -301,12 +299,10 @@ int wiphy_register(struct wiphy *wiphy)
301 /* check and set up bitrates */ 299 /* check and set up bitrates */
302 ieee80211_set_bitrate_flags(wiphy); 300 ieee80211_set_bitrate_flags(wiphy);
303 301
302 mutex_lock(&cfg80211_drv_mutex);
303
304 /* set up regulatory info */ 304 /* set up regulatory info */
305 mutex_lock(&cfg80211_reg_mutex);
306 wiphy_update_regulatory(wiphy, REGDOM_SET_BY_CORE); 305 wiphy_update_regulatory(wiphy, REGDOM_SET_BY_CORE);
307 mutex_unlock(&cfg80211_reg_mutex);
308
309 mutex_lock(&cfg80211_drv_mutex);
310 306
311 res = device_add(&drv->wiphy.dev); 307 res = device_add(&drv->wiphy.dev);
312 if (res) 308 if (res)
@@ -351,6 +347,10 @@ void wiphy_unregister(struct wiphy *wiphy)
351 /* unlock again before freeing */ 347 /* unlock again before freeing */
352 mutex_unlock(&drv->mtx); 348 mutex_unlock(&drv->mtx);
353 349
350 /* If this device got a regulatory hint tell core its
351 * free to listen now to a new shiny device regulatory hint */
352 reg_device_remove(wiphy);
353
354 list_del(&drv->list); 354 list_del(&drv->list);
355 device_del(&drv->wiphy.dev); 355 device_del(&drv->wiphy.dev);
356 debugfs_remove(drv->wiphy.debugfsdir); 356 debugfs_remove(drv->wiphy.debugfsdir);
diff --git a/net/wireless/core.h b/net/wireless/core.h
index 771cc5cc7658..f7fb9f413028 100644
--- a/net/wireless/core.h
+++ b/net/wireless/core.h
@@ -11,6 +11,7 @@
11#include <net/genetlink.h> 11#include <net/genetlink.h>
12#include <net/wireless.h> 12#include <net/wireless.h>
13#include <net/cfg80211.h> 13#include <net/cfg80211.h>
14#include "reg.h"
14 15
15struct cfg80211_registered_device { 16struct cfg80211_registered_device {
16 struct cfg80211_ops *ops; 17 struct cfg80211_ops *ops;
@@ -21,6 +22,18 @@ struct cfg80211_registered_device {
21 * any call is in progress */ 22 * any call is in progress */
22 struct mutex mtx; 23 struct mutex mtx;
23 24
25 /* ISO / IEC 3166 alpha2 for which this device is receiving
26 * country IEs on, this can help disregard country IEs from APs
27 * on the same alpha2 quickly. The alpha2 may differ from
28 * cfg80211_regdomain's alpha2 when an intersection has occurred.
29 * If the AP is reconfigured this can also be used to tell us if
30 * the country on the country IE changed. */
31 char country_ie_alpha2[2];
32
33 /* If a Country IE has been received this tells us the environment
34 * which its telling us its in. This defaults to ENVIRON_ANY */
35 enum environment_cap env;
36
24 /* wiphy index, internal only */ 37 /* wiphy index, internal only */
25 int idx; 38 int idx;
26 39
diff --git a/net/wireless/lib80211.c b/net/wireless/lib80211.c
new file mode 100644
index 000000000000..97d411f74507
--- /dev/null
+++ b/net/wireless/lib80211.c
@@ -0,0 +1,284 @@
1/*
2 * lib80211 -- common bits for IEEE802.11 drivers
3 *
4 * Copyright(c) 2008 John W. Linville <linville@tuxdriver.com>
5 *
6 * Portions copied from old ieee80211 component, w/ original copyright
7 * notices below:
8 *
9 * Host AP crypto routines
10 *
11 * Copyright (c) 2002-2003, Jouni Malinen <j@w1.fi>
12 * Portions Copyright (C) 2004, Intel Corporation <jketreno@linux.intel.com>
13 *
14 */
15
16#include <linux/module.h>
17#include <linux/ctype.h>
18#include <linux/ieee80211.h>
19#include <linux/errno.h>
20#include <linux/init.h>
21#include <linux/slab.h>
22#include <linux/string.h>
23
24#include <net/lib80211.h>
25
26#define DRV_NAME "lib80211"
27
28#define DRV_DESCRIPTION "common routines for IEEE802.11 drivers"
29
30MODULE_DESCRIPTION(DRV_DESCRIPTION);
31MODULE_AUTHOR("John W. Linville <linville@tuxdriver.com>");
32MODULE_LICENSE("GPL");
33
34struct lib80211_crypto_alg {
35 struct list_head list;
36 struct lib80211_crypto_ops *ops;
37};
38
39static LIST_HEAD(lib80211_crypto_algs);
40static DEFINE_SPINLOCK(lib80211_crypto_lock);
41
42const char *print_ssid(char *buf, const char *ssid, u8 ssid_len)
43{
44 const char *s = ssid;
45 char *d = buf;
46
47 ssid_len = min_t(u8, ssid_len, IEEE80211_MAX_SSID_LEN);
48 while (ssid_len--) {
49 if (isprint(*s)) {
50 *d++ = *s++;
51 continue;
52 }
53
54 *d++ = '\\';
55 if (*s == '\0')
56 *d++ = '0';
57 else if (*s == '\n')
58 *d++ = 'n';
59 else if (*s == '\r')
60 *d++ = 'r';
61 else if (*s == '\t')
62 *d++ = 't';
63 else if (*s == '\\')
64 *d++ = '\\';
65 else
66 d += snprintf(d, 3, "%03o", *s);
67 s++;
68 }
69 *d = '\0';
70 return buf;
71}
72EXPORT_SYMBOL(print_ssid);
73
74int lib80211_crypt_info_init(struct lib80211_crypt_info *info, char *name,
75 spinlock_t *lock)
76{
77 memset(info, 0, sizeof(*info));
78
79 info->name = name;
80 info->lock = lock;
81
82 INIT_LIST_HEAD(&info->crypt_deinit_list);
83 setup_timer(&info->crypt_deinit_timer, lib80211_crypt_deinit_handler,
84 (unsigned long)info);
85
86 return 0;
87}
88EXPORT_SYMBOL(lib80211_crypt_info_init);
89
90void lib80211_crypt_info_free(struct lib80211_crypt_info *info)
91{
92 int i;
93
94 lib80211_crypt_quiescing(info);
95 del_timer_sync(&info->crypt_deinit_timer);
96 lib80211_crypt_deinit_entries(info, 1);
97
98 for (i = 0; i < NUM_WEP_KEYS; i++) {
99 struct lib80211_crypt_data *crypt = info->crypt[i];
100 if (crypt) {
101 if (crypt->ops) {
102 crypt->ops->deinit(crypt->priv);
103 module_put(crypt->ops->owner);
104 }
105 kfree(crypt);
106 info->crypt[i] = NULL;
107 }
108 }
109}
110EXPORT_SYMBOL(lib80211_crypt_info_free);
111
112void lib80211_crypt_deinit_entries(struct lib80211_crypt_info *info, int force)
113{
114 struct lib80211_crypt_data *entry, *next;
115 unsigned long flags;
116
117 spin_lock_irqsave(info->lock, flags);
118 list_for_each_entry_safe(entry, next, &info->crypt_deinit_list, list) {
119 if (atomic_read(&entry->refcnt) != 0 && !force)
120 continue;
121
122 list_del(&entry->list);
123
124 if (entry->ops) {
125 entry->ops->deinit(entry->priv);
126 module_put(entry->ops->owner);
127 }
128 kfree(entry);
129 }
130 spin_unlock_irqrestore(info->lock, flags);
131}
132EXPORT_SYMBOL(lib80211_crypt_deinit_entries);
133
134/* After this, crypt_deinit_list won't accept new members */
135void lib80211_crypt_quiescing(struct lib80211_crypt_info *info)
136{
137 unsigned long flags;
138
139 spin_lock_irqsave(info->lock, flags);
140 info->crypt_quiesced = 1;
141 spin_unlock_irqrestore(info->lock, flags);
142}
143EXPORT_SYMBOL(lib80211_crypt_quiescing);
144
145void lib80211_crypt_deinit_handler(unsigned long data)
146{
147 struct lib80211_crypt_info *info = (struct lib80211_crypt_info *)data;
148 unsigned long flags;
149
150 lib80211_crypt_deinit_entries(info, 0);
151
152 spin_lock_irqsave(info->lock, flags);
153 if (!list_empty(&info->crypt_deinit_list) && !info->crypt_quiesced) {
154 printk(KERN_DEBUG "%s: entries remaining in delayed crypt "
155 "deletion list\n", info->name);
156 info->crypt_deinit_timer.expires = jiffies + HZ;
157 add_timer(&info->crypt_deinit_timer);
158 }
159 spin_unlock_irqrestore(info->lock, flags);
160}
161EXPORT_SYMBOL(lib80211_crypt_deinit_handler);
162
163void lib80211_crypt_delayed_deinit(struct lib80211_crypt_info *info,
164 struct lib80211_crypt_data **crypt)
165{
166 struct lib80211_crypt_data *tmp;
167 unsigned long flags;
168
169 if (*crypt == NULL)
170 return;
171
172 tmp = *crypt;
173 *crypt = NULL;
174
175 /* must not run ops->deinit() while there may be pending encrypt or
176 * decrypt operations. Use a list of delayed deinits to avoid needing
177 * locking. */
178
179 spin_lock_irqsave(info->lock, flags);
180 if (!info->crypt_quiesced) {
181 list_add(&tmp->list, &info->crypt_deinit_list);
182 if (!timer_pending(&info->crypt_deinit_timer)) {
183 info->crypt_deinit_timer.expires = jiffies + HZ;
184 add_timer(&info->crypt_deinit_timer);
185 }
186 }
187 spin_unlock_irqrestore(info->lock, flags);
188}
189EXPORT_SYMBOL(lib80211_crypt_delayed_deinit);
190
191int lib80211_register_crypto_ops(struct lib80211_crypto_ops *ops)
192{
193 unsigned long flags;
194 struct lib80211_crypto_alg *alg;
195
196 alg = kzalloc(sizeof(*alg), GFP_KERNEL);
197 if (alg == NULL)
198 return -ENOMEM;
199
200 alg->ops = ops;
201
202 spin_lock_irqsave(&lib80211_crypto_lock, flags);
203 list_add(&alg->list, &lib80211_crypto_algs);
204 spin_unlock_irqrestore(&lib80211_crypto_lock, flags);
205
206 printk(KERN_DEBUG "lib80211_crypt: registered algorithm '%s'\n",
207 ops->name);
208
209 return 0;
210}
211EXPORT_SYMBOL(lib80211_register_crypto_ops);
212
213int lib80211_unregister_crypto_ops(struct lib80211_crypto_ops *ops)
214{
215 struct lib80211_crypto_alg *alg;
216 unsigned long flags;
217
218 spin_lock_irqsave(&lib80211_crypto_lock, flags);
219 list_for_each_entry(alg, &lib80211_crypto_algs, list) {
220 if (alg->ops == ops)
221 goto found;
222 }
223 spin_unlock_irqrestore(&lib80211_crypto_lock, flags);
224 return -EINVAL;
225
226 found:
227 printk(KERN_DEBUG "lib80211_crypt: unregistered algorithm "
228 "'%s'\n", ops->name);
229 list_del(&alg->list);
230 spin_unlock_irqrestore(&lib80211_crypto_lock, flags);
231 kfree(alg);
232 return 0;
233}
234EXPORT_SYMBOL(lib80211_unregister_crypto_ops);
235
236struct lib80211_crypto_ops *lib80211_get_crypto_ops(const char *name)
237{
238 struct lib80211_crypto_alg *alg;
239 unsigned long flags;
240
241 spin_lock_irqsave(&lib80211_crypto_lock, flags);
242 list_for_each_entry(alg, &lib80211_crypto_algs, list) {
243 if (strcmp(alg->ops->name, name) == 0)
244 goto found;
245 }
246 spin_unlock_irqrestore(&lib80211_crypto_lock, flags);
247 return NULL;
248
249 found:
250 spin_unlock_irqrestore(&lib80211_crypto_lock, flags);
251 return alg->ops;
252}
253EXPORT_SYMBOL(lib80211_get_crypto_ops);
254
255static void *lib80211_crypt_null_init(int keyidx)
256{
257 return (void *)1;
258}
259
260static void lib80211_crypt_null_deinit(void *priv)
261{
262}
263
264static struct lib80211_crypto_ops lib80211_crypt_null = {
265 .name = "NULL",
266 .init = lib80211_crypt_null_init,
267 .deinit = lib80211_crypt_null_deinit,
268 .owner = THIS_MODULE,
269};
270
271static int __init lib80211_init(void)
272{
273 printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION "\n");
274 return lib80211_register_crypto_ops(&lib80211_crypt_null);
275}
276
277static void __exit lib80211_exit(void)
278{
279 lib80211_unregister_crypto_ops(&lib80211_crypt_null);
280 BUG_ON(!list_empty(&lib80211_crypto_algs));
281}
282
283module_init(lib80211_init);
284module_exit(lib80211_exit);
diff --git a/net/ieee80211/ieee80211_crypt_ccmp.c b/net/wireless/lib80211_crypt_ccmp.c
index 208bf35b5546..db428194c16a 100644
--- a/net/ieee80211/ieee80211_crypt_ccmp.c
+++ b/net/wireless/lib80211_crypt_ccmp.c
@@ -1,7 +1,8 @@
1/* 1/*
2 * Host AP crypt: host-based CCMP encryption implementation for Host AP driver 2 * lib80211 crypt: host-based CCMP encryption implementation for lib80211
3 * 3 *
4 * Copyright (c) 2003-2004, Jouni Malinen <j@w1.fi> 4 * Copyright (c) 2003-2004, Jouni Malinen <j@w1.fi>
5 * Copyright (c) 2008, John W. Linville <linville@tuxdriver.com>
5 * 6 *
6 * This program is free software; you can redistribute it and/or modify 7 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as 8 * it under the terms of the GNU General Public License version 2 as
@@ -22,10 +23,12 @@
22#include <asm/string.h> 23#include <asm/string.h>
23#include <linux/wireless.h> 24#include <linux/wireless.h>
24 25
25#include <net/ieee80211.h> 26#include <linux/ieee80211.h>
26 27
27#include <linux/crypto.h> 28#include <linux/crypto.h>
28 29
30#include <net/lib80211.h>
31
29MODULE_AUTHOR("Jouni Malinen"); 32MODULE_AUTHOR("Jouni Malinen");
30MODULE_DESCRIPTION("Host AP crypt: CCMP"); 33MODULE_DESCRIPTION("Host AP crypt: CCMP");
31MODULE_LICENSE("GPL"); 34MODULE_LICENSE("GPL");
@@ -36,7 +39,7 @@ MODULE_LICENSE("GPL");
36#define CCMP_TK_LEN 16 39#define CCMP_TK_LEN 16
37#define CCMP_PN_LEN 6 40#define CCMP_PN_LEN 6
38 41
39struct ieee80211_ccmp_data { 42struct lib80211_ccmp_data {
40 u8 key[CCMP_TK_LEN]; 43 u8 key[CCMP_TK_LEN];
41 int key_set; 44 int key_set;
42 45
@@ -57,15 +60,15 @@ struct ieee80211_ccmp_data {
57 u8 rx_b0[AES_BLOCK_LEN], rx_b[AES_BLOCK_LEN], rx_a[AES_BLOCK_LEN]; 60 u8 rx_b0[AES_BLOCK_LEN], rx_b[AES_BLOCK_LEN], rx_a[AES_BLOCK_LEN];
58}; 61};
59 62
60static inline void ieee80211_ccmp_aes_encrypt(struct crypto_cipher *tfm, 63static inline void lib80211_ccmp_aes_encrypt(struct crypto_cipher *tfm,
61 const u8 pt[16], u8 ct[16]) 64 const u8 pt[16], u8 ct[16])
62{ 65{
63 crypto_cipher_encrypt_one(tfm, ct, pt); 66 crypto_cipher_encrypt_one(tfm, ct, pt);
64} 67}
65 68
66static void *ieee80211_ccmp_init(int key_idx) 69static void *lib80211_ccmp_init(int key_idx)
67{ 70{
68 struct ieee80211_ccmp_data *priv; 71 struct lib80211_ccmp_data *priv;
69 72
70 priv = kzalloc(sizeof(*priv), GFP_ATOMIC); 73 priv = kzalloc(sizeof(*priv), GFP_ATOMIC);
71 if (priv == NULL) 74 if (priv == NULL)
@@ -74,7 +77,7 @@ static void *ieee80211_ccmp_init(int key_idx)
74 77
75 priv->tfm = crypto_alloc_cipher("aes", 0, CRYPTO_ALG_ASYNC); 78 priv->tfm = crypto_alloc_cipher("aes", 0, CRYPTO_ALG_ASYNC);
76 if (IS_ERR(priv->tfm)) { 79 if (IS_ERR(priv->tfm)) {
77 printk(KERN_DEBUG "ieee80211_crypt_ccmp: could not allocate " 80 printk(KERN_DEBUG "lib80211_crypt_ccmp: could not allocate "
78 "crypto API aes\n"); 81 "crypto API aes\n");
79 priv->tfm = NULL; 82 priv->tfm = NULL;
80 goto fail; 83 goto fail;
@@ -92,9 +95,9 @@ static void *ieee80211_ccmp_init(int key_idx)
92 return NULL; 95 return NULL;
93} 96}
94 97
95static void ieee80211_ccmp_deinit(void *priv) 98static void lib80211_ccmp_deinit(void *priv)
96{ 99{
97 struct ieee80211_ccmp_data *_priv = priv; 100 struct lib80211_ccmp_data *_priv = priv;
98 if (_priv && _priv->tfm) 101 if (_priv && _priv->tfm)
99 crypto_free_cipher(_priv->tfm); 102 crypto_free_cipher(_priv->tfm);
100 kfree(priv); 103 kfree(priv);
@@ -108,20 +111,17 @@ static inline void xor_block(u8 * b, u8 * a, size_t len)
108} 111}
109 112
110static void ccmp_init_blocks(struct crypto_cipher *tfm, 113static void ccmp_init_blocks(struct crypto_cipher *tfm,
111 struct ieee80211_hdr_4addr *hdr, 114 struct ieee80211_hdr *hdr,
112 u8 * pn, size_t dlen, u8 * b0, u8 * auth, u8 * s0) 115 u8 * pn, size_t dlen, u8 * b0, u8 * auth, u8 * s0)
113{ 116{
114 u8 *pos, qc = 0; 117 u8 *pos, qc = 0;
115 size_t aad_len; 118 size_t aad_len;
116 u16 fc;
117 int a4_included, qc_included; 119 int a4_included, qc_included;
118 u8 aad[2 * AES_BLOCK_LEN]; 120 u8 aad[2 * AES_BLOCK_LEN];
119 121
120 fc = le16_to_cpu(hdr->frame_ctl); 122 a4_included = ieee80211_has_a4(hdr->frame_control);
121 a4_included = ((fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) == 123 qc_included = ieee80211_is_data_qos(hdr->frame_control);
122 (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)); 124
123 qc_included = ((WLAN_FC_GET_TYPE(fc) == IEEE80211_FTYPE_DATA) &&
124 (WLAN_FC_GET_STYPE(fc) & IEEE80211_STYPE_QOS_DATA));
125 aad_len = 22; 125 aad_len = 22;
126 if (a4_included) 126 if (a4_included)
127 aad_len += 6; 127 aad_len += 6;
@@ -158,7 +158,7 @@ static void ccmp_init_blocks(struct crypto_cipher *tfm,
158 aad[2] = pos[0] & 0x8f; 158 aad[2] = pos[0] & 0x8f;
159 aad[3] = pos[1] & 0xc7; 159 aad[3] = pos[1] & 0xc7;
160 memcpy(aad + 4, hdr->addr1, 3 * ETH_ALEN); 160 memcpy(aad + 4, hdr->addr1, 3 * ETH_ALEN);
161 pos = (u8 *) & hdr->seq_ctl; 161 pos = (u8 *) & hdr->seq_ctrl;
162 aad[22] = pos[0] & 0x0f; 162 aad[22] = pos[0] & 0x0f;
163 aad[23] = 0; /* all bits masked */ 163 aad[23] = 0; /* all bits masked */
164 memset(aad + 24, 0, 8); 164 memset(aad + 24, 0, 8);
@@ -170,20 +170,20 @@ static void ccmp_init_blocks(struct crypto_cipher *tfm,
170 } 170 }
171 171
172 /* Start with the first block and AAD */ 172 /* Start with the first block and AAD */
173 ieee80211_ccmp_aes_encrypt(tfm, b0, auth); 173 lib80211_ccmp_aes_encrypt(tfm, b0, auth);
174 xor_block(auth, aad, AES_BLOCK_LEN); 174 xor_block(auth, aad, AES_BLOCK_LEN);
175 ieee80211_ccmp_aes_encrypt(tfm, auth, auth); 175 lib80211_ccmp_aes_encrypt(tfm, auth, auth);
176 xor_block(auth, &aad[AES_BLOCK_LEN], AES_BLOCK_LEN); 176 xor_block(auth, &aad[AES_BLOCK_LEN], AES_BLOCK_LEN);
177 ieee80211_ccmp_aes_encrypt(tfm, auth, auth); 177 lib80211_ccmp_aes_encrypt(tfm, auth, auth);
178 b0[0] &= 0x07; 178 b0[0] &= 0x07;
179 b0[14] = b0[15] = 0; 179 b0[14] = b0[15] = 0;
180 ieee80211_ccmp_aes_encrypt(tfm, b0, s0); 180 lib80211_ccmp_aes_encrypt(tfm, b0, s0);
181} 181}
182 182
183static int ieee80211_ccmp_hdr(struct sk_buff *skb, int hdr_len, 183static int lib80211_ccmp_hdr(struct sk_buff *skb, int hdr_len,
184 u8 *aeskey, int keylen, void *priv) 184 u8 *aeskey, int keylen, void *priv)
185{ 185{
186 struct ieee80211_ccmp_data *key = priv; 186 struct lib80211_ccmp_data *key = priv;
187 int i; 187 int i;
188 u8 *pos; 188 u8 *pos;
189 189
@@ -217,12 +217,12 @@ static int ieee80211_ccmp_hdr(struct sk_buff *skb, int hdr_len,
217 return CCMP_HDR_LEN; 217 return CCMP_HDR_LEN;
218} 218}
219 219
220static int ieee80211_ccmp_encrypt(struct sk_buff *skb, int hdr_len, void *priv) 220static int lib80211_ccmp_encrypt(struct sk_buff *skb, int hdr_len, void *priv)
221{ 221{
222 struct ieee80211_ccmp_data *key = priv; 222 struct lib80211_ccmp_data *key = priv;
223 int data_len, i, blocks, last, len; 223 int data_len, i, blocks, last, len;
224 u8 *pos, *mic; 224 u8 *pos, *mic;
225 struct ieee80211_hdr_4addr *hdr; 225 struct ieee80211_hdr *hdr;
226 u8 *b0 = key->tx_b0; 226 u8 *b0 = key->tx_b0;
227 u8 *b = key->tx_b; 227 u8 *b = key->tx_b;
228 u8 *e = key->tx_e; 228 u8 *e = key->tx_e;
@@ -232,13 +232,13 @@ static int ieee80211_ccmp_encrypt(struct sk_buff *skb, int hdr_len, void *priv)
232 return -1; 232 return -1;
233 233
234 data_len = skb->len - hdr_len; 234 data_len = skb->len - hdr_len;
235 len = ieee80211_ccmp_hdr(skb, hdr_len, NULL, 0, priv); 235 len = lib80211_ccmp_hdr(skb, hdr_len, NULL, 0, priv);
236 if (len < 0) 236 if (len < 0)
237 return -1; 237 return -1;
238 238
239 pos = skb->data + hdr_len + CCMP_HDR_LEN; 239 pos = skb->data + hdr_len + CCMP_HDR_LEN;
240 mic = skb_put(skb, CCMP_MIC_LEN); 240 mic = skb_put(skb, CCMP_MIC_LEN);
241 hdr = (struct ieee80211_hdr_4addr *)skb->data; 241 hdr = (struct ieee80211_hdr *)skb->data;
242 ccmp_init_blocks(key->tfm, hdr, key->tx_pn, data_len, b0, b, s0); 242 ccmp_init_blocks(key->tfm, hdr, key->tx_pn, data_len, b0, b, s0);
243 243
244 blocks = DIV_ROUND_UP(data_len, AES_BLOCK_LEN); 244 blocks = DIV_ROUND_UP(data_len, AES_BLOCK_LEN);
@@ -248,11 +248,11 @@ static int ieee80211_ccmp_encrypt(struct sk_buff *skb, int hdr_len, void *priv)
248 len = (i == blocks && last) ? last : AES_BLOCK_LEN; 248 len = (i == blocks && last) ? last : AES_BLOCK_LEN;
249 /* Authentication */ 249 /* Authentication */
250 xor_block(b, pos, len); 250 xor_block(b, pos, len);
251 ieee80211_ccmp_aes_encrypt(key->tfm, b, b); 251 lib80211_ccmp_aes_encrypt(key->tfm, b, b);
252 /* Encryption, with counter */ 252 /* Encryption, with counter */
253 b0[14] = (i >> 8) & 0xff; 253 b0[14] = (i >> 8) & 0xff;
254 b0[15] = i & 0xff; 254 b0[15] = i & 0xff;
255 ieee80211_ccmp_aes_encrypt(key->tfm, b0, e); 255 lib80211_ccmp_aes_encrypt(key->tfm, b0, e);
256 xor_block(pos, e, len); 256 xor_block(pos, e, len);
257 pos += len; 257 pos += len;
258 } 258 }
@@ -284,11 +284,11 @@ static inline int ccmp_replay_check(u8 *pn_n, u8 *pn_o)
284 return 0; 284 return 0;
285} 285}
286 286
287static int ieee80211_ccmp_decrypt(struct sk_buff *skb, int hdr_len, void *priv) 287static int lib80211_ccmp_decrypt(struct sk_buff *skb, int hdr_len, void *priv)
288{ 288{
289 struct ieee80211_ccmp_data *key = priv; 289 struct lib80211_ccmp_data *key = priv;
290 u8 keyidx, *pos; 290 u8 keyidx, *pos;
291 struct ieee80211_hdr_4addr *hdr; 291 struct ieee80211_hdr *hdr;
292 u8 *b0 = key->rx_b0; 292 u8 *b0 = key->rx_b0;
293 u8 *b = key->rx_b; 293 u8 *b = key->rx_b;
294 u8 *a = key->rx_a; 294 u8 *a = key->rx_a;
@@ -296,20 +296,19 @@ static int ieee80211_ccmp_decrypt(struct sk_buff *skb, int hdr_len, void *priv)
296 int i, blocks, last, len; 296 int i, blocks, last, len;
297 size_t data_len = skb->len - hdr_len - CCMP_HDR_LEN - CCMP_MIC_LEN; 297 size_t data_len = skb->len - hdr_len - CCMP_HDR_LEN - CCMP_MIC_LEN;
298 u8 *mic = skb->data + skb->len - CCMP_MIC_LEN; 298 u8 *mic = skb->data + skb->len - CCMP_MIC_LEN;
299 DECLARE_MAC_BUF(mac);
300 299
301 if (skb->len < hdr_len + CCMP_HDR_LEN + CCMP_MIC_LEN) { 300 if (skb->len < hdr_len + CCMP_HDR_LEN + CCMP_MIC_LEN) {
302 key->dot11RSNAStatsCCMPFormatErrors++; 301 key->dot11RSNAStatsCCMPFormatErrors++;
303 return -1; 302 return -1;
304 } 303 }
305 304
306 hdr = (struct ieee80211_hdr_4addr *)skb->data; 305 hdr = (struct ieee80211_hdr *)skb->data;
307 pos = skb->data + hdr_len; 306 pos = skb->data + hdr_len;
308 keyidx = pos[3]; 307 keyidx = pos[3];
309 if (!(keyidx & (1 << 5))) { 308 if (!(keyidx & (1 << 5))) {
310 if (net_ratelimit()) { 309 if (net_ratelimit()) {
311 printk(KERN_DEBUG "CCMP: received packet without ExtIV" 310 printk(KERN_DEBUG "CCMP: received packet without ExtIV"
312 " flag from %s\n", print_mac(mac, hdr->addr2)); 311 " flag from %pM\n", hdr->addr2);
313 } 312 }
314 key->dot11RSNAStatsCCMPFormatErrors++; 313 key->dot11RSNAStatsCCMPFormatErrors++;
315 return -2; 314 return -2;
@@ -322,9 +321,9 @@ static int ieee80211_ccmp_decrypt(struct sk_buff *skb, int hdr_len, void *priv)
322 } 321 }
323 if (!key->key_set) { 322 if (!key->key_set) {
324 if (net_ratelimit()) { 323 if (net_ratelimit()) {
325 printk(KERN_DEBUG "CCMP: received packet from %s" 324 printk(KERN_DEBUG "CCMP: received packet from %pM"
326 " with keyid=%d that does not have a configured" 325 " with keyid=%d that does not have a configured"
327 " key\n", print_mac(mac, hdr->addr2), keyidx); 326 " key\n", hdr->addr2, keyidx);
328 } 327 }
329 return -3; 328 return -3;
330 } 329 }
@@ -338,11 +337,11 @@ static int ieee80211_ccmp_decrypt(struct sk_buff *skb, int hdr_len, void *priv)
338 pos += 8; 337 pos += 8;
339 338
340 if (ccmp_replay_check(pn, key->rx_pn)) { 339 if (ccmp_replay_check(pn, key->rx_pn)) {
341 if (ieee80211_ratelimit_debug(IEEE80211_DL_DROP)) { 340 if (net_ratelimit()) {
342 IEEE80211_DEBUG_DROP("CCMP: replay detected: STA=%s " 341 printk(KERN_DEBUG "CCMP: replay detected: STA=%pM "
343 "previous PN %02x%02x%02x%02x%02x%02x " 342 "previous PN %02x%02x%02x%02x%02x%02x "
344 "received PN %02x%02x%02x%02x%02x%02x\n", 343 "received PN %02x%02x%02x%02x%02x%02x\n",
345 print_mac(mac, hdr->addr2), 344 hdr->addr2,
346 key->rx_pn[0], key->rx_pn[1], key->rx_pn[2], 345 key->rx_pn[0], key->rx_pn[1], key->rx_pn[2],
347 key->rx_pn[3], key->rx_pn[4], key->rx_pn[5], 346 key->rx_pn[3], key->rx_pn[4], key->rx_pn[5],
348 pn[0], pn[1], pn[2], pn[3], pn[4], pn[5]); 347 pn[0], pn[1], pn[2], pn[3], pn[4], pn[5]);
@@ -362,18 +361,18 @@ static int ieee80211_ccmp_decrypt(struct sk_buff *skb, int hdr_len, void *priv)
362 /* Decrypt, with counter */ 361 /* Decrypt, with counter */
363 b0[14] = (i >> 8) & 0xff; 362 b0[14] = (i >> 8) & 0xff;
364 b0[15] = i & 0xff; 363 b0[15] = i & 0xff;
365 ieee80211_ccmp_aes_encrypt(key->tfm, b0, b); 364 lib80211_ccmp_aes_encrypt(key->tfm, b0, b);
366 xor_block(pos, b, len); 365 xor_block(pos, b, len);
367 /* Authentication */ 366 /* Authentication */
368 xor_block(a, pos, len); 367 xor_block(a, pos, len);
369 ieee80211_ccmp_aes_encrypt(key->tfm, a, a); 368 lib80211_ccmp_aes_encrypt(key->tfm, a, a);
370 pos += len; 369 pos += len;
371 } 370 }
372 371
373 if (memcmp(mic, a, CCMP_MIC_LEN) != 0) { 372 if (memcmp(mic, a, CCMP_MIC_LEN) != 0) {
374 if (net_ratelimit()) { 373 if (net_ratelimit()) {
375 printk(KERN_DEBUG "CCMP: decrypt failed: STA=" 374 printk(KERN_DEBUG "CCMP: decrypt failed: STA="
376 "%s\n", print_mac(mac, hdr->addr2)); 375 "%pM\n", hdr->addr2);
377 } 376 }
378 key->dot11RSNAStatsCCMPDecryptErrors++; 377 key->dot11RSNAStatsCCMPDecryptErrors++;
379 return -5; 378 return -5;
@@ -389,9 +388,9 @@ static int ieee80211_ccmp_decrypt(struct sk_buff *skb, int hdr_len, void *priv)
389 return keyidx; 388 return keyidx;
390} 389}
391 390
392static int ieee80211_ccmp_set_key(void *key, int len, u8 * seq, void *priv) 391static int lib80211_ccmp_set_key(void *key, int len, u8 * seq, void *priv)
393{ 392{
394 struct ieee80211_ccmp_data *data = priv; 393 struct lib80211_ccmp_data *data = priv;
395 int keyidx; 394 int keyidx;
396 struct crypto_cipher *tfm = data->tfm; 395 struct crypto_cipher *tfm = data->tfm;
397 396
@@ -419,9 +418,9 @@ static int ieee80211_ccmp_set_key(void *key, int len, u8 * seq, void *priv)
419 return 0; 418 return 0;
420} 419}
421 420
422static int ieee80211_ccmp_get_key(void *key, int len, u8 * seq, void *priv) 421static int lib80211_ccmp_get_key(void *key, int len, u8 * seq, void *priv)
423{ 422{
424 struct ieee80211_ccmp_data *data = priv; 423 struct lib80211_ccmp_data *data = priv;
425 424
426 if (len < CCMP_TK_LEN) 425 if (len < CCMP_TK_LEN)
427 return -1; 426 return -1;
@@ -442,9 +441,9 @@ static int ieee80211_ccmp_get_key(void *key, int len, u8 * seq, void *priv)
442 return CCMP_TK_LEN; 441 return CCMP_TK_LEN;
443} 442}
444 443
445static char *ieee80211_ccmp_print_stats(char *p, void *priv) 444static char *lib80211_ccmp_print_stats(char *p, void *priv)
446{ 445{
447 struct ieee80211_ccmp_data *ccmp = priv; 446 struct lib80211_ccmp_data *ccmp = priv;
448 447
449 p += sprintf(p, "key[%d] alg=CCMP key_set=%d " 448 p += sprintf(p, "key[%d] alg=CCMP key_set=%d "
450 "tx_pn=%02x%02x%02x%02x%02x%02x " 449 "tx_pn=%02x%02x%02x%02x%02x%02x "
@@ -462,32 +461,32 @@ static char *ieee80211_ccmp_print_stats(char *p, void *priv)
462 return p; 461 return p;
463} 462}
464 463
465static struct ieee80211_crypto_ops ieee80211_crypt_ccmp = { 464static struct lib80211_crypto_ops lib80211_crypt_ccmp = {
466 .name = "CCMP", 465 .name = "CCMP",
467 .init = ieee80211_ccmp_init, 466 .init = lib80211_ccmp_init,
468 .deinit = ieee80211_ccmp_deinit, 467 .deinit = lib80211_ccmp_deinit,
469 .build_iv = ieee80211_ccmp_hdr, 468 .build_iv = lib80211_ccmp_hdr,
470 .encrypt_mpdu = ieee80211_ccmp_encrypt, 469 .encrypt_mpdu = lib80211_ccmp_encrypt,
471 .decrypt_mpdu = ieee80211_ccmp_decrypt, 470 .decrypt_mpdu = lib80211_ccmp_decrypt,
472 .encrypt_msdu = NULL, 471 .encrypt_msdu = NULL,
473 .decrypt_msdu = NULL, 472 .decrypt_msdu = NULL,
474 .set_key = ieee80211_ccmp_set_key, 473 .set_key = lib80211_ccmp_set_key,
475 .get_key = ieee80211_ccmp_get_key, 474 .get_key = lib80211_ccmp_get_key,
476 .print_stats = ieee80211_ccmp_print_stats, 475 .print_stats = lib80211_ccmp_print_stats,
477 .extra_mpdu_prefix_len = CCMP_HDR_LEN, 476 .extra_mpdu_prefix_len = CCMP_HDR_LEN,
478 .extra_mpdu_postfix_len = CCMP_MIC_LEN, 477 .extra_mpdu_postfix_len = CCMP_MIC_LEN,
479 .owner = THIS_MODULE, 478 .owner = THIS_MODULE,
480}; 479};
481 480
482static int __init ieee80211_crypto_ccmp_init(void) 481static int __init lib80211_crypto_ccmp_init(void)
483{ 482{
484 return ieee80211_register_crypto_ops(&ieee80211_crypt_ccmp); 483 return lib80211_register_crypto_ops(&lib80211_crypt_ccmp);
485} 484}
486 485
487static void __exit ieee80211_crypto_ccmp_exit(void) 486static void __exit lib80211_crypto_ccmp_exit(void)
488{ 487{
489 ieee80211_unregister_crypto_ops(&ieee80211_crypt_ccmp); 488 lib80211_unregister_crypto_ops(&lib80211_crypt_ccmp);
490} 489}
491 490
492module_init(ieee80211_crypto_ccmp_init); 491module_init(lib80211_crypto_ccmp_init);
493module_exit(ieee80211_crypto_ccmp_exit); 492module_exit(lib80211_crypto_ccmp_exit);
diff --git a/net/ieee80211/ieee80211_crypt_tkip.c b/net/wireless/lib80211_crypt_tkip.c
index bba0152e2d71..7e8e22bfed90 100644
--- a/net/ieee80211/ieee80211_crypt_tkip.c
+++ b/net/wireless/lib80211_crypt_tkip.c
@@ -1,7 +1,8 @@
1/* 1/*
2 * Host AP crypt: host-based TKIP encryption implementation for Host AP driver 2 * lib80211 crypt: host-based TKIP encryption implementation for lib80211
3 * 3 *
4 * Copyright (c) 2003-2004, Jouni Malinen <j@w1.fi> 4 * Copyright (c) 2003-2004, Jouni Malinen <j@w1.fi>
5 * Copyright (c) 2008, John W. Linville <linville@tuxdriver.com>
5 * 6 *
6 * This program is free software; you can redistribute it and/or modify 7 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as 8 * it under the terms of the GNU General Public License version 2 as
@@ -22,16 +23,20 @@
22#include <linux/if_arp.h> 23#include <linux/if_arp.h>
23#include <asm/string.h> 24#include <asm/string.h>
24 25
25#include <net/ieee80211.h> 26#include <linux/wireless.h>
27#include <linux/ieee80211.h>
28#include <net/iw_handler.h>
26 29
27#include <linux/crypto.h> 30#include <linux/crypto.h>
28#include <linux/crc32.h> 31#include <linux/crc32.h>
29 32
33#include <net/lib80211.h>
34
30MODULE_AUTHOR("Jouni Malinen"); 35MODULE_AUTHOR("Jouni Malinen");
31MODULE_DESCRIPTION("Host AP crypt: TKIP"); 36MODULE_DESCRIPTION("lib80211 crypt: TKIP");
32MODULE_LICENSE("GPL"); 37MODULE_LICENSE("GPL");
33 38
34struct ieee80211_tkip_data { 39struct lib80211_tkip_data {
35#define TKIP_KEY_LEN 32 40#define TKIP_KEY_LEN 32
36 u8 key[TKIP_KEY_LEN]; 41 u8 key[TKIP_KEY_LEN];
37 int key_set; 42 int key_set;
@@ -65,23 +70,23 @@ struct ieee80211_tkip_data {
65 unsigned long flags; 70 unsigned long flags;
66}; 71};
67 72
68static unsigned long ieee80211_tkip_set_flags(unsigned long flags, void *priv) 73static unsigned long lib80211_tkip_set_flags(unsigned long flags, void *priv)
69{ 74{
70 struct ieee80211_tkip_data *_priv = priv; 75 struct lib80211_tkip_data *_priv = priv;
71 unsigned long old_flags = _priv->flags; 76 unsigned long old_flags = _priv->flags;
72 _priv->flags = flags; 77 _priv->flags = flags;
73 return old_flags; 78 return old_flags;
74} 79}
75 80
76static unsigned long ieee80211_tkip_get_flags(void *priv) 81static unsigned long lib80211_tkip_get_flags(void *priv)
77{ 82{
78 struct ieee80211_tkip_data *_priv = priv; 83 struct lib80211_tkip_data *_priv = priv;
79 return _priv->flags; 84 return _priv->flags;
80} 85}
81 86
82static void *ieee80211_tkip_init(int key_idx) 87static void *lib80211_tkip_init(int key_idx)
83{ 88{
84 struct ieee80211_tkip_data *priv; 89 struct lib80211_tkip_data *priv;
85 90
86 priv = kzalloc(sizeof(*priv), GFP_ATOMIC); 91 priv = kzalloc(sizeof(*priv), GFP_ATOMIC);
87 if (priv == NULL) 92 if (priv == NULL)
@@ -92,7 +97,7 @@ static void *ieee80211_tkip_init(int key_idx)
92 priv->tx_tfm_arc4 = crypto_alloc_blkcipher("ecb(arc4)", 0, 97 priv->tx_tfm_arc4 = crypto_alloc_blkcipher("ecb(arc4)", 0,
93 CRYPTO_ALG_ASYNC); 98 CRYPTO_ALG_ASYNC);
94 if (IS_ERR(priv->tx_tfm_arc4)) { 99 if (IS_ERR(priv->tx_tfm_arc4)) {
95 printk(KERN_DEBUG "ieee80211_crypt_tkip: could not allocate " 100 printk(KERN_DEBUG "lib80211_crypt_tkip: could not allocate "
96 "crypto API arc4\n"); 101 "crypto API arc4\n");
97 priv->tx_tfm_arc4 = NULL; 102 priv->tx_tfm_arc4 = NULL;
98 goto fail; 103 goto fail;
@@ -101,7 +106,7 @@ static void *ieee80211_tkip_init(int key_idx)
101 priv->tx_tfm_michael = crypto_alloc_hash("michael_mic", 0, 106 priv->tx_tfm_michael = crypto_alloc_hash("michael_mic", 0,
102 CRYPTO_ALG_ASYNC); 107 CRYPTO_ALG_ASYNC);
103 if (IS_ERR(priv->tx_tfm_michael)) { 108 if (IS_ERR(priv->tx_tfm_michael)) {
104 printk(KERN_DEBUG "ieee80211_crypt_tkip: could not allocate " 109 printk(KERN_DEBUG "lib80211_crypt_tkip: could not allocate "
105 "crypto API michael_mic\n"); 110 "crypto API michael_mic\n");
106 priv->tx_tfm_michael = NULL; 111 priv->tx_tfm_michael = NULL;
107 goto fail; 112 goto fail;
@@ -110,7 +115,7 @@ static void *ieee80211_tkip_init(int key_idx)
110 priv->rx_tfm_arc4 = crypto_alloc_blkcipher("ecb(arc4)", 0, 115 priv->rx_tfm_arc4 = crypto_alloc_blkcipher("ecb(arc4)", 0,
111 CRYPTO_ALG_ASYNC); 116 CRYPTO_ALG_ASYNC);
112 if (IS_ERR(priv->rx_tfm_arc4)) { 117 if (IS_ERR(priv->rx_tfm_arc4)) {
113 printk(KERN_DEBUG "ieee80211_crypt_tkip: could not allocate " 118 printk(KERN_DEBUG "lib80211_crypt_tkip: could not allocate "
114 "crypto API arc4\n"); 119 "crypto API arc4\n");
115 priv->rx_tfm_arc4 = NULL; 120 priv->rx_tfm_arc4 = NULL;
116 goto fail; 121 goto fail;
@@ -119,7 +124,7 @@ static void *ieee80211_tkip_init(int key_idx)
119 priv->rx_tfm_michael = crypto_alloc_hash("michael_mic", 0, 124 priv->rx_tfm_michael = crypto_alloc_hash("michael_mic", 0,
120 CRYPTO_ALG_ASYNC); 125 CRYPTO_ALG_ASYNC);
121 if (IS_ERR(priv->rx_tfm_michael)) { 126 if (IS_ERR(priv->rx_tfm_michael)) {
122 printk(KERN_DEBUG "ieee80211_crypt_tkip: could not allocate " 127 printk(KERN_DEBUG "lib80211_crypt_tkip: could not allocate "
123 "crypto API michael_mic\n"); 128 "crypto API michael_mic\n");
124 priv->rx_tfm_michael = NULL; 129 priv->rx_tfm_michael = NULL;
125 goto fail; 130 goto fail;
@@ -143,9 +148,9 @@ static void *ieee80211_tkip_init(int key_idx)
143 return NULL; 148 return NULL;
144} 149}
145 150
146static void ieee80211_tkip_deinit(void *priv) 151static void lib80211_tkip_deinit(void *priv)
147{ 152{
148 struct ieee80211_tkip_data *_priv = priv; 153 struct lib80211_tkip_data *_priv = priv;
149 if (_priv) { 154 if (_priv) {
150 if (_priv->tx_tfm_michael) 155 if (_priv->tx_tfm_michael)
151 crypto_free_hash(_priv->tx_tfm_michael); 156 crypto_free_hash(_priv->tx_tfm_michael);
@@ -305,15 +310,15 @@ static void tkip_mixing_phase2(u8 * WEPSeed, const u8 * TK, const u16 * TTAK,
305#endif 310#endif
306} 311}
307 312
308static int ieee80211_tkip_hdr(struct sk_buff *skb, int hdr_len, 313static int lib80211_tkip_hdr(struct sk_buff *skb, int hdr_len,
309 u8 * rc4key, int keylen, void *priv) 314 u8 * rc4key, int keylen, void *priv)
310{ 315{
311 struct ieee80211_tkip_data *tkey = priv; 316 struct lib80211_tkip_data *tkey = priv;
312 int len; 317 int len;
313 u8 *pos; 318 u8 *pos;
314 struct ieee80211_hdr_4addr *hdr; 319 struct ieee80211_hdr *hdr;
315 320
316 hdr = (struct ieee80211_hdr_4addr *)skb->data; 321 hdr = (struct ieee80211_hdr *)skb->data;
317 322
318 if (skb_headroom(skb) < 8 || skb->len < hdr_len) 323 if (skb_headroom(skb) < 8 || skb->len < hdr_len)
319 return -1; 324 return -1;
@@ -351,23 +356,21 @@ static int ieee80211_tkip_hdr(struct sk_buff *skb, int hdr_len,
351 return 8; 356 return 8;
352} 357}
353 358
354static int ieee80211_tkip_encrypt(struct sk_buff *skb, int hdr_len, void *priv) 359static int lib80211_tkip_encrypt(struct sk_buff *skb, int hdr_len, void *priv)
355{ 360{
356 struct ieee80211_tkip_data *tkey = priv; 361 struct lib80211_tkip_data *tkey = priv;
357 struct blkcipher_desc desc = { .tfm = tkey->tx_tfm_arc4 }; 362 struct blkcipher_desc desc = { .tfm = tkey->tx_tfm_arc4 };
358 int len; 363 int len;
359 u8 rc4key[16], *pos, *icv; 364 u8 rc4key[16], *pos, *icv;
360 u32 crc; 365 u32 crc;
361 struct scatterlist sg; 366 struct scatterlist sg;
362 DECLARE_MAC_BUF(mac);
363 367
364 if (tkey->flags & IEEE80211_CRYPTO_TKIP_COUNTERMEASURES) { 368 if (tkey->flags & IEEE80211_CRYPTO_TKIP_COUNTERMEASURES) {
365 if (net_ratelimit()) { 369 if (net_ratelimit()) {
366 struct ieee80211_hdr_4addr *hdr = 370 struct ieee80211_hdr *hdr =
367 (struct ieee80211_hdr_4addr *)skb->data; 371 (struct ieee80211_hdr *)skb->data;
368 printk(KERN_DEBUG ": TKIP countermeasures: dropped " 372 printk(KERN_DEBUG ": TKIP countermeasures: dropped "
369 "TX packet to %s\n", 373 "TX packet to %pM\n", hdr->addr1);
370 print_mac(mac, hdr->addr1));
371 } 374 }
372 return -1; 375 return -1;
373 } 376 }
@@ -378,7 +381,7 @@ static int ieee80211_tkip_encrypt(struct sk_buff *skb, int hdr_len, void *priv)
378 len = skb->len - hdr_len; 381 len = skb->len - hdr_len;
379 pos = skb->data + hdr_len; 382 pos = skb->data + hdr_len;
380 383
381 if ((ieee80211_tkip_hdr(skb, hdr_len, rc4key, 16, priv)) < 0) 384 if ((lib80211_tkip_hdr(skb, hdr_len, rc4key, 16, priv)) < 0)
382 return -1; 385 return -1;
383 386
384 icv = skb_put(skb, 4); 387 icv = skb_put(skb, 4);
@@ -407,28 +410,26 @@ static inline int tkip_replay_check(u32 iv32_n, u16 iv16_n,
407 return 0; 410 return 0;
408} 411}
409 412
410static int ieee80211_tkip_decrypt(struct sk_buff *skb, int hdr_len, void *priv) 413static int lib80211_tkip_decrypt(struct sk_buff *skb, int hdr_len, void *priv)
411{ 414{
412 struct ieee80211_tkip_data *tkey = priv; 415 struct lib80211_tkip_data *tkey = priv;
413 struct blkcipher_desc desc = { .tfm = tkey->rx_tfm_arc4 }; 416 struct blkcipher_desc desc = { .tfm = tkey->rx_tfm_arc4 };
414 u8 rc4key[16]; 417 u8 rc4key[16];
415 u8 keyidx, *pos; 418 u8 keyidx, *pos;
416 u32 iv32; 419 u32 iv32;
417 u16 iv16; 420 u16 iv16;
418 struct ieee80211_hdr_4addr *hdr; 421 struct ieee80211_hdr *hdr;
419 u8 icv[4]; 422 u8 icv[4];
420 u32 crc; 423 u32 crc;
421 struct scatterlist sg; 424 struct scatterlist sg;
422 int plen; 425 int plen;
423 DECLARE_MAC_BUF(mac);
424 426
425 hdr = (struct ieee80211_hdr_4addr *)skb->data; 427 hdr = (struct ieee80211_hdr *)skb->data;
426 428
427 if (tkey->flags & IEEE80211_CRYPTO_TKIP_COUNTERMEASURES) { 429 if (tkey->flags & IEEE80211_CRYPTO_TKIP_COUNTERMEASURES) {
428 if (net_ratelimit()) { 430 if (net_ratelimit()) {
429 printk(KERN_DEBUG ": TKIP countermeasures: dropped " 431 printk(KERN_DEBUG ": TKIP countermeasures: dropped "
430 "received packet from %s\n", 432 "received packet from %pM\n", hdr->addr2);
431 print_mac(mac, hdr->addr2));
432 } 433 }
433 return -1; 434 return -1;
434 } 435 }
@@ -441,7 +442,7 @@ static int ieee80211_tkip_decrypt(struct sk_buff *skb, int hdr_len, void *priv)
441 if (!(keyidx & (1 << 5))) { 442 if (!(keyidx & (1 << 5))) {
442 if (net_ratelimit()) { 443 if (net_ratelimit()) {
443 printk(KERN_DEBUG "TKIP: received packet without ExtIV" 444 printk(KERN_DEBUG "TKIP: received packet without ExtIV"
444 " flag from %s\n", print_mac(mac, hdr->addr2)); 445 " flag from %pM\n", hdr->addr2);
445 } 446 }
446 return -2; 447 return -2;
447 } 448 }
@@ -453,9 +454,9 @@ static int ieee80211_tkip_decrypt(struct sk_buff *skb, int hdr_len, void *priv)
453 } 454 }
454 if (!tkey->key_set) { 455 if (!tkey->key_set) {
455 if (net_ratelimit()) { 456 if (net_ratelimit()) {
456 printk(KERN_DEBUG "TKIP: received packet from %s" 457 printk(KERN_DEBUG "TKIP: received packet from %pM"
457 " with keyid=%d that does not have a configured" 458 " with keyid=%d that does not have a configured"
458 " key\n", print_mac(mac, hdr->addr2), keyidx); 459 " key\n", hdr->addr2, keyidx);
459 } 460 }
460 return -3; 461 return -3;
461 } 462 }
@@ -464,10 +465,10 @@ static int ieee80211_tkip_decrypt(struct sk_buff *skb, int hdr_len, void *priv)
464 pos += 8; 465 pos += 8;
465 466
466 if (tkip_replay_check(iv32, iv16, tkey->rx_iv32, tkey->rx_iv16)) { 467 if (tkip_replay_check(iv32, iv16, tkey->rx_iv32, tkey->rx_iv16)) {
467 if (ieee80211_ratelimit_debug(IEEE80211_DL_DROP)) { 468 if (net_ratelimit()) {
468 IEEE80211_DEBUG_DROP("TKIP: replay detected: STA=%s" 469 printk(KERN_DEBUG "TKIP: replay detected: STA=%pM"
469 " previous TSC %08x%04x received TSC " 470 " previous TSC %08x%04x received TSC "
470 "%08x%04x\n", print_mac(mac, hdr->addr2), 471 "%08x%04x\n", hdr->addr2,
471 tkey->rx_iv32, tkey->rx_iv16, iv32, iv16); 472 tkey->rx_iv32, tkey->rx_iv16, iv32, iv16);
472 } 473 }
473 tkey->dot11RSNAStatsTKIPReplays++; 474 tkey->dot11RSNAStatsTKIPReplays++;
@@ -487,8 +488,8 @@ static int ieee80211_tkip_decrypt(struct sk_buff *skb, int hdr_len, void *priv)
487 if (crypto_blkcipher_decrypt(&desc, &sg, &sg, plen + 4)) { 488 if (crypto_blkcipher_decrypt(&desc, &sg, &sg, plen + 4)) {
488 if (net_ratelimit()) { 489 if (net_ratelimit()) {
489 printk(KERN_DEBUG ": TKIP: failed to decrypt " 490 printk(KERN_DEBUG ": TKIP: failed to decrypt "
490 "received packet from %s\n", 491 "received packet from %pM\n",
491 print_mac(mac, hdr->addr2)); 492 hdr->addr2);
492 } 493 }
493 return -7; 494 return -7;
494 } 495 }
@@ -504,9 +505,9 @@ static int ieee80211_tkip_decrypt(struct sk_buff *skb, int hdr_len, void *priv)
504 * it needs to be recalculated for the next packet. */ 505 * it needs to be recalculated for the next packet. */
505 tkey->rx_phase1_done = 0; 506 tkey->rx_phase1_done = 0;
506 } 507 }
507 if (ieee80211_ratelimit_debug(IEEE80211_DL_DROP)) { 508 if (net_ratelimit()) {
508 IEEE80211_DEBUG_DROP("TKIP: ICV error detected: STA=" 509 printk(KERN_DEBUG "TKIP: ICV error detected: STA="
509 "%s\n", print_mac(mac, hdr->addr2)); 510 "%pM\n", hdr->addr2);
510 } 511 }
511 tkey->dot11RSNAStatsTKIPICVErrors++; 512 tkey->dot11RSNAStatsTKIPICVErrors++;
512 return -5; 513 return -5;
@@ -549,13 +550,11 @@ static int michael_mic(struct crypto_hash *tfm_michael, u8 * key, u8 * hdr,
549 550
550static void michael_mic_hdr(struct sk_buff *skb, u8 * hdr) 551static void michael_mic_hdr(struct sk_buff *skb, u8 * hdr)
551{ 552{
552 struct ieee80211_hdr_4addr *hdr11; 553 struct ieee80211_hdr *hdr11;
553 u16 stype;
554 554
555 hdr11 = (struct ieee80211_hdr_4addr *)skb->data; 555 hdr11 = (struct ieee80211_hdr *)skb->data;
556 stype = WLAN_FC_GET_STYPE(le16_to_cpu(hdr11->frame_ctl));
557 556
558 switch (le16_to_cpu(hdr11->frame_ctl) & 557 switch (le16_to_cpu(hdr11->frame_control) &
559 (IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS)) { 558 (IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS)) {
560 case IEEE80211_FCTL_TODS: 559 case IEEE80211_FCTL_TODS:
561 memcpy(hdr, hdr11->addr3, ETH_ALEN); /* DA */ 560 memcpy(hdr, hdr11->addr3, ETH_ALEN); /* DA */
@@ -575,20 +574,19 @@ static void michael_mic_hdr(struct sk_buff *skb, u8 * hdr)
575 break; 574 break;
576 } 575 }
577 576
578 if (stype & IEEE80211_STYPE_QOS_DATA) { 577 if (ieee80211_is_data_qos(hdr11->frame_control)) {
579 const struct ieee80211_hdr_3addrqos *qoshdr = 578 hdr[12] = le16_to_cpu(*ieee80211_get_qos_ctl(hdr11))
580 (struct ieee80211_hdr_3addrqos *)skb->data; 579 & IEEE80211_QOS_CTL_TID_MASK;
581 hdr[12] = le16_to_cpu(qoshdr->qos_ctl) & IEEE80211_QCTL_TID;
582 } else 580 } else
583 hdr[12] = 0; /* priority */ 581 hdr[12] = 0; /* priority */
584 582
585 hdr[13] = hdr[14] = hdr[15] = 0; /* reserved */ 583 hdr[13] = hdr[14] = hdr[15] = 0; /* reserved */
586} 584}
587 585
588static int ieee80211_michael_mic_add(struct sk_buff *skb, int hdr_len, 586static int lib80211_michael_mic_add(struct sk_buff *skb, int hdr_len,
589 void *priv) 587 void *priv)
590{ 588{
591 struct ieee80211_tkip_data *tkey = priv; 589 struct lib80211_tkip_data *tkey = priv;
592 u8 *pos; 590 u8 *pos;
593 591
594 if (skb_tailroom(skb) < 8 || skb->len < hdr_len) { 592 if (skb_tailroom(skb) < 8 || skb->len < hdr_len) {
@@ -607,8 +605,8 @@ static int ieee80211_michael_mic_add(struct sk_buff *skb, int hdr_len,
607 return 0; 605 return 0;
608} 606}
609 607
610static void ieee80211_michael_mic_failure(struct net_device *dev, 608static void lib80211_michael_mic_failure(struct net_device *dev,
611 struct ieee80211_hdr_4addr *hdr, 609 struct ieee80211_hdr *hdr,
612 int keyidx) 610 int keyidx)
613{ 611{
614 union iwreq_data wrqu; 612 union iwreq_data wrqu;
@@ -628,12 +626,11 @@ static void ieee80211_michael_mic_failure(struct net_device *dev,
628 wireless_send_event(dev, IWEVMICHAELMICFAILURE, &wrqu, (char *)&ev); 626 wireless_send_event(dev, IWEVMICHAELMICFAILURE, &wrqu, (char *)&ev);
629} 627}
630 628
631static int ieee80211_michael_mic_verify(struct sk_buff *skb, int keyidx, 629static int lib80211_michael_mic_verify(struct sk_buff *skb, int keyidx,
632 int hdr_len, void *priv) 630 int hdr_len, void *priv)
633{ 631{
634 struct ieee80211_tkip_data *tkey = priv; 632 struct lib80211_tkip_data *tkey = priv;
635 u8 mic[8]; 633 u8 mic[8];
636 DECLARE_MAC_BUF(mac);
637 634
638 if (!tkey->key_set) 635 if (!tkey->key_set)
639 return -1; 636 return -1;
@@ -643,14 +640,14 @@ static int ieee80211_michael_mic_verify(struct sk_buff *skb, int keyidx,
643 skb->data + hdr_len, skb->len - 8 - hdr_len, mic)) 640 skb->data + hdr_len, skb->len - 8 - hdr_len, mic))
644 return -1; 641 return -1;
645 if (memcmp(mic, skb->data + skb->len - 8, 8) != 0) { 642 if (memcmp(mic, skb->data + skb->len - 8, 8) != 0) {
646 struct ieee80211_hdr_4addr *hdr; 643 struct ieee80211_hdr *hdr;
647 hdr = (struct ieee80211_hdr_4addr *)skb->data; 644 hdr = (struct ieee80211_hdr *)skb->data;
648 printk(KERN_DEBUG "%s: Michael MIC verification failed for " 645 printk(KERN_DEBUG "%s: Michael MIC verification failed for "
649 "MSDU from %s keyidx=%d\n", 646 "MSDU from %pM keyidx=%d\n",
650 skb->dev ? skb->dev->name : "N/A", print_mac(mac, hdr->addr2), 647 skb->dev ? skb->dev->name : "N/A", hdr->addr2,
651 keyidx); 648 keyidx);
652 if (skb->dev) 649 if (skb->dev)
653 ieee80211_michael_mic_failure(skb->dev, hdr, keyidx); 650 lib80211_michael_mic_failure(skb->dev, hdr, keyidx);
654 tkey->dot11RSNAStatsTKIPLocalMICFailures++; 651 tkey->dot11RSNAStatsTKIPLocalMICFailures++;
655 return -1; 652 return -1;
656 } 653 }
@@ -665,9 +662,9 @@ static int ieee80211_michael_mic_verify(struct sk_buff *skb, int keyidx,
665 return 0; 662 return 0;
666} 663}
667 664
668static int ieee80211_tkip_set_key(void *key, int len, u8 * seq, void *priv) 665static int lib80211_tkip_set_key(void *key, int len, u8 * seq, void *priv)
669{ 666{
670 struct ieee80211_tkip_data *tkey = priv; 667 struct lib80211_tkip_data *tkey = priv;
671 int keyidx; 668 int keyidx;
672 struct crypto_hash *tfm = tkey->tx_tfm_michael; 669 struct crypto_hash *tfm = tkey->tx_tfm_michael;
673 struct crypto_blkcipher *tfm2 = tkey->tx_tfm_arc4; 670 struct crypto_blkcipher *tfm2 = tkey->tx_tfm_arc4;
@@ -698,9 +695,9 @@ static int ieee80211_tkip_set_key(void *key, int len, u8 * seq, void *priv)
698 return 0; 695 return 0;
699} 696}
700 697
701static int ieee80211_tkip_get_key(void *key, int len, u8 * seq, void *priv) 698static int lib80211_tkip_get_key(void *key, int len, u8 * seq, void *priv)
702{ 699{
703 struct ieee80211_tkip_data *tkey = priv; 700 struct lib80211_tkip_data *tkey = priv;
704 701
705 if (len < TKIP_KEY_LEN) 702 if (len < TKIP_KEY_LEN)
706 return -1; 703 return -1;
@@ -727,9 +724,9 @@ static int ieee80211_tkip_get_key(void *key, int len, u8 * seq, void *priv)
727 return TKIP_KEY_LEN; 724 return TKIP_KEY_LEN;
728} 725}
729 726
730static char *ieee80211_tkip_print_stats(char *p, void *priv) 727static char *lib80211_tkip_print_stats(char *p, void *priv)
731{ 728{
732 struct ieee80211_tkip_data *tkip = priv; 729 struct lib80211_tkip_data *tkip = priv;
733 p += sprintf(p, "key[%d] alg=TKIP key_set=%d " 730 p += sprintf(p, "key[%d] alg=TKIP key_set=%d "
734 "tx_pn=%02x%02x%02x%02x%02x%02x " 731 "tx_pn=%02x%02x%02x%02x%02x%02x "
735 "rx_pn=%02x%02x%02x%02x%02x%02x " 732 "rx_pn=%02x%02x%02x%02x%02x%02x "
@@ -753,35 +750,35 @@ static char *ieee80211_tkip_print_stats(char *p, void *priv)
753 return p; 750 return p;
754} 751}
755 752
756static struct ieee80211_crypto_ops ieee80211_crypt_tkip = { 753static struct lib80211_crypto_ops lib80211_crypt_tkip = {
757 .name = "TKIP", 754 .name = "TKIP",
758 .init = ieee80211_tkip_init, 755 .init = lib80211_tkip_init,
759 .deinit = ieee80211_tkip_deinit, 756 .deinit = lib80211_tkip_deinit,
760 .build_iv = ieee80211_tkip_hdr, 757 .build_iv = lib80211_tkip_hdr,
761 .encrypt_mpdu = ieee80211_tkip_encrypt, 758 .encrypt_mpdu = lib80211_tkip_encrypt,
762 .decrypt_mpdu = ieee80211_tkip_decrypt, 759 .decrypt_mpdu = lib80211_tkip_decrypt,
763 .encrypt_msdu = ieee80211_michael_mic_add, 760 .encrypt_msdu = lib80211_michael_mic_add,
764 .decrypt_msdu = ieee80211_michael_mic_verify, 761 .decrypt_msdu = lib80211_michael_mic_verify,
765 .set_key = ieee80211_tkip_set_key, 762 .set_key = lib80211_tkip_set_key,
766 .get_key = ieee80211_tkip_get_key, 763 .get_key = lib80211_tkip_get_key,
767 .print_stats = ieee80211_tkip_print_stats, 764 .print_stats = lib80211_tkip_print_stats,
768 .extra_mpdu_prefix_len = 4 + 4, /* IV + ExtIV */ 765 .extra_mpdu_prefix_len = 4 + 4, /* IV + ExtIV */
769 .extra_mpdu_postfix_len = 4, /* ICV */ 766 .extra_mpdu_postfix_len = 4, /* ICV */
770 .extra_msdu_postfix_len = 8, /* MIC */ 767 .extra_msdu_postfix_len = 8, /* MIC */
771 .get_flags = ieee80211_tkip_get_flags, 768 .get_flags = lib80211_tkip_get_flags,
772 .set_flags = ieee80211_tkip_set_flags, 769 .set_flags = lib80211_tkip_set_flags,
773 .owner = THIS_MODULE, 770 .owner = THIS_MODULE,
774}; 771};
775 772
776static int __init ieee80211_crypto_tkip_init(void) 773static int __init lib80211_crypto_tkip_init(void)
777{ 774{
778 return ieee80211_register_crypto_ops(&ieee80211_crypt_tkip); 775 return lib80211_register_crypto_ops(&lib80211_crypt_tkip);
779} 776}
780 777
781static void __exit ieee80211_crypto_tkip_exit(void) 778static void __exit lib80211_crypto_tkip_exit(void)
782{ 779{
783 ieee80211_unregister_crypto_ops(&ieee80211_crypt_tkip); 780 lib80211_unregister_crypto_ops(&lib80211_crypt_tkip);
784} 781}
785 782
786module_init(ieee80211_crypto_tkip_init); 783module_init(lib80211_crypto_tkip_init);
787module_exit(ieee80211_crypto_tkip_exit); 784module_exit(lib80211_crypto_tkip_exit);
diff --git a/net/ieee80211/ieee80211_crypt_wep.c b/net/wireless/lib80211_crypt_wep.c
index 3fa30c40779f..6d41e05ca33b 100644
--- a/net/ieee80211/ieee80211_crypt_wep.c
+++ b/net/wireless/lib80211_crypt_wep.c
@@ -1,7 +1,8 @@
1/* 1/*
2 * Host AP crypt: host-based WEP encryption implementation for Host AP driver 2 * lib80211 crypt: host-based WEP encryption implementation for lib80211
3 * 3 *
4 * Copyright (c) 2002-2004, Jouni Malinen <j@w1.fi> 4 * Copyright (c) 2002-2004, Jouni Malinen <j@w1.fi>
5 * Copyright (c) 2008, John W. Linville <linville@tuxdriver.com>
5 * 6 *
6 * This program is free software; you can redistribute it and/or modify 7 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as 8 * it under the terms of the GNU General Public License version 2 as
@@ -19,16 +20,16 @@
19#include <linux/mm.h> 20#include <linux/mm.h>
20#include <asm/string.h> 21#include <asm/string.h>
21 22
22#include <net/ieee80211.h> 23#include <net/lib80211.h>
23 24
24#include <linux/crypto.h> 25#include <linux/crypto.h>
25#include <linux/crc32.h> 26#include <linux/crc32.h>
26 27
27MODULE_AUTHOR("Jouni Malinen"); 28MODULE_AUTHOR("Jouni Malinen");
28MODULE_DESCRIPTION("Host AP crypt: WEP"); 29MODULE_DESCRIPTION("lib80211 crypt: WEP");
29MODULE_LICENSE("GPL"); 30MODULE_LICENSE("GPL");
30 31
31struct prism2_wep_data { 32struct lib80211_wep_data {
32 u32 iv; 33 u32 iv;
33#define WEP_KEY_LEN 13 34#define WEP_KEY_LEN 13
34 u8 key[WEP_KEY_LEN + 1]; 35 u8 key[WEP_KEY_LEN + 1];
@@ -38,9 +39,9 @@ struct prism2_wep_data {
38 struct crypto_blkcipher *rx_tfm; 39 struct crypto_blkcipher *rx_tfm;
39}; 40};
40 41
41static void *prism2_wep_init(int keyidx) 42static void *lib80211_wep_init(int keyidx)
42{ 43{
43 struct prism2_wep_data *priv; 44 struct lib80211_wep_data *priv;
44 45
45 priv = kzalloc(sizeof(*priv), GFP_ATOMIC); 46 priv = kzalloc(sizeof(*priv), GFP_ATOMIC);
46 if (priv == NULL) 47 if (priv == NULL)
@@ -49,7 +50,7 @@ static void *prism2_wep_init(int keyidx)
49 50
50 priv->tx_tfm = crypto_alloc_blkcipher("ecb(arc4)", 0, CRYPTO_ALG_ASYNC); 51 priv->tx_tfm = crypto_alloc_blkcipher("ecb(arc4)", 0, CRYPTO_ALG_ASYNC);
51 if (IS_ERR(priv->tx_tfm)) { 52 if (IS_ERR(priv->tx_tfm)) {
52 printk(KERN_DEBUG "ieee80211_crypt_wep: could not allocate " 53 printk(KERN_DEBUG "lib80211_crypt_wep: could not allocate "
53 "crypto API arc4\n"); 54 "crypto API arc4\n");
54 priv->tx_tfm = NULL; 55 priv->tx_tfm = NULL;
55 goto fail; 56 goto fail;
@@ -57,7 +58,7 @@ static void *prism2_wep_init(int keyidx)
57 58
58 priv->rx_tfm = crypto_alloc_blkcipher("ecb(arc4)", 0, CRYPTO_ALG_ASYNC); 59 priv->rx_tfm = crypto_alloc_blkcipher("ecb(arc4)", 0, CRYPTO_ALG_ASYNC);
59 if (IS_ERR(priv->rx_tfm)) { 60 if (IS_ERR(priv->rx_tfm)) {
60 printk(KERN_DEBUG "ieee80211_crypt_wep: could not allocate " 61 printk(KERN_DEBUG "lib80211_crypt_wep: could not allocate "
61 "crypto API arc4\n"); 62 "crypto API arc4\n");
62 priv->rx_tfm = NULL; 63 priv->rx_tfm = NULL;
63 goto fail; 64 goto fail;
@@ -78,9 +79,9 @@ static void *prism2_wep_init(int keyidx)
78 return NULL; 79 return NULL;
79} 80}
80 81
81static void prism2_wep_deinit(void *priv) 82static void lib80211_wep_deinit(void *priv)
82{ 83{
83 struct prism2_wep_data *_priv = priv; 84 struct lib80211_wep_data *_priv = priv;
84 if (_priv) { 85 if (_priv) {
85 if (_priv->tx_tfm) 86 if (_priv->tx_tfm)
86 crypto_free_blkcipher(_priv->tx_tfm); 87 crypto_free_blkcipher(_priv->tx_tfm);
@@ -91,10 +92,10 @@ static void prism2_wep_deinit(void *priv)
91} 92}
92 93
93/* Add WEP IV/key info to a frame that has at least 4 bytes of headroom */ 94/* Add WEP IV/key info to a frame that has at least 4 bytes of headroom */
94static int prism2_wep_build_iv(struct sk_buff *skb, int hdr_len, 95static int lib80211_wep_build_iv(struct sk_buff *skb, int hdr_len,
95 u8 *key, int keylen, void *priv) 96 u8 *key, int keylen, void *priv)
96{ 97{
97 struct prism2_wep_data *wep = priv; 98 struct lib80211_wep_data *wep = priv;
98 u32 klen, len; 99 u32 klen, len;
99 u8 *pos; 100 u8 *pos;
100 101
@@ -134,21 +135,21 @@ static int prism2_wep_build_iv(struct sk_buff *skb, int hdr_len,
134 * 135 *
135 * WEP frame payload: IV + TX key idx, RC4(data), ICV = RC4(CRC32(data)) 136 * WEP frame payload: IV + TX key idx, RC4(data), ICV = RC4(CRC32(data))
136 */ 137 */
137static int prism2_wep_encrypt(struct sk_buff *skb, int hdr_len, void *priv) 138static int lib80211_wep_encrypt(struct sk_buff *skb, int hdr_len, void *priv)
138{ 139{
139 struct prism2_wep_data *wep = priv; 140 struct lib80211_wep_data *wep = priv;
140 struct blkcipher_desc desc = { .tfm = wep->tx_tfm }; 141 struct blkcipher_desc desc = { .tfm = wep->tx_tfm };
141 u32 crc, klen, len; 142 u32 crc, klen, len;
142 u8 *pos, *icv; 143 u8 *pos, *icv;
143 struct scatterlist sg; 144 struct scatterlist sg;
144 u8 key[WEP_KEY_LEN + 3]; 145 u8 key[WEP_KEY_LEN + 3];
145 146
146 /* other checks are in prism2_wep_build_iv */ 147 /* other checks are in lib80211_wep_build_iv */
147 if (skb_tailroom(skb) < 4) 148 if (skb_tailroom(skb) < 4)
148 return -1; 149 return -1;
149 150
150 /* add the IV to the frame */ 151 /* add the IV to the frame */
151 if (prism2_wep_build_iv(skb, hdr_len, NULL, 0, priv)) 152 if (lib80211_wep_build_iv(skb, hdr_len, NULL, 0, priv))
152 return -1; 153 return -1;
153 154
154 /* Copy the IV into the first 3 bytes of the key */ 155 /* Copy the IV into the first 3 bytes of the key */
@@ -181,9 +182,9 @@ static int prism2_wep_encrypt(struct sk_buff *skb, int hdr_len, void *priv)
181 * Returns 0 if frame was decrypted successfully and ICV was correct and -1 on 182 * Returns 0 if frame was decrypted successfully and ICV was correct and -1 on
182 * failure. If frame is OK, IV and ICV will be removed. 183 * failure. If frame is OK, IV and ICV will be removed.
183 */ 184 */
184static int prism2_wep_decrypt(struct sk_buff *skb, int hdr_len, void *priv) 185static int lib80211_wep_decrypt(struct sk_buff *skb, int hdr_len, void *priv)
185{ 186{
186 struct prism2_wep_data *wep = priv; 187 struct lib80211_wep_data *wep = priv;
187 struct blkcipher_desc desc = { .tfm = wep->rx_tfm }; 188 struct blkcipher_desc desc = { .tfm = wep->rx_tfm };
188 u32 crc, klen, plen; 189 u32 crc, klen, plen;
189 u8 key[WEP_KEY_LEN + 3]; 190 u8 key[WEP_KEY_LEN + 3];
@@ -232,9 +233,9 @@ static int prism2_wep_decrypt(struct sk_buff *skb, int hdr_len, void *priv)
232 return 0; 233 return 0;
233} 234}
234 235
235static int prism2_wep_set_key(void *key, int len, u8 * seq, void *priv) 236static int lib80211_wep_set_key(void *key, int len, u8 * seq, void *priv)
236{ 237{
237 struct prism2_wep_data *wep = priv; 238 struct lib80211_wep_data *wep = priv;
238 239
239 if (len < 0 || len > WEP_KEY_LEN) 240 if (len < 0 || len > WEP_KEY_LEN)
240 return -1; 241 return -1;
@@ -245,9 +246,9 @@ static int prism2_wep_set_key(void *key, int len, u8 * seq, void *priv)
245 return 0; 246 return 0;
246} 247}
247 248
248static int prism2_wep_get_key(void *key, int len, u8 * seq, void *priv) 249static int lib80211_wep_get_key(void *key, int len, u8 * seq, void *priv)
249{ 250{
250 struct prism2_wep_data *wep = priv; 251 struct lib80211_wep_data *wep = priv;
251 252
252 if (len < wep->key_len) 253 if (len < wep->key_len)
253 return -1; 254 return -1;
@@ -257,39 +258,39 @@ static int prism2_wep_get_key(void *key, int len, u8 * seq, void *priv)
257 return wep->key_len; 258 return wep->key_len;
258} 259}
259 260
260static char *prism2_wep_print_stats(char *p, void *priv) 261static char *lib80211_wep_print_stats(char *p, void *priv)
261{ 262{
262 struct prism2_wep_data *wep = priv; 263 struct lib80211_wep_data *wep = priv;
263 p += sprintf(p, "key[%d] alg=WEP len=%d\n", wep->key_idx, wep->key_len); 264 p += sprintf(p, "key[%d] alg=WEP len=%d\n", wep->key_idx, wep->key_len);
264 return p; 265 return p;
265} 266}
266 267
267static struct ieee80211_crypto_ops ieee80211_crypt_wep = { 268static struct lib80211_crypto_ops lib80211_crypt_wep = {
268 .name = "WEP", 269 .name = "WEP",
269 .init = prism2_wep_init, 270 .init = lib80211_wep_init,
270 .deinit = prism2_wep_deinit, 271 .deinit = lib80211_wep_deinit,
271 .build_iv = prism2_wep_build_iv, 272 .build_iv = lib80211_wep_build_iv,
272 .encrypt_mpdu = prism2_wep_encrypt, 273 .encrypt_mpdu = lib80211_wep_encrypt,
273 .decrypt_mpdu = prism2_wep_decrypt, 274 .decrypt_mpdu = lib80211_wep_decrypt,
274 .encrypt_msdu = NULL, 275 .encrypt_msdu = NULL,
275 .decrypt_msdu = NULL, 276 .decrypt_msdu = NULL,
276 .set_key = prism2_wep_set_key, 277 .set_key = lib80211_wep_set_key,
277 .get_key = prism2_wep_get_key, 278 .get_key = lib80211_wep_get_key,
278 .print_stats = prism2_wep_print_stats, 279 .print_stats = lib80211_wep_print_stats,
279 .extra_mpdu_prefix_len = 4, /* IV */ 280 .extra_mpdu_prefix_len = 4, /* IV */
280 .extra_mpdu_postfix_len = 4, /* ICV */ 281 .extra_mpdu_postfix_len = 4, /* ICV */
281 .owner = THIS_MODULE, 282 .owner = THIS_MODULE,
282}; 283};
283 284
284static int __init ieee80211_crypto_wep_init(void) 285static int __init lib80211_crypto_wep_init(void)
285{ 286{
286 return ieee80211_register_crypto_ops(&ieee80211_crypt_wep); 287 return lib80211_register_crypto_ops(&lib80211_crypt_wep);
287} 288}
288 289
289static void __exit ieee80211_crypto_wep_exit(void) 290static void __exit lib80211_crypto_wep_exit(void)
290{ 291{
291 ieee80211_unregister_crypto_ops(&ieee80211_crypt_wep); 292 lib80211_unregister_crypto_ops(&lib80211_crypt_wep);
292} 293}
293 294
294module_init(ieee80211_crypto_wep_init); 295module_init(lib80211_crypto_wep_init);
295module_exit(ieee80211_crypto_wep_exit); 296module_exit(lib80211_crypto_wep_exit);
diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c
index 572793c8c7ab..1e728fff474e 100644
--- a/net/wireless/nl80211.c
+++ b/net/wireless/nl80211.c
@@ -58,6 +58,9 @@ static struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] __read_mostly = {
58 [NL80211_ATTR_WIPHY] = { .type = NLA_U32 }, 58 [NL80211_ATTR_WIPHY] = { .type = NLA_U32 },
59 [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING, 59 [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING,
60 .len = BUS_ID_SIZE-1 }, 60 .len = BUS_ID_SIZE-1 },
61 [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED },
62 [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 },
63 [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 },
61 64
62 [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 }, 65 [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 },
63 [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 }, 66 [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 },
@@ -84,7 +87,7 @@ static struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] __read_mostly = {
84 .len = NL80211_MAX_SUPP_RATES }, 87 .len = NL80211_MAX_SUPP_RATES },
85 [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 }, 88 [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 },
86 [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 }, 89 [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 },
87 [NL80211_ATTR_MNTR_FLAGS] = { .type = NLA_NESTED }, 90 [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ },
88 [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY, 91 [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY,
89 .len = IEEE80211_MAX_MESH_ID_LEN }, 92 .len = IEEE80211_MAX_MESH_ID_LEN },
90 [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 }, 93 [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 },
@@ -95,6 +98,10 @@ static struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] __read_mostly = {
95 [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 }, 98 [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 },
96 [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 }, 99 [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 },
97 [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 }, 100 [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 },
101 [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY,
102 .len = NL80211_MAX_SUPP_RATES },
103
104 [NL80211_ATTR_MESH_PARAMS] = { .type = NLA_NESTED },
98 105
99 [NL80211_ATTR_HT_CAPABILITY] = { .type = NLA_BINARY, 106 [NL80211_ATTR_HT_CAPABILITY] = { .type = NLA_BINARY,
100 .len = NL80211_HT_CAPABILITY_LEN }, 107 .len = NL80211_HT_CAPABILITY_LEN },
@@ -157,6 +164,19 @@ static int nl80211_send_wiphy(struct sk_buff *msg, u32 pid, u32 seq, int flags,
157 if (!nl_band) 164 if (!nl_band)
158 goto nla_put_failure; 165 goto nla_put_failure;
159 166
167 /* add HT info */
168 if (dev->wiphy.bands[band]->ht_cap.ht_supported) {
169 NLA_PUT(msg, NL80211_BAND_ATTR_HT_MCS_SET,
170 sizeof(dev->wiphy.bands[band]->ht_cap.mcs),
171 &dev->wiphy.bands[band]->ht_cap.mcs);
172 NLA_PUT_U16(msg, NL80211_BAND_ATTR_HT_CAPA,
173 dev->wiphy.bands[band]->ht_cap.cap);
174 NLA_PUT_U8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
175 dev->wiphy.bands[band]->ht_cap.ampdu_factor);
176 NLA_PUT_U8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
177 dev->wiphy.bands[band]->ht_cap.ampdu_density);
178 }
179
160 /* add frequencies */ 180 /* add frequencies */
161 nl_freqs = nla_nest_start(msg, NL80211_BAND_ATTR_FREQS); 181 nl_freqs = nla_nest_start(msg, NL80211_BAND_ATTR_FREQS);
162 if (!nl_freqs) 182 if (!nl_freqs)
@@ -180,6 +200,9 @@ static int nl80211_send_wiphy(struct sk_buff *msg, u32 pid, u32 seq, int flags,
180 if (chan->flags & IEEE80211_CHAN_RADAR) 200 if (chan->flags & IEEE80211_CHAN_RADAR)
181 NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_RADAR); 201 NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_RADAR);
182 202
203 NLA_PUT_U32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
204 DBM_TO_MBM(chan->max_power));
205
183 nla_nest_end(msg, nl_freq); 206 nla_nest_end(msg, nl_freq);
184 } 207 }
185 208
@@ -269,20 +292,142 @@ static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
269 return -ENOBUFS; 292 return -ENOBUFS;
270} 293}
271 294
295static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
296 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
297 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
298 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
299 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
300 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
301};
302
303static int parse_txq_params(struct nlattr *tb[],
304 struct ieee80211_txq_params *txq_params)
305{
306 if (!tb[NL80211_TXQ_ATTR_QUEUE] || !tb[NL80211_TXQ_ATTR_TXOP] ||
307 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
308 !tb[NL80211_TXQ_ATTR_AIFS])
309 return -EINVAL;
310
311 txq_params->queue = nla_get_u8(tb[NL80211_TXQ_ATTR_QUEUE]);
312 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
313 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
314 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
315 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
316
317 return 0;
318}
319
272static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) 320static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
273{ 321{
274 struct cfg80211_registered_device *rdev; 322 struct cfg80211_registered_device *rdev;
275 int result; 323 int result = 0, rem_txq_params = 0;
276 324 struct nlattr *nl_txq_params;
277 if (!info->attrs[NL80211_ATTR_WIPHY_NAME])
278 return -EINVAL;
279 325
280 rdev = cfg80211_get_dev_from_info(info); 326 rdev = cfg80211_get_dev_from_info(info);
281 if (IS_ERR(rdev)) 327 if (IS_ERR(rdev))
282 return PTR_ERR(rdev); 328 return PTR_ERR(rdev);
283 329
284 result = cfg80211_dev_rename(rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); 330 if (info->attrs[NL80211_ATTR_WIPHY_NAME]) {
331 result = cfg80211_dev_rename(
332 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
333 if (result)
334 goto bad_res;
335 }
336
337 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
338 struct ieee80211_txq_params txq_params;
339 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
340
341 if (!rdev->ops->set_txq_params) {
342 result = -EOPNOTSUPP;
343 goto bad_res;
344 }
345
346 nla_for_each_nested(nl_txq_params,
347 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
348 rem_txq_params) {
349 nla_parse(tb, NL80211_TXQ_ATTR_MAX,
350 nla_data(nl_txq_params),
351 nla_len(nl_txq_params),
352 txq_params_policy);
353 result = parse_txq_params(tb, &txq_params);
354 if (result)
355 goto bad_res;
356
357 result = rdev->ops->set_txq_params(&rdev->wiphy,
358 &txq_params);
359 if (result)
360 goto bad_res;
361 }
362 }
363
364 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
365 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
366 struct ieee80211_channel *chan;
367 struct ieee80211_sta_ht_cap *ht_cap;
368 u32 freq, sec_freq;
369
370 if (!rdev->ops->set_channel) {
371 result = -EOPNOTSUPP;
372 goto bad_res;
373 }
374
375 result = -EINVAL;
376
377 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
378 channel_type = nla_get_u32(info->attrs[
379 NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
380 if (channel_type != NL80211_CHAN_NO_HT &&
381 channel_type != NL80211_CHAN_HT20 &&
382 channel_type != NL80211_CHAN_HT40PLUS &&
383 channel_type != NL80211_CHAN_HT40MINUS)
384 goto bad_res;
385 }
386
387 freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
388 chan = ieee80211_get_channel(&rdev->wiphy, freq);
389
390 /* Primary channel not allowed */
391 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED)
392 goto bad_res;
393
394 if (channel_type == NL80211_CHAN_HT40MINUS)
395 sec_freq = freq - 20;
396 else if (channel_type == NL80211_CHAN_HT40PLUS)
397 sec_freq = freq + 20;
398 else
399 sec_freq = 0;
400
401 ht_cap = &rdev->wiphy.bands[chan->band]->ht_cap;
285 402
403 /* no HT capabilities */
404 if (channel_type != NL80211_CHAN_NO_HT &&
405 !ht_cap->ht_supported)
406 goto bad_res;
407
408 if (sec_freq) {
409 struct ieee80211_channel *schan;
410
411 /* no 40 MHz capabilities */
412 if (!(ht_cap->cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) ||
413 (ht_cap->cap & IEEE80211_HT_CAP_40MHZ_INTOLERANT))
414 goto bad_res;
415
416 schan = ieee80211_get_channel(&rdev->wiphy, sec_freq);
417
418 /* Secondary channel not allowed */
419 if (!schan || schan->flags & IEEE80211_CHAN_DISABLED)
420 goto bad_res;
421 }
422
423 result = rdev->ops->set_channel(&rdev->wiphy, chan,
424 channel_type);
425 if (result)
426 goto bad_res;
427 }
428
429
430 bad_res:
286 cfg80211_put_dev(rdev); 431 cfg80211_put_dev(rdev);
287 return result; 432 return result;
288} 433}
@@ -945,12 +1090,46 @@ static int parse_station_flags(struct nlattr *nla, u32 *staflags)
945 return 0; 1090 return 0;
946} 1091}
947 1092
1093static u16 nl80211_calculate_bitrate(struct rate_info *rate)
1094{
1095 int modulation, streams, bitrate;
1096
1097 if (!(rate->flags & RATE_INFO_FLAGS_MCS))
1098 return rate->legacy;
1099
1100 /* the formula below does only work for MCS values smaller than 32 */
1101 if (rate->mcs >= 32)
1102 return 0;
1103
1104 modulation = rate->mcs & 7;
1105 streams = (rate->mcs >> 3) + 1;
1106
1107 bitrate = (rate->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH) ?
1108 13500000 : 6500000;
1109
1110 if (modulation < 4)
1111 bitrate *= (modulation + 1);
1112 else if (modulation == 4)
1113 bitrate *= (modulation + 2);
1114 else
1115 bitrate *= (modulation + 3);
1116
1117 bitrate *= streams;
1118
1119 if (rate->flags & RATE_INFO_FLAGS_SHORT_GI)
1120 bitrate = (bitrate / 9) * 10;
1121
1122 /* do NOT round down here */
1123 return (bitrate + 50000) / 100000;
1124}
1125
948static int nl80211_send_station(struct sk_buff *msg, u32 pid, u32 seq, 1126static int nl80211_send_station(struct sk_buff *msg, u32 pid, u32 seq,
949 int flags, struct net_device *dev, 1127 int flags, struct net_device *dev,
950 u8 *mac_addr, struct station_info *sinfo) 1128 u8 *mac_addr, struct station_info *sinfo)
951{ 1129{
952 void *hdr; 1130 void *hdr;
953 struct nlattr *sinfoattr; 1131 struct nlattr *sinfoattr, *txrate;
1132 u16 bitrate;
954 1133
955 hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION); 1134 hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION);
956 if (!hdr) 1135 if (!hdr)
@@ -980,7 +1159,29 @@ static int nl80211_send_station(struct sk_buff *msg, u32 pid, u32 seq,
980 if (sinfo->filled & STATION_INFO_PLINK_STATE) 1159 if (sinfo->filled & STATION_INFO_PLINK_STATE)
981 NLA_PUT_U8(msg, NL80211_STA_INFO_PLINK_STATE, 1160 NLA_PUT_U8(msg, NL80211_STA_INFO_PLINK_STATE,
982 sinfo->plink_state); 1161 sinfo->plink_state);
1162 if (sinfo->filled & STATION_INFO_SIGNAL)
1163 NLA_PUT_U8(msg, NL80211_STA_INFO_SIGNAL,
1164 sinfo->signal);
1165 if (sinfo->filled & STATION_INFO_TX_BITRATE) {
1166 txrate = nla_nest_start(msg, NL80211_STA_INFO_TX_BITRATE);
1167 if (!txrate)
1168 goto nla_put_failure;
1169
1170 /* nl80211_calculate_bitrate will return 0 for mcs >= 32 */
1171 bitrate = nl80211_calculate_bitrate(&sinfo->txrate);
1172 if (bitrate > 0)
1173 NLA_PUT_U16(msg, NL80211_RATE_INFO_BITRATE, bitrate);
1174
1175 if (sinfo->txrate.flags & RATE_INFO_FLAGS_MCS)
1176 NLA_PUT_U8(msg, NL80211_RATE_INFO_MCS,
1177 sinfo->txrate.mcs);
1178 if (sinfo->txrate.flags & RATE_INFO_FLAGS_40_MHZ_WIDTH)
1179 NLA_PUT_FLAG(msg, NL80211_RATE_INFO_40_MHZ_WIDTH);
1180 if (sinfo->txrate.flags & RATE_INFO_FLAGS_SHORT_GI)
1181 NLA_PUT_FLAG(msg, NL80211_RATE_INFO_SHORT_GI);
983 1182
1183 nla_nest_end(msg, txrate);
1184 }
984 nla_nest_end(msg, sinfoattr); 1185 nla_nest_end(msg, sinfoattr);
985 1186
986 return genlmsg_end(msg, hdr); 1187 return genlmsg_end(msg, hdr);
@@ -1598,6 +1799,12 @@ static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
1598 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) 1799 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
1599 params.use_short_slot_time = 1800 params.use_short_slot_time =
1600 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); 1801 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
1802 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
1803 params.basic_rates =
1804 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
1805 params.basic_rates_len =
1806 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
1807 }
1601 1808
1602 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); 1809 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
1603 if (err) 1810 if (err)
@@ -1680,11 +1887,188 @@ static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
1680 return -EINVAL; 1887 return -EINVAL;
1681#endif 1888#endif
1682 mutex_lock(&cfg80211_drv_mutex); 1889 mutex_lock(&cfg80211_drv_mutex);
1683 r = __regulatory_hint(NULL, REGDOM_SET_BY_USER, data, NULL); 1890 r = __regulatory_hint(NULL, REGDOM_SET_BY_USER, data, 0, ENVIRON_ANY);
1684 mutex_unlock(&cfg80211_drv_mutex); 1891 mutex_unlock(&cfg80211_drv_mutex);
1685 return r; 1892 return r;
1686} 1893}
1687 1894
1895static int nl80211_get_mesh_params(struct sk_buff *skb,
1896 struct genl_info *info)
1897{
1898 struct cfg80211_registered_device *drv;
1899 struct mesh_config cur_params;
1900 int err;
1901 struct net_device *dev;
1902 void *hdr;
1903 struct nlattr *pinfoattr;
1904 struct sk_buff *msg;
1905
1906 /* Look up our device */
1907 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
1908 if (err)
1909 return err;
1910
1911 /* Get the mesh params */
1912 rtnl_lock();
1913 err = drv->ops->get_mesh_params(&drv->wiphy, dev, &cur_params);
1914 rtnl_unlock();
1915 if (err)
1916 goto out;
1917
1918 /* Draw up a netlink message to send back */
1919 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
1920 if (!msg) {
1921 err = -ENOBUFS;
1922 goto out;
1923 }
1924 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
1925 NL80211_CMD_GET_MESH_PARAMS);
1926 if (!hdr)
1927 goto nla_put_failure;
1928 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_PARAMS);
1929 if (!pinfoattr)
1930 goto nla_put_failure;
1931 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
1932 NLA_PUT_U16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
1933 cur_params.dot11MeshRetryTimeout);
1934 NLA_PUT_U16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
1935 cur_params.dot11MeshConfirmTimeout);
1936 NLA_PUT_U16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
1937 cur_params.dot11MeshHoldingTimeout);
1938 NLA_PUT_U16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
1939 cur_params.dot11MeshMaxPeerLinks);
1940 NLA_PUT_U8(msg, NL80211_MESHCONF_MAX_RETRIES,
1941 cur_params.dot11MeshMaxRetries);
1942 NLA_PUT_U8(msg, NL80211_MESHCONF_TTL,
1943 cur_params.dot11MeshTTL);
1944 NLA_PUT_U8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
1945 cur_params.auto_open_plinks);
1946 NLA_PUT_U8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
1947 cur_params.dot11MeshHWMPmaxPREQretries);
1948 NLA_PUT_U32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
1949 cur_params.path_refresh_time);
1950 NLA_PUT_U16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
1951 cur_params.min_discovery_timeout);
1952 NLA_PUT_U32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
1953 cur_params.dot11MeshHWMPactivePathTimeout);
1954 NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
1955 cur_params.dot11MeshHWMPpreqMinInterval);
1956 NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
1957 cur_params.dot11MeshHWMPnetDiameterTraversalTime);
1958 nla_nest_end(msg, pinfoattr);
1959 genlmsg_end(msg, hdr);
1960 err = genlmsg_unicast(msg, info->snd_pid);
1961 goto out;
1962
1963nla_put_failure:
1964 genlmsg_cancel(msg, hdr);
1965 err = -EMSGSIZE;
1966out:
1967 /* Cleanup */
1968 cfg80211_put_dev(drv);
1969 dev_put(dev);
1970 return err;
1971}
1972
1973#define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \
1974do {\
1975 if (table[attr_num]) {\
1976 cfg.param = nla_fn(table[attr_num]); \
1977 mask |= (1 << (attr_num - 1)); \
1978 } \
1979} while (0);\
1980
1981static struct nla_policy
1982nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] __read_mostly = {
1983 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
1984 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
1985 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
1986 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
1987 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
1988 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
1989 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
1990
1991 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
1992 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
1993 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
1994 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
1995 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
1996 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
1997};
1998
1999static int nl80211_set_mesh_params(struct sk_buff *skb, struct genl_info *info)
2000{
2001 int err;
2002 u32 mask;
2003 struct cfg80211_registered_device *drv;
2004 struct net_device *dev;
2005 struct mesh_config cfg;
2006 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
2007 struct nlattr *parent_attr;
2008
2009 parent_attr = info->attrs[NL80211_ATTR_MESH_PARAMS];
2010 if (!parent_attr)
2011 return -EINVAL;
2012 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
2013 parent_attr, nl80211_meshconf_params_policy))
2014 return -EINVAL;
2015
2016 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
2017 if (err)
2018 return err;
2019
2020 /* This makes sure that there aren't more than 32 mesh config
2021 * parameters (otherwise our bitfield scheme would not work.) */
2022 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
2023
2024 /* Fill in the params struct */
2025 mask = 0;
2026 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout,
2027 mask, NL80211_MESHCONF_RETRY_TIMEOUT, nla_get_u16);
2028 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout,
2029 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, nla_get_u16);
2030 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout,
2031 mask, NL80211_MESHCONF_HOLDING_TIMEOUT, nla_get_u16);
2032 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks,
2033 mask, NL80211_MESHCONF_MAX_PEER_LINKS, nla_get_u16);
2034 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries,
2035 mask, NL80211_MESHCONF_MAX_RETRIES, nla_get_u8);
2036 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL,
2037 mask, NL80211_MESHCONF_TTL, nla_get_u8);
2038 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks,
2039 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, nla_get_u8);
2040 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries,
2041 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
2042 nla_get_u8);
2043 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time,
2044 mask, NL80211_MESHCONF_PATH_REFRESH_TIME, nla_get_u32);
2045 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout,
2046 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
2047 nla_get_u16);
2048 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
2049 mask, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
2050 nla_get_u32);
2051 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
2052 mask, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
2053 nla_get_u16);
2054 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
2055 dot11MeshHWMPnetDiameterTraversalTime,
2056 mask, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
2057 nla_get_u16);
2058
2059 /* Apply changes */
2060 rtnl_lock();
2061 err = drv->ops->set_mesh_params(&drv->wiphy, dev, &cfg, mask);
2062 rtnl_unlock();
2063
2064 /* cleanup */
2065 cfg80211_put_dev(drv);
2066 dev_put(dev);
2067 return err;
2068}
2069
2070#undef FILL_IN_MESH_PARAM_IF_SET
2071
1688static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) 2072static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
1689{ 2073{
1690 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; 2074 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
@@ -1743,12 +2127,9 @@ static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
1743 mutex_lock(&cfg80211_drv_mutex); 2127 mutex_lock(&cfg80211_drv_mutex);
1744 r = set_regdom(rd); 2128 r = set_regdom(rd);
1745 mutex_unlock(&cfg80211_drv_mutex); 2129 mutex_unlock(&cfg80211_drv_mutex);
1746 if (r)
1747 goto bad_reg;
1748
1749 return r; 2130 return r;
1750 2131
1751bad_reg: 2132 bad_reg:
1752 kfree(rd); 2133 kfree(rd);
1753 return -EINVAL; 2134 return -EINVAL;
1754} 2135}
@@ -1902,6 +2283,18 @@ static struct genl_ops nl80211_ops[] = {
1902 .policy = nl80211_policy, 2283 .policy = nl80211_policy,
1903 .flags = GENL_ADMIN_PERM, 2284 .flags = GENL_ADMIN_PERM,
1904 }, 2285 },
2286 {
2287 .cmd = NL80211_CMD_GET_MESH_PARAMS,
2288 .doit = nl80211_get_mesh_params,
2289 .policy = nl80211_policy,
2290 /* can be retrieved by unprivileged users */
2291 },
2292 {
2293 .cmd = NL80211_CMD_SET_MESH_PARAMS,
2294 .doit = nl80211_set_mesh_params,
2295 .policy = nl80211_policy,
2296 .flags = GENL_ADMIN_PERM,
2297 },
1905}; 2298};
1906 2299
1907/* multicast groups */ 2300/* multicast groups */
diff --git a/net/wireless/reg.c b/net/wireless/reg.c
index eb3b1a9f9b12..4f877535e666 100644
--- a/net/wireless/reg.c
+++ b/net/wireless/reg.c
@@ -42,17 +42,40 @@
42#include "core.h" 42#include "core.h"
43#include "reg.h" 43#include "reg.h"
44 44
45/* wiphy is set if this request's initiator is REGDOM_SET_BY_DRIVER */ 45/**
46 * struct regulatory_request - receipt of last regulatory request
47 *
48 * @wiphy: this is set if this request's initiator is
49 * %REGDOM_SET_BY_COUNTRY_IE or %REGDOM_SET_BY_DRIVER. This
50 * can be used by the wireless core to deal with conflicts
51 * and potentially inform users of which devices specifically
52 * cased the conflicts.
53 * @initiator: indicates who sent this request, could be any of
54 * of those set in reg_set_by, %REGDOM_SET_BY_*
55 * @alpha2: the ISO / IEC 3166 alpha2 country code of the requested
56 * regulatory domain. We have a few special codes:
57 * 00 - World regulatory domain
58 * 99 - built by driver but a specific alpha2 cannot be determined
59 * 98 - result of an intersection between two regulatory domains
60 * @intersect: indicates whether the wireless core should intersect
61 * the requested regulatory domain with the presently set regulatory
62 * domain.
63 * @country_ie_checksum: checksum of the last processed and accepted
64 * country IE
65 * @country_ie_env: lets us know if the AP is telling us we are outdoor,
66 * indoor, or if it doesn't matter
67 */
46struct regulatory_request { 68struct regulatory_request {
47 struct list_head list;
48 struct wiphy *wiphy; 69 struct wiphy *wiphy;
49 int granted;
50 enum reg_set_by initiator; 70 enum reg_set_by initiator;
51 char alpha2[2]; 71 char alpha2[2];
72 bool intersect;
73 u32 country_ie_checksum;
74 enum environment_cap country_ie_env;
52}; 75};
53 76
54static LIST_HEAD(regulatory_requests); 77/* Receipt of information from last regulatory request */
55DEFINE_MUTEX(cfg80211_reg_mutex); 78static struct regulatory_request *last_request;
56 79
57/* To trigger userspace events */ 80/* To trigger userspace events */
58static struct platform_device *reg_pdev; 81static struct platform_device *reg_pdev;
@@ -63,13 +86,16 @@ static u32 supported_bandwidths[] = {
63 MHZ_TO_KHZ(20), 86 MHZ_TO_KHZ(20),
64}; 87};
65 88
66static struct list_head regulatory_requests;
67
68/* Central wireless core regulatory domains, we only need two, 89/* Central wireless core regulatory domains, we only need two,
69 * the current one and a world regulatory domain in case we have no 90 * the current one and a world regulatory domain in case we have no
70 * information to give us an alpha2 */ 91 * information to give us an alpha2 */
71static const struct ieee80211_regdomain *cfg80211_regdomain; 92static const struct ieee80211_regdomain *cfg80211_regdomain;
72 93
94/* We use this as a place for the rd structure built from the
95 * last parsed country IE to rest until CRDA gets back to us with
96 * what it thinks should apply for the same country */
97static const struct ieee80211_regdomain *country_ie_regdomain;
98
73/* We keep a static world regulatory domain in case of the absence of CRDA */ 99/* We keep a static world regulatory domain in case of the absence of CRDA */
74static const struct ieee80211_regdomain world_regdom = { 100static const struct ieee80211_regdomain world_regdom = {
75 .n_reg_rules = 1, 101 .n_reg_rules = 1,
@@ -204,7 +230,7 @@ static void reset_regdomains(void)
204 * core upon initialization */ 230 * core upon initialization */
205static void update_world_regdomain(const struct ieee80211_regdomain *rd) 231static void update_world_regdomain(const struct ieee80211_regdomain *rd)
206{ 232{
207 BUG_ON(list_empty(&regulatory_requests)); 233 BUG_ON(!last_request);
208 234
209 reset_regdomains(); 235 reset_regdomains();
210 236
@@ -249,6 +275,18 @@ static bool is_unknown_alpha2(const char *alpha2)
249 return false; 275 return false;
250} 276}
251 277
278static bool is_intersected_alpha2(const char *alpha2)
279{
280 if (!alpha2)
281 return false;
282 /* Special case where regulatory domain is the
283 * result of an intersection between two regulatory domain
284 * structures */
285 if (alpha2[0] == '9' && alpha2[1] == '8')
286 return true;
287 return false;
288}
289
252static bool is_an_alpha2(const char *alpha2) 290static bool is_an_alpha2(const char *alpha2)
253{ 291{
254 if (!alpha2) 292 if (!alpha2)
@@ -277,6 +315,25 @@ static bool regdom_changed(const char *alpha2)
277 return true; 315 return true;
278} 316}
279 317
318/**
319 * country_ie_integrity_changes - tells us if the country IE has changed
320 * @checksum: checksum of country IE of fields we are interested in
321 *
322 * If the country IE has not changed you can ignore it safely. This is
323 * useful to determine if two devices are seeing two different country IEs
324 * even on the same alpha2. Note that this will return false if no IE has
325 * been set on the wireless core yet.
326 */
327static bool country_ie_integrity_changes(u32 checksum)
328{
329 /* If no IE has been set then the checksum doesn't change */
330 if (unlikely(!last_request->country_ie_checksum))
331 return false;
332 if (unlikely(last_request->country_ie_checksum != checksum))
333 return true;
334 return false;
335}
336
280/* This lets us keep regulatory code which is updated on a regulatory 337/* This lets us keep regulatory code which is updated on a regulatory
281 * basis in userspace. */ 338 * basis in userspace. */
282static int call_crda(const char *alpha2) 339static int call_crda(const char *alpha2)
@@ -300,121 +357,13 @@ static int call_crda(const char *alpha2)
300 return kobject_uevent_env(&reg_pdev->dev.kobj, KOBJ_CHANGE, envp); 357 return kobject_uevent_env(&reg_pdev->dev.kobj, KOBJ_CHANGE, envp);
301} 358}
302 359
303/* This has the logic which determines when a new request
304 * should be ignored. */
305static int ignore_request(struct wiphy *wiphy, enum reg_set_by set_by,
306 char *alpha2, struct ieee80211_regdomain *rd)
307{
308 struct regulatory_request *last_request = NULL;
309
310 /* All initial requests are respected */
311 if (list_empty(&regulatory_requests))
312 return 0;
313
314 last_request = list_first_entry(&regulatory_requests,
315 struct regulatory_request, list);
316
317 switch (set_by) {
318 case REGDOM_SET_BY_INIT:
319 return -EINVAL;
320 case REGDOM_SET_BY_CORE:
321 /* Always respect new wireless core hints, should only
322 * come in for updating the world regulatory domain at init
323 * anyway */
324 return 0;
325 case REGDOM_SET_BY_COUNTRY_IE:
326 if (last_request->initiator == set_by) {
327 if (last_request->wiphy != wiphy) {
328 /* Two cards with two APs claiming different
329 * different Country IE alpha2s!
330 * You're special!! */
331 if (!alpha2_equal(last_request->alpha2,
332 cfg80211_regdomain->alpha2)) {
333 /* XXX: Deal with conflict, consider
334 * building a new one out of the
335 * intersection */
336 WARN_ON(1);
337 return -EOPNOTSUPP;
338 }
339 return -EALREADY;
340 }
341 /* Two consecutive Country IE hints on the same wiphy */
342 if (!alpha2_equal(cfg80211_regdomain->alpha2, alpha2))
343 return 0;
344 return -EALREADY;
345 }
346 if (WARN(!is_alpha2_set(alpha2) || !is_an_alpha2(alpha2),
347 "Invalid Country IE regulatory hint passed "
348 "to the wireless core\n"))
349 return -EINVAL;
350 /* We ignore Country IE hints for now, as we haven't yet
351 * added the dot11MultiDomainCapabilityEnabled flag
352 * for wiphys */
353 return 1;
354 case REGDOM_SET_BY_DRIVER:
355 BUG_ON(!wiphy);
356 if (last_request->initiator == set_by) {
357 /* Two separate drivers hinting different things,
358 * this is possible if you have two devices present
359 * on a system with different EEPROM regulatory
360 * readings. XXX: Do intersection, we support only
361 * the first regulatory hint for now */
362 if (last_request->wiphy != wiphy)
363 return -EALREADY;
364 if (rd)
365 return -EALREADY;
366 /* Driver should not be trying to hint different
367 * regulatory domains! */
368 BUG_ON(!alpha2_equal(alpha2,
369 cfg80211_regdomain->alpha2));
370 return -EALREADY;
371 }
372 if (last_request->initiator == REGDOM_SET_BY_CORE)
373 return 0;
374 /* XXX: Handle intersection, and add the
375 * dot11MultiDomainCapabilityEnabled flag to wiphy. For now
376 * we assume the driver has this set to false, following the
377 * 802.11d dot11MultiDomainCapabilityEnabled documentation */
378 if (last_request->initiator == REGDOM_SET_BY_COUNTRY_IE)
379 return 0;
380 return 0;
381 case REGDOM_SET_BY_USER:
382 if (last_request->initiator == set_by ||
383 last_request->initiator == REGDOM_SET_BY_CORE)
384 return 0;
385 /* Drivers can use their wiphy's reg_notifier()
386 * to override any information */
387 if (last_request->initiator == REGDOM_SET_BY_DRIVER)
388 return 0;
389 /* XXX: Handle intersection */
390 if (last_request->initiator == REGDOM_SET_BY_COUNTRY_IE)
391 return -EOPNOTSUPP;
392 return 0;
393 default:
394 return -EINVAL;
395 }
396}
397
398static bool __reg_is_valid_request(const char *alpha2,
399 struct regulatory_request **request)
400{
401 struct regulatory_request *req;
402 if (list_empty(&regulatory_requests))
403 return false;
404 list_for_each_entry(req, &regulatory_requests, list) {
405 if (alpha2_equal(req->alpha2, alpha2)) {
406 *request = req;
407 return true;
408 }
409 }
410 return false;
411}
412
413/* Used by nl80211 before kmalloc'ing our regulatory domain */ 360/* Used by nl80211 before kmalloc'ing our regulatory domain */
414bool reg_is_valid_request(const char *alpha2) 361bool reg_is_valid_request(const char *alpha2)
415{ 362{
416 struct regulatory_request *request = NULL; 363 if (!last_request)
417 return __reg_is_valid_request(alpha2, &request); 364 return false;
365
366 return alpha2_equal(last_request->alpha2, alpha2);
418} 367}
419 368
420/* Sanity check on a regulatory rule */ 369/* Sanity check on a regulatory rule */
@@ -423,7 +372,7 @@ static bool is_valid_reg_rule(const struct ieee80211_reg_rule *rule)
423 const struct ieee80211_freq_range *freq_range = &rule->freq_range; 372 const struct ieee80211_freq_range *freq_range = &rule->freq_range;
424 u32 freq_diff; 373 u32 freq_diff;
425 374
426 if (freq_range->start_freq_khz == 0 || freq_range->end_freq_khz == 0) 375 if (freq_range->start_freq_khz <= 0 || freq_range->end_freq_khz <= 0)
427 return false; 376 return false;
428 377
429 if (freq_range->start_freq_khz > freq_range->end_freq_khz) 378 if (freq_range->start_freq_khz > freq_range->end_freq_khz)
@@ -431,7 +380,7 @@ static bool is_valid_reg_rule(const struct ieee80211_reg_rule *rule)
431 380
432 freq_diff = freq_range->end_freq_khz - freq_range->start_freq_khz; 381 freq_diff = freq_range->end_freq_khz - freq_range->start_freq_khz;
433 382
434 if (freq_range->max_bandwidth_khz > freq_diff) 383 if (freq_diff <= 0 || freq_range->max_bandwidth_khz > freq_diff)
435 return false; 384 return false;
436 385
437 return true; 386 return true;
@@ -445,6 +394,9 @@ static bool is_valid_rd(const struct ieee80211_regdomain *rd)
445 if (!rd->n_reg_rules) 394 if (!rd->n_reg_rules)
446 return false; 395 return false;
447 396
397 if (WARN_ON(rd->n_reg_rules > NL80211_MAX_SUPP_REG_RULES))
398 return false;
399
448 for (i = 0; i < rd->n_reg_rules; i++) { 400 for (i = 0; i < rd->n_reg_rules; i++) {
449 reg_rule = &rd->reg_rules[i]; 401 reg_rule = &rd->reg_rules[i];
450 if (!is_valid_reg_rule(reg_rule)) 402 if (!is_valid_reg_rule(reg_rule))
@@ -469,6 +421,311 @@ static u32 freq_max_bandwidth(const struct ieee80211_freq_range *freq_range,
469 return 0; 421 return 0;
470} 422}
471 423
424/* Converts a country IE to a regulatory domain. A regulatory domain
425 * structure has a lot of information which the IE doesn't yet have,
426 * so for the other values we use upper max values as we will intersect
427 * with our userspace regulatory agent to get lower bounds. */
428static struct ieee80211_regdomain *country_ie_2_rd(
429 u8 *country_ie,
430 u8 country_ie_len,
431 u32 *checksum)
432{
433 struct ieee80211_regdomain *rd = NULL;
434 unsigned int i = 0;
435 char alpha2[2];
436 u32 flags = 0;
437 u32 num_rules = 0, size_of_regd = 0;
438 u8 *triplets_start = NULL;
439 u8 len_at_triplet = 0;
440 /* the last channel we have registered in a subband (triplet) */
441 int last_sub_max_channel = 0;
442
443 *checksum = 0xDEADBEEF;
444
445 /* Country IE requirements */
446 BUG_ON(country_ie_len < IEEE80211_COUNTRY_IE_MIN_LEN ||
447 country_ie_len & 0x01);
448
449 alpha2[0] = country_ie[0];
450 alpha2[1] = country_ie[1];
451
452 /*
453 * Third octet can be:
454 * 'I' - Indoor
455 * 'O' - Outdoor
456 *
457 * anything else we assume is no restrictions
458 */
459 if (country_ie[2] == 'I')
460 flags = NL80211_RRF_NO_OUTDOOR;
461 else if (country_ie[2] == 'O')
462 flags = NL80211_RRF_NO_INDOOR;
463
464 country_ie += 3;
465 country_ie_len -= 3;
466
467 triplets_start = country_ie;
468 len_at_triplet = country_ie_len;
469
470 *checksum ^= ((flags ^ alpha2[0] ^ alpha2[1]) << 8);
471
472 /* We need to build a reg rule for each triplet, but first we must
473 * calculate the number of reg rules we will need. We will need one
474 * for each channel subband */
475 while (country_ie_len >= 3) {
476 struct ieee80211_country_ie_triplet *triplet =
477 (struct ieee80211_country_ie_triplet *) country_ie;
478 int cur_sub_max_channel = 0, cur_channel = 0;
479
480 if (triplet->ext.reg_extension_id >=
481 IEEE80211_COUNTRY_EXTENSION_ID) {
482 country_ie += 3;
483 country_ie_len -= 3;
484 continue;
485 }
486
487 cur_channel = triplet->chans.first_channel;
488 cur_sub_max_channel = ieee80211_channel_to_frequency(
489 cur_channel + triplet->chans.num_channels);
490
491 /* Basic sanity check */
492 if (cur_sub_max_channel < cur_channel)
493 return NULL;
494
495 /* Do not allow overlapping channels. Also channels
496 * passed in each subband must be monotonically
497 * increasing */
498 if (last_sub_max_channel) {
499 if (cur_channel <= last_sub_max_channel)
500 return NULL;
501 if (cur_sub_max_channel <= last_sub_max_channel)
502 return NULL;
503 }
504
505 /* When dot11RegulatoryClassesRequired is supported
506 * we can throw ext triplets as part of this soup,
507 * for now we don't care when those change as we
508 * don't support them */
509 *checksum ^= ((cur_channel ^ cur_sub_max_channel) << 8) |
510 ((cur_sub_max_channel ^ cur_sub_max_channel) << 16) |
511 ((triplet->chans.max_power ^ cur_sub_max_channel) << 24);
512
513 last_sub_max_channel = cur_sub_max_channel;
514
515 country_ie += 3;
516 country_ie_len -= 3;
517 num_rules++;
518
519 /* Note: this is not a IEEE requirement but
520 * simply a memory requirement */
521 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
522 return NULL;
523 }
524
525 country_ie = triplets_start;
526 country_ie_len = len_at_triplet;
527
528 size_of_regd = sizeof(struct ieee80211_regdomain) +
529 (num_rules * sizeof(struct ieee80211_reg_rule));
530
531 rd = kzalloc(size_of_regd, GFP_KERNEL);
532 if (!rd)
533 return NULL;
534
535 rd->n_reg_rules = num_rules;
536 rd->alpha2[0] = alpha2[0];
537 rd->alpha2[1] = alpha2[1];
538
539 /* This time around we fill in the rd */
540 while (country_ie_len >= 3) {
541 struct ieee80211_country_ie_triplet *triplet =
542 (struct ieee80211_country_ie_triplet *) country_ie;
543 struct ieee80211_reg_rule *reg_rule = NULL;
544 struct ieee80211_freq_range *freq_range = NULL;
545 struct ieee80211_power_rule *power_rule = NULL;
546
547 /* Must parse if dot11RegulatoryClassesRequired is true,
548 * we don't support this yet */
549 if (triplet->ext.reg_extension_id >=
550 IEEE80211_COUNTRY_EXTENSION_ID) {
551 country_ie += 3;
552 country_ie_len -= 3;
553 continue;
554 }
555
556 reg_rule = &rd->reg_rules[i];
557 freq_range = &reg_rule->freq_range;
558 power_rule = &reg_rule->power_rule;
559
560 reg_rule->flags = flags;
561
562 /* The +10 is since the regulatory domain expects
563 * the actual band edge, not the center of freq for
564 * its start and end freqs, assuming 20 MHz bandwidth on
565 * the channels passed */
566 freq_range->start_freq_khz =
567 MHZ_TO_KHZ(ieee80211_channel_to_frequency(
568 triplet->chans.first_channel) - 10);
569 freq_range->end_freq_khz =
570 MHZ_TO_KHZ(ieee80211_channel_to_frequency(
571 triplet->chans.first_channel +
572 triplet->chans.num_channels) + 10);
573
574 /* Large arbitrary values, we intersect later */
575 /* Increment this if we ever support >= 40 MHz channels
576 * in IEEE 802.11 */
577 freq_range->max_bandwidth_khz = MHZ_TO_KHZ(40);
578 power_rule->max_antenna_gain = DBI_TO_MBI(100);
579 power_rule->max_eirp = DBM_TO_MBM(100);
580
581 country_ie += 3;
582 country_ie_len -= 3;
583 i++;
584
585 BUG_ON(i > NL80211_MAX_SUPP_REG_RULES);
586 }
587
588 return rd;
589}
590
591
592/* Helper for regdom_intersect(), this does the real
593 * mathematical intersection fun */
594static int reg_rules_intersect(
595 const struct ieee80211_reg_rule *rule1,
596 const struct ieee80211_reg_rule *rule2,
597 struct ieee80211_reg_rule *intersected_rule)
598{
599 const struct ieee80211_freq_range *freq_range1, *freq_range2;
600 struct ieee80211_freq_range *freq_range;
601 const struct ieee80211_power_rule *power_rule1, *power_rule2;
602 struct ieee80211_power_rule *power_rule;
603 u32 freq_diff;
604
605 freq_range1 = &rule1->freq_range;
606 freq_range2 = &rule2->freq_range;
607 freq_range = &intersected_rule->freq_range;
608
609 power_rule1 = &rule1->power_rule;
610 power_rule2 = &rule2->power_rule;
611 power_rule = &intersected_rule->power_rule;
612
613 freq_range->start_freq_khz = max(freq_range1->start_freq_khz,
614 freq_range2->start_freq_khz);
615 freq_range->end_freq_khz = min(freq_range1->end_freq_khz,
616 freq_range2->end_freq_khz);
617 freq_range->max_bandwidth_khz = min(freq_range1->max_bandwidth_khz,
618 freq_range2->max_bandwidth_khz);
619
620 freq_diff = freq_range->end_freq_khz - freq_range->start_freq_khz;
621 if (freq_range->max_bandwidth_khz > freq_diff)
622 freq_range->max_bandwidth_khz = freq_diff;
623
624 power_rule->max_eirp = min(power_rule1->max_eirp,
625 power_rule2->max_eirp);
626 power_rule->max_antenna_gain = min(power_rule1->max_antenna_gain,
627 power_rule2->max_antenna_gain);
628
629 intersected_rule->flags = (rule1->flags | rule2->flags);
630
631 if (!is_valid_reg_rule(intersected_rule))
632 return -EINVAL;
633
634 return 0;
635}
636
637/**
638 * regdom_intersect - do the intersection between two regulatory domains
639 * @rd1: first regulatory domain
640 * @rd2: second regulatory domain
641 *
642 * Use this function to get the intersection between two regulatory domains.
643 * Once completed we will mark the alpha2 for the rd as intersected, "98",
644 * as no one single alpha2 can represent this regulatory domain.
645 *
646 * Returns a pointer to the regulatory domain structure which will hold the
647 * resulting intersection of rules between rd1 and rd2. We will
648 * kzalloc() this structure for you.
649 */
650static struct ieee80211_regdomain *regdom_intersect(
651 const struct ieee80211_regdomain *rd1,
652 const struct ieee80211_regdomain *rd2)
653{
654 int r, size_of_regd;
655 unsigned int x, y;
656 unsigned int num_rules = 0, rule_idx = 0;
657 const struct ieee80211_reg_rule *rule1, *rule2;
658 struct ieee80211_reg_rule *intersected_rule;
659 struct ieee80211_regdomain *rd;
660 /* This is just a dummy holder to help us count */
661 struct ieee80211_reg_rule irule;
662
663 /* Uses the stack temporarily for counter arithmetic */
664 intersected_rule = &irule;
665
666 memset(intersected_rule, 0, sizeof(struct ieee80211_reg_rule));
667
668 if (!rd1 || !rd2)
669 return NULL;
670
671 /* First we get a count of the rules we'll need, then we actually
672 * build them. This is to so we can malloc() and free() a
673 * regdomain once. The reason we use reg_rules_intersect() here
674 * is it will return -EINVAL if the rule computed makes no sense.
675 * All rules that do check out OK are valid. */
676
677 for (x = 0; x < rd1->n_reg_rules; x++) {
678 rule1 = &rd1->reg_rules[x];
679 for (y = 0; y < rd2->n_reg_rules; y++) {
680 rule2 = &rd2->reg_rules[y];
681 if (!reg_rules_intersect(rule1, rule2,
682 intersected_rule))
683 num_rules++;
684 memset(intersected_rule, 0,
685 sizeof(struct ieee80211_reg_rule));
686 }
687 }
688
689 if (!num_rules)
690 return NULL;
691
692 size_of_regd = sizeof(struct ieee80211_regdomain) +
693 ((num_rules + 1) * sizeof(struct ieee80211_reg_rule));
694
695 rd = kzalloc(size_of_regd, GFP_KERNEL);
696 if (!rd)
697 return NULL;
698
699 for (x = 0; x < rd1->n_reg_rules; x++) {
700 rule1 = &rd1->reg_rules[x];
701 for (y = 0; y < rd2->n_reg_rules; y++) {
702 rule2 = &rd2->reg_rules[y];
703 /* This time around instead of using the stack lets
704 * write to the target rule directly saving ourselves
705 * a memcpy() */
706 intersected_rule = &rd->reg_rules[rule_idx];
707 r = reg_rules_intersect(rule1, rule2,
708 intersected_rule);
709 /* No need to memset here the intersected rule here as
710 * we're not using the stack anymore */
711 if (r)
712 continue;
713 rule_idx++;
714 }
715 }
716
717 if (rule_idx != num_rules) {
718 kfree(rd);
719 return NULL;
720 }
721
722 rd->n_reg_rules = num_rules;
723 rd->alpha2[0] = '9';
724 rd->alpha2[1] = '8';
725
726 return rd;
727}
728
472/* XXX: add support for the rest of enum nl80211_reg_rule_flags, we may 729/* XXX: add support for the rest of enum nl80211_reg_rule_flags, we may
473 * want to just have the channel structure use these */ 730 * want to just have the channel structure use these */
474static u32 map_regdom_flags(u32 rd_flags) 731static u32 map_regdom_flags(u32 rd_flags)
@@ -559,12 +816,23 @@ static void handle_band(struct ieee80211_supported_band *sband)
559 handle_channel(&sband->channels[i]); 816 handle_channel(&sband->channels[i]);
560} 817}
561 818
819static bool ignore_reg_update(struct wiphy *wiphy, enum reg_set_by setby)
820{
821 if (!last_request)
822 return true;
823 if (setby == REGDOM_SET_BY_CORE &&
824 wiphy->fw_handles_regulatory)
825 return true;
826 return false;
827}
828
562static void update_all_wiphy_regulatory(enum reg_set_by setby) 829static void update_all_wiphy_regulatory(enum reg_set_by setby)
563{ 830{
564 struct cfg80211_registered_device *drv; 831 struct cfg80211_registered_device *drv;
565 832
566 list_for_each_entry(drv, &cfg80211_drv_list, list) 833 list_for_each_entry(drv, &cfg80211_drv_list, list)
567 wiphy_update_regulatory(&drv->wiphy, setby); 834 if (!ignore_reg_update(&drv->wiphy, setby))
835 wiphy_update_regulatory(&drv->wiphy, setby);
568} 836}
569 837
570void wiphy_update_regulatory(struct wiphy *wiphy, enum reg_set_by setby) 838void wiphy_update_regulatory(struct wiphy *wiphy, enum reg_set_by setby)
@@ -578,78 +846,237 @@ void wiphy_update_regulatory(struct wiphy *wiphy, enum reg_set_by setby)
578 } 846 }
579} 847}
580 848
581/* Caller must hold &cfg80211_drv_mutex */ 849/* Return value which can be used by ignore_request() to indicate
582int __regulatory_hint(struct wiphy *wiphy, enum reg_set_by set_by, 850 * it has been determined we should intersect two regulatory domains */
583 const char *alpha2, struct ieee80211_regdomain *rd) 851#define REG_INTERSECT 1
584{
585 struct regulatory_request *request;
586 char *rd_alpha2;
587 int r = 0;
588
589 r = ignore_request(wiphy, set_by, (char *) alpha2, rd);
590 if (r)
591 return r;
592 852
593 if (rd) 853/* This has the logic which determines when a new request
594 rd_alpha2 = rd->alpha2; 854 * should be ignored. */
595 else 855static int ignore_request(struct wiphy *wiphy, enum reg_set_by set_by,
596 rd_alpha2 = (char *) alpha2; 856 const char *alpha2)
857{
858 /* All initial requests are respected */
859 if (!last_request)
860 return 0;
597 861
598 switch (set_by) { 862 switch (set_by) {
863 case REGDOM_SET_BY_INIT:
864 return -EINVAL;
599 case REGDOM_SET_BY_CORE: 865 case REGDOM_SET_BY_CORE:
866 /*
867 * Always respect new wireless core hints, should only happen
868 * when updating the world regulatory domain at init.
869 */
870 return 0;
600 case REGDOM_SET_BY_COUNTRY_IE: 871 case REGDOM_SET_BY_COUNTRY_IE:
872 if (unlikely(!is_an_alpha2(alpha2)))
873 return -EINVAL;
874 if (last_request->initiator == REGDOM_SET_BY_COUNTRY_IE) {
875 if (last_request->wiphy != wiphy) {
876 /*
877 * Two cards with two APs claiming different
878 * different Country IE alpha2s. We could
879 * intersect them, but that seems unlikely
880 * to be correct. Reject second one for now.
881 */
882 if (!alpha2_equal(alpha2,
883 cfg80211_regdomain->alpha2))
884 return -EOPNOTSUPP;
885 return -EALREADY;
886 }
887 /* Two consecutive Country IE hints on the same wiphy.
888 * This should be picked up early by the driver/stack */
889 if (WARN_ON(!alpha2_equal(cfg80211_regdomain->alpha2,
890 alpha2)))
891 return 0;
892 return -EALREADY;
893 }
894 return REG_INTERSECT;
601 case REGDOM_SET_BY_DRIVER: 895 case REGDOM_SET_BY_DRIVER:
896 if (last_request->initiator == REGDOM_SET_BY_DRIVER)
897 return -EALREADY;
898 return 0;
602 case REGDOM_SET_BY_USER: 899 case REGDOM_SET_BY_USER:
603 request = kzalloc(sizeof(struct regulatory_request), 900 if (last_request->initiator == REGDOM_SET_BY_COUNTRY_IE)
604 GFP_KERNEL); 901 return REG_INTERSECT;
605 if (!request) 902 /* If the user knows better the user should set the regdom
606 return -ENOMEM; 903 * to their country before the IE is picked up */
607 904 if (last_request->initiator == REGDOM_SET_BY_USER &&
608 request->alpha2[0] = rd_alpha2[0]; 905 last_request->intersect)
609 request->alpha2[1] = rd_alpha2[1]; 906 return -EOPNOTSUPP;
610 request->initiator = set_by; 907 return 0;
611 request->wiphy = wiphy;
612
613 list_add_tail(&request->list, &regulatory_requests);
614 if (rd)
615 break;
616 r = call_crda(alpha2);
617#ifndef CONFIG_WIRELESS_OLD_REGULATORY
618 if (r)
619 printk(KERN_ERR "cfg80211: Failed calling CRDA\n");
620#endif
621 break;
622 default:
623 r = -ENOTSUPP;
624 break;
625 } 908 }
626 909
627 return r; 910 return -EINVAL;
628} 911}
629 912
630/* If rd is not NULL and if this call fails the caller must free it */ 913/* Caller must hold &cfg80211_drv_mutex */
631int regulatory_hint(struct wiphy *wiphy, const char *alpha2, 914int __regulatory_hint(struct wiphy *wiphy, enum reg_set_by set_by,
632 struct ieee80211_regdomain *rd) 915 const char *alpha2,
916 u32 country_ie_checksum,
917 enum environment_cap env)
633{ 918{
634 int r; 919 struct regulatory_request *request;
635 BUG_ON(!rd && !alpha2); 920 bool intersect = false;
921 int r = 0;
636 922
637 mutex_lock(&cfg80211_drv_mutex); 923 r = ignore_request(wiphy, set_by, alpha2);
638 924
639 r = __regulatory_hint(wiphy, REGDOM_SET_BY_DRIVER, alpha2, rd); 925 if (r == REG_INTERSECT)
640 if (r || !rd) 926 intersect = true;
641 goto unlock_and_exit; 927 else if (r)
928 return r;
642 929
643 /* If the driver passed a regulatory domain we skipped asking 930 request = kzalloc(sizeof(struct regulatory_request),
644 * userspace for one so we can now go ahead and set it */ 931 GFP_KERNEL);
645 r = set_regdom(rd); 932 if (!request)
933 return -ENOMEM;
934
935 request->alpha2[0] = alpha2[0];
936 request->alpha2[1] = alpha2[1];
937 request->initiator = set_by;
938 request->wiphy = wiphy;
939 request->intersect = intersect;
940 request->country_ie_checksum = country_ie_checksum;
941 request->country_ie_env = env;
942
943 kfree(last_request);
944 last_request = request;
945 /*
946 * Note: When CONFIG_WIRELESS_OLD_REGULATORY is enabled
947 * AND if CRDA is NOT present nothing will happen, if someone
948 * wants to bother with 11d with OLD_REG you can add a timer.
949 * If after x amount of time nothing happens you can call:
950 *
951 * return set_regdom(country_ie_regdomain);
952 *
953 * to intersect with the static rd
954 */
955 return call_crda(alpha2);
956}
957
958void regulatory_hint(struct wiphy *wiphy, const char *alpha2)
959{
960 BUG_ON(!alpha2);
646 961
647unlock_and_exit: 962 mutex_lock(&cfg80211_drv_mutex);
963 __regulatory_hint(wiphy, REGDOM_SET_BY_DRIVER, alpha2, 0, ENVIRON_ANY);
648 mutex_unlock(&cfg80211_drv_mutex); 964 mutex_unlock(&cfg80211_drv_mutex);
649 return r;
650} 965}
651EXPORT_SYMBOL(regulatory_hint); 966EXPORT_SYMBOL(regulatory_hint);
652 967
968static bool reg_same_country_ie_hint(struct wiphy *wiphy,
969 u32 country_ie_checksum)
970{
971 if (!last_request->wiphy)
972 return false;
973 if (likely(last_request->wiphy != wiphy))
974 return !country_ie_integrity_changes(country_ie_checksum);
975 /* We should not have let these through at this point, they
976 * should have been picked up earlier by the first alpha2 check
977 * on the device */
978 if (WARN_ON(!country_ie_integrity_changes(country_ie_checksum)))
979 return true;
980 return false;
981}
982
983void regulatory_hint_11d(struct wiphy *wiphy,
984 u8 *country_ie,
985 u8 country_ie_len)
986{
987 struct ieee80211_regdomain *rd = NULL;
988 char alpha2[2];
989 u32 checksum = 0;
990 enum environment_cap env = ENVIRON_ANY;
991
992 if (!last_request)
993 return;
994
995 mutex_lock(&cfg80211_drv_mutex);
996
997 /* IE len must be evenly divisible by 2 */
998 if (country_ie_len & 0x01)
999 goto out;
1000
1001 if (country_ie_len < IEEE80211_COUNTRY_IE_MIN_LEN)
1002 goto out;
1003
1004 /* Pending country IE processing, this can happen after we
1005 * call CRDA and wait for a response if a beacon was received before
1006 * we were able to process the last regulatory_hint_11d() call */
1007 if (country_ie_regdomain)
1008 goto out;
1009
1010 alpha2[0] = country_ie[0];
1011 alpha2[1] = country_ie[1];
1012
1013 if (country_ie[2] == 'I')
1014 env = ENVIRON_INDOOR;
1015 else if (country_ie[2] == 'O')
1016 env = ENVIRON_OUTDOOR;
1017
1018 /* We will run this for *every* beacon processed for the BSSID, so
1019 * we optimize an early check to exit out early if we don't have to
1020 * do anything */
1021 if (likely(last_request->wiphy)) {
1022 struct cfg80211_registered_device *drv_last_ie;
1023
1024 drv_last_ie = wiphy_to_dev(last_request->wiphy);
1025
1026 /* Lets keep this simple -- we trust the first AP
1027 * after we intersect with CRDA */
1028 if (likely(last_request->wiphy == wiphy)) {
1029 /* Ignore IEs coming in on this wiphy with
1030 * the same alpha2 and environment cap */
1031 if (likely(alpha2_equal(drv_last_ie->country_ie_alpha2,
1032 alpha2) &&
1033 env == drv_last_ie->env)) {
1034 goto out;
1035 }
1036 /* the wiphy moved on to another BSSID or the AP
1037 * was reconfigured. XXX: We need to deal with the
1038 * case where the user suspends and goes to goes
1039 * to another country, and then gets IEs from an
1040 * AP with different settings */
1041 goto out;
1042 } else {
1043 /* Ignore IEs coming in on two separate wiphys with
1044 * the same alpha2 and environment cap */
1045 if (likely(alpha2_equal(drv_last_ie->country_ie_alpha2,
1046 alpha2) &&
1047 env == drv_last_ie->env)) {
1048 goto out;
1049 }
1050 /* We could potentially intersect though */
1051 goto out;
1052 }
1053 }
1054
1055 rd = country_ie_2_rd(country_ie, country_ie_len, &checksum);
1056 if (!rd)
1057 goto out;
1058
1059 /* This will not happen right now but we leave it here for the
1060 * the future when we want to add suspend/resume support and having
1061 * the user move to another country after doing so, or having the user
1062 * move to another AP. Right now we just trust the first AP. This is why
1063 * this is marked as likley(). If we hit this before we add this support
1064 * we want to be informed of it as it would indicate a mistake in the
1065 * current design */
1066 if (likely(WARN_ON(reg_same_country_ie_hint(wiphy, checksum))))
1067 goto out;
1068
1069 /* We keep this around for when CRDA comes back with a response so
1070 * we can intersect with that */
1071 country_ie_regdomain = rd;
1072
1073 __regulatory_hint(wiphy, REGDOM_SET_BY_COUNTRY_IE,
1074 country_ie_regdomain->alpha2, checksum, env);
1075
1076out:
1077 mutex_unlock(&cfg80211_drv_mutex);
1078}
1079EXPORT_SYMBOL(regulatory_hint_11d);
653 1080
654static void print_rd_rules(const struct ieee80211_regdomain *rd) 1081static void print_rd_rules(const struct ieee80211_regdomain *rd)
655{ 1082{
@@ -689,7 +1116,25 @@ static void print_rd_rules(const struct ieee80211_regdomain *rd)
689static void print_regdomain(const struct ieee80211_regdomain *rd) 1116static void print_regdomain(const struct ieee80211_regdomain *rd)
690{ 1117{
691 1118
692 if (is_world_regdom(rd->alpha2)) 1119 if (is_intersected_alpha2(rd->alpha2)) {
1120 struct wiphy *wiphy = NULL;
1121 struct cfg80211_registered_device *drv;
1122
1123 if (last_request->initiator == REGDOM_SET_BY_COUNTRY_IE) {
1124 if (last_request->wiphy) {
1125 wiphy = last_request->wiphy;
1126 drv = wiphy_to_dev(wiphy);
1127 printk(KERN_INFO "cfg80211: Current regulatory "
1128 "domain updated by AP to: %c%c\n",
1129 drv->country_ie_alpha2[0],
1130 drv->country_ie_alpha2[1]);
1131 } else
1132 printk(KERN_INFO "cfg80211: Current regulatory "
1133 "domain intersected: \n");
1134 } else
1135 printk(KERN_INFO "cfg80211: Current regulatory "
1136 "intersected: \n");
1137 } else if (is_world_regdom(rd->alpha2))
693 printk(KERN_INFO "cfg80211: World regulatory " 1138 printk(KERN_INFO "cfg80211: World regulatory "
694 "domain updated:\n"); 1139 "domain updated:\n");
695 else { 1140 else {
@@ -705,21 +1150,50 @@ static void print_regdomain(const struct ieee80211_regdomain *rd)
705 print_rd_rules(rd); 1150 print_rd_rules(rd);
706} 1151}
707 1152
708void print_regdomain_info(const struct ieee80211_regdomain *rd) 1153static void print_regdomain_info(const struct ieee80211_regdomain *rd)
709{ 1154{
710 printk(KERN_INFO "cfg80211: Regulatory domain: %c%c\n", 1155 printk(KERN_INFO "cfg80211: Regulatory domain: %c%c\n",
711 rd->alpha2[0], rd->alpha2[1]); 1156 rd->alpha2[0], rd->alpha2[1]);
712 print_rd_rules(rd); 1157 print_rd_rules(rd);
713} 1158}
714 1159
715static int __set_regdom(const struct ieee80211_regdomain *rd) 1160#ifdef CONFIG_CFG80211_REG_DEBUG
1161static void reg_country_ie_process_debug(
1162 const struct ieee80211_regdomain *rd,
1163 const struct ieee80211_regdomain *country_ie_regdomain,
1164 const struct ieee80211_regdomain *intersected_rd)
716{ 1165{
717 struct regulatory_request *request = NULL; 1166 printk(KERN_DEBUG "cfg80211: Received country IE:\n");
1167 print_regdomain_info(country_ie_regdomain);
1168 printk(KERN_DEBUG "cfg80211: CRDA thinks this should applied:\n");
1169 print_regdomain_info(rd);
1170 if (intersected_rd) {
1171 printk(KERN_DEBUG "cfg80211: We intersect both of these "
1172 "and get:\n");
1173 print_regdomain_info(rd);
1174 return;
1175 }
1176 printk(KERN_DEBUG "cfg80211: Intersection between both failed\n");
1177}
1178#else
1179static inline void reg_country_ie_process_debug(
1180 const struct ieee80211_regdomain *rd,
1181 const struct ieee80211_regdomain *country_ie_regdomain,
1182 const struct ieee80211_regdomain *intersected_rd)
1183{
1184}
1185#endif
718 1186
1187/* Takes ownership of rd only if it doesn't fail */
1188static int __set_regdom(const struct ieee80211_regdomain *rd)
1189{
1190 const struct ieee80211_regdomain *intersected_rd = NULL;
1191 struct cfg80211_registered_device *drv = NULL;
1192 struct wiphy *wiphy = NULL;
719 /* Some basic sanity checks first */ 1193 /* Some basic sanity checks first */
720 1194
721 if (is_world_regdom(rd->alpha2)) { 1195 if (is_world_regdom(rd->alpha2)) {
722 if (WARN_ON(!__reg_is_valid_request(rd->alpha2, &request))) 1196 if (WARN_ON(!reg_is_valid_request(rd->alpha2)))
723 return -EINVAL; 1197 return -EINVAL;
724 update_world_regdomain(rd); 1198 update_world_regdomain(rd);
725 return 0; 1199 return 0;
@@ -729,45 +1203,102 @@ static int __set_regdom(const struct ieee80211_regdomain *rd)
729 !is_unknown_alpha2(rd->alpha2)) 1203 !is_unknown_alpha2(rd->alpha2))
730 return -EINVAL; 1204 return -EINVAL;
731 1205
732 if (list_empty(&regulatory_requests)) 1206 if (!last_request)
733 return -EINVAL; 1207 return -EINVAL;
734 1208
735 /* allow overriding the static definitions if CRDA is present */ 1209 /* Lets only bother proceeding on the same alpha2 if the current
736 if (!is_old_static_regdom(cfg80211_regdomain) && 1210 * rd is non static (it means CRDA was present and was used last)
737 !regdom_changed(rd->alpha2)) 1211 * and the pending request came in from a country IE */
738 return -EINVAL; 1212 if (last_request->initiator != REGDOM_SET_BY_COUNTRY_IE) {
1213 /* If someone else asked us to change the rd lets only bother
1214 * checking if the alpha2 changes if CRDA was already called */
1215 if (!is_old_static_regdom(cfg80211_regdomain) &&
1216 !regdom_changed(rd->alpha2))
1217 return -EINVAL;
1218 }
1219
1220 wiphy = last_request->wiphy;
739 1221
740 /* Now lets set the regulatory domain, update all driver channels 1222 /* Now lets set the regulatory domain, update all driver channels
741 * and finally inform them of what we have done, in case they want 1223 * and finally inform them of what we have done, in case they want
742 * to review or adjust their own settings based on their own 1224 * to review or adjust their own settings based on their own
743 * internal EEPROM data */ 1225 * internal EEPROM data */
744 1226
745 if (WARN_ON(!__reg_is_valid_request(rd->alpha2, &request))) 1227 if (WARN_ON(!reg_is_valid_request(rd->alpha2)))
746 return -EINVAL; 1228 return -EINVAL;
747 1229
748 reset_regdomains(); 1230 if (!is_valid_rd(rd)) {
1231 printk(KERN_ERR "cfg80211: Invalid "
1232 "regulatory domain detected:\n");
1233 print_regdomain_info(rd);
1234 return -EINVAL;
1235 }
749 1236
750 /* Country IE parsing coming soon */ 1237 if (!last_request->intersect) {
751 switch (request->initiator) { 1238 reset_regdomains();
752 case REGDOM_SET_BY_CORE: 1239 cfg80211_regdomain = rd;
753 case REGDOM_SET_BY_DRIVER: 1240 return 0;
754 case REGDOM_SET_BY_USER: 1241 }
755 if (!is_valid_rd(rd)) { 1242
756 printk(KERN_ERR "cfg80211: Invalid " 1243 /* Intersection requires a bit more work */
757 "regulatory domain detected:\n"); 1244
758 print_regdomain_info(rd); 1245 if (last_request->initiator != REGDOM_SET_BY_COUNTRY_IE) {
1246
1247 intersected_rd = regdom_intersect(rd, cfg80211_regdomain);
1248 if (!intersected_rd)
759 return -EINVAL; 1249 return -EINVAL;
760 } 1250
761 break; 1251 /* We can trash what CRDA provided now */
762 case REGDOM_SET_BY_COUNTRY_IE: /* Not yet */ 1252 kfree(rd);
763 WARN_ON(1); 1253 rd = NULL;
764 default: 1254
765 return -EOPNOTSUPP; 1255 reset_regdomains();
1256 cfg80211_regdomain = intersected_rd;
1257
1258 return 0;
766 } 1259 }
767 1260
768 /* Tada! */ 1261 /*
769 cfg80211_regdomain = rd; 1262 * Country IE requests are handled a bit differently, we intersect
770 request->granted = 1; 1263 * the country IE rd with what CRDA believes that country should have
1264 */
1265
1266 BUG_ON(!country_ie_regdomain);
1267
1268 if (rd != country_ie_regdomain) {
1269 /* Intersect what CRDA returned and our what we
1270 * had built from the Country IE received */
1271
1272 intersected_rd = regdom_intersect(rd, country_ie_regdomain);
1273
1274 reg_country_ie_process_debug(rd, country_ie_regdomain,
1275 intersected_rd);
1276
1277 kfree(country_ie_regdomain);
1278 country_ie_regdomain = NULL;
1279 } else {
1280 /* This would happen when CRDA was not present and
1281 * OLD_REGULATORY was enabled. We intersect our Country
1282 * IE rd and what was set on cfg80211 originally */
1283 intersected_rd = regdom_intersect(rd, cfg80211_regdomain);
1284 }
1285
1286 if (!intersected_rd)
1287 return -EINVAL;
1288
1289 drv = wiphy_to_dev(wiphy);
1290
1291 drv->country_ie_alpha2[0] = rd->alpha2[0];
1292 drv->country_ie_alpha2[1] = rd->alpha2[1];
1293 drv->env = last_request->country_ie_env;
1294
1295 BUG_ON(intersected_rd == rd);
1296
1297 kfree(rd);
1298 rd = NULL;
1299
1300 reset_regdomains();
1301 cfg80211_regdomain = intersected_rd;
771 1302
772 return 0; 1303 return 0;
773} 1304}
@@ -775,52 +1306,41 @@ static int __set_regdom(const struct ieee80211_regdomain *rd)
775 1306
776/* Use this call to set the current regulatory domain. Conflicts with 1307/* Use this call to set the current regulatory domain. Conflicts with
777 * multiple drivers can be ironed out later. Caller must've already 1308 * multiple drivers can be ironed out later. Caller must've already
778 * kmalloc'd the rd structure. If this calls fails you should kfree() 1309 * kmalloc'd the rd structure. Caller must hold cfg80211_drv_mutex */
779 * the passed rd. Caller must hold cfg80211_drv_mutex */
780int set_regdom(const struct ieee80211_regdomain *rd) 1310int set_regdom(const struct ieee80211_regdomain *rd)
781{ 1311{
782 struct regulatory_request *this_request = NULL, *prev_request = NULL;
783 int r; 1312 int r;
784 1313
785 if (!list_empty(&regulatory_requests))
786 prev_request = list_first_entry(&regulatory_requests,
787 struct regulatory_request, list);
788
789 /* Note that this doesn't update the wiphys, this is done below */ 1314 /* Note that this doesn't update the wiphys, this is done below */
790 r = __set_regdom(rd); 1315 r = __set_regdom(rd);
791 if (r) 1316 if (r) {
1317 kfree(rd);
792 return r; 1318 return r;
793
794 BUG_ON((!__reg_is_valid_request(rd->alpha2, &this_request)));
795
796 /* The initial standard core update of the world regulatory domain, no
797 * need to keep that request info around if it didn't fail. */
798 if (is_world_regdom(rd->alpha2) &&
799 this_request->initiator == REGDOM_SET_BY_CORE &&
800 this_request->granted) {
801 list_del(&this_request->list);
802 kfree(this_request);
803 this_request = NULL;
804 }
805
806 /* Remove old requests, we only leave behind the last one */
807 if (prev_request) {
808 list_del(&prev_request->list);
809 kfree(prev_request);
810 prev_request = NULL;
811 } 1319 }
812 1320
813 /* This would make this whole thing pointless */ 1321 /* This would make this whole thing pointless */
814 BUG_ON(rd != cfg80211_regdomain); 1322 if (!last_request->intersect)
1323 BUG_ON(rd != cfg80211_regdomain);
815 1324
816 /* update all wiphys now with the new established regulatory domain */ 1325 /* update all wiphys now with the new established regulatory domain */
817 update_all_wiphy_regulatory(this_request->initiator); 1326 update_all_wiphy_regulatory(last_request->initiator);
818 1327
819 print_regdomain(rd); 1328 print_regdomain(cfg80211_regdomain);
820 1329
821 return r; 1330 return r;
822} 1331}
823 1332
1333/* Caller must hold cfg80211_drv_mutex */
1334void reg_device_remove(struct wiphy *wiphy)
1335{
1336 if (!last_request || !last_request->wiphy)
1337 return;
1338 if (last_request->wiphy != wiphy)
1339 return;
1340 last_request->wiphy = NULL;
1341 last_request->country_ie_env = ENVIRON_ANY;
1342}
1343
824int regulatory_init(void) 1344int regulatory_init(void)
825{ 1345{
826 int err; 1346 int err;
@@ -838,13 +1358,13 @@ int regulatory_init(void)
838 * you have CRDA you get it updated, otherwise you get 1358 * you have CRDA you get it updated, otherwise you get
839 * stuck with the static values. We ignore "EU" code as 1359 * stuck with the static values. We ignore "EU" code as
840 * that is not a valid ISO / IEC 3166 alpha2 */ 1360 * that is not a valid ISO / IEC 3166 alpha2 */
841 if (ieee80211_regdom[0] != 'E' && ieee80211_regdom[1] != 'U') 1361 if (ieee80211_regdom[0] != 'E' || ieee80211_regdom[1] != 'U')
842 err = __regulatory_hint(NULL, REGDOM_SET_BY_CORE, 1362 err = __regulatory_hint(NULL, REGDOM_SET_BY_CORE,
843 ieee80211_regdom, NULL); 1363 ieee80211_regdom, 0, ENVIRON_ANY);
844#else 1364#else
845 cfg80211_regdomain = cfg80211_world_regdom; 1365 cfg80211_regdomain = cfg80211_world_regdom;
846 1366
847 err = __regulatory_hint(NULL, REGDOM_SET_BY_CORE, "00", NULL); 1367 err = __regulatory_hint(NULL, REGDOM_SET_BY_CORE, "00", 0, ENVIRON_ANY);
848 if (err) 1368 if (err)
849 printk(KERN_ERR "cfg80211: calling CRDA failed - " 1369 printk(KERN_ERR "cfg80211: calling CRDA failed - "
850 "unable to update world regulatory domain, " 1370 "unable to update world regulatory domain, "
@@ -856,16 +1376,15 @@ int regulatory_init(void)
856 1376
857void regulatory_exit(void) 1377void regulatory_exit(void)
858{ 1378{
859 struct regulatory_request *req, *req_tmp;
860
861 mutex_lock(&cfg80211_drv_mutex); 1379 mutex_lock(&cfg80211_drv_mutex);
862 1380
863 reset_regdomains(); 1381 reset_regdomains();
864 1382
865 list_for_each_entry_safe(req, req_tmp, &regulatory_requests, list) { 1383 kfree(country_ie_regdomain);
866 list_del(&req->list); 1384 country_ie_regdomain = NULL;
867 kfree(req); 1385
868 } 1386 kfree(last_request);
1387
869 platform_device_unregister(reg_pdev); 1388 platform_device_unregister(reg_pdev);
870 1389
871 mutex_unlock(&cfg80211_drv_mutex); 1390 mutex_unlock(&cfg80211_drv_mutex);
diff --git a/net/wireless/reg.h b/net/wireless/reg.h
index a33362872f3c..a76ea3ff7cd6 100644
--- a/net/wireless/reg.h
+++ b/net/wireless/reg.h
@@ -1,13 +1,44 @@
1#ifndef __NET_WIRELESS_REG_H 1#ifndef __NET_WIRELESS_REG_H
2#define __NET_WIRELESS_REG_H 2#define __NET_WIRELESS_REG_H
3 3
4extern struct mutex cfg80211_reg_mutex;
5bool is_world_regdom(const char *alpha2); 4bool is_world_regdom(const char *alpha2);
6bool reg_is_valid_request(const char *alpha2); 5bool reg_is_valid_request(const char *alpha2);
7 6
7void reg_device_remove(struct wiphy *wiphy);
8
8int regulatory_init(void); 9int regulatory_init(void);
9void regulatory_exit(void); 10void regulatory_exit(void);
10 11
11int set_regdom(const struct ieee80211_regdomain *rd); 12int set_regdom(const struct ieee80211_regdomain *rd);
12 13
14enum environment_cap {
15 ENVIRON_ANY,
16 ENVIRON_INDOOR,
17 ENVIRON_OUTDOOR,
18};
19
20
21/**
22 * __regulatory_hint - hint to the wireless core a regulatory domain
23 * @wiphy: if the hint comes from country information from an AP, this
24 * is required to be set to the wiphy that received the information
25 * @alpha2: the ISO/IEC 3166 alpha2 being claimed the regulatory domain
26 * should be in.
27 * @country_ie_checksum: checksum of processed country IE, set this to 0
28 * if the hint did not come from a country IE
29 * @country_ie_env: the environment the IE told us we are in, %ENVIRON_*
30 *
31 * The Wireless subsystem can use this function to hint to the wireless core
32 * what it believes should be the current regulatory domain by giving it an
33 * ISO/IEC 3166 alpha2 country code it knows its regulatory domain should be
34 * in.
35 *
36 * Returns zero if all went fine, %-EALREADY if a regulatory domain had
37 * already been set or other standard error codes.
38 *
39 */
40extern int __regulatory_hint(struct wiphy *wiphy, enum reg_set_by set_by,
41 const char *alpha2, u32 country_ie_checksum,
42 enum environment_cap country_ie_env);
43
13#endif /* __NET_WIRELESS_REG_H */ 44#endif /* __NET_WIRELESS_REG_H */
diff --git a/net/wireless/sysfs.c b/net/wireless/sysfs.c
index 29f820e18251..79a382877641 100644
--- a/net/wireless/sysfs.c
+++ b/net/wireless/sysfs.c
@@ -23,25 +23,20 @@ static inline struct cfg80211_registered_device *dev_to_rdev(
23 return container_of(dev, struct cfg80211_registered_device, wiphy.dev); 23 return container_of(dev, struct cfg80211_registered_device, wiphy.dev);
24} 24}
25 25
26static ssize_t _show_index(struct device *dev, struct device_attribute *attr, 26#define SHOW_FMT(name, fmt, member) \
27 char *buf) 27static ssize_t name ## _show(struct device *dev, \
28{ 28 struct device_attribute *attr, \
29 return sprintf(buf, "%d\n", dev_to_rdev(dev)->idx); 29 char *buf) \
30{ \
31 return sprintf(buf, fmt "\n", dev_to_rdev(dev)->member); \
30} 32}
31 33
32static ssize_t _show_permaddr(struct device *dev, 34SHOW_FMT(index, "%d", idx);
33 struct device_attribute *attr, 35SHOW_FMT(macaddress, "%pM", wiphy.perm_addr);
34 char *buf)
35{
36 unsigned char *addr = dev_to_rdev(dev)->wiphy.perm_addr;
37
38 return sprintf(buf, "%.2x:%.2x:%.2x:%.2x:%.2x:%.2x\n",
39 addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]);
40}
41 36
42static struct device_attribute ieee80211_dev_attrs[] = { 37static struct device_attribute ieee80211_dev_attrs[] = {
43 __ATTR(index, S_IRUGO, _show_index, NULL), 38 __ATTR_RO(index),
44 __ATTR(macaddress, S_IRUGO, _show_permaddr, NULL), 39 __ATTR_RO(macaddress),
45 {} 40 {}
46}; 41};
47 42
diff --git a/net/wireless/util.c b/net/wireless/util.c
index f54424693a38..e76cc28b0345 100644
--- a/net/wireless/util.c
+++ b/net/wireless/util.c
@@ -7,6 +7,25 @@
7#include <asm/bitops.h> 7#include <asm/bitops.h>
8#include "core.h" 8#include "core.h"
9 9
10struct ieee80211_rate *
11ieee80211_get_response_rate(struct ieee80211_supported_band *sband,
12 u64 basic_rates, int bitrate)
13{
14 struct ieee80211_rate *result = &sband->bitrates[0];
15 int i;
16
17 for (i = 0; i < sband->n_bitrates; i++) {
18 if (!(basic_rates & BIT(i)))
19 continue;
20 if (sband->bitrates[i].bitrate > bitrate)
21 continue;
22 result = &sband->bitrates[i];
23 }
24
25 return result;
26}
27EXPORT_SYMBOL(ieee80211_get_response_rate);
28
10int ieee80211_channel_to_frequency(int chan) 29int ieee80211_channel_to_frequency(int chan)
11{ 30{
12 if (chan < 14) 31 if (chan < 14)
diff --git a/net/wireless/wext-compat.c b/net/wireless/wext-compat.c
new file mode 100644
index 000000000000..58e489fd4aed
--- /dev/null
+++ b/net/wireless/wext-compat.c
@@ -0,0 +1,139 @@
1/*
2 * cfg80211 - wext compat code
3 *
4 * This is temporary code until all wireless functionality is migrated
5 * into cfg80211, when that happens all the exports here go away and
6 * we directly assign the wireless handlers of wireless interfaces.
7 *
8 * Copyright 2008 Johannes Berg <johannes@sipsolutions.net>
9 */
10
11#include <linux/wireless.h>
12#include <linux/nl80211.h>
13#include <net/iw_handler.h>
14#include <net/wireless.h>
15#include <net/cfg80211.h>
16#include "core.h"
17
18int cfg80211_wext_giwname(struct net_device *dev,
19 struct iw_request_info *info,
20 char *name, char *extra)
21{
22 struct wireless_dev *wdev = dev->ieee80211_ptr;
23 struct ieee80211_supported_band *sband;
24 bool is_ht = false, is_a = false, is_b = false, is_g = false;
25
26 if (!wdev)
27 return -EOPNOTSUPP;
28
29 sband = wdev->wiphy->bands[IEEE80211_BAND_5GHZ];
30 if (sband) {
31 is_a = true;
32 is_ht |= sband->ht_cap.ht_supported;
33 }
34
35 sband = wdev->wiphy->bands[IEEE80211_BAND_2GHZ];
36 if (sband) {
37 int i;
38 /* Check for mandatory rates */
39 for (i = 0; i < sband->n_bitrates; i++) {
40 if (sband->bitrates[i].bitrate == 10)
41 is_b = true;
42 if (sband->bitrates[i].bitrate == 60)
43 is_g = true;
44 }
45 is_ht |= sband->ht_cap.ht_supported;
46 }
47
48 strcpy(name, "IEEE 802.11");
49 if (is_a)
50 strcat(name, "a");
51 if (is_b)
52 strcat(name, "b");
53 if (is_g)
54 strcat(name, "g");
55 if (is_ht)
56 strcat(name, "n");
57
58 return 0;
59}
60EXPORT_SYMBOL(cfg80211_wext_giwname);
61
62int cfg80211_wext_siwmode(struct net_device *dev, struct iw_request_info *info,
63 u32 *mode, char *extra)
64{
65 struct wireless_dev *wdev = dev->ieee80211_ptr;
66 struct cfg80211_registered_device *rdev;
67 struct vif_params vifparams;
68 enum nl80211_iftype type;
69
70 if (!wdev)
71 return -EOPNOTSUPP;
72
73 rdev = wiphy_to_dev(wdev->wiphy);
74
75 if (!rdev->ops->change_virtual_intf)
76 return -EOPNOTSUPP;
77
78 /* don't support changing VLANs, you just re-create them */
79 if (wdev->iftype == NL80211_IFTYPE_AP_VLAN)
80 return -EOPNOTSUPP;
81
82 switch (*mode) {
83 case IW_MODE_INFRA:
84 type = NL80211_IFTYPE_STATION;
85 break;
86 case IW_MODE_ADHOC:
87 type = NL80211_IFTYPE_ADHOC;
88 break;
89 case IW_MODE_REPEAT:
90 type = NL80211_IFTYPE_WDS;
91 break;
92 case IW_MODE_MONITOR:
93 type = NL80211_IFTYPE_MONITOR;
94 break;
95 default:
96 return -EINVAL;
97 }
98
99 memset(&vifparams, 0, sizeof(vifparams));
100
101 return rdev->ops->change_virtual_intf(wdev->wiphy, dev->ifindex, type,
102 NULL, &vifparams);
103}
104EXPORT_SYMBOL(cfg80211_wext_siwmode);
105
106int cfg80211_wext_giwmode(struct net_device *dev, struct iw_request_info *info,
107 u32 *mode, char *extra)
108{
109 struct wireless_dev *wdev = dev->ieee80211_ptr;
110
111 if (!wdev)
112 return -EOPNOTSUPP;
113
114 switch (wdev->iftype) {
115 case NL80211_IFTYPE_AP:
116 *mode = IW_MODE_MASTER;
117 break;
118 case NL80211_IFTYPE_STATION:
119 *mode = IW_MODE_INFRA;
120 break;
121 case NL80211_IFTYPE_ADHOC:
122 *mode = IW_MODE_ADHOC;
123 break;
124 case NL80211_IFTYPE_MONITOR:
125 *mode = IW_MODE_MONITOR;
126 break;
127 case NL80211_IFTYPE_WDS:
128 *mode = IW_MODE_REPEAT;
129 break;
130 case NL80211_IFTYPE_AP_VLAN:
131 *mode = IW_MODE_SECOND; /* FIXME */
132 break;
133 default:
134 *mode = IW_MODE_AUTO;
135 break;
136 }
137 return 0;
138}
139EXPORT_SYMBOL(cfg80211_wext_giwmode);
diff --git a/net/wireless/wext.c b/net/wireless/wext.c
index d98ffb75119a..e49a2d1ef1e4 100644
--- a/net/wireless/wext.c
+++ b/net/wireless/wext.c
@@ -64,7 +64,7 @@
64 * o Remove spy_offset from struct iw_handler_def 64 * o Remove spy_offset from struct iw_handler_def
65 * o Start deprecating dev->get_wireless_stats, output a warning 65 * o Start deprecating dev->get_wireless_stats, output a warning
66 * o If IW_QUAL_DBM is set, show dBm values in /proc/net/wireless 66 * o If IW_QUAL_DBM is set, show dBm values in /proc/net/wireless
67 * o Don't loose INVALID/DBM flags when clearing UPDATED flags (iwstats) 67 * o Don't lose INVALID/DBM flags when clearing UPDATED flags (iwstats)
68 * 68 *
69 * v8 - 17.02.06 - Jean II 69 * v8 - 17.02.06 - Jean II
70 * o RtNetlink requests support (SET/GET) 70 * o RtNetlink requests support (SET/GET)
diff --git a/net/x25/sysctl_net_x25.c b/net/x25/sysctl_net_x25.c
index 6ebda25c24e9..a5d3416522de 100644
--- a/net/x25/sysctl_net_x25.c
+++ b/net/x25/sysctl_net_x25.c
@@ -24,8 +24,8 @@ static struct ctl_table x25_table[] = {
24 .data = &sysctl_x25_restart_request_timeout, 24 .data = &sysctl_x25_restart_request_timeout,
25 .maxlen = sizeof(int), 25 .maxlen = sizeof(int),
26 .mode = 0644, 26 .mode = 0644,
27 .proc_handler = &proc_dointvec_minmax, 27 .proc_handler = proc_dointvec_minmax,
28 .strategy = &sysctl_intvec, 28 .strategy = sysctl_intvec,
29 .extra1 = &min_timer, 29 .extra1 = &min_timer,
30 .extra2 = &max_timer, 30 .extra2 = &max_timer,
31 }, 31 },
@@ -35,8 +35,8 @@ static struct ctl_table x25_table[] = {
35 .data = &sysctl_x25_call_request_timeout, 35 .data = &sysctl_x25_call_request_timeout,
36 .maxlen = sizeof(int), 36 .maxlen = sizeof(int),
37 .mode = 0644, 37 .mode = 0644,
38 .proc_handler = &proc_dointvec_minmax, 38 .proc_handler = proc_dointvec_minmax,
39 .strategy = &sysctl_intvec, 39 .strategy = sysctl_intvec,
40 .extra1 = &min_timer, 40 .extra1 = &min_timer,
41 .extra2 = &max_timer, 41 .extra2 = &max_timer,
42 }, 42 },
@@ -46,8 +46,8 @@ static struct ctl_table x25_table[] = {
46 .data = &sysctl_x25_reset_request_timeout, 46 .data = &sysctl_x25_reset_request_timeout,
47 .maxlen = sizeof(int), 47 .maxlen = sizeof(int),
48 .mode = 0644, 48 .mode = 0644,
49 .proc_handler = &proc_dointvec_minmax, 49 .proc_handler = proc_dointvec_minmax,
50 .strategy = &sysctl_intvec, 50 .strategy = sysctl_intvec,
51 .extra1 = &min_timer, 51 .extra1 = &min_timer,
52 .extra2 = &max_timer, 52 .extra2 = &max_timer,
53 }, 53 },
@@ -57,8 +57,8 @@ static struct ctl_table x25_table[] = {
57 .data = &sysctl_x25_clear_request_timeout, 57 .data = &sysctl_x25_clear_request_timeout,
58 .maxlen = sizeof(int), 58 .maxlen = sizeof(int),
59 .mode = 0644, 59 .mode = 0644,
60 .proc_handler = &proc_dointvec_minmax, 60 .proc_handler = proc_dointvec_minmax,
61 .strategy = &sysctl_intvec, 61 .strategy = sysctl_intvec,
62 .extra1 = &min_timer, 62 .extra1 = &min_timer,
63 .extra2 = &max_timer, 63 .extra2 = &max_timer,
64 }, 64 },
@@ -68,8 +68,8 @@ static struct ctl_table x25_table[] = {
68 .data = &sysctl_x25_ack_holdback_timeout, 68 .data = &sysctl_x25_ack_holdback_timeout,
69 .maxlen = sizeof(int), 69 .maxlen = sizeof(int),
70 .mode = 0644, 70 .mode = 0644,
71 .proc_handler = &proc_dointvec_minmax, 71 .proc_handler = proc_dointvec_minmax,
72 .strategy = &sysctl_intvec, 72 .strategy = sysctl_intvec,
73 .extra1 = &min_timer, 73 .extra1 = &min_timer,
74 .extra2 = &max_timer, 74 .extra2 = &max_timer,
75 }, 75 },
@@ -79,7 +79,7 @@ static struct ctl_table x25_table[] = {
79 .data = &sysctl_x25_forward, 79 .data = &sysctl_x25_forward,
80 .maxlen = sizeof(int), 80 .maxlen = sizeof(int),
81 .mode = 0644, 81 .mode = 0644,
82 .proc_handler = &proc_dointvec, 82 .proc_handler = proc_dointvec,
83 }, 83 },
84 { 0, }, 84 { 0, },
85}; 85};
diff --git a/net/xfrm/Makefile b/net/xfrm/Makefile
index 0f439a72ccab..c631047e1b27 100644
--- a/net/xfrm/Makefile
+++ b/net/xfrm/Makefile
@@ -3,8 +3,8 @@
3# 3#
4 4
5obj-$(CONFIG_XFRM) := xfrm_policy.o xfrm_state.o xfrm_hash.o \ 5obj-$(CONFIG_XFRM) := xfrm_policy.o xfrm_state.o xfrm_hash.o \
6 xfrm_input.o xfrm_output.o xfrm_algo.o 6 xfrm_input.o xfrm_output.o xfrm_algo.o \
7 xfrm_sysctl.o
7obj-$(CONFIG_XFRM_STATISTICS) += xfrm_proc.o 8obj-$(CONFIG_XFRM_STATISTICS) += xfrm_proc.o
8obj-$(CONFIG_XFRM_USER) += xfrm_user.o 9obj-$(CONFIG_XFRM_USER) += xfrm_user.o
9obj-$(CONFIG_XFRM_IPCOMP) += xfrm_ipcomp.o 10obj-$(CONFIG_XFRM_IPCOMP) += xfrm_ipcomp.o
10
diff --git a/net/xfrm/xfrm_input.c b/net/xfrm/xfrm_input.c
index 75279402ccf4..b4a13178fb40 100644
--- a/net/xfrm/xfrm_input.c
+++ b/net/xfrm/xfrm_input.c
@@ -104,6 +104,7 @@ EXPORT_SYMBOL(xfrm_prepare_input);
104 104
105int xfrm_input(struct sk_buff *skb, int nexthdr, __be32 spi, int encap_type) 105int xfrm_input(struct sk_buff *skb, int nexthdr, __be32 spi, int encap_type)
106{ 106{
107 struct net *net = dev_net(skb->dev);
107 int err; 108 int err;
108 __be32 seq; 109 __be32 seq;
109 struct xfrm_state *x; 110 struct xfrm_state *x;
@@ -127,7 +128,7 @@ int xfrm_input(struct sk_buff *skb, int nexthdr, __be32 spi, int encap_type)
127 128
128 sp = secpath_dup(skb->sp); 129 sp = secpath_dup(skb->sp);
129 if (!sp) { 130 if (!sp) {
130 XFRM_INC_STATS(LINUX_MIB_XFRMINERROR); 131 XFRM_INC_STATS(net, LINUX_MIB_XFRMINERROR);
131 goto drop; 132 goto drop;
132 } 133 }
133 if (skb->sp) 134 if (skb->sp)
@@ -141,19 +142,19 @@ int xfrm_input(struct sk_buff *skb, int nexthdr, __be32 spi, int encap_type)
141 142
142 seq = 0; 143 seq = 0;
143 if (!spi && (err = xfrm_parse_spi(skb, nexthdr, &spi, &seq)) != 0) { 144 if (!spi && (err = xfrm_parse_spi(skb, nexthdr, &spi, &seq)) != 0) {
144 XFRM_INC_STATS(LINUX_MIB_XFRMINHDRERROR); 145 XFRM_INC_STATS(net, LINUX_MIB_XFRMINHDRERROR);
145 goto drop; 146 goto drop;
146 } 147 }
147 148
148 do { 149 do {
149 if (skb->sp->len == XFRM_MAX_DEPTH) { 150 if (skb->sp->len == XFRM_MAX_DEPTH) {
150 XFRM_INC_STATS(LINUX_MIB_XFRMINBUFFERERROR); 151 XFRM_INC_STATS(net, LINUX_MIB_XFRMINBUFFERERROR);
151 goto drop; 152 goto drop;
152 } 153 }
153 154
154 x = xfrm_state_lookup(daddr, spi, nexthdr, family); 155 x = xfrm_state_lookup(net, daddr, spi, nexthdr, family);
155 if (x == NULL) { 156 if (x == NULL) {
156 XFRM_INC_STATS(LINUX_MIB_XFRMINNOSTATES); 157 XFRM_INC_STATS(net, LINUX_MIB_XFRMINNOSTATES);
157 xfrm_audit_state_notfound(skb, family, spi, seq); 158 xfrm_audit_state_notfound(skb, family, spi, seq);
158 goto drop; 159 goto drop;
159 } 160 }
@@ -162,22 +163,22 @@ int xfrm_input(struct sk_buff *skb, int nexthdr, __be32 spi, int encap_type)
162 163
163 spin_lock(&x->lock); 164 spin_lock(&x->lock);
164 if (unlikely(x->km.state != XFRM_STATE_VALID)) { 165 if (unlikely(x->km.state != XFRM_STATE_VALID)) {
165 XFRM_INC_STATS(LINUX_MIB_XFRMINSTATEINVALID); 166 XFRM_INC_STATS(net, LINUX_MIB_XFRMINSTATEINVALID);
166 goto drop_unlock; 167 goto drop_unlock;
167 } 168 }
168 169
169 if ((x->encap ? x->encap->encap_type : 0) != encap_type) { 170 if ((x->encap ? x->encap->encap_type : 0) != encap_type) {
170 XFRM_INC_STATS(LINUX_MIB_XFRMINSTATEMISMATCH); 171 XFRM_INC_STATS(net, LINUX_MIB_XFRMINSTATEMISMATCH);
171 goto drop_unlock; 172 goto drop_unlock;
172 } 173 }
173 174
174 if (x->props.replay_window && xfrm_replay_check(x, skb, seq)) { 175 if (x->props.replay_window && xfrm_replay_check(x, skb, seq)) {
175 XFRM_INC_STATS(LINUX_MIB_XFRMINSTATESEQERROR); 176 XFRM_INC_STATS(net, LINUX_MIB_XFRMINSTATESEQERROR);
176 goto drop_unlock; 177 goto drop_unlock;
177 } 178 }
178 179
179 if (xfrm_state_check_expire(x)) { 180 if (xfrm_state_check_expire(x)) {
180 XFRM_INC_STATS(LINUX_MIB_XFRMINSTATEEXPIRED); 181 XFRM_INC_STATS(net, LINUX_MIB_XFRMINSTATEEXPIRED);
181 goto drop_unlock; 182 goto drop_unlock;
182 } 183 }
183 184
@@ -198,7 +199,7 @@ resume:
198 x->type->proto); 199 x->type->proto);
199 x->stats.integrity_failed++; 200 x->stats.integrity_failed++;
200 } 201 }
201 XFRM_INC_STATS(LINUX_MIB_XFRMINSTATEPROTOERROR); 202 XFRM_INC_STATS(net, LINUX_MIB_XFRMINSTATEPROTOERROR);
202 goto drop_unlock; 203 goto drop_unlock;
203 } 204 }
204 205
@@ -224,7 +225,7 @@ resume:
224 } 225 }
225 226
226 if (inner_mode->input(x, skb)) { 227 if (inner_mode->input(x, skb)) {
227 XFRM_INC_STATS(LINUX_MIB_XFRMINSTATEMODEERROR); 228 XFRM_INC_STATS(net, LINUX_MIB_XFRMINSTATEMODEERROR);
228 goto drop; 229 goto drop;
229 } 230 }
230 231
@@ -242,7 +243,7 @@ resume:
242 243
243 err = xfrm_parse_spi(skb, nexthdr, &spi, &seq); 244 err = xfrm_parse_spi(skb, nexthdr, &spi, &seq);
244 if (err < 0) { 245 if (err < 0) {
245 XFRM_INC_STATS(LINUX_MIB_XFRMINHDRERROR); 246 XFRM_INC_STATS(net, LINUX_MIB_XFRMINHDRERROR);
246 goto drop; 247 goto drop;
247 } 248 }
248 } while (!err); 249 } while (!err);
diff --git a/net/xfrm/xfrm_output.c b/net/xfrm/xfrm_output.c
index dc50f1e71f76..c235597ba8dd 100644
--- a/net/xfrm/xfrm_output.c
+++ b/net/xfrm/xfrm_output.c
@@ -41,6 +41,7 @@ static int xfrm_output_one(struct sk_buff *skb, int err)
41{ 41{
42 struct dst_entry *dst = skb->dst; 42 struct dst_entry *dst = skb->dst;
43 struct xfrm_state *x = dst->xfrm; 43 struct xfrm_state *x = dst->xfrm;
44 struct net *net = xs_net(x);
44 45
45 if (err <= 0) 46 if (err <= 0)
46 goto resume; 47 goto resume;
@@ -48,33 +49,33 @@ static int xfrm_output_one(struct sk_buff *skb, int err)
48 do { 49 do {
49 err = xfrm_state_check_space(x, skb); 50 err = xfrm_state_check_space(x, skb);
50 if (err) { 51 if (err) {
51 XFRM_INC_STATS(LINUX_MIB_XFRMOUTERROR); 52 XFRM_INC_STATS(net, LINUX_MIB_XFRMOUTERROR);
52 goto error_nolock; 53 goto error_nolock;
53 } 54 }
54 55
55 err = x->outer_mode->output(x, skb); 56 err = x->outer_mode->output(x, skb);
56 if (err) { 57 if (err) {
57 XFRM_INC_STATS(LINUX_MIB_XFRMOUTSTATEMODEERROR); 58 XFRM_INC_STATS(net, LINUX_MIB_XFRMOUTSTATEMODEERROR);
58 goto error_nolock; 59 goto error_nolock;
59 } 60 }
60 61
61 spin_lock_bh(&x->lock); 62 spin_lock_bh(&x->lock);
62 err = xfrm_state_check_expire(x); 63 err = xfrm_state_check_expire(x);
63 if (err) { 64 if (err) {
64 XFRM_INC_STATS(LINUX_MIB_XFRMOUTSTATEEXPIRED); 65 XFRM_INC_STATS(net, LINUX_MIB_XFRMOUTSTATEEXPIRED);
65 goto error; 66 goto error;
66 } 67 }
67 68
68 if (x->type->flags & XFRM_TYPE_REPLAY_PROT) { 69 if (x->type->flags & XFRM_TYPE_REPLAY_PROT) {
69 XFRM_SKB_CB(skb)->seq.output = ++x->replay.oseq; 70 XFRM_SKB_CB(skb)->seq.output = ++x->replay.oseq;
70 if (unlikely(x->replay.oseq == 0)) { 71 if (unlikely(x->replay.oseq == 0)) {
71 XFRM_INC_STATS(LINUX_MIB_XFRMOUTSTATESEQERROR); 72 XFRM_INC_STATS(net, LINUX_MIB_XFRMOUTSTATESEQERROR);
72 x->replay.oseq--; 73 x->replay.oseq--;
73 xfrm_audit_state_replay_overflow(x, skb); 74 xfrm_audit_state_replay_overflow(x, skb);
74 err = -EOVERFLOW; 75 err = -EOVERFLOW;
75 goto error; 76 goto error;
76 } 77 }
77 if (xfrm_aevent_is_on()) 78 if (xfrm_aevent_is_on(net))
78 xfrm_replay_notify(x, XFRM_REPLAY_UPDATE); 79 xfrm_replay_notify(x, XFRM_REPLAY_UPDATE);
79 } 80 }
80 81
@@ -89,12 +90,12 @@ static int xfrm_output_one(struct sk_buff *skb, int err)
89 90
90resume: 91resume:
91 if (err) { 92 if (err) {
92 XFRM_INC_STATS(LINUX_MIB_XFRMOUTSTATEPROTOERROR); 93 XFRM_INC_STATS(net, LINUX_MIB_XFRMOUTSTATEPROTOERROR);
93 goto error_nolock; 94 goto error_nolock;
94 } 95 }
95 96
96 if (!(skb->dst = dst_pop(dst))) { 97 if (!(skb->dst = dst_pop(dst))) {
97 XFRM_INC_STATS(LINUX_MIB_XFRMOUTERROR); 98 XFRM_INC_STATS(net, LINUX_MIB_XFRMOUTERROR);
98 err = -EHOSTUNREACH; 99 err = -EHOSTUNREACH;
99 goto error_nolock; 100 goto error_nolock;
100 } 101 }
@@ -178,6 +179,7 @@ static int xfrm_output_gso(struct sk_buff *skb)
178 179
179int xfrm_output(struct sk_buff *skb) 180int xfrm_output(struct sk_buff *skb)
180{ 181{
182 struct net *net = dev_net(skb->dst->dev);
181 int err; 183 int err;
182 184
183 if (skb_is_gso(skb)) 185 if (skb_is_gso(skb))
@@ -186,7 +188,7 @@ int xfrm_output(struct sk_buff *skb)
186 if (skb->ip_summed == CHECKSUM_PARTIAL) { 188 if (skb->ip_summed == CHECKSUM_PARTIAL) {
187 err = skb_checksum_help(skb); 189 err = skb_checksum_help(skb);
188 if (err) { 190 if (err) {
189 XFRM_INC_STATS(LINUX_MIB_XFRMOUTERROR); 191 XFRM_INC_STATS(net, LINUX_MIB_XFRMOUTERROR);
190 kfree_skb(skb); 192 kfree_skb(skb);
191 return err; 193 return err;
192 } 194 }
diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
index fb216c9adf86..9c068ab3a834 100644
--- a/net/xfrm/xfrm_policy.c
+++ b/net/xfrm/xfrm_policy.c
@@ -34,28 +34,16 @@
34 34
35#include "xfrm_hash.h" 35#include "xfrm_hash.h"
36 36
37int sysctl_xfrm_larval_drop __read_mostly = 1;
38
39#ifdef CONFIG_XFRM_STATISTICS
40DEFINE_SNMP_STAT(struct linux_xfrm_mib, xfrm_statistics) __read_mostly;
41EXPORT_SYMBOL(xfrm_statistics);
42#endif
43
44DEFINE_MUTEX(xfrm_cfg_mutex); 37DEFINE_MUTEX(xfrm_cfg_mutex);
45EXPORT_SYMBOL(xfrm_cfg_mutex); 38EXPORT_SYMBOL(xfrm_cfg_mutex);
46 39
47static DEFINE_RWLOCK(xfrm_policy_lock); 40static DEFINE_RWLOCK(xfrm_policy_lock);
48 41
49static struct list_head xfrm_policy_all;
50unsigned int xfrm_policy_count[XFRM_POLICY_MAX*2];
51EXPORT_SYMBOL(xfrm_policy_count);
52
53static DEFINE_RWLOCK(xfrm_policy_afinfo_lock); 42static DEFINE_RWLOCK(xfrm_policy_afinfo_lock);
54static struct xfrm_policy_afinfo *xfrm_policy_afinfo[NPROTO]; 43static struct xfrm_policy_afinfo *xfrm_policy_afinfo[NPROTO];
55 44
56static struct kmem_cache *xfrm_dst_cache __read_mostly; 45static struct kmem_cache *xfrm_dst_cache __read_mostly;
57 46
58static struct work_struct xfrm_policy_gc_work;
59static HLIST_HEAD(xfrm_policy_gc_list); 47static HLIST_HEAD(xfrm_policy_gc_list);
60static DEFINE_SPINLOCK(xfrm_policy_gc_lock); 48static DEFINE_SPINLOCK(xfrm_policy_gc_lock);
61 49
@@ -63,6 +51,9 @@ static struct xfrm_policy_afinfo *xfrm_policy_get_afinfo(unsigned short family);
63static void xfrm_policy_put_afinfo(struct xfrm_policy_afinfo *afinfo); 51static void xfrm_policy_put_afinfo(struct xfrm_policy_afinfo *afinfo);
64static void xfrm_init_pmtu(struct dst_entry *dst); 52static void xfrm_init_pmtu(struct dst_entry *dst);
65 53
54static struct xfrm_policy *__xfrm_policy_unlink(struct xfrm_policy *pol,
55 int dir);
56
66static inline int 57static inline int
67__xfrm4_selector_match(struct xfrm_selector *sel, struct flowi *fl) 58__xfrm4_selector_match(struct xfrm_selector *sel, struct flowi *fl)
68{ 59{
@@ -97,7 +88,7 @@ int xfrm_selector_match(struct xfrm_selector *sel, struct flowi *fl,
97 return 0; 88 return 0;
98} 89}
99 90
100static inline struct dst_entry *__xfrm_dst_lookup(int tos, 91static inline struct dst_entry *__xfrm_dst_lookup(struct net *net, int tos,
101 xfrm_address_t *saddr, 92 xfrm_address_t *saddr,
102 xfrm_address_t *daddr, 93 xfrm_address_t *daddr,
103 int family) 94 int family)
@@ -109,7 +100,7 @@ static inline struct dst_entry *__xfrm_dst_lookup(int tos,
109 if (unlikely(afinfo == NULL)) 100 if (unlikely(afinfo == NULL))
110 return ERR_PTR(-EAFNOSUPPORT); 101 return ERR_PTR(-EAFNOSUPPORT);
111 102
112 dst = afinfo->dst_lookup(tos, saddr, daddr); 103 dst = afinfo->dst_lookup(net, tos, saddr, daddr);
113 104
114 xfrm_policy_put_afinfo(afinfo); 105 xfrm_policy_put_afinfo(afinfo);
115 106
@@ -121,6 +112,7 @@ static inline struct dst_entry *xfrm_dst_lookup(struct xfrm_state *x, int tos,
121 xfrm_address_t *prev_daddr, 112 xfrm_address_t *prev_daddr,
122 int family) 113 int family)
123{ 114{
115 struct net *net = xs_net(x);
124 xfrm_address_t *saddr = &x->props.saddr; 116 xfrm_address_t *saddr = &x->props.saddr;
125 xfrm_address_t *daddr = &x->id.daddr; 117 xfrm_address_t *daddr = &x->id.daddr;
126 struct dst_entry *dst; 118 struct dst_entry *dst;
@@ -134,7 +126,7 @@ static inline struct dst_entry *xfrm_dst_lookup(struct xfrm_state *x, int tos,
134 daddr = x->coaddr; 126 daddr = x->coaddr;
135 } 127 }
136 128
137 dst = __xfrm_dst_lookup(tos, saddr, daddr, family); 129 dst = __xfrm_dst_lookup(net, tos, saddr, daddr, family);
138 130
139 if (!IS_ERR(dst)) { 131 if (!IS_ERR(dst)) {
140 if (prev_saddr != saddr) 132 if (prev_saddr != saddr)
@@ -229,13 +221,14 @@ expired:
229 * SPD calls. 221 * SPD calls.
230 */ 222 */
231 223
232struct xfrm_policy *xfrm_policy_alloc(gfp_t gfp) 224struct xfrm_policy *xfrm_policy_alloc(struct net *net, gfp_t gfp)
233{ 225{
234 struct xfrm_policy *policy; 226 struct xfrm_policy *policy;
235 227
236 policy = kzalloc(sizeof(struct xfrm_policy), gfp); 228 policy = kzalloc(sizeof(struct xfrm_policy), gfp);
237 229
238 if (policy) { 230 if (policy) {
231 write_pnet(&policy->xp_net, net);
239 INIT_LIST_HEAD(&policy->walk.all); 232 INIT_LIST_HEAD(&policy->walk.all);
240 INIT_HLIST_NODE(&policy->bydst); 233 INIT_HLIST_NODE(&policy->bydst);
241 INIT_HLIST_NODE(&policy->byidx); 234 INIT_HLIST_NODE(&policy->byidx);
@@ -296,6 +289,7 @@ static void xfrm_policy_gc_task(struct work_struct *work)
296 hlist_for_each_entry_safe(policy, entry, tmp, &gc_list, bydst) 289 hlist_for_each_entry_safe(policy, entry, tmp, &gc_list, bydst)
297 xfrm_policy_gc_kill(policy); 290 xfrm_policy_gc_kill(policy);
298} 291}
292static DECLARE_WORK(xfrm_policy_gc_work, xfrm_policy_gc_task);
299 293
300/* Rule must be locked. Release descentant resources, announce 294/* Rule must be locked. Release descentant resources, announce
301 * entry dead. The rule must be unlinked from lists to the moment. 295 * entry dead. The rule must be unlinked from lists to the moment.
@@ -322,38 +316,29 @@ static void xfrm_policy_kill(struct xfrm_policy *policy)
322 schedule_work(&xfrm_policy_gc_work); 316 schedule_work(&xfrm_policy_gc_work);
323} 317}
324 318
325struct xfrm_policy_hash {
326 struct hlist_head *table;
327 unsigned int hmask;
328};
329
330static struct hlist_head xfrm_policy_inexact[XFRM_POLICY_MAX*2];
331static struct xfrm_policy_hash xfrm_policy_bydst[XFRM_POLICY_MAX*2] __read_mostly;
332static struct hlist_head *xfrm_policy_byidx __read_mostly;
333static unsigned int xfrm_idx_hmask __read_mostly;
334static unsigned int xfrm_policy_hashmax __read_mostly = 1 * 1024 * 1024; 319static unsigned int xfrm_policy_hashmax __read_mostly = 1 * 1024 * 1024;
335 320
336static inline unsigned int idx_hash(u32 index) 321static inline unsigned int idx_hash(struct net *net, u32 index)
337{ 322{
338 return __idx_hash(index, xfrm_idx_hmask); 323 return __idx_hash(index, net->xfrm.policy_idx_hmask);
339} 324}
340 325
341static struct hlist_head *policy_hash_bysel(struct xfrm_selector *sel, unsigned short family, int dir) 326static struct hlist_head *policy_hash_bysel(struct net *net, struct xfrm_selector *sel, unsigned short family, int dir)
342{ 327{
343 unsigned int hmask = xfrm_policy_bydst[dir].hmask; 328 unsigned int hmask = net->xfrm.policy_bydst[dir].hmask;
344 unsigned int hash = __sel_hash(sel, family, hmask); 329 unsigned int hash = __sel_hash(sel, family, hmask);
345 330
346 return (hash == hmask + 1 ? 331 return (hash == hmask + 1 ?
347 &xfrm_policy_inexact[dir] : 332 &net->xfrm.policy_inexact[dir] :
348 xfrm_policy_bydst[dir].table + hash); 333 net->xfrm.policy_bydst[dir].table + hash);
349} 334}
350 335
351static struct hlist_head *policy_hash_direct(xfrm_address_t *daddr, xfrm_address_t *saddr, unsigned short family, int dir) 336static struct hlist_head *policy_hash_direct(struct net *net, xfrm_address_t *daddr, xfrm_address_t *saddr, unsigned short family, int dir)
352{ 337{
353 unsigned int hmask = xfrm_policy_bydst[dir].hmask; 338 unsigned int hmask = net->xfrm.policy_bydst[dir].hmask;
354 unsigned int hash = __addr_hash(daddr, saddr, family, hmask); 339 unsigned int hash = __addr_hash(daddr, saddr, family, hmask);
355 340
356 return xfrm_policy_bydst[dir].table + hash; 341 return net->xfrm.policy_bydst[dir].table + hash;
357} 342}
358 343
359static void xfrm_dst_hash_transfer(struct hlist_head *list, 344static void xfrm_dst_hash_transfer(struct hlist_head *list,
@@ -408,12 +393,12 @@ static unsigned long xfrm_new_hash_mask(unsigned int old_hmask)
408 return ((old_hmask + 1) << 1) - 1; 393 return ((old_hmask + 1) << 1) - 1;
409} 394}
410 395
411static void xfrm_bydst_resize(int dir) 396static void xfrm_bydst_resize(struct net *net, int dir)
412{ 397{
413 unsigned int hmask = xfrm_policy_bydst[dir].hmask; 398 unsigned int hmask = net->xfrm.policy_bydst[dir].hmask;
414 unsigned int nhashmask = xfrm_new_hash_mask(hmask); 399 unsigned int nhashmask = xfrm_new_hash_mask(hmask);
415 unsigned int nsize = (nhashmask + 1) * sizeof(struct hlist_head); 400 unsigned int nsize = (nhashmask + 1) * sizeof(struct hlist_head);
416 struct hlist_head *odst = xfrm_policy_bydst[dir].table; 401 struct hlist_head *odst = net->xfrm.policy_bydst[dir].table;
417 struct hlist_head *ndst = xfrm_hash_alloc(nsize); 402 struct hlist_head *ndst = xfrm_hash_alloc(nsize);
418 int i; 403 int i;
419 404
@@ -425,20 +410,20 @@ static void xfrm_bydst_resize(int dir)
425 for (i = hmask; i >= 0; i--) 410 for (i = hmask; i >= 0; i--)
426 xfrm_dst_hash_transfer(odst + i, ndst, nhashmask); 411 xfrm_dst_hash_transfer(odst + i, ndst, nhashmask);
427 412
428 xfrm_policy_bydst[dir].table = ndst; 413 net->xfrm.policy_bydst[dir].table = ndst;
429 xfrm_policy_bydst[dir].hmask = nhashmask; 414 net->xfrm.policy_bydst[dir].hmask = nhashmask;
430 415
431 write_unlock_bh(&xfrm_policy_lock); 416 write_unlock_bh(&xfrm_policy_lock);
432 417
433 xfrm_hash_free(odst, (hmask + 1) * sizeof(struct hlist_head)); 418 xfrm_hash_free(odst, (hmask + 1) * sizeof(struct hlist_head));
434} 419}
435 420
436static void xfrm_byidx_resize(int total) 421static void xfrm_byidx_resize(struct net *net, int total)
437{ 422{
438 unsigned int hmask = xfrm_idx_hmask; 423 unsigned int hmask = net->xfrm.policy_idx_hmask;
439 unsigned int nhashmask = xfrm_new_hash_mask(hmask); 424 unsigned int nhashmask = xfrm_new_hash_mask(hmask);
440 unsigned int nsize = (nhashmask + 1) * sizeof(struct hlist_head); 425 unsigned int nsize = (nhashmask + 1) * sizeof(struct hlist_head);
441 struct hlist_head *oidx = xfrm_policy_byidx; 426 struct hlist_head *oidx = net->xfrm.policy_byidx;
442 struct hlist_head *nidx = xfrm_hash_alloc(nsize); 427 struct hlist_head *nidx = xfrm_hash_alloc(nsize);
443 int i; 428 int i;
444 429
@@ -450,18 +435,18 @@ static void xfrm_byidx_resize(int total)
450 for (i = hmask; i >= 0; i--) 435 for (i = hmask; i >= 0; i--)
451 xfrm_idx_hash_transfer(oidx + i, nidx, nhashmask); 436 xfrm_idx_hash_transfer(oidx + i, nidx, nhashmask);
452 437
453 xfrm_policy_byidx = nidx; 438 net->xfrm.policy_byidx = nidx;
454 xfrm_idx_hmask = nhashmask; 439 net->xfrm.policy_idx_hmask = nhashmask;
455 440
456 write_unlock_bh(&xfrm_policy_lock); 441 write_unlock_bh(&xfrm_policy_lock);
457 442
458 xfrm_hash_free(oidx, (hmask + 1) * sizeof(struct hlist_head)); 443 xfrm_hash_free(oidx, (hmask + 1) * sizeof(struct hlist_head));
459} 444}
460 445
461static inline int xfrm_bydst_should_resize(int dir, int *total) 446static inline int xfrm_bydst_should_resize(struct net *net, int dir, int *total)
462{ 447{
463 unsigned int cnt = xfrm_policy_count[dir]; 448 unsigned int cnt = net->xfrm.policy_count[dir];
464 unsigned int hmask = xfrm_policy_bydst[dir].hmask; 449 unsigned int hmask = net->xfrm.policy_bydst[dir].hmask;
465 450
466 if (total) 451 if (total)
467 *total += cnt; 452 *total += cnt;
@@ -473,9 +458,9 @@ static inline int xfrm_bydst_should_resize(int dir, int *total)
473 return 0; 458 return 0;
474} 459}
475 460
476static inline int xfrm_byidx_should_resize(int total) 461static inline int xfrm_byidx_should_resize(struct net *net, int total)
477{ 462{
478 unsigned int hmask = xfrm_idx_hmask; 463 unsigned int hmask = net->xfrm.policy_idx_hmask;
479 464
480 if ((hmask + 1) < xfrm_policy_hashmax && 465 if ((hmask + 1) < xfrm_policy_hashmax &&
481 total > hmask) 466 total > hmask)
@@ -487,41 +472,40 @@ static inline int xfrm_byidx_should_resize(int total)
487void xfrm_spd_getinfo(struct xfrmk_spdinfo *si) 472void xfrm_spd_getinfo(struct xfrmk_spdinfo *si)
488{ 473{
489 read_lock_bh(&xfrm_policy_lock); 474 read_lock_bh(&xfrm_policy_lock);
490 si->incnt = xfrm_policy_count[XFRM_POLICY_IN]; 475 si->incnt = init_net.xfrm.policy_count[XFRM_POLICY_IN];
491 si->outcnt = xfrm_policy_count[XFRM_POLICY_OUT]; 476 si->outcnt = init_net.xfrm.policy_count[XFRM_POLICY_OUT];
492 si->fwdcnt = xfrm_policy_count[XFRM_POLICY_FWD]; 477 si->fwdcnt = init_net.xfrm.policy_count[XFRM_POLICY_FWD];
493 si->inscnt = xfrm_policy_count[XFRM_POLICY_IN+XFRM_POLICY_MAX]; 478 si->inscnt = init_net.xfrm.policy_count[XFRM_POLICY_IN+XFRM_POLICY_MAX];
494 si->outscnt = xfrm_policy_count[XFRM_POLICY_OUT+XFRM_POLICY_MAX]; 479 si->outscnt = init_net.xfrm.policy_count[XFRM_POLICY_OUT+XFRM_POLICY_MAX];
495 si->fwdscnt = xfrm_policy_count[XFRM_POLICY_FWD+XFRM_POLICY_MAX]; 480 si->fwdscnt = init_net.xfrm.policy_count[XFRM_POLICY_FWD+XFRM_POLICY_MAX];
496 si->spdhcnt = xfrm_idx_hmask; 481 si->spdhcnt = init_net.xfrm.policy_idx_hmask;
497 si->spdhmcnt = xfrm_policy_hashmax; 482 si->spdhmcnt = xfrm_policy_hashmax;
498 read_unlock_bh(&xfrm_policy_lock); 483 read_unlock_bh(&xfrm_policy_lock);
499} 484}
500EXPORT_SYMBOL(xfrm_spd_getinfo); 485EXPORT_SYMBOL(xfrm_spd_getinfo);
501 486
502static DEFINE_MUTEX(hash_resize_mutex); 487static DEFINE_MUTEX(hash_resize_mutex);
503static void xfrm_hash_resize(struct work_struct *__unused) 488static void xfrm_hash_resize(struct work_struct *work)
504{ 489{
490 struct net *net = container_of(work, struct net, xfrm.policy_hash_work);
505 int dir, total; 491 int dir, total;
506 492
507 mutex_lock(&hash_resize_mutex); 493 mutex_lock(&hash_resize_mutex);
508 494
509 total = 0; 495 total = 0;
510 for (dir = 0; dir < XFRM_POLICY_MAX * 2; dir++) { 496 for (dir = 0; dir < XFRM_POLICY_MAX * 2; dir++) {
511 if (xfrm_bydst_should_resize(dir, &total)) 497 if (xfrm_bydst_should_resize(net, dir, &total))
512 xfrm_bydst_resize(dir); 498 xfrm_bydst_resize(net, dir);
513 } 499 }
514 if (xfrm_byidx_should_resize(total)) 500 if (xfrm_byidx_should_resize(net, total))
515 xfrm_byidx_resize(total); 501 xfrm_byidx_resize(net, total);
516 502
517 mutex_unlock(&hash_resize_mutex); 503 mutex_unlock(&hash_resize_mutex);
518} 504}
519 505
520static DECLARE_WORK(xfrm_hash_work, xfrm_hash_resize);
521
522/* Generate new index... KAME seems to generate them ordered by cost 506/* Generate new index... KAME seems to generate them ordered by cost
523 * of an absolute inpredictability of ordering of rules. This will not pass. */ 507 * of an absolute inpredictability of ordering of rules. This will not pass. */
524static u32 xfrm_gen_index(u8 type, int dir) 508static u32 xfrm_gen_index(struct net *net, int dir)
525{ 509{
526 static u32 idx_generator; 510 static u32 idx_generator;
527 511
@@ -536,7 +520,7 @@ static u32 xfrm_gen_index(u8 type, int dir)
536 idx_generator += 8; 520 idx_generator += 8;
537 if (idx == 0) 521 if (idx == 0)
538 idx = 8; 522 idx = 8;
539 list = xfrm_policy_byidx + idx_hash(idx); 523 list = net->xfrm.policy_byidx + idx_hash(net, idx);
540 found = 0; 524 found = 0;
541 hlist_for_each_entry(p, entry, list, byidx) { 525 hlist_for_each_entry(p, entry, list, byidx) {
542 if (p->index == idx) { 526 if (p->index == idx) {
@@ -566,6 +550,7 @@ static inline int selector_cmp(struct xfrm_selector *s1, struct xfrm_selector *s
566 550
567int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl) 551int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl)
568{ 552{
553 struct net *net = xp_net(policy);
569 struct xfrm_policy *pol; 554 struct xfrm_policy *pol;
570 struct xfrm_policy *delpol; 555 struct xfrm_policy *delpol;
571 struct hlist_head *chain; 556 struct hlist_head *chain;
@@ -573,7 +558,7 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl)
573 struct dst_entry *gc_list; 558 struct dst_entry *gc_list;
574 559
575 write_lock_bh(&xfrm_policy_lock); 560 write_lock_bh(&xfrm_policy_lock);
576 chain = policy_hash_bysel(&policy->selector, policy->family, dir); 561 chain = policy_hash_bysel(net, &policy->selector, policy->family, dir);
577 delpol = NULL; 562 delpol = NULL;
578 newpos = NULL; 563 newpos = NULL;
579 hlist_for_each_entry(pol, entry, chain, bydst) { 564 hlist_for_each_entry(pol, entry, chain, bydst) {
@@ -600,27 +585,23 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl)
600 else 585 else
601 hlist_add_head(&policy->bydst, chain); 586 hlist_add_head(&policy->bydst, chain);
602 xfrm_pol_hold(policy); 587 xfrm_pol_hold(policy);
603 xfrm_policy_count[dir]++; 588 net->xfrm.policy_count[dir]++;
604 atomic_inc(&flow_cache_genid); 589 atomic_inc(&flow_cache_genid);
605 if (delpol) { 590 if (delpol)
606 hlist_del(&delpol->bydst); 591 __xfrm_policy_unlink(delpol, dir);
607 hlist_del(&delpol->byidx); 592 policy->index = delpol ? delpol->index : xfrm_gen_index(net, dir);
608 list_del(&delpol->walk.all); 593 hlist_add_head(&policy->byidx, net->xfrm.policy_byidx+idx_hash(net, policy->index));
609 xfrm_policy_count[dir]--;
610 }
611 policy->index = delpol ? delpol->index : xfrm_gen_index(policy->type, dir);
612 hlist_add_head(&policy->byidx, xfrm_policy_byidx+idx_hash(policy->index));
613 policy->curlft.add_time = get_seconds(); 594 policy->curlft.add_time = get_seconds();
614 policy->curlft.use_time = 0; 595 policy->curlft.use_time = 0;
615 if (!mod_timer(&policy->timer, jiffies + HZ)) 596 if (!mod_timer(&policy->timer, jiffies + HZ))
616 xfrm_pol_hold(policy); 597 xfrm_pol_hold(policy);
617 list_add(&policy->walk.all, &xfrm_policy_all); 598 list_add(&policy->walk.all, &net->xfrm.policy_all);
618 write_unlock_bh(&xfrm_policy_lock); 599 write_unlock_bh(&xfrm_policy_lock);
619 600
620 if (delpol) 601 if (delpol)
621 xfrm_policy_kill(delpol); 602 xfrm_policy_kill(delpol);
622 else if (xfrm_bydst_should_resize(dir, NULL)) 603 else if (xfrm_bydst_should_resize(net, dir, NULL))
623 schedule_work(&xfrm_hash_work); 604 schedule_work(&net->xfrm.policy_hash_work);
624 605
625 read_lock_bh(&xfrm_policy_lock); 606 read_lock_bh(&xfrm_policy_lock);
626 gc_list = NULL; 607 gc_list = NULL;
@@ -654,7 +635,7 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl)
654} 635}
655EXPORT_SYMBOL(xfrm_policy_insert); 636EXPORT_SYMBOL(xfrm_policy_insert);
656 637
657struct xfrm_policy *xfrm_policy_bysel_ctx(u8 type, int dir, 638struct xfrm_policy *xfrm_policy_bysel_ctx(struct net *net, u8 type, int dir,
658 struct xfrm_selector *sel, 639 struct xfrm_selector *sel,
659 struct xfrm_sec_ctx *ctx, int delete, 640 struct xfrm_sec_ctx *ctx, int delete,
660 int *err) 641 int *err)
@@ -665,7 +646,7 @@ struct xfrm_policy *xfrm_policy_bysel_ctx(u8 type, int dir,
665 646
666 *err = 0; 647 *err = 0;
667 write_lock_bh(&xfrm_policy_lock); 648 write_lock_bh(&xfrm_policy_lock);
668 chain = policy_hash_bysel(sel, sel->family, dir); 649 chain = policy_hash_bysel(net, sel, sel->family, dir);
669 ret = NULL; 650 ret = NULL;
670 hlist_for_each_entry(pol, entry, chain, bydst) { 651 hlist_for_each_entry(pol, entry, chain, bydst) {
671 if (pol->type == type && 652 if (pol->type == type &&
@@ -679,10 +660,7 @@ struct xfrm_policy *xfrm_policy_bysel_ctx(u8 type, int dir,
679 write_unlock_bh(&xfrm_policy_lock); 660 write_unlock_bh(&xfrm_policy_lock);
680 return pol; 661 return pol;
681 } 662 }
682 hlist_del(&pol->bydst); 663 __xfrm_policy_unlink(pol, dir);
683 hlist_del(&pol->byidx);
684 list_del(&pol->walk.all);
685 xfrm_policy_count[dir]--;
686 } 664 }
687 ret = pol; 665 ret = pol;
688 break; 666 break;
@@ -698,8 +676,8 @@ struct xfrm_policy *xfrm_policy_bysel_ctx(u8 type, int dir,
698} 676}
699EXPORT_SYMBOL(xfrm_policy_bysel_ctx); 677EXPORT_SYMBOL(xfrm_policy_bysel_ctx);
700 678
701struct xfrm_policy *xfrm_policy_byid(u8 type, int dir, u32 id, int delete, 679struct xfrm_policy *xfrm_policy_byid(struct net *net, u8 type, int dir, u32 id,
702 int *err) 680 int delete, int *err)
703{ 681{
704 struct xfrm_policy *pol, *ret; 682 struct xfrm_policy *pol, *ret;
705 struct hlist_head *chain; 683 struct hlist_head *chain;
@@ -711,7 +689,7 @@ struct xfrm_policy *xfrm_policy_byid(u8 type, int dir, u32 id, int delete,
711 689
712 *err = 0; 690 *err = 0;
713 write_lock_bh(&xfrm_policy_lock); 691 write_lock_bh(&xfrm_policy_lock);
714 chain = xfrm_policy_byidx + idx_hash(id); 692 chain = net->xfrm.policy_byidx + idx_hash(net, id);
715 ret = NULL; 693 ret = NULL;
716 hlist_for_each_entry(pol, entry, chain, byidx) { 694 hlist_for_each_entry(pol, entry, chain, byidx) {
717 if (pol->type == type && pol->index == id) { 695 if (pol->type == type && pol->index == id) {
@@ -723,10 +701,7 @@ struct xfrm_policy *xfrm_policy_byid(u8 type, int dir, u32 id, int delete,
723 write_unlock_bh(&xfrm_policy_lock); 701 write_unlock_bh(&xfrm_policy_lock);
724 return pol; 702 return pol;
725 } 703 }
726 hlist_del(&pol->bydst); 704 __xfrm_policy_unlink(pol, dir);
727 hlist_del(&pol->byidx);
728 list_del(&pol->walk.all);
729 xfrm_policy_count[dir]--;
730 } 705 }
731 ret = pol; 706 ret = pol;
732 break; 707 break;
@@ -744,7 +719,7 @@ EXPORT_SYMBOL(xfrm_policy_byid);
744 719
745#ifdef CONFIG_SECURITY_NETWORK_XFRM 720#ifdef CONFIG_SECURITY_NETWORK_XFRM
746static inline int 721static inline int
747xfrm_policy_flush_secctx_check(u8 type, struct xfrm_audit *audit_info) 722xfrm_policy_flush_secctx_check(struct net *net, u8 type, struct xfrm_audit *audit_info)
748{ 723{
749 int dir, err = 0; 724 int dir, err = 0;
750 725
@@ -754,7 +729,7 @@ xfrm_policy_flush_secctx_check(u8 type, struct xfrm_audit *audit_info)
754 int i; 729 int i;
755 730
756 hlist_for_each_entry(pol, entry, 731 hlist_for_each_entry(pol, entry,
757 &xfrm_policy_inexact[dir], bydst) { 732 &net->xfrm.policy_inexact[dir], bydst) {
758 if (pol->type != type) 733 if (pol->type != type)
759 continue; 734 continue;
760 err = security_xfrm_policy_delete(pol->security); 735 err = security_xfrm_policy_delete(pol->security);
@@ -766,9 +741,9 @@ xfrm_policy_flush_secctx_check(u8 type, struct xfrm_audit *audit_info)
766 return err; 741 return err;
767 } 742 }
768 } 743 }
769 for (i = xfrm_policy_bydst[dir].hmask; i >= 0; i--) { 744 for (i = net->xfrm.policy_bydst[dir].hmask; i >= 0; i--) {
770 hlist_for_each_entry(pol, entry, 745 hlist_for_each_entry(pol, entry,
771 xfrm_policy_bydst[dir].table + i, 746 net->xfrm.policy_bydst[dir].table + i,
772 bydst) { 747 bydst) {
773 if (pol->type != type) 748 if (pol->type != type)
774 continue; 749 continue;
@@ -788,36 +763,33 @@ xfrm_policy_flush_secctx_check(u8 type, struct xfrm_audit *audit_info)
788} 763}
789#else 764#else
790static inline int 765static inline int
791xfrm_policy_flush_secctx_check(u8 type, struct xfrm_audit *audit_info) 766xfrm_policy_flush_secctx_check(struct net *net, u8 type, struct xfrm_audit *audit_info)
792{ 767{
793 return 0; 768 return 0;
794} 769}
795#endif 770#endif
796 771
797int xfrm_policy_flush(u8 type, struct xfrm_audit *audit_info) 772int xfrm_policy_flush(struct net *net, u8 type, struct xfrm_audit *audit_info)
798{ 773{
799 int dir, err = 0; 774 int dir, err = 0;
800 775
801 write_lock_bh(&xfrm_policy_lock); 776 write_lock_bh(&xfrm_policy_lock);
802 777
803 err = xfrm_policy_flush_secctx_check(type, audit_info); 778 err = xfrm_policy_flush_secctx_check(net, type, audit_info);
804 if (err) 779 if (err)
805 goto out; 780 goto out;
806 781
807 for (dir = 0; dir < XFRM_POLICY_MAX; dir++) { 782 for (dir = 0; dir < XFRM_POLICY_MAX; dir++) {
808 struct xfrm_policy *pol; 783 struct xfrm_policy *pol;
809 struct hlist_node *entry; 784 struct hlist_node *entry;
810 int i, killed; 785 int i;
811 786
812 killed = 0;
813 again1: 787 again1:
814 hlist_for_each_entry(pol, entry, 788 hlist_for_each_entry(pol, entry,
815 &xfrm_policy_inexact[dir], bydst) { 789 &net->xfrm.policy_inexact[dir], bydst) {
816 if (pol->type != type) 790 if (pol->type != type)
817 continue; 791 continue;
818 hlist_del(&pol->bydst); 792 __xfrm_policy_unlink(pol, dir);
819 hlist_del(&pol->byidx);
820 list_del(&pol->walk.all);
821 write_unlock_bh(&xfrm_policy_lock); 793 write_unlock_bh(&xfrm_policy_lock);
822 794
823 xfrm_audit_policy_delete(pol, 1, audit_info->loginuid, 795 xfrm_audit_policy_delete(pol, 1, audit_info->loginuid,
@@ -825,22 +797,19 @@ int xfrm_policy_flush(u8 type, struct xfrm_audit *audit_info)
825 audit_info->secid); 797 audit_info->secid);
826 798
827 xfrm_policy_kill(pol); 799 xfrm_policy_kill(pol);
828 killed++;
829 800
830 write_lock_bh(&xfrm_policy_lock); 801 write_lock_bh(&xfrm_policy_lock);
831 goto again1; 802 goto again1;
832 } 803 }
833 804
834 for (i = xfrm_policy_bydst[dir].hmask; i >= 0; i--) { 805 for (i = net->xfrm.policy_bydst[dir].hmask; i >= 0; i--) {
835 again2: 806 again2:
836 hlist_for_each_entry(pol, entry, 807 hlist_for_each_entry(pol, entry,
837 xfrm_policy_bydst[dir].table + i, 808 net->xfrm.policy_bydst[dir].table + i,
838 bydst) { 809 bydst) {
839 if (pol->type != type) 810 if (pol->type != type)
840 continue; 811 continue;
841 hlist_del(&pol->bydst); 812 __xfrm_policy_unlink(pol, dir);
842 hlist_del(&pol->byidx);
843 list_del(&pol->walk.all);
844 write_unlock_bh(&xfrm_policy_lock); 813 write_unlock_bh(&xfrm_policy_lock);
845 814
846 xfrm_audit_policy_delete(pol, 1, 815 xfrm_audit_policy_delete(pol, 1,
@@ -848,14 +817,12 @@ int xfrm_policy_flush(u8 type, struct xfrm_audit *audit_info)
848 audit_info->sessionid, 817 audit_info->sessionid,
849 audit_info->secid); 818 audit_info->secid);
850 xfrm_policy_kill(pol); 819 xfrm_policy_kill(pol);
851 killed++;
852 820
853 write_lock_bh(&xfrm_policy_lock); 821 write_lock_bh(&xfrm_policy_lock);
854 goto again2; 822 goto again2;
855 } 823 }
856 } 824 }
857 825
858 xfrm_policy_count[dir] -= killed;
859 } 826 }
860 atomic_inc(&flow_cache_genid); 827 atomic_inc(&flow_cache_genid);
861out: 828out:
@@ -864,7 +831,7 @@ out:
864} 831}
865EXPORT_SYMBOL(xfrm_policy_flush); 832EXPORT_SYMBOL(xfrm_policy_flush);
866 833
867int xfrm_policy_walk(struct xfrm_policy_walk *walk, 834int xfrm_policy_walk(struct net *net, struct xfrm_policy_walk *walk,
868 int (*func)(struct xfrm_policy *, int, int, void*), 835 int (*func)(struct xfrm_policy *, int, int, void*),
869 void *data) 836 void *data)
870{ 837{
@@ -881,10 +848,10 @@ int xfrm_policy_walk(struct xfrm_policy_walk *walk,
881 848
882 write_lock_bh(&xfrm_policy_lock); 849 write_lock_bh(&xfrm_policy_lock);
883 if (list_empty(&walk->walk.all)) 850 if (list_empty(&walk->walk.all))
884 x = list_first_entry(&xfrm_policy_all, struct xfrm_policy_walk_entry, all); 851 x = list_first_entry(&net->xfrm.policy_all, struct xfrm_policy_walk_entry, all);
885 else 852 else
886 x = list_entry(&walk->walk.all, struct xfrm_policy_walk_entry, all); 853 x = list_entry(&walk->walk.all, struct xfrm_policy_walk_entry, all);
887 list_for_each_entry_from(x, &xfrm_policy_all, all) { 854 list_for_each_entry_from(x, &net->xfrm.policy_all, all) {
888 if (x->dead) 855 if (x->dead)
889 continue; 856 continue;
890 pol = container_of(x, struct xfrm_policy, walk); 857 pol = container_of(x, struct xfrm_policy, walk);
@@ -953,7 +920,8 @@ static int xfrm_policy_match(struct xfrm_policy *pol, struct flowi *fl,
953 return ret; 920 return ret;
954} 921}
955 922
956static struct xfrm_policy *xfrm_policy_lookup_bytype(u8 type, struct flowi *fl, 923static struct xfrm_policy *xfrm_policy_lookup_bytype(struct net *net, u8 type,
924 struct flowi *fl,
957 u16 family, u8 dir) 925 u16 family, u8 dir)
958{ 926{
959 int err; 927 int err;
@@ -969,7 +937,7 @@ static struct xfrm_policy *xfrm_policy_lookup_bytype(u8 type, struct flowi *fl,
969 return NULL; 937 return NULL;
970 938
971 read_lock_bh(&xfrm_policy_lock); 939 read_lock_bh(&xfrm_policy_lock);
972 chain = policy_hash_direct(daddr, saddr, family, dir); 940 chain = policy_hash_direct(net, daddr, saddr, family, dir);
973 ret = NULL; 941 ret = NULL;
974 hlist_for_each_entry(pol, entry, chain, bydst) { 942 hlist_for_each_entry(pol, entry, chain, bydst) {
975 err = xfrm_policy_match(pol, fl, type, family, dir); 943 err = xfrm_policy_match(pol, fl, type, family, dir);
@@ -986,7 +954,7 @@ static struct xfrm_policy *xfrm_policy_lookup_bytype(u8 type, struct flowi *fl,
986 break; 954 break;
987 } 955 }
988 } 956 }
989 chain = &xfrm_policy_inexact[dir]; 957 chain = &net->xfrm.policy_inexact[dir];
990 hlist_for_each_entry(pol, entry, chain, bydst) { 958 hlist_for_each_entry(pol, entry, chain, bydst) {
991 err = xfrm_policy_match(pol, fl, type, family, dir); 959 err = xfrm_policy_match(pol, fl, type, family, dir);
992 if (err) { 960 if (err) {
@@ -1009,14 +977,14 @@ fail:
1009 return ret; 977 return ret;
1010} 978}
1011 979
1012static int xfrm_policy_lookup(struct flowi *fl, u16 family, u8 dir, 980static int xfrm_policy_lookup(struct net *net, struct flowi *fl, u16 family,
1013 void **objp, atomic_t **obj_refp) 981 u8 dir, void **objp, atomic_t **obj_refp)
1014{ 982{
1015 struct xfrm_policy *pol; 983 struct xfrm_policy *pol;
1016 int err = 0; 984 int err = 0;
1017 985
1018#ifdef CONFIG_XFRM_SUB_POLICY 986#ifdef CONFIG_XFRM_SUB_POLICY
1019 pol = xfrm_policy_lookup_bytype(XFRM_POLICY_TYPE_SUB, fl, family, dir); 987 pol = xfrm_policy_lookup_bytype(net, XFRM_POLICY_TYPE_SUB, fl, family, dir);
1020 if (IS_ERR(pol)) { 988 if (IS_ERR(pol)) {
1021 err = PTR_ERR(pol); 989 err = PTR_ERR(pol);
1022 pol = NULL; 990 pol = NULL;
@@ -1024,7 +992,7 @@ static int xfrm_policy_lookup(struct flowi *fl, u16 family, u8 dir,
1024 if (pol || err) 992 if (pol || err)
1025 goto end; 993 goto end;
1026#endif 994#endif
1027 pol = xfrm_policy_lookup_bytype(XFRM_POLICY_TYPE_MAIN, fl, family, dir); 995 pol = xfrm_policy_lookup_bytype(net, XFRM_POLICY_TYPE_MAIN, fl, family, dir);
1028 if (IS_ERR(pol)) { 996 if (IS_ERR(pol)) {
1029 err = PTR_ERR(pol); 997 err = PTR_ERR(pol);
1030 pol = NULL; 998 pol = NULL;
@@ -1083,29 +1051,32 @@ static struct xfrm_policy *xfrm_sk_policy_lookup(struct sock *sk, int dir, struc
1083 1051
1084static void __xfrm_policy_link(struct xfrm_policy *pol, int dir) 1052static void __xfrm_policy_link(struct xfrm_policy *pol, int dir)
1085{ 1053{
1086 struct hlist_head *chain = policy_hash_bysel(&pol->selector, 1054 struct net *net = xp_net(pol);
1055 struct hlist_head *chain = policy_hash_bysel(net, &pol->selector,
1087 pol->family, dir); 1056 pol->family, dir);
1088 1057
1089 list_add(&pol->walk.all, &xfrm_policy_all); 1058 list_add(&pol->walk.all, &net->xfrm.policy_all);
1090 hlist_add_head(&pol->bydst, chain); 1059 hlist_add_head(&pol->bydst, chain);
1091 hlist_add_head(&pol->byidx, xfrm_policy_byidx+idx_hash(pol->index)); 1060 hlist_add_head(&pol->byidx, net->xfrm.policy_byidx+idx_hash(net, pol->index));
1092 xfrm_policy_count[dir]++; 1061 net->xfrm.policy_count[dir]++;
1093 xfrm_pol_hold(pol); 1062 xfrm_pol_hold(pol);
1094 1063
1095 if (xfrm_bydst_should_resize(dir, NULL)) 1064 if (xfrm_bydst_should_resize(net, dir, NULL))
1096 schedule_work(&xfrm_hash_work); 1065 schedule_work(&net->xfrm.policy_hash_work);
1097} 1066}
1098 1067
1099static struct xfrm_policy *__xfrm_policy_unlink(struct xfrm_policy *pol, 1068static struct xfrm_policy *__xfrm_policy_unlink(struct xfrm_policy *pol,
1100 int dir) 1069 int dir)
1101{ 1070{
1071 struct net *net = xp_net(pol);
1072
1102 if (hlist_unhashed(&pol->bydst)) 1073 if (hlist_unhashed(&pol->bydst))
1103 return NULL; 1074 return NULL;
1104 1075
1105 hlist_del(&pol->bydst); 1076 hlist_del(&pol->bydst);
1106 hlist_del(&pol->byidx); 1077 hlist_del(&pol->byidx);
1107 list_del(&pol->walk.all); 1078 list_del(&pol->walk.all);
1108 xfrm_policy_count[dir]--; 1079 net->xfrm.policy_count[dir]--;
1109 1080
1110 return pol; 1081 return pol;
1111} 1082}
@@ -1127,6 +1098,7 @@ EXPORT_SYMBOL(xfrm_policy_delete);
1127 1098
1128int xfrm_sk_policy_insert(struct sock *sk, int dir, struct xfrm_policy *pol) 1099int xfrm_sk_policy_insert(struct sock *sk, int dir, struct xfrm_policy *pol)
1129{ 1100{
1101 struct net *net = xp_net(pol);
1130 struct xfrm_policy *old_pol; 1102 struct xfrm_policy *old_pol;
1131 1103
1132#ifdef CONFIG_XFRM_SUB_POLICY 1104#ifdef CONFIG_XFRM_SUB_POLICY
@@ -1139,7 +1111,7 @@ int xfrm_sk_policy_insert(struct sock *sk, int dir, struct xfrm_policy *pol)
1139 sk->sk_policy[dir] = pol; 1111 sk->sk_policy[dir] = pol;
1140 if (pol) { 1112 if (pol) {
1141 pol->curlft.add_time = get_seconds(); 1113 pol->curlft.add_time = get_seconds();
1142 pol->index = xfrm_gen_index(pol->type, XFRM_POLICY_MAX+dir); 1114 pol->index = xfrm_gen_index(net, XFRM_POLICY_MAX+dir);
1143 __xfrm_policy_link(pol, XFRM_POLICY_MAX+dir); 1115 __xfrm_policy_link(pol, XFRM_POLICY_MAX+dir);
1144 } 1116 }
1145 if (old_pol) 1117 if (old_pol)
@@ -1154,7 +1126,7 @@ int xfrm_sk_policy_insert(struct sock *sk, int dir, struct xfrm_policy *pol)
1154 1126
1155static struct xfrm_policy *clone_policy(struct xfrm_policy *old, int dir) 1127static struct xfrm_policy *clone_policy(struct xfrm_policy *old, int dir)
1156{ 1128{
1157 struct xfrm_policy *newp = xfrm_policy_alloc(GFP_ATOMIC); 1129 struct xfrm_policy *newp = xfrm_policy_alloc(xp_net(old), GFP_ATOMIC);
1158 1130
1159 if (newp) { 1131 if (newp) {
1160 newp->selector = old->selector; 1132 newp->selector = old->selector;
@@ -1194,7 +1166,7 @@ int __xfrm_sk_clone_policy(struct sock *sk)
1194} 1166}
1195 1167
1196static int 1168static int
1197xfrm_get_saddr(xfrm_address_t *local, xfrm_address_t *remote, 1169xfrm_get_saddr(struct net *net, xfrm_address_t *local, xfrm_address_t *remote,
1198 unsigned short family) 1170 unsigned short family)
1199{ 1171{
1200 int err; 1172 int err;
@@ -1202,7 +1174,7 @@ xfrm_get_saddr(xfrm_address_t *local, xfrm_address_t *remote,
1202 1174
1203 if (unlikely(afinfo == NULL)) 1175 if (unlikely(afinfo == NULL))
1204 return -EINVAL; 1176 return -EINVAL;
1205 err = afinfo->get_saddr(local, remote); 1177 err = afinfo->get_saddr(net, local, remote);
1206 xfrm_policy_put_afinfo(afinfo); 1178 xfrm_policy_put_afinfo(afinfo);
1207 return err; 1179 return err;
1208} 1180}
@@ -1214,6 +1186,7 @@ xfrm_tmpl_resolve_one(struct xfrm_policy *policy, struct flowi *fl,
1214 struct xfrm_state **xfrm, 1186 struct xfrm_state **xfrm,
1215 unsigned short family) 1187 unsigned short family)
1216{ 1188{
1189 struct net *net = xp_net(policy);
1217 int nx; 1190 int nx;
1218 int i, error; 1191 int i, error;
1219 xfrm_address_t *daddr = xfrm_flowi_daddr(fl, family); 1192 xfrm_address_t *daddr = xfrm_flowi_daddr(fl, family);
@@ -1232,7 +1205,7 @@ xfrm_tmpl_resolve_one(struct xfrm_policy *policy, struct flowi *fl,
1232 local = &tmpl->saddr; 1205 local = &tmpl->saddr;
1233 family = tmpl->encap_family; 1206 family = tmpl->encap_family;
1234 if (xfrm_addr_any(local, family)) { 1207 if (xfrm_addr_any(local, family)) {
1235 error = xfrm_get_saddr(&tmp, remote, family); 1208 error = xfrm_get_saddr(net, &tmp, remote, family);
1236 if (error) 1209 if (error)
1237 goto fail; 1210 goto fail;
1238 local = &tmp; 1211 local = &tmp;
@@ -1546,7 +1519,7 @@ static int stale_bundle(struct dst_entry *dst);
1546 * At the moment we eat a raw IP route. Mostly to speed up lookups 1519 * At the moment we eat a raw IP route. Mostly to speed up lookups
1547 * on interfaces with disabled IPsec. 1520 * on interfaces with disabled IPsec.
1548 */ 1521 */
1549int __xfrm_lookup(struct dst_entry **dst_p, struct flowi *fl, 1522int __xfrm_lookup(struct net *net, struct dst_entry **dst_p, struct flowi *fl,
1550 struct sock *sk, int flags) 1523 struct sock *sk, int flags)
1551{ 1524{
1552 struct xfrm_policy *policy; 1525 struct xfrm_policy *policy;
@@ -1576,7 +1549,7 @@ restart:
1576 policy = xfrm_sk_policy_lookup(sk, XFRM_POLICY_OUT, fl); 1549 policy = xfrm_sk_policy_lookup(sk, XFRM_POLICY_OUT, fl);
1577 err = PTR_ERR(policy); 1550 err = PTR_ERR(policy);
1578 if (IS_ERR(policy)) { 1551 if (IS_ERR(policy)) {
1579 XFRM_INC_STATS(LINUX_MIB_XFRMOUTPOLERROR); 1552 XFRM_INC_STATS(net, LINUX_MIB_XFRMOUTPOLERROR);
1580 goto dropdst; 1553 goto dropdst;
1581 } 1554 }
1582 } 1555 }
@@ -1584,14 +1557,14 @@ restart:
1584 if (!policy) { 1557 if (!policy) {
1585 /* To accelerate a bit... */ 1558 /* To accelerate a bit... */
1586 if ((dst_orig->flags & DST_NOXFRM) || 1559 if ((dst_orig->flags & DST_NOXFRM) ||
1587 !xfrm_policy_count[XFRM_POLICY_OUT]) 1560 !net->xfrm.policy_count[XFRM_POLICY_OUT])
1588 goto nopol; 1561 goto nopol;
1589 1562
1590 policy = flow_cache_lookup(fl, dst_orig->ops->family, 1563 policy = flow_cache_lookup(net, fl, dst_orig->ops->family,
1591 dir, xfrm_policy_lookup); 1564 dir, xfrm_policy_lookup);
1592 err = PTR_ERR(policy); 1565 err = PTR_ERR(policy);
1593 if (IS_ERR(policy)) { 1566 if (IS_ERR(policy)) {
1594 XFRM_INC_STATS(LINUX_MIB_XFRMOUTPOLERROR); 1567 XFRM_INC_STATS(net, LINUX_MIB_XFRMOUTPOLERROR);
1595 goto dropdst; 1568 goto dropdst;
1596 } 1569 }
1597 } 1570 }
@@ -1614,7 +1587,7 @@ restart:
1614 default: 1587 default:
1615 case XFRM_POLICY_BLOCK: 1588 case XFRM_POLICY_BLOCK:
1616 /* Prohibit the flow */ 1589 /* Prohibit the flow */
1617 XFRM_INC_STATS(LINUX_MIB_XFRMOUTPOLBLOCK); 1590 XFRM_INC_STATS(net, LINUX_MIB_XFRMOUTPOLBLOCK);
1618 err = -EPERM; 1591 err = -EPERM;
1619 goto error; 1592 goto error;
1620 1593
@@ -1634,7 +1607,7 @@ restart:
1634 */ 1607 */
1635 dst = xfrm_find_bundle(fl, policy, family); 1608 dst = xfrm_find_bundle(fl, policy, family);
1636 if (IS_ERR(dst)) { 1609 if (IS_ERR(dst)) {
1637 XFRM_INC_STATS(LINUX_MIB_XFRMOUTBUNDLECHECKERROR); 1610 XFRM_INC_STATS(net, LINUX_MIB_XFRMOUTBUNDLECHECKERROR);
1638 err = PTR_ERR(dst); 1611 err = PTR_ERR(dst);
1639 goto error; 1612 goto error;
1640 } 1613 }
@@ -1644,17 +1617,18 @@ restart:
1644 1617
1645#ifdef CONFIG_XFRM_SUB_POLICY 1618#ifdef CONFIG_XFRM_SUB_POLICY
1646 if (pols[0]->type != XFRM_POLICY_TYPE_MAIN) { 1619 if (pols[0]->type != XFRM_POLICY_TYPE_MAIN) {
1647 pols[1] = xfrm_policy_lookup_bytype(XFRM_POLICY_TYPE_MAIN, 1620 pols[1] = xfrm_policy_lookup_bytype(net,
1621 XFRM_POLICY_TYPE_MAIN,
1648 fl, family, 1622 fl, family,
1649 XFRM_POLICY_OUT); 1623 XFRM_POLICY_OUT);
1650 if (pols[1]) { 1624 if (pols[1]) {
1651 if (IS_ERR(pols[1])) { 1625 if (IS_ERR(pols[1])) {
1652 XFRM_INC_STATS(LINUX_MIB_XFRMOUTPOLERROR); 1626 XFRM_INC_STATS(net, LINUX_MIB_XFRMOUTPOLERROR);
1653 err = PTR_ERR(pols[1]); 1627 err = PTR_ERR(pols[1]);
1654 goto error; 1628 goto error;
1655 } 1629 }
1656 if (pols[1]->action == XFRM_POLICY_BLOCK) { 1630 if (pols[1]->action == XFRM_POLICY_BLOCK) {
1657 XFRM_INC_STATS(LINUX_MIB_XFRMOUTPOLBLOCK); 1631 XFRM_INC_STATS(net, LINUX_MIB_XFRMOUTPOLBLOCK);
1658 err = -EPERM; 1632 err = -EPERM;
1659 goto error; 1633 goto error;
1660 } 1634 }
@@ -1681,27 +1655,27 @@ restart:
1681 1655
1682 if (unlikely(nx<0)) { 1656 if (unlikely(nx<0)) {
1683 err = nx; 1657 err = nx;
1684 if (err == -EAGAIN && sysctl_xfrm_larval_drop) { 1658 if (err == -EAGAIN && net->xfrm.sysctl_larval_drop) {
1685 /* EREMOTE tells the caller to generate 1659 /* EREMOTE tells the caller to generate
1686 * a one-shot blackhole route. 1660 * a one-shot blackhole route.
1687 */ 1661 */
1688 XFRM_INC_STATS(LINUX_MIB_XFRMOUTNOSTATES); 1662 XFRM_INC_STATS(net, LINUX_MIB_XFRMOUTNOSTATES);
1689 xfrm_pol_put(policy); 1663 xfrm_pol_put(policy);
1690 return -EREMOTE; 1664 return -EREMOTE;
1691 } 1665 }
1692 if (err == -EAGAIN && (flags & XFRM_LOOKUP_WAIT)) { 1666 if (err == -EAGAIN && (flags & XFRM_LOOKUP_WAIT)) {
1693 DECLARE_WAITQUEUE(wait, current); 1667 DECLARE_WAITQUEUE(wait, current);
1694 1668
1695 add_wait_queue(&km_waitq, &wait); 1669 add_wait_queue(&net->xfrm.km_waitq, &wait);
1696 set_current_state(TASK_INTERRUPTIBLE); 1670 set_current_state(TASK_INTERRUPTIBLE);
1697 schedule(); 1671 schedule();
1698 set_current_state(TASK_RUNNING); 1672 set_current_state(TASK_RUNNING);
1699 remove_wait_queue(&km_waitq, &wait); 1673 remove_wait_queue(&net->xfrm.km_waitq, &wait);
1700 1674
1701 nx = xfrm_tmpl_resolve(pols, npols, fl, xfrm, family); 1675 nx = xfrm_tmpl_resolve(pols, npols, fl, xfrm, family);
1702 1676
1703 if (nx == -EAGAIN && signal_pending(current)) { 1677 if (nx == -EAGAIN && signal_pending(current)) {
1704 XFRM_INC_STATS(LINUX_MIB_XFRMOUTNOSTATES); 1678 XFRM_INC_STATS(net, LINUX_MIB_XFRMOUTNOSTATES);
1705 err = -ERESTART; 1679 err = -ERESTART;
1706 goto error; 1680 goto error;
1707 } 1681 }
@@ -1713,7 +1687,7 @@ restart:
1713 err = nx; 1687 err = nx;
1714 } 1688 }
1715 if (err < 0) { 1689 if (err < 0) {
1716 XFRM_INC_STATS(LINUX_MIB_XFRMOUTNOSTATES); 1690 XFRM_INC_STATS(net, LINUX_MIB_XFRMOUTNOSTATES);
1717 goto error; 1691 goto error;
1718 } 1692 }
1719 } 1693 }
@@ -1726,7 +1700,7 @@ restart:
1726 dst = xfrm_bundle_create(policy, xfrm, nx, fl, dst_orig); 1700 dst = xfrm_bundle_create(policy, xfrm, nx, fl, dst_orig);
1727 err = PTR_ERR(dst); 1701 err = PTR_ERR(dst);
1728 if (IS_ERR(dst)) { 1702 if (IS_ERR(dst)) {
1729 XFRM_INC_STATS(LINUX_MIB_XFRMOUTBUNDLEGENERROR); 1703 XFRM_INC_STATS(net, LINUX_MIB_XFRMOUTBUNDLEGENERROR);
1730 goto error; 1704 goto error;
1731 } 1705 }
1732 1706
@@ -1747,9 +1721,9 @@ restart:
1747 dst_free(dst); 1721 dst_free(dst);
1748 1722
1749 if (pol_dead) 1723 if (pol_dead)
1750 XFRM_INC_STATS(LINUX_MIB_XFRMOUTPOLDEAD); 1724 XFRM_INC_STATS(net, LINUX_MIB_XFRMOUTPOLDEAD);
1751 else 1725 else
1752 XFRM_INC_STATS(LINUX_MIB_XFRMOUTBUNDLECHECKERROR); 1726 XFRM_INC_STATS(net, LINUX_MIB_XFRMOUTBUNDLECHECKERROR);
1753 err = -EHOSTUNREACH; 1727 err = -EHOSTUNREACH;
1754 goto error; 1728 goto error;
1755 } 1729 }
@@ -1761,7 +1735,7 @@ restart:
1761 if (unlikely(err)) { 1735 if (unlikely(err)) {
1762 write_unlock_bh(&policy->lock); 1736 write_unlock_bh(&policy->lock);
1763 dst_free(dst); 1737 dst_free(dst);
1764 XFRM_INC_STATS(LINUX_MIB_XFRMOUTBUNDLECHECKERROR); 1738 XFRM_INC_STATS(net, LINUX_MIB_XFRMOUTBUNDLECHECKERROR);
1765 goto error; 1739 goto error;
1766 } 1740 }
1767 1741
@@ -1790,10 +1764,10 @@ nopol:
1790} 1764}
1791EXPORT_SYMBOL(__xfrm_lookup); 1765EXPORT_SYMBOL(__xfrm_lookup);
1792 1766
1793int xfrm_lookup(struct dst_entry **dst_p, struct flowi *fl, 1767int xfrm_lookup(struct net *net, struct dst_entry **dst_p, struct flowi *fl,
1794 struct sock *sk, int flags) 1768 struct sock *sk, int flags)
1795{ 1769{
1796 int err = __xfrm_lookup(dst_p, fl, sk, flags); 1770 int err = __xfrm_lookup(net, dst_p, fl, sk, flags);
1797 1771
1798 if (err == -EREMOTE) { 1772 if (err == -EREMOTE) {
1799 dst_release(*dst_p); 1773 dst_release(*dst_p);
@@ -1901,6 +1875,7 @@ static inline int secpath_has_nontransport(struct sec_path *sp, int k, int *idxp
1901int __xfrm_policy_check(struct sock *sk, int dir, struct sk_buff *skb, 1875int __xfrm_policy_check(struct sock *sk, int dir, struct sk_buff *skb,
1902 unsigned short family) 1876 unsigned short family)
1903{ 1877{
1878 struct net *net = dev_net(skb->dev);
1904 struct xfrm_policy *pol; 1879 struct xfrm_policy *pol;
1905 struct xfrm_policy *pols[XFRM_POLICY_TYPE_MAX]; 1880 struct xfrm_policy *pols[XFRM_POLICY_TYPE_MAX];
1906 int npols = 0; 1881 int npols = 0;
@@ -1916,7 +1891,7 @@ int __xfrm_policy_check(struct sock *sk, int dir, struct sk_buff *skb,
1916 fl_dir = policy_to_flow_dir(dir); 1891 fl_dir = policy_to_flow_dir(dir);
1917 1892
1918 if (__xfrm_decode_session(skb, &fl, family, reverse) < 0) { 1893 if (__xfrm_decode_session(skb, &fl, family, reverse) < 0) {
1919 XFRM_INC_STATS(LINUX_MIB_XFRMINHDRERROR); 1894 XFRM_INC_STATS(net, LINUX_MIB_XFRMINHDRERROR);
1920 return 0; 1895 return 0;
1921 } 1896 }
1922 1897
@@ -1929,7 +1904,7 @@ int __xfrm_policy_check(struct sock *sk, int dir, struct sk_buff *skb,
1929 for (i=skb->sp->len-1; i>=0; i--) { 1904 for (i=skb->sp->len-1; i>=0; i--) {
1930 struct xfrm_state *x = skb->sp->xvec[i]; 1905 struct xfrm_state *x = skb->sp->xvec[i];
1931 if (!xfrm_selector_match(&x->sel, &fl, family)) { 1906 if (!xfrm_selector_match(&x->sel, &fl, family)) {
1932 XFRM_INC_STATS(LINUX_MIB_XFRMINSTATEMISMATCH); 1907 XFRM_INC_STATS(net, LINUX_MIB_XFRMINSTATEMISMATCH);
1933 return 0; 1908 return 0;
1934 } 1909 }
1935 } 1910 }
@@ -1939,24 +1914,24 @@ int __xfrm_policy_check(struct sock *sk, int dir, struct sk_buff *skb,
1939 if (sk && sk->sk_policy[dir]) { 1914 if (sk && sk->sk_policy[dir]) {
1940 pol = xfrm_sk_policy_lookup(sk, dir, &fl); 1915 pol = xfrm_sk_policy_lookup(sk, dir, &fl);
1941 if (IS_ERR(pol)) { 1916 if (IS_ERR(pol)) {
1942 XFRM_INC_STATS(LINUX_MIB_XFRMINPOLERROR); 1917 XFRM_INC_STATS(net, LINUX_MIB_XFRMINPOLERROR);
1943 return 0; 1918 return 0;
1944 } 1919 }
1945 } 1920 }
1946 1921
1947 if (!pol) 1922 if (!pol)
1948 pol = flow_cache_lookup(&fl, family, fl_dir, 1923 pol = flow_cache_lookup(net, &fl, family, fl_dir,
1949 xfrm_policy_lookup); 1924 xfrm_policy_lookup);
1950 1925
1951 if (IS_ERR(pol)) { 1926 if (IS_ERR(pol)) {
1952 XFRM_INC_STATS(LINUX_MIB_XFRMINPOLERROR); 1927 XFRM_INC_STATS(net, LINUX_MIB_XFRMINPOLERROR);
1953 return 0; 1928 return 0;
1954 } 1929 }
1955 1930
1956 if (!pol) { 1931 if (!pol) {
1957 if (skb->sp && secpath_has_nontransport(skb->sp, 0, &xerr_idx)) { 1932 if (skb->sp && secpath_has_nontransport(skb->sp, 0, &xerr_idx)) {
1958 xfrm_secpath_reject(xerr_idx, skb, &fl); 1933 xfrm_secpath_reject(xerr_idx, skb, &fl);
1959 XFRM_INC_STATS(LINUX_MIB_XFRMINNOPOLS); 1934 XFRM_INC_STATS(net, LINUX_MIB_XFRMINNOPOLS);
1960 return 0; 1935 return 0;
1961 } 1936 }
1962 return 1; 1937 return 1;
@@ -1968,12 +1943,12 @@ int __xfrm_policy_check(struct sock *sk, int dir, struct sk_buff *skb,
1968 npols ++; 1943 npols ++;
1969#ifdef CONFIG_XFRM_SUB_POLICY 1944#ifdef CONFIG_XFRM_SUB_POLICY
1970 if (pols[0]->type != XFRM_POLICY_TYPE_MAIN) { 1945 if (pols[0]->type != XFRM_POLICY_TYPE_MAIN) {
1971 pols[1] = xfrm_policy_lookup_bytype(XFRM_POLICY_TYPE_MAIN, 1946 pols[1] = xfrm_policy_lookup_bytype(net, XFRM_POLICY_TYPE_MAIN,
1972 &fl, family, 1947 &fl, family,
1973 XFRM_POLICY_IN); 1948 XFRM_POLICY_IN);
1974 if (pols[1]) { 1949 if (pols[1]) {
1975 if (IS_ERR(pols[1])) { 1950 if (IS_ERR(pols[1])) {
1976 XFRM_INC_STATS(LINUX_MIB_XFRMINPOLERROR); 1951 XFRM_INC_STATS(net, LINUX_MIB_XFRMINPOLERROR);
1977 return 0; 1952 return 0;
1978 } 1953 }
1979 pols[1]->curlft.use_time = get_seconds(); 1954 pols[1]->curlft.use_time = get_seconds();
@@ -1997,11 +1972,11 @@ int __xfrm_policy_check(struct sock *sk, int dir, struct sk_buff *skb,
1997 for (pi = 0; pi < npols; pi++) { 1972 for (pi = 0; pi < npols; pi++) {
1998 if (pols[pi] != pol && 1973 if (pols[pi] != pol &&
1999 pols[pi]->action != XFRM_POLICY_ALLOW) { 1974 pols[pi]->action != XFRM_POLICY_ALLOW) {
2000 XFRM_INC_STATS(LINUX_MIB_XFRMINPOLBLOCK); 1975 XFRM_INC_STATS(net, LINUX_MIB_XFRMINPOLBLOCK);
2001 goto reject; 1976 goto reject;
2002 } 1977 }
2003 if (ti + pols[pi]->xfrm_nr >= XFRM_MAX_DEPTH) { 1978 if (ti + pols[pi]->xfrm_nr >= XFRM_MAX_DEPTH) {
2004 XFRM_INC_STATS(LINUX_MIB_XFRMINBUFFERERROR); 1979 XFRM_INC_STATS(net, LINUX_MIB_XFRMINBUFFERERROR);
2005 goto reject_error; 1980 goto reject_error;
2006 } 1981 }
2007 for (i = 0; i < pols[pi]->xfrm_nr; i++) 1982 for (i = 0; i < pols[pi]->xfrm_nr; i++)
@@ -2025,20 +2000,20 @@ int __xfrm_policy_check(struct sock *sk, int dir, struct sk_buff *skb,
2025 if (k < -1) 2000 if (k < -1)
2026 /* "-2 - errored_index" returned */ 2001 /* "-2 - errored_index" returned */
2027 xerr_idx = -(2+k); 2002 xerr_idx = -(2+k);
2028 XFRM_INC_STATS(LINUX_MIB_XFRMINTMPLMISMATCH); 2003 XFRM_INC_STATS(net, LINUX_MIB_XFRMINTMPLMISMATCH);
2029 goto reject; 2004 goto reject;
2030 } 2005 }
2031 } 2006 }
2032 2007
2033 if (secpath_has_nontransport(sp, k, &xerr_idx)) { 2008 if (secpath_has_nontransport(sp, k, &xerr_idx)) {
2034 XFRM_INC_STATS(LINUX_MIB_XFRMINTMPLMISMATCH); 2009 XFRM_INC_STATS(net, LINUX_MIB_XFRMINTMPLMISMATCH);
2035 goto reject; 2010 goto reject;
2036 } 2011 }
2037 2012
2038 xfrm_pols_put(pols, npols); 2013 xfrm_pols_put(pols, npols);
2039 return 1; 2014 return 1;
2040 } 2015 }
2041 XFRM_INC_STATS(LINUX_MIB_XFRMINPOLBLOCK); 2016 XFRM_INC_STATS(net, LINUX_MIB_XFRMINPOLBLOCK);
2042 2017
2043reject: 2018reject:
2044 xfrm_secpath_reject(xerr_idx, skb, &fl); 2019 xfrm_secpath_reject(xerr_idx, skb, &fl);
@@ -2050,15 +2025,16 @@ EXPORT_SYMBOL(__xfrm_policy_check);
2050 2025
2051int __xfrm_route_forward(struct sk_buff *skb, unsigned short family) 2026int __xfrm_route_forward(struct sk_buff *skb, unsigned short family)
2052{ 2027{
2028 struct net *net = dev_net(skb->dev);
2053 struct flowi fl; 2029 struct flowi fl;
2054 2030
2055 if (xfrm_decode_session(skb, &fl, family) < 0) { 2031 if (xfrm_decode_session(skb, &fl, family) < 0) {
2056 /* XXX: we should have something like FWDHDRERROR here. */ 2032 /* XXX: we should have something like FWDHDRERROR here. */
2057 XFRM_INC_STATS(LINUX_MIB_XFRMINHDRERROR); 2033 XFRM_INC_STATS(net, LINUX_MIB_XFRMINHDRERROR);
2058 return 0; 2034 return 0;
2059 } 2035 }
2060 2036
2061 return xfrm_lookup(&skb->dst, &fl, NULL, 0) == 0; 2037 return xfrm_lookup(net, &skb->dst, &fl, NULL, 0) == 0;
2062} 2038}
2063EXPORT_SYMBOL(__xfrm_route_forward); 2039EXPORT_SYMBOL(__xfrm_route_forward);
2064 2040
@@ -2142,7 +2118,7 @@ static void prune_one_bundle(struct xfrm_policy *pol, int (*func)(struct dst_ent
2142 write_unlock(&pol->lock); 2118 write_unlock(&pol->lock);
2143} 2119}
2144 2120
2145static void xfrm_prune_bundles(int (*func)(struct dst_entry *)) 2121static void xfrm_prune_bundles(struct net *net, int (*func)(struct dst_entry *))
2146{ 2122{
2147 struct dst_entry *gc_list = NULL; 2123 struct dst_entry *gc_list = NULL;
2148 int dir; 2124 int dir;
@@ -2155,11 +2131,11 @@ static void xfrm_prune_bundles(int (*func)(struct dst_entry *))
2155 int i; 2131 int i;
2156 2132
2157 hlist_for_each_entry(pol, entry, 2133 hlist_for_each_entry(pol, entry,
2158 &xfrm_policy_inexact[dir], bydst) 2134 &net->xfrm.policy_inexact[dir], bydst)
2159 prune_one_bundle(pol, func, &gc_list); 2135 prune_one_bundle(pol, func, &gc_list);
2160 2136
2161 table = xfrm_policy_bydst[dir].table; 2137 table = net->xfrm.policy_bydst[dir].table;
2162 for (i = xfrm_policy_bydst[dir].hmask; i >= 0; i--) { 2138 for (i = net->xfrm.policy_bydst[dir].hmask; i >= 0; i--) {
2163 hlist_for_each_entry(pol, entry, table + i, bydst) 2139 hlist_for_each_entry(pol, entry, table + i, bydst)
2164 prune_one_bundle(pol, func, &gc_list); 2140 prune_one_bundle(pol, func, &gc_list);
2165 } 2141 }
@@ -2178,14 +2154,14 @@ static int unused_bundle(struct dst_entry *dst)
2178 return !atomic_read(&dst->__refcnt); 2154 return !atomic_read(&dst->__refcnt);
2179} 2155}
2180 2156
2181static void __xfrm_garbage_collect(void) 2157static void __xfrm_garbage_collect(struct net *net)
2182{ 2158{
2183 xfrm_prune_bundles(unused_bundle); 2159 xfrm_prune_bundles(net, unused_bundle);
2184} 2160}
2185 2161
2186static int xfrm_flush_bundles(void) 2162static int xfrm_flush_bundles(struct net *net)
2187{ 2163{
2188 xfrm_prune_bundles(stale_bundle); 2164 xfrm_prune_bundles(net, stale_bundle);
2189 return 0; 2165 return 0;
2190} 2166}
2191 2167
@@ -2371,38 +2347,54 @@ static int xfrm_dev_event(struct notifier_block *this, unsigned long event, void
2371{ 2347{
2372 struct net_device *dev = ptr; 2348 struct net_device *dev = ptr;
2373 2349
2374 if (!net_eq(dev_net(dev), &init_net))
2375 return NOTIFY_DONE;
2376
2377 switch (event) { 2350 switch (event) {
2378 case NETDEV_DOWN: 2351 case NETDEV_DOWN:
2379 xfrm_flush_bundles(); 2352 xfrm_flush_bundles(dev_net(dev));
2380 } 2353 }
2381 return NOTIFY_DONE; 2354 return NOTIFY_DONE;
2382} 2355}
2383 2356
2384static struct notifier_block xfrm_dev_notifier = { 2357static struct notifier_block xfrm_dev_notifier = {
2385 xfrm_dev_event, 2358 .notifier_call = xfrm_dev_event,
2386 NULL,
2387 0
2388}; 2359};
2389 2360
2390#ifdef CONFIG_XFRM_STATISTICS 2361#ifdef CONFIG_XFRM_STATISTICS
2391static int __init xfrm_statistics_init(void) 2362static int __net_init xfrm_statistics_init(struct net *net)
2392{ 2363{
2393 if (snmp_mib_init((void **)xfrm_statistics, 2364 int rv;
2365
2366 if (snmp_mib_init((void **)net->mib.xfrm_statistics,
2394 sizeof(struct linux_xfrm_mib)) < 0) 2367 sizeof(struct linux_xfrm_mib)) < 0)
2395 return -ENOMEM; 2368 return -ENOMEM;
2369 rv = xfrm_proc_init(net);
2370 if (rv < 0)
2371 snmp_mib_free((void **)net->mib.xfrm_statistics);
2372 return rv;
2373}
2374
2375static void xfrm_statistics_fini(struct net *net)
2376{
2377 xfrm_proc_fini(net);
2378 snmp_mib_free((void **)net->mib.xfrm_statistics);
2379}
2380#else
2381static int __net_init xfrm_statistics_init(struct net *net)
2382{
2396 return 0; 2383 return 0;
2397} 2384}
2385
2386static void xfrm_statistics_fini(struct net *net)
2387{
2388}
2398#endif 2389#endif
2399 2390
2400static void __init xfrm_policy_init(void) 2391static int __net_init xfrm_policy_init(struct net *net)
2401{ 2392{
2402 unsigned int hmask, sz; 2393 unsigned int hmask, sz;
2403 int dir; 2394 int dir;
2404 2395
2405 xfrm_dst_cache = kmem_cache_create("xfrm_dst_cache", 2396 if (net_eq(net, &init_net))
2397 xfrm_dst_cache = kmem_cache_create("xfrm_dst_cache",
2406 sizeof(struct xfrm_dst), 2398 sizeof(struct xfrm_dst),
2407 0, SLAB_HWCACHE_ALIGN|SLAB_PANIC, 2399 0, SLAB_HWCACHE_ALIGN|SLAB_PANIC,
2408 NULL); 2400 NULL);
@@ -2410,39 +2402,124 @@ static void __init xfrm_policy_init(void)
2410 hmask = 8 - 1; 2402 hmask = 8 - 1;
2411 sz = (hmask+1) * sizeof(struct hlist_head); 2403 sz = (hmask+1) * sizeof(struct hlist_head);
2412 2404
2413 xfrm_policy_byidx = xfrm_hash_alloc(sz); 2405 net->xfrm.policy_byidx = xfrm_hash_alloc(sz);
2414 xfrm_idx_hmask = hmask; 2406 if (!net->xfrm.policy_byidx)
2415 if (!xfrm_policy_byidx) 2407 goto out_byidx;
2416 panic("XFRM: failed to allocate byidx hash\n"); 2408 net->xfrm.policy_idx_hmask = hmask;
2417 2409
2418 for (dir = 0; dir < XFRM_POLICY_MAX * 2; dir++) { 2410 for (dir = 0; dir < XFRM_POLICY_MAX * 2; dir++) {
2419 struct xfrm_policy_hash *htab; 2411 struct xfrm_policy_hash *htab;
2420 2412
2421 INIT_HLIST_HEAD(&xfrm_policy_inexact[dir]); 2413 net->xfrm.policy_count[dir] = 0;
2414 INIT_HLIST_HEAD(&net->xfrm.policy_inexact[dir]);
2422 2415
2423 htab = &xfrm_policy_bydst[dir]; 2416 htab = &net->xfrm.policy_bydst[dir];
2424 htab->table = xfrm_hash_alloc(sz); 2417 htab->table = xfrm_hash_alloc(sz);
2425 htab->hmask = hmask;
2426 if (!htab->table) 2418 if (!htab->table)
2427 panic("XFRM: failed to allocate bydst hash\n"); 2419 goto out_bydst;
2420 htab->hmask = hmask;
2428 } 2421 }
2429 2422
2430 INIT_LIST_HEAD(&xfrm_policy_all); 2423 INIT_LIST_HEAD(&net->xfrm.policy_all);
2431 INIT_WORK(&xfrm_policy_gc_work, xfrm_policy_gc_task); 2424 INIT_WORK(&net->xfrm.policy_hash_work, xfrm_hash_resize);
2432 register_netdevice_notifier(&xfrm_dev_notifier); 2425 if (net_eq(net, &init_net))
2426 register_netdevice_notifier(&xfrm_dev_notifier);
2427 return 0;
2428
2429out_bydst:
2430 for (dir--; dir >= 0; dir--) {
2431 struct xfrm_policy_hash *htab;
2432
2433 htab = &net->xfrm.policy_bydst[dir];
2434 xfrm_hash_free(htab->table, sz);
2435 }
2436 xfrm_hash_free(net->xfrm.policy_byidx, sz);
2437out_byidx:
2438 return -ENOMEM;
2433} 2439}
2434 2440
2435void __init xfrm_init(void) 2441static void xfrm_policy_fini(struct net *net)
2436{ 2442{
2437#ifdef CONFIG_XFRM_STATISTICS 2443 struct xfrm_audit audit_info;
2438 xfrm_statistics_init(); 2444 unsigned int sz;
2445 int dir;
2446
2447 flush_work(&net->xfrm.policy_hash_work);
2448#ifdef CONFIG_XFRM_SUB_POLICY
2449 audit_info.loginuid = -1;
2450 audit_info.sessionid = -1;
2451 audit_info.secid = 0;
2452 xfrm_policy_flush(net, XFRM_POLICY_TYPE_SUB, &audit_info);
2439#endif 2453#endif
2440 xfrm_state_init(); 2454 audit_info.loginuid = -1;
2441 xfrm_policy_init(); 2455 audit_info.sessionid = -1;
2456 audit_info.secid = 0;
2457 xfrm_policy_flush(net, XFRM_POLICY_TYPE_MAIN, &audit_info);
2458 flush_work(&xfrm_policy_gc_work);
2459
2460 WARN_ON(!list_empty(&net->xfrm.policy_all));
2461
2462 for (dir = 0; dir < XFRM_POLICY_MAX * 2; dir++) {
2463 struct xfrm_policy_hash *htab;
2464
2465 WARN_ON(!hlist_empty(&net->xfrm.policy_inexact[dir]));
2466
2467 htab = &net->xfrm.policy_bydst[dir];
2468 sz = (htab->hmask + 1);
2469 WARN_ON(!hlist_empty(htab->table));
2470 xfrm_hash_free(htab->table, sz);
2471 }
2472
2473 sz = (net->xfrm.policy_idx_hmask + 1) * sizeof(struct hlist_head);
2474 WARN_ON(!hlist_empty(net->xfrm.policy_byidx));
2475 xfrm_hash_free(net->xfrm.policy_byidx, sz);
2476}
2477
2478static int __net_init xfrm_net_init(struct net *net)
2479{
2480 int rv;
2481
2482 rv = xfrm_statistics_init(net);
2483 if (rv < 0)
2484 goto out_statistics;
2485 rv = xfrm_state_init(net);
2486 if (rv < 0)
2487 goto out_state;
2488 rv = xfrm_policy_init(net);
2489 if (rv < 0)
2490 goto out_policy;
2491 rv = xfrm_sysctl_init(net);
2492 if (rv < 0)
2493 goto out_sysctl;
2494 return 0;
2495
2496out_sysctl:
2497 xfrm_policy_fini(net);
2498out_policy:
2499 xfrm_state_fini(net);
2500out_state:
2501 xfrm_statistics_fini(net);
2502out_statistics:
2503 return rv;
2504}
2505
2506static void __net_exit xfrm_net_exit(struct net *net)
2507{
2508 xfrm_sysctl_fini(net);
2509 xfrm_policy_fini(net);
2510 xfrm_state_fini(net);
2511 xfrm_statistics_fini(net);
2512}
2513
2514static struct pernet_operations __net_initdata xfrm_net_ops = {
2515 .init = xfrm_net_init,
2516 .exit = xfrm_net_exit,
2517};
2518
2519void __init xfrm_init(void)
2520{
2521 register_pernet_subsys(&xfrm_net_ops);
2442 xfrm_input_init(); 2522 xfrm_input_init();
2443#ifdef CONFIG_XFRM_STATISTICS
2444 xfrm_proc_init();
2445#endif
2446} 2523}
2447 2524
2448#ifdef CONFIG_AUDITSYSCALL 2525#ifdef CONFIG_AUDITSYSCALL
@@ -2458,25 +2535,21 @@ static void xfrm_audit_common_policyinfo(struct xfrm_policy *xp,
2458 2535
2459 switch(sel->family) { 2536 switch(sel->family) {
2460 case AF_INET: 2537 case AF_INET:
2461 audit_log_format(audit_buf, " src=" NIPQUAD_FMT, 2538 audit_log_format(audit_buf, " src=%pI4", &sel->saddr.a4);
2462 NIPQUAD(sel->saddr.a4));
2463 if (sel->prefixlen_s != 32) 2539 if (sel->prefixlen_s != 32)
2464 audit_log_format(audit_buf, " src_prefixlen=%d", 2540 audit_log_format(audit_buf, " src_prefixlen=%d",
2465 sel->prefixlen_s); 2541 sel->prefixlen_s);
2466 audit_log_format(audit_buf, " dst=" NIPQUAD_FMT, 2542 audit_log_format(audit_buf, " dst=%pI4", &sel->daddr.a4);
2467 NIPQUAD(sel->daddr.a4));
2468 if (sel->prefixlen_d != 32) 2543 if (sel->prefixlen_d != 32)
2469 audit_log_format(audit_buf, " dst_prefixlen=%d", 2544 audit_log_format(audit_buf, " dst_prefixlen=%d",
2470 sel->prefixlen_d); 2545 sel->prefixlen_d);
2471 break; 2546 break;
2472 case AF_INET6: 2547 case AF_INET6:
2473 audit_log_format(audit_buf, " src=" NIP6_FMT, 2548 audit_log_format(audit_buf, " src=%pI6", sel->saddr.a6);
2474 NIP6(*(struct in6_addr *)sel->saddr.a6));
2475 if (sel->prefixlen_s != 128) 2549 if (sel->prefixlen_s != 128)
2476 audit_log_format(audit_buf, " src_prefixlen=%d", 2550 audit_log_format(audit_buf, " src_prefixlen=%d",
2477 sel->prefixlen_s); 2551 sel->prefixlen_s);
2478 audit_log_format(audit_buf, " dst=" NIP6_FMT, 2552 audit_log_format(audit_buf, " dst=%pI6", sel->daddr.a6);
2479 NIP6(*(struct in6_addr *)sel->daddr.a6));
2480 if (sel->prefixlen_d != 128) 2553 if (sel->prefixlen_d != 128)
2481 audit_log_format(audit_buf, " dst_prefixlen=%d", 2554 audit_log_format(audit_buf, " dst_prefixlen=%d",
2482 sel->prefixlen_d); 2555 sel->prefixlen_d);
@@ -2546,7 +2619,7 @@ static struct xfrm_policy * xfrm_migrate_policy_find(struct xfrm_selector *sel,
2546 u32 priority = ~0U; 2619 u32 priority = ~0U;
2547 2620
2548 read_lock_bh(&xfrm_policy_lock); 2621 read_lock_bh(&xfrm_policy_lock);
2549 chain = policy_hash_direct(&sel->daddr, &sel->saddr, sel->family, dir); 2622 chain = policy_hash_direct(&init_net, &sel->daddr, &sel->saddr, sel->family, dir);
2550 hlist_for_each_entry(pol, entry, chain, bydst) { 2623 hlist_for_each_entry(pol, entry, chain, bydst) {
2551 if (xfrm_migrate_selector_match(sel, &pol->selector) && 2624 if (xfrm_migrate_selector_match(sel, &pol->selector) &&
2552 pol->type == type) { 2625 pol->type == type) {
@@ -2555,7 +2628,7 @@ static struct xfrm_policy * xfrm_migrate_policy_find(struct xfrm_selector *sel,
2555 break; 2628 break;
2556 } 2629 }
2557 } 2630 }
2558 chain = &xfrm_policy_inexact[dir]; 2631 chain = &init_net.xfrm.policy_inexact[dir];
2559 hlist_for_each_entry(pol, entry, chain, bydst) { 2632 hlist_for_each_entry(pol, entry, chain, bydst) {
2560 if (xfrm_migrate_selector_match(sel, &pol->selector) && 2633 if (xfrm_migrate_selector_match(sel, &pol->selector) &&
2561 pol->type == type && 2634 pol->type == type &&
diff --git a/net/xfrm/xfrm_proc.c b/net/xfrm/xfrm_proc.c
index 2b0db13f0cda..284eaef1dbf2 100644
--- a/net/xfrm/xfrm_proc.c
+++ b/net/xfrm/xfrm_proc.c
@@ -59,17 +59,18 @@ fold_field(void *mib[], int offt)
59 59
60static int xfrm_statistics_seq_show(struct seq_file *seq, void *v) 60static int xfrm_statistics_seq_show(struct seq_file *seq, void *v)
61{ 61{
62 struct net *net = seq->private;
62 int i; 63 int i;
63 for (i=0; xfrm_mib_list[i].name; i++) 64 for (i=0; xfrm_mib_list[i].name; i++)
64 seq_printf(seq, "%-24s\t%lu\n", xfrm_mib_list[i].name, 65 seq_printf(seq, "%-24s\t%lu\n", xfrm_mib_list[i].name,
65 fold_field((void **)xfrm_statistics, 66 fold_field((void **)net->mib.xfrm_statistics,
66 xfrm_mib_list[i].entry)); 67 xfrm_mib_list[i].entry));
67 return 0; 68 return 0;
68} 69}
69 70
70static int xfrm_statistics_seq_open(struct inode *inode, struct file *file) 71static int xfrm_statistics_seq_open(struct inode *inode, struct file *file)
71{ 72{
72 return single_open(file, xfrm_statistics_seq_show, NULL); 73 return single_open_net(inode, file, xfrm_statistics_seq_show);
73} 74}
74 75
75static struct file_operations xfrm_statistics_seq_fops = { 76static struct file_operations xfrm_statistics_seq_fops = {
@@ -77,21 +78,18 @@ static struct file_operations xfrm_statistics_seq_fops = {
77 .open = xfrm_statistics_seq_open, 78 .open = xfrm_statistics_seq_open,
78 .read = seq_read, 79 .read = seq_read,
79 .llseek = seq_lseek, 80 .llseek = seq_lseek,
80 .release = single_release, 81 .release = single_release_net,
81}; 82};
82 83
83int __init xfrm_proc_init(void) 84int __net_init xfrm_proc_init(struct net *net)
84{ 85{
85 int rc = 0; 86 if (!proc_net_fops_create(net, "xfrm_stat", S_IRUGO,
86
87 if (!proc_net_fops_create(&init_net, "xfrm_stat", S_IRUGO,
88 &xfrm_statistics_seq_fops)) 87 &xfrm_statistics_seq_fops))
89 goto stat_fail; 88 return -ENOMEM;
90 89 return 0;
91 out: 90}
92 return rc;
93 91
94 stat_fail: 92void xfrm_proc_fini(struct net *net)
95 rc = -ENOMEM; 93{
96 goto out; 94 proc_net_remove(net, "xfrm_stat");
97} 95}
diff --git a/net/xfrm/xfrm_state.c b/net/xfrm/xfrm_state.c
index 508337f97249..e25ff62ab2a6 100644
--- a/net/xfrm/xfrm_state.c
+++ b/net/xfrm/xfrm_state.c
@@ -24,17 +24,6 @@
24 24
25#include "xfrm_hash.h" 25#include "xfrm_hash.h"
26 26
27struct sock *xfrm_nl;
28EXPORT_SYMBOL(xfrm_nl);
29
30u32 sysctl_xfrm_aevent_etime __read_mostly = XFRM_AE_ETIME;
31EXPORT_SYMBOL(sysctl_xfrm_aevent_etime);
32
33u32 sysctl_xfrm_aevent_rseqth __read_mostly = XFRM_AE_SEQT_SIZE;
34EXPORT_SYMBOL(sysctl_xfrm_aevent_rseqth);
35
36u32 sysctl_xfrm_acq_expires __read_mostly = 30;
37
38/* Each xfrm_state may be linked to two tables: 27/* Each xfrm_state may be linked to two tables:
39 28
40 1. Hash table by (spi,daddr,ah/esp) to find SA by SPI. (input,ctl) 29 1. Hash table by (spi,daddr,ah/esp) to find SA by SPI. (input,ctl)
@@ -44,19 +33,7 @@ u32 sysctl_xfrm_acq_expires __read_mostly = 30;
44 33
45static DEFINE_SPINLOCK(xfrm_state_lock); 34static DEFINE_SPINLOCK(xfrm_state_lock);
46 35
47/* Hash table to find appropriate SA towards given target (endpoint
48 * of tunnel or destination of transport mode) allowed by selector.
49 *
50 * Main use is finding SA after policy selected tunnel or transport mode.
51 * Also, it can be used by ah/esp icmp error handler to find offending SA.
52 */
53static LIST_HEAD(xfrm_state_all);
54static struct hlist_head *xfrm_state_bydst __read_mostly;
55static struct hlist_head *xfrm_state_bysrc __read_mostly;
56static struct hlist_head *xfrm_state_byspi __read_mostly;
57static unsigned int xfrm_state_hmask __read_mostly;
58static unsigned int xfrm_state_hashmax __read_mostly = 1 * 1024 * 1024; 36static unsigned int xfrm_state_hashmax __read_mostly = 1 * 1024 * 1024;
59static unsigned int xfrm_state_num;
60static unsigned int xfrm_state_genid; 37static unsigned int xfrm_state_genid;
61 38
62static struct xfrm_state_afinfo *xfrm_state_get_afinfo(unsigned int family); 39static struct xfrm_state_afinfo *xfrm_state_get_afinfo(unsigned int family);
@@ -69,25 +46,27 @@ static void xfrm_audit_state_replay(struct xfrm_state *x,
69#define xfrm_audit_state_replay(x, s, sq) do { ; } while (0) 46#define xfrm_audit_state_replay(x, s, sq) do { ; } while (0)
70#endif /* CONFIG_AUDITSYSCALL */ 47#endif /* CONFIG_AUDITSYSCALL */
71 48
72static inline unsigned int xfrm_dst_hash(xfrm_address_t *daddr, 49static inline unsigned int xfrm_dst_hash(struct net *net,
50 xfrm_address_t *daddr,
73 xfrm_address_t *saddr, 51 xfrm_address_t *saddr,
74 u32 reqid, 52 u32 reqid,
75 unsigned short family) 53 unsigned short family)
76{ 54{
77 return __xfrm_dst_hash(daddr, saddr, reqid, family, xfrm_state_hmask); 55 return __xfrm_dst_hash(daddr, saddr, reqid, family, net->xfrm.state_hmask);
78} 56}
79 57
80static inline unsigned int xfrm_src_hash(xfrm_address_t *daddr, 58static inline unsigned int xfrm_src_hash(struct net *net,
59 xfrm_address_t *daddr,
81 xfrm_address_t *saddr, 60 xfrm_address_t *saddr,
82 unsigned short family) 61 unsigned short family)
83{ 62{
84 return __xfrm_src_hash(daddr, saddr, family, xfrm_state_hmask); 63 return __xfrm_src_hash(daddr, saddr, family, net->xfrm.state_hmask);
85} 64}
86 65
87static inline unsigned int 66static inline unsigned int
88xfrm_spi_hash(xfrm_address_t *daddr, __be32 spi, u8 proto, unsigned short family) 67xfrm_spi_hash(struct net *net, xfrm_address_t *daddr, __be32 spi, u8 proto, unsigned short family)
89{ 68{
90 return __xfrm_spi_hash(daddr, spi, proto, family, xfrm_state_hmask); 69 return __xfrm_spi_hash(daddr, spi, proto, family, net->xfrm.state_hmask);
91} 70}
92 71
93static void xfrm_hash_transfer(struct hlist_head *list, 72static void xfrm_hash_transfer(struct hlist_head *list,
@@ -121,16 +100,16 @@ static void xfrm_hash_transfer(struct hlist_head *list,
121 } 100 }
122} 101}
123 102
124static unsigned long xfrm_hash_new_size(void) 103static unsigned long xfrm_hash_new_size(unsigned int state_hmask)
125{ 104{
126 return ((xfrm_state_hmask + 1) << 1) * 105 return ((state_hmask + 1) << 1) * sizeof(struct hlist_head);
127 sizeof(struct hlist_head);
128} 106}
129 107
130static DEFINE_MUTEX(hash_resize_mutex); 108static DEFINE_MUTEX(hash_resize_mutex);
131 109
132static void xfrm_hash_resize(struct work_struct *__unused) 110static void xfrm_hash_resize(struct work_struct *work)
133{ 111{
112 struct net *net = container_of(work, struct net, xfrm.state_hash_work);
134 struct hlist_head *ndst, *nsrc, *nspi, *odst, *osrc, *ospi; 113 struct hlist_head *ndst, *nsrc, *nspi, *odst, *osrc, *ospi;
135 unsigned long nsize, osize; 114 unsigned long nsize, osize;
136 unsigned int nhashmask, ohashmask; 115 unsigned int nhashmask, ohashmask;
@@ -138,7 +117,7 @@ static void xfrm_hash_resize(struct work_struct *__unused)
138 117
139 mutex_lock(&hash_resize_mutex); 118 mutex_lock(&hash_resize_mutex);
140 119
141 nsize = xfrm_hash_new_size(); 120 nsize = xfrm_hash_new_size(net->xfrm.state_hmask);
142 ndst = xfrm_hash_alloc(nsize); 121 ndst = xfrm_hash_alloc(nsize);
143 if (!ndst) 122 if (!ndst)
144 goto out_unlock; 123 goto out_unlock;
@@ -157,19 +136,19 @@ static void xfrm_hash_resize(struct work_struct *__unused)
157 spin_lock_bh(&xfrm_state_lock); 136 spin_lock_bh(&xfrm_state_lock);
158 137
159 nhashmask = (nsize / sizeof(struct hlist_head)) - 1U; 138 nhashmask = (nsize / sizeof(struct hlist_head)) - 1U;
160 for (i = xfrm_state_hmask; i >= 0; i--) 139 for (i = net->xfrm.state_hmask; i >= 0; i--)
161 xfrm_hash_transfer(xfrm_state_bydst+i, ndst, nsrc, nspi, 140 xfrm_hash_transfer(net->xfrm.state_bydst+i, ndst, nsrc, nspi,
162 nhashmask); 141 nhashmask);
163 142
164 odst = xfrm_state_bydst; 143 odst = net->xfrm.state_bydst;
165 osrc = xfrm_state_bysrc; 144 osrc = net->xfrm.state_bysrc;
166 ospi = xfrm_state_byspi; 145 ospi = net->xfrm.state_byspi;
167 ohashmask = xfrm_state_hmask; 146 ohashmask = net->xfrm.state_hmask;
168 147
169 xfrm_state_bydst = ndst; 148 net->xfrm.state_bydst = ndst;
170 xfrm_state_bysrc = nsrc; 149 net->xfrm.state_bysrc = nsrc;
171 xfrm_state_byspi = nspi; 150 net->xfrm.state_byspi = nspi;
172 xfrm_state_hmask = nhashmask; 151 net->xfrm.state_hmask = nhashmask;
173 152
174 spin_unlock_bh(&xfrm_state_lock); 153 spin_unlock_bh(&xfrm_state_lock);
175 154
@@ -182,16 +161,9 @@ out_unlock:
182 mutex_unlock(&hash_resize_mutex); 161 mutex_unlock(&hash_resize_mutex);
183} 162}
184 163
185static DECLARE_WORK(xfrm_hash_work, xfrm_hash_resize);
186
187DECLARE_WAIT_QUEUE_HEAD(km_waitq);
188EXPORT_SYMBOL(km_waitq);
189
190static DEFINE_RWLOCK(xfrm_state_afinfo_lock); 164static DEFINE_RWLOCK(xfrm_state_afinfo_lock);
191static struct xfrm_state_afinfo *xfrm_state_afinfo[NPROTO]; 165static struct xfrm_state_afinfo *xfrm_state_afinfo[NPROTO];
192 166
193static struct work_struct xfrm_state_gc_work;
194static HLIST_HEAD(xfrm_state_gc_list);
195static DEFINE_SPINLOCK(xfrm_state_gc_lock); 167static DEFINE_SPINLOCK(xfrm_state_gc_lock);
196 168
197int __xfrm_state_delete(struct xfrm_state *x); 169int __xfrm_state_delete(struct xfrm_state *x);
@@ -401,20 +373,21 @@ static void xfrm_state_gc_destroy(struct xfrm_state *x)
401 kfree(x); 373 kfree(x);
402} 374}
403 375
404static void xfrm_state_gc_task(struct work_struct *data) 376static void xfrm_state_gc_task(struct work_struct *work)
405{ 377{
378 struct net *net = container_of(work, struct net, xfrm.state_gc_work);
406 struct xfrm_state *x; 379 struct xfrm_state *x;
407 struct hlist_node *entry, *tmp; 380 struct hlist_node *entry, *tmp;
408 struct hlist_head gc_list; 381 struct hlist_head gc_list;
409 382
410 spin_lock_bh(&xfrm_state_gc_lock); 383 spin_lock_bh(&xfrm_state_gc_lock);
411 hlist_move_list(&xfrm_state_gc_list, &gc_list); 384 hlist_move_list(&net->xfrm.state_gc_list, &gc_list);
412 spin_unlock_bh(&xfrm_state_gc_lock); 385 spin_unlock_bh(&xfrm_state_gc_lock);
413 386
414 hlist_for_each_entry_safe(x, entry, tmp, &gc_list, gclist) 387 hlist_for_each_entry_safe(x, entry, tmp, &gc_list, gclist)
415 xfrm_state_gc_destroy(x); 388 xfrm_state_gc_destroy(x);
416 389
417 wake_up(&km_waitq); 390 wake_up(&net->xfrm.km_waitq);
418} 391}
419 392
420static inline unsigned long make_jiffies(long secs) 393static inline unsigned long make_jiffies(long secs)
@@ -428,6 +401,7 @@ static inline unsigned long make_jiffies(long secs)
428static void xfrm_timer_handler(unsigned long data) 401static void xfrm_timer_handler(unsigned long data)
429{ 402{
430 struct xfrm_state *x = (struct xfrm_state*)data; 403 struct xfrm_state *x = (struct xfrm_state*)data;
404 struct net *net = xs_net(x);
431 unsigned long now = get_seconds(); 405 unsigned long now = get_seconds();
432 long next = LONG_MAX; 406 long next = LONG_MAX;
433 int warn = 0; 407 int warn = 0;
@@ -485,7 +459,7 @@ resched:
485expired: 459expired:
486 if (x->km.state == XFRM_STATE_ACQ && x->id.spi == 0) { 460 if (x->km.state == XFRM_STATE_ACQ && x->id.spi == 0) {
487 x->km.state = XFRM_STATE_EXPIRED; 461 x->km.state = XFRM_STATE_EXPIRED;
488 wake_up(&km_waitq); 462 wake_up(&net->xfrm.km_waitq);
489 next = 2; 463 next = 2;
490 goto resched; 464 goto resched;
491 } 465 }
@@ -504,13 +478,14 @@ out:
504 478
505static void xfrm_replay_timer_handler(unsigned long data); 479static void xfrm_replay_timer_handler(unsigned long data);
506 480
507struct xfrm_state *xfrm_state_alloc(void) 481struct xfrm_state *xfrm_state_alloc(struct net *net)
508{ 482{
509 struct xfrm_state *x; 483 struct xfrm_state *x;
510 484
511 x = kzalloc(sizeof(struct xfrm_state), GFP_ATOMIC); 485 x = kzalloc(sizeof(struct xfrm_state), GFP_ATOMIC);
512 486
513 if (x) { 487 if (x) {
488 write_pnet(&x->xs_net, net);
514 atomic_set(&x->refcnt, 1); 489 atomic_set(&x->refcnt, 1);
515 atomic_set(&x->tunnel_users, 0); 490 atomic_set(&x->tunnel_users, 0);
516 INIT_LIST_HEAD(&x->km.all); 491 INIT_LIST_HEAD(&x->km.all);
@@ -537,17 +512,20 @@ EXPORT_SYMBOL(xfrm_state_alloc);
537 512
538void __xfrm_state_destroy(struct xfrm_state *x) 513void __xfrm_state_destroy(struct xfrm_state *x)
539{ 514{
515 struct net *net = xs_net(x);
516
540 WARN_ON(x->km.state != XFRM_STATE_DEAD); 517 WARN_ON(x->km.state != XFRM_STATE_DEAD);
541 518
542 spin_lock_bh(&xfrm_state_gc_lock); 519 spin_lock_bh(&xfrm_state_gc_lock);
543 hlist_add_head(&x->gclist, &xfrm_state_gc_list); 520 hlist_add_head(&x->gclist, &net->xfrm.state_gc_list);
544 spin_unlock_bh(&xfrm_state_gc_lock); 521 spin_unlock_bh(&xfrm_state_gc_lock);
545 schedule_work(&xfrm_state_gc_work); 522 schedule_work(&net->xfrm.state_gc_work);
546} 523}
547EXPORT_SYMBOL(__xfrm_state_destroy); 524EXPORT_SYMBOL(__xfrm_state_destroy);
548 525
549int __xfrm_state_delete(struct xfrm_state *x) 526int __xfrm_state_delete(struct xfrm_state *x)
550{ 527{
528 struct net *net = xs_net(x);
551 int err = -ESRCH; 529 int err = -ESRCH;
552 530
553 if (x->km.state != XFRM_STATE_DEAD) { 531 if (x->km.state != XFRM_STATE_DEAD) {
@@ -558,7 +536,7 @@ int __xfrm_state_delete(struct xfrm_state *x)
558 hlist_del(&x->bysrc); 536 hlist_del(&x->bysrc);
559 if (x->id.spi) 537 if (x->id.spi)
560 hlist_del(&x->byspi); 538 hlist_del(&x->byspi);
561 xfrm_state_num--; 539 net->xfrm.state_num--;
562 spin_unlock(&xfrm_state_lock); 540 spin_unlock(&xfrm_state_lock);
563 541
564 /* All xfrm_state objects are created by xfrm_state_alloc. 542 /* All xfrm_state objects are created by xfrm_state_alloc.
@@ -587,15 +565,15 @@ EXPORT_SYMBOL(xfrm_state_delete);
587 565
588#ifdef CONFIG_SECURITY_NETWORK_XFRM 566#ifdef CONFIG_SECURITY_NETWORK_XFRM
589static inline int 567static inline int
590xfrm_state_flush_secctx_check(u8 proto, struct xfrm_audit *audit_info) 568xfrm_state_flush_secctx_check(struct net *net, u8 proto, struct xfrm_audit *audit_info)
591{ 569{
592 int i, err = 0; 570 int i, err = 0;
593 571
594 for (i = 0; i <= xfrm_state_hmask; i++) { 572 for (i = 0; i <= net->xfrm.state_hmask; i++) {
595 struct hlist_node *entry; 573 struct hlist_node *entry;
596 struct xfrm_state *x; 574 struct xfrm_state *x;
597 575
598 hlist_for_each_entry(x, entry, xfrm_state_bydst+i, bydst) { 576 hlist_for_each_entry(x, entry, net->xfrm.state_bydst+i, bydst) {
599 if (xfrm_id_proto_match(x->id.proto, proto) && 577 if (xfrm_id_proto_match(x->id.proto, proto) &&
600 (err = security_xfrm_state_delete(x)) != 0) { 578 (err = security_xfrm_state_delete(x)) != 0) {
601 xfrm_audit_state_delete(x, 0, 579 xfrm_audit_state_delete(x, 0,
@@ -611,26 +589,26 @@ xfrm_state_flush_secctx_check(u8 proto, struct xfrm_audit *audit_info)
611} 589}
612#else 590#else
613static inline int 591static inline int
614xfrm_state_flush_secctx_check(u8 proto, struct xfrm_audit *audit_info) 592xfrm_state_flush_secctx_check(struct net *net, u8 proto, struct xfrm_audit *audit_info)
615{ 593{
616 return 0; 594 return 0;
617} 595}
618#endif 596#endif
619 597
620int xfrm_state_flush(u8 proto, struct xfrm_audit *audit_info) 598int xfrm_state_flush(struct net *net, u8 proto, struct xfrm_audit *audit_info)
621{ 599{
622 int i, err = 0; 600 int i, err = 0;
623 601
624 spin_lock_bh(&xfrm_state_lock); 602 spin_lock_bh(&xfrm_state_lock);
625 err = xfrm_state_flush_secctx_check(proto, audit_info); 603 err = xfrm_state_flush_secctx_check(net, proto, audit_info);
626 if (err) 604 if (err)
627 goto out; 605 goto out;
628 606
629 for (i = 0; i <= xfrm_state_hmask; i++) { 607 for (i = 0; i <= net->xfrm.state_hmask; i++) {
630 struct hlist_node *entry; 608 struct hlist_node *entry;
631 struct xfrm_state *x; 609 struct xfrm_state *x;
632restart: 610restart:
633 hlist_for_each_entry(x, entry, xfrm_state_bydst+i, bydst) { 611 hlist_for_each_entry(x, entry, net->xfrm.state_bydst+i, bydst) {
634 if (!xfrm_state_kern(x) && 612 if (!xfrm_state_kern(x) &&
635 xfrm_id_proto_match(x->id.proto, proto)) { 613 xfrm_id_proto_match(x->id.proto, proto)) {
636 xfrm_state_hold(x); 614 xfrm_state_hold(x);
@@ -652,7 +630,7 @@ restart:
652 630
653out: 631out:
654 spin_unlock_bh(&xfrm_state_lock); 632 spin_unlock_bh(&xfrm_state_lock);
655 wake_up(&km_waitq); 633 wake_up(&net->xfrm.km_waitq);
656 return err; 634 return err;
657} 635}
658EXPORT_SYMBOL(xfrm_state_flush); 636EXPORT_SYMBOL(xfrm_state_flush);
@@ -660,8 +638,8 @@ EXPORT_SYMBOL(xfrm_state_flush);
660void xfrm_sad_getinfo(struct xfrmk_sadinfo *si) 638void xfrm_sad_getinfo(struct xfrmk_sadinfo *si)
661{ 639{
662 spin_lock_bh(&xfrm_state_lock); 640 spin_lock_bh(&xfrm_state_lock);
663 si->sadcnt = xfrm_state_num; 641 si->sadcnt = init_net.xfrm.state_num;
664 si->sadhcnt = xfrm_state_hmask; 642 si->sadhcnt = init_net.xfrm.state_hmask;
665 si->sadhmcnt = xfrm_state_hashmax; 643 si->sadhmcnt = xfrm_state_hashmax;
666 spin_unlock_bh(&xfrm_state_lock); 644 spin_unlock_bh(&xfrm_state_lock);
667} 645}
@@ -681,13 +659,13 @@ xfrm_init_tempsel(struct xfrm_state *x, struct flowi *fl,
681 return 0; 659 return 0;
682} 660}
683 661
684static struct xfrm_state *__xfrm_state_lookup(xfrm_address_t *daddr, __be32 spi, u8 proto, unsigned short family) 662static struct xfrm_state *__xfrm_state_lookup(struct net *net, xfrm_address_t *daddr, __be32 spi, u8 proto, unsigned short family)
685{ 663{
686 unsigned int h = xfrm_spi_hash(daddr, spi, proto, family); 664 unsigned int h = xfrm_spi_hash(net, daddr, spi, proto, family);
687 struct xfrm_state *x; 665 struct xfrm_state *x;
688 struct hlist_node *entry; 666 struct hlist_node *entry;
689 667
690 hlist_for_each_entry(x, entry, xfrm_state_byspi+h, byspi) { 668 hlist_for_each_entry(x, entry, net->xfrm.state_byspi+h, byspi) {
691 if (x->props.family != family || 669 if (x->props.family != family ||
692 x->id.spi != spi || 670 x->id.spi != spi ||
693 x->id.proto != proto) 671 x->id.proto != proto)
@@ -713,13 +691,13 @@ static struct xfrm_state *__xfrm_state_lookup(xfrm_address_t *daddr, __be32 spi,
713 return NULL; 691 return NULL;
714} 692}
715 693
716static struct xfrm_state *__xfrm_state_lookup_byaddr(xfrm_address_t *daddr, xfrm_address_t *saddr, u8 proto, unsigned short family) 694static struct xfrm_state *__xfrm_state_lookup_byaddr(struct net *net, xfrm_address_t *daddr, xfrm_address_t *saddr, u8 proto, unsigned short family)
717{ 695{
718 unsigned int h = xfrm_src_hash(daddr, saddr, family); 696 unsigned int h = xfrm_src_hash(net, daddr, saddr, family);
719 struct xfrm_state *x; 697 struct xfrm_state *x;
720 struct hlist_node *entry; 698 struct hlist_node *entry;
721 699
722 hlist_for_each_entry(x, entry, xfrm_state_bysrc+h, bysrc) { 700 hlist_for_each_entry(x, entry, net->xfrm.state_bysrc+h, bysrc) {
723 if (x->props.family != family || 701 if (x->props.family != family ||
724 x->id.proto != proto) 702 x->id.proto != proto)
725 continue; 703 continue;
@@ -751,21 +729,23 @@ static struct xfrm_state *__xfrm_state_lookup_byaddr(xfrm_address_t *daddr, xfrm
751static inline struct xfrm_state * 729static inline struct xfrm_state *
752__xfrm_state_locate(struct xfrm_state *x, int use_spi, int family) 730__xfrm_state_locate(struct xfrm_state *x, int use_spi, int family)
753{ 731{
732 struct net *net = xs_net(x);
733
754 if (use_spi) 734 if (use_spi)
755 return __xfrm_state_lookup(&x->id.daddr, x->id.spi, 735 return __xfrm_state_lookup(net, &x->id.daddr, x->id.spi,
756 x->id.proto, family); 736 x->id.proto, family);
757 else 737 else
758 return __xfrm_state_lookup_byaddr(&x->id.daddr, 738 return __xfrm_state_lookup_byaddr(net, &x->id.daddr,
759 &x->props.saddr, 739 &x->props.saddr,
760 x->id.proto, family); 740 x->id.proto, family);
761} 741}
762 742
763static void xfrm_hash_grow_check(int have_hash_collision) 743static void xfrm_hash_grow_check(struct net *net, int have_hash_collision)
764{ 744{
765 if (have_hash_collision && 745 if (have_hash_collision &&
766 (xfrm_state_hmask + 1) < xfrm_state_hashmax && 746 (net->xfrm.state_hmask + 1) < xfrm_state_hashmax &&
767 xfrm_state_num > xfrm_state_hmask) 747 net->xfrm.state_num > net->xfrm.state_hmask)
768 schedule_work(&xfrm_hash_work); 748 schedule_work(&net->xfrm.state_hash_work);
769} 749}
770 750
771struct xfrm_state * 751struct xfrm_state *
@@ -774,6 +754,7 @@ xfrm_state_find(xfrm_address_t *daddr, xfrm_address_t *saddr,
774 struct xfrm_policy *pol, int *err, 754 struct xfrm_policy *pol, int *err,
775 unsigned short family) 755 unsigned short family)
776{ 756{
757 struct net *net = xp_net(pol);
777 unsigned int h; 758 unsigned int h;
778 struct hlist_node *entry; 759 struct hlist_node *entry;
779 struct xfrm_state *x, *x0, *to_put; 760 struct xfrm_state *x, *x0, *to_put;
@@ -784,8 +765,8 @@ xfrm_state_find(xfrm_address_t *daddr, xfrm_address_t *saddr,
784 to_put = NULL; 765 to_put = NULL;
785 766
786 spin_lock_bh(&xfrm_state_lock); 767 spin_lock_bh(&xfrm_state_lock);
787 h = xfrm_dst_hash(daddr, saddr, tmpl->reqid, family); 768 h = xfrm_dst_hash(net, daddr, saddr, tmpl->reqid, family);
788 hlist_for_each_entry(x, entry, xfrm_state_bydst+h, bydst) { 769 hlist_for_each_entry(x, entry, net->xfrm.state_bydst+h, bydst) {
789 if (x->props.family == family && 770 if (x->props.family == family &&
790 x->props.reqid == tmpl->reqid && 771 x->props.reqid == tmpl->reqid &&
791 !(x->props.flags & XFRM_STATE_WILDRECV) && 772 !(x->props.flags & XFRM_STATE_WILDRECV) &&
@@ -829,13 +810,13 @@ xfrm_state_find(xfrm_address_t *daddr, xfrm_address_t *saddr,
829 x = best; 810 x = best;
830 if (!x && !error && !acquire_in_progress) { 811 if (!x && !error && !acquire_in_progress) {
831 if (tmpl->id.spi && 812 if (tmpl->id.spi &&
832 (x0 = __xfrm_state_lookup(daddr, tmpl->id.spi, 813 (x0 = __xfrm_state_lookup(net, daddr, tmpl->id.spi,
833 tmpl->id.proto, family)) != NULL) { 814 tmpl->id.proto, family)) != NULL) {
834 to_put = x0; 815 to_put = x0;
835 error = -EEXIST; 816 error = -EEXIST;
836 goto out; 817 goto out;
837 } 818 }
838 x = xfrm_state_alloc(); 819 x = xfrm_state_alloc(net);
839 if (x == NULL) { 820 if (x == NULL) {
840 error = -ENOMEM; 821 error = -ENOMEM;
841 goto out; 822 goto out;
@@ -854,19 +835,19 @@ xfrm_state_find(xfrm_address_t *daddr, xfrm_address_t *saddr,
854 835
855 if (km_query(x, tmpl, pol) == 0) { 836 if (km_query(x, tmpl, pol) == 0) {
856 x->km.state = XFRM_STATE_ACQ; 837 x->km.state = XFRM_STATE_ACQ;
857 list_add(&x->km.all, &xfrm_state_all); 838 list_add(&x->km.all, &net->xfrm.state_all);
858 hlist_add_head(&x->bydst, xfrm_state_bydst+h); 839 hlist_add_head(&x->bydst, net->xfrm.state_bydst+h);
859 h = xfrm_src_hash(daddr, saddr, family); 840 h = xfrm_src_hash(net, daddr, saddr, family);
860 hlist_add_head(&x->bysrc, xfrm_state_bysrc+h); 841 hlist_add_head(&x->bysrc, net->xfrm.state_bysrc+h);
861 if (x->id.spi) { 842 if (x->id.spi) {
862 h = xfrm_spi_hash(&x->id.daddr, x->id.spi, x->id.proto, family); 843 h = xfrm_spi_hash(net, &x->id.daddr, x->id.spi, x->id.proto, family);
863 hlist_add_head(&x->byspi, xfrm_state_byspi+h); 844 hlist_add_head(&x->byspi, net->xfrm.state_byspi+h);
864 } 845 }
865 x->lft.hard_add_expires_seconds = sysctl_xfrm_acq_expires; 846 x->lft.hard_add_expires_seconds = net->xfrm.sysctl_acq_expires;
866 x->timer.expires = jiffies + sysctl_xfrm_acq_expires*HZ; 847 x->timer.expires = jiffies + net->xfrm.sysctl_acq_expires*HZ;
867 add_timer(&x->timer); 848 add_timer(&x->timer);
868 xfrm_state_num++; 849 net->xfrm.state_num++;
869 xfrm_hash_grow_check(x->bydst.next != NULL); 850 xfrm_hash_grow_check(net, x->bydst.next != NULL);
870 } else { 851 } else {
871 x->km.state = XFRM_STATE_DEAD; 852 x->km.state = XFRM_STATE_DEAD;
872 to_put = x; 853 to_put = x;
@@ -886,7 +867,8 @@ out:
886} 867}
887 868
888struct xfrm_state * 869struct xfrm_state *
889xfrm_stateonly_find(xfrm_address_t *daddr, xfrm_address_t *saddr, 870xfrm_stateonly_find(struct net *net,
871 xfrm_address_t *daddr, xfrm_address_t *saddr,
890 unsigned short family, u8 mode, u8 proto, u32 reqid) 872 unsigned short family, u8 mode, u8 proto, u32 reqid)
891{ 873{
892 unsigned int h; 874 unsigned int h;
@@ -894,8 +876,8 @@ xfrm_stateonly_find(xfrm_address_t *daddr, xfrm_address_t *saddr,
894 struct hlist_node *entry; 876 struct hlist_node *entry;
895 877
896 spin_lock(&xfrm_state_lock); 878 spin_lock(&xfrm_state_lock);
897 h = xfrm_dst_hash(daddr, saddr, reqid, family); 879 h = xfrm_dst_hash(net, daddr, saddr, reqid, family);
898 hlist_for_each_entry(x, entry, xfrm_state_bydst+h, bydst) { 880 hlist_for_each_entry(x, entry, net->xfrm.state_bydst+h, bydst) {
899 if (x->props.family == family && 881 if (x->props.family == family &&
900 x->props.reqid == reqid && 882 x->props.reqid == reqid &&
901 !(x->props.flags & XFRM_STATE_WILDRECV) && 883 !(x->props.flags & XFRM_STATE_WILDRECV) &&
@@ -919,48 +901,50 @@ EXPORT_SYMBOL(xfrm_stateonly_find);
919 901
920static void __xfrm_state_insert(struct xfrm_state *x) 902static void __xfrm_state_insert(struct xfrm_state *x)
921{ 903{
904 struct net *net = xs_net(x);
922 unsigned int h; 905 unsigned int h;
923 906
924 x->genid = ++xfrm_state_genid; 907 x->genid = ++xfrm_state_genid;
925 908
926 list_add(&x->km.all, &xfrm_state_all); 909 list_add(&x->km.all, &net->xfrm.state_all);
927 910
928 h = xfrm_dst_hash(&x->id.daddr, &x->props.saddr, 911 h = xfrm_dst_hash(net, &x->id.daddr, &x->props.saddr,
929 x->props.reqid, x->props.family); 912 x->props.reqid, x->props.family);
930 hlist_add_head(&x->bydst, xfrm_state_bydst+h); 913 hlist_add_head(&x->bydst, net->xfrm.state_bydst+h);
931 914
932 h = xfrm_src_hash(&x->id.daddr, &x->props.saddr, x->props.family); 915 h = xfrm_src_hash(net, &x->id.daddr, &x->props.saddr, x->props.family);
933 hlist_add_head(&x->bysrc, xfrm_state_bysrc+h); 916 hlist_add_head(&x->bysrc, net->xfrm.state_bysrc+h);
934 917
935 if (x->id.spi) { 918 if (x->id.spi) {
936 h = xfrm_spi_hash(&x->id.daddr, x->id.spi, x->id.proto, 919 h = xfrm_spi_hash(net, &x->id.daddr, x->id.spi, x->id.proto,
937 x->props.family); 920 x->props.family);
938 921
939 hlist_add_head(&x->byspi, xfrm_state_byspi+h); 922 hlist_add_head(&x->byspi, net->xfrm.state_byspi+h);
940 } 923 }
941 924
942 mod_timer(&x->timer, jiffies + HZ); 925 mod_timer(&x->timer, jiffies + HZ);
943 if (x->replay_maxage) 926 if (x->replay_maxage)
944 mod_timer(&x->rtimer, jiffies + x->replay_maxage); 927 mod_timer(&x->rtimer, jiffies + x->replay_maxage);
945 928
946 wake_up(&km_waitq); 929 wake_up(&net->xfrm.km_waitq);
947 930
948 xfrm_state_num++; 931 net->xfrm.state_num++;
949 932
950 xfrm_hash_grow_check(x->bydst.next != NULL); 933 xfrm_hash_grow_check(net, x->bydst.next != NULL);
951} 934}
952 935
953/* xfrm_state_lock is held */ 936/* xfrm_state_lock is held */
954static void __xfrm_state_bump_genids(struct xfrm_state *xnew) 937static void __xfrm_state_bump_genids(struct xfrm_state *xnew)
955{ 938{
939 struct net *net = xs_net(xnew);
956 unsigned short family = xnew->props.family; 940 unsigned short family = xnew->props.family;
957 u32 reqid = xnew->props.reqid; 941 u32 reqid = xnew->props.reqid;
958 struct xfrm_state *x; 942 struct xfrm_state *x;
959 struct hlist_node *entry; 943 struct hlist_node *entry;
960 unsigned int h; 944 unsigned int h;
961 945
962 h = xfrm_dst_hash(&xnew->id.daddr, &xnew->props.saddr, reqid, family); 946 h = xfrm_dst_hash(net, &xnew->id.daddr, &xnew->props.saddr, reqid, family);
963 hlist_for_each_entry(x, entry, xfrm_state_bydst+h, bydst) { 947 hlist_for_each_entry(x, entry, net->xfrm.state_bydst+h, bydst) {
964 if (x->props.family == family && 948 if (x->props.family == family &&
965 x->props.reqid == reqid && 949 x->props.reqid == reqid &&
966 !xfrm_addr_cmp(&x->id.daddr, &xnew->id.daddr, family) && 950 !xfrm_addr_cmp(&x->id.daddr, &xnew->id.daddr, family) &&
@@ -979,13 +963,13 @@ void xfrm_state_insert(struct xfrm_state *x)
979EXPORT_SYMBOL(xfrm_state_insert); 963EXPORT_SYMBOL(xfrm_state_insert);
980 964
981/* xfrm_state_lock is held */ 965/* xfrm_state_lock is held */
982static struct xfrm_state *__find_acq_core(unsigned short family, u8 mode, u32 reqid, u8 proto, xfrm_address_t *daddr, xfrm_address_t *saddr, int create) 966static struct xfrm_state *__find_acq_core(struct net *net, unsigned short family, u8 mode, u32 reqid, u8 proto, xfrm_address_t *daddr, xfrm_address_t *saddr, int create)
983{ 967{
984 unsigned int h = xfrm_dst_hash(daddr, saddr, reqid, family); 968 unsigned int h = xfrm_dst_hash(net, daddr, saddr, reqid, family);
985 struct hlist_node *entry; 969 struct hlist_node *entry;
986 struct xfrm_state *x; 970 struct xfrm_state *x;
987 971
988 hlist_for_each_entry(x, entry, xfrm_state_bydst+h, bydst) { 972 hlist_for_each_entry(x, entry, net->xfrm.state_bydst+h, bydst) {
989 if (x->props.reqid != reqid || 973 if (x->props.reqid != reqid ||
990 x->props.mode != mode || 974 x->props.mode != mode ||
991 x->props.family != family || 975 x->props.family != family ||
@@ -1017,7 +1001,7 @@ static struct xfrm_state *__find_acq_core(unsigned short family, u8 mode, u32 re
1017 if (!create) 1001 if (!create)
1018 return NULL; 1002 return NULL;
1019 1003
1020 x = xfrm_state_alloc(); 1004 x = xfrm_state_alloc(net);
1021 if (likely(x)) { 1005 if (likely(x)) {
1022 switch (family) { 1006 switch (family) {
1023 case AF_INET: 1007 case AF_INET:
@@ -1048,27 +1032,28 @@ static struct xfrm_state *__find_acq_core(unsigned short family, u8 mode, u32 re
1048 x->props.family = family; 1032 x->props.family = family;
1049 x->props.mode = mode; 1033 x->props.mode = mode;
1050 x->props.reqid = reqid; 1034 x->props.reqid = reqid;
1051 x->lft.hard_add_expires_seconds = sysctl_xfrm_acq_expires; 1035 x->lft.hard_add_expires_seconds = net->xfrm.sysctl_acq_expires;
1052 xfrm_state_hold(x); 1036 xfrm_state_hold(x);
1053 x->timer.expires = jiffies + sysctl_xfrm_acq_expires*HZ; 1037 x->timer.expires = jiffies + net->xfrm.sysctl_acq_expires*HZ;
1054 add_timer(&x->timer); 1038 add_timer(&x->timer);
1055 list_add(&x->km.all, &xfrm_state_all); 1039 list_add(&x->km.all, &net->xfrm.state_all);
1056 hlist_add_head(&x->bydst, xfrm_state_bydst+h); 1040 hlist_add_head(&x->bydst, net->xfrm.state_bydst+h);
1057 h = xfrm_src_hash(daddr, saddr, family); 1041 h = xfrm_src_hash(net, daddr, saddr, family);
1058 hlist_add_head(&x->bysrc, xfrm_state_bysrc+h); 1042 hlist_add_head(&x->bysrc, net->xfrm.state_bysrc+h);
1059 1043
1060 xfrm_state_num++; 1044 net->xfrm.state_num++;
1061 1045
1062 xfrm_hash_grow_check(x->bydst.next != NULL); 1046 xfrm_hash_grow_check(net, x->bydst.next != NULL);
1063 } 1047 }
1064 1048
1065 return x; 1049 return x;
1066} 1050}
1067 1051
1068static struct xfrm_state *__xfrm_find_acq_byseq(u32 seq); 1052static struct xfrm_state *__xfrm_find_acq_byseq(struct net *net, u32 seq);
1069 1053
1070int xfrm_state_add(struct xfrm_state *x) 1054int xfrm_state_add(struct xfrm_state *x)
1071{ 1055{
1056 struct net *net = xs_net(x);
1072 struct xfrm_state *x1, *to_put; 1057 struct xfrm_state *x1, *to_put;
1073 int family; 1058 int family;
1074 int err; 1059 int err;
@@ -1089,7 +1074,7 @@ int xfrm_state_add(struct xfrm_state *x)
1089 } 1074 }
1090 1075
1091 if (use_spi && x->km.seq) { 1076 if (use_spi && x->km.seq) {
1092 x1 = __xfrm_find_acq_byseq(x->km.seq); 1077 x1 = __xfrm_find_acq_byseq(net, x->km.seq);
1093 if (x1 && ((x1->id.proto != x->id.proto) || 1078 if (x1 && ((x1->id.proto != x->id.proto) ||
1094 xfrm_addr_cmp(&x1->id.daddr, &x->id.daddr, family))) { 1079 xfrm_addr_cmp(&x1->id.daddr, &x->id.daddr, family))) {
1095 to_put = x1; 1080 to_put = x1;
@@ -1098,7 +1083,7 @@ int xfrm_state_add(struct xfrm_state *x)
1098 } 1083 }
1099 1084
1100 if (use_spi && !x1) 1085 if (use_spi && !x1)
1101 x1 = __find_acq_core(family, x->props.mode, x->props.reqid, 1086 x1 = __find_acq_core(net, family, x->props.mode, x->props.reqid,
1102 x->id.proto, 1087 x->id.proto,
1103 &x->id.daddr, &x->props.saddr, 0); 1088 &x->id.daddr, &x->props.saddr, 0);
1104 1089
@@ -1124,8 +1109,9 @@ EXPORT_SYMBOL(xfrm_state_add);
1124#ifdef CONFIG_XFRM_MIGRATE 1109#ifdef CONFIG_XFRM_MIGRATE
1125static struct xfrm_state *xfrm_state_clone(struct xfrm_state *orig, int *errp) 1110static struct xfrm_state *xfrm_state_clone(struct xfrm_state *orig, int *errp)
1126{ 1111{
1112 struct net *net = xs_net(orig);
1127 int err = -ENOMEM; 1113 int err = -ENOMEM;
1128 struct xfrm_state *x = xfrm_state_alloc(); 1114 struct xfrm_state *x = xfrm_state_alloc(net);
1129 if (!x) 1115 if (!x)
1130 goto error; 1116 goto error;
1131 1117
@@ -1206,9 +1192,9 @@ struct xfrm_state * xfrm_migrate_state_find(struct xfrm_migrate *m)
1206 struct hlist_node *entry; 1192 struct hlist_node *entry;
1207 1193
1208 if (m->reqid) { 1194 if (m->reqid) {
1209 h = xfrm_dst_hash(&m->old_daddr, &m->old_saddr, 1195 h = xfrm_dst_hash(&init_net, &m->old_daddr, &m->old_saddr,
1210 m->reqid, m->old_family); 1196 m->reqid, m->old_family);
1211 hlist_for_each_entry(x, entry, xfrm_state_bydst+h, bydst) { 1197 hlist_for_each_entry(x, entry, init_net.xfrm.state_bydst+h, bydst) {
1212 if (x->props.mode != m->mode || 1198 if (x->props.mode != m->mode ||
1213 x->id.proto != m->proto) 1199 x->id.proto != m->proto)
1214 continue; 1200 continue;
@@ -1223,9 +1209,9 @@ struct xfrm_state * xfrm_migrate_state_find(struct xfrm_migrate *m)
1223 return x; 1209 return x;
1224 } 1210 }
1225 } else { 1211 } else {
1226 h = xfrm_src_hash(&m->old_daddr, &m->old_saddr, 1212 h = xfrm_src_hash(&init_net, &m->old_daddr, &m->old_saddr,
1227 m->old_family); 1213 m->old_family);
1228 hlist_for_each_entry(x, entry, xfrm_state_bysrc+h, bysrc) { 1214 hlist_for_each_entry(x, entry, init_net.xfrm.state_bysrc+h, bysrc) {
1229 if (x->props.mode != m->mode || 1215 if (x->props.mode != m->mode ||
1230 x->id.proto != m->proto) 1216 x->id.proto != m->proto)
1231 continue; 1217 continue;
@@ -1369,40 +1355,41 @@ int xfrm_state_check_expire(struct xfrm_state *x)
1369EXPORT_SYMBOL(xfrm_state_check_expire); 1355EXPORT_SYMBOL(xfrm_state_check_expire);
1370 1356
1371struct xfrm_state * 1357struct xfrm_state *
1372xfrm_state_lookup(xfrm_address_t *daddr, __be32 spi, u8 proto, 1358xfrm_state_lookup(struct net *net, xfrm_address_t *daddr, __be32 spi, u8 proto,
1373 unsigned short family) 1359 unsigned short family)
1374{ 1360{
1375 struct xfrm_state *x; 1361 struct xfrm_state *x;
1376 1362
1377 spin_lock_bh(&xfrm_state_lock); 1363 spin_lock_bh(&xfrm_state_lock);
1378 x = __xfrm_state_lookup(daddr, spi, proto, family); 1364 x = __xfrm_state_lookup(net, daddr, spi, proto, family);
1379 spin_unlock_bh(&xfrm_state_lock); 1365 spin_unlock_bh(&xfrm_state_lock);
1380 return x; 1366 return x;
1381} 1367}
1382EXPORT_SYMBOL(xfrm_state_lookup); 1368EXPORT_SYMBOL(xfrm_state_lookup);
1383 1369
1384struct xfrm_state * 1370struct xfrm_state *
1385xfrm_state_lookup_byaddr(xfrm_address_t *daddr, xfrm_address_t *saddr, 1371xfrm_state_lookup_byaddr(struct net *net,
1372 xfrm_address_t *daddr, xfrm_address_t *saddr,
1386 u8 proto, unsigned short family) 1373 u8 proto, unsigned short family)
1387{ 1374{
1388 struct xfrm_state *x; 1375 struct xfrm_state *x;
1389 1376
1390 spin_lock_bh(&xfrm_state_lock); 1377 spin_lock_bh(&xfrm_state_lock);
1391 x = __xfrm_state_lookup_byaddr(daddr, saddr, proto, family); 1378 x = __xfrm_state_lookup_byaddr(net, daddr, saddr, proto, family);
1392 spin_unlock_bh(&xfrm_state_lock); 1379 spin_unlock_bh(&xfrm_state_lock);
1393 return x; 1380 return x;
1394} 1381}
1395EXPORT_SYMBOL(xfrm_state_lookup_byaddr); 1382EXPORT_SYMBOL(xfrm_state_lookup_byaddr);
1396 1383
1397struct xfrm_state * 1384struct xfrm_state *
1398xfrm_find_acq(u8 mode, u32 reqid, u8 proto, 1385xfrm_find_acq(struct net *net, u8 mode, u32 reqid, u8 proto,
1399 xfrm_address_t *daddr, xfrm_address_t *saddr, 1386 xfrm_address_t *daddr, xfrm_address_t *saddr,
1400 int create, unsigned short family) 1387 int create, unsigned short family)
1401{ 1388{
1402 struct xfrm_state *x; 1389 struct xfrm_state *x;
1403 1390
1404 spin_lock_bh(&xfrm_state_lock); 1391 spin_lock_bh(&xfrm_state_lock);
1405 x = __find_acq_core(family, mode, reqid, proto, daddr, saddr, create); 1392 x = __find_acq_core(net, family, mode, reqid, proto, daddr, saddr, create);
1406 spin_unlock_bh(&xfrm_state_lock); 1393 spin_unlock_bh(&xfrm_state_lock);
1407 1394
1408 return x; 1395 return x;
@@ -1449,15 +1436,15 @@ EXPORT_SYMBOL(xfrm_state_sort);
1449 1436
1450/* Silly enough, but I'm lazy to build resolution list */ 1437/* Silly enough, but I'm lazy to build resolution list */
1451 1438
1452static struct xfrm_state *__xfrm_find_acq_byseq(u32 seq) 1439static struct xfrm_state *__xfrm_find_acq_byseq(struct net *net, u32 seq)
1453{ 1440{
1454 int i; 1441 int i;
1455 1442
1456 for (i = 0; i <= xfrm_state_hmask; i++) { 1443 for (i = 0; i <= net->xfrm.state_hmask; i++) {
1457 struct hlist_node *entry; 1444 struct hlist_node *entry;
1458 struct xfrm_state *x; 1445 struct xfrm_state *x;
1459 1446
1460 hlist_for_each_entry(x, entry, xfrm_state_bydst+i, bydst) { 1447 hlist_for_each_entry(x, entry, net->xfrm.state_bydst+i, bydst) {
1461 if (x->km.seq == seq && 1448 if (x->km.seq == seq &&
1462 x->km.state == XFRM_STATE_ACQ) { 1449 x->km.state == XFRM_STATE_ACQ) {
1463 xfrm_state_hold(x); 1450 xfrm_state_hold(x);
@@ -1468,12 +1455,12 @@ static struct xfrm_state *__xfrm_find_acq_byseq(u32 seq)
1468 return NULL; 1455 return NULL;
1469} 1456}
1470 1457
1471struct xfrm_state *xfrm_find_acq_byseq(u32 seq) 1458struct xfrm_state *xfrm_find_acq_byseq(struct net *net, u32 seq)
1472{ 1459{
1473 struct xfrm_state *x; 1460 struct xfrm_state *x;
1474 1461
1475 spin_lock_bh(&xfrm_state_lock); 1462 spin_lock_bh(&xfrm_state_lock);
1476 x = __xfrm_find_acq_byseq(seq); 1463 x = __xfrm_find_acq_byseq(net, seq);
1477 spin_unlock_bh(&xfrm_state_lock); 1464 spin_unlock_bh(&xfrm_state_lock);
1478 return x; 1465 return x;
1479} 1466}
@@ -1494,6 +1481,7 @@ EXPORT_SYMBOL(xfrm_get_acqseq);
1494 1481
1495int xfrm_alloc_spi(struct xfrm_state *x, u32 low, u32 high) 1482int xfrm_alloc_spi(struct xfrm_state *x, u32 low, u32 high)
1496{ 1483{
1484 struct net *net = xs_net(x);
1497 unsigned int h; 1485 unsigned int h;
1498 struct xfrm_state *x0; 1486 struct xfrm_state *x0;
1499 int err = -ENOENT; 1487 int err = -ENOENT;
@@ -1511,7 +1499,7 @@ int xfrm_alloc_spi(struct xfrm_state *x, u32 low, u32 high)
1511 err = -ENOENT; 1499 err = -ENOENT;
1512 1500
1513 if (minspi == maxspi) { 1501 if (minspi == maxspi) {
1514 x0 = xfrm_state_lookup(&x->id.daddr, minspi, x->id.proto, x->props.family); 1502 x0 = xfrm_state_lookup(net, &x->id.daddr, minspi, x->id.proto, x->props.family);
1515 if (x0) { 1503 if (x0) {
1516 xfrm_state_put(x0); 1504 xfrm_state_put(x0);
1517 goto unlock; 1505 goto unlock;
@@ -1521,7 +1509,7 @@ int xfrm_alloc_spi(struct xfrm_state *x, u32 low, u32 high)
1521 u32 spi = 0; 1509 u32 spi = 0;
1522 for (h=0; h<high-low+1; h++) { 1510 for (h=0; h<high-low+1; h++) {
1523 spi = low + net_random()%(high-low+1); 1511 spi = low + net_random()%(high-low+1);
1524 x0 = xfrm_state_lookup(&x->id.daddr, htonl(spi), x->id.proto, x->props.family); 1512 x0 = xfrm_state_lookup(net, &x->id.daddr, htonl(spi), x->id.proto, x->props.family);
1525 if (x0 == NULL) { 1513 if (x0 == NULL) {
1526 x->id.spi = htonl(spi); 1514 x->id.spi = htonl(spi);
1527 break; 1515 break;
@@ -1531,8 +1519,8 @@ int xfrm_alloc_spi(struct xfrm_state *x, u32 low, u32 high)
1531 } 1519 }
1532 if (x->id.spi) { 1520 if (x->id.spi) {
1533 spin_lock_bh(&xfrm_state_lock); 1521 spin_lock_bh(&xfrm_state_lock);
1534 h = xfrm_spi_hash(&x->id.daddr, x->id.spi, x->id.proto, x->props.family); 1522 h = xfrm_spi_hash(net, &x->id.daddr, x->id.spi, x->id.proto, x->props.family);
1535 hlist_add_head(&x->byspi, xfrm_state_byspi+h); 1523 hlist_add_head(&x->byspi, net->xfrm.state_byspi+h);
1536 spin_unlock_bh(&xfrm_state_lock); 1524 spin_unlock_bh(&xfrm_state_lock);
1537 1525
1538 err = 0; 1526 err = 0;
@@ -1545,7 +1533,7 @@ unlock:
1545} 1533}
1546EXPORT_SYMBOL(xfrm_alloc_spi); 1534EXPORT_SYMBOL(xfrm_alloc_spi);
1547 1535
1548int xfrm_state_walk(struct xfrm_state_walk *walk, 1536int xfrm_state_walk(struct net *net, struct xfrm_state_walk *walk,
1549 int (*func)(struct xfrm_state *, int, void*), 1537 int (*func)(struct xfrm_state *, int, void*),
1550 void *data) 1538 void *data)
1551{ 1539{
@@ -1558,10 +1546,10 @@ int xfrm_state_walk(struct xfrm_state_walk *walk,
1558 1546
1559 spin_lock_bh(&xfrm_state_lock); 1547 spin_lock_bh(&xfrm_state_lock);
1560 if (list_empty(&walk->all)) 1548 if (list_empty(&walk->all))
1561 x = list_first_entry(&xfrm_state_all, struct xfrm_state_walk, all); 1549 x = list_first_entry(&net->xfrm.state_all, struct xfrm_state_walk, all);
1562 else 1550 else
1563 x = list_entry(&walk->all, struct xfrm_state_walk, all); 1551 x = list_entry(&walk->all, struct xfrm_state_walk, all);
1564 list_for_each_entry_from(x, &xfrm_state_all, all) { 1552 list_for_each_entry_from(x, &net->xfrm.state_all, all) {
1565 if (x->state == XFRM_STATE_DEAD) 1553 if (x->state == XFRM_STATE_DEAD)
1566 continue; 1554 continue;
1567 state = container_of(x, struct xfrm_state, km); 1555 state = container_of(x, struct xfrm_state, km);
@@ -1660,7 +1648,7 @@ static void xfrm_replay_timer_handler(unsigned long data)
1660 spin_lock(&x->lock); 1648 spin_lock(&x->lock);
1661 1649
1662 if (x->km.state == XFRM_STATE_VALID) { 1650 if (x->km.state == XFRM_STATE_VALID) {
1663 if (xfrm_aevent_is_on()) 1651 if (xfrm_aevent_is_on(xs_net(x)))
1664 xfrm_replay_notify(x, XFRM_REPLAY_TIMEOUT); 1652 xfrm_replay_notify(x, XFRM_REPLAY_TIMEOUT);
1665 else 1653 else
1666 x->xflags |= XFRM_TIME_DEFER; 1654 x->xflags |= XFRM_TIME_DEFER;
@@ -1716,7 +1704,7 @@ void xfrm_replay_advance(struct xfrm_state *x, __be32 net_seq)
1716 x->replay.bitmap |= (1U << diff); 1704 x->replay.bitmap |= (1U << diff);
1717 } 1705 }
1718 1706
1719 if (xfrm_aevent_is_on()) 1707 if (xfrm_aevent_is_on(xs_net(x)))
1720 xfrm_replay_notify(x, XFRM_REPLAY_UPDATE); 1708 xfrm_replay_notify(x, XFRM_REPLAY_UPDATE);
1721} 1709}
1722 1710
@@ -1749,6 +1737,7 @@ EXPORT_SYMBOL(km_state_notify);
1749 1737
1750void km_state_expired(struct xfrm_state *x, int hard, u32 pid) 1738void km_state_expired(struct xfrm_state *x, int hard, u32 pid)
1751{ 1739{
1740 struct net *net = xs_net(x);
1752 struct km_event c; 1741 struct km_event c;
1753 1742
1754 c.data.hard = hard; 1743 c.data.hard = hard;
@@ -1757,7 +1746,7 @@ void km_state_expired(struct xfrm_state *x, int hard, u32 pid)
1757 km_state_notify(x, &c); 1746 km_state_notify(x, &c);
1758 1747
1759 if (hard) 1748 if (hard)
1760 wake_up(&km_waitq); 1749 wake_up(&net->xfrm.km_waitq);
1761} 1750}
1762 1751
1763EXPORT_SYMBOL(km_state_expired); 1752EXPORT_SYMBOL(km_state_expired);
@@ -1800,6 +1789,7 @@ EXPORT_SYMBOL(km_new_mapping);
1800 1789
1801void km_policy_expired(struct xfrm_policy *pol, int dir, int hard, u32 pid) 1790void km_policy_expired(struct xfrm_policy *pol, int dir, int hard, u32 pid)
1802{ 1791{
1792 struct net *net = xp_net(pol);
1803 struct km_event c; 1793 struct km_event c;
1804 1794
1805 c.data.hard = hard; 1795 c.data.hard = hard;
@@ -1808,7 +1798,7 @@ void km_policy_expired(struct xfrm_policy *pol, int dir, int hard, u32 pid)
1808 km_policy_notify(pol, dir, &c); 1798 km_policy_notify(pol, dir, &c);
1809 1799
1810 if (hard) 1800 if (hard)
1811 wake_up(&km_waitq); 1801 wake_up(&net->xfrm.km_waitq);
1812} 1802}
1813EXPORT_SYMBOL(km_policy_expired); 1803EXPORT_SYMBOL(km_policy_expired);
1814 1804
@@ -1835,7 +1825,7 @@ int km_migrate(struct xfrm_selector *sel, u8 dir, u8 type,
1835EXPORT_SYMBOL(km_migrate); 1825EXPORT_SYMBOL(km_migrate);
1836#endif 1826#endif
1837 1827
1838int km_report(u8 proto, struct xfrm_selector *sel, xfrm_address_t *addr) 1828int km_report(struct net *net, u8 proto, struct xfrm_selector *sel, xfrm_address_t *addr)
1839{ 1829{
1840 int err = -EINVAL; 1830 int err = -EINVAL;
1841 int ret; 1831 int ret;
@@ -1844,7 +1834,7 @@ int km_report(u8 proto, struct xfrm_selector *sel, xfrm_address_t *addr)
1844 read_lock(&xfrm_km_lock); 1834 read_lock(&xfrm_km_lock);
1845 list_for_each_entry(km, &xfrm_km_list, list) { 1835 list_for_each_entry(km, &xfrm_km_list, list) {
1846 if (km->report) { 1836 if (km->report) {
1847 ret = km->report(proto, sel, addr); 1837 ret = km->report(net, proto, sel, addr);
1848 if (!ret) 1838 if (!ret)
1849 err = ret; 1839 err = ret;
1850 } 1840 }
@@ -2032,8 +2022,9 @@ int xfrm_init_state(struct xfrm_state *x)
2032 x->inner_mode = inner_mode; 2022 x->inner_mode = inner_mode;
2033 } else { 2023 } else {
2034 struct xfrm_mode *inner_mode_iaf; 2024 struct xfrm_mode *inner_mode_iaf;
2025 int iafamily = AF_INET;
2035 2026
2036 inner_mode = xfrm_get_mode(x->props.mode, AF_INET); 2027 inner_mode = xfrm_get_mode(x->props.mode, x->props.family);
2037 if (inner_mode == NULL) 2028 if (inner_mode == NULL)
2038 goto error; 2029 goto error;
2039 2030
@@ -2041,22 +2032,17 @@ int xfrm_init_state(struct xfrm_state *x)
2041 xfrm_put_mode(inner_mode); 2032 xfrm_put_mode(inner_mode);
2042 goto error; 2033 goto error;
2043 } 2034 }
2035 x->inner_mode = inner_mode;
2044 2036
2045 inner_mode_iaf = xfrm_get_mode(x->props.mode, AF_INET6); 2037 if (x->props.family == AF_INET)
2046 if (inner_mode_iaf == NULL) 2038 iafamily = AF_INET6;
2047 goto error;
2048
2049 if (!(inner_mode_iaf->flags & XFRM_MODE_FLAG_TUNNEL)) {
2050 xfrm_put_mode(inner_mode_iaf);
2051 goto error;
2052 }
2053 2039
2054 if (x->props.family == AF_INET) { 2040 inner_mode_iaf = xfrm_get_mode(x->props.mode, iafamily);
2055 x->inner_mode = inner_mode; 2041 if (inner_mode_iaf) {
2056 x->inner_mode_iaf = inner_mode_iaf; 2042 if (inner_mode_iaf->flags & XFRM_MODE_FLAG_TUNNEL)
2057 } else { 2043 x->inner_mode_iaf = inner_mode_iaf;
2058 x->inner_mode = inner_mode_iaf; 2044 else
2059 x->inner_mode_iaf = inner_mode; 2045 xfrm_put_mode(inner_mode_iaf);
2060 } 2046 }
2061 } 2047 }
2062 2048
@@ -2080,20 +2066,61 @@ error:
2080 2066
2081EXPORT_SYMBOL(xfrm_init_state); 2067EXPORT_SYMBOL(xfrm_init_state);
2082 2068
2083void __init xfrm_state_init(void) 2069int __net_init xfrm_state_init(struct net *net)
2084{ 2070{
2085 unsigned int sz; 2071 unsigned int sz;
2086 2072
2073 INIT_LIST_HEAD(&net->xfrm.state_all);
2074
2087 sz = sizeof(struct hlist_head) * 8; 2075 sz = sizeof(struct hlist_head) * 8;
2088 2076
2089 xfrm_state_bydst = xfrm_hash_alloc(sz); 2077 net->xfrm.state_bydst = xfrm_hash_alloc(sz);
2090 xfrm_state_bysrc = xfrm_hash_alloc(sz); 2078 if (!net->xfrm.state_bydst)
2091 xfrm_state_byspi = xfrm_hash_alloc(sz); 2079 goto out_bydst;
2092 if (!xfrm_state_bydst || !xfrm_state_bysrc || !xfrm_state_byspi) 2080 net->xfrm.state_bysrc = xfrm_hash_alloc(sz);
2093 panic("XFRM: Cannot allocate bydst/bysrc/byspi hashes."); 2081 if (!net->xfrm.state_bysrc)
2094 xfrm_state_hmask = ((sz / sizeof(struct hlist_head)) - 1); 2082 goto out_bysrc;
2083 net->xfrm.state_byspi = xfrm_hash_alloc(sz);
2084 if (!net->xfrm.state_byspi)
2085 goto out_byspi;
2086 net->xfrm.state_hmask = ((sz / sizeof(struct hlist_head)) - 1);
2087
2088 net->xfrm.state_num = 0;
2089 INIT_WORK(&net->xfrm.state_hash_work, xfrm_hash_resize);
2090 INIT_HLIST_HEAD(&net->xfrm.state_gc_list);
2091 INIT_WORK(&net->xfrm.state_gc_work, xfrm_state_gc_task);
2092 init_waitqueue_head(&net->xfrm.km_waitq);
2093 return 0;
2094
2095out_byspi:
2096 xfrm_hash_free(net->xfrm.state_bysrc, sz);
2097out_bysrc:
2098 xfrm_hash_free(net->xfrm.state_bydst, sz);
2099out_bydst:
2100 return -ENOMEM;
2101}
2102
2103void xfrm_state_fini(struct net *net)
2104{
2105 struct xfrm_audit audit_info;
2106 unsigned int sz;
2107
2108 flush_work(&net->xfrm.state_hash_work);
2109 audit_info.loginuid = -1;
2110 audit_info.sessionid = -1;
2111 audit_info.secid = 0;
2112 xfrm_state_flush(net, IPSEC_PROTO_ANY, &audit_info);
2113 flush_work(&net->xfrm.state_gc_work);
2114
2115 WARN_ON(!list_empty(&net->xfrm.state_all));
2095 2116
2096 INIT_WORK(&xfrm_state_gc_work, xfrm_state_gc_task); 2117 sz = (net->xfrm.state_hmask + 1) * sizeof(struct hlist_head);
2118 WARN_ON(!hlist_empty(net->xfrm.state_byspi));
2119 xfrm_hash_free(net->xfrm.state_byspi, sz);
2120 WARN_ON(!hlist_empty(net->xfrm.state_bysrc));
2121 xfrm_hash_free(net->xfrm.state_bysrc, sz);
2122 WARN_ON(!hlist_empty(net->xfrm.state_bydst));
2123 xfrm_hash_free(net->xfrm.state_bydst, sz);
2097} 2124}
2098 2125
2099#ifdef CONFIG_AUDITSYSCALL 2126#ifdef CONFIG_AUDITSYSCALL
@@ -2109,16 +2136,12 @@ static void xfrm_audit_helper_sainfo(struct xfrm_state *x,
2109 2136
2110 switch(x->props.family) { 2137 switch(x->props.family) {
2111 case AF_INET: 2138 case AF_INET:
2112 audit_log_format(audit_buf, 2139 audit_log_format(audit_buf, " src=%pI4 dst=%pI4",
2113 " src=" NIPQUAD_FMT " dst=" NIPQUAD_FMT, 2140 &x->props.saddr.a4, &x->id.daddr.a4);
2114 NIPQUAD(x->props.saddr.a4),
2115 NIPQUAD(x->id.daddr.a4));
2116 break; 2141 break;
2117 case AF_INET6: 2142 case AF_INET6:
2118 audit_log_format(audit_buf, 2143 audit_log_format(audit_buf, " src=%pI6 dst=%pI6",
2119 " src=" NIP6_FMT " dst=" NIP6_FMT, 2144 x->props.saddr.a6, x->id.daddr.a6);
2120 NIP6(*(struct in6_addr *)x->props.saddr.a6),
2121 NIP6(*(struct in6_addr *)x->id.daddr.a6));
2122 break; 2145 break;
2123 } 2146 }
2124 2147
@@ -2134,18 +2157,14 @@ static void xfrm_audit_helper_pktinfo(struct sk_buff *skb, u16 family,
2134 switch (family) { 2157 switch (family) {
2135 case AF_INET: 2158 case AF_INET:
2136 iph4 = ip_hdr(skb); 2159 iph4 = ip_hdr(skb);
2137 audit_log_format(audit_buf, 2160 audit_log_format(audit_buf, " src=%pI4 dst=%pI4",
2138 " src=" NIPQUAD_FMT " dst=" NIPQUAD_FMT, 2161 &iph4->saddr, &iph4->daddr);
2139 NIPQUAD(iph4->saddr),
2140 NIPQUAD(iph4->daddr));
2141 break; 2162 break;
2142 case AF_INET6: 2163 case AF_INET6:
2143 iph6 = ipv6_hdr(skb); 2164 iph6 = ipv6_hdr(skb);
2144 audit_log_format(audit_buf, 2165 audit_log_format(audit_buf,
2145 " src=" NIP6_FMT " dst=" NIP6_FMT 2166 " src=%pI6 dst=%pI6 flowlbl=0x%x%02x%02x",
2146 " flowlbl=0x%x%02x%02x", 2167 &iph6->saddr,&iph6->daddr,
2147 NIP6(iph6->saddr),
2148 NIP6(iph6->daddr),
2149 iph6->flow_lbl[0] & 0x0f, 2168 iph6->flow_lbl[0] & 0x0f,
2150 iph6->flow_lbl[1], 2169 iph6->flow_lbl[1],
2151 iph6->flow_lbl[2]); 2170 iph6->flow_lbl[2]);
diff --git a/net/xfrm/xfrm_sysctl.c b/net/xfrm/xfrm_sysctl.c
new file mode 100644
index 000000000000..2e6ffb66f06f
--- /dev/null
+++ b/net/xfrm/xfrm_sysctl.c
@@ -0,0 +1,85 @@
1#include <linux/sysctl.h>
2#include <net/net_namespace.h>
3#include <net/xfrm.h>
4
5static void __xfrm_sysctl_init(struct net *net)
6{
7 net->xfrm.sysctl_aevent_etime = XFRM_AE_ETIME;
8 net->xfrm.sysctl_aevent_rseqth = XFRM_AE_SEQT_SIZE;
9 net->xfrm.sysctl_larval_drop = 1;
10 net->xfrm.sysctl_acq_expires = 30;
11}
12
13#ifdef CONFIG_SYSCTL
14static struct ctl_table xfrm_table[] = {
15 {
16 .ctl_name = NET_CORE_AEVENT_ETIME,
17 .procname = "xfrm_aevent_etime",
18 .maxlen = sizeof(u32),
19 .mode = 0644,
20 .proc_handler = proc_dointvec
21 },
22 {
23 .ctl_name = NET_CORE_AEVENT_RSEQTH,
24 .procname = "xfrm_aevent_rseqth",
25 .maxlen = sizeof(u32),
26 .mode = 0644,
27 .proc_handler = proc_dointvec
28 },
29 {
30 .ctl_name = CTL_UNNUMBERED,
31 .procname = "xfrm_larval_drop",
32 .maxlen = sizeof(int),
33 .mode = 0644,
34 .proc_handler = proc_dointvec
35 },
36 {
37 .ctl_name = CTL_UNNUMBERED,
38 .procname = "xfrm_acq_expires",
39 .maxlen = sizeof(int),
40 .mode = 0644,
41 .proc_handler = proc_dointvec
42 },
43 {}
44};
45
46int __net_init xfrm_sysctl_init(struct net *net)
47{
48 struct ctl_table *table;
49
50 __xfrm_sysctl_init(net);
51
52 table = kmemdup(xfrm_table, sizeof(xfrm_table), GFP_KERNEL);
53 if (!table)
54 goto out_kmemdup;
55 table[0].data = &net->xfrm.sysctl_aevent_etime;
56 table[1].data = &net->xfrm.sysctl_aevent_rseqth;
57 table[2].data = &net->xfrm.sysctl_larval_drop;
58 table[3].data = &net->xfrm.sysctl_acq_expires;
59
60 net->xfrm.sysctl_hdr = register_net_sysctl_table(net, net_core_path, table);
61 if (!net->xfrm.sysctl_hdr)
62 goto out_register;
63 return 0;
64
65out_register:
66 kfree(table);
67out_kmemdup:
68 return -ENOMEM;
69}
70
71void xfrm_sysctl_fini(struct net *net)
72{
73 struct ctl_table *table;
74
75 table = net->xfrm.sysctl_hdr->ctl_table_arg;
76 unregister_net_sysctl_table(net->xfrm.sysctl_hdr);
77 kfree(table);
78}
79#else
80int __net_init xfrm_sysctl_init(struct net *net)
81{
82 __xfrm_sysctl_init(net);
83 return 0;
84}
85#endif
diff --git a/net/xfrm/xfrm_user.c b/net/xfrm/xfrm_user.c
index a278a6f3b991..b95a2d64eb59 100644
--- a/net/xfrm/xfrm_user.c
+++ b/net/xfrm/xfrm_user.c
@@ -316,11 +316,12 @@ static void xfrm_update_ae_params(struct xfrm_state *x, struct nlattr **attrs)
316 x->replay_maxdiff = nla_get_u32(rt); 316 x->replay_maxdiff = nla_get_u32(rt);
317} 317}
318 318
319static struct xfrm_state *xfrm_state_construct(struct xfrm_usersa_info *p, 319static struct xfrm_state *xfrm_state_construct(struct net *net,
320 struct xfrm_usersa_info *p,
320 struct nlattr **attrs, 321 struct nlattr **attrs,
321 int *errp) 322 int *errp)
322{ 323{
323 struct xfrm_state *x = xfrm_state_alloc(); 324 struct xfrm_state *x = xfrm_state_alloc(net);
324 int err = -ENOMEM; 325 int err = -ENOMEM;
325 326
326 if (!x) 327 if (!x)
@@ -367,9 +368,9 @@ static struct xfrm_state *xfrm_state_construct(struct xfrm_usersa_info *p,
367 goto error; 368 goto error;
368 369
369 x->km.seq = p->seq; 370 x->km.seq = p->seq;
370 x->replay_maxdiff = sysctl_xfrm_aevent_rseqth; 371 x->replay_maxdiff = net->xfrm.sysctl_aevent_rseqth;
371 /* sysctl_xfrm_aevent_etime is in 100ms units */ 372 /* sysctl_xfrm_aevent_etime is in 100ms units */
372 x->replay_maxage = (sysctl_xfrm_aevent_etime*HZ)/XFRM_AE_ETH_M; 373 x->replay_maxage = (net->xfrm.sysctl_aevent_etime*HZ)/XFRM_AE_ETH_M;
373 x->preplay.bitmap = 0; 374 x->preplay.bitmap = 0;
374 x->preplay.seq = x->replay.seq+x->replay_maxdiff; 375 x->preplay.seq = x->replay.seq+x->replay_maxdiff;
375 x->preplay.oseq = x->replay.oseq +x->replay_maxdiff; 376 x->preplay.oseq = x->replay.oseq +x->replay_maxdiff;
@@ -391,6 +392,7 @@ error_no_put:
391static int xfrm_add_sa(struct sk_buff *skb, struct nlmsghdr *nlh, 392static int xfrm_add_sa(struct sk_buff *skb, struct nlmsghdr *nlh,
392 struct nlattr **attrs) 393 struct nlattr **attrs)
393{ 394{
395 struct net *net = sock_net(skb->sk);
394 struct xfrm_usersa_info *p = nlmsg_data(nlh); 396 struct xfrm_usersa_info *p = nlmsg_data(nlh);
395 struct xfrm_state *x; 397 struct xfrm_state *x;
396 int err; 398 int err;
@@ -403,7 +405,7 @@ static int xfrm_add_sa(struct sk_buff *skb, struct nlmsghdr *nlh,
403 if (err) 405 if (err)
404 return err; 406 return err;
405 407
406 x = xfrm_state_construct(p, attrs, &err); 408 x = xfrm_state_construct(net, p, attrs, &err);
407 if (!x) 409 if (!x)
408 return err; 410 return err;
409 411
@@ -431,7 +433,8 @@ out:
431 return err; 433 return err;
432} 434}
433 435
434static struct xfrm_state *xfrm_user_state_lookup(struct xfrm_usersa_id *p, 436static struct xfrm_state *xfrm_user_state_lookup(struct net *net,
437 struct xfrm_usersa_id *p,
435 struct nlattr **attrs, 438 struct nlattr **attrs,
436 int *errp) 439 int *errp)
437{ 440{
@@ -440,7 +443,7 @@ static struct xfrm_state *xfrm_user_state_lookup(struct xfrm_usersa_id *p,
440 443
441 if (xfrm_id_proto_match(p->proto, IPSEC_PROTO_ANY)) { 444 if (xfrm_id_proto_match(p->proto, IPSEC_PROTO_ANY)) {
442 err = -ESRCH; 445 err = -ESRCH;
443 x = xfrm_state_lookup(&p->daddr, p->spi, p->proto, p->family); 446 x = xfrm_state_lookup(net, &p->daddr, p->spi, p->proto, p->family);
444 } else { 447 } else {
445 xfrm_address_t *saddr = NULL; 448 xfrm_address_t *saddr = NULL;
446 449
@@ -451,8 +454,8 @@ static struct xfrm_state *xfrm_user_state_lookup(struct xfrm_usersa_id *p,
451 } 454 }
452 455
453 err = -ESRCH; 456 err = -ESRCH;
454 x = xfrm_state_lookup_byaddr(&p->daddr, saddr, p->proto, 457 x = xfrm_state_lookup_byaddr(net, &p->daddr, saddr,
455 p->family); 458 p->proto, p->family);
456 } 459 }
457 460
458 out: 461 out:
@@ -464,6 +467,7 @@ static struct xfrm_state *xfrm_user_state_lookup(struct xfrm_usersa_id *p,
464static int xfrm_del_sa(struct sk_buff *skb, struct nlmsghdr *nlh, 467static int xfrm_del_sa(struct sk_buff *skb, struct nlmsghdr *nlh,
465 struct nlattr **attrs) 468 struct nlattr **attrs)
466{ 469{
470 struct net *net = sock_net(skb->sk);
467 struct xfrm_state *x; 471 struct xfrm_state *x;
468 int err = -ESRCH; 472 int err = -ESRCH;
469 struct km_event c; 473 struct km_event c;
@@ -472,7 +476,7 @@ static int xfrm_del_sa(struct sk_buff *skb, struct nlmsghdr *nlh,
472 u32 sessionid = NETLINK_CB(skb).sessionid; 476 u32 sessionid = NETLINK_CB(skb).sessionid;
473 u32 sid = NETLINK_CB(skb).sid; 477 u32 sid = NETLINK_CB(skb).sid;
474 478
475 x = xfrm_user_state_lookup(p, attrs, &err); 479 x = xfrm_user_state_lookup(net, p, attrs, &err);
476 if (x == NULL) 480 if (x == NULL)
477 return err; 481 return err;
478 482
@@ -615,6 +619,7 @@ static int xfrm_dump_sa_done(struct netlink_callback *cb)
615 619
616static int xfrm_dump_sa(struct sk_buff *skb, struct netlink_callback *cb) 620static int xfrm_dump_sa(struct sk_buff *skb, struct netlink_callback *cb)
617{ 621{
622 struct net *net = sock_net(skb->sk);
618 struct xfrm_state_walk *walk = (struct xfrm_state_walk *) &cb->args[1]; 623 struct xfrm_state_walk *walk = (struct xfrm_state_walk *) &cb->args[1];
619 struct xfrm_dump_info info; 624 struct xfrm_dump_info info;
620 625
@@ -631,7 +636,7 @@ static int xfrm_dump_sa(struct sk_buff *skb, struct netlink_callback *cb)
631 xfrm_state_walk_init(walk, 0); 636 xfrm_state_walk_init(walk, 0);
632 } 637 }
633 638
634 (void) xfrm_state_walk(walk, dump_one_state, &info); 639 (void) xfrm_state_walk(net, walk, dump_one_state, &info);
635 640
636 return skb->len; 641 return skb->len;
637} 642}
@@ -703,6 +708,7 @@ nla_put_failure:
703static int xfrm_get_spdinfo(struct sk_buff *skb, struct nlmsghdr *nlh, 708static int xfrm_get_spdinfo(struct sk_buff *skb, struct nlmsghdr *nlh,
704 struct nlattr **attrs) 709 struct nlattr **attrs)
705{ 710{
711 struct net *net = sock_net(skb->sk);
706 struct sk_buff *r_skb; 712 struct sk_buff *r_skb;
707 u32 *flags = nlmsg_data(nlh); 713 u32 *flags = nlmsg_data(nlh);
708 u32 spid = NETLINK_CB(skb).pid; 714 u32 spid = NETLINK_CB(skb).pid;
@@ -715,7 +721,7 @@ static int xfrm_get_spdinfo(struct sk_buff *skb, struct nlmsghdr *nlh,
715 if (build_spdinfo(r_skb, spid, seq, *flags) < 0) 721 if (build_spdinfo(r_skb, spid, seq, *flags) < 0)
716 BUG(); 722 BUG();
717 723
718 return nlmsg_unicast(xfrm_nl, r_skb, spid); 724 return nlmsg_unicast(net->xfrm.nlsk, r_skb, spid);
719} 725}
720 726
721static inline size_t xfrm_sadinfo_msgsize(void) 727static inline size_t xfrm_sadinfo_msgsize(void)
@@ -756,6 +762,7 @@ nla_put_failure:
756static int xfrm_get_sadinfo(struct sk_buff *skb, struct nlmsghdr *nlh, 762static int xfrm_get_sadinfo(struct sk_buff *skb, struct nlmsghdr *nlh,
757 struct nlattr **attrs) 763 struct nlattr **attrs)
758{ 764{
765 struct net *net = sock_net(skb->sk);
759 struct sk_buff *r_skb; 766 struct sk_buff *r_skb;
760 u32 *flags = nlmsg_data(nlh); 767 u32 *flags = nlmsg_data(nlh);
761 u32 spid = NETLINK_CB(skb).pid; 768 u32 spid = NETLINK_CB(skb).pid;
@@ -768,18 +775,19 @@ static int xfrm_get_sadinfo(struct sk_buff *skb, struct nlmsghdr *nlh,
768 if (build_sadinfo(r_skb, spid, seq, *flags) < 0) 775 if (build_sadinfo(r_skb, spid, seq, *flags) < 0)
769 BUG(); 776 BUG();
770 777
771 return nlmsg_unicast(xfrm_nl, r_skb, spid); 778 return nlmsg_unicast(net->xfrm.nlsk, r_skb, spid);
772} 779}
773 780
774static int xfrm_get_sa(struct sk_buff *skb, struct nlmsghdr *nlh, 781static int xfrm_get_sa(struct sk_buff *skb, struct nlmsghdr *nlh,
775 struct nlattr **attrs) 782 struct nlattr **attrs)
776{ 783{
784 struct net *net = sock_net(skb->sk);
777 struct xfrm_usersa_id *p = nlmsg_data(nlh); 785 struct xfrm_usersa_id *p = nlmsg_data(nlh);
778 struct xfrm_state *x; 786 struct xfrm_state *x;
779 struct sk_buff *resp_skb; 787 struct sk_buff *resp_skb;
780 int err = -ESRCH; 788 int err = -ESRCH;
781 789
782 x = xfrm_user_state_lookup(p, attrs, &err); 790 x = xfrm_user_state_lookup(net, p, attrs, &err);
783 if (x == NULL) 791 if (x == NULL)
784 goto out_noput; 792 goto out_noput;
785 793
@@ -787,7 +795,7 @@ static int xfrm_get_sa(struct sk_buff *skb, struct nlmsghdr *nlh,
787 if (IS_ERR(resp_skb)) { 795 if (IS_ERR(resp_skb)) {
788 err = PTR_ERR(resp_skb); 796 err = PTR_ERR(resp_skb);
789 } else { 797 } else {
790 err = nlmsg_unicast(xfrm_nl, resp_skb, NETLINK_CB(skb).pid); 798 err = nlmsg_unicast(net->xfrm.nlsk, resp_skb, NETLINK_CB(skb).pid);
791 } 799 }
792 xfrm_state_put(x); 800 xfrm_state_put(x);
793out_noput: 801out_noput:
@@ -820,6 +828,7 @@ static int verify_userspi_info(struct xfrm_userspi_info *p)
820static int xfrm_alloc_userspi(struct sk_buff *skb, struct nlmsghdr *nlh, 828static int xfrm_alloc_userspi(struct sk_buff *skb, struct nlmsghdr *nlh,
821 struct nlattr **attrs) 829 struct nlattr **attrs)
822{ 830{
831 struct net *net = sock_net(skb->sk);
823 struct xfrm_state *x; 832 struct xfrm_state *x;
824 struct xfrm_userspi_info *p; 833 struct xfrm_userspi_info *p;
825 struct sk_buff *resp_skb; 834 struct sk_buff *resp_skb;
@@ -837,7 +846,7 @@ static int xfrm_alloc_userspi(struct sk_buff *skb, struct nlmsghdr *nlh,
837 846
838 x = NULL; 847 x = NULL;
839 if (p->info.seq) { 848 if (p->info.seq) {
840 x = xfrm_find_acq_byseq(p->info.seq); 849 x = xfrm_find_acq_byseq(net, p->info.seq);
841 if (x && xfrm_addr_cmp(&x->id.daddr, daddr, family)) { 850 if (x && xfrm_addr_cmp(&x->id.daddr, daddr, family)) {
842 xfrm_state_put(x); 851 xfrm_state_put(x);
843 x = NULL; 852 x = NULL;
@@ -845,7 +854,7 @@ static int xfrm_alloc_userspi(struct sk_buff *skb, struct nlmsghdr *nlh,
845 } 854 }
846 855
847 if (!x) 856 if (!x)
848 x = xfrm_find_acq(p->info.mode, p->info.reqid, 857 x = xfrm_find_acq(net, p->info.mode, p->info.reqid,
849 p->info.id.proto, daddr, 858 p->info.id.proto, daddr,
850 &p->info.saddr, 1, 859 &p->info.saddr, 1,
851 family); 860 family);
@@ -863,7 +872,7 @@ static int xfrm_alloc_userspi(struct sk_buff *skb, struct nlmsghdr *nlh,
863 goto out; 872 goto out;
864 } 873 }
865 874
866 err = nlmsg_unicast(xfrm_nl, resp_skb, NETLINK_CB(skb).pid); 875 err = nlmsg_unicast(net->xfrm.nlsk, resp_skb, NETLINK_CB(skb).pid);
867 876
868out: 877out:
869 xfrm_state_put(x); 878 xfrm_state_put(x);
@@ -1078,9 +1087,9 @@ static void copy_to_user_policy(struct xfrm_policy *xp, struct xfrm_userpolicy_i
1078 p->share = XFRM_SHARE_ANY; /* XXX xp->share */ 1087 p->share = XFRM_SHARE_ANY; /* XXX xp->share */
1079} 1088}
1080 1089
1081static struct xfrm_policy *xfrm_policy_construct(struct xfrm_userpolicy_info *p, struct nlattr **attrs, int *errp) 1090static struct xfrm_policy *xfrm_policy_construct(struct net *net, struct xfrm_userpolicy_info *p, struct nlattr **attrs, int *errp)
1082{ 1091{
1083 struct xfrm_policy *xp = xfrm_policy_alloc(GFP_KERNEL); 1092 struct xfrm_policy *xp = xfrm_policy_alloc(net, GFP_KERNEL);
1084 int err; 1093 int err;
1085 1094
1086 if (!xp) { 1095 if (!xp) {
@@ -1110,6 +1119,7 @@ static struct xfrm_policy *xfrm_policy_construct(struct xfrm_userpolicy_info *p,
1110static int xfrm_add_policy(struct sk_buff *skb, struct nlmsghdr *nlh, 1119static int xfrm_add_policy(struct sk_buff *skb, struct nlmsghdr *nlh,
1111 struct nlattr **attrs) 1120 struct nlattr **attrs)
1112{ 1121{
1122 struct net *net = sock_net(skb->sk);
1113 struct xfrm_userpolicy_info *p = nlmsg_data(nlh); 1123 struct xfrm_userpolicy_info *p = nlmsg_data(nlh);
1114 struct xfrm_policy *xp; 1124 struct xfrm_policy *xp;
1115 struct km_event c; 1125 struct km_event c;
@@ -1126,7 +1136,7 @@ static int xfrm_add_policy(struct sk_buff *skb, struct nlmsghdr *nlh,
1126 if (err) 1136 if (err)
1127 return err; 1137 return err;
1128 1138
1129 xp = xfrm_policy_construct(p, attrs, &err); 1139 xp = xfrm_policy_construct(net, p, attrs, &err);
1130 if (!xp) 1140 if (!xp)
1131 return err; 1141 return err;
1132 1142
@@ -1263,6 +1273,7 @@ static int xfrm_dump_policy_done(struct netlink_callback *cb)
1263 1273
1264static int xfrm_dump_policy(struct sk_buff *skb, struct netlink_callback *cb) 1274static int xfrm_dump_policy(struct sk_buff *skb, struct netlink_callback *cb)
1265{ 1275{
1276 struct net *net = sock_net(skb->sk);
1266 struct xfrm_policy_walk *walk = (struct xfrm_policy_walk *) &cb->args[1]; 1277 struct xfrm_policy_walk *walk = (struct xfrm_policy_walk *) &cb->args[1];
1267 struct xfrm_dump_info info; 1278 struct xfrm_dump_info info;
1268 1279
@@ -1279,7 +1290,7 @@ static int xfrm_dump_policy(struct sk_buff *skb, struct netlink_callback *cb)
1279 xfrm_policy_walk_init(walk, XFRM_POLICY_TYPE_ANY); 1290 xfrm_policy_walk_init(walk, XFRM_POLICY_TYPE_ANY);
1280 } 1291 }
1281 1292
1282 (void) xfrm_policy_walk(walk, dump_one_policy, &info); 1293 (void) xfrm_policy_walk(net, walk, dump_one_policy, &info);
1283 1294
1284 return skb->len; 1295 return skb->len;
1285} 1296}
@@ -1311,6 +1322,7 @@ static struct sk_buff *xfrm_policy_netlink(struct sk_buff *in_skb,
1311static int xfrm_get_policy(struct sk_buff *skb, struct nlmsghdr *nlh, 1322static int xfrm_get_policy(struct sk_buff *skb, struct nlmsghdr *nlh,
1312 struct nlattr **attrs) 1323 struct nlattr **attrs)
1313{ 1324{
1325 struct net *net = sock_net(skb->sk);
1314 struct xfrm_policy *xp; 1326 struct xfrm_policy *xp;
1315 struct xfrm_userpolicy_id *p; 1327 struct xfrm_userpolicy_id *p;
1316 u8 type = XFRM_POLICY_TYPE_MAIN; 1328 u8 type = XFRM_POLICY_TYPE_MAIN;
@@ -1330,7 +1342,7 @@ static int xfrm_get_policy(struct sk_buff *skb, struct nlmsghdr *nlh,
1330 return err; 1342 return err;
1331 1343
1332 if (p->index) 1344 if (p->index)
1333 xp = xfrm_policy_byid(type, p->dir, p->index, delete, &err); 1345 xp = xfrm_policy_byid(net, type, p->dir, p->index, delete, &err);
1334 else { 1346 else {
1335 struct nlattr *rt = attrs[XFRMA_SEC_CTX]; 1347 struct nlattr *rt = attrs[XFRMA_SEC_CTX];
1336 struct xfrm_sec_ctx *ctx; 1348 struct xfrm_sec_ctx *ctx;
@@ -1347,7 +1359,7 @@ static int xfrm_get_policy(struct sk_buff *skb, struct nlmsghdr *nlh,
1347 if (err) 1359 if (err)
1348 return err; 1360 return err;
1349 } 1361 }
1350 xp = xfrm_policy_bysel_ctx(type, p->dir, &p->sel, ctx, 1362 xp = xfrm_policy_bysel_ctx(net, type, p->dir, &p->sel, ctx,
1351 delete, &err); 1363 delete, &err);
1352 security_xfrm_policy_free(ctx); 1364 security_xfrm_policy_free(ctx);
1353 } 1365 }
@@ -1361,7 +1373,7 @@ static int xfrm_get_policy(struct sk_buff *skb, struct nlmsghdr *nlh,
1361 if (IS_ERR(resp_skb)) { 1373 if (IS_ERR(resp_skb)) {
1362 err = PTR_ERR(resp_skb); 1374 err = PTR_ERR(resp_skb);
1363 } else { 1375 } else {
1364 err = nlmsg_unicast(xfrm_nl, resp_skb, 1376 err = nlmsg_unicast(net->xfrm.nlsk, resp_skb,
1365 NETLINK_CB(skb).pid); 1377 NETLINK_CB(skb).pid);
1366 } 1378 }
1367 } else { 1379 } else {
@@ -1390,6 +1402,7 @@ out:
1390static int xfrm_flush_sa(struct sk_buff *skb, struct nlmsghdr *nlh, 1402static int xfrm_flush_sa(struct sk_buff *skb, struct nlmsghdr *nlh,
1391 struct nlattr **attrs) 1403 struct nlattr **attrs)
1392{ 1404{
1405 struct net *net = sock_net(skb->sk);
1393 struct km_event c; 1406 struct km_event c;
1394 struct xfrm_usersa_flush *p = nlmsg_data(nlh); 1407 struct xfrm_usersa_flush *p = nlmsg_data(nlh);
1395 struct xfrm_audit audit_info; 1408 struct xfrm_audit audit_info;
@@ -1398,13 +1411,14 @@ static int xfrm_flush_sa(struct sk_buff *skb, struct nlmsghdr *nlh,
1398 audit_info.loginuid = NETLINK_CB(skb).loginuid; 1411 audit_info.loginuid = NETLINK_CB(skb).loginuid;
1399 audit_info.sessionid = NETLINK_CB(skb).sessionid; 1412 audit_info.sessionid = NETLINK_CB(skb).sessionid;
1400 audit_info.secid = NETLINK_CB(skb).sid; 1413 audit_info.secid = NETLINK_CB(skb).sid;
1401 err = xfrm_state_flush(p->proto, &audit_info); 1414 err = xfrm_state_flush(net, p->proto, &audit_info);
1402 if (err) 1415 if (err)
1403 return err; 1416 return err;
1404 c.data.proto = p->proto; 1417 c.data.proto = p->proto;
1405 c.event = nlh->nlmsg_type; 1418 c.event = nlh->nlmsg_type;
1406 c.seq = nlh->nlmsg_seq; 1419 c.seq = nlh->nlmsg_seq;
1407 c.pid = nlh->nlmsg_pid; 1420 c.pid = nlh->nlmsg_pid;
1421 c.net = net;
1408 km_state_notify(NULL, &c); 1422 km_state_notify(NULL, &c);
1409 1423
1410 return 0; 1424 return 0;
@@ -1457,6 +1471,7 @@ nla_put_failure:
1457static int xfrm_get_ae(struct sk_buff *skb, struct nlmsghdr *nlh, 1471static int xfrm_get_ae(struct sk_buff *skb, struct nlmsghdr *nlh,
1458 struct nlattr **attrs) 1472 struct nlattr **attrs)
1459{ 1473{
1474 struct net *net = sock_net(skb->sk);
1460 struct xfrm_state *x; 1475 struct xfrm_state *x;
1461 struct sk_buff *r_skb; 1476 struct sk_buff *r_skb;
1462 int err; 1477 int err;
@@ -1468,7 +1483,7 @@ static int xfrm_get_ae(struct sk_buff *skb, struct nlmsghdr *nlh,
1468 if (r_skb == NULL) 1483 if (r_skb == NULL)
1469 return -ENOMEM; 1484 return -ENOMEM;
1470 1485
1471 x = xfrm_state_lookup(&id->daddr, id->spi, id->proto, id->family); 1486 x = xfrm_state_lookup(net, &id->daddr, id->spi, id->proto, id->family);
1472 if (x == NULL) { 1487 if (x == NULL) {
1473 kfree_skb(r_skb); 1488 kfree_skb(r_skb);
1474 return -ESRCH; 1489 return -ESRCH;
@@ -1486,7 +1501,7 @@ static int xfrm_get_ae(struct sk_buff *skb, struct nlmsghdr *nlh,
1486 1501
1487 if (build_aevent(r_skb, x, &c) < 0) 1502 if (build_aevent(r_skb, x, &c) < 0)
1488 BUG(); 1503 BUG();
1489 err = nlmsg_unicast(xfrm_nl, r_skb, NETLINK_CB(skb).pid); 1504 err = nlmsg_unicast(net->xfrm.nlsk, r_skb, NETLINK_CB(skb).pid);
1490 spin_unlock_bh(&x->lock); 1505 spin_unlock_bh(&x->lock);
1491 xfrm_state_put(x); 1506 xfrm_state_put(x);
1492 return err; 1507 return err;
@@ -1495,6 +1510,7 @@ static int xfrm_get_ae(struct sk_buff *skb, struct nlmsghdr *nlh,
1495static int xfrm_new_ae(struct sk_buff *skb, struct nlmsghdr *nlh, 1510static int xfrm_new_ae(struct sk_buff *skb, struct nlmsghdr *nlh,
1496 struct nlattr **attrs) 1511 struct nlattr **attrs)
1497{ 1512{
1513 struct net *net = sock_net(skb->sk);
1498 struct xfrm_state *x; 1514 struct xfrm_state *x;
1499 struct km_event c; 1515 struct km_event c;
1500 int err = - EINVAL; 1516 int err = - EINVAL;
@@ -1509,7 +1525,7 @@ static int xfrm_new_ae(struct sk_buff *skb, struct nlmsghdr *nlh,
1509 if (!(nlh->nlmsg_flags&NLM_F_REPLACE)) 1525 if (!(nlh->nlmsg_flags&NLM_F_REPLACE))
1510 return err; 1526 return err;
1511 1527
1512 x = xfrm_state_lookup(&p->sa_id.daddr, p->sa_id.spi, p->sa_id.proto, p->sa_id.family); 1528 x = xfrm_state_lookup(net, &p->sa_id.daddr, p->sa_id.spi, p->sa_id.proto, p->sa_id.family);
1513 if (x == NULL) 1529 if (x == NULL)
1514 return -ESRCH; 1530 return -ESRCH;
1515 1531
@@ -1534,6 +1550,7 @@ out:
1534static int xfrm_flush_policy(struct sk_buff *skb, struct nlmsghdr *nlh, 1550static int xfrm_flush_policy(struct sk_buff *skb, struct nlmsghdr *nlh,
1535 struct nlattr **attrs) 1551 struct nlattr **attrs)
1536{ 1552{
1553 struct net *net = sock_net(skb->sk);
1537 struct km_event c; 1554 struct km_event c;
1538 u8 type = XFRM_POLICY_TYPE_MAIN; 1555 u8 type = XFRM_POLICY_TYPE_MAIN;
1539 int err; 1556 int err;
@@ -1546,13 +1563,14 @@ static int xfrm_flush_policy(struct sk_buff *skb, struct nlmsghdr *nlh,
1546 audit_info.loginuid = NETLINK_CB(skb).loginuid; 1563 audit_info.loginuid = NETLINK_CB(skb).loginuid;
1547 audit_info.sessionid = NETLINK_CB(skb).sessionid; 1564 audit_info.sessionid = NETLINK_CB(skb).sessionid;
1548 audit_info.secid = NETLINK_CB(skb).sid; 1565 audit_info.secid = NETLINK_CB(skb).sid;
1549 err = xfrm_policy_flush(type, &audit_info); 1566 err = xfrm_policy_flush(net, type, &audit_info);
1550 if (err) 1567 if (err)
1551 return err; 1568 return err;
1552 c.data.type = type; 1569 c.data.type = type;
1553 c.event = nlh->nlmsg_type; 1570 c.event = nlh->nlmsg_type;
1554 c.seq = nlh->nlmsg_seq; 1571 c.seq = nlh->nlmsg_seq;
1555 c.pid = nlh->nlmsg_pid; 1572 c.pid = nlh->nlmsg_pid;
1573 c.net = net;
1556 km_policy_notify(NULL, 0, &c); 1574 km_policy_notify(NULL, 0, &c);
1557 return 0; 1575 return 0;
1558} 1576}
@@ -1560,6 +1578,7 @@ static int xfrm_flush_policy(struct sk_buff *skb, struct nlmsghdr *nlh,
1560static int xfrm_add_pol_expire(struct sk_buff *skb, struct nlmsghdr *nlh, 1578static int xfrm_add_pol_expire(struct sk_buff *skb, struct nlmsghdr *nlh,
1561 struct nlattr **attrs) 1579 struct nlattr **attrs)
1562{ 1580{
1581 struct net *net = sock_net(skb->sk);
1563 struct xfrm_policy *xp; 1582 struct xfrm_policy *xp;
1564 struct xfrm_user_polexpire *up = nlmsg_data(nlh); 1583 struct xfrm_user_polexpire *up = nlmsg_data(nlh);
1565 struct xfrm_userpolicy_info *p = &up->pol; 1584 struct xfrm_userpolicy_info *p = &up->pol;
@@ -1571,7 +1590,7 @@ static int xfrm_add_pol_expire(struct sk_buff *skb, struct nlmsghdr *nlh,
1571 return err; 1590 return err;
1572 1591
1573 if (p->index) 1592 if (p->index)
1574 xp = xfrm_policy_byid(type, p->dir, p->index, 0, &err); 1593 xp = xfrm_policy_byid(net, type, p->dir, p->index, 0, &err);
1575 else { 1594 else {
1576 struct nlattr *rt = attrs[XFRMA_SEC_CTX]; 1595 struct nlattr *rt = attrs[XFRMA_SEC_CTX];
1577 struct xfrm_sec_ctx *ctx; 1596 struct xfrm_sec_ctx *ctx;
@@ -1588,7 +1607,7 @@ static int xfrm_add_pol_expire(struct sk_buff *skb, struct nlmsghdr *nlh,
1588 if (err) 1607 if (err)
1589 return err; 1608 return err;
1590 } 1609 }
1591 xp = xfrm_policy_bysel_ctx(type, p->dir, &p->sel, ctx, 0, &err); 1610 xp = xfrm_policy_bysel_ctx(net, type, p->dir, &p->sel, ctx, 0, &err);
1592 security_xfrm_policy_free(ctx); 1611 security_xfrm_policy_free(ctx);
1593 } 1612 }
1594 if (xp == NULL) 1613 if (xp == NULL)
@@ -1623,12 +1642,13 @@ out:
1623static int xfrm_add_sa_expire(struct sk_buff *skb, struct nlmsghdr *nlh, 1642static int xfrm_add_sa_expire(struct sk_buff *skb, struct nlmsghdr *nlh,
1624 struct nlattr **attrs) 1643 struct nlattr **attrs)
1625{ 1644{
1645 struct net *net = sock_net(skb->sk);
1626 struct xfrm_state *x; 1646 struct xfrm_state *x;
1627 int err; 1647 int err;
1628 struct xfrm_user_expire *ue = nlmsg_data(nlh); 1648 struct xfrm_user_expire *ue = nlmsg_data(nlh);
1629 struct xfrm_usersa_info *p = &ue->state; 1649 struct xfrm_usersa_info *p = &ue->state;
1630 1650
1631 x = xfrm_state_lookup(&p->id.daddr, p->id.spi, p->id.proto, p->family); 1651 x = xfrm_state_lookup(net, &p->id.daddr, p->id.spi, p->id.proto, p->family);
1632 1652
1633 err = -ENOENT; 1653 err = -ENOENT;
1634 if (x == NULL) 1654 if (x == NULL)
@@ -1657,31 +1677,27 @@ out:
1657static int xfrm_add_acquire(struct sk_buff *skb, struct nlmsghdr *nlh, 1677static int xfrm_add_acquire(struct sk_buff *skb, struct nlmsghdr *nlh,
1658 struct nlattr **attrs) 1678 struct nlattr **attrs)
1659{ 1679{
1680 struct net *net = sock_net(skb->sk);
1660 struct xfrm_policy *xp; 1681 struct xfrm_policy *xp;
1661 struct xfrm_user_tmpl *ut; 1682 struct xfrm_user_tmpl *ut;
1662 int i; 1683 int i;
1663 struct nlattr *rt = attrs[XFRMA_TMPL]; 1684 struct nlattr *rt = attrs[XFRMA_TMPL];
1664 1685
1665 struct xfrm_user_acquire *ua = nlmsg_data(nlh); 1686 struct xfrm_user_acquire *ua = nlmsg_data(nlh);
1666 struct xfrm_state *x = xfrm_state_alloc(); 1687 struct xfrm_state *x = xfrm_state_alloc(net);
1667 int err = -ENOMEM; 1688 int err = -ENOMEM;
1668 1689
1669 if (!x) 1690 if (!x)
1670 return err; 1691 goto nomem;
1671 1692
1672 err = verify_newpolicy_info(&ua->policy); 1693 err = verify_newpolicy_info(&ua->policy);
1673 if (err) { 1694 if (err)
1674 printk("BAD policy passed\n"); 1695 goto bad_policy;
1675 kfree(x);
1676 return err;
1677 }
1678 1696
1679 /* build an XP */ 1697 /* build an XP */
1680 xp = xfrm_policy_construct(&ua->policy, attrs, &err); 1698 xp = xfrm_policy_construct(net, &ua->policy, attrs, &err);
1681 if (!xp) { 1699 if (!xp)
1682 kfree(x); 1700 goto free_state;
1683 return err;
1684 }
1685 1701
1686 memcpy(&x->id, &ua->id, sizeof(ua->id)); 1702 memcpy(&x->id, &ua->id, sizeof(ua->id));
1687 memcpy(&x->props.saddr, &ua->saddr, sizeof(ua->saddr)); 1703 memcpy(&x->props.saddr, &ua->saddr, sizeof(ua->saddr));
@@ -1706,6 +1722,13 @@ static int xfrm_add_acquire(struct sk_buff *skb, struct nlmsghdr *nlh,
1706 kfree(xp); 1722 kfree(xp);
1707 1723
1708 return 0; 1724 return 0;
1725
1726bad_policy:
1727 printk("BAD policy passed\n");
1728free_state:
1729 kfree(x);
1730nomem:
1731 return err;
1709} 1732}
1710 1733
1711#ifdef CONFIG_XFRM_MIGRATE 1734#ifdef CONFIG_XFRM_MIGRATE
@@ -1869,6 +1892,7 @@ static int xfrm_send_migrate(struct xfrm_selector *sel, u8 dir, u8 type,
1869 struct xfrm_migrate *m, int num_migrate, 1892 struct xfrm_migrate *m, int num_migrate,
1870 struct xfrm_kmaddress *k) 1893 struct xfrm_kmaddress *k)
1871{ 1894{
1895 struct net *net = &init_net;
1872 struct sk_buff *skb; 1896 struct sk_buff *skb;
1873 1897
1874 skb = nlmsg_new(xfrm_migrate_msgsize(num_migrate, !!k), GFP_ATOMIC); 1898 skb = nlmsg_new(xfrm_migrate_msgsize(num_migrate, !!k), GFP_ATOMIC);
@@ -1879,7 +1903,7 @@ static int xfrm_send_migrate(struct xfrm_selector *sel, u8 dir, u8 type,
1879 if (build_migrate(skb, m, num_migrate, k, sel, dir, type) < 0) 1903 if (build_migrate(skb, m, num_migrate, k, sel, dir, type) < 0)
1880 BUG(); 1904 BUG();
1881 1905
1882 return nlmsg_multicast(xfrm_nl, skb, 0, XFRMNLGRP_MIGRATE, GFP_ATOMIC); 1906 return nlmsg_multicast(net->xfrm.nlsk, skb, 0, XFRMNLGRP_MIGRATE, GFP_ATOMIC);
1883} 1907}
1884#else 1908#else
1885static int xfrm_send_migrate(struct xfrm_selector *sel, u8 dir, u8 type, 1909static int xfrm_send_migrate(struct xfrm_selector *sel, u8 dir, u8 type,
@@ -1968,6 +1992,7 @@ static struct xfrm_link {
1968 1992
1969static int xfrm_user_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh) 1993static int xfrm_user_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
1970{ 1994{
1995 struct net *net = sock_net(skb->sk);
1971 struct nlattr *attrs[XFRMA_MAX+1]; 1996 struct nlattr *attrs[XFRMA_MAX+1];
1972 struct xfrm_link *link; 1997 struct xfrm_link *link;
1973 int type, err; 1998 int type, err;
@@ -1989,7 +2014,7 @@ static int xfrm_user_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
1989 if (link->dump == NULL) 2014 if (link->dump == NULL)
1990 return -EINVAL; 2015 return -EINVAL;
1991 2016
1992 return netlink_dump_start(xfrm_nl, skb, nlh, link->dump, link->done); 2017 return netlink_dump_start(net->xfrm.nlsk, skb, nlh, link->dump, link->done);
1993 } 2018 }
1994 2019
1995 err = nlmsg_parse(nlh, xfrm_msg_min[type], attrs, XFRMA_MAX, 2020 err = nlmsg_parse(nlh, xfrm_msg_min[type], attrs, XFRMA_MAX,
@@ -2033,6 +2058,7 @@ static int build_expire(struct sk_buff *skb, struct xfrm_state *x, struct km_eve
2033 2058
2034static int xfrm_exp_state_notify(struct xfrm_state *x, struct km_event *c) 2059static int xfrm_exp_state_notify(struct xfrm_state *x, struct km_event *c)
2035{ 2060{
2061 struct net *net = xs_net(x);
2036 struct sk_buff *skb; 2062 struct sk_buff *skb;
2037 2063
2038 skb = nlmsg_new(xfrm_expire_msgsize(), GFP_ATOMIC); 2064 skb = nlmsg_new(xfrm_expire_msgsize(), GFP_ATOMIC);
@@ -2042,11 +2068,12 @@ static int xfrm_exp_state_notify(struct xfrm_state *x, struct km_event *c)
2042 if (build_expire(skb, x, c) < 0) 2068 if (build_expire(skb, x, c) < 0)
2043 BUG(); 2069 BUG();
2044 2070
2045 return nlmsg_multicast(xfrm_nl, skb, 0, XFRMNLGRP_EXPIRE, GFP_ATOMIC); 2071 return nlmsg_multicast(net->xfrm.nlsk, skb, 0, XFRMNLGRP_EXPIRE, GFP_ATOMIC);
2046} 2072}
2047 2073
2048static int xfrm_aevent_state_notify(struct xfrm_state *x, struct km_event *c) 2074static int xfrm_aevent_state_notify(struct xfrm_state *x, struct km_event *c)
2049{ 2075{
2076 struct net *net = xs_net(x);
2050 struct sk_buff *skb; 2077 struct sk_buff *skb;
2051 2078
2052 skb = nlmsg_new(xfrm_aevent_msgsize(), GFP_ATOMIC); 2079 skb = nlmsg_new(xfrm_aevent_msgsize(), GFP_ATOMIC);
@@ -2056,11 +2083,12 @@ static int xfrm_aevent_state_notify(struct xfrm_state *x, struct km_event *c)
2056 if (build_aevent(skb, x, c) < 0) 2083 if (build_aevent(skb, x, c) < 0)
2057 BUG(); 2084 BUG();
2058 2085
2059 return nlmsg_multicast(xfrm_nl, skb, 0, XFRMNLGRP_AEVENTS, GFP_ATOMIC); 2086 return nlmsg_multicast(net->xfrm.nlsk, skb, 0, XFRMNLGRP_AEVENTS, GFP_ATOMIC);
2060} 2087}
2061 2088
2062static int xfrm_notify_sa_flush(struct km_event *c) 2089static int xfrm_notify_sa_flush(struct km_event *c)
2063{ 2090{
2091 struct net *net = c->net;
2064 struct xfrm_usersa_flush *p; 2092 struct xfrm_usersa_flush *p;
2065 struct nlmsghdr *nlh; 2093 struct nlmsghdr *nlh;
2066 struct sk_buff *skb; 2094 struct sk_buff *skb;
@@ -2081,7 +2109,7 @@ static int xfrm_notify_sa_flush(struct km_event *c)
2081 2109
2082 nlmsg_end(skb, nlh); 2110 nlmsg_end(skb, nlh);
2083 2111
2084 return nlmsg_multicast(xfrm_nl, skb, 0, XFRMNLGRP_SA, GFP_ATOMIC); 2112 return nlmsg_multicast(net->xfrm.nlsk, skb, 0, XFRMNLGRP_SA, GFP_ATOMIC);
2085} 2113}
2086 2114
2087static inline size_t xfrm_sa_len(struct xfrm_state *x) 2115static inline size_t xfrm_sa_len(struct xfrm_state *x)
@@ -2111,6 +2139,7 @@ static inline size_t xfrm_sa_len(struct xfrm_state *x)
2111 2139
2112static int xfrm_notify_sa(struct xfrm_state *x, struct km_event *c) 2140static int xfrm_notify_sa(struct xfrm_state *x, struct km_event *c)
2113{ 2141{
2142 struct net *net = xs_net(x);
2114 struct xfrm_usersa_info *p; 2143 struct xfrm_usersa_info *p;
2115 struct xfrm_usersa_id *id; 2144 struct xfrm_usersa_id *id;
2116 struct nlmsghdr *nlh; 2145 struct nlmsghdr *nlh;
@@ -2155,7 +2184,7 @@ static int xfrm_notify_sa(struct xfrm_state *x, struct km_event *c)
2155 2184
2156 nlmsg_end(skb, nlh); 2185 nlmsg_end(skb, nlh);
2157 2186
2158 return nlmsg_multicast(xfrm_nl, skb, 0, XFRMNLGRP_SA, GFP_ATOMIC); 2187 return nlmsg_multicast(net->xfrm.nlsk, skb, 0, XFRMNLGRP_SA, GFP_ATOMIC);
2159 2188
2160nla_put_failure: 2189nla_put_failure:
2161 /* Somebody screwed up with xfrm_sa_len! */ 2190 /* Somebody screwed up with xfrm_sa_len! */
@@ -2235,6 +2264,7 @@ nlmsg_failure:
2235static int xfrm_send_acquire(struct xfrm_state *x, struct xfrm_tmpl *xt, 2264static int xfrm_send_acquire(struct xfrm_state *x, struct xfrm_tmpl *xt,
2236 struct xfrm_policy *xp, int dir) 2265 struct xfrm_policy *xp, int dir)
2237{ 2266{
2267 struct net *net = xs_net(x);
2238 struct sk_buff *skb; 2268 struct sk_buff *skb;
2239 2269
2240 skb = nlmsg_new(xfrm_acquire_msgsize(x, xp), GFP_ATOMIC); 2270 skb = nlmsg_new(xfrm_acquire_msgsize(x, xp), GFP_ATOMIC);
@@ -2244,7 +2274,7 @@ static int xfrm_send_acquire(struct xfrm_state *x, struct xfrm_tmpl *xt,
2244 if (build_acquire(skb, x, xt, xp, dir) < 0) 2274 if (build_acquire(skb, x, xt, xp, dir) < 0)
2245 BUG(); 2275 BUG();
2246 2276
2247 return nlmsg_multicast(xfrm_nl, skb, 0, XFRMNLGRP_ACQUIRE, GFP_ATOMIC); 2277 return nlmsg_multicast(net->xfrm.nlsk, skb, 0, XFRMNLGRP_ACQUIRE, GFP_ATOMIC);
2248} 2278}
2249 2279
2250/* User gives us xfrm_user_policy_info followed by an array of 0 2280/* User gives us xfrm_user_policy_info followed by an array of 0
@@ -2253,6 +2283,7 @@ static int xfrm_send_acquire(struct xfrm_state *x, struct xfrm_tmpl *xt,
2253static struct xfrm_policy *xfrm_compile_policy(struct sock *sk, int opt, 2283static struct xfrm_policy *xfrm_compile_policy(struct sock *sk, int opt,
2254 u8 *data, int len, int *dir) 2284 u8 *data, int len, int *dir)
2255{ 2285{
2286 struct net *net = sock_net(sk);
2256 struct xfrm_userpolicy_info *p = (struct xfrm_userpolicy_info *)data; 2287 struct xfrm_userpolicy_info *p = (struct xfrm_userpolicy_info *)data;
2257 struct xfrm_user_tmpl *ut = (struct xfrm_user_tmpl *) (p + 1); 2288 struct xfrm_user_tmpl *ut = (struct xfrm_user_tmpl *) (p + 1);
2258 struct xfrm_policy *xp; 2289 struct xfrm_policy *xp;
@@ -2291,7 +2322,7 @@ static struct xfrm_policy *xfrm_compile_policy(struct sock *sk, int opt,
2291 if (p->dir > XFRM_POLICY_OUT) 2322 if (p->dir > XFRM_POLICY_OUT)
2292 return NULL; 2323 return NULL;
2293 2324
2294 xp = xfrm_policy_alloc(GFP_KERNEL); 2325 xp = xfrm_policy_alloc(net, GFP_KERNEL);
2295 if (xp == NULL) { 2326 if (xp == NULL) {
2296 *dir = -ENOBUFS; 2327 *dir = -ENOBUFS;
2297 return NULL; 2328 return NULL;
@@ -2344,6 +2375,7 @@ nlmsg_failure:
2344 2375
2345static int xfrm_exp_policy_notify(struct xfrm_policy *xp, int dir, struct km_event *c) 2376static int xfrm_exp_policy_notify(struct xfrm_policy *xp, int dir, struct km_event *c)
2346{ 2377{
2378 struct net *net = xp_net(xp);
2347 struct sk_buff *skb; 2379 struct sk_buff *skb;
2348 2380
2349 skb = nlmsg_new(xfrm_polexpire_msgsize(xp), GFP_ATOMIC); 2381 skb = nlmsg_new(xfrm_polexpire_msgsize(xp), GFP_ATOMIC);
@@ -2353,11 +2385,12 @@ static int xfrm_exp_policy_notify(struct xfrm_policy *xp, int dir, struct km_eve
2353 if (build_polexpire(skb, xp, dir, c) < 0) 2385 if (build_polexpire(skb, xp, dir, c) < 0)
2354 BUG(); 2386 BUG();
2355 2387
2356 return nlmsg_multicast(xfrm_nl, skb, 0, XFRMNLGRP_EXPIRE, GFP_ATOMIC); 2388 return nlmsg_multicast(net->xfrm.nlsk, skb, 0, XFRMNLGRP_EXPIRE, GFP_ATOMIC);
2357} 2389}
2358 2390
2359static int xfrm_notify_policy(struct xfrm_policy *xp, int dir, struct km_event *c) 2391static int xfrm_notify_policy(struct xfrm_policy *xp, int dir, struct km_event *c)
2360{ 2392{
2393 struct net *net = xp_net(xp);
2361 struct xfrm_userpolicy_info *p; 2394 struct xfrm_userpolicy_info *p;
2362 struct xfrm_userpolicy_id *id; 2395 struct xfrm_userpolicy_id *id;
2363 struct nlmsghdr *nlh; 2396 struct nlmsghdr *nlh;
@@ -2408,7 +2441,7 @@ static int xfrm_notify_policy(struct xfrm_policy *xp, int dir, struct km_event *
2408 2441
2409 nlmsg_end(skb, nlh); 2442 nlmsg_end(skb, nlh);
2410 2443
2411 return nlmsg_multicast(xfrm_nl, skb, 0, XFRMNLGRP_POLICY, GFP_ATOMIC); 2444 return nlmsg_multicast(net->xfrm.nlsk, skb, 0, XFRMNLGRP_POLICY, GFP_ATOMIC);
2412 2445
2413nlmsg_failure: 2446nlmsg_failure:
2414 kfree_skb(skb); 2447 kfree_skb(skb);
@@ -2417,6 +2450,7 @@ nlmsg_failure:
2417 2450
2418static int xfrm_notify_policy_flush(struct km_event *c) 2451static int xfrm_notify_policy_flush(struct km_event *c)
2419{ 2452{
2453 struct net *net = c->net;
2420 struct nlmsghdr *nlh; 2454 struct nlmsghdr *nlh;
2421 struct sk_buff *skb; 2455 struct sk_buff *skb;
2422 2456
@@ -2432,7 +2466,7 @@ static int xfrm_notify_policy_flush(struct km_event *c)
2432 2466
2433 nlmsg_end(skb, nlh); 2467 nlmsg_end(skb, nlh);
2434 2468
2435 return nlmsg_multicast(xfrm_nl, skb, 0, XFRMNLGRP_POLICY, GFP_ATOMIC); 2469 return nlmsg_multicast(net->xfrm.nlsk, skb, 0, XFRMNLGRP_POLICY, GFP_ATOMIC);
2436 2470
2437nlmsg_failure: 2471nlmsg_failure:
2438 kfree_skb(skb); 2472 kfree_skb(skb);
@@ -2488,8 +2522,8 @@ nla_put_failure:
2488 return -EMSGSIZE; 2522 return -EMSGSIZE;
2489} 2523}
2490 2524
2491static int xfrm_send_report(u8 proto, struct xfrm_selector *sel, 2525static int xfrm_send_report(struct net *net, u8 proto,
2492 xfrm_address_t *addr) 2526 struct xfrm_selector *sel, xfrm_address_t *addr)
2493{ 2527{
2494 struct sk_buff *skb; 2528 struct sk_buff *skb;
2495 2529
@@ -2500,7 +2534,59 @@ static int xfrm_send_report(u8 proto, struct xfrm_selector *sel,
2500 if (build_report(skb, proto, sel, addr) < 0) 2534 if (build_report(skb, proto, sel, addr) < 0)
2501 BUG(); 2535 BUG();
2502 2536
2503 return nlmsg_multicast(xfrm_nl, skb, 0, XFRMNLGRP_REPORT, GFP_ATOMIC); 2537 return nlmsg_multicast(net->xfrm.nlsk, skb, 0, XFRMNLGRP_REPORT, GFP_ATOMIC);
2538}
2539
2540static inline size_t xfrm_mapping_msgsize(void)
2541{
2542 return NLMSG_ALIGN(sizeof(struct xfrm_user_mapping));
2543}
2544
2545static int build_mapping(struct sk_buff *skb, struct xfrm_state *x,
2546 xfrm_address_t *new_saddr, __be16 new_sport)
2547{
2548 struct xfrm_user_mapping *um;
2549 struct nlmsghdr *nlh;
2550
2551 nlh = nlmsg_put(skb, 0, 0, XFRM_MSG_MAPPING, sizeof(*um), 0);
2552 if (nlh == NULL)
2553 return -EMSGSIZE;
2554
2555 um = nlmsg_data(nlh);
2556
2557 memcpy(&um->id.daddr, &x->id.daddr, sizeof(um->id.daddr));
2558 um->id.spi = x->id.spi;
2559 um->id.family = x->props.family;
2560 um->id.proto = x->id.proto;
2561 memcpy(&um->new_saddr, new_saddr, sizeof(um->new_saddr));
2562 memcpy(&um->old_saddr, &x->props.saddr, sizeof(um->old_saddr));
2563 um->new_sport = new_sport;
2564 um->old_sport = x->encap->encap_sport;
2565 um->reqid = x->props.reqid;
2566
2567 return nlmsg_end(skb, nlh);
2568}
2569
2570static int xfrm_send_mapping(struct xfrm_state *x, xfrm_address_t *ipaddr,
2571 __be16 sport)
2572{
2573 struct net *net = xs_net(x);
2574 struct sk_buff *skb;
2575
2576 if (x->id.proto != IPPROTO_ESP)
2577 return -EINVAL;
2578
2579 if (!x->encap)
2580 return -EINVAL;
2581
2582 skb = nlmsg_new(xfrm_mapping_msgsize(), GFP_ATOMIC);
2583 if (skb == NULL)
2584 return -ENOMEM;
2585
2586 if (build_mapping(skb, x, ipaddr, sport) < 0)
2587 BUG();
2588
2589 return nlmsg_multicast(net->xfrm.nlsk, skb, 0, XFRMNLGRP_MAPPING, GFP_ATOMIC);
2504} 2590}
2505 2591
2506static struct xfrm_mgr netlink_mgr = { 2592static struct xfrm_mgr netlink_mgr = {
@@ -2511,35 +2597,56 @@ static struct xfrm_mgr netlink_mgr = {
2511 .notify_policy = xfrm_send_policy_notify, 2597 .notify_policy = xfrm_send_policy_notify,
2512 .report = xfrm_send_report, 2598 .report = xfrm_send_report,
2513 .migrate = xfrm_send_migrate, 2599 .migrate = xfrm_send_migrate,
2600 .new_mapping = xfrm_send_mapping,
2514}; 2601};
2515 2602
2516static int __init xfrm_user_init(void) 2603static int __net_init xfrm_user_net_init(struct net *net)
2517{ 2604{
2518 struct sock *nlsk; 2605 struct sock *nlsk;
2519 2606
2520 printk(KERN_INFO "Initializing XFRM netlink socket\n"); 2607 nlsk = netlink_kernel_create(net, NETLINK_XFRM, XFRMNLGRP_MAX,
2521
2522 nlsk = netlink_kernel_create(&init_net, NETLINK_XFRM, XFRMNLGRP_MAX,
2523 xfrm_netlink_rcv, NULL, THIS_MODULE); 2608 xfrm_netlink_rcv, NULL, THIS_MODULE);
2524 if (nlsk == NULL) 2609 if (nlsk == NULL)
2525 return -ENOMEM; 2610 return -ENOMEM;
2526 rcu_assign_pointer(xfrm_nl, nlsk); 2611 rcu_assign_pointer(net->xfrm.nlsk, nlsk);
2527
2528 xfrm_register_km(&netlink_mgr);
2529
2530 return 0; 2612 return 0;
2531} 2613}
2532 2614
2533static void __exit xfrm_user_exit(void) 2615static void __net_exit xfrm_user_net_exit(struct net *net)
2534{ 2616{
2535 struct sock *nlsk = xfrm_nl; 2617 struct sock *nlsk = net->xfrm.nlsk;
2536 2618
2537 xfrm_unregister_km(&netlink_mgr); 2619 rcu_assign_pointer(net->xfrm.nlsk, NULL);
2538 rcu_assign_pointer(xfrm_nl, NULL);
2539 synchronize_rcu(); 2620 synchronize_rcu();
2540 netlink_kernel_release(nlsk); 2621 netlink_kernel_release(nlsk);
2541} 2622}
2542 2623
2624static struct pernet_operations xfrm_user_net_ops = {
2625 .init = xfrm_user_net_init,
2626 .exit = xfrm_user_net_exit,
2627};
2628
2629static int __init xfrm_user_init(void)
2630{
2631 int rv;
2632
2633 printk(KERN_INFO "Initializing XFRM netlink socket\n");
2634
2635 rv = register_pernet_subsys(&xfrm_user_net_ops);
2636 if (rv < 0)
2637 return rv;
2638 rv = xfrm_register_km(&netlink_mgr);
2639 if (rv < 0)
2640 unregister_pernet_subsys(&xfrm_user_net_ops);
2641 return rv;
2642}
2643
2644static void __exit xfrm_user_exit(void)
2645{
2646 xfrm_unregister_km(&netlink_mgr);
2647 unregister_pernet_subsys(&xfrm_user_net_ops);
2648}
2649
2543module_init(xfrm_user_init); 2650module_init(xfrm_user_init);
2544module_exit(xfrm_user_exit); 2651module_exit(xfrm_user_exit);
2545MODULE_LICENSE("GPL"); 2652MODULE_LICENSE("GPL");