aboutsummaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
Diffstat (limited to 'net')
-rw-r--r--net/802/garp.c1
-rw-r--r--net/802/p8022.c1
-rw-r--r--net/802/p8023.c1
-rw-r--r--net/802/psnap.c1
-rw-r--r--net/802/stp.c1
-rw-r--r--net/802/tr.c8
-rw-r--r--net/8021q/vlan.c97
-rw-r--r--net/8021q/vlan.h21
-rw-r--r--net/8021q/vlan_core.c43
-rw-r--r--net/8021q/vlan_dev.c153
-rw-r--r--net/8021q/vlan_netlink.c7
-rw-r--r--net/8021q/vlanproc.c15
-rw-r--r--net/9p/client.c187
-rw-r--r--net/9p/protocol.c75
-rw-r--r--net/9p/protocol.h6
-rw-r--r--net/9p/trans_fd.c127
-rw-r--r--net/9p/trans_rdma.c10
-rw-r--r--net/9p/trans_virtio.c147
-rw-r--r--net/9p/util.c1
-rw-r--r--net/appletalk/aarp.c3
-rw-r--r--net/appletalk/atalk_proc.c30
-rw-r--r--net/appletalk/ddp.c135
-rw-r--r--net/appletalk/sysctl_net_atalk.c13
-rw-r--r--net/atm/addr.c3
-rw-r--r--net/atm/atm_misc.c40
-rw-r--r--net/atm/atm_sysfs.c28
-rw-r--r--net/atm/br2684.c102
-rw-r--r--net/atm/clip.c87
-rw-r--r--net/atm/common.c389
-rw-r--r--net/atm/ioctl.c369
-rw-r--r--net/atm/lec.c610
-rw-r--r--net/atm/mpc.c541
-rw-r--r--net/atm/mpoa_caches.c191
-rw-r--r--net/atm/mpoa_proc.c90
-rw-r--r--net/atm/pppoatm.c29
-rw-r--r--net/atm/proc.c84
-rw-r--r--net/atm/pvc.c48
-rw-r--r--net/atm/raw.c27
-rw-r--r--net/atm/resources.c419
-rw-r--r--net/atm/signaling.c220
-rw-r--r--net/atm/svc.c267
-rw-r--r--net/ax25/af_ax25.c33
-rw-r--r--net/ax25/ax25_dev.c1
-rw-r--r--net/ax25/ax25_ds_subr.c1
-rw-r--r--net/ax25/ax25_iface.c1
-rw-r--r--net/ax25/ax25_in.c1
-rw-r--r--net/ax25/ax25_ip.c1
-rw-r--r--net/ax25/ax25_out.c7
-rw-r--r--net/ax25/ax25_route.c1
-rw-r--r--net/ax25/ax25_subr.c1
-rw-r--r--net/ax25/ax25_uid.c26
-rw-r--r--net/ax25/sysctl_net_ax25.c39
-rw-r--r--net/bluetooth/af_bluetooth.c12
-rw-r--r--net/bluetooth/bnep/core.c10
-rw-r--r--net/bluetooth/bnep/netdev.c7
-rw-r--r--net/bluetooth/bnep/sock.c7
-rw-r--r--net/bluetooth/cmtp/capi.c37
-rw-r--r--net/bluetooth/cmtp/sock.c7
-rw-r--r--net/bluetooth/hci_conn.c3
-rw-r--r--net/bluetooth/hci_core.c51
-rw-r--r--net/bluetooth/hci_event.c8
-rw-r--r--net/bluetooth/hci_sock.c20
-rw-r--r--net/bluetooth/hci_sysfs.c125
-rw-r--r--net/bluetooth/hidp/core.c137
-rw-r--r--net/bluetooth/hidp/hidp.h4
-rw-r--r--net/bluetooth/hidp/sock.c7
-rw-r--r--net/bluetooth/l2cap.c210
-rw-r--r--net/bluetooth/rfcomm/core.c54
-rw-r--r--net/bluetooth/rfcomm/sock.c46
-rw-r--r--net/bluetooth/sco.c44
-rw-r--r--net/bridge/Kconfig14
-rw-r--r--net/bridge/Makefile2
-rw-r--r--net/bridge/br_device.c24
-rw-r--r--net/bridge/br_fdb.c5
-rw-r--r--net/bridge/br_forward.c167
-rw-r--r--net/bridge/br_if.c32
-rw-r--r--net/bridge/br_input.c42
-rw-r--r--net/bridge/br_ioctl.c5
-rw-r--r--net/bridge/br_multicast.c1309
-rw-r--r--net/bridge/br_netfilter.c7
-rw-r--r--net/bridge/br_netlink.c1
-rw-r--r--net/bridge/br_private.h185
-rw-r--r--net/bridge/br_stp.c2
-rw-r--r--net/bridge/br_stp_bpdu.c1
-rw-r--r--net/bridge/br_stp_if.c1
-rw-r--r--net/bridge/br_sysfs_br.c287
-rw-r--r--net/bridge/br_sysfs_if.c20
-rw-r--r--net/bridge/netfilter/ebt_802_3.c2
-rw-r--r--net/bridge/netfilter/ebt_arp.c2
-rw-r--r--net/bridge/netfilter/ebt_arpreply.c2
-rw-r--r--net/bridge/netfilter/ebt_dnat.c2
-rw-r--r--net/bridge/netfilter/ebt_ip.c2
-rw-r--r--net/bridge/netfilter/ebt_ip6.c2
-rw-r--r--net/bridge/netfilter/ebt_limit.c18
-rw-r--r--net/bridge/netfilter/ebt_log.c2
-rw-r--r--net/bridge/netfilter/ebt_mark.c33
-rw-r--r--net/bridge/netfilter/ebt_mark_m.c39
-rw-r--r--net/bridge/netfilter/ebt_nflog.c2
-rw-r--r--net/bridge/netfilter/ebt_pkttype.c2
-rw-r--r--net/bridge/netfilter/ebt_redirect.c2
-rw-r--r--net/bridge/netfilter/ebt_snat.c2
-rw-r--r--net/bridge/netfilter/ebt_stp.c6
-rw-r--r--net/bridge/netfilter/ebt_ulog.c3
-rw-r--r--net/bridge/netfilter/ebt_vlan.c2
-rw-r--r--net/bridge/netfilter/ebtable_broute.c2
-rw-r--r--net/bridge/netfilter/ebtable_filter.c2
-rw-r--r--net/bridge/netfilter/ebtable_nat.c2
-rw-r--r--net/bridge/netfilter/ebtables.c1248
-rw-r--r--net/can/af_can.c144
-rw-r--r--net/can/af_can.h4
-rw-r--r--net/can/bcm.c13
-rw-r--r--net/can/proc.c93
-rw-r--r--net/can/raw.c8
-rw-r--r--net/compat.c36
-rw-r--r--net/core/Makefile1
-rw-r--r--net/core/datagram.c2
-rw-r--r--net/core/dev.c955
-rw-r--r--net/core/dev_mcast.c5
-rw-r--r--net/core/drop_monitor.c4
-rw-r--r--net/core/dst.c3
-rw-r--r--net/core/ethtool.c514
-rw-r--r--net/core/fib_rules.c110
-rw-r--r--net/core/filter.c15
-rw-r--r--net/core/gen_estimator.c1
-rw-r--r--net/core/gen_stats.c8
-rw-r--r--net/core/iovec.c1
-rw-r--r--net/core/link_watch.c95
-rw-r--r--net/core/neighbour.c68
-rw-r--r--net/core/net-sysfs.c63
-rw-r--r--net/core/net-traces.c1
-rw-r--r--net/core/net_namespace.c272
-rw-r--r--net/core/netpoll.c179
-rw-r--r--net/core/pktgen.c43
-rw-r--r--net/core/rtnetlink.c378
-rw-r--r--net/core/scm.c3
-rw-r--r--net/core/skb_dma_map.c65
-rw-r--r--net/core/skbuff.c7
-rw-r--r--net/core/sock.c100
-rw-r--r--net/core/sysctl_net_core.c26
-rw-r--r--net/core/utils.c2
-rw-r--r--net/dcb/dcbnl.c23
-rw-r--r--net/dccp/ccid.c31
-rw-r--r--net/dccp/ccid.h6
-rw-r--r--net/dccp/ccids/ccid2.c328
-rw-r--r--net/dccp/ccids/ccid2.h46
-rw-r--r--net/dccp/ccids/ccid3.c400
-rw-r--r--net/dccp/ccids/ccid3.h120
-rw-r--r--net/dccp/feat.c1
-rw-r--r--net/dccp/input.c1
-rw-r--r--net/dccp/ipv4.c61
-rw-r--r--net/dccp/ipv6.c54
-rw-r--r--net/dccp/minisocks.c5
-rw-r--r--net/dccp/output.c5
-rw-r--r--net/dccp/probe.c55
-rw-r--r--net/dccp/proto.c41
-rw-r--r--net/dccp/sysctl.c8
-rw-r--r--net/dccp/timer.c4
-rw-r--r--net/decnet/af_decnet.c15
-rw-r--r--net/decnet/dn_dev.c118
-rw-r--r--net/decnet/dn_fib.c11
-rw-r--r--net/decnet/dn_neigh.c1
-rw-r--r--net/decnet/dn_nsp_in.c1
-rw-r--r--net/decnet/dn_nsp_out.c1
-rw-r--r--net/decnet/dn_route.c25
-rw-r--r--net/decnet/dn_rules.c22
-rw-r--r--net/decnet/dn_table.c8
-rw-r--r--net/decnet/netfilter/dn_rtmsg.c1
-rw-r--r--net/decnet/sysctl_net_decnet.c123
-rw-r--r--net/dsa/dsa.c1
-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/econet/af_econet.c16
-rw-r--r--net/ethernet/eth.c13
-rw-r--r--net/ethernet/pe2.c1
-rw-r--r--net/ieee802154/Makefile4
-rw-r--r--net/ieee802154/af_ieee802154.c13
-rw-r--r--net/ieee802154/dgram.c4
-rw-r--r--net/ieee802154/ieee802154.h53
-rw-r--r--net/ieee802154/netlink.c614
-rw-r--r--net/ieee802154/nl-mac.c618
-rw-r--r--net/ieee802154/nl-phy.c345
-rw-r--r--net/ieee802154/nl_policy.c2
-rw-r--r--net/ieee802154/raw.c4
-rw-r--r--net/ieee802154/wpan-class.c76
-rw-r--r--net/ipv4/Kconfig6
-rw-r--r--net/ipv4/af_inet.c126
-rw-r--r--net/ipv4/ah4.c300
-rw-r--r--net/ipv4/arp.c65
-rw-r--r--net/ipv4/cipso_ipv4.c3
-rw-r--r--net/ipv4/datagram.c18
-rw-r--r--net/ipv4/devinet.c306
-rw-r--r--net/ipv4/esp4.c4
-rw-r--r--net/ipv4/fib_frontend.c57
-rw-r--r--net/ipv4/fib_hash.c26
-rw-r--r--net/ipv4/fib_rules.c16
-rw-r--r--net/ipv4/fib_semantics.c85
-rw-r--r--net/ipv4/fib_trie.c35
-rw-r--r--net/ipv4/icmp.c16
-rw-r--r--net/ipv4/igmp.c140
-rw-r--r--net/ipv4/inet_connection_sock.c29
-rw-r--r--net/ipv4/inet_diag.c31
-rw-r--r--net/ipv4/inet_fragment.c1
-rw-r--r--net/ipv4/inet_hashtables.c73
-rw-r--r--net/ipv4/inet_lro.c36
-rw-r--r--net/ipv4/inet_timewait_sock.c154
-rw-r--r--net/ipv4/inetpeer.c5
-rw-r--r--net/ipv4/ip_forward.c1
-rw-r--r--net/ipv4/ip_fragment.c53
-rw-r--r--net/ipv4/ip_gre.c119
-rw-r--r--net/ipv4/ip_input.c5
-rw-r--r--net/ipv4/ip_options.c1
-rw-r--r--net/ipv4/ip_output.c28
-rw-r--r--net/ipv4/ip_sockglue.c27
-rw-r--r--net/ipv4/ipcomp.c17
-rw-r--r--net/ipv4/ipconfig.c73
-rw-r--r--net/ipv4/ipip.c116
-rw-r--r--net/ipv4/ipmr.c50
-rw-r--r--net/ipv4/netfilter.c15
-rw-r--r--net/ipv4/netfilter/arp_tables.c412
-rw-r--r--net/ipv4/netfilter/arptable_filter.c96
-rw-r--r--net/ipv4/netfilter/ip_queue.c11
-rw-r--r--net/ipv4/netfilter/ip_tables.c607
-rw-r--r--net/ipv4/netfilter/ipt_CLUSTERIP.c35
-rw-r--r--net/ipv4/netfilter/ipt_ECN.c10
-rw-r--r--net/ipv4/netfilter/ipt_LOG.c22
-rw-r--r--net/ipv4/netfilter/ipt_MASQUERADE.c4
-rw-r--r--net/ipv4/netfilter/ipt_REJECT.c5
-rw-r--r--net/ipv4/netfilter/ipt_ULOG.c11
-rw-r--r--net/ipv4/netfilter/ipt_ecn.c4
-rw-r--r--net/ipv4/netfilter/iptable_filter.c125
-rw-r--r--net/ipv4/netfilter/iptable_mangle.c171
-rw-r--r--net/ipv4/netfilter/iptable_raw.c97
-rw-r--r--net/ipv4/netfilter/iptable_security.c118
-rw-r--r--net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c23
-rw-r--r--net/ipv4/netfilter/nf_conntrack_l3proto_ipv4_compat.c4
-rw-r--r--net/ipv4/netfilter/nf_conntrack_proto_icmp.c47
-rw-r--r--net/ipv4/netfilter/nf_defrag_ipv4.c34
-rw-r--r--net/ipv4/netfilter/nf_nat_core.c41
-rw-r--r--net/ipv4/netfilter/nf_nat_ftp.c105
-rw-r--r--net/ipv4/netfilter/nf_nat_helper.c62
-rw-r--r--net/ipv4/netfilter/nf_nat_pptp.c3
-rw-r--r--net/ipv4/netfilter/nf_nat_rule.c42
-rw-r--r--net/ipv4/netfilter/nf_nat_sip.c154
-rw-r--r--net/ipv4/netfilter/nf_nat_snmp_basic.c32
-rw-r--r--net/ipv4/netfilter/nf_nat_standalone.c11
-rw-r--r--net/ipv4/proc.c34
-rw-r--r--net/ipv4/raw.c34
-rw-r--r--net/ipv4/route.c305
-rw-r--r--net/ipv4/syncookies.c11
-rw-r--r--net/ipv4/sysctl_net_ipv4.c190
-rw-r--r--net/ipv4/tcp.c450
-rw-r--r--net/ipv4/tcp_cong.c1
-rw-r--r--net/ipv4/tcp_diag.c2
-rw-r--r--net/ipv4/tcp_htcp.c10
-rw-r--r--net/ipv4/tcp_input.c142
-rw-r--r--net/ipv4/tcp_ipv4.c232
-rw-r--r--net/ipv4/tcp_lp.c4
-rw-r--r--net/ipv4/tcp_minisocks.c73
-rw-r--r--net/ipv4/tcp_output.c336
-rw-r--r--net/ipv4/tcp_probe.c33
-rw-r--r--net/ipv4/tcp_timer.c69
-rw-r--r--net/ipv4/tcp_veno.c5
-rw-r--r--net/ipv4/tcp_yeah.c4
-rw-r--r--net/ipv4/tunnel4.c1
-rw-r--r--net/ipv4/udp.c515
-rw-r--r--net/ipv4/udplite.c9
-rw-r--r--net/ipv4/xfrm4_input.c1
-rw-r--r--net/ipv4/xfrm4_mode_tunnel.c1
-rw-r--r--net/ipv4/xfrm4_policy.c20
-rw-r--r--net/ipv6/Kconfig19
-rw-r--r--net/ipv6/addrconf.c493
-rw-r--r--net/ipv6/addrconf_core.c2
-rw-r--r--net/ipv6/addrlabel.c1
-rw-r--r--net/ipv6/af_inet6.c88
-rw-r--r--net/ipv6/ah6.c357
-rw-r--r--net/ipv6/anycast.c38
-rw-r--r--net/ipv6/datagram.c57
-rw-r--r--net/ipv6/esp6.c4
-rw-r--r--net/ipv6/exthdrs.c10
-rw-r--r--net/ipv6/fib6_rules.c39
-rw-r--r--net/ipv6/icmp.c17
-rw-r--r--net/ipv6/inet6_connection_sock.c11
-rw-r--r--net/ipv6/inet6_hashtables.c37
-rw-r--r--net/ipv6/ip6_fib.c53
-rw-r--r--net/ipv6/ip6_flowlabel.c27
-rw-r--r--net/ipv6/ip6_input.c4
-rw-r--r--net/ipv6/ip6_output.c29
-rw-r--r--net/ipv6/ip6_tunnel.c135
-rw-r--r--net/ipv6/ip6mr.c32
-rw-r--r--net/ipv6/ipcomp6.c21
-rw-r--r--net/ipv6/ipv6_sockglue.c10
-rw-r--r--net/ipv6/mcast.c84
-rw-r--r--net/ipv6/mip6.c2
-rw-r--r--net/ipv6/ndisc.c48
-rw-r--r--net/ipv6/netfilter/ip6_queue.c12
-rw-r--r--net/ipv6/netfilter/ip6_tables.c605
-rw-r--r--net/ipv6/netfilter/ip6t_LOG.c4
-rw-r--r--net/ipv6/netfilter/ip6t_REJECT.c7
-rw-r--r--net/ipv6/netfilter/ip6t_ah.c19
-rw-r--r--net/ipv6/netfilter/ip6t_frag.c47
-rw-r--r--net/ipv6/netfilter/ip6t_rt.c9
-rw-r--r--net/ipv6/netfilter/ip6table_filter.c114
-rw-r--r--net/ipv6/netfilter/ip6table_mangle.c156
-rw-r--r--net/ipv6/netfilter/ip6table_raw.c87
-rw-r--r--net/ipv6/netfilter/ip6table_security.c110
-rw-r--r--net/ipv6/netfilter/nf_conntrack_l3proto_ipv6.c27
-rw-r--r--net/ipv6/netfilter/nf_conntrack_proto_icmpv6.c27
-rw-r--r--net/ipv6/netfilter/nf_conntrack_reasm.c28
-rw-r--r--net/ipv6/proc.c39
-rw-r--r--net/ipv6/raw.c65
-rw-r--r--net/ipv6/reassembly.c59
-rw-r--r--net/ipv6/route.c63
-rw-r--r--net/ipv6/sit.c356
-rw-r--r--net/ipv6/syncookies.c11
-rw-r--r--net/ipv6/sysctl_net_ipv6.c17
-rw-r--r--net/ipv6/tcp_ipv6.c176
-rw-r--r--net/ipv6/tunnel6.c5
-rw-r--r--net/ipv6/udp.c300
-rw-r--r--net/ipv6/udplite.c5
-rw-r--r--net/ipv6/xfrm6_input.c2
-rw-r--r--net/ipv6/xfrm6_mode_tunnel.c1
-rw-r--r--net/ipv6/xfrm6_output.c2
-rw-r--r--net/ipv6/xfrm6_policy.c31
-rw-r--r--net/ipv6/xfrm6_tunnel.c234
-rw-r--r--net/ipx/af_ipx.c62
-rw-r--r--net/ipx/ipx_proc.c90
-rw-r--r--net/ipx/ipx_route.c1
-rw-r--r--net/ipx/sysctl_net_ipx.c7
-rw-r--r--net/irda/af_irda.c341
-rw-r--r--net/irda/discovery.c1
-rw-r--r--net/irda/ircomm/ircomm_core.c1
-rw-r--r--net/irda/ircomm/ircomm_lmp.c1
-rw-r--r--net/irda/ircomm/ircomm_param.c1
-rw-r--r--net/irda/ircomm/ircomm_tty.c7
-rw-r--r--net/irda/irda_device.c1
-rw-r--r--net/irda/iriap.c1
-rw-r--r--net/irda/iriap_event.c2
-rw-r--r--net/irda/irias_object.c1
-rw-r--r--net/irda/irlan/irlan_client.c1
-rw-r--r--net/irda/irlan/irlan_common.c29
-rw-r--r--net/irda/irlan/irlan_eth.c5
-rw-r--r--net/irda/irlan/irlan_provider.c1
-rw-r--r--net/irda/irlap.c14
-rw-r--r--net/irda/irlap_event.c3
-rw-r--r--net/irda/irlap_frame.c1
-rw-r--r--net/irda/irlmp.c4
-rw-r--r--net/irda/irnet/irnet.h1
-rw-r--r--net/irda/irnet/irnet_irda.c5
-rw-r--r--net/irda/irnet/irnet_ppp.c14
-rw-r--r--net/irda/irnetlink.c3
-rw-r--r--net/irda/irqueue.c1
-rw-r--r--net/irda/irsysctl.c31
-rw-r--r--net/irda/irttp.c1
-rw-r--r--net/iucv/af_iucv.c12
-rw-r--r--net/iucv/iucv.c18
-rw-r--r--net/key/af_key.c215
-rw-r--r--net/lapb/lapb_iface.c1
-rw-r--r--net/lapb/lapb_in.c1
-rw-r--r--net/lapb/lapb_out.c1
-rw-r--r--net/lapb/lapb_subr.c1
-rw-r--r--net/llc/af_llc.c74
-rw-r--r--net/llc/llc_c_ac.c3
-rw-r--r--net/llc/llc_conn.c147
-rw-r--r--net/llc/llc_core.c53
-rw-r--r--net/llc/llc_if.c1
-rw-r--r--net/llc/llc_input.c1
-rw-r--r--net/llc/llc_output.c45
-rw-r--r--net/llc/llc_proc.c69
-rw-r--r--net/llc/llc_sap.c114
-rw-r--r--net/llc/llc_station.c1
-rw-r--r--net/llc/sysctl_net_llc.c25
-rw-r--r--net/mac80211/Kconfig25
-rw-r--r--net/mac80211/Makefile6
-rw-r--r--net/mac80211/agg-rx.c22
-rw-r--r--net/mac80211/agg-tx.c133
-rw-r--r--net/mac80211/cfg.c260
-rw-r--r--net/mac80211/debugfs.c202
-rw-r--r--net/mac80211/debugfs.h2
-rw-r--r--net/mac80211/debugfs_key.c47
-rw-r--r--net/mac80211/debugfs_netdev.c391
-rw-r--r--net/mac80211/debugfs_netdev.h9
-rw-r--r--net/mac80211/debugfs_sta.c147
-rw-r--r--net/mac80211/driver-ops.h168
-rw-r--r--net/mac80211/driver-trace.h207
-rw-r--r--net/mac80211/ht.c80
-rw-r--r--net/mac80211/ibss.c139
-rw-r--r--net/mac80211/ieee80211_i.h394
-rw-r--r--net/mac80211/iface.c190
-rw-r--r--net/mac80211/key.c11
-rw-r--r--net/mac80211/key.h20
-rw-r--r--net/mac80211/led.c1
-rw-r--r--net/mac80211/main.c426
-rw-r--r--net/mac80211/mesh.c165
-rw-r--r--net/mac80211/mesh.h35
-rw-r--r--net/mac80211/mesh_hwmp.c426
-rw-r--r--net/mac80211/mesh_pathtbl.c32
-rw-r--r--net/mac80211/mesh_plink.c84
-rw-r--r--net/mac80211/mlme.c1366
-rw-r--r--net/mac80211/offchannel.c170
-rw-r--r--net/mac80211/pm.c18
-rw-r--r--net/mac80211/rate.c113
-rw-r--r--net/mac80211/rate.h28
-rw-r--r--net/mac80211/rc80211_minstrel.c1
-rw-r--r--net/mac80211/rc80211_minstrel_debugfs.c1
-rw-r--r--net/mac80211/rc80211_pid_algo.c11
-rw-r--r--net/mac80211/rc80211_pid_debugfs.c1
-rw-r--r--net/mac80211/rx.c1419
-rw-r--r--net/mac80211/scan.c349
-rw-r--r--net/mac80211/spectmgmt.c6
-rw-r--r--net/mac80211/sta_info.c935
-rw-r--r--net/mac80211/sta_info.h119
-rw-r--r--net/mac80211/status.c388
-rw-r--r--net/mac80211/tkip.c47
-rw-r--r--net/mac80211/tx.c503
-rw-r--r--net/mac80211/util.c363
-rw-r--r--net/mac80211/wep.c26
-rw-r--r--net/mac80211/wme.c96
-rw-r--r--net/mac80211/wme.h8
-rw-r--r--net/mac80211/work.c1101
-rw-r--r--net/mac80211/wpa.c84
-rw-r--r--net/netfilter/Kconfig25
-rw-r--r--net/netfilter/Makefile1
-rw-r--r--net/netfilter/core.c5
-rw-r--r--net/netfilter/ipvs/Kconfig14
-rw-r--r--net/netfilter/ipvs/Makefile1
-rw-r--r--net/netfilter/ipvs/ip_vs_app.c1
-rw-r--r--net/netfilter/ipvs/ip_vs_conn.c43
-rw-r--r--net/netfilter/ipvs/ip_vs_core.c69
-rw-r--r--net/netfilter/ipvs/ip_vs_ctl.c38
-rw-r--r--net/netfilter/ipvs/ip_vs_dh.c1
-rw-r--r--net/netfilter/ipvs/ip_vs_est.c1
-rw-r--r--net/netfilter/ipvs/ip_vs_ftp.c3
-rw-r--r--net/netfilter/ipvs/ip_vs_lblc.c3
-rw-r--r--net/netfilter/ipvs/ip_vs_lblcr.c47
-rw-r--r--net/netfilter/ipvs/ip_vs_proto.c4
-rw-r--r--net/netfilter/ipvs/ip_vs_proto_sctp.c1183
-rw-r--r--net/netfilter/ipvs/ip_vs_sh.c1
-rw-r--r--net/netfilter/ipvs/ip_vs_sync.c14
-rw-r--r--net/netfilter/ipvs/ip_vs_wrr.c16
-rw-r--r--net/netfilter/ipvs/ip_vs_xmit.c11
-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.c274
-rw-r--r--net/netfilter/nf_conntrack_ecache.c3
-rw-r--r--net/netfilter/nf_conntrack_expect.c39
-rw-r--r--net/netfilter/nf_conntrack_extend.c1
-rw-r--r--net/netfilter/nf_conntrack_ftp.c27
-rw-r--r--net/netfilter/nf_conntrack_h323_main.c4
-rw-r--r--net/netfilter/nf_conntrack_helper.c47
-rw-r--r--net/netfilter/nf_conntrack_irc.c1
-rw-r--r--net/netfilter/nf_conntrack_netlink.c236
-rw-r--r--net/netfilter/nf_conntrack_pptp.c14
-rw-r--r--net/netfilter/nf_conntrack_proto.c1
-rw-r--r--net/netfilter/nf_conntrack_proto_dccp.c51
-rw-r--r--net/netfilter/nf_conntrack_proto_generic.c8
-rw-r--r--net/netfilter/nf_conntrack_proto_gre.c25
-rw-r--r--net/netfilter/nf_conntrack_proto_sctp.c10
-rw-r--r--net/netfilter/nf_conntrack_proto_tcp.c69
-rw-r--r--net/netfilter/nf_conntrack_proto_udp.c14
-rw-r--r--net/netfilter/nf_conntrack_proto_udplite.c10
-rw-r--r--net/netfilter/nf_conntrack_sane.c1
-rw-r--r--net/netfilter/nf_conntrack_sip.c336
-rw-r--r--net/netfilter/nf_conntrack_standalone.c28
-rw-r--r--net/netfilter/nf_log.c7
-rw-r--r--net/netfilter/nf_queue.c3
-rw-r--r--net/netfilter/nfnetlink.c65
-rw-r--r--net/netfilter/nfnetlink_log.c11
-rw-r--r--net/netfilter/nfnetlink_queue.c11
-rw-r--r--net/netfilter/x_tables.c81
-rw-r--r--net/netfilter/xt_CT.c165
-rw-r--r--net/netfilter/xt_LED.c1
-rw-r--r--net/netfilter/xt_NFQUEUE.c6
-rw-r--r--net/netfilter/xt_RATEEST.c8
-rw-r--r--net/netfilter/xt_TCPMSS.c31
-rw-r--r--net/netfilter/xt_connlimit.c28
-rw-r--r--net/netfilter/xt_conntrack.c61
-rw-r--r--net/netfilter/xt_dccp.c1
-rw-r--r--net/netfilter/xt_hashlimit.c221
-rw-r--r--net/netfilter/xt_limit.c5
-rw-r--r--net/netfilter/xt_osf.c4
-rw-r--r--net/netfilter/xt_quota.c1
-rw-r--r--net/netfilter/xt_recent.c172
-rw-r--r--net/netfilter/xt_repldata.h35
-rw-r--r--net/netfilter/xt_socket.c8
-rw-r--r--net/netfilter/xt_statistic.c1
-rw-r--r--net/netfilter/xt_string.c1
-rw-r--r--net/netlabel/netlabel_cipso_v4.c1
-rw-r--r--net/netlabel/netlabel_domainhash.c32
-rw-r--r--net/netlabel/netlabel_kapi.c1
-rw-r--r--net/netlabel/netlabel_mgmt.c1
-rw-r--r--net/netlabel/netlabel_unlabeled.c76
-rw-r--r--net/netlabel/netlabel_user.c1
-rw-r--r--net/netlink/af_netlink.c43
-rw-r--r--net/netlink/genetlink.c37
-rw-r--r--net/netrom/af_netrom.c29
-rw-r--r--net/netrom/nr_dev.c1
-rw-r--r--net/netrom/nr_in.c1
-rw-r--r--net/netrom/nr_loopback.c1
-rw-r--r--net/netrom/nr_out.c1
-rw-r--r--net/netrom/nr_route.c80
-rw-r--r--net/netrom/nr_subr.c1
-rw-r--r--net/netrom/sysctl_net_netrom.c30
-rw-r--r--net/packet/Kconfig10
-rw-r--r--net/packet/af_packet.c466
-rw-r--r--net/phonet/af_phonet.c84
-rw-r--r--net/phonet/datagram.c13
-rw-r--r--net/phonet/pep-gprs.c4
-rw-r--r--net/phonet/pep.c65
-rw-r--r--net/phonet/pn_dev.c227
-rw-r--r--net/phonet/pn_netlink.c142
-rw-r--r--net/phonet/socket.c83
-rw-r--r--net/phonet/sysctl.c8
-rw-r--r--net/rds/af_rds.c17
-rw-r--r--net/rds/cong.c3
-rw-r--r--net/rds/connection.c7
-rw-r--r--net/rds/ib.c5
-rw-r--r--net/rds/ib.h2
-rw-r--r--net/rds/ib_cm.c7
-rw-r--r--net/rds/ib_rdma.c10
-rw-r--r--net/rds/ib_recv.c48
-rw-r--r--net/rds/ib_send.c4
-rw-r--r--net/rds/ib_sysctl.c26
-rw-r--r--net/rds/info.c1
-rw-r--r--net/rds/iw.c5
-rw-r--r--net/rds/iw.h2
-rw-r--r--net/rds/iw_cm.c3
-rw-r--r--net/rds/iw_rdma.c10
-rw-r--r--net/rds/iw_recv.c48
-rw-r--r--net/rds/iw_send.c7
-rw-r--r--net/rds/iw_sysctl.c26
-rw-r--r--net/rds/loop.c1
-rw-r--r--net/rds/message.c4
-rw-r--r--net/rds/page.c1
-rw-r--r--net/rds/rdma.c37
-rw-r--r--net/rds/rdma.h1
-rw-r--r--net/rds/rdma_transport.c2
-rw-r--r--net/rds/recv.c12
-rw-r--r--net/rds/send.c28
-rw-r--r--net/rds/sysctl.c21
-rw-r--r--net/rds/tcp.c1
-rw-r--r--net/rds/tcp_connect.c7
-rw-r--r--net/rds/tcp_listen.c11
-rw-r--r--net/rds/tcp_recv.c1
-rw-r--r--net/rds/tcp_send.c4
-rw-r--r--net/rds/threads.c4
-rw-r--r--net/rfkill/core.c7
-rw-r--r--net/rfkill/input.c8
-rw-r--r--net/rose/af_rose.c30
-rw-r--r--net/rose/rose_dev.c1
-rw-r--r--net/rose/rose_link.c9
-rw-r--r--net/rose/rose_loopback.c3
-rw-r--r--net/rose/rose_out.c1
-rw-r--r--net/rose/rose_route.c34
-rw-r--r--net/rose/rose_subr.c1
-rw-r--r--net/rose/sysctl_net_rose.c26
-rw-r--r--net/rxrpc/af_rxrpc.c8
-rw-r--r--net/rxrpc/ar-accept.c7
-rw-r--r--net/rxrpc/ar-ack.c1
-rw-r--r--net/rxrpc/ar-call.c1
-rw-r--r--net/rxrpc/ar-connection.c1
-rw-r--r--net/rxrpc/ar-input.c1
-rw-r--r--net/rxrpc/ar-key.c1
-rw-r--r--net/rxrpc/ar-local.c1
-rw-r--r--net/rxrpc/ar-output.c1
-rw-r--r--net/rxrpc/ar-peer.c1
-rw-r--r--net/rxrpc/ar-recvmsg.c2
-rw-r--r--net/rxrpc/ar-transport.c1
-rw-r--r--net/rxrpc/rxkad.c1
-rw-r--r--net/sched/Kconfig21
-rw-r--r--net/sched/act_api.c10
-rw-r--r--net/sched/act_ipt.c1
-rw-r--r--net/sched/act_mirred.c108
-rw-r--r--net/sched/act_pedit.c1
-rw-r--r--net/sched/act_police.c1
-rw-r--r--net/sched/act_simple.c1
-rw-r--r--net/sched/act_skbedit.c17
-rw-r--r--net/sched/cls_api.c9
-rw-r--r--net/sched/cls_basic.c1
-rw-r--r--net/sched/cls_cgroup.c37
-rw-r--r--net/sched/cls_flow.c3
-rw-r--r--net/sched/cls_fw.c1
-rw-r--r--net/sched/cls_route.c1
-rw-r--r--net/sched/cls_rsvp.h28
-rw-r--r--net/sched/cls_tcindex.c1
-rw-r--r--net/sched/cls_u32.c1
-rw-r--r--net/sched/em_meta.c14
-rw-r--r--net/sched/em_nbyte.c1
-rw-r--r--net/sched/em_text.c1
-rw-r--r--net/sched/ematch.c1
-rw-r--r--net/sched/sch_api.c21
-rw-r--r--net/sched/sch_atm.c1
-rw-r--r--net/sched/sch_cbq.c3
-rw-r--r--net/sched/sch_drr.c3
-rw-r--r--net/sched/sch_dsmark.c1
-rw-r--r--net/sched/sch_fifo.c35
-rw-r--r--net/sched/sch_generic.c19
-rw-r--r--net/sched/sch_gred.c1
-rw-r--r--net/sched/sch_hfsc.c2
-rw-r--r--net/sched/sch_htb.c7
-rw-r--r--net/sched/sch_mq.c1
-rw-r--r--net/sched/sch_multiq.c1
-rw-r--r--net/sched/sch_netem.c13
-rw-r--r--net/sched/sch_prio.c1
-rw-r--r--net/sched/sch_sfq.c1
-rw-r--r--net/sched/sch_teql.c12
-rw-r--r--net/sctp/associola.c33
-rw-r--r--net/sctp/auth.c1
-rw-r--r--net/sctp/bind_addr.c2
-rw-r--r--net/sctp/chunk.c16
-rw-r--r--net/sctp/endpointola.c1
-rw-r--r--net/sctp/input.c65
-rw-r--r--net/sctp/inqueue.c1
-rw-r--r--net/sctp/ipv6.c23
-rw-r--r--net/sctp/output.c49
-rw-r--r--net/sctp/outqueue.c27
-rw-r--r--net/sctp/primitive.c1
-rw-r--r--net/sctp/proc.c4
-rw-r--r--net/sctp/protocol.c26
-rw-r--r--net/sctp/sm_make_chunk.c108
-rw-r--r--net/sctp/sm_sideeffect.c71
-rw-r--r--net/sctp/sm_statefuns.c37
-rw-r--r--net/sctp/socket.c390
-rw-r--r--net/sctp/ssnmap.c1
-rw-r--r--net/sctp/sysctl.c62
-rw-r--r--net/sctp/transport.c52
-rw-r--r--net/sctp/tsnmap.c1
-rw-r--r--net/sctp/ulpevent.c1
-rw-r--r--net/sctp/ulpqueue.c1
-rw-r--r--net/socket.c973
-rw-r--r--net/sunrpc/addr.c19
-rw-r--r--net/sunrpc/auth.c47
-rw-r--r--net/sunrpc/auth_generic.c1
-rw-r--r--net/sunrpc/auth_gss/auth_gss.c39
-rw-r--r--net/sunrpc/auth_gss/gss_generic_token.c1
-rw-r--r--net/sunrpc/auth_gss/gss_krb5_crypto.c1
-rw-r--r--net/sunrpc/auth_gss/gss_krb5_mech.c4
-rw-r--r--net/sunrpc/auth_gss/gss_krb5_seal.c1
-rw-r--r--net/sunrpc/auth_gss/gss_krb5_seqnum.c5
-rw-r--r--net/sunrpc/auth_gss/gss_krb5_unseal.c1
-rw-r--r--net/sunrpc/auth_gss/gss_krb5_wrap.c1
-rw-r--r--net/sunrpc/auth_gss/gss_mech_switch.c2
-rw-r--r--net/sunrpc/auth_gss/gss_spkm3_seal.c1
-rw-r--r--net/sunrpc/auth_gss/svcauth_gss.c5
-rw-r--r--net/sunrpc/auth_unix.c1
-rw-r--r--net/sunrpc/backchannel_rqst.c1
-rw-r--r--net/sunrpc/bc_svc.c15
-rw-r--r--net/sunrpc/cache.c5
-rw-r--r--net/sunrpc/clnt.c55
-rw-r--r--net/sunrpc/rpc_pipe.c13
-rw-r--r--net/sunrpc/rpcb_clnt.c105
-rw-r--r--net/sunrpc/sched.c15
-rw-r--r--net/sunrpc/socklib.c1
-rw-r--r--net/sunrpc/stats.c1
-rw-r--r--net/sunrpc/sunrpc_syms.c3
-rw-r--r--net/sunrpc/svc.c12
-rw-r--r--net/sunrpc/svc_xprt.c66
-rw-r--r--net/sunrpc/svcauth.c4
-rw-r--r--net/sunrpc/svcauth_unix.c110
-rw-r--r--net/sunrpc/svcsock.c11
-rw-r--r--net/sunrpc/sysctl.c15
-rw-r--r--net/sunrpc/xdr.c1
-rw-r--r--net/sunrpc/xprt.c26
-rw-r--r--net/sunrpc/xprtrdma/svc_rdma.c41
-rw-r--r--net/sunrpc/xprtrdma/svc_rdma_recvfrom.c7
-rw-r--r--net/sunrpc/xprtrdma/svc_rdma_sendto.c2
-rw-r--r--net/sunrpc/xprtrdma/svc_rdma_transport.c6
-rw-r--r--net/sunrpc/xprtrdma/transport.c40
-rw-r--r--net/sunrpc/xprtrdma/verbs.c5
-rw-r--r--net/sunrpc/xprtsock.c59
-rw-r--r--net/sysctl_net.c4
-rw-r--r--net/tipc/Kconfig75
-rw-r--r--net/tipc/bearer.c37
-rw-r--r--net/tipc/bearer.h2
-rw-r--r--net/tipc/cluster.c16
-rw-r--r--net/tipc/core.c10
-rw-r--r--net/tipc/core.h1
-rw-r--r--net/tipc/eth_media.c1
-rw-r--r--net/tipc/link.c21
-rw-r--r--net/tipc/net.c25
-rw-r--r--net/tipc/ref.c26
-rw-r--r--net/tipc/socket.c28
-rw-r--r--net/tipc/subscr.c63
-rw-r--r--net/tipc/subscr.h2
-rw-r--r--net/unix/af_unix.c21
-rw-r--r--net/unix/garbage.c1
-rw-r--r--net/unix/sysctl_net_unix.c10
-rw-r--r--net/wimax/op-msg.c6
-rw-r--r--net/wimax/op-reset.c5
-rw-r--r--net/wimax/op-rfkill.c21
-rw-r--r--net/wimax/op-state-get.c3
-rw-r--r--net/wimax/stack.c15
-rw-r--r--net/wireless/.gitignore1
-rw-r--r--net/wireless/Kconfig57
-rw-r--r--net/wireless/Makefile16
-rw-r--r--net/wireless/chan.c41
-rw-r--r--net/wireless/core.c114
-rw-r--r--net/wireless/core.h35
-rw-r--r--net/wireless/db.txt17
-rw-r--r--net/wireless/debugfs.c16
-rw-r--r--net/wireless/debugfs.h3
-rw-r--r--net/wireless/ethtool.c45
-rw-r--r--net/wireless/ethtool.h6
-rw-r--r--net/wireless/genregdb.awk118
-rw-r--r--net/wireless/ibss.c17
-rw-r--r--net/wireless/lib80211_crypt_ccmp.c2
-rw-r--r--net/wireless/lib80211_crypt_tkip.c23
-rw-r--r--net/wireless/mlme.c331
-rw-r--r--net/wireless/nl80211.c1271
-rw-r--r--net/wireless/nl80211.h23
-rw-r--r--net/wireless/radiotap.c305
-rw-r--r--net/wireless/reg.c732
-rw-r--r--net/wireless/reg.h29
-rw-r--r--net/wireless/regdb.h7
-rw-r--r--net/wireless/scan.c230
-rw-r--r--net/wireless/sme.c61
-rw-r--r--net/wireless/sysfs.c20
-rw-r--r--net/wireless/util.c178
-rw-r--r--net/wireless/wext-compat.c148
-rw-r--r--net/wireless/wext-core.c (renamed from net/wireless/wext.c)1465
-rw-r--r--net/wireless/wext-priv.c249
-rw-r--r--net/wireless/wext-proc.c155
-rw-r--r--net/wireless/wext-sme.c1
-rw-r--r--net/wireless/wext-spy.c231
-rw-r--r--net/x25/af_x25.c206
-rw-r--r--net/x25/sysctl_net_x25.c15
-rw-r--r--net/x25/x25_dev.c3
-rw-r--r--net/x25/x25_facilities.c27
-rw-r--r--net/x25/x25_forward.c1
-rw-r--r--net/x25/x25_in.c18
-rw-r--r--net/x25/x25_link.c1
-rw-r--r--net/x25/x25_out.c1
-rw-r--r--net/x25/x25_proc.c114
-rw-r--r--net/x25/x25_route.c7
-rw-r--r--net/x25/x25_subr.c7
-rw-r--r--net/xfrm/xfrm_algo.c129
-rw-r--r--net/xfrm/xfrm_input.c2
-rw-r--r--net/xfrm/xfrm_ipcomp.c18
-rw-r--r--net/xfrm/xfrm_output.c1
-rw-r--r--net/xfrm/xfrm_policy.c127
-rw-r--r--net/xfrm/xfrm_proc.c6
-rw-r--r--net/xfrm/xfrm_state.c139
-rw-r--r--net/xfrm/xfrm_sysctl.c9
-rw-r--r--net/xfrm/xfrm_user.c272
744 files changed, 35080 insertions, 19738 deletions
diff --git a/net/802/garp.c b/net/802/garp.c
index 1dcb0660c49d..9ed7c0e7dc17 100644
--- a/net/802/garp.c
+++ b/net/802/garp.c
@@ -14,6 +14,7 @@
14#include <linux/etherdevice.h> 14#include <linux/etherdevice.h>
15#include <linux/rtnetlink.h> 15#include <linux/rtnetlink.h>
16#include <linux/llc.h> 16#include <linux/llc.h>
17#include <linux/slab.h>
17#include <net/llc.h> 18#include <net/llc.h>
18#include <net/llc_pdu.h> 19#include <net/llc_pdu.h>
19#include <net/garp.h> 20#include <net/garp.h>
diff --git a/net/802/p8022.c b/net/802/p8022.c
index 2530f35241cd..7f353c4f437a 100644
--- a/net/802/p8022.c
+++ b/net/802/p8022.c
@@ -18,6 +18,7 @@
18#include <linux/module.h> 18#include <linux/module.h>
19#include <linux/netdevice.h> 19#include <linux/netdevice.h>
20#include <linux/skbuff.h> 20#include <linux/skbuff.h>
21#include <linux/slab.h>
21#include <net/datalink.h> 22#include <net/datalink.h>
22#include <linux/mm.h> 23#include <linux/mm.h>
23#include <linux/in.h> 24#include <linux/in.h>
diff --git a/net/802/p8023.c b/net/802/p8023.c
index 6ab1835041a7..1256a40da43c 100644
--- a/net/802/p8023.c
+++ b/net/802/p8023.c
@@ -18,6 +18,7 @@
18#include <linux/module.h> 18#include <linux/module.h>
19#include <linux/netdevice.h> 19#include <linux/netdevice.h>
20#include <linux/skbuff.h> 20#include <linux/skbuff.h>
21#include <linux/slab.h>
21 22
22#include <net/datalink.h> 23#include <net/datalink.h>
23#include <net/p8022.h> 24#include <net/p8022.h>
diff --git a/net/802/psnap.c b/net/802/psnap.c
index 6fea0750662b..21cde8fd5795 100644
--- a/net/802/psnap.c
+++ b/net/802/psnap.c
@@ -14,6 +14,7 @@
14#include <linux/module.h> 14#include <linux/module.h>
15#include <linux/netdevice.h> 15#include <linux/netdevice.h>
16#include <linux/skbuff.h> 16#include <linux/skbuff.h>
17#include <linux/slab.h>
17#include <net/datalink.h> 18#include <net/datalink.h>
18#include <net/llc.h> 19#include <net/llc.h>
19#include <net/psnap.h> 20#include <net/psnap.h>
diff --git a/net/802/stp.c b/net/802/stp.c
index 0b7a24452d11..53c8f77f0ccd 100644
--- a/net/802/stp.c
+++ b/net/802/stp.c
@@ -11,6 +11,7 @@
11#include <linux/skbuff.h> 11#include <linux/skbuff.h>
12#include <linux/etherdevice.h> 12#include <linux/etherdevice.h>
13#include <linux/llc.h> 13#include <linux/llc.h>
14#include <linux/slab.h>
14#include <net/llc.h> 15#include <net/llc.h>
15#include <net/llc_pdu.h> 16#include <net/llc_pdu.h>
16#include <net/stp.h> 17#include <net/stp.h>
diff --git a/net/802/tr.c b/net/802/tr.c
index e874447ad144..1c6e596074df 100644
--- a/net/802/tr.c
+++ b/net/802/tr.c
@@ -36,6 +36,7 @@
36#include <linux/seq_file.h> 36#include <linux/seq_file.h>
37#include <linux/init.h> 37#include <linux/init.h>
38#include <linux/sysctl.h> 38#include <linux/sysctl.h>
39#include <linux/slab.h>
39#include <net/arp.h> 40#include <net/arp.h>
40#include <net/net_namespace.h> 41#include <net/net_namespace.h>
41 42
@@ -635,19 +636,18 @@ struct net_device *alloc_trdev(int sizeof_priv)
635#ifdef CONFIG_SYSCTL 636#ifdef CONFIG_SYSCTL
636static struct ctl_table tr_table[] = { 637static struct ctl_table tr_table[] = {
637 { 638 {
638 .ctl_name = NET_TR_RIF_TIMEOUT,
639 .procname = "rif_timeout", 639 .procname = "rif_timeout",
640 .data = &sysctl_tr_rif_timeout, 640 .data = &sysctl_tr_rif_timeout,
641 .maxlen = sizeof(int), 641 .maxlen = sizeof(int),
642 .mode = 0644, 642 .mode = 0644,
643 .proc_handler = proc_dointvec 643 .proc_handler = proc_dointvec
644 }, 644 },
645 { 0 }, 645 { },
646}; 646};
647 647
648static __initdata struct ctl_path tr_path[] = { 648static __initdata struct ctl_path tr_path[] = {
649 { .procname = "net", .ctl_name = CTL_NET, }, 649 { .procname = "net", },
650 { .procname = "token-ring", .ctl_name = NET_TR, }, 650 { .procname = "token-ring", },
651 { } 651 { }
652}; 652};
653#endif 653#endif
diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
index a29c5ab5815c..97da977c2a23 100644
--- a/net/8021q/vlan.c
+++ b/net/8021q/vlan.c
@@ -22,6 +22,7 @@
22#include <linux/module.h> 22#include <linux/module.h>
23#include <linux/netdevice.h> 23#include <linux/netdevice.h>
24#include <linux/skbuff.h> 24#include <linux/skbuff.h>
25#include <linux/slab.h>
25#include <linux/init.h> 26#include <linux/init.h>
26#include <linux/rculist.h> 27#include <linux/rculist.h>
27#include <net/p8022.h> 28#include <net/p8022.h>
@@ -41,7 +42,7 @@
41 42
42/* Global VLAN variables */ 43/* Global VLAN variables */
43 44
44int vlan_net_id; 45int vlan_net_id __read_mostly;
45 46
46/* Our listing of VLAN group(s) */ 47/* Our listing of VLAN group(s) */
47static struct hlist_head vlan_group_hash[VLAN_GRP_HASH_SIZE]; 48static struct hlist_head vlan_group_hash[VLAN_GRP_HASH_SIZE];
@@ -140,7 +141,7 @@ static void vlan_rcu_free(struct rcu_head *rcu)
140 vlan_group_free(container_of(rcu, struct vlan_group, rcu)); 141 vlan_group_free(container_of(rcu, struct vlan_group, rcu));
141} 142}
142 143
143void unregister_vlan_dev(struct net_device *dev) 144void unregister_vlan_dev(struct net_device *dev, struct list_head *head)
144{ 145{
145 struct vlan_dev_info *vlan = vlan_dev_info(dev); 146 struct vlan_dev_info *vlan = vlan_dev_info(dev);
146 struct net_device *real_dev = vlan->real_dev; 147 struct net_device *real_dev = vlan->real_dev;
@@ -159,12 +160,13 @@ void unregister_vlan_dev(struct net_device *dev)
159 if (real_dev->features & NETIF_F_HW_VLAN_FILTER) 160 if (real_dev->features & NETIF_F_HW_VLAN_FILTER)
160 ops->ndo_vlan_rx_kill_vid(real_dev, vlan_id); 161 ops->ndo_vlan_rx_kill_vid(real_dev, vlan_id);
161 162
162 vlan_group_set_device(grp, vlan_id, NULL);
163 grp->nr_vlans--; 163 grp->nr_vlans--;
164 164
165 synchronize_net(); 165 vlan_group_set_device(grp, vlan_id, NULL);
166 if (!grp->killall)
167 synchronize_net();
166 168
167 unregister_netdevice(dev); 169 unregister_netdevice_queue(dev, head);
168 170
169 /* If the group is now empty, kill off the group. */ 171 /* If the group is now empty, kill off the group. */
170 if (grp->nr_vlans == 0) { 172 if (grp->nr_vlans == 0) {
@@ -183,27 +185,6 @@ void unregister_vlan_dev(struct net_device *dev)
183 dev_put(real_dev); 185 dev_put(real_dev);
184} 186}
185 187
186static void vlan_transfer_operstate(const struct net_device *dev,
187 struct net_device *vlandev)
188{
189 /* Have to respect userspace enforced dormant state
190 * of real device, also must allow supplicant running
191 * on VLAN device
192 */
193 if (dev->operstate == IF_OPER_DORMANT)
194 netif_dormant_on(vlandev);
195 else
196 netif_dormant_off(vlandev);
197
198 if (netif_carrier_ok(dev)) {
199 if (!netif_carrier_ok(vlandev))
200 netif_carrier_on(vlandev);
201 } else {
202 if (netif_carrier_ok(vlandev))
203 netif_carrier_off(vlandev);
204 }
205}
206
207int vlan_check_real_dev(struct net_device *real_dev, u16 vlan_id) 188int vlan_check_real_dev(struct net_device *real_dev, u16 vlan_id)
208{ 189{
209 const char *name = real_dev->name; 190 const char *name = real_dev->name;
@@ -261,7 +242,7 @@ int register_vlan_dev(struct net_device *dev)
261 /* Account for reference in struct vlan_dev_info */ 242 /* Account for reference in struct vlan_dev_info */
262 dev_hold(real_dev); 243 dev_hold(real_dev);
263 244
264 vlan_transfer_operstate(real_dev, dev); 245 netif_stacked_transfer_operstate(real_dev, dev);
265 linkwatch_fire_event(dev); /* _MUST_ call rfc2863_policy() */ 246 linkwatch_fire_event(dev); /* _MUST_ call rfc2863_policy() */
266 247
267 /* So, got the sucker initialized, now lets place 248 /* So, got the sucker initialized, now lets place
@@ -398,6 +379,8 @@ static void vlan_transfer_features(struct net_device *dev,
398#if defined(CONFIG_FCOE) || defined(CONFIG_FCOE_MODULE) 379#if defined(CONFIG_FCOE) || defined(CONFIG_FCOE_MODULE)
399 vlandev->fcoe_ddp_xid = dev->fcoe_ddp_xid; 380 vlandev->fcoe_ddp_xid = dev->fcoe_ddp_xid;
400#endif 381#endif
382 vlandev->real_num_tx_queues = dev->real_num_tx_queues;
383 BUG_ON(vlandev->real_num_tx_queues > vlandev->num_tx_queues);
401 384
402 if (old_features != vlandev->features) 385 if (old_features != vlandev->features)
403 netdev_features_change(vlandev); 386 netdev_features_change(vlandev);
@@ -430,6 +413,8 @@ static int vlan_device_event(struct notifier_block *unused, unsigned long event,
430 struct vlan_group *grp; 413 struct vlan_group *grp;
431 int i, flgs; 414 int i, flgs;
432 struct net_device *vlandev; 415 struct net_device *vlandev;
416 struct vlan_dev_info *vlan;
417 LIST_HEAD(list);
433 418
434 if (is_vlan_dev(dev)) 419 if (is_vlan_dev(dev))
435 __vlan_device_event(dev, event); 420 __vlan_device_event(dev, event);
@@ -450,7 +435,7 @@ static int vlan_device_event(struct notifier_block *unused, unsigned long event,
450 if (!vlandev) 435 if (!vlandev)
451 continue; 436 continue;
452 437
453 vlan_transfer_operstate(dev, vlandev); 438 netif_stacked_transfer_operstate(dev, vlandev);
454 } 439 }
455 break; 440 break;
456 441
@@ -505,8 +490,10 @@ static int vlan_device_event(struct notifier_block *unused, unsigned long event,
505 if (!(flgs & IFF_UP)) 490 if (!(flgs & IFF_UP))
506 continue; 491 continue;
507 492
508 dev_change_flags(vlandev, flgs & ~IFF_UP); 493 vlan = vlan_dev_info(vlandev);
509 vlan_transfer_operstate(dev, vlandev); 494 if (!(vlan->flags & VLAN_FLAG_LOOSE_BINDING))
495 dev_change_flags(vlandev, flgs & ~IFF_UP);
496 netif_stacked_transfer_operstate(dev, vlandev);
510 } 497 }
511 break; 498 break;
512 499
@@ -521,13 +508,17 @@ static int vlan_device_event(struct notifier_block *unused, unsigned long event,
521 if (flgs & IFF_UP) 508 if (flgs & IFF_UP)
522 continue; 509 continue;
523 510
524 dev_change_flags(vlandev, flgs | IFF_UP); 511 vlan = vlan_dev_info(vlandev);
525 vlan_transfer_operstate(dev, vlandev); 512 if (!(vlan->flags & VLAN_FLAG_LOOSE_BINDING))
513 dev_change_flags(vlandev, flgs | IFF_UP);
514 netif_stacked_transfer_operstate(dev, vlandev);
526 } 515 }
527 break; 516 break;
528 517
529 case NETDEV_UNREGISTER: 518 case NETDEV_UNREGISTER:
530 /* Delete all VLANs for this dev. */ 519 /* Delete all VLANs for this dev. */
520 grp->killall = 1;
521
531 for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) { 522 for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) {
532 vlandev = vlan_group_get_device(grp, i); 523 vlandev = vlan_group_get_device(grp, i);
533 if (!vlandev) 524 if (!vlandev)
@@ -538,8 +529,9 @@ static int vlan_device_event(struct notifier_block *unused, unsigned long event,
538 if (grp->nr_vlans == 1) 529 if (grp->nr_vlans == 1)
539 i = VLAN_GROUP_ARRAY_LEN; 530 i = VLAN_GROUP_ARRAY_LEN;
540 531
541 unregister_vlan_dev(vlandev); 532 unregister_vlan_dev(vlandev, &list);
542 } 533 }
534 unregister_netdevice_many(&list);
543 break; 535 break;
544 } 536 }
545 537
@@ -645,7 +637,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
645 err = -EPERM; 637 err = -EPERM;
646 if (!capable(CAP_NET_ADMIN)) 638 if (!capable(CAP_NET_ADMIN))
647 break; 639 break;
648 unregister_vlan_dev(dev); 640 unregister_vlan_dev(dev, NULL);
649 err = 0; 641 err = 0;
650 break; 642 break;
651 643
@@ -674,49 +666,28 @@ out:
674 return err; 666 return err;
675} 667}
676 668
677static int vlan_init_net(struct net *net) 669static int __net_init vlan_init_net(struct net *net)
678{ 670{
671 struct vlan_net *vn = net_generic(net, vlan_net_id);
679 int err; 672 int err;
680 struct vlan_net *vn;
681
682 err = -ENOMEM;
683 vn = kzalloc(sizeof(struct vlan_net), GFP_KERNEL);
684 if (vn == NULL)
685 goto err_alloc;
686
687 err = net_assign_generic(net, vlan_net_id, vn);
688 if (err < 0)
689 goto err_assign;
690 673
691 vn->name_type = VLAN_NAME_TYPE_RAW_PLUS_VID_NO_PAD; 674 vn->name_type = VLAN_NAME_TYPE_RAW_PLUS_VID_NO_PAD;
692 675
693 err = vlan_proc_init(net); 676 err = vlan_proc_init(net);
694 if (err < 0)
695 goto err_proc;
696
697 return 0;
698 677
699err_proc:
700 /* nothing */
701err_assign:
702 kfree(vn);
703err_alloc:
704 return err; 678 return err;
705} 679}
706 680
707static void vlan_exit_net(struct net *net) 681static void __net_exit vlan_exit_net(struct net *net)
708{ 682{
709 struct vlan_net *vn;
710
711 vn = net_generic(net, vlan_net_id);
712 rtnl_kill_links(net, &vlan_link_ops);
713 vlan_proc_cleanup(net); 683 vlan_proc_cleanup(net);
714 kfree(vn);
715} 684}
716 685
717static struct pernet_operations vlan_net_ops = { 686static struct pernet_operations vlan_net_ops = {
718 .init = vlan_init_net, 687 .init = vlan_init_net,
719 .exit = vlan_exit_net, 688 .exit = vlan_exit_net,
689 .id = &vlan_net_id,
690 .size = sizeof(struct vlan_net),
720}; 691};
721 692
722static int __init vlan_proto_init(void) 693static int __init vlan_proto_init(void)
@@ -726,7 +697,7 @@ static int __init vlan_proto_init(void)
726 pr_info("%s v%s %s\n", vlan_fullname, vlan_version, vlan_copyright); 697 pr_info("%s v%s %s\n", vlan_fullname, vlan_version, vlan_copyright);
727 pr_info("All bugs added by %s\n", vlan_buggyright); 698 pr_info("All bugs added by %s\n", vlan_buggyright);
728 699
729 err = register_pernet_gen_device(&vlan_net_id, &vlan_net_ops); 700 err = register_pernet_subsys(&vlan_net_ops);
730 if (err < 0) 701 if (err < 0)
731 goto err0; 702 goto err0;
732 703
@@ -751,7 +722,7 @@ err4:
751err3: 722err3:
752 unregister_netdevice_notifier(&vlan_notifier_block); 723 unregister_netdevice_notifier(&vlan_notifier_block);
753err2: 724err2:
754 unregister_pernet_gen_device(vlan_net_id, &vlan_net_ops); 725 unregister_pernet_subsys(&vlan_net_ops);
755err0: 726err0:
756 return err; 727 return err;
757} 728}
@@ -771,7 +742,7 @@ static void __exit vlan_cleanup_module(void)
771 for (i = 0; i < VLAN_GRP_HASH_SIZE; i++) 742 for (i = 0; i < VLAN_GRP_HASH_SIZE; i++)
772 BUG_ON(!hlist_empty(&vlan_group_hash[i])); 743 BUG_ON(!hlist_empty(&vlan_group_hash[i]));
773 744
774 unregister_pernet_gen_device(vlan_net_id, &vlan_net_ops); 745 unregister_pernet_subsys(&vlan_net_ops);
775 rcu_barrier(); /* Wait for completion of call_rcu()'s */ 746 rcu_barrier(); /* Wait for completion of call_rcu()'s */
776 747
777 vlan_gvrp_uninit(); 748 vlan_gvrp_uninit();
diff --git a/net/8021q/vlan.h b/net/8021q/vlan.h
index 82570bc2a180..6abdcac1b2e8 100644
--- a/net/8021q/vlan.h
+++ b/net/8021q/vlan.h
@@ -16,6 +16,21 @@ struct vlan_priority_tci_mapping {
16 struct vlan_priority_tci_mapping *next; 16 struct vlan_priority_tci_mapping *next;
17}; 17};
18 18
19
20/**
21 * struct vlan_rx_stats - VLAN percpu rx stats
22 * @rx_packets: number of received packets
23 * @rx_bytes: number of received bytes
24 * @multicast: number of received multicast packets
25 * @rx_errors: number of errors
26 */
27struct vlan_rx_stats {
28 unsigned long rx_packets;
29 unsigned long rx_bytes;
30 unsigned long multicast;
31 unsigned long rx_errors;
32};
33
19/** 34/**
20 * struct vlan_dev_info - VLAN private device data 35 * struct vlan_dev_info - VLAN private device data
21 * @nr_ingress_mappings: number of ingress priority mappings 36 * @nr_ingress_mappings: number of ingress priority mappings
@@ -29,6 +44,7 @@ struct vlan_priority_tci_mapping {
29 * @dent: proc dir entry 44 * @dent: proc dir entry
30 * @cnt_inc_headroom_on_tx: statistic - number of skb expansions on TX 45 * @cnt_inc_headroom_on_tx: statistic - number of skb expansions on TX
31 * @cnt_encap_on_xmit: statistic - number of skb encapsulations on TX 46 * @cnt_encap_on_xmit: statistic - number of skb encapsulations on TX
47 * @vlan_rx_stats: ptr to percpu rx stats
32 */ 48 */
33struct vlan_dev_info { 49struct vlan_dev_info {
34 unsigned int nr_ingress_mappings; 50 unsigned int nr_ingress_mappings;
@@ -45,6 +61,7 @@ struct vlan_dev_info {
45 struct proc_dir_entry *dent; 61 struct proc_dir_entry *dent;
46 unsigned long cnt_inc_headroom_on_tx; 62 unsigned long cnt_inc_headroom_on_tx;
47 unsigned long cnt_encap_on_xmit; 63 unsigned long cnt_encap_on_xmit;
64 struct vlan_rx_stats __percpu *vlan_rx_stats;
48}; 65};
49 66
50static inline struct vlan_dev_info *vlan_dev_info(const struct net_device *dev) 67static inline struct vlan_dev_info *vlan_dev_info(const struct net_device *dev)
@@ -82,14 +99,14 @@ void vlan_dev_get_realdev_name(const struct net_device *dev, char *result);
82int vlan_check_real_dev(struct net_device *real_dev, u16 vlan_id); 99int vlan_check_real_dev(struct net_device *real_dev, u16 vlan_id);
83void vlan_setup(struct net_device *dev); 100void vlan_setup(struct net_device *dev);
84int register_vlan_dev(struct net_device *dev); 101int register_vlan_dev(struct net_device *dev);
85void unregister_vlan_dev(struct net_device *dev); 102void unregister_vlan_dev(struct net_device *dev, struct list_head *head);
86 103
87static inline u32 vlan_get_ingress_priority(struct net_device *dev, 104static inline u32 vlan_get_ingress_priority(struct net_device *dev,
88 u16 vlan_tci) 105 u16 vlan_tci)
89{ 106{
90 struct vlan_dev_info *vip = vlan_dev_info(dev); 107 struct vlan_dev_info *vip = vlan_dev_info(dev);
91 108
92 return vip->ingress_priority_map[(vlan_tci >> 13) & 0x7]; 109 return vip->ingress_priority_map[(vlan_tci >> VLAN_PRIO_SHIFT) & 0x7];
93} 110}
94 111
95#ifdef CONFIG_VLAN_8021Q_GVRP 112#ifdef CONFIG_VLAN_8021Q_GVRP
diff --git a/net/8021q/vlan_core.c b/net/8021q/vlan_core.c
index 7f7de1a04de6..c584a0af77d3 100644
--- a/net/8021q/vlan_core.c
+++ b/net/8021q/vlan_core.c
@@ -11,10 +11,11 @@ int __vlan_hwaccel_rx(struct sk_buff *skb, struct vlan_group *grp,
11 if (netpoll_rx(skb)) 11 if (netpoll_rx(skb))
12 return NET_RX_DROP; 12 return NET_RX_DROP;
13 13
14 if (skb_bond_should_drop(skb)) 14 if (skb_bond_should_drop(skb, ACCESS_ONCE(skb->dev->master)))
15 goto drop; 15 goto drop;
16 16
17 skb->vlan_tci = vlan_tci; 17 skb->skb_iif = skb->dev->ifindex;
18 __vlan_hwaccel_put_tag(skb, vlan_tci);
18 skb->dev = vlan_group_get_device(grp, vlan_tci & VLAN_VID_MASK); 19 skb->dev = vlan_group_get_device(grp, vlan_tci & VLAN_VID_MASK);
19 20
20 if (!skb->dev) 21 if (!skb->dev)
@@ -31,7 +32,7 @@ EXPORT_SYMBOL(__vlan_hwaccel_rx);
31int vlan_hwaccel_do_receive(struct sk_buff *skb) 32int vlan_hwaccel_do_receive(struct sk_buff *skb)
32{ 33{
33 struct net_device *dev = skb->dev; 34 struct net_device *dev = skb->dev;
34 struct net_device_stats *stats; 35 struct vlan_rx_stats *rx_stats;
35 36
36 skb->dev = vlan_dev_info(dev)->real_dev; 37 skb->dev = vlan_dev_info(dev)->real_dev;
37 netif_nit_deliver(skb); 38 netif_nit_deliver(skb);
@@ -40,15 +41,17 @@ int vlan_hwaccel_do_receive(struct sk_buff *skb)
40 skb->priority = vlan_get_ingress_priority(dev, skb->vlan_tci); 41 skb->priority = vlan_get_ingress_priority(dev, skb->vlan_tci);
41 skb->vlan_tci = 0; 42 skb->vlan_tci = 0;
42 43
43 stats = &dev->stats; 44 rx_stats = per_cpu_ptr(vlan_dev_info(dev)->vlan_rx_stats,
44 stats->rx_packets++; 45 smp_processor_id());
45 stats->rx_bytes += skb->len; 46
47 rx_stats->rx_packets++;
48 rx_stats->rx_bytes += skb->len;
46 49
47 switch (skb->pkt_type) { 50 switch (skb->pkt_type) {
48 case PACKET_BROADCAST: 51 case PACKET_BROADCAST:
49 break; 52 break;
50 case PACKET_MULTICAST: 53 case PACKET_MULTICAST:
51 stats->multicast++; 54 rx_stats->multicast++;
52 break; 55 break;
53 case PACKET_OTHERHOST: 56 case PACKET_OTHERHOST:
54 /* Our lower layer thinks this is not local, let's make sure. 57 /* Our lower layer thinks this is not local, let's make sure.
@@ -74,15 +77,17 @@ u16 vlan_dev_vlan_id(const struct net_device *dev)
74} 77}
75EXPORT_SYMBOL(vlan_dev_vlan_id); 78EXPORT_SYMBOL(vlan_dev_vlan_id);
76 79
77static int vlan_gro_common(struct napi_struct *napi, struct vlan_group *grp, 80static gro_result_t
78 unsigned int vlan_tci, struct sk_buff *skb) 81vlan_gro_common(struct napi_struct *napi, struct vlan_group *grp,
82 unsigned int vlan_tci, struct sk_buff *skb)
79{ 83{
80 struct sk_buff *p; 84 struct sk_buff *p;
81 85
82 if (skb_bond_should_drop(skb)) 86 if (skb_bond_should_drop(skb, ACCESS_ONCE(skb->dev->master)))
83 goto drop; 87 goto drop;
84 88
85 skb->vlan_tci = vlan_tci; 89 skb->skb_iif = skb->dev->ifindex;
90 __vlan_hwaccel_put_tag(skb, vlan_tci);
86 skb->dev = vlan_group_get_device(grp, vlan_tci & VLAN_VID_MASK); 91 skb->dev = vlan_group_get_device(grp, vlan_tci & VLAN_VID_MASK);
87 92
88 if (!skb->dev) 93 if (!skb->dev)
@@ -101,11 +106,12 @@ drop:
101 return GRO_DROP; 106 return GRO_DROP;
102} 107}
103 108
104int vlan_gro_receive(struct napi_struct *napi, struct vlan_group *grp, 109gro_result_t vlan_gro_receive(struct napi_struct *napi, struct vlan_group *grp,
105 unsigned int vlan_tci, struct sk_buff *skb) 110 unsigned int vlan_tci, struct sk_buff *skb)
106{ 111{
107 if (netpoll_rx_on(skb)) 112 if (netpoll_rx_on(skb))
108 return vlan_hwaccel_receive_skb(skb, grp, vlan_tci); 113 return vlan_hwaccel_receive_skb(skb, grp, vlan_tci)
114 ? GRO_DROP : GRO_NORMAL;
109 115
110 skb_gro_reset_offset(skb); 116 skb_gro_reset_offset(skb);
111 117
@@ -113,17 +119,18 @@ int vlan_gro_receive(struct napi_struct *napi, struct vlan_group *grp,
113} 119}
114EXPORT_SYMBOL(vlan_gro_receive); 120EXPORT_SYMBOL(vlan_gro_receive);
115 121
116int vlan_gro_frags(struct napi_struct *napi, struct vlan_group *grp, 122gro_result_t vlan_gro_frags(struct napi_struct *napi, struct vlan_group *grp,
117 unsigned int vlan_tci) 123 unsigned int vlan_tci)
118{ 124{
119 struct sk_buff *skb = napi_frags_skb(napi); 125 struct sk_buff *skb = napi_frags_skb(napi);
120 126
121 if (!skb) 127 if (!skb)
122 return NET_RX_DROP; 128 return GRO_DROP;
123 129
124 if (netpoll_rx_on(skb)) { 130 if (netpoll_rx_on(skb)) {
125 skb->protocol = eth_type_trans(skb, skb->dev); 131 skb->protocol = eth_type_trans(skb, skb->dev);
126 return vlan_hwaccel_receive_skb(skb, grp, vlan_tci); 132 return vlan_hwaccel_receive_skb(skb, grp, vlan_tci)
133 ? GRO_DROP : GRO_NORMAL;
127 } 134 }
128 135
129 return napi_frags_finish(napi, skb, 136 return napi_frags_finish(napi, skb,
diff --git a/net/8021q/vlan_dev.c b/net/8021q/vlan_dev.c
index 4198ec5c8abc..29b6348c8d4d 100644
--- a/net/8021q/vlan_dev.c
+++ b/net/8021q/vlan_dev.c
@@ -21,6 +21,7 @@
21 */ 21 */
22 22
23#include <linux/module.h> 23#include <linux/module.h>
24#include <linux/slab.h>
24#include <linux/skbuff.h> 25#include <linux/skbuff.h>
25#include <linux/netdevice.h> 26#include <linux/netdevice.h>
26#include <linux/etherdevice.h> 27#include <linux/etherdevice.h>
@@ -140,7 +141,7 @@ int vlan_skb_recv(struct sk_buff *skb, struct net_device *dev,
140 struct packet_type *ptype, struct net_device *orig_dev) 141 struct packet_type *ptype, struct net_device *orig_dev)
141{ 142{
142 struct vlan_hdr *vhdr; 143 struct vlan_hdr *vhdr;
143 struct net_device_stats *stats; 144 struct vlan_rx_stats *rx_stats;
144 u16 vlan_id; 145 u16 vlan_id;
145 u16 vlan_tci; 146 u16 vlan_tci;
146 147
@@ -163,9 +164,10 @@ int vlan_skb_recv(struct sk_buff *skb, struct net_device *dev,
163 goto err_unlock; 164 goto err_unlock;
164 } 165 }
165 166
166 stats = &skb->dev->stats; 167 rx_stats = per_cpu_ptr(vlan_dev_info(skb->dev)->vlan_rx_stats,
167 stats->rx_packets++; 168 smp_processor_id());
168 stats->rx_bytes += skb->len; 169 rx_stats->rx_packets++;
170 rx_stats->rx_bytes += skb->len;
169 171
170 skb_pull_rcsum(skb, VLAN_HLEN); 172 skb_pull_rcsum(skb, VLAN_HLEN);
171 173
@@ -180,7 +182,7 @@ int vlan_skb_recv(struct sk_buff *skb, struct net_device *dev,
180 break; 182 break;
181 183
182 case PACKET_MULTICAST: 184 case PACKET_MULTICAST:
183 stats->multicast++; 185 rx_stats->multicast++;
184 break; 186 break;
185 187
186 case PACKET_OTHERHOST: 188 case PACKET_OTHERHOST:
@@ -200,7 +202,7 @@ int vlan_skb_recv(struct sk_buff *skb, struct net_device *dev,
200 202
201 skb = vlan_check_reorder_header(skb); 203 skb = vlan_check_reorder_header(skb);
202 if (!skb) { 204 if (!skb) {
203 stats->rx_errors++; 205 rx_stats->rx_errors++;
204 goto err_unlock; 206 goto err_unlock;
205 } 207 }
206 208
@@ -262,11 +264,10 @@ static int vlan_dev_hard_header(struct sk_buff *skb, struct net_device *dev,
262 vhdr->h_vlan_TCI = htons(vlan_tci); 264 vhdr->h_vlan_TCI = htons(vlan_tci);
263 265
264 /* 266 /*
265 * Set the protocol type. For a packet of type ETH_P_802_3 we 267 * Set the protocol type. For a packet of type ETH_P_802_3/2 we
266 * put the length in here instead. It is up to the 802.2 268 * put the length in here instead.
267 * layer to carry protocol information.
268 */ 269 */
269 if (type != ETH_P_802_3) 270 if (type != ETH_P_802_3 && type != ETH_P_802_2)
270 vhdr->h_vlan_encapsulated_proto = htons(type); 271 vhdr->h_vlan_encapsulated_proto = htons(type);
271 else 272 else
272 vhdr->h_vlan_encapsulated_proto = htons(len); 273 vhdr->h_vlan_encapsulated_proto = htons(len);
@@ -322,7 +323,7 @@ static netdev_tx_t vlan_dev_hard_start_xmit(struct sk_buff *skb,
322 } 323 }
323 324
324 325
325 skb->dev = vlan_dev_info(dev)->real_dev; 326 skb_set_dev(skb, vlan_dev_info(dev)->real_dev);
326 len = skb->len; 327 len = skb->len;
327 ret = dev_queue_xmit(skb); 328 ret = dev_queue_xmit(skb);
328 329
@@ -332,7 +333,7 @@ static netdev_tx_t vlan_dev_hard_start_xmit(struct sk_buff *skb,
332 } else 333 } else
333 txq->tx_dropped++; 334 txq->tx_dropped++;
334 335
335 return NETDEV_TX_OK; 336 return ret;
336} 337}
337 338
338static netdev_tx_t vlan_dev_hwaccel_hard_start_xmit(struct sk_buff *skb, 339static netdev_tx_t vlan_dev_hwaccel_hard_start_xmit(struct sk_buff *skb,
@@ -358,7 +359,15 @@ static netdev_tx_t vlan_dev_hwaccel_hard_start_xmit(struct sk_buff *skb,
358 } else 359 } else
359 txq->tx_dropped++; 360 txq->tx_dropped++;
360 361
361 return NETDEV_TX_OK; 362 return ret;
363}
364
365static u16 vlan_dev_select_queue(struct net_device *dev, struct sk_buff *skb)
366{
367 struct net_device *rdev = vlan_dev_info(dev)->real_dev;
368 const struct net_device_ops *ops = rdev->netdev_ops;
369
370 return ops->ndo_select_queue(rdev, skb);
362} 371}
363 372
364static int vlan_dev_change_mtu(struct net_device *dev, int new_mtu) 373static int vlan_dev_change_mtu(struct net_device *dev, int new_mtu)
@@ -393,7 +402,7 @@ int vlan_dev_set_egress_priority(const struct net_device *dev,
393 struct vlan_dev_info *vlan = vlan_dev_info(dev); 402 struct vlan_dev_info *vlan = vlan_dev_info(dev);
394 struct vlan_priority_tci_mapping *mp = NULL; 403 struct vlan_priority_tci_mapping *mp = NULL;
395 struct vlan_priority_tci_mapping *np; 404 struct vlan_priority_tci_mapping *np;
396 u32 vlan_qos = (vlan_prio << 13) & 0xE000; 405 u32 vlan_qos = (vlan_prio << VLAN_PRIO_SHIFT) & VLAN_PRIO_MASK;
397 406
398 /* See if a priority mapping exists.. */ 407 /* See if a priority mapping exists.. */
399 mp = vlan->egress_priority_map[skb_prio & 0xF]; 408 mp = vlan->egress_priority_map[skb_prio & 0xF];
@@ -430,7 +439,8 @@ int vlan_dev_change_flags(const struct net_device *dev, u32 flags, u32 mask)
430 struct vlan_dev_info *vlan = vlan_dev_info(dev); 439 struct vlan_dev_info *vlan = vlan_dev_info(dev);
431 u32 old_flags = vlan->flags; 440 u32 old_flags = vlan->flags;
432 441
433 if (mask & ~(VLAN_FLAG_REORDER_HDR | VLAN_FLAG_GVRP)) 442 if (mask & ~(VLAN_FLAG_REORDER_HDR | VLAN_FLAG_GVRP |
443 VLAN_FLAG_LOOSE_BINDING))
434 return -EINVAL; 444 return -EINVAL;
435 445
436 vlan->flags = (old_flags & ~mask) | (flags & mask); 446 vlan->flags = (old_flags & ~mask) | (flags & mask);
@@ -455,7 +465,8 @@ static int vlan_dev_open(struct net_device *dev)
455 struct net_device *real_dev = vlan->real_dev; 465 struct net_device *real_dev = vlan->real_dev;
456 int err; 466 int err;
457 467
458 if (!(real_dev->flags & IFF_UP)) 468 if (!(real_dev->flags & IFF_UP) &&
469 !(vlan->flags & VLAN_FLAG_LOOSE_BINDING))
459 return -ENETDOWN; 470 return -ENETDOWN;
460 471
461 if (compare_ether_addr(dev->dev_addr, real_dev->dev_addr)) { 472 if (compare_ether_addr(dev->dev_addr, real_dev->dev_addr)) {
@@ -626,6 +637,17 @@ static int vlan_dev_fcoe_disable(struct net_device *dev)
626 rc = ops->ndo_fcoe_disable(real_dev); 637 rc = ops->ndo_fcoe_disable(real_dev);
627 return rc; 638 return rc;
628} 639}
640
641static int vlan_dev_fcoe_get_wwn(struct net_device *dev, u64 *wwn, int type)
642{
643 struct net_device *real_dev = vlan_dev_info(dev)->real_dev;
644 const struct net_device_ops *ops = real_dev->netdev_ops;
645 int rc = -EINVAL;
646
647 if (ops->ndo_fcoe_get_wwn)
648 rc = ops->ndo_fcoe_get_wwn(real_dev, wwn, type);
649 return rc;
650}
629#endif 651#endif
630 652
631static void vlan_dev_change_rx_flags(struct net_device *dev, int change) 653static void vlan_dev_change_rx_flags(struct net_device *dev, int change)
@@ -675,7 +697,8 @@ static const struct header_ops vlan_header_ops = {
675 .parse = eth_header_parse, 697 .parse = eth_header_parse,
676}; 698};
677 699
678static const struct net_device_ops vlan_netdev_ops, vlan_netdev_accel_ops; 700static const struct net_device_ops vlan_netdev_ops, vlan_netdev_accel_ops,
701 vlan_netdev_ops_sq, vlan_netdev_accel_ops_sq;
679 702
680static int vlan_dev_init(struct net_device *dev) 703static int vlan_dev_init(struct net_device *dev)
681{ 704{
@@ -709,17 +732,28 @@ static int vlan_dev_init(struct net_device *dev)
709 if (real_dev->features & NETIF_F_HW_VLAN_TX) { 732 if (real_dev->features & NETIF_F_HW_VLAN_TX) {
710 dev->header_ops = real_dev->header_ops; 733 dev->header_ops = real_dev->header_ops;
711 dev->hard_header_len = real_dev->hard_header_len; 734 dev->hard_header_len = real_dev->hard_header_len;
712 dev->netdev_ops = &vlan_netdev_accel_ops; 735 if (real_dev->netdev_ops->ndo_select_queue)
736 dev->netdev_ops = &vlan_netdev_accel_ops_sq;
737 else
738 dev->netdev_ops = &vlan_netdev_accel_ops;
713 } else { 739 } else {
714 dev->header_ops = &vlan_header_ops; 740 dev->header_ops = &vlan_header_ops;
715 dev->hard_header_len = real_dev->hard_header_len + VLAN_HLEN; 741 dev->hard_header_len = real_dev->hard_header_len + VLAN_HLEN;
716 dev->netdev_ops = &vlan_netdev_ops; 742 if (real_dev->netdev_ops->ndo_select_queue)
743 dev->netdev_ops = &vlan_netdev_ops_sq;
744 else
745 dev->netdev_ops = &vlan_netdev_ops;
717 } 746 }
718 747
719 if (is_vlan_dev(real_dev)) 748 if (is_vlan_dev(real_dev))
720 subclass = 1; 749 subclass = 1;
721 750
722 vlan_dev_set_lockdep_class(dev, subclass); 751 vlan_dev_set_lockdep_class(dev, subclass);
752
753 vlan_dev_info(dev)->vlan_rx_stats = alloc_percpu(struct vlan_rx_stats);
754 if (!vlan_dev_info(dev)->vlan_rx_stats)
755 return -ENOMEM;
756
723 return 0; 757 return 0;
724} 758}
725 759
@@ -729,6 +763,8 @@ static void vlan_dev_uninit(struct net_device *dev)
729 struct vlan_dev_info *vlan = vlan_dev_info(dev); 763 struct vlan_dev_info *vlan = vlan_dev_info(dev);
730 int i; 764 int i;
731 765
766 free_percpu(vlan->vlan_rx_stats);
767 vlan->vlan_rx_stats = NULL;
732 for (i = 0; i < ARRAY_SIZE(vlan->egress_priority_map); i++) { 768 for (i = 0; i < ARRAY_SIZE(vlan->egress_priority_map); i++) {
733 while ((pm = vlan->egress_priority_map[i]) != NULL) { 769 while ((pm = vlan->egress_priority_map[i]) != NULL) {
734 vlan->egress_priority_map[i] = pm->next; 770 vlan->egress_priority_map[i] = pm->next;
@@ -764,6 +800,31 @@ static u32 vlan_ethtool_get_flags(struct net_device *dev)
764 return dev_ethtool_get_flags(vlan->real_dev); 800 return dev_ethtool_get_flags(vlan->real_dev);
765} 801}
766 802
803static struct net_device_stats *vlan_dev_get_stats(struct net_device *dev)
804{
805 struct net_device_stats *stats = &dev->stats;
806
807 dev_txq_stats_fold(dev, stats);
808
809 if (vlan_dev_info(dev)->vlan_rx_stats) {
810 struct vlan_rx_stats *p, rx = {0};
811 int i;
812
813 for_each_possible_cpu(i) {
814 p = per_cpu_ptr(vlan_dev_info(dev)->vlan_rx_stats, i);
815 rx.rx_packets += p->rx_packets;
816 rx.rx_bytes += p->rx_bytes;
817 rx.rx_errors += p->rx_errors;
818 rx.multicast += p->multicast;
819 }
820 stats->rx_packets = rx.rx_packets;
821 stats->rx_bytes = rx.rx_bytes;
822 stats->rx_errors = rx.rx_errors;
823 stats->multicast = rx.multicast;
824 }
825 return stats;
826}
827
767static const struct ethtool_ops vlan_ethtool_ops = { 828static const struct ethtool_ops vlan_ethtool_ops = {
768 .get_settings = vlan_ethtool_get_settings, 829 .get_settings = vlan_ethtool_get_settings,
769 .get_drvinfo = vlan_ethtool_get_drvinfo, 830 .get_drvinfo = vlan_ethtool_get_drvinfo,
@@ -786,11 +847,13 @@ static const struct net_device_ops vlan_netdev_ops = {
786 .ndo_change_rx_flags = vlan_dev_change_rx_flags, 847 .ndo_change_rx_flags = vlan_dev_change_rx_flags,
787 .ndo_do_ioctl = vlan_dev_ioctl, 848 .ndo_do_ioctl = vlan_dev_ioctl,
788 .ndo_neigh_setup = vlan_dev_neigh_setup, 849 .ndo_neigh_setup = vlan_dev_neigh_setup,
850 .ndo_get_stats = vlan_dev_get_stats,
789#if defined(CONFIG_FCOE) || defined(CONFIG_FCOE_MODULE) 851#if defined(CONFIG_FCOE) || defined(CONFIG_FCOE_MODULE)
790 .ndo_fcoe_ddp_setup = vlan_dev_fcoe_ddp_setup, 852 .ndo_fcoe_ddp_setup = vlan_dev_fcoe_ddp_setup,
791 .ndo_fcoe_ddp_done = vlan_dev_fcoe_ddp_done, 853 .ndo_fcoe_ddp_done = vlan_dev_fcoe_ddp_done,
792 .ndo_fcoe_enable = vlan_dev_fcoe_enable, 854 .ndo_fcoe_enable = vlan_dev_fcoe_enable,
793 .ndo_fcoe_disable = vlan_dev_fcoe_disable, 855 .ndo_fcoe_disable = vlan_dev_fcoe_disable,
856 .ndo_fcoe_get_wwn = vlan_dev_fcoe_get_wwn,
794#endif 857#endif
795}; 858};
796 859
@@ -808,11 +871,63 @@ static const struct net_device_ops vlan_netdev_accel_ops = {
808 .ndo_change_rx_flags = vlan_dev_change_rx_flags, 871 .ndo_change_rx_flags = vlan_dev_change_rx_flags,
809 .ndo_do_ioctl = vlan_dev_ioctl, 872 .ndo_do_ioctl = vlan_dev_ioctl,
810 .ndo_neigh_setup = vlan_dev_neigh_setup, 873 .ndo_neigh_setup = vlan_dev_neigh_setup,
874 .ndo_get_stats = vlan_dev_get_stats,
875#if defined(CONFIG_FCOE) || defined(CONFIG_FCOE_MODULE)
876 .ndo_fcoe_ddp_setup = vlan_dev_fcoe_ddp_setup,
877 .ndo_fcoe_ddp_done = vlan_dev_fcoe_ddp_done,
878 .ndo_fcoe_enable = vlan_dev_fcoe_enable,
879 .ndo_fcoe_disable = vlan_dev_fcoe_disable,
880 .ndo_fcoe_get_wwn = vlan_dev_fcoe_get_wwn,
881#endif
882};
883
884static const struct net_device_ops vlan_netdev_ops_sq = {
885 .ndo_select_queue = vlan_dev_select_queue,
886 .ndo_change_mtu = vlan_dev_change_mtu,
887 .ndo_init = vlan_dev_init,
888 .ndo_uninit = vlan_dev_uninit,
889 .ndo_open = vlan_dev_open,
890 .ndo_stop = vlan_dev_stop,
891 .ndo_start_xmit = vlan_dev_hard_start_xmit,
892 .ndo_validate_addr = eth_validate_addr,
893 .ndo_set_mac_address = vlan_dev_set_mac_address,
894 .ndo_set_rx_mode = vlan_dev_set_rx_mode,
895 .ndo_set_multicast_list = vlan_dev_set_rx_mode,
896 .ndo_change_rx_flags = vlan_dev_change_rx_flags,
897 .ndo_do_ioctl = vlan_dev_ioctl,
898 .ndo_neigh_setup = vlan_dev_neigh_setup,
899 .ndo_get_stats = vlan_dev_get_stats,
900#if defined(CONFIG_FCOE) || defined(CONFIG_FCOE_MODULE)
901 .ndo_fcoe_ddp_setup = vlan_dev_fcoe_ddp_setup,
902 .ndo_fcoe_ddp_done = vlan_dev_fcoe_ddp_done,
903 .ndo_fcoe_enable = vlan_dev_fcoe_enable,
904 .ndo_fcoe_disable = vlan_dev_fcoe_disable,
905 .ndo_fcoe_get_wwn = vlan_dev_fcoe_get_wwn,
906#endif
907};
908
909static const struct net_device_ops vlan_netdev_accel_ops_sq = {
910 .ndo_select_queue = vlan_dev_select_queue,
911 .ndo_change_mtu = vlan_dev_change_mtu,
912 .ndo_init = vlan_dev_init,
913 .ndo_uninit = vlan_dev_uninit,
914 .ndo_open = vlan_dev_open,
915 .ndo_stop = vlan_dev_stop,
916 .ndo_start_xmit = vlan_dev_hwaccel_hard_start_xmit,
917 .ndo_validate_addr = eth_validate_addr,
918 .ndo_set_mac_address = vlan_dev_set_mac_address,
919 .ndo_set_rx_mode = vlan_dev_set_rx_mode,
920 .ndo_set_multicast_list = vlan_dev_set_rx_mode,
921 .ndo_change_rx_flags = vlan_dev_change_rx_flags,
922 .ndo_do_ioctl = vlan_dev_ioctl,
923 .ndo_neigh_setup = vlan_dev_neigh_setup,
924 .ndo_get_stats = vlan_dev_get_stats,
811#if defined(CONFIG_FCOE) || defined(CONFIG_FCOE_MODULE) 925#if defined(CONFIG_FCOE) || defined(CONFIG_FCOE_MODULE)
812 .ndo_fcoe_ddp_setup = vlan_dev_fcoe_ddp_setup, 926 .ndo_fcoe_ddp_setup = vlan_dev_fcoe_ddp_setup,
813 .ndo_fcoe_ddp_done = vlan_dev_fcoe_ddp_done, 927 .ndo_fcoe_ddp_done = vlan_dev_fcoe_ddp_done,
814 .ndo_fcoe_enable = vlan_dev_fcoe_enable, 928 .ndo_fcoe_enable = vlan_dev_fcoe_enable,
815 .ndo_fcoe_disable = vlan_dev_fcoe_disable, 929 .ndo_fcoe_disable = vlan_dev_fcoe_disable,
930 .ndo_fcoe_get_wwn = vlan_dev_fcoe_get_wwn,
816#endif 931#endif
817}; 932};
818 933
diff --git a/net/8021q/vlan_netlink.c b/net/8021q/vlan_netlink.c
index a91504850195..ddc105734af7 100644
--- a/net/8021q/vlan_netlink.c
+++ b/net/8021q/vlan_netlink.c
@@ -60,7 +60,8 @@ static int vlan_validate(struct nlattr *tb[], struct nlattr *data[])
60 if (data[IFLA_VLAN_FLAGS]) { 60 if (data[IFLA_VLAN_FLAGS]) {
61 flags = nla_data(data[IFLA_VLAN_FLAGS]); 61 flags = nla_data(data[IFLA_VLAN_FLAGS]);
62 if ((flags->flags & flags->mask) & 62 if ((flags->flags & flags->mask) &
63 ~(VLAN_FLAG_REORDER_HDR | VLAN_FLAG_GVRP)) 63 ~(VLAN_FLAG_REORDER_HDR | VLAN_FLAG_GVRP |
64 VLAN_FLAG_LOOSE_BINDING))
64 return -EINVAL; 65 return -EINVAL;
65 } 66 }
66 67
@@ -119,7 +120,7 @@ static int vlan_get_tx_queues(struct net *net,
119 return 0; 120 return 0;
120} 121}
121 122
122static int vlan_newlink(struct net_device *dev, 123static int vlan_newlink(struct net *src_net, struct net_device *dev,
123 struct nlattr *tb[], struct nlattr *data[]) 124 struct nlattr *tb[], struct nlattr *data[])
124{ 125{
125 struct vlan_dev_info *vlan = vlan_dev_info(dev); 126 struct vlan_dev_info *vlan = vlan_dev_info(dev);
@@ -131,7 +132,7 @@ static int vlan_newlink(struct net_device *dev,
131 132
132 if (!tb[IFLA_LINK]) 133 if (!tb[IFLA_LINK])
133 return -EINVAL; 134 return -EINVAL;
134 real_dev = __dev_get_by_index(dev_net(dev), nla_get_u32(tb[IFLA_LINK])); 135 real_dev = __dev_get_by_index(src_net, nla_get_u32(tb[IFLA_LINK]));
135 if (!real_dev) 136 if (!real_dev)
136 return -ENODEV; 137 return -ENODEV;
137 138
diff --git a/net/8021q/vlanproc.c b/net/8021q/vlanproc.c
index 6262c335f3c2..afead353e215 100644
--- a/net/8021q/vlanproc.c
+++ b/net/8021q/vlanproc.c
@@ -140,7 +140,7 @@ void vlan_proc_cleanup(struct net *net)
140 * Create /proc/net/vlan entries 140 * Create /proc/net/vlan entries
141 */ 141 */
142 142
143int vlan_proc_init(struct net *net) 143int __net_init vlan_proc_init(struct net *net)
144{ 144{
145 struct vlan_net *vn = net_generic(net, vlan_net_id); 145 struct vlan_net *vn = net_generic(net, vlan_net_id);
146 146
@@ -201,18 +201,17 @@ int vlan_proc_rem_dev(struct net_device *vlandev)
201 201
202/* start read of /proc/net/vlan/config */ 202/* start read of /proc/net/vlan/config */
203static void *vlan_seq_start(struct seq_file *seq, loff_t *pos) 203static void *vlan_seq_start(struct seq_file *seq, loff_t *pos)
204 __acquires(dev_base_lock) 204 __acquires(rcu)
205{ 205{
206 struct net_device *dev; 206 struct net_device *dev;
207 struct net *net = seq_file_net(seq); 207 struct net *net = seq_file_net(seq);
208 loff_t i = 1; 208 loff_t i = 1;
209 209
210 read_lock(&dev_base_lock); 210 rcu_read_lock();
211
212 if (*pos == 0) 211 if (*pos == 0)
213 return SEQ_START_TOKEN; 212 return SEQ_START_TOKEN;
214 213
215 for_each_netdev(net, dev) { 214 for_each_netdev_rcu(net, dev) {
216 if (!is_vlan_dev(dev)) 215 if (!is_vlan_dev(dev))
217 continue; 216 continue;
218 217
@@ -234,7 +233,7 @@ static void *vlan_seq_next(struct seq_file *seq, void *v, loff_t *pos)
234 if (v == SEQ_START_TOKEN) 233 if (v == SEQ_START_TOKEN)
235 dev = net_device_entry(&net->dev_base_head); 234 dev = net_device_entry(&net->dev_base_head);
236 235
237 for_each_netdev_continue(net, dev) { 236 for_each_netdev_continue_rcu(net, dev) {
238 if (!is_vlan_dev(dev)) 237 if (!is_vlan_dev(dev))
239 continue; 238 continue;
240 239
@@ -245,9 +244,9 @@ static void *vlan_seq_next(struct seq_file *seq, void *v, loff_t *pos)
245} 244}
246 245
247static void vlan_seq_stop(struct seq_file *seq, void *v) 246static void vlan_seq_stop(struct seq_file *seq, void *v)
248 __releases(dev_base_lock) 247 __releases(rcu)
249{ 248{
250 read_unlock(&dev_base_lock); 249 rcu_read_unlock();
251} 250}
252 251
253static int vlan_seq_show(struct seq_file *seq, void *v) 252static int vlan_seq_show(struct seq_file *seq, void *v)
diff --git a/net/9p/client.c b/net/9p/client.c
index 8af95b2dddd6..0aa79faa9850 100644
--- a/net/9p/client.c
+++ b/net/9p/client.c
@@ -29,6 +29,7 @@
29#include <linux/poll.h> 29#include <linux/poll.h>
30#include <linux/idr.h> 30#include <linux/idr.h>
31#include <linux/mutex.h> 31#include <linux/mutex.h>
32#include <linux/slab.h>
32#include <linux/sched.h> 33#include <linux/sched.h>
33#include <linux/uaccess.h> 34#include <linux/uaccess.h>
34#include <net/9p/9p.h> 35#include <net/9p/9p.h>
@@ -46,6 +47,7 @@ enum {
46 Opt_msize, 47 Opt_msize,
47 Opt_trans, 48 Opt_trans,
48 Opt_legacy, 49 Opt_legacy,
50 Opt_version,
49 Opt_err, 51 Opt_err,
50}; 52};
51 53
@@ -53,9 +55,43 @@ static const match_table_t tokens = {
53 {Opt_msize, "msize=%u"}, 55 {Opt_msize, "msize=%u"},
54 {Opt_legacy, "noextend"}, 56 {Opt_legacy, "noextend"},
55 {Opt_trans, "trans=%s"}, 57 {Opt_trans, "trans=%s"},
58 {Opt_version, "version=%s"},
56 {Opt_err, NULL}, 59 {Opt_err, NULL},
57}; 60};
58 61
62inline int p9_is_proto_dotl(struct p9_client *clnt)
63{
64 return (clnt->proto_version == p9_proto_2000L);
65}
66EXPORT_SYMBOL(p9_is_proto_dotl);
67
68inline int p9_is_proto_dotu(struct p9_client *clnt)
69{
70 return (clnt->proto_version == p9_proto_2000u);
71}
72EXPORT_SYMBOL(p9_is_proto_dotu);
73
74/* Interpret mount option for protocol version */
75static int get_protocol_version(const substring_t *name)
76{
77 int version = -EINVAL;
78
79 if (!strncmp("9p2000", name->from, name->to-name->from)) {
80 version = p9_proto_legacy;
81 P9_DPRINTK(P9_DEBUG_9P, "Protocol version: Legacy\n");
82 } else if (!strncmp("9p2000.u", name->from, name->to-name->from)) {
83 version = p9_proto_2000u;
84 P9_DPRINTK(P9_DEBUG_9P, "Protocol version: 9P2000.u\n");
85 } else if (!strncmp("9p2000.L", name->from, name->to-name->from)) {
86 version = p9_proto_2000L;
87 P9_DPRINTK(P9_DEBUG_9P, "Protocol version: 9P2000.L\n");
88 } else {
89 P9_DPRINTK(P9_DEBUG_ERROR, "Unknown protocol version %s. ",
90 name->from);
91 }
92 return version;
93}
94
59static struct p9_req_t * 95static struct p9_req_t *
60p9_client_rpc(struct p9_client *c, int8_t type, const char *fmt, ...); 96p9_client_rpc(struct p9_client *c, int8_t type, const char *fmt, ...);
61 97
@@ -69,24 +105,25 @@ p9_client_rpc(struct p9_client *c, int8_t type, const char *fmt, ...);
69 105
70static int parse_opts(char *opts, struct p9_client *clnt) 106static int parse_opts(char *opts, struct p9_client *clnt)
71{ 107{
72 char *options; 108 char *options, *tmp_options;
73 char *p; 109 char *p;
74 substring_t args[MAX_OPT_ARGS]; 110 substring_t args[MAX_OPT_ARGS];
75 int option; 111 int option;
76 int ret = 0; 112 int ret = 0;
77 113
78 clnt->dotu = 1; 114 clnt->proto_version = p9_proto_2000u;
79 clnt->msize = 8192; 115 clnt->msize = 8192;
80 116
81 if (!opts) 117 if (!opts)
82 return 0; 118 return 0;
83 119
84 options = kstrdup(opts, GFP_KERNEL); 120 tmp_options = kstrdup(opts, GFP_KERNEL);
85 if (!options) { 121 if (!tmp_options) {
86 P9_DPRINTK(P9_DEBUG_ERROR, 122 P9_DPRINTK(P9_DEBUG_ERROR,
87 "failed to allocate copy of option string\n"); 123 "failed to allocate copy of option string\n");
88 return -ENOMEM; 124 return -ENOMEM;
89 } 125 }
126 options = tmp_options;
90 127
91 while ((p = strsep(&options, ",")) != NULL) { 128 while ((p = strsep(&options, ",")) != NULL) {
92 int token; 129 int token;
@@ -108,16 +145,30 @@ static int parse_opts(char *opts, struct p9_client *clnt)
108 break; 145 break;
109 case Opt_trans: 146 case Opt_trans:
110 clnt->trans_mod = v9fs_get_trans_by_name(&args[0]); 147 clnt->trans_mod = v9fs_get_trans_by_name(&args[0]);
148 if(clnt->trans_mod == NULL) {
149 P9_DPRINTK(P9_DEBUG_ERROR,
150 "Could not find request transport: %s\n",
151 (char *) &args[0]);
152 ret = -EINVAL;
153 goto free_and_return;
154 }
111 break; 155 break;
112 case Opt_legacy: 156 case Opt_legacy:
113 clnt->dotu = 0; 157 clnt->proto_version = p9_proto_legacy;
158 break;
159 case Opt_version:
160 ret = get_protocol_version(&args[0]);
161 if (ret == -EINVAL)
162 goto free_and_return;
163 clnt->proto_version = ret;
114 break; 164 break;
115 default: 165 default:
116 continue; 166 continue;
117 } 167 }
118 } 168 }
119 169
120 kfree(options); 170free_and_return:
171 kfree(tmp_options);
121 return ret; 172 return ret;
122} 173}
123 174
@@ -401,14 +452,15 @@ static int p9_check_errors(struct p9_client *c, struct p9_req_t *req)
401 int ecode; 452 int ecode;
402 char *ename; 453 char *ename;
403 454
404 err = p9pdu_readf(req->rc, c->dotu, "s?d", &ename, &ecode); 455 err = p9pdu_readf(req->rc, c->proto_version, "s?d",
456 &ename, &ecode);
405 if (err) { 457 if (err) {
406 P9_DPRINTK(P9_DEBUG_ERROR, "couldn't parse error%d\n", 458 P9_DPRINTK(P9_DEBUG_ERROR, "couldn't parse error%d\n",
407 err); 459 err);
408 return err; 460 return err;
409 } 461 }
410 462
411 if (c->dotu) 463 if (p9_is_proto_dotu(c))
412 err = -ecode; 464 err = -ecode;
413 465
414 if (!err || !IS_ERR_VALUE(err)) 466 if (!err || !IS_ERR_VALUE(err))
@@ -483,7 +535,12 @@ p9_client_rpc(struct p9_client *c, int8_t type, const char *fmt, ...)
483 535
484 P9_DPRINTK(P9_DEBUG_MUX, "client %p op %d\n", c, type); 536 P9_DPRINTK(P9_DEBUG_MUX, "client %p op %d\n", c, type);
485 537
486 if (c->status != Connected) 538 /* we allow for any status other than disconnected */
539 if (c->status == Disconnected)
540 return ERR_PTR(-EIO);
541
542 /* if status is begin_disconnected we allow only clunk request */
543 if ((c->status == BeginDisconnect) && (type != P9_TCLUNK))
487 return ERR_PTR(-EIO); 544 return ERR_PTR(-EIO);
488 545
489 if (signal_pending(current)) { 546 if (signal_pending(current)) {
@@ -506,7 +563,7 @@ p9_client_rpc(struct p9_client *c, int8_t type, const char *fmt, ...)
506 /* marshall the data */ 563 /* marshall the data */
507 p9pdu_prepare(req->tc, tag, type); 564 p9pdu_prepare(req->tc, tag, type);
508 va_start(ap, fmt); 565 va_start(ap, fmt);
509 err = p9pdu_vwritef(req->tc, c->dotu, fmt, ap); 566 err = p9pdu_vwritef(req->tc, c->proto_version, fmt, ap);
510 va_end(ap); 567 va_end(ap);
511 p9pdu_finalize(req->tc); 568 p9pdu_finalize(req->tc);
512 569
@@ -618,14 +675,31 @@ int p9_client_version(struct p9_client *c)
618 char *version; 675 char *version;
619 int msize; 676 int msize;
620 677
621 P9_DPRINTK(P9_DEBUG_9P, ">>> TVERSION msize %d extended %d\n", 678 P9_DPRINTK(P9_DEBUG_9P, ">>> TVERSION msize %d protocol %d\n",
622 c->msize, c->dotu); 679 c->msize, c->proto_version);
623 req = p9_client_rpc(c, P9_TVERSION, "ds", c->msize, 680
624 c->dotu ? "9P2000.u" : "9P2000"); 681 switch (c->proto_version) {
682 case p9_proto_2000L:
683 req = p9_client_rpc(c, P9_TVERSION, "ds",
684 c->msize, "9P2000.L");
685 break;
686 case p9_proto_2000u:
687 req = p9_client_rpc(c, P9_TVERSION, "ds",
688 c->msize, "9P2000.u");
689 break;
690 case p9_proto_legacy:
691 req = p9_client_rpc(c, P9_TVERSION, "ds",
692 c->msize, "9P2000");
693 break;
694 default:
695 return -EINVAL;
696 break;
697 }
698
625 if (IS_ERR(req)) 699 if (IS_ERR(req))
626 return PTR_ERR(req); 700 return PTR_ERR(req);
627 701
628 err = p9pdu_readf(req->rc, c->dotu, "ds", &msize, &version); 702 err = p9pdu_readf(req->rc, c->proto_version, "ds", &msize, &version);
629 if (err) { 703 if (err) {
630 P9_DPRINTK(P9_DEBUG_9P, "version error %d\n", err); 704 P9_DPRINTK(P9_DEBUG_9P, "version error %d\n", err);
631 p9pdu_dump(1, req->rc); 705 p9pdu_dump(1, req->rc);
@@ -633,10 +707,12 @@ int p9_client_version(struct p9_client *c)
633 } 707 }
634 708
635 P9_DPRINTK(P9_DEBUG_9P, "<<< RVERSION msize %d %s\n", msize, version); 709 P9_DPRINTK(P9_DEBUG_9P, "<<< RVERSION msize %d %s\n", msize, version);
636 if (!memcmp(version, "9P2000.u", 8)) 710 if (!strncmp(version, "9P2000.L", 8))
637 c->dotu = 1; 711 c->proto_version = p9_proto_2000L;
638 else if (!memcmp(version, "9P2000", 6)) 712 else if (!strncmp(version, "9P2000.u", 8))
639 c->dotu = 0; 713 c->proto_version = p9_proto_2000u;
714 else if (!strncmp(version, "9P2000", 6))
715 c->proto_version = p9_proto_legacy;
640 else { 716 else {
641 err = -EREMOTEIO; 717 err = -EREMOTEIO;
642 goto error; 718 goto error;
@@ -667,18 +743,12 @@ struct p9_client *p9_client_create(const char *dev_name, char *options)
667 clnt->trans = NULL; 743 clnt->trans = NULL;
668 spin_lock_init(&clnt->lock); 744 spin_lock_init(&clnt->lock);
669 INIT_LIST_HEAD(&clnt->fidlist); 745 INIT_LIST_HEAD(&clnt->fidlist);
670 clnt->fidpool = p9_idpool_create();
671 if (IS_ERR(clnt->fidpool)) {
672 err = PTR_ERR(clnt->fidpool);
673 clnt->fidpool = NULL;
674 goto error;
675 }
676 746
677 p9_tag_init(clnt); 747 p9_tag_init(clnt);
678 748
679 err = parse_opts(options, clnt); 749 err = parse_opts(options, clnt);
680 if (err < 0) 750 if (err < 0)
681 goto error; 751 goto free_client;
682 752
683 if (!clnt->trans_mod) 753 if (!clnt->trans_mod)
684 clnt->trans_mod = v9fs_get_default_trans(); 754 clnt->trans_mod = v9fs_get_default_trans();
@@ -687,27 +757,40 @@ struct p9_client *p9_client_create(const char *dev_name, char *options)
687 err = -EPROTONOSUPPORT; 757 err = -EPROTONOSUPPORT;
688 P9_DPRINTK(P9_DEBUG_ERROR, 758 P9_DPRINTK(P9_DEBUG_ERROR,
689 "No transport defined or default transport\n"); 759 "No transport defined or default transport\n");
690 goto error; 760 goto free_client;
761 }
762
763 clnt->fidpool = p9_idpool_create();
764 if (IS_ERR(clnt->fidpool)) {
765 err = PTR_ERR(clnt->fidpool);
766 clnt->fidpool = NULL;
767 goto put_trans;
691 } 768 }
692 769
693 P9_DPRINTK(P9_DEBUG_MUX, "clnt %p trans %p msize %d dotu %d\n", 770 P9_DPRINTK(P9_DEBUG_MUX, "clnt %p trans %p msize %d protocol %d\n",
694 clnt, clnt->trans_mod, clnt->msize, clnt->dotu); 771 clnt, clnt->trans_mod, clnt->msize, clnt->proto_version);
695 772
696 err = clnt->trans_mod->create(clnt, dev_name, options); 773 err = clnt->trans_mod->create(clnt, dev_name, options);
697 if (err) 774 if (err)
698 goto error; 775 goto destroy_fidpool;
699 776
700 if ((clnt->msize+P9_IOHDRSZ) > clnt->trans_mod->maxsize) 777 if ((clnt->msize+P9_IOHDRSZ) > clnt->trans_mod->maxsize)
701 clnt->msize = clnt->trans_mod->maxsize-P9_IOHDRSZ; 778 clnt->msize = clnt->trans_mod->maxsize-P9_IOHDRSZ;
702 779
703 err = p9_client_version(clnt); 780 err = p9_client_version(clnt);
704 if (err) 781 if (err)
705 goto error; 782 goto close_trans;
706 783
707 return clnt; 784 return clnt;
708 785
709error: 786close_trans:
710 p9_client_destroy(clnt); 787 clnt->trans_mod->close(clnt);
788destroy_fidpool:
789 p9_idpool_destroy(clnt->fidpool);
790put_trans:
791 v9fs_put_trans(clnt->trans_mod);
792free_client:
793 kfree(clnt);
711 return ERR_PTR(err); 794 return ERR_PTR(err);
712} 795}
713EXPORT_SYMBOL(p9_client_create); 796EXPORT_SYMBOL(p9_client_create);
@@ -723,8 +806,10 @@ void p9_client_destroy(struct p9_client *clnt)
723 806
724 v9fs_put_trans(clnt->trans_mod); 807 v9fs_put_trans(clnt->trans_mod);
725 808
726 list_for_each_entry_safe(fid, fidptr, &clnt->fidlist, flist) 809 list_for_each_entry_safe(fid, fidptr, &clnt->fidlist, flist) {
810 printk(KERN_INFO "Found fid %d not clunked\n", fid->fid);
727 p9_fid_destroy(fid); 811 p9_fid_destroy(fid);
812 }
728 813
729 if (clnt->fidpool) 814 if (clnt->fidpool)
730 p9_idpool_destroy(clnt->fidpool); 815 p9_idpool_destroy(clnt->fidpool);
@@ -742,6 +827,13 @@ void p9_client_disconnect(struct p9_client *clnt)
742} 827}
743EXPORT_SYMBOL(p9_client_disconnect); 828EXPORT_SYMBOL(p9_client_disconnect);
744 829
830void p9_client_begin_disconnect(struct p9_client *clnt)
831{
832 P9_DPRINTK(P9_DEBUG_9P, "clnt %p\n", clnt);
833 clnt->status = BeginDisconnect;
834}
835EXPORT_SYMBOL(p9_client_begin_disconnect);
836
745struct p9_fid *p9_client_attach(struct p9_client *clnt, struct p9_fid *afid, 837struct p9_fid *p9_client_attach(struct p9_client *clnt, struct p9_fid *afid,
746 char *uname, u32 n_uname, char *aname) 838 char *uname, u32 n_uname, char *aname)
747{ 839{
@@ -768,7 +860,7 @@ struct p9_fid *p9_client_attach(struct p9_client *clnt, struct p9_fid *afid,
768 goto error; 860 goto error;
769 } 861 }
770 862
771 err = p9pdu_readf(req->rc, clnt->dotu, "Q", &qid); 863 err = p9pdu_readf(req->rc, clnt->proto_version, "Q", &qid);
772 if (err) { 864 if (err) {
773 p9pdu_dump(1, req->rc); 865 p9pdu_dump(1, req->rc);
774 p9_free_req(clnt, req); 866 p9_free_req(clnt, req);
@@ -817,7 +909,7 @@ p9_client_auth(struct p9_client *clnt, char *uname, u32 n_uname, char *aname)
817 goto error; 909 goto error;
818 } 910 }
819 911
820 err = p9pdu_readf(req->rc, clnt->dotu, "Q", &qid); 912 err = p9pdu_readf(req->rc, clnt->proto_version, "Q", &qid);
821 if (err) { 913 if (err) {
822 p9pdu_dump(1, req->rc); 914 p9pdu_dump(1, req->rc);
823 p9_free_req(clnt, req); 915 p9_free_req(clnt, req);
@@ -875,7 +967,7 @@ struct p9_fid *p9_client_walk(struct p9_fid *oldfid, int nwname, char **wnames,
875 goto error; 967 goto error;
876 } 968 }
877 969
878 err = p9pdu_readf(req->rc, clnt->dotu, "R", &nwqids, &wqids); 970 err = p9pdu_readf(req->rc, clnt->proto_version, "R", &nwqids, &wqids);
879 if (err) { 971 if (err) {
880 p9pdu_dump(1, req->rc); 972 p9pdu_dump(1, req->rc);
881 p9_free_req(clnt, req); 973 p9_free_req(clnt, req);
@@ -936,7 +1028,7 @@ int p9_client_open(struct p9_fid *fid, int mode)
936 goto error; 1028 goto error;
937 } 1029 }
938 1030
939 err = p9pdu_readf(req->rc, clnt->dotu, "Qd", &qid, &iounit); 1031 err = p9pdu_readf(req->rc, clnt->proto_version, "Qd", &qid, &iounit);
940 if (err) { 1032 if (err) {
941 p9pdu_dump(1, req->rc); 1033 p9pdu_dump(1, req->rc);
942 goto free_and_error; 1034 goto free_and_error;
@@ -981,7 +1073,7 @@ int p9_client_fcreate(struct p9_fid *fid, char *name, u32 perm, int mode,
981 goto error; 1073 goto error;
982 } 1074 }
983 1075
984 err = p9pdu_readf(req->rc, clnt->dotu, "Qd", &qid, &iounit); 1076 err = p9pdu_readf(req->rc, clnt->proto_version, "Qd", &qid, &iounit);
985 if (err) { 1077 if (err) {
986 p9pdu_dump(1, req->rc); 1078 p9pdu_dump(1, req->rc);
987 goto free_and_error; 1079 goto free_and_error;
@@ -1082,7 +1174,7 @@ p9_client_read(struct p9_fid *fid, char *data, char __user *udata, u64 offset,
1082 goto error; 1174 goto error;
1083 } 1175 }
1084 1176
1085 err = p9pdu_readf(req->rc, clnt->dotu, "D", &count, &dataptr); 1177 err = p9pdu_readf(req->rc, clnt->proto_version, "D", &count, &dataptr);
1086 if (err) { 1178 if (err) {
1087 p9pdu_dump(1, req->rc); 1179 p9pdu_dump(1, req->rc);
1088 goto free_and_error; 1180 goto free_and_error;
@@ -1143,7 +1235,7 @@ p9_client_write(struct p9_fid *fid, char *data, const char __user *udata,
1143 goto error; 1235 goto error;
1144 } 1236 }
1145 1237
1146 err = p9pdu_readf(req->rc, clnt->dotu, "d", &count); 1238 err = p9pdu_readf(req->rc, clnt->proto_version, "d", &count);
1147 if (err) { 1239 if (err) {
1148 p9pdu_dump(1, req->rc); 1240 p9pdu_dump(1, req->rc);
1149 goto free_and_error; 1241 goto free_and_error;
@@ -1183,7 +1275,7 @@ struct p9_wstat *p9_client_stat(struct p9_fid *fid)
1183 goto error; 1275 goto error;
1184 } 1276 }
1185 1277
1186 err = p9pdu_readf(req->rc, clnt->dotu, "wS", &ignored, ret); 1278 err = p9pdu_readf(req->rc, clnt->proto_version, "wS", &ignored, ret);
1187 if (err) { 1279 if (err) {
1188 p9pdu_dump(1, req->rc); 1280 p9pdu_dump(1, req->rc);
1189 p9_free_req(clnt, req); 1281 p9_free_req(clnt, req);
@@ -1210,14 +1302,15 @@ error:
1210} 1302}
1211EXPORT_SYMBOL(p9_client_stat); 1303EXPORT_SYMBOL(p9_client_stat);
1212 1304
1213static int p9_client_statsize(struct p9_wstat *wst, int optional) 1305static int p9_client_statsize(struct p9_wstat *wst, int proto_version)
1214{ 1306{
1215 int ret; 1307 int ret;
1216 1308
1309 /* NOTE: size shouldn't include its own length */
1217 /* size[2] type[2] dev[4] qid[13] */ 1310 /* size[2] type[2] dev[4] qid[13] */
1218 /* mode[4] atime[4] mtime[4] length[8]*/ 1311 /* mode[4] atime[4] mtime[4] length[8]*/
1219 /* name[s] uid[s] gid[s] muid[s] */ 1312 /* name[s] uid[s] gid[s] muid[s] */
1220 ret = 2+2+4+13+4+4+4+8+2+2+2+2; 1313 ret = 2+4+13+4+4+4+8+2+2+2+2;
1221 1314
1222 if (wst->name) 1315 if (wst->name)
1223 ret += strlen(wst->name); 1316 ret += strlen(wst->name);
@@ -1228,7 +1321,7 @@ static int p9_client_statsize(struct p9_wstat *wst, int optional)
1228 if (wst->muid) 1321 if (wst->muid)
1229 ret += strlen(wst->muid); 1322 ret += strlen(wst->muid);
1230 1323
1231 if (optional) { 1324 if (proto_version == p9_proto_2000u) {
1232 ret += 2+4+4+4; /* extension[s] n_uid[4] n_gid[4] n_muid[4] */ 1325 ret += 2+4+4+4; /* extension[s] n_uid[4] n_gid[4] n_muid[4] */
1233 if (wst->extension) 1326 if (wst->extension)
1234 ret += strlen(wst->extension); 1327 ret += strlen(wst->extension);
@@ -1245,7 +1338,7 @@ int p9_client_wstat(struct p9_fid *fid, struct p9_wstat *wst)
1245 1338
1246 err = 0; 1339 err = 0;
1247 clnt = fid->clnt; 1340 clnt = fid->clnt;
1248 wst->size = p9_client_statsize(wst, clnt->dotu); 1341 wst->size = p9_client_statsize(wst, clnt->proto_version);
1249 P9_DPRINTK(P9_DEBUG_9P, ">>> TWSTAT fid %d\n", fid->fid); 1342 P9_DPRINTK(P9_DEBUG_9P, ">>> TWSTAT fid %d\n", fid->fid);
1250 P9_DPRINTK(P9_DEBUG_9P, 1343 P9_DPRINTK(P9_DEBUG_9P,
1251 " sz=%x type=%x dev=%x qid=%x.%llx.%x\n" 1344 " sz=%x type=%x dev=%x qid=%x.%llx.%x\n"
@@ -1258,7 +1351,7 @@ int p9_client_wstat(struct p9_fid *fid, struct p9_wstat *wst)
1258 wst->name, wst->uid, wst->gid, wst->muid, wst->extension, 1351 wst->name, wst->uid, wst->gid, wst->muid, wst->extension,
1259 wst->n_uid, wst->n_gid, wst->n_muid); 1352 wst->n_uid, wst->n_gid, wst->n_muid);
1260 1353
1261 req = p9_client_rpc(clnt, P9_TWSTAT, "dwS", fid->fid, wst->size, wst); 1354 req = p9_client_rpc(clnt, P9_TWSTAT, "dwS", fid->fid, wst->size+2, wst);
1262 if (IS_ERR(req)) { 1355 if (IS_ERR(req)) {
1263 err = PTR_ERR(req); 1356 err = PTR_ERR(req);
1264 goto error; 1357 goto error;
diff --git a/net/9p/protocol.c b/net/9p/protocol.c
index fc70147c771e..e7541d5b0118 100644
--- a/net/9p/protocol.c
+++ b/net/9p/protocol.c
@@ -28,6 +28,7 @@
28#include <linux/module.h> 28#include <linux/module.h>
29#include <linux/errno.h> 29#include <linux/errno.h>
30#include <linux/uaccess.h> 30#include <linux/uaccess.h>
31#include <linux/slab.h>
31#include <linux/sched.h> 32#include <linux/sched.h>
32#include <linux/types.h> 33#include <linux/types.h>
33#include <net/9p/9p.h> 34#include <net/9p/9p.h>
@@ -52,7 +53,7 @@
52#endif 53#endif
53 54
54static int 55static int
55p9pdu_writef(struct p9_fcall *pdu, int optional, const char *fmt, ...); 56p9pdu_writef(struct p9_fcall *pdu, int proto_version, const char *fmt, ...);
56 57
57#ifdef CONFIG_NET_9P_DEBUG 58#ifdef CONFIG_NET_9P_DEBUG
58void 59void
@@ -144,7 +145,8 @@ pdu_write_u(struct p9_fcall *pdu, const char __user *udata, size_t size)
144*/ 145*/
145 146
146static int 147static int
147p9pdu_vreadf(struct p9_fcall *pdu, int optional, const char *fmt, va_list ap) 148p9pdu_vreadf(struct p9_fcall *pdu, int proto_version, const char *fmt,
149 va_list ap)
148{ 150{
149 const char *ptr; 151 const char *ptr;
150 int errcode = 0; 152 int errcode = 0;
@@ -194,7 +196,8 @@ p9pdu_vreadf(struct p9_fcall *pdu, int optional, const char *fmt, va_list ap)
194 int16_t len; 196 int16_t len;
195 int size; 197 int size;
196 198
197 errcode = p9pdu_readf(pdu, optional, "w", &len); 199 errcode = p9pdu_readf(pdu, proto_version,
200 "w", &len);
198 if (errcode) 201 if (errcode)
199 break; 202 break;
200 203
@@ -217,7 +220,7 @@ p9pdu_vreadf(struct p9_fcall *pdu, int optional, const char *fmt, va_list ap)
217 struct p9_qid *qid = 220 struct p9_qid *qid =
218 va_arg(ap, struct p9_qid *); 221 va_arg(ap, struct p9_qid *);
219 222
220 errcode = p9pdu_readf(pdu, optional, "bdq", 223 errcode = p9pdu_readf(pdu, proto_version, "bdq",
221 &qid->type, &qid->version, 224 &qid->type, &qid->version,
222 &qid->path); 225 &qid->path);
223 } 226 }
@@ -230,7 +233,7 @@ p9pdu_vreadf(struct p9_fcall *pdu, int optional, const char *fmt, va_list ap)
230 stbuf->n_uid = stbuf->n_gid = stbuf->n_muid = 233 stbuf->n_uid = stbuf->n_gid = stbuf->n_muid =
231 -1; 234 -1;
232 errcode = 235 errcode =
233 p9pdu_readf(pdu, optional, 236 p9pdu_readf(pdu, proto_version,
234 "wwdQdddqssss?sddd", 237 "wwdQdddqssss?sddd",
235 &stbuf->size, &stbuf->type, 238 &stbuf->size, &stbuf->type,
236 &stbuf->dev, &stbuf->qid, 239 &stbuf->dev, &stbuf->qid,
@@ -250,7 +253,7 @@ p9pdu_vreadf(struct p9_fcall *pdu, int optional, const char *fmt, va_list ap)
250 void **data = va_arg(ap, void **); 253 void **data = va_arg(ap, void **);
251 254
252 errcode = 255 errcode =
253 p9pdu_readf(pdu, optional, "d", count); 256 p9pdu_readf(pdu, proto_version, "d", count);
254 if (!errcode) { 257 if (!errcode) {
255 *count = 258 *count =
256 MIN(*count, 259 MIN(*count,
@@ -263,8 +266,8 @@ p9pdu_vreadf(struct p9_fcall *pdu, int optional, const char *fmt, va_list ap)
263 int16_t *nwname = va_arg(ap, int16_t *); 266 int16_t *nwname = va_arg(ap, int16_t *);
264 char ***wnames = va_arg(ap, char ***); 267 char ***wnames = va_arg(ap, char ***);
265 268
266 errcode = 269 errcode = p9pdu_readf(pdu, proto_version,
267 p9pdu_readf(pdu, optional, "w", nwname); 270 "w", nwname);
268 if (!errcode) { 271 if (!errcode) {
269 *wnames = 272 *wnames =
270 kmalloc(sizeof(char *) * *nwname, 273 kmalloc(sizeof(char *) * *nwname,
@@ -278,7 +281,8 @@ p9pdu_vreadf(struct p9_fcall *pdu, int optional, const char *fmt, va_list ap)
278 281
279 for (i = 0; i < *nwname; i++) { 282 for (i = 0; i < *nwname; i++) {
280 errcode = 283 errcode =
281 p9pdu_readf(pdu, optional, 284 p9pdu_readf(pdu,
285 proto_version,
282 "s", 286 "s",
283 &(*wnames)[i]); 287 &(*wnames)[i]);
284 if (errcode) 288 if (errcode)
@@ -306,7 +310,7 @@ p9pdu_vreadf(struct p9_fcall *pdu, int optional, const char *fmt, va_list ap)
306 *wqids = NULL; 310 *wqids = NULL;
307 311
308 errcode = 312 errcode =
309 p9pdu_readf(pdu, optional, "w", nwqid); 313 p9pdu_readf(pdu, proto_version, "w", nwqid);
310 if (!errcode) { 314 if (!errcode) {
311 *wqids = 315 *wqids =
312 kmalloc(*nwqid * 316 kmalloc(*nwqid *
@@ -321,7 +325,8 @@ p9pdu_vreadf(struct p9_fcall *pdu, int optional, const char *fmt, va_list ap)
321 325
322 for (i = 0; i < *nwqid; i++) { 326 for (i = 0; i < *nwqid; i++) {
323 errcode = 327 errcode =
324 p9pdu_readf(pdu, optional, 328 p9pdu_readf(pdu,
329 proto_version,
325 "Q", 330 "Q",
326 &(*wqids)[i]); 331 &(*wqids)[i]);
327 if (errcode) 332 if (errcode)
@@ -336,7 +341,7 @@ p9pdu_vreadf(struct p9_fcall *pdu, int optional, const char *fmt, va_list ap)
336 } 341 }
337 break; 342 break;
338 case '?': 343 case '?':
339 if (!optional) 344 if (proto_version != p9_proto_2000u)
340 return 0; 345 return 0;
341 break; 346 break;
342 default: 347 default:
@@ -352,7 +357,8 @@ p9pdu_vreadf(struct p9_fcall *pdu, int optional, const char *fmt, va_list ap)
352} 357}
353 358
354int 359int
355p9pdu_vwritef(struct p9_fcall *pdu, int optional, const char *fmt, va_list ap) 360p9pdu_vwritef(struct p9_fcall *pdu, int proto_version, const char *fmt,
361 va_list ap)
356{ 362{
357 const char *ptr; 363 const char *ptr;
358 int errcode = 0; 364 int errcode = 0;
@@ -389,7 +395,8 @@ p9pdu_vwritef(struct p9_fcall *pdu, int optional, const char *fmt, va_list ap)
389 if (sptr) 395 if (sptr)
390 len = MIN(strlen(sptr), USHORT_MAX); 396 len = MIN(strlen(sptr), USHORT_MAX);
391 397
392 errcode = p9pdu_writef(pdu, optional, "w", len); 398 errcode = p9pdu_writef(pdu, proto_version,
399 "w", len);
393 if (!errcode && pdu_write(pdu, sptr, len)) 400 if (!errcode && pdu_write(pdu, sptr, len))
394 errcode = -EFAULT; 401 errcode = -EFAULT;
395 } 402 }
@@ -398,7 +405,7 @@ p9pdu_vwritef(struct p9_fcall *pdu, int optional, const char *fmt, va_list ap)
398 const struct p9_qid *qid = 405 const struct p9_qid *qid =
399 va_arg(ap, const struct p9_qid *); 406 va_arg(ap, const struct p9_qid *);
400 errcode = 407 errcode =
401 p9pdu_writef(pdu, optional, "bdq", 408 p9pdu_writef(pdu, proto_version, "bdq",
402 qid->type, qid->version, 409 qid->type, qid->version,
403 qid->path); 410 qid->path);
404 } break; 411 } break;
@@ -406,7 +413,7 @@ p9pdu_vwritef(struct p9_fcall *pdu, int optional, const char *fmt, va_list ap)
406 const struct p9_wstat *stbuf = 413 const struct p9_wstat *stbuf =
407 va_arg(ap, const struct p9_wstat *); 414 va_arg(ap, const struct p9_wstat *);
408 errcode = 415 errcode =
409 p9pdu_writef(pdu, optional, 416 p9pdu_writef(pdu, proto_version,
410 "wwdQdddqssss?sddd", 417 "wwdQdddqssss?sddd",
411 stbuf->size, stbuf->type, 418 stbuf->size, stbuf->type,
412 stbuf->dev, &stbuf->qid, 419 stbuf->dev, &stbuf->qid,
@@ -421,8 +428,8 @@ p9pdu_vwritef(struct p9_fcall *pdu, int optional, const char *fmt, va_list ap)
421 int32_t count = va_arg(ap, int32_t); 428 int32_t count = va_arg(ap, int32_t);
422 const void *data = va_arg(ap, const void *); 429 const void *data = va_arg(ap, const void *);
423 430
424 errcode = 431 errcode = p9pdu_writef(pdu, proto_version, "d",
425 p9pdu_writef(pdu, optional, "d", count); 432 count);
426 if (!errcode && pdu_write(pdu, data, count)) 433 if (!errcode && pdu_write(pdu, data, count))
427 errcode = -EFAULT; 434 errcode = -EFAULT;
428 } 435 }
@@ -431,8 +438,8 @@ p9pdu_vwritef(struct p9_fcall *pdu, int optional, const char *fmt, va_list ap)
431 int32_t count = va_arg(ap, int32_t); 438 int32_t count = va_arg(ap, int32_t);
432 const char __user *udata = 439 const char __user *udata =
433 va_arg(ap, const void __user *); 440 va_arg(ap, const void __user *);
434 errcode = 441 errcode = p9pdu_writef(pdu, proto_version, "d",
435 p9pdu_writef(pdu, optional, "d", count); 442 count);
436 if (!errcode && pdu_write_u(pdu, udata, count)) 443 if (!errcode && pdu_write_u(pdu, udata, count))
437 errcode = -EFAULT; 444 errcode = -EFAULT;
438 } 445 }
@@ -441,14 +448,15 @@ p9pdu_vwritef(struct p9_fcall *pdu, int optional, const char *fmt, va_list ap)
441 int16_t nwname = va_arg(ap, int); 448 int16_t nwname = va_arg(ap, int);
442 const char **wnames = va_arg(ap, const char **); 449 const char **wnames = va_arg(ap, const char **);
443 450
444 errcode = 451 errcode = p9pdu_writef(pdu, proto_version, "w",
445 p9pdu_writef(pdu, optional, "w", nwname); 452 nwname);
446 if (!errcode) { 453 if (!errcode) {
447 int i; 454 int i;
448 455
449 for (i = 0; i < nwname; i++) { 456 for (i = 0; i < nwname; i++) {
450 errcode = 457 errcode =
451 p9pdu_writef(pdu, optional, 458 p9pdu_writef(pdu,
459 proto_version,
452 "s", 460 "s",
453 wnames[i]); 461 wnames[i]);
454 if (errcode) 462 if (errcode)
@@ -462,14 +470,15 @@ p9pdu_vwritef(struct p9_fcall *pdu, int optional, const char *fmt, va_list ap)
462 struct p9_qid *wqids = 470 struct p9_qid *wqids =
463 va_arg(ap, struct p9_qid *); 471 va_arg(ap, struct p9_qid *);
464 472
465 errcode = 473 errcode = p9pdu_writef(pdu, proto_version, "w",
466 p9pdu_writef(pdu, optional, "w", nwqid); 474 nwqid);
467 if (!errcode) { 475 if (!errcode) {
468 int i; 476 int i;
469 477
470 for (i = 0; i < nwqid; i++) { 478 for (i = 0; i < nwqid; i++) {
471 errcode = 479 errcode =
472 p9pdu_writef(pdu, optional, 480 p9pdu_writef(pdu,
481 proto_version,
473 "Q", 482 "Q",
474 &wqids[i]); 483 &wqids[i]);
475 if (errcode) 484 if (errcode)
@@ -479,7 +488,7 @@ p9pdu_vwritef(struct p9_fcall *pdu, int optional, const char *fmt, va_list ap)
479 } 488 }
480 break; 489 break;
481 case '?': 490 case '?':
482 if (!optional) 491 if (proto_version != p9_proto_2000u)
483 return 0; 492 return 0;
484 break; 493 break;
485 default: 494 default:
@@ -494,32 +503,32 @@ p9pdu_vwritef(struct p9_fcall *pdu, int optional, const char *fmt, va_list ap)
494 return errcode; 503 return errcode;
495} 504}
496 505
497int p9pdu_readf(struct p9_fcall *pdu, int optional, const char *fmt, ...) 506int p9pdu_readf(struct p9_fcall *pdu, int proto_version, const char *fmt, ...)
498{ 507{
499 va_list ap; 508 va_list ap;
500 int ret; 509 int ret;
501 510
502 va_start(ap, fmt); 511 va_start(ap, fmt);
503 ret = p9pdu_vreadf(pdu, optional, fmt, ap); 512 ret = p9pdu_vreadf(pdu, proto_version, fmt, ap);
504 va_end(ap); 513 va_end(ap);
505 514
506 return ret; 515 return ret;
507} 516}
508 517
509static int 518static int
510p9pdu_writef(struct p9_fcall *pdu, int optional, const char *fmt, ...) 519p9pdu_writef(struct p9_fcall *pdu, int proto_version, const char *fmt, ...)
511{ 520{
512 va_list ap; 521 va_list ap;
513 int ret; 522 int ret;
514 523
515 va_start(ap, fmt); 524 va_start(ap, fmt);
516 ret = p9pdu_vwritef(pdu, optional, fmt, ap); 525 ret = p9pdu_vwritef(pdu, proto_version, fmt, ap);
517 va_end(ap); 526 va_end(ap);
518 527
519 return ret; 528 return ret;
520} 529}
521 530
522int p9stat_read(char *buf, int len, struct p9_wstat *st, int dotu) 531int p9stat_read(char *buf, int len, struct p9_wstat *st, int proto_version)
523{ 532{
524 struct p9_fcall fake_pdu; 533 struct p9_fcall fake_pdu;
525 int ret; 534 int ret;
@@ -529,7 +538,7 @@ int p9stat_read(char *buf, int len, struct p9_wstat *st, int dotu)
529 fake_pdu.sdata = buf; 538 fake_pdu.sdata = buf;
530 fake_pdu.offset = 0; 539 fake_pdu.offset = 0;
531 540
532 ret = p9pdu_readf(&fake_pdu, dotu, "S", st); 541 ret = p9pdu_readf(&fake_pdu, proto_version, "S", st);
533 if (ret) { 542 if (ret) {
534 P9_DPRINTK(P9_DEBUG_9P, "<<< p9stat_read failed: %d\n", ret); 543 P9_DPRINTK(P9_DEBUG_9P, "<<< p9stat_read failed: %d\n", ret);
535 p9pdu_dump(1, &fake_pdu); 544 p9pdu_dump(1, &fake_pdu);
diff --git a/net/9p/protocol.h b/net/9p/protocol.h
index ccde462e7ac5..2431c0f38d56 100644
--- a/net/9p/protocol.h
+++ b/net/9p/protocol.h
@@ -25,9 +25,9 @@
25 * 25 *
26 */ 26 */
27 27
28int 28int p9pdu_vwritef(struct p9_fcall *pdu, int proto_version, const char *fmt,
29p9pdu_vwritef(struct p9_fcall *pdu, int optional, const char *fmt, va_list ap); 29 va_list ap);
30int p9pdu_readf(struct p9_fcall *pdu, int optional, const char *fmt, ...); 30int p9pdu_readf(struct p9_fcall *pdu, int proto_version, const char *fmt, ...);
31int p9pdu_prepare(struct p9_fcall *pdu, int16_t tag, int8_t type); 31int p9pdu_prepare(struct p9_fcall *pdu, int16_t tag, int8_t type);
32int p9pdu_finalize(struct p9_fcall *pdu); 32int p9pdu_finalize(struct p9_fcall *pdu);
33void p9pdu_dump(int, struct p9_fcall *); 33void p9pdu_dump(int, struct p9_fcall *);
diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
index 8d934dd7fd54..98ce9bcb0e15 100644
--- a/net/9p/trans_fd.c
+++ b/net/9p/trans_fd.c
@@ -38,10 +38,13 @@
38#include <linux/idr.h> 38#include <linux/idr.h>
39#include <linux/file.h> 39#include <linux/file.h>
40#include <linux/parser.h> 40#include <linux/parser.h>
41#include <linux/slab.h>
41#include <net/9p/9p.h> 42#include <net/9p/9p.h>
42#include <net/9p/client.h> 43#include <net/9p/client.h>
43#include <net/9p/transport.h> 44#include <net/9p/transport.h>
44 45
46#include <linux/syscalls.h> /* killme */
47
45#define P9_PORT 564 48#define P9_PORT 564
46#define MAX_SOCK_BUF (64*1024) 49#define MAX_SOCK_BUF (64*1024)
47#define MAXPOLLWADDR 2 50#define MAXPOLLWADDR 2
@@ -633,8 +636,8 @@ static void p9_poll_mux(struct p9_conn *m)
633 if (n & POLLOUT) { 636 if (n & POLLOUT) {
634 set_bit(Wpending, &m->wsched); 637 set_bit(Wpending, &m->wsched);
635 P9_DPRINTK(P9_DEBUG_TRANS, "mux %p can write\n", m); 638 P9_DPRINTK(P9_DEBUG_TRANS, "mux %p can write\n", m);
636 if ((m->wsize || !list_empty(&m->unsent_req_list)) 639 if ((m->wsize || !list_empty(&m->unsent_req_list)) &&
637 && !test_and_set_bit(Wworksched, &m->wsched)) { 640 !test_and_set_bit(Wworksched, &m->wsched)) {
638 P9_DPRINTK(P9_DEBUG_TRANS, "sched write work %p\n", m); 641 P9_DPRINTK(P9_DEBUG_TRANS, "sched write work %p\n", m);
639 queue_work(p9_mux_wq, &m->wq); 642 queue_work(p9_mux_wq, &m->wq);
640 } 643 }
@@ -712,7 +715,7 @@ static int parse_opts(char *params, struct p9_fd_opts *opts)
712 char *p; 715 char *p;
713 substring_t args[MAX_OPT_ARGS]; 716 substring_t args[MAX_OPT_ARGS];
714 int option; 717 int option;
715 char *options; 718 char *options, *tmp_options;
716 int ret; 719 int ret;
717 720
718 opts->port = P9_PORT; 721 opts->port = P9_PORT;
@@ -722,12 +725,13 @@ static int parse_opts(char *params, struct p9_fd_opts *opts)
722 if (!params) 725 if (!params)
723 return 0; 726 return 0;
724 727
725 options = kstrdup(params, GFP_KERNEL); 728 tmp_options = kstrdup(params, GFP_KERNEL);
726 if (!options) { 729 if (!tmp_options) {
727 P9_DPRINTK(P9_DEBUG_ERROR, 730 P9_DPRINTK(P9_DEBUG_ERROR,
728 "failed to allocate copy of option string\n"); 731 "failed to allocate copy of option string\n");
729 return -ENOMEM; 732 return -ENOMEM;
730 } 733 }
734 options = tmp_options;
731 735
732 while ((p = strsep(&options, ",")) != NULL) { 736 while ((p = strsep(&options, ",")) != NULL) {
733 int token; 737 int token;
@@ -758,7 +762,8 @@ static int parse_opts(char *params, struct p9_fd_opts *opts)
758 continue; 762 continue;
759 } 763 }
760 } 764 }
761 kfree(options); 765
766 kfree(tmp_options);
762 return 0; 767 return 0;
763} 768}
764 769
@@ -788,24 +793,41 @@ static int p9_fd_open(struct p9_client *client, int rfd, int wfd)
788 793
789static int p9_socket_open(struct p9_client *client, struct socket *csocket) 794static int p9_socket_open(struct p9_client *client, struct socket *csocket)
790{ 795{
791 int fd, ret; 796 struct p9_trans_fd *p;
797 int ret, fd;
798
799 p = kmalloc(sizeof(struct p9_trans_fd), GFP_KERNEL);
800 if (!p)
801 return -ENOMEM;
792 802
793 csocket->sk->sk_allocation = GFP_NOIO; 803 csocket->sk->sk_allocation = GFP_NOIO;
794 fd = sock_map_fd(csocket, 0); 804 fd = sock_map_fd(csocket, 0);
795 if (fd < 0) { 805 if (fd < 0) {
796 P9_EPRINTK(KERN_ERR, "p9_socket_open: failed to map fd\n"); 806 P9_EPRINTK(KERN_ERR, "p9_socket_open: failed to map fd\n");
807 sock_release(csocket);
808 kfree(p);
797 return fd; 809 return fd;
798 } 810 }
799 811
800 ret = p9_fd_open(client, fd, fd); 812 get_file(csocket->file);
801 if (ret < 0) { 813 get_file(csocket->file);
802 P9_EPRINTK(KERN_ERR, "p9_socket_open: failed to open fd\n"); 814 p->wr = p->rd = csocket->file;
815 client->trans = p;
816 client->status = Connected;
817
818 sys_close(fd); /* still racy */
819
820 p->rd->f_flags |= O_NONBLOCK;
821
822 p->conn = p9_conn_create(client);
823 if (IS_ERR(p->conn)) {
824 ret = PTR_ERR(p->conn);
825 p->conn = NULL;
826 kfree(p);
827 sockfd_put(csocket);
803 sockfd_put(csocket); 828 sockfd_put(csocket);
804 return ret; 829 return ret;
805 } 830 }
806
807 ((struct p9_trans_fd *)client->trans)->rd->f_flags |= O_NONBLOCK;
808
809 return 0; 831 return 0;
810} 832}
811 833
@@ -883,7 +905,6 @@ p9_fd_create_tcp(struct p9_client *client, const char *addr, char *args)
883 struct socket *csocket; 905 struct socket *csocket;
884 struct sockaddr_in sin_server; 906 struct sockaddr_in sin_server;
885 struct p9_fd_opts opts; 907 struct p9_fd_opts opts;
886 struct p9_trans_fd *p = NULL; /* this gets allocated in p9_fd_open */
887 908
888 err = parse_opts(args, &opts); 909 err = parse_opts(args, &opts);
889 if (err < 0) 910 if (err < 0)
@@ -897,12 +918,11 @@ p9_fd_create_tcp(struct p9_client *client, const char *addr, char *args)
897 sin_server.sin_family = AF_INET; 918 sin_server.sin_family = AF_INET;
898 sin_server.sin_addr.s_addr = in_aton(addr); 919 sin_server.sin_addr.s_addr = in_aton(addr);
899 sin_server.sin_port = htons(opts.port); 920 sin_server.sin_port = htons(opts.port);
900 sock_create_kern(PF_INET, SOCK_STREAM, IPPROTO_TCP, &csocket); 921 err = sock_create_kern(PF_INET, SOCK_STREAM, IPPROTO_TCP, &csocket);
901 922
902 if (!csocket) { 923 if (err) {
903 P9_EPRINTK(KERN_ERR, "p9_trans_tcp: problem creating socket\n"); 924 P9_EPRINTK(KERN_ERR, "p9_trans_tcp: problem creating socket\n");
904 err = -EIO; 925 return err;
905 goto error;
906 } 926 }
907 927
908 err = csocket->ops->connect(csocket, 928 err = csocket->ops->connect(csocket,
@@ -912,30 +932,11 @@ p9_fd_create_tcp(struct p9_client *client, const char *addr, char *args)
912 P9_EPRINTK(KERN_ERR, 932 P9_EPRINTK(KERN_ERR,
913 "p9_trans_tcp: problem connecting socket to %s\n", 933 "p9_trans_tcp: problem connecting socket to %s\n",
914 addr); 934 addr);
915 goto error;
916 }
917
918 err = p9_socket_open(client, csocket);
919 if (err < 0)
920 goto error;
921
922 p = (struct p9_trans_fd *) client->trans;
923 p->conn = p9_conn_create(client);
924 if (IS_ERR(p->conn)) {
925 err = PTR_ERR(p->conn);
926 p->conn = NULL;
927 goto error;
928 }
929
930 return 0;
931
932error:
933 if (csocket)
934 sock_release(csocket); 935 sock_release(csocket);
936 return err;
937 }
935 938
936 kfree(p); 939 return p9_socket_open(client, csocket);
937
938 return err;
939} 940}
940 941
941static int 942static int
@@ -944,49 +945,33 @@ p9_fd_create_unix(struct p9_client *client, const char *addr, char *args)
944 int err; 945 int err;
945 struct socket *csocket; 946 struct socket *csocket;
946 struct sockaddr_un sun_server; 947 struct sockaddr_un sun_server;
947 struct p9_trans_fd *p = NULL; /* this gets allocated in p9_fd_open */
948 948
949 csocket = NULL; 949 csocket = NULL;
950 950
951 if (strlen(addr) > UNIX_PATH_MAX) { 951 if (strlen(addr) > UNIX_PATH_MAX) {
952 P9_EPRINTK(KERN_ERR, "p9_trans_unix: address too long: %s\n", 952 P9_EPRINTK(KERN_ERR, "p9_trans_unix: address too long: %s\n",
953 addr); 953 addr);
954 err = -ENAMETOOLONG; 954 return -ENAMETOOLONG;
955 goto error;
956 } 955 }
957 956
958 sun_server.sun_family = PF_UNIX; 957 sun_server.sun_family = PF_UNIX;
959 strcpy(sun_server.sun_path, addr); 958 strcpy(sun_server.sun_path, addr);
960 sock_create_kern(PF_UNIX, SOCK_STREAM, 0, &csocket); 959 err = sock_create_kern(PF_UNIX, SOCK_STREAM, 0, &csocket);
960 if (err < 0) {
961 P9_EPRINTK(KERN_ERR, "p9_trans_unix: problem creating socket\n");
962 return err;
963 }
961 err = csocket->ops->connect(csocket, (struct sockaddr *)&sun_server, 964 err = csocket->ops->connect(csocket, (struct sockaddr *)&sun_server,
962 sizeof(struct sockaddr_un) - 1, 0); 965 sizeof(struct sockaddr_un) - 1, 0);
963 if (err < 0) { 966 if (err < 0) {
964 P9_EPRINTK(KERN_ERR, 967 P9_EPRINTK(KERN_ERR,
965 "p9_trans_unix: problem connecting socket: %s: %d\n", 968 "p9_trans_unix: problem connecting socket: %s: %d\n",
966 addr, err); 969 addr, err);
967 goto error;
968 }
969
970 err = p9_socket_open(client, csocket);
971 if (err < 0)
972 goto error;
973
974 p = (struct p9_trans_fd *) client->trans;
975 p->conn = p9_conn_create(client);
976 if (IS_ERR(p->conn)) {
977 err = PTR_ERR(p->conn);
978 p->conn = NULL;
979 goto error;
980 }
981
982 return 0;
983
984error:
985 if (csocket)
986 sock_release(csocket); 970 sock_release(csocket);
971 return err;
972 }
987 973
988 kfree(p); 974 return p9_socket_open(client, csocket);
989 return err;
990} 975}
991 976
992static int 977static int
@@ -994,7 +979,7 @@ p9_fd_create(struct p9_client *client, const char *addr, char *args)
994{ 979{
995 int err; 980 int err;
996 struct p9_fd_opts opts; 981 struct p9_fd_opts opts;
997 struct p9_trans_fd *p = NULL; /* this get allocated in p9_fd_open */ 982 struct p9_trans_fd *p;
998 983
999 parse_opts(args, &opts); 984 parse_opts(args, &opts);
1000 985
@@ -1005,21 +990,19 @@ p9_fd_create(struct p9_client *client, const char *addr, char *args)
1005 990
1006 err = p9_fd_open(client, opts.rfd, opts.wfd); 991 err = p9_fd_open(client, opts.rfd, opts.wfd);
1007 if (err < 0) 992 if (err < 0)
1008 goto error; 993 return err;
1009 994
1010 p = (struct p9_trans_fd *) client->trans; 995 p = (struct p9_trans_fd *) client->trans;
1011 p->conn = p9_conn_create(client); 996 p->conn = p9_conn_create(client);
1012 if (IS_ERR(p->conn)) { 997 if (IS_ERR(p->conn)) {
1013 err = PTR_ERR(p->conn); 998 err = PTR_ERR(p->conn);
1014 p->conn = NULL; 999 p->conn = NULL;
1015 goto error; 1000 fput(p->rd);
1001 fput(p->wr);
1002 return err;
1016 } 1003 }
1017 1004
1018 return 0; 1005 return 0;
1019
1020error:
1021 kfree(p);
1022 return err;
1023} 1006}
1024 1007
1025static struct p9_trans_module p9_tcp_trans = { 1008static struct p9_trans_module p9_tcp_trans = {
diff --git a/net/9p/trans_rdma.c b/net/9p/trans_rdma.c
index 65cb29db03f8..041101ab4aa5 100644
--- a/net/9p/trans_rdma.c
+++ b/net/9p/trans_rdma.c
@@ -40,6 +40,7 @@
40#include <linux/file.h> 40#include <linux/file.h>
41#include <linux/parser.h> 41#include <linux/parser.h>
42#include <linux/semaphore.h> 42#include <linux/semaphore.h>
43#include <linux/slab.h>
43#include <net/9p/9p.h> 44#include <net/9p/9p.h>
44#include <net/9p/client.h> 45#include <net/9p/client.h>
45#include <net/9p/transport.h> 46#include <net/9p/transport.h>
@@ -166,7 +167,7 @@ static int parse_opts(char *params, struct p9_rdma_opts *opts)
166 char *p; 167 char *p;
167 substring_t args[MAX_OPT_ARGS]; 168 substring_t args[MAX_OPT_ARGS];
168 int option; 169 int option;
169 char *options; 170 char *options, *tmp_options;
170 int ret; 171 int ret;
171 172
172 opts->port = P9_PORT; 173 opts->port = P9_PORT;
@@ -177,12 +178,13 @@ static int parse_opts(char *params, struct p9_rdma_opts *opts)
177 if (!params) 178 if (!params)
178 return 0; 179 return 0;
179 180
180 options = kstrdup(params, GFP_KERNEL); 181 tmp_options = kstrdup(params, GFP_KERNEL);
181 if (!options) { 182 if (!tmp_options) {
182 P9_DPRINTK(P9_DEBUG_ERROR, 183 P9_DPRINTK(P9_DEBUG_ERROR,
183 "failed to allocate copy of option string\n"); 184 "failed to allocate copy of option string\n");
184 return -ENOMEM; 185 return -ENOMEM;
185 } 186 }
187 options = tmp_options;
186 188
187 while ((p = strsep(&options, ",")) != NULL) { 189 while ((p = strsep(&options, ",")) != NULL) {
188 int token; 190 int token;
@@ -216,7 +218,7 @@ static int parse_opts(char *params, struct p9_rdma_opts *opts)
216 } 218 }
217 /* RQ must be at least as large as the SQ */ 219 /* RQ must be at least as large as the SQ */
218 opts->rq_depth = max(opts->rq_depth, opts->sq_depth); 220 opts->rq_depth = max(opts->rq_depth, opts->sq_depth);
219 kfree(options); 221 kfree(tmp_options);
220 return 0; 222 return 0;
221} 223}
222 224
diff --git a/net/9p/trans_virtio.c b/net/9p/trans_virtio.c
index ea1e3daabefe..7eb78ecc1618 100644
--- a/net/9p/trans_virtio.c
+++ b/net/9p/trans_virtio.c
@@ -37,6 +37,7 @@
37#include <linux/inet.h> 37#include <linux/inet.h>
38#include <linux/idr.h> 38#include <linux/idr.h>
39#include <linux/file.h> 39#include <linux/file.h>
40#include <linux/slab.h>
40#include <net/9p/9p.h> 41#include <net/9p/9p.h>
41#include <linux/parser.h> 42#include <linux/parser.h>
42#include <net/9p/client.h> 43#include <net/9p/client.h>
@@ -49,8 +50,6 @@
49 50
50/* a single mutex to manage channel initialization and attachment */ 51/* a single mutex to manage channel initialization and attachment */
51static DEFINE_MUTEX(virtio_9p_lock); 52static DEFINE_MUTEX(virtio_9p_lock);
52/* global which tracks highest initialized channel */
53static int chan_index;
54 53
55/** 54/**
56 * struct virtio_chan - per-instance transport information 55 * struct virtio_chan - per-instance transport information
@@ -68,8 +67,7 @@ static int chan_index;
68 * 67 *
69 */ 68 */
70 69
71static struct virtio_chan { 70struct virtio_chan {
72 bool initialized;
73 bool inuse; 71 bool inuse;
74 72
75 spinlock_t lock; 73 spinlock_t lock;
@@ -80,7 +78,17 @@ static struct virtio_chan {
80 78
81 /* Scatterlist: can be too big for stack. */ 79 /* Scatterlist: can be too big for stack. */
82 struct scatterlist sg[VIRTQUEUE_NUM]; 80 struct scatterlist sg[VIRTQUEUE_NUM];
83} channels[MAX_9P_CHAN]; 81
82 int tag_len;
83 /*
84 * tag name to identify a mount Non-null terminated
85 */
86 char *tag;
87
88 struct list_head chan_list;
89};
90
91static struct list_head virtio_chan_list;
84 92
85/* How many bytes left in this page. */ 93/* How many bytes left in this page. */
86static unsigned int rest_of_page(void *data) 94static unsigned int rest_of_page(void *data)
@@ -102,7 +110,8 @@ static void p9_virtio_close(struct p9_client *client)
102 struct virtio_chan *chan = client->trans; 110 struct virtio_chan *chan = client->trans;
103 111
104 mutex_lock(&virtio_9p_lock); 112 mutex_lock(&virtio_9p_lock);
105 chan->inuse = false; 113 if (chan)
114 chan->inuse = false;
106 mutex_unlock(&virtio_9p_lock); 115 mutex_unlock(&virtio_9p_lock);
107} 116}
108 117
@@ -212,30 +221,38 @@ p9_virtio_request(struct p9_client *client, struct p9_req_t *req)
212 return 0; 221 return 0;
213} 222}
214 223
224static ssize_t p9_mount_tag_show(struct device *dev,
225 struct device_attribute *attr, char *buf)
226{
227 struct virtio_chan *chan;
228 struct virtio_device *vdev;
229
230 vdev = dev_to_virtio(dev);
231 chan = vdev->priv;
232
233 return snprintf(buf, chan->tag_len + 1, "%s", chan->tag);
234}
235
236static DEVICE_ATTR(mount_tag, 0444, p9_mount_tag_show, NULL);
237
215/** 238/**
216 * p9_virtio_probe - probe for existence of 9P virtio channels 239 * p9_virtio_probe - probe for existence of 9P virtio channels
217 * @vdev: virtio device to probe 240 * @vdev: virtio device to probe
218 * 241 *
219 * This probes for existing virtio channels. At present only 242 * This probes for existing virtio channels.
220 * a single channel is in use, so in the future more work may need
221 * to be done here.
222 * 243 *
223 */ 244 */
224 245
225static int p9_virtio_probe(struct virtio_device *vdev) 246static int p9_virtio_probe(struct virtio_device *vdev)
226{ 247{
248 __u16 tag_len;
249 char *tag;
227 int err; 250 int err;
228 struct virtio_chan *chan; 251 struct virtio_chan *chan;
229 int index;
230 252
231 mutex_lock(&virtio_9p_lock); 253 chan = kmalloc(sizeof(struct virtio_chan), GFP_KERNEL);
232 index = chan_index++; 254 if (!chan) {
233 chan = &channels[index]; 255 printk(KERN_ERR "9p: Failed to allocate virtio 9P channel\n");
234 mutex_unlock(&virtio_9p_lock);
235
236 if (chan_index > MAX_9P_CHAN) {
237 printk(KERN_ERR "9p: virtio: Maximum channels exceeded\n");
238 BUG();
239 err = -ENOMEM; 256 err = -ENOMEM;
240 goto fail; 257 goto fail;
241 } 258 }
@@ -254,15 +271,37 @@ static int p9_virtio_probe(struct virtio_device *vdev)
254 sg_init_table(chan->sg, VIRTQUEUE_NUM); 271 sg_init_table(chan->sg, VIRTQUEUE_NUM);
255 272
256 chan->inuse = false; 273 chan->inuse = false;
257 chan->initialized = true; 274 if (virtio_has_feature(vdev, VIRTIO_9P_MOUNT_TAG)) {
275 vdev->config->get(vdev,
276 offsetof(struct virtio_9p_config, tag_len),
277 &tag_len, sizeof(tag_len));
278 } else {
279 err = -EINVAL;
280 goto out_free_vq;
281 }
282 tag = kmalloc(tag_len, GFP_KERNEL);
283 if (!tag) {
284 err = -ENOMEM;
285 goto out_free_vq;
286 }
287 vdev->config->get(vdev, offsetof(struct virtio_9p_config, tag),
288 tag, tag_len);
289 chan->tag = tag;
290 chan->tag_len = tag_len;
291 err = sysfs_create_file(&(vdev->dev.kobj), &dev_attr_mount_tag.attr);
292 if (err) {
293 kfree(tag);
294 goto out_free_vq;
295 }
296 mutex_lock(&virtio_9p_lock);
297 list_add_tail(&chan->chan_list, &virtio_chan_list);
298 mutex_unlock(&virtio_9p_lock);
258 return 0; 299 return 0;
259 300
260out_free_vq: 301out_free_vq:
261 vdev->config->del_vqs(vdev); 302 vdev->config->del_vqs(vdev);
303 kfree(chan);
262fail: 304fail:
263 mutex_lock(&virtio_9p_lock);
264 chan_index--;
265 mutex_unlock(&virtio_9p_lock);
266 return err; 305 return err;
267} 306}
268 307
@@ -279,38 +318,35 @@ fail:
279 * We use a simple reference count mechanism to ensure that only a single 318 * We use a simple reference count mechanism to ensure that only a single
280 * mount has a channel open at a time. 319 * mount has a channel open at a time.
281 * 320 *
282 * Bugs: doesn't allow identification of a specific channel
283 * to allocate, channels are allocated sequentially. This was
284 * a pragmatic decision to get things rolling, but ideally some
285 * way of identifying the channel to attach to would be nice
286 * if we are going to support multiple channels.
287 *
288 */ 321 */
289 322
290static int 323static int
291p9_virtio_create(struct p9_client *client, const char *devname, char *args) 324p9_virtio_create(struct p9_client *client, const char *devname, char *args)
292{ 325{
293 struct virtio_chan *chan = channels; 326 struct virtio_chan *chan;
294 int index = 0; 327 int ret = -ENOENT;
328 int found = 0;
295 329
296 mutex_lock(&virtio_9p_lock); 330 mutex_lock(&virtio_9p_lock);
297 while (index < MAX_9P_CHAN) { 331 list_for_each_entry(chan, &virtio_chan_list, chan_list) {
298 if (chan->initialized && !chan->inuse) { 332 if (!strncmp(devname, chan->tag, chan->tag_len)) {
299 chan->inuse = true; 333 if (!chan->inuse) {
300 break; 334 chan->inuse = true;
301 } else { 335 found = 1;
302 index++; 336 break;
303 chan = &channels[index]; 337 }
338 ret = -EBUSY;
304 } 339 }
305 } 340 }
306 mutex_unlock(&virtio_9p_lock); 341 mutex_unlock(&virtio_9p_lock);
307 342
308 if (index >= MAX_9P_CHAN) { 343 if (!found) {
309 printk(KERN_ERR "9p: no channels available\n"); 344 printk(KERN_ERR "9p: no channels available\n");
310 return -ENODEV; 345 return ret;
311 } 346 }
312 347
313 client->trans = (void *)chan; 348 client->trans = (void *)chan;
349 client->status = Connected;
314 chan->client = client; 350 chan->client = client;
315 351
316 return 0; 352 return 0;
@@ -327,11 +363,15 @@ static void p9_virtio_remove(struct virtio_device *vdev)
327 struct virtio_chan *chan = vdev->priv; 363 struct virtio_chan *chan = vdev->priv;
328 364
329 BUG_ON(chan->inuse); 365 BUG_ON(chan->inuse);
366 vdev->config->del_vqs(vdev);
367
368 mutex_lock(&virtio_9p_lock);
369 list_del(&chan->chan_list);
370 mutex_unlock(&virtio_9p_lock);
371 sysfs_remove_file(&(vdev->dev.kobj), &dev_attr_mount_tag.attr);
372 kfree(chan->tag);
373 kfree(chan);
330 374
331 if (chan->initialized) {
332 vdev->config->del_vqs(vdev);
333 chan->initialized = false;
334 }
335} 375}
336 376
337static struct virtio_device_id id_table[] = { 377static struct virtio_device_id id_table[] = {
@@ -339,13 +379,19 @@ static struct virtio_device_id id_table[] = {
339 { 0 }, 379 { 0 },
340}; 380};
341 381
382static unsigned int features[] = {
383 VIRTIO_9P_MOUNT_TAG,
384};
385
342/* The standard "struct lguest_driver": */ 386/* The standard "struct lguest_driver": */
343static struct virtio_driver p9_virtio_drv = { 387static struct virtio_driver p9_virtio_drv = {
344 .driver.name = KBUILD_MODNAME, 388 .feature_table = features,
345 .driver.owner = THIS_MODULE, 389 .feature_table_size = ARRAY_SIZE(features),
346 .id_table = id_table, 390 .driver.name = KBUILD_MODNAME,
347 .probe = p9_virtio_probe, 391 .driver.owner = THIS_MODULE,
348 .remove = p9_virtio_remove, 392 .id_table = id_table,
393 .probe = p9_virtio_probe,
394 .remove = p9_virtio_remove,
349}; 395};
350 396
351static struct p9_trans_module p9_virtio_trans = { 397static struct p9_trans_module p9_virtio_trans = {
@@ -362,10 +408,7 @@ static struct p9_trans_module p9_virtio_trans = {
362/* The standard init function */ 408/* The standard init function */
363static int __init p9_virtio_init(void) 409static int __init p9_virtio_init(void)
364{ 410{
365 int count; 411 INIT_LIST_HEAD(&virtio_chan_list);
366
367 for (count = 0; count < MAX_9P_CHAN; count++)
368 channels[count].initialized = false;
369 412
370 v9fs_register_trans(&p9_virtio_trans); 413 v9fs_register_trans(&p9_virtio_trans);
371 return register_virtio_driver(&p9_virtio_drv); 414 return register_virtio_driver(&p9_virtio_drv);
diff --git a/net/9p/util.c b/net/9p/util.c
index dc4ec05ad93d..e048701a72d2 100644
--- a/net/9p/util.c
+++ b/net/9p/util.c
@@ -30,6 +30,7 @@
30#include <linux/sched.h> 30#include <linux/sched.h>
31#include <linux/parser.h> 31#include <linux/parser.h>
32#include <linux/idr.h> 32#include <linux/idr.h>
33#include <linux/slab.h>
33#include <net/9p/9p.h> 34#include <net/9p/9p.h>
34 35
35/** 36/**
diff --git a/net/appletalk/aarp.c b/net/appletalk/aarp.c
index 9d4adfd22757..50dce7981321 100644
--- a/net/appletalk/aarp.c
+++ b/net/appletalk/aarp.c
@@ -30,6 +30,7 @@
30 */ 30 */
31 31
32#include <linux/if_arp.h> 32#include <linux/if_arp.h>
33#include <linux/slab.h>
33#include <net/sock.h> 34#include <net/sock.h>
34#include <net/datalink.h> 35#include <net/datalink.h>
35#include <net/psnap.h> 36#include <net/psnap.h>
@@ -819,7 +820,7 @@ static int aarp_rcv(struct sk_buff *skb, struct net_device *dev,
819 ma = &ifa->address; 820 ma = &ifa->address;
820 else { /* We need to make a copy of the entry. */ 821 else { /* We need to make a copy of the entry. */
821 da.s_node = sa.s_node; 822 da.s_node = sa.s_node;
822 da.s_net = da.s_net; 823 da.s_net = sa.s_net;
823 ma = &da; 824 ma = &da;
824 } 825 }
825 826
diff --git a/net/appletalk/atalk_proc.c b/net/appletalk/atalk_proc.c
index 80caad1a31a5..6ef0e761e5de 100644
--- a/net/appletalk/atalk_proc.c
+++ b/net/appletalk/atalk_proc.c
@@ -144,40 +144,16 @@ out:
144 return 0; 144 return 0;
145} 145}
146 146
147static __inline__ struct sock *atalk_get_socket_idx(loff_t pos)
148{
149 struct sock *s;
150 struct hlist_node *node;
151
152 sk_for_each(s, node, &atalk_sockets)
153 if (!pos--)
154 goto found;
155 s = NULL;
156found:
157 return s;
158}
159
160static void *atalk_seq_socket_start(struct seq_file *seq, loff_t *pos) 147static void *atalk_seq_socket_start(struct seq_file *seq, loff_t *pos)
161 __acquires(atalk_sockets_lock) 148 __acquires(atalk_sockets_lock)
162{ 149{
163 loff_t l = *pos;
164
165 read_lock_bh(&atalk_sockets_lock); 150 read_lock_bh(&atalk_sockets_lock);
166 return l ? atalk_get_socket_idx(--l) : SEQ_START_TOKEN; 151 return seq_hlist_start_head(&atalk_sockets, *pos);
167} 152}
168 153
169static void *atalk_seq_socket_next(struct seq_file *seq, void *v, loff_t *pos) 154static void *atalk_seq_socket_next(struct seq_file *seq, void *v, loff_t *pos)
170{ 155{
171 struct sock *i; 156 return seq_hlist_next(v, &atalk_sockets, pos);
172
173 ++*pos;
174 if (v == SEQ_START_TOKEN) {
175 i = sk_head(&atalk_sockets);
176 goto out;
177 }
178 i = sk_next(v);
179out:
180 return i;
181} 157}
182 158
183static void atalk_seq_socket_stop(struct seq_file *seq, void *v) 159static void atalk_seq_socket_stop(struct seq_file *seq, void *v)
@@ -197,7 +173,7 @@ static int atalk_seq_socket_show(struct seq_file *seq, void *v)
197 goto out; 173 goto out;
198 } 174 }
199 175
200 s = v; 176 s = sk_entry(v);
201 at = at_sk(s); 177 at = at_sk(s);
202 178
203 seq_printf(seq, "%02X %04X:%02X:%02X %04X:%02X:%02X %08X:%08X " 179 seq_printf(seq, "%02X %04X:%02X:%02X %04X:%02X:%02X %08X:%08X "
diff --git a/net/appletalk/ddp.c b/net/appletalk/ddp.c
index b1a4290996b5..7b02967fbbe7 100644
--- a/net/appletalk/ddp.c
+++ b/net/appletalk/ddp.c
@@ -56,6 +56,8 @@
56#include <linux/if_arp.h> 56#include <linux/if_arp.h>
57#include <linux/smp_lock.h> 57#include <linux/smp_lock.h>
58#include <linux/termios.h> /* For TIOCOUTQ/INQ */ 58#include <linux/termios.h> /* For TIOCOUTQ/INQ */
59#include <linux/compat.h>
60#include <linux/slab.h>
59#include <net/datalink.h> 61#include <net/datalink.h>
60#include <net/psnap.h> 62#include <net/psnap.h>
61#include <net/sock.h> 63#include <net/sock.h>
@@ -922,13 +924,8 @@ static unsigned long atalk_sum_partial(const unsigned char *data,
922{ 924{
923 /* This ought to be unwrapped neatly. I'll trust gcc for now */ 925 /* This ought to be unwrapped neatly. I'll trust gcc for now */
924 while (len--) { 926 while (len--) {
925 sum += *data; 927 sum += *data++;
926 sum <<= 1; 928 sum = rol16(sum, 1);
927 if (sum & 0x10000) {
928 sum++;
929 sum &= 0xffff;
930 }
931 data++;
932 } 929 }
933 return sum; 930 return sum;
934} 931}
@@ -1021,12 +1018,13 @@ static struct proto ddp_proto = {
1021 * Create a socket. Initialise the socket, blank the addresses 1018 * Create a socket. Initialise the socket, blank the addresses
1022 * set the state. 1019 * set the state.
1023 */ 1020 */
1024static int atalk_create(struct net *net, struct socket *sock, int protocol) 1021static int atalk_create(struct net *net, struct socket *sock, int protocol,
1022 int kern)
1025{ 1023{
1026 struct sock *sk; 1024 struct sock *sk;
1027 int rc = -ESOCKTNOSUPPORT; 1025 int rc = -ESOCKTNOSUPPORT;
1028 1026
1029 if (net != &init_net) 1027 if (!net_eq(net, &init_net))
1030 return -EAFNOSUPPORT; 1028 return -EAFNOSUPPORT;
1031 1029
1032 /* 1030 /*
@@ -1054,11 +1052,13 @@ static int atalk_release(struct socket *sock)
1054{ 1052{
1055 struct sock *sk = sock->sk; 1053 struct sock *sk = sock->sk;
1056 1054
1055 lock_kernel();
1057 if (sk) { 1056 if (sk) {
1058 sock_orphan(sk); 1057 sock_orphan(sk);
1059 sock->sk = NULL; 1058 sock->sk = NULL;
1060 atalk_destroy_socket(sk); 1059 atalk_destroy_socket(sk);
1061 } 1060 }
1061 unlock_kernel();
1062 return 0; 1062 return 0;
1063} 1063}
1064 1064
@@ -1134,6 +1134,7 @@ static int atalk_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
1134 struct sockaddr_at *addr = (struct sockaddr_at *)uaddr; 1134 struct sockaddr_at *addr = (struct sockaddr_at *)uaddr;
1135 struct sock *sk = sock->sk; 1135 struct sock *sk = sock->sk;
1136 struct atalk_sock *at = at_sk(sk); 1136 struct atalk_sock *at = at_sk(sk);
1137 int err;
1137 1138
1138 if (!sock_flag(sk, SOCK_ZAPPED) || 1139 if (!sock_flag(sk, SOCK_ZAPPED) ||
1139 addr_len != sizeof(struct sockaddr_at)) 1140 addr_len != sizeof(struct sockaddr_at))
@@ -1142,37 +1143,44 @@ static int atalk_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
1142 if (addr->sat_family != AF_APPLETALK) 1143 if (addr->sat_family != AF_APPLETALK)
1143 return -EAFNOSUPPORT; 1144 return -EAFNOSUPPORT;
1144 1145
1146 lock_kernel();
1145 if (addr->sat_addr.s_net == htons(ATADDR_ANYNET)) { 1147 if (addr->sat_addr.s_net == htons(ATADDR_ANYNET)) {
1146 struct atalk_addr *ap = atalk_find_primary(); 1148 struct atalk_addr *ap = atalk_find_primary();
1147 1149
1150 err = -EADDRNOTAVAIL;
1148 if (!ap) 1151 if (!ap)
1149 return -EADDRNOTAVAIL; 1152 goto out;
1150 1153
1151 at->src_net = addr->sat_addr.s_net = ap->s_net; 1154 at->src_net = addr->sat_addr.s_net = ap->s_net;
1152 at->src_node = addr->sat_addr.s_node= ap->s_node; 1155 at->src_node = addr->sat_addr.s_node= ap->s_node;
1153 } else { 1156 } else {
1157 err = -EADDRNOTAVAIL;
1154 if (!atalk_find_interface(addr->sat_addr.s_net, 1158 if (!atalk_find_interface(addr->sat_addr.s_net,
1155 addr->sat_addr.s_node)) 1159 addr->sat_addr.s_node))
1156 return -EADDRNOTAVAIL; 1160 goto out;
1157 1161
1158 at->src_net = addr->sat_addr.s_net; 1162 at->src_net = addr->sat_addr.s_net;
1159 at->src_node = addr->sat_addr.s_node; 1163 at->src_node = addr->sat_addr.s_node;
1160 } 1164 }
1161 1165
1162 if (addr->sat_port == ATADDR_ANYPORT) { 1166 if (addr->sat_port == ATADDR_ANYPORT) {
1163 int n = atalk_pick_and_bind_port(sk, addr); 1167 err = atalk_pick_and_bind_port(sk, addr);
1164 1168
1165 if (n < 0) 1169 if (err < 0)
1166 return n; 1170 goto out;
1167 } else { 1171 } else {
1168 at->src_port = addr->sat_port; 1172 at->src_port = addr->sat_port;
1169 1173
1174 err = -EADDRINUSE;
1170 if (atalk_find_or_insert_socket(sk, addr)) 1175 if (atalk_find_or_insert_socket(sk, addr))
1171 return -EADDRINUSE; 1176 goto out;
1172 } 1177 }
1173 1178
1174 sock_reset_flag(sk, SOCK_ZAPPED); 1179 sock_reset_flag(sk, SOCK_ZAPPED);
1175 return 0; 1180 err = 0;
1181out:
1182 unlock_kernel();
1183 return err;
1176} 1184}
1177 1185
1178/* Set the address we talk to */ 1186/* Set the address we talk to */
@@ -1182,6 +1190,7 @@ static int atalk_connect(struct socket *sock, struct sockaddr *uaddr,
1182 struct sock *sk = sock->sk; 1190 struct sock *sk = sock->sk;
1183 struct atalk_sock *at = at_sk(sk); 1191 struct atalk_sock *at = at_sk(sk);
1184 struct sockaddr_at *addr; 1192 struct sockaddr_at *addr;
1193 int err;
1185 1194
1186 sk->sk_state = TCP_CLOSE; 1195 sk->sk_state = TCP_CLOSE;
1187 sock->state = SS_UNCONNECTED; 1196 sock->state = SS_UNCONNECTED;
@@ -1206,12 +1215,15 @@ static int atalk_connect(struct socket *sock, struct sockaddr *uaddr,
1206#endif 1215#endif
1207 } 1216 }
1208 1217
1218 lock_kernel();
1219 err = -EBUSY;
1209 if (sock_flag(sk, SOCK_ZAPPED)) 1220 if (sock_flag(sk, SOCK_ZAPPED))
1210 if (atalk_autobind(sk) < 0) 1221 if (atalk_autobind(sk) < 0)
1211 return -EBUSY; 1222 goto out;
1212 1223
1224 err = -ENETUNREACH;
1213 if (!atrtr_get_dev(&addr->sat_addr)) 1225 if (!atrtr_get_dev(&addr->sat_addr))
1214 return -ENETUNREACH; 1226 goto out;
1215 1227
1216 at->dest_port = addr->sat_port; 1228 at->dest_port = addr->sat_port;
1217 at->dest_net = addr->sat_addr.s_net; 1229 at->dest_net = addr->sat_addr.s_net;
@@ -1219,7 +1231,10 @@ static int atalk_connect(struct socket *sock, struct sockaddr *uaddr,
1219 1231
1220 sock->state = SS_CONNECTED; 1232 sock->state = SS_CONNECTED;
1221 sk->sk_state = TCP_ESTABLISHED; 1233 sk->sk_state = TCP_ESTABLISHED;
1222 return 0; 1234 err = 0;
1235out:
1236 unlock_kernel();
1237 return err;
1223} 1238}
1224 1239
1225/* 1240/*
@@ -1232,17 +1247,21 @@ static int atalk_getname(struct socket *sock, struct sockaddr *uaddr,
1232 struct sockaddr_at sat; 1247 struct sockaddr_at sat;
1233 struct sock *sk = sock->sk; 1248 struct sock *sk = sock->sk;
1234 struct atalk_sock *at = at_sk(sk); 1249 struct atalk_sock *at = at_sk(sk);
1250 int err;
1235 1251
1252 lock_kernel();
1253 err = -ENOBUFS;
1236 if (sock_flag(sk, SOCK_ZAPPED)) 1254 if (sock_flag(sk, SOCK_ZAPPED))
1237 if (atalk_autobind(sk) < 0) 1255 if (atalk_autobind(sk) < 0)
1238 return -ENOBUFS; 1256 goto out;
1239 1257
1240 *uaddr_len = sizeof(struct sockaddr_at); 1258 *uaddr_len = sizeof(struct sockaddr_at);
1241 memset(&sat.sat_zero, 0, sizeof(sat.sat_zero)); 1259 memset(&sat.sat_zero, 0, sizeof(sat.sat_zero));
1242 1260
1243 if (peer) { 1261 if (peer) {
1262 err = -ENOTCONN;
1244 if (sk->sk_state != TCP_ESTABLISHED) 1263 if (sk->sk_state != TCP_ESTABLISHED)
1245 return -ENOTCONN; 1264 goto out;
1246 1265
1247 sat.sat_addr.s_net = at->dest_net; 1266 sat.sat_addr.s_net = at->dest_net;
1248 sat.sat_addr.s_node = at->dest_node; 1267 sat.sat_addr.s_node = at->dest_node;
@@ -1253,9 +1272,23 @@ static int atalk_getname(struct socket *sock, struct sockaddr *uaddr,
1253 sat.sat_port = at->src_port; 1272 sat.sat_port = at->src_port;
1254 } 1273 }
1255 1274
1275 err = 0;
1256 sat.sat_family = AF_APPLETALK; 1276 sat.sat_family = AF_APPLETALK;
1257 memcpy(uaddr, &sat, sizeof(sat)); 1277 memcpy(uaddr, &sat, sizeof(sat));
1258 return 0; 1278
1279out:
1280 unlock_kernel();
1281 return err;
1282}
1283
1284static unsigned int atalk_poll(struct file *file, struct socket *sock,
1285 poll_table *wait)
1286{
1287 int err;
1288 lock_kernel();
1289 err = datagram_poll(file, sock, wait);
1290 unlock_kernel();
1291 return err;
1259} 1292}
1260 1293
1261#if defined(CONFIG_IPDDP) || defined(CONFIG_IPDDP_MODULE) 1294#if defined(CONFIG_IPDDP) || defined(CONFIG_IPDDP_MODULE)
@@ -1563,23 +1596,28 @@ static int atalk_sendmsg(struct kiocb *iocb, struct socket *sock, struct msghdr
1563 if (len > DDP_MAXSZ) 1596 if (len > DDP_MAXSZ)
1564 return -EMSGSIZE; 1597 return -EMSGSIZE;
1565 1598
1599 lock_kernel();
1566 if (usat) { 1600 if (usat) {
1601 err = -EBUSY;
1567 if (sock_flag(sk, SOCK_ZAPPED)) 1602 if (sock_flag(sk, SOCK_ZAPPED))
1568 if (atalk_autobind(sk) < 0) 1603 if (atalk_autobind(sk) < 0)
1569 return -EBUSY; 1604 goto out;
1570 1605
1606 err = -EINVAL;
1571 if (msg->msg_namelen < sizeof(*usat) || 1607 if (msg->msg_namelen < sizeof(*usat) ||
1572 usat->sat_family != AF_APPLETALK) 1608 usat->sat_family != AF_APPLETALK)
1573 return -EINVAL; 1609 goto out;
1574 1610
1611 err = -EPERM;
1575 /* netatalk didn't implement this check */ 1612 /* netatalk didn't implement this check */
1576 if (usat->sat_addr.s_node == ATADDR_BCAST && 1613 if (usat->sat_addr.s_node == ATADDR_BCAST &&
1577 !sock_flag(sk, SOCK_BROADCAST)) { 1614 !sock_flag(sk, SOCK_BROADCAST)) {
1578 return -EPERM; 1615 goto out;
1579 } 1616 }
1580 } else { 1617 } else {
1618 err = -ENOTCONN;
1581 if (sk->sk_state != TCP_ESTABLISHED) 1619 if (sk->sk_state != TCP_ESTABLISHED)
1582 return -ENOTCONN; 1620 goto out;
1583 usat = &local_satalk; 1621 usat = &local_satalk;
1584 usat->sat_family = AF_APPLETALK; 1622 usat->sat_family = AF_APPLETALK;
1585 usat->sat_port = at->dest_port; 1623 usat->sat_port = at->dest_port;
@@ -1603,8 +1641,9 @@ static int atalk_sendmsg(struct kiocb *iocb, struct socket *sock, struct msghdr
1603 1641
1604 rt = atrtr_find(&at_hint); 1642 rt = atrtr_find(&at_hint);
1605 } 1643 }
1644 err = ENETUNREACH;
1606 if (!rt) 1645 if (!rt)
1607 return -ENETUNREACH; 1646 goto out;
1608 1647
1609 dev = rt->dev; 1648 dev = rt->dev;
1610 1649
@@ -1614,7 +1653,7 @@ static int atalk_sendmsg(struct kiocb *iocb, struct socket *sock, struct msghdr
1614 size += dev->hard_header_len; 1653 size += dev->hard_header_len;
1615 skb = sock_alloc_send_skb(sk, size, (flags & MSG_DONTWAIT), &err); 1654 skb = sock_alloc_send_skb(sk, size, (flags & MSG_DONTWAIT), &err);
1616 if (!skb) 1655 if (!skb)
1617 return err; 1656 goto out;
1618 1657
1619 skb->sk = sk; 1658 skb->sk = sk;
1620 skb_reserve(skb, ddp_dl->header_length); 1659 skb_reserve(skb, ddp_dl->header_length);
@@ -1637,7 +1676,8 @@ static int atalk_sendmsg(struct kiocb *iocb, struct socket *sock, struct msghdr
1637 err = memcpy_fromiovec(skb_put(skb, len), msg->msg_iov, len); 1676 err = memcpy_fromiovec(skb_put(skb, len), msg->msg_iov, len);
1638 if (err) { 1677 if (err) {
1639 kfree_skb(skb); 1678 kfree_skb(skb);
1640 return -EFAULT; 1679 err = -EFAULT;
1680 goto out;
1641 } 1681 }
1642 1682
1643 if (sk->sk_no_check == 1) 1683 if (sk->sk_no_check == 1)
@@ -1676,7 +1716,8 @@ static int atalk_sendmsg(struct kiocb *iocb, struct socket *sock, struct msghdr
1676 rt = atrtr_find(&at_lo); 1716 rt = atrtr_find(&at_lo);
1677 if (!rt) { 1717 if (!rt) {
1678 kfree_skb(skb); 1718 kfree_skb(skb);
1679 return -ENETUNREACH; 1719 err = -ENETUNREACH;
1720 goto out;
1680 } 1721 }
1681 dev = rt->dev; 1722 dev = rt->dev;
1682 skb->dev = dev; 1723 skb->dev = dev;
@@ -1696,7 +1737,9 @@ static int atalk_sendmsg(struct kiocb *iocb, struct socket *sock, struct msghdr
1696 } 1737 }
1697 SOCK_DEBUG(sk, "SK %p: Done write (%Zd).\n", sk, len); 1738 SOCK_DEBUG(sk, "SK %p: Done write (%Zd).\n", sk, len);
1698 1739
1699 return len; 1740out:
1741 unlock_kernel();
1742 return err ? : len;
1700} 1743}
1701 1744
1702static int atalk_recvmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *msg, 1745static int atalk_recvmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *msg,
@@ -1708,10 +1751,13 @@ static int atalk_recvmsg(struct kiocb *iocb, struct socket *sock, struct msghdr
1708 int copied = 0; 1751 int copied = 0;
1709 int offset = 0; 1752 int offset = 0;
1710 int err = 0; 1753 int err = 0;
1711 struct sk_buff *skb = skb_recv_datagram(sk, flags & ~MSG_DONTWAIT, 1754 struct sk_buff *skb;
1755
1756 lock_kernel();
1757 skb = skb_recv_datagram(sk, flags & ~MSG_DONTWAIT,
1712 flags & MSG_DONTWAIT, &err); 1758 flags & MSG_DONTWAIT, &err);
1713 if (!skb) 1759 if (!skb)
1714 return err; 1760 goto out;
1715 1761
1716 /* FIXME: use skb->cb to be able to use shared skbs */ 1762 /* FIXME: use skb->cb to be able to use shared skbs */
1717 ddp = ddp_hdr(skb); 1763 ddp = ddp_hdr(skb);
@@ -1739,6 +1785,9 @@ static int atalk_recvmsg(struct kiocb *iocb, struct socket *sock, struct msghdr
1739 } 1785 }
1740 1786
1741 skb_free_datagram(sk, skb); /* Free the datagram. */ 1787 skb_free_datagram(sk, skb); /* Free the datagram. */
1788
1789out:
1790 unlock_kernel();
1742 return err ? : copied; 1791 return err ? : copied;
1743} 1792}
1744 1793
@@ -1810,24 +1859,26 @@ static int atalk_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
1810static int atalk_compat_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg) 1859static int atalk_compat_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
1811{ 1860{
1812 /* 1861 /*
1813 * All Appletalk ioctls except SIOCATALKDIFADDR are standard. And 1862 * SIOCATALKDIFADDR is a SIOCPROTOPRIVATE ioctl number, so we
1814 * SIOCATALKDIFADDR is handled by upper layer as well, so there is 1863 * cannot handle it in common code. The data we access if ifreq
1815 * nothing to do. Eventually SIOCATALKDIFADDR should be moved 1864 * here is compatible, so we can simply call the native
1816 * here so there is no generic SIOCPROTOPRIVATE translation in the 1865 * handler.
1817 * system.
1818 */ 1866 */
1867 if (cmd == SIOCATALKDIFADDR)
1868 return atalk_ioctl(sock, cmd, (unsigned long)compat_ptr(arg));
1869
1819 return -ENOIOCTLCMD; 1870 return -ENOIOCTLCMD;
1820} 1871}
1821#endif 1872#endif
1822 1873
1823 1874
1824static struct net_proto_family atalk_family_ops = { 1875static const struct net_proto_family atalk_family_ops = {
1825 .family = PF_APPLETALK, 1876 .family = PF_APPLETALK,
1826 .create = atalk_create, 1877 .create = atalk_create,
1827 .owner = THIS_MODULE, 1878 .owner = THIS_MODULE,
1828}; 1879};
1829 1880
1830static const struct proto_ops SOCKOPS_WRAPPED(atalk_dgram_ops) = { 1881static const struct proto_ops atalk_dgram_ops = {
1831 .family = PF_APPLETALK, 1882 .family = PF_APPLETALK,
1832 .owner = THIS_MODULE, 1883 .owner = THIS_MODULE,
1833 .release = atalk_release, 1884 .release = atalk_release,
@@ -1836,7 +1887,7 @@ static const struct proto_ops SOCKOPS_WRAPPED(atalk_dgram_ops) = {
1836 .socketpair = sock_no_socketpair, 1887 .socketpair = sock_no_socketpair,
1837 .accept = sock_no_accept, 1888 .accept = sock_no_accept,
1838 .getname = atalk_getname, 1889 .getname = atalk_getname,
1839 .poll = datagram_poll, 1890 .poll = atalk_poll,
1840 .ioctl = atalk_ioctl, 1891 .ioctl = atalk_ioctl,
1841#ifdef CONFIG_COMPAT 1892#ifdef CONFIG_COMPAT
1842 .compat_ioctl = atalk_compat_ioctl, 1893 .compat_ioctl = atalk_compat_ioctl,
@@ -1851,8 +1902,6 @@ static const struct proto_ops SOCKOPS_WRAPPED(atalk_dgram_ops) = {
1851 .sendpage = sock_no_sendpage, 1902 .sendpage = sock_no_sendpage,
1852}; 1903};
1853 1904
1854SOCKOPS_WRAP(atalk_dgram, PF_APPLETALK);
1855
1856static struct notifier_block ddp_notifier = { 1905static struct notifier_block ddp_notifier = {
1857 .notifier_call = ddp_device_event, 1906 .notifier_call = ddp_device_event,
1858}; 1907};
diff --git a/net/appletalk/sysctl_net_atalk.c b/net/appletalk/sysctl_net_atalk.c
index 8d237b15183b..04e9c0da7aa9 100644
--- a/net/appletalk/sysctl_net_atalk.c
+++ b/net/appletalk/sysctl_net_atalk.c
@@ -12,25 +12,20 @@
12 12
13static struct ctl_table atalk_table[] = { 13static struct ctl_table atalk_table[] = {
14 { 14 {
15 .ctl_name = NET_ATALK_AARP_EXPIRY_TIME,
16 .procname = "aarp-expiry-time", 15 .procname = "aarp-expiry-time",
17 .data = &sysctl_aarp_expiry_time, 16 .data = &sysctl_aarp_expiry_time,
18 .maxlen = sizeof(int), 17 .maxlen = sizeof(int),
19 .mode = 0644, 18 .mode = 0644,
20 .proc_handler = proc_dointvec_jiffies, 19 .proc_handler = proc_dointvec_jiffies,
21 .strategy = sysctl_jiffies,
22 }, 20 },
23 { 21 {
24 .ctl_name = NET_ATALK_AARP_TICK_TIME,
25 .procname = "aarp-tick-time", 22 .procname = "aarp-tick-time",
26 .data = &sysctl_aarp_tick_time, 23 .data = &sysctl_aarp_tick_time,
27 .maxlen = sizeof(int), 24 .maxlen = sizeof(int),
28 .mode = 0644, 25 .mode = 0644,
29 .proc_handler = proc_dointvec_jiffies, 26 .proc_handler = proc_dointvec_jiffies,
30 .strategy = sysctl_jiffies,
31 }, 27 },
32 { 28 {
33 .ctl_name = NET_ATALK_AARP_RETRANSMIT_LIMIT,
34 .procname = "aarp-retransmit-limit", 29 .procname = "aarp-retransmit-limit",
35 .data = &sysctl_aarp_retransmit_limit, 30 .data = &sysctl_aarp_retransmit_limit,
36 .maxlen = sizeof(int), 31 .maxlen = sizeof(int),
@@ -38,20 +33,18 @@ static struct ctl_table atalk_table[] = {
38 .proc_handler = proc_dointvec, 33 .proc_handler = proc_dointvec,
39 }, 34 },
40 { 35 {
41 .ctl_name = NET_ATALK_AARP_RESOLVE_TIME,
42 .procname = "aarp-resolve-time", 36 .procname = "aarp-resolve-time",
43 .data = &sysctl_aarp_resolve_time, 37 .data = &sysctl_aarp_resolve_time,
44 .maxlen = sizeof(int), 38 .maxlen = sizeof(int),
45 .mode = 0644, 39 .mode = 0644,
46 .proc_handler = proc_dointvec_jiffies, 40 .proc_handler = proc_dointvec_jiffies,
47 .strategy = sysctl_jiffies,
48 }, 41 },
49 { 0 }, 42 { },
50}; 43};
51 44
52static struct ctl_path atalk_path[] = { 45static struct ctl_path atalk_path[] = {
53 { .procname = "net", .ctl_name = CTL_NET, }, 46 { .procname = "net", },
54 { .procname = "appletalk", .ctl_name = NET_ATALK, }, 47 { .procname = "appletalk", },
55 { } 48 { }
56}; 49};
57 50
diff --git a/net/atm/addr.c b/net/atm/addr.c
index 82e85abc303d..dcda35c66f15 100644
--- a/net/atm/addr.c
+++ b/net/atm/addr.c
@@ -4,7 +4,8 @@
4 4
5#include <linux/atm.h> 5#include <linux/atm.h>
6#include <linux/atmdev.h> 6#include <linux/atmdev.h>
7#include <asm/uaccess.h> 7#include <linux/slab.h>
8#include <linux/uaccess.h>
8 9
9#include "signaling.h" 10#include "signaling.h"
10#include "addr.h" 11#include "addr.h"
diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
index 02cc7e71efea..fc63526d8695 100644
--- a/net/atm/atm_misc.c
+++ b/net/atm/atm_misc.c
@@ -2,37 +2,35 @@
2 2
3/* Written 1995-2000 by Werner Almesberger, EPFL ICA */ 3/* Written 1995-2000 by Werner Almesberger, EPFL ICA */
4 4
5
6#include <linux/module.h> 5#include <linux/module.h>
7#include <linux/atm.h> 6#include <linux/atm.h>
8#include <linux/atmdev.h> 7#include <linux/atmdev.h>
9#include <linux/skbuff.h> 8#include <linux/skbuff.h>
10#include <linux/sonet.h> 9#include <linux/sonet.h>
11#include <linux/bitops.h> 10#include <linux/bitops.h>
11#include <linux/errno.h>
12#include <asm/atomic.h> 12#include <asm/atomic.h>
13#include <asm/errno.h>
14
15 13
16int atm_charge(struct atm_vcc *vcc,int truesize) 14int atm_charge(struct atm_vcc *vcc, int truesize)
17{ 15{
18 atm_force_charge(vcc,truesize); 16 atm_force_charge(vcc, truesize);
19 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf) 17 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
20 return 1; 18 return 1;
21 atm_return(vcc,truesize); 19 atm_return(vcc, truesize);
22 atomic_inc(&vcc->stats->rx_drop); 20 atomic_inc(&vcc->stats->rx_drop);
23 return 0; 21 return 0;
24} 22}
23EXPORT_SYMBOL(atm_charge);
25 24
26 25struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
27struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc,int pdu_size, 26 gfp_t gfp_flags)
28 gfp_t gfp_flags)
29{ 27{
30 struct sock *sk = sk_atm(vcc); 28 struct sock *sk = sk_atm(vcc);
31 int guess = atm_guess_pdu2truesize(pdu_size); 29 int guess = atm_guess_pdu2truesize(pdu_size);
32 30
33 atm_force_charge(vcc,guess); 31 atm_force_charge(vcc, guess);
34 if (atomic_read(&sk->sk_rmem_alloc) <= sk->sk_rcvbuf) { 32 if (atomic_read(&sk->sk_rmem_alloc) <= sk->sk_rcvbuf) {
35 struct sk_buff *skb = alloc_skb(pdu_size,gfp_flags); 33 struct sk_buff *skb = alloc_skb(pdu_size, gfp_flags);
36 34
37 if (skb) { 35 if (skb) {
38 atomic_add(skb->truesize-guess, 36 atomic_add(skb->truesize-guess,
@@ -40,10 +38,11 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc,int pdu_size,
40 return skb; 38 return skb;
41 } 39 }
42 } 40 }
43 atm_return(vcc,guess); 41 atm_return(vcc, guess);
44 atomic_inc(&vcc->stats->rx_drop); 42 atomic_inc(&vcc->stats->rx_drop);
45 return NULL; 43 return NULL;
46} 44}
45EXPORT_SYMBOL(atm_alloc_charge);
47 46
48 47
49/* 48/*
@@ -73,7 +72,6 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc,int pdu_size,
73 * else * 72 * else *
74 */ 73 */
75 74
76
77int atm_pcr_goal(const struct atm_trafprm *tp) 75int atm_pcr_goal(const struct atm_trafprm *tp)
78{ 76{
79 if (tp->pcr && tp->pcr != ATM_MAX_PCR) 77 if (tp->pcr && tp->pcr != ATM_MAX_PCR)
@@ -84,26 +82,20 @@ int atm_pcr_goal(const struct atm_trafprm *tp)
84 return -tp->max_pcr; 82 return -tp->max_pcr;
85 return 0; 83 return 0;
86} 84}
85EXPORT_SYMBOL(atm_pcr_goal);
87 86
88 87void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
89void sonet_copy_stats(struct k_sonet_stats *from,struct sonet_stats *to)
90{ 88{
91#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i) 89#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
92 __SONET_ITEMS 90 __SONET_ITEMS
93#undef __HANDLE_ITEM 91#undef __HANDLE_ITEM
94} 92}
93EXPORT_SYMBOL(sonet_copy_stats);
95 94
96 95void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
97void sonet_subtract_stats(struct k_sonet_stats *from,struct sonet_stats *to)
98{ 96{
99#define __HANDLE_ITEM(i) atomic_sub(to->i,&from->i) 97#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
100 __SONET_ITEMS 98 __SONET_ITEMS
101#undef __HANDLE_ITEM 99#undef __HANDLE_ITEM
102} 100}
103
104
105EXPORT_SYMBOL(atm_charge);
106EXPORT_SYMBOL(atm_alloc_charge);
107EXPORT_SYMBOL(atm_pcr_goal);
108EXPORT_SYMBOL(sonet_copy_stats);
109EXPORT_SYMBOL(sonet_subtract_stats); 101EXPORT_SYMBOL(sonet_subtract_stats);
diff --git a/net/atm/atm_sysfs.c b/net/atm/atm_sysfs.c
index b5674dc2083d..799c631f0fed 100644
--- a/net/atm/atm_sysfs.c
+++ b/net/atm/atm_sysfs.c
@@ -1,6 +1,7 @@
1/* ATM driver model support. */ 1/* ATM driver model support. */
2 2
3#include <linux/kernel.h> 3#include <linux/kernel.h>
4#include <linux/slab.h>
4#include <linux/init.h> 5#include <linux/init.h>
5#include <linux/kobject.h> 6#include <linux/kobject.h>
6#include <linux/atmdev.h> 7#include <linux/atmdev.h>
@@ -42,13 +43,14 @@ static ssize_t show_atmaddress(struct device *cdev,
42 43
43 spin_lock_irqsave(&adev->lock, flags); 44 spin_lock_irqsave(&adev->lock, flags);
44 list_for_each_entry(aaddr, &adev->local, entry) { 45 list_for_each_entry(aaddr, &adev->local, entry) {
45 for(i = 0, j = 0; i < ATM_ESA_LEN; ++i, ++j) { 46 for (i = 0, j = 0; i < ATM_ESA_LEN; ++i, ++j) {
46 if (j == *fmt) { 47 if (j == *fmt) {
47 pos += sprintf(pos, "."); 48 pos += sprintf(pos, ".");
48 ++fmt; 49 ++fmt;
49 j = 0; 50 j = 0;
50 } 51 }
51 pos += sprintf(pos, "%02x", aaddr->addr.sas_addr.prv[i]); 52 pos += sprintf(pos, "%02x",
53 aaddr->addr.sas_addr.prv[i]);
52 } 54 }
53 pos += sprintf(pos, "\n"); 55 pos += sprintf(pos, "\n");
54 } 56 }
@@ -78,17 +80,17 @@ static ssize_t show_link_rate(struct device *cdev,
78 80
79 /* show the link rate, not the data rate */ 81 /* show the link rate, not the data rate */
80 switch (adev->link_rate) { 82 switch (adev->link_rate) {
81 case ATM_OC3_PCR: 83 case ATM_OC3_PCR:
82 link_rate = 155520000; 84 link_rate = 155520000;
83 break; 85 break;
84 case ATM_OC12_PCR: 86 case ATM_OC12_PCR:
85 link_rate = 622080000; 87 link_rate = 622080000;
86 break; 88 break;
87 case ATM_25_PCR: 89 case ATM_25_PCR:
88 link_rate = 25600000; 90 link_rate = 25600000;
89 break; 91 break;
90 default: 92 default:
91 link_rate = adev->link_rate * 8 * 53; 93 link_rate = adev->link_rate * 8 * 53;
92 } 94 }
93 pos += sprintf(pos, "%d\n", link_rate); 95 pos += sprintf(pos, "%d\n", link_rate);
94 96
diff --git a/net/atm/br2684.c b/net/atm/br2684.c
index 26a646d4eb32..d6c7ceaf13e9 100644
--- a/net/atm/br2684.c
+++ b/net/atm/br2684.c
@@ -6,6 +6,8 @@
6 * Eric Kinzie, 2006-2007, US Naval Research Laboratory 6 * Eric Kinzie, 2006-2007, US Naval Research Laboratory
7 */ 7 */
8 8
9#define pr_fmt(fmt) KBUILD_MODNAME ":%s: " fmt, __func__
10
9#include <linux/module.h> 11#include <linux/module.h>
10#include <linux/init.h> 12#include <linux/init.h>
11#include <linux/kernel.h> 13#include <linux/kernel.h>
@@ -15,7 +17,8 @@
15#include <linux/etherdevice.h> 17#include <linux/etherdevice.h>
16#include <linux/rtnetlink.h> 18#include <linux/rtnetlink.h>
17#include <linux/ip.h> 19#include <linux/ip.h>
18#include <asm/uaccess.h> 20#include <linux/uaccess.h>
21#include <linux/slab.h>
19#include <net/arp.h> 22#include <net/arp.h>
20#include <linux/atm.h> 23#include <linux/atm.h>
21#include <linux/atmdev.h> 24#include <linux/atmdev.h>
@@ -26,20 +29,14 @@
26 29
27#include "common.h" 30#include "common.h"
28 31
29#ifdef SKB_DEBUG
30static void skb_debug(const struct sk_buff *skb) 32static void skb_debug(const struct sk_buff *skb)
31{ 33{
34#ifdef SKB_DEBUG
32#define NUM2PRINT 50 35#define NUM2PRINT 50
33 char buf[NUM2PRINT * 3 + 1]; /* 3 chars per byte */ 36 print_hex_dump(KERN_DEBUG, "br2684: skb: ", DUMP_OFFSET,
34 int i = 0; 37 16, 1, skb->data, min(NUM2PRINT, skb->len), true);
35 for (i = 0; i < skb->len && i < NUM2PRINT; i++) {
36 sprintf(buf + i * 3, "%2.2x ", 0xff & skb->data[i]);
37 }
38 printk(KERN_DEBUG "br2684: skb: %s\n", buf);
39}
40#else
41#define skb_debug(skb) do {} while (0)
42#endif 38#endif
39}
43 40
44#define BR2684_ETHERTYPE_LEN 2 41#define BR2684_ETHERTYPE_LEN 2
45#define BR2684_PAD_LEN 2 42#define BR2684_PAD_LEN 2
@@ -68,7 +65,7 @@ struct br2684_vcc {
68 struct atm_vcc *atmvcc; 65 struct atm_vcc *atmvcc;
69 struct net_device *device; 66 struct net_device *device;
70 /* keep old push, pop functions for chaining */ 67 /* keep old push, pop functions for chaining */
71 void (*old_push) (struct atm_vcc * vcc, struct sk_buff * skb); 68 void (*old_push)(struct atm_vcc *vcc, struct sk_buff *skb);
72 void (*old_pop)(struct atm_vcc *vcc, struct sk_buff *skb); 69 void (*old_pop)(struct atm_vcc *vcc, struct sk_buff *skb);
73 enum br2684_encaps encaps; 70 enum br2684_encaps encaps;
74 struct list_head brvccs; 71 struct list_head brvccs;
@@ -148,7 +145,7 @@ static void br2684_pop(struct atm_vcc *vcc, struct sk_buff *skb)
148 struct br2684_vcc *brvcc = BR2684_VCC(vcc); 145 struct br2684_vcc *brvcc = BR2684_VCC(vcc);
149 struct net_device *net_dev = skb->dev; 146 struct net_device *net_dev = skb->dev;
150 147
151 pr_debug("br2684_pop(vcc %p ; net_dev %p )\n", vcc, net_dev); 148 pr_debug("(vcc %p ; net_dev %p )\n", vcc, net_dev);
152 brvcc->old_pop(vcc, skb); 149 brvcc->old_pop(vcc, skb);
153 150
154 if (!net_dev) 151 if (!net_dev)
@@ -244,7 +241,7 @@ static netdev_tx_t br2684_start_xmit(struct sk_buff *skb,
244 struct br2684_dev *brdev = BRPRIV(dev); 241 struct br2684_dev *brdev = BRPRIV(dev);
245 struct br2684_vcc *brvcc; 242 struct br2684_vcc *brvcc;
246 243
247 pr_debug("br2684_start_xmit, skb_dst(skb)=%p\n", skb_dst(skb)); 244 pr_debug("skb_dst(skb)=%p\n", skb_dst(skb));
248 read_lock(&devs_lock); 245 read_lock(&devs_lock);
249 brvcc = pick_outgoing_vcc(skb, brdev); 246 brvcc = pick_outgoing_vcc(skb, brdev);
250 if (brvcc == NULL) { 247 if (brvcc == NULL) {
@@ -300,7 +297,8 @@ static int br2684_setfilt(struct atm_vcc *atmvcc, void __user * arg)
300 struct br2684_dev *brdev; 297 struct br2684_dev *brdev;
301 read_lock(&devs_lock); 298 read_lock(&devs_lock);
302 brdev = BRPRIV(br2684_find_dev(&fs.ifspec)); 299 brdev = BRPRIV(br2684_find_dev(&fs.ifspec));
303 if (brdev == NULL || list_empty(&brdev->brvccs) || brdev->brvccs.next != brdev->brvccs.prev) /* >1 VCC */ 300 if (brdev == NULL || list_empty(&brdev->brvccs) ||
301 brdev->brvccs.next != brdev->brvccs.prev) /* >1 VCC */
304 brvcc = NULL; 302 brvcc = NULL;
305 else 303 else
306 brvcc = list_entry_brvcc(brdev->brvccs.next); 304 brvcc = list_entry_brvcc(brdev->brvccs.next);
@@ -352,7 +350,7 @@ static void br2684_push(struct atm_vcc *atmvcc, struct sk_buff *skb)
352 struct net_device *net_dev = brvcc->device; 350 struct net_device *net_dev = brvcc->device;
353 struct br2684_dev *brdev = BRPRIV(net_dev); 351 struct br2684_dev *brdev = BRPRIV(net_dev);
354 352
355 pr_debug("br2684_push\n"); 353 pr_debug("\n");
356 354
357 if (unlikely(skb == NULL)) { 355 if (unlikely(skb == NULL)) {
358 /* skb==NULL means VCC is being destroyed */ 356 /* skb==NULL means VCC is being destroyed */
@@ -376,29 +374,25 @@ static void br2684_push(struct atm_vcc *atmvcc, struct sk_buff *skb)
376 __skb_trim(skb, skb->len - 4); 374 __skb_trim(skb, skb->len - 4);
377 375
378 /* accept packets that have "ipv[46]" in the snap header */ 376 /* accept packets that have "ipv[46]" in the snap header */
379 if ((skb->len >= (sizeof(llc_oui_ipv4))) 377 if ((skb->len >= (sizeof(llc_oui_ipv4))) &&
380 && 378 (memcmp(skb->data, llc_oui_ipv4,
381 (memcmp 379 sizeof(llc_oui_ipv4) - BR2684_ETHERTYPE_LEN) == 0)) {
382 (skb->data, llc_oui_ipv4, 380 if (memcmp(skb->data + 6, ethertype_ipv6,
383 sizeof(llc_oui_ipv4) - BR2684_ETHERTYPE_LEN) == 0)) { 381 sizeof(ethertype_ipv6)) == 0)
384 if (memcmp
385 (skb->data + 6, ethertype_ipv6,
386 sizeof(ethertype_ipv6)) == 0)
387 skb->protocol = htons(ETH_P_IPV6); 382 skb->protocol = htons(ETH_P_IPV6);
388 else if (memcmp 383 else if (memcmp(skb->data + 6, ethertype_ipv4,
389 (skb->data + 6, ethertype_ipv4, 384 sizeof(ethertype_ipv4)) == 0)
390 sizeof(ethertype_ipv4)) == 0)
391 skb->protocol = htons(ETH_P_IP); 385 skb->protocol = htons(ETH_P_IP);
392 else 386 else
393 goto error; 387 goto error;
394 skb_pull(skb, sizeof(llc_oui_ipv4)); 388 skb_pull(skb, sizeof(llc_oui_ipv4));
395 skb_reset_network_header(skb); 389 skb_reset_network_header(skb);
396 skb->pkt_type = PACKET_HOST; 390 skb->pkt_type = PACKET_HOST;
397 /* 391 /*
398 * Let us waste some time for checking the encapsulation. 392 * Let us waste some time for checking the encapsulation.
399 * Note, that only 7 char is checked so frames with a valid FCS 393 * Note, that only 7 char is checked so frames with a valid FCS
400 * are also accepted (but FCS is not checked of course). 394 * are also accepted (but FCS is not checked of course).
401 */ 395 */
402 } else if ((skb->len >= sizeof(llc_oui_pid_pad)) && 396 } else if ((skb->len >= sizeof(llc_oui_pid_pad)) &&
403 (memcmp(skb->data, llc_oui_pid_pad, 7) == 0)) { 397 (memcmp(skb->data, llc_oui_pid_pad, 7) == 0)) {
404 skb_pull(skb, sizeof(llc_oui_pid_pad)); 398 skb_pull(skb, sizeof(llc_oui_pid_pad));
@@ -479,8 +473,7 @@ static int br2684_regvcc(struct atm_vcc *atmvcc, void __user * arg)
479 write_lock_irq(&devs_lock); 473 write_lock_irq(&devs_lock);
480 net_dev = br2684_find_dev(&be.ifspec); 474 net_dev = br2684_find_dev(&be.ifspec);
481 if (net_dev == NULL) { 475 if (net_dev == NULL) {
482 printk(KERN_ERR 476 pr_err("tried to attach to non-existant device\n");
483 "br2684: tried to attach to non-existant device\n");
484 err = -ENXIO; 477 err = -ENXIO;
485 goto error; 478 goto error;
486 } 479 }
@@ -494,17 +487,16 @@ static int br2684_regvcc(struct atm_vcc *atmvcc, void __user * arg)
494 err = -EEXIST; 487 err = -EEXIST;
495 goto error; 488 goto error;
496 } 489 }
497 if (be.fcs_in != BR2684_FCSIN_NO || be.fcs_out != BR2684_FCSOUT_NO || 490 if (be.fcs_in != BR2684_FCSIN_NO ||
498 be.fcs_auto || be.has_vpiid || be.send_padding || (be.encaps != 491 be.fcs_out != BR2684_FCSOUT_NO ||
499 BR2684_ENCAPS_VC 492 be.fcs_auto || be.has_vpiid || be.send_padding ||
500 && be.encaps != 493 (be.encaps != BR2684_ENCAPS_VC &&
501 BR2684_ENCAPS_LLC) 494 be.encaps != BR2684_ENCAPS_LLC) ||
502 || be.min_size != 0) { 495 be.min_size != 0) {
503 err = -EINVAL; 496 err = -EINVAL;
504 goto error; 497 goto error;
505 } 498 }
506 pr_debug("br2684_regvcc vcc=%p, encaps=%d, brvcc=%p\n", atmvcc, 499 pr_debug("vcc=%p, encaps=%d, brvcc=%p\n", atmvcc, be.encaps, brvcc);
507 be.encaps, brvcc);
508 if (list_empty(&brdev->brvccs) && !brdev->mac_was_set) { 500 if (list_empty(&brdev->brvccs) && !brdev->mac_was_set) {
509 unsigned char *esi = atmvcc->dev->esi; 501 unsigned char *esi = atmvcc->dev->esi;
510 if (esi[0] | esi[1] | esi[2] | esi[3] | esi[4] | esi[5]) 502 if (esi[0] | esi[1] | esi[2] | esi[3] | esi[4] | esi[5])
@@ -541,7 +533,8 @@ static int br2684_regvcc(struct atm_vcc *atmvcc, void __user * arg)
541 } 533 }
542 __module_get(THIS_MODULE); 534 __module_get(THIS_MODULE);
543 return 0; 535 return 0;
544 error: 536
537error:
545 write_unlock_irq(&devs_lock); 538 write_unlock_irq(&devs_lock);
546 kfree(brvcc); 539 kfree(brvcc);
547 return err; 540 return err;
@@ -554,6 +547,12 @@ static const struct net_device_ops br2684_netdev_ops = {
554 .ndo_validate_addr = eth_validate_addr, 547 .ndo_validate_addr = eth_validate_addr,
555}; 548};
556 549
550static const struct net_device_ops br2684_netdev_ops_routed = {
551 .ndo_start_xmit = br2684_start_xmit,
552 .ndo_set_mac_address = br2684_mac_addr,
553 .ndo_change_mtu = eth_change_mtu
554};
555
557static void br2684_setup(struct net_device *netdev) 556static void br2684_setup(struct net_device *netdev)
558{ 557{
559 struct br2684_dev *brdev = BRPRIV(netdev); 558 struct br2684_dev *brdev = BRPRIV(netdev);
@@ -569,11 +568,10 @@ static void br2684_setup(struct net_device *netdev)
569static void br2684_setup_routed(struct net_device *netdev) 568static void br2684_setup_routed(struct net_device *netdev)
570{ 569{
571 struct br2684_dev *brdev = BRPRIV(netdev); 570 struct br2684_dev *brdev = BRPRIV(netdev);
572 brdev->net_dev = netdev;
573 571
572 brdev->net_dev = netdev;
574 netdev->hard_header_len = 0; 573 netdev->hard_header_len = 0;
575 574 netdev->netdev_ops = &br2684_netdev_ops_routed;
576 netdev->netdev_ops = &br2684_netdev_ops;
577 netdev->addr_len = 0; 575 netdev->addr_len = 0;
578 netdev->mtu = 1500; 576 netdev->mtu = 1500;
579 netdev->type = ARPHRD_PPP; 577 netdev->type = ARPHRD_PPP;
@@ -582,7 +580,7 @@ static void br2684_setup_routed(struct net_device *netdev)
582 INIT_LIST_HEAD(&brdev->brvccs); 580 INIT_LIST_HEAD(&brdev->brvccs);
583} 581}
584 582
585static int br2684_create(void __user * arg) 583static int br2684_create(void __user *arg)
586{ 584{
587 int err; 585 int err;
588 struct net_device *netdev; 586 struct net_device *netdev;
@@ -590,11 +588,10 @@ static int br2684_create(void __user * arg)
590 struct atm_newif_br2684 ni; 588 struct atm_newif_br2684 ni;
591 enum br2684_payload payload; 589 enum br2684_payload payload;
592 590
593 pr_debug("br2684_create\n"); 591 pr_debug("\n");
594 592
595 if (copy_from_user(&ni, arg, sizeof ni)) { 593 if (copy_from_user(&ni, arg, sizeof ni))
596 return -EFAULT; 594 return -EFAULT;
597 }
598 595
599 if (ni.media & BR2684_FLAG_ROUTED) 596 if (ni.media & BR2684_FLAG_ROUTED)
600 payload = p_routed; 597 payload = p_routed;
@@ -602,9 +599,8 @@ static int br2684_create(void __user * arg)
602 payload = p_bridged; 599 payload = p_bridged;
603 ni.media &= 0xffff; /* strip flags */ 600 ni.media &= 0xffff; /* strip flags */
604 601
605 if (ni.media != BR2684_MEDIA_ETHERNET || ni.mtu != 1500) { 602 if (ni.media != BR2684_MEDIA_ETHERNET || ni.mtu != 1500)
606 return -EINVAL; 603 return -EINVAL;
607 }
608 604
609 netdev = alloc_netdev(sizeof(struct br2684_dev), 605 netdev = alloc_netdev(sizeof(struct br2684_dev),
610 ni.ifname[0] ? ni.ifname : "nas%d", 606 ni.ifname[0] ? ni.ifname : "nas%d",
@@ -619,7 +615,7 @@ static int br2684_create(void __user * arg)
619 /* open, stop, do_ioctl ? */ 615 /* open, stop, do_ioctl ? */
620 err = register_netdev(netdev); 616 err = register_netdev(netdev);
621 if (err < 0) { 617 if (err < 0) {
622 printk(KERN_ERR "br2684_create: register_netdev failed\n"); 618 pr_err("register_netdev failed\n");
623 free_netdev(netdev); 619 free_netdev(netdev);
624 return err; 620 return err;
625 } 621 }
diff --git a/net/atm/clip.c b/net/atm/clip.c
index 64629c354343..313aba11316b 100644
--- a/net/atm/clip.c
+++ b/net/atm/clip.c
@@ -2,6 +2,8 @@
2 2
3/* Written 1995-2000 by Werner Almesberger, EPFL LRC/ICA */ 3/* Written 1995-2000 by Werner Almesberger, EPFL LRC/ICA */
4 4
5#define pr_fmt(fmt) KBUILD_MODNAME ":%s: " fmt, __func__
6
5#include <linux/string.h> 7#include <linux/string.h>
6#include <linux/errno.h> 8#include <linux/errno.h>
7#include <linux/kernel.h> /* for UINT_MAX */ 9#include <linux/kernel.h> /* for UINT_MAX */
@@ -28,12 +30,13 @@
28#include <linux/seq_file.h> 30#include <linux/seq_file.h>
29#include <linux/rcupdate.h> 31#include <linux/rcupdate.h>
30#include <linux/jhash.h> 32#include <linux/jhash.h>
33#include <linux/slab.h>
31#include <net/route.h> /* for struct rtable and routing */ 34#include <net/route.h> /* for struct rtable and routing */
32#include <net/icmp.h> /* icmp_send */ 35#include <net/icmp.h> /* icmp_send */
33#include <asm/param.h> /* for HZ */ 36#include <linux/param.h> /* for HZ */
37#include <linux/uaccess.h>
34#include <asm/byteorder.h> /* for htons etc. */ 38#include <asm/byteorder.h> /* for htons etc. */
35#include <asm/system.h> /* save/restore_flags */ 39#include <asm/system.h> /* save/restore_flags */
36#include <asm/uaccess.h>
37#include <asm/atomic.h> 40#include <asm/atomic.h>
38 41
39#include "common.h" 42#include "common.h"
@@ -51,13 +54,13 @@ static int to_atmarpd(enum atmarp_ctrl_type type, int itf, __be32 ip)
51 struct atmarp_ctrl *ctrl; 54 struct atmarp_ctrl *ctrl;
52 struct sk_buff *skb; 55 struct sk_buff *skb;
53 56
54 pr_debug("to_atmarpd(%d)\n", type); 57 pr_debug("(%d)\n", type);
55 if (!atmarpd) 58 if (!atmarpd)
56 return -EUNATCH; 59 return -EUNATCH;
57 skb = alloc_skb(sizeof(struct atmarp_ctrl),GFP_ATOMIC); 60 skb = alloc_skb(sizeof(struct atmarp_ctrl), GFP_ATOMIC);
58 if (!skb) 61 if (!skb)
59 return -ENOMEM; 62 return -ENOMEM;
60 ctrl = (struct atmarp_ctrl *) skb_put(skb,sizeof(struct atmarp_ctrl)); 63 ctrl = (struct atmarp_ctrl *)skb_put(skb, sizeof(struct atmarp_ctrl));
61 ctrl->type = type; 64 ctrl->type = type;
62 ctrl->itf_num = itf; 65 ctrl->itf_num = itf;
63 ctrl->ip = ip; 66 ctrl->ip = ip;
@@ -71,8 +74,7 @@ static int to_atmarpd(enum atmarp_ctrl_type type, int itf, __be32 ip)
71 74
72static void link_vcc(struct clip_vcc *clip_vcc, struct atmarp_entry *entry) 75static void link_vcc(struct clip_vcc *clip_vcc, struct atmarp_entry *entry)
73{ 76{
74 pr_debug("link_vcc %p to entry %p (neigh %p)\n", clip_vcc, entry, 77 pr_debug("%p to entry %p (neigh %p)\n", clip_vcc, entry, entry->neigh);
75 entry->neigh);
76 clip_vcc->entry = entry; 78 clip_vcc->entry = entry;
77 clip_vcc->xoff = 0; /* @@@ may overrun buffer by one packet */ 79 clip_vcc->xoff = 0; /* @@@ may overrun buffer by one packet */
78 clip_vcc->next = entry->vccs; 80 clip_vcc->next = entry->vccs;
@@ -86,7 +88,7 @@ static void unlink_clip_vcc(struct clip_vcc *clip_vcc)
86 struct clip_vcc **walk; 88 struct clip_vcc **walk;
87 89
88 if (!entry) { 90 if (!entry) {
89 printk(KERN_CRIT "!clip_vcc->entry (clip_vcc %p)\n", clip_vcc); 91 pr_crit("!clip_vcc->entry (clip_vcc %p)\n", clip_vcc);
90 return; 92 return;
91 } 93 }
92 netif_tx_lock_bh(entry->neigh->dev); /* block clip_start_xmit() */ 94 netif_tx_lock_bh(entry->neigh->dev); /* block clip_start_xmit() */
@@ -106,13 +108,11 @@ static void unlink_clip_vcc(struct clip_vcc *clip_vcc)
106 error = neigh_update(entry->neigh, NULL, NUD_NONE, 108 error = neigh_update(entry->neigh, NULL, NUD_NONE,
107 NEIGH_UPDATE_F_ADMIN); 109 NEIGH_UPDATE_F_ADMIN);
108 if (error) 110 if (error)
109 printk(KERN_CRIT "unlink_clip_vcc: " 111 pr_crit("neigh_update failed with %d\n", error);
110 "neigh_update failed with %d\n", error);
111 goto out; 112 goto out;
112 } 113 }
113 printk(KERN_CRIT "ATMARP: unlink_clip_vcc failed (entry %p, vcc " 114 pr_crit("ATMARP: failed (entry %p, vcc 0x%p)\n", entry, clip_vcc);
114 "0x%p)\n", entry, clip_vcc); 115out:
115 out:
116 netif_tx_unlock_bh(entry->neigh->dev); 116 netif_tx_unlock_bh(entry->neigh->dev);
117} 117}
118 118
@@ -127,7 +127,7 @@ static int neigh_check_cb(struct neighbour *n)
127 127
128 if (cv->idle_timeout && time_after(jiffies, exp)) { 128 if (cv->idle_timeout && time_after(jiffies, exp)) {
129 pr_debug("releasing vcc %p->%p of entry %p\n", 129 pr_debug("releasing vcc %p->%p of entry %p\n",
130 cv, cv->vcc, entry); 130 cv, cv->vcc, entry);
131 vcc_release_async(cv->vcc, -ETIMEDOUT); 131 vcc_release_async(cv->vcc, -ETIMEDOUT);
132 } 132 }
133 } 133 }
@@ -139,7 +139,7 @@ static int neigh_check_cb(struct neighbour *n)
139 struct sk_buff *skb; 139 struct sk_buff *skb;
140 140
141 pr_debug("destruction postponed with ref %d\n", 141 pr_debug("destruction postponed with ref %d\n",
142 atomic_read(&n->refcnt)); 142 atomic_read(&n->refcnt));
143 143
144 while ((skb = skb_dequeue(&n->arp_queue)) != NULL) 144 while ((skb = skb_dequeue(&n->arp_queue)) != NULL)
145 dev_kfree_skb(skb); 145 dev_kfree_skb(skb);
@@ -163,7 +163,7 @@ static int clip_arp_rcv(struct sk_buff *skb)
163{ 163{
164 struct atm_vcc *vcc; 164 struct atm_vcc *vcc;
165 165
166 pr_debug("clip_arp_rcv\n"); 166 pr_debug("\n");
167 vcc = ATM_SKB(skb)->vcc; 167 vcc = ATM_SKB(skb)->vcc;
168 if (!vcc || !atm_charge(vcc, skb->truesize)) { 168 if (!vcc || !atm_charge(vcc, skb->truesize)) {
169 dev_kfree_skb_any(skb); 169 dev_kfree_skb_any(skb);
@@ -188,7 +188,7 @@ static void clip_push(struct atm_vcc *vcc, struct sk_buff *skb)
188{ 188{
189 struct clip_vcc *clip_vcc = CLIP_VCC(vcc); 189 struct clip_vcc *clip_vcc = CLIP_VCC(vcc);
190 190
191 pr_debug("clip push\n"); 191 pr_debug("\n");
192 if (!skb) { 192 if (!skb) {
193 pr_debug("removing VCC %p\n", clip_vcc); 193 pr_debug("removing VCC %p\n", clip_vcc);
194 if (clip_vcc->entry) 194 if (clip_vcc->entry)
@@ -206,12 +206,12 @@ static void clip_push(struct atm_vcc *vcc, struct sk_buff *skb)
206 } 206 }
207 ATM_SKB(skb)->vcc = vcc; 207 ATM_SKB(skb)->vcc = vcc;
208 skb_reset_mac_header(skb); 208 skb_reset_mac_header(skb);
209 if (!clip_vcc->encap 209 if (!clip_vcc->encap ||
210 || skb->len < RFC1483LLC_LEN 210 skb->len < RFC1483LLC_LEN ||
211 || memcmp(skb->data, llc_oui, sizeof (llc_oui))) 211 memcmp(skb->data, llc_oui, sizeof(llc_oui)))
212 skb->protocol = htons(ETH_P_IP); 212 skb->protocol = htons(ETH_P_IP);
213 else { 213 else {
214 skb->protocol = ((__be16 *) skb->data)[3]; 214 skb->protocol = ((__be16 *)skb->data)[3];
215 skb_pull(skb, RFC1483LLC_LEN); 215 skb_pull(skb, RFC1483LLC_LEN);
216 if (skb->protocol == htons(ETH_P_ARP)) { 216 if (skb->protocol == htons(ETH_P_ARP)) {
217 skb->dev->stats.rx_packets++; 217 skb->dev->stats.rx_packets++;
@@ -239,7 +239,7 @@ static void clip_pop(struct atm_vcc *vcc, struct sk_buff *skb)
239 int old; 239 int old;
240 unsigned long flags; 240 unsigned long flags;
241 241
242 pr_debug("clip_pop(vcc %p)\n", vcc); 242 pr_debug("(vcc %p)\n", vcc);
243 clip_vcc->old_pop(vcc, skb); 243 clip_vcc->old_pop(vcc, skb);
244 /* skb->dev == NULL in outbound ARP packets */ 244 /* skb->dev == NULL in outbound ARP packets */
245 if (!dev) 245 if (!dev)
@@ -255,7 +255,7 @@ static void clip_pop(struct atm_vcc *vcc, struct sk_buff *skb)
255 255
256static void clip_neigh_solicit(struct neighbour *neigh, struct sk_buff *skb) 256static void clip_neigh_solicit(struct neighbour *neigh, struct sk_buff *skb)
257{ 257{
258 pr_debug("clip_neigh_solicit (neigh %p, skb %p)\n", neigh, skb); 258 pr_debug("(neigh %p, skb %p)\n", neigh, skb);
259 to_atmarpd(act_need, PRIV(neigh->dev)->number, NEIGH2ENTRY(neigh)->ip); 259 to_atmarpd(act_need, PRIV(neigh->dev)->number, NEIGH2ENTRY(neigh)->ip);
260} 260}
261 261
@@ -284,7 +284,7 @@ static int clip_constructor(struct neighbour *neigh)
284 struct in_device *in_dev; 284 struct in_device *in_dev;
285 struct neigh_parms *parms; 285 struct neigh_parms *parms;
286 286
287 pr_debug("clip_constructor (neigh %p, entry %p)\n", neigh, entry); 287 pr_debug("(neigh %p, entry %p)\n", neigh, entry);
288 neigh->type = inet_addr_type(&init_net, entry->ip); 288 neigh->type = inet_addr_type(&init_net, entry->ip);
289 if (neigh->type != RTN_UNICAST) 289 if (neigh->type != RTN_UNICAST)
290 return -EINVAL; 290 return -EINVAL;
@@ -369,9 +369,9 @@ static netdev_tx_t clip_start_xmit(struct sk_buff *skb,
369 int old; 369 int old;
370 unsigned long flags; 370 unsigned long flags;
371 371
372 pr_debug("clip_start_xmit (skb %p)\n", skb); 372 pr_debug("(skb %p)\n", skb);
373 if (!skb_dst(skb)) { 373 if (!skb_dst(skb)) {
374 printk(KERN_ERR "clip_start_xmit: skb_dst(skb) == NULL\n"); 374 pr_err("skb_dst(skb) == NULL\n");
375 dev_kfree_skb(skb); 375 dev_kfree_skb(skb);
376 dev->stats.tx_dropped++; 376 dev->stats.tx_dropped++;
377 return NETDEV_TX_OK; 377 return NETDEV_TX_OK;
@@ -385,7 +385,7 @@ static netdev_tx_t clip_start_xmit(struct sk_buff *skb,
385 return 0; 385 return 0;
386 } 386 }
387#endif 387#endif
388 printk(KERN_ERR "clip_start_xmit: NO NEIGHBOUR !\n"); 388 pr_err("NO NEIGHBOUR !\n");
389 dev_kfree_skb(skb); 389 dev_kfree_skb(skb);
390 dev->stats.tx_dropped++; 390 dev->stats.tx_dropped++;
391 return NETDEV_TX_OK; 391 return NETDEV_TX_OK;
@@ -421,7 +421,7 @@ static netdev_tx_t clip_start_xmit(struct sk_buff *skb,
421 pr_debug("atm_skb(%p)->vcc(%p)->dev(%p)\n", skb, vcc, vcc->dev); 421 pr_debug("atm_skb(%p)->vcc(%p)->dev(%p)\n", skb, vcc, vcc->dev);
422 old = xchg(&entry->vccs->xoff, 1); /* assume XOFF ... */ 422 old = xchg(&entry->vccs->xoff, 1); /* assume XOFF ... */
423 if (old) { 423 if (old) {
424 printk(KERN_WARNING "clip_start_xmit: XOFF->XOFF transition\n"); 424 pr_warning("XOFF->XOFF transition\n");
425 return NETDEV_TX_OK; 425 return NETDEV_TX_OK;
426 } 426 }
427 dev->stats.tx_packets++; 427 dev->stats.tx_packets++;
@@ -456,7 +456,7 @@ static int clip_mkip(struct atm_vcc *vcc, int timeout)
456 clip_vcc = kmalloc(sizeof(struct clip_vcc), GFP_KERNEL); 456 clip_vcc = kmalloc(sizeof(struct clip_vcc), GFP_KERNEL);
457 if (!clip_vcc) 457 if (!clip_vcc)
458 return -ENOMEM; 458 return -ENOMEM;
459 pr_debug("mkip clip_vcc %p vcc %p\n", clip_vcc, vcc); 459 pr_debug("%p vcc %p\n", clip_vcc, vcc);
460 clip_vcc->vcc = vcc; 460 clip_vcc->vcc = vcc;
461 vcc->user_back = clip_vcc; 461 vcc->user_back = clip_vcc;
462 set_bit(ATM_VF_IS_CLIP, &vcc->flags); 462 set_bit(ATM_VF_IS_CLIP, &vcc->flags);
@@ -506,16 +506,16 @@ static int clip_setentry(struct atm_vcc *vcc, __be32 ip)
506 struct rtable *rt; 506 struct rtable *rt;
507 507
508 if (vcc->push != clip_push) { 508 if (vcc->push != clip_push) {
509 printk(KERN_WARNING "clip_setentry: non-CLIP VCC\n"); 509 pr_warning("non-CLIP VCC\n");
510 return -EBADF; 510 return -EBADF;
511 } 511 }
512 clip_vcc = CLIP_VCC(vcc); 512 clip_vcc = CLIP_VCC(vcc);
513 if (!ip) { 513 if (!ip) {
514 if (!clip_vcc->entry) { 514 if (!clip_vcc->entry) {
515 printk(KERN_ERR "hiding hidden ATMARP entry\n"); 515 pr_err("hiding hidden ATMARP entry\n");
516 return 0; 516 return 0;
517 } 517 }
518 pr_debug("setentry: remove\n"); 518 pr_debug("remove\n");
519 unlink_clip_vcc(clip_vcc); 519 unlink_clip_vcc(clip_vcc);
520 return 0; 520 return 0;
521 } 521 }
@@ -529,9 +529,9 @@ static int clip_setentry(struct atm_vcc *vcc, __be32 ip)
529 entry = NEIGH2ENTRY(neigh); 529 entry = NEIGH2ENTRY(neigh);
530 if (entry != clip_vcc->entry) { 530 if (entry != clip_vcc->entry) {
531 if (!clip_vcc->entry) 531 if (!clip_vcc->entry)
532 pr_debug("setentry: add\n"); 532 pr_debug("add\n");
533 else { 533 else {
534 pr_debug("setentry: update\n"); 534 pr_debug("update\n");
535 unlink_clip_vcc(clip_vcc); 535 unlink_clip_vcc(clip_vcc);
536 } 536 }
537 link_vcc(clip_vcc, entry); 537 link_vcc(clip_vcc, entry);
@@ -614,16 +614,16 @@ static int clip_device_event(struct notifier_block *this, unsigned long event,
614 614
615 switch (event) { 615 switch (event) {
616 case NETDEV_UP: 616 case NETDEV_UP:
617 pr_debug("clip_device_event NETDEV_UP\n"); 617 pr_debug("NETDEV_UP\n");
618 to_atmarpd(act_up, PRIV(dev)->number, 0); 618 to_atmarpd(act_up, PRIV(dev)->number, 0);
619 break; 619 break;
620 case NETDEV_GOING_DOWN: 620 case NETDEV_GOING_DOWN:
621 pr_debug("clip_device_event NETDEV_DOWN\n"); 621 pr_debug("NETDEV_DOWN\n");
622 to_atmarpd(act_down, PRIV(dev)->number, 0); 622 to_atmarpd(act_down, PRIV(dev)->number, 0);
623 break; 623 break;
624 case NETDEV_CHANGE: 624 case NETDEV_CHANGE:
625 case NETDEV_CHANGEMTU: 625 case NETDEV_CHANGEMTU:
626 pr_debug("clip_device_event NETDEV_CHANGE*\n"); 626 pr_debug("NETDEV_CHANGE*\n");
627 to_atmarpd(act_change, PRIV(dev)->number, 0); 627 to_atmarpd(act_change, PRIV(dev)->number, 0);
628 break; 628 break;
629 } 629 }
@@ -645,7 +645,6 @@ static int clip_inet_event(struct notifier_block *this, unsigned long event,
645 return clip_device_event(this, NETDEV_CHANGE, in_dev->dev); 645 return clip_device_event(this, NETDEV_CHANGE, in_dev->dev);
646} 646}
647 647
648
649static struct notifier_block clip_dev_notifier = { 648static struct notifier_block clip_dev_notifier = {
650 .notifier_call = clip_device_event, 649 .notifier_call = clip_device_event,
651}; 650};
@@ -660,7 +659,7 @@ static struct notifier_block clip_inet_notifier = {
660 659
661static void atmarpd_close(struct atm_vcc *vcc) 660static void atmarpd_close(struct atm_vcc *vcc)
662{ 661{
663 pr_debug("atmarpd_close\n"); 662 pr_debug("\n");
664 663
665 rtnl_lock(); 664 rtnl_lock();
666 atmarpd = NULL; 665 atmarpd = NULL;
@@ -671,7 +670,6 @@ static void atmarpd_close(struct atm_vcc *vcc)
671 module_put(THIS_MODULE); 670 module_put(THIS_MODULE);
672} 671}
673 672
674
675static struct atmdev_ops atmarpd_dev_ops = { 673static struct atmdev_ops atmarpd_dev_ops = {
676 .close = atmarpd_close 674 .close = atmarpd_close
677}; 675};
@@ -693,11 +691,11 @@ static int atm_init_atmarp(struct atm_vcc *vcc)
693 return -EADDRINUSE; 691 return -EADDRINUSE;
694 } 692 }
695 693
696 mod_timer(&idle_timer, jiffies+CLIP_CHECK_INTERVAL*HZ); 694 mod_timer(&idle_timer, jiffies + CLIP_CHECK_INTERVAL * HZ);
697 695
698 atmarpd = vcc; 696 atmarpd = vcc;
699 set_bit(ATM_VF_META,&vcc->flags); 697 set_bit(ATM_VF_META, &vcc->flags);
700 set_bit(ATM_VF_READY,&vcc->flags); 698 set_bit(ATM_VF_READY, &vcc->flags);
701 /* allow replies and avoid getting closed if signaling dies */ 699 /* allow replies and avoid getting closed if signaling dies */
702 vcc->dev = &atmarpd_dev; 700 vcc->dev = &atmarpd_dev;
703 vcc_insert_socket(sk_atm(vcc)); 701 vcc_insert_socket(sk_atm(vcc));
@@ -950,8 +948,7 @@ static int __init atm_clip_init(void)
950 948
951 p = proc_create("arp", S_IRUGO, atm_proc_root, &arp_seq_fops); 949 p = proc_create("arp", S_IRUGO, atm_proc_root, &arp_seq_fops);
952 if (!p) { 950 if (!p) {
953 printk(KERN_ERR "Unable to initialize " 951 pr_err("Unable to initialize /proc/net/atm/arp\n");
954 "/proc/net/atm/arp\n");
955 atm_clip_exit_noproc(); 952 atm_clip_exit_noproc();
956 return -ENOMEM; 953 return -ENOMEM;
957 } 954 }
diff --git a/net/atm/common.c b/net/atm/common.c
index 950bd16d2383..97ed94aa0cbc 100644
--- a/net/atm/common.c
+++ b/net/atm/common.c
@@ -2,6 +2,7 @@
2 2
3/* Written 1995-2000 by Werner Almesberger, EPFL LRC/ICA */ 3/* Written 1995-2000 by Werner Almesberger, EPFL LRC/ICA */
4 4
5#define pr_fmt(fmt) KBUILD_MODNAME ":%s: " fmt, __func__
5 6
6#include <linux/module.h> 7#include <linux/module.h>
7#include <linux/kmod.h> 8#include <linux/kmod.h>
@@ -17,12 +18,12 @@
17#include <linux/skbuff.h> 18#include <linux/skbuff.h>
18#include <linux/bitops.h> 19#include <linux/bitops.h>
19#include <linux/init.h> 20#include <linux/init.h>
21#include <linux/slab.h>
20#include <net/sock.h> /* struct sock */ 22#include <net/sock.h> /* struct sock */
23#include <linux/uaccess.h>
24#include <linux/poll.h>
21 25
22#include <asm/uaccess.h>
23#include <asm/atomic.h> 26#include <asm/atomic.h>
24#include <asm/poll.h>
25
26 27
27#include "resources.h" /* atm_find_dev */ 28#include "resources.h" /* atm_find_dev */
28#include "common.h" /* prototypes */ 29#include "common.h" /* prototypes */
@@ -31,13 +32,15 @@
31#include "signaling.h" /* for WAITING and sigd_attach */ 32#include "signaling.h" /* for WAITING and sigd_attach */
32 33
33struct hlist_head vcc_hash[VCC_HTABLE_SIZE]; 34struct hlist_head vcc_hash[VCC_HTABLE_SIZE];
35EXPORT_SYMBOL(vcc_hash);
36
34DEFINE_RWLOCK(vcc_sklist_lock); 37DEFINE_RWLOCK(vcc_sklist_lock);
38EXPORT_SYMBOL(vcc_sklist_lock);
35 39
36static void __vcc_insert_socket(struct sock *sk) 40static void __vcc_insert_socket(struct sock *sk)
37{ 41{
38 struct atm_vcc *vcc = atm_sk(sk); 42 struct atm_vcc *vcc = atm_sk(sk);
39 struct hlist_head *head = &vcc_hash[vcc->vci & 43 struct hlist_head *head = &vcc_hash[vcc->vci & (VCC_HTABLE_SIZE - 1)];
40 (VCC_HTABLE_SIZE - 1)];
41 sk->sk_hash = vcc->vci & (VCC_HTABLE_SIZE - 1); 44 sk->sk_hash = vcc->vci & (VCC_HTABLE_SIZE - 1);
42 sk_add_node(sk, head); 45 sk_add_node(sk, head);
43} 46}
@@ -48,6 +51,7 @@ void vcc_insert_socket(struct sock *sk)
48 __vcc_insert_socket(sk); 51 __vcc_insert_socket(sk);
49 write_unlock_irq(&vcc_sklist_lock); 52 write_unlock_irq(&vcc_sklist_lock);
50} 53}
54EXPORT_SYMBOL(vcc_insert_socket);
51 55
52static void vcc_remove_socket(struct sock *sk) 56static void vcc_remove_socket(struct sock *sk)
53{ 57{
@@ -56,37 +60,32 @@ static void vcc_remove_socket(struct sock *sk)
56 write_unlock_irq(&vcc_sklist_lock); 60 write_unlock_irq(&vcc_sklist_lock);
57} 61}
58 62
59 63static struct sk_buff *alloc_tx(struct atm_vcc *vcc, unsigned int size)
60static struct sk_buff *alloc_tx(struct atm_vcc *vcc,unsigned int size)
61{ 64{
62 struct sk_buff *skb; 65 struct sk_buff *skb;
63 struct sock *sk = sk_atm(vcc); 66 struct sock *sk = sk_atm(vcc);
64 67
65 if (sk_wmem_alloc_get(sk) && !atm_may_send(vcc, size)) { 68 if (sk_wmem_alloc_get(sk) && !atm_may_send(vcc, size)) {
66 pr_debug("Sorry: wmem_alloc = %d, size = %d, sndbuf = %d\n", 69 pr_debug("Sorry: wmem_alloc = %d, size = %d, sndbuf = %d\n",
67 sk_wmem_alloc_get(sk), size, 70 sk_wmem_alloc_get(sk), size, sk->sk_sndbuf);
68 sk->sk_sndbuf);
69 return NULL; 71 return NULL;
70 } 72 }
71 while (!(skb = alloc_skb(size, GFP_KERNEL))) 73 while (!(skb = alloc_skb(size, GFP_KERNEL)))
72 schedule(); 74 schedule();
73 pr_debug("AlTx %d += %d\n", sk_wmem_alloc_get(sk), skb->truesize); 75 pr_debug("%d += %d\n", sk_wmem_alloc_get(sk), skb->truesize);
74 atomic_add(skb->truesize, &sk->sk_wmem_alloc); 76 atomic_add(skb->truesize, &sk->sk_wmem_alloc);
75 return skb; 77 return skb;
76} 78}
77 79
78
79EXPORT_SYMBOL(vcc_hash);
80EXPORT_SYMBOL(vcc_sklist_lock);
81EXPORT_SYMBOL(vcc_insert_socket);
82
83static void vcc_sock_destruct(struct sock *sk) 80static void vcc_sock_destruct(struct sock *sk)
84{ 81{
85 if (atomic_read(&sk->sk_rmem_alloc)) 82 if (atomic_read(&sk->sk_rmem_alloc))
86 printk(KERN_DEBUG "vcc_sock_destruct: rmem leakage (%d bytes) detected.\n", atomic_read(&sk->sk_rmem_alloc)); 83 printk(KERN_DEBUG "%s: rmem leakage (%d bytes) detected.\n",
84 __func__, atomic_read(&sk->sk_rmem_alloc));
87 85
88 if (atomic_read(&sk->sk_wmem_alloc)) 86 if (atomic_read(&sk->sk_wmem_alloc))
89 printk(KERN_DEBUG "vcc_sock_destruct: wmem leakage (%d bytes) detected.\n", atomic_read(&sk->sk_wmem_alloc)); 87 printk(KERN_DEBUG "%s: wmem leakage (%d bytes) detected.\n",
88 __func__, atomic_read(&sk->sk_wmem_alloc));
90} 89}
91 90
92static void vcc_def_wakeup(struct sock *sk) 91static void vcc_def_wakeup(struct sock *sk)
@@ -142,8 +141,8 @@ int vcc_create(struct net *net, struct socket *sock, int protocol, int family)
142 141
143 vcc = atm_sk(sk); 142 vcc = atm_sk(sk);
144 vcc->dev = NULL; 143 vcc->dev = NULL;
145 memset(&vcc->local,0,sizeof(struct sockaddr_atmsvc)); 144 memset(&vcc->local, 0, sizeof(struct sockaddr_atmsvc));
146 memset(&vcc->remote,0,sizeof(struct sockaddr_atmsvc)); 145 memset(&vcc->remote, 0, sizeof(struct sockaddr_atmsvc));
147 vcc->qos.txtp.max_sdu = 1 << 16; /* for meta VCs */ 146 vcc->qos.txtp.max_sdu = 1 << 16; /* for meta VCs */
148 atomic_set(&sk->sk_wmem_alloc, 1); 147 atomic_set(&sk->sk_wmem_alloc, 1);
149 atomic_set(&sk->sk_rmem_alloc, 0); 148 atomic_set(&sk->sk_rmem_alloc, 0);
@@ -156,7 +155,6 @@ int vcc_create(struct net *net, struct socket *sock, int protocol, int family)
156 return 0; 155 return 0;
157} 156}
158 157
159
160static void vcc_destroy_socket(struct sock *sk) 158static void vcc_destroy_socket(struct sock *sk)
161{ 159{
162 struct atm_vcc *vcc = atm_sk(sk); 160 struct atm_vcc *vcc = atm_sk(sk);
@@ -171,7 +169,7 @@ static void vcc_destroy_socket(struct sock *sk)
171 vcc->push(vcc, NULL); /* atmarpd has no push */ 169 vcc->push(vcc, NULL); /* atmarpd has no push */
172 170
173 while ((skb = skb_dequeue(&sk->sk_receive_queue)) != NULL) { 171 while ((skb = skb_dequeue(&sk->sk_receive_queue)) != NULL) {
174 atm_return(vcc,skb->truesize); 172 atm_return(vcc, skb->truesize);
175 kfree_skb(skb); 173 kfree_skb(skb);
176 } 174 }
177 175
@@ -182,7 +180,6 @@ static void vcc_destroy_socket(struct sock *sk)
182 vcc_remove_socket(sk); 180 vcc_remove_socket(sk);
183} 181}
184 182
185
186int vcc_release(struct socket *sock) 183int vcc_release(struct socket *sock)
187{ 184{
188 struct sock *sk = sock->sk; 185 struct sock *sk = sock->sk;
@@ -197,7 +194,6 @@ int vcc_release(struct socket *sock)
197 return 0; 194 return 0;
198} 195}
199 196
200
201void vcc_release_async(struct atm_vcc *vcc, int reply) 197void vcc_release_async(struct atm_vcc *vcc, int reply)
202{ 198{
203 struct sock *sk = sk_atm(vcc); 199 struct sock *sk = sk_atm(vcc);
@@ -208,8 +204,6 @@ void vcc_release_async(struct atm_vcc *vcc, int reply)
208 clear_bit(ATM_VF_WAITING, &vcc->flags); 204 clear_bit(ATM_VF_WAITING, &vcc->flags);
209 sk->sk_state_change(sk); 205 sk->sk_state_change(sk);
210} 206}
211
212
213EXPORT_SYMBOL(vcc_release_async); 207EXPORT_SYMBOL(vcc_release_async);
214 208
215 209
@@ -235,37 +229,37 @@ void atm_dev_release_vccs(struct atm_dev *dev)
235 write_unlock_irq(&vcc_sklist_lock); 229 write_unlock_irq(&vcc_sklist_lock);
236} 230}
237 231
238 232static int adjust_tp(struct atm_trafprm *tp, unsigned char aal)
239static int adjust_tp(struct atm_trafprm *tp,unsigned char aal)
240{ 233{
241 int max_sdu; 234 int max_sdu;
242 235
243 if (!tp->traffic_class) return 0; 236 if (!tp->traffic_class)
237 return 0;
244 switch (aal) { 238 switch (aal) {
245 case ATM_AAL0: 239 case ATM_AAL0:
246 max_sdu = ATM_CELL_SIZE-1; 240 max_sdu = ATM_CELL_SIZE-1;
247 break; 241 break;
248 case ATM_AAL34: 242 case ATM_AAL34:
249 max_sdu = ATM_MAX_AAL34_PDU; 243 max_sdu = ATM_MAX_AAL34_PDU;
250 break; 244 break;
251 default: 245 default:
252 printk(KERN_WARNING "ATM: AAL problems ... " 246 pr_warning("AAL problems ... (%d)\n", aal);
253 "(%d)\n",aal); 247 /* fall through */
254 /* fall through */ 248 case ATM_AAL5:
255 case ATM_AAL5: 249 max_sdu = ATM_MAX_AAL5_PDU;
256 max_sdu = ATM_MAX_AAL5_PDU;
257 } 250 }
258 if (!tp->max_sdu) tp->max_sdu = max_sdu; 251 if (!tp->max_sdu)
259 else if (tp->max_sdu > max_sdu) return -EINVAL; 252 tp->max_sdu = max_sdu;
260 if (!tp->max_cdv) tp->max_cdv = ATM_MAX_CDV; 253 else if (tp->max_sdu > max_sdu)
254 return -EINVAL;
255 if (!tp->max_cdv)
256 tp->max_cdv = ATM_MAX_CDV;
261 return 0; 257 return 0;
262} 258}
263 259
264
265static int check_ci(const struct atm_vcc *vcc, short vpi, int vci) 260static int check_ci(const struct atm_vcc *vcc, short vpi, int vci)
266{ 261{
267 struct hlist_head *head = &vcc_hash[vci & 262 struct hlist_head *head = &vcc_hash[vci & (VCC_HTABLE_SIZE - 1)];
268 (VCC_HTABLE_SIZE - 1)];
269 struct hlist_node *node; 263 struct hlist_node *node;
270 struct sock *s; 264 struct sock *s;
271 struct atm_vcc *walk; 265 struct atm_vcc *walk;
@@ -289,7 +283,6 @@ static int check_ci(const struct atm_vcc *vcc, short vpi, int vci)
289 return 0; 283 return 0;
290} 284}
291 285
292
293static int find_ci(const struct atm_vcc *vcc, short *vpi, int *vci) 286static int find_ci(const struct atm_vcc *vcc, short *vpi, int *vci)
294{ 287{
295 static short p; /* poor man's per-device cache */ 288 static short p; /* poor man's per-device cache */
@@ -327,14 +320,13 @@ static int find_ci(const struct atm_vcc *vcc, short *vpi, int *vci)
327 if ((c == ATM_NOT_RSV_VCI || *vci != ATM_VCI_ANY) && 320 if ((c == ATM_NOT_RSV_VCI || *vci != ATM_VCI_ANY) &&
328 *vpi == ATM_VPI_ANY) { 321 *vpi == ATM_VPI_ANY) {
329 p++; 322 p++;
330 if (p >= 1 << vcc->dev->ci_range.vpi_bits) p = 0; 323 if (p >= 1 << vcc->dev->ci_range.vpi_bits)
324 p = 0;
331 } 325 }
332 } 326 } while (old_p != p || old_c != c);
333 while (old_p != p || old_c != c);
334 return -EADDRINUSE; 327 return -EADDRINUSE;
335} 328}
336 329
337
338static int __vcc_connect(struct atm_vcc *vcc, struct atm_dev *dev, short vpi, 330static int __vcc_connect(struct atm_vcc *vcc, struct atm_dev *dev, short vpi,
339 int vci) 331 int vci)
340{ 332{
@@ -362,37 +354,46 @@ static int __vcc_connect(struct atm_vcc *vcc, struct atm_dev *dev, short vpi,
362 __vcc_insert_socket(sk); 354 __vcc_insert_socket(sk);
363 write_unlock_irq(&vcc_sklist_lock); 355 write_unlock_irq(&vcc_sklist_lock);
364 switch (vcc->qos.aal) { 356 switch (vcc->qos.aal) {
365 case ATM_AAL0: 357 case ATM_AAL0:
366 error = atm_init_aal0(vcc); 358 error = atm_init_aal0(vcc);
367 vcc->stats = &dev->stats.aal0; 359 vcc->stats = &dev->stats.aal0;
368 break; 360 break;
369 case ATM_AAL34: 361 case ATM_AAL34:
370 error = atm_init_aal34(vcc); 362 error = atm_init_aal34(vcc);
371 vcc->stats = &dev->stats.aal34; 363 vcc->stats = &dev->stats.aal34;
372 break; 364 break;
373 case ATM_NO_AAL: 365 case ATM_NO_AAL:
374 /* ATM_AAL5 is also used in the "0 for default" case */ 366 /* ATM_AAL5 is also used in the "0 for default" case */
375 vcc->qos.aal = ATM_AAL5; 367 vcc->qos.aal = ATM_AAL5;
376 /* fall through */ 368 /* fall through */
377 case ATM_AAL5: 369 case ATM_AAL5:
378 error = atm_init_aal5(vcc); 370 error = atm_init_aal5(vcc);
379 vcc->stats = &dev->stats.aal5; 371 vcc->stats = &dev->stats.aal5;
380 break; 372 break;
381 default: 373 default:
382 error = -EPROTOTYPE; 374 error = -EPROTOTYPE;
383 } 375 }
384 if (!error) error = adjust_tp(&vcc->qos.txtp,vcc->qos.aal); 376 if (!error)
385 if (!error) error = adjust_tp(&vcc->qos.rxtp,vcc->qos.aal); 377 error = adjust_tp(&vcc->qos.txtp, vcc->qos.aal);
378 if (!error)
379 error = adjust_tp(&vcc->qos.rxtp, vcc->qos.aal);
386 if (error) 380 if (error)
387 goto fail; 381 goto fail;
388 pr_debug("VCC %d.%d, AAL %d\n",vpi,vci,vcc->qos.aal); 382 pr_debug("VCC %d.%d, AAL %d\n", vpi, vci, vcc->qos.aal);
389 pr_debug(" TX: %d, PCR %d..%d, SDU %d\n",vcc->qos.txtp.traffic_class, 383 pr_debug(" TX: %d, PCR %d..%d, SDU %d\n",
390 vcc->qos.txtp.min_pcr,vcc->qos.txtp.max_pcr,vcc->qos.txtp.max_sdu); 384 vcc->qos.txtp.traffic_class,
391 pr_debug(" RX: %d, PCR %d..%d, SDU %d\n",vcc->qos.rxtp.traffic_class, 385 vcc->qos.txtp.min_pcr,
392 vcc->qos.rxtp.min_pcr,vcc->qos.rxtp.max_pcr,vcc->qos.rxtp.max_sdu); 386 vcc->qos.txtp.max_pcr,
387 vcc->qos.txtp.max_sdu);
388 pr_debug(" RX: %d, PCR %d..%d, SDU %d\n",
389 vcc->qos.rxtp.traffic_class,
390 vcc->qos.rxtp.min_pcr,
391 vcc->qos.rxtp.max_pcr,
392 vcc->qos.rxtp.max_sdu);
393 393
394 if (dev->ops->open) { 394 if (dev->ops->open) {
395 if ((error = dev->ops->open(vcc))) 395 error = dev->ops->open(vcc);
396 if (error)
396 goto fail; 397 goto fail;
397 } 398 }
398 return 0; 399 return 0;
@@ -406,14 +407,13 @@ fail_module_put:
406 return error; 407 return error;
407} 408}
408 409
409
410int vcc_connect(struct socket *sock, int itf, short vpi, int vci) 410int vcc_connect(struct socket *sock, int itf, short vpi, int vci)
411{ 411{
412 struct atm_dev *dev; 412 struct atm_dev *dev;
413 struct atm_vcc *vcc = ATM_SD(sock); 413 struct atm_vcc *vcc = ATM_SD(sock);
414 int error; 414 int error;
415 415
416 pr_debug("vcc_connect (vpi %d, vci %d)\n",vpi,vci); 416 pr_debug("(vpi %d, vci %d)\n", vpi, vci);
417 if (sock->state == SS_CONNECTED) 417 if (sock->state == SS_CONNECTED)
418 return -EISCONN; 418 return -EISCONN;
419 if (sock->state != SS_UNCONNECTED) 419 if (sock->state != SS_UNCONNECTED)
@@ -422,30 +422,33 @@ int vcc_connect(struct socket *sock, int itf, short vpi, int vci)
422 return -EINVAL; 422 return -EINVAL;
423 423
424 if (vpi != ATM_VPI_UNSPEC && vci != ATM_VCI_UNSPEC) 424 if (vpi != ATM_VPI_UNSPEC && vci != ATM_VCI_UNSPEC)
425 clear_bit(ATM_VF_PARTIAL,&vcc->flags); 425 clear_bit(ATM_VF_PARTIAL, &vcc->flags);
426 else 426 else
427 if (test_bit(ATM_VF_PARTIAL,&vcc->flags)) 427 if (test_bit(ATM_VF_PARTIAL, &vcc->flags))
428 return -EINVAL; 428 return -EINVAL;
429 pr_debug("vcc_connect (TX: cl %d,bw %d-%d,sdu %d; " 429 pr_debug("(TX: cl %d,bw %d-%d,sdu %d; "
430 "RX: cl %d,bw %d-%d,sdu %d,AAL %s%d)\n", 430 "RX: cl %d,bw %d-%d,sdu %d,AAL %s%d)\n",
431 vcc->qos.txtp.traffic_class,vcc->qos.txtp.min_pcr, 431 vcc->qos.txtp.traffic_class, vcc->qos.txtp.min_pcr,
432 vcc->qos.txtp.max_pcr,vcc->qos.txtp.max_sdu, 432 vcc->qos.txtp.max_pcr, vcc->qos.txtp.max_sdu,
433 vcc->qos.rxtp.traffic_class,vcc->qos.rxtp.min_pcr, 433 vcc->qos.rxtp.traffic_class, vcc->qos.rxtp.min_pcr,
434 vcc->qos.rxtp.max_pcr,vcc->qos.rxtp.max_sdu, 434 vcc->qos.rxtp.max_pcr, vcc->qos.rxtp.max_sdu,
435 vcc->qos.aal == ATM_AAL5 ? "" : vcc->qos.aal == ATM_AAL0 ? "" : 435 vcc->qos.aal == ATM_AAL5 ? "" :
436 " ??? code ",vcc->qos.aal == ATM_AAL0 ? 0 : vcc->qos.aal); 436 vcc->qos.aal == ATM_AAL0 ? "" : " ??? code ",
437 vcc->qos.aal == ATM_AAL0 ? 0 : vcc->qos.aal);
437 if (!test_bit(ATM_VF_HASQOS, &vcc->flags)) 438 if (!test_bit(ATM_VF_HASQOS, &vcc->flags))
438 return -EBADFD; 439 return -EBADFD;
439 if (vcc->qos.txtp.traffic_class == ATM_ANYCLASS || 440 if (vcc->qos.txtp.traffic_class == ATM_ANYCLASS ||
440 vcc->qos.rxtp.traffic_class == ATM_ANYCLASS) 441 vcc->qos.rxtp.traffic_class == ATM_ANYCLASS)
441 return -EINVAL; 442 return -EINVAL;
442 if (likely(itf != ATM_ITF_ANY)) { 443 if (likely(itf != ATM_ITF_ANY)) {
443 dev = try_then_request_module(atm_dev_lookup(itf), "atm-device-%d", itf); 444 dev = try_then_request_module(atm_dev_lookup(itf),
445 "atm-device-%d", itf);
444 } else { 446 } else {
445 dev = NULL; 447 dev = NULL;
446 mutex_lock(&atm_dev_mutex); 448 mutex_lock(&atm_dev_mutex);
447 if (!list_empty(&atm_devs)) { 449 if (!list_empty(&atm_devs)) {
448 dev = list_entry(atm_devs.next, struct atm_dev, dev_list); 450 dev = list_entry(atm_devs.next,
451 struct atm_dev, dev_list);
449 atm_dev_hold(dev); 452 atm_dev_hold(dev);
450 } 453 }
451 mutex_unlock(&atm_dev_mutex); 454 mutex_unlock(&atm_dev_mutex);
@@ -458,13 +461,12 @@ int vcc_connect(struct socket *sock, int itf, short vpi, int vci)
458 return error; 461 return error;
459 } 462 }
460 if (vpi == ATM_VPI_UNSPEC || vci == ATM_VCI_UNSPEC) 463 if (vpi == ATM_VPI_UNSPEC || vci == ATM_VCI_UNSPEC)
461 set_bit(ATM_VF_PARTIAL,&vcc->flags); 464 set_bit(ATM_VF_PARTIAL, &vcc->flags);
462 if (test_bit(ATM_VF_READY,&ATM_SD(sock)->flags)) 465 if (test_bit(ATM_VF_READY, &ATM_SD(sock)->flags))
463 sock->state = SS_CONNECTED; 466 sock->state = SS_CONNECTED;
464 return 0; 467 return 0;
465} 468}
466 469
467
468int vcc_recvmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *msg, 470int vcc_recvmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *msg,
469 size_t size, int flags) 471 size_t size, int flags)
470{ 472{
@@ -478,8 +480,8 @@ int vcc_recvmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *msg,
478 if (flags & ~MSG_DONTWAIT) /* only handle MSG_DONTWAIT */ 480 if (flags & ~MSG_DONTWAIT) /* only handle MSG_DONTWAIT */
479 return -EOPNOTSUPP; 481 return -EOPNOTSUPP;
480 vcc = ATM_SD(sock); 482 vcc = ATM_SD(sock);
481 if (test_bit(ATM_VF_RELEASED,&vcc->flags) || 483 if (test_bit(ATM_VF_RELEASED, &vcc->flags) ||
482 test_bit(ATM_VF_CLOSE,&vcc->flags) || 484 test_bit(ATM_VF_CLOSE, &vcc->flags) ||
483 !test_bit(ATM_VF_READY, &vcc->flags)) 485 !test_bit(ATM_VF_READY, &vcc->flags))
484 return 0; 486 return 0;
485 487
@@ -496,14 +498,13 @@ int vcc_recvmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *msg,
496 error = skb_copy_datagram_iovec(skb, 0, msg->msg_iov, copied); 498 error = skb_copy_datagram_iovec(skb, 0, msg->msg_iov, copied);
497 if (error) 499 if (error)
498 return error; 500 return error;
499 sock_recv_timestamp(msg, sk, skb); 501 sock_recv_ts_and_drops(msg, sk, skb);
500 pr_debug("RcvM %d -= %d\n", atomic_read(&sk->sk_rmem_alloc), skb->truesize); 502 pr_debug("%d -= %d\n", atomic_read(&sk->sk_rmem_alloc), skb->truesize);
501 atm_return(vcc, skb->truesize); 503 atm_return(vcc, skb->truesize);
502 skb_free_datagram(sk, skb); 504 skb_free_datagram(sk, skb);
503 return copied; 505 return copied;
504} 506}
505 507
506
507int vcc_sendmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *m, 508int vcc_sendmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *m,
508 size_t total_len) 509 size_t total_len)
509{ 510{
@@ -511,7 +512,7 @@ int vcc_sendmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *m,
511 DEFINE_WAIT(wait); 512 DEFINE_WAIT(wait);
512 struct atm_vcc *vcc; 513 struct atm_vcc *vcc;
513 struct sk_buff *skb; 514 struct sk_buff *skb;
514 int eff,error; 515 int eff, error;
515 const void __user *buff; 516 const void __user *buff;
516 int size; 517 int size;
517 518
@@ -550,7 +551,7 @@ int vcc_sendmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *m,
550 eff = (size+3) & ~3; /* align to word boundary */ 551 eff = (size+3) & ~3; /* align to word boundary */
551 prepare_to_wait(sk->sk_sleep, &wait, TASK_INTERRUPTIBLE); 552 prepare_to_wait(sk->sk_sleep, &wait, TASK_INTERRUPTIBLE);
552 error = 0; 553 error = 0;
553 while (!(skb = alloc_tx(vcc,eff))) { 554 while (!(skb = alloc_tx(vcc, eff))) {
554 if (m->msg_flags & MSG_DONTWAIT) { 555 if (m->msg_flags & MSG_DONTWAIT) {
555 error = -EAGAIN; 556 error = -EAGAIN;
556 break; 557 break;
@@ -560,9 +561,9 @@ int vcc_sendmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *m,
560 error = -ERESTARTSYS; 561 error = -ERESTARTSYS;
561 break; 562 break;
562 } 563 }
563 if (test_bit(ATM_VF_RELEASED,&vcc->flags) || 564 if (test_bit(ATM_VF_RELEASED, &vcc->flags) ||
564 test_bit(ATM_VF_CLOSE,&vcc->flags) || 565 test_bit(ATM_VF_CLOSE, &vcc->flags) ||
565 !test_bit(ATM_VF_READY,&vcc->flags)) { 566 !test_bit(ATM_VF_READY, &vcc->flags)) {
566 error = -EPIPE; 567 error = -EPIPE;
567 send_sig(SIGPIPE, current, 0); 568 send_sig(SIGPIPE, current, 0);
568 break; 569 break;
@@ -574,20 +575,20 @@ int vcc_sendmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *m,
574 goto out; 575 goto out;
575 skb->dev = NULL; /* for paths shared with net_device interfaces */ 576 skb->dev = NULL; /* for paths shared with net_device interfaces */
576 ATM_SKB(skb)->atm_options = vcc->atm_options; 577 ATM_SKB(skb)->atm_options = vcc->atm_options;
577 if (copy_from_user(skb_put(skb,size),buff,size)) { 578 if (copy_from_user(skb_put(skb, size), buff, size)) {
578 kfree_skb(skb); 579 kfree_skb(skb);
579 error = -EFAULT; 580 error = -EFAULT;
580 goto out; 581 goto out;
581 } 582 }
582 if (eff != size) memset(skb->data+size,0,eff-size); 583 if (eff != size)
583 error = vcc->dev->ops->send(vcc,skb); 584 memset(skb->data + size, 0, eff-size);
585 error = vcc->dev->ops->send(vcc, skb);
584 error = error ? error : size; 586 error = error ? error : size;
585out: 587out:
586 release_sock(sk); 588 release_sock(sk);
587 return error; 589 return error;
588} 590}
589 591
590
591unsigned int vcc_poll(struct file *file, struct socket *sock, poll_table *wait) 592unsigned int vcc_poll(struct file *file, struct socket *sock, poll_table *wait)
592{ 593{
593 struct sock *sk = sock->sk; 594 struct sock *sk = sock->sk;
@@ -623,8 +624,7 @@ unsigned int vcc_poll(struct file *file, struct socket *sock, poll_table *wait)
623 return mask; 624 return mask;
624} 625}
625 626
626 627static int atm_change_qos(struct atm_vcc *vcc, struct atm_qos *qos)
627static int atm_change_qos(struct atm_vcc *vcc,struct atm_qos *qos)
628{ 628{
629 int error; 629 int error;
630 630
@@ -636,25 +636,31 @@ static int atm_change_qos(struct atm_vcc *vcc,struct atm_qos *qos)
636 qos->rxtp.traffic_class != vcc->qos.rxtp.traffic_class || 636 qos->rxtp.traffic_class != vcc->qos.rxtp.traffic_class ||
637 qos->txtp.traffic_class != vcc->qos.txtp.traffic_class) 637 qos->txtp.traffic_class != vcc->qos.txtp.traffic_class)
638 return -EINVAL; 638 return -EINVAL;
639 error = adjust_tp(&qos->txtp,qos->aal); 639 error = adjust_tp(&qos->txtp, qos->aal);
640 if (!error) error = adjust_tp(&qos->rxtp,qos->aal); 640 if (!error)
641 if (error) return error; 641 error = adjust_tp(&qos->rxtp, qos->aal);
642 if (!vcc->dev->ops->change_qos) return -EOPNOTSUPP; 642 if (error)
643 return error;
644 if (!vcc->dev->ops->change_qos)
645 return -EOPNOTSUPP;
643 if (sk_atm(vcc)->sk_family == AF_ATMPVC) 646 if (sk_atm(vcc)->sk_family == AF_ATMPVC)
644 return vcc->dev->ops->change_qos(vcc,qos,ATM_MF_SET); 647 return vcc->dev->ops->change_qos(vcc, qos, ATM_MF_SET);
645 return svc_change_qos(vcc,qos); 648 return svc_change_qos(vcc, qos);
646} 649}
647 650
648
649static int check_tp(const struct atm_trafprm *tp) 651static int check_tp(const struct atm_trafprm *tp)
650{ 652{
651 /* @@@ Should be merged with adjust_tp */ 653 /* @@@ Should be merged with adjust_tp */
652 if (!tp->traffic_class || tp->traffic_class == ATM_ANYCLASS) return 0; 654 if (!tp->traffic_class || tp->traffic_class == ATM_ANYCLASS)
655 return 0;
653 if (tp->traffic_class != ATM_UBR && !tp->min_pcr && !tp->pcr && 656 if (tp->traffic_class != ATM_UBR && !tp->min_pcr && !tp->pcr &&
654 !tp->max_pcr) return -EINVAL; 657 !tp->max_pcr)
655 if (tp->min_pcr == ATM_MAX_PCR) return -EINVAL; 658 return -EINVAL;
659 if (tp->min_pcr == ATM_MAX_PCR)
660 return -EINVAL;
656 if (tp->min_pcr && tp->max_pcr && tp->max_pcr != ATM_MAX_PCR && 661 if (tp->min_pcr && tp->max_pcr && tp->max_pcr != ATM_MAX_PCR &&
657 tp->min_pcr > tp->max_pcr) return -EINVAL; 662 tp->min_pcr > tp->max_pcr)
663 return -EINVAL;
658 /* 664 /*
659 * We allow pcr to be outside [min_pcr,max_pcr], because later 665 * We allow pcr to be outside [min_pcr,max_pcr], because later
660 * adjustment may still push it in the valid range. 666 * adjustment may still push it in the valid range.
@@ -662,7 +668,6 @@ static int check_tp(const struct atm_trafprm *tp)
662 return 0; 668 return 0;
663} 669}
664 670
665
666static int check_qos(const struct atm_qos *qos) 671static int check_qos(const struct atm_qos *qos)
667{ 672{
668 int error; 673 int error;
@@ -672,9 +677,11 @@ static int check_qos(const struct atm_qos *qos)
672 if (qos->txtp.traffic_class != qos->rxtp.traffic_class && 677 if (qos->txtp.traffic_class != qos->rxtp.traffic_class &&
673 qos->txtp.traffic_class && qos->rxtp.traffic_class && 678 qos->txtp.traffic_class && qos->rxtp.traffic_class &&
674 qos->txtp.traffic_class != ATM_ANYCLASS && 679 qos->txtp.traffic_class != ATM_ANYCLASS &&
675 qos->rxtp.traffic_class != ATM_ANYCLASS) return -EINVAL; 680 qos->rxtp.traffic_class != ATM_ANYCLASS)
681 return -EINVAL;
676 error = check_tp(&qos->txtp); 682 error = check_tp(&qos->txtp);
677 if (error) return error; 683 if (error)
684 return error;
678 return check_tp(&qos->rxtp); 685 return check_tp(&qos->rxtp);
679} 686}
680 687
@@ -690,37 +697,41 @@ int vcc_setsockopt(struct socket *sock, int level, int optname,
690 697
691 vcc = ATM_SD(sock); 698 vcc = ATM_SD(sock);
692 switch (optname) { 699 switch (optname) {
693 case SO_ATMQOS: 700 case SO_ATMQOS:
694 { 701 {
695 struct atm_qos qos; 702 struct atm_qos qos;
696 703
697 if (copy_from_user(&qos,optval,sizeof(qos))) 704 if (copy_from_user(&qos, optval, sizeof(qos)))
698 return -EFAULT; 705 return -EFAULT;
699 error = check_qos(&qos); 706 error = check_qos(&qos);
700 if (error) return error; 707 if (error)
701 if (sock->state == SS_CONNECTED) 708 return error;
702 return atm_change_qos(vcc,&qos); 709 if (sock->state == SS_CONNECTED)
703 if (sock->state != SS_UNCONNECTED) 710 return atm_change_qos(vcc, &qos);
704 return -EBADFD; 711 if (sock->state != SS_UNCONNECTED)
705 vcc->qos = qos; 712 return -EBADFD;
706 set_bit(ATM_VF_HASQOS,&vcc->flags); 713 vcc->qos = qos;
707 return 0; 714 set_bit(ATM_VF_HASQOS, &vcc->flags);
708 } 715 return 0;
709 case SO_SETCLP:
710 if (get_user(value,(unsigned long __user *)optval))
711 return -EFAULT;
712 if (value) vcc->atm_options |= ATM_ATMOPT_CLP;
713 else vcc->atm_options &= ~ATM_ATMOPT_CLP;
714 return 0;
715 default:
716 if (level == SOL_SOCKET) return -EINVAL;
717 break;
718 } 716 }
719 if (!vcc->dev || !vcc->dev->ops->setsockopt) return -EINVAL; 717 case SO_SETCLP:
720 return vcc->dev->ops->setsockopt(vcc,level,optname,optval,optlen); 718 if (get_user(value, (unsigned long __user *)optval))
719 return -EFAULT;
720 if (value)
721 vcc->atm_options |= ATM_ATMOPT_CLP;
722 else
723 vcc->atm_options &= ~ATM_ATMOPT_CLP;
724 return 0;
725 default:
726 if (level == SOL_SOCKET)
727 return -EINVAL;
728 break;
729 }
730 if (!vcc->dev || !vcc->dev->ops->setsockopt)
731 return -EINVAL;
732 return vcc->dev->ops->setsockopt(vcc, level, optname, optval, optlen);
721} 733}
722 734
723
724int vcc_getsockopt(struct socket *sock, int level, int optname, 735int vcc_getsockopt(struct socket *sock, int level, int optname,
725 char __user *optval, int __user *optlen) 736 char __user *optval, int __user *optlen)
726{ 737{
@@ -734,33 +745,33 @@ int vcc_getsockopt(struct socket *sock, int level, int optname,
734 745
735 vcc = ATM_SD(sock); 746 vcc = ATM_SD(sock);
736 switch (optname) { 747 switch (optname) {
737 case SO_ATMQOS: 748 case SO_ATMQOS:
738 if (!test_bit(ATM_VF_HASQOS,&vcc->flags)) 749 if (!test_bit(ATM_VF_HASQOS, &vcc->flags))
739 return -EINVAL; 750 return -EINVAL;
740 return copy_to_user(optval,&vcc->qos,sizeof(vcc->qos)) ? 751 return copy_to_user(optval, &vcc->qos, sizeof(vcc->qos))
741 -EFAULT : 0; 752 ? -EFAULT : 0;
742 case SO_SETCLP: 753 case SO_SETCLP:
743 return put_user(vcc->atm_options & ATM_ATMOPT_CLP ? 1 : 754 return put_user(vcc->atm_options & ATM_ATMOPT_CLP ? 1 : 0,
744 0,(unsigned long __user *)optval) ? -EFAULT : 0; 755 (unsigned long __user *)optval) ? -EFAULT : 0;
745 case SO_ATMPVC: 756 case SO_ATMPVC:
746 { 757 {
747 struct sockaddr_atmpvc pvc; 758 struct sockaddr_atmpvc pvc;
748 759
749 if (!vcc->dev || 760 if (!vcc->dev || !test_bit(ATM_VF_ADDR, &vcc->flags))
750 !test_bit(ATM_VF_ADDR,&vcc->flags)) 761 return -ENOTCONN;
751 return -ENOTCONN; 762 pvc.sap_family = AF_ATMPVC;
752 pvc.sap_family = AF_ATMPVC; 763 pvc.sap_addr.itf = vcc->dev->number;
753 pvc.sap_addr.itf = vcc->dev->number; 764 pvc.sap_addr.vpi = vcc->vpi;
754 pvc.sap_addr.vpi = vcc->vpi; 765 pvc.sap_addr.vci = vcc->vci;
755 pvc.sap_addr.vci = vcc->vci; 766 return copy_to_user(optval, &pvc, sizeof(pvc)) ? -EFAULT : 0;
756 return copy_to_user(optval,&pvc,sizeof(pvc)) ? 767 }
757 -EFAULT : 0; 768 default:
758 } 769 if (level == SOL_SOCKET)
759 default: 770 return -EINVAL;
760 if (level == SOL_SOCKET) return -EINVAL;
761 break; 771 break;
762 } 772 }
763 if (!vcc->dev || !vcc->dev->ops->getsockopt) return -EINVAL; 773 if (!vcc->dev || !vcc->dev->ops->getsockopt)
774 return -EINVAL;
764 return vcc->dev->ops->getsockopt(vcc, level, optname, optval, len); 775 return vcc->dev->ops->getsockopt(vcc, level, optname, optval, len);
765} 776}
766 777
@@ -768,23 +779,27 @@ static int __init atm_init(void)
768{ 779{
769 int error; 780 int error;
770 781
771 if ((error = proto_register(&vcc_proto, 0)) < 0) 782 error = proto_register(&vcc_proto, 0);
783 if (error < 0)
772 goto out; 784 goto out;
773 785 error = atmpvc_init();
774 if ((error = atmpvc_init()) < 0) { 786 if (error < 0) {
775 printk(KERN_ERR "atmpvc_init() failed with %d\n", error); 787 pr_err("atmpvc_init() failed with %d\n", error);
776 goto out_unregister_vcc_proto; 788 goto out_unregister_vcc_proto;
777 } 789 }
778 if ((error = atmsvc_init()) < 0) { 790 error = atmsvc_init();
779 printk(KERN_ERR "atmsvc_init() failed with %d\n", error); 791 if (error < 0) {
792 pr_err("atmsvc_init() failed with %d\n", error);
780 goto out_atmpvc_exit; 793 goto out_atmpvc_exit;
781 } 794 }
782 if ((error = atm_proc_init()) < 0) { 795 error = atm_proc_init();
783 printk(KERN_ERR "atm_proc_init() failed with %d\n",error); 796 if (error < 0) {
797 pr_err("atm_proc_init() failed with %d\n", error);
784 goto out_atmsvc_exit; 798 goto out_atmsvc_exit;
785 } 799 }
786 if ((error = atm_sysfs_init()) < 0) { 800 error = atm_sysfs_init();
787 printk(KERN_ERR "atm_sysfs_init() failed with %d\n",error); 801 if (error < 0) {
802 pr_err("atm_sysfs_init() failed with %d\n", error);
788 goto out_atmproc_exit; 803 goto out_atmproc_exit;
789 } 804 }
790out: 805out:
diff --git a/net/atm/ioctl.c b/net/atm/ioctl.c
index 4da8892ced5f..62dc8bfe6fe7 100644
--- a/net/atm/ioctl.c
+++ b/net/atm/ioctl.c
@@ -3,6 +3,7 @@
3/* Written 1995-2000 by Werner Almesberger, EPFL LRC/ICA */ 3/* Written 1995-2000 by Werner Almesberger, EPFL LRC/ICA */
4/* 2003 John Levon <levon@movementarian.org> */ 4/* 2003 John Levon <levon@movementarian.org> */
5 5
6#define pr_fmt(fmt) KBUILD_MODNAME ":%s: " fmt, __func__
6 7
7#include <linux/module.h> 8#include <linux/module.h>
8#include <linux/kmod.h> 9#include <linux/kmod.h>
@@ -36,6 +37,7 @@ void register_atm_ioctl(struct atm_ioctl *ioctl)
36 list_add_tail(&ioctl->list, &ioctl_list); 37 list_add_tail(&ioctl->list, &ioctl_list);
37 mutex_unlock(&ioctl_mutex); 38 mutex_unlock(&ioctl_mutex);
38} 39}
40EXPORT_SYMBOL(register_atm_ioctl);
39 41
40void deregister_atm_ioctl(struct atm_ioctl *ioctl) 42void deregister_atm_ioctl(struct atm_ioctl *ioctl)
41{ 43{
@@ -43,129 +45,128 @@ void deregister_atm_ioctl(struct atm_ioctl *ioctl)
43 list_del(&ioctl->list); 45 list_del(&ioctl->list);
44 mutex_unlock(&ioctl_mutex); 46 mutex_unlock(&ioctl_mutex);
45} 47}
46
47EXPORT_SYMBOL(register_atm_ioctl);
48EXPORT_SYMBOL(deregister_atm_ioctl); 48EXPORT_SYMBOL(deregister_atm_ioctl);
49 49
50static int do_vcc_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg, int compat) 50static int do_vcc_ioctl(struct socket *sock, unsigned int cmd,
51 unsigned long arg, int compat)
51{ 52{
52 struct sock *sk = sock->sk; 53 struct sock *sk = sock->sk;
53 struct atm_vcc *vcc; 54 struct atm_vcc *vcc;
54 int error; 55 int error;
55 struct list_head * pos; 56 struct list_head *pos;
56 void __user *argp = (void __user *)arg; 57 void __user *argp = (void __user *)arg;
57 58
58 vcc = ATM_SD(sock); 59 vcc = ATM_SD(sock);
59 switch (cmd) { 60 switch (cmd) {
60 case SIOCOUTQ: 61 case SIOCOUTQ:
61 if (sock->state != SS_CONNECTED || 62 if (sock->state != SS_CONNECTED ||
62 !test_bit(ATM_VF_READY, &vcc->flags)) { 63 !test_bit(ATM_VF_READY, &vcc->flags)) {
63 error = -EINVAL; 64 error = -EINVAL;
64 goto done; 65 goto done;
65 } 66 }
66 error = put_user(sk->sk_sndbuf - sk_wmem_alloc_get(sk), 67 error = put_user(sk->sk_sndbuf - sk_wmem_alloc_get(sk),
67 (int __user *) argp) ? -EFAULT : 0; 68 (int __user *)argp) ? -EFAULT : 0;
69 goto done;
70 case SIOCINQ:
71 {
72 struct sk_buff *skb;
73
74 if (sock->state != SS_CONNECTED) {
75 error = -EINVAL;
68 goto done; 76 goto done;
69 case SIOCINQ: 77 }
70 { 78 skb = skb_peek(&sk->sk_receive_queue);
71 struct sk_buff *skb; 79 error = put_user(skb ? skb->len : 0,
72 80 (int __user *)argp) ? -EFAULT : 0;
73 if (sock->state != SS_CONNECTED) { 81 goto done;
74 error = -EINVAL; 82 }
75 goto done; 83 case SIOCGSTAMP: /* borrowed from IP */
76 }
77 skb = skb_peek(&sk->sk_receive_queue);
78 error = put_user(skb ? skb->len : 0,
79 (int __user *)argp) ? -EFAULT : 0;
80 goto done;
81 }
82 case SIOCGSTAMP: /* borrowed from IP */
83#ifdef CONFIG_COMPAT 84#ifdef CONFIG_COMPAT
84 if (compat) 85 if (compat)
85 error = compat_sock_get_timestamp(sk, argp); 86 error = compat_sock_get_timestamp(sk, argp);
86 else 87 else
87#endif 88#endif
88 error = sock_get_timestamp(sk, argp); 89 error = sock_get_timestamp(sk, argp);
89 goto done; 90 goto done;
90 case SIOCGSTAMPNS: /* borrowed from IP */ 91 case SIOCGSTAMPNS: /* borrowed from IP */
91#ifdef CONFIG_COMPAT 92#ifdef CONFIG_COMPAT
92 if (compat) 93 if (compat)
93 error = compat_sock_get_timestampns(sk, argp); 94 error = compat_sock_get_timestampns(sk, argp);
94 else 95 else
95#endif 96#endif
96 error = sock_get_timestampns(sk, argp); 97 error = sock_get_timestampns(sk, argp);
98 goto done;
99 case ATM_SETSC:
100 if (net_ratelimit())
101 pr_warning("ATM_SETSC is obsolete; used by %s:%d\n",
102 current->comm, task_pid_nr(current));
103 error = 0;
104 goto done;
105 case ATMSIGD_CTRL:
106 if (!capable(CAP_NET_ADMIN)) {
107 error = -EPERM;
97 goto done; 108 goto done;
98 case ATM_SETSC: 109 }
99 if (net_ratelimit()) 110 /*
100 printk(KERN_WARNING "ATM_SETSC is obsolete; used by %s:%d\n", 111 * The user/kernel protocol for exchanging signalling
101 current->comm, task_pid_nr(current)); 112 * info uses kernel pointers as opaque references,
102 error = 0; 113 * so the holder of the file descriptor can scribble
114 * on the kernel... so we should make sure that we
115 * have the same privileges that /proc/kcore needs
116 */
117 if (!capable(CAP_SYS_RAWIO)) {
118 error = -EPERM;
103 goto done; 119 goto done;
104 case ATMSIGD_CTRL: 120 }
105 if (!capable(CAP_NET_ADMIN)) {
106 error = -EPERM;
107 goto done;
108 }
109 /*
110 * The user/kernel protocol for exchanging signalling
111 * info uses kernel pointers as opaque references,
112 * so the holder of the file descriptor can scribble
113 * on the kernel... so we should make sure that we
114 * have the same privileges that /proc/kcore needs
115 */
116 if (!capable(CAP_SYS_RAWIO)) {
117 error = -EPERM;
118 goto done;
119 }
120#ifdef CONFIG_COMPAT 121#ifdef CONFIG_COMPAT
121 /* WTF? I don't even want to _think_ about making this 122 /* WTF? I don't even want to _think_ about making this
122 work for 32-bit userspace. TBH I don't really want 123 work for 32-bit userspace. TBH I don't really want
123 to think about it at all. dwmw2. */ 124 to think about it at all. dwmw2. */
124 if (compat) { 125 if (compat) {
125 if (net_ratelimit()) 126 if (net_ratelimit())
126 printk(KERN_WARNING "32-bit task cannot be atmsigd\n"); 127 pr_warning("32-bit task cannot be atmsigd\n");
127 error = -EINVAL; 128 error = -EINVAL;
128 goto done; 129 goto done;
129 } 130 }
130#endif 131#endif
131 error = sigd_attach(vcc); 132 error = sigd_attach(vcc);
132 if (!error) 133 if (!error)
133 sock->state = SS_CONNECTED; 134 sock->state = SS_CONNECTED;
135 goto done;
136 case ATM_SETBACKEND:
137 case ATM_NEWBACKENDIF:
138 {
139 atm_backend_t backend;
140 error = get_user(backend, (atm_backend_t __user *)argp);
141 if (error)
134 goto done; 142 goto done;
135 case ATM_SETBACKEND: 143 switch (backend) {
136 case ATM_NEWBACKENDIF: 144 case ATM_BACKEND_PPP:
137 { 145 request_module("pppoatm");
138 atm_backend_t backend;
139 error = get_user(backend, (atm_backend_t __user *) argp);
140 if (error)
141 goto done;
142 switch (backend) {
143 case ATM_BACKEND_PPP:
144 request_module("pppoatm");
145 break;
146 case ATM_BACKEND_BR2684:
147 request_module("br2684");
148 break;
149 }
150 }
151 break;
152 case ATMMPC_CTRL:
153 case ATMMPC_DATA:
154 request_module("mpoa");
155 break; 146 break;
156 case ATMARPD_CTRL: 147 case ATM_BACKEND_BR2684:
157 request_module("clip"); 148 request_module("br2684");
158 break;
159 case ATMLEC_CTRL:
160 request_module("lec");
161 break; 149 break;
150 }
151 break;
152 }
153 case ATMMPC_CTRL:
154 case ATMMPC_DATA:
155 request_module("mpoa");
156 break;
157 case ATMARPD_CTRL:
158 request_module("clip");
159 break;
160 case ATMLEC_CTRL:
161 request_module("lec");
162 break;
162 } 163 }
163 164
164 error = -ENOIOCTLCMD; 165 error = -ENOIOCTLCMD;
165 166
166 mutex_lock(&ioctl_mutex); 167 mutex_lock(&ioctl_mutex);
167 list_for_each(pos, &ioctl_list) { 168 list_for_each(pos, &ioctl_list) {
168 struct atm_ioctl * ic = list_entry(pos, struct atm_ioctl, list); 169 struct atm_ioctl *ic = list_entry(pos, struct atm_ioctl, list);
169 if (try_module_get(ic->owner)) { 170 if (try_module_get(ic->owner)) {
170 error = ic->ioctl(sock, cmd, arg); 171 error = ic->ioctl(sock, cmd, arg);
171 module_put(ic->owner); 172 module_put(ic->owner);
@@ -184,15 +185,187 @@ done:
184 return error; 185 return error;
185} 186}
186 187
187
188int vcc_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg) 188int vcc_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
189{ 189{
190 return do_vcc_ioctl(sock, cmd, arg, 0); 190 return do_vcc_ioctl(sock, cmd, arg, 0);
191} 191}
192 192
193#ifdef CONFIG_COMPAT 193#ifdef CONFIG_COMPAT
194int vcc_compat_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg) 194/*
195 * FIXME:
196 * The compat_ioctl handling is duplicated, using both these conversion
197 * routines and the compat argument to the actual handlers. Both
198 * versions are somewhat incomplete and should be merged, e.g. by
199 * moving the ioctl number translation into the actual handlers and
200 * killing the conversion code.
201 *
202 * -arnd, November 2009
203 */
204#define ATM_GETLINKRATE32 _IOW('a', ATMIOC_ITF+1, struct compat_atmif_sioc)
205#define ATM_GETNAMES32 _IOW('a', ATMIOC_ITF+3, struct compat_atm_iobuf)
206#define ATM_GETTYPE32 _IOW('a', ATMIOC_ITF+4, struct compat_atmif_sioc)
207#define ATM_GETESI32 _IOW('a', ATMIOC_ITF+5, struct compat_atmif_sioc)
208#define ATM_GETADDR32 _IOW('a', ATMIOC_ITF+6, struct compat_atmif_sioc)
209#define ATM_RSTADDR32 _IOW('a', ATMIOC_ITF+7, struct compat_atmif_sioc)
210#define ATM_ADDADDR32 _IOW('a', ATMIOC_ITF+8, struct compat_atmif_sioc)
211#define ATM_DELADDR32 _IOW('a', ATMIOC_ITF+9, struct compat_atmif_sioc)
212#define ATM_GETCIRANGE32 _IOW('a', ATMIOC_ITF+10, struct compat_atmif_sioc)
213#define ATM_SETCIRANGE32 _IOW('a', ATMIOC_ITF+11, struct compat_atmif_sioc)
214#define ATM_SETESI32 _IOW('a', ATMIOC_ITF+12, struct compat_atmif_sioc)
215#define ATM_SETESIF32 _IOW('a', ATMIOC_ITF+13, struct compat_atmif_sioc)
216#define ATM_GETSTAT32 _IOW('a', ATMIOC_SARCOM+0, struct compat_atmif_sioc)
217#define ATM_GETSTATZ32 _IOW('a', ATMIOC_SARCOM+1, struct compat_atmif_sioc)
218#define ATM_GETLOOP32 _IOW('a', ATMIOC_SARCOM+2, struct compat_atmif_sioc)
219#define ATM_SETLOOP32 _IOW('a', ATMIOC_SARCOM+3, struct compat_atmif_sioc)
220#define ATM_QUERYLOOP32 _IOW('a', ATMIOC_SARCOM+4, struct compat_atmif_sioc)
221
222static struct {
223 unsigned int cmd32;
224 unsigned int cmd;
225} atm_ioctl_map[] = {
226 { ATM_GETLINKRATE32, ATM_GETLINKRATE },
227 { ATM_GETNAMES32, ATM_GETNAMES },
228 { ATM_GETTYPE32, ATM_GETTYPE },
229 { ATM_GETESI32, ATM_GETESI },
230 { ATM_GETADDR32, ATM_GETADDR },
231 { ATM_RSTADDR32, ATM_RSTADDR },
232 { ATM_ADDADDR32, ATM_ADDADDR },
233 { ATM_DELADDR32, ATM_DELADDR },
234 { ATM_GETCIRANGE32, ATM_GETCIRANGE },
235 { ATM_SETCIRANGE32, ATM_SETCIRANGE },
236 { ATM_SETESI32, ATM_SETESI },
237 { ATM_SETESIF32, ATM_SETESIF },
238 { ATM_GETSTAT32, ATM_GETSTAT },
239 { ATM_GETSTATZ32, ATM_GETSTATZ },
240 { ATM_GETLOOP32, ATM_GETLOOP },
241 { ATM_SETLOOP32, ATM_SETLOOP },
242 { ATM_QUERYLOOP32, ATM_QUERYLOOP },
243};
244
245#define NR_ATM_IOCTL ARRAY_SIZE(atm_ioctl_map)
246
247static int do_atm_iobuf(struct socket *sock, unsigned int cmd,
248 unsigned long arg)
249{
250 struct atm_iobuf __user *iobuf;
251 struct compat_atm_iobuf __user *iobuf32;
252 u32 data;
253 void __user *datap;
254 int len, err;
255
256 iobuf = compat_alloc_user_space(sizeof(*iobuf));
257 iobuf32 = compat_ptr(arg);
258
259 if (get_user(len, &iobuf32->length) ||
260 get_user(data, &iobuf32->buffer))
261 return -EFAULT;
262 datap = compat_ptr(data);
263 if (put_user(len, &iobuf->length) ||
264 put_user(datap, &iobuf->buffer))
265 return -EFAULT;
266
267 err = do_vcc_ioctl(sock, cmd, (unsigned long) iobuf, 0);
268
269 if (!err) {
270 if (copy_in_user(&iobuf32->length, &iobuf->length,
271 sizeof(int)))
272 err = -EFAULT;
273 }
274
275 return err;
276}
277
278static int do_atmif_sioc(struct socket *sock, unsigned int cmd,
279 unsigned long arg)
280{
281 struct atmif_sioc __user *sioc;
282 struct compat_atmif_sioc __user *sioc32;
283 u32 data;
284 void __user *datap;
285 int err;
286
287 sioc = compat_alloc_user_space(sizeof(*sioc));
288 sioc32 = compat_ptr(arg);
289
290 if (copy_in_user(&sioc->number, &sioc32->number, 2 * sizeof(int)) ||
291 get_user(data, &sioc32->arg))
292 return -EFAULT;
293 datap = compat_ptr(data);
294 if (put_user(datap, &sioc->arg))
295 return -EFAULT;
296
297 err = do_vcc_ioctl(sock, cmd, (unsigned long) sioc, 0);
298
299 if (!err) {
300 if (copy_in_user(&sioc32->length, &sioc->length,
301 sizeof(int)))
302 err = -EFAULT;
303 }
304 return err;
305}
306
307static int do_atm_ioctl(struct socket *sock, unsigned int cmd32,
308 unsigned long arg)
195{ 309{
196 return do_vcc_ioctl(sock, cmd, arg, 1); 310 int i;
311 unsigned int cmd = 0;
312
313 switch (cmd32) {
314 case SONET_GETSTAT:
315 case SONET_GETSTATZ:
316 case SONET_GETDIAG:
317 case SONET_SETDIAG:
318 case SONET_CLRDIAG:
319 case SONET_SETFRAMING:
320 case SONET_GETFRAMING:
321 case SONET_GETFRSENSE:
322 return do_atmif_sioc(sock, cmd32, arg);
323 }
324
325 for (i = 0; i < NR_ATM_IOCTL; i++) {
326 if (cmd32 == atm_ioctl_map[i].cmd32) {
327 cmd = atm_ioctl_map[i].cmd;
328 break;
329 }
330 }
331 if (i == NR_ATM_IOCTL)
332 return -EINVAL;
333
334 switch (cmd) {
335 case ATM_GETNAMES:
336 return do_atm_iobuf(sock, cmd, arg);
337
338 case ATM_GETLINKRATE:
339 case ATM_GETTYPE:
340 case ATM_GETESI:
341 case ATM_GETADDR:
342 case ATM_RSTADDR:
343 case ATM_ADDADDR:
344 case ATM_DELADDR:
345 case ATM_GETCIRANGE:
346 case ATM_SETCIRANGE:
347 case ATM_SETESI:
348 case ATM_SETESIF:
349 case ATM_GETSTAT:
350 case ATM_GETSTATZ:
351 case ATM_GETLOOP:
352 case ATM_SETLOOP:
353 case ATM_QUERYLOOP:
354 return do_atmif_sioc(sock, cmd, arg);
355 }
356
357 return -EINVAL;
358}
359
360int vcc_compat_ioctl(struct socket *sock, unsigned int cmd,
361 unsigned long arg)
362{
363 int ret;
364
365 ret = do_vcc_ioctl(sock, cmd, arg, 1);
366 if (ret != -ENOIOCTLCMD)
367 return ret;
368
369 return do_atm_ioctl(sock, cmd, arg);
197} 370}
198#endif 371#endif
diff --git a/net/atm/lec.c b/net/atm/lec.c
index b2d644560323..feeaf5718472 100644
--- a/net/atm/lec.c
+++ b/net/atm/lec.c
@@ -4,6 +4,9 @@
4 * Marko Kiiskila <mkiiskila@yahoo.com> 4 * Marko Kiiskila <mkiiskila@yahoo.com>
5 */ 5 */
6 6
7#define pr_fmt(fmt) KBUILD_MODNAME ":%s: " fmt, __func__
8
9#include <linux/slab.h>
7#include <linux/kernel.h> 10#include <linux/kernel.h>
8#include <linux/bitops.h> 11#include <linux/bitops.h>
9#include <linux/capability.h> 12#include <linux/capability.h>
@@ -16,7 +19,7 @@
16#include <linux/skbuff.h> 19#include <linux/skbuff.h>
17#include <linux/ip.h> 20#include <linux/ip.h>
18#include <asm/byteorder.h> 21#include <asm/byteorder.h>
19#include <asm/uaccess.h> 22#include <linux/uaccess.h>
20#include <net/arp.h> 23#include <net/arp.h>
21#include <net/dst.h> 24#include <net/dst.h>
22#include <linux/proc_fs.h> 25#include <linux/proc_fs.h>
@@ -62,7 +65,6 @@ static int lec_open(struct net_device *dev);
62static netdev_tx_t lec_start_xmit(struct sk_buff *skb, 65static netdev_tx_t lec_start_xmit(struct sk_buff *skb,
63 struct net_device *dev); 66 struct net_device *dev);
64static int lec_close(struct net_device *dev); 67static int lec_close(struct net_device *dev);
65static void lec_init(struct net_device *dev);
66static struct lec_arp_table *lec_arp_find(struct lec_priv *priv, 68static struct lec_arp_table *lec_arp_find(struct lec_priv *priv,
67 const unsigned char *mac_addr); 69 const unsigned char *mac_addr);
68static int lec_arp_remove(struct lec_priv *priv, 70static int lec_arp_remove(struct lec_priv *priv,
@@ -86,17 +88,19 @@ static struct atm_vcc *lec_arp_resolve(struct lec_priv *priv,
86 int is_rdesc, 88 int is_rdesc,
87 struct lec_arp_table **ret_entry); 89 struct lec_arp_table **ret_entry);
88static void lec_arp_update(struct lec_priv *priv, const unsigned char *mac_addr, 90static void lec_arp_update(struct lec_priv *priv, const unsigned char *mac_addr,
89 const unsigned char *atm_addr, unsigned long remoteflag, 91 const unsigned char *atm_addr,
92 unsigned long remoteflag,
90 unsigned int targetless_le_arp); 93 unsigned int targetless_le_arp);
91static void lec_flush_complete(struct lec_priv *priv, unsigned long tran_id); 94static void lec_flush_complete(struct lec_priv *priv, unsigned long tran_id);
92static int lec_mcast_make(struct lec_priv *priv, struct atm_vcc *vcc); 95static int lec_mcast_make(struct lec_priv *priv, struct atm_vcc *vcc);
93static void lec_set_flush_tran_id(struct lec_priv *priv, 96static void lec_set_flush_tran_id(struct lec_priv *priv,
94 const unsigned char *atm_addr, 97 const unsigned char *atm_addr,
95 unsigned long tran_id); 98 unsigned long tran_id);
96static void lec_vcc_added(struct lec_priv *priv, const struct atmlec_ioc *ioc_data, 99static void lec_vcc_added(struct lec_priv *priv,
100 const struct atmlec_ioc *ioc_data,
97 struct atm_vcc *vcc, 101 struct atm_vcc *vcc,
98 void (*old_push) (struct atm_vcc *vcc, 102 void (*old_push)(struct atm_vcc *vcc,
99 struct sk_buff *skb)); 103 struct sk_buff *skb));
100static void lec_vcc_close(struct lec_priv *priv, struct atm_vcc *vcc); 104static void lec_vcc_close(struct lec_priv *priv, struct atm_vcc *vcc);
101 105
102/* must be done under lec_arp_lock */ 106/* must be done under lec_arp_lock */
@@ -111,7 +115,6 @@ static inline void lec_arp_put(struct lec_arp_table *entry)
111 kfree(entry); 115 kfree(entry);
112} 116}
113 117
114
115static struct lane2_ops lane2_ops = { 118static struct lane2_ops lane2_ops = {
116 lane2_resolve, /* resolve, spec 3.1.3 */ 119 lane2_resolve, /* resolve, spec 3.1.3 */
117 lane2_associate_req, /* associate_req, spec 3.1.4 */ 120 lane2_associate_req, /* associate_req, spec 3.1.4 */
@@ -149,7 +152,8 @@ static void lec_handle_bridge(struct sk_buff *skb, struct net_device *dev)
149 mesg = (struct atmlec_msg *)skb2->data; 152 mesg = (struct atmlec_msg *)skb2->data;
150 mesg->type = l_topology_change; 153 mesg->type = l_topology_change;
151 buff += 4; 154 buff += 4;
152 mesg->content.normal.flag = *buff & 0x01; /* 0x01 is topology change */ 155 mesg->content.normal.flag = *buff & 0x01;
156 /* 0x01 is topology change */
153 157
154 priv = netdev_priv(dev); 158 priv = netdev_priv(dev);
155 atm_force_charge(priv->lecd, skb2->truesize); 159 atm_force_charge(priv->lecd, skb2->truesize);
@@ -243,7 +247,7 @@ lec_send(struct atm_vcc *vcc, struct sk_buff *skb)
243 247
244static void lec_tx_timeout(struct net_device *dev) 248static void lec_tx_timeout(struct net_device *dev)
245{ 249{
246 printk(KERN_INFO "%s: tx timeout\n", dev->name); 250 pr_info("%s\n", dev->name);
247 dev->trans_start = jiffies; 251 dev->trans_start = jiffies;
248 netif_wake_queue(dev); 252 netif_wake_queue(dev);
249} 253}
@@ -262,14 +266,10 @@ static netdev_tx_t lec_start_xmit(struct sk_buff *skb,
262 unsigned char rdesc[ETH_ALEN]; /* Token Ring route descriptor */ 266 unsigned char rdesc[ETH_ALEN]; /* Token Ring route descriptor */
263#endif 267#endif
264 int is_rdesc; 268 int is_rdesc;
265#if DUMP_PACKETS > 0
266 char buf[300];
267 int i = 0;
268#endif /* DUMP_PACKETS >0 */
269 269
270 pr_debug("lec_start_xmit called\n"); 270 pr_debug("called\n");
271 if (!priv->lecd) { 271 if (!priv->lecd) {
272 printk("%s:No lecd attached\n", dev->name); 272 pr_info("%s:No lecd attached\n", dev->name);
273 dev->stats.tx_errors++; 273 dev->stats.tx_errors++;
274 netif_stop_queue(dev); 274 netif_stop_queue(dev);
275 kfree_skb(skb); 275 kfree_skb(skb);
@@ -277,8 +277,8 @@ static netdev_tx_t lec_start_xmit(struct sk_buff *skb,
277 } 277 }
278 278
279 pr_debug("skbuff head:%lx data:%lx tail:%lx end:%lx\n", 279 pr_debug("skbuff head:%lx data:%lx tail:%lx end:%lx\n",
280 (long)skb->head, (long)skb->data, (long)skb_tail_pointer(skb), 280 (long)skb->head, (long)skb->data, (long)skb_tail_pointer(skb),
281 (long)skb_end_pointer(skb)); 281 (long)skb_end_pointer(skb));
282#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE) 282#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
283 if (memcmp(skb->data, bridge_ula_lec, sizeof(bridge_ula_lec)) == 0) 283 if (memcmp(skb->data, bridge_ula_lec, sizeof(bridge_ula_lec)) == 0)
284 lec_handle_bridge(skb, dev); 284 lec_handle_bridge(skb, dev);
@@ -286,8 +286,7 @@ static netdev_tx_t lec_start_xmit(struct sk_buff *skb,
286 286
287 /* Make sure we have room for lec_id */ 287 /* Make sure we have room for lec_id */
288 if (skb_headroom(skb) < 2) { 288 if (skb_headroom(skb) < 2) {
289 289 pr_debug("reallocating skb\n");
290 pr_debug("lec_start_xmit: reallocating skb\n");
291 skb2 = skb_realloc_headroom(skb, LEC_HEADER_LEN); 290 skb2 = skb_realloc_headroom(skb, LEC_HEADER_LEN);
292 kfree_skb(skb); 291 kfree_skb(skb);
293 if (skb2 == NULL) 292 if (skb2 == NULL)
@@ -314,23 +313,17 @@ static netdev_tx_t lec_start_xmit(struct sk_buff *skb,
314 } 313 }
315#endif 314#endif
316 315
317#if DUMP_PACKETS > 0
318 printk("%s: send datalen:%ld lecid:%4.4x\n", dev->name,
319 skb->len, priv->lecid);
320#if DUMP_PACKETS >= 2 316#if DUMP_PACKETS >= 2
321 for (i = 0; i < skb->len && i < 99; i++) { 317#define MAX_DUMP_SKB 99
322 sprintf(buf + i * 3, "%2.2x ", 0xff & skb->data[i]);
323 }
324#elif DUMP_PACKETS >= 1 318#elif DUMP_PACKETS >= 1
325 for (i = 0; i < skb->len && i < 30; i++) { 319#define MAX_DUMP_SKB 30
326 sprintf(buf + i * 3, "%2.2x ", 0xff & skb->data[i]); 320#endif
327 } 321#if DUMP_PACKETS >= 1
322 printk(KERN_DEBUG "%s: send datalen:%ld lecid:%4.4x\n",
323 dev->name, skb->len, priv->lecid);
324 print_hex_dump(KERN_DEBUG, "", DUMP_OFFSET, 16, 1,
325 skb->data, min(skb->len, MAX_DUMP_SKB), true);
328#endif /* DUMP_PACKETS >= 1 */ 326#endif /* DUMP_PACKETS >= 1 */
329 if (i == skb->len)
330 printk("%s\n", buf);
331 else
332 printk("%s...\n", buf);
333#endif /* DUMP_PACKETS > 0 */
334 327
335 /* Minimum ethernet-frame size */ 328 /* Minimum ethernet-frame size */
336#ifdef CONFIG_TR 329#ifdef CONFIG_TR
@@ -368,31 +361,28 @@ static netdev_tx_t lec_start_xmit(struct sk_buff *skb,
368#endif 361#endif
369 entry = NULL; 362 entry = NULL;
370 vcc = lec_arp_resolve(priv, dst, is_rdesc, &entry); 363 vcc = lec_arp_resolve(priv, dst, is_rdesc, &entry);
371 pr_debug("%s:vcc:%p vcc_flags:%lx, entry:%p\n", dev->name, 364 pr_debug("%s:vcc:%p vcc_flags:%lx, entry:%p\n",
372 vcc, vcc ? vcc->flags : 0, entry); 365 dev->name, vcc, vcc ? vcc->flags : 0, entry);
373 if (!vcc || !test_bit(ATM_VF_READY, &vcc->flags)) { 366 if (!vcc || !test_bit(ATM_VF_READY, &vcc->flags)) {
374 if (entry && (entry->tx_wait.qlen < LEC_UNRES_QUE_LEN)) { 367 if (entry && (entry->tx_wait.qlen < LEC_UNRES_QUE_LEN)) {
375 pr_debug("%s:lec_start_xmit: queuing packet, ", 368 pr_debug("%s:queuing packet, MAC address %pM\n",
376 dev->name); 369 dev->name, lec_h->h_dest);
377 pr_debug("MAC address %pM\n", lec_h->h_dest);
378 skb_queue_tail(&entry->tx_wait, skb); 370 skb_queue_tail(&entry->tx_wait, skb);
379 } else { 371 } else {
380 pr_debug 372 pr_debug("%s:tx queue full or no arp entry, dropping, MAC address: %pM\n",
381 ("%s:lec_start_xmit: tx queue full or no arp entry, dropping, ", 373 dev->name, lec_h->h_dest);
382 dev->name);
383 pr_debug("MAC address %pM\n", lec_h->h_dest);
384 dev->stats.tx_dropped++; 374 dev->stats.tx_dropped++;
385 dev_kfree_skb(skb); 375 dev_kfree_skb(skb);
386 } 376 }
387 goto out; 377 goto out;
388 } 378 }
389#if DUMP_PACKETS > 0 379#if DUMP_PACKETS > 0
390 printk("%s:sending to vpi:%d vci:%d\n", dev->name, vcc->vpi, vcc->vci); 380 printk(KERN_DEBUG "%s:sending to vpi:%d vci:%d\n",
381 dev->name, vcc->vpi, vcc->vci);
391#endif /* DUMP_PACKETS > 0 */ 382#endif /* DUMP_PACKETS > 0 */
392 383
393 while (entry && (skb2 = skb_dequeue(&entry->tx_wait))) { 384 while (entry && (skb2 = skb_dequeue(&entry->tx_wait))) {
394 pr_debug("lec.c: emptying tx queue, "); 385 pr_debug("emptying tx queue, MAC address %pM\n", lec_h->h_dest);
395 pr_debug("MAC address %pM\n", lec_h->h_dest);
396 lec_send(vcc, skb2); 386 lec_send(vcc, skb2);
397 } 387 }
398 388
@@ -445,14 +435,12 @@ static int lec_atm_send(struct atm_vcc *vcc, struct sk_buff *skb)
445 pr_debug("%s: msg from zeppelin:%d\n", dev->name, mesg->type); 435 pr_debug("%s: msg from zeppelin:%d\n", dev->name, mesg->type);
446 switch (mesg->type) { 436 switch (mesg->type) {
447 case l_set_mac_addr: 437 case l_set_mac_addr:
448 for (i = 0; i < 6; i++) { 438 for (i = 0; i < 6; i++)
449 dev->dev_addr[i] = mesg->content.normal.mac_addr[i]; 439 dev->dev_addr[i] = mesg->content.normal.mac_addr[i];
450 }
451 break; 440 break;
452 case l_del_mac_addr: 441 case l_del_mac_addr:
453 for (i = 0; i < 6; i++) { 442 for (i = 0; i < 6; i++)
454 dev->dev_addr[i] = 0; 443 dev->dev_addr[i] = 0;
455 }
456 break; 444 break;
457 case l_addr_delete: 445 case l_addr_delete:
458 lec_addr_delete(priv, mesg->content.normal.atm_addr, 446 lec_addr_delete(priv, mesg->content.normal.atm_addr,
@@ -478,10 +466,10 @@ static int lec_atm_send(struct atm_vcc *vcc, struct sk_buff *skb)
478 mesg->content.normal.atm_addr, 466 mesg->content.normal.atm_addr,
479 mesg->content.normal.flag, 467 mesg->content.normal.flag,
480 mesg->content.normal.targetless_le_arp); 468 mesg->content.normal.targetless_le_arp);
481 pr_debug("lec: in l_arp_update\n"); 469 pr_debug("in l_arp_update\n");
482 if (mesg->sizeoftlvs != 0) { /* LANE2 3.1.5 */ 470 if (mesg->sizeoftlvs != 0) { /* LANE2 3.1.5 */
483 pr_debug("lec: LANE2 3.1.5, got tlvs, size %d\n", 471 pr_debug("LANE2 3.1.5, got tlvs, size %d\n",
484 mesg->sizeoftlvs); 472 mesg->sizeoftlvs);
485 lane2_associate_ind(dev, mesg->content.normal.mac_addr, 473 lane2_associate_ind(dev, mesg->content.normal.mac_addr,
486 tmp, mesg->sizeoftlvs); 474 tmp, mesg->sizeoftlvs);
487 } 475 }
@@ -500,13 +488,14 @@ static int lec_atm_send(struct atm_vcc *vcc, struct sk_buff *skb)
500 priv->flush_timeout = (mesg->content.config.flush_timeout * HZ); 488 priv->flush_timeout = (mesg->content.config.flush_timeout * HZ);
501 priv->path_switching_delay = 489 priv->path_switching_delay =
502 (mesg->content.config.path_switching_delay * HZ); 490 (mesg->content.config.path_switching_delay * HZ);
503 priv->lane_version = mesg->content.config.lane_version; /* LANE2 */ 491 priv->lane_version = mesg->content.config.lane_version;
492 /* LANE2 */
504 priv->lane2_ops = NULL; 493 priv->lane2_ops = NULL;
505 if (priv->lane_version > 1) 494 if (priv->lane_version > 1)
506 priv->lane2_ops = &lane2_ops; 495 priv->lane2_ops = &lane2_ops;
507 if (dev_set_mtu(dev, mesg->content.config.mtu)) 496 if (dev_set_mtu(dev, mesg->content.config.mtu))
508 printk("%s: change_mtu to %d failed\n", dev->name, 497 pr_info("%s: change_mtu to %d failed\n",
509 mesg->content.config.mtu); 498 dev->name, mesg->content.config.mtu);
510 priv->is_proxy = mesg->content.config.is_proxy; 499 priv->is_proxy = mesg->content.config.is_proxy;
511 break; 500 break;
512 case l_flush_tran_id: 501 case l_flush_tran_id:
@@ -519,40 +508,35 @@ static int lec_atm_send(struct atm_vcc *vcc, struct sk_buff *skb)
519 break; 508 break;
520 case l_should_bridge: 509 case l_should_bridge:
521#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE) 510#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
522 { 511 {
523 pr_debug("%s: bridge zeppelin asks about %pM\n", 512 pr_debug("%s: bridge zeppelin asks about %pM\n",
524 dev->name, mesg->content.proxy.mac_addr); 513 dev->name, mesg->content.proxy.mac_addr);
525 514
526 if (br_fdb_test_addr_hook == NULL) 515 if (br_fdb_test_addr_hook == NULL)
527 break; 516 break;
528 517
529 if (br_fdb_test_addr_hook(dev, 518 if (br_fdb_test_addr_hook(dev, mesg->content.proxy.mac_addr)) {
530 mesg->content.proxy.mac_addr)) { 519 /* hit from bridge table, send LE_ARP_RESPONSE */
531 /* hit from bridge table, send LE_ARP_RESPONSE */ 520 struct sk_buff *skb2;
532 struct sk_buff *skb2; 521 struct sock *sk;
533 struct sock *sk; 522
534 523 pr_debug("%s: entry found, responding to zeppelin\n",
535 pr_debug 524 dev->name);
536 ("%s: entry found, responding to zeppelin\n", 525 skb2 = alloc_skb(sizeof(struct atmlec_msg), GFP_ATOMIC);
537 dev->name); 526 if (skb2 == NULL)
538 skb2 = 527 break;
539 alloc_skb(sizeof(struct atmlec_msg), 528 skb2->len = sizeof(struct atmlec_msg);
540 GFP_ATOMIC); 529 skb_copy_to_linear_data(skb2, mesg, sizeof(*mesg));
541 if (skb2 == NULL) 530 atm_force_charge(priv->lecd, skb2->truesize);
542 break; 531 sk = sk_atm(priv->lecd);
543 skb2->len = sizeof(struct atmlec_msg); 532 skb_queue_tail(&sk->sk_receive_queue, skb2);
544 skb_copy_to_linear_data(skb2, mesg, 533 sk->sk_data_ready(sk, skb2->len);
545 sizeof(*mesg));
546 atm_force_charge(priv->lecd, skb2->truesize);
547 sk = sk_atm(priv->lecd);
548 skb_queue_tail(&sk->sk_receive_queue, skb2);
549 sk->sk_data_ready(sk, skb2->len);
550 }
551 } 534 }
535 }
552#endif /* defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE) */ 536#endif /* defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE) */
553 break; 537 break;
554 default: 538 default:
555 printk("%s: Unknown message type %d\n", dev->name, mesg->type); 539 pr_info("%s: Unknown message type %d\n", dev->name, mesg->type);
556 dev_kfree_skb(skb); 540 dev_kfree_skb(skb);
557 return -EINVAL; 541 return -EINVAL;
558 } 542 }
@@ -573,14 +557,13 @@ static void lec_atm_close(struct atm_vcc *vcc)
573 lec_arp_destroy(priv); 557 lec_arp_destroy(priv);
574 558
575 if (skb_peek(&sk_atm(vcc)->sk_receive_queue)) 559 if (skb_peek(&sk_atm(vcc)->sk_receive_queue))
576 printk("%s lec_atm_close: closing with messages pending\n", 560 pr_info("%s closing with messages pending\n", dev->name);
577 dev->name); 561 while ((skb = skb_dequeue(&sk_atm(vcc)->sk_receive_queue))) {
578 while ((skb = skb_dequeue(&sk_atm(vcc)->sk_receive_queue)) != NULL) {
579 atm_return(vcc, skb->truesize); 562 atm_return(vcc, skb->truesize);
580 dev_kfree_skb(skb); 563 dev_kfree_skb(skb);
581 } 564 }
582 565
583 printk("%s: Shut down!\n", dev->name); 566 pr_info("%s: Shut down!\n", dev->name);
584 module_put(THIS_MODULE); 567 module_put(THIS_MODULE);
585} 568}
586 569
@@ -609,9 +592,8 @@ send_to_lecd(struct lec_priv *priv, atmlec_msg_type type,
609 struct sk_buff *skb; 592 struct sk_buff *skb;
610 struct atmlec_msg *mesg; 593 struct atmlec_msg *mesg;
611 594
612 if (!priv || !priv->lecd) { 595 if (!priv || !priv->lecd)
613 return -1; 596 return -1;
614 }
615 skb = alloc_skb(sizeof(struct atmlec_msg), GFP_ATOMIC); 597 skb = alloc_skb(sizeof(struct atmlec_msg), GFP_ATOMIC);
616 if (!skb) 598 if (!skb)
617 return -1; 599 return -1;
@@ -634,7 +616,7 @@ send_to_lecd(struct lec_priv *priv, atmlec_msg_type type,
634 sk->sk_data_ready(sk, skb->len); 616 sk->sk_data_ready(sk, skb->len);
635 617
636 if (data != NULL) { 618 if (data != NULL) {
637 pr_debug("lec: about to send %d bytes of data\n", data->len); 619 pr_debug("about to send %d bytes of data\n", data->len);
638 atm_force_charge(priv->lecd, data->truesize); 620 atm_force_charge(priv->lecd, data->truesize);
639 skb_queue_tail(&sk->sk_receive_queue, data); 621 skb_queue_tail(&sk->sk_receive_queue, data);
640 sk->sk_data_ready(sk, skb->len); 622 sk->sk_data_ready(sk, skb->len);
@@ -670,13 +652,6 @@ static const struct net_device_ops lec_netdev_ops = {
670 .ndo_set_multicast_list = lec_set_multicast_list, 652 .ndo_set_multicast_list = lec_set_multicast_list,
671}; 653};
672 654
673
674static void lec_init(struct net_device *dev)
675{
676 dev->netdev_ops = &lec_netdev_ops;
677 printk("%s: Initialized!\n", dev->name);
678}
679
680static const unsigned char lec_ctrl_magic[] = { 655static const unsigned char lec_ctrl_magic[] = {
681 0xff, 656 0xff,
682 0x00, 657 0x00,
@@ -699,36 +674,28 @@ static void lec_push(struct atm_vcc *vcc, struct sk_buff *skb)
699 struct net_device *dev = (struct net_device *)vcc->proto_data; 674 struct net_device *dev = (struct net_device *)vcc->proto_data;
700 struct lec_priv *priv = netdev_priv(dev); 675 struct lec_priv *priv = netdev_priv(dev);
701 676
702#if DUMP_PACKETS >0 677#if DUMP_PACKETS > 0
703 int i = 0; 678 printk(KERN_DEBUG "%s: vcc vpi:%d vci:%d\n",
704 char buf[300]; 679 dev->name, vcc->vpi, vcc->vci);
705
706 printk("%s: lec_push vcc vpi:%d vci:%d\n", dev->name,
707 vcc->vpi, vcc->vci);
708#endif 680#endif
709 if (!skb) { 681 if (!skb) {
710 pr_debug("%s: null skb\n", dev->name); 682 pr_debug("%s: null skb\n", dev->name);
711 lec_vcc_close(priv, vcc); 683 lec_vcc_close(priv, vcc);
712 return; 684 return;
713 } 685 }
714#if DUMP_PACKETS > 0
715 printk("%s: rcv datalen:%ld lecid:%4.4x\n", dev->name,
716 skb->len, priv->lecid);
717#if DUMP_PACKETS >= 2 686#if DUMP_PACKETS >= 2
718 for (i = 0; i < skb->len && i < 99; i++) { 687#define MAX_SKB_DUMP 99
719 sprintf(buf + i * 3, "%2.2x ", 0xff & skb->data[i]);
720 }
721#elif DUMP_PACKETS >= 1 688#elif DUMP_PACKETS >= 1
722 for (i = 0; i < skb->len && i < 30; i++) { 689#define MAX_SKB_DUMP 30
723 sprintf(buf + i * 3, "%2.2x ", 0xff & skb->data[i]); 690#endif
724 } 691#if DUMP_PACKETS > 0
725#endif /* DUMP_PACKETS >= 1 */ 692 printk(KERN_DEBUG "%s: rcv datalen:%ld lecid:%4.4x\n",
726 if (i == skb->len) 693 dev->name, skb->len, priv->lecid);
727 printk("%s\n", buf); 694 print_hex_dump(KERN_DEBUG, "", DUMP_OFFSET, 16, 1,
728 else 695 skb->data, min(MAX_SKB_DUMP, skb->len), true);
729 printk("%s...\n", buf);
730#endif /* DUMP_PACKETS > 0 */ 696#endif /* DUMP_PACKETS > 0 */
731 if (memcmp(skb->data, lec_ctrl_magic, 4) == 0) { /* Control frame, to daemon */ 697 if (memcmp(skb->data, lec_ctrl_magic, 4) == 0) {
698 /* Control frame, to daemon */
732 struct sock *sk = sk_atm(vcc); 699 struct sock *sk = sk_atm(vcc);
733 700
734 pr_debug("%s: To daemon\n", dev->name); 701 pr_debug("%s: To daemon\n", dev->name);
@@ -786,9 +753,8 @@ static void lec_push(struct atm_vcc *vcc, struct sk_buff *skb)
786 dev_kfree_skb(skb); 753 dev_kfree_skb(skb);
787 return; 754 return;
788 } 755 }
789 if (!hlist_empty(&priv->lec_arp_empty_ones)) { 756 if (!hlist_empty(&priv->lec_arp_empty_ones))
790 lec_arp_check_empties(priv, vcc, skb); 757 lec_arp_check_empties(priv, vcc, skb);
791 }
792 skb_pull(skb, 2); /* skip lec_id */ 758 skb_pull(skb, 2); /* skip lec_id */
793#ifdef CONFIG_TR 759#ifdef CONFIG_TR
794 if (priv->is_trdev) 760 if (priv->is_trdev)
@@ -809,7 +775,7 @@ static void lec_pop(struct atm_vcc *vcc, struct sk_buff *skb)
809 struct net_device *dev = skb->dev; 775 struct net_device *dev = skb->dev;
810 776
811 if (vpriv == NULL) { 777 if (vpriv == NULL) {
812 printk("lec_pop(): vpriv = NULL!?!?!?\n"); 778 pr_info("vpriv = NULL!?!?!?\n");
813 return; 779 return;
814 } 780 }
815 781
@@ -830,15 +796,13 @@ static int lec_vcc_attach(struct atm_vcc *vcc, void __user *arg)
830 796
831 /* Lecd must be up in this case */ 797 /* Lecd must be up in this case */
832 bytes_left = copy_from_user(&ioc_data, arg, sizeof(struct atmlec_ioc)); 798 bytes_left = copy_from_user(&ioc_data, arg, sizeof(struct atmlec_ioc));
833 if (bytes_left != 0) { 799 if (bytes_left != 0)
834 printk 800 pr_info("copy from user failed for %d bytes\n", bytes_left);
835 ("lec: lec_vcc_attach, copy from user failed for %d bytes\n",
836 bytes_left);
837 }
838 if (ioc_data.dev_num < 0 || ioc_data.dev_num >= MAX_LEC_ITF || 801 if (ioc_data.dev_num < 0 || ioc_data.dev_num >= MAX_LEC_ITF ||
839 !dev_lec[ioc_data.dev_num]) 802 !dev_lec[ioc_data.dev_num])
840 return -EINVAL; 803 return -EINVAL;
841 if (!(vpriv = kmalloc(sizeof(struct lec_vcc_priv), GFP_KERNEL))) 804 vpriv = kmalloc(sizeof(struct lec_vcc_priv), GFP_KERNEL);
805 if (!vpriv)
842 return -ENOMEM; 806 return -ENOMEM;
843 vpriv->xoff = 0; 807 vpriv->xoff = 0;
844 vpriv->old_pop = vcc->pop; 808 vpriv->old_pop = vcc->pop;
@@ -893,6 +857,7 @@ static int lecd_attach(struct atm_vcc *vcc, int arg)
893 dev_lec[i] = alloc_etherdev(size); 857 dev_lec[i] = alloc_etherdev(size);
894 if (!dev_lec[i]) 858 if (!dev_lec[i])
895 return -ENOMEM; 859 return -ENOMEM;
860 dev_lec[i]->netdev_ops = &lec_netdev_ops;
896 snprintf(dev_lec[i]->name, IFNAMSIZ, "lec%d", i); 861 snprintf(dev_lec[i]->name, IFNAMSIZ, "lec%d", i);
897 if (register_netdev(dev_lec[i])) { 862 if (register_netdev(dev_lec[i])) {
898 free_netdev(dev_lec[i]); 863 free_netdev(dev_lec[i]);
@@ -901,7 +866,6 @@ static int lecd_attach(struct atm_vcc *vcc, int arg)
901 866
902 priv = netdev_priv(dev_lec[i]); 867 priv = netdev_priv(dev_lec[i]);
903 priv->is_trdev = is_trdev; 868 priv->is_trdev = is_trdev;
904 lec_init(dev_lec[i]);
905 } else { 869 } else {
906 priv = netdev_priv(dev_lec[i]); 870 priv = netdev_priv(dev_lec[i]);
907 if (priv->lecd) 871 if (priv->lecd)
@@ -929,9 +893,8 @@ static int lecd_attach(struct atm_vcc *vcc, int arg)
929 priv->flush_timeout = (4 * HZ); 893 priv->flush_timeout = (4 * HZ);
930 priv->path_switching_delay = (6 * HZ); 894 priv->path_switching_delay = (6 * HZ);
931 895
932 if (dev_lec[i]->flags & IFF_UP) { 896 if (dev_lec[i]->flags & IFF_UP)
933 netif_start_queue(dev_lec[i]); 897 netif_start_queue(dev_lec[i]);
934 }
935 __module_get(THIS_MODULE); 898 __module_get(THIS_MODULE);
936 return i; 899 return i;
937} 900}
@@ -1133,7 +1096,9 @@ static int lec_seq_show(struct seq_file *seq, void *v)
1133 else { 1096 else {
1134 struct lec_state *state = seq->private; 1097 struct lec_state *state = seq->private;
1135 struct net_device *dev = state->dev; 1098 struct net_device *dev = state->dev;
1136 struct lec_arp_table *entry = hlist_entry(state->node, struct lec_arp_table, next); 1099 struct lec_arp_table *entry = hlist_entry(state->node,
1100 struct lec_arp_table,
1101 next);
1137 1102
1138 seq_printf(seq, "%s ", dev->name); 1103 seq_printf(seq, "%s ", dev->name);
1139 lec_info(seq, entry); 1104 lec_info(seq, entry);
@@ -1207,13 +1172,13 @@ static int __init lane_module_init(void)
1207 1172
1208 p = proc_create("lec", S_IRUGO, atm_proc_root, &lec_seq_fops); 1173 p = proc_create("lec", S_IRUGO, atm_proc_root, &lec_seq_fops);
1209 if (!p) { 1174 if (!p) {
1210 printk(KERN_ERR "Unable to initialize /proc/net/atm/lec\n"); 1175 pr_err("Unable to initialize /proc/net/atm/lec\n");
1211 return -ENOMEM; 1176 return -ENOMEM;
1212 } 1177 }
1213#endif 1178#endif
1214 1179
1215 register_atm_ioctl(&lane_ioctl_ops); 1180 register_atm_ioctl(&lane_ioctl_ops);
1216 printk("lec.c: " __DATE__ " " __TIME__ " initialized\n"); 1181 pr_info("lec.c: " __DATE__ " " __TIME__ " initialized\n");
1217 return 0; 1182 return 0;
1218} 1183}
1219 1184
@@ -1302,13 +1267,13 @@ static int lane2_associate_req(struct net_device *dev, const u8 *lan_dst,
1302 struct lec_priv *priv = netdev_priv(dev); 1267 struct lec_priv *priv = netdev_priv(dev);
1303 1268
1304 if (compare_ether_addr(lan_dst, dev->dev_addr)) 1269 if (compare_ether_addr(lan_dst, dev->dev_addr))
1305 return (0); /* not our mac address */ 1270 return 0; /* not our mac address */
1306 1271
1307 kfree(priv->tlvs); /* NULL if there was no previous association */ 1272 kfree(priv->tlvs); /* NULL if there was no previous association */
1308 1273
1309 priv->tlvs = kmemdup(tlvs, sizeoftlvs, GFP_KERNEL); 1274 priv->tlvs = kmemdup(tlvs, sizeoftlvs, GFP_KERNEL);
1310 if (priv->tlvs == NULL) 1275 if (priv->tlvs == NULL)
1311 return (0); 1276 return 0;
1312 priv->sizeoftlvs = sizeoftlvs; 1277 priv->sizeoftlvs = sizeoftlvs;
1313 1278
1314 skb = alloc_skb(sizeoftlvs, GFP_ATOMIC); 1279 skb = alloc_skb(sizeoftlvs, GFP_ATOMIC);
@@ -1318,12 +1283,12 @@ static int lane2_associate_req(struct net_device *dev, const u8 *lan_dst,
1318 skb_copy_to_linear_data(skb, tlvs, sizeoftlvs); 1283 skb_copy_to_linear_data(skb, tlvs, sizeoftlvs);
1319 retval = send_to_lecd(priv, l_associate_req, NULL, NULL, skb); 1284 retval = send_to_lecd(priv, l_associate_req, NULL, NULL, skb);
1320 if (retval != 0) 1285 if (retval != 0)
1321 printk("lec.c: lane2_associate_req() failed\n"); 1286 pr_info("lec.c: lane2_associate_req() failed\n");
1322 /* 1287 /*
1323 * If the previous association has changed we must 1288 * If the previous association has changed we must
1324 * somehow notify other LANE entities about the change 1289 * somehow notify other LANE entities about the change
1325 */ 1290 */
1326 return (1); 1291 return 1;
1327} 1292}
1328 1293
1329/* 1294/*
@@ -1356,12 +1321,12 @@ static void lane2_associate_ind(struct net_device *dev, const u8 *mac_addr,
1356 entry->sizeoftlvs = sizeoftlvs; 1321 entry->sizeoftlvs = sizeoftlvs;
1357#endif 1322#endif
1358#if 0 1323#if 0
1359 printk("lec.c: lane2_associate_ind()\n"); 1324 pr_info("\n");
1360 printk("dump of tlvs, sizeoftlvs=%d\n", sizeoftlvs); 1325 pr_info("dump of tlvs, sizeoftlvs=%d\n", sizeoftlvs);
1361 while (i < sizeoftlvs) 1326 while (i < sizeoftlvs)
1362 printk("%02x ", tlvs[i++]); 1327 pr_cont("%02x ", tlvs[i++]);
1363 1328
1364 printk("\n"); 1329 pr_cont("\n");
1365#endif 1330#endif
1366 1331
1367 /* tell MPOA about the TLVs we saw */ 1332 /* tell MPOA about the TLVs we saw */
@@ -1381,15 +1346,15 @@ static void lane2_associate_ind(struct net_device *dev, const u8 *mac_addr,
1381 1346
1382#include <linux/types.h> 1347#include <linux/types.h>
1383#include <linux/timer.h> 1348#include <linux/timer.h>
1384#include <asm/param.h> 1349#include <linux/param.h>
1385#include <asm/atomic.h> 1350#include <asm/atomic.h>
1386#include <linux/inetdevice.h> 1351#include <linux/inetdevice.h>
1387#include <net/route.h> 1352#include <net/route.h>
1388 1353
1389#if 0 1354#if 0
1390#define pr_debug(format,args...) 1355#define pr_debug(format, args...)
1391/* 1356/*
1392#define pr_debug printk 1357 #define pr_debug printk
1393*/ 1358*/
1394#endif 1359#endif
1395#define DEBUG_ARP_TABLE 0 1360#define DEBUG_ARP_TABLE 0
@@ -1403,7 +1368,7 @@ static void lec_arp_expire_arp(unsigned long data);
1403 * Arp table funcs 1368 * Arp table funcs
1404 */ 1369 */
1405 1370
1406#define HASH(ch) (ch & (LEC_ARP_TABLE_SIZE -1)) 1371#define HASH(ch) (ch & (LEC_ARP_TABLE_SIZE - 1))
1407 1372
1408/* 1373/*
1409 * Initialization of arp-cache 1374 * Initialization of arp-cache
@@ -1412,9 +1377,8 @@ static void lec_arp_init(struct lec_priv *priv)
1412{ 1377{
1413 unsigned short i; 1378 unsigned short i;
1414 1379
1415 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) { 1380 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++)
1416 INIT_HLIST_HEAD(&priv->lec_arp_tables[i]); 1381 INIT_HLIST_HEAD(&priv->lec_arp_tables[i]);
1417 }
1418 INIT_HLIST_HEAD(&priv->lec_arp_empty_ones); 1382 INIT_HLIST_HEAD(&priv->lec_arp_empty_ones);
1419 INIT_HLIST_HEAD(&priv->lec_no_forward); 1383 INIT_HLIST_HEAD(&priv->lec_no_forward);
1420 INIT_HLIST_HEAD(&priv->mcast_fwds); 1384 INIT_HLIST_HEAD(&priv->mcast_fwds);
@@ -1458,10 +1422,7 @@ lec_arp_add(struct lec_priv *priv, struct lec_arp_table *entry)
1458 tmp = &priv->lec_arp_tables[HASH(entry->mac_addr[ETH_ALEN - 1])]; 1422 tmp = &priv->lec_arp_tables[HASH(entry->mac_addr[ETH_ALEN - 1])];
1459 hlist_add_head(&entry->next, tmp); 1423 hlist_add_head(&entry->next, tmp);
1460 1424
1461 pr_debug("LEC_ARP: Added entry:%2.2x %2.2x %2.2x %2.2x %2.2x %2.2x\n", 1425 pr_debug("Added entry:%pM\n", entry->mac_addr);
1462 0xff & entry->mac_addr[0], 0xff & entry->mac_addr[1],
1463 0xff & entry->mac_addr[2], 0xff & entry->mac_addr[3],
1464 0xff & entry->mac_addr[4], 0xff & entry->mac_addr[5]);
1465} 1426}
1466 1427
1467/* 1428/*
@@ -1474,20 +1435,23 @@ lec_arp_remove(struct lec_priv *priv, struct lec_arp_table *to_remove)
1474 struct lec_arp_table *entry; 1435 struct lec_arp_table *entry;
1475 int i, remove_vcc = 1; 1436 int i, remove_vcc = 1;
1476 1437
1477 if (!to_remove) { 1438 if (!to_remove)
1478 return -1; 1439 return -1;
1479 }
1480 1440
1481 hlist_del(&to_remove->next); 1441 hlist_del(&to_remove->next);
1482 del_timer(&to_remove->timer); 1442 del_timer(&to_remove->timer);
1483 1443
1484 /* If this is the only MAC connected to this VCC, also tear down the VCC */ 1444 /*
1445 * If this is the only MAC connected to this VCC,
1446 * also tear down the VCC
1447 */
1485 if (to_remove->status >= ESI_FLUSH_PENDING) { 1448 if (to_remove->status >= ESI_FLUSH_PENDING) {
1486 /* 1449 /*
1487 * ESI_FLUSH_PENDING, ESI_FORWARD_DIRECT 1450 * ESI_FLUSH_PENDING, ESI_FORWARD_DIRECT
1488 */ 1451 */
1489 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) { 1452 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
1490 hlist_for_each_entry(entry, node, &priv->lec_arp_tables[i], next) { 1453 hlist_for_each_entry(entry, node,
1454 &priv->lec_arp_tables[i], next) {
1491 if (memcmp(to_remove->atm_addr, 1455 if (memcmp(to_remove->atm_addr,
1492 entry->atm_addr, ATM_ESA_LEN) == 0) { 1456 entry->atm_addr, ATM_ESA_LEN) == 0) {
1493 remove_vcc = 0; 1457 remove_vcc = 0;
@@ -1500,10 +1464,7 @@ lec_arp_remove(struct lec_priv *priv, struct lec_arp_table *to_remove)
1500 } 1464 }
1501 skb_queue_purge(&to_remove->tx_wait); /* FIXME: good place for this? */ 1465 skb_queue_purge(&to_remove->tx_wait); /* FIXME: good place for this? */
1502 1466
1503 pr_debug("LEC_ARP: Removed entry:%2.2x %2.2x %2.2x %2.2x %2.2x %2.2x\n", 1467 pr_debug("Removed entry:%pM\n", to_remove->mac_addr);
1504 0xff & to_remove->mac_addr[0], 0xff & to_remove->mac_addr[1],
1505 0xff & to_remove->mac_addr[2], 0xff & to_remove->mac_addr[3],
1506 0xff & to_remove->mac_addr[4], 0xff & to_remove->mac_addr[5]);
1507 return 0; 1468 return 0;
1508} 1469}
1509 1470
@@ -1521,9 +1482,8 @@ static const char *get_status_string(unsigned char st)
1521 return "ESI_FLUSH_PENDING"; 1482 return "ESI_FLUSH_PENDING";
1522 case ESI_FORWARD_DIRECT: 1483 case ESI_FORWARD_DIRECT:
1523 return "ESI_FORWARD_DIRECT"; 1484 return "ESI_FORWARD_DIRECT";
1524 default:
1525 return "<UNKNOWN>";
1526 } 1485 }
1486 return "<UNKNOWN>";
1527} 1487}
1528 1488
1529static void dump_arp_table(struct lec_priv *priv) 1489static void dump_arp_table(struct lec_priv *priv)
@@ -1533,18 +1493,15 @@ static void dump_arp_table(struct lec_priv *priv)
1533 char buf[256]; 1493 char buf[256];
1534 int i, j, offset; 1494 int i, j, offset;
1535 1495
1536 printk("Dump %p:\n", priv); 1496 pr_info("Dump %p:\n", priv);
1537 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) { 1497 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
1538 hlist_for_each_entry(rulla, node, &priv->lec_arp_tables[i], next) { 1498 hlist_for_each_entry(rulla, node,
1499 &priv->lec_arp_tables[i], next) {
1539 offset = 0; 1500 offset = 0;
1540 offset += sprintf(buf, "%d: %p\n", i, rulla); 1501 offset += sprintf(buf, "%d: %p\n", i, rulla);
1541 offset += sprintf(buf + offset, "Mac:"); 1502 offset += sprintf(buf + offset, "Mac: %pM",
1542 for (j = 0; j < ETH_ALEN; j++) { 1503 rulla->mac_addr);
1543 offset += sprintf(buf + offset, 1504 offset += sprintf(buf + offset, " Atm:");
1544 "%2.2x ",
1545 rulla->mac_addr[j] & 0xff);
1546 }
1547 offset += sprintf(buf + offset, "Atm:");
1548 for (j = 0; j < ATM_ESA_LEN; j++) { 1505 for (j = 0; j < ATM_ESA_LEN; j++) {
1549 offset += sprintf(buf + offset, 1506 offset += sprintf(buf + offset,
1550 "%2.2x ", 1507 "%2.2x ",
@@ -1564,20 +1521,16 @@ static void dump_arp_table(struct lec_priv *priv)
1564 "Flags:%x, Packets_flooded:%x, Status: %s ", 1521 "Flags:%x, Packets_flooded:%x, Status: %s ",
1565 rulla->flags, rulla->packets_flooded, 1522 rulla->flags, rulla->packets_flooded,
1566 get_status_string(rulla->status)); 1523 get_status_string(rulla->status));
1567 printk("%s\n", buf); 1524 pr_info("%s\n", buf);
1568 } 1525 }
1569 } 1526 }
1570 1527
1571 if (!hlist_empty(&priv->lec_no_forward)) 1528 if (!hlist_empty(&priv->lec_no_forward))
1572 printk("No forward\n"); 1529 pr_info("No forward\n");
1573 hlist_for_each_entry(rulla, node, &priv->lec_no_forward, next) { 1530 hlist_for_each_entry(rulla, node, &priv->lec_no_forward, next) {
1574 offset = 0; 1531 offset = 0;
1575 offset += sprintf(buf + offset, "Mac:"); 1532 offset += sprintf(buf + offset, "Mac: %pM", rulla->mac_addr);
1576 for (j = 0; j < ETH_ALEN; j++) { 1533 offset += sprintf(buf + offset, " Atm:");
1577 offset += sprintf(buf + offset, "%2.2x ",
1578 rulla->mac_addr[j] & 0xff);
1579 }
1580 offset += sprintf(buf + offset, "Atm:");
1581 for (j = 0; j < ATM_ESA_LEN; j++) { 1534 for (j = 0; j < ATM_ESA_LEN; j++) {
1582 offset += sprintf(buf + offset, "%2.2x ", 1535 offset += sprintf(buf + offset, "%2.2x ",
1583 rulla->atm_addr[j] & 0xff); 1536 rulla->atm_addr[j] & 0xff);
@@ -1594,19 +1547,15 @@ static void dump_arp_table(struct lec_priv *priv)
1594 "Flags:%x, Packets_flooded:%x, Status: %s ", 1547 "Flags:%x, Packets_flooded:%x, Status: %s ",
1595 rulla->flags, rulla->packets_flooded, 1548 rulla->flags, rulla->packets_flooded,
1596 get_status_string(rulla->status)); 1549 get_status_string(rulla->status));
1597 printk("%s\n", buf); 1550 pr_info("%s\n", buf);
1598 } 1551 }
1599 1552
1600 if (!hlist_empty(&priv->lec_arp_empty_ones)) 1553 if (!hlist_empty(&priv->lec_arp_empty_ones))
1601 printk("Empty ones\n"); 1554 pr_info("Empty ones\n");
1602 hlist_for_each_entry(rulla, node, &priv->lec_arp_empty_ones, next) { 1555 hlist_for_each_entry(rulla, node, &priv->lec_arp_empty_ones, next) {
1603 offset = 0; 1556 offset = 0;
1604 offset += sprintf(buf + offset, "Mac:"); 1557 offset += sprintf(buf + offset, "Mac: %pM", rulla->mac_addr);
1605 for (j = 0; j < ETH_ALEN; j++) { 1558 offset += sprintf(buf + offset, " Atm:");
1606 offset += sprintf(buf + offset, "%2.2x ",
1607 rulla->mac_addr[j] & 0xff);
1608 }
1609 offset += sprintf(buf + offset, "Atm:");
1610 for (j = 0; j < ATM_ESA_LEN; j++) { 1559 for (j = 0; j < ATM_ESA_LEN; j++) {
1611 offset += sprintf(buf + offset, "%2.2x ", 1560 offset += sprintf(buf + offset, "%2.2x ",
1612 rulla->atm_addr[j] & 0xff); 1561 rulla->atm_addr[j] & 0xff);
@@ -1623,19 +1572,15 @@ static void dump_arp_table(struct lec_priv *priv)
1623 "Flags:%x, Packets_flooded:%x, Status: %s ", 1572 "Flags:%x, Packets_flooded:%x, Status: %s ",
1624 rulla->flags, rulla->packets_flooded, 1573 rulla->flags, rulla->packets_flooded,
1625 get_status_string(rulla->status)); 1574 get_status_string(rulla->status));
1626 printk("%s", buf); 1575 pr_info("%s", buf);
1627 } 1576 }
1628 1577
1629 if (!hlist_empty(&priv->mcast_fwds)) 1578 if (!hlist_empty(&priv->mcast_fwds))
1630 printk("Multicast Forward VCCs\n"); 1579 pr_info("Multicast Forward VCCs\n");
1631 hlist_for_each_entry(rulla, node, &priv->mcast_fwds, next) { 1580 hlist_for_each_entry(rulla, node, &priv->mcast_fwds, next) {
1632 offset = 0; 1581 offset = 0;
1633 offset += sprintf(buf + offset, "Mac:"); 1582 offset += sprintf(buf + offset, "Mac: %pM", rulla->mac_addr);
1634 for (j = 0; j < ETH_ALEN; j++) { 1583 offset += sprintf(buf + offset, " Atm:");
1635 offset += sprintf(buf + offset, "%2.2x ",
1636 rulla->mac_addr[j] & 0xff);
1637 }
1638 offset += sprintf(buf + offset, "Atm:");
1639 for (j = 0; j < ATM_ESA_LEN; j++) { 1584 for (j = 0; j < ATM_ESA_LEN; j++) {
1640 offset += sprintf(buf + offset, "%2.2x ", 1585 offset += sprintf(buf + offset, "%2.2x ",
1641 rulla->atm_addr[j] & 0xff); 1586 rulla->atm_addr[j] & 0xff);
@@ -1652,7 +1597,7 @@ static void dump_arp_table(struct lec_priv *priv)
1652 "Flags:%x, Packets_flooded:%x, Status: %s ", 1597 "Flags:%x, Packets_flooded:%x, Status: %s ",
1653 rulla->flags, rulla->packets_flooded, 1598 rulla->flags, rulla->packets_flooded,
1654 get_status_string(rulla->status)); 1599 get_status_string(rulla->status));
1655 printk("%s\n", buf); 1600 pr_info("%s\n", buf);
1656 } 1601 }
1657 1602
1658} 1603}
@@ -1678,14 +1623,16 @@ static void lec_arp_destroy(struct lec_priv *priv)
1678 1623
1679 spin_lock_irqsave(&priv->lec_arp_lock, flags); 1624 spin_lock_irqsave(&priv->lec_arp_lock, flags);
1680 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) { 1625 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
1681 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_tables[i], next) { 1626 hlist_for_each_entry_safe(entry, node, next,
1627 &priv->lec_arp_tables[i], next) {
1682 lec_arp_remove(priv, entry); 1628 lec_arp_remove(priv, entry);
1683 lec_arp_put(entry); 1629 lec_arp_put(entry);
1684 } 1630 }
1685 INIT_HLIST_HEAD(&priv->lec_arp_tables[i]); 1631 INIT_HLIST_HEAD(&priv->lec_arp_tables[i]);
1686 } 1632 }
1687 1633
1688 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_empty_ones, next) { 1634 hlist_for_each_entry_safe(entry, node, next,
1635 &priv->lec_arp_empty_ones, next) {
1689 del_timer_sync(&entry->timer); 1636 del_timer_sync(&entry->timer);
1690 lec_arp_clear_vccs(entry); 1637 lec_arp_clear_vccs(entry);
1691 hlist_del(&entry->next); 1638 hlist_del(&entry->next);
@@ -1693,7 +1640,8 @@ static void lec_arp_destroy(struct lec_priv *priv)
1693 } 1640 }
1694 INIT_HLIST_HEAD(&priv->lec_arp_empty_ones); 1641 INIT_HLIST_HEAD(&priv->lec_arp_empty_ones);
1695 1642
1696 hlist_for_each_entry_safe(entry, node, next, &priv->lec_no_forward, next) { 1643 hlist_for_each_entry_safe(entry, node, next,
1644 &priv->lec_no_forward, next) {
1697 del_timer_sync(&entry->timer); 1645 del_timer_sync(&entry->timer);
1698 lec_arp_clear_vccs(entry); 1646 lec_arp_clear_vccs(entry);
1699 hlist_del(&entry->next); 1647 hlist_del(&entry->next);
@@ -1722,15 +1670,12 @@ static struct lec_arp_table *lec_arp_find(struct lec_priv *priv,
1722 struct hlist_head *head; 1670 struct hlist_head *head;
1723 struct lec_arp_table *entry; 1671 struct lec_arp_table *entry;
1724 1672
1725 pr_debug("LEC_ARP: lec_arp_find :%2.2x %2.2x %2.2x %2.2x %2.2x %2.2x\n", 1673 pr_debug("%pM\n", mac_addr);
1726 mac_addr[0] & 0xff, mac_addr[1] & 0xff, mac_addr[2] & 0xff,
1727 mac_addr[3] & 0xff, mac_addr[4] & 0xff, mac_addr[5] & 0xff);
1728 1674
1729 head = &priv->lec_arp_tables[HASH(mac_addr[ETH_ALEN - 1])]; 1675 head = &priv->lec_arp_tables[HASH(mac_addr[ETH_ALEN - 1])];
1730 hlist_for_each_entry(entry, node, head, next) { 1676 hlist_for_each_entry(entry, node, head, next) {
1731 if (!compare_ether_addr(mac_addr, entry->mac_addr)) { 1677 if (!compare_ether_addr(mac_addr, entry->mac_addr))
1732 return entry; 1678 return entry;
1733 }
1734 } 1679 }
1735 return NULL; 1680 return NULL;
1736} 1681}
@@ -1742,7 +1687,7 @@ static struct lec_arp_table *make_entry(struct lec_priv *priv,
1742 1687
1743 to_return = kzalloc(sizeof(struct lec_arp_table), GFP_ATOMIC); 1688 to_return = kzalloc(sizeof(struct lec_arp_table), GFP_ATOMIC);
1744 if (!to_return) { 1689 if (!to_return) {
1745 printk("LEC: Arp entry kmalloc failed\n"); 1690 pr_info("LEC: Arp entry kmalloc failed\n");
1746 return NULL; 1691 return NULL;
1747 } 1692 }
1748 memcpy(to_return->mac_addr, mac_addr, ETH_ALEN); 1693 memcpy(to_return->mac_addr, mac_addr, ETH_ALEN);
@@ -1763,7 +1708,7 @@ static void lec_arp_expire_arp(unsigned long data)
1763 1708
1764 entry = (struct lec_arp_table *)data; 1709 entry = (struct lec_arp_table *)data;
1765 1710
1766 pr_debug("lec_arp_expire_arp\n"); 1711 pr_debug("\n");
1767 if (entry->status == ESI_ARP_PENDING) { 1712 if (entry->status == ESI_ARP_PENDING) {
1768 if (entry->no_tries <= entry->priv->max_retry_count) { 1713 if (entry->no_tries <= entry->priv->max_retry_count) {
1769 if (entry->is_rdesc) 1714 if (entry->is_rdesc)
@@ -1787,10 +1732,10 @@ static void lec_arp_expire_vcc(unsigned long data)
1787 1732
1788 del_timer(&to_remove->timer); 1733 del_timer(&to_remove->timer);
1789 1734
1790 pr_debug("LEC_ARP %p %p: lec_arp_expire_vcc vpi:%d vci:%d\n", 1735 pr_debug("%p %p: vpi:%d vci:%d\n",
1791 to_remove, priv, 1736 to_remove, priv,
1792 to_remove->vcc ? to_remove->recv_vcc->vpi : 0, 1737 to_remove->vcc ? to_remove->recv_vcc->vpi : 0,
1793 to_remove->vcc ? to_remove->recv_vcc->vci : 0); 1738 to_remove->vcc ? to_remove->recv_vcc->vci : 0);
1794 1739
1795 spin_lock_irqsave(&priv->lec_arp_lock, flags); 1740 spin_lock_irqsave(&priv->lec_arp_lock, flags);
1796 hlist_del(&to_remove->next); 1741 hlist_del(&to_remove->next);
@@ -1800,6 +1745,50 @@ static void lec_arp_expire_vcc(unsigned long data)
1800 lec_arp_put(to_remove); 1745 lec_arp_put(to_remove);
1801} 1746}
1802 1747
1748static bool __lec_arp_check_expire(struct lec_arp_table *entry,
1749 unsigned long now,
1750 struct lec_priv *priv)
1751{
1752 unsigned long time_to_check;
1753
1754 if ((entry->flags) & LEC_REMOTE_FLAG && priv->topology_change)
1755 time_to_check = priv->forward_delay_time;
1756 else
1757 time_to_check = priv->aging_time;
1758
1759 pr_debug("About to expire: %lx - %lx > %lx\n",
1760 now, entry->last_used, time_to_check);
1761 if (time_after(now, entry->last_used + time_to_check) &&
1762 !(entry->flags & LEC_PERMANENT_FLAG) &&
1763 !(entry->mac_addr[0] & 0x01)) { /* LANE2: 7.1.20 */
1764 /* Remove entry */
1765 pr_debug("Entry timed out\n");
1766 lec_arp_remove(priv, entry);
1767 lec_arp_put(entry);
1768 } else {
1769 /* Something else */
1770 if ((entry->status == ESI_VC_PENDING ||
1771 entry->status == ESI_ARP_PENDING) &&
1772 time_after_eq(now, entry->timestamp +
1773 priv->max_unknown_frame_time)) {
1774 entry->timestamp = jiffies;
1775 entry->packets_flooded = 0;
1776 if (entry->status == ESI_VC_PENDING)
1777 send_to_lecd(priv, l_svc_setup,
1778 entry->mac_addr,
1779 entry->atm_addr,
1780 NULL);
1781 }
1782 if (entry->status == ESI_FLUSH_PENDING &&
1783 time_after_eq(now, entry->timestamp +
1784 priv->path_switching_delay)) {
1785 lec_arp_hold(entry);
1786 return true;
1787 }
1788 }
1789
1790 return false;
1791}
1803/* 1792/*
1804 * Expire entries. 1793 * Expire entries.
1805 * 1. Re-set timer 1794 * 1. Re-set timer
@@ -1824,62 +1813,28 @@ static void lec_arp_check_expire(struct work_struct *work)
1824 struct hlist_node *node, *next; 1813 struct hlist_node *node, *next;
1825 struct lec_arp_table *entry; 1814 struct lec_arp_table *entry;
1826 unsigned long now; 1815 unsigned long now;
1827 unsigned long time_to_check;
1828 int i; 1816 int i;
1829 1817
1830 pr_debug("lec_arp_check_expire %p\n", priv); 1818 pr_debug("%p\n", priv);
1831 now = jiffies; 1819 now = jiffies;
1832restart: 1820restart:
1833 spin_lock_irqsave(&priv->lec_arp_lock, flags); 1821 spin_lock_irqsave(&priv->lec_arp_lock, flags);
1834 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) { 1822 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
1835 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_tables[i], next) { 1823 hlist_for_each_entry_safe(entry, node, next,
1836 if ((entry->flags) & LEC_REMOTE_FLAG && 1824 &priv->lec_arp_tables[i], next) {
1837 priv->topology_change) 1825 if (__lec_arp_check_expire(entry, now, priv)) {
1838 time_to_check = priv->forward_delay_time; 1826 struct sk_buff *skb;
1839 else 1827 struct atm_vcc *vcc = entry->vcc;
1840 time_to_check = priv->aging_time; 1828
1841 1829 spin_unlock_irqrestore(&priv->lec_arp_lock,
1842 pr_debug("About to expire: %lx - %lx > %lx\n", 1830 flags);
1843 now, entry->last_used, time_to_check); 1831 while ((skb = skb_dequeue(&entry->tx_wait)))
1844 if (time_after(now, entry->last_used + time_to_check) 1832 lec_send(vcc, skb);
1845 && !(entry->flags & LEC_PERMANENT_FLAG) 1833 entry->last_used = jiffies;
1846 && !(entry->mac_addr[0] & 0x01)) { /* LANE2: 7.1.20 */ 1834 entry->status = ESI_FORWARD_DIRECT;
1847 /* Remove entry */
1848 pr_debug("LEC:Entry timed out\n");
1849 lec_arp_remove(priv, entry);
1850 lec_arp_put(entry); 1835 lec_arp_put(entry);
1851 } else { 1836
1852 /* Something else */ 1837 goto restart;
1853 if ((entry->status == ESI_VC_PENDING ||
1854 entry->status == ESI_ARP_PENDING)
1855 && time_after_eq(now,
1856 entry->timestamp +
1857 priv->
1858 max_unknown_frame_time)) {
1859 entry->timestamp = jiffies;
1860 entry->packets_flooded = 0;
1861 if (entry->status == ESI_VC_PENDING)
1862 send_to_lecd(priv, l_svc_setup,
1863 entry->mac_addr,
1864 entry->atm_addr,
1865 NULL);
1866 }
1867 if (entry->status == ESI_FLUSH_PENDING
1868 &&
1869 time_after_eq(now, entry->timestamp +
1870 priv->path_switching_delay)) {
1871 struct sk_buff *skb;
1872 struct atm_vcc *vcc = entry->vcc;
1873
1874 lec_arp_hold(entry);
1875 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1876 while ((skb = skb_dequeue(&entry->tx_wait)) != NULL)
1877 lec_send(vcc, skb);
1878 entry->last_used = jiffies;
1879 entry->status = ESI_FORWARD_DIRECT;
1880 lec_arp_put(entry);
1881 goto restart;
1882 }
1883 } 1838 }
1884 } 1839 }
1885 } 1840 }
@@ -1893,7 +1848,8 @@ restart:
1893 * 1848 *
1894 */ 1849 */
1895static struct atm_vcc *lec_arp_resolve(struct lec_priv *priv, 1850static struct atm_vcc *lec_arp_resolve(struct lec_priv *priv,
1896 const unsigned char *mac_to_find, int is_rdesc, 1851 const unsigned char *mac_to_find,
1852 int is_rdesc,
1897 struct lec_arp_table **ret_entry) 1853 struct lec_arp_table **ret_entry)
1898{ 1854{
1899 unsigned long flags; 1855 unsigned long flags;
@@ -1929,9 +1885,8 @@ static struct atm_vcc *lec_arp_resolve(struct lec_priv *priv,
1929 * If the LE_ARP cache entry is still pending, reset count to 0 1885 * If the LE_ARP cache entry is still pending, reset count to 0
1930 * so another LE_ARP request can be made for this frame. 1886 * so another LE_ARP request can be made for this frame.
1931 */ 1887 */
1932 if (entry->status == ESI_ARP_PENDING) { 1888 if (entry->status == ESI_ARP_PENDING)
1933 entry->no_tries = 0; 1889 entry->no_tries = 0;
1934 }
1935 /* 1890 /*
1936 * Data direct VC not yet set up, check to see if the unknown 1891 * Data direct VC not yet set up, check to see if the unknown
1937 * frame count is greater than the limit. If the limit has 1892 * frame count is greater than the limit. If the limit has
@@ -1942,7 +1897,7 @@ static struct atm_vcc *lec_arp_resolve(struct lec_priv *priv,
1942 entry->packets_flooded < 1897 entry->packets_flooded <
1943 priv->maximum_unknown_frame_count) { 1898 priv->maximum_unknown_frame_count) {
1944 entry->packets_flooded++; 1899 entry->packets_flooded++;
1945 pr_debug("LEC_ARP: Flooding..\n"); 1900 pr_debug("Flooding..\n");
1946 found = priv->mcast_vcc; 1901 found = priv->mcast_vcc;
1947 goto out; 1902 goto out;
1948 } 1903 }
@@ -1953,13 +1908,13 @@ static struct atm_vcc *lec_arp_resolve(struct lec_priv *priv,
1953 */ 1908 */
1954 lec_arp_hold(entry); 1909 lec_arp_hold(entry);
1955 *ret_entry = entry; 1910 *ret_entry = entry;
1956 pr_debug("lec: entry->status %d entry->vcc %p\n", entry->status, 1911 pr_debug("entry->status %d entry->vcc %p\n", entry->status,
1957 entry->vcc); 1912 entry->vcc);
1958 found = NULL; 1913 found = NULL;
1959 } else { 1914 } else {
1960 /* No matching entry was found */ 1915 /* No matching entry was found */
1961 entry = make_entry(priv, mac_to_find); 1916 entry = make_entry(priv, mac_to_find);
1962 pr_debug("LEC_ARP: Making entry\n"); 1917 pr_debug("Making entry\n");
1963 if (!entry) { 1918 if (!entry) {
1964 found = priv->mcast_vcc; 1919 found = priv->mcast_vcc;
1965 goto out; 1920 goto out;
@@ -1996,13 +1951,14 @@ lec_addr_delete(struct lec_priv *priv, const unsigned char *atm_addr,
1996 struct lec_arp_table *entry; 1951 struct lec_arp_table *entry;
1997 int i; 1952 int i;
1998 1953
1999 pr_debug("lec_addr_delete\n"); 1954 pr_debug("\n");
2000 spin_lock_irqsave(&priv->lec_arp_lock, flags); 1955 spin_lock_irqsave(&priv->lec_arp_lock, flags);
2001 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) { 1956 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
2002 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_tables[i], next) { 1957 hlist_for_each_entry_safe(entry, node, next,
2003 if (!memcmp(atm_addr, entry->atm_addr, ATM_ESA_LEN) 1958 &priv->lec_arp_tables[i], next) {
2004 && (permanent || 1959 if (!memcmp(atm_addr, entry->atm_addr, ATM_ESA_LEN) &&
2005 !(entry->flags & LEC_PERMANENT_FLAG))) { 1960 (permanent ||
1961 !(entry->flags & LEC_PERMANENT_FLAG))) {
2006 lec_arp_remove(priv, entry); 1962 lec_arp_remove(priv, entry);
2007 lec_arp_put(entry); 1963 lec_arp_put(entry);
2008 } 1964 }
@@ -2027,10 +1983,8 @@ lec_arp_update(struct lec_priv *priv, const unsigned char *mac_addr,
2027 struct lec_arp_table *entry, *tmp; 1983 struct lec_arp_table *entry, *tmp;
2028 int i; 1984 int i;
2029 1985
2030 pr_debug("lec:%s", (targetless_le_arp) ? "targetless " : " "); 1986 pr_debug("%smac:%pM\n",
2031 pr_debug("lec_arp_update mac:%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x\n", 1987 (targetless_le_arp) ? "targetless " : "", mac_addr);
2032 mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3],
2033 mac_addr[4], mac_addr[5]);
2034 1988
2035 spin_lock_irqsave(&priv->lec_arp_lock, flags); 1989 spin_lock_irqsave(&priv->lec_arp_lock, flags);
2036 entry = lec_arp_find(priv, mac_addr); 1990 entry = lec_arp_find(priv, mac_addr);
@@ -2040,7 +1994,8 @@ lec_arp_update(struct lec_priv *priv, const unsigned char *mac_addr,
2040 * we have no entry in the cache. 7.1.30 1994 * we have no entry in the cache. 7.1.30
2041 */ 1995 */
2042 if (!hlist_empty(&priv->lec_arp_empty_ones)) { 1996 if (!hlist_empty(&priv->lec_arp_empty_ones)) {
2043 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_empty_ones, next) { 1997 hlist_for_each_entry_safe(entry, node, next,
1998 &priv->lec_arp_empty_ones, next) {
2044 if (memcmp(entry->atm_addr, atm_addr, ATM_ESA_LEN) == 0) { 1999 if (memcmp(entry->atm_addr, atm_addr, ATM_ESA_LEN) == 0) {
2045 hlist_del(&entry->next); 2000 hlist_del(&entry->next);
2046 del_timer(&entry->timer); 2001 del_timer(&entry->timer);
@@ -2084,7 +2039,8 @@ lec_arp_update(struct lec_priv *priv, const unsigned char *mac_addr,
2084 memcpy(entry->atm_addr, atm_addr, ATM_ESA_LEN); 2039 memcpy(entry->atm_addr, atm_addr, ATM_ESA_LEN);
2085 del_timer(&entry->timer); 2040 del_timer(&entry->timer);
2086 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) { 2041 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
2087 hlist_for_each_entry(tmp, node, &priv->lec_arp_tables[i], next) { 2042 hlist_for_each_entry(tmp, node,
2043 &priv->lec_arp_tables[i], next) {
2088 if (entry != tmp && 2044 if (entry != tmp &&
2089 !memcmp(tmp->atm_addr, atm_addr, ATM_ESA_LEN)) { 2045 !memcmp(tmp->atm_addr, atm_addr, ATM_ESA_LEN)) {
2090 /* Vcc to this host exists */ 2046 /* Vcc to this host exists */
@@ -2129,14 +2085,13 @@ lec_vcc_added(struct lec_priv *priv, const struct atmlec_ioc *ioc_data,
2129 int i, found_entry = 0; 2085 int i, found_entry = 0;
2130 2086
2131 spin_lock_irqsave(&priv->lec_arp_lock, flags); 2087 spin_lock_irqsave(&priv->lec_arp_lock, flags);
2088 /* Vcc for Multicast Forward. No timer, LANEv2 7.1.20 and 2.3.5.3 */
2132 if (ioc_data->receive == 2) { 2089 if (ioc_data->receive == 2) {
2133 /* Vcc for Multicast Forward. No timer, LANEv2 7.1.20 and 2.3.5.3 */
2134
2135 pr_debug("LEC_ARP: Attaching mcast forward\n"); 2090 pr_debug("LEC_ARP: Attaching mcast forward\n");
2136#if 0 2091#if 0
2137 entry = lec_arp_find(priv, bus_mac); 2092 entry = lec_arp_find(priv, bus_mac);
2138 if (!entry) { 2093 if (!entry) {
2139 printk("LEC_ARP: Multicast entry not found!\n"); 2094 pr_info("LEC_ARP: Multicast entry not found!\n");
2140 goto out; 2095 goto out;
2141 } 2096 }
2142 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN); 2097 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
@@ -2157,19 +2112,17 @@ lec_vcc_added(struct lec_priv *priv, const struct atmlec_ioc *ioc_data,
2157 * Vcc which we don't want to make default vcc, 2112 * Vcc which we don't want to make default vcc,
2158 * attach it anyway. 2113 * attach it anyway.
2159 */ 2114 */
2160 pr_debug 2115 pr_debug("LEC_ARP:Attaching data direct, not default: %2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x\n",
2161 ("LEC_ARP:Attaching data direct, not default: " 2116 ioc_data->atm_addr[0], ioc_data->atm_addr[1],
2162 "%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x\n", 2117 ioc_data->atm_addr[2], ioc_data->atm_addr[3],
2163 ioc_data->atm_addr[0], ioc_data->atm_addr[1], 2118 ioc_data->atm_addr[4], ioc_data->atm_addr[5],
2164 ioc_data->atm_addr[2], ioc_data->atm_addr[3], 2119 ioc_data->atm_addr[6], ioc_data->atm_addr[7],
2165 ioc_data->atm_addr[4], ioc_data->atm_addr[5], 2120 ioc_data->atm_addr[8], ioc_data->atm_addr[9],
2166 ioc_data->atm_addr[6], ioc_data->atm_addr[7], 2121 ioc_data->atm_addr[10], ioc_data->atm_addr[11],
2167 ioc_data->atm_addr[8], ioc_data->atm_addr[9], 2122 ioc_data->atm_addr[12], ioc_data->atm_addr[13],
2168 ioc_data->atm_addr[10], ioc_data->atm_addr[11], 2123 ioc_data->atm_addr[14], ioc_data->atm_addr[15],
2169 ioc_data->atm_addr[12], ioc_data->atm_addr[13], 2124 ioc_data->atm_addr[16], ioc_data->atm_addr[17],
2170 ioc_data->atm_addr[14], ioc_data->atm_addr[15], 2125 ioc_data->atm_addr[18], ioc_data->atm_addr[19]);
2171 ioc_data->atm_addr[16], ioc_data->atm_addr[17],
2172 ioc_data->atm_addr[18], ioc_data->atm_addr[19]);
2173 entry = make_entry(priv, bus_mac); 2126 entry = make_entry(priv, bus_mac);
2174 if (entry == NULL) 2127 if (entry == NULL)
2175 goto out; 2128 goto out;
@@ -2185,29 +2138,28 @@ lec_vcc_added(struct lec_priv *priv, const struct atmlec_ioc *ioc_data,
2185 dump_arp_table(priv); 2138 dump_arp_table(priv);
2186 goto out; 2139 goto out;
2187 } 2140 }
2188 pr_debug 2141 pr_debug("LEC_ARP:Attaching data direct, default: %2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x\n",
2189 ("LEC_ARP:Attaching data direct, default: " 2142 ioc_data->atm_addr[0], ioc_data->atm_addr[1],
2190 "%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x\n", 2143 ioc_data->atm_addr[2], ioc_data->atm_addr[3],
2191 ioc_data->atm_addr[0], ioc_data->atm_addr[1], 2144 ioc_data->atm_addr[4], ioc_data->atm_addr[5],
2192 ioc_data->atm_addr[2], ioc_data->atm_addr[3], 2145 ioc_data->atm_addr[6], ioc_data->atm_addr[7],
2193 ioc_data->atm_addr[4], ioc_data->atm_addr[5], 2146 ioc_data->atm_addr[8], ioc_data->atm_addr[9],
2194 ioc_data->atm_addr[6], ioc_data->atm_addr[7], 2147 ioc_data->atm_addr[10], ioc_data->atm_addr[11],
2195 ioc_data->atm_addr[8], ioc_data->atm_addr[9], 2148 ioc_data->atm_addr[12], ioc_data->atm_addr[13],
2196 ioc_data->atm_addr[10], ioc_data->atm_addr[11], 2149 ioc_data->atm_addr[14], ioc_data->atm_addr[15],
2197 ioc_data->atm_addr[12], ioc_data->atm_addr[13], 2150 ioc_data->atm_addr[16], ioc_data->atm_addr[17],
2198 ioc_data->atm_addr[14], ioc_data->atm_addr[15], 2151 ioc_data->atm_addr[18], ioc_data->atm_addr[19]);
2199 ioc_data->atm_addr[16], ioc_data->atm_addr[17],
2200 ioc_data->atm_addr[18], ioc_data->atm_addr[19]);
2201 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) { 2152 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
2202 hlist_for_each_entry(entry, node, &priv->lec_arp_tables[i], next) { 2153 hlist_for_each_entry(entry, node,
2154 &priv->lec_arp_tables[i], next) {
2203 if (memcmp 2155 if (memcmp
2204 (ioc_data->atm_addr, entry->atm_addr, 2156 (ioc_data->atm_addr, entry->atm_addr,
2205 ATM_ESA_LEN) == 0) { 2157 ATM_ESA_LEN) == 0) {
2206 pr_debug("LEC_ARP: Attaching data direct\n"); 2158 pr_debug("LEC_ARP: Attaching data direct\n");
2207 pr_debug("Currently -> Vcc: %d, Rvcc:%d\n", 2159 pr_debug("Currently -> Vcc: %d, Rvcc:%d\n",
2208 entry->vcc ? entry->vcc->vci : 0, 2160 entry->vcc ? entry->vcc->vci : 0,
2209 entry->recv_vcc ? entry->recv_vcc-> 2161 entry->recv_vcc ? entry->recv_vcc->
2210 vci : 0); 2162 vci : 0);
2211 found_entry = 1; 2163 found_entry = 1;
2212 del_timer(&entry->timer); 2164 del_timer(&entry->timer);
2213 entry->vcc = vcc; 2165 entry->vcc = vcc;
@@ -2279,19 +2231,21 @@ static void lec_flush_complete(struct lec_priv *priv, unsigned long tran_id)
2279 struct lec_arp_table *entry; 2231 struct lec_arp_table *entry;
2280 int i; 2232 int i;
2281 2233
2282 pr_debug("LEC:lec_flush_complete %lx\n", tran_id); 2234 pr_debug("%lx\n", tran_id);
2283restart: 2235restart:
2284 spin_lock_irqsave(&priv->lec_arp_lock, flags); 2236 spin_lock_irqsave(&priv->lec_arp_lock, flags);
2285 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) { 2237 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
2286 hlist_for_each_entry(entry, node, &priv->lec_arp_tables[i], next) { 2238 hlist_for_each_entry(entry, node,
2287 if (entry->flush_tran_id == tran_id 2239 &priv->lec_arp_tables[i], next) {
2288 && entry->status == ESI_FLUSH_PENDING) { 2240 if (entry->flush_tran_id == tran_id &&
2241 entry->status == ESI_FLUSH_PENDING) {
2289 struct sk_buff *skb; 2242 struct sk_buff *skb;
2290 struct atm_vcc *vcc = entry->vcc; 2243 struct atm_vcc *vcc = entry->vcc;
2291 2244
2292 lec_arp_hold(entry); 2245 lec_arp_hold(entry);
2293 spin_unlock_irqrestore(&priv->lec_arp_lock, flags); 2246 spin_unlock_irqrestore(&priv->lec_arp_lock,
2294 while ((skb = skb_dequeue(&entry->tx_wait)) != NULL) 2247 flags);
2248 while ((skb = skb_dequeue(&entry->tx_wait)))
2295 lec_send(vcc, skb); 2249 lec_send(vcc, skb);
2296 entry->last_used = jiffies; 2250 entry->last_used = jiffies;
2297 entry->status = ESI_FORWARD_DIRECT; 2251 entry->status = ESI_FORWARD_DIRECT;
@@ -2316,11 +2270,12 @@ lec_set_flush_tran_id(struct lec_priv *priv,
2316 2270
2317 spin_lock_irqsave(&priv->lec_arp_lock, flags); 2271 spin_lock_irqsave(&priv->lec_arp_lock, flags);
2318 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) 2272 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++)
2319 hlist_for_each_entry(entry, node, &priv->lec_arp_tables[i], next) { 2273 hlist_for_each_entry(entry, node,
2274 &priv->lec_arp_tables[i], next) {
2320 if (!memcmp(atm_addr, entry->atm_addr, ATM_ESA_LEN)) { 2275 if (!memcmp(atm_addr, entry->atm_addr, ATM_ESA_LEN)) {
2321 entry->flush_tran_id = tran_id; 2276 entry->flush_tran_id = tran_id;
2322 pr_debug("Set flush transaction id to %lx for %p\n", 2277 pr_debug("Set flush transaction id to %lx for %p\n",
2323 tran_id, entry); 2278 tran_id, entry);
2324 } 2279 }
2325 } 2280 }
2326 spin_unlock_irqrestore(&priv->lec_arp_lock, flags); 2281 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
@@ -2336,7 +2291,8 @@ static int lec_mcast_make(struct lec_priv *priv, struct atm_vcc *vcc)
2336 struct lec_vcc_priv *vpriv; 2291 struct lec_vcc_priv *vpriv;
2337 int err = 0; 2292 int err = 0;
2338 2293
2339 if (!(vpriv = kmalloc(sizeof(struct lec_vcc_priv), GFP_KERNEL))) 2294 vpriv = kmalloc(sizeof(struct lec_vcc_priv), GFP_KERNEL);
2295 if (!vpriv)
2340 return -ENOMEM; 2296 return -ENOMEM;
2341 vpriv->xoff = 0; 2297 vpriv->xoff = 0;
2342 vpriv->old_pop = vcc->pop; 2298 vpriv->old_pop = vcc->pop;
@@ -2376,18 +2332,19 @@ static void lec_vcc_close(struct lec_priv *priv, struct atm_vcc *vcc)
2376 spin_lock_irqsave(&priv->lec_arp_lock, flags); 2332 spin_lock_irqsave(&priv->lec_arp_lock, flags);
2377 2333
2378 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) { 2334 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
2379 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_tables[i], next) { 2335 hlist_for_each_entry_safe(entry, node, next,
2336 &priv->lec_arp_tables[i], next) {
2380 if (vcc == entry->vcc) { 2337 if (vcc == entry->vcc) {
2381 lec_arp_remove(priv, entry); 2338 lec_arp_remove(priv, entry);
2382 lec_arp_put(entry); 2339 lec_arp_put(entry);
2383 if (priv->mcast_vcc == vcc) { 2340 if (priv->mcast_vcc == vcc)
2384 priv->mcast_vcc = NULL; 2341 priv->mcast_vcc = NULL;
2385 }
2386 } 2342 }
2387 } 2343 }
2388 } 2344 }
2389 2345
2390 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_empty_ones, next) { 2346 hlist_for_each_entry_safe(entry, node, next,
2347 &priv->lec_arp_empty_ones, next) {
2391 if (entry->vcc == vcc) { 2348 if (entry->vcc == vcc) {
2392 lec_arp_clear_vccs(entry); 2349 lec_arp_clear_vccs(entry);
2393 del_timer(&entry->timer); 2350 del_timer(&entry->timer);
@@ -2396,7 +2353,8 @@ static void lec_vcc_close(struct lec_priv *priv, struct atm_vcc *vcc)
2396 } 2353 }
2397 } 2354 }
2398 2355
2399 hlist_for_each_entry_safe(entry, node, next, &priv->lec_no_forward, next) { 2356 hlist_for_each_entry_safe(entry, node, next,
2357 &priv->lec_no_forward, next) {
2400 if (entry->recv_vcc == vcc) { 2358 if (entry->recv_vcc == vcc) {
2401 lec_arp_clear_vccs(entry); 2359 lec_arp_clear_vccs(entry);
2402 del_timer(&entry->timer); 2360 del_timer(&entry->timer);
@@ -2437,14 +2395,16 @@ lec_arp_check_empties(struct lec_priv *priv,
2437 src = hdr->h_source; 2395 src = hdr->h_source;
2438 2396
2439 spin_lock_irqsave(&priv->lec_arp_lock, flags); 2397 spin_lock_irqsave(&priv->lec_arp_lock, flags);
2440 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_empty_ones, next) { 2398 hlist_for_each_entry_safe(entry, node, next,
2399 &priv->lec_arp_empty_ones, next) {
2441 if (vcc == entry->vcc) { 2400 if (vcc == entry->vcc) {
2442 del_timer(&entry->timer); 2401 del_timer(&entry->timer);
2443 memcpy(entry->mac_addr, src, ETH_ALEN); 2402 memcpy(entry->mac_addr, src, ETH_ALEN);
2444 entry->status = ESI_FORWARD_DIRECT; 2403 entry->status = ESI_FORWARD_DIRECT;
2445 entry->last_used = jiffies; 2404 entry->last_used = jiffies;
2446 /* We might have got an entry */ 2405 /* We might have got an entry */
2447 if ((tmp = lec_arp_find(priv, src))) { 2406 tmp = lec_arp_find(priv, src);
2407 if (tmp) {
2448 lec_arp_remove(priv, tmp); 2408 lec_arp_remove(priv, tmp);
2449 lec_arp_put(tmp); 2409 lec_arp_put(tmp);
2450 } 2410 }
diff --git a/net/atm/mpc.c b/net/atm/mpc.c
index 38a6cb0863f0..436f2e177657 100644
--- a/net/atm/mpc.c
+++ b/net/atm/mpc.c
@@ -1,5 +1,8 @@
1#define pr_fmt(fmt) KBUILD_MODNAME ":%s: " fmt, __func__
2
1#include <linux/kernel.h> 3#include <linux/kernel.h>
2#include <linux/string.h> 4#include <linux/string.h>
5#include <linux/slab.h>
3#include <linux/timer.h> 6#include <linux/timer.h>
4#include <linux/init.h> 7#include <linux/init.h>
5#include <linux/bitops.h> 8#include <linux/bitops.h>
@@ -13,8 +16,8 @@
13#include <net/sock.h> 16#include <net/sock.h>
14#include <linux/skbuff.h> 17#include <linux/skbuff.h>
15#include <linux/ip.h> 18#include <linux/ip.h>
19#include <linux/uaccess.h>
16#include <asm/byteorder.h> 20#include <asm/byteorder.h>
17#include <asm/uaccess.h>
18#include <net/checksum.h> /* for ip_fast_csum() */ 21#include <net/checksum.h> /* for ip_fast_csum() */
19#include <net/arp.h> 22#include <net/arp.h>
20#include <net/dst.h> 23#include <net/dst.h>
@@ -36,31 +39,47 @@
36 */ 39 */
37 40
38#if 0 41#if 0
39#define dprintk printk /* debug */ 42#define dprintk(format, args...) \
43 printk(KERN_DEBUG "mpoa:%s: " format, __func__, ##args)
44#define dprintk_cont(format, args...) printk(KERN_CONT format, ##args)
40#else 45#else
41#define dprintk(format,args...) 46#define dprintk(format, args...) \
47 do { if (0) \
48 printk(KERN_DEBUG "mpoa:%s: " format, __func__, ##args);\
49 } while (0)
50#define dprintk_cont(format, args...) \
51 do { if (0) printk(KERN_CONT format, ##args); } while (0)
42#endif 52#endif
43 53
44#if 0 54#if 0
45#define ddprintk printk /* more debug */ 55#define ddprintk(format, args...) \
56 printk(KERN_DEBUG "mpoa:%s: " format, __func__, ##args)
57#define ddprintk_cont(format, args...) printk(KERN_CONT format, ##args)
46#else 58#else
47#define ddprintk(format,args...) 59#define ddprintk(format, args...) \
60 do { if (0) \
61 printk(KERN_DEBUG "mpoa:%s: " format, __func__, ##args);\
62 } while (0)
63#define ddprintk_cont(format, args...) \
64 do { if (0) printk(KERN_CONT format, ##args); } while (0)
48#endif 65#endif
49 66
50
51
52#define MPOA_TAG_LEN 4 67#define MPOA_TAG_LEN 4
53 68
54/* mpc_daemon -> kernel */ 69/* mpc_daemon -> kernel */
55static void MPOA_trigger_rcvd (struct k_message *msg, struct mpoa_client *mpc); 70static void MPOA_trigger_rcvd(struct k_message *msg, struct mpoa_client *mpc);
56static void MPOA_res_reply_rcvd(struct k_message *msg, struct mpoa_client *mpc); 71static void MPOA_res_reply_rcvd(struct k_message *msg, struct mpoa_client *mpc);
57static void ingress_purge_rcvd(struct k_message *msg, struct mpoa_client *mpc); 72static void ingress_purge_rcvd(struct k_message *msg, struct mpoa_client *mpc);
58static void egress_purge_rcvd(struct k_message *msg, struct mpoa_client *mpc); 73static void egress_purge_rcvd(struct k_message *msg, struct mpoa_client *mpc);
59static void mps_death(struct k_message *msg, struct mpoa_client *mpc); 74static void mps_death(struct k_message *msg, struct mpoa_client *mpc);
60static void clean_up(struct k_message *msg, struct mpoa_client *mpc, int action); 75static void clean_up(struct k_message *msg, struct mpoa_client *mpc,
61static void MPOA_cache_impos_rcvd(struct k_message *msg, struct mpoa_client *mpc); 76 int action);
62static void set_mpc_ctrl_addr_rcvd(struct k_message *mesg, struct mpoa_client *mpc); 77static void MPOA_cache_impos_rcvd(struct k_message *msg,
63static void set_mps_mac_addr_rcvd(struct k_message *mesg, struct mpoa_client *mpc); 78 struct mpoa_client *mpc);
79static void set_mpc_ctrl_addr_rcvd(struct k_message *mesg,
80 struct mpoa_client *mpc);
81static void set_mps_mac_addr_rcvd(struct k_message *mesg,
82 struct mpoa_client *mpc);
64 83
65static const uint8_t *copy_macs(struct mpoa_client *mpc, 84static const uint8_t *copy_macs(struct mpoa_client *mpc,
66 const uint8_t *router_mac, 85 const uint8_t *router_mac,
@@ -74,10 +93,11 @@ static int msg_from_mpoad(struct atm_vcc *vcc, struct sk_buff *skb);
74 93
75static void mpc_push(struct atm_vcc *vcc, struct sk_buff *skb); 94static void mpc_push(struct atm_vcc *vcc, struct sk_buff *skb);
76static netdev_tx_t mpc_send_packet(struct sk_buff *skb, 95static netdev_tx_t mpc_send_packet(struct sk_buff *skb,
77 struct net_device *dev); 96 struct net_device *dev);
78static int mpoa_event_listener(struct notifier_block *mpoa_notifier, unsigned long event, void *dev); 97static int mpoa_event_listener(struct notifier_block *mpoa_notifier,
98 unsigned long event, void *dev);
79static void mpc_timer_refresh(void); 99static void mpc_timer_refresh(void);
80static void mpc_cache_check( unsigned long checking_time ); 100static void mpc_cache_check(unsigned long checking_time);
81 101
82static struct llc_snap_hdr llc_snap_mpoa_ctrl = { 102static struct llc_snap_hdr llc_snap_mpoa_ctrl = {
83 0xaa, 0xaa, 0x03, 103 0xaa, 0xaa, 0x03,
@@ -167,7 +187,7 @@ struct atm_mpoa_qos *atm_mpoa_add_qos(__be32 dst_ip, struct atm_qos *qos)
167 187
168 entry = kmalloc(sizeof(struct atm_mpoa_qos), GFP_KERNEL); 188 entry = kmalloc(sizeof(struct atm_mpoa_qos), GFP_KERNEL);
169 if (entry == NULL) { 189 if (entry == NULL) {
170 printk("mpoa: atm_mpoa_add_qos: out of memory\n"); 190 pr_info("mpoa: out of memory\n");
171 return entry; 191 return entry;
172 } 192 }
173 193
@@ -185,10 +205,9 @@ struct atm_mpoa_qos *atm_mpoa_search_qos(__be32 dst_ip)
185 struct atm_mpoa_qos *qos; 205 struct atm_mpoa_qos *qos;
186 206
187 qos = qos_head; 207 qos = qos_head;
188 while( qos != NULL ){ 208 while (qos) {
189 if(qos->ipaddr == dst_ip) { 209 if (qos->ipaddr == dst_ip)
190 break; 210 break;
191 }
192 qos = qos->next; 211 qos = qos->next;
193 } 212 }
194 213
@@ -200,10 +219,10 @@ struct atm_mpoa_qos *atm_mpoa_search_qos(__be32 dst_ip)
200 */ 219 */
201int atm_mpoa_delete_qos(struct atm_mpoa_qos *entry) 220int atm_mpoa_delete_qos(struct atm_mpoa_qos *entry)
202{ 221{
203
204 struct atm_mpoa_qos *curr; 222 struct atm_mpoa_qos *curr;
205 223
206 if (entry == NULL) return 0; 224 if (entry == NULL)
225 return 0;
207 if (entry == qos_head) { 226 if (entry == qos_head) {
208 qos_head = qos_head->next; 227 qos_head = qos_head->next;
209 kfree(entry); 228 kfree(entry);
@@ -234,9 +253,17 @@ void atm_mpoa_disp_qos(struct seq_file *m)
234 253
235 while (qos != NULL) { 254 while (qos != NULL) {
236 seq_printf(m, "%pI4\n %-7d %-7d %-7d %-7d %-7d\n %-7d %-7d %-7d %-7d %-7d\n", 255 seq_printf(m, "%pI4\n %-7d %-7d %-7d %-7d %-7d\n %-7d %-7d %-7d %-7d %-7d\n",
237 &qos->ipaddr, 256 &qos->ipaddr,
238 qos->qos.txtp.max_pcr, qos->qos.txtp.pcr, qos->qos.txtp.min_pcr, qos->qos.txtp.max_cdv, qos->qos.txtp.max_sdu, 257 qos->qos.txtp.max_pcr,
239 qos->qos.rxtp.max_pcr, qos->qos.rxtp.pcr, qos->qos.rxtp.min_pcr, qos->qos.rxtp.max_cdv, qos->qos.rxtp.max_sdu); 258 qos->qos.txtp.pcr,
259 qos->qos.txtp.min_pcr,
260 qos->qos.txtp.max_cdv,
261 qos->qos.txtp.max_sdu,
262 qos->qos.rxtp.max_pcr,
263 qos->qos.rxtp.pcr,
264 qos->qos.rxtp.min_pcr,
265 qos->qos.rxtp.max_cdv,
266 qos->qos.rxtp.max_sdu);
240 qos = qos->next; 267 qos = qos->next;
241 } 268 }
242} 269}
@@ -256,7 +283,7 @@ static struct mpoa_client *alloc_mpc(void)
256{ 283{
257 struct mpoa_client *mpc; 284 struct mpoa_client *mpc;
258 285
259 mpc = kzalloc(sizeof (struct mpoa_client), GFP_KERNEL); 286 mpc = kzalloc(sizeof(struct mpoa_client), GFP_KERNEL);
260 if (mpc == NULL) 287 if (mpc == NULL)
261 return NULL; 288 return NULL;
262 rwlock_init(&mpc->ingress_lock); 289 rwlock_init(&mpc->ingress_lock);
@@ -266,7 +293,7 @@ static struct mpoa_client *alloc_mpc(void)
266 293
267 mpc->parameters.mpc_p1 = MPC_P1; 294 mpc->parameters.mpc_p1 = MPC_P1;
268 mpc->parameters.mpc_p2 = MPC_P2; 295 mpc->parameters.mpc_p2 = MPC_P2;
269 memset(mpc->parameters.mpc_p3,0,sizeof(mpc->parameters.mpc_p3)); 296 memset(mpc->parameters.mpc_p3, 0, sizeof(mpc->parameters.mpc_p3));
270 mpc->parameters.mpc_p4 = MPC_P4; 297 mpc->parameters.mpc_p4 = MPC_P4;
271 mpc->parameters.mpc_p5 = MPC_P5; 298 mpc->parameters.mpc_p5 = MPC_P5;
272 mpc->parameters.mpc_p6 = MPC_P6; 299 mpc->parameters.mpc_p6 = MPC_P6;
@@ -286,9 +313,9 @@ static struct mpoa_client *alloc_mpc(void)
286static void start_mpc(struct mpoa_client *mpc, struct net_device *dev) 313static void start_mpc(struct mpoa_client *mpc, struct net_device *dev)
287{ 314{
288 315
289 dprintk("mpoa: (%s) start_mpc:\n", mpc->dev->name); 316 dprintk("(%s)\n", mpc->dev->name);
290 if (!dev->netdev_ops) 317 if (!dev->netdev_ops)
291 printk("mpoa: (%s) start_mpc not starting\n", dev->name); 318 pr_info("(%s) not starting\n", dev->name);
292 else { 319 else {
293 mpc->old_ops = dev->netdev_ops; 320 mpc->old_ops = dev->netdev_ops;
294 mpc->new_ops = *mpc->old_ops; 321 mpc->new_ops = *mpc->old_ops;
@@ -300,14 +327,14 @@ static void start_mpc(struct mpoa_client *mpc, struct net_device *dev)
300static void stop_mpc(struct mpoa_client *mpc) 327static void stop_mpc(struct mpoa_client *mpc)
301{ 328{
302 struct net_device *dev = mpc->dev; 329 struct net_device *dev = mpc->dev;
303 dprintk("mpoa: (%s) stop_mpc:", mpc->dev->name); 330 dprintk("(%s)", mpc->dev->name);
304 331
305 /* Lets not nullify lec device's dev->hard_start_xmit */ 332 /* Lets not nullify lec device's dev->hard_start_xmit */
306 if (dev->netdev_ops != &mpc->new_ops) { 333 if (dev->netdev_ops != &mpc->new_ops) {
307 dprintk(" mpc already stopped, not fatal\n"); 334 dprintk_cont(" mpc already stopped, not fatal\n");
308 return; 335 return;
309 } 336 }
310 dprintk("\n"); 337 dprintk_cont("\n");
311 338
312 dev->netdev_ops = mpc->old_ops; 339 dev->netdev_ops = mpc->old_ops;
313 mpc->old_ops = NULL; 340 mpc->old_ops = NULL;
@@ -319,25 +346,18 @@ static const char *mpoa_device_type_string(char type) __attribute__ ((unused));
319 346
320static const char *mpoa_device_type_string(char type) 347static const char *mpoa_device_type_string(char type)
321{ 348{
322 switch(type) { 349 switch (type) {
323 case NON_MPOA: 350 case NON_MPOA:
324 return "non-MPOA device"; 351 return "non-MPOA device";
325 break;
326 case MPS: 352 case MPS:
327 return "MPS"; 353 return "MPS";
328 break;
329 case MPC: 354 case MPC:
330 return "MPC"; 355 return "MPC";
331 break;
332 case MPS_AND_MPC: 356 case MPS_AND_MPC:
333 return "both MPS and MPC"; 357 return "both MPS and MPC";
334 break;
335 default:
336 return "unspecified (non-MPOA) device";
337 break;
338 } 358 }
339 359
340 return ""; /* not reached */ 360 return "unspecified (non-MPOA) device";
341} 361}
342 362
343/* 363/*
@@ -362,26 +382,28 @@ static void lane2_assoc_ind(struct net_device *dev, const u8 *mac_addr,
362 struct mpoa_client *mpc; 382 struct mpoa_client *mpc;
363 383
364 mpoa_device_type = number_of_mps_macs = 0; /* silence gcc */ 384 mpoa_device_type = number_of_mps_macs = 0; /* silence gcc */
365 dprintk("mpoa: (%s) lane2_assoc_ind: received TLV(s), ", dev->name); 385 dprintk("(%s) received TLV(s), ", dev->name);
366 dprintk("total length of all TLVs %d\n", sizeoftlvs); 386 dprintk("total length of all TLVs %d\n", sizeoftlvs);
367 mpc = find_mpc_by_lec(dev); /* Sampo-Fix: moved here from below */ 387 mpc = find_mpc_by_lec(dev); /* Sampo-Fix: moved here from below */
368 if (mpc == NULL) { 388 if (mpc == NULL) {
369 printk("mpoa: (%s) lane2_assoc_ind: no mpc\n", dev->name); 389 pr_info("(%s) no mpc\n", dev->name);
370 return; 390 return;
371 } 391 }
372 end_of_tlvs = tlvs + sizeoftlvs; 392 end_of_tlvs = tlvs + sizeoftlvs;
373 while (end_of_tlvs - tlvs >= 5) { 393 while (end_of_tlvs - tlvs >= 5) {
374 type = (tlvs[0] << 24) | (tlvs[1] << 16) | (tlvs[2] << 8) | tlvs[3]; 394 type = ((tlvs[0] << 24) | (tlvs[1] << 16) |
395 (tlvs[2] << 8) | tlvs[3]);
375 length = tlvs[4]; 396 length = tlvs[4];
376 tlvs += 5; 397 tlvs += 5;
377 dprintk(" type 0x%x length %02x\n", type, length); 398 dprintk(" type 0x%x length %02x\n", type, length);
378 if (tlvs + length > end_of_tlvs) { 399 if (tlvs + length > end_of_tlvs) {
379 printk("TLV value extends past its buffer, aborting parse\n"); 400 pr_info("TLV value extends past its buffer, aborting parse\n");
380 return; 401 return;
381 } 402 }
382 403
383 if (type == 0) { 404 if (type == 0) {
384 printk("mpoa: (%s) lane2_assoc_ind: TLV type was 0, returning\n", dev->name); 405 pr_info("mpoa: (%s) TLV type was 0, returning\n",
406 dev->name);
385 return; 407 return;
386 } 408 }
387 409
@@ -391,39 +413,48 @@ static void lane2_assoc_ind(struct net_device *dev, const u8 *mac_addr,
391 } 413 }
392 mpoa_device_type = *tlvs++; 414 mpoa_device_type = *tlvs++;
393 number_of_mps_macs = *tlvs++; 415 number_of_mps_macs = *tlvs++;
394 dprintk("mpoa: (%s) MPOA device type '%s', ", dev->name, mpoa_device_type_string(mpoa_device_type)); 416 dprintk("(%s) MPOA device type '%s', ",
417 dev->name, mpoa_device_type_string(mpoa_device_type));
395 if (mpoa_device_type == MPS_AND_MPC && 418 if (mpoa_device_type == MPS_AND_MPC &&
396 length < (42 + number_of_mps_macs*ETH_ALEN)) { /* :) */ 419 length < (42 + number_of_mps_macs*ETH_ALEN)) { /* :) */
397 printk("\nmpoa: (%s) lane2_assoc_ind: short MPOA Device Type TLV\n", 420 pr_info("(%s) short MPOA Device Type TLV\n",
398 dev->name); 421 dev->name);
399 continue; 422 continue;
400 } 423 }
401 if ((mpoa_device_type == MPS || mpoa_device_type == MPC) 424 if ((mpoa_device_type == MPS || mpoa_device_type == MPC) &&
402 && length < 22 + number_of_mps_macs*ETH_ALEN) { 425 length < 22 + number_of_mps_macs*ETH_ALEN) {
403 printk("\nmpoa: (%s) lane2_assoc_ind: short MPOA Device Type TLV\n", 426 pr_info("(%s) short MPOA Device Type TLV\n", dev->name);
404 dev->name);
405 continue; 427 continue;
406 } 428 }
407 if (mpoa_device_type != MPS && mpoa_device_type != MPS_AND_MPC) { 429 if (mpoa_device_type != MPS &&
408 dprintk("ignoring non-MPS device\n"); 430 mpoa_device_type != MPS_AND_MPC) {
409 if (mpoa_device_type == MPC) tlvs += 20; 431 dprintk("ignoring non-MPS device ");
432 if (mpoa_device_type == MPC)
433 tlvs += 20;
410 continue; /* we are only interested in MPSs */ 434 continue; /* we are only interested in MPSs */
411 } 435 }
412 if (number_of_mps_macs == 0 && mpoa_device_type == MPS_AND_MPC) { 436 if (number_of_mps_macs == 0 &&
413 printk("\nmpoa: (%s) lane2_assoc_ind: MPS_AND_MPC has zero MACs\n", dev->name); 437 mpoa_device_type == MPS_AND_MPC) {
438 pr_info("(%s) MPS_AND_MPC has zero MACs\n", dev->name);
414 continue; /* someone should read the spec */ 439 continue; /* someone should read the spec */
415 } 440 }
416 dprintk("this MPS has %d MAC addresses\n", number_of_mps_macs); 441 dprintk_cont("this MPS has %d MAC addresses\n",
442 number_of_mps_macs);
417 443
418 /* ok, now we can go and tell our daemon the control address of MPS */ 444 /*
445 * ok, now we can go and tell our daemon
446 * the control address of MPS
447 */
419 send_set_mps_ctrl_addr(tlvs, mpc); 448 send_set_mps_ctrl_addr(tlvs, mpc);
420 449
421 tlvs = copy_macs(mpc, mac_addr, tlvs, number_of_mps_macs, mpoa_device_type); 450 tlvs = copy_macs(mpc, mac_addr, tlvs,
422 if (tlvs == NULL) return; 451 number_of_mps_macs, mpoa_device_type);
452 if (tlvs == NULL)
453 return;
423 } 454 }
424 if (end_of_tlvs - tlvs != 0) 455 if (end_of_tlvs - tlvs != 0)
425 printk("mpoa: (%s) lane2_assoc_ind: ignoring %Zd bytes of trailing TLV carbage\n", 456 pr_info("(%s) ignoring %Zd bytes of trailing TLV garbage\n",
426 dev->name, end_of_tlvs - tlvs); 457 dev->name, end_of_tlvs - tlvs);
427 return; 458 return;
428} 459}
429 460
@@ -441,11 +472,12 @@ static const uint8_t *copy_macs(struct mpoa_client *mpc,
441 num_macs = (mps_macs > 1) ? mps_macs : 1; 472 num_macs = (mps_macs > 1) ? mps_macs : 1;
442 473
443 if (mpc->number_of_mps_macs != num_macs) { /* need to reallocate? */ 474 if (mpc->number_of_mps_macs != num_macs) { /* need to reallocate? */
444 if (mpc->number_of_mps_macs != 0) kfree(mpc->mps_macs); 475 if (mpc->number_of_mps_macs != 0)
476 kfree(mpc->mps_macs);
445 mpc->number_of_mps_macs = 0; 477 mpc->number_of_mps_macs = 0;
446 mpc->mps_macs = kmalloc(num_macs*ETH_ALEN, GFP_KERNEL); 478 mpc->mps_macs = kmalloc(num_macs * ETH_ALEN, GFP_KERNEL);
447 if (mpc->mps_macs == NULL) { 479 if (mpc->mps_macs == NULL) {
448 printk("mpoa: (%s) copy_macs: out of mem\n", mpc->dev->name); 480 pr_info("(%s) out of mem\n", mpc->dev->name);
449 return NULL; 481 return NULL;
450 } 482 }
451 } 483 }
@@ -478,24 +510,30 @@ static int send_via_shortcut(struct sk_buff *skb, struct mpoa_client *mpc)
478 iph = (struct iphdr *)buff; 510 iph = (struct iphdr *)buff;
479 ipaddr = iph->daddr; 511 ipaddr = iph->daddr;
480 512
481 ddprintk("mpoa: (%s) send_via_shortcut: ipaddr 0x%x\n", mpc->dev->name, ipaddr); 513 ddprintk("(%s) ipaddr 0x%x\n",
514 mpc->dev->name, ipaddr);
482 515
483 entry = mpc->in_ops->get(ipaddr, mpc); 516 entry = mpc->in_ops->get(ipaddr, mpc);
484 if (entry == NULL) { 517 if (entry == NULL) {
485 entry = mpc->in_ops->add_entry(ipaddr, mpc); 518 entry = mpc->in_ops->add_entry(ipaddr, mpc);
486 if (entry != NULL) mpc->in_ops->put(entry); 519 if (entry != NULL)
520 mpc->in_ops->put(entry);
487 return 1; 521 return 1;
488 } 522 }
489 if (mpc->in_ops->cache_hit(entry, mpc) != OPEN){ /* threshold not exceeded or VCC not ready */ 523 /* threshold not exceeded or VCC not ready */
490 ddprintk("mpoa: (%s) send_via_shortcut: cache_hit: returns != OPEN\n", mpc->dev->name); 524 if (mpc->in_ops->cache_hit(entry, mpc) != OPEN) {
525 ddprintk("(%s) cache_hit: returns != OPEN\n",
526 mpc->dev->name);
491 mpc->in_ops->put(entry); 527 mpc->in_ops->put(entry);
492 return 1; 528 return 1;
493 } 529 }
494 530
495 ddprintk("mpoa: (%s) send_via_shortcut: using shortcut\n", mpc->dev->name); 531 ddprintk("(%s) using shortcut\n",
532 mpc->dev->name);
496 /* MPOA spec A.1.4, MPOA client must decrement IP ttl at least by one */ 533 /* MPOA spec A.1.4, MPOA client must decrement IP ttl at least by one */
497 if (iph->ttl <= 1) { 534 if (iph->ttl <= 1) {
498 ddprintk("mpoa: (%s) send_via_shortcut: IP ttl = %u, using LANE\n", mpc->dev->name, iph->ttl); 535 ddprintk("(%s) IP ttl = %u, using LANE\n",
536 mpc->dev->name, iph->ttl);
499 mpc->in_ops->put(entry); 537 mpc->in_ops->put(entry);
500 return 1; 538 return 1;
501 } 539 }
@@ -504,15 +542,18 @@ static int send_via_shortcut(struct sk_buff *skb, struct mpoa_client *mpc)
504 iph->check = ip_fast_csum((unsigned char *)iph, iph->ihl); 542 iph->check = ip_fast_csum((unsigned char *)iph, iph->ihl);
505 543
506 if (entry->ctrl_info.tag != 0) { 544 if (entry->ctrl_info.tag != 0) {
507 ddprintk("mpoa: (%s) send_via_shortcut: adding tag 0x%x\n", mpc->dev->name, entry->ctrl_info.tag); 545 ddprintk("(%s) adding tag 0x%x\n",
546 mpc->dev->name, entry->ctrl_info.tag);
508 tagged_llc_snap_hdr.tag = entry->ctrl_info.tag; 547 tagged_llc_snap_hdr.tag = entry->ctrl_info.tag;
509 skb_pull(skb, ETH_HLEN); /* get rid of Eth header */ 548 skb_pull(skb, ETH_HLEN); /* get rid of Eth header */
510 skb_push(skb, sizeof(tagged_llc_snap_hdr)); /* add LLC/SNAP header */ 549 skb_push(skb, sizeof(tagged_llc_snap_hdr));
550 /* add LLC/SNAP header */
511 skb_copy_to_linear_data(skb, &tagged_llc_snap_hdr, 551 skb_copy_to_linear_data(skb, &tagged_llc_snap_hdr,
512 sizeof(tagged_llc_snap_hdr)); 552 sizeof(tagged_llc_snap_hdr));
513 } else { 553 } else {
514 skb_pull(skb, ETH_HLEN); /* get rid of Eth header */ 554 skb_pull(skb, ETH_HLEN); /* get rid of Eth header */
515 skb_push(skb, sizeof(struct llc_snap_hdr)); /* add LLC/SNAP header + tag */ 555 skb_push(skb, sizeof(struct llc_snap_hdr));
556 /* add LLC/SNAP header + tag */
516 skb_copy_to_linear_data(skb, &llc_snap_mpoa_data, 557 skb_copy_to_linear_data(skb, &llc_snap_mpoa_data,
517 sizeof(struct llc_snap_hdr)); 558 sizeof(struct llc_snap_hdr));
518 } 559 }
@@ -537,8 +578,8 @@ static netdev_tx_t mpc_send_packet(struct sk_buff *skb,
537 int i = 0; 578 int i = 0;
538 579
539 mpc = find_mpc_by_lec(dev); /* this should NEVER fail */ 580 mpc = find_mpc_by_lec(dev); /* this should NEVER fail */
540 if(mpc == NULL) { 581 if (mpc == NULL) {
541 printk("mpoa: (%s) mpc_send_packet: no MPC found\n", dev->name); 582 pr_info("(%s) no MPC found\n", dev->name);
542 goto non_ip; 583 goto non_ip;
543 } 584 }
544 585
@@ -554,14 +595,15 @@ static netdev_tx_t mpc_send_packet(struct sk_buff *skb,
554 goto non_ip; 595 goto non_ip;
555 596
556 while (i < mpc->number_of_mps_macs) { 597 while (i < mpc->number_of_mps_macs) {
557 if (!compare_ether_addr(eth->h_dest, (mpc->mps_macs + i*ETH_ALEN))) 598 if (!compare_ether_addr(eth->h_dest,
558 if ( send_via_shortcut(skb, mpc) == 0 ) /* try shortcut */ 599 (mpc->mps_macs + i*ETH_ALEN)))
559 return NETDEV_TX_OK; /* success! */ 600 if (send_via_shortcut(skb, mpc) == 0) /* try shortcut */
601 return NETDEV_TX_OK;
560 i++; 602 i++;
561 } 603 }
562 604
563 non_ip: 605non_ip:
564 return mpc->old_ops->ndo_start_xmit(skb,dev); 606 return mpc->old_ops->ndo_start_xmit(skb, dev);
565} 607}
566 608
567static int atm_mpoa_vcc_attach(struct atm_vcc *vcc, void __user *arg) 609static int atm_mpoa_vcc_attach(struct atm_vcc *vcc, void __user *arg)
@@ -574,7 +616,8 @@ static int atm_mpoa_vcc_attach(struct atm_vcc *vcc, void __user *arg)
574 616
575 bytes_left = copy_from_user(&ioc_data, arg, sizeof(struct atmmpc_ioc)); 617 bytes_left = copy_from_user(&ioc_data, arg, sizeof(struct atmmpc_ioc));
576 if (bytes_left != 0) { 618 if (bytes_left != 0) {
577 printk("mpoa: mpc_vcc_attach: Short read (missed %d bytes) from userland\n", bytes_left); 619 pr_info("mpoa:Short read (missed %d bytes) from userland\n",
620 bytes_left);
578 return -EFAULT; 621 return -EFAULT;
579 } 622 }
580 ipaddr = ioc_data.ipaddr; 623 ipaddr = ioc_data.ipaddr;
@@ -587,18 +630,20 @@ static int atm_mpoa_vcc_attach(struct atm_vcc *vcc, void __user *arg)
587 630
588 if (ioc_data.type == MPC_SOCKET_INGRESS) { 631 if (ioc_data.type == MPC_SOCKET_INGRESS) {
589 in_entry = mpc->in_ops->get(ipaddr, mpc); 632 in_entry = mpc->in_ops->get(ipaddr, mpc);
590 if (in_entry == NULL || in_entry->entry_state < INGRESS_RESOLVED) { 633 if (in_entry == NULL ||
591 printk("mpoa: (%s) mpc_vcc_attach: did not find RESOLVED entry from ingress cache\n", 634 in_entry->entry_state < INGRESS_RESOLVED) {
635 pr_info("(%s) did not find RESOLVED entry from ingress cache\n",
592 mpc->dev->name); 636 mpc->dev->name);
593 if (in_entry != NULL) mpc->in_ops->put(in_entry); 637 if (in_entry != NULL)
638 mpc->in_ops->put(in_entry);
594 return -EINVAL; 639 return -EINVAL;
595 } 640 }
596 printk("mpoa: (%s) mpc_vcc_attach: attaching ingress SVC, entry = %pI4\n", 641 pr_info("(%s) attaching ingress SVC, entry = %pI4\n",
597 mpc->dev->name, &in_entry->ctrl_info.in_dst_ip); 642 mpc->dev->name, &in_entry->ctrl_info.in_dst_ip);
598 in_entry->shortcut = vcc; 643 in_entry->shortcut = vcc;
599 mpc->in_ops->put(in_entry); 644 mpc->in_ops->put(in_entry);
600 } else { 645 } else {
601 printk("mpoa: (%s) mpc_vcc_attach: attaching egress SVC\n", mpc->dev->name); 646 pr_info("(%s) attaching egress SVC\n", mpc->dev->name);
602 } 647 }
603 648
604 vcc->proto_data = mpc->dev; 649 vcc->proto_data = mpc->dev;
@@ -618,27 +663,27 @@ static void mpc_vcc_close(struct atm_vcc *vcc, struct net_device *dev)
618 663
619 mpc = find_mpc_by_lec(dev); 664 mpc = find_mpc_by_lec(dev);
620 if (mpc == NULL) { 665 if (mpc == NULL) {
621 printk("mpoa: (%s) mpc_vcc_close: close for unknown MPC\n", dev->name); 666 pr_info("(%s) close for unknown MPC\n", dev->name);
622 return; 667 return;
623 } 668 }
624 669
625 dprintk("mpoa: (%s) mpc_vcc_close:\n", dev->name); 670 dprintk("(%s)\n", dev->name);
626 in_entry = mpc->in_ops->get_by_vcc(vcc, mpc); 671 in_entry = mpc->in_ops->get_by_vcc(vcc, mpc);
627 if (in_entry) { 672 if (in_entry) {
628 dprintk("mpoa: (%s) mpc_vcc_close: ingress SVC closed ip = %pI4\n", 673 dprintk("(%s) ingress SVC closed ip = %pI4\n",
629 mpc->dev->name, &in_entry->ctrl_info.in_dst_ip); 674 mpc->dev->name, &in_entry->ctrl_info.in_dst_ip);
630 in_entry->shortcut = NULL; 675 in_entry->shortcut = NULL;
631 mpc->in_ops->put(in_entry); 676 mpc->in_ops->put(in_entry);
632 } 677 }
633 eg_entry = mpc->eg_ops->get_by_vcc(vcc, mpc); 678 eg_entry = mpc->eg_ops->get_by_vcc(vcc, mpc);
634 if (eg_entry) { 679 if (eg_entry) {
635 dprintk("mpoa: (%s) mpc_vcc_close: egress SVC closed\n", mpc->dev->name); 680 dprintk("(%s) egress SVC closed\n", mpc->dev->name);
636 eg_entry->shortcut = NULL; 681 eg_entry->shortcut = NULL;
637 mpc->eg_ops->put(eg_entry); 682 mpc->eg_ops->put(eg_entry);
638 } 683 }
639 684
640 if (in_entry == NULL && eg_entry == NULL) 685 if (in_entry == NULL && eg_entry == NULL)
641 dprintk("mpoa: (%s) mpc_vcc_close: unused vcc closed\n", dev->name); 686 dprintk("(%s) unused vcc closed\n", dev->name);
642 687
643 return; 688 return;
644} 689}
@@ -652,18 +697,19 @@ static void mpc_push(struct atm_vcc *vcc, struct sk_buff *skb)
652 __be32 tag; 697 __be32 tag;
653 char *tmp; 698 char *tmp;
654 699
655 ddprintk("mpoa: (%s) mpc_push:\n", dev->name); 700 ddprintk("(%s)\n", dev->name);
656 if (skb == NULL) { 701 if (skb == NULL) {
657 dprintk("mpoa: (%s) mpc_push: null skb, closing VCC\n", dev->name); 702 dprintk("(%s) null skb, closing VCC\n", dev->name);
658 mpc_vcc_close(vcc, dev); 703 mpc_vcc_close(vcc, dev);
659 return; 704 return;
660 } 705 }
661 706
662 skb->dev = dev; 707 skb->dev = dev;
663 if (memcmp(skb->data, &llc_snap_mpoa_ctrl, sizeof(struct llc_snap_hdr)) == 0) { 708 if (memcmp(skb->data, &llc_snap_mpoa_ctrl,
709 sizeof(struct llc_snap_hdr)) == 0) {
664 struct sock *sk = sk_atm(vcc); 710 struct sock *sk = sk_atm(vcc);
665 711
666 dprintk("mpoa: (%s) mpc_push: control packet arrived\n", dev->name); 712 dprintk("(%s) control packet arrived\n", dev->name);
667 /* Pass control packets to daemon */ 713 /* Pass control packets to daemon */
668 skb_queue_tail(&sk->sk_receive_queue, skb); 714 skb_queue_tail(&sk->sk_receive_queue, skb);
669 sk->sk_data_ready(sk, skb->len); 715 sk->sk_data_ready(sk, skb->len);
@@ -675,20 +721,22 @@ static void mpc_push(struct atm_vcc *vcc, struct sk_buff *skb)
675 721
676 mpc = find_mpc_by_lec(dev); 722 mpc = find_mpc_by_lec(dev);
677 if (mpc == NULL) { 723 if (mpc == NULL) {
678 printk("mpoa: (%s) mpc_push: unknown MPC\n", dev->name); 724 pr_info("(%s) unknown MPC\n", dev->name);
679 return; 725 return;
680 } 726 }
681 727
682 if (memcmp(skb->data, &llc_snap_mpoa_data_tagged, sizeof(struct llc_snap_hdr)) == 0) { /* MPOA tagged data */ 728 if (memcmp(skb->data, &llc_snap_mpoa_data_tagged,
683 ddprintk("mpoa: (%s) mpc_push: tagged data packet arrived\n", dev->name); 729 sizeof(struct llc_snap_hdr)) == 0) { /* MPOA tagged data */
730 ddprintk("(%s) tagged data packet arrived\n", dev->name);
684 731
685 } else if (memcmp(skb->data, &llc_snap_mpoa_data, sizeof(struct llc_snap_hdr)) == 0) { /* MPOA data */ 732 } else if (memcmp(skb->data, &llc_snap_mpoa_data,
686 printk("mpoa: (%s) mpc_push: non-tagged data packet arrived\n", dev->name); 733 sizeof(struct llc_snap_hdr)) == 0) { /* MPOA data */
687 printk(" mpc_push: non-tagged data unsupported, purging\n"); 734 pr_info("(%s) Unsupported non-tagged data packet arrived. Purging\n",
735 dev->name);
688 dev_kfree_skb_any(skb); 736 dev_kfree_skb_any(skb);
689 return; 737 return;
690 } else { 738 } else {
691 printk("mpoa: (%s) mpc_push: garbage arrived, purging\n", dev->name); 739 pr_info("(%s) garbage arrived, purging\n", dev->name);
692 dev_kfree_skb_any(skb); 740 dev_kfree_skb_any(skb);
693 return; 741 return;
694 } 742 }
@@ -698,8 +746,8 @@ static void mpc_push(struct atm_vcc *vcc, struct sk_buff *skb)
698 746
699 eg = mpc->eg_ops->get_by_tag(tag, mpc); 747 eg = mpc->eg_ops->get_by_tag(tag, mpc);
700 if (eg == NULL) { 748 if (eg == NULL) {
701 printk("mpoa: (%s) mpc_push: Didn't find egress cache entry, tag = %u\n", 749 pr_info("mpoa: (%s) Didn't find egress cache entry, tag = %u\n",
702 dev->name,tag); 750 dev->name, tag);
703 purge_egress_shortcut(vcc, NULL); 751 purge_egress_shortcut(vcc, NULL);
704 dev_kfree_skb_any(skb); 752 dev_kfree_skb_any(skb);
705 return; 753 return;
@@ -711,13 +759,15 @@ static void mpc_push(struct atm_vcc *vcc, struct sk_buff *skb)
711 */ 759 */
712 if (eg->shortcut == NULL) { 760 if (eg->shortcut == NULL) {
713 eg->shortcut = vcc; 761 eg->shortcut = vcc;
714 printk("mpoa: (%s) mpc_push: egress SVC in use\n", dev->name); 762 pr_info("(%s) egress SVC in use\n", dev->name);
715 } 763 }
716 764
717 skb_pull(skb, sizeof(struct llc_snap_hdr) + sizeof(tag)); /* get rid of LLC/SNAP header */ 765 skb_pull(skb, sizeof(struct llc_snap_hdr) + sizeof(tag));
718 new_skb = skb_realloc_headroom(skb, eg->ctrl_info.DH_length); /* LLC/SNAP is shorter than MAC header :( */ 766 /* get rid of LLC/SNAP header */
767 new_skb = skb_realloc_headroom(skb, eg->ctrl_info.DH_length);
768 /* LLC/SNAP is shorter than MAC header :( */
719 dev_kfree_skb_any(skb); 769 dev_kfree_skb_any(skb);
720 if (new_skb == NULL){ 770 if (new_skb == NULL) {
721 mpc->eg_ops->put(eg); 771 mpc->eg_ops->put(eg);
722 return; 772 return;
723 } 773 }
@@ -750,7 +800,7 @@ static struct atm_dev mpc_dev = {
750 /* members not explicitly initialised will be 0 */ 800 /* members not explicitly initialised will be 0 */
751}; 801};
752 802
753static int atm_mpoa_mpoad_attach (struct atm_vcc *vcc, int arg) 803static int atm_mpoa_mpoad_attach(struct atm_vcc *vcc, int arg)
754{ 804{
755 struct mpoa_client *mpc; 805 struct mpoa_client *mpc;
756 struct lec_priv *priv; 806 struct lec_priv *priv;
@@ -770,15 +820,16 @@ static int atm_mpoa_mpoad_attach (struct atm_vcc *vcc, int arg)
770 820
771 mpc = find_mpc_by_itfnum(arg); 821 mpc = find_mpc_by_itfnum(arg);
772 if (mpc == NULL) { 822 if (mpc == NULL) {
773 dprintk("mpoa: mpoad_attach: allocating new mpc for itf %d\n", arg); 823 dprintk("allocating new mpc for itf %d\n", arg);
774 mpc = alloc_mpc(); 824 mpc = alloc_mpc();
775 if (mpc == NULL) 825 if (mpc == NULL)
776 return -ENOMEM; 826 return -ENOMEM;
777 mpc->dev_num = arg; 827 mpc->dev_num = arg;
778 mpc->dev = find_lec_by_itfnum(arg); /* NULL if there was no lec */ 828 mpc->dev = find_lec_by_itfnum(arg);
829 /* NULL if there was no lec */
779 } 830 }
780 if (mpc->mpoad_vcc) { 831 if (mpc->mpoad_vcc) {
781 printk("mpoa: mpoad_attach: mpoad is already present for itf %d\n", arg); 832 pr_info("mpoad is already present for itf %d\n", arg);
782 return -EADDRINUSE; 833 return -EADDRINUSE;
783 } 834 }
784 835
@@ -794,8 +845,8 @@ static int atm_mpoa_mpoad_attach (struct atm_vcc *vcc, int arg)
794 mpc->mpoad_vcc = vcc; 845 mpc->mpoad_vcc = vcc;
795 vcc->dev = &mpc_dev; 846 vcc->dev = &mpc_dev;
796 vcc_insert_socket(sk_atm(vcc)); 847 vcc_insert_socket(sk_atm(vcc));
797 set_bit(ATM_VF_META,&vcc->flags); 848 set_bit(ATM_VF_META, &vcc->flags);
798 set_bit(ATM_VF_READY,&vcc->flags); 849 set_bit(ATM_VF_READY, &vcc->flags);
799 850
800 if (mpc->dev) { 851 if (mpc->dev) {
801 char empty[ATM_ESA_LEN]; 852 char empty[ATM_ESA_LEN];
@@ -805,7 +856,7 @@ static int atm_mpoa_mpoad_attach (struct atm_vcc *vcc, int arg)
805 /* set address if mpcd e.g. gets killed and restarted. 856 /* set address if mpcd e.g. gets killed and restarted.
806 * If we do not do it now we have to wait for the next LE_ARP 857 * If we do not do it now we have to wait for the next LE_ARP
807 */ 858 */
808 if ( memcmp(mpc->mps_ctrl_addr, empty, ATM_ESA_LEN) != 0 ) 859 if (memcmp(mpc->mps_ctrl_addr, empty, ATM_ESA_LEN) != 0)
809 send_set_mps_ctrl_addr(mpc->mps_ctrl_addr, mpc); 860 send_set_mps_ctrl_addr(mpc->mps_ctrl_addr, mpc);
810 } 861 }
811 862
@@ -817,7 +868,7 @@ static void send_set_mps_ctrl_addr(const char *addr, struct mpoa_client *mpc)
817{ 868{
818 struct k_message mesg; 869 struct k_message mesg;
819 870
820 memcpy (mpc->mps_ctrl_addr, addr, ATM_ESA_LEN); 871 memcpy(mpc->mps_ctrl_addr, addr, ATM_ESA_LEN);
821 872
822 mesg.type = SET_MPS_CTRL_ADDR; 873 mesg.type = SET_MPS_CTRL_ADDR;
823 memcpy(mesg.MPS_ctrl, addr, ATM_ESA_LEN); 874 memcpy(mesg.MPS_ctrl, addr, ATM_ESA_LEN);
@@ -833,11 +884,11 @@ static void mpoad_close(struct atm_vcc *vcc)
833 884
834 mpc = find_mpc_by_vcc(vcc); 885 mpc = find_mpc_by_vcc(vcc);
835 if (mpc == NULL) { 886 if (mpc == NULL) {
836 printk("mpoa: mpoad_close: did not find MPC\n"); 887 pr_info("did not find MPC\n");
837 return; 888 return;
838 } 889 }
839 if (!mpc->mpoad_vcc) { 890 if (!mpc->mpoad_vcc) {
840 printk("mpoa: mpoad_close: close for non-present mpoad\n"); 891 pr_info("close for non-present mpoad\n");
841 return; 892 return;
842 } 893 }
843 894
@@ -857,7 +908,7 @@ static void mpoad_close(struct atm_vcc *vcc)
857 kfree_skb(skb); 908 kfree_skb(skb);
858 } 909 }
859 910
860 printk("mpoa: (%s) going down\n", 911 pr_info("(%s) going down\n",
861 (mpc->dev) ? mpc->dev->name : "<unknown>"); 912 (mpc->dev) ? mpc->dev->name : "<unknown>");
862 module_put(THIS_MODULE); 913 module_put(THIS_MODULE);
863 914
@@ -871,61 +922,61 @@ static int msg_from_mpoad(struct atm_vcc *vcc, struct sk_buff *skb)
871{ 922{
872 923
873 struct mpoa_client *mpc = find_mpc_by_vcc(vcc); 924 struct mpoa_client *mpc = find_mpc_by_vcc(vcc);
874 struct k_message *mesg = (struct k_message*)skb->data; 925 struct k_message *mesg = (struct k_message *)skb->data;
875 atomic_sub(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc); 926 atomic_sub(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
876 927
877 if (mpc == NULL) { 928 if (mpc == NULL) {
878 printk("mpoa: msg_from_mpoad: no mpc found\n"); 929 pr_info("no mpc found\n");
879 return 0; 930 return 0;
880 } 931 }
881 dprintk("mpoa: (%s) msg_from_mpoad:", (mpc->dev) ? mpc->dev->name : "<unknown>"); 932 dprintk("(%s)", mpc->dev ? mpc->dev->name : "<unknown>");
882 switch(mesg->type) { 933 switch (mesg->type) {
883 case MPOA_RES_REPLY_RCVD: 934 case MPOA_RES_REPLY_RCVD:
884 dprintk(" mpoa_res_reply_rcvd\n"); 935 dprintk_cont("mpoa_res_reply_rcvd\n");
885 MPOA_res_reply_rcvd(mesg, mpc); 936 MPOA_res_reply_rcvd(mesg, mpc);
886 break; 937 break;
887 case MPOA_TRIGGER_RCVD: 938 case MPOA_TRIGGER_RCVD:
888 dprintk(" mpoa_trigger_rcvd\n"); 939 dprintk_cont("mpoa_trigger_rcvd\n");
889 MPOA_trigger_rcvd(mesg, mpc); 940 MPOA_trigger_rcvd(mesg, mpc);
890 break; 941 break;
891 case INGRESS_PURGE_RCVD: 942 case INGRESS_PURGE_RCVD:
892 dprintk(" nhrp_purge_rcvd\n"); 943 dprintk_cont("nhrp_purge_rcvd\n");
893 ingress_purge_rcvd(mesg, mpc); 944 ingress_purge_rcvd(mesg, mpc);
894 break; 945 break;
895 case EGRESS_PURGE_RCVD: 946 case EGRESS_PURGE_RCVD:
896 dprintk(" egress_purge_reply_rcvd\n"); 947 dprintk_cont("egress_purge_reply_rcvd\n");
897 egress_purge_rcvd(mesg, mpc); 948 egress_purge_rcvd(mesg, mpc);
898 break; 949 break;
899 case MPS_DEATH: 950 case MPS_DEATH:
900 dprintk(" mps_death\n"); 951 dprintk_cont("mps_death\n");
901 mps_death(mesg, mpc); 952 mps_death(mesg, mpc);
902 break; 953 break;
903 case CACHE_IMPOS_RCVD: 954 case CACHE_IMPOS_RCVD:
904 dprintk(" cache_impos_rcvd\n"); 955 dprintk_cont("cache_impos_rcvd\n");
905 MPOA_cache_impos_rcvd(mesg, mpc); 956 MPOA_cache_impos_rcvd(mesg, mpc);
906 break; 957 break;
907 case SET_MPC_CTRL_ADDR: 958 case SET_MPC_CTRL_ADDR:
908 dprintk(" set_mpc_ctrl_addr\n"); 959 dprintk_cont("set_mpc_ctrl_addr\n");
909 set_mpc_ctrl_addr_rcvd(mesg, mpc); 960 set_mpc_ctrl_addr_rcvd(mesg, mpc);
910 break; 961 break;
911 case SET_MPS_MAC_ADDR: 962 case SET_MPS_MAC_ADDR:
912 dprintk(" set_mps_mac_addr\n"); 963 dprintk_cont("set_mps_mac_addr\n");
913 set_mps_mac_addr_rcvd(mesg, mpc); 964 set_mps_mac_addr_rcvd(mesg, mpc);
914 break; 965 break;
915 case CLEAN_UP_AND_EXIT: 966 case CLEAN_UP_AND_EXIT:
916 dprintk(" clean_up_and_exit\n"); 967 dprintk_cont("clean_up_and_exit\n");
917 clean_up(mesg, mpc, DIE); 968 clean_up(mesg, mpc, DIE);
918 break; 969 break;
919 case RELOAD: 970 case RELOAD:
920 dprintk(" reload\n"); 971 dprintk_cont("reload\n");
921 clean_up(mesg, mpc, RELOAD); 972 clean_up(mesg, mpc, RELOAD);
922 break; 973 break;
923 case SET_MPC_PARAMS: 974 case SET_MPC_PARAMS:
924 dprintk(" set_mpc_params\n"); 975 dprintk_cont("set_mpc_params\n");
925 mpc->parameters = mesg->content.params; 976 mpc->parameters = mesg->content.params;
926 break; 977 break;
927 default: 978 default:
928 dprintk(" unknown message %d\n", mesg->type); 979 dprintk_cont("unknown message %d\n", mesg->type);
929 break; 980 break;
930 } 981 }
931 kfree_skb(skb); 982 kfree_skb(skb);
@@ -940,7 +991,7 @@ int msg_to_mpoad(struct k_message *mesg, struct mpoa_client *mpc)
940 struct sock *sk; 991 struct sock *sk;
941 992
942 if (mpc == NULL || !mpc->mpoad_vcc) { 993 if (mpc == NULL || !mpc->mpoad_vcc) {
943 printk("mpoa: msg_to_mpoad: mesg %d to a non-existent mpoad\n", mesg->type); 994 pr_info("mesg %d to a non-existent mpoad\n", mesg->type);
944 return -ENXIO; 995 return -ENXIO;
945 } 996 }
946 997
@@ -958,7 +1009,8 @@ int msg_to_mpoad(struct k_message *mesg, struct mpoa_client *mpc)
958 return 0; 1009 return 0;
959} 1010}
960 1011
961static int mpoa_event_listener(struct notifier_block *mpoa_notifier, unsigned long event, void *dev_ptr) 1012static int mpoa_event_listener(struct notifier_block *mpoa_notifier,
1013 unsigned long event, void *dev_ptr)
962{ 1014{
963 struct net_device *dev; 1015 struct net_device *dev;
964 struct mpoa_client *mpc; 1016 struct mpoa_client *mpc;
@@ -980,25 +1032,24 @@ static int mpoa_event_listener(struct notifier_block *mpoa_notifier, unsigned lo
980 priv->lane2_ops->associate_indicator = lane2_assoc_ind; 1032 priv->lane2_ops->associate_indicator = lane2_assoc_ind;
981 mpc = find_mpc_by_itfnum(priv->itfnum); 1033 mpc = find_mpc_by_itfnum(priv->itfnum);
982 if (mpc == NULL) { 1034 if (mpc == NULL) {
983 dprintk("mpoa: mpoa_event_listener: allocating new mpc for %s\n", 1035 dprintk("allocating new mpc for %s\n", dev->name);
984 dev->name);
985 mpc = alloc_mpc(); 1036 mpc = alloc_mpc();
986 if (mpc == NULL) { 1037 if (mpc == NULL) {
987 printk("mpoa: mpoa_event_listener: no new mpc"); 1038 pr_info("no new mpc");
988 break; 1039 break;
989 } 1040 }
990 } 1041 }
991 mpc->dev_num = priv->itfnum; 1042 mpc->dev_num = priv->itfnum;
992 mpc->dev = dev; 1043 mpc->dev = dev;
993 dev_hold(dev); 1044 dev_hold(dev);
994 dprintk("mpoa: (%s) was initialized\n", dev->name); 1045 dprintk("(%s) was initialized\n", dev->name);
995 break; 1046 break;
996 case NETDEV_UNREGISTER: 1047 case NETDEV_UNREGISTER:
997 /* the lec device was deallocated */ 1048 /* the lec device was deallocated */
998 mpc = find_mpc_by_lec(dev); 1049 mpc = find_mpc_by_lec(dev);
999 if (mpc == NULL) 1050 if (mpc == NULL)
1000 break; 1051 break;
1001 dprintk("mpoa: device (%s) was deallocated\n", dev->name); 1052 dprintk("device (%s) was deallocated\n", dev->name);
1002 stop_mpc(mpc); 1053 stop_mpc(mpc);
1003 dev_put(mpc->dev); 1054 dev_put(mpc->dev);
1004 mpc->dev = NULL; 1055 mpc->dev = NULL;
@@ -1008,9 +1059,8 @@ static int mpoa_event_listener(struct notifier_block *mpoa_notifier, unsigned lo
1008 mpc = find_mpc_by_lec(dev); 1059 mpc = find_mpc_by_lec(dev);
1009 if (mpc == NULL) 1060 if (mpc == NULL)
1010 break; 1061 break;
1011 if (mpc->mpoad_vcc != NULL) { 1062 if (mpc->mpoad_vcc != NULL)
1012 start_mpc(mpc, dev); 1063 start_mpc(mpc, dev);
1013 }
1014 break; 1064 break;
1015 case NETDEV_DOWN: 1065 case NETDEV_DOWN:
1016 /* the dev was ifconfig'ed down */ 1066 /* the dev was ifconfig'ed down */
@@ -1020,9 +1070,8 @@ static int mpoa_event_listener(struct notifier_block *mpoa_notifier, unsigned lo
1020 mpc = find_mpc_by_lec(dev); 1070 mpc = find_mpc_by_lec(dev);
1021 if (mpc == NULL) 1071 if (mpc == NULL)
1022 break; 1072 break;
1023 if (mpc->mpoad_vcc != NULL) { 1073 if (mpc->mpoad_vcc != NULL)
1024 stop_mpc(mpc); 1074 stop_mpc(mpc);
1025 }
1026 break; 1075 break;
1027 case NETDEV_REBOOT: 1076 case NETDEV_REBOOT:
1028 case NETDEV_CHANGE: 1077 case NETDEV_CHANGE:
@@ -1049,7 +1098,7 @@ static void MPOA_trigger_rcvd(struct k_message *msg, struct mpoa_client *mpc)
1049 in_cache_entry *entry; 1098 in_cache_entry *entry;
1050 1099
1051 entry = mpc->in_ops->get(dst_ip, mpc); 1100 entry = mpc->in_ops->get(dst_ip, mpc);
1052 if(entry == NULL){ 1101 if (entry == NULL) {
1053 entry = mpc->in_ops->add_entry(dst_ip, mpc); 1102 entry = mpc->in_ops->add_entry(dst_ip, mpc);
1054 entry->entry_state = INGRESS_RESOLVING; 1103 entry->entry_state = INGRESS_RESOLVING;
1055 msg->type = SND_MPOA_RES_RQST; 1104 msg->type = SND_MPOA_RES_RQST;
@@ -1060,7 +1109,7 @@ static void MPOA_trigger_rcvd(struct k_message *msg, struct mpoa_client *mpc)
1060 return; 1109 return;
1061 } 1110 }
1062 1111
1063 if(entry->entry_state == INGRESS_INVALID){ 1112 if (entry->entry_state == INGRESS_INVALID) {
1064 entry->entry_state = INGRESS_RESOLVING; 1113 entry->entry_state = INGRESS_RESOLVING;
1065 msg->type = SND_MPOA_RES_RQST; 1114 msg->type = SND_MPOA_RES_RQST;
1066 msg->content.in_info = entry->ctrl_info; 1115 msg->content.in_info = entry->ctrl_info;
@@ -1070,7 +1119,7 @@ static void MPOA_trigger_rcvd(struct k_message *msg, struct mpoa_client *mpc)
1070 return; 1119 return;
1071 } 1120 }
1072 1121
1073 printk("mpoa: (%s) MPOA_trigger_rcvd: entry already in resolving state\n", 1122 pr_info("(%s) entry already in resolving state\n",
1074 (mpc->dev) ? mpc->dev->name : "<unknown>"); 1123 (mpc->dev) ? mpc->dev->name : "<unknown>");
1075 mpc->in_ops->put(entry); 1124 mpc->in_ops->put(entry);
1076 return; 1125 return;
@@ -1080,23 +1129,25 @@ static void MPOA_trigger_rcvd(struct k_message *msg, struct mpoa_client *mpc)
1080 * Things get complicated because we have to check if there's an egress 1129 * Things get complicated because we have to check if there's an egress
1081 * shortcut with suitable traffic parameters we could use. 1130 * shortcut with suitable traffic parameters we could use.
1082 */ 1131 */
1083static void check_qos_and_open_shortcut(struct k_message *msg, struct mpoa_client *client, in_cache_entry *entry) 1132static void check_qos_and_open_shortcut(struct k_message *msg,
1133 struct mpoa_client *client,
1134 in_cache_entry *entry)
1084{ 1135{
1085 __be32 dst_ip = msg->content.in_info.in_dst_ip; 1136 __be32 dst_ip = msg->content.in_info.in_dst_ip;
1086 struct atm_mpoa_qos *qos = atm_mpoa_search_qos(dst_ip); 1137 struct atm_mpoa_qos *qos = atm_mpoa_search_qos(dst_ip);
1087 eg_cache_entry *eg_entry = client->eg_ops->get_by_src_ip(dst_ip, client); 1138 eg_cache_entry *eg_entry = client->eg_ops->get_by_src_ip(dst_ip, client);
1088 1139
1089 if(eg_entry && eg_entry->shortcut){ 1140 if (eg_entry && eg_entry->shortcut) {
1090 if(eg_entry->shortcut->qos.txtp.traffic_class & 1141 if (eg_entry->shortcut->qos.txtp.traffic_class &
1091 msg->qos.txtp.traffic_class & 1142 msg->qos.txtp.traffic_class &
1092 (qos ? qos->qos.txtp.traffic_class : ATM_UBR | ATM_CBR)){ 1143 (qos ? qos->qos.txtp.traffic_class : ATM_UBR | ATM_CBR)) {
1093 if(eg_entry->shortcut->qos.txtp.traffic_class == ATM_UBR) 1144 if (eg_entry->shortcut->qos.txtp.traffic_class == ATM_UBR)
1094 entry->shortcut = eg_entry->shortcut; 1145 entry->shortcut = eg_entry->shortcut;
1095 else if(eg_entry->shortcut->qos.txtp.max_pcr > 0) 1146 else if (eg_entry->shortcut->qos.txtp.max_pcr > 0)
1096 entry->shortcut = eg_entry->shortcut; 1147 entry->shortcut = eg_entry->shortcut;
1097 } 1148 }
1098 if(entry->shortcut){ 1149 if (entry->shortcut) {
1099 dprintk("mpoa: (%s) using egress SVC to reach %pI4\n", 1150 dprintk("(%s) using egress SVC to reach %pI4\n",
1100 client->dev->name, &dst_ip); 1151 client->dev->name, &dst_ip);
1101 client->eg_ops->put(eg_entry); 1152 client->eg_ops->put(eg_entry);
1102 return; 1153 return;
@@ -1107,12 +1158,13 @@ static void check_qos_and_open_shortcut(struct k_message *msg, struct mpoa_clien
1107 1158
1108 /* No luck in the egress cache we must open an ingress SVC */ 1159 /* No luck in the egress cache we must open an ingress SVC */
1109 msg->type = OPEN_INGRESS_SVC; 1160 msg->type = OPEN_INGRESS_SVC;
1110 if (qos && (qos->qos.txtp.traffic_class == msg->qos.txtp.traffic_class)) 1161 if (qos &&
1111 { 1162 (qos->qos.txtp.traffic_class == msg->qos.txtp.traffic_class)) {
1112 msg->qos = qos->qos; 1163 msg->qos = qos->qos;
1113 printk("mpoa: (%s) trying to get a CBR shortcut\n",client->dev->name); 1164 pr_info("(%s) trying to get a CBR shortcut\n",
1114 } 1165 client->dev->name);
1115 else memset(&msg->qos,0,sizeof(struct atm_qos)); 1166 } else
1167 memset(&msg->qos, 0, sizeof(struct atm_qos));
1116 msg_to_mpoad(msg, client); 1168 msg_to_mpoad(msg, client);
1117 return; 1169 return;
1118} 1170}
@@ -1122,17 +1174,19 @@ static void MPOA_res_reply_rcvd(struct k_message *msg, struct mpoa_client *mpc)
1122 __be32 dst_ip = msg->content.in_info.in_dst_ip; 1174 __be32 dst_ip = msg->content.in_info.in_dst_ip;
1123 in_cache_entry *entry = mpc->in_ops->get(dst_ip, mpc); 1175 in_cache_entry *entry = mpc->in_ops->get(dst_ip, mpc);
1124 1176
1125 dprintk("mpoa: (%s) MPOA_res_reply_rcvd: ip %pI4\n", 1177 dprintk("(%s) ip %pI4\n",
1126 mpc->dev->name, &dst_ip); 1178 mpc->dev->name, &dst_ip);
1127 ddprintk("mpoa: (%s) MPOA_res_reply_rcvd() entry = %p", mpc->dev->name, entry); 1179 ddprintk("(%s) entry = %p",
1128 if(entry == NULL){ 1180 mpc->dev->name, entry);
1129 printk("\nmpoa: (%s) ARGH, received res. reply for an entry that doesn't exist.\n", mpc->dev->name); 1181 if (entry == NULL) {
1182 pr_info("(%s) ARGH, received res. reply for an entry that doesn't exist.\n",
1183 mpc->dev->name);
1130 return; 1184 return;
1131 } 1185 }
1132 ddprintk(" entry_state = %d ", entry->entry_state); 1186 ddprintk_cont(" entry_state = %d ", entry->entry_state);
1133 1187
1134 if (entry->entry_state == INGRESS_RESOLVED) { 1188 if (entry->entry_state == INGRESS_RESOLVED) {
1135 printk("\nmpoa: (%s) MPOA_res_reply_rcvd for RESOLVED entry!\n", mpc->dev->name); 1189 pr_info("(%s) RESOLVED entry!\n", mpc->dev->name);
1136 mpc->in_ops->put(entry); 1190 mpc->in_ops->put(entry);
1137 return; 1191 return;
1138 } 1192 }
@@ -1141,17 +1195,18 @@ static void MPOA_res_reply_rcvd(struct k_message *msg, struct mpoa_client *mpc)
1141 do_gettimeofday(&(entry->tv)); 1195 do_gettimeofday(&(entry->tv));
1142 do_gettimeofday(&(entry->reply_wait)); /* Used in refreshing func from now on */ 1196 do_gettimeofday(&(entry->reply_wait)); /* Used in refreshing func from now on */
1143 entry->refresh_time = 0; 1197 entry->refresh_time = 0;
1144 ddprintk("entry->shortcut = %p\n", entry->shortcut); 1198 ddprintk_cont("entry->shortcut = %p\n", entry->shortcut);
1145 1199
1146 if(entry->entry_state == INGRESS_RESOLVING && entry->shortcut != NULL){ 1200 if (entry->entry_state == INGRESS_RESOLVING &&
1201 entry->shortcut != NULL) {
1147 entry->entry_state = INGRESS_RESOLVED; 1202 entry->entry_state = INGRESS_RESOLVED;
1148 mpc->in_ops->put(entry); 1203 mpc->in_ops->put(entry);
1149 return; /* Shortcut already open... */ 1204 return; /* Shortcut already open... */
1150 } 1205 }
1151 1206
1152 if (entry->shortcut != NULL) { 1207 if (entry->shortcut != NULL) {
1153 printk("mpoa: (%s) MPOA_res_reply_rcvd: entry->shortcut != NULL, impossible!\n", 1208 pr_info("(%s) entry->shortcut != NULL, impossible!\n",
1154 mpc->dev->name); 1209 mpc->dev->name);
1155 mpc->in_ops->put(entry); 1210 mpc->in_ops->put(entry);
1156 return; 1211 return;
1157 } 1212 }
@@ -1170,14 +1225,14 @@ static void ingress_purge_rcvd(struct k_message *msg, struct mpoa_client *mpc)
1170 __be32 mask = msg->ip_mask; 1225 __be32 mask = msg->ip_mask;
1171 in_cache_entry *entry = mpc->in_ops->get_with_mask(dst_ip, mpc, mask); 1226 in_cache_entry *entry = mpc->in_ops->get_with_mask(dst_ip, mpc, mask);
1172 1227
1173 if(entry == NULL){ 1228 if (entry == NULL) {
1174 printk("mpoa: (%s) ingress_purge_rcvd: purge for a non-existing entry, ip = %pI4\n", 1229 pr_info("(%s) purge for a non-existing entry, ip = %pI4\n",
1175 mpc->dev->name, &dst_ip); 1230 mpc->dev->name, &dst_ip);
1176 return; 1231 return;
1177 } 1232 }
1178 1233
1179 do { 1234 do {
1180 dprintk("mpoa: (%s) ingress_purge_rcvd: removing an ingress entry, ip = %pI4\n", 1235 dprintk("(%s) removing an ingress entry, ip = %pI4\n",
1181 mpc->dev->name, &dst_ip); 1236 mpc->dev->name, &dst_ip);
1182 write_lock_bh(&mpc->ingress_lock); 1237 write_lock_bh(&mpc->ingress_lock);
1183 mpc->in_ops->remove_entry(entry, mpc); 1238 mpc->in_ops->remove_entry(entry, mpc);
@@ -1195,7 +1250,8 @@ static void egress_purge_rcvd(struct k_message *msg, struct mpoa_client *mpc)
1195 eg_cache_entry *entry = mpc->eg_ops->get_by_cache_id(cache_id, mpc); 1250 eg_cache_entry *entry = mpc->eg_ops->get_by_cache_id(cache_id, mpc);
1196 1251
1197 if (entry == NULL) { 1252 if (entry == NULL) {
1198 dprintk("mpoa: (%s) egress_purge_rcvd: purge for a non-existing entry\n", mpc->dev->name); 1253 dprintk("(%s) purge for a non-existing entry\n",
1254 mpc->dev->name);
1199 return; 1255 return;
1200 } 1256 }
1201 1257
@@ -1214,15 +1270,15 @@ static void purge_egress_shortcut(struct atm_vcc *vcc, eg_cache_entry *entry)
1214 struct k_message *purge_msg; 1270 struct k_message *purge_msg;
1215 struct sk_buff *skb; 1271 struct sk_buff *skb;
1216 1272
1217 dprintk("mpoa: purge_egress_shortcut: entering\n"); 1273 dprintk("entering\n");
1218 if (vcc == NULL) { 1274 if (vcc == NULL) {
1219 printk("mpoa: purge_egress_shortcut: vcc == NULL\n"); 1275 pr_info("vcc == NULL\n");
1220 return; 1276 return;
1221 } 1277 }
1222 1278
1223 skb = alloc_skb(sizeof(struct k_message), GFP_ATOMIC); 1279 skb = alloc_skb(sizeof(struct k_message), GFP_ATOMIC);
1224 if (skb == NULL) { 1280 if (skb == NULL) {
1225 printk("mpoa: purge_egress_shortcut: out of memory\n"); 1281 pr_info("out of memory\n");
1226 return; 1282 return;
1227 } 1283 }
1228 1284
@@ -1238,7 +1294,7 @@ static void purge_egress_shortcut(struct atm_vcc *vcc, eg_cache_entry *entry)
1238 sk = sk_atm(vcc); 1294 sk = sk_atm(vcc);
1239 skb_queue_tail(&sk->sk_receive_queue, skb); 1295 skb_queue_tail(&sk->sk_receive_queue, skb);
1240 sk->sk_data_ready(sk, skb->len); 1296 sk->sk_data_ready(sk, skb->len);
1241 dprintk("mpoa: purge_egress_shortcut: exiting:\n"); 1297 dprintk("exiting\n");
1242 1298
1243 return; 1299 return;
1244} 1300}
@@ -1247,14 +1303,14 @@ static void purge_egress_shortcut(struct atm_vcc *vcc, eg_cache_entry *entry)
1247 * Our MPS died. Tell our daemon to send NHRP data plane purge to each 1303 * Our MPS died. Tell our daemon to send NHRP data plane purge to each
1248 * of the egress shortcuts we have. 1304 * of the egress shortcuts we have.
1249 */ 1305 */
1250static void mps_death( struct k_message * msg, struct mpoa_client * mpc ) 1306static void mps_death(struct k_message *msg, struct mpoa_client *mpc)
1251{ 1307{
1252 eg_cache_entry *entry; 1308 eg_cache_entry *entry;
1253 1309
1254 dprintk("mpoa: (%s) mps_death:\n", mpc->dev->name); 1310 dprintk("(%s)\n", mpc->dev->name);
1255 1311
1256 if(memcmp(msg->MPS_ctrl, mpc->mps_ctrl_addr, ATM_ESA_LEN)){ 1312 if (memcmp(msg->MPS_ctrl, mpc->mps_ctrl_addr, ATM_ESA_LEN)) {
1257 printk("mpoa: (%s) mps_death: wrong MPS\n", mpc->dev->name); 1313 pr_info("(%s) wrong MPS\n", mpc->dev->name);
1258 return; 1314 return;
1259 } 1315 }
1260 1316
@@ -1273,20 +1329,21 @@ static void mps_death( struct k_message * msg, struct mpoa_client * mpc )
1273 return; 1329 return;
1274} 1330}
1275 1331
1276static void MPOA_cache_impos_rcvd( struct k_message * msg, struct mpoa_client * mpc) 1332static void MPOA_cache_impos_rcvd(struct k_message *msg,
1333 struct mpoa_client *mpc)
1277{ 1334{
1278 uint16_t holding_time; 1335 uint16_t holding_time;
1279 eg_cache_entry *entry = mpc->eg_ops->get_by_cache_id(msg->content.eg_info.cache_id, mpc); 1336 eg_cache_entry *entry = mpc->eg_ops->get_by_cache_id(msg->content.eg_info.cache_id, mpc);
1280 1337
1281 holding_time = msg->content.eg_info.holding_time; 1338 holding_time = msg->content.eg_info.holding_time;
1282 dprintk("mpoa: (%s) MPOA_cache_impos_rcvd: entry = %p, holding_time = %u\n", 1339 dprintk("(%s) entry = %p, holding_time = %u\n",
1283 mpc->dev->name, entry, holding_time); 1340 mpc->dev->name, entry, holding_time);
1284 if(entry == NULL && holding_time) { 1341 if (entry == NULL && holding_time) {
1285 entry = mpc->eg_ops->add_entry(msg, mpc); 1342 entry = mpc->eg_ops->add_entry(msg, mpc);
1286 mpc->eg_ops->put(entry); 1343 mpc->eg_ops->put(entry);
1287 return; 1344 return;
1288 } 1345 }
1289 if(holding_time){ 1346 if (holding_time) {
1290 mpc->eg_ops->update(entry, holding_time); 1347 mpc->eg_ops->update(entry, holding_time);
1291 return; 1348 return;
1292 } 1349 }
@@ -1300,7 +1357,8 @@ static void MPOA_cache_impos_rcvd( struct k_message * msg, struct mpoa_client *
1300 return; 1357 return;
1301} 1358}
1302 1359
1303static void set_mpc_ctrl_addr_rcvd(struct k_message *mesg, struct mpoa_client *mpc) 1360static void set_mpc_ctrl_addr_rcvd(struct k_message *mesg,
1361 struct mpoa_client *mpc)
1304{ 1362{
1305 struct lec_priv *priv; 1363 struct lec_priv *priv;
1306 int i, retval ; 1364 int i, retval ;
@@ -1315,34 +1373,39 @@ static void set_mpc_ctrl_addr_rcvd(struct k_message *mesg, struct mpoa_client *m
1315 memcpy(&tlv[7], mesg->MPS_ctrl, ATM_ESA_LEN); /* MPC ctrl ATM addr */ 1373 memcpy(&tlv[7], mesg->MPS_ctrl, ATM_ESA_LEN); /* MPC ctrl ATM addr */
1316 memcpy(mpc->our_ctrl_addr, mesg->MPS_ctrl, ATM_ESA_LEN); 1374 memcpy(mpc->our_ctrl_addr, mesg->MPS_ctrl, ATM_ESA_LEN);
1317 1375
1318 dprintk("mpoa: (%s) setting MPC ctrl ATM address to ", 1376 dprintk("(%s) setting MPC ctrl ATM address to",
1319 (mpc->dev) ? mpc->dev->name : "<unknown>"); 1377 mpc->dev ? mpc->dev->name : "<unknown>");
1320 for (i = 7; i < sizeof(tlv); i++) 1378 for (i = 7; i < sizeof(tlv); i++)
1321 dprintk("%02x ", tlv[i]); 1379 dprintk_cont(" %02x", tlv[i]);
1322 dprintk("\n"); 1380 dprintk_cont("\n");
1323 1381
1324 if (mpc->dev) { 1382 if (mpc->dev) {
1325 priv = netdev_priv(mpc->dev); 1383 priv = netdev_priv(mpc->dev);
1326 retval = priv->lane2_ops->associate_req(mpc->dev, mpc->dev->dev_addr, tlv, sizeof(tlv)); 1384 retval = priv->lane2_ops->associate_req(mpc->dev,
1385 mpc->dev->dev_addr,
1386 tlv, sizeof(tlv));
1327 if (retval == 0) 1387 if (retval == 0)
1328 printk("mpoa: (%s) MPOA device type TLV association failed\n", mpc->dev->name); 1388 pr_info("(%s) MPOA device type TLV association failed\n",
1389 mpc->dev->name);
1329 retval = priv->lane2_ops->resolve(mpc->dev, NULL, 1, NULL, NULL); 1390 retval = priv->lane2_ops->resolve(mpc->dev, NULL, 1, NULL, NULL);
1330 if (retval < 0) 1391 if (retval < 0)
1331 printk("mpoa: (%s) targetless LE_ARP request failed\n", mpc->dev->name); 1392 pr_info("(%s) targetless LE_ARP request failed\n",
1393 mpc->dev->name);
1332 } 1394 }
1333 1395
1334 return; 1396 return;
1335} 1397}
1336 1398
1337static void set_mps_mac_addr_rcvd(struct k_message *msg, struct mpoa_client *client) 1399static void set_mps_mac_addr_rcvd(struct k_message *msg,
1400 struct mpoa_client *client)
1338{ 1401{
1339 1402
1340 if(client->number_of_mps_macs) 1403 if (client->number_of_mps_macs)
1341 kfree(client->mps_macs); 1404 kfree(client->mps_macs);
1342 client->number_of_mps_macs = 0; 1405 client->number_of_mps_macs = 0;
1343 client->mps_macs = kmemdup(msg->MPS_ctrl, ETH_ALEN, GFP_KERNEL); 1406 client->mps_macs = kmemdup(msg->MPS_ctrl, ETH_ALEN, GFP_KERNEL);
1344 if (client->mps_macs == NULL) { 1407 if (client->mps_macs == NULL) {
1345 printk("mpoa: set_mps_mac_addr_rcvd: out of memory\n"); 1408 pr_info("out of memory\n");
1346 return; 1409 return;
1347 } 1410 }
1348 client->number_of_mps_macs = 1; 1411 client->number_of_mps_macs = 1;
@@ -1363,11 +1426,11 @@ static void clean_up(struct k_message *msg, struct mpoa_client *mpc, int action)
1363 /* FIXME: This knows too much of the cache structure */ 1426 /* FIXME: This knows too much of the cache structure */
1364 read_lock_irq(&mpc->egress_lock); 1427 read_lock_irq(&mpc->egress_lock);
1365 entry = mpc->eg_cache; 1428 entry = mpc->eg_cache;
1366 while (entry != NULL){ 1429 while (entry != NULL) {
1367 msg->content.eg_info = entry->ctrl_info; 1430 msg->content.eg_info = entry->ctrl_info;
1368 dprintk("mpoa: cache_id %u\n", entry->ctrl_info.cache_id); 1431 dprintk("cache_id %u\n", entry->ctrl_info.cache_id);
1369 msg_to_mpoad(msg, mpc); 1432 msg_to_mpoad(msg, mpc);
1370 entry = entry->next; 1433 entry = entry->next;
1371 } 1434 }
1372 read_unlock_irq(&mpc->egress_lock); 1435 read_unlock_irq(&mpc->egress_lock);
1373 1436
@@ -1386,20 +1449,22 @@ static void mpc_timer_refresh(void)
1386 return; 1449 return;
1387} 1450}
1388 1451
1389static void mpc_cache_check( unsigned long checking_time ) 1452static void mpc_cache_check(unsigned long checking_time)
1390{ 1453{
1391 struct mpoa_client *mpc = mpcs; 1454 struct mpoa_client *mpc = mpcs;
1392 static unsigned long previous_resolving_check_time; 1455 static unsigned long previous_resolving_check_time;
1393 static unsigned long previous_refresh_time; 1456 static unsigned long previous_refresh_time;
1394 1457
1395 while( mpc != NULL ){ 1458 while (mpc != NULL) {
1396 mpc->in_ops->clear_count(mpc); 1459 mpc->in_ops->clear_count(mpc);
1397 mpc->eg_ops->clear_expired(mpc); 1460 mpc->eg_ops->clear_expired(mpc);
1398 if(checking_time - previous_resolving_check_time > mpc->parameters.mpc_p4 * HZ ){ 1461 if (checking_time - previous_resolving_check_time >
1462 mpc->parameters.mpc_p4 * HZ) {
1399 mpc->in_ops->check_resolving(mpc); 1463 mpc->in_ops->check_resolving(mpc);
1400 previous_resolving_check_time = checking_time; 1464 previous_resolving_check_time = checking_time;
1401 } 1465 }
1402 if(checking_time - previous_refresh_time > mpc->parameters.mpc_p5 * HZ ){ 1466 if (checking_time - previous_refresh_time >
1467 mpc->parameters.mpc_p5 * HZ) {
1403 mpc->in_ops->refresh(mpc); 1468 mpc->in_ops->refresh(mpc);
1404 previous_refresh_time = checking_time; 1469 previous_refresh_time = checking_time;
1405 } 1470 }
@@ -1410,7 +1475,8 @@ static void mpc_cache_check( unsigned long checking_time )
1410 return; 1475 return;
1411} 1476}
1412 1477
1413static int atm_mpoa_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg) 1478static int atm_mpoa_ioctl(struct socket *sock, unsigned int cmd,
1479 unsigned long arg)
1414{ 1480{
1415 int err = 0; 1481 int err = 0;
1416 struct atm_vcc *vcc = ATM_SD(sock); 1482 struct atm_vcc *vcc = ATM_SD(sock);
@@ -1422,21 +1488,20 @@ static int atm_mpoa_ioctl(struct socket *sock, unsigned int cmd, unsigned long a
1422 return -EPERM; 1488 return -EPERM;
1423 1489
1424 switch (cmd) { 1490 switch (cmd) {
1425 case ATMMPC_CTRL: 1491 case ATMMPC_CTRL:
1426 err = atm_mpoa_mpoad_attach(vcc, (int)arg); 1492 err = atm_mpoa_mpoad_attach(vcc, (int)arg);
1427 if (err >= 0) 1493 if (err >= 0)
1428 sock->state = SS_CONNECTED; 1494 sock->state = SS_CONNECTED;
1429 break; 1495 break;
1430 case ATMMPC_DATA: 1496 case ATMMPC_DATA:
1431 err = atm_mpoa_vcc_attach(vcc, (void __user *)arg); 1497 err = atm_mpoa_vcc_attach(vcc, (void __user *)arg);
1432 break; 1498 break;
1433 default: 1499 default:
1434 break; 1500 break;
1435 } 1501 }
1436 return err; 1502 return err;
1437} 1503}
1438 1504
1439
1440static struct atm_ioctl atm_ioctl_ops = { 1505static struct atm_ioctl atm_ioctl_ops = {
1441 .owner = THIS_MODULE, 1506 .owner = THIS_MODULE,
1442 .ioctl = atm_mpoa_ioctl, 1507 .ioctl = atm_mpoa_ioctl,
@@ -1447,9 +1512,9 @@ static __init int atm_mpoa_init(void)
1447 register_atm_ioctl(&atm_ioctl_ops); 1512 register_atm_ioctl(&atm_ioctl_ops);
1448 1513
1449 if (mpc_proc_init() != 0) 1514 if (mpc_proc_init() != 0)
1450 printk(KERN_INFO "mpoa: failed to initialize /proc/mpoa\n"); 1515 pr_info("failed to initialize /proc/mpoa\n");
1451 1516
1452 printk("mpc.c: " __DATE__ " " __TIME__ " initialized\n"); 1517 pr_info("mpc.c: " __DATE__ " " __TIME__ " initialized\n");
1453 1518
1454 return 0; 1519 return 0;
1455} 1520}
@@ -1476,15 +1541,15 @@ static void __exit atm_mpoa_cleanup(void)
1476 if (priv->lane2_ops != NULL) 1541 if (priv->lane2_ops != NULL)
1477 priv->lane2_ops->associate_indicator = NULL; 1542 priv->lane2_ops->associate_indicator = NULL;
1478 } 1543 }
1479 ddprintk("mpoa: cleanup_module: about to clear caches\n"); 1544 ddprintk("about to clear caches\n");
1480 mpc->in_ops->destroy_cache(mpc); 1545 mpc->in_ops->destroy_cache(mpc);
1481 mpc->eg_ops->destroy_cache(mpc); 1546 mpc->eg_ops->destroy_cache(mpc);
1482 ddprintk("mpoa: cleanup_module: caches cleared\n"); 1547 ddprintk("caches cleared\n");
1483 kfree(mpc->mps_macs); 1548 kfree(mpc->mps_macs);
1484 memset(mpc, 0, sizeof(struct mpoa_client)); 1549 memset(mpc, 0, sizeof(struct mpoa_client));
1485 ddprintk("mpoa: cleanup_module: about to kfree %p\n", mpc); 1550 ddprintk("about to kfree %p\n", mpc);
1486 kfree(mpc); 1551 kfree(mpc);
1487 ddprintk("mpoa: cleanup_module: next mpc is at %p\n", tmp); 1552 ddprintk("next mpc is at %p\n", tmp);
1488 mpc = tmp; 1553 mpc = tmp;
1489 } 1554 }
1490 1555
@@ -1492,7 +1557,7 @@ static void __exit atm_mpoa_cleanup(void)
1492 qos_head = NULL; 1557 qos_head = NULL;
1493 while (qos != NULL) { 1558 while (qos != NULL) {
1494 nextqos = qos->next; 1559 nextqos = qos->next;
1495 dprintk("mpoa: cleanup_module: freeing qos entry %p\n", qos); 1560 dprintk("freeing qos entry %p\n", qos);
1496 kfree(qos); 1561 kfree(qos);
1497 qos = nextqos; 1562 qos = nextqos;
1498 } 1563 }
diff --git a/net/atm/mpoa_caches.c b/net/atm/mpoa_caches.c
index 4504a4b339bb..e773d8336918 100644
--- a/net/atm/mpoa_caches.c
+++ b/net/atm/mpoa_caches.c
@@ -1,5 +1,6 @@
1#include <linux/types.h> 1#include <linux/types.h>
2#include <linux/atmmpc.h> 2#include <linux/atmmpc.h>
3#include <linux/slab.h>
3#include <linux/time.h> 4#include <linux/time.h>
4 5
5#include "mpoa_caches.h" 6#include "mpoa_caches.h"
@@ -11,15 +12,23 @@
11 */ 12 */
12 13
13#if 0 14#if 0
14#define dprintk printk /* debug */ 15#define dprintk(format, args...) \
16 printk(KERN_DEBUG "mpoa:%s: " format, __FILE__, ##args) /* debug */
15#else 17#else
16#define dprintk(format,args...) 18#define dprintk(format, args...) \
19 do { if (0) \
20 printk(KERN_DEBUG "mpoa:%s: " format, __FILE__, ##args);\
21 } while (0)
17#endif 22#endif
18 23
19#if 0 24#if 0
20#define ddprintk printk /* more debug */ 25#define ddprintk(format, args...) \
26 printk(KERN_DEBUG "mpoa:%s: " format, __FILE__, ##args) /* debug */
21#else 27#else
22#define ddprintk(format,args...) 28#define ddprintk(format, args...) \
29 do { if (0) \
30 printk(KERN_DEBUG "mpoa:%s: " format, __FILE__, ##args);\
31 } while (0)
23#endif 32#endif
24 33
25static in_cache_entry *in_cache_get(__be32 dst_ip, 34static in_cache_entry *in_cache_get(__be32 dst_ip,
@@ -29,8 +38,8 @@ static in_cache_entry *in_cache_get(__be32 dst_ip,
29 38
30 read_lock_bh(&client->ingress_lock); 39 read_lock_bh(&client->ingress_lock);
31 entry = client->in_cache; 40 entry = client->in_cache;
32 while(entry != NULL){ 41 while (entry != NULL) {
33 if( entry->ctrl_info.in_dst_ip == dst_ip ){ 42 if (entry->ctrl_info.in_dst_ip == dst_ip) {
34 atomic_inc(&entry->use); 43 atomic_inc(&entry->use);
35 read_unlock_bh(&client->ingress_lock); 44 read_unlock_bh(&client->ingress_lock);
36 return entry; 45 return entry;
@@ -50,8 +59,8 @@ static in_cache_entry *in_cache_get_with_mask(__be32 dst_ip,
50 59
51 read_lock_bh(&client->ingress_lock); 60 read_lock_bh(&client->ingress_lock);
52 entry = client->in_cache; 61 entry = client->in_cache;
53 while(entry != NULL){ 62 while (entry != NULL) {
54 if((entry->ctrl_info.in_dst_ip & mask) == (dst_ip & mask )){ 63 if ((entry->ctrl_info.in_dst_ip & mask) == (dst_ip & mask)) {
55 atomic_inc(&entry->use); 64 atomic_inc(&entry->use);
56 read_unlock_bh(&client->ingress_lock); 65 read_unlock_bh(&client->ingress_lock);
57 return entry; 66 return entry;
@@ -65,14 +74,14 @@ static in_cache_entry *in_cache_get_with_mask(__be32 dst_ip,
65} 74}
66 75
67static in_cache_entry *in_cache_get_by_vcc(struct atm_vcc *vcc, 76static in_cache_entry *in_cache_get_by_vcc(struct atm_vcc *vcc,
68 struct mpoa_client *client ) 77 struct mpoa_client *client)
69{ 78{
70 in_cache_entry *entry; 79 in_cache_entry *entry;
71 80
72 read_lock_bh(&client->ingress_lock); 81 read_lock_bh(&client->ingress_lock);
73 entry = client->in_cache; 82 entry = client->in_cache;
74 while(entry != NULL){ 83 while (entry != NULL) {
75 if(entry->shortcut == vcc) { 84 if (entry->shortcut == vcc) {
76 atomic_inc(&entry->use); 85 atomic_inc(&entry->use);
77 read_unlock_bh(&client->ingress_lock); 86 read_unlock_bh(&client->ingress_lock);
78 return entry; 87 return entry;
@@ -90,14 +99,14 @@ static in_cache_entry *in_cache_add_entry(__be32 dst_ip,
90 in_cache_entry *entry = kzalloc(sizeof(in_cache_entry), GFP_KERNEL); 99 in_cache_entry *entry = kzalloc(sizeof(in_cache_entry), GFP_KERNEL);
91 100
92 if (entry == NULL) { 101 if (entry == NULL) {
93 printk("mpoa: mpoa_caches.c: new_in_cache_entry: out of memory\n"); 102 pr_info("mpoa: mpoa_caches.c: new_in_cache_entry: out of memory\n");
94 return NULL; 103 return NULL;
95 } 104 }
96 105
97 dprintk("mpoa: mpoa_caches.c: adding an ingress entry, ip = %pI4\n", &dst_ip); 106 dprintk("adding an ingress entry, ip = %pI4\n", &dst_ip);
98 107
99 atomic_set(&entry->use, 1); 108 atomic_set(&entry->use, 1);
100 dprintk("mpoa: mpoa_caches.c: new_in_cache_entry: about to lock\n"); 109 dprintk("new_in_cache_entry: about to lock\n");
101 write_lock_bh(&client->ingress_lock); 110 write_lock_bh(&client->ingress_lock);
102 entry->next = client->in_cache; 111 entry->next = client->in_cache;
103 entry->prev = NULL; 112 entry->prev = NULL;
@@ -115,7 +124,7 @@ static in_cache_entry *in_cache_add_entry(__be32 dst_ip,
115 atomic_inc(&entry->use); 124 atomic_inc(&entry->use);
116 125
117 write_unlock_bh(&client->ingress_lock); 126 write_unlock_bh(&client->ingress_lock);
118 dprintk("mpoa: mpoa_caches.c: new_in_cache_entry: unlocked\n"); 127 dprintk("new_in_cache_entry: unlocked\n");
119 128
120 return entry; 129 return entry;
121} 130}
@@ -126,39 +135,41 @@ static int cache_hit(in_cache_entry *entry, struct mpoa_client *mpc)
126 struct k_message msg; 135 struct k_message msg;
127 136
128 entry->count++; 137 entry->count++;
129 if(entry->entry_state == INGRESS_RESOLVED && entry->shortcut != NULL) 138 if (entry->entry_state == INGRESS_RESOLVED && entry->shortcut != NULL)
130 return OPEN; 139 return OPEN;
131 140
132 if(entry->entry_state == INGRESS_REFRESHING){ 141 if (entry->entry_state == INGRESS_REFRESHING) {
133 if(entry->count > mpc->parameters.mpc_p1){ 142 if (entry->count > mpc->parameters.mpc_p1) {
134 msg.type = SND_MPOA_RES_RQST; 143 msg.type = SND_MPOA_RES_RQST;
135 msg.content.in_info = entry->ctrl_info; 144 msg.content.in_info = entry->ctrl_info;
136 memcpy(msg.MPS_ctrl, mpc->mps_ctrl_addr, ATM_ESA_LEN); 145 memcpy(msg.MPS_ctrl, mpc->mps_ctrl_addr, ATM_ESA_LEN);
137 qos = atm_mpoa_search_qos(entry->ctrl_info.in_dst_ip); 146 qos = atm_mpoa_search_qos(entry->ctrl_info.in_dst_ip);
138 if (qos != NULL) msg.qos = qos->qos; 147 if (qos != NULL)
148 msg.qos = qos->qos;
139 msg_to_mpoad(&msg, mpc); 149 msg_to_mpoad(&msg, mpc);
140 do_gettimeofday(&(entry->reply_wait)); 150 do_gettimeofday(&(entry->reply_wait));
141 entry->entry_state = INGRESS_RESOLVING; 151 entry->entry_state = INGRESS_RESOLVING;
142 } 152 }
143 if(entry->shortcut != NULL) 153 if (entry->shortcut != NULL)
144 return OPEN; 154 return OPEN;
145 return CLOSED; 155 return CLOSED;
146 } 156 }
147 157
148 if(entry->entry_state == INGRESS_RESOLVING && entry->shortcut != NULL) 158 if (entry->entry_state == INGRESS_RESOLVING && entry->shortcut != NULL)
149 return OPEN; 159 return OPEN;
150 160
151 if( entry->count > mpc->parameters.mpc_p1 && 161 if (entry->count > mpc->parameters.mpc_p1 &&
152 entry->entry_state == INGRESS_INVALID){ 162 entry->entry_state == INGRESS_INVALID) {
153 dprintk("mpoa: (%s) mpoa_caches.c: threshold exceeded for ip %pI4, sending MPOA res req\n", 163 dprintk("(%s) threshold exceeded for ip %pI4, sending MPOA res req\n",
154 mpc->dev->name, &entry->ctrl_info.in_dst_ip); 164 mpc->dev->name, &entry->ctrl_info.in_dst_ip);
155 entry->entry_state = INGRESS_RESOLVING; 165 entry->entry_state = INGRESS_RESOLVING;
156 msg.type = SND_MPOA_RES_RQST; 166 msg.type = SND_MPOA_RES_RQST;
157 memcpy(msg.MPS_ctrl, mpc->mps_ctrl_addr, ATM_ESA_LEN ); 167 memcpy(msg.MPS_ctrl, mpc->mps_ctrl_addr, ATM_ESA_LEN);
158 msg.content.in_info = entry->ctrl_info; 168 msg.content.in_info = entry->ctrl_info;
159 qos = atm_mpoa_search_qos(entry->ctrl_info.in_dst_ip); 169 qos = atm_mpoa_search_qos(entry->ctrl_info.in_dst_ip);
160 if (qos != NULL) msg.qos = qos->qos; 170 if (qos != NULL)
161 msg_to_mpoad( &msg, mpc); 171 msg.qos = qos->qos;
172 msg_to_mpoad(&msg, mpc);
162 do_gettimeofday(&(entry->reply_wait)); 173 do_gettimeofday(&(entry->reply_wait));
163 } 174 }
164 175
@@ -185,7 +196,7 @@ static void in_cache_remove_entry(in_cache_entry *entry,
185 struct k_message msg; 196 struct k_message msg;
186 197
187 vcc = entry->shortcut; 198 vcc = entry->shortcut;
188 dprintk("mpoa: mpoa_caches.c: removing an ingress entry, ip = %pI4\n", 199 dprintk("removing an ingress entry, ip = %pI4\n",
189 &entry->ctrl_info.in_dst_ip); 200 &entry->ctrl_info.in_dst_ip);
190 201
191 if (entry->prev != NULL) 202 if (entry->prev != NULL)
@@ -195,14 +206,15 @@ static void in_cache_remove_entry(in_cache_entry *entry,
195 if (entry->next != NULL) 206 if (entry->next != NULL)
196 entry->next->prev = entry->prev; 207 entry->next->prev = entry->prev;
197 client->in_ops->put(entry); 208 client->in_ops->put(entry);
198 if(client->in_cache == NULL && client->eg_cache == NULL){ 209 if (client->in_cache == NULL && client->eg_cache == NULL) {
199 msg.type = STOP_KEEP_ALIVE_SM; 210 msg.type = STOP_KEEP_ALIVE_SM;
200 msg_to_mpoad(&msg,client); 211 msg_to_mpoad(&msg, client);
201 } 212 }
202 213
203 /* Check if the egress side still uses this VCC */ 214 /* Check if the egress side still uses this VCC */
204 if (vcc != NULL) { 215 if (vcc != NULL) {
205 eg_cache_entry *eg_entry = client->eg_ops->get_by_vcc(vcc, client); 216 eg_cache_entry *eg_entry = client->eg_ops->get_by_vcc(vcc,
217 client);
206 if (eg_entry != NULL) { 218 if (eg_entry != NULL) {
207 client->eg_ops->put(eg_entry); 219 client->eg_ops->put(eg_entry);
208 return; 220 return;
@@ -213,7 +225,6 @@ static void in_cache_remove_entry(in_cache_entry *entry,
213 return; 225 return;
214} 226}
215 227
216
217/* Call this every MPC-p2 seconds... Not exactly correct solution, 228/* Call this every MPC-p2 seconds... Not exactly correct solution,
218 but an easy one... */ 229 but an easy one... */
219static void clear_count_and_expired(struct mpoa_client *client) 230static void clear_count_and_expired(struct mpoa_client *client)
@@ -225,12 +236,12 @@ static void clear_count_and_expired(struct mpoa_client *client)
225 236
226 write_lock_bh(&client->ingress_lock); 237 write_lock_bh(&client->ingress_lock);
227 entry = client->in_cache; 238 entry = client->in_cache;
228 while(entry != NULL){ 239 while (entry != NULL) {
229 entry->count=0; 240 entry->count = 0;
230 next_entry = entry->next; 241 next_entry = entry->next;
231 if((now.tv_sec - entry->tv.tv_sec) 242 if ((now.tv_sec - entry->tv.tv_sec)
232 > entry->ctrl_info.holding_time){ 243 > entry->ctrl_info.holding_time) {
233 dprintk("mpoa: mpoa_caches.c: holding time expired, ip = %pI4\n", 244 dprintk("holding time expired, ip = %pI4\n",
234 &entry->ctrl_info.in_dst_ip); 245 &entry->ctrl_info.in_dst_ip);
235 client->in_ops->remove_entry(entry, client); 246 client->in_ops->remove_entry(entry, client);
236 } 247 }
@@ -250,33 +261,38 @@ static void check_resolving_entries(struct mpoa_client *client)
250 struct timeval now; 261 struct timeval now;
251 struct k_message msg; 262 struct k_message msg;
252 263
253 do_gettimeofday( &now ); 264 do_gettimeofday(&now);
254 265
255 read_lock_bh(&client->ingress_lock); 266 read_lock_bh(&client->ingress_lock);
256 entry = client->in_cache; 267 entry = client->in_cache;
257 while( entry != NULL ){ 268 while (entry != NULL) {
258 if(entry->entry_state == INGRESS_RESOLVING){ 269 if (entry->entry_state == INGRESS_RESOLVING) {
259 if(now.tv_sec - entry->hold_down.tv_sec < client->parameters.mpc_p6){ 270 if ((now.tv_sec - entry->hold_down.tv_sec) <
260 entry = entry->next; /* Entry in hold down */ 271 client->parameters.mpc_p6) {
272 entry = entry->next; /* Entry in hold down */
261 continue; 273 continue;
262 } 274 }
263 if( (now.tv_sec - entry->reply_wait.tv_sec) > 275 if ((now.tv_sec - entry->reply_wait.tv_sec) >
264 entry->retry_time ){ 276 entry->retry_time) {
265 entry->retry_time = MPC_C1*( entry->retry_time ); 277 entry->retry_time = MPC_C1 * (entry->retry_time);
266 if(entry->retry_time > client->parameters.mpc_p5){ 278 /*
267 /* Retry time maximum exceeded, put entry in hold down. */ 279 * Retry time maximum exceeded,
280 * put entry in hold down.
281 */
282 if (entry->retry_time > client->parameters.mpc_p5) {
268 do_gettimeofday(&(entry->hold_down)); 283 do_gettimeofday(&(entry->hold_down));
269 entry->retry_time = client->parameters.mpc_p4; 284 entry->retry_time = client->parameters.mpc_p4;
270 entry = entry->next; 285 entry = entry->next;
271 continue; 286 continue;
272 } 287 }
273 /* Ask daemon to send a resolution request. */ 288 /* Ask daemon to send a resolution request. */
274 memset(&(entry->hold_down),0,sizeof(struct timeval)); 289 memset(&(entry->hold_down), 0, sizeof(struct timeval));
275 msg.type = SND_MPOA_RES_RTRY; 290 msg.type = SND_MPOA_RES_RTRY;
276 memcpy(msg.MPS_ctrl, client->mps_ctrl_addr, ATM_ESA_LEN); 291 memcpy(msg.MPS_ctrl, client->mps_ctrl_addr, ATM_ESA_LEN);
277 msg.content.in_info = entry->ctrl_info; 292 msg.content.in_info = entry->ctrl_info;
278 qos = atm_mpoa_search_qos(entry->ctrl_info.in_dst_ip); 293 qos = atm_mpoa_search_qos(entry->ctrl_info.in_dst_ip);
279 if (qos != NULL) msg.qos = qos->qos; 294 if (qos != NULL)
295 msg.qos = qos->qos;
280 msg_to_mpoad(&msg, client); 296 msg_to_mpoad(&msg, client);
281 do_gettimeofday(&(entry->reply_wait)); 297 do_gettimeofday(&(entry->reply_wait));
282 } 298 }
@@ -292,16 +308,17 @@ static void refresh_entries(struct mpoa_client *client)
292 struct timeval now; 308 struct timeval now;
293 struct in_cache_entry *entry = client->in_cache; 309 struct in_cache_entry *entry = client->in_cache;
294 310
295 ddprintk("mpoa: mpoa_caches.c: refresh_entries\n"); 311 ddprintk("refresh_entries\n");
296 do_gettimeofday(&now); 312 do_gettimeofday(&now);
297 313
298 read_lock_bh(&client->ingress_lock); 314 read_lock_bh(&client->ingress_lock);
299 while( entry != NULL ){ 315 while (entry != NULL) {
300 if( entry->entry_state == INGRESS_RESOLVED ){ 316 if (entry->entry_state == INGRESS_RESOLVED) {
301 if(!(entry->refresh_time)) 317 if (!(entry->refresh_time))
302 entry->refresh_time = (2*(entry->ctrl_info.holding_time))/3; 318 entry->refresh_time = (2 * (entry->ctrl_info.holding_time))/3;
303 if( (now.tv_sec - entry->reply_wait.tv_sec) > entry->refresh_time ){ 319 if ((now.tv_sec - entry->reply_wait.tv_sec) >
304 dprintk("mpoa: mpoa_caches.c: refreshing an entry.\n"); 320 entry->refresh_time) {
321 dprintk("refreshing an entry.\n");
305 entry->entry_state = INGRESS_REFRESHING; 322 entry->entry_state = INGRESS_REFRESHING;
306 323
307 } 324 }
@@ -314,21 +331,22 @@ static void refresh_entries(struct mpoa_client *client)
314static void in_destroy_cache(struct mpoa_client *mpc) 331static void in_destroy_cache(struct mpoa_client *mpc)
315{ 332{
316 write_lock_irq(&mpc->ingress_lock); 333 write_lock_irq(&mpc->ingress_lock);
317 while(mpc->in_cache != NULL) 334 while (mpc->in_cache != NULL)
318 mpc->in_ops->remove_entry(mpc->in_cache, mpc); 335 mpc->in_ops->remove_entry(mpc->in_cache, mpc);
319 write_unlock_irq(&mpc->ingress_lock); 336 write_unlock_irq(&mpc->ingress_lock);
320 337
321 return; 338 return;
322} 339}
323 340
324static eg_cache_entry *eg_cache_get_by_cache_id(__be32 cache_id, struct mpoa_client *mpc) 341static eg_cache_entry *eg_cache_get_by_cache_id(__be32 cache_id,
342 struct mpoa_client *mpc)
325{ 343{
326 eg_cache_entry *entry; 344 eg_cache_entry *entry;
327 345
328 read_lock_irq(&mpc->egress_lock); 346 read_lock_irq(&mpc->egress_lock);
329 entry = mpc->eg_cache; 347 entry = mpc->eg_cache;
330 while(entry != NULL){ 348 while (entry != NULL) {
331 if(entry->ctrl_info.cache_id == cache_id){ 349 if (entry->ctrl_info.cache_id == cache_id) {
332 atomic_inc(&entry->use); 350 atomic_inc(&entry->use);
333 read_unlock_irq(&mpc->egress_lock); 351 read_unlock_irq(&mpc->egress_lock);
334 return entry; 352 return entry;
@@ -348,7 +366,7 @@ static eg_cache_entry *eg_cache_get_by_tag(__be32 tag, struct mpoa_client *mpc)
348 366
349 read_lock_irqsave(&mpc->egress_lock, flags); 367 read_lock_irqsave(&mpc->egress_lock, flags);
350 entry = mpc->eg_cache; 368 entry = mpc->eg_cache;
351 while (entry != NULL){ 369 while (entry != NULL) {
352 if (entry->ctrl_info.tag == tag) { 370 if (entry->ctrl_info.tag == tag) {
353 atomic_inc(&entry->use); 371 atomic_inc(&entry->use);
354 read_unlock_irqrestore(&mpc->egress_lock, flags); 372 read_unlock_irqrestore(&mpc->egress_lock, flags);
@@ -362,14 +380,15 @@ static eg_cache_entry *eg_cache_get_by_tag(__be32 tag, struct mpoa_client *mpc)
362} 380}
363 381
364/* This can be called from any context since it saves CPU flags */ 382/* This can be called from any context since it saves CPU flags */
365static eg_cache_entry *eg_cache_get_by_vcc(struct atm_vcc *vcc, struct mpoa_client *mpc) 383static eg_cache_entry *eg_cache_get_by_vcc(struct atm_vcc *vcc,
384 struct mpoa_client *mpc)
366{ 385{
367 unsigned long flags; 386 unsigned long flags;
368 eg_cache_entry *entry; 387 eg_cache_entry *entry;
369 388
370 read_lock_irqsave(&mpc->egress_lock, flags); 389 read_lock_irqsave(&mpc->egress_lock, flags);
371 entry = mpc->eg_cache; 390 entry = mpc->eg_cache;
372 while (entry != NULL){ 391 while (entry != NULL) {
373 if (entry->shortcut == vcc) { 392 if (entry->shortcut == vcc) {
374 atomic_inc(&entry->use); 393 atomic_inc(&entry->use);
375 read_unlock_irqrestore(&mpc->egress_lock, flags); 394 read_unlock_irqrestore(&mpc->egress_lock, flags);
@@ -382,14 +401,15 @@ static eg_cache_entry *eg_cache_get_by_vcc(struct atm_vcc *vcc, struct mpoa_clie
382 return NULL; 401 return NULL;
383} 402}
384 403
385static eg_cache_entry *eg_cache_get_by_src_ip(__be32 ipaddr, struct mpoa_client *mpc) 404static eg_cache_entry *eg_cache_get_by_src_ip(__be32 ipaddr,
405 struct mpoa_client *mpc)
386{ 406{
387 eg_cache_entry *entry; 407 eg_cache_entry *entry;
388 408
389 read_lock_irq(&mpc->egress_lock); 409 read_lock_irq(&mpc->egress_lock);
390 entry = mpc->eg_cache; 410 entry = mpc->eg_cache;
391 while(entry != NULL){ 411 while (entry != NULL) {
392 if(entry->latest_ip_addr == ipaddr) { 412 if (entry->latest_ip_addr == ipaddr) {
393 atomic_inc(&entry->use); 413 atomic_inc(&entry->use);
394 read_unlock_irq(&mpc->egress_lock); 414 read_unlock_irq(&mpc->egress_lock);
395 return entry; 415 return entry;
@@ -421,7 +441,7 @@ static void eg_cache_remove_entry(eg_cache_entry *entry,
421 struct k_message msg; 441 struct k_message msg;
422 442
423 vcc = entry->shortcut; 443 vcc = entry->shortcut;
424 dprintk("mpoa: mpoa_caches.c: removing an egress entry.\n"); 444 dprintk("removing an egress entry.\n");
425 if (entry->prev != NULL) 445 if (entry->prev != NULL)
426 entry->prev->next = entry->next; 446 entry->prev->next = entry->next;
427 else 447 else
@@ -429,9 +449,9 @@ static void eg_cache_remove_entry(eg_cache_entry *entry,
429 if (entry->next != NULL) 449 if (entry->next != NULL)
430 entry->next->prev = entry->prev; 450 entry->next->prev = entry->prev;
431 client->eg_ops->put(entry); 451 client->eg_ops->put(entry);
432 if(client->in_cache == NULL && client->eg_cache == NULL){ 452 if (client->in_cache == NULL && client->eg_cache == NULL) {
433 msg.type = STOP_KEEP_ALIVE_SM; 453 msg.type = STOP_KEEP_ALIVE_SM;
434 msg_to_mpoad(&msg,client); 454 msg_to_mpoad(&msg, client);
435 } 455 }
436 456
437 /* Check if the ingress side still uses this VCC */ 457 /* Check if the ingress side still uses this VCC */
@@ -447,20 +467,21 @@ static void eg_cache_remove_entry(eg_cache_entry *entry,
447 return; 467 return;
448} 468}
449 469
450static eg_cache_entry *eg_cache_add_entry(struct k_message *msg, struct mpoa_client *client) 470static eg_cache_entry *eg_cache_add_entry(struct k_message *msg,
471 struct mpoa_client *client)
451{ 472{
452 eg_cache_entry *entry = kzalloc(sizeof(eg_cache_entry), GFP_KERNEL); 473 eg_cache_entry *entry = kzalloc(sizeof(eg_cache_entry), GFP_KERNEL);
453 474
454 if (entry == NULL) { 475 if (entry == NULL) {
455 printk("mpoa: mpoa_caches.c: new_eg_cache_entry: out of memory\n"); 476 pr_info("out of memory\n");
456 return NULL; 477 return NULL;
457 } 478 }
458 479
459 dprintk("mpoa: mpoa_caches.c: adding an egress entry, ip = %pI4, this should be our IP\n", 480 dprintk("adding an egress entry, ip = %pI4, this should be our IP\n",
460 &msg->content.eg_info.eg_dst_ip); 481 &msg->content.eg_info.eg_dst_ip);
461 482
462 atomic_set(&entry->use, 1); 483 atomic_set(&entry->use, 1);
463 dprintk("mpoa: mpoa_caches.c: new_eg_cache_entry: about to lock\n"); 484 dprintk("new_eg_cache_entry: about to lock\n");
464 write_lock_irq(&client->egress_lock); 485 write_lock_irq(&client->egress_lock);
465 entry->next = client->eg_cache; 486 entry->next = client->eg_cache;
466 entry->prev = NULL; 487 entry->prev = NULL;
@@ -472,18 +493,18 @@ static eg_cache_entry *eg_cache_add_entry(struct k_message *msg, struct mpoa_cli
472 entry->ctrl_info = msg->content.eg_info; 493 entry->ctrl_info = msg->content.eg_info;
473 do_gettimeofday(&(entry->tv)); 494 do_gettimeofday(&(entry->tv));
474 entry->entry_state = EGRESS_RESOLVED; 495 entry->entry_state = EGRESS_RESOLVED;
475 dprintk("mpoa: mpoa_caches.c: new_eg_cache_entry cache_id %lu\n", ntohl(entry->ctrl_info.cache_id)); 496 dprintk("new_eg_cache_entry cache_id %u\n",
476 dprintk("mpoa: mpoa_caches.c: mps_ip = %pI4\n", 497 ntohl(entry->ctrl_info.cache_id));
477 &entry->ctrl_info.mps_ip); 498 dprintk("mps_ip = %pI4\n", &entry->ctrl_info.mps_ip);
478 atomic_inc(&entry->use); 499 atomic_inc(&entry->use);
479 500
480 write_unlock_irq(&client->egress_lock); 501 write_unlock_irq(&client->egress_lock);
481 dprintk("mpoa: mpoa_caches.c: new_eg_cache_entry: unlocked\n"); 502 dprintk("new_eg_cache_entry: unlocked\n");
482 503
483 return entry; 504 return entry;
484} 505}
485 506
486static void update_eg_cache_entry(eg_cache_entry * entry, uint16_t holding_time) 507static void update_eg_cache_entry(eg_cache_entry *entry, uint16_t holding_time)
487{ 508{
488 do_gettimeofday(&(entry->tv)); 509 do_gettimeofday(&(entry->tv));
489 entry->entry_state = EGRESS_RESOLVED; 510 entry->entry_state = EGRESS_RESOLVED;
@@ -502,13 +523,14 @@ static void clear_expired(struct mpoa_client *client)
502 523
503 write_lock_irq(&client->egress_lock); 524 write_lock_irq(&client->egress_lock);
504 entry = client->eg_cache; 525 entry = client->eg_cache;
505 while(entry != NULL){ 526 while (entry != NULL) {
506 next_entry = entry->next; 527 next_entry = entry->next;
507 if((now.tv_sec - entry->tv.tv_sec) 528 if ((now.tv_sec - entry->tv.tv_sec)
508 > entry->ctrl_info.holding_time){ 529 > entry->ctrl_info.holding_time) {
509 msg.type = SND_EGRESS_PURGE; 530 msg.type = SND_EGRESS_PURGE;
510 msg.content.eg_info = entry->ctrl_info; 531 msg.content.eg_info = entry->ctrl_info;
511 dprintk("mpoa: mpoa_caches.c: egress_cache: holding time expired, cache_id = %lu.\n",ntohl(entry->ctrl_info.cache_id)); 532 dprintk("egress_cache: holding time expired, cache_id = %u.\n",
533 ntohl(entry->ctrl_info.cache_id));
512 msg_to_mpoad(&msg, client); 534 msg_to_mpoad(&msg, client);
513 client->eg_ops->remove_entry(entry, client); 535 client->eg_ops->remove_entry(entry, client);
514 } 536 }
@@ -522,7 +544,7 @@ static void clear_expired(struct mpoa_client *client)
522static void eg_destroy_cache(struct mpoa_client *mpc) 544static void eg_destroy_cache(struct mpoa_client *mpc)
523{ 545{
524 write_lock_irq(&mpc->egress_lock); 546 write_lock_irq(&mpc->egress_lock);
525 while(mpc->eg_cache != NULL) 547 while (mpc->eg_cache != NULL)
526 mpc->eg_ops->remove_entry(mpc->eg_cache, mpc); 548 mpc->eg_ops->remove_entry(mpc->eg_cache, mpc);
527 write_unlock_irq(&mpc->egress_lock); 549 write_unlock_irq(&mpc->egress_lock);
528 550
@@ -530,7 +552,6 @@ static void eg_destroy_cache(struct mpoa_client *mpc)
530} 552}
531 553
532 554
533
534static struct in_cache_ops ingress_ops = { 555static struct in_cache_ops ingress_ops = {
535 in_cache_add_entry, /* add_entry */ 556 in_cache_add_entry, /* add_entry */
536 in_cache_get, /* get */ 557 in_cache_get, /* get */
diff --git a/net/atm/mpoa_proc.c b/net/atm/mpoa_proc.c
index 1a0f5ccea9c4..53e500292271 100644
--- a/net/atm/mpoa_proc.c
+++ b/net/atm/mpoa_proc.c
@@ -1,3 +1,4 @@
1#define pr_fmt(fmt) KBUILD_MODNAME ":%s: " fmt, __func__
1 2
2#ifdef CONFIG_PROC_FS 3#ifdef CONFIG_PROC_FS
3#include <linux/errno.h> 4#include <linux/errno.h>
@@ -8,9 +9,10 @@
8#include <linux/proc_fs.h> 9#include <linux/proc_fs.h>
9#include <linux/time.h> 10#include <linux/time.h>
10#include <linux/seq_file.h> 11#include <linux/seq_file.h>
11#include <asm/uaccess.h> 12#include <linux/uaccess.h>
12#include <linux/atmmpc.h> 13#include <linux/atmmpc.h>
13#include <linux/atm.h> 14#include <linux/atm.h>
15#include <linux/gfp.h>
14#include "mpc.h" 16#include "mpc.h"
15#include "mpoa_caches.h" 17#include "mpoa_caches.h"
16 18
@@ -20,9 +22,23 @@
20 */ 22 */
21 23
22#if 1 24#if 1
23#define dprintk printk /* debug */ 25#define dprintk(format, args...) \
26 printk(KERN_DEBUG "mpoa:%s: " format, __FILE__, ##args) /* debug */
24#else 27#else
25#define dprintk(format,args...) 28#define dprintk(format, args...) \
29 do { if (0) \
30 printk(KERN_DEBUG "mpoa:%s: " format, __FILE__, ##args);\
31 } while (0)
32#endif
33
34#if 0
35#define ddprintk(format, args...) \
36 printk(KERN_DEBUG "mpoa:%s: " format, __FILE__, ##args) /* debug */
37#else
38#define ddprintk(format, args...) \
39 do { if (0) \
40 printk(KERN_DEBUG "mpoa:%s: " format, __FILE__, ##args);\
41 } while (0)
26#endif 42#endif
27 43
28#define STAT_FILE_NAME "mpc" /* Our statistic file's name */ 44#define STAT_FILE_NAME "mpc" /* Our statistic file's name */
@@ -51,42 +67,37 @@ static const struct file_operations mpc_file_operations = {
51/* 67/*
52 * Returns the state of an ingress cache entry as a string 68 * Returns the state of an ingress cache entry as a string
53 */ 69 */
54static const char *ingress_state_string(int state){ 70static const char *ingress_state_string(int state)
55 switch(state) { 71{
72 switch (state) {
56 case INGRESS_RESOLVING: 73 case INGRESS_RESOLVING:
57 return "resolving "; 74 return "resolving ";
58 break;
59 case INGRESS_RESOLVED: 75 case INGRESS_RESOLVED:
60 return "resolved "; 76 return "resolved ";
61 break;
62 case INGRESS_INVALID: 77 case INGRESS_INVALID:
63 return "invalid "; 78 return "invalid ";
64 break;
65 case INGRESS_REFRESHING: 79 case INGRESS_REFRESHING:
66 return "refreshing "; 80 return "refreshing ";
67 break;
68 default:
69 return "";
70 } 81 }
82
83 return "";
71} 84}
72 85
73/* 86/*
74 * Returns the state of an egress cache entry as a string 87 * Returns the state of an egress cache entry as a string
75 */ 88 */
76static const char *egress_state_string(int state){ 89static const char *egress_state_string(int state)
77 switch(state) { 90{
91 switch (state) {
78 case EGRESS_RESOLVED: 92 case EGRESS_RESOLVED:
79 return "resolved "; 93 return "resolved ";
80 break;
81 case EGRESS_PURGE: 94 case EGRESS_PURGE:
82 return "purge "; 95 return "purge ";
83 break;
84 case EGRESS_INVALID: 96 case EGRESS_INVALID:
85 return "invalid "; 97 return "invalid ";
86 break;
87 default:
88 return "";
89 } 98 }
99
100 return "";
90} 101}
91 102
92/* 103/*
@@ -123,7 +134,6 @@ static void mpc_stop(struct seq_file *m, void *v)
123static int mpc_show(struct seq_file *m, void *v) 134static int mpc_show(struct seq_file *m, void *v)
124{ 135{
125 struct mpoa_client *mpc = v; 136 struct mpoa_client *mpc = v;
126 unsigned char *temp;
127 int i; 137 int i;
128 in_cache_entry *in_entry; 138 in_cache_entry *in_entry;
129 eg_cache_entry *eg_entry; 139 eg_cache_entry *eg_entry;
@@ -140,15 +150,17 @@ static int mpc_show(struct seq_file *m, void *v)
140 do_gettimeofday(&now); 150 do_gettimeofday(&now);
141 151
142 for (in_entry = mpc->in_cache; in_entry; in_entry = in_entry->next) { 152 for (in_entry = mpc->in_cache; in_entry; in_entry = in_entry->next) {
143 temp = (unsigned char *)&in_entry->ctrl_info.in_dst_ip; 153 sprintf(ip_string, "%pI4", &in_entry->ctrl_info.in_dst_ip);
144 sprintf(ip_string,"%d.%d.%d.%d", temp[0], temp[1], temp[2], temp[3]);
145 seq_printf(m, "%-16s%s%-14lu%-12u", 154 seq_printf(m, "%-16s%s%-14lu%-12u",
146 ip_string, 155 ip_string,
147 ingress_state_string(in_entry->entry_state), 156 ingress_state_string(in_entry->entry_state),
148 in_entry->ctrl_info.holding_time-(now.tv_sec-in_entry->tv.tv_sec), 157 in_entry->ctrl_info.holding_time -
149 in_entry->packets_fwded); 158 (now.tv_sec-in_entry->tv.tv_sec),
159 in_entry->packets_fwded);
150 if (in_entry->shortcut) 160 if (in_entry->shortcut)
151 seq_printf(m, " %-3d %-3d",in_entry->shortcut->vpi,in_entry->shortcut->vci); 161 seq_printf(m, " %-3d %-3d",
162 in_entry->shortcut->vpi,
163 in_entry->shortcut->vci);
152 seq_printf(m, "\n"); 164 seq_printf(m, "\n");
153 } 165 }
154 166
@@ -156,21 +168,23 @@ static int mpc_show(struct seq_file *m, void *v)
156 seq_printf(m, "Egress Entries:\nIngress MPC ATM addr\nCache-id State Holding time Packets recvd Latest IP addr VPI VCI\n"); 168 seq_printf(m, "Egress Entries:\nIngress MPC ATM addr\nCache-id State Holding time Packets recvd Latest IP addr VPI VCI\n");
157 for (eg_entry = mpc->eg_cache; eg_entry; eg_entry = eg_entry->next) { 169 for (eg_entry = mpc->eg_cache; eg_entry; eg_entry = eg_entry->next) {
158 unsigned char *p = eg_entry->ctrl_info.in_MPC_data_ATM_addr; 170 unsigned char *p = eg_entry->ctrl_info.in_MPC_data_ATM_addr;
159 for(i = 0; i < ATM_ESA_LEN; i++) 171 for (i = 0; i < ATM_ESA_LEN; i++)
160 seq_printf(m, "%02x", p[i]); 172 seq_printf(m, "%02x", p[i]);
161 seq_printf(m, "\n%-16lu%s%-14lu%-15u", 173 seq_printf(m, "\n%-16lu%s%-14lu%-15u",
162 (unsigned long)ntohl(eg_entry->ctrl_info.cache_id), 174 (unsigned long)ntohl(eg_entry->ctrl_info.cache_id),
163 egress_state_string(eg_entry->entry_state), 175 egress_state_string(eg_entry->entry_state),
164 (eg_entry->ctrl_info.holding_time-(now.tv_sec-eg_entry->tv.tv_sec)), 176 (eg_entry->ctrl_info.holding_time -
177 (now.tv_sec-eg_entry->tv.tv_sec)),
165 eg_entry->packets_rcvd); 178 eg_entry->packets_rcvd);
166 179
167 /* latest IP address */ 180 /* latest IP address */
168 temp = (unsigned char *)&eg_entry->latest_ip_addr; 181 sprintf(ip_string, "%pI4", &eg_entry->latest_ip_addr);
169 sprintf(ip_string, "%d.%d.%d.%d", temp[0], temp[1], temp[2], temp[3]);
170 seq_printf(m, "%-16s", ip_string); 182 seq_printf(m, "%-16s", ip_string);
171 183
172 if (eg_entry->shortcut) 184 if (eg_entry->shortcut)
173 seq_printf(m, " %-3d %-3d",eg_entry->shortcut->vpi,eg_entry->shortcut->vci); 185 seq_printf(m, " %-3d %-3d",
186 eg_entry->shortcut->vpi,
187 eg_entry->shortcut->vci);
174 seq_printf(m, "\n"); 188 seq_printf(m, "\n");
175 } 189 }
176 seq_printf(m, "\n"); 190 seq_printf(m, "\n");
@@ -258,12 +272,9 @@ static int parse_qos(const char *buff)
258 qos.rxtp.max_pcr = rx_pcr; 272 qos.rxtp.max_pcr = rx_pcr;
259 qos.rxtp.max_sdu = rx_sdu; 273 qos.rxtp.max_sdu = rx_sdu;
260 qos.aal = ATM_AAL5; 274 qos.aal = ATM_AAL5;
261 dprintk("mpoa: mpoa_proc.c: parse_qos(): setting qos paramameters to tx=%d,%d rx=%d,%d\n", 275 dprintk("parse_qos(): setting qos paramameters to tx=%d,%d rx=%d,%d\n",
262 qos.txtp.max_pcr, 276 qos.txtp.max_pcr, qos.txtp.max_sdu,
263 qos.txtp.max_sdu, 277 qos.rxtp.max_pcr, qos.rxtp.max_sdu);
264 qos.rxtp.max_pcr,
265 qos.rxtp.max_sdu
266 );
267 278
268 atm_mpoa_add_qos(ipaddr, &qos); 279 atm_mpoa_add_qos(ipaddr, &qos);
269 return 1; 280 return 1;
@@ -278,7 +289,7 @@ int mpc_proc_init(void)
278 289
279 p = proc_create(STAT_FILE_NAME, 0, atm_proc_root, &mpc_file_operations); 290 p = proc_create(STAT_FILE_NAME, 0, atm_proc_root, &mpc_file_operations);
280 if (!p) { 291 if (!p) {
281 printk(KERN_ERR "Unable to initialize /proc/atm/%s\n", STAT_FILE_NAME); 292 pr_err("Unable to initialize /proc/atm/%s\n", STAT_FILE_NAME);
282 return -ENOMEM; 293 return -ENOMEM;
283 } 294 }
284 return 0; 295 return 0;
@@ -289,10 +300,9 @@ int mpc_proc_init(void)
289 */ 300 */
290void mpc_proc_clean(void) 301void mpc_proc_clean(void)
291{ 302{
292 remove_proc_entry(STAT_FILE_NAME,atm_proc_root); 303 remove_proc_entry(STAT_FILE_NAME, atm_proc_root);
293} 304}
294 305
295
296#endif /* CONFIG_PROC_FS */ 306#endif /* CONFIG_PROC_FS */
297 307
298 308
diff --git a/net/atm/pppoatm.c b/net/atm/pppoatm.c
index 0af84cd4f65b..e49bb6d948a1 100644
--- a/net/atm/pppoatm.c
+++ b/net/atm/pppoatm.c
@@ -33,9 +33,12 @@
33 * These hooks are not yet available in ppp_generic 33 * These hooks are not yet available in ppp_generic
34 */ 34 */
35 35
36#define pr_fmt(fmt) KBUILD_MODNAME ":%s: " fmt, __func__
37
36#include <linux/module.h> 38#include <linux/module.h>
37#include <linux/init.h> 39#include <linux/init.h>
38#include <linux/skbuff.h> 40#include <linux/skbuff.h>
41#include <linux/slab.h>
39#include <linux/atm.h> 42#include <linux/atm.h>
40#include <linux/atmdev.h> 43#include <linux/atmdev.h>
41#include <linux/capability.h> 44#include <linux/capability.h>
@@ -132,7 +135,7 @@ static void pppoatm_unassign_vcc(struct atm_vcc *atmvcc)
132static void pppoatm_push(struct atm_vcc *atmvcc, struct sk_buff *skb) 135static void pppoatm_push(struct atm_vcc *atmvcc, struct sk_buff *skb)
133{ 136{
134 struct pppoatm_vcc *pvcc = atmvcc_to_pvcc(atmvcc); 137 struct pppoatm_vcc *pvcc = atmvcc_to_pvcc(atmvcc);
135 pr_debug("pppoatm push\n"); 138 pr_debug("\n");
136 if (skb == NULL) { /* VCC was closed */ 139 if (skb == NULL) { /* VCC was closed */
137 pr_debug("removing ATMPPP VCC %p\n", pvcc); 140 pr_debug("removing ATMPPP VCC %p\n", pvcc);
138 pppoatm_unassign_vcc(atmvcc); 141 pppoatm_unassign_vcc(atmvcc);
@@ -165,17 +168,17 @@ static void pppoatm_push(struct atm_vcc *atmvcc, struct sk_buff *skb)
165 pvcc->chan.mtu += LLC_LEN; 168 pvcc->chan.mtu += LLC_LEN;
166 break; 169 break;
167 } 170 }
168 pr_debug("Couldn't autodetect yet " 171 pr_debug("Couldn't autodetect yet (skb: %02X %02X %02X %02X %02X %02X)\n",
169 "(skb: %02X %02X %02X %02X %02X %02X)\n", 172 skb->data[0], skb->data[1], skb->data[2],
170 skb->data[0], skb->data[1], skb->data[2], 173 skb->data[3], skb->data[4], skb->data[5]);
171 skb->data[3], skb->data[4], skb->data[5]);
172 goto error; 174 goto error;
173 case e_vc: 175 case e_vc:
174 break; 176 break;
175 } 177 }
176 ppp_input(&pvcc->chan, skb); 178 ppp_input(&pvcc->chan, skb);
177 return; 179 return;
178 error: 180
181error:
179 kfree_skb(skb); 182 kfree_skb(skb);
180 ppp_input_error(&pvcc->chan, 0); 183 ppp_input_error(&pvcc->chan, 0);
181} 184}
@@ -194,7 +197,7 @@ static int pppoatm_send(struct ppp_channel *chan, struct sk_buff *skb)
194{ 197{
195 struct pppoatm_vcc *pvcc = chan_to_pvcc(chan); 198 struct pppoatm_vcc *pvcc = chan_to_pvcc(chan);
196 ATM_SKB(skb)->vcc = pvcc->atmvcc; 199 ATM_SKB(skb)->vcc = pvcc->atmvcc;
197 pr_debug("pppoatm_send (skb=0x%p, vcc=0x%p)\n", skb, pvcc->atmvcc); 200 pr_debug("(skb=0x%p, vcc=0x%p)\n", skb, pvcc->atmvcc);
198 if (skb->data[0] == '\0' && (pvcc->flags & SC_COMP_PROT)) 201 if (skb->data[0] == '\0' && (pvcc->flags & SC_COMP_PROT))
199 (void) skb_pull(skb, 1); 202 (void) skb_pull(skb, 1);
200 switch (pvcc->encaps) { /* LLC encapsulation needed */ 203 switch (pvcc->encaps) { /* LLC encapsulation needed */
@@ -208,7 +211,8 @@ static int pppoatm_send(struct ppp_channel *chan, struct sk_buff *skb)
208 goto nospace; 211 goto nospace;
209 } 212 }
210 kfree_skb(skb); 213 kfree_skb(skb);
211 if ((skb = n) == NULL) 214 skb = n;
215 if (skb == NULL)
212 return DROP_PACKET; 216 return DROP_PACKET;
213 } else if (!atm_may_send(pvcc->atmvcc, skb->truesize)) 217 } else if (!atm_may_send(pvcc->atmvcc, skb->truesize))
214 goto nospace; 218 goto nospace;
@@ -226,11 +230,11 @@ static int pppoatm_send(struct ppp_channel *chan, struct sk_buff *skb)
226 230
227 atomic_add(skb->truesize, &sk_atm(ATM_SKB(skb)->vcc)->sk_wmem_alloc); 231 atomic_add(skb->truesize, &sk_atm(ATM_SKB(skb)->vcc)->sk_wmem_alloc);
228 ATM_SKB(skb)->atm_options = ATM_SKB(skb)->vcc->atm_options; 232 ATM_SKB(skb)->atm_options = ATM_SKB(skb)->vcc->atm_options;
229 pr_debug("atm_skb(%p)->vcc(%p)->dev(%p)\n", skb, ATM_SKB(skb)->vcc, 233 pr_debug("atm_skb(%p)->vcc(%p)->dev(%p)\n",
230 ATM_SKB(skb)->vcc->dev); 234 skb, ATM_SKB(skb)->vcc, ATM_SKB(skb)->vcc->dev);
231 return ATM_SKB(skb)->vcc->send(ATM_SKB(skb)->vcc, skb) 235 return ATM_SKB(skb)->vcc->send(ATM_SKB(skb)->vcc, skb)
232 ? DROP_PACKET : 1; 236 ? DROP_PACKET : 1;
233 nospace: 237nospace:
234 /* 238 /*
235 * We don't have space to send this SKB now, but we might have 239 * We don't have space to send this SKB now, but we might have
236 * already applied SC_COMP_PROT compression, so may need to undo 240 * already applied SC_COMP_PROT compression, so may need to undo
@@ -289,7 +293,8 @@ static int pppoatm_assign_vcc(struct atm_vcc *atmvcc, void __user *arg)
289 (be.encaps == e_vc ? 0 : LLC_LEN); 293 (be.encaps == e_vc ? 0 : LLC_LEN);
290 pvcc->wakeup_tasklet = tasklet_proto; 294 pvcc->wakeup_tasklet = tasklet_proto;
291 pvcc->wakeup_tasklet.data = (unsigned long) &pvcc->chan; 295 pvcc->wakeup_tasklet.data = (unsigned long) &pvcc->chan;
292 if ((err = ppp_register_channel(&pvcc->chan)) != 0) { 296 err = ppp_register_channel(&pvcc->chan);
297 if (err != 0) {
293 kfree(pvcc); 298 kfree(pvcc);
294 return err; 299 return err;
295 } 300 }
diff --git a/net/atm/proc.c b/net/atm/proc.c
index ab8419a324b6..696e218436e5 100644
--- a/net/atm/proc.c
+++ b/net/atm/proc.c
@@ -22,17 +22,18 @@
22#include <linux/netdevice.h> 22#include <linux/netdevice.h>
23#include <linux/atmclip.h> 23#include <linux/atmclip.h>
24#include <linux/init.h> /* for __init */ 24#include <linux/init.h> /* for __init */
25#include <linux/slab.h>
25#include <net/net_namespace.h> 26#include <net/net_namespace.h>
26#include <net/atmclip.h> 27#include <net/atmclip.h>
27#include <asm/uaccess.h> 28#include <linux/uaccess.h>
29#include <linux/param.h> /* for HZ */
28#include <asm/atomic.h> 30#include <asm/atomic.h>
29#include <asm/param.h> /* for HZ */
30#include "resources.h" 31#include "resources.h"
31#include "common.h" /* atm_proc_init prototype */ 32#include "common.h" /* atm_proc_init prototype */
32#include "signaling.h" /* to get sigd - ugly too */ 33#include "signaling.h" /* to get sigd - ugly too */
33 34
34static ssize_t proc_dev_atm_read(struct file *file,char __user *buf,size_t count, 35static ssize_t proc_dev_atm_read(struct file *file, char __user *buf,
35 loff_t *pos); 36 size_t count, loff_t *pos);
36 37
37static const struct file_operations proc_atm_dev_ops = { 38static const struct file_operations proc_atm_dev_ops = {
38 .owner = THIS_MODULE, 39 .owner = THIS_MODULE,
@@ -43,9 +44,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
43 const struct k_atm_aal_stats *stats) 44 const struct k_atm_aal_stats *stats)
44{ 45{
45 seq_printf(seq, "%s ( %d %d %d %d %d )", aal, 46 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
46 atomic_read(&stats->tx),atomic_read(&stats->tx_err), 47 atomic_read(&stats->tx), atomic_read(&stats->tx_err),
47 atomic_read(&stats->rx),atomic_read(&stats->rx_err), 48 atomic_read(&stats->rx), atomic_read(&stats->rx_err),
48 atomic_read(&stats->rx_drop)); 49 atomic_read(&stats->rx_drop));
49} 50}
50 51
51static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev) 52static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
@@ -151,8 +152,8 @@ static void *vcc_seq_next(struct seq_file *seq, void *v, loff_t *pos)
151 152
152static void pvc_info(struct seq_file *seq, struct atm_vcc *vcc) 153static void pvc_info(struct seq_file *seq, struct atm_vcc *vcc)
153{ 154{
154 static const char *const class_name[] = 155 static const char *const class_name[] = {
155 {"off","UBR","CBR","VBR","ABR"}; 156 "off", "UBR", "CBR", "VBR", "ABR"};
156 static const char *const aal_name[] = { 157 static const char *const aal_name[] = {
157 "---", "1", "2", "3/4", /* 0- 3 */ 158 "---", "1", "2", "3/4", /* 0- 3 */
158 "???", "5", "???", "???", /* 4- 7 */ 159 "???", "5", "???", "???", /* 4- 7 */
@@ -160,11 +161,12 @@ static void pvc_info(struct seq_file *seq, struct atm_vcc *vcc)
160 "???", "0", "???", "???"}; /* 12-15 */ 161 "???", "0", "???", "???"}; /* 12-15 */
161 162
162 seq_printf(seq, "%3d %3d %5d %-3s %7d %-5s %7d %-6s", 163 seq_printf(seq, "%3d %3d %5d %-3s %7d %-5s %7d %-6s",
163 vcc->dev->number,vcc->vpi,vcc->vci, 164 vcc->dev->number, vcc->vpi, vcc->vci,
164 vcc->qos.aal >= ARRAY_SIZE(aal_name) ? "err" : 165 vcc->qos.aal >= ARRAY_SIZE(aal_name) ? "err" :
165 aal_name[vcc->qos.aal],vcc->qos.rxtp.min_pcr, 166 aal_name[vcc->qos.aal], vcc->qos.rxtp.min_pcr,
166 class_name[vcc->qos.rxtp.traffic_class],vcc->qos.txtp.min_pcr, 167 class_name[vcc->qos.rxtp.traffic_class],
167 class_name[vcc->qos.txtp.traffic_class]); 168 vcc->qos.txtp.min_pcr,
169 class_name[vcc->qos.txtp.traffic_class]);
168 if (test_bit(ATM_VF_IS_CLIP, &vcc->flags)) { 170 if (test_bit(ATM_VF_IS_CLIP, &vcc->flags)) {
169 struct clip_vcc *clip_vcc = CLIP_VCC(vcc); 171 struct clip_vcc *clip_vcc = CLIP_VCC(vcc);
170 struct net_device *dev; 172 struct net_device *dev;
@@ -195,19 +197,20 @@ static void vcc_info(struct seq_file *seq, struct atm_vcc *vcc)
195 seq_printf(seq, "%3d %3d %5d ", vcc->dev->number, vcc->vpi, 197 seq_printf(seq, "%3d %3d %5d ", vcc->dev->number, vcc->vpi,
196 vcc->vci); 198 vcc->vci);
197 switch (sk->sk_family) { 199 switch (sk->sk_family) {
198 case AF_ATMPVC: 200 case AF_ATMPVC:
199 seq_printf(seq, "PVC"); 201 seq_printf(seq, "PVC");
200 break; 202 break;
201 case AF_ATMSVC: 203 case AF_ATMSVC:
202 seq_printf(seq, "SVC"); 204 seq_printf(seq, "SVC");
203 break; 205 break;
204 default: 206 default:
205 seq_printf(seq, "%3d", sk->sk_family); 207 seq_printf(seq, "%3d", sk->sk_family);
206 } 208 }
207 seq_printf(seq, " %04lx %5d %7d/%7d %7d/%7d [%d]\n", vcc->flags, sk->sk_err, 209 seq_printf(seq, " %04lx %5d %7d/%7d %7d/%7d [%d]\n",
208 sk_wmem_alloc_get(sk), sk->sk_sndbuf, 210 vcc->flags, sk->sk_err,
209 sk_rmem_alloc_get(sk), sk->sk_rcvbuf, 211 sk_wmem_alloc_get(sk), sk->sk_sndbuf,
210 atomic_read(&sk->sk_refcnt)); 212 sk_rmem_alloc_get(sk), sk->sk_rcvbuf,
213 atomic_read(&sk->sk_refcnt));
211} 214}
212 215
213static void svc_info(struct seq_file *seq, struct atm_vcc *vcc) 216static void svc_info(struct seq_file *seq, struct atm_vcc *vcc)
@@ -236,7 +239,7 @@ static int atm_dev_seq_show(struct seq_file *seq, void *v)
236 "Itf Type ESI/\"MAC\"addr " 239 "Itf Type ESI/\"MAC\"addr "
237 "AAL(TX,err,RX,err,drop) ... [refcnt]\n"; 240 "AAL(TX,err,RX,err,drop) ... [refcnt]\n";
238 241
239 if (v == SEQ_START_TOKEN) 242 if (v == &atm_devs)
240 seq_puts(seq, atm_dev_banner); 243 seq_puts(seq, atm_dev_banner);
241 else { 244 else {
242 struct atm_dev *dev = list_entry(v, struct atm_dev, dev_list); 245 struct atm_dev *dev = list_entry(v, struct atm_dev, dev_list);
@@ -376,32 +379,35 @@ static ssize_t proc_dev_atm_read(struct file *file, char __user *buf,
376 unsigned long page; 379 unsigned long page;
377 int length; 380 int length;
378 381
379 if (count == 0) return 0; 382 if (count == 0)
383 return 0;
380 page = get_zeroed_page(GFP_KERNEL); 384 page = get_zeroed_page(GFP_KERNEL);
381 if (!page) return -ENOMEM; 385 if (!page)
386 return -ENOMEM;
382 dev = PDE(file->f_path.dentry->d_inode)->data; 387 dev = PDE(file->f_path.dentry->d_inode)->data;
383 if (!dev->ops->proc_read) 388 if (!dev->ops->proc_read)
384 length = -EINVAL; 389 length = -EINVAL;
385 else { 390 else {
386 length = dev->ops->proc_read(dev,pos,(char *) page); 391 length = dev->ops->proc_read(dev, pos, (char *)page);
387 if (length > count) length = -EINVAL; 392 if (length > count)
393 length = -EINVAL;
388 } 394 }
389 if (length >= 0) { 395 if (length >= 0) {
390 if (copy_to_user(buf,(char *) page,length)) length = -EFAULT; 396 if (copy_to_user(buf, (char *)page, length))
397 length = -EFAULT;
391 (*pos)++; 398 (*pos)++;
392 } 399 }
393 free_page(page); 400 free_page(page);
394 return length; 401 return length;
395} 402}
396 403
397
398struct proc_dir_entry *atm_proc_root; 404struct proc_dir_entry *atm_proc_root;
399EXPORT_SYMBOL(atm_proc_root); 405EXPORT_SYMBOL(atm_proc_root);
400 406
401 407
402int atm_proc_dev_register(struct atm_dev *dev) 408int atm_proc_dev_register(struct atm_dev *dev)
403{ 409{
404 int digits,num; 410 int digits, num;
405 int error; 411 int error;
406 412
407 /* No proc info */ 413 /* No proc info */
@@ -410,26 +416,28 @@ int atm_proc_dev_register(struct atm_dev *dev)
410 416
411 error = -ENOMEM; 417 error = -ENOMEM;
412 digits = 0; 418 digits = 0;
413 for (num = dev->number; num; num /= 10) digits++; 419 for (num = dev->number; num; num /= 10)
414 if (!digits) digits++; 420 digits++;
421 if (!digits)
422 digits++;
415 423
416 dev->proc_name = kmalloc(strlen(dev->type) + digits + 2, GFP_KERNEL); 424 dev->proc_name = kmalloc(strlen(dev->type) + digits + 2, GFP_KERNEL);
417 if (!dev->proc_name) 425 if (!dev->proc_name)
418 goto err_out; 426 goto err_out;
419 sprintf(dev->proc_name,"%s:%d",dev->type, dev->number); 427 sprintf(dev->proc_name, "%s:%d", dev->type, dev->number);
420 428
421 dev->proc_entry = proc_create_data(dev->proc_name, 0, atm_proc_root, 429 dev->proc_entry = proc_create_data(dev->proc_name, 0, atm_proc_root,
422 &proc_atm_dev_ops, dev); 430 &proc_atm_dev_ops, dev);
423 if (!dev->proc_entry) 431 if (!dev->proc_entry)
424 goto err_free_name; 432 goto err_free_name;
425 return 0; 433 return 0;
434
426err_free_name: 435err_free_name:
427 kfree(dev->proc_name); 436 kfree(dev->proc_name);
428err_out: 437err_out:
429 return error; 438 return error;
430} 439}
431 440
432
433void atm_proc_dev_deregister(struct atm_dev *dev) 441void atm_proc_dev_deregister(struct atm_dev *dev)
434{ 442{
435 if (!dev->ops->proc_read) 443 if (!dev->ops->proc_read)
diff --git a/net/atm/pvc.c b/net/atm/pvc.c
index d4c024504f99..437ee70c5e62 100644
--- a/net/atm/pvc.c
+++ b/net/atm/pvc.c
@@ -17,32 +17,35 @@
17#include "common.h" /* common for PVCs and SVCs */ 17#include "common.h" /* common for PVCs and SVCs */
18 18
19 19
20static int pvc_shutdown(struct socket *sock,int how) 20static int pvc_shutdown(struct socket *sock, int how)
21{ 21{
22 return 0; 22 return 0;
23} 23}
24 24
25 25static int pvc_bind(struct socket *sock, struct sockaddr *sockaddr,
26static int pvc_bind(struct socket *sock,struct sockaddr *sockaddr, 26 int sockaddr_len)
27 int sockaddr_len)
28{ 27{
29 struct sock *sk = sock->sk; 28 struct sock *sk = sock->sk;
30 struct sockaddr_atmpvc *addr; 29 struct sockaddr_atmpvc *addr;
31 struct atm_vcc *vcc; 30 struct atm_vcc *vcc;
32 int error; 31 int error;
33 32
34 if (sockaddr_len != sizeof(struct sockaddr_atmpvc)) return -EINVAL; 33 if (sockaddr_len != sizeof(struct sockaddr_atmpvc))
35 addr = (struct sockaddr_atmpvc *) sockaddr; 34 return -EINVAL;
36 if (addr->sap_family != AF_ATMPVC) return -EAFNOSUPPORT; 35 addr = (struct sockaddr_atmpvc *)sockaddr;
36 if (addr->sap_family != AF_ATMPVC)
37 return -EAFNOSUPPORT;
37 lock_sock(sk); 38 lock_sock(sk);
38 vcc = ATM_SD(sock); 39 vcc = ATM_SD(sock);
39 if (!test_bit(ATM_VF_HASQOS, &vcc->flags)) { 40 if (!test_bit(ATM_VF_HASQOS, &vcc->flags)) {
40 error = -EBADFD; 41 error = -EBADFD;
41 goto out; 42 goto out;
42 } 43 }
43 if (test_bit(ATM_VF_PARTIAL,&vcc->flags)) { 44 if (test_bit(ATM_VF_PARTIAL, &vcc->flags)) {
44 if (vcc->vpi != ATM_VPI_UNSPEC) addr->sap_addr.vpi = vcc->vpi; 45 if (vcc->vpi != ATM_VPI_UNSPEC)
45 if (vcc->vci != ATM_VCI_UNSPEC) addr->sap_addr.vci = vcc->vci; 46 addr->sap_addr.vpi = vcc->vpi;
47 if (vcc->vci != ATM_VCI_UNSPEC)
48 addr->sap_addr.vci = vcc->vci;
46 } 49 }
47 error = vcc_connect(sock, addr->sap_addr.itf, addr->sap_addr.vpi, 50 error = vcc_connect(sock, addr->sap_addr.itf, addr->sap_addr.vpi,
48 addr->sap_addr.vci); 51 addr->sap_addr.vci);
@@ -51,11 +54,10 @@ out:
51 return error; 54 return error;
52} 55}
53 56
54 57static int pvc_connect(struct socket *sock, struct sockaddr *sockaddr,
55static int pvc_connect(struct socket *sock,struct sockaddr *sockaddr, 58 int sockaddr_len, int flags)
56 int sockaddr_len,int flags)
57{ 59{
58 return pvc_bind(sock,sockaddr,sockaddr_len); 60 return pvc_bind(sock, sockaddr, sockaddr_len);
59} 61}
60 62
61static int pvc_setsockopt(struct socket *sock, int level, int optname, 63static int pvc_setsockopt(struct socket *sock, int level, int optname,
@@ -70,7 +72,6 @@ static int pvc_setsockopt(struct socket *sock, int level, int optname,
70 return error; 72 return error;
71} 73}
72 74
73
74static int pvc_getsockopt(struct socket *sock, int level, int optname, 75static int pvc_getsockopt(struct socket *sock, int level, int optname,
75 char __user *optval, int __user *optlen) 76 char __user *optval, int __user *optlen)
76{ 77{
@@ -83,16 +84,16 @@ static int pvc_getsockopt(struct socket *sock, int level, int optname,
83 return error; 84 return error;
84} 85}
85 86
86 87static int pvc_getname(struct socket *sock, struct sockaddr *sockaddr,
87static int pvc_getname(struct socket *sock,struct sockaddr *sockaddr, 88 int *sockaddr_len, int peer)
88 int *sockaddr_len,int peer)
89{ 89{
90 struct sockaddr_atmpvc *addr; 90 struct sockaddr_atmpvc *addr;
91 struct atm_vcc *vcc = ATM_SD(sock); 91 struct atm_vcc *vcc = ATM_SD(sock);
92 92
93 if (!vcc->dev || !test_bit(ATM_VF_ADDR,&vcc->flags)) return -ENOTCONN; 93 if (!vcc->dev || !test_bit(ATM_VF_ADDR, &vcc->flags))
94 return -ENOTCONN;
94 *sockaddr_len = sizeof(struct sockaddr_atmpvc); 95 *sockaddr_len = sizeof(struct sockaddr_atmpvc);
95 addr = (struct sockaddr_atmpvc *) sockaddr; 96 addr = (struct sockaddr_atmpvc *)sockaddr;
96 addr->sap_family = AF_ATMPVC; 97 addr->sap_family = AF_ATMPVC;
97 addr->sap_addr.itf = vcc->dev->number; 98 addr->sap_addr.itf = vcc->dev->number;
98 addr->sap_addr.vpi = vcc->vpi; 99 addr->sap_addr.vpi = vcc->vpi;
@@ -100,7 +101,6 @@ static int pvc_getname(struct socket *sock,struct sockaddr *sockaddr,
100 return 0; 101 return 0;
101} 102}
102 103
103
104static const struct proto_ops pvc_proto_ops = { 104static const struct proto_ops pvc_proto_ops = {
105 .family = PF_ATMPVC, 105 .family = PF_ATMPVC,
106 .owner = THIS_MODULE, 106 .owner = THIS_MODULE,
@@ -127,7 +127,8 @@ static const struct proto_ops pvc_proto_ops = {
127}; 127};
128 128
129 129
130static int pvc_create(struct net *net, struct socket *sock,int protocol) 130static int pvc_create(struct net *net, struct socket *sock, int protocol,
131 int kern)
131{ 132{
132 if (net != &init_net) 133 if (net != &init_net)
133 return -EAFNOSUPPORT; 134 return -EAFNOSUPPORT;
@@ -136,8 +137,7 @@ static int pvc_create(struct net *net, struct socket *sock,int protocol)
136 return vcc_create(net, sock, protocol, PF_ATMPVC); 137 return vcc_create(net, sock, protocol, PF_ATMPVC);
137} 138}
138 139
139 140static const struct net_proto_family pvc_family_ops = {
140static struct net_proto_family pvc_family_ops = {
141 .family = PF_ATMPVC, 141 .family = PF_ATMPVC,
142 .create = pvc_create, 142 .create = pvc_create,
143 .owner = THIS_MODULE, 143 .owner = THIS_MODULE,
diff --git a/net/atm/raw.c b/net/atm/raw.c
index cbfcc71a17b1..b4f7b9ff3c74 100644
--- a/net/atm/raw.c
+++ b/net/atm/raw.c
@@ -2,6 +2,7 @@
2 2
3/* Written 1995-2000 by Werner Almesberger, EPFL LRC/ICA */ 3/* Written 1995-2000 by Werner Almesberger, EPFL LRC/ICA */
4 4
5#define pr_fmt(fmt) KBUILD_MODNAME ":%s: " fmt, __func__
5 6
6#include <linux/module.h> 7#include <linux/module.h>
7#include <linux/atmdev.h> 8#include <linux/atmdev.h>
@@ -9,6 +10,7 @@
9#include <linux/kernel.h> 10#include <linux/kernel.h>
10#include <linux/skbuff.h> 11#include <linux/skbuff.h>
11#include <linux/mm.h> 12#include <linux/mm.h>
13#include <linux/slab.h>
12 14
13#include "common.h" 15#include "common.h"
14#include "protocols.h" 16#include "protocols.h"
@@ -17,7 +19,7 @@
17 * SKB == NULL indicates that the link is being closed 19 * SKB == NULL indicates that the link is being closed
18 */ 20 */
19 21
20static void atm_push_raw(struct atm_vcc *vcc,struct sk_buff *skb) 22static void atm_push_raw(struct atm_vcc *vcc, struct sk_buff *skb)
21{ 23{
22 if (skb) { 24 if (skb) {
23 struct sock *sk = sk_atm(vcc); 25 struct sock *sk = sk_atm(vcc);
@@ -27,36 +29,33 @@ static void atm_push_raw(struct atm_vcc *vcc,struct sk_buff *skb)
27 } 29 }
28} 30}
29 31
30 32static void atm_pop_raw(struct atm_vcc *vcc, struct sk_buff *skb)
31static void atm_pop_raw(struct atm_vcc *vcc,struct sk_buff *skb)
32{ 33{
33 struct sock *sk = sk_atm(vcc); 34 struct sock *sk = sk_atm(vcc);
34 35
35 pr_debug("APopR (%d) %d -= %d\n", vcc->vci, 36 pr_debug("(%d) %d -= %d\n",
36 sk_wmem_alloc_get(sk), skb->truesize); 37 vcc->vci, sk_wmem_alloc_get(sk), skb->truesize);
37 atomic_sub(skb->truesize, &sk->sk_wmem_alloc); 38 atomic_sub(skb->truesize, &sk->sk_wmem_alloc);
38 dev_kfree_skb_any(skb); 39 dev_kfree_skb_any(skb);
39 sk->sk_write_space(sk); 40 sk->sk_write_space(sk);
40} 41}
41 42
42 43static int atm_send_aal0(struct atm_vcc *vcc, struct sk_buff *skb)
43static int atm_send_aal0(struct atm_vcc *vcc,struct sk_buff *skb)
44{ 44{
45 /* 45 /*
46 * Note that if vpi/vci are _ANY or _UNSPEC the below will 46 * Note that if vpi/vci are _ANY or _UNSPEC the below will
47 * still work 47 * still work
48 */ 48 */
49 if (!capable(CAP_NET_ADMIN) && 49 if (!capable(CAP_NET_ADMIN) &&
50 (((u32 *) skb->data)[0] & (ATM_HDR_VPI_MASK | ATM_HDR_VCI_MASK)) != 50 (((u32 *)skb->data)[0] & (ATM_HDR_VPI_MASK | ATM_HDR_VCI_MASK)) !=
51 ((vcc->vpi << ATM_HDR_VPI_SHIFT) | (vcc->vci << ATM_HDR_VCI_SHIFT))) 51 ((vcc->vpi << ATM_HDR_VPI_SHIFT) |
52 { 52 (vcc->vci << ATM_HDR_VCI_SHIFT))) {
53 kfree_skb(skb); 53 kfree_skb(skb);
54 return -EADDRNOTAVAIL; 54 return -EADDRNOTAVAIL;
55 } 55 }
56 return vcc->dev->ops->send(vcc,skb); 56 return vcc->dev->ops->send(vcc, skb);
57} 57}
58 58
59
60int atm_init_aal0(struct atm_vcc *vcc) 59int atm_init_aal0(struct atm_vcc *vcc)
61{ 60{
62 vcc->push = atm_push_raw; 61 vcc->push = atm_push_raw;
@@ -66,7 +65,6 @@ int atm_init_aal0(struct atm_vcc *vcc)
66 return 0; 65 return 0;
67} 66}
68 67
69
70int atm_init_aal34(struct atm_vcc *vcc) 68int atm_init_aal34(struct atm_vcc *vcc)
71{ 69{
72 vcc->push = atm_push_raw; 70 vcc->push = atm_push_raw;
@@ -76,7 +74,6 @@ int atm_init_aal34(struct atm_vcc *vcc)
76 return 0; 74 return 0;
77} 75}
78 76
79
80int atm_init_aal5(struct atm_vcc *vcc) 77int atm_init_aal5(struct atm_vcc *vcc)
81{ 78{
82 vcc->push = atm_push_raw; 79 vcc->push = atm_push_raw;
@@ -85,6 +82,4 @@ int atm_init_aal5(struct atm_vcc *vcc)
85 vcc->send = vcc->dev->ops->send; 82 vcc->send = vcc->dev->ops->send;
86 return 0; 83 return 0;
87} 84}
88
89
90EXPORT_SYMBOL(atm_init_aal5); 85EXPORT_SYMBOL(atm_init_aal5);
diff --git a/net/atm/resources.c b/net/atm/resources.c
index 56b7322ff461..d29e58261511 100644
--- a/net/atm/resources.c
+++ b/net/atm/resources.c
@@ -7,6 +7,7 @@
7 * 2002/01 - don't free the whole struct sock on sk->destruct time, 7 * 2002/01 - don't free the whole struct sock on sk->destruct time,
8 * use the default destruct function initialized by sock_init_data */ 8 * use the default destruct function initialized by sock_init_data */
9 9
10#define pr_fmt(fmt) KBUILD_MODNAME ":%s: " fmt, __func__
10 11
11#include <linux/ctype.h> 12#include <linux/ctype.h>
12#include <linux/string.h> 13#include <linux/string.h>
@@ -18,6 +19,7 @@
18#include <linux/capability.h> 19#include <linux/capability.h>
19#include <linux/delay.h> 20#include <linux/delay.h>
20#include <linux/mutex.h> 21#include <linux/mutex.h>
22#include <linux/slab.h>
21 23
22#include <net/sock.h> /* for struct sock */ 24#include <net/sock.h> /* for struct sock */
23 25
@@ -70,7 +72,7 @@ struct atm_dev *atm_dev_lookup(int number)
70 mutex_unlock(&atm_dev_mutex); 72 mutex_unlock(&atm_dev_mutex);
71 return dev; 73 return dev;
72} 74}
73 75EXPORT_SYMBOL(atm_dev_lookup);
74 76
75struct atm_dev *atm_dev_register(const char *type, const struct atmdev_ops *ops, 77struct atm_dev *atm_dev_register(const char *type, const struct atmdev_ops *ops,
76 int number, unsigned long *flags) 78 int number, unsigned long *flags)
@@ -79,13 +81,13 @@ struct atm_dev *atm_dev_register(const char *type, const struct atmdev_ops *ops,
79 81
80 dev = __alloc_atm_dev(type); 82 dev = __alloc_atm_dev(type);
81 if (!dev) { 83 if (!dev) {
82 printk(KERN_ERR "atm_dev_register: no space for dev %s\n", 84 pr_err("no space for dev %s\n", type);
83 type);
84 return NULL; 85 return NULL;
85 } 86 }
86 mutex_lock(&atm_dev_mutex); 87 mutex_lock(&atm_dev_mutex);
87 if (number != -1) { 88 if (number != -1) {
88 if ((inuse = __atm_dev_lookup(number))) { 89 inuse = __atm_dev_lookup(number);
90 if (inuse) {
89 atm_dev_put(inuse); 91 atm_dev_put(inuse);
90 mutex_unlock(&atm_dev_mutex); 92 mutex_unlock(&atm_dev_mutex);
91 kfree(dev); 93 kfree(dev);
@@ -109,16 +111,12 @@ struct atm_dev *atm_dev_register(const char *type, const struct atmdev_ops *ops,
109 atomic_set(&dev->refcnt, 1); 111 atomic_set(&dev->refcnt, 1);
110 112
111 if (atm_proc_dev_register(dev) < 0) { 113 if (atm_proc_dev_register(dev) < 0) {
112 printk(KERN_ERR "atm_dev_register: " 114 pr_err("atm_proc_dev_register failed for dev %s\n", type);
113 "atm_proc_dev_register failed for dev %s\n",
114 type);
115 goto out_fail; 115 goto out_fail;
116 } 116 }
117 117
118 if (atm_register_sysfs(dev) < 0) { 118 if (atm_register_sysfs(dev) < 0) {
119 printk(KERN_ERR "atm_dev_register: " 119 pr_err("atm_register_sysfs failed for dev %s\n", type);
120 "atm_register_sysfs failed for dev %s\n",
121 type);
122 atm_proc_dev_deregister(dev); 120 atm_proc_dev_deregister(dev);
123 goto out_fail; 121 goto out_fail;
124 } 122 }
@@ -134,7 +132,7 @@ out_fail:
134 dev = NULL; 132 dev = NULL;
135 goto out; 133 goto out;
136} 134}
137 135EXPORT_SYMBOL(atm_dev_register);
138 136
139void atm_dev_deregister(struct atm_dev *dev) 137void atm_dev_deregister(struct atm_dev *dev)
140{ 138{
@@ -156,7 +154,7 @@ void atm_dev_deregister(struct atm_dev *dev)
156 154
157 atm_dev_put(dev); 155 atm_dev_put(dev);
158} 156}
159 157EXPORT_SYMBOL(atm_dev_deregister);
160 158
161static void copy_aal_stats(struct k_atm_aal_stats *from, 159static void copy_aal_stats(struct k_atm_aal_stats *from,
162 struct atm_aal_stats *to) 160 struct atm_aal_stats *to)
@@ -166,7 +164,6 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
166#undef __HANDLE_ITEM 164#undef __HANDLE_ITEM
167} 165}
168 166
169
170static void subtract_aal_stats(struct k_atm_aal_stats *from, 167static void subtract_aal_stats(struct k_atm_aal_stats *from,
171 struct atm_aal_stats *to) 168 struct atm_aal_stats *to)
172{ 169{
@@ -175,8 +172,8 @@ static void subtract_aal_stats(struct k_atm_aal_stats *from,
175#undef __HANDLE_ITEM 172#undef __HANDLE_ITEM
176} 173}
177 174
178 175static int fetch_stats(struct atm_dev *dev, struct atm_dev_stats __user *arg,
179static int fetch_stats(struct atm_dev *dev, struct atm_dev_stats __user *arg, int zero) 176 int zero)
180{ 177{
181 struct atm_dev_stats tmp; 178 struct atm_dev_stats tmp;
182 int error = 0; 179 int error = 0;
@@ -194,7 +191,6 @@ static int fetch_stats(struct atm_dev *dev, struct atm_dev_stats __user *arg, in
194 return error ? -EFAULT : 0; 191 return error ? -EFAULT : 0;
195} 192}
196 193
197
198int atm_dev_ioctl(unsigned int cmd, void __user *arg, int compat) 194int atm_dev_ioctl(unsigned int cmd, void __user *arg, int compat)
199{ 195{
200 void __user *buf; 196 void __user *buf;
@@ -210,50 +206,49 @@ int atm_dev_ioctl(unsigned int cmd, void __user *arg, int compat)
210#endif 206#endif
211 207
212 switch (cmd) { 208 switch (cmd) {
213 case ATM_GETNAMES: 209 case ATM_GETNAMES:
214 210 if (compat) {
215 if (compat) {
216#ifdef CONFIG_COMPAT 211#ifdef CONFIG_COMPAT
217 struct compat_atm_iobuf __user *ciobuf = arg; 212 struct compat_atm_iobuf __user *ciobuf = arg;
218 compat_uptr_t cbuf; 213 compat_uptr_t cbuf;
219 iobuf_len = &ciobuf->length; 214 iobuf_len = &ciobuf->length;
220 if (get_user(cbuf, &ciobuf->buffer)) 215 if (get_user(cbuf, &ciobuf->buffer))
221 return -EFAULT; 216 return -EFAULT;
222 buf = compat_ptr(cbuf); 217 buf = compat_ptr(cbuf);
223#endif 218#endif
224 } else { 219 } else {
225 struct atm_iobuf __user *iobuf = arg; 220 struct atm_iobuf __user *iobuf = arg;
226 iobuf_len = &iobuf->length; 221 iobuf_len = &iobuf->length;
227 if (get_user(buf, &iobuf->buffer)) 222 if (get_user(buf, &iobuf->buffer))
228 return -EFAULT;
229 }
230 if (get_user(len, iobuf_len))
231 return -EFAULT; 223 return -EFAULT;
232 mutex_lock(&atm_dev_mutex); 224 }
233 list_for_each(p, &atm_devs) 225 if (get_user(len, iobuf_len))
234 size += sizeof(int); 226 return -EFAULT;
235 if (size > len) { 227 mutex_lock(&atm_dev_mutex);
236 mutex_unlock(&atm_dev_mutex); 228 list_for_each(p, &atm_devs)
237 return -E2BIG; 229 size += sizeof(int);
238 } 230 if (size > len) {
239 tmp_buf = kmalloc(size, GFP_ATOMIC); 231 mutex_unlock(&atm_dev_mutex);
240 if (!tmp_buf) { 232 return -E2BIG;
241 mutex_unlock(&atm_dev_mutex); 233 }
242 return -ENOMEM; 234 tmp_buf = kmalloc(size, GFP_ATOMIC);
243 } 235 if (!tmp_buf) {
244 tmp_p = tmp_buf;
245 list_for_each(p, &atm_devs) {
246 dev = list_entry(p, struct atm_dev, dev_list);
247 *tmp_p++ = dev->number;
248 }
249 mutex_unlock(&atm_dev_mutex); 236 mutex_unlock(&atm_dev_mutex);
250 error = ((copy_to_user(buf, tmp_buf, size)) || 237 return -ENOMEM;
251 put_user(size, iobuf_len)) 238 }
252 ? -EFAULT : 0; 239 tmp_p = tmp_buf;
253 kfree(tmp_buf); 240 list_for_each(p, &atm_devs) {
254 return error; 241 dev = list_entry(p, struct atm_dev, dev_list);
255 default: 242 *tmp_p++ = dev->number;
256 break; 243 }
244 mutex_unlock(&atm_dev_mutex);
245 error = ((copy_to_user(buf, tmp_buf, size)) ||
246 put_user(size, iobuf_len))
247 ? -EFAULT : 0;
248 kfree(tmp_buf);
249 return error;
250 default:
251 break;
257 } 252 }
258 253
259 if (compat) { 254 if (compat) {
@@ -282,166 +277,167 @@ int atm_dev_ioctl(unsigned int cmd, void __user *arg, int compat)
282 if (get_user(number, &sioc->number)) 277 if (get_user(number, &sioc->number))
283 return -EFAULT; 278 return -EFAULT;
284 } 279 }
285 if (!(dev = try_then_request_module(atm_dev_lookup(number), 280
286 "atm-device-%d", number))) 281 dev = try_then_request_module(atm_dev_lookup(number), "atm-device-%d",
282 number);
283 if (!dev)
287 return -ENODEV; 284 return -ENODEV;
288 285
289 switch (cmd) { 286 switch (cmd) {
290 case ATM_GETTYPE: 287 case ATM_GETTYPE:
291 size = strlen(dev->type) + 1; 288 size = strlen(dev->type) + 1;
292 if (copy_to_user(buf, dev->type, size)) { 289 if (copy_to_user(buf, dev->type, size)) {
293 error = -EFAULT; 290 error = -EFAULT;
294 goto done; 291 goto done;
295 } 292 }
296 break; 293 break;
297 case ATM_GETESI: 294 case ATM_GETESI:
298 size = ESI_LEN; 295 size = ESI_LEN;
299 if (copy_to_user(buf, dev->esi, size)) { 296 if (copy_to_user(buf, dev->esi, size)) {
300 error = -EFAULT; 297 error = -EFAULT;
301 goto done; 298 goto done;
302 } 299 }
303 break; 300 break;
304 case ATM_SETESI: 301 case ATM_SETESI:
305 { 302 {
306 int i; 303 int i;
307 304
308 for (i = 0; i < ESI_LEN; i++) 305 for (i = 0; i < ESI_LEN; i++)
309 if (dev->esi[i]) { 306 if (dev->esi[i]) {
310 error = -EEXIST; 307 error = -EEXIST;
311 goto done;
312 }
313 }
314 /* fall through */
315 case ATM_SETESIF:
316 {
317 unsigned char esi[ESI_LEN];
318
319 if (!capable(CAP_NET_ADMIN)) {
320 error = -EPERM;
321 goto done;
322 }
323 if (copy_from_user(esi, buf, ESI_LEN)) {
324 error = -EFAULT;
325 goto done;
326 }
327 memcpy(dev->esi, esi, ESI_LEN);
328 error = ESI_LEN;
329 goto done;
330 }
331 case ATM_GETSTATZ:
332 if (!capable(CAP_NET_ADMIN)) {
333 error = -EPERM;
334 goto done;
335 }
336 /* fall through */
337 case ATM_GETSTAT:
338 size = sizeof(struct atm_dev_stats);
339 error = fetch_stats(dev, buf, cmd == ATM_GETSTATZ);
340 if (error)
341 goto done;
342 break;
343 case ATM_GETCIRANGE:
344 size = sizeof(struct atm_cirange);
345 if (copy_to_user(buf, &dev->ci_range, size)) {
346 error = -EFAULT;
347 goto done;
348 }
349 break;
350 case ATM_GETLINKRATE:
351 size = sizeof(int);
352 if (copy_to_user(buf, &dev->link_rate, size)) {
353 error = -EFAULT;
354 goto done;
355 }
356 break;
357 case ATM_RSTADDR:
358 if (!capable(CAP_NET_ADMIN)) {
359 error = -EPERM;
360 goto done;
361 }
362 atm_reset_addr(dev, ATM_ADDR_LOCAL);
363 break;
364 case ATM_ADDADDR:
365 case ATM_DELADDR:
366 case ATM_ADDLECSADDR:
367 case ATM_DELLECSADDR:
368 if (!capable(CAP_NET_ADMIN)) {
369 error = -EPERM;
370 goto done;
371 }
372 {
373 struct sockaddr_atmsvc addr;
374
375 if (copy_from_user(&addr, buf, sizeof(addr))) {
376 error = -EFAULT;
377 goto done;
378 }
379 if (cmd == ATM_ADDADDR || cmd == ATM_ADDLECSADDR)
380 error = atm_add_addr(dev, &addr,
381 (cmd == ATM_ADDADDR ?
382 ATM_ADDR_LOCAL : ATM_ADDR_LECS));
383 else
384 error = atm_del_addr(dev, &addr,
385 (cmd == ATM_DELADDR ?
386 ATM_ADDR_LOCAL : ATM_ADDR_LECS));
387 goto done; 308 goto done;
388 } 309 }
389 case ATM_GETADDR: 310 }
390 case ATM_GETLECSADDR: 311 /* fall through */
391 error = atm_get_addr(dev, buf, len, 312 case ATM_SETESIF:
392 (cmd == ATM_GETADDR ? 313 {
314 unsigned char esi[ESI_LEN];
315
316 if (!capable(CAP_NET_ADMIN)) {
317 error = -EPERM;
318 goto done;
319 }
320 if (copy_from_user(esi, buf, ESI_LEN)) {
321 error = -EFAULT;
322 goto done;
323 }
324 memcpy(dev->esi, esi, ESI_LEN);
325 error = ESI_LEN;
326 goto done;
327 }
328 case ATM_GETSTATZ:
329 if (!capable(CAP_NET_ADMIN)) {
330 error = -EPERM;
331 goto done;
332 }
333 /* fall through */
334 case ATM_GETSTAT:
335 size = sizeof(struct atm_dev_stats);
336 error = fetch_stats(dev, buf, cmd == ATM_GETSTATZ);
337 if (error)
338 goto done;
339 break;
340 case ATM_GETCIRANGE:
341 size = sizeof(struct atm_cirange);
342 if (copy_to_user(buf, &dev->ci_range, size)) {
343 error = -EFAULT;
344 goto done;
345 }
346 break;
347 case ATM_GETLINKRATE:
348 size = sizeof(int);
349 if (copy_to_user(buf, &dev->link_rate, size)) {
350 error = -EFAULT;
351 goto done;
352 }
353 break;
354 case ATM_RSTADDR:
355 if (!capable(CAP_NET_ADMIN)) {
356 error = -EPERM;
357 goto done;
358 }
359 atm_reset_addr(dev, ATM_ADDR_LOCAL);
360 break;
361 case ATM_ADDADDR:
362 case ATM_DELADDR:
363 case ATM_ADDLECSADDR:
364 case ATM_DELLECSADDR:
365 {
366 struct sockaddr_atmsvc addr;
367
368 if (!capable(CAP_NET_ADMIN)) {
369 error = -EPERM;
370 goto done;
371 }
372
373 if (copy_from_user(&addr, buf, sizeof(addr))) {
374 error = -EFAULT;
375 goto done;
376 }
377 if (cmd == ATM_ADDADDR || cmd == ATM_ADDLECSADDR)
378 error = atm_add_addr(dev, &addr,
379 (cmd == ATM_ADDADDR ?
393 ATM_ADDR_LOCAL : ATM_ADDR_LECS)); 380 ATM_ADDR_LOCAL : ATM_ADDR_LECS));
394 if (error < 0) 381 else
395 goto done; 382 error = atm_del_addr(dev, &addr,
396 size = error; 383 (cmd == ATM_DELADDR ?
397 /* may return 0, but later on size == 0 means "don't 384 ATM_ADDR_LOCAL : ATM_ADDR_LECS));
398 write the length" */ 385 goto done;
399 error = put_user(size, sioc_len) 386 }
400 ? -EFAULT : 0; 387 case ATM_GETADDR:
388 case ATM_GETLECSADDR:
389 error = atm_get_addr(dev, buf, len,
390 (cmd == ATM_GETADDR ?
391 ATM_ADDR_LOCAL : ATM_ADDR_LECS));
392 if (error < 0)
393 goto done;
394 size = error;
395 /* may return 0, but later on size == 0 means "don't
396 write the length" */
397 error = put_user(size, sioc_len) ? -EFAULT : 0;
398 goto done;
399 case ATM_SETLOOP:
400 if (__ATM_LM_XTRMT((int) (unsigned long) buf) &&
401 __ATM_LM_XTLOC((int) (unsigned long) buf) >
402 __ATM_LM_XTRMT((int) (unsigned long) buf)) {
403 error = -EINVAL;
404 goto done;
405 }
406 /* fall through */
407 case ATM_SETCIRANGE:
408 case SONET_GETSTATZ:
409 case SONET_SETDIAG:
410 case SONET_CLRDIAG:
411 case SONET_SETFRAMING:
412 if (!capable(CAP_NET_ADMIN)) {
413 error = -EPERM;
401 goto done; 414 goto done;
402 case ATM_SETLOOP: 415 }
403 if (__ATM_LM_XTRMT((int) (unsigned long) buf) && 416 /* fall through */
404 __ATM_LM_XTLOC((int) (unsigned long) buf) > 417 default:
405 __ATM_LM_XTRMT((int) (unsigned long) buf)) { 418 if (compat) {
419#ifdef CONFIG_COMPAT
420 if (!dev->ops->compat_ioctl) {
406 error = -EINVAL; 421 error = -EINVAL;
407 goto done; 422 goto done;
408 } 423 }
409 /* fall through */ 424 size = dev->ops->compat_ioctl(dev, cmd, buf);
410 case ATM_SETCIRANGE:
411 case SONET_GETSTATZ:
412 case SONET_SETDIAG:
413 case SONET_CLRDIAG:
414 case SONET_SETFRAMING:
415 if (!capable(CAP_NET_ADMIN)) {
416 error = -EPERM;
417 goto done;
418 }
419 /* fall through */
420 default:
421 if (compat) {
422#ifdef CONFIG_COMPAT
423 if (!dev->ops->compat_ioctl) {
424 error = -EINVAL;
425 goto done;
426 }
427 size = dev->ops->compat_ioctl(dev, cmd, buf);
428#endif 425#endif
429 } else { 426 } else {
430 if (!dev->ops->ioctl) { 427 if (!dev->ops->ioctl) {
431 error = -EINVAL; 428 error = -EINVAL;
432 goto done;
433 }
434 size = dev->ops->ioctl(dev, cmd, buf);
435 }
436 if (size < 0) {
437 error = (size == -ENOIOCTLCMD ? -EINVAL : size);
438 goto done; 429 goto done;
439 } 430 }
431 size = dev->ops->ioctl(dev, cmd, buf);
432 }
433 if (size < 0) {
434 error = (size == -ENOIOCTLCMD ? -EINVAL : size);
435 goto done;
436 }
440 } 437 }
441 438
442 if (size) 439 if (size)
443 error = put_user(size, sioc_len) 440 error = put_user(size, sioc_len) ? -EFAULT : 0;
444 ? -EFAULT : 0;
445 else 441 else
446 error = 0; 442 error = 0;
447done: 443done:
@@ -449,21 +445,10 @@ done:
449 return error; 445 return error;
450} 446}
451 447
452static __inline__ void *dev_get_idx(loff_t left)
453{
454 struct list_head *p;
455
456 list_for_each(p, &atm_devs) {
457 if (!--left)
458 break;
459 }
460 return (p != &atm_devs) ? p : NULL;
461}
462
463void *atm_dev_seq_start(struct seq_file *seq, loff_t *pos) 448void *atm_dev_seq_start(struct seq_file *seq, loff_t *pos)
464{ 449{
465 mutex_lock(&atm_dev_mutex); 450 mutex_lock(&atm_dev_mutex);
466 return *pos ? dev_get_idx(*pos) : SEQ_START_TOKEN; 451 return seq_list_start_head(&atm_devs, *pos);
467} 452}
468 453
469void atm_dev_seq_stop(struct seq_file *seq, void *v) 454void atm_dev_seq_stop(struct seq_file *seq, void *v)
@@ -473,13 +458,5 @@ void atm_dev_seq_stop(struct seq_file *seq, void *v)
473 458
474void *atm_dev_seq_next(struct seq_file *seq, void *v, loff_t *pos) 459void *atm_dev_seq_next(struct seq_file *seq, void *v, loff_t *pos)
475{ 460{
476 ++*pos; 461 return seq_list_next(v, &atm_devs, pos);
477 v = (v == SEQ_START_TOKEN)
478 ? atm_devs.next : ((struct list_head *)v)->next;
479 return (v == &atm_devs) ? NULL : v;
480} 462}
481
482
483EXPORT_SYMBOL(atm_dev_register);
484EXPORT_SYMBOL(atm_dev_deregister);
485EXPORT_SYMBOL(atm_dev_lookup);
diff --git a/net/atm/signaling.c b/net/atm/signaling.c
index 229921400522..6ba6e466ee54 100644
--- a/net/atm/signaling.c
+++ b/net/atm/signaling.c
@@ -2,6 +2,7 @@
2 2
3/* Written 1995-2000 by Werner Almesberger, EPFL LRC/ICA */ 3/* Written 1995-2000 by Werner Almesberger, EPFL LRC/ICA */
4 4
5#define pr_fmt(fmt) KBUILD_MODNAME ":%s: " fmt, __func__
5 6
6#include <linux/errno.h> /* error codes */ 7#include <linux/errno.h> /* error codes */
7#include <linux/kernel.h> /* printk */ 8#include <linux/kernel.h> /* printk */
@@ -13,11 +14,11 @@
13#include <linux/atmsvc.h> 14#include <linux/atmsvc.h>
14#include <linux/atmdev.h> 15#include <linux/atmdev.h>
15#include <linux/bitops.h> 16#include <linux/bitops.h>
17#include <linux/slab.h>
16 18
17#include "resources.h" 19#include "resources.h"
18#include "signaling.h" 20#include "signaling.h"
19 21
20
21#undef WAIT_FOR_DEMON /* #define this if system calls on SVC sockets 22#undef WAIT_FOR_DEMON /* #define this if system calls on SVC sockets
22 should block until the demon runs. 23 should block until the demon runs.
23 Danger: may cause nasty hangs if the demon 24 Danger: may cause nasty hangs if the demon
@@ -28,60 +29,59 @@ struct atm_vcc *sigd = NULL;
28static DECLARE_WAIT_QUEUE_HEAD(sigd_sleep); 29static DECLARE_WAIT_QUEUE_HEAD(sigd_sleep);
29#endif 30#endif
30 31
31
32static void sigd_put_skb(struct sk_buff *skb) 32static void sigd_put_skb(struct sk_buff *skb)
33{ 33{
34#ifdef WAIT_FOR_DEMON 34#ifdef WAIT_FOR_DEMON
35 DECLARE_WAITQUEUE(wait,current); 35 DECLARE_WAITQUEUE(wait, current);
36 36
37 add_wait_queue(&sigd_sleep,&wait); 37 add_wait_queue(&sigd_sleep, &wait);
38 while (!sigd) { 38 while (!sigd) {
39 set_current_state(TASK_UNINTERRUPTIBLE); 39 set_current_state(TASK_UNINTERRUPTIBLE);
40 pr_debug("atmsvc: waiting for signaling demon...\n"); 40 pr_debug("atmsvc: waiting for signaling daemon...\n");
41 schedule(); 41 schedule();
42 } 42 }
43 current->state = TASK_RUNNING; 43 current->state = TASK_RUNNING;
44 remove_wait_queue(&sigd_sleep,&wait); 44 remove_wait_queue(&sigd_sleep, &wait);
45#else 45#else
46 if (!sigd) { 46 if (!sigd) {
47 pr_debug("atmsvc: no signaling demon\n"); 47 pr_debug("atmsvc: no signaling daemon\n");
48 kfree_skb(skb); 48 kfree_skb(skb);
49 return; 49 return;
50 } 50 }
51#endif 51#endif
52 atm_force_charge(sigd,skb->truesize); 52 atm_force_charge(sigd, skb->truesize);
53 skb_queue_tail(&sk_atm(sigd)->sk_receive_queue,skb); 53 skb_queue_tail(&sk_atm(sigd)->sk_receive_queue, skb);
54 sk_atm(sigd)->sk_data_ready(sk_atm(sigd), skb->len); 54 sk_atm(sigd)->sk_data_ready(sk_atm(sigd), skb->len);
55} 55}
56 56
57 57static void modify_qos(struct atm_vcc *vcc, struct atmsvc_msg *msg)
58static void modify_qos(struct atm_vcc *vcc,struct atmsvc_msg *msg)
59{ 58{
60 struct sk_buff *skb; 59 struct sk_buff *skb;
61 60
62 if (test_bit(ATM_VF_RELEASED,&vcc->flags) || 61 if (test_bit(ATM_VF_RELEASED, &vcc->flags) ||
63 !test_bit(ATM_VF_READY,&vcc->flags)) 62 !test_bit(ATM_VF_READY, &vcc->flags))
64 return; 63 return;
65 msg->type = as_error; 64 msg->type = as_error;
66 if (!vcc->dev->ops->change_qos) msg->reply = -EOPNOTSUPP; 65 if (!vcc->dev->ops->change_qos)
66 msg->reply = -EOPNOTSUPP;
67 else { 67 else {
68 /* should lock VCC */ 68 /* should lock VCC */
69 msg->reply = vcc->dev->ops->change_qos(vcc,&msg->qos, 69 msg->reply = vcc->dev->ops->change_qos(vcc, &msg->qos,
70 msg->reply); 70 msg->reply);
71 if (!msg->reply) msg->type = as_okay; 71 if (!msg->reply)
72 msg->type = as_okay;
72 } 73 }
73 /* 74 /*
74 * Should probably just turn around the old skb. But the, the buffer 75 * Should probably just turn around the old skb. But the, the buffer
75 * space accounting needs to follow the change too. Maybe later. 76 * space accounting needs to follow the change too. Maybe later.
76 */ 77 */
77 while (!(skb = alloc_skb(sizeof(struct atmsvc_msg),GFP_KERNEL))) 78 while (!(skb = alloc_skb(sizeof(struct atmsvc_msg), GFP_KERNEL)))
78 schedule(); 79 schedule();
79 *(struct atmsvc_msg *) skb_put(skb,sizeof(struct atmsvc_msg)) = *msg; 80 *(struct atmsvc_msg *)skb_put(skb, sizeof(struct atmsvc_msg)) = *msg;
80 sigd_put_skb(skb); 81 sigd_put_skb(skb);
81} 82}
82 83
83 84static int sigd_send(struct atm_vcc *vcc, struct sk_buff *skb)
84static int sigd_send(struct atm_vcc *vcc,struct sk_buff *skb)
85{ 85{
86 struct atmsvc_msg *msg; 86 struct atmsvc_msg *msg;
87 struct atm_vcc *session_vcc; 87 struct atm_vcc *session_vcc;
@@ -90,69 +90,68 @@ static int sigd_send(struct atm_vcc *vcc,struct sk_buff *skb)
90 msg = (struct atmsvc_msg *) skb->data; 90 msg = (struct atmsvc_msg *) skb->data;
91 atomic_sub(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc); 91 atomic_sub(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
92 vcc = *(struct atm_vcc **) &msg->vcc; 92 vcc = *(struct atm_vcc **) &msg->vcc;
93 pr_debug("sigd_send %d (0x%lx)\n",(int) msg->type, 93 pr_debug("%d (0x%lx)\n", (int)msg->type, (unsigned long)vcc);
94 (unsigned long) vcc);
95 sk = sk_atm(vcc); 94 sk = sk_atm(vcc);
96 95
97 switch (msg->type) { 96 switch (msg->type) {
98 case as_okay: 97 case as_okay:
99 sk->sk_err = -msg->reply; 98 sk->sk_err = -msg->reply;
100 clear_bit(ATM_VF_WAITING, &vcc->flags); 99 clear_bit(ATM_VF_WAITING, &vcc->flags);
101 if (!*vcc->local.sas_addr.prv && 100 if (!*vcc->local.sas_addr.prv && !*vcc->local.sas_addr.pub) {
102 !*vcc->local.sas_addr.pub) { 101 vcc->local.sas_family = AF_ATMSVC;
103 vcc->local.sas_family = AF_ATMSVC; 102 memcpy(vcc->local.sas_addr.prv,
104 memcpy(vcc->local.sas_addr.prv, 103 msg->local.sas_addr.prv, ATM_ESA_LEN);
105 msg->local.sas_addr.prv,ATM_ESA_LEN); 104 memcpy(vcc->local.sas_addr.pub,
106 memcpy(vcc->local.sas_addr.pub, 105 msg->local.sas_addr.pub, ATM_E164_LEN + 1);
107 msg->local.sas_addr.pub,ATM_E164_LEN+1); 106 }
108 } 107 session_vcc = vcc->session ? vcc->session : vcc;
109 session_vcc = vcc->session ? vcc->session : vcc; 108 if (session_vcc->vpi || session_vcc->vci)
110 if (session_vcc->vpi || session_vcc->vci) break;
111 session_vcc->itf = msg->pvc.sap_addr.itf;
112 session_vcc->vpi = msg->pvc.sap_addr.vpi;
113 session_vcc->vci = msg->pvc.sap_addr.vci;
114 if (session_vcc->vpi || session_vcc->vci)
115 session_vcc->qos = msg->qos;
116 break;
117 case as_error:
118 clear_bit(ATM_VF_REGIS,&vcc->flags);
119 clear_bit(ATM_VF_READY,&vcc->flags);
120 sk->sk_err = -msg->reply;
121 clear_bit(ATM_VF_WAITING, &vcc->flags);
122 break; 109 break;
123 case as_indicate: 110 session_vcc->itf = msg->pvc.sap_addr.itf;
124 vcc = *(struct atm_vcc **) &msg->listen_vcc; 111 session_vcc->vpi = msg->pvc.sap_addr.vpi;
125 sk = sk_atm(vcc); 112 session_vcc->vci = msg->pvc.sap_addr.vci;
126 pr_debug("as_indicate!!!\n"); 113 if (session_vcc->vpi || session_vcc->vci)
127 lock_sock(sk); 114 session_vcc->qos = msg->qos;
128 if (sk_acceptq_is_full(sk)) { 115 break;
129 sigd_enq(NULL,as_reject,vcc,NULL,NULL); 116 case as_error:
130 dev_kfree_skb(skb); 117 clear_bit(ATM_VF_REGIS, &vcc->flags);
131 goto as_indicate_complete; 118 clear_bit(ATM_VF_READY, &vcc->flags);
132 } 119 sk->sk_err = -msg->reply;
133 sk->sk_ack_backlog++; 120 clear_bit(ATM_VF_WAITING, &vcc->flags);
134 skb_queue_tail(&sk->sk_receive_queue, skb); 121 break;
135 pr_debug("waking sk->sk_sleep 0x%p\n", sk->sk_sleep); 122 case as_indicate:
136 sk->sk_state_change(sk); 123 vcc = *(struct atm_vcc **)&msg->listen_vcc;
124 sk = sk_atm(vcc);
125 pr_debug("as_indicate!!!\n");
126 lock_sock(sk);
127 if (sk_acceptq_is_full(sk)) {
128 sigd_enq(NULL, as_reject, vcc, NULL, NULL);
129 dev_kfree_skb(skb);
130 goto as_indicate_complete;
131 }
132 sk->sk_ack_backlog++;
133 skb_queue_tail(&sk->sk_receive_queue, skb);
134 pr_debug("waking sk->sk_sleep 0x%p\n", sk->sk_sleep);
135 sk->sk_state_change(sk);
137as_indicate_complete: 136as_indicate_complete:
138 release_sock(sk); 137 release_sock(sk);
139 return 0; 138 return 0;
140 case as_close: 139 case as_close:
141 set_bit(ATM_VF_RELEASED,&vcc->flags); 140 set_bit(ATM_VF_RELEASED, &vcc->flags);
142 vcc_release_async(vcc, msg->reply); 141 vcc_release_async(vcc, msg->reply);
143 goto out; 142 goto out;
144 case as_modify: 143 case as_modify:
145 modify_qos(vcc,msg); 144 modify_qos(vcc, msg);
146 break; 145 break;
147 case as_addparty: 146 case as_addparty:
148 case as_dropparty: 147 case as_dropparty:
149 sk->sk_err_soft = msg->reply; /* < 0 failure, otherwise ep_ref */ 148 sk->sk_err_soft = msg->reply;
150 clear_bit(ATM_VF_WAITING, &vcc->flags); 149 /* < 0 failure, otherwise ep_ref */
151 break; 150 clear_bit(ATM_VF_WAITING, &vcc->flags);
152 default: 151 break;
153 printk(KERN_ALERT "sigd_send: bad message type %d\n", 152 default:
154 (int) msg->type); 153 pr_alert("bad message type %d\n", (int)msg->type);
155 return -EINVAL; 154 return -EINVAL;
156 } 155 }
157 sk->sk_state_change(sk); 156 sk->sk_state_change(sk);
158out: 157out:
@@ -160,48 +159,52 @@ out:
160 return 0; 159 return 0;
161} 160}
162 161
163 162void sigd_enq2(struct atm_vcc *vcc, enum atmsvc_msg_type type,
164void sigd_enq2(struct atm_vcc *vcc,enum atmsvc_msg_type type, 163 struct atm_vcc *listen_vcc, const struct sockaddr_atmpvc *pvc,
165 struct atm_vcc *listen_vcc,const struct sockaddr_atmpvc *pvc, 164 const struct sockaddr_atmsvc *svc, const struct atm_qos *qos,
166 const struct sockaddr_atmsvc *svc,const struct atm_qos *qos,int reply) 165 int reply)
167{ 166{
168 struct sk_buff *skb; 167 struct sk_buff *skb;
169 struct atmsvc_msg *msg; 168 struct atmsvc_msg *msg;
170 static unsigned session = 0; 169 static unsigned session = 0;
171 170
172 pr_debug("sigd_enq %d (0x%p)\n",(int) type,vcc); 171 pr_debug("%d (0x%p)\n", (int)type, vcc);
173 while (!(skb = alloc_skb(sizeof(struct atmsvc_msg),GFP_KERNEL))) 172 while (!(skb = alloc_skb(sizeof(struct atmsvc_msg), GFP_KERNEL)))
174 schedule(); 173 schedule();
175 msg = (struct atmsvc_msg *) skb_put(skb,sizeof(struct atmsvc_msg)); 174 msg = (struct atmsvc_msg *)skb_put(skb, sizeof(struct atmsvc_msg));
176 memset(msg,0,sizeof(*msg)); 175 memset(msg, 0, sizeof(*msg));
177 msg->type = type; 176 msg->type = type;
178 *(struct atm_vcc **) &msg->vcc = vcc; 177 *(struct atm_vcc **) &msg->vcc = vcc;
179 *(struct atm_vcc **) &msg->listen_vcc = listen_vcc; 178 *(struct atm_vcc **) &msg->listen_vcc = listen_vcc;
180 msg->reply = reply; 179 msg->reply = reply;
181 if (qos) msg->qos = *qos; 180 if (qos)
182 if (vcc) msg->sap = vcc->sap; 181 msg->qos = *qos;
183 if (svc) msg->svc = *svc; 182 if (vcc)
184 if (vcc) msg->local = vcc->local; 183 msg->sap = vcc->sap;
185 if (pvc) msg->pvc = *pvc; 184 if (svc)
185 msg->svc = *svc;
186 if (vcc)
187 msg->local = vcc->local;
188 if (pvc)
189 msg->pvc = *pvc;
186 if (vcc) { 190 if (vcc) {
187 if (type == as_connect && test_bit(ATM_VF_SESSION, &vcc->flags)) 191 if (type == as_connect && test_bit(ATM_VF_SESSION, &vcc->flags))
188 msg->session = ++session; 192 msg->session = ++session;
189 /* every new pmp connect gets the next session number */ 193 /* every new pmp connect gets the next session number */
190 } 194 }
191 sigd_put_skb(skb); 195 sigd_put_skb(skb);
192 if (vcc) set_bit(ATM_VF_REGIS,&vcc->flags); 196 if (vcc)
197 set_bit(ATM_VF_REGIS, &vcc->flags);
193} 198}
194 199
195 200void sigd_enq(struct atm_vcc *vcc, enum atmsvc_msg_type type,
196void sigd_enq(struct atm_vcc *vcc,enum atmsvc_msg_type type, 201 struct atm_vcc *listen_vcc, const struct sockaddr_atmpvc *pvc,
197 struct atm_vcc *listen_vcc,const struct sockaddr_atmpvc *pvc, 202 const struct sockaddr_atmsvc *svc)
198 const struct sockaddr_atmsvc *svc)
199{ 203{
200 sigd_enq2(vcc,type,listen_vcc,pvc,svc,vcc ? &vcc->qos : NULL,0); 204 sigd_enq2(vcc, type, listen_vcc, pvc, svc, vcc ? &vcc->qos : NULL, 0);
201 /* other ISP applications may use "reply" */ 205 /* other ISP applications may use "reply" */
202} 206}
203 207
204
205static void purge_vcc(struct atm_vcc *vcc) 208static void purge_vcc(struct atm_vcc *vcc)
206{ 209{
207 if (sk_atm(vcc)->sk_family == PF_ATMSVC && 210 if (sk_atm(vcc)->sk_family == PF_ATMSVC &&
@@ -212,21 +215,20 @@ static void purge_vcc(struct atm_vcc *vcc)
212 } 215 }
213} 216}
214 217
215
216static void sigd_close(struct atm_vcc *vcc) 218static void sigd_close(struct atm_vcc *vcc)
217{ 219{
218 struct hlist_node *node; 220 struct hlist_node *node;
219 struct sock *s; 221 struct sock *s;
220 int i; 222 int i;
221 223
222 pr_debug("sigd_close\n"); 224 pr_debug("\n");
223 sigd = NULL; 225 sigd = NULL;
224 if (skb_peek(&sk_atm(vcc)->sk_receive_queue)) 226 if (skb_peek(&sk_atm(vcc)->sk_receive_queue))
225 printk(KERN_ERR "sigd_close: closing with requests pending\n"); 227 pr_err("closing with requests pending\n");
226 skb_queue_purge(&sk_atm(vcc)->sk_receive_queue); 228 skb_queue_purge(&sk_atm(vcc)->sk_receive_queue);
227 229
228 read_lock(&vcc_sklist_lock); 230 read_lock(&vcc_sklist_lock);
229 for(i = 0; i < VCC_HTABLE_SIZE; ++i) { 231 for (i = 0; i < VCC_HTABLE_SIZE; ++i) {
230 struct hlist_head *head = &vcc_hash[i]; 232 struct hlist_head *head = &vcc_hash[i];
231 233
232 sk_for_each(s, node, head) { 234 sk_for_each(s, node, head) {
@@ -238,13 +240,11 @@ static void sigd_close(struct atm_vcc *vcc)
238 read_unlock(&vcc_sklist_lock); 240 read_unlock(&vcc_sklist_lock);
239} 241}
240 242
241
242static struct atmdev_ops sigd_dev_ops = { 243static struct atmdev_ops sigd_dev_ops = {
243 .close = sigd_close, 244 .close = sigd_close,
244 .send = sigd_send 245 .send = sigd_send
245}; 246};
246 247
247
248static struct atm_dev sigd_dev = { 248static struct atm_dev sigd_dev = {
249 .ops = &sigd_dev_ops, 249 .ops = &sigd_dev_ops,
250 .type = "sig", 250 .type = "sig",
@@ -252,16 +252,16 @@ static struct atm_dev sigd_dev = {
252 .lock = __SPIN_LOCK_UNLOCKED(sigd_dev.lock) 252 .lock = __SPIN_LOCK_UNLOCKED(sigd_dev.lock)
253}; 253};
254 254
255
256int sigd_attach(struct atm_vcc *vcc) 255int sigd_attach(struct atm_vcc *vcc)
257{ 256{
258 if (sigd) return -EADDRINUSE; 257 if (sigd)
259 pr_debug("sigd_attach\n"); 258 return -EADDRINUSE;
259 pr_debug("\n");
260 sigd = vcc; 260 sigd = vcc;
261 vcc->dev = &sigd_dev; 261 vcc->dev = &sigd_dev;
262 vcc_insert_socket(sk_atm(vcc)); 262 vcc_insert_socket(sk_atm(vcc));
263 set_bit(ATM_VF_META,&vcc->flags); 263 set_bit(ATM_VF_META, &vcc->flags);
264 set_bit(ATM_VF_READY,&vcc->flags); 264 set_bit(ATM_VF_READY, &vcc->flags);
265#ifdef WAIT_FOR_DEMON 265#ifdef WAIT_FOR_DEMON
266 wake_up(&sigd_sleep); 266 wake_up(&sigd_sleep);
267#endif 267#endif
diff --git a/net/atm/svc.c b/net/atm/svc.c
index f90d143c4b25..3ba9a45a51ac 100644
--- a/net/atm/svc.c
+++ b/net/atm/svc.c
@@ -2,6 +2,7 @@
2 2
3/* Written 1995-2000 by Werner Almesberger, EPFL LRC/ICA */ 3/* Written 1995-2000 by Werner Almesberger, EPFL LRC/ICA */
4 4
5#define pr_fmt(fmt) KBUILD_MODNAME ":%s: " fmt, __func__
5 6
6#include <linux/string.h> 7#include <linux/string.h>
7#include <linux/net.h> /* struct socket, struct proto_ops */ 8#include <linux/net.h> /* struct socket, struct proto_ops */
@@ -18,14 +19,15 @@
18#include <linux/atmdev.h> 19#include <linux/atmdev.h>
19#include <linux/bitops.h> 20#include <linux/bitops.h>
20#include <net/sock.h> /* for sock_no_* */ 21#include <net/sock.h> /* for sock_no_* */
21#include <asm/uaccess.h> 22#include <linux/uaccess.h>
22 23
23#include "resources.h" 24#include "resources.h"
24#include "common.h" /* common for PVCs and SVCs */ 25#include "common.h" /* common for PVCs and SVCs */
25#include "signaling.h" 26#include "signaling.h"
26#include "addr.h" 27#include "addr.h"
27 28
28static int svc_create(struct net *net, struct socket *sock,int protocol); 29static int svc_create(struct net *net, struct socket *sock, int protocol,
30 int kern);
29 31
30/* 32/*
31 * Note: since all this is still nicely synchronized with the signaling demon, 33 * Note: since all this is still nicely synchronized with the signaling demon,
@@ -34,25 +36,25 @@ static int svc_create(struct net *net, struct socket *sock,int protocol);
34 */ 36 */
35 37
36 38
37static int svc_shutdown(struct socket *sock,int how) 39static int svc_shutdown(struct socket *sock, int how)
38{ 40{
39 return 0; 41 return 0;
40} 42}
41 43
42
43static void svc_disconnect(struct atm_vcc *vcc) 44static void svc_disconnect(struct atm_vcc *vcc)
44{ 45{
45 DEFINE_WAIT(wait); 46 DEFINE_WAIT(wait);
46 struct sk_buff *skb; 47 struct sk_buff *skb;
47 struct sock *sk = sk_atm(vcc); 48 struct sock *sk = sk_atm(vcc);
48 49
49 pr_debug("svc_disconnect %p\n",vcc); 50 pr_debug("%p\n", vcc);
50 if (test_bit(ATM_VF_REGIS,&vcc->flags)) { 51 if (test_bit(ATM_VF_REGIS, &vcc->flags)) {
51 prepare_to_wait(sk->sk_sleep, &wait, TASK_UNINTERRUPTIBLE); 52 prepare_to_wait(sk->sk_sleep, &wait, TASK_UNINTERRUPTIBLE);
52 sigd_enq(vcc,as_close,NULL,NULL,NULL); 53 sigd_enq(vcc, as_close, NULL, NULL, NULL);
53 while (!test_bit(ATM_VF_RELEASED,&vcc->flags) && sigd) { 54 while (!test_bit(ATM_VF_RELEASED, &vcc->flags) && sigd) {
54 schedule(); 55 schedule();
55 prepare_to_wait(sk->sk_sleep, &wait, TASK_UNINTERRUPTIBLE); 56 prepare_to_wait(sk->sk_sleep, &wait,
57 TASK_UNINTERRUPTIBLE);
56 } 58 }
57 finish_wait(sk->sk_sleep, &wait); 59 finish_wait(sk->sk_sleep, &wait);
58 } 60 }
@@ -61,35 +63,35 @@ static void svc_disconnect(struct atm_vcc *vcc)
61 while ((skb = skb_dequeue(&sk->sk_receive_queue)) != NULL) { 63 while ((skb = skb_dequeue(&sk->sk_receive_queue)) != NULL) {
62 atm_return(vcc, skb->truesize); 64 atm_return(vcc, skb->truesize);
63 pr_debug("LISTEN REL\n"); 65 pr_debug("LISTEN REL\n");
64 sigd_enq2(NULL,as_reject,vcc,NULL,NULL,&vcc->qos,0); 66 sigd_enq2(NULL, as_reject, vcc, NULL, NULL, &vcc->qos, 0);
65 dev_kfree_skb(skb); 67 dev_kfree_skb(skb);
66 } 68 }
67 clear_bit(ATM_VF_REGIS, &vcc->flags); 69 clear_bit(ATM_VF_REGIS, &vcc->flags);
68 /* ... may retry later */ 70 /* ... may retry later */
69} 71}
70 72
71
72static int svc_release(struct socket *sock) 73static int svc_release(struct socket *sock)
73{ 74{
74 struct sock *sk = sock->sk; 75 struct sock *sk = sock->sk;
75 struct atm_vcc *vcc; 76 struct atm_vcc *vcc;
76 77
77 if (sk) { 78 if (sk) {
78 vcc = ATM_SD(sock); 79 vcc = ATM_SD(sock);
79 pr_debug("svc_release %p\n", vcc); 80 pr_debug("%p\n", vcc);
80 clear_bit(ATM_VF_READY, &vcc->flags); 81 clear_bit(ATM_VF_READY, &vcc->flags);
81 /* VCC pointer is used as a reference, so we must not free it 82 /*
82 (thereby subjecting it to re-use) before all pending connections 83 * VCC pointer is used as a reference,
83 are closed */ 84 * so we must not free it (thereby subjecting it to re-use)
85 * before all pending connections are closed
86 */
84 svc_disconnect(vcc); 87 svc_disconnect(vcc);
85 vcc_release(sock); 88 vcc_release(sock);
86 } 89 }
87 return 0; 90 return 0;
88} 91}
89 92
90 93static int svc_bind(struct socket *sock, struct sockaddr *sockaddr,
91static int svc_bind(struct socket *sock,struct sockaddr *sockaddr, 94 int sockaddr_len)
92 int sockaddr_len)
93{ 95{
94 DEFINE_WAIT(wait); 96 DEFINE_WAIT(wait);
95 struct sock *sk = sock->sk; 97 struct sock *sk = sock->sk;
@@ -114,38 +116,37 @@ static int svc_bind(struct socket *sock,struct sockaddr *sockaddr,
114 error = -EAFNOSUPPORT; 116 error = -EAFNOSUPPORT;
115 goto out; 117 goto out;
116 } 118 }
117 clear_bit(ATM_VF_BOUND,&vcc->flags); 119 clear_bit(ATM_VF_BOUND, &vcc->flags);
118 /* failing rebind will kill old binding */ 120 /* failing rebind will kill old binding */
119 /* @@@ check memory (de)allocation on rebind */ 121 /* @@@ check memory (de)allocation on rebind */
120 if (!test_bit(ATM_VF_HASQOS,&vcc->flags)) { 122 if (!test_bit(ATM_VF_HASQOS, &vcc->flags)) {
121 error = -EBADFD; 123 error = -EBADFD;
122 goto out; 124 goto out;
123 } 125 }
124 vcc->local = *addr; 126 vcc->local = *addr;
125 set_bit(ATM_VF_WAITING, &vcc->flags); 127 set_bit(ATM_VF_WAITING, &vcc->flags);
126 prepare_to_wait(sk->sk_sleep, &wait, TASK_UNINTERRUPTIBLE); 128 prepare_to_wait(sk->sk_sleep, &wait, TASK_UNINTERRUPTIBLE);
127 sigd_enq(vcc,as_bind,NULL,NULL,&vcc->local); 129 sigd_enq(vcc, as_bind, NULL, NULL, &vcc->local);
128 while (test_bit(ATM_VF_WAITING, &vcc->flags) && sigd) { 130 while (test_bit(ATM_VF_WAITING, &vcc->flags) && sigd) {
129 schedule(); 131 schedule();
130 prepare_to_wait(sk->sk_sleep, &wait, TASK_UNINTERRUPTIBLE); 132 prepare_to_wait(sk->sk_sleep, &wait, TASK_UNINTERRUPTIBLE);
131 } 133 }
132 finish_wait(sk->sk_sleep, &wait); 134 finish_wait(sk->sk_sleep, &wait);
133 clear_bit(ATM_VF_REGIS,&vcc->flags); /* doesn't count */ 135 clear_bit(ATM_VF_REGIS, &vcc->flags); /* doesn't count */
134 if (!sigd) { 136 if (!sigd) {
135 error = -EUNATCH; 137 error = -EUNATCH;
136 goto out; 138 goto out;
137 } 139 }
138 if (!sk->sk_err) 140 if (!sk->sk_err)
139 set_bit(ATM_VF_BOUND,&vcc->flags); 141 set_bit(ATM_VF_BOUND, &vcc->flags);
140 error = -sk->sk_err; 142 error = -sk->sk_err;
141out: 143out:
142 release_sock(sk); 144 release_sock(sk);
143 return error; 145 return error;
144} 146}
145 147
146 148static int svc_connect(struct socket *sock, struct sockaddr *sockaddr,
147static int svc_connect(struct socket *sock,struct sockaddr *sockaddr, 149 int sockaddr_len, int flags)
148 int sockaddr_len,int flags)
149{ 150{
150 DEFINE_WAIT(wait); 151 DEFINE_WAIT(wait);
151 struct sock *sk = sock->sk; 152 struct sock *sk = sock->sk;
@@ -153,7 +154,7 @@ static int svc_connect(struct socket *sock,struct sockaddr *sockaddr,
153 struct atm_vcc *vcc = ATM_SD(sock); 154 struct atm_vcc *vcc = ATM_SD(sock);
154 int error; 155 int error;
155 156
156 pr_debug("svc_connect %p\n",vcc); 157 pr_debug("%p\n", vcc);
157 lock_sock(sk); 158 lock_sock(sk);
158 if (sockaddr_len != sizeof(struct sockaddr_atmsvc)) { 159 if (sockaddr_len != sizeof(struct sockaddr_atmsvc)) {
159 error = -EINVAL; 160 error = -EINVAL;
@@ -201,7 +202,7 @@ static int svc_connect(struct socket *sock,struct sockaddr *sockaddr,
201 vcc->remote = *addr; 202 vcc->remote = *addr;
202 set_bit(ATM_VF_WAITING, &vcc->flags); 203 set_bit(ATM_VF_WAITING, &vcc->flags);
203 prepare_to_wait(sk->sk_sleep, &wait, TASK_INTERRUPTIBLE); 204 prepare_to_wait(sk->sk_sleep, &wait, TASK_INTERRUPTIBLE);
204 sigd_enq(vcc,as_connect,NULL,NULL,&vcc->remote); 205 sigd_enq(vcc, as_connect, NULL, NULL, &vcc->remote);
205 if (flags & O_NONBLOCK) { 206 if (flags & O_NONBLOCK) {
206 finish_wait(sk->sk_sleep, &wait); 207 finish_wait(sk->sk_sleep, &wait);
207 sock->state = SS_CONNECTING; 208 sock->state = SS_CONNECTING;
@@ -212,7 +213,8 @@ static int svc_connect(struct socket *sock,struct sockaddr *sockaddr,
212 while (test_bit(ATM_VF_WAITING, &vcc->flags) && sigd) { 213 while (test_bit(ATM_VF_WAITING, &vcc->flags) && sigd) {
213 schedule(); 214 schedule();
214 if (!signal_pending(current)) { 215 if (!signal_pending(current)) {
215 prepare_to_wait(sk->sk_sleep, &wait, TASK_INTERRUPTIBLE); 216 prepare_to_wait(sk->sk_sleep, &wait,
217 TASK_INTERRUPTIBLE);
216 continue; 218 continue;
217 } 219 }
218 pr_debug("*ABORT*\n"); 220 pr_debug("*ABORT*\n");
@@ -228,20 +230,22 @@ static int svc_connect(struct socket *sock,struct sockaddr *sockaddr,
228 * Kernel <--okay---- Demon 230 * Kernel <--okay---- Demon
229 * Kernel <--close--- Demon 231 * Kernel <--close--- Demon
230 */ 232 */
231 sigd_enq(vcc,as_close,NULL,NULL,NULL); 233 sigd_enq(vcc, as_close, NULL, NULL, NULL);
232 while (test_bit(ATM_VF_WAITING, &vcc->flags) && sigd) { 234 while (test_bit(ATM_VF_WAITING, &vcc->flags) && sigd) {
233 prepare_to_wait(sk->sk_sleep, &wait, TASK_INTERRUPTIBLE); 235 prepare_to_wait(sk->sk_sleep, &wait,
236 TASK_INTERRUPTIBLE);
234 schedule(); 237 schedule();
235 } 238 }
236 if (!sk->sk_err) 239 if (!sk->sk_err)
237 while (!test_bit(ATM_VF_RELEASED,&vcc->flags) 240 while (!test_bit(ATM_VF_RELEASED, &vcc->flags) &&
238 && sigd) { 241 sigd) {
239 prepare_to_wait(sk->sk_sleep, &wait, TASK_INTERRUPTIBLE); 242 prepare_to_wait(sk->sk_sleep, &wait,
243 TASK_INTERRUPTIBLE);
240 schedule(); 244 schedule();
241 } 245 }
242 clear_bit(ATM_VF_REGIS,&vcc->flags); 246 clear_bit(ATM_VF_REGIS, &vcc->flags);
243 clear_bit(ATM_VF_RELEASED,&vcc->flags); 247 clear_bit(ATM_VF_RELEASED, &vcc->flags);
244 clear_bit(ATM_VF_CLOSE,&vcc->flags); 248 clear_bit(ATM_VF_CLOSE, &vcc->flags);
245 /* we're gone now but may connect later */ 249 /* we're gone now but may connect later */
246 error = -EINTR; 250 error = -EINTR;
247 break; 251 break;
@@ -269,37 +273,37 @@ static int svc_connect(struct socket *sock,struct sockaddr *sockaddr,
269/* 273/*
270 * #endif 274 * #endif
271 */ 275 */
272 if (!(error = vcc_connect(sock, vcc->itf, vcc->vpi, vcc->vci))) 276 error = vcc_connect(sock, vcc->itf, vcc->vpi, vcc->vci);
277 if (!error)
273 sock->state = SS_CONNECTED; 278 sock->state = SS_CONNECTED;
274 else 279 else
275 (void) svc_disconnect(vcc); 280 (void)svc_disconnect(vcc);
276out: 281out:
277 release_sock(sk); 282 release_sock(sk);
278 return error; 283 return error;
279} 284}
280 285
281 286static int svc_listen(struct socket *sock, int backlog)
282static int svc_listen(struct socket *sock,int backlog)
283{ 287{
284 DEFINE_WAIT(wait); 288 DEFINE_WAIT(wait);
285 struct sock *sk = sock->sk; 289 struct sock *sk = sock->sk;
286 struct atm_vcc *vcc = ATM_SD(sock); 290 struct atm_vcc *vcc = ATM_SD(sock);
287 int error; 291 int error;
288 292
289 pr_debug("svc_listen %p\n",vcc); 293 pr_debug("%p\n", vcc);
290 lock_sock(sk); 294 lock_sock(sk);
291 /* let server handle listen on unbound sockets */ 295 /* let server handle listen on unbound sockets */
292 if (test_bit(ATM_VF_SESSION,&vcc->flags)) { 296 if (test_bit(ATM_VF_SESSION, &vcc->flags)) {
293 error = -EINVAL; 297 error = -EINVAL;
294 goto out; 298 goto out;
295 } 299 }
296 if (test_bit(ATM_VF_LISTEN, &vcc->flags)) { 300 if (test_bit(ATM_VF_LISTEN, &vcc->flags)) {
297 error = -EADDRINUSE; 301 error = -EADDRINUSE;
298 goto out; 302 goto out;
299 } 303 }
300 set_bit(ATM_VF_WAITING, &vcc->flags); 304 set_bit(ATM_VF_WAITING, &vcc->flags);
301 prepare_to_wait(sk->sk_sleep, &wait, TASK_UNINTERRUPTIBLE); 305 prepare_to_wait(sk->sk_sleep, &wait, TASK_UNINTERRUPTIBLE);
302 sigd_enq(vcc,as_listen,NULL,NULL,&vcc->local); 306 sigd_enq(vcc, as_listen, NULL, NULL, &vcc->local);
303 while (test_bit(ATM_VF_WAITING, &vcc->flags) && sigd) { 307 while (test_bit(ATM_VF_WAITING, &vcc->flags) && sigd) {
304 schedule(); 308 schedule();
305 prepare_to_wait(sk->sk_sleep, &wait, TASK_UNINTERRUPTIBLE); 309 prepare_to_wait(sk->sk_sleep, &wait, TASK_UNINTERRUPTIBLE);
@@ -309,7 +313,7 @@ static int svc_listen(struct socket *sock,int backlog)
309 error = -EUNATCH; 313 error = -EUNATCH;
310 goto out; 314 goto out;
311 } 315 }
312 set_bit(ATM_VF_LISTEN,&vcc->flags); 316 set_bit(ATM_VF_LISTEN, &vcc->flags);
313 vcc_insert_socket(sk); 317 vcc_insert_socket(sk);
314 sk->sk_max_ack_backlog = backlog > 0 ? backlog : ATM_BACKLOG_DEFAULT; 318 sk->sk_max_ack_backlog = backlog > 0 ? backlog : ATM_BACKLOG_DEFAULT;
315 error = -sk->sk_err; 319 error = -sk->sk_err;
@@ -318,8 +322,7 @@ out:
318 return error; 322 return error;
319} 323}
320 324
321 325static int svc_accept(struct socket *sock, struct socket *newsock, int flags)
322static int svc_accept(struct socket *sock,struct socket *newsock,int flags)
323{ 326{
324 struct sock *sk = sock->sk; 327 struct sock *sk = sock->sk;
325 struct sk_buff *skb; 328 struct sk_buff *skb;
@@ -330,21 +333,22 @@ static int svc_accept(struct socket *sock,struct socket *newsock,int flags)
330 333
331 lock_sock(sk); 334 lock_sock(sk);
332 335
333 error = svc_create(sock_net(sk), newsock,0); 336 error = svc_create(sock_net(sk), newsock, 0, 0);
334 if (error) 337 if (error)
335 goto out; 338 goto out;
336 339
337 new_vcc = ATM_SD(newsock); 340 new_vcc = ATM_SD(newsock);
338 341
339 pr_debug("svc_accept %p -> %p\n",old_vcc,new_vcc); 342 pr_debug("%p -> %p\n", old_vcc, new_vcc);
340 while (1) { 343 while (1) {
341 DEFINE_WAIT(wait); 344 DEFINE_WAIT(wait);
342 345
343 prepare_to_wait(sk->sk_sleep, &wait, TASK_INTERRUPTIBLE); 346 prepare_to_wait(sk->sk_sleep, &wait, TASK_INTERRUPTIBLE);
344 while (!(skb = skb_dequeue(&sk->sk_receive_queue)) && 347 while (!(skb = skb_dequeue(&sk->sk_receive_queue)) &&
345 sigd) { 348 sigd) {
346 if (test_bit(ATM_VF_RELEASED,&old_vcc->flags)) break; 349 if (test_bit(ATM_VF_RELEASED, &old_vcc->flags))
347 if (test_bit(ATM_VF_CLOSE,&old_vcc->flags)) { 350 break;
351 if (test_bit(ATM_VF_CLOSE, &old_vcc->flags)) {
348 error = -sk->sk_err; 352 error = -sk->sk_err;
349 break; 353 break;
350 } 354 }
@@ -359,7 +363,8 @@ static int svc_accept(struct socket *sock,struct socket *newsock,int flags)
359 error = -ERESTARTSYS; 363 error = -ERESTARTSYS;
360 break; 364 break;
361 } 365 }
362 prepare_to_wait(sk->sk_sleep, &wait, TASK_INTERRUPTIBLE); 366 prepare_to_wait(sk->sk_sleep, &wait,
367 TASK_INTERRUPTIBLE);
363 } 368 }
364 finish_wait(sk->sk_sleep, &wait); 369 finish_wait(sk->sk_sleep, &wait);
365 if (error) 370 if (error)
@@ -368,31 +373,34 @@ static int svc_accept(struct socket *sock,struct socket *newsock,int flags)
368 error = -EUNATCH; 373 error = -EUNATCH;
369 goto out; 374 goto out;
370 } 375 }
371 msg = (struct atmsvc_msg *) skb->data; 376 msg = (struct atmsvc_msg *)skb->data;
372 new_vcc->qos = msg->qos; 377 new_vcc->qos = msg->qos;
373 set_bit(ATM_VF_HASQOS,&new_vcc->flags); 378 set_bit(ATM_VF_HASQOS, &new_vcc->flags);
374 new_vcc->remote = msg->svc; 379 new_vcc->remote = msg->svc;
375 new_vcc->local = msg->local; 380 new_vcc->local = msg->local;
376 new_vcc->sap = msg->sap; 381 new_vcc->sap = msg->sap;
377 error = vcc_connect(newsock, msg->pvc.sap_addr.itf, 382 error = vcc_connect(newsock, msg->pvc.sap_addr.itf,
378 msg->pvc.sap_addr.vpi, msg->pvc.sap_addr.vci); 383 msg->pvc.sap_addr.vpi,
384 msg->pvc.sap_addr.vci);
379 dev_kfree_skb(skb); 385 dev_kfree_skb(skb);
380 sk->sk_ack_backlog--; 386 sk->sk_ack_backlog--;
381 if (error) { 387 if (error) {
382 sigd_enq2(NULL,as_reject,old_vcc,NULL,NULL, 388 sigd_enq2(NULL, as_reject, old_vcc, NULL, NULL,
383 &old_vcc->qos,error); 389 &old_vcc->qos, error);
384 error = error == -EAGAIN ? -EBUSY : error; 390 error = error == -EAGAIN ? -EBUSY : error;
385 goto out; 391 goto out;
386 } 392 }
387 /* wait should be short, so we ignore the non-blocking flag */ 393 /* wait should be short, so we ignore the non-blocking flag */
388 set_bit(ATM_VF_WAITING, &new_vcc->flags); 394 set_bit(ATM_VF_WAITING, &new_vcc->flags);
389 prepare_to_wait(sk_atm(new_vcc)->sk_sleep, &wait, TASK_UNINTERRUPTIBLE); 395 prepare_to_wait(sk_atm(new_vcc)->sk_sleep, &wait,
390 sigd_enq(new_vcc,as_accept,old_vcc,NULL,NULL); 396 TASK_UNINTERRUPTIBLE);
397 sigd_enq(new_vcc, as_accept, old_vcc, NULL, NULL);
391 while (test_bit(ATM_VF_WAITING, &new_vcc->flags) && sigd) { 398 while (test_bit(ATM_VF_WAITING, &new_vcc->flags) && sigd) {
392 release_sock(sk); 399 release_sock(sk);
393 schedule(); 400 schedule();
394 lock_sock(sk); 401 lock_sock(sk);
395 prepare_to_wait(sk_atm(new_vcc)->sk_sleep, &wait, TASK_UNINTERRUPTIBLE); 402 prepare_to_wait(sk_atm(new_vcc)->sk_sleep, &wait,
403 TASK_UNINTERRUPTIBLE);
396 } 404 }
397 finish_wait(sk_atm(new_vcc)->sk_sleep, &wait); 405 finish_wait(sk_atm(new_vcc)->sk_sleep, &wait);
398 if (!sigd) { 406 if (!sigd) {
@@ -412,39 +420,37 @@ out:
412 return error; 420 return error;
413} 421}
414 422
415 423static int svc_getname(struct socket *sock, struct sockaddr *sockaddr,
416static int svc_getname(struct socket *sock,struct sockaddr *sockaddr, 424 int *sockaddr_len, int peer)
417 int *sockaddr_len,int peer)
418{ 425{
419 struct sockaddr_atmsvc *addr; 426 struct sockaddr_atmsvc *addr;
420 427
421 *sockaddr_len = sizeof(struct sockaddr_atmsvc); 428 *sockaddr_len = sizeof(struct sockaddr_atmsvc);
422 addr = (struct sockaddr_atmsvc *) sockaddr; 429 addr = (struct sockaddr_atmsvc *) sockaddr;
423 memcpy(addr,peer ? &ATM_SD(sock)->remote : &ATM_SD(sock)->local, 430 memcpy(addr, peer ? &ATM_SD(sock)->remote : &ATM_SD(sock)->local,
424 sizeof(struct sockaddr_atmsvc)); 431 sizeof(struct sockaddr_atmsvc));
425 return 0; 432 return 0;
426} 433}
427 434
428 435int svc_change_qos(struct atm_vcc *vcc, struct atm_qos *qos)
429int svc_change_qos(struct atm_vcc *vcc,struct atm_qos *qos)
430{ 436{
431 struct sock *sk = sk_atm(vcc); 437 struct sock *sk = sk_atm(vcc);
432 DEFINE_WAIT(wait); 438 DEFINE_WAIT(wait);
433 439
434 set_bit(ATM_VF_WAITING, &vcc->flags); 440 set_bit(ATM_VF_WAITING, &vcc->flags);
435 prepare_to_wait(sk->sk_sleep, &wait, TASK_UNINTERRUPTIBLE); 441 prepare_to_wait(sk->sk_sleep, &wait, TASK_UNINTERRUPTIBLE);
436 sigd_enq2(vcc,as_modify,NULL,NULL,&vcc->local,qos,0); 442 sigd_enq2(vcc, as_modify, NULL, NULL, &vcc->local, qos, 0);
437 while (test_bit(ATM_VF_WAITING, &vcc->flags) && 443 while (test_bit(ATM_VF_WAITING, &vcc->flags) &&
438 !test_bit(ATM_VF_RELEASED, &vcc->flags) && sigd) { 444 !test_bit(ATM_VF_RELEASED, &vcc->flags) && sigd) {
439 schedule(); 445 schedule();
440 prepare_to_wait(sk->sk_sleep, &wait, TASK_UNINTERRUPTIBLE); 446 prepare_to_wait(sk->sk_sleep, &wait, TASK_UNINTERRUPTIBLE);
441 } 447 }
442 finish_wait(sk->sk_sleep, &wait); 448 finish_wait(sk->sk_sleep, &wait);
443 if (!sigd) return -EUNATCH; 449 if (!sigd)
450 return -EUNATCH;
444 return -sk->sk_err; 451 return -sk->sk_err;
445} 452}
446 453
447
448static int svc_setsockopt(struct socket *sock, int level, int optname, 454static int svc_setsockopt(struct socket *sock, int level, int optname,
449 char __user *optval, unsigned int optlen) 455 char __user *optval, unsigned int optlen)
450{ 456{
@@ -454,37 +460,35 @@ static int svc_setsockopt(struct socket *sock, int level, int optname,
454 460
455 lock_sock(sk); 461 lock_sock(sk);
456 switch (optname) { 462 switch (optname) {
457 case SO_ATMSAP: 463 case SO_ATMSAP:
458 if (level != SOL_ATM || optlen != sizeof(struct atm_sap)) { 464 if (level != SOL_ATM || optlen != sizeof(struct atm_sap)) {
459 error = -EINVAL; 465 error = -EINVAL;
460 goto out; 466 goto out;
461 } 467 }
462 if (copy_from_user(&vcc->sap, optval, optlen)) { 468 if (copy_from_user(&vcc->sap, optval, optlen)) {
463 error = -EFAULT; 469 error = -EFAULT;
464 goto out; 470 goto out;
465 } 471 }
466 set_bit(ATM_VF_HASSAP, &vcc->flags); 472 set_bit(ATM_VF_HASSAP, &vcc->flags);
467 break; 473 break;
468 case SO_MULTIPOINT: 474 case SO_MULTIPOINT:
469 if (level != SOL_ATM || optlen != sizeof(int)) { 475 if (level != SOL_ATM || optlen != sizeof(int)) {
470 error = -EINVAL; 476 error = -EINVAL;
471 goto out; 477 goto out;
472 } 478 }
473 if (get_user(value, (int __user *) optval)) { 479 if (get_user(value, (int __user *)optval)) {
474 error = -EFAULT; 480 error = -EFAULT;
475 goto out; 481 goto out;
476 } 482 }
477 if (value == 1) { 483 if (value == 1)
478 set_bit(ATM_VF_SESSION, &vcc->flags); 484 set_bit(ATM_VF_SESSION, &vcc->flags);
479 } else if (value == 0) { 485 else if (value == 0)
480 clear_bit(ATM_VF_SESSION, &vcc->flags); 486 clear_bit(ATM_VF_SESSION, &vcc->flags);
481 } else { 487 else
482 error = -EINVAL; 488 error = -EINVAL;
483 } 489 break;
484 break; 490 default:
485 default: 491 error = vcc_setsockopt(sock, level, optname, optval, optlen);
486 error = vcc_setsockopt(sock, level, optname,
487 optval, optlen);
488 } 492 }
489 493
490out: 494out:
@@ -492,9 +496,8 @@ out:
492 return error; 496 return error;
493} 497}
494 498
495 499static int svc_getsockopt(struct socket *sock, int level, int optname,
496static int svc_getsockopt(struct socket *sock,int level,int optname, 500 char __user *optval, int __user *optlen)
497 char __user *optval,int __user *optlen)
498{ 501{
499 struct sock *sk = sock->sk; 502 struct sock *sk = sock->sk;
500 int error = 0, len; 503 int error = 0, len;
@@ -521,7 +524,6 @@ out:
521 return error; 524 return error;
522} 525}
523 526
524
525static int svc_addparty(struct socket *sock, struct sockaddr *sockaddr, 527static int svc_addparty(struct socket *sock, struct sockaddr *sockaddr,
526 int sockaddr_len, int flags) 528 int sockaddr_len, int flags)
527{ 529{
@@ -540,7 +542,7 @@ static int svc_addparty(struct socket *sock, struct sockaddr *sockaddr,
540 error = -EINPROGRESS; 542 error = -EINPROGRESS;
541 goto out; 543 goto out;
542 } 544 }
543 pr_debug("svc_addparty added wait queue\n"); 545 pr_debug("added wait queue\n");
544 while (test_bit(ATM_VF_WAITING, &vcc->flags) && sigd) { 546 while (test_bit(ATM_VF_WAITING, &vcc->flags) && sigd) {
545 schedule(); 547 schedule();
546 prepare_to_wait(sk->sk_sleep, &wait, TASK_INTERRUPTIBLE); 548 prepare_to_wait(sk->sk_sleep, &wait, TASK_INTERRUPTIBLE);
@@ -552,7 +554,6 @@ out:
552 return error; 554 return error;
553} 555}
554 556
555
556static int svc_dropparty(struct socket *sock, int ep_ref) 557static int svc_dropparty(struct socket *sock, int ep_ref)
557{ 558{
558 DEFINE_WAIT(wait); 559 DEFINE_WAIT(wait);
@@ -579,7 +580,6 @@ out:
579 return error; 580 return error;
580} 581}
581 582
582
583static int svc_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg) 583static int svc_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
584{ 584{
585 int error, ep_ref; 585 int error, ep_ref;
@@ -587,29 +587,31 @@ static int svc_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
587 struct atm_vcc *vcc = ATM_SD(sock); 587 struct atm_vcc *vcc = ATM_SD(sock);
588 588
589 switch (cmd) { 589 switch (cmd) {
590 case ATM_ADDPARTY: 590 case ATM_ADDPARTY:
591 if (!test_bit(ATM_VF_SESSION, &vcc->flags)) 591 if (!test_bit(ATM_VF_SESSION, &vcc->flags))
592 return -EINVAL; 592 return -EINVAL;
593 if (copy_from_user(&sa, (void __user *) arg, sizeof(sa))) 593 if (copy_from_user(&sa, (void __user *) arg, sizeof(sa)))
594 return -EFAULT; 594 return -EFAULT;
595 error = svc_addparty(sock, (struct sockaddr *) &sa, sizeof(sa), 0); 595 error = svc_addparty(sock, (struct sockaddr *)&sa, sizeof(sa),
596 break; 596 0);
597 case ATM_DROPPARTY: 597 break;
598 if (!test_bit(ATM_VF_SESSION, &vcc->flags)) 598 case ATM_DROPPARTY:
599 return -EINVAL; 599 if (!test_bit(ATM_VF_SESSION, &vcc->flags))
600 if (copy_from_user(&ep_ref, (void __user *) arg, sizeof(int))) 600 return -EINVAL;
601 return -EFAULT; 601 if (copy_from_user(&ep_ref, (void __user *) arg, sizeof(int)))
602 error = svc_dropparty(sock, ep_ref); 602 return -EFAULT;
603 break; 603 error = svc_dropparty(sock, ep_ref);
604 default: 604 break;
605 error = vcc_ioctl(sock, cmd, arg); 605 default:
606 error = vcc_ioctl(sock, cmd, arg);
606 } 607 }
607 608
608 return error; 609 return error;
609} 610}
610 611
611#ifdef CONFIG_COMPAT 612#ifdef CONFIG_COMPAT
612static int svc_compat_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg) 613static int svc_compat_ioctl(struct socket *sock, unsigned int cmd,
614 unsigned long arg)
613{ 615{
614 /* The definition of ATM_ADDPARTY uses the size of struct atm_iobuf. 616 /* 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 617 But actually it takes a struct sockaddr_atmsvc, which doesn't need
@@ -650,23 +652,24 @@ static const struct proto_ops svc_proto_ops = {
650}; 652};
651 653
652 654
653static int svc_create(struct net *net, struct socket *sock,int protocol) 655static int svc_create(struct net *net, struct socket *sock, int protocol,
656 int kern)
654{ 657{
655 int error; 658 int error;
656 659
657 if (net != &init_net) 660 if (!net_eq(net, &init_net))
658 return -EAFNOSUPPORT; 661 return -EAFNOSUPPORT;
659 662
660 sock->ops = &svc_proto_ops; 663 sock->ops = &svc_proto_ops;
661 error = vcc_create(net, sock, protocol, AF_ATMSVC); 664 error = vcc_create(net, sock, protocol, AF_ATMSVC);
662 if (error) return error; 665 if (error)
666 return error;
663 ATM_SD(sock)->local.sas_family = AF_ATMSVC; 667 ATM_SD(sock)->local.sas_family = AF_ATMSVC;
664 ATM_SD(sock)->remote.sas_family = AF_ATMSVC; 668 ATM_SD(sock)->remote.sas_family = AF_ATMSVC;
665 return 0; 669 return 0;
666} 670}
667 671
668 672static const struct net_proto_family svc_family_ops = {
669static struct net_proto_family svc_family_ops = {
670 .family = PF_ATMSVC, 673 .family = PF_ATMSVC,
671 .create = svc_create, 674 .create = svc_create,
672 .owner = THIS_MODULE, 675 .owner = THIS_MODULE,
diff --git a/net/ax25/af_ax25.c b/net/ax25/af_ax25.c
index f45460730371..65c5801261f9 100644
--- a/net/ax25/af_ax25.c
+++ b/net/ax25/af_ax25.c
@@ -25,6 +25,7 @@
25#include <linux/string.h> 25#include <linux/string.h>
26#include <linux/sockios.h> 26#include <linux/sockios.h>
27#include <linux/net.h> 27#include <linux/net.h>
28#include <linux/slab.h>
28#include <net/ax25.h> 29#include <net/ax25.h>
29#include <linux/inet.h> 30#include <linux/inet.h>
30#include <linux/netdevice.h> 31#include <linux/netdevice.h>
@@ -369,6 +370,9 @@ static int ax25_ctl_ioctl(const unsigned int cmd, void __user *arg)
369 if (ax25_ctl.digi_count > AX25_MAX_DIGIS) 370 if (ax25_ctl.digi_count > AX25_MAX_DIGIS)
370 return -EINVAL; 371 return -EINVAL;
371 372
373 if (ax25_ctl.arg > ULONG_MAX / HZ && ax25_ctl.cmd != AX25_KILL)
374 return -EINVAL;
375
372 digi.ndigi = ax25_ctl.digi_count; 376 digi.ndigi = ax25_ctl.digi_count;
373 for (k = 0; k < digi.ndigi; k++) 377 for (k = 0; k < digi.ndigi; k++)
374 digi.calls[k] = ax25_ctl.digi_addr[k]; 378 digi.calls[k] = ax25_ctl.digi_addr[k];
@@ -418,14 +422,10 @@ static int ax25_ctl_ioctl(const unsigned int cmd, void __user *arg)
418 break; 422 break;
419 423
420 case AX25_T3: 424 case AX25_T3:
421 if (ax25_ctl.arg < 0)
422 goto einval_put;
423 ax25->t3 = ax25_ctl.arg * HZ; 425 ax25->t3 = ax25_ctl.arg * HZ;
424 break; 426 break;
425 427
426 case AX25_IDLE: 428 case AX25_IDLE:
427 if (ax25_ctl.arg < 0)
428 goto einval_put;
429 ax25->idle = ax25_ctl.arg * 60 * HZ; 429 ax25->idle = ax25_ctl.arg * 60 * HZ;
430 break; 430 break;
431 431
@@ -800,12 +800,13 @@ static struct proto ax25_proto = {
800 .obj_size = sizeof(struct sock), 800 .obj_size = sizeof(struct sock),
801}; 801};
802 802
803static int ax25_create(struct net *net, struct socket *sock, int protocol) 803static int ax25_create(struct net *net, struct socket *sock, int protocol,
804 int kern)
804{ 805{
805 struct sock *sk; 806 struct sock *sk;
806 ax25_cb *ax25; 807 ax25_cb *ax25;
807 808
808 if (net != &init_net) 809 if (!net_eq(net, &init_net))
809 return -EAFNOSUPPORT; 810 return -EAFNOSUPPORT;
810 811
811 switch (sock->type) { 812 switch (sock->type) {
@@ -1863,25 +1864,13 @@ static int ax25_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
1863static void *ax25_info_start(struct seq_file *seq, loff_t *pos) 1864static void *ax25_info_start(struct seq_file *seq, loff_t *pos)
1864 __acquires(ax25_list_lock) 1865 __acquires(ax25_list_lock)
1865{ 1866{
1866 struct ax25_cb *ax25;
1867 struct hlist_node *node;
1868 int i = 0;
1869
1870 spin_lock_bh(&ax25_list_lock); 1867 spin_lock_bh(&ax25_list_lock);
1871 ax25_for_each(ax25, node, &ax25_list) { 1868 return seq_hlist_start(&ax25_list, *pos);
1872 if (i == *pos)
1873 return ax25;
1874 ++i;
1875 }
1876 return NULL;
1877} 1869}
1878 1870
1879static void *ax25_info_next(struct seq_file *seq, void *v, loff_t *pos) 1871static void *ax25_info_next(struct seq_file *seq, void *v, loff_t *pos)
1880{ 1872{
1881 ++*pos; 1873 return seq_hlist_next(v, &ax25_list, pos);
1882
1883 return hlist_entry( ((struct ax25_cb *)v)->ax25_node.next,
1884 struct ax25_cb, ax25_node);
1885} 1874}
1886 1875
1887static void ax25_info_stop(struct seq_file *seq, void *v) 1876static void ax25_info_stop(struct seq_file *seq, void *v)
@@ -1892,7 +1881,7 @@ static void ax25_info_stop(struct seq_file *seq, void *v)
1892 1881
1893static int ax25_info_show(struct seq_file *seq, void *v) 1882static int ax25_info_show(struct seq_file *seq, void *v)
1894{ 1883{
1895 ax25_cb *ax25 = v; 1884 ax25_cb *ax25 = hlist_entry(v, struct ax25_cb, ax25_node);
1896 char buf[11]; 1885 char buf[11];
1897 int k; 1886 int k;
1898 1887
@@ -1961,7 +1950,7 @@ static const struct file_operations ax25_info_fops = {
1961 1950
1962#endif 1951#endif
1963 1952
1964static struct net_proto_family ax25_family_ops = { 1953static const struct net_proto_family ax25_family_ops = {
1965 .family = PF_AX25, 1954 .family = PF_AX25,
1966 .create = ax25_create, 1955 .create = ax25_create,
1967 .owner = THIS_MODULE, 1956 .owner = THIS_MODULE,
diff --git a/net/ax25/ax25_dev.c b/net/ax25/ax25_dev.c
index a7a0e0c9698b..c1cb982f6e86 100644
--- a/net/ax25/ax25_dev.c
+++ b/net/ax25/ax25_dev.c
@@ -9,6 +9,7 @@
9#include <linux/errno.h> 9#include <linux/errno.h>
10#include <linux/types.h> 10#include <linux/types.h>
11#include <linux/socket.h> 11#include <linux/socket.h>
12#include <linux/slab.h>
12#include <linux/in.h> 13#include <linux/in.h>
13#include <linux/kernel.h> 14#include <linux/kernel.h>
14#include <linux/timer.h> 15#include <linux/timer.h>
diff --git a/net/ax25/ax25_ds_subr.c b/net/ax25/ax25_ds_subr.c
index b5e59787be2f..85816e612dc0 100644
--- a/net/ax25/ax25_ds_subr.c
+++ b/net/ax25/ax25_ds_subr.c
@@ -17,6 +17,7 @@
17#include <linux/sockios.h> 17#include <linux/sockios.h>
18#include <linux/spinlock.h> 18#include <linux/spinlock.h>
19#include <linux/net.h> 19#include <linux/net.h>
20#include <linux/gfp.h>
20#include <net/ax25.h> 21#include <net/ax25.h>
21#include <linux/inet.h> 22#include <linux/inet.h>
22#include <linux/netdevice.h> 23#include <linux/netdevice.h>
diff --git a/net/ax25/ax25_iface.c b/net/ax25/ax25_iface.c
index 71338f112108..5a0dda8df492 100644
--- a/net/ax25/ax25_iface.c
+++ b/net/ax25/ax25_iface.c
@@ -17,6 +17,7 @@
17#include <linux/string.h> 17#include <linux/string.h>
18#include <linux/sockios.h> 18#include <linux/sockios.h>
19#include <linux/net.h> 19#include <linux/net.h>
20#include <linux/slab.h>
20#include <net/ax25.h> 21#include <net/ax25.h>
21#include <linux/inet.h> 22#include <linux/inet.h>
22#include <linux/netdevice.h> 23#include <linux/netdevice.h>
diff --git a/net/ax25/ax25_in.c b/net/ax25/ax25_in.c
index de56d3983de0..9bb776541203 100644
--- a/net/ax25/ax25_in.c
+++ b/net/ax25/ax25_in.c
@@ -18,6 +18,7 @@
18#include <linux/string.h> 18#include <linux/string.h>
19#include <linux/sockios.h> 19#include <linux/sockios.h>
20#include <linux/net.h> 20#include <linux/net.h>
21#include <linux/slab.h>
21#include <net/ax25.h> 22#include <net/ax25.h>
22#include <linux/inet.h> 23#include <linux/inet.h>
23#include <linux/netdevice.h> 24#include <linux/netdevice.h>
diff --git a/net/ax25/ax25_ip.c b/net/ax25/ax25_ip.c
index f047a57aa95c..cf0c47a26530 100644
--- a/net/ax25/ax25_ip.c
+++ b/net/ax25/ax25_ip.c
@@ -16,6 +16,7 @@
16#include <linux/string.h> 16#include <linux/string.h>
17#include <linux/sockios.h> 17#include <linux/sockios.h>
18#include <linux/net.h> 18#include <linux/net.h>
19#include <linux/slab.h>
19#include <net/ax25.h> 20#include <net/ax25.h>
20#include <linux/inet.h> 21#include <linux/inet.h>
21#include <linux/netdevice.h> 22#include <linux/netdevice.h>
diff --git a/net/ax25/ax25_out.c b/net/ax25/ax25_out.c
index bf706f83a5c9..37507d806f65 100644
--- a/net/ax25/ax25_out.c
+++ b/net/ax25/ax25_out.c
@@ -19,6 +19,7 @@
19#include <linux/sockios.h> 19#include <linux/sockios.h>
20#include <linux/spinlock.h> 20#include <linux/spinlock.h>
21#include <linux/net.h> 21#include <linux/net.h>
22#include <linux/slab.h>
22#include <net/ax25.h> 23#include <net/ax25.h>
23#include <linux/inet.h> 24#include <linux/inet.h>
24#include <linux/netdevice.h> 25#include <linux/netdevice.h>
@@ -92,6 +93,12 @@ ax25_cb *ax25_send_frame(struct sk_buff *skb, int paclen, ax25_address *src, ax2
92#endif 93#endif
93 } 94 }
94 95
96 /*
97 * There is one ref for the state machine; a caller needs
98 * one more to put it back, just like with the existing one.
99 */
100 ax25_cb_hold(ax25);
101
95 ax25_cb_add(ax25); 102 ax25_cb_add(ax25);
96 103
97 ax25->state = AX25_STATE_1; 104 ax25->state = AX25_STATE_1;
diff --git a/net/ax25/ax25_route.c b/net/ax25/ax25_route.c
index c833ba4c45a5..7805945a5fd6 100644
--- a/net/ax25/ax25_route.c
+++ b/net/ax25/ax25_route.c
@@ -23,6 +23,7 @@
23#include <linux/string.h> 23#include <linux/string.h>
24#include <linux/sockios.h> 24#include <linux/sockios.h>
25#include <linux/net.h> 25#include <linux/net.h>
26#include <linux/slab.h>
26#include <net/ax25.h> 27#include <net/ax25.h>
27#include <linux/inet.h> 28#include <linux/inet.h>
28#include <linux/netdevice.h> 29#include <linux/netdevice.h>
diff --git a/net/ax25/ax25_subr.c b/net/ax25/ax25_subr.c
index 034aa10a5198..c6715ee4ab8f 100644
--- a/net/ax25/ax25_subr.c
+++ b/net/ax25/ax25_subr.c
@@ -18,6 +18,7 @@
18#include <linux/string.h> 18#include <linux/string.h>
19#include <linux/sockios.h> 19#include <linux/sockios.h>
20#include <linux/net.h> 20#include <linux/net.h>
21#include <linux/slab.h>
21#include <net/ax25.h> 22#include <net/ax25.h>
22#include <linux/inet.h> 23#include <linux/inet.h>
23#include <linux/netdevice.h> 24#include <linux/netdevice.h>
diff --git a/net/ax25/ax25_uid.c b/net/ax25/ax25_uid.c
index 832bcf092a01..d349be9578f5 100644
--- a/net/ax25/ax25_uid.c
+++ b/net/ax25/ax25_uid.c
@@ -18,6 +18,7 @@
18#include <linux/sockios.h> 18#include <linux/sockios.h>
19#include <linux/net.h> 19#include <linux/net.h>
20#include <linux/spinlock.h> 20#include <linux/spinlock.h>
21#include <linux/slab.h>
21#include <net/ax25.h> 22#include <net/ax25.h>
22#include <linux/inet.h> 23#include <linux/inet.h>
23#include <linux/netdevice.h> 24#include <linux/netdevice.h>
@@ -146,31 +147,13 @@ int ax25_uid_ioctl(int cmd, struct sockaddr_ax25 *sax)
146static void *ax25_uid_seq_start(struct seq_file *seq, loff_t *pos) 147static void *ax25_uid_seq_start(struct seq_file *seq, loff_t *pos)
147 __acquires(ax25_uid_lock) 148 __acquires(ax25_uid_lock)
148{ 149{
149 struct ax25_uid_assoc *pt;
150 struct hlist_node *node;
151 int i = 1;
152
153 read_lock(&ax25_uid_lock); 150 read_lock(&ax25_uid_lock);
154 151 return seq_hlist_start_head(&ax25_uid_list, *pos);
155 if (*pos == 0)
156 return SEQ_START_TOKEN;
157
158 ax25_uid_for_each(pt, node, &ax25_uid_list) {
159 if (i == *pos)
160 return pt;
161 ++i;
162 }
163 return NULL;
164} 152}
165 153
166static void *ax25_uid_seq_next(struct seq_file *seq, void *v, loff_t *pos) 154static void *ax25_uid_seq_next(struct seq_file *seq, void *v, loff_t *pos)
167{ 155{
168 ++*pos; 156 return seq_hlist_next(v, &ax25_uid_list, pos);
169 if (v == SEQ_START_TOKEN)
170 return ax25_uid_list.first;
171 else
172 return hlist_entry(((ax25_uid_assoc *)v)->uid_node.next,
173 ax25_uid_assoc, uid_node);
174} 157}
175 158
176static void ax25_uid_seq_stop(struct seq_file *seq, void *v) 159static void ax25_uid_seq_stop(struct seq_file *seq, void *v)
@@ -186,8 +169,9 @@ static int ax25_uid_seq_show(struct seq_file *seq, void *v)
186 if (v == SEQ_START_TOKEN) 169 if (v == SEQ_START_TOKEN)
187 seq_printf(seq, "Policy: %d\n", ax25_uid_policy); 170 seq_printf(seq, "Policy: %d\n", ax25_uid_policy);
188 else { 171 else {
189 struct ax25_uid_assoc *pt = v; 172 struct ax25_uid_assoc *pt;
190 173
174 pt = hlist_entry(v, struct ax25_uid_assoc, uid_node);
191 seq_printf(seq, "%6d %s\n", pt->uid, ax2asc(buf, &pt->call)); 175 seq_printf(seq, "%6d %s\n", pt->uid, ax2asc(buf, &pt->call));
192 } 176 }
193 return 0; 177 return 0;
diff --git a/net/ax25/sysctl_net_ax25.c b/net/ax25/sysctl_net_ax25.c
index 62ee3fb34732..ebe0ef3f1d83 100644
--- a/net/ax25/sysctl_net_ax25.c
+++ b/net/ax25/sysctl_net_ax25.c
@@ -7,6 +7,7 @@
7 * Copyright (C) 1996 Mike Shaver (shaver@zeroknowledge.com) 7 * Copyright (C) 1996 Mike Shaver (shaver@zeroknowledge.com)
8 */ 8 */
9#include <linux/mm.h> 9#include <linux/mm.h>
10#include <linux/slab.h>
10#include <linux/sysctl.h> 11#include <linux/sysctl.h>
11#include <linux/spinlock.h> 12#include <linux/spinlock.h>
12#include <net/ax25.h> 13#include <net/ax25.h>
@@ -34,156 +35,128 @@ static ctl_table *ax25_table;
34static int ax25_table_size; 35static int ax25_table_size;
35 36
36static struct ctl_path ax25_path[] = { 37static struct ctl_path ax25_path[] = {
37 { .procname = "net", .ctl_name = CTL_NET, }, 38 { .procname = "net", },
38 { .procname = "ax25", .ctl_name = NET_AX25, }, 39 { .procname = "ax25", },
39 { } 40 { }
40}; 41};
41 42
42static const ctl_table ax25_param_table[] = { 43static const ctl_table ax25_param_table[] = {
43 { 44 {
44 .ctl_name = NET_AX25_IP_DEFAULT_MODE,
45 .procname = "ip_default_mode", 45 .procname = "ip_default_mode",
46 .maxlen = sizeof(int), 46 .maxlen = sizeof(int),
47 .mode = 0644, 47 .mode = 0644,
48 .proc_handler = proc_dointvec_minmax, 48 .proc_handler = proc_dointvec_minmax,
49 .strategy = sysctl_intvec,
50 .extra1 = &min_ipdefmode, 49 .extra1 = &min_ipdefmode,
51 .extra2 = &max_ipdefmode 50 .extra2 = &max_ipdefmode
52 }, 51 },
53 { 52 {
54 .ctl_name = NET_AX25_DEFAULT_MODE,
55 .procname = "ax25_default_mode", 53 .procname = "ax25_default_mode",
56 .maxlen = sizeof(int), 54 .maxlen = sizeof(int),
57 .mode = 0644, 55 .mode = 0644,
58 .proc_handler = proc_dointvec_minmax, 56 .proc_handler = proc_dointvec_minmax,
59 .strategy = sysctl_intvec,
60 .extra1 = &min_axdefmode, 57 .extra1 = &min_axdefmode,
61 .extra2 = &max_axdefmode 58 .extra2 = &max_axdefmode
62 }, 59 },
63 { 60 {
64 .ctl_name = NET_AX25_BACKOFF_TYPE,
65 .procname = "backoff_type", 61 .procname = "backoff_type",
66 .maxlen = sizeof(int), 62 .maxlen = sizeof(int),
67 .mode = 0644, 63 .mode = 0644,
68 .proc_handler = proc_dointvec_minmax, 64 .proc_handler = proc_dointvec_minmax,
69 .strategy = sysctl_intvec,
70 .extra1 = &min_backoff, 65 .extra1 = &min_backoff,
71 .extra2 = &max_backoff 66 .extra2 = &max_backoff
72 }, 67 },
73 { 68 {
74 .ctl_name = NET_AX25_CONNECT_MODE,
75 .procname = "connect_mode", 69 .procname = "connect_mode",
76 .maxlen = sizeof(int), 70 .maxlen = sizeof(int),
77 .mode = 0644, 71 .mode = 0644,
78 .proc_handler = proc_dointvec_minmax, 72 .proc_handler = proc_dointvec_minmax,
79 .strategy = sysctl_intvec,
80 .extra1 = &min_conmode, 73 .extra1 = &min_conmode,
81 .extra2 = &max_conmode 74 .extra2 = &max_conmode
82 }, 75 },
83 { 76 {
84 .ctl_name = NET_AX25_STANDARD_WINDOW,
85 .procname = "standard_window_size", 77 .procname = "standard_window_size",
86 .maxlen = sizeof(int), 78 .maxlen = sizeof(int),
87 .mode = 0644, 79 .mode = 0644,
88 .proc_handler = proc_dointvec_minmax, 80 .proc_handler = proc_dointvec_minmax,
89 .strategy = sysctl_intvec,
90 .extra1 = &min_window, 81 .extra1 = &min_window,
91 .extra2 = &max_window 82 .extra2 = &max_window
92 }, 83 },
93 { 84 {
94 .ctl_name = NET_AX25_EXTENDED_WINDOW,
95 .procname = "extended_window_size", 85 .procname = "extended_window_size",
96 .maxlen = sizeof(int), 86 .maxlen = sizeof(int),
97 .mode = 0644, 87 .mode = 0644,
98 .proc_handler = proc_dointvec_minmax, 88 .proc_handler = proc_dointvec_minmax,
99 .strategy = sysctl_intvec,
100 .extra1 = &min_ewindow, 89 .extra1 = &min_ewindow,
101 .extra2 = &max_ewindow 90 .extra2 = &max_ewindow
102 }, 91 },
103 { 92 {
104 .ctl_name = NET_AX25_T1_TIMEOUT,
105 .procname = "t1_timeout", 93 .procname = "t1_timeout",
106 .maxlen = sizeof(int), 94 .maxlen = sizeof(int),
107 .mode = 0644, 95 .mode = 0644,
108 .proc_handler = proc_dointvec_minmax, 96 .proc_handler = proc_dointvec_minmax,
109 .strategy = sysctl_intvec,
110 .extra1 = &min_t1, 97 .extra1 = &min_t1,
111 .extra2 = &max_t1 98 .extra2 = &max_t1
112 }, 99 },
113 { 100 {
114 .ctl_name = NET_AX25_T2_TIMEOUT,
115 .procname = "t2_timeout", 101 .procname = "t2_timeout",
116 .maxlen = sizeof(int), 102 .maxlen = sizeof(int),
117 .mode = 0644, 103 .mode = 0644,
118 .proc_handler = proc_dointvec_minmax, 104 .proc_handler = proc_dointvec_minmax,
119 .strategy = sysctl_intvec,
120 .extra1 = &min_t2, 105 .extra1 = &min_t2,
121 .extra2 = &max_t2 106 .extra2 = &max_t2
122 }, 107 },
123 { 108 {
124 .ctl_name = NET_AX25_T3_TIMEOUT,
125 .procname = "t3_timeout", 109 .procname = "t3_timeout",
126 .maxlen = sizeof(int), 110 .maxlen = sizeof(int),
127 .mode = 0644, 111 .mode = 0644,
128 .proc_handler = proc_dointvec_minmax, 112 .proc_handler = proc_dointvec_minmax,
129 .strategy = sysctl_intvec,
130 .extra1 = &min_t3, 113 .extra1 = &min_t3,
131 .extra2 = &max_t3 114 .extra2 = &max_t3
132 }, 115 },
133 { 116 {
134 .ctl_name = NET_AX25_IDLE_TIMEOUT,
135 .procname = "idle_timeout", 117 .procname = "idle_timeout",
136 .maxlen = sizeof(int), 118 .maxlen = sizeof(int),
137 .mode = 0644, 119 .mode = 0644,
138 .proc_handler = proc_dointvec_minmax, 120 .proc_handler = proc_dointvec_minmax,
139 .strategy = sysctl_intvec,
140 .extra1 = &min_idle, 121 .extra1 = &min_idle,
141 .extra2 = &max_idle 122 .extra2 = &max_idle
142 }, 123 },
143 { 124 {
144 .ctl_name = NET_AX25_N2,
145 .procname = "maximum_retry_count", 125 .procname = "maximum_retry_count",
146 .maxlen = sizeof(int), 126 .maxlen = sizeof(int),
147 .mode = 0644, 127 .mode = 0644,
148 .proc_handler = proc_dointvec_minmax, 128 .proc_handler = proc_dointvec_minmax,
149 .strategy = sysctl_intvec,
150 .extra1 = &min_n2, 129 .extra1 = &min_n2,
151 .extra2 = &max_n2 130 .extra2 = &max_n2
152 }, 131 },
153 { 132 {
154 .ctl_name = NET_AX25_PACLEN,
155 .procname = "maximum_packet_length", 133 .procname = "maximum_packet_length",
156 .maxlen = sizeof(int), 134 .maxlen = sizeof(int),
157 .mode = 0644, 135 .mode = 0644,
158 .proc_handler = proc_dointvec_minmax, 136 .proc_handler = proc_dointvec_minmax,
159 .strategy = sysctl_intvec,
160 .extra1 = &min_paclen, 137 .extra1 = &min_paclen,
161 .extra2 = &max_paclen 138 .extra2 = &max_paclen
162 }, 139 },
163 { 140 {
164 .ctl_name = NET_AX25_PROTOCOL,
165 .procname = "protocol", 141 .procname = "protocol",
166 .maxlen = sizeof(int), 142 .maxlen = sizeof(int),
167 .mode = 0644, 143 .mode = 0644,
168 .proc_handler = proc_dointvec_minmax, 144 .proc_handler = proc_dointvec_minmax,
169 .strategy = sysctl_intvec,
170 .extra1 = &min_proto, 145 .extra1 = &min_proto,
171 .extra2 = &max_proto 146 .extra2 = &max_proto
172 }, 147 },
173#ifdef CONFIG_AX25_DAMA_SLAVE 148#ifdef CONFIG_AX25_DAMA_SLAVE
174 { 149 {
175 .ctl_name = NET_AX25_DAMA_SLAVE_TIMEOUT,
176 .procname = "dama_slave_timeout", 150 .procname = "dama_slave_timeout",
177 .maxlen = sizeof(int), 151 .maxlen = sizeof(int),
178 .mode = 0644, 152 .mode = 0644,
179 .proc_handler = proc_dointvec_minmax, 153 .proc_handler = proc_dointvec_minmax,
180 .strategy = sysctl_intvec,
181 .extra1 = &min_ds_timeout, 154 .extra1 = &min_ds_timeout,
182 .extra2 = &max_ds_timeout 155 .extra2 = &max_ds_timeout
183 }, 156 },
184#endif 157#endif
185 158
186 { .ctl_name = 0 } /* that's all, folks! */ 159 { } /* that's all, folks! */
187}; 160};
188 161
189void ax25_register_sysctl(void) 162void ax25_register_sysctl(void)
@@ -212,11 +185,9 @@ void ax25_register_sysctl(void)
212 return; 185 return;
213 } 186 }
214 ax25_table[n].child = ax25_dev->systable = child; 187 ax25_table[n].child = ax25_dev->systable = child;
215 ax25_table[n].ctl_name = n + 1;
216 ax25_table[n].procname = ax25_dev->dev->name; 188 ax25_table[n].procname = ax25_dev->dev->name;
217 ax25_table[n].mode = 0555; 189 ax25_table[n].mode = 0555;
218 190
219 child[AX25_MAX_VALUES].ctl_name = 0; /* just in case... */
220 191
221 for (k = 0; k < AX25_MAX_VALUES; k++) 192 for (k = 0; k < AX25_MAX_VALUES; k++)
222 child[k].data = &ax25_dev->values[k]; 193 child[k].data = &ax25_dev->values[k];
@@ -233,7 +204,7 @@ void ax25_unregister_sysctl(void)
233 ctl_table *p; 204 ctl_table *p;
234 unregister_sysctl_table(ax25_table_header); 205 unregister_sysctl_table(ax25_table_header);
235 206
236 for (p = ax25_table; p->ctl_name; p++) 207 for (p = ax25_table; p->procname; p++)
237 kfree(p->child); 208 kfree(p->child);
238 kfree(ax25_table); 209 kfree(ax25_table);
239} 210}
diff --git a/net/bluetooth/af_bluetooth.c b/net/bluetooth/af_bluetooth.c
index 8cfb5a849841..404a8500fd03 100644
--- a/net/bluetooth/af_bluetooth.c
+++ b/net/bluetooth/af_bluetooth.c
@@ -31,7 +31,6 @@
31#include <linux/errno.h> 31#include <linux/errno.h>
32#include <linux/kernel.h> 32#include <linux/kernel.h>
33#include <linux/sched.h> 33#include <linux/sched.h>
34#include <linux/slab.h>
35#include <linux/skbuff.h> 34#include <linux/skbuff.h>
36#include <linux/init.h> 35#include <linux/init.h>
37#include <linux/poll.h> 36#include <linux/poll.h>
@@ -45,7 +44,7 @@
45 44
46/* Bluetooth sockets */ 45/* Bluetooth sockets */
47#define BT_MAX_PROTO 8 46#define BT_MAX_PROTO 8
48static struct net_proto_family *bt_proto[BT_MAX_PROTO]; 47static const struct net_proto_family *bt_proto[BT_MAX_PROTO];
49static DEFINE_RWLOCK(bt_proto_lock); 48static DEFINE_RWLOCK(bt_proto_lock);
50 49
51static struct lock_class_key bt_lock_key[BT_MAX_PROTO]; 50static struct lock_class_key bt_lock_key[BT_MAX_PROTO];
@@ -86,7 +85,7 @@ static inline void bt_sock_reclassify_lock(struct socket *sock, int proto)
86 bt_key_strings[proto], &bt_lock_key[proto]); 85 bt_key_strings[proto], &bt_lock_key[proto]);
87} 86}
88 87
89int bt_sock_register(int proto, struct net_proto_family *ops) 88int bt_sock_register(int proto, const struct net_proto_family *ops)
90{ 89{
91 int err = 0; 90 int err = 0;
92 91
@@ -126,7 +125,8 @@ int bt_sock_unregister(int proto)
126} 125}
127EXPORT_SYMBOL(bt_sock_unregister); 126EXPORT_SYMBOL(bt_sock_unregister);
128 127
129static int bt_sock_create(struct net *net, struct socket *sock, int proto) 128static int bt_sock_create(struct net *net, struct socket *sock, int proto,
129 int kern)
130{ 130{
131 int err; 131 int err;
132 132
@@ -144,7 +144,7 @@ static int bt_sock_create(struct net *net, struct socket *sock, int proto)
144 read_lock(&bt_proto_lock); 144 read_lock(&bt_proto_lock);
145 145
146 if (bt_proto[proto] && try_module_get(bt_proto[proto]->owner)) { 146 if (bt_proto[proto] && try_module_get(bt_proto[proto]->owner)) {
147 err = bt_proto[proto]->create(net, sock, proto); 147 err = bt_proto[proto]->create(net, sock, proto, kern);
148 bt_sock_reclassify_lock(sock, proto); 148 bt_sock_reclassify_lock(sock, proto);
149 module_put(bt_proto[proto]->owner); 149 module_put(bt_proto[proto]->owner);
150 } 150 }
@@ -257,7 +257,7 @@ int bt_sock_recvmsg(struct kiocb *iocb, struct socket *sock,
257 skb_reset_transport_header(skb); 257 skb_reset_transport_header(skb);
258 err = skb_copy_datagram_iovec(skb, 0, msg->msg_iov, copied); 258 err = skb_copy_datagram_iovec(skb, 0, msg->msg_iov, copied);
259 if (err == 0) 259 if (err == 0)
260 sock_recv_timestamp(msg, sk, skb); 260 sock_recv_ts_and_drops(msg, sk, skb);
261 261
262 skb_free_datagram(sk, skb); 262 skb_free_datagram(sk, skb);
263 263
diff --git a/net/bluetooth/bnep/core.c b/net/bluetooth/bnep/core.c
index cafe9f54d841..8062dad6d10d 100644
--- a/net/bluetooth/bnep/core.c
+++ b/net/bluetooth/bnep/core.c
@@ -35,6 +35,7 @@
35#include <linux/freezer.h> 35#include <linux/freezer.h>
36#include <linux/errno.h> 36#include <linux/errno.h>
37#include <linux/net.h> 37#include <linux/net.h>
38#include <linux/slab.h>
38#include <net/sock.h> 39#include <net/sock.h>
39 40
40#include <linux/socket.h> 41#include <linux/socket.h>
@@ -78,7 +79,7 @@ static struct bnep_session *__bnep_get_session(u8 *dst)
78static void __bnep_link_session(struct bnep_session *s) 79static void __bnep_link_session(struct bnep_session *s)
79{ 80{
80 /* It's safe to call __module_get() here because sessions are added 81 /* It's safe to call __module_get() here because sessions are added
81 by the socket layer which has to hold the refference to this module. 82 by the socket layer which has to hold the reference to this module.
82 */ 83 */
83 __module_get(THIS_MODULE); 84 __module_get(THIS_MODULE);
84 list_add(&s->list, &bnep_session_list); 85 list_add(&s->list, &bnep_session_list);
@@ -230,7 +231,6 @@ static int bnep_rx_control(struct bnep_session *s, void *data, int len)
230 231
231 switch (cmd) { 232 switch (cmd) {
232 case BNEP_CMD_NOT_UNDERSTOOD: 233 case BNEP_CMD_NOT_UNDERSTOOD:
233 case BNEP_SETUP_CONN_REQ:
234 case BNEP_SETUP_CONN_RSP: 234 case BNEP_SETUP_CONN_RSP:
235 case BNEP_FILTER_NET_TYPE_RSP: 235 case BNEP_FILTER_NET_TYPE_RSP:
236 case BNEP_FILTER_MULTI_ADDR_RSP: 236 case BNEP_FILTER_MULTI_ADDR_RSP:
@@ -245,6 +245,10 @@ static int bnep_rx_control(struct bnep_session *s, void *data, int len)
245 err = bnep_ctrl_set_mcfilter(s, data, len); 245 err = bnep_ctrl_set_mcfilter(s, data, len);
246 break; 246 break;
247 247
248 case BNEP_SETUP_CONN_REQ:
249 err = bnep_send_rsp(s, BNEP_SETUP_CONN_RSP, BNEP_CONN_NOT_ALLOWED);
250 break;
251
248 default: { 252 default: {
249 u8 pkt[3]; 253 u8 pkt[3];
250 pkt[0] = BNEP_CONTROL; 254 pkt[0] = BNEP_CONTROL;
@@ -629,7 +633,7 @@ int bnep_del_connection(struct bnep_conndel_req *req)
629 s = __bnep_get_session(req->dst); 633 s = __bnep_get_session(req->dst);
630 if (s) { 634 if (s) {
631 /* Wakeup user-space which is polling for socket errors. 635 /* Wakeup user-space which is polling for socket errors.
632 * This is temporary hack untill we have shutdown in L2CAP */ 636 * This is temporary hack until we have shutdown in L2CAP */
633 s->sock->sk->sk_err = EUNATCH; 637 s->sock->sk->sk_err = EUNATCH;
634 638
635 /* Kill session thread */ 639 /* Kill session thread */
diff --git a/net/bluetooth/bnep/netdev.c b/net/bluetooth/bnep/netdev.c
index 26fb831ef7e0..5643a2391e76 100644
--- a/net/bluetooth/bnep/netdev.c
+++ b/net/bluetooth/bnep/netdev.c
@@ -26,6 +26,7 @@
26*/ 26*/
27 27
28#include <linux/module.h> 28#include <linux/module.h>
29#include <linux/slab.h>
29 30
30#include <linux/socket.h> 31#include <linux/socket.h>
31#include <linux/netdevice.h> 32#include <linux/netdevice.h>
@@ -64,7 +65,7 @@ static void bnep_net_set_mc_list(struct net_device *dev)
64 struct sk_buff *skb; 65 struct sk_buff *skb;
65 int size; 66 int size;
66 67
67 BT_DBG("%s mc_count %d", dev->name, dev->mc_count); 68 BT_DBG("%s mc_count %d", dev->name, netdev_mc_count(dev));
68 69
69 size = sizeof(*r) + (BNEP_MAX_MULTICAST_FILTERS + 1) * ETH_ALEN * 2; 70 size = sizeof(*r) + (BNEP_MAX_MULTICAST_FILTERS + 1) * ETH_ALEN * 2;
70 skb = alloc_skb(size, GFP_ATOMIC); 71 skb = alloc_skb(size, GFP_ATOMIC);
@@ -97,7 +98,9 @@ static void bnep_net_set_mc_list(struct net_device *dev)
97 98
98 /* FIXME: We should group addresses here. */ 99 /* FIXME: We should group addresses here. */
99 100
100 for (i = 0; i < dev->mc_count && i < BNEP_MAX_MULTICAST_FILTERS; i++) { 101 for (i = 0;
102 i < netdev_mc_count(dev) && i < BNEP_MAX_MULTICAST_FILTERS;
103 i++) {
101 memcpy(__skb_put(skb, ETH_ALEN), dmi->dmi_addr, ETH_ALEN); 104 memcpy(__skb_put(skb, ETH_ALEN), dmi->dmi_addr, ETH_ALEN);
102 memcpy(__skb_put(skb, ETH_ALEN), dmi->dmi_addr, ETH_ALEN); 105 memcpy(__skb_put(skb, ETH_ALEN), dmi->dmi_addr, ETH_ALEN);
103 dmi = dmi->next; 106 dmi = dmi->next;
diff --git a/net/bluetooth/bnep/sock.c b/net/bluetooth/bnep/sock.c
index e857628b0b27..2862f53b66b1 100644
--- a/net/bluetooth/bnep/sock.c
+++ b/net/bluetooth/bnep/sock.c
@@ -30,7 +30,6 @@
30#include <linux/capability.h> 30#include <linux/capability.h>
31#include <linux/errno.h> 31#include <linux/errno.h>
32#include <linux/kernel.h> 32#include <linux/kernel.h>
33#include <linux/slab.h>
34#include <linux/poll.h> 33#include <linux/poll.h>
35#include <linux/fcntl.h> 34#include <linux/fcntl.h>
36#include <linux/skbuff.h> 35#include <linux/skbuff.h>
@@ -39,6 +38,7 @@
39#include <linux/file.h> 38#include <linux/file.h>
40#include <linux/init.h> 39#include <linux/init.h>
41#include <linux/compat.h> 40#include <linux/compat.h>
41#include <linux/gfp.h>
42#include <net/sock.h> 42#include <net/sock.h>
43 43
44#include <asm/system.h> 44#include <asm/system.h>
@@ -195,7 +195,8 @@ static struct proto bnep_proto = {
195 .obj_size = sizeof(struct bt_sock) 195 .obj_size = sizeof(struct bt_sock)
196}; 196};
197 197
198static int bnep_sock_create(struct net *net, struct socket *sock, int protocol) 198static int bnep_sock_create(struct net *net, struct socket *sock, int protocol,
199 int kern)
199{ 200{
200 struct sock *sk; 201 struct sock *sk;
201 202
@@ -222,7 +223,7 @@ static int bnep_sock_create(struct net *net, struct socket *sock, int protocol)
222 return 0; 223 return 0;
223} 224}
224 225
225static struct net_proto_family bnep_sock_family_ops = { 226static const struct net_proto_family bnep_sock_family_ops = {
226 .family = PF_BLUETOOTH, 227 .family = PF_BLUETOOTH,
227 .owner = THIS_MODULE, 228 .owner = THIS_MODULE,
228 .create = bnep_sock_create 229 .create = bnep_sock_create
diff --git a/net/bluetooth/cmtp/capi.c b/net/bluetooth/cmtp/capi.c
index 97f8d68d574d..3487cfe74aec 100644
--- a/net/bluetooth/cmtp/capi.c
+++ b/net/bluetooth/cmtp/capi.c
@@ -21,7 +21,8 @@
21*/ 21*/
22 22
23#include <linux/module.h> 23#include <linux/module.h>
24 24#include <linux/proc_fs.h>
25#include <linux/seq_file.h>
25#include <linux/types.h> 26#include <linux/types.h>
26#include <linux/errno.h> 27#include <linux/errno.h>
27#include <linux/kernel.h> 28#include <linux/kernel.h>
@@ -516,33 +517,37 @@ static char *cmtp_procinfo(struct capi_ctr *ctrl)
516 return "CAPI Message Transport Protocol"; 517 return "CAPI Message Transport Protocol";
517} 518}
518 519
519static int cmtp_ctr_read_proc(char *page, char **start, off_t off, int count, int *eof, struct capi_ctr *ctrl) 520static int cmtp_proc_show(struct seq_file *m, void *v)
520{ 521{
522 struct capi_ctr *ctrl = m->private;
521 struct cmtp_session *session = ctrl->driverdata; 523 struct cmtp_session *session = ctrl->driverdata;
522 struct cmtp_application *app; 524 struct cmtp_application *app;
523 struct list_head *p, *n; 525 struct list_head *p, *n;
524 int len = 0;
525 526
526 len += sprintf(page + len, "%s\n\n", cmtp_procinfo(ctrl)); 527 seq_printf(m, "%s\n\n", cmtp_procinfo(ctrl));
527 len += sprintf(page + len, "addr %s\n", session->name); 528 seq_printf(m, "addr %s\n", session->name);
528 len += sprintf(page + len, "ctrl %d\n", session->num); 529 seq_printf(m, "ctrl %d\n", session->num);
529 530
530 list_for_each_safe(p, n, &session->applications) { 531 list_for_each_safe(p, n, &session->applications) {
531 app = list_entry(p, struct cmtp_application, list); 532 app = list_entry(p, struct cmtp_application, list);
532 len += sprintf(page + len, "appl %d -> %d\n", app->appl, app->mapping); 533 seq_printf(m, "appl %d -> %d\n", app->appl, app->mapping);
533 } 534 }
534 535
535 if (off + count >= len) 536 return 0;
536 *eof = 1; 537}
537
538 if (len < off)
539 return 0;
540
541 *start = page + off;
542 538
543 return ((count < len - off) ? count : len - off); 539static int cmtp_proc_open(struct inode *inode, struct file *file)
540{
541 return single_open(file, cmtp_proc_show, PDE(inode)->data);
544} 542}
545 543
544static const struct file_operations cmtp_proc_fops = {
545 .owner = THIS_MODULE,
546 .open = cmtp_proc_open,
547 .read = seq_read,
548 .llseek = seq_lseek,
549 .release = single_release,
550};
546 551
547int cmtp_attach_device(struct cmtp_session *session) 552int cmtp_attach_device(struct cmtp_session *session)
548{ 553{
@@ -582,7 +587,7 @@ int cmtp_attach_device(struct cmtp_session *session)
582 session->ctrl.send_message = cmtp_send_message; 587 session->ctrl.send_message = cmtp_send_message;
583 588
584 session->ctrl.procinfo = cmtp_procinfo; 589 session->ctrl.procinfo = cmtp_procinfo;
585 session->ctrl.ctr_read_proc = cmtp_ctr_read_proc; 590 session->ctrl.proc_fops = &cmtp_proc_fops;
586 591
587 if (attach_capi_ctr(&session->ctrl) < 0) { 592 if (attach_capi_ctr(&session->ctrl) < 0) {
588 BT_ERR("Can't attach new controller"); 593 BT_ERR("Can't attach new controller");
diff --git a/net/bluetooth/cmtp/sock.c b/net/bluetooth/cmtp/sock.c
index 16b0fad74f6e..7ea1979a8e4f 100644
--- a/net/bluetooth/cmtp/sock.c
+++ b/net/bluetooth/cmtp/sock.c
@@ -26,7 +26,6 @@
26#include <linux/capability.h> 26#include <linux/capability.h>
27#include <linux/errno.h> 27#include <linux/errno.h>
28#include <linux/kernel.h> 28#include <linux/kernel.h>
29#include <linux/slab.h>
30#include <linux/poll.h> 29#include <linux/poll.h>
31#include <linux/fcntl.h> 30#include <linux/fcntl.h>
32#include <linux/skbuff.h> 31#include <linux/skbuff.h>
@@ -34,6 +33,7 @@
34#include <linux/ioctl.h> 33#include <linux/ioctl.h>
35#include <linux/file.h> 34#include <linux/file.h>
36#include <linux/compat.h> 35#include <linux/compat.h>
36#include <linux/gfp.h>
37#include <net/sock.h> 37#include <net/sock.h>
38 38
39#include <linux/isdn/capilli.h> 39#include <linux/isdn/capilli.h>
@@ -190,7 +190,8 @@ static struct proto cmtp_proto = {
190 .obj_size = sizeof(struct bt_sock) 190 .obj_size = sizeof(struct bt_sock)
191}; 191};
192 192
193static int cmtp_sock_create(struct net *net, struct socket *sock, int protocol) 193static int cmtp_sock_create(struct net *net, struct socket *sock, int protocol,
194 int kern)
194{ 195{
195 struct sock *sk; 196 struct sock *sk;
196 197
@@ -217,7 +218,7 @@ static int cmtp_sock_create(struct net *net, struct socket *sock, int protocol)
217 return 0; 218 return 0;
218} 219}
219 220
220static struct net_proto_family cmtp_sock_family_ops = { 221static const struct net_proto_family cmtp_sock_family_ops = {
221 .family = PF_BLUETOOTH, 222 .family = PF_BLUETOOTH,
222 .owner = THIS_MODULE, 223 .owner = THIS_MODULE,
223 .create = cmtp_sock_create 224 .create = cmtp_sock_create
diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c
index b7c4224f4e7d..b10e3cdb08f8 100644
--- a/net/bluetooth/hci_conn.c
+++ b/net/bluetooth/hci_conn.c
@@ -377,6 +377,9 @@ struct hci_conn *hci_connect(struct hci_dev *hdev, int type, bdaddr_t *dst, __u8
377 377
378 if (acl->state == BT_CONNECTED && 378 if (acl->state == BT_CONNECTED &&
379 (sco->state == BT_OPEN || sco->state == BT_CLOSED)) { 379 (sco->state == BT_OPEN || sco->state == BT_CLOSED)) {
380 acl->power_save = 1;
381 hci_conn_enter_active_mode(acl);
382
380 if (lmp_esco_capable(hdev)) 383 if (lmp_esco_capable(hdev))
381 hci_setup_sync(sco, acl->handle); 384 hci_setup_sync(sco, acl->handle);
382 else 385 else
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index e1da8f68759c..4ad23192c7a5 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -193,8 +193,9 @@ static void hci_init_req(struct hci_dev *hdev, unsigned long opt)
193 while ((skb = skb_dequeue(&hdev->driver_init))) { 193 while ((skb = skb_dequeue(&hdev->driver_init))) {
194 bt_cb(skb)->pkt_type = HCI_COMMAND_PKT; 194 bt_cb(skb)->pkt_type = HCI_COMMAND_PKT;
195 skb->dev = (void *) hdev; 195 skb->dev = (void *) hdev;
196
196 skb_queue_tail(&hdev->cmd_q, skb); 197 skb_queue_tail(&hdev->cmd_q, skb);
197 hci_sched_cmd(hdev); 198 tasklet_schedule(&hdev->cmd_task);
198 } 199 }
199 skb_queue_purge(&hdev->driver_init); 200 skb_queue_purge(&hdev->driver_init);
200 201
@@ -490,6 +491,10 @@ int hci_dev_open(__u16 dev)
490 if (test_bit(HCI_QUIRK_RAW_DEVICE, &hdev->quirks)) 491 if (test_bit(HCI_QUIRK_RAW_DEVICE, &hdev->quirks))
491 set_bit(HCI_RAW, &hdev->flags); 492 set_bit(HCI_RAW, &hdev->flags);
492 493
494 /* Treat all non BR/EDR controllers as raw devices for now */
495 if (hdev->dev_type != HCI_BREDR)
496 set_bit(HCI_RAW, &hdev->flags);
497
493 if (hdev->open(hdev)) { 498 if (hdev->open(hdev)) {
494 ret = -EIO; 499 ret = -EIO;
495 goto done; 500 goto done;
@@ -796,7 +801,7 @@ int hci_get_dev_info(void __user *arg)
796 801
797 strcpy(di.name, hdev->name); 802 strcpy(di.name, hdev->name);
798 di.bdaddr = hdev->bdaddr; 803 di.bdaddr = hdev->bdaddr;
799 di.type = hdev->type; 804 di.type = (hdev->bus & 0x0f) | (hdev->dev_type << 4);
800 di.flags = hdev->flags; 805 di.flags = hdev->flags;
801 di.pkt_type = hdev->pkt_type; 806 di.pkt_type = hdev->pkt_type;
802 di.acl_mtu = hdev->acl_mtu; 807 di.acl_mtu = hdev->acl_mtu;
@@ -868,8 +873,8 @@ int hci_register_dev(struct hci_dev *hdev)
868 struct list_head *head = &hci_dev_list, *p; 873 struct list_head *head = &hci_dev_list, *p;
869 int i, id = 0; 874 int i, id = 0;
870 875
871 BT_DBG("%p name %s type %d owner %p", hdev, hdev->name, 876 BT_DBG("%p name %s bus %d owner %p", hdev, hdev->name,
872 hdev->type, hdev->owner); 877 hdev->bus, hdev->owner);
873 878
874 if (!hdev->open || !hdev->close || !hdev->destruct) 879 if (!hdev->open || !hdev->close || !hdev->destruct)
875 return -EINVAL; 880 return -EINVAL;
@@ -945,7 +950,7 @@ int hci_unregister_dev(struct hci_dev *hdev)
945{ 950{
946 int i; 951 int i;
947 952
948 BT_DBG("%p name %s type %d", hdev, hdev->name, hdev->type); 953 BT_DBG("%p name %s bus %d", hdev, hdev->name, hdev->bus);
949 954
950 write_lock_bh(&hci_dev_list_lock); 955 write_lock_bh(&hci_dev_list_lock);
951 list_del(&hdev->list); 956 list_del(&hdev->list);
@@ -987,6 +992,30 @@ int hci_resume_dev(struct hci_dev *hdev)
987} 992}
988EXPORT_SYMBOL(hci_resume_dev); 993EXPORT_SYMBOL(hci_resume_dev);
989 994
995/* Receive frame from HCI drivers */
996int hci_recv_frame(struct sk_buff *skb)
997{
998 struct hci_dev *hdev = (struct hci_dev *) skb->dev;
999 if (!hdev || (!test_bit(HCI_UP, &hdev->flags)
1000 && !test_bit(HCI_INIT, &hdev->flags))) {
1001 kfree_skb(skb);
1002 return -ENXIO;
1003 }
1004
1005 /* Incomming skb */
1006 bt_cb(skb)->incoming = 1;
1007
1008 /* Time stamp */
1009 __net_timestamp(skb);
1010
1011 /* Queue frame for rx task */
1012 skb_queue_tail(&hdev->rx_q, skb);
1013 tasklet_schedule(&hdev->rx_task);
1014
1015 return 0;
1016}
1017EXPORT_SYMBOL(hci_recv_frame);
1018
990/* Receive packet type fragment */ 1019/* Receive packet type fragment */
991#define __reassembly(hdev, type) ((hdev)->reassembly[(type) - 2]) 1020#define __reassembly(hdev, type) ((hdev)->reassembly[(type) - 2])
992 1021
@@ -1193,8 +1222,9 @@ int hci_send_cmd(struct hci_dev *hdev, __u16 opcode, __u32 plen, void *param)
1193 1222
1194 bt_cb(skb)->pkt_type = HCI_COMMAND_PKT; 1223 bt_cb(skb)->pkt_type = HCI_COMMAND_PKT;
1195 skb->dev = (void *) hdev; 1224 skb->dev = (void *) hdev;
1225
1196 skb_queue_tail(&hdev->cmd_q, skb); 1226 skb_queue_tail(&hdev->cmd_q, skb);
1197 hci_sched_cmd(hdev); 1227 tasklet_schedule(&hdev->cmd_task);
1198 1228
1199 return 0; 1229 return 0;
1200} 1230}
@@ -1271,7 +1301,8 @@ int hci_send_acl(struct hci_conn *conn, struct sk_buff *skb, __u16 flags)
1271 spin_unlock_bh(&conn->data_q.lock); 1301 spin_unlock_bh(&conn->data_q.lock);
1272 } 1302 }
1273 1303
1274 hci_sched_tx(hdev); 1304 tasklet_schedule(&hdev->tx_task);
1305
1275 return 0; 1306 return 0;
1276} 1307}
1277EXPORT_SYMBOL(hci_send_acl); 1308EXPORT_SYMBOL(hci_send_acl);
@@ -1298,8 +1329,10 @@ int hci_send_sco(struct hci_conn *conn, struct sk_buff *skb)
1298 1329
1299 skb->dev = (void *) hdev; 1330 skb->dev = (void *) hdev;
1300 bt_cb(skb)->pkt_type = HCI_SCODATA_PKT; 1331 bt_cb(skb)->pkt_type = HCI_SCODATA_PKT;
1332
1301 skb_queue_tail(&conn->data_q, skb); 1333 skb_queue_tail(&conn->data_q, skb);
1302 hci_sched_tx(hdev); 1334 tasklet_schedule(&hdev->tx_task);
1335
1303 return 0; 1336 return 0;
1304} 1337}
1305EXPORT_SYMBOL(hci_send_sco); 1338EXPORT_SYMBOL(hci_send_sco);
@@ -1612,7 +1645,7 @@ static void hci_cmd_task(unsigned long arg)
1612 hdev->cmd_last_tx = jiffies; 1645 hdev->cmd_last_tx = jiffies;
1613 } else { 1646 } else {
1614 skb_queue_head(&hdev->cmd_q, skb); 1647 skb_queue_head(&hdev->cmd_q, skb);
1615 hci_sched_cmd(hdev); 1648 tasklet_schedule(&hdev->cmd_task);
1616 } 1649 }
1617 } 1650 }
1618} 1651}
diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index e99fe385fba2..6c57fc71c7e2 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -1320,7 +1320,7 @@ static inline void hci_cmd_complete_evt(struct hci_dev *hdev, struct sk_buff *sk
1320 if (ev->ncmd) { 1320 if (ev->ncmd) {
1321 atomic_set(&hdev->cmd_cnt, 1); 1321 atomic_set(&hdev->cmd_cnt, 1);
1322 if (!skb_queue_empty(&hdev->cmd_q)) 1322 if (!skb_queue_empty(&hdev->cmd_q))
1323 hci_sched_cmd(hdev); 1323 tasklet_schedule(&hdev->cmd_task);
1324 } 1324 }
1325} 1325}
1326 1326
@@ -1386,7 +1386,7 @@ static inline void hci_cmd_status_evt(struct hci_dev *hdev, struct sk_buff *skb)
1386 if (ev->ncmd) { 1386 if (ev->ncmd) {
1387 atomic_set(&hdev->cmd_cnt, 1); 1387 atomic_set(&hdev->cmd_cnt, 1);
1388 if (!skb_queue_empty(&hdev->cmd_q)) 1388 if (!skb_queue_empty(&hdev->cmd_q))
1389 hci_sched_cmd(hdev); 1389 tasklet_schedule(&hdev->cmd_task);
1390 } 1390 }
1391} 1391}
1392 1392
@@ -1454,7 +1454,7 @@ static inline void hci_num_comp_pkts_evt(struct hci_dev *hdev, struct sk_buff *s
1454 } 1454 }
1455 } 1455 }
1456 1456
1457 hci_sched_tx(hdev); 1457 tasklet_schedule(&hdev->tx_task);
1458 1458
1459 tasklet_enable(&hdev->tx_task); 1459 tasklet_enable(&hdev->tx_task);
1460} 1460}
@@ -1698,7 +1698,9 @@ static inline void hci_sync_conn_complete_evt(struct hci_dev *hdev, struct sk_bu
1698 hci_conn_add_sysfs(conn); 1698 hci_conn_add_sysfs(conn);
1699 break; 1699 break;
1700 1700
1701 case 0x11: /* Unsupported Feature or Parameter Value */
1701 case 0x1c: /* SCO interval rejected */ 1702 case 0x1c: /* SCO interval rejected */
1703 case 0x1a: /* Unsupported Remote Feature */
1702 case 0x1f: /* Unspecified error */ 1704 case 0x1f: /* Unspecified error */
1703 if (conn->out && conn->attempt < 2) { 1705 if (conn->out && conn->attempt < 2) {
1704 conn->pkt_type = (hdev->esco_type & SCO_ESCO_MASK) | 1706 conn->pkt_type = (hdev->esco_type & SCO_ESCO_MASK) |
diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
index 75302a986067..38f08f6b86f6 100644
--- a/net/bluetooth/hci_sock.c
+++ b/net/bluetooth/hci_sock.c
@@ -329,6 +329,9 @@ static inline void hci_sock_cmsg(struct sock *sk, struct msghdr *msg, struct sk_
329 } 329 }
330 330
331 if (mask & HCI_CMSG_TSTAMP) { 331 if (mask & HCI_CMSG_TSTAMP) {
332#ifdef CONFIG_COMPAT
333 struct compat_timeval ctv;
334#endif
332 struct timeval tv; 335 struct timeval tv;
333 void *data; 336 void *data;
334 int len; 337 int len;
@@ -339,7 +342,6 @@ static inline void hci_sock_cmsg(struct sock *sk, struct msghdr *msg, struct sk_
339 len = sizeof(tv); 342 len = sizeof(tv);
340#ifdef CONFIG_COMPAT 343#ifdef CONFIG_COMPAT
341 if (msg->msg_flags & MSG_CMSG_COMPAT) { 344 if (msg->msg_flags & MSG_CMSG_COMPAT) {
342 struct compat_timeval ctv;
343 ctv.tv_sec = tv.tv_sec; 345 ctv.tv_sec = tv.tv_sec;
344 ctv.tv_usec = tv.tv_usec; 346 ctv.tv_usec = tv.tv_usec;
345 data = &ctv; 347 data = &ctv;
@@ -414,6 +416,11 @@ static int hci_sock_sendmsg(struct kiocb *iocb, struct socket *sock,
414 goto done; 416 goto done;
415 } 417 }
416 418
419 if (!test_bit(HCI_UP, &hdev->flags)) {
420 err = -ENETDOWN;
421 goto done;
422 }
423
417 if (!(skb = bt_skb_send_alloc(sk, len, msg->msg_flags & MSG_DONTWAIT, &err))) 424 if (!(skb = bt_skb_send_alloc(sk, len, msg->msg_flags & MSG_DONTWAIT, &err)))
418 goto done; 425 goto done;
419 426
@@ -440,10 +447,10 @@ static int hci_sock_sendmsg(struct kiocb *iocb, struct socket *sock,
440 447
441 if (test_bit(HCI_RAW, &hdev->flags) || (ogf == 0x3f)) { 448 if (test_bit(HCI_RAW, &hdev->flags) || (ogf == 0x3f)) {
442 skb_queue_tail(&hdev->raw_q, skb); 449 skb_queue_tail(&hdev->raw_q, skb);
443 hci_sched_tx(hdev); 450 tasklet_schedule(&hdev->tx_task);
444 } else { 451 } else {
445 skb_queue_tail(&hdev->cmd_q, skb); 452 skb_queue_tail(&hdev->cmd_q, skb);
446 hci_sched_cmd(hdev); 453 tasklet_schedule(&hdev->cmd_task);
447 } 454 }
448 } else { 455 } else {
449 if (!capable(CAP_NET_RAW)) { 456 if (!capable(CAP_NET_RAW)) {
@@ -452,7 +459,7 @@ static int hci_sock_sendmsg(struct kiocb *iocb, struct socket *sock,
452 } 459 }
453 460
454 skb_queue_tail(&hdev->raw_q, skb); 461 skb_queue_tail(&hdev->raw_q, skb);
455 hci_sched_tx(hdev); 462 tasklet_schedule(&hdev->tx_task);
456 } 463 }
457 464
458 err = len; 465 err = len;
@@ -621,7 +628,8 @@ static struct proto hci_sk_proto = {
621 .obj_size = sizeof(struct hci_pinfo) 628 .obj_size = sizeof(struct hci_pinfo)
622}; 629};
623 630
624static int hci_sock_create(struct net *net, struct socket *sock, int protocol) 631static int hci_sock_create(struct net *net, struct socket *sock, int protocol,
632 int kern)
625{ 633{
626 struct sock *sk; 634 struct sock *sk;
627 635
@@ -687,7 +695,7 @@ static int hci_sock_dev_event(struct notifier_block *this, unsigned long event,
687 return NOTIFY_DONE; 695 return NOTIFY_DONE;
688} 696}
689 697
690static struct net_proto_family hci_sock_family_ops = { 698static const struct net_proto_family hci_sock_family_ops = {
691 .family = PF_BLUETOOTH, 699 .family = PF_BLUETOOTH,
692 .owner = THIS_MODULE, 700 .owner = THIS_MODULE,
693 .create = hci_sock_create, 701 .create = hci_sock_create,
diff --git a/net/bluetooth/hci_sysfs.c b/net/bluetooth/hci_sysfs.c
index 2bc6f6a8de68..0e8e1a59856c 100644
--- a/net/bluetooth/hci_sysfs.c
+++ b/net/bluetooth/hci_sysfs.c
@@ -1,13 +1,18 @@
1/* Bluetooth HCI driver model support. */ 1/* Bluetooth HCI driver model support. */
2 2
3#include <linux/kernel.h> 3#include <linux/kernel.h>
4#include <linux/slab.h>
4#include <linux/init.h> 5#include <linux/init.h>
6#include <linux/debugfs.h>
7#include <linux/seq_file.h>
5 8
6#include <net/bluetooth/bluetooth.h> 9#include <net/bluetooth/bluetooth.h>
7#include <net/bluetooth/hci_core.h> 10#include <net/bluetooth/hci_core.h>
8 11
9struct class *bt_class = NULL; 12static struct class *bt_class;
10EXPORT_SYMBOL_GPL(bt_class); 13
14struct dentry *bt_debugfs = NULL;
15EXPORT_SYMBOL_GPL(bt_debugfs);
11 16
12static struct workqueue_struct *bt_workq; 17static struct workqueue_struct *bt_workq;
13 18
@@ -166,9 +171,9 @@ void hci_conn_del_sysfs(struct hci_conn *conn)
166 queue_work(bt_workq, &conn->work_del); 171 queue_work(bt_workq, &conn->work_del);
167} 172}
168 173
169static inline char *host_typetostr(int type) 174static inline char *host_bustostr(int bus)
170{ 175{
171 switch (type) { 176 switch (bus) {
172 case HCI_VIRTUAL: 177 case HCI_VIRTUAL:
173 return "VIRTUAL"; 178 return "VIRTUAL";
174 case HCI_USB: 179 case HCI_USB:
@@ -188,10 +193,28 @@ static inline char *host_typetostr(int type)
188 } 193 }
189} 194}
190 195
196static inline char *host_typetostr(int type)
197{
198 switch (type) {
199 case HCI_BREDR:
200 return "BR/EDR";
201 case HCI_80211:
202 return "802.11";
203 default:
204 return "UNKNOWN";
205 }
206}
207
208static ssize_t show_bus(struct device *dev, struct device_attribute *attr, char *buf)
209{
210 struct hci_dev *hdev = dev_get_drvdata(dev);
211 return sprintf(buf, "%s\n", host_bustostr(hdev->bus));
212}
213
191static ssize_t show_type(struct device *dev, struct device_attribute *attr, char *buf) 214static ssize_t show_type(struct device *dev, struct device_attribute *attr, char *buf)
192{ 215{
193 struct hci_dev *hdev = dev_get_drvdata(dev); 216 struct hci_dev *hdev = dev_get_drvdata(dev);
194 return sprintf(buf, "%s\n", host_typetostr(hdev->type)); 217 return sprintf(buf, "%s\n", host_typetostr(hdev->dev_type));
195} 218}
196 219
197static ssize_t show_name(struct device *dev, struct device_attribute *attr, char *buf) 220static ssize_t show_name(struct device *dev, struct device_attribute *attr, char *buf)
@@ -251,32 +274,6 @@ static ssize_t show_hci_revision(struct device *dev, struct device_attribute *at
251 return sprintf(buf, "%d\n", hdev->hci_rev); 274 return sprintf(buf, "%d\n", hdev->hci_rev);
252} 275}
253 276
254static ssize_t show_inquiry_cache(struct device *dev, struct device_attribute *attr, char *buf)
255{
256 struct hci_dev *hdev = dev_get_drvdata(dev);
257 struct inquiry_cache *cache = &hdev->inq_cache;
258 struct inquiry_entry *e;
259 int n = 0;
260
261 hci_dev_lock_bh(hdev);
262
263 for (e = cache->list; e; e = e->next) {
264 struct inquiry_data *data = &e->data;
265 bdaddr_t bdaddr;
266 baswap(&bdaddr, &data->bdaddr);
267 n += sprintf(buf + n, "%s %d %d %d 0x%.2x%.2x%.2x 0x%.4x %d %d %u\n",
268 batostr(&bdaddr),
269 data->pscan_rep_mode, data->pscan_period_mode,
270 data->pscan_mode, data->dev_class[2],
271 data->dev_class[1], data->dev_class[0],
272 __le16_to_cpu(data->clock_offset),
273 data->rssi, data->ssp_mode, e->timestamp);
274 }
275
276 hci_dev_unlock_bh(hdev);
277 return n;
278}
279
280static ssize_t show_idle_timeout(struct device *dev, struct device_attribute *attr, char *buf) 277static ssize_t show_idle_timeout(struct device *dev, struct device_attribute *attr, char *buf)
281{ 278{
282 struct hci_dev *hdev = dev_get_drvdata(dev); 279 struct hci_dev *hdev = dev_get_drvdata(dev);
@@ -355,6 +352,7 @@ static ssize_t store_sniff_min_interval(struct device *dev, struct device_attrib
355 return count; 352 return count;
356} 353}
357 354
355static DEVICE_ATTR(bus, S_IRUGO, show_bus, NULL);
358static DEVICE_ATTR(type, S_IRUGO, show_type, NULL); 356static DEVICE_ATTR(type, S_IRUGO, show_type, NULL);
359static DEVICE_ATTR(name, S_IRUGO, show_name, NULL); 357static DEVICE_ATTR(name, S_IRUGO, show_name, NULL);
360static DEVICE_ATTR(class, S_IRUGO, show_class, NULL); 358static DEVICE_ATTR(class, S_IRUGO, show_class, NULL);
@@ -363,7 +361,6 @@ static DEVICE_ATTR(features, S_IRUGO, show_features, NULL);
363static DEVICE_ATTR(manufacturer, S_IRUGO, show_manufacturer, NULL); 361static DEVICE_ATTR(manufacturer, S_IRUGO, show_manufacturer, NULL);
364static DEVICE_ATTR(hci_version, S_IRUGO, show_hci_version, NULL); 362static DEVICE_ATTR(hci_version, S_IRUGO, show_hci_version, NULL);
365static DEVICE_ATTR(hci_revision, S_IRUGO, show_hci_revision, NULL); 363static DEVICE_ATTR(hci_revision, S_IRUGO, show_hci_revision, NULL);
366static DEVICE_ATTR(inquiry_cache, S_IRUGO, show_inquiry_cache, NULL);
367 364
368static DEVICE_ATTR(idle_timeout, S_IRUGO | S_IWUSR, 365static DEVICE_ATTR(idle_timeout, S_IRUGO | S_IWUSR,
369 show_idle_timeout, store_idle_timeout); 366 show_idle_timeout, store_idle_timeout);
@@ -373,6 +370,7 @@ static DEVICE_ATTR(sniff_min_interval, S_IRUGO | S_IWUSR,
373 show_sniff_min_interval, store_sniff_min_interval); 370 show_sniff_min_interval, store_sniff_min_interval);
374 371
375static struct attribute *bt_host_attrs[] = { 372static struct attribute *bt_host_attrs[] = {
373 &dev_attr_bus.attr,
376 &dev_attr_type.attr, 374 &dev_attr_type.attr,
377 &dev_attr_name.attr, 375 &dev_attr_name.attr,
378 &dev_attr_class.attr, 376 &dev_attr_class.attr,
@@ -381,7 +379,6 @@ static struct attribute *bt_host_attrs[] = {
381 &dev_attr_manufacturer.attr, 379 &dev_attr_manufacturer.attr,
382 &dev_attr_hci_version.attr, 380 &dev_attr_hci_version.attr,
383 &dev_attr_hci_revision.attr, 381 &dev_attr_hci_revision.attr,
384 &dev_attr_inquiry_cache.attr,
385 &dev_attr_idle_timeout.attr, 382 &dev_attr_idle_timeout.attr,
386 &dev_attr_sniff_max_interval.attr, 383 &dev_attr_sniff_max_interval.attr,
387 &dev_attr_sniff_min_interval.attr, 384 &dev_attr_sniff_min_interval.attr,
@@ -409,12 +406,50 @@ static struct device_type bt_host = {
409 .release = bt_host_release, 406 .release = bt_host_release,
410}; 407};
411 408
409static int inquiry_cache_show(struct seq_file *f, void *p)
410{
411 struct hci_dev *hdev = f->private;
412 struct inquiry_cache *cache = &hdev->inq_cache;
413 struct inquiry_entry *e;
414
415 hci_dev_lock_bh(hdev);
416
417 for (e = cache->list; e; e = e->next) {
418 struct inquiry_data *data = &e->data;
419 bdaddr_t bdaddr;
420 baswap(&bdaddr, &data->bdaddr);
421 seq_printf(f, "%s %d %d %d 0x%.2x%.2x%.2x 0x%.4x %d %d %u\n",
422 batostr(&bdaddr),
423 data->pscan_rep_mode, data->pscan_period_mode,
424 data->pscan_mode, data->dev_class[2],
425 data->dev_class[1], data->dev_class[0],
426 __le16_to_cpu(data->clock_offset),
427 data->rssi, data->ssp_mode, e->timestamp);
428 }
429
430 hci_dev_unlock_bh(hdev);
431
432 return 0;
433}
434
435static int inquiry_cache_open(struct inode *inode, struct file *file)
436{
437 return single_open(file, inquiry_cache_show, inode->i_private);
438}
439
440static const struct file_operations inquiry_cache_fops = {
441 .open = inquiry_cache_open,
442 .read = seq_read,
443 .llseek = seq_lseek,
444 .release = single_release,
445};
446
412int hci_register_sysfs(struct hci_dev *hdev) 447int hci_register_sysfs(struct hci_dev *hdev)
413{ 448{
414 struct device *dev = &hdev->dev; 449 struct device *dev = &hdev->dev;
415 int err; 450 int err;
416 451
417 BT_DBG("%p name %s type %d", hdev, hdev->name, hdev->type); 452 BT_DBG("%p name %s bus %d", hdev, hdev->name, hdev->bus);
418 453
419 dev->type = &bt_host; 454 dev->type = &bt_host;
420 dev->class = bt_class; 455 dev->class = bt_class;
@@ -428,12 +463,24 @@ int hci_register_sysfs(struct hci_dev *hdev)
428 if (err < 0) 463 if (err < 0)
429 return err; 464 return err;
430 465
466 if (!bt_debugfs)
467 return 0;
468
469 hdev->debugfs = debugfs_create_dir(hdev->name, bt_debugfs);
470 if (!hdev->debugfs)
471 return 0;
472
473 debugfs_create_file("inquiry_cache", 0444, hdev->debugfs,
474 hdev, &inquiry_cache_fops);
475
431 return 0; 476 return 0;
432} 477}
433 478
434void hci_unregister_sysfs(struct hci_dev *hdev) 479void hci_unregister_sysfs(struct hci_dev *hdev)
435{ 480{
436 BT_DBG("%p name %s type %d", hdev, hdev->name, hdev->type); 481 BT_DBG("%p name %s bus %d", hdev, hdev->name, hdev->bus);
482
483 debugfs_remove_recursive(hdev->debugfs);
437 484
438 device_del(&hdev->dev); 485 device_del(&hdev->dev);
439} 486}
@@ -444,6 +491,8 @@ int __init bt_sysfs_init(void)
444 if (!bt_workq) 491 if (!bt_workq)
445 return -ENOMEM; 492 return -ENOMEM;
446 493
494 bt_debugfs = debugfs_create_dir("bluetooth", NULL);
495
447 bt_class = class_create(THIS_MODULE, "bluetooth"); 496 bt_class = class_create(THIS_MODULE, "bluetooth");
448 if (IS_ERR(bt_class)) { 497 if (IS_ERR(bt_class)) {
449 destroy_workqueue(bt_workq); 498 destroy_workqueue(bt_workq);
@@ -455,7 +504,9 @@ int __init bt_sysfs_init(void)
455 504
456void bt_sysfs_cleanup(void) 505void bt_sysfs_cleanup(void)
457{ 506{
458 destroy_workqueue(bt_workq);
459
460 class_destroy(bt_class); 507 class_destroy(bt_class);
508
509 debugfs_remove_recursive(bt_debugfs);
510
511 destroy_workqueue(bt_workq);
461} 512}
diff --git a/net/bluetooth/hidp/core.c b/net/bluetooth/hidp/core.c
index 49d8495d69be..280529ad9274 100644
--- a/net/bluetooth/hidp/core.c
+++ b/net/bluetooth/hidp/core.c
@@ -243,6 +243,39 @@ static void hidp_input_report(struct hidp_session *session, struct sk_buff *skb)
243 input_sync(dev); 243 input_sync(dev);
244} 244}
245 245
246static int __hidp_send_ctrl_message(struct hidp_session *session,
247 unsigned char hdr, unsigned char *data, int size)
248{
249 struct sk_buff *skb;
250
251 BT_DBG("session %p data %p size %d", session, data, size);
252
253 if (!(skb = alloc_skb(size + 1, GFP_ATOMIC))) {
254 BT_ERR("Can't allocate memory for new frame");
255 return -ENOMEM;
256 }
257
258 *skb_put(skb, 1) = hdr;
259 if (data && size > 0)
260 memcpy(skb_put(skb, size), data, size);
261
262 skb_queue_tail(&session->ctrl_transmit, skb);
263
264 return 0;
265}
266
267static inline int hidp_send_ctrl_message(struct hidp_session *session,
268 unsigned char hdr, unsigned char *data, int size)
269{
270 int err;
271
272 err = __hidp_send_ctrl_message(session, hdr, data, size);
273
274 hidp_schedule(session);
275
276 return err;
277}
278
246static int hidp_queue_report(struct hidp_session *session, 279static int hidp_queue_report(struct hidp_session *session,
247 unsigned char *data, int size) 280 unsigned char *data, int size)
248{ 281{
@@ -280,6 +313,26 @@ static int hidp_send_report(struct hidp_session *session, struct hid_report *rep
280 return hidp_queue_report(session, buf, rsize); 313 return hidp_queue_report(session, buf, rsize);
281} 314}
282 315
316static int hidp_output_raw_report(struct hid_device *hid, unsigned char *data, size_t count,
317 unsigned char report_type)
318{
319 switch (report_type) {
320 case HID_FEATURE_REPORT:
321 report_type = HIDP_TRANS_SET_REPORT | HIDP_DATA_RTYPE_FEATURE;
322 break;
323 case HID_OUTPUT_REPORT:
324 report_type = HIDP_TRANS_DATA | HIDP_DATA_RTYPE_OUPUT;
325 break;
326 default:
327 return -EINVAL;
328 }
329
330 if (hidp_send_ctrl_message(hid->driver_data, report_type,
331 data, count))
332 return -ENOMEM;
333 return count;
334}
335
283static void hidp_idle_timeout(unsigned long arg) 336static void hidp_idle_timeout(unsigned long arg)
284{ 337{
285 struct hidp_session *session = (struct hidp_session *) arg; 338 struct hidp_session *session = (struct hidp_session *) arg;
@@ -300,39 +353,6 @@ static inline void hidp_del_timer(struct hidp_session *session)
300 del_timer(&session->timer); 353 del_timer(&session->timer);
301} 354}
302 355
303static int __hidp_send_ctrl_message(struct hidp_session *session,
304 unsigned char hdr, unsigned char *data, int size)
305{
306 struct sk_buff *skb;
307
308 BT_DBG("session %p data %p size %d", session, data, size);
309
310 if (!(skb = alloc_skb(size + 1, GFP_ATOMIC))) {
311 BT_ERR("Can't allocate memory for new frame");
312 return -ENOMEM;
313 }
314
315 *skb_put(skb, 1) = hdr;
316 if (data && size > 0)
317 memcpy(skb_put(skb, size), data, size);
318
319 skb_queue_tail(&session->ctrl_transmit, skb);
320
321 return 0;
322}
323
324static inline int hidp_send_ctrl_message(struct hidp_session *session,
325 unsigned char hdr, unsigned char *data, int size)
326{
327 int err;
328
329 err = __hidp_send_ctrl_message(session, hdr, data, size);
330
331 hidp_schedule(session);
332
333 return err;
334}
335
336static void hidp_process_handshake(struct hidp_session *session, 356static void hidp_process_handshake(struct hidp_session *session,
337 unsigned char param) 357 unsigned char param)
338{ 358{
@@ -694,29 +714,9 @@ static void hidp_close(struct hid_device *hid)
694static int hidp_parse(struct hid_device *hid) 714static int hidp_parse(struct hid_device *hid)
695{ 715{
696 struct hidp_session *session = hid->driver_data; 716 struct hidp_session *session = hid->driver_data;
697 struct hidp_connadd_req *req = session->req;
698 unsigned char *buf;
699 int ret;
700
701 buf = kmalloc(req->rd_size, GFP_KERNEL);
702 if (!buf)
703 return -ENOMEM;
704
705 if (copy_from_user(buf, req->rd_data, req->rd_size)) {
706 kfree(buf);
707 return -EFAULT;
708 }
709
710 ret = hid_parse_report(session->hid, buf, req->rd_size);
711
712 kfree(buf);
713
714 if (ret)
715 return ret;
716 717
717 session->req = NULL; 718 return hid_parse_report(session->hid, session->rd_data,
718 719 session->rd_size);
719 return 0;
720} 720}
721 721
722static int hidp_start(struct hid_device *hid) 722static int hidp_start(struct hid_device *hid)
@@ -761,12 +761,24 @@ static int hidp_setup_hid(struct hidp_session *session,
761 bdaddr_t src, dst; 761 bdaddr_t src, dst;
762 int err; 762 int err;
763 763
764 session->rd_data = kzalloc(req->rd_size, GFP_KERNEL);
765 if (!session->rd_data)
766 return -ENOMEM;
767
768 if (copy_from_user(session->rd_data, req->rd_data, req->rd_size)) {
769 err = -EFAULT;
770 goto fault;
771 }
772 session->rd_size = req->rd_size;
773
764 hid = hid_allocate_device(); 774 hid = hid_allocate_device();
765 if (IS_ERR(hid)) 775 if (IS_ERR(hid)) {
766 return PTR_ERR(session->hid); 776 err = PTR_ERR(hid);
777 goto fault;
778 }
767 779
768 session->hid = hid; 780 session->hid = hid;
769 session->req = req; 781
770 hid->driver_data = session; 782 hid->driver_data = session;
771 783
772 baswap(&src, &bt_sk(session->ctrl_sock->sk)->src); 784 baswap(&src, &bt_sk(session->ctrl_sock->sk)->src);
@@ -785,6 +797,8 @@ static int hidp_setup_hid(struct hidp_session *session,
785 hid->dev.parent = hidp_get_device(session); 797 hid->dev.parent = hidp_get_device(session);
786 hid->ll_driver = &hidp_hid_driver; 798 hid->ll_driver = &hidp_hid_driver;
787 799
800 hid->hid_output_raw_report = hidp_output_raw_report;
801
788 err = hid_add_device(hid); 802 err = hid_add_device(hid);
789 if (err < 0) 803 if (err < 0)
790 goto failed; 804 goto failed;
@@ -795,6 +809,10 @@ failed:
795 hid_destroy_device(hid); 809 hid_destroy_device(hid);
796 session->hid = NULL; 810 session->hid = NULL;
797 811
812fault:
813 kfree(session->rd_data);
814 session->rd_data = NULL;
815
798 return err; 816 return err;
799} 817}
800 818
@@ -889,6 +907,9 @@ unlink:
889 session->hid = NULL; 907 session->hid = NULL;
890 } 908 }
891 909
910 kfree(session->rd_data);
911 session->rd_data = NULL;
912
892purge: 913purge:
893 skb_queue_purge(&session->ctrl_transmit); 914 skb_queue_purge(&session->ctrl_transmit);
894 skb_queue_purge(&session->intr_transmit); 915 skb_queue_purge(&session->intr_transmit);
diff --git a/net/bluetooth/hidp/hidp.h b/net/bluetooth/hidp/hidp.h
index faf3d74c3586..a4e215d50c10 100644
--- a/net/bluetooth/hidp/hidp.h
+++ b/net/bluetooth/hidp/hidp.h
@@ -154,7 +154,9 @@ struct hidp_session {
154 struct sk_buff_head ctrl_transmit; 154 struct sk_buff_head ctrl_transmit;
155 struct sk_buff_head intr_transmit; 155 struct sk_buff_head intr_transmit;
156 156
157 struct hidp_connadd_req *req; 157 /* Report descriptor */
158 __u8 *rd_data;
159 uint rd_size;
158}; 160};
159 161
160static inline void hidp_schedule(struct hidp_session *session) 162static inline void hidp_schedule(struct hidp_session *session)
diff --git a/net/bluetooth/hidp/sock.c b/net/bluetooth/hidp/sock.c
index 37c9d7d2e688..250dfd46237d 100644
--- a/net/bluetooth/hidp/sock.c
+++ b/net/bluetooth/hidp/sock.c
@@ -26,7 +26,6 @@
26#include <linux/capability.h> 26#include <linux/capability.h>
27#include <linux/errno.h> 27#include <linux/errno.h>
28#include <linux/kernel.h> 28#include <linux/kernel.h>
29#include <linux/slab.h>
30#include <linux/poll.h> 29#include <linux/poll.h>
31#include <linux/fcntl.h> 30#include <linux/fcntl.h>
32#include <linux/skbuff.h> 31#include <linux/skbuff.h>
@@ -35,6 +34,7 @@
35#include <linux/file.h> 34#include <linux/file.h>
36#include <linux/init.h> 35#include <linux/init.h>
37#include <linux/compat.h> 36#include <linux/compat.h>
37#include <linux/gfp.h>
38#include <net/sock.h> 38#include <net/sock.h>
39 39
40#include "hidp.h" 40#include "hidp.h"
@@ -241,7 +241,8 @@ static struct proto hidp_proto = {
241 .obj_size = sizeof(struct bt_sock) 241 .obj_size = sizeof(struct bt_sock)
242}; 242};
243 243
244static int hidp_sock_create(struct net *net, struct socket *sock, int protocol) 244static int hidp_sock_create(struct net *net, struct socket *sock, int protocol,
245 int kern)
245{ 246{
246 struct sock *sk; 247 struct sock *sk;
247 248
@@ -268,7 +269,7 @@ static int hidp_sock_create(struct net *net, struct socket *sock, int protocol)
268 return 0; 269 return 0;
269} 270}
270 271
271static struct net_proto_family hidp_sock_family_ops = { 272static const struct net_proto_family hidp_sock_family_ops = {
272 .family = PF_BLUETOOTH, 273 .family = PF_BLUETOOTH,
273 .owner = THIS_MODULE, 274 .owner = THIS_MODULE,
274 .create = hidp_sock_create 275 .create = hidp_sock_create
diff --git a/net/bluetooth/l2cap.c b/net/bluetooth/l2cap.c
index 947f8bbb4bb3..9753b690a8b3 100644
--- a/net/bluetooth/l2cap.c
+++ b/net/bluetooth/l2cap.c
@@ -40,6 +40,8 @@
40#include <linux/skbuff.h> 40#include <linux/skbuff.h>
41#include <linux/list.h> 41#include <linux/list.h>
42#include <linux/device.h> 42#include <linux/device.h>
43#include <linux/debugfs.h>
44#include <linux/seq_file.h>
43#include <linux/uaccess.h> 45#include <linux/uaccess.h>
44#include <linux/crc16.h> 46#include <linux/crc16.h>
45#include <net/sock.h> 47#include <net/sock.h>
@@ -54,6 +56,7 @@
54#define VERSION "2.14" 56#define VERSION "2.14"
55 57
56static int enable_ertm = 0; 58static int enable_ertm = 0;
59static int max_transmit = L2CAP_DEFAULT_MAX_TX;
57 60
58static u32 l2cap_feat_mask = L2CAP_FEAT_FIXED_CHAN; 61static u32 l2cap_feat_mask = L2CAP_FEAT_FIXED_CHAN;
59static u8 l2cap_fixed_chan[8] = { 0x02, }; 62static u8 l2cap_fixed_chan[8] = { 0x02, };
@@ -373,6 +376,8 @@ static inline int l2cap_send_rr_or_rnr(struct l2cap_pinfo *pi, u16 control)
373 else 376 else
374 control |= L2CAP_SUPER_RCV_READY; 377 control |= L2CAP_SUPER_RCV_READY;
375 378
379 control |= pi->buffer_seq << L2CAP_CTRL_REQSEQ_SHIFT;
380
376 return l2cap_send_sframe(pi, control); 381 return l2cap_send_sframe(pi, control);
377} 382}
378 383
@@ -819,7 +824,8 @@ static struct sock *l2cap_sock_alloc(struct net *net, struct socket *sock, int p
819 return sk; 824 return sk;
820} 825}
821 826
822static int l2cap_sock_create(struct net *net, struct socket *sock, int protocol) 827static int l2cap_sock_create(struct net *net, struct socket *sock, int protocol,
828 int kern)
823{ 829{
824 struct sock *sk; 830 struct sock *sk;
825 831
@@ -831,7 +837,7 @@ static int l2cap_sock_create(struct net *net, struct socket *sock, int protocol)
831 sock->type != SOCK_DGRAM && sock->type != SOCK_RAW) 837 sock->type != SOCK_DGRAM && sock->type != SOCK_RAW)
832 return -ESOCKTNOSUPPORT; 838 return -ESOCKTNOSUPPORT;
833 839
834 if (sock->type == SOCK_RAW && !capable(CAP_NET_RAW)) 840 if (sock->type == SOCK_RAW && !kern && !capable(CAP_NET_RAW))
835 return -EPERM; 841 return -EPERM;
836 842
837 sock->ops = &l2cap_sock_ops; 843 sock->ops = &l2cap_sock_ops;
@@ -996,7 +1002,8 @@ static int l2cap_sock_connect(struct socket *sock, struct sockaddr *addr, int al
996 1002
997 BT_DBG("sk %p", sk); 1003 BT_DBG("sk %p", sk);
998 1004
999 if (!addr || addr->sa_family != AF_BLUETOOTH) 1005 if (!addr || alen < sizeof(addr->sa_family) ||
1006 addr->sa_family != AF_BLUETOOTH)
1000 return -EINVAL; 1007 return -EINVAL;
1001 1008
1002 memset(&la, 0, sizeof(la)); 1009 memset(&la, 0, sizeof(la));
@@ -1208,6 +1215,7 @@ static void l2cap_monitor_timeout(unsigned long arg)
1208 bh_lock_sock(sk); 1215 bh_lock_sock(sk);
1209 if (l2cap_pi(sk)->retry_count >= l2cap_pi(sk)->remote_max_tx) { 1216 if (l2cap_pi(sk)->retry_count >= l2cap_pi(sk)->remote_max_tx) {
1210 l2cap_send_disconn_req(l2cap_pi(sk)->conn, sk); 1217 l2cap_send_disconn_req(l2cap_pi(sk)->conn, sk);
1218 bh_unlock_sock(sk);
1211 return; 1219 return;
1212 } 1220 }
1213 1221
@@ -1332,7 +1340,7 @@ static int l2cap_retransmit_frame(struct sock *sk, u8 tx_seq)
1332 tx_skb = skb_clone(skb, GFP_ATOMIC); 1340 tx_skb = skb_clone(skb, GFP_ATOMIC);
1333 bt_cb(skb)->retries++; 1341 bt_cb(skb)->retries++;
1334 control = get_unaligned_le16(tx_skb->data + L2CAP_HDR_SIZE); 1342 control = get_unaligned_le16(tx_skb->data + L2CAP_HDR_SIZE);
1335 control |= (pi->req_seq << L2CAP_CTRL_REQSEQ_SHIFT) 1343 control |= (pi->buffer_seq << L2CAP_CTRL_REQSEQ_SHIFT)
1336 | (tx_seq << L2CAP_CTRL_TXSEQ_SHIFT); 1344 | (tx_seq << L2CAP_CTRL_TXSEQ_SHIFT);
1337 put_unaligned_le16(control, tx_skb->data + L2CAP_HDR_SIZE); 1345 put_unaligned_le16(control, tx_skb->data + L2CAP_HDR_SIZE);
1338 1346
@@ -1361,9 +1369,8 @@ static int l2cap_ertm_send(struct sock *sk)
1361 if (pi->conn_state & L2CAP_CONN_WAIT_F) 1369 if (pi->conn_state & L2CAP_CONN_WAIT_F)
1362 return 0; 1370 return 0;
1363 1371
1364 while ((skb = sk->sk_send_head) && (!l2cap_tx_window_full(sk)) 1372 while ((skb = sk->sk_send_head) && (!l2cap_tx_window_full(sk)) &&
1365 && !(pi->conn_state & L2CAP_CONN_REMOTE_BUSY)) { 1373 !(pi->conn_state & L2CAP_CONN_REMOTE_BUSY)) {
1366 tx_skb = skb_clone(skb, GFP_ATOMIC);
1367 1374
1368 if (pi->remote_max_tx && 1375 if (pi->remote_max_tx &&
1369 bt_cb(skb)->retries == pi->remote_max_tx) { 1376 bt_cb(skb)->retries == pi->remote_max_tx) {
@@ -1371,10 +1378,12 @@ static int l2cap_ertm_send(struct sock *sk)
1371 break; 1378 break;
1372 } 1379 }
1373 1380
1381 tx_skb = skb_clone(skb, GFP_ATOMIC);
1382
1374 bt_cb(skb)->retries++; 1383 bt_cb(skb)->retries++;
1375 1384
1376 control = get_unaligned_le16(tx_skb->data + L2CAP_HDR_SIZE); 1385 control = get_unaligned_le16(tx_skb->data + L2CAP_HDR_SIZE);
1377 control |= (pi->req_seq << L2CAP_CTRL_REQSEQ_SHIFT) 1386 control |= (pi->buffer_seq << L2CAP_CTRL_REQSEQ_SHIFT)
1378 | (pi->next_tx_seq << L2CAP_CTRL_TXSEQ_SHIFT); 1387 | (pi->next_tx_seq << L2CAP_CTRL_TXSEQ_SHIFT);
1379 put_unaligned_le16(control, tx_skb->data + L2CAP_HDR_SIZE); 1388 put_unaligned_le16(control, tx_skb->data + L2CAP_HDR_SIZE);
1380 1389
@@ -1603,8 +1612,8 @@ static int l2cap_sock_sendmsg(struct kiocb *iocb, struct socket *sock, struct ms
1603 return -EOPNOTSUPP; 1612 return -EOPNOTSUPP;
1604 1613
1605 /* Check outgoing MTU */ 1614 /* Check outgoing MTU */
1606 if (sk->sk_type == SOCK_SEQPACKET && pi->mode == L2CAP_MODE_BASIC 1615 if (sk->sk_type == SOCK_SEQPACKET && pi->mode == L2CAP_MODE_BASIC &&
1607 && len > pi->omtu) 1616 len > pi->omtu)
1608 return -EINVAL; 1617 return -EINVAL;
1609 1618
1610 lock_sock(sk); 1619 lock_sock(sk);
@@ -1617,7 +1626,10 @@ static int l2cap_sock_sendmsg(struct kiocb *iocb, struct socket *sock, struct ms
1617 /* Connectionless channel */ 1626 /* Connectionless channel */
1618 if (sk->sk_type == SOCK_DGRAM) { 1627 if (sk->sk_type == SOCK_DGRAM) {
1619 skb = l2cap_create_connless_pdu(sk, msg, len); 1628 skb = l2cap_create_connless_pdu(sk, msg, len);
1620 err = l2cap_do_send(sk, skb); 1629 if (IS_ERR(skb))
1630 err = PTR_ERR(skb);
1631 else
1632 err = l2cap_do_send(sk, skb);
1621 goto done; 1633 goto done;
1622 } 1634 }
1623 1635
@@ -2172,6 +2184,21 @@ static void l2cap_add_conf_opt(void **ptr, u8 type, u8 len, unsigned long val)
2172 *ptr += L2CAP_CONF_OPT_SIZE + len; 2184 *ptr += L2CAP_CONF_OPT_SIZE + len;
2173} 2185}
2174 2186
2187static inline void l2cap_ertm_init(struct sock *sk)
2188{
2189 l2cap_pi(sk)->expected_ack_seq = 0;
2190 l2cap_pi(sk)->unacked_frames = 0;
2191 l2cap_pi(sk)->buffer_seq = 0;
2192 l2cap_pi(sk)->num_to_ack = 0;
2193
2194 setup_timer(&l2cap_pi(sk)->retrans_timer,
2195 l2cap_retrans_timeout, (unsigned long) sk);
2196 setup_timer(&l2cap_pi(sk)->monitor_timer,
2197 l2cap_monitor_timeout, (unsigned long) sk);
2198
2199 __skb_queue_head_init(SREJ_QUEUE(sk));
2200}
2201
2175static int l2cap_mode_supported(__u8 mode, __u32 feat_mask) 2202static int l2cap_mode_supported(__u8 mode, __u32 feat_mask)
2176{ 2203{
2177 u32 local_feat_mask = l2cap_feat_mask; 2204 u32 local_feat_mask = l2cap_feat_mask;
@@ -2235,7 +2262,7 @@ done:
2235 case L2CAP_MODE_ERTM: 2262 case L2CAP_MODE_ERTM:
2236 rfc.mode = L2CAP_MODE_ERTM; 2263 rfc.mode = L2CAP_MODE_ERTM;
2237 rfc.txwin_size = L2CAP_DEFAULT_TX_WINDOW; 2264 rfc.txwin_size = L2CAP_DEFAULT_TX_WINDOW;
2238 rfc.max_transmit = L2CAP_DEFAULT_MAX_TX; 2265 rfc.max_transmit = max_transmit;
2239 rfc.retrans_timeout = 0; 2266 rfc.retrans_timeout = 0;
2240 rfc.monitor_timeout = 0; 2267 rfc.monitor_timeout = 0;
2241 rfc.max_pdu_size = cpu_to_le16(L2CAP_DEFAULT_MAX_PDU_SIZE); 2268 rfc.max_pdu_size = cpu_to_le16(L2CAP_DEFAULT_MAX_PDU_SIZE);
@@ -2755,22 +2782,18 @@ static inline int l2cap_config_req(struct l2cap_conn *conn, struct l2cap_cmd_hdr
2755 goto unlock; 2782 goto unlock;
2756 2783
2757 if (l2cap_pi(sk)->conf_state & L2CAP_CONF_INPUT_DONE) { 2784 if (l2cap_pi(sk)->conf_state & L2CAP_CONF_INPUT_DONE) {
2758 if (!(l2cap_pi(sk)->conf_state & L2CAP_CONF_NO_FCS_RECV) 2785 if (!(l2cap_pi(sk)->conf_state & L2CAP_CONF_NO_FCS_RECV) ||
2759 || l2cap_pi(sk)->fcs != L2CAP_FCS_NONE) 2786 l2cap_pi(sk)->fcs != L2CAP_FCS_NONE)
2760 l2cap_pi(sk)->fcs = L2CAP_FCS_CRC16; 2787 l2cap_pi(sk)->fcs = L2CAP_FCS_CRC16;
2761 2788
2762 sk->sk_state = BT_CONNECTED; 2789 sk->sk_state = BT_CONNECTED;
2763 l2cap_pi(sk)->next_tx_seq = 0;
2764 l2cap_pi(sk)->expected_ack_seq = 0;
2765 l2cap_pi(sk)->unacked_frames = 0;
2766
2767 setup_timer(&l2cap_pi(sk)->retrans_timer,
2768 l2cap_retrans_timeout, (unsigned long) sk);
2769 setup_timer(&l2cap_pi(sk)->monitor_timer,
2770 l2cap_monitor_timeout, (unsigned long) sk);
2771 2790
2791 l2cap_pi(sk)->next_tx_seq = 0;
2792 l2cap_pi(sk)->expected_tx_seq = 0;
2772 __skb_queue_head_init(TX_QUEUE(sk)); 2793 __skb_queue_head_init(TX_QUEUE(sk));
2773 __skb_queue_head_init(SREJ_QUEUE(sk)); 2794 if (l2cap_pi(sk)->mode == L2CAP_MODE_ERTM)
2795 l2cap_ertm_init(sk);
2796
2774 l2cap_chan_ready(sk); 2797 l2cap_chan_ready(sk);
2775 goto unlock; 2798 goto unlock;
2776 } 2799 }
@@ -2813,6 +2836,11 @@ static inline int l2cap_config_rsp(struct l2cap_conn *conn, struct l2cap_cmd_hdr
2813 int len = cmd->len - sizeof(*rsp); 2836 int len = cmd->len - sizeof(*rsp);
2814 char req[64]; 2837 char req[64];
2815 2838
2839 if (len > sizeof(req) - sizeof(struct l2cap_conf_req)) {
2840 l2cap_send_disconn_req(conn, sk);
2841 goto done;
2842 }
2843
2816 /* throw out any old stored conf requests */ 2844 /* throw out any old stored conf requests */
2817 result = L2CAP_CONF_SUCCESS; 2845 result = L2CAP_CONF_SUCCESS;
2818 len = l2cap_parse_conf_rsp(sk, rsp->data, 2846 len = l2cap_parse_conf_rsp(sk, rsp->data,
@@ -2844,16 +2872,17 @@ static inline int l2cap_config_rsp(struct l2cap_conn *conn, struct l2cap_cmd_hdr
2844 l2cap_pi(sk)->conf_state |= L2CAP_CONF_INPUT_DONE; 2872 l2cap_pi(sk)->conf_state |= L2CAP_CONF_INPUT_DONE;
2845 2873
2846 if (l2cap_pi(sk)->conf_state & L2CAP_CONF_OUTPUT_DONE) { 2874 if (l2cap_pi(sk)->conf_state & L2CAP_CONF_OUTPUT_DONE) {
2847 if (!(l2cap_pi(sk)->conf_state & L2CAP_CONF_NO_FCS_RECV) 2875 if (!(l2cap_pi(sk)->conf_state & L2CAP_CONF_NO_FCS_RECV) ||
2848 || l2cap_pi(sk)->fcs != L2CAP_FCS_NONE) 2876 l2cap_pi(sk)->fcs != L2CAP_FCS_NONE)
2849 l2cap_pi(sk)->fcs = L2CAP_FCS_CRC16; 2877 l2cap_pi(sk)->fcs = L2CAP_FCS_CRC16;
2850 2878
2851 sk->sk_state = BT_CONNECTED; 2879 sk->sk_state = BT_CONNECTED;
2880 l2cap_pi(sk)->next_tx_seq = 0;
2852 l2cap_pi(sk)->expected_tx_seq = 0; 2881 l2cap_pi(sk)->expected_tx_seq = 0;
2853 l2cap_pi(sk)->buffer_seq = 0;
2854 l2cap_pi(sk)->num_to_ack = 0;
2855 __skb_queue_head_init(TX_QUEUE(sk)); 2882 __skb_queue_head_init(TX_QUEUE(sk));
2856 __skb_queue_head_init(SREJ_QUEUE(sk)); 2883 if (l2cap_pi(sk)->mode == L2CAP_MODE_ERTM)
2884 l2cap_ertm_init(sk);
2885
2857 l2cap_chan_ready(sk); 2886 l2cap_chan_ready(sk);
2858 } 2887 }
2859 2888
@@ -2885,9 +2914,12 @@ static inline int l2cap_disconnect_req(struct l2cap_conn *conn, struct l2cap_cmd
2885 sk->sk_shutdown = SHUTDOWN_MASK; 2914 sk->sk_shutdown = SHUTDOWN_MASK;
2886 2915
2887 skb_queue_purge(TX_QUEUE(sk)); 2916 skb_queue_purge(TX_QUEUE(sk));
2888 skb_queue_purge(SREJ_QUEUE(sk)); 2917
2889 del_timer(&l2cap_pi(sk)->retrans_timer); 2918 if (l2cap_pi(sk)->mode == L2CAP_MODE_ERTM) {
2890 del_timer(&l2cap_pi(sk)->monitor_timer); 2919 skb_queue_purge(SREJ_QUEUE(sk));
2920 del_timer(&l2cap_pi(sk)->retrans_timer);
2921 del_timer(&l2cap_pi(sk)->monitor_timer);
2922 }
2891 2923
2892 l2cap_chan_del(sk, ECONNRESET); 2924 l2cap_chan_del(sk, ECONNRESET);
2893 bh_unlock_sock(sk); 2925 bh_unlock_sock(sk);
@@ -2912,9 +2944,12 @@ static inline int l2cap_disconnect_rsp(struct l2cap_conn *conn, struct l2cap_cmd
2912 return 0; 2944 return 0;
2913 2945
2914 skb_queue_purge(TX_QUEUE(sk)); 2946 skb_queue_purge(TX_QUEUE(sk));
2915 skb_queue_purge(SREJ_QUEUE(sk)); 2947
2916 del_timer(&l2cap_pi(sk)->retrans_timer); 2948 if (l2cap_pi(sk)->mode == L2CAP_MODE_ERTM) {
2917 del_timer(&l2cap_pi(sk)->monitor_timer); 2949 skb_queue_purge(SREJ_QUEUE(sk));
2950 del_timer(&l2cap_pi(sk)->retrans_timer);
2951 del_timer(&l2cap_pi(sk)->monitor_timer);
2952 }
2918 2953
2919 l2cap_chan_del(sk, 0); 2954 l2cap_chan_del(sk, 0);
2920 bh_unlock_sock(sk); 2955 bh_unlock_sock(sk);
@@ -3279,12 +3314,16 @@ static inline int l2cap_data_channel_iframe(struct sock *sk, u16 rx_control, str
3279{ 3314{
3280 struct l2cap_pinfo *pi = l2cap_pi(sk); 3315 struct l2cap_pinfo *pi = l2cap_pi(sk);
3281 u8 tx_seq = __get_txseq(rx_control); 3316 u8 tx_seq = __get_txseq(rx_control);
3317 u8 req_seq = __get_reqseq(rx_control);
3282 u16 tx_control = 0; 3318 u16 tx_control = 0;
3283 u8 sar = rx_control >> L2CAP_CTRL_SAR_SHIFT; 3319 u8 sar = rx_control >> L2CAP_CTRL_SAR_SHIFT;
3284 int err = 0; 3320 int err = 0;
3285 3321
3286 BT_DBG("sk %p rx_control 0x%4.4x len %d", sk, rx_control, skb->len); 3322 BT_DBG("sk %p rx_control 0x%4.4x len %d", sk, rx_control, skb->len);
3287 3323
3324 pi->expected_ack_seq = req_seq;
3325 l2cap_drop_acked_frames(sk);
3326
3288 if (tx_seq == pi->expected_tx_seq) 3327 if (tx_seq == pi->expected_tx_seq)
3289 goto expected; 3328 goto expected;
3290 3329
@@ -3339,6 +3378,16 @@ expected:
3339 return 0; 3378 return 0;
3340 } 3379 }
3341 3380
3381 if (rx_control & L2CAP_CTRL_FINAL) {
3382 if (pi->conn_state & L2CAP_CONN_REJ_ACT)
3383 pi->conn_state &= ~L2CAP_CONN_REJ_ACT;
3384 else {
3385 sk->sk_send_head = TX_QUEUE(sk)->next;
3386 pi->next_tx_seq = pi->expected_ack_seq;
3387 l2cap_ertm_send(sk);
3388 }
3389 }
3390
3342 pi->buffer_seq = (pi->buffer_seq + 1) % 64; 3391 pi->buffer_seq = (pi->buffer_seq + 1) % 64;
3343 3392
3344 err = l2cap_sar_reassembly_sdu(sk, skb, rx_control); 3393 err = l2cap_sar_reassembly_sdu(sk, skb, rx_control);
@@ -3375,6 +3424,14 @@ static inline int l2cap_data_channel_sframe(struct sock *sk, u16 rx_control, str
3375 pi->expected_ack_seq = tx_seq; 3424 pi->expected_ack_seq = tx_seq;
3376 l2cap_drop_acked_frames(sk); 3425 l2cap_drop_acked_frames(sk);
3377 3426
3427 if (pi->conn_state & L2CAP_CONN_REJ_ACT)
3428 pi->conn_state &= ~L2CAP_CONN_REJ_ACT;
3429 else {
3430 sk->sk_send_head = TX_QUEUE(sk)->next;
3431 pi->next_tx_seq = pi->expected_ack_seq;
3432 l2cap_ertm_send(sk);
3433 }
3434
3378 if (!(pi->conn_state & L2CAP_CONN_WAIT_F)) 3435 if (!(pi->conn_state & L2CAP_CONN_WAIT_F))
3379 break; 3436 break;
3380 3437
@@ -3387,12 +3444,12 @@ static inline int l2cap_data_channel_sframe(struct sock *sk, u16 rx_control, str
3387 pi->expected_ack_seq = tx_seq; 3444 pi->expected_ack_seq = tx_seq;
3388 l2cap_drop_acked_frames(sk); 3445 l2cap_drop_acked_frames(sk);
3389 3446
3390 if ((pi->conn_state & L2CAP_CONN_REMOTE_BUSY) 3447 if ((pi->conn_state & L2CAP_CONN_REMOTE_BUSY) &&
3391 && (pi->unacked_frames > 0)) 3448 (pi->unacked_frames > 0))
3392 __mod_retrans_timer(); 3449 __mod_retrans_timer();
3393 3450
3394 l2cap_ertm_send(sk);
3395 pi->conn_state &= ~L2CAP_CONN_REMOTE_BUSY; 3451 pi->conn_state &= ~L2CAP_CONN_REMOTE_BUSY;
3452 l2cap_ertm_send(sk);
3396 } 3453 }
3397 break; 3454 break;
3398 3455
@@ -3402,10 +3459,24 @@ static inline int l2cap_data_channel_sframe(struct sock *sk, u16 rx_control, str
3402 pi->expected_ack_seq = __get_reqseq(rx_control); 3459 pi->expected_ack_seq = __get_reqseq(rx_control);
3403 l2cap_drop_acked_frames(sk); 3460 l2cap_drop_acked_frames(sk);
3404 3461
3405 sk->sk_send_head = TX_QUEUE(sk)->next; 3462 if (rx_control & L2CAP_CTRL_FINAL) {
3406 pi->next_tx_seq = pi->expected_ack_seq; 3463 if (pi->conn_state & L2CAP_CONN_REJ_ACT)
3464 pi->conn_state &= ~L2CAP_CONN_REJ_ACT;
3465 else {
3466 sk->sk_send_head = TX_QUEUE(sk)->next;
3467 pi->next_tx_seq = pi->expected_ack_seq;
3468 l2cap_ertm_send(sk);
3469 }
3470 } else {
3471 sk->sk_send_head = TX_QUEUE(sk)->next;
3472 pi->next_tx_seq = pi->expected_ack_seq;
3473 l2cap_ertm_send(sk);
3407 3474
3408 l2cap_ertm_send(sk); 3475 if (pi->conn_state & L2CAP_CONN_WAIT_F) {
3476 pi->srej_save_reqseq = tx_seq;
3477 pi->conn_state |= L2CAP_CONN_REJ_ACT;
3478 }
3479 }
3409 3480
3410 break; 3481 break;
3411 3482
@@ -3413,9 +3484,9 @@ static inline int l2cap_data_channel_sframe(struct sock *sk, u16 rx_control, str
3413 pi->conn_state &= ~L2CAP_CONN_REMOTE_BUSY; 3484 pi->conn_state &= ~L2CAP_CONN_REMOTE_BUSY;
3414 3485
3415 if (rx_control & L2CAP_CTRL_POLL) { 3486 if (rx_control & L2CAP_CTRL_POLL) {
3416 l2cap_retransmit_frame(sk, tx_seq);
3417 pi->expected_ack_seq = tx_seq; 3487 pi->expected_ack_seq = tx_seq;
3418 l2cap_drop_acked_frames(sk); 3488 l2cap_drop_acked_frames(sk);
3489 l2cap_retransmit_frame(sk, tx_seq);
3419 l2cap_ertm_send(sk); 3490 l2cap_ertm_send(sk);
3420 if (pi->conn_state & L2CAP_CONN_WAIT_F) { 3491 if (pi->conn_state & L2CAP_CONN_WAIT_F) {
3421 pi->srej_save_reqseq = tx_seq; 3492 pi->srej_save_reqseq = tx_seq;
@@ -3424,7 +3495,7 @@ static inline int l2cap_data_channel_sframe(struct sock *sk, u16 rx_control, str
3424 } else if (rx_control & L2CAP_CTRL_FINAL) { 3495 } else if (rx_control & L2CAP_CTRL_FINAL) {
3425 if ((pi->conn_state & L2CAP_CONN_SREJ_ACT) && 3496 if ((pi->conn_state & L2CAP_CONN_SREJ_ACT) &&
3426 pi->srej_save_reqseq == tx_seq) 3497 pi->srej_save_reqseq == tx_seq)
3427 pi->srej_save_reqseq &= ~L2CAP_CONN_SREJ_ACT; 3498 pi->conn_state &= ~L2CAP_CONN_SREJ_ACT;
3428 else 3499 else
3429 l2cap_retransmit_frame(sk, tx_seq); 3500 l2cap_retransmit_frame(sk, tx_seq);
3430 } 3501 }
@@ -3459,7 +3530,6 @@ static inline int l2cap_data_channel(struct l2cap_conn *conn, u16 cid, struct sk
3459 struct l2cap_pinfo *pi; 3530 struct l2cap_pinfo *pi;
3460 u16 control, len; 3531 u16 control, len;
3461 u8 tx_seq; 3532 u8 tx_seq;
3462 int err;
3463 3533
3464 sk = l2cap_get_chan_by_scid(&conn->chan_list, cid); 3534 sk = l2cap_get_chan_by_scid(&conn->chan_list, cid);
3465 if (!sk) { 3535 if (!sk) {
@@ -3511,13 +3581,11 @@ static inline int l2cap_data_channel(struct l2cap_conn *conn, u16 cid, struct sk
3511 goto drop; 3581 goto drop;
3512 3582
3513 if (__is_iframe(control)) 3583 if (__is_iframe(control))
3514 err = l2cap_data_channel_iframe(sk, control, skb); 3584 l2cap_data_channel_iframe(sk, control, skb);
3515 else 3585 else
3516 err = l2cap_data_channel_sframe(sk, control, skb); 3586 l2cap_data_channel_sframe(sk, control, skb);
3517 3587
3518 if (!err) 3588 goto done;
3519 goto done;
3520 break;
3521 3589
3522 case L2CAP_MODE_STREAMING: 3590 case L2CAP_MODE_STREAMING:
3523 control = get_unaligned_le16(skb->data); 3591 control = get_unaligned_le16(skb->data);
@@ -3543,7 +3611,7 @@ static inline int l2cap_data_channel(struct l2cap_conn *conn, u16 cid, struct sk
3543 else 3611 else
3544 pi->expected_tx_seq = tx_seq + 1; 3612 pi->expected_tx_seq = tx_seq + 1;
3545 3613
3546 err = l2cap_sar_reassembly_sdu(sk, skb, control); 3614 l2cap_sar_reassembly_sdu(sk, skb, control);
3547 3615
3548 goto done; 3616 goto done;
3549 3617
@@ -3880,29 +3948,42 @@ drop:
3880 return 0; 3948 return 0;
3881} 3949}
3882 3950
3883static ssize_t l2cap_sysfs_show(struct class *dev, char *buf) 3951static int l2cap_debugfs_show(struct seq_file *f, void *p)
3884{ 3952{
3885 struct sock *sk; 3953 struct sock *sk;
3886 struct hlist_node *node; 3954 struct hlist_node *node;
3887 char *str = buf;
3888 3955
3889 read_lock_bh(&l2cap_sk_list.lock); 3956 read_lock_bh(&l2cap_sk_list.lock);
3890 3957
3891 sk_for_each(sk, node, &l2cap_sk_list.head) { 3958 sk_for_each(sk, node, &l2cap_sk_list.head) {
3892 struct l2cap_pinfo *pi = l2cap_pi(sk); 3959 struct l2cap_pinfo *pi = l2cap_pi(sk);
3893 3960
3894 str += sprintf(str, "%s %s %d %d 0x%4.4x 0x%4.4x %d %d %d\n", 3961 seq_printf(f, "%s %s %d %d 0x%4.4x 0x%4.4x %d %d %d\n",
3895 batostr(&bt_sk(sk)->src), batostr(&bt_sk(sk)->dst), 3962 batostr(&bt_sk(sk)->src),
3896 sk->sk_state, __le16_to_cpu(pi->psm), pi->scid, 3963 batostr(&bt_sk(sk)->dst),
3897 pi->dcid, pi->imtu, pi->omtu, pi->sec_level); 3964 sk->sk_state, __le16_to_cpu(pi->psm),
3965 pi->scid, pi->dcid,
3966 pi->imtu, pi->omtu, pi->sec_level);
3898 } 3967 }
3899 3968
3900 read_unlock_bh(&l2cap_sk_list.lock); 3969 read_unlock_bh(&l2cap_sk_list.lock);
3901 3970
3902 return str - buf; 3971 return 0;
3972}
3973
3974static int l2cap_debugfs_open(struct inode *inode, struct file *file)
3975{
3976 return single_open(file, l2cap_debugfs_show, inode->i_private);
3903} 3977}
3904 3978
3905static CLASS_ATTR(l2cap, S_IRUGO, l2cap_sysfs_show, NULL); 3979static const struct file_operations l2cap_debugfs_fops = {
3980 .open = l2cap_debugfs_open,
3981 .read = seq_read,
3982 .llseek = seq_lseek,
3983 .release = single_release,
3984};
3985
3986static struct dentry *l2cap_debugfs;
3906 3987
3907static const struct proto_ops l2cap_sock_ops = { 3988static const struct proto_ops l2cap_sock_ops = {
3908 .family = PF_BLUETOOTH, 3989 .family = PF_BLUETOOTH,
@@ -3924,7 +4005,7 @@ static const struct proto_ops l2cap_sock_ops = {
3924 .getsockopt = l2cap_sock_getsockopt 4005 .getsockopt = l2cap_sock_getsockopt
3925}; 4006};
3926 4007
3927static struct net_proto_family l2cap_sock_family_ops = { 4008static const struct net_proto_family l2cap_sock_family_ops = {
3928 .family = PF_BLUETOOTH, 4009 .family = PF_BLUETOOTH,
3929 .owner = THIS_MODULE, 4010 .owner = THIS_MODULE,
3930 .create = l2cap_sock_create, 4011 .create = l2cap_sock_create,
@@ -3962,8 +4043,12 @@ static int __init l2cap_init(void)
3962 goto error; 4043 goto error;
3963 } 4044 }
3964 4045
3965 if (class_create_file(bt_class, &class_attr_l2cap) < 0) 4046 if (bt_debugfs) {
3966 BT_ERR("Failed to create L2CAP info file"); 4047 l2cap_debugfs = debugfs_create_file("l2cap", 0444,
4048 bt_debugfs, NULL, &l2cap_debugfs_fops);
4049 if (!l2cap_debugfs)
4050 BT_ERR("Failed to create L2CAP debug file");
4051 }
3967 4052
3968 BT_INFO("L2CAP ver %s", VERSION); 4053 BT_INFO("L2CAP ver %s", VERSION);
3969 BT_INFO("L2CAP socket layer initialized"); 4054 BT_INFO("L2CAP socket layer initialized");
@@ -3977,7 +4062,7 @@ error:
3977 4062
3978static void __exit l2cap_exit(void) 4063static void __exit l2cap_exit(void)
3979{ 4064{
3980 class_remove_file(bt_class, &class_attr_l2cap); 4065 debugfs_remove(l2cap_debugfs);
3981 4066
3982 if (bt_sock_unregister(BTPROTO_L2CAP) < 0) 4067 if (bt_sock_unregister(BTPROTO_L2CAP) < 0)
3983 BT_ERR("L2CAP socket unregistration failed"); 4068 BT_ERR("L2CAP socket unregistration failed");
@@ -4003,6 +4088,9 @@ module_exit(l2cap_exit);
4003module_param(enable_ertm, bool, 0644); 4088module_param(enable_ertm, bool, 0644);
4004MODULE_PARM_DESC(enable_ertm, "Enable enhanced retransmission mode"); 4089MODULE_PARM_DESC(enable_ertm, "Enable enhanced retransmission mode");
4005 4090
4091module_param(max_transmit, uint, 0644);
4092MODULE_PARM_DESC(max_transmit, "Max transmit value (default = 3)");
4093
4006MODULE_AUTHOR("Marcel Holtmann <marcel@holtmann.org>"); 4094MODULE_AUTHOR("Marcel Holtmann <marcel@holtmann.org>");
4007MODULE_DESCRIPTION("Bluetooth L2CAP ver " VERSION); 4095MODULE_DESCRIPTION("Bluetooth L2CAP ver " VERSION);
4008MODULE_VERSION(VERSION); 4096MODULE_VERSION(VERSION);
diff --git a/net/bluetooth/rfcomm/core.c b/net/bluetooth/rfcomm/core.c
index 25692bc0a342..7dca91bb8c57 100644
--- a/net/bluetooth/rfcomm/core.c
+++ b/net/bluetooth/rfcomm/core.c
@@ -33,9 +33,12 @@
33#include <linux/init.h> 33#include <linux/init.h>
34#include <linux/wait.h> 34#include <linux/wait.h>
35#include <linux/device.h> 35#include <linux/device.h>
36#include <linux/debugfs.h>
37#include <linux/seq_file.h>
36#include <linux/net.h> 38#include <linux/net.h>
37#include <linux/mutex.h> 39#include <linux/mutex.h>
38#include <linux/kthread.h> 40#include <linux/kthread.h>
41#include <linux/slab.h>
39 42
40#include <net/sock.h> 43#include <net/sock.h>
41#include <asm/uaccess.h> 44#include <asm/uaccess.h>
@@ -51,6 +54,7 @@
51static int disable_cfc = 0; 54static int disable_cfc = 0;
52static int channel_mtu = -1; 55static int channel_mtu = -1;
53static unsigned int l2cap_mtu = RFCOMM_MAX_L2CAP_MTU; 56static unsigned int l2cap_mtu = RFCOMM_MAX_L2CAP_MTU;
57static int l2cap_ertm = 0;
54 58
55static struct task_struct *rfcomm_thread; 59static struct task_struct *rfcomm_thread;
56 60
@@ -251,7 +255,6 @@ static void rfcomm_session_timeout(unsigned long arg)
251 BT_DBG("session %p state %ld", s, s->state); 255 BT_DBG("session %p state %ld", s, s->state);
252 256
253 set_bit(RFCOMM_TIMED_OUT, &s->flags); 257 set_bit(RFCOMM_TIMED_OUT, &s->flags);
254 rfcomm_session_put(s);
255 rfcomm_schedule(RFCOMM_SCHED_TIMEO); 258 rfcomm_schedule(RFCOMM_SCHED_TIMEO);
256} 259}
257 260
@@ -702,6 +705,8 @@ static struct rfcomm_session *rfcomm_session_create(bdaddr_t *src, bdaddr_t *dst
702 sk = sock->sk; 705 sk = sock->sk;
703 lock_sock(sk); 706 lock_sock(sk);
704 l2cap_pi(sk)->imtu = l2cap_mtu; 707 l2cap_pi(sk)->imtu = l2cap_mtu;
708 if (l2cap_ertm)
709 l2cap_pi(sk)->mode = L2CAP_MODE_ERTM;
705 release_sock(sk); 710 release_sock(sk);
706 711
707 s = rfcomm_session_add(sock, BT_BOUND); 712 s = rfcomm_session_add(sock, BT_BOUND);
@@ -1148,7 +1153,11 @@ static int rfcomm_recv_ua(struct rfcomm_session *s, u8 dlci)
1148 break; 1153 break;
1149 1154
1150 case BT_DISCONN: 1155 case BT_DISCONN:
1151 rfcomm_session_put(s); 1156 /* When socket is closed and we are not RFCOMM
1157 * initiator rfcomm_process_rx already calls
1158 * rfcomm_session_put() */
1159 if (s->sock->sk->sk_state != BT_CLOSED)
1160 rfcomm_session_put(s);
1152 break; 1161 break;
1153 } 1162 }
1154 } 1163 }
@@ -1917,6 +1926,7 @@ static inline void rfcomm_process_sessions(void)
1917 if (test_and_clear_bit(RFCOMM_TIMED_OUT, &s->flags)) { 1926 if (test_and_clear_bit(RFCOMM_TIMED_OUT, &s->flags)) {
1918 s->state = BT_DISCONN; 1927 s->state = BT_DISCONN;
1919 rfcomm_send_disc(s, 0); 1928 rfcomm_send_disc(s, 0);
1929 rfcomm_session_put(s);
1920 continue; 1930 continue;
1921 } 1931 }
1922 1932
@@ -2091,11 +2101,10 @@ static struct hci_cb rfcomm_cb = {
2091 .security_cfm = rfcomm_security_cfm 2101 .security_cfm = rfcomm_security_cfm
2092}; 2102};
2093 2103
2094static ssize_t rfcomm_dlc_sysfs_show(struct class *dev, char *buf) 2104static int rfcomm_dlc_debugfs_show(struct seq_file *f, void *x)
2095{ 2105{
2096 struct rfcomm_session *s; 2106 struct rfcomm_session *s;
2097 struct list_head *pp, *p; 2107 struct list_head *pp, *p;
2098 char *str = buf;
2099 2108
2100 rfcomm_lock(); 2109 rfcomm_lock();
2101 2110
@@ -2105,18 +2114,32 @@ static ssize_t rfcomm_dlc_sysfs_show(struct class *dev, char *buf)
2105 struct sock *sk = s->sock->sk; 2114 struct sock *sk = s->sock->sk;
2106 struct rfcomm_dlc *d = list_entry(pp, struct rfcomm_dlc, list); 2115 struct rfcomm_dlc *d = list_entry(pp, struct rfcomm_dlc, list);
2107 2116
2108 str += sprintf(str, "%s %s %ld %d %d %d %d\n", 2117 seq_printf(f, "%s %s %ld %d %d %d %d\n",
2109 batostr(&bt_sk(sk)->src), batostr(&bt_sk(sk)->dst), 2118 batostr(&bt_sk(sk)->src),
2110 d->state, d->dlci, d->mtu, d->rx_credits, d->tx_credits); 2119 batostr(&bt_sk(sk)->dst),
2120 d->state, d->dlci, d->mtu,
2121 d->rx_credits, d->tx_credits);
2111 } 2122 }
2112 } 2123 }
2113 2124
2114 rfcomm_unlock(); 2125 rfcomm_unlock();
2115 2126
2116 return (str - buf); 2127 return 0;
2117} 2128}
2118 2129
2119static CLASS_ATTR(rfcomm_dlc, S_IRUGO, rfcomm_dlc_sysfs_show, NULL); 2130static int rfcomm_dlc_debugfs_open(struct inode *inode, struct file *file)
2131{
2132 return single_open(file, rfcomm_dlc_debugfs_show, inode->i_private);
2133}
2134
2135static const struct file_operations rfcomm_dlc_debugfs_fops = {
2136 .open = rfcomm_dlc_debugfs_open,
2137 .read = seq_read,
2138 .llseek = seq_lseek,
2139 .release = single_release,
2140};
2141
2142static struct dentry *rfcomm_dlc_debugfs;
2120 2143
2121/* ---- Initialization ---- */ 2144/* ---- Initialization ---- */
2122static int __init rfcomm_init(void) 2145static int __init rfcomm_init(void)
@@ -2133,8 +2156,12 @@ static int __init rfcomm_init(void)
2133 goto unregister; 2156 goto unregister;
2134 } 2157 }
2135 2158
2136 if (class_create_file(bt_class, &class_attr_rfcomm_dlc) < 0) 2159 if (bt_debugfs) {
2137 BT_ERR("Failed to create RFCOMM info file"); 2160 rfcomm_dlc_debugfs = debugfs_create_file("rfcomm_dlc", 0444,
2161 bt_debugfs, NULL, &rfcomm_dlc_debugfs_fops);
2162 if (!rfcomm_dlc_debugfs)
2163 BT_ERR("Failed to create RFCOMM debug file");
2164 }
2138 2165
2139 err = rfcomm_init_ttys(); 2166 err = rfcomm_init_ttys();
2140 if (err < 0) 2167 if (err < 0)
@@ -2162,7 +2189,7 @@ unregister:
2162 2189
2163static void __exit rfcomm_exit(void) 2190static void __exit rfcomm_exit(void)
2164{ 2191{
2165 class_remove_file(bt_class, &class_attr_rfcomm_dlc); 2192 debugfs_remove(rfcomm_dlc_debugfs);
2166 2193
2167 hci_unregister_cb(&rfcomm_cb); 2194 hci_unregister_cb(&rfcomm_cb);
2168 2195
@@ -2185,6 +2212,9 @@ MODULE_PARM_DESC(channel_mtu, "Default MTU for the RFCOMM channel");
2185module_param(l2cap_mtu, uint, 0644); 2212module_param(l2cap_mtu, uint, 0644);
2186MODULE_PARM_DESC(l2cap_mtu, "Default MTU for the L2CAP connection"); 2213MODULE_PARM_DESC(l2cap_mtu, "Default MTU for the L2CAP connection");
2187 2214
2215module_param(l2cap_ertm, bool, 0644);
2216MODULE_PARM_DESC(l2cap_ertm, "Use L2CAP ERTM mode for connection");
2217
2188MODULE_AUTHOR("Marcel Holtmann <marcel@holtmann.org>"); 2218MODULE_AUTHOR("Marcel Holtmann <marcel@holtmann.org>");
2189MODULE_DESCRIPTION("Bluetooth RFCOMM ver " VERSION); 2219MODULE_DESCRIPTION("Bluetooth RFCOMM ver " VERSION);
2190MODULE_VERSION(VERSION); 2220MODULE_VERSION(VERSION);
diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
index 8a20aaf1f231..8ed3c37684fa 100644
--- a/net/bluetooth/rfcomm/sock.c
+++ b/net/bluetooth/rfcomm/sock.c
@@ -40,6 +40,8 @@
40#include <linux/skbuff.h> 40#include <linux/skbuff.h>
41#include <linux/list.h> 41#include <linux/list.h>
42#include <linux/device.h> 42#include <linux/device.h>
43#include <linux/debugfs.h>
44#include <linux/seq_file.h>
43#include <net/sock.h> 45#include <net/sock.h>
44 46
45#include <asm/system.h> 47#include <asm/system.h>
@@ -323,7 +325,8 @@ static struct sock *rfcomm_sock_alloc(struct net *net, struct socket *sock, int
323 return sk; 325 return sk;
324} 326}
325 327
326static int rfcomm_sock_create(struct net *net, struct socket *sock, int protocol) 328static int rfcomm_sock_create(struct net *net, struct socket *sock,
329 int protocol, int kern)
327{ 330{
328 struct sock *sk; 331 struct sock *sk;
329 332
@@ -394,7 +397,8 @@ static int rfcomm_sock_connect(struct socket *sock, struct sockaddr *addr, int a
394 397
395 BT_DBG("sk %p", sk); 398 BT_DBG("sk %p", sk);
396 399
397 if (addr->sa_family != AF_BLUETOOTH || alen < sizeof(struct sockaddr_rc)) 400 if (alen < sizeof(struct sockaddr_rc) ||
401 addr->sa_family != AF_BLUETOOTH)
398 return -EINVAL; 402 return -EINVAL;
399 403
400 lock_sock(sk); 404 lock_sock(sk);
@@ -703,7 +707,7 @@ static int rfcomm_sock_recvmsg(struct kiocb *iocb, struct socket *sock,
703 copied += chunk; 707 copied += chunk;
704 size -= chunk; 708 size -= chunk;
705 709
706 sock_recv_timestamp(msg, sk, skb); 710 sock_recv_ts_and_drops(msg, sk, skb);
707 711
708 if (!(flags & MSG_PEEK)) { 712 if (!(flags & MSG_PEEK)) {
709 atomic_sub(chunk, &sk->sk_rmem_alloc); 713 atomic_sub(chunk, &sk->sk_rmem_alloc);
@@ -1060,26 +1064,38 @@ done:
1060 return result; 1064 return result;
1061} 1065}
1062 1066
1063static ssize_t rfcomm_sock_sysfs_show(struct class *dev, char *buf) 1067static int rfcomm_sock_debugfs_show(struct seq_file *f, void *p)
1064{ 1068{
1065 struct sock *sk; 1069 struct sock *sk;
1066 struct hlist_node *node; 1070 struct hlist_node *node;
1067 char *str = buf;
1068 1071
1069 read_lock_bh(&rfcomm_sk_list.lock); 1072 read_lock_bh(&rfcomm_sk_list.lock);
1070 1073
1071 sk_for_each(sk, node, &rfcomm_sk_list.head) { 1074 sk_for_each(sk, node, &rfcomm_sk_list.head) {
1072 str += sprintf(str, "%s %s %d %d\n", 1075 seq_printf(f, "%s %s %d %d\n",
1073 batostr(&bt_sk(sk)->src), batostr(&bt_sk(sk)->dst), 1076 batostr(&bt_sk(sk)->src),
1077 batostr(&bt_sk(sk)->dst),
1074 sk->sk_state, rfcomm_pi(sk)->channel); 1078 sk->sk_state, rfcomm_pi(sk)->channel);
1075 } 1079 }
1076 1080
1077 read_unlock_bh(&rfcomm_sk_list.lock); 1081 read_unlock_bh(&rfcomm_sk_list.lock);
1078 1082
1079 return (str - buf); 1083 return 0;
1080} 1084}
1081 1085
1082static CLASS_ATTR(rfcomm, S_IRUGO, rfcomm_sock_sysfs_show, NULL); 1086static int rfcomm_sock_debugfs_open(struct inode *inode, struct file *file)
1087{
1088 return single_open(file, rfcomm_sock_debugfs_show, inode->i_private);
1089}
1090
1091static const struct file_operations rfcomm_sock_debugfs_fops = {
1092 .open = rfcomm_sock_debugfs_open,
1093 .read = seq_read,
1094 .llseek = seq_lseek,
1095 .release = single_release,
1096};
1097
1098static struct dentry *rfcomm_sock_debugfs;
1083 1099
1084static const struct proto_ops rfcomm_sock_ops = { 1100static const struct proto_ops rfcomm_sock_ops = {
1085 .family = PF_BLUETOOTH, 1101 .family = PF_BLUETOOTH,
@@ -1101,7 +1117,7 @@ static const struct proto_ops rfcomm_sock_ops = {
1101 .mmap = sock_no_mmap 1117 .mmap = sock_no_mmap
1102}; 1118};
1103 1119
1104static struct net_proto_family rfcomm_sock_family_ops = { 1120static const struct net_proto_family rfcomm_sock_family_ops = {
1105 .family = PF_BLUETOOTH, 1121 .family = PF_BLUETOOTH,
1106 .owner = THIS_MODULE, 1122 .owner = THIS_MODULE,
1107 .create = rfcomm_sock_create 1123 .create = rfcomm_sock_create
@@ -1119,8 +1135,12 @@ int __init rfcomm_init_sockets(void)
1119 if (err < 0) 1135 if (err < 0)
1120 goto error; 1136 goto error;
1121 1137
1122 if (class_create_file(bt_class, &class_attr_rfcomm) < 0) 1138 if (bt_debugfs) {
1123 BT_ERR("Failed to create RFCOMM info file"); 1139 rfcomm_sock_debugfs = debugfs_create_file("rfcomm", 0444,
1140 bt_debugfs, NULL, &rfcomm_sock_debugfs_fops);
1141 if (!rfcomm_sock_debugfs)
1142 BT_ERR("Failed to create RFCOMM debug file");
1143 }
1124 1144
1125 BT_INFO("RFCOMM socket layer initialized"); 1145 BT_INFO("RFCOMM socket layer initialized");
1126 1146
@@ -1134,7 +1154,7 @@ error:
1134 1154
1135void rfcomm_cleanup_sockets(void) 1155void rfcomm_cleanup_sockets(void)
1136{ 1156{
1137 class_remove_file(bt_class, &class_attr_rfcomm); 1157 debugfs_remove(rfcomm_sock_debugfs);
1138 1158
1139 if (bt_sock_unregister(BTPROTO_RFCOMM) < 0) 1159 if (bt_sock_unregister(BTPROTO_RFCOMM) < 0)
1140 BT_ERR("RFCOMM socket layer unregistration failed"); 1160 BT_ERR("RFCOMM socket layer unregistration failed");
diff --git a/net/bluetooth/sco.c b/net/bluetooth/sco.c
index 77f4153bdb5e..ca6b2ad1c3fc 100644
--- a/net/bluetooth/sco.c
+++ b/net/bluetooth/sco.c
@@ -38,6 +38,8 @@
38#include <linux/socket.h> 38#include <linux/socket.h>
39#include <linux/skbuff.h> 39#include <linux/skbuff.h>
40#include <linux/device.h> 40#include <linux/device.h>
41#include <linux/debugfs.h>
42#include <linux/seq_file.h>
41#include <linux/list.h> 43#include <linux/list.h>
42#include <net/sock.h> 44#include <net/sock.h>
43 45
@@ -430,7 +432,8 @@ static struct sock *sco_sock_alloc(struct net *net, struct socket *sock, int pro
430 return sk; 432 return sk;
431} 433}
432 434
433static int sco_sock_create(struct net *net, struct socket *sock, int protocol) 435static int sco_sock_create(struct net *net, struct socket *sock, int protocol,
436 int kern)
434{ 437{
435 struct sock *sk; 438 struct sock *sk;
436 439
@@ -496,7 +499,8 @@ static int sco_sock_connect(struct socket *sock, struct sockaddr *addr, int alen
496 499
497 BT_DBG("sk %p", sk); 500 BT_DBG("sk %p", sk);
498 501
499 if (addr->sa_family != AF_BLUETOOTH || alen < sizeof(struct sockaddr_sco)) 502 if (alen < sizeof(struct sockaddr_sco) ||
503 addr->sa_family != AF_BLUETOOTH)
500 return -EINVAL; 504 return -EINVAL;
501 505
502 if (sk->sk_state != BT_OPEN && sk->sk_state != BT_BOUND) 506 if (sk->sk_state != BT_OPEN && sk->sk_state != BT_BOUND)
@@ -952,26 +956,36 @@ drop:
952 return 0; 956 return 0;
953} 957}
954 958
955static ssize_t sco_sysfs_show(struct class *dev, char *buf) 959static int sco_debugfs_show(struct seq_file *f, void *p)
956{ 960{
957 struct sock *sk; 961 struct sock *sk;
958 struct hlist_node *node; 962 struct hlist_node *node;
959 char *str = buf;
960 963
961 read_lock_bh(&sco_sk_list.lock); 964 read_lock_bh(&sco_sk_list.lock);
962 965
963 sk_for_each(sk, node, &sco_sk_list.head) { 966 sk_for_each(sk, node, &sco_sk_list.head) {
964 str += sprintf(str, "%s %s %d\n", 967 seq_printf(f, "%s %s %d\n", batostr(&bt_sk(sk)->src),
965 batostr(&bt_sk(sk)->src), batostr(&bt_sk(sk)->dst), 968 batostr(&bt_sk(sk)->dst), sk->sk_state);
966 sk->sk_state);
967 } 969 }
968 970
969 read_unlock_bh(&sco_sk_list.lock); 971 read_unlock_bh(&sco_sk_list.lock);
970 972
971 return (str - buf); 973 return 0;
972} 974}
973 975
974static CLASS_ATTR(sco, S_IRUGO, sco_sysfs_show, NULL); 976static int sco_debugfs_open(struct inode *inode, struct file *file)
977{
978 return single_open(file, sco_debugfs_show, inode->i_private);
979}
980
981static const struct file_operations sco_debugfs_fops = {
982 .open = sco_debugfs_open,
983 .read = seq_read,
984 .llseek = seq_lseek,
985 .release = single_release,
986};
987
988static struct dentry *sco_debugfs;
975 989
976static const struct proto_ops sco_sock_ops = { 990static const struct proto_ops sco_sock_ops = {
977 .family = PF_BLUETOOTH, 991 .family = PF_BLUETOOTH,
@@ -993,7 +1007,7 @@ static const struct proto_ops sco_sock_ops = {
993 .getsockopt = sco_sock_getsockopt 1007 .getsockopt = sco_sock_getsockopt
994}; 1008};
995 1009
996static struct net_proto_family sco_sock_family_ops = { 1010static const struct net_proto_family sco_sock_family_ops = {
997 .family = PF_BLUETOOTH, 1011 .family = PF_BLUETOOTH,
998 .owner = THIS_MODULE, 1012 .owner = THIS_MODULE,
999 .create = sco_sock_create, 1013 .create = sco_sock_create,
@@ -1029,8 +1043,12 @@ static int __init sco_init(void)
1029 goto error; 1043 goto error;
1030 } 1044 }
1031 1045
1032 if (class_create_file(bt_class, &class_attr_sco) < 0) 1046 if (bt_debugfs) {
1033 BT_ERR("Failed to create SCO info file"); 1047 sco_debugfs = debugfs_create_file("sco", 0444,
1048 bt_debugfs, NULL, &sco_debugfs_fops);
1049 if (!sco_debugfs)
1050 BT_ERR("Failed to create SCO debug file");
1051 }
1034 1052
1035 BT_INFO("SCO (Voice Link) ver %s", VERSION); 1053 BT_INFO("SCO (Voice Link) ver %s", VERSION);
1036 BT_INFO("SCO socket layer initialized"); 1054 BT_INFO("SCO socket layer initialized");
@@ -1044,7 +1062,7 @@ error:
1044 1062
1045static void __exit sco_exit(void) 1063static void __exit sco_exit(void)
1046{ 1064{
1047 class_remove_file(bt_class, &class_attr_sco); 1065 debugfs_remove(sco_debugfs);
1048 1066
1049 if (bt_sock_unregister(BTPROTO_SCO) < 0) 1067 if (bt_sock_unregister(BTPROTO_SCO) < 0)
1050 BT_ERR("SCO socket unregistration failed"); 1068 BT_ERR("SCO socket unregistration failed");
diff --git a/net/bridge/Kconfig b/net/bridge/Kconfig
index e143ca678881..d115d5cea5b6 100644
--- a/net/bridge/Kconfig
+++ b/net/bridge/Kconfig
@@ -31,3 +31,17 @@ config BRIDGE
31 will be called bridge. 31 will be called bridge.
32 32
33 If unsure, say N. 33 If unsure, say N.
34
35config BRIDGE_IGMP_SNOOPING
36 bool "IGMP snooping"
37 depends on BRIDGE
38 depends on INET
39 default y
40 ---help---
41 If you say Y here, then the Ethernet bridge will be able selectively
42 forward multicast traffic based on IGMP traffic received from each
43 port.
44
45 Say N to exclude this support and reduce the binary size.
46
47 If unsure, say Y.
diff --git a/net/bridge/Makefile b/net/bridge/Makefile
index f444c12cde5a..d0359ea8ee79 100644
--- a/net/bridge/Makefile
+++ b/net/bridge/Makefile
@@ -12,4 +12,6 @@ bridge-$(CONFIG_SYSFS) += br_sysfs_if.o br_sysfs_br.o
12 12
13bridge-$(CONFIG_BRIDGE_NETFILTER) += br_netfilter.o 13bridge-$(CONFIG_BRIDGE_NETFILTER) += br_netfilter.o
14 14
15bridge-$(CONFIG_BRIDGE_IGMP_SNOOPING) += br_multicast.o
16
15obj-$(CONFIG_BRIDGE_NF_EBTABLES) += netfilter/ 17obj-$(CONFIG_BRIDGE_NF_EBTABLES) += netfilter/
diff --git a/net/bridge/br_device.c b/net/bridge/br_device.c
index 07a07770c8b6..90a9024e5c1e 100644
--- a/net/bridge/br_device.c
+++ b/net/bridge/br_device.c
@@ -25,6 +25,9 @@ netdev_tx_t br_dev_xmit(struct sk_buff *skb, struct net_device *dev)
25 struct net_bridge *br = netdev_priv(dev); 25 struct net_bridge *br = netdev_priv(dev);
26 const unsigned char *dest = skb->data; 26 const unsigned char *dest = skb->data;
27 struct net_bridge_fdb_entry *dst; 27 struct net_bridge_fdb_entry *dst;
28 struct net_bridge_mdb_entry *mdst;
29
30 BR_INPUT_SKB_CB(skb)->brdev = dev;
28 31
29 dev->stats.tx_packets++; 32 dev->stats.tx_packets++;
30 dev->stats.tx_bytes += skb->len; 33 dev->stats.tx_bytes += skb->len;
@@ -32,13 +35,21 @@ netdev_tx_t br_dev_xmit(struct sk_buff *skb, struct net_device *dev)
32 skb_reset_mac_header(skb); 35 skb_reset_mac_header(skb);
33 skb_pull(skb, ETH_HLEN); 36 skb_pull(skb, ETH_HLEN);
34 37
35 if (dest[0] & 1) 38 if (dest[0] & 1) {
36 br_flood_deliver(br, skb); 39 if (br_multicast_rcv(br, NULL, skb))
37 else if ((dst = __br_fdb_get(br, dest)) != NULL) 40 goto out;
41
42 mdst = br_mdb_get(br, skb);
43 if (mdst || BR_INPUT_SKB_CB_MROUTERS_ONLY(skb))
44 br_multicast_deliver(mdst, skb);
45 else
46 br_flood_deliver(br, skb);
47 } else if ((dst = __br_fdb_get(br, dest)) != NULL)
38 br_deliver(dst->dst, skb); 48 br_deliver(dst->dst, skb);
39 else 49 else
40 br_flood_deliver(br, skb); 50 br_flood_deliver(br, skb);
41 51
52out:
42 return NETDEV_TX_OK; 53 return NETDEV_TX_OK;
43} 54}
44 55
@@ -49,6 +60,7 @@ static int br_dev_open(struct net_device *dev)
49 br_features_recompute(br); 60 br_features_recompute(br);
50 netif_start_queue(dev); 61 netif_start_queue(dev);
51 br_stp_enable_bridge(br); 62 br_stp_enable_bridge(br);
63 br_multicast_open(br);
52 64
53 return 0; 65 return 0;
54} 66}
@@ -59,7 +71,10 @@ static void br_dev_set_multicast_list(struct net_device *dev)
59 71
60static int br_dev_stop(struct net_device *dev) 72static int br_dev_stop(struct net_device *dev)
61{ 73{
62 br_stp_disable_bridge(netdev_priv(dev)); 74 struct net_bridge *br = netdev_priv(dev);
75
76 br_stp_disable_bridge(br);
77 br_multicast_stop(br);
63 78
64 netif_stop_queue(dev); 79 netif_stop_queue(dev);
65 80
@@ -157,6 +172,7 @@ static const struct ethtool_ops br_ethtool_ops = {
157 .get_tso = ethtool_op_get_tso, 172 .get_tso = ethtool_op_get_tso,
158 .set_tso = br_set_tso, 173 .set_tso = br_set_tso,
159 .get_ufo = ethtool_op_get_ufo, 174 .get_ufo = ethtool_op_get_ufo,
175 .set_ufo = ethtool_op_set_ufo,
160 .get_flags = ethtool_op_get_flags, 176 .get_flags = ethtool_op_get_flags,
161}; 177};
162 178
diff --git a/net/bridge/br_fdb.c b/net/bridge/br_fdb.c
index 57bf05c353bc..9101a4e56201 100644
--- a/net/bridge/br_fdb.c
+++ b/net/bridge/br_fdb.c
@@ -20,6 +20,7 @@
20#include <linux/etherdevice.h> 20#include <linux/etherdevice.h>
21#include <linux/jhash.h> 21#include <linux/jhash.h>
22#include <linux/random.h> 22#include <linux/random.h>
23#include <linux/slab.h>
23#include <asm/atomic.h> 24#include <asm/atomic.h>
24#include <asm/unaligned.h> 25#include <asm/unaligned.h>
25#include "br_private.h" 26#include "br_private.h"
@@ -60,8 +61,8 @@ static inline unsigned long hold_time(const struct net_bridge *br)
60static inline int has_expired(const struct net_bridge *br, 61static inline int has_expired(const struct net_bridge *br,
61 const struct net_bridge_fdb_entry *fdb) 62 const struct net_bridge_fdb_entry *fdb)
62{ 63{
63 return !fdb->is_static 64 return !fdb->is_static &&
64 && time_before_eq(fdb->ageing_timer + hold_time(br), jiffies); 65 time_before_eq(fdb->ageing_timer + hold_time(br), jiffies);
65} 66}
66 67
67static inline int br_mac_hash(const unsigned char *mac) 68static inline int br_mac_hash(const unsigned char *mac)
diff --git a/net/bridge/br_forward.c b/net/bridge/br_forward.c
index bc1704ac6cd9..7a241c396981 100644
--- a/net/bridge/br_forward.c
+++ b/net/bridge/br_forward.c
@@ -11,6 +11,8 @@
11 * 2 of the License, or (at your option) any later version. 11 * 2 of the License, or (at your option) any later version.
12 */ 12 */
13 13
14#include <linux/err.h>
15#include <linux/slab.h>
14#include <linux/kernel.h> 16#include <linux/kernel.h>
15#include <linux/netdevice.h> 17#include <linux/netdevice.h>
16#include <linux/skbuff.h> 18#include <linux/skbuff.h>
@@ -18,6 +20,11 @@
18#include <linux/netfilter_bridge.h> 20#include <linux/netfilter_bridge.h>
19#include "br_private.h" 21#include "br_private.h"
20 22
23static int deliver_clone(const struct net_bridge_port *prev,
24 struct sk_buff *skb,
25 void (*__packet_hook)(const struct net_bridge_port *p,
26 struct sk_buff *skb));
27
21/* Don't forward packets to originating port or forwarding diasabled */ 28/* Don't forward packets to originating port or forwarding diasabled */
22static inline int should_deliver(const struct net_bridge_port *p, 29static inline int should_deliver(const struct net_bridge_port *p,
23 const struct sk_buff *skb) 30 const struct sk_buff *skb)
@@ -93,61 +100,167 @@ void br_deliver(const struct net_bridge_port *to, struct sk_buff *skb)
93} 100}
94 101
95/* called with rcu_read_lock */ 102/* called with rcu_read_lock */
96void br_forward(const struct net_bridge_port *to, struct sk_buff *skb) 103void br_forward(const struct net_bridge_port *to, struct sk_buff *skb, struct sk_buff *skb0)
97{ 104{
98 if (should_deliver(to, skb)) { 105 if (should_deliver(to, skb)) {
99 __br_forward(to, skb); 106 if (skb0)
107 deliver_clone(to, skb, __br_forward);
108 else
109 __br_forward(to, skb);
100 return; 110 return;
101 } 111 }
102 112
103 kfree_skb(skb); 113 if (!skb0)
114 kfree_skb(skb);
104} 115}
105 116
106/* called under bridge lock */ 117static int deliver_clone(const struct net_bridge_port *prev,
107static void br_flood(struct net_bridge *br, struct sk_buff *skb, 118 struct sk_buff *skb,
119 void (*__packet_hook)(const struct net_bridge_port *p,
120 struct sk_buff *skb))
121{
122 skb = skb_clone(skb, GFP_ATOMIC);
123 if (!skb) {
124 struct net_device *dev = BR_INPUT_SKB_CB(skb)->brdev;
125
126 dev->stats.tx_dropped++;
127 return -ENOMEM;
128 }
129
130 __packet_hook(prev, skb);
131 return 0;
132}
133
134static struct net_bridge_port *maybe_deliver(
135 struct net_bridge_port *prev, struct net_bridge_port *p,
136 struct sk_buff *skb,
108 void (*__packet_hook)(const struct net_bridge_port *p, 137 void (*__packet_hook)(const struct net_bridge_port *p,
109 struct sk_buff *skb)) 138 struct sk_buff *skb))
110{ 139{
140 int err;
141
142 if (!should_deliver(p, skb))
143 return prev;
144
145 if (!prev)
146 goto out;
147
148 err = deliver_clone(prev, skb, __packet_hook);
149 if (err)
150 return ERR_PTR(err);
151
152out:
153 return p;
154}
155
156/* called under bridge lock */
157static void br_flood(struct net_bridge *br, struct sk_buff *skb,
158 struct sk_buff *skb0,
159 void (*__packet_hook)(const struct net_bridge_port *p,
160 struct sk_buff *skb))
161{
111 struct net_bridge_port *p; 162 struct net_bridge_port *p;
112 struct net_bridge_port *prev; 163 struct net_bridge_port *prev;
113 164
114 prev = NULL; 165 prev = NULL;
115 166
116 list_for_each_entry_rcu(p, &br->port_list, list) { 167 list_for_each_entry_rcu(p, &br->port_list, list) {
117 if (should_deliver(p, skb)) { 168 prev = maybe_deliver(prev, p, skb, __packet_hook);
118 if (prev != NULL) { 169 if (IS_ERR(prev))
119 struct sk_buff *skb2; 170 goto out;
120
121 if ((skb2 = skb_clone(skb, GFP_ATOMIC)) == NULL) {
122 br->dev->stats.tx_dropped++;
123 kfree_skb(skb);
124 return;
125 }
126
127 __packet_hook(prev, skb2);
128 }
129
130 prev = p;
131 }
132 } 171 }
133 172
134 if (prev != NULL) { 173 if (!prev)
174 goto out;
175
176 if (skb0)
177 deliver_clone(prev, skb, __packet_hook);
178 else
135 __packet_hook(prev, skb); 179 __packet_hook(prev, skb);
136 return; 180 return;
137 }
138 181
139 kfree_skb(skb); 182out:
183 if (!skb0)
184 kfree_skb(skb);
140} 185}
141 186
142 187
143/* called with rcu_read_lock */ 188/* called with rcu_read_lock */
144void br_flood_deliver(struct net_bridge *br, struct sk_buff *skb) 189void br_flood_deliver(struct net_bridge *br, struct sk_buff *skb)
145{ 190{
146 br_flood(br, skb, __br_deliver); 191 br_flood(br, skb, NULL, __br_deliver);
147} 192}
148 193
149/* called under bridge lock */ 194/* called under bridge lock */
150void br_flood_forward(struct net_bridge *br, struct sk_buff *skb) 195void br_flood_forward(struct net_bridge *br, struct sk_buff *skb,
196 struct sk_buff *skb2)
197{
198 br_flood(br, skb, skb2, __br_forward);
199}
200
201#ifdef CONFIG_BRIDGE_IGMP_SNOOPING
202/* called with rcu_read_lock */
203static void br_multicast_flood(struct net_bridge_mdb_entry *mdst,
204 struct sk_buff *skb, struct sk_buff *skb0,
205 void (*__packet_hook)(
206 const struct net_bridge_port *p,
207 struct sk_buff *skb))
208{
209 struct net_device *dev = BR_INPUT_SKB_CB(skb)->brdev;
210 struct net_bridge *br = netdev_priv(dev);
211 struct net_bridge_port *port;
212 struct net_bridge_port *lport, *rport;
213 struct net_bridge_port *prev;
214 struct net_bridge_port_group *p;
215 struct hlist_node *rp;
216
217 prev = NULL;
218
219 rp = br->router_list.first;
220 p = mdst ? mdst->ports : NULL;
221 while (p || rp) {
222 lport = p ? p->port : NULL;
223 rport = rp ? hlist_entry(rp, struct net_bridge_port, rlist) :
224 NULL;
225
226 port = (unsigned long)lport > (unsigned long)rport ?
227 lport : rport;
228
229 prev = maybe_deliver(prev, port, skb, __packet_hook);
230 if (IS_ERR(prev))
231 goto out;
232
233 if ((unsigned long)lport >= (unsigned long)port)
234 p = p->next;
235 if ((unsigned long)rport >= (unsigned long)port)
236 rp = rp->next;
237 }
238
239 if (!prev)
240 goto out;
241
242 if (skb0)
243 deliver_clone(prev, skb, __packet_hook);
244 else
245 __packet_hook(prev, skb);
246 return;
247
248out:
249 if (!skb0)
250 kfree_skb(skb);
251}
252
253/* called with rcu_read_lock */
254void br_multicast_deliver(struct net_bridge_mdb_entry *mdst,
255 struct sk_buff *skb)
256{
257 br_multicast_flood(mdst, skb, NULL, __br_deliver);
258}
259
260/* called with rcu_read_lock */
261void br_multicast_forward(struct net_bridge_mdb_entry *mdst,
262 struct sk_buff *skb, struct sk_buff *skb2)
151{ 263{
152 br_flood(br, skb, __br_forward); 264 br_multicast_flood(mdst, skb, skb2, __br_forward);
153} 265}
266#endif
diff --git a/net/bridge/br_if.c b/net/bridge/br_if.c
index 4a9f52732655..0b6b1f2ff7ac 100644
--- a/net/bridge/br_if.c
+++ b/net/bridge/br_if.c
@@ -19,6 +19,7 @@
19#include <linux/init.h> 19#include <linux/init.h>
20#include <linux/rtnetlink.h> 20#include <linux/rtnetlink.h>
21#include <linux/if_ether.h> 21#include <linux/if_ether.h>
22#include <linux/slab.h>
22#include <net/sock.h> 23#include <net/sock.h>
23 24
24#include "br_private.h" 25#include "br_private.h"
@@ -147,6 +148,8 @@ static void del_nbp(struct net_bridge_port *p)
147 148
148 rcu_assign_pointer(dev->br_port, NULL); 149 rcu_assign_pointer(dev->br_port, NULL);
149 150
151 br_multicast_del_port(p);
152
150 kobject_uevent(&p->kobj, KOBJ_REMOVE); 153 kobject_uevent(&p->kobj, KOBJ_REMOVE);
151 kobject_del(&p->kobj); 154 kobject_del(&p->kobj);
152 155
@@ -154,7 +157,7 @@ static void del_nbp(struct net_bridge_port *p)
154} 157}
155 158
156/* called with RTNL */ 159/* called with RTNL */
157static void del_br(struct net_bridge *br) 160static void del_br(struct net_bridge *br, struct list_head *head)
158{ 161{
159 struct net_bridge_port *p, *n; 162 struct net_bridge_port *p, *n;
160 163
@@ -165,7 +168,7 @@ static void del_br(struct net_bridge *br)
165 del_timer_sync(&br->gc_timer); 168 del_timer_sync(&br->gc_timer);
166 169
167 br_sysfs_delbr(br->dev); 170 br_sysfs_delbr(br->dev);
168 unregister_netdevice(br->dev); 171 unregister_netdevice_queue(br->dev, head);
169} 172}
170 173
171static struct net_device *new_bridge_dev(struct net *net, const char *name) 174static struct net_device *new_bridge_dev(struct net *net, const char *name)
@@ -206,9 +209,8 @@ static struct net_device *new_bridge_dev(struct net *net, const char *name)
206 209
207 br_netfilter_rtable_init(br); 210 br_netfilter_rtable_init(br);
208 211
209 INIT_LIST_HEAD(&br->age_list);
210
211 br_stp_timer_init(br); 212 br_stp_timer_init(br);
213 br_multicast_init(br);
212 214
213 return dev; 215 return dev;
214} 216}
@@ -260,6 +262,7 @@ static struct net_bridge_port *new_nbp(struct net_bridge *br,
260 br_init_port(p); 262 br_init_port(p);
261 p->state = BR_STATE_DISABLED; 263 p->state = BR_STATE_DISABLED;
262 br_stp_port_timer_init(p); 264 br_stp_port_timer_init(p);
265 br_multicast_add_port(p);
263 266
264 return p; 267 return p;
265} 268}
@@ -323,7 +326,7 @@ int br_del_bridge(struct net *net, const char *name)
323 } 326 }
324 327
325 else 328 else
326 del_br(netdev_priv(dev)); 329 del_br(netdev_priv(dev), NULL);
327 330
328 rtnl_unlock(); 331 rtnl_unlock();
329 return ret; 332 return ret;
@@ -390,6 +393,10 @@ int br_add_if(struct net_bridge *br, struct net_device *dev)
390 if (dev->br_port != NULL) 393 if (dev->br_port != NULL)
391 return -EBUSY; 394 return -EBUSY;
392 395
396 /* No bridging devices that dislike that (e.g. wireless) */
397 if (dev->priv_flags & IFF_DONT_BRIDGE)
398 return -EOPNOTSUPP;
399
393 p = new_nbp(br, dev); 400 p = new_nbp(br, dev);
394 if (IS_ERR(p)) 401 if (IS_ERR(p))
395 return PTR_ERR(p); 402 return PTR_ERR(p);
@@ -463,18 +470,17 @@ int br_del_if(struct net_bridge *br, struct net_device *dev)
463 return 0; 470 return 0;
464} 471}
465 472
466void br_net_exit(struct net *net) 473void __net_exit br_net_exit(struct net *net)
467{ 474{
468 struct net_device *dev; 475 struct net_device *dev;
476 LIST_HEAD(list);
469 477
470 rtnl_lock(); 478 rtnl_lock();
471restart: 479 for_each_netdev(net, dev)
472 for_each_netdev(net, dev) { 480 if (dev->priv_flags & IFF_EBRIDGE)
473 if (dev->priv_flags & IFF_EBRIDGE) { 481 del_br(netdev_priv(dev), &list);
474 del_br(netdev_priv(dev)); 482
475 goto restart; 483 unregister_netdevice_many(&list);
476 }
477 }
478 rtnl_unlock(); 484 rtnl_unlock();
479 485
480} 486}
diff --git a/net/bridge/br_input.c b/net/bridge/br_input.c
index 5ee1a3682bf2..a82dde2d2ead 100644
--- a/net/bridge/br_input.c
+++ b/net/bridge/br_input.c
@@ -11,6 +11,7 @@
11 * 2 of the License, or (at your option) any later version. 11 * 2 of the License, or (at your option) any later version.
12 */ 12 */
13 13
14#include <linux/slab.h>
14#include <linux/kernel.h> 15#include <linux/kernel.h>
15#include <linux/netdevice.h> 16#include <linux/netdevice.h>
16#include <linux/etherdevice.h> 17#include <linux/etherdevice.h>
@@ -20,9 +21,9 @@
20/* Bridge group multicast address 802.1d (pg 51). */ 21/* Bridge group multicast address 802.1d (pg 51). */
21const u8 br_group_address[ETH_ALEN] = { 0x01, 0x80, 0xc2, 0x00, 0x00, 0x00 }; 22const u8 br_group_address[ETH_ALEN] = { 0x01, 0x80, 0xc2, 0x00, 0x00, 0x00 };
22 23
23static void br_pass_frame_up(struct net_bridge *br, struct sk_buff *skb) 24static int br_pass_frame_up(struct sk_buff *skb)
24{ 25{
25 struct net_device *indev, *brdev = br->dev; 26 struct net_device *indev, *brdev = BR_INPUT_SKB_CB(skb)->brdev;
26 27
27 brdev->stats.rx_packets++; 28 brdev->stats.rx_packets++;
28 brdev->stats.rx_bytes += skb->len; 29 brdev->stats.rx_bytes += skb->len;
@@ -30,8 +31,8 @@ static void br_pass_frame_up(struct net_bridge *br, struct sk_buff *skb)
30 indev = skb->dev; 31 indev = skb->dev;
31 skb->dev = brdev; 32 skb->dev = brdev;
32 33
33 NF_HOOK(PF_BRIDGE, NF_BR_LOCAL_IN, skb, indev, NULL, 34 return NF_HOOK(PF_BRIDGE, NF_BR_LOCAL_IN, skb, indev, NULL,
34 netif_receive_skb); 35 netif_receive_skb);
35} 36}
36 37
37/* note: already called with rcu_read_lock (preempt_disabled) */ 38/* note: already called with rcu_read_lock (preempt_disabled) */
@@ -41,6 +42,7 @@ int br_handle_frame_finish(struct sk_buff *skb)
41 struct net_bridge_port *p = rcu_dereference(skb->dev->br_port); 42 struct net_bridge_port *p = rcu_dereference(skb->dev->br_port);
42 struct net_bridge *br; 43 struct net_bridge *br;
43 struct net_bridge_fdb_entry *dst; 44 struct net_bridge_fdb_entry *dst;
45 struct net_bridge_mdb_entry *mdst;
44 struct sk_buff *skb2; 46 struct sk_buff *skb2;
45 47
46 if (!p || p->state == BR_STATE_DISABLED) 48 if (!p || p->state == BR_STATE_DISABLED)
@@ -50,9 +52,15 @@ int br_handle_frame_finish(struct sk_buff *skb)
50 br = p->br; 52 br = p->br;
51 br_fdb_update(br, p, eth_hdr(skb)->h_source); 53 br_fdb_update(br, p, eth_hdr(skb)->h_source);
52 54
55 if (is_multicast_ether_addr(dest) &&
56 br_multicast_rcv(br, p, skb))
57 goto drop;
58
53 if (p->state == BR_STATE_LEARNING) 59 if (p->state == BR_STATE_LEARNING)
54 goto drop; 60 goto drop;
55 61
62 BR_INPUT_SKB_CB(skb)->brdev = br->dev;
63
56 /* The packet skb2 goes to the local host (NULL to skip). */ 64 /* The packet skb2 goes to the local host (NULL to skip). */
57 skb2 = NULL; 65 skb2 = NULL;
58 66
@@ -62,27 +70,35 @@ int br_handle_frame_finish(struct sk_buff *skb)
62 dst = NULL; 70 dst = NULL;
63 71
64 if (is_multicast_ether_addr(dest)) { 72 if (is_multicast_ether_addr(dest)) {
73 mdst = br_mdb_get(br, skb);
74 if (mdst || BR_INPUT_SKB_CB_MROUTERS_ONLY(skb)) {
75 if ((mdst && !hlist_unhashed(&mdst->mglist)) ||
76 br_multicast_is_router(br))
77 skb2 = skb;
78 br_multicast_forward(mdst, skb, skb2);
79 skb = NULL;
80 if (!skb2)
81 goto out;
82 } else
83 skb2 = skb;
84
65 br->dev->stats.multicast++; 85 br->dev->stats.multicast++;
66 skb2 = skb;
67 } else if ((dst = __br_fdb_get(br, dest)) && dst->is_local) { 86 } else if ((dst = __br_fdb_get(br, dest)) && dst->is_local) {
68 skb2 = skb; 87 skb2 = skb;
69 /* Do not forward the packet since it's local. */ 88 /* Do not forward the packet since it's local. */
70 skb = NULL; 89 skb = NULL;
71 } 90 }
72 91
73 if (skb2 == skb)
74 skb2 = skb_clone(skb, GFP_ATOMIC);
75
76 if (skb2)
77 br_pass_frame_up(br, skb2);
78
79 if (skb) { 92 if (skb) {
80 if (dst) 93 if (dst)
81 br_forward(dst->dst, skb); 94 br_forward(dst->dst, skb, skb2);
82 else 95 else
83 br_flood_forward(br, skb); 96 br_flood_forward(br, skb, skb2);
84 } 97 }
85 98
99 if (skb2)
100 return br_pass_frame_up(skb2);
101
86out: 102out:
87 return 0; 103 return 0;
88drop: 104drop:
diff --git a/net/bridge/br_ioctl.c b/net/bridge/br_ioctl.c
index 6a6433daaf27..995afc4b04dc 100644
--- a/net/bridge/br_ioctl.c
+++ b/net/bridge/br_ioctl.c
@@ -15,6 +15,7 @@
15#include <linux/kernel.h> 15#include <linux/kernel.h>
16#include <linux/if_bridge.h> 16#include <linux/if_bridge.h>
17#include <linux/netdevice.h> 17#include <linux/netdevice.h>
18#include <linux/slab.h>
18#include <linux/times.h> 19#include <linux/times.h>
19#include <net/net_namespace.h> 20#include <net/net_namespace.h>
20#include <asm/uaccess.h> 21#include <asm/uaccess.h>
@@ -81,6 +82,7 @@ static int get_fdb_entries(struct net_bridge *br, void __user *userbuf,
81 return num; 82 return num;
82} 83}
83 84
85/* called with RTNL */
84static int add_del_if(struct net_bridge *br, int ifindex, int isadd) 86static int add_del_if(struct net_bridge *br, int ifindex, int isadd)
85{ 87{
86 struct net_device *dev; 88 struct net_device *dev;
@@ -89,7 +91,7 @@ static int add_del_if(struct net_bridge *br, int ifindex, int isadd)
89 if (!capable(CAP_NET_ADMIN)) 91 if (!capable(CAP_NET_ADMIN))
90 return -EPERM; 92 return -EPERM;
91 93
92 dev = dev_get_by_index(dev_net(br->dev), ifindex); 94 dev = __dev_get_by_index(dev_net(br->dev), ifindex);
93 if (dev == NULL) 95 if (dev == NULL)
94 return -EINVAL; 96 return -EINVAL;
95 97
@@ -98,7 +100,6 @@ static int add_del_if(struct net_bridge *br, int ifindex, int isadd)
98 else 100 else
99 ret = br_del_if(br, dev); 101 ret = br_del_if(br, dev);
100 102
101 dev_put(dev);
102 return ret; 103 return ret;
103} 104}
104 105
diff --git a/net/bridge/br_multicast.c b/net/bridge/br_multicast.c
new file mode 100644
index 000000000000..eaa0e1bae49b
--- /dev/null
+++ b/net/bridge/br_multicast.c
@@ -0,0 +1,1309 @@
1/*
2 * Bridge multicast support.
3 *
4 * Copyright (c) 2010 Herbert Xu <herbert@gondor.apana.org.au>
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the Free
8 * Software Foundation; either version 2 of the License, or (at your option)
9 * any later version.
10 *
11 */
12
13#include <linux/err.h>
14#include <linux/if_ether.h>
15#include <linux/igmp.h>
16#include <linux/jhash.h>
17#include <linux/kernel.h>
18#include <linux/log2.h>
19#include <linux/netdevice.h>
20#include <linux/netfilter_bridge.h>
21#include <linux/random.h>
22#include <linux/rculist.h>
23#include <linux/skbuff.h>
24#include <linux/slab.h>
25#include <linux/timer.h>
26#include <net/ip.h>
27
28#include "br_private.h"
29
30static inline int br_ip_hash(struct net_bridge_mdb_htable *mdb, __be32 ip)
31{
32 return jhash_1word(mdb->secret, (u32)ip) & (mdb->max - 1);
33}
34
35static struct net_bridge_mdb_entry *__br_mdb_ip_get(
36 struct net_bridge_mdb_htable *mdb, __be32 dst, int hash)
37{
38 struct net_bridge_mdb_entry *mp;
39 struct hlist_node *p;
40
41 hlist_for_each_entry_rcu(mp, p, &mdb->mhash[hash], hlist[mdb->ver]) {
42 if (dst == mp->addr)
43 return mp;
44 }
45
46 return NULL;
47}
48
49static struct net_bridge_mdb_entry *br_mdb_ip_get(
50 struct net_bridge_mdb_htable *mdb, __be32 dst)
51{
52 if (!mdb)
53 return NULL;
54
55 return __br_mdb_ip_get(mdb, dst, br_ip_hash(mdb, dst));
56}
57
58struct net_bridge_mdb_entry *br_mdb_get(struct net_bridge *br,
59 struct sk_buff *skb)
60{
61 if (br->multicast_disabled)
62 return NULL;
63
64 switch (skb->protocol) {
65 case htons(ETH_P_IP):
66 if (BR_INPUT_SKB_CB(skb)->igmp)
67 break;
68 return br_mdb_ip_get(br->mdb, ip_hdr(skb)->daddr);
69 }
70
71 return NULL;
72}
73
74static void br_mdb_free(struct rcu_head *head)
75{
76 struct net_bridge_mdb_htable *mdb =
77 container_of(head, struct net_bridge_mdb_htable, rcu);
78 struct net_bridge_mdb_htable *old = mdb->old;
79
80 mdb->old = NULL;
81 kfree(old->mhash);
82 kfree(old);
83}
84
85static int br_mdb_copy(struct net_bridge_mdb_htable *new,
86 struct net_bridge_mdb_htable *old,
87 int elasticity)
88{
89 struct net_bridge_mdb_entry *mp;
90 struct hlist_node *p;
91 int maxlen;
92 int len;
93 int i;
94
95 for (i = 0; i < old->max; i++)
96 hlist_for_each_entry(mp, p, &old->mhash[i], hlist[old->ver])
97 hlist_add_head(&mp->hlist[new->ver],
98 &new->mhash[br_ip_hash(new, mp->addr)]);
99
100 if (!elasticity)
101 return 0;
102
103 maxlen = 0;
104 for (i = 0; i < new->max; i++) {
105 len = 0;
106 hlist_for_each_entry(mp, p, &new->mhash[i], hlist[new->ver])
107 len++;
108 if (len > maxlen)
109 maxlen = len;
110 }
111
112 return maxlen > elasticity ? -EINVAL : 0;
113}
114
115static void br_multicast_free_pg(struct rcu_head *head)
116{
117 struct net_bridge_port_group *p =
118 container_of(head, struct net_bridge_port_group, rcu);
119
120 kfree(p);
121}
122
123static void br_multicast_free_group(struct rcu_head *head)
124{
125 struct net_bridge_mdb_entry *mp =
126 container_of(head, struct net_bridge_mdb_entry, rcu);
127
128 kfree(mp);
129}
130
131static void br_multicast_group_expired(unsigned long data)
132{
133 struct net_bridge_mdb_entry *mp = (void *)data;
134 struct net_bridge *br = mp->br;
135 struct net_bridge_mdb_htable *mdb;
136
137 spin_lock(&br->multicast_lock);
138 if (!netif_running(br->dev) || timer_pending(&mp->timer))
139 goto out;
140
141 if (!hlist_unhashed(&mp->mglist))
142 hlist_del_init(&mp->mglist);
143
144 if (mp->ports)
145 goto out;
146
147 mdb = br->mdb;
148 hlist_del_rcu(&mp->hlist[mdb->ver]);
149 mdb->size--;
150
151 del_timer(&mp->query_timer);
152 call_rcu_bh(&mp->rcu, br_multicast_free_group);
153
154out:
155 spin_unlock(&br->multicast_lock);
156}
157
158static void br_multicast_del_pg(struct net_bridge *br,
159 struct net_bridge_port_group *pg)
160{
161 struct net_bridge_mdb_htable *mdb = br->mdb;
162 struct net_bridge_mdb_entry *mp;
163 struct net_bridge_port_group *p;
164 struct net_bridge_port_group **pp;
165
166 mp = br_mdb_ip_get(mdb, pg->addr);
167 if (WARN_ON(!mp))
168 return;
169
170 for (pp = &mp->ports; (p = *pp); pp = &p->next) {
171 if (p != pg)
172 continue;
173
174 *pp = p->next;
175 hlist_del_init(&p->mglist);
176 del_timer(&p->timer);
177 del_timer(&p->query_timer);
178 call_rcu_bh(&p->rcu, br_multicast_free_pg);
179
180 if (!mp->ports && hlist_unhashed(&mp->mglist) &&
181 netif_running(br->dev))
182 mod_timer(&mp->timer, jiffies);
183
184 return;
185 }
186
187 WARN_ON(1);
188}
189
190static void br_multicast_port_group_expired(unsigned long data)
191{
192 struct net_bridge_port_group *pg = (void *)data;
193 struct net_bridge *br = pg->port->br;
194
195 spin_lock(&br->multicast_lock);
196 if (!netif_running(br->dev) || timer_pending(&pg->timer) ||
197 hlist_unhashed(&pg->mglist))
198 goto out;
199
200 br_multicast_del_pg(br, pg);
201
202out:
203 spin_unlock(&br->multicast_lock);
204}
205
206static int br_mdb_rehash(struct net_bridge_mdb_htable **mdbp, int max,
207 int elasticity)
208{
209 struct net_bridge_mdb_htable *old = *mdbp;
210 struct net_bridge_mdb_htable *mdb;
211 int err;
212
213 mdb = kmalloc(sizeof(*mdb), GFP_ATOMIC);
214 if (!mdb)
215 return -ENOMEM;
216
217 mdb->max = max;
218 mdb->old = old;
219
220 mdb->mhash = kzalloc(max * sizeof(*mdb->mhash), GFP_ATOMIC);
221 if (!mdb->mhash) {
222 kfree(mdb);
223 return -ENOMEM;
224 }
225
226 mdb->size = old ? old->size : 0;
227 mdb->ver = old ? old->ver ^ 1 : 0;
228
229 if (!old || elasticity)
230 get_random_bytes(&mdb->secret, sizeof(mdb->secret));
231 else
232 mdb->secret = old->secret;
233
234 if (!old)
235 goto out;
236
237 err = br_mdb_copy(mdb, old, elasticity);
238 if (err) {
239 kfree(mdb->mhash);
240 kfree(mdb);
241 return err;
242 }
243
244 call_rcu_bh(&mdb->rcu, br_mdb_free);
245
246out:
247 rcu_assign_pointer(*mdbp, mdb);
248
249 return 0;
250}
251
252static struct sk_buff *br_multicast_alloc_query(struct net_bridge *br,
253 __be32 group)
254{
255 struct sk_buff *skb;
256 struct igmphdr *ih;
257 struct ethhdr *eth;
258 struct iphdr *iph;
259
260 skb = netdev_alloc_skb_ip_align(br->dev, sizeof(*eth) + sizeof(*iph) +
261 sizeof(*ih) + 4);
262 if (!skb)
263 goto out;
264
265 skb->protocol = htons(ETH_P_IP);
266
267 skb_reset_mac_header(skb);
268 eth = eth_hdr(skb);
269
270 memcpy(eth->h_source, br->dev->dev_addr, 6);
271 eth->h_dest[0] = 1;
272 eth->h_dest[1] = 0;
273 eth->h_dest[2] = 0x5e;
274 eth->h_dest[3] = 0;
275 eth->h_dest[4] = 0;
276 eth->h_dest[5] = 1;
277 eth->h_proto = htons(ETH_P_IP);
278 skb_put(skb, sizeof(*eth));
279
280 skb_set_network_header(skb, skb->len);
281 iph = ip_hdr(skb);
282
283 iph->version = 4;
284 iph->ihl = 6;
285 iph->tos = 0xc0;
286 iph->tot_len = htons(sizeof(*iph) + sizeof(*ih) + 4);
287 iph->id = 0;
288 iph->frag_off = htons(IP_DF);
289 iph->ttl = 1;
290 iph->protocol = IPPROTO_IGMP;
291 iph->saddr = 0;
292 iph->daddr = htonl(INADDR_ALLHOSTS_GROUP);
293 ((u8 *)&iph[1])[0] = IPOPT_RA;
294 ((u8 *)&iph[1])[1] = 4;
295 ((u8 *)&iph[1])[2] = 0;
296 ((u8 *)&iph[1])[3] = 0;
297 ip_send_check(iph);
298 skb_put(skb, 24);
299
300 skb_set_transport_header(skb, skb->len);
301 ih = igmp_hdr(skb);
302 ih->type = IGMP_HOST_MEMBERSHIP_QUERY;
303 ih->code = (group ? br->multicast_last_member_interval :
304 br->multicast_query_response_interval) /
305 (HZ / IGMP_TIMER_SCALE);
306 ih->group = group;
307 ih->csum = 0;
308 ih->csum = ip_compute_csum((void *)ih, sizeof(struct igmphdr));
309 skb_put(skb, sizeof(*ih));
310
311 __skb_pull(skb, sizeof(*eth));
312
313out:
314 return skb;
315}
316
317static void br_multicast_send_group_query(struct net_bridge_mdb_entry *mp)
318{
319 struct net_bridge *br = mp->br;
320 struct sk_buff *skb;
321
322 skb = br_multicast_alloc_query(br, mp->addr);
323 if (!skb)
324 goto timer;
325
326 netif_rx(skb);
327
328timer:
329 if (++mp->queries_sent < br->multicast_last_member_count)
330 mod_timer(&mp->query_timer,
331 jiffies + br->multicast_last_member_interval);
332}
333
334static void br_multicast_group_query_expired(unsigned long data)
335{
336 struct net_bridge_mdb_entry *mp = (void *)data;
337 struct net_bridge *br = mp->br;
338
339 spin_lock(&br->multicast_lock);
340 if (!netif_running(br->dev) || hlist_unhashed(&mp->mglist) ||
341 mp->queries_sent >= br->multicast_last_member_count)
342 goto out;
343
344 br_multicast_send_group_query(mp);
345
346out:
347 spin_unlock(&br->multicast_lock);
348}
349
350static void br_multicast_send_port_group_query(struct net_bridge_port_group *pg)
351{
352 struct net_bridge_port *port = pg->port;
353 struct net_bridge *br = port->br;
354 struct sk_buff *skb;
355
356 skb = br_multicast_alloc_query(br, pg->addr);
357 if (!skb)
358 goto timer;
359
360 br_deliver(port, skb);
361
362timer:
363 if (++pg->queries_sent < br->multicast_last_member_count)
364 mod_timer(&pg->query_timer,
365 jiffies + br->multicast_last_member_interval);
366}
367
368static void br_multicast_port_group_query_expired(unsigned long data)
369{
370 struct net_bridge_port_group *pg = (void *)data;
371 struct net_bridge_port *port = pg->port;
372 struct net_bridge *br = port->br;
373
374 spin_lock(&br->multicast_lock);
375 if (!netif_running(br->dev) || hlist_unhashed(&pg->mglist) ||
376 pg->queries_sent >= br->multicast_last_member_count)
377 goto out;
378
379 br_multicast_send_port_group_query(pg);
380
381out:
382 spin_unlock(&br->multicast_lock);
383}
384
385static struct net_bridge_mdb_entry *br_multicast_get_group(
386 struct net_bridge *br, struct net_bridge_port *port, __be32 group,
387 int hash)
388{
389 struct net_bridge_mdb_htable *mdb = br->mdb;
390 struct net_bridge_mdb_entry *mp;
391 struct hlist_node *p;
392 unsigned count = 0;
393 unsigned max;
394 int elasticity;
395 int err;
396
397 hlist_for_each_entry(mp, p, &mdb->mhash[hash], hlist[mdb->ver]) {
398 count++;
399 if (unlikely(group == mp->addr)) {
400 return mp;
401 }
402 }
403
404 elasticity = 0;
405 max = mdb->max;
406
407 if (unlikely(count > br->hash_elasticity && count)) {
408 if (net_ratelimit())
409 printk(KERN_INFO "%s: Multicast hash table "
410 "chain limit reached: %s\n",
411 br->dev->name, port ? port->dev->name :
412 br->dev->name);
413
414 elasticity = br->hash_elasticity;
415 }
416
417 if (mdb->size >= max) {
418 max *= 2;
419 if (unlikely(max >= br->hash_max)) {
420 printk(KERN_WARNING "%s: Multicast hash table maximum "
421 "reached, disabling snooping: %s, %d\n",
422 br->dev->name, port ? port->dev->name :
423 br->dev->name,
424 max);
425 err = -E2BIG;
426disable:
427 br->multicast_disabled = 1;
428 goto err;
429 }
430 }
431
432 if (max > mdb->max || elasticity) {
433 if (mdb->old) {
434 if (net_ratelimit())
435 printk(KERN_INFO "%s: Multicast hash table "
436 "on fire: %s\n",
437 br->dev->name, port ? port->dev->name :
438 br->dev->name);
439 err = -EEXIST;
440 goto err;
441 }
442
443 err = br_mdb_rehash(&br->mdb, max, elasticity);
444 if (err) {
445 printk(KERN_WARNING "%s: Cannot rehash multicast "
446 "hash table, disabling snooping: "
447 "%s, %d, %d\n",
448 br->dev->name, port ? port->dev->name :
449 br->dev->name,
450 mdb->size, err);
451 goto disable;
452 }
453
454 err = -EAGAIN;
455 goto err;
456 }
457
458 return NULL;
459
460err:
461 mp = ERR_PTR(err);
462 return mp;
463}
464
465static struct net_bridge_mdb_entry *br_multicast_new_group(
466 struct net_bridge *br, struct net_bridge_port *port, __be32 group)
467{
468 struct net_bridge_mdb_htable *mdb = br->mdb;
469 struct net_bridge_mdb_entry *mp;
470 int hash;
471
472 if (!mdb) {
473 if (br_mdb_rehash(&br->mdb, BR_HASH_SIZE, 0))
474 return NULL;
475 goto rehash;
476 }
477
478 hash = br_ip_hash(mdb, group);
479 mp = br_multicast_get_group(br, port, group, hash);
480 switch (PTR_ERR(mp)) {
481 case 0:
482 break;
483
484 case -EAGAIN:
485rehash:
486 mdb = br->mdb;
487 hash = br_ip_hash(mdb, group);
488 break;
489
490 default:
491 goto out;
492 }
493
494 mp = kzalloc(sizeof(*mp), GFP_ATOMIC);
495 if (unlikely(!mp))
496 goto out;
497
498 mp->br = br;
499 mp->addr = group;
500 setup_timer(&mp->timer, br_multicast_group_expired,
501 (unsigned long)mp);
502 setup_timer(&mp->query_timer, br_multicast_group_query_expired,
503 (unsigned long)mp);
504
505 hlist_add_head_rcu(&mp->hlist[mdb->ver], &mdb->mhash[hash]);
506 mdb->size++;
507
508out:
509 return mp;
510}
511
512static int br_multicast_add_group(struct net_bridge *br,
513 struct net_bridge_port *port, __be32 group)
514{
515 struct net_bridge_mdb_entry *mp;
516 struct net_bridge_port_group *p;
517 struct net_bridge_port_group **pp;
518 unsigned long now = jiffies;
519 int err;
520
521 if (ipv4_is_local_multicast(group))
522 return 0;
523
524 spin_lock(&br->multicast_lock);
525 if (!netif_running(br->dev) ||
526 (port && port->state == BR_STATE_DISABLED))
527 goto out;
528
529 mp = br_multicast_new_group(br, port, group);
530 err = PTR_ERR(mp);
531 if (unlikely(IS_ERR(mp) || !mp))
532 goto err;
533
534 if (!port) {
535 hlist_add_head(&mp->mglist, &br->mglist);
536 mod_timer(&mp->timer, now + br->multicast_membership_interval);
537 goto out;
538 }
539
540 for (pp = &mp->ports; (p = *pp); pp = &p->next) {
541 if (p->port == port)
542 goto found;
543 if ((unsigned long)p->port < (unsigned long)port)
544 break;
545 }
546
547 p = kzalloc(sizeof(*p), GFP_ATOMIC);
548 err = -ENOMEM;
549 if (unlikely(!p))
550 goto err;
551
552 p->addr = group;
553 p->port = port;
554 p->next = *pp;
555 hlist_add_head(&p->mglist, &port->mglist);
556 setup_timer(&p->timer, br_multicast_port_group_expired,
557 (unsigned long)p);
558 setup_timer(&p->query_timer, br_multicast_port_group_query_expired,
559 (unsigned long)p);
560
561 rcu_assign_pointer(*pp, p);
562
563found:
564 mod_timer(&p->timer, now + br->multicast_membership_interval);
565out:
566 err = 0;
567
568err:
569 spin_unlock(&br->multicast_lock);
570 return err;
571}
572
573static void br_multicast_router_expired(unsigned long data)
574{
575 struct net_bridge_port *port = (void *)data;
576 struct net_bridge *br = port->br;
577
578 spin_lock(&br->multicast_lock);
579 if (port->multicast_router != 1 ||
580 timer_pending(&port->multicast_router_timer) ||
581 hlist_unhashed(&port->rlist))
582 goto out;
583
584 hlist_del_init_rcu(&port->rlist);
585
586out:
587 spin_unlock(&br->multicast_lock);
588}
589
590static void br_multicast_local_router_expired(unsigned long data)
591{
592}
593
594static void br_multicast_send_query(struct net_bridge *br,
595 struct net_bridge_port *port, u32 sent)
596{
597 unsigned long time;
598 struct sk_buff *skb;
599
600 if (!netif_running(br->dev) || br->multicast_disabled ||
601 timer_pending(&br->multicast_querier_timer))
602 return;
603
604 skb = br_multicast_alloc_query(br, 0);
605 if (!skb)
606 goto timer;
607
608 if (port) {
609 __skb_push(skb, sizeof(struct ethhdr));
610 skb->dev = port->dev;
611 NF_HOOK(PF_BRIDGE, NF_BR_LOCAL_OUT, skb, NULL, skb->dev,
612 dev_queue_xmit);
613 } else
614 netif_rx(skb);
615
616timer:
617 time = jiffies;
618 time += sent < br->multicast_startup_query_count ?
619 br->multicast_startup_query_interval :
620 br->multicast_query_interval;
621 mod_timer(port ? &port->multicast_query_timer :
622 &br->multicast_query_timer, time);
623}
624
625static void br_multicast_port_query_expired(unsigned long data)
626{
627 struct net_bridge_port *port = (void *)data;
628 struct net_bridge *br = port->br;
629
630 spin_lock(&br->multicast_lock);
631 if (port->state == BR_STATE_DISABLED ||
632 port->state == BR_STATE_BLOCKING)
633 goto out;
634
635 if (port->multicast_startup_queries_sent <
636 br->multicast_startup_query_count)
637 port->multicast_startup_queries_sent++;
638
639 br_multicast_send_query(port->br, port,
640 port->multicast_startup_queries_sent);
641
642out:
643 spin_unlock(&br->multicast_lock);
644}
645
646void br_multicast_add_port(struct net_bridge_port *port)
647{
648 port->multicast_router = 1;
649
650 setup_timer(&port->multicast_router_timer, br_multicast_router_expired,
651 (unsigned long)port);
652 setup_timer(&port->multicast_query_timer,
653 br_multicast_port_query_expired, (unsigned long)port);
654}
655
656void br_multicast_del_port(struct net_bridge_port *port)
657{
658 del_timer_sync(&port->multicast_router_timer);
659}
660
661static void __br_multicast_enable_port(struct net_bridge_port *port)
662{
663 port->multicast_startup_queries_sent = 0;
664
665 if (try_to_del_timer_sync(&port->multicast_query_timer) >= 0 ||
666 del_timer(&port->multicast_query_timer))
667 mod_timer(&port->multicast_query_timer, jiffies);
668}
669
670void br_multicast_enable_port(struct net_bridge_port *port)
671{
672 struct net_bridge *br = port->br;
673
674 spin_lock(&br->multicast_lock);
675 if (br->multicast_disabled || !netif_running(br->dev))
676 goto out;
677
678 __br_multicast_enable_port(port);
679
680out:
681 spin_unlock(&br->multicast_lock);
682}
683
684void br_multicast_disable_port(struct net_bridge_port *port)
685{
686 struct net_bridge *br = port->br;
687 struct net_bridge_port_group *pg;
688 struct hlist_node *p, *n;
689
690 spin_lock(&br->multicast_lock);
691 hlist_for_each_entry_safe(pg, p, n, &port->mglist, mglist)
692 br_multicast_del_pg(br, pg);
693
694 if (!hlist_unhashed(&port->rlist))
695 hlist_del_init_rcu(&port->rlist);
696 del_timer(&port->multicast_router_timer);
697 del_timer(&port->multicast_query_timer);
698 spin_unlock(&br->multicast_lock);
699}
700
701static int br_multicast_igmp3_report(struct net_bridge *br,
702 struct net_bridge_port *port,
703 struct sk_buff *skb)
704{
705 struct igmpv3_report *ih;
706 struct igmpv3_grec *grec;
707 int i;
708 int len;
709 int num;
710 int type;
711 int err = 0;
712 __be32 group;
713
714 if (!pskb_may_pull(skb, sizeof(*ih)))
715 return -EINVAL;
716
717 ih = igmpv3_report_hdr(skb);
718 num = ntohs(ih->ngrec);
719 len = sizeof(*ih);
720
721 for (i = 0; i < num; i++) {
722 len += sizeof(*grec);
723 if (!pskb_may_pull(skb, len))
724 return -EINVAL;
725
726 grec = (void *)(skb->data + len - sizeof(*grec));
727 group = grec->grec_mca;
728 type = grec->grec_type;
729
730 len += ntohs(grec->grec_nsrcs) * 4;
731 if (!pskb_may_pull(skb, len))
732 return -EINVAL;
733
734 /* We treat this as an IGMPv2 report for now. */
735 switch (type) {
736 case IGMPV3_MODE_IS_INCLUDE:
737 case IGMPV3_MODE_IS_EXCLUDE:
738 case IGMPV3_CHANGE_TO_INCLUDE:
739 case IGMPV3_CHANGE_TO_EXCLUDE:
740 case IGMPV3_ALLOW_NEW_SOURCES:
741 case IGMPV3_BLOCK_OLD_SOURCES:
742 break;
743
744 default:
745 continue;
746 }
747
748 err = br_multicast_add_group(br, port, group);
749 if (err)
750 break;
751 }
752
753 return err;
754}
755
756static void br_multicast_add_router(struct net_bridge *br,
757 struct net_bridge_port *port)
758{
759 struct hlist_node *p;
760 struct hlist_node **h;
761
762 for (h = &br->router_list.first;
763 (p = *h) &&
764 (unsigned long)container_of(p, struct net_bridge_port, rlist) >
765 (unsigned long)port;
766 h = &p->next)
767 ;
768
769 port->rlist.pprev = h;
770 port->rlist.next = p;
771 rcu_assign_pointer(*h, &port->rlist);
772 if (p)
773 p->pprev = &port->rlist.next;
774}
775
776static void br_multicast_mark_router(struct net_bridge *br,
777 struct net_bridge_port *port)
778{
779 unsigned long now = jiffies;
780
781 if (!port) {
782 if (br->multicast_router == 1)
783 mod_timer(&br->multicast_router_timer,
784 now + br->multicast_querier_interval);
785 return;
786 }
787
788 if (port->multicast_router != 1)
789 return;
790
791 if (!hlist_unhashed(&port->rlist))
792 goto timer;
793
794 br_multicast_add_router(br, port);
795
796timer:
797 mod_timer(&port->multicast_router_timer,
798 now + br->multicast_querier_interval);
799}
800
801static void br_multicast_query_received(struct net_bridge *br,
802 struct net_bridge_port *port,
803 __be32 saddr)
804{
805 if (saddr)
806 mod_timer(&br->multicast_querier_timer,
807 jiffies + br->multicast_querier_interval);
808 else if (timer_pending(&br->multicast_querier_timer))
809 return;
810
811 br_multicast_mark_router(br, port);
812}
813
814static int br_multicast_query(struct net_bridge *br,
815 struct net_bridge_port *port,
816 struct sk_buff *skb)
817{
818 struct iphdr *iph = ip_hdr(skb);
819 struct igmphdr *ih = igmp_hdr(skb);
820 struct net_bridge_mdb_entry *mp;
821 struct igmpv3_query *ih3;
822 struct net_bridge_port_group *p;
823 struct net_bridge_port_group **pp;
824 unsigned long max_delay;
825 unsigned long now = jiffies;
826 __be32 group;
827 int err = 0;
828
829 spin_lock(&br->multicast_lock);
830 if (!netif_running(br->dev) ||
831 (port && port->state == BR_STATE_DISABLED))
832 goto out;
833
834 br_multicast_query_received(br, port, iph->saddr);
835
836 group = ih->group;
837
838 if (skb->len == sizeof(*ih)) {
839 max_delay = ih->code * (HZ / IGMP_TIMER_SCALE);
840
841 if (!max_delay) {
842 max_delay = 10 * HZ;
843 group = 0;
844 }
845 } else {
846 if (!pskb_may_pull(skb, sizeof(struct igmpv3_query))) {
847 err = -EINVAL;
848 goto out;
849 }
850
851 ih3 = igmpv3_query_hdr(skb);
852 if (ih3->nsrcs)
853 goto out;
854
855 max_delay = ih3->code ?
856 IGMPV3_MRC(ih3->code) * (HZ / IGMP_TIMER_SCALE) : 1;
857 }
858
859 if (!group)
860 goto out;
861
862 mp = br_mdb_ip_get(br->mdb, group);
863 if (!mp)
864 goto out;
865
866 max_delay *= br->multicast_last_member_count;
867
868 if (!hlist_unhashed(&mp->mglist) &&
869 (timer_pending(&mp->timer) ?
870 time_after(mp->timer.expires, now + max_delay) :
871 try_to_del_timer_sync(&mp->timer) >= 0))
872 mod_timer(&mp->timer, now + max_delay);
873
874 for (pp = &mp->ports; (p = *pp); pp = &p->next) {
875 if (timer_pending(&p->timer) ?
876 time_after(p->timer.expires, now + max_delay) :
877 try_to_del_timer_sync(&p->timer) >= 0)
878 mod_timer(&mp->timer, now + max_delay);
879 }
880
881out:
882 spin_unlock(&br->multicast_lock);
883 return err;
884}
885
886static void br_multicast_leave_group(struct net_bridge *br,
887 struct net_bridge_port *port,
888 __be32 group)
889{
890 struct net_bridge_mdb_htable *mdb;
891 struct net_bridge_mdb_entry *mp;
892 struct net_bridge_port_group *p;
893 unsigned long now;
894 unsigned long time;
895
896 if (ipv4_is_local_multicast(group))
897 return;
898
899 spin_lock(&br->multicast_lock);
900 if (!netif_running(br->dev) ||
901 (port && port->state == BR_STATE_DISABLED) ||
902 timer_pending(&br->multicast_querier_timer))
903 goto out;
904
905 mdb = br->mdb;
906 mp = br_mdb_ip_get(mdb, group);
907 if (!mp)
908 goto out;
909
910 now = jiffies;
911 time = now + br->multicast_last_member_count *
912 br->multicast_last_member_interval;
913
914 if (!port) {
915 if (!hlist_unhashed(&mp->mglist) &&
916 (timer_pending(&mp->timer) ?
917 time_after(mp->timer.expires, time) :
918 try_to_del_timer_sync(&mp->timer) >= 0)) {
919 mod_timer(&mp->timer, time);
920
921 mp->queries_sent = 0;
922 mod_timer(&mp->query_timer, now);
923 }
924
925 goto out;
926 }
927
928 for (p = mp->ports; p; p = p->next) {
929 if (p->port != port)
930 continue;
931
932 if (!hlist_unhashed(&p->mglist) &&
933 (timer_pending(&p->timer) ?
934 time_after(p->timer.expires, time) :
935 try_to_del_timer_sync(&p->timer) >= 0)) {
936 mod_timer(&p->timer, time);
937
938 p->queries_sent = 0;
939 mod_timer(&p->query_timer, now);
940 }
941
942 break;
943 }
944
945out:
946 spin_unlock(&br->multicast_lock);
947}
948
949static int br_multicast_ipv4_rcv(struct net_bridge *br,
950 struct net_bridge_port *port,
951 struct sk_buff *skb)
952{
953 struct sk_buff *skb2 = skb;
954 struct iphdr *iph;
955 struct igmphdr *ih;
956 unsigned len;
957 unsigned offset;
958 int err;
959
960 /* We treat OOM as packet loss for now. */
961 if (!pskb_may_pull(skb, sizeof(*iph)))
962 return -EINVAL;
963
964 iph = ip_hdr(skb);
965
966 if (iph->ihl < 5 || iph->version != 4)
967 return -EINVAL;
968
969 if (!pskb_may_pull(skb, ip_hdrlen(skb)))
970 return -EINVAL;
971
972 iph = ip_hdr(skb);
973
974 if (unlikely(ip_fast_csum((u8 *)iph, iph->ihl)))
975 return -EINVAL;
976
977 if (iph->protocol != IPPROTO_IGMP)
978 return 0;
979
980 len = ntohs(iph->tot_len);
981 if (skb->len < len || len < ip_hdrlen(skb))
982 return -EINVAL;
983
984 if (skb->len > len) {
985 skb2 = skb_clone(skb, GFP_ATOMIC);
986 if (!skb2)
987 return -ENOMEM;
988
989 err = pskb_trim_rcsum(skb2, len);
990 if (err)
991 goto err_out;
992 }
993
994 len -= ip_hdrlen(skb2);
995 offset = skb_network_offset(skb2) + ip_hdrlen(skb2);
996 __skb_pull(skb2, offset);
997 skb_reset_transport_header(skb2);
998
999 err = -EINVAL;
1000 if (!pskb_may_pull(skb2, sizeof(*ih)))
1001 goto out;
1002
1003 iph = ip_hdr(skb2);
1004
1005 switch (skb2->ip_summed) {
1006 case CHECKSUM_COMPLETE:
1007 if (!csum_fold(skb2->csum))
1008 break;
1009 /* fall through */
1010 case CHECKSUM_NONE:
1011 skb2->csum = 0;
1012 if (skb_checksum_complete(skb2))
1013 goto out;
1014 }
1015
1016 err = 0;
1017
1018 BR_INPUT_SKB_CB(skb)->igmp = 1;
1019 ih = igmp_hdr(skb2);
1020
1021 switch (ih->type) {
1022 case IGMP_HOST_MEMBERSHIP_REPORT:
1023 case IGMPV2_HOST_MEMBERSHIP_REPORT:
1024 BR_INPUT_SKB_CB(skb2)->mrouters_only = 1;
1025 err = br_multicast_add_group(br, port, ih->group);
1026 break;
1027 case IGMPV3_HOST_MEMBERSHIP_REPORT:
1028 err = br_multicast_igmp3_report(br, port, skb2);
1029 break;
1030 case IGMP_HOST_MEMBERSHIP_QUERY:
1031 err = br_multicast_query(br, port, skb2);
1032 break;
1033 case IGMP_HOST_LEAVE_MESSAGE:
1034 br_multicast_leave_group(br, port, ih->group);
1035 break;
1036 }
1037
1038out:
1039 __skb_push(skb2, offset);
1040err_out:
1041 if (skb2 != skb)
1042 kfree_skb(skb2);
1043 return err;
1044}
1045
1046int br_multicast_rcv(struct net_bridge *br, struct net_bridge_port *port,
1047 struct sk_buff *skb)
1048{
1049 BR_INPUT_SKB_CB(skb)->igmp = 0;
1050 BR_INPUT_SKB_CB(skb)->mrouters_only = 0;
1051
1052 if (br->multicast_disabled)
1053 return 0;
1054
1055 switch (skb->protocol) {
1056 case htons(ETH_P_IP):
1057 return br_multicast_ipv4_rcv(br, port, skb);
1058 }
1059
1060 return 0;
1061}
1062
1063static void br_multicast_query_expired(unsigned long data)
1064{
1065 struct net_bridge *br = (void *)data;
1066
1067 spin_lock(&br->multicast_lock);
1068 if (br->multicast_startup_queries_sent <
1069 br->multicast_startup_query_count)
1070 br->multicast_startup_queries_sent++;
1071
1072 br_multicast_send_query(br, NULL, br->multicast_startup_queries_sent);
1073
1074 spin_unlock(&br->multicast_lock);
1075}
1076
1077void br_multicast_init(struct net_bridge *br)
1078{
1079 br->hash_elasticity = 4;
1080 br->hash_max = 512;
1081
1082 br->multicast_router = 1;
1083 br->multicast_last_member_count = 2;
1084 br->multicast_startup_query_count = 2;
1085
1086 br->multicast_last_member_interval = HZ;
1087 br->multicast_query_response_interval = 10 * HZ;
1088 br->multicast_startup_query_interval = 125 * HZ / 4;
1089 br->multicast_query_interval = 125 * HZ;
1090 br->multicast_querier_interval = 255 * HZ;
1091 br->multicast_membership_interval = 260 * HZ;
1092
1093 spin_lock_init(&br->multicast_lock);
1094 setup_timer(&br->multicast_router_timer,
1095 br_multicast_local_router_expired, 0);
1096 setup_timer(&br->multicast_querier_timer,
1097 br_multicast_local_router_expired, 0);
1098 setup_timer(&br->multicast_query_timer, br_multicast_query_expired,
1099 (unsigned long)br);
1100}
1101
1102void br_multicast_open(struct net_bridge *br)
1103{
1104 br->multicast_startup_queries_sent = 0;
1105
1106 if (br->multicast_disabled)
1107 return;
1108
1109 mod_timer(&br->multicast_query_timer, jiffies);
1110}
1111
1112void br_multicast_stop(struct net_bridge *br)
1113{
1114 struct net_bridge_mdb_htable *mdb;
1115 struct net_bridge_mdb_entry *mp;
1116 struct hlist_node *p, *n;
1117 u32 ver;
1118 int i;
1119
1120 del_timer_sync(&br->multicast_router_timer);
1121 del_timer_sync(&br->multicast_querier_timer);
1122 del_timer_sync(&br->multicast_query_timer);
1123
1124 spin_lock_bh(&br->multicast_lock);
1125 mdb = br->mdb;
1126 if (!mdb)
1127 goto out;
1128
1129 br->mdb = NULL;
1130
1131 ver = mdb->ver;
1132 for (i = 0; i < mdb->max; i++) {
1133 hlist_for_each_entry_safe(mp, p, n, &mdb->mhash[i],
1134 hlist[ver]) {
1135 del_timer(&mp->timer);
1136 del_timer(&mp->query_timer);
1137 call_rcu_bh(&mp->rcu, br_multicast_free_group);
1138 }
1139 }
1140
1141 if (mdb->old) {
1142 spin_unlock_bh(&br->multicast_lock);
1143 rcu_barrier_bh();
1144 spin_lock_bh(&br->multicast_lock);
1145 WARN_ON(mdb->old);
1146 }
1147
1148 mdb->old = mdb;
1149 call_rcu_bh(&mdb->rcu, br_mdb_free);
1150
1151out:
1152 spin_unlock_bh(&br->multicast_lock);
1153}
1154
1155int br_multicast_set_router(struct net_bridge *br, unsigned long val)
1156{
1157 int err = -ENOENT;
1158
1159 spin_lock_bh(&br->multicast_lock);
1160 if (!netif_running(br->dev))
1161 goto unlock;
1162
1163 switch (val) {
1164 case 0:
1165 case 2:
1166 del_timer(&br->multicast_router_timer);
1167 /* fall through */
1168 case 1:
1169 br->multicast_router = val;
1170 err = 0;
1171 break;
1172
1173 default:
1174 err = -EINVAL;
1175 break;
1176 }
1177
1178unlock:
1179 spin_unlock_bh(&br->multicast_lock);
1180
1181 return err;
1182}
1183
1184int br_multicast_set_port_router(struct net_bridge_port *p, unsigned long val)
1185{
1186 struct net_bridge *br = p->br;
1187 int err = -ENOENT;
1188
1189 spin_lock(&br->multicast_lock);
1190 if (!netif_running(br->dev) || p->state == BR_STATE_DISABLED)
1191 goto unlock;
1192
1193 switch (val) {
1194 case 0:
1195 case 1:
1196 case 2:
1197 p->multicast_router = val;
1198 err = 0;
1199
1200 if (val < 2 && !hlist_unhashed(&p->rlist))
1201 hlist_del_init_rcu(&p->rlist);
1202
1203 if (val == 1)
1204 break;
1205
1206 del_timer(&p->multicast_router_timer);
1207
1208 if (val == 0)
1209 break;
1210
1211 br_multicast_add_router(br, p);
1212 break;
1213
1214 default:
1215 err = -EINVAL;
1216 break;
1217 }
1218
1219unlock:
1220 spin_unlock(&br->multicast_lock);
1221
1222 return err;
1223}
1224
1225int br_multicast_toggle(struct net_bridge *br, unsigned long val)
1226{
1227 struct net_bridge_port *port;
1228 int err = -ENOENT;
1229
1230 spin_lock(&br->multicast_lock);
1231 if (!netif_running(br->dev))
1232 goto unlock;
1233
1234 err = 0;
1235 if (br->multicast_disabled == !val)
1236 goto unlock;
1237
1238 br->multicast_disabled = !val;
1239 if (br->multicast_disabled)
1240 goto unlock;
1241
1242 if (br->mdb) {
1243 if (br->mdb->old) {
1244 err = -EEXIST;
1245rollback:
1246 br->multicast_disabled = !!val;
1247 goto unlock;
1248 }
1249
1250 err = br_mdb_rehash(&br->mdb, br->mdb->max,
1251 br->hash_elasticity);
1252 if (err)
1253 goto rollback;
1254 }
1255
1256 br_multicast_open(br);
1257 list_for_each_entry(port, &br->port_list, list) {
1258 if (port->state == BR_STATE_DISABLED ||
1259 port->state == BR_STATE_BLOCKING)
1260 continue;
1261
1262 __br_multicast_enable_port(port);
1263 }
1264
1265unlock:
1266 spin_unlock(&br->multicast_lock);
1267
1268 return err;
1269}
1270
1271int br_multicast_set_hash_max(struct net_bridge *br, unsigned long val)
1272{
1273 int err = -ENOENT;
1274 u32 old;
1275
1276 spin_lock(&br->multicast_lock);
1277 if (!netif_running(br->dev))
1278 goto unlock;
1279
1280 err = -EINVAL;
1281 if (!is_power_of_2(val))
1282 goto unlock;
1283 if (br->mdb && val < br->mdb->size)
1284 goto unlock;
1285
1286 err = 0;
1287
1288 old = br->hash_max;
1289 br->hash_max = val;
1290
1291 if (br->mdb) {
1292 if (br->mdb->old) {
1293 err = -EEXIST;
1294rollback:
1295 br->hash_max = old;
1296 goto unlock;
1297 }
1298
1299 err = br_mdb_rehash(&br->mdb, br->hash_max,
1300 br->hash_elasticity);
1301 if (err)
1302 goto rollback;
1303 }
1304
1305unlock:
1306 spin_unlock(&br->multicast_lock);
1307
1308 return err;
1309}
diff --git a/net/bridge/br_netfilter.c b/net/bridge/br_netfilter.c
index a16a2342f6bf..4c4977d12fd6 100644
--- a/net/bridge/br_netfilter.c
+++ b/net/bridge/br_netfilter.c
@@ -23,6 +23,7 @@
23 23
24#include <linux/module.h> 24#include <linux/module.h>
25#include <linux/kernel.h> 25#include <linux/kernel.h>
26#include <linux/slab.h>
26#include <linux/ip.h> 27#include <linux/ip.h>
27#include <linux/netdevice.h> 28#include <linux/netdevice.h>
28#include <linux/skbuff.h> 29#include <linux/skbuff.h>
@@ -1013,12 +1014,12 @@ static ctl_table brnf_table[] = {
1013 .mode = 0644, 1014 .mode = 0644,
1014 .proc_handler = brnf_sysctl_call_tables, 1015 .proc_handler = brnf_sysctl_call_tables,
1015 }, 1016 },
1016 { .ctl_name = 0 } 1017 { }
1017}; 1018};
1018 1019
1019static struct ctl_path brnf_path[] = { 1020static struct ctl_path brnf_path[] = {
1020 { .procname = "net", .ctl_name = CTL_NET, }, 1021 { .procname = "net", },
1021 { .procname = "bridge", .ctl_name = NET_BRIDGE, }, 1022 { .procname = "bridge", },
1022 { } 1023 { }
1023}; 1024};
1024#endif 1025#endif
diff --git a/net/bridge/br_netlink.c b/net/bridge/br_netlink.c
index fcffb3fb1177..aa56ac2c8829 100644
--- a/net/bridge/br_netlink.c
+++ b/net/bridge/br_netlink.c
@@ -11,6 +11,7 @@
11 */ 11 */
12 12
13#include <linux/kernel.h> 13#include <linux/kernel.h>
14#include <linux/slab.h>
14#include <net/rtnetlink.h> 15#include <net/rtnetlink.h>
15#include <net/net_namespace.h> 16#include <net/net_namespace.h>
16#include <net/sock.h> 17#include <net/sock.h>
diff --git a/net/bridge/br_private.h b/net/bridge/br_private.h
index 2114e45682ea..846d7d1e2075 100644
--- a/net/bridge/br_private.h
+++ b/net/bridge/br_private.h
@@ -57,6 +57,41 @@ struct net_bridge_fdb_entry
57 unsigned char is_static; 57 unsigned char is_static;
58}; 58};
59 59
60struct net_bridge_port_group {
61 struct net_bridge_port *port;
62 struct net_bridge_port_group *next;
63 struct hlist_node mglist;
64 struct rcu_head rcu;
65 struct timer_list timer;
66 struct timer_list query_timer;
67 __be32 addr;
68 u32 queries_sent;
69};
70
71struct net_bridge_mdb_entry
72{
73 struct hlist_node hlist[2];
74 struct hlist_node mglist;
75 struct net_bridge *br;
76 struct net_bridge_port_group *ports;
77 struct rcu_head rcu;
78 struct timer_list timer;
79 struct timer_list query_timer;
80 __be32 addr;
81 u32 queries_sent;
82};
83
84struct net_bridge_mdb_htable
85{
86 struct hlist_head *mhash;
87 struct rcu_head rcu;
88 struct net_bridge_mdb_htable *old;
89 u32 size;
90 u32 max;
91 u32 secret;
92 u32 ver;
93};
94
60struct net_bridge_port 95struct net_bridge_port
61{ 96{
62 struct net_bridge *br; 97 struct net_bridge *br;
@@ -84,6 +119,15 @@ struct net_bridge_port
84 119
85 unsigned long flags; 120 unsigned long flags;
86#define BR_HAIRPIN_MODE 0x00000001 121#define BR_HAIRPIN_MODE 0x00000001
122
123#ifdef CONFIG_BRIDGE_IGMP_SNOOPING
124 u32 multicast_startup_queries_sent;
125 unsigned char multicast_router;
126 struct timer_list multicast_router_timer;
127 struct timer_list multicast_query_timer;
128 struct hlist_head mglist;
129 struct hlist_node rlist;
130#endif
87}; 131};
88 132
89struct net_bridge 133struct net_bridge
@@ -93,7 +137,6 @@ struct net_bridge
93 struct net_device *dev; 137 struct net_device *dev;
94 spinlock_t hash_lock; 138 spinlock_t hash_lock;
95 struct hlist_head hash[BR_HASH_SIZE]; 139 struct hlist_head hash[BR_HASH_SIZE];
96 struct list_head age_list;
97 unsigned long feature_mask; 140 unsigned long feature_mask;
98#ifdef CONFIG_BRIDGE_NETFILTER 141#ifdef CONFIG_BRIDGE_NETFILTER
99 struct rtable fake_rtable; 142 struct rtable fake_rtable;
@@ -125,6 +168,35 @@ struct net_bridge
125 unsigned char topology_change; 168 unsigned char topology_change;
126 unsigned char topology_change_detected; 169 unsigned char topology_change_detected;
127 170
171#ifdef CONFIG_BRIDGE_IGMP_SNOOPING
172 unsigned char multicast_router;
173
174 u8 multicast_disabled:1;
175
176 u32 hash_elasticity;
177 u32 hash_max;
178
179 u32 multicast_last_member_count;
180 u32 multicast_startup_queries_sent;
181 u32 multicast_startup_query_count;
182
183 unsigned long multicast_last_member_interval;
184 unsigned long multicast_membership_interval;
185 unsigned long multicast_querier_interval;
186 unsigned long multicast_query_interval;
187 unsigned long multicast_query_response_interval;
188 unsigned long multicast_startup_query_interval;
189
190 spinlock_t multicast_lock;
191 struct net_bridge_mdb_htable *mdb;
192 struct hlist_head router_list;
193 struct hlist_head mglist;
194
195 struct timer_list multicast_router_timer;
196 struct timer_list multicast_querier_timer;
197 struct timer_list multicast_query_timer;
198#endif
199
128 struct timer_list hello_timer; 200 struct timer_list hello_timer;
129 struct timer_list tcn_timer; 201 struct timer_list tcn_timer;
130 struct timer_list topology_change_timer; 202 struct timer_list topology_change_timer;
@@ -132,6 +204,22 @@ struct net_bridge
132 struct kobject *ifobj; 204 struct kobject *ifobj;
133}; 205};
134 206
207struct br_input_skb_cb {
208 struct net_device *brdev;
209#ifdef CONFIG_BRIDGE_IGMP_SNOOPING
210 int igmp;
211 int mrouters_only;
212#endif
213};
214
215#define BR_INPUT_SKB_CB(__skb) ((struct br_input_skb_cb *)(__skb)->cb)
216
217#ifdef CONFIG_BRIDGE_IGMP_SNOOPING
218# define BR_INPUT_SKB_CB_MROUTERS_ONLY(__skb) (BR_INPUT_SKB_CB(__skb)->mrouters_only)
219#else
220# define BR_INPUT_SKB_CB_MROUTERS_ONLY(__skb) (0)
221#endif
222
135extern struct notifier_block br_device_notifier; 223extern struct notifier_block br_device_notifier;
136extern const u8 br_group_address[ETH_ALEN]; 224extern const u8 br_group_address[ETH_ALEN];
137 225
@@ -172,10 +260,11 @@ extern void br_deliver(const struct net_bridge_port *to,
172 struct sk_buff *skb); 260 struct sk_buff *skb);
173extern int br_dev_queue_push_xmit(struct sk_buff *skb); 261extern int br_dev_queue_push_xmit(struct sk_buff *skb);
174extern void br_forward(const struct net_bridge_port *to, 262extern void br_forward(const struct net_bridge_port *to,
175 struct sk_buff *skb); 263 struct sk_buff *skb, struct sk_buff *skb0);
176extern int br_forward_finish(struct sk_buff *skb); 264extern int br_forward_finish(struct sk_buff *skb);
177extern void br_flood_deliver(struct net_bridge *br, struct sk_buff *skb); 265extern void br_flood_deliver(struct net_bridge *br, struct sk_buff *skb);
178extern void br_flood_forward(struct net_bridge *br, struct sk_buff *skb); 266extern void br_flood_forward(struct net_bridge *br, struct sk_buff *skb,
267 struct sk_buff *skb2);
179 268
180/* br_if.c */ 269/* br_if.c */
181extern void br_port_carrier_check(struct net_bridge_port *p); 270extern void br_port_carrier_check(struct net_bridge_port *p);
@@ -198,6 +287,94 @@ extern struct sk_buff *br_handle_frame(struct net_bridge_port *p,
198extern int br_dev_ioctl(struct net_device *dev, struct ifreq *rq, int cmd); 287extern int br_dev_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
199extern int br_ioctl_deviceless_stub(struct net *net, unsigned int cmd, void __user *arg); 288extern int br_ioctl_deviceless_stub(struct net *net, unsigned int cmd, void __user *arg);
200 289
290/* br_multicast.c */
291#ifdef CONFIG_BRIDGE_IGMP_SNOOPING
292extern int br_multicast_rcv(struct net_bridge *br,
293 struct net_bridge_port *port,
294 struct sk_buff *skb);
295extern struct net_bridge_mdb_entry *br_mdb_get(struct net_bridge *br,
296 struct sk_buff *skb);
297extern void br_multicast_add_port(struct net_bridge_port *port);
298extern void br_multicast_del_port(struct net_bridge_port *port);
299extern void br_multicast_enable_port(struct net_bridge_port *port);
300extern void br_multicast_disable_port(struct net_bridge_port *port);
301extern void br_multicast_init(struct net_bridge *br);
302extern void br_multicast_open(struct net_bridge *br);
303extern void br_multicast_stop(struct net_bridge *br);
304extern void br_multicast_deliver(struct net_bridge_mdb_entry *mdst,
305 struct sk_buff *skb);
306extern void br_multicast_forward(struct net_bridge_mdb_entry *mdst,
307 struct sk_buff *skb, struct sk_buff *skb2);
308extern int br_multicast_set_router(struct net_bridge *br, unsigned long val);
309extern int br_multicast_set_port_router(struct net_bridge_port *p,
310 unsigned long val);
311extern int br_multicast_toggle(struct net_bridge *br, unsigned long val);
312extern int br_multicast_set_hash_max(struct net_bridge *br, unsigned long val);
313
314static inline bool br_multicast_is_router(struct net_bridge *br)
315{
316 return br->multicast_router == 2 ||
317 (br->multicast_router == 1 &&
318 timer_pending(&br->multicast_router_timer));
319}
320#else
321static inline int br_multicast_rcv(struct net_bridge *br,
322 struct net_bridge_port *port,
323 struct sk_buff *skb)
324{
325 return 0;
326}
327
328static inline struct net_bridge_mdb_entry *br_mdb_get(struct net_bridge *br,
329 struct sk_buff *skb)
330{
331 return NULL;
332}
333
334static inline void br_multicast_add_port(struct net_bridge_port *port)
335{
336}
337
338static inline void br_multicast_del_port(struct net_bridge_port *port)
339{
340}
341
342static inline void br_multicast_enable_port(struct net_bridge_port *port)
343{
344}
345
346static inline void br_multicast_disable_port(struct net_bridge_port *port)
347{
348}
349
350static inline void br_multicast_init(struct net_bridge *br)
351{
352}
353
354static inline void br_multicast_open(struct net_bridge *br)
355{
356}
357
358static inline void br_multicast_stop(struct net_bridge *br)
359{
360}
361
362static inline void br_multicast_deliver(struct net_bridge_mdb_entry *mdst,
363 struct sk_buff *skb)
364{
365}
366
367static inline void br_multicast_forward(struct net_bridge_mdb_entry *mdst,
368 struct sk_buff *skb,
369 struct sk_buff *skb2)
370{
371}
372static inline bool br_multicast_is_router(struct net_bridge *br)
373{
374 return 0;
375}
376#endif
377
201/* br_netfilter.c */ 378/* br_netfilter.c */
202#ifdef CONFIG_BRIDGE_NETFILTER 379#ifdef CONFIG_BRIDGE_NETFILTER
203extern int br_netfilter_init(void); 380extern int br_netfilter_init(void);
@@ -254,7 +431,7 @@ extern void br_ifinfo_notify(int event, struct net_bridge_port *port);
254 431
255#ifdef CONFIG_SYSFS 432#ifdef CONFIG_SYSFS
256/* br_sysfs_if.c */ 433/* br_sysfs_if.c */
257extern struct sysfs_ops brport_sysfs_ops; 434extern const struct sysfs_ops brport_sysfs_ops;
258extern int br_sysfs_addif(struct net_bridge_port *p); 435extern int br_sysfs_addif(struct net_bridge_port *p);
259 436
260/* br_sysfs_br.c */ 437/* br_sysfs_br.c */
diff --git a/net/bridge/br_stp.c b/net/bridge/br_stp.c
index fd3f8d6c0998..edcf14b560f6 100644
--- a/net/bridge/br_stp.c
+++ b/net/bridge/br_stp.c
@@ -386,6 +386,8 @@ static void br_make_forwarding(struct net_bridge_port *p)
386 else 386 else
387 p->state = BR_STATE_LEARNING; 387 p->state = BR_STATE_LEARNING;
388 388
389 br_multicast_enable_port(p);
390
389 br_log_state(p); 391 br_log_state(p);
390 392
391 if (br->forward_delay != 0) 393 if (br->forward_delay != 0)
diff --git a/net/bridge/br_stp_bpdu.c b/net/bridge/br_stp_bpdu.c
index 81ae40b3f655..d66cce11f3bf 100644
--- a/net/bridge/br_stp_bpdu.c
+++ b/net/bridge/br_stp_bpdu.c
@@ -15,6 +15,7 @@
15#include <linux/netfilter_bridge.h> 15#include <linux/netfilter_bridge.h>
16#include <linux/etherdevice.h> 16#include <linux/etherdevice.h>
17#include <linux/llc.h> 17#include <linux/llc.h>
18#include <linux/slab.h>
18#include <net/net_namespace.h> 19#include <net/net_namespace.h>
19#include <net/llc.h> 20#include <net/llc.h>
20#include <net/llc_pdu.h> 21#include <net/llc_pdu.h>
diff --git a/net/bridge/br_stp_if.c b/net/bridge/br_stp_if.c
index 9a52ac5b4525..d527119e9f54 100644
--- a/net/bridge/br_stp_if.c
+++ b/net/bridge/br_stp_if.c
@@ -108,6 +108,7 @@ void br_stp_disable_port(struct net_bridge_port *p)
108 del_timer(&p->hold_timer); 108 del_timer(&p->hold_timer);
109 109
110 br_fdb_delete_by_port(br, p, 0); 110 br_fdb_delete_by_port(br, p, 0);
111 br_multicast_disable_port(p);
111 112
112 br_configuration_update(br); 113 br_configuration_update(br);
113 114
diff --git a/net/bridge/br_sysfs_br.c b/net/bridge/br_sysfs_br.c
index ee4820aa1843..dd321e39e621 100644
--- a/net/bridge/br_sysfs_br.c
+++ b/net/bridge/br_sysfs_br.c
@@ -316,9 +316,9 @@ static ssize_t store_group_addr(struct device *d,
316 if (new_addr[5] & ~0xf) 316 if (new_addr[5] & ~0xf)
317 return -EINVAL; 317 return -EINVAL;
318 318
319 if (new_addr[5] == 1 /* 802.3x Pause address */ 319 if (new_addr[5] == 1 || /* 802.3x Pause address */
320 || new_addr[5] == 2 /* 802.3ad Slow protocols */ 320 new_addr[5] == 2 || /* 802.3ad Slow protocols */
321 || new_addr[5] == 3) /* 802.1X PAE address */ 321 new_addr[5] == 3) /* 802.1X PAE address */
322 return -EINVAL; 322 return -EINVAL;
323 323
324 spin_lock_bh(&br->lock); 324 spin_lock_bh(&br->lock);
@@ -345,6 +345,273 @@ static ssize_t store_flush(struct device *d,
345} 345}
346static DEVICE_ATTR(flush, S_IWUSR, NULL, store_flush); 346static DEVICE_ATTR(flush, S_IWUSR, NULL, store_flush);
347 347
348#ifdef CONFIG_BRIDGE_IGMP_SNOOPING
349static ssize_t show_multicast_router(struct device *d,
350 struct device_attribute *attr, char *buf)
351{
352 struct net_bridge *br = to_bridge(d);
353 return sprintf(buf, "%d\n", br->multicast_router);
354}
355
356static ssize_t store_multicast_router(struct device *d,
357 struct device_attribute *attr,
358 const char *buf, size_t len)
359{
360 return store_bridge_parm(d, buf, len, br_multicast_set_router);
361}
362static DEVICE_ATTR(multicast_router, S_IRUGO | S_IWUSR, show_multicast_router,
363 store_multicast_router);
364
365static ssize_t show_multicast_snooping(struct device *d,
366 struct device_attribute *attr,
367 char *buf)
368{
369 struct net_bridge *br = to_bridge(d);
370 return sprintf(buf, "%d\n", !br->multicast_disabled);
371}
372
373static ssize_t store_multicast_snooping(struct device *d,
374 struct device_attribute *attr,
375 const char *buf, size_t len)
376{
377 return store_bridge_parm(d, buf, len, br_multicast_toggle);
378}
379static DEVICE_ATTR(multicast_snooping, S_IRUGO | S_IWUSR,
380 show_multicast_snooping, store_multicast_snooping);
381
382static ssize_t show_hash_elasticity(struct device *d,
383 struct device_attribute *attr, char *buf)
384{
385 struct net_bridge *br = to_bridge(d);
386 return sprintf(buf, "%u\n", br->hash_elasticity);
387}
388
389static int set_elasticity(struct net_bridge *br, unsigned long val)
390{
391 br->hash_elasticity = val;
392 return 0;
393}
394
395static ssize_t store_hash_elasticity(struct device *d,
396 struct device_attribute *attr,
397 const char *buf, size_t len)
398{
399 return store_bridge_parm(d, buf, len, set_elasticity);
400}
401static DEVICE_ATTR(hash_elasticity, S_IRUGO | S_IWUSR, show_hash_elasticity,
402 store_hash_elasticity);
403
404static ssize_t show_hash_max(struct device *d, struct device_attribute *attr,
405 char *buf)
406{
407 struct net_bridge *br = to_bridge(d);
408 return sprintf(buf, "%u\n", br->hash_max);
409}
410
411static ssize_t store_hash_max(struct device *d, struct device_attribute *attr,
412 const char *buf, size_t len)
413{
414 return store_bridge_parm(d, buf, len, br_multicast_set_hash_max);
415}
416static DEVICE_ATTR(hash_max, S_IRUGO | S_IWUSR, show_hash_max,
417 store_hash_max);
418
419static ssize_t show_multicast_last_member_count(struct device *d,
420 struct device_attribute *attr,
421 char *buf)
422{
423 struct net_bridge *br = to_bridge(d);
424 return sprintf(buf, "%u\n", br->multicast_last_member_count);
425}
426
427static int set_last_member_count(struct net_bridge *br, unsigned long val)
428{
429 br->multicast_last_member_count = val;
430 return 0;
431}
432
433static ssize_t store_multicast_last_member_count(struct device *d,
434 struct device_attribute *attr,
435 const char *buf, size_t len)
436{
437 return store_bridge_parm(d, buf, len, set_last_member_count);
438}
439static DEVICE_ATTR(multicast_last_member_count, S_IRUGO | S_IWUSR,
440 show_multicast_last_member_count,
441 store_multicast_last_member_count);
442
443static ssize_t show_multicast_startup_query_count(
444 struct device *d, struct device_attribute *attr, char *buf)
445{
446 struct net_bridge *br = to_bridge(d);
447 return sprintf(buf, "%u\n", br->multicast_startup_query_count);
448}
449
450static int set_startup_query_count(struct net_bridge *br, unsigned long val)
451{
452 br->multicast_startup_query_count = val;
453 return 0;
454}
455
456static ssize_t store_multicast_startup_query_count(
457 struct device *d, struct device_attribute *attr, const char *buf,
458 size_t len)
459{
460 return store_bridge_parm(d, buf, len, set_startup_query_count);
461}
462static DEVICE_ATTR(multicast_startup_query_count, S_IRUGO | S_IWUSR,
463 show_multicast_startup_query_count,
464 store_multicast_startup_query_count);
465
466static ssize_t show_multicast_last_member_interval(
467 struct device *d, struct device_attribute *attr, char *buf)
468{
469 struct net_bridge *br = to_bridge(d);
470 return sprintf(buf, "%lu\n",
471 jiffies_to_clock_t(br->multicast_last_member_interval));
472}
473
474static int set_last_member_interval(struct net_bridge *br, unsigned long val)
475{
476 br->multicast_last_member_interval = clock_t_to_jiffies(val);
477 return 0;
478}
479
480static ssize_t store_multicast_last_member_interval(
481 struct device *d, struct device_attribute *attr, const char *buf,
482 size_t len)
483{
484 return store_bridge_parm(d, buf, len, set_last_member_interval);
485}
486static DEVICE_ATTR(multicast_last_member_interval, S_IRUGO | S_IWUSR,
487 show_multicast_last_member_interval,
488 store_multicast_last_member_interval);
489
490static ssize_t show_multicast_membership_interval(
491 struct device *d, struct device_attribute *attr, char *buf)
492{
493 struct net_bridge *br = to_bridge(d);
494 return sprintf(buf, "%lu\n",
495 jiffies_to_clock_t(br->multicast_membership_interval));
496}
497
498static int set_membership_interval(struct net_bridge *br, unsigned long val)
499{
500 br->multicast_membership_interval = clock_t_to_jiffies(val);
501 return 0;
502}
503
504static ssize_t store_multicast_membership_interval(
505 struct device *d, struct device_attribute *attr, const char *buf,
506 size_t len)
507{
508 return store_bridge_parm(d, buf, len, set_membership_interval);
509}
510static DEVICE_ATTR(multicast_membership_interval, S_IRUGO | S_IWUSR,
511 show_multicast_membership_interval,
512 store_multicast_membership_interval);
513
514static ssize_t show_multicast_querier_interval(struct device *d,
515 struct device_attribute *attr,
516 char *buf)
517{
518 struct net_bridge *br = to_bridge(d);
519 return sprintf(buf, "%lu\n",
520 jiffies_to_clock_t(br->multicast_querier_interval));
521}
522
523static int set_querier_interval(struct net_bridge *br, unsigned long val)
524{
525 br->multicast_querier_interval = clock_t_to_jiffies(val);
526 return 0;
527}
528
529static ssize_t store_multicast_querier_interval(struct device *d,
530 struct device_attribute *attr,
531 const char *buf, size_t len)
532{
533 return store_bridge_parm(d, buf, len, set_querier_interval);
534}
535static DEVICE_ATTR(multicast_querier_interval, S_IRUGO | S_IWUSR,
536 show_multicast_querier_interval,
537 store_multicast_querier_interval);
538
539static ssize_t show_multicast_query_interval(struct device *d,
540 struct device_attribute *attr,
541 char *buf)
542{
543 struct net_bridge *br = to_bridge(d);
544 return sprintf(buf, "%lu\n",
545 jiffies_to_clock_t(br->multicast_query_interval));
546}
547
548static int set_query_interval(struct net_bridge *br, unsigned long val)
549{
550 br->multicast_query_interval = clock_t_to_jiffies(val);
551 return 0;
552}
553
554static ssize_t store_multicast_query_interval(struct device *d,
555 struct device_attribute *attr,
556 const char *buf, size_t len)
557{
558 return store_bridge_parm(d, buf, len, set_query_interval);
559}
560static DEVICE_ATTR(multicast_query_interval, S_IRUGO | S_IWUSR,
561 show_multicast_query_interval,
562 store_multicast_query_interval);
563
564static ssize_t show_multicast_query_response_interval(
565 struct device *d, struct device_attribute *attr, char *buf)
566{
567 struct net_bridge *br = to_bridge(d);
568 return sprintf(
569 buf, "%lu\n",
570 jiffies_to_clock_t(br->multicast_query_response_interval));
571}
572
573static int set_query_response_interval(struct net_bridge *br, unsigned long val)
574{
575 br->multicast_query_response_interval = clock_t_to_jiffies(val);
576 return 0;
577}
578
579static ssize_t store_multicast_query_response_interval(
580 struct device *d, struct device_attribute *attr, const char *buf,
581 size_t len)
582{
583 return store_bridge_parm(d, buf, len, set_query_response_interval);
584}
585static DEVICE_ATTR(multicast_query_response_interval, S_IRUGO | S_IWUSR,
586 show_multicast_query_response_interval,
587 store_multicast_query_response_interval);
588
589static ssize_t show_multicast_startup_query_interval(
590 struct device *d, struct device_attribute *attr, char *buf)
591{
592 struct net_bridge *br = to_bridge(d);
593 return sprintf(
594 buf, "%lu\n",
595 jiffies_to_clock_t(br->multicast_startup_query_interval));
596}
597
598static int set_startup_query_interval(struct net_bridge *br, unsigned long val)
599{
600 br->multicast_startup_query_interval = clock_t_to_jiffies(val);
601 return 0;
602}
603
604static ssize_t store_multicast_startup_query_interval(
605 struct device *d, struct device_attribute *attr, const char *buf,
606 size_t len)
607{
608 return store_bridge_parm(d, buf, len, set_startup_query_interval);
609}
610static DEVICE_ATTR(multicast_startup_query_interval, S_IRUGO | S_IWUSR,
611 show_multicast_startup_query_interval,
612 store_multicast_startup_query_interval);
613#endif
614
348static struct attribute *bridge_attrs[] = { 615static struct attribute *bridge_attrs[] = {
349 &dev_attr_forward_delay.attr, 616 &dev_attr_forward_delay.attr,
350 &dev_attr_hello_time.attr, 617 &dev_attr_hello_time.attr,
@@ -364,6 +631,20 @@ static struct attribute *bridge_attrs[] = {
364 &dev_attr_gc_timer.attr, 631 &dev_attr_gc_timer.attr,
365 &dev_attr_group_addr.attr, 632 &dev_attr_group_addr.attr,
366 &dev_attr_flush.attr, 633 &dev_attr_flush.attr,
634#ifdef CONFIG_BRIDGE_IGMP_SNOOPING
635 &dev_attr_multicast_router.attr,
636 &dev_attr_multicast_snooping.attr,
637 &dev_attr_hash_elasticity.attr,
638 &dev_attr_hash_max.attr,
639 &dev_attr_multicast_last_member_count.attr,
640 &dev_attr_multicast_startup_query_count.attr,
641 &dev_attr_multicast_last_member_interval.attr,
642 &dev_attr_multicast_membership_interval.attr,
643 &dev_attr_multicast_querier_interval.attr,
644 &dev_attr_multicast_query_interval.attr,
645 &dev_attr_multicast_query_response_interval.attr,
646 &dev_attr_multicast_startup_query_interval.attr,
647#endif
367 NULL 648 NULL
368}; 649};
369 650
diff --git a/net/bridge/br_sysfs_if.c b/net/bridge/br_sysfs_if.c
index 820643a3ba9c..0b9916489d6b 100644
--- a/net/bridge/br_sysfs_if.c
+++ b/net/bridge/br_sysfs_if.c
@@ -159,6 +159,21 @@ static ssize_t store_hairpin_mode(struct net_bridge_port *p, unsigned long v)
159static BRPORT_ATTR(hairpin_mode, S_IRUGO | S_IWUSR, 159static BRPORT_ATTR(hairpin_mode, S_IRUGO | S_IWUSR,
160 show_hairpin_mode, store_hairpin_mode); 160 show_hairpin_mode, store_hairpin_mode);
161 161
162#ifdef CONFIG_BRIDGE_IGMP_SNOOPING
163static ssize_t show_multicast_router(struct net_bridge_port *p, char *buf)
164{
165 return sprintf(buf, "%d\n", p->multicast_router);
166}
167
168static ssize_t store_multicast_router(struct net_bridge_port *p,
169 unsigned long v)
170{
171 return br_multicast_set_port_router(p, v);
172}
173static BRPORT_ATTR(multicast_router, S_IRUGO | S_IWUSR, show_multicast_router,
174 store_multicast_router);
175#endif
176
162static struct brport_attribute *brport_attrs[] = { 177static struct brport_attribute *brport_attrs[] = {
163 &brport_attr_path_cost, 178 &brport_attr_path_cost,
164 &brport_attr_priority, 179 &brport_attr_priority,
@@ -176,6 +191,9 @@ static struct brport_attribute *brport_attrs[] = {
176 &brport_attr_hold_timer, 191 &brport_attr_hold_timer,
177 &brport_attr_flush, 192 &brport_attr_flush,
178 &brport_attr_hairpin_mode, 193 &brport_attr_hairpin_mode,
194#ifdef CONFIG_BRIDGE_IGMP_SNOOPING
195 &brport_attr_multicast_router,
196#endif
179 NULL 197 NULL
180}; 198};
181 199
@@ -220,7 +238,7 @@ static ssize_t brport_store(struct kobject * kobj,
220 return ret; 238 return ret;
221} 239}
222 240
223struct sysfs_ops brport_sysfs_ops = { 241const struct sysfs_ops brport_sysfs_ops = {
224 .show = brport_show, 242 .show = brport_show,
225 .store = brport_store, 243 .store = brport_store,
226}; 244};
diff --git a/net/bridge/netfilter/ebt_802_3.c b/net/bridge/netfilter/ebt_802_3.c
index bd91dc58d49b..5d1176758ca5 100644
--- a/net/bridge/netfilter/ebt_802_3.c
+++ b/net/bridge/netfilter/ebt_802_3.c
@@ -52,7 +52,7 @@ static struct xt_match ebt_802_3_mt_reg __read_mostly = {
52 .family = NFPROTO_BRIDGE, 52 .family = NFPROTO_BRIDGE,
53 .match = ebt_802_3_mt, 53 .match = ebt_802_3_mt,
54 .checkentry = ebt_802_3_mt_check, 54 .checkentry = ebt_802_3_mt_check,
55 .matchsize = XT_ALIGN(sizeof(struct ebt_802_3_info)), 55 .matchsize = sizeof(struct ebt_802_3_info),
56 .me = THIS_MODULE, 56 .me = THIS_MODULE,
57}; 57};
58 58
diff --git a/net/bridge/netfilter/ebt_arp.c b/net/bridge/netfilter/ebt_arp.c
index b7ad60419f9a..e727697c5847 100644
--- a/net/bridge/netfilter/ebt_arp.c
+++ b/net/bridge/netfilter/ebt_arp.c
@@ -120,7 +120,7 @@ static struct xt_match ebt_arp_mt_reg __read_mostly = {
120 .family = NFPROTO_BRIDGE, 120 .family = NFPROTO_BRIDGE,
121 .match = ebt_arp_mt, 121 .match = ebt_arp_mt,
122 .checkentry = ebt_arp_mt_check, 122 .checkentry = ebt_arp_mt_check,
123 .matchsize = XT_ALIGN(sizeof(struct ebt_arp_info)), 123 .matchsize = sizeof(struct ebt_arp_info),
124 .me = THIS_MODULE, 124 .me = THIS_MODULE,
125}; 125};
126 126
diff --git a/net/bridge/netfilter/ebt_arpreply.c b/net/bridge/netfilter/ebt_arpreply.c
index 76584cd72e57..f392e9d93f53 100644
--- a/net/bridge/netfilter/ebt_arpreply.c
+++ b/net/bridge/netfilter/ebt_arpreply.c
@@ -78,7 +78,7 @@ static struct xt_target ebt_arpreply_tg_reg __read_mostly = {
78 .hooks = (1 << NF_BR_NUMHOOKS) | (1 << NF_BR_PRE_ROUTING), 78 .hooks = (1 << NF_BR_NUMHOOKS) | (1 << NF_BR_PRE_ROUTING),
79 .target = ebt_arpreply_tg, 79 .target = ebt_arpreply_tg,
80 .checkentry = ebt_arpreply_tg_check, 80 .checkentry = ebt_arpreply_tg_check,
81 .targetsize = XT_ALIGN(sizeof(struct ebt_arpreply_info)), 81 .targetsize = sizeof(struct ebt_arpreply_info),
82 .me = THIS_MODULE, 82 .me = THIS_MODULE,
83}; 83};
84 84
diff --git a/net/bridge/netfilter/ebt_dnat.c b/net/bridge/netfilter/ebt_dnat.c
index 6b49ea9e31fb..2bb40d728a35 100644
--- a/net/bridge/netfilter/ebt_dnat.c
+++ b/net/bridge/netfilter/ebt_dnat.c
@@ -54,7 +54,7 @@ static struct xt_target ebt_dnat_tg_reg __read_mostly = {
54 (1 << NF_BR_LOCAL_OUT) | (1 << NF_BR_BROUTING), 54 (1 << NF_BR_LOCAL_OUT) | (1 << NF_BR_BROUTING),
55 .target = ebt_dnat_tg, 55 .target = ebt_dnat_tg,
56 .checkentry = ebt_dnat_tg_check, 56 .checkentry = ebt_dnat_tg_check,
57 .targetsize = XT_ALIGN(sizeof(struct ebt_nat_info)), 57 .targetsize = sizeof(struct ebt_nat_info),
58 .me = THIS_MODULE, 58 .me = THIS_MODULE,
59}; 59};
60 60
diff --git a/net/bridge/netfilter/ebt_ip.c b/net/bridge/netfilter/ebt_ip.c
index d771bbfbcbe6..5de6df6f86b8 100644
--- a/net/bridge/netfilter/ebt_ip.c
+++ b/net/bridge/netfilter/ebt_ip.c
@@ -110,7 +110,7 @@ static struct xt_match ebt_ip_mt_reg __read_mostly = {
110 .family = NFPROTO_BRIDGE, 110 .family = NFPROTO_BRIDGE,
111 .match = ebt_ip_mt, 111 .match = ebt_ip_mt,
112 .checkentry = ebt_ip_mt_check, 112 .checkentry = ebt_ip_mt_check,
113 .matchsize = XT_ALIGN(sizeof(struct ebt_ip_info)), 113 .matchsize = sizeof(struct ebt_ip_info),
114 .me = THIS_MODULE, 114 .me = THIS_MODULE,
115}; 115};
116 116
diff --git a/net/bridge/netfilter/ebt_ip6.c b/net/bridge/netfilter/ebt_ip6.c
index 784a6573876c..bbf2534ef026 100644
--- a/net/bridge/netfilter/ebt_ip6.c
+++ b/net/bridge/netfilter/ebt_ip6.c
@@ -122,7 +122,7 @@ static struct xt_match ebt_ip6_mt_reg __read_mostly = {
122 .family = NFPROTO_BRIDGE, 122 .family = NFPROTO_BRIDGE,
123 .match = ebt_ip6_mt, 123 .match = ebt_ip6_mt,
124 .checkentry = ebt_ip6_mt_check, 124 .checkentry = ebt_ip6_mt_check,
125 .matchsize = XT_ALIGN(sizeof(struct ebt_ip6_info)), 125 .matchsize = sizeof(struct ebt_ip6_info),
126 .me = THIS_MODULE, 126 .me = THIS_MODULE,
127}; 127};
128 128
diff --git a/net/bridge/netfilter/ebt_limit.c b/net/bridge/netfilter/ebt_limit.c
index f7bd9192ff0c..7a8182710eb3 100644
--- a/net/bridge/netfilter/ebt_limit.c
+++ b/net/bridge/netfilter/ebt_limit.c
@@ -84,13 +84,29 @@ static bool ebt_limit_mt_check(const struct xt_mtchk_param *par)
84 return true; 84 return true;
85} 85}
86 86
87
88#ifdef CONFIG_COMPAT
89/*
90 * no conversion function needed --
91 * only avg/burst have meaningful values in userspace.
92 */
93struct ebt_compat_limit_info {
94 compat_uint_t avg, burst;
95 compat_ulong_t prev;
96 compat_uint_t credit, credit_cap, cost;
97};
98#endif
99
87static struct xt_match ebt_limit_mt_reg __read_mostly = { 100static struct xt_match ebt_limit_mt_reg __read_mostly = {
88 .name = "limit", 101 .name = "limit",
89 .revision = 0, 102 .revision = 0,
90 .family = NFPROTO_BRIDGE, 103 .family = NFPROTO_BRIDGE,
91 .match = ebt_limit_mt, 104 .match = ebt_limit_mt,
92 .checkentry = ebt_limit_mt_check, 105 .checkentry = ebt_limit_mt_check,
93 .matchsize = XT_ALIGN(sizeof(struct ebt_limit_info)), 106 .matchsize = sizeof(struct ebt_limit_info),
107#ifdef CONFIG_COMPAT
108 .compatsize = sizeof(struct ebt_compat_limit_info),
109#endif
94 .me = THIS_MODULE, 110 .me = THIS_MODULE,
95}; 111};
96 112
diff --git a/net/bridge/netfilter/ebt_log.c b/net/bridge/netfilter/ebt_log.c
index e4ea3fdd1d41..e873924ddb5d 100644
--- a/net/bridge/netfilter/ebt_log.c
+++ b/net/bridge/netfilter/ebt_log.c
@@ -195,7 +195,7 @@ static struct xt_target ebt_log_tg_reg __read_mostly = {
195 .family = NFPROTO_BRIDGE, 195 .family = NFPROTO_BRIDGE,
196 .target = ebt_log_tg, 196 .target = ebt_log_tg,
197 .checkentry = ebt_log_tg_check, 197 .checkentry = ebt_log_tg_check,
198 .targetsize = XT_ALIGN(sizeof(struct ebt_log_info)), 198 .targetsize = sizeof(struct ebt_log_info),
199 .me = THIS_MODULE, 199 .me = THIS_MODULE,
200}; 200};
201 201
diff --git a/net/bridge/netfilter/ebt_mark.c b/net/bridge/netfilter/ebt_mark.c
index 2fee7e8e2e93..2b5ce533d6b9 100644
--- a/net/bridge/netfilter/ebt_mark.c
+++ b/net/bridge/netfilter/ebt_mark.c
@@ -52,6 +52,32 @@ static bool ebt_mark_tg_check(const struct xt_tgchk_param *par)
52 return false; 52 return false;
53 return true; 53 return true;
54} 54}
55#ifdef CONFIG_COMPAT
56struct compat_ebt_mark_t_info {
57 compat_ulong_t mark;
58 compat_uint_t target;
59};
60
61static void mark_tg_compat_from_user(void *dst, const void *src)
62{
63 const struct compat_ebt_mark_t_info *user = src;
64 struct ebt_mark_t_info *kern = dst;
65
66 kern->mark = user->mark;
67 kern->target = user->target;
68}
69
70static int mark_tg_compat_to_user(void __user *dst, const void *src)
71{
72 struct compat_ebt_mark_t_info __user *user = dst;
73 const struct ebt_mark_t_info *kern = src;
74
75 if (put_user(kern->mark, &user->mark) ||
76 put_user(kern->target, &user->target))
77 return -EFAULT;
78 return 0;
79}
80#endif
55 81
56static struct xt_target ebt_mark_tg_reg __read_mostly = { 82static struct xt_target ebt_mark_tg_reg __read_mostly = {
57 .name = "mark", 83 .name = "mark",
@@ -59,7 +85,12 @@ static struct xt_target ebt_mark_tg_reg __read_mostly = {
59 .family = NFPROTO_BRIDGE, 85 .family = NFPROTO_BRIDGE,
60 .target = ebt_mark_tg, 86 .target = ebt_mark_tg,
61 .checkentry = ebt_mark_tg_check, 87 .checkentry = ebt_mark_tg_check,
62 .targetsize = XT_ALIGN(sizeof(struct ebt_mark_t_info)), 88 .targetsize = sizeof(struct ebt_mark_t_info),
89#ifdef CONFIG_COMPAT
90 .compatsize = sizeof(struct compat_ebt_mark_t_info),
91 .compat_from_user = mark_tg_compat_from_user,
92 .compat_to_user = mark_tg_compat_to_user,
93#endif
63 .me = THIS_MODULE, 94 .me = THIS_MODULE,
64}; 95};
65 96
diff --git a/net/bridge/netfilter/ebt_mark_m.c b/net/bridge/netfilter/ebt_mark_m.c
index ea570f214b1d..8de8c396d913 100644
--- a/net/bridge/netfilter/ebt_mark_m.c
+++ b/net/bridge/netfilter/ebt_mark_m.c
@@ -35,13 +35,50 @@ static bool ebt_mark_mt_check(const struct xt_mtchk_param *par)
35 return true; 35 return true;
36} 36}
37 37
38
39#ifdef CONFIG_COMPAT
40struct compat_ebt_mark_m_info {
41 compat_ulong_t mark, mask;
42 uint8_t invert, bitmask;
43};
44
45static void mark_mt_compat_from_user(void *dst, const void *src)
46{
47 const struct compat_ebt_mark_m_info *user = src;
48 struct ebt_mark_m_info *kern = dst;
49
50 kern->mark = user->mark;
51 kern->mask = user->mask;
52 kern->invert = user->invert;
53 kern->bitmask = user->bitmask;
54}
55
56static int mark_mt_compat_to_user(void __user *dst, const void *src)
57{
58 struct compat_ebt_mark_m_info __user *user = dst;
59 const struct ebt_mark_m_info *kern = src;
60
61 if (put_user(kern->mark, &user->mark) ||
62 put_user(kern->mask, &user->mask) ||
63 put_user(kern->invert, &user->invert) ||
64 put_user(kern->bitmask, &user->bitmask))
65 return -EFAULT;
66 return 0;
67}
68#endif
69
38static struct xt_match ebt_mark_mt_reg __read_mostly = { 70static struct xt_match ebt_mark_mt_reg __read_mostly = {
39 .name = "mark_m", 71 .name = "mark_m",
40 .revision = 0, 72 .revision = 0,
41 .family = NFPROTO_BRIDGE, 73 .family = NFPROTO_BRIDGE,
42 .match = ebt_mark_mt, 74 .match = ebt_mark_mt,
43 .checkentry = ebt_mark_mt_check, 75 .checkentry = ebt_mark_mt_check,
44 .matchsize = XT_ALIGN(sizeof(struct ebt_mark_m_info)), 76 .matchsize = sizeof(struct ebt_mark_m_info),
77#ifdef CONFIG_COMPAT
78 .compatsize = sizeof(struct compat_ebt_mark_m_info),
79 .compat_from_user = mark_mt_compat_from_user,
80 .compat_to_user = mark_mt_compat_to_user,
81#endif
45 .me = THIS_MODULE, 82 .me = THIS_MODULE,
46}; 83};
47 84
diff --git a/net/bridge/netfilter/ebt_nflog.c b/net/bridge/netfilter/ebt_nflog.c
index 2a63d996dd4e..40dbd248b9ae 100644
--- a/net/bridge/netfilter/ebt_nflog.c
+++ b/net/bridge/netfilter/ebt_nflog.c
@@ -51,7 +51,7 @@ static struct xt_target ebt_nflog_tg_reg __read_mostly = {
51 .family = NFPROTO_BRIDGE, 51 .family = NFPROTO_BRIDGE,
52 .target = ebt_nflog_tg, 52 .target = ebt_nflog_tg,
53 .checkentry = ebt_nflog_tg_check, 53 .checkentry = ebt_nflog_tg_check,
54 .targetsize = XT_ALIGN(sizeof(struct ebt_nflog_info)), 54 .targetsize = sizeof(struct ebt_nflog_info),
55 .me = THIS_MODULE, 55 .me = THIS_MODULE,
56}; 56};
57 57
diff --git a/net/bridge/netfilter/ebt_pkttype.c b/net/bridge/netfilter/ebt_pkttype.c
index 883e96e2a542..e2a07e6cbef3 100644
--- a/net/bridge/netfilter/ebt_pkttype.c
+++ b/net/bridge/netfilter/ebt_pkttype.c
@@ -36,7 +36,7 @@ static struct xt_match ebt_pkttype_mt_reg __read_mostly = {
36 .family = NFPROTO_BRIDGE, 36 .family = NFPROTO_BRIDGE,
37 .match = ebt_pkttype_mt, 37 .match = ebt_pkttype_mt,
38 .checkentry = ebt_pkttype_mt_check, 38 .checkentry = ebt_pkttype_mt_check,
39 .matchsize = XT_ALIGN(sizeof(struct ebt_pkttype_info)), 39 .matchsize = sizeof(struct ebt_pkttype_info),
40 .me = THIS_MODULE, 40 .me = THIS_MODULE,
41}; 41};
42 42
diff --git a/net/bridge/netfilter/ebt_redirect.c b/net/bridge/netfilter/ebt_redirect.c
index c8a49f7a57ba..9be8fbcd370b 100644
--- a/net/bridge/netfilter/ebt_redirect.c
+++ b/net/bridge/netfilter/ebt_redirect.c
@@ -59,7 +59,7 @@ static struct xt_target ebt_redirect_tg_reg __read_mostly = {
59 (1 << NF_BR_BROUTING), 59 (1 << NF_BR_BROUTING),
60 .target = ebt_redirect_tg, 60 .target = ebt_redirect_tg,
61 .checkentry = ebt_redirect_tg_check, 61 .checkentry = ebt_redirect_tg_check,
62 .targetsize = XT_ALIGN(sizeof(struct ebt_redirect_info)), 62 .targetsize = sizeof(struct ebt_redirect_info),
63 .me = THIS_MODULE, 63 .me = THIS_MODULE,
64}; 64};
65 65
diff --git a/net/bridge/netfilter/ebt_snat.c b/net/bridge/netfilter/ebt_snat.c
index 8d04d4c302bd..9c7b520765a2 100644
--- a/net/bridge/netfilter/ebt_snat.c
+++ b/net/bridge/netfilter/ebt_snat.c
@@ -67,7 +67,7 @@ static struct xt_target ebt_snat_tg_reg __read_mostly = {
67 .hooks = (1 << NF_BR_NUMHOOKS) | (1 << NF_BR_POST_ROUTING), 67 .hooks = (1 << NF_BR_NUMHOOKS) | (1 << NF_BR_POST_ROUTING),
68 .target = ebt_snat_tg, 68 .target = ebt_snat_tg,
69 .checkentry = ebt_snat_tg_check, 69 .checkentry = ebt_snat_tg_check,
70 .targetsize = XT_ALIGN(sizeof(struct ebt_nat_info)), 70 .targetsize = sizeof(struct ebt_nat_info),
71 .me = THIS_MODULE, 71 .me = THIS_MODULE,
72}; 72};
73 73
diff --git a/net/bridge/netfilter/ebt_stp.c b/net/bridge/netfilter/ebt_stp.c
index 48527e621626..92a93d363765 100644
--- a/net/bridge/netfilter/ebt_stp.c
+++ b/net/bridge/netfilter/ebt_stp.c
@@ -135,8 +135,8 @@ ebt_stp_mt(const struct sk_buff *skb, const struct xt_match_param *par)
135 if (memcmp(sp, header, sizeof(header))) 135 if (memcmp(sp, header, sizeof(header)))
136 return false; 136 return false;
137 137
138 if (info->bitmask & EBT_STP_TYPE 138 if (info->bitmask & EBT_STP_TYPE &&
139 && FWINV(info->type != sp->type, EBT_STP_TYPE)) 139 FWINV(info->type != sp->type, EBT_STP_TYPE))
140 return false; 140 return false;
141 141
142 if (sp->type == BPDU_TYPE_CONFIG && 142 if (sp->type == BPDU_TYPE_CONFIG &&
@@ -177,7 +177,7 @@ static struct xt_match ebt_stp_mt_reg __read_mostly = {
177 .family = NFPROTO_BRIDGE, 177 .family = NFPROTO_BRIDGE,
178 .match = ebt_stp_mt, 178 .match = ebt_stp_mt,
179 .checkentry = ebt_stp_mt_check, 179 .checkentry = ebt_stp_mt_check,
180 .matchsize = XT_ALIGN(sizeof(struct ebt_stp_info)), 180 .matchsize = sizeof(struct ebt_stp_info),
181 .me = THIS_MODULE, 181 .me = THIS_MODULE,
182}; 182};
183 183
diff --git a/net/bridge/netfilter/ebt_ulog.c b/net/bridge/netfilter/ebt_ulog.c
index ce50688a6431..f9560f3dbdc7 100644
--- a/net/bridge/netfilter/ebt_ulog.c
+++ b/net/bridge/netfilter/ebt_ulog.c
@@ -29,6 +29,7 @@
29 */ 29 */
30 30
31#include <linux/module.h> 31#include <linux/module.h>
32#include <linux/slab.h>
32#include <linux/spinlock.h> 33#include <linux/spinlock.h>
33#include <linux/socket.h> 34#include <linux/socket.h>
34#include <linux/skbuff.h> 35#include <linux/skbuff.h>
@@ -275,7 +276,7 @@ static struct xt_target ebt_ulog_tg_reg __read_mostly = {
275 .family = NFPROTO_BRIDGE, 276 .family = NFPROTO_BRIDGE,
276 .target = ebt_ulog_tg, 277 .target = ebt_ulog_tg,
277 .checkentry = ebt_ulog_tg_check, 278 .checkentry = ebt_ulog_tg_check,
278 .targetsize = XT_ALIGN(sizeof(struct ebt_ulog_info)), 279 .targetsize = sizeof(struct ebt_ulog_info),
279 .me = THIS_MODULE, 280 .me = THIS_MODULE,
280}; 281};
281 282
diff --git a/net/bridge/netfilter/ebt_vlan.c b/net/bridge/netfilter/ebt_vlan.c
index 3dddd489328e..be1dd2e1f615 100644
--- a/net/bridge/netfilter/ebt_vlan.c
+++ b/net/bridge/netfilter/ebt_vlan.c
@@ -163,7 +163,7 @@ static struct xt_match ebt_vlan_mt_reg __read_mostly = {
163 .family = NFPROTO_BRIDGE, 163 .family = NFPROTO_BRIDGE,
164 .match = ebt_vlan_mt, 164 .match = ebt_vlan_mt,
165 .checkentry = ebt_vlan_mt_check, 165 .checkentry = ebt_vlan_mt_check,
166 .matchsize = XT_ALIGN(sizeof(struct ebt_vlan_info)), 166 .matchsize = sizeof(struct ebt_vlan_info),
167 .me = THIS_MODULE, 167 .me = THIS_MODULE,
168}; 168};
169 169
diff --git a/net/bridge/netfilter/ebtable_broute.c b/net/bridge/netfilter/ebtable_broute.c
index d32ab13e728c..ae3f106c3908 100644
--- a/net/bridge/netfilter/ebtable_broute.c
+++ b/net/bridge/netfilter/ebtable_broute.c
@@ -71,7 +71,7 @@ static int __net_init broute_net_init(struct net *net)
71 71
72static void __net_exit broute_net_exit(struct net *net) 72static void __net_exit broute_net_exit(struct net *net)
73{ 73{
74 ebt_unregister_table(net->xt.broute_table); 74 ebt_unregister_table(net, net->xt.broute_table);
75} 75}
76 76
77static struct pernet_operations broute_net_ops = { 77static struct pernet_operations broute_net_ops = {
diff --git a/net/bridge/netfilter/ebtable_filter.c b/net/bridge/netfilter/ebtable_filter.c
index 60b1a6ca7185..42e6bd094574 100644
--- a/net/bridge/netfilter/ebtable_filter.c
+++ b/net/bridge/netfilter/ebtable_filter.c
@@ -107,7 +107,7 @@ static int __net_init frame_filter_net_init(struct net *net)
107 107
108static void __net_exit frame_filter_net_exit(struct net *net) 108static void __net_exit frame_filter_net_exit(struct net *net)
109{ 109{
110 ebt_unregister_table(net->xt.frame_filter); 110 ebt_unregister_table(net, net->xt.frame_filter);
111} 111}
112 112
113static struct pernet_operations frame_filter_net_ops = { 113static struct pernet_operations frame_filter_net_ops = {
diff --git a/net/bridge/netfilter/ebtable_nat.c b/net/bridge/netfilter/ebtable_nat.c
index 4a98804203b0..6dc2f878ae05 100644
--- a/net/bridge/netfilter/ebtable_nat.c
+++ b/net/bridge/netfilter/ebtable_nat.c
@@ -107,7 +107,7 @@ static int __net_init frame_nat_net_init(struct net *net)
107 107
108static void __net_exit frame_nat_net_exit(struct net *net) 108static void __net_exit frame_nat_net_exit(struct net *net)
109{ 109{
110 ebt_unregister_table(net->xt.frame_nat); 110 ebt_unregister_table(net, net->xt.frame_nat);
111} 111}
112 112
113static struct pernet_operations frame_nat_net_ops = { 113static struct pernet_operations frame_nat_net_ops = {
diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
index bd1c65425d4f..f0865fd1e3ec 100644
--- a/net/bridge/netfilter/ebtables.c
+++ b/net/bridge/netfilter/ebtables.c
@@ -23,6 +23,7 @@
23#include <linux/netfilter_bridge/ebtables.h> 23#include <linux/netfilter_bridge/ebtables.h>
24#include <linux/spinlock.h> 24#include <linux/spinlock.h>
25#include <linux/mutex.h> 25#include <linux/mutex.h>
26#include <linux/slab.h>
26#include <asm/uaccess.h> 27#include <asm/uaccess.h>
27#include <linux/smp.h> 28#include <linux/smp.h>
28#include <linux/cpumask.h> 29#include <linux/cpumask.h>
@@ -33,11 +34,6 @@
33#define BUGPRINT(format, args...) printk("kernel msg: ebtables bug: please "\ 34#define BUGPRINT(format, args...) printk("kernel msg: ebtables bug: please "\
34 "report to author: "format, ## args) 35 "report to author: "format, ## args)
35/* #define BUGPRINT(format, args...) */ 36/* #define BUGPRINT(format, args...) */
36#define MEMPRINT(format, args...) printk("kernel msg: ebtables "\
37 ": out of memory: "format, ## args)
38/* #define MEMPRINT(format, args...) */
39
40
41 37
42/* 38/*
43 * Each cpu has its own set of counters, so there is no need for write_lock in 39 * Each cpu has its own set of counters, so there is no need for write_lock in
@@ -56,11 +52,37 @@
56 52
57static DEFINE_MUTEX(ebt_mutex); 53static DEFINE_MUTEX(ebt_mutex);
58 54
55#ifdef CONFIG_COMPAT
56static void ebt_standard_compat_from_user(void *dst, const void *src)
57{
58 int v = *(compat_int_t *)src;
59
60 if (v >= 0)
61 v += xt_compat_calc_jump(NFPROTO_BRIDGE, v);
62 memcpy(dst, &v, sizeof(v));
63}
64
65static int ebt_standard_compat_to_user(void __user *dst, const void *src)
66{
67 compat_int_t cv = *(int *)src;
68
69 if (cv >= 0)
70 cv -= xt_compat_calc_jump(NFPROTO_BRIDGE, cv);
71 return copy_to_user(dst, &cv, sizeof(cv)) ? -EFAULT : 0;
72}
73#endif
74
75
59static struct xt_target ebt_standard_target = { 76static struct xt_target ebt_standard_target = {
60 .name = "standard", 77 .name = "standard",
61 .revision = 0, 78 .revision = 0,
62 .family = NFPROTO_BRIDGE, 79 .family = NFPROTO_BRIDGE,
63 .targetsize = sizeof(int), 80 .targetsize = sizeof(int),
81#ifdef CONFIG_COMPAT
82 .compatsize = sizeof(compat_int_t),
83 .compat_from_user = ebt_standard_compat_from_user,
84 .compat_to_user = ebt_standard_compat_to_user,
85#endif
64}; 86};
65 87
66static inline int 88static inline int
@@ -82,7 +104,8 @@ static inline int ebt_do_match (struct ebt_entry_match *m,
82 return m->u.match->match(skb, par) ? EBT_MATCH : EBT_NOMATCH; 104 return m->u.match->match(skb, par) ? EBT_MATCH : EBT_NOMATCH;
83} 105}
84 106
85static inline int ebt_dev_check(char *entry, const struct net_device *device) 107static inline int
108ebt_dev_check(const char *entry, const struct net_device *device)
86{ 109{
87 int i = 0; 110 int i = 0;
88 const char *devname; 111 const char *devname;
@@ -100,8 +123,9 @@ static inline int ebt_dev_check(char *entry, const struct net_device *device)
100 123
101#define FWINV2(bool,invflg) ((bool) ^ !!(e->invflags & invflg)) 124#define FWINV2(bool,invflg) ((bool) ^ !!(e->invflags & invflg))
102/* process standard matches */ 125/* process standard matches */
103static inline int ebt_basic_match(struct ebt_entry *e, struct ethhdr *h, 126static inline int
104 const struct net_device *in, const struct net_device *out) 127ebt_basic_match(const struct ebt_entry *e, const struct ethhdr *h,
128 const struct net_device *in, const struct net_device *out)
105{ 129{
106 int verdict, i; 130 int verdict, i;
107 131
@@ -156,12 +180,12 @@ unsigned int ebt_do_table (unsigned int hook, struct sk_buff *skb,
156 int i, nentries; 180 int i, nentries;
157 struct ebt_entry *point; 181 struct ebt_entry *point;
158 struct ebt_counter *counter_base, *cb_base; 182 struct ebt_counter *counter_base, *cb_base;
159 struct ebt_entry_target *t; 183 const struct ebt_entry_target *t;
160 int verdict, sp = 0; 184 int verdict, sp = 0;
161 struct ebt_chainstack *cs; 185 struct ebt_chainstack *cs;
162 struct ebt_entries *chaininfo; 186 struct ebt_entries *chaininfo;
163 char *base; 187 const char *base;
164 struct ebt_table_info *private; 188 const struct ebt_table_info *private;
165 bool hotdrop = false; 189 bool hotdrop = false;
166 struct xt_match_param mtpar; 190 struct xt_match_param mtpar;
167 struct xt_target_param tgpar; 191 struct xt_target_param tgpar;
@@ -395,7 +419,7 @@ ebt_check_watcher(struct ebt_entry_watcher *w, struct xt_tgchk_param *par,
395 return 0; 419 return 0;
396} 420}
397 421
398static int ebt_verify_pointers(struct ebt_replace *repl, 422static int ebt_verify_pointers(const struct ebt_replace *repl,
399 struct ebt_table_info *newinfo) 423 struct ebt_table_info *newinfo)
400{ 424{
401 unsigned int limit = repl->entries_size; 425 unsigned int limit = repl->entries_size;
@@ -442,6 +466,8 @@ static int ebt_verify_pointers(struct ebt_replace *repl,
442 break; 466 break;
443 if (left < e->next_offset) 467 if (left < e->next_offset)
444 break; 468 break;
469 if (e->next_offset < sizeof(struct ebt_entry))
470 return -EINVAL;
445 offset += e->next_offset; 471 offset += e->next_offset;
446 } 472 }
447 } 473 }
@@ -466,8 +492,8 @@ static int ebt_verify_pointers(struct ebt_replace *repl,
466 * to parse the userspace data 492 * to parse the userspace data
467 */ 493 */
468static inline int 494static inline int
469ebt_check_entry_size_and_hooks(struct ebt_entry *e, 495ebt_check_entry_size_and_hooks(const struct ebt_entry *e,
470 struct ebt_table_info *newinfo, 496 const struct ebt_table_info *newinfo,
471 unsigned int *n, unsigned int *cnt, 497 unsigned int *n, unsigned int *cnt,
472 unsigned int *totalcnt, unsigned int *udc_cnt) 498 unsigned int *totalcnt, unsigned int *udc_cnt)
473{ 499{
@@ -561,13 +587,14 @@ ebt_get_udc_positions(struct ebt_entry *e, struct ebt_table_info *newinfo,
561} 587}
562 588
563static inline int 589static inline int
564ebt_cleanup_match(struct ebt_entry_match *m, unsigned int *i) 590ebt_cleanup_match(struct ebt_entry_match *m, struct net *net, unsigned int *i)
565{ 591{
566 struct xt_mtdtor_param par; 592 struct xt_mtdtor_param par;
567 593
568 if (i && (*i)-- == 0) 594 if (i && (*i)-- == 0)
569 return 1; 595 return 1;
570 596
597 par.net = net;
571 par.match = m->u.match; 598 par.match = m->u.match;
572 par.matchinfo = m->data; 599 par.matchinfo = m->data;
573 par.family = NFPROTO_BRIDGE; 600 par.family = NFPROTO_BRIDGE;
@@ -578,13 +605,14 @@ ebt_cleanup_match(struct ebt_entry_match *m, unsigned int *i)
578} 605}
579 606
580static inline int 607static inline int
581ebt_cleanup_watcher(struct ebt_entry_watcher *w, unsigned int *i) 608ebt_cleanup_watcher(struct ebt_entry_watcher *w, struct net *net, unsigned int *i)
582{ 609{
583 struct xt_tgdtor_param par; 610 struct xt_tgdtor_param par;
584 611
585 if (i && (*i)-- == 0) 612 if (i && (*i)-- == 0)
586 return 1; 613 return 1;
587 614
615 par.net = net;
588 par.target = w->u.watcher; 616 par.target = w->u.watcher;
589 par.targinfo = w->data; 617 par.targinfo = w->data;
590 par.family = NFPROTO_BRIDGE; 618 par.family = NFPROTO_BRIDGE;
@@ -595,7 +623,7 @@ ebt_cleanup_watcher(struct ebt_entry_watcher *w, unsigned int *i)
595} 623}
596 624
597static inline int 625static inline int
598ebt_cleanup_entry(struct ebt_entry *e, unsigned int *cnt) 626ebt_cleanup_entry(struct ebt_entry *e, struct net *net, unsigned int *cnt)
599{ 627{
600 struct xt_tgdtor_param par; 628 struct xt_tgdtor_param par;
601 struct ebt_entry_target *t; 629 struct ebt_entry_target *t;
@@ -605,10 +633,11 @@ ebt_cleanup_entry(struct ebt_entry *e, unsigned int *cnt)
605 /* we're done */ 633 /* we're done */
606 if (cnt && (*cnt)-- == 0) 634 if (cnt && (*cnt)-- == 0)
607 return 1; 635 return 1;
608 EBT_WATCHER_ITERATE(e, ebt_cleanup_watcher, NULL); 636 EBT_WATCHER_ITERATE(e, ebt_cleanup_watcher, net, NULL);
609 EBT_MATCH_ITERATE(e, ebt_cleanup_match, NULL); 637 EBT_MATCH_ITERATE(e, ebt_cleanup_match, net, NULL);
610 t = (struct ebt_entry_target *)(((char *)e) + e->target_offset); 638 t = (struct ebt_entry_target *)(((char *)e) + e->target_offset);
611 639
640 par.net = net;
612 par.target = t->u.target; 641 par.target = t->u.target;
613 par.targinfo = t->data; 642 par.targinfo = t->data;
614 par.family = NFPROTO_BRIDGE; 643 par.family = NFPROTO_BRIDGE;
@@ -619,7 +648,8 @@ ebt_cleanup_entry(struct ebt_entry *e, unsigned int *cnt)
619} 648}
620 649
621static inline int 650static inline int
622ebt_check_entry(struct ebt_entry *e, struct ebt_table_info *newinfo, 651ebt_check_entry(struct ebt_entry *e, struct net *net,
652 const struct ebt_table_info *newinfo,
623 const char *name, unsigned int *cnt, 653 const char *name, unsigned int *cnt,
624 struct ebt_cl_stack *cl_s, unsigned int udc_cnt) 654 struct ebt_cl_stack *cl_s, unsigned int udc_cnt)
625{ 655{
@@ -671,6 +701,7 @@ ebt_check_entry(struct ebt_entry *e, struct ebt_table_info *newinfo,
671 } 701 }
672 i = 0; 702 i = 0;
673 703
704 mtpar.net = tgpar.net = net;
674 mtpar.table = tgpar.table = name; 705 mtpar.table = tgpar.table = name;
675 mtpar.entryinfo = tgpar.entryinfo = e; 706 mtpar.entryinfo = tgpar.entryinfo = e;
676 mtpar.hook_mask = tgpar.hook_mask = hookmask; 707 mtpar.hook_mask = tgpar.hook_mask = hookmask;
@@ -726,9 +757,9 @@ ebt_check_entry(struct ebt_entry *e, struct ebt_table_info *newinfo,
726 (*cnt)++; 757 (*cnt)++;
727 return 0; 758 return 0;
728cleanup_watchers: 759cleanup_watchers:
729 EBT_WATCHER_ITERATE(e, ebt_cleanup_watcher, &j); 760 EBT_WATCHER_ITERATE(e, ebt_cleanup_watcher, net, &j);
730cleanup_matches: 761cleanup_matches:
731 EBT_MATCH_ITERATE(e, ebt_cleanup_match, &i); 762 EBT_MATCH_ITERATE(e, ebt_cleanup_match, net, &i);
732 return ret; 763 return ret;
733} 764}
734 765
@@ -737,12 +768,12 @@ cleanup_matches:
737 * the hook mask for udc tells us from which base chains the udc can be 768 * the hook mask for udc tells us from which base chains the udc can be
738 * accessed. This mask is a parameter to the check() functions of the extensions 769 * accessed. This mask is a parameter to the check() functions of the extensions
739 */ 770 */
740static int check_chainloops(struct ebt_entries *chain, struct ebt_cl_stack *cl_s, 771static int check_chainloops(const struct ebt_entries *chain, struct ebt_cl_stack *cl_s,
741 unsigned int udc_cnt, unsigned int hooknr, char *base) 772 unsigned int udc_cnt, unsigned int hooknr, char *base)
742{ 773{
743 int i, chain_nr = -1, pos = 0, nentries = chain->nentries, verdict; 774 int i, chain_nr = -1, pos = 0, nentries = chain->nentries, verdict;
744 struct ebt_entry *e = (struct ebt_entry *)chain->data; 775 const struct ebt_entry *e = (struct ebt_entry *)chain->data;
745 struct ebt_entry_target *t; 776 const struct ebt_entry_target *t;
746 777
747 while (pos < nentries || chain_nr != -1) { 778 while (pos < nentries || chain_nr != -1) {
748 /* end of udc, go back one 'recursion' step */ 779 /* end of udc, go back one 'recursion' step */
@@ -808,7 +839,8 @@ letscontinue:
808} 839}
809 840
810/* do the parsing of the table/chains/entries/matches/watchers/targets, heh */ 841/* do the parsing of the table/chains/entries/matches/watchers/targets, heh */
811static int translate_table(char *name, struct ebt_table_info *newinfo) 842static int translate_table(struct net *net, const char *name,
843 struct ebt_table_info *newinfo)
812{ 844{
813 unsigned int i, j, k, udc_cnt; 845 unsigned int i, j, k, udc_cnt;
814 int ret; 846 int ret;
@@ -917,17 +949,17 @@ static int translate_table(char *name, struct ebt_table_info *newinfo)
917 /* used to know what we need to clean up if something goes wrong */ 949 /* used to know what we need to clean up if something goes wrong */
918 i = 0; 950 i = 0;
919 ret = EBT_ENTRY_ITERATE(newinfo->entries, newinfo->entries_size, 951 ret = EBT_ENTRY_ITERATE(newinfo->entries, newinfo->entries_size,
920 ebt_check_entry, newinfo, name, &i, cl_s, udc_cnt); 952 ebt_check_entry, net, newinfo, name, &i, cl_s, udc_cnt);
921 if (ret != 0) { 953 if (ret != 0) {
922 EBT_ENTRY_ITERATE(newinfo->entries, newinfo->entries_size, 954 EBT_ENTRY_ITERATE(newinfo->entries, newinfo->entries_size,
923 ebt_cleanup_entry, &i); 955 ebt_cleanup_entry, net, &i);
924 } 956 }
925 vfree(cl_s); 957 vfree(cl_s);
926 return ret; 958 return ret;
927} 959}
928 960
929/* called under write_lock */ 961/* called under write_lock */
930static void get_counters(struct ebt_counter *oldcounters, 962static void get_counters(const struct ebt_counter *oldcounters,
931 struct ebt_counter *counters, unsigned int nentries) 963 struct ebt_counter *counters, unsigned int nentries)
932{ 964{
933 int i, cpu; 965 int i, cpu;
@@ -949,90 +981,45 @@ static void get_counters(struct ebt_counter *oldcounters,
949 } 981 }
950} 982}
951 983
952/* replace the table */ 984static int do_replace_finish(struct net *net, struct ebt_replace *repl,
953static int do_replace(struct net *net, void __user *user, unsigned int len) 985 struct ebt_table_info *newinfo)
954{ 986{
955 int ret, i, countersize; 987 int ret, i;
956 struct ebt_table_info *newinfo;
957 struct ebt_replace tmp;
958 struct ebt_table *t;
959 struct ebt_counter *counterstmp = NULL; 988 struct ebt_counter *counterstmp = NULL;
960 /* used to be able to unlock earlier */ 989 /* used to be able to unlock earlier */
961 struct ebt_table_info *table; 990 struct ebt_table_info *table;
962 991 struct ebt_table *t;
963 if (copy_from_user(&tmp, user, sizeof(tmp)) != 0)
964 return -EFAULT;
965
966 if (len != sizeof(tmp) + tmp.entries_size) {
967 BUGPRINT("Wrong len argument\n");
968 return -EINVAL;
969 }
970
971 if (tmp.entries_size == 0) {
972 BUGPRINT("Entries_size never zero\n");
973 return -EINVAL;
974 }
975 /* overflow check */
976 if (tmp.nentries >= ((INT_MAX - sizeof(struct ebt_table_info)) / NR_CPUS -
977 SMP_CACHE_BYTES) / sizeof(struct ebt_counter))
978 return -ENOMEM;
979 if (tmp.num_counters >= INT_MAX / sizeof(struct ebt_counter))
980 return -ENOMEM;
981
982 countersize = COUNTER_OFFSET(tmp.nentries) * nr_cpu_ids;
983 newinfo = vmalloc(sizeof(*newinfo) + countersize);
984 if (!newinfo)
985 return -ENOMEM;
986
987 if (countersize)
988 memset(newinfo->counters, 0, countersize);
989
990 newinfo->entries = vmalloc(tmp.entries_size);
991 if (!newinfo->entries) {
992 ret = -ENOMEM;
993 goto free_newinfo;
994 }
995 if (copy_from_user(
996 newinfo->entries, tmp.entries, tmp.entries_size) != 0) {
997 BUGPRINT("Couldn't copy entries from userspace\n");
998 ret = -EFAULT;
999 goto free_entries;
1000 }
1001 992
1002 /* the user wants counters back 993 /* the user wants counters back
1003 the check on the size is done later, when we have the lock */ 994 the check on the size is done later, when we have the lock */
1004 if (tmp.num_counters) { 995 if (repl->num_counters) {
1005 counterstmp = vmalloc(tmp.num_counters * sizeof(*counterstmp)); 996 unsigned long size = repl->num_counters * sizeof(*counterstmp);
1006 if (!counterstmp) { 997 counterstmp = vmalloc(size);
1007 ret = -ENOMEM; 998 if (!counterstmp)
1008 goto free_entries; 999 return -ENOMEM;
1009 }
1010 } 1000 }
1011 else
1012 counterstmp = NULL;
1013 1001
1014 /* this can get initialized by translate_table() */
1015 newinfo->chainstack = NULL; 1002 newinfo->chainstack = NULL;
1016 ret = ebt_verify_pointers(&tmp, newinfo); 1003 ret = ebt_verify_pointers(repl, newinfo);
1017 if (ret != 0) 1004 if (ret != 0)
1018 goto free_counterstmp; 1005 goto free_counterstmp;
1019 1006
1020 ret = translate_table(tmp.name, newinfo); 1007 ret = translate_table(net, repl->name, newinfo);
1021 1008
1022 if (ret != 0) 1009 if (ret != 0)
1023 goto free_counterstmp; 1010 goto free_counterstmp;
1024 1011
1025 t = find_table_lock(net, tmp.name, &ret, &ebt_mutex); 1012 t = find_table_lock(net, repl->name, &ret, &ebt_mutex);
1026 if (!t) { 1013 if (!t) {
1027 ret = -ENOENT; 1014 ret = -ENOENT;
1028 goto free_iterate; 1015 goto free_iterate;
1029 } 1016 }
1030 1017
1031 /* the table doesn't like it */ 1018 /* the table doesn't like it */
1032 if (t->check && (ret = t->check(newinfo, tmp.valid_hooks))) 1019 if (t->check && (ret = t->check(newinfo, repl->valid_hooks)))
1033 goto free_unlock; 1020 goto free_unlock;
1034 1021
1035 if (tmp.num_counters && tmp.num_counters != t->private->nentries) { 1022 if (repl->num_counters && repl->num_counters != t->private->nentries) {
1036 BUGPRINT("Wrong nr. of counters requested\n"); 1023 BUGPRINT("Wrong nr. of counters requested\n");
1037 ret = -EINVAL; 1024 ret = -EINVAL;
1038 goto free_unlock; 1025 goto free_unlock;
@@ -1048,7 +1035,7 @@ static int do_replace(struct net *net, void __user *user, unsigned int len)
1048 module_put(t->me); 1035 module_put(t->me);
1049 /* we need an atomic snapshot of the counters */ 1036 /* we need an atomic snapshot of the counters */
1050 write_lock_bh(&t->lock); 1037 write_lock_bh(&t->lock);
1051 if (tmp.num_counters) 1038 if (repl->num_counters)
1052 get_counters(t->private->counters, counterstmp, 1039 get_counters(t->private->counters, counterstmp,
1053 t->private->nentries); 1040 t->private->nentries);
1054 1041
@@ -1059,10 +1046,9 @@ static int do_replace(struct net *net, void __user *user, unsigned int len)
1059 allocation. Only reason why this is done is because this way the lock 1046 allocation. Only reason why this is done is because this way the lock
1060 is held only once, while this doesn't bring the kernel into a 1047 is held only once, while this doesn't bring the kernel into a
1061 dangerous state. */ 1048 dangerous state. */
1062 if (tmp.num_counters && 1049 if (repl->num_counters &&
1063 copy_to_user(tmp.counters, counterstmp, 1050 copy_to_user(repl->counters, counterstmp,
1064 tmp.num_counters * sizeof(struct ebt_counter))) { 1051 repl->num_counters * sizeof(struct ebt_counter))) {
1065 BUGPRINT("Couldn't copy counters to userspace\n");
1066 ret = -EFAULT; 1052 ret = -EFAULT;
1067 } 1053 }
1068 else 1054 else
@@ -1070,7 +1056,7 @@ static int do_replace(struct net *net, void __user *user, unsigned int len)
1070 1056
1071 /* decrease module count and free resources */ 1057 /* decrease module count and free resources */
1072 EBT_ENTRY_ITERATE(table->entries, table->entries_size, 1058 EBT_ENTRY_ITERATE(table->entries, table->entries_size,
1073 ebt_cleanup_entry, NULL); 1059 ebt_cleanup_entry, net, NULL);
1074 1060
1075 vfree(table->entries); 1061 vfree(table->entries);
1076 if (table->chainstack) { 1062 if (table->chainstack) {
@@ -1087,7 +1073,7 @@ free_unlock:
1087 mutex_unlock(&ebt_mutex); 1073 mutex_unlock(&ebt_mutex);
1088free_iterate: 1074free_iterate:
1089 EBT_ENTRY_ITERATE(newinfo->entries, newinfo->entries_size, 1075 EBT_ENTRY_ITERATE(newinfo->entries, newinfo->entries_size,
1090 ebt_cleanup_entry, NULL); 1076 ebt_cleanup_entry, net, NULL);
1091free_counterstmp: 1077free_counterstmp:
1092 vfree(counterstmp); 1078 vfree(counterstmp);
1093 /* can be initialized in translate_table() */ 1079 /* can be initialized in translate_table() */
@@ -1096,6 +1082,59 @@ free_counterstmp:
1096 vfree(newinfo->chainstack[i]); 1082 vfree(newinfo->chainstack[i]);
1097 vfree(newinfo->chainstack); 1083 vfree(newinfo->chainstack);
1098 } 1084 }
1085 return ret;
1086}
1087
1088/* replace the table */
1089static int do_replace(struct net *net, const void __user *user,
1090 unsigned int len)
1091{
1092 int ret, countersize;
1093 struct ebt_table_info *newinfo;
1094 struct ebt_replace tmp;
1095
1096 if (copy_from_user(&tmp, user, sizeof(tmp)) != 0)
1097 return -EFAULT;
1098
1099 if (len != sizeof(tmp) + tmp.entries_size) {
1100 BUGPRINT("Wrong len argument\n");
1101 return -EINVAL;
1102 }
1103
1104 if (tmp.entries_size == 0) {
1105 BUGPRINT("Entries_size never zero\n");
1106 return -EINVAL;
1107 }
1108 /* overflow check */
1109 if (tmp.nentries >= ((INT_MAX - sizeof(struct ebt_table_info)) /
1110 NR_CPUS - SMP_CACHE_BYTES) / sizeof(struct ebt_counter))
1111 return -ENOMEM;
1112 if (tmp.num_counters >= INT_MAX / sizeof(struct ebt_counter))
1113 return -ENOMEM;
1114
1115 countersize = COUNTER_OFFSET(tmp.nentries) * nr_cpu_ids;
1116 newinfo = vmalloc(sizeof(*newinfo) + countersize);
1117 if (!newinfo)
1118 return -ENOMEM;
1119
1120 if (countersize)
1121 memset(newinfo->counters, 0, countersize);
1122
1123 newinfo->entries = vmalloc(tmp.entries_size);
1124 if (!newinfo->entries) {
1125 ret = -ENOMEM;
1126 goto free_newinfo;
1127 }
1128 if (copy_from_user(
1129 newinfo->entries, tmp.entries, tmp.entries_size) != 0) {
1130 BUGPRINT("Couldn't copy entries from userspace\n");
1131 ret = -EFAULT;
1132 goto free_entries;
1133 }
1134
1135 ret = do_replace_finish(net, &tmp, newinfo);
1136 if (ret == 0)
1137 return ret;
1099free_entries: 1138free_entries:
1100 vfree(newinfo->entries); 1139 vfree(newinfo->entries);
1101free_newinfo: 1140free_newinfo:
@@ -1154,7 +1193,7 @@ ebt_register_table(struct net *net, const struct ebt_table *input_table)
1154 newinfo->hook_entry[i] = p + 1193 newinfo->hook_entry[i] = p +
1155 ((char *)repl->hook_entry[i] - repl->entries); 1194 ((char *)repl->hook_entry[i] - repl->entries);
1156 } 1195 }
1157 ret = translate_table(repl->name, newinfo); 1196 ret = translate_table(net, repl->name, newinfo);
1158 if (ret != 0) { 1197 if (ret != 0) {
1159 BUGPRINT("Translate_table failed\n"); 1198 BUGPRINT("Translate_table failed\n");
1160 goto free_chainstack; 1199 goto free_chainstack;
@@ -1204,7 +1243,7 @@ out:
1204 return ERR_PTR(ret); 1243 return ERR_PTR(ret);
1205} 1244}
1206 1245
1207void ebt_unregister_table(struct ebt_table *table) 1246void ebt_unregister_table(struct net *net, struct ebt_table *table)
1208{ 1247{
1209 int i; 1248 int i;
1210 1249
@@ -1216,7 +1255,7 @@ void ebt_unregister_table(struct ebt_table *table)
1216 list_del(&table->list); 1255 list_del(&table->list);
1217 mutex_unlock(&ebt_mutex); 1256 mutex_unlock(&ebt_mutex);
1218 EBT_ENTRY_ITERATE(table->private->entries, table->private->entries_size, 1257 EBT_ENTRY_ITERATE(table->private->entries, table->private->entries_size,
1219 ebt_cleanup_entry, NULL); 1258 ebt_cleanup_entry, net, NULL);
1220 if (table->private->nentries) 1259 if (table->private->nentries)
1221 module_put(table->me); 1260 module_put(table->me);
1222 vfree(table->private->entries); 1261 vfree(table->private->entries);
@@ -1230,39 +1269,33 @@ void ebt_unregister_table(struct ebt_table *table)
1230} 1269}
1231 1270
1232/* userspace just supplied us with counters */ 1271/* userspace just supplied us with counters */
1233static int update_counters(struct net *net, void __user *user, unsigned int len) 1272static int do_update_counters(struct net *net, const char *name,
1273 struct ebt_counter __user *counters,
1274 unsigned int num_counters,
1275 const void __user *user, unsigned int len)
1234{ 1276{
1235 int i, ret; 1277 int i, ret;
1236 struct ebt_counter *tmp; 1278 struct ebt_counter *tmp;
1237 struct ebt_replace hlp;
1238 struct ebt_table *t; 1279 struct ebt_table *t;
1239 1280
1240 if (copy_from_user(&hlp, user, sizeof(hlp))) 1281 if (num_counters == 0)
1241 return -EFAULT;
1242
1243 if (len != sizeof(hlp) + hlp.num_counters * sizeof(struct ebt_counter))
1244 return -EINVAL;
1245 if (hlp.num_counters == 0)
1246 return -EINVAL; 1282 return -EINVAL;
1247 1283
1248 if (!(tmp = vmalloc(hlp.num_counters * sizeof(*tmp)))) { 1284 tmp = vmalloc(num_counters * sizeof(*tmp));
1249 MEMPRINT("Update_counters && nomemory\n"); 1285 if (!tmp)
1250 return -ENOMEM; 1286 return -ENOMEM;
1251 }
1252 1287
1253 t = find_table_lock(net, hlp.name, &ret, &ebt_mutex); 1288 t = find_table_lock(net, name, &ret, &ebt_mutex);
1254 if (!t) 1289 if (!t)
1255 goto free_tmp; 1290 goto free_tmp;
1256 1291
1257 if (hlp.num_counters != t->private->nentries) { 1292 if (num_counters != t->private->nentries) {
1258 BUGPRINT("Wrong nr of counters\n"); 1293 BUGPRINT("Wrong nr of counters\n");
1259 ret = -EINVAL; 1294 ret = -EINVAL;
1260 goto unlock_mutex; 1295 goto unlock_mutex;
1261 } 1296 }
1262 1297
1263 if ( copy_from_user(tmp, hlp.counters, 1298 if (copy_from_user(tmp, counters, num_counters * sizeof(*counters))) {
1264 hlp.num_counters * sizeof(struct ebt_counter)) ) {
1265 BUGPRINT("Updata_counters && !cfu\n");
1266 ret = -EFAULT; 1299 ret = -EFAULT;
1267 goto unlock_mutex; 1300 goto unlock_mutex;
1268 } 1301 }
@@ -1271,7 +1304,7 @@ static int update_counters(struct net *net, void __user *user, unsigned int len)
1271 write_lock_bh(&t->lock); 1304 write_lock_bh(&t->lock);
1272 1305
1273 /* we add to the counters of the first cpu */ 1306 /* we add to the counters of the first cpu */
1274 for (i = 0; i < hlp.num_counters; i++) { 1307 for (i = 0; i < num_counters; i++) {
1275 t->private->counters[i].pcnt += tmp[i].pcnt; 1308 t->private->counters[i].pcnt += tmp[i].pcnt;
1276 t->private->counters[i].bcnt += tmp[i].bcnt; 1309 t->private->counters[i].bcnt += tmp[i].bcnt;
1277 } 1310 }
@@ -1285,8 +1318,23 @@ free_tmp:
1285 return ret; 1318 return ret;
1286} 1319}
1287 1320
1288static inline int ebt_make_matchname(struct ebt_entry_match *m, 1321static int update_counters(struct net *net, const void __user *user,
1289 char *base, char __user *ubase) 1322 unsigned int len)
1323{
1324 struct ebt_replace hlp;
1325
1326 if (copy_from_user(&hlp, user, sizeof(hlp)))
1327 return -EFAULT;
1328
1329 if (len != sizeof(hlp) + hlp.num_counters * sizeof(struct ebt_counter))
1330 return -EINVAL;
1331
1332 return do_update_counters(net, hlp.name, hlp.counters,
1333 hlp.num_counters, user, len);
1334}
1335
1336static inline int ebt_make_matchname(const struct ebt_entry_match *m,
1337 const char *base, char __user *ubase)
1290{ 1338{
1291 char __user *hlp = ubase + ((char *)m - base); 1339 char __user *hlp = ubase + ((char *)m - base);
1292 if (copy_to_user(hlp, m->u.match->name, EBT_FUNCTION_MAXNAMELEN)) 1340 if (copy_to_user(hlp, m->u.match->name, EBT_FUNCTION_MAXNAMELEN))
@@ -1294,8 +1342,8 @@ static inline int ebt_make_matchname(struct ebt_entry_match *m,
1294 return 0; 1342 return 0;
1295} 1343}
1296 1344
1297static inline int ebt_make_watchername(struct ebt_entry_watcher *w, 1345static inline int ebt_make_watchername(const struct ebt_entry_watcher *w,
1298 char *base, char __user *ubase) 1346 const char *base, char __user *ubase)
1299{ 1347{
1300 char __user *hlp = ubase + ((char *)w - base); 1348 char __user *hlp = ubase + ((char *)w - base);
1301 if (copy_to_user(hlp , w->u.watcher->name, EBT_FUNCTION_MAXNAMELEN)) 1349 if (copy_to_user(hlp , w->u.watcher->name, EBT_FUNCTION_MAXNAMELEN))
@@ -1303,11 +1351,12 @@ static inline int ebt_make_watchername(struct ebt_entry_watcher *w,
1303 return 0; 1351 return 0;
1304} 1352}
1305 1353
1306static inline int ebt_make_names(struct ebt_entry *e, char *base, char __user *ubase) 1354static inline int
1355ebt_make_names(struct ebt_entry *e, const char *base, char __user *ubase)
1307{ 1356{
1308 int ret; 1357 int ret;
1309 char __user *hlp; 1358 char __user *hlp;
1310 struct ebt_entry_target *t; 1359 const struct ebt_entry_target *t;
1311 1360
1312 if (e->bitmask == 0) 1361 if (e->bitmask == 0)
1313 return 0; 1362 return 0;
@@ -1326,13 +1375,46 @@ static inline int ebt_make_names(struct ebt_entry *e, char *base, char __user *u
1326 return 0; 1375 return 0;
1327} 1376}
1328 1377
1378static int copy_counters_to_user(struct ebt_table *t,
1379 const struct ebt_counter *oldcounters,
1380 void __user *user, unsigned int num_counters,
1381 unsigned int nentries)
1382{
1383 struct ebt_counter *counterstmp;
1384 int ret = 0;
1385
1386 /* userspace might not need the counters */
1387 if (num_counters == 0)
1388 return 0;
1389
1390 if (num_counters != nentries) {
1391 BUGPRINT("Num_counters wrong\n");
1392 return -EINVAL;
1393 }
1394
1395 counterstmp = vmalloc(nentries * sizeof(*counterstmp));
1396 if (!counterstmp)
1397 return -ENOMEM;
1398
1399 write_lock_bh(&t->lock);
1400 get_counters(oldcounters, counterstmp, nentries);
1401 write_unlock_bh(&t->lock);
1402
1403 if (copy_to_user(user, counterstmp,
1404 nentries * sizeof(struct ebt_counter)))
1405 ret = -EFAULT;
1406 vfree(counterstmp);
1407 return ret;
1408}
1409
1329/* called with ebt_mutex locked */ 1410/* called with ebt_mutex locked */
1330static int copy_everything_to_user(struct ebt_table *t, void __user *user, 1411static int copy_everything_to_user(struct ebt_table *t, void __user *user,
1331 int *len, int cmd) 1412 const int *len, int cmd)
1332{ 1413{
1333 struct ebt_replace tmp; 1414 struct ebt_replace tmp;
1334 struct ebt_counter *counterstmp, *oldcounters; 1415 const struct ebt_counter *oldcounters;
1335 unsigned int entries_size, nentries; 1416 unsigned int entries_size, nentries;
1417 int ret;
1336 char *entries; 1418 char *entries;
1337 1419
1338 if (cmd == EBT_SO_GET_ENTRIES) { 1420 if (cmd == EBT_SO_GET_ENTRIES) {
@@ -1347,16 +1429,12 @@ static int copy_everything_to_user(struct ebt_table *t, void __user *user,
1347 oldcounters = t->table->counters; 1429 oldcounters = t->table->counters;
1348 } 1430 }
1349 1431
1350 if (copy_from_user(&tmp, user, sizeof(tmp))) { 1432 if (copy_from_user(&tmp, user, sizeof(tmp)))
1351 BUGPRINT("Cfu didn't work\n");
1352 return -EFAULT; 1433 return -EFAULT;
1353 }
1354 1434
1355 if (*len != sizeof(struct ebt_replace) + entries_size + 1435 if (*len != sizeof(struct ebt_replace) + entries_size +
1356 (tmp.num_counters? nentries * sizeof(struct ebt_counter): 0)) { 1436 (tmp.num_counters? nentries * sizeof(struct ebt_counter): 0))
1357 BUGPRINT("Wrong size\n");
1358 return -EINVAL; 1437 return -EINVAL;
1359 }
1360 1438
1361 if (tmp.nentries != nentries) { 1439 if (tmp.nentries != nentries) {
1362 BUGPRINT("Nentries wrong\n"); 1440 BUGPRINT("Nentries wrong\n");
@@ -1368,29 +1446,10 @@ static int copy_everything_to_user(struct ebt_table *t, void __user *user,
1368 return -EINVAL; 1446 return -EINVAL;
1369 } 1447 }
1370 1448
1371 /* userspace might not need the counters */ 1449 ret = copy_counters_to_user(t, oldcounters, tmp.counters,
1372 if (tmp.num_counters) { 1450 tmp.num_counters, nentries);
1373 if (tmp.num_counters != nentries) { 1451 if (ret)
1374 BUGPRINT("Num_counters wrong\n"); 1452 return ret;
1375 return -EINVAL;
1376 }
1377 counterstmp = vmalloc(nentries * sizeof(*counterstmp));
1378 if (!counterstmp) {
1379 MEMPRINT("Couldn't copy counters, out of memory\n");
1380 return -ENOMEM;
1381 }
1382 write_lock_bh(&t->lock);
1383 get_counters(oldcounters, counterstmp, nentries);
1384 write_unlock_bh(&t->lock);
1385
1386 if (copy_to_user(tmp.counters, counterstmp,
1387 nentries * sizeof(struct ebt_counter))) {
1388 BUGPRINT("Couldn't copy counters to userspace\n");
1389 vfree(counterstmp);
1390 return -EFAULT;
1391 }
1392 vfree(counterstmp);
1393 }
1394 1453
1395 if (copy_to_user(tmp.entries, entries, entries_size)) { 1454 if (copy_to_user(tmp.entries, entries, entries_size)) {
1396 BUGPRINT("Couldn't copy entries to userspace\n"); 1455 BUGPRINT("Couldn't copy entries to userspace\n");
@@ -1406,6 +1465,9 @@ static int do_ebt_set_ctl(struct sock *sk,
1406{ 1465{
1407 int ret; 1466 int ret;
1408 1467
1468 if (!capable(CAP_NET_ADMIN))
1469 return -EPERM;
1470
1409 switch(cmd) { 1471 switch(cmd) {
1410 case EBT_SO_SET_ENTRIES: 1472 case EBT_SO_SET_ENTRIES:
1411 ret = do_replace(sock_net(sk), user, len); 1473 ret = do_replace(sock_net(sk), user, len);
@@ -1415,7 +1477,7 @@ static int do_ebt_set_ctl(struct sock *sk,
1415 break; 1477 break;
1416 default: 1478 default:
1417 ret = -EINVAL; 1479 ret = -EINVAL;
1418 } 1480 }
1419 return ret; 1481 return ret;
1420} 1482}
1421 1483
@@ -1425,6 +1487,9 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
1425 struct ebt_replace tmp; 1487 struct ebt_replace tmp;
1426 struct ebt_table *t; 1488 struct ebt_table *t;
1427 1489
1490 if (!capable(CAP_NET_ADMIN))
1491 return -EPERM;
1492
1428 if (copy_from_user(&tmp, user, sizeof(tmp))) 1493 if (copy_from_user(&tmp, user, sizeof(tmp)))
1429 return -EFAULT; 1494 return -EFAULT;
1430 1495
@@ -1472,15 +1537,892 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
1472 return ret; 1537 return ret;
1473} 1538}
1474 1539
1540#ifdef CONFIG_COMPAT
1541/* 32 bit-userspace compatibility definitions. */
1542struct compat_ebt_replace {
1543 char name[EBT_TABLE_MAXNAMELEN];
1544 compat_uint_t valid_hooks;
1545 compat_uint_t nentries;
1546 compat_uint_t entries_size;
1547 /* start of the chains */
1548 compat_uptr_t hook_entry[NF_BR_NUMHOOKS];
1549 /* nr of counters userspace expects back */
1550 compat_uint_t num_counters;
1551 /* where the kernel will put the old counters. */
1552 compat_uptr_t counters;
1553 compat_uptr_t entries;
1554};
1555
1556/* struct ebt_entry_match, _target and _watcher have same layout */
1557struct compat_ebt_entry_mwt {
1558 union {
1559 char name[EBT_FUNCTION_MAXNAMELEN];
1560 compat_uptr_t ptr;
1561 } u;
1562 compat_uint_t match_size;
1563 compat_uint_t data[0];
1564};
1565
1566/* account for possible padding between match_size and ->data */
1567static int ebt_compat_entry_padsize(void)
1568{
1569 BUILD_BUG_ON(XT_ALIGN(sizeof(struct ebt_entry_match)) <
1570 COMPAT_XT_ALIGN(sizeof(struct compat_ebt_entry_mwt)));
1571 return (int) XT_ALIGN(sizeof(struct ebt_entry_match)) -
1572 COMPAT_XT_ALIGN(sizeof(struct compat_ebt_entry_mwt));
1573}
1574
1575static int ebt_compat_match_offset(const struct xt_match *match,
1576 unsigned int userlen)
1577{
1578 /*
1579 * ebt_among needs special handling. The kernel .matchsize is
1580 * set to -1 at registration time; at runtime an EBT_ALIGN()ed
1581 * value is expected.
1582 * Example: userspace sends 4500, ebt_among.c wants 4504.
1583 */
1584 if (unlikely(match->matchsize == -1))
1585 return XT_ALIGN(userlen) - COMPAT_XT_ALIGN(userlen);
1586 return xt_compat_match_offset(match);
1587}
1588
1589static int compat_match_to_user(struct ebt_entry_match *m, void __user **dstptr,
1590 unsigned int *size)
1591{
1592 const struct xt_match *match = m->u.match;
1593 struct compat_ebt_entry_mwt __user *cm = *dstptr;
1594 int off = ebt_compat_match_offset(match, m->match_size);
1595 compat_uint_t msize = m->match_size - off;
1596
1597 BUG_ON(off >= m->match_size);
1598
1599 if (copy_to_user(cm->u.name, match->name,
1600 strlen(match->name) + 1) || put_user(msize, &cm->match_size))
1601 return -EFAULT;
1602
1603 if (match->compat_to_user) {
1604 if (match->compat_to_user(cm->data, m->data))
1605 return -EFAULT;
1606 } else if (copy_to_user(cm->data, m->data, msize))
1607 return -EFAULT;
1608
1609 *size -= ebt_compat_entry_padsize() + off;
1610 *dstptr = cm->data;
1611 *dstptr += msize;
1612 return 0;
1613}
1614
1615static int compat_target_to_user(struct ebt_entry_target *t,
1616 void __user **dstptr,
1617 unsigned int *size)
1618{
1619 const struct xt_target *target = t->u.target;
1620 struct compat_ebt_entry_mwt __user *cm = *dstptr;
1621 int off = xt_compat_target_offset(target);
1622 compat_uint_t tsize = t->target_size - off;
1623
1624 BUG_ON(off >= t->target_size);
1625
1626 if (copy_to_user(cm->u.name, target->name,
1627 strlen(target->name) + 1) || put_user(tsize, &cm->match_size))
1628 return -EFAULT;
1629
1630 if (target->compat_to_user) {
1631 if (target->compat_to_user(cm->data, t->data))
1632 return -EFAULT;
1633 } else if (copy_to_user(cm->data, t->data, tsize))
1634 return -EFAULT;
1635
1636 *size -= ebt_compat_entry_padsize() + off;
1637 *dstptr = cm->data;
1638 *dstptr += tsize;
1639 return 0;
1640}
1641
1642static int compat_watcher_to_user(struct ebt_entry_watcher *w,
1643 void __user **dstptr,
1644 unsigned int *size)
1645{
1646 return compat_target_to_user((struct ebt_entry_target *)w,
1647 dstptr, size);
1648}
1649
1650static int compat_copy_entry_to_user(struct ebt_entry *e, void __user **dstptr,
1651 unsigned int *size)
1652{
1653 struct ebt_entry_target *t;
1654 struct ebt_entry __user *ce;
1655 u32 watchers_offset, target_offset, next_offset;
1656 compat_uint_t origsize;
1657 int ret;
1658
1659 if (e->bitmask == 0) {
1660 if (*size < sizeof(struct ebt_entries))
1661 return -EINVAL;
1662 if (copy_to_user(*dstptr, e, sizeof(struct ebt_entries)))
1663 return -EFAULT;
1664
1665 *dstptr += sizeof(struct ebt_entries);
1666 *size -= sizeof(struct ebt_entries);
1667 return 0;
1668 }
1669
1670 if (*size < sizeof(*ce))
1671 return -EINVAL;
1672
1673 ce = (struct ebt_entry __user *)*dstptr;
1674 if (copy_to_user(ce, e, sizeof(*ce)))
1675 return -EFAULT;
1676
1677 origsize = *size;
1678 *dstptr += sizeof(*ce);
1679
1680 ret = EBT_MATCH_ITERATE(e, compat_match_to_user, dstptr, size);
1681 if (ret)
1682 return ret;
1683 watchers_offset = e->watchers_offset - (origsize - *size);
1684
1685 ret = EBT_WATCHER_ITERATE(e, compat_watcher_to_user, dstptr, size);
1686 if (ret)
1687 return ret;
1688 target_offset = e->target_offset - (origsize - *size);
1689
1690 t = (struct ebt_entry_target *) ((char *) e + e->target_offset);
1691
1692 ret = compat_target_to_user(t, dstptr, size);
1693 if (ret)
1694 return ret;
1695 next_offset = e->next_offset - (origsize - *size);
1696
1697 if (put_user(watchers_offset, &ce->watchers_offset) ||
1698 put_user(target_offset, &ce->target_offset) ||
1699 put_user(next_offset, &ce->next_offset))
1700 return -EFAULT;
1701
1702 *size -= sizeof(*ce);
1703 return 0;
1704}
1705
1706static int compat_calc_match(struct ebt_entry_match *m, int *off)
1707{
1708 *off += ebt_compat_match_offset(m->u.match, m->match_size);
1709 *off += ebt_compat_entry_padsize();
1710 return 0;
1711}
1712
1713static int compat_calc_watcher(struct ebt_entry_watcher *w, int *off)
1714{
1715 *off += xt_compat_target_offset(w->u.watcher);
1716 *off += ebt_compat_entry_padsize();
1717 return 0;
1718}
1719
1720static int compat_calc_entry(const struct ebt_entry *e,
1721 const struct ebt_table_info *info,
1722 const void *base,
1723 struct compat_ebt_replace *newinfo)
1724{
1725 const struct ebt_entry_target *t;
1726 unsigned int entry_offset;
1727 int off, ret, i;
1728
1729 if (e->bitmask == 0)
1730 return 0;
1731
1732 off = 0;
1733 entry_offset = (void *)e - base;
1734
1735 EBT_MATCH_ITERATE(e, compat_calc_match, &off);
1736 EBT_WATCHER_ITERATE(e, compat_calc_watcher, &off);
1737
1738 t = (const struct ebt_entry_target *) ((char *) e + e->target_offset);
1739
1740 off += xt_compat_target_offset(t->u.target);
1741 off += ebt_compat_entry_padsize();
1742
1743 newinfo->entries_size -= off;
1744
1745 ret = xt_compat_add_offset(NFPROTO_BRIDGE, entry_offset, off);
1746 if (ret)
1747 return ret;
1748
1749 for (i = 0; i < NF_BR_NUMHOOKS; i++) {
1750 const void *hookptr = info->hook_entry[i];
1751 if (info->hook_entry[i] &&
1752 (e < (struct ebt_entry *)(base - hookptr))) {
1753 newinfo->hook_entry[i] -= off;
1754 pr_debug("0x%08X -> 0x%08X\n",
1755 newinfo->hook_entry[i] + off,
1756 newinfo->hook_entry[i]);
1757 }
1758 }
1759
1760 return 0;
1761}
1762
1763
1764static int compat_table_info(const struct ebt_table_info *info,
1765 struct compat_ebt_replace *newinfo)
1766{
1767 unsigned int size = info->entries_size;
1768 const void *entries = info->entries;
1769
1770 newinfo->entries_size = size;
1771
1772 return EBT_ENTRY_ITERATE(entries, size, compat_calc_entry, info,
1773 entries, newinfo);
1774}
1775
1776static int compat_copy_everything_to_user(struct ebt_table *t,
1777 void __user *user, int *len, int cmd)
1778{
1779 struct compat_ebt_replace repl, tmp;
1780 struct ebt_counter *oldcounters;
1781 struct ebt_table_info tinfo;
1782 int ret;
1783 void __user *pos;
1784
1785 memset(&tinfo, 0, sizeof(tinfo));
1786
1787 if (cmd == EBT_SO_GET_ENTRIES) {
1788 tinfo.entries_size = t->private->entries_size;
1789 tinfo.nentries = t->private->nentries;
1790 tinfo.entries = t->private->entries;
1791 oldcounters = t->private->counters;
1792 } else {
1793 tinfo.entries_size = t->table->entries_size;
1794 tinfo.nentries = t->table->nentries;
1795 tinfo.entries = t->table->entries;
1796 oldcounters = t->table->counters;
1797 }
1798
1799 if (copy_from_user(&tmp, user, sizeof(tmp)))
1800 return -EFAULT;
1801
1802 if (tmp.nentries != tinfo.nentries ||
1803 (tmp.num_counters && tmp.num_counters != tinfo.nentries))
1804 return -EINVAL;
1805
1806 memcpy(&repl, &tmp, sizeof(repl));
1807 if (cmd == EBT_SO_GET_ENTRIES)
1808 ret = compat_table_info(t->private, &repl);
1809 else
1810 ret = compat_table_info(&tinfo, &repl);
1811 if (ret)
1812 return ret;
1813
1814 if (*len != sizeof(tmp) + repl.entries_size +
1815 (tmp.num_counters? tinfo.nentries * sizeof(struct ebt_counter): 0)) {
1816 pr_err("wrong size: *len %d, entries_size %u, replsz %d\n",
1817 *len, tinfo.entries_size, repl.entries_size);
1818 return -EINVAL;
1819 }
1820
1821 /* userspace might not need the counters */
1822 ret = copy_counters_to_user(t, oldcounters, compat_ptr(tmp.counters),
1823 tmp.num_counters, tinfo.nentries);
1824 if (ret)
1825 return ret;
1826
1827 pos = compat_ptr(tmp.entries);
1828 return EBT_ENTRY_ITERATE(tinfo.entries, tinfo.entries_size,
1829 compat_copy_entry_to_user, &pos, &tmp.entries_size);
1830}
1831
1832struct ebt_entries_buf_state {
1833 char *buf_kern_start; /* kernel buffer to copy (translated) data to */
1834 u32 buf_kern_len; /* total size of kernel buffer */
1835 u32 buf_kern_offset; /* amount of data copied so far */
1836 u32 buf_user_offset; /* read position in userspace buffer */
1837};
1838
1839static int ebt_buf_count(struct ebt_entries_buf_state *state, unsigned int sz)
1840{
1841 state->buf_kern_offset += sz;
1842 return state->buf_kern_offset >= sz ? 0 : -EINVAL;
1843}
1844
1845static int ebt_buf_add(struct ebt_entries_buf_state *state,
1846 void *data, unsigned int sz)
1847{
1848 if (state->buf_kern_start == NULL)
1849 goto count_only;
1850
1851 BUG_ON(state->buf_kern_offset + sz > state->buf_kern_len);
1852
1853 memcpy(state->buf_kern_start + state->buf_kern_offset, data, sz);
1854
1855 count_only:
1856 state->buf_user_offset += sz;
1857 return ebt_buf_count(state, sz);
1858}
1859
1860static int ebt_buf_add_pad(struct ebt_entries_buf_state *state, unsigned int sz)
1861{
1862 char *b = state->buf_kern_start;
1863
1864 BUG_ON(b && state->buf_kern_offset > state->buf_kern_len);
1865
1866 if (b != NULL && sz > 0)
1867 memset(b + state->buf_kern_offset, 0, sz);
1868 /* do not adjust ->buf_user_offset here, we added kernel-side padding */
1869 return ebt_buf_count(state, sz);
1870}
1871
1872enum compat_mwt {
1873 EBT_COMPAT_MATCH,
1874 EBT_COMPAT_WATCHER,
1875 EBT_COMPAT_TARGET,
1876};
1877
1878static int compat_mtw_from_user(struct compat_ebt_entry_mwt *mwt,
1879 enum compat_mwt compat_mwt,
1880 struct ebt_entries_buf_state *state,
1881 const unsigned char *base)
1882{
1883 char name[EBT_FUNCTION_MAXNAMELEN];
1884 struct xt_match *match;
1885 struct xt_target *wt;
1886 void *dst = NULL;
1887 int off, pad = 0, ret = 0;
1888 unsigned int size_kern, entry_offset, match_size = mwt->match_size;
1889
1890 strlcpy(name, mwt->u.name, sizeof(name));
1891
1892 if (state->buf_kern_start)
1893 dst = state->buf_kern_start + state->buf_kern_offset;
1894
1895 entry_offset = (unsigned char *) mwt - base;
1896 switch (compat_mwt) {
1897 case EBT_COMPAT_MATCH:
1898 match = try_then_request_module(xt_find_match(NFPROTO_BRIDGE,
1899 name, 0), "ebt_%s", name);
1900 if (match == NULL)
1901 return -ENOENT;
1902 if (IS_ERR(match))
1903 return PTR_ERR(match);
1904
1905 off = ebt_compat_match_offset(match, match_size);
1906 if (dst) {
1907 if (match->compat_from_user)
1908 match->compat_from_user(dst, mwt->data);
1909 else
1910 memcpy(dst, mwt->data, match_size);
1911 }
1912
1913 size_kern = match->matchsize;
1914 if (unlikely(size_kern == -1))
1915 size_kern = match_size;
1916 module_put(match->me);
1917 break;
1918 case EBT_COMPAT_WATCHER: /* fallthrough */
1919 case EBT_COMPAT_TARGET:
1920 wt = try_then_request_module(xt_find_target(NFPROTO_BRIDGE,
1921 name, 0), "ebt_%s", name);
1922 if (wt == NULL)
1923 return -ENOENT;
1924 if (IS_ERR(wt))
1925 return PTR_ERR(wt);
1926 off = xt_compat_target_offset(wt);
1927
1928 if (dst) {
1929 if (wt->compat_from_user)
1930 wt->compat_from_user(dst, mwt->data);
1931 else
1932 memcpy(dst, mwt->data, match_size);
1933 }
1934
1935 size_kern = wt->targetsize;
1936 module_put(wt->me);
1937 break;
1938 }
1939
1940 if (!dst) {
1941 ret = xt_compat_add_offset(NFPROTO_BRIDGE, entry_offset,
1942 off + ebt_compat_entry_padsize());
1943 if (ret < 0)
1944 return ret;
1945 }
1946
1947 state->buf_kern_offset += match_size + off;
1948 state->buf_user_offset += match_size;
1949 pad = XT_ALIGN(size_kern) - size_kern;
1950
1951 if (pad > 0 && dst) {
1952 BUG_ON(state->buf_kern_len <= pad);
1953 BUG_ON(state->buf_kern_offset - (match_size + off) + size_kern > state->buf_kern_len - pad);
1954 memset(dst + size_kern, 0, pad);
1955 }
1956 return off + match_size;
1957}
1958
1959/*
1960 * return size of all matches, watchers or target, including necessary
1961 * alignment and padding.
1962 */
1963static int ebt_size_mwt(struct compat_ebt_entry_mwt *match32,
1964 unsigned int size_left, enum compat_mwt type,
1965 struct ebt_entries_buf_state *state, const void *base)
1966{
1967 int growth = 0;
1968 char *buf;
1969
1970 if (size_left == 0)
1971 return 0;
1972
1973 buf = (char *) match32;
1974
1975 while (size_left >= sizeof(*match32)) {
1976 struct ebt_entry_match *match_kern;
1977 int ret;
1978
1979 match_kern = (struct ebt_entry_match *) state->buf_kern_start;
1980 if (match_kern) {
1981 char *tmp;
1982 tmp = state->buf_kern_start + state->buf_kern_offset;
1983 match_kern = (struct ebt_entry_match *) tmp;
1984 }
1985 ret = ebt_buf_add(state, buf, sizeof(*match32));
1986 if (ret < 0)
1987 return ret;
1988 size_left -= sizeof(*match32);
1989
1990 /* add padding before match->data (if any) */
1991 ret = ebt_buf_add_pad(state, ebt_compat_entry_padsize());
1992 if (ret < 0)
1993 return ret;
1994
1995 if (match32->match_size > size_left)
1996 return -EINVAL;
1997
1998 size_left -= match32->match_size;
1999
2000 ret = compat_mtw_from_user(match32, type, state, base);
2001 if (ret < 0)
2002 return ret;
2003
2004 BUG_ON(ret < match32->match_size);
2005 growth += ret - match32->match_size;
2006 growth += ebt_compat_entry_padsize();
2007
2008 buf += sizeof(*match32);
2009 buf += match32->match_size;
2010
2011 if (match_kern)
2012 match_kern->match_size = ret;
2013
2014 WARN_ON(type == EBT_COMPAT_TARGET && size_left);
2015 match32 = (struct compat_ebt_entry_mwt *) buf;
2016 }
2017
2018 return growth;
2019}
2020
2021#define EBT_COMPAT_WATCHER_ITERATE(e, fn, args...) \
2022({ \
2023 unsigned int __i; \
2024 int __ret = 0; \
2025 struct compat_ebt_entry_mwt *__watcher; \
2026 \
2027 for (__i = e->watchers_offset; \
2028 __i < (e)->target_offset; \
2029 __i += __watcher->watcher_size + \
2030 sizeof(struct compat_ebt_entry_mwt)) { \
2031 __watcher = (void *)(e) + __i; \
2032 __ret = fn(__watcher , ## args); \
2033 if (__ret != 0) \
2034 break; \
2035 } \
2036 if (__ret == 0) { \
2037 if (__i != (e)->target_offset) \
2038 __ret = -EINVAL; \
2039 } \
2040 __ret; \
2041})
2042
2043#define EBT_COMPAT_MATCH_ITERATE(e, fn, args...) \
2044({ \
2045 unsigned int __i; \
2046 int __ret = 0; \
2047 struct compat_ebt_entry_mwt *__match; \
2048 \
2049 for (__i = sizeof(struct ebt_entry); \
2050 __i < (e)->watchers_offset; \
2051 __i += __match->match_size + \
2052 sizeof(struct compat_ebt_entry_mwt)) { \
2053 __match = (void *)(e) + __i; \
2054 __ret = fn(__match , ## args); \
2055 if (__ret != 0) \
2056 break; \
2057 } \
2058 if (__ret == 0) { \
2059 if (__i != (e)->watchers_offset) \
2060 __ret = -EINVAL; \
2061 } \
2062 __ret; \
2063})
2064
2065/* called for all ebt_entry structures. */
2066static int size_entry_mwt(struct ebt_entry *entry, const unsigned char *base,
2067 unsigned int *total,
2068 struct ebt_entries_buf_state *state)
2069{
2070 unsigned int i, j, startoff, new_offset = 0;
2071 /* stores match/watchers/targets & offset of next struct ebt_entry: */
2072 unsigned int offsets[4];
2073 unsigned int *offsets_update = NULL;
2074 int ret;
2075 char *buf_start;
2076
2077 if (*total < sizeof(struct ebt_entries))
2078 return -EINVAL;
2079
2080 if (!entry->bitmask) {
2081 *total -= sizeof(struct ebt_entries);
2082 return ebt_buf_add(state, entry, sizeof(struct ebt_entries));
2083 }
2084 if (*total < sizeof(*entry) || entry->next_offset < sizeof(*entry))
2085 return -EINVAL;
2086
2087 startoff = state->buf_user_offset;
2088 /* pull in most part of ebt_entry, it does not need to be changed. */
2089 ret = ebt_buf_add(state, entry,
2090 offsetof(struct ebt_entry, watchers_offset));
2091 if (ret < 0)
2092 return ret;
2093
2094 offsets[0] = sizeof(struct ebt_entry); /* matches come first */
2095 memcpy(&offsets[1], &entry->watchers_offset,
2096 sizeof(offsets) - sizeof(offsets[0]));
2097
2098 if (state->buf_kern_start) {
2099 buf_start = state->buf_kern_start + state->buf_kern_offset;
2100 offsets_update = (unsigned int *) buf_start;
2101 }
2102 ret = ebt_buf_add(state, &offsets[1],
2103 sizeof(offsets) - sizeof(offsets[0]));
2104 if (ret < 0)
2105 return ret;
2106 buf_start = (char *) entry;
2107 /*
2108 * 0: matches offset, always follows ebt_entry.
2109 * 1: watchers offset, from ebt_entry structure
2110 * 2: target offset, from ebt_entry structure
2111 * 3: next ebt_entry offset, from ebt_entry structure
2112 *
2113 * offsets are relative to beginning of struct ebt_entry (i.e., 0).
2114 */
2115 for (i = 0, j = 1 ; j < 4 ; j++, i++) {
2116 struct compat_ebt_entry_mwt *match32;
2117 unsigned int size;
2118 char *buf = buf_start;
2119
2120 buf = buf_start + offsets[i];
2121 if (offsets[i] > offsets[j])
2122 return -EINVAL;
2123
2124 match32 = (struct compat_ebt_entry_mwt *) buf;
2125 size = offsets[j] - offsets[i];
2126 ret = ebt_size_mwt(match32, size, i, state, base);
2127 if (ret < 0)
2128 return ret;
2129 new_offset += ret;
2130 if (offsets_update && new_offset) {
2131 pr_debug("ebtables: change offset %d to %d\n",
2132 offsets_update[i], offsets[j] + new_offset);
2133 offsets_update[i] = offsets[j] + new_offset;
2134 }
2135 }
2136
2137 startoff = state->buf_user_offset - startoff;
2138
2139 BUG_ON(*total < startoff);
2140 *total -= startoff;
2141 return 0;
2142}
2143
2144/*
2145 * repl->entries_size is the size of the ebt_entry blob in userspace.
2146 * It might need more memory when copied to a 64 bit kernel in case
2147 * userspace is 32-bit. So, first task: find out how much memory is needed.
2148 *
2149 * Called before validation is performed.
2150 */
2151static int compat_copy_entries(unsigned char *data, unsigned int size_user,
2152 struct ebt_entries_buf_state *state)
2153{
2154 unsigned int size_remaining = size_user;
2155 int ret;
2156
2157 ret = EBT_ENTRY_ITERATE(data, size_user, size_entry_mwt, data,
2158 &size_remaining, state);
2159 if (ret < 0)
2160 return ret;
2161
2162 WARN_ON(size_remaining);
2163 return state->buf_kern_offset;
2164}
2165
2166
2167static int compat_copy_ebt_replace_from_user(struct ebt_replace *repl,
2168 void __user *user, unsigned int len)
2169{
2170 struct compat_ebt_replace tmp;
2171 int i;
2172
2173 if (len < sizeof(tmp))
2174 return -EINVAL;
2175
2176 if (copy_from_user(&tmp, user, sizeof(tmp)))
2177 return -EFAULT;
2178
2179 if (len != sizeof(tmp) + tmp.entries_size)
2180 return -EINVAL;
2181
2182 if (tmp.entries_size == 0)
2183 return -EINVAL;
2184
2185 if (tmp.nentries >= ((INT_MAX - sizeof(struct ebt_table_info)) /
2186 NR_CPUS - SMP_CACHE_BYTES) / sizeof(struct ebt_counter))
2187 return -ENOMEM;
2188 if (tmp.num_counters >= INT_MAX / sizeof(struct ebt_counter))
2189 return -ENOMEM;
2190
2191 memcpy(repl, &tmp, offsetof(struct ebt_replace, hook_entry));
2192
2193 /* starting with hook_entry, 32 vs. 64 bit structures are different */
2194 for (i = 0; i < NF_BR_NUMHOOKS; i++)
2195 repl->hook_entry[i] = compat_ptr(tmp.hook_entry[i]);
2196
2197 repl->num_counters = tmp.num_counters;
2198 repl->counters = compat_ptr(tmp.counters);
2199 repl->entries = compat_ptr(tmp.entries);
2200 return 0;
2201}
2202
2203static int compat_do_replace(struct net *net, void __user *user,
2204 unsigned int len)
2205{
2206 int ret, i, countersize, size64;
2207 struct ebt_table_info *newinfo;
2208 struct ebt_replace tmp;
2209 struct ebt_entries_buf_state state;
2210 void *entries_tmp;
2211
2212 ret = compat_copy_ebt_replace_from_user(&tmp, user, len);
2213 if (ret) {
2214 /* try real handler in case userland supplied needed padding */
2215 if (ret == -EINVAL && do_replace(net, user, len) == 0)
2216 ret = 0;
2217 return ret;
2218 }
2219
2220 countersize = COUNTER_OFFSET(tmp.nentries) * nr_cpu_ids;
2221 newinfo = vmalloc(sizeof(*newinfo) + countersize);
2222 if (!newinfo)
2223 return -ENOMEM;
2224
2225 if (countersize)
2226 memset(newinfo->counters, 0, countersize);
2227
2228 memset(&state, 0, sizeof(state));
2229
2230 newinfo->entries = vmalloc(tmp.entries_size);
2231 if (!newinfo->entries) {
2232 ret = -ENOMEM;
2233 goto free_newinfo;
2234 }
2235 if (copy_from_user(
2236 newinfo->entries, tmp.entries, tmp.entries_size) != 0) {
2237 ret = -EFAULT;
2238 goto free_entries;
2239 }
2240
2241 entries_tmp = newinfo->entries;
2242
2243 xt_compat_lock(NFPROTO_BRIDGE);
2244
2245 ret = compat_copy_entries(entries_tmp, tmp.entries_size, &state);
2246 if (ret < 0)
2247 goto out_unlock;
2248
2249 pr_debug("tmp.entries_size %d, kern off %d, user off %d delta %d\n",
2250 tmp.entries_size, state.buf_kern_offset, state.buf_user_offset,
2251 xt_compat_calc_jump(NFPROTO_BRIDGE, tmp.entries_size));
2252
2253 size64 = ret;
2254 newinfo->entries = vmalloc(size64);
2255 if (!newinfo->entries) {
2256 vfree(entries_tmp);
2257 ret = -ENOMEM;
2258 goto out_unlock;
2259 }
2260
2261 memset(&state, 0, sizeof(state));
2262 state.buf_kern_start = newinfo->entries;
2263 state.buf_kern_len = size64;
2264
2265 ret = compat_copy_entries(entries_tmp, tmp.entries_size, &state);
2266 BUG_ON(ret < 0); /* parses same data again */
2267
2268 vfree(entries_tmp);
2269 tmp.entries_size = size64;
2270
2271 for (i = 0; i < NF_BR_NUMHOOKS; i++) {
2272 char __user *usrptr;
2273 if (tmp.hook_entry[i]) {
2274 unsigned int delta;
2275 usrptr = (char __user *) tmp.hook_entry[i];
2276 delta = usrptr - tmp.entries;
2277 usrptr += xt_compat_calc_jump(NFPROTO_BRIDGE, delta);
2278 tmp.hook_entry[i] = (struct ebt_entries __user *)usrptr;
2279 }
2280 }
2281
2282 xt_compat_flush_offsets(NFPROTO_BRIDGE);
2283 xt_compat_unlock(NFPROTO_BRIDGE);
2284
2285 ret = do_replace_finish(net, &tmp, newinfo);
2286 if (ret == 0)
2287 return ret;
2288free_entries:
2289 vfree(newinfo->entries);
2290free_newinfo:
2291 vfree(newinfo);
2292 return ret;
2293out_unlock:
2294 xt_compat_flush_offsets(NFPROTO_BRIDGE);
2295 xt_compat_unlock(NFPROTO_BRIDGE);
2296 goto free_entries;
2297}
2298
2299static int compat_update_counters(struct net *net, void __user *user,
2300 unsigned int len)
2301{
2302 struct compat_ebt_replace hlp;
2303
2304 if (copy_from_user(&hlp, user, sizeof(hlp)))
2305 return -EFAULT;
2306
2307 /* try real handler in case userland supplied needed padding */
2308 if (len != sizeof(hlp) + hlp.num_counters * sizeof(struct ebt_counter))
2309 return update_counters(net, user, len);
2310
2311 return do_update_counters(net, hlp.name, compat_ptr(hlp.counters),
2312 hlp.num_counters, user, len);
2313}
2314
2315static int compat_do_ebt_set_ctl(struct sock *sk,
2316 int cmd, void __user *user, unsigned int len)
2317{
2318 int ret;
2319
2320 if (!capable(CAP_NET_ADMIN))
2321 return -EPERM;
2322
2323 switch (cmd) {
2324 case EBT_SO_SET_ENTRIES:
2325 ret = compat_do_replace(sock_net(sk), user, len);
2326 break;
2327 case EBT_SO_SET_COUNTERS:
2328 ret = compat_update_counters(sock_net(sk), user, len);
2329 break;
2330 default:
2331 ret = -EINVAL;
2332 }
2333 return ret;
2334}
2335
2336static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
2337 void __user *user, int *len)
2338{
2339 int ret;
2340 struct compat_ebt_replace tmp;
2341 struct ebt_table *t;
2342
2343 if (!capable(CAP_NET_ADMIN))
2344 return -EPERM;
2345
2346 /* try real handler in case userland supplied needed padding */
2347 if ((cmd == EBT_SO_GET_INFO ||
2348 cmd == EBT_SO_GET_INIT_INFO) && *len != sizeof(tmp))
2349 return do_ebt_get_ctl(sk, cmd, user, len);
2350
2351 if (copy_from_user(&tmp, user, sizeof(tmp)))
2352 return -EFAULT;
2353
2354 t = find_table_lock(sock_net(sk), tmp.name, &ret, &ebt_mutex);
2355 if (!t)
2356 return ret;
2357
2358 xt_compat_lock(NFPROTO_BRIDGE);
2359 switch (cmd) {
2360 case EBT_SO_GET_INFO:
2361 tmp.nentries = t->private->nentries;
2362 ret = compat_table_info(t->private, &tmp);
2363 if (ret)
2364 goto out;
2365 tmp.valid_hooks = t->valid_hooks;
2366
2367 if (copy_to_user(user, &tmp, *len) != 0) {
2368 ret = -EFAULT;
2369 break;
2370 }
2371 ret = 0;
2372 break;
2373 case EBT_SO_GET_INIT_INFO:
2374 tmp.nentries = t->table->nentries;
2375 tmp.entries_size = t->table->entries_size;
2376 tmp.valid_hooks = t->table->valid_hooks;
2377
2378 if (copy_to_user(user, &tmp, *len) != 0) {
2379 ret = -EFAULT;
2380 break;
2381 }
2382 ret = 0;
2383 break;
2384 case EBT_SO_GET_ENTRIES:
2385 case EBT_SO_GET_INIT_ENTRIES:
2386 /*
2387 * try real handler first in case of userland-side padding.
2388 * in case we are dealing with an 'ordinary' 32 bit binary
2389 * without 64bit compatibility padding, this will fail right
2390 * after copy_from_user when the *len argument is validated.
2391 *
2392 * the compat_ variant needs to do one pass over the kernel
2393 * data set to adjust for size differences before it the check.
2394 */
2395 if (copy_everything_to_user(t, user, len, cmd) == 0)
2396 ret = 0;
2397 else
2398 ret = compat_copy_everything_to_user(t, user, len, cmd);
2399 break;
2400 default:
2401 ret = -EINVAL;
2402 }
2403 out:
2404 xt_compat_flush_offsets(NFPROTO_BRIDGE);
2405 xt_compat_unlock(NFPROTO_BRIDGE);
2406 mutex_unlock(&ebt_mutex);
2407 return ret;
2408}
2409#endif
2410
1475static struct nf_sockopt_ops ebt_sockopts = 2411static struct nf_sockopt_ops ebt_sockopts =
1476{ 2412{
1477 .pf = PF_INET, 2413 .pf = PF_INET,
1478 .set_optmin = EBT_BASE_CTL, 2414 .set_optmin = EBT_BASE_CTL,
1479 .set_optmax = EBT_SO_SET_MAX + 1, 2415 .set_optmax = EBT_SO_SET_MAX + 1,
1480 .set = do_ebt_set_ctl, 2416 .set = do_ebt_set_ctl,
2417#ifdef CONFIG_COMPAT
2418 .compat_set = compat_do_ebt_set_ctl,
2419#endif
1481 .get_optmin = EBT_BASE_CTL, 2420 .get_optmin = EBT_BASE_CTL,
1482 .get_optmax = EBT_SO_GET_MAX + 1, 2421 .get_optmax = EBT_SO_GET_MAX + 1,
1483 .get = do_ebt_get_ctl, 2422 .get = do_ebt_get_ctl,
2423#ifdef CONFIG_COMPAT
2424 .compat_get = compat_do_ebt_get_ctl,
2425#endif
1484 .owner = THIS_MODULE, 2426 .owner = THIS_MODULE,
1485}; 2427};
1486 2428
diff --git a/net/can/af_can.c b/net/can/af_can.c
index 606832115674..702be5a2c956 100644
--- a/net/can/af_can.c
+++ b/net/can/af_can.c
@@ -77,8 +77,8 @@ static int stats_timer __read_mostly = 1;
77module_param(stats_timer, int, S_IRUGO); 77module_param(stats_timer, int, S_IRUGO);
78MODULE_PARM_DESC(stats_timer, "enable timer for statistics (default:on)"); 78MODULE_PARM_DESC(stats_timer, "enable timer for statistics (default:on)");
79 79
80HLIST_HEAD(can_rx_dev_list); 80/* receive filters subscribed for 'all' CAN devices */
81static struct dev_rcv_lists can_rx_alldev_list; 81struct dev_rcv_lists can_rx_alldev_list;
82static DEFINE_SPINLOCK(can_rcvlists_lock); 82static DEFINE_SPINLOCK(can_rcvlists_lock);
83 83
84static struct kmem_cache *rcv_cache __read_mostly; 84static struct kmem_cache *rcv_cache __read_mostly;
@@ -114,7 +114,8 @@ static void can_sock_destruct(struct sock *sk)
114 skb_queue_purge(&sk->sk_receive_queue); 114 skb_queue_purge(&sk->sk_receive_queue);
115} 115}
116 116
117static int can_create(struct net *net, struct socket *sock, int protocol) 117static int can_create(struct net *net, struct socket *sock, int protocol,
118 int kern)
118{ 119{
119 struct sock *sk; 120 struct sock *sk;
120 struct can_proto *cp; 121 struct can_proto *cp;
@@ -125,7 +126,7 @@ static int can_create(struct net *net, struct socket *sock, int protocol)
125 if (protocol < 0 || protocol >= CAN_NPROTO) 126 if (protocol < 0 || protocol >= CAN_NPROTO)
126 return -EINVAL; 127 return -EINVAL;
127 128
128 if (net != &init_net) 129 if (!net_eq(net, &init_net))
129 return -EAFNOSUPPORT; 130 return -EAFNOSUPPORT;
130 131
131#ifdef CONFIG_MODULES 132#ifdef CONFIG_MODULES
@@ -160,11 +161,6 @@ static int can_create(struct net *net, struct socket *sock, int protocol)
160 goto errout; 161 goto errout;
161 } 162 }
162 163
163 if (cp->capability >= 0 && !capable(cp->capability)) {
164 err = -EPERM;
165 goto errout;
166 }
167
168 sock->ops = cp->ops; 164 sock->ops = cp->ops;
169 165
170 sk = sk_alloc(net, PF_CAN, GFP_KERNEL, cp->prot); 166 sk = sk_alloc(net, PF_CAN, GFP_KERNEL, cp->prot);
@@ -296,28 +292,10 @@ EXPORT_SYMBOL(can_send);
296 292
297static struct dev_rcv_lists *find_dev_rcv_lists(struct net_device *dev) 293static struct dev_rcv_lists *find_dev_rcv_lists(struct net_device *dev)
298{ 294{
299 struct dev_rcv_lists *d = NULL; 295 if (!dev)
300 struct hlist_node *n; 296 return &can_rx_alldev_list;
301 297 else
302 /* 298 return (struct dev_rcv_lists *)dev->ml_priv;
303 * find receive list for this device
304 *
305 * The hlist_for_each_entry*() macros curse through the list
306 * using the pointer variable n and set d to the containing
307 * struct in each list iteration. Therefore, after list
308 * iteration, d is unmodified when the list is empty, and it
309 * points to last list element, when the list is non-empty
310 * but no match in the loop body is found. I.e. d is *not*
311 * NULL when no match is found. We can, however, use the
312 * cursor variable n to decide if a match was found.
313 */
314
315 hlist_for_each_entry_rcu(d, n, &can_rx_dev_list, list) {
316 if (d->dev == dev)
317 break;
318 }
319
320 return n ? d : NULL;
321} 299}
322 300
323/** 301/**
@@ -379,8 +357,8 @@ static struct hlist_head *find_rcv_list(canid_t *can_id, canid_t *mask,
379 return &d->rx[RX_ALL]; 357 return &d->rx[RX_ALL];
380 358
381 /* extra filterlists for the subscription of a single non-RTR can_id */ 359 /* extra filterlists for the subscription of a single non-RTR can_id */
382 if (((*mask & CAN_EFF_RTR_FLAGS) == CAN_EFF_RTR_FLAGS) 360 if (((*mask & CAN_EFF_RTR_FLAGS) == CAN_EFF_RTR_FLAGS) &&
383 && !(*can_id & CAN_RTR_FLAG)) { 361 !(*can_id & CAN_RTR_FLAG)) {
384 362
385 if (*can_id & CAN_EFF_FLAG) { 363 if (*can_id & CAN_EFF_FLAG) {
386 if (*mask == (CAN_EFF_MASK | CAN_EFF_RTR_FLAGS)) { 364 if (*mask == (CAN_EFF_MASK | CAN_EFF_RTR_FLAGS)) {
@@ -437,6 +415,9 @@ int can_rx_register(struct net_device *dev, canid_t can_id, canid_t mask,
437 415
438 /* insert new receiver (dev,canid,mask) -> (func,data) */ 416 /* insert new receiver (dev,canid,mask) -> (func,data) */
439 417
418 if (dev && dev->type != ARPHRD_CAN)
419 return -ENODEV;
420
440 r = kmem_cache_alloc(rcv_cache, GFP_KERNEL); 421 r = kmem_cache_alloc(rcv_cache, GFP_KERNEL);
441 if (!r) 422 if (!r)
442 return -ENOMEM; 423 return -ENOMEM;
@@ -472,16 +453,6 @@ int can_rx_register(struct net_device *dev, canid_t can_id, canid_t mask,
472EXPORT_SYMBOL(can_rx_register); 453EXPORT_SYMBOL(can_rx_register);
473 454
474/* 455/*
475 * can_rx_delete_device - rcu callback for dev_rcv_lists structure removal
476 */
477static void can_rx_delete_device(struct rcu_head *rp)
478{
479 struct dev_rcv_lists *d = container_of(rp, struct dev_rcv_lists, rcu);
480
481 kfree(d);
482}
483
484/*
485 * can_rx_delete_receiver - rcu callback for single receiver entry removal 456 * can_rx_delete_receiver - rcu callback for single receiver entry removal
486 */ 457 */
487static void can_rx_delete_receiver(struct rcu_head *rp) 458static void can_rx_delete_receiver(struct rcu_head *rp)
@@ -510,6 +481,9 @@ void can_rx_unregister(struct net_device *dev, canid_t can_id, canid_t mask,
510 struct hlist_node *next; 481 struct hlist_node *next;
511 struct dev_rcv_lists *d; 482 struct dev_rcv_lists *d;
512 483
484 if (dev && dev->type != ARPHRD_CAN)
485 return;
486
513 spin_lock(&can_rcvlists_lock); 487 spin_lock(&can_rcvlists_lock);
514 488
515 d = find_dev_rcv_lists(dev); 489 d = find_dev_rcv_lists(dev);
@@ -529,8 +503,8 @@ void can_rx_unregister(struct net_device *dev, canid_t can_id, canid_t mask,
529 */ 503 */
530 504
531 hlist_for_each_entry_rcu(r, next, rl, list) { 505 hlist_for_each_entry_rcu(r, next, rl, list) {
532 if (r->can_id == can_id && r->mask == mask 506 if (r->can_id == can_id && r->mask == mask &&
533 && r->func == func && r->data == data) 507 r->func == func && r->data == data)
534 break; 508 break;
535 } 509 }
536 510
@@ -545,7 +519,6 @@ void can_rx_unregister(struct net_device *dev, canid_t can_id, canid_t mask,
545 "dev %s, id %03X, mask %03X\n", 519 "dev %s, id %03X, mask %03X\n",
546 DNAME(dev), can_id, mask); 520 DNAME(dev), can_id, mask);
547 r = NULL; 521 r = NULL;
548 d = NULL;
549 goto out; 522 goto out;
550 } 523 }
551 524
@@ -556,10 +529,10 @@ void can_rx_unregister(struct net_device *dev, canid_t can_id, canid_t mask,
556 can_pstats.rcv_entries--; 529 can_pstats.rcv_entries--;
557 530
558 /* remove device structure requested by NETDEV_UNREGISTER */ 531 /* remove device structure requested by NETDEV_UNREGISTER */
559 if (d->remove_on_zero_entries && !d->entries) 532 if (d->remove_on_zero_entries && !d->entries) {
560 hlist_del_rcu(&d->list); 533 kfree(d);
561 else 534 dev->ml_priv = NULL;
562 d = NULL; 535 }
563 536
564 out: 537 out:
565 spin_unlock(&can_rcvlists_lock); 538 spin_unlock(&can_rcvlists_lock);
@@ -567,10 +540,6 @@ void can_rx_unregister(struct net_device *dev, canid_t can_id, canid_t mask,
567 /* schedule the receiver item for deletion */ 540 /* schedule the receiver item for deletion */
568 if (r) 541 if (r)
569 call_rcu(&r->rcu, can_rx_delete_receiver); 542 call_rcu(&r->rcu, can_rx_delete_receiver);
570
571 /* schedule the device structure for deletion */
572 if (d)
573 call_rcu(&d->rcu, can_rx_delete_device);
574} 543}
575EXPORT_SYMBOL(can_rx_unregister); 544EXPORT_SYMBOL(can_rx_unregister);
576 545
@@ -784,48 +753,35 @@ static int can_notifier(struct notifier_block *nb, unsigned long msg,
784 753
785 case NETDEV_REGISTER: 754 case NETDEV_REGISTER:
786 755
787 /* 756 /* create new dev_rcv_lists for this device */
788 * create new dev_rcv_lists for this device
789 *
790 * N.B. zeroing the struct is the correct initialization
791 * for the embedded hlist_head structs.
792 * Another list type, e.g. list_head, would require
793 * explicit initialization.
794 */
795
796 d = kzalloc(sizeof(*d), GFP_KERNEL); 757 d = kzalloc(sizeof(*d), GFP_KERNEL);
797 if (!d) { 758 if (!d) {
798 printk(KERN_ERR 759 printk(KERN_ERR
799 "can: allocation of receive list failed\n"); 760 "can: allocation of receive list failed\n");
800 return NOTIFY_DONE; 761 return NOTIFY_DONE;
801 } 762 }
802 d->dev = dev; 763 BUG_ON(dev->ml_priv);
803 764 dev->ml_priv = d;
804 spin_lock(&can_rcvlists_lock);
805 hlist_add_head_rcu(&d->list, &can_rx_dev_list);
806 spin_unlock(&can_rcvlists_lock);
807 765
808 break; 766 break;
809 767
810 case NETDEV_UNREGISTER: 768 case NETDEV_UNREGISTER:
811 spin_lock(&can_rcvlists_lock); 769 spin_lock(&can_rcvlists_lock);
812 770
813 d = find_dev_rcv_lists(dev); 771 d = dev->ml_priv;
814 if (d) { 772 if (d) {
815 if (d->entries) { 773 if (d->entries)
816 d->remove_on_zero_entries = 1; 774 d->remove_on_zero_entries = 1;
817 d = NULL; 775 else {
818 } else 776 kfree(d);
819 hlist_del_rcu(&d->list); 777 dev->ml_priv = NULL;
778 }
820 } else 779 } else
821 printk(KERN_ERR "can: notifier: receive list not " 780 printk(KERN_ERR "can: notifier: receive list not "
822 "found for dev %s\n", dev->name); 781 "found for dev %s\n", dev->name);
823 782
824 spin_unlock(&can_rcvlists_lock); 783 spin_unlock(&can_rcvlists_lock);
825 784
826 if (d)
827 call_rcu(&d->rcu, can_rx_delete_device);
828
829 break; 785 break;
830 } 786 }
831 787
@@ -842,7 +798,7 @@ static struct packet_type can_packet __read_mostly = {
842 .func = can_rcv, 798 .func = can_rcv,
843}; 799};
844 800
845static struct net_proto_family can_family_ops __read_mostly = { 801static const struct net_proto_family can_family_ops = {
846 .family = PF_CAN, 802 .family = PF_CAN,
847 .create = can_create, 803 .create = can_create,
848 .owner = THIS_MODULE, 804 .owner = THIS_MODULE,
@@ -857,21 +813,13 @@ static __init int can_init(void)
857{ 813{
858 printk(banner); 814 printk(banner);
859 815
816 memset(&can_rx_alldev_list, 0, sizeof(can_rx_alldev_list));
817
860 rcv_cache = kmem_cache_create("can_receiver", sizeof(struct receiver), 818 rcv_cache = kmem_cache_create("can_receiver", sizeof(struct receiver),
861 0, 0, NULL); 819 0, 0, NULL);
862 if (!rcv_cache) 820 if (!rcv_cache)
863 return -ENOMEM; 821 return -ENOMEM;
864 822
865 /*
866 * Insert can_rx_alldev_list for reception on all devices.
867 * This struct is zero initialized which is correct for the
868 * embedded hlist heads, the dev pointer, and the entries counter.
869 */
870
871 spin_lock(&can_rcvlists_lock);
872 hlist_add_head_rcu(&can_rx_alldev_list.list, &can_rx_dev_list);
873 spin_unlock(&can_rcvlists_lock);
874
875 if (stats_timer) { 823 if (stats_timer) {
876 /* the statistics are updated every second (timer triggered) */ 824 /* the statistics are updated every second (timer triggered) */
877 setup_timer(&can_stattimer, can_stat_update, 0); 825 setup_timer(&can_stattimer, can_stat_update, 0);
@@ -891,8 +839,7 @@ static __init int can_init(void)
891 839
892static __exit void can_exit(void) 840static __exit void can_exit(void)
893{ 841{
894 struct dev_rcv_lists *d; 842 struct net_device *dev;
895 struct hlist_node *n, *next;
896 843
897 if (stats_timer) 844 if (stats_timer)
898 del_timer(&can_stattimer); 845 del_timer(&can_stattimer);
@@ -904,14 +851,19 @@ static __exit void can_exit(void)
904 unregister_netdevice_notifier(&can_netdev_notifier); 851 unregister_netdevice_notifier(&can_netdev_notifier);
905 sock_unregister(PF_CAN); 852 sock_unregister(PF_CAN);
906 853
907 /* remove can_rx_dev_list */ 854 /* remove created dev_rcv_lists from still registered CAN devices */
908 spin_lock(&can_rcvlists_lock); 855 rcu_read_lock();
909 hlist_del(&can_rx_alldev_list.list); 856 for_each_netdev_rcu(&init_net, dev) {
910 hlist_for_each_entry_safe(d, n, next, &can_rx_dev_list, list) { 857 if (dev->type == ARPHRD_CAN && dev->ml_priv){
911 hlist_del(&d->list); 858
912 kfree(d); 859 struct dev_rcv_lists *d = dev->ml_priv;
860
861 BUG_ON(d->entries);
862 kfree(d);
863 dev->ml_priv = NULL;
864 }
913 } 865 }
914 spin_unlock(&can_rcvlists_lock); 866 rcu_read_unlock();
915 867
916 rcu_barrier(); /* Wait for completion of call_rcu()'s */ 868 rcu_barrier(); /* Wait for completion of call_rcu()'s */
917 869
diff --git a/net/can/af_can.h b/net/can/af_can.h
index 18f91e37cc30..34253b84e30f 100644
--- a/net/can/af_can.h
+++ b/net/can/af_can.h
@@ -63,10 +63,8 @@ struct receiver {
63 63
64enum { RX_ERR, RX_ALL, RX_FIL, RX_INV, RX_EFF, RX_MAX }; 64enum { RX_ERR, RX_ALL, RX_FIL, RX_INV, RX_EFF, RX_MAX };
65 65
66/* per device receive filters linked at dev->ml_priv */
66struct dev_rcv_lists { 67struct dev_rcv_lists {
67 struct hlist_node list;
68 struct rcu_head rcu;
69 struct net_device *dev;
70 struct hlist_head rx[RX_MAX]; 68 struct hlist_head rx[RX_MAX];
71 struct hlist_head rx_sff[0x800]; 69 struct hlist_head rx_sff[0x800];
72 int remove_on_zero_entries; 70 int remove_on_zero_entries;
diff --git a/net/can/bcm.c b/net/can/bcm.c
index e8d58f33fe09..907dc871fac8 100644
--- a/net/can/bcm.c
+++ b/net/can/bcm.c
@@ -56,6 +56,7 @@
56#include <linux/can.h> 56#include <linux/can.h>
57#include <linux/can/core.h> 57#include <linux/can/core.h>
58#include <linux/can/bcm.h> 58#include <linux/can/bcm.h>
59#include <linux/slab.h>
59#include <net/sock.h> 60#include <net/sock.h>
60#include <net/net_namespace.h> 61#include <net/net_namespace.h>
61 62
@@ -139,13 +140,13 @@ static char *bcm_proc_getifname(char *result, int ifindex)
139 if (!ifindex) 140 if (!ifindex)
140 return "any"; 141 return "any";
141 142
142 read_lock(&dev_base_lock); 143 rcu_read_lock();
143 dev = __dev_get_by_index(&init_net, ifindex); 144 dev = dev_get_by_index_rcu(&init_net, ifindex);
144 if (dev) 145 if (dev)
145 strcpy(result, dev->name); 146 strcpy(result, dev->name);
146 else 147 else
147 strcpy(result, "???"); 148 strcpy(result, "???");
148 read_unlock(&dev_base_lock); 149 rcu_read_unlock();
149 150
150 return result; 151 return result;
151} 152}
@@ -1478,6 +1479,9 @@ static int bcm_connect(struct socket *sock, struct sockaddr *uaddr, int len,
1478 struct sock *sk = sock->sk; 1479 struct sock *sk = sock->sk;
1479 struct bcm_sock *bo = bcm_sk(sk); 1480 struct bcm_sock *bo = bcm_sk(sk);
1480 1481
1482 if (len < sizeof(*addr))
1483 return -EINVAL;
1484
1481 if (bo->bound) 1485 if (bo->bound)
1482 return -EISCONN; 1486 return -EISCONN;
1483 1487
@@ -1539,7 +1543,7 @@ static int bcm_recvmsg(struct kiocb *iocb, struct socket *sock,
1539 return err; 1543 return err;
1540 } 1544 }
1541 1545
1542 sock_recv_timestamp(msg, sk, skb); 1546 sock_recv_ts_and_drops(msg, sk, skb);
1543 1547
1544 if (msg->msg_name) { 1548 if (msg->msg_name) {
1545 msg->msg_namelen = sizeof(struct sockaddr_can); 1549 msg->msg_namelen = sizeof(struct sockaddr_can);
@@ -1581,7 +1585,6 @@ static struct proto bcm_proto __read_mostly = {
1581static struct can_proto bcm_can_proto __read_mostly = { 1585static struct can_proto bcm_can_proto __read_mostly = {
1582 .type = SOCK_DGRAM, 1586 .type = SOCK_DGRAM,
1583 .protocol = CAN_BCM, 1587 .protocol = CAN_BCM,
1584 .capability = -1,
1585 .ops = &bcm_ops, 1588 .ops = &bcm_ops,
1586 .prot = &bcm_proto, 1589 .prot = &bcm_proto,
1587}; 1590};
diff --git a/net/can/proc.c b/net/can/proc.c
index 9b9ad29be567..f4265cc9c3fb 100644
--- a/net/can/proc.c
+++ b/net/can/proc.c
@@ -45,6 +45,7 @@
45#include <linux/proc_fs.h> 45#include <linux/proc_fs.h>
46#include <linux/list.h> 46#include <linux/list.h>
47#include <linux/rcupdate.h> 47#include <linux/rcupdate.h>
48#include <linux/if_arp.h>
48#include <linux/can/core.h> 49#include <linux/can/core.h>
49 50
50#include "af_can.h" 51#include "af_can.h"
@@ -84,6 +85,9 @@ static const char rx_list_name[][8] = {
84 [RX_EFF] = "rx_eff", 85 [RX_EFF] = "rx_eff",
85}; 86};
86 87
88/* receive filters subscribed for 'all' CAN devices */
89extern struct dev_rcv_lists can_rx_alldev_list;
90
87/* 91/*
88 * af_can statistics stuff 92 * af_can statistics stuff
89 */ 93 */
@@ -190,10 +194,6 @@ void can_stat_update(unsigned long data)
190 194
191/* 195/*
192 * proc read functions 196 * proc read functions
193 *
194 * From known use-cases we expect about 10 entries in a receive list to be
195 * printed in the proc_fs. So PAGE_SIZE is definitely enough space here.
196 *
197 */ 197 */
198 198
199static void can_print_rcvlist(struct seq_file *m, struct hlist_head *rx_list, 199static void can_print_rcvlist(struct seq_file *m, struct hlist_head *rx_list,
@@ -202,7 +202,6 @@ static void can_print_rcvlist(struct seq_file *m, struct hlist_head *rx_list,
202 struct receiver *r; 202 struct receiver *r;
203 struct hlist_node *n; 203 struct hlist_node *n;
204 204
205 rcu_read_lock();
206 hlist_for_each_entry_rcu(r, n, rx_list, list) { 205 hlist_for_each_entry_rcu(r, n, rx_list, list) {
207 char *fmt = (r->can_id & CAN_EFF_FLAG)? 206 char *fmt = (r->can_id & CAN_EFF_FLAG)?
208 " %-5s %08X %08x %08x %08x %8ld %s\n" : 207 " %-5s %08X %08x %08x %08x %8ld %s\n" :
@@ -212,7 +211,6 @@ static void can_print_rcvlist(struct seq_file *m, struct hlist_head *rx_list,
212 (unsigned long)r->func, (unsigned long)r->data, 211 (unsigned long)r->func, (unsigned long)r->data,
213 r->matches, r->ident); 212 r->matches, r->ident);
214 } 213 }
215 rcu_read_unlock();
216} 214}
217 215
218static void can_print_recv_banner(struct seq_file *m) 216static void can_print_recv_banner(struct seq_file *m)
@@ -346,24 +344,39 @@ static const struct file_operations can_version_proc_fops = {
346 .release = single_release, 344 .release = single_release,
347}; 345};
348 346
347static inline void can_rcvlist_proc_show_one(struct seq_file *m, int idx,
348 struct net_device *dev,
349 struct dev_rcv_lists *d)
350{
351 if (!hlist_empty(&d->rx[idx])) {
352 can_print_recv_banner(m);
353 can_print_rcvlist(m, &d->rx[idx], dev);
354 } else
355 seq_printf(m, " (%s: no entry)\n", DNAME(dev));
356
357}
358
349static int can_rcvlist_proc_show(struct seq_file *m, void *v) 359static int can_rcvlist_proc_show(struct seq_file *m, void *v)
350{ 360{
351 /* double cast to prevent GCC warning */ 361 /* double cast to prevent GCC warning */
352 int idx = (int)(long)m->private; 362 int idx = (int)(long)m->private;
363 struct net_device *dev;
353 struct dev_rcv_lists *d; 364 struct dev_rcv_lists *d;
354 struct hlist_node *n;
355 365
356 seq_printf(m, "\nreceive list '%s':\n", rx_list_name[idx]); 366 seq_printf(m, "\nreceive list '%s':\n", rx_list_name[idx]);
357 367
358 rcu_read_lock(); 368 rcu_read_lock();
359 hlist_for_each_entry_rcu(d, n, &can_rx_dev_list, list) {
360 369
361 if (!hlist_empty(&d->rx[idx])) { 370 /* receive list for 'all' CAN devices (dev == NULL) */
362 can_print_recv_banner(m); 371 d = &can_rx_alldev_list;
363 can_print_rcvlist(m, &d->rx[idx], d->dev); 372 can_rcvlist_proc_show_one(m, idx, NULL, d);
364 } else 373
365 seq_printf(m, " (%s: no entry)\n", DNAME(d->dev)); 374 /* receive list for registered CAN devices */
375 for_each_netdev_rcu(&init_net, dev) {
376 if (dev->type == ARPHRD_CAN && dev->ml_priv)
377 can_rcvlist_proc_show_one(m, idx, dev, dev->ml_priv);
366 } 378 }
379
367 rcu_read_unlock(); 380 rcu_read_unlock();
368 381
369 seq_putc(m, '\n'); 382 seq_putc(m, '\n');
@@ -383,34 +396,50 @@ static const struct file_operations can_rcvlist_proc_fops = {
383 .release = single_release, 396 .release = single_release,
384}; 397};
385 398
399static inline void can_rcvlist_sff_proc_show_one(struct seq_file *m,
400 struct net_device *dev,
401 struct dev_rcv_lists *d)
402{
403 int i;
404 int all_empty = 1;
405
406 /* check wether at least one list is non-empty */
407 for (i = 0; i < 0x800; i++)
408 if (!hlist_empty(&d->rx_sff[i])) {
409 all_empty = 0;
410 break;
411 }
412
413 if (!all_empty) {
414 can_print_recv_banner(m);
415 for (i = 0; i < 0x800; i++) {
416 if (!hlist_empty(&d->rx_sff[i]))
417 can_print_rcvlist(m, &d->rx_sff[i], dev);
418 }
419 } else
420 seq_printf(m, " (%s: no entry)\n", DNAME(dev));
421}
422
386static int can_rcvlist_sff_proc_show(struct seq_file *m, void *v) 423static int can_rcvlist_sff_proc_show(struct seq_file *m, void *v)
387{ 424{
425 struct net_device *dev;
388 struct dev_rcv_lists *d; 426 struct dev_rcv_lists *d;
389 struct hlist_node *n;
390 427
391 /* RX_SFF */ 428 /* RX_SFF */
392 seq_puts(m, "\nreceive list 'rx_sff':\n"); 429 seq_puts(m, "\nreceive list 'rx_sff':\n");
393 430
394 rcu_read_lock(); 431 rcu_read_lock();
395 hlist_for_each_entry_rcu(d, n, &can_rx_dev_list, list) { 432
396 int i, all_empty = 1; 433 /* sff receive list for 'all' CAN devices (dev == NULL) */
397 /* check wether at least one list is non-empty */ 434 d = &can_rx_alldev_list;
398 for (i = 0; i < 0x800; i++) 435 can_rcvlist_sff_proc_show_one(m, NULL, d);
399 if (!hlist_empty(&d->rx_sff[i])) { 436
400 all_empty = 0; 437 /* sff receive list for registered CAN devices */
401 break; 438 for_each_netdev_rcu(&init_net, dev) {
402 } 439 if (dev->type == ARPHRD_CAN && dev->ml_priv)
403 440 can_rcvlist_sff_proc_show_one(m, dev, dev->ml_priv);
404 if (!all_empty) {
405 can_print_recv_banner(m);
406 for (i = 0; i < 0x800; i++) {
407 if (!hlist_empty(&d->rx_sff[i]))
408 can_print_rcvlist(m, &d->rx_sff[i],
409 d->dev);
410 }
411 } else
412 seq_printf(m, " (%s: no entry)\n", DNAME(d->dev));
413 } 441 }
442
414 rcu_read_unlock(); 443 rcu_read_unlock();
415 444
416 seq_putc(m, '\n'); 445 seq_putc(m, '\n');
diff --git a/net/can/raw.c b/net/can/raw.c
index b5e897922d32..da99cf153b33 100644
--- a/net/can/raw.c
+++ b/net/can/raw.c
@@ -45,6 +45,7 @@
45#include <linux/init.h> 45#include <linux/init.h>
46#include <linux/uio.h> 46#include <linux/uio.h>
47#include <linux/net.h> 47#include <linux/net.h>
48#include <linux/slab.h>
48#include <linux/netdevice.h> 49#include <linux/netdevice.h>
49#include <linux/socket.h> 50#include <linux/socket.h>
50#include <linux/if_arp.h> 51#include <linux/if_arp.h>
@@ -424,8 +425,6 @@ static int raw_setsockopt(struct socket *sock, int level, int optname,
424 425
425 if (level != SOL_CAN_RAW) 426 if (level != SOL_CAN_RAW)
426 return -EINVAL; 427 return -EINVAL;
427 if (optlen < 0)
428 return -EINVAL;
429 428
430 switch (optname) { 429 switch (optname) {
431 430
@@ -446,7 +445,7 @@ static int raw_setsockopt(struct socket *sock, int level, int optname,
446 return -EFAULT; 445 return -EFAULT;
447 } 446 }
448 } else if (count == 1) { 447 } else if (count == 1) {
449 if (copy_from_user(&sfilter, optval, optlen)) 448 if (copy_from_user(&sfilter, optval, sizeof(sfilter)))
450 return -EFAULT; 449 return -EFAULT;
451 } 450 }
452 451
@@ -702,7 +701,7 @@ static int raw_recvmsg(struct kiocb *iocb, struct socket *sock,
702 return err; 701 return err;
703 } 702 }
704 703
705 sock_recv_timestamp(msg, sk, skb); 704 sock_recv_ts_and_drops(msg, sk, skb);
706 705
707 if (msg->msg_name) { 706 if (msg->msg_name) {
708 msg->msg_namelen = sizeof(struct sockaddr_can); 707 msg->msg_namelen = sizeof(struct sockaddr_can);
@@ -744,7 +743,6 @@ static struct proto raw_proto __read_mostly = {
744static struct can_proto raw_can_proto __read_mostly = { 743static struct can_proto raw_can_proto __read_mostly = {
745 .type = SOCK_RAW, 744 .type = SOCK_RAW,
746 .protocol = CAN_RAW, 745 .protocol = CAN_RAW,
747 .capability = -1,
748 .ops = &raw_ops, 746 .ops = &raw_ops,
749 .prot = &raw_proto, 747 .prot = &raw_proto,
750}; 748};
diff --git a/net/compat.c b/net/compat.c
index a407c3addbae..ec24d9edb025 100644
--- a/net/compat.c
+++ b/net/compat.c
@@ -12,6 +12,7 @@
12 */ 12 */
13 13
14#include <linux/kernel.h> 14#include <linux/kernel.h>
15#include <linux/gfp.h>
15#include <linux/fs.h> 16#include <linux/fs.h>
16#include <linux/types.h> 17#include <linux/types.h>
17#include <linux/file.h> 18#include <linux/file.h>
@@ -390,9 +391,6 @@ asmlinkage long compat_sys_setsockopt(int fd, int level, int optname,
390 int err; 391 int err;
391 struct socket *sock; 392 struct socket *sock;
392 393
393 if (optlen < 0)
394 return -EINVAL;
395
396 if ((sock = sockfd_lookup(fd, &err))!=NULL) 394 if ((sock = sockfd_lookup(fd, &err))!=NULL)
397 { 395 {
398 err = security_socket_setsockopt(sock,level,optname); 396 err = security_socket_setsockopt(sock,level,optname);
@@ -727,10 +725,10 @@ EXPORT_SYMBOL(compat_mc_getsockopt);
727 725
728/* Argument list sizes for compat_sys_socketcall */ 726/* Argument list sizes for compat_sys_socketcall */
729#define AL(x) ((x) * sizeof(u32)) 727#define AL(x) ((x) * sizeof(u32))
730static unsigned char nas[19]={AL(0),AL(3),AL(3),AL(3),AL(2),AL(3), 728static unsigned char nas[20]={AL(0),AL(3),AL(3),AL(3),AL(2),AL(3),
731 AL(3),AL(3),AL(4),AL(4),AL(4),AL(6), 729 AL(3),AL(3),AL(4),AL(4),AL(4),AL(6),
732 AL(6),AL(2),AL(5),AL(5),AL(3),AL(3), 730 AL(6),AL(2),AL(5),AL(5),AL(3),AL(3),
733 AL(4)}; 731 AL(4),AL(5)};
734#undef AL 732#undef AL
735 733
736asmlinkage long compat_sys_sendmsg(int fd, struct compat_msghdr __user *msg, unsigned flags) 734asmlinkage long compat_sys_sendmsg(int fd, struct compat_msghdr __user *msg, unsigned flags)
@@ -755,13 +753,35 @@ asmlinkage long compat_sys_recvfrom(int fd, void __user *buf, size_t len,
755 return sys_recvfrom(fd, buf, len, flags | MSG_CMSG_COMPAT, addr, addrlen); 753 return sys_recvfrom(fd, buf, len, flags | MSG_CMSG_COMPAT, addr, addrlen);
756} 754}
757 755
756asmlinkage long compat_sys_recvmmsg(int fd, struct compat_mmsghdr __user *mmsg,
757 unsigned vlen, unsigned int flags,
758 struct compat_timespec __user *timeout)
759{
760 int datagrams;
761 struct timespec ktspec;
762
763 if (timeout == NULL)
764 return __sys_recvmmsg(fd, (struct mmsghdr __user *)mmsg, vlen,
765 flags | MSG_CMSG_COMPAT, NULL);
766
767 if (get_compat_timespec(&ktspec, timeout))
768 return -EFAULT;
769
770 datagrams = __sys_recvmmsg(fd, (struct mmsghdr __user *)mmsg, vlen,
771 flags | MSG_CMSG_COMPAT, &ktspec);
772 if (datagrams > 0 && put_compat_timespec(&ktspec, timeout))
773 datagrams = -EFAULT;
774
775 return datagrams;
776}
777
758asmlinkage long compat_sys_socketcall(int call, u32 __user *args) 778asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
759{ 779{
760 int ret; 780 int ret;
761 u32 a[6]; 781 u32 a[6];
762 u32 a0, a1; 782 u32 a0, a1;
763 783
764 if (call < SYS_SOCKET || call > SYS_ACCEPT4) 784 if (call < SYS_SOCKET || call > SYS_RECVMMSG)
765 return -EINVAL; 785 return -EINVAL;
766 if (copy_from_user(a, args, nas[call])) 786 if (copy_from_user(a, args, nas[call]))
767 return -EFAULT; 787 return -EFAULT;
@@ -823,6 +843,10 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
823 case SYS_RECVMSG: 843 case SYS_RECVMSG:
824 ret = compat_sys_recvmsg(a0, compat_ptr(a1), a[2]); 844 ret = compat_sys_recvmsg(a0, compat_ptr(a1), a[2]);
825 break; 845 break;
846 case SYS_RECVMMSG:
847 ret = compat_sys_recvmmsg(a0, compat_ptr(a1), a[2], a[3],
848 compat_ptr(a[4]));
849 break;
826 case SYS_ACCEPT4: 850 case SYS_ACCEPT4:
827 ret = sys_accept4(a0, compat_ptr(a1), compat_ptr(a[2]), a[3]); 851 ret = sys_accept4(a0, compat_ptr(a1), compat_ptr(a[2]), a[3]);
828 break; 852 break;
diff --git a/net/core/Makefile b/net/core/Makefile
index 796f46eece5f..08791ac3e05a 100644
--- a/net/core/Makefile
+++ b/net/core/Makefile
@@ -6,7 +6,6 @@ obj-y := sock.o request_sock.o skbuff.o iovec.o datagram.o stream.o scm.o \
6 gen_stats.o gen_estimator.o net_namespace.o 6 gen_stats.o gen_estimator.o net_namespace.o
7 7
8obj-$(CONFIG_SYSCTL) += sysctl_net_core.o 8obj-$(CONFIG_SYSCTL) += sysctl_net_core.o
9obj-$(CONFIG_HAS_DMA) += skb_dma_map.o
10 9
11obj-y += dev.o ethtool.o dev_mcast.o dst.o netevent.o \ 10obj-y += dev.o ethtool.o dev_mcast.o dst.o netevent.o \
12 neighbour.o rtnetlink.o utils.o link_watch.o filter.o 11 neighbour.o rtnetlink.o utils.o link_watch.o filter.o
diff --git a/net/core/datagram.c b/net/core/datagram.c
index 4ade3011bb3c..2dccd4ee591b 100644
--- a/net/core/datagram.c
+++ b/net/core/datagram.c
@@ -48,6 +48,7 @@
48#include <linux/poll.h> 48#include <linux/poll.h>
49#include <linux/highmem.h> 49#include <linux/highmem.h>
50#include <linux/spinlock.h> 50#include <linux/spinlock.h>
51#include <linux/slab.h>
51 52
52#include <net/protocol.h> 53#include <net/protocol.h>
53#include <linux/skbuff.h> 54#include <linux/skbuff.h>
@@ -271,6 +272,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
271 } 272 }
272 273
273 kfree_skb(skb); 274 kfree_skb(skb);
275 atomic_inc(&sk->sk_drops);
274 sk_mem_reclaim_partial(sk); 276 sk_mem_reclaim_partial(sk);
275 277
276 return err; 278 return err;
diff --git a/net/core/dev.c b/net/core/dev.c
index fe10551d3671..264137fce3a2 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -79,6 +79,8 @@
79#include <linux/cpu.h> 79#include <linux/cpu.h>
80#include <linux/types.h> 80#include <linux/types.h>
81#include <linux/kernel.h> 81#include <linux/kernel.h>
82#include <linux/hash.h>
83#include <linux/slab.h>
82#include <linux/sched.h> 84#include <linux/sched.h>
83#include <linux/mutex.h> 85#include <linux/mutex.h>
84#include <linux/string.h> 86#include <linux/string.h>
@@ -104,6 +106,7 @@
104#include <net/dst.h> 106#include <net/dst.h>
105#include <net/pkt_sched.h> 107#include <net/pkt_sched.h>
106#include <net/checksum.h> 108#include <net/checksum.h>
109#include <net/xfrm.h>
107#include <linux/highmem.h> 110#include <linux/highmem.h>
108#include <linux/init.h> 111#include <linux/init.h>
109#include <linux/kmod.h> 112#include <linux/kmod.h>
@@ -175,7 +178,7 @@ static struct list_head ptype_all __read_mostly; /* Taps */
175 * The @dev_base_head list is protected by @dev_base_lock and the rtnl 178 * The @dev_base_head list is protected by @dev_base_lock and the rtnl
176 * semaphore. 179 * semaphore.
177 * 180 *
178 * Pure readers hold dev_base_lock for reading. 181 * Pure readers hold dev_base_lock for reading, or rcu_read_lock()
179 * 182 *
180 * Writers must hold the rtnl semaphore while they loop through the 183 * Writers must hold the rtnl semaphore while they loop through the
181 * dev_base_head list, and hold dev_base_lock for writing when they do the 184 * dev_base_head list, and hold dev_base_lock for writing when they do the
@@ -193,18 +196,15 @@ static struct list_head ptype_all __read_mostly; /* Taps */
193DEFINE_RWLOCK(dev_base_lock); 196DEFINE_RWLOCK(dev_base_lock);
194EXPORT_SYMBOL(dev_base_lock); 197EXPORT_SYMBOL(dev_base_lock);
195 198
196#define NETDEV_HASHBITS 8
197#define NETDEV_HASHENTRIES (1 << NETDEV_HASHBITS)
198
199static inline struct hlist_head *dev_name_hash(struct net *net, const char *name) 199static inline struct hlist_head *dev_name_hash(struct net *net, const char *name)
200{ 200{
201 unsigned hash = full_name_hash(name, strnlen(name, IFNAMSIZ)); 201 unsigned hash = full_name_hash(name, strnlen(name, IFNAMSIZ));
202 return &net->dev_name_head[hash & ((1 << NETDEV_HASHBITS) - 1)]; 202 return &net->dev_name_head[hash_32(hash, NETDEV_HASHBITS)];
203} 203}
204 204
205static inline struct hlist_head *dev_index_hash(struct net *net, int ifindex) 205static inline struct hlist_head *dev_index_hash(struct net *net, int ifindex)
206{ 206{
207 return &net->dev_index_head[ifindex & ((1 << NETDEV_HASHBITS) - 1)]; 207 return &net->dev_index_head[ifindex & (NETDEV_HASHENTRIES - 1)];
208} 208}
209 209
210/* Device list insertion */ 210/* Device list insertion */
@@ -215,23 +215,26 @@ static int list_netdevice(struct net_device *dev)
215 ASSERT_RTNL(); 215 ASSERT_RTNL();
216 216
217 write_lock_bh(&dev_base_lock); 217 write_lock_bh(&dev_base_lock);
218 list_add_tail(&dev->dev_list, &net->dev_base_head); 218 list_add_tail_rcu(&dev->dev_list, &net->dev_base_head);
219 hlist_add_head(&dev->name_hlist, dev_name_hash(net, dev->name)); 219 hlist_add_head_rcu(&dev->name_hlist, dev_name_hash(net, dev->name));
220 hlist_add_head(&dev->index_hlist, dev_index_hash(net, dev->ifindex)); 220 hlist_add_head_rcu(&dev->index_hlist,
221 dev_index_hash(net, dev->ifindex));
221 write_unlock_bh(&dev_base_lock); 222 write_unlock_bh(&dev_base_lock);
222 return 0; 223 return 0;
223} 224}
224 225
225/* Device list removal */ 226/* Device list removal
227 * caller must respect a RCU grace period before freeing/reusing dev
228 */
226static void unlist_netdevice(struct net_device *dev) 229static void unlist_netdevice(struct net_device *dev)
227{ 230{
228 ASSERT_RTNL(); 231 ASSERT_RTNL();
229 232
230 /* Unlink dev from the device chain */ 233 /* Unlink dev from the device chain */
231 write_lock_bh(&dev_base_lock); 234 write_lock_bh(&dev_base_lock);
232 list_del(&dev->dev_list); 235 list_del_rcu(&dev->dev_list);
233 hlist_del(&dev->name_hlist); 236 hlist_del_rcu(&dev->name_hlist);
234 hlist_del(&dev->index_hlist); 237 hlist_del_rcu(&dev->index_hlist);
235 write_unlock_bh(&dev_base_lock); 238 write_unlock_bh(&dev_base_lock);
236} 239}
237 240
@@ -587,18 +590,44 @@ __setup("netdev=", netdev_boot_setup);
587struct net_device *__dev_get_by_name(struct net *net, const char *name) 590struct net_device *__dev_get_by_name(struct net *net, const char *name)
588{ 591{
589 struct hlist_node *p; 592 struct hlist_node *p;
593 struct net_device *dev;
594 struct hlist_head *head = dev_name_hash(net, name);
590 595
591 hlist_for_each(p, dev_name_hash(net, name)) { 596 hlist_for_each_entry(dev, p, head, name_hlist)
592 struct net_device *dev
593 = hlist_entry(p, struct net_device, name_hlist);
594 if (!strncmp(dev->name, name, IFNAMSIZ)) 597 if (!strncmp(dev->name, name, IFNAMSIZ))
595 return dev; 598 return dev;
596 } 599
597 return NULL; 600 return NULL;
598} 601}
599EXPORT_SYMBOL(__dev_get_by_name); 602EXPORT_SYMBOL(__dev_get_by_name);
600 603
601/** 604/**
605 * dev_get_by_name_rcu - find a device by its name
606 * @net: the applicable net namespace
607 * @name: name to find
608 *
609 * Find an interface by name.
610 * If the name is found a pointer to the device is returned.
611 * If the name is not found then %NULL is returned.
612 * The reference counters are not incremented so the caller must be
613 * careful with locks. The caller must hold RCU lock.
614 */
615
616struct net_device *dev_get_by_name_rcu(struct net *net, const char *name)
617{
618 struct hlist_node *p;
619 struct net_device *dev;
620 struct hlist_head *head = dev_name_hash(net, name);
621
622 hlist_for_each_entry_rcu(dev, p, head, name_hlist)
623 if (!strncmp(dev->name, name, IFNAMSIZ))
624 return dev;
625
626 return NULL;
627}
628EXPORT_SYMBOL(dev_get_by_name_rcu);
629
630/**
602 * dev_get_by_name - find a device by its name 631 * dev_get_by_name - find a device by its name
603 * @net: the applicable net namespace 632 * @net: the applicable net namespace
604 * @name: name to find 633 * @name: name to find
@@ -614,11 +643,11 @@ struct net_device *dev_get_by_name(struct net *net, const char *name)
614{ 643{
615 struct net_device *dev; 644 struct net_device *dev;
616 645
617 read_lock(&dev_base_lock); 646 rcu_read_lock();
618 dev = __dev_get_by_name(net, name); 647 dev = dev_get_by_name_rcu(net, name);
619 if (dev) 648 if (dev)
620 dev_hold(dev); 649 dev_hold(dev);
621 read_unlock(&dev_base_lock); 650 rcu_read_unlock();
622 return dev; 651 return dev;
623} 652}
624EXPORT_SYMBOL(dev_get_by_name); 653EXPORT_SYMBOL(dev_get_by_name);
@@ -638,17 +667,42 @@ EXPORT_SYMBOL(dev_get_by_name);
638struct net_device *__dev_get_by_index(struct net *net, int ifindex) 667struct net_device *__dev_get_by_index(struct net *net, int ifindex)
639{ 668{
640 struct hlist_node *p; 669 struct hlist_node *p;
670 struct net_device *dev;
671 struct hlist_head *head = dev_index_hash(net, ifindex);
641 672
642 hlist_for_each(p, dev_index_hash(net, ifindex)) { 673 hlist_for_each_entry(dev, p, head, index_hlist)
643 struct net_device *dev
644 = hlist_entry(p, struct net_device, index_hlist);
645 if (dev->ifindex == ifindex) 674 if (dev->ifindex == ifindex)
646 return dev; 675 return dev;
647 } 676
648 return NULL; 677 return NULL;
649} 678}
650EXPORT_SYMBOL(__dev_get_by_index); 679EXPORT_SYMBOL(__dev_get_by_index);
651 680
681/**
682 * dev_get_by_index_rcu - find a device by its ifindex
683 * @net: the applicable net namespace
684 * @ifindex: index of device
685 *
686 * Search for an interface by index. Returns %NULL if the device
687 * is not found or a pointer to the device. The device has not
688 * had its reference counter increased so the caller must be careful
689 * about locking. The caller must hold RCU lock.
690 */
691
692struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex)
693{
694 struct hlist_node *p;
695 struct net_device *dev;
696 struct hlist_head *head = dev_index_hash(net, ifindex);
697
698 hlist_for_each_entry_rcu(dev, p, head, index_hlist)
699 if (dev->ifindex == ifindex)
700 return dev;
701
702 return NULL;
703}
704EXPORT_SYMBOL(dev_get_by_index_rcu);
705
652 706
653/** 707/**
654 * dev_get_by_index - find a device by its ifindex 708 * dev_get_by_index - find a device by its ifindex
@@ -665,11 +719,11 @@ struct net_device *dev_get_by_index(struct net *net, int ifindex)
665{ 719{
666 struct net_device *dev; 720 struct net_device *dev;
667 721
668 read_lock(&dev_base_lock); 722 rcu_read_lock();
669 dev = __dev_get_by_index(net, ifindex); 723 dev = dev_get_by_index_rcu(net, ifindex);
670 if (dev) 724 if (dev)
671 dev_hold(dev); 725 dev_hold(dev);
672 read_unlock(&dev_base_lock); 726 rcu_read_unlock();
673 return dev; 727 return dev;
674} 728}
675EXPORT_SYMBOL(dev_get_by_index); 729EXPORT_SYMBOL(dev_get_by_index);
@@ -748,15 +802,15 @@ struct net_device *dev_get_by_flags(struct net *net, unsigned short if_flags,
748 struct net_device *dev, *ret; 802 struct net_device *dev, *ret;
749 803
750 ret = NULL; 804 ret = NULL;
751 read_lock(&dev_base_lock); 805 rcu_read_lock();
752 for_each_netdev(net, dev) { 806 for_each_netdev_rcu(net, dev) {
753 if (((dev->flags ^ if_flags) & mask) == 0) { 807 if (((dev->flags ^ if_flags) & mask) == 0) {
754 dev_hold(dev); 808 dev_hold(dev);
755 ret = dev; 809 ret = dev;
756 break; 810 break;
757 } 811 }
758 } 812 }
759 read_unlock(&dev_base_lock); 813 rcu_read_unlock();
760 return ret; 814 return ret;
761} 815}
762EXPORT_SYMBOL(dev_get_by_flags); 816EXPORT_SYMBOL(dev_get_by_flags);
@@ -841,7 +895,8 @@ static int __dev_alloc_name(struct net *net, const char *name, char *buf)
841 free_page((unsigned long) inuse); 895 free_page((unsigned long) inuse);
842 } 896 }
843 897
844 snprintf(buf, IFNAMSIZ, name, i); 898 if (buf != name)
899 snprintf(buf, IFNAMSIZ, name, i);
845 if (!__dev_get_by_name(net, buf)) 900 if (!__dev_get_by_name(net, buf))
846 return i; 901 return i;
847 902
@@ -881,6 +936,21 @@ int dev_alloc_name(struct net_device *dev, const char *name)
881} 936}
882EXPORT_SYMBOL(dev_alloc_name); 937EXPORT_SYMBOL(dev_alloc_name);
883 938
939static int dev_get_valid_name(struct net *net, const char *name, char *buf,
940 bool fmt)
941{
942 if (!dev_valid_name(name))
943 return -EINVAL;
944
945 if (fmt && strchr(name, '%'))
946 return __dev_alloc_name(net, name, buf);
947 else if (__dev_get_by_name(net, name))
948 return -EEXIST;
949 else if (buf != name)
950 strlcpy(buf, name, IFNAMSIZ);
951
952 return 0;
953}
884 954
885/** 955/**
886 * dev_change_name - change name of a device 956 * dev_change_name - change name of a device
@@ -904,28 +974,20 @@ int dev_change_name(struct net_device *dev, const char *newname)
904 if (dev->flags & IFF_UP) 974 if (dev->flags & IFF_UP)
905 return -EBUSY; 975 return -EBUSY;
906 976
907 if (!dev_valid_name(newname))
908 return -EINVAL;
909
910 if (strncmp(newname, dev->name, IFNAMSIZ) == 0) 977 if (strncmp(newname, dev->name, IFNAMSIZ) == 0)
911 return 0; 978 return 0;
912 979
913 memcpy(oldname, dev->name, IFNAMSIZ); 980 memcpy(oldname, dev->name, IFNAMSIZ);
914 981
915 if (strchr(newname, '%')) { 982 err = dev_get_valid_name(net, newname, dev->name, 1);
916 err = dev_alloc_name(dev, newname); 983 if (err < 0)
917 if (err < 0) 984 return err;
918 return err;
919 } else if (__dev_get_by_name(net, newname))
920 return -EEXIST;
921 else
922 strlcpy(dev->name, newname, IFNAMSIZ);
923 985
924rollback: 986rollback:
925 /* For now only devices in the initial network namespace 987 /* For now only devices in the initial network namespace
926 * are in sysfs. 988 * are in sysfs.
927 */ 989 */
928 if (net == &init_net) { 990 if (net_eq(net, &init_net)) {
929 ret = device_rename(&dev->dev, dev->name); 991 ret = device_rename(&dev->dev, dev->name);
930 if (ret) { 992 if (ret) {
931 memcpy(dev->name, oldname, IFNAMSIZ); 993 memcpy(dev->name, oldname, IFNAMSIZ);
@@ -935,7 +997,12 @@ rollback:
935 997
936 write_lock_bh(&dev_base_lock); 998 write_lock_bh(&dev_base_lock);
937 hlist_del(&dev->name_hlist); 999 hlist_del(&dev->name_hlist);
938 hlist_add_head(&dev->name_hlist, dev_name_hash(net, dev->name)); 1000 write_unlock_bh(&dev_base_lock);
1001
1002 synchronize_rcu();
1003
1004 write_lock_bh(&dev_base_lock);
1005 hlist_add_head_rcu(&dev->name_hlist, dev_name_hash(net, dev->name));
939 write_unlock_bh(&dev_base_lock); 1006 write_unlock_bh(&dev_base_lock);
940 1007
941 ret = call_netdevice_notifiers(NETDEV_CHANGENAME, dev); 1008 ret = call_netdevice_notifiers(NETDEV_CHANGENAME, dev);
@@ -1038,28 +1105,16 @@ void dev_load(struct net *net, const char *name)
1038{ 1105{
1039 struct net_device *dev; 1106 struct net_device *dev;
1040 1107
1041 read_lock(&dev_base_lock); 1108 rcu_read_lock();
1042 dev = __dev_get_by_name(net, name); 1109 dev = dev_get_by_name_rcu(net, name);
1043 read_unlock(&dev_base_lock); 1110 rcu_read_unlock();
1044 1111
1045 if (!dev && capable(CAP_NET_ADMIN)) 1112 if (!dev && capable(CAP_NET_ADMIN))
1046 request_module("%s", name); 1113 request_module("%s", name);
1047} 1114}
1048EXPORT_SYMBOL(dev_load); 1115EXPORT_SYMBOL(dev_load);
1049 1116
1050/** 1117static int __dev_open(struct net_device *dev)
1051 * dev_open - prepare an interface for use.
1052 * @dev: device to open
1053 *
1054 * Takes a device from down to up state. The device's private open
1055 * function is invoked and then the multicast lists are loaded. Finally
1056 * the device is moved into the up state and a %NETDEV_UP message is
1057 * sent to the netdev notifier chain.
1058 *
1059 * Calling this function on an active interface is a nop. On a failure
1060 * a negative errno code is returned.
1061 */
1062int dev_open(struct net_device *dev)
1063{ 1118{
1064 const struct net_device_ops *ops = dev->netdev_ops; 1119 const struct net_device_ops *ops = dev->netdev_ops;
1065 int ret; 1120 int ret;
@@ -1067,13 +1122,6 @@ int dev_open(struct net_device *dev)
1067 ASSERT_RTNL(); 1122 ASSERT_RTNL();
1068 1123
1069 /* 1124 /*
1070 * Is it already up?
1071 */
1072
1073 if (dev->flags & IFF_UP)
1074 return 0;
1075
1076 /*
1077 * Is it even present? 1125 * Is it even present?
1078 */ 1126 */
1079 if (!netif_device_present(dev)) 1127 if (!netif_device_present(dev))
@@ -1121,36 +1169,57 @@ int dev_open(struct net_device *dev)
1121 * Wakeup transmit queue engine 1169 * Wakeup transmit queue engine
1122 */ 1170 */
1123 dev_activate(dev); 1171 dev_activate(dev);
1124
1125 /*
1126 * ... and announce new interface.
1127 */
1128 call_netdevice_notifiers(NETDEV_UP, dev);
1129 } 1172 }
1130 1173
1131 return ret; 1174 return ret;
1132} 1175}
1133EXPORT_SYMBOL(dev_open);
1134 1176
1135/** 1177/**
1136 * dev_close - shutdown an interface. 1178 * dev_open - prepare an interface for use.
1137 * @dev: device to shutdown 1179 * @dev: device to open
1138 * 1180 *
1139 * This function moves an active device into down state. A 1181 * Takes a device from down to up state. The device's private open
1140 * %NETDEV_GOING_DOWN is sent to the netdev notifier chain. The device 1182 * function is invoked and then the multicast lists are loaded. Finally
1141 * is then deactivated and finally a %NETDEV_DOWN is sent to the notifier 1183 * the device is moved into the up state and a %NETDEV_UP message is
1142 * chain. 1184 * sent to the netdev notifier chain.
1185 *
1186 * Calling this function on an active interface is a nop. On a failure
1187 * a negative errno code is returned.
1143 */ 1188 */
1144int dev_close(struct net_device *dev) 1189int dev_open(struct net_device *dev)
1190{
1191 int ret;
1192
1193 /*
1194 * Is it already up?
1195 */
1196 if (dev->flags & IFF_UP)
1197 return 0;
1198
1199 /*
1200 * Open device
1201 */
1202 ret = __dev_open(dev);
1203 if (ret < 0)
1204 return ret;
1205
1206 /*
1207 * ... and announce new interface.
1208 */
1209 rtmsg_ifinfo(RTM_NEWLINK, dev, IFF_UP|IFF_RUNNING);
1210 call_netdevice_notifiers(NETDEV_UP, dev);
1211
1212 return ret;
1213}
1214EXPORT_SYMBOL(dev_open);
1215
1216static int __dev_close(struct net_device *dev)
1145{ 1217{
1146 const struct net_device_ops *ops = dev->netdev_ops; 1218 const struct net_device_ops *ops = dev->netdev_ops;
1147 ASSERT_RTNL();
1148 1219
1220 ASSERT_RTNL();
1149 might_sleep(); 1221 might_sleep();
1150 1222
1151 if (!(dev->flags & IFF_UP))
1152 return 0;
1153
1154 /* 1223 /*
1155 * Tell people we are going down, so that they can 1224 * Tell people we are going down, so that they can
1156 * prepare to death, when device is still operating. 1225 * prepare to death, when device is still operating.
@@ -1186,14 +1255,34 @@ int dev_close(struct net_device *dev)
1186 dev->flags &= ~IFF_UP; 1255 dev->flags &= ~IFF_UP;
1187 1256
1188 /* 1257 /*
1189 * Tell people we are down 1258 * Shutdown NET_DMA
1190 */ 1259 */
1191 call_netdevice_notifiers(NETDEV_DOWN, dev); 1260 net_dmaengine_put();
1261
1262 return 0;
1263}
1264
1265/**
1266 * dev_close - shutdown an interface.
1267 * @dev: device to shutdown
1268 *
1269 * This function moves an active device into down state. A
1270 * %NETDEV_GOING_DOWN is sent to the netdev notifier chain. The device
1271 * is then deactivated and finally a %NETDEV_DOWN is sent to the notifier
1272 * chain.
1273 */
1274int dev_close(struct net_device *dev)
1275{
1276 if (!(dev->flags & IFF_UP))
1277 return 0;
1278
1279 __dev_close(dev);
1192 1280
1193 /* 1281 /*
1194 * Shutdown NET_DMA 1282 * Tell people we are down
1195 */ 1283 */
1196 net_dmaengine_put(); 1284 rtmsg_ifinfo(RTM_NEWLINK, dev, IFF_UP|IFF_RUNNING);
1285 call_netdevice_notifiers(NETDEV_DOWN, dev);
1197 1286
1198 return 0; 1287 return 0;
1199} 1288}
@@ -1287,6 +1376,7 @@ rollback:
1287 nb->notifier_call(nb, NETDEV_DOWN, dev); 1376 nb->notifier_call(nb, NETDEV_DOWN, dev);
1288 } 1377 }
1289 nb->notifier_call(nb, NETDEV_UNREGISTER, dev); 1378 nb->notifier_call(nb, NETDEV_UNREGISTER, dev);
1379 nb->notifier_call(nb, NETDEV_UNREGISTER_BATCH, dev);
1290 } 1380 }
1291 } 1381 }
1292 1382
@@ -1353,6 +1443,41 @@ static inline void net_timestamp(struct sk_buff *skb)
1353 skb->tstamp.tv64 = 0; 1443 skb->tstamp.tv64 = 0;
1354} 1444}
1355 1445
1446/**
1447 * dev_forward_skb - loopback an skb to another netif
1448 *
1449 * @dev: destination network device
1450 * @skb: buffer to forward
1451 *
1452 * return values:
1453 * NET_RX_SUCCESS (no congestion)
1454 * NET_RX_DROP (packet was dropped, but freed)
1455 *
1456 * dev_forward_skb can be used for injecting an skb from the
1457 * start_xmit function of one device into the receive queue
1458 * of another device.
1459 *
1460 * The receiving device may be in another namespace, so
1461 * we have to clear all information in the skb that could
1462 * impact namespace isolation.
1463 */
1464int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
1465{
1466 skb_orphan(skb);
1467
1468 if (!(dev->flags & IFF_UP) ||
1469 (skb->len > (dev->mtu + dev->hard_header_len))) {
1470 kfree_skb(skb);
1471 return NET_RX_DROP;
1472 }
1473 skb_set_dev(skb, dev);
1474 skb->tstamp.tv64 = 0;
1475 skb->pkt_type = PACKET_HOST;
1476 skb->protocol = eth_type_trans(skb, dev);
1477 return netif_rx(skb);
1478}
1479EXPORT_SYMBOL_GPL(dev_forward_skb);
1480
1356/* 1481/*
1357 * Support routine. Sends outgoing frames to any network 1482 * Support routine. Sends outgoing frames to any network
1358 * taps currently in use. 1483 * taps currently in use.
@@ -1508,6 +1633,36 @@ static bool dev_can_checksum(struct net_device *dev, struct sk_buff *skb)
1508 return false; 1633 return false;
1509} 1634}
1510 1635
1636/**
1637 * skb_dev_set -- assign a new device to a buffer
1638 * @skb: buffer for the new device
1639 * @dev: network device
1640 *
1641 * If an skb is owned by a device already, we have to reset
1642 * all data private to the namespace a device belongs to
1643 * before assigning it a new device.
1644 */
1645#ifdef CONFIG_NET_NS
1646void skb_set_dev(struct sk_buff *skb, struct net_device *dev)
1647{
1648 skb_dst_drop(skb);
1649 if (skb->dev && !net_eq(dev_net(skb->dev), dev_net(dev))) {
1650 secpath_reset(skb);
1651 nf_reset(skb);
1652 skb_init_secmark(skb);
1653 skb->mark = 0;
1654 skb->priority = 0;
1655 skb->nf_trace = 0;
1656 skb->ipvs_property = 0;
1657#ifdef CONFIG_NET_SCHED
1658 skb->tc_index = 0;
1659#endif
1660 }
1661 skb->dev = dev;
1662}
1663EXPORT_SYMBOL(skb_set_dev);
1664#endif /* CONFIG_NET_NS */
1665
1511/* 1666/*
1512 * Invalidate hardware checksum when packet is to be mangled, and 1667 * Invalidate hardware checksum when packet is to be mangled, and
1513 * complete checksum manually on outgoing path. 1668 * complete checksum manually on outgoing path.
@@ -1701,7 +1856,7 @@ int dev_hard_start_xmit(struct sk_buff *skb, struct net_device *dev,
1701 struct netdev_queue *txq) 1856 struct netdev_queue *txq)
1702{ 1857{
1703 const struct net_device_ops *ops = dev->netdev_ops; 1858 const struct net_device_ops *ops = dev->netdev_ops;
1704 int rc; 1859 int rc = NETDEV_TX_OK;
1705 1860
1706 if (likely(!skb->next)) { 1861 if (likely(!skb->next)) {
1707 if (!list_empty(&ptype_all)) 1862 if (!list_empty(&ptype_all))
@@ -1747,8 +1902,18 @@ gso:
1747 1902
1748 skb->next = nskb->next; 1903 skb->next = nskb->next;
1749 nskb->next = NULL; 1904 nskb->next = NULL;
1905
1906 /*
1907 * If device doesnt need nskb->dst, release it right now while
1908 * its hot in this cpu cache
1909 */
1910 if (dev->priv_flags & IFF_XMIT_DST_RELEASE)
1911 skb_dst_drop(nskb);
1912
1750 rc = ops->ndo_start_xmit(nskb, dev); 1913 rc = ops->ndo_start_xmit(nskb, dev);
1751 if (unlikely(rc != NETDEV_TX_OK)) { 1914 if (unlikely(rc != NETDEV_TX_OK)) {
1915 if (rc & ~NETDEV_TX_MASK)
1916 goto out_kfree_gso_skb;
1752 nskb->next = skb->next; 1917 nskb->next = skb->next;
1753 skb->next = nskb; 1918 skb->next = nskb;
1754 return rc; 1919 return rc;
@@ -1758,11 +1923,12 @@ gso:
1758 return NETDEV_TX_BUSY; 1923 return NETDEV_TX_BUSY;
1759 } while (skb->next); 1924 } while (skb->next);
1760 1925
1761 skb->destructor = DEV_GSO_CB(skb)->destructor; 1926out_kfree_gso_skb:
1762 1927 if (likely(skb->next == NULL))
1928 skb->destructor = DEV_GSO_CB(skb)->destructor;
1763out_kfree_skb: 1929out_kfree_skb:
1764 kfree_skb(skb); 1930 kfree_skb(skb);
1765 return NETDEV_TX_OK; 1931 return rc;
1766} 1932}
1767 1933
1768static u32 skb_tx_hashrnd; 1934static u32 skb_tx_hashrnd;
@@ -1789,16 +1955,47 @@ u16 skb_tx_hash(const struct net_device *dev, const struct sk_buff *skb)
1789} 1955}
1790EXPORT_SYMBOL(skb_tx_hash); 1956EXPORT_SYMBOL(skb_tx_hash);
1791 1957
1958static inline u16 dev_cap_txqueue(struct net_device *dev, u16 queue_index)
1959{
1960 if (unlikely(queue_index >= dev->real_num_tx_queues)) {
1961 if (net_ratelimit()) {
1962 WARN(1, "%s selects TX queue %d, but "
1963 "real number of TX queues is %d\n",
1964 dev->name, queue_index,
1965 dev->real_num_tx_queues);
1966 }
1967 return 0;
1968 }
1969 return queue_index;
1970}
1971
1792static struct netdev_queue *dev_pick_tx(struct net_device *dev, 1972static struct netdev_queue *dev_pick_tx(struct net_device *dev,
1793 struct sk_buff *skb) 1973 struct sk_buff *skb)
1794{ 1974{
1795 const struct net_device_ops *ops = dev->netdev_ops; 1975 u16 queue_index;
1796 u16 queue_index = 0; 1976 struct sock *sk = skb->sk;
1977
1978 if (sk_tx_queue_recorded(sk)) {
1979 queue_index = sk_tx_queue_get(sk);
1980 } else {
1981 const struct net_device_ops *ops = dev->netdev_ops;
1982
1983 if (ops->ndo_select_queue) {
1984 queue_index = ops->ndo_select_queue(dev, skb);
1985 queue_index = dev_cap_txqueue(dev, queue_index);
1986 } else {
1987 queue_index = 0;
1988 if (dev->real_num_tx_queues > 1)
1989 queue_index = skb_tx_hash(dev, skb);
1990
1991 if (sk) {
1992 struct dst_entry *dst = rcu_dereference_bh(sk->sk_dst_cache);
1797 1993
1798 if (ops->ndo_select_queue) 1994 if (dst && skb_dst(skb) == dst)
1799 queue_index = ops->ndo_select_queue(dev, skb); 1995 sk_tx_queue_set(sk, queue_index);
1800 else if (dev->real_num_tx_queues > 1) 1996 }
1801 queue_index = skb_tx_hash(dev, skb); 1997 }
1998 }
1802 1999
1803 skb_set_queue_mapping(skb, queue_index); 2000 skb_set_queue_mapping(skb, queue_index);
1804 return netdev_get_tx_queue(dev, queue_index); 2001 return netdev_get_tx_queue(dev, queue_index);
@@ -1838,6 +2035,21 @@ static inline int __dev_xmit_skb(struct sk_buff *skb, struct Qdisc *q,
1838 return rc; 2035 return rc;
1839} 2036}
1840 2037
2038/*
2039 * Returns true if either:
2040 * 1. skb has frag_list and the device doesn't support FRAGLIST, or
2041 * 2. skb is fragmented and the device does not support SG, or if
2042 * at least one of fragments is in highmem and device does not
2043 * support DMA from it.
2044 */
2045static inline int skb_needs_linearize(struct sk_buff *skb,
2046 struct net_device *dev)
2047{
2048 return (skb_has_frags(skb) && !(dev->features & NETIF_F_FRAGLIST)) ||
2049 (skb_shinfo(skb)->nr_frags && (!(dev->features & NETIF_F_SG) ||
2050 illegal_highdma(dev, skb)));
2051}
2052
1841/** 2053/**
1842 * dev_queue_xmit - transmit a buffer 2054 * dev_queue_xmit - transmit a buffer
1843 * @skb: buffer to transmit 2055 * @skb: buffer to transmit
@@ -1874,18 +2086,8 @@ int dev_queue_xmit(struct sk_buff *skb)
1874 if (netif_needs_gso(dev, skb)) 2086 if (netif_needs_gso(dev, skb))
1875 goto gso; 2087 goto gso;
1876 2088
1877 if (skb_has_frags(skb) && 2089 /* Convert a paged skb to linear, if required */
1878 !(dev->features & NETIF_F_FRAGLIST) && 2090 if (skb_needs_linearize(skb, dev) && __skb_linearize(skb))
1879 __skb_linearize(skb))
1880 goto out_kfree_skb;
1881
1882 /* Fragmented skb is linearized if device does not support SG,
1883 * or if at least one of fragments is in highmem and device
1884 * does not support DMA from it.
1885 */
1886 if (skb_shinfo(skb)->nr_frags &&
1887 (!(dev->features & NETIF_F_SG) || illegal_highdma(dev, skb)) &&
1888 __skb_linearize(skb))
1889 goto out_kfree_skb; 2091 goto out_kfree_skb;
1890 2092
1891 /* If packet is not checksummed and device does not support 2093 /* If packet is not checksummed and device does not support
@@ -1905,7 +2107,7 @@ gso:
1905 rcu_read_lock_bh(); 2107 rcu_read_lock_bh();
1906 2108
1907 txq = dev_pick_tx(dev, skb); 2109 txq = dev_pick_tx(dev, skb);
1908 q = rcu_dereference(txq->qdisc); 2110 q = rcu_dereference_bh(txq->qdisc);
1909 2111
1910#ifdef CONFIG_NET_CLS_ACT 2112#ifdef CONFIG_NET_CLS_ACT
1911 skb->tc_verd = SET_TC_AT(skb->tc_verd, AT_EGRESS); 2113 skb->tc_verd = SET_TC_AT(skb->tc_verd, AT_EGRESS);
@@ -1935,8 +2137,8 @@ gso:
1935 HARD_TX_LOCK(dev, txq, cpu); 2137 HARD_TX_LOCK(dev, txq, cpu);
1936 2138
1937 if (!netif_tx_queue_stopped(txq)) { 2139 if (!netif_tx_queue_stopped(txq)) {
1938 rc = NET_XMIT_SUCCESS; 2140 rc = dev_hard_start_xmit(skb, dev, txq);
1939 if (!dev_hard_start_xmit(skb, dev, txq)) { 2141 if (dev_xmit_complete(rc)) {
1940 HARD_TX_UNLOCK(dev, txq); 2142 HARD_TX_UNLOCK(dev, txq);
1941 goto out; 2143 goto out;
1942 } 2144 }
@@ -2191,7 +2393,7 @@ static int ing_filter(struct sk_buff *skb)
2191 if (MAX_RED_LOOP < ttl++) { 2393 if (MAX_RED_LOOP < ttl++) {
2192 printk(KERN_WARNING 2394 printk(KERN_WARNING
2193 "Redir loop detected Dropping packet (%d->%d)\n", 2395 "Redir loop detected Dropping packet (%d->%d)\n",
2194 skb->iif, dev->ifindex); 2396 skb->skb_iif, dev->ifindex);
2195 return TC_ACT_SHOT; 2397 return TC_ACT_SHOT;
2196 } 2398 }
2197 2399
@@ -2285,30 +2487,33 @@ int netif_receive_skb(struct sk_buff *skb)
2285{ 2487{
2286 struct packet_type *ptype, *pt_prev; 2488 struct packet_type *ptype, *pt_prev;
2287 struct net_device *orig_dev; 2489 struct net_device *orig_dev;
2490 struct net_device *master;
2288 struct net_device *null_or_orig; 2491 struct net_device *null_or_orig;
2492 struct net_device *null_or_bond;
2289 int ret = NET_RX_DROP; 2493 int ret = NET_RX_DROP;
2290 __be16 type; 2494 __be16 type;
2291 2495
2292 if (!skb->tstamp.tv64) 2496 if (!skb->tstamp.tv64)
2293 net_timestamp(skb); 2497 net_timestamp(skb);
2294 2498
2295 if (skb->vlan_tci && vlan_hwaccel_do_receive(skb)) 2499 if (vlan_tx_tag_present(skb) && vlan_hwaccel_do_receive(skb))
2296 return NET_RX_SUCCESS; 2500 return NET_RX_SUCCESS;
2297 2501
2298 /* if we've gotten here through NAPI, check netpoll */ 2502 /* if we've gotten here through NAPI, check netpoll */
2299 if (netpoll_receive_skb(skb)) 2503 if (netpoll_receive_skb(skb))
2300 return NET_RX_DROP; 2504 return NET_RX_DROP;
2301 2505
2302 if (!skb->iif) 2506 if (!skb->skb_iif)
2303 skb->iif = skb->dev->ifindex; 2507 skb->skb_iif = skb->dev->ifindex;
2304 2508
2305 null_or_orig = NULL; 2509 null_or_orig = NULL;
2306 orig_dev = skb->dev; 2510 orig_dev = skb->dev;
2307 if (orig_dev->master) { 2511 master = ACCESS_ONCE(orig_dev->master);
2308 if (skb_bond_should_drop(skb)) 2512 if (master) {
2513 if (skb_bond_should_drop(skb, master))
2309 null_or_orig = orig_dev; /* deliver only exact match */ 2514 null_or_orig = orig_dev; /* deliver only exact match */
2310 else 2515 else
2311 skb->dev = orig_dev->master; 2516 skb->dev = master;
2312 } 2517 }
2313 2518
2314 __get_cpu_var(netdev_rx_stat).total++; 2519 __get_cpu_var(netdev_rx_stat).total++;
@@ -2351,12 +2556,24 @@ ncls:
2351 if (!skb) 2556 if (!skb)
2352 goto out; 2557 goto out;
2353 2558
2559 /*
2560 * Make sure frames received on VLAN interfaces stacked on
2561 * bonding interfaces still make their way to any base bonding
2562 * device that may have registered for a specific ptype. The
2563 * handler may have to adjust skb->dev and orig_dev.
2564 */
2565 null_or_bond = NULL;
2566 if ((skb->dev->priv_flags & IFF_802_1Q_VLAN) &&
2567 (vlan_dev_real_dev(skb->dev)->priv_flags & IFF_BONDING)) {
2568 null_or_bond = vlan_dev_real_dev(skb->dev);
2569 }
2570
2354 type = skb->protocol; 2571 type = skb->protocol;
2355 list_for_each_entry_rcu(ptype, 2572 list_for_each_entry_rcu(ptype,
2356 &ptype_base[ntohs(type) & PTYPE_HASH_MASK], list) { 2573 &ptype_base[ntohs(type) & PTYPE_HASH_MASK], list) {
2357 if (ptype->type == type && 2574 if (ptype->type == type && (ptype->dev == null_or_orig ||
2358 (ptype->dev == null_or_orig || ptype->dev == skb->dev || 2575 ptype->dev == skb->dev || ptype->dev == orig_dev ||
2359 ptype->dev == orig_dev)) { 2576 ptype->dev == null_or_bond)) {
2360 if (pt_prev) 2577 if (pt_prev)
2361 ret = deliver_skb(skb, pt_prev, orig_dev); 2578 ret = deliver_skb(skb, pt_prev, orig_dev);
2362 pt_prev = ptype; 2579 pt_prev = ptype;
@@ -2425,7 +2642,7 @@ out:
2425 return netif_receive_skb(skb); 2642 return netif_receive_skb(skb);
2426} 2643}
2427 2644
2428void napi_gro_flush(struct napi_struct *napi) 2645static void napi_gro_flush(struct napi_struct *napi)
2429{ 2646{
2430 struct sk_buff *skb, *next; 2647 struct sk_buff *skb, *next;
2431 2648
@@ -2438,9 +2655,8 @@ void napi_gro_flush(struct napi_struct *napi)
2438 napi->gro_count = 0; 2655 napi->gro_count = 0;
2439 napi->gro_list = NULL; 2656 napi->gro_list = NULL;
2440} 2657}
2441EXPORT_SYMBOL(napi_gro_flush);
2442 2658
2443int dev_gro_receive(struct napi_struct *napi, struct sk_buff *skb) 2659enum gro_result dev_gro_receive(struct napi_struct *napi, struct sk_buff *skb)
2444{ 2660{
2445 struct sk_buff **pp = NULL; 2661 struct sk_buff **pp = NULL;
2446 struct packet_type *ptype; 2662 struct packet_type *ptype;
@@ -2448,7 +2664,7 @@ int dev_gro_receive(struct napi_struct *napi, struct sk_buff *skb)
2448 struct list_head *head = &ptype_base[ntohs(type) & PTYPE_HASH_MASK]; 2664 struct list_head *head = &ptype_base[ntohs(type) & PTYPE_HASH_MASK];
2449 int same_flow; 2665 int same_flow;
2450 int mac_len; 2666 int mac_len;
2451 int ret; 2667 enum gro_result ret;
2452 2668
2453 if (!(skb->dev->features & NETIF_F_GRO)) 2669 if (!(skb->dev->features & NETIF_F_GRO))
2454 goto normal; 2670 goto normal;
@@ -2532,7 +2748,8 @@ normal:
2532} 2748}
2533EXPORT_SYMBOL(dev_gro_receive); 2749EXPORT_SYMBOL(dev_gro_receive);
2534 2750
2535static int __napi_gro_receive(struct napi_struct *napi, struct sk_buff *skb) 2751static gro_result_t
2752__napi_gro_receive(struct napi_struct *napi, struct sk_buff *skb)
2536{ 2753{
2537 struct sk_buff *p; 2754 struct sk_buff *p;
2538 2755
@@ -2540,33 +2757,35 @@ static int __napi_gro_receive(struct napi_struct *napi, struct sk_buff *skb)
2540 return GRO_NORMAL; 2757 return GRO_NORMAL;
2541 2758
2542 for (p = napi->gro_list; p; p = p->next) { 2759 for (p = napi->gro_list; p; p = p->next) {
2543 NAPI_GRO_CB(p)->same_flow = (p->dev == skb->dev) 2760 NAPI_GRO_CB(p)->same_flow =
2544 && !compare_ether_header(skb_mac_header(p), 2761 (p->dev == skb->dev) &&
2545 skb_gro_mac_header(skb)); 2762 !compare_ether_header(skb_mac_header(p),
2763 skb_gro_mac_header(skb));
2546 NAPI_GRO_CB(p)->flush = 0; 2764 NAPI_GRO_CB(p)->flush = 0;
2547 } 2765 }
2548 2766
2549 return dev_gro_receive(napi, skb); 2767 return dev_gro_receive(napi, skb);
2550} 2768}
2551 2769
2552int napi_skb_finish(int ret, struct sk_buff *skb) 2770gro_result_t napi_skb_finish(gro_result_t ret, struct sk_buff *skb)
2553{ 2771{
2554 int err = NET_RX_SUCCESS;
2555
2556 switch (ret) { 2772 switch (ret) {
2557 case GRO_NORMAL: 2773 case GRO_NORMAL:
2558 return netif_receive_skb(skb); 2774 if (netif_receive_skb(skb))
2775 ret = GRO_DROP;
2776 break;
2559 2777
2560 case GRO_DROP: 2778 case GRO_DROP:
2561 err = NET_RX_DROP;
2562 /* fall through */
2563
2564 case GRO_MERGED_FREE: 2779 case GRO_MERGED_FREE:
2565 kfree_skb(skb); 2780 kfree_skb(skb);
2566 break; 2781 break;
2782
2783 case GRO_HELD:
2784 case GRO_MERGED:
2785 break;
2567 } 2786 }
2568 2787
2569 return err; 2788 return ret;
2570} 2789}
2571EXPORT_SYMBOL(napi_skb_finish); 2790EXPORT_SYMBOL(napi_skb_finish);
2572 2791
@@ -2586,7 +2805,7 @@ void skb_gro_reset_offset(struct sk_buff *skb)
2586} 2805}
2587EXPORT_SYMBOL(skb_gro_reset_offset); 2806EXPORT_SYMBOL(skb_gro_reset_offset);
2588 2807
2589int napi_gro_receive(struct napi_struct *napi, struct sk_buff *skb) 2808gro_result_t napi_gro_receive(struct napi_struct *napi, struct sk_buff *skb)
2590{ 2809{
2591 skb_gro_reset_offset(skb); 2810 skb_gro_reset_offset(skb);
2592 2811
@@ -2605,49 +2824,41 @@ EXPORT_SYMBOL(napi_reuse_skb);
2605 2824
2606struct sk_buff *napi_get_frags(struct napi_struct *napi) 2825struct sk_buff *napi_get_frags(struct napi_struct *napi)
2607{ 2826{
2608 struct net_device *dev = napi->dev;
2609 struct sk_buff *skb = napi->skb; 2827 struct sk_buff *skb = napi->skb;
2610 2828
2611 if (!skb) { 2829 if (!skb) {
2612 skb = netdev_alloc_skb(dev, GRO_MAX_HEAD + NET_IP_ALIGN); 2830 skb = netdev_alloc_skb_ip_align(napi->dev, GRO_MAX_HEAD);
2613 if (!skb) 2831 if (skb)
2614 goto out; 2832 napi->skb = skb;
2615
2616 skb_reserve(skb, NET_IP_ALIGN);
2617
2618 napi->skb = skb;
2619 } 2833 }
2620
2621out:
2622 return skb; 2834 return skb;
2623} 2835}
2624EXPORT_SYMBOL(napi_get_frags); 2836EXPORT_SYMBOL(napi_get_frags);
2625 2837
2626int napi_frags_finish(struct napi_struct *napi, struct sk_buff *skb, int ret) 2838gro_result_t napi_frags_finish(struct napi_struct *napi, struct sk_buff *skb,
2839 gro_result_t ret)
2627{ 2840{
2628 int err = NET_RX_SUCCESS;
2629
2630 switch (ret) { 2841 switch (ret) {
2631 case GRO_NORMAL: 2842 case GRO_NORMAL:
2632 case GRO_HELD: 2843 case GRO_HELD:
2633 skb->protocol = eth_type_trans(skb, napi->dev); 2844 skb->protocol = eth_type_trans(skb, skb->dev);
2634 2845
2635 if (ret == GRO_NORMAL) 2846 if (ret == GRO_HELD)
2636 return netif_receive_skb(skb); 2847 skb_gro_pull(skb, -ETH_HLEN);
2637 2848 else if (netif_receive_skb(skb))
2638 skb_gro_pull(skb, -ETH_HLEN); 2849 ret = GRO_DROP;
2639 break; 2850 break;
2640 2851
2641 case GRO_DROP: 2852 case GRO_DROP:
2642 err = NET_RX_DROP;
2643 /* fall through */
2644
2645 case GRO_MERGED_FREE: 2853 case GRO_MERGED_FREE:
2646 napi_reuse_skb(napi, skb); 2854 napi_reuse_skb(napi, skb);
2647 break; 2855 break;
2856
2857 case GRO_MERGED:
2858 break;
2648 } 2859 }
2649 2860
2650 return err; 2861 return ret;
2651} 2862}
2652EXPORT_SYMBOL(napi_frags_finish); 2863EXPORT_SYMBOL(napi_frags_finish);
2653 2864
@@ -2688,12 +2899,12 @@ out:
2688} 2899}
2689EXPORT_SYMBOL(napi_frags_skb); 2900EXPORT_SYMBOL(napi_frags_skb);
2690 2901
2691int napi_gro_frags(struct napi_struct *napi) 2902gro_result_t napi_gro_frags(struct napi_struct *napi)
2692{ 2903{
2693 struct sk_buff *skb = napi_frags_skb(napi); 2904 struct sk_buff *skb = napi_frags_skb(napi);
2694 2905
2695 if (!skb) 2906 if (!skb)
2696 return NET_RX_DROP; 2907 return GRO_DROP;
2697 2908
2698 return napi_frags_finish(napi, skb, __napi_gro_receive(napi, skb)); 2909 return napi_frags_finish(napi, skb, __napi_gro_receive(napi, skb));
2699} 2910}
@@ -2835,7 +3046,7 @@ static void net_rx_action(struct softirq_action *h)
2835 * entries to the tail of this list, and only ->poll() 3046 * entries to the tail of this list, and only ->poll()
2836 * calls can remove this head entry from the list. 3047 * calls can remove this head entry from the list.
2837 */ 3048 */
2838 n = list_entry(list->next, struct napi_struct, poll_list); 3049 n = list_first_entry(list, struct napi_struct, poll_list);
2839 3050
2840 have = netpoll_poll_lock(n); 3051 have = netpoll_poll_lock(n);
2841 3052
@@ -2938,15 +3149,15 @@ static int dev_ifname(struct net *net, struct ifreq __user *arg)
2938 if (copy_from_user(&ifr, arg, sizeof(struct ifreq))) 3149 if (copy_from_user(&ifr, arg, sizeof(struct ifreq)))
2939 return -EFAULT; 3150 return -EFAULT;
2940 3151
2941 read_lock(&dev_base_lock); 3152 rcu_read_lock();
2942 dev = __dev_get_by_index(net, ifr.ifr_ifindex); 3153 dev = dev_get_by_index_rcu(net, ifr.ifr_ifindex);
2943 if (!dev) { 3154 if (!dev) {
2944 read_unlock(&dev_base_lock); 3155 rcu_read_unlock();
2945 return -ENODEV; 3156 return -ENODEV;
2946 } 3157 }
2947 3158
2948 strcpy(ifr.ifr_name, dev->name); 3159 strcpy(ifr.ifr_name, dev->name);
2949 read_unlock(&dev_base_lock); 3160 rcu_read_unlock();
2950 3161
2951 if (copy_to_user(arg, &ifr, sizeof(struct ifreq))) 3162 if (copy_to_user(arg, &ifr, sizeof(struct ifreq)))
2952 return -EFAULT; 3163 return -EFAULT;
@@ -3016,18 +3227,18 @@ static int dev_ifconf(struct net *net, char __user *arg)
3016 * in detail. 3227 * in detail.
3017 */ 3228 */
3018void *dev_seq_start(struct seq_file *seq, loff_t *pos) 3229void *dev_seq_start(struct seq_file *seq, loff_t *pos)
3019 __acquires(dev_base_lock) 3230 __acquires(RCU)
3020{ 3231{
3021 struct net *net = seq_file_net(seq); 3232 struct net *net = seq_file_net(seq);
3022 loff_t off; 3233 loff_t off;
3023 struct net_device *dev; 3234 struct net_device *dev;
3024 3235
3025 read_lock(&dev_base_lock); 3236 rcu_read_lock();
3026 if (!*pos) 3237 if (!*pos)
3027 return SEQ_START_TOKEN; 3238 return SEQ_START_TOKEN;
3028 3239
3029 off = 1; 3240 off = 1;
3030 for_each_netdev(net, dev) 3241 for_each_netdev_rcu(net, dev)
3031 if (off++ == *pos) 3242 if (off++ == *pos)
3032 return dev; 3243 return dev;
3033 3244
@@ -3036,23 +3247,25 @@ void *dev_seq_start(struct seq_file *seq, loff_t *pos)
3036 3247
3037void *dev_seq_next(struct seq_file *seq, void *v, loff_t *pos) 3248void *dev_seq_next(struct seq_file *seq, void *v, loff_t *pos)
3038{ 3249{
3039 struct net *net = seq_file_net(seq); 3250 struct net_device *dev = (v == SEQ_START_TOKEN) ?
3251 first_net_device(seq_file_net(seq)) :
3252 next_net_device((struct net_device *)v);
3253
3040 ++*pos; 3254 ++*pos;
3041 return v == SEQ_START_TOKEN ? 3255 return rcu_dereference(dev);
3042 first_net_device(net) : next_net_device((struct net_device *)v);
3043} 3256}
3044 3257
3045void dev_seq_stop(struct seq_file *seq, void *v) 3258void dev_seq_stop(struct seq_file *seq, void *v)
3046 __releases(dev_base_lock) 3259 __releases(RCU)
3047{ 3260{
3048 read_unlock(&dev_base_lock); 3261 rcu_read_unlock();
3049} 3262}
3050 3263
3051static void dev_seq_printf_stats(struct seq_file *seq, struct net_device *dev) 3264static void dev_seq_printf_stats(struct seq_file *seq, struct net_device *dev)
3052{ 3265{
3053 const struct net_device_stats *stats = dev_get_stats(dev); 3266 const struct net_device_stats *stats = dev_get_stats(dev);
3054 3267
3055 seq_printf(seq, "%6s:%8lu %7lu %4lu %4lu %4lu %5lu %10lu %9lu " 3268 seq_printf(seq, "%6s: %7lu %7lu %4lu %4lu %4lu %5lu %10lu %9lu "
3056 "%8lu %7lu %4lu %4lu %4lu %5lu %7lu %10lu\n", 3269 "%8lu %7lu %4lu %4lu %4lu %5lu %7lu %10lu\n",
3057 dev->name, stats->rx_bytes, stats->rx_packets, 3270 dev->name, stats->rx_bytes, stats->rx_packets,
3058 stats->rx_errors, 3271 stats->rx_errors,
@@ -3507,10 +3720,10 @@ void __dev_set_rx_mode(struct net_device *dev)
3507 /* Unicast addresses changes may only happen under the rtnl, 3720 /* Unicast addresses changes may only happen under the rtnl,
3508 * therefore calling __dev_set_promiscuity here is safe. 3721 * therefore calling __dev_set_promiscuity here is safe.
3509 */ 3722 */
3510 if (dev->uc.count > 0 && !dev->uc_promisc) { 3723 if (!netdev_uc_empty(dev) && !dev->uc_promisc) {
3511 __dev_set_promiscuity(dev, 1); 3724 __dev_set_promiscuity(dev, 1);
3512 dev->uc_promisc = 1; 3725 dev->uc_promisc = 1;
3513 } else if (dev->uc.count == 0 && dev->uc_promisc) { 3726 } else if (netdev_uc_empty(dev) && dev->uc_promisc) {
3514 __dev_set_promiscuity(dev, -1); 3727 __dev_set_promiscuity(dev, -1);
3515 dev->uc_promisc = 0; 3728 dev->uc_promisc = 0;
3516 } 3729 }
@@ -4078,7 +4291,7 @@ static void dev_addr_discard(struct net_device *dev)
4078 netif_addr_lock_bh(dev); 4291 netif_addr_lock_bh(dev);
4079 4292
4080 __dev_addr_discard(&dev->mc_list); 4293 __dev_addr_discard(&dev->mc_list);
4081 dev->mc_count = 0; 4294 netdev_mc_count(dev) = 0;
4082 4295
4083 netif_addr_unlock_bh(dev); 4296 netif_addr_unlock_bh(dev);
4084} 4297}
@@ -4114,18 +4327,10 @@ unsigned dev_get_flags(const struct net_device *dev)
4114} 4327}
4115EXPORT_SYMBOL(dev_get_flags); 4328EXPORT_SYMBOL(dev_get_flags);
4116 4329
4117/** 4330int __dev_change_flags(struct net_device *dev, unsigned int flags)
4118 * dev_change_flags - change device settings
4119 * @dev: device
4120 * @flags: device state flags
4121 *
4122 * Change settings on device based state flags. The flags are
4123 * in the userspace exported format.
4124 */
4125int dev_change_flags(struct net_device *dev, unsigned flags)
4126{ 4331{
4127 int ret, changes;
4128 int old_flags = dev->flags; 4332 int old_flags = dev->flags;
4333 int ret;
4129 4334
4130 ASSERT_RTNL(); 4335 ASSERT_RTNL();
4131 4336
@@ -4156,17 +4361,12 @@ int dev_change_flags(struct net_device *dev, unsigned flags)
4156 4361
4157 ret = 0; 4362 ret = 0;
4158 if ((old_flags ^ flags) & IFF_UP) { /* Bit is different ? */ 4363 if ((old_flags ^ flags) & IFF_UP) { /* Bit is different ? */
4159 ret = ((old_flags & IFF_UP) ? dev_close : dev_open)(dev); 4364 ret = ((old_flags & IFF_UP) ? __dev_close : __dev_open)(dev);
4160 4365
4161 if (!ret) 4366 if (!ret)
4162 dev_set_rx_mode(dev); 4367 dev_set_rx_mode(dev);
4163 } 4368 }
4164 4369
4165 if (dev->flags & IFF_UP &&
4166 ((old_flags ^ dev->flags) & ~(IFF_UP | IFF_PROMISC | IFF_ALLMULTI |
4167 IFF_VOLATILE)))
4168 call_netdevice_notifiers(NETDEV_CHANGE, dev);
4169
4170 if ((flags ^ dev->gflags) & IFF_PROMISC) { 4370 if ((flags ^ dev->gflags) & IFF_PROMISC) {
4171 int inc = (flags & IFF_PROMISC) ? 1 : -1; 4371 int inc = (flags & IFF_PROMISC) ? 1 : -1;
4172 4372
@@ -4185,11 +4385,47 @@ int dev_change_flags(struct net_device *dev, unsigned flags)
4185 dev_set_allmulti(dev, inc); 4385 dev_set_allmulti(dev, inc);
4186 } 4386 }
4187 4387
4188 /* Exclude state transition flags, already notified */ 4388 return ret;
4189 changes = (old_flags ^ dev->flags) & ~(IFF_UP | IFF_RUNNING); 4389}
4390
4391void __dev_notify_flags(struct net_device *dev, unsigned int old_flags)
4392{
4393 unsigned int changes = dev->flags ^ old_flags;
4394
4395 if (changes & IFF_UP) {
4396 if (dev->flags & IFF_UP)
4397 call_netdevice_notifiers(NETDEV_UP, dev);
4398 else
4399 call_netdevice_notifiers(NETDEV_DOWN, dev);
4400 }
4401
4402 if (dev->flags & IFF_UP &&
4403 (changes & ~(IFF_UP | IFF_PROMISC | IFF_ALLMULTI | IFF_VOLATILE)))
4404 call_netdevice_notifiers(NETDEV_CHANGE, dev);
4405}
4406
4407/**
4408 * dev_change_flags - change device settings
4409 * @dev: device
4410 * @flags: device state flags
4411 *
4412 * Change settings on device based state flags. The flags are
4413 * in the userspace exported format.
4414 */
4415int dev_change_flags(struct net_device *dev, unsigned flags)
4416{
4417 int ret, changes;
4418 int old_flags = dev->flags;
4419
4420 ret = __dev_change_flags(dev, flags);
4421 if (ret < 0)
4422 return ret;
4423
4424 changes = old_flags ^ dev->flags;
4190 if (changes) 4425 if (changes)
4191 rtmsg_ifinfo(RTM_NEWLINK, dev, changes); 4426 rtmsg_ifinfo(RTM_NEWLINK, dev, changes);
4192 4427
4428 __dev_notify_flags(dev, old_flags);
4193 return ret; 4429 return ret;
4194} 4430}
4195EXPORT_SYMBOL(dev_change_flags); 4431EXPORT_SYMBOL(dev_change_flags);
@@ -4254,12 +4490,12 @@ int dev_set_mac_address(struct net_device *dev, struct sockaddr *sa)
4254EXPORT_SYMBOL(dev_set_mac_address); 4490EXPORT_SYMBOL(dev_set_mac_address);
4255 4491
4256/* 4492/*
4257 * Perform the SIOCxIFxxx calls, inside read_lock(dev_base_lock) 4493 * Perform the SIOCxIFxxx calls, inside rcu_read_lock()
4258 */ 4494 */
4259static int dev_ifsioc_locked(struct net *net, struct ifreq *ifr, unsigned int cmd) 4495static int dev_ifsioc_locked(struct net *net, struct ifreq *ifr, unsigned int cmd)
4260{ 4496{
4261 int err; 4497 int err;
4262 struct net_device *dev = __dev_get_by_name(net, ifr->ifr_name); 4498 struct net_device *dev = dev_get_by_name_rcu(net, ifr->ifr_name);
4263 4499
4264 if (!dev) 4500 if (!dev)
4265 return -ENODEV; 4501 return -ENODEV;
@@ -4491,9 +4727,9 @@ int dev_ioctl(struct net *net, unsigned int cmd, void __user *arg)
4491 case SIOCGIFINDEX: 4727 case SIOCGIFINDEX:
4492 case SIOCGIFTXQLEN: 4728 case SIOCGIFTXQLEN:
4493 dev_load(net, ifr.ifr_name); 4729 dev_load(net, ifr.ifr_name);
4494 read_lock(&dev_base_lock); 4730 rcu_read_lock();
4495 ret = dev_ifsioc_locked(net, &ifr, cmd); 4731 ret = dev_ifsioc_locked(net, &ifr, cmd);
4496 read_unlock(&dev_base_lock); 4732 rcu_read_unlock();
4497 if (!ret) { 4733 if (!ret) {
4498 if (colon) 4734 if (colon)
4499 *colon = ':'; 4735 *colon = ':';
@@ -4636,59 +4872,86 @@ static void net_set_todo(struct net_device *dev)
4636 list_add_tail(&dev->todo_list, &net_todo_list); 4872 list_add_tail(&dev->todo_list, &net_todo_list);
4637} 4873}
4638 4874
4639static void rollback_registered(struct net_device *dev) 4875static void rollback_registered_many(struct list_head *head)
4640{ 4876{
4877 struct net_device *dev, *tmp;
4878
4641 BUG_ON(dev_boot_phase); 4879 BUG_ON(dev_boot_phase);
4642 ASSERT_RTNL(); 4880 ASSERT_RTNL();
4643 4881
4644 /* Some devices call without registering for initialization unwind. */ 4882 list_for_each_entry_safe(dev, tmp, head, unreg_list) {
4645 if (dev->reg_state == NETREG_UNINITIALIZED) { 4883 /* Some devices call without registering
4646 printk(KERN_DEBUG "unregister_netdevice: device %s/%p never " 4884 * for initialization unwind. Remove those
4647 "was registered\n", dev->name, dev); 4885 * devices and proceed with the remaining.
4886 */
4887 if (dev->reg_state == NETREG_UNINITIALIZED) {
4888 pr_debug("unregister_netdevice: device %s/%p never "
4889 "was registered\n", dev->name, dev);
4648 4890
4649 WARN_ON(1); 4891 WARN_ON(1);
4650 return; 4892 list_del(&dev->unreg_list);
4651 } 4893 continue;
4894 }
4652 4895
4653 BUG_ON(dev->reg_state != NETREG_REGISTERED); 4896 BUG_ON(dev->reg_state != NETREG_REGISTERED);
4654 4897
4655 /* If device is running, close it first. */ 4898 /* If device is running, close it first. */
4656 dev_close(dev); 4899 dev_close(dev);
4657 4900
4658 /* And unlink it from device chain. */ 4901 /* And unlink it from device chain. */
4659 unlist_netdevice(dev); 4902 unlist_netdevice(dev);
4660 4903
4661 dev->reg_state = NETREG_UNREGISTERING; 4904 dev->reg_state = NETREG_UNREGISTERING;
4905 }
4662 4906
4663 synchronize_net(); 4907 synchronize_net();
4664 4908
4665 /* Shutdown queueing discipline. */ 4909 list_for_each_entry(dev, head, unreg_list) {
4666 dev_shutdown(dev); 4910 /* Shutdown queueing discipline. */
4911 dev_shutdown(dev);
4667 4912
4668 4913
4669 /* Notify protocols, that we are about to destroy 4914 /* Notify protocols, that we are about to destroy
4670 this device. They should clean all the things. 4915 this device. They should clean all the things.
4671 */ 4916 */
4672 call_netdevice_notifiers(NETDEV_UNREGISTER, dev); 4917 call_netdevice_notifiers(NETDEV_UNREGISTER, dev);
4673 4918
4674 /* 4919 if (!dev->rtnl_link_ops ||
4675 * Flush the unicast and multicast chains 4920 dev->rtnl_link_state == RTNL_LINK_INITIALIZED)
4676 */ 4921 rtmsg_ifinfo(RTM_DELLINK, dev, ~0U);
4677 dev_unicast_flush(dev);
4678 dev_addr_discard(dev);
4679 4922
4680 if (dev->netdev_ops->ndo_uninit) 4923 /*
4681 dev->netdev_ops->ndo_uninit(dev); 4924 * Flush the unicast and multicast chains
4925 */
4926 dev_unicast_flush(dev);
4927 dev_addr_discard(dev);
4682 4928
4683 /* Notifier chain MUST detach us from master device. */ 4929 if (dev->netdev_ops->ndo_uninit)
4684 WARN_ON(dev->master); 4930 dev->netdev_ops->ndo_uninit(dev);
4685 4931
4686 /* Remove entries from kobject tree */ 4932 /* Notifier chain MUST detach us from master device. */
4687 netdev_unregister_kobject(dev); 4933 WARN_ON(dev->master);
4934
4935 /* Remove entries from kobject tree */
4936 netdev_unregister_kobject(dev);
4937 }
4938
4939 /* Process any work delayed until the end of the batch */
4940 dev = list_first_entry(head, struct net_device, unreg_list);
4941 call_netdevice_notifiers(NETDEV_UNREGISTER_BATCH, dev);
4688 4942
4689 synchronize_net(); 4943 synchronize_net();
4690 4944
4691 dev_put(dev); 4945 list_for_each_entry(dev, head, unreg_list)
4946 dev_put(dev);
4947}
4948
4949static void rollback_registered(struct net_device *dev)
4950{
4951 LIST_HEAD(single);
4952
4953 list_add(&dev->unreg_list, &single);
4954 rollback_registered_many(&single);
4692} 4955}
4693 4956
4694static void __netdev_init_queue_locks_one(struct net_device *dev, 4957static void __netdev_init_queue_locks_one(struct net_device *dev,
@@ -4747,6 +5010,33 @@ unsigned long netdev_fix_features(unsigned long features, const char *name)
4747EXPORT_SYMBOL(netdev_fix_features); 5010EXPORT_SYMBOL(netdev_fix_features);
4748 5011
4749/** 5012/**
5013 * netif_stacked_transfer_operstate - transfer operstate
5014 * @rootdev: the root or lower level device to transfer state from
5015 * @dev: the device to transfer operstate to
5016 *
5017 * Transfer operational state from root to device. This is normally
5018 * called when a stacking relationship exists between the root
5019 * device and the device(a leaf device).
5020 */
5021void netif_stacked_transfer_operstate(const struct net_device *rootdev,
5022 struct net_device *dev)
5023{
5024 if (rootdev->operstate == IF_OPER_DORMANT)
5025 netif_dormant_on(dev);
5026 else
5027 netif_dormant_off(dev);
5028
5029 if (netif_carrier_ok(rootdev)) {
5030 if (!netif_carrier_ok(dev))
5031 netif_carrier_on(dev);
5032 } else {
5033 if (netif_carrier_ok(dev))
5034 netif_carrier_off(dev);
5035 }
5036}
5037EXPORT_SYMBOL(netif_stacked_transfer_operstate);
5038
5039/**
4750 * register_netdevice - register a network device 5040 * register_netdevice - register a network device
4751 * @dev: device to register 5041 * @dev: device to register
4752 * 5042 *
@@ -4765,8 +5055,6 @@ EXPORT_SYMBOL(netdev_fix_features);
4765 5055
4766int register_netdevice(struct net_device *dev) 5056int register_netdevice(struct net_device *dev)
4767{ 5057{
4768 struct hlist_head *head;
4769 struct hlist_node *p;
4770 int ret; 5058 int ret;
4771 struct net *net = dev_net(dev); 5059 struct net *net = dev_net(dev);
4772 5060
@@ -4795,26 +5083,14 @@ int register_netdevice(struct net_device *dev)
4795 } 5083 }
4796 } 5084 }
4797 5085
4798 if (!dev_valid_name(dev->name)) { 5086 ret = dev_get_valid_name(net, dev->name, dev->name, 0);
4799 ret = -EINVAL; 5087 if (ret)
4800 goto err_uninit; 5088 goto err_uninit;
4801 }
4802 5089
4803 dev->ifindex = dev_new_index(net); 5090 dev->ifindex = dev_new_index(net);
4804 if (dev->iflink == -1) 5091 if (dev->iflink == -1)
4805 dev->iflink = dev->ifindex; 5092 dev->iflink = dev->ifindex;
4806 5093
4807 /* Check for existence of name */
4808 head = dev_name_hash(net, dev->name);
4809 hlist_for_each(p, head) {
4810 struct net_device *d
4811 = hlist_entry(p, struct net_device, name_hlist);
4812 if (!strncmp(d->name, dev->name, IFNAMSIZ)) {
4813 ret = -EEXIST;
4814 goto err_uninit;
4815 }
4816 }
4817
4818 /* Fix illegal checksum combinations */ 5094 /* Fix illegal checksum combinations */
4819 if ((dev->features & NETIF_F_HW_CSUM) && 5095 if ((dev->features & NETIF_F_HW_CSUM) &&
4820 (dev->features & (NETIF_F_IP_CSUM|NETIF_F_IPV6_CSUM))) { 5096 (dev->features & (NETIF_F_IP_CSUM|NETIF_F_IPV6_CSUM))) {
@@ -4837,6 +5113,12 @@ int register_netdevice(struct net_device *dev)
4837 dev->features |= NETIF_F_GSO; 5113 dev->features |= NETIF_F_GSO;
4838 5114
4839 netdev_initialize_kobject(dev); 5115 netdev_initialize_kobject(dev);
5116
5117 ret = call_netdevice_notifiers(NETDEV_POST_INIT, dev);
5118 ret = notifier_to_errno(ret);
5119 if (ret)
5120 goto err_uninit;
5121
4840 ret = netdev_register_kobject(dev); 5122 ret = netdev_register_kobject(dev);
4841 if (ret) 5123 if (ret)
4842 goto err_uninit; 5124 goto err_uninit;
@@ -4860,6 +5142,13 @@ int register_netdevice(struct net_device *dev)
4860 rollback_registered(dev); 5142 rollback_registered(dev);
4861 dev->reg_state = NETREG_UNREGISTERED; 5143 dev->reg_state = NETREG_UNREGISTERED;
4862 } 5144 }
5145 /*
5146 * Prevent userspace races by waiting until the network
5147 * device is fully setup before sending notifications.
5148 */
5149 if (!dev->rtnl_link_ops ||
5150 dev->rtnl_link_state == RTNL_LINK_INITIALIZED)
5151 rtmsg_ifinfo(RTM_NEWLINK, dev, ~0U);
4863 5152
4864out: 5153out:
4865 return ret; 5154 return ret;
@@ -4961,6 +5250,8 @@ static void netdev_wait_allrefs(struct net_device *dev)
4961{ 5250{
4962 unsigned long rebroadcast_time, warning_time; 5251 unsigned long rebroadcast_time, warning_time;
4963 5252
5253 linkwatch_forget_dev(dev);
5254
4964 rebroadcast_time = warning_time = jiffies; 5255 rebroadcast_time = warning_time = jiffies;
4965 while (atomic_read(&dev->refcnt) != 0) { 5256 while (atomic_read(&dev->refcnt) != 0) {
4966 if (time_after(jiffies, rebroadcast_time + 1 * HZ)) { 5257 if (time_after(jiffies, rebroadcast_time + 1 * HZ)) {
@@ -4968,6 +5259,8 @@ static void netdev_wait_allrefs(struct net_device *dev)
4968 5259
4969 /* Rebroadcast unregister notification */ 5260 /* Rebroadcast unregister notification */
4970 call_netdevice_notifiers(NETDEV_UNREGISTER, dev); 5261 call_netdevice_notifiers(NETDEV_UNREGISTER, dev);
5262 /* don't resend NETDEV_UNREGISTER_BATCH, _BATCH users
5263 * should have already handle it the first time */
4971 5264
4972 if (test_bit(__LINK_STATE_LINKWATCH_PENDING, 5265 if (test_bit(__LINK_STATE_LINKWATCH_PENDING,
4973 &dev->state)) { 5266 &dev->state)) {
@@ -5032,7 +5325,7 @@ void netdev_run_todo(void)
5032 5325
5033 while (!list_empty(&list)) { 5326 while (!list_empty(&list)) {
5034 struct net_device *dev 5327 struct net_device *dev
5035 = list_entry(list.next, struct net_device, todo_list); 5328 = list_first_entry(&list, struct net_device, todo_list);
5036 list_del(&dev->todo_list); 5329 list_del(&dev->todo_list);
5037 5330
5038 if (unlikely(dev->reg_state != NETREG_UNREGISTERING)) { 5331 if (unlikely(dev->reg_state != NETREG_UNREGISTERING)) {
@@ -5063,6 +5356,32 @@ void netdev_run_todo(void)
5063} 5356}
5064 5357
5065/** 5358/**
5359 * dev_txq_stats_fold - fold tx_queues stats
5360 * @dev: device to get statistics from
5361 * @stats: struct net_device_stats to hold results
5362 */
5363void dev_txq_stats_fold(const struct net_device *dev,
5364 struct net_device_stats *stats)
5365{
5366 unsigned long tx_bytes = 0, tx_packets = 0, tx_dropped = 0;
5367 unsigned int i;
5368 struct netdev_queue *txq;
5369
5370 for (i = 0; i < dev->num_tx_queues; i++) {
5371 txq = netdev_get_tx_queue(dev, i);
5372 tx_bytes += txq->tx_bytes;
5373 tx_packets += txq->tx_packets;
5374 tx_dropped += txq->tx_dropped;
5375 }
5376 if (tx_bytes || tx_packets || tx_dropped) {
5377 stats->tx_bytes = tx_bytes;
5378 stats->tx_packets = tx_packets;
5379 stats->tx_dropped = tx_dropped;
5380 }
5381}
5382EXPORT_SYMBOL(dev_txq_stats_fold);
5383
5384/**
5066 * dev_get_stats - get network device statistics 5385 * dev_get_stats - get network device statistics
5067 * @dev: device to get statistics from 5386 * @dev: device to get statistics from
5068 * 5387 *
@@ -5076,25 +5395,9 @@ const struct net_device_stats *dev_get_stats(struct net_device *dev)
5076 5395
5077 if (ops->ndo_get_stats) 5396 if (ops->ndo_get_stats)
5078 return ops->ndo_get_stats(dev); 5397 return ops->ndo_get_stats(dev);
5079 else { 5398
5080 unsigned long tx_bytes = 0, tx_packets = 0, tx_dropped = 0; 5399 dev_txq_stats_fold(dev, &dev->stats);
5081 struct net_device_stats *stats = &dev->stats; 5400 return &dev->stats;
5082 unsigned int i;
5083 struct netdev_queue *txq;
5084
5085 for (i = 0; i < dev->num_tx_queues; i++) {
5086 txq = netdev_get_tx_queue(dev, i);
5087 tx_bytes += txq->tx_bytes;
5088 tx_packets += txq->tx_packets;
5089 tx_dropped += txq->tx_dropped;
5090 }
5091 if (tx_bytes || tx_packets || tx_dropped) {
5092 stats->tx_bytes = tx_bytes;
5093 stats->tx_packets = tx_packets;
5094 stats->tx_dropped = tx_dropped;
5095 }
5096 return stats;
5097 }
5098} 5401}
5099EXPORT_SYMBOL(dev_get_stats); 5402EXPORT_SYMBOL(dev_get_stats);
5100 5403
@@ -5173,7 +5476,11 @@ struct net_device *alloc_netdev_mq(int sizeof_priv, const char *name,
5173 5476
5174 netdev_init_queues(dev); 5477 netdev_init_queues(dev);
5175 5478
5479 INIT_LIST_HEAD(&dev->ethtool_ntuple_list.list);
5480 dev->ethtool_ntuple_list.count = 0;
5176 INIT_LIST_HEAD(&dev->napi_list); 5481 INIT_LIST_HEAD(&dev->napi_list);
5482 INIT_LIST_HEAD(&dev->unreg_list);
5483 INIT_LIST_HEAD(&dev->link_watch_list);
5177 dev->priv_flags = IFF_XMIT_DST_RELEASE; 5484 dev->priv_flags = IFF_XMIT_DST_RELEASE;
5178 setup(dev); 5485 setup(dev);
5179 strcpy(dev->name, name); 5486 strcpy(dev->name, name);
@@ -5207,6 +5514,9 @@ void free_netdev(struct net_device *dev)
5207 /* Flush device addresses */ 5514 /* Flush device addresses */
5208 dev_addr_flush(dev); 5515 dev_addr_flush(dev);
5209 5516
5517 /* Clear ethtool n-tuple list */
5518 ethtool_ntuple_flush(dev);
5519
5210 list_for_each_entry_safe(p, n, &dev->napi_list, dev_list) 5520 list_for_each_entry_safe(p, n, &dev->napi_list, dev_list)
5211 netif_napi_del(p); 5521 netif_napi_del(p);
5212 5522
@@ -5238,25 +5548,47 @@ void synchronize_net(void)
5238EXPORT_SYMBOL(synchronize_net); 5548EXPORT_SYMBOL(synchronize_net);
5239 5549
5240/** 5550/**
5241 * unregister_netdevice - remove device from the kernel 5551 * unregister_netdevice_queue - remove device from the kernel
5242 * @dev: device 5552 * @dev: device
5553 * @head: list
5243 * 5554 *
5244 * This function shuts down a device interface and removes it 5555 * This function shuts down a device interface and removes it
5245 * from the kernel tables. 5556 * from the kernel tables.
5557 * If head not NULL, device is queued to be unregistered later.
5246 * 5558 *
5247 * Callers must hold the rtnl semaphore. You may want 5559 * Callers must hold the rtnl semaphore. You may want
5248 * unregister_netdev() instead of this. 5560 * unregister_netdev() instead of this.
5249 */ 5561 */
5250 5562
5251void unregister_netdevice(struct net_device *dev) 5563void unregister_netdevice_queue(struct net_device *dev, struct list_head *head)
5252{ 5564{
5253 ASSERT_RTNL(); 5565 ASSERT_RTNL();
5254 5566
5255 rollback_registered(dev); 5567 if (head) {
5256 /* Finish processing unregister after unlock */ 5568 list_move_tail(&dev->unreg_list, head);
5257 net_set_todo(dev); 5569 } else {
5570 rollback_registered(dev);
5571 /* Finish processing unregister after unlock */
5572 net_set_todo(dev);
5573 }
5258} 5574}
5259EXPORT_SYMBOL(unregister_netdevice); 5575EXPORT_SYMBOL(unregister_netdevice_queue);
5576
5577/**
5578 * unregister_netdevice_many - unregister many devices
5579 * @head: list of devices
5580 */
5581void unregister_netdevice_many(struct list_head *head)
5582{
5583 struct net_device *dev;
5584
5585 if (!list_empty(head)) {
5586 rollback_registered_many(head);
5587 list_for_each_entry(dev, head, unreg_list)
5588 net_set_todo(dev);
5589 }
5590}
5591EXPORT_SYMBOL(unregister_netdevice_many);
5260 5592
5261/** 5593/**
5262 * unregister_netdev - remove device from the kernel 5594 * unregister_netdev - remove device from the kernel
@@ -5293,8 +5625,6 @@ EXPORT_SYMBOL(unregister_netdev);
5293 5625
5294int dev_change_net_namespace(struct net_device *dev, struct net *net, const char *pat) 5626int dev_change_net_namespace(struct net_device *dev, struct net *net, const char *pat)
5295{ 5627{
5296 char buf[IFNAMSIZ];
5297 const char *destname;
5298 int err; 5628 int err;
5299 5629
5300 ASSERT_RTNL(); 5630 ASSERT_RTNL();
@@ -5327,20 +5657,11 @@ int dev_change_net_namespace(struct net_device *dev, struct net *net, const char
5327 * we can use it in the destination network namespace. 5657 * we can use it in the destination network namespace.
5328 */ 5658 */
5329 err = -EEXIST; 5659 err = -EEXIST;
5330 destname = dev->name; 5660 if (__dev_get_by_name(net, dev->name)) {
5331 if (__dev_get_by_name(net, destname)) {
5332 /* We get here if we can't use the current device name */ 5661 /* We get here if we can't use the current device name */
5333 if (!pat) 5662 if (!pat)
5334 goto out; 5663 goto out;
5335 if (!dev_valid_name(pat)) 5664 if (dev_get_valid_name(net, pat, dev->name, 1))
5336 goto out;
5337 if (strchr(pat, '%')) {
5338 if (__dev_alloc_name(net, pat, buf) < 0)
5339 goto out;
5340 destname = buf;
5341 } else
5342 destname = pat;
5343 if (__dev_get_by_name(net, destname))
5344 goto out; 5665 goto out;
5345 } 5666 }
5346 5667
@@ -5364,6 +5685,7 @@ int dev_change_net_namespace(struct net_device *dev, struct net *net, const char
5364 this device. They should clean all the things. 5685 this device. They should clean all the things.
5365 */ 5686 */
5366 call_netdevice_notifiers(NETDEV_UNREGISTER, dev); 5687 call_netdevice_notifiers(NETDEV_UNREGISTER, dev);
5688 call_netdevice_notifiers(NETDEV_UNREGISTER_BATCH, dev);
5367 5689
5368 /* 5690 /*
5369 * Flush the unicast and multicast chains 5691 * Flush the unicast and multicast chains
@@ -5376,10 +5698,6 @@ int dev_change_net_namespace(struct net_device *dev, struct net *net, const char
5376 /* Actually switch the network namespace */ 5698 /* Actually switch the network namespace */
5377 dev_net_set(dev, net); 5699 dev_net_set(dev, net);
5378 5700
5379 /* Assign the new device name */
5380 if (destname != dev->name)
5381 strcpy(dev->name, destname);
5382
5383 /* If there is an ifindex conflict assign a new one */ 5701 /* If there is an ifindex conflict assign a new one */
5384 if (__dev_get_by_index(net, dev->ifindex)) { 5702 if (__dev_get_by_index(net, dev->ifindex)) {
5385 int iflink = (dev->iflink == dev->ifindex); 5703 int iflink = (dev->iflink == dev->ifindex);
@@ -5398,6 +5716,12 @@ int dev_change_net_namespace(struct net_device *dev, struct net *net, const char
5398 /* Notify protocols, that a new device appeared. */ 5716 /* Notify protocols, that a new device appeared. */
5399 call_netdevice_notifiers(NETDEV_REGISTER, dev); 5717 call_netdevice_notifiers(NETDEV_REGISTER, dev);
5400 5718
5719 /*
5720 * Prevent userspace races by waiting until the network
5721 * device is fully setup before sending notifications.
5722 */
5723 rtmsg_ifinfo(RTM_NEWLINK, dev, ~0U);
5724
5401 synchronize_net(); 5725 synchronize_net();
5402 err = 0; 5726 err = 0;
5403out: 5727out:
@@ -5484,7 +5808,7 @@ unsigned long netdev_increment_features(unsigned long all, unsigned long one,
5484 one |= NETIF_F_ALL_CSUM; 5808 one |= NETIF_F_ALL_CSUM;
5485 5809
5486 one |= all & NETIF_F_ONE_FOR_ALL; 5810 one |= all & NETIF_F_ONE_FOR_ALL;
5487 all &= one | NETIF_F_LLTX | NETIF_F_GSO; 5811 all &= one | NETIF_F_LLTX | NETIF_F_GSO | NETIF_F_UFO;
5488 all |= one & mask & NETIF_F_ONE_FOR_ALL; 5812 all |= one & mask & NETIF_F_ONE_FOR_ALL;
5489 5813
5490 return all; 5814 return all;
@@ -5566,14 +5890,13 @@ static struct pernet_operations __net_initdata netdev_net_ops = {
5566 5890
5567static void __net_exit default_device_exit(struct net *net) 5891static void __net_exit default_device_exit(struct net *net)
5568{ 5892{
5569 struct net_device *dev; 5893 struct net_device *dev, *aux;
5570 /* 5894 /*
5571 * Push all migratable of the network devices back to the 5895 * Push all migratable network devices back to the
5572 * initial network namespace 5896 * initial network namespace
5573 */ 5897 */
5574 rtnl_lock(); 5898 rtnl_lock();
5575restart: 5899 for_each_netdev_safe(net, dev, aux) {
5576 for_each_netdev(net, dev) {
5577 int err; 5900 int err;
5578 char fb_name[IFNAMSIZ]; 5901 char fb_name[IFNAMSIZ];
5579 5902
@@ -5581,11 +5904,9 @@ restart:
5581 if (dev->features & NETIF_F_NETNS_LOCAL) 5904 if (dev->features & NETIF_F_NETNS_LOCAL)
5582 continue; 5905 continue;
5583 5906
5584 /* Delete virtual devices */ 5907 /* Leave virtual devices for the generic cleanup */
5585 if (dev->rtnl_link_ops && dev->rtnl_link_ops->dellink) { 5908 if (dev->rtnl_link_ops)
5586 dev->rtnl_link_ops->dellink(dev); 5909 continue;
5587 goto restart;
5588 }
5589 5910
5590 /* Push remaing network devices to init_net */ 5911 /* Push remaing network devices to init_net */
5591 snprintf(fb_name, IFNAMSIZ, "dev%d", dev->ifindex); 5912 snprintf(fb_name, IFNAMSIZ, "dev%d", dev->ifindex);
@@ -5595,13 +5916,37 @@ restart:
5595 __func__, dev->name, err); 5916 __func__, dev->name, err);
5596 BUG(); 5917 BUG();
5597 } 5918 }
5598 goto restart;
5599 } 5919 }
5600 rtnl_unlock(); 5920 rtnl_unlock();
5601} 5921}
5602 5922
5923static void __net_exit default_device_exit_batch(struct list_head *net_list)
5924{
5925 /* At exit all network devices most be removed from a network
5926 * namespace. Do this in the reverse order of registeration.
5927 * Do this across as many network namespaces as possible to
5928 * improve batching efficiency.
5929 */
5930 struct net_device *dev;
5931 struct net *net;
5932 LIST_HEAD(dev_kill_list);
5933
5934 rtnl_lock();
5935 list_for_each_entry(net, net_list, exit_list) {
5936 for_each_netdev_reverse(net, dev) {
5937 if (dev->rtnl_link_ops)
5938 dev->rtnl_link_ops->dellink(dev, &dev_kill_list);
5939 else
5940 unregister_netdevice_queue(dev, &dev_kill_list);
5941 }
5942 }
5943 unregister_netdevice_many(&dev_kill_list);
5944 rtnl_unlock();
5945}
5946
5603static struct pernet_operations __net_initdata default_device_ops = { 5947static struct pernet_operations __net_initdata default_device_ops = {
5604 .exit = default_device_exit, 5948 .exit = default_device_exit,
5949 .exit_batch = default_device_exit_batch,
5605}; 5950};
5606 5951
5607/* 5952/*
diff --git a/net/core/dev_mcast.c b/net/core/dev_mcast.c
index 9e2fa39f22a3..3dc295beb483 100644
--- a/net/core/dev_mcast.c
+++ b/net/core/dev_mcast.c
@@ -96,7 +96,10 @@ int dev_mc_add(struct net_device *dev, void *addr, int alen, int glbl)
96 int err; 96 int err;
97 97
98 netif_addr_lock_bh(dev); 98 netif_addr_lock_bh(dev);
99 err = __dev_addr_add(&dev->mc_list, &dev->mc_count, addr, alen, glbl); 99 if (alen != dev->addr_len)
100 err = -EINVAL;
101 else
102 err = __dev_addr_add(&dev->mc_list, &dev->mc_count, addr, alen, glbl);
100 if (!err) 103 if (!err)
101 __dev_set_rx_mode(dev); 104 __dev_set_rx_mode(dev);
102 netif_addr_unlock_bh(dev); 105 netif_addr_unlock_bh(dev);
diff --git a/net/core/drop_monitor.c b/net/core/drop_monitor.c
index 0a113f26bc9f..cf208d8042b1 100644
--- a/net/core/drop_monitor.c
+++ b/net/core/drop_monitor.c
@@ -21,6 +21,7 @@
21#include <linux/percpu.h> 21#include <linux/percpu.h>
22#include <linux/timer.h> 22#include <linux/timer.h>
23#include <linux/bitops.h> 23#include <linux/bitops.h>
24#include <linux/slab.h>
24#include <net/genetlink.h> 25#include <net/genetlink.h>
25#include <net/netevent.h> 26#include <net/netevent.h>
26 27
@@ -41,7 +42,7 @@ static void send_dm_alert(struct work_struct *unused);
41 * netlink alerts 42 * netlink alerts
42 */ 43 */
43static int trace_state = TRACE_OFF; 44static int trace_state = TRACE_OFF;
44static spinlock_t trace_state_lock = SPIN_LOCK_UNLOCKED; 45static DEFINE_SPINLOCK(trace_state_lock);
45 46
46struct per_cpu_dm_data { 47struct per_cpu_dm_data {
47 struct work_struct dm_alert_work; 48 struct work_struct dm_alert_work;
@@ -296,7 +297,6 @@ static int dropmon_net_event(struct notifier_block *ev_block,
296 297
297 new_stat->dev = dev; 298 new_stat->dev = dev;
298 new_stat->last_rx = jiffies; 299 new_stat->last_rx = jiffies;
299 INIT_RCU_HEAD(&new_stat->rcu);
300 spin_lock(&trace_state_lock); 300 spin_lock(&trace_state_lock);
301 list_add_rcu(&new_stat->list, &hw_stats_list); 301 list_add_rcu(&new_stat->list, &hw_stats_list);
302 spin_unlock(&trace_state_lock); 302 spin_unlock(&trace_state_lock);
diff --git a/net/core/dst.c b/net/core/dst.c
index 57bc4d5b8d08..f307bc18f6a0 100644
--- a/net/core/dst.c
+++ b/net/core/dst.c
@@ -12,11 +12,13 @@
12#include <linux/workqueue.h> 12#include <linux/workqueue.h>
13#include <linux/mm.h> 13#include <linux/mm.h>
14#include <linux/module.h> 14#include <linux/module.h>
15#include <linux/slab.h>
15#include <linux/netdevice.h> 16#include <linux/netdevice.h>
16#include <linux/skbuff.h> 17#include <linux/skbuff.h>
17#include <linux/string.h> 18#include <linux/string.h>
18#include <linux/types.h> 19#include <linux/types.h>
19#include <net/net_namespace.h> 20#include <net/net_namespace.h>
21#include <linux/sched.h>
20 22
21#include <net/dst.h> 23#include <net/dst.h>
22 24
@@ -79,6 +81,7 @@ loop:
79 while ((dst = next) != NULL) { 81 while ((dst = next) != NULL) {
80 next = dst->next; 82 next = dst->next;
81 prefetch(&next->next); 83 prefetch(&next->next);
84 cond_resched();
82 if (likely(atomic_read(&dst->__refcnt))) { 85 if (likely(atomic_read(&dst->__refcnt))) {
83 last->next = dst; 86 last->next = dst;
84 last = dst; 87 last = dst;
diff --git a/net/core/ethtool.c b/net/core/ethtool.c
index 4c12ddb5f5ee..9d55c57f318a 100644
--- a/net/core/ethtool.c
+++ b/net/core/ethtool.c
@@ -17,6 +17,8 @@
17#include <linux/errno.h> 17#include <linux/errno.h>
18#include <linux/ethtool.h> 18#include <linux/ethtool.h>
19#include <linux/netdevice.h> 19#include <linux/netdevice.h>
20#include <linux/bitops.h>
21#include <linux/slab.h>
20#include <asm/uaccess.h> 22#include <asm/uaccess.h>
21 23
22/* 24/*
@@ -120,7 +122,7 @@ int ethtool_op_set_ufo(struct net_device *dev, u32 data)
120 * NETIF_F_xxx values in include/linux/netdevice.h 122 * NETIF_F_xxx values in include/linux/netdevice.h
121 */ 123 */
122static const u32 flags_dup_features = 124static const u32 flags_dup_features =
123 ETH_FLAG_LRO; 125 (ETH_FLAG_LRO | ETH_FLAG_NTUPLE);
124 126
125u32 ethtool_op_get_flags(struct net_device *dev) 127u32 ethtool_op_get_flags(struct net_device *dev)
126{ 128{
@@ -134,19 +136,44 @@ u32 ethtool_op_get_flags(struct net_device *dev)
134 136
135int ethtool_op_set_flags(struct net_device *dev, u32 data) 137int ethtool_op_set_flags(struct net_device *dev, u32 data)
136{ 138{
139 const struct ethtool_ops *ops = dev->ethtool_ops;
140 unsigned long features = dev->features;
141
137 if (data & ETH_FLAG_LRO) 142 if (data & ETH_FLAG_LRO)
138 dev->features |= NETIF_F_LRO; 143 features |= NETIF_F_LRO;
139 else 144 else
140 dev->features &= ~NETIF_F_LRO; 145 features &= ~NETIF_F_LRO;
146
147 if (data & ETH_FLAG_NTUPLE) {
148 if (!ops->set_rx_ntuple)
149 return -EOPNOTSUPP;
150 features |= NETIF_F_NTUPLE;
151 } else {
152 /* safe to clear regardless */
153 features &= ~NETIF_F_NTUPLE;
154 }
141 155
156 dev->features = features;
142 return 0; 157 return 0;
143} 158}
144 159
160void ethtool_ntuple_flush(struct net_device *dev)
161{
162 struct ethtool_rx_ntuple_flow_spec_container *fsc, *f;
163
164 list_for_each_entry_safe(fsc, f, &dev->ethtool_ntuple_list.list, list) {
165 list_del(&fsc->list);
166 kfree(fsc);
167 }
168 dev->ethtool_ntuple_list.count = 0;
169}
170EXPORT_SYMBOL(ethtool_ntuple_flush);
171
145/* Handlers for each ethtool command */ 172/* Handlers for each ethtool command */
146 173
147static int ethtool_get_settings(struct net_device *dev, void __user *useraddr) 174static int ethtool_get_settings(struct net_device *dev, void __user *useraddr)
148{ 175{
149 struct ethtool_cmd cmd = { ETHTOOL_GSET }; 176 struct ethtool_cmd cmd = { .cmd = ETHTOOL_GSET };
150 int err; 177 int err;
151 178
152 if (!dev->ethtool_ops->get_settings) 179 if (!dev->ethtool_ops->get_settings)
@@ -174,7 +201,7 @@ static int ethtool_set_settings(struct net_device *dev, void __user *useraddr)
174 return dev->ethtool_ops->set_settings(dev, &cmd); 201 return dev->ethtool_ops->set_settings(dev, &cmd);
175} 202}
176 203
177static int ethtool_get_drvinfo(struct net_device *dev, void __user *useraddr) 204static noinline_for_stack int ethtool_get_drvinfo(struct net_device *dev, void __user *useraddr)
178{ 205{
179 struct ethtool_drvinfo info; 206 struct ethtool_drvinfo info;
180 const struct ethtool_ops *ops = dev->ethtool_ops; 207 const struct ethtool_ops *ops = dev->ethtool_ops;
@@ -186,6 +213,10 @@ static int ethtool_get_drvinfo(struct net_device *dev, void __user *useraddr)
186 info.cmd = ETHTOOL_GDRVINFO; 213 info.cmd = ETHTOOL_GDRVINFO;
187 ops->get_drvinfo(dev, &info); 214 ops->get_drvinfo(dev, &info);
188 215
216 /*
217 * this method of obtaining string set info is deprecated;
218 * Use ETHTOOL_GSSET_INFO instead.
219 */
189 if (ops->get_sset_count) { 220 if (ops->get_sset_count) {
190 int rc; 221 int rc;
191 222
@@ -198,13 +229,6 @@ static int ethtool_get_drvinfo(struct net_device *dev, void __user *useraddr)
198 rc = ops->get_sset_count(dev, ETH_SS_PRIV_FLAGS); 229 rc = ops->get_sset_count(dev, ETH_SS_PRIV_FLAGS);
199 if (rc >= 0) 230 if (rc >= 0)
200 info.n_priv_flags = rc; 231 info.n_priv_flags = rc;
201 } else {
202 /* code path for obsolete hooks */
203
204 if (ops->self_test_count)
205 info.testinfo_len = ops->self_test_count(dev);
206 if (ops->get_stats_count)
207 info.n_stats = ops->get_stats_count(dev);
208 } 232 }
209 if (ops->get_regs_len) 233 if (ops->get_regs_len)
210 info.regdump_len = ops->get_regs_len(dev); 234 info.regdump_len = ops->get_regs_len(dev);
@@ -216,7 +240,67 @@ static int ethtool_get_drvinfo(struct net_device *dev, void __user *useraddr)
216 return 0; 240 return 0;
217} 241}
218 242
219static int ethtool_set_rxnfc(struct net_device *dev, void __user *useraddr) 243static noinline_for_stack int ethtool_get_sset_info(struct net_device *dev,
244 void __user *useraddr)
245{
246 struct ethtool_sset_info info;
247 const struct ethtool_ops *ops = dev->ethtool_ops;
248 u64 sset_mask;
249 int i, idx = 0, n_bits = 0, ret, rc;
250 u32 *info_buf = NULL;
251
252 if (!ops->get_sset_count)
253 return -EOPNOTSUPP;
254
255 if (copy_from_user(&info, useraddr, sizeof(info)))
256 return -EFAULT;
257
258 /* store copy of mask, because we zero struct later on */
259 sset_mask = info.sset_mask;
260 if (!sset_mask)
261 return 0;
262
263 /* calculate size of return buffer */
264 n_bits = hweight64(sset_mask);
265
266 memset(&info, 0, sizeof(info));
267 info.cmd = ETHTOOL_GSSET_INFO;
268
269 info_buf = kzalloc(n_bits * sizeof(u32), GFP_USER);
270 if (!info_buf)
271 return -ENOMEM;
272
273 /*
274 * fill return buffer based on input bitmask and successful
275 * get_sset_count return
276 */
277 for (i = 0; i < 64; i++) {
278 if (!(sset_mask & (1ULL << i)))
279 continue;
280
281 rc = ops->get_sset_count(dev, i);
282 if (rc >= 0) {
283 info.sset_mask |= (1ULL << i);
284 info_buf[idx++] = rc;
285 }
286 }
287
288 ret = -EFAULT;
289 if (copy_to_user(useraddr, &info, sizeof(info)))
290 goto out;
291
292 useraddr += offsetof(struct ethtool_sset_info, data);
293 if (copy_to_user(useraddr, info_buf, idx * sizeof(u32)))
294 goto out;
295
296 ret = 0;
297
298out:
299 kfree(info_buf);
300 return ret;
301}
302
303static noinline_for_stack int ethtool_set_rxnfc(struct net_device *dev, void __user *useraddr)
220{ 304{
221 struct ethtool_rxnfc cmd; 305 struct ethtool_rxnfc cmd;
222 306
@@ -229,7 +313,7 @@ static int ethtool_set_rxnfc(struct net_device *dev, void __user *useraddr)
229 return dev->ethtool_ops->set_rxnfc(dev, &cmd); 313 return dev->ethtool_ops->set_rxnfc(dev, &cmd);
230} 314}
231 315
232static int ethtool_get_rxnfc(struct net_device *dev, void __user *useraddr) 316static noinline_for_stack int ethtool_get_rxnfc(struct net_device *dev, void __user *useraddr)
233{ 317{
234 struct ethtool_rxnfc info; 318 struct ethtool_rxnfc info;
235 const struct ethtool_ops *ops = dev->ethtool_ops; 319 const struct ethtool_ops *ops = dev->ethtool_ops;
@@ -273,6 +357,312 @@ err_out:
273 return ret; 357 return ret;
274} 358}
275 359
360static void __rx_ntuple_filter_add(struct ethtool_rx_ntuple_list *list,
361 struct ethtool_rx_ntuple_flow_spec *spec,
362 struct ethtool_rx_ntuple_flow_spec_container *fsc)
363{
364
365 /* don't add filters forever */
366 if (list->count >= ETHTOOL_MAX_NTUPLE_LIST_ENTRY) {
367 /* free the container */
368 kfree(fsc);
369 return;
370 }
371
372 /* Copy the whole filter over */
373 fsc->fs.flow_type = spec->flow_type;
374 memcpy(&fsc->fs.h_u, &spec->h_u, sizeof(spec->h_u));
375 memcpy(&fsc->fs.m_u, &spec->m_u, sizeof(spec->m_u));
376
377 fsc->fs.vlan_tag = spec->vlan_tag;
378 fsc->fs.vlan_tag_mask = spec->vlan_tag_mask;
379 fsc->fs.data = spec->data;
380 fsc->fs.data_mask = spec->data_mask;
381 fsc->fs.action = spec->action;
382
383 /* add to the list */
384 list_add_tail_rcu(&fsc->list, &list->list);
385 list->count++;
386}
387
388static noinline_for_stack int ethtool_set_rx_ntuple(struct net_device *dev, void __user *useraddr)
389{
390 struct ethtool_rx_ntuple cmd;
391 const struct ethtool_ops *ops = dev->ethtool_ops;
392 struct ethtool_rx_ntuple_flow_spec_container *fsc = NULL;
393 int ret;
394
395 if (!(dev->features & NETIF_F_NTUPLE))
396 return -EINVAL;
397
398 if (copy_from_user(&cmd, useraddr, sizeof(cmd)))
399 return -EFAULT;
400
401 /*
402 * Cache filter in dev struct for GET operation only if
403 * the underlying driver doesn't have its own GET operation, and
404 * only if the filter was added successfully. First make sure we
405 * can allocate the filter, then continue if successful.
406 */
407 if (!ops->get_rx_ntuple) {
408 fsc = kmalloc(sizeof(*fsc), GFP_ATOMIC);
409 if (!fsc)
410 return -ENOMEM;
411 }
412
413 ret = ops->set_rx_ntuple(dev, &cmd);
414 if (ret) {
415 kfree(fsc);
416 return ret;
417 }
418
419 if (!ops->get_rx_ntuple)
420 __rx_ntuple_filter_add(&dev->ethtool_ntuple_list, &cmd.fs, fsc);
421
422 return ret;
423}
424
425static int ethtool_get_rx_ntuple(struct net_device *dev, void __user *useraddr)
426{
427 struct ethtool_gstrings gstrings;
428 const struct ethtool_ops *ops = dev->ethtool_ops;
429 struct ethtool_rx_ntuple_flow_spec_container *fsc;
430 u8 *data;
431 char *p;
432 int ret, i, num_strings = 0;
433
434 if (!ops->get_sset_count)
435 return -EOPNOTSUPP;
436
437 if (copy_from_user(&gstrings, useraddr, sizeof(gstrings)))
438 return -EFAULT;
439
440 ret = ops->get_sset_count(dev, gstrings.string_set);
441 if (ret < 0)
442 return ret;
443
444 gstrings.len = ret;
445
446 data = kmalloc(gstrings.len * ETH_GSTRING_LEN, GFP_USER);
447 if (!data)
448 return -ENOMEM;
449
450 if (ops->get_rx_ntuple) {
451 /* driver-specific filter grab */
452 ret = ops->get_rx_ntuple(dev, gstrings.string_set, data);
453 goto copy;
454 }
455
456 /* default ethtool filter grab */
457 i = 0;
458 p = (char *)data;
459 list_for_each_entry(fsc, &dev->ethtool_ntuple_list.list, list) {
460 sprintf(p, "Filter %d:\n", i);
461 p += ETH_GSTRING_LEN;
462 num_strings++;
463
464 switch (fsc->fs.flow_type) {
465 case TCP_V4_FLOW:
466 sprintf(p, "\tFlow Type: TCP\n");
467 p += ETH_GSTRING_LEN;
468 num_strings++;
469 break;
470 case UDP_V4_FLOW:
471 sprintf(p, "\tFlow Type: UDP\n");
472 p += ETH_GSTRING_LEN;
473 num_strings++;
474 break;
475 case SCTP_V4_FLOW:
476 sprintf(p, "\tFlow Type: SCTP\n");
477 p += ETH_GSTRING_LEN;
478 num_strings++;
479 break;
480 case AH_ESP_V4_FLOW:
481 sprintf(p, "\tFlow Type: AH ESP\n");
482 p += ETH_GSTRING_LEN;
483 num_strings++;
484 break;
485 case ESP_V4_FLOW:
486 sprintf(p, "\tFlow Type: ESP\n");
487 p += ETH_GSTRING_LEN;
488 num_strings++;
489 break;
490 case IP_USER_FLOW:
491 sprintf(p, "\tFlow Type: Raw IP\n");
492 p += ETH_GSTRING_LEN;
493 num_strings++;
494 break;
495 case IPV4_FLOW:
496 sprintf(p, "\tFlow Type: IPv4\n");
497 p += ETH_GSTRING_LEN;
498 num_strings++;
499 break;
500 default:
501 sprintf(p, "\tFlow Type: Unknown\n");
502 p += ETH_GSTRING_LEN;
503 num_strings++;
504 goto unknown_filter;
505 };
506
507 /* now the rest of the filters */
508 switch (fsc->fs.flow_type) {
509 case TCP_V4_FLOW:
510 case UDP_V4_FLOW:
511 case SCTP_V4_FLOW:
512 sprintf(p, "\tSrc IP addr: 0x%x\n",
513 fsc->fs.h_u.tcp_ip4_spec.ip4src);
514 p += ETH_GSTRING_LEN;
515 num_strings++;
516 sprintf(p, "\tSrc IP mask: 0x%x\n",
517 fsc->fs.m_u.tcp_ip4_spec.ip4src);
518 p += ETH_GSTRING_LEN;
519 num_strings++;
520 sprintf(p, "\tDest IP addr: 0x%x\n",
521 fsc->fs.h_u.tcp_ip4_spec.ip4dst);
522 p += ETH_GSTRING_LEN;
523 num_strings++;
524 sprintf(p, "\tDest IP mask: 0x%x\n",
525 fsc->fs.m_u.tcp_ip4_spec.ip4dst);
526 p += ETH_GSTRING_LEN;
527 num_strings++;
528 sprintf(p, "\tSrc Port: %d, mask: 0x%x\n",
529 fsc->fs.h_u.tcp_ip4_spec.psrc,
530 fsc->fs.m_u.tcp_ip4_spec.psrc);
531 p += ETH_GSTRING_LEN;
532 num_strings++;
533 sprintf(p, "\tDest Port: %d, mask: 0x%x\n",
534 fsc->fs.h_u.tcp_ip4_spec.pdst,
535 fsc->fs.m_u.tcp_ip4_spec.pdst);
536 p += ETH_GSTRING_LEN;
537 num_strings++;
538 sprintf(p, "\tTOS: %d, mask: 0x%x\n",
539 fsc->fs.h_u.tcp_ip4_spec.tos,
540 fsc->fs.m_u.tcp_ip4_spec.tos);
541 p += ETH_GSTRING_LEN;
542 num_strings++;
543 break;
544 case AH_ESP_V4_FLOW:
545 case ESP_V4_FLOW:
546 sprintf(p, "\tSrc IP addr: 0x%x\n",
547 fsc->fs.h_u.ah_ip4_spec.ip4src);
548 p += ETH_GSTRING_LEN;
549 num_strings++;
550 sprintf(p, "\tSrc IP mask: 0x%x\n",
551 fsc->fs.m_u.ah_ip4_spec.ip4src);
552 p += ETH_GSTRING_LEN;
553 num_strings++;
554 sprintf(p, "\tDest IP addr: 0x%x\n",
555 fsc->fs.h_u.ah_ip4_spec.ip4dst);
556 p += ETH_GSTRING_LEN;
557 num_strings++;
558 sprintf(p, "\tDest IP mask: 0x%x\n",
559 fsc->fs.m_u.ah_ip4_spec.ip4dst);
560 p += ETH_GSTRING_LEN;
561 num_strings++;
562 sprintf(p, "\tSPI: %d, mask: 0x%x\n",
563 fsc->fs.h_u.ah_ip4_spec.spi,
564 fsc->fs.m_u.ah_ip4_spec.spi);
565 p += ETH_GSTRING_LEN;
566 num_strings++;
567 sprintf(p, "\tTOS: %d, mask: 0x%x\n",
568 fsc->fs.h_u.ah_ip4_spec.tos,
569 fsc->fs.m_u.ah_ip4_spec.tos);
570 p += ETH_GSTRING_LEN;
571 num_strings++;
572 break;
573 case IP_USER_FLOW:
574 sprintf(p, "\tSrc IP addr: 0x%x\n",
575 fsc->fs.h_u.raw_ip4_spec.ip4src);
576 p += ETH_GSTRING_LEN;
577 num_strings++;
578 sprintf(p, "\tSrc IP mask: 0x%x\n",
579 fsc->fs.m_u.raw_ip4_spec.ip4src);
580 p += ETH_GSTRING_LEN;
581 num_strings++;
582 sprintf(p, "\tDest IP addr: 0x%x\n",
583 fsc->fs.h_u.raw_ip4_spec.ip4dst);
584 p += ETH_GSTRING_LEN;
585 num_strings++;
586 sprintf(p, "\tDest IP mask: 0x%x\n",
587 fsc->fs.m_u.raw_ip4_spec.ip4dst);
588 p += ETH_GSTRING_LEN;
589 num_strings++;
590 break;
591 case IPV4_FLOW:
592 sprintf(p, "\tSrc IP addr: 0x%x\n",
593 fsc->fs.h_u.usr_ip4_spec.ip4src);
594 p += ETH_GSTRING_LEN;
595 num_strings++;
596 sprintf(p, "\tSrc IP mask: 0x%x\n",
597 fsc->fs.m_u.usr_ip4_spec.ip4src);
598 p += ETH_GSTRING_LEN;
599 num_strings++;
600 sprintf(p, "\tDest IP addr: 0x%x\n",
601 fsc->fs.h_u.usr_ip4_spec.ip4dst);
602 p += ETH_GSTRING_LEN;
603 num_strings++;
604 sprintf(p, "\tDest IP mask: 0x%x\n",
605 fsc->fs.m_u.usr_ip4_spec.ip4dst);
606 p += ETH_GSTRING_LEN;
607 num_strings++;
608 sprintf(p, "\tL4 bytes: 0x%x, mask: 0x%x\n",
609 fsc->fs.h_u.usr_ip4_spec.l4_4_bytes,
610 fsc->fs.m_u.usr_ip4_spec.l4_4_bytes);
611 p += ETH_GSTRING_LEN;
612 num_strings++;
613 sprintf(p, "\tTOS: %d, mask: 0x%x\n",
614 fsc->fs.h_u.usr_ip4_spec.tos,
615 fsc->fs.m_u.usr_ip4_spec.tos);
616 p += ETH_GSTRING_LEN;
617 num_strings++;
618 sprintf(p, "\tIP Version: %d, mask: 0x%x\n",
619 fsc->fs.h_u.usr_ip4_spec.ip_ver,
620 fsc->fs.m_u.usr_ip4_spec.ip_ver);
621 p += ETH_GSTRING_LEN;
622 num_strings++;
623 sprintf(p, "\tProtocol: %d, mask: 0x%x\n",
624 fsc->fs.h_u.usr_ip4_spec.proto,
625 fsc->fs.m_u.usr_ip4_spec.proto);
626 p += ETH_GSTRING_LEN;
627 num_strings++;
628 break;
629 };
630 sprintf(p, "\tVLAN: %d, mask: 0x%x\n",
631 fsc->fs.vlan_tag, fsc->fs.vlan_tag_mask);
632 p += ETH_GSTRING_LEN;
633 num_strings++;
634 sprintf(p, "\tUser-defined: 0x%Lx\n", fsc->fs.data);
635 p += ETH_GSTRING_LEN;
636 num_strings++;
637 sprintf(p, "\tUser-defined mask: 0x%Lx\n", fsc->fs.data_mask);
638 p += ETH_GSTRING_LEN;
639 num_strings++;
640 if (fsc->fs.action == ETHTOOL_RXNTUPLE_ACTION_DROP)
641 sprintf(p, "\tAction: Drop\n");
642 else
643 sprintf(p, "\tAction: Direct to queue %d\n",
644 fsc->fs.action);
645 p += ETH_GSTRING_LEN;
646 num_strings++;
647unknown_filter:
648 i++;
649 }
650copy:
651 /* indicate to userspace how many strings we actually have */
652 gstrings.len = num_strings;
653 ret = -EFAULT;
654 if (copy_to_user(useraddr, &gstrings, sizeof(gstrings)))
655 goto out;
656 useraddr += sizeof(gstrings);
657 if (copy_to_user(useraddr, data, gstrings.len * ETH_GSTRING_LEN))
658 goto out;
659 ret = 0;
660
661out:
662 kfree(data);
663 return ret;
664}
665
276static int ethtool_get_regs(struct net_device *dev, char __user *useraddr) 666static int ethtool_get_regs(struct net_device *dev, char __user *useraddr)
277{ 667{
278 struct ethtool_regs regs; 668 struct ethtool_regs regs;
@@ -309,9 +699,29 @@ static int ethtool_get_regs(struct net_device *dev, char __user *useraddr)
309 return ret; 699 return ret;
310} 700}
311 701
702static int ethtool_reset(struct net_device *dev, char __user *useraddr)
703{
704 struct ethtool_value reset;
705 int ret;
706
707 if (!dev->ethtool_ops->reset)
708 return -EOPNOTSUPP;
709
710 if (copy_from_user(&reset, useraddr, sizeof(reset)))
711 return -EFAULT;
712
713 ret = dev->ethtool_ops->reset(dev, &reset.data);
714 if (ret)
715 return ret;
716
717 if (copy_to_user(useraddr, &reset, sizeof(reset)))
718 return -EFAULT;
719 return 0;
720}
721
312static int ethtool_get_wol(struct net_device *dev, char __user *useraddr) 722static int ethtool_get_wol(struct net_device *dev, char __user *useraddr)
313{ 723{
314 struct ethtool_wolinfo wol = { ETHTOOL_GWOL }; 724 struct ethtool_wolinfo wol = { .cmd = ETHTOOL_GWOL };
315 725
316 if (!dev->ethtool_ops->get_wol) 726 if (!dev->ethtool_ops->get_wol)
317 return -EOPNOTSUPP; 727 return -EOPNOTSUPP;
@@ -443,9 +853,9 @@ static int ethtool_set_eeprom(struct net_device *dev, void __user *useraddr)
443 return ret; 853 return ret;
444} 854}
445 855
446static int ethtool_get_coalesce(struct net_device *dev, void __user *useraddr) 856static noinline_for_stack int ethtool_get_coalesce(struct net_device *dev, void __user *useraddr)
447{ 857{
448 struct ethtool_coalesce coalesce = { ETHTOOL_GCOALESCE }; 858 struct ethtool_coalesce coalesce = { .cmd = ETHTOOL_GCOALESCE };
449 859
450 if (!dev->ethtool_ops->get_coalesce) 860 if (!dev->ethtool_ops->get_coalesce)
451 return -EOPNOTSUPP; 861 return -EOPNOTSUPP;
@@ -457,7 +867,7 @@ static int ethtool_get_coalesce(struct net_device *dev, void __user *useraddr)
457 return 0; 867 return 0;
458} 868}
459 869
460static int ethtool_set_coalesce(struct net_device *dev, void __user *useraddr) 870static noinline_for_stack int ethtool_set_coalesce(struct net_device *dev, void __user *useraddr)
461{ 871{
462 struct ethtool_coalesce coalesce; 872 struct ethtool_coalesce coalesce;
463 873
@@ -472,7 +882,7 @@ static int ethtool_set_coalesce(struct net_device *dev, void __user *useraddr)
472 882
473static int ethtool_get_ringparam(struct net_device *dev, void __user *useraddr) 883static int ethtool_get_ringparam(struct net_device *dev, void __user *useraddr)
474{ 884{
475 struct ethtool_ringparam ringparam = { ETHTOOL_GRINGPARAM }; 885 struct ethtool_ringparam ringparam = { .cmd = ETHTOOL_GRINGPARAM };
476 886
477 if (!dev->ethtool_ops->get_ringparam) 887 if (!dev->ethtool_ops->get_ringparam)
478 return -EOPNOTSUPP; 888 return -EOPNOTSUPP;
@@ -684,16 +1094,10 @@ static int ethtool_self_test(struct net_device *dev, char __user *useraddr)
684 u64 *data; 1094 u64 *data;
685 int ret, test_len; 1095 int ret, test_len;
686 1096
687 if (!ops->self_test) 1097 if (!ops->self_test || !ops->get_sset_count)
688 return -EOPNOTSUPP;
689 if (!ops->get_sset_count && !ops->self_test_count)
690 return -EOPNOTSUPP; 1098 return -EOPNOTSUPP;
691 1099
692 if (ops->get_sset_count) 1100 test_len = ops->get_sset_count(dev, ETH_SS_TEST);
693 test_len = ops->get_sset_count(dev, ETH_SS_TEST);
694 else
695 /* code path for obsolete hook */
696 test_len = ops->self_test_count(dev);
697 if (test_len < 0) 1101 if (test_len < 0)
698 return test_len; 1102 return test_len;
699 WARN_ON(test_len == 0); 1103 WARN_ON(test_len == 0);
@@ -728,36 +1132,17 @@ static int ethtool_get_strings(struct net_device *dev, void __user *useraddr)
728 u8 *data; 1132 u8 *data;
729 int ret; 1133 int ret;
730 1134
731 if (!ops->get_strings) 1135 if (!ops->get_strings || !ops->get_sset_count)
732 return -EOPNOTSUPP; 1136 return -EOPNOTSUPP;
733 1137
734 if (copy_from_user(&gstrings, useraddr, sizeof(gstrings))) 1138 if (copy_from_user(&gstrings, useraddr, sizeof(gstrings)))
735 return -EFAULT; 1139 return -EFAULT;
736 1140
737 if (ops->get_sset_count) { 1141 ret = ops->get_sset_count(dev, gstrings.string_set);
738 ret = ops->get_sset_count(dev, gstrings.string_set); 1142 if (ret < 0)
739 if (ret < 0) 1143 return ret;
740 return ret;
741 1144
742 gstrings.len = ret; 1145 gstrings.len = ret;
743 } else {
744 /* code path for obsolete hooks */
745
746 switch (gstrings.string_set) {
747 case ETH_SS_TEST:
748 if (!ops->self_test_count)
749 return -EOPNOTSUPP;
750 gstrings.len = ops->self_test_count(dev);
751 break;
752 case ETH_SS_STATS:
753 if (!ops->get_stats_count)
754 return -EOPNOTSUPP;
755 gstrings.len = ops->get_stats_count(dev);
756 break;
757 default:
758 return -EINVAL;
759 }
760 }
761 1146
762 data = kmalloc(gstrings.len * ETH_GSTRING_LEN, GFP_USER); 1147 data = kmalloc(gstrings.len * ETH_GSTRING_LEN, GFP_USER);
763 if (!data) 1148 if (!data)
@@ -798,16 +1183,10 @@ static int ethtool_get_stats(struct net_device *dev, void __user *useraddr)
798 u64 *data; 1183 u64 *data;
799 int ret, n_stats; 1184 int ret, n_stats;
800 1185
801 if (!ops->get_ethtool_stats) 1186 if (!ops->get_ethtool_stats || !ops->get_sset_count)
802 return -EOPNOTSUPP;
803 if (!ops->get_sset_count && !ops->get_stats_count)
804 return -EOPNOTSUPP; 1187 return -EOPNOTSUPP;
805 1188
806 if (ops->get_sset_count) 1189 n_stats = ops->get_sset_count(dev, ETH_SS_STATS);
807 n_stats = ops->get_sset_count(dev, ETH_SS_STATS);
808 else
809 /* code path for obsolete hook */
810 n_stats = ops->get_stats_count(dev);
811 if (n_stats < 0) 1190 if (n_stats < 0)
812 return n_stats; 1191 return n_stats;
813 WARN_ON(n_stats == 0); 1192 WARN_ON(n_stats == 0);
@@ -857,7 +1236,7 @@ static int ethtool_get_perm_addr(struct net_device *dev, void __user *useraddr)
857static int ethtool_get_value(struct net_device *dev, char __user *useraddr, 1236static int ethtool_get_value(struct net_device *dev, char __user *useraddr,
858 u32 cmd, u32 (*actor)(struct net_device *)) 1237 u32 cmd, u32 (*actor)(struct net_device *))
859{ 1238{
860 struct ethtool_value edata = { cmd }; 1239 struct ethtool_value edata = { .cmd = cmd };
861 1240
862 if (!actor) 1241 if (!actor)
863 return -EOPNOTSUPP; 1242 return -EOPNOTSUPP;
@@ -898,7 +1277,7 @@ static int ethtool_set_value(struct net_device *dev, char __user *useraddr,
898 return actor(dev, edata.data); 1277 return actor(dev, edata.data);
899} 1278}
900 1279
901static int ethtool_flash_device(struct net_device *dev, char __user *useraddr) 1280static noinline_for_stack int ethtool_flash_device(struct net_device *dev, char __user *useraddr)
902{ 1281{
903 struct ethtool_flash efl; 1282 struct ethtool_flash efl;
904 1283
@@ -945,6 +1324,7 @@ int dev_ethtool(struct net *net, struct ifreq *ifr)
945 case ETHTOOL_GPERMADDR: 1324 case ETHTOOL_GPERMADDR:
946 case ETHTOOL_GUFO: 1325 case ETHTOOL_GUFO:
947 case ETHTOOL_GGSO: 1326 case ETHTOOL_GGSO:
1327 case ETHTOOL_GGRO:
948 case ETHTOOL_GFLAGS: 1328 case ETHTOOL_GFLAGS:
949 case ETHTOOL_GPFLAGS: 1329 case ETHTOOL_GPFLAGS:
950 case ETHTOOL_GRXFH: 1330 case ETHTOOL_GRXFH:
@@ -1127,6 +1507,18 @@ int dev_ethtool(struct net *net, struct ifreq *ifr)
1127 case ETHTOOL_FLASHDEV: 1507 case ETHTOOL_FLASHDEV:
1128 rc = ethtool_flash_device(dev, useraddr); 1508 rc = ethtool_flash_device(dev, useraddr);
1129 break; 1509 break;
1510 case ETHTOOL_RESET:
1511 rc = ethtool_reset(dev, useraddr);
1512 break;
1513 case ETHTOOL_SRXNTUPLE:
1514 rc = ethtool_set_rx_ntuple(dev, useraddr);
1515 break;
1516 case ETHTOOL_GRXNTUPLE:
1517 rc = ethtool_get_rx_ntuple(dev, useraddr);
1518 break;
1519 case ETHTOOL_GSSET_INFO:
1520 rc = ethtool_get_sset_info(dev, useraddr);
1521 break;
1130 default: 1522 default:
1131 rc = -EOPNOTSUPP; 1523 rc = -EOPNOTSUPP;
1132 } 1524 }
diff --git a/net/core/fib_rules.c b/net/core/fib_rules.c
index bd309384f8b8..d2c3e7dc2e5f 100644
--- a/net/core/fib_rules.c
+++ b/net/core/fib_rules.c
@@ -10,6 +10,7 @@
10 10
11#include <linux/types.h> 11#include <linux/types.h>
12#include <linux/kernel.h> 12#include <linux/kernel.h>
13#include <linux/slab.h>
13#include <linux/list.h> 14#include <linux/list.h>
14#include <net/net_namespace.h> 15#include <net/net_namespace.h>
15#include <net/sock.h> 16#include <net/sock.h>
@@ -72,7 +73,7 @@ static void flush_route_cache(struct fib_rules_ops *ops)
72 ops->flush_cache(ops); 73 ops->flush_cache(ops);
73} 74}
74 75
75int fib_rules_register(struct fib_rules_ops *ops) 76static int __fib_rules_register(struct fib_rules_ops *ops)
76{ 77{
77 int err = -EEXIST; 78 int err = -EEXIST;
78 struct fib_rules_ops *o; 79 struct fib_rules_ops *o;
@@ -102,6 +103,28 @@ errout:
102 return err; 103 return err;
103} 104}
104 105
106struct fib_rules_ops *
107fib_rules_register(struct fib_rules_ops *tmpl, struct net *net)
108{
109 struct fib_rules_ops *ops;
110 int err;
111
112 ops = kmemdup(tmpl, sizeof (*ops), GFP_KERNEL);
113 if (ops == NULL)
114 return ERR_PTR(-ENOMEM);
115
116 INIT_LIST_HEAD(&ops->rules_list);
117 ops->fro_net = net;
118
119 err = __fib_rules_register(ops);
120 if (err) {
121 kfree(ops);
122 ops = ERR_PTR(err);
123 }
124
125 return ops;
126}
127
105EXPORT_SYMBOL_GPL(fib_rules_register); 128EXPORT_SYMBOL_GPL(fib_rules_register);
106 129
107void fib_rules_cleanup_ops(struct fib_rules_ops *ops) 130void fib_rules_cleanup_ops(struct fib_rules_ops *ops)
@@ -115,6 +138,15 @@ void fib_rules_cleanup_ops(struct fib_rules_ops *ops)
115} 138}
116EXPORT_SYMBOL_GPL(fib_rules_cleanup_ops); 139EXPORT_SYMBOL_GPL(fib_rules_cleanup_ops);
117 140
141static void fib_rules_put_rcu(struct rcu_head *head)
142{
143 struct fib_rules_ops *ops = container_of(head, struct fib_rules_ops, rcu);
144 struct net *net = ops->fro_net;
145
146 release_net(net);
147 kfree(ops);
148}
149
118void fib_rules_unregister(struct fib_rules_ops *ops) 150void fib_rules_unregister(struct fib_rules_ops *ops)
119{ 151{
120 struct net *net = ops->fro_net; 152 struct net *net = ops->fro_net;
@@ -124,8 +156,7 @@ void fib_rules_unregister(struct fib_rules_ops *ops)
124 fib_rules_cleanup_ops(ops); 156 fib_rules_cleanup_ops(ops);
125 spin_unlock(&net->rules_mod_lock); 157 spin_unlock(&net->rules_mod_lock);
126 158
127 synchronize_rcu(); 159 call_rcu(&ops->rcu, fib_rules_put_rcu);
128 release_net(net);
129} 160}
130 161
131EXPORT_SYMBOL_GPL(fib_rules_unregister); 162EXPORT_SYMBOL_GPL(fib_rules_unregister);
@@ -135,7 +166,10 @@ static int fib_rule_match(struct fib_rule *rule, struct fib_rules_ops *ops,
135{ 166{
136 int ret = 0; 167 int ret = 0;
137 168
138 if (rule->ifindex && (rule->ifindex != fl->iif)) 169 if (rule->iifindex && (rule->iifindex != fl->iif))
170 goto out;
171
172 if (rule->oifindex && (rule->oifindex != fl->oif))
139 goto out; 173 goto out;
140 174
141 if ((rule->mark ^ fl->mark) & rule->mark_mask) 175 if ((rule->mark ^ fl->mark) & rule->mark_mask)
@@ -248,14 +282,24 @@ static int fib_nl_newrule(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg)
248 if (tb[FRA_PRIORITY]) 282 if (tb[FRA_PRIORITY])
249 rule->pref = nla_get_u32(tb[FRA_PRIORITY]); 283 rule->pref = nla_get_u32(tb[FRA_PRIORITY]);
250 284
251 if (tb[FRA_IFNAME]) { 285 if (tb[FRA_IIFNAME]) {
286 struct net_device *dev;
287
288 rule->iifindex = -1;
289 nla_strlcpy(rule->iifname, tb[FRA_IIFNAME], IFNAMSIZ);
290 dev = __dev_get_by_name(net, rule->iifname);
291 if (dev)
292 rule->iifindex = dev->ifindex;
293 }
294
295 if (tb[FRA_OIFNAME]) {
252 struct net_device *dev; 296 struct net_device *dev;
253 297
254 rule->ifindex = -1; 298 rule->oifindex = -1;
255 nla_strlcpy(rule->ifname, tb[FRA_IFNAME], IFNAMSIZ); 299 nla_strlcpy(rule->oifname, tb[FRA_OIFNAME], IFNAMSIZ);
256 dev = __dev_get_by_name(net, rule->ifname); 300 dev = __dev_get_by_name(net, rule->oifname);
257 if (dev) 301 if (dev)
258 rule->ifindex = dev->ifindex; 302 rule->oifindex = dev->ifindex;
259 } 303 }
260 304
261 if (tb[FRA_FWMARK]) { 305 if (tb[FRA_FWMARK]) {
@@ -274,7 +318,7 @@ static int fib_nl_newrule(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg)
274 rule->flags = frh->flags; 318 rule->flags = frh->flags;
275 rule->table = frh_get_table(frh, tb); 319 rule->table = frh_get_table(frh, tb);
276 320
277 if (!rule->pref && ops->default_pref) 321 if (!tb[FRA_PRIORITY] && ops->default_pref)
278 rule->pref = ops->default_pref(ops); 322 rule->pref = ops->default_pref(ops);
279 323
280 err = -EINVAL; 324 err = -EINVAL;
@@ -388,8 +432,12 @@ static int fib_nl_delrule(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg)
388 (rule->pref != nla_get_u32(tb[FRA_PRIORITY]))) 432 (rule->pref != nla_get_u32(tb[FRA_PRIORITY])))
389 continue; 433 continue;
390 434
391 if (tb[FRA_IFNAME] && 435 if (tb[FRA_IIFNAME] &&
392 nla_strcmp(tb[FRA_IFNAME], rule->ifname)) 436 nla_strcmp(tb[FRA_IIFNAME], rule->iifname))
437 continue;
438
439 if (tb[FRA_OIFNAME] &&
440 nla_strcmp(tb[FRA_OIFNAME], rule->oifname))
393 continue; 441 continue;
394 442
395 if (tb[FRA_FWMARK] && 443 if (tb[FRA_FWMARK] &&
@@ -447,7 +495,8 @@ static inline size_t fib_rule_nlmsg_size(struct fib_rules_ops *ops,
447 struct fib_rule *rule) 495 struct fib_rule *rule)
448{ 496{
449 size_t payload = NLMSG_ALIGN(sizeof(struct fib_rule_hdr)) 497 size_t payload = NLMSG_ALIGN(sizeof(struct fib_rule_hdr))
450 + nla_total_size(IFNAMSIZ) /* FRA_IFNAME */ 498 + nla_total_size(IFNAMSIZ) /* FRA_IIFNAME */
499 + nla_total_size(IFNAMSIZ) /* FRA_OIFNAME */
451 + nla_total_size(4) /* FRA_PRIORITY */ 500 + nla_total_size(4) /* FRA_PRIORITY */
452 + nla_total_size(4) /* FRA_TABLE */ 501 + nla_total_size(4) /* FRA_TABLE */
453 + nla_total_size(4) /* FRA_FWMARK */ 502 + nla_total_size(4) /* FRA_FWMARK */
@@ -481,11 +530,18 @@ static int fib_nl_fill_rule(struct sk_buff *skb, struct fib_rule *rule,
481 if (rule->action == FR_ACT_GOTO && rule->ctarget == NULL) 530 if (rule->action == FR_ACT_GOTO && rule->ctarget == NULL)
482 frh->flags |= FIB_RULE_UNRESOLVED; 531 frh->flags |= FIB_RULE_UNRESOLVED;
483 532
484 if (rule->ifname[0]) { 533 if (rule->iifname[0]) {
485 NLA_PUT_STRING(skb, FRA_IFNAME, rule->ifname); 534 NLA_PUT_STRING(skb, FRA_IIFNAME, rule->iifname);
486 535
487 if (rule->ifindex == -1) 536 if (rule->iifindex == -1)
488 frh->flags |= FIB_RULE_DEV_DETACHED; 537 frh->flags |= FIB_RULE_IIF_DETACHED;
538 }
539
540 if (rule->oifname[0]) {
541 NLA_PUT_STRING(skb, FRA_OIFNAME, rule->oifname);
542
543 if (rule->oifindex == -1)
544 frh->flags |= FIB_RULE_OIF_DETACHED;
489 } 545 }
490 546
491 if (rule->pref) 547 if (rule->pref)
@@ -600,9 +656,12 @@ static void attach_rules(struct list_head *rules, struct net_device *dev)
600 struct fib_rule *rule; 656 struct fib_rule *rule;
601 657
602 list_for_each_entry(rule, rules, list) { 658 list_for_each_entry(rule, rules, list) {
603 if (rule->ifindex == -1 && 659 if (rule->iifindex == -1 &&
604 strcmp(dev->name, rule->ifname) == 0) 660 strcmp(dev->name, rule->iifname) == 0)
605 rule->ifindex = dev->ifindex; 661 rule->iifindex = dev->ifindex;
662 if (rule->oifindex == -1 &&
663 strcmp(dev->name, rule->oifname) == 0)
664 rule->oifindex = dev->ifindex;
606 } 665 }
607} 666}
608 667
@@ -610,9 +669,12 @@ static void detach_rules(struct list_head *rules, struct net_device *dev)
610{ 669{
611 struct fib_rule *rule; 670 struct fib_rule *rule;
612 671
613 list_for_each_entry(rule, rules, list) 672 list_for_each_entry(rule, rules, list) {
614 if (rule->ifindex == dev->ifindex) 673 if (rule->iifindex == dev->ifindex)
615 rule->ifindex = -1; 674 rule->iifindex = -1;
675 if (rule->oifindex == dev->ifindex)
676 rule->oifindex = -1;
677 }
616} 678}
617 679
618 680
@@ -647,7 +709,7 @@ static struct notifier_block fib_rules_notifier = {
647 .notifier_call = fib_rules_event, 709 .notifier_call = fib_rules_event,
648}; 710};
649 711
650static int fib_rules_net_init(struct net *net) 712static int __net_init fib_rules_net_init(struct net *net)
651{ 713{
652 INIT_LIST_HEAD(&net->rules_ops); 714 INIT_LIST_HEAD(&net->rules_ops);
653 spin_lock_init(&net->rules_mod_lock); 715 spin_lock_init(&net->rules_mod_lock);
diff --git a/net/core/filter.c b/net/core/filter.c
index d1d779ca096d..ff943bed21af 100644
--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ -25,6 +25,7 @@
25#include <linux/inet.h> 25#include <linux/inet.h>
26#include <linux/netdevice.h> 26#include <linux/netdevice.h>
27#include <linux/if_packet.h> 27#include <linux/if_packet.h>
28#include <linux/gfp.h>
28#include <net/ip.h> 29#include <net/ip.h>
29#include <net/protocol.h> 30#include <net/protocol.h>
30#include <net/netlink.h> 31#include <net/netlink.h>
@@ -86,7 +87,7 @@ int sk_filter(struct sock *sk, struct sk_buff *skb)
86 return err; 87 return err;
87 88
88 rcu_read_lock_bh(); 89 rcu_read_lock_bh();
89 filter = rcu_dereference(sk->sk_filter); 90 filter = rcu_dereference_bh(sk->sk_filter);
90 if (filter) { 91 if (filter) {
91 unsigned int pkt_len = sk_run_filter(skb, filter->insns, 92 unsigned int pkt_len = sk_run_filter(skb, filter->insns,
92 filter->len); 93 filter->len);
@@ -303,6 +304,12 @@ load_b:
303 case SKF_AD_IFINDEX: 304 case SKF_AD_IFINDEX:
304 A = skb->dev->ifindex; 305 A = skb->dev->ifindex;
305 continue; 306 continue;
307 case SKF_AD_MARK:
308 A = skb->mark;
309 continue;
310 case SKF_AD_QUEUE:
311 A = skb->queue_mapping;
312 continue;
306 case SKF_AD_NLATTR: { 313 case SKF_AD_NLATTR: {
307 struct nlattr *nla; 314 struct nlattr *nla;
308 315
@@ -515,7 +522,7 @@ int sk_attach_filter(struct sock_fprog *fprog, struct sock *sk)
515 } 522 }
516 523
517 rcu_read_lock_bh(); 524 rcu_read_lock_bh();
518 old_fp = rcu_dereference(sk->sk_filter); 525 old_fp = rcu_dereference_bh(sk->sk_filter);
519 rcu_assign_pointer(sk->sk_filter, fp); 526 rcu_assign_pointer(sk->sk_filter, fp);
520 rcu_read_unlock_bh(); 527 rcu_read_unlock_bh();
521 528
@@ -523,6 +530,7 @@ int sk_attach_filter(struct sock_fprog *fprog, struct sock *sk)
523 sk_filter_delayed_uncharge(sk, old_fp); 530 sk_filter_delayed_uncharge(sk, old_fp);
524 return 0; 531 return 0;
525} 532}
533EXPORT_SYMBOL_GPL(sk_attach_filter);
526 534
527int sk_detach_filter(struct sock *sk) 535int sk_detach_filter(struct sock *sk)
528{ 536{
@@ -530,7 +538,7 @@ int sk_detach_filter(struct sock *sk)
530 struct sk_filter *filter; 538 struct sk_filter *filter;
531 539
532 rcu_read_lock_bh(); 540 rcu_read_lock_bh();
533 filter = rcu_dereference(sk->sk_filter); 541 filter = rcu_dereference_bh(sk->sk_filter);
534 if (filter) { 542 if (filter) {
535 rcu_assign_pointer(sk->sk_filter, NULL); 543 rcu_assign_pointer(sk->sk_filter, NULL);
536 sk_filter_delayed_uncharge(sk, filter); 544 sk_filter_delayed_uncharge(sk, filter);
@@ -539,3 +547,4 @@ int sk_detach_filter(struct sock *sk)
539 rcu_read_unlock_bh(); 547 rcu_read_unlock_bh();
540 return ret; 548 return ret;
541} 549}
550EXPORT_SYMBOL_GPL(sk_detach_filter);
diff --git a/net/core/gen_estimator.c b/net/core/gen_estimator.c
index 493775f4f2f1..cf8e70392fe0 100644
--- a/net/core/gen_estimator.c
+++ b/net/core/gen_estimator.c
@@ -32,6 +32,7 @@
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 <linux/rbtree.h>
35#include <linux/slab.h>
35#include <net/sock.h> 36#include <net/sock.h>
36#include <net/gen_stats.h> 37#include <net/gen_stats.h>
37 38
diff --git a/net/core/gen_stats.c b/net/core/gen_stats.c
index 8569310268ab..393b1d8618e2 100644
--- a/net/core/gen_stats.c
+++ b/net/core/gen_stats.c
@@ -127,6 +127,7 @@ gnet_stats_copy_basic(struct gnet_dump *d, struct gnet_stats_basic_packed *b)
127/** 127/**
128 * gnet_stats_copy_rate_est - copy rate estimator statistics into statistics TLV 128 * gnet_stats_copy_rate_est - copy rate estimator statistics into statistics TLV
129 * @d: dumping handle 129 * @d: dumping handle
130 * @b: basic statistics
130 * @r: rate estimator statistics 131 * @r: rate estimator statistics
131 * 132 *
132 * Appends the rate estimator statistics to the top level TLV created by 133 * Appends the rate estimator statistics to the top level TLV created by
@@ -136,8 +137,13 @@ gnet_stats_copy_basic(struct gnet_dump *d, struct gnet_stats_basic_packed *b)
136 * if the room in the socket buffer was not sufficient. 137 * if the room in the socket buffer was not sufficient.
137 */ 138 */
138int 139int
139gnet_stats_copy_rate_est(struct gnet_dump *d, struct gnet_stats_rate_est *r) 140gnet_stats_copy_rate_est(struct gnet_dump *d,
141 const struct gnet_stats_basic_packed *b,
142 struct gnet_stats_rate_est *r)
140{ 143{
144 if (b && !gen_estimator_active(b, r))
145 return 0;
146
141 if (d->compat_tc_stats) { 147 if (d->compat_tc_stats) {
142 d->tc_stats.bps = r->bps; 148 d->tc_stats.bps = r->bps;
143 d->tc_stats.pps = r->pps; 149 d->tc_stats.pps = r->pps;
diff --git a/net/core/iovec.c b/net/core/iovec.c
index 16ad45d4882b..1e7f4e91a935 100644
--- a/net/core/iovec.c
+++ b/net/core/iovec.c
@@ -20,7 +20,6 @@
20#include <linux/module.h> 20#include <linux/module.h>
21#include <linux/kernel.h> 21#include <linux/kernel.h>
22#include <linux/mm.h> 22#include <linux/mm.h>
23#include <linux/slab.h>
24#include <linux/net.h> 23#include <linux/net.h>
25#include <linux/in6.h> 24#include <linux/in6.h>
26#include <asm/uaccess.h> 25#include <asm/uaccess.h>
diff --git a/net/core/link_watch.c b/net/core/link_watch.c
index bf8f7af699d7..bdbce2f5875b 100644
--- a/net/core/link_watch.c
+++ b/net/core/link_watch.c
@@ -19,7 +19,6 @@
19#include <linux/rtnetlink.h> 19#include <linux/rtnetlink.h>
20#include <linux/jiffies.h> 20#include <linux/jiffies.h>
21#include <linux/spinlock.h> 21#include <linux/spinlock.h>
22#include <linux/slab.h>
23#include <linux/workqueue.h> 22#include <linux/workqueue.h>
24#include <linux/bitops.h> 23#include <linux/bitops.h>
25#include <asm/types.h> 24#include <asm/types.h>
@@ -35,7 +34,7 @@ static unsigned long linkwatch_nextevent;
35static void linkwatch_event(struct work_struct *dummy); 34static void linkwatch_event(struct work_struct *dummy);
36static DECLARE_DELAYED_WORK(linkwatch_work, linkwatch_event); 35static DECLARE_DELAYED_WORK(linkwatch_work, linkwatch_event);
37 36
38static struct net_device *lweventlist; 37static LIST_HEAD(lweventlist);
39static DEFINE_SPINLOCK(lweventlist_lock); 38static DEFINE_SPINLOCK(lweventlist_lock);
40 39
41static unsigned char default_operstate(const struct net_device *dev) 40static unsigned char default_operstate(const struct net_device *dev)
@@ -89,8 +88,10 @@ static void linkwatch_add_event(struct net_device *dev)
89 unsigned long flags; 88 unsigned long flags;
90 89
91 spin_lock_irqsave(&lweventlist_lock, flags); 90 spin_lock_irqsave(&lweventlist_lock, flags);
92 dev->link_watch_next = lweventlist; 91 if (list_empty(&dev->link_watch_list)) {
93 lweventlist = dev; 92 list_add_tail(&dev->link_watch_list, &lweventlist);
93 dev_hold(dev);
94 }
94 spin_unlock_irqrestore(&lweventlist_lock, flags); 95 spin_unlock_irqrestore(&lweventlist_lock, flags);
95} 96}
96 97
@@ -133,9 +134,35 @@ static void linkwatch_schedule_work(int urgent)
133} 134}
134 135
135 136
137static void linkwatch_do_dev(struct net_device *dev)
138{
139 /*
140 * Make sure the above read is complete since it can be
141 * rewritten as soon as we clear the bit below.
142 */
143 smp_mb__before_clear_bit();
144
145 /* We are about to handle this device,
146 * so new events can be accepted
147 */
148 clear_bit(__LINK_STATE_LINKWATCH_PENDING, &dev->state);
149
150 rfc2863_policy(dev);
151 if (dev->flags & IFF_UP) {
152 if (netif_carrier_ok(dev))
153 dev_activate(dev);
154 else
155 dev_deactivate(dev);
156
157 netdev_state_change(dev);
158 }
159 dev_put(dev);
160}
161
136static void __linkwatch_run_queue(int urgent_only) 162static void __linkwatch_run_queue(int urgent_only)
137{ 163{
138 struct net_device *next; 164 struct net_device *dev;
165 LIST_HEAD(wrk);
139 166
140 /* 167 /*
141 * Limit the number of linkwatch events to one 168 * Limit the number of linkwatch events to one
@@ -153,46 +180,40 @@ static void __linkwatch_run_queue(int urgent_only)
153 clear_bit(LW_URGENT, &linkwatch_flags); 180 clear_bit(LW_URGENT, &linkwatch_flags);
154 181
155 spin_lock_irq(&lweventlist_lock); 182 spin_lock_irq(&lweventlist_lock);
156 next = lweventlist; 183 list_splice_init(&lweventlist, &wrk);
157 lweventlist = NULL;
158 spin_unlock_irq(&lweventlist_lock);
159 184
160 while (next) { 185 while (!list_empty(&wrk)) {
161 struct net_device *dev = next;
162 186
163 next = dev->link_watch_next; 187 dev = list_first_entry(&wrk, struct net_device, link_watch_list);
188 list_del_init(&dev->link_watch_list);
164 189
165 if (urgent_only && !linkwatch_urgent_event(dev)) { 190 if (urgent_only && !linkwatch_urgent_event(dev)) {
166 linkwatch_add_event(dev); 191 list_add_tail(&dev->link_watch_list, &lweventlist);
167 continue; 192 continue;
168 } 193 }
169 194 spin_unlock_irq(&lweventlist_lock);
170 /* 195 linkwatch_do_dev(dev);
171 * Make sure the above read is complete since it can be 196 spin_lock_irq(&lweventlist_lock);
172 * rewritten as soon as we clear the bit below.
173 */
174 smp_mb__before_clear_bit();
175
176 /* We are about to handle this device,
177 * so new events can be accepted
178 */
179 clear_bit(__LINK_STATE_LINKWATCH_PENDING, &dev->state);
180
181 rfc2863_policy(dev);
182 if (dev->flags & IFF_UP) {
183 if (netif_carrier_ok(dev))
184 dev_activate(dev);
185 else
186 dev_deactivate(dev);
187
188 netdev_state_change(dev);
189 }
190
191 dev_put(dev);
192 } 197 }
193 198
194 if (lweventlist) 199 if (!list_empty(&lweventlist))
195 linkwatch_schedule_work(0); 200 linkwatch_schedule_work(0);
201 spin_unlock_irq(&lweventlist_lock);
202}
203
204void linkwatch_forget_dev(struct net_device *dev)
205{
206 unsigned long flags;
207 int clean = 0;
208
209 spin_lock_irqsave(&lweventlist_lock, flags);
210 if (!list_empty(&dev->link_watch_list)) {
211 list_del_init(&dev->link_watch_list);
212 clean = 1;
213 }
214 spin_unlock_irqrestore(&lweventlist_lock, flags);
215 if (clean)
216 linkwatch_do_dev(dev);
196} 217}
197 218
198 219
@@ -216,8 +237,6 @@ void linkwatch_fire_event(struct net_device *dev)
216 bool urgent = linkwatch_urgent_event(dev); 237 bool urgent = linkwatch_urgent_event(dev);
217 238
218 if (!test_and_set_bit(__LINK_STATE_LINKWATCH_PENDING, &dev->state)) { 239 if (!test_and_set_bit(__LINK_STATE_LINKWATCH_PENDING, &dev->state)) {
219 dev_hold(dev);
220
221 linkwatch_add_event(dev); 240 linkwatch_add_event(dev);
222 } else if (!urgent) 241 } else if (!urgent)
223 return; 242 return;
diff --git a/net/core/neighbour.c b/net/core/neighbour.c
index e587e6819698..bff37908bd55 100644
--- a/net/core/neighbour.c
+++ b/net/core/neighbour.c
@@ -15,6 +15,7 @@
15 * Harald Welte Add neighbour cache statistics like rtstat 15 * Harald Welte Add neighbour cache statistics like rtstat
16 */ 16 */
17 17
18#include <linux/slab.h>
18#include <linux/types.h> 19#include <linux/types.h>
19#include <linux/kernel.h> 20#include <linux/kernel.h>
20#include <linux/module.h> 21#include <linux/module.h>
@@ -771,6 +772,8 @@ static __inline__ int neigh_max_probes(struct neighbour *n)
771} 772}
772 773
773static void neigh_invalidate(struct neighbour *neigh) 774static void neigh_invalidate(struct neighbour *neigh)
775 __releases(neigh->lock)
776 __acquires(neigh->lock)
774{ 777{
775 struct sk_buff *skb; 778 struct sk_buff *skb;
776 779
@@ -2092,7 +2095,7 @@ static int neigh_dump_table(struct neigh_table *tbl, struct sk_buff *skb,
2092 if (h > s_h) 2095 if (h > s_h)
2093 s_idx = 0; 2096 s_idx = 0;
2094 for (n = tbl->hash_buckets[h], idx = 0; n; n = n->next) { 2097 for (n = tbl->hash_buckets[h], idx = 0; n; n = n->next) {
2095 if (dev_net(n->dev) != net) 2098 if (!net_eq(dev_net(n->dev), net))
2096 continue; 2099 continue;
2097 if (idx < s_idx) 2100 if (idx < s_idx)
2098 goto next; 2101 goto next;
@@ -2417,8 +2420,7 @@ EXPORT_SYMBOL(neigh_seq_stop);
2417 2420
2418static void *neigh_stat_seq_start(struct seq_file *seq, loff_t *pos) 2421static void *neigh_stat_seq_start(struct seq_file *seq, loff_t *pos)
2419{ 2422{
2420 struct proc_dir_entry *pde = seq->private; 2423 struct neigh_table *tbl = seq->private;
2421 struct neigh_table *tbl = pde->data;
2422 int cpu; 2424 int cpu;
2423 2425
2424 if (*pos == 0) 2426 if (*pos == 0)
@@ -2435,8 +2437,7 @@ static void *neigh_stat_seq_start(struct seq_file *seq, loff_t *pos)
2435 2437
2436static void *neigh_stat_seq_next(struct seq_file *seq, void *v, loff_t *pos) 2438static void *neigh_stat_seq_next(struct seq_file *seq, void *v, loff_t *pos)
2437{ 2439{
2438 struct proc_dir_entry *pde = seq->private; 2440 struct neigh_table *tbl = seq->private;
2439 struct neigh_table *tbl = pde->data;
2440 int cpu; 2441 int cpu;
2441 2442
2442 for (cpu = *pos; cpu < nr_cpu_ids; ++cpu) { 2443 for (cpu = *pos; cpu < nr_cpu_ids; ++cpu) {
@@ -2455,8 +2456,7 @@ static void neigh_stat_seq_stop(struct seq_file *seq, void *v)
2455 2456
2456static int neigh_stat_seq_show(struct seq_file *seq, void *v) 2457static int neigh_stat_seq_show(struct seq_file *seq, void *v)
2457{ 2458{
2458 struct proc_dir_entry *pde = seq->private; 2459 struct neigh_table *tbl = seq->private;
2459 struct neigh_table *tbl = pde->data;
2460 struct neigh_statistics *st = v; 2460 struct neigh_statistics *st = v;
2461 2461
2462 if (v == SEQ_START_TOKEN) { 2462 if (v == SEQ_START_TOKEN) {
@@ -2501,7 +2501,7 @@ static int neigh_stat_seq_open(struct inode *inode, struct file *file)
2501 2501
2502 if (!ret) { 2502 if (!ret) {
2503 struct seq_file *sf = file->private_data; 2503 struct seq_file *sf = file->private_data;
2504 sf->private = PDE(inode); 2504 sf->private = PDE(inode)->data;
2505 } 2505 }
2506 return ret; 2506 return ret;
2507}; 2507};
@@ -2559,28 +2559,27 @@ EXPORT_SYMBOL(neigh_app_ns);
2559 2559
2560#ifdef CONFIG_SYSCTL 2560#ifdef CONFIG_SYSCTL
2561 2561
2562#define NEIGH_VARS_MAX 19
2563
2562static struct neigh_sysctl_table { 2564static struct neigh_sysctl_table {
2563 struct ctl_table_header *sysctl_header; 2565 struct ctl_table_header *sysctl_header;
2564 struct ctl_table neigh_vars[__NET_NEIGH_MAX]; 2566 struct ctl_table neigh_vars[NEIGH_VARS_MAX];
2565 char *dev_name; 2567 char *dev_name;
2566} neigh_sysctl_template __read_mostly = { 2568} neigh_sysctl_template __read_mostly = {
2567 .neigh_vars = { 2569 .neigh_vars = {
2568 { 2570 {
2569 .ctl_name = NET_NEIGH_MCAST_SOLICIT,
2570 .procname = "mcast_solicit", 2571 .procname = "mcast_solicit",
2571 .maxlen = sizeof(int), 2572 .maxlen = sizeof(int),
2572 .mode = 0644, 2573 .mode = 0644,
2573 .proc_handler = proc_dointvec, 2574 .proc_handler = proc_dointvec,
2574 }, 2575 },
2575 { 2576 {
2576 .ctl_name = NET_NEIGH_UCAST_SOLICIT,
2577 .procname = "ucast_solicit", 2577 .procname = "ucast_solicit",
2578 .maxlen = sizeof(int), 2578 .maxlen = sizeof(int),
2579 .mode = 0644, 2579 .mode = 0644,
2580 .proc_handler = proc_dointvec, 2580 .proc_handler = proc_dointvec,
2581 }, 2581 },
2582 { 2582 {
2583 .ctl_name = NET_NEIGH_APP_SOLICIT,
2584 .procname = "app_solicit", 2583 .procname = "app_solicit",
2585 .maxlen = sizeof(int), 2584 .maxlen = sizeof(int),
2586 .mode = 0644, 2585 .mode = 0644,
@@ -2593,38 +2592,30 @@ static struct neigh_sysctl_table {
2593 .proc_handler = proc_dointvec_userhz_jiffies, 2592 .proc_handler = proc_dointvec_userhz_jiffies,
2594 }, 2593 },
2595 { 2594 {
2596 .ctl_name = NET_NEIGH_REACHABLE_TIME,
2597 .procname = "base_reachable_time", 2595 .procname = "base_reachable_time",
2598 .maxlen = sizeof(int), 2596 .maxlen = sizeof(int),
2599 .mode = 0644, 2597 .mode = 0644,
2600 .proc_handler = proc_dointvec_jiffies, 2598 .proc_handler = proc_dointvec_jiffies,
2601 .strategy = sysctl_jiffies,
2602 }, 2599 },
2603 { 2600 {
2604 .ctl_name = NET_NEIGH_DELAY_PROBE_TIME,
2605 .procname = "delay_first_probe_time", 2601 .procname = "delay_first_probe_time",
2606 .maxlen = sizeof(int), 2602 .maxlen = sizeof(int),
2607 .mode = 0644, 2603 .mode = 0644,
2608 .proc_handler = proc_dointvec_jiffies, 2604 .proc_handler = proc_dointvec_jiffies,
2609 .strategy = sysctl_jiffies,
2610 }, 2605 },
2611 { 2606 {
2612 .ctl_name = NET_NEIGH_GC_STALE_TIME,
2613 .procname = "gc_stale_time", 2607 .procname = "gc_stale_time",
2614 .maxlen = sizeof(int), 2608 .maxlen = sizeof(int),
2615 .mode = 0644, 2609 .mode = 0644,
2616 .proc_handler = proc_dointvec_jiffies, 2610 .proc_handler = proc_dointvec_jiffies,
2617 .strategy = sysctl_jiffies,
2618 }, 2611 },
2619 { 2612 {
2620 .ctl_name = NET_NEIGH_UNRES_QLEN,
2621 .procname = "unres_qlen", 2613 .procname = "unres_qlen",
2622 .maxlen = sizeof(int), 2614 .maxlen = sizeof(int),
2623 .mode = 0644, 2615 .mode = 0644,
2624 .proc_handler = proc_dointvec, 2616 .proc_handler = proc_dointvec,
2625 }, 2617 },
2626 { 2618 {
2627 .ctl_name = NET_NEIGH_PROXY_QLEN,
2628 .procname = "proxy_qlen", 2619 .procname = "proxy_qlen",
2629 .maxlen = sizeof(int), 2620 .maxlen = sizeof(int),
2630 .mode = 0644, 2621 .mode = 0644,
@@ -2649,45 +2640,36 @@ static struct neigh_sysctl_table {
2649 .proc_handler = proc_dointvec_userhz_jiffies, 2640 .proc_handler = proc_dointvec_userhz_jiffies,
2650 }, 2641 },
2651 { 2642 {
2652 .ctl_name = NET_NEIGH_RETRANS_TIME_MS,
2653 .procname = "retrans_time_ms", 2643 .procname = "retrans_time_ms",
2654 .maxlen = sizeof(int), 2644 .maxlen = sizeof(int),
2655 .mode = 0644, 2645 .mode = 0644,
2656 .proc_handler = proc_dointvec_ms_jiffies, 2646 .proc_handler = proc_dointvec_ms_jiffies,
2657 .strategy = sysctl_ms_jiffies,
2658 }, 2647 },
2659 { 2648 {
2660 .ctl_name = NET_NEIGH_REACHABLE_TIME_MS,
2661 .procname = "base_reachable_time_ms", 2649 .procname = "base_reachable_time_ms",
2662 .maxlen = sizeof(int), 2650 .maxlen = sizeof(int),
2663 .mode = 0644, 2651 .mode = 0644,
2664 .proc_handler = proc_dointvec_ms_jiffies, 2652 .proc_handler = proc_dointvec_ms_jiffies,
2665 .strategy = sysctl_ms_jiffies,
2666 }, 2653 },
2667 { 2654 {
2668 .ctl_name = NET_NEIGH_GC_INTERVAL,
2669 .procname = "gc_interval", 2655 .procname = "gc_interval",
2670 .maxlen = sizeof(int), 2656 .maxlen = sizeof(int),
2671 .mode = 0644, 2657 .mode = 0644,
2672 .proc_handler = proc_dointvec_jiffies, 2658 .proc_handler = proc_dointvec_jiffies,
2673 .strategy = sysctl_jiffies,
2674 }, 2659 },
2675 { 2660 {
2676 .ctl_name = NET_NEIGH_GC_THRESH1,
2677 .procname = "gc_thresh1", 2661 .procname = "gc_thresh1",
2678 .maxlen = sizeof(int), 2662 .maxlen = sizeof(int),
2679 .mode = 0644, 2663 .mode = 0644,
2680 .proc_handler = proc_dointvec, 2664 .proc_handler = proc_dointvec,
2681 }, 2665 },
2682 { 2666 {
2683 .ctl_name = NET_NEIGH_GC_THRESH2,
2684 .procname = "gc_thresh2", 2667 .procname = "gc_thresh2",
2685 .maxlen = sizeof(int), 2668 .maxlen = sizeof(int),
2686 .mode = 0644, 2669 .mode = 0644,
2687 .proc_handler = proc_dointvec, 2670 .proc_handler = proc_dointvec,
2688 }, 2671 },
2689 { 2672 {
2690 .ctl_name = NET_NEIGH_GC_THRESH3,
2691 .procname = "gc_thresh3", 2673 .procname = "gc_thresh3",
2692 .maxlen = sizeof(int), 2674 .maxlen = sizeof(int),
2693 .mode = 0644, 2675 .mode = 0644,
@@ -2698,8 +2680,7 @@ static struct neigh_sysctl_table {
2698}; 2680};
2699 2681
2700int neigh_sysctl_register(struct net_device *dev, struct neigh_parms *p, 2682int neigh_sysctl_register(struct net_device *dev, struct neigh_parms *p,
2701 int p_id, int pdev_id, char *p_name, 2683 char *p_name, proc_handler *handler)
2702 proc_handler *handler, ctl_handler *strategy)
2703{ 2684{
2704 struct neigh_sysctl_table *t; 2685 struct neigh_sysctl_table *t;
2705 const char *dev_name_source = NULL; 2686 const char *dev_name_source = NULL;
@@ -2710,10 +2691,10 @@ int neigh_sysctl_register(struct net_device *dev, struct neigh_parms *p,
2710#define NEIGH_CTL_PATH_DEV 3 2691#define NEIGH_CTL_PATH_DEV 3
2711 2692
2712 struct ctl_path neigh_path[] = { 2693 struct ctl_path neigh_path[] = {
2713 { .procname = "net", .ctl_name = CTL_NET, }, 2694 { .procname = "net", },
2714 { .procname = "proto", .ctl_name = 0, }, 2695 { .procname = "proto", },
2715 { .procname = "neigh", .ctl_name = 0, }, 2696 { .procname = "neigh", },
2716 { .procname = "default", .ctl_name = NET_PROTO_CONF_DEFAULT, }, 2697 { .procname = "default", },
2717 { }, 2698 { },
2718 }; 2699 };
2719 2700
@@ -2738,7 +2719,6 @@ int neigh_sysctl_register(struct net_device *dev, struct neigh_parms *p,
2738 2719
2739 if (dev) { 2720 if (dev) {
2740 dev_name_source = dev->name; 2721 dev_name_source = dev->name;
2741 neigh_path[NEIGH_CTL_PATH_DEV].ctl_name = dev->ifindex;
2742 /* Terminate the table early */ 2722 /* Terminate the table early */
2743 memset(&t->neigh_vars[14], 0, sizeof(t->neigh_vars[14])); 2723 memset(&t->neigh_vars[14], 0, sizeof(t->neigh_vars[14]));
2744 } else { 2724 } else {
@@ -2750,31 +2730,19 @@ int neigh_sysctl_register(struct net_device *dev, struct neigh_parms *p,
2750 } 2730 }
2751 2731
2752 2732
2753 if (handler || strategy) { 2733 if (handler) {
2754 /* RetransTime */ 2734 /* RetransTime */
2755 t->neigh_vars[3].proc_handler = handler; 2735 t->neigh_vars[3].proc_handler = handler;
2756 t->neigh_vars[3].strategy = strategy;
2757 t->neigh_vars[3].extra1 = dev; 2736 t->neigh_vars[3].extra1 = dev;
2758 if (!strategy)
2759 t->neigh_vars[3].ctl_name = CTL_UNNUMBERED;
2760 /* ReachableTime */ 2737 /* ReachableTime */
2761 t->neigh_vars[4].proc_handler = handler; 2738 t->neigh_vars[4].proc_handler = handler;
2762 t->neigh_vars[4].strategy = strategy;
2763 t->neigh_vars[4].extra1 = dev; 2739 t->neigh_vars[4].extra1 = dev;
2764 if (!strategy)
2765 t->neigh_vars[4].ctl_name = CTL_UNNUMBERED;
2766 /* RetransTime (in milliseconds)*/ 2740 /* RetransTime (in milliseconds)*/
2767 t->neigh_vars[12].proc_handler = handler; 2741 t->neigh_vars[12].proc_handler = handler;
2768 t->neigh_vars[12].strategy = strategy;
2769 t->neigh_vars[12].extra1 = dev; 2742 t->neigh_vars[12].extra1 = dev;
2770 if (!strategy)
2771 t->neigh_vars[12].ctl_name = CTL_UNNUMBERED;
2772 /* ReachableTime (in milliseconds) */ 2743 /* ReachableTime (in milliseconds) */
2773 t->neigh_vars[13].proc_handler = handler; 2744 t->neigh_vars[13].proc_handler = handler;
2774 t->neigh_vars[13].strategy = strategy;
2775 t->neigh_vars[13].extra1 = dev; 2745 t->neigh_vars[13].extra1 = dev;
2776 if (!strategy)
2777 t->neigh_vars[13].ctl_name = CTL_UNNUMBERED;
2778 } 2746 }
2779 2747
2780 t->dev_name = kstrdup(dev_name_source, GFP_KERNEL); 2748 t->dev_name = kstrdup(dev_name_source, GFP_KERNEL);
@@ -2782,9 +2750,7 @@ int neigh_sysctl_register(struct net_device *dev, struct neigh_parms *p,
2782 goto free; 2750 goto free;
2783 2751
2784 neigh_path[NEIGH_CTL_PATH_DEV].procname = t->dev_name; 2752 neigh_path[NEIGH_CTL_PATH_DEV].procname = t->dev_name;
2785 neigh_path[NEIGH_CTL_PATH_NEIGH].ctl_name = pdev_id;
2786 neigh_path[NEIGH_CTL_PATH_PROTO].procname = p_name; 2753 neigh_path[NEIGH_CTL_PATH_PROTO].procname = p_name;
2787 neigh_path[NEIGH_CTL_PATH_PROTO].ctl_name = p_id;
2788 2754
2789 t->sysctl_header = 2755 t->sysctl_header =
2790 register_net_sysctl_table(neigh_parms_net(p), neigh_path, t->neigh_vars); 2756 register_net_sysctl_table(neigh_parms_net(p), neigh_path, t->neigh_vars);
diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
index 427ded841224..59cfc7d8fc45 100644
--- a/net/core/net-sysfs.c
+++ b/net/core/net-sysfs.c
@@ -13,6 +13,7 @@
13#include <linux/kernel.h> 13#include <linux/kernel.h>
14#include <linux/netdevice.h> 14#include <linux/netdevice.h>
15#include <linux/if_arp.h> 15#include <linux/if_arp.h>
16#include <linux/slab.h>
16#include <net/sock.h> 17#include <net/sock.h>
17#include <linux/rtnetlink.h> 18#include <linux/rtnetlink.h>
18#include <linux/wireless.h> 19#include <linux/wireless.h>
@@ -130,6 +131,48 @@ static ssize_t show_carrier(struct device *dev,
130 return -EINVAL; 131 return -EINVAL;
131} 132}
132 133
134static ssize_t show_speed(struct device *dev,
135 struct device_attribute *attr, char *buf)
136{
137 struct net_device *netdev = to_net_dev(dev);
138 int ret = -EINVAL;
139
140 if (!rtnl_trylock())
141 return restart_syscall();
142
143 if (netif_running(netdev) &&
144 netdev->ethtool_ops &&
145 netdev->ethtool_ops->get_settings) {
146 struct ethtool_cmd cmd = { ETHTOOL_GSET };
147
148 if (!netdev->ethtool_ops->get_settings(netdev, &cmd))
149 ret = sprintf(buf, fmt_dec, ethtool_cmd_speed(&cmd));
150 }
151 rtnl_unlock();
152 return ret;
153}
154
155static ssize_t show_duplex(struct device *dev,
156 struct device_attribute *attr, char *buf)
157{
158 struct net_device *netdev = to_net_dev(dev);
159 int ret = -EINVAL;
160
161 if (!rtnl_trylock())
162 return restart_syscall();
163
164 if (netif_running(netdev) &&
165 netdev->ethtool_ops &&
166 netdev->ethtool_ops->get_settings) {
167 struct ethtool_cmd cmd = { ETHTOOL_GSET };
168
169 if (!netdev->ethtool_ops->get_settings(netdev, &cmd))
170 ret = sprintf(buf, "%s\n", cmd.duplex ? "full" : "half");
171 }
172 rtnl_unlock();
173 return ret;
174}
175
133static ssize_t show_dormant(struct device *dev, 176static ssize_t show_dormant(struct device *dev,
134 struct device_attribute *attr, char *buf) 177 struct device_attribute *attr, char *buf)
135{ 178{
@@ -259,6 +302,8 @@ static struct device_attribute net_class_attributes[] = {
259 __ATTR(address, S_IRUGO, show_address, NULL), 302 __ATTR(address, S_IRUGO, show_address, NULL),
260 __ATTR(broadcast, S_IRUGO, show_broadcast, NULL), 303 __ATTR(broadcast, S_IRUGO, show_broadcast, NULL),
261 __ATTR(carrier, S_IRUGO, show_carrier, NULL), 304 __ATTR(carrier, S_IRUGO, show_carrier, NULL),
305 __ATTR(speed, S_IRUGO, show_speed, NULL),
306 __ATTR(duplex, S_IRUGO, show_duplex, NULL),
262 __ATTR(dormant, S_IRUGO, show_dormant, NULL), 307 __ATTR(dormant, S_IRUGO, show_dormant, NULL),
263 __ATTR(operstate, S_IRUGO, show_operstate, NULL), 308 __ATTR(operstate, S_IRUGO, show_operstate, NULL),
264 __ATTR(mtu, S_IRUGO | S_IWUSR, show_mtu, store_mtu), 309 __ATTR(mtu, S_IRUGO | S_IWUSR, show_mtu, store_mtu),
@@ -366,7 +411,8 @@ static ssize_t wireless_show(struct device *d, char *buf,
366 const struct iw_statistics *iw; 411 const struct iw_statistics *iw;
367 ssize_t ret = -EINVAL; 412 ssize_t ret = -EINVAL;
368 413
369 rtnl_lock(); 414 if (!rtnl_trylock())
415 return restart_syscall();
370 if (dev_isalive(dev)) { 416 if (dev_isalive(dev)) {
371 iw = get_wireless_stats(dev); 417 iw = get_wireless_stats(dev);
372 if (iw) 418 if (iw)
@@ -481,7 +527,7 @@ void netdev_unregister_kobject(struct net_device * net)
481 527
482 kobject_get(&dev->kobj); 528 kobject_get(&dev->kobj);
483 529
484 if (dev_net(net) != &init_net) 530 if (!net_eq(dev_net(net), &init_net))
485 return; 531 return;
486 532
487 device_del(dev); 533 device_del(dev);
@@ -500,15 +546,22 @@ int netdev_register_kobject(struct net_device *net)
500 dev_set_name(dev, "%s", net->name); 546 dev_set_name(dev, "%s", net->name);
501 547
502#ifdef CONFIG_SYSFS 548#ifdef CONFIG_SYSFS
503 *groups++ = &netstat_group; 549 /* Allow for a device specific group */
550 if (*groups)
551 groups++;
504 552
553 *groups++ = &netstat_group;
505#ifdef CONFIG_WIRELESS_EXT_SYSFS 554#ifdef CONFIG_WIRELESS_EXT_SYSFS
506 if (net->wireless_handlers || net->ieee80211_ptr) 555 if (net->ieee80211_ptr)
507 *groups++ = &wireless_group; 556 *groups++ = &wireless_group;
557#ifdef CONFIG_WIRELESS_EXT
558 else if (net->wireless_handlers)
559 *groups++ = &wireless_group;
560#endif
508#endif 561#endif
509#endif /* CONFIG_SYSFS */ 562#endif /* CONFIG_SYSFS */
510 563
511 if (dev_net(net) != &init_net) 564 if (!net_eq(dev_net(net), &init_net))
512 return 0; 565 return 0;
513 566
514 return device_add(dev); 567 return device_add(dev);
diff --git a/net/core/net-traces.c b/net/core/net-traces.c
index f1e982c508bb..afa6380ed88a 100644
--- a/net/core/net-traces.c
+++ b/net/core/net-traces.c
@@ -19,6 +19,7 @@
19#include <linux/workqueue.h> 19#include <linux/workqueue.h>
20#include <linux/netlink.h> 20#include <linux/netlink.h>
21#include <linux/net_dropmon.h> 21#include <linux/net_dropmon.h>
22#include <linux/slab.h>
22 23
23#include <asm/unaligned.h> 24#include <asm/unaligned.h>
24#include <asm/bitops.h> 25#include <asm/bitops.h>
diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
index 1c1af2756f38..bd8c4712ea24 100644
--- a/net/core/net_namespace.c
+++ b/net/core/net_namespace.c
@@ -27,14 +27,64 @@ EXPORT_SYMBOL(init_net);
27 27
28#define INITIAL_NET_GEN_PTRS 13 /* +1 for len +2 for rcu_head */ 28#define INITIAL_NET_GEN_PTRS 13 /* +1 for len +2 for rcu_head */
29 29
30static int ops_init(const struct pernet_operations *ops, struct net *net)
31{
32 int err;
33 if (ops->id && ops->size) {
34 void *data = kzalloc(ops->size, GFP_KERNEL);
35 if (!data)
36 return -ENOMEM;
37
38 err = net_assign_generic(net, *ops->id, data);
39 if (err) {
40 kfree(data);
41 return err;
42 }
43 }
44 if (ops->init)
45 return ops->init(net);
46 return 0;
47}
48
49static void ops_free(const struct pernet_operations *ops, struct net *net)
50{
51 if (ops->id && ops->size) {
52 int id = *ops->id;
53 kfree(net_generic(net, id));
54 }
55}
56
57static void ops_exit_list(const struct pernet_operations *ops,
58 struct list_head *net_exit_list)
59{
60 struct net *net;
61 if (ops->exit) {
62 list_for_each_entry(net, net_exit_list, exit_list)
63 ops->exit(net);
64 }
65 if (ops->exit_batch)
66 ops->exit_batch(net_exit_list);
67}
68
69static void ops_free_list(const struct pernet_operations *ops,
70 struct list_head *net_exit_list)
71{
72 struct net *net;
73 if (ops->size && ops->id) {
74 list_for_each_entry(net, net_exit_list, exit_list)
75 ops_free(ops, net);
76 }
77}
78
30/* 79/*
31 * setup_net runs the initializers for the network namespace object. 80 * setup_net runs the initializers for the network namespace object.
32 */ 81 */
33static __net_init int setup_net(struct net *net) 82static __net_init int setup_net(struct net *net)
34{ 83{
35 /* Must be called with net_mutex held */ 84 /* Must be called with net_mutex held */
36 struct pernet_operations *ops; 85 const struct pernet_operations *ops, *saved_ops;
37 int error = 0; 86 int error = 0;
87 LIST_HEAD(net_exit_list);
38 88
39 atomic_set(&net->count, 1); 89 atomic_set(&net->count, 1);
40 90
@@ -43,11 +93,9 @@ static __net_init int setup_net(struct net *net)
43#endif 93#endif
44 94
45 list_for_each_entry(ops, &pernet_list, list) { 95 list_for_each_entry(ops, &pernet_list, list) {
46 if (ops->init) { 96 error = ops_init(ops, net);
47 error = ops->init(net); 97 if (error < 0)
48 if (error < 0) 98 goto out_undo;
49 goto out_undo;
50 }
51 } 99 }
52out: 100out:
53 return error; 101 return error;
@@ -56,10 +104,14 @@ out_undo:
56 /* Walk through the list backwards calling the exit functions 104 /* Walk through the list backwards calling the exit functions
57 * for the pernet modules whose init functions did not fail. 105 * for the pernet modules whose init functions did not fail.
58 */ 106 */
59 list_for_each_entry_continue_reverse(ops, &pernet_list, list) { 107 list_add(&net->exit_list, &net_exit_list);
60 if (ops->exit) 108 saved_ops = ops;
61 ops->exit(net); 109 list_for_each_entry_continue_reverse(ops, &pernet_list, list)
62 } 110 ops_exit_list(ops, &net_exit_list);
111
112 ops = saved_ops;
113 list_for_each_entry_continue_reverse(ops, &pernet_list, list)
114 ops_free_list(ops, &net_exit_list);
63 115
64 rcu_barrier(); 116 rcu_barrier();
65 goto out; 117 goto out;
@@ -147,18 +199,29 @@ struct net *copy_net_ns(unsigned long flags, struct net *old_net)
147 return net_create(); 199 return net_create();
148} 200}
149 201
202static DEFINE_SPINLOCK(cleanup_list_lock);
203static LIST_HEAD(cleanup_list); /* Must hold cleanup_list_lock to touch */
204
150static void cleanup_net(struct work_struct *work) 205static void cleanup_net(struct work_struct *work)
151{ 206{
152 struct pernet_operations *ops; 207 const struct pernet_operations *ops;
153 struct net *net; 208 struct net *net, *tmp;
209 LIST_HEAD(net_kill_list);
210 LIST_HEAD(net_exit_list);
154 211
155 net = container_of(work, struct net, work); 212 /* Atomically snapshot the list of namespaces to cleanup */
213 spin_lock_irq(&cleanup_list_lock);
214 list_replace_init(&cleanup_list, &net_kill_list);
215 spin_unlock_irq(&cleanup_list_lock);
156 216
157 mutex_lock(&net_mutex); 217 mutex_lock(&net_mutex);
158 218
159 /* Don't let anyone else find us. */ 219 /* Don't let anyone else find us. */
160 rtnl_lock(); 220 rtnl_lock();
161 list_del_rcu(&net->list); 221 list_for_each_entry(net, &net_kill_list, cleanup_list) {
222 list_del_rcu(&net->list);
223 list_add_tail(&net->exit_list, &net_exit_list);
224 }
162 rtnl_unlock(); 225 rtnl_unlock();
163 226
164 /* 227 /*
@@ -169,10 +232,12 @@ static void cleanup_net(struct work_struct *work)
169 synchronize_rcu(); 232 synchronize_rcu();
170 233
171 /* Run all of the network namespace exit methods */ 234 /* Run all of the network namespace exit methods */
172 list_for_each_entry_reverse(ops, &pernet_list, list) { 235 list_for_each_entry_reverse(ops, &pernet_list, list)
173 if (ops->exit) 236 ops_exit_list(ops, &net_exit_list);
174 ops->exit(net); 237
175 } 238 /* Free the net generic variables */
239 list_for_each_entry_reverse(ops, &pernet_list, list)
240 ops_free_list(ops, &net_exit_list);
176 241
177 mutex_unlock(&net_mutex); 242 mutex_unlock(&net_mutex);
178 243
@@ -182,14 +247,23 @@ static void cleanup_net(struct work_struct *work)
182 rcu_barrier(); 247 rcu_barrier();
183 248
184 /* Finally it is safe to free my network namespace structure */ 249 /* Finally it is safe to free my network namespace structure */
185 net_free(net); 250 list_for_each_entry_safe(net, tmp, &net_exit_list, exit_list) {
251 list_del_init(&net->exit_list);
252 net_free(net);
253 }
186} 254}
255static DECLARE_WORK(net_cleanup_work, cleanup_net);
187 256
188void __put_net(struct net *net) 257void __put_net(struct net *net)
189{ 258{
190 /* Cleanup the network namespace in process context */ 259 /* Cleanup the network namespace in process context */
191 INIT_WORK(&net->work, cleanup_net); 260 unsigned long flags;
192 queue_work(netns_wq, &net->work); 261
262 spin_lock_irqsave(&cleanup_list_lock, flags);
263 list_add(&net->cleanup_list, &cleanup_list);
264 spin_unlock_irqrestore(&cleanup_list_lock, flags);
265
266 queue_work(netns_wq, &net_cleanup_work);
193} 267}
194EXPORT_SYMBOL_GPL(__put_net); 268EXPORT_SYMBOL_GPL(__put_net);
195 269
@@ -259,18 +333,20 @@ static int __init net_ns_init(void)
259pure_initcall(net_ns_init); 333pure_initcall(net_ns_init);
260 334
261#ifdef CONFIG_NET_NS 335#ifdef CONFIG_NET_NS
262static int register_pernet_operations(struct list_head *list, 336static int __register_pernet_operations(struct list_head *list,
263 struct pernet_operations *ops) 337 struct pernet_operations *ops)
264{ 338{
265 struct net *net, *undo_net; 339 struct net *net;
266 int error; 340 int error;
341 LIST_HEAD(net_exit_list);
267 342
268 list_add_tail(&ops->list, list); 343 list_add_tail(&ops->list, list);
269 if (ops->init) { 344 if (ops->init || (ops->id && ops->size)) {
270 for_each_net(net) { 345 for_each_net(net) {
271 error = ops->init(net); 346 error = ops_init(ops, net);
272 if (error) 347 if (error)
273 goto out_undo; 348 goto out_undo;
349 list_add_tail(&net->exit_list, &net_exit_list);
274 } 350 }
275 } 351 }
276 return 0; 352 return 0;
@@ -278,45 +354,82 @@ static int register_pernet_operations(struct list_head *list,
278out_undo: 354out_undo:
279 /* If I have an error cleanup all namespaces I initialized */ 355 /* If I have an error cleanup all namespaces I initialized */
280 list_del(&ops->list); 356 list_del(&ops->list);
281 if (ops->exit) { 357 ops_exit_list(ops, &net_exit_list);
282 for_each_net(undo_net) { 358 ops_free_list(ops, &net_exit_list);
283 if (undo_net == net)
284 goto undone;
285 ops->exit(undo_net);
286 }
287 }
288undone:
289 return error; 359 return error;
290} 360}
291 361
292static void unregister_pernet_operations(struct pernet_operations *ops) 362static void __unregister_pernet_operations(struct pernet_operations *ops)
293{ 363{
294 struct net *net; 364 struct net *net;
365 LIST_HEAD(net_exit_list);
295 366
296 list_del(&ops->list); 367 list_del(&ops->list);
297 if (ops->exit) 368 for_each_net(net)
298 for_each_net(net) 369 list_add_tail(&net->exit_list, &net_exit_list);
299 ops->exit(net); 370 ops_exit_list(ops, &net_exit_list);
371 ops_free_list(ops, &net_exit_list);
300} 372}
301 373
302#else 374#else
303 375
376static int __register_pernet_operations(struct list_head *list,
377 struct pernet_operations *ops)
378{
379 int err = 0;
380 err = ops_init(ops, &init_net);
381 if (err)
382 ops_free(ops, &init_net);
383 return err;
384
385}
386
387static void __unregister_pernet_operations(struct pernet_operations *ops)
388{
389 LIST_HEAD(net_exit_list);
390 list_add(&init_net.exit_list, &net_exit_list);
391 ops_exit_list(ops, &net_exit_list);
392 ops_free_list(ops, &net_exit_list);
393}
394
395#endif /* CONFIG_NET_NS */
396
397static DEFINE_IDA(net_generic_ids);
398
304static int register_pernet_operations(struct list_head *list, 399static int register_pernet_operations(struct list_head *list,
305 struct pernet_operations *ops) 400 struct pernet_operations *ops)
306{ 401{
307 if (ops->init == NULL) 402 int error;
308 return 0; 403
309 return ops->init(&init_net); 404 if (ops->id) {
405again:
406 error = ida_get_new_above(&net_generic_ids, 1, ops->id);
407 if (error < 0) {
408 if (error == -EAGAIN) {
409 ida_pre_get(&net_generic_ids, GFP_KERNEL);
410 goto again;
411 }
412 return error;
413 }
414 }
415 error = __register_pernet_operations(list, ops);
416 if (error) {
417 rcu_barrier();
418 if (ops->id)
419 ida_remove(&net_generic_ids, *ops->id);
420 }
421
422 return error;
310} 423}
311 424
312static void unregister_pernet_operations(struct pernet_operations *ops) 425static void unregister_pernet_operations(struct pernet_operations *ops)
313{ 426{
314 if (ops->exit) 427
315 ops->exit(&init_net); 428 __unregister_pernet_operations(ops);
429 rcu_barrier();
430 if (ops->id)
431 ida_remove(&net_generic_ids, *ops->id);
316} 432}
317#endif
318
319static DEFINE_IDA(net_generic_ids);
320 433
321/** 434/**
322 * register_pernet_subsys - register a network namespace subsystem 435 * register_pernet_subsys - register a network namespace subsystem
@@ -364,38 +477,6 @@ void unregister_pernet_subsys(struct pernet_operations *module)
364} 477}
365EXPORT_SYMBOL_GPL(unregister_pernet_subsys); 478EXPORT_SYMBOL_GPL(unregister_pernet_subsys);
366 479
367int register_pernet_gen_subsys(int *id, struct pernet_operations *ops)
368{
369 int rv;
370
371 mutex_lock(&net_mutex);
372again:
373 rv = ida_get_new_above(&net_generic_ids, 1, id);
374 if (rv < 0) {
375 if (rv == -EAGAIN) {
376 ida_pre_get(&net_generic_ids, GFP_KERNEL);
377 goto again;
378 }
379 goto out;
380 }
381 rv = register_pernet_operations(first_device, ops);
382 if (rv < 0)
383 ida_remove(&net_generic_ids, *id);
384out:
385 mutex_unlock(&net_mutex);
386 return rv;
387}
388EXPORT_SYMBOL_GPL(register_pernet_gen_subsys);
389
390void unregister_pernet_gen_subsys(int id, struct pernet_operations *ops)
391{
392 mutex_lock(&net_mutex);
393 unregister_pernet_operations(ops);
394 ida_remove(&net_generic_ids, id);
395 mutex_unlock(&net_mutex);
396}
397EXPORT_SYMBOL_GPL(unregister_pernet_gen_subsys);
398
399/** 480/**
400 * register_pernet_device - register a network namespace device 481 * register_pernet_device - register a network namespace device
401 * @ops: pernet operations structure for the subsystem 482 * @ops: pernet operations structure for the subsystem
@@ -427,30 +508,6 @@ int register_pernet_device(struct pernet_operations *ops)
427} 508}
428EXPORT_SYMBOL_GPL(register_pernet_device); 509EXPORT_SYMBOL_GPL(register_pernet_device);
429 510
430int register_pernet_gen_device(int *id, struct pernet_operations *ops)
431{
432 int error;
433 mutex_lock(&net_mutex);
434again:
435 error = ida_get_new_above(&net_generic_ids, 1, id);
436 if (error) {
437 if (error == -EAGAIN) {
438 ida_pre_get(&net_generic_ids, GFP_KERNEL);
439 goto again;
440 }
441 goto out;
442 }
443 error = register_pernet_operations(&pernet_list, ops);
444 if (error)
445 ida_remove(&net_generic_ids, *id);
446 else if (first_device == &pernet_list)
447 first_device = &ops->list;
448out:
449 mutex_unlock(&net_mutex);
450 return error;
451}
452EXPORT_SYMBOL_GPL(register_pernet_gen_device);
453
454/** 511/**
455 * unregister_pernet_device - unregister a network namespace netdevice 512 * unregister_pernet_device - unregister a network namespace netdevice
456 * @ops: pernet operations structure to manipulate 513 * @ops: pernet operations structure to manipulate
@@ -470,17 +527,6 @@ void unregister_pernet_device(struct pernet_operations *ops)
470} 527}
471EXPORT_SYMBOL_GPL(unregister_pernet_device); 528EXPORT_SYMBOL_GPL(unregister_pernet_device);
472 529
473void unregister_pernet_gen_device(int id, struct pernet_operations *ops)
474{
475 mutex_lock(&net_mutex);
476 if (&ops->list == first_device)
477 first_device = first_device->next;
478 unregister_pernet_operations(ops);
479 ida_remove(&net_generic_ids, id);
480 mutex_unlock(&net_mutex);
481}
482EXPORT_SYMBOL_GPL(unregister_pernet_gen_device);
483
484static void net_generic_release(struct rcu_head *rcu) 530static void net_generic_release(struct rcu_head *rcu)
485{ 531{
486 struct net_generic *ng; 532 struct net_generic *ng;
diff --git a/net/core/netpoll.c b/net/core/netpoll.c
index 0b4d0d35ef40..a58f59b97597 100644
--- a/net/core/netpoll.c
+++ b/net/core/netpoll.c
@@ -22,6 +22,7 @@
22#include <linux/delay.h> 22#include <linux/delay.h>
23#include <linux/rcupdate.h> 23#include <linux/rcupdate.h>
24#include <linux/workqueue.h> 24#include <linux/workqueue.h>
25#include <linux/slab.h>
25#include <net/tcp.h> 26#include <net/tcp.h>
26#include <net/udp.h> 27#include <net/udp.h>
27#include <asm/unaligned.h> 28#include <asm/unaligned.h>
@@ -407,11 +408,24 @@ static void arp_reply(struct sk_buff *skb)
407 __be32 sip, tip; 408 __be32 sip, tip;
408 unsigned char *sha; 409 unsigned char *sha;
409 struct sk_buff *send_skb; 410 struct sk_buff *send_skb;
410 struct netpoll *np = NULL; 411 struct netpoll *np, *tmp;
412 unsigned long flags;
413 int hits = 0;
414
415 if (list_empty(&npinfo->rx_np))
416 return;
417
418 /* Before checking the packet, we do some early
419 inspection whether this is interesting at all */
420 spin_lock_irqsave(&npinfo->rx_lock, flags);
421 list_for_each_entry_safe(np, tmp, &npinfo->rx_np, rx) {
422 if (np->dev == skb->dev)
423 hits++;
424 }
425 spin_unlock_irqrestore(&npinfo->rx_lock, flags);
411 426
412 if (npinfo->rx_np && npinfo->rx_np->dev == skb->dev) 427 /* No netpoll struct is using this dev */
413 np = npinfo->rx_np; 428 if (!hits)
414 if (!np)
415 return; 429 return;
416 430
417 /* No arp on this interface */ 431 /* No arp on this interface */
@@ -437,77 +451,91 @@ static void arp_reply(struct sk_buff *skb)
437 arp_ptr += skb->dev->addr_len; 451 arp_ptr += skb->dev->addr_len;
438 memcpy(&sip, arp_ptr, 4); 452 memcpy(&sip, arp_ptr, 4);
439 arp_ptr += 4; 453 arp_ptr += 4;
440 /* if we actually cared about dst hw addr, it would get copied here */ 454 /* If we actually cared about dst hw addr,
455 it would get copied here */
441 arp_ptr += skb->dev->addr_len; 456 arp_ptr += skb->dev->addr_len;
442 memcpy(&tip, arp_ptr, 4); 457 memcpy(&tip, arp_ptr, 4);
443 458
444 /* Should we ignore arp? */ 459 /* Should we ignore arp? */
445 if (tip != np->local_ip || 460 if (ipv4_is_loopback(tip) || ipv4_is_multicast(tip))
446 ipv4_is_loopback(tip) || ipv4_is_multicast(tip))
447 return; 461 return;
448 462
449 size = arp_hdr_len(skb->dev); 463 size = arp_hdr_len(skb->dev);
450 send_skb = find_skb(np, size + LL_ALLOCATED_SPACE(np->dev),
451 LL_RESERVED_SPACE(np->dev));
452 464
453 if (!send_skb) 465 spin_lock_irqsave(&npinfo->rx_lock, flags);
454 return; 466 list_for_each_entry_safe(np, tmp, &npinfo->rx_np, rx) {
455 467 if (tip != np->local_ip)
456 skb_reset_network_header(send_skb); 468 continue;
457 arp = (struct arphdr *) skb_put(send_skb, size);
458 send_skb->dev = skb->dev;
459 send_skb->protocol = htons(ETH_P_ARP);
460 469
461 /* Fill the device header for the ARP frame */ 470 send_skb = find_skb(np, size + LL_ALLOCATED_SPACE(np->dev),
462 if (dev_hard_header(send_skb, skb->dev, ptype, 471 LL_RESERVED_SPACE(np->dev));
463 sha, np->dev->dev_addr, 472 if (!send_skb)
464 send_skb->len) < 0) { 473 continue;
465 kfree_skb(send_skb);
466 return;
467 }
468 474
469 /* 475 skb_reset_network_header(send_skb);
470 * Fill out the arp protocol part. 476 arp = (struct arphdr *) skb_put(send_skb, size);
471 * 477 send_skb->dev = skb->dev;
472 * we only support ethernet device type, 478 send_skb->protocol = htons(ETH_P_ARP);
473 * which (according to RFC 1390) should always equal 1 (Ethernet).
474 */
475 479
476 arp->ar_hrd = htons(np->dev->type); 480 /* Fill the device header for the ARP frame */
477 arp->ar_pro = htons(ETH_P_IP); 481 if (dev_hard_header(send_skb, skb->dev, ptype,
478 arp->ar_hln = np->dev->addr_len; 482 sha, np->dev->dev_addr,
479 arp->ar_pln = 4; 483 send_skb->len) < 0) {
480 arp->ar_op = htons(type); 484 kfree_skb(send_skb);
485 continue;
486 }
481 487
482 arp_ptr=(unsigned char *)(arp + 1); 488 /*
483 memcpy(arp_ptr, np->dev->dev_addr, np->dev->addr_len); 489 * Fill out the arp protocol part.
484 arp_ptr += np->dev->addr_len; 490 *
485 memcpy(arp_ptr, &tip, 4); 491 * we only support ethernet device type,
486 arp_ptr += 4; 492 * which (according to RFC 1390) should
487 memcpy(arp_ptr, sha, np->dev->addr_len); 493 * always equal 1 (Ethernet).
488 arp_ptr += np->dev->addr_len; 494 */
489 memcpy(arp_ptr, &sip, 4);
490 495
491 netpoll_send_skb(np, send_skb); 496 arp->ar_hrd = htons(np->dev->type);
497 arp->ar_pro = htons(ETH_P_IP);
498 arp->ar_hln = np->dev->addr_len;
499 arp->ar_pln = 4;
500 arp->ar_op = htons(type);
501
502 arp_ptr = (unsigned char *)(arp + 1);
503 memcpy(arp_ptr, np->dev->dev_addr, np->dev->addr_len);
504 arp_ptr += np->dev->addr_len;
505 memcpy(arp_ptr, &tip, 4);
506 arp_ptr += 4;
507 memcpy(arp_ptr, sha, np->dev->addr_len);
508 arp_ptr += np->dev->addr_len;
509 memcpy(arp_ptr, &sip, 4);
510
511 netpoll_send_skb(np, send_skb);
512
513 /* If there are several rx_hooks for the same address,
514 we're fine by sending a single reply */
515 break;
516 }
517 spin_unlock_irqrestore(&npinfo->rx_lock, flags);
492} 518}
493 519
494int __netpoll_rx(struct sk_buff *skb) 520int __netpoll_rx(struct sk_buff *skb)
495{ 521{
496 int proto, len, ulen; 522 int proto, len, ulen;
523 int hits = 0;
497 struct iphdr *iph; 524 struct iphdr *iph;
498 struct udphdr *uh; 525 struct udphdr *uh;
499 struct netpoll_info *npi = skb->dev->npinfo; 526 struct netpoll_info *npinfo = skb->dev->npinfo;
500 struct netpoll *np = npi->rx_np; 527 struct netpoll *np, *tmp;
501 528
502 if (!np) 529 if (list_empty(&npinfo->rx_np))
503 goto out; 530 goto out;
531
504 if (skb->dev->type != ARPHRD_ETHER) 532 if (skb->dev->type != ARPHRD_ETHER)
505 goto out; 533 goto out;
506 534
507 /* check if netpoll clients need ARP */ 535 /* check if netpoll clients need ARP */
508 if (skb->protocol == htons(ETH_P_ARP) && 536 if (skb->protocol == htons(ETH_P_ARP) &&
509 atomic_read(&trapped)) { 537 atomic_read(&trapped)) {
510 skb_queue_tail(&npi->arp_tx, skb); 538 skb_queue_tail(&npinfo->arp_tx, skb);
511 return 1; 539 return 1;
512 } 540 }
513 541
@@ -551,16 +579,23 @@ int __netpoll_rx(struct sk_buff *skb)
551 goto out; 579 goto out;
552 if (checksum_udp(skb, uh, ulen, iph->saddr, iph->daddr)) 580 if (checksum_udp(skb, uh, ulen, iph->saddr, iph->daddr))
553 goto out; 581 goto out;
554 if (np->local_ip && np->local_ip != iph->daddr)
555 goto out;
556 if (np->remote_ip && np->remote_ip != iph->saddr)
557 goto out;
558 if (np->local_port && np->local_port != ntohs(uh->dest))
559 goto out;
560 582
561 np->rx_hook(np, ntohs(uh->source), 583 list_for_each_entry_safe(np, tmp, &npinfo->rx_np, rx) {
562 (char *)(uh+1), 584 if (np->local_ip && np->local_ip != iph->daddr)
563 ulen - sizeof(struct udphdr)); 585 continue;
586 if (np->remote_ip && np->remote_ip != iph->saddr)
587 continue;
588 if (np->local_port && np->local_port != ntohs(uh->dest))
589 continue;
590
591 np->rx_hook(np, ntohs(uh->source),
592 (char *)(uh+1),
593 ulen - sizeof(struct udphdr));
594 hits++;
595 }
596
597 if (!hits)
598 goto out;
564 599
565 kfree_skb(skb); 600 kfree_skb(skb);
566 return 1; 601 return 1;
@@ -580,7 +615,7 @@ void netpoll_print_options(struct netpoll *np)
580 np->name, np->local_port); 615 np->name, np->local_port);
581 printk(KERN_INFO "%s: local IP %pI4\n", 616 printk(KERN_INFO "%s: local IP %pI4\n",
582 np->name, &np->local_ip); 617 np->name, &np->local_ip);
583 printk(KERN_INFO "%s: interface %s\n", 618 printk(KERN_INFO "%s: interface '%s'\n",
584 np->name, np->dev_name); 619 np->name, np->dev_name);
585 printk(KERN_INFO "%s: remote port %d\n", 620 printk(KERN_INFO "%s: remote port %d\n",
586 np->name, np->remote_port); 621 np->name, np->remote_port);
@@ -627,6 +662,9 @@ int netpoll_parse_options(struct netpoll *np, char *opt)
627 if ((delim = strchr(cur, '@')) == NULL) 662 if ((delim = strchr(cur, '@')) == NULL)
628 goto parse_failed; 663 goto parse_failed;
629 *delim = 0; 664 *delim = 0;
665 if (*cur == ' ' || *cur == '\t')
666 printk(KERN_INFO "%s: warning: whitespace"
667 "is not allowed\n", np->name);
630 np->remote_port = simple_strtol(cur, NULL, 10); 668 np->remote_port = simple_strtol(cur, NULL, 10);
631 cur = delim; 669 cur = delim;
632 } 670 }
@@ -674,7 +712,7 @@ int netpoll_parse_options(struct netpoll *np, char *opt)
674 return 0; 712 return 0;
675 713
676 parse_failed: 714 parse_failed:
677 printk(KERN_INFO "%s: couldn't parse config at %s!\n", 715 printk(KERN_INFO "%s: couldn't parse config at '%s'!\n",
678 np->name, cur); 716 np->name, cur);
679 return -1; 717 return -1;
680} 718}
@@ -684,6 +722,7 @@ int netpoll_setup(struct netpoll *np)
684 struct net_device *ndev = NULL; 722 struct net_device *ndev = NULL;
685 struct in_device *in_dev; 723 struct in_device *in_dev;
686 struct netpoll_info *npinfo; 724 struct netpoll_info *npinfo;
725 struct netpoll *npe, *tmp;
687 unsigned long flags; 726 unsigned long flags;
688 int err; 727 int err;
689 728
@@ -700,11 +739,11 @@ int netpoll_setup(struct netpoll *np)
700 npinfo = kmalloc(sizeof(*npinfo), GFP_KERNEL); 739 npinfo = kmalloc(sizeof(*npinfo), GFP_KERNEL);
701 if (!npinfo) { 740 if (!npinfo) {
702 err = -ENOMEM; 741 err = -ENOMEM;
703 goto release; 742 goto put;
704 } 743 }
705 744
706 npinfo->rx_flags = 0; 745 npinfo->rx_flags = 0;
707 npinfo->rx_np = NULL; 746 INIT_LIST_HEAD(&npinfo->rx_np);
708 747
709 spin_lock_init(&npinfo->rx_lock); 748 spin_lock_init(&npinfo->rx_lock);
710 skb_queue_head_init(&npinfo->arp_tx); 749 skb_queue_head_init(&npinfo->arp_tx);
@@ -785,7 +824,7 @@ int netpoll_setup(struct netpoll *np)
785 if (np->rx_hook) { 824 if (np->rx_hook) {
786 spin_lock_irqsave(&npinfo->rx_lock, flags); 825 spin_lock_irqsave(&npinfo->rx_lock, flags);
787 npinfo->rx_flags |= NETPOLL_RX_ENABLED; 826 npinfo->rx_flags |= NETPOLL_RX_ENABLED;
788 npinfo->rx_np = np; 827 list_add_tail(&np->rx, &npinfo->rx_np);
789 spin_unlock_irqrestore(&npinfo->rx_lock, flags); 828 spin_unlock_irqrestore(&npinfo->rx_lock, flags);
790 } 829 }
791 830
@@ -801,9 +840,16 @@ int netpoll_setup(struct netpoll *np)
801 return 0; 840 return 0;
802 841
803 release: 842 release:
804 if (!ndev->npinfo) 843 if (!ndev->npinfo) {
844 spin_lock_irqsave(&npinfo->rx_lock, flags);
845 list_for_each_entry_safe(npe, tmp, &npinfo->rx_np, rx) {
846 npe->dev = NULL;
847 }
848 spin_unlock_irqrestore(&npinfo->rx_lock, flags);
849
805 kfree(npinfo); 850 kfree(npinfo);
806 np->dev = NULL; 851 }
852put:
807 dev_put(ndev); 853 dev_put(ndev);
808 return err; 854 return err;
809} 855}
@@ -823,10 +869,11 @@ void netpoll_cleanup(struct netpoll *np)
823 if (np->dev) { 869 if (np->dev) {
824 npinfo = np->dev->npinfo; 870 npinfo = np->dev->npinfo;
825 if (npinfo) { 871 if (npinfo) {
826 if (npinfo->rx_np == np) { 872 if (!list_empty(&npinfo->rx_np)) {
827 spin_lock_irqsave(&npinfo->rx_lock, flags); 873 spin_lock_irqsave(&npinfo->rx_lock, flags);
828 npinfo->rx_np = NULL; 874 list_del(&np->rx);
829 npinfo->rx_flags &= ~NETPOLL_RX_ENABLED; 875 if (list_empty(&npinfo->rx_np))
876 npinfo->rx_flags &= ~NETPOLL_RX_ENABLED;
830 spin_unlock_irqrestore(&npinfo->rx_lock, flags); 877 spin_unlock_irqrestore(&npinfo->rx_lock, flags);
831 } 878 }
832 879
diff --git a/net/core/pktgen.c b/net/core/pktgen.c
index 6e79e96cb4f2..43923811bd6a 100644
--- a/net/core/pktgen.c
+++ b/net/core/pktgen.c
@@ -250,8 +250,7 @@ struct pktgen_dev {
250 __u64 count; /* Default No packets to send */ 250 __u64 count; /* Default No packets to send */
251 __u64 sofar; /* How many pkts we've sent so far */ 251 __u64 sofar; /* How many pkts we've sent so far */
252 __u64 tx_bytes; /* How many bytes we've transmitted */ 252 __u64 tx_bytes; /* How many bytes we've transmitted */
253 __u64 errors; /* Errors when trying to transmit, 253 __u64 errors; /* Errors when trying to transmit, */
254 pkts will be re-sent */
255 254
256 /* runtime counters relating to clone_skb */ 255 /* runtime counters relating to clone_skb */
257 256
@@ -340,6 +339,7 @@ struct pktgen_dev {
340 __u16 cur_udp_src; 339 __u16 cur_udp_src;
341 __u16 cur_queue_map; 340 __u16 cur_queue_map;
342 __u32 cur_pkt_size; 341 __u32 cur_pkt_size;
342 __u32 last_pkt_size;
343 343
344 __u8 hh[14]; 344 __u8 hh[14];
345 /* = { 345 /* = {
@@ -2051,9 +2051,8 @@ static void pktgen_setup_inject(struct pktgen_dev *pkt_dev)
2051 read_lock_bh(&idev->lock); 2051 read_lock_bh(&idev->lock);
2052 for (ifp = idev->addr_list; ifp; 2052 for (ifp = idev->addr_list; ifp;
2053 ifp = ifp->if_next) { 2053 ifp = ifp->if_next) {
2054 if (ifp->scope == IFA_LINK 2054 if (ifp->scope == IFA_LINK &&
2055 && !(ifp-> 2055 !(ifp->flags & IFA_F_TENTATIVE)) {
2056 flags & IFA_F_TENTATIVE)) {
2057 ipv6_addr_copy(&pkt_dev-> 2056 ipv6_addr_copy(&pkt_dev->
2058 cur_in6_saddr, 2057 cur_in6_saddr,
2059 &ifp->addr); 2058 &ifp->addr);
@@ -2189,12 +2188,13 @@ static inline int f_pick(struct pktgen_dev *pkt_dev)
2189/* If there was already an IPSEC SA, we keep it as is, else 2188/* If there was already an IPSEC SA, we keep it as is, else
2190 * we go look for it ... 2189 * we go look for it ...
2191*/ 2190*/
2191#define DUMMY_MARK 0
2192static void get_ipsec_sa(struct pktgen_dev *pkt_dev, int flow) 2192static void get_ipsec_sa(struct pktgen_dev *pkt_dev, int flow)
2193{ 2193{
2194 struct xfrm_state *x = pkt_dev->flows[flow].x; 2194 struct xfrm_state *x = pkt_dev->flows[flow].x;
2195 if (!x) { 2195 if (!x) {
2196 /*slow path: we dont already have xfrm_state*/ 2196 /*slow path: we dont already have xfrm_state*/
2197 x = xfrm_stateonly_find(&init_net, 2197 x = xfrm_stateonly_find(&init_net, DUMMY_MARK,
2198 (xfrm_address_t *)&pkt_dev->cur_daddr, 2198 (xfrm_address_t *)&pkt_dev->cur_daddr,
2199 (xfrm_address_t *)&pkt_dev->cur_saddr, 2199 (xfrm_address_t *)&pkt_dev->cur_saddr,
2200 AF_INET, 2200 AF_INET,
@@ -3436,7 +3436,7 @@ static void pktgen_xmit(struct pktgen_dev *pkt_dev)
3436 pkt_dev->clone_count--; /* back out increment, OOM */ 3436 pkt_dev->clone_count--; /* back out increment, OOM */
3437 return; 3437 return;
3438 } 3438 }
3439 3439 pkt_dev->last_pkt_size = pkt_dev->skb->len;
3440 pkt_dev->allocated_skbs++; 3440 pkt_dev->allocated_skbs++;
3441 pkt_dev->clone_count = 0; /* reset counter */ 3441 pkt_dev->clone_count = 0; /* reset counter */
3442 } 3442 }
@@ -3448,12 +3448,14 @@ static void pktgen_xmit(struct pktgen_dev *pkt_dev)
3448 txq = netdev_get_tx_queue(odev, queue_map); 3448 txq = netdev_get_tx_queue(odev, queue_map);
3449 3449
3450 __netif_tx_lock_bh(txq); 3450 __netif_tx_lock_bh(txq);
3451 atomic_inc(&(pkt_dev->skb->users));
3452 3451
3453 if (unlikely(netif_tx_queue_stopped(txq) || netif_tx_queue_frozen(txq))) 3452 if (unlikely(netif_tx_queue_stopped(txq) || netif_tx_queue_frozen(txq))) {
3454 ret = NETDEV_TX_BUSY; 3453 ret = NETDEV_TX_BUSY;
3455 else 3454 pkt_dev->last_ok = 0;
3456 ret = (*xmit)(pkt_dev->skb, odev); 3455 goto unlock;
3456 }
3457 atomic_inc(&(pkt_dev->skb->users));
3458 ret = (*xmit)(pkt_dev->skb, odev);
3457 3459
3458 switch (ret) { 3460 switch (ret) {
3459 case NETDEV_TX_OK: 3461 case NETDEV_TX_OK:
@@ -3461,7 +3463,13 @@ static void pktgen_xmit(struct pktgen_dev *pkt_dev)
3461 pkt_dev->last_ok = 1; 3463 pkt_dev->last_ok = 1;
3462 pkt_dev->sofar++; 3464 pkt_dev->sofar++;
3463 pkt_dev->seq_num++; 3465 pkt_dev->seq_num++;
3464 pkt_dev->tx_bytes += pkt_dev->cur_pkt_size; 3466 pkt_dev->tx_bytes += pkt_dev->last_pkt_size;
3467 break;
3468 case NET_XMIT_DROP:
3469 case NET_XMIT_CN:
3470 case NET_XMIT_POLICED:
3471 /* skb has been consumed */
3472 pkt_dev->errors++;
3465 break; 3473 break;
3466 default: /* Drivers are not supposed to return other values! */ 3474 default: /* Drivers are not supposed to return other values! */
3467 if (net_ratelimit()) 3475 if (net_ratelimit())
@@ -3475,6 +3483,7 @@ static void pktgen_xmit(struct pktgen_dev *pkt_dev)
3475 atomic_dec(&(pkt_dev->skb->users)); 3483 atomic_dec(&(pkt_dev->skb->users));
3476 pkt_dev->last_ok = 0; 3484 pkt_dev->last_ok = 0;
3477 } 3485 }
3486unlock:
3478 __netif_tx_unlock_bh(txq); 3487 __netif_tx_unlock_bh(txq);
3479 3488
3480 /* If pkt_dev->count is zero, then run forever */ 3489 /* If pkt_dev->count is zero, then run forever */
@@ -3516,6 +3525,7 @@ static int pktgen_thread_worker(void *arg)
3516 wait_event_interruptible_timeout(t->queue, 3525 wait_event_interruptible_timeout(t->queue,
3517 t->control != 0, 3526 t->control != 0,
3518 HZ/10); 3527 HZ/10);
3528 try_to_freeze();
3519 continue; 3529 continue;
3520 } 3530 }
3521 3531
@@ -3622,6 +3632,7 @@ static int pktgen_add_device(struct pktgen_thread *t, const char *ifname)
3622{ 3632{
3623 struct pktgen_dev *pkt_dev; 3633 struct pktgen_dev *pkt_dev;
3624 int err; 3634 int err;
3635 int node = cpu_to_node(t->cpu);
3625 3636
3626 /* We don't allow a device to be on several threads */ 3637 /* We don't allow a device to be on several threads */
3627 3638
@@ -3631,12 +3642,13 @@ static int pktgen_add_device(struct pktgen_thread *t, const char *ifname)
3631 return -EBUSY; 3642 return -EBUSY;
3632 } 3643 }
3633 3644
3634 pkt_dev = kzalloc(sizeof(struct pktgen_dev), GFP_KERNEL); 3645 pkt_dev = kzalloc_node(sizeof(struct pktgen_dev), GFP_KERNEL, node);
3635 if (!pkt_dev) 3646 if (!pkt_dev)
3636 return -ENOMEM; 3647 return -ENOMEM;
3637 3648
3638 strcpy(pkt_dev->odevname, ifname); 3649 strcpy(pkt_dev->odevname, ifname);
3639 pkt_dev->flows = vmalloc(MAX_CFLOWS * sizeof(struct flow_state)); 3650 pkt_dev->flows = vmalloc_node(MAX_CFLOWS * sizeof(struct flow_state),
3651 node);
3640 if (pkt_dev->flows == NULL) { 3652 if (pkt_dev->flows == NULL) {
3641 kfree(pkt_dev); 3653 kfree(pkt_dev);
3642 return -ENOMEM; 3654 return -ENOMEM;
@@ -3698,7 +3710,8 @@ static int __init pktgen_create_thread(int cpu)
3698 struct proc_dir_entry *pe; 3710 struct proc_dir_entry *pe;
3699 struct task_struct *p; 3711 struct task_struct *p;
3700 3712
3701 t = kzalloc(sizeof(struct pktgen_thread), GFP_KERNEL); 3713 t = kzalloc_node(sizeof(struct pktgen_thread), GFP_KERNEL,
3714 cpu_to_node(cpu));
3702 if (!t) { 3715 if (!t) {
3703 printk(KERN_ERR "pktgen: ERROR: out of memory, can't " 3716 printk(KERN_ERR "pktgen: ERROR: out of memory, can't "
3704 "create new thread.\n"); 3717 "create new thread.\n");
diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
index eb42873f2a3a..31e85d327aa2 100644
--- a/net/core/rtnetlink.c
+++ b/net/core/rtnetlink.c
@@ -35,10 +35,10 @@
35#include <linux/security.h> 35#include <linux/security.h>
36#include <linux/mutex.h> 36#include <linux/mutex.h>
37#include <linux/if_addr.h> 37#include <linux/if_addr.h>
38#include <linux/pci.h>
38 39
39#include <asm/uaccess.h> 40#include <asm/uaccess.h>
40#include <asm/system.h> 41#include <asm/system.h>
41#include <asm/string.h>
42 42
43#include <linux/inet.h> 43#include <linux/inet.h>
44#include <linux/netdevice.h> 44#include <linux/netdevice.h>
@@ -53,8 +53,7 @@
53#include <net/rtnetlink.h> 53#include <net/rtnetlink.h>
54#include <net/net_namespace.h> 54#include <net/net_namespace.h>
55 55
56struct rtnl_link 56struct rtnl_link {
57{
58 rtnl_doit_func doit; 57 rtnl_doit_func doit;
59 rtnl_dumpit_func dumpit; 58 rtnl_dumpit_func dumpit;
60}; 59};
@@ -65,6 +64,7 @@ void rtnl_lock(void)
65{ 64{
66 mutex_lock(&rtnl_mutex); 65 mutex_lock(&rtnl_mutex);
67} 66}
67EXPORT_SYMBOL(rtnl_lock);
68 68
69void __rtnl_unlock(void) 69void __rtnl_unlock(void)
70{ 70{
@@ -76,16 +76,27 @@ void rtnl_unlock(void)
76 /* This fellow will unlock it for us. */ 76 /* This fellow will unlock it for us. */
77 netdev_run_todo(); 77 netdev_run_todo();
78} 78}
79EXPORT_SYMBOL(rtnl_unlock);
79 80
80int rtnl_trylock(void) 81int rtnl_trylock(void)
81{ 82{
82 return mutex_trylock(&rtnl_mutex); 83 return mutex_trylock(&rtnl_mutex);
83} 84}
85EXPORT_SYMBOL(rtnl_trylock);
84 86
85int rtnl_is_locked(void) 87int rtnl_is_locked(void)
86{ 88{
87 return mutex_is_locked(&rtnl_mutex); 89 return mutex_is_locked(&rtnl_mutex);
88} 90}
91EXPORT_SYMBOL(rtnl_is_locked);
92
93#ifdef CONFIG_PROVE_LOCKING
94int lockdep_rtnl_is_held(void)
95{
96 return lockdep_is_held(&rtnl_mutex);
97}
98EXPORT_SYMBOL(lockdep_rtnl_is_held);
99#endif /* #ifdef CONFIG_PROVE_LOCKING */
89 100
90static struct rtnl_link *rtnl_msg_handlers[NPROTO]; 101static struct rtnl_link *rtnl_msg_handlers[NPROTO];
91 102
@@ -168,7 +179,6 @@ int __rtnl_register(int protocol, int msgtype,
168 179
169 return 0; 180 return 0;
170} 181}
171
172EXPORT_SYMBOL_GPL(__rtnl_register); 182EXPORT_SYMBOL_GPL(__rtnl_register);
173 183
174/** 184/**
@@ -188,7 +198,6 @@ void rtnl_register(int protocol, int msgtype,
188 "protocol = %d, message type = %d\n", 198 "protocol = %d, message type = %d\n",
189 protocol, msgtype); 199 protocol, msgtype);
190} 200}
191
192EXPORT_SYMBOL_GPL(rtnl_register); 201EXPORT_SYMBOL_GPL(rtnl_register);
193 202
194/** 203/**
@@ -213,7 +222,6 @@ int rtnl_unregister(int protocol, int msgtype)
213 222
214 return 0; 223 return 0;
215} 224}
216
217EXPORT_SYMBOL_GPL(rtnl_unregister); 225EXPORT_SYMBOL_GPL(rtnl_unregister);
218 226
219/** 227/**
@@ -230,7 +238,6 @@ void rtnl_unregister_all(int protocol)
230 kfree(rtnl_msg_handlers[protocol]); 238 kfree(rtnl_msg_handlers[protocol]);
231 rtnl_msg_handlers[protocol] = NULL; 239 rtnl_msg_handlers[protocol] = NULL;
232} 240}
233
234EXPORT_SYMBOL_GPL(rtnl_unregister_all); 241EXPORT_SYMBOL_GPL(rtnl_unregister_all);
235 242
236static LIST_HEAD(link_ops); 243static LIST_HEAD(link_ops);
@@ -248,12 +255,11 @@ static LIST_HEAD(link_ops);
248int __rtnl_link_register(struct rtnl_link_ops *ops) 255int __rtnl_link_register(struct rtnl_link_ops *ops)
249{ 256{
250 if (!ops->dellink) 257 if (!ops->dellink)
251 ops->dellink = unregister_netdevice; 258 ops->dellink = unregister_netdevice_queue;
252 259
253 list_add_tail(&ops->list, &link_ops); 260 list_add_tail(&ops->list, &link_ops);
254 return 0; 261 return 0;
255} 262}
256
257EXPORT_SYMBOL_GPL(__rtnl_link_register); 263EXPORT_SYMBOL_GPL(__rtnl_link_register);
258 264
259/** 265/**
@@ -271,19 +277,18 @@ int rtnl_link_register(struct rtnl_link_ops *ops)
271 rtnl_unlock(); 277 rtnl_unlock();
272 return err; 278 return err;
273} 279}
274
275EXPORT_SYMBOL_GPL(rtnl_link_register); 280EXPORT_SYMBOL_GPL(rtnl_link_register);
276 281
277static void __rtnl_kill_links(struct net *net, struct rtnl_link_ops *ops) 282static void __rtnl_kill_links(struct net *net, struct rtnl_link_ops *ops)
278{ 283{
279 struct net_device *dev; 284 struct net_device *dev;
280restart: 285 LIST_HEAD(list_kill);
286
281 for_each_netdev(net, dev) { 287 for_each_netdev(net, dev) {
282 if (dev->rtnl_link_ops == ops) { 288 if (dev->rtnl_link_ops == ops)
283 ops->dellink(dev); 289 ops->dellink(dev, &list_kill);
284 goto restart;
285 }
286 } 290 }
291 unregister_netdevice_many(&list_kill);
287} 292}
288 293
289void rtnl_kill_links(struct net *net, struct rtnl_link_ops *ops) 294void rtnl_kill_links(struct net *net, struct rtnl_link_ops *ops)
@@ -309,7 +314,6 @@ void __rtnl_link_unregister(struct rtnl_link_ops *ops)
309 } 314 }
310 list_del(&ops->list); 315 list_del(&ops->list);
311} 316}
312
313EXPORT_SYMBOL_GPL(__rtnl_link_unregister); 317EXPORT_SYMBOL_GPL(__rtnl_link_unregister);
314 318
315/** 319/**
@@ -322,7 +326,6 @@ void rtnl_link_unregister(struct rtnl_link_ops *ops)
322 __rtnl_link_unregister(ops); 326 __rtnl_link_unregister(ops);
323 rtnl_unlock(); 327 rtnl_unlock();
324} 328}
325
326EXPORT_SYMBOL_GPL(rtnl_link_unregister); 329EXPORT_SYMBOL_GPL(rtnl_link_unregister);
327 330
328static const struct rtnl_link_ops *rtnl_link_ops_get(const char *kind) 331static const struct rtnl_link_ops *rtnl_link_ops_get(const char *kind)
@@ -427,12 +430,13 @@ void __rta_fill(struct sk_buff *skb, int attrtype, int attrlen, const void *data
427 struct rtattr *rta; 430 struct rtattr *rta;
428 int size = RTA_LENGTH(attrlen); 431 int size = RTA_LENGTH(attrlen);
429 432
430 rta = (struct rtattr*)skb_put(skb, RTA_ALIGN(size)); 433 rta = (struct rtattr *)skb_put(skb, RTA_ALIGN(size));
431 rta->rta_type = attrtype; 434 rta->rta_type = attrtype;
432 rta->rta_len = size; 435 rta->rta_len = size;
433 memcpy(RTA_DATA(rta), data, attrlen); 436 memcpy(RTA_DATA(rta), data, attrlen);
434 memset(RTA_DATA(rta) + attrlen, 0, RTA_ALIGN(size) - size); 437 memset(RTA_DATA(rta) + attrlen, 0, RTA_ALIGN(size) - size);
435} 438}
439EXPORT_SYMBOL(__rta_fill);
436 440
437int rtnetlink_send(struct sk_buff *skb, struct net *net, u32 pid, unsigned group, int echo) 441int rtnetlink_send(struct sk_buff *skb, struct net *net, u32 pid, unsigned group, int echo)
438{ 442{
@@ -454,6 +458,7 @@ int rtnl_unicast(struct sk_buff *skb, struct net *net, u32 pid)
454 458
455 return nlmsg_unicast(rtnl, skb, pid); 459 return nlmsg_unicast(rtnl, skb, pid);
456} 460}
461EXPORT_SYMBOL(rtnl_unicast);
457 462
458void rtnl_notify(struct sk_buff *skb, struct net *net, u32 pid, u32 group, 463void rtnl_notify(struct sk_buff *skb, struct net *net, u32 pid, u32 group,
459 struct nlmsghdr *nlh, gfp_t flags) 464 struct nlmsghdr *nlh, gfp_t flags)
@@ -466,6 +471,7 @@ void rtnl_notify(struct sk_buff *skb, struct net *net, u32 pid, u32 group,
466 471
467 nlmsg_notify(rtnl, skb, pid, group, report, flags); 472 nlmsg_notify(rtnl, skb, pid, group, report, flags);
468} 473}
474EXPORT_SYMBOL(rtnl_notify);
469 475
470void rtnl_set_sk_err(struct net *net, u32 group, int error) 476void rtnl_set_sk_err(struct net *net, u32 group, int error)
471{ 477{
@@ -473,6 +479,7 @@ void rtnl_set_sk_err(struct net *net, u32 group, int error)
473 479
474 netlink_set_err(rtnl, 0, group, error); 480 netlink_set_err(rtnl, 0, group, error);
475} 481}
482EXPORT_SYMBOL(rtnl_set_sk_err);
476 483
477int rtnetlink_put_metrics(struct sk_buff *skb, u32 *metrics) 484int rtnetlink_put_metrics(struct sk_buff *skb, u32 *metrics)
478{ 485{
@@ -501,6 +508,7 @@ nla_put_failure:
501 nla_nest_cancel(skb, mx); 508 nla_nest_cancel(skb, mx);
502 return -EMSGSIZE; 509 return -EMSGSIZE;
503} 510}
511EXPORT_SYMBOL(rtnetlink_put_metrics);
504 512
505int rtnl_put_cacheinfo(struct sk_buff *skb, struct dst_entry *dst, u32 id, 513int rtnl_put_cacheinfo(struct sk_buff *skb, struct dst_entry *dst, u32 id,
506 u32 ts, u32 tsage, long expires, u32 error) 514 u32 ts, u32 tsage, long expires, u32 error)
@@ -520,14 +528,13 @@ int rtnl_put_cacheinfo(struct sk_buff *skb, struct dst_entry *dst, u32 id,
520 528
521 return nla_put(skb, RTA_CACHEINFO, sizeof(ci), &ci); 529 return nla_put(skb, RTA_CACHEINFO, sizeof(ci), &ci);
522} 530}
523
524EXPORT_SYMBOL_GPL(rtnl_put_cacheinfo); 531EXPORT_SYMBOL_GPL(rtnl_put_cacheinfo);
525 532
526static void set_operstate(struct net_device *dev, unsigned char transition) 533static void set_operstate(struct net_device *dev, unsigned char transition)
527{ 534{
528 unsigned char operstate = dev->operstate; 535 unsigned char operstate = dev->operstate;
529 536
530 switch(transition) { 537 switch (transition) {
531 case IF_OPER_UP: 538 case IF_OPER_UP:
532 if ((operstate == IF_OPER_DORMANT || 539 if ((operstate == IF_OPER_DORMANT ||
533 operstate == IF_OPER_UNKNOWN) && 540 operstate == IF_OPER_UNKNOWN) &&
@@ -550,6 +557,19 @@ static void set_operstate(struct net_device *dev, unsigned char transition)
550 } 557 }
551} 558}
552 559
560static unsigned int rtnl_dev_combine_flags(const struct net_device *dev,
561 const struct ifinfomsg *ifm)
562{
563 unsigned int flags = ifm->ifi_flags;
564
565 /* bugwards compatibility: ifi_change == 0 is treated as ~0 */
566 if (ifm->ifi_change)
567 flags = (flags & ifm->ifi_change) |
568 (dev->flags & ~ifm->ifi_change);
569
570 return flags;
571}
572
553static void copy_rtnl_link_stats(struct rtnl_link_stats *a, 573static void copy_rtnl_link_stats(struct rtnl_link_stats *a,
554 const struct net_device_stats *b) 574 const struct net_device_stats *b)
555{ 575{
@@ -582,6 +602,22 @@ static void copy_rtnl_link_stats(struct rtnl_link_stats *a,
582 a->tx_compressed = b->tx_compressed; 602 a->tx_compressed = b->tx_compressed;
583}; 603};
584 604
605/* All VF info */
606static inline int rtnl_vfinfo_size(const struct net_device *dev)
607{
608 if (dev->dev.parent && dev_is_pci(dev->dev.parent)) {
609
610 int num_vfs = dev_num_vf(dev->dev.parent);
611 size_t size = nlmsg_total_size(sizeof(struct nlattr));
612 size += nlmsg_total_size(num_vfs * sizeof(struct nlattr));
613 size += num_vfs * (sizeof(struct ifla_vf_mac) +
614 sizeof(struct ifla_vf_vlan) +
615 sizeof(struct ifla_vf_tx_rate));
616 return size;
617 } else
618 return 0;
619}
620
585static inline size_t if_nlmsg_size(const struct net_device *dev) 621static inline size_t if_nlmsg_size(const struct net_device *dev)
586{ 622{
587 return NLMSG_ALIGN(sizeof(struct ifinfomsg)) 623 return NLMSG_ALIGN(sizeof(struct ifinfomsg))
@@ -599,6 +635,8 @@ static inline size_t if_nlmsg_size(const struct net_device *dev)
599 + nla_total_size(4) /* IFLA_MASTER */ 635 + nla_total_size(4) /* IFLA_MASTER */
600 + nla_total_size(1) /* IFLA_OPERSTATE */ 636 + nla_total_size(1) /* IFLA_OPERSTATE */
601 + nla_total_size(1) /* IFLA_LINKMODE */ 637 + nla_total_size(1) /* IFLA_LINKMODE */
638 + nla_total_size(4) /* IFLA_NUM_VF */
639 + rtnl_vfinfo_size(dev) /* IFLA_VFINFO_LIST */
602 + rtnl_link_get_size(dev); /* IFLA_LINKINFO */ 640 + rtnl_link_get_size(dev); /* IFLA_LINKINFO */
603} 641}
604 642
@@ -667,6 +705,40 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb, struct net_device *dev,
667 stats = dev_get_stats(dev); 705 stats = dev_get_stats(dev);
668 copy_rtnl_link_stats(nla_data(attr), stats); 706 copy_rtnl_link_stats(nla_data(attr), stats);
669 707
708 if (dev->netdev_ops->ndo_get_vf_config && dev->dev.parent) {
709 int i;
710
711 struct nlattr *vfinfo, *vf;
712 int num_vfs = dev_num_vf(dev->dev.parent);
713
714 NLA_PUT_U32(skb, IFLA_NUM_VF, num_vfs);
715 vfinfo = nla_nest_start(skb, IFLA_VFINFO_LIST);
716 if (!vfinfo)
717 goto nla_put_failure;
718 for (i = 0; i < num_vfs; i++) {
719 struct ifla_vf_info ivi;
720 struct ifla_vf_mac vf_mac;
721 struct ifla_vf_vlan vf_vlan;
722 struct ifla_vf_tx_rate vf_tx_rate;
723 if (dev->netdev_ops->ndo_get_vf_config(dev, i, &ivi))
724 break;
725 vf_mac.vf = vf_vlan.vf = vf_tx_rate.vf = ivi.vf;
726 memcpy(vf_mac.mac, ivi.mac, sizeof(ivi.mac));
727 vf_vlan.vlan = ivi.vlan;
728 vf_vlan.qos = ivi.qos;
729 vf_tx_rate.rate = ivi.tx_rate;
730 vf = nla_nest_start(skb, IFLA_VF_INFO);
731 if (!vf) {
732 nla_nest_cancel(skb, vfinfo);
733 goto nla_put_failure;
734 }
735 NLA_PUT(skb, IFLA_VF_MAC, sizeof(vf_mac), &vf_mac);
736 NLA_PUT(skb, IFLA_VF_VLAN, sizeof(vf_vlan), &vf_vlan);
737 NLA_PUT(skb, IFLA_VF_TX_RATE, sizeof(vf_tx_rate), &vf_tx_rate);
738 nla_nest_end(skb, vf);
739 }
740 nla_nest_end(skb, vfinfo);
741 }
670 if (dev->rtnl_link_ops) { 742 if (dev->rtnl_link_ops) {
671 if (rtnl_link_fill(skb, dev) < 0) 743 if (rtnl_link_fill(skb, dev) < 0)
672 goto nla_put_failure; 744 goto nla_put_failure;
@@ -682,22 +754,33 @@ nla_put_failure:
682static int rtnl_dump_ifinfo(struct sk_buff *skb, struct netlink_callback *cb) 754static int rtnl_dump_ifinfo(struct sk_buff *skb, struct netlink_callback *cb)
683{ 755{
684 struct net *net = sock_net(skb->sk); 756 struct net *net = sock_net(skb->sk);
685 int idx; 757 int h, s_h;
686 int s_idx = cb->args[0]; 758 int idx = 0, s_idx;
687 struct net_device *dev; 759 struct net_device *dev;
688 760 struct hlist_head *head;
689 idx = 0; 761 struct hlist_node *node;
690 for_each_netdev(net, dev) { 762
691 if (idx < s_idx) 763 s_h = cb->args[0];
692 goto cont; 764 s_idx = cb->args[1];
693 if (rtnl_fill_ifinfo(skb, dev, RTM_NEWLINK, 765
694 NETLINK_CB(cb->skb).pid, 766 for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) {
695 cb->nlh->nlmsg_seq, 0, NLM_F_MULTI) <= 0) 767 idx = 0;
696 break; 768 head = &net->dev_index_head[h];
769 hlist_for_each_entry(dev, node, head, index_hlist) {
770 if (idx < s_idx)
771 goto cont;
772 if (rtnl_fill_ifinfo(skb, dev, RTM_NEWLINK,
773 NETLINK_CB(cb->skb).pid,
774 cb->nlh->nlmsg_seq, 0,
775 NLM_F_MULTI) <= 0)
776 goto out;
697cont: 777cont:
698 idx++; 778 idx++;
779 }
699 } 780 }
700 cb->args[0] = idx; 781out:
782 cb->args[1] = idx;
783 cb->args[0] = h;
701 784
702 return skb->len; 785 return skb->len;
703} 786}
@@ -716,13 +799,42 @@ const struct nla_policy ifla_policy[IFLA_MAX+1] = {
716 [IFLA_LINKINFO] = { .type = NLA_NESTED }, 799 [IFLA_LINKINFO] = { .type = NLA_NESTED },
717 [IFLA_NET_NS_PID] = { .type = NLA_U32 }, 800 [IFLA_NET_NS_PID] = { .type = NLA_U32 },
718 [IFLA_IFALIAS] = { .type = NLA_STRING, .len = IFALIASZ-1 }, 801 [IFLA_IFALIAS] = { .type = NLA_STRING, .len = IFALIASZ-1 },
802 [IFLA_VFINFO_LIST] = {. type = NLA_NESTED },
719}; 803};
804EXPORT_SYMBOL(ifla_policy);
720 805
721static const struct nla_policy ifla_info_policy[IFLA_INFO_MAX+1] = { 806static const struct nla_policy ifla_info_policy[IFLA_INFO_MAX+1] = {
722 [IFLA_INFO_KIND] = { .type = NLA_STRING }, 807 [IFLA_INFO_KIND] = { .type = NLA_STRING },
723 [IFLA_INFO_DATA] = { .type = NLA_NESTED }, 808 [IFLA_INFO_DATA] = { .type = NLA_NESTED },
724}; 809};
725 810
811static const struct nla_policy ifla_vfinfo_policy[IFLA_VF_INFO_MAX+1] = {
812 [IFLA_VF_INFO] = { .type = NLA_NESTED },
813};
814
815static const struct nla_policy ifla_vf_policy[IFLA_VF_MAX+1] = {
816 [IFLA_VF_MAC] = { .type = NLA_BINARY,
817 .len = sizeof(struct ifla_vf_mac) },
818 [IFLA_VF_VLAN] = { .type = NLA_BINARY,
819 .len = sizeof(struct ifla_vf_vlan) },
820 [IFLA_VF_TX_RATE] = { .type = NLA_BINARY,
821 .len = sizeof(struct ifla_vf_tx_rate) },
822};
823
824struct net *rtnl_link_get_net(struct net *src_net, struct nlattr *tb[])
825{
826 struct net *net;
827 /* Examine the link attributes and figure out which
828 * network namespace we are talking about.
829 */
830 if (tb[IFLA_NET_NS_PID])
831 net = get_net_ns_by_pid(nla_get_u32(tb[IFLA_NET_NS_PID]));
832 else
833 net = get_net(src_net);
834 return net;
835}
836EXPORT_SYMBOL(rtnl_link_get_net);
837
726static int validate_linkmsg(struct net_device *dev, struct nlattr *tb[]) 838static int validate_linkmsg(struct net_device *dev, struct nlattr *tb[])
727{ 839{
728 if (dev) { 840 if (dev) {
@@ -738,6 +850,52 @@ static int validate_linkmsg(struct net_device *dev, struct nlattr *tb[])
738 return 0; 850 return 0;
739} 851}
740 852
853static int do_setvfinfo(struct net_device *dev, struct nlattr *attr)
854{
855 int rem, err = -EINVAL;
856 struct nlattr *vf;
857 const struct net_device_ops *ops = dev->netdev_ops;
858
859 nla_for_each_nested(vf, attr, rem) {
860 switch (nla_type(vf)) {
861 case IFLA_VF_MAC: {
862 struct ifla_vf_mac *ivm;
863 ivm = nla_data(vf);
864 err = -EOPNOTSUPP;
865 if (ops->ndo_set_vf_mac)
866 err = ops->ndo_set_vf_mac(dev, ivm->vf,
867 ivm->mac);
868 break;
869 }
870 case IFLA_VF_VLAN: {
871 struct ifla_vf_vlan *ivv;
872 ivv = nla_data(vf);
873 err = -EOPNOTSUPP;
874 if (ops->ndo_set_vf_vlan)
875 err = ops->ndo_set_vf_vlan(dev, ivv->vf,
876 ivv->vlan,
877 ivv->qos);
878 break;
879 }
880 case IFLA_VF_TX_RATE: {
881 struct ifla_vf_tx_rate *ivt;
882 ivt = nla_data(vf);
883 err = -EOPNOTSUPP;
884 if (ops->ndo_set_vf_tx_rate)
885 err = ops->ndo_set_vf_tx_rate(dev, ivt->vf,
886 ivt->rate);
887 break;
888 }
889 default:
890 err = -EINVAL;
891 break;
892 }
893 if (err)
894 break;
895 }
896 return err;
897}
898
741static int do_setlink(struct net_device *dev, struct ifinfomsg *ifm, 899static int do_setlink(struct net_device *dev, struct ifinfomsg *ifm,
742 struct nlattr **tb, char *ifname, int modified) 900 struct nlattr **tb, char *ifname, int modified)
743{ 901{
@@ -746,8 +904,7 @@ static int do_setlink(struct net_device *dev, struct ifinfomsg *ifm,
746 int err; 904 int err;
747 905
748 if (tb[IFLA_NET_NS_PID]) { 906 if (tb[IFLA_NET_NS_PID]) {
749 struct net *net; 907 struct net *net = rtnl_link_get_net(dev_net(dev), tb);
750 net = get_net_ns_by_pid(nla_get_u32(tb[IFLA_NET_NS_PID]));
751 if (IS_ERR(net)) { 908 if (IS_ERR(net)) {
752 err = PTR_ERR(net); 909 err = PTR_ERR(net);
753 goto errout; 910 goto errout;
@@ -852,13 +1009,7 @@ static int do_setlink(struct net_device *dev, struct ifinfomsg *ifm,
852 } 1009 }
853 1010
854 if (ifm->ifi_flags || ifm->ifi_change) { 1011 if (ifm->ifi_flags || ifm->ifi_change) {
855 unsigned int flags = ifm->ifi_flags; 1012 err = dev_change_flags(dev, rtnl_dev_combine_flags(dev, ifm));
856
857 /* bugwards compatibility: ifi_change == 0 is treated as ~0 */
858 if (ifm->ifi_change)
859 flags = (flags & ifm->ifi_change) |
860 (dev->flags & ~ifm->ifi_change);
861 err = dev_change_flags(dev, flags);
862 if (err < 0) 1013 if (err < 0)
863 goto errout; 1014 goto errout;
864 } 1015 }
@@ -875,6 +1026,18 @@ static int do_setlink(struct net_device *dev, struct ifinfomsg *ifm,
875 write_unlock_bh(&dev_base_lock); 1026 write_unlock_bh(&dev_base_lock);
876 } 1027 }
877 1028
1029 if (tb[IFLA_VFINFO_LIST]) {
1030 struct nlattr *attr;
1031 int rem;
1032 nla_for_each_nested(attr, tb[IFLA_VFINFO_LIST], rem) {
1033 if (nla_type(attr) != IFLA_VF_INFO)
1034 goto errout;
1035 err = do_setvfinfo(dev, attr);
1036 if (err < 0)
1037 goto errout;
1038 modified = 1;
1039 }
1040 }
878 err = 0; 1041 err = 0;
879 1042
880errout: 1043errout:
@@ -910,9 +1073,9 @@ static int rtnl_setlink(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
910 err = -EINVAL; 1073 err = -EINVAL;
911 ifm = nlmsg_data(nlh); 1074 ifm = nlmsg_data(nlh);
912 if (ifm->ifi_index > 0) 1075 if (ifm->ifi_index > 0)
913 dev = dev_get_by_index(net, ifm->ifi_index); 1076 dev = __dev_get_by_index(net, ifm->ifi_index);
914 else if (tb[IFLA_IFNAME]) 1077 else if (tb[IFLA_IFNAME])
915 dev = dev_get_by_name(net, ifname); 1078 dev = __dev_get_by_name(net, ifname);
916 else 1079 else
917 goto errout; 1080 goto errout;
918 1081
@@ -921,12 +1084,11 @@ static int rtnl_setlink(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
921 goto errout; 1084 goto errout;
922 } 1085 }
923 1086
924 if ((err = validate_linkmsg(dev, tb)) < 0) 1087 err = validate_linkmsg(dev, tb);
925 goto errout_dev; 1088 if (err < 0)
1089 goto errout;
926 1090
927 err = do_setlink(dev, ifm, tb, ifname, 0); 1091 err = do_setlink(dev, ifm, tb, ifname, 0);
928errout_dev:
929 dev_put(dev);
930errout: 1092errout:
931 return err; 1093 return err;
932} 1094}
@@ -963,12 +1125,32 @@ static int rtnl_dellink(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
963 if (!ops) 1125 if (!ops)
964 return -EOPNOTSUPP; 1126 return -EOPNOTSUPP;
965 1127
966 ops->dellink(dev); 1128 ops->dellink(dev, NULL);
967 return 0; 1129 return 0;
968} 1130}
969 1131
970struct net_device *rtnl_create_link(struct net *net, char *ifname, 1132int rtnl_configure_link(struct net_device *dev, const struct ifinfomsg *ifm)
971 const struct rtnl_link_ops *ops, struct nlattr *tb[]) 1133{
1134 unsigned int old_flags;
1135 int err;
1136
1137 old_flags = dev->flags;
1138 if (ifm && (ifm->ifi_flags || ifm->ifi_change)) {
1139 err = __dev_change_flags(dev, rtnl_dev_combine_flags(dev, ifm));
1140 if (err < 0)
1141 return err;
1142 }
1143
1144 dev->rtnl_link_state = RTNL_LINK_INITIALIZED;
1145 rtmsg_ifinfo(RTM_NEWLINK, dev, ~0U);
1146
1147 __dev_notify_flags(dev, old_flags);
1148 return 0;
1149}
1150EXPORT_SYMBOL(rtnl_configure_link);
1151
1152struct net_device *rtnl_create_link(struct net *src_net, struct net *net,
1153 char *ifname, const struct rtnl_link_ops *ops, struct nlattr *tb[])
972{ 1154{
973 int err; 1155 int err;
974 struct net_device *dev; 1156 struct net_device *dev;
@@ -976,7 +1158,8 @@ struct net_device *rtnl_create_link(struct net *net, char *ifname,
976 unsigned int real_num_queues = 1; 1158 unsigned int real_num_queues = 1;
977 1159
978 if (ops->get_tx_queues) { 1160 if (ops->get_tx_queues) {
979 err = ops->get_tx_queues(net, tb, &num_queues, &real_num_queues); 1161 err = ops->get_tx_queues(src_net, tb, &num_queues,
1162 &real_num_queues);
980 if (err) 1163 if (err)
981 goto err; 1164 goto err;
982 } 1165 }
@@ -985,16 +1168,17 @@ struct net_device *rtnl_create_link(struct net *net, char *ifname,
985 if (!dev) 1168 if (!dev)
986 goto err; 1169 goto err;
987 1170
1171 dev_net_set(dev, net);
1172 dev->rtnl_link_ops = ops;
1173 dev->rtnl_link_state = RTNL_LINK_INITIALIZING;
988 dev->real_num_tx_queues = real_num_queues; 1174 dev->real_num_tx_queues = real_num_queues;
1175
989 if (strchr(dev->name, '%')) { 1176 if (strchr(dev->name, '%')) {
990 err = dev_alloc_name(dev, dev->name); 1177 err = dev_alloc_name(dev, dev->name);
991 if (err < 0) 1178 if (err < 0)
992 goto err_free; 1179 goto err_free;
993 } 1180 }
994 1181
995 dev_net_set(dev, net);
996 dev->rtnl_link_ops = ops;
997
998 if (tb[IFLA_MTU]) 1182 if (tb[IFLA_MTU])
999 dev->mtu = nla_get_u32(tb[IFLA_MTU]); 1183 dev->mtu = nla_get_u32(tb[IFLA_MTU]);
1000 if (tb[IFLA_ADDRESS]) 1184 if (tb[IFLA_ADDRESS])
@@ -1017,6 +1201,7 @@ err_free:
1017err: 1201err:
1018 return ERR_PTR(err); 1202 return ERR_PTR(err);
1019} 1203}
1204EXPORT_SYMBOL(rtnl_create_link);
1020 1205
1021static int rtnl_newlink(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg) 1206static int rtnl_newlink(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
1022{ 1207{
@@ -1050,7 +1235,8 @@ replay:
1050 else 1235 else
1051 dev = NULL; 1236 dev = NULL;
1052 1237
1053 if ((err = validate_linkmsg(dev, tb)) < 0) 1238 err = validate_linkmsg(dev, tb);
1239 if (err < 0)
1054 return err; 1240 return err;
1055 1241
1056 if (tb[IFLA_LINKINFO]) { 1242 if (tb[IFLA_LINKINFO]) {
@@ -1071,6 +1257,7 @@ replay:
1071 1257
1072 if (1) { 1258 if (1) {
1073 struct nlattr *attr[ops ? ops->maxtype + 1 : 0], **data = NULL; 1259 struct nlattr *attr[ops ? ops->maxtype + 1 : 0], **data = NULL;
1260 struct net *dest_net;
1074 1261
1075 if (ops) { 1262 if (ops) {
1076 if (ops->maxtype && linkinfo[IFLA_INFO_DATA]) { 1263 if (ops->maxtype && linkinfo[IFLA_INFO_DATA]) {
@@ -1113,7 +1300,7 @@ replay:
1113 if (!(nlh->nlmsg_flags & NLM_F_CREATE)) 1300 if (!(nlh->nlmsg_flags & NLM_F_CREATE))
1114 return -ENODEV; 1301 return -ENODEV;
1115 1302
1116 if (ifm->ifi_index || ifm->ifi_flags || ifm->ifi_change) 1303 if (ifm->ifi_index)
1117 return -EOPNOTSUPP; 1304 return -EOPNOTSUPP;
1118 if (tb[IFLA_MAP] || tb[IFLA_MASTER] || tb[IFLA_PROTINFO]) 1305 if (tb[IFLA_MAP] || tb[IFLA_MASTER] || tb[IFLA_PROTINFO])
1119 return -EOPNOTSUPP; 1306 return -EOPNOTSUPP;
@@ -1135,17 +1322,26 @@ replay:
1135 if (!ifname[0]) 1322 if (!ifname[0])
1136 snprintf(ifname, IFNAMSIZ, "%s%%d", ops->kind); 1323 snprintf(ifname, IFNAMSIZ, "%s%%d", ops->kind);
1137 1324
1138 dev = rtnl_create_link(net, ifname, ops, tb); 1325 dest_net = rtnl_link_get_net(net, tb);
1326 dev = rtnl_create_link(net, dest_net, ifname, ops, tb);
1139 1327
1140 if (IS_ERR(dev)) 1328 if (IS_ERR(dev))
1141 err = PTR_ERR(dev); 1329 err = PTR_ERR(dev);
1142 else if (ops->newlink) 1330 else if (ops->newlink)
1143 err = ops->newlink(dev, tb, data); 1331 err = ops->newlink(net, dev, tb, data);
1144 else 1332 else
1145 err = register_netdevice(dev); 1333 err = register_netdevice(dev);
1146 1334
1147 if (err < 0 && !IS_ERR(dev)) 1335 if (err < 0 && !IS_ERR(dev))
1148 free_netdev(dev); 1336 free_netdev(dev);
1337 if (err < 0)
1338 goto out;
1339
1340 err = rtnl_configure_link(dev, ifm);
1341 if (err < 0)
1342 unregister_netdevice(dev);
1343out:
1344 put_net(dest_net);
1149 return err; 1345 return err;
1150 } 1346 }
1151} 1347}
@@ -1154,6 +1350,7 @@ static int rtnl_getlink(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg)
1154{ 1350{
1155 struct net *net = sock_net(skb->sk); 1351 struct net *net = sock_net(skb->sk);
1156 struct ifinfomsg *ifm; 1352 struct ifinfomsg *ifm;
1353 char ifname[IFNAMSIZ];
1157 struct nlattr *tb[IFLA_MAX+1]; 1354 struct nlattr *tb[IFLA_MAX+1];
1158 struct net_device *dev = NULL; 1355 struct net_device *dev = NULL;
1159 struct sk_buff *nskb; 1356 struct sk_buff *nskb;
@@ -1163,19 +1360,23 @@ static int rtnl_getlink(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg)
1163 if (err < 0) 1360 if (err < 0)
1164 return err; 1361 return err;
1165 1362
1363 if (tb[IFLA_IFNAME])
1364 nla_strlcpy(ifname, tb[IFLA_IFNAME], IFNAMSIZ);
1365
1166 ifm = nlmsg_data(nlh); 1366 ifm = nlmsg_data(nlh);
1167 if (ifm->ifi_index > 0) { 1367 if (ifm->ifi_index > 0)
1168 dev = dev_get_by_index(net, ifm->ifi_index); 1368 dev = __dev_get_by_index(net, ifm->ifi_index);
1169 if (dev == NULL) 1369 else if (tb[IFLA_IFNAME])
1170 return -ENODEV; 1370 dev = __dev_get_by_name(net, ifname);
1171 } else 1371 else
1172 return -EINVAL; 1372 return -EINVAL;
1173 1373
1374 if (dev == NULL)
1375 return -ENODEV;
1376
1174 nskb = nlmsg_new(if_nlmsg_size(dev), GFP_KERNEL); 1377 nskb = nlmsg_new(if_nlmsg_size(dev), GFP_KERNEL);
1175 if (nskb == NULL) { 1378 if (nskb == NULL)
1176 err = -ENOBUFS; 1379 return -ENOBUFS;
1177 goto errout;
1178 }
1179 1380
1180 err = rtnl_fill_ifinfo(nskb, dev, RTM_NEWLINK, NETLINK_CB(skb).pid, 1381 err = rtnl_fill_ifinfo(nskb, dev, RTM_NEWLINK, NETLINK_CB(skb).pid,
1181 nlh->nlmsg_seq, 0, 0); 1382 nlh->nlmsg_seq, 0, 0);
@@ -1183,11 +1384,8 @@ static int rtnl_getlink(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg)
1183 /* -EMSGSIZE implies BUG in if_nlmsg_size */ 1384 /* -EMSGSIZE implies BUG in if_nlmsg_size */
1184 WARN_ON(err == -EMSGSIZE); 1385 WARN_ON(err == -EMSGSIZE);
1185 kfree_skb(nskb); 1386 kfree_skb(nskb);
1186 goto errout; 1387 } else
1187 } 1388 err = rtnl_unicast(nskb, net, NETLINK_CB(skb).pid);
1188 err = rtnl_unicast(nskb, net, NETLINK_CB(skb).pid);
1189errout:
1190 dev_put(dev);
1191 1389
1192 return err; 1390 return err;
1193} 1391}
@@ -1199,7 +1397,7 @@ static int rtnl_dump_all(struct sk_buff *skb, struct netlink_callback *cb)
1199 1397
1200 if (s_idx == 0) 1398 if (s_idx == 0)
1201 s_idx = 1; 1399 s_idx = 1;
1202 for (idx=1; idx<NPROTO; idx++) { 1400 for (idx = 1; idx < NPROTO; idx++) {
1203 int type = cb->nlh->nlmsg_type-RTM_BASE; 1401 int type = cb->nlh->nlmsg_type-RTM_BASE;
1204 if (idx < s_idx || idx == PF_PACKET) 1402 if (idx < s_idx || idx == PF_PACKET)
1205 continue; 1403 continue;
@@ -1266,7 +1464,7 @@ static int rtnetlink_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
1266 if (nlh->nlmsg_len < NLMSG_LENGTH(sizeof(struct rtgenmsg))) 1464 if (nlh->nlmsg_len < NLMSG_LENGTH(sizeof(struct rtgenmsg)))
1267 return 0; 1465 return 0;
1268 1466
1269 family = ((struct rtgenmsg*)NLMSG_DATA(nlh))->rtgen_family; 1467 family = ((struct rtgenmsg *)NLMSG_DATA(nlh))->rtgen_family;
1270 if (family >= NPROTO) 1468 if (family >= NPROTO)
1271 return -EAFNOSUPPORT; 1469 return -EAFNOSUPPORT;
1272 1470
@@ -1299,7 +1497,7 @@ static int rtnetlink_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
1299 1497
1300 if (nlh->nlmsg_len > min_len) { 1498 if (nlh->nlmsg_len > min_len) {
1301 int attrlen = nlh->nlmsg_len - NLMSG_ALIGN(min_len); 1499 int attrlen = nlh->nlmsg_len - NLMSG_ALIGN(min_len);
1302 struct rtattr *attr = (void*)nlh + NLMSG_ALIGN(min_len); 1500 struct rtattr *attr = (void *)nlh + NLMSG_ALIGN(min_len);
1303 1501
1304 while (RTA_OK(attr, attrlen)) { 1502 while (RTA_OK(attr, attrlen)) {
1305 unsigned flavor = attr->rta_type; 1503 unsigned flavor = attr->rta_type;
@@ -1331,18 +1529,15 @@ static int rtnetlink_event(struct notifier_block *this, unsigned long event, voi
1331 struct net_device *dev = ptr; 1529 struct net_device *dev = ptr;
1332 1530
1333 switch (event) { 1531 switch (event) {
1334 case NETDEV_UNREGISTER:
1335 rtmsg_ifinfo(RTM_DELLINK, dev, ~0U);
1336 break;
1337 case NETDEV_REGISTER:
1338 rtmsg_ifinfo(RTM_NEWLINK, dev, ~0U);
1339 break;
1340 case NETDEV_UP: 1532 case NETDEV_UP:
1341 case NETDEV_DOWN: 1533 case NETDEV_DOWN:
1342 rtmsg_ifinfo(RTM_NEWLINK, dev, IFF_UP|IFF_RUNNING); 1534 case NETDEV_PRE_UP:
1343 break; 1535 case NETDEV_POST_INIT:
1536 case NETDEV_REGISTER:
1344 case NETDEV_CHANGE: 1537 case NETDEV_CHANGE:
1345 case NETDEV_GOING_DOWN: 1538 case NETDEV_GOING_DOWN:
1539 case NETDEV_UNREGISTER:
1540 case NETDEV_UNREGISTER_BATCH:
1346 break; 1541 break;
1347 default: 1542 default:
1348 rtmsg_ifinfo(RTM_NEWLINK, dev, 0); 1543 rtmsg_ifinfo(RTM_NEWLINK, dev, 0);
@@ -1356,7 +1551,7 @@ static struct notifier_block rtnetlink_dev_notifier = {
1356}; 1551};
1357 1552
1358 1553
1359static int rtnetlink_net_init(struct net *net) 1554static int __net_init rtnetlink_net_init(struct net *net)
1360{ 1555{
1361 struct sock *sk; 1556 struct sock *sk;
1362 sk = netlink_kernel_create(net, NETLINK_ROUTE, RTNLGRP_MAX, 1557 sk = netlink_kernel_create(net, NETLINK_ROUTE, RTNLGRP_MAX,
@@ -1367,7 +1562,7 @@ static int rtnetlink_net_init(struct net *net)
1367 return 0; 1562 return 0;
1368} 1563}
1369 1564
1370static void rtnetlink_net_exit(struct net *net) 1565static void __net_exit rtnetlink_net_exit(struct net *net)
1371{ 1566{
1372 netlink_kernel_release(net->rtnl); 1567 netlink_kernel_release(net->rtnl);
1373 net->rtnl = NULL; 1568 net->rtnl = NULL;
@@ -1405,14 +1600,3 @@ void __init rtnetlink_init(void)
1405 rtnl_register(PF_UNSPEC, RTM_GETROUTE, NULL, rtnl_dump_all); 1600 rtnl_register(PF_UNSPEC, RTM_GETROUTE, NULL, rtnl_dump_all);
1406} 1601}
1407 1602
1408EXPORT_SYMBOL(__rta_fill);
1409EXPORT_SYMBOL(rtnetlink_put_metrics);
1410EXPORT_SYMBOL(rtnl_lock);
1411EXPORT_SYMBOL(rtnl_trylock);
1412EXPORT_SYMBOL(rtnl_unlock);
1413EXPORT_SYMBOL(rtnl_is_locked);
1414EXPORT_SYMBOL(rtnl_unicast);
1415EXPORT_SYMBOL(rtnl_notify);
1416EXPORT_SYMBOL(rtnl_set_sk_err);
1417EXPORT_SYMBOL(rtnl_create_link);
1418EXPORT_SYMBOL(ifla_policy);
diff --git a/net/core/scm.c b/net/core/scm.c
index b7ba91b074b3..b88f6f9d0b97 100644
--- a/net/core/scm.c
+++ b/net/core/scm.c
@@ -26,6 +26,7 @@
26#include <linux/security.h> 26#include <linux/security.h>
27#include <linux/pid.h> 27#include <linux/pid.h>
28#include <linux/nsproxy.h> 28#include <linux/nsproxy.h>
29#include <linux/slab.h>
29 30
30#include <asm/system.h> 31#include <asm/system.h>
31#include <asm/uaccess.h> 32#include <asm/uaccess.h>
@@ -156,6 +157,8 @@ int __scm_send(struct socket *sock, struct msghdr *msg, struct scm_cookie *p)
156 switch (cmsg->cmsg_type) 157 switch (cmsg->cmsg_type)
157 { 158 {
158 case SCM_RIGHTS: 159 case SCM_RIGHTS:
160 if (!sock->ops || sock->ops->family != PF_UNIX)
161 goto error;
159 err=scm_fp_copy(cmsg, &p->fp); 162 err=scm_fp_copy(cmsg, &p->fp);
160 if (err<0) 163 if (err<0)
161 goto error; 164 goto error;
diff --git a/net/core/skb_dma_map.c b/net/core/skb_dma_map.c
deleted file mode 100644
index 79687dfd6957..000000000000
--- a/net/core/skb_dma_map.c
+++ /dev/null
@@ -1,65 +0,0 @@
1/* skb_dma_map.c: DMA mapping helpers for socket buffers.
2 *
3 * Copyright (C) David S. Miller <davem@davemloft.net>
4 */
5
6#include <linux/kernel.h>
7#include <linux/module.h>
8#include <linux/dma-mapping.h>
9#include <linux/skbuff.h>
10
11int skb_dma_map(struct device *dev, struct sk_buff *skb,
12 enum dma_data_direction dir)
13{
14 struct skb_shared_info *sp = skb_shinfo(skb);
15 dma_addr_t map;
16 int i;
17
18 map = dma_map_single(dev, skb->data,
19 skb_headlen(skb), dir);
20 if (dma_mapping_error(dev, map))
21 goto out_err;
22
23 sp->dma_head = map;
24 for (i = 0; i < sp->nr_frags; i++) {
25 skb_frag_t *fp = &sp->frags[i];
26
27 map = dma_map_page(dev, fp->page, fp->page_offset,
28 fp->size, dir);
29 if (dma_mapping_error(dev, map))
30 goto unwind;
31 sp->dma_maps[i] = map;
32 }
33
34 return 0;
35
36unwind:
37 while (--i >= 0) {
38 skb_frag_t *fp = &sp->frags[i];
39
40 dma_unmap_page(dev, sp->dma_maps[i],
41 fp->size, dir);
42 }
43 dma_unmap_single(dev, sp->dma_head,
44 skb_headlen(skb), dir);
45out_err:
46 return -ENOMEM;
47}
48EXPORT_SYMBOL(skb_dma_map);
49
50void skb_dma_unmap(struct device *dev, struct sk_buff *skb,
51 enum dma_data_direction dir)
52{
53 struct skb_shared_info *sp = skb_shinfo(skb);
54 int i;
55
56 dma_unmap_single(dev, sp->dma_head,
57 skb_headlen(skb), dir);
58 for (i = 0; i < sp->nr_frags; i++) {
59 skb_frag_t *fp = &sp->frags[i];
60
61 dma_unmap_page(dev, sp->dma_maps[i],
62 fp->size, dir);
63 }
64}
65EXPORT_SYMBOL(skb_dma_unmap);
diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index ec85681a7dd8..93c4e060c91e 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -93,7 +93,7 @@ static int sock_pipe_buf_steal(struct pipe_inode_info *pipe,
93 93
94 94
95/* Pipe buffer operations for a socket. */ 95/* Pipe buffer operations for a socket. */
96static struct pipe_buf_operations sock_pipe_buf_ops = { 96static const struct pipe_buf_operations sock_pipe_buf_ops = {
97 .can_merge = 0, 97 .can_merge = 0,
98 .map = generic_pipe_buf_map, 98 .map = generic_pipe_buf_map,
99 .unmap = generic_pipe_buf_unmap, 99 .unmap = generic_pipe_buf_unmap,
@@ -493,6 +493,9 @@ int skb_recycle_check(struct sk_buff *skb, int skb_size)
493{ 493{
494 struct skb_shared_info *shinfo; 494 struct skb_shared_info *shinfo;
495 495
496 if (irqs_disabled())
497 return 0;
498
496 if (skb_is_nonlinear(skb) || skb->fclone != SKB_FCLONE_UNAVAILABLE) 499 if (skb_is_nonlinear(skb) || skb->fclone != SKB_FCLONE_UNAVAILABLE)
497 return 0; 500 return 0;
498 501
@@ -546,7 +549,7 @@ static void __copy_skb_header(struct sk_buff *new, const struct sk_buff *old)
546#endif 549#endif
547 new->protocol = old->protocol; 550 new->protocol = old->protocol;
548 new->mark = old->mark; 551 new->mark = old->mark;
549 new->iif = old->iif; 552 new->skb_iif = old->skb_iif;
550 __nf_copy(new, old); 553 __nf_copy(new, old);
551#if defined(CONFIG_NETFILTER_XT_TARGET_TRACE) || \ 554#if defined(CONFIG_NETFILTER_XT_TARGET_TRACE) || \
552 defined(CONFIG_NETFILTER_XT_TARGET_TRACE_MODULE) 555 defined(CONFIG_NETFILTER_XT_TARGET_TRACE_MODULE)
diff --git a/net/core/sock.c b/net/core/sock.c
index 7626b6aacd68..c5812bbc2cc9 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -274,25 +274,27 @@ static void sock_disable_timestamp(struct sock *sk, int flag)
274 274
275int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb) 275int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
276{ 276{
277 int err = 0; 277 int err;
278 int skb_len; 278 int skb_len;
279 unsigned long flags;
280 struct sk_buff_head *list = &sk->sk_receive_queue;
279 281
280 /* Cast sk->rcvbuf to unsigned... It's pointless, but reduces 282 /* Cast sk->rcvbuf to unsigned... It's pointless, but reduces
281 number of warnings when compiling with -W --ANK 283 number of warnings when compiling with -W --ANK
282 */ 284 */
283 if (atomic_read(&sk->sk_rmem_alloc) + skb->truesize >= 285 if (atomic_read(&sk->sk_rmem_alloc) + skb->truesize >=
284 (unsigned)sk->sk_rcvbuf) { 286 (unsigned)sk->sk_rcvbuf) {
285 err = -ENOMEM; 287 atomic_inc(&sk->sk_drops);
286 goto out; 288 return -ENOMEM;
287 } 289 }
288 290
289 err = sk_filter(sk, skb); 291 err = sk_filter(sk, skb);
290 if (err) 292 if (err)
291 goto out; 293 return err;
292 294
293 if (!sk_rmem_schedule(sk, skb->truesize)) { 295 if (!sk_rmem_schedule(sk, skb->truesize)) {
294 err = -ENOBUFS; 296 atomic_inc(&sk->sk_drops);
295 goto out; 297 return -ENOBUFS;
296 } 298 }
297 299
298 skb->dev = NULL; 300 skb->dev = NULL;
@@ -305,12 +307,14 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
305 */ 307 */
306 skb_len = skb->len; 308 skb_len = skb->len;
307 309
308 skb_queue_tail(&sk->sk_receive_queue, skb); 310 spin_lock_irqsave(&list->lock, flags);
311 skb->dropcount = atomic_read(&sk->sk_drops);
312 __skb_queue_tail(list, skb);
313 spin_unlock_irqrestore(&list->lock, flags);
309 314
310 if (!sock_flag(sk, SOCK_DEAD)) 315 if (!sock_flag(sk, SOCK_DEAD))
311 sk->sk_data_ready(sk, skb_len); 316 sk->sk_data_ready(sk, skb_len);
312out: 317 return 0;
313 return err;
314} 318}
315EXPORT_SYMBOL(sock_queue_rcv_skb); 319EXPORT_SYMBOL(sock_queue_rcv_skb);
316 320
@@ -336,8 +340,12 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
336 rc = sk_backlog_rcv(sk, skb); 340 rc = sk_backlog_rcv(sk, skb);
337 341
338 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_); 342 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
339 } else 343 } else if (sk_add_backlog(sk, skb)) {
340 sk_add_backlog(sk, skb); 344 bh_unlock_sock(sk);
345 atomic_inc(&sk->sk_drops);
346 goto discard_and_relse;
347 }
348
341 bh_unlock_sock(sk); 349 bh_unlock_sock(sk);
342out: 350out:
343 sock_put(sk); 351 sock_put(sk);
@@ -348,11 +356,18 @@ discard_and_relse:
348} 356}
349EXPORT_SYMBOL(sk_receive_skb); 357EXPORT_SYMBOL(sk_receive_skb);
350 358
359void sk_reset_txq(struct sock *sk)
360{
361 sk_tx_queue_clear(sk);
362}
363EXPORT_SYMBOL(sk_reset_txq);
364
351struct dst_entry *__sk_dst_check(struct sock *sk, u32 cookie) 365struct dst_entry *__sk_dst_check(struct sock *sk, u32 cookie)
352{ 366{
353 struct dst_entry *dst = sk->sk_dst_cache; 367 struct dst_entry *dst = sk->sk_dst_cache;
354 368
355 if (dst && dst->obsolete && dst->ops->check(dst, cookie) == NULL) { 369 if (dst && dst->obsolete && dst->ops->check(dst, cookie) == NULL) {
370 sk_tx_queue_clear(sk);
356 sk->sk_dst_cache = NULL; 371 sk->sk_dst_cache = NULL;
357 dst_release(dst); 372 dst_release(dst);
358 return NULL; 373 return NULL;
@@ -406,17 +421,18 @@ static int sock_bindtodevice(struct sock *sk, char __user *optval, int optlen)
406 if (copy_from_user(devname, optval, optlen)) 421 if (copy_from_user(devname, optval, optlen))
407 goto out; 422 goto out;
408 423
409 if (devname[0] == '\0') { 424 index = 0;
410 index = 0; 425 if (devname[0] != '\0') {
411 } else { 426 struct net_device *dev;
412 struct net_device *dev = dev_get_by_name(net, devname);
413 427
428 rcu_read_lock();
429 dev = dev_get_by_name_rcu(net, devname);
430 if (dev)
431 index = dev->ifindex;
432 rcu_read_unlock();
414 ret = -ENODEV; 433 ret = -ENODEV;
415 if (!dev) 434 if (!dev)
416 goto out; 435 goto out;
417
418 index = dev->ifindex;
419 dev_put(dev);
420 } 436 }
421 437
422 lock_sock(sk); 438 lock_sock(sk);
@@ -702,6 +718,12 @@ set_rcvbuf:
702 718
703 /* We implement the SO_SNDLOWAT etc to 719 /* We implement the SO_SNDLOWAT etc to
704 not be settable (1003.1g 5.3) */ 720 not be settable (1003.1g 5.3) */
721 case SO_RXQ_OVFL:
722 if (valbool)
723 sock_set_flag(sk, SOCK_RXQ_OVFL);
724 else
725 sock_reset_flag(sk, SOCK_RXQ_OVFL);
726 break;
705 default: 727 default:
706 ret = -ENOPROTOOPT; 728 ret = -ENOPROTOOPT;
707 break; 729 break;
@@ -723,7 +745,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
723 struct timeval tm; 745 struct timeval tm;
724 } v; 746 } v;
725 747
726 unsigned int lv = sizeof(int); 748 int lv = sizeof(int);
727 int len; 749 int len;
728 750
729 if (get_user(len, optlen)) 751 if (get_user(len, optlen))
@@ -901,6 +923,10 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
901 v.val = sk->sk_mark; 923 v.val = sk->sk_mark;
902 break; 924 break;
903 925
926 case SO_RXQ_OVFL:
927 v.val = !!sock_flag(sk, SOCK_RXQ_OVFL);
928 break;
929
904 default: 930 default:
905 return -ENOPROTOOPT; 931 return -ENOPROTOOPT;
906 } 932 }
@@ -939,7 +965,8 @@ static void sock_copy(struct sock *nsk, const struct sock *osk)
939 void *sptr = nsk->sk_security; 965 void *sptr = nsk->sk_security;
940#endif 966#endif
941 BUILD_BUG_ON(offsetof(struct sock, sk_copy_start) != 967 BUILD_BUG_ON(offsetof(struct sock, sk_copy_start) !=
942 sizeof(osk->sk_node) + sizeof(osk->sk_refcnt)); 968 sizeof(osk->sk_node) + sizeof(osk->sk_refcnt) +
969 sizeof(osk->sk_tx_queue_mapping));
943 memcpy(&nsk->sk_copy_start, &osk->sk_copy_start, 970 memcpy(&nsk->sk_copy_start, &osk->sk_copy_start,
944 osk->sk_prot->obj_size - offsetof(struct sock, sk_copy_start)); 971 osk->sk_prot->obj_size - offsetof(struct sock, sk_copy_start));
945#ifdef CONFIG_SECURITY_NETWORK 972#ifdef CONFIG_SECURITY_NETWORK
@@ -983,6 +1010,7 @@ static struct sock *sk_prot_alloc(struct proto *prot, gfp_t priority,
983 1010
984 if (!try_module_get(prot->owner)) 1011 if (!try_module_get(prot->owner))
985 goto out_free_sec; 1012 goto out_free_sec;
1013 sk_tx_queue_clear(sk);
986 } 1014 }
987 1015
988 return sk; 1016 return sk;
@@ -1049,7 +1077,8 @@ static void __sk_free(struct sock *sk)
1049 if (sk->sk_destruct) 1077 if (sk->sk_destruct)
1050 sk->sk_destruct(sk); 1078 sk->sk_destruct(sk);
1051 1079
1052 filter = rcu_dereference(sk->sk_filter); 1080 filter = rcu_dereference_check(sk->sk_filter,
1081 atomic_read(&sk->sk_wmem_alloc) == 0);
1053 if (filter) { 1082 if (filter) {
1054 sk_filter_uncharge(sk, filter); 1083 sk_filter_uncharge(sk, filter);
1055 rcu_assign_pointer(sk->sk_filter, NULL); 1084 rcu_assign_pointer(sk->sk_filter, NULL);
@@ -1114,6 +1143,7 @@ struct sock *sk_clone(const struct sock *sk, const gfp_t priority)
1114 sock_lock_init(newsk); 1143 sock_lock_init(newsk);
1115 bh_lock_sock(newsk); 1144 bh_lock_sock(newsk);
1116 newsk->sk_backlog.head = newsk->sk_backlog.tail = NULL; 1145 newsk->sk_backlog.head = newsk->sk_backlog.tail = NULL;
1146 newsk->sk_backlog.len = 0;
1117 1147
1118 atomic_set(&newsk->sk_rmem_alloc, 0); 1148 atomic_set(&newsk->sk_rmem_alloc, 0);
1119 /* 1149 /*
@@ -1181,6 +1211,10 @@ struct sock *sk_clone(const struct sock *sk, const gfp_t priority)
1181 1211
1182 if (newsk->sk_prot->sockets_allocated) 1212 if (newsk->sk_prot->sockets_allocated)
1183 percpu_counter_inc(newsk->sk_prot->sockets_allocated); 1213 percpu_counter_inc(newsk->sk_prot->sockets_allocated);
1214
1215 if (sock_flag(newsk, SOCK_TIMESTAMP) ||
1216 sock_flag(newsk, SOCK_TIMESTAMPING_RX_SOFTWARE))
1217 net_enable_timestamp();
1184 } 1218 }
1185out: 1219out:
1186 return newsk; 1220 return newsk;
@@ -1513,6 +1547,12 @@ static void __release_sock(struct sock *sk)
1513 1547
1514 bh_lock_sock(sk); 1548 bh_lock_sock(sk);
1515 } while ((skb = sk->sk_backlog.head) != NULL); 1549 } while ((skb = sk->sk_backlog.head) != NULL);
1550
1551 /*
1552 * Doing the zeroing here guarantee we can not loop forever
1553 * while a wild producer attempts to flood us.
1554 */
1555 sk->sk_backlog.len = 0;
1516} 1556}
1517 1557
1518/** 1558/**
@@ -1845,6 +1885,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
1845 sk->sk_allocation = GFP_KERNEL; 1885 sk->sk_allocation = GFP_KERNEL;
1846 sk->sk_rcvbuf = sysctl_rmem_default; 1886 sk->sk_rcvbuf = sysctl_rmem_default;
1847 sk->sk_sndbuf = sysctl_wmem_default; 1887 sk->sk_sndbuf = sysctl_wmem_default;
1888 sk->sk_backlog.limit = sk->sk_rcvbuf << 1;
1848 sk->sk_state = TCP_CLOSE; 1889 sk->sk_state = TCP_CLOSE;
1849 sk_set_socket(sk, sock); 1890 sk_set_socket(sk, sock);
1850 1891
@@ -2112,13 +2153,13 @@ int sock_prot_inuse_get(struct net *net, struct proto *prot)
2112} 2153}
2113EXPORT_SYMBOL_GPL(sock_prot_inuse_get); 2154EXPORT_SYMBOL_GPL(sock_prot_inuse_get);
2114 2155
2115static int sock_inuse_init_net(struct net *net) 2156static int __net_init sock_inuse_init_net(struct net *net)
2116{ 2157{
2117 net->core.inuse = alloc_percpu(struct prot_inuse); 2158 net->core.inuse = alloc_percpu(struct prot_inuse);
2118 return net->core.inuse ? 0 : -ENOMEM; 2159 return net->core.inuse ? 0 : -ENOMEM;
2119} 2160}
2120 2161
2121static void sock_inuse_exit_net(struct net *net) 2162static void __net_exit sock_inuse_exit_net(struct net *net)
2122{ 2163{
2123 free_percpu(net->core.inuse); 2164 free_percpu(net->core.inuse);
2124} 2165}
@@ -2200,13 +2241,10 @@ int proto_register(struct proto *prot, int alloc_slab)
2200 } 2241 }
2201 2242
2202 if (prot->rsk_prot != NULL) { 2243 if (prot->rsk_prot != NULL) {
2203 static const char mask[] = "request_sock_%s"; 2244 prot->rsk_prot->slab_name = kasprintf(GFP_KERNEL, "request_sock_%s", prot->name);
2204
2205 prot->rsk_prot->slab_name = kmalloc(strlen(prot->name) + sizeof(mask) - 1, GFP_KERNEL);
2206 if (prot->rsk_prot->slab_name == NULL) 2245 if (prot->rsk_prot->slab_name == NULL)
2207 goto out_free_sock_slab; 2246 goto out_free_sock_slab;
2208 2247
2209 sprintf(prot->rsk_prot->slab_name, mask, prot->name);
2210 prot->rsk_prot->slab = kmem_cache_create(prot->rsk_prot->slab_name, 2248 prot->rsk_prot->slab = kmem_cache_create(prot->rsk_prot->slab_name,
2211 prot->rsk_prot->obj_size, 0, 2249 prot->rsk_prot->obj_size, 0,
2212 SLAB_HWCACHE_ALIGN, NULL); 2250 SLAB_HWCACHE_ALIGN, NULL);
@@ -2219,14 +2257,11 @@ int proto_register(struct proto *prot, int alloc_slab)
2219 } 2257 }
2220 2258
2221 if (prot->twsk_prot != NULL) { 2259 if (prot->twsk_prot != NULL) {
2222 static const char mask[] = "tw_sock_%s"; 2260 prot->twsk_prot->twsk_slab_name = kasprintf(GFP_KERNEL, "tw_sock_%s", prot->name);
2223
2224 prot->twsk_prot->twsk_slab_name = kmalloc(strlen(prot->name) + sizeof(mask) - 1, GFP_KERNEL);
2225 2261
2226 if (prot->twsk_prot->twsk_slab_name == NULL) 2262 if (prot->twsk_prot->twsk_slab_name == NULL)
2227 goto out_free_request_sock_slab; 2263 goto out_free_request_sock_slab;
2228 2264
2229 sprintf(prot->twsk_prot->twsk_slab_name, mask, prot->name);
2230 prot->twsk_prot->twsk_slab = 2265 prot->twsk_prot->twsk_slab =
2231 kmem_cache_create(prot->twsk_prot->twsk_slab_name, 2266 kmem_cache_create(prot->twsk_prot->twsk_slab_name,
2232 prot->twsk_prot->twsk_obj_size, 2267 prot->twsk_prot->twsk_obj_size,
@@ -2253,7 +2288,8 @@ out_free_request_sock_slab:
2253 prot->rsk_prot->slab = NULL; 2288 prot->rsk_prot->slab = NULL;
2254 } 2289 }
2255out_free_request_sock_slab_name: 2290out_free_request_sock_slab_name:
2256 kfree(prot->rsk_prot->slab_name); 2291 if (prot->rsk_prot)
2292 kfree(prot->rsk_prot->slab_name);
2257out_free_sock_slab: 2293out_free_sock_slab:
2258 kmem_cache_destroy(prot->slab); 2294 kmem_cache_destroy(prot->slab);
2259 prot->slab = NULL; 2295 prot->slab = NULL;
diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
index 7db1de0497c6..b7b6b8208f75 100644
--- a/net/core/sysctl_net_core.c
+++ b/net/core/sysctl_net_core.c
@@ -10,14 +10,16 @@
10#include <linux/module.h> 10#include <linux/module.h>
11#include <linux/socket.h> 11#include <linux/socket.h>
12#include <linux/netdevice.h> 12#include <linux/netdevice.h>
13#include <linux/ratelimit.h>
13#include <linux/init.h> 14#include <linux/init.h>
15#include <linux/slab.h>
16
14#include <net/ip.h> 17#include <net/ip.h>
15#include <net/sock.h> 18#include <net/sock.h>
16 19
17static struct ctl_table net_core_table[] = { 20static struct ctl_table net_core_table[] = {
18#ifdef CONFIG_NET 21#ifdef CONFIG_NET
19 { 22 {
20 .ctl_name = NET_CORE_WMEM_MAX,
21 .procname = "wmem_max", 23 .procname = "wmem_max",
22 .data = &sysctl_wmem_max, 24 .data = &sysctl_wmem_max,
23 .maxlen = sizeof(int), 25 .maxlen = sizeof(int),
@@ -25,7 +27,6 @@ static struct ctl_table net_core_table[] = {
25 .proc_handler = proc_dointvec 27 .proc_handler = proc_dointvec
26 }, 28 },
27 { 29 {
28 .ctl_name = NET_CORE_RMEM_MAX,
29 .procname = "rmem_max", 30 .procname = "rmem_max",
30 .data = &sysctl_rmem_max, 31 .data = &sysctl_rmem_max,
31 .maxlen = sizeof(int), 32 .maxlen = sizeof(int),
@@ -33,7 +34,6 @@ static struct ctl_table net_core_table[] = {
33 .proc_handler = proc_dointvec 34 .proc_handler = proc_dointvec
34 }, 35 },
35 { 36 {
36 .ctl_name = NET_CORE_WMEM_DEFAULT,
37 .procname = "wmem_default", 37 .procname = "wmem_default",
38 .data = &sysctl_wmem_default, 38 .data = &sysctl_wmem_default,
39 .maxlen = sizeof(int), 39 .maxlen = sizeof(int),
@@ -41,7 +41,6 @@ static struct ctl_table net_core_table[] = {
41 .proc_handler = proc_dointvec 41 .proc_handler = proc_dointvec
42 }, 42 },
43 { 43 {
44 .ctl_name = NET_CORE_RMEM_DEFAULT,
45 .procname = "rmem_default", 44 .procname = "rmem_default",
46 .data = &sysctl_rmem_default, 45 .data = &sysctl_rmem_default,
47 .maxlen = sizeof(int), 46 .maxlen = sizeof(int),
@@ -49,7 +48,6 @@ static struct ctl_table net_core_table[] = {
49 .proc_handler = proc_dointvec 48 .proc_handler = proc_dointvec
50 }, 49 },
51 { 50 {
52 .ctl_name = NET_CORE_DEV_WEIGHT,
53 .procname = "dev_weight", 51 .procname = "dev_weight",
54 .data = &weight_p, 52 .data = &weight_p,
55 .maxlen = sizeof(int), 53 .maxlen = sizeof(int),
@@ -57,7 +55,6 @@ static struct ctl_table net_core_table[] = {
57 .proc_handler = proc_dointvec 55 .proc_handler = proc_dointvec
58 }, 56 },
59 { 57 {
60 .ctl_name = NET_CORE_MAX_BACKLOG,
61 .procname = "netdev_max_backlog", 58 .procname = "netdev_max_backlog",
62 .data = &netdev_max_backlog, 59 .data = &netdev_max_backlog,
63 .maxlen = sizeof(int), 60 .maxlen = sizeof(int),
@@ -65,16 +62,13 @@ static struct ctl_table net_core_table[] = {
65 .proc_handler = proc_dointvec 62 .proc_handler = proc_dointvec
66 }, 63 },
67 { 64 {
68 .ctl_name = NET_CORE_MSG_COST,
69 .procname = "message_cost", 65 .procname = "message_cost",
70 .data = &net_ratelimit_state.interval, 66 .data = &net_ratelimit_state.interval,
71 .maxlen = sizeof(int), 67 .maxlen = sizeof(int),
72 .mode = 0644, 68 .mode = 0644,
73 .proc_handler = proc_dointvec_jiffies, 69 .proc_handler = proc_dointvec_jiffies,
74 .strategy = sysctl_jiffies,
75 }, 70 },
76 { 71 {
77 .ctl_name = NET_CORE_MSG_BURST,
78 .procname = "message_burst", 72 .procname = "message_burst",
79 .data = &net_ratelimit_state.burst, 73 .data = &net_ratelimit_state.burst,
80 .maxlen = sizeof(int), 74 .maxlen = sizeof(int),
@@ -82,7 +76,6 @@ static struct ctl_table net_core_table[] = {
82 .proc_handler = proc_dointvec, 76 .proc_handler = proc_dointvec,
83 }, 77 },
84 { 78 {
85 .ctl_name = NET_CORE_OPTMEM_MAX,
86 .procname = "optmem_max", 79 .procname = "optmem_max",
87 .data = &sysctl_optmem_max, 80 .data = &sysctl_optmem_max,
88 .maxlen = sizeof(int), 81 .maxlen = sizeof(int),
@@ -91,7 +84,6 @@ static struct ctl_table net_core_table[] = {
91 }, 84 },
92#endif /* CONFIG_NET */ 85#endif /* CONFIG_NET */
93 { 86 {
94 .ctl_name = NET_CORE_BUDGET,
95 .procname = "netdev_budget", 87 .procname = "netdev_budget",
96 .data = &netdev_budget, 88 .data = &netdev_budget,
97 .maxlen = sizeof(int), 89 .maxlen = sizeof(int),
@@ -99,31 +91,29 @@ static struct ctl_table net_core_table[] = {
99 .proc_handler = proc_dointvec 91 .proc_handler = proc_dointvec
100 }, 92 },
101 { 93 {
102 .ctl_name = NET_CORE_WARNINGS,
103 .procname = "warnings", 94 .procname = "warnings",
104 .data = &net_msg_warn, 95 .data = &net_msg_warn,
105 .maxlen = sizeof(int), 96 .maxlen = sizeof(int),
106 .mode = 0644, 97 .mode = 0644,
107 .proc_handler = proc_dointvec 98 .proc_handler = proc_dointvec
108 }, 99 },
109 { .ctl_name = 0 } 100 { }
110}; 101};
111 102
112static struct ctl_table netns_core_table[] = { 103static struct ctl_table netns_core_table[] = {
113 { 104 {
114 .ctl_name = NET_CORE_SOMAXCONN,
115 .procname = "somaxconn", 105 .procname = "somaxconn",
116 .data = &init_net.core.sysctl_somaxconn, 106 .data = &init_net.core.sysctl_somaxconn,
117 .maxlen = sizeof(int), 107 .maxlen = sizeof(int),
118 .mode = 0644, 108 .mode = 0644,
119 .proc_handler = proc_dointvec 109 .proc_handler = proc_dointvec
120 }, 110 },
121 { .ctl_name = 0 } 111 { }
122}; 112};
123 113
124__net_initdata struct ctl_path net_core_path[] = { 114__net_initdata struct ctl_path net_core_path[] = {
125 { .procname = "net", .ctl_name = CTL_NET, }, 115 { .procname = "net", },
126 { .procname = "core", .ctl_name = NET_CORE, }, 116 { .procname = "core", },
127 { }, 117 { },
128}; 118};
129 119
@@ -134,7 +124,7 @@ static __net_init int sysctl_core_net_init(struct net *net)
134 net->core.sysctl_somaxconn = SOMAXCONN; 124 net->core.sysctl_somaxconn = SOMAXCONN;
135 125
136 tbl = netns_core_table; 126 tbl = netns_core_table;
137 if (net != &init_net) { 127 if (!net_eq(net, &init_net)) {
138 tbl = kmemdup(tbl, sizeof(netns_core_table), GFP_KERNEL); 128 tbl = kmemdup(tbl, sizeof(netns_core_table), GFP_KERNEL);
139 if (tbl == NULL) 129 if (tbl == NULL)
140 goto err_dup; 130 goto err_dup;
diff --git a/net/core/utils.c b/net/core/utils.c
index 83221aee7084..838250241d26 100644
--- a/net/core/utils.c
+++ b/net/core/utils.c
@@ -24,6 +24,8 @@
24#include <linux/types.h> 24#include <linux/types.h>
25#include <linux/percpu.h> 25#include <linux/percpu.h>
26#include <linux/init.h> 26#include <linux/init.h>
27#include <linux/ratelimit.h>
28
27#include <net/sock.h> 29#include <net/sock.h>
28 30
29#include <asm/byteorder.h> 31#include <asm/byteorder.h>
diff --git a/net/dcb/dcbnl.c b/net/dcb/dcbnl.c
index ac1205df6c86..19ac2b985485 100644
--- a/net/dcb/dcbnl.c
+++ b/net/dcb/dcbnl.c
@@ -19,6 +19,7 @@
19 19
20#include <linux/netdevice.h> 20#include <linux/netdevice.h>
21#include <linux/netlink.h> 21#include <linux/netlink.h>
22#include <linux/slab.h>
22#include <net/netlink.h> 23#include <net/netlink.h>
23#include <net/rtnetlink.h> 24#include <net/rtnetlink.h>
24#include <linux/dcbnl.h> 25#include <linux/dcbnl.h>
@@ -54,7 +55,7 @@ MODULE_LICENSE("GPL");
54/**************** DCB attribute policies *************************************/ 55/**************** DCB attribute policies *************************************/
55 56
56/* DCB netlink attributes policy */ 57/* DCB netlink attributes policy */
57static struct nla_policy dcbnl_rtnl_policy[DCB_ATTR_MAX + 1] = { 58static const struct nla_policy dcbnl_rtnl_policy[DCB_ATTR_MAX + 1] = {
58 [DCB_ATTR_IFNAME] = {.type = NLA_NUL_STRING, .len = IFNAMSIZ - 1}, 59 [DCB_ATTR_IFNAME] = {.type = NLA_NUL_STRING, .len = IFNAMSIZ - 1},
59 [DCB_ATTR_STATE] = {.type = NLA_U8}, 60 [DCB_ATTR_STATE] = {.type = NLA_U8},
60 [DCB_ATTR_PFC_CFG] = {.type = NLA_NESTED}, 61 [DCB_ATTR_PFC_CFG] = {.type = NLA_NESTED},
@@ -68,7 +69,7 @@ static struct nla_policy dcbnl_rtnl_policy[DCB_ATTR_MAX + 1] = {
68}; 69};
69 70
70/* DCB priority flow control to User Priority nested attributes */ 71/* DCB priority flow control to User Priority nested attributes */
71static struct nla_policy dcbnl_pfc_up_nest[DCB_PFC_UP_ATTR_MAX + 1] = { 72static const struct nla_policy dcbnl_pfc_up_nest[DCB_PFC_UP_ATTR_MAX + 1] = {
72 [DCB_PFC_UP_ATTR_0] = {.type = NLA_U8}, 73 [DCB_PFC_UP_ATTR_0] = {.type = NLA_U8},
73 [DCB_PFC_UP_ATTR_1] = {.type = NLA_U8}, 74 [DCB_PFC_UP_ATTR_1] = {.type = NLA_U8},
74 [DCB_PFC_UP_ATTR_2] = {.type = NLA_U8}, 75 [DCB_PFC_UP_ATTR_2] = {.type = NLA_U8},
@@ -81,7 +82,7 @@ static struct nla_policy dcbnl_pfc_up_nest[DCB_PFC_UP_ATTR_MAX + 1] = {
81}; 82};
82 83
83/* DCB priority grouping nested attributes */ 84/* DCB priority grouping nested attributes */
84static struct nla_policy dcbnl_pg_nest[DCB_PG_ATTR_MAX + 1] = { 85static const struct nla_policy dcbnl_pg_nest[DCB_PG_ATTR_MAX + 1] = {
85 [DCB_PG_ATTR_TC_0] = {.type = NLA_NESTED}, 86 [DCB_PG_ATTR_TC_0] = {.type = NLA_NESTED},
86 [DCB_PG_ATTR_TC_1] = {.type = NLA_NESTED}, 87 [DCB_PG_ATTR_TC_1] = {.type = NLA_NESTED},
87 [DCB_PG_ATTR_TC_2] = {.type = NLA_NESTED}, 88 [DCB_PG_ATTR_TC_2] = {.type = NLA_NESTED},
@@ -103,7 +104,7 @@ static struct nla_policy dcbnl_pg_nest[DCB_PG_ATTR_MAX + 1] = {
103}; 104};
104 105
105/* DCB traffic class nested attributes. */ 106/* DCB traffic class nested attributes. */
106static struct nla_policy dcbnl_tc_param_nest[DCB_TC_ATTR_PARAM_MAX + 1] = { 107static const struct nla_policy dcbnl_tc_param_nest[DCB_TC_ATTR_PARAM_MAX + 1] = {
107 [DCB_TC_ATTR_PARAM_PGID] = {.type = NLA_U8}, 108 [DCB_TC_ATTR_PARAM_PGID] = {.type = NLA_U8},
108 [DCB_TC_ATTR_PARAM_UP_MAPPING] = {.type = NLA_U8}, 109 [DCB_TC_ATTR_PARAM_UP_MAPPING] = {.type = NLA_U8},
109 [DCB_TC_ATTR_PARAM_STRICT_PRIO] = {.type = NLA_U8}, 110 [DCB_TC_ATTR_PARAM_STRICT_PRIO] = {.type = NLA_U8},
@@ -112,7 +113,7 @@ static struct nla_policy dcbnl_tc_param_nest[DCB_TC_ATTR_PARAM_MAX + 1] = {
112}; 113};
113 114
114/* DCB capabilities nested attributes. */ 115/* DCB capabilities nested attributes. */
115static struct nla_policy dcbnl_cap_nest[DCB_CAP_ATTR_MAX + 1] = { 116static const struct nla_policy dcbnl_cap_nest[DCB_CAP_ATTR_MAX + 1] = {
116 [DCB_CAP_ATTR_ALL] = {.type = NLA_FLAG}, 117 [DCB_CAP_ATTR_ALL] = {.type = NLA_FLAG},
117 [DCB_CAP_ATTR_PG] = {.type = NLA_U8}, 118 [DCB_CAP_ATTR_PG] = {.type = NLA_U8},
118 [DCB_CAP_ATTR_PFC] = {.type = NLA_U8}, 119 [DCB_CAP_ATTR_PFC] = {.type = NLA_U8},
@@ -124,14 +125,14 @@ static struct nla_policy dcbnl_cap_nest[DCB_CAP_ATTR_MAX + 1] = {
124}; 125};
125 126
126/* DCB capabilities nested attributes. */ 127/* DCB capabilities nested attributes. */
127static struct nla_policy dcbnl_numtcs_nest[DCB_NUMTCS_ATTR_MAX + 1] = { 128static const struct nla_policy dcbnl_numtcs_nest[DCB_NUMTCS_ATTR_MAX + 1] = {
128 [DCB_NUMTCS_ATTR_ALL] = {.type = NLA_FLAG}, 129 [DCB_NUMTCS_ATTR_ALL] = {.type = NLA_FLAG},
129 [DCB_NUMTCS_ATTR_PG] = {.type = NLA_U8}, 130 [DCB_NUMTCS_ATTR_PG] = {.type = NLA_U8},
130 [DCB_NUMTCS_ATTR_PFC] = {.type = NLA_U8}, 131 [DCB_NUMTCS_ATTR_PFC] = {.type = NLA_U8},
131}; 132};
132 133
133/* DCB BCN nested attributes. */ 134/* DCB BCN nested attributes. */
134static struct nla_policy dcbnl_bcn_nest[DCB_BCN_ATTR_MAX + 1] = { 135static const struct nla_policy dcbnl_bcn_nest[DCB_BCN_ATTR_MAX + 1] = {
135 [DCB_BCN_ATTR_RP_0] = {.type = NLA_U8}, 136 [DCB_BCN_ATTR_RP_0] = {.type = NLA_U8},
136 [DCB_BCN_ATTR_RP_1] = {.type = NLA_U8}, 137 [DCB_BCN_ATTR_RP_1] = {.type = NLA_U8},
137 [DCB_BCN_ATTR_RP_2] = {.type = NLA_U8}, 138 [DCB_BCN_ATTR_RP_2] = {.type = NLA_U8},
@@ -160,7 +161,7 @@ static struct nla_policy dcbnl_bcn_nest[DCB_BCN_ATTR_MAX + 1] = {
160}; 161};
161 162
162/* DCB APP nested attributes. */ 163/* DCB APP nested attributes. */
163static struct nla_policy dcbnl_app_nest[DCB_APP_ATTR_MAX + 1] = { 164static const struct nla_policy dcbnl_app_nest[DCB_APP_ATTR_MAX + 1] = {
164 [DCB_APP_ATTR_IDTYPE] = {.type = NLA_U8}, 165 [DCB_APP_ATTR_IDTYPE] = {.type = NLA_U8},
165 [DCB_APP_ATTR_ID] = {.type = NLA_U16}, 166 [DCB_APP_ATTR_ID] = {.type = NLA_U16},
166 [DCB_APP_ATTR_PRIORITY] = {.type = NLA_U8}, 167 [DCB_APP_ATTR_PRIORITY] = {.type = NLA_U8},
@@ -1085,8 +1086,8 @@ static int dcbnl_bcn_setcfg(struct net_device *netdev, struct nlattr **tb,
1085 u8 value_byte; 1086 u8 value_byte;
1086 u32 value_int; 1087 u32 value_int;
1087 1088
1088 if (!tb[DCB_ATTR_BCN] || !netdev->dcbnl_ops->setbcncfg 1089 if (!tb[DCB_ATTR_BCN] || !netdev->dcbnl_ops->setbcncfg ||
1089 || !netdev->dcbnl_ops->setbcnrp) 1090 !netdev->dcbnl_ops->setbcnrp)
1090 return ret; 1091 return ret;
1091 1092
1092 ret = nla_parse_nested(data, DCB_BCN_ATTR_MAX, 1093 ret = nla_parse_nested(data, DCB_BCN_ATTR_MAX,
@@ -1126,7 +1127,7 @@ static int dcb_doit(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
1126 u32 pid = skb ? NETLINK_CB(skb).pid : 0; 1127 u32 pid = skb ? NETLINK_CB(skb).pid : 0;
1127 int ret = -EINVAL; 1128 int ret = -EINVAL;
1128 1129
1129 if (net != &init_net) 1130 if (!net_eq(net, &init_net))
1130 return -EINVAL; 1131 return -EINVAL;
1131 1132
1132 ret = nlmsg_parse(nlh, sizeof(*dcb), tb, DCB_ATTR_MAX, 1133 ret = nlmsg_parse(nlh, sizeof(*dcb), tb, DCB_ATTR_MAX,
diff --git a/net/dccp/ccid.c b/net/dccp/ccid.c
index f3e9ba1cfd01..36479ca61e03 100644
--- a/net/dccp/ccid.c
+++ b/net/dccp/ccid.c
@@ -11,6 +11,8 @@
11 * published by the Free Software Foundation. 11 * published by the Free Software Foundation.
12 */ 12 */
13 13
14#include <linux/slab.h>
15
14#include "ccid.h" 16#include "ccid.h"
15#include "ccids/lib/tfrc.h" 17#include "ccids/lib/tfrc.h"
16 18
@@ -63,48 +65,37 @@ int ccid_getsockopt_builtin_ccids(struct sock *sk, int len,
63 u8 *ccid_array, array_len; 65 u8 *ccid_array, array_len;
64 int err = 0; 66 int err = 0;
65 67
66 if (len < ARRAY_SIZE(ccids))
67 return -EINVAL;
68
69 if (ccid_get_builtin_ccids(&ccid_array, &array_len)) 68 if (ccid_get_builtin_ccids(&ccid_array, &array_len))
70 return -ENOBUFS; 69 return -ENOBUFS;
71 70
72 if (put_user(array_len, optlen) || 71 if (put_user(array_len, optlen))
73 copy_to_user(optval, ccid_array, array_len)) 72 err = -EFAULT;
73 else if (len > 0 && copy_to_user(optval, ccid_array,
74 len > array_len ? array_len : len))
74 err = -EFAULT; 75 err = -EFAULT;
75 76
76 kfree(ccid_array); 77 kfree(ccid_array);
77 return err; 78 return err;
78} 79}
79 80
80static struct kmem_cache *ccid_kmem_cache_create(int obj_size, const char *fmt,...) 81static struct kmem_cache *ccid_kmem_cache_create(int obj_size, char *slab_name_fmt, const char *fmt,...)
81{ 82{
82 struct kmem_cache *slab; 83 struct kmem_cache *slab;
83 char slab_name_fmt[32], *slab_name;
84 va_list args; 84 va_list args;
85 85
86 va_start(args, fmt); 86 va_start(args, fmt);
87 vsnprintf(slab_name_fmt, sizeof(slab_name_fmt), fmt, args); 87 vsnprintf(slab_name_fmt, CCID_SLAB_NAME_LENGTH, fmt, args);
88 va_end(args); 88 va_end(args);
89 89
90 slab_name = kstrdup(slab_name_fmt, GFP_KERNEL); 90 slab = kmem_cache_create(slab_name_fmt, sizeof(struct ccid) + obj_size, 0,
91 if (slab_name == NULL)
92 return NULL;
93 slab = kmem_cache_create(slab_name, sizeof(struct ccid) + obj_size, 0,
94 SLAB_HWCACHE_ALIGN, NULL); 91 SLAB_HWCACHE_ALIGN, NULL);
95 if (slab == NULL)
96 kfree(slab_name);
97 return slab; 92 return slab;
98} 93}
99 94
100static void ccid_kmem_cache_destroy(struct kmem_cache *slab) 95static void ccid_kmem_cache_destroy(struct kmem_cache *slab)
101{ 96{
102 if (slab != NULL) { 97 if (slab != NULL)
103 const char *name = kmem_cache_name(slab);
104
105 kmem_cache_destroy(slab); 98 kmem_cache_destroy(slab);
106 kfree(name);
107 }
108} 99}
109 100
110static int ccid_activate(struct ccid_operations *ccid_ops) 101static int ccid_activate(struct ccid_operations *ccid_ops)
@@ -113,6 +104,7 @@ static int ccid_activate(struct ccid_operations *ccid_ops)
113 104
114 ccid_ops->ccid_hc_rx_slab = 105 ccid_ops->ccid_hc_rx_slab =
115 ccid_kmem_cache_create(ccid_ops->ccid_hc_rx_obj_size, 106 ccid_kmem_cache_create(ccid_ops->ccid_hc_rx_obj_size,
107 ccid_ops->ccid_hc_rx_slab_name,
116 "ccid%u_hc_rx_sock", 108 "ccid%u_hc_rx_sock",
117 ccid_ops->ccid_id); 109 ccid_ops->ccid_id);
118 if (ccid_ops->ccid_hc_rx_slab == NULL) 110 if (ccid_ops->ccid_hc_rx_slab == NULL)
@@ -120,6 +112,7 @@ static int ccid_activate(struct ccid_operations *ccid_ops)
120 112
121 ccid_ops->ccid_hc_tx_slab = 113 ccid_ops->ccid_hc_tx_slab =
122 ccid_kmem_cache_create(ccid_ops->ccid_hc_tx_obj_size, 114 ccid_kmem_cache_create(ccid_ops->ccid_hc_tx_obj_size,
115 ccid_ops->ccid_hc_tx_slab_name,
123 "ccid%u_hc_tx_sock", 116 "ccid%u_hc_tx_sock",
124 ccid_ops->ccid_id); 117 ccid_ops->ccid_id);
125 if (ccid_ops->ccid_hc_tx_slab == NULL) 118 if (ccid_ops->ccid_hc_tx_slab == NULL)
diff --git a/net/dccp/ccid.h b/net/dccp/ccid.h
index facedd20b531..6df6f8ac9636 100644
--- a/net/dccp/ccid.h
+++ b/net/dccp/ccid.h
@@ -19,7 +19,9 @@
19#include <linux/list.h> 19#include <linux/list.h>
20#include <linux/module.h> 20#include <linux/module.h>
21 21
22#define CCID_MAX 255 22/* maximum value for a CCID (RFC 4340, 19.5) */
23#define CCID_MAX 255
24#define CCID_SLAB_NAME_LENGTH 32
23 25
24struct tcp_info; 26struct tcp_info;
25 27
@@ -49,6 +51,8 @@ struct ccid_operations {
49 const char *ccid_name; 51 const char *ccid_name;
50 struct kmem_cache *ccid_hc_rx_slab, 52 struct kmem_cache *ccid_hc_rx_slab,
51 *ccid_hc_tx_slab; 53 *ccid_hc_tx_slab;
54 char ccid_hc_rx_slab_name[CCID_SLAB_NAME_LENGTH];
55 char ccid_hc_tx_slab_name[CCID_SLAB_NAME_LENGTH];
52 __u32 ccid_hc_rx_obj_size, 56 __u32 ccid_hc_rx_obj_size,
53 ccid_hc_tx_obj_size; 57 ccid_hc_tx_obj_size;
54 /* Interface Routines */ 58 /* Interface Routines */
diff --git a/net/dccp/ccids/ccid2.c b/net/dccp/ccids/ccid2.c
index e8cf99e880b0..9b3ae9922be1 100644
--- a/net/dccp/ccids/ccid2.c
+++ b/net/dccp/ccids/ccid2.c
@@ -23,6 +23,7 @@
23/* 23/*
24 * This implementation should follow RFC 4341 24 * This implementation should follow RFC 4341
25 */ 25 */
26#include <linux/slab.h>
26#include "../feat.h" 27#include "../feat.h"
27#include "../ccid.h" 28#include "../ccid.h"
28#include "../dccp.h" 29#include "../dccp.h"
@@ -33,20 +34,20 @@
33static int ccid2_debug; 34static int ccid2_debug;
34#define ccid2_pr_debug(format, a...) DCCP_PR_DEBUG(ccid2_debug, format, ##a) 35#define ccid2_pr_debug(format, a...) DCCP_PR_DEBUG(ccid2_debug, format, ##a)
35 36
36static void ccid2_hc_tx_check_sanity(const struct ccid2_hc_tx_sock *hctx) 37static void ccid2_hc_tx_check_sanity(const struct ccid2_hc_tx_sock *hc)
37{ 38{
38 int len = 0; 39 int len = 0;
39 int pipe = 0; 40 int pipe = 0;
40 struct ccid2_seq *seqp = hctx->ccid2hctx_seqh; 41 struct ccid2_seq *seqp = hc->tx_seqh;
41 42
42 /* there is data in the chain */ 43 /* there is data in the chain */
43 if (seqp != hctx->ccid2hctx_seqt) { 44 if (seqp != hc->tx_seqt) {
44 seqp = seqp->ccid2s_prev; 45 seqp = seqp->ccid2s_prev;
45 len++; 46 len++;
46 if (!seqp->ccid2s_acked) 47 if (!seqp->ccid2s_acked)
47 pipe++; 48 pipe++;
48 49
49 while (seqp != hctx->ccid2hctx_seqt) { 50 while (seqp != hc->tx_seqt) {
50 struct ccid2_seq *prev = seqp->ccid2s_prev; 51 struct ccid2_seq *prev = seqp->ccid2s_prev;
51 52
52 len++; 53 len++;
@@ -63,30 +64,30 @@ static void ccid2_hc_tx_check_sanity(const struct ccid2_hc_tx_sock *hctx)
63 } 64 }
64 } 65 }
65 66
66 BUG_ON(pipe != hctx->ccid2hctx_pipe); 67 BUG_ON(pipe != hc->tx_pipe);
67 ccid2_pr_debug("len of chain=%d\n", len); 68 ccid2_pr_debug("len of chain=%d\n", len);
68 69
69 do { 70 do {
70 seqp = seqp->ccid2s_prev; 71 seqp = seqp->ccid2s_prev;
71 len++; 72 len++;
72 } while (seqp != hctx->ccid2hctx_seqh); 73 } while (seqp != hc->tx_seqh);
73 74
74 ccid2_pr_debug("total len=%d\n", len); 75 ccid2_pr_debug("total len=%d\n", len);
75 BUG_ON(len != hctx->ccid2hctx_seqbufc * CCID2_SEQBUF_LEN); 76 BUG_ON(len != hc->tx_seqbufc * CCID2_SEQBUF_LEN);
76} 77}
77#else 78#else
78#define ccid2_pr_debug(format, a...) 79#define ccid2_pr_debug(format, a...)
79#define ccid2_hc_tx_check_sanity(hctx) 80#define ccid2_hc_tx_check_sanity(hc)
80#endif 81#endif
81 82
82static int ccid2_hc_tx_alloc_seq(struct ccid2_hc_tx_sock *hctx) 83static int ccid2_hc_tx_alloc_seq(struct ccid2_hc_tx_sock *hc)
83{ 84{
84 struct ccid2_seq *seqp; 85 struct ccid2_seq *seqp;
85 int i; 86 int i;
86 87
87 /* check if we have space to preserve the pointer to the buffer */ 88 /* check if we have space to preserve the pointer to the buffer */
88 if (hctx->ccid2hctx_seqbufc >= (sizeof(hctx->ccid2hctx_seqbuf) / 89 if (hc->tx_seqbufc >= (sizeof(hc->tx_seqbuf) /
89 sizeof(struct ccid2_seq*))) 90 sizeof(struct ccid2_seq *)))
90 return -ENOMEM; 91 return -ENOMEM;
91 92
92 /* allocate buffer and initialize linked list */ 93 /* allocate buffer and initialize linked list */
@@ -102,29 +103,29 @@ static int ccid2_hc_tx_alloc_seq(struct ccid2_hc_tx_sock *hctx)
102 seqp->ccid2s_prev = &seqp[CCID2_SEQBUF_LEN - 1]; 103 seqp->ccid2s_prev = &seqp[CCID2_SEQBUF_LEN - 1];
103 104
104 /* This is the first allocation. Initiate the head and tail. */ 105 /* This is the first allocation. Initiate the head and tail. */
105 if (hctx->ccid2hctx_seqbufc == 0) 106 if (hc->tx_seqbufc == 0)
106 hctx->ccid2hctx_seqh = hctx->ccid2hctx_seqt = seqp; 107 hc->tx_seqh = hc->tx_seqt = seqp;
107 else { 108 else {
108 /* link the existing list with the one we just created */ 109 /* link the existing list with the one we just created */
109 hctx->ccid2hctx_seqh->ccid2s_next = seqp; 110 hc->tx_seqh->ccid2s_next = seqp;
110 seqp->ccid2s_prev = hctx->ccid2hctx_seqh; 111 seqp->ccid2s_prev = hc->tx_seqh;
111 112
112 hctx->ccid2hctx_seqt->ccid2s_prev = &seqp[CCID2_SEQBUF_LEN - 1]; 113 hc->tx_seqt->ccid2s_prev = &seqp[CCID2_SEQBUF_LEN - 1];
113 seqp[CCID2_SEQBUF_LEN - 1].ccid2s_next = hctx->ccid2hctx_seqt; 114 seqp[CCID2_SEQBUF_LEN - 1].ccid2s_next = hc->tx_seqt;
114 } 115 }
115 116
116 /* store the original pointer to the buffer so we can free it */ 117 /* store the original pointer to the buffer so we can free it */
117 hctx->ccid2hctx_seqbuf[hctx->ccid2hctx_seqbufc] = seqp; 118 hc->tx_seqbuf[hc->tx_seqbufc] = seqp;
118 hctx->ccid2hctx_seqbufc++; 119 hc->tx_seqbufc++;
119 120
120 return 0; 121 return 0;
121} 122}
122 123
123static int ccid2_hc_tx_send_packet(struct sock *sk, struct sk_buff *skb) 124static int ccid2_hc_tx_send_packet(struct sock *sk, struct sk_buff *skb)
124{ 125{
125 struct ccid2_hc_tx_sock *hctx = ccid2_hc_tx_sk(sk); 126 struct ccid2_hc_tx_sock *hc = ccid2_hc_tx_sk(sk);
126 127
127 if (hctx->ccid2hctx_pipe < hctx->ccid2hctx_cwnd) 128 if (hc->tx_pipe < hc->tx_cwnd)
128 return 0; 129 return 0;
129 130
130 return 1; /* XXX CCID should dequeue when ready instead of polling */ 131 return 1; /* XXX CCID should dequeue when ready instead of polling */
@@ -133,7 +134,7 @@ static int ccid2_hc_tx_send_packet(struct sock *sk, struct sk_buff *skb)
133static void ccid2_change_l_ack_ratio(struct sock *sk, u32 val) 134static void ccid2_change_l_ack_ratio(struct sock *sk, u32 val)
134{ 135{
135 struct dccp_sock *dp = dccp_sk(sk); 136 struct dccp_sock *dp = dccp_sk(sk);
136 u32 max_ratio = DIV_ROUND_UP(ccid2_hc_tx_sk(sk)->ccid2hctx_cwnd, 2); 137 u32 max_ratio = DIV_ROUND_UP(ccid2_hc_tx_sk(sk)->tx_cwnd, 2);
137 138
138 /* 139 /*
139 * Ensure that Ack Ratio does not exceed ceil(cwnd/2), which is (2) from 140 * Ensure that Ack Ratio does not exceed ceil(cwnd/2), which is (2) from
@@ -155,10 +156,10 @@ static void ccid2_change_l_ack_ratio(struct sock *sk, u32 val)
155 dp->dccps_l_ack_ratio = val; 156 dp->dccps_l_ack_ratio = val;
156} 157}
157 158
158static void ccid2_change_srtt(struct ccid2_hc_tx_sock *hctx, long val) 159static void ccid2_change_srtt(struct ccid2_hc_tx_sock *hc, long val)
159{ 160{
160 ccid2_pr_debug("change SRTT to %ld\n", val); 161 ccid2_pr_debug("change SRTT to %ld\n", val);
161 hctx->ccid2hctx_srtt = val; 162 hc->tx_srtt = val;
162} 163}
163 164
164static void ccid2_start_rto_timer(struct sock *sk); 165static void ccid2_start_rto_timer(struct sock *sk);
@@ -166,45 +167,44 @@ static void ccid2_start_rto_timer(struct sock *sk);
166static void ccid2_hc_tx_rto_expire(unsigned long data) 167static void ccid2_hc_tx_rto_expire(unsigned long data)
167{ 168{
168 struct sock *sk = (struct sock *)data; 169 struct sock *sk = (struct sock *)data;
169 struct ccid2_hc_tx_sock *hctx = ccid2_hc_tx_sk(sk); 170 struct ccid2_hc_tx_sock *hc = ccid2_hc_tx_sk(sk);
170 long s; 171 long s;
171 172
172 bh_lock_sock(sk); 173 bh_lock_sock(sk);
173 if (sock_owned_by_user(sk)) { 174 if (sock_owned_by_user(sk)) {
174 sk_reset_timer(sk, &hctx->ccid2hctx_rtotimer, 175 sk_reset_timer(sk, &hc->tx_rtotimer, jiffies + HZ / 5);
175 jiffies + HZ / 5);
176 goto out; 176 goto out;
177 } 177 }
178 178
179 ccid2_pr_debug("RTO_EXPIRE\n"); 179 ccid2_pr_debug("RTO_EXPIRE\n");
180 180
181 ccid2_hc_tx_check_sanity(hctx); 181 ccid2_hc_tx_check_sanity(hc);
182 182
183 /* back-off timer */ 183 /* back-off timer */
184 hctx->ccid2hctx_rto <<= 1; 184 hc->tx_rto <<= 1;
185 185
186 s = hctx->ccid2hctx_rto / HZ; 186 s = hc->tx_rto / HZ;
187 if (s > 60) 187 if (s > 60)
188 hctx->ccid2hctx_rto = 60 * HZ; 188 hc->tx_rto = 60 * HZ;
189 189
190 ccid2_start_rto_timer(sk); 190 ccid2_start_rto_timer(sk);
191 191
192 /* adjust pipe, cwnd etc */ 192 /* adjust pipe, cwnd etc */
193 hctx->ccid2hctx_ssthresh = hctx->ccid2hctx_cwnd / 2; 193 hc->tx_ssthresh = hc->tx_cwnd / 2;
194 if (hctx->ccid2hctx_ssthresh < 2) 194 if (hc->tx_ssthresh < 2)
195 hctx->ccid2hctx_ssthresh = 2; 195 hc->tx_ssthresh = 2;
196 hctx->ccid2hctx_cwnd = 1; 196 hc->tx_cwnd = 1;
197 hctx->ccid2hctx_pipe = 0; 197 hc->tx_pipe = 0;
198 198
199 /* clear state about stuff we sent */ 199 /* clear state about stuff we sent */
200 hctx->ccid2hctx_seqt = hctx->ccid2hctx_seqh; 200 hc->tx_seqt = hc->tx_seqh;
201 hctx->ccid2hctx_packets_acked = 0; 201 hc->tx_packets_acked = 0;
202 202
203 /* clear ack ratio state. */ 203 /* clear ack ratio state. */
204 hctx->ccid2hctx_rpseq = 0; 204 hc->tx_rpseq = 0;
205 hctx->ccid2hctx_rpdupack = -1; 205 hc->tx_rpdupack = -1;
206 ccid2_change_l_ack_ratio(sk, 1); 206 ccid2_change_l_ack_ratio(sk, 1);
207 ccid2_hc_tx_check_sanity(hctx); 207 ccid2_hc_tx_check_sanity(hc);
208out: 208out:
209 bh_unlock_sock(sk); 209 bh_unlock_sock(sk);
210 sock_put(sk); 210 sock_put(sk);
@@ -212,42 +212,40 @@ out:
212 212
213static void ccid2_start_rto_timer(struct sock *sk) 213static void ccid2_start_rto_timer(struct sock *sk)
214{ 214{
215 struct ccid2_hc_tx_sock *hctx = ccid2_hc_tx_sk(sk); 215 struct ccid2_hc_tx_sock *hc = ccid2_hc_tx_sk(sk);
216 216
217 ccid2_pr_debug("setting RTO timeout=%ld\n", hctx->ccid2hctx_rto); 217 ccid2_pr_debug("setting RTO timeout=%ld\n", hc->tx_rto);
218 218
219 BUG_ON(timer_pending(&hctx->ccid2hctx_rtotimer)); 219 BUG_ON(timer_pending(&hc->tx_rtotimer));
220 sk_reset_timer(sk, &hctx->ccid2hctx_rtotimer, 220 sk_reset_timer(sk, &hc->tx_rtotimer, jiffies + hc->tx_rto);
221 jiffies + hctx->ccid2hctx_rto);
222} 221}
223 222
224static void ccid2_hc_tx_packet_sent(struct sock *sk, int more, unsigned int len) 223static void ccid2_hc_tx_packet_sent(struct sock *sk, int more, unsigned int len)
225{ 224{
226 struct dccp_sock *dp = dccp_sk(sk); 225 struct dccp_sock *dp = dccp_sk(sk);
227 struct ccid2_hc_tx_sock *hctx = ccid2_hc_tx_sk(sk); 226 struct ccid2_hc_tx_sock *hc = ccid2_hc_tx_sk(sk);
228 struct ccid2_seq *next; 227 struct ccid2_seq *next;
229 228
230 hctx->ccid2hctx_pipe++; 229 hc->tx_pipe++;
231 230
232 hctx->ccid2hctx_seqh->ccid2s_seq = dp->dccps_gss; 231 hc->tx_seqh->ccid2s_seq = dp->dccps_gss;
233 hctx->ccid2hctx_seqh->ccid2s_acked = 0; 232 hc->tx_seqh->ccid2s_acked = 0;
234 hctx->ccid2hctx_seqh->ccid2s_sent = jiffies; 233 hc->tx_seqh->ccid2s_sent = jiffies;
235 234
236 next = hctx->ccid2hctx_seqh->ccid2s_next; 235 next = hc->tx_seqh->ccid2s_next;
237 /* check if we need to alloc more space */ 236 /* check if we need to alloc more space */
238 if (next == hctx->ccid2hctx_seqt) { 237 if (next == hc->tx_seqt) {
239 if (ccid2_hc_tx_alloc_seq(hctx)) { 238 if (ccid2_hc_tx_alloc_seq(hc)) {
240 DCCP_CRIT("packet history - out of memory!"); 239 DCCP_CRIT("packet history - out of memory!");
241 /* FIXME: find a more graceful way to bail out */ 240 /* FIXME: find a more graceful way to bail out */
242 return; 241 return;
243 } 242 }
244 next = hctx->ccid2hctx_seqh->ccid2s_next; 243 next = hc->tx_seqh->ccid2s_next;
245 BUG_ON(next == hctx->ccid2hctx_seqt); 244 BUG_ON(next == hc->tx_seqt);
246 } 245 }
247 hctx->ccid2hctx_seqh = next; 246 hc->tx_seqh = next;
248 247
249 ccid2_pr_debug("cwnd=%d pipe=%d\n", hctx->ccid2hctx_cwnd, 248 ccid2_pr_debug("cwnd=%d pipe=%d\n", hc->tx_cwnd, hc->tx_pipe);
250 hctx->ccid2hctx_pipe);
251 249
252 /* 250 /*
253 * FIXME: The code below is broken and the variables have been removed 251 * FIXME: The code below is broken and the variables have been removed
@@ -270,12 +268,12 @@ static void ccid2_hc_tx_packet_sent(struct sock *sk, int more, unsigned int len)
270 */ 268 */
271#if 0 269#if 0
272 /* Ack Ratio. Need to maintain a concept of how many windows we sent */ 270 /* Ack Ratio. Need to maintain a concept of how many windows we sent */
273 hctx->ccid2hctx_arsent++; 271 hc->tx_arsent++;
274 /* We had an ack loss in this window... */ 272 /* We had an ack loss in this window... */
275 if (hctx->ccid2hctx_ackloss) { 273 if (hc->tx_ackloss) {
276 if (hctx->ccid2hctx_arsent >= hctx->ccid2hctx_cwnd) { 274 if (hc->tx_arsent >= hc->tx_cwnd) {
277 hctx->ccid2hctx_arsent = 0; 275 hc->tx_arsent = 0;
278 hctx->ccid2hctx_ackloss = 0; 276 hc->tx_ackloss = 0;
279 } 277 }
280 } else { 278 } else {
281 /* No acks lost up to now... */ 279 /* No acks lost up to now... */
@@ -285,28 +283,28 @@ static void ccid2_hc_tx_packet_sent(struct sock *sk, int more, unsigned int len)
285 int denom = dp->dccps_l_ack_ratio * dp->dccps_l_ack_ratio - 283 int denom = dp->dccps_l_ack_ratio * dp->dccps_l_ack_ratio -
286 dp->dccps_l_ack_ratio; 284 dp->dccps_l_ack_ratio;
287 285
288 denom = hctx->ccid2hctx_cwnd * hctx->ccid2hctx_cwnd / denom; 286 denom = hc->tx_cwnd * hc->tx_cwnd / denom;
289 287
290 if (hctx->ccid2hctx_arsent >= denom) { 288 if (hc->tx_arsent >= denom) {
291 ccid2_change_l_ack_ratio(sk, dp->dccps_l_ack_ratio - 1); 289 ccid2_change_l_ack_ratio(sk, dp->dccps_l_ack_ratio - 1);
292 hctx->ccid2hctx_arsent = 0; 290 hc->tx_arsent = 0;
293 } 291 }
294 } else { 292 } else {
295 /* we can't increase ack ratio further [1] */ 293 /* we can't increase ack ratio further [1] */
296 hctx->ccid2hctx_arsent = 0; /* or maybe set it to cwnd*/ 294 hc->tx_arsent = 0; /* or maybe set it to cwnd*/
297 } 295 }
298 } 296 }
299#endif 297#endif
300 298
301 /* setup RTO timer */ 299 /* setup RTO timer */
302 if (!timer_pending(&hctx->ccid2hctx_rtotimer)) 300 if (!timer_pending(&hc->tx_rtotimer))
303 ccid2_start_rto_timer(sk); 301 ccid2_start_rto_timer(sk);
304 302
305#ifdef CONFIG_IP_DCCP_CCID2_DEBUG 303#ifdef CONFIG_IP_DCCP_CCID2_DEBUG
306 do { 304 do {
307 struct ccid2_seq *seqp = hctx->ccid2hctx_seqt; 305 struct ccid2_seq *seqp = hc->tx_seqt;
308 306
309 while (seqp != hctx->ccid2hctx_seqh) { 307 while (seqp != hc->tx_seqh) {
310 ccid2_pr_debug("out seq=%llu acked=%d time=%lu\n", 308 ccid2_pr_debug("out seq=%llu acked=%d time=%lu\n",
311 (unsigned long long)seqp->ccid2s_seq, 309 (unsigned long long)seqp->ccid2s_seq,
312 seqp->ccid2s_acked, seqp->ccid2s_sent); 310 seqp->ccid2s_acked, seqp->ccid2s_sent);
@@ -314,7 +312,7 @@ static void ccid2_hc_tx_packet_sent(struct sock *sk, int more, unsigned int len)
314 } 312 }
315 } while (0); 313 } while (0);
316 ccid2_pr_debug("=========\n"); 314 ccid2_pr_debug("=========\n");
317 ccid2_hc_tx_check_sanity(hctx); 315 ccid2_hc_tx_check_sanity(hc);
318#endif 316#endif
319} 317}
320 318
@@ -382,9 +380,9 @@ out_invalid_option:
382 380
383static void ccid2_hc_tx_kill_rto_timer(struct sock *sk) 381static void ccid2_hc_tx_kill_rto_timer(struct sock *sk)
384{ 382{
385 struct ccid2_hc_tx_sock *hctx = ccid2_hc_tx_sk(sk); 383 struct ccid2_hc_tx_sock *hc = ccid2_hc_tx_sk(sk);
386 384
387 sk_stop_timer(sk, &hctx->ccid2hctx_rtotimer); 385 sk_stop_timer(sk, &hc->tx_rtotimer);
388 ccid2_pr_debug("deleted RTO timer\n"); 386 ccid2_pr_debug("deleted RTO timer\n");
389} 387}
390 388
@@ -392,75 +390,75 @@ static inline void ccid2_new_ack(struct sock *sk,
392 struct ccid2_seq *seqp, 390 struct ccid2_seq *seqp,
393 unsigned int *maxincr) 391 unsigned int *maxincr)
394{ 392{
395 struct ccid2_hc_tx_sock *hctx = ccid2_hc_tx_sk(sk); 393 struct ccid2_hc_tx_sock *hc = ccid2_hc_tx_sk(sk);
396 394
397 if (hctx->ccid2hctx_cwnd < hctx->ccid2hctx_ssthresh) { 395 if (hc->tx_cwnd < hc->tx_ssthresh) {
398 if (*maxincr > 0 && ++hctx->ccid2hctx_packets_acked == 2) { 396 if (*maxincr > 0 && ++hc->tx_packets_acked == 2) {
399 hctx->ccid2hctx_cwnd += 1; 397 hc->tx_cwnd += 1;
400 *maxincr -= 1; 398 *maxincr -= 1;
401 hctx->ccid2hctx_packets_acked = 0; 399 hc->tx_packets_acked = 0;
402 } 400 }
403 } else if (++hctx->ccid2hctx_packets_acked >= hctx->ccid2hctx_cwnd) { 401 } else if (++hc->tx_packets_acked >= hc->tx_cwnd) {
404 hctx->ccid2hctx_cwnd += 1; 402 hc->tx_cwnd += 1;
405 hctx->ccid2hctx_packets_acked = 0; 403 hc->tx_packets_acked = 0;
406 } 404 }
407 405
408 /* update RTO */ 406 /* update RTO */
409 if (hctx->ccid2hctx_srtt == -1 || 407 if (hc->tx_srtt == -1 ||
410 time_after(jiffies, hctx->ccid2hctx_lastrtt + hctx->ccid2hctx_srtt)) { 408 time_after(jiffies, hc->tx_lastrtt + hc->tx_srtt)) {
411 unsigned long r = (long)jiffies - (long)seqp->ccid2s_sent; 409 unsigned long r = (long)jiffies - (long)seqp->ccid2s_sent;
412 int s; 410 int s;
413 411
414 /* first measurement */ 412 /* first measurement */
415 if (hctx->ccid2hctx_srtt == -1) { 413 if (hc->tx_srtt == -1) {
416 ccid2_pr_debug("R: %lu Time=%lu seq=%llu\n", 414 ccid2_pr_debug("R: %lu Time=%lu seq=%llu\n",
417 r, jiffies, 415 r, jiffies,
418 (unsigned long long)seqp->ccid2s_seq); 416 (unsigned long long)seqp->ccid2s_seq);
419 ccid2_change_srtt(hctx, r); 417 ccid2_change_srtt(hc, r);
420 hctx->ccid2hctx_rttvar = r >> 1; 418 hc->tx_rttvar = r >> 1;
421 } else { 419 } else {
422 /* RTTVAR */ 420 /* RTTVAR */
423 long tmp = hctx->ccid2hctx_srtt - r; 421 long tmp = hc->tx_srtt - r;
424 long srtt; 422 long srtt;
425 423
426 if (tmp < 0) 424 if (tmp < 0)
427 tmp *= -1; 425 tmp *= -1;
428 426
429 tmp >>= 2; 427 tmp >>= 2;
430 hctx->ccid2hctx_rttvar *= 3; 428 hc->tx_rttvar *= 3;
431 hctx->ccid2hctx_rttvar >>= 2; 429 hc->tx_rttvar >>= 2;
432 hctx->ccid2hctx_rttvar += tmp; 430 hc->tx_rttvar += tmp;
433 431
434 /* SRTT */ 432 /* SRTT */
435 srtt = hctx->ccid2hctx_srtt; 433 srtt = hc->tx_srtt;
436 srtt *= 7; 434 srtt *= 7;
437 srtt >>= 3; 435 srtt >>= 3;
438 tmp = r >> 3; 436 tmp = r >> 3;
439 srtt += tmp; 437 srtt += tmp;
440 ccid2_change_srtt(hctx, srtt); 438 ccid2_change_srtt(hc, srtt);
441 } 439 }
442 s = hctx->ccid2hctx_rttvar << 2; 440 s = hc->tx_rttvar << 2;
443 /* clock granularity is 1 when based on jiffies */ 441 /* clock granularity is 1 when based on jiffies */
444 if (!s) 442 if (!s)
445 s = 1; 443 s = 1;
446 hctx->ccid2hctx_rto = hctx->ccid2hctx_srtt + s; 444 hc->tx_rto = hc->tx_srtt + s;
447 445
448 /* must be at least a second */ 446 /* must be at least a second */
449 s = hctx->ccid2hctx_rto / HZ; 447 s = hc->tx_rto / HZ;
450 /* DCCP doesn't require this [but I like it cuz my code sux] */ 448 /* DCCP doesn't require this [but I like it cuz my code sux] */
451#if 1 449#if 1
452 if (s < 1) 450 if (s < 1)
453 hctx->ccid2hctx_rto = HZ; 451 hc->tx_rto = HZ;
454#endif 452#endif
455 /* max 60 seconds */ 453 /* max 60 seconds */
456 if (s > 60) 454 if (s > 60)
457 hctx->ccid2hctx_rto = HZ * 60; 455 hc->tx_rto = HZ * 60;
458 456
459 hctx->ccid2hctx_lastrtt = jiffies; 457 hc->tx_lastrtt = jiffies;
460 458
461 ccid2_pr_debug("srtt: %ld rttvar: %ld rto: %ld (HZ=%d) R=%lu\n", 459 ccid2_pr_debug("srtt: %ld rttvar: %ld rto: %ld (HZ=%d) R=%lu\n",
462 hctx->ccid2hctx_srtt, hctx->ccid2hctx_rttvar, 460 hc->tx_srtt, hc->tx_rttvar,
463 hctx->ccid2hctx_rto, HZ, r); 461 hc->tx_rto, HZ, r);
464 } 462 }
465 463
466 /* we got a new ack, so re-start RTO timer */ 464 /* we got a new ack, so re-start RTO timer */
@@ -470,40 +468,40 @@ static inline void ccid2_new_ack(struct sock *sk,
470 468
471static void ccid2_hc_tx_dec_pipe(struct sock *sk) 469static void ccid2_hc_tx_dec_pipe(struct sock *sk)
472{ 470{
473 struct ccid2_hc_tx_sock *hctx = ccid2_hc_tx_sk(sk); 471 struct ccid2_hc_tx_sock *hc = ccid2_hc_tx_sk(sk);
474 472
475 if (hctx->ccid2hctx_pipe == 0) 473 if (hc->tx_pipe == 0)
476 DCCP_BUG("pipe == 0"); 474 DCCP_BUG("pipe == 0");
477 else 475 else
478 hctx->ccid2hctx_pipe--; 476 hc->tx_pipe--;
479 477
480 if (hctx->ccid2hctx_pipe == 0) 478 if (hc->tx_pipe == 0)
481 ccid2_hc_tx_kill_rto_timer(sk); 479 ccid2_hc_tx_kill_rto_timer(sk);
482} 480}
483 481
484static void ccid2_congestion_event(struct sock *sk, struct ccid2_seq *seqp) 482static void ccid2_congestion_event(struct sock *sk, struct ccid2_seq *seqp)
485{ 483{
486 struct ccid2_hc_tx_sock *hctx = ccid2_hc_tx_sk(sk); 484 struct ccid2_hc_tx_sock *hc = ccid2_hc_tx_sk(sk);
487 485
488 if (time_before(seqp->ccid2s_sent, hctx->ccid2hctx_last_cong)) { 486 if (time_before(seqp->ccid2s_sent, hc->tx_last_cong)) {
489 ccid2_pr_debug("Multiple losses in an RTT---treating as one\n"); 487 ccid2_pr_debug("Multiple losses in an RTT---treating as one\n");
490 return; 488 return;
491 } 489 }
492 490
493 hctx->ccid2hctx_last_cong = jiffies; 491 hc->tx_last_cong = jiffies;
494 492
495 hctx->ccid2hctx_cwnd = hctx->ccid2hctx_cwnd / 2 ? : 1U; 493 hc->tx_cwnd = hc->tx_cwnd / 2 ? : 1U;
496 hctx->ccid2hctx_ssthresh = max(hctx->ccid2hctx_cwnd, 2U); 494 hc->tx_ssthresh = max(hc->tx_cwnd, 2U);
497 495
498 /* Avoid spurious timeouts resulting from Ack Ratio > cwnd */ 496 /* Avoid spurious timeouts resulting from Ack Ratio > cwnd */
499 if (dccp_sk(sk)->dccps_l_ack_ratio > hctx->ccid2hctx_cwnd) 497 if (dccp_sk(sk)->dccps_l_ack_ratio > hc->tx_cwnd)
500 ccid2_change_l_ack_ratio(sk, hctx->ccid2hctx_cwnd); 498 ccid2_change_l_ack_ratio(sk, hc->tx_cwnd);
501} 499}
502 500
503static void ccid2_hc_tx_packet_recv(struct sock *sk, struct sk_buff *skb) 501static void ccid2_hc_tx_packet_recv(struct sock *sk, struct sk_buff *skb)
504{ 502{
505 struct dccp_sock *dp = dccp_sk(sk); 503 struct dccp_sock *dp = dccp_sk(sk);
506 struct ccid2_hc_tx_sock *hctx = ccid2_hc_tx_sk(sk); 504 struct ccid2_hc_tx_sock *hc = ccid2_hc_tx_sk(sk);
507 u64 ackno, seqno; 505 u64 ackno, seqno;
508 struct ccid2_seq *seqp; 506 struct ccid2_seq *seqp;
509 unsigned char *vector; 507 unsigned char *vector;
@@ -512,7 +510,7 @@ static void ccid2_hc_tx_packet_recv(struct sock *sk, struct sk_buff *skb)
512 int done = 0; 510 int done = 0;
513 unsigned int maxincr = 0; 511 unsigned int maxincr = 0;
514 512
515 ccid2_hc_tx_check_sanity(hctx); 513 ccid2_hc_tx_check_sanity(hc);
516 /* check reverse path congestion */ 514 /* check reverse path congestion */
517 seqno = DCCP_SKB_CB(skb)->dccpd_seq; 515 seqno = DCCP_SKB_CB(skb)->dccpd_seq;
518 516
@@ -521,21 +519,21 @@ static void ccid2_hc_tx_packet_recv(struct sock *sk, struct sk_buff *skb)
521 * -sorbo. 519 * -sorbo.
522 */ 520 */
523 /* need to bootstrap */ 521 /* need to bootstrap */
524 if (hctx->ccid2hctx_rpdupack == -1) { 522 if (hc->tx_rpdupack == -1) {
525 hctx->ccid2hctx_rpdupack = 0; 523 hc->tx_rpdupack = 0;
526 hctx->ccid2hctx_rpseq = seqno; 524 hc->tx_rpseq = seqno;
527 } else { 525 } else {
528 /* check if packet is consecutive */ 526 /* check if packet is consecutive */
529 if (dccp_delta_seqno(hctx->ccid2hctx_rpseq, seqno) == 1) 527 if (dccp_delta_seqno(hc->tx_rpseq, seqno) == 1)
530 hctx->ccid2hctx_rpseq = seqno; 528 hc->tx_rpseq = seqno;
531 /* it's a later packet */ 529 /* it's a later packet */
532 else if (after48(seqno, hctx->ccid2hctx_rpseq)) { 530 else if (after48(seqno, hc->tx_rpseq)) {
533 hctx->ccid2hctx_rpdupack++; 531 hc->tx_rpdupack++;
534 532
535 /* check if we got enough dupacks */ 533 /* check if we got enough dupacks */
536 if (hctx->ccid2hctx_rpdupack >= NUMDUPACK) { 534 if (hc->tx_rpdupack >= NUMDUPACK) {
537 hctx->ccid2hctx_rpdupack = -1; /* XXX lame */ 535 hc->tx_rpdupack = -1; /* XXX lame */
538 hctx->ccid2hctx_rpseq = 0; 536 hc->tx_rpseq = 0;
539 537
540 ccid2_change_l_ack_ratio(sk, 2 * dp->dccps_l_ack_ratio); 538 ccid2_change_l_ack_ratio(sk, 2 * dp->dccps_l_ack_ratio);
541 } 539 }
@@ -544,7 +542,7 @@ static void ccid2_hc_tx_packet_recv(struct sock *sk, struct sk_buff *skb)
544 542
545 /* check forward path congestion */ 543 /* check forward path congestion */
546 /* still didn't send out new data packets */ 544 /* still didn't send out new data packets */
547 if (hctx->ccid2hctx_seqh == hctx->ccid2hctx_seqt) 545 if (hc->tx_seqh == hc->tx_seqt)
548 return; 546 return;
549 547
550 switch (DCCP_SKB_CB(skb)->dccpd_type) { 548 switch (DCCP_SKB_CB(skb)->dccpd_type) {
@@ -556,14 +554,14 @@ static void ccid2_hc_tx_packet_recv(struct sock *sk, struct sk_buff *skb)
556 } 554 }
557 555
558 ackno = DCCP_SKB_CB(skb)->dccpd_ack_seq; 556 ackno = DCCP_SKB_CB(skb)->dccpd_ack_seq;
559 if (after48(ackno, hctx->ccid2hctx_high_ack)) 557 if (after48(ackno, hc->tx_high_ack))
560 hctx->ccid2hctx_high_ack = ackno; 558 hc->tx_high_ack = ackno;
561 559
562 seqp = hctx->ccid2hctx_seqt; 560 seqp = hc->tx_seqt;
563 while (before48(seqp->ccid2s_seq, ackno)) { 561 while (before48(seqp->ccid2s_seq, ackno)) {
564 seqp = seqp->ccid2s_next; 562 seqp = seqp->ccid2s_next;
565 if (seqp == hctx->ccid2hctx_seqh) { 563 if (seqp == hc->tx_seqh) {
566 seqp = hctx->ccid2hctx_seqh->ccid2s_prev; 564 seqp = hc->tx_seqh->ccid2s_prev;
567 break; 565 break;
568 } 566 }
569 } 567 }
@@ -573,7 +571,7 @@ static void ccid2_hc_tx_packet_recv(struct sock *sk, struct sk_buff *skb)
573 * packets per acknowledgement. Rounding up avoids that cwnd is not 571 * packets per acknowledgement. Rounding up avoids that cwnd is not
574 * advanced when Ack Ratio is 1 and gives a slight edge otherwise. 572 * advanced when Ack Ratio is 1 and gives a slight edge otherwise.
575 */ 573 */
576 if (hctx->ccid2hctx_cwnd < hctx->ccid2hctx_ssthresh) 574 if (hc->tx_cwnd < hc->tx_ssthresh)
577 maxincr = DIV_ROUND_UP(dp->dccps_l_ack_ratio, 2); 575 maxincr = DIV_ROUND_UP(dp->dccps_l_ack_ratio, 2);
578 576
579 /* go through all ack vectors */ 577 /* go through all ack vectors */
@@ -592,7 +590,7 @@ static void ccid2_hc_tx_packet_recv(struct sock *sk, struct sk_buff *skb)
592 * seqnos. 590 * seqnos.
593 */ 591 */
594 while (after48(seqp->ccid2s_seq, ackno)) { 592 while (after48(seqp->ccid2s_seq, ackno)) {
595 if (seqp == hctx->ccid2hctx_seqt) { 593 if (seqp == hc->tx_seqt) {
596 done = 1; 594 done = 1;
597 break; 595 break;
598 } 596 }
@@ -624,7 +622,7 @@ static void ccid2_hc_tx_packet_recv(struct sock *sk, struct sk_buff *skb)
624 (unsigned long long)seqp->ccid2s_seq); 622 (unsigned long long)seqp->ccid2s_seq);
625 ccid2_hc_tx_dec_pipe(sk); 623 ccid2_hc_tx_dec_pipe(sk);
626 } 624 }
627 if (seqp == hctx->ccid2hctx_seqt) { 625 if (seqp == hc->tx_seqt) {
628 done = 1; 626 done = 1;
629 break; 627 break;
630 } 628 }
@@ -643,11 +641,11 @@ static void ccid2_hc_tx_packet_recv(struct sock *sk, struct sk_buff *skb)
643 /* The state about what is acked should be correct now 641 /* The state about what is acked should be correct now
644 * Check for NUMDUPACK 642 * Check for NUMDUPACK
645 */ 643 */
646 seqp = hctx->ccid2hctx_seqt; 644 seqp = hc->tx_seqt;
647 while (before48(seqp->ccid2s_seq, hctx->ccid2hctx_high_ack)) { 645 while (before48(seqp->ccid2s_seq, hc->tx_high_ack)) {
648 seqp = seqp->ccid2s_next; 646 seqp = seqp->ccid2s_next;
649 if (seqp == hctx->ccid2hctx_seqh) { 647 if (seqp == hc->tx_seqh) {
650 seqp = hctx->ccid2hctx_seqh->ccid2s_prev; 648 seqp = hc->tx_seqh->ccid2s_prev;
651 break; 649 break;
652 } 650 }
653 } 651 }
@@ -658,7 +656,7 @@ static void ccid2_hc_tx_packet_recv(struct sock *sk, struct sk_buff *skb)
658 if (done == NUMDUPACK) 656 if (done == NUMDUPACK)
659 break; 657 break;
660 } 658 }
661 if (seqp == hctx->ccid2hctx_seqt) 659 if (seqp == hc->tx_seqt)
662 break; 660 break;
663 seqp = seqp->ccid2s_prev; 661 seqp = seqp->ccid2s_prev;
664 } 662 }
@@ -681,86 +679,86 @@ static void ccid2_hc_tx_packet_recv(struct sock *sk, struct sk_buff *skb)
681 ccid2_congestion_event(sk, seqp); 679 ccid2_congestion_event(sk, seqp);
682 ccid2_hc_tx_dec_pipe(sk); 680 ccid2_hc_tx_dec_pipe(sk);
683 } 681 }
684 if (seqp == hctx->ccid2hctx_seqt) 682 if (seqp == hc->tx_seqt)
685 break; 683 break;
686 seqp = seqp->ccid2s_prev; 684 seqp = seqp->ccid2s_prev;
687 } 685 }
688 686
689 hctx->ccid2hctx_seqt = last_acked; 687 hc->tx_seqt = last_acked;
690 } 688 }
691 689
692 /* trim acked packets in tail */ 690 /* trim acked packets in tail */
693 while (hctx->ccid2hctx_seqt != hctx->ccid2hctx_seqh) { 691 while (hc->tx_seqt != hc->tx_seqh) {
694 if (!hctx->ccid2hctx_seqt->ccid2s_acked) 692 if (!hc->tx_seqt->ccid2s_acked)
695 break; 693 break;
696 694
697 hctx->ccid2hctx_seqt = hctx->ccid2hctx_seqt->ccid2s_next; 695 hc->tx_seqt = hc->tx_seqt->ccid2s_next;
698 } 696 }
699 697
700 ccid2_hc_tx_check_sanity(hctx); 698 ccid2_hc_tx_check_sanity(hc);
701} 699}
702 700
703static int ccid2_hc_tx_init(struct ccid *ccid, struct sock *sk) 701static int ccid2_hc_tx_init(struct ccid *ccid, struct sock *sk)
704{ 702{
705 struct ccid2_hc_tx_sock *hctx = ccid_priv(ccid); 703 struct ccid2_hc_tx_sock *hc = ccid_priv(ccid);
706 struct dccp_sock *dp = dccp_sk(sk); 704 struct dccp_sock *dp = dccp_sk(sk);
707 u32 max_ratio; 705 u32 max_ratio;
708 706
709 /* RFC 4341, 5: initialise ssthresh to arbitrarily high (max) value */ 707 /* RFC 4341, 5: initialise ssthresh to arbitrarily high (max) value */
710 hctx->ccid2hctx_ssthresh = ~0U; 708 hc->tx_ssthresh = ~0U;
711 709
712 /* 710 /*
713 * RFC 4341, 5: "The cwnd parameter is initialized to at most four 711 * RFC 4341, 5: "The cwnd parameter is initialized to at most four
714 * packets for new connections, following the rules from [RFC3390]". 712 * packets for new connections, following the rules from [RFC3390]".
715 * We need to convert the bytes of RFC3390 into the packets of RFC 4341. 713 * We need to convert the bytes of RFC3390 into the packets of RFC 4341.
716 */ 714 */
717 hctx->ccid2hctx_cwnd = clamp(4380U / dp->dccps_mss_cache, 2U, 4U); 715 hc->tx_cwnd = clamp(4380U / dp->dccps_mss_cache, 2U, 4U);
718 716
719 /* Make sure that Ack Ratio is enabled and within bounds. */ 717 /* Make sure that Ack Ratio is enabled and within bounds. */
720 max_ratio = DIV_ROUND_UP(hctx->ccid2hctx_cwnd, 2); 718 max_ratio = DIV_ROUND_UP(hc->tx_cwnd, 2);
721 if (dp->dccps_l_ack_ratio == 0 || dp->dccps_l_ack_ratio > max_ratio) 719 if (dp->dccps_l_ack_ratio == 0 || dp->dccps_l_ack_ratio > max_ratio)
722 dp->dccps_l_ack_ratio = max_ratio; 720 dp->dccps_l_ack_ratio = max_ratio;
723 721
724 /* XXX init ~ to window size... */ 722 /* XXX init ~ to window size... */
725 if (ccid2_hc_tx_alloc_seq(hctx)) 723 if (ccid2_hc_tx_alloc_seq(hc))
726 return -ENOMEM; 724 return -ENOMEM;
727 725
728 hctx->ccid2hctx_rto = 3 * HZ; 726 hc->tx_rto = 3 * HZ;
729 ccid2_change_srtt(hctx, -1); 727 ccid2_change_srtt(hc, -1);
730 hctx->ccid2hctx_rttvar = -1; 728 hc->tx_rttvar = -1;
731 hctx->ccid2hctx_rpdupack = -1; 729 hc->tx_rpdupack = -1;
732 hctx->ccid2hctx_last_cong = jiffies; 730 hc->tx_last_cong = jiffies;
733 setup_timer(&hctx->ccid2hctx_rtotimer, ccid2_hc_tx_rto_expire, 731 setup_timer(&hc->tx_rtotimer, ccid2_hc_tx_rto_expire,
734 (unsigned long)sk); 732 (unsigned long)sk);
735 733
736 ccid2_hc_tx_check_sanity(hctx); 734 ccid2_hc_tx_check_sanity(hc);
737 return 0; 735 return 0;
738} 736}
739 737
740static void ccid2_hc_tx_exit(struct sock *sk) 738static void ccid2_hc_tx_exit(struct sock *sk)
741{ 739{
742 struct ccid2_hc_tx_sock *hctx = ccid2_hc_tx_sk(sk); 740 struct ccid2_hc_tx_sock *hc = ccid2_hc_tx_sk(sk);
743 int i; 741 int i;
744 742
745 ccid2_hc_tx_kill_rto_timer(sk); 743 ccid2_hc_tx_kill_rto_timer(sk);
746 744
747 for (i = 0; i < hctx->ccid2hctx_seqbufc; i++) 745 for (i = 0; i < hc->tx_seqbufc; i++)
748 kfree(hctx->ccid2hctx_seqbuf[i]); 746 kfree(hc->tx_seqbuf[i]);
749 hctx->ccid2hctx_seqbufc = 0; 747 hc->tx_seqbufc = 0;
750} 748}
751 749
752static void ccid2_hc_rx_packet_recv(struct sock *sk, struct sk_buff *skb) 750static void ccid2_hc_rx_packet_recv(struct sock *sk, struct sk_buff *skb)
753{ 751{
754 const struct dccp_sock *dp = dccp_sk(sk); 752 const struct dccp_sock *dp = dccp_sk(sk);
755 struct ccid2_hc_rx_sock *hcrx = ccid2_hc_rx_sk(sk); 753 struct ccid2_hc_rx_sock *hc = ccid2_hc_rx_sk(sk);
756 754
757 switch (DCCP_SKB_CB(skb)->dccpd_type) { 755 switch (DCCP_SKB_CB(skb)->dccpd_type) {
758 case DCCP_PKT_DATA: 756 case DCCP_PKT_DATA:
759 case DCCP_PKT_DATAACK: 757 case DCCP_PKT_DATAACK:
760 hcrx->ccid2hcrx_data++; 758 hc->rx_data++;
761 if (hcrx->ccid2hcrx_data >= dp->dccps_r_ack_ratio) { 759 if (hc->rx_data >= dp->dccps_r_ack_ratio) {
762 dccp_send_ack(sk); 760 dccp_send_ack(sk);
763 hcrx->ccid2hcrx_data = 0; 761 hc->rx_data = 0;
764 } 762 }
765 break; 763 break;
766 } 764 }
diff --git a/net/dccp/ccids/ccid2.h b/net/dccp/ccids/ccid2.h
index 326ac90fb909..1ec6a30103bb 100644
--- a/net/dccp/ccids/ccid2.h
+++ b/net/dccp/ccids/ccid2.h
@@ -40,34 +40,34 @@ struct ccid2_seq {
40 40
41/** 41/**
42 * struct ccid2_hc_tx_sock - CCID2 TX half connection 42 * struct ccid2_hc_tx_sock - CCID2 TX half connection
43 * @ccid2hctx_{cwnd,ssthresh,pipe}: as per RFC 4341, section 5 43 * @tx_{cwnd,ssthresh,pipe}: as per RFC 4341, section 5
44 * @ccid2hctx_packets_acked - Ack counter for deriving cwnd growth (RFC 3465) 44 * @tx_packets_acked: Ack counter for deriving cwnd growth (RFC 3465)
45 * @ccid2hctx_lastrtt -time RTT was last measured 45 * @tx_lastrtt: time RTT was last measured
46 * @ccid2hctx_rpseq - last consecutive seqno 46 * @tx_rpseq: last consecutive seqno
47 * @ccid2hctx_rpdupack - dupacks since rpseq 47 * @tx_rpdupack: dupacks since rpseq
48 */ 48 */
49struct ccid2_hc_tx_sock { 49struct ccid2_hc_tx_sock {
50 u32 ccid2hctx_cwnd; 50 u32 tx_cwnd;
51 u32 ccid2hctx_ssthresh; 51 u32 tx_ssthresh;
52 u32 ccid2hctx_pipe; 52 u32 tx_pipe;
53 u32 ccid2hctx_packets_acked; 53 u32 tx_packets_acked;
54 struct ccid2_seq *ccid2hctx_seqbuf[CCID2_SEQBUF_MAX]; 54 struct ccid2_seq *tx_seqbuf[CCID2_SEQBUF_MAX];
55 int ccid2hctx_seqbufc; 55 int tx_seqbufc;
56 struct ccid2_seq *ccid2hctx_seqh; 56 struct ccid2_seq *tx_seqh;
57 struct ccid2_seq *ccid2hctx_seqt; 57 struct ccid2_seq *tx_seqt;
58 long ccid2hctx_rto; 58 long tx_rto;
59 long ccid2hctx_srtt; 59 long tx_srtt;
60 long ccid2hctx_rttvar; 60 long tx_rttvar;
61 unsigned long ccid2hctx_lastrtt; 61 unsigned long tx_lastrtt;
62 struct timer_list ccid2hctx_rtotimer; 62 struct timer_list tx_rtotimer;
63 u64 ccid2hctx_rpseq; 63 u64 tx_rpseq;
64 int ccid2hctx_rpdupack; 64 int tx_rpdupack;
65 unsigned long ccid2hctx_last_cong; 65 unsigned long tx_last_cong;
66 u64 ccid2hctx_high_ack; 66 u64 tx_high_ack;
67}; 67};
68 68
69struct ccid2_hc_rx_sock { 69struct ccid2_hc_rx_sock {
70 int ccid2hcrx_data; 70 int rx_data;
71}; 71};
72 72
73static inline struct ccid2_hc_tx_sock *ccid2_hc_tx_sk(const struct sock *sk) 73static inline struct ccid2_hc_tx_sock *ccid2_hc_tx_sk(const struct sock *sk)
diff --git a/net/dccp/ccids/ccid3.c b/net/dccp/ccids/ccid3.c
index 34dcc798c457..bcd7632299f5 100644
--- a/net/dccp/ccids/ccid3.c
+++ b/net/dccp/ccids/ccid3.c
@@ -64,14 +64,14 @@ static const char *ccid3_tx_state_name(enum ccid3_hc_tx_states state)
64static void ccid3_hc_tx_set_state(struct sock *sk, 64static void ccid3_hc_tx_set_state(struct sock *sk,
65 enum ccid3_hc_tx_states state) 65 enum ccid3_hc_tx_states state)
66{ 66{
67 struct ccid3_hc_tx_sock *hctx = ccid3_hc_tx_sk(sk); 67 struct ccid3_hc_tx_sock *hc = ccid3_hc_tx_sk(sk);
68 enum ccid3_hc_tx_states oldstate = hctx->ccid3hctx_state; 68 enum ccid3_hc_tx_states oldstate = hc->tx_state;
69 69
70 ccid3_pr_debug("%s(%p) %-8.8s -> %s\n", 70 ccid3_pr_debug("%s(%p) %-8.8s -> %s\n",
71 dccp_role(sk), sk, ccid3_tx_state_name(oldstate), 71 dccp_role(sk), sk, ccid3_tx_state_name(oldstate),
72 ccid3_tx_state_name(state)); 72 ccid3_tx_state_name(state));
73 WARN_ON(state == oldstate); 73 WARN_ON(state == oldstate);
74 hctx->ccid3hctx_state = state; 74 hc->tx_state = state;
75} 75}
76 76
77/* 77/*
@@ -85,37 +85,32 @@ static void ccid3_hc_tx_set_state(struct sock *sk,
85 */ 85 */
86static inline u64 rfc3390_initial_rate(struct sock *sk) 86static inline u64 rfc3390_initial_rate(struct sock *sk)
87{ 87{
88 const struct ccid3_hc_tx_sock *hctx = ccid3_hc_tx_sk(sk); 88 const struct ccid3_hc_tx_sock *hc = ccid3_hc_tx_sk(sk);
89 const __u32 w_init = clamp_t(__u32, 4380U, 89 const __u32 w_init = clamp_t(__u32, 4380U, 2 * hc->tx_s, 4 * hc->tx_s);
90 2 * hctx->ccid3hctx_s, 4 * hctx->ccid3hctx_s);
91 90
92 return scaled_div(w_init << 6, hctx->ccid3hctx_rtt); 91 return scaled_div(w_init << 6, hc->tx_rtt);
93} 92}
94 93
95/* 94/*
96 * Recalculate t_ipi and delta (should be called whenever X changes) 95 * Recalculate t_ipi and delta (should be called whenever X changes)
97 */ 96 */
98static void ccid3_update_send_interval(struct ccid3_hc_tx_sock *hctx) 97static void ccid3_update_send_interval(struct ccid3_hc_tx_sock *hc)
99{ 98{
100 /* Calculate new t_ipi = s / X_inst (X_inst is in 64 * bytes/second) */ 99 /* Calculate new t_ipi = s / X_inst (X_inst is in 64 * bytes/second) */
101 hctx->ccid3hctx_t_ipi = scaled_div32(((u64)hctx->ccid3hctx_s) << 6, 100 hc->tx_t_ipi = scaled_div32(((u64)hc->tx_s) << 6, hc->tx_x);
102 hctx->ccid3hctx_x);
103 101
104 /* Calculate new delta by delta = min(t_ipi / 2, t_gran / 2) */ 102 /* Calculate new delta by delta = min(t_ipi / 2, t_gran / 2) */
105 hctx->ccid3hctx_delta = min_t(u32, hctx->ccid3hctx_t_ipi / 2, 103 hc->tx_delta = min_t(u32, hc->tx_t_ipi / 2, TFRC_OPSYS_HALF_TIME_GRAN);
106 TFRC_OPSYS_HALF_TIME_GRAN);
107
108 ccid3_pr_debug("t_ipi=%u, delta=%u, s=%u, X=%u\n",
109 hctx->ccid3hctx_t_ipi, hctx->ccid3hctx_delta,
110 hctx->ccid3hctx_s, (unsigned)(hctx->ccid3hctx_x >> 6));
111 104
105 ccid3_pr_debug("t_ipi=%u, delta=%u, s=%u, X=%u\n", hc->tx_t_ipi,
106 hc->tx_delta, hc->tx_s, (unsigned)(hc->tx_x >> 6));
112} 107}
113 108
114static u32 ccid3_hc_tx_idle_rtt(struct ccid3_hc_tx_sock *hctx, ktime_t now) 109static u32 ccid3_hc_tx_idle_rtt(struct ccid3_hc_tx_sock *hc, ktime_t now)
115{ 110{
116 u32 delta = ktime_us_delta(now, hctx->ccid3hctx_t_last_win_count); 111 u32 delta = ktime_us_delta(now, hc->tx_t_last_win_count);
117 112
118 return delta / hctx->ccid3hctx_rtt; 113 return delta / hc->tx_rtt;
119} 114}
120 115
121/** 116/**
@@ -130,9 +125,9 @@ static u32 ccid3_hc_tx_idle_rtt(struct ccid3_hc_tx_sock *hctx, ktime_t now)
130 */ 125 */
131static void ccid3_hc_tx_update_x(struct sock *sk, ktime_t *stamp) 126static void ccid3_hc_tx_update_x(struct sock *sk, ktime_t *stamp)
132{ 127{
133 struct ccid3_hc_tx_sock *hctx = ccid3_hc_tx_sk(sk); 128 struct ccid3_hc_tx_sock *hc = ccid3_hc_tx_sk(sk);
134 __u64 min_rate = 2 * hctx->ccid3hctx_x_recv; 129 __u64 min_rate = 2 * hc->tx_x_recv;
135 const __u64 old_x = hctx->ccid3hctx_x; 130 const __u64 old_x = hc->tx_x;
136 ktime_t now = stamp ? *stamp : ktime_get_real(); 131 ktime_t now = stamp ? *stamp : ktime_get_real();
137 132
138 /* 133 /*
@@ -141,37 +136,31 @@ static void ccid3_hc_tx_update_x(struct sock *sk, ktime_t *stamp)
141 * a sender is idle if it has not sent anything over a 2-RTT-period. 136 * a sender is idle if it has not sent anything over a 2-RTT-period.
142 * For consistency with X and X_recv, min_rate is also scaled by 2^6. 137 * For consistency with X and X_recv, min_rate is also scaled by 2^6.
143 */ 138 */
144 if (ccid3_hc_tx_idle_rtt(hctx, now) >= 2) { 139 if (ccid3_hc_tx_idle_rtt(hc, now) >= 2) {
145 min_rate = rfc3390_initial_rate(sk); 140 min_rate = rfc3390_initial_rate(sk);
146 min_rate = max(min_rate, 2 * hctx->ccid3hctx_x_recv); 141 min_rate = max(min_rate, 2 * hc->tx_x_recv);
147 } 142 }
148 143
149 if (hctx->ccid3hctx_p > 0) { 144 if (hc->tx_p > 0) {
150 145
151 hctx->ccid3hctx_x = min(((__u64)hctx->ccid3hctx_x_calc) << 6, 146 hc->tx_x = min(((__u64)hc->tx_x_calc) << 6, min_rate);
152 min_rate); 147 hc->tx_x = max(hc->tx_x, (((__u64)hc->tx_s) << 6) / TFRC_T_MBI);
153 hctx->ccid3hctx_x = max(hctx->ccid3hctx_x,
154 (((__u64)hctx->ccid3hctx_s) << 6) /
155 TFRC_T_MBI);
156 148
157 } else if (ktime_us_delta(now, hctx->ccid3hctx_t_ld) 149 } else if (ktime_us_delta(now, hc->tx_t_ld) - (s64)hc->tx_rtt >= 0) {
158 - (s64)hctx->ccid3hctx_rtt >= 0) {
159 150
160 hctx->ccid3hctx_x = min(2 * hctx->ccid3hctx_x, min_rate); 151 hc->tx_x = min(2 * hc->tx_x, min_rate);
161 hctx->ccid3hctx_x = max(hctx->ccid3hctx_x, 152 hc->tx_x = max(hc->tx_x,
162 scaled_div(((__u64)hctx->ccid3hctx_s) << 6, 153 scaled_div(((__u64)hc->tx_s) << 6, hc->tx_rtt));
163 hctx->ccid3hctx_rtt)); 154 hc->tx_t_ld = now;
164 hctx->ccid3hctx_t_ld = now;
165 } 155 }
166 156
167 if (hctx->ccid3hctx_x != old_x) { 157 if (hc->tx_x != old_x) {
168 ccid3_pr_debug("X_prev=%u, X_now=%u, X_calc=%u, " 158 ccid3_pr_debug("X_prev=%u, X_now=%u, X_calc=%u, "
169 "X_recv=%u\n", (unsigned)(old_x >> 6), 159 "X_recv=%u\n", (unsigned)(old_x >> 6),
170 (unsigned)(hctx->ccid3hctx_x >> 6), 160 (unsigned)(hc->tx_x >> 6), hc->tx_x_calc,
171 hctx->ccid3hctx_x_calc, 161 (unsigned)(hc->tx_x_recv >> 6));
172 (unsigned)(hctx->ccid3hctx_x_recv >> 6));
173 162
174 ccid3_update_send_interval(hctx); 163 ccid3_update_send_interval(hc);
175 } 164 }
176} 165}
177 166
@@ -179,37 +168,37 @@ static void ccid3_hc_tx_update_x(struct sock *sk, ktime_t *stamp)
179 * Track the mean packet size `s' (cf. RFC 4342, 5.3 and RFC 3448, 4.1) 168 * Track the mean packet size `s' (cf. RFC 4342, 5.3 and RFC 3448, 4.1)
180 * @len: DCCP packet payload size in bytes 169 * @len: DCCP packet payload size in bytes
181 */ 170 */
182static inline void ccid3_hc_tx_update_s(struct ccid3_hc_tx_sock *hctx, int len) 171static inline void ccid3_hc_tx_update_s(struct ccid3_hc_tx_sock *hc, int len)
183{ 172{
184 const u16 old_s = hctx->ccid3hctx_s; 173 const u16 old_s = hc->tx_s;
185 174
186 hctx->ccid3hctx_s = tfrc_ewma(hctx->ccid3hctx_s, len, 9); 175 hc->tx_s = tfrc_ewma(hc->tx_s, len, 9);
187 176
188 if (hctx->ccid3hctx_s != old_s) 177 if (hc->tx_s != old_s)
189 ccid3_update_send_interval(hctx); 178 ccid3_update_send_interval(hc);
190} 179}
191 180
192/* 181/*
193 * Update Window Counter using the algorithm from [RFC 4342, 8.1]. 182 * Update Window Counter using the algorithm from [RFC 4342, 8.1].
194 * As elsewhere, RTT > 0 is assumed by using dccp_sample_rtt(). 183 * As elsewhere, RTT > 0 is assumed by using dccp_sample_rtt().
195 */ 184 */
196static inline void ccid3_hc_tx_update_win_count(struct ccid3_hc_tx_sock *hctx, 185static inline void ccid3_hc_tx_update_win_count(struct ccid3_hc_tx_sock *hc,
197 ktime_t now) 186 ktime_t now)
198{ 187{
199 u32 delta = ktime_us_delta(now, hctx->ccid3hctx_t_last_win_count), 188 u32 delta = ktime_us_delta(now, hc->tx_t_last_win_count),
200 quarter_rtts = (4 * delta) / hctx->ccid3hctx_rtt; 189 quarter_rtts = (4 * delta) / hc->tx_rtt;
201 190
202 if (quarter_rtts > 0) { 191 if (quarter_rtts > 0) {
203 hctx->ccid3hctx_t_last_win_count = now; 192 hc->tx_t_last_win_count = now;
204 hctx->ccid3hctx_last_win_count += min(quarter_rtts, 5U); 193 hc->tx_last_win_count += min(quarter_rtts, 5U);
205 hctx->ccid3hctx_last_win_count &= 0xF; /* mod 16 */ 194 hc->tx_last_win_count &= 0xF; /* mod 16 */
206 } 195 }
207} 196}
208 197
209static void ccid3_hc_tx_no_feedback_timer(unsigned long data) 198static void ccid3_hc_tx_no_feedback_timer(unsigned long data)
210{ 199{
211 struct sock *sk = (struct sock *)data; 200 struct sock *sk = (struct sock *)data;
212 struct ccid3_hc_tx_sock *hctx = ccid3_hc_tx_sk(sk); 201 struct ccid3_hc_tx_sock *hc = ccid3_hc_tx_sk(sk);
213 unsigned long t_nfb = USEC_PER_SEC / 5; 202 unsigned long t_nfb = USEC_PER_SEC / 5;
214 203
215 bh_lock_sock(sk); 204 bh_lock_sock(sk);
@@ -220,24 +209,23 @@ static void ccid3_hc_tx_no_feedback_timer(unsigned long data)
220 } 209 }
221 210
222 ccid3_pr_debug("%s(%p, state=%s) - entry \n", dccp_role(sk), sk, 211 ccid3_pr_debug("%s(%p, state=%s) - entry \n", dccp_role(sk), sk,
223 ccid3_tx_state_name(hctx->ccid3hctx_state)); 212 ccid3_tx_state_name(hc->tx_state));
224 213
225 if (hctx->ccid3hctx_state == TFRC_SSTATE_FBACK) 214 if (hc->tx_state == TFRC_SSTATE_FBACK)
226 ccid3_hc_tx_set_state(sk, TFRC_SSTATE_NO_FBACK); 215 ccid3_hc_tx_set_state(sk, TFRC_SSTATE_NO_FBACK);
227 else if (hctx->ccid3hctx_state != TFRC_SSTATE_NO_FBACK) 216 else if (hc->tx_state != TFRC_SSTATE_NO_FBACK)
228 goto out; 217 goto out;
229 218
230 /* 219 /*
231 * Determine new allowed sending rate X as per draft rfc3448bis-00, 4.4 220 * Determine new allowed sending rate X as per draft rfc3448bis-00, 4.4
232 */ 221 */
233 if (hctx->ccid3hctx_t_rto == 0 || /* no feedback received yet */ 222 if (hc->tx_t_rto == 0 || /* no feedback received yet */
234 hctx->ccid3hctx_p == 0) { 223 hc->tx_p == 0) {
235 224
236 /* halve send rate directly */ 225 /* halve send rate directly */
237 hctx->ccid3hctx_x = max(hctx->ccid3hctx_x / 2, 226 hc->tx_x = max(hc->tx_x / 2,
238 (((__u64)hctx->ccid3hctx_s) << 6) / 227 (((__u64)hc->tx_s) << 6) / TFRC_T_MBI);
239 TFRC_T_MBI); 228 ccid3_update_send_interval(hc);
240 ccid3_update_send_interval(hctx);
241 } else { 229 } else {
242 /* 230 /*
243 * Modify the cached value of X_recv 231 * Modify the cached value of X_recv
@@ -249,33 +237,32 @@ static void ccid3_hc_tx_no_feedback_timer(unsigned long data)
249 * 237 *
250 * Note that X_recv is scaled by 2^6 while X_calc is not 238 * Note that X_recv is scaled by 2^6 while X_calc is not
251 */ 239 */
252 BUG_ON(hctx->ccid3hctx_p && !hctx->ccid3hctx_x_calc); 240 BUG_ON(hc->tx_p && !hc->tx_x_calc);
253 241
254 if (hctx->ccid3hctx_x_calc > (hctx->ccid3hctx_x_recv >> 5)) 242 if (hc->tx_x_calc > (hc->tx_x_recv >> 5))
255 hctx->ccid3hctx_x_recv = 243 hc->tx_x_recv =
256 max(hctx->ccid3hctx_x_recv / 2, 244 max(hc->tx_x_recv / 2,
257 (((__u64)hctx->ccid3hctx_s) << 6) / 245 (((__u64)hc->tx_s) << 6) / (2*TFRC_T_MBI));
258 (2 * TFRC_T_MBI));
259 else { 246 else {
260 hctx->ccid3hctx_x_recv = hctx->ccid3hctx_x_calc; 247 hc->tx_x_recv = hc->tx_x_calc;
261 hctx->ccid3hctx_x_recv <<= 4; 248 hc->tx_x_recv <<= 4;
262 } 249 }
263 ccid3_hc_tx_update_x(sk, NULL); 250 ccid3_hc_tx_update_x(sk, NULL);
264 } 251 }
265 ccid3_pr_debug("Reduced X to %llu/64 bytes/sec\n", 252 ccid3_pr_debug("Reduced X to %llu/64 bytes/sec\n",
266 (unsigned long long)hctx->ccid3hctx_x); 253 (unsigned long long)hc->tx_x);
267 254
268 /* 255 /*
269 * Set new timeout for the nofeedback timer. 256 * Set new timeout for the nofeedback timer.
270 * See comments in packet_recv() regarding the value of t_RTO. 257 * See comments in packet_recv() regarding the value of t_RTO.
271 */ 258 */
272 if (unlikely(hctx->ccid3hctx_t_rto == 0)) /* no feedback yet */ 259 if (unlikely(hc->tx_t_rto == 0)) /* no feedback yet */
273 t_nfb = TFRC_INITIAL_TIMEOUT; 260 t_nfb = TFRC_INITIAL_TIMEOUT;
274 else 261 else
275 t_nfb = max(hctx->ccid3hctx_t_rto, 2 * hctx->ccid3hctx_t_ipi); 262 t_nfb = max(hc->tx_t_rto, 2 * hc->tx_t_ipi);
276 263
277restart_timer: 264restart_timer:
278 sk_reset_timer(sk, &hctx->ccid3hctx_no_feedback_timer, 265 sk_reset_timer(sk, &hc->tx_no_feedback_timer,
279 jiffies + usecs_to_jiffies(t_nfb)); 266 jiffies + usecs_to_jiffies(t_nfb));
280out: 267out:
281 bh_unlock_sock(sk); 268 bh_unlock_sock(sk);
@@ -291,7 +278,7 @@ out:
291static int ccid3_hc_tx_send_packet(struct sock *sk, struct sk_buff *skb) 278static int ccid3_hc_tx_send_packet(struct sock *sk, struct sk_buff *skb)
292{ 279{
293 struct dccp_sock *dp = dccp_sk(sk); 280 struct dccp_sock *dp = dccp_sk(sk);
294 struct ccid3_hc_tx_sock *hctx = ccid3_hc_tx_sk(sk); 281 struct ccid3_hc_tx_sock *hc = ccid3_hc_tx_sk(sk);
295 ktime_t now = ktime_get_real(); 282 ktime_t now = ktime_get_real();
296 s64 delay; 283 s64 delay;
297 284
@@ -303,18 +290,17 @@ static int ccid3_hc_tx_send_packet(struct sock *sk, struct sk_buff *skb)
303 if (unlikely(skb->len == 0)) 290 if (unlikely(skb->len == 0))
304 return -EBADMSG; 291 return -EBADMSG;
305 292
306 switch (hctx->ccid3hctx_state) { 293 switch (hc->tx_state) {
307 case TFRC_SSTATE_NO_SENT: 294 case TFRC_SSTATE_NO_SENT:
308 sk_reset_timer(sk, &hctx->ccid3hctx_no_feedback_timer, 295 sk_reset_timer(sk, &hc->tx_no_feedback_timer, (jiffies +
309 (jiffies + 296 usecs_to_jiffies(TFRC_INITIAL_TIMEOUT)));
310 usecs_to_jiffies(TFRC_INITIAL_TIMEOUT))); 297 hc->tx_last_win_count = 0;
311 hctx->ccid3hctx_last_win_count = 0; 298 hc->tx_t_last_win_count = now;
312 hctx->ccid3hctx_t_last_win_count = now;
313 299
314 /* Set t_0 for initial packet */ 300 /* Set t_0 for initial packet */
315 hctx->ccid3hctx_t_nom = now; 301 hc->tx_t_nom = now;
316 302
317 hctx->ccid3hctx_s = skb->len; 303 hc->tx_s = skb->len;
318 304
319 /* 305 /*
320 * Use initial RTT sample when available: recommended by erratum 306 * Use initial RTT sample when available: recommended by erratum
@@ -323,9 +309,9 @@ static int ccid3_hc_tx_send_packet(struct sock *sk, struct sk_buff *skb)
323 */ 309 */
324 if (dp->dccps_syn_rtt) { 310 if (dp->dccps_syn_rtt) {
325 ccid3_pr_debug("SYN RTT = %uus\n", dp->dccps_syn_rtt); 311 ccid3_pr_debug("SYN RTT = %uus\n", dp->dccps_syn_rtt);
326 hctx->ccid3hctx_rtt = dp->dccps_syn_rtt; 312 hc->tx_rtt = dp->dccps_syn_rtt;
327 hctx->ccid3hctx_x = rfc3390_initial_rate(sk); 313 hc->tx_x = rfc3390_initial_rate(sk);
328 hctx->ccid3hctx_t_ld = now; 314 hc->tx_t_ld = now;
329 } else { 315 } else {
330 /* 316 /*
331 * Sender does not have RTT sample: 317 * Sender does not have RTT sample:
@@ -333,17 +319,17 @@ static int ccid3_hc_tx_send_packet(struct sock *sk, struct sk_buff *skb)
333 * is needed in several parts (e.g. window counter); 319 * is needed in several parts (e.g. window counter);
334 * - set sending rate X_pps = 1pps as per RFC 3448, 4.2. 320 * - set sending rate X_pps = 1pps as per RFC 3448, 4.2.
335 */ 321 */
336 hctx->ccid3hctx_rtt = DCCP_FALLBACK_RTT; 322 hc->tx_rtt = DCCP_FALLBACK_RTT;
337 hctx->ccid3hctx_x = hctx->ccid3hctx_s; 323 hc->tx_x = hc->tx_s;
338 hctx->ccid3hctx_x <<= 6; 324 hc->tx_x <<= 6;
339 } 325 }
340 ccid3_update_send_interval(hctx); 326 ccid3_update_send_interval(hc);
341 327
342 ccid3_hc_tx_set_state(sk, TFRC_SSTATE_NO_FBACK); 328 ccid3_hc_tx_set_state(sk, TFRC_SSTATE_NO_FBACK);
343 break; 329 break;
344 case TFRC_SSTATE_NO_FBACK: 330 case TFRC_SSTATE_NO_FBACK:
345 case TFRC_SSTATE_FBACK: 331 case TFRC_SSTATE_FBACK:
346 delay = ktime_us_delta(hctx->ccid3hctx_t_nom, now); 332 delay = ktime_us_delta(hc->tx_t_nom, now);
347 ccid3_pr_debug("delay=%ld\n", (long)delay); 333 ccid3_pr_debug("delay=%ld\n", (long)delay);
348 /* 334 /*
349 * Scheduling of packet transmissions [RFC 3448, 4.6] 335 * Scheduling of packet transmissions [RFC 3448, 4.6]
@@ -353,10 +339,10 @@ static int ccid3_hc_tx_send_packet(struct sock *sk, struct sk_buff *skb)
353 * else 339 * else
354 * // send the packet in (t_nom - t_now) milliseconds. 340 * // send the packet in (t_nom - t_now) milliseconds.
355 */ 341 */
356 if (delay - (s64)hctx->ccid3hctx_delta >= 1000) 342 if (delay - (s64)hc->tx_delta >= 1000)
357 return (u32)delay / 1000L; 343 return (u32)delay / 1000L;
358 344
359 ccid3_hc_tx_update_win_count(hctx, now); 345 ccid3_hc_tx_update_win_count(hc, now);
360 break; 346 break;
361 case TFRC_SSTATE_TERM: 347 case TFRC_SSTATE_TERM:
362 DCCP_BUG("%s(%p) - Illegal state TERM", dccp_role(sk), sk); 348 DCCP_BUG("%s(%p) - Illegal state TERM", dccp_role(sk), sk);
@@ -365,28 +351,27 @@ static int ccid3_hc_tx_send_packet(struct sock *sk, struct sk_buff *skb)
365 351
366 /* prepare to send now (add options etc.) */ 352 /* prepare to send now (add options etc.) */
367 dp->dccps_hc_tx_insert_options = 1; 353 dp->dccps_hc_tx_insert_options = 1;
368 DCCP_SKB_CB(skb)->dccpd_ccval = hctx->ccid3hctx_last_win_count; 354 DCCP_SKB_CB(skb)->dccpd_ccval = hc->tx_last_win_count;
369 355
370 /* set the nominal send time for the next following packet */ 356 /* set the nominal send time for the next following packet */
371 hctx->ccid3hctx_t_nom = ktime_add_us(hctx->ccid3hctx_t_nom, 357 hc->tx_t_nom = ktime_add_us(hc->tx_t_nom, hc->tx_t_ipi);
372 hctx->ccid3hctx_t_ipi);
373 return 0; 358 return 0;
374} 359}
375 360
376static void ccid3_hc_tx_packet_sent(struct sock *sk, int more, 361static void ccid3_hc_tx_packet_sent(struct sock *sk, int more,
377 unsigned int len) 362 unsigned int len)
378{ 363{
379 struct ccid3_hc_tx_sock *hctx = ccid3_hc_tx_sk(sk); 364 struct ccid3_hc_tx_sock *hc = ccid3_hc_tx_sk(sk);
380 365
381 ccid3_hc_tx_update_s(hctx, len); 366 ccid3_hc_tx_update_s(hc, len);
382 367
383 if (tfrc_tx_hist_add(&hctx->ccid3hctx_hist, dccp_sk(sk)->dccps_gss)) 368 if (tfrc_tx_hist_add(&hc->tx_hist, dccp_sk(sk)->dccps_gss))
384 DCCP_CRIT("packet history - out of memory!"); 369 DCCP_CRIT("packet history - out of memory!");
385} 370}
386 371
387static void ccid3_hc_tx_packet_recv(struct sock *sk, struct sk_buff *skb) 372static void ccid3_hc_tx_packet_recv(struct sock *sk, struct sk_buff *skb)
388{ 373{
389 struct ccid3_hc_tx_sock *hctx = ccid3_hc_tx_sk(sk); 374 struct ccid3_hc_tx_sock *hc = ccid3_hc_tx_sk(sk);
390 struct ccid3_options_received *opt_recv; 375 struct ccid3_options_received *opt_recv;
391 ktime_t now; 376 ktime_t now;
392 unsigned long t_nfb; 377 unsigned long t_nfb;
@@ -397,15 +382,15 @@ static void ccid3_hc_tx_packet_recv(struct sock *sk, struct sk_buff *skb)
397 DCCP_SKB_CB(skb)->dccpd_type == DCCP_PKT_DATAACK)) 382 DCCP_SKB_CB(skb)->dccpd_type == DCCP_PKT_DATAACK))
398 return; 383 return;
399 /* ... and only in the established state */ 384 /* ... and only in the established state */
400 if (hctx->ccid3hctx_state != TFRC_SSTATE_FBACK && 385 if (hc->tx_state != TFRC_SSTATE_FBACK &&
401 hctx->ccid3hctx_state != TFRC_SSTATE_NO_FBACK) 386 hc->tx_state != TFRC_SSTATE_NO_FBACK)
402 return; 387 return;
403 388
404 opt_recv = &hctx->ccid3hctx_options_received; 389 opt_recv = &hc->tx_options_received;
405 now = ktime_get_real(); 390 now = ktime_get_real();
406 391
407 /* Estimate RTT from history if ACK number is valid */ 392 /* Estimate RTT from history if ACK number is valid */
408 r_sample = tfrc_tx_hist_rtt(hctx->ccid3hctx_hist, 393 r_sample = tfrc_tx_hist_rtt(hc->tx_hist,
409 DCCP_SKB_CB(skb)->dccpd_ack_seq, now); 394 DCCP_SKB_CB(skb)->dccpd_ack_seq, now);
410 if (r_sample == 0) { 395 if (r_sample == 0) {
411 DCCP_WARN("%s(%p): %s with bogus ACK-%llu\n", dccp_role(sk), sk, 396 DCCP_WARN("%s(%p): %s with bogus ACK-%llu\n", dccp_role(sk), sk,
@@ -415,37 +400,37 @@ static void ccid3_hc_tx_packet_recv(struct sock *sk, struct sk_buff *skb)
415 } 400 }
416 401
417 /* Update receive rate in units of 64 * bytes/second */ 402 /* Update receive rate in units of 64 * bytes/second */
418 hctx->ccid3hctx_x_recv = opt_recv->ccid3or_receive_rate; 403 hc->tx_x_recv = opt_recv->ccid3or_receive_rate;
419 hctx->ccid3hctx_x_recv <<= 6; 404 hc->tx_x_recv <<= 6;
420 405
421 /* Update loss event rate (which is scaled by 1e6) */ 406 /* Update loss event rate (which is scaled by 1e6) */
422 pinv = opt_recv->ccid3or_loss_event_rate; 407 pinv = opt_recv->ccid3or_loss_event_rate;
423 if (pinv == ~0U || pinv == 0) /* see RFC 4342, 8.5 */ 408 if (pinv == ~0U || pinv == 0) /* see RFC 4342, 8.5 */
424 hctx->ccid3hctx_p = 0; 409 hc->tx_p = 0;
425 else /* can not exceed 100% */ 410 else /* can not exceed 100% */
426 hctx->ccid3hctx_p = scaled_div(1, pinv); 411 hc->tx_p = scaled_div(1, pinv);
427 /* 412 /*
428 * Validate new RTT sample and update moving average 413 * Validate new RTT sample and update moving average
429 */ 414 */
430 r_sample = dccp_sample_rtt(sk, r_sample); 415 r_sample = dccp_sample_rtt(sk, r_sample);
431 hctx->ccid3hctx_rtt = tfrc_ewma(hctx->ccid3hctx_rtt, r_sample, 9); 416 hc->tx_rtt = tfrc_ewma(hc->tx_rtt, r_sample, 9);
432 /* 417 /*
433 * Update allowed sending rate X as per draft rfc3448bis-00, 4.2/3 418 * Update allowed sending rate X as per draft rfc3448bis-00, 4.2/3
434 */ 419 */
435 if (hctx->ccid3hctx_state == TFRC_SSTATE_NO_FBACK) { 420 if (hc->tx_state == TFRC_SSTATE_NO_FBACK) {
436 ccid3_hc_tx_set_state(sk, TFRC_SSTATE_FBACK); 421 ccid3_hc_tx_set_state(sk, TFRC_SSTATE_FBACK);
437 422
438 if (hctx->ccid3hctx_t_rto == 0) { 423 if (hc->tx_t_rto == 0) {
439 /* 424 /*
440 * Initial feedback packet: Larger Initial Windows (4.2) 425 * Initial feedback packet: Larger Initial Windows (4.2)
441 */ 426 */
442 hctx->ccid3hctx_x = rfc3390_initial_rate(sk); 427 hc->tx_x = rfc3390_initial_rate(sk);
443 hctx->ccid3hctx_t_ld = now; 428 hc->tx_t_ld = now;
444 429
445 ccid3_update_send_interval(hctx); 430 ccid3_update_send_interval(hc);
446 431
447 goto done_computing_x; 432 goto done_computing_x;
448 } else if (hctx->ccid3hctx_p == 0) { 433 } else if (hc->tx_p == 0) {
449 /* 434 /*
450 * First feedback after nofeedback timer expiry (4.3) 435 * First feedback after nofeedback timer expiry (4.3)
451 */ 436 */
@@ -454,25 +439,20 @@ static void ccid3_hc_tx_packet_recv(struct sock *sk, struct sk_buff *skb)
454 } 439 }
455 440
456 /* Update sending rate (step 4 of [RFC 3448, 4.3]) */ 441 /* Update sending rate (step 4 of [RFC 3448, 4.3]) */
457 if (hctx->ccid3hctx_p > 0) 442 if (hc->tx_p > 0)
458 hctx->ccid3hctx_x_calc = 443 hc->tx_x_calc = tfrc_calc_x(hc->tx_s, hc->tx_rtt, hc->tx_p);
459 tfrc_calc_x(hctx->ccid3hctx_s,
460 hctx->ccid3hctx_rtt,
461 hctx->ccid3hctx_p);
462 ccid3_hc_tx_update_x(sk, &now); 444 ccid3_hc_tx_update_x(sk, &now);
463 445
464done_computing_x: 446done_computing_x:
465 ccid3_pr_debug("%s(%p), RTT=%uus (sample=%uus), s=%u, " 447 ccid3_pr_debug("%s(%p), RTT=%uus (sample=%uus), s=%u, "
466 "p=%u, X_calc=%u, X_recv=%u, X=%u\n", 448 "p=%u, X_calc=%u, X_recv=%u, X=%u\n",
467 dccp_role(sk), 449 dccp_role(sk), sk, hc->tx_rtt, r_sample,
468 sk, hctx->ccid3hctx_rtt, r_sample, 450 hc->tx_s, hc->tx_p, hc->tx_x_calc,
469 hctx->ccid3hctx_s, hctx->ccid3hctx_p, 451 (unsigned)(hc->tx_x_recv >> 6),
470 hctx->ccid3hctx_x_calc, 452 (unsigned)(hc->tx_x >> 6));
471 (unsigned)(hctx->ccid3hctx_x_recv >> 6),
472 (unsigned)(hctx->ccid3hctx_x >> 6));
473 453
474 /* unschedule no feedback timer */ 454 /* unschedule no feedback timer */
475 sk_stop_timer(sk, &hctx->ccid3hctx_no_feedback_timer); 455 sk_stop_timer(sk, &hc->tx_no_feedback_timer);
476 456
477 /* 457 /*
478 * As we have calculated new ipi, delta, t_nom it is possible 458 * As we have calculated new ipi, delta, t_nom it is possible
@@ -486,21 +466,19 @@ done_computing_x:
486 * This can help avoid triggering the nofeedback timer too 466 * This can help avoid triggering the nofeedback timer too
487 * often ('spinning') on LANs with small RTTs. 467 * often ('spinning') on LANs with small RTTs.
488 */ 468 */
489 hctx->ccid3hctx_t_rto = max_t(u32, 4 * hctx->ccid3hctx_rtt, 469 hc->tx_t_rto = max_t(u32, 4 * hc->tx_rtt, (CONFIG_IP_DCCP_CCID3_RTO *
490 (CONFIG_IP_DCCP_CCID3_RTO * 470 (USEC_PER_SEC / 1000)));
491 (USEC_PER_SEC / 1000)));
492 /* 471 /*
493 * Schedule no feedback timer to expire in 472 * Schedule no feedback timer to expire in
494 * max(t_RTO, 2 * s/X) = max(t_RTO, 2 * t_ipi) 473 * max(t_RTO, 2 * s/X) = max(t_RTO, 2 * t_ipi)
495 */ 474 */
496 t_nfb = max(hctx->ccid3hctx_t_rto, 2 * hctx->ccid3hctx_t_ipi); 475 t_nfb = max(hc->tx_t_rto, 2 * hc->tx_t_ipi);
497 476
498 ccid3_pr_debug("%s(%p), Scheduled no feedback timer to " 477 ccid3_pr_debug("%s(%p), Scheduled no feedback timer to "
499 "expire in %lu jiffies (%luus)\n", 478 "expire in %lu jiffies (%luus)\n",
500 dccp_role(sk), 479 dccp_role(sk), sk, usecs_to_jiffies(t_nfb), t_nfb);
501 sk, usecs_to_jiffies(t_nfb), t_nfb);
502 480
503 sk_reset_timer(sk, &hctx->ccid3hctx_no_feedback_timer, 481 sk_reset_timer(sk, &hc->tx_no_feedback_timer,
504 jiffies + usecs_to_jiffies(t_nfb)); 482 jiffies + usecs_to_jiffies(t_nfb));
505} 483}
506 484
@@ -510,11 +488,11 @@ static int ccid3_hc_tx_parse_options(struct sock *sk, unsigned char option,
510{ 488{
511 int rc = 0; 489 int rc = 0;
512 const struct dccp_sock *dp = dccp_sk(sk); 490 const struct dccp_sock *dp = dccp_sk(sk);
513 struct ccid3_hc_tx_sock *hctx = ccid3_hc_tx_sk(sk); 491 struct ccid3_hc_tx_sock *hc = ccid3_hc_tx_sk(sk);
514 struct ccid3_options_received *opt_recv; 492 struct ccid3_options_received *opt_recv;
515 __be32 opt_val; 493 __be32 opt_val;
516 494
517 opt_recv = &hctx->ccid3hctx_options_received; 495 opt_recv = &hc->tx_options_received;
518 496
519 if (opt_recv->ccid3or_seqno != dp->dccps_gsr) { 497 if (opt_recv->ccid3or_seqno != dp->dccps_gsr) {
520 opt_recv->ccid3or_seqno = dp->dccps_gsr; 498 opt_recv->ccid3or_seqno = dp->dccps_gsr;
@@ -568,56 +546,55 @@ static int ccid3_hc_tx_parse_options(struct sock *sk, unsigned char option,
568 546
569static int ccid3_hc_tx_init(struct ccid *ccid, struct sock *sk) 547static int ccid3_hc_tx_init(struct ccid *ccid, struct sock *sk)
570{ 548{
571 struct ccid3_hc_tx_sock *hctx = ccid_priv(ccid); 549 struct ccid3_hc_tx_sock *hc = ccid_priv(ccid);
572 550
573 hctx->ccid3hctx_state = TFRC_SSTATE_NO_SENT; 551 hc->tx_state = TFRC_SSTATE_NO_SENT;
574 hctx->ccid3hctx_hist = NULL; 552 hc->tx_hist = NULL;
575 setup_timer(&hctx->ccid3hctx_no_feedback_timer, 553 setup_timer(&hc->tx_no_feedback_timer,
576 ccid3_hc_tx_no_feedback_timer, (unsigned long)sk); 554 ccid3_hc_tx_no_feedback_timer, (unsigned long)sk);
577
578 return 0; 555 return 0;
579} 556}
580 557
581static void ccid3_hc_tx_exit(struct sock *sk) 558static void ccid3_hc_tx_exit(struct sock *sk)
582{ 559{
583 struct ccid3_hc_tx_sock *hctx = ccid3_hc_tx_sk(sk); 560 struct ccid3_hc_tx_sock *hc = ccid3_hc_tx_sk(sk);
584 561
585 ccid3_hc_tx_set_state(sk, TFRC_SSTATE_TERM); 562 ccid3_hc_tx_set_state(sk, TFRC_SSTATE_TERM);
586 sk_stop_timer(sk, &hctx->ccid3hctx_no_feedback_timer); 563 sk_stop_timer(sk, &hc->tx_no_feedback_timer);
587 564
588 tfrc_tx_hist_purge(&hctx->ccid3hctx_hist); 565 tfrc_tx_hist_purge(&hc->tx_hist);
589} 566}
590 567
591static void ccid3_hc_tx_get_info(struct sock *sk, struct tcp_info *info) 568static void ccid3_hc_tx_get_info(struct sock *sk, struct tcp_info *info)
592{ 569{
593 struct ccid3_hc_tx_sock *hctx; 570 struct ccid3_hc_tx_sock *hc;
594 571
595 /* Listen socks doesn't have a private CCID block */ 572 /* Listen socks doesn't have a private CCID block */
596 if (sk->sk_state == DCCP_LISTEN) 573 if (sk->sk_state == DCCP_LISTEN)
597 return; 574 return;
598 575
599 hctx = ccid3_hc_tx_sk(sk); 576 hc = ccid3_hc_tx_sk(sk);
600 info->tcpi_rto = hctx->ccid3hctx_t_rto; 577 info->tcpi_rto = hc->tx_t_rto;
601 info->tcpi_rtt = hctx->ccid3hctx_rtt; 578 info->tcpi_rtt = hc->tx_rtt;
602} 579}
603 580
604static int ccid3_hc_tx_getsockopt(struct sock *sk, const int optname, int len, 581static int ccid3_hc_tx_getsockopt(struct sock *sk, const int optname, int len,
605 u32 __user *optval, int __user *optlen) 582 u32 __user *optval, int __user *optlen)
606{ 583{
607 const struct ccid3_hc_tx_sock *hctx; 584 const struct ccid3_hc_tx_sock *hc;
608 const void *val; 585 const void *val;
609 586
610 /* Listen socks doesn't have a private CCID block */ 587 /* Listen socks doesn't have a private CCID block */
611 if (sk->sk_state == DCCP_LISTEN) 588 if (sk->sk_state == DCCP_LISTEN)
612 return -EINVAL; 589 return -EINVAL;
613 590
614 hctx = ccid3_hc_tx_sk(sk); 591 hc = ccid3_hc_tx_sk(sk);
615 switch (optname) { 592 switch (optname) {
616 case DCCP_SOCKOPT_CCID_TX_INFO: 593 case DCCP_SOCKOPT_CCID_TX_INFO:
617 if (len < sizeof(hctx->ccid3hctx_tfrc)) 594 if (len < sizeof(hc->tx_tfrc))
618 return -EINVAL; 595 return -EINVAL;
619 len = sizeof(hctx->ccid3hctx_tfrc); 596 len = sizeof(hc->tx_tfrc);
620 val = &hctx->ccid3hctx_tfrc; 597 val = &hc->tx_tfrc;
621 break; 598 break;
622 default: 599 default:
623 return -ENOPROTOOPT; 600 return -ENOPROTOOPT;
@@ -657,34 +634,34 @@ static const char *ccid3_rx_state_name(enum ccid3_hc_rx_states state)
657static void ccid3_hc_rx_set_state(struct sock *sk, 634static void ccid3_hc_rx_set_state(struct sock *sk,
658 enum ccid3_hc_rx_states state) 635 enum ccid3_hc_rx_states state)
659{ 636{
660 struct ccid3_hc_rx_sock *hcrx = ccid3_hc_rx_sk(sk); 637 struct ccid3_hc_rx_sock *hc = ccid3_hc_rx_sk(sk);
661 enum ccid3_hc_rx_states oldstate = hcrx->ccid3hcrx_state; 638 enum ccid3_hc_rx_states oldstate = hc->rx_state;
662 639
663 ccid3_pr_debug("%s(%p) %-8.8s -> %s\n", 640 ccid3_pr_debug("%s(%p) %-8.8s -> %s\n",
664 dccp_role(sk), sk, ccid3_rx_state_name(oldstate), 641 dccp_role(sk), sk, ccid3_rx_state_name(oldstate),
665 ccid3_rx_state_name(state)); 642 ccid3_rx_state_name(state));
666 WARN_ON(state == oldstate); 643 WARN_ON(state == oldstate);
667 hcrx->ccid3hcrx_state = state; 644 hc->rx_state = state;
668} 645}
669 646
670static void ccid3_hc_rx_send_feedback(struct sock *sk, 647static void ccid3_hc_rx_send_feedback(struct sock *sk,
671 const struct sk_buff *skb, 648 const struct sk_buff *skb,
672 enum ccid3_fback_type fbtype) 649 enum ccid3_fback_type fbtype)
673{ 650{
674 struct ccid3_hc_rx_sock *hcrx = ccid3_hc_rx_sk(sk); 651 struct ccid3_hc_rx_sock *hc = ccid3_hc_rx_sk(sk);
675 struct dccp_sock *dp = dccp_sk(sk); 652 struct dccp_sock *dp = dccp_sk(sk);
676 ktime_t now; 653 ktime_t now;
677 s64 delta = 0; 654 s64 delta = 0;
678 655
679 if (unlikely(hcrx->ccid3hcrx_state == TFRC_RSTATE_TERM)) 656 if (unlikely(hc->rx_state == TFRC_RSTATE_TERM))
680 return; 657 return;
681 658
682 now = ktime_get_real(); 659 now = ktime_get_real();
683 660
684 switch (fbtype) { 661 switch (fbtype) {
685 case CCID3_FBACK_INITIAL: 662 case CCID3_FBACK_INITIAL:
686 hcrx->ccid3hcrx_x_recv = 0; 663 hc->rx_x_recv = 0;
687 hcrx->ccid3hcrx_pinv = ~0U; /* see RFC 4342, 8.5 */ 664 hc->rx_pinv = ~0U; /* see RFC 4342, 8.5 */
688 break; 665 break;
689 case CCID3_FBACK_PARAM_CHANGE: 666 case CCID3_FBACK_PARAM_CHANGE:
690 /* 667 /*
@@ -697,27 +674,26 @@ static void ccid3_hc_rx_send_feedback(struct sock *sk,
697 * the number of bytes since last feedback. 674 * the number of bytes since last feedback.
698 * This is a safe fallback, since X is bounded above by X_calc. 675 * This is a safe fallback, since X is bounded above by X_calc.
699 */ 676 */
700 if (hcrx->ccid3hcrx_x_recv > 0) 677 if (hc->rx_x_recv > 0)
701 break; 678 break;
702 /* fall through */ 679 /* fall through */
703 case CCID3_FBACK_PERIODIC: 680 case CCID3_FBACK_PERIODIC:
704 delta = ktime_us_delta(now, hcrx->ccid3hcrx_tstamp_last_feedback); 681 delta = ktime_us_delta(now, hc->rx_tstamp_last_feedback);
705 if (delta <= 0) 682 if (delta <= 0)
706 DCCP_BUG("delta (%ld) <= 0", (long)delta); 683 DCCP_BUG("delta (%ld) <= 0", (long)delta);
707 else 684 else
708 hcrx->ccid3hcrx_x_recv = 685 hc->rx_x_recv = scaled_div32(hc->rx_bytes_recv, delta);
709 scaled_div32(hcrx->ccid3hcrx_bytes_recv, delta);
710 break; 686 break;
711 default: 687 default:
712 return; 688 return;
713 } 689 }
714 690
715 ccid3_pr_debug("Interval %ldusec, X_recv=%u, 1/p=%u\n", (long)delta, 691 ccid3_pr_debug("Interval %ldusec, X_recv=%u, 1/p=%u\n", (long)delta,
716 hcrx->ccid3hcrx_x_recv, hcrx->ccid3hcrx_pinv); 692 hc->rx_x_recv, hc->rx_pinv);
717 693
718 hcrx->ccid3hcrx_tstamp_last_feedback = now; 694 hc->rx_tstamp_last_feedback = now;
719 hcrx->ccid3hcrx_last_counter = dccp_hdr(skb)->dccph_ccval; 695 hc->rx_last_counter = dccp_hdr(skb)->dccph_ccval;
720 hcrx->ccid3hcrx_bytes_recv = 0; 696 hc->rx_bytes_recv = 0;
721 697
722 dp->dccps_hc_rx_insert_options = 1; 698 dp->dccps_hc_rx_insert_options = 1;
723 dccp_send_ack(sk); 699 dccp_send_ack(sk);
@@ -725,19 +701,19 @@ static void ccid3_hc_rx_send_feedback(struct sock *sk,
725 701
726static int ccid3_hc_rx_insert_options(struct sock *sk, struct sk_buff *skb) 702static int ccid3_hc_rx_insert_options(struct sock *sk, struct sk_buff *skb)
727{ 703{
728 const struct ccid3_hc_rx_sock *hcrx; 704 const struct ccid3_hc_rx_sock *hc;
729 __be32 x_recv, pinv; 705 __be32 x_recv, pinv;
730 706
731 if (!(sk->sk_state == DCCP_OPEN || sk->sk_state == DCCP_PARTOPEN)) 707 if (!(sk->sk_state == DCCP_OPEN || sk->sk_state == DCCP_PARTOPEN))
732 return 0; 708 return 0;
733 709
734 hcrx = ccid3_hc_rx_sk(sk); 710 hc = ccid3_hc_rx_sk(sk);
735 711
736 if (dccp_packet_without_ack(skb)) 712 if (dccp_packet_without_ack(skb))
737 return 0; 713 return 0;
738 714
739 x_recv = htonl(hcrx->ccid3hcrx_x_recv); 715 x_recv = htonl(hc->rx_x_recv);
740 pinv = htonl(hcrx->ccid3hcrx_pinv); 716 pinv = htonl(hc->rx_pinv);
741 717
742 if (dccp_insert_option(sk, skb, TFRC_OPT_LOSS_EVENT_RATE, 718 if (dccp_insert_option(sk, skb, TFRC_OPT_LOSS_EVENT_RATE,
743 &pinv, sizeof(pinv)) || 719 &pinv, sizeof(pinv)) ||
@@ -760,26 +736,26 @@ static int ccid3_hc_rx_insert_options(struct sock *sk, struct sk_buff *skb)
760 */ 736 */
761static u32 ccid3_first_li(struct sock *sk) 737static u32 ccid3_first_li(struct sock *sk)
762{ 738{
763 struct ccid3_hc_rx_sock *hcrx = ccid3_hc_rx_sk(sk); 739 struct ccid3_hc_rx_sock *hc = ccid3_hc_rx_sk(sk);
764 u32 x_recv, p, delta; 740 u32 x_recv, p, delta;
765 u64 fval; 741 u64 fval;
766 742
767 if (hcrx->ccid3hcrx_rtt == 0) { 743 if (hc->rx_rtt == 0) {
768 DCCP_WARN("No RTT estimate available, using fallback RTT\n"); 744 DCCP_WARN("No RTT estimate available, using fallback RTT\n");
769 hcrx->ccid3hcrx_rtt = DCCP_FALLBACK_RTT; 745 hc->rx_rtt = DCCP_FALLBACK_RTT;
770 } 746 }
771 747
772 delta = ktime_to_us(net_timedelta(hcrx->ccid3hcrx_tstamp_last_feedback)); 748 delta = ktime_to_us(net_timedelta(hc->rx_tstamp_last_feedback));
773 x_recv = scaled_div32(hcrx->ccid3hcrx_bytes_recv, delta); 749 x_recv = scaled_div32(hc->rx_bytes_recv, delta);
774 if (x_recv == 0) { /* would also trigger divide-by-zero */ 750 if (x_recv == 0) { /* would also trigger divide-by-zero */
775 DCCP_WARN("X_recv==0\n"); 751 DCCP_WARN("X_recv==0\n");
776 if ((x_recv = hcrx->ccid3hcrx_x_recv) == 0) { 752 if ((x_recv = hc->rx_x_recv) == 0) {
777 DCCP_BUG("stored value of X_recv is zero"); 753 DCCP_BUG("stored value of X_recv is zero");
778 return ~0U; 754 return ~0U;
779 } 755 }
780 } 756 }
781 757
782 fval = scaled_div(hcrx->ccid3hcrx_s, hcrx->ccid3hcrx_rtt); 758 fval = scaled_div(hc->rx_s, hc->rx_rtt);
783 fval = scaled_div32(fval, x_recv); 759 fval = scaled_div32(fval, x_recv);
784 p = tfrc_calc_x_reverse_lookup(fval); 760 p = tfrc_calc_x_reverse_lookup(fval);
785 761
@@ -791,19 +767,19 @@ static u32 ccid3_first_li(struct sock *sk)
791 767
792static void ccid3_hc_rx_packet_recv(struct sock *sk, struct sk_buff *skb) 768static void ccid3_hc_rx_packet_recv(struct sock *sk, struct sk_buff *skb)
793{ 769{
794 struct ccid3_hc_rx_sock *hcrx = ccid3_hc_rx_sk(sk); 770 struct ccid3_hc_rx_sock *hc = ccid3_hc_rx_sk(sk);
795 enum ccid3_fback_type do_feedback = CCID3_FBACK_NONE; 771 enum ccid3_fback_type do_feedback = CCID3_FBACK_NONE;
796 const u64 ndp = dccp_sk(sk)->dccps_options_received.dccpor_ndp; 772 const u64 ndp = dccp_sk(sk)->dccps_options_received.dccpor_ndp;
797 const bool is_data_packet = dccp_data_packet(skb); 773 const bool is_data_packet = dccp_data_packet(skb);
798 774
799 if (unlikely(hcrx->ccid3hcrx_state == TFRC_RSTATE_NO_DATA)) { 775 if (unlikely(hc->rx_state == TFRC_RSTATE_NO_DATA)) {
800 if (is_data_packet) { 776 if (is_data_packet) {
801 const u32 payload = skb->len - dccp_hdr(skb)->dccph_doff * 4; 777 const u32 payload = skb->len - dccp_hdr(skb)->dccph_doff * 4;
802 do_feedback = CCID3_FBACK_INITIAL; 778 do_feedback = CCID3_FBACK_INITIAL;
803 ccid3_hc_rx_set_state(sk, TFRC_RSTATE_DATA); 779 ccid3_hc_rx_set_state(sk, TFRC_RSTATE_DATA);
804 hcrx->ccid3hcrx_s = payload; 780 hc->rx_s = payload;
805 /* 781 /*
806 * Not necessary to update ccid3hcrx_bytes_recv here, 782 * Not necessary to update rx_bytes_recv here,
807 * since X_recv = 0 for the first feedback packet (cf. 783 * since X_recv = 0 for the first feedback packet (cf.
808 * RFC 3448, 6.3) -- gerrit 784 * RFC 3448, 6.3) -- gerrit
809 */ 785 */
@@ -811,7 +787,7 @@ static void ccid3_hc_rx_packet_recv(struct sock *sk, struct sk_buff *skb)
811 goto update_records; 787 goto update_records;
812 } 788 }
813 789
814 if (tfrc_rx_hist_duplicate(&hcrx->ccid3hcrx_hist, skb)) 790 if (tfrc_rx_hist_duplicate(&hc->rx_hist, skb))
815 return; /* done receiving */ 791 return; /* done receiving */
816 792
817 if (is_data_packet) { 793 if (is_data_packet) {
@@ -819,20 +795,20 @@ static void ccid3_hc_rx_packet_recv(struct sock *sk, struct sk_buff *skb)
819 /* 795 /*
820 * Update moving-average of s and the sum of received payload bytes 796 * Update moving-average of s and the sum of received payload bytes
821 */ 797 */
822 hcrx->ccid3hcrx_s = tfrc_ewma(hcrx->ccid3hcrx_s, payload, 9); 798 hc->rx_s = tfrc_ewma(hc->rx_s, payload, 9);
823 hcrx->ccid3hcrx_bytes_recv += payload; 799 hc->rx_bytes_recv += payload;
824 } 800 }
825 801
826 /* 802 /*
827 * Perform loss detection and handle pending losses 803 * Perform loss detection and handle pending losses
828 */ 804 */
829 if (tfrc_rx_handle_loss(&hcrx->ccid3hcrx_hist, &hcrx->ccid3hcrx_li_hist, 805 if (tfrc_rx_handle_loss(&hc->rx_hist, &hc->rx_li_hist,
830 skb, ndp, ccid3_first_li, sk)) { 806 skb, ndp, ccid3_first_li, sk)) {
831 do_feedback = CCID3_FBACK_PARAM_CHANGE; 807 do_feedback = CCID3_FBACK_PARAM_CHANGE;
832 goto done_receiving; 808 goto done_receiving;
833 } 809 }
834 810
835 if (tfrc_rx_hist_loss_pending(&hcrx->ccid3hcrx_hist)) 811 if (tfrc_rx_hist_loss_pending(&hc->rx_hist))
836 return; /* done receiving */ 812 return; /* done receiving */
837 813
838 /* 814 /*
@@ -841,17 +817,17 @@ static void ccid3_hc_rx_packet_recv(struct sock *sk, struct sk_buff *skb)
841 if (unlikely(!is_data_packet)) 817 if (unlikely(!is_data_packet))
842 goto update_records; 818 goto update_records;
843 819
844 if (!tfrc_lh_is_initialised(&hcrx->ccid3hcrx_li_hist)) { 820 if (!tfrc_lh_is_initialised(&hc->rx_li_hist)) {
845 const u32 sample = tfrc_rx_hist_sample_rtt(&hcrx->ccid3hcrx_hist, skb); 821 const u32 sample = tfrc_rx_hist_sample_rtt(&hc->rx_hist, skb);
846 /* 822 /*
847 * Empty loss history: no loss so far, hence p stays 0. 823 * Empty loss history: no loss so far, hence p stays 0.
848 * Sample RTT values, since an RTT estimate is required for the 824 * Sample RTT values, since an RTT estimate is required for the
849 * computation of p when the first loss occurs; RFC 3448, 6.3.1. 825 * computation of p when the first loss occurs; RFC 3448, 6.3.1.
850 */ 826 */
851 if (sample != 0) 827 if (sample != 0)
852 hcrx->ccid3hcrx_rtt = tfrc_ewma(hcrx->ccid3hcrx_rtt, sample, 9); 828 hc->rx_rtt = tfrc_ewma(hc->rx_rtt, sample, 9);
853 829
854 } else if (tfrc_lh_update_i_mean(&hcrx->ccid3hcrx_li_hist, skb)) { 830 } else if (tfrc_lh_update_i_mean(&hc->rx_li_hist, skb)) {
855 /* 831 /*
856 * Step (3) of [RFC 3448, 6.1]: Recompute I_mean and, if I_mean 832 * Step (3) of [RFC 3448, 6.1]: Recompute I_mean and, if I_mean
857 * has decreased (resp. p has increased), send feedback now. 833 * has decreased (resp. p has increased), send feedback now.
@@ -862,11 +838,11 @@ static void ccid3_hc_rx_packet_recv(struct sock *sk, struct sk_buff *skb)
862 /* 838 /*
863 * Check if the periodic once-per-RTT feedback is due; RFC 4342, 10.3 839 * Check if the periodic once-per-RTT feedback is due; RFC 4342, 10.3
864 */ 840 */
865 if (SUB16(dccp_hdr(skb)->dccph_ccval, hcrx->ccid3hcrx_last_counter) > 3) 841 if (SUB16(dccp_hdr(skb)->dccph_ccval, hc->rx_last_counter) > 3)
866 do_feedback = CCID3_FBACK_PERIODIC; 842 do_feedback = CCID3_FBACK_PERIODIC;
867 843
868update_records: 844update_records:
869 tfrc_rx_hist_add_packet(&hcrx->ccid3hcrx_hist, skb, ndp); 845 tfrc_rx_hist_add_packet(&hc->rx_hist, skb, ndp);
870 846
871done_receiving: 847done_receiving:
872 if (do_feedback) 848 if (do_feedback)
@@ -875,41 +851,41 @@ done_receiving:
875 851
876static int ccid3_hc_rx_init(struct ccid *ccid, struct sock *sk) 852static int ccid3_hc_rx_init(struct ccid *ccid, struct sock *sk)
877{ 853{
878 struct ccid3_hc_rx_sock *hcrx = ccid_priv(ccid); 854 struct ccid3_hc_rx_sock *hc = ccid_priv(ccid);
879 855
880 hcrx->ccid3hcrx_state = TFRC_RSTATE_NO_DATA; 856 hc->rx_state = TFRC_RSTATE_NO_DATA;
881 tfrc_lh_init(&hcrx->ccid3hcrx_li_hist); 857 tfrc_lh_init(&hc->rx_li_hist);
882 return tfrc_rx_hist_alloc(&hcrx->ccid3hcrx_hist); 858 return tfrc_rx_hist_alloc(&hc->rx_hist);
883} 859}
884 860
885static void ccid3_hc_rx_exit(struct sock *sk) 861static void ccid3_hc_rx_exit(struct sock *sk)
886{ 862{
887 struct ccid3_hc_rx_sock *hcrx = ccid3_hc_rx_sk(sk); 863 struct ccid3_hc_rx_sock *hc = ccid3_hc_rx_sk(sk);
888 864
889 ccid3_hc_rx_set_state(sk, TFRC_RSTATE_TERM); 865 ccid3_hc_rx_set_state(sk, TFRC_RSTATE_TERM);
890 866
891 tfrc_rx_hist_purge(&hcrx->ccid3hcrx_hist); 867 tfrc_rx_hist_purge(&hc->rx_hist);
892 tfrc_lh_cleanup(&hcrx->ccid3hcrx_li_hist); 868 tfrc_lh_cleanup(&hc->rx_li_hist);
893} 869}
894 870
895static void ccid3_hc_rx_get_info(struct sock *sk, struct tcp_info *info) 871static void ccid3_hc_rx_get_info(struct sock *sk, struct tcp_info *info)
896{ 872{
897 const struct ccid3_hc_rx_sock *hcrx; 873 const struct ccid3_hc_rx_sock *hc;
898 874
899 /* Listen socks doesn't have a private CCID block */ 875 /* Listen socks doesn't have a private CCID block */
900 if (sk->sk_state == DCCP_LISTEN) 876 if (sk->sk_state == DCCP_LISTEN)
901 return; 877 return;
902 878
903 hcrx = ccid3_hc_rx_sk(sk); 879 hc = ccid3_hc_rx_sk(sk);
904 info->tcpi_ca_state = hcrx->ccid3hcrx_state; 880 info->tcpi_ca_state = hc->rx_state;
905 info->tcpi_options |= TCPI_OPT_TIMESTAMPS; 881 info->tcpi_options |= TCPI_OPT_TIMESTAMPS;
906 info->tcpi_rcv_rtt = hcrx->ccid3hcrx_rtt; 882 info->tcpi_rcv_rtt = hc->rx_rtt;
907} 883}
908 884
909static int ccid3_hc_rx_getsockopt(struct sock *sk, const int optname, int len, 885static int ccid3_hc_rx_getsockopt(struct sock *sk, const int optname, int len,
910 u32 __user *optval, int __user *optlen) 886 u32 __user *optval, int __user *optlen)
911{ 887{
912 const struct ccid3_hc_rx_sock *hcrx; 888 const struct ccid3_hc_rx_sock *hc;
913 struct tfrc_rx_info rx_info; 889 struct tfrc_rx_info rx_info;
914 const void *val; 890 const void *val;
915 891
@@ -917,15 +893,15 @@ static int ccid3_hc_rx_getsockopt(struct sock *sk, const int optname, int len,
917 if (sk->sk_state == DCCP_LISTEN) 893 if (sk->sk_state == DCCP_LISTEN)
918 return -EINVAL; 894 return -EINVAL;
919 895
920 hcrx = ccid3_hc_rx_sk(sk); 896 hc = ccid3_hc_rx_sk(sk);
921 switch (optname) { 897 switch (optname) {
922 case DCCP_SOCKOPT_CCID_RX_INFO: 898 case DCCP_SOCKOPT_CCID_RX_INFO:
923 if (len < sizeof(rx_info)) 899 if (len < sizeof(rx_info))
924 return -EINVAL; 900 return -EINVAL;
925 rx_info.tfrcrx_x_recv = hcrx->ccid3hcrx_x_recv; 901 rx_info.tfrcrx_x_recv = hc->rx_x_recv;
926 rx_info.tfrcrx_rtt = hcrx->ccid3hcrx_rtt; 902 rx_info.tfrcrx_rtt = hc->rx_rtt;
927 rx_info.tfrcrx_p = hcrx->ccid3hcrx_pinv == 0 ? ~0U : 903 rx_info.tfrcrx_p = hc->rx_pinv == 0 ? ~0U :
928 scaled_div(1, hcrx->ccid3hcrx_pinv); 904 scaled_div(1, hc->rx_pinv);
929 len = sizeof(rx_info); 905 len = sizeof(rx_info);
930 val = &rx_info; 906 val = &rx_info;
931 break; 907 break;
diff --git a/net/dccp/ccids/ccid3.h b/net/dccp/ccids/ccid3.h
index e5a244143846..032635776653 100644
--- a/net/dccp/ccids/ccid3.h
+++ b/net/dccp/ccids/ccid3.h
@@ -75,44 +75,44 @@ enum ccid3_hc_tx_states {
75 75
76/** 76/**
77 * struct ccid3_hc_tx_sock - CCID3 sender half-connection socket 77 * struct ccid3_hc_tx_sock - CCID3 sender half-connection socket
78 * @ccid3hctx_x - Current sending rate in 64 * bytes per second 78 * @tx_x: Current sending rate in 64 * bytes per second
79 * @ccid3hctx_x_recv - Receive rate in 64 * bytes per second 79 * @tx_x_recv: Receive rate in 64 * bytes per second
80 * @ccid3hctx_x_calc - Calculated rate in bytes per second 80 * @tx_x_calc: Calculated rate in bytes per second
81 * @ccid3hctx_rtt - Estimate of current round trip time in usecs 81 * @tx_rtt: Estimate of current round trip time in usecs
82 * @ccid3hctx_p - Current loss event rate (0-1) scaled by 1000000 82 * @tx_p: Current loss event rate (0-1) scaled by 1000000
83 * @ccid3hctx_s - Packet size in bytes 83 * @tx_s: Packet size in bytes
84 * @ccid3hctx_t_rto - Nofeedback Timer setting in usecs 84 * @tx_t_rto: Nofeedback Timer setting in usecs
85 * @ccid3hctx_t_ipi - Interpacket (send) interval (RFC 3448, 4.6) in usecs 85 * @tx_t_ipi: Interpacket (send) interval (RFC 3448, 4.6) in usecs
86 * @ccid3hctx_state - Sender state, one of %ccid3_hc_tx_states 86 * @tx_state: Sender state, one of %ccid3_hc_tx_states
87 * @ccid3hctx_last_win_count - Last window counter sent 87 * @tx_last_win_count: Last window counter sent
88 * @ccid3hctx_t_last_win_count - Timestamp of earliest packet 88 * @tx_t_last_win_count: Timestamp of earliest packet
89 * with last_win_count value sent 89 * with last_win_count value sent
90 * @ccid3hctx_no_feedback_timer - Handle to no feedback timer 90 * @tx_no_feedback_timer: Handle to no feedback timer
91 * @ccid3hctx_t_ld - Time last doubled during slow start 91 * @tx_t_ld: Time last doubled during slow start
92 * @ccid3hctx_t_nom - Nominal send time of next packet 92 * @tx_t_nom: Nominal send time of next packet
93 * @ccid3hctx_delta - Send timer delta (RFC 3448, 4.6) in usecs 93 * @tx_delta: Send timer delta (RFC 3448, 4.6) in usecs
94 * @ccid3hctx_hist - Packet history 94 * @tx_hist: Packet history
95 * @ccid3hctx_options_received - Parsed set of retrieved options 95 * @tx_options_received: Parsed set of retrieved options
96 */ 96 */
97struct ccid3_hc_tx_sock { 97struct ccid3_hc_tx_sock {
98 struct tfrc_tx_info ccid3hctx_tfrc; 98 struct tfrc_tx_info tx_tfrc;
99#define ccid3hctx_x ccid3hctx_tfrc.tfrctx_x 99#define tx_x tx_tfrc.tfrctx_x
100#define ccid3hctx_x_recv ccid3hctx_tfrc.tfrctx_x_recv 100#define tx_x_recv tx_tfrc.tfrctx_x_recv
101#define ccid3hctx_x_calc ccid3hctx_tfrc.tfrctx_x_calc 101#define tx_x_calc tx_tfrc.tfrctx_x_calc
102#define ccid3hctx_rtt ccid3hctx_tfrc.tfrctx_rtt 102#define tx_rtt tx_tfrc.tfrctx_rtt
103#define ccid3hctx_p ccid3hctx_tfrc.tfrctx_p 103#define tx_p tx_tfrc.tfrctx_p
104#define ccid3hctx_t_rto ccid3hctx_tfrc.tfrctx_rto 104#define tx_t_rto tx_tfrc.tfrctx_rto
105#define ccid3hctx_t_ipi ccid3hctx_tfrc.tfrctx_ipi 105#define tx_t_ipi tx_tfrc.tfrctx_ipi
106 u16 ccid3hctx_s; 106 u16 tx_s;
107 enum ccid3_hc_tx_states ccid3hctx_state:8; 107 enum ccid3_hc_tx_states tx_state:8;
108 u8 ccid3hctx_last_win_count; 108 u8 tx_last_win_count;
109 ktime_t ccid3hctx_t_last_win_count; 109 ktime_t tx_t_last_win_count;
110 struct timer_list ccid3hctx_no_feedback_timer; 110 struct timer_list tx_no_feedback_timer;
111 ktime_t ccid3hctx_t_ld; 111 ktime_t tx_t_ld;
112 ktime_t ccid3hctx_t_nom; 112 ktime_t tx_t_nom;
113 u32 ccid3hctx_delta; 113 u32 tx_delta;
114 struct tfrc_tx_hist_entry *ccid3hctx_hist; 114 struct tfrc_tx_hist_entry *tx_hist;
115 struct ccid3_options_received ccid3hctx_options_received; 115 struct ccid3_options_received tx_options_received;
116}; 116};
117 117
118static inline struct ccid3_hc_tx_sock *ccid3_hc_tx_sk(const struct sock *sk) 118static inline struct ccid3_hc_tx_sock *ccid3_hc_tx_sk(const struct sock *sk)
@@ -131,32 +131,32 @@ enum ccid3_hc_rx_states {
131 131
132/** 132/**
133 * struct ccid3_hc_rx_sock - CCID3 receiver half-connection socket 133 * struct ccid3_hc_rx_sock - CCID3 receiver half-connection socket
134 * @ccid3hcrx_x_recv - Receiver estimate of send rate (RFC 3448 4.3) 134 * @rx_x_recv: Receiver estimate of send rate (RFC 3448 4.3)
135 * @ccid3hcrx_rtt - Receiver estimate of rtt (non-standard) 135 * @rx_rtt: Receiver estimate of rtt (non-standard)
136 * @ccid3hcrx_p - Current loss event rate (RFC 3448 5.4) 136 * @rx_p: Current loss event rate (RFC 3448 5.4)
137 * @ccid3hcrx_last_counter - Tracks window counter (RFC 4342, 8.1) 137 * @rx_last_counter: Tracks window counter (RFC 4342, 8.1)
138 * @ccid3hcrx_state - Receiver state, one of %ccid3_hc_rx_states 138 * @rx_state: Receiver state, one of %ccid3_hc_rx_states
139 * @ccid3hcrx_bytes_recv - Total sum of DCCP payload bytes 139 * @rx_bytes_recv: Total sum of DCCP payload bytes
140 * @ccid3hcrx_x_recv - Receiver estimate of send rate (RFC 3448, sec. 4.3) 140 * @rx_x_recv: Receiver estimate of send rate (RFC 3448, sec. 4.3)
141 * @ccid3hcrx_rtt - Receiver estimate of RTT 141 * @rx_rtt: Receiver estimate of RTT
142 * @ccid3hcrx_tstamp_last_feedback - Time at which last feedback was sent 142 * @rx_tstamp_last_feedback: Time at which last feedback was sent
143 * @ccid3hcrx_tstamp_last_ack - Time at which last feedback was sent 143 * @rx_tstamp_last_ack: Time at which last feedback was sent
144 * @ccid3hcrx_hist - Packet history (loss detection + RTT sampling) 144 * @rx_hist: Packet history (loss detection + RTT sampling)
145 * @ccid3hcrx_li_hist - Loss Interval database 145 * @rx_li_hist: Loss Interval database
146 * @ccid3hcrx_s - Received packet size in bytes 146 * @rx_s: Received packet size in bytes
147 * @ccid3hcrx_pinv - Inverse of Loss Event Rate (RFC 4342, sec. 8.5) 147 * @rx_pinv: Inverse of Loss Event Rate (RFC 4342, sec. 8.5)
148 */ 148 */
149struct ccid3_hc_rx_sock { 149struct ccid3_hc_rx_sock {
150 u8 ccid3hcrx_last_counter:4; 150 u8 rx_last_counter:4;
151 enum ccid3_hc_rx_states ccid3hcrx_state:8; 151 enum ccid3_hc_rx_states rx_state:8;
152 u32 ccid3hcrx_bytes_recv; 152 u32 rx_bytes_recv;
153 u32 ccid3hcrx_x_recv; 153 u32 rx_x_recv;
154 u32 ccid3hcrx_rtt; 154 u32 rx_rtt;
155 ktime_t ccid3hcrx_tstamp_last_feedback; 155 ktime_t rx_tstamp_last_feedback;
156 struct tfrc_rx_hist ccid3hcrx_hist; 156 struct tfrc_rx_hist rx_hist;
157 struct tfrc_loss_hist ccid3hcrx_li_hist; 157 struct tfrc_loss_hist rx_li_hist;
158 u16 ccid3hcrx_s; 158 u16 rx_s;
159#define ccid3hcrx_pinv ccid3hcrx_li_hist.i_mean 159#define rx_pinv rx_li_hist.i_mean
160}; 160};
161 161
162static inline struct ccid3_hc_rx_sock *ccid3_hc_rx_sk(const struct sock *sk) 162static inline struct ccid3_hc_rx_sock *ccid3_hc_rx_sk(const struct sock *sk)
diff --git a/net/dccp/feat.c b/net/dccp/feat.c
index 972b8dc918d6..df7dd26cf07e 100644
--- a/net/dccp/feat.c
+++ b/net/dccp/feat.c
@@ -22,6 +22,7 @@
22 * 2 of the License, or (at your option) any later version. 22 * 2 of the License, or (at your option) any later version.
23 */ 23 */
24#include <linux/module.h> 24#include <linux/module.h>
25#include <linux/slab.h>
25#include "ccid.h" 26#include "ccid.h"
26#include "feat.h" 27#include "feat.h"
27 28
diff --git a/net/dccp/input.c b/net/dccp/input.c
index 7648f316310f..9ec717426024 100644
--- a/net/dccp/input.c
+++ b/net/dccp/input.c
@@ -12,6 +12,7 @@
12 12
13#include <linux/dccp.h> 13#include <linux/dccp.h>
14#include <linux/skbuff.h> 14#include <linux/skbuff.h>
15#include <linux/slab.h>
15 16
16#include <net/sock.h> 17#include <net/sock.h>
17 18
diff --git a/net/dccp/ipv4.c b/net/dccp/ipv4.c
index 7302e1498d46..52ffa1cde15a 100644
--- a/net/dccp/ipv4.c
+++ b/net/dccp/ipv4.c
@@ -12,6 +12,7 @@
12 12
13#include <linux/dccp.h> 13#include <linux/dccp.h>
14#include <linux/icmp.h> 14#include <linux/icmp.h>
15#include <linux/slab.h>
15#include <linux/module.h> 16#include <linux/module.h>
16#include <linux/skbuff.h> 17#include <linux/skbuff.h>
17#include <linux/random.h> 18#include <linux/random.h>
@@ -62,10 +63,10 @@ int dccp_v4_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len)
62 nexthop = inet->opt->faddr; 63 nexthop = inet->opt->faddr;
63 } 64 }
64 65
65 tmp = ip_route_connect(&rt, nexthop, inet->saddr, 66 tmp = ip_route_connect(&rt, nexthop, inet->inet_saddr,
66 RT_CONN_FLAGS(sk), sk->sk_bound_dev_if, 67 RT_CONN_FLAGS(sk), sk->sk_bound_dev_if,
67 IPPROTO_DCCP, 68 IPPROTO_DCCP,
68 inet->sport, usin->sin_port, sk, 1); 69 inet->inet_sport, usin->sin_port, sk, 1);
69 if (tmp < 0) 70 if (tmp < 0)
70 return tmp; 71 return tmp;
71 72
@@ -77,12 +78,12 @@ int dccp_v4_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len)
77 if (inet->opt == NULL || !inet->opt->srr) 78 if (inet->opt == NULL || !inet->opt->srr)
78 daddr = rt->rt_dst; 79 daddr = rt->rt_dst;
79 80
80 if (inet->saddr == 0) 81 if (inet->inet_saddr == 0)
81 inet->saddr = rt->rt_src; 82 inet->inet_saddr = rt->rt_src;
82 inet->rcv_saddr = inet->saddr; 83 inet->inet_rcv_saddr = inet->inet_saddr;
83 84
84 inet->dport = usin->sin_port; 85 inet->inet_dport = usin->sin_port;
85 inet->daddr = daddr; 86 inet->inet_daddr = daddr;
86 87
87 inet_csk(sk)->icsk_ext_hdr_len = 0; 88 inet_csk(sk)->icsk_ext_hdr_len = 0;
88 if (inet->opt != NULL) 89 if (inet->opt != NULL)
@@ -98,17 +99,19 @@ int dccp_v4_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len)
98 if (err != 0) 99 if (err != 0)
99 goto failure; 100 goto failure;
100 101
101 err = ip_route_newports(&rt, IPPROTO_DCCP, inet->sport, inet->dport, 102 err = ip_route_newports(&rt, IPPROTO_DCCP, inet->inet_sport,
102 sk); 103 inet->inet_dport, sk);
103 if (err != 0) 104 if (err != 0)
104 goto failure; 105 goto failure;
105 106
106 /* OK, now commit destination to socket. */ 107 /* OK, now commit destination to socket. */
107 sk_setup_caps(sk, &rt->u.dst); 108 sk_setup_caps(sk, &rt->u.dst);
108 109
109 dp->dccps_iss = secure_dccp_sequence_number(inet->saddr, inet->daddr, 110 dp->dccps_iss = secure_dccp_sequence_number(inet->inet_saddr,
110 inet->sport, inet->dport); 111 inet->inet_daddr,
111 inet->id = dp->dccps_iss ^ jiffies; 112 inet->inet_sport,
113 inet->inet_dport);
114 inet->inet_id = dp->dccps_iss ^ jiffies;
112 115
113 err = dccp_connect(sk); 116 err = dccp_connect(sk);
114 rt = NULL; 117 rt = NULL;
@@ -123,7 +126,7 @@ failure:
123 dccp_set_state(sk, DCCP_CLOSED); 126 dccp_set_state(sk, DCCP_CLOSED);
124 ip_rt_put(rt); 127 ip_rt_put(rt);
125 sk->sk_route_caps = 0; 128 sk->sk_route_caps = 0;
126 inet->dport = 0; 129 inet->inet_dport = 0;
127 goto out; 130 goto out;
128} 131}
129 132
@@ -352,7 +355,9 @@ void dccp_v4_send_check(struct sock *sk, int unused, struct sk_buff *skb)
352 struct dccp_hdr *dh = dccp_hdr(skb); 355 struct dccp_hdr *dh = dccp_hdr(skb);
353 356
354 dccp_csum_outgoing(skb); 357 dccp_csum_outgoing(skb);
355 dh->dccph_checksum = dccp_v4_csum_finish(skb, inet->saddr, inet->daddr); 358 dh->dccph_checksum = dccp_v4_csum_finish(skb,
359 inet->inet_saddr,
360 inet->inet_daddr);
356} 361}
357 362
358EXPORT_SYMBOL_GPL(dccp_v4_send_check); 363EXPORT_SYMBOL_GPL(dccp_v4_send_check);
@@ -393,18 +398,18 @@ struct sock *dccp_v4_request_recv_sock(struct sock *sk, struct sk_buff *skb,
393 398
394 newinet = inet_sk(newsk); 399 newinet = inet_sk(newsk);
395 ireq = inet_rsk(req); 400 ireq = inet_rsk(req);
396 newinet->daddr = ireq->rmt_addr; 401 newinet->inet_daddr = ireq->rmt_addr;
397 newinet->rcv_saddr = ireq->loc_addr; 402 newinet->inet_rcv_saddr = ireq->loc_addr;
398 newinet->saddr = ireq->loc_addr; 403 newinet->inet_saddr = ireq->loc_addr;
399 newinet->opt = ireq->opt; 404 newinet->opt = ireq->opt;
400 ireq->opt = NULL; 405 ireq->opt = NULL;
401 newinet->mc_index = inet_iif(skb); 406 newinet->mc_index = inet_iif(skb);
402 newinet->mc_ttl = ip_hdr(skb)->ttl; 407 newinet->mc_ttl = ip_hdr(skb)->ttl;
403 newinet->id = jiffies; 408 newinet->inet_id = jiffies;
404 409
405 dccp_sync_mss(newsk, dst_mtu(dst)); 410 dccp_sync_mss(newsk, dst_mtu(dst));
406 411
407 __inet_hash_nolisten(newsk); 412 __inet_hash_nolisten(newsk, NULL);
408 __inet_inherit_port(sk, newsk); 413 __inet_inherit_port(sk, newsk);
409 414
410 return newsk; 415 return newsk;
@@ -473,7 +478,8 @@ static struct dst_entry* dccp_v4_route_skb(struct net *net, struct sock *sk,
473 return &rt->u.dst; 478 return &rt->u.dst;
474} 479}
475 480
476static int dccp_v4_send_response(struct sock *sk, struct request_sock *req) 481static int dccp_v4_send_response(struct sock *sk, struct request_sock *req,
482 struct request_values *rv_unused)
477{ 483{
478 int err = -1; 484 int err = -1;
479 struct sk_buff *skb; 485 struct sk_buff *skb;
@@ -622,7 +628,7 @@ int dccp_v4_conn_request(struct sock *sk, struct sk_buff *skb)
622 dreq->dreq_iss = dccp_v4_init_sequence(skb); 628 dreq->dreq_iss = dccp_v4_init_sequence(skb);
623 dreq->dreq_service = service; 629 dreq->dreq_service = service;
624 630
625 if (dccp_v4_send_response(sk, req)) 631 if (dccp_v4_send_response(sk, req, NULL))
626 goto drop_and_free; 632 goto drop_and_free;
627 633
628 inet_csk_reqsk_queue_hash_add(sk, req, DCCP_TIMEOUT_INIT); 634 inet_csk_reqsk_queue_hash_add(sk, req, DCCP_TIMEOUT_INIT);
@@ -987,21 +993,20 @@ static struct inet_protosw dccp_v4_protosw = {
987 .protocol = IPPROTO_DCCP, 993 .protocol = IPPROTO_DCCP,
988 .prot = &dccp_v4_prot, 994 .prot = &dccp_v4_prot,
989 .ops = &inet_dccp_ops, 995 .ops = &inet_dccp_ops,
990 .capability = -1,
991 .no_check = 0, 996 .no_check = 0,
992 .flags = INET_PROTOSW_ICSK, 997 .flags = INET_PROTOSW_ICSK,
993}; 998};
994 999
995static int dccp_v4_init_net(struct net *net) 1000static int __net_init dccp_v4_init_net(struct net *net)
996{ 1001{
997 int err; 1002 if (dccp_hashinfo.bhash == NULL)
1003 return -ESOCKTNOSUPPORT;
998 1004
999 err = inet_ctl_sock_create(&net->dccp.v4_ctl_sk, PF_INET, 1005 return inet_ctl_sock_create(&net->dccp.v4_ctl_sk, PF_INET,
1000 SOCK_DCCP, IPPROTO_DCCP, net); 1006 SOCK_DCCP, IPPROTO_DCCP, net);
1001 return err;
1002} 1007}
1003 1008
1004static void dccp_v4_exit_net(struct net *net) 1009static void __net_exit dccp_v4_exit_net(struct net *net)
1005{ 1010{
1006 inet_ctl_sock_destroy(net->dccp.v4_ctl_sk); 1011 inet_ctl_sock_destroy(net->dccp.v4_ctl_sk);
1007} 1012}
diff --git a/net/dccp/ipv6.c b/net/dccp/ipv6.c
index e48ca5d45658..3b11e41a2929 100644
--- a/net/dccp/ipv6.c
+++ b/net/dccp/ipv6.c
@@ -14,6 +14,7 @@
14 14
15#include <linux/module.h> 15#include <linux/module.h>
16#include <linux/random.h> 16#include <linux/random.h>
17#include <linux/slab.h>
17#include <linux/xfrm.h> 18#include <linux/xfrm.h>
18 19
19#include <net/addrconf.h> 20#include <net/addrconf.h>
@@ -46,7 +47,7 @@ static void dccp_v6_hash(struct sock *sk)
46 return; 47 return;
47 } 48 }
48 local_bh_disable(); 49 local_bh_disable();
49 __inet6_hash(sk); 50 __inet6_hash(sk, NULL);
50 local_bh_enable(); 51 local_bh_enable();
51 } 52 }
52} 53}
@@ -158,8 +159,8 @@ static void dccp_v6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
158 ipv6_addr_copy(&fl.fl6_dst, &np->daddr); 159 ipv6_addr_copy(&fl.fl6_dst, &np->daddr);
159 ipv6_addr_copy(&fl.fl6_src, &np->saddr); 160 ipv6_addr_copy(&fl.fl6_src, &np->saddr);
160 fl.oif = sk->sk_bound_dev_if; 161 fl.oif = sk->sk_bound_dev_if;
161 fl.fl_ip_dport = inet->dport; 162 fl.fl_ip_dport = inet->inet_dport;
162 fl.fl_ip_sport = inet->sport; 163 fl.fl_ip_sport = inet->inet_sport;
163 security_sk_classify_flow(sk, &fl); 164 security_sk_classify_flow(sk, &fl);
164 165
165 err = ip6_dst_lookup(sk, &dst, &fl); 166 err = ip6_dst_lookup(sk, &dst, &fl);
@@ -241,7 +242,8 @@ out:
241} 242}
242 243
243 244
244static int dccp_v6_send_response(struct sock *sk, struct request_sock *req) 245static int dccp_v6_send_response(struct sock *sk, struct request_sock *req,
246 struct request_values *rv_unused)
245{ 247{
246 struct inet6_request_sock *ireq6 = inet6_rsk(req); 248 struct inet6_request_sock *ireq6 = inet6_rsk(req);
247 struct ipv6_pinfo *np = inet6_sk(sk); 249 struct ipv6_pinfo *np = inet6_sk(sk);
@@ -468,7 +470,7 @@ static int dccp_v6_conn_request(struct sock *sk, struct sk_buff *skb)
468 dreq->dreq_iss = dccp_v6_init_sequence(skb); 470 dreq->dreq_iss = dccp_v6_init_sequence(skb);
469 dreq->dreq_service = service; 471 dreq->dreq_service = service;
470 472
471 if (dccp_v6_send_response(sk, req)) 473 if (dccp_v6_send_response(sk, req, NULL))
472 goto drop_and_free; 474 goto drop_and_free;
473 475
474 inet6_csk_reqsk_queue_hash_add(sk, req, DCCP_TIMEOUT_INIT); 476 inet6_csk_reqsk_queue_hash_add(sk, req, DCCP_TIMEOUT_INIT);
@@ -510,11 +512,9 @@ static struct sock *dccp_v6_request_recv_sock(struct sock *sk,
510 512
511 memcpy(newnp, np, sizeof(struct ipv6_pinfo)); 513 memcpy(newnp, np, sizeof(struct ipv6_pinfo));
512 514
513 ipv6_addr_set(&newnp->daddr, 0, 0, htonl(0x0000FFFF), 515 ipv6_addr_set_v4mapped(newinet->inet_daddr, &newnp->daddr);
514 newinet->daddr);
515 516
516 ipv6_addr_set(&newnp->saddr, 0, 0, htonl(0x0000FFFF), 517 ipv6_addr_set_v4mapped(newinet->inet_saddr, &newnp->saddr);
517 newinet->saddr);
518 518
519 ipv6_addr_copy(&newnp->rcv_saddr, &newnp->saddr); 519 ipv6_addr_copy(&newnp->rcv_saddr, &newnp->saddr);
520 520
@@ -642,9 +642,10 @@ static struct sock *dccp_v6_request_recv_sock(struct sock *sk,
642 642
643 dccp_sync_mss(newsk, dst_mtu(dst)); 643 dccp_sync_mss(newsk, dst_mtu(dst));
644 644
645 newinet->daddr = newinet->saddr = newinet->rcv_saddr = LOOPBACK4_IPV6; 645 newinet->inet_daddr = newinet->inet_saddr = LOOPBACK4_IPV6;
646 newinet->inet_rcv_saddr = LOOPBACK4_IPV6;
646 647
647 __inet6_hash(newsk); 648 __inet6_hash(newsk, NULL);
648 __inet_inherit_port(sk, newsk); 649 __inet_inherit_port(sk, newsk);
649 650
650 return newsk; 651 return newsk;
@@ -970,12 +971,9 @@ static int dccp_v6_connect(struct sock *sk, struct sockaddr *uaddr,
970 icsk->icsk_af_ops = &dccp_ipv6_af_ops; 971 icsk->icsk_af_ops = &dccp_ipv6_af_ops;
971 sk->sk_backlog_rcv = dccp_v6_do_rcv; 972 sk->sk_backlog_rcv = dccp_v6_do_rcv;
972 goto failure; 973 goto failure;
973 } else {
974 ipv6_addr_set(&np->saddr, 0, 0, htonl(0x0000FFFF),
975 inet->saddr);
976 ipv6_addr_set(&np->rcv_saddr, 0, 0, htonl(0x0000FFFF),
977 inet->rcv_saddr);
978 } 974 }
975 ipv6_addr_set_v4mapped(inet->inet_saddr, &np->saddr);
976 ipv6_addr_set_v4mapped(inet->inet_rcv_saddr, &np->rcv_saddr);
979 977
980 return err; 978 return err;
981 } 979 }
@@ -988,7 +986,7 @@ static int dccp_v6_connect(struct sock *sk, struct sockaddr *uaddr,
988 ipv6_addr_copy(&fl.fl6_src, saddr ? saddr : &np->saddr); 986 ipv6_addr_copy(&fl.fl6_src, saddr ? saddr : &np->saddr);
989 fl.oif = sk->sk_bound_dev_if; 987 fl.oif = sk->sk_bound_dev_if;
990 fl.fl_ip_dport = usin->sin6_port; 988 fl.fl_ip_dport = usin->sin6_port;
991 fl.fl_ip_sport = inet->sport; 989 fl.fl_ip_sport = inet->inet_sport;
992 security_sk_classify_flow(sk, &fl); 990 security_sk_classify_flow(sk, &fl);
993 991
994 if (np->opt != NULL && np->opt->srcrt != NULL) { 992 if (np->opt != NULL && np->opt->srcrt != NULL) {
@@ -1021,7 +1019,7 @@ static int dccp_v6_connect(struct sock *sk, struct sockaddr *uaddr,
1021 1019
1022 /* set the source address */ 1020 /* set the source address */
1023 ipv6_addr_copy(&np->saddr, saddr); 1021 ipv6_addr_copy(&np->saddr, saddr);
1024 inet->rcv_saddr = LOOPBACK4_IPV6; 1022 inet->inet_rcv_saddr = LOOPBACK4_IPV6;
1025 1023
1026 __ip6_dst_store(sk, dst, NULL, NULL); 1024 __ip6_dst_store(sk, dst, NULL, NULL);
1027 1025
@@ -1030,7 +1028,7 @@ static int dccp_v6_connect(struct sock *sk, struct sockaddr *uaddr,
1030 icsk->icsk_ext_hdr_len = (np->opt->opt_flen + 1028 icsk->icsk_ext_hdr_len = (np->opt->opt_flen +
1031 np->opt->opt_nflen); 1029 np->opt->opt_nflen);
1032 1030
1033 inet->dport = usin->sin6_port; 1031 inet->inet_dport = usin->sin6_port;
1034 1032
1035 dccp_set_state(sk, DCCP_REQUESTING); 1033 dccp_set_state(sk, DCCP_REQUESTING);
1036 err = inet6_hash_connect(&dccp_death_row, sk); 1034 err = inet6_hash_connect(&dccp_death_row, sk);
@@ -1039,7 +1037,8 @@ static int dccp_v6_connect(struct sock *sk, struct sockaddr *uaddr,
1039 1037
1040 dp->dccps_iss = secure_dccpv6_sequence_number(np->saddr.s6_addr32, 1038 dp->dccps_iss = secure_dccpv6_sequence_number(np->saddr.s6_addr32,
1041 np->daddr.s6_addr32, 1039 np->daddr.s6_addr32,
1042 inet->sport, inet->dport); 1040 inet->inet_sport,
1041 inet->inet_dport);
1043 err = dccp_connect(sk); 1042 err = dccp_connect(sk);
1044 if (err) 1043 if (err)
1045 goto late_failure; 1044 goto late_failure;
@@ -1050,7 +1049,7 @@ late_failure:
1050 dccp_set_state(sk, DCCP_CLOSED); 1049 dccp_set_state(sk, DCCP_CLOSED);
1051 __sk_dst_reset(sk); 1050 __sk_dst_reset(sk);
1052failure: 1051failure:
1053 inet->dport = 0; 1052 inet->inet_dport = 0;
1054 sk->sk_route_caps = 0; 1053 sk->sk_route_caps = 0;
1055 return err; 1054 return err;
1056} 1055}
@@ -1188,20 +1187,19 @@ static struct inet_protosw dccp_v6_protosw = {
1188 .protocol = IPPROTO_DCCP, 1187 .protocol = IPPROTO_DCCP,
1189 .prot = &dccp_v6_prot, 1188 .prot = &dccp_v6_prot,
1190 .ops = &inet6_dccp_ops, 1189 .ops = &inet6_dccp_ops,
1191 .capability = -1,
1192 .flags = INET_PROTOSW_ICSK, 1190 .flags = INET_PROTOSW_ICSK,
1193}; 1191};
1194 1192
1195static int dccp_v6_init_net(struct net *net) 1193static int __net_init dccp_v6_init_net(struct net *net)
1196{ 1194{
1197 int err; 1195 if (dccp_hashinfo.bhash == NULL)
1196 return -ESOCKTNOSUPPORT;
1198 1197
1199 err = inet_ctl_sock_create(&net->dccp.v6_ctl_sk, PF_INET6, 1198 return inet_ctl_sock_create(&net->dccp.v6_ctl_sk, PF_INET6,
1200 SOCK_DCCP, IPPROTO_DCCP, net); 1199 SOCK_DCCP, IPPROTO_DCCP, net);
1201 return err;
1202} 1200}
1203 1201
1204static void dccp_v6_exit_net(struct net *net) 1202static void __net_exit dccp_v6_exit_net(struct net *net)
1205{ 1203{
1206 inet_ctl_sock_destroy(net->dccp.v6_ctl_sk); 1204 inet_ctl_sock_destroy(net->dccp.v6_ctl_sk);
1207} 1205}
diff --git a/net/dccp/minisocks.c b/net/dccp/minisocks.c
index 5ca49cec95f5..128b089d3aef 100644
--- a/net/dccp/minisocks.c
+++ b/net/dccp/minisocks.c
@@ -11,6 +11,7 @@
11 */ 11 */
12 12
13#include <linux/dccp.h> 13#include <linux/dccp.h>
14#include <linux/gfp.h>
14#include <linux/kernel.h> 15#include <linux/kernel.h>
15#include <linux/skbuff.h> 16#include <linux/skbuff.h>
16#include <linux/timer.h> 17#include <linux/timer.h>
@@ -184,7 +185,7 @@ struct sock *dccp_check_req(struct sock *sk, struct sk_buff *skb,
184 * counter (backoff, monitored by dccp_response_timer). 185 * counter (backoff, monitored by dccp_response_timer).
185 */ 186 */
186 req->retrans++; 187 req->retrans++;
187 req->rsk_ops->rtx_syn_ack(sk, req); 188 req->rsk_ops->rtx_syn_ack(sk, req, NULL);
188 } 189 }
189 /* Network Duplicate, discard packet */ 190 /* Network Duplicate, discard packet */
190 return NULL; 191 return NULL;
@@ -254,7 +255,7 @@ int dccp_child_process(struct sock *parent, struct sock *child,
254 * in main socket hash table and lock on listening 255 * in main socket hash table and lock on listening
255 * socket does not protect us more. 256 * socket does not protect us more.
256 */ 257 */
257 sk_add_backlog(child, skb); 258 __sk_add_backlog(child, skb);
258 } 259 }
259 260
260 bh_unlock_sock(child); 261 bh_unlock_sock(child);
diff --git a/net/dccp/output.c b/net/dccp/output.c
index c96119fda688..fc3f436440b4 100644
--- a/net/dccp/output.c
+++ b/net/dccp/output.c
@@ -13,6 +13,7 @@
13#include <linux/dccp.h> 13#include <linux/dccp.h>
14#include <linux/kernel.h> 14#include <linux/kernel.h>
15#include <linux/skbuff.h> 15#include <linux/skbuff.h>
16#include <linux/slab.h>
16 17
17#include <net/inet_sock.h> 18#include <net/inet_sock.h>
18#include <net/sock.h> 19#include <net/sock.h>
@@ -99,8 +100,8 @@ static int dccp_transmit_skb(struct sock *sk, struct sk_buff *skb)
99 /* Build DCCP header and checksum it. */ 100 /* Build DCCP header and checksum it. */
100 dh = dccp_zeroed_hdr(skb, dccp_header_size); 101 dh = dccp_zeroed_hdr(skb, dccp_header_size);
101 dh->dccph_type = dcb->dccpd_type; 102 dh->dccph_type = dcb->dccpd_type;
102 dh->dccph_sport = inet->sport; 103 dh->dccph_sport = inet->inet_sport;
103 dh->dccph_dport = inet->dport; 104 dh->dccph_dport = inet->inet_dport;
104 dh->dccph_doff = (dccp_header_size + dcb->dccpd_opt_len) / 4; 105 dh->dccph_doff = (dccp_header_size + dcb->dccpd_opt_len) / 4;
105 dh->dccph_ccval = dcb->dccpd_ccval; 106 dh->dccph_ccval = dcb->dccpd_ccval;
106 dh->dccph_cscov = dp->dccps_pcslen; 107 dh->dccph_cscov = dp->dccps_pcslen;
diff --git a/net/dccp/probe.c b/net/dccp/probe.c
index 37731da41481..078e48d442fd 100644
--- a/net/dccp/probe.c
+++ b/net/dccp/probe.c
@@ -30,6 +30,7 @@
30#include <linux/module.h> 30#include <linux/module.h>
31#include <linux/kfifo.h> 31#include <linux/kfifo.h>
32#include <linux/vmalloc.h> 32#include <linux/vmalloc.h>
33#include <linux/gfp.h>
33#include <net/net_namespace.h> 34#include <net/net_namespace.h>
34 35
35#include "dccp.h" 36#include "dccp.h"
@@ -43,7 +44,7 @@ static int bufsize = 64 * 1024;
43static const char procname[] = "dccpprobe"; 44static const char procname[] = "dccpprobe";
44 45
45static struct { 46static struct {
46 struct kfifo *fifo; 47 struct kfifo fifo;
47 spinlock_t lock; 48 spinlock_t lock;
48 wait_queue_head_t wait; 49 wait_queue_head_t wait;
49 struct timespec tstart; 50 struct timespec tstart;
@@ -67,7 +68,7 @@ static void printl(const char *fmt, ...)
67 len += vscnprintf(tbuf+len, sizeof(tbuf)-len, fmt, args); 68 len += vscnprintf(tbuf+len, sizeof(tbuf)-len, fmt, args);
68 va_end(args); 69 va_end(args);
69 70
70 kfifo_put(dccpw.fifo, tbuf, len); 71 kfifo_in_locked(&dccpw.fifo, tbuf, len, &dccpw.lock);
71 wake_up(&dccpw.wait); 72 wake_up(&dccpw.wait);
72} 73}
73 74
@@ -75,26 +76,25 @@ static int jdccp_sendmsg(struct kiocb *iocb, struct sock *sk,
75 struct msghdr *msg, size_t size) 76 struct msghdr *msg, size_t size)
76{ 77{
77 const struct inet_sock *inet = inet_sk(sk); 78 const struct inet_sock *inet = inet_sk(sk);
78 struct ccid3_hc_tx_sock *hctx = NULL; 79 struct ccid3_hc_tx_sock *hc = NULL;
79 80
80 if (ccid_get_current_tx_ccid(dccp_sk(sk)) == DCCPC_CCID3) 81 if (ccid_get_current_tx_ccid(dccp_sk(sk)) == DCCPC_CCID3)
81 hctx = ccid3_hc_tx_sk(sk); 82 hc = ccid3_hc_tx_sk(sk);
82 83
83 if (port == 0 || ntohs(inet->dport) == port || 84 if (port == 0 || ntohs(inet->inet_dport) == port ||
84 ntohs(inet->sport) == port) { 85 ntohs(inet->inet_sport) == port) {
85 if (hctx) 86 if (hc)
86 printl("%pI4:%u %pI4:%u %d %d %d %d %u " 87 printl("%pI4:%u %pI4:%u %d %d %d %d %u %llu %llu %d\n",
87 "%llu %llu %d\n", 88 &inet->inet_saddr, ntohs(inet->inet_sport),
88 &inet->saddr, ntohs(inet->sport), 89 &inet->inet_daddr, ntohs(inet->inet_dport), size,
89 &inet->daddr, ntohs(inet->dport), size, 90 hc->tx_s, hc->tx_rtt, hc->tx_p,
90 hctx->ccid3hctx_s, hctx->ccid3hctx_rtt, 91 hc->tx_x_calc, hc->tx_x_recv >> 6,
91 hctx->ccid3hctx_p, hctx->ccid3hctx_x_calc, 92 hc->tx_x >> 6, hc->tx_t_ipi);
92 hctx->ccid3hctx_x_recv >> 6,
93 hctx->ccid3hctx_x >> 6, hctx->ccid3hctx_t_ipi);
94 else 93 else
95 printl("%pI4:%u %pI4:%u %d\n", 94 printl("%pI4:%u %pI4:%u %d\n",
96 &inet->saddr, ntohs(inet->sport), 95 &inet->inet_saddr, ntohs(inet->inet_sport),
97 &inet->daddr, ntohs(inet->dport), size); 96 &inet->inet_daddr, ntohs(inet->inet_dport),
97 size);
98 } 98 }
99 99
100 jprobe_return(); 100 jprobe_return();
@@ -110,7 +110,7 @@ static struct jprobe dccp_send_probe = {
110 110
111static int dccpprobe_open(struct inode *inode, struct file *file) 111static int dccpprobe_open(struct inode *inode, struct file *file)
112{ 112{
113 kfifo_reset(dccpw.fifo); 113 kfifo_reset(&dccpw.fifo);
114 getnstimeofday(&dccpw.tstart); 114 getnstimeofday(&dccpw.tstart);
115 return 0; 115 return 0;
116} 116}
@@ -132,11 +132,11 @@ static ssize_t dccpprobe_read(struct file *file, char __user *buf,
132 return -ENOMEM; 132 return -ENOMEM;
133 133
134 error = wait_event_interruptible(dccpw.wait, 134 error = wait_event_interruptible(dccpw.wait,
135 __kfifo_len(dccpw.fifo) != 0); 135 kfifo_len(&dccpw.fifo) != 0);
136 if (error) 136 if (error)
137 goto out_free; 137 goto out_free;
138 138
139 cnt = kfifo_get(dccpw.fifo, tbuf, len); 139 cnt = kfifo_out_locked(&dccpw.fifo, tbuf, len, &dccpw.lock);
140 error = copy_to_user(buf, tbuf, cnt) ? -EFAULT : 0; 140 error = copy_to_user(buf, tbuf, cnt) ? -EFAULT : 0;
141 141
142out_free: 142out_free:
@@ -157,14 +157,13 @@ static __init int dccpprobe_init(void)
157 157
158 init_waitqueue_head(&dccpw.wait); 158 init_waitqueue_head(&dccpw.wait);
159 spin_lock_init(&dccpw.lock); 159 spin_lock_init(&dccpw.lock);
160 dccpw.fifo = kfifo_alloc(bufsize, GFP_KERNEL, &dccpw.lock); 160 if (kfifo_alloc(&dccpw.fifo, bufsize, GFP_KERNEL))
161 if (IS_ERR(dccpw.fifo)) 161 return ret;
162 return PTR_ERR(dccpw.fifo);
163
164 if (!proc_net_fops_create(&init_net, procname, S_IRUSR, &dccpprobe_fops)) 162 if (!proc_net_fops_create(&init_net, procname, S_IRUSR, &dccpprobe_fops))
165 goto err0; 163 goto err0;
166 164
167 ret = register_jprobe(&dccp_send_probe); 165 try_then_request_module((ret = register_jprobe(&dccp_send_probe)) == 0,
166 "dccp");
168 if (ret) 167 if (ret)
169 goto err1; 168 goto err1;
170 169
@@ -173,14 +172,14 @@ static __init int dccpprobe_init(void)
173err1: 172err1:
174 proc_net_remove(&init_net, procname); 173 proc_net_remove(&init_net, procname);
175err0: 174err0:
176 kfifo_free(dccpw.fifo); 175 kfifo_free(&dccpw.fifo);
177 return ret; 176 return ret;
178} 177}
179module_init(dccpprobe_init); 178module_init(dccpprobe_init);
180 179
181static __exit void dccpprobe_exit(void) 180static __exit void dccpprobe_exit(void)
182{ 181{
183 kfifo_free(dccpw.fifo); 182 kfifo_free(&dccpw.fifo);
184 proc_net_remove(&init_net, procname); 183 proc_net_remove(&init_net, procname);
185 unregister_jprobe(&dccp_send_probe); 184 unregister_jprobe(&dccp_send_probe);
186 185
diff --git a/net/dccp/proto.c b/net/dccp/proto.c
index a156319fd0ac..a0e38d8018f5 100644
--- a/net/dccp/proto.c
+++ b/net/dccp/proto.c
@@ -20,6 +20,7 @@
20#include <linux/if_arp.h> 20#include <linux/if_arp.h>
21#include <linux/init.h> 21#include <linux/init.h>
22#include <linux/random.h> 22#include <linux/random.h>
23#include <linux/slab.h>
23#include <net/checksum.h> 24#include <net/checksum.h>
24 25
25#include <net/inet_sock.h> 26#include <net/inet_sock.h>
@@ -278,7 +279,7 @@ int dccp_disconnect(struct sock *sk, int flags)
278 sk->sk_send_head = NULL; 279 sk->sk_send_head = NULL;
279 } 280 }
280 281
281 inet->dport = 0; 282 inet->inet_dport = 0;
282 283
283 if (!(sk->sk_userlocks & SOCK_BINDADDR_LOCK)) 284 if (!(sk->sk_userlocks & SOCK_BINDADDR_LOCK))
284 inet_reset_saddr(sk); 285 inet_reset_saddr(sk);
@@ -290,7 +291,7 @@ int dccp_disconnect(struct sock *sk, int flags)
290 inet_csk_delack_init(sk); 291 inet_csk_delack_init(sk);
291 __sk_dst_reset(sk); 292 __sk_dst_reset(sk);
292 293
293 WARN_ON(inet->num && !icsk->icsk_bind_hash); 294 WARN_ON(inet->inet_num && !icsk->icsk_bind_hash);
294 295
295 sk->sk_error_report(sk); 296 sk->sk_error_report(sk);
296 return err; 297 return err;
@@ -835,6 +836,8 @@ verify_sock_status:
835 len = -EFAULT; 836 len = -EFAULT;
836 break; 837 break;
837 } 838 }
839 if (flags & MSG_TRUNC)
840 len = skb->len;
838 found_fin_ok: 841 found_fin_ok:
839 if (!(flags & MSG_PEEK)) 842 if (!(flags & MSG_PEEK))
840 sk_eat_skb(sk, skb, 0); 843 sk_eat_skb(sk, skb, 0);
@@ -1003,12 +1006,13 @@ EXPORT_SYMBOL_GPL(dccp_shutdown);
1003 1006
1004static inline int dccp_mib_init(void) 1007static inline int dccp_mib_init(void)
1005{ 1008{
1006 return snmp_mib_init((void**)dccp_statistics, sizeof(struct dccp_mib)); 1009 return snmp_mib_init((void __percpu **)dccp_statistics,
1010 sizeof(struct dccp_mib));
1007} 1011}
1008 1012
1009static inline void dccp_mib_exit(void) 1013static inline void dccp_mib_exit(void)
1010{ 1014{
1011 snmp_mib_free((void**)dccp_statistics); 1015 snmp_mib_free((void __percpu **)dccp_statistics);
1012} 1016}
1013 1017
1014static int thash_entries; 1018static int thash_entries;
@@ -1033,7 +1037,7 @@ static int __init dccp_init(void)
1033 FIELD_SIZEOF(struct sk_buff, cb)); 1037 FIELD_SIZEOF(struct sk_buff, cb));
1034 rc = percpu_counter_init(&dccp_orphan_count, 0); 1038 rc = percpu_counter_init(&dccp_orphan_count, 0);
1035 if (rc) 1039 if (rc)
1036 goto out; 1040 goto out_fail;
1037 rc = -ENOBUFS; 1041 rc = -ENOBUFS;
1038 inet_hashinfo_init(&dccp_hashinfo); 1042 inet_hashinfo_init(&dccp_hashinfo);
1039 dccp_hashinfo.bind_bucket_cachep = 1043 dccp_hashinfo.bind_bucket_cachep =
@@ -1060,11 +1064,12 @@ static int __init dccp_init(void)
1060 for (ehash_order = 0; (1UL << ehash_order) < goal; ehash_order++) 1064 for (ehash_order = 0; (1UL << ehash_order) < goal; ehash_order++)
1061 ; 1065 ;
1062 do { 1066 do {
1063 dccp_hashinfo.ehash_size = (1UL << ehash_order) * PAGE_SIZE / 1067 unsigned long hash_size = (1UL << ehash_order) * PAGE_SIZE /
1064 sizeof(struct inet_ehash_bucket); 1068 sizeof(struct inet_ehash_bucket);
1065 while (dccp_hashinfo.ehash_size & 1069
1066 (dccp_hashinfo.ehash_size - 1)) 1070 while (hash_size & (hash_size - 1))
1067 dccp_hashinfo.ehash_size--; 1071 hash_size--;
1072 dccp_hashinfo.ehash_mask = hash_size - 1;
1068 dccp_hashinfo.ehash = (struct inet_ehash_bucket *) 1073 dccp_hashinfo.ehash = (struct inet_ehash_bucket *)
1069 __get_free_pages(GFP_ATOMIC|__GFP_NOWARN, ehash_order); 1074 __get_free_pages(GFP_ATOMIC|__GFP_NOWARN, ehash_order);
1070 } while (!dccp_hashinfo.ehash && --ehash_order > 0); 1075 } while (!dccp_hashinfo.ehash && --ehash_order > 0);
@@ -1074,7 +1079,7 @@ static int __init dccp_init(void)
1074 goto out_free_bind_bucket_cachep; 1079 goto out_free_bind_bucket_cachep;
1075 } 1080 }
1076 1081
1077 for (i = 0; i < dccp_hashinfo.ehash_size; i++) { 1082 for (i = 0; i <= dccp_hashinfo.ehash_mask; i++) {
1078 INIT_HLIST_NULLS_HEAD(&dccp_hashinfo.ehash[i].chain, i); 1083 INIT_HLIST_NULLS_HEAD(&dccp_hashinfo.ehash[i].chain, i);
1079 INIT_HLIST_NULLS_HEAD(&dccp_hashinfo.ehash[i].twchain, i); 1084 INIT_HLIST_NULLS_HEAD(&dccp_hashinfo.ehash[i].twchain, i);
1080 } 1085 }
@@ -1121,8 +1126,9 @@ static int __init dccp_init(void)
1121 goto out_sysctl_exit; 1126 goto out_sysctl_exit;
1122 1127
1123 dccp_timestamping_init(); 1128 dccp_timestamping_init();
1124out: 1129
1125 return rc; 1130 return 0;
1131
1126out_sysctl_exit: 1132out_sysctl_exit:
1127 dccp_sysctl_exit(); 1133 dccp_sysctl_exit();
1128out_ackvec_exit: 1134out_ackvec_exit:
@@ -1131,18 +1137,19 @@ out_free_dccp_mib:
1131 dccp_mib_exit(); 1137 dccp_mib_exit();
1132out_free_dccp_bhash: 1138out_free_dccp_bhash:
1133 free_pages((unsigned long)dccp_hashinfo.bhash, bhash_order); 1139 free_pages((unsigned long)dccp_hashinfo.bhash, bhash_order);
1134 dccp_hashinfo.bhash = NULL;
1135out_free_dccp_locks: 1140out_free_dccp_locks:
1136 inet_ehash_locks_free(&dccp_hashinfo); 1141 inet_ehash_locks_free(&dccp_hashinfo);
1137out_free_dccp_ehash: 1142out_free_dccp_ehash:
1138 free_pages((unsigned long)dccp_hashinfo.ehash, ehash_order); 1143 free_pages((unsigned long)dccp_hashinfo.ehash, ehash_order);
1139 dccp_hashinfo.ehash = NULL;
1140out_free_bind_bucket_cachep: 1144out_free_bind_bucket_cachep:
1141 kmem_cache_destroy(dccp_hashinfo.bind_bucket_cachep); 1145 kmem_cache_destroy(dccp_hashinfo.bind_bucket_cachep);
1142 dccp_hashinfo.bind_bucket_cachep = NULL;
1143out_free_percpu: 1146out_free_percpu:
1144 percpu_counter_destroy(&dccp_orphan_count); 1147 percpu_counter_destroy(&dccp_orphan_count);
1145 goto out; 1148out_fail:
1149 dccp_hashinfo.bhash = NULL;
1150 dccp_hashinfo.ehash = NULL;
1151 dccp_hashinfo.bind_bucket_cachep = NULL;
1152 return rc;
1146} 1153}
1147 1154
1148static void __exit dccp_fini(void) 1155static void __exit dccp_fini(void)
@@ -1153,7 +1160,7 @@ static void __exit dccp_fini(void)
1153 get_order(dccp_hashinfo.bhash_size * 1160 get_order(dccp_hashinfo.bhash_size *
1154 sizeof(struct inet_bind_hashbucket))); 1161 sizeof(struct inet_bind_hashbucket)));
1155 free_pages((unsigned long)dccp_hashinfo.ehash, 1162 free_pages((unsigned long)dccp_hashinfo.ehash,
1156 get_order(dccp_hashinfo.ehash_size * 1163 get_order((dccp_hashinfo.ehash_mask + 1) *
1157 sizeof(struct inet_ehash_bucket))); 1164 sizeof(struct inet_ehash_bucket)));
1158 inet_ehash_locks_free(&dccp_hashinfo); 1165 inet_ehash_locks_free(&dccp_hashinfo);
1159 kmem_cache_destroy(dccp_hashinfo.bind_bucket_cachep); 1166 kmem_cache_destroy(dccp_hashinfo.bind_bucket_cachep);
diff --git a/net/dccp/sysctl.c b/net/dccp/sysctl.c
index a5a1856234e7..563943822e58 100644
--- a/net/dccp/sysctl.c
+++ b/net/dccp/sysctl.c
@@ -93,13 +93,13 @@ static struct ctl_table dccp_default_table[] = {
93 .proc_handler = proc_dointvec_ms_jiffies, 93 .proc_handler = proc_dointvec_ms_jiffies,
94 }, 94 },
95 95
96 { .ctl_name = 0, } 96 { }
97}; 97};
98 98
99static struct ctl_path dccp_path[] = { 99static struct ctl_path dccp_path[] = {
100 { .procname = "net", .ctl_name = CTL_NET, }, 100 { .procname = "net", },
101 { .procname = "dccp", .ctl_name = NET_DCCP, }, 101 { .procname = "dccp", },
102 { .procname = "default", .ctl_name = NET_DCCP_DEFAULT, }, 102 { .procname = "default", },
103 { } 103 { }
104}; 104};
105 105
diff --git a/net/dccp/timer.c b/net/dccp/timer.c
index 162d1e683c39..bbfeb5eae46a 100644
--- a/net/dccp/timer.c
+++ b/net/dccp/timer.c
@@ -38,7 +38,7 @@ static int dccp_write_timeout(struct sock *sk)
38 38
39 if (sk->sk_state == DCCP_REQUESTING || sk->sk_state == DCCP_PARTOPEN) { 39 if (sk->sk_state == DCCP_REQUESTING || sk->sk_state == DCCP_PARTOPEN) {
40 if (icsk->icsk_retransmits != 0) 40 if (icsk->icsk_retransmits != 0)
41 dst_negative_advice(&sk->sk_dst_cache); 41 dst_negative_advice(&sk->sk_dst_cache, sk);
42 retry_until = icsk->icsk_syn_retries ? 42 retry_until = icsk->icsk_syn_retries ?
43 : sysctl_dccp_request_retries; 43 : sysctl_dccp_request_retries;
44 } else { 44 } else {
@@ -63,7 +63,7 @@ static int dccp_write_timeout(struct sock *sk)
63 Golden words :-). 63 Golden words :-).
64 */ 64 */
65 65
66 dst_negative_advice(&sk->sk_dst_cache); 66 dst_negative_advice(&sk->sk_dst_cache, sk);
67 } 67 }
68 68
69 retry_until = sysctl_dccp_retries2; 69 retry_until = sysctl_dccp_retries2;
diff --git a/net/decnet/af_decnet.c b/net/decnet/af_decnet.c
index 7a58c87baf17..2b494fac9468 100644
--- a/net/decnet/af_decnet.c
+++ b/net/decnet/af_decnet.c
@@ -675,11 +675,12 @@ char *dn_addr2asc(__u16 addr, char *buf)
675 675
676 676
677 677
678static int dn_create(struct net *net, struct socket *sock, int protocol) 678static int dn_create(struct net *net, struct socket *sock, int protocol,
679 int kern)
679{ 680{
680 struct sock *sk; 681 struct sock *sk;
681 682
682 if (net != &init_net) 683 if (!net_eq(net, &init_net))
683 return -EAFNOSUPPORT; 684 return -EAFNOSUPPORT;
684 685
685 switch(sock->type) { 686 switch(sock->type) {
@@ -749,9 +750,9 @@ static int dn_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
749 750
750 if (!(saddr->sdn_flags & SDF_WILD)) { 751 if (!(saddr->sdn_flags & SDF_WILD)) {
751 if (le16_to_cpu(saddr->sdn_nodeaddrl)) { 752 if (le16_to_cpu(saddr->sdn_nodeaddrl)) {
752 read_lock(&dev_base_lock); 753 rcu_read_lock();
753 ldev = NULL; 754 ldev = NULL;
754 for_each_netdev(&init_net, dev) { 755 for_each_netdev_rcu(&init_net, dev) {
755 if (!dev->dn_ptr) 756 if (!dev->dn_ptr)
756 continue; 757 continue;
757 if (dn_dev_islocal(dev, dn_saddr2dn(saddr))) { 758 if (dn_dev_islocal(dev, dn_saddr2dn(saddr))) {
@@ -759,7 +760,7 @@ static int dn_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
759 break; 760 break;
760 } 761 }
761 } 762 }
762 read_unlock(&dev_base_lock); 763 rcu_read_unlock();
763 if (ldev == NULL) 764 if (ldev == NULL)
764 return -EADDRNOTAVAIL; 765 return -EADDRNOTAVAIL;
765 } 766 }
@@ -1955,7 +1956,7 @@ static int dn_sendmsg(struct kiocb *iocb, struct socket *sock,
1955 } 1956 }
1956 1957
1957 if ((flags & MSG_TRYHARD) && sk->sk_dst_cache) 1958 if ((flags & MSG_TRYHARD) && sk->sk_dst_cache)
1958 dst_negative_advice(&sk->sk_dst_cache); 1959 dst_negative_advice(&sk->sk_dst_cache, sk);
1959 1960
1960 mss = scp->segsize_rem; 1961 mss = scp->segsize_rem;
1961 fctype = scp->services_rem & NSP_FC_MASK; 1962 fctype = scp->services_rem & NSP_FC_MASK;
@@ -2325,7 +2326,7 @@ static const struct file_operations dn_socket_seq_fops = {
2325}; 2326};
2326#endif 2327#endif
2327 2328
2328static struct net_proto_family dn_family_ops = { 2329static const struct net_proto_family dn_family_ops = {
2329 .family = AF_DECnet, 2330 .family = AF_DECnet,
2330 .create = dn_create, 2331 .create = dn_create,
2331 .owner = THIS_MODULE, 2332 .owner = THIS_MODULE,
diff --git a/net/decnet/dn_dev.c b/net/decnet/dn_dev.c
index 6e1f085db06a..cead68eb254c 100644
--- a/net/decnet/dn_dev.c
+++ b/net/decnet/dn_dev.c
@@ -40,6 +40,7 @@
40#include <linux/skbuff.h> 40#include <linux/skbuff.h>
41#include <linux/sysctl.h> 41#include <linux/sysctl.h>
42#include <linux/notifier.h> 42#include <linux/notifier.h>
43#include <linux/slab.h>
43#include <asm/uaccess.h> 44#include <asm/uaccess.h>
44#include <asm/system.h> 45#include <asm/system.h>
45#include <net/net_namespace.h> 46#include <net/net_namespace.h>
@@ -68,7 +69,7 @@ extern struct neigh_table dn_neigh_table;
68 */ 69 */
69__le16 decnet_address = 0; 70__le16 decnet_address = 0;
70 71
71static DEFINE_RWLOCK(dndev_lock); 72static DEFINE_SPINLOCK(dndev_lock);
72static struct net_device *decnet_default_device; 73static struct net_device *decnet_default_device;
73static BLOCKING_NOTIFIER_HEAD(dnaddr_chain); 74static BLOCKING_NOTIFIER_HEAD(dnaddr_chain);
74 75
@@ -89,7 +90,6 @@ static struct dn_dev_parms dn_dev_list[] = {
89 .t2 = 1, 90 .t2 = 1,
90 .t3 = 10, 91 .t3 = 10,
91 .name = "ethernet", 92 .name = "ethernet",
92 .ctl_name = NET_DECNET_CONF_ETHER,
93 .up = dn_eth_up, 93 .up = dn_eth_up,
94 .down = dn_eth_down, 94 .down = dn_eth_down,
95 .timer3 = dn_send_brd_hello, 95 .timer3 = dn_send_brd_hello,
@@ -101,7 +101,6 @@ static struct dn_dev_parms dn_dev_list[] = {
101 .t2 = 1, 101 .t2 = 1,
102 .t3 = 10, 102 .t3 = 10,
103 .name = "ipgre", 103 .name = "ipgre",
104 .ctl_name = NET_DECNET_CONF_GRE,
105 .timer3 = dn_send_brd_hello, 104 .timer3 = dn_send_brd_hello,
106}, 105},
107#if 0 106#if 0
@@ -112,7 +111,6 @@ static struct dn_dev_parms dn_dev_list[] = {
112 .t2 = 1, 111 .t2 = 1,
113 .t3 = 120, 112 .t3 = 120,
114 .name = "x25", 113 .name = "x25",
115 .ctl_name = NET_DECNET_CONF_X25,
116 .timer3 = dn_send_ptp_hello, 114 .timer3 = dn_send_ptp_hello,
117}, 115},
118#endif 116#endif
@@ -124,7 +122,6 @@ static struct dn_dev_parms dn_dev_list[] = {
124 .t2 = 1, 122 .t2 = 1,
125 .t3 = 10, 123 .t3 = 10,
126 .name = "ppp", 124 .name = "ppp",
127 .ctl_name = NET_DECNET_CONF_PPP,
128 .timer3 = dn_send_brd_hello, 125 .timer3 = dn_send_brd_hello,
129}, 126},
130#endif 127#endif
@@ -135,7 +132,6 @@ static struct dn_dev_parms dn_dev_list[] = {
135 .t2 = 1, 132 .t2 = 1,
136 .t3 = 120, 133 .t3 = 120,
137 .name = "ddcmp", 134 .name = "ddcmp",
138 .ctl_name = NET_DECNET_CONF_DDCMP,
139 .timer3 = dn_send_ptp_hello, 135 .timer3 = dn_send_ptp_hello,
140}, 136},
141{ 137{
@@ -145,7 +141,6 @@ static struct dn_dev_parms dn_dev_list[] = {
145 .t2 = 1, 141 .t2 = 1,
146 .t3 = 10, 142 .t3 = 10,
147 .name = "loopback", 143 .name = "loopback",
148 .ctl_name = NET_DECNET_CONF_LOOPBACK,
149 .timer3 = dn_send_brd_hello, 144 .timer3 = dn_send_brd_hello,
150} 145}
151}; 146};
@@ -166,10 +161,6 @@ static int max_priority[] = { 127 }; /* From DECnet spec */
166 161
167static int dn_forwarding_proc(ctl_table *, int, 162static int dn_forwarding_proc(ctl_table *, int,
168 void __user *, size_t *, loff_t *); 163 void __user *, size_t *, loff_t *);
169static int dn_forwarding_sysctl(ctl_table *table,
170 void __user *oldval, size_t __user *oldlenp,
171 void __user *newval, size_t newlen);
172
173static struct dn_dev_sysctl_table { 164static struct dn_dev_sysctl_table {
174 struct ctl_table_header *sysctl_header; 165 struct ctl_table_header *sysctl_header;
175 ctl_table dn_dev_vars[5]; 166 ctl_table dn_dev_vars[5];
@@ -177,44 +168,36 @@ static struct dn_dev_sysctl_table {
177 NULL, 168 NULL,
178 { 169 {
179 { 170 {
180 .ctl_name = NET_DECNET_CONF_DEV_FORWARDING,
181 .procname = "forwarding", 171 .procname = "forwarding",
182 .data = (void *)DN_DEV_PARMS_OFFSET(forwarding), 172 .data = (void *)DN_DEV_PARMS_OFFSET(forwarding),
183 .maxlen = sizeof(int), 173 .maxlen = sizeof(int),
184 .mode = 0644, 174 .mode = 0644,
185 .proc_handler = dn_forwarding_proc, 175 .proc_handler = dn_forwarding_proc,
186 .strategy = dn_forwarding_sysctl,
187 }, 176 },
188 { 177 {
189 .ctl_name = NET_DECNET_CONF_DEV_PRIORITY,
190 .procname = "priority", 178 .procname = "priority",
191 .data = (void *)DN_DEV_PARMS_OFFSET(priority), 179 .data = (void *)DN_DEV_PARMS_OFFSET(priority),
192 .maxlen = sizeof(int), 180 .maxlen = sizeof(int),
193 .mode = 0644, 181 .mode = 0644,
194 .proc_handler = proc_dointvec_minmax, 182 .proc_handler = proc_dointvec_minmax,
195 .strategy = sysctl_intvec,
196 .extra1 = &min_priority, 183 .extra1 = &min_priority,
197 .extra2 = &max_priority 184 .extra2 = &max_priority
198 }, 185 },
199 { 186 {
200 .ctl_name = NET_DECNET_CONF_DEV_T2,
201 .procname = "t2", 187 .procname = "t2",
202 .data = (void *)DN_DEV_PARMS_OFFSET(t2), 188 .data = (void *)DN_DEV_PARMS_OFFSET(t2),
203 .maxlen = sizeof(int), 189 .maxlen = sizeof(int),
204 .mode = 0644, 190 .mode = 0644,
205 .proc_handler = proc_dointvec_minmax, 191 .proc_handler = proc_dointvec_minmax,
206 .strategy = sysctl_intvec,
207 .extra1 = &min_t2, 192 .extra1 = &min_t2,
208 .extra2 = &max_t2 193 .extra2 = &max_t2
209 }, 194 },
210 { 195 {
211 .ctl_name = NET_DECNET_CONF_DEV_T3,
212 .procname = "t3", 196 .procname = "t3",
213 .data = (void *)DN_DEV_PARMS_OFFSET(t3), 197 .data = (void *)DN_DEV_PARMS_OFFSET(t3),
214 .maxlen = sizeof(int), 198 .maxlen = sizeof(int),
215 .mode = 0644, 199 .mode = 0644,
216 .proc_handler = proc_dointvec_minmax, 200 .proc_handler = proc_dointvec_minmax,
217 .strategy = sysctl_intvec,
218 .extra1 = &min_t3, 201 .extra1 = &min_t3,
219 .extra2 = &max_t3 202 .extra2 = &max_t3
220 }, 203 },
@@ -230,9 +213,9 @@ static void dn_dev_sysctl_register(struct net_device *dev, struct dn_dev_parms *
230#define DN_CTL_PATH_DEV 3 213#define DN_CTL_PATH_DEV 3
231 214
232 struct ctl_path dn_ctl_path[] = { 215 struct ctl_path dn_ctl_path[] = {
233 { .procname = "net", .ctl_name = CTL_NET, }, 216 { .procname = "net", },
234 { .procname = "decnet", .ctl_name = NET_DECNET, }, 217 { .procname = "decnet", },
235 { .procname = "conf", .ctl_name = NET_DECNET_CONF, }, 218 { .procname = "conf", },
236 { /* to be set */ }, 219 { /* to be set */ },
237 { }, 220 { },
238 }; 221 };
@@ -248,10 +231,8 @@ static void dn_dev_sysctl_register(struct net_device *dev, struct dn_dev_parms *
248 231
249 if (dev) { 232 if (dev) {
250 dn_ctl_path[DN_CTL_PATH_DEV].procname = dev->name; 233 dn_ctl_path[DN_CTL_PATH_DEV].procname = dev->name;
251 dn_ctl_path[DN_CTL_PATH_DEV].ctl_name = dev->ifindex;
252 } else { 234 } else {
253 dn_ctl_path[DN_CTL_PATH_DEV].procname = parms->name; 235 dn_ctl_path[DN_CTL_PATH_DEV].procname = parms->name;
254 dn_ctl_path[DN_CTL_PATH_DEV].ctl_name = parms->ctl_name;
255 } 236 }
256 237
257 t->dn_dev_vars[0].extra1 = (void *)dev; 238 t->dn_dev_vars[0].extra1 = (void *)dev;
@@ -317,44 +298,6 @@ static int dn_forwarding_proc(ctl_table *table, int write,
317#endif 298#endif
318} 299}
319 300
320static int dn_forwarding_sysctl(ctl_table *table,
321 void __user *oldval, size_t __user *oldlenp,
322 void __user *newval, size_t newlen)
323{
324#ifdef CONFIG_DECNET_ROUTER
325 struct net_device *dev = table->extra1;
326 struct dn_dev *dn_db;
327 int value;
328
329 if (table->extra1 == NULL)
330 return -EINVAL;
331
332 dn_db = dev->dn_ptr;
333
334 if (newval && newlen) {
335 if (newlen != sizeof(int))
336 return -EINVAL;
337
338 if (get_user(value, (int __user *)newval))
339 return -EFAULT;
340 if (value < 0)
341 return -EINVAL;
342 if (value > 2)
343 return -EINVAL;
344
345 if (dn_db->parms.down)
346 dn_db->parms.down(dev);
347 dn_db->parms.forwarding = value;
348 if (dn_db->parms.up)
349 dn_db->parms.up(dev);
350 }
351
352 return 0;
353#else
354 return -EINVAL;
355#endif
356}
357
358#else /* CONFIG_SYSCTL */ 301#else /* CONFIG_SYSCTL */
359static void dn_dev_sysctl_unregister(struct dn_dev_parms *parms) 302static void dn_dev_sysctl_unregister(struct dn_dev_parms *parms)
360{ 303{
@@ -557,7 +500,8 @@ rarok:
557struct net_device *dn_dev_get_default(void) 500struct net_device *dn_dev_get_default(void)
558{ 501{
559 struct net_device *dev; 502 struct net_device *dev;
560 read_lock(&dndev_lock); 503
504 spin_lock(&dndev_lock);
561 dev = decnet_default_device; 505 dev = decnet_default_device;
562 if (dev) { 506 if (dev) {
563 if (dev->dn_ptr) 507 if (dev->dn_ptr)
@@ -565,7 +509,8 @@ struct net_device *dn_dev_get_default(void)
565 else 509 else
566 dev = NULL; 510 dev = NULL;
567 } 511 }
568 read_unlock(&dndev_lock); 512 spin_unlock(&dndev_lock);
513
569 return dev; 514 return dev;
570} 515}
571 516
@@ -575,13 +520,15 @@ int dn_dev_set_default(struct net_device *dev, int force)
575 int rv = -EBUSY; 520 int rv = -EBUSY;
576 if (!dev->dn_ptr) 521 if (!dev->dn_ptr)
577 return -ENODEV; 522 return -ENODEV;
578 write_lock(&dndev_lock); 523
524 spin_lock(&dndev_lock);
579 if (force || decnet_default_device == NULL) { 525 if (force || decnet_default_device == NULL) {
580 old = decnet_default_device; 526 old = decnet_default_device;
581 decnet_default_device = dev; 527 decnet_default_device = dev;
582 rv = 0; 528 rv = 0;
583 } 529 }
584 write_unlock(&dndev_lock); 530 spin_unlock(&dndev_lock);
531
585 if (old) 532 if (old)
586 dev_put(old); 533 dev_put(old);
587 return rv; 534 return rv;
@@ -589,26 +536,29 @@ int dn_dev_set_default(struct net_device *dev, int force)
589 536
590static void dn_dev_check_default(struct net_device *dev) 537static void dn_dev_check_default(struct net_device *dev)
591{ 538{
592 write_lock(&dndev_lock); 539 spin_lock(&dndev_lock);
593 if (dev == decnet_default_device) { 540 if (dev == decnet_default_device) {
594 decnet_default_device = NULL; 541 decnet_default_device = NULL;
595 } else { 542 } else {
596 dev = NULL; 543 dev = NULL;
597 } 544 }
598 write_unlock(&dndev_lock); 545 spin_unlock(&dndev_lock);
546
599 if (dev) 547 if (dev)
600 dev_put(dev); 548 dev_put(dev);
601} 549}
602 550
551/*
552 * Called with RTNL
553 */
603static struct dn_dev *dn_dev_by_index(int ifindex) 554static struct dn_dev *dn_dev_by_index(int ifindex)
604{ 555{
605 struct net_device *dev; 556 struct net_device *dev;
606 struct dn_dev *dn_dev = NULL; 557 struct dn_dev *dn_dev = NULL;
607 dev = dev_get_by_index(&init_net, ifindex); 558
608 if (dev) { 559 dev = __dev_get_by_index(&init_net, ifindex);
560 if (dev)
609 dn_dev = dev->dn_ptr; 561 dn_dev = dev->dn_ptr;
610 dev_put(dev);
611 }
612 562
613 return dn_dev; 563 return dn_dev;
614} 564}
@@ -629,7 +579,7 @@ static int dn_nl_deladdr(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
629 struct dn_ifaddr *ifa, **ifap; 579 struct dn_ifaddr *ifa, **ifap;
630 int err = -EINVAL; 580 int err = -EINVAL;
631 581
632 if (net != &init_net) 582 if (!net_eq(net, &init_net))
633 goto errout; 583 goto errout;
634 584
635 err = nlmsg_parse(nlh, sizeof(*ifm), tb, IFA_MAX, dn_ifa_policy); 585 err = nlmsg_parse(nlh, sizeof(*ifm), tb, IFA_MAX, dn_ifa_policy);
@@ -668,7 +618,7 @@ static int dn_nl_newaddr(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
668 struct dn_ifaddr *ifa; 618 struct dn_ifaddr *ifa;
669 int err; 619 int err;
670 620
671 if (net != &init_net) 621 if (!net_eq(net, &init_net))
672 return -EINVAL; 622 return -EINVAL;
673 623
674 err = nlmsg_parse(nlh, sizeof(*ifm), tb, IFA_MAX, dn_ifa_policy); 624 err = nlmsg_parse(nlh, sizeof(*ifm), tb, IFA_MAX, dn_ifa_policy);
@@ -782,7 +732,7 @@ static int dn_nl_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
782 struct dn_dev *dn_db; 732 struct dn_dev *dn_db;
783 struct dn_ifaddr *ifa; 733 struct dn_ifaddr *ifa;
784 734
785 if (net != &init_net) 735 if (!net_eq(net, &init_net))
786 return 0; 736 return 0;
787 737
788 skip_ndevs = cb->args[0]; 738 skip_ndevs = cb->args[0];
@@ -826,13 +776,17 @@ static int dn_dev_get_first(struct net_device *dev, __le16 *addr)
826 struct dn_dev *dn_db = (struct dn_dev *)dev->dn_ptr; 776 struct dn_dev *dn_db = (struct dn_dev *)dev->dn_ptr;
827 struct dn_ifaddr *ifa; 777 struct dn_ifaddr *ifa;
828 int rv = -ENODEV; 778 int rv = -ENODEV;
779
829 if (dn_db == NULL) 780 if (dn_db == NULL)
830 goto out; 781 goto out;
782
783 rtnl_lock();
831 ifa = dn_db->ifa_list; 784 ifa = dn_db->ifa_list;
832 if (ifa != NULL) { 785 if (ifa != NULL) {
833 *addr = ifa->ifa_local; 786 *addr = ifa->ifa_local;
834 rv = 0; 787 rv = 0;
835 } 788 }
789 rtnl_unlock();
836out: 790out:
837 return rv; 791 return rv;
838} 792}
@@ -854,9 +808,7 @@ int dn_dev_bind_default(__le16 *addr)
854 dev = dn_dev_get_default(); 808 dev = dn_dev_get_default();
855last_chance: 809last_chance:
856 if (dev) { 810 if (dev) {
857 read_lock(&dev_base_lock);
858 rv = dn_dev_get_first(dev, addr); 811 rv = dn_dev_get_first(dev, addr);
859 read_unlock(&dev_base_lock);
860 dev_put(dev); 812 dev_put(dev);
861 if (rv == 0 || dev == init_net.loopback_dev) 813 if (rv == 0 || dev == init_net.loopback_dev)
862 return rv; 814 return rv;
@@ -1321,18 +1273,18 @@ static inline int is_dn_dev(struct net_device *dev)
1321} 1273}
1322 1274
1323static void *dn_dev_seq_start(struct seq_file *seq, loff_t *pos) 1275static void *dn_dev_seq_start(struct seq_file *seq, loff_t *pos)
1324 __acquires(&dev_base_lock) 1276 __acquires(rcu)
1325{ 1277{
1326 int i; 1278 int i;
1327 struct net_device *dev; 1279 struct net_device *dev;
1328 1280
1329 read_lock(&dev_base_lock); 1281 rcu_read_lock();
1330 1282
1331 if (*pos == 0) 1283 if (*pos == 0)
1332 return SEQ_START_TOKEN; 1284 return SEQ_START_TOKEN;
1333 1285
1334 i = 1; 1286 i = 1;
1335 for_each_netdev(&init_net, dev) { 1287 for_each_netdev_rcu(&init_net, dev) {
1336 if (!is_dn_dev(dev)) 1288 if (!is_dn_dev(dev))
1337 continue; 1289 continue;
1338 1290
@@ -1353,7 +1305,7 @@ static void *dn_dev_seq_next(struct seq_file *seq, void *v, loff_t *pos)
1353 if (v == SEQ_START_TOKEN) 1305 if (v == SEQ_START_TOKEN)
1354 dev = net_device_entry(&init_net.dev_base_head); 1306 dev = net_device_entry(&init_net.dev_base_head);
1355 1307
1356 for_each_netdev_continue(&init_net, dev) { 1308 for_each_netdev_continue_rcu(&init_net, dev) {
1357 if (!is_dn_dev(dev)) 1309 if (!is_dn_dev(dev))
1358 continue; 1310 continue;
1359 1311
@@ -1364,9 +1316,9 @@ static void *dn_dev_seq_next(struct seq_file *seq, void *v, loff_t *pos)
1364} 1316}
1365 1317
1366static void dn_dev_seq_stop(struct seq_file *seq, void *v) 1318static void dn_dev_seq_stop(struct seq_file *seq, void *v)
1367 __releases(&dev_base_lock) 1319 __releases(rcu)
1368{ 1320{
1369 read_unlock(&dev_base_lock); 1321 rcu_read_unlock();
1370} 1322}
1371 1323
1372static char *dn_type2asc(char type) 1324static char *dn_type2asc(char type)
diff --git a/net/decnet/dn_fib.c b/net/decnet/dn_fib.c
index 27ea2e9b080a..4ab96c15166d 100644
--- a/net/decnet/dn_fib.c
+++ b/net/decnet/dn_fib.c
@@ -20,6 +20,7 @@
20#include <linux/string.h> 20#include <linux/string.h>
21#include <linux/net.h> 21#include <linux/net.h>
22#include <linux/socket.h> 22#include <linux/socket.h>
23#include <linux/slab.h>
23#include <linux/sockios.h> 24#include <linux/sockios.h>
24#include <linux/init.h> 25#include <linux/init.h>
25#include <linux/skbuff.h> 26#include <linux/skbuff.h>
@@ -509,7 +510,7 @@ static int dn_fib_rtm_delroute(struct sk_buff *skb, struct nlmsghdr *nlh, void *
509 struct rtattr **rta = arg; 510 struct rtattr **rta = arg;
510 struct rtmsg *r = NLMSG_DATA(nlh); 511 struct rtmsg *r = NLMSG_DATA(nlh);
511 512
512 if (net != &init_net) 513 if (!net_eq(net, &init_net))
513 return -EINVAL; 514 return -EINVAL;
514 515
515 if (dn_fib_check_attr(r, rta)) 516 if (dn_fib_check_attr(r, rta))
@@ -529,7 +530,7 @@ static int dn_fib_rtm_newroute(struct sk_buff *skb, struct nlmsghdr *nlh, void *
529 struct rtattr **rta = arg; 530 struct rtattr **rta = arg;
530 struct rtmsg *r = NLMSG_DATA(nlh); 531 struct rtmsg *r = NLMSG_DATA(nlh);
531 532
532 if (net != &init_net) 533 if (!net_eq(net, &init_net))
533 return -EINVAL; 534 return -EINVAL;
534 535
535 if (dn_fib_check_attr(r, rta)) 536 if (dn_fib_check_attr(r, rta))
@@ -607,8 +608,8 @@ static void dn_fib_del_ifaddr(struct dn_ifaddr *ifa)
607 ASSERT_RTNL(); 608 ASSERT_RTNL();
608 609
609 /* Scan device list */ 610 /* Scan device list */
610 read_lock(&dev_base_lock); 611 rcu_read_lock();
611 for_each_netdev(&init_net, dev) { 612 for_each_netdev_rcu(&init_net, dev) {
612 dn_db = dev->dn_ptr; 613 dn_db = dev->dn_ptr;
613 if (dn_db == NULL) 614 if (dn_db == NULL)
614 continue; 615 continue;
@@ -619,7 +620,7 @@ static void dn_fib_del_ifaddr(struct dn_ifaddr *ifa)
619 } 620 }
620 } 621 }
621 } 622 }
622 read_unlock(&dev_base_lock); 623 rcu_read_unlock();
623 624
624 if (found_it == 0) { 625 if (found_it == 0) {
625 fib_magic(RTM_DELROUTE, RTN_LOCAL, ifa->ifa_local, 16, ifa); 626 fib_magic(RTM_DELROUTE, RTN_LOCAL, ifa->ifa_local, 16, ifa);
diff --git a/net/decnet/dn_neigh.c b/net/decnet/dn_neigh.c
index 794b5bf95af1..deb723dba44b 100644
--- a/net/decnet/dn_neigh.c
+++ b/net/decnet/dn_neigh.c
@@ -28,6 +28,7 @@
28#include <linux/module.h> 28#include <linux/module.h>
29#include <linux/socket.h> 29#include <linux/socket.h>
30#include <linux/if_arp.h> 30#include <linux/if_arp.h>
31#include <linux/slab.h>
31#include <linux/if_ether.h> 32#include <linux/if_ether.h>
32#include <linux/init.h> 33#include <linux/init.h>
33#include <linux/proc_fs.h> 34#include <linux/proc_fs.h>
diff --git a/net/decnet/dn_nsp_in.c b/net/decnet/dn_nsp_in.c
index 932408dca86d..25a37299bc65 100644
--- a/net/decnet/dn_nsp_in.c
+++ b/net/decnet/dn_nsp_in.c
@@ -57,6 +57,7 @@
57#include <linux/netdevice.h> 57#include <linux/netdevice.h>
58#include <linux/inet.h> 58#include <linux/inet.h>
59#include <linux/route.h> 59#include <linux/route.h>
60#include <linux/slab.h>
60#include <net/sock.h> 61#include <net/sock.h>
61#include <net/tcp_states.h> 62#include <net/tcp_states.h>
62#include <asm/system.h> 63#include <asm/system.h>
diff --git a/net/decnet/dn_nsp_out.c b/net/decnet/dn_nsp_out.c
index a65e929ce76c..baeb1eaf011b 100644
--- a/net/decnet/dn_nsp_out.c
+++ b/net/decnet/dn_nsp_out.c
@@ -50,6 +50,7 @@
50#include <linux/netdevice.h> 50#include <linux/netdevice.h>
51#include <linux/inet.h> 51#include <linux/inet.h>
52#include <linux/route.h> 52#include <linux/route.h>
53#include <linux/slab.h>
53#include <net/sock.h> 54#include <net/sock.h>
54#include <asm/system.h> 55#include <asm/system.h>
55#include <linux/fcntl.h> 56#include <linux/fcntl.h>
diff --git a/net/decnet/dn_route.c b/net/decnet/dn_route.c
index 57662cabaf9b..70ebe74027d5 100644
--- a/net/decnet/dn_route.c
+++ b/net/decnet/dn_route.c
@@ -66,6 +66,7 @@
66#include <linux/inet.h> 66#include <linux/inet.h>
67#include <linux/route.h> 67#include <linux/route.h>
68#include <linux/in_route.h> 68#include <linux/in_route.h>
69#include <linux/slab.h>
69#include <net/sock.h> 70#include <net/sock.h>
70#include <linux/mm.h> 71#include <linux/mm.h>
71#include <linux/proc_fs.h> 72#include <linux/proc_fs.h>
@@ -908,8 +909,8 @@ static int dn_route_output_slow(struct dst_entry **pprt, const struct flowi *old
908 dev_put(dev_out); 909 dev_put(dev_out);
909 goto out; 910 goto out;
910 } 911 }
911 read_lock(&dev_base_lock); 912 rcu_read_lock();
912 for_each_netdev(&init_net, dev) { 913 for_each_netdev_rcu(&init_net, dev) {
913 if (!dev->dn_ptr) 914 if (!dev->dn_ptr)
914 continue; 915 continue;
915 if (!dn_dev_islocal(dev, oldflp->fld_src)) 916 if (!dn_dev_islocal(dev, oldflp->fld_src))
@@ -922,7 +923,7 @@ static int dn_route_output_slow(struct dst_entry **pprt, const struct flowi *old
922 dev_out = dev; 923 dev_out = dev;
923 break; 924 break;
924 } 925 }
925 read_unlock(&dev_base_lock); 926 rcu_read_unlock();
926 if (dev_out == NULL) 927 if (dev_out == NULL)
927 goto out; 928 goto out;
928 dev_hold(dev_out); 929 dev_hold(dev_out);
@@ -1155,8 +1156,8 @@ static int __dn_route_output_key(struct dst_entry **pprt, const struct flowi *fl
1155 1156
1156 if (!(flags & MSG_TRYHARD)) { 1157 if (!(flags & MSG_TRYHARD)) {
1157 rcu_read_lock_bh(); 1158 rcu_read_lock_bh();
1158 for(rt = rcu_dereference(dn_rt_hash_table[hash].chain); rt; 1159 for (rt = rcu_dereference_bh(dn_rt_hash_table[hash].chain); rt;
1159 rt = rcu_dereference(rt->u.dst.dn_next)) { 1160 rt = rcu_dereference_bh(rt->u.dst.dn_next)) {
1160 if ((flp->fld_dst == rt->fl.fld_dst) && 1161 if ((flp->fld_dst == rt->fl.fld_dst) &&
1161 (flp->fld_src == rt->fl.fld_src) && 1162 (flp->fld_src == rt->fl.fld_src) &&
1162 (flp->mark == rt->fl.mark) && 1163 (flp->mark == rt->fl.mark) &&
@@ -1517,7 +1518,7 @@ static int dn_cache_getroute(struct sk_buff *in_skb, struct nlmsghdr *nlh, void
1517 struct sk_buff *skb; 1518 struct sk_buff *skb;
1518 struct flowi fl; 1519 struct flowi fl;
1519 1520
1520 if (net != &init_net) 1521 if (!net_eq(net, &init_net))
1521 return -EINVAL; 1522 return -EINVAL;
1522 1523
1523 memset(&fl, 0, sizeof(fl)); 1524 memset(&fl, 0, sizeof(fl));
@@ -1602,7 +1603,7 @@ int dn_cache_dump(struct sk_buff *skb, struct netlink_callback *cb)
1602 int h, s_h; 1603 int h, s_h;
1603 int idx, s_idx; 1604 int idx, s_idx;
1604 1605
1605 if (net != &init_net) 1606 if (!net_eq(net, &init_net))
1606 return 0; 1607 return 0;
1607 1608
1608 if (NLMSG_PAYLOAD(cb->nlh, 0) < sizeof(struct rtmsg)) 1609 if (NLMSG_PAYLOAD(cb->nlh, 0) < sizeof(struct rtmsg))
@@ -1618,9 +1619,9 @@ int dn_cache_dump(struct sk_buff *skb, struct netlink_callback *cb)
1618 if (h > s_h) 1619 if (h > s_h)
1619 s_idx = 0; 1620 s_idx = 0;
1620 rcu_read_lock_bh(); 1621 rcu_read_lock_bh();
1621 for(rt = rcu_dereference(dn_rt_hash_table[h].chain), idx = 0; 1622 for(rt = rcu_dereference_bh(dn_rt_hash_table[h].chain), idx = 0;
1622 rt; 1623 rt;
1623 rt = rcu_dereference(rt->u.dst.dn_next), idx++) { 1624 rt = rcu_dereference_bh(rt->u.dst.dn_next), idx++) {
1624 if (idx < s_idx) 1625 if (idx < s_idx)
1625 continue; 1626 continue;
1626 skb_dst_set(skb, dst_clone(&rt->u.dst)); 1627 skb_dst_set(skb, dst_clone(&rt->u.dst));
@@ -1654,12 +1655,12 @@ static struct dn_route *dn_rt_cache_get_first(struct seq_file *seq)
1654 1655
1655 for(s->bucket = dn_rt_hash_mask; s->bucket >= 0; --s->bucket) { 1656 for(s->bucket = dn_rt_hash_mask; s->bucket >= 0; --s->bucket) {
1656 rcu_read_lock_bh(); 1657 rcu_read_lock_bh();
1657 rt = dn_rt_hash_table[s->bucket].chain; 1658 rt = rcu_dereference_bh(dn_rt_hash_table[s->bucket].chain);
1658 if (rt) 1659 if (rt)
1659 break; 1660 break;
1660 rcu_read_unlock_bh(); 1661 rcu_read_unlock_bh();
1661 } 1662 }
1662 return rcu_dereference(rt); 1663 return rt;
1663} 1664}
1664 1665
1665static struct dn_route *dn_rt_cache_get_next(struct seq_file *seq, struct dn_route *rt) 1666static struct dn_route *dn_rt_cache_get_next(struct seq_file *seq, struct dn_route *rt)
@@ -1674,7 +1675,7 @@ static struct dn_route *dn_rt_cache_get_next(struct seq_file *seq, struct dn_rou
1674 rcu_read_lock_bh(); 1675 rcu_read_lock_bh();
1675 rt = dn_rt_hash_table[s->bucket].chain; 1676 rt = dn_rt_hash_table[s->bucket].chain;
1676 } 1677 }
1677 return rcu_dereference(rt); 1678 return rcu_dereference_bh(rt);
1678} 1679}
1679 1680
1680static void *dn_rt_cache_seq_start(struct seq_file *seq, loff_t *pos) 1681static void *dn_rt_cache_seq_start(struct seq_file *seq, loff_t *pos)
diff --git a/net/decnet/dn_rules.c b/net/decnet/dn_rules.c
index 72495f25269f..7466c546f286 100644
--- a/net/decnet/dn_rules.c
+++ b/net/decnet/dn_rules.c
@@ -33,7 +33,7 @@
33#include <net/dn_dev.h> 33#include <net/dn_dev.h>
34#include <net/dn_route.h> 34#include <net/dn_route.h>
35 35
36static struct fib_rules_ops dn_fib_rules_ops; 36static struct fib_rules_ops *dn_fib_rules_ops;
37 37
38struct dn_fib_rule 38struct dn_fib_rule
39{ 39{
@@ -56,7 +56,7 @@ int dn_fib_lookup(struct flowi *flp, struct dn_fib_res *res)
56 }; 56 };
57 int err; 57 int err;
58 58
59 err = fib_rules_lookup(&dn_fib_rules_ops, flp, 0, &arg); 59 err = fib_rules_lookup(dn_fib_rules_ops, flp, 0, &arg);
60 res->r = arg.rule; 60 res->r = arg.rule;
61 61
62 return err; 62 return err;
@@ -217,9 +217,9 @@ static u32 dn_fib_rule_default_pref(struct fib_rules_ops *ops)
217 struct list_head *pos; 217 struct list_head *pos;
218 struct fib_rule *rule; 218 struct fib_rule *rule;
219 219
220 if (!list_empty(&dn_fib_rules_ops.rules_list)) { 220 if (!list_empty(&dn_fib_rules_ops->rules_list)) {
221 pos = dn_fib_rules_ops.rules_list.next; 221 pos = dn_fib_rules_ops->rules_list.next;
222 if (pos->next != &dn_fib_rules_ops.rules_list) { 222 if (pos->next != &dn_fib_rules_ops->rules_list) {
223 rule = list_entry(pos->next, struct fib_rule, list); 223 rule = list_entry(pos->next, struct fib_rule, list);
224 if (rule->pref) 224 if (rule->pref)
225 return rule->pref - 1; 225 return rule->pref - 1;
@@ -234,7 +234,7 @@ static void dn_fib_rule_flush_cache(struct fib_rules_ops *ops)
234 dn_rt_cache_flush(-1); 234 dn_rt_cache_flush(-1);
235} 235}
236 236
237static struct fib_rules_ops dn_fib_rules_ops = { 237static struct fib_rules_ops dn_fib_rules_ops_template = {
238 .family = AF_DECnet, 238 .family = AF_DECnet,
239 .rule_size = sizeof(struct dn_fib_rule), 239 .rule_size = sizeof(struct dn_fib_rule),
240 .addr_size = sizeof(u16), 240 .addr_size = sizeof(u16),
@@ -247,21 +247,23 @@ static struct fib_rules_ops dn_fib_rules_ops = {
247 .flush_cache = dn_fib_rule_flush_cache, 247 .flush_cache = dn_fib_rule_flush_cache,
248 .nlgroup = RTNLGRP_DECnet_RULE, 248 .nlgroup = RTNLGRP_DECnet_RULE,
249 .policy = dn_fib_rule_policy, 249 .policy = dn_fib_rule_policy,
250 .rules_list = LIST_HEAD_INIT(dn_fib_rules_ops.rules_list),
251 .owner = THIS_MODULE, 250 .owner = THIS_MODULE,
252 .fro_net = &init_net, 251 .fro_net = &init_net,
253}; 252};
254 253
255void __init dn_fib_rules_init(void) 254void __init dn_fib_rules_init(void)
256{ 255{
257 BUG_ON(fib_default_rule_add(&dn_fib_rules_ops, 0x7fff, 256 dn_fib_rules_ops =
257 fib_rules_register(&dn_fib_rules_ops_template, &init_net);
258 BUG_ON(IS_ERR(dn_fib_rules_ops));
259 BUG_ON(fib_default_rule_add(dn_fib_rules_ops, 0x7fff,
258 RT_TABLE_MAIN, 0)); 260 RT_TABLE_MAIN, 0));
259 fib_rules_register(&dn_fib_rules_ops);
260} 261}
261 262
262void __exit dn_fib_rules_cleanup(void) 263void __exit dn_fib_rules_cleanup(void)
263{ 264{
264 fib_rules_unregister(&dn_fib_rules_ops); 265 fib_rules_unregister(dn_fib_rules_ops);
266 rcu_barrier();
265} 267}
266 268
267 269
diff --git a/net/decnet/dn_table.c b/net/decnet/dn_table.c
index 67054b0d550f..f2abd3755690 100644
--- a/net/decnet/dn_table.c
+++ b/net/decnet/dn_table.c
@@ -15,6 +15,7 @@
15#include <linux/string.h> 15#include <linux/string.h>
16#include <linux/net.h> 16#include <linux/net.h>
17#include <linux/socket.h> 17#include <linux/socket.h>
18#include <linux/slab.h>
18#include <linux/sockios.h> 19#include <linux/sockios.h>
19#include <linux/init.h> 20#include <linux/init.h>
20#include <linux/skbuff.h> 21#include <linux/skbuff.h>
@@ -471,7 +472,7 @@ int dn_fib_dump(struct sk_buff *skb, struct netlink_callback *cb)
471 struct hlist_node *node; 472 struct hlist_node *node;
472 int dumped = 0; 473 int dumped = 0;
473 474
474 if (net != &init_net) 475 if (!net_eq(net, &init_net))
475 return 0; 476 return 0;
476 477
477 if (NLMSG_PAYLOAD(cb->nlh, 0) >= sizeof(struct rtmsg) && 478 if (NLMSG_PAYLOAD(cb->nlh, 0) >= sizeof(struct rtmsg) &&
@@ -581,8 +582,9 @@ static int dn_fib_table_insert(struct dn_fib_table *tb, struct rtmsg *r, struct
581 DN_FIB_SCAN_KEY(f, fp, key) { 582 DN_FIB_SCAN_KEY(f, fp, key) {
582 if (fi->fib_priority != DN_FIB_INFO(f)->fib_priority) 583 if (fi->fib_priority != DN_FIB_INFO(f)->fib_priority)
583 break; 584 break;
584 if (f->fn_type == type && f->fn_scope == r->rtm_scope 585 if (f->fn_type == type &&
585 && DN_FIB_INFO(f) == fi) 586 f->fn_scope == r->rtm_scope &&
587 DN_FIB_INFO(f) == fi)
586 goto out; 588 goto out;
587 } 589 }
588 590
diff --git a/net/decnet/netfilter/dn_rtmsg.c b/net/decnet/netfilter/dn_rtmsg.c
index 6d2bd3202048..64a7f39e069f 100644
--- a/net/decnet/netfilter/dn_rtmsg.c
+++ b/net/decnet/netfilter/dn_rtmsg.c
@@ -14,6 +14,7 @@
14 */ 14 */
15#include <linux/module.h> 15#include <linux/module.h>
16#include <linux/skbuff.h> 16#include <linux/skbuff.h>
17#include <linux/slab.h>
17#include <linux/init.h> 18#include <linux/init.h>
18#include <linux/netdevice.h> 19#include <linux/netdevice.h>
19#include <linux/netfilter.h> 20#include <linux/netfilter.h>
diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
index 2036568beea9..be3eb8e23288 100644
--- a/net/decnet/sysctl_net_decnet.c
+++ b/net/decnet/sysctl_net_decnet.c
@@ -131,39 +131,6 @@ static int parse_addr(__le16 *addr, char *str)
131 return 0; 131 return 0;
132} 132}
133 133
134
135static int dn_node_address_strategy(ctl_table *table,
136 void __user *oldval, size_t __user *oldlenp,
137 void __user *newval, size_t newlen)
138{
139 size_t len;
140 __le16 addr;
141
142 if (oldval && oldlenp) {
143 if (get_user(len, oldlenp))
144 return -EFAULT;
145 if (len) {
146 if (len != sizeof(unsigned short))
147 return -EINVAL;
148 if (put_user(decnet_address, (__le16 __user *)oldval))
149 return -EFAULT;
150 }
151 }
152 if (newval && newlen) {
153 if (newlen != sizeof(unsigned short))
154 return -EINVAL;
155 if (get_user(addr, (__le16 __user *)newval))
156 return -EFAULT;
157
158 dn_dev_devices_off();
159
160 decnet_address = addr;
161
162 dn_dev_devices_on();
163 }
164 return 0;
165}
166
167static int dn_node_address_handler(ctl_table *table, int write, 134static int dn_node_address_handler(ctl_table *table, int write,
168 void __user *buffer, 135 void __user *buffer,
169 size_t *lenp, loff_t *ppos) 136 size_t *lenp, loff_t *ppos)
@@ -215,64 +182,6 @@ static int dn_node_address_handler(ctl_table *table, int write,
215 return 0; 182 return 0;
216} 183}
217 184
218
219static int dn_def_dev_strategy(ctl_table *table,
220 void __user *oldval, size_t __user *oldlenp,
221 void __user *newval, size_t newlen)
222{
223 size_t len;
224 struct net_device *dev;
225 char devname[17];
226 size_t namel;
227 int rv = 0;
228
229 devname[0] = 0;
230
231 if (oldval && oldlenp) {
232 if (get_user(len, oldlenp))
233 return -EFAULT;
234 if (len) {
235 dev = dn_dev_get_default();
236 if (dev) {
237 strcpy(devname, dev->name);
238 dev_put(dev);
239 }
240
241 namel = strlen(devname) + 1;
242 if (len > namel) len = namel;
243
244 if (copy_to_user(oldval, devname, len))
245 return -EFAULT;
246
247 if (put_user(len, oldlenp))
248 return -EFAULT;
249 }
250 }
251
252 if (newval && newlen) {
253 if (newlen > 16)
254 return -E2BIG;
255
256 if (copy_from_user(devname, newval, newlen))
257 return -EFAULT;
258
259 devname[newlen] = 0;
260
261 dev = dev_get_by_name(&init_net, devname);
262 if (dev == NULL)
263 return -ENODEV;
264
265 rv = -ENODEV;
266 if (dev->dn_ptr != NULL)
267 rv = dn_dev_set_default(dev, 1);
268 if (rv)
269 dev_put(dev);
270 }
271
272 return rv;
273}
274
275
276static int dn_def_dev_handler(ctl_table *table, int write, 185static int dn_def_dev_handler(ctl_table *table, int write,
277 void __user *buffer, 186 void __user *buffer,
278 size_t *lenp, loff_t *ppos) 187 size_t *lenp, loff_t *ppos)
@@ -338,138 +247,112 @@ static int dn_def_dev_handler(ctl_table *table, int write,
338 247
339static ctl_table dn_table[] = { 248static ctl_table dn_table[] = {
340 { 249 {
341 .ctl_name = NET_DECNET_NODE_ADDRESS,
342 .procname = "node_address", 250 .procname = "node_address",
343 .maxlen = 7, 251 .maxlen = 7,
344 .mode = 0644, 252 .mode = 0644,
345 .proc_handler = dn_node_address_handler, 253 .proc_handler = dn_node_address_handler,
346 .strategy = dn_node_address_strategy,
347 }, 254 },
348 { 255 {
349 .ctl_name = NET_DECNET_NODE_NAME,
350 .procname = "node_name", 256 .procname = "node_name",
351 .data = node_name, 257 .data = node_name,
352 .maxlen = 7, 258 .maxlen = 7,
353 .mode = 0644, 259 .mode = 0644,
354 .proc_handler = proc_dostring, 260 .proc_handler = proc_dostring,
355 .strategy = sysctl_string,
356 }, 261 },
357 { 262 {
358 .ctl_name = NET_DECNET_DEFAULT_DEVICE,
359 .procname = "default_device", 263 .procname = "default_device",
360 .maxlen = 16, 264 .maxlen = 16,
361 .mode = 0644, 265 .mode = 0644,
362 .proc_handler = dn_def_dev_handler, 266 .proc_handler = dn_def_dev_handler,
363 .strategy = dn_def_dev_strategy,
364 }, 267 },
365 { 268 {
366 .ctl_name = NET_DECNET_TIME_WAIT,
367 .procname = "time_wait", 269 .procname = "time_wait",
368 .data = &decnet_time_wait, 270 .data = &decnet_time_wait,
369 .maxlen = sizeof(int), 271 .maxlen = sizeof(int),
370 .mode = 0644, 272 .mode = 0644,
371 .proc_handler = proc_dointvec_minmax, 273 .proc_handler = proc_dointvec_minmax,
372 .strategy = sysctl_intvec,
373 .extra1 = &min_decnet_time_wait, 274 .extra1 = &min_decnet_time_wait,
374 .extra2 = &max_decnet_time_wait 275 .extra2 = &max_decnet_time_wait
375 }, 276 },
376 { 277 {
377 .ctl_name = NET_DECNET_DN_COUNT,
378 .procname = "dn_count", 278 .procname = "dn_count",
379 .data = &decnet_dn_count, 279 .data = &decnet_dn_count,
380 .maxlen = sizeof(int), 280 .maxlen = sizeof(int),
381 .mode = 0644, 281 .mode = 0644,
382 .proc_handler = proc_dointvec_minmax, 282 .proc_handler = proc_dointvec_minmax,
383 .strategy = sysctl_intvec,
384 .extra1 = &min_state_count, 283 .extra1 = &min_state_count,
385 .extra2 = &max_state_count 284 .extra2 = &max_state_count
386 }, 285 },
387 { 286 {
388 .ctl_name = NET_DECNET_DI_COUNT,
389 .procname = "di_count", 287 .procname = "di_count",
390 .data = &decnet_di_count, 288 .data = &decnet_di_count,
391 .maxlen = sizeof(int), 289 .maxlen = sizeof(int),
392 .mode = 0644, 290 .mode = 0644,
393 .proc_handler = proc_dointvec_minmax, 291 .proc_handler = proc_dointvec_minmax,
394 .strategy = sysctl_intvec,
395 .extra1 = &min_state_count, 292 .extra1 = &min_state_count,
396 .extra2 = &max_state_count 293 .extra2 = &max_state_count
397 }, 294 },
398 { 295 {
399 .ctl_name = NET_DECNET_DR_COUNT,
400 .procname = "dr_count", 296 .procname = "dr_count",
401 .data = &decnet_dr_count, 297 .data = &decnet_dr_count,
402 .maxlen = sizeof(int), 298 .maxlen = sizeof(int),
403 .mode = 0644, 299 .mode = 0644,
404 .proc_handler = proc_dointvec_minmax, 300 .proc_handler = proc_dointvec_minmax,
405 .strategy = sysctl_intvec,
406 .extra1 = &min_state_count, 301 .extra1 = &min_state_count,
407 .extra2 = &max_state_count 302 .extra2 = &max_state_count
408 }, 303 },
409 { 304 {
410 .ctl_name = NET_DECNET_DST_GC_INTERVAL,
411 .procname = "dst_gc_interval", 305 .procname = "dst_gc_interval",
412 .data = &decnet_dst_gc_interval, 306 .data = &decnet_dst_gc_interval,
413 .maxlen = sizeof(int), 307 .maxlen = sizeof(int),
414 .mode = 0644, 308 .mode = 0644,
415 .proc_handler = proc_dointvec_minmax, 309 .proc_handler = proc_dointvec_minmax,
416 .strategy = sysctl_intvec,
417 .extra1 = &min_decnet_dst_gc_interval, 310 .extra1 = &min_decnet_dst_gc_interval,
418 .extra2 = &max_decnet_dst_gc_interval 311 .extra2 = &max_decnet_dst_gc_interval
419 }, 312 },
420 { 313 {
421 .ctl_name = NET_DECNET_NO_FC_MAX_CWND,
422 .procname = "no_fc_max_cwnd", 314 .procname = "no_fc_max_cwnd",
423 .data = &decnet_no_fc_max_cwnd, 315 .data = &decnet_no_fc_max_cwnd,
424 .maxlen = sizeof(int), 316 .maxlen = sizeof(int),
425 .mode = 0644, 317 .mode = 0644,
426 .proc_handler = proc_dointvec_minmax, 318 .proc_handler = proc_dointvec_minmax,
427 .strategy = sysctl_intvec,
428 .extra1 = &min_decnet_no_fc_max_cwnd, 319 .extra1 = &min_decnet_no_fc_max_cwnd,
429 .extra2 = &max_decnet_no_fc_max_cwnd 320 .extra2 = &max_decnet_no_fc_max_cwnd
430 }, 321 },
431 { 322 {
432 .ctl_name = NET_DECNET_MEM,
433 .procname = "decnet_mem", 323 .procname = "decnet_mem",
434 .data = &sysctl_decnet_mem, 324 .data = &sysctl_decnet_mem,
435 .maxlen = sizeof(sysctl_decnet_mem), 325 .maxlen = sizeof(sysctl_decnet_mem),
436 .mode = 0644, 326 .mode = 0644,
437 .proc_handler = proc_dointvec, 327 .proc_handler = proc_dointvec,
438 .strategy = sysctl_intvec,
439 }, 328 },
440 { 329 {
441 .ctl_name = NET_DECNET_RMEM,
442 .procname = "decnet_rmem", 330 .procname = "decnet_rmem",
443 .data = &sysctl_decnet_rmem, 331 .data = &sysctl_decnet_rmem,
444 .maxlen = sizeof(sysctl_decnet_rmem), 332 .maxlen = sizeof(sysctl_decnet_rmem),
445 .mode = 0644, 333 .mode = 0644,
446 .proc_handler = proc_dointvec, 334 .proc_handler = proc_dointvec,
447 .strategy = sysctl_intvec,
448 }, 335 },
449 { 336 {
450 .ctl_name = NET_DECNET_WMEM,
451 .procname = "decnet_wmem", 337 .procname = "decnet_wmem",
452 .data = &sysctl_decnet_wmem, 338 .data = &sysctl_decnet_wmem,
453 .maxlen = sizeof(sysctl_decnet_wmem), 339 .maxlen = sizeof(sysctl_decnet_wmem),
454 .mode = 0644, 340 .mode = 0644,
455 .proc_handler = proc_dointvec, 341 .proc_handler = proc_dointvec,
456 .strategy = sysctl_intvec,
457 }, 342 },
458 { 343 {
459 .ctl_name = NET_DECNET_DEBUG_LEVEL,
460 .procname = "debug", 344 .procname = "debug",
461 .data = &decnet_debug_level, 345 .data = &decnet_debug_level,
462 .maxlen = sizeof(int), 346 .maxlen = sizeof(int),
463 .mode = 0644, 347 .mode = 0644,
464 .proc_handler = proc_dointvec, 348 .proc_handler = proc_dointvec,
465 .strategy = sysctl_intvec,
466 }, 349 },
467 {0} 350 { }
468}; 351};
469 352
470static struct ctl_path dn_path[] = { 353static struct ctl_path dn_path[] = {
471 { .procname = "net", .ctl_name = CTL_NET, }, 354 { .procname = "net", },
472 { .procname = "decnet", .ctl_name = NET_DECNET, }, 355 { .procname = "decnet", },
473 { } 356 { }
474}; 357};
475 358
diff --git a/net/dsa/dsa.c b/net/dsa/dsa.c
index 71489f69a42c..6112a12578b2 100644
--- a/net/dsa/dsa.c
+++ b/net/dsa/dsa.c
@@ -11,6 +11,7 @@
11#include <linux/list.h> 11#include <linux/list.h>
12#include <linux/netdevice.h> 12#include <linux/netdevice.h>
13#include <linux/platform_device.h> 13#include <linux/platform_device.h>
14#include <linux/slab.h>
14#include <net/dsa.h> 15#include <net/dsa.h>
15#include "dsa_priv.h" 16#include "dsa_priv.h"
16 17
diff --git a/net/dsa/tag_dsa.c b/net/dsa/tag_dsa.c
index cdf2d28a0297..98dfe80b4538 100644
--- a/net/dsa/tag_dsa.c
+++ b/net/dsa/tag_dsa.c
@@ -11,6 +11,7 @@
11#include <linux/etherdevice.h> 11#include <linux/etherdevice.h>
12#include <linux/list.h> 12#include <linux/list.h>
13#include <linux/netdevice.h> 13#include <linux/netdevice.h>
14#include <linux/slab.h>
14#include "dsa_priv.h" 15#include "dsa_priv.h"
15 16
16#define DSA_HLEN 4 17#define DSA_HLEN 4
diff --git a/net/dsa/tag_edsa.c b/net/dsa/tag_edsa.c
index 8f53948cff4f..6f383322ad25 100644
--- a/net/dsa/tag_edsa.c
+++ b/net/dsa/tag_edsa.c
@@ -11,6 +11,7 @@
11#include <linux/etherdevice.h> 11#include <linux/etherdevice.h>
12#include <linux/list.h> 12#include <linux/list.h>
13#include <linux/netdevice.h> 13#include <linux/netdevice.h>
14#include <linux/slab.h>
14#include "dsa_priv.h" 15#include "dsa_priv.h"
15 16
16#define DSA_HLEN 4 17#define DSA_HLEN 4
diff --git a/net/dsa/tag_trailer.c b/net/dsa/tag_trailer.c
index a85c829853c0..d6d7d0add3cb 100644
--- a/net/dsa/tag_trailer.c
+++ b/net/dsa/tag_trailer.c
@@ -11,6 +11,7 @@
11#include <linux/etherdevice.h> 11#include <linux/etherdevice.h>
12#include <linux/list.h> 12#include <linux/list.h>
13#include <linux/netdevice.h> 13#include <linux/netdevice.h>
14#include <linux/slab.h>
14#include "dsa_priv.h" 15#include "dsa_priv.h"
15 16
16netdev_tx_t trailer_xmit(struct sk_buff *skb, struct net_device *dev) 17netdev_tx_t trailer_xmit(struct sk_buff *skb, struct net_device *dev)
diff --git a/net/econet/af_econet.c b/net/econet/af_econet.c
index 0e0254fd767d..2a5a8053e000 100644
--- a/net/econet/af_econet.c
+++ b/net/econet/af_econet.c
@@ -30,6 +30,7 @@
30#include <linux/wireless.h> 30#include <linux/wireless.h>
31#include <linux/skbuff.h> 31#include <linux/skbuff.h>
32#include <linux/udp.h> 32#include <linux/udp.h>
33#include <linux/slab.h>
33#include <net/sock.h> 34#include <net/sock.h>
34#include <net/inet_common.h> 35#include <net/inet_common.h>
35#include <linux/stat.h> 36#include <linux/stat.h>
@@ -457,15 +458,15 @@ static int econet_sendmsg(struct kiocb *iocb, struct socket *sock,
457 iov[0].iov_len = size; 458 iov[0].iov_len = size;
458 for (i = 0; i < msg->msg_iovlen; i++) { 459 for (i = 0; i < msg->msg_iovlen; i++) {
459 void __user *base = msg->msg_iov[i].iov_base; 460 void __user *base = msg->msg_iov[i].iov_base;
460 size_t len = msg->msg_iov[i].iov_len; 461 size_t iov_len = msg->msg_iov[i].iov_len;
461 /* Check it now since we switch to KERNEL_DS later. */ 462 /* Check it now since we switch to KERNEL_DS later. */
462 if (!access_ok(VERIFY_READ, base, len)) { 463 if (!access_ok(VERIFY_READ, base, iov_len)) {
463 mutex_unlock(&econet_mutex); 464 mutex_unlock(&econet_mutex);
464 return -EFAULT; 465 return -EFAULT;
465 } 466 }
466 iov[i+1].iov_base = base; 467 iov[i+1].iov_base = base;
467 iov[i+1].iov_len = len; 468 iov[i+1].iov_len = iov_len;
468 size += len; 469 size += iov_len;
469 } 470 }
470 471
471 /* Get a skbuff (no data, just holds our cb information) */ 472 /* Get a skbuff (no data, just holds our cb information) */
@@ -605,13 +606,14 @@ static struct proto econet_proto = {
605 * Create an Econet socket 606 * Create an Econet socket
606 */ 607 */
607 608
608static int econet_create(struct net *net, struct socket *sock, int protocol) 609static int econet_create(struct net *net, struct socket *sock, int protocol,
610 int kern)
609{ 611{
610 struct sock *sk; 612 struct sock *sk;
611 struct econet_sock *eo; 613 struct econet_sock *eo;
612 int err; 614 int err;
613 615
614 if (net != &init_net) 616 if (!net_eq(net, &init_net))
615 return -EAFNOSUPPORT; 617 return -EAFNOSUPPORT;
616 618
617 /* Econet only provides datagram services. */ 619 /* Econet only provides datagram services. */
@@ -742,7 +744,7 @@ static int econet_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg
742 return 0; 744 return 0;
743} 745}
744 746
745static struct net_proto_family econet_family_ops = { 747static const struct net_proto_family econet_family_ops = {
746 .family = PF_ECONET, 748 .family = PF_ECONET,
747 .create = econet_create, 749 .create = econet_create,
748 .owner = THIS_MODULE, 750 .owner = THIS_MODULE,
diff --git a/net/ethernet/eth.c b/net/ethernet/eth.c
index 5a883affecd3..205a1c12f3c0 100644
--- a/net/ethernet/eth.c
+++ b/net/ethernet/eth.c
@@ -73,8 +73,8 @@ __setup("ether=", netdev_boot_setup);
73 * @len: packet length (<= skb->len) 73 * @len: packet length (<= skb->len)
74 * 74 *
75 * 75 *
76 * Set the protocol type. For a packet of type ETH_P_802_3 we put the length 76 * Set the protocol type. For a packet of type ETH_P_802_3/2 we put the length
77 * in here instead. It is up to the 802.2 layer to carry protocol information. 77 * in here instead.
78 */ 78 */
79int eth_header(struct sk_buff *skb, struct net_device *dev, 79int eth_header(struct sk_buff *skb, struct net_device *dev,
80 unsigned short type, 80 unsigned short type,
@@ -82,7 +82,7 @@ int eth_header(struct sk_buff *skb, struct net_device *dev,
82{ 82{
83 struct ethhdr *eth = (struct ethhdr *)skb_push(skb, ETH_HLEN); 83 struct ethhdr *eth = (struct ethhdr *)skb_push(skb, ETH_HLEN);
84 84
85 if (type != ETH_P_802_3) 85 if (type != ETH_P_802_3 && type != ETH_P_802_2)
86 eth->h_proto = htons(type); 86 eth->h_proto = htons(type);
87 else 87 else
88 eth->h_proto = htons(len); 88 eth->h_proto = htons(len);
@@ -393,10 +393,3 @@ ssize_t sysfs_format_mac(char *buf, const unsigned char *addr, int len)
393 return ((ssize_t) l); 393 return ((ssize_t) l);
394} 394}
395EXPORT_SYMBOL(sysfs_format_mac); 395EXPORT_SYMBOL(sysfs_format_mac);
396
397char *print_mac(char *buf, const unsigned char *addr)
398{
399 _format_mac_addr(buf, MAC_BUF_SIZE, addr, ETH_ALEN);
400 return buf;
401}
402EXPORT_SYMBOL(print_mac);
diff --git a/net/ethernet/pe2.c b/net/ethernet/pe2.c
index d60e15d9365e..eb00796758c3 100644
--- a/net/ethernet/pe2.c
+++ b/net/ethernet/pe2.c
@@ -3,6 +3,7 @@
3#include <linux/module.h> 3#include <linux/module.h>
4#include <linux/netdevice.h> 4#include <linux/netdevice.h>
5#include <linux/skbuff.h> 5#include <linux/skbuff.h>
6#include <linux/slab.h>
6 7
7#include <net/datalink.h> 8#include <net/datalink.h>
8 9
diff --git a/net/ieee802154/Makefile b/net/ieee802154/Makefile
index 4068a9f5113e..ce2d33582859 100644
--- a/net/ieee802154/Makefile
+++ b/net/ieee802154/Makefile
@@ -1,5 +1,5 @@
1obj-$(CONFIG_IEEE802154) += nl802154.o af_802154.o wpan-class.o 1obj-$(CONFIG_IEEE802154) += ieee802154.o af_802154.o
2nl802154-y := netlink.o nl_policy.o 2ieee802154-y := netlink.o nl-mac.o nl-phy.o nl_policy.o wpan-class.o
3af_802154-y := af_ieee802154.o raw.o dgram.o 3af_802154-y := af_ieee802154.o raw.o dgram.o
4 4
5ccflags-y += -Wall -DDEBUG 5ccflags-y += -Wall -DDEBUG
diff --git a/net/ieee802154/af_ieee802154.c b/net/ieee802154/af_ieee802154.c
index cd949d5e451b..93c91b633a56 100644
--- a/net/ieee802154/af_ieee802154.c
+++ b/net/ieee802154/af_ieee802154.c
@@ -28,6 +28,7 @@
28#include <linux/if.h> 28#include <linux/if.h>
29#include <linux/termios.h> /* For TIOCOUTQ/INQ */ 29#include <linux/termios.h> /* For TIOCOUTQ/INQ */
30#include <linux/list.h> 30#include <linux/list.h>
31#include <linux/slab.h>
31#include <net/datalink.h> 32#include <net/datalink.h>
32#include <net/psnap.h> 33#include <net/psnap.h>
33#include <net/sock.h> 34#include <net/sock.h>
@@ -126,6 +127,9 @@ static int ieee802154_sock_connect(struct socket *sock, struct sockaddr *uaddr,
126{ 127{
127 struct sock *sk = sock->sk; 128 struct sock *sk = sock->sk;
128 129
130 if (addr_len < sizeof(uaddr->sa_family))
131 return -EINVAL;
132
129 if (uaddr->sa_family == AF_UNSPEC) 133 if (uaddr->sa_family == AF_UNSPEC)
130 return sk->sk_prot->disconnect(sk, flags); 134 return sk->sk_prot->disconnect(sk, flags);
131 135
@@ -147,6 +151,9 @@ static int ieee802154_dev_ioctl(struct sock *sk, struct ifreq __user *arg,
147 dev_load(sock_net(sk), ifr.ifr_name); 151 dev_load(sock_net(sk), ifr.ifr_name);
148 dev = dev_get_by_name(sock_net(sk), ifr.ifr_name); 152 dev = dev_get_by_name(sock_net(sk), ifr.ifr_name);
149 153
154 if (!dev)
155 return -ENODEV;
156
150 if (dev->type == ARPHRD_IEEE802154 && dev->netdev_ops->ndo_do_ioctl) 157 if (dev->type == ARPHRD_IEEE802154 && dev->netdev_ops->ndo_do_ioctl)
151 ret = dev->netdev_ops->ndo_do_ioctl(dev, &ifr, cmd); 158 ret = dev->netdev_ops->ndo_do_ioctl(dev, &ifr, cmd);
152 159
@@ -234,14 +241,14 @@ static const struct proto_ops ieee802154_dgram_ops = {
234 * set the state. 241 * set the state.
235 */ 242 */
236static int ieee802154_create(struct net *net, struct socket *sock, 243static int ieee802154_create(struct net *net, struct socket *sock,
237 int protocol) 244 int protocol, int kern)
238{ 245{
239 struct sock *sk; 246 struct sock *sk;
240 int rc; 247 int rc;
241 struct proto *proto; 248 struct proto *proto;
242 const struct proto_ops *ops; 249 const struct proto_ops *ops;
243 250
244 if (net != &init_net) 251 if (!net_eq(net, &init_net))
245 return -EAFNOSUPPORT; 252 return -EAFNOSUPPORT;
246 253
247 switch (sock->type) { 254 switch (sock->type) {
@@ -285,7 +292,7 @@ out:
285 return rc; 292 return rc;
286} 293}
287 294
288static struct net_proto_family ieee802154_family_ops = { 295static const struct net_proto_family ieee802154_family_ops = {
289 .family = PF_IEEE802154, 296 .family = PF_IEEE802154,
290 .create = ieee802154_create, 297 .create = ieee802154_create,
291 .owner = THIS_MODULE, 298 .owner = THIS_MODULE,
diff --git a/net/ieee802154/dgram.c b/net/ieee802154/dgram.c
index a413b1bf4465..1a3334c2609a 100644
--- a/net/ieee802154/dgram.c
+++ b/net/ieee802154/dgram.c
@@ -25,6 +25,7 @@
25#include <linux/module.h> 25#include <linux/module.h>
26#include <linux/if_arp.h> 26#include <linux/if_arp.h>
27#include <linux/list.h> 27#include <linux/list.h>
28#include <linux/slab.h>
28#include <net/sock.h> 29#include <net/sock.h>
29#include <net/af_ieee802154.h> 30#include <net/af_ieee802154.h>
30#include <net/ieee802154.h> 31#include <net/ieee802154.h>
@@ -303,7 +304,7 @@ static int dgram_recvmsg(struct kiocb *iocb, struct sock *sk,
303 if (err) 304 if (err)
304 goto done; 305 goto done;
305 306
306 sock_recv_timestamp(msg, sk, skb); 307 sock_recv_ts_and_drops(msg, sk, skb);
307 308
308 if (flags & MSG_TRUNC) 309 if (flags & MSG_TRUNC)
309 copied = skb->len; 310 copied = skb->len;
@@ -318,7 +319,6 @@ out:
318static int dgram_rcv_skb(struct sock *sk, struct sk_buff *skb) 319static int dgram_rcv_skb(struct sock *sk, struct sk_buff *skb)
319{ 320{
320 if (sock_queue_rcv_skb(sk, skb) < 0) { 321 if (sock_queue_rcv_skb(sk, skb) < 0) {
321 atomic_inc(&sk->sk_drops);
322 kfree_skb(skb); 322 kfree_skb(skb);
323 return NET_RX_DROP; 323 return NET_RX_DROP;
324 } 324 }
diff --git a/net/ieee802154/ieee802154.h b/net/ieee802154/ieee802154.h
new file mode 100644
index 000000000000..aadec428e6ec
--- /dev/null
+++ b/net/ieee802154/ieee802154.h
@@ -0,0 +1,53 @@
1/*
2 * Copyright (C) 2007, 2008, 2009 Siemens AG
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2
6 * as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16 *
17 */
18#ifndef IEEE_802154_LOCAL_H
19#define IEEE_802154_LOCAL_H
20
21int __init ieee802154_nl_init(void);
22void __exit ieee802154_nl_exit(void);
23
24#define IEEE802154_OP(_cmd, _func) \
25 { \
26 .cmd = _cmd, \
27 .policy = ieee802154_policy, \
28 .doit = _func, \
29 .dumpit = NULL, \
30 .flags = GENL_ADMIN_PERM, \
31 }
32
33#define IEEE802154_DUMP(_cmd, _func, _dump) \
34 { \
35 .cmd = _cmd, \
36 .policy = ieee802154_policy, \
37 .doit = _func, \
38 .dumpit = _dump, \
39 }
40
41struct genl_info;
42
43struct sk_buff *ieee802154_nl_create(int flags, u8 req);
44int ieee802154_nl_mcast(struct sk_buff *msg, unsigned int group);
45struct sk_buff *ieee802154_nl_new_reply(struct genl_info *info,
46 int flags, u8 req);
47int ieee802154_nl_reply(struct sk_buff *msg, struct genl_info *info);
48
49extern struct genl_family nl802154_family;
50int nl802154_mac_register(void);
51int nl802154_phy_register(void);
52
53#endif
diff --git a/net/ieee802154/netlink.c b/net/ieee802154/netlink.c
index ca767bde17a4..c8097ae2482f 100644
--- a/net/ieee802154/netlink.c
+++ b/net/ieee802154/netlink.c
@@ -23,21 +23,16 @@
23 */ 23 */
24 24
25#include <linux/kernel.h> 25#include <linux/kernel.h>
26#include <linux/if_arp.h> 26#include <linux/gfp.h>
27#include <linux/netdevice.h>
28#include <net/netlink.h>
29#include <net/genetlink.h> 27#include <net/genetlink.h>
30#include <net/sock.h>
31#include <linux/nl802154.h> 28#include <linux/nl802154.h>
32#include <net/af_ieee802154.h> 29
33#include <net/nl802154.h> 30#include "ieee802154.h"
34#include <net/ieee802154.h>
35#include <net/ieee802154_netdev.h>
36 31
37static unsigned int ieee802154_seq_num; 32static unsigned int ieee802154_seq_num;
38static DEFINE_SPINLOCK(ieee802154_seq_lock); 33static DEFINE_SPINLOCK(ieee802154_seq_lock);
39 34
40static struct genl_family ieee802154_coordinator_family = { 35struct genl_family nl802154_family = {
41 .id = GENL_ID_GENERATE, 36 .id = GENL_ID_GENERATE,
42 .hdrsize = 0, 37 .hdrsize = 0,
43 .name = IEEE802154_NL_NAME, 38 .name = IEEE802154_NL_NAME,
@@ -45,16 +40,8 @@ static struct genl_family ieee802154_coordinator_family = {
45 .maxattr = IEEE802154_ATTR_MAX, 40 .maxattr = IEEE802154_ATTR_MAX,
46}; 41};
47 42
48static struct genl_multicast_group ieee802154_coord_mcgrp = {
49 .name = IEEE802154_MCAST_COORD_NAME,
50};
51
52static struct genl_multicast_group ieee802154_beacon_mcgrp = {
53 .name = IEEE802154_MCAST_BEACON_NAME,
54};
55
56/* Requests to userspace */ 43/* Requests to userspace */
57static struct sk_buff *ieee802154_nl_create(int flags, u8 req) 44struct sk_buff *ieee802154_nl_create(int flags, u8 req)
58{ 45{
59 void *hdr; 46 void *hdr;
60 struct sk_buff *msg = nlmsg_new(NLMSG_GOODSIZE, GFP_ATOMIC); 47 struct sk_buff *msg = nlmsg_new(NLMSG_GOODSIZE, GFP_ATOMIC);
@@ -65,7 +52,7 @@ static struct sk_buff *ieee802154_nl_create(int flags, u8 req)
65 52
66 spin_lock_irqsave(&ieee802154_seq_lock, f); 53 spin_lock_irqsave(&ieee802154_seq_lock, f);
67 hdr = genlmsg_put(msg, 0, ieee802154_seq_num++, 54 hdr = genlmsg_put(msg, 0, ieee802154_seq_num++,
68 &ieee802154_coordinator_family, flags, req); 55 &nl802154_family, flags, req);
69 spin_unlock_irqrestore(&ieee802154_seq_lock, f); 56 spin_unlock_irqrestore(&ieee802154_seq_lock, f);
70 if (!hdr) { 57 if (!hdr) {
71 nlmsg_free(msg); 58 nlmsg_free(msg);
@@ -75,7 +62,7 @@ static struct sk_buff *ieee802154_nl_create(int flags, u8 req)
75 return msg; 62 return msg;
76} 63}
77 64
78static int ieee802154_nl_finish(struct sk_buff *msg) 65int ieee802154_nl_mcast(struct sk_buff *msg, unsigned int group)
79{ 66{
80 /* XXX: nlh is right at the start of msg */ 67 /* XXX: nlh is right at the start of msg */
81 void *hdr = genlmsg_data(NLMSG_DATA(msg->data)); 68 void *hdr = genlmsg_data(NLMSG_DATA(msg->data));
@@ -83,607 +70,70 @@ static int ieee802154_nl_finish(struct sk_buff *msg)
83 if (genlmsg_end(msg, hdr) < 0) 70 if (genlmsg_end(msg, hdr) < 0)
84 goto out; 71 goto out;
85 72
86 return genlmsg_multicast(msg, 0, ieee802154_coord_mcgrp.id, 73 return genlmsg_multicast(msg, 0, group, GFP_ATOMIC);
87 GFP_ATOMIC);
88out: 74out:
89 nlmsg_free(msg); 75 nlmsg_free(msg);
90 return -ENOBUFS; 76 return -ENOBUFS;
91} 77}
92 78
93int ieee802154_nl_assoc_indic(struct net_device *dev, 79struct sk_buff *ieee802154_nl_new_reply(struct genl_info *info,
94 struct ieee802154_addr *addr, u8 cap) 80 int flags, u8 req)
95{
96 struct sk_buff *msg;
97
98 pr_debug("%s\n", __func__);
99
100 if (addr->addr_type != IEEE802154_ADDR_LONG) {
101 pr_err("%s: received non-long source address!\n", __func__);
102 return -EINVAL;
103 }
104
105 msg = ieee802154_nl_create(0, IEEE802154_ASSOCIATE_INDIC);
106 if (!msg)
107 return -ENOBUFS;
108
109 NLA_PUT_STRING(msg, IEEE802154_ATTR_DEV_NAME, dev->name);
110 NLA_PUT_U32(msg, IEEE802154_ATTR_DEV_INDEX, dev->ifindex);
111 NLA_PUT(msg, IEEE802154_ATTR_HW_ADDR, IEEE802154_ADDR_LEN,
112 dev->dev_addr);
113
114 NLA_PUT(msg, IEEE802154_ATTR_SRC_HW_ADDR, IEEE802154_ADDR_LEN,
115 addr->hwaddr);
116
117 NLA_PUT_U8(msg, IEEE802154_ATTR_CAPABILITY, cap);
118
119 return ieee802154_nl_finish(msg);
120
121nla_put_failure:
122 nlmsg_free(msg);
123 return -ENOBUFS;
124}
125EXPORT_SYMBOL(ieee802154_nl_assoc_indic);
126
127int ieee802154_nl_assoc_confirm(struct net_device *dev, u16 short_addr,
128 u8 status)
129{
130 struct sk_buff *msg;
131
132 pr_debug("%s\n", __func__);
133
134 msg = ieee802154_nl_create(0, IEEE802154_ASSOCIATE_CONF);
135 if (!msg)
136 return -ENOBUFS;
137
138 NLA_PUT_STRING(msg, IEEE802154_ATTR_DEV_NAME, dev->name);
139 NLA_PUT_U32(msg, IEEE802154_ATTR_DEV_INDEX, dev->ifindex);
140 NLA_PUT(msg, IEEE802154_ATTR_HW_ADDR, IEEE802154_ADDR_LEN,
141 dev->dev_addr);
142
143 NLA_PUT_U16(msg, IEEE802154_ATTR_SHORT_ADDR, short_addr);
144 NLA_PUT_U8(msg, IEEE802154_ATTR_STATUS, status);
145
146 return ieee802154_nl_finish(msg);
147
148nla_put_failure:
149 nlmsg_free(msg);
150 return -ENOBUFS;
151}
152EXPORT_SYMBOL(ieee802154_nl_assoc_confirm);
153
154int ieee802154_nl_disassoc_indic(struct net_device *dev,
155 struct ieee802154_addr *addr, u8 reason)
156{
157 struct sk_buff *msg;
158
159 pr_debug("%s\n", __func__);
160
161 msg = ieee802154_nl_create(0, IEEE802154_DISASSOCIATE_INDIC);
162 if (!msg)
163 return -ENOBUFS;
164
165 NLA_PUT_STRING(msg, IEEE802154_ATTR_DEV_NAME, dev->name);
166 NLA_PUT_U32(msg, IEEE802154_ATTR_DEV_INDEX, dev->ifindex);
167 NLA_PUT(msg, IEEE802154_ATTR_HW_ADDR, IEEE802154_ADDR_LEN,
168 dev->dev_addr);
169
170 if (addr->addr_type == IEEE802154_ADDR_LONG)
171 NLA_PUT(msg, IEEE802154_ATTR_SRC_HW_ADDR, IEEE802154_ADDR_LEN,
172 addr->hwaddr);
173 else
174 NLA_PUT_U16(msg, IEEE802154_ATTR_SRC_SHORT_ADDR,
175 addr->short_addr);
176
177 NLA_PUT_U8(msg, IEEE802154_ATTR_REASON, reason);
178
179 return ieee802154_nl_finish(msg);
180
181nla_put_failure:
182 nlmsg_free(msg);
183 return -ENOBUFS;
184}
185EXPORT_SYMBOL(ieee802154_nl_disassoc_indic);
186
187int ieee802154_nl_disassoc_confirm(struct net_device *dev, u8 status)
188{
189 struct sk_buff *msg;
190
191 pr_debug("%s\n", __func__);
192
193 msg = ieee802154_nl_create(0, IEEE802154_DISASSOCIATE_CONF);
194 if (!msg)
195 return -ENOBUFS;
196
197 NLA_PUT_STRING(msg, IEEE802154_ATTR_DEV_NAME, dev->name);
198 NLA_PUT_U32(msg, IEEE802154_ATTR_DEV_INDEX, dev->ifindex);
199 NLA_PUT(msg, IEEE802154_ATTR_HW_ADDR, IEEE802154_ADDR_LEN,
200 dev->dev_addr);
201
202 NLA_PUT_U8(msg, IEEE802154_ATTR_STATUS, status);
203
204 return ieee802154_nl_finish(msg);
205
206nla_put_failure:
207 nlmsg_free(msg);
208 return -ENOBUFS;
209}
210EXPORT_SYMBOL(ieee802154_nl_disassoc_confirm);
211
212int ieee802154_nl_beacon_indic(struct net_device *dev,
213 u16 panid, u16 coord_addr)
214{
215 struct sk_buff *msg;
216
217 pr_debug("%s\n", __func__);
218
219 msg = ieee802154_nl_create(0, IEEE802154_BEACON_NOTIFY_INDIC);
220 if (!msg)
221 return -ENOBUFS;
222
223 NLA_PUT_STRING(msg, IEEE802154_ATTR_DEV_NAME, dev->name);
224 NLA_PUT_U32(msg, IEEE802154_ATTR_DEV_INDEX, dev->ifindex);
225 NLA_PUT(msg, IEEE802154_ATTR_HW_ADDR, IEEE802154_ADDR_LEN,
226 dev->dev_addr);
227 NLA_PUT_U16(msg, IEEE802154_ATTR_COORD_SHORT_ADDR, coord_addr);
228 NLA_PUT_U16(msg, IEEE802154_ATTR_COORD_PAN_ID, panid);
229
230 return ieee802154_nl_finish(msg);
231
232nla_put_failure:
233 nlmsg_free(msg);
234 return -ENOBUFS;
235}
236EXPORT_SYMBOL(ieee802154_nl_beacon_indic);
237
238int ieee802154_nl_scan_confirm(struct net_device *dev,
239 u8 status, u8 scan_type, u32 unscanned, u8 page,
240 u8 *edl/* , struct list_head *pan_desc_list */)
241{
242 struct sk_buff *msg;
243
244 pr_debug("%s\n", __func__);
245
246 msg = ieee802154_nl_create(0, IEEE802154_SCAN_CONF);
247 if (!msg)
248 return -ENOBUFS;
249
250 NLA_PUT_STRING(msg, IEEE802154_ATTR_DEV_NAME, dev->name);
251 NLA_PUT_U32(msg, IEEE802154_ATTR_DEV_INDEX, dev->ifindex);
252 NLA_PUT(msg, IEEE802154_ATTR_HW_ADDR, IEEE802154_ADDR_LEN,
253 dev->dev_addr);
254
255 NLA_PUT_U8(msg, IEEE802154_ATTR_STATUS, status);
256 NLA_PUT_U8(msg, IEEE802154_ATTR_SCAN_TYPE, scan_type);
257 NLA_PUT_U32(msg, IEEE802154_ATTR_CHANNELS, unscanned);
258 NLA_PUT_U8(msg, IEEE802154_ATTR_PAGE, page);
259
260 if (edl)
261 NLA_PUT(msg, IEEE802154_ATTR_ED_LIST, 27, edl);
262
263 return ieee802154_nl_finish(msg);
264
265nla_put_failure:
266 nlmsg_free(msg);
267 return -ENOBUFS;
268}
269EXPORT_SYMBOL(ieee802154_nl_scan_confirm);
270
271int ieee802154_nl_start_confirm(struct net_device *dev, u8 status)
272{
273 struct sk_buff *msg;
274
275 pr_debug("%s\n", __func__);
276
277 msg = ieee802154_nl_create(0, IEEE802154_START_CONF);
278 if (!msg)
279 return -ENOBUFS;
280
281 NLA_PUT_STRING(msg, IEEE802154_ATTR_DEV_NAME, dev->name);
282 NLA_PUT_U32(msg, IEEE802154_ATTR_DEV_INDEX, dev->ifindex);
283 NLA_PUT(msg, IEEE802154_ATTR_HW_ADDR, IEEE802154_ADDR_LEN,
284 dev->dev_addr);
285
286 NLA_PUT_U8(msg, IEEE802154_ATTR_STATUS, status);
287
288 return ieee802154_nl_finish(msg);
289
290nla_put_failure:
291 nlmsg_free(msg);
292 return -ENOBUFS;
293}
294EXPORT_SYMBOL(ieee802154_nl_start_confirm);
295
296static int ieee802154_nl_fill_iface(struct sk_buff *msg, u32 pid,
297 u32 seq, int flags, struct net_device *dev)
298{ 81{
299 void *hdr; 82 void *hdr;
83 struct sk_buff *msg = nlmsg_new(NLMSG_GOODSIZE, GFP_ATOMIC);
300 84
301 pr_debug("%s\n", __func__); 85 if (!msg)
302
303 hdr = genlmsg_put(msg, 0, seq, &ieee802154_coordinator_family, flags,
304 IEEE802154_LIST_IFACE);
305 if (!hdr)
306 goto out;
307
308 NLA_PUT_STRING(msg, IEEE802154_ATTR_DEV_NAME, dev->name);
309 NLA_PUT_U32(msg, IEEE802154_ATTR_DEV_INDEX, dev->ifindex);
310
311 NLA_PUT(msg, IEEE802154_ATTR_HW_ADDR, IEEE802154_ADDR_LEN,
312 dev->dev_addr);
313 NLA_PUT_U16(msg, IEEE802154_ATTR_SHORT_ADDR,
314 ieee802154_mlme_ops(dev)->get_short_addr(dev));
315 NLA_PUT_U16(msg, IEEE802154_ATTR_PAN_ID,
316 ieee802154_mlme_ops(dev)->get_pan_id(dev));
317 return genlmsg_end(msg, hdr);
318
319nla_put_failure:
320 genlmsg_cancel(msg, hdr);
321out:
322 return -EMSGSIZE;
323}
324
325/* Requests from userspace */
326static struct net_device *ieee802154_nl_get_dev(struct genl_info *info)
327{
328 struct net_device *dev;
329
330 if (info->attrs[IEEE802154_ATTR_DEV_NAME]) {
331 char name[IFNAMSIZ + 1];
332 nla_strlcpy(name, info->attrs[IEEE802154_ATTR_DEV_NAME],
333 sizeof(name));
334 dev = dev_get_by_name(&init_net, name);
335 } else if (info->attrs[IEEE802154_ATTR_DEV_INDEX])
336 dev = dev_get_by_index(&init_net,
337 nla_get_u32(info->attrs[IEEE802154_ATTR_DEV_INDEX]));
338 else
339 return NULL;
340
341 if (!dev)
342 return NULL; 86 return NULL;
343 87
344 if (dev->type != ARPHRD_IEEE802154) { 88 hdr = genlmsg_put_reply(msg, info,
345 dev_put(dev); 89 &nl802154_family, flags, req);
90 if (!hdr) {
91 nlmsg_free(msg);
346 return NULL; 92 return NULL;
347 } 93 }
348 94
349 return dev; 95 return msg;
350}
351
352static int ieee802154_associate_req(struct sk_buff *skb,
353 struct genl_info *info)
354{
355 struct net_device *dev;
356 struct ieee802154_addr addr;
357 u8 page;
358 int ret = -EINVAL;
359
360 if (!info->attrs[IEEE802154_ATTR_CHANNEL] ||
361 !info->attrs[IEEE802154_ATTR_COORD_PAN_ID] ||
362 (!info->attrs[IEEE802154_ATTR_COORD_HW_ADDR] &&
363 !info->attrs[IEEE802154_ATTR_COORD_SHORT_ADDR]) ||
364 !info->attrs[IEEE802154_ATTR_CAPABILITY])
365 return -EINVAL;
366
367 dev = ieee802154_nl_get_dev(info);
368 if (!dev)
369 return -ENODEV;
370
371 if (info->attrs[IEEE802154_ATTR_COORD_HW_ADDR]) {
372 addr.addr_type = IEEE802154_ADDR_LONG;
373 nla_memcpy(addr.hwaddr,
374 info->attrs[IEEE802154_ATTR_COORD_HW_ADDR],
375 IEEE802154_ADDR_LEN);
376 } else {
377 addr.addr_type = IEEE802154_ADDR_SHORT;
378 addr.short_addr = nla_get_u16(
379 info->attrs[IEEE802154_ATTR_COORD_SHORT_ADDR]);
380 }
381 addr.pan_id = nla_get_u16(info->attrs[IEEE802154_ATTR_COORD_PAN_ID]);
382
383 if (info->attrs[IEEE802154_ATTR_PAGE])
384 page = nla_get_u8(info->attrs[IEEE802154_ATTR_PAGE]);
385 else
386 page = 0;
387
388 ret = ieee802154_mlme_ops(dev)->assoc_req(dev, &addr,
389 nla_get_u8(info->attrs[IEEE802154_ATTR_CHANNEL]),
390 page,
391 nla_get_u8(info->attrs[IEEE802154_ATTR_CAPABILITY]));
392
393 dev_put(dev);
394 return ret;
395}
396
397static int ieee802154_associate_resp(struct sk_buff *skb,
398 struct genl_info *info)
399{
400 struct net_device *dev;
401 struct ieee802154_addr addr;
402 int ret = -EINVAL;
403
404 if (!info->attrs[IEEE802154_ATTR_STATUS] ||
405 !info->attrs[IEEE802154_ATTR_DEST_HW_ADDR] ||
406 !info->attrs[IEEE802154_ATTR_DEST_SHORT_ADDR])
407 return -EINVAL;
408
409 dev = ieee802154_nl_get_dev(info);
410 if (!dev)
411 return -ENODEV;
412
413 addr.addr_type = IEEE802154_ADDR_LONG;
414 nla_memcpy(addr.hwaddr, info->attrs[IEEE802154_ATTR_DEST_HW_ADDR],
415 IEEE802154_ADDR_LEN);
416 addr.pan_id = ieee802154_mlme_ops(dev)->get_pan_id(dev);
417
418
419 ret = ieee802154_mlme_ops(dev)->assoc_resp(dev, &addr,
420 nla_get_u16(info->attrs[IEEE802154_ATTR_DEST_SHORT_ADDR]),
421 nla_get_u8(info->attrs[IEEE802154_ATTR_STATUS]));
422
423 dev_put(dev);
424 return ret;
425}
426
427static int ieee802154_disassociate_req(struct sk_buff *skb,
428 struct genl_info *info)
429{
430 struct net_device *dev;
431 struct ieee802154_addr addr;
432 int ret = -EINVAL;
433
434 if ((!info->attrs[IEEE802154_ATTR_DEST_HW_ADDR] &&
435 !info->attrs[IEEE802154_ATTR_DEST_SHORT_ADDR]) ||
436 !info->attrs[IEEE802154_ATTR_REASON])
437 return -EINVAL;
438
439 dev = ieee802154_nl_get_dev(info);
440 if (!dev)
441 return -ENODEV;
442
443 if (info->attrs[IEEE802154_ATTR_DEST_HW_ADDR]) {
444 addr.addr_type = IEEE802154_ADDR_LONG;
445 nla_memcpy(addr.hwaddr,
446 info->attrs[IEEE802154_ATTR_DEST_HW_ADDR],
447 IEEE802154_ADDR_LEN);
448 } else {
449 addr.addr_type = IEEE802154_ADDR_SHORT;
450 addr.short_addr = nla_get_u16(
451 info->attrs[IEEE802154_ATTR_DEST_SHORT_ADDR]);
452 }
453 addr.pan_id = ieee802154_mlme_ops(dev)->get_pan_id(dev);
454
455 ret = ieee802154_mlme_ops(dev)->disassoc_req(dev, &addr,
456 nla_get_u8(info->attrs[IEEE802154_ATTR_REASON]));
457
458 dev_put(dev);
459 return ret;
460}
461
462/*
463 * PANid, channel, beacon_order = 15, superframe_order = 15,
464 * PAN_coordinator, battery_life_extension = 0,
465 * coord_realignment = 0, security_enable = 0
466*/
467static int ieee802154_start_req(struct sk_buff *skb, struct genl_info *info)
468{
469 struct net_device *dev;
470 struct ieee802154_addr addr;
471
472 u8 channel, bcn_ord, sf_ord;
473 u8 page;
474 int pan_coord, blx, coord_realign;
475 int ret;
476
477 if (!info->attrs[IEEE802154_ATTR_COORD_PAN_ID] ||
478 !info->attrs[IEEE802154_ATTR_COORD_SHORT_ADDR] ||
479 !info->attrs[IEEE802154_ATTR_CHANNEL] ||
480 !info->attrs[IEEE802154_ATTR_BCN_ORD] ||
481 !info->attrs[IEEE802154_ATTR_SF_ORD] ||
482 !info->attrs[IEEE802154_ATTR_PAN_COORD] ||
483 !info->attrs[IEEE802154_ATTR_BAT_EXT] ||
484 !info->attrs[IEEE802154_ATTR_COORD_REALIGN]
485 )
486 return -EINVAL;
487
488 dev = ieee802154_nl_get_dev(info);
489 if (!dev)
490 return -ENODEV;
491
492 addr.addr_type = IEEE802154_ADDR_SHORT;
493 addr.short_addr = nla_get_u16(
494 info->attrs[IEEE802154_ATTR_COORD_SHORT_ADDR]);
495 addr.pan_id = nla_get_u16(info->attrs[IEEE802154_ATTR_COORD_PAN_ID]);
496
497 channel = nla_get_u8(info->attrs[IEEE802154_ATTR_CHANNEL]);
498 bcn_ord = nla_get_u8(info->attrs[IEEE802154_ATTR_BCN_ORD]);
499 sf_ord = nla_get_u8(info->attrs[IEEE802154_ATTR_SF_ORD]);
500 pan_coord = nla_get_u8(info->attrs[IEEE802154_ATTR_PAN_COORD]);
501 blx = nla_get_u8(info->attrs[IEEE802154_ATTR_BAT_EXT]);
502 coord_realign = nla_get_u8(info->attrs[IEEE802154_ATTR_COORD_REALIGN]);
503
504 if (info->attrs[IEEE802154_ATTR_PAGE])
505 page = nla_get_u8(info->attrs[IEEE802154_ATTR_PAGE]);
506 else
507 page = 0;
508
509
510 if (addr.short_addr == IEEE802154_ADDR_BROADCAST) {
511 ieee802154_nl_start_confirm(dev, IEEE802154_NO_SHORT_ADDRESS);
512 dev_put(dev);
513 return -EINVAL;
514 }
515
516 ret = ieee802154_mlme_ops(dev)->start_req(dev, &addr, channel, page,
517 bcn_ord, sf_ord, pan_coord, blx, coord_realign);
518
519 dev_put(dev);
520 return ret;
521}
522
523static int ieee802154_scan_req(struct sk_buff *skb, struct genl_info *info)
524{
525 struct net_device *dev;
526 int ret;
527 u8 type;
528 u32 channels;
529 u8 duration;
530 u8 page;
531
532 if (!info->attrs[IEEE802154_ATTR_SCAN_TYPE] ||
533 !info->attrs[IEEE802154_ATTR_CHANNELS] ||
534 !info->attrs[IEEE802154_ATTR_DURATION])
535 return -EINVAL;
536
537 dev = ieee802154_nl_get_dev(info);
538 if (!dev)
539 return -ENODEV;
540
541 type = nla_get_u8(info->attrs[IEEE802154_ATTR_SCAN_TYPE]);
542 channels = nla_get_u32(info->attrs[IEEE802154_ATTR_CHANNELS]);
543 duration = nla_get_u8(info->attrs[IEEE802154_ATTR_DURATION]);
544
545 if (info->attrs[IEEE802154_ATTR_PAGE])
546 page = nla_get_u8(info->attrs[IEEE802154_ATTR_PAGE]);
547 else
548 page = 0;
549
550
551 ret = ieee802154_mlme_ops(dev)->scan_req(dev, type, channels, page,
552 duration);
553
554 dev_put(dev);
555 return ret;
556} 96}
557 97
558static int ieee802154_list_iface(struct sk_buff *skb, 98int ieee802154_nl_reply(struct sk_buff *msg, struct genl_info *info)
559 struct genl_info *info)
560{ 99{
561 /* Request for interface name, index, type, IEEE address, 100 /* XXX: nlh is right at the start of msg */
562 PAN Id, short address */ 101 void *hdr = genlmsg_data(NLMSG_DATA(msg->data));
563 struct sk_buff *msg;
564 struct net_device *dev = NULL;
565 int rc = -ENOBUFS;
566
567 pr_debug("%s\n", __func__);
568
569 dev = ieee802154_nl_get_dev(info);
570 if (!dev)
571 return -ENODEV;
572
573 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
574 if (!msg)
575 goto out_dev;
576
577 rc = ieee802154_nl_fill_iface(msg, info->snd_pid, info->snd_seq,
578 0, dev);
579 if (rc < 0)
580 goto out_free;
581 102
582 dev_put(dev); 103 if (genlmsg_end(msg, hdr) < 0)
104 goto out;
583 105
584 return genlmsg_unicast(&init_net, msg, info->snd_pid); 106 return genlmsg_reply(msg, info);
585out_free: 107out:
586 nlmsg_free(msg); 108 nlmsg_free(msg);
587out_dev: 109 return -ENOBUFS;
588 dev_put(dev);
589 return rc;
590
591}
592
593static int ieee802154_dump_iface(struct sk_buff *skb,
594 struct netlink_callback *cb)
595{
596 struct net *net = sock_net(skb->sk);
597 struct net_device *dev;
598 int idx;
599 int s_idx = cb->args[0];
600
601 pr_debug("%s\n", __func__);
602
603 idx = 0;
604 for_each_netdev(net, dev) {
605 if (idx < s_idx || (dev->type != ARPHRD_IEEE802154))
606 goto cont;
607
608 if (ieee802154_nl_fill_iface(skb, NETLINK_CB(cb->skb).pid,
609 cb->nlh->nlmsg_seq, NLM_F_MULTI, dev) < 0)
610 break;
611cont:
612 idx++;
613 }
614 cb->args[0] = idx;
615
616 return skb->len;
617} 110}
618 111
619#define IEEE802154_OP(_cmd, _func) \ 112int __init ieee802154_nl_init(void)
620 { \
621 .cmd = _cmd, \
622 .policy = ieee802154_policy, \
623 .doit = _func, \
624 .dumpit = NULL, \
625 .flags = GENL_ADMIN_PERM, \
626 }
627
628#define IEEE802154_DUMP(_cmd, _func, _dump) \
629 { \
630 .cmd = _cmd, \
631 .policy = ieee802154_policy, \
632 .doit = _func, \
633 .dumpit = _dump, \
634 }
635
636static struct genl_ops ieee802154_coordinator_ops[] = {
637 IEEE802154_OP(IEEE802154_ASSOCIATE_REQ, ieee802154_associate_req),
638 IEEE802154_OP(IEEE802154_ASSOCIATE_RESP, ieee802154_associate_resp),
639 IEEE802154_OP(IEEE802154_DISASSOCIATE_REQ, ieee802154_disassociate_req),
640 IEEE802154_OP(IEEE802154_SCAN_REQ, ieee802154_scan_req),
641 IEEE802154_OP(IEEE802154_START_REQ, ieee802154_start_req),
642 IEEE802154_DUMP(IEEE802154_LIST_IFACE, ieee802154_list_iface,
643 ieee802154_dump_iface),
644};
645
646static int __init ieee802154_nl_init(void)
647{ 113{
648 int rc; 114 int rc;
649 int i;
650 115
651 rc = genl_register_family(&ieee802154_coordinator_family); 116 rc = genl_register_family(&nl802154_family);
652 if (rc) 117 if (rc)
653 goto fail; 118 goto fail;
654 119
655 rc = genl_register_mc_group(&ieee802154_coordinator_family, 120 rc = nl802154_mac_register();
656 &ieee802154_coord_mcgrp);
657 if (rc) 121 if (rc)
658 goto fail; 122 goto fail;
659 123
660 rc = genl_register_mc_group(&ieee802154_coordinator_family, 124 rc = nl802154_phy_register();
661 &ieee802154_beacon_mcgrp);
662 if (rc) 125 if (rc)
663 goto fail; 126 goto fail;
664 127
665
666 for (i = 0; i < ARRAY_SIZE(ieee802154_coordinator_ops); i++) {
667 rc = genl_register_ops(&ieee802154_coordinator_family,
668 &ieee802154_coordinator_ops[i]);
669 if (rc)
670 goto fail;
671 }
672
673 return 0; 128 return 0;
674 129
675fail: 130fail:
676 genl_unregister_family(&ieee802154_coordinator_family); 131 genl_unregister_family(&nl802154_family);
677 return rc; 132 return rc;
678} 133}
679module_init(ieee802154_nl_init);
680 134
681static void __exit ieee802154_nl_exit(void) 135void __exit ieee802154_nl_exit(void)
682{ 136{
683 genl_unregister_family(&ieee802154_coordinator_family); 137 genl_unregister_family(&nl802154_family);
684} 138}
685module_exit(ieee802154_nl_exit);
686
687MODULE_LICENSE("GPL v2");
688MODULE_DESCRIPTION("ieee 802.15.4 configuration interface");
689 139
diff --git a/net/ieee802154/nl-mac.c b/net/ieee802154/nl-mac.c
new file mode 100644
index 000000000000..71ee1108d4f8
--- /dev/null
+++ b/net/ieee802154/nl-mac.c
@@ -0,0 +1,618 @@
1/*
2 * Netlink inteface for IEEE 802.15.4 stack
3 *
4 * Copyright 2007, 2008 Siemens AG
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2
8 * as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Written by:
20 * Sergey Lapin <slapin@ossfans.org>
21 * Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
22 * Maxim Osipov <maxim.osipov@siemens.com>
23 */
24
25#include <linux/gfp.h>
26#include <linux/kernel.h>
27#include <linux/if_arp.h>
28#include <linux/netdevice.h>
29#include <net/netlink.h>
30#include <net/genetlink.h>
31#include <net/sock.h>
32#include <linux/nl802154.h>
33#include <net/af_ieee802154.h>
34#include <net/nl802154.h>
35#include <net/ieee802154.h>
36#include <net/ieee802154_netdev.h>
37#include <net/wpan-phy.h>
38
39#include "ieee802154.h"
40
41static struct genl_multicast_group ieee802154_coord_mcgrp = {
42 .name = IEEE802154_MCAST_COORD_NAME,
43};
44
45static struct genl_multicast_group ieee802154_beacon_mcgrp = {
46 .name = IEEE802154_MCAST_BEACON_NAME,
47};
48
49int ieee802154_nl_assoc_indic(struct net_device *dev,
50 struct ieee802154_addr *addr, u8 cap)
51{
52 struct sk_buff *msg;
53
54 pr_debug("%s\n", __func__);
55
56 if (addr->addr_type != IEEE802154_ADDR_LONG) {
57 pr_err("%s: received non-long source address!\n", __func__);
58 return -EINVAL;
59 }
60
61 msg = ieee802154_nl_create(0, IEEE802154_ASSOCIATE_INDIC);
62 if (!msg)
63 return -ENOBUFS;
64
65 NLA_PUT_STRING(msg, IEEE802154_ATTR_DEV_NAME, dev->name);
66 NLA_PUT_U32(msg, IEEE802154_ATTR_DEV_INDEX, dev->ifindex);
67 NLA_PUT(msg, IEEE802154_ATTR_HW_ADDR, IEEE802154_ADDR_LEN,
68 dev->dev_addr);
69
70 NLA_PUT(msg, IEEE802154_ATTR_SRC_HW_ADDR, IEEE802154_ADDR_LEN,
71 addr->hwaddr);
72
73 NLA_PUT_U8(msg, IEEE802154_ATTR_CAPABILITY, cap);
74
75 return ieee802154_nl_mcast(msg, ieee802154_coord_mcgrp.id);
76
77nla_put_failure:
78 nlmsg_free(msg);
79 return -ENOBUFS;
80}
81EXPORT_SYMBOL(ieee802154_nl_assoc_indic);
82
83int ieee802154_nl_assoc_confirm(struct net_device *dev, u16 short_addr,
84 u8 status)
85{
86 struct sk_buff *msg;
87
88 pr_debug("%s\n", __func__);
89
90 msg = ieee802154_nl_create(0, IEEE802154_ASSOCIATE_CONF);
91 if (!msg)
92 return -ENOBUFS;
93
94 NLA_PUT_STRING(msg, IEEE802154_ATTR_DEV_NAME, dev->name);
95 NLA_PUT_U32(msg, IEEE802154_ATTR_DEV_INDEX, dev->ifindex);
96 NLA_PUT(msg, IEEE802154_ATTR_HW_ADDR, IEEE802154_ADDR_LEN,
97 dev->dev_addr);
98
99 NLA_PUT_U16(msg, IEEE802154_ATTR_SHORT_ADDR, short_addr);
100 NLA_PUT_U8(msg, IEEE802154_ATTR_STATUS, status);
101
102 return ieee802154_nl_mcast(msg, ieee802154_coord_mcgrp.id);
103
104nla_put_failure:
105 nlmsg_free(msg);
106 return -ENOBUFS;
107}
108EXPORT_SYMBOL(ieee802154_nl_assoc_confirm);
109
110int ieee802154_nl_disassoc_indic(struct net_device *dev,
111 struct ieee802154_addr *addr, u8 reason)
112{
113 struct sk_buff *msg;
114
115 pr_debug("%s\n", __func__);
116
117 msg = ieee802154_nl_create(0, IEEE802154_DISASSOCIATE_INDIC);
118 if (!msg)
119 return -ENOBUFS;
120
121 NLA_PUT_STRING(msg, IEEE802154_ATTR_DEV_NAME, dev->name);
122 NLA_PUT_U32(msg, IEEE802154_ATTR_DEV_INDEX, dev->ifindex);
123 NLA_PUT(msg, IEEE802154_ATTR_HW_ADDR, IEEE802154_ADDR_LEN,
124 dev->dev_addr);
125
126 if (addr->addr_type == IEEE802154_ADDR_LONG)
127 NLA_PUT(msg, IEEE802154_ATTR_SRC_HW_ADDR, IEEE802154_ADDR_LEN,
128 addr->hwaddr);
129 else
130 NLA_PUT_U16(msg, IEEE802154_ATTR_SRC_SHORT_ADDR,
131 addr->short_addr);
132
133 NLA_PUT_U8(msg, IEEE802154_ATTR_REASON, reason);
134
135 return ieee802154_nl_mcast(msg, ieee802154_coord_mcgrp.id);
136
137nla_put_failure:
138 nlmsg_free(msg);
139 return -ENOBUFS;
140}
141EXPORT_SYMBOL(ieee802154_nl_disassoc_indic);
142
143int ieee802154_nl_disassoc_confirm(struct net_device *dev, u8 status)
144{
145 struct sk_buff *msg;
146
147 pr_debug("%s\n", __func__);
148
149 msg = ieee802154_nl_create(0, IEEE802154_DISASSOCIATE_CONF);
150 if (!msg)
151 return -ENOBUFS;
152
153 NLA_PUT_STRING(msg, IEEE802154_ATTR_DEV_NAME, dev->name);
154 NLA_PUT_U32(msg, IEEE802154_ATTR_DEV_INDEX, dev->ifindex);
155 NLA_PUT(msg, IEEE802154_ATTR_HW_ADDR, IEEE802154_ADDR_LEN,
156 dev->dev_addr);
157
158 NLA_PUT_U8(msg, IEEE802154_ATTR_STATUS, status);
159
160 return ieee802154_nl_mcast(msg, ieee802154_coord_mcgrp.id);
161
162nla_put_failure:
163 nlmsg_free(msg);
164 return -ENOBUFS;
165}
166EXPORT_SYMBOL(ieee802154_nl_disassoc_confirm);
167
168int ieee802154_nl_beacon_indic(struct net_device *dev,
169 u16 panid, u16 coord_addr)
170{
171 struct sk_buff *msg;
172
173 pr_debug("%s\n", __func__);
174
175 msg = ieee802154_nl_create(0, IEEE802154_BEACON_NOTIFY_INDIC);
176 if (!msg)
177 return -ENOBUFS;
178
179 NLA_PUT_STRING(msg, IEEE802154_ATTR_DEV_NAME, dev->name);
180 NLA_PUT_U32(msg, IEEE802154_ATTR_DEV_INDEX, dev->ifindex);
181 NLA_PUT(msg, IEEE802154_ATTR_HW_ADDR, IEEE802154_ADDR_LEN,
182 dev->dev_addr);
183 NLA_PUT_U16(msg, IEEE802154_ATTR_COORD_SHORT_ADDR, coord_addr);
184 NLA_PUT_U16(msg, IEEE802154_ATTR_COORD_PAN_ID, panid);
185
186 return ieee802154_nl_mcast(msg, ieee802154_coord_mcgrp.id);
187
188nla_put_failure:
189 nlmsg_free(msg);
190 return -ENOBUFS;
191}
192EXPORT_SYMBOL(ieee802154_nl_beacon_indic);
193
194int ieee802154_nl_scan_confirm(struct net_device *dev,
195 u8 status, u8 scan_type, u32 unscanned, u8 page,
196 u8 *edl/* , struct list_head *pan_desc_list */)
197{
198 struct sk_buff *msg;
199
200 pr_debug("%s\n", __func__);
201
202 msg = ieee802154_nl_create(0, IEEE802154_SCAN_CONF);
203 if (!msg)
204 return -ENOBUFS;
205
206 NLA_PUT_STRING(msg, IEEE802154_ATTR_DEV_NAME, dev->name);
207 NLA_PUT_U32(msg, IEEE802154_ATTR_DEV_INDEX, dev->ifindex);
208 NLA_PUT(msg, IEEE802154_ATTR_HW_ADDR, IEEE802154_ADDR_LEN,
209 dev->dev_addr);
210
211 NLA_PUT_U8(msg, IEEE802154_ATTR_STATUS, status);
212 NLA_PUT_U8(msg, IEEE802154_ATTR_SCAN_TYPE, scan_type);
213 NLA_PUT_U32(msg, IEEE802154_ATTR_CHANNELS, unscanned);
214 NLA_PUT_U8(msg, IEEE802154_ATTR_PAGE, page);
215
216 if (edl)
217 NLA_PUT(msg, IEEE802154_ATTR_ED_LIST, 27, edl);
218
219 return ieee802154_nl_mcast(msg, ieee802154_coord_mcgrp.id);
220
221nla_put_failure:
222 nlmsg_free(msg);
223 return -ENOBUFS;
224}
225EXPORT_SYMBOL(ieee802154_nl_scan_confirm);
226
227int ieee802154_nl_start_confirm(struct net_device *dev, u8 status)
228{
229 struct sk_buff *msg;
230
231 pr_debug("%s\n", __func__);
232
233 msg = ieee802154_nl_create(0, IEEE802154_START_CONF);
234 if (!msg)
235 return -ENOBUFS;
236
237 NLA_PUT_STRING(msg, IEEE802154_ATTR_DEV_NAME, dev->name);
238 NLA_PUT_U32(msg, IEEE802154_ATTR_DEV_INDEX, dev->ifindex);
239 NLA_PUT(msg, IEEE802154_ATTR_HW_ADDR, IEEE802154_ADDR_LEN,
240 dev->dev_addr);
241
242 NLA_PUT_U8(msg, IEEE802154_ATTR_STATUS, status);
243
244 return ieee802154_nl_mcast(msg, ieee802154_coord_mcgrp.id);
245
246nla_put_failure:
247 nlmsg_free(msg);
248 return -ENOBUFS;
249}
250EXPORT_SYMBOL(ieee802154_nl_start_confirm);
251
252static int ieee802154_nl_fill_iface(struct sk_buff *msg, u32 pid,
253 u32 seq, int flags, struct net_device *dev)
254{
255 void *hdr;
256 struct wpan_phy *phy;
257
258 pr_debug("%s\n", __func__);
259
260 hdr = genlmsg_put(msg, 0, seq, &nl802154_family, flags,
261 IEEE802154_LIST_IFACE);
262 if (!hdr)
263 goto out;
264
265 phy = ieee802154_mlme_ops(dev)->get_phy(dev);
266 BUG_ON(!phy);
267
268 NLA_PUT_STRING(msg, IEEE802154_ATTR_DEV_NAME, dev->name);
269 NLA_PUT_STRING(msg, IEEE802154_ATTR_PHY_NAME, wpan_phy_name(phy));
270 NLA_PUT_U32(msg, IEEE802154_ATTR_DEV_INDEX, dev->ifindex);
271
272 NLA_PUT(msg, IEEE802154_ATTR_HW_ADDR, IEEE802154_ADDR_LEN,
273 dev->dev_addr);
274 NLA_PUT_U16(msg, IEEE802154_ATTR_SHORT_ADDR,
275 ieee802154_mlme_ops(dev)->get_short_addr(dev));
276 NLA_PUT_U16(msg, IEEE802154_ATTR_PAN_ID,
277 ieee802154_mlme_ops(dev)->get_pan_id(dev));
278 wpan_phy_put(phy);
279 return genlmsg_end(msg, hdr);
280
281nla_put_failure:
282 wpan_phy_put(phy);
283 genlmsg_cancel(msg, hdr);
284out:
285 return -EMSGSIZE;
286}
287
288/* Requests from userspace */
289static struct net_device *ieee802154_nl_get_dev(struct genl_info *info)
290{
291 struct net_device *dev;
292
293 if (info->attrs[IEEE802154_ATTR_DEV_NAME]) {
294 char name[IFNAMSIZ + 1];
295 nla_strlcpy(name, info->attrs[IEEE802154_ATTR_DEV_NAME],
296 sizeof(name));
297 dev = dev_get_by_name(&init_net, name);
298 } else if (info->attrs[IEEE802154_ATTR_DEV_INDEX])
299 dev = dev_get_by_index(&init_net,
300 nla_get_u32(info->attrs[IEEE802154_ATTR_DEV_INDEX]));
301 else
302 return NULL;
303
304 if (!dev)
305 return NULL;
306
307 if (dev->type != ARPHRD_IEEE802154) {
308 dev_put(dev);
309 return NULL;
310 }
311
312 return dev;
313}
314
315static int ieee802154_associate_req(struct sk_buff *skb,
316 struct genl_info *info)
317{
318 struct net_device *dev;
319 struct ieee802154_addr addr;
320 u8 page;
321 int ret = -EINVAL;
322
323 if (!info->attrs[IEEE802154_ATTR_CHANNEL] ||
324 !info->attrs[IEEE802154_ATTR_COORD_PAN_ID] ||
325 (!info->attrs[IEEE802154_ATTR_COORD_HW_ADDR] &&
326 !info->attrs[IEEE802154_ATTR_COORD_SHORT_ADDR]) ||
327 !info->attrs[IEEE802154_ATTR_CAPABILITY])
328 return -EINVAL;
329
330 dev = ieee802154_nl_get_dev(info);
331 if (!dev)
332 return -ENODEV;
333
334 if (info->attrs[IEEE802154_ATTR_COORD_HW_ADDR]) {
335 addr.addr_type = IEEE802154_ADDR_LONG;
336 nla_memcpy(addr.hwaddr,
337 info->attrs[IEEE802154_ATTR_COORD_HW_ADDR],
338 IEEE802154_ADDR_LEN);
339 } else {
340 addr.addr_type = IEEE802154_ADDR_SHORT;
341 addr.short_addr = nla_get_u16(
342 info->attrs[IEEE802154_ATTR_COORD_SHORT_ADDR]);
343 }
344 addr.pan_id = nla_get_u16(info->attrs[IEEE802154_ATTR_COORD_PAN_ID]);
345
346 if (info->attrs[IEEE802154_ATTR_PAGE])
347 page = nla_get_u8(info->attrs[IEEE802154_ATTR_PAGE]);
348 else
349 page = 0;
350
351 ret = ieee802154_mlme_ops(dev)->assoc_req(dev, &addr,
352 nla_get_u8(info->attrs[IEEE802154_ATTR_CHANNEL]),
353 page,
354 nla_get_u8(info->attrs[IEEE802154_ATTR_CAPABILITY]));
355
356 dev_put(dev);
357 return ret;
358}
359
360static int ieee802154_associate_resp(struct sk_buff *skb,
361 struct genl_info *info)
362{
363 struct net_device *dev;
364 struct ieee802154_addr addr;
365 int ret = -EINVAL;
366
367 if (!info->attrs[IEEE802154_ATTR_STATUS] ||
368 !info->attrs[IEEE802154_ATTR_DEST_HW_ADDR] ||
369 !info->attrs[IEEE802154_ATTR_DEST_SHORT_ADDR])
370 return -EINVAL;
371
372 dev = ieee802154_nl_get_dev(info);
373 if (!dev)
374 return -ENODEV;
375
376 addr.addr_type = IEEE802154_ADDR_LONG;
377 nla_memcpy(addr.hwaddr, info->attrs[IEEE802154_ATTR_DEST_HW_ADDR],
378 IEEE802154_ADDR_LEN);
379 addr.pan_id = ieee802154_mlme_ops(dev)->get_pan_id(dev);
380
381
382 ret = ieee802154_mlme_ops(dev)->assoc_resp(dev, &addr,
383 nla_get_u16(info->attrs[IEEE802154_ATTR_DEST_SHORT_ADDR]),
384 nla_get_u8(info->attrs[IEEE802154_ATTR_STATUS]));
385
386 dev_put(dev);
387 return ret;
388}
389
390static int ieee802154_disassociate_req(struct sk_buff *skb,
391 struct genl_info *info)
392{
393 struct net_device *dev;
394 struct ieee802154_addr addr;
395 int ret = -EINVAL;
396
397 if ((!info->attrs[IEEE802154_ATTR_DEST_HW_ADDR] &&
398 !info->attrs[IEEE802154_ATTR_DEST_SHORT_ADDR]) ||
399 !info->attrs[IEEE802154_ATTR_REASON])
400 return -EINVAL;
401
402 dev = ieee802154_nl_get_dev(info);
403 if (!dev)
404 return -ENODEV;
405
406 if (info->attrs[IEEE802154_ATTR_DEST_HW_ADDR]) {
407 addr.addr_type = IEEE802154_ADDR_LONG;
408 nla_memcpy(addr.hwaddr,
409 info->attrs[IEEE802154_ATTR_DEST_HW_ADDR],
410 IEEE802154_ADDR_LEN);
411 } else {
412 addr.addr_type = IEEE802154_ADDR_SHORT;
413 addr.short_addr = nla_get_u16(
414 info->attrs[IEEE802154_ATTR_DEST_SHORT_ADDR]);
415 }
416 addr.pan_id = ieee802154_mlme_ops(dev)->get_pan_id(dev);
417
418 ret = ieee802154_mlme_ops(dev)->disassoc_req(dev, &addr,
419 nla_get_u8(info->attrs[IEEE802154_ATTR_REASON]));
420
421 dev_put(dev);
422 return ret;
423}
424
425/*
426 * PANid, channel, beacon_order = 15, superframe_order = 15,
427 * PAN_coordinator, battery_life_extension = 0,
428 * coord_realignment = 0, security_enable = 0
429*/
430static int ieee802154_start_req(struct sk_buff *skb, struct genl_info *info)
431{
432 struct net_device *dev;
433 struct ieee802154_addr addr;
434
435 u8 channel, bcn_ord, sf_ord;
436 u8 page;
437 int pan_coord, blx, coord_realign;
438 int ret;
439
440 if (!info->attrs[IEEE802154_ATTR_COORD_PAN_ID] ||
441 !info->attrs[IEEE802154_ATTR_COORD_SHORT_ADDR] ||
442 !info->attrs[IEEE802154_ATTR_CHANNEL] ||
443 !info->attrs[IEEE802154_ATTR_BCN_ORD] ||
444 !info->attrs[IEEE802154_ATTR_SF_ORD] ||
445 !info->attrs[IEEE802154_ATTR_PAN_COORD] ||
446 !info->attrs[IEEE802154_ATTR_BAT_EXT] ||
447 !info->attrs[IEEE802154_ATTR_COORD_REALIGN]
448 )
449 return -EINVAL;
450
451 dev = ieee802154_nl_get_dev(info);
452 if (!dev)
453 return -ENODEV;
454
455 addr.addr_type = IEEE802154_ADDR_SHORT;
456 addr.short_addr = nla_get_u16(
457 info->attrs[IEEE802154_ATTR_COORD_SHORT_ADDR]);
458 addr.pan_id = nla_get_u16(info->attrs[IEEE802154_ATTR_COORD_PAN_ID]);
459
460 channel = nla_get_u8(info->attrs[IEEE802154_ATTR_CHANNEL]);
461 bcn_ord = nla_get_u8(info->attrs[IEEE802154_ATTR_BCN_ORD]);
462 sf_ord = nla_get_u8(info->attrs[IEEE802154_ATTR_SF_ORD]);
463 pan_coord = nla_get_u8(info->attrs[IEEE802154_ATTR_PAN_COORD]);
464 blx = nla_get_u8(info->attrs[IEEE802154_ATTR_BAT_EXT]);
465 coord_realign = nla_get_u8(info->attrs[IEEE802154_ATTR_COORD_REALIGN]);
466
467 if (info->attrs[IEEE802154_ATTR_PAGE])
468 page = nla_get_u8(info->attrs[IEEE802154_ATTR_PAGE]);
469 else
470 page = 0;
471
472
473 if (addr.short_addr == IEEE802154_ADDR_BROADCAST) {
474 ieee802154_nl_start_confirm(dev, IEEE802154_NO_SHORT_ADDRESS);
475 dev_put(dev);
476 return -EINVAL;
477 }
478
479 ret = ieee802154_mlme_ops(dev)->start_req(dev, &addr, channel, page,
480 bcn_ord, sf_ord, pan_coord, blx, coord_realign);
481
482 dev_put(dev);
483 return ret;
484}
485
486static int ieee802154_scan_req(struct sk_buff *skb, struct genl_info *info)
487{
488 struct net_device *dev;
489 int ret;
490 u8 type;
491 u32 channels;
492 u8 duration;
493 u8 page;
494
495 if (!info->attrs[IEEE802154_ATTR_SCAN_TYPE] ||
496 !info->attrs[IEEE802154_ATTR_CHANNELS] ||
497 !info->attrs[IEEE802154_ATTR_DURATION])
498 return -EINVAL;
499
500 dev = ieee802154_nl_get_dev(info);
501 if (!dev)
502 return -ENODEV;
503
504 type = nla_get_u8(info->attrs[IEEE802154_ATTR_SCAN_TYPE]);
505 channels = nla_get_u32(info->attrs[IEEE802154_ATTR_CHANNELS]);
506 duration = nla_get_u8(info->attrs[IEEE802154_ATTR_DURATION]);
507
508 if (info->attrs[IEEE802154_ATTR_PAGE])
509 page = nla_get_u8(info->attrs[IEEE802154_ATTR_PAGE]);
510 else
511 page = 0;
512
513
514 ret = ieee802154_mlme_ops(dev)->scan_req(dev, type, channels, page,
515 duration);
516
517 dev_put(dev);
518 return ret;
519}
520
521static int ieee802154_list_iface(struct sk_buff *skb,
522 struct genl_info *info)
523{
524 /* Request for interface name, index, type, IEEE address,
525 PAN Id, short address */
526 struct sk_buff *msg;
527 struct net_device *dev = NULL;
528 int rc = -ENOBUFS;
529
530 pr_debug("%s\n", __func__);
531
532 dev = ieee802154_nl_get_dev(info);
533 if (!dev)
534 return -ENODEV;
535
536 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
537 if (!msg)
538 goto out_dev;
539
540 rc = ieee802154_nl_fill_iface(msg, info->snd_pid, info->snd_seq,
541 0, dev);
542 if (rc < 0)
543 goto out_free;
544
545 dev_put(dev);
546
547 return genlmsg_reply(msg, info);
548out_free:
549 nlmsg_free(msg);
550out_dev:
551 dev_put(dev);
552 return rc;
553
554}
555
556static int ieee802154_dump_iface(struct sk_buff *skb,
557 struct netlink_callback *cb)
558{
559 struct net *net = sock_net(skb->sk);
560 struct net_device *dev;
561 int idx;
562 int s_idx = cb->args[0];
563
564 pr_debug("%s\n", __func__);
565
566 idx = 0;
567 for_each_netdev(net, dev) {
568 if (idx < s_idx || (dev->type != ARPHRD_IEEE802154))
569 goto cont;
570
571 if (ieee802154_nl_fill_iface(skb, NETLINK_CB(cb->skb).pid,
572 cb->nlh->nlmsg_seq, NLM_F_MULTI, dev) < 0)
573 break;
574cont:
575 idx++;
576 }
577 cb->args[0] = idx;
578
579 return skb->len;
580}
581
582static struct genl_ops ieee802154_coordinator_ops[] = {
583 IEEE802154_OP(IEEE802154_ASSOCIATE_REQ, ieee802154_associate_req),
584 IEEE802154_OP(IEEE802154_ASSOCIATE_RESP, ieee802154_associate_resp),
585 IEEE802154_OP(IEEE802154_DISASSOCIATE_REQ, ieee802154_disassociate_req),
586 IEEE802154_OP(IEEE802154_SCAN_REQ, ieee802154_scan_req),
587 IEEE802154_OP(IEEE802154_START_REQ, ieee802154_start_req),
588 IEEE802154_DUMP(IEEE802154_LIST_IFACE, ieee802154_list_iface,
589 ieee802154_dump_iface),
590};
591
592/*
593 * No need to unregister as family unregistration will do it.
594 */
595int nl802154_mac_register(void)
596{
597 int i;
598 int rc;
599
600 rc = genl_register_mc_group(&nl802154_family,
601 &ieee802154_coord_mcgrp);
602 if (rc)
603 return rc;
604
605 rc = genl_register_mc_group(&nl802154_family,
606 &ieee802154_beacon_mcgrp);
607 if (rc)
608 return rc;
609
610 for (i = 0; i < ARRAY_SIZE(ieee802154_coordinator_ops); i++) {
611 rc = genl_register_ops(&nl802154_family,
612 &ieee802154_coordinator_ops[i]);
613 if (rc)
614 return rc;
615 }
616
617 return 0;
618}
diff --git a/net/ieee802154/nl-phy.c b/net/ieee802154/nl-phy.c
new file mode 100644
index 000000000000..ed0eab39f531
--- /dev/null
+++ b/net/ieee802154/nl-phy.c
@@ -0,0 +1,345 @@
1/*
2 * Netlink inteface for IEEE 802.15.4 stack
3 *
4 * Copyright 2007, 2008 Siemens AG
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2
8 * as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Written by:
20 * Sergey Lapin <slapin@ossfans.org>
21 * Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
22 * Maxim Osipov <maxim.osipov@siemens.com>
23 */
24
25#include <linux/kernel.h>
26#include <linux/slab.h>
27#include <net/netlink.h>
28#include <net/genetlink.h>
29#include <net/wpan-phy.h>
30#include <net/af_ieee802154.h>
31#include <net/ieee802154_netdev.h>
32#include <net/rtnetlink.h> /* for rtnl_{un,}lock */
33#include <linux/nl802154.h>
34
35#include "ieee802154.h"
36
37static int ieee802154_nl_fill_phy(struct sk_buff *msg, u32 pid,
38 u32 seq, int flags, struct wpan_phy *phy)
39{
40 void *hdr;
41 int i, pages = 0;
42 uint32_t *buf = kzalloc(32 * sizeof(uint32_t), GFP_KERNEL);
43
44 pr_debug("%s\n", __func__);
45
46 if (!buf)
47 goto out;
48
49 hdr = genlmsg_put(msg, 0, seq, &nl802154_family, flags,
50 IEEE802154_LIST_PHY);
51 if (!hdr)
52 goto out;
53
54 mutex_lock(&phy->pib_lock);
55 NLA_PUT_STRING(msg, IEEE802154_ATTR_PHY_NAME, wpan_phy_name(phy));
56
57 NLA_PUT_U8(msg, IEEE802154_ATTR_PAGE, phy->current_page);
58 NLA_PUT_U8(msg, IEEE802154_ATTR_CHANNEL, phy->current_channel);
59 for (i = 0; i < 32; i++) {
60 if (phy->channels_supported[i])
61 buf[pages++] = phy->channels_supported[i] | (i << 27);
62 }
63 if (pages)
64 NLA_PUT(msg, IEEE802154_ATTR_CHANNEL_PAGE_LIST,
65 pages * sizeof(uint32_t), buf);
66
67 mutex_unlock(&phy->pib_lock);
68 return genlmsg_end(msg, hdr);
69
70nla_put_failure:
71 mutex_unlock(&phy->pib_lock);
72 genlmsg_cancel(msg, hdr);
73out:
74 kfree(buf);
75 return -EMSGSIZE;
76}
77
78static int ieee802154_list_phy(struct sk_buff *skb,
79 struct genl_info *info)
80{
81 /* Request for interface name, index, type, IEEE address,
82 PAN Id, short address */
83 struct sk_buff *msg;
84 struct wpan_phy *phy;
85 const char *name;
86 int rc = -ENOBUFS;
87
88 pr_debug("%s\n", __func__);
89
90 if (!info->attrs[IEEE802154_ATTR_PHY_NAME])
91 return -EINVAL;
92
93 name = nla_data(info->attrs[IEEE802154_ATTR_PHY_NAME]);
94 if (name[nla_len(info->attrs[IEEE802154_ATTR_PHY_NAME]) - 1] != '\0')
95 return -EINVAL; /* phy name should be null-terminated */
96
97
98 phy = wpan_phy_find(name);
99 if (!phy)
100 return -ENODEV;
101
102 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
103 if (!msg)
104 goto out_dev;
105
106 rc = ieee802154_nl_fill_phy(msg, info->snd_pid, info->snd_seq,
107 0, phy);
108 if (rc < 0)
109 goto out_free;
110
111 wpan_phy_put(phy);
112
113 return genlmsg_reply(msg, info);
114out_free:
115 nlmsg_free(msg);
116out_dev:
117 wpan_phy_put(phy);
118 return rc;
119
120}
121
122struct dump_phy_data {
123 struct sk_buff *skb;
124 struct netlink_callback *cb;
125 int idx, s_idx;
126};
127
128static int ieee802154_dump_phy_iter(struct wpan_phy *phy, void *_data)
129{
130 int rc;
131 struct dump_phy_data *data = _data;
132
133 pr_debug("%s\n", __func__);
134
135 if (data->idx++ < data->s_idx)
136 return 0;
137
138 rc = ieee802154_nl_fill_phy(data->skb,
139 NETLINK_CB(data->cb->skb).pid,
140 data->cb->nlh->nlmsg_seq,
141 NLM_F_MULTI,
142 phy);
143
144 if (rc < 0) {
145 data->idx--;
146 return rc;
147 }
148
149 return 0;
150}
151
152static int ieee802154_dump_phy(struct sk_buff *skb,
153 struct netlink_callback *cb)
154{
155 struct dump_phy_data data = {
156 .cb = cb,
157 .skb = skb,
158 .s_idx = cb->args[0],
159 .idx = 0,
160 };
161
162 pr_debug("%s\n", __func__);
163
164 wpan_phy_for_each(ieee802154_dump_phy_iter, &data);
165
166 cb->args[0] = data.idx;
167
168 return skb->len;
169}
170
171static int ieee802154_add_iface(struct sk_buff *skb,
172 struct genl_info *info)
173{
174 struct sk_buff *msg;
175 struct wpan_phy *phy;
176 const char *name;
177 const char *devname;
178 int rc = -ENOBUFS;
179 struct net_device *dev;
180
181 pr_debug("%s\n", __func__);
182
183 if (!info->attrs[IEEE802154_ATTR_PHY_NAME])
184 return -EINVAL;
185
186 name = nla_data(info->attrs[IEEE802154_ATTR_PHY_NAME]);
187 if (name[nla_len(info->attrs[IEEE802154_ATTR_PHY_NAME]) - 1] != '\0')
188 return -EINVAL; /* phy name should be null-terminated */
189
190 if (info->attrs[IEEE802154_ATTR_DEV_NAME]) {
191 devname = nla_data(info->attrs[IEEE802154_ATTR_DEV_NAME]);
192 if (devname[nla_len(info->attrs[IEEE802154_ATTR_DEV_NAME]) - 1]
193 != '\0')
194 return -EINVAL; /* phy name should be null-terminated */
195 } else {
196 devname = "wpan%d";
197 }
198
199 if (strlen(devname) >= IFNAMSIZ)
200 return -ENAMETOOLONG;
201
202 phy = wpan_phy_find(name);
203 if (!phy)
204 return -ENODEV;
205
206 msg = ieee802154_nl_new_reply(info, 0, IEEE802154_ADD_IFACE);
207 if (!msg)
208 goto out_dev;
209
210 if (!phy->add_iface) {
211 rc = -EINVAL;
212 goto nla_put_failure;
213 }
214
215 dev = phy->add_iface(phy, devname);
216 if (IS_ERR(dev)) {
217 rc = PTR_ERR(dev);
218 goto nla_put_failure;
219 }
220
221 NLA_PUT_STRING(msg, IEEE802154_ATTR_PHY_NAME, wpan_phy_name(phy));
222 NLA_PUT_STRING(msg, IEEE802154_ATTR_DEV_NAME, dev->name);
223
224 dev_put(dev);
225
226 wpan_phy_put(phy);
227
228 return ieee802154_nl_reply(msg, info);
229
230nla_put_failure:
231 nlmsg_free(msg);
232out_dev:
233 wpan_phy_put(phy);
234 return rc;
235}
236
237static int ieee802154_del_iface(struct sk_buff *skb,
238 struct genl_info *info)
239{
240 struct sk_buff *msg;
241 struct wpan_phy *phy;
242 const char *name;
243 int rc;
244 struct net_device *dev;
245
246 pr_debug("%s\n", __func__);
247
248 if (!info->attrs[IEEE802154_ATTR_DEV_NAME])
249 return -EINVAL;
250
251 name = nla_data(info->attrs[IEEE802154_ATTR_DEV_NAME]);
252 if (name[nla_len(info->attrs[IEEE802154_ATTR_DEV_NAME]) - 1] != '\0')
253 return -EINVAL; /* name should be null-terminated */
254
255 dev = dev_get_by_name(genl_info_net(info), name);
256 if (!dev)
257 return -ENODEV;
258
259 phy = ieee802154_mlme_ops(dev)->get_phy(dev);
260 BUG_ON(!phy);
261
262 rc = -EINVAL;
263 /* phy name is optional, but should be checked if it's given */
264 if (info->attrs[IEEE802154_ATTR_PHY_NAME]) {
265 struct wpan_phy *phy2;
266
267 const char *pname =
268 nla_data(info->attrs[IEEE802154_ATTR_PHY_NAME]);
269 if (pname[nla_len(info->attrs[IEEE802154_ATTR_PHY_NAME]) - 1]
270 != '\0')
271 /* name should be null-terminated */
272 goto out_dev;
273
274 phy2 = wpan_phy_find(pname);
275 if (!phy2)
276 goto out_dev;
277
278 if (phy != phy2) {
279 wpan_phy_put(phy2);
280 goto out_dev;
281 }
282 }
283
284 rc = -ENOBUFS;
285
286 msg = ieee802154_nl_new_reply(info, 0, IEEE802154_DEL_IFACE);
287 if (!msg)
288 goto out_dev;
289
290 if (!phy->del_iface) {
291 rc = -EINVAL;
292 goto nla_put_failure;
293 }
294
295 rtnl_lock();
296 phy->del_iface(phy, dev);
297
298 /* We don't have device anymore */
299 dev_put(dev);
300 dev = NULL;
301
302 rtnl_unlock();
303
304
305 NLA_PUT_STRING(msg, IEEE802154_ATTR_PHY_NAME, wpan_phy_name(phy));
306 NLA_PUT_STRING(msg, IEEE802154_ATTR_DEV_NAME, name);
307
308 wpan_phy_put(phy);
309
310 return ieee802154_nl_reply(msg, info);
311
312nla_put_failure:
313 nlmsg_free(msg);
314out_dev:
315 wpan_phy_put(phy);
316 if (dev)
317 dev_put(dev);
318
319 return rc;
320}
321
322static struct genl_ops ieee802154_phy_ops[] = {
323 IEEE802154_DUMP(IEEE802154_LIST_PHY, ieee802154_list_phy,
324 ieee802154_dump_phy),
325 IEEE802154_OP(IEEE802154_ADD_IFACE, ieee802154_add_iface),
326 IEEE802154_OP(IEEE802154_DEL_IFACE, ieee802154_del_iface),
327};
328
329/*
330 * No need to unregister as family unregistration will do it.
331 */
332int nl802154_phy_register(void)
333{
334 int i;
335 int rc;
336
337 for (i = 0; i < ARRAY_SIZE(ieee802154_phy_ops); i++) {
338 rc = genl_register_ops(&nl802154_family,
339 &ieee802154_phy_ops[i]);
340 if (rc)
341 return rc;
342 }
343
344 return 0;
345}
diff --git a/net/ieee802154/nl_policy.c b/net/ieee802154/nl_policy.c
index 2363ebee02e7..6adda4d46f95 100644
--- a/net/ieee802154/nl_policy.c
+++ b/net/ieee802154/nl_policy.c
@@ -27,6 +27,7 @@
27const struct nla_policy ieee802154_policy[IEEE802154_ATTR_MAX + 1] = { 27const struct nla_policy ieee802154_policy[IEEE802154_ATTR_MAX + 1] = {
28 [IEEE802154_ATTR_DEV_NAME] = { .type = NLA_STRING, }, 28 [IEEE802154_ATTR_DEV_NAME] = { .type = NLA_STRING, },
29 [IEEE802154_ATTR_DEV_INDEX] = { .type = NLA_U32, }, 29 [IEEE802154_ATTR_DEV_INDEX] = { .type = NLA_U32, },
30 [IEEE802154_ATTR_PHY_NAME] = { .type = NLA_STRING, },
30 31
31 [IEEE802154_ATTR_STATUS] = { .type = NLA_U8, }, 32 [IEEE802154_ATTR_STATUS] = { .type = NLA_U8, },
32 [IEEE802154_ATTR_SHORT_ADDR] = { .type = NLA_U16, }, 33 [IEEE802154_ATTR_SHORT_ADDR] = { .type = NLA_U16, },
@@ -50,5 +51,6 @@ const struct nla_policy ieee802154_policy[IEEE802154_ATTR_MAX + 1] = {
50 [IEEE802154_ATTR_CHANNELS] = { .type = NLA_U32, }, 51 [IEEE802154_ATTR_CHANNELS] = { .type = NLA_U32, },
51 [IEEE802154_ATTR_DURATION] = { .type = NLA_U8, }, 52 [IEEE802154_ATTR_DURATION] = { .type = NLA_U8, },
52 [IEEE802154_ATTR_ED_LIST] = { .len = 27 }, 53 [IEEE802154_ATTR_ED_LIST] = { .len = 27 },
54 [IEEE802154_ATTR_CHANNEL_PAGE_LIST] = { .len = 32 * 4, },
53}; 55};
54 56
diff --git a/net/ieee802154/raw.c b/net/ieee802154/raw.c
index 30e74eee07d6..10970ca85748 100644
--- a/net/ieee802154/raw.c
+++ b/net/ieee802154/raw.c
@@ -25,6 +25,7 @@
25#include <linux/module.h> 25#include <linux/module.h>
26#include <linux/if_arp.h> 26#include <linux/if_arp.h>
27#include <linux/list.h> 27#include <linux/list.h>
28#include <linux/slab.h>
28#include <net/sock.h> 29#include <net/sock.h>
29#include <net/af_ieee802154.h> 30#include <net/af_ieee802154.h>
30 31
@@ -191,7 +192,7 @@ static int raw_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
191 if (err) 192 if (err)
192 goto done; 193 goto done;
193 194
194 sock_recv_timestamp(msg, sk, skb); 195 sock_recv_ts_and_drops(msg, sk, skb);
195 196
196 if (flags & MSG_TRUNC) 197 if (flags & MSG_TRUNC)
197 copied = skb->len; 198 copied = skb->len;
@@ -206,7 +207,6 @@ out:
206static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb) 207static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
207{ 208{
208 if (sock_queue_rcv_skb(sk, skb) < 0) { 209 if (sock_queue_rcv_skb(sk, skb) < 0) {
209 atomic_inc(&sk->sk_drops);
210 kfree_skb(skb); 210 kfree_skb(skb);
211 return NET_RX_DROP; 211 return NET_RX_DROP;
212 } 212 }
diff --git a/net/ieee802154/wpan-class.c b/net/ieee802154/wpan-class.c
index f306604da67a..3d803a1b9fb6 100644
--- a/net/ieee802154/wpan-class.c
+++ b/net/ieee802154/wpan-class.c
@@ -16,12 +16,15 @@
16 * 16 *
17 */ 17 */
18 18
19#include <linux/slab.h>
19#include <linux/kernel.h> 20#include <linux/kernel.h>
20#include <linux/module.h> 21#include <linux/module.h>
21#include <linux/device.h> 22#include <linux/device.h>
22 23
23#include <net/wpan-phy.h> 24#include <net/wpan-phy.h>
24 25
26#include "ieee802154.h"
27
25#define MASTER_SHOW_COMPLEX(name, format_string, args...) \ 28#define MASTER_SHOW_COMPLEX(name, format_string, args...) \
26static ssize_t name ## _show(struct device *dev, \ 29static ssize_t name ## _show(struct device *dev, \
27 struct device_attribute *attr, char *buf) \ 30 struct device_attribute *attr, char *buf) \
@@ -30,7 +33,7 @@ static ssize_t name ## _show(struct device *dev, \
30 int ret; \ 33 int ret; \
31 \ 34 \
32 mutex_lock(&phy->pib_lock); \ 35 mutex_lock(&phy->pib_lock); \
33 ret = sprintf(buf, format_string "\n", args); \ 36 ret = snprintf(buf, PAGE_SIZE, format_string "\n", args); \
34 mutex_unlock(&phy->pib_lock); \ 37 mutex_unlock(&phy->pib_lock); \
35 return ret; \ 38 return ret; \
36} 39}
@@ -40,12 +43,30 @@ static ssize_t name ## _show(struct device *dev, \
40 43
41MASTER_SHOW(current_channel, "%d"); 44MASTER_SHOW(current_channel, "%d");
42MASTER_SHOW(current_page, "%d"); 45MASTER_SHOW(current_page, "%d");
43MASTER_SHOW(channels_supported, "%#x");
44MASTER_SHOW_COMPLEX(transmit_power, "%d +- %d dB", 46MASTER_SHOW_COMPLEX(transmit_power, "%d +- %d dB",
45 ((signed char) (phy->transmit_power << 2)) >> 2, 47 ((signed char) (phy->transmit_power << 2)) >> 2,
46 (phy->transmit_power >> 6) ? (phy->transmit_power >> 6) * 3 : 1 ); 48 (phy->transmit_power >> 6) ? (phy->transmit_power >> 6) * 3 : 1 );
47MASTER_SHOW(cca_mode, "%d"); 49MASTER_SHOW(cca_mode, "%d");
48 50
51static ssize_t channels_supported_show(struct device *dev,
52 struct device_attribute *attr, char *buf)
53{
54 struct wpan_phy *phy = container_of(dev, struct wpan_phy, dev);
55 int ret;
56 int i, len = 0;
57
58 mutex_lock(&phy->pib_lock);
59 for (i = 0; i < 32; i++) {
60 ret = snprintf(buf + len, PAGE_SIZE - len,
61 "%#09x\n", phy->channels_supported[i]);
62 if (ret < 0)
63 break;
64 len += ret;
65 }
66 mutex_unlock(&phy->pib_lock);
67 return len;
68}
69
49static struct device_attribute pmib_attrs[] = { 70static struct device_attribute pmib_attrs[] = {
50 __ATTR_RO(current_channel), 71 __ATTR_RO(current_channel),
51 __ATTR_RO(current_page), 72 __ATTR_RO(current_page),
@@ -91,6 +112,31 @@ struct wpan_phy *wpan_phy_find(const char *str)
91} 112}
92EXPORT_SYMBOL(wpan_phy_find); 113EXPORT_SYMBOL(wpan_phy_find);
93 114
115struct wpan_phy_iter_data {
116 int (*fn)(struct wpan_phy *phy, void *data);
117 void *data;
118};
119
120static int wpan_phy_iter(struct device *dev, void *_data)
121{
122 struct wpan_phy_iter_data *wpid = _data;
123 struct wpan_phy *phy = container_of(dev, struct wpan_phy, dev);
124 return wpid->fn(phy, wpid->data);
125}
126
127int wpan_phy_for_each(int (*fn)(struct wpan_phy *phy, void *data),
128 void *data)
129{
130 struct wpan_phy_iter_data wpid = {
131 .fn = fn,
132 .data = data,
133 };
134
135 return class_for_each_device(&wpan_phy_class, NULL,
136 &wpid, wpan_phy_iter);
137}
138EXPORT_SYMBOL(wpan_phy_for_each);
139
94static int wpan_phy_idx_valid(int idx) 140static int wpan_phy_idx_valid(int idx)
95{ 141{
96 return idx >= 0; 142 return idx >= 0;
@@ -118,14 +164,15 @@ struct wpan_phy *wpan_phy_alloc(size_t priv_size)
118 164
119 phy->dev.class = &wpan_phy_class; 165 phy->dev.class = &wpan_phy_class;
120 166
167 phy->current_channel = -1; /* not initialised */
168 phy->current_page = 0; /* for compatibility */
169
121 return phy; 170 return phy;
122} 171}
123EXPORT_SYMBOL(wpan_phy_alloc); 172EXPORT_SYMBOL(wpan_phy_alloc);
124 173
125int wpan_phy_register(struct device *parent, struct wpan_phy *phy) 174int wpan_phy_register(struct wpan_phy *phy)
126{ 175{
127 phy->dev.parent = parent;
128
129 return device_add(&phy->dev); 176 return device_add(&phy->dev);
130} 177}
131EXPORT_SYMBOL(wpan_phy_register); 178EXPORT_SYMBOL(wpan_phy_register);
@@ -144,16 +191,31 @@ EXPORT_SYMBOL(wpan_phy_free);
144 191
145static int __init wpan_phy_class_init(void) 192static int __init wpan_phy_class_init(void)
146{ 193{
147 return class_register(&wpan_phy_class); 194 int rc;
195 rc = class_register(&wpan_phy_class);
196 if (rc)
197 goto err;
198
199 rc = ieee802154_nl_init();
200 if (rc)
201 goto err_nl;
202
203 return 0;
204err_nl:
205 class_unregister(&wpan_phy_class);
206err:
207 return rc;
148} 208}
149subsys_initcall(wpan_phy_class_init); 209subsys_initcall(wpan_phy_class_init);
150 210
151static void __exit wpan_phy_class_exit(void) 211static void __exit wpan_phy_class_exit(void)
152{ 212{
213 ieee802154_nl_exit();
153 class_unregister(&wpan_phy_class); 214 class_unregister(&wpan_phy_class);
154} 215}
155module_exit(wpan_phy_class_exit); 216module_exit(wpan_phy_class_exit);
156 217
157MODULE_DESCRIPTION("IEEE 802.15.4 device class");
158MODULE_LICENSE("GPL v2"); 218MODULE_LICENSE("GPL v2");
219MODULE_DESCRIPTION("IEEE 802.15.4 configuration interface");
220MODULE_AUTHOR("Dmitry Eremin-Solenikov");
159 221
diff --git a/net/ipv4/Kconfig b/net/ipv4/Kconfig
index 70491d9035eb..0c94a1ac2946 100644
--- a/net/ipv4/Kconfig
+++ b/net/ipv4/Kconfig
@@ -166,7 +166,7 @@ config IP_PNP_DHCP
166 166
167 If unsure, say Y. Note that if you want to use DHCP, a DHCP server 167 If unsure, say Y. Note that if you want to use DHCP, a DHCP server
168 must be operating on your network. Read 168 must be operating on your network. Read
169 <file:Documentation/filesystems/nfsroot.txt> for details. 169 <file:Documentation/filesystems/nfs/nfsroot.txt> for details.
170 170
171config IP_PNP_BOOTP 171config IP_PNP_BOOTP
172 bool "IP: BOOTP support" 172 bool "IP: BOOTP support"
@@ -181,7 +181,7 @@ config IP_PNP_BOOTP
181 does BOOTP itself, providing all necessary information on the kernel 181 does BOOTP itself, providing all necessary information on the kernel
182 command line, you can say N here. If unsure, say Y. Note that if you 182 command line, you can say N here. If unsure, say Y. Note that if you
183 want to use BOOTP, a BOOTP server must be operating on your network. 183 want to use BOOTP, a BOOTP server must be operating on your network.
184 Read <file:Documentation/filesystems/nfsroot.txt> for details. 184 Read <file:Documentation/filesystems/nfs/nfsroot.txt> for details.
185 185
186config IP_PNP_RARP 186config IP_PNP_RARP
187 bool "IP: RARP support" 187 bool "IP: RARP support"
@@ -194,7 +194,7 @@ config IP_PNP_RARP
194 older protocol which is being obsoleted by BOOTP and DHCP), say Y 194 older protocol which is being obsoleted by BOOTP and DHCP), say Y
195 here. Note that if you want to use RARP, a RARP server must be 195 here. Note that if you want to use RARP, a RARP server must be
196 operating on your network. Read 196 operating on your network. Read
197 <file:Documentation/filesystems/nfsroot.txt> for details. 197 <file:Documentation/filesystems/nfs/nfsroot.txt> for details.
198 198
199# not yet ready.. 199# not yet ready..
200# bool ' IP: ARP support' CONFIG_IP_PNP_ARP 200# bool ' IP: ARP support' CONFIG_IP_PNP_ARP
diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
index 57737b8d1711..f71357422380 100644
--- a/net/ipv4/af_inet.c
+++ b/net/ipv4/af_inet.c
@@ -86,6 +86,7 @@
86#include <linux/poll.h> 86#include <linux/poll.h>
87#include <linux/netfilter_ipv4.h> 87#include <linux/netfilter_ipv4.h>
88#include <linux/random.h> 88#include <linux/random.h>
89#include <linux/slab.h>
89 90
90#include <asm/uaccess.h> 91#include <asm/uaccess.h>
91#include <asm/system.h> 92#include <asm/system.h>
@@ -174,12 +175,12 @@ static int inet_autobind(struct sock *sk)
174 /* We may need to bind the socket. */ 175 /* We may need to bind the socket. */
175 lock_sock(sk); 176 lock_sock(sk);
176 inet = inet_sk(sk); 177 inet = inet_sk(sk);
177 if (!inet->num) { 178 if (!inet->inet_num) {
178 if (sk->sk_prot->get_port(sk, 0)) { 179 if (sk->sk_prot->get_port(sk, 0)) {
179 release_sock(sk); 180 release_sock(sk);
180 return -EAGAIN; 181 return -EAGAIN;
181 } 182 }
182 inet->sport = htons(inet->num); 183 inet->inet_sport = htons(inet->inet_num);
183 } 184 }
184 release_sock(sk); 185 release_sock(sk);
185 return 0; 186 return 0;
@@ -262,7 +263,8 @@ static inline int inet_netns_ok(struct net *net, int protocol)
262 * Create an inet socket. 263 * Create an inet socket.
263 */ 264 */
264 265
265static int inet_create(struct net *net, struct socket *sock, int protocol) 266static int inet_create(struct net *net, struct socket *sock, int protocol,
267 int kern)
266{ 268{
267 struct sock *sk; 269 struct sock *sk;
268 struct inet_protosw *answer; 270 struct inet_protosw *answer;
@@ -325,7 +327,7 @@ lookup_protocol:
325 } 327 }
326 328
327 err = -EPERM; 329 err = -EPERM;
328 if (answer->capability > 0 && !capable(answer->capability)) 330 if (sock->type == SOCK_RAW && !kern && !capable(CAP_NET_RAW))
329 goto out_rcu_unlock; 331 goto out_rcu_unlock;
330 332
331 err = -EAFNOSUPPORT; 333 err = -EAFNOSUPPORT;
@@ -354,7 +356,7 @@ lookup_protocol:
354 inet->is_icsk = (INET_PROTOSW_ICSK & answer_flags) != 0; 356 inet->is_icsk = (INET_PROTOSW_ICSK & answer_flags) != 0;
355 357
356 if (SOCK_RAW == sock->type) { 358 if (SOCK_RAW == sock->type) {
357 inet->num = protocol; 359 inet->inet_num = protocol;
358 if (IPPROTO_RAW == protocol) 360 if (IPPROTO_RAW == protocol)
359 inet->hdrincl = 1; 361 inet->hdrincl = 1;
360 } 362 }
@@ -364,7 +366,7 @@ lookup_protocol:
364 else 366 else
365 inet->pmtudisc = IP_PMTUDISC_WANT; 367 inet->pmtudisc = IP_PMTUDISC_WANT;
366 368
367 inet->id = 0; 369 inet->inet_id = 0;
368 370
369 sock_init_data(sock, sk); 371 sock_init_data(sock, sk);
370 372
@@ -381,13 +383,13 @@ lookup_protocol:
381 383
382 sk_refcnt_debug_inc(sk); 384 sk_refcnt_debug_inc(sk);
383 385
384 if (inet->num) { 386 if (inet->inet_num) {
385 /* It assumes that any protocol which allows 387 /* It assumes that any protocol which allows
386 * the user to assign a number at socket 388 * the user to assign a number at socket
387 * creation time automatically 389 * creation time automatically
388 * shares. 390 * shares.
389 */ 391 */
390 inet->sport = htons(inet->num); 392 inet->inet_sport = htons(inet->inet_num);
391 /* Add to protocol hash chains. */ 393 /* Add to protocol hash chains. */
392 sk->sk_prot->hash(sk); 394 sk->sk_prot->hash(sk);
393 } 395 }
@@ -494,27 +496,27 @@ int inet_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
494 496
495 /* Check these errors (active socket, double bind). */ 497 /* Check these errors (active socket, double bind). */
496 err = -EINVAL; 498 err = -EINVAL;
497 if (sk->sk_state != TCP_CLOSE || inet->num) 499 if (sk->sk_state != TCP_CLOSE || inet->inet_num)
498 goto out_release_sock; 500 goto out_release_sock;
499 501
500 inet->rcv_saddr = inet->saddr = addr->sin_addr.s_addr; 502 inet->inet_rcv_saddr = inet->inet_saddr = addr->sin_addr.s_addr;
501 if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST) 503 if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
502 inet->saddr = 0; /* Use device */ 504 inet->inet_saddr = 0; /* Use device */
503 505
504 /* Make sure we are allowed to bind here. */ 506 /* Make sure we are allowed to bind here. */
505 if (sk->sk_prot->get_port(sk, snum)) { 507 if (sk->sk_prot->get_port(sk, snum)) {
506 inet->saddr = inet->rcv_saddr = 0; 508 inet->inet_saddr = inet->inet_rcv_saddr = 0;
507 err = -EADDRINUSE; 509 err = -EADDRINUSE;
508 goto out_release_sock; 510 goto out_release_sock;
509 } 511 }
510 512
511 if (inet->rcv_saddr) 513 if (inet->inet_rcv_saddr)
512 sk->sk_userlocks |= SOCK_BINDADDR_LOCK; 514 sk->sk_userlocks |= SOCK_BINDADDR_LOCK;
513 if (snum) 515 if (snum)
514 sk->sk_userlocks |= SOCK_BINDPORT_LOCK; 516 sk->sk_userlocks |= SOCK_BINDPORT_LOCK;
515 inet->sport = htons(inet->num); 517 inet->inet_sport = htons(inet->inet_num);
516 inet->daddr = 0; 518 inet->inet_daddr = 0;
517 inet->dport = 0; 519 inet->inet_dport = 0;
518 sk_dst_reset(sk); 520 sk_dst_reset(sk);
519 err = 0; 521 err = 0;
520out_release_sock: 522out_release_sock:
@@ -529,10 +531,12 @@ int inet_dgram_connect(struct socket *sock, struct sockaddr * uaddr,
529{ 531{
530 struct sock *sk = sock->sk; 532 struct sock *sk = sock->sk;
531 533
534 if (addr_len < sizeof(uaddr->sa_family))
535 return -EINVAL;
532 if (uaddr->sa_family == AF_UNSPEC) 536 if (uaddr->sa_family == AF_UNSPEC)
533 return sk->sk_prot->disconnect(sk, flags); 537 return sk->sk_prot->disconnect(sk, flags);
534 538
535 if (!inet_sk(sk)->num && inet_autobind(sk)) 539 if (!inet_sk(sk)->inet_num && inet_autobind(sk))
536 return -EAGAIN; 540 return -EAGAIN;
537 return sk->sk_prot->connect(sk, (struct sockaddr *)uaddr, addr_len); 541 return sk->sk_prot->connect(sk, (struct sockaddr *)uaddr, addr_len);
538} 542}
@@ -572,6 +576,9 @@ int inet_stream_connect(struct socket *sock, struct sockaddr *uaddr,
572 int err; 576 int err;
573 long timeo; 577 long timeo;
574 578
579 if (addr_len < sizeof(uaddr->sa_family))
580 return -EINVAL;
581
575 lock_sock(sk); 582 lock_sock(sk);
576 583
577 if (uaddr->sa_family == AF_UNSPEC) { 584 if (uaddr->sa_family == AF_UNSPEC) {
@@ -685,21 +692,21 @@ int inet_getname(struct socket *sock, struct sockaddr *uaddr,
685{ 692{
686 struct sock *sk = sock->sk; 693 struct sock *sk = sock->sk;
687 struct inet_sock *inet = inet_sk(sk); 694 struct inet_sock *inet = inet_sk(sk);
688 struct sockaddr_in *sin = (struct sockaddr_in *)uaddr; 695 DECLARE_SOCKADDR(struct sockaddr_in *, sin, uaddr);
689 696
690 sin->sin_family = AF_INET; 697 sin->sin_family = AF_INET;
691 if (peer) { 698 if (peer) {
692 if (!inet->dport || 699 if (!inet->inet_dport ||
693 (((1 << sk->sk_state) & (TCPF_CLOSE | TCPF_SYN_SENT)) && 700 (((1 << sk->sk_state) & (TCPF_CLOSE | TCPF_SYN_SENT)) &&
694 peer == 1)) 701 peer == 1))
695 return -ENOTCONN; 702 return -ENOTCONN;
696 sin->sin_port = inet->dport; 703 sin->sin_port = inet->inet_dport;
697 sin->sin_addr.s_addr = inet->daddr; 704 sin->sin_addr.s_addr = inet->inet_daddr;
698 } else { 705 } else {
699 __be32 addr = inet->rcv_saddr; 706 __be32 addr = inet->inet_rcv_saddr;
700 if (!addr) 707 if (!addr)
701 addr = inet->saddr; 708 addr = inet->inet_saddr;
702 sin->sin_port = inet->sport; 709 sin->sin_port = inet->inet_sport;
703 sin->sin_addr.s_addr = addr; 710 sin->sin_addr.s_addr = addr;
704 } 711 }
705 memset(sin->sin_zero, 0, sizeof(sin->sin_zero)); 712 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
@@ -714,7 +721,7 @@ int inet_sendmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *msg,
714 struct sock *sk = sock->sk; 721 struct sock *sk = sock->sk;
715 722
716 /* We may need to bind the socket. */ 723 /* We may need to bind the socket. */
717 if (!inet_sk(sk)->num && inet_autobind(sk)) 724 if (!inet_sk(sk)->inet_num && inet_autobind(sk))
718 return -EAGAIN; 725 return -EAGAIN;
719 726
720 return sk->sk_prot->sendmsg(iocb, sk, msg, size); 727 return sk->sk_prot->sendmsg(iocb, sk, msg, size);
@@ -728,7 +735,7 @@ static ssize_t inet_sendpage(struct socket *sock, struct page *page, int offset,
728 struct sock *sk = sock->sk; 735 struct sock *sk = sock->sk;
729 736
730 /* We may need to bind the socket. */ 737 /* We may need to bind the socket. */
731 if (!inet_sk(sk)->num && inet_autobind(sk)) 738 if (!inet_sk(sk)->inet_num && inet_autobind(sk))
732 return -EAGAIN; 739 return -EAGAIN;
733 740
734 if (sk->sk_prot->sendpage) 741 if (sk->sk_prot->sendpage)
@@ -931,7 +938,7 @@ static const struct proto_ops inet_sockraw_ops = {
931#endif 938#endif
932}; 939};
933 940
934static struct net_proto_family inet_family_ops = { 941static const struct net_proto_family inet_family_ops = {
935 .family = PF_INET, 942 .family = PF_INET,
936 .create = inet_create, 943 .create = inet_create,
937 .owner = THIS_MODULE, 944 .owner = THIS_MODULE,
@@ -947,7 +954,6 @@ static struct inet_protosw inetsw_array[] =
947 .protocol = IPPROTO_TCP, 954 .protocol = IPPROTO_TCP,
948 .prot = &tcp_prot, 955 .prot = &tcp_prot,
949 .ops = &inet_stream_ops, 956 .ops = &inet_stream_ops,
950 .capability = -1,
951 .no_check = 0, 957 .no_check = 0,
952 .flags = INET_PROTOSW_PERMANENT | 958 .flags = INET_PROTOSW_PERMANENT |
953 INET_PROTOSW_ICSK, 959 INET_PROTOSW_ICSK,
@@ -958,7 +964,6 @@ static struct inet_protosw inetsw_array[] =
958 .protocol = IPPROTO_UDP, 964 .protocol = IPPROTO_UDP,
959 .prot = &udp_prot, 965 .prot = &udp_prot,
960 .ops = &inet_dgram_ops, 966 .ops = &inet_dgram_ops,
961 .capability = -1,
962 .no_check = UDP_CSUM_DEFAULT, 967 .no_check = UDP_CSUM_DEFAULT,
963 .flags = INET_PROTOSW_PERMANENT, 968 .flags = INET_PROTOSW_PERMANENT,
964 }, 969 },
@@ -969,7 +974,6 @@ static struct inet_protosw inetsw_array[] =
969 .protocol = IPPROTO_IP, /* wild card */ 974 .protocol = IPPROTO_IP, /* wild card */
970 .prot = &raw_prot, 975 .prot = &raw_prot,
971 .ops = &inet_sockraw_ops, 976 .ops = &inet_sockraw_ops,
972 .capability = CAP_NET_RAW,
973 .no_check = UDP_CSUM_DEFAULT, 977 .no_check = UDP_CSUM_DEFAULT,
974 .flags = INET_PROTOSW_REUSE, 978 .flags = INET_PROTOSW_REUSE,
975 } 979 }
@@ -1059,9 +1063,9 @@ static int inet_sk_reselect_saddr(struct sock *sk)
1059 struct inet_sock *inet = inet_sk(sk); 1063 struct inet_sock *inet = inet_sk(sk);
1060 int err; 1064 int err;
1061 struct rtable *rt; 1065 struct rtable *rt;
1062 __be32 old_saddr = inet->saddr; 1066 __be32 old_saddr = inet->inet_saddr;
1063 __be32 new_saddr; 1067 __be32 new_saddr;
1064 __be32 daddr = inet->daddr; 1068 __be32 daddr = inet->inet_daddr;
1065 1069
1066 if (inet->opt && inet->opt->srr) 1070 if (inet->opt && inet->opt->srr)
1067 daddr = inet->opt->faddr; 1071 daddr = inet->opt->faddr;
@@ -1071,7 +1075,7 @@ static int inet_sk_reselect_saddr(struct sock *sk)
1071 RT_CONN_FLAGS(sk), 1075 RT_CONN_FLAGS(sk),
1072 sk->sk_bound_dev_if, 1076 sk->sk_bound_dev_if,
1073 sk->sk_protocol, 1077 sk->sk_protocol,
1074 inet->sport, inet->dport, sk, 0); 1078 inet->inet_sport, inet->inet_dport, sk, 0);
1075 if (err) 1079 if (err)
1076 return err; 1080 return err;
1077 1081
@@ -1087,7 +1091,7 @@ static int inet_sk_reselect_saddr(struct sock *sk)
1087 __func__, &old_saddr, &new_saddr); 1091 __func__, &old_saddr, &new_saddr);
1088 } 1092 }
1089 1093
1090 inet->saddr = inet->rcv_saddr = new_saddr; 1094 inet->inet_saddr = inet->inet_rcv_saddr = new_saddr;
1091 1095
1092 /* 1096 /*
1093 * XXX The only one ugly spot where we need to 1097 * XXX The only one ugly spot where we need to
@@ -1113,7 +1117,7 @@ int inet_sk_rebuild_header(struct sock *sk)
1113 return 0; 1117 return 0;
1114 1118
1115 /* Reroute. */ 1119 /* Reroute. */
1116 daddr = inet->daddr; 1120 daddr = inet->inet_daddr;
1117 if (inet->opt && inet->opt->srr) 1121 if (inet->opt && inet->opt->srr)
1118 daddr = inet->opt->faddr; 1122 daddr = inet->opt->faddr;
1119{ 1123{
@@ -1123,7 +1127,7 @@ int inet_sk_rebuild_header(struct sock *sk)
1123 .nl_u = { 1127 .nl_u = {
1124 .ip4_u = { 1128 .ip4_u = {
1125 .daddr = daddr, 1129 .daddr = daddr,
1126 .saddr = inet->saddr, 1130 .saddr = inet->inet_saddr,
1127 .tos = RT_CONN_FLAGS(sk), 1131 .tos = RT_CONN_FLAGS(sk),
1128 }, 1132 },
1129 }, 1133 },
@@ -1131,8 +1135,8 @@ int inet_sk_rebuild_header(struct sock *sk)
1131 .flags = inet_sk_flowi_flags(sk), 1135 .flags = inet_sk_flowi_flags(sk),
1132 .uli_u = { 1136 .uli_u = {
1133 .ports = { 1137 .ports = {
1134 .sport = inet->sport, 1138 .sport = inet->inet_sport,
1135 .dport = inet->dport, 1139 .dport = inet->inet_dport,
1136 }, 1140 },
1137 }, 1141 },
1138 }; 1142 };
@@ -1387,7 +1391,7 @@ int inet_ctl_sock_create(struct sock **sk, unsigned short family,
1387} 1391}
1388EXPORT_SYMBOL_GPL(inet_ctl_sock_create); 1392EXPORT_SYMBOL_GPL(inet_ctl_sock_create);
1389 1393
1390unsigned long snmp_fold_field(void *mib[], int offt) 1394unsigned long snmp_fold_field(void __percpu *mib[], int offt)
1391{ 1395{
1392 unsigned long res = 0; 1396 unsigned long res = 0;
1393 int i; 1397 int i;
@@ -1400,7 +1404,7 @@ unsigned long snmp_fold_field(void *mib[], int offt)
1400} 1404}
1401EXPORT_SYMBOL_GPL(snmp_fold_field); 1405EXPORT_SYMBOL_GPL(snmp_fold_field);
1402 1406
1403int snmp_mib_init(void *ptr[2], size_t mibsize) 1407int snmp_mib_init(void __percpu *ptr[2], size_t mibsize)
1404{ 1408{
1405 BUG_ON(ptr == NULL); 1409 BUG_ON(ptr == NULL);
1406 ptr[0] = __alloc_percpu(mibsize, __alignof__(unsigned long long)); 1410 ptr[0] = __alloc_percpu(mibsize, __alignof__(unsigned long long));
@@ -1418,7 +1422,7 @@ err0:
1418} 1422}
1419EXPORT_SYMBOL_GPL(snmp_mib_init); 1423EXPORT_SYMBOL_GPL(snmp_mib_init);
1420 1424
1421void snmp_mib_free(void *ptr[2]) 1425void snmp_mib_free(void __percpu *ptr[2])
1422{ 1426{
1423 BUG_ON(ptr == NULL); 1427 BUG_ON(ptr == NULL);
1424 free_percpu(ptr[0]); 1428 free_percpu(ptr[0]);
@@ -1462,25 +1466,25 @@ static const struct net_protocol icmp_protocol = {
1462 1466
1463static __net_init int ipv4_mib_init_net(struct net *net) 1467static __net_init int ipv4_mib_init_net(struct net *net)
1464{ 1468{
1465 if (snmp_mib_init((void **)net->mib.tcp_statistics, 1469 if (snmp_mib_init((void __percpu **)net->mib.tcp_statistics,
1466 sizeof(struct tcp_mib)) < 0) 1470 sizeof(struct tcp_mib)) < 0)
1467 goto err_tcp_mib; 1471 goto err_tcp_mib;
1468 if (snmp_mib_init((void **)net->mib.ip_statistics, 1472 if (snmp_mib_init((void __percpu **)net->mib.ip_statistics,
1469 sizeof(struct ipstats_mib)) < 0) 1473 sizeof(struct ipstats_mib)) < 0)
1470 goto err_ip_mib; 1474 goto err_ip_mib;
1471 if (snmp_mib_init((void **)net->mib.net_statistics, 1475 if (snmp_mib_init((void __percpu **)net->mib.net_statistics,
1472 sizeof(struct linux_mib)) < 0) 1476 sizeof(struct linux_mib)) < 0)
1473 goto err_net_mib; 1477 goto err_net_mib;
1474 if (snmp_mib_init((void **)net->mib.udp_statistics, 1478 if (snmp_mib_init((void __percpu **)net->mib.udp_statistics,
1475 sizeof(struct udp_mib)) < 0) 1479 sizeof(struct udp_mib)) < 0)
1476 goto err_udp_mib; 1480 goto err_udp_mib;
1477 if (snmp_mib_init((void **)net->mib.udplite_statistics, 1481 if (snmp_mib_init((void __percpu **)net->mib.udplite_statistics,
1478 sizeof(struct udp_mib)) < 0) 1482 sizeof(struct udp_mib)) < 0)
1479 goto err_udplite_mib; 1483 goto err_udplite_mib;
1480 if (snmp_mib_init((void **)net->mib.icmp_statistics, 1484 if (snmp_mib_init((void __percpu **)net->mib.icmp_statistics,
1481 sizeof(struct icmp_mib)) < 0) 1485 sizeof(struct icmp_mib)) < 0)
1482 goto err_icmp_mib; 1486 goto err_icmp_mib;
1483 if (snmp_mib_init((void **)net->mib.icmpmsg_statistics, 1487 if (snmp_mib_init((void __percpu **)net->mib.icmpmsg_statistics,
1484 sizeof(struct icmpmsg_mib)) < 0) 1488 sizeof(struct icmpmsg_mib)) < 0)
1485 goto err_icmpmsg_mib; 1489 goto err_icmpmsg_mib;
1486 1490
@@ -1488,30 +1492,30 @@ static __net_init int ipv4_mib_init_net(struct net *net)
1488 return 0; 1492 return 0;
1489 1493
1490err_icmpmsg_mib: 1494err_icmpmsg_mib:
1491 snmp_mib_free((void **)net->mib.icmp_statistics); 1495 snmp_mib_free((void __percpu **)net->mib.icmp_statistics);
1492err_icmp_mib: 1496err_icmp_mib:
1493 snmp_mib_free((void **)net->mib.udplite_statistics); 1497 snmp_mib_free((void __percpu **)net->mib.udplite_statistics);
1494err_udplite_mib: 1498err_udplite_mib:
1495 snmp_mib_free((void **)net->mib.udp_statistics); 1499 snmp_mib_free((void __percpu **)net->mib.udp_statistics);
1496err_udp_mib: 1500err_udp_mib:
1497 snmp_mib_free((void **)net->mib.net_statistics); 1501 snmp_mib_free((void __percpu **)net->mib.net_statistics);
1498err_net_mib: 1502err_net_mib:
1499 snmp_mib_free((void **)net->mib.ip_statistics); 1503 snmp_mib_free((void __percpu **)net->mib.ip_statistics);
1500err_ip_mib: 1504err_ip_mib:
1501 snmp_mib_free((void **)net->mib.tcp_statistics); 1505 snmp_mib_free((void __percpu **)net->mib.tcp_statistics);
1502err_tcp_mib: 1506err_tcp_mib:
1503 return -ENOMEM; 1507 return -ENOMEM;
1504} 1508}
1505 1509
1506static __net_exit void ipv4_mib_exit_net(struct net *net) 1510static __net_exit void ipv4_mib_exit_net(struct net *net)
1507{ 1511{
1508 snmp_mib_free((void **)net->mib.icmpmsg_statistics); 1512 snmp_mib_free((void __percpu **)net->mib.icmpmsg_statistics);
1509 snmp_mib_free((void **)net->mib.icmp_statistics); 1513 snmp_mib_free((void __percpu **)net->mib.icmp_statistics);
1510 snmp_mib_free((void **)net->mib.udplite_statistics); 1514 snmp_mib_free((void __percpu **)net->mib.udplite_statistics);
1511 snmp_mib_free((void **)net->mib.udp_statistics); 1515 snmp_mib_free((void __percpu **)net->mib.udp_statistics);
1512 snmp_mib_free((void **)net->mib.net_statistics); 1516 snmp_mib_free((void __percpu **)net->mib.net_statistics);
1513 snmp_mib_free((void **)net->mib.ip_statistics); 1517 snmp_mib_free((void __percpu **)net->mib.ip_statistics);
1514 snmp_mib_free((void **)net->mib.tcp_statistics); 1518 snmp_mib_free((void __percpu **)net->mib.tcp_statistics);
1515} 1519}
1516 1520
1517static __net_initdata struct pernet_operations ipv4_mib_ops = { 1521static __net_initdata struct pernet_operations ipv4_mib_ops = {
diff --git a/net/ipv4/ah4.c b/net/ipv4/ah4.c
index 5c662703eb1e..880a5ec6dce0 100644
--- a/net/ipv4/ah4.c
+++ b/net/ipv4/ah4.c
@@ -1,14 +1,73 @@
1#include <crypto/hash.h>
1#include <linux/err.h> 2#include <linux/err.h>
2#include <linux/module.h> 3#include <linux/module.h>
4#include <linux/slab.h>
3#include <net/ip.h> 5#include <net/ip.h>
4#include <net/xfrm.h> 6#include <net/xfrm.h>
5#include <net/ah.h> 7#include <net/ah.h>
6#include <linux/crypto.h> 8#include <linux/crypto.h>
7#include <linux/pfkeyv2.h> 9#include <linux/pfkeyv2.h>
8#include <linux/spinlock.h> 10#include <linux/scatterlist.h>
9#include <net/icmp.h> 11#include <net/icmp.h>
10#include <net/protocol.h> 12#include <net/protocol.h>
11 13
14struct ah_skb_cb {
15 struct xfrm_skb_cb xfrm;
16 void *tmp;
17};
18
19#define AH_SKB_CB(__skb) ((struct ah_skb_cb *)&((__skb)->cb[0]))
20
21static void *ah_alloc_tmp(struct crypto_ahash *ahash, int nfrags,
22 unsigned int size)
23{
24 unsigned int len;
25
26 len = size + crypto_ahash_digestsize(ahash) +
27 (crypto_ahash_alignmask(ahash) &
28 ~(crypto_tfm_ctx_alignment() - 1));
29
30 len = ALIGN(len, crypto_tfm_ctx_alignment());
31
32 len += sizeof(struct ahash_request) + crypto_ahash_reqsize(ahash);
33 len = ALIGN(len, __alignof__(struct scatterlist));
34
35 len += sizeof(struct scatterlist) * nfrags;
36
37 return kmalloc(len, GFP_ATOMIC);
38}
39
40static inline u8 *ah_tmp_auth(void *tmp, unsigned int offset)
41{
42 return tmp + offset;
43}
44
45static inline u8 *ah_tmp_icv(struct crypto_ahash *ahash, void *tmp,
46 unsigned int offset)
47{
48 return PTR_ALIGN((u8 *)tmp + offset, crypto_ahash_alignmask(ahash) + 1);
49}
50
51static inline struct ahash_request *ah_tmp_req(struct crypto_ahash *ahash,
52 u8 *icv)
53{
54 struct ahash_request *req;
55
56 req = (void *)PTR_ALIGN(icv + crypto_ahash_digestsize(ahash),
57 crypto_tfm_ctx_alignment());
58
59 ahash_request_set_tfm(req, ahash);
60
61 return req;
62}
63
64static inline struct scatterlist *ah_req_sg(struct crypto_ahash *ahash,
65 struct ahash_request *req)
66{
67 return (void *)ALIGN((unsigned long)(req + 1) +
68 crypto_ahash_reqsize(ahash),
69 __alignof__(struct scatterlist));
70}
12 71
13/* Clear mutable options and find final destination to substitute 72/* Clear mutable options and find final destination to substitute
14 * into IP header for icv calculation. Options are already checked 73 * into IP header for icv calculation. Options are already checked
@@ -54,20 +113,72 @@ static int ip_clear_mutable_options(struct iphdr *iph, __be32 *daddr)
54 return 0; 113 return 0;
55} 114}
56 115
116static void ah_output_done(struct crypto_async_request *base, int err)
117{
118 u8 *icv;
119 struct iphdr *iph;
120 struct sk_buff *skb = base->data;
121 struct xfrm_state *x = skb_dst(skb)->xfrm;
122 struct ah_data *ahp = x->data;
123 struct iphdr *top_iph = ip_hdr(skb);
124 struct ip_auth_hdr *ah = ip_auth_hdr(skb);
125 int ihl = ip_hdrlen(skb);
126
127 iph = AH_SKB_CB(skb)->tmp;
128 icv = ah_tmp_icv(ahp->ahash, iph, ihl);
129 memcpy(ah->auth_data, icv, ahp->icv_trunc_len);
130
131 top_iph->tos = iph->tos;
132 top_iph->ttl = iph->ttl;
133 top_iph->frag_off = iph->frag_off;
134 if (top_iph->ihl != 5) {
135 top_iph->daddr = iph->daddr;
136 memcpy(top_iph+1, iph+1, top_iph->ihl*4 - sizeof(struct iphdr));
137 }
138
139 err = ah->nexthdr;
140
141 kfree(AH_SKB_CB(skb)->tmp);
142 xfrm_output_resume(skb, err);
143}
144
57static int ah_output(struct xfrm_state *x, struct sk_buff *skb) 145static int ah_output(struct xfrm_state *x, struct sk_buff *skb)
58{ 146{
59 int err; 147 int err;
148 int nfrags;
149 int ihl;
150 u8 *icv;
151 struct sk_buff *trailer;
152 struct crypto_ahash *ahash;
153 struct ahash_request *req;
154 struct scatterlist *sg;
60 struct iphdr *iph, *top_iph; 155 struct iphdr *iph, *top_iph;
61 struct ip_auth_hdr *ah; 156 struct ip_auth_hdr *ah;
62 struct ah_data *ahp; 157 struct ah_data *ahp;
63 union { 158
64 struct iphdr iph; 159 ahp = x->data;
65 char buf[60]; 160 ahash = ahp->ahash;
66 } tmp_iph; 161
162 if ((err = skb_cow_data(skb, 0, &trailer)) < 0)
163 goto out;
164 nfrags = err;
67 165
68 skb_push(skb, -skb_network_offset(skb)); 166 skb_push(skb, -skb_network_offset(skb));
167 ah = ip_auth_hdr(skb);
168 ihl = ip_hdrlen(skb);
169
170 err = -ENOMEM;
171 iph = ah_alloc_tmp(ahash, nfrags, ihl);
172 if (!iph)
173 goto out;
174
175 icv = ah_tmp_icv(ahash, iph, ihl);
176 req = ah_tmp_req(ahash, icv);
177 sg = ah_req_sg(ahash, req);
178
179 memset(ah->auth_data, 0, ahp->icv_trunc_len);
180
69 top_iph = ip_hdr(skb); 181 top_iph = ip_hdr(skb);
70 iph = &tmp_iph.iph;
71 182
72 iph->tos = top_iph->tos; 183 iph->tos = top_iph->tos;
73 iph->ttl = top_iph->ttl; 184 iph->ttl = top_iph->ttl;
@@ -78,10 +189,9 @@ static int ah_output(struct xfrm_state *x, struct sk_buff *skb)
78 memcpy(iph+1, top_iph+1, top_iph->ihl*4 - sizeof(struct iphdr)); 189 memcpy(iph+1, top_iph+1, top_iph->ihl*4 - sizeof(struct iphdr));
79 err = ip_clear_mutable_options(top_iph, &top_iph->daddr); 190 err = ip_clear_mutable_options(top_iph, &top_iph->daddr);
80 if (err) 191 if (err)
81 goto error; 192 goto out_free;
82 } 193 }
83 194
84 ah = ip_auth_hdr(skb);
85 ah->nexthdr = *skb_mac_header(skb); 195 ah->nexthdr = *skb_mac_header(skb);
86 *skb_mac_header(skb) = IPPROTO_AH; 196 *skb_mac_header(skb) = IPPROTO_AH;
87 197
@@ -91,20 +201,31 @@ static int ah_output(struct xfrm_state *x, struct sk_buff *skb)
91 top_iph->ttl = 0; 201 top_iph->ttl = 0;
92 top_iph->check = 0; 202 top_iph->check = 0;
93 203
94 ahp = x->data;
95 ah->hdrlen = (XFRM_ALIGN8(sizeof(*ah) + ahp->icv_trunc_len) >> 2) - 2; 204 ah->hdrlen = (XFRM_ALIGN8(sizeof(*ah) + ahp->icv_trunc_len) >> 2) - 2;
96 205
97 ah->reserved = 0; 206 ah->reserved = 0;
98 ah->spi = x->id.spi; 207 ah->spi = x->id.spi;
99 ah->seq_no = htonl(XFRM_SKB_CB(skb)->seq.output); 208 ah->seq_no = htonl(XFRM_SKB_CB(skb)->seq.output);
100 209
101 spin_lock_bh(&x->lock); 210 sg_init_table(sg, nfrags);
102 err = ah_mac_digest(ahp, skb, ah->auth_data); 211 skb_to_sgvec(skb, sg, 0, skb->len);
103 memcpy(ah->auth_data, ahp->work_icv, ahp->icv_trunc_len);
104 spin_unlock_bh(&x->lock);
105 212
106 if (err) 213 ahash_request_set_crypt(req, sg, icv, skb->len);
107 goto error; 214 ahash_request_set_callback(req, 0, ah_output_done, skb);
215
216 AH_SKB_CB(skb)->tmp = iph;
217
218 err = crypto_ahash_digest(req);
219 if (err) {
220 if (err == -EINPROGRESS)
221 goto out;
222
223 if (err == -EBUSY)
224 err = NET_XMIT_DROP;
225 goto out_free;
226 }
227
228 memcpy(ah->auth_data, icv, ahp->icv_trunc_len);
108 229
109 top_iph->tos = iph->tos; 230 top_iph->tos = iph->tos;
110 top_iph->ttl = iph->ttl; 231 top_iph->ttl = iph->ttl;
@@ -114,28 +235,67 @@ static int ah_output(struct xfrm_state *x, struct sk_buff *skb)
114 memcpy(top_iph+1, iph+1, top_iph->ihl*4 - sizeof(struct iphdr)); 235 memcpy(top_iph+1, iph+1, top_iph->ihl*4 - sizeof(struct iphdr));
115 } 236 }
116 237
117 err = 0; 238out_free:
118 239 kfree(iph);
119error: 240out:
120 return err; 241 return err;
121} 242}
122 243
244static void ah_input_done(struct crypto_async_request *base, int err)
245{
246 u8 *auth_data;
247 u8 *icv;
248 struct iphdr *work_iph;
249 struct sk_buff *skb = base->data;
250 struct xfrm_state *x = xfrm_input_state(skb);
251 struct ah_data *ahp = x->data;
252 struct ip_auth_hdr *ah = ip_auth_hdr(skb);
253 int ihl = ip_hdrlen(skb);
254 int ah_hlen = (ah->hdrlen + 2) << 2;
255
256 work_iph = AH_SKB_CB(skb)->tmp;
257 auth_data = ah_tmp_auth(work_iph, ihl);
258 icv = ah_tmp_icv(ahp->ahash, auth_data, ahp->icv_trunc_len);
259
260 err = memcmp(icv, auth_data, ahp->icv_trunc_len) ? -EBADMSG: 0;
261 if (err)
262 goto out;
263
264 skb->network_header += ah_hlen;
265 memcpy(skb_network_header(skb), work_iph, ihl);
266 __skb_pull(skb, ah_hlen + ihl);
267 skb_set_transport_header(skb, -ihl);
268
269 err = ah->nexthdr;
270out:
271 kfree(AH_SKB_CB(skb)->tmp);
272 xfrm_input_resume(skb, err);
273}
274
123static int ah_input(struct xfrm_state *x, struct sk_buff *skb) 275static int ah_input(struct xfrm_state *x, struct sk_buff *skb)
124{ 276{
125 int ah_hlen; 277 int ah_hlen;
126 int ihl; 278 int ihl;
127 int nexthdr; 279 int nexthdr;
128 int err = -EINVAL; 280 int nfrags;
129 struct iphdr *iph; 281 u8 *auth_data;
282 u8 *icv;
283 struct sk_buff *trailer;
284 struct crypto_ahash *ahash;
285 struct ahash_request *req;
286 struct scatterlist *sg;
287 struct iphdr *iph, *work_iph;
130 struct ip_auth_hdr *ah; 288 struct ip_auth_hdr *ah;
131 struct ah_data *ahp; 289 struct ah_data *ahp;
132 char work_buf[60]; 290 int err = -ENOMEM;
133 291
134 if (!pskb_may_pull(skb, sizeof(*ah))) 292 if (!pskb_may_pull(skb, sizeof(*ah)))
135 goto out; 293 goto out;
136 294
137 ah = (struct ip_auth_hdr *)skb->data; 295 ah = (struct ip_auth_hdr *)skb->data;
138 ahp = x->data; 296 ahp = x->data;
297 ahash = ahp->ahash;
298
139 nexthdr = ah->nexthdr; 299 nexthdr = ah->nexthdr;
140 ah_hlen = (ah->hdrlen + 2) << 2; 300 ah_hlen = (ah->hdrlen + 2) << 2;
141 301
@@ -156,9 +316,24 @@ static int ah_input(struct xfrm_state *x, struct sk_buff *skb)
156 316
157 ah = (struct ip_auth_hdr *)skb->data; 317 ah = (struct ip_auth_hdr *)skb->data;
158 iph = ip_hdr(skb); 318 iph = ip_hdr(skb);
319 ihl = ip_hdrlen(skb);
320
321 if ((err = skb_cow_data(skb, 0, &trailer)) < 0)
322 goto out;
323 nfrags = err;
324
325 work_iph = ah_alloc_tmp(ahash, nfrags, ihl + ahp->icv_trunc_len);
326 if (!work_iph)
327 goto out;
328
329 auth_data = ah_tmp_auth(work_iph, ihl);
330 icv = ah_tmp_icv(ahash, auth_data, ahp->icv_trunc_len);
331 req = ah_tmp_req(ahash, icv);
332 sg = ah_req_sg(ahash, req);
159 333
160 ihl = skb->data - skb_network_header(skb); 334 memcpy(work_iph, iph, ihl);
161 memcpy(work_buf, iph, ihl); 335 memcpy(auth_data, ah->auth_data, ahp->icv_trunc_len);
336 memset(ah->auth_data, 0, ahp->icv_trunc_len);
162 337
163 iph->ttl = 0; 338 iph->ttl = 0;
164 iph->tos = 0; 339 iph->tos = 0;
@@ -166,35 +341,44 @@ static int ah_input(struct xfrm_state *x, struct sk_buff *skb)
166 iph->check = 0; 341 iph->check = 0;
167 if (ihl > sizeof(*iph)) { 342 if (ihl > sizeof(*iph)) {
168 __be32 dummy; 343 __be32 dummy;
169 if (ip_clear_mutable_options(iph, &dummy)) 344 err = ip_clear_mutable_options(iph, &dummy);
170 goto out; 345 if (err)
346 goto out_free;
171 } 347 }
172 348
173 spin_lock(&x->lock); 349 skb_push(skb, ihl);
174 {
175 u8 auth_data[MAX_AH_AUTH_LEN];
176 350
177 memcpy(auth_data, ah->auth_data, ahp->icv_trunc_len); 351 sg_init_table(sg, nfrags);
178 skb_push(skb, ihl); 352 skb_to_sgvec(skb, sg, 0, skb->len);
179 err = ah_mac_digest(ahp, skb, ah->auth_data); 353
180 if (err) 354 ahash_request_set_crypt(req, sg, icv, skb->len);
181 goto unlock; 355 ahash_request_set_callback(req, 0, ah_input_done, skb);
182 if (memcmp(ahp->work_icv, auth_data, ahp->icv_trunc_len)) 356
183 err = -EBADMSG; 357 AH_SKB_CB(skb)->tmp = work_iph;
358
359 err = crypto_ahash_digest(req);
360 if (err) {
361 if (err == -EINPROGRESS)
362 goto out;
363
364 if (err == -EBUSY)
365 err = NET_XMIT_DROP;
366 goto out_free;
184 } 367 }
185unlock:
186 spin_unlock(&x->lock);
187 368
369 err = memcmp(icv, auth_data, ahp->icv_trunc_len) ? -EBADMSG: 0;
188 if (err) 370 if (err)
189 goto out; 371 goto out_free;
190 372
191 skb->network_header += ah_hlen; 373 skb->network_header += ah_hlen;
192 memcpy(skb_network_header(skb), work_buf, ihl); 374 memcpy(skb_network_header(skb), work_iph, ihl);
193 skb->transport_header = skb->network_header;
194 __skb_pull(skb, ah_hlen + ihl); 375 __skb_pull(skb, ah_hlen + ihl);
376 skb_set_transport_header(skb, -ihl);
195 377
196 return nexthdr; 378 err = nexthdr;
197 379
380out_free:
381 kfree (work_iph);
198out: 382out:
199 return err; 383 return err;
200} 384}
@@ -210,7 +394,7 @@ static void ah4_err(struct sk_buff *skb, u32 info)
210 icmp_hdr(skb)->code != ICMP_FRAG_NEEDED) 394 icmp_hdr(skb)->code != ICMP_FRAG_NEEDED)
211 return; 395 return;
212 396
213 x = xfrm_state_lookup(net, (xfrm_address_t *)&iph->daddr, ah->spi, IPPROTO_AH, AF_INET); 397 x = xfrm_state_lookup(net, skb->mark, (xfrm_address_t *)&iph->daddr, ah->spi, IPPROTO_AH, AF_INET);
214 if (!x) 398 if (!x)
215 return; 399 return;
216 printk(KERN_DEBUG "pmtu discovery on SA AH/%08x/%08x\n", 400 printk(KERN_DEBUG "pmtu discovery on SA AH/%08x/%08x\n",
@@ -222,7 +406,7 @@ static int ah_init_state(struct xfrm_state *x)
222{ 406{
223 struct ah_data *ahp = NULL; 407 struct ah_data *ahp = NULL;
224 struct xfrm_algo_desc *aalg_desc; 408 struct xfrm_algo_desc *aalg_desc;
225 struct crypto_hash *tfm; 409 struct crypto_ahash *ahash;
226 410
227 if (!x->aalg) 411 if (!x->aalg)
228 goto error; 412 goto error;
@@ -231,44 +415,40 @@ static int ah_init_state(struct xfrm_state *x)
231 goto error; 415 goto error;
232 416
233 ahp = kzalloc(sizeof(*ahp), GFP_KERNEL); 417 ahp = kzalloc(sizeof(*ahp), GFP_KERNEL);
234 if (ahp == NULL) 418 if (!ahp)
235 return -ENOMEM; 419 return -ENOMEM;
236 420
237 tfm = crypto_alloc_hash(x->aalg->alg_name, 0, CRYPTO_ALG_ASYNC); 421 ahash = crypto_alloc_ahash(x->aalg->alg_name, 0, 0);
238 if (IS_ERR(tfm)) 422 if (IS_ERR(ahash))
239 goto error; 423 goto error;
240 424
241 ahp->tfm = tfm; 425 ahp->ahash = ahash;
242 if (crypto_hash_setkey(tfm, x->aalg->alg_key, 426 if (crypto_ahash_setkey(ahash, x->aalg->alg_key,
243 (x->aalg->alg_key_len + 7) / 8)) 427 (x->aalg->alg_key_len + 7) / 8))
244 goto error; 428 goto error;
245 429
246 /* 430 /*
247 * Lookup the algorithm description maintained by xfrm_algo, 431 * Lookup the algorithm description maintained by xfrm_algo,
248 * verify crypto transform properties, and store information 432 * verify crypto transform properties, and store information
249 * we need for AH processing. This lookup cannot fail here 433 * we need for AH processing. This lookup cannot fail here
250 * after a successful crypto_alloc_hash(). 434 * after a successful crypto_alloc_ahash().
251 */ 435 */
252 aalg_desc = xfrm_aalg_get_byname(x->aalg->alg_name, 0); 436 aalg_desc = xfrm_aalg_get_byname(x->aalg->alg_name, 0);
253 BUG_ON(!aalg_desc); 437 BUG_ON(!aalg_desc);
254 438
255 if (aalg_desc->uinfo.auth.icv_fullbits/8 != 439 if (aalg_desc->uinfo.auth.icv_fullbits/8 !=
256 crypto_hash_digestsize(tfm)) { 440 crypto_ahash_digestsize(ahash)) {
257 printk(KERN_INFO "AH: %s digestsize %u != %hu\n", 441 printk(KERN_INFO "AH: %s digestsize %u != %hu\n",
258 x->aalg->alg_name, crypto_hash_digestsize(tfm), 442 x->aalg->alg_name, crypto_ahash_digestsize(ahash),
259 aalg_desc->uinfo.auth.icv_fullbits/8); 443 aalg_desc->uinfo.auth.icv_fullbits/8);
260 goto error; 444 goto error;
261 } 445 }
262 446
263 ahp->icv_full_len = aalg_desc->uinfo.auth.icv_fullbits/8; 447 ahp->icv_full_len = aalg_desc->uinfo.auth.icv_fullbits/8;
264 ahp->icv_trunc_len = aalg_desc->uinfo.auth.icv_truncbits/8; 448 ahp->icv_trunc_len = x->aalg->alg_trunc_len/8;
265 449
266 BUG_ON(ahp->icv_trunc_len > MAX_AH_AUTH_LEN); 450 BUG_ON(ahp->icv_trunc_len > MAX_AH_AUTH_LEN);
267 451
268 ahp->work_icv = kmalloc(ahp->icv_full_len, GFP_KERNEL);
269 if (!ahp->work_icv)
270 goto error;
271
272 x->props.header_len = XFRM_ALIGN8(sizeof(struct ip_auth_hdr) + 452 x->props.header_len = XFRM_ALIGN8(sizeof(struct ip_auth_hdr) +
273 ahp->icv_trunc_len); 453 ahp->icv_trunc_len);
274 if (x->props.mode == XFRM_MODE_TUNNEL) 454 if (x->props.mode == XFRM_MODE_TUNNEL)
@@ -279,8 +459,7 @@ static int ah_init_state(struct xfrm_state *x)
279 459
280error: 460error:
281 if (ahp) { 461 if (ahp) {
282 kfree(ahp->work_icv); 462 crypto_free_ahash(ahp->ahash);
283 crypto_free_hash(ahp->tfm);
284 kfree(ahp); 463 kfree(ahp);
285 } 464 }
286 return -EINVAL; 465 return -EINVAL;
@@ -293,8 +472,7 @@ static void ah_destroy(struct xfrm_state *x)
293 if (!ahp) 472 if (!ahp)
294 return; 473 return;
295 474
296 kfree(ahp->work_icv); 475 crypto_free_ahash(ahp->ahash);
297 crypto_free_hash(ahp->tfm);
298 kfree(ahp); 476 kfree(ahp);
299} 477}
300 478
diff --git a/net/ipv4/arp.c b/net/ipv4/arp.c
index 4e80f336c0cf..80769f1f9fab 100644
--- a/net/ipv4/arp.c
+++ b/net/ipv4/arp.c
@@ -70,6 +70,7 @@
70 * bonding can change the skb before 70 * bonding can change the skb before
71 * sending (e.g. insert 8021q tag). 71 * sending (e.g. insert 8021q tag).
72 * Harald Welte : convert to make use of jenkins hash 72 * Harald Welte : convert to make use of jenkins hash
73 * Jesper D. Brouer: Proxy ARP PVLAN RFC 3069 support.
73 */ 74 */
74 75
75#include <linux/module.h> 76#include <linux/module.h>
@@ -97,6 +98,7 @@
97#include <linux/net.h> 98#include <linux/net.h>
98#include <linux/rcupdate.h> 99#include <linux/rcupdate.h>
99#include <linux/jhash.h> 100#include <linux/jhash.h>
101#include <linux/slab.h>
100#ifdef CONFIG_SYSCTL 102#ifdef CONFIG_SYSCTL
101#include <linux/sysctl.h> 103#include <linux/sysctl.h>
102#endif 104#endif
@@ -524,12 +526,15 @@ int arp_bind_neighbour(struct dst_entry *dst)
524/* 526/*
525 * Check if we can use proxy ARP for this path 527 * Check if we can use proxy ARP for this path
526 */ 528 */
527 529static inline int arp_fwd_proxy(struct in_device *in_dev,
528static inline int arp_fwd_proxy(struct in_device *in_dev, struct rtable *rt) 530 struct net_device *dev, struct rtable *rt)
529{ 531{
530 struct in_device *out_dev; 532 struct in_device *out_dev;
531 int imi, omi = -1; 533 int imi, omi = -1;
532 534
535 if (rt->u.dst.dev == dev)
536 return 0;
537
533 if (!IN_DEV_PROXY_ARP(in_dev)) 538 if (!IN_DEV_PROXY_ARP(in_dev))
534 return 0; 539 return 0;
535 540
@@ -548,6 +553,43 @@ static inline int arp_fwd_proxy(struct in_device *in_dev, struct rtable *rt)
548} 553}
549 554
550/* 555/*
556 * Check for RFC3069 proxy arp private VLAN (allow to send back to same dev)
557 *
558 * RFC3069 supports proxy arp replies back to the same interface. This
559 * is done to support (ethernet) switch features, like RFC 3069, where
560 * the individual ports are not allowed to communicate with each
561 * other, BUT they are allowed to talk to the upstream router. As
562 * described in RFC 3069, it is possible to allow these hosts to
563 * communicate through the upstream router, by proxy_arp'ing.
564 *
565 * RFC 3069: "VLAN Aggregation for Efficient IP Address Allocation"
566 *
567 * This technology is known by different names:
568 * In RFC 3069 it is called VLAN Aggregation.
569 * Cisco and Allied Telesyn call it Private VLAN.
570 * Hewlett-Packard call it Source-Port filtering or port-isolation.
571 * Ericsson call it MAC-Forced Forwarding (RFC Draft).
572 *
573 */
574static inline int arp_fwd_pvlan(struct in_device *in_dev,
575 struct net_device *dev, struct rtable *rt,
576 __be32 sip, __be32 tip)
577{
578 /* Private VLAN is only concerned about the same ethernet segment */
579 if (rt->u.dst.dev != dev)
580 return 0;
581
582 /* Don't reply on self probes (often done by windowz boxes)*/
583 if (sip == tip)
584 return 0;
585
586 if (IN_DEV_PROXY_ARP_PVLAN(in_dev))
587 return 1;
588 else
589 return 0;
590}
591
592/*
551 * Interface to link layer: send routine and receive handler. 593 * Interface to link layer: send routine and receive handler.
552 */ 594 */
553 595
@@ -619,13 +661,13 @@ struct sk_buff *arp_create(int type, int ptype, __be32 dest_ip,
619#endif 661#endif
620#endif 662#endif
621 663
622#ifdef CONFIG_FDDI 664#if defined(CONFIG_FDDI) || defined(CONFIG_FDDI_MODULE)
623 case ARPHRD_FDDI: 665 case ARPHRD_FDDI:
624 arp->ar_hrd = htons(ARPHRD_ETHER); 666 arp->ar_hrd = htons(ARPHRD_ETHER);
625 arp->ar_pro = htons(ETH_P_IP); 667 arp->ar_pro = htons(ETH_P_IP);
626 break; 668 break;
627#endif 669#endif
628#ifdef CONFIG_TR 670#if defined(CONFIG_TR) || defined(CONFIG_TR_MODULE)
629 case ARPHRD_IEEE802_TR: 671 case ARPHRD_IEEE802_TR:
630 arp->ar_hrd = htons(ARPHRD_IEEE802); 672 arp->ar_hrd = htons(ARPHRD_IEEE802);
631 arp->ar_pro = htons(ETH_P_IP); 673 arp->ar_pro = htons(ETH_P_IP);
@@ -833,8 +875,11 @@ static int arp_process(struct sk_buff *skb)
833 } 875 }
834 goto out; 876 goto out;
835 } else if (IN_DEV_FORWARD(in_dev)) { 877 } else if (IN_DEV_FORWARD(in_dev)) {
836 if (addr_type == RTN_UNICAST && rt->u.dst.dev != dev && 878 if (addr_type == RTN_UNICAST &&
837 (arp_fwd_proxy(in_dev, rt) || pneigh_lookup(&arp_tbl, net, &tip, dev, 0))) { 879 (arp_fwd_proxy(in_dev, dev, rt) ||
880 arp_fwd_pvlan(in_dev, dev, rt, sip, tip) ||
881 pneigh_lookup(&arp_tbl, net, &tip, dev, 0)))
882 {
838 n = neigh_event_ns(&arp_tbl, sha, &sip, dev); 883 n = neigh_event_ns(&arp_tbl, sha, &sip, dev);
839 if (n) 884 if (n)
840 neigh_release(n); 885 neigh_release(n);
@@ -863,7 +908,8 @@ static int arp_process(struct sk_buff *skb)
863 devices (strip is candidate) 908 devices (strip is candidate)
864 */ 909 */
865 if (n == NULL && 910 if (n == NULL &&
866 arp->ar_op == htons(ARPOP_REPLY) && 911 (arp->ar_op == htons(ARPOP_REPLY) ||
912 (arp->ar_op == htons(ARPOP_REQUEST) && tip == sip)) &&
867 inet_addr_type(net, sip) == RTN_UNICAST) 913 inet_addr_type(net, sip) == RTN_UNICAST)
868 n = __neigh_lookup(&arp_tbl, &sip, dev, 1); 914 n = __neigh_lookup(&arp_tbl, &sip, dev, 1);
869 } 915 }
@@ -1005,7 +1051,7 @@ static int arp_req_set(struct net *net, struct arpreq *r,
1005 return -EINVAL; 1051 return -EINVAL;
1006 } 1052 }
1007 switch (dev->type) { 1053 switch (dev->type) {
1008#ifdef CONFIG_FDDI 1054#if defined(CONFIG_FDDI) || defined(CONFIG_FDDI_MODULE)
1009 case ARPHRD_FDDI: 1055 case ARPHRD_FDDI:
1010 /* 1056 /*
1011 * According to RFC 1390, FDDI devices should accept ARP 1057 * According to RFC 1390, FDDI devices should accept ARP
@@ -1239,8 +1285,7 @@ void __init arp_init(void)
1239 dev_add_pack(&arp_packet_type); 1285 dev_add_pack(&arp_packet_type);
1240 arp_proc_init(); 1286 arp_proc_init();
1241#ifdef CONFIG_SYSCTL 1287#ifdef CONFIG_SYSCTL
1242 neigh_sysctl_register(NULL, &arp_tbl.parms, NET_IPV4, 1288 neigh_sysctl_register(NULL, &arp_tbl.parms, "ipv4", NULL);
1243 NET_IPV4_NEIGH, "ipv4", NULL, NULL);
1244#endif 1289#endif
1245 register_netdevice_notifier(&arp_netdev_notifier); 1290 register_netdevice_notifier(&arp_netdev_notifier);
1246} 1291}
diff --git a/net/ipv4/cipso_ipv4.c b/net/ipv4/cipso_ipv4.c
index 039cc1ffe977..c97cd9ff697e 100644
--- a/net/ipv4/cipso_ipv4.c
+++ b/net/ipv4/cipso_ipv4.c
@@ -44,6 +44,7 @@
44#include <linux/string.h> 44#include <linux/string.h>
45#include <linux/jhash.h> 45#include <linux/jhash.h>
46#include <linux/audit.h> 46#include <linux/audit.h>
47#include <linux/slab.h>
47#include <net/ip.h> 48#include <net/ip.h>
48#include <net/icmp.h> 49#include <net/icmp.h>
49#include <net/tcp.h> 50#include <net/tcp.h>
@@ -2017,7 +2018,7 @@ req_setattr_failure:
2017 * values on failure. 2018 * values on failure.
2018 * 2019 *
2019 */ 2020 */
2020int cipso_v4_delopt(struct ip_options **opt_ptr) 2021static int cipso_v4_delopt(struct ip_options **opt_ptr)
2021{ 2022{
2022 int hdr_delta = 0; 2023 int hdr_delta = 0;
2023 struct ip_options *opt = *opt_ptr; 2024 struct ip_options *opt = *opt_ptr;
diff --git a/net/ipv4/datagram.c b/net/ipv4/datagram.c
index 5e6c5a0f3fde..fb2465811b48 100644
--- a/net/ipv4/datagram.c
+++ b/net/ipv4/datagram.c
@@ -39,7 +39,7 @@ int ip4_datagram_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len)
39 sk_dst_reset(sk); 39 sk_dst_reset(sk);
40 40
41 oif = sk->sk_bound_dev_if; 41 oif = sk->sk_bound_dev_if;
42 saddr = inet->saddr; 42 saddr = inet->inet_saddr;
43 if (ipv4_is_multicast(usin->sin_addr.s_addr)) { 43 if (ipv4_is_multicast(usin->sin_addr.s_addr)) {
44 if (!oif) 44 if (!oif)
45 oif = inet->mc_index; 45 oif = inet->mc_index;
@@ -49,7 +49,7 @@ int ip4_datagram_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len)
49 err = ip_route_connect(&rt, usin->sin_addr.s_addr, saddr, 49 err = ip_route_connect(&rt, usin->sin_addr.s_addr, saddr,
50 RT_CONN_FLAGS(sk), oif, 50 RT_CONN_FLAGS(sk), oif,
51 sk->sk_protocol, 51 sk->sk_protocol,
52 inet->sport, usin->sin_port, sk, 1); 52 inet->inet_sport, usin->sin_port, sk, 1);
53 if (err) { 53 if (err) {
54 if (err == -ENETUNREACH) 54 if (err == -ENETUNREACH)
55 IP_INC_STATS_BH(sock_net(sk), IPSTATS_MIB_OUTNOROUTES); 55 IP_INC_STATS_BH(sock_net(sk), IPSTATS_MIB_OUTNOROUTES);
@@ -60,14 +60,14 @@ int ip4_datagram_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len)
60 ip_rt_put(rt); 60 ip_rt_put(rt);
61 return -EACCES; 61 return -EACCES;
62 } 62 }
63 if (!inet->saddr) 63 if (!inet->inet_saddr)
64 inet->saddr = rt->rt_src; /* Update source address */ 64 inet->inet_saddr = rt->rt_src; /* Update source address */
65 if (!inet->rcv_saddr) 65 if (!inet->inet_rcv_saddr)
66 inet->rcv_saddr = rt->rt_src; 66 inet->inet_rcv_saddr = rt->rt_src;
67 inet->daddr = rt->rt_dst; 67 inet->inet_daddr = rt->rt_dst;
68 inet->dport = usin->sin_port; 68 inet->inet_dport = usin->sin_port;
69 sk->sk_state = TCP_ESTABLISHED; 69 sk->sk_state = TCP_ESTABLISHED;
70 inet->id = jiffies; 70 inet->inet_id = jiffies;
71 71
72 sk_dst_set(sk, &rt->u.dst); 72 sk_dst_set(sk, &rt->u.dst);
73 return(0); 73 return(0);
diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
index 5df2f6a0b0f0..90e3d6379a42 100644
--- a/net/ipv4/devinet.c
+++ b/net/ipv4/devinet.c
@@ -50,6 +50,7 @@
50#include <linux/notifier.h> 50#include <linux/notifier.h>
51#include <linux/inetdevice.h> 51#include <linux/inetdevice.h>
52#include <linux/igmp.h> 52#include <linux/igmp.h>
53#include <linux/slab.h>
53#ifdef CONFIG_SYSCTL 54#ifdef CONFIG_SYSCTL
54#include <linux/sysctl.h> 55#include <linux/sysctl.h>
55#endif 56#endif
@@ -64,20 +65,20 @@
64 65
65static struct ipv4_devconf ipv4_devconf = { 66static struct ipv4_devconf ipv4_devconf = {
66 .data = { 67 .data = {
67 [NET_IPV4_CONF_ACCEPT_REDIRECTS - 1] = 1, 68 [IPV4_DEVCONF_ACCEPT_REDIRECTS - 1] = 1,
68 [NET_IPV4_CONF_SEND_REDIRECTS - 1] = 1, 69 [IPV4_DEVCONF_SEND_REDIRECTS - 1] = 1,
69 [NET_IPV4_CONF_SECURE_REDIRECTS - 1] = 1, 70 [IPV4_DEVCONF_SECURE_REDIRECTS - 1] = 1,
70 [NET_IPV4_CONF_SHARED_MEDIA - 1] = 1, 71 [IPV4_DEVCONF_SHARED_MEDIA - 1] = 1,
71 }, 72 },
72}; 73};
73 74
74static struct ipv4_devconf ipv4_devconf_dflt = { 75static struct ipv4_devconf ipv4_devconf_dflt = {
75 .data = { 76 .data = {
76 [NET_IPV4_CONF_ACCEPT_REDIRECTS - 1] = 1, 77 [IPV4_DEVCONF_ACCEPT_REDIRECTS - 1] = 1,
77 [NET_IPV4_CONF_SEND_REDIRECTS - 1] = 1, 78 [IPV4_DEVCONF_SEND_REDIRECTS - 1] = 1,
78 [NET_IPV4_CONF_SECURE_REDIRECTS - 1] = 1, 79 [IPV4_DEVCONF_SECURE_REDIRECTS - 1] = 1,
79 [NET_IPV4_CONF_SHARED_MEDIA - 1] = 1, 80 [IPV4_DEVCONF_SHARED_MEDIA - 1] = 1,
80 [NET_IPV4_CONF_ACCEPT_SOURCE_ROUTE - 1] = 1, 81 [IPV4_DEVCONF_ACCEPT_SOURCE_ROUTE - 1] = 1,
81 }, 82 },
82}; 83};
83 84
@@ -140,11 +141,11 @@ void in_dev_finish_destroy(struct in_device *idev)
140#endif 141#endif
141 dev_put(dev); 142 dev_put(dev);
142 if (!idev->dead) 143 if (!idev->dead)
143 printk("Freeing alive in_device %p\n", idev); 144 pr_err("Freeing alive in_device %p\n", idev);
144 else { 145 else
145 kfree(idev); 146 kfree(idev);
146 }
147} 147}
148EXPORT_SYMBOL(in_dev_finish_destroy);
148 149
149static struct in_device *inetdev_init(struct net_device *dev) 150static struct in_device *inetdev_init(struct net_device *dev)
150{ 151{
@@ -159,7 +160,8 @@ static struct in_device *inetdev_init(struct net_device *dev)
159 sizeof(in_dev->cnf)); 160 sizeof(in_dev->cnf));
160 in_dev->cnf.sysctl = NULL; 161 in_dev->cnf.sysctl = NULL;
161 in_dev->dev = dev; 162 in_dev->dev = dev;
162 if ((in_dev->arp_parms = neigh_parms_alloc(dev, &arp_tbl)) == NULL) 163 in_dev->arp_parms = neigh_parms_alloc(dev, &arp_tbl);
164 if (!in_dev->arp_parms)
163 goto out_kfree; 165 goto out_kfree;
164 if (IPV4_DEVCONF(in_dev->cnf, FORWARDING)) 166 if (IPV4_DEVCONF(in_dev->cnf, FORWARDING))
165 dev_disable_lro(dev); 167 dev_disable_lro(dev);
@@ -405,13 +407,15 @@ struct in_device *inetdev_by_index(struct net *net, int ifindex)
405{ 407{
406 struct net_device *dev; 408 struct net_device *dev;
407 struct in_device *in_dev = NULL; 409 struct in_device *in_dev = NULL;
408 read_lock(&dev_base_lock); 410
409 dev = __dev_get_by_index(net, ifindex); 411 rcu_read_lock();
412 dev = dev_get_by_index_rcu(net, ifindex);
410 if (dev) 413 if (dev)
411 in_dev = in_dev_get(dev); 414 in_dev = in_dev_get(dev);
412 read_unlock(&dev_base_lock); 415 rcu_read_unlock();
413 return in_dev; 416 return in_dev;
414} 417}
418EXPORT_SYMBOL(inetdev_by_index);
415 419
416/* Called only from RTNL semaphored context. No locks. */ 420/* Called only from RTNL semaphored context. No locks. */
417 421
@@ -557,7 +561,7 @@ static int inet_rtm_newaddr(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg
557 * Determine a default network mask, based on the IP address. 561 * Determine a default network mask, based on the IP address.
558 */ 562 */
559 563
560static __inline__ int inet_abc_len(__be32 addr) 564static inline int inet_abc_len(__be32 addr)
561{ 565{
562 int rc = -1; /* Something else, probably a multicast. */ 566 int rc = -1; /* Something else, probably a multicast. */
563 567
@@ -646,13 +650,15 @@ int devinet_ioctl(struct net *net, unsigned int cmd, void __user *arg)
646 rtnl_lock(); 650 rtnl_lock();
647 651
648 ret = -ENODEV; 652 ret = -ENODEV;
649 if ((dev = __dev_get_by_name(net, ifr.ifr_name)) == NULL) 653 dev = __dev_get_by_name(net, ifr.ifr_name);
654 if (!dev)
650 goto done; 655 goto done;
651 656
652 if (colon) 657 if (colon)
653 *colon = ':'; 658 *colon = ':';
654 659
655 if ((in_dev = __in_dev_get_rtnl(dev)) != NULL) { 660 in_dev = __in_dev_get_rtnl(dev);
661 if (in_dev) {
656 if (tryaddrmatch) { 662 if (tryaddrmatch) {
657 /* Matthias Andree */ 663 /* Matthias Andree */
658 /* compare label and address (4.4BSD style) */ 664 /* compare label and address (4.4BSD style) */
@@ -720,7 +726,8 @@ int devinet_ioctl(struct net *net, unsigned int cmd, void __user *arg)
720 726
721 if (!ifa) { 727 if (!ifa) {
722 ret = -ENOBUFS; 728 ret = -ENOBUFS;
723 if ((ifa = inet_alloc_ifa()) == NULL) 729 ifa = inet_alloc_ifa();
730 if (!ifa)
724 break; 731 break;
725 if (colon) 732 if (colon)
726 memcpy(ifa->ifa_label, ifr.ifr_name, IFNAMSIZ); 733 memcpy(ifa->ifa_label, ifr.ifr_name, IFNAMSIZ);
@@ -822,10 +829,10 @@ static int inet_gifconf(struct net_device *dev, char __user *buf, int len)
822 struct ifreq ifr; 829 struct ifreq ifr;
823 int done = 0; 830 int done = 0;
824 831
825 if (!in_dev || (ifa = in_dev->ifa_list) == NULL) 832 if (!in_dev)
826 goto out; 833 goto out;
827 834
828 for (; ifa; ifa = ifa->ifa_next) { 835 for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) {
829 if (!buf) { 836 if (!buf) {
830 done += sizeof(ifr); 837 done += sizeof(ifr);
831 continue; 838 continue;
@@ -875,36 +882,33 @@ __be32 inet_select_addr(const struct net_device *dev, __be32 dst, int scope)
875 if (!addr) 882 if (!addr)
876 addr = ifa->ifa_local; 883 addr = ifa->ifa_local;
877 } endfor_ifa(in_dev); 884 } endfor_ifa(in_dev);
878no_in_dev:
879 rcu_read_unlock();
880 885
881 if (addr) 886 if (addr)
882 goto out; 887 goto out_unlock;
888no_in_dev:
883 889
884 /* Not loopback addresses on loopback should be preferred 890 /* Not loopback addresses on loopback should be preferred
885 in this case. It is importnat that lo is the first interface 891 in this case. It is importnat that lo is the first interface
886 in dev_base list. 892 in dev_base list.
887 */ 893 */
888 read_lock(&dev_base_lock); 894 for_each_netdev_rcu(net, dev) {
889 rcu_read_lock(); 895 in_dev = __in_dev_get_rcu(dev);
890 for_each_netdev(net, dev) { 896 if (!in_dev)
891 if ((in_dev = __in_dev_get_rcu(dev)) == NULL)
892 continue; 897 continue;
893 898
894 for_primary_ifa(in_dev) { 899 for_primary_ifa(in_dev) {
895 if (ifa->ifa_scope != RT_SCOPE_LINK && 900 if (ifa->ifa_scope != RT_SCOPE_LINK &&
896 ifa->ifa_scope <= scope) { 901 ifa->ifa_scope <= scope) {
897 addr = ifa->ifa_local; 902 addr = ifa->ifa_local;
898 goto out_unlock_both; 903 goto out_unlock;
899 } 904 }
900 } endfor_ifa(in_dev); 905 } endfor_ifa(in_dev);
901 } 906 }
902out_unlock_both: 907out_unlock:
903 read_unlock(&dev_base_lock);
904 rcu_read_unlock(); 908 rcu_read_unlock();
905out:
906 return addr; 909 return addr;
907} 910}
911EXPORT_SYMBOL(inet_select_addr);
908 912
909static __be32 confirm_addr_indev(struct in_device *in_dev, __be32 dst, 913static __be32 confirm_addr_indev(struct in_device *in_dev, __be32 dst,
910 __be32 local, int scope) 914 __be32 local, int scope)
@@ -940,7 +944,7 @@ static __be32 confirm_addr_indev(struct in_device *in_dev, __be32 dst,
940 } 944 }
941 } endfor_ifa(in_dev); 945 } endfor_ifa(in_dev);
942 946
943 return same? addr : 0; 947 return same ? addr : 0;
944} 948}
945 949
946/* 950/*
@@ -961,17 +965,16 @@ __be32 inet_confirm_addr(struct in_device *in_dev,
961 return confirm_addr_indev(in_dev, dst, local, scope); 965 return confirm_addr_indev(in_dev, dst, local, scope);
962 966
963 net = dev_net(in_dev->dev); 967 net = dev_net(in_dev->dev);
964 read_lock(&dev_base_lock);
965 rcu_read_lock(); 968 rcu_read_lock();
966 for_each_netdev(net, dev) { 969 for_each_netdev_rcu(net, dev) {
967 if ((in_dev = __in_dev_get_rcu(dev))) { 970 in_dev = __in_dev_get_rcu(dev);
971 if (in_dev) {
968 addr = confirm_addr_indev(in_dev, dst, local, scope); 972 addr = confirm_addr_indev(in_dev, dst, local, scope);
969 if (addr) 973 if (addr)
970 break; 974 break;
971 } 975 }
972 } 976 }
973 rcu_read_unlock(); 977 rcu_read_unlock();
974 read_unlock(&dev_base_lock);
975 978
976 return addr; 979 return addr;
977} 980}
@@ -984,14 +987,16 @@ int register_inetaddr_notifier(struct notifier_block *nb)
984{ 987{
985 return blocking_notifier_chain_register(&inetaddr_chain, nb); 988 return blocking_notifier_chain_register(&inetaddr_chain, nb);
986} 989}
990EXPORT_SYMBOL(register_inetaddr_notifier);
987 991
988int unregister_inetaddr_notifier(struct notifier_block *nb) 992int unregister_inetaddr_notifier(struct notifier_block *nb)
989{ 993{
990 return blocking_notifier_chain_unregister(&inetaddr_chain, nb); 994 return blocking_notifier_chain_unregister(&inetaddr_chain, nb);
991} 995}
996EXPORT_SYMBOL(unregister_inetaddr_notifier);
992 997
993/* Rename ifa_labels for a device name change. Make some effort to preserve existing 998/* Rename ifa_labels for a device name change. Make some effort to preserve
994 * alias numbering and to create unique labels if possible. 999 * existing alias numbering and to create unique labels if possible.
995*/ 1000*/
996static void inetdev_changename(struct net_device *dev, struct in_device *in_dev) 1001static void inetdev_changename(struct net_device *dev, struct in_device *in_dev)
997{ 1002{
@@ -1010,11 +1015,10 @@ static void inetdev_changename(struct net_device *dev, struct in_device *in_dev)
1010 sprintf(old, ":%d", named); 1015 sprintf(old, ":%d", named);
1011 dot = old; 1016 dot = old;
1012 } 1017 }
1013 if (strlen(dot) + strlen(dev->name) < IFNAMSIZ) { 1018 if (strlen(dot) + strlen(dev->name) < IFNAMSIZ)
1014 strcat(ifa->ifa_label, dot); 1019 strcat(ifa->ifa_label, dot);
1015 } else { 1020 else
1016 strcpy(ifa->ifa_label + (IFNAMSIZ - strlen(dot) - 1), dot); 1021 strcpy(ifa->ifa_label + (IFNAMSIZ - strlen(dot) - 1), dot);
1017 }
1018skip: 1022skip:
1019 rtmsg_ifa(RTM_NEWADDR, ifa, NULL, 0); 1023 rtmsg_ifa(RTM_NEWADDR, ifa, NULL, 0);
1020 } 1024 }
@@ -1061,8 +1065,9 @@ static int inetdev_event(struct notifier_block *this, unsigned long event,
1061 if (!inetdev_valid_mtu(dev->mtu)) 1065 if (!inetdev_valid_mtu(dev->mtu))
1062 break; 1066 break;
1063 if (dev->flags & IFF_LOOPBACK) { 1067 if (dev->flags & IFF_LOOPBACK) {
1064 struct in_ifaddr *ifa; 1068 struct in_ifaddr *ifa = inet_alloc_ifa();
1065 if ((ifa = inet_alloc_ifa()) != NULL) { 1069
1070 if (ifa) {
1066 ifa->ifa_local = 1071 ifa->ifa_local =
1067 ifa->ifa_address = htonl(INADDR_LOOPBACK); 1072 ifa->ifa_address = htonl(INADDR_LOOPBACK);
1068 ifa->ifa_prefixlen = 8; 1073 ifa->ifa_prefixlen = 8;
@@ -1170,38 +1175,54 @@ nla_put_failure:
1170static int inet_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb) 1175static int inet_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
1171{ 1176{
1172 struct net *net = sock_net(skb->sk); 1177 struct net *net = sock_net(skb->sk);
1173 int idx, ip_idx; 1178 int h, s_h;
1179 int idx, s_idx;
1180 int ip_idx, s_ip_idx;
1174 struct net_device *dev; 1181 struct net_device *dev;
1175 struct in_device *in_dev; 1182 struct in_device *in_dev;
1176 struct in_ifaddr *ifa; 1183 struct in_ifaddr *ifa;
1177 int s_ip_idx, s_idx = cb->args[0]; 1184 struct hlist_head *head;
1185 struct hlist_node *node;
1178 1186
1179 s_ip_idx = ip_idx = cb->args[1]; 1187 s_h = cb->args[0];
1180 idx = 0; 1188 s_idx = idx = cb->args[1];
1181 for_each_netdev(net, dev) { 1189 s_ip_idx = ip_idx = cb->args[2];
1182 if (idx < s_idx) 1190
1183 goto cont; 1191 for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) {
1184 if (idx > s_idx) 1192 idx = 0;
1185 s_ip_idx = 0; 1193 head = &net->dev_index_head[h];
1186 if ((in_dev = __in_dev_get_rtnl(dev)) == NULL) 1194 rcu_read_lock();
1187 goto cont; 1195 hlist_for_each_entry_rcu(dev, node, head, index_hlist) {
1188 1196 if (idx < s_idx)
1189 for (ifa = in_dev->ifa_list, ip_idx = 0; ifa; 1197 goto cont;
1190 ifa = ifa->ifa_next, ip_idx++) { 1198 if (h > s_h || idx > s_idx)
1191 if (ip_idx < s_ip_idx) 1199 s_ip_idx = 0;
1192 continue; 1200 in_dev = __in_dev_get_rcu(dev);
1193 if (inet_fill_ifaddr(skb, ifa, NETLINK_CB(cb->skb).pid, 1201 if (!in_dev)
1202 goto cont;
1203
1204 for (ifa = in_dev->ifa_list, ip_idx = 0; ifa;
1205 ifa = ifa->ifa_next, ip_idx++) {
1206 if (ip_idx < s_ip_idx)
1207 continue;
1208 if (inet_fill_ifaddr(skb, ifa,
1209 NETLINK_CB(cb->skb).pid,
1194 cb->nlh->nlmsg_seq, 1210 cb->nlh->nlmsg_seq,
1195 RTM_NEWADDR, NLM_F_MULTI) <= 0) 1211 RTM_NEWADDR, NLM_F_MULTI) <= 0) {
1196 goto done; 1212 rcu_read_unlock();
1197 } 1213 goto done;
1214 }
1215 }
1198cont: 1216cont:
1199 idx++; 1217 idx++;
1218 }
1219 rcu_read_unlock();
1200 } 1220 }
1201 1221
1202done: 1222done:
1203 cb->args[0] = idx; 1223 cb->args[0] = h;
1204 cb->args[1] = ip_idx; 1224 cb->args[1] = idx;
1225 cb->args[2] = ip_idx;
1205 1226
1206 return skb->len; 1227 return skb->len;
1207} 1228}
@@ -1239,18 +1260,18 @@ static void devinet_copy_dflt_conf(struct net *net, int i)
1239{ 1260{
1240 struct net_device *dev; 1261 struct net_device *dev;
1241 1262
1242 read_lock(&dev_base_lock); 1263 rcu_read_lock();
1243 for_each_netdev(net, dev) { 1264 for_each_netdev_rcu(net, dev) {
1244 struct in_device *in_dev; 1265 struct in_device *in_dev;
1245 rcu_read_lock(); 1266
1246 in_dev = __in_dev_get_rcu(dev); 1267 in_dev = __in_dev_get_rcu(dev);
1247 if (in_dev && !test_bit(i, in_dev->cnf.state)) 1268 if (in_dev && !test_bit(i, in_dev->cnf.state))
1248 in_dev->cnf.data[i] = net->ipv4.devconf_dflt->data[i]; 1269 in_dev->cnf.data[i] = net->ipv4.devconf_dflt->data[i];
1249 rcu_read_unlock();
1250 } 1270 }
1251 read_unlock(&dev_base_lock); 1271 rcu_read_unlock();
1252} 1272}
1253 1273
1274/* called with RTNL locked */
1254static void inet_forward_change(struct net *net) 1275static void inet_forward_change(struct net *net)
1255{ 1276{
1256 struct net_device *dev; 1277 struct net_device *dev;
@@ -1259,7 +1280,6 @@ static void inet_forward_change(struct net *net)
1259 IPV4_DEVCONF_ALL(net, ACCEPT_REDIRECTS) = !on; 1280 IPV4_DEVCONF_ALL(net, ACCEPT_REDIRECTS) = !on;
1260 IPV4_DEVCONF_DFLT(net, FORWARDING) = on; 1281 IPV4_DEVCONF_DFLT(net, FORWARDING) = on;
1261 1282
1262 read_lock(&dev_base_lock);
1263 for_each_netdev(net, dev) { 1283 for_each_netdev(net, dev) {
1264 struct in_device *in_dev; 1284 struct in_device *in_dev;
1265 if (on) 1285 if (on)
@@ -1270,7 +1290,6 @@ static void inet_forward_change(struct net *net)
1270 IN_DEV_CONF_SET(in_dev, FORWARDING, on); 1290 IN_DEV_CONF_SET(in_dev, FORWARDING, on);
1271 rcu_read_unlock(); 1291 rcu_read_unlock();
1272 } 1292 }
1273 read_unlock(&dev_base_lock);
1274} 1293}
1275 1294
1276static int devinet_conf_proc(ctl_table *ctl, int write, 1295static int devinet_conf_proc(ctl_table *ctl, int write,
@@ -1293,72 +1312,25 @@ static int devinet_conf_proc(ctl_table *ctl, int write,
1293 return ret; 1312 return ret;
1294} 1313}
1295 1314
1296static int devinet_conf_sysctl(ctl_table *table,
1297 void __user *oldval, size_t __user *oldlenp,
1298 void __user *newval, size_t newlen)
1299{
1300 struct ipv4_devconf *cnf;
1301 struct net *net;
1302 int *valp = table->data;
1303 int new;
1304 int i;
1305
1306 if (!newval || !newlen)
1307 return 0;
1308
1309 if (newlen != sizeof(int))
1310 return -EINVAL;
1311
1312 if (get_user(new, (int __user *)newval))
1313 return -EFAULT;
1314
1315 if (new == *valp)
1316 return 0;
1317
1318 if (oldval && oldlenp) {
1319 size_t len;
1320
1321 if (get_user(len, oldlenp))
1322 return -EFAULT;
1323
1324 if (len) {
1325 if (len > table->maxlen)
1326 len = table->maxlen;
1327 if (copy_to_user(oldval, valp, len))
1328 return -EFAULT;
1329 if (put_user(len, oldlenp))
1330 return -EFAULT;
1331 }
1332 }
1333
1334 *valp = new;
1335
1336 cnf = table->extra1;
1337 net = table->extra2;
1338 i = (int *)table->data - cnf->data;
1339
1340 set_bit(i, cnf->state);
1341
1342 if (cnf == net->ipv4.devconf_dflt)
1343 devinet_copy_dflt_conf(net, i);
1344
1345 return 1;
1346}
1347
1348static int devinet_sysctl_forward(ctl_table *ctl, int write, 1315static int devinet_sysctl_forward(ctl_table *ctl, int write,
1349 void __user *buffer, 1316 void __user *buffer,
1350 size_t *lenp, loff_t *ppos) 1317 size_t *lenp, loff_t *ppos)
1351{ 1318{
1352 int *valp = ctl->data; 1319 int *valp = ctl->data;
1353 int val = *valp; 1320 int val = *valp;
1321 loff_t pos = *ppos;
1354 int ret = proc_dointvec(ctl, write, buffer, lenp, ppos); 1322 int ret = proc_dointvec(ctl, write, buffer, lenp, ppos);
1355 1323
1356 if (write && *valp != val) { 1324 if (write && *valp != val) {
1357 struct net *net = ctl->extra2; 1325 struct net *net = ctl->extra2;
1358 1326
1359 if (valp != &IPV4_DEVCONF_DFLT(net, FORWARDING)) { 1327 if (valp != &IPV4_DEVCONF_DFLT(net, FORWARDING)) {
1360 if (!rtnl_trylock()) 1328 if (!rtnl_trylock()) {
1329 /* Restore the original values before restarting */
1330 *valp = val;
1331 *ppos = pos;
1361 return restart_syscall(); 1332 return restart_syscall();
1333 }
1362 if (valp == &IPV4_DEVCONF_ALL(net, FORWARDING)) { 1334 if (valp == &IPV4_DEVCONF_ALL(net, FORWARDING)) {
1363 inet_forward_change(net); 1335 inet_forward_change(net);
1364 } else if (*valp) { 1336 } else if (*valp) {
@@ -1390,57 +1362,37 @@ int ipv4_doint_and_flush(ctl_table *ctl, int write,
1390 return ret; 1362 return ret;
1391} 1363}
1392 1364
1393int ipv4_doint_and_flush_strategy(ctl_table *table, 1365#define DEVINET_SYSCTL_ENTRY(attr, name, mval, proc) \
1394 void __user *oldval, size_t __user *oldlenp,
1395 void __user *newval, size_t newlen)
1396{
1397 int ret = devinet_conf_sysctl(table, oldval, oldlenp, newval, newlen);
1398 struct net *net = table->extra2;
1399
1400 if (ret == 1)
1401 rt_cache_flush(net, 0);
1402
1403 return ret;
1404}
1405
1406
1407#define DEVINET_SYSCTL_ENTRY(attr, name, mval, proc, sysctl) \
1408 { \ 1366 { \
1409 .ctl_name = NET_IPV4_CONF_ ## attr, \
1410 .procname = name, \ 1367 .procname = name, \
1411 .data = ipv4_devconf.data + \ 1368 .data = ipv4_devconf.data + \
1412 NET_IPV4_CONF_ ## attr - 1, \ 1369 IPV4_DEVCONF_ ## attr - 1, \
1413 .maxlen = sizeof(int), \ 1370 .maxlen = sizeof(int), \
1414 .mode = mval, \ 1371 .mode = mval, \
1415 .proc_handler = proc, \ 1372 .proc_handler = proc, \
1416 .strategy = sysctl, \
1417 .extra1 = &ipv4_devconf, \ 1373 .extra1 = &ipv4_devconf, \
1418 } 1374 }
1419 1375
1420#define DEVINET_SYSCTL_RW_ENTRY(attr, name) \ 1376#define DEVINET_SYSCTL_RW_ENTRY(attr, name) \
1421 DEVINET_SYSCTL_ENTRY(attr, name, 0644, devinet_conf_proc, \ 1377 DEVINET_SYSCTL_ENTRY(attr, name, 0644, devinet_conf_proc)
1422 devinet_conf_sysctl)
1423 1378
1424#define DEVINET_SYSCTL_RO_ENTRY(attr, name) \ 1379#define DEVINET_SYSCTL_RO_ENTRY(attr, name) \
1425 DEVINET_SYSCTL_ENTRY(attr, name, 0444, devinet_conf_proc, \ 1380 DEVINET_SYSCTL_ENTRY(attr, name, 0444, devinet_conf_proc)
1426 devinet_conf_sysctl)
1427 1381
1428#define DEVINET_SYSCTL_COMPLEX_ENTRY(attr, name, proc, sysctl) \ 1382#define DEVINET_SYSCTL_COMPLEX_ENTRY(attr, name, proc) \
1429 DEVINET_SYSCTL_ENTRY(attr, name, 0644, proc, sysctl) 1383 DEVINET_SYSCTL_ENTRY(attr, name, 0644, proc)
1430 1384
1431#define DEVINET_SYSCTL_FLUSHING_ENTRY(attr, name) \ 1385#define DEVINET_SYSCTL_FLUSHING_ENTRY(attr, name) \
1432 DEVINET_SYSCTL_COMPLEX_ENTRY(attr, name, ipv4_doint_and_flush, \ 1386 DEVINET_SYSCTL_COMPLEX_ENTRY(attr, name, ipv4_doint_and_flush)
1433 ipv4_doint_and_flush_strategy)
1434 1387
1435static struct devinet_sysctl_table { 1388static struct devinet_sysctl_table {
1436 struct ctl_table_header *sysctl_header; 1389 struct ctl_table_header *sysctl_header;
1437 struct ctl_table devinet_vars[__NET_IPV4_CONF_MAX]; 1390 struct ctl_table devinet_vars[__IPV4_DEVCONF_MAX];
1438 char *dev_name; 1391 char *dev_name;
1439} devinet_sysctl = { 1392} devinet_sysctl = {
1440 .devinet_vars = { 1393 .devinet_vars = {
1441 DEVINET_SYSCTL_COMPLEX_ENTRY(FORWARDING, "forwarding", 1394 DEVINET_SYSCTL_COMPLEX_ENTRY(FORWARDING, "forwarding",
1442 devinet_sysctl_forward, 1395 devinet_sysctl_forward),
1443 devinet_conf_sysctl),
1444 DEVINET_SYSCTL_RO_ENTRY(MC_FORWARDING, "mc_forwarding"), 1396 DEVINET_SYSCTL_RO_ENTRY(MC_FORWARDING, "mc_forwarding"),
1445 1397
1446 DEVINET_SYSCTL_RW_ENTRY(ACCEPT_REDIRECTS, "accept_redirects"), 1398 DEVINET_SYSCTL_RW_ENTRY(ACCEPT_REDIRECTS, "accept_redirects"),
@@ -1450,6 +1402,8 @@ static struct devinet_sysctl_table {
1450 DEVINET_SYSCTL_RW_ENTRY(SEND_REDIRECTS, "send_redirects"), 1402 DEVINET_SYSCTL_RW_ENTRY(SEND_REDIRECTS, "send_redirects"),
1451 DEVINET_SYSCTL_RW_ENTRY(ACCEPT_SOURCE_ROUTE, 1403 DEVINET_SYSCTL_RW_ENTRY(ACCEPT_SOURCE_ROUTE,
1452 "accept_source_route"), 1404 "accept_source_route"),
1405 DEVINET_SYSCTL_RW_ENTRY(ACCEPT_LOCAL, "accept_local"),
1406 DEVINET_SYSCTL_RW_ENTRY(SRC_VMARK, "src_valid_mark"),
1453 DEVINET_SYSCTL_RW_ENTRY(PROXY_ARP, "proxy_arp"), 1407 DEVINET_SYSCTL_RW_ENTRY(PROXY_ARP, "proxy_arp"),
1454 DEVINET_SYSCTL_RW_ENTRY(MEDIUM_ID, "medium_id"), 1408 DEVINET_SYSCTL_RW_ENTRY(MEDIUM_ID, "medium_id"),
1455 DEVINET_SYSCTL_RW_ENTRY(BOOTP_RELAY, "bootp_relay"), 1409 DEVINET_SYSCTL_RW_ENTRY(BOOTP_RELAY, "bootp_relay"),
@@ -1460,6 +1414,7 @@ static struct devinet_sysctl_table {
1460 DEVINET_SYSCTL_RW_ENTRY(ARP_IGNORE, "arp_ignore"), 1414 DEVINET_SYSCTL_RW_ENTRY(ARP_IGNORE, "arp_ignore"),
1461 DEVINET_SYSCTL_RW_ENTRY(ARP_ACCEPT, "arp_accept"), 1415 DEVINET_SYSCTL_RW_ENTRY(ARP_ACCEPT, "arp_accept"),
1462 DEVINET_SYSCTL_RW_ENTRY(ARP_NOTIFY, "arp_notify"), 1416 DEVINET_SYSCTL_RW_ENTRY(ARP_NOTIFY, "arp_notify"),
1417 DEVINET_SYSCTL_RW_ENTRY(PROXY_ARP_PVLAN, "proxy_arp_pvlan"),
1463 1418
1464 DEVINET_SYSCTL_FLUSHING_ENTRY(NOXFRM, "disable_xfrm"), 1419 DEVINET_SYSCTL_FLUSHING_ENTRY(NOXFRM, "disable_xfrm"),
1465 DEVINET_SYSCTL_FLUSHING_ENTRY(NOPOLICY, "disable_policy"), 1420 DEVINET_SYSCTL_FLUSHING_ENTRY(NOPOLICY, "disable_policy"),
@@ -1471,7 +1426,7 @@ static struct devinet_sysctl_table {
1471}; 1426};
1472 1427
1473static int __devinet_sysctl_register(struct net *net, char *dev_name, 1428static int __devinet_sysctl_register(struct net *net, char *dev_name,
1474 int ctl_name, struct ipv4_devconf *p) 1429 struct ipv4_devconf *p)
1475{ 1430{
1476 int i; 1431 int i;
1477 struct devinet_sysctl_table *t; 1432 struct devinet_sysctl_table *t;
@@ -1479,9 +1434,9 @@ static int __devinet_sysctl_register(struct net *net, char *dev_name,
1479#define DEVINET_CTL_PATH_DEV 3 1434#define DEVINET_CTL_PATH_DEV 3
1480 1435
1481 struct ctl_path devinet_ctl_path[] = { 1436 struct ctl_path devinet_ctl_path[] = {
1482 { .procname = "net", .ctl_name = CTL_NET, }, 1437 { .procname = "net", },
1483 { .procname = "ipv4", .ctl_name = NET_IPV4, }, 1438 { .procname = "ipv4", },
1484 { .procname = "conf", .ctl_name = NET_IPV4_CONF, }, 1439 { .procname = "conf", },
1485 { /* to be set */ }, 1440 { /* to be set */ },
1486 { }, 1441 { },
1487 }; 1442 };
@@ -1506,7 +1461,6 @@ static int __devinet_sysctl_register(struct net *net, char *dev_name,
1506 goto free; 1461 goto free;
1507 1462
1508 devinet_ctl_path[DEVINET_CTL_PATH_DEV].procname = t->dev_name; 1463 devinet_ctl_path[DEVINET_CTL_PATH_DEV].procname = t->dev_name;
1509 devinet_ctl_path[DEVINET_CTL_PATH_DEV].ctl_name = ctl_name;
1510 1464
1511 t->sysctl_header = register_net_sysctl_table(net, devinet_ctl_path, 1465 t->sysctl_header = register_net_sysctl_table(net, devinet_ctl_path,
1512 t->devinet_vars); 1466 t->devinet_vars);
@@ -1539,10 +1493,9 @@ static void __devinet_sysctl_unregister(struct ipv4_devconf *cnf)
1539 1493
1540static void devinet_sysctl_register(struct in_device *idev) 1494static void devinet_sysctl_register(struct in_device *idev)
1541{ 1495{
1542 neigh_sysctl_register(idev->dev, idev->arp_parms, NET_IPV4, 1496 neigh_sysctl_register(idev->dev, idev->arp_parms, "ipv4", NULL);
1543 NET_IPV4_NEIGH, "ipv4", NULL, NULL);
1544 __devinet_sysctl_register(dev_net(idev->dev), idev->dev->name, 1497 __devinet_sysctl_register(dev_net(idev->dev), idev->dev->name,
1545 idev->dev->ifindex, &idev->cnf); 1498 &idev->cnf);
1546} 1499}
1547 1500
1548static void devinet_sysctl_unregister(struct in_device *idev) 1501static void devinet_sysctl_unregister(struct in_device *idev)
@@ -1553,14 +1506,12 @@ static void devinet_sysctl_unregister(struct in_device *idev)
1553 1506
1554static struct ctl_table ctl_forward_entry[] = { 1507static struct ctl_table ctl_forward_entry[] = {
1555 { 1508 {
1556 .ctl_name = NET_IPV4_FORWARD,
1557 .procname = "ip_forward", 1509 .procname = "ip_forward",
1558 .data = &ipv4_devconf.data[ 1510 .data = &ipv4_devconf.data[
1559 NET_IPV4_CONF_FORWARDING - 1], 1511 IPV4_DEVCONF_FORWARDING - 1],
1560 .maxlen = sizeof(int), 1512 .maxlen = sizeof(int),
1561 .mode = 0644, 1513 .mode = 0644,
1562 .proc_handler = devinet_sysctl_forward, 1514 .proc_handler = devinet_sysctl_forward,
1563 .strategy = devinet_conf_sysctl,
1564 .extra1 = &ipv4_devconf, 1515 .extra1 = &ipv4_devconf,
1565 .extra2 = &init_net, 1516 .extra2 = &init_net,
1566 }, 1517 },
@@ -1568,8 +1519,8 @@ static struct ctl_table ctl_forward_entry[] = {
1568}; 1519};
1569 1520
1570static __net_initdata struct ctl_path net_ipv4_path[] = { 1521static __net_initdata struct ctl_path net_ipv4_path[] = {
1571 { .procname = "net", .ctl_name = CTL_NET, }, 1522 { .procname = "net", },
1572 { .procname = "ipv4", .ctl_name = NET_IPV4, }, 1523 { .procname = "ipv4", },
1573 { }, 1524 { },
1574}; 1525};
1575#endif 1526#endif
@@ -1587,7 +1538,7 @@ static __net_init int devinet_init_net(struct net *net)
1587 all = &ipv4_devconf; 1538 all = &ipv4_devconf;
1588 dflt = &ipv4_devconf_dflt; 1539 dflt = &ipv4_devconf_dflt;
1589 1540
1590 if (net != &init_net) { 1541 if (!net_eq(net, &init_net)) {
1591 all = kmemdup(all, sizeof(ipv4_devconf), GFP_KERNEL); 1542 all = kmemdup(all, sizeof(ipv4_devconf), GFP_KERNEL);
1592 if (all == NULL) 1543 if (all == NULL)
1593 goto err_alloc_all; 1544 goto err_alloc_all;
@@ -1601,20 +1552,18 @@ static __net_init int devinet_init_net(struct net *net)
1601 if (tbl == NULL) 1552 if (tbl == NULL)
1602 goto err_alloc_ctl; 1553 goto err_alloc_ctl;
1603 1554
1604 tbl[0].data = &all->data[NET_IPV4_CONF_FORWARDING - 1]; 1555 tbl[0].data = &all->data[IPV4_DEVCONF_FORWARDING - 1];
1605 tbl[0].extra1 = all; 1556 tbl[0].extra1 = all;
1606 tbl[0].extra2 = net; 1557 tbl[0].extra2 = net;
1607#endif 1558#endif
1608 } 1559 }
1609 1560
1610#ifdef CONFIG_SYSCTL 1561#ifdef CONFIG_SYSCTL
1611 err = __devinet_sysctl_register(net, "all", 1562 err = __devinet_sysctl_register(net, "all", all);
1612 NET_PROTO_CONF_ALL, all);
1613 if (err < 0) 1563 if (err < 0)
1614 goto err_reg_all; 1564 goto err_reg_all;
1615 1565
1616 err = __devinet_sysctl_register(net, "default", 1566 err = __devinet_sysctl_register(net, "default", dflt);
1617 NET_PROTO_CONF_DEFAULT, dflt);
1618 if (err < 0) 1567 if (err < 0)
1619 goto err_reg_dflt; 1568 goto err_reg_dflt;
1620 1569
@@ -1680,8 +1629,3 @@ void __init devinet_init(void)
1680 rtnl_register(PF_INET, RTM_GETADDR, NULL, inet_dump_ifaddr); 1629 rtnl_register(PF_INET, RTM_GETADDR, NULL, inet_dump_ifaddr);
1681} 1630}
1682 1631
1683EXPORT_SYMBOL(in_dev_finish_destroy);
1684EXPORT_SYMBOL(inet_select_addr);
1685EXPORT_SYMBOL(inetdev_by_index);
1686EXPORT_SYMBOL(register_inetaddr_notifier);
1687EXPORT_SYMBOL(unregister_inetaddr_notifier);
diff --git a/net/ipv4/esp4.c b/net/ipv4/esp4.c
index 12f7287e902d..14ca1f1c3fb0 100644
--- a/net/ipv4/esp4.c
+++ b/net/ipv4/esp4.c
@@ -422,7 +422,7 @@ static void esp4_err(struct sk_buff *skb, u32 info)
422 icmp_hdr(skb)->code != ICMP_FRAG_NEEDED) 422 icmp_hdr(skb)->code != ICMP_FRAG_NEEDED)
423 return; 423 return;
424 424
425 x = xfrm_state_lookup(net, (xfrm_address_t *)&iph->daddr, esph->spi, IPPROTO_ESP, AF_INET); 425 x = xfrm_state_lookup(net, skb->mark, (xfrm_address_t *)&iph->daddr, esph->spi, IPPROTO_ESP, AF_INET);
426 if (!x) 426 if (!x)
427 return; 427 return;
428 NETDEBUG(KERN_DEBUG "pmtu discovery on SA ESP/%08x/%08x\n", 428 NETDEBUG(KERN_DEBUG "pmtu discovery on SA ESP/%08x/%08x\n",
@@ -530,7 +530,7 @@ static int esp_init_authenc(struct xfrm_state *x)
530 } 530 }
531 531
532 err = crypto_aead_setauthsize( 532 err = crypto_aead_setauthsize(
533 aead, aalg_desc->uinfo.auth.icv_truncbits / 8); 533 aead, x->aalg->alg_trunc_len / 8);
534 if (err) 534 if (err)
535 goto free_key; 535 goto free_key;
536 } 536 }
diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
index aa00398be80e..4f0ed458c883 100644
--- a/net/ipv4/fib_frontend.c
+++ b/net/ipv4/fib_frontend.c
@@ -34,6 +34,7 @@
34#include <linux/skbuff.h> 34#include <linux/skbuff.h>
35#include <linux/init.h> 35#include <linux/init.h>
36#include <linux/list.h> 36#include <linux/list.h>
37#include <linux/slab.h>
37 38
38#include <net/ip.h> 39#include <net/ip.h>
39#include <net/protocol.h> 40#include <net/protocol.h>
@@ -125,7 +126,7 @@ void fib_select_default(struct net *net,
125#endif 126#endif
126 tb = fib_get_table(net, table); 127 tb = fib_get_table(net, table);
127 if (FIB_RES_GW(*res) && FIB_RES_NH(*res).nh_scope == RT_SCOPE_LINK) 128 if (FIB_RES_GW(*res) && FIB_RES_NH(*res).nh_scope == RT_SCOPE_LINK)
128 tb->tb_select_default(tb, flp, res); 129 fib_table_select_default(tb, flp, res);
129} 130}
130 131
131static void fib_flush(struct net *net) 132static void fib_flush(struct net *net)
@@ -139,7 +140,7 @@ static void fib_flush(struct net *net)
139 for (h = 0; h < FIB_TABLE_HASHSZ; h++) { 140 for (h = 0; h < FIB_TABLE_HASHSZ; h++) {
140 head = &net->ipv4.fib_table_hash[h]; 141 head = &net->ipv4.fib_table_hash[h];
141 hlist_for_each_entry(tb, node, head, tb_hlist) 142 hlist_for_each_entry(tb, node, head, tb_hlist)
142 flushed += tb->tb_flush(tb); 143 flushed += fib_table_flush(tb);
143 } 144 }
144 145
145 if (flushed) 146 if (flushed)
@@ -162,7 +163,7 @@ struct net_device * ip_dev_find(struct net *net, __be32 addr)
162#endif 163#endif
163 164
164 local_table = fib_get_table(net, RT_TABLE_LOCAL); 165 local_table = fib_get_table(net, RT_TABLE_LOCAL);
165 if (!local_table || local_table->tb_lookup(local_table, &fl, &res)) 166 if (!local_table || fib_table_lookup(local_table, &fl, &res))
166 return NULL; 167 return NULL;
167 if (res.type != RTN_LOCAL) 168 if (res.type != RTN_LOCAL)
168 goto out; 169 goto out;
@@ -200,7 +201,7 @@ static inline unsigned __inet_dev_addr_type(struct net *net,
200 local_table = fib_get_table(net, RT_TABLE_LOCAL); 201 local_table = fib_get_table(net, RT_TABLE_LOCAL);
201 if (local_table) { 202 if (local_table) {
202 ret = RTN_UNICAST; 203 ret = RTN_UNICAST;
203 if (!local_table->tb_lookup(local_table, &fl, &res)) { 204 if (!fib_table_lookup(local_table, &fl, &res)) {
204 if (!dev || dev == res.fi->fib_dev) 205 if (!dev || dev == res.fi->fib_dev)
205 ret = res.type; 206 ret = res.type;
206 fib_res_put(&res); 207 fib_res_put(&res);
@@ -241,16 +242,19 @@ int fib_validate_source(__be32 src, __be32 dst, u8 tos, int oif,
241 .iif = oif }; 242 .iif = oif };
242 243
243 struct fib_result res; 244 struct fib_result res;
244 int no_addr, rpf; 245 int no_addr, rpf, accept_local;
245 int ret; 246 int ret;
246 struct net *net; 247 struct net *net;
247 248
248 no_addr = rpf = 0; 249 no_addr = rpf = accept_local = 0;
249 rcu_read_lock(); 250 rcu_read_lock();
250 in_dev = __in_dev_get_rcu(dev); 251 in_dev = __in_dev_get_rcu(dev);
251 if (in_dev) { 252 if (in_dev) {
252 no_addr = in_dev->ifa_list == NULL; 253 no_addr = in_dev->ifa_list == NULL;
253 rpf = IN_DEV_RPFILTER(in_dev); 254 rpf = IN_DEV_RPFILTER(in_dev);
255 accept_local = IN_DEV_ACCEPT_LOCAL(in_dev);
256 if (mark && !IN_DEV_SRC_VMARK(in_dev))
257 fl.mark = 0;
254 } 258 }
255 rcu_read_unlock(); 259 rcu_read_unlock();
256 260
@@ -260,8 +264,10 @@ int fib_validate_source(__be32 src, __be32 dst, u8 tos, int oif,
260 net = dev_net(dev); 264 net = dev_net(dev);
261 if (fib_lookup(net, &fl, &res)) 265 if (fib_lookup(net, &fl, &res))
262 goto last_resort; 266 goto last_resort;
263 if (res.type != RTN_UNICAST) 267 if (res.type != RTN_UNICAST) {
264 goto e_inval_res; 268 if (res.type != RTN_LOCAL || !accept_local)
269 goto e_inval_res;
270 }
265 *spec_dst = FIB_RES_PREFSRC(res); 271 *spec_dst = FIB_RES_PREFSRC(res);
266 fib_combine_itag(itag, &res); 272 fib_combine_itag(itag, &res);
267#ifdef CONFIG_IP_ROUTE_MULTIPATH 273#ifdef CONFIG_IP_ROUTE_MULTIPATH
@@ -476,13 +482,13 @@ int ip_rt_ioctl(struct net *net, unsigned int cmd, void __user *arg)
476 if (cmd == SIOCDELRT) { 482 if (cmd == SIOCDELRT) {
477 tb = fib_get_table(net, cfg.fc_table); 483 tb = fib_get_table(net, cfg.fc_table);
478 if (tb) 484 if (tb)
479 err = tb->tb_delete(tb, &cfg); 485 err = fib_table_delete(tb, &cfg);
480 else 486 else
481 err = -ESRCH; 487 err = -ESRCH;
482 } else { 488 } else {
483 tb = fib_new_table(net, cfg.fc_table); 489 tb = fib_new_table(net, cfg.fc_table);
484 if (tb) 490 if (tb)
485 err = tb->tb_insert(tb, &cfg); 491 err = fib_table_insert(tb, &cfg);
486 else 492 else
487 err = -ENOBUFS; 493 err = -ENOBUFS;
488 } 494 }
@@ -597,7 +603,7 @@ static int inet_rtm_delroute(struct sk_buff *skb, struct nlmsghdr *nlh, void *ar
597 goto errout; 603 goto errout;
598 } 604 }
599 605
600 err = tb->tb_delete(tb, &cfg); 606 err = fib_table_delete(tb, &cfg);
601errout: 607errout:
602 return err; 608 return err;
603} 609}
@@ -619,7 +625,7 @@ static int inet_rtm_newroute(struct sk_buff *skb, struct nlmsghdr *nlh, void *ar
619 goto errout; 625 goto errout;
620 } 626 }
621 627
622 err = tb->tb_insert(tb, &cfg); 628 err = fib_table_insert(tb, &cfg);
623errout: 629errout:
624 return err; 630 return err;
625} 631}
@@ -650,7 +656,7 @@ static int inet_dump_fib(struct sk_buff *skb, struct netlink_callback *cb)
650 if (dumped) 656 if (dumped)
651 memset(&cb->args[2], 0, sizeof(cb->args) - 657 memset(&cb->args[2], 0, sizeof(cb->args) -
652 2 * sizeof(cb->args[0])); 658 2 * sizeof(cb->args[0]));
653 if (tb->tb_dump(tb, skb, cb) < 0) 659 if (fib_table_dump(tb, skb, cb) < 0)
654 goto out; 660 goto out;
655 dumped = 1; 661 dumped = 1;
656next: 662next:
@@ -704,9 +710,9 @@ static void fib_magic(int cmd, int type, __be32 dst, int dst_len, struct in_ifad
704 cfg.fc_scope = RT_SCOPE_HOST; 710 cfg.fc_scope = RT_SCOPE_HOST;
705 711
706 if (cmd == RTM_NEWROUTE) 712 if (cmd == RTM_NEWROUTE)
707 tb->tb_insert(tb, &cfg); 713 fib_table_insert(tb, &cfg);
708 else 714 else
709 tb->tb_delete(tb, &cfg); 715 fib_table_delete(tb, &cfg);
710} 716}
711 717
712void fib_add_ifaddr(struct in_ifaddr *ifa) 718void fib_add_ifaddr(struct in_ifaddr *ifa)
@@ -835,7 +841,7 @@ static void nl_fib_lookup(struct fib_result_nl *frn, struct fib_table *tb )
835 local_bh_disable(); 841 local_bh_disable();
836 842
837 frn->tb_id = tb->tb_id; 843 frn->tb_id = tb->tb_id;
838 frn->err = tb->tb_lookup(tb, &fl, &res); 844 frn->err = fib_table_lookup(tb, &fl, &res);
839 845
840 if (!frn->err) { 846 if (!frn->err) {
841 frn->prefixlen = res.prefixlen; 847 frn->prefixlen = res.prefixlen;
@@ -878,7 +884,7 @@ static void nl_fib_input(struct sk_buff *skb)
878 netlink_unicast(net->ipv4.fibnl, skb, pid, MSG_DONTWAIT); 884 netlink_unicast(net->ipv4.fibnl, skb, pid, MSG_DONTWAIT);
879} 885}
880 886
881static int nl_fib_lookup_init(struct net *net) 887static int __net_init nl_fib_lookup_init(struct net *net)
882{ 888{
883 struct sock *sk; 889 struct sock *sk;
884 sk = netlink_kernel_create(net, NETLINK_FIB_LOOKUP, 0, 890 sk = netlink_kernel_create(net, NETLINK_FIB_LOOKUP, 0,
@@ -895,11 +901,11 @@ static void nl_fib_lookup_exit(struct net *net)
895 net->ipv4.fibnl = NULL; 901 net->ipv4.fibnl = NULL;
896} 902}
897 903
898static void fib_disable_ip(struct net_device *dev, int force) 904static void fib_disable_ip(struct net_device *dev, int force, int delay)
899{ 905{
900 if (fib_sync_down_dev(dev, force)) 906 if (fib_sync_down_dev(dev, force))
901 fib_flush(dev_net(dev)); 907 fib_flush(dev_net(dev));
902 rt_cache_flush(dev_net(dev), 0); 908 rt_cache_flush(dev_net(dev), delay);
903 arp_ifdown(dev); 909 arp_ifdown(dev);
904} 910}
905 911
@@ -922,7 +928,7 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
922 /* Last address was deleted from this interface. 928 /* Last address was deleted from this interface.
923 Disable IP. 929 Disable IP.
924 */ 930 */
925 fib_disable_ip(dev, 1); 931 fib_disable_ip(dev, 1, 0);
926 } else { 932 } else {
927 rt_cache_flush(dev_net(dev), -1); 933 rt_cache_flush(dev_net(dev), -1);
928 } 934 }
@@ -937,7 +943,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
937 struct in_device *in_dev = __in_dev_get_rtnl(dev); 943 struct in_device *in_dev = __in_dev_get_rtnl(dev);
938 944
939 if (event == NETDEV_UNREGISTER) { 945 if (event == NETDEV_UNREGISTER) {
940 fib_disable_ip(dev, 2); 946 fib_disable_ip(dev, 2, -1);
941 return NOTIFY_DONE; 947 return NOTIFY_DONE;
942 } 948 }
943 949
@@ -955,12 +961,15 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
955 rt_cache_flush(dev_net(dev), -1); 961 rt_cache_flush(dev_net(dev), -1);
956 break; 962 break;
957 case NETDEV_DOWN: 963 case NETDEV_DOWN:
958 fib_disable_ip(dev, 0); 964 fib_disable_ip(dev, 0, 0);
959 break; 965 break;
960 case NETDEV_CHANGEMTU: 966 case NETDEV_CHANGEMTU:
961 case NETDEV_CHANGE: 967 case NETDEV_CHANGE:
962 rt_cache_flush(dev_net(dev), 0); 968 rt_cache_flush(dev_net(dev), 0);
963 break; 969 break;
970 case NETDEV_UNREGISTER_BATCH:
971 rt_cache_flush_batch();
972 break;
964 } 973 }
965 return NOTIFY_DONE; 974 return NOTIFY_DONE;
966} 975}
@@ -996,7 +1005,7 @@ fail:
996 return err; 1005 return err;
997} 1006}
998 1007
999static void __net_exit ip_fib_net_exit(struct net *net) 1008static void ip_fib_net_exit(struct net *net)
1000{ 1009{
1001 unsigned int i; 1010 unsigned int i;
1002 1011
@@ -1012,7 +1021,7 @@ static void __net_exit ip_fib_net_exit(struct net *net)
1012 head = &net->ipv4.fib_table_hash[i]; 1021 head = &net->ipv4.fib_table_hash[i];
1013 hlist_for_each_entry_safe(tb, node, tmp, head, tb_hlist) { 1022 hlist_for_each_entry_safe(tb, node, tmp, head, tb_hlist) {
1014 hlist_del(node); 1023 hlist_del(node);
1015 tb->tb_flush(tb); 1024 fib_table_flush(tb);
1016 kfree(tb); 1025 kfree(tb);
1017 } 1026 }
1018 } 1027 }
diff --git a/net/ipv4/fib_hash.c b/net/ipv4/fib_hash.c
index ecd39454235c..4ed7e0dea1bc 100644
--- a/net/ipv4/fib_hash.c
+++ b/net/ipv4/fib_hash.c
@@ -32,6 +32,7 @@
32#include <linux/skbuff.h> 32#include <linux/skbuff.h>
33#include <linux/netlink.h> 33#include <linux/netlink.h>
34#include <linux/init.h> 34#include <linux/init.h>
35#include <linux/slab.h>
35 36
36#include <net/net_namespace.h> 37#include <net/net_namespace.h>
37#include <net/ip.h> 38#include <net/ip.h>
@@ -242,8 +243,8 @@ fn_new_zone(struct fn_hash *table, int z)
242 return fz; 243 return fz;
243} 244}
244 245
245static int 246int fib_table_lookup(struct fib_table *tb,
246fn_hash_lookup(struct fib_table *tb, const struct flowi *flp, struct fib_result *res) 247 const struct flowi *flp, struct fib_result *res)
247{ 248{
248 int err; 249 int err;
249 struct fn_zone *fz; 250 struct fn_zone *fz;
@@ -274,8 +275,8 @@ out:
274 return err; 275 return err;
275} 276}
276 277
277static void 278void fib_table_select_default(struct fib_table *tb,
278fn_hash_select_default(struct fib_table *tb, const struct flowi *flp, struct fib_result *res) 279 const struct flowi *flp, struct fib_result *res)
279{ 280{
280 int order, last_idx; 281 int order, last_idx;
281 struct hlist_node *node; 282 struct hlist_node *node;
@@ -366,7 +367,7 @@ static struct fib_node *fib_find_node(struct fn_zone *fz, __be32 key)
366 return NULL; 367 return NULL;
367} 368}
368 369
369static int fn_hash_insert(struct fib_table *tb, struct fib_config *cfg) 370int fib_table_insert(struct fib_table *tb, struct fib_config *cfg)
370{ 371{
371 struct fn_hash *table = (struct fn_hash *) tb->tb_data; 372 struct fn_hash *table = (struct fn_hash *) tb->tb_data;
372 struct fib_node *new_f = NULL; 373 struct fib_node *new_f = NULL;
@@ -544,8 +545,7 @@ out:
544 return err; 545 return err;
545} 546}
546 547
547 548int fib_table_delete(struct fib_table *tb, struct fib_config *cfg)
548static int fn_hash_delete(struct fib_table *tb, struct fib_config *cfg)
549{ 549{
550 struct fn_hash *table = (struct fn_hash *)tb->tb_data; 550 struct fn_hash *table = (struct fn_hash *)tb->tb_data;
551 struct fib_node *f; 551 struct fib_node *f;
@@ -662,7 +662,7 @@ static int fn_flush_list(struct fn_zone *fz, int idx)
662 return found; 662 return found;
663} 663}
664 664
665static int fn_hash_flush(struct fib_table *tb) 665int fib_table_flush(struct fib_table *tb)
666{ 666{
667 struct fn_hash *table = (struct fn_hash *) tb->tb_data; 667 struct fn_hash *table = (struct fn_hash *) tb->tb_data;
668 struct fn_zone *fz; 668 struct fn_zone *fz;
@@ -743,7 +743,8 @@ fn_hash_dump_zone(struct sk_buff *skb, struct netlink_callback *cb,
743 return skb->len; 743 return skb->len;
744} 744}
745 745
746static int fn_hash_dump(struct fib_table *tb, struct sk_buff *skb, struct netlink_callback *cb) 746int fib_table_dump(struct fib_table *tb, struct sk_buff *skb,
747 struct netlink_callback *cb)
747{ 748{
748 int m, s_m; 749 int m, s_m;
749 struct fn_zone *fz; 750 struct fn_zone *fz;
@@ -787,12 +788,7 @@ struct fib_table *fib_hash_table(u32 id)
787 788
788 tb->tb_id = id; 789 tb->tb_id = id;
789 tb->tb_default = -1; 790 tb->tb_default = -1;
790 tb->tb_lookup = fn_hash_lookup; 791
791 tb->tb_insert = fn_hash_insert;
792 tb->tb_delete = fn_hash_delete;
793 tb->tb_flush = fn_hash_flush;
794 tb->tb_select_default = fn_hash_select_default;
795 tb->tb_dump = fn_hash_dump;
796 memset(tb->tb_data, 0, sizeof(struct fn_hash)); 792 memset(tb->tb_data, 0, sizeof(struct fn_hash));
797 return tb; 793 return tb;
798} 794}
diff --git a/net/ipv4/fib_rules.c b/net/ipv4/fib_rules.c
index 92d9d97ec5e3..ca2d07b1c706 100644
--- a/net/ipv4/fib_rules.c
+++ b/net/ipv4/fib_rules.c
@@ -94,7 +94,7 @@ static int fib4_rule_action(struct fib_rule *rule, struct flowi *flp,
94 if ((tbl = fib_get_table(rule->fr_net, rule->table)) == NULL) 94 if ((tbl = fib_get_table(rule->fr_net, rule->table)) == NULL)
95 goto errout; 95 goto errout;
96 96
97 err = tbl->tb_lookup(tbl, flp, (struct fib_result *) arg->result); 97 err = fib_table_lookup(tbl, flp, (struct fib_result *) arg->result);
98 if (err > 0) 98 if (err > 0)
99 err = -EAGAIN; 99 err = -EAGAIN;
100errout: 100errout:
@@ -284,7 +284,7 @@ static int fib_default_rules_init(struct fib_rules_ops *ops)
284{ 284{
285 int err; 285 int err;
286 286
287 err = fib_default_rule_add(ops, 0, RT_TABLE_LOCAL, FIB_RULE_PERMANENT); 287 err = fib_default_rule_add(ops, 0, RT_TABLE_LOCAL, 0);
288 if (err < 0) 288 if (err < 0)
289 return err; 289 return err;
290 err = fib_default_rule_add(ops, 0x7FFE, RT_TABLE_MAIN, 0); 290 err = fib_default_rule_add(ops, 0x7FFE, RT_TABLE_MAIN, 0);
@@ -301,13 +301,9 @@ int __net_init fib4_rules_init(struct net *net)
301 int err; 301 int err;
302 struct fib_rules_ops *ops; 302 struct fib_rules_ops *ops;
303 303
304 ops = kmemdup(&fib4_rules_ops_template, sizeof(*ops), GFP_KERNEL); 304 ops = fib_rules_register(&fib4_rules_ops_template, net);
305 if (ops == NULL) 305 if (IS_ERR(ops))
306 return -ENOMEM; 306 return PTR_ERR(ops);
307 INIT_LIST_HEAD(&ops->rules_list);
308 ops->fro_net = net;
309
310 fib_rules_register(ops);
311 307
312 err = fib_default_rules_init(ops); 308 err = fib_default_rules_init(ops);
313 if (err < 0) 309 if (err < 0)
@@ -318,12 +314,10 @@ int __net_init fib4_rules_init(struct net *net)
318fail: 314fail:
319 /* also cleans all rules already added */ 315 /* also cleans all rules already added */
320 fib_rules_unregister(ops); 316 fib_rules_unregister(ops);
321 kfree(ops);
322 return err; 317 return err;
323} 318}
324 319
325void __net_exit fib4_rules_exit(struct net *net) 320void __net_exit fib4_rules_exit(struct net *net)
326{ 321{
327 fib_rules_unregister(net->ipv4.rules_ops); 322 fib_rules_unregister(net->ipv4.rules_ops);
328 kfree(net->ipv4.rules_ops);
329} 323}
diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
index 9b096d6ff3f2..20f09c5b31e8 100644
--- a/net/ipv4/fib_semantics.c
+++ b/net/ipv4/fib_semantics.c
@@ -32,6 +32,7 @@
32#include <linux/proc_fs.h> 32#include <linux/proc_fs.h>
33#include <linux/skbuff.h> 33#include <linux/skbuff.h>
34#include <linux/init.h> 34#include <linux/init.h>
35#include <linux/slab.h>
35 36
36#include <net/arp.h> 37#include <net/arp.h>
37#include <net/ip.h> 38#include <net/ip.h>
@@ -62,8 +63,8 @@ static DEFINE_SPINLOCK(fib_multipath_lock);
62#define for_nexthops(fi) { int nhsel; const struct fib_nh * nh; \ 63#define for_nexthops(fi) { int nhsel; const struct fib_nh * nh; \
63for (nhsel=0, nh = (fi)->fib_nh; nhsel < (fi)->fib_nhs; nh++, nhsel++) 64for (nhsel=0, nh = (fi)->fib_nh; nhsel < (fi)->fib_nhs; nh++, nhsel++)
64 65
65#define change_nexthops(fi) { int nhsel; struct fib_nh * nh; \ 66#define change_nexthops(fi) { int nhsel; struct fib_nh *nexthop_nh; \
66for (nhsel=0, nh = (struct fib_nh *)((fi)->fib_nh); nhsel < (fi)->fib_nhs; nh++, nhsel++) 67for (nhsel=0, nexthop_nh = (struct fib_nh *)((fi)->fib_nh); nhsel < (fi)->fib_nhs; nexthop_nh++, nhsel++)
67 68
68#else /* CONFIG_IP_ROUTE_MULTIPATH */ 69#else /* CONFIG_IP_ROUTE_MULTIPATH */
69 70
@@ -72,7 +73,7 @@ for (nhsel=0, nh = (struct fib_nh *)((fi)->fib_nh); nhsel < (fi)->fib_nhs; nh++,
72#define for_nexthops(fi) { int nhsel = 0; const struct fib_nh * nh = (fi)->fib_nh; \ 73#define for_nexthops(fi) { int nhsel = 0; const struct fib_nh * nh = (fi)->fib_nh; \
73for (nhsel=0; nhsel < 1; nhsel++) 74for (nhsel=0; nhsel < 1; nhsel++)
74 75
75#define change_nexthops(fi) { int nhsel = 0; struct fib_nh * nh = (struct fib_nh *)((fi)->fib_nh); \ 76#define change_nexthops(fi) { int nhsel = 0; struct fib_nh *nexthop_nh = (struct fib_nh *)((fi)->fib_nh); \
76for (nhsel=0; nhsel < 1; nhsel++) 77for (nhsel=0; nhsel < 1; nhsel++)
77 78
78#endif /* CONFIG_IP_ROUTE_MULTIPATH */ 79#endif /* CONFIG_IP_ROUTE_MULTIPATH */
@@ -145,9 +146,9 @@ void free_fib_info(struct fib_info *fi)
145 return; 146 return;
146 } 147 }
147 change_nexthops(fi) { 148 change_nexthops(fi) {
148 if (nh->nh_dev) 149 if (nexthop_nh->nh_dev)
149 dev_put(nh->nh_dev); 150 dev_put(nexthop_nh->nh_dev);
150 nh->nh_dev = NULL; 151 nexthop_nh->nh_dev = NULL;
151 } endfor_nexthops(fi); 152 } endfor_nexthops(fi);
152 fib_info_cnt--; 153 fib_info_cnt--;
153 release_net(fi->fib_net); 154 release_net(fi->fib_net);
@@ -162,9 +163,9 @@ void fib_release_info(struct fib_info *fi)
162 if (fi->fib_prefsrc) 163 if (fi->fib_prefsrc)
163 hlist_del(&fi->fib_lhash); 164 hlist_del(&fi->fib_lhash);
164 change_nexthops(fi) { 165 change_nexthops(fi) {
165 if (!nh->nh_dev) 166 if (!nexthop_nh->nh_dev)
166 continue; 167 continue;
167 hlist_del(&nh->nh_hash); 168 hlist_del(&nexthop_nh->nh_hash);
168 } endfor_nexthops(fi) 169 } endfor_nexthops(fi)
169 fi->fib_dead = 1; 170 fi->fib_dead = 1;
170 fib_info_put(fi); 171 fib_info_put(fi);
@@ -228,7 +229,7 @@ static struct fib_info *fib_find_info(const struct fib_info *nfi)
228 head = &fib_info_hash[hash]; 229 head = &fib_info_hash[hash];
229 230
230 hlist_for_each_entry(fi, node, head, fib_hash) { 231 hlist_for_each_entry(fi, node, head, fib_hash) {
231 if (fi->fib_net != nfi->fib_net) 232 if (!net_eq(fi->fib_net, nfi->fib_net))
232 continue; 233 continue;
233 if (fi->fib_nhs != nfi->fib_nhs) 234 if (fi->fib_nhs != nfi->fib_nhs)
234 continue; 235 continue;
@@ -395,19 +396,20 @@ static int fib_get_nhs(struct fib_info *fi, struct rtnexthop *rtnh,
395 if (!rtnh_ok(rtnh, remaining)) 396 if (!rtnh_ok(rtnh, remaining))
396 return -EINVAL; 397 return -EINVAL;
397 398
398 nh->nh_flags = (cfg->fc_flags & ~0xFF) | rtnh->rtnh_flags; 399 nexthop_nh->nh_flags =
399 nh->nh_oif = rtnh->rtnh_ifindex; 400 (cfg->fc_flags & ~0xFF) | rtnh->rtnh_flags;
400 nh->nh_weight = rtnh->rtnh_hops + 1; 401 nexthop_nh->nh_oif = rtnh->rtnh_ifindex;
402 nexthop_nh->nh_weight = rtnh->rtnh_hops + 1;
401 403
402 attrlen = rtnh_attrlen(rtnh); 404 attrlen = rtnh_attrlen(rtnh);
403 if (attrlen > 0) { 405 if (attrlen > 0) {
404 struct nlattr *nla, *attrs = rtnh_attrs(rtnh); 406 struct nlattr *nla, *attrs = rtnh_attrs(rtnh);
405 407
406 nla = nla_find(attrs, attrlen, RTA_GATEWAY); 408 nla = nla_find(attrs, attrlen, RTA_GATEWAY);
407 nh->nh_gw = nla ? nla_get_be32(nla) : 0; 409 nexthop_nh->nh_gw = nla ? nla_get_be32(nla) : 0;
408#ifdef CONFIG_NET_CLS_ROUTE 410#ifdef CONFIG_NET_CLS_ROUTE
409 nla = nla_find(attrs, attrlen, RTA_FLOW); 411 nla = nla_find(attrs, attrlen, RTA_FLOW);
410 nh->nh_tclassid = nla ? nla_get_u32(nla) : 0; 412 nexthop_nh->nh_tclassid = nla ? nla_get_u32(nla) : 0;
411#endif 413#endif
412 } 414 }
413 415
@@ -527,10 +529,6 @@ static int fib_check_nh(struct fib_config *cfg, struct fib_info *fi,
527 if (nh->nh_gw) { 529 if (nh->nh_gw) {
528 struct fib_result res; 530 struct fib_result res;
529 531
530#ifdef CONFIG_IP_ROUTE_PERVASIVE
531 if (nh->nh_flags&RTNH_F_PERVASIVE)
532 return 0;
533#endif
534 if (nh->nh_flags&RTNH_F_ONLINK) { 532 if (nh->nh_flags&RTNH_F_ONLINK) {
535 struct net_device *dev; 533 struct net_device *dev;
536 534
@@ -738,7 +736,7 @@ struct fib_info *fib_create_info(struct fib_config *cfg)
738 736
739 fi->fib_nhs = nhs; 737 fi->fib_nhs = nhs;
740 change_nexthops(fi) { 738 change_nexthops(fi) {
741 nh->nh_parent = fi; 739 nexthop_nh->nh_parent = fi;
742 } endfor_nexthops(fi) 740 } endfor_nexthops(fi)
743 741
744 if (cfg->fc_mx) { 742 if (cfg->fc_mx) {
@@ -808,7 +806,7 @@ struct fib_info *fib_create_info(struct fib_config *cfg)
808 goto failure; 806 goto failure;
809 } else { 807 } else {
810 change_nexthops(fi) { 808 change_nexthops(fi) {
811 if ((err = fib_check_nh(cfg, fi, nh)) != 0) 809 if ((err = fib_check_nh(cfg, fi, nexthop_nh)) != 0)
812 goto failure; 810 goto failure;
813 } endfor_nexthops(fi) 811 } endfor_nexthops(fi)
814 } 812 }
@@ -843,11 +841,11 @@ link_it:
843 struct hlist_head *head; 841 struct hlist_head *head;
844 unsigned int hash; 842 unsigned int hash;
845 843
846 if (!nh->nh_dev) 844 if (!nexthop_nh->nh_dev)
847 continue; 845 continue;
848 hash = fib_devindex_hashfn(nh->nh_dev->ifindex); 846 hash = fib_devindex_hashfn(nexthop_nh->nh_dev->ifindex);
849 head = &fib_info_devhash[hash]; 847 head = &fib_info_devhash[hash];
850 hlist_add_head(&nh->nh_hash, head); 848 hlist_add_head(&nexthop_nh->nh_hash, head);
851 } endfor_nexthops(fi) 849 } endfor_nexthops(fi)
852 spin_unlock_bh(&fib_info_lock); 850 spin_unlock_bh(&fib_info_lock);
853 return fi; 851 return fi;
@@ -1047,7 +1045,7 @@ int fib_sync_down_addr(struct net *net, __be32 local)
1047 return 0; 1045 return 0;
1048 1046
1049 hlist_for_each_entry(fi, node, head, fib_lhash) { 1047 hlist_for_each_entry(fi, node, head, fib_lhash) {
1050 if (fi->fib_net != net) 1048 if (!net_eq(fi->fib_net, net))
1051 continue; 1049 continue;
1052 if (fi->fib_prefsrc == local) { 1050 if (fi->fib_prefsrc == local) {
1053 fi->fib_flags |= RTNH_F_DEAD; 1051 fi->fib_flags |= RTNH_F_DEAD;
@@ -1080,21 +1078,21 @@ int fib_sync_down_dev(struct net_device *dev, int force)
1080 prev_fi = fi; 1078 prev_fi = fi;
1081 dead = 0; 1079 dead = 0;
1082 change_nexthops(fi) { 1080 change_nexthops(fi) {
1083 if (nh->nh_flags&RTNH_F_DEAD) 1081 if (nexthop_nh->nh_flags&RTNH_F_DEAD)
1084 dead++; 1082 dead++;
1085 else if (nh->nh_dev == dev && 1083 else if (nexthop_nh->nh_dev == dev &&
1086 nh->nh_scope != scope) { 1084 nexthop_nh->nh_scope != scope) {
1087 nh->nh_flags |= RTNH_F_DEAD; 1085 nexthop_nh->nh_flags |= RTNH_F_DEAD;
1088#ifdef CONFIG_IP_ROUTE_MULTIPATH 1086#ifdef CONFIG_IP_ROUTE_MULTIPATH
1089 spin_lock_bh(&fib_multipath_lock); 1087 spin_lock_bh(&fib_multipath_lock);
1090 fi->fib_power -= nh->nh_power; 1088 fi->fib_power -= nexthop_nh->nh_power;
1091 nh->nh_power = 0; 1089 nexthop_nh->nh_power = 0;
1092 spin_unlock_bh(&fib_multipath_lock); 1090 spin_unlock_bh(&fib_multipath_lock);
1093#endif 1091#endif
1094 dead++; 1092 dead++;
1095 } 1093 }
1096#ifdef CONFIG_IP_ROUTE_MULTIPATH 1094#ifdef CONFIG_IP_ROUTE_MULTIPATH
1097 if (force > 1 && nh->nh_dev == dev) { 1095 if (force > 1 && nexthop_nh->nh_dev == dev) {
1098 dead = fi->fib_nhs; 1096 dead = fi->fib_nhs;
1099 break; 1097 break;
1100 } 1098 }
@@ -1144,18 +1142,20 @@ int fib_sync_up(struct net_device *dev)
1144 prev_fi = fi; 1142 prev_fi = fi;
1145 alive = 0; 1143 alive = 0;
1146 change_nexthops(fi) { 1144 change_nexthops(fi) {
1147 if (!(nh->nh_flags&RTNH_F_DEAD)) { 1145 if (!(nexthop_nh->nh_flags&RTNH_F_DEAD)) {
1148 alive++; 1146 alive++;
1149 continue; 1147 continue;
1150 } 1148 }
1151 if (nh->nh_dev == NULL || !(nh->nh_dev->flags&IFF_UP)) 1149 if (nexthop_nh->nh_dev == NULL ||
1150 !(nexthop_nh->nh_dev->flags&IFF_UP))
1152 continue; 1151 continue;
1153 if (nh->nh_dev != dev || !__in_dev_get_rtnl(dev)) 1152 if (nexthop_nh->nh_dev != dev ||
1153 !__in_dev_get_rtnl(dev))
1154 continue; 1154 continue;
1155 alive++; 1155 alive++;
1156 spin_lock_bh(&fib_multipath_lock); 1156 spin_lock_bh(&fib_multipath_lock);
1157 nh->nh_power = 0; 1157 nexthop_nh->nh_power = 0;
1158 nh->nh_flags &= ~RTNH_F_DEAD; 1158 nexthop_nh->nh_flags &= ~RTNH_F_DEAD;
1159 spin_unlock_bh(&fib_multipath_lock); 1159 spin_unlock_bh(&fib_multipath_lock);
1160 } endfor_nexthops(fi) 1160 } endfor_nexthops(fi)
1161 1161
@@ -1182,9 +1182,9 @@ void fib_select_multipath(const struct flowi *flp, struct fib_result *res)
1182 if (fi->fib_power <= 0) { 1182 if (fi->fib_power <= 0) {
1183 int power = 0; 1183 int power = 0;
1184 change_nexthops(fi) { 1184 change_nexthops(fi) {
1185 if (!(nh->nh_flags&RTNH_F_DEAD)) { 1185 if (!(nexthop_nh->nh_flags&RTNH_F_DEAD)) {
1186 power += nh->nh_weight; 1186 power += nexthop_nh->nh_weight;
1187 nh->nh_power = nh->nh_weight; 1187 nexthop_nh->nh_power = nexthop_nh->nh_weight;
1188 } 1188 }
1189 } endfor_nexthops(fi); 1189 } endfor_nexthops(fi);
1190 fi->fib_power = power; 1190 fi->fib_power = power;
@@ -1204,9 +1204,10 @@ void fib_select_multipath(const struct flowi *flp, struct fib_result *res)
1204 w = jiffies % fi->fib_power; 1204 w = jiffies % fi->fib_power;
1205 1205
1206 change_nexthops(fi) { 1206 change_nexthops(fi) {
1207 if (!(nh->nh_flags&RTNH_F_DEAD) && nh->nh_power) { 1207 if (!(nexthop_nh->nh_flags&RTNH_F_DEAD) &&
1208 if ((w -= nh->nh_power) <= 0) { 1208 nexthop_nh->nh_power) {
1209 nh->nh_power--; 1209 if ((w -= nexthop_nh->nh_power) <= 0) {
1210 nexthop_nh->nh_power--;
1210 fi->fib_power--; 1211 fi->fib_power--;
1211 res->nh_sel = nhsel; 1212 res->nh_sel = nhsel;
1212 spin_unlock_bh(&fib_multipath_lock); 1213 spin_unlock_bh(&fib_multipath_lock);
diff --git a/net/ipv4/fib_trie.c b/net/ipv4/fib_trie.c
index 291bdf50a21f..c98f115fb0fd 100644
--- a/net/ipv4/fib_trie.c
+++ b/net/ipv4/fib_trie.c
@@ -71,6 +71,7 @@
71#include <linux/netlink.h> 71#include <linux/netlink.h>
72#include <linux/init.h> 72#include <linux/init.h>
73#include <linux/list.h> 73#include <linux/list.h>
74#include <linux/slab.h>
74#include <net/net_namespace.h> 75#include <net/net_namespace.h>
75#include <net/ip.h> 76#include <net/ip.h>
76#include <net/protocol.h> 77#include <net/protocol.h>
@@ -208,7 +209,9 @@ static inline struct node *tnode_get_child_rcu(struct tnode *tn, unsigned int i)
208{ 209{
209 struct node *ret = tnode_get_child(tn, i); 210 struct node *ret = tnode_get_child(tn, i);
210 211
211 return rcu_dereference(ret); 212 return rcu_dereference_check(ret,
213 rcu_read_lock_held() ||
214 lockdep_rtnl_is_held());
212} 215}
213 216
214static inline int tnode_child_length(const struct tnode *tn) 217static inline int tnode_child_length(const struct tnode *tn)
@@ -961,7 +964,9 @@ fib_find_node(struct trie *t, u32 key)
961 struct node *n; 964 struct node *n;
962 965
963 pos = 0; 966 pos = 0;
964 n = rcu_dereference(t->trie); 967 n = rcu_dereference_check(t->trie,
968 rcu_read_lock_held() ||
969 lockdep_rtnl_is_held());
965 970
966 while (n != NULL && NODE_TYPE(n) == T_TNODE) { 971 while (n != NULL && NODE_TYPE(n) == T_TNODE) {
967 tn = (struct tnode *) n; 972 tn = (struct tnode *) n;
@@ -1174,7 +1179,7 @@ done:
1174/* 1179/*
1175 * Caller must hold RTNL. 1180 * Caller must hold RTNL.
1176 */ 1181 */
1177static int fn_trie_insert(struct fib_table *tb, struct fib_config *cfg) 1182int fib_table_insert(struct fib_table *tb, struct fib_config *cfg)
1178{ 1183{
1179 struct trie *t = (struct trie *) tb->tb_data; 1184 struct trie *t = (struct trie *) tb->tb_data;
1180 struct fib_alias *fa, *new_fa; 1185 struct fib_alias *fa, *new_fa;
@@ -1373,8 +1378,8 @@ static int check_leaf(struct trie *t, struct leaf *l,
1373 return 1; 1378 return 1;
1374} 1379}
1375 1380
1376static int fn_trie_lookup(struct fib_table *tb, const struct flowi *flp, 1381int fib_table_lookup(struct fib_table *tb, const struct flowi *flp,
1377 struct fib_result *res) 1382 struct fib_result *res)
1378{ 1383{
1379 struct trie *t = (struct trie *) tb->tb_data; 1384 struct trie *t = (struct trie *) tb->tb_data;
1380 int ret; 1385 int ret;
@@ -1595,7 +1600,7 @@ static void trie_leaf_remove(struct trie *t, struct leaf *l)
1595/* 1600/*
1596 * Caller must hold RTNL. 1601 * Caller must hold RTNL.
1597 */ 1602 */
1598static int fn_trie_delete(struct fib_table *tb, struct fib_config *cfg) 1603int fib_table_delete(struct fib_table *tb, struct fib_config *cfg)
1599{ 1604{
1600 struct trie *t = (struct trie *) tb->tb_data; 1605 struct trie *t = (struct trie *) tb->tb_data;
1601 u32 key, mask; 1606 u32 key, mask;
@@ -1786,7 +1791,7 @@ static struct leaf *trie_leafindex(struct trie *t, int index)
1786/* 1791/*
1787 * Caller must hold RTNL. 1792 * Caller must hold RTNL.
1788 */ 1793 */
1789static int fn_trie_flush(struct fib_table *tb) 1794int fib_table_flush(struct fib_table *tb)
1790{ 1795{
1791 struct trie *t = (struct trie *) tb->tb_data; 1796 struct trie *t = (struct trie *) tb->tb_data;
1792 struct leaf *l, *ll = NULL; 1797 struct leaf *l, *ll = NULL;
@@ -1807,9 +1812,9 @@ static int fn_trie_flush(struct fib_table *tb)
1807 return found; 1812 return found;
1808} 1813}
1809 1814
1810static void fn_trie_select_default(struct fib_table *tb, 1815void fib_table_select_default(struct fib_table *tb,
1811 const struct flowi *flp, 1816 const struct flowi *flp,
1812 struct fib_result *res) 1817 struct fib_result *res)
1813{ 1818{
1814 struct trie *t = (struct trie *) tb->tb_data; 1819 struct trie *t = (struct trie *) tb->tb_data;
1815 int order, last_idx; 1820 int order, last_idx;
@@ -1952,8 +1957,8 @@ static int fn_trie_dump_leaf(struct leaf *l, struct fib_table *tb,
1952 return skb->len; 1957 return skb->len;
1953} 1958}
1954 1959
1955static int fn_trie_dump(struct fib_table *tb, struct sk_buff *skb, 1960int fib_table_dump(struct fib_table *tb, struct sk_buff *skb,
1956 struct netlink_callback *cb) 1961 struct netlink_callback *cb)
1957{ 1962{
1958 struct leaf *l; 1963 struct leaf *l;
1959 struct trie *t = (struct trie *) tb->tb_data; 1964 struct trie *t = (struct trie *) tb->tb_data;
@@ -2020,12 +2025,6 @@ struct fib_table *fib_hash_table(u32 id)
2020 2025
2021 tb->tb_id = id; 2026 tb->tb_id = id;
2022 tb->tb_default = -1; 2027 tb->tb_default = -1;
2023 tb->tb_lookup = fn_trie_lookup;
2024 tb->tb_insert = fn_trie_insert;
2025 tb->tb_delete = fn_trie_delete;
2026 tb->tb_flush = fn_trie_flush;
2027 tb->tb_select_default = fn_trie_select_default;
2028 tb->tb_dump = fn_trie_dump;
2029 2028
2030 t = (struct trie *) tb->tb_data; 2029 t = (struct trie *) tb->tb_data;
2031 memset(t, 0, sizeof(*t)); 2030 memset(t, 0, sizeof(*t));
diff --git a/net/ipv4/icmp.c b/net/ipv4/icmp.c
index 5bc13fe816d1..ac4dec132735 100644
--- a/net/ipv4/icmp.c
+++ b/net/ipv4/icmp.c
@@ -74,6 +74,7 @@
74#include <linux/netdevice.h> 74#include <linux/netdevice.h>
75#include <linux/string.h> 75#include <linux/string.h>
76#include <linux/netfilter_ipv4.h> 76#include <linux/netfilter_ipv4.h>
77#include <linux/slab.h>
77#include <net/snmp.h> 78#include <net/snmp.h>
78#include <net/ip.h> 79#include <net/ip.h>
79#include <net/route.h> 80#include <net/route.h>
@@ -114,7 +115,7 @@ struct icmp_bxm {
114/* An array of errno for error messages from dest unreach. */ 115/* An array of errno for error messages from dest unreach. */
115/* RFC 1122: 3.2.2.1 States that NET_UNREACH, HOST_UNREACH and SR_FAILED MUST be considered 'transient errs'. */ 116/* RFC 1122: 3.2.2.1 States that NET_UNREACH, HOST_UNREACH and SR_FAILED MUST be considered 'transient errs'. */
116 117
117struct icmp_err icmp_err_convert[] = { 118const struct icmp_err icmp_err_convert[] = {
118 { 119 {
119 .errno = ENETUNREACH, /* ICMP_NET_UNREACH */ 120 .errno = ENETUNREACH, /* ICMP_NET_UNREACH */
120 .fatal = 0, 121 .fatal = 0,
@@ -501,15 +502,16 @@ void icmp_send(struct sk_buff *skb_in, int type, int code, __be32 info)
501 if (!(rt->rt_flags & RTCF_LOCAL)) { 502 if (!(rt->rt_flags & RTCF_LOCAL)) {
502 struct net_device *dev = NULL; 503 struct net_device *dev = NULL;
503 504
505 rcu_read_lock();
504 if (rt->fl.iif && 506 if (rt->fl.iif &&
505 net->ipv4.sysctl_icmp_errors_use_inbound_ifaddr) 507 net->ipv4.sysctl_icmp_errors_use_inbound_ifaddr)
506 dev = dev_get_by_index(net, rt->fl.iif); 508 dev = dev_get_by_index_rcu(net, rt->fl.iif);
507 509
508 if (dev) { 510 if (dev)
509 saddr = inet_select_addr(dev, 0, RT_SCOPE_LINK); 511 saddr = inet_select_addr(dev, 0, RT_SCOPE_LINK);
510 dev_put(dev); 512 else
511 } else
512 saddr = 0; 513 saddr = 0;
514 rcu_read_unlock();
513 } 515 }
514 516
515 tos = icmp_pointers[type].error ? ((iph->tos & IPTOS_TOS_MASK) | 517 tos = icmp_pointers[type].error ? ((iph->tos & IPTOS_TOS_MASK) |
@@ -1165,6 +1167,10 @@ static int __net_init icmp_sk_init(struct net *net)
1165 sk->sk_sndbuf = 1167 sk->sk_sndbuf =
1166 (2 * ((64 * 1024) + sizeof(struct sk_buff))); 1168 (2 * ((64 * 1024) + sizeof(struct sk_buff)));
1167 1169
1170 /*
1171 * Speedup sock_wfree()
1172 */
1173 sock_set_flag(sk, SOCK_USE_WRITE_QUEUE);
1168 inet_sk(sk)->pmtudisc = IP_PMTUDISC_DONT; 1174 inet_sk(sk)->pmtudisc = IP_PMTUDISC_DONT;
1169 } 1175 }
1170 1176
diff --git a/net/ipv4/igmp.c b/net/ipv4/igmp.c
index d41e5de79a82..15d3eeda92f5 100644
--- a/net/ipv4/igmp.c
+++ b/net/ipv4/igmp.c
@@ -71,6 +71,7 @@
71 */ 71 */
72 72
73#include <linux/module.h> 73#include <linux/module.h>
74#include <linux/slab.h>
74#include <asm/uaccess.h> 75#include <asm/uaccess.h>
75#include <asm/system.h> 76#include <asm/system.h>
76#include <linux/types.h> 77#include <linux/types.h>
@@ -946,7 +947,6 @@ int igmp_rcv(struct sk_buff *skb)
946 break; 947 break;
947 case IGMP_HOST_MEMBERSHIP_REPORT: 948 case IGMP_HOST_MEMBERSHIP_REPORT:
948 case IGMPV2_HOST_MEMBERSHIP_REPORT: 949 case IGMPV2_HOST_MEMBERSHIP_REPORT:
949 case IGMPV3_HOST_MEMBERSHIP_REPORT:
950 /* Is it our report looped back? */ 950 /* Is it our report looped back? */
951 if (skb_rtable(skb)->fl.iif == 0) 951 if (skb_rtable(skb)->fl.iif == 0)
952 break; 952 break;
@@ -960,6 +960,7 @@ int igmp_rcv(struct sk_buff *skb)
960 in_dev_put(in_dev); 960 in_dev_put(in_dev);
961 return pim_rcv_v1(skb); 961 return pim_rcv_v1(skb);
962#endif 962#endif
963 case IGMPV3_HOST_MEMBERSHIP_REPORT:
963 case IGMP_DVMRP: 964 case IGMP_DVMRP:
964 case IGMP_TRACE: 965 case IGMP_TRACE:
965 case IGMP_HOST_LEAVE_MESSAGE: 966 case IGMP_HOST_LEAVE_MESSAGE:
@@ -1799,7 +1800,7 @@ int ip_mc_join_group(struct sock *sk , struct ip_mreqn *imr)
1799 iml->next = inet->mc_list; 1800 iml->next = inet->mc_list;
1800 iml->sflist = NULL; 1801 iml->sflist = NULL;
1801 iml->sfmode = MCAST_EXCLUDE; 1802 iml->sfmode = MCAST_EXCLUDE;
1802 inet->mc_list = iml; 1803 rcu_assign_pointer(inet->mc_list, iml);
1803 ip_mc_inc_group(in_dev, addr); 1804 ip_mc_inc_group(in_dev, addr);
1804 err = 0; 1805 err = 0;
1805done: 1806done:
@@ -1807,24 +1808,46 @@ done:
1807 return err; 1808 return err;
1808} 1809}
1809 1810
1811static void ip_sf_socklist_reclaim(struct rcu_head *rp)
1812{
1813 struct ip_sf_socklist *psf;
1814
1815 psf = container_of(rp, struct ip_sf_socklist, rcu);
1816 /* sk_omem_alloc should have been decreased by the caller*/
1817 kfree(psf);
1818}
1819
1810static int ip_mc_leave_src(struct sock *sk, struct ip_mc_socklist *iml, 1820static int ip_mc_leave_src(struct sock *sk, struct ip_mc_socklist *iml,
1811 struct in_device *in_dev) 1821 struct in_device *in_dev)
1812{ 1822{
1823 struct ip_sf_socklist *psf = iml->sflist;
1813 int err; 1824 int err;
1814 1825
1815 if (iml->sflist == NULL) { 1826 if (psf == NULL) {
1816 /* any-source empty exclude case */ 1827 /* any-source empty exclude case */
1817 return ip_mc_del_src(in_dev, &iml->multi.imr_multiaddr.s_addr, 1828 return ip_mc_del_src(in_dev, &iml->multi.imr_multiaddr.s_addr,
1818 iml->sfmode, 0, NULL, 0); 1829 iml->sfmode, 0, NULL, 0);
1819 } 1830 }
1820 err = ip_mc_del_src(in_dev, &iml->multi.imr_multiaddr.s_addr, 1831 err = ip_mc_del_src(in_dev, &iml->multi.imr_multiaddr.s_addr,
1821 iml->sfmode, iml->sflist->sl_count, 1832 iml->sfmode, psf->sl_count, psf->sl_addr, 0);
1822 iml->sflist->sl_addr, 0); 1833 rcu_assign_pointer(iml->sflist, NULL);
1823 sock_kfree_s(sk, iml->sflist, IP_SFLSIZE(iml->sflist->sl_max)); 1834 /* decrease mem now to avoid the memleak warning */
1824 iml->sflist = NULL; 1835 atomic_sub(IP_SFLSIZE(psf->sl_max), &sk->sk_omem_alloc);
1836 call_rcu(&psf->rcu, ip_sf_socklist_reclaim);
1825 return err; 1837 return err;
1826} 1838}
1827 1839
1840
1841static void ip_mc_socklist_reclaim(struct rcu_head *rp)
1842{
1843 struct ip_mc_socklist *iml;
1844
1845 iml = container_of(rp, struct ip_mc_socklist, rcu);
1846 /* sk_omem_alloc should have been decreased by the caller*/
1847 kfree(iml);
1848}
1849
1850
1828/* 1851/*
1829 * Ask a socket to leave a group. 1852 * Ask a socket to leave a group.
1830 */ 1853 */
@@ -1854,12 +1877,14 @@ int ip_mc_leave_group(struct sock *sk, struct ip_mreqn *imr)
1854 1877
1855 (void) ip_mc_leave_src(sk, iml, in_dev); 1878 (void) ip_mc_leave_src(sk, iml, in_dev);
1856 1879
1857 *imlp = iml->next; 1880 rcu_assign_pointer(*imlp, iml->next);
1858 1881
1859 if (in_dev) 1882 if (in_dev)
1860 ip_mc_dec_group(in_dev, group); 1883 ip_mc_dec_group(in_dev, group);
1861 rtnl_unlock(); 1884 rtnl_unlock();
1862 sock_kfree_s(sk, iml, sizeof(*iml)); 1885 /* decrease mem now to avoid the memleak warning */
1886 atomic_sub(sizeof(*iml), &sk->sk_omem_alloc);
1887 call_rcu(&iml->rcu, ip_mc_socklist_reclaim);
1863 return 0; 1888 return 0;
1864 } 1889 }
1865 if (!in_dev) 1890 if (!in_dev)
@@ -1899,8 +1924,9 @@ int ip_mc_source(int add, int omode, struct sock *sk, struct
1899 err = -EADDRNOTAVAIL; 1924 err = -EADDRNOTAVAIL;
1900 1925
1901 for (pmc=inet->mc_list; pmc; pmc=pmc->next) { 1926 for (pmc=inet->mc_list; pmc; pmc=pmc->next) {
1902 if (pmc->multi.imr_multiaddr.s_addr == imr.imr_multiaddr.s_addr 1927 if ((pmc->multi.imr_multiaddr.s_addr ==
1903 && pmc->multi.imr_ifindex == imr.imr_ifindex) 1928 imr.imr_multiaddr.s_addr) &&
1929 (pmc->multi.imr_ifindex == imr.imr_ifindex))
1904 break; 1930 break;
1905 } 1931 }
1906 if (!pmc) { /* must have a prior join */ 1932 if (!pmc) { /* must have a prior join */
@@ -1973,9 +1999,12 @@ int ip_mc_source(int add, int omode, struct sock *sk, struct
1973 if (psl) { 1999 if (psl) {
1974 for (i=0; i<psl->sl_count; i++) 2000 for (i=0; i<psl->sl_count; i++)
1975 newpsl->sl_addr[i] = psl->sl_addr[i]; 2001 newpsl->sl_addr[i] = psl->sl_addr[i];
1976 sock_kfree_s(sk, psl, IP_SFLSIZE(psl->sl_max)); 2002 /* decrease mem now to avoid the memleak warning */
2003 atomic_sub(IP_SFLSIZE(psl->sl_max), &sk->sk_omem_alloc);
2004 call_rcu(&psl->rcu, ip_sf_socklist_reclaim);
1977 } 2005 }
1978 pmc->sflist = psl = newpsl; 2006 rcu_assign_pointer(pmc->sflist, newpsl);
2007 psl = newpsl;
1979 } 2008 }
1980 rv = 1; /* > 0 for insert logic below if sl_count is 0 */ 2009 rv = 1; /* > 0 for insert logic below if sl_count is 0 */
1981 for (i=0; i<psl->sl_count; i++) { 2010 for (i=0; i<psl->sl_count; i++) {
@@ -2071,11 +2100,13 @@ int ip_mc_msfilter(struct sock *sk, struct ip_msfilter *msf, int ifindex)
2071 if (psl) { 2100 if (psl) {
2072 (void) ip_mc_del_src(in_dev, &msf->imsf_multiaddr, pmc->sfmode, 2101 (void) ip_mc_del_src(in_dev, &msf->imsf_multiaddr, pmc->sfmode,
2073 psl->sl_count, psl->sl_addr, 0); 2102 psl->sl_count, psl->sl_addr, 0);
2074 sock_kfree_s(sk, psl, IP_SFLSIZE(psl->sl_max)); 2103 /* decrease mem now to avoid the memleak warning */
2104 atomic_sub(IP_SFLSIZE(psl->sl_max), &sk->sk_omem_alloc);
2105 call_rcu(&psl->rcu, ip_sf_socklist_reclaim);
2075 } else 2106 } else
2076 (void) ip_mc_del_src(in_dev, &msf->imsf_multiaddr, pmc->sfmode, 2107 (void) ip_mc_del_src(in_dev, &msf->imsf_multiaddr, pmc->sfmode,
2077 0, NULL, 0); 2108 0, NULL, 0);
2078 pmc->sflist = newpsl; 2109 rcu_assign_pointer(pmc->sflist, newpsl);
2079 pmc->sfmode = msf->imsf_fmode; 2110 pmc->sfmode = msf->imsf_fmode;
2080 err = 0; 2111 err = 0;
2081done: 2112done:
@@ -2208,30 +2239,40 @@ int ip_mc_sf_allow(struct sock *sk, __be32 loc_addr, __be32 rmt_addr, int dif)
2208 struct ip_mc_socklist *pmc; 2239 struct ip_mc_socklist *pmc;
2209 struct ip_sf_socklist *psl; 2240 struct ip_sf_socklist *psl;
2210 int i; 2241 int i;
2242 int ret;
2211 2243
2244 ret = 1;
2212 if (!ipv4_is_multicast(loc_addr)) 2245 if (!ipv4_is_multicast(loc_addr))
2213 return 1; 2246 goto out;
2214 2247
2215 for (pmc=inet->mc_list; pmc; pmc=pmc->next) { 2248 rcu_read_lock();
2249 for (pmc=rcu_dereference(inet->mc_list); pmc; pmc=rcu_dereference(pmc->next)) {
2216 if (pmc->multi.imr_multiaddr.s_addr == loc_addr && 2250 if (pmc->multi.imr_multiaddr.s_addr == loc_addr &&
2217 pmc->multi.imr_ifindex == dif) 2251 pmc->multi.imr_ifindex == dif)
2218 break; 2252 break;
2219 } 2253 }
2254 ret = inet->mc_all;
2220 if (!pmc) 2255 if (!pmc)
2221 return inet->mc_all; 2256 goto unlock;
2222 psl = pmc->sflist; 2257 psl = pmc->sflist;
2258 ret = (pmc->sfmode == MCAST_EXCLUDE);
2223 if (!psl) 2259 if (!psl)
2224 return pmc->sfmode == MCAST_EXCLUDE; 2260 goto unlock;
2225 2261
2226 for (i=0; i<psl->sl_count; i++) { 2262 for (i=0; i<psl->sl_count; i++) {
2227 if (psl->sl_addr[i] == rmt_addr) 2263 if (psl->sl_addr[i] == rmt_addr)
2228 break; 2264 break;
2229 } 2265 }
2266 ret = 0;
2230 if (pmc->sfmode == MCAST_INCLUDE && i >= psl->sl_count) 2267 if (pmc->sfmode == MCAST_INCLUDE && i >= psl->sl_count)
2231 return 0; 2268 goto unlock;
2232 if (pmc->sfmode == MCAST_EXCLUDE && i < psl->sl_count) 2269 if (pmc->sfmode == MCAST_EXCLUDE && i < psl->sl_count)
2233 return 0; 2270 goto unlock;
2234 return 1; 2271 ret = 1;
2272unlock:
2273 rcu_read_unlock();
2274out:
2275 return ret;
2235} 2276}
2236 2277
2237/* 2278/*
@@ -2250,7 +2291,7 @@ void ip_mc_drop_socket(struct sock *sk)
2250 rtnl_lock(); 2291 rtnl_lock();
2251 while ((iml = inet->mc_list) != NULL) { 2292 while ((iml = inet->mc_list) != NULL) {
2252 struct in_device *in_dev; 2293 struct in_device *in_dev;
2253 inet->mc_list = iml->next; 2294 rcu_assign_pointer(inet->mc_list, iml->next);
2254 2295
2255 in_dev = inetdev_by_index(net, iml->multi.imr_ifindex); 2296 in_dev = inetdev_by_index(net, iml->multi.imr_ifindex);
2256 (void) ip_mc_leave_src(sk, iml, in_dev); 2297 (void) ip_mc_leave_src(sk, iml, in_dev);
@@ -2258,7 +2299,9 @@ void ip_mc_drop_socket(struct sock *sk)
2258 ip_mc_dec_group(in_dev, iml->multi.imr_multiaddr.s_addr); 2299 ip_mc_dec_group(in_dev, iml->multi.imr_multiaddr.s_addr);
2259 in_dev_put(in_dev); 2300 in_dev_put(in_dev);
2260 } 2301 }
2261 sock_kfree_s(sk, iml, sizeof(*iml)); 2302 /* decrease mem now to avoid the memleak warning */
2303 atomic_sub(sizeof(*iml), &sk->sk_omem_alloc);
2304 call_rcu(&iml->rcu, ip_mc_socklist_reclaim);
2262 } 2305 }
2263 rtnl_unlock(); 2306 rtnl_unlock();
2264} 2307}
@@ -2311,9 +2354,10 @@ static inline struct ip_mc_list *igmp_mc_get_first(struct seq_file *seq)
2311 struct igmp_mc_iter_state *state = igmp_mc_seq_private(seq); 2354 struct igmp_mc_iter_state *state = igmp_mc_seq_private(seq);
2312 2355
2313 state->in_dev = NULL; 2356 state->in_dev = NULL;
2314 for_each_netdev(net, state->dev) { 2357 for_each_netdev_rcu(net, state->dev) {
2315 struct in_device *in_dev; 2358 struct in_device *in_dev;
2316 in_dev = in_dev_get(state->dev); 2359
2360 in_dev = __in_dev_get_rcu(state->dev);
2317 if (!in_dev) 2361 if (!in_dev)
2318 continue; 2362 continue;
2319 read_lock(&in_dev->mc_list_lock); 2363 read_lock(&in_dev->mc_list_lock);
@@ -2323,7 +2367,6 @@ static inline struct ip_mc_list *igmp_mc_get_first(struct seq_file *seq)
2323 break; 2367 break;
2324 } 2368 }
2325 read_unlock(&in_dev->mc_list_lock); 2369 read_unlock(&in_dev->mc_list_lock);
2326 in_dev_put(in_dev);
2327 } 2370 }
2328 return im; 2371 return im;
2329} 2372}
@@ -2333,16 +2376,15 @@ static struct ip_mc_list *igmp_mc_get_next(struct seq_file *seq, struct ip_mc_li
2333 struct igmp_mc_iter_state *state = igmp_mc_seq_private(seq); 2376 struct igmp_mc_iter_state *state = igmp_mc_seq_private(seq);
2334 im = im->next; 2377 im = im->next;
2335 while (!im) { 2378 while (!im) {
2336 if (likely(state->in_dev != NULL)) { 2379 if (likely(state->in_dev != NULL))
2337 read_unlock(&state->in_dev->mc_list_lock); 2380 read_unlock(&state->in_dev->mc_list_lock);
2338 in_dev_put(state->in_dev); 2381
2339 } 2382 state->dev = next_net_device_rcu(state->dev);
2340 state->dev = next_net_device(state->dev);
2341 if (!state->dev) { 2383 if (!state->dev) {
2342 state->in_dev = NULL; 2384 state->in_dev = NULL;
2343 break; 2385 break;
2344 } 2386 }
2345 state->in_dev = in_dev_get(state->dev); 2387 state->in_dev = __in_dev_get_rcu(state->dev);
2346 if (!state->in_dev) 2388 if (!state->in_dev)
2347 continue; 2389 continue;
2348 read_lock(&state->in_dev->mc_list_lock); 2390 read_lock(&state->in_dev->mc_list_lock);
@@ -2361,9 +2403,9 @@ static struct ip_mc_list *igmp_mc_get_idx(struct seq_file *seq, loff_t pos)
2361} 2403}
2362 2404
2363static void *igmp_mc_seq_start(struct seq_file *seq, loff_t *pos) 2405static void *igmp_mc_seq_start(struct seq_file *seq, loff_t *pos)
2364 __acquires(dev_base_lock) 2406 __acquires(rcu)
2365{ 2407{
2366 read_lock(&dev_base_lock); 2408 rcu_read_lock();
2367 return *pos ? igmp_mc_get_idx(seq, *pos - 1) : SEQ_START_TOKEN; 2409 return *pos ? igmp_mc_get_idx(seq, *pos - 1) : SEQ_START_TOKEN;
2368} 2410}
2369 2411
@@ -2379,16 +2421,15 @@ static void *igmp_mc_seq_next(struct seq_file *seq, void *v, loff_t *pos)
2379} 2421}
2380 2422
2381static void igmp_mc_seq_stop(struct seq_file *seq, void *v) 2423static void igmp_mc_seq_stop(struct seq_file *seq, void *v)
2382 __releases(dev_base_lock) 2424 __releases(rcu)
2383{ 2425{
2384 struct igmp_mc_iter_state *state = igmp_mc_seq_private(seq); 2426 struct igmp_mc_iter_state *state = igmp_mc_seq_private(seq);
2385 if (likely(state->in_dev != NULL)) { 2427 if (likely(state->in_dev != NULL)) {
2386 read_unlock(&state->in_dev->mc_list_lock); 2428 read_unlock(&state->in_dev->mc_list_lock);
2387 in_dev_put(state->in_dev);
2388 state->in_dev = NULL; 2429 state->in_dev = NULL;
2389 } 2430 }
2390 state->dev = NULL; 2431 state->dev = NULL;
2391 read_unlock(&dev_base_lock); 2432 rcu_read_unlock();
2392} 2433}
2393 2434
2394static int igmp_mc_seq_show(struct seq_file *seq, void *v) 2435static int igmp_mc_seq_show(struct seq_file *seq, void *v)
@@ -2462,9 +2503,9 @@ static inline struct ip_sf_list *igmp_mcf_get_first(struct seq_file *seq)
2462 2503
2463 state->idev = NULL; 2504 state->idev = NULL;
2464 state->im = NULL; 2505 state->im = NULL;
2465 for_each_netdev(net, state->dev) { 2506 for_each_netdev_rcu(net, state->dev) {
2466 struct in_device *idev; 2507 struct in_device *idev;
2467 idev = in_dev_get(state->dev); 2508 idev = __in_dev_get_rcu(state->dev);
2468 if (unlikely(idev == NULL)) 2509 if (unlikely(idev == NULL))
2469 continue; 2510 continue;
2470 read_lock(&idev->mc_list_lock); 2511 read_lock(&idev->mc_list_lock);
@@ -2480,7 +2521,6 @@ static inline struct ip_sf_list *igmp_mcf_get_first(struct seq_file *seq)
2480 spin_unlock_bh(&im->lock); 2521 spin_unlock_bh(&im->lock);
2481 } 2522 }
2482 read_unlock(&idev->mc_list_lock); 2523 read_unlock(&idev->mc_list_lock);
2483 in_dev_put(idev);
2484 } 2524 }
2485 return psf; 2525 return psf;
2486} 2526}
@@ -2494,16 +2534,15 @@ static struct ip_sf_list *igmp_mcf_get_next(struct seq_file *seq, struct ip_sf_l
2494 spin_unlock_bh(&state->im->lock); 2534 spin_unlock_bh(&state->im->lock);
2495 state->im = state->im->next; 2535 state->im = state->im->next;
2496 while (!state->im) { 2536 while (!state->im) {
2497 if (likely(state->idev != NULL)) { 2537 if (likely(state->idev != NULL))
2498 read_unlock(&state->idev->mc_list_lock); 2538 read_unlock(&state->idev->mc_list_lock);
2499 in_dev_put(state->idev); 2539
2500 } 2540 state->dev = next_net_device_rcu(state->dev);
2501 state->dev = next_net_device(state->dev);
2502 if (!state->dev) { 2541 if (!state->dev) {
2503 state->idev = NULL; 2542 state->idev = NULL;
2504 goto out; 2543 goto out;
2505 } 2544 }
2506 state->idev = in_dev_get(state->dev); 2545 state->idev = __in_dev_get_rcu(state->dev);
2507 if (!state->idev) 2546 if (!state->idev)
2508 continue; 2547 continue;
2509 read_lock(&state->idev->mc_list_lock); 2548 read_lock(&state->idev->mc_list_lock);
@@ -2528,8 +2567,9 @@ static struct ip_sf_list *igmp_mcf_get_idx(struct seq_file *seq, loff_t pos)
2528} 2567}
2529 2568
2530static void *igmp_mcf_seq_start(struct seq_file *seq, loff_t *pos) 2569static void *igmp_mcf_seq_start(struct seq_file *seq, loff_t *pos)
2570 __acquires(rcu)
2531{ 2571{
2532 read_lock(&dev_base_lock); 2572 rcu_read_lock();
2533 return *pos ? igmp_mcf_get_idx(seq, *pos - 1) : SEQ_START_TOKEN; 2573 return *pos ? igmp_mcf_get_idx(seq, *pos - 1) : SEQ_START_TOKEN;
2534} 2574}
2535 2575
@@ -2545,6 +2585,7 @@ static void *igmp_mcf_seq_next(struct seq_file *seq, void *v, loff_t *pos)
2545} 2585}
2546 2586
2547static void igmp_mcf_seq_stop(struct seq_file *seq, void *v) 2587static void igmp_mcf_seq_stop(struct seq_file *seq, void *v)
2588 __releases(rcu)
2548{ 2589{
2549 struct igmp_mcf_iter_state *state = igmp_mcf_seq_private(seq); 2590 struct igmp_mcf_iter_state *state = igmp_mcf_seq_private(seq);
2550 if (likely(state->im != NULL)) { 2591 if (likely(state->im != NULL)) {
@@ -2553,11 +2594,10 @@ static void igmp_mcf_seq_stop(struct seq_file *seq, void *v)
2553 } 2594 }
2554 if (likely(state->idev != NULL)) { 2595 if (likely(state->idev != NULL)) {
2555 read_unlock(&state->idev->mc_list_lock); 2596 read_unlock(&state->idev->mc_list_lock);
2556 in_dev_put(state->idev);
2557 state->idev = NULL; 2597 state->idev = NULL;
2558 } 2598 }
2559 state->dev = NULL; 2599 state->dev = NULL;
2560 read_unlock(&dev_base_lock); 2600 rcu_read_unlock();
2561} 2601}
2562 2602
2563static int igmp_mcf_seq_show(struct seq_file *seq, void *v) 2603static int igmp_mcf_seq_show(struct seq_file *seq, void *v)
@@ -2605,7 +2645,7 @@ static const struct file_operations igmp_mcf_seq_fops = {
2605 .release = seq_release_net, 2645 .release = seq_release_net,
2606}; 2646};
2607 2647
2608static int igmp_net_init(struct net *net) 2648static int __net_init igmp_net_init(struct net *net)
2609{ 2649{
2610 struct proc_dir_entry *pde; 2650 struct proc_dir_entry *pde;
2611 2651
@@ -2623,7 +2663,7 @@ out_igmp:
2623 return -ENOMEM; 2663 return -ENOMEM;
2624} 2664}
2625 2665
2626static void igmp_net_exit(struct net *net) 2666static void __net_exit igmp_net_exit(struct net *net)
2627{ 2667{
2628 proc_net_remove(net, "mcfilter"); 2668 proc_net_remove(net, "mcfilter");
2629 proc_net_remove(net, "igmp"); 2669 proc_net_remove(net, "igmp");
diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
index 537731b3bcb3..8da6429269dd 100644
--- a/net/ipv4/inet_connection_sock.c
+++ b/net/ipv4/inet_connection_sock.c
@@ -112,7 +112,7 @@ again:
112 hashinfo->bhash_size)]; 112 hashinfo->bhash_size)];
113 spin_lock(&head->lock); 113 spin_lock(&head->lock);
114 inet_bind_bucket_for_each(tb, node, &head->chain) 114 inet_bind_bucket_for_each(tb, node, &head->chain)
115 if (ib_net(tb) == net && tb->port == rover) { 115 if (net_eq(ib_net(tb), net) && tb->port == rover) {
116 if (tb->fastreuse > 0 && 116 if (tb->fastreuse > 0 &&
117 sk->sk_reuse && 117 sk->sk_reuse &&
118 sk->sk_state != TCP_LISTEN && 118 sk->sk_state != TCP_LISTEN &&
@@ -158,7 +158,7 @@ have_snum:
158 hashinfo->bhash_size)]; 158 hashinfo->bhash_size)];
159 spin_lock(&head->lock); 159 spin_lock(&head->lock);
160 inet_bind_bucket_for_each(tb, node, &head->chain) 160 inet_bind_bucket_for_each(tb, node, &head->chain)
161 if (ib_net(tb) == net && tb->port == snum) 161 if (net_eq(ib_net(tb), net) && tb->port == snum)
162 goto tb_found; 162 goto tb_found;
163 } 163 }
164 tb = NULL; 164 tb = NULL;
@@ -358,6 +358,7 @@ struct dst_entry *inet_csk_route_req(struct sock *sk,
358 const struct inet_request_sock *ireq = inet_rsk(req); 358 const struct inet_request_sock *ireq = inet_rsk(req);
359 struct ip_options *opt = inet_rsk(req)->opt; 359 struct ip_options *opt = inet_rsk(req)->opt;
360 struct flowi fl = { .oif = sk->sk_bound_dev_if, 360 struct flowi fl = { .oif = sk->sk_bound_dev_if,
361 .mark = sk->sk_mark,
361 .nl_u = { .ip4_u = 362 .nl_u = { .ip4_u =
362 { .daddr = ((opt && opt->srr) ? 363 { .daddr = ((opt && opt->srr) ?
363 opt->faddr : 364 opt->faddr :
@@ -367,7 +368,7 @@ struct dst_entry *inet_csk_route_req(struct sock *sk,
367 .proto = sk->sk_protocol, 368 .proto = sk->sk_protocol,
368 .flags = inet_sk_flowi_flags(sk), 369 .flags = inet_sk_flowi_flags(sk),
369 .uli_u = { .ports = 370 .uli_u = { .ports =
370 { .sport = inet_sk(sk)->sport, 371 { .sport = inet_sk(sk)->inet_sport,
371 .dport = ireq->rmt_port } } }; 372 .dport = ireq->rmt_port } } };
372 struct net *net = sock_net(sk); 373 struct net *net = sock_net(sk);
373 374
@@ -528,9 +529,11 @@ void inet_csk_reqsk_queue_prune(struct sock *parent,
528 syn_ack_recalc(req, thresh, max_retries, 529 syn_ack_recalc(req, thresh, max_retries,
529 queue->rskq_defer_accept, 530 queue->rskq_defer_accept,
530 &expire, &resend); 531 &expire, &resend);
532 if (req->rsk_ops->syn_ack_timeout)
533 req->rsk_ops->syn_ack_timeout(parent, req);
531 if (!expire && 534 if (!expire &&
532 (!resend || 535 (!resend ||
533 !req->rsk_ops->rtx_syn_ack(parent, req) || 536 !req->rsk_ops->rtx_syn_ack(parent, req, NULL) ||
534 inet_rsk(req)->acked)) { 537 inet_rsk(req)->acked)) {
535 unsigned long timeo; 538 unsigned long timeo;
536 539
@@ -574,9 +577,9 @@ struct sock *inet_csk_clone(struct sock *sk, const struct request_sock *req,
574 newsk->sk_state = TCP_SYN_RECV; 577 newsk->sk_state = TCP_SYN_RECV;
575 newicsk->icsk_bind_hash = NULL; 578 newicsk->icsk_bind_hash = NULL;
576 579
577 inet_sk(newsk)->dport = inet_rsk(req)->rmt_port; 580 inet_sk(newsk)->inet_dport = inet_rsk(req)->rmt_port;
578 inet_sk(newsk)->num = ntohs(inet_rsk(req)->loc_port); 581 inet_sk(newsk)->inet_num = ntohs(inet_rsk(req)->loc_port);
579 inet_sk(newsk)->sport = inet_rsk(req)->loc_port; 582 inet_sk(newsk)->inet_sport = inet_rsk(req)->loc_port;
580 newsk->sk_write_space = sk_stream_write_space; 583 newsk->sk_write_space = sk_stream_write_space;
581 584
582 newicsk->icsk_retransmits = 0; 585 newicsk->icsk_retransmits = 0;
@@ -607,8 +610,8 @@ void inet_csk_destroy_sock(struct sock *sk)
607 /* It cannot be in hash table! */ 610 /* It cannot be in hash table! */
608 WARN_ON(!sk_unhashed(sk)); 611 WARN_ON(!sk_unhashed(sk));
609 612
610 /* If it has not 0 inet_sk(sk)->num, it must be bound */ 613 /* If it has not 0 inet_sk(sk)->inet_num, it must be bound */
611 WARN_ON(inet_sk(sk)->num && !inet_csk(sk)->icsk_bind_hash); 614 WARN_ON(inet_sk(sk)->inet_num && !inet_csk(sk)->icsk_bind_hash);
612 615
613 sk->sk_prot->destroy(sk); 616 sk->sk_prot->destroy(sk);
614 617
@@ -643,8 +646,8 @@ int inet_csk_listen_start(struct sock *sk, const int nr_table_entries)
643 * after validation is complete. 646 * after validation is complete.
644 */ 647 */
645 sk->sk_state = TCP_LISTEN; 648 sk->sk_state = TCP_LISTEN;
646 if (!sk->sk_prot->get_port(sk, inet->num)) { 649 if (!sk->sk_prot->get_port(sk, inet->inet_num)) {
647 inet->sport = htons(inet->num); 650 inet->inet_sport = htons(inet->inet_num);
648 651
649 sk_dst_reset(sk); 652 sk_dst_reset(sk);
650 sk->sk_prot->hash(sk); 653 sk->sk_prot->hash(sk);
@@ -720,8 +723,8 @@ void inet_csk_addr2sockaddr(struct sock *sk, struct sockaddr *uaddr)
720 const struct inet_sock *inet = inet_sk(sk); 723 const struct inet_sock *inet = inet_sk(sk);
721 724
722 sin->sin_family = AF_INET; 725 sin->sin_family = AF_INET;
723 sin->sin_addr.s_addr = inet->daddr; 726 sin->sin_addr.s_addr = inet->inet_daddr;
724 sin->sin_port = inet->dport; 727 sin->sin_port = inet->inet_dport;
725} 728}
726 729
727EXPORT_SYMBOL_GPL(inet_csk_addr2sockaddr); 730EXPORT_SYMBOL_GPL(inet_csk_addr2sockaddr);
diff --git a/net/ipv4/inet_diag.c b/net/ipv4/inet_diag.c
index a706a47f4dbb..e5fa2ddce320 100644
--- a/net/ipv4/inet_diag.c
+++ b/net/ipv4/inet_diag.c
@@ -14,6 +14,7 @@
14#include <linux/types.h> 14#include <linux/types.h>
15#include <linux/fcntl.h> 15#include <linux/fcntl.h>
16#include <linux/random.h> 16#include <linux/random.h>
17#include <linux/slab.h>
17#include <linux/cache.h> 18#include <linux/cache.h>
18#include <linux/init.h> 19#include <linux/init.h>
19#include <linux/time.h> 20#include <linux/time.h>
@@ -116,10 +117,10 @@ static int inet_csk_diag_fill(struct sock *sk,
116 r->id.idiag_cookie[0] = (u32)(unsigned long)sk; 117 r->id.idiag_cookie[0] = (u32)(unsigned long)sk;
117 r->id.idiag_cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1); 118 r->id.idiag_cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
118 119
119 r->id.idiag_sport = inet->sport; 120 r->id.idiag_sport = inet->inet_sport;
120 r->id.idiag_dport = inet->dport; 121 r->id.idiag_dport = inet->inet_dport;
121 r->id.idiag_src[0] = inet->rcv_saddr; 122 r->id.idiag_src[0] = inet->inet_rcv_saddr;
122 r->id.idiag_dst[0] = inet->daddr; 123 r->id.idiag_dst[0] = inet->inet_daddr;
123 124
124#if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE) 125#if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
125 if (r->idiag_family == AF_INET6) { 126 if (r->idiag_family == AF_INET6) {
@@ -368,7 +369,7 @@ static int inet_diag_bc_run(const void *bc, int len,
368 yes = entry->sport >= op[1].no; 369 yes = entry->sport >= op[1].no;
369 break; 370 break;
370 case INET_DIAG_BC_S_LE: 371 case INET_DIAG_BC_S_LE:
371 yes = entry->dport <= op[1].no; 372 yes = entry->sport <= op[1].no;
372 break; 373 break;
373 case INET_DIAG_BC_D_GE: 374 case INET_DIAG_BC_D_GE:
374 yes = entry->dport >= op[1].no; 375 yes = entry->dport >= op[1].no;
@@ -504,11 +505,11 @@ static int inet_csk_diag_dump(struct sock *sk,
504 } else 505 } else
505#endif 506#endif
506 { 507 {
507 entry.saddr = &inet->rcv_saddr; 508 entry.saddr = &inet->inet_rcv_saddr;
508 entry.daddr = &inet->daddr; 509 entry.daddr = &inet->inet_daddr;
509 } 510 }
510 entry.sport = inet->num; 511 entry.sport = inet->inet_num;
511 entry.dport = ntohs(inet->dport); 512 entry.dport = ntohs(inet->inet_dport);
512 entry.userlocks = sk->sk_userlocks; 513 entry.userlocks = sk->sk_userlocks;
513 514
514 if (!inet_diag_bc_run(RTA_DATA(bc), RTA_PAYLOAD(bc), &entry)) 515 if (!inet_diag_bc_run(RTA_DATA(bc), RTA_PAYLOAD(bc), &entry))
@@ -584,7 +585,7 @@ static int inet_diag_fill_req(struct sk_buff *skb, struct sock *sk,
584 if (tmo < 0) 585 if (tmo < 0)
585 tmo = 0; 586 tmo = 0;
586 587
587 r->id.idiag_sport = inet->sport; 588 r->id.idiag_sport = inet->inet_sport;
588 r->id.idiag_dport = ireq->rmt_port; 589 r->id.idiag_dport = ireq->rmt_port;
589 r->id.idiag_src[0] = ireq->loc_addr; 590 r->id.idiag_src[0] = ireq->loc_addr;
590 r->id.idiag_dst[0] = ireq->rmt_addr; 591 r->id.idiag_dst[0] = ireq->rmt_addr;
@@ -639,7 +640,7 @@ static int inet_diag_dump_reqs(struct sk_buff *skb, struct sock *sk,
639 640
640 if (cb->nlh->nlmsg_len > 4 + NLMSG_SPACE(sizeof(*r))) { 641 if (cb->nlh->nlmsg_len > 4 + NLMSG_SPACE(sizeof(*r))) {
641 bc = (struct rtattr *)(r + 1); 642 bc = (struct rtattr *)(r + 1);
642 entry.sport = inet->num; 643 entry.sport = inet->inet_num;
643 entry.userlocks = sk->sk_userlocks; 644 entry.userlocks = sk->sk_userlocks;
644 } 645 }
645 646
@@ -732,7 +733,7 @@ static int inet_diag_dump(struct sk_buff *skb, struct netlink_callback *cb)
732 continue; 733 continue;
733 } 734 }
734 735
735 if (r->id.idiag_sport != inet->sport && 736 if (r->id.idiag_sport != inet->inet_sport &&
736 r->id.idiag_sport) 737 r->id.idiag_sport)
737 goto next_listen; 738 goto next_listen;
738 739
@@ -774,7 +775,7 @@ skip_listen_ht:
774 if (!(r->idiag_states & ~(TCPF_LISTEN | TCPF_SYN_RECV))) 775 if (!(r->idiag_states & ~(TCPF_LISTEN | TCPF_SYN_RECV)))
775 goto unlock; 776 goto unlock;
776 777
777 for (i = s_i; i < hashinfo->ehash_size; i++) { 778 for (i = s_i; i <= hashinfo->ehash_mask; i++) {
778 struct inet_ehash_bucket *head = &hashinfo->ehash[i]; 779 struct inet_ehash_bucket *head = &hashinfo->ehash[i];
779 spinlock_t *lock = inet_ehash_lockp(hashinfo, i); 780 spinlock_t *lock = inet_ehash_lockp(hashinfo, i);
780 struct sock *sk; 781 struct sock *sk;
@@ -797,10 +798,10 @@ skip_listen_ht:
797 goto next_normal; 798 goto next_normal;
798 if (!(r->idiag_states & (1 << sk->sk_state))) 799 if (!(r->idiag_states & (1 << sk->sk_state)))
799 goto next_normal; 800 goto next_normal;
800 if (r->id.idiag_sport != inet->sport && 801 if (r->id.idiag_sport != inet->inet_sport &&
801 r->id.idiag_sport) 802 r->id.idiag_sport)
802 goto next_normal; 803 goto next_normal;
803 if (r->id.idiag_dport != inet->dport && 804 if (r->id.idiag_dport != inet->inet_dport &&
804 r->id.idiag_dport) 805 r->id.idiag_dport)
805 goto next_normal; 806 goto next_normal;
806 if (inet_csk_diag_dump(sk, skb, cb) < 0) { 807 if (inet_csk_diag_dump(sk, skb, cb) < 0) {
diff --git a/net/ipv4/inet_fragment.c b/net/ipv4/inet_fragment.c
index eaf3e2c8646a..a2ca6aed763b 100644
--- a/net/ipv4/inet_fragment.c
+++ b/net/ipv4/inet_fragment.c
@@ -19,6 +19,7 @@
19#include <linux/random.h> 19#include <linux/random.h>
20#include <linux/skbuff.h> 20#include <linux/skbuff.h>
21#include <linux/rtnetlink.h> 21#include <linux/rtnetlink.h>
22#include <linux/slab.h>
22 23
23#include <net/inet_frag.h> 24#include <net/inet_frag.h>
24 25
diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
index 625cc5f64c94..2b79377b468d 100644
--- a/net/ipv4/inet_hashtables.c
+++ b/net/ipv4/inet_hashtables.c
@@ -64,7 +64,7 @@ void inet_bind_hash(struct sock *sk, struct inet_bind_bucket *tb,
64 64
65 atomic_inc(&hashinfo->bsockets); 65 atomic_inc(&hashinfo->bsockets);
66 66
67 inet_sk(sk)->num = snum; 67 inet_sk(sk)->inet_num = snum;
68 sk_add_bind_node(sk, &tb->owners); 68 sk_add_bind_node(sk, &tb->owners);
69 tb->num_owners++; 69 tb->num_owners++;
70 inet_csk(sk)->icsk_bind_hash = tb; 70 inet_csk(sk)->icsk_bind_hash = tb;
@@ -76,7 +76,7 @@ void inet_bind_hash(struct sock *sk, struct inet_bind_bucket *tb,
76static void __inet_put_port(struct sock *sk) 76static void __inet_put_port(struct sock *sk)
77{ 77{
78 struct inet_hashinfo *hashinfo = sk->sk_prot->h.hashinfo; 78 struct inet_hashinfo *hashinfo = sk->sk_prot->h.hashinfo;
79 const int bhash = inet_bhashfn(sock_net(sk), inet_sk(sk)->num, 79 const int bhash = inet_bhashfn(sock_net(sk), inet_sk(sk)->inet_num,
80 hashinfo->bhash_size); 80 hashinfo->bhash_size);
81 struct inet_bind_hashbucket *head = &hashinfo->bhash[bhash]; 81 struct inet_bind_hashbucket *head = &hashinfo->bhash[bhash];
82 struct inet_bind_bucket *tb; 82 struct inet_bind_bucket *tb;
@@ -88,7 +88,7 @@ static void __inet_put_port(struct sock *sk)
88 __sk_del_bind_node(sk); 88 __sk_del_bind_node(sk);
89 tb->num_owners--; 89 tb->num_owners--;
90 inet_csk(sk)->icsk_bind_hash = NULL; 90 inet_csk(sk)->icsk_bind_hash = NULL;
91 inet_sk(sk)->num = 0; 91 inet_sk(sk)->inet_num = 0;
92 inet_bind_bucket_destroy(hashinfo->bind_bucket_cachep, tb); 92 inet_bind_bucket_destroy(hashinfo->bind_bucket_cachep, tb);
93 spin_unlock(&head->lock); 93 spin_unlock(&head->lock);
94} 94}
@@ -105,7 +105,7 @@ EXPORT_SYMBOL(inet_put_port);
105void __inet_inherit_port(struct sock *sk, struct sock *child) 105void __inet_inherit_port(struct sock *sk, struct sock *child)
106{ 106{
107 struct inet_hashinfo *table = sk->sk_prot->h.hashinfo; 107 struct inet_hashinfo *table = sk->sk_prot->h.hashinfo;
108 const int bhash = inet_bhashfn(sock_net(sk), inet_sk(child)->num, 108 const int bhash = inet_bhashfn(sock_net(sk), inet_sk(child)->inet_num,
109 table->bhash_size); 109 table->bhash_size);
110 struct inet_bind_hashbucket *head = &table->bhash[bhash]; 110 struct inet_bind_hashbucket *head = &table->bhash[bhash];
111 struct inet_bind_bucket *tb; 111 struct inet_bind_bucket *tb;
@@ -126,9 +126,9 @@ static inline int compute_score(struct sock *sk, struct net *net,
126 int score = -1; 126 int score = -1;
127 struct inet_sock *inet = inet_sk(sk); 127 struct inet_sock *inet = inet_sk(sk);
128 128
129 if (net_eq(sock_net(sk), net) && inet->num == hnum && 129 if (net_eq(sock_net(sk), net) && inet->inet_num == hnum &&
130 !ipv6_only_sock(sk)) { 130 !ipv6_only_sock(sk)) {
131 __be32 rcv_saddr = inet->rcv_saddr; 131 __be32 rcv_saddr = inet->inet_rcv_saddr;
132 score = sk->sk_family == PF_INET ? 1 : 0; 132 score = sk->sk_family == PF_INET ? 1 : 0;
133 if (rcv_saddr) { 133 if (rcv_saddr) {
134 if (rcv_saddr != daddr) 134 if (rcv_saddr != daddr)
@@ -209,7 +209,7 @@ struct sock * __inet_lookup_established(struct net *net,
209 * have wildcards anyways. 209 * have wildcards anyways.
210 */ 210 */
211 unsigned int hash = inet_ehashfn(net, daddr, hnum, saddr, sport); 211 unsigned int hash = inet_ehashfn(net, daddr, hnum, saddr, sport);
212 unsigned int slot = hash & (hashinfo->ehash_size - 1); 212 unsigned int slot = hash & hashinfo->ehash_mask;
213 struct inet_ehash_bucket *head = &hashinfo->ehash[slot]; 213 struct inet_ehash_bucket *head = &hashinfo->ehash[slot];
214 214
215 rcu_read_lock(); 215 rcu_read_lock();
@@ -273,18 +273,20 @@ static int __inet_check_established(struct inet_timewait_death_row *death_row,
273{ 273{
274 struct inet_hashinfo *hinfo = death_row->hashinfo; 274 struct inet_hashinfo *hinfo = death_row->hashinfo;
275 struct inet_sock *inet = inet_sk(sk); 275 struct inet_sock *inet = inet_sk(sk);
276 __be32 daddr = inet->rcv_saddr; 276 __be32 daddr = inet->inet_rcv_saddr;
277 __be32 saddr = inet->daddr; 277 __be32 saddr = inet->inet_daddr;
278 int dif = sk->sk_bound_dev_if; 278 int dif = sk->sk_bound_dev_if;
279 INET_ADDR_COOKIE(acookie, saddr, daddr) 279 INET_ADDR_COOKIE(acookie, saddr, daddr)
280 const __portpair ports = INET_COMBINED_PORTS(inet->dport, lport); 280 const __portpair ports = INET_COMBINED_PORTS(inet->inet_dport, lport);
281 struct net *net = sock_net(sk); 281 struct net *net = sock_net(sk);
282 unsigned int hash = inet_ehashfn(net, daddr, lport, saddr, inet->dport); 282 unsigned int hash = inet_ehashfn(net, daddr, lport,
283 saddr, inet->inet_dport);
283 struct inet_ehash_bucket *head = inet_ehash_bucket(hinfo, hash); 284 struct inet_ehash_bucket *head = inet_ehash_bucket(hinfo, hash);
284 spinlock_t *lock = inet_ehash_lockp(hinfo, hash); 285 spinlock_t *lock = inet_ehash_lockp(hinfo, hash);
285 struct sock *sk2; 286 struct sock *sk2;
286 const struct hlist_nulls_node *node; 287 const struct hlist_nulls_node *node;
287 struct inet_timewait_sock *tw; 288 struct inet_timewait_sock *tw;
289 int twrefcnt = 0;
288 290
289 spin_lock(lock); 291 spin_lock(lock);
290 292
@@ -312,25 +314,28 @@ static int __inet_check_established(struct inet_timewait_death_row *death_row,
312unique: 314unique:
313 /* Must record num and sport now. Otherwise we will see 315 /* Must record num and sport now. Otherwise we will see
314 * in hash table socket with a funny identity. */ 316 * in hash table socket with a funny identity. */
315 inet->num = lport; 317 inet->inet_num = lport;
316 inet->sport = htons(lport); 318 inet->inet_sport = htons(lport);
317 sk->sk_hash = hash; 319 sk->sk_hash = hash;
318 WARN_ON(!sk_unhashed(sk)); 320 WARN_ON(!sk_unhashed(sk));
319 __sk_nulls_add_node_rcu(sk, &head->chain); 321 __sk_nulls_add_node_rcu(sk, &head->chain);
322 if (tw) {
323 twrefcnt = inet_twsk_unhash(tw);
324 NET_INC_STATS_BH(net, LINUX_MIB_TIMEWAITRECYCLED);
325 }
320 spin_unlock(lock); 326 spin_unlock(lock);
327 if (twrefcnt)
328 inet_twsk_put(tw);
321 sock_prot_inuse_add(sock_net(sk), sk->sk_prot, 1); 329 sock_prot_inuse_add(sock_net(sk), sk->sk_prot, 1);
322 330
323 if (twp) { 331 if (twp) {
324 *twp = tw; 332 *twp = tw;
325 NET_INC_STATS_BH(net, LINUX_MIB_TIMEWAITRECYCLED);
326 } else if (tw) { 333 } else if (tw) {
327 /* Silly. Should hash-dance instead... */ 334 /* Silly. Should hash-dance instead... */
328 inet_twsk_deschedule(tw, death_row); 335 inet_twsk_deschedule(tw, death_row);
329 NET_INC_STATS_BH(net, LINUX_MIB_TIMEWAITRECYCLED);
330 336
331 inet_twsk_put(tw); 337 inet_twsk_put(tw);
332 } 338 }
333
334 return 0; 339 return 0;
335 340
336not_unique: 341not_unique:
@@ -341,16 +346,18 @@ not_unique:
341static inline u32 inet_sk_port_offset(const struct sock *sk) 346static inline u32 inet_sk_port_offset(const struct sock *sk)
342{ 347{
343 const struct inet_sock *inet = inet_sk(sk); 348 const struct inet_sock *inet = inet_sk(sk);
344 return secure_ipv4_port_ephemeral(inet->rcv_saddr, inet->daddr, 349 return secure_ipv4_port_ephemeral(inet->inet_rcv_saddr,
345 inet->dport); 350 inet->inet_daddr,
351 inet->inet_dport);
346} 352}
347 353
348void __inet_hash_nolisten(struct sock *sk) 354int __inet_hash_nolisten(struct sock *sk, struct inet_timewait_sock *tw)
349{ 355{
350 struct inet_hashinfo *hashinfo = sk->sk_prot->h.hashinfo; 356 struct inet_hashinfo *hashinfo = sk->sk_prot->h.hashinfo;
351 struct hlist_nulls_head *list; 357 struct hlist_nulls_head *list;
352 spinlock_t *lock; 358 spinlock_t *lock;
353 struct inet_ehash_bucket *head; 359 struct inet_ehash_bucket *head;
360 int twrefcnt = 0;
354 361
355 WARN_ON(!sk_unhashed(sk)); 362 WARN_ON(!sk_unhashed(sk));
356 363
@@ -361,8 +368,13 @@ void __inet_hash_nolisten(struct sock *sk)
361 368
362 spin_lock(lock); 369 spin_lock(lock);
363 __sk_nulls_add_node_rcu(sk, list); 370 __sk_nulls_add_node_rcu(sk, list);
371 if (tw) {
372 WARN_ON(sk->sk_hash != tw->tw_hash);
373 twrefcnt = inet_twsk_unhash(tw);
374 }
364 spin_unlock(lock); 375 spin_unlock(lock);
365 sock_prot_inuse_add(sock_net(sk), sk->sk_prot, 1); 376 sock_prot_inuse_add(sock_net(sk), sk->sk_prot, 1);
377 return twrefcnt;
366} 378}
367EXPORT_SYMBOL_GPL(__inet_hash_nolisten); 379EXPORT_SYMBOL_GPL(__inet_hash_nolisten);
368 380
@@ -372,7 +384,7 @@ static void __inet_hash(struct sock *sk)
372 struct inet_listen_hashbucket *ilb; 384 struct inet_listen_hashbucket *ilb;
373 385
374 if (sk->sk_state != TCP_LISTEN) { 386 if (sk->sk_state != TCP_LISTEN) {
375 __inet_hash_nolisten(sk); 387 __inet_hash_nolisten(sk, NULL);
376 return; 388 return;
377 } 389 }
378 390
@@ -421,14 +433,15 @@ int __inet_hash_connect(struct inet_timewait_death_row *death_row,
421 struct sock *sk, u32 port_offset, 433 struct sock *sk, u32 port_offset,
422 int (*check_established)(struct inet_timewait_death_row *, 434 int (*check_established)(struct inet_timewait_death_row *,
423 struct sock *, __u16, struct inet_timewait_sock **), 435 struct sock *, __u16, struct inet_timewait_sock **),
424 void (*hash)(struct sock *sk)) 436 int (*hash)(struct sock *sk, struct inet_timewait_sock *twp))
425{ 437{
426 struct inet_hashinfo *hinfo = death_row->hashinfo; 438 struct inet_hashinfo *hinfo = death_row->hashinfo;
427 const unsigned short snum = inet_sk(sk)->num; 439 const unsigned short snum = inet_sk(sk)->inet_num;
428 struct inet_bind_hashbucket *head; 440 struct inet_bind_hashbucket *head;
429 struct inet_bind_bucket *tb; 441 struct inet_bind_bucket *tb;
430 int ret; 442 int ret;
431 struct net *net = sock_net(sk); 443 struct net *net = sock_net(sk);
444 int twrefcnt = 1;
432 445
433 if (!snum) { 446 if (!snum) {
434 int i, remaining, low, high, port; 447 int i, remaining, low, high, port;
@@ -452,7 +465,8 @@ int __inet_hash_connect(struct inet_timewait_death_row *death_row,
452 * unique enough. 465 * unique enough.
453 */ 466 */
454 inet_bind_bucket_for_each(tb, node, &head->chain) { 467 inet_bind_bucket_for_each(tb, node, &head->chain) {
455 if (ib_net(tb) == net && tb->port == port) { 468 if (net_eq(ib_net(tb), net) &&
469 tb->port == port) {
456 if (tb->fastreuse >= 0) 470 if (tb->fastreuse >= 0)
457 goto next_port; 471 goto next_port;
458 WARN_ON(hlist_empty(&tb->owners)); 472 WARN_ON(hlist_empty(&tb->owners));
@@ -485,14 +499,19 @@ ok:
485 /* Head lock still held and bh's disabled */ 499 /* Head lock still held and bh's disabled */
486 inet_bind_hash(sk, tb, port); 500 inet_bind_hash(sk, tb, port);
487 if (sk_unhashed(sk)) { 501 if (sk_unhashed(sk)) {
488 inet_sk(sk)->sport = htons(port); 502 inet_sk(sk)->inet_sport = htons(port);
489 hash(sk); 503 twrefcnt += hash(sk, tw);
490 } 504 }
505 if (tw)
506 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
491 spin_unlock(&head->lock); 507 spin_unlock(&head->lock);
492 508
493 if (tw) { 509 if (tw) {
494 inet_twsk_deschedule(tw, death_row); 510 inet_twsk_deschedule(tw, death_row);
495 inet_twsk_put(tw); 511 while (twrefcnt) {
512 twrefcnt--;
513 inet_twsk_put(tw);
514 }
496 } 515 }
497 516
498 ret = 0; 517 ret = 0;
@@ -503,7 +522,7 @@ ok:
503 tb = inet_csk(sk)->icsk_bind_hash; 522 tb = inet_csk(sk)->icsk_bind_hash;
504 spin_lock_bh(&head->lock); 523 spin_lock_bh(&head->lock);
505 if (sk_head(&tb->owners) == sk && !sk->sk_bind_node.next) { 524 if (sk_head(&tb->owners) == sk && !sk->sk_bind_node.next) {
506 hash(sk); 525 hash(sk, NULL);
507 spin_unlock_bh(&head->lock); 526 spin_unlock_bh(&head->lock);
508 return 0; 527 return 0;
509 } else { 528 } else {
diff --git a/net/ipv4/inet_lro.c b/net/ipv4/inet_lro.c
index 6a667dae315e..47038cb6c138 100644
--- a/net/ipv4/inet_lro.c
+++ b/net/ipv4/inet_lro.c
@@ -64,15 +64,15 @@ static int lro_tcp_ip_check(struct iphdr *iph, struct tcphdr *tcph,
64 if (iph->ihl != IPH_LEN_WO_OPTIONS) 64 if (iph->ihl != IPH_LEN_WO_OPTIONS)
65 return -1; 65 return -1;
66 66
67 if (tcph->cwr || tcph->ece || tcph->urg || !tcph->ack 67 if (tcph->cwr || tcph->ece || tcph->urg || !tcph->ack ||
68 || tcph->rst || tcph->syn || tcph->fin) 68 tcph->rst || tcph->syn || tcph->fin)
69 return -1; 69 return -1;
70 70
71 if (INET_ECN_is_ce(ipv4_get_dsfield(iph))) 71 if (INET_ECN_is_ce(ipv4_get_dsfield(iph)))
72 return -1; 72 return -1;
73 73
74 if (tcph->doff != TCPH_LEN_WO_OPTIONS 74 if (tcph->doff != TCPH_LEN_WO_OPTIONS &&
75 && tcph->doff != TCPH_LEN_W_TIMESTAMP) 75 tcph->doff != TCPH_LEN_W_TIMESTAMP)
76 return -1; 76 return -1;
77 77
78 /* check tcp options (only timestamp allowed) */ 78 /* check tcp options (only timestamp allowed) */
@@ -262,10 +262,10 @@ static int lro_check_tcp_conn(struct net_lro_desc *lro_desc,
262 struct iphdr *iph, 262 struct iphdr *iph,
263 struct tcphdr *tcph) 263 struct tcphdr *tcph)
264{ 264{
265 if ((lro_desc->iph->saddr != iph->saddr) 265 if ((lro_desc->iph->saddr != iph->saddr) ||
266 || (lro_desc->iph->daddr != iph->daddr) 266 (lro_desc->iph->daddr != iph->daddr) ||
267 || (lro_desc->tcph->source != tcph->source) 267 (lro_desc->tcph->source != tcph->source) ||
268 || (lro_desc->tcph->dest != tcph->dest)) 268 (lro_desc->tcph->dest != tcph->dest))
269 return -1; 269 return -1;
270 return 0; 270 return 0;
271} 271}
@@ -339,9 +339,9 @@ static int __lro_proc_skb(struct net_lro_mgr *lro_mgr, struct sk_buff *skb,
339 u64 flags; 339 u64 flags;
340 int vlan_hdr_len = 0; 340 int vlan_hdr_len = 0;
341 341
342 if (!lro_mgr->get_skb_header 342 if (!lro_mgr->get_skb_header ||
343 || lro_mgr->get_skb_header(skb, (void *)&iph, (void *)&tcph, 343 lro_mgr->get_skb_header(skb, (void *)&iph, (void *)&tcph,
344 &flags, priv)) 344 &flags, priv))
345 goto out; 345 goto out;
346 346
347 if (!(flags & LRO_IPV4) || !(flags & LRO_TCP)) 347 if (!(flags & LRO_IPV4) || !(flags & LRO_TCP))
@@ -351,8 +351,8 @@ static int __lro_proc_skb(struct net_lro_mgr *lro_mgr, struct sk_buff *skb,
351 if (!lro_desc) 351 if (!lro_desc)
352 goto out; 352 goto out;
353 353
354 if ((skb->protocol == htons(ETH_P_8021Q)) 354 if ((skb->protocol == htons(ETH_P_8021Q)) &&
355 && !(lro_mgr->features & LRO_F_EXTRACT_VLAN_ID)) 355 !(lro_mgr->features & LRO_F_EXTRACT_VLAN_ID))
356 vlan_hdr_len = VLAN_HLEN; 356 vlan_hdr_len = VLAN_HLEN;
357 357
358 if (!lro_desc->active) { /* start new lro session */ 358 if (!lro_desc->active) { /* start new lro session */
@@ -446,9 +446,9 @@ static struct sk_buff *__lro_proc_segment(struct net_lro_mgr *lro_mgr,
446 int hdr_len = LRO_MAX_PG_HLEN; 446 int hdr_len = LRO_MAX_PG_HLEN;
447 int vlan_hdr_len = 0; 447 int vlan_hdr_len = 0;
448 448
449 if (!lro_mgr->get_frag_header 449 if (!lro_mgr->get_frag_header ||
450 || lro_mgr->get_frag_header(frags, (void *)&mac_hdr, (void *)&iph, 450 lro_mgr->get_frag_header(frags, (void *)&mac_hdr, (void *)&iph,
451 (void *)&tcph, &flags, priv)) { 451 (void *)&tcph, &flags, priv)) {
452 mac_hdr = page_address(frags->page) + frags->page_offset; 452 mac_hdr = page_address(frags->page) + frags->page_offset;
453 goto out1; 453 goto out1;
454 } 454 }
@@ -472,8 +472,8 @@ static struct sk_buff *__lro_proc_segment(struct net_lro_mgr *lro_mgr,
472 if (!skb) 472 if (!skb)
473 goto out; 473 goto out;
474 474
475 if ((skb->protocol == htons(ETH_P_8021Q)) 475 if ((skb->protocol == htons(ETH_P_8021Q)) &&
476 && !(lro_mgr->features & LRO_F_EXTRACT_VLAN_ID)) 476 !(lro_mgr->features & LRO_F_EXTRACT_VLAN_ID))
477 vlan_hdr_len = VLAN_HLEN; 477 vlan_hdr_len = VLAN_HLEN;
478 478
479 iph = (void *)(skb->data + vlan_hdr_len); 479 iph = (void *)(skb->data + vlan_hdr_len);
diff --git a/net/ipv4/inet_timewait_sock.c b/net/ipv4/inet_timewait_sock.c
index 13f0781f35cd..c5af909cf701 100644
--- a/net/ipv4/inet_timewait_sock.c
+++ b/net/ipv4/inet_timewait_sock.c
@@ -10,44 +10,92 @@
10 10
11#include <linux/kernel.h> 11#include <linux/kernel.h>
12#include <linux/kmemcheck.h> 12#include <linux/kmemcheck.h>
13#include <linux/slab.h>
13#include <net/inet_hashtables.h> 14#include <net/inet_hashtables.h>
14#include <net/inet_timewait_sock.h> 15#include <net/inet_timewait_sock.h>
15#include <net/ip.h> 16#include <net/ip.h>
16 17
18
19/**
20 * inet_twsk_unhash - unhash a timewait socket from established hash
21 * @tw: timewait socket
22 *
23 * unhash a timewait socket from established hash, if hashed.
24 * ehash lock must be held by caller.
25 * Returns 1 if caller should call inet_twsk_put() after lock release.
26 */
27int inet_twsk_unhash(struct inet_timewait_sock *tw)
28{
29 if (hlist_nulls_unhashed(&tw->tw_node))
30 return 0;
31
32 hlist_nulls_del_rcu(&tw->tw_node);
33 sk_nulls_node_init(&tw->tw_node);
34 /*
35 * We cannot call inet_twsk_put() ourself under lock,
36 * caller must call it for us.
37 */
38 return 1;
39}
40
41/**
42 * inet_twsk_bind_unhash - unhash a timewait socket from bind hash
43 * @tw: timewait socket
44 * @hashinfo: hashinfo pointer
45 *
46 * unhash a timewait socket from bind hash, if hashed.
47 * bind hash lock must be held by caller.
48 * Returns 1 if caller should call inet_twsk_put() after lock release.
49 */
50int inet_twsk_bind_unhash(struct inet_timewait_sock *tw,
51 struct inet_hashinfo *hashinfo)
52{
53 struct inet_bind_bucket *tb = tw->tw_tb;
54
55 if (!tb)
56 return 0;
57
58 __hlist_del(&tw->tw_bind_node);
59 tw->tw_tb = NULL;
60 inet_bind_bucket_destroy(hashinfo->bind_bucket_cachep, tb);
61 /*
62 * We cannot call inet_twsk_put() ourself under lock,
63 * caller must call it for us.
64 */
65 return 1;
66}
67
17/* Must be called with locally disabled BHs. */ 68/* Must be called with locally disabled BHs. */
18static void __inet_twsk_kill(struct inet_timewait_sock *tw, 69static void __inet_twsk_kill(struct inet_timewait_sock *tw,
19 struct inet_hashinfo *hashinfo) 70 struct inet_hashinfo *hashinfo)
20{ 71{
21 struct inet_bind_hashbucket *bhead; 72 struct inet_bind_hashbucket *bhead;
22 struct inet_bind_bucket *tb; 73 int refcnt;
23 /* Unlink from established hashes. */ 74 /* Unlink from established hashes. */
24 spinlock_t *lock = inet_ehash_lockp(hashinfo, tw->tw_hash); 75 spinlock_t *lock = inet_ehash_lockp(hashinfo, tw->tw_hash);
25 76
26 spin_lock(lock); 77 spin_lock(lock);
27 if (hlist_nulls_unhashed(&tw->tw_node)) { 78 refcnt = inet_twsk_unhash(tw);
28 spin_unlock(lock);
29 return;
30 }
31 hlist_nulls_del_rcu(&tw->tw_node);
32 sk_nulls_node_init(&tw->tw_node);
33 spin_unlock(lock); 79 spin_unlock(lock);
34 80
35 /* Disassociate with bind bucket. */ 81 /* Disassociate with bind bucket. */
36 bhead = &hashinfo->bhash[inet_bhashfn(twsk_net(tw), tw->tw_num, 82 bhead = &hashinfo->bhash[inet_bhashfn(twsk_net(tw), tw->tw_num,
37 hashinfo->bhash_size)]; 83 hashinfo->bhash_size)];
84
38 spin_lock(&bhead->lock); 85 spin_lock(&bhead->lock);
39 tb = tw->tw_tb; 86 refcnt += inet_twsk_bind_unhash(tw, hashinfo);
40 __hlist_del(&tw->tw_bind_node);
41 tw->tw_tb = NULL;
42 inet_bind_bucket_destroy(hashinfo->bind_bucket_cachep, tb);
43 spin_unlock(&bhead->lock); 87 spin_unlock(&bhead->lock);
88
44#ifdef SOCK_REFCNT_DEBUG 89#ifdef SOCK_REFCNT_DEBUG
45 if (atomic_read(&tw->tw_refcnt) != 1) { 90 if (atomic_read(&tw->tw_refcnt) != 1) {
46 printk(KERN_DEBUG "%s timewait_sock %p refcnt=%d\n", 91 printk(KERN_DEBUG "%s timewait_sock %p refcnt=%d\n",
47 tw->tw_prot->name, tw, atomic_read(&tw->tw_refcnt)); 92 tw->tw_prot->name, tw, atomic_read(&tw->tw_refcnt));
48 } 93 }
49#endif 94#endif
50 inet_twsk_put(tw); 95 while (refcnt) {
96 inet_twsk_put(tw);
97 refcnt--;
98 }
51} 99}
52 100
53static noinline void inet_twsk_free(struct inet_timewait_sock *tw) 101static noinline void inet_twsk_free(struct inet_timewait_sock *tw)
@@ -86,7 +134,7 @@ void __inet_twsk_hashdance(struct inet_timewait_sock *tw, struct sock *sk,
86 Note, that any socket with inet->num != 0 MUST be bound in 134 Note, that any socket with inet->num != 0 MUST be bound in
87 binding cache, even if it is closed. 135 binding cache, even if it is closed.
88 */ 136 */
89 bhead = &hashinfo->bhash[inet_bhashfn(twsk_net(tw), inet->num, 137 bhead = &hashinfo->bhash[inet_bhashfn(twsk_net(tw), inet->inet_num,
90 hashinfo->bhash_size)]; 138 hashinfo->bhash_size)];
91 spin_lock(&bhead->lock); 139 spin_lock(&bhead->lock);
92 tw->tw_tb = icsk->icsk_bind_hash; 140 tw->tw_tb = icsk->icsk_bind_hash;
@@ -101,16 +149,24 @@ void __inet_twsk_hashdance(struct inet_timewait_sock *tw, struct sock *sk,
101 * Should be done before removing sk from established chain 149 * Should be done before removing sk from established chain
102 * because readers are lockless and search established first. 150 * because readers are lockless and search established first.
103 */ 151 */
104 atomic_inc(&tw->tw_refcnt);
105 inet_twsk_add_node_rcu(tw, &ehead->twchain); 152 inet_twsk_add_node_rcu(tw, &ehead->twchain);
106 153
107 /* Step 3: Remove SK from established hash. */ 154 /* Step 3: Remove SK from established hash. */
108 if (__sk_nulls_del_node_init_rcu(sk)) 155 if (__sk_nulls_del_node_init_rcu(sk))
109 sock_prot_inuse_add(sock_net(sk), sk->sk_prot, -1); 156 sock_prot_inuse_add(sock_net(sk), sk->sk_prot, -1);
110 157
158 /*
159 * Notes :
160 * - We initially set tw_refcnt to 0 in inet_twsk_alloc()
161 * - We add one reference for the bhash link
162 * - We add one reference for the ehash link
163 * - We want this refcnt update done before allowing other
164 * threads to find this tw in ehash chain.
165 */
166 atomic_add(1 + 1 + 1, &tw->tw_refcnt);
167
111 spin_unlock(lock); 168 spin_unlock(lock);
112} 169}
113
114EXPORT_SYMBOL_GPL(__inet_twsk_hashdance); 170EXPORT_SYMBOL_GPL(__inet_twsk_hashdance);
115 171
116struct inet_timewait_sock *inet_twsk_alloc(const struct sock *sk, const int state) 172struct inet_timewait_sock *inet_twsk_alloc(const struct sock *sk, const int state)
@@ -124,14 +180,14 @@ struct inet_timewait_sock *inet_twsk_alloc(const struct sock *sk, const int stat
124 kmemcheck_annotate_bitfield(tw, flags); 180 kmemcheck_annotate_bitfield(tw, flags);
125 181
126 /* Give us an identity. */ 182 /* Give us an identity. */
127 tw->tw_daddr = inet->daddr; 183 tw->tw_daddr = inet->inet_daddr;
128 tw->tw_rcv_saddr = inet->rcv_saddr; 184 tw->tw_rcv_saddr = inet->inet_rcv_saddr;
129 tw->tw_bound_dev_if = sk->sk_bound_dev_if; 185 tw->tw_bound_dev_if = sk->sk_bound_dev_if;
130 tw->tw_num = inet->num; 186 tw->tw_num = inet->inet_num;
131 tw->tw_state = TCP_TIME_WAIT; 187 tw->tw_state = TCP_TIME_WAIT;
132 tw->tw_substate = state; 188 tw->tw_substate = state;
133 tw->tw_sport = inet->sport; 189 tw->tw_sport = inet->inet_sport;
134 tw->tw_dport = inet->dport; 190 tw->tw_dport = inet->inet_dport;
135 tw->tw_family = sk->sk_family; 191 tw->tw_family = sk->sk_family;
136 tw->tw_reuse = sk->sk_reuse; 192 tw->tw_reuse = sk->sk_reuse;
137 tw->tw_hash = sk->sk_hash; 193 tw->tw_hash = sk->sk_hash;
@@ -139,14 +195,18 @@ struct inet_timewait_sock *inet_twsk_alloc(const struct sock *sk, const int stat
139 tw->tw_transparent = inet->transparent; 195 tw->tw_transparent = inet->transparent;
140 tw->tw_prot = sk->sk_prot_creator; 196 tw->tw_prot = sk->sk_prot_creator;
141 twsk_net_set(tw, hold_net(sock_net(sk))); 197 twsk_net_set(tw, hold_net(sock_net(sk)));
142 atomic_set(&tw->tw_refcnt, 1); 198 /*
199 * Because we use RCU lookups, we should not set tw_refcnt
200 * to a non null value before everything is setup for this
201 * timewait socket.
202 */
203 atomic_set(&tw->tw_refcnt, 0);
143 inet_twsk_dead_node_init(tw); 204 inet_twsk_dead_node_init(tw);
144 __module_get(tw->tw_prot->owner); 205 __module_get(tw->tw_prot->owner);
145 } 206 }
146 207
147 return tw; 208 return tw;
148} 209}
149
150EXPORT_SYMBOL_GPL(inet_twsk_alloc); 210EXPORT_SYMBOL_GPL(inet_twsk_alloc);
151 211
152/* Returns non-zero if quota exceeded. */ 212/* Returns non-zero if quota exceeded. */
@@ -225,7 +285,6 @@ void inet_twdr_hangman(unsigned long data)
225out: 285out:
226 spin_unlock(&twdr->death_lock); 286 spin_unlock(&twdr->death_lock);
227} 287}
228
229EXPORT_SYMBOL_GPL(inet_twdr_hangman); 288EXPORT_SYMBOL_GPL(inet_twdr_hangman);
230 289
231void inet_twdr_twkill_work(struct work_struct *work) 290void inet_twdr_twkill_work(struct work_struct *work)
@@ -256,7 +315,6 @@ void inet_twdr_twkill_work(struct work_struct *work)
256 spin_unlock_bh(&twdr->death_lock); 315 spin_unlock_bh(&twdr->death_lock);
257 } 316 }
258} 317}
259
260EXPORT_SYMBOL_GPL(inet_twdr_twkill_work); 318EXPORT_SYMBOL_GPL(inet_twdr_twkill_work);
261 319
262/* These are always called from BH context. See callers in 320/* These are always called from BH context. See callers in
@@ -276,7 +334,6 @@ void inet_twsk_deschedule(struct inet_timewait_sock *tw,
276 spin_unlock(&twdr->death_lock); 334 spin_unlock(&twdr->death_lock);
277 __inet_twsk_kill(tw, twdr->hashinfo); 335 __inet_twsk_kill(tw, twdr->hashinfo);
278} 336}
279
280EXPORT_SYMBOL(inet_twsk_deschedule); 337EXPORT_SYMBOL(inet_twsk_deschedule);
281 338
282void inet_twsk_schedule(struct inet_timewait_sock *tw, 339void inet_twsk_schedule(struct inet_timewait_sock *tw,
@@ -357,7 +414,6 @@ void inet_twsk_schedule(struct inet_timewait_sock *tw,
357 mod_timer(&twdr->tw_timer, jiffies + twdr->period); 414 mod_timer(&twdr->tw_timer, jiffies + twdr->period);
358 spin_unlock(&twdr->death_lock); 415 spin_unlock(&twdr->death_lock);
359} 416}
360
361EXPORT_SYMBOL_GPL(inet_twsk_schedule); 417EXPORT_SYMBOL_GPL(inet_twsk_schedule);
362 418
363void inet_twdr_twcal_tick(unsigned long data) 419void inet_twdr_twcal_tick(unsigned long data)
@@ -418,40 +474,48 @@ out:
418#endif 474#endif
419 spin_unlock(&twdr->death_lock); 475 spin_unlock(&twdr->death_lock);
420} 476}
421
422EXPORT_SYMBOL_GPL(inet_twdr_twcal_tick); 477EXPORT_SYMBOL_GPL(inet_twdr_twcal_tick);
423 478
424void inet_twsk_purge(struct net *net, struct inet_hashinfo *hashinfo, 479void inet_twsk_purge(struct inet_hashinfo *hashinfo,
425 struct inet_timewait_death_row *twdr, int family) 480 struct inet_timewait_death_row *twdr, int family)
426{ 481{
427 struct inet_timewait_sock *tw; 482 struct inet_timewait_sock *tw;
428 struct sock *sk; 483 struct sock *sk;
429 struct hlist_nulls_node *node; 484 struct hlist_nulls_node *node;
430 int h; 485 unsigned int slot;
431 486
432 local_bh_disable(); 487 for (slot = 0; slot <= hashinfo->ehash_mask; slot++) {
433 for (h = 0; h < (hashinfo->ehash_size); h++) { 488 struct inet_ehash_bucket *head = &hashinfo->ehash[slot];
434 struct inet_ehash_bucket *head = 489restart_rcu:
435 inet_ehash_bucket(hashinfo, h); 490 rcu_read_lock();
436 spinlock_t *lock = inet_ehash_lockp(hashinfo, h);
437restart: 491restart:
438 spin_lock(lock); 492 sk_nulls_for_each_rcu(sk, node, &head->twchain) {
439 sk_nulls_for_each(sk, node, &head->twchain) {
440
441 tw = inet_twsk(sk); 493 tw = inet_twsk(sk);
442 if (!net_eq(twsk_net(tw), net) || 494 if ((tw->tw_family != family) ||
443 tw->tw_family != family) 495 atomic_read(&twsk_net(tw)->count))
444 continue; 496 continue;
445 497
446 atomic_inc(&tw->tw_refcnt); 498 if (unlikely(!atomic_inc_not_zero(&tw->tw_refcnt)))
447 spin_unlock(lock); 499 continue;
500
501 if (unlikely((tw->tw_family != family) ||
502 atomic_read(&twsk_net(tw)->count))) {
503 inet_twsk_put(tw);
504 goto restart;
505 }
506
507 rcu_read_unlock();
448 inet_twsk_deschedule(tw, twdr); 508 inet_twsk_deschedule(tw, twdr);
449 inet_twsk_put(tw); 509 inet_twsk_put(tw);
450 510 goto restart_rcu;
451 goto restart;
452 } 511 }
453 spin_unlock(lock); 512 /* If the nulls value we got at the end of this lookup is
513 * not the expected one, we must restart lookup.
514 * We probably met an item that was moved to another chain.
515 */
516 if (get_nulls_value(node) != slot)
517 goto restart;
518 rcu_read_unlock();
454 } 519 }
455 local_bh_enable();
456} 520}
457EXPORT_SYMBOL_GPL(inet_twsk_purge); 521EXPORT_SYMBOL_GPL(inet_twsk_purge);
diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
index b1fbe18feb5a..6bcfe52a9c87 100644
--- a/net/ipv4/inetpeer.c
+++ b/net/ipv4/inetpeer.c
@@ -67,9 +67,6 @@
67 * ip_id_count: idlock 67 * ip_id_count: idlock
68 */ 68 */
69 69
70/* Exported for inet_getid inline function. */
71DEFINE_SPINLOCK(inet_peer_idlock);
72
73static struct kmem_cache *peer_cachep __read_mostly; 70static struct kmem_cache *peer_cachep __read_mostly;
74 71
75#define node_height(x) x->avl_height 72#define node_height(x) x->avl_height
@@ -390,7 +387,7 @@ struct inet_peer *inet_getpeer(__be32 daddr, int create)
390 n->v4daddr = daddr; 387 n->v4daddr = daddr;
391 atomic_set(&n->refcnt, 1); 388 atomic_set(&n->refcnt, 1);
392 atomic_set(&n->rid, 0); 389 atomic_set(&n->rid, 0);
393 n->ip_id_count = secure_ip_id(daddr); 390 atomic_set(&n->ip_id_count, secure_ip_id(daddr));
394 n->tcp_ts_stamp = 0; 391 n->tcp_ts_stamp = 0;
395 392
396 write_lock_bh(&peer_pool_lock); 393 write_lock_bh(&peer_pool_lock);
diff --git a/net/ipv4/ip_forward.c b/net/ipv4/ip_forward.c
index a2991bc8e32e..af10942b326c 100644
--- a/net/ipv4/ip_forward.c
+++ b/net/ipv4/ip_forward.c
@@ -25,6 +25,7 @@
25#include <linux/ip.h> 25#include <linux/ip.h>
26#include <linux/icmp.h> 26#include <linux/icmp.h>
27#include <linux/netdevice.h> 27#include <linux/netdevice.h>
28#include <linux/slab.h>
28#include <net/sock.h> 29#include <net/sock.h>
29#include <net/ip.h> 30#include <net/ip.h>
30#include <net/tcp.h> 31#include <net/tcp.h>
diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
index d3fe10be7219..75347ea70ea0 100644
--- a/net/ipv4/ip_fragment.c
+++ b/net/ipv4/ip_fragment.c
@@ -32,6 +32,9 @@
32#include <linux/netdevice.h> 32#include <linux/netdevice.h>
33#include <linux/jhash.h> 33#include <linux/jhash.h>
34#include <linux/random.h> 34#include <linux/random.h>
35#include <linux/slab.h>
36#include <net/route.h>
37#include <net/dst.h>
35#include <net/sock.h> 38#include <net/sock.h>
36#include <net/ip.h> 39#include <net/ip.h>
37#include <net/icmp.h> 40#include <net/icmp.h>
@@ -205,11 +208,35 @@ static void ip_expire(unsigned long arg)
205 if ((qp->q.last_in & INET_FRAG_FIRST_IN) && qp->q.fragments != NULL) { 208 if ((qp->q.last_in & INET_FRAG_FIRST_IN) && qp->q.fragments != NULL) {
206 struct sk_buff *head = qp->q.fragments; 209 struct sk_buff *head = qp->q.fragments;
207 210
208 /* Send an ICMP "Fragment Reassembly Timeout" message. */ 211 rcu_read_lock();
209 if ((head->dev = dev_get_by_index(net, qp->iif)) != NULL) { 212 head->dev = dev_get_by_index_rcu(net, qp->iif);
210 icmp_send(head, ICMP_TIME_EXCEEDED, ICMP_EXC_FRAGTIME, 0); 213 if (!head->dev)
211 dev_put(head->dev); 214 goto out_rcu_unlock;
215
216 /*
217 * Only search router table for the head fragment,
218 * when defraging timeout at PRE_ROUTING HOOK.
219 */
220 if (qp->user == IP_DEFRAG_CONNTRACK_IN && !skb_dst(head)) {
221 const struct iphdr *iph = ip_hdr(head);
222 int err = ip_route_input(head, iph->daddr, iph->saddr,
223 iph->tos, head->dev);
224 if (unlikely(err))
225 goto out_rcu_unlock;
226
227 /*
228 * Only an end host needs to send an ICMP
229 * "Fragment Reassembly Timeout" message, per RFC792.
230 */
231 if (skb_rtable(head)->rt_type != RTN_LOCAL)
232 goto out_rcu_unlock;
233
212 } 234 }
235
236 /* Send an ICMP "Fragment Reassembly Timeout" message. */
237 icmp_send(head, ICMP_TIME_EXCEEDED, ICMP_EXC_FRAGTIME, 0);
238out_rcu_unlock:
239 rcu_read_unlock();
213 } 240 }
214out: 241out:
215 spin_unlock(&qp->q.lock); 242 spin_unlock(&qp->q.lock);
@@ -603,7 +630,6 @@ static int zero;
603 630
604static struct ctl_table ip4_frags_ns_ctl_table[] = { 631static struct ctl_table ip4_frags_ns_ctl_table[] = {
605 { 632 {
606 .ctl_name = NET_IPV4_IPFRAG_HIGH_THRESH,
607 .procname = "ipfrag_high_thresh", 633 .procname = "ipfrag_high_thresh",
608 .data = &init_net.ipv4.frags.high_thresh, 634 .data = &init_net.ipv4.frags.high_thresh,
609 .maxlen = sizeof(int), 635 .maxlen = sizeof(int),
@@ -611,7 +637,6 @@ static struct ctl_table ip4_frags_ns_ctl_table[] = {
611 .proc_handler = proc_dointvec 637 .proc_handler = proc_dointvec
612 }, 638 },
613 { 639 {
614 .ctl_name = NET_IPV4_IPFRAG_LOW_THRESH,
615 .procname = "ipfrag_low_thresh", 640 .procname = "ipfrag_low_thresh",
616 .data = &init_net.ipv4.frags.low_thresh, 641 .data = &init_net.ipv4.frags.low_thresh,
617 .maxlen = sizeof(int), 642 .maxlen = sizeof(int),
@@ -619,26 +644,22 @@ static struct ctl_table ip4_frags_ns_ctl_table[] = {
619 .proc_handler = proc_dointvec 644 .proc_handler = proc_dointvec
620 }, 645 },
621 { 646 {
622 .ctl_name = NET_IPV4_IPFRAG_TIME,
623 .procname = "ipfrag_time", 647 .procname = "ipfrag_time",
624 .data = &init_net.ipv4.frags.timeout, 648 .data = &init_net.ipv4.frags.timeout,
625 .maxlen = sizeof(int), 649 .maxlen = sizeof(int),
626 .mode = 0644, 650 .mode = 0644,
627 .proc_handler = proc_dointvec_jiffies, 651 .proc_handler = proc_dointvec_jiffies,
628 .strategy = sysctl_jiffies
629 }, 652 },
630 { } 653 { }
631}; 654};
632 655
633static struct ctl_table ip4_frags_ctl_table[] = { 656static struct ctl_table ip4_frags_ctl_table[] = {
634 { 657 {
635 .ctl_name = NET_IPV4_IPFRAG_SECRET_INTERVAL,
636 .procname = "ipfrag_secret_interval", 658 .procname = "ipfrag_secret_interval",
637 .data = &ip4_frags.secret_interval, 659 .data = &ip4_frags.secret_interval,
638 .maxlen = sizeof(int), 660 .maxlen = sizeof(int),
639 .mode = 0644, 661 .mode = 0644,
640 .proc_handler = proc_dointvec_jiffies, 662 .proc_handler = proc_dointvec_jiffies,
641 .strategy = sysctl_jiffies
642 }, 663 },
643 { 664 {
644 .procname = "ipfrag_max_dist", 665 .procname = "ipfrag_max_dist",
@@ -651,13 +672,13 @@ static struct ctl_table ip4_frags_ctl_table[] = {
651 { } 672 { }
652}; 673};
653 674
654static int ip4_frags_ns_ctl_register(struct net *net) 675static int __net_init ip4_frags_ns_ctl_register(struct net *net)
655{ 676{
656 struct ctl_table *table; 677 struct ctl_table *table;
657 struct ctl_table_header *hdr; 678 struct ctl_table_header *hdr;
658 679
659 table = ip4_frags_ns_ctl_table; 680 table = ip4_frags_ns_ctl_table;
660 if (net != &init_net) { 681 if (!net_eq(net, &init_net)) {
661 table = kmemdup(table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL); 682 table = kmemdup(table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
662 if (table == NULL) 683 if (table == NULL)
663 goto err_alloc; 684 goto err_alloc;
@@ -675,13 +696,13 @@ static int ip4_frags_ns_ctl_register(struct net *net)
675 return 0; 696 return 0;
676 697
677err_reg: 698err_reg:
678 if (net != &init_net) 699 if (!net_eq(net, &init_net))
679 kfree(table); 700 kfree(table);
680err_alloc: 701err_alloc:
681 return -ENOMEM; 702 return -ENOMEM;
682} 703}
683 704
684static void ip4_frags_ns_ctl_unregister(struct net *net) 705static void __net_exit ip4_frags_ns_ctl_unregister(struct net *net)
685{ 706{
686 struct ctl_table *table; 707 struct ctl_table *table;
687 708
@@ -709,7 +730,7 @@ static inline void ip4_frags_ctl_register(void)
709} 730}
710#endif 731#endif
711 732
712static int ipv4_frags_init_net(struct net *net) 733static int __net_init ipv4_frags_init_net(struct net *net)
713{ 734{
714 /* 735 /*
715 * Fragment cache limits. We will commit 256K at one time. Should we 736 * Fragment cache limits. We will commit 256K at one time. Should we
@@ -731,7 +752,7 @@ static int ipv4_frags_init_net(struct net *net)
731 return ip4_frags_ns_ctl_register(net); 752 return ip4_frags_ns_ctl_register(net);
732} 753}
733 754
734static void ipv4_frags_exit_net(struct net *net) 755static void __net_exit ipv4_frags_exit_net(struct net *net)
735{ 756{
736 ip4_frags_ns_ctl_unregister(net); 757 ip4_frags_ns_ctl_unregister(net);
737 inet_frags_exit_net(&net->ipv4.frags, &ip4_frags); 758 inet_frags_exit_net(&net->ipv4.frags, &ip4_frags);
diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
index 143333852624..fe381d12ecdd 100644
--- a/net/ipv4/ip_gre.c
+++ b/net/ipv4/ip_gre.c
@@ -14,6 +14,7 @@
14#include <linux/module.h> 14#include <linux/module.h>
15#include <linux/types.h> 15#include <linux/types.h>
16#include <linux/kernel.h> 16#include <linux/kernel.h>
17#include <linux/slab.h>
17#include <asm/uaccess.h> 18#include <asm/uaccess.h>
18#include <linux/skbuff.h> 19#include <linux/skbuff.h>
19#include <linux/netdevice.h> 20#include <linux/netdevice.h>
@@ -125,7 +126,7 @@ static int ipgre_tunnel_bind_dev(struct net_device *dev);
125 126
126#define HASH_SIZE 16 127#define HASH_SIZE 16
127 128
128static int ipgre_net_id; 129static int ipgre_net_id __read_mostly;
129struct ipgre_net { 130struct ipgre_net {
130 struct ip_tunnel *tunnels[4][HASH_SIZE]; 131 struct ip_tunnel *tunnels[4][HASH_SIZE];
131 132
@@ -156,8 +157,13 @@ struct ipgre_net {
156#define tunnels_r tunnels[2] 157#define tunnels_r tunnels[2]
157#define tunnels_l tunnels[1] 158#define tunnels_l tunnels[1]
158#define tunnels_wc tunnels[0] 159#define tunnels_wc tunnels[0]
160/*
161 * Locking : hash tables are protected by RCU and a spinlock
162 */
163static DEFINE_SPINLOCK(ipgre_lock);
159 164
160static DEFINE_RWLOCK(ipgre_lock); 165#define for_each_ip_tunnel_rcu(start) \
166 for (t = rcu_dereference(start); t; t = rcu_dereference(t->next))
161 167
162/* Given src, dst and key, find appropriate for input tunnel. */ 168/* Given src, dst and key, find appropriate for input tunnel. */
163 169
@@ -175,7 +181,7 @@ static struct ip_tunnel * ipgre_tunnel_lookup(struct net_device *dev,
175 ARPHRD_ETHER : ARPHRD_IPGRE; 181 ARPHRD_ETHER : ARPHRD_IPGRE;
176 int score, cand_score = 4; 182 int score, cand_score = 4;
177 183
178 for (t = ign->tunnels_r_l[h0^h1]; t; t = t->next) { 184 for_each_ip_tunnel_rcu(ign->tunnels_r_l[h0 ^ h1]) {
179 if (local != t->parms.iph.saddr || 185 if (local != t->parms.iph.saddr ||
180 remote != t->parms.iph.daddr || 186 remote != t->parms.iph.daddr ||
181 key != t->parms.i_key || 187 key != t->parms.i_key ||
@@ -200,7 +206,7 @@ static struct ip_tunnel * ipgre_tunnel_lookup(struct net_device *dev,
200 } 206 }
201 } 207 }
202 208
203 for (t = ign->tunnels_r[h0^h1]; t; t = t->next) { 209 for_each_ip_tunnel_rcu(ign->tunnels_r[h0 ^ h1]) {
204 if (remote != t->parms.iph.daddr || 210 if (remote != t->parms.iph.daddr ||
205 key != t->parms.i_key || 211 key != t->parms.i_key ||
206 !(t->dev->flags & IFF_UP)) 212 !(t->dev->flags & IFF_UP))
@@ -224,7 +230,7 @@ static struct ip_tunnel * ipgre_tunnel_lookup(struct net_device *dev,
224 } 230 }
225 } 231 }
226 232
227 for (t = ign->tunnels_l[h1]; t; t = t->next) { 233 for_each_ip_tunnel_rcu(ign->tunnels_l[h1]) {
228 if ((local != t->parms.iph.saddr && 234 if ((local != t->parms.iph.saddr &&
229 (local != t->parms.iph.daddr || 235 (local != t->parms.iph.daddr ||
230 !ipv4_is_multicast(local))) || 236 !ipv4_is_multicast(local))) ||
@@ -250,7 +256,7 @@ static struct ip_tunnel * ipgre_tunnel_lookup(struct net_device *dev,
250 } 256 }
251 } 257 }
252 258
253 for (t = ign->tunnels_wc[h1]; t; t = t->next) { 259 for_each_ip_tunnel_rcu(ign->tunnels_wc[h1]) {
254 if (t->parms.i_key != key || 260 if (t->parms.i_key != key ||
255 !(t->dev->flags & IFF_UP)) 261 !(t->dev->flags & IFF_UP))
256 continue; 262 continue;
@@ -276,8 +282,9 @@ static struct ip_tunnel * ipgre_tunnel_lookup(struct net_device *dev,
276 if (cand != NULL) 282 if (cand != NULL)
277 return cand; 283 return cand;
278 284
279 if (ign->fb_tunnel_dev->flags & IFF_UP) 285 dev = ign->fb_tunnel_dev;
280 return netdev_priv(ign->fb_tunnel_dev); 286 if (dev->flags & IFF_UP)
287 return netdev_priv(dev);
281 288
282 return NULL; 289 return NULL;
283} 290}
@@ -311,10 +318,10 @@ static void ipgre_tunnel_link(struct ipgre_net *ign, struct ip_tunnel *t)
311{ 318{
312 struct ip_tunnel **tp = ipgre_bucket(ign, t); 319 struct ip_tunnel **tp = ipgre_bucket(ign, t);
313 320
321 spin_lock_bh(&ipgre_lock);
314 t->next = *tp; 322 t->next = *tp;
315 write_lock_bh(&ipgre_lock); 323 rcu_assign_pointer(*tp, t);
316 *tp = t; 324 spin_unlock_bh(&ipgre_lock);
317 write_unlock_bh(&ipgre_lock);
318} 325}
319 326
320static void ipgre_tunnel_unlink(struct ipgre_net *ign, struct ip_tunnel *t) 327static void ipgre_tunnel_unlink(struct ipgre_net *ign, struct ip_tunnel *t)
@@ -323,9 +330,9 @@ static void ipgre_tunnel_unlink(struct ipgre_net *ign, struct ip_tunnel *t)
323 330
324 for (tp = ipgre_bucket(ign, t); *tp; tp = &(*tp)->next) { 331 for (tp = ipgre_bucket(ign, t); *tp; tp = &(*tp)->next) {
325 if (t == *tp) { 332 if (t == *tp) {
326 write_lock_bh(&ipgre_lock); 333 spin_lock_bh(&ipgre_lock);
327 *tp = t->next; 334 *tp = t->next;
328 write_unlock_bh(&ipgre_lock); 335 spin_unlock_bh(&ipgre_lock);
329 break; 336 break;
330 } 337 }
331 } 338 }
@@ -476,7 +483,7 @@ static void ipgre_err(struct sk_buff *skb, u32 info)
476 break; 483 break;
477 } 484 }
478 485
479 read_lock(&ipgre_lock); 486 rcu_read_lock();
480 t = ipgre_tunnel_lookup(skb->dev, iph->daddr, iph->saddr, 487 t = ipgre_tunnel_lookup(skb->dev, iph->daddr, iph->saddr,
481 flags & GRE_KEY ? 488 flags & GRE_KEY ?
482 *(((__be32 *)p) + (grehlen / 4) - 1) : 0, 489 *(((__be32 *)p) + (grehlen / 4) - 1) : 0,
@@ -494,7 +501,7 @@ static void ipgre_err(struct sk_buff *skb, u32 info)
494 t->err_count = 1; 501 t->err_count = 1;
495 t->err_time = jiffies; 502 t->err_time = jiffies;
496out: 503out:
497 read_unlock(&ipgre_lock); 504 rcu_read_unlock();
498 return; 505 return;
499} 506}
500 507
@@ -573,7 +580,7 @@ static int ipgre_rcv(struct sk_buff *skb)
573 580
574 gre_proto = *(__be16 *)(h + 2); 581 gre_proto = *(__be16 *)(h + 2);
575 582
576 read_lock(&ipgre_lock); 583 rcu_read_lock();
577 if ((tunnel = ipgre_tunnel_lookup(skb->dev, 584 if ((tunnel = ipgre_tunnel_lookup(skb->dev,
578 iph->saddr, iph->daddr, key, 585 iph->saddr, iph->daddr, key,
579 gre_proto))) { 586 gre_proto))) {
@@ -647,13 +654,13 @@ static int ipgre_rcv(struct sk_buff *skb)
647 ipgre_ecn_decapsulate(iph, skb); 654 ipgre_ecn_decapsulate(iph, skb);
648 655
649 netif_rx(skb); 656 netif_rx(skb);
650 read_unlock(&ipgre_lock); 657 rcu_read_unlock();
651 return(0); 658 return(0);
652 } 659 }
653 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0); 660 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
654 661
655drop: 662drop:
656 read_unlock(&ipgre_lock); 663 rcu_read_unlock();
657drop_nolock: 664drop_nolock:
658 kfree_skb(skb); 665 kfree_skb(skb);
659 return(0); 666 return(0);
@@ -662,7 +669,8 @@ drop_nolock:
662static netdev_tx_t ipgre_tunnel_xmit(struct sk_buff *skb, struct net_device *dev) 669static netdev_tx_t ipgre_tunnel_xmit(struct sk_buff *skb, struct net_device *dev)
663{ 670{
664 struct ip_tunnel *tunnel = netdev_priv(dev); 671 struct ip_tunnel *tunnel = netdev_priv(dev);
665 struct net_device_stats *stats = &tunnel->dev->stats; 672 struct net_device_stats *stats = &dev->stats;
673 struct netdev_queue *txq = netdev_get_tx_queue(dev, 0);
666 struct iphdr *old_iph = ip_hdr(skb); 674 struct iphdr *old_iph = ip_hdr(skb);
667 struct iphdr *tiph; 675 struct iphdr *tiph;
668 u8 tos; 676 u8 tos;
@@ -786,7 +794,7 @@ static netdev_tx_t ipgre_tunnel_xmit(struct sk_buff *skb, struct net_device *dev
786 } 794 }
787 795
788 if (mtu >= IPV6_MIN_MTU && mtu < skb->len - tunnel->hlen + gre_hlen) { 796 if (mtu >= IPV6_MIN_MTU && mtu < skb->len - tunnel->hlen + gre_hlen) {
789 icmpv6_send(skb, ICMPV6_PKT_TOOBIG, 0, mtu, dev); 797 icmpv6_send(skb, ICMPV6_PKT_TOOBIG, 0, mtu);
790 ip_rt_put(rt); 798 ip_rt_put(rt);
791 goto tx_error; 799 goto tx_error;
792 } 800 }
@@ -803,14 +811,16 @@ static netdev_tx_t ipgre_tunnel_xmit(struct sk_buff *skb, struct net_device *dev
803 tunnel->err_count = 0; 811 tunnel->err_count = 0;
804 } 812 }
805 813
806 max_headroom = LL_RESERVED_SPACE(tdev) + gre_hlen; 814 max_headroom = LL_RESERVED_SPACE(tdev) + gre_hlen + rt->u.dst.header_len;
807 815
808 if (skb_headroom(skb) < max_headroom || skb_shared(skb)|| 816 if (skb_headroom(skb) < max_headroom || skb_shared(skb)||
809 (skb_cloned(skb) && !skb_clone_writable(skb, 0))) { 817 (skb_cloned(skb) && !skb_clone_writable(skb, 0))) {
810 struct sk_buff *new_skb = skb_realloc_headroom(skb, max_headroom); 818 struct sk_buff *new_skb = skb_realloc_headroom(skb, max_headroom);
819 if (max_headroom > dev->needed_headroom)
820 dev->needed_headroom = max_headroom;
811 if (!new_skb) { 821 if (!new_skb) {
812 ip_rt_put(rt); 822 ip_rt_put(rt);
813 stats->tx_dropped++; 823 txq->tx_dropped++;
814 dev_kfree_skb(skb); 824 dev_kfree_skb(skb);
815 return NETDEV_TX_OK; 825 return NETDEV_TX_OK;
816 } 826 }
@@ -1137,12 +1147,9 @@ static int ipgre_header(struct sk_buff *skb, struct net_device *dev,
1137 1147
1138 if (saddr) 1148 if (saddr)
1139 memcpy(&iph->saddr, saddr, 4); 1149 memcpy(&iph->saddr, saddr, 4);
1140 1150 if (daddr)
1141 if (daddr) {
1142 memcpy(&iph->daddr, daddr, 4); 1151 memcpy(&iph->daddr, daddr, 4);
1143 return t->hlen; 1152 if (iph->daddr)
1144 }
1145 if (iph->daddr && !ipv4_is_multicast(iph->daddr))
1146 return t->hlen; 1153 return t->hlen;
1147 1154
1148 return -t->hlen; 1155 return -t->hlen;
@@ -1283,33 +1290,27 @@ static const struct net_protocol ipgre_protocol = {
1283 .netns_ok = 1, 1290 .netns_ok = 1,
1284}; 1291};
1285 1292
1286static void ipgre_destroy_tunnels(struct ipgre_net *ign) 1293static void ipgre_destroy_tunnels(struct ipgre_net *ign, struct list_head *head)
1287{ 1294{
1288 int prio; 1295 int prio;
1289 1296
1290 for (prio = 0; prio < 4; prio++) { 1297 for (prio = 0; prio < 4; prio++) {
1291 int h; 1298 int h;
1292 for (h = 0; h < HASH_SIZE; h++) { 1299 for (h = 0; h < HASH_SIZE; h++) {
1293 struct ip_tunnel *t; 1300 struct ip_tunnel *t = ign->tunnels[prio][h];
1294 while ((t = ign->tunnels[prio][h]) != NULL) 1301
1295 unregister_netdevice(t->dev); 1302 while (t != NULL) {
1303 unregister_netdevice_queue(t->dev, head);
1304 t = t->next;
1305 }
1296 } 1306 }
1297 } 1307 }
1298} 1308}
1299 1309
1300static int ipgre_init_net(struct net *net) 1310static int __net_init ipgre_init_net(struct net *net)
1301{ 1311{
1312 struct ipgre_net *ign = net_generic(net, ipgre_net_id);
1302 int err; 1313 int err;
1303 struct ipgre_net *ign;
1304
1305 err = -ENOMEM;
1306 ign = kzalloc(sizeof(struct ipgre_net), GFP_KERNEL);
1307 if (ign == NULL)
1308 goto err_alloc;
1309
1310 err = net_assign_generic(net, ipgre_net_id, ign);
1311 if (err < 0)
1312 goto err_assign;
1313 1314
1314 ign->fb_tunnel_dev = alloc_netdev(sizeof(struct ip_tunnel), "gre0", 1315 ign->fb_tunnel_dev = alloc_netdev(sizeof(struct ip_tunnel), "gre0",
1315 ipgre_tunnel_setup); 1316 ipgre_tunnel_setup);
@@ -1330,27 +1331,26 @@ static int ipgre_init_net(struct net *net)
1330err_reg_dev: 1331err_reg_dev:
1331 free_netdev(ign->fb_tunnel_dev); 1332 free_netdev(ign->fb_tunnel_dev);
1332err_alloc_dev: 1333err_alloc_dev:
1333 /* nothing */
1334err_assign:
1335 kfree(ign);
1336err_alloc:
1337 return err; 1334 return err;
1338} 1335}
1339 1336
1340static void ipgre_exit_net(struct net *net) 1337static void __net_exit ipgre_exit_net(struct net *net)
1341{ 1338{
1342 struct ipgre_net *ign; 1339 struct ipgre_net *ign;
1340 LIST_HEAD(list);
1343 1341
1344 ign = net_generic(net, ipgre_net_id); 1342 ign = net_generic(net, ipgre_net_id);
1345 rtnl_lock(); 1343 rtnl_lock();
1346 ipgre_destroy_tunnels(ign); 1344 ipgre_destroy_tunnels(ign, &list);
1345 unregister_netdevice_many(&list);
1347 rtnl_unlock(); 1346 rtnl_unlock();
1348 kfree(ign);
1349} 1347}
1350 1348
1351static struct pernet_operations ipgre_net_ops = { 1349static struct pernet_operations ipgre_net_ops = {
1352 .init = ipgre_init_net, 1350 .init = ipgre_init_net,
1353 .exit = ipgre_exit_net, 1351 .exit = ipgre_exit_net,
1352 .id = &ipgre_net_id,
1353 .size = sizeof(struct ipgre_net),
1354}; 1354};
1355 1355
1356static int ipgre_tunnel_validate(struct nlattr *tb[], struct nlattr *data[]) 1356static int ipgre_tunnel_validate(struct nlattr *tb[], struct nlattr *data[])
@@ -1471,7 +1471,7 @@ static void ipgre_tap_setup(struct net_device *dev)
1471 dev->features |= NETIF_F_NETNS_LOCAL; 1471 dev->features |= NETIF_F_NETNS_LOCAL;
1472} 1472}
1473 1473
1474static int ipgre_newlink(struct net_device *dev, struct nlattr *tb[], 1474static int ipgre_newlink(struct net *src_net, struct net_device *dev, struct nlattr *tb[],
1475 struct nlattr *data[]) 1475 struct nlattr *data[])
1476{ 1476{
1477 struct ip_tunnel *nt; 1477 struct ip_tunnel *nt;
@@ -1665,15 +1665,16 @@ static int __init ipgre_init(void)
1665 1665
1666 printk(KERN_INFO "GRE over IPv4 tunneling driver\n"); 1666 printk(KERN_INFO "GRE over IPv4 tunneling driver\n");
1667 1667
1668 if (inet_add_protocol(&ipgre_protocol, IPPROTO_GRE) < 0) { 1668 err = register_pernet_device(&ipgre_net_ops);
1669 if (err < 0)
1670 return err;
1671
1672 err = inet_add_protocol(&ipgre_protocol, IPPROTO_GRE);
1673 if (err < 0) {
1669 printk(KERN_INFO "ipgre init: can't add protocol\n"); 1674 printk(KERN_INFO "ipgre init: can't add protocol\n");
1670 return -EAGAIN; 1675 goto add_proto_failed;
1671 } 1676 }
1672 1677
1673 err = register_pernet_gen_device(&ipgre_net_id, &ipgre_net_ops);
1674 if (err < 0)
1675 goto gen_device_failed;
1676
1677 err = rtnl_link_register(&ipgre_link_ops); 1678 err = rtnl_link_register(&ipgre_link_ops);
1678 if (err < 0) 1679 if (err < 0)
1679 goto rtnl_link_failed; 1680 goto rtnl_link_failed;
@@ -1688,9 +1689,9 @@ out:
1688tap_ops_failed: 1689tap_ops_failed:
1689 rtnl_link_unregister(&ipgre_link_ops); 1690 rtnl_link_unregister(&ipgre_link_ops);
1690rtnl_link_failed: 1691rtnl_link_failed:
1691 unregister_pernet_gen_device(ipgre_net_id, &ipgre_net_ops);
1692gen_device_failed:
1693 inet_del_protocol(&ipgre_protocol, IPPROTO_GRE); 1692 inet_del_protocol(&ipgre_protocol, IPPROTO_GRE);
1693add_proto_failed:
1694 unregister_pernet_device(&ipgre_net_ops);
1694 goto out; 1695 goto out;
1695} 1696}
1696 1697
@@ -1698,9 +1699,9 @@ static void __exit ipgre_fini(void)
1698{ 1699{
1699 rtnl_link_unregister(&ipgre_tap_ops); 1700 rtnl_link_unregister(&ipgre_tap_ops);
1700 rtnl_link_unregister(&ipgre_link_ops); 1701 rtnl_link_unregister(&ipgre_link_ops);
1701 unregister_pernet_gen_device(ipgre_net_id, &ipgre_net_ops);
1702 if (inet_del_protocol(&ipgre_protocol, IPPROTO_GRE) < 0) 1702 if (inet_del_protocol(&ipgre_protocol, IPPROTO_GRE) < 0)
1703 printk(KERN_INFO "ipgre close: can't remove protocol\n"); 1703 printk(KERN_INFO "ipgre close: can't remove protocol\n");
1704 unregister_pernet_device(&ipgre_net_ops);
1704} 1705}
1705 1706
1706module_init(ipgre_init); 1707module_init(ipgre_init);
diff --git a/net/ipv4/ip_input.c b/net/ipv4/ip_input.c
index 6c98b43badf4..f8ab7a380d4a 100644
--- a/net/ipv4/ip_input.c
+++ b/net/ipv4/ip_input.c
@@ -119,6 +119,7 @@
119#include <linux/kernel.h> 119#include <linux/kernel.h>
120#include <linux/string.h> 120#include <linux/string.h>
121#include <linux/errno.h> 121#include <linux/errno.h>
122#include <linux/slab.h>
122 123
123#include <linux/net.h> 124#include <linux/net.h>
124#include <linux/socket.h> 125#include <linux/socket.h>
@@ -161,10 +162,10 @@ int ip_call_ra_chain(struct sk_buff *skb)
161 /* If socket is bound to an interface, only report 162 /* If socket is bound to an interface, only report
162 * the packet if it came from that interface. 163 * the packet if it came from that interface.
163 */ 164 */
164 if (sk && inet_sk(sk)->num == protocol && 165 if (sk && inet_sk(sk)->inet_num == protocol &&
165 (!sk->sk_bound_dev_if || 166 (!sk->sk_bound_dev_if ||
166 sk->sk_bound_dev_if == dev->ifindex) && 167 sk->sk_bound_dev_if == dev->ifindex) &&
167 sock_net(sk) == dev_net(dev)) { 168 net_eq(sock_net(sk), dev_net(dev))) {
168 if (ip_hdr(skb)->frag_off & htons(IP_MF | IP_OFFSET)) { 169 if (ip_hdr(skb)->frag_off & htons(IP_MF | IP_OFFSET)) {
169 if (ip_defrag(skb, IP_DEFRAG_CALL_RA_CHAIN)) { 170 if (ip_defrag(skb, IP_DEFRAG_CALL_RA_CHAIN)) {
170 read_unlock(&ip_ra_lock); 171 read_unlock(&ip_ra_lock);
diff --git a/net/ipv4/ip_options.c b/net/ipv4/ip_options.c
index 94bf105ef3c9..4c09a31fd140 100644
--- a/net/ipv4/ip_options.c
+++ b/net/ipv4/ip_options.c
@@ -11,6 +11,7 @@
11 11
12#include <linux/capability.h> 12#include <linux/capability.h>
13#include <linux/module.h> 13#include <linux/module.h>
14#include <linux/slab.h>
14#include <linux/types.h> 15#include <linux/types.h>
15#include <asm/uaccess.h> 16#include <asm/uaccess.h>
16#include <linux/skbuff.h> 17#include <linux/skbuff.h>
diff --git a/net/ipv4/ip_output.c b/net/ipv4/ip_output.c
index f9895180f481..d1bcc9f21d4f 100644
--- a/net/ipv4/ip_output.c
+++ b/net/ipv4/ip_output.c
@@ -51,6 +51,7 @@
51#include <linux/string.h> 51#include <linux/string.h>
52#include <linux/errno.h> 52#include <linux/errno.h>
53#include <linux/highmem.h> 53#include <linux/highmem.h>
54#include <linux/slab.h>
54 55
55#include <linux/socket.h> 56#include <linux/socket.h>
56#include <linux/sockios.h> 57#include <linux/sockios.h>
@@ -119,7 +120,7 @@ static int ip_dev_loopback_xmit(struct sk_buff *newskb)
119 newskb->pkt_type = PACKET_LOOPBACK; 120 newskb->pkt_type = PACKET_LOOPBACK;
120 newskb->ip_summed = CHECKSUM_UNNECESSARY; 121 newskb->ip_summed = CHECKSUM_UNNECESSARY;
121 WARN_ON(!skb_dst(newskb)); 122 WARN_ON(!skb_dst(newskb));
122 netif_rx(newskb); 123 netif_rx_ni(newskb);
123 return 0; 124 return 0;
124} 125}
125 126
@@ -254,7 +255,7 @@ int ip_mc_output(struct sk_buff *skb)
254 */ 255 */
255 256
256 if (rt->rt_flags&RTCF_MULTICAST) { 257 if (rt->rt_flags&RTCF_MULTICAST) {
257 if ((!sk || inet_sk(sk)->mc_loop) 258 if (sk_mc_loop(sk)
258#ifdef CONFIG_IP_MROUTE 259#ifdef CONFIG_IP_MROUTE
259 /* Small optimization: do not loopback not local frames, 260 /* Small optimization: do not loopback not local frames,
260 which returned after forwarding; they will be dropped 261 which returned after forwarding; they will be dropped
@@ -264,9 +265,11 @@ int ip_mc_output(struct sk_buff *skb)
264 265
265 This check is duplicated in ip_mr_input at the moment. 266 This check is duplicated in ip_mr_input at the moment.
266 */ 267 */
267 && ((rt->rt_flags&RTCF_LOCAL) || !(IPCB(skb)->flags&IPSKB_FORWARDED)) 268 &&
269 ((rt->rt_flags & RTCF_LOCAL) ||
270 !(IPCB(skb)->flags & IPSKB_FORWARDED))
268#endif 271#endif
269 ) { 272 ) {
270 struct sk_buff *newskb = skb_clone(skb, GFP_ATOMIC); 273 struct sk_buff *newskb = skb_clone(skb, GFP_ATOMIC);
271 if (newskb) 274 if (newskb)
272 NF_HOOK(PF_INET, NF_INET_POST_ROUTING, newskb, 275 NF_HOOK(PF_INET, NF_INET_POST_ROUTING, newskb,
@@ -329,7 +332,7 @@ int ip_queue_xmit(struct sk_buff *skb, int ipfragok)
329 __be32 daddr; 332 __be32 daddr;
330 333
331 /* Use correct destination address if we have options. */ 334 /* Use correct destination address if we have options. */
332 daddr = inet->daddr; 335 daddr = inet->inet_daddr;
333 if(opt && opt->srr) 336 if(opt && opt->srr)
334 daddr = opt->faddr; 337 daddr = opt->faddr;
335 338
@@ -338,13 +341,13 @@ int ip_queue_xmit(struct sk_buff *skb, int ipfragok)
338 .mark = sk->sk_mark, 341 .mark = sk->sk_mark,
339 .nl_u = { .ip4_u = 342 .nl_u = { .ip4_u =
340 { .daddr = daddr, 343 { .daddr = daddr,
341 .saddr = inet->saddr, 344 .saddr = inet->inet_saddr,
342 .tos = RT_CONN_FLAGS(sk) } }, 345 .tos = RT_CONN_FLAGS(sk) } },
343 .proto = sk->sk_protocol, 346 .proto = sk->sk_protocol,
344 .flags = inet_sk_flowi_flags(sk), 347 .flags = inet_sk_flowi_flags(sk),
345 .uli_u = { .ports = 348 .uli_u = { .ports =
346 { .sport = inet->sport, 349 { .sport = inet->inet_sport,
347 .dport = inet->dport } } }; 350 .dport = inet->inet_dport } } };
348 351
349 /* If this fails, retransmit mechanism of transport layer will 352 /* If this fails, retransmit mechanism of transport layer will
350 * keep trying until route appears or the connection times 353 * keep trying until route appears or the connection times
@@ -379,7 +382,7 @@ packet_routed:
379 382
380 if (opt && opt->optlen) { 383 if (opt && opt->optlen) {
381 iph->ihl += opt->optlen >> 2; 384 iph->ihl += opt->optlen >> 2;
382 ip_options_build(skb, opt, inet->daddr, rt, 0); 385 ip_options_build(skb, opt, inet->inet_daddr, rt, 0);
383 } 386 }
384 387
385 ip_select_ident_more(iph, &rt->u.dst, sk, 388 ip_select_ident_more(iph, &rt->u.dst, sk,
@@ -501,8 +504,8 @@ int ip_fragment(struct sk_buff *skb, int (*output)(struct sk_buff *))
501 if (skb->sk) { 504 if (skb->sk) {
502 frag->sk = skb->sk; 505 frag->sk = skb->sk;
503 frag->destructor = sock_wfree; 506 frag->destructor = sock_wfree;
504 truesizes += frag->truesize;
505 } 507 }
508 truesizes += frag->truesize;
506 } 509 }
507 510
508 /* Everything is OK. Generate! */ 511 /* Everything is OK. Generate! */
@@ -846,7 +849,8 @@ int ip_append_data(struct sock *sk,
846 maxfraglen = ((mtu - fragheaderlen) & ~7) + fragheaderlen; 849 maxfraglen = ((mtu - fragheaderlen) & ~7) + fragheaderlen;
847 850
848 if (inet->cork.length + length > 0xFFFF - fragheaderlen) { 851 if (inet->cork.length + length > 0xFFFF - fragheaderlen) {
849 ip_local_error(sk, EMSGSIZE, rt->rt_dst, inet->dport, mtu-exthdrlen); 852 ip_local_error(sk, EMSGSIZE, rt->rt_dst, inet->inet_dport,
853 mtu-exthdrlen);
850 return -EMSGSIZE; 854 return -EMSGSIZE;
851 } 855 }
852 856
@@ -1100,7 +1104,7 @@ ssize_t ip_append_page(struct sock *sk, struct page *page,
1100 maxfraglen = ((mtu - fragheaderlen) & ~7) + fragheaderlen; 1104 maxfraglen = ((mtu - fragheaderlen) & ~7) + fragheaderlen;
1101 1105
1102 if (inet->cork.length + size > 0xFFFF - fragheaderlen) { 1106 if (inet->cork.length + size > 0xFFFF - fragheaderlen) {
1103 ip_local_error(sk, EMSGSIZE, rt->rt_dst, inet->dport, mtu); 1107 ip_local_error(sk, EMSGSIZE, rt->rt_dst, inet->inet_dport, mtu);
1104 return -EMSGSIZE; 1108 return -EMSGSIZE;
1105 } 1109 }
1106 1110
diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
index e982b5c1ee17..1e64dabbd232 100644
--- a/net/ipv4/ip_sockglue.c
+++ b/net/ipv4/ip_sockglue.c
@@ -23,6 +23,7 @@
23#include <linux/icmp.h> 23#include <linux/icmp.h>
24#include <linux/inetdevice.h> 24#include <linux/inetdevice.h>
25#include <linux/netdevice.h> 25#include <linux/netdevice.h>
26#include <linux/slab.h>
26#include <net/sock.h> 27#include <net/sock.h>
27#include <net/ip.h> 28#include <net/ip.h>
28#include <net/icmp.h> 29#include <net/icmp.h>
@@ -245,7 +246,7 @@ int ip_ra_control(struct sock *sk, unsigned char on,
245{ 246{
246 struct ip_ra_chain *ra, *new_ra, **rap; 247 struct ip_ra_chain *ra, *new_ra, **rap;
247 248
248 if (sk->sk_type != SOCK_RAW || inet_sk(sk)->num == IPPROTO_RAW) 249 if (sk->sk_type != SOCK_RAW || inet_sk(sk)->inet_num == IPPROTO_RAW)
249 return -EINVAL; 250 return -EINVAL;
250 251
251 new_ra = on ? kmalloc(sizeof(*new_ra), GFP_KERNEL) : NULL; 252 new_ra = on ? kmalloc(sizeof(*new_ra), GFP_KERNEL) : NULL;
@@ -451,7 +452,8 @@ static int do_ip_setsockopt(struct sock *sk, int level,
451 (1<<IP_TTL) | (1<<IP_HDRINCL) | 452 (1<<IP_TTL) | (1<<IP_HDRINCL) |
452 (1<<IP_MTU_DISCOVER) | (1<<IP_RECVERR) | 453 (1<<IP_MTU_DISCOVER) | (1<<IP_RECVERR) |
453 (1<<IP_ROUTER_ALERT) | (1<<IP_FREEBIND) | 454 (1<<IP_ROUTER_ALERT) | (1<<IP_FREEBIND) |
454 (1<<IP_PASSSEC) | (1<<IP_TRANSPARENT))) || 455 (1<<IP_PASSSEC) | (1<<IP_TRANSPARENT) |
456 (1<<IP_MINTTL))) ||
455 optname == IP_MULTICAST_TTL || 457 optname == IP_MULTICAST_TTL ||
456 optname == IP_MULTICAST_ALL || 458 optname == IP_MULTICAST_ALL ||
457 optname == IP_MULTICAST_LOOP || 459 optname == IP_MULTICAST_LOOP ||
@@ -480,7 +482,7 @@ static int do_ip_setsockopt(struct sock *sk, int level,
480 case IP_OPTIONS: 482 case IP_OPTIONS:
481 { 483 {
482 struct ip_options *opt = NULL; 484 struct ip_options *opt = NULL;
483 if (optlen > 40 || optlen < 0) 485 if (optlen > 40)
484 goto e_inval; 486 goto e_inval;
485 err = ip_options_get_from_user(sock_net(sk), &opt, 487 err = ip_options_get_from_user(sock_net(sk), &opt,
486 optval, optlen); 488 optval, optlen);
@@ -492,7 +494,7 @@ static int do_ip_setsockopt(struct sock *sk, int level,
492 if (sk->sk_family == PF_INET || 494 if (sk->sk_family == PF_INET ||
493 (!((1 << sk->sk_state) & 495 (!((1 << sk->sk_state) &
494 (TCPF_LISTEN | TCPF_CLOSE)) && 496 (TCPF_LISTEN | TCPF_CLOSE)) &&
495 inet->daddr != LOOPBACK4_IPV6)) { 497 inet->inet_daddr != LOOPBACK4_IPV6)) {
496#endif 498#endif
497 if (inet->opt) 499 if (inet->opt)
498 icsk->icsk_ext_hdr_len -= inet->opt->optlen; 500 icsk->icsk_ext_hdr_len -= inet->opt->optlen;
@@ -575,7 +577,7 @@ static int do_ip_setsockopt(struct sock *sk, int level,
575 inet->hdrincl = val ? 1 : 0; 577 inet->hdrincl = val ? 1 : 0;
576 break; 578 break;
577 case IP_MTU_DISCOVER: 579 case IP_MTU_DISCOVER:
578 if (val < 0 || val > 3) 580 if (val < IP_PMTUDISC_DONT || val > IP_PMTUDISC_PROBE)
579 goto e_inval; 581 goto e_inval;
580 inet->pmtudisc = val; 582 inet->pmtudisc = val;
581 break; 583 break;
@@ -936,6 +938,14 @@ mc_msf_out:
936 inet->transparent = !!val; 938 inet->transparent = !!val;
937 break; 939 break;
938 940
941 case IP_MINTTL:
942 if (optlen < 1)
943 goto e_inval;
944 if (val < 0 || val > 255)
945 goto e_inval;
946 inet->min_ttl = val;
947 break;
948
939 default: 949 default:
940 err = -ENOPROTOOPT; 950 err = -ENOPROTOOPT;
941 break; 951 break;
@@ -1180,8 +1190,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
1180 if (inet->cmsg_flags & IP_CMSG_PKTINFO) { 1190 if (inet->cmsg_flags & IP_CMSG_PKTINFO) {
1181 struct in_pktinfo info; 1191 struct in_pktinfo info;
1182 1192
1183 info.ipi_addr.s_addr = inet->rcv_saddr; 1193 info.ipi_addr.s_addr = inet->inet_rcv_saddr;
1184 info.ipi_spec_dst.s_addr = inet->rcv_saddr; 1194 info.ipi_spec_dst.s_addr = inet->inet_rcv_saddr;
1185 info.ipi_ifindex = inet->mc_index; 1195 info.ipi_ifindex = inet->mc_index;
1186 put_cmsg(&msg, SOL_IP, IP_PKTINFO, sizeof(info), &info); 1196 put_cmsg(&msg, SOL_IP, IP_PKTINFO, sizeof(info), &info);
1187 } 1197 }
@@ -1198,6 +1208,9 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
1198 case IP_TRANSPARENT: 1208 case IP_TRANSPARENT:
1199 val = inet->transparent; 1209 val = inet->transparent;
1200 break; 1210 break;
1211 case IP_MINTTL:
1212 val = inet->min_ttl;
1213 break;
1201 default: 1214 default:
1202 release_sock(sk); 1215 release_sock(sk);
1203 return -ENOPROTOOPT; 1216 return -ENOPROTOOPT;
diff --git a/net/ipv4/ipcomp.c b/net/ipv4/ipcomp.c
index 38fbf04150ae..629067571f02 100644
--- a/net/ipv4/ipcomp.c
+++ b/net/ipv4/ipcomp.c
@@ -25,6 +25,7 @@
25 25
26static void ipcomp4_err(struct sk_buff *skb, u32 info) 26static void ipcomp4_err(struct sk_buff *skb, u32 info)
27{ 27{
28 struct net *net = dev_net(skb->dev);
28 __be32 spi; 29 __be32 spi;
29 struct iphdr *iph = (struct iphdr *)skb->data; 30 struct iphdr *iph = (struct iphdr *)skb->data;
30 struct ip_comp_hdr *ipch = (struct ip_comp_hdr *)(skb->data+(iph->ihl<<2)); 31 struct ip_comp_hdr *ipch = (struct ip_comp_hdr *)(skb->data+(iph->ihl<<2));
@@ -35,7 +36,7 @@ static void ipcomp4_err(struct sk_buff *skb, u32 info)
35 return; 36 return;
36 37
37 spi = htonl(ntohs(ipch->cpi)); 38 spi = htonl(ntohs(ipch->cpi));
38 x = xfrm_state_lookup(&init_net, (xfrm_address_t *)&iph->daddr, 39 x = xfrm_state_lookup(net, skb->mark, (xfrm_address_t *)&iph->daddr,
39 spi, IPPROTO_COMP, AF_INET); 40 spi, IPPROTO_COMP, AF_INET);
40 if (!x) 41 if (!x)
41 return; 42 return;
@@ -47,9 +48,10 @@ static void ipcomp4_err(struct sk_buff *skb, u32 info)
47/* We always hold one tunnel user reference to indicate a tunnel */ 48/* We always hold one tunnel user reference to indicate a tunnel */
48static struct xfrm_state *ipcomp_tunnel_create(struct xfrm_state *x) 49static struct xfrm_state *ipcomp_tunnel_create(struct xfrm_state *x)
49{ 50{
51 struct net *net = xs_net(x);
50 struct xfrm_state *t; 52 struct xfrm_state *t;
51 53
52 t = xfrm_state_alloc(&init_net); 54 t = xfrm_state_alloc(net);
53 if (t == NULL) 55 if (t == NULL)
54 goto out; 56 goto out;
55 57
@@ -61,6 +63,7 @@ static struct xfrm_state *ipcomp_tunnel_create(struct xfrm_state *x)
61 t->props.mode = x->props.mode; 63 t->props.mode = x->props.mode;
62 t->props.saddr.a4 = x->props.saddr.a4; 64 t->props.saddr.a4 = x->props.saddr.a4;
63 t->props.flags = x->props.flags; 65 t->props.flags = x->props.flags;
66 memcpy(&t->mark, &x->mark, sizeof(t->mark));
64 67
65 if (xfrm_init_state(t)) 68 if (xfrm_init_state(t))
66 goto error; 69 goto error;
@@ -82,10 +85,12 @@ error:
82 */ 85 */
83static int ipcomp_tunnel_attach(struct xfrm_state *x) 86static int ipcomp_tunnel_attach(struct xfrm_state *x)
84{ 87{
88 struct net *net = xs_net(x);
85 int err = 0; 89 int err = 0;
86 struct xfrm_state *t; 90 struct xfrm_state *t;
91 u32 mark = x->mark.v & x->mark.m;
87 92
88 t = xfrm_state_lookup(&init_net, (xfrm_address_t *)&x->id.daddr.a4, 93 t = xfrm_state_lookup(net, mark, (xfrm_address_t *)&x->id.daddr.a4,
89 x->props.saddr.a4, IPPROTO_IPIP, AF_INET); 94 x->props.saddr.a4, IPPROTO_IPIP, AF_INET);
90 if (!t) { 95 if (!t) {
91 t = ipcomp_tunnel_create(x); 96 t = ipcomp_tunnel_create(x);
@@ -124,16 +129,12 @@ static int ipcomp4_init_state(struct xfrm_state *x)
124 if (x->props.mode == XFRM_MODE_TUNNEL) { 129 if (x->props.mode == XFRM_MODE_TUNNEL) {
125 err = ipcomp_tunnel_attach(x); 130 err = ipcomp_tunnel_attach(x);
126 if (err) 131 if (err)
127 goto error_tunnel; 132 goto out;
128 } 133 }
129 134
130 err = 0; 135 err = 0;
131out: 136out:
132 return err; 137 return err;
133
134error_tunnel:
135 ipcomp_destroy(x);
136 goto out;
137} 138}
138 139
139static const struct xfrm_type ipcomp_type = { 140static const struct xfrm_type ipcomp_type = {
diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
index f8d04c256454..067ce9e043dc 100644
--- a/net/ipv4/ipconfig.c
+++ b/net/ipv4/ipconfig.c
@@ -53,6 +53,7 @@
53#include <linux/root_dev.h> 53#include <linux/root_dev.h>
54#include <linux/delay.h> 54#include <linux/delay.h>
55#include <linux/nfs_fs.h> 55#include <linux/nfs_fs.h>
56#include <linux/slab.h>
56#include <net/net_namespace.h> 57#include <net/net_namespace.h>
57#include <net/arp.h> 58#include <net/arp.h>
58#include <net/ip.h> 59#include <net/ip.h>
@@ -187,6 +188,16 @@ struct ic_device {
187static struct ic_device *ic_first_dev __initdata = NULL;/* List of open device */ 188static struct ic_device *ic_first_dev __initdata = NULL;/* List of open device */
188static struct net_device *ic_dev __initdata = NULL; /* Selected device */ 189static struct net_device *ic_dev __initdata = NULL; /* Selected device */
189 190
191static bool __init ic_device_match(struct net_device *dev)
192{
193 if (user_dev_name[0] ? !strcmp(dev->name, user_dev_name) :
194 (!(dev->flags & IFF_LOOPBACK) &&
195 (dev->flags & (IFF_POINTOPOINT|IFF_BROADCAST)) &&
196 strncmp(dev->name, "dummy", 5)))
197 return true;
198 return false;
199}
200
190static int __init ic_open_devs(void) 201static int __init ic_open_devs(void)
191{ 202{
192 struct ic_device *d, **last; 203 struct ic_device *d, **last;
@@ -207,10 +218,7 @@ static int __init ic_open_devs(void)
207 for_each_netdev(&init_net, dev) { 218 for_each_netdev(&init_net, dev) {
208 if (dev->flags & IFF_LOOPBACK) 219 if (dev->flags & IFF_LOOPBACK)
209 continue; 220 continue;
210 if (user_dev_name[0] ? !strcmp(dev->name, user_dev_name) : 221 if (ic_device_match(dev)) {
211 (!(dev->flags & IFF_LOOPBACK) &&
212 (dev->flags & (IFF_POINTOPOINT|IFF_BROADCAST)) &&
213 strncmp(dev->name, "dummy", 5))) {
214 int able = 0; 222 int able = 0;
215 if (dev->mtu >= 364) 223 if (dev->mtu >= 364)
216 able |= IC_BOOTP; 224 able |= IC_BOOTP;
@@ -228,7 +236,7 @@ static int __init ic_open_devs(void)
228 } 236 }
229 if (!(d = kmalloc(sizeof(struct ic_device), GFP_KERNEL))) { 237 if (!(d = kmalloc(sizeof(struct ic_device), GFP_KERNEL))) {
230 rtnl_unlock(); 238 rtnl_unlock();
231 return -1; 239 return -ENOMEM;
232 } 240 }
233 d->dev = dev; 241 d->dev = dev;
234 *last = d; 242 *last = d;
@@ -253,7 +261,7 @@ static int __init ic_open_devs(void)
253 printk(KERN_ERR "IP-Config: Device `%s' not found.\n", user_dev_name); 261 printk(KERN_ERR "IP-Config: Device `%s' not found.\n", user_dev_name);
254 else 262 else
255 printk(KERN_ERR "IP-Config: No network devices available.\n"); 263 printk(KERN_ERR "IP-Config: No network devices available.\n");
256 return -1; 264 return -ENODEV;
257 } 265 }
258 return 0; 266 return 0;
259} 267}
@@ -1172,10 +1180,9 @@ static int __init ic_dynamic(void)
1172 schedule_timeout_uninterruptible(1); 1180 schedule_timeout_uninterruptible(1);
1173#ifdef IPCONFIG_DHCP 1181#ifdef IPCONFIG_DHCP
1174 /* DHCP isn't done until we get a DHCPACK. */ 1182 /* DHCP isn't done until we get a DHCPACK. */
1175 if ((ic_got_reply & IC_BOOTP) 1183 if ((ic_got_reply & IC_BOOTP) &&
1176 && (ic_proto_enabled & IC_USE_DHCP) 1184 (ic_proto_enabled & IC_USE_DHCP) &&
1177 && ic_dhcp_msgtype != DHCPACK) 1185 ic_dhcp_msgtype != DHCPACK) {
1178 {
1179 ic_got_reply = 0; 1186 ic_got_reply = 0;
1180 printk(","); 1187 printk(",");
1181 continue; 1188 continue;
@@ -1304,6 +1311,32 @@ __be32 __init root_nfs_parse_addr(char *name)
1304 return addr; 1311 return addr;
1305} 1312}
1306 1313
1314#define DEVICE_WAIT_MAX 12 /* 12 seconds */
1315
1316static int __init wait_for_devices(void)
1317{
1318 int i;
1319
1320 msleep(CONF_PRE_OPEN);
1321 for (i = 0; i < DEVICE_WAIT_MAX; i++) {
1322 struct net_device *dev;
1323 int found = 0;
1324
1325 rtnl_lock();
1326 for_each_netdev(&init_net, dev) {
1327 if (ic_device_match(dev)) {
1328 found = 1;
1329 break;
1330 }
1331 }
1332 rtnl_unlock();
1333 if (found)
1334 return 0;
1335 ssleep(1);
1336 }
1337 return -ENODEV;
1338}
1339
1307/* 1340/*
1308 * IP Autoconfig dispatcher. 1341 * IP Autoconfig dispatcher.
1309 */ 1342 */
@@ -1314,6 +1347,7 @@ static int __init ip_auto_config(void)
1314#ifdef IPCONFIG_DYNAMIC 1347#ifdef IPCONFIG_DYNAMIC
1315 int retries = CONF_OPEN_RETRIES; 1348 int retries = CONF_OPEN_RETRIES;
1316#endif 1349#endif
1350 int err;
1317 1351
1318#ifdef CONFIG_PROC_FS 1352#ifdef CONFIG_PROC_FS
1319 proc_net_fops_create(&init_net, "pnp", S_IRUGO, &pnp_seq_fops); 1353 proc_net_fops_create(&init_net, "pnp", S_IRUGO, &pnp_seq_fops);
@@ -1326,12 +1360,15 @@ static int __init ip_auto_config(void)
1326#ifdef IPCONFIG_DYNAMIC 1360#ifdef IPCONFIG_DYNAMIC
1327 try_try_again: 1361 try_try_again:
1328#endif 1362#endif
1329 /* Give hardware a chance to settle */ 1363 /* Wait for devices to appear */
1330 msleep(CONF_PRE_OPEN); 1364 err = wait_for_devices();
1365 if (err)
1366 return err;
1331 1367
1332 /* Setup all network devices */ 1368 /* Setup all network devices */
1333 if (ic_open_devs() < 0) 1369 err = ic_open_devs();
1334 return -1; 1370 if (err)
1371 return err;
1335 1372
1336 /* Give drivers a chance to settle */ 1373 /* Give drivers a chance to settle */
1337 ssleep(CONF_POST_OPEN); 1374 ssleep(CONF_POST_OPEN);
@@ -1344,9 +1381,9 @@ static int __init ip_auto_config(void)
1344 */ 1381 */
1345 if (ic_myaddr == NONE || 1382 if (ic_myaddr == NONE ||
1346#ifdef CONFIG_ROOT_NFS 1383#ifdef CONFIG_ROOT_NFS
1347 (root_server_addr == NONE 1384 (root_server_addr == NONE &&
1348 && ic_servaddr == NONE 1385 ic_servaddr == NONE &&
1349 && ROOT_DEV == Root_NFS) || 1386 ROOT_DEV == Root_NFS) ||
1350#endif 1387#endif
1351 ic_first_dev->next) { 1388 ic_first_dev->next) {
1352#ifdef IPCONFIG_DYNAMIC 1389#ifdef IPCONFIG_DYNAMIC
@@ -1447,7 +1484,7 @@ late_initcall(ip_auto_config);
1447 1484
1448/* 1485/*
1449 * Decode any IP configuration options in the "ip=" or "nfsaddrs=" kernel 1486 * Decode any IP configuration options in the "ip=" or "nfsaddrs=" kernel
1450 * command line parameter. See Documentation/filesystems/nfsroot.txt. 1487 * command line parameter. See Documentation/filesystems/nfs/nfsroot.txt.
1451 */ 1488 */
1452static int __init ic_proto_name(char *name) 1489static int __init ic_proto_name(char *name)
1453{ 1490{
diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c
index ae40ed1ba560..0b27b14dcc9d 100644
--- a/net/ipv4/ipip.c
+++ b/net/ipv4/ipip.c
@@ -95,6 +95,7 @@
95#include <linux/module.h> 95#include <linux/module.h>
96#include <linux/types.h> 96#include <linux/types.h>
97#include <linux/kernel.h> 97#include <linux/kernel.h>
98#include <linux/slab.h>
98#include <asm/uaccess.h> 99#include <asm/uaccess.h>
99#include <linux/skbuff.h> 100#include <linux/skbuff.h>
100#include <linux/netdevice.h> 101#include <linux/netdevice.h>
@@ -119,7 +120,7 @@
119#define HASH_SIZE 16 120#define HASH_SIZE 16
120#define HASH(addr) (((__force u32)addr^((__force u32)addr>>4))&0xF) 121#define HASH(addr) (((__force u32)addr^((__force u32)addr>>4))&0xF)
121 122
122static int ipip_net_id; 123static int ipip_net_id __read_mostly;
123struct ipip_net { 124struct ipip_net {
124 struct ip_tunnel *tunnels_r_l[HASH_SIZE]; 125 struct ip_tunnel *tunnels_r_l[HASH_SIZE];
125 struct ip_tunnel *tunnels_r[HASH_SIZE]; 126 struct ip_tunnel *tunnels_r[HASH_SIZE];
@@ -130,11 +131,16 @@ struct ipip_net {
130 struct net_device *fb_tunnel_dev; 131 struct net_device *fb_tunnel_dev;
131}; 132};
132 133
133static void ipip_fb_tunnel_init(struct net_device *dev);
134static void 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); 137/*
138 * Locking : hash tables are protected by RCU and a spinlock
139 */
140static DEFINE_SPINLOCK(ipip_lock);
141
142#define for_each_ip_tunnel_rcu(start) \
143 for (t = rcu_dereference(start); t; t = rcu_dereference(t->next))
138 144
139static struct ip_tunnel * ipip_tunnel_lookup(struct net *net, 145static struct ip_tunnel * ipip_tunnel_lookup(struct net *net,
140 __be32 remote, __be32 local) 146 __be32 remote, __be32 local)
@@ -144,20 +150,21 @@ static struct ip_tunnel * ipip_tunnel_lookup(struct net *net,
144 struct ip_tunnel *t; 150 struct ip_tunnel *t;
145 struct ipip_net *ipn = net_generic(net, ipip_net_id); 151 struct ipip_net *ipn = net_generic(net, ipip_net_id);
146 152
147 for (t = ipn->tunnels_r_l[h0^h1]; t; t = t->next) { 153 for_each_ip_tunnel_rcu(ipn->tunnels_r_l[h0 ^ h1])
148 if (local == t->parms.iph.saddr && 154 if (local == t->parms.iph.saddr &&
149 remote == t->parms.iph.daddr && (t->dev->flags&IFF_UP)) 155 remote == t->parms.iph.daddr && (t->dev->flags&IFF_UP))
150 return t; 156 return t;
151 } 157
152 for (t = ipn->tunnels_r[h0]; t; t = t->next) { 158 for_each_ip_tunnel_rcu(ipn->tunnels_r[h0])
153 if (remote == t->parms.iph.daddr && (t->dev->flags&IFF_UP)) 159 if (remote == t->parms.iph.daddr && (t->dev->flags&IFF_UP))
154 return t; 160 return t;
155 } 161
156 for (t = ipn->tunnels_l[h1]; t; t = t->next) { 162 for_each_ip_tunnel_rcu(ipn->tunnels_l[h1])
157 if (local == t->parms.iph.saddr && (t->dev->flags&IFF_UP)) 163 if (local == t->parms.iph.saddr && (t->dev->flags&IFF_UP))
158 return t; 164 return t;
159 } 165
160 if ((t = ipn->tunnels_wc[0]) != NULL && (t->dev->flags&IFF_UP)) 166 t = rcu_dereference(ipn->tunnels_wc[0]);
167 if (t && (t->dev->flags&IFF_UP))
161 return t; 168 return t;
162 return NULL; 169 return NULL;
163} 170}
@@ -193,9 +200,9 @@ static void ipip_tunnel_unlink(struct ipip_net *ipn, struct ip_tunnel *t)
193 200
194 for (tp = ipip_bucket(ipn, t); *tp; tp = &(*tp)->next) { 201 for (tp = ipip_bucket(ipn, t); *tp; tp = &(*tp)->next) {
195 if (t == *tp) { 202 if (t == *tp) {
196 write_lock_bh(&ipip_lock); 203 spin_lock_bh(&ipip_lock);
197 *tp = t->next; 204 *tp = t->next;
198 write_unlock_bh(&ipip_lock); 205 spin_unlock_bh(&ipip_lock);
199 break; 206 break;
200 } 207 }
201 } 208 }
@@ -205,10 +212,10 @@ static void ipip_tunnel_link(struct ipip_net *ipn, struct ip_tunnel *t)
205{ 212{
206 struct ip_tunnel **tp = ipip_bucket(ipn, t); 213 struct ip_tunnel **tp = ipip_bucket(ipn, t);
207 214
215 spin_lock_bh(&ipip_lock);
208 t->next = *tp; 216 t->next = *tp;
209 write_lock_bh(&ipip_lock); 217 rcu_assign_pointer(*tp, t);
210 *tp = t; 218 spin_unlock_bh(&ipip_lock);
211 write_unlock_bh(&ipip_lock);
212} 219}
213 220
214static struct ip_tunnel * ipip_tunnel_locate(struct net *net, 221static struct ip_tunnel * ipip_tunnel_locate(struct net *net,
@@ -267,9 +274,9 @@ static void ipip_tunnel_uninit(struct net_device *dev)
267 struct ipip_net *ipn = net_generic(net, ipip_net_id); 274 struct ipip_net *ipn = net_generic(net, ipip_net_id);
268 275
269 if (dev == ipn->fb_tunnel_dev) { 276 if (dev == ipn->fb_tunnel_dev) {
270 write_lock_bh(&ipip_lock); 277 spin_lock_bh(&ipip_lock);
271 ipn->tunnels_wc[0] = NULL; 278 ipn->tunnels_wc[0] = NULL;
272 write_unlock_bh(&ipip_lock); 279 spin_unlock_bh(&ipip_lock);
273 } else 280 } else
274 ipip_tunnel_unlink(ipn, netdev_priv(dev)); 281 ipip_tunnel_unlink(ipn, netdev_priv(dev));
275 dev_put(dev); 282 dev_put(dev);
@@ -318,7 +325,7 @@ static int ipip_err(struct sk_buff *skb, u32 info)
318 325
319 err = -ENOENT; 326 err = -ENOENT;
320 327
321 read_lock(&ipip_lock); 328 rcu_read_lock();
322 t = ipip_tunnel_lookup(dev_net(skb->dev), iph->daddr, iph->saddr); 329 t = ipip_tunnel_lookup(dev_net(skb->dev), iph->daddr, iph->saddr);
323 if (t == NULL || t->parms.iph.daddr == 0) 330 if (t == NULL || t->parms.iph.daddr == 0)
324 goto out; 331 goto out;
@@ -333,7 +340,7 @@ static int ipip_err(struct sk_buff *skb, u32 info)
333 t->err_count = 1; 340 t->err_count = 1;
334 t->err_time = jiffies; 341 t->err_time = jiffies;
335out: 342out:
336 read_unlock(&ipip_lock); 343 rcu_read_unlock();
337 return err; 344 return err;
338} 345}
339 346
@@ -351,11 +358,11 @@ static int ipip_rcv(struct sk_buff *skb)
351 struct ip_tunnel *tunnel; 358 struct ip_tunnel *tunnel;
352 const struct iphdr *iph = ip_hdr(skb); 359 const struct iphdr *iph = ip_hdr(skb);
353 360
354 read_lock(&ipip_lock); 361 rcu_read_lock();
355 if ((tunnel = ipip_tunnel_lookup(dev_net(skb->dev), 362 if ((tunnel = ipip_tunnel_lookup(dev_net(skb->dev),
356 iph->saddr, iph->daddr)) != NULL) { 363 iph->saddr, iph->daddr)) != NULL) {
357 if (!xfrm4_policy_check(NULL, XFRM_POLICY_IN, skb)) { 364 if (!xfrm4_policy_check(NULL, XFRM_POLICY_IN, skb)) {
358 read_unlock(&ipip_lock); 365 rcu_read_unlock();
359 kfree_skb(skb); 366 kfree_skb(skb);
360 return 0; 367 return 0;
361 } 368 }
@@ -374,10 +381,10 @@ static int ipip_rcv(struct sk_buff *skb)
374 nf_reset(skb); 381 nf_reset(skb);
375 ipip_ecn_decapsulate(iph, skb); 382 ipip_ecn_decapsulate(iph, skb);
376 netif_rx(skb); 383 netif_rx(skb);
377 read_unlock(&ipip_lock); 384 rcu_read_unlock();
378 return 0; 385 return 0;
379 } 386 }
380 read_unlock(&ipip_lock); 387 rcu_read_unlock();
381 388
382 return -1; 389 return -1;
383} 390}
@@ -390,7 +397,8 @@ static int ipip_rcv(struct sk_buff *skb)
390static netdev_tx_t ipip_tunnel_xmit(struct sk_buff *skb, struct net_device *dev) 397static netdev_tx_t ipip_tunnel_xmit(struct sk_buff *skb, struct net_device *dev)
391{ 398{
392 struct ip_tunnel *tunnel = netdev_priv(dev); 399 struct ip_tunnel *tunnel = netdev_priv(dev);
393 struct net_device_stats *stats = &tunnel->dev->stats; 400 struct net_device_stats *stats = &dev->stats;
401 struct netdev_queue *txq = netdev_get_tx_queue(dev, 0);
394 struct iphdr *tiph = &tunnel->parms.iph; 402 struct iphdr *tiph = &tunnel->parms.iph;
395 u8 tos = tunnel->parms.iph.tos; 403 u8 tos = tunnel->parms.iph.tos;
396 __be16 df = tiph->frag_off; 404 __be16 df = tiph->frag_off;
@@ -480,7 +488,7 @@ static netdev_tx_t ipip_tunnel_xmit(struct sk_buff *skb, struct net_device *dev)
480 struct sk_buff *new_skb = skb_realloc_headroom(skb, max_headroom); 488 struct sk_buff *new_skb = skb_realloc_headroom(skb, max_headroom);
481 if (!new_skb) { 489 if (!new_skb) {
482 ip_rt_put(rt); 490 ip_rt_put(rt);
483 stats->tx_dropped++; 491 txq->tx_dropped++;
484 dev_kfree_skb(skb); 492 dev_kfree_skb(skb);
485 return NETDEV_TX_OK; 493 return NETDEV_TX_OK;
486 } 494 }
@@ -722,7 +730,7 @@ static void ipip_tunnel_init(struct net_device *dev)
722 ipip_tunnel_bind_dev(dev); 730 ipip_tunnel_bind_dev(dev);
723} 731}
724 732
725static void ipip_fb_tunnel_init(struct net_device *dev) 733static void __net_init ipip_fb_tunnel_init(struct net_device *dev)
726{ 734{
727 struct ip_tunnel *tunnel = netdev_priv(dev); 735 struct ip_tunnel *tunnel = netdev_priv(dev);
728 struct iphdr *iph = &tunnel->parms.iph; 736 struct iphdr *iph = &tunnel->parms.iph;
@@ -748,33 +756,27 @@ static struct xfrm_tunnel ipip_handler = {
748static const char banner[] __initconst = 756static const char banner[] __initconst =
749 KERN_INFO "IPv4 over IPv4 tunneling driver\n"; 757 KERN_INFO "IPv4 over IPv4 tunneling driver\n";
750 758
751static void ipip_destroy_tunnels(struct ipip_net *ipn) 759static void ipip_destroy_tunnels(struct ipip_net *ipn, struct list_head *head)
752{ 760{
753 int prio; 761 int prio;
754 762
755 for (prio = 1; prio < 4; prio++) { 763 for (prio = 1; prio < 4; prio++) {
756 int h; 764 int h;
757 for (h = 0; h < HASH_SIZE; h++) { 765 for (h = 0; h < HASH_SIZE; h++) {
758 struct ip_tunnel *t; 766 struct ip_tunnel *t = ipn->tunnels[prio][h];
759 while ((t = ipn->tunnels[prio][h]) != NULL) 767
760 unregister_netdevice(t->dev); 768 while (t != NULL) {
769 unregister_netdevice_queue(t->dev, head);
770 t = t->next;
771 }
761 } 772 }
762 } 773 }
763} 774}
764 775
765static int ipip_init_net(struct net *net) 776static int __net_init ipip_init_net(struct net *net)
766{ 777{
778 struct ipip_net *ipn = net_generic(net, ipip_net_id);
767 int err; 779 int err;
768 struct ipip_net *ipn;
769
770 err = -ENOMEM;
771 ipn = kzalloc(sizeof(struct ipip_net), GFP_KERNEL);
772 if (ipn == NULL)
773 goto err_alloc;
774
775 err = net_assign_generic(net, ipip_net_id, ipn);
776 if (err < 0)
777 goto err_assign;
778 780
779 ipn->tunnels[0] = ipn->tunnels_wc; 781 ipn->tunnels[0] = ipn->tunnels_wc;
780 ipn->tunnels[1] = ipn->tunnels_l; 782 ipn->tunnels[1] = ipn->tunnels_l;
@@ -801,27 +803,26 @@ err_reg_dev:
801 free_netdev(ipn->fb_tunnel_dev); 803 free_netdev(ipn->fb_tunnel_dev);
802err_alloc_dev: 804err_alloc_dev:
803 /* nothing */ 805 /* nothing */
804err_assign:
805 kfree(ipn);
806err_alloc:
807 return err; 806 return err;
808} 807}
809 808
810static void ipip_exit_net(struct net *net) 809static void __net_exit ipip_exit_net(struct net *net)
811{ 810{
812 struct ipip_net *ipn; 811 struct ipip_net *ipn = net_generic(net, ipip_net_id);
812 LIST_HEAD(list);
813 813
814 ipn = net_generic(net, ipip_net_id);
815 rtnl_lock(); 814 rtnl_lock();
816 ipip_destroy_tunnels(ipn); 815 ipip_destroy_tunnels(ipn, &list);
817 unregister_netdevice(ipn->fb_tunnel_dev); 816 unregister_netdevice_queue(ipn->fb_tunnel_dev, &list);
817 unregister_netdevice_many(&list);
818 rtnl_unlock(); 818 rtnl_unlock();
819 kfree(ipn);
820} 819}
821 820
822static struct pernet_operations ipip_net_ops = { 821static struct pernet_operations ipip_net_ops = {
823 .init = ipip_init_net, 822 .init = ipip_init_net,
824 .exit = ipip_exit_net, 823 .exit = ipip_exit_net,
824 .id = &ipip_net_id,
825 .size = sizeof(struct ipip_net),
825}; 826};
826 827
827static int __init ipip_init(void) 828static int __init ipip_init(void)
@@ -830,15 +831,14 @@ static int __init ipip_init(void)
830 831
831 printk(banner); 832 printk(banner);
832 833
833 if (xfrm4_tunnel_register(&ipip_handler, AF_INET)) { 834 err = register_pernet_device(&ipip_net_ops);
835 if (err < 0)
836 return err;
837 err = xfrm4_tunnel_register(&ipip_handler, AF_INET);
838 if (err < 0) {
839 unregister_pernet_device(&ipip_net_ops);
834 printk(KERN_INFO "ipip init: can't register tunnel\n"); 840 printk(KERN_INFO "ipip init: can't register tunnel\n");
835 return -EAGAIN;
836 } 841 }
837
838 err = register_pernet_gen_device(&ipip_net_id, &ipip_net_ops);
839 if (err)
840 xfrm4_tunnel_deregister(&ipip_handler, AF_INET);
841
842 return err; 842 return err;
843} 843}
844 844
@@ -847,7 +847,7 @@ static void __exit ipip_fini(void)
847 if (xfrm4_tunnel_deregister(&ipip_handler, AF_INET)) 847 if (xfrm4_tunnel_deregister(&ipip_handler, AF_INET))
848 printk(KERN_INFO "ipip close: can't deregister tunnel\n"); 848 printk(KERN_INFO "ipip close: can't deregister tunnel\n");
849 849
850 unregister_pernet_gen_device(ipip_net_id, &ipip_net_ops); 850 unregister_pernet_device(&ipip_net_ops);
851} 851}
852 852
853module_init(ipip_init); 853module_init(ipip_init);
diff --git a/net/ipv4/ipmr.c b/net/ipv4/ipmr.c
index 99508d66a642..ec19a890c9a0 100644
--- a/net/ipv4/ipmr.c
+++ b/net/ipv4/ipmr.c
@@ -47,6 +47,7 @@
47#include <linux/mroute.h> 47#include <linux/mroute.h>
48#include <linux/init.h> 48#include <linux/init.h>
49#include <linux/if_ether.h> 49#include <linux/if_ether.h>
50#include <linux/slab.h>
50#include <net/net_namespace.h> 51#include <net/net_namespace.h>
51#include <net/ip.h> 52#include <net/ip.h>
52#include <net/protocol.h> 53#include <net/protocol.h>
@@ -275,7 +276,8 @@ failure:
275 * @notify: Set to 1, if the caller is a notifier_call 276 * @notify: Set to 1, if the caller is a notifier_call
276 */ 277 */
277 278
278static int vif_delete(struct net *net, int vifi, int notify) 279static int vif_delete(struct net *net, int vifi, int notify,
280 struct list_head *head)
279{ 281{
280 struct vif_device *v; 282 struct vif_device *v;
281 struct net_device *dev; 283 struct net_device *dev;
@@ -319,7 +321,7 @@ static int vif_delete(struct net *net, int vifi, int notify)
319 } 321 }
320 322
321 if (v->flags&(VIFF_TUNNEL|VIFF_REGISTER) && !notify) 323 if (v->flags&(VIFF_TUNNEL|VIFF_REGISTER) && !notify)
322 unregister_netdevice(dev); 324 unregister_netdevice_queue(dev, head);
323 325
324 dev_put(dev); 326 dev_put(dev);
325 return 0; 327 return 0;
@@ -469,8 +471,18 @@ static int vif_add(struct net *net, struct vifctl *vifc, int mrtsock)
469 return err; 471 return err;
470 } 472 }
471 break; 473 break;
474
475 case VIFF_USE_IFINDEX:
472 case 0: 476 case 0:
473 dev = ip_dev_find(net, vifc->vifc_lcl_addr.s_addr); 477 if (vifc->vifc_flags == VIFF_USE_IFINDEX) {
478 dev = dev_get_by_index(net, vifc->vifc_lcl_ifindex);
479 if (dev && dev->ip_ptr == NULL) {
480 dev_put(dev);
481 return -EADDRNOTAVAIL;
482 }
483 } else
484 dev = ip_dev_find(net, vifc->vifc_lcl_addr.s_addr);
485
474 if (!dev) 486 if (!dev)
475 return -EADDRNOTAVAIL; 487 return -EADDRNOTAVAIL;
476 err = dev_set_allmulti(dev, 1); 488 err = dev_set_allmulti(dev, 1);
@@ -742,7 +754,8 @@ ipmr_cache_unresolved(struct net *net, vifi_t vifi, struct sk_buff *skb)
742 c->next = mfc_unres_queue; 754 c->next = mfc_unres_queue;
743 mfc_unres_queue = c; 755 mfc_unres_queue = c;
744 756
745 mod_timer(&ipmr_expire_timer, c->mfc_un.unres.expires); 757 if (atomic_read(&net->ipv4.cache_resolve_queue_len) == 1)
758 mod_timer(&ipmr_expire_timer, c->mfc_un.unres.expires);
746 } 759 }
747 760
748 /* 761 /*
@@ -791,6 +804,9 @@ static int ipmr_mfc_add(struct net *net, struct mfcctl *mfc, int mrtsock)
791 int line; 804 int line;
792 struct mfc_cache *uc, *c, **cp; 805 struct mfc_cache *uc, *c, **cp;
793 806
807 if (mfc->mfcc_parent >= MAXVIFS)
808 return -ENFILE;
809
794 line = MFC_HASH(mfc->mfcc_mcastgrp.s_addr, mfc->mfcc_origin.s_addr); 810 line = MFC_HASH(mfc->mfcc_mcastgrp.s_addr, mfc->mfcc_origin.s_addr);
795 811
796 for (cp = &net->ipv4.mfc_cache_array[line]; 812 for (cp = &net->ipv4.mfc_cache_array[line];
@@ -862,14 +878,16 @@ static int ipmr_mfc_add(struct net *net, struct mfcctl *mfc, int mrtsock)
862static void mroute_clean_tables(struct net *net) 878static void mroute_clean_tables(struct net *net)
863{ 879{
864 int i; 880 int i;
881 LIST_HEAD(list);
865 882
866 /* 883 /*
867 * Shut down all active vif entries 884 * Shut down all active vif entries
868 */ 885 */
869 for (i = 0; i < net->ipv4.maxvif; i++) { 886 for (i = 0; i < net->ipv4.maxvif; i++) {
870 if (!(net->ipv4.vif_table[i].flags&VIFF_STATIC)) 887 if (!(net->ipv4.vif_table[i].flags&VIFF_STATIC))
871 vif_delete(net, i, 0); 888 vif_delete(net, i, 0, &list);
872 } 889 }
890 unregister_netdevice_many(&list);
873 891
874 /* 892 /*
875 * Wipe the cache 893 * Wipe the cache
@@ -948,7 +966,7 @@ int ip_mroute_setsockopt(struct sock *sk, int optname, char __user *optval, unsi
948 switch (optname) { 966 switch (optname) {
949 case MRT_INIT: 967 case MRT_INIT:
950 if (sk->sk_type != SOCK_RAW || 968 if (sk->sk_type != SOCK_RAW ||
951 inet_sk(sk)->num != IPPROTO_IGMP) 969 inet_sk(sk)->inet_num != IPPROTO_IGMP)
952 return -EOPNOTSUPP; 970 return -EOPNOTSUPP;
953 if (optlen != sizeof(int)) 971 if (optlen != sizeof(int))
954 return -ENOPROTOOPT; 972 return -ENOPROTOOPT;
@@ -985,7 +1003,7 @@ int ip_mroute_setsockopt(struct sock *sk, int optname, char __user *optval, unsi
985 if (optname == MRT_ADD_VIF) { 1003 if (optname == MRT_ADD_VIF) {
986 ret = vif_add(net, &vif, sk == net->ipv4.mroute_sk); 1004 ret = vif_add(net, &vif, sk == net->ipv4.mroute_sk);
987 } else { 1005 } else {
988 ret = vif_delete(net, vif.vifc_vifi, 0); 1006 ret = vif_delete(net, vif.vifc_vifi, 0, NULL);
989 } 1007 }
990 rtnl_unlock(); 1008 rtnl_unlock();
991 return ret; 1009 return ret;
@@ -1148,17 +1166,16 @@ static int ipmr_device_event(struct notifier_block *this, unsigned long event, v
1148 struct net *net = dev_net(dev); 1166 struct net *net = dev_net(dev);
1149 struct vif_device *v; 1167 struct vif_device *v;
1150 int ct; 1168 int ct;
1151 1169 LIST_HEAD(list);
1152 if (!net_eq(dev_net(dev), net))
1153 return NOTIFY_DONE;
1154 1170
1155 if (event != NETDEV_UNREGISTER) 1171 if (event != NETDEV_UNREGISTER)
1156 return NOTIFY_DONE; 1172 return NOTIFY_DONE;
1157 v = &net->ipv4.vif_table[0]; 1173 v = &net->ipv4.vif_table[0];
1158 for (ct = 0; ct < net->ipv4.maxvif; ct++, v++) { 1174 for (ct = 0; ct < net->ipv4.maxvif; ct++, v++) {
1159 if (v->dev == dev) 1175 if (v->dev == dev)
1160 vif_delete(net, ct, 1); 1176 vif_delete(net, ct, 1, &list);
1161 } 1177 }
1178 unregister_netdevice_many(&list);
1162 return NOTIFY_DONE; 1179 return NOTIFY_DONE;
1163} 1180}
1164 1181
@@ -1601,17 +1618,20 @@ ipmr_fill_mroute(struct sk_buff *skb, struct mfc_cache *c, struct rtmsg *rtm)
1601 int ct; 1618 int ct;
1602 struct rtnexthop *nhp; 1619 struct rtnexthop *nhp;
1603 struct net *net = mfc_net(c); 1620 struct net *net = mfc_net(c);
1604 struct net_device *dev = net->ipv4.vif_table[c->mfc_parent].dev;
1605 u8 *b = skb_tail_pointer(skb); 1621 u8 *b = skb_tail_pointer(skb);
1606 struct rtattr *mp_head; 1622 struct rtattr *mp_head;
1607 1623
1608 if (dev) 1624 /* If cache is unresolved, don't try to parse IIF and OIF */
1609 RTA_PUT(skb, RTA_IIF, 4, &dev->ifindex); 1625 if (c->mfc_parent > MAXVIFS)
1626 return -ENOENT;
1627
1628 if (VIF_EXISTS(net, c->mfc_parent))
1629 RTA_PUT(skb, RTA_IIF, 4, &net->ipv4.vif_table[c->mfc_parent].dev->ifindex);
1610 1630
1611 mp_head = (struct rtattr *)skb_put(skb, RTA_LENGTH(0)); 1631 mp_head = (struct rtattr *)skb_put(skb, RTA_LENGTH(0));
1612 1632
1613 for (ct = c->mfc_un.res.minvif; ct < c->mfc_un.res.maxvif; ct++) { 1633 for (ct = c->mfc_un.res.minvif; ct < c->mfc_un.res.maxvif; ct++) {
1614 if (c->mfc_un.res.ttls[ct] < 255) { 1634 if (VIF_EXISTS(net, ct) && c->mfc_un.res.ttls[ct] < 255) {
1615 if (skb_tailroom(skb) < RTA_ALIGN(RTA_ALIGN(sizeof(*nhp)) + 4)) 1635 if (skb_tailroom(skb) < RTA_ALIGN(RTA_ALIGN(sizeof(*nhp)) + 4))
1616 goto rtattr_failure; 1636 goto rtattr_failure;
1617 nhp = (struct rtnexthop *)skb_put(skb, RTA_ALIGN(sizeof(*nhp))); 1637 nhp = (struct rtnexthop *)skb_put(skb, RTA_ALIGN(sizeof(*nhp)));
diff --git a/net/ipv4/netfilter.c b/net/ipv4/netfilter.c
index 1725dc0ef688..82fb43c5c59e 100644
--- a/net/ipv4/netfilter.c
+++ b/net/ipv4/netfilter.c
@@ -4,6 +4,7 @@
4#include <linux/netfilter_ipv4.h> 4#include <linux/netfilter_ipv4.h>
5#include <linux/ip.h> 5#include <linux/ip.h>
6#include <linux/skbuff.h> 6#include <linux/skbuff.h>
7#include <linux/gfp.h>
7#include <net/route.h> 8#include <net/route.h>
8#include <net/xfrm.h> 9#include <net/xfrm.h>
9#include <net/ip.h> 10#include <net/ip.h>
@@ -155,10 +156,10 @@ static int nf_ip_reroute(struct sk_buff *skb,
155 if (entry->hook == NF_INET_LOCAL_OUT) { 156 if (entry->hook == NF_INET_LOCAL_OUT) {
156 const struct iphdr *iph = ip_hdr(skb); 157 const struct iphdr *iph = ip_hdr(skb);
157 158
158 if (!(iph->tos == rt_info->tos 159 if (!(iph->tos == rt_info->tos &&
159 && skb->mark == rt_info->mark 160 skb->mark == rt_info->mark &&
160 && iph->daddr == rt_info->daddr 161 iph->daddr == rt_info->daddr &&
161 && iph->saddr == rt_info->saddr)) 162 iph->saddr == rt_info->saddr))
162 return ip_route_me_harder(skb, RTN_UNSPEC); 163 return ip_route_me_harder(skb, RTN_UNSPEC);
163 } 164 }
164 return 0; 165 return 0;
@@ -248,9 +249,9 @@ module_exit(ipv4_netfilter_fini);
248 249
249#ifdef CONFIG_SYSCTL 250#ifdef CONFIG_SYSCTL
250struct ctl_path nf_net_ipv4_netfilter_sysctl_path[] = { 251struct ctl_path nf_net_ipv4_netfilter_sysctl_path[] = {
251 { .procname = "net", .ctl_name = CTL_NET, }, 252 { .procname = "net", },
252 { .procname = "ipv4", .ctl_name = NET_IPV4, }, 253 { .procname = "ipv4", },
253 { .procname = "netfilter", .ctl_name = NET_IPV4_NETFILTER, }, 254 { .procname = "netfilter", },
254 { } 255 { }
255}; 256};
256EXPORT_SYMBOL_GPL(nf_net_ipv4_netfilter_sysctl_path); 257EXPORT_SYMBOL_GPL(nf_net_ipv4_netfilter_sysctl_path);
diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
index 27774c99d888..f07d77f65751 100644
--- a/net/ipv4/netfilter/arp_tables.c
+++ b/net/ipv4/netfilter/arp_tables.c
@@ -27,6 +27,7 @@
27 27
28#include <linux/netfilter/x_tables.h> 28#include <linux/netfilter/x_tables.h>
29#include <linux/netfilter_arp/arp_tables.h> 29#include <linux/netfilter_arp/arp_tables.h>
30#include "../../netfilter/xt_repldata.h"
30 31
31MODULE_LICENSE("GPL"); 32MODULE_LICENSE("GPL");
32MODULE_AUTHOR("David S. Miller <davem@redhat.com>"); 33MODULE_AUTHOR("David S. Miller <davem@redhat.com>");
@@ -58,6 +59,12 @@ do { \
58#define ARP_NF_ASSERT(x) 59#define ARP_NF_ASSERT(x)
59#endif 60#endif
60 61
62void *arpt_alloc_initial_table(const struct xt_table *info)
63{
64 return xt_alloc_initial_table(arpt, ARPT);
65}
66EXPORT_SYMBOL_GPL(arpt_alloc_initial_table);
67
61static inline int arp_devaddr_compare(const struct arpt_devaddr_info *ap, 68static inline int arp_devaddr_compare(const struct arpt_devaddr_info *ap,
62 const char *hdr_addr, int len) 69 const char *hdr_addr, int len)
63{ 70{
@@ -226,7 +233,14 @@ arpt_error(struct sk_buff *skb, const struct xt_target_param *par)
226 return NF_DROP; 233 return NF_DROP;
227} 234}
228 235
229static inline struct arpt_entry *get_entry(void *base, unsigned int offset) 236static inline const struct arpt_entry_target *
237arpt_get_target_c(const struct arpt_entry *e)
238{
239 return arpt_get_target((struct arpt_entry *)e);
240}
241
242static inline struct arpt_entry *
243get_entry(const void *base, unsigned int offset)
230{ 244{
231 return (struct arpt_entry *)(base + offset); 245 return (struct arpt_entry *)(base + offset);
232} 246}
@@ -273,7 +287,7 @@ unsigned int arpt_do_table(struct sk_buff *skb,
273 287
274 arp = arp_hdr(skb); 288 arp = arp_hdr(skb);
275 do { 289 do {
276 struct arpt_entry_target *t; 290 const struct arpt_entry_target *t;
277 int hdr_len; 291 int hdr_len;
278 292
279 if (!arp_packet_match(arp, skb->dev, indev, outdev, &e->arp)) { 293 if (!arp_packet_match(arp, skb->dev, indev, outdev, &e->arp)) {
@@ -285,7 +299,7 @@ unsigned int arpt_do_table(struct sk_buff *skb,
285 (2 * skb->dev->addr_len); 299 (2 * skb->dev->addr_len);
286 ADD_COUNTER(e->counters, hdr_len, 1); 300 ADD_COUNTER(e->counters, hdr_len, 1);
287 301
288 t = arpt_get_target(e); 302 t = arpt_get_target_c(e);
289 303
290 /* Standard target? */ 304 /* Standard target? */
291 if (!t->u.kernel.target->target) { 305 if (!t->u.kernel.target->target) {
@@ -351,7 +365,7 @@ static inline bool unconditional(const struct arpt_arp *arp)
351/* Figures out from what hook each rule can be called: returns 0 if 365/* Figures out from what hook each rule can be called: returns 0 if
352 * there are loops. Puts hook bitmask in comefrom. 366 * there are loops. Puts hook bitmask in comefrom.
353 */ 367 */
354static int mark_source_chains(struct xt_table_info *newinfo, 368static int mark_source_chains(const struct xt_table_info *newinfo,
355 unsigned int valid_hooks, void *entry0) 369 unsigned int valid_hooks, void *entry0)
356{ 370{
357 unsigned int hook; 371 unsigned int hook;
@@ -372,7 +386,7 @@ static int mark_source_chains(struct xt_table_info *newinfo,
372 386
373 for (;;) { 387 for (;;) {
374 const struct arpt_standard_target *t 388 const struct arpt_standard_target *t
375 = (void *)arpt_get_target(e); 389 = (void *)arpt_get_target_c(e);
376 int visited = e->comefrom & (1 << hook); 390 int visited = e->comefrom & (1 << hook);
377 391
378 if (e->comefrom & (1 << NF_ARP_NUMHOOKS)) { 392 if (e->comefrom & (1 << NF_ARP_NUMHOOKS)) {
@@ -384,11 +398,11 @@ static int mark_source_chains(struct xt_table_info *newinfo,
384 |= ((1 << hook) | (1 << NF_ARP_NUMHOOKS)); 398 |= ((1 << hook) | (1 << NF_ARP_NUMHOOKS));
385 399
386 /* Unconditional return/END. */ 400 /* Unconditional return/END. */
387 if ((e->target_offset == sizeof(struct arpt_entry) 401 if ((e->target_offset == sizeof(struct arpt_entry) &&
388 && (strcmp(t->target.u.user.name, 402 (strcmp(t->target.u.user.name,
389 ARPT_STANDARD_TARGET) == 0) 403 ARPT_STANDARD_TARGET) == 0) &&
390 && t->verdict < 0 404 t->verdict < 0 && unconditional(&e->arp)) ||
391 && unconditional(&e->arp)) || visited) { 405 visited) {
392 unsigned int oldpos, size; 406 unsigned int oldpos, size;
393 407
394 if ((strcmp(t->target.u.user.name, 408 if ((strcmp(t->target.u.user.name,
@@ -427,8 +441,8 @@ static int mark_source_chains(struct xt_table_info *newinfo,
427 int newpos = t->verdict; 441 int newpos = t->verdict;
428 442
429 if (strcmp(t->target.u.user.name, 443 if (strcmp(t->target.u.user.name,
430 ARPT_STANDARD_TARGET) == 0 444 ARPT_STANDARD_TARGET) == 0 &&
431 && newpos >= 0) { 445 newpos >= 0) {
432 if (newpos > newinfo->size - 446 if (newpos > newinfo->size -
433 sizeof(struct arpt_entry)) { 447 sizeof(struct arpt_entry)) {
434 duprintf("mark_source_chains: " 448 duprintf("mark_source_chains: "
@@ -456,7 +470,7 @@ static int mark_source_chains(struct xt_table_info *newinfo,
456 return 1; 470 return 1;
457} 471}
458 472
459static inline int check_entry(struct arpt_entry *e, const char *name) 473static inline int check_entry(const struct arpt_entry *e, const char *name)
460{ 474{
461 const struct arpt_entry_target *t; 475 const struct arpt_entry_target *t;
462 476
@@ -468,7 +482,7 @@ static inline int check_entry(struct arpt_entry *e, const char *name)
468 if (e->target_offset + sizeof(struct arpt_entry_target) > e->next_offset) 482 if (e->target_offset + sizeof(struct arpt_entry_target) > e->next_offset)
469 return -EINVAL; 483 return -EINVAL;
470 484
471 t = arpt_get_target(e); 485 t = arpt_get_target_c(e);
472 if (e->target_offset + t->u.target_size > e->next_offset) 486 if (e->target_offset + t->u.target_size > e->next_offset)
473 return -EINVAL; 487 return -EINVAL;
474 488
@@ -498,8 +512,7 @@ static inline int check_target(struct arpt_entry *e, const char *name)
498} 512}
499 513
500static inline int 514static inline int
501find_check_entry(struct arpt_entry *e, const char *name, unsigned int size, 515find_check_entry(struct arpt_entry *e, const char *name, unsigned int size)
502 unsigned int *i)
503{ 516{
504 struct arpt_entry_target *t; 517 struct arpt_entry_target *t;
505 struct xt_target *target; 518 struct xt_target *target;
@@ -524,8 +537,6 @@ find_check_entry(struct arpt_entry *e, const char *name, unsigned int size,
524 ret = check_target(e, name); 537 ret = check_target(e, name);
525 if (ret) 538 if (ret)
526 goto err; 539 goto err;
527
528 (*i)++;
529 return 0; 540 return 0;
530err: 541err:
531 module_put(t->u.kernel.target->me); 542 module_put(t->u.kernel.target->me);
@@ -533,14 +544,14 @@ out:
533 return ret; 544 return ret;
534} 545}
535 546
536static bool check_underflow(struct arpt_entry *e) 547static bool check_underflow(const struct arpt_entry *e)
537{ 548{
538 const struct arpt_entry_target *t; 549 const struct arpt_entry_target *t;
539 unsigned int verdict; 550 unsigned int verdict;
540 551
541 if (!unconditional(&e->arp)) 552 if (!unconditional(&e->arp))
542 return false; 553 return false;
543 t = arpt_get_target(e); 554 t = arpt_get_target_c(e);
544 if (strcmp(t->u.user.name, XT_STANDARD_TARGET) != 0) 555 if (strcmp(t->u.user.name, XT_STANDARD_TARGET) != 0)
545 return false; 556 return false;
546 verdict = ((struct arpt_standard_target *)t)->verdict; 557 verdict = ((struct arpt_standard_target *)t)->verdict;
@@ -550,17 +561,16 @@ static bool check_underflow(struct arpt_entry *e)
550 561
551static inline int check_entry_size_and_hooks(struct arpt_entry *e, 562static inline int check_entry_size_and_hooks(struct arpt_entry *e,
552 struct xt_table_info *newinfo, 563 struct xt_table_info *newinfo,
553 unsigned char *base, 564 const unsigned char *base,
554 unsigned char *limit, 565 const unsigned char *limit,
555 const unsigned int *hook_entries, 566 const unsigned int *hook_entries,
556 const unsigned int *underflows, 567 const unsigned int *underflows,
557 unsigned int valid_hooks, 568 unsigned int valid_hooks)
558 unsigned int *i)
559{ 569{
560 unsigned int h; 570 unsigned int h;
561 571
562 if ((unsigned long)e % __alignof__(struct arpt_entry) != 0 572 if ((unsigned long)e % __alignof__(struct arpt_entry) != 0 ||
563 || (unsigned char *)e + sizeof(struct arpt_entry) >= limit) { 573 (unsigned char *)e + sizeof(struct arpt_entry) >= limit) {
564 duprintf("Bad offset %p\n", e); 574 duprintf("Bad offset %p\n", e);
565 return -EINVAL; 575 return -EINVAL;
566 } 576 }
@@ -592,19 +602,14 @@ static inline int check_entry_size_and_hooks(struct arpt_entry *e,
592 /* Clear counters and comefrom */ 602 /* Clear counters and comefrom */
593 e->counters = ((struct xt_counters) { 0, 0 }); 603 e->counters = ((struct xt_counters) { 0, 0 });
594 e->comefrom = 0; 604 e->comefrom = 0;
595
596 (*i)++;
597 return 0; 605 return 0;
598} 606}
599 607
600static inline int cleanup_entry(struct arpt_entry *e, unsigned int *i) 608static inline void cleanup_entry(struct arpt_entry *e)
601{ 609{
602 struct xt_tgdtor_param par; 610 struct xt_tgdtor_param par;
603 struct arpt_entry_target *t; 611 struct arpt_entry_target *t;
604 612
605 if (i && (*i)-- == 0)
606 return 1;
607
608 t = arpt_get_target(e); 613 t = arpt_get_target(e);
609 par.target = t->u.kernel.target; 614 par.target = t->u.kernel.target;
610 par.targinfo = t->data; 615 par.targinfo = t->data;
@@ -612,26 +617,20 @@ static inline int cleanup_entry(struct arpt_entry *e, unsigned int *i)
612 if (par.target->destroy != NULL) 617 if (par.target->destroy != NULL)
613 par.target->destroy(&par); 618 par.target->destroy(&par);
614 module_put(par.target->me); 619 module_put(par.target->me);
615 return 0;
616} 620}
617 621
618/* Checks and translates the user-supplied table segment (held in 622/* Checks and translates the user-supplied table segment (held in
619 * newinfo). 623 * newinfo).
620 */ 624 */
621static int translate_table(const char *name, 625static int translate_table(struct xt_table_info *newinfo, void *entry0,
622 unsigned int valid_hooks, 626 const struct arpt_replace *repl)
623 struct xt_table_info *newinfo,
624 void *entry0,
625 unsigned int size,
626 unsigned int number,
627 const unsigned int *hook_entries,
628 const unsigned int *underflows)
629{ 627{
628 struct arpt_entry *iter;
630 unsigned int i; 629 unsigned int i;
631 int ret; 630 int ret = 0;
632 631
633 newinfo->size = size; 632 newinfo->size = repl->size;
634 newinfo->number = number; 633 newinfo->number = repl->num_entries;
635 634
636 /* Init all hooks to impossible value. */ 635 /* Init all hooks to impossible value. */
637 for (i = 0; i < NF_ARP_NUMHOOKS; i++) { 636 for (i = 0; i < NF_ARP_NUMHOOKS; i++) {
@@ -643,52 +642,63 @@ static int translate_table(const char *name,
643 i = 0; 642 i = 0;
644 643
645 /* Walk through entries, checking offsets. */ 644 /* Walk through entries, checking offsets. */
646 ret = ARPT_ENTRY_ITERATE(entry0, newinfo->size, 645 xt_entry_foreach(iter, entry0, newinfo->size) {
647 check_entry_size_and_hooks, 646 ret = check_entry_size_and_hooks(iter, newinfo, entry0,
648 newinfo, 647 entry0 + repl->size,
649 entry0, 648 repl->hook_entry,
650 entry0 + size, 649 repl->underflow,
651 hook_entries, underflows, valid_hooks, &i); 650 repl->valid_hooks);
651 if (ret != 0)
652 break;
653 ++i;
654 }
652 duprintf("translate_table: ARPT_ENTRY_ITERATE gives %d\n", ret); 655 duprintf("translate_table: ARPT_ENTRY_ITERATE gives %d\n", ret);
653 if (ret != 0) 656 if (ret != 0)
654 return ret; 657 return ret;
655 658
656 if (i != number) { 659 if (i != repl->num_entries) {
657 duprintf("translate_table: %u not %u entries\n", 660 duprintf("translate_table: %u not %u entries\n",
658 i, number); 661 i, repl->num_entries);
659 return -EINVAL; 662 return -EINVAL;
660 } 663 }
661 664
662 /* Check hooks all assigned */ 665 /* Check hooks all assigned */
663 for (i = 0; i < NF_ARP_NUMHOOKS; i++) { 666 for (i = 0; i < NF_ARP_NUMHOOKS; i++) {
664 /* Only hooks which are valid */ 667 /* Only hooks which are valid */
665 if (!(valid_hooks & (1 << i))) 668 if (!(repl->valid_hooks & (1 << i)))
666 continue; 669 continue;
667 if (newinfo->hook_entry[i] == 0xFFFFFFFF) { 670 if (newinfo->hook_entry[i] == 0xFFFFFFFF) {
668 duprintf("Invalid hook entry %u %u\n", 671 duprintf("Invalid hook entry %u %u\n",
669 i, hook_entries[i]); 672 i, repl->hook_entry[i]);
670 return -EINVAL; 673 return -EINVAL;
671 } 674 }
672 if (newinfo->underflow[i] == 0xFFFFFFFF) { 675 if (newinfo->underflow[i] == 0xFFFFFFFF) {
673 duprintf("Invalid underflow %u %u\n", 676 duprintf("Invalid underflow %u %u\n",
674 i, underflows[i]); 677 i, repl->underflow[i]);
675 return -EINVAL; 678 return -EINVAL;
676 } 679 }
677 } 680 }
678 681
679 if (!mark_source_chains(newinfo, valid_hooks, entry0)) { 682 if (!mark_source_chains(newinfo, repl->valid_hooks, entry0)) {
680 duprintf("Looping hook\n"); 683 duprintf("Looping hook\n");
681 return -ELOOP; 684 return -ELOOP;
682 } 685 }
683 686
684 /* Finally, each sanity check must pass */ 687 /* Finally, each sanity check must pass */
685 i = 0; 688 i = 0;
686 ret = ARPT_ENTRY_ITERATE(entry0, newinfo->size, 689 xt_entry_foreach(iter, entry0, newinfo->size) {
687 find_check_entry, name, size, &i); 690 ret = find_check_entry(iter, repl->name, repl->size);
691 if (ret != 0)
692 break;
693 ++i;
694 }
688 695
689 if (ret != 0) { 696 if (ret != 0) {
690 ARPT_ENTRY_ITERATE(entry0, newinfo->size, 697 xt_entry_foreach(iter, entry0, newinfo->size) {
691 cleanup_entry, &i); 698 if (i-- == 0)
699 break;
700 cleanup_entry(iter);
701 }
692 return ret; 702 return ret;
693 } 703 }
694 704
@@ -701,30 +711,10 @@ static int translate_table(const char *name,
701 return ret; 711 return ret;
702} 712}
703 713
704/* Gets counters. */
705static inline int add_entry_to_counter(const struct arpt_entry *e,
706 struct xt_counters total[],
707 unsigned int *i)
708{
709 ADD_COUNTER(total[*i], e->counters.bcnt, e->counters.pcnt);
710
711 (*i)++;
712 return 0;
713}
714
715static inline int set_entry_to_counter(const struct arpt_entry *e,
716 struct xt_counters total[],
717 unsigned int *i)
718{
719 SET_COUNTER(total[*i], e->counters.bcnt, e->counters.pcnt);
720
721 (*i)++;
722 return 0;
723}
724
725static void get_counters(const struct xt_table_info *t, 714static void get_counters(const struct xt_table_info *t,
726 struct xt_counters counters[]) 715 struct xt_counters counters[])
727{ 716{
717 struct arpt_entry *iter;
728 unsigned int cpu; 718 unsigned int cpu;
729 unsigned int i; 719 unsigned int i;
730 unsigned int curcpu; 720 unsigned int curcpu;
@@ -740,32 +730,32 @@ static void get_counters(const struct xt_table_info *t,
740 curcpu = smp_processor_id(); 730 curcpu = smp_processor_id();
741 731
742 i = 0; 732 i = 0;
743 ARPT_ENTRY_ITERATE(t->entries[curcpu], 733 xt_entry_foreach(iter, t->entries[curcpu], t->size) {
744 t->size, 734 SET_COUNTER(counters[i], iter->counters.bcnt,
745 set_entry_to_counter, 735 iter->counters.pcnt);
746 counters, 736 ++i;
747 &i); 737 }
748 738
749 for_each_possible_cpu(cpu) { 739 for_each_possible_cpu(cpu) {
750 if (cpu == curcpu) 740 if (cpu == curcpu)
751 continue; 741 continue;
752 i = 0; 742 i = 0;
753 xt_info_wrlock(cpu); 743 xt_info_wrlock(cpu);
754 ARPT_ENTRY_ITERATE(t->entries[cpu], 744 xt_entry_foreach(iter, t->entries[cpu], t->size) {
755 t->size, 745 ADD_COUNTER(counters[i], iter->counters.bcnt,
756 add_entry_to_counter, 746 iter->counters.pcnt);
757 counters, 747 ++i;
758 &i); 748 }
759 xt_info_wrunlock(cpu); 749 xt_info_wrunlock(cpu);
760 } 750 }
761 local_bh_enable(); 751 local_bh_enable();
762} 752}
763 753
764static struct xt_counters *alloc_counters(struct xt_table *table) 754static struct xt_counters *alloc_counters(const struct xt_table *table)
765{ 755{
766 unsigned int countersize; 756 unsigned int countersize;
767 struct xt_counters *counters; 757 struct xt_counters *counters;
768 struct xt_table_info *private = table->private; 758 const struct xt_table_info *private = table->private;
769 759
770 /* We need atomic snapshot of counters: rest doesn't change 760 /* We need atomic snapshot of counters: rest doesn't change
771 * (other than comefrom, which userspace doesn't care 761 * (other than comefrom, which userspace doesn't care
@@ -783,11 +773,11 @@ static struct xt_counters *alloc_counters(struct xt_table *table)
783} 773}
784 774
785static int copy_entries_to_user(unsigned int total_size, 775static int copy_entries_to_user(unsigned int total_size,
786 struct xt_table *table, 776 const struct xt_table *table,
787 void __user *userptr) 777 void __user *userptr)
788{ 778{
789 unsigned int off, num; 779 unsigned int off, num;
790 struct arpt_entry *e; 780 const struct arpt_entry *e;
791 struct xt_counters *counters; 781 struct xt_counters *counters;
792 struct xt_table_info *private = table->private; 782 struct xt_table_info *private = table->private;
793 int ret = 0; 783 int ret = 0;
@@ -807,7 +797,7 @@ static int copy_entries_to_user(unsigned int total_size,
807 /* FIXME: use iterator macros --RR */ 797 /* FIXME: use iterator macros --RR */
808 /* ... then go back and fix counters and names */ 798 /* ... then go back and fix counters and names */
809 for (off = 0, num = 0; off < total_size; off += e->next_offset, num++){ 799 for (off = 0, num = 0; off < total_size; off += e->next_offset, num++){
810 struct arpt_entry_target *t; 800 const struct arpt_entry_target *t;
811 801
812 e = (struct arpt_entry *)(loc_cpu_entry + off); 802 e = (struct arpt_entry *)(loc_cpu_entry + off);
813 if (copy_to_user(userptr + off 803 if (copy_to_user(userptr + off
@@ -818,7 +808,7 @@ static int copy_entries_to_user(unsigned int total_size,
818 goto free_counters; 808 goto free_counters;
819 } 809 }
820 810
821 t = arpt_get_target(e); 811 t = arpt_get_target_c(e);
822 if (copy_to_user(userptr + off + e->target_offset 812 if (copy_to_user(userptr + off + e->target_offset
823 + offsetof(struct arpt_entry_target, 813 + offsetof(struct arpt_entry_target,
824 u.user.name), 814 u.user.name),
@@ -835,7 +825,7 @@ static int copy_entries_to_user(unsigned int total_size,
835} 825}
836 826
837#ifdef CONFIG_COMPAT 827#ifdef CONFIG_COMPAT
838static void compat_standard_from_user(void *dst, void *src) 828static void compat_standard_from_user(void *dst, const void *src)
839{ 829{
840 int v = *(compat_int_t *)src; 830 int v = *(compat_int_t *)src;
841 831
@@ -844,7 +834,7 @@ static void compat_standard_from_user(void *dst, void *src)
844 memcpy(dst, &v, sizeof(v)); 834 memcpy(dst, &v, sizeof(v));
845} 835}
846 836
847static int compat_standard_to_user(void __user *dst, void *src) 837static int compat_standard_to_user(void __user *dst, const void *src)
848{ 838{
849 compat_int_t cv = *(int *)src; 839 compat_int_t cv = *(int *)src;
850 840
@@ -853,18 +843,18 @@ static int compat_standard_to_user(void __user *dst, void *src)
853 return copy_to_user(dst, &cv, sizeof(cv)) ? -EFAULT : 0; 843 return copy_to_user(dst, &cv, sizeof(cv)) ? -EFAULT : 0;
854} 844}
855 845
856static int compat_calc_entry(struct arpt_entry *e, 846static int compat_calc_entry(const struct arpt_entry *e,
857 const struct xt_table_info *info, 847 const struct xt_table_info *info,
858 void *base, struct xt_table_info *newinfo) 848 const void *base, struct xt_table_info *newinfo)
859{ 849{
860 struct arpt_entry_target *t; 850 const struct arpt_entry_target *t;
861 unsigned int entry_offset; 851 unsigned int entry_offset;
862 int off, i, ret; 852 int off, i, ret;
863 853
864 off = sizeof(struct arpt_entry) - sizeof(struct compat_arpt_entry); 854 off = sizeof(struct arpt_entry) - sizeof(struct compat_arpt_entry);
865 entry_offset = (void *)e - base; 855 entry_offset = (void *)e - base;
866 856
867 t = arpt_get_target(e); 857 t = arpt_get_target_c(e);
868 off += xt_compat_target_offset(t->u.kernel.target); 858 off += xt_compat_target_offset(t->u.kernel.target);
869 newinfo->size -= off; 859 newinfo->size -= off;
870 ret = xt_compat_add_offset(NFPROTO_ARP, entry_offset, off); 860 ret = xt_compat_add_offset(NFPROTO_ARP, entry_offset, off);
@@ -885,7 +875,9 @@ static int compat_calc_entry(struct arpt_entry *e,
885static int compat_table_info(const struct xt_table_info *info, 875static int compat_table_info(const struct xt_table_info *info,
886 struct xt_table_info *newinfo) 876 struct xt_table_info *newinfo)
887{ 877{
878 struct arpt_entry *iter;
888 void *loc_cpu_entry; 879 void *loc_cpu_entry;
880 int ret;
889 881
890 if (!newinfo || !info) 882 if (!newinfo || !info)
891 return -EINVAL; 883 return -EINVAL;
@@ -894,13 +886,17 @@ static int compat_table_info(const struct xt_table_info *info,
894 memcpy(newinfo, info, offsetof(struct xt_table_info, entries)); 886 memcpy(newinfo, info, offsetof(struct xt_table_info, entries));
895 newinfo->initial_entries = 0; 887 newinfo->initial_entries = 0;
896 loc_cpu_entry = info->entries[raw_smp_processor_id()]; 888 loc_cpu_entry = info->entries[raw_smp_processor_id()];
897 return ARPT_ENTRY_ITERATE(loc_cpu_entry, info->size, 889 xt_entry_foreach(iter, loc_cpu_entry, info->size) {
898 compat_calc_entry, info, loc_cpu_entry, 890 ret = compat_calc_entry(iter, info, loc_cpu_entry, newinfo);
899 newinfo); 891 if (ret != 0)
892 return ret;
893 }
894 return 0;
900} 895}
901#endif 896#endif
902 897
903static int get_info(struct net *net, void __user *user, int *len, int compat) 898static int get_info(struct net *net, void __user *user,
899 const int *len, int compat)
904{ 900{
905 char name[ARPT_TABLE_MAXNAMELEN]; 901 char name[ARPT_TABLE_MAXNAMELEN];
906 struct xt_table *t; 902 struct xt_table *t;
@@ -925,10 +921,10 @@ static int get_info(struct net *net, void __user *user, int *len, int compat)
925 if (t && !IS_ERR(t)) { 921 if (t && !IS_ERR(t)) {
926 struct arpt_getinfo info; 922 struct arpt_getinfo info;
927 const struct xt_table_info *private = t->private; 923 const struct xt_table_info *private = t->private;
928
929#ifdef CONFIG_COMPAT 924#ifdef CONFIG_COMPAT
925 struct xt_table_info tmp;
926
930 if (compat) { 927 if (compat) {
931 struct xt_table_info tmp;
932 ret = compat_table_info(private, &tmp); 928 ret = compat_table_info(private, &tmp);
933 xt_compat_flush_offsets(NFPROTO_ARP); 929 xt_compat_flush_offsets(NFPROTO_ARP);
934 private = &tmp; 930 private = &tmp;
@@ -959,7 +955,7 @@ static int get_info(struct net *net, void __user *user, int *len, int compat)
959} 955}
960 956
961static int get_entries(struct net *net, struct arpt_get_entries __user *uptr, 957static int get_entries(struct net *net, struct arpt_get_entries __user *uptr,
962 int *len) 958 const int *len)
963{ 959{
964 int ret; 960 int ret;
965 struct arpt_get_entries get; 961 struct arpt_get_entries get;
@@ -1010,6 +1006,7 @@ static int __do_replace(struct net *net, const char *name,
1010 struct xt_table_info *oldinfo; 1006 struct xt_table_info *oldinfo;
1011 struct xt_counters *counters; 1007 struct xt_counters *counters;
1012 void *loc_cpu_old_entry; 1008 void *loc_cpu_old_entry;
1009 struct arpt_entry *iter;
1013 1010
1014 ret = 0; 1011 ret = 0;
1015 counters = vmalloc_node(num_counters * sizeof(struct xt_counters), 1012 counters = vmalloc_node(num_counters * sizeof(struct xt_counters),
@@ -1053,8 +1050,8 @@ static int __do_replace(struct net *net, const char *name,
1053 1050
1054 /* Decrease module usage counts and free resource */ 1051 /* Decrease module usage counts and free resource */
1055 loc_cpu_old_entry = oldinfo->entries[raw_smp_processor_id()]; 1052 loc_cpu_old_entry = oldinfo->entries[raw_smp_processor_id()];
1056 ARPT_ENTRY_ITERATE(loc_cpu_old_entry, oldinfo->size, cleanup_entry, 1053 xt_entry_foreach(iter, loc_cpu_old_entry, oldinfo->size)
1057 NULL); 1054 cleanup_entry(iter);
1058 1055
1059 xt_free_table_info(oldinfo); 1056 xt_free_table_info(oldinfo);
1060 if (copy_to_user(counters_ptr, counters, 1057 if (copy_to_user(counters_ptr, counters,
@@ -1073,12 +1070,14 @@ static int __do_replace(struct net *net, const char *name,
1073 return ret; 1070 return ret;
1074} 1071}
1075 1072
1076static int do_replace(struct net *net, void __user *user, unsigned int len) 1073static int do_replace(struct net *net, const void __user *user,
1074 unsigned int len)
1077{ 1075{
1078 int ret; 1076 int ret;
1079 struct arpt_replace tmp; 1077 struct arpt_replace tmp;
1080 struct xt_table_info *newinfo; 1078 struct xt_table_info *newinfo;
1081 void *loc_cpu_entry; 1079 void *loc_cpu_entry;
1080 struct arpt_entry *iter;
1082 1081
1083 if (copy_from_user(&tmp, user, sizeof(tmp)) != 0) 1082 if (copy_from_user(&tmp, user, sizeof(tmp)) != 0)
1084 return -EFAULT; 1083 return -EFAULT;
@@ -1099,9 +1098,7 @@ static int do_replace(struct net *net, void __user *user, unsigned int len)
1099 goto free_newinfo; 1098 goto free_newinfo;
1100 } 1099 }
1101 1100
1102 ret = translate_table(tmp.name, tmp.valid_hooks, 1101 ret = translate_table(newinfo, loc_cpu_entry, &tmp);
1103 newinfo, loc_cpu_entry, tmp.size, tmp.num_entries,
1104 tmp.hook_entry, tmp.underflow);
1105 if (ret != 0) 1102 if (ret != 0)
1106 goto free_newinfo; 1103 goto free_newinfo;
1107 1104
@@ -1114,27 +1111,15 @@ static int do_replace(struct net *net, void __user *user, unsigned int len)
1114 return 0; 1111 return 0;
1115 1112
1116 free_newinfo_untrans: 1113 free_newinfo_untrans:
1117 ARPT_ENTRY_ITERATE(loc_cpu_entry, newinfo->size, cleanup_entry, NULL); 1114 xt_entry_foreach(iter, loc_cpu_entry, newinfo->size)
1115 cleanup_entry(iter);
1118 free_newinfo: 1116 free_newinfo:
1119 xt_free_table_info(newinfo); 1117 xt_free_table_info(newinfo);
1120 return ret; 1118 return ret;
1121} 1119}
1122 1120
1123/* We're lazy, and add to the first CPU; overflow works its fey magic 1121static int do_add_counters(struct net *net, const void __user *user,
1124 * and everything is OK. */ 1122 unsigned int len, int compat)
1125static int
1126add_counter_to_entry(struct arpt_entry *e,
1127 const struct xt_counters addme[],
1128 unsigned int *i)
1129{
1130 ADD_COUNTER(e->counters, addme[*i].bcnt, addme[*i].pcnt);
1131
1132 (*i)++;
1133 return 0;
1134}
1135
1136static int do_add_counters(struct net *net, void __user *user, unsigned int len,
1137 int compat)
1138{ 1123{
1139 unsigned int i, curcpu; 1124 unsigned int i, curcpu;
1140 struct xt_counters_info tmp; 1125 struct xt_counters_info tmp;
@@ -1147,6 +1132,7 @@ static int do_add_counters(struct net *net, void __user *user, unsigned int len,
1147 const struct xt_table_info *private; 1132 const struct xt_table_info *private;
1148 int ret = 0; 1133 int ret = 0;
1149 void *loc_cpu_entry; 1134 void *loc_cpu_entry;
1135 struct arpt_entry *iter;
1150#ifdef CONFIG_COMPAT 1136#ifdef CONFIG_COMPAT
1151 struct compat_xt_counters_info compat_tmp; 1137 struct compat_xt_counters_info compat_tmp;
1152 1138
@@ -1204,11 +1190,10 @@ static int do_add_counters(struct net *net, void __user *user, unsigned int len,
1204 curcpu = smp_processor_id(); 1190 curcpu = smp_processor_id();
1205 loc_cpu_entry = private->entries[curcpu]; 1191 loc_cpu_entry = private->entries[curcpu];
1206 xt_info_wrlock(curcpu); 1192 xt_info_wrlock(curcpu);
1207 ARPT_ENTRY_ITERATE(loc_cpu_entry, 1193 xt_entry_foreach(iter, loc_cpu_entry, private->size) {
1208 private->size, 1194 ADD_COUNTER(iter->counters, paddc[i].bcnt, paddc[i].pcnt);
1209 add_counter_to_entry, 1195 ++i;
1210 paddc, 1196 }
1211 &i);
1212 xt_info_wrunlock(curcpu); 1197 xt_info_wrunlock(curcpu);
1213 unlock_up_free: 1198 unlock_up_free:
1214 local_bh_enable(); 1199 local_bh_enable();
@@ -1221,28 +1206,22 @@ static int do_add_counters(struct net *net, void __user *user, unsigned int len,
1221} 1206}
1222 1207
1223#ifdef CONFIG_COMPAT 1208#ifdef CONFIG_COMPAT
1224static inline int 1209static inline void compat_release_entry(struct compat_arpt_entry *e)
1225compat_release_entry(struct compat_arpt_entry *e, unsigned int *i)
1226{ 1210{
1227 struct arpt_entry_target *t; 1211 struct arpt_entry_target *t;
1228 1212
1229 if (i && (*i)-- == 0)
1230 return 1;
1231
1232 t = compat_arpt_get_target(e); 1213 t = compat_arpt_get_target(e);
1233 module_put(t->u.kernel.target->me); 1214 module_put(t->u.kernel.target->me);
1234 return 0;
1235} 1215}
1236 1216
1237static inline int 1217static inline int
1238check_compat_entry_size_and_hooks(struct compat_arpt_entry *e, 1218check_compat_entry_size_and_hooks(struct compat_arpt_entry *e,
1239 struct xt_table_info *newinfo, 1219 struct xt_table_info *newinfo,
1240 unsigned int *size, 1220 unsigned int *size,
1241 unsigned char *base, 1221 const unsigned char *base,
1242 unsigned char *limit, 1222 const unsigned char *limit,
1243 unsigned int *hook_entries, 1223 const unsigned int *hook_entries,
1244 unsigned int *underflows, 1224 const unsigned int *underflows,
1245 unsigned int *i,
1246 const char *name) 1225 const char *name)
1247{ 1226{
1248 struct arpt_entry_target *t; 1227 struct arpt_entry_target *t;
@@ -1251,8 +1230,8 @@ check_compat_entry_size_and_hooks(struct compat_arpt_entry *e,
1251 int ret, off, h; 1230 int ret, off, h;
1252 1231
1253 duprintf("check_compat_entry_size_and_hooks %p\n", e); 1232 duprintf("check_compat_entry_size_and_hooks %p\n", e);
1254 if ((unsigned long)e % __alignof__(struct compat_arpt_entry) != 0 1233 if ((unsigned long)e % __alignof__(struct compat_arpt_entry) != 0 ||
1255 || (unsigned char *)e + sizeof(struct compat_arpt_entry) >= limit) { 1234 (unsigned char *)e + sizeof(struct compat_arpt_entry) >= limit) {
1256 duprintf("Bad offset %p, limit = %p\n", e, limit); 1235 duprintf("Bad offset %p, limit = %p\n", e, limit);
1257 return -EINVAL; 1236 return -EINVAL;
1258 } 1237 }
@@ -1302,8 +1281,6 @@ check_compat_entry_size_and_hooks(struct compat_arpt_entry *e,
1302 /* Clear counters and comefrom */ 1281 /* Clear counters and comefrom */
1303 memset(&e->counters, 0, sizeof(e->counters)); 1282 memset(&e->counters, 0, sizeof(e->counters));
1304 e->comefrom = 0; 1283 e->comefrom = 0;
1305
1306 (*i)++;
1307 return 0; 1284 return 0;
1308 1285
1309release_target: 1286release_target:
@@ -1347,19 +1324,6 @@ compat_copy_entry_from_user(struct compat_arpt_entry *e, void **dstptr,
1347 return ret; 1324 return ret;
1348} 1325}
1349 1326
1350static inline int compat_check_entry(struct arpt_entry *e, const char *name,
1351 unsigned int *i)
1352{
1353 int ret;
1354
1355 ret = check_target(e, name);
1356 if (ret)
1357 return ret;
1358
1359 (*i)++;
1360 return 0;
1361}
1362
1363static int translate_compat_table(const char *name, 1327static int translate_compat_table(const char *name,
1364 unsigned int valid_hooks, 1328 unsigned int valid_hooks,
1365 struct xt_table_info **pinfo, 1329 struct xt_table_info **pinfo,
@@ -1372,8 +1336,10 @@ static int translate_compat_table(const char *name,
1372 unsigned int i, j; 1336 unsigned int i, j;
1373 struct xt_table_info *newinfo, *info; 1337 struct xt_table_info *newinfo, *info;
1374 void *pos, *entry0, *entry1; 1338 void *pos, *entry0, *entry1;
1339 struct compat_arpt_entry *iter0;
1340 struct arpt_entry *iter1;
1375 unsigned int size; 1341 unsigned int size;
1376 int ret; 1342 int ret = 0;
1377 1343
1378 info = *pinfo; 1344 info = *pinfo;
1379 entry0 = *pentry0; 1345 entry0 = *pentry0;
@@ -1390,13 +1356,17 @@ static int translate_compat_table(const char *name,
1390 j = 0; 1356 j = 0;
1391 xt_compat_lock(NFPROTO_ARP); 1357 xt_compat_lock(NFPROTO_ARP);
1392 /* Walk through entries, checking offsets. */ 1358 /* Walk through entries, checking offsets. */
1393 ret = COMPAT_ARPT_ENTRY_ITERATE(entry0, total_size, 1359 xt_entry_foreach(iter0, entry0, total_size) {
1394 check_compat_entry_size_and_hooks, 1360 ret = check_compat_entry_size_and_hooks(iter0, info, &size,
1395 info, &size, entry0, 1361 entry0,
1396 entry0 + total_size, 1362 entry0 + total_size,
1397 hook_entries, underflows, &j, name); 1363 hook_entries,
1398 if (ret != 0) 1364 underflows,
1399 goto out_unlock; 1365 name);
1366 if (ret != 0)
1367 goto out_unlock;
1368 ++j;
1369 }
1400 1370
1401 ret = -EINVAL; 1371 ret = -EINVAL;
1402 if (j != number) { 1372 if (j != number) {
@@ -1435,9 +1405,12 @@ static int translate_compat_table(const char *name,
1435 entry1 = newinfo->entries[raw_smp_processor_id()]; 1405 entry1 = newinfo->entries[raw_smp_processor_id()];
1436 pos = entry1; 1406 pos = entry1;
1437 size = total_size; 1407 size = total_size;
1438 ret = COMPAT_ARPT_ENTRY_ITERATE(entry0, total_size, 1408 xt_entry_foreach(iter0, entry0, total_size) {
1439 compat_copy_entry_from_user, 1409 ret = compat_copy_entry_from_user(iter0, &pos, &size,
1440 &pos, &size, name, newinfo, entry1); 1410 name, newinfo, entry1);
1411 if (ret != 0)
1412 break;
1413 }
1441 xt_compat_flush_offsets(NFPROTO_ARP); 1414 xt_compat_flush_offsets(NFPROTO_ARP);
1442 xt_compat_unlock(NFPROTO_ARP); 1415 xt_compat_unlock(NFPROTO_ARP);
1443 if (ret) 1416 if (ret)
@@ -1448,13 +1421,32 @@ static int translate_compat_table(const char *name,
1448 goto free_newinfo; 1421 goto free_newinfo;
1449 1422
1450 i = 0; 1423 i = 0;
1451 ret = ARPT_ENTRY_ITERATE(entry1, newinfo->size, compat_check_entry, 1424 xt_entry_foreach(iter1, entry1, newinfo->size) {
1452 name, &i); 1425 ret = check_target(iter1, name);
1426 if (ret != 0)
1427 break;
1428 ++i;
1429 }
1453 if (ret) { 1430 if (ret) {
1431 /*
1432 * The first i matches need cleanup_entry (calls ->destroy)
1433 * because they had called ->check already. The other j-i
1434 * entries need only release.
1435 */
1436 int skip = i;
1454 j -= i; 1437 j -= i;
1455 COMPAT_ARPT_ENTRY_ITERATE_CONTINUE(entry0, newinfo->size, i, 1438 xt_entry_foreach(iter0, entry0, newinfo->size) {
1456 compat_release_entry, &j); 1439 if (skip-- > 0)
1457 ARPT_ENTRY_ITERATE(entry1, newinfo->size, cleanup_entry, &i); 1440 continue;
1441 if (j-- == 0)
1442 break;
1443 compat_release_entry(iter0);
1444 }
1445 xt_entry_foreach(iter1, entry1, newinfo->size) {
1446 if (i-- == 0)
1447 break;
1448 cleanup_entry(iter1);
1449 }
1458 xt_free_table_info(newinfo); 1450 xt_free_table_info(newinfo);
1459 return ret; 1451 return ret;
1460 } 1452 }
@@ -1472,7 +1464,11 @@ static int translate_compat_table(const char *name,
1472free_newinfo: 1464free_newinfo:
1473 xt_free_table_info(newinfo); 1465 xt_free_table_info(newinfo);
1474out: 1466out:
1475 COMPAT_ARPT_ENTRY_ITERATE(entry0, total_size, compat_release_entry, &j); 1467 xt_entry_foreach(iter0, entry0, total_size) {
1468 if (j-- == 0)
1469 break;
1470 compat_release_entry(iter0);
1471 }
1476 return ret; 1472 return ret;
1477out_unlock: 1473out_unlock:
1478 xt_compat_flush_offsets(NFPROTO_ARP); 1474 xt_compat_flush_offsets(NFPROTO_ARP);
@@ -1499,6 +1495,7 @@ static int compat_do_replace(struct net *net, void __user *user,
1499 struct compat_arpt_replace tmp; 1495 struct compat_arpt_replace tmp;
1500 struct xt_table_info *newinfo; 1496 struct xt_table_info *newinfo;
1501 void *loc_cpu_entry; 1497 void *loc_cpu_entry;
1498 struct arpt_entry *iter;
1502 1499
1503 if (copy_from_user(&tmp, user, sizeof(tmp)) != 0) 1500 if (copy_from_user(&tmp, user, sizeof(tmp)) != 0)
1504 return -EFAULT; 1501 return -EFAULT;
@@ -1536,7 +1533,8 @@ static int compat_do_replace(struct net *net, void __user *user,
1536 return 0; 1533 return 0;
1537 1534
1538 free_newinfo_untrans: 1535 free_newinfo_untrans:
1539 ARPT_ENTRY_ITERATE(loc_cpu_entry, newinfo->size, cleanup_entry, NULL); 1536 xt_entry_foreach(iter, loc_cpu_entry, newinfo->size)
1537 cleanup_entry(iter);
1540 free_newinfo: 1538 free_newinfo:
1541 xt_free_table_info(newinfo); 1539 xt_free_table_info(newinfo);
1542 return ret; 1540 return ret;
@@ -1570,7 +1568,7 @@ static int compat_do_arpt_set_ctl(struct sock *sk, int cmd, void __user *user,
1570static int compat_copy_entry_to_user(struct arpt_entry *e, void __user **dstptr, 1568static int compat_copy_entry_to_user(struct arpt_entry *e, void __user **dstptr,
1571 compat_uint_t *size, 1569 compat_uint_t *size,
1572 struct xt_counters *counters, 1570 struct xt_counters *counters,
1573 unsigned int *i) 1571 unsigned int i)
1574{ 1572{
1575 struct arpt_entry_target *t; 1573 struct arpt_entry_target *t;
1576 struct compat_arpt_entry __user *ce; 1574 struct compat_arpt_entry __user *ce;
@@ -1578,14 +1576,12 @@ static int compat_copy_entry_to_user(struct arpt_entry *e, void __user **dstptr,
1578 compat_uint_t origsize; 1576 compat_uint_t origsize;
1579 int ret; 1577 int ret;
1580 1578
1581 ret = -EFAULT;
1582 origsize = *size; 1579 origsize = *size;
1583 ce = (struct compat_arpt_entry __user *)*dstptr; 1580 ce = (struct compat_arpt_entry __user *)*dstptr;
1584 if (copy_to_user(ce, e, sizeof(struct arpt_entry))) 1581 if (copy_to_user(ce, e, sizeof(struct arpt_entry)) != 0 ||
1585 goto out; 1582 copy_to_user(&ce->counters, &counters[i],
1586 1583 sizeof(counters[i])) != 0)
1587 if (copy_to_user(&ce->counters, &counters[*i], sizeof(counters[*i]))) 1584 return -EFAULT;
1588 goto out;
1589 1585
1590 *dstptr += sizeof(struct compat_arpt_entry); 1586 *dstptr += sizeof(struct compat_arpt_entry);
1591 *size -= sizeof(struct arpt_entry) - sizeof(struct compat_arpt_entry); 1587 *size -= sizeof(struct arpt_entry) - sizeof(struct compat_arpt_entry);
@@ -1595,18 +1591,12 @@ static int compat_copy_entry_to_user(struct arpt_entry *e, void __user **dstptr,
1595 t = arpt_get_target(e); 1591 t = arpt_get_target(e);
1596 ret = xt_compat_target_to_user(t, dstptr, size); 1592 ret = xt_compat_target_to_user(t, dstptr, size);
1597 if (ret) 1593 if (ret)
1598 goto out; 1594 return ret;
1599 ret = -EFAULT;
1600 next_offset = e->next_offset - (origsize - *size); 1595 next_offset = e->next_offset - (origsize - *size);
1601 if (put_user(target_offset, &ce->target_offset)) 1596 if (put_user(target_offset, &ce->target_offset) != 0 ||
1602 goto out; 1597 put_user(next_offset, &ce->next_offset) != 0)
1603 if (put_user(next_offset, &ce->next_offset)) 1598 return -EFAULT;
1604 goto out;
1605
1606 (*i)++;
1607 return 0; 1599 return 0;
1608out:
1609 return ret;
1610} 1600}
1611 1601
1612static int compat_copy_entries_to_user(unsigned int total_size, 1602static int compat_copy_entries_to_user(unsigned int total_size,
@@ -1620,6 +1610,7 @@ static int compat_copy_entries_to_user(unsigned int total_size,
1620 int ret = 0; 1610 int ret = 0;
1621 void *loc_cpu_entry; 1611 void *loc_cpu_entry;
1622 unsigned int i = 0; 1612 unsigned int i = 0;
1613 struct arpt_entry *iter;
1623 1614
1624 counters = alloc_counters(table); 1615 counters = alloc_counters(table);
1625 if (IS_ERR(counters)) 1616 if (IS_ERR(counters))
@@ -1629,9 +1620,12 @@ static int compat_copy_entries_to_user(unsigned int total_size,
1629 loc_cpu_entry = private->entries[raw_smp_processor_id()]; 1620 loc_cpu_entry = private->entries[raw_smp_processor_id()];
1630 pos = userptr; 1621 pos = userptr;
1631 size = total_size; 1622 size = total_size;
1632 ret = ARPT_ENTRY_ITERATE(loc_cpu_entry, total_size, 1623 xt_entry_foreach(iter, loc_cpu_entry, total_size) {
1633 compat_copy_entry_to_user, 1624 ret = compat_copy_entry_to_user(iter, &pos,
1634 &pos, &size, counters, &i); 1625 &size, counters, i++);
1626 if (ret != 0)
1627 break;
1628 }
1635 vfree(counters); 1629 vfree(counters);
1636 return ret; 1630 return ret;
1637} 1631}
@@ -1799,12 +1793,7 @@ struct xt_table *arpt_register_table(struct net *net,
1799 loc_cpu_entry = newinfo->entries[raw_smp_processor_id()]; 1793 loc_cpu_entry = newinfo->entries[raw_smp_processor_id()];
1800 memcpy(loc_cpu_entry, repl->entries, repl->size); 1794 memcpy(loc_cpu_entry, repl->entries, repl->size);
1801 1795
1802 ret = translate_table(table->name, table->valid_hooks, 1796 ret = translate_table(newinfo, loc_cpu_entry, repl);
1803 newinfo, loc_cpu_entry, repl->size,
1804 repl->num_entries,
1805 repl->hook_entry,
1806 repl->underflow);
1807
1808 duprintf("arpt_register_table: translate table gives %d\n", ret); 1797 duprintf("arpt_register_table: translate table gives %d\n", ret);
1809 if (ret != 0) 1798 if (ret != 0)
1810 goto out_free; 1799 goto out_free;
@@ -1827,13 +1816,14 @@ void arpt_unregister_table(struct xt_table *table)
1827 struct xt_table_info *private; 1816 struct xt_table_info *private;
1828 void *loc_cpu_entry; 1817 void *loc_cpu_entry;
1829 struct module *table_owner = table->me; 1818 struct module *table_owner = table->me;
1819 struct arpt_entry *iter;
1830 1820
1831 private = xt_unregister_table(table); 1821 private = xt_unregister_table(table);
1832 1822
1833 /* Decrease module usage counts and free resources */ 1823 /* Decrease module usage counts and free resources */
1834 loc_cpu_entry = private->entries[raw_smp_processor_id()]; 1824 loc_cpu_entry = private->entries[raw_smp_processor_id()];
1835 ARPT_ENTRY_ITERATE(loc_cpu_entry, private->size, 1825 xt_entry_foreach(iter, loc_cpu_entry, private->size)
1836 cleanup_entry, NULL); 1826 cleanup_entry(iter);
1837 if (private->number > private->initial_entries) 1827 if (private->number > private->initial_entries)
1838 module_put(table_owner); 1828 module_put(table_owner);
1839 xt_free_table_info(private); 1829 xt_free_table_info(private);
diff --git a/net/ipv4/netfilter/arptable_filter.c b/net/ipv4/netfilter/arptable_filter.c
index 97337601827a..79ca5e70d497 100644
--- a/net/ipv4/netfilter/arptable_filter.c
+++ b/net/ipv4/netfilter/arptable_filter.c
@@ -6,7 +6,9 @@
6 */ 6 */
7 7
8#include <linux/module.h> 8#include <linux/module.h>
9#include <linux/netfilter/x_tables.h>
9#include <linux/netfilter_arp/arp_tables.h> 10#include <linux/netfilter_arp/arp_tables.h>
11#include <linux/slab.h>
10 12
11MODULE_LICENSE("GPL"); 13MODULE_LICENSE("GPL");
12MODULE_AUTHOR("David S. Miller <davem@redhat.com>"); 14MODULE_AUTHOR("David S. Miller <davem@redhat.com>");
@@ -15,93 +17,37 @@ MODULE_DESCRIPTION("arptables filter table");
15#define FILTER_VALID_HOOKS ((1 << NF_ARP_IN) | (1 << NF_ARP_OUT) | \ 17#define FILTER_VALID_HOOKS ((1 << NF_ARP_IN) | (1 << NF_ARP_OUT) | \
16 (1 << NF_ARP_FORWARD)) 18 (1 << NF_ARP_FORWARD))
17 19
18static const struct
19{
20 struct arpt_replace repl;
21 struct arpt_standard entries[3];
22 struct arpt_error term;
23} initial_table __net_initdata = {
24 .repl = {
25 .name = "filter",
26 .valid_hooks = FILTER_VALID_HOOKS,
27 .num_entries = 4,
28 .size = sizeof(struct arpt_standard) * 3 + sizeof(struct arpt_error),
29 .hook_entry = {
30 [NF_ARP_IN] = 0,
31 [NF_ARP_OUT] = sizeof(struct arpt_standard),
32 [NF_ARP_FORWARD] = 2 * sizeof(struct arpt_standard),
33 },
34 .underflow = {
35 [NF_ARP_IN] = 0,
36 [NF_ARP_OUT] = sizeof(struct arpt_standard),
37 [NF_ARP_FORWARD] = 2 * sizeof(struct arpt_standard),
38 },
39 },
40 .entries = {
41 ARPT_STANDARD_INIT(NF_ACCEPT), /* ARP_IN */
42 ARPT_STANDARD_INIT(NF_ACCEPT), /* ARP_OUT */
43 ARPT_STANDARD_INIT(NF_ACCEPT), /* ARP_FORWARD */
44 },
45 .term = ARPT_ERROR_INIT,
46};
47
48static const struct xt_table packet_filter = { 20static const struct xt_table packet_filter = {
49 .name = "filter", 21 .name = "filter",
50 .valid_hooks = FILTER_VALID_HOOKS, 22 .valid_hooks = FILTER_VALID_HOOKS,
51 .me = THIS_MODULE, 23 .me = THIS_MODULE,
52 .af = NFPROTO_ARP, 24 .af = NFPROTO_ARP,
25 .priority = NF_IP_PRI_FILTER,
53}; 26};
54 27
55/* The work comes in here from netfilter.c */ 28/* The work comes in here from netfilter.c */
56static unsigned int arpt_in_hook(unsigned int hook, 29static unsigned int
57 struct sk_buff *skb, 30arptable_filter_hook(unsigned int hook, struct sk_buff *skb,
58 const struct net_device *in, 31 const struct net_device *in, const struct net_device *out,
59 const struct net_device *out, 32 int (*okfn)(struct sk_buff *))
60 int (*okfn)(struct sk_buff *))
61{ 33{
62 return arpt_do_table(skb, hook, in, out, 34 const struct net *net = dev_net((in != NULL) ? in : out);
63 dev_net(in)->ipv4.arptable_filter);
64}
65 35
66static unsigned int arpt_out_hook(unsigned int hook, 36 return arpt_do_table(skb, hook, in, out, net->ipv4.arptable_filter);
67 struct sk_buff *skb,
68 const struct net_device *in,
69 const struct net_device *out,
70 int (*okfn)(struct sk_buff *))
71{
72 return arpt_do_table(skb, hook, in, out,
73 dev_net(out)->ipv4.arptable_filter);
74} 37}
75 38
76static struct nf_hook_ops arpt_ops[] __read_mostly = { 39static struct nf_hook_ops *arpfilter_ops __read_mostly;
77 {
78 .hook = arpt_in_hook,
79 .owner = THIS_MODULE,
80 .pf = NFPROTO_ARP,
81 .hooknum = NF_ARP_IN,
82 .priority = NF_IP_PRI_FILTER,
83 },
84 {
85 .hook = arpt_out_hook,
86 .owner = THIS_MODULE,
87 .pf = NFPROTO_ARP,
88 .hooknum = NF_ARP_OUT,
89 .priority = NF_IP_PRI_FILTER,
90 },
91 {
92 .hook = arpt_in_hook,
93 .owner = THIS_MODULE,
94 .pf = NFPROTO_ARP,
95 .hooknum = NF_ARP_FORWARD,
96 .priority = NF_IP_PRI_FILTER,
97 },
98};
99 40
100static int __net_init arptable_filter_net_init(struct net *net) 41static int __net_init arptable_filter_net_init(struct net *net)
101{ 42{
102 /* Register table */ 43 struct arpt_replace *repl;
44
45 repl = arpt_alloc_initial_table(&packet_filter);
46 if (repl == NULL)
47 return -ENOMEM;
103 net->ipv4.arptable_filter = 48 net->ipv4.arptable_filter =
104 arpt_register_table(net, &packet_filter, &initial_table.repl); 49 arpt_register_table(net, &packet_filter, repl);
50 kfree(repl);
105 if (IS_ERR(net->ipv4.arptable_filter)) 51 if (IS_ERR(net->ipv4.arptable_filter))
106 return PTR_ERR(net->ipv4.arptable_filter); 52 return PTR_ERR(net->ipv4.arptable_filter);
107 return 0; 53 return 0;
@@ -125,9 +71,11 @@ static int __init arptable_filter_init(void)
125 if (ret < 0) 71 if (ret < 0)
126 return ret; 72 return ret;
127 73
128 ret = nf_register_hooks(arpt_ops, ARRAY_SIZE(arpt_ops)); 74 arpfilter_ops = xt_hook_link(&packet_filter, arptable_filter_hook);
129 if (ret < 0) 75 if (IS_ERR(arpfilter_ops)) {
76 ret = PTR_ERR(arpfilter_ops);
130 goto cleanup_table; 77 goto cleanup_table;
78 }
131 return ret; 79 return ret;
132 80
133cleanup_table: 81cleanup_table:
@@ -137,7 +85,7 @@ cleanup_table:
137 85
138static void __exit arptable_filter_fini(void) 86static void __exit arptable_filter_fini(void)
139{ 87{
140 nf_unregister_hooks(arpt_ops, ARRAY_SIZE(arpt_ops)); 88 xt_hook_unlink(&packet_filter, arpfilter_ops);
141 unregister_pernet_subsys(&arptable_filter_net_ops); 89 unregister_pernet_subsys(&arptable_filter_net_ops);
142} 90}
143 91
diff --git a/net/ipv4/netfilter/ip_queue.c b/net/ipv4/netfilter/ip_queue.c
index c156db215987..e2787048aa0a 100644
--- a/net/ipv4/netfilter/ip_queue.c
+++ b/net/ipv4/netfilter/ip_queue.c
@@ -26,6 +26,7 @@
26#include <linux/security.h> 26#include <linux/security.h>
27#include <linux/net.h> 27#include <linux/net.h>
28#include <linux/mutex.h> 28#include <linux/mutex.h>
29#include <linux/slab.h>
29#include <net/net_namespace.h> 30#include <net/net_namespace.h>
30#include <net/sock.h> 31#include <net/sock.h>
31#include <net/route.h> 32#include <net/route.h>
@@ -497,10 +498,9 @@ ipq_rcv_nl_event(struct notifier_block *this,
497{ 498{
498 struct netlink_notify *n = ptr; 499 struct netlink_notify *n = ptr;
499 500
500 if (event == NETLINK_URELEASE && 501 if (event == NETLINK_URELEASE && n->protocol == NETLINK_FIREWALL) {
501 n->protocol == NETLINK_FIREWALL && n->pid) {
502 write_lock_bh(&queue_lock); 502 write_lock_bh(&queue_lock);
503 if ((n->net == &init_net) && (n->pid == peer_pid)) 503 if ((net_eq(n->net, &init_net)) && (n->pid == peer_pid))
504 __ipq_reset(); 504 __ipq_reset();
505 write_unlock_bh(&queue_lock); 505 write_unlock_bh(&queue_lock);
506 } 506 }
@@ -516,14 +516,13 @@ static struct ctl_table_header *ipq_sysctl_header;
516 516
517static ctl_table ipq_table[] = { 517static ctl_table ipq_table[] = {
518 { 518 {
519 .ctl_name = NET_IPQ_QMAX,
520 .procname = NET_IPQ_QMAX_NAME, 519 .procname = NET_IPQ_QMAX_NAME,
521 .data = &queue_maxlen, 520 .data = &queue_maxlen,
522 .maxlen = sizeof(queue_maxlen), 521 .maxlen = sizeof(queue_maxlen),
523 .mode = 0644, 522 .mode = 0644,
524 .proc_handler = proc_dointvec 523 .proc_handler = proc_dointvec
525 }, 524 },
526 { .ctl_name = 0 } 525 { }
527}; 526};
528#endif 527#endif
529 528
@@ -622,7 +621,7 @@ cleanup_netlink_notifier:
622static void __exit ip_queue_fini(void) 621static void __exit ip_queue_fini(void)
623{ 622{
624 nf_unregister_queue_handlers(&nfqh); 623 nf_unregister_queue_handlers(&nfqh);
625 synchronize_net(); 624
626 ipq_flush(NULL, 0); 625 ipq_flush(NULL, 0);
627 626
628#ifdef CONFIG_SYSCTL 627#ifdef CONFIG_SYSCTL
diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
index cde755d5eeab..b29c66df8d1f 100644
--- a/net/ipv4/netfilter/ip_tables.c
+++ b/net/ipv4/netfilter/ip_tables.c
@@ -28,6 +28,7 @@
28#include <linux/netfilter/x_tables.h> 28#include <linux/netfilter/x_tables.h>
29#include <linux/netfilter_ipv4/ip_tables.h> 29#include <linux/netfilter_ipv4/ip_tables.h>
30#include <net/netfilter/nf_log.h> 30#include <net/netfilter/nf_log.h>
31#include "../../netfilter/xt_repldata.h"
31 32
32MODULE_LICENSE("GPL"); 33MODULE_LICENSE("GPL");
33MODULE_AUTHOR("Netfilter Core Team <coreteam@netfilter.org>"); 34MODULE_AUTHOR("Netfilter Core Team <coreteam@netfilter.org>");
@@ -66,6 +67,12 @@ do { \
66#define inline 67#define inline
67#endif 68#endif
68 69
70void *ipt_alloc_initial_table(const struct xt_table *info)
71{
72 return xt_alloc_initial_table(ipt, IPT);
73}
74EXPORT_SYMBOL_GPL(ipt_alloc_initial_table);
75
69/* 76/*
70 We keep a set of rules for each CPU, so we can avoid write-locking 77 We keep a set of rules for each CPU, so we can avoid write-locking
71 them in the softirq when updating the counters and therefore 78 them in the softirq when updating the counters and therefore
@@ -89,9 +96,9 @@ ip_packet_match(const struct iphdr *ip,
89#define FWINV(bool, invflg) ((bool) ^ !!(ipinfo->invflags & (invflg))) 96#define FWINV(bool, invflg) ((bool) ^ !!(ipinfo->invflags & (invflg)))
90 97
91 if (FWINV((ip->saddr&ipinfo->smsk.s_addr) != ipinfo->src.s_addr, 98 if (FWINV((ip->saddr&ipinfo->smsk.s_addr) != ipinfo->src.s_addr,
92 IPT_INV_SRCIP) 99 IPT_INV_SRCIP) ||
93 || FWINV((ip->daddr&ipinfo->dmsk.s_addr) != ipinfo->dst.s_addr, 100 FWINV((ip->daddr&ipinfo->dmsk.s_addr) != ipinfo->dst.s_addr,
94 IPT_INV_DSTIP)) { 101 IPT_INV_DSTIP)) {
95 dprintf("Source or dest mismatch.\n"); 102 dprintf("Source or dest mismatch.\n");
96 103
97 dprintf("SRC: %pI4. Mask: %pI4. Target: %pI4.%s\n", 104 dprintf("SRC: %pI4. Mask: %pI4. Target: %pI4.%s\n",
@@ -122,8 +129,8 @@ ip_packet_match(const struct iphdr *ip,
122 } 129 }
123 130
124 /* Check specific protocol */ 131 /* Check specific protocol */
125 if (ipinfo->proto 132 if (ipinfo->proto &&
126 && FWINV(ip->protocol != ipinfo->proto, IPT_INV_PROTO)) { 133 FWINV(ip->protocol != ipinfo->proto, IPT_INV_PROTO)) {
127 dprintf("Packet protocol %hi does not match %hi.%s\n", 134 dprintf("Packet protocol %hi does not match %hi.%s\n",
128 ip->protocol, ipinfo->proto, 135 ip->protocol, ipinfo->proto,
129 ipinfo->invflags&IPT_INV_PROTO ? " (INV)":""); 136 ipinfo->invflags&IPT_INV_PROTO ? " (INV)":"");
@@ -169,7 +176,7 @@ ipt_error(struct sk_buff *skb, const struct xt_target_param *par)
169 176
170/* Performance critical - called for every packet */ 177/* Performance critical - called for every packet */
171static inline bool 178static inline bool
172do_match(struct ipt_entry_match *m, const struct sk_buff *skb, 179do_match(const struct ipt_entry_match *m, const struct sk_buff *skb,
173 struct xt_match_param *par) 180 struct xt_match_param *par)
174{ 181{
175 par->match = m->u.kernel.match; 182 par->match = m->u.kernel.match;
@@ -184,7 +191,7 @@ do_match(struct ipt_entry_match *m, const struct sk_buff *skb,
184 191
185/* Performance critical */ 192/* Performance critical */
186static inline struct ipt_entry * 193static inline struct ipt_entry *
187get_entry(void *base, unsigned int offset) 194get_entry(const void *base, unsigned int offset)
188{ 195{
189 return (struct ipt_entry *)(base + offset); 196 return (struct ipt_entry *)(base + offset);
190} 197}
@@ -199,6 +206,13 @@ static inline bool unconditional(const struct ipt_ip *ip)
199#undef FWINV 206#undef FWINV
200} 207}
201 208
209/* for const-correctness */
210static inline const struct ipt_entry_target *
211ipt_get_target_c(const struct ipt_entry *e)
212{
213 return ipt_get_target((struct ipt_entry *)e);
214}
215
202#if defined(CONFIG_NETFILTER_XT_TARGET_TRACE) || \ 216#if defined(CONFIG_NETFILTER_XT_TARGET_TRACE) || \
203 defined(CONFIG_NETFILTER_XT_TARGET_TRACE_MODULE) 217 defined(CONFIG_NETFILTER_XT_TARGET_TRACE_MODULE)
204static const char *const hooknames[] = { 218static const char *const hooknames[] = {
@@ -233,11 +247,11 @@ static struct nf_loginfo trace_loginfo = {
233 247
234/* Mildly perf critical (only if packet tracing is on) */ 248/* Mildly perf critical (only if packet tracing is on) */
235static inline int 249static inline int
236get_chainname_rulenum(struct ipt_entry *s, struct ipt_entry *e, 250get_chainname_rulenum(const struct ipt_entry *s, const struct ipt_entry *e,
237 const char *hookname, const char **chainname, 251 const char *hookname, const char **chainname,
238 const char **comment, unsigned int *rulenum) 252 const char **comment, unsigned int *rulenum)
239{ 253{
240 struct ipt_standard_target *t = (void *)ipt_get_target(s); 254 const struct ipt_standard_target *t = (void *)ipt_get_target_c(s);
241 255
242 if (strcmp(t->target.u.kernel.target->name, IPT_ERROR_TARGET) == 0) { 256 if (strcmp(t->target.u.kernel.target->name, IPT_ERROR_TARGET) == 0) {
243 /* Head of user chain: ERROR target with chainname */ 257 /* Head of user chain: ERROR target with chainname */
@@ -246,11 +260,11 @@ get_chainname_rulenum(struct ipt_entry *s, struct ipt_entry *e,
246 } else if (s == e) { 260 } else if (s == e) {
247 (*rulenum)++; 261 (*rulenum)++;
248 262
249 if (s->target_offset == sizeof(struct ipt_entry) 263 if (s->target_offset == sizeof(struct ipt_entry) &&
250 && strcmp(t->target.u.kernel.target->name, 264 strcmp(t->target.u.kernel.target->name,
251 IPT_STANDARD_TARGET) == 0 265 IPT_STANDARD_TARGET) == 0 &&
252 && t->verdict < 0 266 t->verdict < 0 &&
253 && unconditional(&s->ip)) { 267 unconditional(&s->ip)) {
254 /* Tail of chains: STANDARD target (return/policy) */ 268 /* Tail of chains: STANDARD target (return/policy) */
255 *comment = *chainname == hookname 269 *comment = *chainname == hookname
256 ? comments[NF_IP_TRACE_COMMENT_POLICY] 270 ? comments[NF_IP_TRACE_COMMENT_POLICY]
@@ -263,17 +277,18 @@ get_chainname_rulenum(struct ipt_entry *s, struct ipt_entry *e,
263 return 0; 277 return 0;
264} 278}
265 279
266static void trace_packet(struct sk_buff *skb, 280static void trace_packet(const struct sk_buff *skb,
267 unsigned int hook, 281 unsigned int hook,
268 const struct net_device *in, 282 const struct net_device *in,
269 const struct net_device *out, 283 const struct net_device *out,
270 const char *tablename, 284 const char *tablename,
271 struct xt_table_info *private, 285 const struct xt_table_info *private,
272 struct ipt_entry *e) 286 const struct ipt_entry *e)
273{ 287{
274 void *table_base; 288 const void *table_base;
275 const struct ipt_entry *root; 289 const struct ipt_entry *root;
276 const char *hookname, *chainname, *comment; 290 const char *hookname, *chainname, *comment;
291 const struct ipt_entry *iter;
277 unsigned int rulenum = 0; 292 unsigned int rulenum = 0;
278 293
279 table_base = private->entries[smp_processor_id()]; 294 table_base = private->entries[smp_processor_id()];
@@ -282,10 +297,10 @@ static void trace_packet(struct sk_buff *skb,
282 hookname = chainname = hooknames[hook]; 297 hookname = chainname = hooknames[hook];
283 comment = comments[NF_IP_TRACE_COMMENT_RULE]; 298 comment = comments[NF_IP_TRACE_COMMENT_RULE];
284 299
285 IPT_ENTRY_ITERATE(root, 300 xt_entry_foreach(iter, root, private->size - private->hook_entry[hook])
286 private->size - private->hook_entry[hook], 301 if (get_chainname_rulenum(iter, e, hookname,
287 get_chainname_rulenum, 302 &chainname, &comment, &rulenum) != 0)
288 e, hookname, &chainname, &comment, &rulenum); 303 break;
289 304
290 nf_log_packet(AF_INET, hook, skb, in, out, &trace_loginfo, 305 nf_log_packet(AF_INET, hook, skb, in, out, &trace_loginfo,
291 "TRACE: %s:%s:%s:%u ", 306 "TRACE: %s:%s:%s:%u ",
@@ -315,9 +330,9 @@ ipt_do_table(struct sk_buff *skb,
315 /* Initializing verdict to NF_DROP keeps gcc happy. */ 330 /* Initializing verdict to NF_DROP keeps gcc happy. */
316 unsigned int verdict = NF_DROP; 331 unsigned int verdict = NF_DROP;
317 const char *indev, *outdev; 332 const char *indev, *outdev;
318 void *table_base; 333 const void *table_base;
319 struct ipt_entry *e, *back; 334 struct ipt_entry *e, *back;
320 struct xt_table_info *private; 335 const struct xt_table_info *private;
321 struct xt_match_param mtpar; 336 struct xt_match_param mtpar;
322 struct xt_target_param tgpar; 337 struct xt_target_param tgpar;
323 338
@@ -350,17 +365,22 @@ ipt_do_table(struct sk_buff *skb,
350 back = get_entry(table_base, private->underflow[hook]); 365 back = get_entry(table_base, private->underflow[hook]);
351 366
352 do { 367 do {
353 struct ipt_entry_target *t; 368 const struct ipt_entry_target *t;
369 const struct xt_entry_match *ematch;
354 370
355 IP_NF_ASSERT(e); 371 IP_NF_ASSERT(e);
356 IP_NF_ASSERT(back); 372 IP_NF_ASSERT(back);
357 if (!ip_packet_match(ip, indev, outdev, 373 if (!ip_packet_match(ip, indev, outdev,
358 &e->ip, mtpar.fragoff) || 374 &e->ip, mtpar.fragoff)) {
359 IPT_MATCH_ITERATE(e, do_match, skb, &mtpar) != 0) { 375 no_match:
360 e = ipt_next_entry(e); 376 e = ipt_next_entry(e);
361 continue; 377 continue;
362 } 378 }
363 379
380 xt_ematch_foreach(ematch, e)
381 if (do_match(ematch, skb, &mtpar) != 0)
382 goto no_match;
383
364 ADD_COUNTER(e->counters, ntohs(ip->tot_len), 1); 384 ADD_COUNTER(e->counters, ntohs(ip->tot_len), 1);
365 385
366 t = ipt_get_target(e); 386 t = ipt_get_target(e);
@@ -388,8 +408,8 @@ ipt_do_table(struct sk_buff *skb,
388 back = get_entry(table_base, back->comefrom); 408 back = get_entry(table_base, back->comefrom);
389 continue; 409 continue;
390 } 410 }
391 if (table_base + v != ipt_next_entry(e) 411 if (table_base + v != ipt_next_entry(e) &&
392 && !(e->ip.flags & IPT_F_GOTO)) { 412 !(e->ip.flags & IPT_F_GOTO)) {
393 /* Save old back ptr in next entry */ 413 /* Save old back ptr in next entry */
394 struct ipt_entry *next = ipt_next_entry(e); 414 struct ipt_entry *next = ipt_next_entry(e);
395 next->comefrom = (void *)back - table_base; 415 next->comefrom = (void *)back - table_base;
@@ -443,7 +463,7 @@ ipt_do_table(struct sk_buff *skb,
443/* Figures out from what hook each rule can be called: returns 0 if 463/* Figures out from what hook each rule can be called: returns 0 if
444 there are loops. Puts hook bitmask in comefrom. */ 464 there are loops. Puts hook bitmask in comefrom. */
445static int 465static int
446mark_source_chains(struct xt_table_info *newinfo, 466mark_source_chains(const struct xt_table_info *newinfo,
447 unsigned int valid_hooks, void *entry0) 467 unsigned int valid_hooks, void *entry0)
448{ 468{
449 unsigned int hook; 469 unsigned int hook;
@@ -461,8 +481,8 @@ mark_source_chains(struct xt_table_info *newinfo,
461 e->counters.pcnt = pos; 481 e->counters.pcnt = pos;
462 482
463 for (;;) { 483 for (;;) {
464 struct ipt_standard_target *t 484 const struct ipt_standard_target *t
465 = (void *)ipt_get_target(e); 485 = (void *)ipt_get_target_c(e);
466 int visited = e->comefrom & (1 << hook); 486 int visited = e->comefrom & (1 << hook);
467 487
468 if (e->comefrom & (1 << NF_INET_NUMHOOKS)) { 488 if (e->comefrom & (1 << NF_INET_NUMHOOKS)) {
@@ -473,11 +493,11 @@ mark_source_chains(struct xt_table_info *newinfo,
473 e->comefrom |= ((1 << hook) | (1 << NF_INET_NUMHOOKS)); 493 e->comefrom |= ((1 << hook) | (1 << NF_INET_NUMHOOKS));
474 494
475 /* Unconditional return/END. */ 495 /* Unconditional return/END. */
476 if ((e->target_offset == sizeof(struct ipt_entry) 496 if ((e->target_offset == sizeof(struct ipt_entry) &&
477 && (strcmp(t->target.u.user.name, 497 (strcmp(t->target.u.user.name,
478 IPT_STANDARD_TARGET) == 0) 498 IPT_STANDARD_TARGET) == 0) &&
479 && t->verdict < 0 499 t->verdict < 0 && unconditional(&e->ip)) ||
480 && unconditional(&e->ip)) || visited) { 500 visited) {
481 unsigned int oldpos, size; 501 unsigned int oldpos, size;
482 502
483 if ((strcmp(t->target.u.user.name, 503 if ((strcmp(t->target.u.user.name,
@@ -524,8 +544,8 @@ mark_source_chains(struct xt_table_info *newinfo,
524 int newpos = t->verdict; 544 int newpos = t->verdict;
525 545
526 if (strcmp(t->target.u.user.name, 546 if (strcmp(t->target.u.user.name,
527 IPT_STANDARD_TARGET) == 0 547 IPT_STANDARD_TARGET) == 0 &&
528 && newpos >= 0) { 548 newpos >= 0) {
529 if (newpos > newinfo->size - 549 if (newpos > newinfo->size -
530 sizeof(struct ipt_entry)) { 550 sizeof(struct ipt_entry)) {
531 duprintf("mark_source_chains: " 551 duprintf("mark_source_chains: "
@@ -552,27 +572,23 @@ mark_source_chains(struct xt_table_info *newinfo,
552 return 1; 572 return 1;
553} 573}
554 574
555static int 575static void cleanup_match(struct ipt_entry_match *m, struct net *net)
556cleanup_match(struct ipt_entry_match *m, unsigned int *i)
557{ 576{
558 struct xt_mtdtor_param par; 577 struct xt_mtdtor_param par;
559 578
560 if (i && (*i)-- == 0) 579 par.net = net;
561 return 1;
562
563 par.match = m->u.kernel.match; 580 par.match = m->u.kernel.match;
564 par.matchinfo = m->data; 581 par.matchinfo = m->data;
565 par.family = NFPROTO_IPV4; 582 par.family = NFPROTO_IPV4;
566 if (par.match->destroy != NULL) 583 if (par.match->destroy != NULL)
567 par.match->destroy(&par); 584 par.match->destroy(&par);
568 module_put(par.match->me); 585 module_put(par.match->me);
569 return 0;
570} 586}
571 587
572static int 588static int
573check_entry(struct ipt_entry *e, const char *name) 589check_entry(const struct ipt_entry *e, const char *name)
574{ 590{
575 struct ipt_entry_target *t; 591 const struct ipt_entry_target *t;
576 592
577 if (!ip_checkentry(&e->ip)) { 593 if (!ip_checkentry(&e->ip)) {
578 duprintf("ip_tables: ip check failed %p %s.\n", e, name); 594 duprintf("ip_tables: ip check failed %p %s.\n", e, name);
@@ -583,7 +599,7 @@ check_entry(struct ipt_entry *e, const char *name)
583 e->next_offset) 599 e->next_offset)
584 return -EINVAL; 600 return -EINVAL;
585 601
586 t = ipt_get_target(e); 602 t = ipt_get_target_c(e);
587 if (e->target_offset + t->u.target_size > e->next_offset) 603 if (e->target_offset + t->u.target_size > e->next_offset)
588 return -EINVAL; 604 return -EINVAL;
589 605
@@ -591,8 +607,7 @@ check_entry(struct ipt_entry *e, const char *name)
591} 607}
592 608
593static int 609static int
594check_match(struct ipt_entry_match *m, struct xt_mtchk_param *par, 610check_match(struct ipt_entry_match *m, struct xt_mtchk_param *par)
595 unsigned int *i)
596{ 611{
597 const struct ipt_ip *ip = par->entryinfo; 612 const struct ipt_ip *ip = par->entryinfo;
598 int ret; 613 int ret;
@@ -607,13 +622,11 @@ check_match(struct ipt_entry_match *m, struct xt_mtchk_param *par,
607 par.match->name); 622 par.match->name);
608 return ret; 623 return ret;
609 } 624 }
610 ++*i;
611 return 0; 625 return 0;
612} 626}
613 627
614static int 628static int
615find_check_match(struct ipt_entry_match *m, struct xt_mtchk_param *par, 629find_check_match(struct ipt_entry_match *m, struct xt_mtchk_param *par)
616 unsigned int *i)
617{ 630{
618 struct xt_match *match; 631 struct xt_match *match;
619 int ret; 632 int ret;
@@ -627,7 +640,7 @@ find_check_match(struct ipt_entry_match *m, struct xt_mtchk_param *par,
627 } 640 }
628 m->u.kernel.match = match; 641 m->u.kernel.match = match;
629 642
630 ret = check_match(m, par, i); 643 ret = check_match(m, par);
631 if (ret) 644 if (ret)
632 goto err; 645 goto err;
633 646
@@ -637,10 +650,11 @@ err:
637 return ret; 650 return ret;
638} 651}
639 652
640static int check_target(struct ipt_entry *e, const char *name) 653static int check_target(struct ipt_entry *e, struct net *net, const char *name)
641{ 654{
642 struct ipt_entry_target *t = ipt_get_target(e); 655 struct ipt_entry_target *t = ipt_get_target(e);
643 struct xt_tgchk_param par = { 656 struct xt_tgchk_param par = {
657 .net = net,
644 .table = name, 658 .table = name,
645 .entryinfo = e, 659 .entryinfo = e,
646 .target = t->u.kernel.target, 660 .target = t->u.kernel.target,
@@ -661,27 +675,32 @@ static int check_target(struct ipt_entry *e, const char *name)
661} 675}
662 676
663static int 677static int
664find_check_entry(struct ipt_entry *e, const char *name, unsigned int size, 678find_check_entry(struct ipt_entry *e, struct net *net, const char *name,
665 unsigned int *i) 679 unsigned int size)
666{ 680{
667 struct ipt_entry_target *t; 681 struct ipt_entry_target *t;
668 struct xt_target *target; 682 struct xt_target *target;
669 int ret; 683 int ret;
670 unsigned int j; 684 unsigned int j;
671 struct xt_mtchk_param mtpar; 685 struct xt_mtchk_param mtpar;
686 struct xt_entry_match *ematch;
672 687
673 ret = check_entry(e, name); 688 ret = check_entry(e, name);
674 if (ret) 689 if (ret)
675 return ret; 690 return ret;
676 691
677 j = 0; 692 j = 0;
693 mtpar.net = net;
678 mtpar.table = name; 694 mtpar.table = name;
679 mtpar.entryinfo = &e->ip; 695 mtpar.entryinfo = &e->ip;
680 mtpar.hook_mask = e->comefrom; 696 mtpar.hook_mask = e->comefrom;
681 mtpar.family = NFPROTO_IPV4; 697 mtpar.family = NFPROTO_IPV4;
682 ret = IPT_MATCH_ITERATE(e, find_check_match, &mtpar, &j); 698 xt_ematch_foreach(ematch, e) {
683 if (ret != 0) 699 ret = find_check_match(ematch, &mtpar);
684 goto cleanup_matches; 700 if (ret != 0)
701 goto cleanup_matches;
702 ++j;
703 }
685 704
686 t = ipt_get_target(e); 705 t = ipt_get_target(e);
687 target = try_then_request_module(xt_find_target(AF_INET, 706 target = try_then_request_module(xt_find_target(AF_INET,
@@ -695,27 +714,29 @@ find_check_entry(struct ipt_entry *e, const char *name, unsigned int size,
695 } 714 }
696 t->u.kernel.target = target; 715 t->u.kernel.target = target;
697 716
698 ret = check_target(e, name); 717 ret = check_target(e, net, name);
699 if (ret) 718 if (ret)
700 goto err; 719 goto err;
701
702 (*i)++;
703 return 0; 720 return 0;
704 err: 721 err:
705 module_put(t->u.kernel.target->me); 722 module_put(t->u.kernel.target->me);
706 cleanup_matches: 723 cleanup_matches:
707 IPT_MATCH_ITERATE(e, cleanup_match, &j); 724 xt_ematch_foreach(ematch, e) {
725 if (j-- == 0)
726 break;
727 cleanup_match(ematch, net);
728 }
708 return ret; 729 return ret;
709} 730}
710 731
711static bool check_underflow(struct ipt_entry *e) 732static bool check_underflow(const struct ipt_entry *e)
712{ 733{
713 const struct ipt_entry_target *t; 734 const struct ipt_entry_target *t;
714 unsigned int verdict; 735 unsigned int verdict;
715 736
716 if (!unconditional(&e->ip)) 737 if (!unconditional(&e->ip))
717 return false; 738 return false;
718 t = ipt_get_target(e); 739 t = ipt_get_target_c(e);
719 if (strcmp(t->u.user.name, XT_STANDARD_TARGET) != 0) 740 if (strcmp(t->u.user.name, XT_STANDARD_TARGET) != 0)
720 return false; 741 return false;
721 verdict = ((struct ipt_standard_target *)t)->verdict; 742 verdict = ((struct ipt_standard_target *)t)->verdict;
@@ -726,17 +747,16 @@ static bool check_underflow(struct ipt_entry *e)
726static int 747static int
727check_entry_size_and_hooks(struct ipt_entry *e, 748check_entry_size_and_hooks(struct ipt_entry *e,
728 struct xt_table_info *newinfo, 749 struct xt_table_info *newinfo,
729 unsigned char *base, 750 const unsigned char *base,
730 unsigned char *limit, 751 const unsigned char *limit,
731 const unsigned int *hook_entries, 752 const unsigned int *hook_entries,
732 const unsigned int *underflows, 753 const unsigned int *underflows,
733 unsigned int valid_hooks, 754 unsigned int valid_hooks)
734 unsigned int *i)
735{ 755{
736 unsigned int h; 756 unsigned int h;
737 757
738 if ((unsigned long)e % __alignof__(struct ipt_entry) != 0 758 if ((unsigned long)e % __alignof__(struct ipt_entry) != 0 ||
739 || (unsigned char *)e + sizeof(struct ipt_entry) >= limit) { 759 (unsigned char *)e + sizeof(struct ipt_entry) >= limit) {
740 duprintf("Bad offset %p\n", e); 760 duprintf("Bad offset %p\n", e);
741 return -EINVAL; 761 return -EINVAL;
742 } 762 }
@@ -768,50 +788,42 @@ check_entry_size_and_hooks(struct ipt_entry *e,
768 /* Clear counters and comefrom */ 788 /* Clear counters and comefrom */
769 e->counters = ((struct xt_counters) { 0, 0 }); 789 e->counters = ((struct xt_counters) { 0, 0 });
770 e->comefrom = 0; 790 e->comefrom = 0;
771
772 (*i)++;
773 return 0; 791 return 0;
774} 792}
775 793
776static int 794static void
777cleanup_entry(struct ipt_entry *e, unsigned int *i) 795cleanup_entry(struct ipt_entry *e, struct net *net)
778{ 796{
779 struct xt_tgdtor_param par; 797 struct xt_tgdtor_param par;
780 struct ipt_entry_target *t; 798 struct ipt_entry_target *t;
781 799 struct xt_entry_match *ematch;
782 if (i && (*i)-- == 0)
783 return 1;
784 800
785 /* Cleanup all matches */ 801 /* Cleanup all matches */
786 IPT_MATCH_ITERATE(e, cleanup_match, NULL); 802 xt_ematch_foreach(ematch, e)
803 cleanup_match(ematch, net);
787 t = ipt_get_target(e); 804 t = ipt_get_target(e);
788 805
806 par.net = net;
789 par.target = t->u.kernel.target; 807 par.target = t->u.kernel.target;
790 par.targinfo = t->data; 808 par.targinfo = t->data;
791 par.family = NFPROTO_IPV4; 809 par.family = NFPROTO_IPV4;
792 if (par.target->destroy != NULL) 810 if (par.target->destroy != NULL)
793 par.target->destroy(&par); 811 par.target->destroy(&par);
794 module_put(par.target->me); 812 module_put(par.target->me);
795 return 0;
796} 813}
797 814
798/* Checks and translates the user-supplied table segment (held in 815/* Checks and translates the user-supplied table segment (held in
799 newinfo) */ 816 newinfo) */
800static int 817static int
801translate_table(const char *name, 818translate_table(struct net *net, struct xt_table_info *newinfo, void *entry0,
802 unsigned int valid_hooks, 819 const struct ipt_replace *repl)
803 struct xt_table_info *newinfo,
804 void *entry0,
805 unsigned int size,
806 unsigned int number,
807 const unsigned int *hook_entries,
808 const unsigned int *underflows)
809{ 820{
821 struct ipt_entry *iter;
810 unsigned int i; 822 unsigned int i;
811 int ret; 823 int ret = 0;
812 824
813 newinfo->size = size; 825 newinfo->size = repl->size;
814 newinfo->number = number; 826 newinfo->number = repl->num_entries;
815 827
816 /* Init all hooks to impossible value. */ 828 /* Init all hooks to impossible value. */
817 for (i = 0; i < NF_INET_NUMHOOKS; i++) { 829 for (i = 0; i < NF_INET_NUMHOOKS; i++) {
@@ -822,49 +834,58 @@ translate_table(const char *name,
822 duprintf("translate_table: size %u\n", newinfo->size); 834 duprintf("translate_table: size %u\n", newinfo->size);
823 i = 0; 835 i = 0;
824 /* Walk through entries, checking offsets. */ 836 /* Walk through entries, checking offsets. */
825 ret = IPT_ENTRY_ITERATE(entry0, newinfo->size, 837 xt_entry_foreach(iter, entry0, newinfo->size) {
826 check_entry_size_and_hooks, 838 ret = check_entry_size_and_hooks(iter, newinfo, entry0,
827 newinfo, 839 entry0 + repl->size,
828 entry0, 840 repl->hook_entry,
829 entry0 + size, 841 repl->underflow,
830 hook_entries, underflows, valid_hooks, &i); 842 repl->valid_hooks);
831 if (ret != 0) 843 if (ret != 0)
832 return ret; 844 return ret;
845 ++i;
846 }
833 847
834 if (i != number) { 848 if (i != repl->num_entries) {
835 duprintf("translate_table: %u not %u entries\n", 849 duprintf("translate_table: %u not %u entries\n",
836 i, number); 850 i, repl->num_entries);
837 return -EINVAL; 851 return -EINVAL;
838 } 852 }
839 853
840 /* Check hooks all assigned */ 854 /* Check hooks all assigned */
841 for (i = 0; i < NF_INET_NUMHOOKS; i++) { 855 for (i = 0; i < NF_INET_NUMHOOKS; i++) {
842 /* Only hooks which are valid */ 856 /* Only hooks which are valid */
843 if (!(valid_hooks & (1 << i))) 857 if (!(repl->valid_hooks & (1 << i)))
844 continue; 858 continue;
845 if (newinfo->hook_entry[i] == 0xFFFFFFFF) { 859 if (newinfo->hook_entry[i] == 0xFFFFFFFF) {
846 duprintf("Invalid hook entry %u %u\n", 860 duprintf("Invalid hook entry %u %u\n",
847 i, hook_entries[i]); 861 i, repl->hook_entry[i]);
848 return -EINVAL; 862 return -EINVAL;
849 } 863 }
850 if (newinfo->underflow[i] == 0xFFFFFFFF) { 864 if (newinfo->underflow[i] == 0xFFFFFFFF) {
851 duprintf("Invalid underflow %u %u\n", 865 duprintf("Invalid underflow %u %u\n",
852 i, underflows[i]); 866 i, repl->underflow[i]);
853 return -EINVAL; 867 return -EINVAL;
854 } 868 }
855 } 869 }
856 870
857 if (!mark_source_chains(newinfo, valid_hooks, entry0)) 871 if (!mark_source_chains(newinfo, repl->valid_hooks, entry0))
858 return -ELOOP; 872 return -ELOOP;
859 873
860 /* Finally, each sanity check must pass */ 874 /* Finally, each sanity check must pass */
861 i = 0; 875 i = 0;
862 ret = IPT_ENTRY_ITERATE(entry0, newinfo->size, 876 xt_entry_foreach(iter, entry0, newinfo->size) {
863 find_check_entry, name, size, &i); 877 ret = find_check_entry(iter, net, repl->name, repl->size);
878 if (ret != 0)
879 break;
880 ++i;
881 }
864 882
865 if (ret != 0) { 883 if (ret != 0) {
866 IPT_ENTRY_ITERATE(entry0, newinfo->size, 884 xt_entry_foreach(iter, entry0, newinfo->size) {
867 cleanup_entry, &i); 885 if (i-- == 0)
886 break;
887 cleanup_entry(iter, net);
888 }
868 return ret; 889 return ret;
869 } 890 }
870 891
@@ -877,33 +898,11 @@ translate_table(const char *name,
877 return ret; 898 return ret;
878} 899}
879 900
880/* Gets counters. */
881static inline int
882add_entry_to_counter(const struct ipt_entry *e,
883 struct xt_counters total[],
884 unsigned int *i)
885{
886 ADD_COUNTER(total[*i], e->counters.bcnt, e->counters.pcnt);
887
888 (*i)++;
889 return 0;
890}
891
892static inline int
893set_entry_to_counter(const struct ipt_entry *e,
894 struct ipt_counters total[],
895 unsigned int *i)
896{
897 SET_COUNTER(total[*i], e->counters.bcnt, e->counters.pcnt);
898
899 (*i)++;
900 return 0;
901}
902
903static void 901static void
904get_counters(const struct xt_table_info *t, 902get_counters(const struct xt_table_info *t,
905 struct xt_counters counters[]) 903 struct xt_counters counters[])
906{ 904{
905 struct ipt_entry *iter;
907 unsigned int cpu; 906 unsigned int cpu;
908 unsigned int i; 907 unsigned int i;
909 unsigned int curcpu; 908 unsigned int curcpu;
@@ -919,32 +918,32 @@ get_counters(const struct xt_table_info *t,
919 curcpu = smp_processor_id(); 918 curcpu = smp_processor_id();
920 919
921 i = 0; 920 i = 0;
922 IPT_ENTRY_ITERATE(t->entries[curcpu], 921 xt_entry_foreach(iter, t->entries[curcpu], t->size) {
923 t->size, 922 SET_COUNTER(counters[i], iter->counters.bcnt,
924 set_entry_to_counter, 923 iter->counters.pcnt);
925 counters, 924 ++i;
926 &i); 925 }
927 926
928 for_each_possible_cpu(cpu) { 927 for_each_possible_cpu(cpu) {
929 if (cpu == curcpu) 928 if (cpu == curcpu)
930 continue; 929 continue;
931 i = 0; 930 i = 0;
932 xt_info_wrlock(cpu); 931 xt_info_wrlock(cpu);
933 IPT_ENTRY_ITERATE(t->entries[cpu], 932 xt_entry_foreach(iter, t->entries[cpu], t->size) {
934 t->size, 933 ADD_COUNTER(counters[i], iter->counters.bcnt,
935 add_entry_to_counter, 934 iter->counters.pcnt);
936 counters, 935 ++i; /* macro does multi eval of i */
937 &i); 936 }
938 xt_info_wrunlock(cpu); 937 xt_info_wrunlock(cpu);
939 } 938 }
940 local_bh_enable(); 939 local_bh_enable();
941} 940}
942 941
943static struct xt_counters * alloc_counters(struct xt_table *table) 942static struct xt_counters *alloc_counters(const struct xt_table *table)
944{ 943{
945 unsigned int countersize; 944 unsigned int countersize;
946 struct xt_counters *counters; 945 struct xt_counters *counters;
947 struct xt_table_info *private = table->private; 946 const struct xt_table_info *private = table->private;
948 947
949 /* We need atomic snapshot of counters: rest doesn't change 948 /* We need atomic snapshot of counters: rest doesn't change
950 (other than comefrom, which userspace doesn't care 949 (other than comefrom, which userspace doesn't care
@@ -962,11 +961,11 @@ static struct xt_counters * alloc_counters(struct xt_table *table)
962 961
963static int 962static int
964copy_entries_to_user(unsigned int total_size, 963copy_entries_to_user(unsigned int total_size,
965 struct xt_table *table, 964 const struct xt_table *table,
966 void __user *userptr) 965 void __user *userptr)
967{ 966{
968 unsigned int off, num; 967 unsigned int off, num;
969 struct ipt_entry *e; 968 const struct ipt_entry *e;
970 struct xt_counters *counters; 969 struct xt_counters *counters;
971 const struct xt_table_info *private = table->private; 970 const struct xt_table_info *private = table->private;
972 int ret = 0; 971 int ret = 0;
@@ -1018,7 +1017,7 @@ copy_entries_to_user(unsigned int total_size,
1018 } 1017 }
1019 } 1018 }
1020 1019
1021 t = ipt_get_target(e); 1020 t = ipt_get_target_c(e);
1022 if (copy_to_user(userptr + off + e->target_offset 1021 if (copy_to_user(userptr + off + e->target_offset
1023 + offsetof(struct ipt_entry_target, 1022 + offsetof(struct ipt_entry_target,
1024 u.user.name), 1023 u.user.name),
@@ -1035,7 +1034,7 @@ copy_entries_to_user(unsigned int total_size,
1035} 1034}
1036 1035
1037#ifdef CONFIG_COMPAT 1036#ifdef CONFIG_COMPAT
1038static void compat_standard_from_user(void *dst, void *src) 1037static void compat_standard_from_user(void *dst, const void *src)
1039{ 1038{
1040 int v = *(compat_int_t *)src; 1039 int v = *(compat_int_t *)src;
1041 1040
@@ -1044,7 +1043,7 @@ static void compat_standard_from_user(void *dst, void *src)
1044 memcpy(dst, &v, sizeof(v)); 1043 memcpy(dst, &v, sizeof(v));
1045} 1044}
1046 1045
1047static int compat_standard_to_user(void __user *dst, void *src) 1046static int compat_standard_to_user(void __user *dst, const void *src)
1048{ 1047{
1049 compat_int_t cv = *(int *)src; 1048 compat_int_t cv = *(int *)src;
1050 1049
@@ -1053,25 +1052,20 @@ static int compat_standard_to_user(void __user *dst, void *src)
1053 return copy_to_user(dst, &cv, sizeof(cv)) ? -EFAULT : 0; 1052 return copy_to_user(dst, &cv, sizeof(cv)) ? -EFAULT : 0;
1054} 1053}
1055 1054
1056static inline int 1055static int compat_calc_entry(const struct ipt_entry *e,
1057compat_calc_match(struct ipt_entry_match *m, int *size)
1058{
1059 *size += xt_compat_match_offset(m->u.kernel.match);
1060 return 0;
1061}
1062
1063static int compat_calc_entry(struct ipt_entry *e,
1064 const struct xt_table_info *info, 1056 const struct xt_table_info *info,
1065 void *base, struct xt_table_info *newinfo) 1057 const void *base, struct xt_table_info *newinfo)
1066{ 1058{
1067 struct ipt_entry_target *t; 1059 const struct xt_entry_match *ematch;
1060 const struct ipt_entry_target *t;
1068 unsigned int entry_offset; 1061 unsigned int entry_offset;
1069 int off, i, ret; 1062 int off, i, ret;
1070 1063
1071 off = sizeof(struct ipt_entry) - sizeof(struct compat_ipt_entry); 1064 off = sizeof(struct ipt_entry) - sizeof(struct compat_ipt_entry);
1072 entry_offset = (void *)e - base; 1065 entry_offset = (void *)e - base;
1073 IPT_MATCH_ITERATE(e, compat_calc_match, &off); 1066 xt_ematch_foreach(ematch, e)
1074 t = ipt_get_target(e); 1067 off += xt_compat_match_offset(ematch->u.kernel.match);
1068 t = ipt_get_target_c(e);
1075 off += xt_compat_target_offset(t->u.kernel.target); 1069 off += xt_compat_target_offset(t->u.kernel.target);
1076 newinfo->size -= off; 1070 newinfo->size -= off;
1077 ret = xt_compat_add_offset(AF_INET, entry_offset, off); 1071 ret = xt_compat_add_offset(AF_INET, entry_offset, off);
@@ -1092,7 +1086,9 @@ static int compat_calc_entry(struct ipt_entry *e,
1092static int compat_table_info(const struct xt_table_info *info, 1086static int compat_table_info(const struct xt_table_info *info,
1093 struct xt_table_info *newinfo) 1087 struct xt_table_info *newinfo)
1094{ 1088{
1089 struct ipt_entry *iter;
1095 void *loc_cpu_entry; 1090 void *loc_cpu_entry;
1091 int ret;
1096 1092
1097 if (!newinfo || !info) 1093 if (!newinfo || !info)
1098 return -EINVAL; 1094 return -EINVAL;
@@ -1101,13 +1097,17 @@ static int compat_table_info(const struct xt_table_info *info,
1101 memcpy(newinfo, info, offsetof(struct xt_table_info, entries)); 1097 memcpy(newinfo, info, offsetof(struct xt_table_info, entries));
1102 newinfo->initial_entries = 0; 1098 newinfo->initial_entries = 0;
1103 loc_cpu_entry = info->entries[raw_smp_processor_id()]; 1099 loc_cpu_entry = info->entries[raw_smp_processor_id()];
1104 return IPT_ENTRY_ITERATE(loc_cpu_entry, info->size, 1100 xt_entry_foreach(iter, loc_cpu_entry, info->size) {
1105 compat_calc_entry, info, loc_cpu_entry, 1101 ret = compat_calc_entry(iter, info, loc_cpu_entry, newinfo);
1106 newinfo); 1102 if (ret != 0)
1103 return ret;
1104 }
1105 return 0;
1107} 1106}
1108#endif 1107#endif
1109 1108
1110static int get_info(struct net *net, void __user *user, int *len, int compat) 1109static int get_info(struct net *net, void __user *user,
1110 const int *len, int compat)
1111{ 1111{
1112 char name[IPT_TABLE_MAXNAMELEN]; 1112 char name[IPT_TABLE_MAXNAMELEN];
1113 struct xt_table *t; 1113 struct xt_table *t;
@@ -1132,10 +1132,10 @@ static int get_info(struct net *net, void __user *user, int *len, int compat)
1132 if (t && !IS_ERR(t)) { 1132 if (t && !IS_ERR(t)) {
1133 struct ipt_getinfo info; 1133 struct ipt_getinfo info;
1134 const struct xt_table_info *private = t->private; 1134 const struct xt_table_info *private = t->private;
1135
1136#ifdef CONFIG_COMPAT 1135#ifdef CONFIG_COMPAT
1136 struct xt_table_info tmp;
1137
1137 if (compat) { 1138 if (compat) {
1138 struct xt_table_info tmp;
1139 ret = compat_table_info(private, &tmp); 1139 ret = compat_table_info(private, &tmp);
1140 xt_compat_flush_offsets(AF_INET); 1140 xt_compat_flush_offsets(AF_INET);
1141 private = &tmp; 1141 private = &tmp;
@@ -1167,7 +1167,8 @@ static int get_info(struct net *net, void __user *user, int *len, int compat)
1167} 1167}
1168 1168
1169static int 1169static int
1170get_entries(struct net *net, struct ipt_get_entries __user *uptr, int *len) 1170get_entries(struct net *net, struct ipt_get_entries __user *uptr,
1171 const int *len)
1171{ 1172{
1172 int ret; 1173 int ret;
1173 struct ipt_get_entries get; 1174 struct ipt_get_entries get;
@@ -1215,6 +1216,7 @@ __do_replace(struct net *net, const char *name, unsigned int valid_hooks,
1215 struct xt_table_info *oldinfo; 1216 struct xt_table_info *oldinfo;
1216 struct xt_counters *counters; 1217 struct xt_counters *counters;
1217 void *loc_cpu_old_entry; 1218 void *loc_cpu_old_entry;
1219 struct ipt_entry *iter;
1218 1220
1219 ret = 0; 1221 ret = 0;
1220 counters = vmalloc(num_counters * sizeof(struct xt_counters)); 1222 counters = vmalloc(num_counters * sizeof(struct xt_counters));
@@ -1257,8 +1259,9 @@ __do_replace(struct net *net, const char *name, unsigned int valid_hooks,
1257 1259
1258 /* Decrease module usage counts and free resource */ 1260 /* Decrease module usage counts and free resource */
1259 loc_cpu_old_entry = oldinfo->entries[raw_smp_processor_id()]; 1261 loc_cpu_old_entry = oldinfo->entries[raw_smp_processor_id()];
1260 IPT_ENTRY_ITERATE(loc_cpu_old_entry, oldinfo->size, cleanup_entry, 1262 xt_entry_foreach(iter, loc_cpu_old_entry, oldinfo->size)
1261 NULL); 1263 cleanup_entry(iter, net);
1264
1262 xt_free_table_info(oldinfo); 1265 xt_free_table_info(oldinfo);
1263 if (copy_to_user(counters_ptr, counters, 1266 if (copy_to_user(counters_ptr, counters,
1264 sizeof(struct xt_counters) * num_counters) != 0) 1267 sizeof(struct xt_counters) * num_counters) != 0)
@@ -1277,12 +1280,13 @@ __do_replace(struct net *net, const char *name, unsigned int valid_hooks,
1277} 1280}
1278 1281
1279static int 1282static int
1280do_replace(struct net *net, void __user *user, unsigned int len) 1283do_replace(struct net *net, const void __user *user, unsigned int len)
1281{ 1284{
1282 int ret; 1285 int ret;
1283 struct ipt_replace tmp; 1286 struct ipt_replace tmp;
1284 struct xt_table_info *newinfo; 1287 struct xt_table_info *newinfo;
1285 void *loc_cpu_entry; 1288 void *loc_cpu_entry;
1289 struct ipt_entry *iter;
1286 1290
1287 if (copy_from_user(&tmp, user, sizeof(tmp)) != 0) 1291 if (copy_from_user(&tmp, user, sizeof(tmp)) != 0)
1288 return -EFAULT; 1292 return -EFAULT;
@@ -1303,9 +1307,7 @@ do_replace(struct net *net, void __user *user, unsigned int len)
1303 goto free_newinfo; 1307 goto free_newinfo;
1304 } 1308 }
1305 1309
1306 ret = translate_table(tmp.name, tmp.valid_hooks, 1310 ret = translate_table(net, newinfo, loc_cpu_entry, &tmp);
1307 newinfo, loc_cpu_entry, tmp.size, tmp.num_entries,
1308 tmp.hook_entry, tmp.underflow);
1309 if (ret != 0) 1311 if (ret != 0)
1310 goto free_newinfo; 1312 goto free_newinfo;
1311 1313
@@ -1318,27 +1320,16 @@ do_replace(struct net *net, void __user *user, unsigned int len)
1318 return 0; 1320 return 0;
1319 1321
1320 free_newinfo_untrans: 1322 free_newinfo_untrans:
1321 IPT_ENTRY_ITERATE(loc_cpu_entry, newinfo->size, cleanup_entry, NULL); 1323 xt_entry_foreach(iter, loc_cpu_entry, newinfo->size)
1324 cleanup_entry(iter, net);
1322 free_newinfo: 1325 free_newinfo:
1323 xt_free_table_info(newinfo); 1326 xt_free_table_info(newinfo);
1324 return ret; 1327 return ret;
1325} 1328}
1326 1329
1327/* We're lazy, and add to the first CPU; overflow works its fey magic
1328 * and everything is OK. */
1329static int 1330static int
1330add_counter_to_entry(struct ipt_entry *e, 1331do_add_counters(struct net *net, const void __user *user,
1331 const struct xt_counters addme[], 1332 unsigned int len, int compat)
1332 unsigned int *i)
1333{
1334 ADD_COUNTER(e->counters, addme[*i].bcnt, addme[*i].pcnt);
1335
1336 (*i)++;
1337 return 0;
1338}
1339
1340static int
1341do_add_counters(struct net *net, void __user *user, unsigned int len, int compat)
1342{ 1333{
1343 unsigned int i, curcpu; 1334 unsigned int i, curcpu;
1344 struct xt_counters_info tmp; 1335 struct xt_counters_info tmp;
@@ -1351,6 +1342,7 @@ do_add_counters(struct net *net, void __user *user, unsigned int len, int compat
1351 const struct xt_table_info *private; 1342 const struct xt_table_info *private;
1352 int ret = 0; 1343 int ret = 0;
1353 void *loc_cpu_entry; 1344 void *loc_cpu_entry;
1345 struct ipt_entry *iter;
1354#ifdef CONFIG_COMPAT 1346#ifdef CONFIG_COMPAT
1355 struct compat_xt_counters_info compat_tmp; 1347 struct compat_xt_counters_info compat_tmp;
1356 1348
@@ -1408,11 +1400,10 @@ do_add_counters(struct net *net, void __user *user, unsigned int len, int compat
1408 curcpu = smp_processor_id(); 1400 curcpu = smp_processor_id();
1409 loc_cpu_entry = private->entries[curcpu]; 1401 loc_cpu_entry = private->entries[curcpu];
1410 xt_info_wrlock(curcpu); 1402 xt_info_wrlock(curcpu);
1411 IPT_ENTRY_ITERATE(loc_cpu_entry, 1403 xt_entry_foreach(iter, loc_cpu_entry, private->size) {
1412 private->size, 1404 ADD_COUNTER(iter->counters, paddc[i].bcnt, paddc[i].pcnt);
1413 add_counter_to_entry, 1405 ++i;
1414 paddc, 1406 }
1415 &i);
1416 xt_info_wrunlock(curcpu); 1407 xt_info_wrunlock(curcpu);
1417 unlock_up_free: 1408 unlock_up_free:
1418 local_bh_enable(); 1409 local_bh_enable();
@@ -1440,45 +1431,40 @@ struct compat_ipt_replace {
1440static int 1431static int
1441compat_copy_entry_to_user(struct ipt_entry *e, void __user **dstptr, 1432compat_copy_entry_to_user(struct ipt_entry *e, void __user **dstptr,
1442 unsigned int *size, struct xt_counters *counters, 1433 unsigned int *size, struct xt_counters *counters,
1443 unsigned int *i) 1434 unsigned int i)
1444{ 1435{
1445 struct ipt_entry_target *t; 1436 struct ipt_entry_target *t;
1446 struct compat_ipt_entry __user *ce; 1437 struct compat_ipt_entry __user *ce;
1447 u_int16_t target_offset, next_offset; 1438 u_int16_t target_offset, next_offset;
1448 compat_uint_t origsize; 1439 compat_uint_t origsize;
1449 int ret; 1440 const struct xt_entry_match *ematch;
1441 int ret = 0;
1450 1442
1451 ret = -EFAULT;
1452 origsize = *size; 1443 origsize = *size;
1453 ce = (struct compat_ipt_entry __user *)*dstptr; 1444 ce = (struct compat_ipt_entry __user *)*dstptr;
1454 if (copy_to_user(ce, e, sizeof(struct ipt_entry))) 1445 if (copy_to_user(ce, e, sizeof(struct ipt_entry)) != 0 ||
1455 goto out; 1446 copy_to_user(&ce->counters, &counters[i],
1456 1447 sizeof(counters[i])) != 0)
1457 if (copy_to_user(&ce->counters, &counters[*i], sizeof(counters[*i]))) 1448 return -EFAULT;
1458 goto out;
1459 1449
1460 *dstptr += sizeof(struct compat_ipt_entry); 1450 *dstptr += sizeof(struct compat_ipt_entry);
1461 *size -= sizeof(struct ipt_entry) - sizeof(struct compat_ipt_entry); 1451 *size -= sizeof(struct ipt_entry) - sizeof(struct compat_ipt_entry);
1462 1452
1463 ret = IPT_MATCH_ITERATE(e, xt_compat_match_to_user, dstptr, size); 1453 xt_ematch_foreach(ematch, e) {
1454 ret = xt_compat_match_to_user(ematch, dstptr, size);
1455 if (ret != 0)
1456 return ret;
1457 }
1464 target_offset = e->target_offset - (origsize - *size); 1458 target_offset = e->target_offset - (origsize - *size);
1465 if (ret)
1466 goto out;
1467 t = ipt_get_target(e); 1459 t = ipt_get_target(e);
1468 ret = xt_compat_target_to_user(t, dstptr, size); 1460 ret = xt_compat_target_to_user(t, dstptr, size);
1469 if (ret) 1461 if (ret)
1470 goto out; 1462 return ret;
1471 ret = -EFAULT;
1472 next_offset = e->next_offset - (origsize - *size); 1463 next_offset = e->next_offset - (origsize - *size);
1473 if (put_user(target_offset, &ce->target_offset)) 1464 if (put_user(target_offset, &ce->target_offset) != 0 ||
1474 goto out; 1465 put_user(next_offset, &ce->next_offset) != 0)
1475 if (put_user(next_offset, &ce->next_offset)) 1466 return -EFAULT;
1476 goto out;
1477
1478 (*i)++;
1479 return 0; 1467 return 0;
1480out:
1481 return ret;
1482} 1468}
1483 1469
1484static int 1470static int
@@ -1486,7 +1472,7 @@ compat_find_calc_match(struct ipt_entry_match *m,
1486 const char *name, 1472 const char *name,
1487 const struct ipt_ip *ip, 1473 const struct ipt_ip *ip,
1488 unsigned int hookmask, 1474 unsigned int hookmask,
1489 int *size, unsigned int *i) 1475 int *size)
1490{ 1476{
1491 struct xt_match *match; 1477 struct xt_match *match;
1492 1478
@@ -1500,47 +1486,32 @@ compat_find_calc_match(struct ipt_entry_match *m,
1500 } 1486 }
1501 m->u.kernel.match = match; 1487 m->u.kernel.match = match;
1502 *size += xt_compat_match_offset(match); 1488 *size += xt_compat_match_offset(match);
1503
1504 (*i)++;
1505 return 0;
1506}
1507
1508static int
1509compat_release_match(struct ipt_entry_match *m, unsigned int *i)
1510{
1511 if (i && (*i)-- == 0)
1512 return 1;
1513
1514 module_put(m->u.kernel.match->me);
1515 return 0; 1489 return 0;
1516} 1490}
1517 1491
1518static int 1492static void compat_release_entry(struct compat_ipt_entry *e)
1519compat_release_entry(struct compat_ipt_entry *e, unsigned int *i)
1520{ 1493{
1521 struct ipt_entry_target *t; 1494 struct ipt_entry_target *t;
1522 1495 struct xt_entry_match *ematch;
1523 if (i && (*i)-- == 0)
1524 return 1;
1525 1496
1526 /* Cleanup all matches */ 1497 /* Cleanup all matches */
1527 COMPAT_IPT_MATCH_ITERATE(e, compat_release_match, NULL); 1498 xt_ematch_foreach(ematch, e)
1499 module_put(ematch->u.kernel.match->me);
1528 t = compat_ipt_get_target(e); 1500 t = compat_ipt_get_target(e);
1529 module_put(t->u.kernel.target->me); 1501 module_put(t->u.kernel.target->me);
1530 return 0;
1531} 1502}
1532 1503
1533static int 1504static int
1534check_compat_entry_size_and_hooks(struct compat_ipt_entry *e, 1505check_compat_entry_size_and_hooks(struct compat_ipt_entry *e,
1535 struct xt_table_info *newinfo, 1506 struct xt_table_info *newinfo,
1536 unsigned int *size, 1507 unsigned int *size,
1537 unsigned char *base, 1508 const unsigned char *base,
1538 unsigned char *limit, 1509 const unsigned char *limit,
1539 unsigned int *hook_entries, 1510 const unsigned int *hook_entries,
1540 unsigned int *underflows, 1511 const unsigned int *underflows,
1541 unsigned int *i,
1542 const char *name) 1512 const char *name)
1543{ 1513{
1514 struct xt_entry_match *ematch;
1544 struct ipt_entry_target *t; 1515 struct ipt_entry_target *t;
1545 struct xt_target *target; 1516 struct xt_target *target;
1546 unsigned int entry_offset; 1517 unsigned int entry_offset;
@@ -1548,8 +1519,8 @@ check_compat_entry_size_and_hooks(struct compat_ipt_entry *e,
1548 int ret, off, h; 1519 int ret, off, h;
1549 1520
1550 duprintf("check_compat_entry_size_and_hooks %p\n", e); 1521 duprintf("check_compat_entry_size_and_hooks %p\n", e);
1551 if ((unsigned long)e % __alignof__(struct compat_ipt_entry) != 0 1522 if ((unsigned long)e % __alignof__(struct compat_ipt_entry) != 0 ||
1552 || (unsigned char *)e + sizeof(struct compat_ipt_entry) >= limit) { 1523 (unsigned char *)e + sizeof(struct compat_ipt_entry) >= limit) {
1553 duprintf("Bad offset %p, limit = %p\n", e, limit); 1524 duprintf("Bad offset %p, limit = %p\n", e, limit);
1554 return -EINVAL; 1525 return -EINVAL;
1555 } 1526 }
@@ -1569,10 +1540,13 @@ check_compat_entry_size_and_hooks(struct compat_ipt_entry *e,
1569 off = sizeof(struct ipt_entry) - sizeof(struct compat_ipt_entry); 1540 off = sizeof(struct ipt_entry) - sizeof(struct compat_ipt_entry);
1570 entry_offset = (void *)e - (void *)base; 1541 entry_offset = (void *)e - (void *)base;
1571 j = 0; 1542 j = 0;
1572 ret = COMPAT_IPT_MATCH_ITERATE(e, compat_find_calc_match, name, 1543 xt_ematch_foreach(ematch, e) {
1573 &e->ip, e->comefrom, &off, &j); 1544 ret = compat_find_calc_match(ematch, name,
1574 if (ret != 0) 1545 &e->ip, e->comefrom, &off);
1575 goto release_matches; 1546 if (ret != 0)
1547 goto release_matches;
1548 ++j;
1549 }
1576 1550
1577 t = compat_ipt_get_target(e); 1551 t = compat_ipt_get_target(e);
1578 target = try_then_request_module(xt_find_target(AF_INET, 1552 target = try_then_request_module(xt_find_target(AF_INET,
@@ -1604,14 +1578,16 @@ check_compat_entry_size_and_hooks(struct compat_ipt_entry *e,
1604 /* Clear counters and comefrom */ 1578 /* Clear counters and comefrom */
1605 memset(&e->counters, 0, sizeof(e->counters)); 1579 memset(&e->counters, 0, sizeof(e->counters));
1606 e->comefrom = 0; 1580 e->comefrom = 0;
1607
1608 (*i)++;
1609 return 0; 1581 return 0;
1610 1582
1611out: 1583out:
1612 module_put(t->u.kernel.target->me); 1584 module_put(t->u.kernel.target->me);
1613release_matches: 1585release_matches:
1614 IPT_MATCH_ITERATE(e, compat_release_match, &j); 1586 xt_ematch_foreach(ematch, e) {
1587 if (j-- == 0)
1588 break;
1589 module_put(ematch->u.kernel.match->me);
1590 }
1615 return ret; 1591 return ret;
1616} 1592}
1617 1593
@@ -1625,6 +1601,7 @@ compat_copy_entry_from_user(struct compat_ipt_entry *e, void **dstptr,
1625 struct ipt_entry *de; 1601 struct ipt_entry *de;
1626 unsigned int origsize; 1602 unsigned int origsize;
1627 int ret, h; 1603 int ret, h;
1604 struct xt_entry_match *ematch;
1628 1605
1629 ret = 0; 1606 ret = 0;
1630 origsize = *size; 1607 origsize = *size;
@@ -1635,10 +1612,11 @@ compat_copy_entry_from_user(struct compat_ipt_entry *e, void **dstptr,
1635 *dstptr += sizeof(struct ipt_entry); 1612 *dstptr += sizeof(struct ipt_entry);
1636 *size += sizeof(struct ipt_entry) - sizeof(struct compat_ipt_entry); 1613 *size += sizeof(struct ipt_entry) - sizeof(struct compat_ipt_entry);
1637 1614
1638 ret = COMPAT_IPT_MATCH_ITERATE(e, xt_compat_match_from_user, 1615 xt_ematch_foreach(ematch, e) {
1639 dstptr, size); 1616 ret = xt_compat_match_from_user(ematch, dstptr, size);
1640 if (ret) 1617 if (ret != 0)
1641 return ret; 1618 return ret;
1619 }
1642 de->target_offset = e->target_offset - (origsize - *size); 1620 de->target_offset = e->target_offset - (origsize - *size);
1643 t = compat_ipt_get_target(e); 1621 t = compat_ipt_get_target(e);
1644 target = t->u.kernel.target; 1622 target = t->u.kernel.target;
@@ -1655,36 +1633,43 @@ compat_copy_entry_from_user(struct compat_ipt_entry *e, void **dstptr,
1655} 1633}
1656 1634
1657static int 1635static int
1658compat_check_entry(struct ipt_entry *e, const char *name, 1636compat_check_entry(struct ipt_entry *e, struct net *net, const char *name)
1659 unsigned int *i)
1660{ 1637{
1638 struct xt_entry_match *ematch;
1661 struct xt_mtchk_param mtpar; 1639 struct xt_mtchk_param mtpar;
1662 unsigned int j; 1640 unsigned int j;
1663 int ret; 1641 int ret = 0;
1664 1642
1665 j = 0; 1643 j = 0;
1644 mtpar.net = net;
1666 mtpar.table = name; 1645 mtpar.table = name;
1667 mtpar.entryinfo = &e->ip; 1646 mtpar.entryinfo = &e->ip;
1668 mtpar.hook_mask = e->comefrom; 1647 mtpar.hook_mask = e->comefrom;
1669 mtpar.family = NFPROTO_IPV4; 1648 mtpar.family = NFPROTO_IPV4;
1670 ret = IPT_MATCH_ITERATE(e, check_match, &mtpar, &j); 1649 xt_ematch_foreach(ematch, e) {
1671 if (ret) 1650 ret = check_match(ematch, &mtpar);
1672 goto cleanup_matches; 1651 if (ret != 0)
1652 goto cleanup_matches;
1653 ++j;
1654 }
1673 1655
1674 ret = check_target(e, name); 1656 ret = check_target(e, net, name);
1675 if (ret) 1657 if (ret)
1676 goto cleanup_matches; 1658 goto cleanup_matches;
1677
1678 (*i)++;
1679 return 0; 1659 return 0;
1680 1660
1681 cleanup_matches: 1661 cleanup_matches:
1682 IPT_MATCH_ITERATE(e, cleanup_match, &j); 1662 xt_ematch_foreach(ematch, e) {
1663 if (j-- == 0)
1664 break;
1665 cleanup_match(ematch, net);
1666 }
1683 return ret; 1667 return ret;
1684} 1668}
1685 1669
1686static int 1670static int
1687translate_compat_table(const char *name, 1671translate_compat_table(struct net *net,
1672 const char *name,
1688 unsigned int valid_hooks, 1673 unsigned int valid_hooks,
1689 struct xt_table_info **pinfo, 1674 struct xt_table_info **pinfo,
1690 void **pentry0, 1675 void **pentry0,
@@ -1696,6 +1681,8 @@ translate_compat_table(const char *name,
1696 unsigned int i, j; 1681 unsigned int i, j;
1697 struct xt_table_info *newinfo, *info; 1682 struct xt_table_info *newinfo, *info;
1698 void *pos, *entry0, *entry1; 1683 void *pos, *entry0, *entry1;
1684 struct compat_ipt_entry *iter0;
1685 struct ipt_entry *iter1;
1699 unsigned int size; 1686 unsigned int size;
1700 int ret; 1687 int ret;
1701 1688
@@ -1714,13 +1701,17 @@ translate_compat_table(const char *name,
1714 j = 0; 1701 j = 0;
1715 xt_compat_lock(AF_INET); 1702 xt_compat_lock(AF_INET);
1716 /* Walk through entries, checking offsets. */ 1703 /* Walk through entries, checking offsets. */
1717 ret = COMPAT_IPT_ENTRY_ITERATE(entry0, total_size, 1704 xt_entry_foreach(iter0, entry0, total_size) {
1718 check_compat_entry_size_and_hooks, 1705 ret = check_compat_entry_size_and_hooks(iter0, info, &size,
1719 info, &size, entry0, 1706 entry0,
1720 entry0 + total_size, 1707 entry0 + total_size,
1721 hook_entries, underflows, &j, name); 1708 hook_entries,
1722 if (ret != 0) 1709 underflows,
1723 goto out_unlock; 1710 name);
1711 if (ret != 0)
1712 goto out_unlock;
1713 ++j;
1714 }
1724 1715
1725 ret = -EINVAL; 1716 ret = -EINVAL;
1726 if (j != number) { 1717 if (j != number) {
@@ -1759,9 +1750,12 @@ translate_compat_table(const char *name,
1759 entry1 = newinfo->entries[raw_smp_processor_id()]; 1750 entry1 = newinfo->entries[raw_smp_processor_id()];
1760 pos = entry1; 1751 pos = entry1;
1761 size = total_size; 1752 size = total_size;
1762 ret = COMPAT_IPT_ENTRY_ITERATE(entry0, total_size, 1753 xt_entry_foreach(iter0, entry0, total_size) {
1763 compat_copy_entry_from_user, 1754 ret = compat_copy_entry_from_user(iter0, &pos, &size,
1764 &pos, &size, name, newinfo, entry1); 1755 name, newinfo, entry1);
1756 if (ret != 0)
1757 break;
1758 }
1765 xt_compat_flush_offsets(AF_INET); 1759 xt_compat_flush_offsets(AF_INET);
1766 xt_compat_unlock(AF_INET); 1760 xt_compat_unlock(AF_INET);
1767 if (ret) 1761 if (ret)
@@ -1772,13 +1766,32 @@ translate_compat_table(const char *name,
1772 goto free_newinfo; 1766 goto free_newinfo;
1773 1767
1774 i = 0; 1768 i = 0;
1775 ret = IPT_ENTRY_ITERATE(entry1, newinfo->size, compat_check_entry, 1769 xt_entry_foreach(iter1, entry1, newinfo->size) {
1776 name, &i); 1770 ret = compat_check_entry(iter1, net, name);
1771 if (ret != 0)
1772 break;
1773 ++i;
1774 }
1777 if (ret) { 1775 if (ret) {
1776 /*
1777 * The first i matches need cleanup_entry (calls ->destroy)
1778 * because they had called ->check already. The other j-i
1779 * entries need only release.
1780 */
1781 int skip = i;
1778 j -= i; 1782 j -= i;
1779 COMPAT_IPT_ENTRY_ITERATE_CONTINUE(entry0, newinfo->size, i, 1783 xt_entry_foreach(iter0, entry0, newinfo->size) {
1780 compat_release_entry, &j); 1784 if (skip-- > 0)
1781 IPT_ENTRY_ITERATE(entry1, newinfo->size, cleanup_entry, &i); 1785 continue;
1786 if (j-- == 0)
1787 break;
1788 compat_release_entry(iter0);
1789 }
1790 xt_entry_foreach(iter1, entry1, newinfo->size) {
1791 if (i-- == 0)
1792 break;
1793 cleanup_entry(iter1, net);
1794 }
1782 xt_free_table_info(newinfo); 1795 xt_free_table_info(newinfo);
1783 return ret; 1796 return ret;
1784 } 1797 }
@@ -1796,7 +1809,11 @@ translate_compat_table(const char *name,
1796free_newinfo: 1809free_newinfo:
1797 xt_free_table_info(newinfo); 1810 xt_free_table_info(newinfo);
1798out: 1811out:
1799 COMPAT_IPT_ENTRY_ITERATE(entry0, total_size, compat_release_entry, &j); 1812 xt_entry_foreach(iter0, entry0, total_size) {
1813 if (j-- == 0)
1814 break;
1815 compat_release_entry(iter0);
1816 }
1800 return ret; 1817 return ret;
1801out_unlock: 1818out_unlock:
1802 xt_compat_flush_offsets(AF_INET); 1819 xt_compat_flush_offsets(AF_INET);
@@ -1811,6 +1828,7 @@ compat_do_replace(struct net *net, void __user *user, unsigned int len)
1811 struct compat_ipt_replace tmp; 1828 struct compat_ipt_replace tmp;
1812 struct xt_table_info *newinfo; 1829 struct xt_table_info *newinfo;
1813 void *loc_cpu_entry; 1830 void *loc_cpu_entry;
1831 struct ipt_entry *iter;
1814 1832
1815 if (copy_from_user(&tmp, user, sizeof(tmp)) != 0) 1833 if (copy_from_user(&tmp, user, sizeof(tmp)) != 0)
1816 return -EFAULT; 1834 return -EFAULT;
@@ -1833,7 +1851,7 @@ compat_do_replace(struct net *net, void __user *user, unsigned int len)
1833 goto free_newinfo; 1851 goto free_newinfo;
1834 } 1852 }
1835 1853
1836 ret = translate_compat_table(tmp.name, tmp.valid_hooks, 1854 ret = translate_compat_table(net, tmp.name, tmp.valid_hooks,
1837 &newinfo, &loc_cpu_entry, tmp.size, 1855 &newinfo, &loc_cpu_entry, tmp.size,
1838 tmp.num_entries, tmp.hook_entry, 1856 tmp.num_entries, tmp.hook_entry,
1839 tmp.underflow); 1857 tmp.underflow);
@@ -1849,7 +1867,8 @@ compat_do_replace(struct net *net, void __user *user, unsigned int len)
1849 return 0; 1867 return 0;
1850 1868
1851 free_newinfo_untrans: 1869 free_newinfo_untrans:
1852 IPT_ENTRY_ITERATE(loc_cpu_entry, newinfo->size, cleanup_entry, NULL); 1870 xt_entry_foreach(iter, loc_cpu_entry, newinfo->size)
1871 cleanup_entry(iter, net);
1853 free_newinfo: 1872 free_newinfo:
1854 xt_free_table_info(newinfo); 1873 xt_free_table_info(newinfo);
1855 return ret; 1874 return ret;
@@ -1898,6 +1917,7 @@ compat_copy_entries_to_user(unsigned int total_size, struct xt_table *table,
1898 int ret = 0; 1917 int ret = 0;
1899 const void *loc_cpu_entry; 1918 const void *loc_cpu_entry;
1900 unsigned int i = 0; 1919 unsigned int i = 0;
1920 struct ipt_entry *iter;
1901 1921
1902 counters = alloc_counters(table); 1922 counters = alloc_counters(table);
1903 if (IS_ERR(counters)) 1923 if (IS_ERR(counters))
@@ -1910,9 +1930,12 @@ compat_copy_entries_to_user(unsigned int total_size, struct xt_table *table,
1910 loc_cpu_entry = private->entries[raw_smp_processor_id()]; 1930 loc_cpu_entry = private->entries[raw_smp_processor_id()];
1911 pos = userptr; 1931 pos = userptr;
1912 size = total_size; 1932 size = total_size;
1913 ret = IPT_ENTRY_ITERATE(loc_cpu_entry, total_size, 1933 xt_entry_foreach(iter, loc_cpu_entry, total_size) {
1914 compat_copy_entry_to_user, 1934 ret = compat_copy_entry_to_user(iter, &pos,
1915 &pos, &size, counters, &i); 1935 &size, counters, i++);
1936 if (ret != 0)
1937 break;
1938 }
1916 1939
1917 vfree(counters); 1940 vfree(counters);
1918 return ret; 1941 return ret;
@@ -2086,11 +2109,7 @@ struct xt_table *ipt_register_table(struct net *net,
2086 loc_cpu_entry = newinfo->entries[raw_smp_processor_id()]; 2109 loc_cpu_entry = newinfo->entries[raw_smp_processor_id()];
2087 memcpy(loc_cpu_entry, repl->entries, repl->size); 2110 memcpy(loc_cpu_entry, repl->entries, repl->size);
2088 2111
2089 ret = translate_table(table->name, table->valid_hooks, 2112 ret = translate_table(net, newinfo, loc_cpu_entry, repl);
2090 newinfo, loc_cpu_entry, repl->size,
2091 repl->num_entries,
2092 repl->hook_entry,
2093 repl->underflow);
2094 if (ret != 0) 2113 if (ret != 0)
2095 goto out_free; 2114 goto out_free;
2096 2115
@@ -2108,17 +2127,19 @@ out:
2108 return ERR_PTR(ret); 2127 return ERR_PTR(ret);
2109} 2128}
2110 2129
2111void ipt_unregister_table(struct xt_table *table) 2130void ipt_unregister_table(struct net *net, struct xt_table *table)
2112{ 2131{
2113 struct xt_table_info *private; 2132 struct xt_table_info *private;
2114 void *loc_cpu_entry; 2133 void *loc_cpu_entry;
2115 struct module *table_owner = table->me; 2134 struct module *table_owner = table->me;
2135 struct ipt_entry *iter;
2116 2136
2117 private = xt_unregister_table(table); 2137 private = xt_unregister_table(table);
2118 2138
2119 /* Decrease module usage counts and free resources */ 2139 /* Decrease module usage counts and free resources */
2120 loc_cpu_entry = private->entries[raw_smp_processor_id()]; 2140 loc_cpu_entry = private->entries[raw_smp_processor_id()];
2121 IPT_ENTRY_ITERATE(loc_cpu_entry, private->size, cleanup_entry, NULL); 2141 xt_entry_foreach(iter, loc_cpu_entry, private->size)
2142 cleanup_entry(iter, net);
2122 if (private->number > private->initial_entries) 2143 if (private->number > private->initial_entries)
2123 module_put(table_owner); 2144 module_put(table_owner);
2124 xt_free_table_info(private); 2145 xt_free_table_info(private);
diff --git a/net/ipv4/netfilter/ipt_CLUSTERIP.c b/net/ipv4/netfilter/ipt_CLUSTERIP.c
index 2e4f98b85524..ab828400ed71 100644
--- a/net/ipv4/netfilter/ipt_CLUSTERIP.c
+++ b/net/ipv4/netfilter/ipt_CLUSTERIP.c
@@ -14,6 +14,7 @@
14#include <linux/jhash.h> 14#include <linux/jhash.h>
15#include <linux/bitops.h> 15#include <linux/bitops.h>
16#include <linux/skbuff.h> 16#include <linux/skbuff.h>
17#include <linux/slab.h>
17#include <linux/ip.h> 18#include <linux/ip.h>
18#include <linux/tcp.h> 19#include <linux/tcp.h>
19#include <linux/udp.h> 20#include <linux/udp.h>
@@ -303,9 +304,9 @@ clusterip_tg(struct sk_buff *skb, const struct xt_target_param *par)
303 304
304 /* special case: ICMP error handling. conntrack distinguishes between 305 /* special case: ICMP error handling. conntrack distinguishes between
305 * error messages (RELATED) and information requests (see below) */ 306 * error messages (RELATED) and information requests (see below) */
306 if (ip_hdr(skb)->protocol == IPPROTO_ICMP 307 if (ip_hdr(skb)->protocol == IPPROTO_ICMP &&
307 && (ctinfo == IP_CT_RELATED 308 (ctinfo == IP_CT_RELATED ||
308 || ctinfo == IP_CT_RELATED+IP_CT_IS_REPLY)) 309 ctinfo == IP_CT_RELATED + IP_CT_IS_REPLY))
309 return XT_CONTINUE; 310 return XT_CONTINUE;
310 311
311 /* ip_conntrack_icmp guarantees us that we only have ICMP_ECHO, 312 /* ip_conntrack_icmp guarantees us that we only have ICMP_ECHO,
@@ -362,8 +363,8 @@ static bool clusterip_tg_check(const struct xt_tgchk_param *par)
362 return false; 363 return false;
363 364
364 } 365 }
365 if (e->ip.dmsk.s_addr != htonl(0xffffffff) 366 if (e->ip.dmsk.s_addr != htonl(0xffffffff) ||
366 || e->ip.dst.s_addr == 0) { 367 e->ip.dst.s_addr == 0) {
367 printk(KERN_ERR "CLUSTERIP: Please specify destination IP\n"); 368 printk(KERN_ERR "CLUSTERIP: Please specify destination IP\n");
368 return false; 369 return false;
369 } 370 }
@@ -495,14 +496,14 @@ arp_mangle(unsigned int hook,
495 struct clusterip_config *c; 496 struct clusterip_config *c;
496 497
497 /* we don't care about non-ethernet and non-ipv4 ARP */ 498 /* we don't care about non-ethernet and non-ipv4 ARP */
498 if (arp->ar_hrd != htons(ARPHRD_ETHER) 499 if (arp->ar_hrd != htons(ARPHRD_ETHER) ||
499 || arp->ar_pro != htons(ETH_P_IP) 500 arp->ar_pro != htons(ETH_P_IP) ||
500 || arp->ar_pln != 4 || arp->ar_hln != ETH_ALEN) 501 arp->ar_pln != 4 || arp->ar_hln != ETH_ALEN)
501 return NF_ACCEPT; 502 return NF_ACCEPT;
502 503
503 /* we only want to mangle arp requests and replies */ 504 /* we only want to mangle arp requests and replies */
504 if (arp->ar_op != htons(ARPOP_REPLY) 505 if (arp->ar_op != htons(ARPOP_REPLY) &&
505 && arp->ar_op != htons(ARPOP_REQUEST)) 506 arp->ar_op != htons(ARPOP_REQUEST))
506 return NF_ACCEPT; 507 return NF_ACCEPT;
507 508
508 payload = (void *)(arp+1); 509 payload = (void *)(arp+1);
@@ -560,8 +561,7 @@ struct clusterip_seq_position {
560 561
561static void *clusterip_seq_start(struct seq_file *s, loff_t *pos) 562static void *clusterip_seq_start(struct seq_file *s, loff_t *pos)
562{ 563{
563 const struct proc_dir_entry *pde = s->private; 564 struct clusterip_config *c = s->private;
564 struct clusterip_config *c = pde->data;
565 unsigned int weight; 565 unsigned int weight;
566 u_int32_t local_nodes; 566 u_int32_t local_nodes;
567 struct clusterip_seq_position *idx; 567 struct clusterip_seq_position *idx;
@@ -632,10 +632,9 @@ static int clusterip_proc_open(struct inode *inode, struct file *file)
632 632
633 if (!ret) { 633 if (!ret) {
634 struct seq_file *sf = file->private_data; 634 struct seq_file *sf = file->private_data;
635 struct proc_dir_entry *pde = PDE(inode); 635 struct clusterip_config *c = PDE(inode)->data;
636 struct clusterip_config *c = pde->data;
637 636
638 sf->private = pde; 637 sf->private = c;
639 638
640 clusterip_config_get(c); 639 clusterip_config_get(c);
641 } 640 }
@@ -645,8 +644,7 @@ static int clusterip_proc_open(struct inode *inode, struct file *file)
645 644
646static int clusterip_proc_release(struct inode *inode, struct file *file) 645static int clusterip_proc_release(struct inode *inode, struct file *file)
647{ 646{
648 struct proc_dir_entry *pde = PDE(inode); 647 struct clusterip_config *c = PDE(inode)->data;
649 struct clusterip_config *c = pde->data;
650 int ret; 648 int ret;
651 649
652 ret = seq_release(inode, file); 650 ret = seq_release(inode, file);
@@ -660,10 +658,9 @@ static int clusterip_proc_release(struct inode *inode, struct file *file)
660static ssize_t clusterip_proc_write(struct file *file, const char __user *input, 658static ssize_t clusterip_proc_write(struct file *file, const char __user *input,
661 size_t size, loff_t *ofs) 659 size_t size, loff_t *ofs)
662{ 660{
661 struct clusterip_config *c = PDE(file->f_path.dentry->d_inode)->data;
663#define PROC_WRITELEN 10 662#define PROC_WRITELEN 10
664 char buffer[PROC_WRITELEN+1]; 663 char buffer[PROC_WRITELEN+1];
665 const struct proc_dir_entry *pde = PDE(file->f_path.dentry->d_inode);
666 struct clusterip_config *c = pde->data;
667 unsigned long nodenum; 664 unsigned long nodenum;
668 665
669 if (copy_from_user(buffer, input, PROC_WRITELEN)) 666 if (copy_from_user(buffer, input, PROC_WRITELEN))
diff --git a/net/ipv4/netfilter/ipt_ECN.c b/net/ipv4/netfilter/ipt_ECN.c
index f7e2fa0974dc..ea5cea2415c1 100644
--- a/net/ipv4/netfilter/ipt_ECN.c
+++ b/net/ipv4/netfilter/ipt_ECN.c
@@ -50,7 +50,7 @@ set_ect_tcp(struct sk_buff *skb, const struct ipt_ECN_info *einfo)
50 struct tcphdr _tcph, *tcph; 50 struct tcphdr _tcph, *tcph;
51 __be16 oldval; 51 __be16 oldval;
52 52
53 /* Not enought header? */ 53 /* Not enough header? */
54 tcph = skb_header_pointer(skb, ip_hdrlen(skb), sizeof(_tcph), &_tcph); 54 tcph = skb_header_pointer(skb, ip_hdrlen(skb), sizeof(_tcph), &_tcph);
55 if (!tcph) 55 if (!tcph)
56 return false; 56 return false;
@@ -85,8 +85,8 @@ ecn_tg(struct sk_buff *skb, const struct xt_target_param *par)
85 if (!set_ect_ip(skb, einfo)) 85 if (!set_ect_ip(skb, einfo))
86 return NF_DROP; 86 return NF_DROP;
87 87
88 if (einfo->operation & (IPT_ECN_OP_SET_ECE | IPT_ECN_OP_SET_CWR) 88 if (einfo->operation & (IPT_ECN_OP_SET_ECE | IPT_ECN_OP_SET_CWR) &&
89 && ip_hdr(skb)->protocol == IPPROTO_TCP) 89 ip_hdr(skb)->protocol == IPPROTO_TCP)
90 if (!set_ect_tcp(skb, einfo)) 90 if (!set_ect_tcp(skb, einfo))
91 return NF_DROP; 91 return NF_DROP;
92 92
@@ -108,8 +108,8 @@ static bool ecn_tg_check(const struct xt_tgchk_param *par)
108 einfo->ip_ect); 108 einfo->ip_ect);
109 return false; 109 return false;
110 } 110 }
111 if ((einfo->operation & (IPT_ECN_OP_SET_ECE|IPT_ECN_OP_SET_CWR)) 111 if ((einfo->operation & (IPT_ECN_OP_SET_ECE|IPT_ECN_OP_SET_CWR)) &&
112 && (e->ip.proto != IPPROTO_TCP || (e->ip.invflags & XT_INV_PROTO))) { 112 (e->ip.proto != IPPROTO_TCP || (e->ip.invflags & XT_INV_PROTO))) {
113 printk(KERN_WARNING "ECN: cannot use TCP operations on a " 113 printk(KERN_WARNING "ECN: cannot use TCP operations on a "
114 "non-tcp rule\n"); 114 "non-tcp rule\n");
115 return false; 115 return false;
diff --git a/net/ipv4/netfilter/ipt_LOG.c b/net/ipv4/netfilter/ipt_LOG.c
index acc44c69eb68..ee128efa1c8d 100644
--- a/net/ipv4/netfilter/ipt_LOG.c
+++ b/net/ipv4/netfilter/ipt_LOG.c
@@ -74,8 +74,8 @@ static void dump_packet(const struct nf_loginfo *info,
74 if (ntohs(ih->frag_off) & IP_OFFSET) 74 if (ntohs(ih->frag_off) & IP_OFFSET)
75 printk("FRAG:%u ", ntohs(ih->frag_off) & IP_OFFSET); 75 printk("FRAG:%u ", ntohs(ih->frag_off) & IP_OFFSET);
76 76
77 if ((logflags & IPT_LOG_IPOPT) 77 if ((logflags & IPT_LOG_IPOPT) &&
78 && ih->ihl * 4 > sizeof(struct iphdr)) { 78 ih->ihl * 4 > sizeof(struct iphdr)) {
79 const unsigned char *op; 79 const unsigned char *op;
80 unsigned char _opt[4 * 15 - sizeof(struct iphdr)]; 80 unsigned char _opt[4 * 15 - sizeof(struct iphdr)];
81 unsigned int i, optsize; 81 unsigned int i, optsize;
@@ -146,8 +146,8 @@ static void dump_packet(const struct nf_loginfo *info,
146 /* Max length: 11 "URGP=65535 " */ 146 /* Max length: 11 "URGP=65535 " */
147 printk("URGP=%u ", ntohs(th->urg_ptr)); 147 printk("URGP=%u ", ntohs(th->urg_ptr));
148 148
149 if ((logflags & IPT_LOG_TCPOPT) 149 if ((logflags & IPT_LOG_TCPOPT) &&
150 && th->doff * 4 > sizeof(struct tcphdr)) { 150 th->doff * 4 > sizeof(struct tcphdr)) {
151 unsigned char _opt[4 * 15 - sizeof(struct tcphdr)]; 151 unsigned char _opt[4 * 15 - sizeof(struct tcphdr)];
152 const unsigned char *op; 152 const unsigned char *op;
153 unsigned int i, optsize; 153 unsigned int i, optsize;
@@ -238,9 +238,9 @@ static void dump_packet(const struct nf_loginfo *info,
238 printk("TYPE=%u CODE=%u ", ich->type, ich->code); 238 printk("TYPE=%u CODE=%u ", ich->type, ich->code);
239 239
240 /* Max length: 25 "INCOMPLETE [65535 bytes] " */ 240 /* Max length: 25 "INCOMPLETE [65535 bytes] " */
241 if (ich->type <= NR_ICMP_TYPES 241 if (ich->type <= NR_ICMP_TYPES &&
242 && required_len[ich->type] 242 required_len[ich->type] &&
243 && skb->len-iphoff-ih->ihl*4 < required_len[ich->type]) { 243 skb->len-iphoff-ih->ihl*4 < required_len[ich->type]) {
244 printk("INCOMPLETE [%u bytes] ", 244 printk("INCOMPLETE [%u bytes] ",
245 skb->len - iphoff - ih->ihl*4); 245 skb->len - iphoff - ih->ihl*4);
246 break; 246 break;
@@ -276,8 +276,8 @@ static void dump_packet(const struct nf_loginfo *info,
276 } 276 }
277 277
278 /* Max length: 10 "MTU=65535 " */ 278 /* Max length: 10 "MTU=65535 " */
279 if (ich->type == ICMP_DEST_UNREACH 279 if (ich->type == ICMP_DEST_UNREACH &&
280 && ich->code == ICMP_FRAG_NEEDED) 280 ich->code == ICMP_FRAG_NEEDED)
281 printk("MTU=%u ", ntohs(ich->un.frag.mtu)); 281 printk("MTU=%u ", ntohs(ich->un.frag.mtu));
282 } 282 }
283 break; 283 break;
@@ -407,8 +407,8 @@ ipt_log_packet(u_int8_t pf,
407 if (in && !out) { 407 if (in && !out) {
408 /* MAC logging for input chain only. */ 408 /* MAC logging for input chain only. */
409 printk("MAC="); 409 printk("MAC=");
410 if (skb->dev && skb->dev->hard_header_len 410 if (skb->dev && skb->dev->hard_header_len &&
411 && skb->mac_header != skb->network_header) { 411 skb->mac_header != skb->network_header) {
412 int i; 412 int i;
413 const unsigned char *p = skb_mac_header(skb); 413 const unsigned char *p = skb_mac_header(skb);
414 for (i = 0; i < skb->dev->hard_header_len; i++,p++) 414 for (i = 0; i < skb->dev->hard_header_len; i++,p++)
diff --git a/net/ipv4/netfilter/ipt_MASQUERADE.c b/net/ipv4/netfilter/ipt_MASQUERADE.c
index dada0863946d..650b54042b01 100644
--- a/net/ipv4/netfilter/ipt_MASQUERADE.c
+++ b/net/ipv4/netfilter/ipt_MASQUERADE.c
@@ -59,8 +59,8 @@ masquerade_tg(struct sk_buff *skb, const struct xt_target_param *par)
59 ct = nf_ct_get(skb, &ctinfo); 59 ct = nf_ct_get(skb, &ctinfo);
60 nat = nfct_nat(ct); 60 nat = nfct_nat(ct);
61 61
62 NF_CT_ASSERT(ct && (ctinfo == IP_CT_NEW || ctinfo == IP_CT_RELATED 62 NF_CT_ASSERT(ct && (ctinfo == IP_CT_NEW || ctinfo == IP_CT_RELATED ||
63 || ctinfo == IP_CT_RELATED + IP_CT_IS_REPLY)); 63 ctinfo == IP_CT_RELATED + IP_CT_IS_REPLY));
64 64
65 /* Source address is 0.0.0.0 - locally generated packet that is 65 /* Source address is 0.0.0.0 - locally generated packet that is
66 * probably not supposed to be masqueraded. 66 * probably not supposed to be masqueraded.
diff --git a/net/ipv4/netfilter/ipt_REJECT.c b/net/ipv4/netfilter/ipt_REJECT.c
index c93ae44bff2a..a0e8bcf04159 100644
--- a/net/ipv4/netfilter/ipt_REJECT.c
+++ b/net/ipv4/netfilter/ipt_REJECT.c
@@ -12,6 +12,7 @@
12 12
13#include <linux/module.h> 13#include <linux/module.h>
14#include <linux/skbuff.h> 14#include <linux/skbuff.h>
15#include <linux/slab.h>
15#include <linux/ip.h> 16#include <linux/ip.h>
16#include <linux/udp.h> 17#include <linux/udp.h>
17#include <linux/icmp.h> 18#include <linux/icmp.h>
@@ -184,8 +185,8 @@ static bool reject_tg_check(const struct xt_tgchk_param *par)
184 return false; 185 return false;
185 } else if (rejinfo->with == IPT_TCP_RESET) { 186 } else if (rejinfo->with == IPT_TCP_RESET) {
186 /* Must specify that it's a TCP packet */ 187 /* Must specify that it's a TCP packet */
187 if (e->ip.proto != IPPROTO_TCP 188 if (e->ip.proto != IPPROTO_TCP ||
188 || (e->ip.invflags & XT_INV_PROTO)) { 189 (e->ip.invflags & XT_INV_PROTO)) {
189 printk("ipt_REJECT: TCP_RESET invalid for non-tcp\n"); 190 printk("ipt_REJECT: TCP_RESET invalid for non-tcp\n");
190 return false; 191 return false;
191 } 192 }
diff --git a/net/ipv4/netfilter/ipt_ULOG.c b/net/ipv4/netfilter/ipt_ULOG.c
index d32cc4bb328a..0dbe697f164f 100644
--- a/net/ipv4/netfilter/ipt_ULOG.c
+++ b/net/ipv4/netfilter/ipt_ULOG.c
@@ -33,6 +33,7 @@
33#include <linux/module.h> 33#include <linux/module.h>
34#include <linux/spinlock.h> 34#include <linux/spinlock.h>
35#include <linux/socket.h> 35#include <linux/socket.h>
36#include <linux/slab.h>
36#include <linux/skbuff.h> 37#include <linux/skbuff.h>
37#include <linux/kernel.h> 38#include <linux/kernel.h>
38#include <linux/timer.h> 39#include <linux/timer.h>
@@ -226,9 +227,9 @@ static void ipt_ulog_packet(unsigned int hooknum,
226 else 227 else
227 *(pm->prefix) = '\0'; 228 *(pm->prefix) = '\0';
228 229
229 if (in && in->hard_header_len > 0 230 if (in && in->hard_header_len > 0 &&
230 && skb->mac_header != skb->network_header 231 skb->mac_header != skb->network_header &&
231 && in->hard_header_len <= ULOG_MAC_LEN) { 232 in->hard_header_len <= ULOG_MAC_LEN) {
232 memcpy(pm->mac, skb_mac_header(skb), in->hard_header_len); 233 memcpy(pm->mac, skb_mac_header(skb), in->hard_header_len);
233 pm->mac_len = in->hard_header_len; 234 pm->mac_len = in->hard_header_len;
234 } else 235 } else
@@ -338,7 +339,7 @@ struct compat_ipt_ulog_info {
338 char prefix[ULOG_PREFIX_LEN]; 339 char prefix[ULOG_PREFIX_LEN];
339}; 340};
340 341
341static void ulog_tg_compat_from_user(void *dst, void *src) 342static void ulog_tg_compat_from_user(void *dst, const void *src)
342{ 343{
343 const struct compat_ipt_ulog_info *cl = src; 344 const struct compat_ipt_ulog_info *cl = src;
344 struct ipt_ulog_info l = { 345 struct ipt_ulog_info l = {
@@ -351,7 +352,7 @@ static void ulog_tg_compat_from_user(void *dst, void *src)
351 memcpy(dst, &l, sizeof(l)); 352 memcpy(dst, &l, sizeof(l));
352} 353}
353 354
354static int ulog_tg_compat_to_user(void __user *dst, void *src) 355static int ulog_tg_compat_to_user(void __user *dst, const void *src)
355{ 356{
356 const struct ipt_ulog_info *l = src; 357 const struct ipt_ulog_info *l = src;
357 struct compat_ipt_ulog_info cl = { 358 struct compat_ipt_ulog_info cl = {
diff --git a/net/ipv4/netfilter/ipt_ecn.c b/net/ipv4/netfilter/ipt_ecn.c
index 6289b64144c6..2a1e56b71908 100644
--- a/net/ipv4/netfilter/ipt_ecn.c
+++ b/net/ipv4/netfilter/ipt_ecn.c
@@ -96,8 +96,8 @@ static bool ecn_mt_check(const struct xt_mtchk_param *par)
96 if (info->invert & IPT_ECN_OP_MATCH_MASK) 96 if (info->invert & IPT_ECN_OP_MATCH_MASK)
97 return false; 97 return false;
98 98
99 if (info->operation & (IPT_ECN_OP_MATCH_ECE|IPT_ECN_OP_MATCH_CWR) 99 if (info->operation & (IPT_ECN_OP_MATCH_ECE|IPT_ECN_OP_MATCH_CWR) &&
100 && ip->proto != IPPROTO_TCP) { 100 ip->proto != IPPROTO_TCP) {
101 printk(KERN_WARNING "ipt_ecn: can't match TCP bits in rule for" 101 printk(KERN_WARNING "ipt_ecn: can't match TCP bits in rule for"
102 " non-tcp packets\n"); 102 " non-tcp packets\n");
103 return false; 103 return false;
diff --git a/net/ipv4/netfilter/iptable_filter.c b/net/ipv4/netfilter/iptable_filter.c
index df566cbd68e5..55392466daa4 100644
--- a/net/ipv4/netfilter/iptable_filter.c
+++ b/net/ipv4/netfilter/iptable_filter.c
@@ -13,6 +13,7 @@
13#include <linux/module.h> 13#include <linux/module.h>
14#include <linux/moduleparam.h> 14#include <linux/moduleparam.h>
15#include <linux/netfilter_ipv4/ip_tables.h> 15#include <linux/netfilter_ipv4/ip_tables.h>
16#include <linux/slab.h>
16#include <net/ip.h> 17#include <net/ip.h>
17 18
18MODULE_LICENSE("GPL"); 19MODULE_LICENSE("GPL");
@@ -23,104 +24,32 @@ MODULE_DESCRIPTION("iptables filter table");
23 (1 << NF_INET_FORWARD) | \ 24 (1 << NF_INET_FORWARD) | \
24 (1 << NF_INET_LOCAL_OUT)) 25 (1 << NF_INET_LOCAL_OUT))
25 26
26static struct
27{
28 struct ipt_replace repl;
29 struct ipt_standard entries[3];
30 struct ipt_error term;
31} initial_table __net_initdata = {
32 .repl = {
33 .name = "filter",
34 .valid_hooks = FILTER_VALID_HOOKS,
35 .num_entries = 4,
36 .size = sizeof(struct ipt_standard) * 3 + sizeof(struct ipt_error),
37 .hook_entry = {
38 [NF_INET_LOCAL_IN] = 0,
39 [NF_INET_FORWARD] = sizeof(struct ipt_standard),
40 [NF_INET_LOCAL_OUT] = sizeof(struct ipt_standard) * 2,
41 },
42 .underflow = {
43 [NF_INET_LOCAL_IN] = 0,
44 [NF_INET_FORWARD] = sizeof(struct ipt_standard),
45 [NF_INET_LOCAL_OUT] = sizeof(struct ipt_standard) * 2,
46 },
47 },
48 .entries = {
49 IPT_STANDARD_INIT(NF_ACCEPT), /* LOCAL_IN */
50 IPT_STANDARD_INIT(NF_ACCEPT), /* FORWARD */
51 IPT_STANDARD_INIT(NF_ACCEPT), /* LOCAL_OUT */
52 },
53 .term = IPT_ERROR_INIT, /* ERROR */
54};
55
56static const struct xt_table packet_filter = { 27static const struct xt_table packet_filter = {
57 .name = "filter", 28 .name = "filter",
58 .valid_hooks = FILTER_VALID_HOOKS, 29 .valid_hooks = FILTER_VALID_HOOKS,
59 .me = THIS_MODULE, 30 .me = THIS_MODULE,
60 .af = NFPROTO_IPV4, 31 .af = NFPROTO_IPV4,
32 .priority = NF_IP_PRI_FILTER,
61}; 33};
62 34
63/* The work comes in here from netfilter.c. */
64static unsigned int
65ipt_local_in_hook(unsigned int hook,
66 struct sk_buff *skb,
67 const struct net_device *in,
68 const struct net_device *out,
69 int (*okfn)(struct sk_buff *))
70{
71 return ipt_do_table(skb, hook, in, out,
72 dev_net(in)->ipv4.iptable_filter);
73}
74
75static unsigned int 35static unsigned int
76ipt_hook(unsigned int hook, 36iptable_filter_hook(unsigned int hook, struct sk_buff *skb,
77 struct sk_buff *skb, 37 const struct net_device *in, const struct net_device *out,
78 const struct net_device *in, 38 int (*okfn)(struct sk_buff *))
79 const struct net_device *out,
80 int (*okfn)(struct sk_buff *))
81{ 39{
82 return ipt_do_table(skb, hook, in, out, 40 const struct net *net;
83 dev_net(in)->ipv4.iptable_filter);
84}
85 41
86static unsigned int 42 if (hook == NF_INET_LOCAL_OUT &&
87ipt_local_out_hook(unsigned int hook, 43 (skb->len < sizeof(struct iphdr) ||
88 struct sk_buff *skb, 44 ip_hdrlen(skb) < sizeof(struct iphdr)))
89 const struct net_device *in, 45 /* root is playing with raw sockets. */
90 const struct net_device *out,
91 int (*okfn)(struct sk_buff *))
92{
93 /* root is playing with raw sockets. */
94 if (skb->len < sizeof(struct iphdr) ||
95 ip_hdrlen(skb) < sizeof(struct iphdr))
96 return NF_ACCEPT; 46 return NF_ACCEPT;
97 return ipt_do_table(skb, hook, in, out, 47
98 dev_net(out)->ipv4.iptable_filter); 48 net = dev_net((in != NULL) ? in : out);
49 return ipt_do_table(skb, hook, in, out, net->ipv4.iptable_filter);
99} 50}
100 51
101static struct nf_hook_ops ipt_ops[] __read_mostly = { 52static struct nf_hook_ops *filter_ops __read_mostly;
102 {
103 .hook = ipt_local_in_hook,
104 .owner = THIS_MODULE,
105 .pf = NFPROTO_IPV4,
106 .hooknum = NF_INET_LOCAL_IN,
107 .priority = NF_IP_PRI_FILTER,
108 },
109 {
110 .hook = ipt_hook,
111 .owner = THIS_MODULE,
112 .pf = NFPROTO_IPV4,
113 .hooknum = NF_INET_FORWARD,
114 .priority = NF_IP_PRI_FILTER,
115 },
116 {
117 .hook = ipt_local_out_hook,
118 .owner = THIS_MODULE,
119 .pf = NFPROTO_IPV4,
120 .hooknum = NF_INET_LOCAL_OUT,
121 .priority = NF_IP_PRI_FILTER,
122 },
123};
124 53
125/* Default to forward because I got too much mail already. */ 54/* Default to forward because I got too much mail already. */
126static int forward = NF_ACCEPT; 55static int forward = NF_ACCEPT;
@@ -128,9 +57,18 @@ module_param(forward, bool, 0000);
128 57
129static int __net_init iptable_filter_net_init(struct net *net) 58static int __net_init iptable_filter_net_init(struct net *net)
130{ 59{
131 /* Register table */ 60 struct ipt_replace *repl;
61
62 repl = ipt_alloc_initial_table(&packet_filter);
63 if (repl == NULL)
64 return -ENOMEM;
65 /* Entry 1 is the FORWARD hook */
66 ((struct ipt_standard *)repl->entries)[1].target.verdict =
67 -forward - 1;
68
132 net->ipv4.iptable_filter = 69 net->ipv4.iptable_filter =
133 ipt_register_table(net, &packet_filter, &initial_table.repl); 70 ipt_register_table(net, &packet_filter, repl);
71 kfree(repl);
134 if (IS_ERR(net->ipv4.iptable_filter)) 72 if (IS_ERR(net->ipv4.iptable_filter))
135 return PTR_ERR(net->ipv4.iptable_filter); 73 return PTR_ERR(net->ipv4.iptable_filter);
136 return 0; 74 return 0;
@@ -138,7 +76,7 @@ static int __net_init iptable_filter_net_init(struct net *net)
138 76
139static void __net_exit iptable_filter_net_exit(struct net *net) 77static void __net_exit iptable_filter_net_exit(struct net *net)
140{ 78{
141 ipt_unregister_table(net->ipv4.iptable_filter); 79 ipt_unregister_table(net, net->ipv4.iptable_filter);
142} 80}
143 81
144static struct pernet_operations iptable_filter_net_ops = { 82static struct pernet_operations iptable_filter_net_ops = {
@@ -155,17 +93,16 @@ static int __init iptable_filter_init(void)
155 return -EINVAL; 93 return -EINVAL;
156 } 94 }
157 95
158 /* Entry 1 is the FORWARD hook */
159 initial_table.entries[1].target.verdict = -forward - 1;
160
161 ret = register_pernet_subsys(&iptable_filter_net_ops); 96 ret = register_pernet_subsys(&iptable_filter_net_ops);
162 if (ret < 0) 97 if (ret < 0)
163 return ret; 98 return ret;
164 99
165 /* Register hooks */ 100 /* Register hooks */
166 ret = nf_register_hooks(ipt_ops, ARRAY_SIZE(ipt_ops)); 101 filter_ops = xt_hook_link(&packet_filter, iptable_filter_hook);
167 if (ret < 0) 102 if (IS_ERR(filter_ops)) {
103 ret = PTR_ERR(filter_ops);
168 goto cleanup_table; 104 goto cleanup_table;
105 }
169 106
170 return ret; 107 return ret;
171 108
@@ -176,7 +113,7 @@ static int __init iptable_filter_init(void)
176 113
177static void __exit iptable_filter_fini(void) 114static void __exit iptable_filter_fini(void)
178{ 115{
179 nf_unregister_hooks(ipt_ops, ARRAY_SIZE(ipt_ops)); 116 xt_hook_unlink(&packet_filter, filter_ops);
180 unregister_pernet_subsys(&iptable_filter_net_ops); 117 unregister_pernet_subsys(&iptable_filter_net_ops);
181} 118}
182 119
diff --git a/net/ipv4/netfilter/iptable_mangle.c b/net/ipv4/netfilter/iptable_mangle.c
index 036047f9b0f2..294a2a32f293 100644
--- a/net/ipv4/netfilter/iptable_mangle.c
+++ b/net/ipv4/netfilter/iptable_mangle.c
@@ -12,6 +12,7 @@
12#include <linux/netfilter_ipv4/ip_tables.h> 12#include <linux/netfilter_ipv4/ip_tables.h>
13#include <linux/netdevice.h> 13#include <linux/netdevice.h>
14#include <linux/skbuff.h> 14#include <linux/skbuff.h>
15#include <linux/slab.h>
15#include <net/sock.h> 16#include <net/sock.h>
16#include <net/route.h> 17#include <net/route.h>
17#include <linux/ip.h> 18#include <linux/ip.h>
@@ -27,101 +28,16 @@ MODULE_DESCRIPTION("iptables mangle table");
27 (1 << NF_INET_LOCAL_OUT) | \ 28 (1 << NF_INET_LOCAL_OUT) | \
28 (1 << NF_INET_POST_ROUTING)) 29 (1 << NF_INET_POST_ROUTING))
29 30
30/* Ouch - five different hooks? Maybe this should be a config option..... -- BC */
31static const struct
32{
33 struct ipt_replace repl;
34 struct ipt_standard entries[5];
35 struct ipt_error term;
36} initial_table __net_initdata = {
37 .repl = {
38 .name = "mangle",
39 .valid_hooks = MANGLE_VALID_HOOKS,
40 .num_entries = 6,
41 .size = sizeof(struct ipt_standard) * 5 + sizeof(struct ipt_error),
42 .hook_entry = {
43 [NF_INET_PRE_ROUTING] = 0,
44 [NF_INET_LOCAL_IN] = sizeof(struct ipt_standard),
45 [NF_INET_FORWARD] = sizeof(struct ipt_standard) * 2,
46 [NF_INET_LOCAL_OUT] = sizeof(struct ipt_standard) * 3,
47 [NF_INET_POST_ROUTING] = sizeof(struct ipt_standard) * 4,
48 },
49 .underflow = {
50 [NF_INET_PRE_ROUTING] = 0,
51 [NF_INET_LOCAL_IN] = sizeof(struct ipt_standard),
52 [NF_INET_FORWARD] = sizeof(struct ipt_standard) * 2,
53 [NF_INET_LOCAL_OUT] = sizeof(struct ipt_standard) * 3,
54 [NF_INET_POST_ROUTING] = sizeof(struct ipt_standard) * 4,
55 },
56 },
57 .entries = {
58 IPT_STANDARD_INIT(NF_ACCEPT), /* PRE_ROUTING */
59 IPT_STANDARD_INIT(NF_ACCEPT), /* LOCAL_IN */
60 IPT_STANDARD_INIT(NF_ACCEPT), /* FORWARD */
61 IPT_STANDARD_INIT(NF_ACCEPT), /* LOCAL_OUT */
62 IPT_STANDARD_INIT(NF_ACCEPT), /* POST_ROUTING */
63 },
64 .term = IPT_ERROR_INIT, /* ERROR */
65};
66
67static const struct xt_table packet_mangler = { 31static const struct xt_table packet_mangler = {
68 .name = "mangle", 32 .name = "mangle",
69 .valid_hooks = MANGLE_VALID_HOOKS, 33 .valid_hooks = MANGLE_VALID_HOOKS,
70 .me = THIS_MODULE, 34 .me = THIS_MODULE,
71 .af = NFPROTO_IPV4, 35 .af = NFPROTO_IPV4,
36 .priority = NF_IP_PRI_MANGLE,
72}; 37};
73 38
74/* The work comes in here from netfilter.c. */
75static unsigned int
76ipt_pre_routing_hook(unsigned int hook,
77 struct sk_buff *skb,
78 const struct net_device *in,
79 const struct net_device *out,
80 int (*okfn)(struct sk_buff *))
81{
82 return ipt_do_table(skb, hook, in, out,
83 dev_net(in)->ipv4.iptable_mangle);
84}
85
86static unsigned int
87ipt_post_routing_hook(unsigned int hook,
88 struct sk_buff *skb,
89 const struct net_device *in,
90 const struct net_device *out,
91 int (*okfn)(struct sk_buff *))
92{
93 return ipt_do_table(skb, hook, in, out,
94 dev_net(out)->ipv4.iptable_mangle);
95}
96
97static unsigned int
98ipt_local_in_hook(unsigned int hook,
99 struct sk_buff *skb,
100 const struct net_device *in,
101 const struct net_device *out,
102 int (*okfn)(struct sk_buff *))
103{
104 return ipt_do_table(skb, hook, in, out,
105 dev_net(in)->ipv4.iptable_mangle);
106}
107
108static unsigned int
109ipt_forward_hook(unsigned int hook,
110 struct sk_buff *skb,
111 const struct net_device *in,
112 const struct net_device *out,
113 int (*okfn)(struct sk_buff *))
114{
115 return ipt_do_table(skb, hook, in, out,
116 dev_net(in)->ipv4.iptable_mangle);
117}
118
119static unsigned int 39static unsigned int
120ipt_local_hook(unsigned int hook, 40ipt_mangle_out(struct sk_buff *skb, const struct net_device *out)
121 struct sk_buff *skb,
122 const struct net_device *in,
123 const struct net_device *out,
124 int (*okfn)(struct sk_buff *))
125{ 41{
126 unsigned int ret; 42 unsigned int ret;
127 const struct iphdr *iph; 43 const struct iphdr *iph;
@@ -130,8 +46,8 @@ ipt_local_hook(unsigned int hook,
130 u_int32_t mark; 46 u_int32_t mark;
131 47
132 /* root is playing with raw sockets. */ 48 /* root is playing with raw sockets. */
133 if (skb->len < sizeof(struct iphdr) 49 if (skb->len < sizeof(struct iphdr) ||
134 || ip_hdrlen(skb) < sizeof(struct iphdr)) 50 ip_hdrlen(skb) < sizeof(struct iphdr))
135 return NF_ACCEPT; 51 return NF_ACCEPT;
136 52
137 /* Save things which could affect route */ 53 /* Save things which could affect route */
@@ -141,7 +57,7 @@ ipt_local_hook(unsigned int hook,
141 daddr = iph->daddr; 57 daddr = iph->daddr;
142 tos = iph->tos; 58 tos = iph->tos;
143 59
144 ret = ipt_do_table(skb, hook, in, out, 60 ret = ipt_do_table(skb, NF_INET_LOCAL_OUT, NULL, out,
145 dev_net(out)->ipv4.iptable_mangle); 61 dev_net(out)->ipv4.iptable_mangle);
146 /* Reroute for ANY change. */ 62 /* Reroute for ANY change. */
147 if (ret != NF_DROP && ret != NF_STOLEN && ret != NF_QUEUE) { 63 if (ret != NF_DROP && ret != NF_STOLEN && ret != NF_QUEUE) {
@@ -158,49 +74,36 @@ ipt_local_hook(unsigned int hook,
158 return ret; 74 return ret;
159} 75}
160 76
161static struct nf_hook_ops ipt_ops[] __read_mostly = { 77/* The work comes in here from netfilter.c. */
162 { 78static unsigned int
163 .hook = ipt_pre_routing_hook, 79iptable_mangle_hook(unsigned int hook,
164 .owner = THIS_MODULE, 80 struct sk_buff *skb,
165 .pf = NFPROTO_IPV4, 81 const struct net_device *in,
166 .hooknum = NF_INET_PRE_ROUTING, 82 const struct net_device *out,
167 .priority = NF_IP_PRI_MANGLE, 83 int (*okfn)(struct sk_buff *))
168 }, 84{
169 { 85 if (hook == NF_INET_LOCAL_OUT)
170 .hook = ipt_local_in_hook, 86 return ipt_mangle_out(skb, out);
171 .owner = THIS_MODULE, 87 if (hook == NF_INET_POST_ROUTING)
172 .pf = NFPROTO_IPV4, 88 return ipt_do_table(skb, hook, in, out,
173 .hooknum = NF_INET_LOCAL_IN, 89 dev_net(out)->ipv4.iptable_mangle);
174 .priority = NF_IP_PRI_MANGLE, 90 /* PREROUTING/INPUT/FORWARD: */
175 }, 91 return ipt_do_table(skb, hook, in, out,
176 { 92 dev_net(in)->ipv4.iptable_mangle);
177 .hook = ipt_forward_hook, 93}
178 .owner = THIS_MODULE, 94
179 .pf = NFPROTO_IPV4, 95static struct nf_hook_ops *mangle_ops __read_mostly;
180 .hooknum = NF_INET_FORWARD,
181 .priority = NF_IP_PRI_MANGLE,
182 },
183 {
184 .hook = ipt_local_hook,
185 .owner = THIS_MODULE,
186 .pf = NFPROTO_IPV4,
187 .hooknum = NF_INET_LOCAL_OUT,
188 .priority = NF_IP_PRI_MANGLE,
189 },
190 {
191 .hook = ipt_post_routing_hook,
192 .owner = THIS_MODULE,
193 .pf = NFPROTO_IPV4,
194 .hooknum = NF_INET_POST_ROUTING,
195 .priority = NF_IP_PRI_MANGLE,
196 },
197};
198 96
199static int __net_init iptable_mangle_net_init(struct net *net) 97static int __net_init iptable_mangle_net_init(struct net *net)
200{ 98{
201 /* Register table */ 99 struct ipt_replace *repl;
100
101 repl = ipt_alloc_initial_table(&packet_mangler);
102 if (repl == NULL)
103 return -ENOMEM;
202 net->ipv4.iptable_mangle = 104 net->ipv4.iptable_mangle =
203 ipt_register_table(net, &packet_mangler, &initial_table.repl); 105 ipt_register_table(net, &packet_mangler, repl);
106 kfree(repl);
204 if (IS_ERR(net->ipv4.iptable_mangle)) 107 if (IS_ERR(net->ipv4.iptable_mangle))
205 return PTR_ERR(net->ipv4.iptable_mangle); 108 return PTR_ERR(net->ipv4.iptable_mangle);
206 return 0; 109 return 0;
@@ -208,7 +111,7 @@ static int __net_init iptable_mangle_net_init(struct net *net)
208 111
209static void __net_exit iptable_mangle_net_exit(struct net *net) 112static void __net_exit iptable_mangle_net_exit(struct net *net)
210{ 113{
211 ipt_unregister_table(net->ipv4.iptable_mangle); 114 ipt_unregister_table(net, net->ipv4.iptable_mangle);
212} 115}
213 116
214static struct pernet_operations iptable_mangle_net_ops = { 117static struct pernet_operations iptable_mangle_net_ops = {
@@ -225,9 +128,11 @@ static int __init iptable_mangle_init(void)
225 return ret; 128 return ret;
226 129
227 /* Register hooks */ 130 /* Register hooks */
228 ret = nf_register_hooks(ipt_ops, ARRAY_SIZE(ipt_ops)); 131 mangle_ops = xt_hook_link(&packet_mangler, iptable_mangle_hook);
229 if (ret < 0) 132 if (IS_ERR(mangle_ops)) {
133 ret = PTR_ERR(mangle_ops);
230 goto cleanup_table; 134 goto cleanup_table;
135 }
231 136
232 return ret; 137 return ret;
233 138
@@ -238,7 +143,7 @@ static int __init iptable_mangle_init(void)
238 143
239static void __exit iptable_mangle_fini(void) 144static void __exit iptable_mangle_fini(void)
240{ 145{
241 nf_unregister_hooks(ipt_ops, ARRAY_SIZE(ipt_ops)); 146 xt_hook_unlink(&packet_mangler, mangle_ops);
242 unregister_pernet_subsys(&iptable_mangle_net_ops); 147 unregister_pernet_subsys(&iptable_mangle_net_ops);
243} 148}
244 149
diff --git a/net/ipv4/netfilter/iptable_raw.c b/net/ipv4/netfilter/iptable_raw.c
index 993edc23be09..07fb710cd722 100644
--- a/net/ipv4/netfilter/iptable_raw.c
+++ b/net/ipv4/netfilter/iptable_raw.c
@@ -5,94 +5,49 @@
5 */ 5 */
6#include <linux/module.h> 6#include <linux/module.h>
7#include <linux/netfilter_ipv4/ip_tables.h> 7#include <linux/netfilter_ipv4/ip_tables.h>
8#include <linux/slab.h>
8#include <net/ip.h> 9#include <net/ip.h>
9 10
10#define RAW_VALID_HOOKS ((1 << NF_INET_PRE_ROUTING) | (1 << NF_INET_LOCAL_OUT)) 11#define RAW_VALID_HOOKS ((1 << NF_INET_PRE_ROUTING) | (1 << NF_INET_LOCAL_OUT))
11 12
12static const struct
13{
14 struct ipt_replace repl;
15 struct ipt_standard entries[2];
16 struct ipt_error term;
17} initial_table __net_initdata = {
18 .repl = {
19 .name = "raw",
20 .valid_hooks = RAW_VALID_HOOKS,
21 .num_entries = 3,
22 .size = sizeof(struct ipt_standard) * 2 + sizeof(struct ipt_error),
23 .hook_entry = {
24 [NF_INET_PRE_ROUTING] = 0,
25 [NF_INET_LOCAL_OUT] = sizeof(struct ipt_standard)
26 },
27 .underflow = {
28 [NF_INET_PRE_ROUTING] = 0,
29 [NF_INET_LOCAL_OUT] = sizeof(struct ipt_standard)
30 },
31 },
32 .entries = {
33 IPT_STANDARD_INIT(NF_ACCEPT), /* PRE_ROUTING */
34 IPT_STANDARD_INIT(NF_ACCEPT), /* LOCAL_OUT */
35 },
36 .term = IPT_ERROR_INIT, /* ERROR */
37};
38
39static const struct xt_table packet_raw = { 13static const struct xt_table packet_raw = {
40 .name = "raw", 14 .name = "raw",
41 .valid_hooks = RAW_VALID_HOOKS, 15 .valid_hooks = RAW_VALID_HOOKS,
42 .me = THIS_MODULE, 16 .me = THIS_MODULE,
43 .af = NFPROTO_IPV4, 17 .af = NFPROTO_IPV4,
18 .priority = NF_IP_PRI_RAW,
44}; 19};
45 20
46/* The work comes in here from netfilter.c. */ 21/* The work comes in here from netfilter.c. */
47static unsigned int 22static unsigned int
48ipt_hook(unsigned int hook, 23iptable_raw_hook(unsigned int hook, struct sk_buff *skb,
49 struct sk_buff *skb, 24 const struct net_device *in, const struct net_device *out,
50 const struct net_device *in, 25 int (*okfn)(struct sk_buff *))
51 const struct net_device *out,
52 int (*okfn)(struct sk_buff *))
53{ 26{
54 return ipt_do_table(skb, hook, in, out, 27 const struct net *net;
55 dev_net(in)->ipv4.iptable_raw);
56}
57 28
58static unsigned int 29 if (hook == NF_INET_LOCAL_OUT &&
59ipt_local_hook(unsigned int hook, 30 (skb->len < sizeof(struct iphdr) ||
60 struct sk_buff *skb, 31 ip_hdrlen(skb) < sizeof(struct iphdr)))
61 const struct net_device *in, 32 /* root is playing with raw sockets. */
62 const struct net_device *out,
63 int (*okfn)(struct sk_buff *))
64{
65 /* root is playing with raw sockets. */
66 if (skb->len < sizeof(struct iphdr) ||
67 ip_hdrlen(skb) < sizeof(struct iphdr))
68 return NF_ACCEPT; 33 return NF_ACCEPT;
69 return ipt_do_table(skb, hook, in, out, 34
70 dev_net(out)->ipv4.iptable_raw); 35 net = dev_net((in != NULL) ? in : out);
36 return ipt_do_table(skb, hook, in, out, net->ipv4.iptable_raw);
71} 37}
72 38
73/* 'raw' is the very first table. */ 39static struct nf_hook_ops *rawtable_ops __read_mostly;
74static struct nf_hook_ops ipt_ops[] __read_mostly = {
75 {
76 .hook = ipt_hook,
77 .pf = NFPROTO_IPV4,
78 .hooknum = NF_INET_PRE_ROUTING,
79 .priority = NF_IP_PRI_RAW,
80 .owner = THIS_MODULE,
81 },
82 {
83 .hook = ipt_local_hook,
84 .pf = NFPROTO_IPV4,
85 .hooknum = NF_INET_LOCAL_OUT,
86 .priority = NF_IP_PRI_RAW,
87 .owner = THIS_MODULE,
88 },
89};
90 40
91static int __net_init iptable_raw_net_init(struct net *net) 41static int __net_init iptable_raw_net_init(struct net *net)
92{ 42{
93 /* Register table */ 43 struct ipt_replace *repl;
44
45 repl = ipt_alloc_initial_table(&packet_raw);
46 if (repl == NULL)
47 return -ENOMEM;
94 net->ipv4.iptable_raw = 48 net->ipv4.iptable_raw =
95 ipt_register_table(net, &packet_raw, &initial_table.repl); 49 ipt_register_table(net, &packet_raw, repl);
50 kfree(repl);
96 if (IS_ERR(net->ipv4.iptable_raw)) 51 if (IS_ERR(net->ipv4.iptable_raw))
97 return PTR_ERR(net->ipv4.iptable_raw); 52 return PTR_ERR(net->ipv4.iptable_raw);
98 return 0; 53 return 0;
@@ -100,7 +55,7 @@ static int __net_init iptable_raw_net_init(struct net *net)
100 55
101static void __net_exit iptable_raw_net_exit(struct net *net) 56static void __net_exit iptable_raw_net_exit(struct net *net)
102{ 57{
103 ipt_unregister_table(net->ipv4.iptable_raw); 58 ipt_unregister_table(net, net->ipv4.iptable_raw);
104} 59}
105 60
106static struct pernet_operations iptable_raw_net_ops = { 61static struct pernet_operations iptable_raw_net_ops = {
@@ -117,9 +72,11 @@ static int __init iptable_raw_init(void)
117 return ret; 72 return ret;
118 73
119 /* Register hooks */ 74 /* Register hooks */
120 ret = nf_register_hooks(ipt_ops, ARRAY_SIZE(ipt_ops)); 75 rawtable_ops = xt_hook_link(&packet_raw, iptable_raw_hook);
121 if (ret < 0) 76 if (IS_ERR(rawtable_ops)) {
77 ret = PTR_ERR(rawtable_ops);
122 goto cleanup_table; 78 goto cleanup_table;
79 }
123 80
124 return ret; 81 return ret;
125 82
@@ -130,7 +87,7 @@ static int __init iptable_raw_init(void)
130 87
131static void __exit iptable_raw_fini(void) 88static void __exit iptable_raw_fini(void)
132{ 89{
133 nf_unregister_hooks(ipt_ops, ARRAY_SIZE(ipt_ops)); 90 xt_hook_unlink(&packet_raw, rawtable_ops);
134 unregister_pernet_subsys(&iptable_raw_net_ops); 91 unregister_pernet_subsys(&iptable_raw_net_ops);
135} 92}
136 93
diff --git a/net/ipv4/netfilter/iptable_security.c b/net/ipv4/netfilter/iptable_security.c
index 99eb76c65d25..be45bdc4c602 100644
--- a/net/ipv4/netfilter/iptable_security.c
+++ b/net/ipv4/netfilter/iptable_security.c
@@ -17,6 +17,7 @@
17 */ 17 */
18#include <linux/module.h> 18#include <linux/module.h>
19#include <linux/netfilter_ipv4/ip_tables.h> 19#include <linux/netfilter_ipv4/ip_tables.h>
20#include <linux/slab.h>
20#include <net/ip.h> 21#include <net/ip.h>
21 22
22MODULE_LICENSE("GPL"); 23MODULE_LICENSE("GPL");
@@ -27,109 +28,44 @@ MODULE_DESCRIPTION("iptables security table, for MAC rules");
27 (1 << NF_INET_FORWARD) | \ 28 (1 << NF_INET_FORWARD) | \
28 (1 << NF_INET_LOCAL_OUT) 29 (1 << NF_INET_LOCAL_OUT)
29 30
30static const struct
31{
32 struct ipt_replace repl;
33 struct ipt_standard entries[3];
34 struct ipt_error term;
35} initial_table __net_initdata = {
36 .repl = {
37 .name = "security",
38 .valid_hooks = SECURITY_VALID_HOOKS,
39 .num_entries = 4,
40 .size = sizeof(struct ipt_standard) * 3 + sizeof(struct ipt_error),
41 .hook_entry = {
42 [NF_INET_LOCAL_IN] = 0,
43 [NF_INET_FORWARD] = sizeof(struct ipt_standard),
44 [NF_INET_LOCAL_OUT] = sizeof(struct ipt_standard) * 2,
45 },
46 .underflow = {
47 [NF_INET_LOCAL_IN] = 0,
48 [NF_INET_FORWARD] = sizeof(struct ipt_standard),
49 [NF_INET_LOCAL_OUT] = sizeof(struct ipt_standard) * 2,
50 },
51 },
52 .entries = {
53 IPT_STANDARD_INIT(NF_ACCEPT), /* LOCAL_IN */
54 IPT_STANDARD_INIT(NF_ACCEPT), /* FORWARD */
55 IPT_STANDARD_INIT(NF_ACCEPT), /* LOCAL_OUT */
56 },
57 .term = IPT_ERROR_INIT, /* ERROR */
58};
59
60static const struct xt_table security_table = { 31static const struct xt_table security_table = {
61 .name = "security", 32 .name = "security",
62 .valid_hooks = SECURITY_VALID_HOOKS, 33 .valid_hooks = SECURITY_VALID_HOOKS,
63 .me = THIS_MODULE, 34 .me = THIS_MODULE,
64 .af = NFPROTO_IPV4, 35 .af = NFPROTO_IPV4,
36 .priority = NF_IP_PRI_SECURITY,
65}; 37};
66 38
67static unsigned int 39static unsigned int
68ipt_local_in_hook(unsigned int hook, 40iptable_security_hook(unsigned int hook, struct sk_buff *skb,
69 struct sk_buff *skb, 41 const struct net_device *in,
70 const struct net_device *in, 42 const struct net_device *out,
71 const struct net_device *out, 43 int (*okfn)(struct sk_buff *))
72 int (*okfn)(struct sk_buff *))
73{
74 return ipt_do_table(skb, hook, in, out,
75 dev_net(in)->ipv4.iptable_security);
76}
77
78static unsigned int
79ipt_forward_hook(unsigned int hook,
80 struct sk_buff *skb,
81 const struct net_device *in,
82 const struct net_device *out,
83 int (*okfn)(struct sk_buff *))
84{ 44{
85 return ipt_do_table(skb, hook, in, out, 45 const struct net *net;
86 dev_net(in)->ipv4.iptable_security);
87}
88 46
89static unsigned int 47 if (hook == NF_INET_LOCAL_OUT &&
90ipt_local_out_hook(unsigned int hook, 48 (skb->len < sizeof(struct iphdr) ||
91 struct sk_buff *skb, 49 ip_hdrlen(skb) < sizeof(struct iphdr)))
92 const struct net_device *in, 50 /* Somebody is playing with raw sockets. */
93 const struct net_device *out,
94 int (*okfn)(struct sk_buff *))
95{
96 /* Somebody is playing with raw sockets. */
97 if (skb->len < sizeof(struct iphdr)
98 || ip_hdrlen(skb) < sizeof(struct iphdr))
99 return NF_ACCEPT; 51 return NF_ACCEPT;
100 return ipt_do_table(skb, hook, in, out, 52
101 dev_net(out)->ipv4.iptable_security); 53 net = dev_net((in != NULL) ? in : out);
54 return ipt_do_table(skb, hook, in, out, net->ipv4.iptable_security);
102} 55}
103 56
104static struct nf_hook_ops ipt_ops[] __read_mostly = { 57static struct nf_hook_ops *sectbl_ops __read_mostly;
105 {
106 .hook = ipt_local_in_hook,
107 .owner = THIS_MODULE,
108 .pf = NFPROTO_IPV4,
109 .hooknum = NF_INET_LOCAL_IN,
110 .priority = NF_IP_PRI_SECURITY,
111 },
112 {
113 .hook = ipt_forward_hook,
114 .owner = THIS_MODULE,
115 .pf = NFPROTO_IPV4,
116 .hooknum = NF_INET_FORWARD,
117 .priority = NF_IP_PRI_SECURITY,
118 },
119 {
120 .hook = ipt_local_out_hook,
121 .owner = THIS_MODULE,
122 .pf = NFPROTO_IPV4,
123 .hooknum = NF_INET_LOCAL_OUT,
124 .priority = NF_IP_PRI_SECURITY,
125 },
126};
127 58
128static int __net_init iptable_security_net_init(struct net *net) 59static int __net_init iptable_security_net_init(struct net *net)
129{ 60{
130 net->ipv4.iptable_security = 61 struct ipt_replace *repl;
131 ipt_register_table(net, &security_table, &initial_table.repl);
132 62
63 repl = ipt_alloc_initial_table(&security_table);
64 if (repl == NULL)
65 return -ENOMEM;
66 net->ipv4.iptable_security =
67 ipt_register_table(net, &security_table, repl);
68 kfree(repl);
133 if (IS_ERR(net->ipv4.iptable_security)) 69 if (IS_ERR(net->ipv4.iptable_security))
134 return PTR_ERR(net->ipv4.iptable_security); 70 return PTR_ERR(net->ipv4.iptable_security);
135 71
@@ -138,7 +74,7 @@ static int __net_init iptable_security_net_init(struct net *net)
138 74
139static void __net_exit iptable_security_net_exit(struct net *net) 75static void __net_exit iptable_security_net_exit(struct net *net)
140{ 76{
141 ipt_unregister_table(net->ipv4.iptable_security); 77 ipt_unregister_table(net, net->ipv4.iptable_security);
142} 78}
143 79
144static struct pernet_operations iptable_security_net_ops = { 80static struct pernet_operations iptable_security_net_ops = {
@@ -154,9 +90,11 @@ static int __init iptable_security_init(void)
154 if (ret < 0) 90 if (ret < 0)
155 return ret; 91 return ret;
156 92
157 ret = nf_register_hooks(ipt_ops, ARRAY_SIZE(ipt_ops)); 93 sectbl_ops = xt_hook_link(&security_table, iptable_security_hook);
158 if (ret < 0) 94 if (IS_ERR(sectbl_ops)) {
95 ret = PTR_ERR(sectbl_ops);
159 goto cleanup_table; 96 goto cleanup_table;
97 }
160 98
161 return ret; 99 return ret;
162 100
@@ -167,7 +105,7 @@ cleanup_table:
167 105
168static void __exit iptable_security_fini(void) 106static void __exit iptable_security_fini(void)
169{ 107{
170 nf_unregister_hooks(ipt_ops, ARRAY_SIZE(ipt_ops)); 108 xt_hook_unlink(&security_table, sectbl_ops);
171 unregister_pernet_subsys(&iptable_security_net_ops); 109 unregister_pernet_subsys(&iptable_security_net_ops);
172} 110}
173 111
diff --git a/net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c b/net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c
index aa95bb82ee6c..2bb1f87051c4 100644
--- a/net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c
+++ b/net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c
@@ -22,6 +22,7 @@
22#include <net/netfilter/nf_conntrack_helper.h> 22#include <net/netfilter/nf_conntrack_helper.h>
23#include <net/netfilter/nf_conntrack_l4proto.h> 23#include <net/netfilter/nf_conntrack_l4proto.h>
24#include <net/netfilter/nf_conntrack_l3proto.h> 24#include <net/netfilter/nf_conntrack_l3proto.h>
25#include <net/netfilter/nf_conntrack_zones.h>
25#include <net/netfilter/nf_conntrack_core.h> 26#include <net/netfilter/nf_conntrack_core.h>
26#include <net/netfilter/ipv4/nf_conntrack_ipv4.h> 27#include <net/netfilter/ipv4/nf_conntrack_ipv4.h>
27#include <net/netfilter/nf_nat_helper.h> 28#include <net/netfilter/nf_nat_helper.h>
@@ -195,7 +196,6 @@ static int log_invalid_proto_max = 255;
195 196
196static ctl_table ip_ct_sysctl_table[] = { 197static ctl_table ip_ct_sysctl_table[] = {
197 { 198 {
198 .ctl_name = NET_IPV4_NF_CONNTRACK_MAX,
199 .procname = "ip_conntrack_max", 199 .procname = "ip_conntrack_max",
200 .data = &nf_conntrack_max, 200 .data = &nf_conntrack_max,
201 .maxlen = sizeof(int), 201 .maxlen = sizeof(int),
@@ -203,7 +203,6 @@ static ctl_table ip_ct_sysctl_table[] = {
203 .proc_handler = proc_dointvec, 203 .proc_handler = proc_dointvec,
204 }, 204 },
205 { 205 {
206 .ctl_name = NET_IPV4_NF_CONNTRACK_COUNT,
207 .procname = "ip_conntrack_count", 206 .procname = "ip_conntrack_count",
208 .data = &init_net.ct.count, 207 .data = &init_net.ct.count,
209 .maxlen = sizeof(int), 208 .maxlen = sizeof(int),
@@ -211,15 +210,13 @@ static ctl_table ip_ct_sysctl_table[] = {
211 .proc_handler = proc_dointvec, 210 .proc_handler = proc_dointvec,
212 }, 211 },
213 { 212 {
214 .ctl_name = NET_IPV4_NF_CONNTRACK_BUCKETS,
215 .procname = "ip_conntrack_buckets", 213 .procname = "ip_conntrack_buckets",
216 .data = &nf_conntrack_htable_size, 214 .data = &init_net.ct.htable_size,
217 .maxlen = sizeof(unsigned int), 215 .maxlen = sizeof(unsigned int),
218 .mode = 0444, 216 .mode = 0444,
219 .proc_handler = proc_dointvec, 217 .proc_handler = proc_dointvec,
220 }, 218 },
221 { 219 {
222 .ctl_name = NET_IPV4_NF_CONNTRACK_CHECKSUM,
223 .procname = "ip_conntrack_checksum", 220 .procname = "ip_conntrack_checksum",
224 .data = &init_net.ct.sysctl_checksum, 221 .data = &init_net.ct.sysctl_checksum,
225 .maxlen = sizeof(int), 222 .maxlen = sizeof(int),
@@ -227,19 +224,15 @@ static ctl_table ip_ct_sysctl_table[] = {
227 .proc_handler = proc_dointvec, 224 .proc_handler = proc_dointvec,
228 }, 225 },
229 { 226 {
230 .ctl_name = NET_IPV4_NF_CONNTRACK_LOG_INVALID,
231 .procname = "ip_conntrack_log_invalid", 227 .procname = "ip_conntrack_log_invalid",
232 .data = &init_net.ct.sysctl_log_invalid, 228 .data = &init_net.ct.sysctl_log_invalid,
233 .maxlen = sizeof(unsigned int), 229 .maxlen = sizeof(unsigned int),
234 .mode = 0644, 230 .mode = 0644,
235 .proc_handler = proc_dointvec_minmax, 231 .proc_handler = proc_dointvec_minmax,
236 .strategy = sysctl_intvec,
237 .extra1 = &log_invalid_proto_min, 232 .extra1 = &log_invalid_proto_min,
238 .extra2 = &log_invalid_proto_max, 233 .extra2 = &log_invalid_proto_max,
239 }, 234 },
240 { 235 { }
241 .ctl_name = 0
242 }
243}; 236};
244#endif /* CONFIG_SYSCTL && CONFIG_NF_CONNTRACK_PROC_COMPAT */ 237#endif /* CONFIG_SYSCTL && CONFIG_NF_CONNTRACK_PROC_COMPAT */
245 238
@@ -255,10 +248,10 @@ getorigdst(struct sock *sk, int optval, void __user *user, int *len)
255 struct nf_conntrack_tuple tuple; 248 struct nf_conntrack_tuple tuple;
256 249
257 memset(&tuple, 0, sizeof(tuple)); 250 memset(&tuple, 0, sizeof(tuple));
258 tuple.src.u3.ip = inet->rcv_saddr; 251 tuple.src.u3.ip = inet->inet_rcv_saddr;
259 tuple.src.u.tcp.port = inet->sport; 252 tuple.src.u.tcp.port = inet->inet_sport;
260 tuple.dst.u3.ip = inet->daddr; 253 tuple.dst.u3.ip = inet->inet_daddr;
261 tuple.dst.u.tcp.port = inet->dport; 254 tuple.dst.u.tcp.port = inet->inet_dport;
262 tuple.src.l3num = PF_INET; 255 tuple.src.l3num = PF_INET;
263 tuple.dst.protonum = sk->sk_protocol; 256 tuple.dst.protonum = sk->sk_protocol;
264 257
@@ -274,7 +267,7 @@ getorigdst(struct sock *sk, int optval, void __user *user, int *len)
274 return -EINVAL; 267 return -EINVAL;
275 } 268 }
276 269
277 h = nf_conntrack_find_get(sock_net(sk), &tuple); 270 h = nf_conntrack_find_get(sock_net(sk), NF_CT_DEFAULT_ZONE, &tuple);
278 if (h) { 271 if (h) {
279 struct sockaddr_in sin; 272 struct sockaddr_in sin;
280 struct nf_conn *ct = nf_ct_tuplehash_to_ctrack(h); 273 struct nf_conn *ct = nf_ct_tuplehash_to_ctrack(h);
diff --git a/net/ipv4/netfilter/nf_conntrack_l3proto_ipv4_compat.c b/net/ipv4/netfilter/nf_conntrack_l3proto_ipv4_compat.c
index 8668a3defda6..2fb7b76da94f 100644
--- a/net/ipv4/netfilter/nf_conntrack_l3proto_ipv4_compat.c
+++ b/net/ipv4/netfilter/nf_conntrack_l3proto_ipv4_compat.c
@@ -32,7 +32,7 @@ static struct hlist_nulls_node *ct_get_first(struct seq_file *seq)
32 struct hlist_nulls_node *n; 32 struct hlist_nulls_node *n;
33 33
34 for (st->bucket = 0; 34 for (st->bucket = 0;
35 st->bucket < nf_conntrack_htable_size; 35 st->bucket < net->ct.htable_size;
36 st->bucket++) { 36 st->bucket++) {
37 n = rcu_dereference(net->ct.hash[st->bucket].first); 37 n = rcu_dereference(net->ct.hash[st->bucket].first);
38 if (!is_a_nulls(n)) 38 if (!is_a_nulls(n))
@@ -50,7 +50,7 @@ static struct hlist_nulls_node *ct_get_next(struct seq_file *seq,
50 head = rcu_dereference(head->next); 50 head = rcu_dereference(head->next);
51 while (is_a_nulls(head)) { 51 while (is_a_nulls(head)) {
52 if (likely(get_nulls_value(head) == st->bucket)) { 52 if (likely(get_nulls_value(head) == st->bucket)) {
53 if (++st->bucket >= nf_conntrack_htable_size) 53 if (++st->bucket >= net->ct.htable_size)
54 return NULL; 54 return NULL;
55 } 55 }
56 head = rcu_dereference(net->ct.hash[st->bucket].first); 56 head = rcu_dereference(net->ct.hash[st->bucket].first);
diff --git a/net/ipv4/netfilter/nf_conntrack_proto_icmp.c b/net/ipv4/netfilter/nf_conntrack_proto_icmp.c
index d71ba7677344..7404bde95994 100644
--- a/net/ipv4/netfilter/nf_conntrack_proto_icmp.c
+++ b/net/ipv4/netfilter/nf_conntrack_proto_icmp.c
@@ -18,6 +18,7 @@
18#include <net/netfilter/nf_conntrack_tuple.h> 18#include <net/netfilter/nf_conntrack_tuple.h>
19#include <net/netfilter/nf_conntrack_l4proto.h> 19#include <net/netfilter/nf_conntrack_l4proto.h>
20#include <net/netfilter/nf_conntrack_core.h> 20#include <net/netfilter/nf_conntrack_core.h>
21#include <net/netfilter/nf_conntrack_zones.h>
21#include <net/netfilter/nf_log.h> 22#include <net/netfilter/nf_log.h>
22 23
23static unsigned int nf_ct_icmp_timeout __read_mostly = 30*HZ; 24static unsigned int nf_ct_icmp_timeout __read_mostly = 30*HZ;
@@ -54,8 +55,8 @@ static const u_int8_t invmap[] = {
54static bool icmp_invert_tuple(struct nf_conntrack_tuple *tuple, 55static bool icmp_invert_tuple(struct nf_conntrack_tuple *tuple,
55 const struct nf_conntrack_tuple *orig) 56 const struct nf_conntrack_tuple *orig)
56{ 57{
57 if (orig->dst.u.icmp.type >= sizeof(invmap) 58 if (orig->dst.u.icmp.type >= sizeof(invmap) ||
58 || !invmap[orig->dst.u.icmp.type]) 59 !invmap[orig->dst.u.icmp.type])
59 return false; 60 return false;
60 61
61 tuple->src.u.icmp.id = orig->src.u.icmp.id; 62 tuple->src.u.icmp.id = orig->src.u.icmp.id;
@@ -101,8 +102,8 @@ static bool icmp_new(struct nf_conn *ct, const struct sk_buff *skb,
101 [ICMP_ADDRESS] = 1 102 [ICMP_ADDRESS] = 1
102 }; 103 };
103 104
104 if (ct->tuplehash[0].tuple.dst.u.icmp.type >= sizeof(valid_new) 105 if (ct->tuplehash[0].tuple.dst.u.icmp.type >= sizeof(valid_new) ||
105 || !valid_new[ct->tuplehash[0].tuple.dst.u.icmp.type]) { 106 !valid_new[ct->tuplehash[0].tuple.dst.u.icmp.type]) {
106 /* Can't create a new ICMP `conn' with this. */ 107 /* Can't create a new ICMP `conn' with this. */
107 pr_debug("icmp: can't create new conn with type %u\n", 108 pr_debug("icmp: can't create new conn with type %u\n",
108 ct->tuplehash[0].tuple.dst.u.icmp.type); 109 ct->tuplehash[0].tuple.dst.u.icmp.type);
@@ -114,13 +115,14 @@ static bool icmp_new(struct nf_conn *ct, const struct sk_buff *skb,
114 115
115/* Returns conntrack if it dealt with ICMP, and filled in skb fields */ 116/* Returns conntrack if it dealt with ICMP, and filled in skb fields */
116static int 117static int
117icmp_error_message(struct net *net, struct sk_buff *skb, 118icmp_error_message(struct net *net, struct nf_conn *tmpl, struct sk_buff *skb,
118 enum ip_conntrack_info *ctinfo, 119 enum ip_conntrack_info *ctinfo,
119 unsigned int hooknum) 120 unsigned int hooknum)
120{ 121{
121 struct nf_conntrack_tuple innertuple, origtuple; 122 struct nf_conntrack_tuple innertuple, origtuple;
122 const struct nf_conntrack_l4proto *innerproto; 123 const struct nf_conntrack_l4proto *innerproto;
123 const struct nf_conntrack_tuple_hash *h; 124 const struct nf_conntrack_tuple_hash *h;
125 u16 zone = tmpl ? nf_ct_zone(tmpl) : NF_CT_DEFAULT_ZONE;
124 126
125 NF_CT_ASSERT(skb->nfct == NULL); 127 NF_CT_ASSERT(skb->nfct == NULL);
126 128
@@ -146,7 +148,7 @@ icmp_error_message(struct net *net, struct sk_buff *skb,
146 148
147 *ctinfo = IP_CT_RELATED; 149 *ctinfo = IP_CT_RELATED;
148 150
149 h = nf_conntrack_find_get(net, &innertuple); 151 h = nf_conntrack_find_get(net, zone, &innertuple);
150 if (!h) { 152 if (!h) {
151 pr_debug("icmp_error_message: no match\n"); 153 pr_debug("icmp_error_message: no match\n");
152 return -NF_ACCEPT; 154 return -NF_ACCEPT;
@@ -163,7 +165,8 @@ icmp_error_message(struct net *net, struct sk_buff *skb,
163 165
164/* Small and modified version of icmp_rcv */ 166/* Small and modified version of icmp_rcv */
165static int 167static int
166icmp_error(struct net *net, struct sk_buff *skb, unsigned int dataoff, 168icmp_error(struct net *net, struct nf_conn *tmpl,
169 struct sk_buff *skb, unsigned int dataoff,
167 enum ip_conntrack_info *ctinfo, u_int8_t pf, unsigned int hooknum) 170 enum ip_conntrack_info *ctinfo, u_int8_t pf, unsigned int hooknum)
168{ 171{
169 const struct icmphdr *icmph; 172 const struct icmphdr *icmph;
@@ -201,14 +204,14 @@ icmp_error(struct net *net, struct sk_buff *skb, unsigned int dataoff,
201 } 204 }
202 205
203 /* Need to track icmp error message? */ 206 /* Need to track icmp error message? */
204 if (icmph->type != ICMP_DEST_UNREACH 207 if (icmph->type != ICMP_DEST_UNREACH &&
205 && icmph->type != ICMP_SOURCE_QUENCH 208 icmph->type != ICMP_SOURCE_QUENCH &&
206 && icmph->type != ICMP_TIME_EXCEEDED 209 icmph->type != ICMP_TIME_EXCEEDED &&
207 && icmph->type != ICMP_PARAMETERPROB 210 icmph->type != ICMP_PARAMETERPROB &&
208 && icmph->type != ICMP_REDIRECT) 211 icmph->type != ICMP_REDIRECT)
209 return NF_ACCEPT; 212 return NF_ACCEPT;
210 213
211 return icmp_error_message(net, skb, ctinfo, hooknum); 214 return icmp_error_message(net, tmpl, skb, ctinfo, hooknum);
212} 215}
213 216
214#if defined(CONFIG_NF_CT_NETLINK) || defined(CONFIG_NF_CT_NETLINK_MODULE) 217#if defined(CONFIG_NF_CT_NETLINK) || defined(CONFIG_NF_CT_NETLINK_MODULE)
@@ -238,17 +241,17 @@ static const struct nla_policy icmp_nla_policy[CTA_PROTO_MAX+1] = {
238static int icmp_nlattr_to_tuple(struct nlattr *tb[], 241static int icmp_nlattr_to_tuple(struct nlattr *tb[],
239 struct nf_conntrack_tuple *tuple) 242 struct nf_conntrack_tuple *tuple)
240{ 243{
241 if (!tb[CTA_PROTO_ICMP_TYPE] 244 if (!tb[CTA_PROTO_ICMP_TYPE] ||
242 || !tb[CTA_PROTO_ICMP_CODE] 245 !tb[CTA_PROTO_ICMP_CODE] ||
243 || !tb[CTA_PROTO_ICMP_ID]) 246 !tb[CTA_PROTO_ICMP_ID])
244 return -EINVAL; 247 return -EINVAL;
245 248
246 tuple->dst.u.icmp.type = nla_get_u8(tb[CTA_PROTO_ICMP_TYPE]); 249 tuple->dst.u.icmp.type = nla_get_u8(tb[CTA_PROTO_ICMP_TYPE]);
247 tuple->dst.u.icmp.code = nla_get_u8(tb[CTA_PROTO_ICMP_CODE]); 250 tuple->dst.u.icmp.code = nla_get_u8(tb[CTA_PROTO_ICMP_CODE]);
248 tuple->src.u.icmp.id = nla_get_be16(tb[CTA_PROTO_ICMP_ID]); 251 tuple->src.u.icmp.id = nla_get_be16(tb[CTA_PROTO_ICMP_ID]);
249 252
250 if (tuple->dst.u.icmp.type >= sizeof(invmap) 253 if (tuple->dst.u.icmp.type >= sizeof(invmap) ||
251 || !invmap[tuple->dst.u.icmp.type]) 254 !invmap[tuple->dst.u.icmp.type])
252 return -EINVAL; 255 return -EINVAL;
253 256
254 return 0; 257 return 0;
@@ -270,9 +273,7 @@ static struct ctl_table icmp_sysctl_table[] = {
270 .mode = 0644, 273 .mode = 0644,
271 .proc_handler = proc_dointvec_jiffies, 274 .proc_handler = proc_dointvec_jiffies,
272 }, 275 },
273 { 276 { }
274 .ctl_name = 0
275 }
276}; 277};
277#ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT 278#ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
278static struct ctl_table icmp_compat_sysctl_table[] = { 279static struct ctl_table icmp_compat_sysctl_table[] = {
@@ -283,9 +284,7 @@ static struct ctl_table icmp_compat_sysctl_table[] = {
283 .mode = 0644, 284 .mode = 0644,
284 .proc_handler = proc_dointvec_jiffies, 285 .proc_handler = proc_dointvec_jiffies,
285 }, 286 },
286 { 287 { }
287 .ctl_name = 0
288 }
289}; 288};
290#endif /* CONFIG_NF_CONNTRACK_PROC_COMPAT */ 289#endif /* CONFIG_NF_CONNTRACK_PROC_COMPAT */
291#endif /* CONFIG_SYSCTL */ 290#endif /* CONFIG_SYSCTL */
diff --git a/net/ipv4/netfilter/nf_defrag_ipv4.c b/net/ipv4/netfilter/nf_defrag_ipv4.c
index fa2d6b6fc3e5..cb763ae9ed90 100644
--- a/net/ipv4/netfilter/nf_defrag_ipv4.c
+++ b/net/ipv4/netfilter/nf_defrag_ipv4.c
@@ -14,8 +14,13 @@
14#include <net/route.h> 14#include <net/route.h>
15#include <net/ip.h> 15#include <net/ip.h>
16 16
17#include <linux/netfilter_bridge.h>
17#include <linux/netfilter_ipv4.h> 18#include <linux/netfilter_ipv4.h>
18#include <net/netfilter/ipv4/nf_defrag_ipv4.h> 19#include <net/netfilter/ipv4/nf_defrag_ipv4.h>
20#if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE)
21#include <net/netfilter/nf_conntrack.h>
22#endif
23#include <net/netfilter/nf_conntrack_zones.h>
19 24
20/* Returns new sk_buff, or NULL */ 25/* Returns new sk_buff, or NULL */
21static int nf_ct_ipv4_gather_frags(struct sk_buff *skb, u_int32_t user) 26static int nf_ct_ipv4_gather_frags(struct sk_buff *skb, u_int32_t user)
@@ -34,6 +39,27 @@ static int nf_ct_ipv4_gather_frags(struct sk_buff *skb, u_int32_t user)
34 return err; 39 return err;
35} 40}
36 41
42static enum ip_defrag_users nf_ct_defrag_user(unsigned int hooknum,
43 struct sk_buff *skb)
44{
45 u16 zone = NF_CT_DEFAULT_ZONE;
46
47#if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE)
48 if (skb->nfct)
49 zone = nf_ct_zone((struct nf_conn *)skb->nfct);
50#endif
51
52#ifdef CONFIG_BRIDGE_NETFILTER
53 if (skb->nf_bridge &&
54 skb->nf_bridge->mask & BRNF_NF_BRIDGE_PREROUTING)
55 return IP_DEFRAG_CONNTRACK_BRIDGE_IN + zone;
56#endif
57 if (hooknum == NF_INET_PRE_ROUTING)
58 return IP_DEFRAG_CONNTRACK_IN + zone;
59 else
60 return IP_DEFRAG_CONNTRACK_OUT + zone;
61}
62
37static unsigned int ipv4_conntrack_defrag(unsigned int hooknum, 63static unsigned int ipv4_conntrack_defrag(unsigned int hooknum,
38 struct sk_buff *skb, 64 struct sk_buff *skb,
39 const struct net_device *in, 65 const struct net_device *in,
@@ -44,16 +70,14 @@ static unsigned int ipv4_conntrack_defrag(unsigned int hooknum,
44#if !defined(CONFIG_NF_NAT) && !defined(CONFIG_NF_NAT_MODULE) 70#if !defined(CONFIG_NF_NAT) && !defined(CONFIG_NF_NAT_MODULE)
45 /* Previously seen (loopback)? Ignore. Do this before 71 /* Previously seen (loopback)? Ignore. Do this before
46 fragment check. */ 72 fragment check. */
47 if (skb->nfct) 73 if (skb->nfct && !nf_ct_is_template((struct nf_conn *)skb->nfct))
48 return NF_ACCEPT; 74 return NF_ACCEPT;
49#endif 75#endif
50#endif 76#endif
51 /* Gather fragments. */ 77 /* Gather fragments. */
52 if (ip_hdr(skb)->frag_off & htons(IP_MF | IP_OFFSET)) { 78 if (ip_hdr(skb)->frag_off & htons(IP_MF | IP_OFFSET)) {
53 if (nf_ct_ipv4_gather_frags(skb, 79 enum ip_defrag_users user = nf_ct_defrag_user(hooknum, skb);
54 hooknum == NF_INET_PRE_ROUTING ? 80 if (nf_ct_ipv4_gather_frags(skb, user))
55 IP_DEFRAG_CONNTRACK_IN :
56 IP_DEFRAG_CONNTRACK_OUT))
57 return NF_STOLEN; 81 return NF_STOLEN;
58 } 82 }
59 return NF_ACCEPT; 83 return NF_ACCEPT;
diff --git a/net/ipv4/netfilter/nf_nat_core.c b/net/ipv4/netfilter/nf_nat_core.c
index fe1a64479dd0..4f8bddb760c9 100644
--- a/net/ipv4/netfilter/nf_nat_core.c
+++ b/net/ipv4/netfilter/nf_nat_core.c
@@ -12,6 +12,7 @@
12#include <linux/types.h> 12#include <linux/types.h>
13#include <linux/timer.h> 13#include <linux/timer.h>
14#include <linux/skbuff.h> 14#include <linux/skbuff.h>
15#include <linux/gfp.h>
15#include <net/checksum.h> 16#include <net/checksum.h>
16#include <net/icmp.h> 17#include <net/icmp.h>
17#include <net/ip.h> 18#include <net/ip.h>
@@ -30,14 +31,12 @@
30#include <net/netfilter/nf_conntrack_helper.h> 31#include <net/netfilter/nf_conntrack_helper.h>
31#include <net/netfilter/nf_conntrack_l3proto.h> 32#include <net/netfilter/nf_conntrack_l3proto.h>
32#include <net/netfilter/nf_conntrack_l4proto.h> 33#include <net/netfilter/nf_conntrack_l4proto.h>
34#include <net/netfilter/nf_conntrack_zones.h>
33 35
34static DEFINE_SPINLOCK(nf_nat_lock); 36static DEFINE_SPINLOCK(nf_nat_lock);
35 37
36static struct nf_conntrack_l3proto *l3proto __read_mostly; 38static struct nf_conntrack_l3proto *l3proto __read_mostly;
37 39
38/* Calculated at init based on memory size */
39static unsigned int nf_nat_htable_size __read_mostly;
40
41#define MAX_IP_NAT_PROTO 256 40#define MAX_IP_NAT_PROTO 256
42static const struct nf_nat_protocol *nf_nat_protos[MAX_IP_NAT_PROTO] 41static const struct nf_nat_protocol *nf_nat_protos[MAX_IP_NAT_PROTO]
43 __read_mostly; 42 __read_mostly;
@@ -72,15 +71,16 @@ EXPORT_SYMBOL_GPL(nf_nat_proto_put);
72 71
73/* We keep an extra hash for each conntrack, for fast searching. */ 72/* We keep an extra hash for each conntrack, for fast searching. */
74static inline unsigned int 73static inline unsigned int
75hash_by_src(const struct nf_conntrack_tuple *tuple) 74hash_by_src(const struct net *net, u16 zone,
75 const struct nf_conntrack_tuple *tuple)
76{ 76{
77 unsigned int hash; 77 unsigned int hash;
78 78
79 /* Original src, to ensure we map it consistently if poss. */ 79 /* Original src, to ensure we map it consistently if poss. */
80 hash = jhash_3words((__force u32)tuple->src.u3.ip, 80 hash = jhash_3words((__force u32)tuple->src.u3.ip,
81 (__force u32)tuple->src.u.all, 81 (__force u32)tuple->src.u.all ^ zone,
82 tuple->dst.protonum, 0); 82 tuple->dst.protonum, 0);
83 return ((u64)hash * nf_nat_htable_size) >> 32; 83 return ((u64)hash * net->ipv4.nat_htable_size) >> 32;
84} 84}
85 85
86/* Is this tuple already taken? (not by us) */ 86/* Is this tuple already taken? (not by us) */
@@ -142,12 +142,12 @@ same_src(const struct nf_conn *ct,
142 142
143/* Only called for SRC manip */ 143/* Only called for SRC manip */
144static int 144static int
145find_appropriate_src(struct net *net, 145find_appropriate_src(struct net *net, u16 zone,
146 const struct nf_conntrack_tuple *tuple, 146 const struct nf_conntrack_tuple *tuple,
147 struct nf_conntrack_tuple *result, 147 struct nf_conntrack_tuple *result,
148 const struct nf_nat_range *range) 148 const struct nf_nat_range *range)
149{ 149{
150 unsigned int h = hash_by_src(tuple); 150 unsigned int h = hash_by_src(net, zone, tuple);
151 const struct nf_conn_nat *nat; 151 const struct nf_conn_nat *nat;
152 const struct nf_conn *ct; 152 const struct nf_conn *ct;
153 const struct hlist_node *n; 153 const struct hlist_node *n;
@@ -155,7 +155,7 @@ find_appropriate_src(struct net *net,
155 rcu_read_lock(); 155 rcu_read_lock();
156 hlist_for_each_entry_rcu(nat, n, &net->ipv4.nat_bysource[h], bysource) { 156 hlist_for_each_entry_rcu(nat, n, &net->ipv4.nat_bysource[h], bysource) {
157 ct = nat->ct; 157 ct = nat->ct;
158 if (same_src(ct, tuple)) { 158 if (same_src(ct, tuple) && nf_ct_zone(ct) == zone) {
159 /* Copy source part from reply tuple. */ 159 /* Copy source part from reply tuple. */
160 nf_ct_invert_tuplepr(result, 160 nf_ct_invert_tuplepr(result,
161 &ct->tuplehash[IP_CT_DIR_REPLY].tuple); 161 &ct->tuplehash[IP_CT_DIR_REPLY].tuple);
@@ -178,7 +178,7 @@ find_appropriate_src(struct net *net,
178 the ip with the lowest src-ip/dst-ip/proto usage. 178 the ip with the lowest src-ip/dst-ip/proto usage.
179*/ 179*/
180static void 180static void
181find_best_ips_proto(struct nf_conntrack_tuple *tuple, 181find_best_ips_proto(u16 zone, struct nf_conntrack_tuple *tuple,
182 const struct nf_nat_range *range, 182 const struct nf_nat_range *range,
183 const struct nf_conn *ct, 183 const struct nf_conn *ct,
184 enum nf_nat_manip_type maniptype) 184 enum nf_nat_manip_type maniptype)
@@ -212,7 +212,7 @@ find_best_ips_proto(struct nf_conntrack_tuple *tuple,
212 maxip = ntohl(range->max_ip); 212 maxip = ntohl(range->max_ip);
213 j = jhash_2words((__force u32)tuple->src.u3.ip, 213 j = jhash_2words((__force u32)tuple->src.u3.ip,
214 range->flags & IP_NAT_RANGE_PERSISTENT ? 214 range->flags & IP_NAT_RANGE_PERSISTENT ?
215 0 : (__force u32)tuple->dst.u3.ip, 0); 215 0 : (__force u32)tuple->dst.u3.ip ^ zone, 0);
216 j = ((u64)j * (maxip - minip + 1)) >> 32; 216 j = ((u64)j * (maxip - minip + 1)) >> 32;
217 *var_ipp = htonl(minip + j); 217 *var_ipp = htonl(minip + j);
218} 218}
@@ -232,6 +232,7 @@ get_unique_tuple(struct nf_conntrack_tuple *tuple,
232{ 232{
233 struct net *net = nf_ct_net(ct); 233 struct net *net = nf_ct_net(ct);
234 const struct nf_nat_protocol *proto; 234 const struct nf_nat_protocol *proto;
235 u16 zone = nf_ct_zone(ct);
235 236
236 /* 1) If this srcip/proto/src-proto-part is currently mapped, 237 /* 1) If this srcip/proto/src-proto-part is currently mapped,
237 and that same mapping gives a unique tuple within the given 238 and that same mapping gives a unique tuple within the given
@@ -242,7 +243,7 @@ get_unique_tuple(struct nf_conntrack_tuple *tuple,
242 manips not an issue. */ 243 manips not an issue. */
243 if (maniptype == IP_NAT_MANIP_SRC && 244 if (maniptype == IP_NAT_MANIP_SRC &&
244 !(range->flags & IP_NAT_RANGE_PROTO_RANDOM)) { 245 !(range->flags & IP_NAT_RANGE_PROTO_RANDOM)) {
245 if (find_appropriate_src(net, orig_tuple, tuple, range)) { 246 if (find_appropriate_src(net, zone, orig_tuple, tuple, range)) {
246 pr_debug("get_unique_tuple: Found current src map\n"); 247 pr_debug("get_unique_tuple: Found current src map\n");
247 if (!nf_nat_used_tuple(tuple, ct)) 248 if (!nf_nat_used_tuple(tuple, ct))
248 return; 249 return;
@@ -252,7 +253,7 @@ get_unique_tuple(struct nf_conntrack_tuple *tuple,
252 /* 2) Select the least-used IP/proto combination in the given 253 /* 2) Select the least-used IP/proto combination in the given
253 range. */ 254 range. */
254 *tuple = *orig_tuple; 255 *tuple = *orig_tuple;
255 find_best_ips_proto(tuple, range, ct, maniptype); 256 find_best_ips_proto(zone, tuple, range, ct, maniptype);
256 257
257 /* 3) The per-protocol part of the manip is made to map into 258 /* 3) The per-protocol part of the manip is made to map into
258 the range to make a unique tuple. */ 259 the range to make a unique tuple. */
@@ -330,7 +331,8 @@ nf_nat_setup_info(struct nf_conn *ct,
330 if (have_to_hash) { 331 if (have_to_hash) {
331 unsigned int srchash; 332 unsigned int srchash;
332 333
333 srchash = hash_by_src(&ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple); 334 srchash = hash_by_src(net, nf_ct_zone(ct),
335 &ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple);
334 spin_lock_bh(&nf_nat_lock); 336 spin_lock_bh(&nf_nat_lock);
335 /* nf_conntrack_alter_reply might re-allocate exntension aera */ 337 /* nf_conntrack_alter_reply might re-allocate exntension aera */
336 nat = nfct_nat(ct); 338 nat = nfct_nat(ct);
@@ -679,8 +681,10 @@ nfnetlink_parse_nat_setup(struct nf_conn *ct,
679 681
680static int __net_init nf_nat_net_init(struct net *net) 682static int __net_init nf_nat_net_init(struct net *net)
681{ 683{
682 net->ipv4.nat_bysource = nf_ct_alloc_hashtable(&nf_nat_htable_size, 684 /* Leave them the same for the moment. */
683 &net->ipv4.nat_vmalloced, 0); 685 net->ipv4.nat_htable_size = net->ct.htable_size;
686 net->ipv4.nat_bysource = nf_ct_alloc_hashtable(&net->ipv4.nat_htable_size,
687 &net->ipv4.nat_vmalloced, 0);
684 if (!net->ipv4.nat_bysource) 688 if (!net->ipv4.nat_bysource)
685 return -ENOMEM; 689 return -ENOMEM;
686 return 0; 690 return 0;
@@ -703,7 +707,7 @@ static void __net_exit nf_nat_net_exit(struct net *net)
703 nf_ct_iterate_cleanup(net, &clean_nat, NULL); 707 nf_ct_iterate_cleanup(net, &clean_nat, NULL);
704 synchronize_rcu(); 708 synchronize_rcu();
705 nf_ct_free_hashtable(net->ipv4.nat_bysource, net->ipv4.nat_vmalloced, 709 nf_ct_free_hashtable(net->ipv4.nat_bysource, net->ipv4.nat_vmalloced,
706 nf_nat_htable_size); 710 net->ipv4.nat_htable_size);
707} 711}
708 712
709static struct pernet_operations nf_nat_net_ops = { 713static struct pernet_operations nf_nat_net_ops = {
@@ -724,9 +728,6 @@ static int __init nf_nat_init(void)
724 return ret; 728 return ret;
725 } 729 }
726 730
727 /* Leave them the same for the moment. */
728 nf_nat_htable_size = nf_conntrack_htable_size;
729
730 ret = register_pernet_subsys(&nf_nat_net_ops); 731 ret = register_pernet_subsys(&nf_nat_net_ops);
731 if (ret < 0) 732 if (ret < 0)
732 goto cleanup_extend; 733 goto cleanup_extend;
diff --git a/net/ipv4/netfilter/nf_nat_ftp.c b/net/ipv4/netfilter/nf_nat_ftp.c
index a1d5d58a58bf..86e0e84ff0a0 100644
--- a/net/ipv4/netfilter/nf_nat_ftp.c
+++ b/net/ipv4/netfilter/nf_nat_ftp.c
@@ -27,76 +27,29 @@ MODULE_ALIAS("ip_nat_ftp");
27 27
28/* FIXME: Time out? --RR */ 28/* FIXME: Time out? --RR */
29 29
30static int 30static int nf_nat_ftp_fmt_cmd(enum nf_ct_ftp_type type,
31mangle_rfc959_packet(struct sk_buff *skb, 31 char *buffer, size_t buflen,
32 __be32 newip, 32 __be32 addr, u16 port)
33 u_int16_t port,
34 unsigned int matchoff,
35 unsigned int matchlen,
36 struct nf_conn *ct,
37 enum ip_conntrack_info ctinfo)
38{ 33{
39 char buffer[sizeof("nnn,nnn,nnn,nnn,nnn,nnn")]; 34 switch (type) {
40 35 case NF_CT_FTP_PORT:
41 sprintf(buffer, "%u,%u,%u,%u,%u,%u", 36 case NF_CT_FTP_PASV:
42 NIPQUAD(newip), port>>8, port&0xFF); 37 return snprintf(buffer, buflen, "%u,%u,%u,%u,%u,%u",
43 38 ((unsigned char *)&addr)[0],
44 pr_debug("calling nf_nat_mangle_tcp_packet\n"); 39 ((unsigned char *)&addr)[1],
45 40 ((unsigned char *)&addr)[2],
46 return nf_nat_mangle_tcp_packet(skb, ct, ctinfo, matchoff, 41 ((unsigned char *)&addr)[3],
47 matchlen, buffer, strlen(buffer)); 42 port >> 8,
48} 43 port & 0xFF);
49 44 case NF_CT_FTP_EPRT:
50/* |1|132.235.1.2|6275| */ 45 return snprintf(buffer, buflen, "|1|%pI4|%u|", &addr, port);
51static int 46 case NF_CT_FTP_EPSV:
52mangle_eprt_packet(struct sk_buff *skb, 47 return snprintf(buffer, buflen, "|||%u|", port);
53 __be32 newip, 48 }
54 u_int16_t port,
55 unsigned int matchoff,
56 unsigned int matchlen,
57 struct nf_conn *ct,
58 enum ip_conntrack_info ctinfo)
59{
60 char buffer[sizeof("|1|255.255.255.255|65535|")];
61
62 sprintf(buffer, "|1|%u.%u.%u.%u|%u|", NIPQUAD(newip), port);
63
64 pr_debug("calling nf_nat_mangle_tcp_packet\n");
65
66 return nf_nat_mangle_tcp_packet(skb, ct, ctinfo, matchoff,
67 matchlen, buffer, strlen(buffer));
68}
69
70/* |1|132.235.1.2|6275| */
71static int
72mangle_epsv_packet(struct sk_buff *skb,
73 __be32 newip,
74 u_int16_t port,
75 unsigned int matchoff,
76 unsigned int matchlen,
77 struct nf_conn *ct,
78 enum ip_conntrack_info ctinfo)
79{
80 char buffer[sizeof("|||65535|")];
81
82 sprintf(buffer, "|||%u|", port);
83
84 pr_debug("calling nf_nat_mangle_tcp_packet\n");
85 49
86 return nf_nat_mangle_tcp_packet(skb, ct, ctinfo, matchoff, 50 return 0;
87 matchlen, buffer, strlen(buffer));
88} 51}
89 52
90static int (*mangle[])(struct sk_buff *, __be32, u_int16_t,
91 unsigned int, unsigned int, struct nf_conn *,
92 enum ip_conntrack_info)
93= {
94 [NF_CT_FTP_PORT] = mangle_rfc959_packet,
95 [NF_CT_FTP_PASV] = mangle_rfc959_packet,
96 [NF_CT_FTP_EPRT] = mangle_eprt_packet,
97 [NF_CT_FTP_EPSV] = mangle_epsv_packet
98};
99
100/* So, this packet has hit the connection tracking matching code. 53/* So, this packet has hit the connection tracking matching code.
101 Mangle it, and change the expectation to match the new version. */ 54 Mangle it, and change the expectation to match the new version. */
102static unsigned int nf_nat_ftp(struct sk_buff *skb, 55static unsigned int nf_nat_ftp(struct sk_buff *skb,
@@ -110,6 +63,8 @@ static unsigned int nf_nat_ftp(struct sk_buff *skb,
110 u_int16_t port; 63 u_int16_t port;
111 int dir = CTINFO2DIR(ctinfo); 64 int dir = CTINFO2DIR(ctinfo);
112 struct nf_conn *ct = exp->master; 65 struct nf_conn *ct = exp->master;
66 char buffer[sizeof("|1|255.255.255.255|65535|")];
67 unsigned int buflen;
113 68
114 pr_debug("FTP_NAT: type %i, off %u len %u\n", type, matchoff, matchlen); 69 pr_debug("FTP_NAT: type %i, off %u len %u\n", type, matchoff, matchlen);
115 70
@@ -132,11 +87,21 @@ static unsigned int nf_nat_ftp(struct sk_buff *skb,
132 if (port == 0) 87 if (port == 0)
133 return NF_DROP; 88 return NF_DROP;
134 89
135 if (!mangle[type](skb, newip, port, matchoff, matchlen, ct, ctinfo)) { 90 buflen = nf_nat_ftp_fmt_cmd(type, buffer, sizeof(buffer), newip, port);
136 nf_ct_unexpect_related(exp); 91 if (!buflen)
137 return NF_DROP; 92 goto out;
138 } 93
94 pr_debug("calling nf_nat_mangle_tcp_packet\n");
95
96 if (!nf_nat_mangle_tcp_packet(skb, ct, ctinfo, matchoff,
97 matchlen, buffer, buflen))
98 goto out;
99
139 return NF_ACCEPT; 100 return NF_ACCEPT;
101
102out:
103 nf_ct_unexpect_related(exp);
104 return NF_DROP;
140} 105}
141 106
142static void __exit nf_nat_ftp_fini(void) 107static void __exit nf_nat_ftp_fini(void)
diff --git a/net/ipv4/netfilter/nf_nat_helper.c b/net/ipv4/netfilter/nf_nat_helper.c
index f9520fa3aba9..4a0c6b548eee 100644
--- a/net/ipv4/netfilter/nf_nat_helper.c
+++ b/net/ipv4/netfilter/nf_nat_helper.c
@@ -8,6 +8,7 @@
8 * published by the Free Software Foundation. 8 * published by the Free Software Foundation.
9 */ 9 */
10#include <linux/module.h> 10#include <linux/module.h>
11#include <linux/gfp.h>
11#include <linux/kmod.h> 12#include <linux/kmod.h>
12#include <linux/types.h> 13#include <linux/types.h>
13#include <linux/timer.h> 14#include <linux/timer.h>
@@ -41,18 +42,14 @@ adjust_tcp_sequence(u32 seq,
41 struct nf_conn *ct, 42 struct nf_conn *ct,
42 enum ip_conntrack_info ctinfo) 43 enum ip_conntrack_info ctinfo)
43{ 44{
44 int dir; 45 enum ip_conntrack_dir dir = CTINFO2DIR(ctinfo);
45 struct nf_nat_seq *this_way, *other_way;
46 struct nf_conn_nat *nat = nfct_nat(ct); 46 struct nf_conn_nat *nat = nfct_nat(ct);
47 struct nf_nat_seq *this_way = &nat->seq[dir];
47 48
48 pr_debug("adjust_tcp_sequence: seq = %u, sizediff = %d\n", seq, seq); 49 pr_debug("adjust_tcp_sequence: seq = %u, sizediff = %d\n",
49 50 seq, sizediff);
50 dir = CTINFO2DIR(ctinfo);
51
52 this_way = &nat->seq[dir];
53 other_way = &nat->seq[!dir];
54 51
55 pr_debug("nf_nat_resize_packet: Seq_offset before: "); 52 pr_debug("adjust_tcp_sequence: Seq_offset before: ");
56 DUMP_OFFSET(this_way); 53 DUMP_OFFSET(this_way);
57 54
58 spin_lock_bh(&nf_nat_seqofs_lock); 55 spin_lock_bh(&nf_nat_seqofs_lock);
@@ -63,13 +60,13 @@ adjust_tcp_sequence(u32 seq,
63 * retransmit */ 60 * retransmit */
64 if (this_way->offset_before == this_way->offset_after || 61 if (this_way->offset_before == this_way->offset_after ||
65 before(this_way->correction_pos, seq)) { 62 before(this_way->correction_pos, seq)) {
66 this_way->correction_pos = seq; 63 this_way->correction_pos = seq;
67 this_way->offset_before = this_way->offset_after; 64 this_way->offset_before = this_way->offset_after;
68 this_way->offset_after += sizediff; 65 this_way->offset_after += sizediff;
69 } 66 }
70 spin_unlock_bh(&nf_nat_seqofs_lock); 67 spin_unlock_bh(&nf_nat_seqofs_lock);
71 68
72 pr_debug("nf_nat_resize_packet: Seq_offset after: "); 69 pr_debug("adjust_tcp_sequence: Seq_offset after: ");
73 DUMP_OFFSET(this_way); 70 DUMP_OFFSET(this_way);
74} 71}
75 72
@@ -145,6 +142,17 @@ static int enlarge_skb(struct sk_buff *skb, unsigned int extra)
145 return 1; 142 return 1;
146} 143}
147 144
145void nf_nat_set_seq_adjust(struct nf_conn *ct, enum ip_conntrack_info ctinfo,
146 __be32 seq, s16 off)
147{
148 if (!off)
149 return;
150 set_bit(IPS_SEQ_ADJUST_BIT, &ct->status);
151 adjust_tcp_sequence(ntohl(seq), off, ct, ctinfo);
152 nf_conntrack_event_cache(IPCT_NATSEQADJ, ct);
153}
154EXPORT_SYMBOL_GPL(nf_nat_set_seq_adjust);
155
148/* Generic function for mangling variable-length address changes inside 156/* Generic function for mangling variable-length address changes inside
149 * NATed TCP connections (like the PORT XXX,XXX,XXX,XXX,XXX,XXX 157 * NATed TCP connections (like the PORT XXX,XXX,XXX,XXX,XXX,XXX
150 * command in FTP). 158 * command in FTP).
@@ -153,14 +161,13 @@ static int enlarge_skb(struct sk_buff *skb, unsigned int extra)
153 * skb enlargement, ... 161 * skb enlargement, ...
154 * 162 *
155 * */ 163 * */
156int 164int __nf_nat_mangle_tcp_packet(struct sk_buff *skb,
157nf_nat_mangle_tcp_packet(struct sk_buff *skb, 165 struct nf_conn *ct,
158 struct nf_conn *ct, 166 enum ip_conntrack_info ctinfo,
159 enum ip_conntrack_info ctinfo, 167 unsigned int match_offset,
160 unsigned int match_offset, 168 unsigned int match_len,
161 unsigned int match_len, 169 const char *rep_buffer,
162 const char *rep_buffer, 170 unsigned int rep_len, bool adjust)
163 unsigned int rep_len)
164{ 171{
165 struct rtable *rt = skb_rtable(skb); 172 struct rtable *rt = skb_rtable(skb);
166 struct iphdr *iph; 173 struct iphdr *iph;
@@ -206,16 +213,13 @@ nf_nat_mangle_tcp_packet(struct sk_buff *skb,
206 inet_proto_csum_replace2(&tcph->check, skb, 213 inet_proto_csum_replace2(&tcph->check, skb,
207 htons(oldlen), htons(datalen), 1); 214 htons(oldlen), htons(datalen), 1);
208 215
209 if (rep_len != match_len) { 216 if (adjust && rep_len != match_len)
210 set_bit(IPS_SEQ_ADJUST_BIT, &ct->status); 217 nf_nat_set_seq_adjust(ct, ctinfo, tcph->seq,
211 adjust_tcp_sequence(ntohl(tcph->seq), 218 (int)rep_len - (int)match_len);
212 (int)rep_len - (int)match_len, 219
213 ct, ctinfo);
214 nf_conntrack_event_cache(IPCT_NATSEQADJ, ct);
215 }
216 return 1; 220 return 1;
217} 221}
218EXPORT_SYMBOL(nf_nat_mangle_tcp_packet); 222EXPORT_SYMBOL(__nf_nat_mangle_tcp_packet);
219 223
220/* Generic function for mangling variable-length address changes inside 224/* Generic function for mangling variable-length address changes inside
221 * NATed UDP connections (like the CONNECT DATA XXXXX MESG XXXXX INDEX XXXXX 225 * NATed UDP connections (like the CONNECT DATA XXXXX MESG XXXXX INDEX XXXXX
diff --git a/net/ipv4/netfilter/nf_nat_pptp.c b/net/ipv4/netfilter/nf_nat_pptp.c
index 9eb171056c63..4c060038d29f 100644
--- a/net/ipv4/netfilter/nf_nat_pptp.c
+++ b/net/ipv4/netfilter/nf_nat_pptp.c
@@ -25,6 +25,7 @@
25#include <net/netfilter/nf_nat_rule.h> 25#include <net/netfilter/nf_nat_rule.h>
26#include <net/netfilter/nf_conntrack_helper.h> 26#include <net/netfilter/nf_conntrack_helper.h>
27#include <net/netfilter/nf_conntrack_expect.h> 27#include <net/netfilter/nf_conntrack_expect.h>
28#include <net/netfilter/nf_conntrack_zones.h>
28#include <linux/netfilter/nf_conntrack_proto_gre.h> 29#include <linux/netfilter/nf_conntrack_proto_gre.h>
29#include <linux/netfilter/nf_conntrack_pptp.h> 30#include <linux/netfilter/nf_conntrack_pptp.h>
30 31
@@ -74,7 +75,7 @@ static void pptp_nat_expected(struct nf_conn *ct,
74 75
75 pr_debug("trying to unexpect other dir: "); 76 pr_debug("trying to unexpect other dir: ");
76 nf_ct_dump_tuple_ip(&t); 77 nf_ct_dump_tuple_ip(&t);
77 other_exp = nf_ct_expect_find_get(net, &t); 78 other_exp = nf_ct_expect_find_get(net, nf_ct_zone(ct), &t);
78 if (other_exp) { 79 if (other_exp) {
79 nf_ct_unexpect_related(other_exp); 80 nf_ct_unexpect_related(other_exp);
80 nf_ct_expect_put(other_exp); 81 nf_ct_expect_put(other_exp);
diff --git a/net/ipv4/netfilter/nf_nat_rule.c b/net/ipv4/netfilter/nf_nat_rule.c
index 9e81e0dfb4ec..26de2c1f7fab 100644
--- a/net/ipv4/netfilter/nf_nat_rule.c
+++ b/net/ipv4/netfilter/nf_nat_rule.c
@@ -15,6 +15,7 @@
15#include <linux/kmod.h> 15#include <linux/kmod.h>
16#include <linux/skbuff.h> 16#include <linux/skbuff.h>
17#include <linux/proc_fs.h> 17#include <linux/proc_fs.h>
18#include <linux/slab.h>
18#include <net/checksum.h> 19#include <net/checksum.h>
19#include <net/route.h> 20#include <net/route.h>
20#include <linux/bitops.h> 21#include <linux/bitops.h>
@@ -28,36 +29,6 @@
28 (1 << NF_INET_POST_ROUTING) | \ 29 (1 << NF_INET_POST_ROUTING) | \
29 (1 << NF_INET_LOCAL_OUT)) 30 (1 << NF_INET_LOCAL_OUT))
30 31
31static const struct
32{
33 struct ipt_replace repl;
34 struct ipt_standard entries[3];
35 struct ipt_error term;
36} nat_initial_table __net_initdata = {
37 .repl = {
38 .name = "nat",
39 .valid_hooks = NAT_VALID_HOOKS,
40 .num_entries = 4,
41 .size = sizeof(struct ipt_standard) * 3 + sizeof(struct ipt_error),
42 .hook_entry = {
43 [NF_INET_PRE_ROUTING] = 0,
44 [NF_INET_POST_ROUTING] = sizeof(struct ipt_standard),
45 [NF_INET_LOCAL_OUT] = sizeof(struct ipt_standard) * 2
46 },
47 .underflow = {
48 [NF_INET_PRE_ROUTING] = 0,
49 [NF_INET_POST_ROUTING] = sizeof(struct ipt_standard),
50 [NF_INET_LOCAL_OUT] = sizeof(struct ipt_standard) * 2
51 },
52 },
53 .entries = {
54 IPT_STANDARD_INIT(NF_ACCEPT), /* PRE_ROUTING */
55 IPT_STANDARD_INIT(NF_ACCEPT), /* POST_ROUTING */
56 IPT_STANDARD_INIT(NF_ACCEPT), /* LOCAL_OUT */
57 },
58 .term = IPT_ERROR_INIT, /* ERROR */
59};
60
61static const struct xt_table nat_table = { 32static const struct xt_table nat_table = {
62 .name = "nat", 33 .name = "nat",
63 .valid_hooks = NAT_VALID_HOOKS, 34 .valid_hooks = NAT_VALID_HOOKS,
@@ -186,8 +157,13 @@ static struct xt_target ipt_dnat_reg __read_mostly = {
186 157
187static int __net_init nf_nat_rule_net_init(struct net *net) 158static int __net_init nf_nat_rule_net_init(struct net *net)
188{ 159{
189 net->ipv4.nat_table = ipt_register_table(net, &nat_table, 160 struct ipt_replace *repl;
190 &nat_initial_table.repl); 161
162 repl = ipt_alloc_initial_table(&nat_table);
163 if (repl == NULL)
164 return -ENOMEM;
165 net->ipv4.nat_table = ipt_register_table(net, &nat_table, repl);
166 kfree(repl);
191 if (IS_ERR(net->ipv4.nat_table)) 167 if (IS_ERR(net->ipv4.nat_table))
192 return PTR_ERR(net->ipv4.nat_table); 168 return PTR_ERR(net->ipv4.nat_table);
193 return 0; 169 return 0;
@@ -195,7 +171,7 @@ static int __net_init nf_nat_rule_net_init(struct net *net)
195 171
196static void __net_exit nf_nat_rule_net_exit(struct net *net) 172static void __net_exit nf_nat_rule_net_exit(struct net *net)
197{ 173{
198 ipt_unregister_table(net->ipv4.nat_table); 174 ipt_unregister_table(net, net->ipv4.nat_table);
199} 175}
200 176
201static struct pernet_operations nf_nat_rule_net_ops = { 177static struct pernet_operations nf_nat_rule_net_ops = {
diff --git a/net/ipv4/netfilter/nf_nat_sip.c b/net/ipv4/netfilter/nf_nat_sip.c
index 07d61a57613c..11b538deaaec 100644
--- a/net/ipv4/netfilter/nf_nat_sip.c
+++ b/net/ipv4/netfilter/nf_nat_sip.c
@@ -1,4 +1,4 @@
1/* SIP extension for UDP NAT alteration. 1/* SIP extension for NAT alteration.
2 * 2 *
3 * (C) 2005 by Christian Hentschel <chentschel@arnet.com.ar> 3 * (C) 2005 by Christian Hentschel <chentschel@arnet.com.ar>
4 * based on RR's ip_nat_ftp.c and other modules. 4 * based on RR's ip_nat_ftp.c and other modules.
@@ -15,6 +15,7 @@
15#include <linux/ip.h> 15#include <linux/ip.h>
16#include <net/ip.h> 16#include <net/ip.h>
17#include <linux/udp.h> 17#include <linux/udp.h>
18#include <linux/tcp.h>
18 19
19#include <net/netfilter/nf_nat.h> 20#include <net/netfilter/nf_nat.h>
20#include <net/netfilter/nf_nat_helper.h> 21#include <net/netfilter/nf_nat_helper.h>
@@ -29,25 +30,42 @@ MODULE_DESCRIPTION("SIP NAT helper");
29MODULE_ALIAS("ip_nat_sip"); 30MODULE_ALIAS("ip_nat_sip");
30 31
31 32
32static unsigned int mangle_packet(struct sk_buff *skb, 33static unsigned int mangle_packet(struct sk_buff *skb, unsigned int dataoff,
33 const char **dptr, unsigned int *datalen, 34 const char **dptr, unsigned int *datalen,
34 unsigned int matchoff, unsigned int matchlen, 35 unsigned int matchoff, unsigned int matchlen,
35 const char *buffer, unsigned int buflen) 36 const char *buffer, unsigned int buflen)
36{ 37{
37 enum ip_conntrack_info ctinfo; 38 enum ip_conntrack_info ctinfo;
38 struct nf_conn *ct = nf_ct_get(skb, &ctinfo); 39 struct nf_conn *ct = nf_ct_get(skb, &ctinfo);
39 40 struct tcphdr *th;
40 if (!nf_nat_mangle_udp_packet(skb, ct, ctinfo, matchoff, matchlen, 41 unsigned int baseoff;
41 buffer, buflen)) 42
42 return 0; 43 if (nf_ct_protonum(ct) == IPPROTO_TCP) {
44 th = (struct tcphdr *)(skb->data + ip_hdrlen(skb));
45 baseoff = ip_hdrlen(skb) + th->doff * 4;
46 matchoff += dataoff - baseoff;
47
48 if (!__nf_nat_mangle_tcp_packet(skb, ct, ctinfo,
49 matchoff, matchlen,
50 buffer, buflen, false))
51 return 0;
52 } else {
53 baseoff = ip_hdrlen(skb) + sizeof(struct udphdr);
54 matchoff += dataoff - baseoff;
55
56 if (!nf_nat_mangle_udp_packet(skb, ct, ctinfo,
57 matchoff, matchlen,
58 buffer, buflen))
59 return 0;
60 }
43 61
44 /* Reload data pointer and adjust datalen value */ 62 /* Reload data pointer and adjust datalen value */
45 *dptr = skb->data + ip_hdrlen(skb) + sizeof(struct udphdr); 63 *dptr = skb->data + dataoff;
46 *datalen += buflen - matchlen; 64 *datalen += buflen - matchlen;
47 return 1; 65 return 1;
48} 66}
49 67
50static int map_addr(struct sk_buff *skb, 68static int map_addr(struct sk_buff *skb, unsigned int dataoff,
51 const char **dptr, unsigned int *datalen, 69 const char **dptr, unsigned int *datalen,
52 unsigned int matchoff, unsigned int matchlen, 70 unsigned int matchoff, unsigned int matchlen,
53 union nf_inet_addr *addr, __be16 port) 71 union nf_inet_addr *addr, __be16 port)
@@ -76,11 +94,11 @@ static int map_addr(struct sk_buff *skb,
76 94
77 buflen = sprintf(buffer, "%pI4:%u", &newaddr, ntohs(newport)); 95 buflen = sprintf(buffer, "%pI4:%u", &newaddr, ntohs(newport));
78 96
79 return mangle_packet(skb, dptr, datalen, matchoff, matchlen, 97 return mangle_packet(skb, dataoff, dptr, datalen, matchoff, matchlen,
80 buffer, buflen); 98 buffer, buflen);
81} 99}
82 100
83static int map_sip_addr(struct sk_buff *skb, 101static int map_sip_addr(struct sk_buff *skb, unsigned int dataoff,
84 const char **dptr, unsigned int *datalen, 102 const char **dptr, unsigned int *datalen,
85 enum sip_header_types type) 103 enum sip_header_types type)
86{ 104{
@@ -93,16 +111,18 @@ static int map_sip_addr(struct sk_buff *skb,
93 if (ct_sip_parse_header_uri(ct, *dptr, NULL, *datalen, type, NULL, 111 if (ct_sip_parse_header_uri(ct, *dptr, NULL, *datalen, type, NULL,
94 &matchoff, &matchlen, &addr, &port) <= 0) 112 &matchoff, &matchlen, &addr, &port) <= 0)
95 return 1; 113 return 1;
96 return map_addr(skb, dptr, datalen, matchoff, matchlen, &addr, port); 114 return map_addr(skb, dataoff, dptr, datalen, matchoff, matchlen,
115 &addr, port);
97} 116}
98 117
99static unsigned int ip_nat_sip(struct sk_buff *skb, 118static unsigned int ip_nat_sip(struct sk_buff *skb, unsigned int dataoff,
100 const char **dptr, unsigned int *datalen) 119 const char **dptr, unsigned int *datalen)
101{ 120{
102 enum ip_conntrack_info ctinfo; 121 enum ip_conntrack_info ctinfo;
103 struct nf_conn *ct = nf_ct_get(skb, &ctinfo); 122 struct nf_conn *ct = nf_ct_get(skb, &ctinfo);
104 enum ip_conntrack_dir dir = CTINFO2DIR(ctinfo); 123 enum ip_conntrack_dir dir = CTINFO2DIR(ctinfo);
105 unsigned int dataoff, matchoff, matchlen; 124 unsigned int coff, matchoff, matchlen;
125 enum sip_header_types hdr;
106 union nf_inet_addr addr; 126 union nf_inet_addr addr;
107 __be16 port; 127 __be16 port;
108 int request, in_header; 128 int request, in_header;
@@ -112,16 +132,21 @@ static unsigned int ip_nat_sip(struct sk_buff *skb,
112 if (ct_sip_parse_request(ct, *dptr, *datalen, 132 if (ct_sip_parse_request(ct, *dptr, *datalen,
113 &matchoff, &matchlen, 133 &matchoff, &matchlen,
114 &addr, &port) > 0 && 134 &addr, &port) > 0 &&
115 !map_addr(skb, dptr, datalen, matchoff, matchlen, 135 !map_addr(skb, dataoff, dptr, datalen, matchoff, matchlen,
116 &addr, port)) 136 &addr, port))
117 return NF_DROP; 137 return NF_DROP;
118 request = 1; 138 request = 1;
119 } else 139 } else
120 request = 0; 140 request = 0;
121 141
142 if (nf_ct_protonum(ct) == IPPROTO_TCP)
143 hdr = SIP_HDR_VIA_TCP;
144 else
145 hdr = SIP_HDR_VIA_UDP;
146
122 /* Translate topmost Via header and parameters */ 147 /* Translate topmost Via header and parameters */
123 if (ct_sip_parse_header_uri(ct, *dptr, NULL, *datalen, 148 if (ct_sip_parse_header_uri(ct, *dptr, NULL, *datalen,
124 SIP_HDR_VIA, NULL, &matchoff, &matchlen, 149 hdr, NULL, &matchoff, &matchlen,
125 &addr, &port) > 0) { 150 &addr, &port) > 0) {
126 unsigned int matchend, poff, plen, buflen, n; 151 unsigned int matchend, poff, plen, buflen, n;
127 char buffer[sizeof("nnn.nnn.nnn.nnn:nnnnn")]; 152 char buffer[sizeof("nnn.nnn.nnn.nnn:nnnnn")];
@@ -138,7 +163,7 @@ static unsigned int ip_nat_sip(struct sk_buff *skb,
138 goto next; 163 goto next;
139 } 164 }
140 165
141 if (!map_addr(skb, dptr, datalen, matchoff, matchlen, 166 if (!map_addr(skb, dataoff, dptr, datalen, matchoff, matchlen,
142 &addr, port)) 167 &addr, port))
143 return NF_DROP; 168 return NF_DROP;
144 169
@@ -153,8 +178,8 @@ static unsigned int ip_nat_sip(struct sk_buff *skb,
153 addr.ip != ct->tuplehash[!dir].tuple.dst.u3.ip) { 178 addr.ip != ct->tuplehash[!dir].tuple.dst.u3.ip) {
154 buflen = sprintf(buffer, "%pI4", 179 buflen = sprintf(buffer, "%pI4",
155 &ct->tuplehash[!dir].tuple.dst.u3.ip); 180 &ct->tuplehash[!dir].tuple.dst.u3.ip);
156 if (!mangle_packet(skb, dptr, datalen, poff, plen, 181 if (!mangle_packet(skb, dataoff, dptr, datalen,
157 buffer, buflen)) 182 poff, plen, buffer, buflen))
158 return NF_DROP; 183 return NF_DROP;
159 } 184 }
160 185
@@ -167,8 +192,8 @@ static unsigned int ip_nat_sip(struct sk_buff *skb,
167 addr.ip != ct->tuplehash[!dir].tuple.src.u3.ip) { 192 addr.ip != ct->tuplehash[!dir].tuple.src.u3.ip) {
168 buflen = sprintf(buffer, "%pI4", 193 buflen = sprintf(buffer, "%pI4",
169 &ct->tuplehash[!dir].tuple.src.u3.ip); 194 &ct->tuplehash[!dir].tuple.src.u3.ip);
170 if (!mangle_packet(skb, dptr, datalen, poff, plen, 195 if (!mangle_packet(skb, dataoff, dptr, datalen,
171 buffer, buflen)) 196 poff, plen, buffer, buflen))
172 return NF_DROP; 197 return NF_DROP;
173 } 198 }
174 199
@@ -181,31 +206,45 @@ static unsigned int ip_nat_sip(struct sk_buff *skb,
181 htons(n) != ct->tuplehash[!dir].tuple.src.u.udp.port) { 206 htons(n) != ct->tuplehash[!dir].tuple.src.u.udp.port) {
182 __be16 p = ct->tuplehash[!dir].tuple.src.u.udp.port; 207 __be16 p = ct->tuplehash[!dir].tuple.src.u.udp.port;
183 buflen = sprintf(buffer, "%u", ntohs(p)); 208 buflen = sprintf(buffer, "%u", ntohs(p));
184 if (!mangle_packet(skb, dptr, datalen, poff, plen, 209 if (!mangle_packet(skb, dataoff, dptr, datalen,
185 buffer, buflen)) 210 poff, plen, buffer, buflen))
186 return NF_DROP; 211 return NF_DROP;
187 } 212 }
188 } 213 }
189 214
190next: 215next:
191 /* Translate Contact headers */ 216 /* Translate Contact headers */
192 dataoff = 0; 217 coff = 0;
193 in_header = 0; 218 in_header = 0;
194 while (ct_sip_parse_header_uri(ct, *dptr, &dataoff, *datalen, 219 while (ct_sip_parse_header_uri(ct, *dptr, &coff, *datalen,
195 SIP_HDR_CONTACT, &in_header, 220 SIP_HDR_CONTACT, &in_header,
196 &matchoff, &matchlen, 221 &matchoff, &matchlen,
197 &addr, &port) > 0) { 222 &addr, &port) > 0) {
198 if (!map_addr(skb, dptr, datalen, matchoff, matchlen, 223 if (!map_addr(skb, dataoff, dptr, datalen, matchoff, matchlen,
199 &addr, port)) 224 &addr, port))
200 return NF_DROP; 225 return NF_DROP;
201 } 226 }
202 227
203 if (!map_sip_addr(skb, dptr, datalen, SIP_HDR_FROM) || 228 if (!map_sip_addr(skb, dataoff, dptr, datalen, SIP_HDR_FROM) ||
204 !map_sip_addr(skb, dptr, datalen, SIP_HDR_TO)) 229 !map_sip_addr(skb, dataoff, dptr, datalen, SIP_HDR_TO))
205 return NF_DROP; 230 return NF_DROP;
231
206 return NF_ACCEPT; 232 return NF_ACCEPT;
207} 233}
208 234
235static void ip_nat_sip_seq_adjust(struct sk_buff *skb, s16 off)
236{
237 enum ip_conntrack_info ctinfo;
238 struct nf_conn *ct = nf_ct_get(skb, &ctinfo);
239 const struct tcphdr *th;
240
241 if (nf_ct_protonum(ct) != IPPROTO_TCP || off == 0)
242 return;
243
244 th = (struct tcphdr *)(skb->data + ip_hdrlen(skb));
245 nf_nat_set_seq_adjust(ct, ctinfo, th->seq, off);
246}
247
209/* Handles expected signalling connections and media streams */ 248/* Handles expected signalling connections and media streams */
210static void ip_nat_sip_expected(struct nf_conn *ct, 249static void ip_nat_sip_expected(struct nf_conn *ct,
211 struct nf_conntrack_expect *exp) 250 struct nf_conntrack_expect *exp)
@@ -232,7 +271,7 @@ static void ip_nat_sip_expected(struct nf_conn *ct,
232 } 271 }
233} 272}
234 273
235static unsigned int ip_nat_sip_expect(struct sk_buff *skb, 274static unsigned int ip_nat_sip_expect(struct sk_buff *skb, unsigned int dataoff,
236 const char **dptr, unsigned int *datalen, 275 const char **dptr, unsigned int *datalen,
237 struct nf_conntrack_expect *exp, 276 struct nf_conntrack_expect *exp,
238 unsigned int matchoff, 277 unsigned int matchoff,
@@ -279,8 +318,8 @@ static unsigned int ip_nat_sip_expect(struct sk_buff *skb,
279 if (exp->tuple.dst.u3.ip != exp->saved_ip || 318 if (exp->tuple.dst.u3.ip != exp->saved_ip ||
280 exp->tuple.dst.u.udp.port != exp->saved_proto.udp.port) { 319 exp->tuple.dst.u.udp.port != exp->saved_proto.udp.port) {
281 buflen = sprintf(buffer, "%pI4:%u", &newip, port); 320 buflen = sprintf(buffer, "%pI4:%u", &newip, port);
282 if (!mangle_packet(skb, dptr, datalen, matchoff, matchlen, 321 if (!mangle_packet(skb, dataoff, dptr, datalen,
283 buffer, buflen)) 322 matchoff, matchlen, buffer, buflen))
284 goto err; 323 goto err;
285 } 324 }
286 return NF_ACCEPT; 325 return NF_ACCEPT;
@@ -290,7 +329,7 @@ err:
290 return NF_DROP; 329 return NF_DROP;
291} 330}
292 331
293static int mangle_content_len(struct sk_buff *skb, 332static int mangle_content_len(struct sk_buff *skb, unsigned int dataoff,
294 const char **dptr, unsigned int *datalen) 333 const char **dptr, unsigned int *datalen)
295{ 334{
296 enum ip_conntrack_info ctinfo; 335 enum ip_conntrack_info ctinfo;
@@ -312,12 +351,13 @@ static int mangle_content_len(struct sk_buff *skb,
312 return 0; 351 return 0;
313 352
314 buflen = sprintf(buffer, "%u", c_len); 353 buflen = sprintf(buffer, "%u", c_len);
315 return mangle_packet(skb, dptr, datalen, matchoff, matchlen, 354 return mangle_packet(skb, dataoff, dptr, datalen, matchoff, matchlen,
316 buffer, buflen); 355 buffer, buflen);
317} 356}
318 357
319static int mangle_sdp_packet(struct sk_buff *skb, const char **dptr, 358static int mangle_sdp_packet(struct sk_buff *skb, unsigned int dataoff,
320 unsigned int dataoff, unsigned int *datalen, 359 const char **dptr, unsigned int *datalen,
360 unsigned int sdpoff,
321 enum sdp_header_types type, 361 enum sdp_header_types type,
322 enum sdp_header_types term, 362 enum sdp_header_types term,
323 char *buffer, int buflen) 363 char *buffer, int buflen)
@@ -326,16 +366,16 @@ static int mangle_sdp_packet(struct sk_buff *skb, const char **dptr,
326 struct nf_conn *ct = nf_ct_get(skb, &ctinfo); 366 struct nf_conn *ct = nf_ct_get(skb, &ctinfo);
327 unsigned int matchlen, matchoff; 367 unsigned int matchlen, matchoff;
328 368
329 if (ct_sip_get_sdp_header(ct, *dptr, dataoff, *datalen, type, term, 369 if (ct_sip_get_sdp_header(ct, *dptr, sdpoff, *datalen, type, term,
330 &matchoff, &matchlen) <= 0) 370 &matchoff, &matchlen) <= 0)
331 return -ENOENT; 371 return -ENOENT;
332 return mangle_packet(skb, dptr, datalen, matchoff, matchlen, 372 return mangle_packet(skb, dataoff, dptr, datalen, matchoff, matchlen,
333 buffer, buflen) ? 0 : -EINVAL; 373 buffer, buflen) ? 0 : -EINVAL;
334} 374}
335 375
336static unsigned int ip_nat_sdp_addr(struct sk_buff *skb, const char **dptr, 376static unsigned int ip_nat_sdp_addr(struct sk_buff *skb, unsigned int dataoff,
337 unsigned int dataoff, 377 const char **dptr, unsigned int *datalen,
338 unsigned int *datalen, 378 unsigned int sdpoff,
339 enum sdp_header_types type, 379 enum sdp_header_types type,
340 enum sdp_header_types term, 380 enum sdp_header_types term,
341 const union nf_inet_addr *addr) 381 const union nf_inet_addr *addr)
@@ -344,16 +384,15 @@ static unsigned int ip_nat_sdp_addr(struct sk_buff *skb, const char **dptr,
344 unsigned int buflen; 384 unsigned int buflen;
345 385
346 buflen = sprintf(buffer, "%pI4", &addr->ip); 386 buflen = sprintf(buffer, "%pI4", &addr->ip);
347 if (mangle_sdp_packet(skb, dptr, dataoff, datalen, type, term, 387 if (mangle_sdp_packet(skb, dataoff, dptr, datalen, sdpoff, type, term,
348 buffer, buflen)) 388 buffer, buflen))
349 return 0; 389 return 0;
350 390
351 return mangle_content_len(skb, dptr, datalen); 391 return mangle_content_len(skb, dataoff, dptr, datalen);
352} 392}
353 393
354static unsigned int ip_nat_sdp_port(struct sk_buff *skb, 394static unsigned int ip_nat_sdp_port(struct sk_buff *skb, unsigned int dataoff,
355 const char **dptr, 395 const char **dptr, unsigned int *datalen,
356 unsigned int *datalen,
357 unsigned int matchoff, 396 unsigned int matchoff,
358 unsigned int matchlen, 397 unsigned int matchlen,
359 u_int16_t port) 398 u_int16_t port)
@@ -362,16 +401,16 @@ static unsigned int ip_nat_sdp_port(struct sk_buff *skb,
362 unsigned int buflen; 401 unsigned int buflen;
363 402
364 buflen = sprintf(buffer, "%u", port); 403 buflen = sprintf(buffer, "%u", port);
365 if (!mangle_packet(skb, dptr, datalen, matchoff, matchlen, 404 if (!mangle_packet(skb, dataoff, dptr, datalen, matchoff, matchlen,
366 buffer, buflen)) 405 buffer, buflen))
367 return 0; 406 return 0;
368 407
369 return mangle_content_len(skb, dptr, datalen); 408 return mangle_content_len(skb, dataoff, dptr, datalen);
370} 409}
371 410
372static unsigned int ip_nat_sdp_session(struct sk_buff *skb, const char **dptr, 411static unsigned int ip_nat_sdp_session(struct sk_buff *skb, unsigned int dataoff,
373 unsigned int dataoff, 412 const char **dptr, unsigned int *datalen,
374 unsigned int *datalen, 413 unsigned int sdpoff,
375 const union nf_inet_addr *addr) 414 const union nf_inet_addr *addr)
376{ 415{
377 char buffer[sizeof("nnn.nnn.nnn.nnn")]; 416 char buffer[sizeof("nnn.nnn.nnn.nnn")];
@@ -379,12 +418,12 @@ static unsigned int ip_nat_sdp_session(struct sk_buff *skb, const char **dptr,
379 418
380 /* Mangle session description owner and contact addresses */ 419 /* Mangle session description owner and contact addresses */
381 buflen = sprintf(buffer, "%pI4", &addr->ip); 420 buflen = sprintf(buffer, "%pI4", &addr->ip);
382 if (mangle_sdp_packet(skb, dptr, dataoff, datalen, 421 if (mangle_sdp_packet(skb, dataoff, dptr, datalen, sdpoff,
383 SDP_HDR_OWNER_IP4, SDP_HDR_MEDIA, 422 SDP_HDR_OWNER_IP4, SDP_HDR_MEDIA,
384 buffer, buflen)) 423 buffer, buflen))
385 return 0; 424 return 0;
386 425
387 switch (mangle_sdp_packet(skb, dptr, dataoff, datalen, 426 switch (mangle_sdp_packet(skb, dataoff, dptr, datalen, sdpoff,
388 SDP_HDR_CONNECTION_IP4, SDP_HDR_MEDIA, 427 SDP_HDR_CONNECTION_IP4, SDP_HDR_MEDIA,
389 buffer, buflen)) { 428 buffer, buflen)) {
390 case 0: 429 case 0:
@@ -401,14 +440,13 @@ static unsigned int ip_nat_sdp_session(struct sk_buff *skb, const char **dptr,
401 return 0; 440 return 0;
402 } 441 }
403 442
404 return mangle_content_len(skb, dptr, datalen); 443 return mangle_content_len(skb, dataoff, dptr, datalen);
405} 444}
406 445
407/* So, this packet has hit the connection tracking matching code. 446/* So, this packet has hit the connection tracking matching code.
408 Mangle it, and change the expectation to match the new version. */ 447 Mangle it, and change the expectation to match the new version. */
409static unsigned int ip_nat_sdp_media(struct sk_buff *skb, 448static unsigned int ip_nat_sdp_media(struct sk_buff *skb, unsigned int dataoff,
410 const char **dptr, 449 const char **dptr, unsigned int *datalen,
411 unsigned int *datalen,
412 struct nf_conntrack_expect *rtp_exp, 450 struct nf_conntrack_expect *rtp_exp,
413 struct nf_conntrack_expect *rtcp_exp, 451 struct nf_conntrack_expect *rtcp_exp,
414 unsigned int mediaoff, 452 unsigned int mediaoff,
@@ -456,7 +494,8 @@ static unsigned int ip_nat_sdp_media(struct sk_buff *skb,
456 494
457 /* Update media port. */ 495 /* Update media port. */
458 if (rtp_exp->tuple.dst.u.udp.port != rtp_exp->saved_proto.udp.port && 496 if (rtp_exp->tuple.dst.u.udp.port != rtp_exp->saved_proto.udp.port &&
459 !ip_nat_sdp_port(skb, dptr, datalen, mediaoff, medialen, port)) 497 !ip_nat_sdp_port(skb, dataoff, dptr, datalen,
498 mediaoff, medialen, port))
460 goto err2; 499 goto err2;
461 500
462 return NF_ACCEPT; 501 return NF_ACCEPT;
@@ -471,6 +510,7 @@ err1:
471static void __exit nf_nat_sip_fini(void) 510static void __exit nf_nat_sip_fini(void)
472{ 511{
473 rcu_assign_pointer(nf_nat_sip_hook, NULL); 512 rcu_assign_pointer(nf_nat_sip_hook, NULL);
513 rcu_assign_pointer(nf_nat_sip_seq_adjust_hook, NULL);
474 rcu_assign_pointer(nf_nat_sip_expect_hook, NULL); 514 rcu_assign_pointer(nf_nat_sip_expect_hook, NULL);
475 rcu_assign_pointer(nf_nat_sdp_addr_hook, NULL); 515 rcu_assign_pointer(nf_nat_sdp_addr_hook, NULL);
476 rcu_assign_pointer(nf_nat_sdp_port_hook, NULL); 516 rcu_assign_pointer(nf_nat_sdp_port_hook, NULL);
@@ -482,12 +522,14 @@ static void __exit nf_nat_sip_fini(void)
482static int __init nf_nat_sip_init(void) 522static int __init nf_nat_sip_init(void)
483{ 523{
484 BUG_ON(nf_nat_sip_hook != NULL); 524 BUG_ON(nf_nat_sip_hook != NULL);
525 BUG_ON(nf_nat_sip_seq_adjust_hook != NULL);
485 BUG_ON(nf_nat_sip_expect_hook != NULL); 526 BUG_ON(nf_nat_sip_expect_hook != NULL);
486 BUG_ON(nf_nat_sdp_addr_hook != NULL); 527 BUG_ON(nf_nat_sdp_addr_hook != NULL);
487 BUG_ON(nf_nat_sdp_port_hook != NULL); 528 BUG_ON(nf_nat_sdp_port_hook != NULL);
488 BUG_ON(nf_nat_sdp_session_hook != NULL); 529 BUG_ON(nf_nat_sdp_session_hook != NULL);
489 BUG_ON(nf_nat_sdp_media_hook != NULL); 530 BUG_ON(nf_nat_sdp_media_hook != NULL);
490 rcu_assign_pointer(nf_nat_sip_hook, ip_nat_sip); 531 rcu_assign_pointer(nf_nat_sip_hook, ip_nat_sip);
532 rcu_assign_pointer(nf_nat_sip_seq_adjust_hook, ip_nat_sip_seq_adjust);
491 rcu_assign_pointer(nf_nat_sip_expect_hook, ip_nat_sip_expect); 533 rcu_assign_pointer(nf_nat_sip_expect_hook, ip_nat_sip_expect);
492 rcu_assign_pointer(nf_nat_sdp_addr_hook, ip_nat_sdp_addr); 534 rcu_assign_pointer(nf_nat_sdp_addr_hook, ip_nat_sdp_addr);
493 rcu_assign_pointer(nf_nat_sdp_port_hook, ip_nat_sdp_port); 535 rcu_assign_pointer(nf_nat_sdp_port_hook, ip_nat_sdp_port);
diff --git a/net/ipv4/netfilter/nf_nat_snmp_basic.c b/net/ipv4/netfilter/nf_nat_snmp_basic.c
index d9521f6f9ed0..4d85b6e55f29 100644
--- a/net/ipv4/netfilter/nf_nat_snmp_basic.c
+++ b/net/ipv4/netfilter/nf_nat_snmp_basic.c
@@ -43,6 +43,7 @@
43#include <linux/moduleparam.h> 43#include <linux/moduleparam.h>
44#include <linux/types.h> 44#include <linux/types.h>
45#include <linux/kernel.h> 45#include <linux/kernel.h>
46#include <linux/slab.h>
46#include <linux/in.h> 47#include <linux/in.h>
47#include <linux/ip.h> 48#include <linux/ip.h>
48#include <linux/udp.h> 49#include <linux/udp.h>
@@ -1038,7 +1039,7 @@ static int snmp_parse_mangle(unsigned char *msg,
1038 unsigned int cls, con, tag, vers, pdutype; 1039 unsigned int cls, con, tag, vers, pdutype;
1039 struct asn1_ctx ctx; 1040 struct asn1_ctx ctx;
1040 struct asn1_octstr comm; 1041 struct asn1_octstr comm;
1041 struct snmp_object **obj; 1042 struct snmp_object *obj;
1042 1043
1043 if (debug > 1) 1044 if (debug > 1)
1044 hex_dump(msg, len); 1045 hex_dump(msg, len);
@@ -1148,43 +1149,34 @@ static int snmp_parse_mangle(unsigned char *msg,
1148 if (cls != ASN1_UNI || con != ASN1_CON || tag != ASN1_SEQ) 1149 if (cls != ASN1_UNI || con != ASN1_CON || tag != ASN1_SEQ)
1149 return 0; 1150 return 0;
1150 1151
1151 obj = kmalloc(sizeof(struct snmp_object), GFP_ATOMIC);
1152 if (obj == NULL) {
1153 if (net_ratelimit())
1154 printk(KERN_WARNING "OOM in bsalg(%d)\n", __LINE__);
1155 return 0;
1156 }
1157
1158 while (!asn1_eoc_decode(&ctx, eoc)) { 1152 while (!asn1_eoc_decode(&ctx, eoc)) {
1159 unsigned int i; 1153 unsigned int i;
1160 1154
1161 if (!snmp_object_decode(&ctx, obj)) { 1155 if (!snmp_object_decode(&ctx, &obj)) {
1162 if (*obj) { 1156 if (obj) {
1163 kfree((*obj)->id); 1157 kfree(obj->id);
1164 kfree(*obj); 1158 kfree(obj);
1165 } 1159 }
1166 kfree(obj);
1167 return 0; 1160 return 0;
1168 } 1161 }
1169 1162
1170 if (debug > 1) { 1163 if (debug > 1) {
1171 printk(KERN_DEBUG "bsalg: object: "); 1164 printk(KERN_DEBUG "bsalg: object: ");
1172 for (i = 0; i < (*obj)->id_len; i++) { 1165 for (i = 0; i < obj->id_len; i++) {
1173 if (i > 0) 1166 if (i > 0)
1174 printk("."); 1167 printk(".");
1175 printk("%lu", (*obj)->id[i]); 1168 printk("%lu", obj->id[i]);
1176 } 1169 }
1177 printk(": type=%u\n", (*obj)->type); 1170 printk(": type=%u\n", obj->type);
1178 1171
1179 } 1172 }
1180 1173
1181 if ((*obj)->type == SNMP_IPADDR) 1174 if (obj->type == SNMP_IPADDR)
1182 mangle_address(ctx.begin, ctx.pointer - 4 , map, check); 1175 mangle_address(ctx.begin, ctx.pointer - 4 , map, check);
1183 1176
1184 kfree((*obj)->id); 1177 kfree(obj->id);
1185 kfree(*obj); 1178 kfree(obj);
1186 } 1179 }
1187 kfree(obj);
1188 1180
1189 if (!asn1_eoc_decode(&ctx, eoc)) 1181 if (!asn1_eoc_decode(&ctx, eoc))
1190 return 0; 1182 return 0;
diff --git a/net/ipv4/netfilter/nf_nat_standalone.c b/net/ipv4/netfilter/nf_nat_standalone.c
index 5f41d017ddd8..c39c9cf6bee6 100644
--- a/net/ipv4/netfilter/nf_nat_standalone.c
+++ b/net/ipv4/netfilter/nf_nat_standalone.c
@@ -7,6 +7,7 @@
7 */ 7 */
8#include <linux/types.h> 8#include <linux/types.h>
9#include <linux/icmp.h> 9#include <linux/icmp.h>
10#include <linux/gfp.h>
10#include <linux/ip.h> 11#include <linux/ip.h>
11#include <linux/netfilter.h> 12#include <linux/netfilter.h>
12#include <linux/netfilter_ipv4.h> 13#include <linux/netfilter_ipv4.h>
@@ -197,11 +198,11 @@ nf_nat_out(unsigned int hooknum,
197 (ct = nf_ct_get(skb, &ctinfo)) != NULL) { 198 (ct = nf_ct_get(skb, &ctinfo)) != NULL) {
198 enum ip_conntrack_dir dir = CTINFO2DIR(ctinfo); 199 enum ip_conntrack_dir dir = CTINFO2DIR(ctinfo);
199 200
200 if (ct->tuplehash[dir].tuple.src.u3.ip != 201 if ((ct->tuplehash[dir].tuple.src.u3.ip !=
201 ct->tuplehash[!dir].tuple.dst.u3.ip 202 ct->tuplehash[!dir].tuple.dst.u3.ip) ||
202 || ct->tuplehash[dir].tuple.src.u.all != 203 (ct->tuplehash[dir].tuple.src.u.all !=
203 ct->tuplehash[!dir].tuple.dst.u.all 204 ct->tuplehash[!dir].tuple.dst.u.all)
204 ) 205 )
205 return ip_xfrm_me_harder(skb) == 0 ? ret : NF_DROP; 206 return ip_xfrm_me_harder(skb) == 0 ? ret : NF_DROP;
206 } 207 }
207#endif 208#endif
diff --git a/net/ipv4/proc.c b/net/ipv4/proc.c
index f25542c48b7d..4f1f337f4337 100644
--- a/net/ipv4/proc.c
+++ b/net/ipv4/proc.c
@@ -127,8 +127,8 @@ static const struct snmp_mib snmp4_ipextstats_list[] = {
127 SNMP_MIB_SENTINEL 127 SNMP_MIB_SENTINEL
128}; 128};
129 129
130static struct { 130static const struct {
131 char *name; 131 const char *name;
132 int index; 132 int index;
133} icmpmibmap[] = { 133} icmpmibmap[] = {
134 { "DestUnreachs", ICMP_DEST_UNREACH }, 134 { "DestUnreachs", ICMP_DEST_UNREACH },
@@ -249,6 +249,8 @@ static const struct snmp_mib snmp4_net_list[] = {
249 SNMP_MIB_ITEM("TCPSackShifted", LINUX_MIB_SACKSHIFTED), 249 SNMP_MIB_ITEM("TCPSackShifted", LINUX_MIB_SACKSHIFTED),
250 SNMP_MIB_ITEM("TCPSackMerged", LINUX_MIB_SACKMERGED), 250 SNMP_MIB_ITEM("TCPSackMerged", LINUX_MIB_SACKMERGED),
251 SNMP_MIB_ITEM("TCPSackShiftFallback", LINUX_MIB_SACKSHIFTFALLBACK), 251 SNMP_MIB_ITEM("TCPSackShiftFallback", LINUX_MIB_SACKSHIFTFALLBACK),
252 SNMP_MIB_ITEM("TCPBacklogDrop", LINUX_MIB_TCPBACKLOGDROP),
253 SNMP_MIB_ITEM("TCPMinTTLDrop", LINUX_MIB_TCPMINTTLDROP),
252 SNMP_MIB_SENTINEL 254 SNMP_MIB_SENTINEL
253}; 255};
254 256
@@ -280,7 +282,7 @@ static void icmpmsg_put(struct seq_file *seq)
280 282
281 count = 0; 283 count = 0;
282 for (i = 0; i < ICMPMSG_MIB_MAX; i++) { 284 for (i = 0; i < ICMPMSG_MIB_MAX; i++) {
283 val = snmp_fold_field((void **) net->mib.icmpmsg_statistics, i); 285 val = snmp_fold_field((void __percpu **) net->mib.icmpmsg_statistics, i);
284 if (val) { 286 if (val) {
285 type[count] = i; 287 type[count] = i;
286 vals[count++] = val; 288 vals[count++] = val;
@@ -307,18 +309,18 @@ static void icmp_put(struct seq_file *seq)
307 for (i=0; icmpmibmap[i].name != NULL; i++) 309 for (i=0; icmpmibmap[i].name != NULL; i++)
308 seq_printf(seq, " Out%s", icmpmibmap[i].name); 310 seq_printf(seq, " Out%s", icmpmibmap[i].name);
309 seq_printf(seq, "\nIcmp: %lu %lu", 311 seq_printf(seq, "\nIcmp: %lu %lu",
310 snmp_fold_field((void **) net->mib.icmp_statistics, ICMP_MIB_INMSGS), 312 snmp_fold_field((void __percpu **) net->mib.icmp_statistics, ICMP_MIB_INMSGS),
311 snmp_fold_field((void **) net->mib.icmp_statistics, ICMP_MIB_INERRORS)); 313 snmp_fold_field((void __percpu **) net->mib.icmp_statistics, ICMP_MIB_INERRORS));
312 for (i=0; icmpmibmap[i].name != NULL; i++) 314 for (i=0; icmpmibmap[i].name != NULL; i++)
313 seq_printf(seq, " %lu", 315 seq_printf(seq, " %lu",
314 snmp_fold_field((void **) net->mib.icmpmsg_statistics, 316 snmp_fold_field((void __percpu **) net->mib.icmpmsg_statistics,
315 icmpmibmap[i].index)); 317 icmpmibmap[i].index));
316 seq_printf(seq, " %lu %lu", 318 seq_printf(seq, " %lu %lu",
317 snmp_fold_field((void **) net->mib.icmp_statistics, ICMP_MIB_OUTMSGS), 319 snmp_fold_field((void __percpu **) net->mib.icmp_statistics, ICMP_MIB_OUTMSGS),
318 snmp_fold_field((void **) net->mib.icmp_statistics, ICMP_MIB_OUTERRORS)); 320 snmp_fold_field((void __percpu **) net->mib.icmp_statistics, ICMP_MIB_OUTERRORS));
319 for (i=0; icmpmibmap[i].name != NULL; i++) 321 for (i=0; icmpmibmap[i].name != NULL; i++)
320 seq_printf(seq, " %lu", 322 seq_printf(seq, " %lu",
321 snmp_fold_field((void **) net->mib.icmpmsg_statistics, 323 snmp_fold_field((void __percpu **) net->mib.icmpmsg_statistics,
322 icmpmibmap[i].index | 0x100)); 324 icmpmibmap[i].index | 0x100));
323} 325}
324 326
@@ -341,7 +343,7 @@ static int snmp_seq_show(struct seq_file *seq, void *v)
341 343
342 for (i = 0; snmp4_ipstats_list[i].name != NULL; i++) 344 for (i = 0; snmp4_ipstats_list[i].name != NULL; i++)
343 seq_printf(seq, " %lu", 345 seq_printf(seq, " %lu",
344 snmp_fold_field((void **)net->mib.ip_statistics, 346 snmp_fold_field((void __percpu **)net->mib.ip_statistics,
345 snmp4_ipstats_list[i].entry)); 347 snmp4_ipstats_list[i].entry));
346 348
347 icmp_put(seq); /* RFC 2011 compatibility */ 349 icmp_put(seq); /* RFC 2011 compatibility */
@@ -356,11 +358,11 @@ static int snmp_seq_show(struct seq_file *seq, void *v)
356 /* MaxConn field is signed, RFC 2012 */ 358 /* MaxConn field is signed, RFC 2012 */
357 if (snmp4_tcp_list[i].entry == TCP_MIB_MAXCONN) 359 if (snmp4_tcp_list[i].entry == TCP_MIB_MAXCONN)
358 seq_printf(seq, " %ld", 360 seq_printf(seq, " %ld",
359 snmp_fold_field((void **)net->mib.tcp_statistics, 361 snmp_fold_field((void __percpu **)net->mib.tcp_statistics,
360 snmp4_tcp_list[i].entry)); 362 snmp4_tcp_list[i].entry));
361 else 363 else
362 seq_printf(seq, " %lu", 364 seq_printf(seq, " %lu",
363 snmp_fold_field((void **)net->mib.tcp_statistics, 365 snmp_fold_field((void __percpu **)net->mib.tcp_statistics,
364 snmp4_tcp_list[i].entry)); 366 snmp4_tcp_list[i].entry));
365 } 367 }
366 368
@@ -371,7 +373,7 @@ static int snmp_seq_show(struct seq_file *seq, void *v)
371 seq_puts(seq, "\nUdp:"); 373 seq_puts(seq, "\nUdp:");
372 for (i = 0; snmp4_udp_list[i].name != NULL; i++) 374 for (i = 0; snmp4_udp_list[i].name != NULL; i++)
373 seq_printf(seq, " %lu", 375 seq_printf(seq, " %lu",
374 snmp_fold_field((void **)net->mib.udp_statistics, 376 snmp_fold_field((void __percpu **)net->mib.udp_statistics,
375 snmp4_udp_list[i].entry)); 377 snmp4_udp_list[i].entry));
376 378
377 /* the UDP and UDP-Lite MIBs are the same */ 379 /* the UDP and UDP-Lite MIBs are the same */
@@ -382,7 +384,7 @@ static int snmp_seq_show(struct seq_file *seq, void *v)
382 seq_puts(seq, "\nUdpLite:"); 384 seq_puts(seq, "\nUdpLite:");
383 for (i = 0; snmp4_udp_list[i].name != NULL; i++) 385 for (i = 0; snmp4_udp_list[i].name != NULL; i++)
384 seq_printf(seq, " %lu", 386 seq_printf(seq, " %lu",
385 snmp_fold_field((void **)net->mib.udplite_statistics, 387 snmp_fold_field((void __percpu **)net->mib.udplite_statistics,
386 snmp4_udp_list[i].entry)); 388 snmp4_udp_list[i].entry));
387 389
388 seq_putc(seq, '\n'); 390 seq_putc(seq, '\n');
@@ -419,7 +421,7 @@ static int netstat_seq_show(struct seq_file *seq, void *v)
419 seq_puts(seq, "\nTcpExt:"); 421 seq_puts(seq, "\nTcpExt:");
420 for (i = 0; snmp4_net_list[i].name != NULL; i++) 422 for (i = 0; snmp4_net_list[i].name != NULL; i++)
421 seq_printf(seq, " %lu", 423 seq_printf(seq, " %lu",
422 snmp_fold_field((void **)net->mib.net_statistics, 424 snmp_fold_field((void __percpu **)net->mib.net_statistics,
423 snmp4_net_list[i].entry)); 425 snmp4_net_list[i].entry));
424 426
425 seq_puts(seq, "\nIpExt:"); 427 seq_puts(seq, "\nIpExt:");
@@ -429,7 +431,7 @@ static int netstat_seq_show(struct seq_file *seq, void *v)
429 seq_puts(seq, "\nIpExt:"); 431 seq_puts(seq, "\nIpExt:");
430 for (i = 0; snmp4_ipextstats_list[i].name != NULL; i++) 432 for (i = 0; snmp4_ipextstats_list[i].name != NULL; i++)
431 seq_printf(seq, " %lu", 433 seq_printf(seq, " %lu",
432 snmp_fold_field((void **)net->mib.ip_statistics, 434 snmp_fold_field((void __percpu **)net->mib.ip_statistics,
433 snmp4_ipextstats_list[i].entry)); 435 snmp4_ipextstats_list[i].entry));
434 436
435 seq_putc(seq, '\n'); 437 seq_putc(seq, '\n');
diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
index ab996f9c0fe0..cc6f097fbd5f 100644
--- a/net/ipv4/raw.c
+++ b/net/ipv4/raw.c
@@ -60,7 +60,6 @@
60#include <net/net_namespace.h> 60#include <net/net_namespace.h>
61#include <net/dst.h> 61#include <net/dst.h>
62#include <net/sock.h> 62#include <net/sock.h>
63#include <linux/gfp.h>
64#include <linux/ip.h> 63#include <linux/ip.h>
65#include <linux/net.h> 64#include <linux/net.h>
66#include <net/ip.h> 65#include <net/ip.h>
@@ -87,7 +86,7 @@ void raw_hash_sk(struct sock *sk)
87 struct raw_hashinfo *h = sk->sk_prot->h.raw_hash; 86 struct raw_hashinfo *h = sk->sk_prot->h.raw_hash;
88 struct hlist_head *head; 87 struct hlist_head *head;
89 88
90 head = &h->ht[inet_sk(sk)->num & (RAW_HTABLE_SIZE - 1)]; 89 head = &h->ht[inet_sk(sk)->inet_num & (RAW_HTABLE_SIZE - 1)];
91 90
92 write_lock_bh(&h->lock); 91 write_lock_bh(&h->lock);
93 sk_add_node(sk, head); 92 sk_add_node(sk, head);
@@ -115,9 +114,9 @@ static struct sock *__raw_v4_lookup(struct net *net, struct sock *sk,
115 sk_for_each_from(sk, node) { 114 sk_for_each_from(sk, node) {
116 struct inet_sock *inet = inet_sk(sk); 115 struct inet_sock *inet = inet_sk(sk);
117 116
118 if (net_eq(sock_net(sk), net) && inet->num == num && 117 if (net_eq(sock_net(sk), net) && inet->inet_num == num &&
119 !(inet->daddr && inet->daddr != raddr) && 118 !(inet->inet_daddr && inet->inet_daddr != raddr) &&
120 !(inet->rcv_saddr && inet->rcv_saddr != laddr) && 119 !(inet->inet_rcv_saddr && inet->inet_rcv_saddr != laddr) &&
121 !(sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif)) 120 !(sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif))
122 goto found; /* gotcha */ 121 goto found; /* gotcha */
123 } 122 }
@@ -292,7 +291,6 @@ static int raw_rcv_skb(struct sock * sk, struct sk_buff * skb)
292 /* Charge it to the socket. */ 291 /* Charge it to the socket. */
293 292
294 if (sock_queue_rcv_skb(sk, skb) < 0) { 293 if (sock_queue_rcv_skb(sk, skb) < 0) {
295 atomic_inc(&sk->sk_drops);
296 kfree_skb(skb); 294 kfree_skb(skb);
297 return NET_RX_DROP; 295 return NET_RX_DROP;
298 } 296 }
@@ -327,7 +325,7 @@ static int raw_send_hdrinc(struct sock *sk, void *from, size_t length,
327 int err; 325 int err;
328 326
329 if (length > rt->u.dst.dev->mtu) { 327 if (length > rt->u.dst.dev->mtu) {
330 ip_local_error(sk, EMSGSIZE, rt->rt_dst, inet->dport, 328 ip_local_error(sk, EMSGSIZE, rt->rt_dst, inet->inet_dport,
331 rt->u.dst.dev->mtu); 329 rt->u.dst.dev->mtu);
332 return -EMSGSIZE; 330 return -EMSGSIZE;
333 } 331 }
@@ -500,10 +498,10 @@ static int raw_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
500 err = -EDESTADDRREQ; 498 err = -EDESTADDRREQ;
501 if (sk->sk_state != TCP_ESTABLISHED) 499 if (sk->sk_state != TCP_ESTABLISHED)
502 goto out; 500 goto out;
503 daddr = inet->daddr; 501 daddr = inet->inet_daddr;
504 } 502 }
505 503
506 ipc.addr = inet->saddr; 504 ipc.addr = inet->inet_saddr;
507 ipc.opt = NULL; 505 ipc.opt = NULL;
508 ipc.shtx.flags = 0; 506 ipc.shtx.flags = 0;
509 ipc.oif = sk->sk_bound_dev_if; 507 ipc.oif = sk->sk_bound_dev_if;
@@ -645,9 +643,9 @@ static int raw_bind(struct sock *sk, struct sockaddr *uaddr, int addr_len)
645 if (addr->sin_addr.s_addr && chk_addr_ret != RTN_LOCAL && 643 if (addr->sin_addr.s_addr && chk_addr_ret != RTN_LOCAL &&
646 chk_addr_ret != RTN_MULTICAST && chk_addr_ret != RTN_BROADCAST) 644 chk_addr_ret != RTN_MULTICAST && chk_addr_ret != RTN_BROADCAST)
647 goto out; 645 goto out;
648 inet->rcv_saddr = inet->saddr = addr->sin_addr.s_addr; 646 inet->inet_rcv_saddr = inet->inet_saddr = addr->sin_addr.s_addr;
649 if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST) 647 if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
650 inet->saddr = 0; /* Use device */ 648 inet->inet_saddr = 0; /* Use device */
651 sk_dst_reset(sk); 649 sk_dst_reset(sk);
652 ret = 0; 650 ret = 0;
653out: return ret; 651out: return ret;
@@ -692,7 +690,7 @@ static int raw_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
692 if (err) 690 if (err)
693 goto done; 691 goto done;
694 692
695 sock_recv_timestamp(msg, sk, skb); 693 sock_recv_ts_and_drops(msg, sk, skb);
696 694
697 /* Copy the address. */ 695 /* Copy the address. */
698 if (sin) { 696 if (sin) {
@@ -717,7 +715,7 @@ static int raw_init(struct sock *sk)
717{ 715{
718 struct raw_sock *rp = raw_sk(sk); 716 struct raw_sock *rp = raw_sk(sk);
719 717
720 if (inet_sk(sk)->num == IPPROTO_ICMP) 718 if (inet_sk(sk)->inet_num == IPPROTO_ICMP)
721 memset(&rp->filter, 0, sizeof(rp->filter)); 719 memset(&rp->filter, 0, sizeof(rp->filter));
722 return 0; 720 return 0;
723} 721}
@@ -754,7 +752,7 @@ static int do_raw_setsockopt(struct sock *sk, int level, int optname,
754 char __user *optval, unsigned int optlen) 752 char __user *optval, unsigned int optlen)
755{ 753{
756 if (optname == ICMP_FILTER) { 754 if (optname == ICMP_FILTER) {
757 if (inet_sk(sk)->num != IPPROTO_ICMP) 755 if (inet_sk(sk)->inet_num != IPPROTO_ICMP)
758 return -EOPNOTSUPP; 756 return -EOPNOTSUPP;
759 else 757 else
760 return raw_seticmpfilter(sk, optval, optlen); 758 return raw_seticmpfilter(sk, optval, optlen);
@@ -784,7 +782,7 @@ static int do_raw_getsockopt(struct sock *sk, int level, int optname,
784 char __user *optval, int __user *optlen) 782 char __user *optval, int __user *optlen)
785{ 783{
786 if (optname == ICMP_FILTER) { 784 if (optname == ICMP_FILTER) {
787 if (inet_sk(sk)->num != IPPROTO_ICMP) 785 if (inet_sk(sk)->inet_num != IPPROTO_ICMP)
788 return -EOPNOTSUPP; 786 return -EOPNOTSUPP;
789 else 787 else
790 return raw_geticmpfilter(sk, optval, optlen); 788 return raw_geticmpfilter(sk, optval, optlen);
@@ -943,10 +941,10 @@ EXPORT_SYMBOL_GPL(raw_seq_stop);
943static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i) 941static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
944{ 942{
945 struct inet_sock *inet = inet_sk(sp); 943 struct inet_sock *inet = inet_sk(sp);
946 __be32 dest = inet->daddr, 944 __be32 dest = inet->inet_daddr,
947 src = inet->rcv_saddr; 945 src = inet->inet_rcv_saddr;
948 __u16 destp = 0, 946 __u16 destp = 0,
949 srcp = inet->num; 947 srcp = inet->inet_num;
950 948
951 seq_printf(seq, "%4d: %08X:%04X %08X:%04X" 949 seq_printf(seq, "%4d: %08X:%04X %08X:%04X"
952 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %lu %d %p %d\n", 950 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %lu %d %p %d\n",
diff --git a/net/ipv4/route.c b/net/ipv4/route.c
index 5b1050a5d874..cb562fdd9b9a 100644
--- a/net/ipv4/route.c
+++ b/net/ipv4/route.c
@@ -90,6 +90,7 @@
90#include <linux/jhash.h> 90#include <linux/jhash.h>
91#include <linux/rcupdate.h> 91#include <linux/rcupdate.h>
92#include <linux/times.h> 92#include <linux/times.h>
93#include <linux/slab.h>
93#include <net/dst.h> 94#include <net/dst.h>
94#include <net/net_namespace.h> 95#include <net/net_namespace.h>
95#include <net/protocol.h> 96#include <net/protocol.h>
@@ -146,7 +147,6 @@ static struct dst_entry *ipv4_negative_advice(struct dst_entry *dst);
146static void ipv4_link_failure(struct sk_buff *skb); 147static void ipv4_link_failure(struct sk_buff *skb);
147static void ip_rt_update_pmtu(struct dst_entry *dst, u32 mtu); 148static void ip_rt_update_pmtu(struct dst_entry *dst, u32 mtu);
148static int rt_garbage_collect(struct dst_ops *ops); 149static int rt_garbage_collect(struct dst_ops *ops);
149static void rt_emergency_hash_rebuild(struct net *net);
150 150
151 151
152static struct dst_ops ipv4_dst_ops = { 152static struct dst_ops ipv4_dst_ops = {
@@ -287,12 +287,12 @@ static struct rtable *rt_cache_get_first(struct seq_file *seq)
287 if (!rt_hash_table[st->bucket].chain) 287 if (!rt_hash_table[st->bucket].chain)
288 continue; 288 continue;
289 rcu_read_lock_bh(); 289 rcu_read_lock_bh();
290 r = rcu_dereference(rt_hash_table[st->bucket].chain); 290 r = rcu_dereference_bh(rt_hash_table[st->bucket].chain);
291 while (r) { 291 while (r) {
292 if (dev_net(r->u.dst.dev) == seq_file_net(seq) && 292 if (dev_net(r->u.dst.dev) == seq_file_net(seq) &&
293 r->rt_genid == st->genid) 293 r->rt_genid == st->genid)
294 return r; 294 return r;
295 r = rcu_dereference(r->u.dst.rt_next); 295 r = rcu_dereference_bh(r->u.dst.rt_next);
296 } 296 }
297 rcu_read_unlock_bh(); 297 rcu_read_unlock_bh();
298 } 298 }
@@ -314,7 +314,7 @@ static struct rtable *__rt_cache_get_next(struct seq_file *seq,
314 rcu_read_lock_bh(); 314 rcu_read_lock_bh();
315 r = rt_hash_table[st->bucket].chain; 315 r = rt_hash_table[st->bucket].chain;
316 } 316 }
317 return rcu_dereference(r); 317 return rcu_dereference_bh(r);
318} 318}
319 319
320static struct rtable *rt_cache_get_next(struct seq_file *seq, 320static struct rtable *rt_cache_get_next(struct seq_file *seq,
@@ -513,43 +513,42 @@ static const struct file_operations rt_cpu_seq_fops = {
513}; 513};
514 514
515#ifdef CONFIG_NET_CLS_ROUTE 515#ifdef CONFIG_NET_CLS_ROUTE
516static int ip_rt_acct_read(char *buffer, char **start, off_t offset, 516static int rt_acct_proc_show(struct seq_file *m, void *v)
517 int length, int *eof, void *data) 517{
518{ 518 struct ip_rt_acct *dst, *src;
519 unsigned int i; 519 unsigned int i, j;
520 520
521 if ((offset & 3) || (length & 3)) 521 dst = kcalloc(256, sizeof(struct ip_rt_acct), GFP_KERNEL);
522 return -EIO; 522 if (!dst)
523 523 return -ENOMEM;
524 if (offset >= sizeof(struct ip_rt_acct) * 256) { 524
525 *eof = 1; 525 for_each_possible_cpu(i) {
526 return 0; 526 src = (struct ip_rt_acct *)per_cpu_ptr(ip_rt_acct, i);
527 } 527 for (j = 0; j < 256; j++) {
528 528 dst[j].o_bytes += src[j].o_bytes;
529 if (offset + length >= sizeof(struct ip_rt_acct) * 256) { 529 dst[j].o_packets += src[j].o_packets;
530 length = sizeof(struct ip_rt_acct) * 256 - offset; 530 dst[j].i_bytes += src[j].i_bytes;
531 *eof = 1; 531 dst[j].i_packets += src[j].i_packets;
532 }
532 } 533 }
533 534
534 offset /= sizeof(u32); 535 seq_write(m, dst, 256 * sizeof(struct ip_rt_acct));
535 536 kfree(dst);
536 if (length > 0) { 537 return 0;
537 u32 *dst = (u32 *) buffer; 538}
538
539 *start = buffer;
540 memset(dst, 0, length);
541
542 for_each_possible_cpu(i) {
543 unsigned int j;
544 u32 *src;
545 539
546 src = ((u32 *) per_cpu_ptr(ip_rt_acct, i)) + offset; 540static int rt_acct_proc_open(struct inode *inode, struct file *file)
547 for (j = 0; j < length/4; j++) 541{
548 dst[j] += src[j]; 542 return single_open(file, rt_acct_proc_show, NULL);
549 }
550 }
551 return length;
552} 543}
544
545static const struct file_operations rt_acct_proc_fops = {
546 .owner = THIS_MODULE,
547 .open = rt_acct_proc_open,
548 .read = seq_read,
549 .llseek = seq_lseek,
550 .release = single_release,
551};
553#endif 552#endif
554 553
555static int __net_init ip_rt_do_proc_init(struct net *net) 554static int __net_init ip_rt_do_proc_init(struct net *net)
@@ -567,8 +566,7 @@ static int __net_init ip_rt_do_proc_init(struct net *net)
567 goto err2; 566 goto err2;
568 567
569#ifdef CONFIG_NET_CLS_ROUTE 568#ifdef CONFIG_NET_CLS_ROUTE
570 pde = create_proc_read_entry("rt_acct", 0, net->proc_net, 569 pde = proc_create("rt_acct", 0, net->proc_net, &rt_acct_proc_fops);
571 ip_rt_acct_read, NULL);
572 if (!pde) 570 if (!pde)
573 goto err3; 571 goto err3;
574#endif 572#endif
@@ -588,7 +586,9 @@ static void __net_exit ip_rt_do_proc_exit(struct net *net)
588{ 586{
589 remove_proc_entry("rt_cache", net->proc_net_stat); 587 remove_proc_entry("rt_cache", net->proc_net_stat);
590 remove_proc_entry("rt_cache", net->proc_net); 588 remove_proc_entry("rt_cache", net->proc_net);
589#ifdef CONFIG_NET_CLS_ROUTE
591 remove_proc_entry("rt_acct", net->proc_net); 590 remove_proc_entry("rt_acct", net->proc_net);
591#endif
592} 592}
593 593
594static struct pernet_operations ip_rt_proc_ops __net_initdata = { 594static struct pernet_operations ip_rt_proc_ops __net_initdata = {
@@ -703,7 +703,7 @@ static inline int compare_keys(struct flowi *fl1, struct flowi *fl2)
703 703
704static inline int compare_netns(struct rtable *rt1, struct rtable *rt2) 704static inline int compare_netns(struct rtable *rt1, struct rtable *rt2)
705{ 705{
706 return dev_net(rt1->u.dst.dev) == dev_net(rt2->u.dst.dev); 706 return net_eq(dev_net(rt1->u.dst.dev), dev_net(rt2->u.dst.dev));
707} 707}
708 708
709static inline int rt_is_expired(struct rtable *rth) 709static inline int rt_is_expired(struct rtable *rth)
@@ -780,11 +780,30 @@ static void rt_do_flush(int process_context)
780#define FRACT_BITS 3 780#define FRACT_BITS 3
781#define ONE (1UL << FRACT_BITS) 781#define ONE (1UL << FRACT_BITS)
782 782
783/*
784 * Given a hash chain and an item in this hash chain,
785 * find if a previous entry has the same hash_inputs
786 * (but differs on tos, mark or oif)
787 * Returns 0 if an alias is found.
788 * Returns ONE if rth has no alias before itself.
789 */
790static int has_noalias(const struct rtable *head, const struct rtable *rth)
791{
792 const struct rtable *aux = head;
793
794 while (aux != rth) {
795 if (compare_hash_inputs(&aux->fl, &rth->fl))
796 return 0;
797 aux = aux->u.dst.rt_next;
798 }
799 return ONE;
800}
801
783static void rt_check_expire(void) 802static void rt_check_expire(void)
784{ 803{
785 static unsigned int rover; 804 static unsigned int rover;
786 unsigned int i = rover, goal; 805 unsigned int i = rover, goal;
787 struct rtable *rth, *aux, **rthp; 806 struct rtable *rth, **rthp;
788 unsigned long samples = 0; 807 unsigned long samples = 0;
789 unsigned long sum = 0, sum2 = 0; 808 unsigned long sum = 0, sum2 = 0;
790 unsigned long delta; 809 unsigned long delta;
@@ -835,15 +854,7 @@ nofree:
835 * attributes don't unfairly skew 854 * attributes don't unfairly skew
836 * the length computation 855 * the length computation
837 */ 856 */
838 for (aux = rt_hash_table[i].chain;;) { 857 length += has_noalias(rt_hash_table[i].chain, rth);
839 if (aux == rth) {
840 length += ONE;
841 break;
842 }
843 if (compare_hash_inputs(&aux->fl, &rth->fl))
844 break;
845 aux = aux->u.dst.rt_next;
846 }
847 continue; 858 continue;
848 } 859 }
849 } else if (!rt_may_expire(rth, tmo, ip_rt_gc_timeout)) 860 } else if (!rt_may_expire(rth, tmo, ip_rt_gc_timeout))
@@ -902,6 +913,12 @@ void rt_cache_flush(struct net *net, int delay)
902 rt_do_flush(!in_softirq()); 913 rt_do_flush(!in_softirq());
903} 914}
904 915
916/* Flush previous cache invalidated entries from the cache */
917void rt_cache_flush_batch(void)
918{
919 rt_do_flush(!in_softirq());
920}
921
905/* 922/*
906 * We change rt_genid and let gc do the cleanup 923 * We change rt_genid and let gc do the cleanup
907 */ 924 */
@@ -916,10 +933,8 @@ static void rt_secret_rebuild_oneshot(struct net *net)
916{ 933{
917 del_timer_sync(&net->ipv4.rt_secret_timer); 934 del_timer_sync(&net->ipv4.rt_secret_timer);
918 rt_cache_invalidate(net); 935 rt_cache_invalidate(net);
919 if (ip_rt_secret_interval) { 936 if (ip_rt_secret_interval)
920 net->ipv4.rt_secret_timer.expires += ip_rt_secret_interval; 937 mod_timer(&net->ipv4.rt_secret_timer, jiffies + ip_rt_secret_interval);
921 add_timer(&net->ipv4.rt_secret_timer);
922 }
923} 938}
924 939
925static void rt_emergency_hash_rebuild(struct net *net) 940static void rt_emergency_hash_rebuild(struct net *net)
@@ -1067,8 +1082,23 @@ work_done:
1067out: return 0; 1082out: return 0;
1068} 1083}
1069 1084
1085/*
1086 * Returns number of entries in a hash chain that have different hash_inputs
1087 */
1088static int slow_chain_length(const struct rtable *head)
1089{
1090 int length = 0;
1091 const struct rtable *rth = head;
1092
1093 while (rth) {
1094 length += has_noalias(head, rth);
1095 rth = rth->u.dst.rt_next;
1096 }
1097 return length >> FRACT_BITS;
1098}
1099
1070static int rt_intern_hash(unsigned hash, struct rtable *rt, 1100static int rt_intern_hash(unsigned hash, struct rtable *rt,
1071 struct rtable **rp, struct sk_buff *skb) 1101 struct rtable **rp, struct sk_buff *skb, int ifindex)
1072{ 1102{
1073 struct rtable *rth, **rthp; 1103 struct rtable *rth, **rthp;
1074 unsigned long now; 1104 unsigned long now;
@@ -1179,14 +1209,20 @@ restart:
1179 rt_free(cand); 1209 rt_free(cand);
1180 } 1210 }
1181 } else { 1211 } else {
1182 if (chain_length > rt_chain_length_max) { 1212 if (chain_length > rt_chain_length_max &&
1213 slow_chain_length(rt_hash_table[hash].chain) > rt_chain_length_max) {
1183 struct net *net = dev_net(rt->u.dst.dev); 1214 struct net *net = dev_net(rt->u.dst.dev);
1184 int num = ++net->ipv4.current_rt_cache_rebuild_count; 1215 int num = ++net->ipv4.current_rt_cache_rebuild_count;
1185 if (!rt_caching(dev_net(rt->u.dst.dev))) { 1216 if (!rt_caching(net)) {
1186 printk(KERN_WARNING "%s: %d rebuilds is over limit, route caching disabled\n", 1217 printk(KERN_WARNING "%s: %d rebuilds is over limit, route caching disabled\n",
1187 rt->u.dst.dev->name, num); 1218 rt->u.dst.dev->name, num);
1188 } 1219 }
1189 rt_emergency_hash_rebuild(dev_net(rt->u.dst.dev)); 1220 rt_emergency_hash_rebuild(net);
1221 spin_unlock_bh(rt_hash_lock_addr(hash));
1222
1223 hash = rt_hash(rt->fl.fl4_dst, rt->fl.fl4_src,
1224 ifindex, rt_genid(net));
1225 goto restart;
1190 } 1226 }
1191 } 1227 }
1192 1228
@@ -1346,9 +1382,9 @@ void ip_rt_redirect(__be32 old_gw, __be32 daddr, __be32 new_gw,
1346 return; 1382 return;
1347 1383
1348 net = dev_net(dev); 1384 net = dev_net(dev);
1349 if (new_gw == old_gw || !IN_DEV_RX_REDIRECTS(in_dev) 1385 if (new_gw == old_gw || !IN_DEV_RX_REDIRECTS(in_dev) ||
1350 || ipv4_is_multicast(new_gw) || ipv4_is_lbcast(new_gw) 1386 ipv4_is_multicast(new_gw) || ipv4_is_lbcast(new_gw) ||
1351 || ipv4_is_zeronet(new_gw)) 1387 ipv4_is_zeronet(new_gw))
1352 goto reject_redirect; 1388 goto reject_redirect;
1353 1389
1354 if (!rt_caching(net)) 1390 if (!rt_caching(net))
@@ -1411,7 +1447,7 @@ void ip_rt_redirect(__be32 old_gw, __be32 daddr, __be32 new_gw,
1411 dev_hold(rt->u.dst.dev); 1447 dev_hold(rt->u.dst.dev);
1412 if (rt->idev) 1448 if (rt->idev)
1413 in_dev_hold(rt->idev); 1449 in_dev_hold(rt->idev);
1414 rt->u.dst.obsolete = 0; 1450 rt->u.dst.obsolete = -1;
1415 rt->u.dst.lastuse = jiffies; 1451 rt->u.dst.lastuse = jiffies;
1416 rt->u.dst.path = &rt->u.dst; 1452 rt->u.dst.path = &rt->u.dst;
1417 rt->u.dst.neighbour = NULL; 1453 rt->u.dst.neighbour = NULL;
@@ -1447,7 +1483,7 @@ void ip_rt_redirect(__be32 old_gw, __be32 daddr, __be32 new_gw,
1447 &netevent); 1483 &netevent);
1448 1484
1449 rt_del(hash, rth); 1485 rt_del(hash, rth);
1450 if (!rt_intern_hash(hash, rt, &rt, NULL)) 1486 if (!rt_intern_hash(hash, rt, &rt, NULL, rt->fl.oif))
1451 ip_rt_put(rt); 1487 ip_rt_put(rt);
1452 goto do_next; 1488 goto do_next;
1453 } 1489 }
@@ -1476,11 +1512,12 @@ static struct dst_entry *ipv4_negative_advice(struct dst_entry *dst)
1476 struct dst_entry *ret = dst; 1512 struct dst_entry *ret = dst;
1477 1513
1478 if (rt) { 1514 if (rt) {
1479 if (dst->obsolete) { 1515 if (dst->obsolete > 0) {
1480 ip_rt_put(rt); 1516 ip_rt_put(rt);
1481 ret = NULL; 1517 ret = NULL;
1482 } else if ((rt->rt_flags & RTCF_REDIRECTED) || 1518 } else if ((rt->rt_flags & RTCF_REDIRECTED) ||
1483 rt->u.dst.expires) { 1519 (rt->u.dst.expires &&
1520 time_after_eq(jiffies, rt->u.dst.expires))) {
1484 unsigned hash = rt_hash(rt->fl.fl4_dst, rt->fl.fl4_src, 1521 unsigned hash = rt_hash(rt->fl.fl4_dst, rt->fl.fl4_src,
1485 rt->fl.oif, 1522 rt->fl.oif,
1486 rt_genid(dev_net(dst->dev))); 1523 rt_genid(dev_net(dst->dev)));
@@ -1628,9 +1665,6 @@ unsigned short ip_rt_frag_needed(struct net *net, struct iphdr *iph,
1628 __be32 daddr = iph->daddr; 1665 __be32 daddr = iph->daddr;
1629 unsigned short est_mtu = 0; 1666 unsigned short est_mtu = 0;
1630 1667
1631 if (ipv4_config.no_pmtu_disc)
1632 return 0;
1633
1634 for (k = 0; k < 2; k++) { 1668 for (k = 0; k < 2; k++) {
1635 for (i = 0; i < 2; i++) { 1669 for (i = 0; i < 2; i++) {
1636 unsigned hash = rt_hash(daddr, skeys[i], ikeys[k], 1670 unsigned hash = rt_hash(daddr, skeys[i], ikeys[k],
@@ -1699,7 +1733,9 @@ static void ip_rt_update_pmtu(struct dst_entry *dst, u32 mtu)
1699 1733
1700static struct dst_entry *ipv4_dst_check(struct dst_entry *dst, u32 cookie) 1734static struct dst_entry *ipv4_dst_check(struct dst_entry *dst, u32 cookie)
1701{ 1735{
1702 return NULL; 1736 if (rt_is_expired((struct rtable *)dst))
1737 return NULL;
1738 return dst;
1703} 1739}
1704 1740
1705static void ipv4_dst_destroy(struct dst_entry *dst) 1741static void ipv4_dst_destroy(struct dst_entry *dst)
@@ -1861,7 +1897,8 @@ static int ip_route_input_mc(struct sk_buff *skb, __be32 daddr, __be32 saddr,
1861 if (!rth) 1897 if (!rth)
1862 goto e_nobufs; 1898 goto e_nobufs;
1863 1899
1864 rth->u.dst.output= ip_rt_bug; 1900 rth->u.dst.output = ip_rt_bug;
1901 rth->u.dst.obsolete = -1;
1865 1902
1866 atomic_set(&rth->u.dst.__refcnt, 1); 1903 atomic_set(&rth->u.dst.__refcnt, 1);
1867 rth->u.dst.flags= DST_HOST; 1904 rth->u.dst.flags= DST_HOST;
@@ -1900,7 +1937,7 @@ static int ip_route_input_mc(struct sk_buff *skb, __be32 daddr, __be32 saddr,
1900 1937
1901 in_dev_put(in_dev); 1938 in_dev_put(in_dev);
1902 hash = rt_hash(daddr, saddr, dev->ifindex, rt_genid(dev_net(dev))); 1939 hash = rt_hash(daddr, saddr, dev->ifindex, rt_genid(dev_net(dev)));
1903 return rt_intern_hash(hash, rth, NULL, skb); 1940 return rt_intern_hash(hash, rth, NULL, skb, dev->ifindex);
1904 1941
1905e_nobufs: 1942e_nobufs:
1906 in_dev_put(in_dev); 1943 in_dev_put(in_dev);
@@ -1987,8 +2024,13 @@ static int __mkroute_input(struct sk_buff *skb,
1987 if (skb->protocol != htons(ETH_P_IP)) { 2024 if (skb->protocol != htons(ETH_P_IP)) {
1988 /* Not IP (i.e. ARP). Do not create route, if it is 2025 /* Not IP (i.e. ARP). Do not create route, if it is
1989 * invalid for proxy arp. DNAT routes are always valid. 2026 * invalid for proxy arp. DNAT routes are always valid.
2027 *
2028 * Proxy arp feature have been extended to allow, ARP
2029 * replies back to the same interface, to support
2030 * Private VLAN switch technologies. See arp.c.
1990 */ 2031 */
1991 if (out_dev == in_dev) { 2032 if (out_dev == in_dev &&
2033 IN_DEV_PROXY_ARP_PVLAN(in_dev) == 0) {
1992 err = -EINVAL; 2034 err = -EINVAL;
1993 goto cleanup; 2035 goto cleanup;
1994 } 2036 }
@@ -2022,6 +2064,7 @@ static int __mkroute_input(struct sk_buff *skb,
2022 rth->fl.oif = 0; 2064 rth->fl.oif = 0;
2023 rth->rt_spec_dst= spec_dst; 2065 rth->rt_spec_dst= spec_dst;
2024 2066
2067 rth->u.dst.obsolete = -1;
2025 rth->u.dst.input = ip_forward; 2068 rth->u.dst.input = ip_forward;
2026 rth->u.dst.output = ip_output; 2069 rth->u.dst.output = ip_output;
2027 rth->rt_genid = rt_genid(dev_net(rth->u.dst.dev)); 2070 rth->rt_genid = rt_genid(dev_net(rth->u.dst.dev));
@@ -2061,7 +2104,7 @@ static int ip_mkroute_input(struct sk_buff *skb,
2061 /* put it into the cache */ 2104 /* put it into the cache */
2062 hash = rt_hash(daddr, saddr, fl->iif, 2105 hash = rt_hash(daddr, saddr, fl->iif,
2063 rt_genid(dev_net(rth->u.dst.dev))); 2106 rt_genid(dev_net(rth->u.dst.dev)));
2064 return rt_intern_hash(hash, rth, NULL, skb); 2107 return rt_intern_hash(hash, rth, NULL, skb, fl->iif);
2065} 2108}
2066 2109
2067/* 2110/*
@@ -2186,6 +2229,7 @@ local_input:
2186 goto e_nobufs; 2229 goto e_nobufs;
2187 2230
2188 rth->u.dst.output= ip_rt_bug; 2231 rth->u.dst.output= ip_rt_bug;
2232 rth->u.dst.obsolete = -1;
2189 rth->rt_genid = rt_genid(net); 2233 rth->rt_genid = rt_genid(net);
2190 2234
2191 atomic_set(&rth->u.dst.__refcnt, 1); 2235 atomic_set(&rth->u.dst.__refcnt, 1);
@@ -2217,7 +2261,7 @@ local_input:
2217 } 2261 }
2218 rth->rt_type = res.type; 2262 rth->rt_type = res.type;
2219 hash = rt_hash(daddr, saddr, fl.iif, rt_genid(net)); 2263 hash = rt_hash(daddr, saddr, fl.iif, rt_genid(net));
2220 err = rt_intern_hash(hash, rth, NULL, skb); 2264 err = rt_intern_hash(hash, rth, NULL, skb, fl.iif);
2221 goto done; 2265 goto done;
2222 2266
2223no_route: 2267no_route:
@@ -2314,10 +2358,11 @@ skip_cache:
2314 ip_hdr(skb)->protocol); 2358 ip_hdr(skb)->protocol);
2315 if (our 2359 if (our
2316#ifdef CONFIG_IP_MROUTE 2360#ifdef CONFIG_IP_MROUTE
2317 || (!ipv4_is_local_multicast(daddr) && 2361 ||
2318 IN_DEV_MFORWARD(in_dev)) 2362 (!ipv4_is_local_multicast(daddr) &&
2363 IN_DEV_MFORWARD(in_dev))
2319#endif 2364#endif
2320 ) { 2365 ) {
2321 rcu_read_unlock(); 2366 rcu_read_unlock();
2322 return ip_route_input_mc(skb, daddr, saddr, 2367 return ip_route_input_mc(skb, daddr, saddr,
2323 tos, dev, our); 2368 tos, dev, our);
@@ -2411,6 +2456,7 @@ static int __mkroute_output(struct rtable **result,
2411 rth->rt_spec_dst= fl->fl4_src; 2456 rth->rt_spec_dst= fl->fl4_src;
2412 2457
2413 rth->u.dst.output=ip_output; 2458 rth->u.dst.output=ip_output;
2459 rth->u.dst.obsolete = -1;
2414 rth->rt_genid = rt_genid(dev_net(dev_out)); 2460 rth->rt_genid = rt_genid(dev_net(dev_out));
2415 2461
2416 RT_CACHE_STAT_INC(out_slow_tot); 2462 RT_CACHE_STAT_INC(out_slow_tot);
@@ -2462,7 +2508,7 @@ static int ip_mkroute_output(struct rtable **rp,
2462 if (err == 0) { 2508 if (err == 0) {
2463 hash = rt_hash(oldflp->fl4_dst, oldflp->fl4_src, oldflp->oif, 2509 hash = rt_hash(oldflp->fl4_dst, oldflp->fl4_src, oldflp->oif,
2464 rt_genid(dev_net(dev_out))); 2510 rt_genid(dev_net(dev_out)));
2465 err = rt_intern_hash(hash, rth, rp, NULL); 2511 err = rt_intern_hash(hash, rth, rp, NULL, oldflp->oif);
2466 } 2512 }
2467 2513
2468 return err; 2514 return err;
@@ -2514,9 +2560,9 @@ static int ip_route_output_slow(struct net *net, struct rtable **rp,
2514 of another iface. --ANK 2560 of another iface. --ANK
2515 */ 2561 */
2516 2562
2517 if (oldflp->oif == 0 2563 if (oldflp->oif == 0 &&
2518 && (ipv4_is_multicast(oldflp->fl4_dst) || 2564 (ipv4_is_multicast(oldflp->fl4_dst) ||
2519 oldflp->fl4_dst == htonl(0xFFFFFFFF))) { 2565 oldflp->fl4_dst == htonl(0xFFFFFFFF))) {
2520 /* It is equivalent to inet_addr_type(saddr) == RTN_LOCAL */ 2566 /* It is equivalent to inet_addr_type(saddr) == RTN_LOCAL */
2521 dev_out = ip_dev_find(net, oldflp->fl4_src); 2567 dev_out = ip_dev_find(net, oldflp->fl4_src);
2522 if (dev_out == NULL) 2568 if (dev_out == NULL)
@@ -2685,8 +2731,8 @@ int __ip_route_output_key(struct net *net, struct rtable **rp,
2685 hash = rt_hash(flp->fl4_dst, flp->fl4_src, flp->oif, rt_genid(net)); 2731 hash = rt_hash(flp->fl4_dst, flp->fl4_src, flp->oif, rt_genid(net));
2686 2732
2687 rcu_read_lock_bh(); 2733 rcu_read_lock_bh();
2688 for (rth = rcu_dereference(rt_hash_table[hash].chain); rth; 2734 for (rth = rcu_dereference_bh(rt_hash_table[hash].chain); rth;
2689 rth = rcu_dereference(rth->u.dst.rt_next)) { 2735 rth = rcu_dereference_bh(rth->u.dst.rt_next)) {
2690 if (rth->fl.fl4_dst == flp->fl4_dst && 2736 if (rth->fl.fl4_dst == flp->fl4_dst &&
2691 rth->fl.fl4_src == flp->fl4_src && 2737 rth->fl.fl4_src == flp->fl4_src &&
2692 rth->fl.iif == 0 && 2738 rth->fl.iif == 0 &&
@@ -2855,7 +2901,7 @@ static int rt_fill_info(struct net *net,
2855 error = rt->u.dst.error; 2901 error = rt->u.dst.error;
2856 expires = rt->u.dst.expires ? rt->u.dst.expires - jiffies : 0; 2902 expires = rt->u.dst.expires ? rt->u.dst.expires - jiffies : 0;
2857 if (rt->peer) { 2903 if (rt->peer) {
2858 id = rt->peer->ip_id_count; 2904 id = atomic_read(&rt->peer->ip_id_count) & 0xffff;
2859 if (rt->peer->tcp_ts_stamp) { 2905 if (rt->peer->tcp_ts_stamp) {
2860 ts = rt->peer->tcp_ts; 2906 ts = rt->peer->tcp_ts;
2861 tsage = get_seconds() - rt->peer->tcp_ts_stamp; 2907 tsage = get_seconds() - rt->peer->tcp_ts_stamp;
@@ -3004,8 +3050,8 @@ int ip_rt_dump(struct sk_buff *skb, struct netlink_callback *cb)
3004 if (!rt_hash_table[h].chain) 3050 if (!rt_hash_table[h].chain)
3005 continue; 3051 continue;
3006 rcu_read_lock_bh(); 3052 rcu_read_lock_bh();
3007 for (rt = rcu_dereference(rt_hash_table[h].chain), idx = 0; rt; 3053 for (rt = rcu_dereference_bh(rt_hash_table[h].chain), idx = 0; rt;
3008 rt = rcu_dereference(rt->u.dst.rt_next), idx++) { 3054 rt = rcu_dereference_bh(rt->u.dst.rt_next), idx++) {
3009 if (!net_eq(dev_net(rt->u.dst.dev), net) || idx < s_idx) 3055 if (!net_eq(dev_net(rt->u.dst.dev), net) || idx < s_idx)
3010 continue; 3056 continue;
3011 if (rt_is_expired(rt)) 3057 if (rt_is_expired(rt))
@@ -3056,23 +3102,6 @@ static int ipv4_sysctl_rtcache_flush(ctl_table *__ctl, int write,
3056 return -EINVAL; 3102 return -EINVAL;
3057} 3103}
3058 3104
3059static int ipv4_sysctl_rtcache_flush_strategy(ctl_table *table,
3060 void __user *oldval,
3061 size_t __user *oldlenp,
3062 void __user *newval,
3063 size_t newlen)
3064{
3065 int delay;
3066 struct net *net;
3067 if (newlen != sizeof(int))
3068 return -EINVAL;
3069 if (get_user(delay, (int __user *)newval))
3070 return -EFAULT;
3071 net = (struct net *)table->extra1;
3072 rt_cache_flush(net, delay);
3073 return 0;
3074}
3075
3076static void rt_secret_reschedule(int old) 3105static void rt_secret_reschedule(int old)
3077{ 3106{
3078 struct net *net; 3107 struct net *net;
@@ -3085,22 +3114,20 @@ static void rt_secret_reschedule(int old)
3085 rtnl_lock(); 3114 rtnl_lock();
3086 for_each_net(net) { 3115 for_each_net(net) {
3087 int deleted = del_timer_sync(&net->ipv4.rt_secret_timer); 3116 int deleted = del_timer_sync(&net->ipv4.rt_secret_timer);
3117 long time;
3088 3118
3089 if (!new) 3119 if (!new)
3090 continue; 3120 continue;
3091 3121
3092 if (deleted) { 3122 if (deleted) {
3093 long time = net->ipv4.rt_secret_timer.expires - jiffies; 3123 time = net->ipv4.rt_secret_timer.expires - jiffies;
3094 3124
3095 if (time <= 0 || (time += diff) <= 0) 3125 if (time <= 0 || (time += diff) <= 0)
3096 time = 0; 3126 time = 0;
3097
3098 net->ipv4.rt_secret_timer.expires = time;
3099 } else 3127 } else
3100 net->ipv4.rt_secret_timer.expires = new; 3128 time = new;
3101 3129
3102 net->ipv4.rt_secret_timer.expires += jiffies; 3130 mod_timer(&net->ipv4.rt_secret_timer, jiffies + time);
3103 add_timer(&net->ipv4.rt_secret_timer);
3104 } 3131 }
3105 rtnl_unlock(); 3132 rtnl_unlock();
3106} 3133}
@@ -3117,23 +3144,8 @@ static int ipv4_sysctl_rt_secret_interval(ctl_table *ctl, int write,
3117 return ret; 3144 return ret;
3118} 3145}
3119 3146
3120static int ipv4_sysctl_rt_secret_interval_strategy(ctl_table *table,
3121 void __user *oldval,
3122 size_t __user *oldlenp,
3123 void __user *newval,
3124 size_t newlen)
3125{
3126 int old = ip_rt_secret_interval;
3127 int ret = sysctl_jiffies(table, oldval, oldlenp, newval, newlen);
3128
3129 rt_secret_reschedule(old);
3130
3131 return ret;
3132}
3133
3134static ctl_table ipv4_route_table[] = { 3147static ctl_table ipv4_route_table[] = {
3135 { 3148 {
3136 .ctl_name = NET_IPV4_ROUTE_GC_THRESH,
3137 .procname = "gc_thresh", 3149 .procname = "gc_thresh",
3138 .data = &ipv4_dst_ops.gc_thresh, 3150 .data = &ipv4_dst_ops.gc_thresh,
3139 .maxlen = sizeof(int), 3151 .maxlen = sizeof(int),
@@ -3141,7 +3153,6 @@ static ctl_table ipv4_route_table[] = {
3141 .proc_handler = proc_dointvec, 3153 .proc_handler = proc_dointvec,
3142 }, 3154 },
3143 { 3155 {
3144 .ctl_name = NET_IPV4_ROUTE_MAX_SIZE,
3145 .procname = "max_size", 3156 .procname = "max_size",
3146 .data = &ip_rt_max_size, 3157 .data = &ip_rt_max_size,
3147 .maxlen = sizeof(int), 3158 .maxlen = sizeof(int),
@@ -3151,43 +3162,34 @@ static ctl_table ipv4_route_table[] = {
3151 { 3162 {
3152 /* Deprecated. Use gc_min_interval_ms */ 3163 /* Deprecated. Use gc_min_interval_ms */
3153 3164
3154 .ctl_name = NET_IPV4_ROUTE_GC_MIN_INTERVAL,
3155 .procname = "gc_min_interval", 3165 .procname = "gc_min_interval",
3156 .data = &ip_rt_gc_min_interval, 3166 .data = &ip_rt_gc_min_interval,
3157 .maxlen = sizeof(int), 3167 .maxlen = sizeof(int),
3158 .mode = 0644, 3168 .mode = 0644,
3159 .proc_handler = proc_dointvec_jiffies, 3169 .proc_handler = proc_dointvec_jiffies,
3160 .strategy = sysctl_jiffies,
3161 }, 3170 },
3162 { 3171 {
3163 .ctl_name = NET_IPV4_ROUTE_GC_MIN_INTERVAL_MS,
3164 .procname = "gc_min_interval_ms", 3172 .procname = "gc_min_interval_ms",
3165 .data = &ip_rt_gc_min_interval, 3173 .data = &ip_rt_gc_min_interval,
3166 .maxlen = sizeof(int), 3174 .maxlen = sizeof(int),
3167 .mode = 0644, 3175 .mode = 0644,
3168 .proc_handler = proc_dointvec_ms_jiffies, 3176 .proc_handler = proc_dointvec_ms_jiffies,
3169 .strategy = sysctl_ms_jiffies,
3170 }, 3177 },
3171 { 3178 {
3172 .ctl_name = NET_IPV4_ROUTE_GC_TIMEOUT,
3173 .procname = "gc_timeout", 3179 .procname = "gc_timeout",
3174 .data = &ip_rt_gc_timeout, 3180 .data = &ip_rt_gc_timeout,
3175 .maxlen = sizeof(int), 3181 .maxlen = sizeof(int),
3176 .mode = 0644, 3182 .mode = 0644,
3177 .proc_handler = proc_dointvec_jiffies, 3183 .proc_handler = proc_dointvec_jiffies,
3178 .strategy = sysctl_jiffies,
3179 }, 3184 },
3180 { 3185 {
3181 .ctl_name = NET_IPV4_ROUTE_GC_INTERVAL,
3182 .procname = "gc_interval", 3186 .procname = "gc_interval",
3183 .data = &ip_rt_gc_interval, 3187 .data = &ip_rt_gc_interval,
3184 .maxlen = sizeof(int), 3188 .maxlen = sizeof(int),
3185 .mode = 0644, 3189 .mode = 0644,
3186 .proc_handler = proc_dointvec_jiffies, 3190 .proc_handler = proc_dointvec_jiffies,
3187 .strategy = sysctl_jiffies,
3188 }, 3191 },
3189 { 3192 {
3190 .ctl_name = NET_IPV4_ROUTE_REDIRECT_LOAD,
3191 .procname = "redirect_load", 3193 .procname = "redirect_load",
3192 .data = &ip_rt_redirect_load, 3194 .data = &ip_rt_redirect_load,
3193 .maxlen = sizeof(int), 3195 .maxlen = sizeof(int),
@@ -3195,7 +3197,6 @@ static ctl_table ipv4_route_table[] = {
3195 .proc_handler = proc_dointvec, 3197 .proc_handler = proc_dointvec,
3196 }, 3198 },
3197 { 3199 {
3198 .ctl_name = NET_IPV4_ROUTE_REDIRECT_NUMBER,
3199 .procname = "redirect_number", 3200 .procname = "redirect_number",
3200 .data = &ip_rt_redirect_number, 3201 .data = &ip_rt_redirect_number,
3201 .maxlen = sizeof(int), 3202 .maxlen = sizeof(int),
@@ -3203,7 +3204,6 @@ static ctl_table ipv4_route_table[] = {
3203 .proc_handler = proc_dointvec, 3204 .proc_handler = proc_dointvec,
3204 }, 3205 },
3205 { 3206 {
3206 .ctl_name = NET_IPV4_ROUTE_REDIRECT_SILENCE,
3207 .procname = "redirect_silence", 3207 .procname = "redirect_silence",
3208 .data = &ip_rt_redirect_silence, 3208 .data = &ip_rt_redirect_silence,
3209 .maxlen = sizeof(int), 3209 .maxlen = sizeof(int),
@@ -3211,7 +3211,6 @@ static ctl_table ipv4_route_table[] = {
3211 .proc_handler = proc_dointvec, 3211 .proc_handler = proc_dointvec,
3212 }, 3212 },
3213 { 3213 {
3214 .ctl_name = NET_IPV4_ROUTE_ERROR_COST,
3215 .procname = "error_cost", 3214 .procname = "error_cost",
3216 .data = &ip_rt_error_cost, 3215 .data = &ip_rt_error_cost,
3217 .maxlen = sizeof(int), 3216 .maxlen = sizeof(int),
@@ -3219,7 +3218,6 @@ static ctl_table ipv4_route_table[] = {
3219 .proc_handler = proc_dointvec, 3218 .proc_handler = proc_dointvec,
3220 }, 3219 },
3221 { 3220 {
3222 .ctl_name = NET_IPV4_ROUTE_ERROR_BURST,
3223 .procname = "error_burst", 3221 .procname = "error_burst",
3224 .data = &ip_rt_error_burst, 3222 .data = &ip_rt_error_burst,
3225 .maxlen = sizeof(int), 3223 .maxlen = sizeof(int),
@@ -3227,7 +3225,6 @@ static ctl_table ipv4_route_table[] = {
3227 .proc_handler = proc_dointvec, 3225 .proc_handler = proc_dointvec,
3228 }, 3226 },
3229 { 3227 {
3230 .ctl_name = NET_IPV4_ROUTE_GC_ELASTICITY,
3231 .procname = "gc_elasticity", 3228 .procname = "gc_elasticity",
3232 .data = &ip_rt_gc_elasticity, 3229 .data = &ip_rt_gc_elasticity,
3233 .maxlen = sizeof(int), 3230 .maxlen = sizeof(int),
@@ -3235,16 +3232,13 @@ static ctl_table ipv4_route_table[] = {
3235 .proc_handler = proc_dointvec, 3232 .proc_handler = proc_dointvec,
3236 }, 3233 },
3237 { 3234 {
3238 .ctl_name = NET_IPV4_ROUTE_MTU_EXPIRES,
3239 .procname = "mtu_expires", 3235 .procname = "mtu_expires",
3240 .data = &ip_rt_mtu_expires, 3236 .data = &ip_rt_mtu_expires,
3241 .maxlen = sizeof(int), 3237 .maxlen = sizeof(int),
3242 .mode = 0644, 3238 .mode = 0644,
3243 .proc_handler = proc_dointvec_jiffies, 3239 .proc_handler = proc_dointvec_jiffies,
3244 .strategy = sysctl_jiffies,
3245 }, 3240 },
3246 { 3241 {
3247 .ctl_name = NET_IPV4_ROUTE_MIN_PMTU,
3248 .procname = "min_pmtu", 3242 .procname = "min_pmtu",
3249 .data = &ip_rt_min_pmtu, 3243 .data = &ip_rt_min_pmtu,
3250 .maxlen = sizeof(int), 3244 .maxlen = sizeof(int),
@@ -3252,7 +3246,6 @@ static ctl_table ipv4_route_table[] = {
3252 .proc_handler = proc_dointvec, 3246 .proc_handler = proc_dointvec,
3253 }, 3247 },
3254 { 3248 {
3255 .ctl_name = NET_IPV4_ROUTE_MIN_ADVMSS,
3256 .procname = "min_adv_mss", 3249 .procname = "min_adv_mss",
3257 .data = &ip_rt_min_advmss, 3250 .data = &ip_rt_min_advmss,
3258 .maxlen = sizeof(int), 3251 .maxlen = sizeof(int),
@@ -3260,50 +3253,46 @@ static ctl_table ipv4_route_table[] = {
3260 .proc_handler = proc_dointvec, 3253 .proc_handler = proc_dointvec,
3261 }, 3254 },
3262 { 3255 {
3263 .ctl_name = NET_IPV4_ROUTE_SECRET_INTERVAL,
3264 .procname = "secret_interval", 3256 .procname = "secret_interval",
3265 .data = &ip_rt_secret_interval, 3257 .data = &ip_rt_secret_interval,
3266 .maxlen = sizeof(int), 3258 .maxlen = sizeof(int),
3267 .mode = 0644, 3259 .mode = 0644,
3268 .proc_handler = ipv4_sysctl_rt_secret_interval, 3260 .proc_handler = ipv4_sysctl_rt_secret_interval,
3269 .strategy = ipv4_sysctl_rt_secret_interval_strategy,
3270 }, 3261 },
3271 { .ctl_name = 0 } 3262 { }
3272}; 3263};
3273 3264
3274static struct ctl_table empty[1]; 3265static struct ctl_table empty[1];
3275 3266
3276static struct ctl_table ipv4_skeleton[] = 3267static struct ctl_table ipv4_skeleton[] =
3277{ 3268{
3278 { .procname = "route", .ctl_name = NET_IPV4_ROUTE, 3269 { .procname = "route",
3279 .mode = 0555, .child = ipv4_route_table}, 3270 .mode = 0555, .child = ipv4_route_table},
3280 { .procname = "neigh", .ctl_name = NET_IPV4_NEIGH, 3271 { .procname = "neigh",
3281 .mode = 0555, .child = empty}, 3272 .mode = 0555, .child = empty},
3282 { } 3273 { }
3283}; 3274};
3284 3275
3285static __net_initdata struct ctl_path ipv4_path[] = { 3276static __net_initdata struct ctl_path ipv4_path[] = {
3286 { .procname = "net", .ctl_name = CTL_NET, }, 3277 { .procname = "net", },
3287 { .procname = "ipv4", .ctl_name = NET_IPV4, }, 3278 { .procname = "ipv4", },
3288 { }, 3279 { },
3289}; 3280};
3290 3281
3291static struct ctl_table ipv4_route_flush_table[] = { 3282static struct ctl_table ipv4_route_flush_table[] = {
3292 { 3283 {
3293 .ctl_name = NET_IPV4_ROUTE_FLUSH,
3294 .procname = "flush", 3284 .procname = "flush",
3295 .maxlen = sizeof(int), 3285 .maxlen = sizeof(int),
3296 .mode = 0200, 3286 .mode = 0200,
3297 .proc_handler = ipv4_sysctl_rtcache_flush, 3287 .proc_handler = ipv4_sysctl_rtcache_flush,
3298 .strategy = ipv4_sysctl_rtcache_flush_strategy,
3299 }, 3288 },
3300 { .ctl_name = 0 }, 3289 { },
3301}; 3290};
3302 3291
3303static __net_initdata struct ctl_path ipv4_route_path[] = { 3292static __net_initdata struct ctl_path ipv4_route_path[] = {
3304 { .procname = "net", .ctl_name = CTL_NET, }, 3293 { .procname = "net", },
3305 { .procname = "ipv4", .ctl_name = NET_IPV4, }, 3294 { .procname = "ipv4", },
3306 { .procname = "route", .ctl_name = NET_IPV4_ROUTE, }, 3295 { .procname = "route", },
3307 { }, 3296 { },
3308}; 3297};
3309 3298
@@ -3312,7 +3301,7 @@ static __net_init int sysctl_route_net_init(struct net *net)
3312 struct ctl_table *tbl; 3301 struct ctl_table *tbl;
3313 3302
3314 tbl = ipv4_route_flush_table; 3303 tbl = ipv4_route_flush_table;
3315 if (net != &init_net) { 3304 if (!net_eq(net, &init_net)) {
3316 tbl = kmemdup(tbl, sizeof(ipv4_route_flush_table), GFP_KERNEL); 3305 tbl = kmemdup(tbl, sizeof(ipv4_route_flush_table), GFP_KERNEL);
3317 if (tbl == NULL) 3306 if (tbl == NULL)
3318 goto err_dup; 3307 goto err_dup;
@@ -3380,7 +3369,7 @@ static __net_initdata struct pernet_operations rt_secret_timer_ops = {
3380 3369
3381 3370
3382#ifdef CONFIG_NET_CLS_ROUTE 3371#ifdef CONFIG_NET_CLS_ROUTE
3383struct ip_rt_acct *ip_rt_acct __read_mostly; 3372struct ip_rt_acct __percpu *ip_rt_acct __read_mostly;
3384#endif /* CONFIG_NET_CLS_ROUTE */ 3373#endif /* CONFIG_NET_CLS_ROUTE */
3385 3374
3386static __initdata unsigned long rhash_entries; 3375static __initdata unsigned long rhash_entries;
diff --git a/net/ipv4/syncookies.c b/net/ipv4/syncookies.c
index a6e0e077ac33..5c24db4a3c91 100644
--- a/net/ipv4/syncookies.c
+++ b/net/ipv4/syncookies.c
@@ -253,6 +253,8 @@ EXPORT_SYMBOL(cookie_check_timestamp);
253struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb, 253struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb,
254 struct ip_options *opt) 254 struct ip_options *opt)
255{ 255{
256 struct tcp_options_received tcp_opt;
257 u8 *hash_location;
256 struct inet_request_sock *ireq; 258 struct inet_request_sock *ireq;
257 struct tcp_request_sock *treq; 259 struct tcp_request_sock *treq;
258 struct tcp_sock *tp = tcp_sk(sk); 260 struct tcp_sock *tp = tcp_sk(sk);
@@ -263,7 +265,6 @@ struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb,
263 int mss; 265 int mss;
264 struct rtable *rt; 266 struct rtable *rt;
265 __u8 rcv_wscale; 267 __u8 rcv_wscale;
266 struct tcp_options_received tcp_opt;
267 268
268 if (!sysctl_tcp_syncookies || !th->ack) 269 if (!sysctl_tcp_syncookies || !th->ack)
269 goto out; 270 goto out;
@@ -278,7 +279,7 @@ struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb,
278 279
279 /* check for timestamp cookie support */ 280 /* check for timestamp cookie support */
280 memset(&tcp_opt, 0, sizeof(tcp_opt)); 281 memset(&tcp_opt, 0, sizeof(tcp_opt));
281 tcp_parse_options(skb, &tcp_opt, 0); 282 tcp_parse_options(skb, &tcp_opt, &hash_location, 0);
282 283
283 if (tcp_opt.saw_tstamp) 284 if (tcp_opt.saw_tstamp)
284 cookie_check_timestamp(&tcp_opt); 285 cookie_check_timestamp(&tcp_opt);
@@ -333,7 +334,8 @@ struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb,
333 * no easy way to do this. 334 * no easy way to do this.
334 */ 335 */
335 { 336 {
336 struct flowi fl = { .nl_u = { .ip4_u = 337 struct flowi fl = { .mark = sk->sk_mark,
338 .nl_u = { .ip4_u =
337 { .daddr = ((opt && opt->srr) ? 339 { .daddr = ((opt && opt->srr) ?
338 opt->faddr : 340 opt->faddr :
339 ireq->rmt_addr), 341 ireq->rmt_addr),
@@ -356,7 +358,8 @@ struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb,
356 358
357 tcp_select_initial_window(tcp_full_space(sk), req->mss, 359 tcp_select_initial_window(tcp_full_space(sk), req->mss,
358 &req->rcv_wnd, &req->window_clamp, 360 &req->rcv_wnd, &req->window_clamp,
359 ireq->wscale_ok, &rcv_wscale); 361 ireq->wscale_ok, &rcv_wscale,
362 dst_metric(&rt->u.dst, RTAX_INITRWND));
360 363
361 ireq->rcv_wscale = rcv_wscale; 364 ireq->rcv_wscale = rcv_wscale;
362 365
diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
index 2dcf04d9b005..1cd5c15174b8 100644
--- a/net/ipv4/sysctl_net_ipv4.c
+++ b/net/ipv4/sysctl_net_ipv4.c
@@ -12,6 +12,7 @@
12#include <linux/inetdevice.h> 12#include <linux/inetdevice.h>
13#include <linux/seqlock.h> 13#include <linux/seqlock.h>
14#include <linux/init.h> 14#include <linux/init.h>
15#include <linux/slab.h>
15#include <net/snmp.h> 16#include <net/snmp.h>
16#include <net/icmp.h> 17#include <net/icmp.h>
17#include <net/ip.h> 18#include <net/ip.h>
@@ -63,34 +64,6 @@ static int ipv4_local_port_range(ctl_table *table, int write,
63 return ret; 64 return ret;
64} 65}
65 66
66/* Validate changes from sysctl interface. */
67static int ipv4_sysctl_local_port_range(ctl_table *table,
68 void __user *oldval,
69 size_t __user *oldlenp,
70 void __user *newval, size_t newlen)
71{
72 int ret;
73 int range[2];
74 ctl_table tmp = {
75 .data = &range,
76 .maxlen = sizeof(range),
77 .mode = table->mode,
78 .extra1 = &ip_local_port_range_min,
79 .extra2 = &ip_local_port_range_max,
80 };
81
82 inet_get_local_port_range(range, range + 1);
83 ret = sysctl_intvec(&tmp, oldval, oldlenp, newval, newlen);
84 if (ret == 0 && newval && newlen) {
85 if (range[1] < range[0])
86 ret = -EINVAL;
87 else
88 set_local_port_range(range);
89 }
90 return ret;
91}
92
93
94static int proc_tcp_congestion_control(ctl_table *ctl, int write, 67static int proc_tcp_congestion_control(ctl_table *ctl, int write,
95 void __user *buffer, size_t *lenp, loff_t *ppos) 68 void __user *buffer, size_t *lenp, loff_t *ppos)
96{ 69{
@@ -109,25 +82,6 @@ static int proc_tcp_congestion_control(ctl_table *ctl, int write,
109 return ret; 82 return ret;
110} 83}
111 84
112static int sysctl_tcp_congestion_control(ctl_table *table,
113 void __user *oldval,
114 size_t __user *oldlenp,
115 void __user *newval, size_t newlen)
116{
117 char val[TCP_CA_NAME_MAX];
118 ctl_table tbl = {
119 .data = val,
120 .maxlen = TCP_CA_NAME_MAX,
121 };
122 int ret;
123
124 tcp_get_default_congestion_control(val);
125 ret = sysctl_string(&tbl, oldval, oldlenp, newval, newlen);
126 if (ret == 1 && newval && newlen)
127 ret = tcp_set_default_congestion_control(val);
128 return ret;
129}
130
131static int proc_tcp_available_congestion_control(ctl_table *ctl, 85static int proc_tcp_available_congestion_control(ctl_table *ctl,
132 int write, 86 int write,
133 void __user *buffer, size_t *lenp, 87 void __user *buffer, size_t *lenp,
@@ -165,32 +119,8 @@ static int proc_allowed_congestion_control(ctl_table *ctl,
165 return ret; 119 return ret;
166} 120}
167 121
168static int strategy_allowed_congestion_control(ctl_table *table,
169 void __user *oldval,
170 size_t __user *oldlenp,
171 void __user *newval,
172 size_t newlen)
173{
174 ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
175 int ret;
176
177 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
178 if (!tbl.data)
179 return -ENOMEM;
180
181 tcp_get_available_congestion_control(tbl.data, tbl.maxlen);
182 ret = sysctl_string(&tbl, oldval, oldlenp, newval, newlen);
183 if (ret == 1 && newval && newlen)
184 ret = tcp_set_allowed_congestion_control(tbl.data);
185 kfree(tbl.data);
186
187 return ret;
188
189}
190
191static struct ctl_table ipv4_table[] = { 122static struct ctl_table ipv4_table[] = {
192 { 123 {
193 .ctl_name = NET_IPV4_TCP_TIMESTAMPS,
194 .procname = "tcp_timestamps", 124 .procname = "tcp_timestamps",
195 .data = &sysctl_tcp_timestamps, 125 .data = &sysctl_tcp_timestamps,
196 .maxlen = sizeof(int), 126 .maxlen = sizeof(int),
@@ -198,7 +128,6 @@ static struct ctl_table ipv4_table[] = {
198 .proc_handler = proc_dointvec 128 .proc_handler = proc_dointvec
199 }, 129 },
200 { 130 {
201 .ctl_name = NET_IPV4_TCP_WINDOW_SCALING,
202 .procname = "tcp_window_scaling", 131 .procname = "tcp_window_scaling",
203 .data = &sysctl_tcp_window_scaling, 132 .data = &sysctl_tcp_window_scaling,
204 .maxlen = sizeof(int), 133 .maxlen = sizeof(int),
@@ -206,7 +135,6 @@ static struct ctl_table ipv4_table[] = {
206 .proc_handler = proc_dointvec 135 .proc_handler = proc_dointvec
207 }, 136 },
208 { 137 {
209 .ctl_name = NET_IPV4_TCP_SACK,
210 .procname = "tcp_sack", 138 .procname = "tcp_sack",
211 .data = &sysctl_tcp_sack, 139 .data = &sysctl_tcp_sack,
212 .maxlen = sizeof(int), 140 .maxlen = sizeof(int),
@@ -214,7 +142,6 @@ static struct ctl_table ipv4_table[] = {
214 .proc_handler = proc_dointvec 142 .proc_handler = proc_dointvec
215 }, 143 },
216 { 144 {
217 .ctl_name = NET_IPV4_TCP_RETRANS_COLLAPSE,
218 .procname = "tcp_retrans_collapse", 145 .procname = "tcp_retrans_collapse",
219 .data = &sysctl_tcp_retrans_collapse, 146 .data = &sysctl_tcp_retrans_collapse,
220 .maxlen = sizeof(int), 147 .maxlen = sizeof(int),
@@ -222,17 +149,14 @@ static struct ctl_table ipv4_table[] = {
222 .proc_handler = proc_dointvec 149 .proc_handler = proc_dointvec
223 }, 150 },
224 { 151 {
225 .ctl_name = NET_IPV4_DEFAULT_TTL,
226 .procname = "ip_default_ttl", 152 .procname = "ip_default_ttl",
227 .data = &sysctl_ip_default_ttl, 153 .data = &sysctl_ip_default_ttl,
228 .maxlen = sizeof(int), 154 .maxlen = sizeof(int),
229 .mode = 0644, 155 .mode = 0644,
230 .proc_handler = ipv4_doint_and_flush, 156 .proc_handler = ipv4_doint_and_flush,
231 .strategy = ipv4_doint_and_flush_strategy,
232 .extra2 = &init_net, 157 .extra2 = &init_net,
233 }, 158 },
234 { 159 {
235 .ctl_name = NET_IPV4_NO_PMTU_DISC,
236 .procname = "ip_no_pmtu_disc", 160 .procname = "ip_no_pmtu_disc",
237 .data = &ipv4_config.no_pmtu_disc, 161 .data = &ipv4_config.no_pmtu_disc,
238 .maxlen = sizeof(int), 162 .maxlen = sizeof(int),
@@ -240,7 +164,6 @@ static struct ctl_table ipv4_table[] = {
240 .proc_handler = proc_dointvec 164 .proc_handler = proc_dointvec
241 }, 165 },
242 { 166 {
243 .ctl_name = NET_IPV4_NONLOCAL_BIND,
244 .procname = "ip_nonlocal_bind", 167 .procname = "ip_nonlocal_bind",
245 .data = &sysctl_ip_nonlocal_bind, 168 .data = &sysctl_ip_nonlocal_bind,
246 .maxlen = sizeof(int), 169 .maxlen = sizeof(int),
@@ -248,7 +171,6 @@ static struct ctl_table ipv4_table[] = {
248 .proc_handler = proc_dointvec 171 .proc_handler = proc_dointvec
249 }, 172 },
250 { 173 {
251 .ctl_name = NET_IPV4_TCP_SYN_RETRIES,
252 .procname = "tcp_syn_retries", 174 .procname = "tcp_syn_retries",
253 .data = &sysctl_tcp_syn_retries, 175 .data = &sysctl_tcp_syn_retries,
254 .maxlen = sizeof(int), 176 .maxlen = sizeof(int),
@@ -256,7 +178,6 @@ static struct ctl_table ipv4_table[] = {
256 .proc_handler = proc_dointvec 178 .proc_handler = proc_dointvec
257 }, 179 },
258 { 180 {
259 .ctl_name = NET_TCP_SYNACK_RETRIES,
260 .procname = "tcp_synack_retries", 181 .procname = "tcp_synack_retries",
261 .data = &sysctl_tcp_synack_retries, 182 .data = &sysctl_tcp_synack_retries,
262 .maxlen = sizeof(int), 183 .maxlen = sizeof(int),
@@ -264,7 +185,6 @@ static struct ctl_table ipv4_table[] = {
264 .proc_handler = proc_dointvec 185 .proc_handler = proc_dointvec
265 }, 186 },
266 { 187 {
267 .ctl_name = NET_TCP_MAX_ORPHANS,
268 .procname = "tcp_max_orphans", 188 .procname = "tcp_max_orphans",
269 .data = &sysctl_tcp_max_orphans, 189 .data = &sysctl_tcp_max_orphans,
270 .maxlen = sizeof(int), 190 .maxlen = sizeof(int),
@@ -272,7 +192,6 @@ static struct ctl_table ipv4_table[] = {
272 .proc_handler = proc_dointvec 192 .proc_handler = proc_dointvec
273 }, 193 },
274 { 194 {
275 .ctl_name = NET_TCP_MAX_TW_BUCKETS,
276 .procname = "tcp_max_tw_buckets", 195 .procname = "tcp_max_tw_buckets",
277 .data = &tcp_death_row.sysctl_max_tw_buckets, 196 .data = &tcp_death_row.sysctl_max_tw_buckets,
278 .maxlen = sizeof(int), 197 .maxlen = sizeof(int),
@@ -280,7 +199,6 @@ static struct ctl_table ipv4_table[] = {
280 .proc_handler = proc_dointvec 199 .proc_handler = proc_dointvec
281 }, 200 },
282 { 201 {
283 .ctl_name = NET_IPV4_DYNADDR,
284 .procname = "ip_dynaddr", 202 .procname = "ip_dynaddr",
285 .data = &sysctl_ip_dynaddr, 203 .data = &sysctl_ip_dynaddr,
286 .maxlen = sizeof(int), 204 .maxlen = sizeof(int),
@@ -288,16 +206,13 @@ static struct ctl_table ipv4_table[] = {
288 .proc_handler = proc_dointvec 206 .proc_handler = proc_dointvec
289 }, 207 },
290 { 208 {
291 .ctl_name = NET_IPV4_TCP_KEEPALIVE_TIME,
292 .procname = "tcp_keepalive_time", 209 .procname = "tcp_keepalive_time",
293 .data = &sysctl_tcp_keepalive_time, 210 .data = &sysctl_tcp_keepalive_time,
294 .maxlen = sizeof(int), 211 .maxlen = sizeof(int),
295 .mode = 0644, 212 .mode = 0644,
296 .proc_handler = proc_dointvec_jiffies, 213 .proc_handler = proc_dointvec_jiffies,
297 .strategy = sysctl_jiffies
298 }, 214 },
299 { 215 {
300 .ctl_name = NET_IPV4_TCP_KEEPALIVE_PROBES,
301 .procname = "tcp_keepalive_probes", 216 .procname = "tcp_keepalive_probes",
302 .data = &sysctl_tcp_keepalive_probes, 217 .data = &sysctl_tcp_keepalive_probes,
303 .maxlen = sizeof(int), 218 .maxlen = sizeof(int),
@@ -305,26 +220,21 @@ static struct ctl_table ipv4_table[] = {
305 .proc_handler = proc_dointvec 220 .proc_handler = proc_dointvec
306 }, 221 },
307 { 222 {
308 .ctl_name = NET_IPV4_TCP_KEEPALIVE_INTVL,
309 .procname = "tcp_keepalive_intvl", 223 .procname = "tcp_keepalive_intvl",
310 .data = &sysctl_tcp_keepalive_intvl, 224 .data = &sysctl_tcp_keepalive_intvl,
311 .maxlen = sizeof(int), 225 .maxlen = sizeof(int),
312 .mode = 0644, 226 .mode = 0644,
313 .proc_handler = proc_dointvec_jiffies, 227 .proc_handler = proc_dointvec_jiffies,
314 .strategy = sysctl_jiffies
315 }, 228 },
316 { 229 {
317 .ctl_name = NET_IPV4_TCP_RETRIES1,
318 .procname = "tcp_retries1", 230 .procname = "tcp_retries1",
319 .data = &sysctl_tcp_retries1, 231 .data = &sysctl_tcp_retries1,
320 .maxlen = sizeof(int), 232 .maxlen = sizeof(int),
321 .mode = 0644, 233 .mode = 0644,
322 .proc_handler = proc_dointvec_minmax, 234 .proc_handler = proc_dointvec_minmax,
323 .strategy = sysctl_intvec,
324 .extra2 = &tcp_retr1_max 235 .extra2 = &tcp_retr1_max
325 }, 236 },
326 { 237 {
327 .ctl_name = NET_IPV4_TCP_RETRIES2,
328 .procname = "tcp_retries2", 238 .procname = "tcp_retries2",
329 .data = &sysctl_tcp_retries2, 239 .data = &sysctl_tcp_retries2,
330 .maxlen = sizeof(int), 240 .maxlen = sizeof(int),
@@ -332,17 +242,14 @@ static struct ctl_table ipv4_table[] = {
332 .proc_handler = proc_dointvec 242 .proc_handler = proc_dointvec
333 }, 243 },
334 { 244 {
335 .ctl_name = NET_IPV4_TCP_FIN_TIMEOUT,
336 .procname = "tcp_fin_timeout", 245 .procname = "tcp_fin_timeout",
337 .data = &sysctl_tcp_fin_timeout, 246 .data = &sysctl_tcp_fin_timeout,
338 .maxlen = sizeof(int), 247 .maxlen = sizeof(int),
339 .mode = 0644, 248 .mode = 0644,
340 .proc_handler = proc_dointvec_jiffies, 249 .proc_handler = proc_dointvec_jiffies,
341 .strategy = sysctl_jiffies
342 }, 250 },
343#ifdef CONFIG_SYN_COOKIES 251#ifdef CONFIG_SYN_COOKIES
344 { 252 {
345 .ctl_name = NET_TCP_SYNCOOKIES,
346 .procname = "tcp_syncookies", 253 .procname = "tcp_syncookies",
347 .data = &sysctl_tcp_syncookies, 254 .data = &sysctl_tcp_syncookies,
348 .maxlen = sizeof(int), 255 .maxlen = sizeof(int),
@@ -351,7 +258,6 @@ static struct ctl_table ipv4_table[] = {
351 }, 258 },
352#endif 259#endif
353 { 260 {
354 .ctl_name = NET_TCP_TW_RECYCLE,
355 .procname = "tcp_tw_recycle", 261 .procname = "tcp_tw_recycle",
356 .data = &tcp_death_row.sysctl_tw_recycle, 262 .data = &tcp_death_row.sysctl_tw_recycle,
357 .maxlen = sizeof(int), 263 .maxlen = sizeof(int),
@@ -359,7 +265,6 @@ static struct ctl_table ipv4_table[] = {
359 .proc_handler = proc_dointvec 265 .proc_handler = proc_dointvec
360 }, 266 },
361 { 267 {
362 .ctl_name = NET_TCP_ABORT_ON_OVERFLOW,
363 .procname = "tcp_abort_on_overflow", 268 .procname = "tcp_abort_on_overflow",
364 .data = &sysctl_tcp_abort_on_overflow, 269 .data = &sysctl_tcp_abort_on_overflow,
365 .maxlen = sizeof(int), 270 .maxlen = sizeof(int),
@@ -367,7 +272,6 @@ static struct ctl_table ipv4_table[] = {
367 .proc_handler = proc_dointvec 272 .proc_handler = proc_dointvec
368 }, 273 },
369 { 274 {
370 .ctl_name = NET_TCP_STDURG,
371 .procname = "tcp_stdurg", 275 .procname = "tcp_stdurg",
372 .data = &sysctl_tcp_stdurg, 276 .data = &sysctl_tcp_stdurg,
373 .maxlen = sizeof(int), 277 .maxlen = sizeof(int),
@@ -375,7 +279,6 @@ static struct ctl_table ipv4_table[] = {
375 .proc_handler = proc_dointvec 279 .proc_handler = proc_dointvec
376 }, 280 },
377 { 281 {
378 .ctl_name = NET_TCP_RFC1337,
379 .procname = "tcp_rfc1337", 282 .procname = "tcp_rfc1337",
380 .data = &sysctl_tcp_rfc1337, 283 .data = &sysctl_tcp_rfc1337,
381 .maxlen = sizeof(int), 284 .maxlen = sizeof(int),
@@ -383,7 +286,6 @@ static struct ctl_table ipv4_table[] = {
383 .proc_handler = proc_dointvec 286 .proc_handler = proc_dointvec
384 }, 287 },
385 { 288 {
386 .ctl_name = NET_TCP_MAX_SYN_BACKLOG,
387 .procname = "tcp_max_syn_backlog", 289 .procname = "tcp_max_syn_backlog",
388 .data = &sysctl_max_syn_backlog, 290 .data = &sysctl_max_syn_backlog,
389 .maxlen = sizeof(int), 291 .maxlen = sizeof(int),
@@ -391,17 +293,14 @@ static struct ctl_table ipv4_table[] = {
391 .proc_handler = proc_dointvec 293 .proc_handler = proc_dointvec
392 }, 294 },
393 { 295 {
394 .ctl_name = NET_IPV4_LOCAL_PORT_RANGE,
395 .procname = "ip_local_port_range", 296 .procname = "ip_local_port_range",
396 .data = &sysctl_local_ports.range, 297 .data = &sysctl_local_ports.range,
397 .maxlen = sizeof(sysctl_local_ports.range), 298 .maxlen = sizeof(sysctl_local_ports.range),
398 .mode = 0644, 299 .mode = 0644,
399 .proc_handler = ipv4_local_port_range, 300 .proc_handler = ipv4_local_port_range,
400 .strategy = ipv4_sysctl_local_port_range,
401 }, 301 },
402#ifdef CONFIG_IP_MULTICAST 302#ifdef CONFIG_IP_MULTICAST
403 { 303 {
404 .ctl_name = NET_IPV4_IGMP_MAX_MEMBERSHIPS,
405 .procname = "igmp_max_memberships", 304 .procname = "igmp_max_memberships",
406 .data = &sysctl_igmp_max_memberships, 305 .data = &sysctl_igmp_max_memberships,
407 .maxlen = sizeof(int), 306 .maxlen = sizeof(int),
@@ -411,7 +310,6 @@ static struct ctl_table ipv4_table[] = {
411 310
412#endif 311#endif
413 { 312 {
414 .ctl_name = NET_IPV4_IGMP_MAX_MSF,
415 .procname = "igmp_max_msf", 313 .procname = "igmp_max_msf",
416 .data = &sysctl_igmp_max_msf, 314 .data = &sysctl_igmp_max_msf,
417 .maxlen = sizeof(int), 315 .maxlen = sizeof(int),
@@ -419,7 +317,6 @@ static struct ctl_table ipv4_table[] = {
419 .proc_handler = proc_dointvec 317 .proc_handler = proc_dointvec
420 }, 318 },
421 { 319 {
422 .ctl_name = NET_IPV4_INET_PEER_THRESHOLD,
423 .procname = "inet_peer_threshold", 320 .procname = "inet_peer_threshold",
424 .data = &inet_peer_threshold, 321 .data = &inet_peer_threshold,
425 .maxlen = sizeof(int), 322 .maxlen = sizeof(int),
@@ -427,43 +324,34 @@ static struct ctl_table ipv4_table[] = {
427 .proc_handler = proc_dointvec 324 .proc_handler = proc_dointvec
428 }, 325 },
429 { 326 {
430 .ctl_name = NET_IPV4_INET_PEER_MINTTL,
431 .procname = "inet_peer_minttl", 327 .procname = "inet_peer_minttl",
432 .data = &inet_peer_minttl, 328 .data = &inet_peer_minttl,
433 .maxlen = sizeof(int), 329 .maxlen = sizeof(int),
434 .mode = 0644, 330 .mode = 0644,
435 .proc_handler = proc_dointvec_jiffies, 331 .proc_handler = proc_dointvec_jiffies,
436 .strategy = sysctl_jiffies
437 }, 332 },
438 { 333 {
439 .ctl_name = NET_IPV4_INET_PEER_MAXTTL,
440 .procname = "inet_peer_maxttl", 334 .procname = "inet_peer_maxttl",
441 .data = &inet_peer_maxttl, 335 .data = &inet_peer_maxttl,
442 .maxlen = sizeof(int), 336 .maxlen = sizeof(int),
443 .mode = 0644, 337 .mode = 0644,
444 .proc_handler = proc_dointvec_jiffies, 338 .proc_handler = proc_dointvec_jiffies,
445 .strategy = sysctl_jiffies
446 }, 339 },
447 { 340 {
448 .ctl_name = NET_IPV4_INET_PEER_GC_MINTIME,
449 .procname = "inet_peer_gc_mintime", 341 .procname = "inet_peer_gc_mintime",
450 .data = &inet_peer_gc_mintime, 342 .data = &inet_peer_gc_mintime,
451 .maxlen = sizeof(int), 343 .maxlen = sizeof(int),
452 .mode = 0644, 344 .mode = 0644,
453 .proc_handler = proc_dointvec_jiffies, 345 .proc_handler = proc_dointvec_jiffies,
454 .strategy = sysctl_jiffies
455 }, 346 },
456 { 347 {
457 .ctl_name = NET_IPV4_INET_PEER_GC_MAXTIME,
458 .procname = "inet_peer_gc_maxtime", 348 .procname = "inet_peer_gc_maxtime",
459 .data = &inet_peer_gc_maxtime, 349 .data = &inet_peer_gc_maxtime,
460 .maxlen = sizeof(int), 350 .maxlen = sizeof(int),
461 .mode = 0644, 351 .mode = 0644,
462 .proc_handler = proc_dointvec_jiffies, 352 .proc_handler = proc_dointvec_jiffies,
463 .strategy = sysctl_jiffies
464 }, 353 },
465 { 354 {
466 .ctl_name = NET_TCP_ORPHAN_RETRIES,
467 .procname = "tcp_orphan_retries", 355 .procname = "tcp_orphan_retries",
468 .data = &sysctl_tcp_orphan_retries, 356 .data = &sysctl_tcp_orphan_retries,
469 .maxlen = sizeof(int), 357 .maxlen = sizeof(int),
@@ -471,7 +359,6 @@ static struct ctl_table ipv4_table[] = {
471 .proc_handler = proc_dointvec 359 .proc_handler = proc_dointvec
472 }, 360 },
473 { 361 {
474 .ctl_name = NET_TCP_FACK,
475 .procname = "tcp_fack", 362 .procname = "tcp_fack",
476 .data = &sysctl_tcp_fack, 363 .data = &sysctl_tcp_fack,
477 .maxlen = sizeof(int), 364 .maxlen = sizeof(int),
@@ -479,7 +366,6 @@ static struct ctl_table ipv4_table[] = {
479 .proc_handler = proc_dointvec 366 .proc_handler = proc_dointvec
480 }, 367 },
481 { 368 {
482 .ctl_name = NET_TCP_REORDERING,
483 .procname = "tcp_reordering", 369 .procname = "tcp_reordering",
484 .data = &sysctl_tcp_reordering, 370 .data = &sysctl_tcp_reordering,
485 .maxlen = sizeof(int), 371 .maxlen = sizeof(int),
@@ -487,7 +373,6 @@ static struct ctl_table ipv4_table[] = {
487 .proc_handler = proc_dointvec 373 .proc_handler = proc_dointvec
488 }, 374 },
489 { 375 {
490 .ctl_name = NET_TCP_ECN,
491 .procname = "tcp_ecn", 376 .procname = "tcp_ecn",
492 .data = &sysctl_tcp_ecn, 377 .data = &sysctl_tcp_ecn,
493 .maxlen = sizeof(int), 378 .maxlen = sizeof(int),
@@ -495,7 +380,6 @@ static struct ctl_table ipv4_table[] = {
495 .proc_handler = proc_dointvec 380 .proc_handler = proc_dointvec
496 }, 381 },
497 { 382 {
498 .ctl_name = NET_TCP_DSACK,
499 .procname = "tcp_dsack", 383 .procname = "tcp_dsack",
500 .data = &sysctl_tcp_dsack, 384 .data = &sysctl_tcp_dsack,
501 .maxlen = sizeof(int), 385 .maxlen = sizeof(int),
@@ -503,7 +387,6 @@ static struct ctl_table ipv4_table[] = {
503 .proc_handler = proc_dointvec 387 .proc_handler = proc_dointvec
504 }, 388 },
505 { 389 {
506 .ctl_name = NET_TCP_MEM,
507 .procname = "tcp_mem", 390 .procname = "tcp_mem",
508 .data = &sysctl_tcp_mem, 391 .data = &sysctl_tcp_mem,
509 .maxlen = sizeof(sysctl_tcp_mem), 392 .maxlen = sizeof(sysctl_tcp_mem),
@@ -511,7 +394,6 @@ static struct ctl_table ipv4_table[] = {
511 .proc_handler = proc_dointvec 394 .proc_handler = proc_dointvec
512 }, 395 },
513 { 396 {
514 .ctl_name = NET_TCP_WMEM,
515 .procname = "tcp_wmem", 397 .procname = "tcp_wmem",
516 .data = &sysctl_tcp_wmem, 398 .data = &sysctl_tcp_wmem,
517 .maxlen = sizeof(sysctl_tcp_wmem), 399 .maxlen = sizeof(sysctl_tcp_wmem),
@@ -519,7 +401,6 @@ static struct ctl_table ipv4_table[] = {
519 .proc_handler = proc_dointvec 401 .proc_handler = proc_dointvec
520 }, 402 },
521 { 403 {
522 .ctl_name = NET_TCP_RMEM,
523 .procname = "tcp_rmem", 404 .procname = "tcp_rmem",
524 .data = &sysctl_tcp_rmem, 405 .data = &sysctl_tcp_rmem,
525 .maxlen = sizeof(sysctl_tcp_rmem), 406 .maxlen = sizeof(sysctl_tcp_rmem),
@@ -527,7 +408,6 @@ static struct ctl_table ipv4_table[] = {
527 .proc_handler = proc_dointvec 408 .proc_handler = proc_dointvec
528 }, 409 },
529 { 410 {
530 .ctl_name = NET_TCP_APP_WIN,
531 .procname = "tcp_app_win", 411 .procname = "tcp_app_win",
532 .data = &sysctl_tcp_app_win, 412 .data = &sysctl_tcp_app_win,
533 .maxlen = sizeof(int), 413 .maxlen = sizeof(int),
@@ -535,7 +415,6 @@ static struct ctl_table ipv4_table[] = {
535 .proc_handler = proc_dointvec 415 .proc_handler = proc_dointvec
536 }, 416 },
537 { 417 {
538 .ctl_name = NET_TCP_ADV_WIN_SCALE,
539 .procname = "tcp_adv_win_scale", 418 .procname = "tcp_adv_win_scale",
540 .data = &sysctl_tcp_adv_win_scale, 419 .data = &sysctl_tcp_adv_win_scale,
541 .maxlen = sizeof(int), 420 .maxlen = sizeof(int),
@@ -543,7 +422,6 @@ static struct ctl_table ipv4_table[] = {
543 .proc_handler = proc_dointvec 422 .proc_handler = proc_dointvec
544 }, 423 },
545 { 424 {
546 .ctl_name = NET_TCP_TW_REUSE,
547 .procname = "tcp_tw_reuse", 425 .procname = "tcp_tw_reuse",
548 .data = &sysctl_tcp_tw_reuse, 426 .data = &sysctl_tcp_tw_reuse,
549 .maxlen = sizeof(int), 427 .maxlen = sizeof(int),
@@ -551,7 +429,6 @@ static struct ctl_table ipv4_table[] = {
551 .proc_handler = proc_dointvec 429 .proc_handler = proc_dointvec
552 }, 430 },
553 { 431 {
554 .ctl_name = NET_TCP_FRTO,
555 .procname = "tcp_frto", 432 .procname = "tcp_frto",
556 .data = &sysctl_tcp_frto, 433 .data = &sysctl_tcp_frto,
557 .maxlen = sizeof(int), 434 .maxlen = sizeof(int),
@@ -559,7 +436,6 @@ static struct ctl_table ipv4_table[] = {
559 .proc_handler = proc_dointvec 436 .proc_handler = proc_dointvec
560 }, 437 },
561 { 438 {
562 .ctl_name = NET_TCP_FRTO_RESPONSE,
563 .procname = "tcp_frto_response", 439 .procname = "tcp_frto_response",
564 .data = &sysctl_tcp_frto_response, 440 .data = &sysctl_tcp_frto_response,
565 .maxlen = sizeof(int), 441 .maxlen = sizeof(int),
@@ -567,7 +443,6 @@ static struct ctl_table ipv4_table[] = {
567 .proc_handler = proc_dointvec 443 .proc_handler = proc_dointvec
568 }, 444 },
569 { 445 {
570 .ctl_name = NET_TCP_LOW_LATENCY,
571 .procname = "tcp_low_latency", 446 .procname = "tcp_low_latency",
572 .data = &sysctl_tcp_low_latency, 447 .data = &sysctl_tcp_low_latency,
573 .maxlen = sizeof(int), 448 .maxlen = sizeof(int),
@@ -575,7 +450,6 @@ static struct ctl_table ipv4_table[] = {
575 .proc_handler = proc_dointvec 450 .proc_handler = proc_dointvec
576 }, 451 },
577 { 452 {
578 .ctl_name = NET_TCP_NO_METRICS_SAVE,
579 .procname = "tcp_no_metrics_save", 453 .procname = "tcp_no_metrics_save",
580 .data = &sysctl_tcp_nometrics_save, 454 .data = &sysctl_tcp_nometrics_save,
581 .maxlen = sizeof(int), 455 .maxlen = sizeof(int),
@@ -583,7 +457,6 @@ static struct ctl_table ipv4_table[] = {
583 .proc_handler = proc_dointvec, 457 .proc_handler = proc_dointvec,
584 }, 458 },
585 { 459 {
586 .ctl_name = NET_TCP_MODERATE_RCVBUF,
587 .procname = "tcp_moderate_rcvbuf", 460 .procname = "tcp_moderate_rcvbuf",
588 .data = &sysctl_tcp_moderate_rcvbuf, 461 .data = &sysctl_tcp_moderate_rcvbuf,
589 .maxlen = sizeof(int), 462 .maxlen = sizeof(int),
@@ -591,7 +464,6 @@ static struct ctl_table ipv4_table[] = {
591 .proc_handler = proc_dointvec, 464 .proc_handler = proc_dointvec,
592 }, 465 },
593 { 466 {
594 .ctl_name = NET_TCP_TSO_WIN_DIVISOR,
595 .procname = "tcp_tso_win_divisor", 467 .procname = "tcp_tso_win_divisor",
596 .data = &sysctl_tcp_tso_win_divisor, 468 .data = &sysctl_tcp_tso_win_divisor,
597 .maxlen = sizeof(int), 469 .maxlen = sizeof(int),
@@ -599,15 +471,12 @@ static struct ctl_table ipv4_table[] = {
599 .proc_handler = proc_dointvec, 471 .proc_handler = proc_dointvec,
600 }, 472 },
601 { 473 {
602 .ctl_name = NET_TCP_CONG_CONTROL,
603 .procname = "tcp_congestion_control", 474 .procname = "tcp_congestion_control",
604 .mode = 0644, 475 .mode = 0644,
605 .maxlen = TCP_CA_NAME_MAX, 476 .maxlen = TCP_CA_NAME_MAX,
606 .proc_handler = proc_tcp_congestion_control, 477 .proc_handler = proc_tcp_congestion_control,
607 .strategy = sysctl_tcp_congestion_control,
608 }, 478 },
609 { 479 {
610 .ctl_name = NET_TCP_ABC,
611 .procname = "tcp_abc", 480 .procname = "tcp_abc",
612 .data = &sysctl_tcp_abc, 481 .data = &sysctl_tcp_abc,
613 .maxlen = sizeof(int), 482 .maxlen = sizeof(int),
@@ -615,7 +484,6 @@ static struct ctl_table ipv4_table[] = {
615 .proc_handler = proc_dointvec, 484 .proc_handler = proc_dointvec,
616 }, 485 },
617 { 486 {
618 .ctl_name = NET_TCP_MTU_PROBING,
619 .procname = "tcp_mtu_probing", 487 .procname = "tcp_mtu_probing",
620 .data = &sysctl_tcp_mtu_probing, 488 .data = &sysctl_tcp_mtu_probing,
621 .maxlen = sizeof(int), 489 .maxlen = sizeof(int),
@@ -623,7 +491,6 @@ static struct ctl_table ipv4_table[] = {
623 .proc_handler = proc_dointvec, 491 .proc_handler = proc_dointvec,
624 }, 492 },
625 { 493 {
626 .ctl_name = NET_TCP_BASE_MSS,
627 .procname = "tcp_base_mss", 494 .procname = "tcp_base_mss",
628 .data = &sysctl_tcp_base_mss, 495 .data = &sysctl_tcp_base_mss,
629 .maxlen = sizeof(int), 496 .maxlen = sizeof(int),
@@ -631,7 +498,6 @@ static struct ctl_table ipv4_table[] = {
631 .proc_handler = proc_dointvec, 498 .proc_handler = proc_dointvec,
632 }, 499 },
633 { 500 {
634 .ctl_name = NET_IPV4_TCP_WORKAROUND_SIGNED_WINDOWS,
635 .procname = "tcp_workaround_signed_windows", 501 .procname = "tcp_workaround_signed_windows",
636 .data = &sysctl_tcp_workaround_signed_windows, 502 .data = &sysctl_tcp_workaround_signed_windows,
637 .maxlen = sizeof(int), 503 .maxlen = sizeof(int),
@@ -640,7 +506,6 @@ static struct ctl_table ipv4_table[] = {
640 }, 506 },
641#ifdef CONFIG_NET_DMA 507#ifdef CONFIG_NET_DMA
642 { 508 {
643 .ctl_name = NET_TCP_DMA_COPYBREAK,
644 .procname = "tcp_dma_copybreak", 509 .procname = "tcp_dma_copybreak",
645 .data = &sysctl_tcp_dma_copybreak, 510 .data = &sysctl_tcp_dma_copybreak,
646 .maxlen = sizeof(int), 511 .maxlen = sizeof(int),
@@ -649,7 +514,6 @@ static struct ctl_table ipv4_table[] = {
649 }, 514 },
650#endif 515#endif
651 { 516 {
652 .ctl_name = NET_TCP_SLOW_START_AFTER_IDLE,
653 .procname = "tcp_slow_start_after_idle", 517 .procname = "tcp_slow_start_after_idle",
654 .data = &sysctl_tcp_slow_start_after_idle, 518 .data = &sysctl_tcp_slow_start_after_idle,
655 .maxlen = sizeof(int), 519 .maxlen = sizeof(int),
@@ -658,7 +522,6 @@ static struct ctl_table ipv4_table[] = {
658 }, 522 },
659#ifdef CONFIG_NETLABEL 523#ifdef CONFIG_NETLABEL
660 { 524 {
661 .ctl_name = NET_CIPSOV4_CACHE_ENABLE,
662 .procname = "cipso_cache_enable", 525 .procname = "cipso_cache_enable",
663 .data = &cipso_v4_cache_enabled, 526 .data = &cipso_v4_cache_enabled,
664 .maxlen = sizeof(int), 527 .maxlen = sizeof(int),
@@ -666,7 +529,6 @@ static struct ctl_table ipv4_table[] = {
666 .proc_handler = proc_dointvec, 529 .proc_handler = proc_dointvec,
667 }, 530 },
668 { 531 {
669 .ctl_name = NET_CIPSOV4_CACHE_BUCKET_SIZE,
670 .procname = "cipso_cache_bucket_size", 532 .procname = "cipso_cache_bucket_size",
671 .data = &cipso_v4_cache_bucketsize, 533 .data = &cipso_v4_cache_bucketsize,
672 .maxlen = sizeof(int), 534 .maxlen = sizeof(int),
@@ -674,7 +536,6 @@ static struct ctl_table ipv4_table[] = {
674 .proc_handler = proc_dointvec, 536 .proc_handler = proc_dointvec,
675 }, 537 },
676 { 538 {
677 .ctl_name = NET_CIPSOV4_RBM_OPTFMT,
678 .procname = "cipso_rbm_optfmt", 539 .procname = "cipso_rbm_optfmt",
679 .data = &cipso_v4_rbm_optfmt, 540 .data = &cipso_v4_rbm_optfmt,
680 .maxlen = sizeof(int), 541 .maxlen = sizeof(int),
@@ -682,7 +543,6 @@ static struct ctl_table ipv4_table[] = {
682 .proc_handler = proc_dointvec, 543 .proc_handler = proc_dointvec,
683 }, 544 },
684 { 545 {
685 .ctl_name = NET_CIPSOV4_RBM_STRICTVALID,
686 .procname = "cipso_rbm_strictvalid", 546 .procname = "cipso_rbm_strictvalid",
687 .data = &cipso_v4_rbm_strictvalid, 547 .data = &cipso_v4_rbm_strictvalid,
688 .maxlen = sizeof(int), 548 .maxlen = sizeof(int),
@@ -697,15 +557,12 @@ static struct ctl_table ipv4_table[] = {
697 .proc_handler = proc_tcp_available_congestion_control, 557 .proc_handler = proc_tcp_available_congestion_control,
698 }, 558 },
699 { 559 {
700 .ctl_name = NET_TCP_ALLOWED_CONG_CONTROL,
701 .procname = "tcp_allowed_congestion_control", 560 .procname = "tcp_allowed_congestion_control",
702 .maxlen = TCP_CA_BUF_MAX, 561 .maxlen = TCP_CA_BUF_MAX,
703 .mode = 0644, 562 .mode = 0644,
704 .proc_handler = proc_allowed_congestion_control, 563 .proc_handler = proc_allowed_congestion_control,
705 .strategy = strategy_allowed_congestion_control,
706 }, 564 },
707 { 565 {
708 .ctl_name = NET_TCP_MAX_SSTHRESH,
709 .procname = "tcp_max_ssthresh", 566 .procname = "tcp_max_ssthresh",
710 .data = &sysctl_tcp_max_ssthresh, 567 .data = &sysctl_tcp_max_ssthresh,
711 .maxlen = sizeof(int), 568 .maxlen = sizeof(int),
@@ -713,41 +570,55 @@ static struct ctl_table ipv4_table[] = {
713 .proc_handler = proc_dointvec, 570 .proc_handler = proc_dointvec,
714 }, 571 },
715 { 572 {
716 .ctl_name = CTL_UNNUMBERED, 573 .procname = "tcp_cookie_size",
574 .data = &sysctl_tcp_cookie_size,
575 .maxlen = sizeof(int),
576 .mode = 0644,
577 .proc_handler = proc_dointvec
578 },
579 {
580 .procname = "tcp_thin_linear_timeouts",
581 .data = &sysctl_tcp_thin_linear_timeouts,
582 .maxlen = sizeof(int),
583 .mode = 0644,
584 .proc_handler = proc_dointvec
585 },
586 {
587 .procname = "tcp_thin_dupack",
588 .data = &sysctl_tcp_thin_dupack,
589 .maxlen = sizeof(int),
590 .mode = 0644,
591 .proc_handler = proc_dointvec
592 },
593 {
717 .procname = "udp_mem", 594 .procname = "udp_mem",
718 .data = &sysctl_udp_mem, 595 .data = &sysctl_udp_mem,
719 .maxlen = sizeof(sysctl_udp_mem), 596 .maxlen = sizeof(sysctl_udp_mem),
720 .mode = 0644, 597 .mode = 0644,
721 .proc_handler = proc_dointvec_minmax, 598 .proc_handler = proc_dointvec_minmax,
722 .strategy = sysctl_intvec,
723 .extra1 = &zero 599 .extra1 = &zero
724 }, 600 },
725 { 601 {
726 .ctl_name = CTL_UNNUMBERED,
727 .procname = "udp_rmem_min", 602 .procname = "udp_rmem_min",
728 .data = &sysctl_udp_rmem_min, 603 .data = &sysctl_udp_rmem_min,
729 .maxlen = sizeof(sysctl_udp_rmem_min), 604 .maxlen = sizeof(sysctl_udp_rmem_min),
730 .mode = 0644, 605 .mode = 0644,
731 .proc_handler = proc_dointvec_minmax, 606 .proc_handler = proc_dointvec_minmax,
732 .strategy = sysctl_intvec,
733 .extra1 = &zero 607 .extra1 = &zero
734 }, 608 },
735 { 609 {
736 .ctl_name = CTL_UNNUMBERED,
737 .procname = "udp_wmem_min", 610 .procname = "udp_wmem_min",
738 .data = &sysctl_udp_wmem_min, 611 .data = &sysctl_udp_wmem_min,
739 .maxlen = sizeof(sysctl_udp_wmem_min), 612 .maxlen = sizeof(sysctl_udp_wmem_min),
740 .mode = 0644, 613 .mode = 0644,
741 .proc_handler = proc_dointvec_minmax, 614 .proc_handler = proc_dointvec_minmax,
742 .strategy = sysctl_intvec,
743 .extra1 = &zero 615 .extra1 = &zero
744 }, 616 },
745 { .ctl_name = 0 } 617 { }
746}; 618};
747 619
748static struct ctl_table ipv4_net_table[] = { 620static struct ctl_table ipv4_net_table[] = {
749 { 621 {
750 .ctl_name = NET_IPV4_ICMP_ECHO_IGNORE_ALL,
751 .procname = "icmp_echo_ignore_all", 622 .procname = "icmp_echo_ignore_all",
752 .data = &init_net.ipv4.sysctl_icmp_echo_ignore_all, 623 .data = &init_net.ipv4.sysctl_icmp_echo_ignore_all,
753 .maxlen = sizeof(int), 624 .maxlen = sizeof(int),
@@ -755,7 +626,6 @@ static struct ctl_table ipv4_net_table[] = {
755 .proc_handler = proc_dointvec 626 .proc_handler = proc_dointvec
756 }, 627 },
757 { 628 {
758 .ctl_name = NET_IPV4_ICMP_ECHO_IGNORE_BROADCASTS,
759 .procname = "icmp_echo_ignore_broadcasts", 629 .procname = "icmp_echo_ignore_broadcasts",
760 .data = &init_net.ipv4.sysctl_icmp_echo_ignore_broadcasts, 630 .data = &init_net.ipv4.sysctl_icmp_echo_ignore_broadcasts,
761 .maxlen = sizeof(int), 631 .maxlen = sizeof(int),
@@ -763,7 +633,6 @@ static struct ctl_table ipv4_net_table[] = {
763 .proc_handler = proc_dointvec 633 .proc_handler = proc_dointvec
764 }, 634 },
765 { 635 {
766 .ctl_name = NET_IPV4_ICMP_IGNORE_BOGUS_ERROR_RESPONSES,
767 .procname = "icmp_ignore_bogus_error_responses", 636 .procname = "icmp_ignore_bogus_error_responses",
768 .data = &init_net.ipv4.sysctl_icmp_ignore_bogus_error_responses, 637 .data = &init_net.ipv4.sysctl_icmp_ignore_bogus_error_responses,
769 .maxlen = sizeof(int), 638 .maxlen = sizeof(int),
@@ -771,7 +640,6 @@ static struct ctl_table ipv4_net_table[] = {
771 .proc_handler = proc_dointvec 640 .proc_handler = proc_dointvec
772 }, 641 },
773 { 642 {
774 .ctl_name = NET_IPV4_ICMP_ERRORS_USE_INBOUND_IFADDR,
775 .procname = "icmp_errors_use_inbound_ifaddr", 643 .procname = "icmp_errors_use_inbound_ifaddr",
776 .data = &init_net.ipv4.sysctl_icmp_errors_use_inbound_ifaddr, 644 .data = &init_net.ipv4.sysctl_icmp_errors_use_inbound_ifaddr,
777 .maxlen = sizeof(int), 645 .maxlen = sizeof(int),
@@ -779,16 +647,13 @@ static struct ctl_table ipv4_net_table[] = {
779 .proc_handler = proc_dointvec 647 .proc_handler = proc_dointvec
780 }, 648 },
781 { 649 {
782 .ctl_name = NET_IPV4_ICMP_RATELIMIT,
783 .procname = "icmp_ratelimit", 650 .procname = "icmp_ratelimit",
784 .data = &init_net.ipv4.sysctl_icmp_ratelimit, 651 .data = &init_net.ipv4.sysctl_icmp_ratelimit,
785 .maxlen = sizeof(int), 652 .maxlen = sizeof(int),
786 .mode = 0644, 653 .mode = 0644,
787 .proc_handler = proc_dointvec_ms_jiffies, 654 .proc_handler = proc_dointvec_ms_jiffies,
788 .strategy = sysctl_ms_jiffies
789 }, 655 },
790 { 656 {
791 .ctl_name = NET_IPV4_ICMP_RATEMASK,
792 .procname = "icmp_ratemask", 657 .procname = "icmp_ratemask",
793 .data = &init_net.ipv4.sysctl_icmp_ratemask, 658 .data = &init_net.ipv4.sysctl_icmp_ratemask,
794 .maxlen = sizeof(int), 659 .maxlen = sizeof(int),
@@ -796,7 +661,6 @@ static struct ctl_table ipv4_net_table[] = {
796 .proc_handler = proc_dointvec 661 .proc_handler = proc_dointvec
797 }, 662 },
798 { 663 {
799 .ctl_name = CTL_UNNUMBERED,
800 .procname = "rt_cache_rebuild_count", 664 .procname = "rt_cache_rebuild_count",
801 .data = &init_net.ipv4.sysctl_rt_cache_rebuild_count, 665 .data = &init_net.ipv4.sysctl_rt_cache_rebuild_count,
802 .maxlen = sizeof(int), 666 .maxlen = sizeof(int),
@@ -807,8 +671,8 @@ static struct ctl_table ipv4_net_table[] = {
807}; 671};
808 672
809struct ctl_path net_ipv4_ctl_path[] = { 673struct ctl_path net_ipv4_ctl_path[] = {
810 { .procname = "net", .ctl_name = CTL_NET, }, 674 { .procname = "net", },
811 { .procname = "ipv4", .ctl_name = NET_IPV4, }, 675 { .procname = "ipv4", },
812 { }, 676 { },
813}; 677};
814EXPORT_SYMBOL_GPL(net_ipv4_ctl_path); 678EXPORT_SYMBOL_GPL(net_ipv4_ctl_path);
@@ -818,7 +682,7 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)
818 struct ctl_table *table; 682 struct ctl_table *table;
819 683
820 table = ipv4_net_table; 684 table = ipv4_net_table;
821 if (net != &init_net) { 685 if (!net_eq(net, &init_net)) {
822 table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL); 686 table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
823 if (table == NULL) 687 if (table == NULL)
824 goto err_alloc; 688 goto err_alloc;
@@ -849,7 +713,7 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)
849 return 0; 713 return 0;
850 714
851err_reg: 715err_reg:
852 if (net != &init_net) 716 if (!net_eq(net, &init_net))
853 kfree(table); 717 kfree(table);
854err_alloc: 718err_alloc:
855 return -ENOMEM; 719 return -ENOMEM;
diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
index f1813bc71088..296150b2a62f 100644
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ -264,6 +264,8 @@
264#include <linux/cache.h> 264#include <linux/cache.h>
265#include <linux/err.h> 265#include <linux/err.h>
266#include <linux/crypto.h> 266#include <linux/crypto.h>
267#include <linux/time.h>
268#include <linux/slab.h>
267 269
268#include <net/icmp.h> 270#include <net/icmp.h>
269#include <net/tcp.h> 271#include <net/tcp.h>
@@ -428,7 +430,7 @@ unsigned int tcp_poll(struct file *file, struct socket *sock, poll_table *wait)
428 if (tp->urg_seq == tp->copied_seq && 430 if (tp->urg_seq == tp->copied_seq &&
429 !sock_flag(sk, SOCK_URGINLINE) && 431 !sock_flag(sk, SOCK_URGINLINE) &&
430 tp->urg_data) 432 tp->urg_data)
431 target--; 433 target++;
432 434
433 /* Potential race condition. If read of tp below will 435 /* Potential race condition. If read of tp below will
434 * escape above sk->sk_state, we can be illegally awaken 436 * escape above sk->sk_state, we can be illegally awaken
@@ -535,8 +537,7 @@ static inline void skb_entail(struct sock *sk, struct sk_buff *skb)
535 tp->nonagle &= ~TCP_NAGLE_PUSH; 537 tp->nonagle &= ~TCP_NAGLE_PUSH;
536} 538}
537 539
538static inline void tcp_mark_urg(struct tcp_sock *tp, int flags, 540static inline void tcp_mark_urg(struct tcp_sock *tp, int flags)
539 struct sk_buff *skb)
540{ 541{
541 if (flags & MSG_OOB) 542 if (flags & MSG_OOB)
542 tp->snd_up = tp->write_seq; 543 tp->snd_up = tp->write_seq;
@@ -545,13 +546,13 @@ static inline void tcp_mark_urg(struct tcp_sock *tp, int flags,
545static inline void tcp_push(struct sock *sk, int flags, int mss_now, 546static inline void tcp_push(struct sock *sk, int flags, int mss_now,
546 int nonagle) 547 int nonagle)
547{ 548{
548 struct tcp_sock *tp = tcp_sk(sk);
549
550 if (tcp_send_head(sk)) { 549 if (tcp_send_head(sk)) {
551 struct sk_buff *skb = tcp_write_queue_tail(sk); 550 struct tcp_sock *tp = tcp_sk(sk);
551
552 if (!(flags & MSG_MORE) || forced_push(tp)) 552 if (!(flags & MSG_MORE) || forced_push(tp))
553 tcp_mark_push(tp, skb); 553 tcp_mark_push(tp, tcp_write_queue_tail(sk));
554 tcp_mark_urg(tp, flags, skb); 554
555 tcp_mark_urg(tp, flags);
555 __tcp_push_pending_frames(sk, mss_now, 556 __tcp_push_pending_frames(sk, mss_now,
556 (flags & MSG_MORE) ? TCP_NAGLE_CORK : nonagle); 557 (flags & MSG_MORE) ? TCP_NAGLE_CORK : nonagle);
557 } 558 }
@@ -876,12 +877,12 @@ ssize_t tcp_sendpage(struct socket *sock, struct page *page, int offset,
876#define TCP_PAGE(sk) (sk->sk_sndmsg_page) 877#define TCP_PAGE(sk) (sk->sk_sndmsg_page)
877#define TCP_OFF(sk) (sk->sk_sndmsg_off) 878#define TCP_OFF(sk) (sk->sk_sndmsg_off)
878 879
879static inline int select_size(struct sock *sk) 880static inline int select_size(struct sock *sk, int sg)
880{ 881{
881 struct tcp_sock *tp = tcp_sk(sk); 882 struct tcp_sock *tp = tcp_sk(sk);
882 int tmp = tp->mss_cache; 883 int tmp = tp->mss_cache;
883 884
884 if (sk->sk_route_caps & NETIF_F_SG) { 885 if (sg) {
885 if (sk_can_gso(sk)) 886 if (sk_can_gso(sk))
886 tmp = 0; 887 tmp = 0;
887 else { 888 else {
@@ -905,7 +906,7 @@ int tcp_sendmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *msg,
905 struct sk_buff *skb; 906 struct sk_buff *skb;
906 int iovlen, flags; 907 int iovlen, flags;
907 int mss_now, size_goal; 908 int mss_now, size_goal;
908 int err, copied; 909 int sg, err, copied;
909 long timeo; 910 long timeo;
910 911
911 lock_sock(sk); 912 lock_sock(sk);
@@ -933,6 +934,8 @@ int tcp_sendmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *msg,
933 if (sk->sk_err || (sk->sk_shutdown & SEND_SHUTDOWN)) 934 if (sk->sk_err || (sk->sk_shutdown & SEND_SHUTDOWN))
934 goto out_err; 935 goto out_err;
935 936
937 sg = sk->sk_route_caps & NETIF_F_SG;
938
936 while (--iovlen >= 0) { 939 while (--iovlen >= 0) {
937 int seglen = iov->iov_len; 940 int seglen = iov->iov_len;
938 unsigned char __user *from = iov->iov_base; 941 unsigned char __user *from = iov->iov_base;
@@ -958,8 +961,9 @@ new_segment:
958 if (!sk_stream_memory_free(sk)) 961 if (!sk_stream_memory_free(sk))
959 goto wait_for_sndbuf; 962 goto wait_for_sndbuf;
960 963
961 skb = sk_stream_alloc_skb(sk, select_size(sk), 964 skb = sk_stream_alloc_skb(sk,
962 sk->sk_allocation); 965 select_size(sk, sg),
966 sk->sk_allocation);
963 if (!skb) 967 if (!skb)
964 goto wait_for_memory; 968 goto wait_for_memory;
965 969
@@ -996,9 +1000,7 @@ new_segment:
996 /* We can extend the last page 1000 /* We can extend the last page
997 * fragment. */ 1001 * fragment. */
998 merge = 1; 1002 merge = 1;
999 } else if (i == MAX_SKB_FRAGS || 1003 } else if (i == MAX_SKB_FRAGS || !sg) {
1000 (!i &&
1001 !(sk->sk_route_caps & NETIF_F_SG))) {
1002 /* Need to add new fragment and cannot 1004 /* Need to add new fragment and cannot
1003 * do this because interface is non-SG, 1005 * do this because interface is non-SG,
1004 * or because all the page slots are 1006 * or because all the page slots are
@@ -1253,6 +1255,39 @@ static void tcp_prequeue_process(struct sock *sk)
1253 tp->ucopy.memory = 0; 1255 tp->ucopy.memory = 0;
1254} 1256}
1255 1257
1258#ifdef CONFIG_NET_DMA
1259static void tcp_service_net_dma(struct sock *sk, bool wait)
1260{
1261 dma_cookie_t done, used;
1262 dma_cookie_t last_issued;
1263 struct tcp_sock *tp = tcp_sk(sk);
1264
1265 if (!tp->ucopy.dma_chan)
1266 return;
1267
1268 last_issued = tp->ucopy.dma_cookie;
1269 dma_async_memcpy_issue_pending(tp->ucopy.dma_chan);
1270
1271 do {
1272 if (dma_async_memcpy_complete(tp->ucopy.dma_chan,
1273 last_issued, &done,
1274 &used) == DMA_SUCCESS) {
1275 /* Safe to free early-copied skbs now */
1276 __skb_queue_purge(&sk->sk_async_wait_queue);
1277 break;
1278 } else {
1279 struct sk_buff *skb;
1280 while ((skb = skb_peek(&sk->sk_async_wait_queue)) &&
1281 (dma_async_is_complete(skb->dma_cookie, done,
1282 used) == DMA_SUCCESS)) {
1283 __skb_dequeue(&sk->sk_async_wait_queue);
1284 kfree_skb(skb);
1285 }
1286 }
1287 } while (wait);
1288}
1289#endif
1290
1256static inline struct sk_buff *tcp_recv_skb(struct sock *sk, u32 seq, u32 *off) 1291static inline struct sk_buff *tcp_recv_skb(struct sock *sk, u32 seq, u32 *off)
1257{ 1292{
1258 struct sk_buff *skb; 1293 struct sk_buff *skb;
@@ -1334,6 +1369,7 @@ int tcp_read_sock(struct sock *sk, read_descriptor_t *desc,
1334 sk_eat_skb(sk, skb, 0); 1369 sk_eat_skb(sk, skb, 0);
1335 if (!desc->count) 1370 if (!desc->count)
1336 break; 1371 break;
1372 tp->copied_seq = seq;
1337 } 1373 }
1338 tp->copied_seq = seq; 1374 tp->copied_seq = seq;
1339 1375
@@ -1545,6 +1581,10 @@ int tcp_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
1545 /* __ Set realtime policy in scheduler __ */ 1581 /* __ Set realtime policy in scheduler __ */
1546 } 1582 }
1547 1583
1584#ifdef CONFIG_NET_DMA
1585 if (tp->ucopy.dma_chan)
1586 dma_async_memcpy_issue_pending(tp->ucopy.dma_chan);
1587#endif
1548 if (copied >= target) { 1588 if (copied >= target) {
1549 /* Do not sleep, just process backlog. */ 1589 /* Do not sleep, just process backlog. */
1550 release_sock(sk); 1590 release_sock(sk);
@@ -1553,6 +1593,7 @@ int tcp_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
1553 sk_wait_data(sk, &timeo); 1593 sk_wait_data(sk, &timeo);
1554 1594
1555#ifdef CONFIG_NET_DMA 1595#ifdef CONFIG_NET_DMA
1596 tcp_service_net_dma(sk, false); /* Don't block */
1556 tp->ucopy.wakeup = 0; 1597 tp->ucopy.wakeup = 0;
1557#endif 1598#endif
1558 1599
@@ -1632,6 +1673,9 @@ do_prequeue:
1632 copied = -EFAULT; 1673 copied = -EFAULT;
1633 break; 1674 break;
1634 } 1675 }
1676
1677 dma_async_memcpy_issue_pending(tp->ucopy.dma_chan);
1678
1635 if ((offset + used) == skb->len) 1679 if ((offset + used) == skb->len)
1636 copied_early = 1; 1680 copied_early = 1;
1637 1681
@@ -1701,27 +1745,9 @@ skip_copy:
1701 } 1745 }
1702 1746
1703#ifdef CONFIG_NET_DMA 1747#ifdef CONFIG_NET_DMA
1704 if (tp->ucopy.dma_chan) { 1748 tcp_service_net_dma(sk, true); /* Wait for queue to drain */
1705 dma_cookie_t done, used; 1749 tp->ucopy.dma_chan = NULL;
1706
1707 dma_async_memcpy_issue_pending(tp->ucopy.dma_chan);
1708
1709 while (dma_async_memcpy_complete(tp->ucopy.dma_chan,
1710 tp->ucopy.dma_cookie, &done,
1711 &used) == DMA_IN_PROGRESS) {
1712 /* do partial cleanup of sk_async_wait_queue */
1713 while ((skb = skb_peek(&sk->sk_async_wait_queue)) &&
1714 (dma_async_is_complete(skb->dma_cookie, done,
1715 used) == DMA_SUCCESS)) {
1716 __skb_dequeue(&sk->sk_async_wait_queue);
1717 kfree_skb(skb);
1718 }
1719 }
1720 1750
1721 /* Safe to free early-copied skbs now */
1722 __skb_queue_purge(&sk->sk_async_wait_queue);
1723 tp->ucopy.dma_chan = NULL;
1724 }
1725 if (tp->ucopy.pinned_list) { 1751 if (tp->ucopy.pinned_list) {
1726 dma_unpin_iovec_pages(tp->ucopy.pinned_list); 1752 dma_unpin_iovec_pages(tp->ucopy.pinned_list);
1727 tp->ucopy.pinned_list = NULL; 1753 tp->ucopy.pinned_list = NULL;
@@ -2042,7 +2068,7 @@ int tcp_disconnect(struct sock *sk, int flags)
2042 __skb_queue_purge(&sk->sk_async_wait_queue); 2068 __skb_queue_purge(&sk->sk_async_wait_queue);
2043#endif 2069#endif
2044 2070
2045 inet->dport = 0; 2071 inet->inet_dport = 0;
2046 2072
2047 if (!(sk->sk_userlocks & SOCK_BINDADDR_LOCK)) 2073 if (!(sk->sk_userlocks & SOCK_BINDADDR_LOCK))
2048 inet_reset_saddr(sk); 2074 inet_reset_saddr(sk);
@@ -2059,6 +2085,7 @@ int tcp_disconnect(struct sock *sk, int flags)
2059 tp->snd_ssthresh = TCP_INFINITE_SSTHRESH; 2085 tp->snd_ssthresh = TCP_INFINITE_SSTHRESH;
2060 tp->snd_cwnd_cnt = 0; 2086 tp->snd_cwnd_cnt = 0;
2061 tp->bytes_acked = 0; 2087 tp->bytes_acked = 0;
2088 tp->window_clamp = 0;
2062 tcp_set_ca_state(sk, TCP_CA_Open); 2089 tcp_set_ca_state(sk, TCP_CA_Open);
2063 tcp_clear_retrans(tp); 2090 tcp_clear_retrans(tp);
2064 inet_csk_delack_init(sk); 2091 inet_csk_delack_init(sk);
@@ -2066,7 +2093,7 @@ int tcp_disconnect(struct sock *sk, int flags)
2066 memset(&tp->rx_opt, 0, sizeof(tp->rx_opt)); 2093 memset(&tp->rx_opt, 0, sizeof(tp->rx_opt));
2067 __sk_dst_reset(sk); 2094 __sk_dst_reset(sk);
2068 2095
2069 WARN_ON(inet->num && !icsk->icsk_bind_hash); 2096 WARN_ON(inet->inet_num && !icsk->icsk_bind_hash);
2070 2097
2071 sk->sk_error_report(sk); 2098 sk->sk_error_report(sk);
2072 return err; 2099 return err;
@@ -2083,8 +2110,9 @@ static int do_tcp_setsockopt(struct sock *sk, int level,
2083 int val; 2110 int val;
2084 int err = 0; 2111 int err = 0;
2085 2112
2086 /* This is a string value all the others are int's */ 2113 /* These are data/string values, all the others are ints */
2087 if (optname == TCP_CONGESTION) { 2114 switch (optname) {
2115 case TCP_CONGESTION: {
2088 char name[TCP_CA_NAME_MAX]; 2116 char name[TCP_CA_NAME_MAX];
2089 2117
2090 if (optlen < 1) 2118 if (optlen < 1)
@@ -2101,6 +2129,93 @@ static int do_tcp_setsockopt(struct sock *sk, int level,
2101 release_sock(sk); 2129 release_sock(sk);
2102 return err; 2130 return err;
2103 } 2131 }
2132 case TCP_COOKIE_TRANSACTIONS: {
2133 struct tcp_cookie_transactions ctd;
2134 struct tcp_cookie_values *cvp = NULL;
2135
2136 if (sizeof(ctd) > optlen)
2137 return -EINVAL;
2138 if (copy_from_user(&ctd, optval, sizeof(ctd)))
2139 return -EFAULT;
2140
2141 if (ctd.tcpct_used > sizeof(ctd.tcpct_value) ||
2142 ctd.tcpct_s_data_desired > TCP_MSS_DESIRED)
2143 return -EINVAL;
2144
2145 if (ctd.tcpct_cookie_desired == 0) {
2146 /* default to global value */
2147 } else if ((0x1 & ctd.tcpct_cookie_desired) ||
2148 ctd.tcpct_cookie_desired > TCP_COOKIE_MAX ||
2149 ctd.tcpct_cookie_desired < TCP_COOKIE_MIN) {
2150 return -EINVAL;
2151 }
2152
2153 if (TCP_COOKIE_OUT_NEVER & ctd.tcpct_flags) {
2154 /* Supercedes all other values */
2155 lock_sock(sk);
2156 if (tp->cookie_values != NULL) {
2157 kref_put(&tp->cookie_values->kref,
2158 tcp_cookie_values_release);
2159 tp->cookie_values = NULL;
2160 }
2161 tp->rx_opt.cookie_in_always = 0; /* false */
2162 tp->rx_opt.cookie_out_never = 1; /* true */
2163 release_sock(sk);
2164 return err;
2165 }
2166
2167 /* Allocate ancillary memory before locking.
2168 */
2169 if (ctd.tcpct_used > 0 ||
2170 (tp->cookie_values == NULL &&
2171 (sysctl_tcp_cookie_size > 0 ||
2172 ctd.tcpct_cookie_desired > 0 ||
2173 ctd.tcpct_s_data_desired > 0))) {
2174 cvp = kzalloc(sizeof(*cvp) + ctd.tcpct_used,
2175 GFP_KERNEL);
2176 if (cvp == NULL)
2177 return -ENOMEM;
2178 }
2179 lock_sock(sk);
2180 tp->rx_opt.cookie_in_always =
2181 (TCP_COOKIE_IN_ALWAYS & ctd.tcpct_flags);
2182 tp->rx_opt.cookie_out_never = 0; /* false */
2183
2184 if (tp->cookie_values != NULL) {
2185 if (cvp != NULL) {
2186 /* Changed values are recorded by a changed
2187 * pointer, ensuring the cookie will differ,
2188 * without separately hashing each value later.
2189 */
2190 kref_put(&tp->cookie_values->kref,
2191 tcp_cookie_values_release);
2192 kref_init(&cvp->kref);
2193 tp->cookie_values = cvp;
2194 } else {
2195 cvp = tp->cookie_values;
2196 }
2197 }
2198 if (cvp != NULL) {
2199 cvp->cookie_desired = ctd.tcpct_cookie_desired;
2200
2201 if (ctd.tcpct_used > 0) {
2202 memcpy(cvp->s_data_payload, ctd.tcpct_value,
2203 ctd.tcpct_used);
2204 cvp->s_data_desired = ctd.tcpct_used;
2205 cvp->s_data_constant = 1; /* true */
2206 } else {
2207 /* No constant payload data. */
2208 cvp->s_data_desired = ctd.tcpct_s_data_desired;
2209 cvp->s_data_constant = 0; /* false */
2210 }
2211 }
2212 release_sock(sk);
2213 return err;
2214 }
2215 default:
2216 /* fallthru */
2217 break;
2218 };
2104 2219
2105 if (optlen < sizeof(int)) 2220 if (optlen < sizeof(int))
2106 return -EINVAL; 2221 return -EINVAL;
@@ -2139,6 +2254,20 @@ static int do_tcp_setsockopt(struct sock *sk, int level,
2139 } 2254 }
2140 break; 2255 break;
2141 2256
2257 case TCP_THIN_LINEAR_TIMEOUTS:
2258 if (val < 0 || val > 1)
2259 err = -EINVAL;
2260 else
2261 tp->thin_lto = val;
2262 break;
2263
2264 case TCP_THIN_DUPACK:
2265 if (val < 0 || val > 1)
2266 err = -EINVAL;
2267 else
2268 tp->thin_dupack = val;
2269 break;
2270
2142 case TCP_CORK: 2271 case TCP_CORK:
2143 /* When set indicates to always queue non-full frames. 2272 /* When set indicates to always queue non-full frames.
2144 * Later the user clears this option and we transmit 2273 * Later the user clears this option and we transmit
@@ -2425,6 +2554,42 @@ static int do_tcp_getsockopt(struct sock *sk, int level,
2425 if (copy_to_user(optval, icsk->icsk_ca_ops->name, len)) 2554 if (copy_to_user(optval, icsk->icsk_ca_ops->name, len))
2426 return -EFAULT; 2555 return -EFAULT;
2427 return 0; 2556 return 0;
2557
2558 case TCP_COOKIE_TRANSACTIONS: {
2559 struct tcp_cookie_transactions ctd;
2560 struct tcp_cookie_values *cvp = tp->cookie_values;
2561
2562 if (get_user(len, optlen))
2563 return -EFAULT;
2564 if (len < sizeof(ctd))
2565 return -EINVAL;
2566
2567 memset(&ctd, 0, sizeof(ctd));
2568 ctd.tcpct_flags = (tp->rx_opt.cookie_in_always ?
2569 TCP_COOKIE_IN_ALWAYS : 0)
2570 | (tp->rx_opt.cookie_out_never ?
2571 TCP_COOKIE_OUT_NEVER : 0);
2572
2573 if (cvp != NULL) {
2574 ctd.tcpct_flags |= (cvp->s_data_in ?
2575 TCP_S_DATA_IN : 0)
2576 | (cvp->s_data_out ?
2577 TCP_S_DATA_OUT : 0);
2578
2579 ctd.tcpct_cookie_desired = cvp->cookie_desired;
2580 ctd.tcpct_s_data_desired = cvp->s_data_desired;
2581
2582 memcpy(&ctd.tcpct_value[0], &cvp->cookie_pair[0],
2583 cvp->cookie_pair_size);
2584 ctd.tcpct_used = cvp->cookie_pair_size;
2585 }
2586
2587 if (put_user(sizeof(ctd), optlen))
2588 return -EFAULT;
2589 if (copy_to_user(optval, &ctd, sizeof(ctd)))
2590 return -EFAULT;
2591 return 0;
2592 }
2428 default: 2593 default:
2429 return -ENOPROTOOPT; 2594 return -ENOPROTOOPT;
2430 } 2595 }
@@ -2662,10 +2827,10 @@ EXPORT_SYMBOL(tcp_gro_complete);
2662 2827
2663#ifdef CONFIG_TCP_MD5SIG 2828#ifdef CONFIG_TCP_MD5SIG
2664static unsigned long tcp_md5sig_users; 2829static unsigned long tcp_md5sig_users;
2665static struct tcp_md5sig_pool **tcp_md5sig_pool; 2830static struct tcp_md5sig_pool * __percpu *tcp_md5sig_pool;
2666static DEFINE_SPINLOCK(tcp_md5sig_pool_lock); 2831static DEFINE_SPINLOCK(tcp_md5sig_pool_lock);
2667 2832
2668static void __tcp_free_md5sig_pool(struct tcp_md5sig_pool **pool) 2833static void __tcp_free_md5sig_pool(struct tcp_md5sig_pool * __percpu *pool)
2669{ 2834{
2670 int cpu; 2835 int cpu;
2671 for_each_possible_cpu(cpu) { 2836 for_each_possible_cpu(cpu) {
@@ -2674,7 +2839,6 @@ static void __tcp_free_md5sig_pool(struct tcp_md5sig_pool **pool)
2674 if (p->md5_desc.tfm) 2839 if (p->md5_desc.tfm)
2675 crypto_free_hash(p->md5_desc.tfm); 2840 crypto_free_hash(p->md5_desc.tfm);
2676 kfree(p); 2841 kfree(p);
2677 p = NULL;
2678 } 2842 }
2679 } 2843 }
2680 free_percpu(pool); 2844 free_percpu(pool);
@@ -2682,7 +2846,7 @@ static void __tcp_free_md5sig_pool(struct tcp_md5sig_pool **pool)
2682 2846
2683void tcp_free_md5sig_pool(void) 2847void tcp_free_md5sig_pool(void)
2684{ 2848{
2685 struct tcp_md5sig_pool **pool = NULL; 2849 struct tcp_md5sig_pool * __percpu *pool = NULL;
2686 2850
2687 spin_lock_bh(&tcp_md5sig_pool_lock); 2851 spin_lock_bh(&tcp_md5sig_pool_lock);
2688 if (--tcp_md5sig_users == 0) { 2852 if (--tcp_md5sig_users == 0) {
@@ -2696,10 +2860,11 @@ void tcp_free_md5sig_pool(void)
2696 2860
2697EXPORT_SYMBOL(tcp_free_md5sig_pool); 2861EXPORT_SYMBOL(tcp_free_md5sig_pool);
2698 2862
2699static struct tcp_md5sig_pool **__tcp_alloc_md5sig_pool(struct sock *sk) 2863static struct tcp_md5sig_pool * __percpu *
2864__tcp_alloc_md5sig_pool(struct sock *sk)
2700{ 2865{
2701 int cpu; 2866 int cpu;
2702 struct tcp_md5sig_pool **pool; 2867 struct tcp_md5sig_pool * __percpu *pool;
2703 2868
2704 pool = alloc_percpu(struct tcp_md5sig_pool *); 2869 pool = alloc_percpu(struct tcp_md5sig_pool *);
2705 if (!pool) 2870 if (!pool)
@@ -2726,9 +2891,9 @@ out_free:
2726 return NULL; 2891 return NULL;
2727} 2892}
2728 2893
2729struct tcp_md5sig_pool **tcp_alloc_md5sig_pool(struct sock *sk) 2894struct tcp_md5sig_pool * __percpu *tcp_alloc_md5sig_pool(struct sock *sk)
2730{ 2895{
2731 struct tcp_md5sig_pool **pool; 2896 struct tcp_md5sig_pool * __percpu *pool;
2732 int alloc = 0; 2897 int alloc = 0;
2733 2898
2734retry: 2899retry:
@@ -2747,7 +2912,9 @@ retry:
2747 2912
2748 if (alloc) { 2913 if (alloc) {
2749 /* we cannot hold spinlock here because this may sleep. */ 2914 /* we cannot hold spinlock here because this may sleep. */
2750 struct tcp_md5sig_pool **p = __tcp_alloc_md5sig_pool(sk); 2915 struct tcp_md5sig_pool * __percpu *p;
2916
2917 p = __tcp_alloc_md5sig_pool(sk);
2751 spin_lock_bh(&tcp_md5sig_pool_lock); 2918 spin_lock_bh(&tcp_md5sig_pool_lock);
2752 if (!p) { 2919 if (!p) {
2753 tcp_md5sig_users--; 2920 tcp_md5sig_users--;
@@ -2769,25 +2936,40 @@ retry:
2769 2936
2770EXPORT_SYMBOL(tcp_alloc_md5sig_pool); 2937EXPORT_SYMBOL(tcp_alloc_md5sig_pool);
2771 2938
2772struct tcp_md5sig_pool *__tcp_get_md5sig_pool(int cpu) 2939
2940/**
2941 * tcp_get_md5sig_pool - get md5sig_pool for this user
2942 *
2943 * We use percpu structure, so if we succeed, we exit with preemption
2944 * and BH disabled, to make sure another thread or softirq handling
2945 * wont try to get same context.
2946 */
2947struct tcp_md5sig_pool *tcp_get_md5sig_pool(void)
2773{ 2948{
2774 struct tcp_md5sig_pool **p; 2949 struct tcp_md5sig_pool * __percpu *p;
2775 spin_lock_bh(&tcp_md5sig_pool_lock); 2950
2951 local_bh_disable();
2952
2953 spin_lock(&tcp_md5sig_pool_lock);
2776 p = tcp_md5sig_pool; 2954 p = tcp_md5sig_pool;
2777 if (p) 2955 if (p)
2778 tcp_md5sig_users++; 2956 tcp_md5sig_users++;
2779 spin_unlock_bh(&tcp_md5sig_pool_lock); 2957 spin_unlock(&tcp_md5sig_pool_lock);
2780 return (p ? *per_cpu_ptr(p, cpu) : NULL);
2781}
2782 2958
2783EXPORT_SYMBOL(__tcp_get_md5sig_pool); 2959 if (p)
2960 return *per_cpu_ptr(p, smp_processor_id());
2961
2962 local_bh_enable();
2963 return NULL;
2964}
2965EXPORT_SYMBOL(tcp_get_md5sig_pool);
2784 2966
2785void __tcp_put_md5sig_pool(void) 2967void tcp_put_md5sig_pool(void)
2786{ 2968{
2969 local_bh_enable();
2787 tcp_free_md5sig_pool(); 2970 tcp_free_md5sig_pool();
2788} 2971}
2789 2972EXPORT_SYMBOL(tcp_put_md5sig_pool);
2790EXPORT_SYMBOL(__tcp_put_md5sig_pool);
2791 2973
2792int tcp_md5_hash_header(struct tcp_md5sig_pool *hp, 2974int tcp_md5_hash_header(struct tcp_md5sig_pool *hp,
2793 struct tcphdr *th) 2975 struct tcphdr *th)
@@ -2847,6 +3029,135 @@ EXPORT_SYMBOL(tcp_md5_hash_key);
2847 3029
2848#endif 3030#endif
2849 3031
3032/**
3033 * Each Responder maintains up to two secret values concurrently for
3034 * efficient secret rollover. Each secret value has 4 states:
3035 *
3036 * Generating. (tcp_secret_generating != tcp_secret_primary)
3037 * Generates new Responder-Cookies, but not yet used for primary
3038 * verification. This is a short-term state, typically lasting only
3039 * one round trip time (RTT).
3040 *
3041 * Primary. (tcp_secret_generating == tcp_secret_primary)
3042 * Used both for generation and primary verification.
3043 *
3044 * Retiring. (tcp_secret_retiring != tcp_secret_secondary)
3045 * Used for verification, until the first failure that can be
3046 * verified by the newer Generating secret. At that time, this
3047 * cookie's state is changed to Secondary, and the Generating
3048 * cookie's state is changed to Primary. This is a short-term state,
3049 * typically lasting only one round trip time (RTT).
3050 *
3051 * Secondary. (tcp_secret_retiring == tcp_secret_secondary)
3052 * Used for secondary verification, after primary verification
3053 * failures. This state lasts no more than twice the Maximum Segment
3054 * Lifetime (2MSL). Then, the secret is discarded.
3055 */
3056struct tcp_cookie_secret {
3057 /* The secret is divided into two parts. The digest part is the
3058 * equivalent of previously hashing a secret and saving the state,
3059 * and serves as an initialization vector (IV). The message part
3060 * serves as the trailing secret.
3061 */
3062 u32 secrets[COOKIE_WORKSPACE_WORDS];
3063 unsigned long expires;
3064};
3065
3066#define TCP_SECRET_1MSL (HZ * TCP_PAWS_MSL)
3067#define TCP_SECRET_2MSL (HZ * TCP_PAWS_MSL * 2)
3068#define TCP_SECRET_LIFE (HZ * 600)
3069
3070static struct tcp_cookie_secret tcp_secret_one;
3071static struct tcp_cookie_secret tcp_secret_two;
3072
3073/* Essentially a circular list, without dynamic allocation. */
3074static struct tcp_cookie_secret *tcp_secret_generating;
3075static struct tcp_cookie_secret *tcp_secret_primary;
3076static struct tcp_cookie_secret *tcp_secret_retiring;
3077static struct tcp_cookie_secret *tcp_secret_secondary;
3078
3079static DEFINE_SPINLOCK(tcp_secret_locker);
3080
3081/* Select a pseudo-random word in the cookie workspace.
3082 */
3083static inline u32 tcp_cookie_work(const u32 *ws, const int n)
3084{
3085 return ws[COOKIE_DIGEST_WORDS + ((COOKIE_MESSAGE_WORDS-1) & ws[n])];
3086}
3087
3088/* Fill bakery[COOKIE_WORKSPACE_WORDS] with generator, updating as needed.
3089 * Called in softirq context.
3090 * Returns: 0 for success.
3091 */
3092int tcp_cookie_generator(u32 *bakery)
3093{
3094 unsigned long jiffy = jiffies;
3095
3096 if (unlikely(time_after_eq(jiffy, tcp_secret_generating->expires))) {
3097 spin_lock_bh(&tcp_secret_locker);
3098 if (!time_after_eq(jiffy, tcp_secret_generating->expires)) {
3099 /* refreshed by another */
3100 memcpy(bakery,
3101 &tcp_secret_generating->secrets[0],
3102 COOKIE_WORKSPACE_WORDS);
3103 } else {
3104 /* still needs refreshing */
3105 get_random_bytes(bakery, COOKIE_WORKSPACE_WORDS);
3106
3107 /* The first time, paranoia assumes that the
3108 * randomization function isn't as strong. But,
3109 * this secret initialization is delayed until
3110 * the last possible moment (packet arrival).
3111 * Although that time is observable, it is
3112 * unpredictably variable. Mash in the most
3113 * volatile clock bits available, and expire the
3114 * secret extra quickly.
3115 */
3116 if (unlikely(tcp_secret_primary->expires ==
3117 tcp_secret_secondary->expires)) {
3118 struct timespec tv;
3119
3120 getnstimeofday(&tv);
3121 bakery[COOKIE_DIGEST_WORDS+0] ^=
3122 (u32)tv.tv_nsec;
3123
3124 tcp_secret_secondary->expires = jiffy
3125 + TCP_SECRET_1MSL
3126 + (0x0f & tcp_cookie_work(bakery, 0));
3127 } else {
3128 tcp_secret_secondary->expires = jiffy
3129 + TCP_SECRET_LIFE
3130 + (0xff & tcp_cookie_work(bakery, 1));
3131 tcp_secret_primary->expires = jiffy
3132 + TCP_SECRET_2MSL
3133 + (0x1f & tcp_cookie_work(bakery, 2));
3134 }
3135 memcpy(&tcp_secret_secondary->secrets[0],
3136 bakery, COOKIE_WORKSPACE_WORDS);
3137
3138 rcu_assign_pointer(tcp_secret_generating,
3139 tcp_secret_secondary);
3140 rcu_assign_pointer(tcp_secret_retiring,
3141 tcp_secret_primary);
3142 /*
3143 * Neither call_rcu() nor synchronize_rcu() needed.
3144 * Retiring data is not freed. It is replaced after
3145 * further (locked) pointer updates, and a quiet time
3146 * (minimum 1MSL, maximum LIFE - 2MSL).
3147 */
3148 }
3149 spin_unlock_bh(&tcp_secret_locker);
3150 } else {
3151 rcu_read_lock_bh();
3152 memcpy(bakery,
3153 &rcu_dereference(tcp_secret_generating)->secrets[0],
3154 COOKIE_WORKSPACE_WORDS);
3155 rcu_read_unlock_bh();
3156 }
3157 return 0;
3158}
3159EXPORT_SYMBOL(tcp_cookie_generator);
3160
2850void tcp_done(struct sock *sk) 3161void tcp_done(struct sock *sk)
2851{ 3162{
2852 if (sk->sk_state == TCP_SYN_SENT || sk->sk_state == TCP_SYN_RECV) 3163 if (sk->sk_state == TCP_SYN_SENT || sk->sk_state == TCP_SYN_RECV)
@@ -2881,6 +3192,7 @@ void __init tcp_init(void)
2881 struct sk_buff *skb = NULL; 3192 struct sk_buff *skb = NULL;
2882 unsigned long nr_pages, limit; 3193 unsigned long nr_pages, limit;
2883 int order, i, max_share; 3194 int order, i, max_share;
3195 unsigned long jiffy = jiffies;
2884 3196
2885 BUILD_BUG_ON(sizeof(struct tcp_skb_cb) > sizeof(skb->cb)); 3197 BUILD_BUG_ON(sizeof(struct tcp_skb_cb) > sizeof(skb->cb));
2886 3198
@@ -2903,11 +3215,10 @@ void __init tcp_init(void)
2903 (totalram_pages >= 128 * 1024) ? 3215 (totalram_pages >= 128 * 1024) ?
2904 13 : 15, 3216 13 : 15,
2905 0, 3217 0,
2906 &tcp_hashinfo.ehash_size,
2907 NULL, 3218 NULL,
3219 &tcp_hashinfo.ehash_mask,
2908 thash_entries ? 0 : 512 * 1024); 3220 thash_entries ? 0 : 512 * 1024);
2909 tcp_hashinfo.ehash_size = 1 << tcp_hashinfo.ehash_size; 3221 for (i = 0; i <= tcp_hashinfo.ehash_mask; i++) {
2910 for (i = 0; i < tcp_hashinfo.ehash_size; i++) {
2911 INIT_HLIST_NULLS_HEAD(&tcp_hashinfo.ehash[i].chain, i); 3222 INIT_HLIST_NULLS_HEAD(&tcp_hashinfo.ehash[i].chain, i);
2912 INIT_HLIST_NULLS_HEAD(&tcp_hashinfo.ehash[i].twchain, i); 3223 INIT_HLIST_NULLS_HEAD(&tcp_hashinfo.ehash[i].twchain, i);
2913 } 3224 }
@@ -2916,7 +3227,7 @@ void __init tcp_init(void)
2916 tcp_hashinfo.bhash = 3227 tcp_hashinfo.bhash =
2917 alloc_large_system_hash("TCP bind", 3228 alloc_large_system_hash("TCP bind",
2918 sizeof(struct inet_bind_hashbucket), 3229 sizeof(struct inet_bind_hashbucket),
2919 tcp_hashinfo.ehash_size, 3230 tcp_hashinfo.ehash_mask + 1,
2920 (totalram_pages >= 128 * 1024) ? 3231 (totalram_pages >= 128 * 1024) ?
2921 13 : 15, 3232 13 : 15,
2922 0, 3233 0,
@@ -2971,10 +3282,19 @@ void __init tcp_init(void)
2971 sysctl_tcp_rmem[2] = max(87380, max_share); 3282 sysctl_tcp_rmem[2] = max(87380, max_share);
2972 3283
2973 printk(KERN_INFO "TCP: Hash tables configured " 3284 printk(KERN_INFO "TCP: Hash tables configured "
2974 "(established %d bind %d)\n", 3285 "(established %u bind %u)\n",
2975 tcp_hashinfo.ehash_size, tcp_hashinfo.bhash_size); 3286 tcp_hashinfo.ehash_mask + 1, tcp_hashinfo.bhash_size);
2976 3287
2977 tcp_register_congestion_control(&tcp_reno); 3288 tcp_register_congestion_control(&tcp_reno);
3289
3290 memset(&tcp_secret_one.secrets[0], 0, sizeof(tcp_secret_one.secrets));
3291 memset(&tcp_secret_two.secrets[0], 0, sizeof(tcp_secret_two.secrets));
3292 tcp_secret_one.expires = jiffy; /* past due */
3293 tcp_secret_two.expires = jiffy; /* past due */
3294 tcp_secret_generating = &tcp_secret_one;
3295 tcp_secret_primary = &tcp_secret_one;
3296 tcp_secret_retiring = &tcp_secret_two;
3297 tcp_secret_secondary = &tcp_secret_two;
2978} 3298}
2979 3299
2980EXPORT_SYMBOL(tcp_close); 3300EXPORT_SYMBOL(tcp_close);
diff --git a/net/ipv4/tcp_cong.c b/net/ipv4/tcp_cong.c
index 6428b342b164..0ec9bd0ae94f 100644
--- a/net/ipv4/tcp_cong.c
+++ b/net/ipv4/tcp_cong.c
@@ -10,6 +10,7 @@
10#include <linux/mm.h> 10#include <linux/mm.h>
11#include <linux/types.h> 11#include <linux/types.h>
12#include <linux/list.h> 12#include <linux/list.h>
13#include <linux/gfp.h>
13#include <net/tcp.h> 14#include <net/tcp.h>
14 15
15int sysctl_tcp_max_ssthresh = 0; 16int sysctl_tcp_max_ssthresh = 0;
diff --git a/net/ipv4/tcp_diag.c b/net/ipv4/tcp_diag.c
index fcbcd4ff6c5f..939edb3b8e4d 100644
--- a/net/ipv4/tcp_diag.c
+++ b/net/ipv4/tcp_diag.c
@@ -27,7 +27,7 @@ static void tcp_diag_get_info(struct sock *sk, struct inet_diag_msg *r,
27 r->idiag_rqueue = sk->sk_ack_backlog; 27 r->idiag_rqueue = sk->sk_ack_backlog;
28 r->idiag_wqueue = sk->sk_max_ack_backlog; 28 r->idiag_wqueue = sk->sk_max_ack_backlog;
29 } else { 29 } else {
30 r->idiag_rqueue = tp->rcv_nxt - tp->copied_seq; 30 r->idiag_rqueue = max_t(int, tp->rcv_nxt - tp->copied_seq, 0);
31 r->idiag_wqueue = tp->write_seq - tp->snd_una; 31 r->idiag_wqueue = tp->write_seq - tp->snd_una;
32 } 32 }
33 if (info != NULL) 33 if (info != NULL)
diff --git a/net/ipv4/tcp_htcp.c b/net/ipv4/tcp_htcp.c
index 26d5c7fc7de5..7c94a4955416 100644
--- a/net/ipv4/tcp_htcp.c
+++ b/net/ipv4/tcp_htcp.c
@@ -92,8 +92,8 @@ static inline void measure_rtt(struct sock *sk, u32 srtt)
92 if (icsk->icsk_ca_state == TCP_CA_Open) { 92 if (icsk->icsk_ca_state == TCP_CA_Open) {
93 if (ca->maxRTT < ca->minRTT) 93 if (ca->maxRTT < ca->minRTT)
94 ca->maxRTT = ca->minRTT; 94 ca->maxRTT = ca->minRTT;
95 if (ca->maxRTT < srtt 95 if (ca->maxRTT < srtt &&
96 && srtt <= ca->maxRTT + msecs_to_jiffies(20)) 96 srtt <= ca->maxRTT + msecs_to_jiffies(20))
97 ca->maxRTT = srtt; 97 ca->maxRTT = srtt;
98 } 98 }
99} 99}
@@ -123,9 +123,9 @@ static void measure_achieved_throughput(struct sock *sk, u32 pkts_acked, s32 rtt
123 123
124 ca->packetcount += pkts_acked; 124 ca->packetcount += pkts_acked;
125 125
126 if (ca->packetcount >= tp->snd_cwnd - (ca->alpha >> 7 ? : 1) 126 if (ca->packetcount >= tp->snd_cwnd - (ca->alpha >> 7 ? : 1) &&
127 && now - ca->lasttime >= ca->minRTT 127 now - ca->lasttime >= ca->minRTT &&
128 && ca->minRTT > 0) { 128 ca->minRTT > 0) {
129 __u32 cur_Bi = ca->packetcount * HZ / (now - ca->lasttime); 129 __u32 cur_Bi = ca->packetcount * HZ / (now - ca->lasttime);
130 130
131 if (htcp_ccount(ca) <= 3) { 131 if (htcp_ccount(ca) <= 3) {
diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
index d86784be7ab3..f240f57b2199 100644
--- a/net/ipv4/tcp_input.c
+++ b/net/ipv4/tcp_input.c
@@ -62,6 +62,7 @@
62 */ 62 */
63 63
64#include <linux/mm.h> 64#include <linux/mm.h>
65#include <linux/slab.h>
65#include <linux/module.h> 66#include <linux/module.h>
66#include <linux/sysctl.h> 67#include <linux/sysctl.h>
67#include <linux/kernel.h> 68#include <linux/kernel.h>
@@ -89,6 +90,8 @@ int sysctl_tcp_frto __read_mostly = 2;
89int sysctl_tcp_frto_response __read_mostly; 90int sysctl_tcp_frto_response __read_mostly;
90int sysctl_tcp_nometrics_save __read_mostly; 91int sysctl_tcp_nometrics_save __read_mostly;
91 92
93int sysctl_tcp_thin_dupack __read_mostly;
94
92int sysctl_tcp_moderate_rcvbuf __read_mostly = 1; 95int sysctl_tcp_moderate_rcvbuf __read_mostly = 1;
93int sysctl_tcp_abc __read_mostly; 96int sysctl_tcp_abc __read_mostly;
94 97
@@ -140,7 +143,7 @@ static void tcp_measure_rcv_mss(struct sock *sk, const struct sk_buff *skb)
140 * "len" is invariant segment length, including TCP header. 143 * "len" is invariant segment length, including TCP header.
141 */ 144 */
142 len += skb->data - skb_transport_header(skb); 145 len += skb->data - skb_transport_header(skb);
143 if (len >= TCP_MIN_RCVMSS + sizeof(struct tcphdr) || 146 if (len >= TCP_MSS_DEFAULT + sizeof(struct tcphdr) ||
144 /* If PSH is not set, packet should be 147 /* If PSH is not set, packet should be
145 * full sized, provided peer TCP is not badly broken. 148 * full sized, provided peer TCP is not badly broken.
146 * This observation (if it is correct 8)) allows 149 * This observation (if it is correct 8)) allows
@@ -411,7 +414,7 @@ void tcp_initialize_rcv_mss(struct sock *sk)
411 unsigned int hint = min_t(unsigned int, tp->advmss, tp->mss_cache); 414 unsigned int hint = min_t(unsigned int, tp->advmss, tp->mss_cache);
412 415
413 hint = min(hint, tp->rcv_wnd / 2); 416 hint = min(hint, tp->rcv_wnd / 2);
414 hint = min(hint, TCP_MIN_RCVMSS); 417 hint = min(hint, TCP_MSS_DEFAULT);
415 hint = max(hint, TCP_MIN_MSS); 418 hint = max(hint, TCP_MIN_MSS);
416 419
417 inet_csk(sk)->icsk_ack.rcv_mss = hint; 420 inet_csk(sk)->icsk_ack.rcv_mss = hint;
@@ -2300,7 +2303,7 @@ static inline int tcp_fackets_out(struct tcp_sock *tp)
2300 * they differ. Since neither occurs due to loss, TCP should really 2303 * they differ. Since neither occurs due to loss, TCP should really
2301 * ignore them. 2304 * ignore them.
2302 */ 2305 */
2303static inline int tcp_dupack_heurestics(struct tcp_sock *tp) 2306static inline int tcp_dupack_heuristics(struct tcp_sock *tp)
2304{ 2307{
2305 return tcp_is_fack(tp) ? tp->fackets_out : tp->sacked_out + 1; 2308 return tcp_is_fack(tp) ? tp->fackets_out : tp->sacked_out + 1;
2306} 2309}
@@ -2425,7 +2428,7 @@ static int tcp_time_to_recover(struct sock *sk)
2425 return 1; 2428 return 1;
2426 2429
2427 /* Not-A-Trick#2 : Classic rule... */ 2430 /* Not-A-Trick#2 : Classic rule... */
2428 if (tcp_dupack_heurestics(tp) > tp->reordering) 2431 if (tcp_dupack_heuristics(tp) > tp->reordering)
2429 return 1; 2432 return 1;
2430 2433
2431 /* Trick#3 : when we use RFC2988 timer restart, fast 2434 /* Trick#3 : when we use RFC2988 timer restart, fast
@@ -2447,6 +2450,16 @@ static int tcp_time_to_recover(struct sock *sk)
2447 return 1; 2450 return 1;
2448 } 2451 }
2449 2452
2453 /* If a thin stream is detected, retransmit after first
2454 * received dupack. Employ only if SACK is supported in order
2455 * to avoid possible corner-case series of spurious retransmissions
2456 * Use only if there are no unsent data.
2457 */
2458 if ((tp->thin_dupack || sysctl_tcp_thin_dupack) &&
2459 tcp_stream_is_thin(tp) && tcp_dupack_heuristics(tp) > 1 &&
2460 tcp_is_sack(tp) && !tcp_send_head(sk))
2461 return 1;
2462
2450 return 0; 2463 return 0;
2451} 2464}
2452 2465
@@ -2499,6 +2512,9 @@ static void tcp_mark_head_lost(struct sock *sk, int packets)
2499 int err; 2512 int err;
2500 unsigned int mss; 2513 unsigned int mss;
2501 2514
2515 if (packets == 0)
2516 return;
2517
2502 WARN_ON(packets > tp->packets_out); 2518 WARN_ON(packets > tp->packets_out);
2503 if (tp->lost_skb_hint) { 2519 if (tp->lost_skb_hint) {
2504 skb = tp->lost_skb_hint; 2520 skb = tp->lost_skb_hint;
@@ -2717,6 +2733,35 @@ static void tcp_try_undo_dsack(struct sock *sk)
2717 } 2733 }
2718} 2734}
2719 2735
2736/* We can clear retrans_stamp when there are no retransmissions in the
2737 * window. It would seem that it is trivially available for us in
2738 * tp->retrans_out, however, that kind of assumptions doesn't consider
2739 * what will happen if errors occur when sending retransmission for the
2740 * second time. ...It could the that such segment has only
2741 * TCPCB_EVER_RETRANS set at the present time. It seems that checking
2742 * the head skb is enough except for some reneging corner cases that
2743 * are not worth the effort.
2744 *
2745 * Main reason for all this complexity is the fact that connection dying
2746 * time now depends on the validity of the retrans_stamp, in particular,
2747 * that successive retransmissions of a segment must not advance
2748 * retrans_stamp under any conditions.
2749 */
2750static int tcp_any_retrans_done(struct sock *sk)
2751{
2752 struct tcp_sock *tp = tcp_sk(sk);
2753 struct sk_buff *skb;
2754
2755 if (tp->retrans_out)
2756 return 1;
2757
2758 skb = tcp_write_queue_head(sk);
2759 if (unlikely(skb && TCP_SKB_CB(skb)->sacked & TCPCB_EVER_RETRANS))
2760 return 1;
2761
2762 return 0;
2763}
2764
2720/* Undo during fast recovery after partial ACK. */ 2765/* Undo during fast recovery after partial ACK. */
2721 2766
2722static int tcp_try_undo_partial(struct sock *sk, int acked) 2767static int tcp_try_undo_partial(struct sock *sk, int acked)
@@ -2729,7 +2774,7 @@ static int tcp_try_undo_partial(struct sock *sk, int acked)
2729 /* Plain luck! Hole if filled with delayed 2774 /* Plain luck! Hole if filled with delayed
2730 * packet, rather than with a retransmit. 2775 * packet, rather than with a retransmit.
2731 */ 2776 */
2732 if (tp->retrans_out == 0) 2777 if (!tcp_any_retrans_done(sk))
2733 tp->retrans_stamp = 0; 2778 tp->retrans_stamp = 0;
2734 2779
2735 tcp_update_reordering(sk, tcp_fackets_out(tp) + acked, 1); 2780 tcp_update_reordering(sk, tcp_fackets_out(tp) + acked, 1);
@@ -2788,7 +2833,7 @@ static void tcp_try_keep_open(struct sock *sk)
2788 struct tcp_sock *tp = tcp_sk(sk); 2833 struct tcp_sock *tp = tcp_sk(sk);
2789 int state = TCP_CA_Open; 2834 int state = TCP_CA_Open;
2790 2835
2791 if (tcp_left_out(tp) || tp->retrans_out || tp->undo_marker) 2836 if (tcp_left_out(tp) || tcp_any_retrans_done(sk) || tp->undo_marker)
2792 state = TCP_CA_Disorder; 2837 state = TCP_CA_Disorder;
2793 2838
2794 if (inet_csk(sk)->icsk_ca_state != state) { 2839 if (inet_csk(sk)->icsk_ca_state != state) {
@@ -2803,7 +2848,7 @@ static void tcp_try_to_open(struct sock *sk, int flag)
2803 2848
2804 tcp_verify_left_out(tp); 2849 tcp_verify_left_out(tp);
2805 2850
2806 if (!tp->frto_counter && tp->retrans_out == 0) 2851 if (!tp->frto_counter && !tcp_any_retrans_done(sk))
2807 tp->retrans_stamp = 0; 2852 tp->retrans_stamp = 0;
2808 2853
2809 if (flag & FLAG_ECE) 2854 if (flag & FLAG_ECE)
@@ -3698,7 +3743,7 @@ old_ack:
3698 * the fast version below fails. 3743 * the fast version below fails.
3699 */ 3744 */
3700void tcp_parse_options(struct sk_buff *skb, struct tcp_options_received *opt_rx, 3745void tcp_parse_options(struct sk_buff *skb, struct tcp_options_received *opt_rx,
3701 int estab) 3746 u8 **hvpp, int estab)
3702{ 3747{
3703 unsigned char *ptr; 3748 unsigned char *ptr;
3704 struct tcphdr *th = tcp_hdr(skb); 3749 struct tcphdr *th = tcp_hdr(skb);
@@ -3782,7 +3827,30 @@ void tcp_parse_options(struct sk_buff *skb, struct tcp_options_received *opt_rx,
3782 */ 3827 */
3783 break; 3828 break;
3784#endif 3829#endif
3785 } 3830 case TCPOPT_COOKIE:
3831 /* This option is variable length.
3832 */
3833 switch (opsize) {
3834 case TCPOLEN_COOKIE_BASE:
3835 /* not yet implemented */
3836 break;
3837 case TCPOLEN_COOKIE_PAIR:
3838 /* not yet implemented */
3839 break;
3840 case TCPOLEN_COOKIE_MIN+0:
3841 case TCPOLEN_COOKIE_MIN+2:
3842 case TCPOLEN_COOKIE_MIN+4:
3843 case TCPOLEN_COOKIE_MIN+6:
3844 case TCPOLEN_COOKIE_MAX:
3845 /* 16-bit multiple */
3846 opt_rx->cookie_plus = opsize;
3847 *hvpp = ptr;
3848 default:
3849 /* ignore option */
3850 break;
3851 };
3852 break;
3853 };
3786 3854
3787 ptr += opsize-2; 3855 ptr += opsize-2;
3788 length -= opsize; 3856 length -= opsize;
@@ -3810,17 +3878,20 @@ static int tcp_parse_aligned_timestamp(struct tcp_sock *tp, struct tcphdr *th)
3810 * If it is wrong it falls back on tcp_parse_options(). 3878 * If it is wrong it falls back on tcp_parse_options().
3811 */ 3879 */
3812static int tcp_fast_parse_options(struct sk_buff *skb, struct tcphdr *th, 3880static int tcp_fast_parse_options(struct sk_buff *skb, struct tcphdr *th,
3813 struct tcp_sock *tp) 3881 struct tcp_sock *tp, u8 **hvpp)
3814{ 3882{
3815 if (th->doff == sizeof(struct tcphdr) >> 2) { 3883 /* In the spirit of fast parsing, compare doff directly to constant
3884 * values. Because equality is used, short doff can be ignored here.
3885 */
3886 if (th->doff == (sizeof(*th) / 4)) {
3816 tp->rx_opt.saw_tstamp = 0; 3887 tp->rx_opt.saw_tstamp = 0;
3817 return 0; 3888 return 0;
3818 } else if (tp->rx_opt.tstamp_ok && 3889 } else if (tp->rx_opt.tstamp_ok &&
3819 th->doff == (sizeof(struct tcphdr)>>2)+(TCPOLEN_TSTAMP_ALIGNED>>2)) { 3890 th->doff == ((sizeof(*th) + TCPOLEN_TSTAMP_ALIGNED) / 4)) {
3820 if (tcp_parse_aligned_timestamp(tp, th)) 3891 if (tcp_parse_aligned_timestamp(tp, th))
3821 return 1; 3892 return 1;
3822 } 3893 }
3823 tcp_parse_options(skb, &tp->rx_opt, 1); 3894 tcp_parse_options(skb, &tp->rx_opt, hvpp, 1);
3824 return 1; 3895 return 1;
3825} 3896}
3826 3897
@@ -4845,11 +4916,11 @@ static void __tcp_ack_snd_check(struct sock *sk, int ofo_possible)
4845 struct tcp_sock *tp = tcp_sk(sk); 4916 struct tcp_sock *tp = tcp_sk(sk);
4846 4917
4847 /* More than one full frame received... */ 4918 /* More than one full frame received... */
4848 if (((tp->rcv_nxt - tp->rcv_wup) > inet_csk(sk)->icsk_ack.rcv_mss 4919 if (((tp->rcv_nxt - tp->rcv_wup) > inet_csk(sk)->icsk_ack.rcv_mss &&
4849 /* ... and right edge of window advances far enough. 4920 /* ... and right edge of window advances far enough.
4850 * (tcp_recvmsg() will send ACK otherwise). Or... 4921 * (tcp_recvmsg() will send ACK otherwise). Or...
4851 */ 4922 */
4852 && __tcp_select_window(sk) >= tp->rcv_wnd) || 4923 __tcp_select_window(sk) >= tp->rcv_wnd) ||
4853 /* We ACK each frame or... */ 4924 /* We ACK each frame or... */
4854 tcp_in_quickack_mode(sk) || 4925 tcp_in_quickack_mode(sk) ||
4855 /* We have out of order data. */ 4926 /* We have out of order data. */
@@ -5070,10 +5141,12 @@ out:
5070static int tcp_validate_incoming(struct sock *sk, struct sk_buff *skb, 5141static int tcp_validate_incoming(struct sock *sk, struct sk_buff *skb,
5071 struct tcphdr *th, int syn_inerr) 5142 struct tcphdr *th, int syn_inerr)
5072{ 5143{
5144 u8 *hash_location;
5073 struct tcp_sock *tp = tcp_sk(sk); 5145 struct tcp_sock *tp = tcp_sk(sk);
5074 5146
5075 /* RFC1323: H1. Apply PAWS check first. */ 5147 /* RFC1323: H1. Apply PAWS check first. */
5076 if (tcp_fast_parse_options(skb, th, tp) && tp->rx_opt.saw_tstamp && 5148 if (tcp_fast_parse_options(skb, th, tp, &hash_location) &&
5149 tp->rx_opt.saw_tstamp &&
5077 tcp_paws_discard(sk, skb)) { 5150 tcp_paws_discard(sk, skb)) {
5078 if (!th->rst) { 5151 if (!th->rst) {
5079 NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_PAWSESTABREJECTED); 5152 NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_PAWSESTABREJECTED);
@@ -5361,11 +5434,13 @@ discard:
5361static int tcp_rcv_synsent_state_process(struct sock *sk, struct sk_buff *skb, 5434static int tcp_rcv_synsent_state_process(struct sock *sk, struct sk_buff *skb,
5362 struct tcphdr *th, unsigned len) 5435 struct tcphdr *th, unsigned len)
5363{ 5436{
5364 struct tcp_sock *tp = tcp_sk(sk); 5437 u8 *hash_location;
5365 struct inet_connection_sock *icsk = inet_csk(sk); 5438 struct inet_connection_sock *icsk = inet_csk(sk);
5439 struct tcp_sock *tp = tcp_sk(sk);
5440 struct tcp_cookie_values *cvp = tp->cookie_values;
5366 int saved_clamp = tp->rx_opt.mss_clamp; 5441 int saved_clamp = tp->rx_opt.mss_clamp;
5367 5442
5368 tcp_parse_options(skb, &tp->rx_opt, 0); 5443 tcp_parse_options(skb, &tp->rx_opt, &hash_location, 0);
5369 5444
5370 if (th->ack) { 5445 if (th->ack) {
5371 /* rfc793: 5446 /* rfc793:
@@ -5462,6 +5537,31 @@ static int tcp_rcv_synsent_state_process(struct sock *sk, struct sk_buff *skb,
5462 * Change state from SYN-SENT only after copied_seq 5537 * Change state from SYN-SENT only after copied_seq
5463 * is initialized. */ 5538 * is initialized. */
5464 tp->copied_seq = tp->rcv_nxt; 5539 tp->copied_seq = tp->rcv_nxt;
5540
5541 if (cvp != NULL &&
5542 cvp->cookie_pair_size > 0 &&
5543 tp->rx_opt.cookie_plus > 0) {
5544 int cookie_size = tp->rx_opt.cookie_plus
5545 - TCPOLEN_COOKIE_BASE;
5546 int cookie_pair_size = cookie_size
5547 + cvp->cookie_desired;
5548
5549 /* A cookie extension option was sent and returned.
5550 * Note that each incoming SYNACK replaces the
5551 * Responder cookie. The initial exchange is most
5552 * fragile, as protection against spoofing relies
5553 * entirely upon the sequence and timestamp (above).
5554 * This replacement strategy allows the correct pair to
5555 * pass through, while any others will be filtered via
5556 * Responder verification later.
5557 */
5558 if (sizeof(cvp->cookie_pair) >= cookie_pair_size) {
5559 memcpy(&cvp->cookie_pair[cvp->cookie_desired],
5560 hash_location, cookie_size);
5561 cvp->cookie_pair_size = cookie_pair_size;
5562 }
5563 }
5564
5465 smp_mb(); 5565 smp_mb();
5466 tcp_set_state(sk, TCP_ESTABLISHED); 5566 tcp_set_state(sk, TCP_ESTABLISHED);
5467 5567
@@ -5699,11 +5799,9 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
5699 5799
5700 /* tcp_ack considers this ACK as duplicate 5800 /* tcp_ack considers this ACK as duplicate
5701 * and does not calculate rtt. 5801 * and does not calculate rtt.
5702 * Fix it at least with timestamps. 5802 * Force it here.
5703 */ 5803 */
5704 if (tp->rx_opt.saw_tstamp && 5804 tcp_ack_update_rtt(sk, 0, 0);
5705 tp->rx_opt.rcv_tsecr && !tp->srtt)
5706 tcp_ack_saw_tstamp(sk, 0);
5707 5805
5708 if (tp->rx_opt.tstamp_ok) 5806 if (tp->rx_opt.tstamp_ok)
5709 tp->advmss -= TCPOLEN_TSTAMP_ALIGNED; 5807 tp->advmss -= TCPOLEN_TSTAMP_ALIGNED;
diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
index 7cda24b53f61..3c23e70885f4 100644
--- a/net/ipv4/tcp_ipv4.c
+++ b/net/ipv4/tcp_ipv4.c
@@ -60,6 +60,7 @@
60#include <linux/jhash.h> 60#include <linux/jhash.h>
61#include <linux/init.h> 61#include <linux/init.h>
62#include <linux/times.h> 62#include <linux/times.h>
63#include <linux/slab.h>
63 64
64#include <net/net_namespace.h> 65#include <net/net_namespace.h>
65#include <net/icmp.h> 66#include <net/icmp.h>
@@ -165,10 +166,10 @@ int tcp_v4_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len)
165 nexthop = inet->opt->faddr; 166 nexthop = inet->opt->faddr;
166 } 167 }
167 168
168 tmp = ip_route_connect(&rt, nexthop, inet->saddr, 169 tmp = ip_route_connect(&rt, nexthop, inet->inet_saddr,
169 RT_CONN_FLAGS(sk), sk->sk_bound_dev_if, 170 RT_CONN_FLAGS(sk), sk->sk_bound_dev_if,
170 IPPROTO_TCP, 171 IPPROTO_TCP,
171 inet->sport, usin->sin_port, sk, 1); 172 inet->inet_sport, usin->sin_port, sk, 1);
172 if (tmp < 0) { 173 if (tmp < 0) {
173 if (tmp == -ENETUNREACH) 174 if (tmp == -ENETUNREACH)
174 IP_INC_STATS_BH(sock_net(sk), IPSTATS_MIB_OUTNOROUTES); 175 IP_INC_STATS_BH(sock_net(sk), IPSTATS_MIB_OUTNOROUTES);
@@ -183,11 +184,11 @@ int tcp_v4_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len)
183 if (!inet->opt || !inet->opt->srr) 184 if (!inet->opt || !inet->opt->srr)
184 daddr = rt->rt_dst; 185 daddr = rt->rt_dst;
185 186
186 if (!inet->saddr) 187 if (!inet->inet_saddr)
187 inet->saddr = rt->rt_src; 188 inet->inet_saddr = rt->rt_src;
188 inet->rcv_saddr = inet->saddr; 189 inet->inet_rcv_saddr = inet->inet_saddr;
189 190
190 if (tp->rx_opt.ts_recent_stamp && inet->daddr != daddr) { 191 if (tp->rx_opt.ts_recent_stamp && inet->inet_daddr != daddr) {
191 /* Reset inherited state */ 192 /* Reset inherited state */
192 tp->rx_opt.ts_recent = 0; 193 tp->rx_opt.ts_recent = 0;
193 tp->rx_opt.ts_recent_stamp = 0; 194 tp->rx_opt.ts_recent_stamp = 0;
@@ -204,20 +205,20 @@ int tcp_v4_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len)
204 * when trying new connection. 205 * when trying new connection.
205 */ 206 */
206 if (peer != NULL && 207 if (peer != NULL &&
207 peer->tcp_ts_stamp + TCP_PAWS_MSL >= get_seconds()) { 208 (u32)get_seconds() - peer->tcp_ts_stamp <= TCP_PAWS_MSL) {
208 tp->rx_opt.ts_recent_stamp = peer->tcp_ts_stamp; 209 tp->rx_opt.ts_recent_stamp = peer->tcp_ts_stamp;
209 tp->rx_opt.ts_recent = peer->tcp_ts; 210 tp->rx_opt.ts_recent = peer->tcp_ts;
210 } 211 }
211 } 212 }
212 213
213 inet->dport = usin->sin_port; 214 inet->inet_dport = usin->sin_port;
214 inet->daddr = daddr; 215 inet->inet_daddr = daddr;
215 216
216 inet_csk(sk)->icsk_ext_hdr_len = 0; 217 inet_csk(sk)->icsk_ext_hdr_len = 0;
217 if (inet->opt) 218 if (inet->opt)
218 inet_csk(sk)->icsk_ext_hdr_len = inet->opt->optlen; 219 inet_csk(sk)->icsk_ext_hdr_len = inet->opt->optlen;
219 220
220 tp->rx_opt.mss_clamp = 536; 221 tp->rx_opt.mss_clamp = TCP_MSS_DEFAULT;
221 222
222 /* Socket identity is still unknown (sport may be zero). 223 /* Socket identity is still unknown (sport may be zero).
223 * However we set state to SYN-SENT and not releasing socket 224 * However we set state to SYN-SENT and not releasing socket
@@ -230,7 +231,7 @@ int tcp_v4_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len)
230 goto failure; 231 goto failure;
231 232
232 err = ip_route_newports(&rt, IPPROTO_TCP, 233 err = ip_route_newports(&rt, IPPROTO_TCP,
233 inet->sport, inet->dport, sk); 234 inet->inet_sport, inet->inet_dport, sk);
234 if (err) 235 if (err)
235 goto failure; 236 goto failure;
236 237
@@ -239,12 +240,12 @@ int tcp_v4_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len)
239 sk_setup_caps(sk, &rt->u.dst); 240 sk_setup_caps(sk, &rt->u.dst);
240 241
241 if (!tp->write_seq) 242 if (!tp->write_seq)
242 tp->write_seq = secure_tcp_sequence_number(inet->saddr, 243 tp->write_seq = secure_tcp_sequence_number(inet->inet_saddr,
243 inet->daddr, 244 inet->inet_daddr,
244 inet->sport, 245 inet->inet_sport,
245 usin->sin_port); 246 usin->sin_port);
246 247
247 inet->id = tp->write_seq ^ jiffies; 248 inet->inet_id = tp->write_seq ^ jiffies;
248 249
249 err = tcp_connect(sk); 250 err = tcp_connect(sk);
250 rt = NULL; 251 rt = NULL;
@@ -261,7 +262,7 @@ failure:
261 tcp_set_state(sk, TCP_CLOSE); 262 tcp_set_state(sk, TCP_CLOSE);
262 ip_rt_put(rt); 263 ip_rt_put(rt);
263 sk->sk_route_caps = 0; 264 sk->sk_route_caps = 0;
264 inet->dport = 0; 265 inet->inet_dport = 0;
265 return err; 266 return err;
266} 267}
267 268
@@ -370,6 +371,11 @@ void tcp_v4_err(struct sk_buff *icmp_skb, u32 info)
370 if (sk->sk_state == TCP_CLOSE) 371 if (sk->sk_state == TCP_CLOSE)
371 goto out; 372 goto out;
372 373
374 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
375 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
376 goto out;
377 }
378
373 icsk = inet_csk(sk); 379 icsk = inet_csk(sk);
374 tp = tcp_sk(sk); 380 tp = tcp_sk(sk);
375 seq = ntohl(th->seq); 381 seq = ntohl(th->seq);
@@ -520,12 +526,13 @@ void tcp_v4_send_check(struct sock *sk, int len, struct sk_buff *skb)
520 struct tcphdr *th = tcp_hdr(skb); 526 struct tcphdr *th = tcp_hdr(skb);
521 527
522 if (skb->ip_summed == CHECKSUM_PARTIAL) { 528 if (skb->ip_summed == CHECKSUM_PARTIAL) {
523 th->check = ~tcp_v4_check(len, inet->saddr, 529 th->check = ~tcp_v4_check(len, inet->inet_saddr,
524 inet->daddr, 0); 530 inet->inet_daddr, 0);
525 skb->csum_start = skb_transport_header(skb) - skb->head; 531 skb->csum_start = skb_transport_header(skb) - skb->head;
526 skb->csum_offset = offsetof(struct tcphdr, check); 532 skb->csum_offset = offsetof(struct tcphdr, check);
527 } else { 533 } else {
528 th->check = tcp_v4_check(len, inet->saddr, inet->daddr, 534 th->check = tcp_v4_check(len, inet->inet_saddr,
535 inet->inet_daddr,
529 csum_partial(th, 536 csum_partial(th,
530 th->doff << 2, 537 th->doff << 2,
531 skb->csum)); 538 skb->csum));
@@ -741,8 +748,9 @@ static void tcp_v4_reqsk_send_ack(struct sock *sk, struct sk_buff *skb,
741 * This still operates on a request_sock only, not on a big 748 * This still operates on a request_sock only, not on a big
742 * socket. 749 * socket.
743 */ 750 */
744static int __tcp_v4_send_synack(struct sock *sk, struct request_sock *req, 751static int tcp_v4_send_synack(struct sock *sk, struct dst_entry *dst,
745 struct dst_entry *dst) 752 struct request_sock *req,
753 struct request_values *rvp)
746{ 754{
747 const struct inet_request_sock *ireq = inet_rsk(req); 755 const struct inet_request_sock *ireq = inet_rsk(req);
748 int err = -1; 756 int err = -1;
@@ -752,7 +760,7 @@ static int __tcp_v4_send_synack(struct sock *sk, struct request_sock *req,
752 if (!dst && (dst = inet_csk_route_req(sk, req)) == NULL) 760 if (!dst && (dst = inet_csk_route_req(sk, req)) == NULL)
753 return -1; 761 return -1;
754 762
755 skb = tcp_make_synack(sk, dst, req); 763 skb = tcp_make_synack(sk, dst, req, rvp);
756 764
757 if (skb) { 765 if (skb) {
758 struct tcphdr *th = tcp_hdr(skb); 766 struct tcphdr *th = tcp_hdr(skb);
@@ -773,9 +781,11 @@ static int __tcp_v4_send_synack(struct sock *sk, struct request_sock *req,
773 return err; 781 return err;
774} 782}
775 783
776static int tcp_v4_send_synack(struct sock *sk, struct request_sock *req) 784static int tcp_v4_rtx_synack(struct sock *sk, struct request_sock *req,
785 struct request_values *rvp)
777{ 786{
778 return __tcp_v4_send_synack(sk, req, NULL); 787 TCP_INC_STATS_BH(sock_net(sk), TCP_MIB_RETRANSSEGS);
788 return tcp_v4_send_synack(sk, NULL, req, rvp);
779} 789}
780 790
781/* 791/*
@@ -848,7 +858,7 @@ static struct tcp_md5sig_key *
848struct tcp_md5sig_key *tcp_v4_md5_lookup(struct sock *sk, 858struct tcp_md5sig_key *tcp_v4_md5_lookup(struct sock *sk,
849 struct sock *addr_sk) 859 struct sock *addr_sk)
850{ 860{
851 return tcp_v4_md5_do_lookup(sk, inet_sk(addr_sk)->daddr); 861 return tcp_v4_md5_do_lookup(sk, inet_sk(addr_sk)->inet_daddr);
852} 862}
853 863
854EXPORT_SYMBOL(tcp_v4_md5_lookup); 864EXPORT_SYMBOL(tcp_v4_md5_lookup);
@@ -923,7 +933,7 @@ EXPORT_SYMBOL(tcp_v4_md5_do_add);
923static int tcp_v4_md5_add_func(struct sock *sk, struct sock *addr_sk, 933static int tcp_v4_md5_add_func(struct sock *sk, struct sock *addr_sk,
924 u8 *newkey, u8 newkeylen) 934 u8 *newkey, u8 newkeylen)
925{ 935{
926 return tcp_v4_md5_do_add(sk, inet_sk(addr_sk)->daddr, 936 return tcp_v4_md5_do_add(sk, inet_sk(addr_sk)->inet_daddr,
927 newkey, newkeylen); 937 newkey, newkeylen);
928} 938}
929 939
@@ -1089,8 +1099,8 @@ int tcp_v4_md5_hash_skb(char *md5_hash, struct tcp_md5sig_key *key,
1089 __be32 saddr, daddr; 1099 __be32 saddr, daddr;
1090 1100
1091 if (sk) { 1101 if (sk) {
1092 saddr = inet_sk(sk)->saddr; 1102 saddr = inet_sk(sk)->inet_saddr;
1093 daddr = inet_sk(sk)->daddr; 1103 daddr = inet_sk(sk)->inet_daddr;
1094 } else if (req) { 1104 } else if (req) {
1095 saddr = inet_rsk(req)->loc_addr; 1105 saddr = inet_rsk(req)->loc_addr;
1096 daddr = inet_rsk(req)->rmt_addr; 1106 daddr = inet_rsk(req)->rmt_addr;
@@ -1189,10 +1199,11 @@ static int tcp_v4_inbound_md5_hash(struct sock *sk, struct sk_buff *skb)
1189struct request_sock_ops tcp_request_sock_ops __read_mostly = { 1199struct request_sock_ops tcp_request_sock_ops __read_mostly = {
1190 .family = PF_INET, 1200 .family = PF_INET,
1191 .obj_size = sizeof(struct tcp_request_sock), 1201 .obj_size = sizeof(struct tcp_request_sock),
1192 .rtx_syn_ack = tcp_v4_send_synack, 1202 .rtx_syn_ack = tcp_v4_rtx_synack,
1193 .send_ack = tcp_v4_reqsk_send_ack, 1203 .send_ack = tcp_v4_reqsk_send_ack,
1194 .destructor = tcp_v4_reqsk_destructor, 1204 .destructor = tcp_v4_reqsk_destructor,
1195 .send_reset = tcp_v4_send_reset, 1205 .send_reset = tcp_v4_send_reset,
1206 .syn_ack_timeout = tcp_syn_ack_timeout,
1196}; 1207};
1197 1208
1198#ifdef CONFIG_TCP_MD5SIG 1209#ifdef CONFIG_TCP_MD5SIG
@@ -1210,13 +1221,16 @@ static struct timewait_sock_ops tcp_timewait_sock_ops = {
1210 1221
1211int tcp_v4_conn_request(struct sock *sk, struct sk_buff *skb) 1222int tcp_v4_conn_request(struct sock *sk, struct sk_buff *skb)
1212{ 1223{
1213 struct inet_request_sock *ireq; 1224 struct tcp_extend_values tmp_ext;
1214 struct tcp_options_received tmp_opt; 1225 struct tcp_options_received tmp_opt;
1226 u8 *hash_location;
1215 struct request_sock *req; 1227 struct request_sock *req;
1228 struct inet_request_sock *ireq;
1229 struct tcp_sock *tp = tcp_sk(sk);
1230 struct dst_entry *dst = NULL;
1216 __be32 saddr = ip_hdr(skb)->saddr; 1231 __be32 saddr = ip_hdr(skb)->saddr;
1217 __be32 daddr = ip_hdr(skb)->daddr; 1232 __be32 daddr = ip_hdr(skb)->daddr;
1218 __u32 isn = TCP_SKB_CB(skb)->when; 1233 __u32 isn = TCP_SKB_CB(skb)->when;
1219 struct dst_entry *dst = NULL;
1220#ifdef CONFIG_SYN_COOKIES 1234#ifdef CONFIG_SYN_COOKIES
1221 int want_cookie = 0; 1235 int want_cookie = 0;
1222#else 1236#else
@@ -1257,16 +1271,50 @@ int tcp_v4_conn_request(struct sock *sk, struct sk_buff *skb)
1257#endif 1271#endif
1258 1272
1259 tcp_clear_options(&tmp_opt); 1273 tcp_clear_options(&tmp_opt);
1260 tmp_opt.mss_clamp = 536; 1274 tmp_opt.mss_clamp = TCP_MSS_DEFAULT;
1261 tmp_opt.user_mss = tcp_sk(sk)->rx_opt.user_mss; 1275 tmp_opt.user_mss = tp->rx_opt.user_mss;
1276 tcp_parse_options(skb, &tmp_opt, &hash_location, 0);
1277
1278 if (tmp_opt.cookie_plus > 0 &&
1279 tmp_opt.saw_tstamp &&
1280 !tp->rx_opt.cookie_out_never &&
1281 (sysctl_tcp_cookie_size > 0 ||
1282 (tp->cookie_values != NULL &&
1283 tp->cookie_values->cookie_desired > 0))) {
1284 u8 *c;
1285 u32 *mess = &tmp_ext.cookie_bakery[COOKIE_DIGEST_WORDS];
1286 int l = tmp_opt.cookie_plus - TCPOLEN_COOKIE_BASE;
1287
1288 if (tcp_cookie_generator(&tmp_ext.cookie_bakery[0]) != 0)
1289 goto drop_and_release;
1290
1291 /* Secret recipe starts with IP addresses */
1292 *mess++ ^= daddr;
1293 *mess++ ^= saddr;
1262 1294
1263 tcp_parse_options(skb, &tmp_opt, 0); 1295 /* plus variable length Initiator Cookie */
1296 c = (u8 *)mess;
1297 while (l-- > 0)
1298 *c++ ^= *hash_location++;
1299
1300#ifdef CONFIG_SYN_COOKIES
1301 want_cookie = 0; /* not our kind of cookie */
1302#endif
1303 tmp_ext.cookie_out_never = 0; /* false */
1304 tmp_ext.cookie_plus = tmp_opt.cookie_plus;
1305 } else if (!tp->rx_opt.cookie_in_always) {
1306 /* redundant indications, but ensure initialization. */
1307 tmp_ext.cookie_out_never = 1; /* true */
1308 tmp_ext.cookie_plus = 0;
1309 } else {
1310 goto drop_and_release;
1311 }
1312 tmp_ext.cookie_in_always = tp->rx_opt.cookie_in_always;
1264 1313
1265 if (want_cookie && !tmp_opt.saw_tstamp) 1314 if (want_cookie && !tmp_opt.saw_tstamp)
1266 tcp_clear_options(&tmp_opt); 1315 tcp_clear_options(&tmp_opt);
1267 1316
1268 tmp_opt.tstamp_ok = tmp_opt.saw_tstamp; 1317 tmp_opt.tstamp_ok = tmp_opt.saw_tstamp;
1269
1270 tcp_openreq_init(req, &tmp_opt, skb); 1318 tcp_openreq_init(req, &tmp_opt, skb);
1271 1319
1272 ireq = inet_rsk(req); 1320 ireq = inet_rsk(req);
@@ -1304,7 +1352,7 @@ int tcp_v4_conn_request(struct sock *sk, struct sk_buff *skb)
1304 (dst = inet_csk_route_req(sk, req)) != NULL && 1352 (dst = inet_csk_route_req(sk, req)) != NULL &&
1305 (peer = rt_get_peer((struct rtable *)dst)) != NULL && 1353 (peer = rt_get_peer((struct rtable *)dst)) != NULL &&
1306 peer->v4daddr == saddr) { 1354 peer->v4daddr == saddr) {
1307 if (get_seconds() < peer->tcp_ts_stamp + TCP_PAWS_MSL && 1355 if ((u32)get_seconds() - peer->tcp_ts_stamp < TCP_PAWS_MSL &&
1308 (s32)(peer->tcp_ts - req->ts_recent) > 1356 (s32)(peer->tcp_ts - req->ts_recent) >
1309 TCP_PAWS_WINDOW) { 1357 TCP_PAWS_WINDOW) {
1310 NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_PAWSPASSIVEREJECTED); 1358 NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_PAWSPASSIVEREJECTED);
@@ -1333,7 +1381,9 @@ int tcp_v4_conn_request(struct sock *sk, struct sk_buff *skb)
1333 } 1381 }
1334 tcp_rsk(req)->snt_isn = isn; 1382 tcp_rsk(req)->snt_isn = isn;
1335 1383
1336 if (__tcp_v4_send_synack(sk, req, dst) || want_cookie) 1384 if (tcp_v4_send_synack(sk, dst, req,
1385 (struct request_values *)&tmp_ext) ||
1386 want_cookie)
1337 goto drop_and_free; 1387 goto drop_and_free;
1338 1388
1339 inet_csk_reqsk_queue_hash_add(sk, req, TCP_TIMEOUT_INIT); 1389 inet_csk_reqsk_queue_hash_add(sk, req, TCP_TIMEOUT_INIT);
@@ -1380,9 +1430,9 @@ struct sock *tcp_v4_syn_recv_sock(struct sock *sk, struct sk_buff *skb,
1380 newtp = tcp_sk(newsk); 1430 newtp = tcp_sk(newsk);
1381 newinet = inet_sk(newsk); 1431 newinet = inet_sk(newsk);
1382 ireq = inet_rsk(req); 1432 ireq = inet_rsk(req);
1383 newinet->daddr = ireq->rmt_addr; 1433 newinet->inet_daddr = ireq->rmt_addr;
1384 newinet->rcv_saddr = ireq->loc_addr; 1434 newinet->inet_rcv_saddr = ireq->loc_addr;
1385 newinet->saddr = ireq->loc_addr; 1435 newinet->inet_saddr = ireq->loc_addr;
1386 newinet->opt = ireq->opt; 1436 newinet->opt = ireq->opt;
1387 ireq->opt = NULL; 1437 ireq->opt = NULL;
1388 newinet->mc_index = inet_iif(skb); 1438 newinet->mc_index = inet_iif(skb);
@@ -1390,7 +1440,7 @@ struct sock *tcp_v4_syn_recv_sock(struct sock *sk, struct sk_buff *skb,
1390 inet_csk(newsk)->icsk_ext_hdr_len = 0; 1440 inet_csk(newsk)->icsk_ext_hdr_len = 0;
1391 if (newinet->opt) 1441 if (newinet->opt)
1392 inet_csk(newsk)->icsk_ext_hdr_len = newinet->opt->optlen; 1442 inet_csk(newsk)->icsk_ext_hdr_len = newinet->opt->optlen;
1393 newinet->id = newtp->write_seq ^ jiffies; 1443 newinet->inet_id = newtp->write_seq ^ jiffies;
1394 1444
1395 tcp_mtup_init(newsk); 1445 tcp_mtup_init(newsk);
1396 tcp_sync_mss(newsk, dst_mtu(dst)); 1446 tcp_sync_mss(newsk, dst_mtu(dst));
@@ -1403,7 +1453,8 @@ struct sock *tcp_v4_syn_recv_sock(struct sock *sk, struct sk_buff *skb,
1403 1453
1404#ifdef CONFIG_TCP_MD5SIG 1454#ifdef CONFIG_TCP_MD5SIG
1405 /* Copy over the MD5 key from the original socket */ 1455 /* Copy over the MD5 key from the original socket */
1406 if ((key = tcp_v4_md5_do_lookup(sk, newinet->daddr)) != NULL) { 1456 key = tcp_v4_md5_do_lookup(sk, newinet->inet_daddr);
1457 if (key != NULL) {
1407 /* 1458 /*
1408 * We're using one, so create a matching key 1459 * We're using one, so create a matching key
1409 * on the newsk structure. If we fail to get 1460 * on the newsk structure. If we fail to get
@@ -1412,13 +1463,13 @@ struct sock *tcp_v4_syn_recv_sock(struct sock *sk, struct sk_buff *skb,
1412 */ 1463 */
1413 char *newkey = kmemdup(key->key, key->keylen, GFP_ATOMIC); 1464 char *newkey = kmemdup(key->key, key->keylen, GFP_ATOMIC);
1414 if (newkey != NULL) 1465 if (newkey != NULL)
1415 tcp_v4_md5_do_add(newsk, newinet->daddr, 1466 tcp_v4_md5_do_add(newsk, newinet->inet_daddr,
1416 newkey, key->keylen); 1467 newkey, key->keylen);
1417 newsk->sk_route_caps &= ~NETIF_F_GSO_MASK; 1468 newsk->sk_route_caps &= ~NETIF_F_GSO_MASK;
1418 } 1469 }
1419#endif 1470#endif
1420 1471
1421 __inet_hash_nolisten(newsk); 1472 __inet_hash_nolisten(newsk, NULL);
1422 __inet_inherit_port(sk, newsk); 1473 __inet_inherit_port(sk, newsk);
1423 1474
1424 return newsk; 1475 return newsk;
@@ -1610,6 +1661,11 @@ process:
1610 if (sk->sk_state == TCP_TIME_WAIT) 1661 if (sk->sk_state == TCP_TIME_WAIT)
1611 goto do_time_wait; 1662 goto do_time_wait;
1612 1663
1664 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
1665 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
1666 goto discard_and_relse;
1667 }
1668
1613 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) 1669 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb))
1614 goto discard_and_relse; 1670 goto discard_and_relse;
1615 nf_reset(skb); 1671 nf_reset(skb);
@@ -1634,8 +1690,11 @@ process:
1634 if (!tcp_prequeue(sk, skb)) 1690 if (!tcp_prequeue(sk, skb))
1635 ret = tcp_v4_do_rcv(sk, skb); 1691 ret = tcp_v4_do_rcv(sk, skb);
1636 } 1692 }
1637 } else 1693 } else if (unlikely(sk_add_backlog(sk, skb))) {
1638 sk_add_backlog(sk, skb); 1694 bh_unlock_sock(sk);
1695 NET_INC_STATS_BH(net, LINUX_MIB_TCPBACKLOGDROP);
1696 goto discard_and_relse;
1697 }
1639 bh_unlock_sock(sk); 1698 bh_unlock_sock(sk);
1640 1699
1641 sock_put(sk); 1700 sock_put(sk);
@@ -1711,8 +1770,8 @@ int tcp_v4_remember_stamp(struct sock *sk)
1711 struct inet_peer *peer = NULL; 1770 struct inet_peer *peer = NULL;
1712 int release_it = 0; 1771 int release_it = 0;
1713 1772
1714 if (!rt || rt->rt_dst != inet->daddr) { 1773 if (!rt || rt->rt_dst != inet->inet_daddr) {
1715 peer = inet_getpeer(inet->daddr, 1); 1774 peer = inet_getpeer(inet->inet_daddr, 1);
1716 release_it = 1; 1775 release_it = 1;
1717 } else { 1776 } else {
1718 if (!rt->peer) 1777 if (!rt->peer)
@@ -1722,9 +1781,9 @@ int tcp_v4_remember_stamp(struct sock *sk)
1722 1781
1723 if (peer) { 1782 if (peer) {
1724 if ((s32)(peer->tcp_ts - tp->rx_opt.ts_recent) <= 0 || 1783 if ((s32)(peer->tcp_ts - tp->rx_opt.ts_recent) <= 0 ||
1725 (peer->tcp_ts_stamp + TCP_PAWS_MSL < get_seconds() && 1784 ((u32)get_seconds() - peer->tcp_ts_stamp > TCP_PAWS_MSL &&
1726 peer->tcp_ts_stamp <= tp->rx_opt.ts_recent_stamp)) { 1785 peer->tcp_ts_stamp <= (u32)tp->rx_opt.ts_recent_stamp)) {
1727 peer->tcp_ts_stamp = tp->rx_opt.ts_recent_stamp; 1786 peer->tcp_ts_stamp = (u32)tp->rx_opt.ts_recent_stamp;
1728 peer->tcp_ts = tp->rx_opt.ts_recent; 1787 peer->tcp_ts = tp->rx_opt.ts_recent;
1729 } 1788 }
1730 if (release_it) 1789 if (release_it)
@@ -1743,9 +1802,9 @@ int tcp_v4_tw_remember_stamp(struct inet_timewait_sock *tw)
1743 const struct tcp_timewait_sock *tcptw = tcp_twsk((struct sock *)tw); 1802 const struct tcp_timewait_sock *tcptw = tcp_twsk((struct sock *)tw);
1744 1803
1745 if ((s32)(peer->tcp_ts - tcptw->tw_ts_recent) <= 0 || 1804 if ((s32)(peer->tcp_ts - tcptw->tw_ts_recent) <= 0 ||
1746 (peer->tcp_ts_stamp + TCP_PAWS_MSL < get_seconds() && 1805 ((u32)get_seconds() - peer->tcp_ts_stamp > TCP_PAWS_MSL &&
1747 peer->tcp_ts_stamp <= tcptw->tw_ts_recent_stamp)) { 1806 peer->tcp_ts_stamp <= (u32)tcptw->tw_ts_recent_stamp)) {
1748 peer->tcp_ts_stamp = tcptw->tw_ts_recent_stamp; 1807 peer->tcp_ts_stamp = (u32)tcptw->tw_ts_recent_stamp;
1749 peer->tcp_ts = tcptw->tw_ts_recent; 1808 peer->tcp_ts = tcptw->tw_ts_recent;
1750 } 1809 }
1751 inet_putpeer(peer); 1810 inet_putpeer(peer);
@@ -1810,7 +1869,7 @@ static int tcp_v4_init_sock(struct sock *sk)
1810 */ 1869 */
1811 tp->snd_ssthresh = TCP_INFINITE_SSTHRESH; 1870 tp->snd_ssthresh = TCP_INFINITE_SSTHRESH;
1812 tp->snd_cwnd_clamp = ~0; 1871 tp->snd_cwnd_clamp = ~0;
1813 tp->mss_cache = 536; 1872 tp->mss_cache = TCP_MSS_DEFAULT;
1814 1873
1815 tp->reordering = sysctl_tcp_reordering; 1874 tp->reordering = sysctl_tcp_reordering;
1816 icsk->icsk_ca_ops = &tcp_init_congestion_ops; 1875 icsk->icsk_ca_ops = &tcp_init_congestion_ops;
@@ -1826,6 +1885,19 @@ static int tcp_v4_init_sock(struct sock *sk)
1826 tp->af_specific = &tcp_sock_ipv4_specific; 1885 tp->af_specific = &tcp_sock_ipv4_specific;
1827#endif 1886#endif
1828 1887
1888 /* TCP Cookie Transactions */
1889 if (sysctl_tcp_cookie_size > 0) {
1890 /* Default, cookies without s_data_payload. */
1891 tp->cookie_values =
1892 kzalloc(sizeof(*tp->cookie_values),
1893 sk->sk_allocation);
1894 if (tp->cookie_values != NULL)
1895 kref_init(&tp->cookie_values->kref);
1896 }
1897 /* Presumed zeroed, in order of appearance:
1898 * cookie_in_always, cookie_out_never,
1899 * s_data_constant, s_data_in, s_data_out
1900 */
1829 sk->sk_sndbuf = sysctl_tcp_wmem[1]; 1901 sk->sk_sndbuf = sysctl_tcp_wmem[1];
1830 sk->sk_rcvbuf = sysctl_tcp_rmem[1]; 1902 sk->sk_rcvbuf = sysctl_tcp_rmem[1];
1831 1903
@@ -1879,6 +1951,13 @@ void tcp_v4_destroy_sock(struct sock *sk)
1879 sk->sk_sndmsg_page = NULL; 1951 sk->sk_sndmsg_page = NULL;
1880 } 1952 }
1881 1953
1954 /* TCP Cookie Transactions */
1955 if (tp->cookie_values != NULL) {
1956 kref_put(&tp->cookie_values->kref,
1957 tcp_cookie_values_release);
1958 tp->cookie_values = NULL;
1959 }
1960
1882 percpu_counter_dec(&tcp_sockets_allocated); 1961 percpu_counter_dec(&tcp_sockets_allocated);
1883} 1962}
1884 1963
@@ -2000,7 +2079,7 @@ static void *established_get_first(struct seq_file *seq)
2000 struct net *net = seq_file_net(seq); 2079 struct net *net = seq_file_net(seq);
2001 void *rc = NULL; 2080 void *rc = NULL;
2002 2081
2003 for (st->bucket = 0; st->bucket < tcp_hashinfo.ehash_size; ++st->bucket) { 2082 for (st->bucket = 0; st->bucket <= tcp_hashinfo.ehash_mask; ++st->bucket) {
2004 struct sock *sk; 2083 struct sock *sk;
2005 struct hlist_nulls_node *node; 2084 struct hlist_nulls_node *node;
2006 struct inet_timewait_sock *tw; 2085 struct inet_timewait_sock *tw;
@@ -2061,10 +2140,10 @@ get_tw:
2061 st->state = TCP_SEQ_STATE_ESTABLISHED; 2140 st->state = TCP_SEQ_STATE_ESTABLISHED;
2062 2141
2063 /* Look for next non empty bucket */ 2142 /* Look for next non empty bucket */
2064 while (++st->bucket < tcp_hashinfo.ehash_size && 2143 while (++st->bucket <= tcp_hashinfo.ehash_mask &&
2065 empty_bucket(st)) 2144 empty_bucket(st))
2066 ; 2145 ;
2067 if (st->bucket >= tcp_hashinfo.ehash_size) 2146 if (st->bucket > tcp_hashinfo.ehash_mask)
2068 return NULL; 2147 return NULL;
2069 2148
2070 spin_lock_bh(inet_ehash_lockp(&tcp_hashinfo, st->bucket)); 2149 spin_lock_bh(inet_ehash_lockp(&tcp_hashinfo, st->bucket));
@@ -2225,7 +2304,7 @@ static void get_openreq4(struct sock *sk, struct request_sock *req,
2225 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %u %d %p%n", 2304 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %u %d %p%n",
2226 i, 2305 i,
2227 ireq->loc_addr, 2306 ireq->loc_addr,
2228 ntohs(inet_sk(sk)->sport), 2307 ntohs(inet_sk(sk)->inet_sport),
2229 ireq->rmt_addr, 2308 ireq->rmt_addr,
2230 ntohs(ireq->rmt_port), 2309 ntohs(ireq->rmt_port),
2231 TCP_SYN_RECV, 2310 TCP_SYN_RECV,
@@ -2248,10 +2327,11 @@ static void get_tcp4_sock(struct sock *sk, struct seq_file *f, int i, int *len)
2248 struct tcp_sock *tp = tcp_sk(sk); 2327 struct tcp_sock *tp = tcp_sk(sk);
2249 const struct inet_connection_sock *icsk = inet_csk(sk); 2328 const struct inet_connection_sock *icsk = inet_csk(sk);
2250 struct inet_sock *inet = inet_sk(sk); 2329 struct inet_sock *inet = inet_sk(sk);
2251 __be32 dest = inet->daddr; 2330 __be32 dest = inet->inet_daddr;
2252 __be32 src = inet->rcv_saddr; 2331 __be32 src = inet->inet_rcv_saddr;
2253 __u16 destp = ntohs(inet->dport); 2332 __u16 destp = ntohs(inet->inet_dport);
2254 __u16 srcp = ntohs(inet->sport); 2333 __u16 srcp = ntohs(inet->inet_sport);
2334 int rx_queue;
2255 2335
2256 if (icsk->icsk_pending == ICSK_TIME_RETRANS) { 2336 if (icsk->icsk_pending == ICSK_TIME_RETRANS) {
2257 timer_active = 1; 2337 timer_active = 1;
@@ -2267,12 +2347,19 @@ static void get_tcp4_sock(struct sock *sk, struct seq_file *f, int i, int *len)
2267 timer_expires = jiffies; 2347 timer_expires = jiffies;
2268 } 2348 }
2269 2349
2350 if (sk->sk_state == TCP_LISTEN)
2351 rx_queue = sk->sk_ack_backlog;
2352 else
2353 /*
2354 * because we dont lock socket, we might find a transient negative value
2355 */
2356 rx_queue = max_t(int, tp->rcv_nxt - tp->copied_seq, 0);
2357
2270 seq_printf(f, "%4d: %08X:%04X %08X:%04X %02X %08X:%08X %02X:%08lX " 2358 seq_printf(f, "%4d: %08X:%04X %08X:%04X %02X %08X:%08X %02X:%08lX "
2271 "%08X %5d %8d %lu %d %p %lu %lu %u %u %d%n", 2359 "%08X %5d %8d %lu %d %p %lu %lu %u %u %d%n",
2272 i, src, srcp, dest, destp, sk->sk_state, 2360 i, src, srcp, dest, destp, sk->sk_state,
2273 tp->write_seq - tp->snd_una, 2361 tp->write_seq - tp->snd_una,
2274 sk->sk_state == TCP_LISTEN ? sk->sk_ack_backlog : 2362 rx_queue,
2275 (tp->rcv_nxt - tp->copied_seq),
2276 timer_active, 2363 timer_active,
2277 jiffies_to_clock_t(timer_expires - jiffies), 2364 jiffies_to_clock_t(timer_expires - jiffies),
2278 icsk->icsk_retransmits, 2365 icsk->icsk_retransmits,
@@ -2354,12 +2441,12 @@ static struct tcp_seq_afinfo tcp4_seq_afinfo = {
2354 }, 2441 },
2355}; 2442};
2356 2443
2357static int tcp4_proc_init_net(struct net *net) 2444static int __net_init tcp4_proc_init_net(struct net *net)
2358{ 2445{
2359 return tcp_proc_register(net, &tcp4_seq_afinfo); 2446 return tcp_proc_register(net, &tcp4_seq_afinfo);
2360} 2447}
2361 2448
2362static void tcp4_proc_exit_net(struct net *net) 2449static void __net_exit tcp4_proc_exit_net(struct net *net)
2363{ 2450{
2364 tcp_proc_unregister(net, &tcp4_seq_afinfo); 2451 tcp_proc_unregister(net, &tcp4_seq_afinfo);
2365} 2452}
@@ -2463,12 +2550,17 @@ static int __net_init tcp_sk_init(struct net *net)
2463static void __net_exit tcp_sk_exit(struct net *net) 2550static void __net_exit tcp_sk_exit(struct net *net)
2464{ 2551{
2465 inet_ctl_sock_destroy(net->ipv4.tcp_sock); 2552 inet_ctl_sock_destroy(net->ipv4.tcp_sock);
2466 inet_twsk_purge(net, &tcp_hashinfo, &tcp_death_row, AF_INET); 2553}
2554
2555static void __net_exit tcp_sk_exit_batch(struct list_head *net_exit_list)
2556{
2557 inet_twsk_purge(&tcp_hashinfo, &tcp_death_row, AF_INET);
2467} 2558}
2468 2559
2469static struct pernet_operations __net_initdata tcp_sk_ops = { 2560static struct pernet_operations __net_initdata tcp_sk_ops = {
2470 .init = tcp_sk_init, 2561 .init = tcp_sk_init,
2471 .exit = tcp_sk_exit, 2562 .exit = tcp_sk_exit,
2563 .exit_batch = tcp_sk_exit_batch,
2472}; 2564};
2473 2565
2474void __init tcp_v4_init(void) 2566void __init tcp_v4_init(void)
diff --git a/net/ipv4/tcp_lp.c b/net/ipv4/tcp_lp.c
index ce3c41ff50b2..de870377fbba 100644
--- a/net/ipv4/tcp_lp.c
+++ b/net/ipv4/tcp_lp.c
@@ -143,8 +143,8 @@ static u32 tcp_lp_remote_hz_estimator(struct sock *sk)
143 goto out; 143 goto out;
144 144
145 /* we can't calc remote HZ with no different!! */ 145 /* we can't calc remote HZ with no different!! */
146 if (tp->rx_opt.rcv_tsval == lp->remote_ref_time 146 if (tp->rx_opt.rcv_tsval == lp->remote_ref_time ||
147 || tp->rx_opt.rcv_tsecr == lp->local_ref_time) 147 tp->rx_opt.rcv_tsecr == lp->local_ref_time)
148 goto out; 148 goto out;
149 149
150 m = HZ * (tp->rx_opt.rcv_tsval - 150 m = HZ * (tp->rx_opt.rcv_tsval -
diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
index 4c03598ed924..5fabff9ac6d6 100644
--- a/net/ipv4/tcp_minisocks.c
+++ b/net/ipv4/tcp_minisocks.c
@@ -20,19 +20,14 @@
20 20
21#include <linux/mm.h> 21#include <linux/mm.h>
22#include <linux/module.h> 22#include <linux/module.h>
23#include <linux/slab.h>
23#include <linux/sysctl.h> 24#include <linux/sysctl.h>
24#include <linux/workqueue.h> 25#include <linux/workqueue.h>
25#include <net/tcp.h> 26#include <net/tcp.h>
26#include <net/inet_common.h> 27#include <net/inet_common.h>
27#include <net/xfrm.h> 28#include <net/xfrm.h>
28 29
29#ifdef CONFIG_SYSCTL 30int sysctl_tcp_syncookies __read_mostly = 1;
30#define SYNC_INIT 0 /* let the user enable it */
31#else
32#define SYNC_INIT 1
33#endif
34
35int sysctl_tcp_syncookies __read_mostly = SYNC_INIT;
36EXPORT_SYMBOL(sysctl_tcp_syncookies); 31EXPORT_SYMBOL(sysctl_tcp_syncookies);
37 32
38int sysctl_tcp_abort_on_overflow __read_mostly; 33int sysctl_tcp_abort_on_overflow __read_mostly;
@@ -96,13 +91,14 @@ enum tcp_tw_status
96tcp_timewait_state_process(struct inet_timewait_sock *tw, struct sk_buff *skb, 91tcp_timewait_state_process(struct inet_timewait_sock *tw, struct sk_buff *skb,
97 const struct tcphdr *th) 92 const struct tcphdr *th)
98{ 93{
99 struct tcp_timewait_sock *tcptw = tcp_twsk((struct sock *)tw);
100 struct tcp_options_received tmp_opt; 94 struct tcp_options_received tmp_opt;
95 u8 *hash_location;
96 struct tcp_timewait_sock *tcptw = tcp_twsk((struct sock *)tw);
101 int paws_reject = 0; 97 int paws_reject = 0;
102 98
103 tmp_opt.saw_tstamp = 0; 99 tmp_opt.saw_tstamp = 0;
104 if (th->doff > (sizeof(*th) >> 2) && tcptw->tw_ts_recent_stamp) { 100 if (th->doff > (sizeof(*th) >> 2) && tcptw->tw_ts_recent_stamp) {
105 tcp_parse_options(skb, &tmp_opt, 0); 101 tcp_parse_options(skb, &tmp_opt, &hash_location, 0);
106 102
107 if (tmp_opt.saw_tstamp) { 103 if (tmp_opt.saw_tstamp) {
108 tmp_opt.ts_recent = tcptw->tw_ts_recent; 104 tmp_opt.ts_recent = tcptw->tw_ts_recent;
@@ -389,14 +385,43 @@ struct sock *tcp_create_openreq_child(struct sock *sk, struct request_sock *req,
389 const struct inet_request_sock *ireq = inet_rsk(req); 385 const struct inet_request_sock *ireq = inet_rsk(req);
390 struct tcp_request_sock *treq = tcp_rsk(req); 386 struct tcp_request_sock *treq = tcp_rsk(req);
391 struct inet_connection_sock *newicsk = inet_csk(newsk); 387 struct inet_connection_sock *newicsk = inet_csk(newsk);
392 struct tcp_sock *newtp; 388 struct tcp_sock *newtp = tcp_sk(newsk);
389 struct tcp_sock *oldtp = tcp_sk(sk);
390 struct tcp_cookie_values *oldcvp = oldtp->cookie_values;
391
392 /* TCP Cookie Transactions require space for the cookie pair,
393 * as it differs for each connection. There is no need to
394 * copy any s_data_payload stored at the original socket.
395 * Failure will prevent resuming the connection.
396 *
397 * Presumed copied, in order of appearance:
398 * cookie_in_always, cookie_out_never
399 */
400 if (oldcvp != NULL) {
401 struct tcp_cookie_values *newcvp =
402 kzalloc(sizeof(*newtp->cookie_values),
403 GFP_ATOMIC);
404
405 if (newcvp != NULL) {
406 kref_init(&newcvp->kref);
407 newcvp->cookie_desired =
408 oldcvp->cookie_desired;
409 newtp->cookie_values = newcvp;
410 } else {
411 /* Not Yet Implemented */
412 newtp->cookie_values = NULL;
413 }
414 }
393 415
394 /* Now setup tcp_sock */ 416 /* Now setup tcp_sock */
395 newtp = tcp_sk(newsk);
396 newtp->pred_flags = 0; 417 newtp->pred_flags = 0;
397 newtp->rcv_wup = newtp->copied_seq = newtp->rcv_nxt = treq->rcv_isn + 1; 418
398 newtp->snd_sml = newtp->snd_una = newtp->snd_nxt = treq->snt_isn + 1; 419 newtp->rcv_wup = newtp->copied_seq =
399 newtp->snd_up = treq->snt_isn + 1; 420 newtp->rcv_nxt = treq->rcv_isn + 1;
421
422 newtp->snd_sml = newtp->snd_una =
423 newtp->snd_nxt = newtp->snd_up =
424 treq->snt_isn + 1 + tcp_s_data_size(oldtp);
400 425
401 tcp_prequeue_init(newtp); 426 tcp_prequeue_init(newtp);
402 427
@@ -429,8 +454,8 @@ struct sock *tcp_create_openreq_child(struct sock *sk, struct request_sock *req,
429 tcp_set_ca_state(newsk, TCP_CA_Open); 454 tcp_set_ca_state(newsk, TCP_CA_Open);
430 tcp_init_xmit_timers(newsk); 455 tcp_init_xmit_timers(newsk);
431 skb_queue_head_init(&newtp->out_of_order_queue); 456 skb_queue_head_init(&newtp->out_of_order_queue);
432 newtp->write_seq = treq->snt_isn + 1; 457 newtp->write_seq = newtp->pushed_seq =
433 newtp->pushed_seq = newtp->write_seq; 458 treq->snt_isn + 1 + tcp_s_data_size(oldtp);
434 459
435 newtp->rx_opt.saw_tstamp = 0; 460 newtp->rx_opt.saw_tstamp = 0;
436 461
@@ -476,7 +501,7 @@ struct sock *tcp_create_openreq_child(struct sock *sk, struct request_sock *req,
476 if (newtp->af_specific->md5_lookup(sk, newsk)) 501 if (newtp->af_specific->md5_lookup(sk, newsk))
477 newtp->tcp_header_len += TCPOLEN_MD5SIG_ALIGNED; 502 newtp->tcp_header_len += TCPOLEN_MD5SIG_ALIGNED;
478#endif 503#endif
479 if (skb->len >= TCP_MIN_RCVMSS+newtp->tcp_header_len) 504 if (skb->len >= TCP_MSS_DEFAULT + newtp->tcp_header_len)
480 newicsk->icsk_ack.last_seg_size = skb->len - newtp->tcp_header_len; 505 newicsk->icsk_ack.last_seg_size = skb->len - newtp->tcp_header_len;
481 newtp->rx_opt.mss_clamp = req->mss; 506 newtp->rx_opt.mss_clamp = req->mss;
482 TCP_ECN_openreq_child(newtp, req); 507 TCP_ECN_openreq_child(newtp, req);
@@ -495,15 +520,16 @@ struct sock *tcp_check_req(struct sock *sk, struct sk_buff *skb,
495 struct request_sock *req, 520 struct request_sock *req,
496 struct request_sock **prev) 521 struct request_sock **prev)
497{ 522{
523 struct tcp_options_received tmp_opt;
524 u8 *hash_location;
525 struct sock *child;
498 const struct tcphdr *th = tcp_hdr(skb); 526 const struct tcphdr *th = tcp_hdr(skb);
499 __be32 flg = tcp_flag_word(th) & (TCP_FLAG_RST|TCP_FLAG_SYN|TCP_FLAG_ACK); 527 __be32 flg = tcp_flag_word(th) & (TCP_FLAG_RST|TCP_FLAG_SYN|TCP_FLAG_ACK);
500 int paws_reject = 0; 528 int paws_reject = 0;
501 struct tcp_options_received tmp_opt;
502 struct sock *child;
503 529
504 tmp_opt.saw_tstamp = 0; 530 tmp_opt.saw_tstamp = 0;
505 if (th->doff > (sizeof(struct tcphdr)>>2)) { 531 if (th->doff > (sizeof(struct tcphdr)>>2)) {
506 tcp_parse_options(skb, &tmp_opt, 0); 532 tcp_parse_options(skb, &tmp_opt, &hash_location, 0);
507 533
508 if (tmp_opt.saw_tstamp) { 534 if (tmp_opt.saw_tstamp) {
509 tmp_opt.ts_recent = req->ts_recent; 535 tmp_opt.ts_recent = req->ts_recent;
@@ -537,7 +563,7 @@ struct sock *tcp_check_req(struct sock *sk, struct sk_buff *skb,
537 * Enforce "SYN-ACK" according to figure 8, figure 6 563 * Enforce "SYN-ACK" according to figure 8, figure 6
538 * of RFC793, fixed by RFC1122. 564 * of RFC793, fixed by RFC1122.
539 */ 565 */
540 req->rsk_ops->rtx_syn_ack(sk, req); 566 req->rsk_ops->rtx_syn_ack(sk, req, NULL);
541 return NULL; 567 return NULL;
542 } 568 }
543 569
@@ -596,7 +622,8 @@ struct sock *tcp_check_req(struct sock *sk, struct sk_buff *skb,
596 * Invalid ACK: reset will be sent by listening socket 622 * Invalid ACK: reset will be sent by listening socket
597 */ 623 */
598 if ((flg & TCP_FLAG_ACK) && 624 if ((flg & TCP_FLAG_ACK) &&
599 (TCP_SKB_CB(skb)->ack_seq != tcp_rsk(req)->snt_isn + 1)) 625 (TCP_SKB_CB(skb)->ack_seq !=
626 tcp_rsk(req)->snt_isn + 1 + tcp_s_data_size(tcp_sk(sk))))
600 return sk; 627 return sk;
601 628
602 /* Also, it would be not so bad idea to check rcv_tsecr, which 629 /* Also, it would be not so bad idea to check rcv_tsecr, which
@@ -702,7 +729,7 @@ int tcp_child_process(struct sock *parent, struct sock *child,
702 * in main socket hash table and lock on listening 729 * in main socket hash table and lock on listening
703 * socket does not protect us more. 730 * socket does not protect us more.
704 */ 731 */
705 sk_add_backlog(child, skb); 732 __sk_add_backlog(child, skb);
706 } 733 }
707 734
708 bh_unlock_sock(child); 735 bh_unlock_sock(child);
diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c
index fcd278a7080e..0dda86e72ad8 100644
--- a/net/ipv4/tcp_output.c
+++ b/net/ipv4/tcp_output.c
@@ -37,6 +37,7 @@
37#include <net/tcp.h> 37#include <net/tcp.h>
38 38
39#include <linux/compiler.h> 39#include <linux/compiler.h>
40#include <linux/gfp.h>
40#include <linux/module.h> 41#include <linux/module.h>
41 42
42/* People can turn this off for buggy TCP's found in printers etc. */ 43/* People can turn this off for buggy TCP's found in printers etc. */
@@ -59,6 +60,10 @@ int sysctl_tcp_base_mss __read_mostly = 512;
59/* By default, RFC2861 behavior. */ 60/* By default, RFC2861 behavior. */
60int sysctl_tcp_slow_start_after_idle __read_mostly = 1; 61int sysctl_tcp_slow_start_after_idle __read_mostly = 1;
61 62
63int sysctl_tcp_cookie_size __read_mostly = 0; /* TCP_COOKIE_MAX */
64EXPORT_SYMBOL_GPL(sysctl_tcp_cookie_size);
65
66
62/* Account for new data that has been sent to the network. */ 67/* Account for new data that has been sent to the network. */
63static void tcp_event_new_data_sent(struct sock *sk, struct sk_buff *skb) 68static void tcp_event_new_data_sent(struct sock *sk, struct sk_buff *skb)
64{ 69{
@@ -179,7 +184,8 @@ static inline void tcp_event_ack_sent(struct sock *sk, unsigned int pkts)
179 */ 184 */
180void tcp_select_initial_window(int __space, __u32 mss, 185void tcp_select_initial_window(int __space, __u32 mss,
181 __u32 *rcv_wnd, __u32 *window_clamp, 186 __u32 *rcv_wnd, __u32 *window_clamp,
182 int wscale_ok, __u8 *rcv_wscale) 187 int wscale_ok, __u8 *rcv_wscale,
188 __u32 init_rcv_wnd)
183{ 189{
184 unsigned int space = (__space < 0 ? 0 : __space); 190 unsigned int space = (__space < 0 ? 0 : __space);
185 191
@@ -228,7 +234,13 @@ void tcp_select_initial_window(int __space, __u32 mss,
228 init_cwnd = 2; 234 init_cwnd = 2;
229 else if (mss > 1460) 235 else if (mss > 1460)
230 init_cwnd = 3; 236 init_cwnd = 3;
231 if (*rcv_wnd > init_cwnd * mss) 237 /* when initializing use the value from init_rcv_wnd
238 * rather than the default from above
239 */
240 if (init_rcv_wnd &&
241 (*rcv_wnd > init_rcv_wnd * mss))
242 *rcv_wnd = init_rcv_wnd * mss;
243 else if (*rcv_wnd > init_cwnd * mss)
232 *rcv_wnd = init_cwnd * mss; 244 *rcv_wnd = init_cwnd * mss;
233 } 245 }
234 246
@@ -362,15 +374,45 @@ static inline int tcp_urg_mode(const struct tcp_sock *tp)
362#define OPTION_TS (1 << 1) 374#define OPTION_TS (1 << 1)
363#define OPTION_MD5 (1 << 2) 375#define OPTION_MD5 (1 << 2)
364#define OPTION_WSCALE (1 << 3) 376#define OPTION_WSCALE (1 << 3)
377#define OPTION_COOKIE_EXTENSION (1 << 4)
365 378
366struct tcp_out_options { 379struct tcp_out_options {
367 u8 options; /* bit field of OPTION_* */ 380 u8 options; /* bit field of OPTION_* */
368 u8 ws; /* window scale, 0 to disable */ 381 u8 ws; /* window scale, 0 to disable */
369 u8 num_sack_blocks; /* number of SACK blocks to include */ 382 u8 num_sack_blocks; /* number of SACK blocks to include */
383 u8 hash_size; /* bytes in hash_location */
370 u16 mss; /* 0 to disable */ 384 u16 mss; /* 0 to disable */
371 __u32 tsval, tsecr; /* need to include OPTION_TS */ 385 __u32 tsval, tsecr; /* need to include OPTION_TS */
386 __u8 *hash_location; /* temporary pointer, overloaded */
372}; 387};
373 388
389/* The sysctl int routines are generic, so check consistency here.
390 */
391static u8 tcp_cookie_size_check(u8 desired)
392{
393 if (desired > 0) {
394 /* previously specified */
395 return desired;
396 }
397 if (sysctl_tcp_cookie_size <= 0) {
398 /* no default specified */
399 return 0;
400 }
401 if (sysctl_tcp_cookie_size <= TCP_COOKIE_MIN) {
402 /* value too small, specify minimum */
403 return TCP_COOKIE_MIN;
404 }
405 if (sysctl_tcp_cookie_size >= TCP_COOKIE_MAX) {
406 /* value too large, specify maximum */
407 return TCP_COOKIE_MAX;
408 }
409 if (0x1 & sysctl_tcp_cookie_size) {
410 /* 8-bit multiple, illegal, fix it */
411 return (u8)(sysctl_tcp_cookie_size + 0x1);
412 }
413 return (u8)sysctl_tcp_cookie_size;
414}
415
374/* Write previously computed TCP options to the packet. 416/* Write previously computed TCP options to the packet.
375 * 417 *
376 * Beware: Something in the Internet is very sensitive to the ordering of 418 * Beware: Something in the Internet is very sensitive to the ordering of
@@ -385,17 +427,34 @@ struct tcp_out_options {
385 * (but it may well be that other scenarios fail similarly). 427 * (but it may well be that other scenarios fail similarly).
386 */ 428 */
387static void tcp_options_write(__be32 *ptr, struct tcp_sock *tp, 429static void tcp_options_write(__be32 *ptr, struct tcp_sock *tp,
388 const struct tcp_out_options *opts, 430 struct tcp_out_options *opts)
389 __u8 **md5_hash) { 431{
390 if (unlikely(OPTION_MD5 & opts->options)) { 432 u8 options = opts->options; /* mungable copy */
391 *ptr++ = htonl((TCPOPT_NOP << 24) | 433
392 (TCPOPT_NOP << 16) | 434 /* Having both authentication and cookies for security is redundant,
393 (TCPOPT_MD5SIG << 8) | 435 * and there's certainly not enough room. Instead, the cookie-less
394 TCPOLEN_MD5SIG); 436 * extension variant is proposed.
395 *md5_hash = (__u8 *)ptr; 437 *
438 * Consider the pessimal case with authentication. The options
439 * could look like:
440 * COOKIE|MD5(20) + MSS(4) + SACK|TS(12) + WSCALE(4) == 40
441 */
442 if (unlikely(OPTION_MD5 & options)) {
443 if (unlikely(OPTION_COOKIE_EXTENSION & options)) {
444 *ptr++ = htonl((TCPOPT_COOKIE << 24) |
445 (TCPOLEN_COOKIE_BASE << 16) |
446 (TCPOPT_MD5SIG << 8) |
447 TCPOLEN_MD5SIG);
448 } else {
449 *ptr++ = htonl((TCPOPT_NOP << 24) |
450 (TCPOPT_NOP << 16) |
451 (TCPOPT_MD5SIG << 8) |
452 TCPOLEN_MD5SIG);
453 }
454 options &= ~OPTION_COOKIE_EXTENSION;
455 /* overload cookie hash location */
456 opts->hash_location = (__u8 *)ptr;
396 ptr += 4; 457 ptr += 4;
397 } else {
398 *md5_hash = NULL;
399 } 458 }
400 459
401 if (unlikely(opts->mss)) { 460 if (unlikely(opts->mss)) {
@@ -404,12 +463,13 @@ static void tcp_options_write(__be32 *ptr, struct tcp_sock *tp,
404 opts->mss); 463 opts->mss);
405 } 464 }
406 465
407 if (likely(OPTION_TS & opts->options)) { 466 if (likely(OPTION_TS & options)) {
408 if (unlikely(OPTION_SACK_ADVERTISE & opts->options)) { 467 if (unlikely(OPTION_SACK_ADVERTISE & options)) {
409 *ptr++ = htonl((TCPOPT_SACK_PERM << 24) | 468 *ptr++ = htonl((TCPOPT_SACK_PERM << 24) |
410 (TCPOLEN_SACK_PERM << 16) | 469 (TCPOLEN_SACK_PERM << 16) |
411 (TCPOPT_TIMESTAMP << 8) | 470 (TCPOPT_TIMESTAMP << 8) |
412 TCPOLEN_TIMESTAMP); 471 TCPOLEN_TIMESTAMP);
472 options &= ~OPTION_SACK_ADVERTISE;
413 } else { 473 } else {
414 *ptr++ = htonl((TCPOPT_NOP << 24) | 474 *ptr++ = htonl((TCPOPT_NOP << 24) |
415 (TCPOPT_NOP << 16) | 475 (TCPOPT_NOP << 16) |
@@ -420,15 +480,52 @@ static void tcp_options_write(__be32 *ptr, struct tcp_sock *tp,
420 *ptr++ = htonl(opts->tsecr); 480 *ptr++ = htonl(opts->tsecr);
421 } 481 }
422 482
423 if (unlikely(OPTION_SACK_ADVERTISE & opts->options && 483 /* Specification requires after timestamp, so do it now.
424 !(OPTION_TS & opts->options))) { 484 *
485 * Consider the pessimal case without authentication. The options
486 * could look like:
487 * MSS(4) + SACK|TS(12) + COOKIE(20) + WSCALE(4) == 40
488 */
489 if (unlikely(OPTION_COOKIE_EXTENSION & options)) {
490 __u8 *cookie_copy = opts->hash_location;
491 u8 cookie_size = opts->hash_size;
492
493 /* 8-bit multiple handled in tcp_cookie_size_check() above,
494 * and elsewhere.
495 */
496 if (0x2 & cookie_size) {
497 __u8 *p = (__u8 *)ptr;
498
499 /* 16-bit multiple */
500 *p++ = TCPOPT_COOKIE;
501 *p++ = TCPOLEN_COOKIE_BASE + cookie_size;
502 *p++ = *cookie_copy++;
503 *p++ = *cookie_copy++;
504 ptr++;
505 cookie_size -= 2;
506 } else {
507 /* 32-bit multiple */
508 *ptr++ = htonl(((TCPOPT_NOP << 24) |
509 (TCPOPT_NOP << 16) |
510 (TCPOPT_COOKIE << 8) |
511 TCPOLEN_COOKIE_BASE) +
512 cookie_size);
513 }
514
515 if (cookie_size > 0) {
516 memcpy(ptr, cookie_copy, cookie_size);
517 ptr += (cookie_size / 4);
518 }
519 }
520
521 if (unlikely(OPTION_SACK_ADVERTISE & options)) {
425 *ptr++ = htonl((TCPOPT_NOP << 24) | 522 *ptr++ = htonl((TCPOPT_NOP << 24) |
426 (TCPOPT_NOP << 16) | 523 (TCPOPT_NOP << 16) |
427 (TCPOPT_SACK_PERM << 8) | 524 (TCPOPT_SACK_PERM << 8) |
428 TCPOLEN_SACK_PERM); 525 TCPOLEN_SACK_PERM);
429 } 526 }
430 527
431 if (unlikely(OPTION_WSCALE & opts->options)) { 528 if (unlikely(OPTION_WSCALE & options)) {
432 *ptr++ = htonl((TCPOPT_NOP << 24) | 529 *ptr++ = htonl((TCPOPT_NOP << 24) |
433 (TCPOPT_WINDOW << 16) | 530 (TCPOPT_WINDOW << 16) |
434 (TCPOLEN_WINDOW << 8) | 531 (TCPOLEN_WINDOW << 8) |
@@ -463,13 +560,17 @@ static unsigned tcp_syn_options(struct sock *sk, struct sk_buff *skb,
463 struct tcp_out_options *opts, 560 struct tcp_out_options *opts,
464 struct tcp_md5sig_key **md5) { 561 struct tcp_md5sig_key **md5) {
465 struct tcp_sock *tp = tcp_sk(sk); 562 struct tcp_sock *tp = tcp_sk(sk);
466 unsigned size = 0; 563 struct tcp_cookie_values *cvp = tp->cookie_values;
564 unsigned remaining = MAX_TCP_OPTION_SPACE;
565 u8 cookie_size = (!tp->rx_opt.cookie_out_never && cvp != NULL) ?
566 tcp_cookie_size_check(cvp->cookie_desired) :
567 0;
467 568
468#ifdef CONFIG_TCP_MD5SIG 569#ifdef CONFIG_TCP_MD5SIG
469 *md5 = tp->af_specific->md5_lookup(sk, sk); 570 *md5 = tp->af_specific->md5_lookup(sk, sk);
470 if (*md5) { 571 if (*md5) {
471 opts->options |= OPTION_MD5; 572 opts->options |= OPTION_MD5;
472 size += TCPOLEN_MD5SIG_ALIGNED; 573 remaining -= TCPOLEN_MD5SIG_ALIGNED;
473 } 574 }
474#else 575#else
475 *md5 = NULL; 576 *md5 = NULL;
@@ -485,26 +586,72 @@ static unsigned tcp_syn_options(struct sock *sk, struct sk_buff *skb,
485 * SACKs don't matter, we never delay an ACK when we have any of those 586 * SACKs don't matter, we never delay an ACK when we have any of those
486 * going out. */ 587 * going out. */
487 opts->mss = tcp_advertise_mss(sk); 588 opts->mss = tcp_advertise_mss(sk);
488 size += TCPOLEN_MSS_ALIGNED; 589 remaining -= TCPOLEN_MSS_ALIGNED;
489 590
490 if (likely(sysctl_tcp_timestamps && *md5 == NULL)) { 591 if (likely(sysctl_tcp_timestamps && *md5 == NULL)) {
491 opts->options |= OPTION_TS; 592 opts->options |= OPTION_TS;
492 opts->tsval = TCP_SKB_CB(skb)->when; 593 opts->tsval = TCP_SKB_CB(skb)->when;
493 opts->tsecr = tp->rx_opt.ts_recent; 594 opts->tsecr = tp->rx_opt.ts_recent;
494 size += TCPOLEN_TSTAMP_ALIGNED; 595 remaining -= TCPOLEN_TSTAMP_ALIGNED;
495 } 596 }
496 if (likely(sysctl_tcp_window_scaling)) { 597 if (likely(sysctl_tcp_window_scaling)) {
497 opts->ws = tp->rx_opt.rcv_wscale; 598 opts->ws = tp->rx_opt.rcv_wscale;
498 opts->options |= OPTION_WSCALE; 599 opts->options |= OPTION_WSCALE;
499 size += TCPOLEN_WSCALE_ALIGNED; 600 remaining -= TCPOLEN_WSCALE_ALIGNED;
500 } 601 }
501 if (likely(sysctl_tcp_sack)) { 602 if (likely(sysctl_tcp_sack)) {
502 opts->options |= OPTION_SACK_ADVERTISE; 603 opts->options |= OPTION_SACK_ADVERTISE;
503 if (unlikely(!(OPTION_TS & opts->options))) 604 if (unlikely(!(OPTION_TS & opts->options)))
504 size += TCPOLEN_SACKPERM_ALIGNED; 605 remaining -= TCPOLEN_SACKPERM_ALIGNED;
505 } 606 }
506 607
507 return size; 608 /* Note that timestamps are required by the specification.
609 *
610 * Odd numbers of bytes are prohibited by the specification, ensuring
611 * that the cookie is 16-bit aligned, and the resulting cookie pair is
612 * 32-bit aligned.
613 */
614 if (*md5 == NULL &&
615 (OPTION_TS & opts->options) &&
616 cookie_size > 0) {
617 int need = TCPOLEN_COOKIE_BASE + cookie_size;
618
619 if (0x2 & need) {
620 /* 32-bit multiple */
621 need += 2; /* NOPs */
622
623 if (need > remaining) {
624 /* try shrinking cookie to fit */
625 cookie_size -= 2;
626 need -= 4;
627 }
628 }
629 while (need > remaining && TCP_COOKIE_MIN <= cookie_size) {
630 cookie_size -= 4;
631 need -= 4;
632 }
633 if (TCP_COOKIE_MIN <= cookie_size) {
634 opts->options |= OPTION_COOKIE_EXTENSION;
635 opts->hash_location = (__u8 *)&cvp->cookie_pair[0];
636 opts->hash_size = cookie_size;
637
638 /* Remember for future incarnations. */
639 cvp->cookie_desired = cookie_size;
640
641 if (cvp->cookie_desired != cvp->cookie_pair_size) {
642 /* Currently use random bytes as a nonce,
643 * assuming these are completely unpredictable
644 * by hostile users of the same system.
645 */
646 get_random_bytes(&cvp->cookie_pair[0],
647 cookie_size);
648 cvp->cookie_pair_size = cookie_size;
649 }
650
651 remaining -= need;
652 }
653 }
654 return MAX_TCP_OPTION_SPACE - remaining;
508} 655}
509 656
510/* Set up TCP options for SYN-ACKs. */ 657/* Set up TCP options for SYN-ACKs. */
@@ -512,48 +659,77 @@ static unsigned tcp_synack_options(struct sock *sk,
512 struct request_sock *req, 659 struct request_sock *req,
513 unsigned mss, struct sk_buff *skb, 660 unsigned mss, struct sk_buff *skb,
514 struct tcp_out_options *opts, 661 struct tcp_out_options *opts,
515 struct tcp_md5sig_key **md5) { 662 struct tcp_md5sig_key **md5,
516 unsigned size = 0; 663 struct tcp_extend_values *xvp)
664{
517 struct inet_request_sock *ireq = inet_rsk(req); 665 struct inet_request_sock *ireq = inet_rsk(req);
518 char doing_ts; 666 unsigned remaining = MAX_TCP_OPTION_SPACE;
667 u8 cookie_plus = (xvp != NULL && !xvp->cookie_out_never) ?
668 xvp->cookie_plus :
669 0;
670 bool doing_ts = ireq->tstamp_ok;
519 671
520#ifdef CONFIG_TCP_MD5SIG 672#ifdef CONFIG_TCP_MD5SIG
521 *md5 = tcp_rsk(req)->af_specific->md5_lookup(sk, req); 673 *md5 = tcp_rsk(req)->af_specific->md5_lookup(sk, req);
522 if (*md5) { 674 if (*md5) {
523 opts->options |= OPTION_MD5; 675 opts->options |= OPTION_MD5;
524 size += TCPOLEN_MD5SIG_ALIGNED; 676 remaining -= TCPOLEN_MD5SIG_ALIGNED;
677
678 /* We can't fit any SACK blocks in a packet with MD5 + TS
679 * options. There was discussion about disabling SACK
680 * rather than TS in order to fit in better with old,
681 * buggy kernels, but that was deemed to be unnecessary.
682 */
683 doing_ts &= !ireq->sack_ok;
525 } 684 }
526#else 685#else
527 *md5 = NULL; 686 *md5 = NULL;
528#endif 687#endif
529 688
530 /* we can't fit any SACK blocks in a packet with MD5 + TS 689 /* We always send an MSS option. */
531 options. There was discussion about disabling SACK rather than TS in
532 order to fit in better with old, buggy kernels, but that was deemed
533 to be unnecessary. */
534 doing_ts = ireq->tstamp_ok && !(*md5 && ireq->sack_ok);
535
536 opts->mss = mss; 690 opts->mss = mss;
537 size += TCPOLEN_MSS_ALIGNED; 691 remaining -= TCPOLEN_MSS_ALIGNED;
538 692
539 if (likely(ireq->wscale_ok)) { 693 if (likely(ireq->wscale_ok)) {
540 opts->ws = ireq->rcv_wscale; 694 opts->ws = ireq->rcv_wscale;
541 opts->options |= OPTION_WSCALE; 695 opts->options |= OPTION_WSCALE;
542 size += TCPOLEN_WSCALE_ALIGNED; 696 remaining -= TCPOLEN_WSCALE_ALIGNED;
543 } 697 }
544 if (likely(doing_ts)) { 698 if (likely(doing_ts)) {
545 opts->options |= OPTION_TS; 699 opts->options |= OPTION_TS;
546 opts->tsval = TCP_SKB_CB(skb)->when; 700 opts->tsval = TCP_SKB_CB(skb)->when;
547 opts->tsecr = req->ts_recent; 701 opts->tsecr = req->ts_recent;
548 size += TCPOLEN_TSTAMP_ALIGNED; 702 remaining -= TCPOLEN_TSTAMP_ALIGNED;
549 } 703 }
550 if (likely(ireq->sack_ok)) { 704 if (likely(ireq->sack_ok)) {
551 opts->options |= OPTION_SACK_ADVERTISE; 705 opts->options |= OPTION_SACK_ADVERTISE;
552 if (unlikely(!doing_ts)) 706 if (unlikely(!doing_ts))
553 size += TCPOLEN_SACKPERM_ALIGNED; 707 remaining -= TCPOLEN_SACKPERM_ALIGNED;
554 } 708 }
555 709
556 return size; 710 /* Similar rationale to tcp_syn_options() applies here, too.
711 * If the <SYN> options fit, the same options should fit now!
712 */
713 if (*md5 == NULL &&
714 doing_ts &&
715 cookie_plus > TCPOLEN_COOKIE_BASE) {
716 int need = cookie_plus; /* has TCPOLEN_COOKIE_BASE */
717
718 if (0x2 & need) {
719 /* 32-bit multiple */
720 need += 2; /* NOPs */
721 }
722 if (need <= remaining) {
723 opts->options |= OPTION_COOKIE_EXTENSION;
724 opts->hash_size = cookie_plus - TCPOLEN_COOKIE_BASE;
725 remaining -= need;
726 } else {
727 /* There's no error return, so flag it. */
728 xvp->cookie_out_never = 1; /* true */
729 opts->hash_size = 0;
730 }
731 }
732 return MAX_TCP_OPTION_SPACE - remaining;
557} 733}
558 734
559/* Compute TCP options for ESTABLISHED sockets. This is not the 735/* Compute TCP options for ESTABLISHED sockets. This is not the
@@ -619,7 +795,6 @@ static int tcp_transmit_skb(struct sock *sk, struct sk_buff *skb, int clone_it,
619 struct tcp_out_options opts; 795 struct tcp_out_options opts;
620 unsigned tcp_options_size, tcp_header_size; 796 unsigned tcp_options_size, tcp_header_size;
621 struct tcp_md5sig_key *md5; 797 struct tcp_md5sig_key *md5;
622 __u8 *md5_hash_location;
623 struct tcphdr *th; 798 struct tcphdr *th;
624 int err; 799 int err;
625 800
@@ -661,8 +836,8 @@ static int tcp_transmit_skb(struct sock *sk, struct sk_buff *skb, int clone_it,
661 836
662 /* Build TCP header and checksum it. */ 837 /* Build TCP header and checksum it. */
663 th = tcp_hdr(skb); 838 th = tcp_hdr(skb);
664 th->source = inet->sport; 839 th->source = inet->inet_sport;
665 th->dest = inet->dport; 840 th->dest = inet->inet_dport;
666 th->seq = htonl(tcb->seq); 841 th->seq = htonl(tcb->seq);
667 th->ack_seq = htonl(tp->rcv_nxt); 842 th->ack_seq = htonl(tp->rcv_nxt);
668 *(((__be16 *)th) + 6) = htons(((tcp_header_size >> 2) << 12) | 843 *(((__be16 *)th) + 6) = htons(((tcp_header_size >> 2) << 12) |
@@ -690,7 +865,7 @@ static int tcp_transmit_skb(struct sock *sk, struct sk_buff *skb, int clone_it,
690 } 865 }
691 } 866 }
692 867
693 tcp_options_write((__be32 *)(th + 1), tp, &opts, &md5_hash_location); 868 tcp_options_write((__be32 *)(th + 1), tp, &opts);
694 if (likely((tcb->flags & TCPCB_FLAG_SYN) == 0)) 869 if (likely((tcb->flags & TCPCB_FLAG_SYN) == 0))
695 TCP_ECN_send(sk, skb, tcp_header_size); 870 TCP_ECN_send(sk, skb, tcp_header_size);
696 871
@@ -698,7 +873,7 @@ static int tcp_transmit_skb(struct sock *sk, struct sk_buff *skb, int clone_it,
698 /* Calculate the MD5 hash, as we have all we need now */ 873 /* Calculate the MD5 hash, as we have all we need now */
699 if (md5) { 874 if (md5) {
700 sk->sk_route_caps &= ~NETIF_F_GSO_MASK; 875 sk->sk_route_caps &= ~NETIF_F_GSO_MASK;
701 tp->af_specific->calc_md5_hash(md5_hash_location, 876 tp->af_specific->calc_md5_hash(opts.hash_location,
702 md5, sk, NULL, skb); 877 md5, sk, NULL, skb);
703 } 878 }
704#endif 879#endif
@@ -1627,11 +1802,6 @@ static int tcp_write_xmit(struct sock *sk, unsigned int mss_now, int nonagle,
1627void __tcp_push_pending_frames(struct sock *sk, unsigned int cur_mss, 1802void __tcp_push_pending_frames(struct sock *sk, unsigned int cur_mss,
1628 int nonagle) 1803 int nonagle)
1629{ 1804{
1630 struct sk_buff *skb = tcp_send_head(sk);
1631
1632 if (!skb)
1633 return;
1634
1635 /* If we are closed, the bytes will have to remain here. 1805 /* If we are closed, the bytes will have to remain here.
1636 * In time closedown will finish, we empty the write queue and 1806 * In time closedown will finish, we empty the write queue and
1637 * all will be happy. 1807 * all will be happy.
@@ -1918,8 +2088,8 @@ int tcp_retransmit_skb(struct sock *sk, struct sk_buff *skb)
1918 * case, when window is shrunk to zero. In this case 2088 * case, when window is shrunk to zero. In this case
1919 * our retransmit serves as a zero window probe. 2089 * our retransmit serves as a zero window probe.
1920 */ 2090 */
1921 if (!before(TCP_SKB_CB(skb)->seq, tcp_wnd_end(tp)) 2091 if (!before(TCP_SKB_CB(skb)->seq, tcp_wnd_end(tp)) &&
1922 && TCP_SKB_CB(skb)->seq != tp->snd_una) 2092 TCP_SKB_CB(skb)->seq != tp->snd_una)
1923 return -EAGAIN; 2093 return -EAGAIN;
1924 2094
1925 if (skb->len > cur_mss) { 2095 if (skb->len > cur_mss) {
@@ -2219,19 +2389,24 @@ int tcp_send_synack(struct sock *sk)
2219 2389
2220/* Prepare a SYN-ACK. */ 2390/* Prepare a SYN-ACK. */
2221struct sk_buff *tcp_make_synack(struct sock *sk, struct dst_entry *dst, 2391struct sk_buff *tcp_make_synack(struct sock *sk, struct dst_entry *dst,
2222 struct request_sock *req) 2392 struct request_sock *req,
2393 struct request_values *rvp)
2223{ 2394{
2395 struct tcp_out_options opts;
2396 struct tcp_extend_values *xvp = tcp_xv(rvp);
2224 struct inet_request_sock *ireq = inet_rsk(req); 2397 struct inet_request_sock *ireq = inet_rsk(req);
2225 struct tcp_sock *tp = tcp_sk(sk); 2398 struct tcp_sock *tp = tcp_sk(sk);
2399 const struct tcp_cookie_values *cvp = tp->cookie_values;
2226 struct tcphdr *th; 2400 struct tcphdr *th;
2227 int tcp_header_size;
2228 struct tcp_out_options opts;
2229 struct sk_buff *skb; 2401 struct sk_buff *skb;
2230 struct tcp_md5sig_key *md5; 2402 struct tcp_md5sig_key *md5;
2231 __u8 *md5_hash_location; 2403 int tcp_header_size;
2232 int mss; 2404 int mss;
2405 int s_data_desired = 0;
2233 2406
2234 skb = sock_wmalloc(sk, MAX_TCP_HEADER + 15, 1, GFP_ATOMIC); 2407 if (cvp != NULL && cvp->s_data_constant && cvp->s_data_desired)
2408 s_data_desired = cvp->s_data_desired;
2409 skb = sock_wmalloc(sk, MAX_TCP_HEADER + 15 + s_data_desired, 1, GFP_ATOMIC);
2235 if (skb == NULL) 2410 if (skb == NULL)
2236 return NULL; 2411 return NULL;
2237 2412
@@ -2254,7 +2429,8 @@ struct sk_buff *tcp_make_synack(struct sock *sk, struct dst_entry *dst,
2254 &req->rcv_wnd, 2429 &req->rcv_wnd,
2255 &req->window_clamp, 2430 &req->window_clamp,
2256 ireq->wscale_ok, 2431 ireq->wscale_ok,
2257 &rcv_wscale); 2432 &rcv_wscale,
2433 dst_metric(dst, RTAX_INITRWND));
2258 ireq->rcv_wscale = rcv_wscale; 2434 ireq->rcv_wscale = rcv_wscale;
2259 } 2435 }
2260 2436
@@ -2266,8 +2442,8 @@ struct sk_buff *tcp_make_synack(struct sock *sk, struct dst_entry *dst,
2266#endif 2442#endif
2267 TCP_SKB_CB(skb)->when = tcp_time_stamp; 2443 TCP_SKB_CB(skb)->when = tcp_time_stamp;
2268 tcp_header_size = tcp_synack_options(sk, req, mss, 2444 tcp_header_size = tcp_synack_options(sk, req, mss,
2269 skb, &opts, &md5) + 2445 skb, &opts, &md5, xvp)
2270 sizeof(struct tcphdr); 2446 + sizeof(*th);
2271 2447
2272 skb_push(skb, tcp_header_size); 2448 skb_push(skb, tcp_header_size);
2273 skb_reset_transport_header(skb); 2449 skb_reset_transport_header(skb);
@@ -2284,19 +2460,54 @@ struct sk_buff *tcp_make_synack(struct sock *sk, struct dst_entry *dst,
2284 */ 2460 */
2285 tcp_init_nondata_skb(skb, tcp_rsk(req)->snt_isn, 2461 tcp_init_nondata_skb(skb, tcp_rsk(req)->snt_isn,
2286 TCPCB_FLAG_SYN | TCPCB_FLAG_ACK); 2462 TCPCB_FLAG_SYN | TCPCB_FLAG_ACK);
2463
2464 if (OPTION_COOKIE_EXTENSION & opts.options) {
2465 if (s_data_desired) {
2466 u8 *buf = skb_put(skb, s_data_desired);
2467
2468 /* copy data directly from the listening socket. */
2469 memcpy(buf, cvp->s_data_payload, s_data_desired);
2470 TCP_SKB_CB(skb)->end_seq += s_data_desired;
2471 }
2472
2473 if (opts.hash_size > 0) {
2474 __u32 workspace[SHA_WORKSPACE_WORDS];
2475 u32 *mess = &xvp->cookie_bakery[COOKIE_DIGEST_WORDS];
2476 u32 *tail = &mess[COOKIE_MESSAGE_WORDS-1];
2477
2478 /* Secret recipe depends on the Timestamp, (future)
2479 * Sequence and Acknowledgment Numbers, Initiator
2480 * Cookie, and others handled by IP variant caller.
2481 */
2482 *tail-- ^= opts.tsval;
2483 *tail-- ^= tcp_rsk(req)->rcv_isn + 1;
2484 *tail-- ^= TCP_SKB_CB(skb)->seq + 1;
2485
2486 /* recommended */
2487 *tail-- ^= ((th->dest << 16) | th->source);
2488 *tail-- ^= (u32)(unsigned long)cvp; /* per sockopt */
2489
2490 sha_transform((__u32 *)&xvp->cookie_bakery[0],
2491 (char *)mess,
2492 &workspace[0]);
2493 opts.hash_location =
2494 (__u8 *)&xvp->cookie_bakery[0];
2495 }
2496 }
2497
2287 th->seq = htonl(TCP_SKB_CB(skb)->seq); 2498 th->seq = htonl(TCP_SKB_CB(skb)->seq);
2288 th->ack_seq = htonl(tcp_rsk(req)->rcv_isn + 1); 2499 th->ack_seq = htonl(tcp_rsk(req)->rcv_isn + 1);
2289 2500
2290 /* RFC1323: The window in SYN & SYN/ACK segments is never scaled. */ 2501 /* RFC1323: The window in SYN & SYN/ACK segments is never scaled. */
2291 th->window = htons(min(req->rcv_wnd, 65535U)); 2502 th->window = htons(min(req->rcv_wnd, 65535U));
2292 tcp_options_write((__be32 *)(th + 1), tp, &opts, &md5_hash_location); 2503 tcp_options_write((__be32 *)(th + 1), tp, &opts);
2293 th->doff = (tcp_header_size >> 2); 2504 th->doff = (tcp_header_size >> 2);
2294 TCP_INC_STATS(sock_net(sk), TCP_MIB_OUTSEGS); 2505 TCP_INC_STATS(sock_net(sk), TCP_MIB_OUTSEGS);
2295 2506
2296#ifdef CONFIG_TCP_MD5SIG 2507#ifdef CONFIG_TCP_MD5SIG
2297 /* Okay, we have all we need - do the md5 hash if needed */ 2508 /* Okay, we have all we need - do the md5 hash if needed */
2298 if (md5) { 2509 if (md5) {
2299 tcp_rsk(req)->af_specific->calc_md5_hash(md5_hash_location, 2510 tcp_rsk(req)->af_specific->calc_md5_hash(opts.hash_location,
2300 md5, NULL, req, skb); 2511 md5, NULL, req, skb);
2301 } 2512 }
2302#endif 2513#endif
@@ -2342,7 +2553,8 @@ static void tcp_connect_init(struct sock *sk)
2342 &tp->rcv_wnd, 2553 &tp->rcv_wnd,
2343 &tp->window_clamp, 2554 &tp->window_clamp,
2344 sysctl_tcp_window_scaling, 2555 sysctl_tcp_window_scaling,
2345 &rcv_wscale); 2556 &rcv_wscale,
2557 dst_metric(dst, RTAX_INITRWND));
2346 2558
2347 tp->rx_opt.rcv_wscale = rcv_wscale; 2559 tp->rx_opt.rcv_wscale = rcv_wscale;
2348 tp->rcv_ssthresh = tp->rcv_wnd; 2560 tp->rcv_ssthresh = tp->rcv_wnd;
diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
index 59f5b5e7c566..f8efada580e8 100644
--- a/net/ipv4/tcp_probe.c
+++ b/net/ipv4/tcp_probe.c
@@ -22,6 +22,7 @@
22#include <linux/kprobes.h> 22#include <linux/kprobes.h>
23#include <linux/socket.h> 23#include <linux/socket.h>
24#include <linux/tcp.h> 24#include <linux/tcp.h>
25#include <linux/slab.h>
25#include <linux/proc_fs.h> 26#include <linux/proc_fs.h>
26#include <linux/module.h> 27#include <linux/module.h>
27#include <linux/ktime.h> 28#include <linux/ktime.h>
@@ -39,9 +40,9 @@ static int port __read_mostly = 0;
39MODULE_PARM_DESC(port, "Port to match (0=all)"); 40MODULE_PARM_DESC(port, "Port to match (0=all)");
40module_param(port, int, 0); 41module_param(port, int, 0);
41 42
42static int bufsize __read_mostly = 4096; 43static unsigned int bufsize __read_mostly = 4096;
43MODULE_PARM_DESC(bufsize, "Log buffer size in packets (4096)"); 44MODULE_PARM_DESC(bufsize, "Log buffer size in packets (4096)");
44module_param(bufsize, int, 0); 45module_param(bufsize, uint, 0);
45 46
46static int full __read_mostly; 47static int full __read_mostly;
47MODULE_PARM_DESC(full, "Full log (1=every ack packet received, 0=only cwnd changes)"); 48MODULE_PARM_DESC(full, "Full log (1=every ack packet received, 0=only cwnd changes)");
@@ -75,12 +76,12 @@ static struct {
75 76
76static inline int tcp_probe_used(void) 77static inline int tcp_probe_used(void)
77{ 78{
78 return (tcp_probe.head - tcp_probe.tail) % bufsize; 79 return (tcp_probe.head - tcp_probe.tail) & (bufsize - 1);
79} 80}
80 81
81static inline int tcp_probe_avail(void) 82static inline int tcp_probe_avail(void)
82{ 83{
83 return bufsize - tcp_probe_used(); 84 return bufsize - tcp_probe_used() - 1;
84} 85}
85 86
86/* 87/*
@@ -94,8 +95,9 @@ static int jtcp_rcv_established(struct sock *sk, struct sk_buff *skb,
94 const struct inet_sock *inet = inet_sk(sk); 95 const struct inet_sock *inet = inet_sk(sk);
95 96
96 /* Only update if port matches */ 97 /* Only update if port matches */
97 if ((port == 0 || ntohs(inet->dport) == port || ntohs(inet->sport) == port) 98 if ((port == 0 || ntohs(inet->inet_dport) == port ||
98 && (full || tp->snd_cwnd != tcp_probe.lastcwnd)) { 99 ntohs(inet->inet_sport) == port) &&
100 (full || tp->snd_cwnd != tcp_probe.lastcwnd)) {
99 101
100 spin_lock(&tcp_probe.lock); 102 spin_lock(&tcp_probe.lock);
101 /* If log fills, just silently drop */ 103 /* If log fills, just silently drop */
@@ -103,10 +105,10 @@ static int jtcp_rcv_established(struct sock *sk, struct sk_buff *skb,
103 struct tcp_log *p = tcp_probe.log + tcp_probe.head; 105 struct tcp_log *p = tcp_probe.log + tcp_probe.head;
104 106
105 p->tstamp = ktime_get(); 107 p->tstamp = ktime_get();
106 p->saddr = inet->saddr; 108 p->saddr = inet->inet_saddr;
107 p->sport = inet->sport; 109 p->sport = inet->inet_sport;
108 p->daddr = inet->daddr; 110 p->daddr = inet->inet_daddr;
109 p->dport = inet->dport; 111 p->dport = inet->inet_dport;
110 p->length = skb->len; 112 p->length = skb->len;
111 p->snd_nxt = tp->snd_nxt; 113 p->snd_nxt = tp->snd_nxt;
112 p->snd_una = tp->snd_una; 114 p->snd_una = tp->snd_una;
@@ -115,7 +117,7 @@ static int jtcp_rcv_established(struct sock *sk, struct sk_buff *skb,
115 p->ssthresh = tcp_current_ssthresh(sk); 117 p->ssthresh = tcp_current_ssthresh(sk);
116 p->srtt = tp->srtt >> 3; 118 p->srtt = tp->srtt >> 3;
117 119
118 tcp_probe.head = (tcp_probe.head + 1) % bufsize; 120 tcp_probe.head = (tcp_probe.head + 1) & (bufsize - 1);
119 } 121 }
120 tcp_probe.lastcwnd = tp->snd_cwnd; 122 tcp_probe.lastcwnd = tp->snd_cwnd;
121 spin_unlock(&tcp_probe.lock); 123 spin_unlock(&tcp_probe.lock);
@@ -148,7 +150,7 @@ static int tcpprobe_open(struct inode * inode, struct file * file)
148static int tcpprobe_sprint(char *tbuf, int n) 150static int tcpprobe_sprint(char *tbuf, int n)
149{ 151{
150 const struct tcp_log *p 152 const struct tcp_log *p
151 = tcp_probe.log + tcp_probe.tail % bufsize; 153 = tcp_probe.log + tcp_probe.tail;
152 struct timespec tv 154 struct timespec tv
153 = ktime_to_timespec(ktime_sub(p->tstamp, tcp_probe.start)); 155 = ktime_to_timespec(ktime_sub(p->tstamp, tcp_probe.start));
154 156
@@ -191,7 +193,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
191 width = tcpprobe_sprint(tbuf, sizeof(tbuf)); 193 width = tcpprobe_sprint(tbuf, sizeof(tbuf));
192 194
193 if (cnt + width < len) 195 if (cnt + width < len)
194 tcp_probe.tail = (tcp_probe.tail + 1) % bufsize; 196 tcp_probe.tail = (tcp_probe.tail + 1) & (bufsize - 1);
195 197
196 spin_unlock_bh(&tcp_probe.lock); 198 spin_unlock_bh(&tcp_probe.lock);
197 199
@@ -221,9 +223,10 @@ static __init int tcpprobe_init(void)
221 init_waitqueue_head(&tcp_probe.wait); 223 init_waitqueue_head(&tcp_probe.wait);
222 spin_lock_init(&tcp_probe.lock); 224 spin_lock_init(&tcp_probe.lock);
223 225
224 if (bufsize < 0) 226 if (bufsize == 0)
225 return -EINVAL; 227 return -EINVAL;
226 228
229 bufsize = roundup_pow_of_two(bufsize);
227 tcp_probe.log = kcalloc(bufsize, sizeof(struct tcp_log), GFP_KERNEL); 230 tcp_probe.log = kcalloc(bufsize, sizeof(struct tcp_log), GFP_KERNEL);
228 if (!tcp_probe.log) 231 if (!tcp_probe.log)
229 goto err0; 232 goto err0;
@@ -235,7 +238,7 @@ static __init int tcpprobe_init(void)
235 if (ret) 238 if (ret)
236 goto err1; 239 goto err1;
237 240
238 pr_info("TCP probe registered (port=%d)\n", port); 241 pr_info("TCP probe registered (port=%d) bufsize=%u\n", port, bufsize);
239 return 0; 242 return 0;
240 err1: 243 err1:
241 proc_net_remove(&init_net, procname); 244 proc_net_remove(&init_net, procname);
diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
index cdb2ca7684d4..8a0ab2977f1f 100644
--- a/net/ipv4/tcp_timer.c
+++ b/net/ipv4/tcp_timer.c
@@ -19,6 +19,7 @@
19 */ 19 */
20 20
21#include <linux/module.h> 21#include <linux/module.h>
22#include <linux/gfp.h>
22#include <net/tcp.h> 23#include <net/tcp.h>
23 24
24int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES; 25int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
@@ -29,6 +30,7 @@ int sysctl_tcp_keepalive_intvl __read_mostly = TCP_KEEPALIVE_INTVL;
29int sysctl_tcp_retries1 __read_mostly = TCP_RETR1; 30int sysctl_tcp_retries1 __read_mostly = TCP_RETR1;
30int sysctl_tcp_retries2 __read_mostly = TCP_RETR2; 31int sysctl_tcp_retries2 __read_mostly = TCP_RETR2;
31int sysctl_tcp_orphan_retries __read_mostly; 32int sysctl_tcp_orphan_retries __read_mostly;
33int sysctl_tcp_thin_linear_timeouts __read_mostly;
32 34
33static void tcp_write_timer(unsigned long); 35static void tcp_write_timer(unsigned long);
34static void tcp_delack_timer(unsigned long); 36static void tcp_delack_timer(unsigned long);
@@ -132,6 +134,35 @@ static void tcp_mtu_probing(struct inet_connection_sock *icsk, struct sock *sk)
132 } 134 }
133} 135}
134 136
137/* This function calculates a "timeout" which is equivalent to the timeout of a
138 * TCP connection after "boundary" unsuccessful, exponentially backed-off
139 * retransmissions with an initial RTO of TCP_RTO_MIN.
140 */
141static bool retransmits_timed_out(struct sock *sk,
142 unsigned int boundary)
143{
144 unsigned int timeout, linear_backoff_thresh;
145 unsigned int start_ts;
146
147 if (!inet_csk(sk)->icsk_retransmits)
148 return false;
149
150 if (unlikely(!tcp_sk(sk)->retrans_stamp))
151 start_ts = TCP_SKB_CB(tcp_write_queue_head(sk))->when;
152 else
153 start_ts = tcp_sk(sk)->retrans_stamp;
154
155 linear_backoff_thresh = ilog2(TCP_RTO_MAX/TCP_RTO_MIN);
156
157 if (boundary <= linear_backoff_thresh)
158 timeout = ((2 << boundary) - 1) * TCP_RTO_MIN;
159 else
160 timeout = ((2 << linear_backoff_thresh) - 1) * TCP_RTO_MIN +
161 (boundary - linear_backoff_thresh) * TCP_RTO_MAX;
162
163 return (tcp_time_stamp - start_ts) >= timeout;
164}
165
135/* A write timeout has occurred. Process the after effects. */ 166/* A write timeout has occurred. Process the after effects. */
136static int tcp_write_timeout(struct sock *sk) 167static int tcp_write_timeout(struct sock *sk)
137{ 168{
@@ -141,14 +172,14 @@ static int tcp_write_timeout(struct sock *sk)
141 172
142 if ((1 << sk->sk_state) & (TCPF_SYN_SENT | TCPF_SYN_RECV)) { 173 if ((1 << sk->sk_state) & (TCPF_SYN_SENT | TCPF_SYN_RECV)) {
143 if (icsk->icsk_retransmits) 174 if (icsk->icsk_retransmits)
144 dst_negative_advice(&sk->sk_dst_cache); 175 dst_negative_advice(&sk->sk_dst_cache, sk);
145 retry_until = icsk->icsk_syn_retries ? : sysctl_tcp_syn_retries; 176 retry_until = icsk->icsk_syn_retries ? : sysctl_tcp_syn_retries;
146 } else { 177 } else {
147 if (retransmits_timed_out(sk, sysctl_tcp_retries1)) { 178 if (retransmits_timed_out(sk, sysctl_tcp_retries1)) {
148 /* Black hole detection */ 179 /* Black hole detection */
149 tcp_mtu_probing(icsk, sk); 180 tcp_mtu_probing(icsk, sk);
150 181
151 dst_negative_advice(&sk->sk_dst_cache); 182 dst_negative_advice(&sk->sk_dst_cache, sk);
152 } 183 }
153 184
154 retry_until = sysctl_tcp_retries2; 185 retry_until = sysctl_tcp_retries2;
@@ -303,15 +334,15 @@ void tcp_retransmit_timer(struct sock *sk)
303 struct inet_sock *inet = inet_sk(sk); 334 struct inet_sock *inet = inet_sk(sk);
304 if (sk->sk_family == AF_INET) { 335 if (sk->sk_family == AF_INET) {
305 LIMIT_NETDEBUG(KERN_DEBUG "TCP: Peer %pI4:%u/%u unexpectedly shrunk window %u:%u (repaired)\n", 336 LIMIT_NETDEBUG(KERN_DEBUG "TCP: Peer %pI4:%u/%u unexpectedly shrunk window %u:%u (repaired)\n",
306 &inet->daddr, ntohs(inet->dport), 337 &inet->inet_daddr, ntohs(inet->inet_dport),
307 inet->num, tp->snd_una, tp->snd_nxt); 338 inet->inet_num, tp->snd_una, tp->snd_nxt);
308 } 339 }
309#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) 340#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
310 else if (sk->sk_family == AF_INET6) { 341 else if (sk->sk_family == AF_INET6) {
311 struct ipv6_pinfo *np = inet6_sk(sk); 342 struct ipv6_pinfo *np = inet6_sk(sk);
312 LIMIT_NETDEBUG(KERN_DEBUG "TCP: Peer %pI6:%u/%u unexpectedly shrunk window %u:%u (repaired)\n", 343 LIMIT_NETDEBUG(KERN_DEBUG "TCP: Peer %pI6:%u/%u unexpectedly shrunk window %u:%u (repaired)\n",
313 &np->daddr, ntohs(inet->dport), 344 &np->daddr, ntohs(inet->inet_dport),
314 inet->num, tp->snd_una, tp->snd_nxt); 345 inet->inet_num, tp->snd_una, tp->snd_nxt);
315 } 346 }
316#endif 347#endif
317#endif 348#endif
@@ -386,7 +417,25 @@ void tcp_retransmit_timer(struct sock *sk)
386 icsk->icsk_retransmits++; 417 icsk->icsk_retransmits++;
387 418
388out_reset_timer: 419out_reset_timer:
389 icsk->icsk_rto = min(icsk->icsk_rto << 1, TCP_RTO_MAX); 420 /* If stream is thin, use linear timeouts. Since 'icsk_backoff' is
421 * used to reset timer, set to 0. Recalculate 'icsk_rto' as this
422 * might be increased if the stream oscillates between thin and thick,
423 * thus the old value might already be too high compared to the value
424 * set by 'tcp_set_rto' in tcp_input.c which resets the rto without
425 * backoff. Limit to TCP_THIN_LINEAR_RETRIES before initiating
426 * exponential backoff behaviour to avoid continue hammering
427 * linear-timeout retransmissions into a black hole
428 */
429 if (sk->sk_state == TCP_ESTABLISHED &&
430 (tp->thin_lto || sysctl_tcp_thin_linear_timeouts) &&
431 tcp_stream_is_thin(tp) &&
432 icsk->icsk_retransmits <= TCP_THIN_LINEAR_RETRIES) {
433 icsk->icsk_backoff = 0;
434 icsk->icsk_rto = min(__tcp_set_rto(tp), TCP_RTO_MAX);
435 } else {
436 /* Use normal (exponential) backoff */
437 icsk->icsk_rto = min(icsk->icsk_rto << 1, TCP_RTO_MAX);
438 }
390 inet_csk_reset_xmit_timer(sk, ICSK_TIME_RETRANS, icsk->icsk_rto, TCP_RTO_MAX); 439 inet_csk_reset_xmit_timer(sk, ICSK_TIME_RETRANS, icsk->icsk_rto, TCP_RTO_MAX);
391 if (retransmits_timed_out(sk, sysctl_tcp_retries1 + 1)) 440 if (retransmits_timed_out(sk, sysctl_tcp_retries1 + 1))
392 __sk_dst_reset(sk); 441 __sk_dst_reset(sk);
@@ -445,6 +494,12 @@ static void tcp_synack_timer(struct sock *sk)
445 TCP_TIMEOUT_INIT, TCP_RTO_MAX); 494 TCP_TIMEOUT_INIT, TCP_RTO_MAX);
446} 495}
447 496
497void tcp_syn_ack_timeout(struct sock *sk, struct request_sock *req)
498{
499 NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_TCPTIMEOUTS);
500}
501EXPORT_SYMBOL(tcp_syn_ack_timeout);
502
448void tcp_set_keepalive(struct sock *sk, int val) 503void tcp_set_keepalive(struct sock *sk, int val)
449{ 504{
450 if ((1 << sk->sk_state) & (TCPF_CLOSE | TCPF_LISTEN)) 505 if ((1 << sk->sk_state) & (TCPF_CLOSE | TCPF_LISTEN))
diff --git a/net/ipv4/tcp_veno.c b/net/ipv4/tcp_veno.c
index e9bbff746488..b612acf76183 100644
--- a/net/ipv4/tcp_veno.c
+++ b/net/ipv4/tcp_veno.c
@@ -165,9 +165,8 @@ static void tcp_veno_cong_avoid(struct sock *sk, u32 ack, u32 in_flight)
165 * every other rtt. 165 * every other rtt.
166 */ 166 */
167 if (tp->snd_cwnd_cnt >= tp->snd_cwnd) { 167 if (tp->snd_cwnd_cnt >= tp->snd_cwnd) {
168 if (veno->inc 168 if (veno->inc &&
169 && tp->snd_cwnd < 169 tp->snd_cwnd < tp->snd_cwnd_clamp) {
170 tp->snd_cwnd_clamp) {
171 tp->snd_cwnd++; 170 tp->snd_cwnd++;
172 veno->inc = 0; 171 veno->inc = 0;
173 } else 172 } else
diff --git a/net/ipv4/tcp_yeah.c b/net/ipv4/tcp_yeah.c
index 66b6821b984e..a0f240358892 100644
--- a/net/ipv4/tcp_yeah.c
+++ b/net/ipv4/tcp_yeah.c
@@ -157,8 +157,8 @@ static void tcp_yeah_cong_avoid(struct sock *sk, u32 ack, u32 in_flight)
157 157
158 if (queue > TCP_YEAH_ALPHA || 158 if (queue > TCP_YEAH_ALPHA ||
159 rtt - yeah->vegas.baseRTT > (yeah->vegas.baseRTT / TCP_YEAH_PHY)) { 159 rtt - yeah->vegas.baseRTT > (yeah->vegas.baseRTT / TCP_YEAH_PHY)) {
160 if (queue > TCP_YEAH_ALPHA 160 if (queue > TCP_YEAH_ALPHA &&
161 && tp->snd_cwnd > yeah->reno_count) { 161 tp->snd_cwnd > yeah->reno_count) {
162 u32 reduction = min(queue / TCP_YEAH_GAMMA , 162 u32 reduction = min(queue / TCP_YEAH_GAMMA ,
163 tp->snd_cwnd >> TCP_YEAH_EPSILON); 163 tp->snd_cwnd >> TCP_YEAH_EPSILON);
164 164
diff --git a/net/ipv4/tunnel4.c b/net/ipv4/tunnel4.c
index 3959e0ca456a..3b3813cc80b9 100644
--- a/net/ipv4/tunnel4.c
+++ b/net/ipv4/tunnel4.c
@@ -8,6 +8,7 @@
8#include <linux/mutex.h> 8#include <linux/mutex.h>
9#include <linux/netdevice.h> 9#include <linux/netdevice.h>
10#include <linux/skbuff.h> 10#include <linux/skbuff.h>
11#include <linux/slab.h>
11#include <net/icmp.h> 12#include <net/icmp.h>
12#include <net/ip.h> 13#include <net/ip.h>
13#include <net/protocol.h> 14#include <net/protocol.h>
diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
index 0fa9f70e4b19..c36522a0f113 100644
--- a/net/ipv4/udp.c
+++ b/net/ipv4/udp.c
@@ -95,6 +95,7 @@
95#include <linux/mm.h> 95#include <linux/mm.h>
96#include <linux/inet.h> 96#include <linux/inet.h>
97#include <linux/netdevice.h> 97#include <linux/netdevice.h>
98#include <linux/slab.h>
98#include <net/tcp_states.h> 99#include <net/tcp_states.h>
99#include <linux/skbuff.h> 100#include <linux/skbuff.h>
100#include <linux/proc_fs.h> 101#include <linux/proc_fs.h>
@@ -106,7 +107,7 @@
106#include <net/xfrm.h> 107#include <net/xfrm.h>
107#include "udp_impl.h" 108#include "udp_impl.h"
108 109
109struct udp_table udp_table; 110struct udp_table udp_table __read_mostly;
110EXPORT_SYMBOL(udp_table); 111EXPORT_SYMBOL(udp_table);
111 112
112int sysctl_udp_mem[3] __read_mostly; 113int sysctl_udp_mem[3] __read_mostly;
@@ -121,28 +122,30 @@ EXPORT_SYMBOL(sysctl_udp_wmem_min);
121atomic_t udp_memory_allocated; 122atomic_t udp_memory_allocated;
122EXPORT_SYMBOL(udp_memory_allocated); 123EXPORT_SYMBOL(udp_memory_allocated);
123 124
124#define PORTS_PER_CHAIN (65536 / UDP_HTABLE_SIZE) 125#define MAX_UDP_PORTS 65536
126#define PORTS_PER_CHAIN (MAX_UDP_PORTS / UDP_HTABLE_SIZE_MIN)
125 127
126static int udp_lib_lport_inuse(struct net *net, __u16 num, 128static int udp_lib_lport_inuse(struct net *net, __u16 num,
127 const struct udp_hslot *hslot, 129 const struct udp_hslot *hslot,
128 unsigned long *bitmap, 130 unsigned long *bitmap,
129 struct sock *sk, 131 struct sock *sk,
130 int (*saddr_comp)(const struct sock *sk1, 132 int (*saddr_comp)(const struct sock *sk1,
131 const struct sock *sk2)) 133 const struct sock *sk2),
134 unsigned int log)
132{ 135{
133 struct sock *sk2; 136 struct sock *sk2;
134 struct hlist_nulls_node *node; 137 struct hlist_nulls_node *node;
135 138
136 sk_nulls_for_each(sk2, node, &hslot->head) 139 sk_nulls_for_each(sk2, node, &hslot->head)
137 if (net_eq(sock_net(sk2), net) && 140 if (net_eq(sock_net(sk2), net) &&
138 sk2 != sk && 141 sk2 != sk &&
139 (bitmap || sk2->sk_hash == num) && 142 (bitmap || udp_sk(sk2)->udp_port_hash == num) &&
140 (!sk2->sk_reuse || !sk->sk_reuse) && 143 (!sk2->sk_reuse || !sk->sk_reuse) &&
141 (!sk2->sk_bound_dev_if || !sk->sk_bound_dev_if 144 (!sk2->sk_bound_dev_if || !sk->sk_bound_dev_if ||
142 || sk2->sk_bound_dev_if == sk->sk_bound_dev_if) && 145 sk2->sk_bound_dev_if == sk->sk_bound_dev_if) &&
143 (*saddr_comp)(sk, sk2)) { 146 (*saddr_comp)(sk, sk2)) {
144 if (bitmap) 147 if (bitmap)
145 __set_bit(sk2->sk_hash / UDP_HTABLE_SIZE, 148 __set_bit(udp_sk(sk2)->udp_port_hash >> log,
146 bitmap); 149 bitmap);
147 else 150 else
148 return 1; 151 return 1;
@@ -150,18 +153,51 @@ static int udp_lib_lport_inuse(struct net *net, __u16 num,
150 return 0; 153 return 0;
151} 154}
152 155
156/*
157 * Note: we still hold spinlock of primary hash chain, so no other writer
158 * can insert/delete a socket with local_port == num
159 */
160static int udp_lib_lport_inuse2(struct net *net, __u16 num,
161 struct udp_hslot *hslot2,
162 struct sock *sk,
163 int (*saddr_comp)(const struct sock *sk1,
164 const struct sock *sk2))
165{
166 struct sock *sk2;
167 struct hlist_nulls_node *node;
168 int res = 0;
169
170 spin_lock(&hslot2->lock);
171 udp_portaddr_for_each_entry(sk2, node, &hslot2->head)
172 if (net_eq(sock_net(sk2), net) &&
173 sk2 != sk &&
174 (udp_sk(sk2)->udp_port_hash == num) &&
175 (!sk2->sk_reuse || !sk->sk_reuse) &&
176 (!sk2->sk_bound_dev_if || !sk->sk_bound_dev_if ||
177 sk2->sk_bound_dev_if == sk->sk_bound_dev_if) &&
178 (*saddr_comp)(sk, sk2)) {
179 res = 1;
180 break;
181 }
182 spin_unlock(&hslot2->lock);
183 return res;
184}
185
153/** 186/**
154 * udp_lib_get_port - UDP/-Lite port lookup for IPv4 and IPv6 187 * udp_lib_get_port - UDP/-Lite port lookup for IPv4 and IPv6
155 * 188 *
156 * @sk: socket struct in question 189 * @sk: socket struct in question
157 * @snum: port number to look up 190 * @snum: port number to look up
158 * @saddr_comp: AF-dependent comparison of bound local IP addresses 191 * @saddr_comp: AF-dependent comparison of bound local IP addresses
192 * @hash2_nulladdr: AF-dependant hash value in secondary hash chains,
193 * with NULL address
159 */ 194 */
160int udp_lib_get_port(struct sock *sk, unsigned short snum, 195int udp_lib_get_port(struct sock *sk, unsigned short snum,
161 int (*saddr_comp)(const struct sock *sk1, 196 int (*saddr_comp)(const struct sock *sk1,
162 const struct sock *sk2)) 197 const struct sock *sk2),
198 unsigned int hash2_nulladdr)
163{ 199{
164 struct udp_hslot *hslot; 200 struct udp_hslot *hslot, *hslot2;
165 struct udp_table *udptable = sk->sk_prot->h.udp_table; 201 struct udp_table *udptable = sk->sk_prot->h.udp_table;
166 int error = 1; 202 int error = 1;
167 struct net *net = sock_net(sk); 203 struct net *net = sock_net(sk);
@@ -180,13 +216,14 @@ int udp_lib_get_port(struct sock *sk, unsigned short snum,
180 /* 216 /*
181 * force rand to be an odd multiple of UDP_HTABLE_SIZE 217 * force rand to be an odd multiple of UDP_HTABLE_SIZE
182 */ 218 */
183 rand = (rand | 1) * UDP_HTABLE_SIZE; 219 rand = (rand | 1) * (udptable->mask + 1);
184 for (last = first + UDP_HTABLE_SIZE; first != last; first++) { 220 last = first + udptable->mask + 1;
185 hslot = &udptable->hash[udp_hashfn(net, first)]; 221 do {
222 hslot = udp_hashslot(udptable, net, first);
186 bitmap_zero(bitmap, PORTS_PER_CHAIN); 223 bitmap_zero(bitmap, PORTS_PER_CHAIN);
187 spin_lock_bh(&hslot->lock); 224 spin_lock_bh(&hslot->lock);
188 udp_lib_lport_inuse(net, snum, hslot, bitmap, sk, 225 udp_lib_lport_inuse(net, snum, hslot, bitmap, sk,
189 saddr_comp); 226 saddr_comp, udptable->log);
190 227
191 snum = first; 228 snum = first;
192 /* 229 /*
@@ -196,25 +233,59 @@ int udp_lib_get_port(struct sock *sk, unsigned short snum,
196 */ 233 */
197 do { 234 do {
198 if (low <= snum && snum <= high && 235 if (low <= snum && snum <= high &&
199 !test_bit(snum / UDP_HTABLE_SIZE, bitmap)) 236 !test_bit(snum >> udptable->log, bitmap))
200 goto found; 237 goto found;
201 snum += rand; 238 snum += rand;
202 } while (snum != first); 239 } while (snum != first);
203 spin_unlock_bh(&hslot->lock); 240 spin_unlock_bh(&hslot->lock);
204 } 241 } while (++first != last);
205 goto fail; 242 goto fail;
206 } else { 243 } else {
207 hslot = &udptable->hash[udp_hashfn(net, snum)]; 244 hslot = udp_hashslot(udptable, net, snum);
208 spin_lock_bh(&hslot->lock); 245 spin_lock_bh(&hslot->lock);
209 if (udp_lib_lport_inuse(net, snum, hslot, NULL, sk, saddr_comp)) 246 if (hslot->count > 10) {
247 int exist;
248 unsigned int slot2 = udp_sk(sk)->udp_portaddr_hash ^ snum;
249
250 slot2 &= udptable->mask;
251 hash2_nulladdr &= udptable->mask;
252
253 hslot2 = udp_hashslot2(udptable, slot2);
254 if (hslot->count < hslot2->count)
255 goto scan_primary_hash;
256
257 exist = udp_lib_lport_inuse2(net, snum, hslot2,
258 sk, saddr_comp);
259 if (!exist && (hash2_nulladdr != slot2)) {
260 hslot2 = udp_hashslot2(udptable, hash2_nulladdr);
261 exist = udp_lib_lport_inuse2(net, snum, hslot2,
262 sk, saddr_comp);
263 }
264 if (exist)
265 goto fail_unlock;
266 else
267 goto found;
268 }
269scan_primary_hash:
270 if (udp_lib_lport_inuse(net, snum, hslot, NULL, sk,
271 saddr_comp, 0))
210 goto fail_unlock; 272 goto fail_unlock;
211 } 273 }
212found: 274found:
213 inet_sk(sk)->num = snum; 275 inet_sk(sk)->inet_num = snum;
214 sk->sk_hash = snum; 276 udp_sk(sk)->udp_port_hash = snum;
277 udp_sk(sk)->udp_portaddr_hash ^= snum;
215 if (sk_unhashed(sk)) { 278 if (sk_unhashed(sk)) {
216 sk_nulls_add_node_rcu(sk, &hslot->head); 279 sk_nulls_add_node_rcu(sk, &hslot->head);
280 hslot->count++;
217 sock_prot_inuse_add(sock_net(sk), sk->sk_prot, 1); 281 sock_prot_inuse_add(sock_net(sk), sk->sk_prot, 1);
282
283 hslot2 = udp_hashslot2(udptable, udp_sk(sk)->udp_portaddr_hash);
284 spin_lock(&hslot2->lock);
285 hlist_nulls_add_head_rcu(&udp_sk(sk)->udp_portaddr_node,
286 &hslot2->head);
287 hslot2->count++;
288 spin_unlock(&hslot2->lock);
218 } 289 }
219 error = 0; 290 error = 0;
220fail_unlock: 291fail_unlock:
@@ -229,13 +300,26 @@ static int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
229 struct inet_sock *inet1 = inet_sk(sk1), *inet2 = inet_sk(sk2); 300 struct inet_sock *inet1 = inet_sk(sk1), *inet2 = inet_sk(sk2);
230 301
231 return (!ipv6_only_sock(sk2) && 302 return (!ipv6_only_sock(sk2) &&
232 (!inet1->rcv_saddr || !inet2->rcv_saddr || 303 (!inet1->inet_rcv_saddr || !inet2->inet_rcv_saddr ||
233 inet1->rcv_saddr == inet2->rcv_saddr)); 304 inet1->inet_rcv_saddr == inet2->inet_rcv_saddr));
305}
306
307static unsigned int udp4_portaddr_hash(struct net *net, __be32 saddr,
308 unsigned int port)
309{
310 return jhash_1word(saddr, net_hash_mix(net)) ^ port;
234} 311}
235 312
236int udp_v4_get_port(struct sock *sk, unsigned short snum) 313int udp_v4_get_port(struct sock *sk, unsigned short snum)
237{ 314{
238 return udp_lib_get_port(sk, snum, ipv4_rcv_saddr_equal); 315 unsigned int hash2_nulladdr =
316 udp4_portaddr_hash(sock_net(sk), INADDR_ANY, snum);
317 unsigned int hash2_partial =
318 udp4_portaddr_hash(sock_net(sk), inet_sk(sk)->inet_rcv_saddr, 0);
319
320 /* precompute partial secondary hash */
321 udp_sk(sk)->udp_portaddr_hash = hash2_partial;
322 return udp_lib_get_port(sk, snum, ipv4_rcv_saddr_equal, hash2_nulladdr);
239} 323}
240 324
241static inline int compute_score(struct sock *sk, struct net *net, __be32 saddr, 325static inline int compute_score(struct sock *sk, struct net *net, __be32 saddr,
@@ -244,23 +328,23 @@ static inline int compute_score(struct sock *sk, struct net *net, __be32 saddr,
244{ 328{
245 int score = -1; 329 int score = -1;
246 330
247 if (net_eq(sock_net(sk), net) && sk->sk_hash == hnum && 331 if (net_eq(sock_net(sk), net) && udp_sk(sk)->udp_port_hash == hnum &&
248 !ipv6_only_sock(sk)) { 332 !ipv6_only_sock(sk)) {
249 struct inet_sock *inet = inet_sk(sk); 333 struct inet_sock *inet = inet_sk(sk);
250 334
251 score = (sk->sk_family == PF_INET ? 1 : 0); 335 score = (sk->sk_family == PF_INET ? 1 : 0);
252 if (inet->rcv_saddr) { 336 if (inet->inet_rcv_saddr) {
253 if (inet->rcv_saddr != daddr) 337 if (inet->inet_rcv_saddr != daddr)
254 return -1; 338 return -1;
255 score += 2; 339 score += 2;
256 } 340 }
257 if (inet->daddr) { 341 if (inet->inet_daddr) {
258 if (inet->daddr != saddr) 342 if (inet->inet_daddr != saddr)
259 return -1; 343 return -1;
260 score += 2; 344 score += 2;
261 } 345 }
262 if (inet->dport) { 346 if (inet->inet_dport) {
263 if (inet->dport != sport) 347 if (inet->inet_dport != sport)
264 return -1; 348 return -1;
265 score += 2; 349 score += 2;
266 } 350 }
@@ -273,6 +357,89 @@ static inline int compute_score(struct sock *sk, struct net *net, __be32 saddr,
273 return score; 357 return score;
274} 358}
275 359
360/*
361 * In this second variant, we check (daddr, dport) matches (inet_rcv_sadd, inet_num)
362 */
363#define SCORE2_MAX (1 + 2 + 2 + 2)
364static inline int compute_score2(struct sock *sk, struct net *net,
365 __be32 saddr, __be16 sport,
366 __be32 daddr, unsigned int hnum, int dif)
367{
368 int score = -1;
369
370 if (net_eq(sock_net(sk), net) && !ipv6_only_sock(sk)) {
371 struct inet_sock *inet = inet_sk(sk);
372
373 if (inet->inet_rcv_saddr != daddr)
374 return -1;
375 if (inet->inet_num != hnum)
376 return -1;
377
378 score = (sk->sk_family == PF_INET ? 1 : 0);
379 if (inet->inet_daddr) {
380 if (inet->inet_daddr != saddr)
381 return -1;
382 score += 2;
383 }
384 if (inet->inet_dport) {
385 if (inet->inet_dport != sport)
386 return -1;
387 score += 2;
388 }
389 if (sk->sk_bound_dev_if) {
390 if (sk->sk_bound_dev_if != dif)
391 return -1;
392 score += 2;
393 }
394 }
395 return score;
396}
397
398
399/* called with read_rcu_lock() */
400static struct sock *udp4_lib_lookup2(struct net *net,
401 __be32 saddr, __be16 sport,
402 __be32 daddr, unsigned int hnum, int dif,
403 struct udp_hslot *hslot2, unsigned int slot2)
404{
405 struct sock *sk, *result;
406 struct hlist_nulls_node *node;
407 int score, badness;
408
409begin:
410 result = NULL;
411 badness = -1;
412 udp_portaddr_for_each_entry_rcu(sk, node, &hslot2->head) {
413 score = compute_score2(sk, net, saddr, sport,
414 daddr, hnum, dif);
415 if (score > badness) {
416 result = sk;
417 badness = score;
418 if (score == SCORE2_MAX)
419 goto exact_match;
420 }
421 }
422 /*
423 * if the nulls value we got at the end of this lookup is
424 * not the expected one, we must restart lookup.
425 * We probably met an item that was moved to another chain.
426 */
427 if (get_nulls_value(node) != slot2)
428 goto begin;
429
430 if (result) {
431exact_match:
432 if (unlikely(!atomic_inc_not_zero(&result->sk_refcnt)))
433 result = NULL;
434 else if (unlikely(compute_score2(result, net, saddr, sport,
435 daddr, hnum, dif) < badness)) {
436 sock_put(result);
437 goto begin;
438 }
439 }
440 return result;
441}
442
276/* UDP is nearly always wildcards out the wazoo, it makes no sense to try 443/* UDP is nearly always wildcards out the wazoo, it makes no sense to try
277 * harder than this. -DaveM 444 * harder than this. -DaveM
278 */ 445 */
@@ -283,11 +450,35 @@ static struct sock *__udp4_lib_lookup(struct net *net, __be32 saddr,
283 struct sock *sk, *result; 450 struct sock *sk, *result;
284 struct hlist_nulls_node *node; 451 struct hlist_nulls_node *node;
285 unsigned short hnum = ntohs(dport); 452 unsigned short hnum = ntohs(dport);
286 unsigned int hash = udp_hashfn(net, hnum); 453 unsigned int hash2, slot2, slot = udp_hashfn(net, hnum, udptable->mask);
287 struct udp_hslot *hslot = &udptable->hash[hash]; 454 struct udp_hslot *hslot2, *hslot = &udptable->hash[slot];
288 int score, badness; 455 int score, badness;
289 456
290 rcu_read_lock(); 457 rcu_read_lock();
458 if (hslot->count > 10) {
459 hash2 = udp4_portaddr_hash(net, daddr, hnum);
460 slot2 = hash2 & udptable->mask;
461 hslot2 = &udptable->hash2[slot2];
462 if (hslot->count < hslot2->count)
463 goto begin;
464
465 result = udp4_lib_lookup2(net, saddr, sport,
466 daddr, hnum, dif,
467 hslot2, slot2);
468 if (!result) {
469 hash2 = udp4_portaddr_hash(net, INADDR_ANY, hnum);
470 slot2 = hash2 & udptable->mask;
471 hslot2 = &udptable->hash2[slot2];
472 if (hslot->count < hslot2->count)
473 goto begin;
474
475 result = udp4_lib_lookup2(net, saddr, sport,
476 INADDR_ANY, hnum, dif,
477 hslot2, slot2);
478 }
479 rcu_read_unlock();
480 return result;
481 }
291begin: 482begin:
292 result = NULL; 483 result = NULL;
293 badness = -1; 484 badness = -1;
@@ -304,7 +495,7 @@ begin:
304 * not the expected one, we must restart lookup. 495 * not the expected one, we must restart lookup.
305 * We probably met an item that was moved to another chain. 496 * We probably met an item that was moved to another chain.
306 */ 497 */
307 if (get_nulls_value(node) != hash) 498 if (get_nulls_value(node) != slot)
308 goto begin; 499 goto begin;
309 500
310 if (result) { 501 if (result) {
@@ -354,12 +545,13 @@ static inline struct sock *udp_v4_mcast_next(struct net *net, struct sock *sk,
354 sk_nulls_for_each_from(s, node) { 545 sk_nulls_for_each_from(s, node) {
355 struct inet_sock *inet = inet_sk(s); 546 struct inet_sock *inet = inet_sk(s);
356 547
357 if (!net_eq(sock_net(s), net) || 548 if (!net_eq(sock_net(s), net) ||
358 s->sk_hash != hnum || 549 udp_sk(s)->udp_port_hash != hnum ||
359 (inet->daddr && inet->daddr != rmt_addr) || 550 (inet->inet_daddr && inet->inet_daddr != rmt_addr) ||
360 (inet->dport != rmt_port && inet->dport) || 551 (inet->inet_dport != rmt_port && inet->inet_dport) ||
361 (inet->rcv_saddr && inet->rcv_saddr != loc_addr) || 552 (inet->inet_rcv_saddr &&
362 ipv6_only_sock(s) || 553 inet->inet_rcv_saddr != loc_addr) ||
554 ipv6_only_sock(s) ||
363 (s->sk_bound_dev_if && s->sk_bound_dev_if != dif)) 555 (s->sk_bound_dev_if && s->sk_bound_dev_if != dif))
364 continue; 556 continue;
365 if (!ip_mc_sf_allow(s, loc_addr, rmt_addr, dif)) 557 if (!ip_mc_sf_allow(s, loc_addr, rmt_addr, dif))
@@ -642,14 +834,14 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
642 } else { 834 } else {
643 if (sk->sk_state != TCP_ESTABLISHED) 835 if (sk->sk_state != TCP_ESTABLISHED)
644 return -EDESTADDRREQ; 836 return -EDESTADDRREQ;
645 daddr = inet->daddr; 837 daddr = inet->inet_daddr;
646 dport = inet->dport; 838 dport = inet->inet_dport;
647 /* Open fast path for connected socket. 839 /* Open fast path for connected socket.
648 Route will not be used, if at least one option is set. 840 Route will not be used, if at least one option is set.
649 */ 841 */
650 connected = 1; 842 connected = 1;
651 } 843 }
652 ipc.addr = inet->saddr; 844 ipc.addr = inet->inet_saddr;
653 845
654 ipc.oif = sk->sk_bound_dev_if; 846 ipc.oif = sk->sk_bound_dev_if;
655 err = sock_tx_timestamp(msg, sk, &ipc.shtx); 847 err = sock_tx_timestamp(msg, sk, &ipc.shtx);
@@ -704,7 +896,7 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
704 .proto = sk->sk_protocol, 896 .proto = sk->sk_protocol,
705 .flags = inet_sk_flowi_flags(sk), 897 .flags = inet_sk_flowi_flags(sk),
706 .uli_u = { .ports = 898 .uli_u = { .ports =
707 { .sport = inet->sport, 899 { .sport = inet->inet_sport,
708 .dport = dport } } }; 900 .dport = dport } } };
709 struct net *net = sock_net(sk); 901 struct net *net = sock_net(sk);
710 902
@@ -748,7 +940,7 @@ back_from_confirm:
748 inet->cork.fl.fl4_dst = daddr; 940 inet->cork.fl.fl4_dst = daddr;
749 inet->cork.fl.fl_ip_dport = dport; 941 inet->cork.fl.fl_ip_dport = dport;
750 inet->cork.fl.fl4_src = saddr; 942 inet->cork.fl.fl4_src = saddr;
751 inet->cork.fl.fl_ip_sport = inet->sport; 943 inet->cork.fl.fl_ip_sport = inet->inet_sport;
752 up->pending = AF_INET; 944 up->pending = AF_INET;
753 945
754do_append_data: 946do_append_data:
@@ -862,6 +1054,7 @@ static unsigned int first_packet_length(struct sock *sk)
862 udp_lib_checksum_complete(skb)) { 1054 udp_lib_checksum_complete(skb)) {
863 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, 1055 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
864 IS_UDPLITE(sk)); 1056 IS_UDPLITE(sk));
1057 atomic_inc(&sk->sk_drops);
865 __skb_unlink(skb, rcvq); 1058 __skb_unlink(skb, rcvq);
866 __skb_queue_tail(&list_kill, skb); 1059 __skb_queue_tail(&list_kill, skb);
867 } 1060 }
@@ -925,7 +1118,7 @@ int udp_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
925 struct inet_sock *inet = inet_sk(sk); 1118 struct inet_sock *inet = inet_sk(sk);
926 struct sockaddr_in *sin = (struct sockaddr_in *)msg->msg_name; 1119 struct sockaddr_in *sin = (struct sockaddr_in *)msg->msg_name;
927 struct sk_buff *skb; 1120 struct sk_buff *skb;
928 unsigned int ulen, copied; 1121 unsigned int ulen;
929 int peeked; 1122 int peeked;
930 int err; 1123 int err;
931 int is_udplite = IS_UDPLITE(sk); 1124 int is_udplite = IS_UDPLITE(sk);
@@ -946,10 +1139,9 @@ try_again:
946 goto out; 1139 goto out;
947 1140
948 ulen = skb->len - sizeof(struct udphdr); 1141 ulen = skb->len - sizeof(struct udphdr);
949 copied = len; 1142 if (len > ulen)
950 if (copied > ulen) 1143 len = ulen;
951 copied = ulen; 1144 else if (len < ulen)
952 else if (copied < ulen)
953 msg->msg_flags |= MSG_TRUNC; 1145 msg->msg_flags |= MSG_TRUNC;
954 1146
955 /* 1147 /*
@@ -958,14 +1150,14 @@ try_again:
958 * coverage checksum (UDP-Lite), do it before the copy. 1150 * coverage checksum (UDP-Lite), do it before the copy.
959 */ 1151 */
960 1152
961 if (copied < ulen || UDP_SKB_CB(skb)->partial_cov) { 1153 if (len < ulen || UDP_SKB_CB(skb)->partial_cov) {
962 if (udp_lib_checksum_complete(skb)) 1154 if (udp_lib_checksum_complete(skb))
963 goto csum_copy_err; 1155 goto csum_copy_err;
964 } 1156 }
965 1157
966 if (skb_csum_unnecessary(skb)) 1158 if (skb_csum_unnecessary(skb))
967 err = skb_copy_datagram_iovec(skb, sizeof(struct udphdr), 1159 err = skb_copy_datagram_iovec(skb, sizeof(struct udphdr),
968 msg->msg_iov, copied); 1160 msg->msg_iov, len);
969 else { 1161 else {
970 err = skb_copy_and_csum_datagram_iovec(skb, 1162 err = skb_copy_and_csum_datagram_iovec(skb,
971 sizeof(struct udphdr), 1163 sizeof(struct udphdr),
@@ -982,7 +1174,7 @@ try_again:
982 UDP_INC_STATS_USER(sock_net(sk), 1174 UDP_INC_STATS_USER(sock_net(sk),
983 UDP_MIB_INDATAGRAMS, is_udplite); 1175 UDP_MIB_INDATAGRAMS, is_udplite);
984 1176
985 sock_recv_timestamp(msg, sk, skb); 1177 sock_recv_ts_and_drops(msg, sk, skb);
986 1178
987 /* Copy the address. */ 1179 /* Copy the address. */
988 if (sin) { 1180 if (sin) {
@@ -994,7 +1186,7 @@ try_again:
994 if (inet->cmsg_flags) 1186 if (inet->cmsg_flags)
995 ip_cmsg_recv(msg, skb); 1187 ip_cmsg_recv(msg, skb);
996 1188
997 err = copied; 1189 err = len;
998 if (flags & MSG_TRUNC) 1190 if (flags & MSG_TRUNC)
999 err = ulen; 1191 err = ulen;
1000 1192
@@ -1023,15 +1215,15 @@ int udp_disconnect(struct sock *sk, int flags)
1023 */ 1215 */
1024 1216
1025 sk->sk_state = TCP_CLOSE; 1217 sk->sk_state = TCP_CLOSE;
1026 inet->daddr = 0; 1218 inet->inet_daddr = 0;
1027 inet->dport = 0; 1219 inet->inet_dport = 0;
1028 sk->sk_bound_dev_if = 0; 1220 sk->sk_bound_dev_if = 0;
1029 if (!(sk->sk_userlocks & SOCK_BINDADDR_LOCK)) 1221 if (!(sk->sk_userlocks & SOCK_BINDADDR_LOCK))
1030 inet_reset_saddr(sk); 1222 inet_reset_saddr(sk);
1031 1223
1032 if (!(sk->sk_userlocks & SOCK_BINDPORT_LOCK)) { 1224 if (!(sk->sk_userlocks & SOCK_BINDPORT_LOCK)) {
1033 sk->sk_prot->unhash(sk); 1225 sk->sk_prot->unhash(sk);
1034 inet->sport = 0; 1226 inet->inet_sport = 0;
1035 } 1227 }
1036 sk_dst_reset(sk); 1228 sk_dst_reset(sk);
1037 return 0; 1229 return 0;
@@ -1042,13 +1234,22 @@ void udp_lib_unhash(struct sock *sk)
1042{ 1234{
1043 if (sk_hashed(sk)) { 1235 if (sk_hashed(sk)) {
1044 struct udp_table *udptable = sk->sk_prot->h.udp_table; 1236 struct udp_table *udptable = sk->sk_prot->h.udp_table;
1045 unsigned int hash = udp_hashfn(sock_net(sk), sk->sk_hash); 1237 struct udp_hslot *hslot, *hslot2;
1046 struct udp_hslot *hslot = &udptable->hash[hash]; 1238
1239 hslot = udp_hashslot(udptable, sock_net(sk),
1240 udp_sk(sk)->udp_port_hash);
1241 hslot2 = udp_hashslot2(udptable, udp_sk(sk)->udp_portaddr_hash);
1047 1242
1048 spin_lock_bh(&hslot->lock); 1243 spin_lock_bh(&hslot->lock);
1049 if (sk_nulls_del_node_init_rcu(sk)) { 1244 if (sk_nulls_del_node_init_rcu(sk)) {
1050 inet_sk(sk)->num = 0; 1245 hslot->count--;
1246 inet_sk(sk)->inet_num = 0;
1051 sock_prot_inuse_add(sock_net(sk), sk->sk_prot, -1); 1247 sock_prot_inuse_add(sock_net(sk), sk->sk_prot, -1);
1248
1249 spin_lock(&hslot2->lock);
1250 hlist_nulls_del_init_rcu(&udp_sk(sk)->udp_portaddr_node);
1251 hslot2->count--;
1252 spin_unlock(&hslot2->lock);
1052 } 1253 }
1053 spin_unlock_bh(&hslot->lock); 1254 spin_unlock_bh(&hslot->lock);
1054 } 1255 }
@@ -1057,25 +1258,22 @@ EXPORT_SYMBOL(udp_lib_unhash);
1057 1258
1058static int __udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb) 1259static int __udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
1059{ 1260{
1060 int is_udplite = IS_UDPLITE(sk); 1261 int rc = sock_queue_rcv_skb(sk, skb);
1061 int rc; 1262
1263 if (rc < 0) {
1264 int is_udplite = IS_UDPLITE(sk);
1062 1265
1063 if ((rc = sock_queue_rcv_skb(sk, skb)) < 0) {
1064 /* Note that an ENOMEM error is charged twice */ 1266 /* Note that an ENOMEM error is charged twice */
1065 if (rc == -ENOMEM) { 1267 if (rc == -ENOMEM)
1066 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS, 1268 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
1067 is_udplite); 1269 is_udplite);
1068 atomic_inc(&sk->sk_drops); 1270 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
1069 } 1271 kfree_skb(skb);
1070 goto drop; 1272 return -1;
1071 } 1273 }
1072 1274
1073 return 0; 1275 return 0;
1074 1276
1075drop:
1076 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
1077 kfree_skb(skb);
1078 return -1;
1079} 1277}
1080 1278
1081/* returns: 1279/* returns:
@@ -1174,61 +1372,98 @@ int udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
1174 bh_lock_sock(sk); 1372 bh_lock_sock(sk);
1175 if (!sock_owned_by_user(sk)) 1373 if (!sock_owned_by_user(sk))
1176 rc = __udp_queue_rcv_skb(sk, skb); 1374 rc = __udp_queue_rcv_skb(sk, skb);
1177 else 1375 else if (sk_add_backlog(sk, skb)) {
1178 sk_add_backlog(sk, skb); 1376 bh_unlock_sock(sk);
1377 goto drop;
1378 }
1179 bh_unlock_sock(sk); 1379 bh_unlock_sock(sk);
1180 1380
1181 return rc; 1381 return rc;
1182 1382
1183drop: 1383drop:
1184 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite); 1384 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
1385 atomic_inc(&sk->sk_drops);
1185 kfree_skb(skb); 1386 kfree_skb(skb);
1186 return -1; 1387 return -1;
1187} 1388}
1188 1389
1390
1391static void flush_stack(struct sock **stack, unsigned int count,
1392 struct sk_buff *skb, unsigned int final)
1393{
1394 unsigned int i;
1395 struct sk_buff *skb1 = NULL;
1396 struct sock *sk;
1397
1398 for (i = 0; i < count; i++) {
1399 sk = stack[i];
1400 if (likely(skb1 == NULL))
1401 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
1402
1403 if (!skb1) {
1404 atomic_inc(&sk->sk_drops);
1405 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
1406 IS_UDPLITE(sk));
1407 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
1408 IS_UDPLITE(sk));
1409 }
1410
1411 if (skb1 && udp_queue_rcv_skb(sk, skb1) <= 0)
1412 skb1 = NULL;
1413 }
1414 if (unlikely(skb1))
1415 kfree_skb(skb1);
1416}
1417
1189/* 1418/*
1190 * Multicasts and broadcasts go to each listener. 1419 * Multicasts and broadcasts go to each listener.
1191 * 1420 *
1192 * Note: called only from the BH handler context, 1421 * Note: called only from the BH handler context.
1193 * so we don't need to lock the hashes.
1194 */ 1422 */
1195static int __udp4_lib_mcast_deliver(struct net *net, struct sk_buff *skb, 1423static int __udp4_lib_mcast_deliver(struct net *net, struct sk_buff *skb,
1196 struct udphdr *uh, 1424 struct udphdr *uh,
1197 __be32 saddr, __be32 daddr, 1425 __be32 saddr, __be32 daddr,
1198 struct udp_table *udptable) 1426 struct udp_table *udptable)
1199{ 1427{
1200 struct sock *sk; 1428 struct sock *sk, *stack[256 / sizeof(struct sock *)];
1201 struct udp_hslot *hslot = &udptable->hash[udp_hashfn(net, ntohs(uh->dest))]; 1429 struct udp_hslot *hslot = udp_hashslot(udptable, net, ntohs(uh->dest));
1202 int dif; 1430 int dif;
1431 unsigned int i, count = 0;
1203 1432
1204 spin_lock(&hslot->lock); 1433 spin_lock(&hslot->lock);
1205 sk = sk_nulls_head(&hslot->head); 1434 sk = sk_nulls_head(&hslot->head);
1206 dif = skb->dev->ifindex; 1435 dif = skb->dev->ifindex;
1207 sk = udp_v4_mcast_next(net, sk, uh->dest, daddr, uh->source, saddr, dif); 1436 sk = udp_v4_mcast_next(net, sk, uh->dest, daddr, uh->source, saddr, dif);
1208 if (sk) { 1437 while (sk) {
1209 struct sock *sknext = NULL; 1438 stack[count++] = sk;
1439 sk = udp_v4_mcast_next(net, sk_nulls_next(sk), uh->dest,
1440 daddr, uh->source, saddr, dif);
1441 if (unlikely(count == ARRAY_SIZE(stack))) {
1442 if (!sk)
1443 break;
1444 flush_stack(stack, count, skb, ~0);
1445 count = 0;
1446 }
1447 }
1448 /*
1449 * before releasing chain lock, we must take a reference on sockets
1450 */
1451 for (i = 0; i < count; i++)
1452 sock_hold(stack[i]);
1210 1453
1211 do {
1212 struct sk_buff *skb1 = skb;
1213
1214 sknext = udp_v4_mcast_next(net, sk_nulls_next(sk), uh->dest,
1215 daddr, uh->source, saddr,
1216 dif);
1217 if (sknext)
1218 skb1 = skb_clone(skb, GFP_ATOMIC);
1219
1220 if (skb1) {
1221 int ret = udp_queue_rcv_skb(sk, skb1);
1222 if (ret > 0)
1223 /* we should probably re-process instead
1224 * of dropping packets here. */
1225 kfree_skb(skb1);
1226 }
1227 sk = sknext;
1228 } while (sknext);
1229 } else
1230 consume_skb(skb);
1231 spin_unlock(&hslot->lock); 1454 spin_unlock(&hslot->lock);
1455
1456 /*
1457 * do the slow work with no lock held
1458 */
1459 if (count) {
1460 flush_stack(stack, count, skb, count - 1);
1461
1462 for (i = 0; i < count; i++)
1463 sock_put(stack[i]);
1464 } else {
1465 kfree_skb(skb);
1466 }
1232 return 0; 1467 return 0;
1233} 1468}
1234 1469
@@ -1292,6 +1527,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
1292 1527
1293 uh = udp_hdr(skb); 1528 uh = udp_hdr(skb);
1294 ulen = ntohs(uh->len); 1529 ulen = ntohs(uh->len);
1530 saddr = ip_hdr(skb)->saddr;
1531 daddr = ip_hdr(skb)->daddr;
1532
1295 if (ulen > skb->len) 1533 if (ulen > skb->len)
1296 goto short_packet; 1534 goto short_packet;
1297 1535
@@ -1305,9 +1543,6 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
1305 if (udp4_csum_init(skb, uh, proto)) 1543 if (udp4_csum_init(skb, uh, proto))
1306 goto csum_error; 1544 goto csum_error;
1307 1545
1308 saddr = ip_hdr(skb)->saddr;
1309 daddr = ip_hdr(skb)->daddr;
1310
1311 if (rt->rt_flags & (RTCF_BROADCAST|RTCF_MULTICAST)) 1546 if (rt->rt_flags & (RTCF_BROADCAST|RTCF_MULTICAST))
1312 return __udp4_lib_mcast_deliver(net, skb, uh, 1547 return __udp4_lib_mcast_deliver(net, skb, uh,
1313 saddr, daddr, udptable); 1548 saddr, daddr, udptable);
@@ -1620,9 +1855,14 @@ static struct sock *udp_get_first(struct seq_file *seq, int start)
1620 struct udp_iter_state *state = seq->private; 1855 struct udp_iter_state *state = seq->private;
1621 struct net *net = seq_file_net(seq); 1856 struct net *net = seq_file_net(seq);
1622 1857
1623 for (state->bucket = start; state->bucket < UDP_HTABLE_SIZE; ++state->bucket) { 1858 for (state->bucket = start; state->bucket <= state->udp_table->mask;
1859 ++state->bucket) {
1624 struct hlist_nulls_node *node; 1860 struct hlist_nulls_node *node;
1625 struct udp_hslot *hslot = &state->udp_table->hash[state->bucket]; 1861 struct udp_hslot *hslot = &state->udp_table->hash[state->bucket];
1862
1863 if (hlist_nulls_empty(&hslot->head))
1864 continue;
1865
1626 spin_lock_bh(&hslot->lock); 1866 spin_lock_bh(&hslot->lock);
1627 sk_nulls_for_each(sk, node, &hslot->head) { 1867 sk_nulls_for_each(sk, node, &hslot->head) {
1628 if (!net_eq(sock_net(sk), net)) 1868 if (!net_eq(sock_net(sk), net))
@@ -1647,7 +1887,7 @@ static struct sock *udp_get_next(struct seq_file *seq, struct sock *sk)
1647 } while (sk && (!net_eq(sock_net(sk), net) || sk->sk_family != state->family)); 1887 } while (sk && (!net_eq(sock_net(sk), net) || sk->sk_family != state->family));
1648 1888
1649 if (!sk) { 1889 if (!sk) {
1650 if (state->bucket < UDP_HTABLE_SIZE) 1890 if (state->bucket <= state->udp_table->mask)
1651 spin_unlock_bh(&state->udp_table->hash[state->bucket].lock); 1891 spin_unlock_bh(&state->udp_table->hash[state->bucket].lock);
1652 return udp_get_first(seq, state->bucket + 1); 1892 return udp_get_first(seq, state->bucket + 1);
1653 } 1893 }
@@ -1667,7 +1907,7 @@ static struct sock *udp_get_idx(struct seq_file *seq, loff_t pos)
1667static void *udp_seq_start(struct seq_file *seq, loff_t *pos) 1907static void *udp_seq_start(struct seq_file *seq, loff_t *pos)
1668{ 1908{
1669 struct udp_iter_state *state = seq->private; 1909 struct udp_iter_state *state = seq->private;
1670 state->bucket = UDP_HTABLE_SIZE; 1910 state->bucket = MAX_UDP_PORTS;
1671 1911
1672 return *pos ? udp_get_idx(seq, *pos-1) : SEQ_START_TOKEN; 1912 return *pos ? udp_get_idx(seq, *pos-1) : SEQ_START_TOKEN;
1673} 1913}
@@ -1689,7 +1929,7 @@ static void udp_seq_stop(struct seq_file *seq, void *v)
1689{ 1929{
1690 struct udp_iter_state *state = seq->private; 1930 struct udp_iter_state *state = seq->private;
1691 1931
1692 if (state->bucket < UDP_HTABLE_SIZE) 1932 if (state->bucket <= state->udp_table->mask)
1693 spin_unlock_bh(&state->udp_table->hash[state->bucket].lock); 1933 spin_unlock_bh(&state->udp_table->hash[state->bucket].lock);
1694} 1934}
1695 1935
@@ -1744,12 +1984,12 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
1744 int bucket, int *len) 1984 int bucket, int *len)
1745{ 1985{
1746 struct inet_sock *inet = inet_sk(sp); 1986 struct inet_sock *inet = inet_sk(sp);
1747 __be32 dest = inet->daddr; 1987 __be32 dest = inet->inet_daddr;
1748 __be32 src = inet->rcv_saddr; 1988 __be32 src = inet->inet_rcv_saddr;
1749 __u16 destp = ntohs(inet->dport); 1989 __u16 destp = ntohs(inet->inet_dport);
1750 __u16 srcp = ntohs(inet->sport); 1990 __u16 srcp = ntohs(inet->inet_sport);
1751 1991
1752 seq_printf(f, "%4d: %08X:%04X %08X:%04X" 1992 seq_printf(f, "%5d: %08X:%04X %08X:%04X"
1753 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %lu %d %p %d%n", 1993 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %lu %d %p %d%n",
1754 bucket, src, srcp, dest, destp, sp->sk_state, 1994 bucket, src, srcp, dest, destp, sp->sk_state,
1755 sk_wmem_alloc_get(sp), 1995 sk_wmem_alloc_get(sp),
@@ -1789,12 +2029,12 @@ static struct udp_seq_afinfo udp4_seq_afinfo = {
1789 }, 2029 },
1790}; 2030};
1791 2031
1792static int udp4_proc_init_net(struct net *net) 2032static int __net_init udp4_proc_init_net(struct net *net)
1793{ 2033{
1794 return udp_proc_register(net, &udp4_seq_afinfo); 2034 return udp_proc_register(net, &udp4_seq_afinfo);
1795} 2035}
1796 2036
1797static void udp4_proc_exit_net(struct net *net) 2037static void __net_exit udp4_proc_exit_net(struct net *net)
1798{ 2038{
1799 udp_proc_unregister(net, &udp4_seq_afinfo); 2039 udp_proc_unregister(net, &udp4_seq_afinfo);
1800} 2040}
@@ -1815,21 +2055,60 @@ void udp4_proc_exit(void)
1815} 2055}
1816#endif /* CONFIG_PROC_FS */ 2056#endif /* CONFIG_PROC_FS */
1817 2057
1818void __init udp_table_init(struct udp_table *table) 2058static __initdata unsigned long uhash_entries;
2059static int __init set_uhash_entries(char *str)
1819{ 2060{
1820 int i; 2061 if (!str)
2062 return 0;
2063 uhash_entries = simple_strtoul(str, &str, 0);
2064 if (uhash_entries && uhash_entries < UDP_HTABLE_SIZE_MIN)
2065 uhash_entries = UDP_HTABLE_SIZE_MIN;
2066 return 1;
2067}
2068__setup("uhash_entries=", set_uhash_entries);
1821 2069
1822 for (i = 0; i < UDP_HTABLE_SIZE; i++) { 2070void __init udp_table_init(struct udp_table *table, const char *name)
2071{
2072 unsigned int i;
2073
2074 if (!CONFIG_BASE_SMALL)
2075 table->hash = alloc_large_system_hash(name,
2076 2 * sizeof(struct udp_hslot),
2077 uhash_entries,
2078 21, /* one slot per 2 MB */
2079 0,
2080 &table->log,
2081 &table->mask,
2082 64 * 1024);
2083 /*
2084 * Make sure hash table has the minimum size
2085 */
2086 if (CONFIG_BASE_SMALL || table->mask < UDP_HTABLE_SIZE_MIN - 1) {
2087 table->hash = kmalloc(UDP_HTABLE_SIZE_MIN *
2088 2 * sizeof(struct udp_hslot), GFP_KERNEL);
2089 if (!table->hash)
2090 panic(name);
2091 table->log = ilog2(UDP_HTABLE_SIZE_MIN);
2092 table->mask = UDP_HTABLE_SIZE_MIN - 1;
2093 }
2094 table->hash2 = table->hash + (table->mask + 1);
2095 for (i = 0; i <= table->mask; i++) {
1823 INIT_HLIST_NULLS_HEAD(&table->hash[i].head, i); 2096 INIT_HLIST_NULLS_HEAD(&table->hash[i].head, i);
2097 table->hash[i].count = 0;
1824 spin_lock_init(&table->hash[i].lock); 2098 spin_lock_init(&table->hash[i].lock);
1825 } 2099 }
2100 for (i = 0; i <= table->mask; i++) {
2101 INIT_HLIST_NULLS_HEAD(&table->hash2[i].head, i);
2102 table->hash2[i].count = 0;
2103 spin_lock_init(&table->hash2[i].lock);
2104 }
1826} 2105}
1827 2106
1828void __init udp_init(void) 2107void __init udp_init(void)
1829{ 2108{
1830 unsigned long nr_pages, limit; 2109 unsigned long nr_pages, limit;
1831 2110
1832 udp_table_init(&udp_table); 2111 udp_table_init(&udp_table, "UDP");
1833 /* Set the pressure threshold up by the same strategy of TCP. It is a 2112 /* Set the pressure threshold up by the same strategy of TCP. It is a
1834 * fraction of global memory that is up to 1/2 at 256 MB, decreasing 2113 * fraction of global memory that is up to 1/2 at 256 MB, decreasing
1835 * toward zero with the amount of memory, with a floor of 128 pages. 2114 * toward zero with the amount of memory, with a floor of 128 pages.
diff --git a/net/ipv4/udplite.c b/net/ipv4/udplite.c
index 95248d7f75ec..6610bf76369f 100644
--- a/net/ipv4/udplite.c
+++ b/net/ipv4/udplite.c
@@ -12,7 +12,7 @@
12 */ 12 */
13#include "udp_impl.h" 13#include "udp_impl.h"
14 14
15struct udp_table udplite_table; 15struct udp_table udplite_table __read_mostly;
16EXPORT_SYMBOL(udplite_table); 16EXPORT_SYMBOL(udplite_table);
17 17
18static int udplite_rcv(struct sk_buff *skb) 18static int udplite_rcv(struct sk_buff *skb)
@@ -64,7 +64,6 @@ static struct inet_protosw udplite4_protosw = {
64 .protocol = IPPROTO_UDPLITE, 64 .protocol = IPPROTO_UDPLITE,
65 .prot = &udplite_prot, 65 .prot = &udplite_prot,
66 .ops = &inet_dgram_ops, 66 .ops = &inet_dgram_ops,
67 .capability = -1,
68 .no_check = 0, /* must checksum (RFC 3828) */ 67 .no_check = 0, /* must checksum (RFC 3828) */
69 .flags = INET_PROTOSW_PERMANENT, 68 .flags = INET_PROTOSW_PERMANENT,
70}; 69};
@@ -82,12 +81,12 @@ static struct udp_seq_afinfo udplite4_seq_afinfo = {
82 }, 81 },
83}; 82};
84 83
85static int udplite4_proc_init_net(struct net *net) 84static int __net_init udplite4_proc_init_net(struct net *net)
86{ 85{
87 return udp_proc_register(net, &udplite4_seq_afinfo); 86 return udp_proc_register(net, &udplite4_seq_afinfo);
88} 87}
89 88
90static void udplite4_proc_exit_net(struct net *net) 89static void __net_exit udplite4_proc_exit_net(struct net *net)
91{ 90{
92 udp_proc_unregister(net, &udplite4_seq_afinfo); 91 udp_proc_unregister(net, &udplite4_seq_afinfo);
93} 92}
@@ -110,7 +109,7 @@ static inline int udplite4_proc_init(void)
110 109
111void __init udplite4_register(void) 110void __init udplite4_register(void)
112{ 111{
113 udp_table_init(&udplite_table); 112 udp_table_init(&udplite_table, "UDP-Lite");
114 if (proto_register(&udplite_prot, 1)) 113 if (proto_register(&udplite_prot, 1))
115 goto out_register_err; 114 goto out_register_err;
116 115
diff --git a/net/ipv4/xfrm4_input.c b/net/ipv4/xfrm4_input.c
index f9f922a0ba88..c791bb63203f 100644
--- a/net/ipv4/xfrm4_input.c
+++ b/net/ipv4/xfrm4_input.c
@@ -9,6 +9,7 @@
9 * 9 *
10 */ 10 */
11 11
12#include <linux/slab.h>
12#include <linux/module.h> 13#include <linux/module.h>
13#include <linux/string.h> 14#include <linux/string.h>
14#include <linux/netfilter.h> 15#include <linux/netfilter.h>
diff --git a/net/ipv4/xfrm4_mode_tunnel.c b/net/ipv4/xfrm4_mode_tunnel.c
index 3444f3b34eca..6f368413eb0e 100644
--- a/net/ipv4/xfrm4_mode_tunnel.c
+++ b/net/ipv4/xfrm4_mode_tunnel.c
@@ -4,6 +4,7 @@
4 * Copyright (c) 2004-2006 Herbert Xu <herbert@gondor.apana.org.au> 4 * Copyright (c) 2004-2006 Herbert Xu <herbert@gondor.apana.org.au>
5 */ 5 */
6 6
7#include <linux/gfp.h>
7#include <linux/init.h> 8#include <linux/init.h>
8#include <linux/kernel.h> 9#include <linux/kernel.h>
9#include <linux/module.h> 10#include <linux/module.h>
diff --git a/net/ipv4/xfrm4_policy.c b/net/ipv4/xfrm4_policy.c
index 74fb2eb833ec..e4a1483fba77 100644
--- a/net/ipv4/xfrm4_policy.c
+++ b/net/ipv4/xfrm4_policy.c
@@ -15,7 +15,6 @@
15#include <net/xfrm.h> 15#include <net/xfrm.h>
16#include <net/ip.h> 16#include <net/ip.h>
17 17
18static struct dst_ops xfrm4_dst_ops;
19static struct xfrm_policy_afinfo xfrm4_policy_afinfo; 18static struct xfrm_policy_afinfo xfrm4_policy_afinfo;
20 19
21static struct dst_entry *xfrm4_dst_lookup(struct net *net, int tos, 20static struct dst_entry *xfrm4_dst_lookup(struct net *net, int tos,
@@ -92,11 +91,12 @@ static int xfrm4_init_path(struct xfrm_dst *path, struct dst_entry *dst,
92 return 0; 91 return 0;
93} 92}
94 93
95static int xfrm4_fill_dst(struct xfrm_dst *xdst, struct net_device *dev) 94static int xfrm4_fill_dst(struct xfrm_dst *xdst, struct net_device *dev,
95 struct flowi *fl)
96{ 96{
97 struct rtable *rt = (struct rtable *)xdst->route; 97 struct rtable *rt = (struct rtable *)xdst->route;
98 98
99 xdst->u.rt.fl = rt->fl; 99 xdst->u.rt.fl = *fl;
100 100
101 xdst->u.dst.dev = dev; 101 xdst->u.dst.dev = dev;
102 dev_hold(dev); 102 dev_hold(dev);
@@ -190,8 +190,10 @@ _decode_session4(struct sk_buff *skb, struct flowi *fl, int reverse)
190 190
191static inline int xfrm4_garbage_collect(struct dst_ops *ops) 191static inline int xfrm4_garbage_collect(struct dst_ops *ops)
192{ 192{
193 xfrm4_policy_afinfo.garbage_collect(&init_net); 193 struct net *net = container_of(ops, struct net, xfrm.xfrm4_dst_ops);
194 return (atomic_read(&xfrm4_dst_ops.entries) > xfrm4_dst_ops.gc_thresh*2); 194
195 xfrm4_policy_afinfo.garbage_collect(net);
196 return (atomic_read(&ops->entries) > ops->gc_thresh * 2);
195} 197}
196 198
197static void xfrm4_update_pmtu(struct dst_entry *dst, u32 mtu) 199static void xfrm4_update_pmtu(struct dst_entry *dst, u32 mtu)
@@ -267,9 +269,8 @@ static struct xfrm_policy_afinfo xfrm4_policy_afinfo = {
267#ifdef CONFIG_SYSCTL 269#ifdef CONFIG_SYSCTL
268static struct ctl_table xfrm4_policy_table[] = { 270static struct ctl_table xfrm4_policy_table[] = {
269 { 271 {
270 .ctl_name = CTL_UNNUMBERED,
271 .procname = "xfrm4_gc_thresh", 272 .procname = "xfrm4_gc_thresh",
272 .data = &xfrm4_dst_ops.gc_thresh, 273 .data = &init_net.xfrm.xfrm4_dst_ops.gc_thresh,
273 .maxlen = sizeof(int), 274 .maxlen = sizeof(int),
274 .mode = 0644, 275 .mode = 0644,
275 .proc_handler = proc_dointvec, 276 .proc_handler = proc_dointvec,
@@ -296,8 +297,6 @@ static void __exit xfrm4_policy_fini(void)
296 297
297void __init xfrm4_init(int rt_max_size) 298void __init xfrm4_init(int rt_max_size)
298{ 299{
299 xfrm4_state_init();
300 xfrm4_policy_init();
301 /* 300 /*
302 * Select a default value for the gc_thresh based on the main route 301 * Select a default value for the gc_thresh based on the main route
303 * table hash size. It seems to me the worst case scenario is when 302 * table hash size. It seems to me the worst case scenario is when
@@ -309,6 +308,9 @@ void __init xfrm4_init(int rt_max_size)
309 * and start cleaning when were 1/2 full 308 * and start cleaning when were 1/2 full
310 */ 309 */
311 xfrm4_dst_ops.gc_thresh = rt_max_size/2; 310 xfrm4_dst_ops.gc_thresh = rt_max_size/2;
311
312 xfrm4_state_init();
313 xfrm4_policy_init();
312#ifdef CONFIG_SYSCTL 314#ifdef CONFIG_SYSCTL
313 sysctl_hdr = register_net_sysctl_table(&init_net, net_ipv4_ctl_path, 315 sysctl_hdr = register_net_sysctl_table(&init_net, net_ipv4_ctl_path,
314 xfrm4_policy_table); 316 xfrm4_policy_table);
diff --git a/net/ipv6/Kconfig b/net/ipv6/Kconfig
index ead6c7a42f44..a578096152ab 100644
--- a/net/ipv6/Kconfig
+++ b/net/ipv6/Kconfig
@@ -170,6 +170,25 @@ config IPV6_SIT
170 170
171 Saying M here will produce a module called sit. If unsure, say Y. 171 Saying M here will produce a module called sit. If unsure, say Y.
172 172
173config IPV6_SIT_6RD
174 bool "IPv6: IPv6 Rapid Deployment (6RD) (EXPERIMENTAL)"
175 depends on IPV6_SIT && EXPERIMENTAL
176 default n
177 ---help---
178 IPv6 Rapid Deployment (6rd; draft-ietf-softwire-ipv6-6rd) builds upon
179 mechanisms of 6to4 (RFC3056) to enable a service provider to rapidly
180 deploy IPv6 unicast service to IPv4 sites to which it provides
181 customer premise equipment. Like 6to4, it utilizes stateless IPv6 in
182 IPv4 encapsulation in order to transit IPv4-only network
183 infrastructure. Unlike 6to4, a 6rd service provider uses an IPv6
184 prefix of its own in place of the fixed 6to4 prefix.
185
186 With this option enabled, the SIT driver offers 6rd functionality by
187 providing additional ioctl API to configure the IPv6 Prefix for in
188 stead of static 2002::/16 for 6to4.
189
190 If unsure, say N.
191
173config IPV6_NDISC_NODETYPE 192config IPV6_NDISC_NODETYPE
174 bool 193 bool
175 194
diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
index 1fd0a3d775d2..413054f02aab 100644
--- a/net/ipv6/addrconf.c
+++ b/net/ipv6/addrconf.c
@@ -53,6 +53,7 @@
53#include <linux/route.h> 53#include <linux/route.h>
54#include <linux/inetdevice.h> 54#include <linux/inetdevice.h>
55#include <linux/init.h> 55#include <linux/init.h>
56#include <linux/slab.h>
56#ifdef CONFIG_SYSCTL 57#ifdef CONFIG_SYSCTL
57#include <linux/sysctl.h> 58#include <linux/sysctl.h>
58#endif 59#endif
@@ -278,31 +279,31 @@ static void addrconf_mod_timer(struct inet6_ifaddr *ifp,
278 279
279static int snmp6_alloc_dev(struct inet6_dev *idev) 280static int snmp6_alloc_dev(struct inet6_dev *idev)
280{ 281{
281 if (snmp_mib_init((void **)idev->stats.ipv6, 282 if (snmp_mib_init((void __percpu **)idev->stats.ipv6,
282 sizeof(struct ipstats_mib)) < 0) 283 sizeof(struct ipstats_mib)) < 0)
283 goto err_ip; 284 goto err_ip;
284 if (snmp_mib_init((void **)idev->stats.icmpv6, 285 if (snmp_mib_init((void __percpu **)idev->stats.icmpv6,
285 sizeof(struct icmpv6_mib)) < 0) 286 sizeof(struct icmpv6_mib)) < 0)
286 goto err_icmp; 287 goto err_icmp;
287 if (snmp_mib_init((void **)idev->stats.icmpv6msg, 288 if (snmp_mib_init((void __percpu **)idev->stats.icmpv6msg,
288 sizeof(struct icmpv6msg_mib)) < 0) 289 sizeof(struct icmpv6msg_mib)) < 0)
289 goto err_icmpmsg; 290 goto err_icmpmsg;
290 291
291 return 0; 292 return 0;
292 293
293err_icmpmsg: 294err_icmpmsg:
294 snmp_mib_free((void **)idev->stats.icmpv6); 295 snmp_mib_free((void __percpu **)idev->stats.icmpv6);
295err_icmp: 296err_icmp:
296 snmp_mib_free((void **)idev->stats.ipv6); 297 snmp_mib_free((void __percpu **)idev->stats.ipv6);
297err_ip: 298err_ip:
298 return -ENOMEM; 299 return -ENOMEM;
299} 300}
300 301
301static void snmp6_free_dev(struct inet6_dev *idev) 302static void snmp6_free_dev(struct inet6_dev *idev)
302{ 303{
303 snmp_mib_free((void **)idev->stats.icmpv6msg); 304 snmp_mib_free((void __percpu **)idev->stats.icmpv6msg);
304 snmp_mib_free((void **)idev->stats.icmpv6); 305 snmp_mib_free((void __percpu **)idev->stats.icmpv6);
305 snmp_mib_free((void **)idev->stats.ipv6); 306 snmp_mib_free((void __percpu **)idev->stats.ipv6);
306} 307}
307 308
308/* Nobody refers to this device, we may destroy it. */ 309/* Nobody refers to this device, we may destroy it. */
@@ -481,9 +482,8 @@ static void addrconf_forward_change(struct net *net, __s32 newf)
481 struct net_device *dev; 482 struct net_device *dev;
482 struct inet6_dev *idev; 483 struct inet6_dev *idev;
483 484
484 read_lock(&dev_base_lock); 485 rcu_read_lock();
485 for_each_netdev(net, dev) { 486 for_each_netdev_rcu(net, dev) {
486 rcu_read_lock();
487 idev = __in6_dev_get(dev); 487 idev = __in6_dev_get(dev);
488 if (idev) { 488 if (idev) {
489 int changed = (!idev->cnf.forwarding) ^ (!newf); 489 int changed = (!idev->cnf.forwarding) ^ (!newf);
@@ -491,9 +491,8 @@ static void addrconf_forward_change(struct net *net, __s32 newf)
491 if (changed) 491 if (changed)
492 dev_forward_change(idev); 492 dev_forward_change(idev);
493 } 493 }
494 rcu_read_unlock();
495 } 494 }
496 read_unlock(&dev_base_lock); 495 rcu_read_unlock();
497} 496}
498 497
499static int addrconf_fixup_forwarding(struct ctl_table *table, int *p, int old) 498static int addrconf_fixup_forwarding(struct ctl_table *table, int *p, int old)
@@ -504,8 +503,11 @@ static int addrconf_fixup_forwarding(struct ctl_table *table, int *p, int old)
504 if (p == &net->ipv6.devconf_dflt->forwarding) 503 if (p == &net->ipv6.devconf_dflt->forwarding)
505 return 0; 504 return 0;
506 505
507 if (!rtnl_trylock()) 506 if (!rtnl_trylock()) {
507 /* Restore the original values before restarting */
508 *p = old;
508 return restart_syscall(); 509 return restart_syscall();
510 }
509 511
510 if (p == &net->ipv6.devconf_all->forwarding) { 512 if (p == &net->ipv6.devconf_all->forwarding) {
511 __s32 newf = net->ipv6.devconf_all->forwarding; 513 __s32 newf = net->ipv6.devconf_all->forwarding;
@@ -991,8 +993,7 @@ struct ipv6_saddr_dst {
991 993
992static inline int ipv6_saddr_preferred(int type) 994static inline int ipv6_saddr_preferred(int type)
993{ 995{
994 if (type & (IPV6_ADDR_MAPPED|IPV6_ADDR_COMPATv4| 996 if (type & (IPV6_ADDR_MAPPED|IPV6_ADDR_COMPATv4|IPV6_ADDR_LOOPBACK))
995 IPV6_ADDR_LOOPBACK|IPV6_ADDR_RESERVED))
996 return 1; 997 return 1;
997 return 0; 998 return 0;
998} 999}
@@ -1137,10 +1138,9 @@ int ipv6_dev_get_saddr(struct net *net, struct net_device *dst_dev,
1137 hiscore->rule = -1; 1138 hiscore->rule = -1;
1138 hiscore->ifa = NULL; 1139 hiscore->ifa = NULL;
1139 1140
1140 read_lock(&dev_base_lock);
1141 rcu_read_lock(); 1141 rcu_read_lock();
1142 1142
1143 for_each_netdev(net, dev) { 1143 for_each_netdev_rcu(net, dev) {
1144 struct inet6_dev *idev; 1144 struct inet6_dev *idev;
1145 1145
1146 /* Candidate Source Address (section 4) 1146 /* Candidate Source Address (section 4)
@@ -1235,7 +1235,6 @@ try_nextdev:
1235 read_unlock_bh(&idev->lock); 1235 read_unlock_bh(&idev->lock);
1236 } 1236 }
1237 rcu_read_unlock(); 1237 rcu_read_unlock();
1238 read_unlock(&dev_base_lock);
1239 1238
1240 if (!hiscore->ifa) 1239 if (!hiscore->ifa)
1241 return -EADDRNOTAVAIL; 1240 return -EADDRNOTAVAIL;
@@ -1382,6 +1381,8 @@ static void addrconf_dad_stop(struct inet6_ifaddr *ifp, int dad_failed)
1382 if (dad_failed) 1381 if (dad_failed)
1383 ifp->flags |= IFA_F_DADFAILED; 1382 ifp->flags |= IFA_F_DADFAILED;
1384 spin_unlock_bh(&ifp->lock); 1383 spin_unlock_bh(&ifp->lock);
1384 if (dad_failed)
1385 ipv6_ifa_notify(0, ifp);
1385 in6_ifa_put(ifp); 1386 in6_ifa_put(ifp);
1386#ifdef CONFIG_IPV6_PRIVACY 1387#ifdef CONFIG_IPV6_PRIVACY
1387 } else if (ifp->flags&IFA_F_TEMPORARY) { 1388 } else if (ifp->flags&IFA_F_TEMPORARY) {
@@ -2617,7 +2618,7 @@ static void addrconf_bonding_change(struct net_device *dev, unsigned long event)
2617static int addrconf_ifdown(struct net_device *dev, int how) 2618static int addrconf_ifdown(struct net_device *dev, int how)
2618{ 2619{
2619 struct inet6_dev *idev; 2620 struct inet6_dev *idev;
2620 struct inet6_ifaddr *ifa, **bifa; 2621 struct inet6_ifaddr *ifa, *keep_list, **bifa;
2621 struct net *net = dev_net(dev); 2622 struct net *net = dev_net(dev);
2622 int i; 2623 int i;
2623 2624
@@ -2650,11 +2651,12 @@ static int addrconf_ifdown(struct net_device *dev, int how)
2650 2651
2651 write_lock_bh(&addrconf_hash_lock); 2652 write_lock_bh(&addrconf_hash_lock);
2652 while ((ifa = *bifa) != NULL) { 2653 while ((ifa = *bifa) != NULL) {
2653 if (ifa->idev == idev) { 2654 if (ifa->idev == idev &&
2655 (how || !(ifa->flags&IFA_F_PERMANENT) ||
2656 ipv6_addr_type(&ifa->addr) & IPV6_ADDR_LINKLOCAL)) {
2654 *bifa = ifa->lst_next; 2657 *bifa = ifa->lst_next;
2655 ifa->lst_next = NULL; 2658 ifa->lst_next = NULL;
2656 addrconf_del_timer(ifa); 2659 __in6_ifa_put(ifa);
2657 in6_ifa_put(ifa);
2658 continue; 2660 continue;
2659 } 2661 }
2660 bifa = &ifa->lst_next; 2662 bifa = &ifa->lst_next;
@@ -2690,11 +2692,40 @@ static int addrconf_ifdown(struct net_device *dev, int how)
2690 write_lock_bh(&idev->lock); 2692 write_lock_bh(&idev->lock);
2691 } 2693 }
2692#endif 2694#endif
2695 keep_list = NULL;
2696 bifa = &keep_list;
2693 while ((ifa = idev->addr_list) != NULL) { 2697 while ((ifa = idev->addr_list) != NULL) {
2694 idev->addr_list = ifa->if_next; 2698 idev->addr_list = ifa->if_next;
2695 ifa->if_next = NULL; 2699 ifa->if_next = NULL;
2696 ifa->dead = 1; 2700
2697 addrconf_del_timer(ifa); 2701 addrconf_del_timer(ifa);
2702
2703 /* If just doing link down, and address is permanent
2704 and not link-local, then retain it. */
2705 if (how == 0 &&
2706 (ifa->flags&IFA_F_PERMANENT) &&
2707 !(ipv6_addr_type(&ifa->addr) & IPV6_ADDR_LINKLOCAL)) {
2708
2709 /* Move to holding list */
2710 *bifa = ifa;
2711 bifa = &ifa->if_next;
2712
2713 /* If not doing DAD on this address, just keep it. */
2714 if ((dev->flags&(IFF_NOARP|IFF_LOOPBACK)) ||
2715 idev->cnf.accept_dad <= 0 ||
2716 (ifa->flags & IFA_F_NODAD))
2717 continue;
2718
2719 /* If it was tentative already, no need to notify */
2720 if (ifa->flags & IFA_F_TENTATIVE)
2721 continue;
2722
2723 /* Flag it for later restoration when link comes up */
2724 ifa->flags |= IFA_F_TENTATIVE;
2725 in6_ifa_hold(ifa);
2726 } else {
2727 ifa->dead = 1;
2728 }
2698 write_unlock_bh(&idev->lock); 2729 write_unlock_bh(&idev->lock);
2699 2730
2700 __ipv6_ifa_notify(RTM_DELADDR, ifa); 2731 __ipv6_ifa_notify(RTM_DELADDR, ifa);
@@ -2703,6 +2734,9 @@ static int addrconf_ifdown(struct net_device *dev, int how)
2703 2734
2704 write_lock_bh(&idev->lock); 2735 write_lock_bh(&idev->lock);
2705 } 2736 }
2737
2738 idev->addr_list = keep_list;
2739
2706 write_unlock_bh(&idev->lock); 2740 write_unlock_bh(&idev->lock);
2707 2741
2708 /* Step 5: Discard multicast list */ 2742 /* Step 5: Discard multicast list */
@@ -2728,28 +2762,29 @@ static int addrconf_ifdown(struct net_device *dev, int how)
2728static void addrconf_rs_timer(unsigned long data) 2762static void addrconf_rs_timer(unsigned long data)
2729{ 2763{
2730 struct inet6_ifaddr *ifp = (struct inet6_ifaddr *) data; 2764 struct inet6_ifaddr *ifp = (struct inet6_ifaddr *) data;
2765 struct inet6_dev *idev = ifp->idev;
2731 2766
2732 if (ifp->idev->cnf.forwarding) 2767 read_lock(&idev->lock);
2768 if (idev->dead || !(idev->if_flags & IF_READY))
2733 goto out; 2769 goto out;
2734 2770
2735 if (ifp->idev->if_flags & IF_RA_RCVD) { 2771 if (idev->cnf.forwarding)
2736 /* 2772 goto out;
2737 * Announcement received after solicitation 2773
2738 * was sent 2774 /* Announcement received after solicitation was sent */
2739 */ 2775 if (idev->if_flags & IF_RA_RCVD)
2740 goto out; 2776 goto out;
2741 }
2742 2777
2743 spin_lock(&ifp->lock); 2778 spin_lock(&ifp->lock);
2744 if (ifp->probes++ < ifp->idev->cnf.rtr_solicits) { 2779 if (ifp->probes++ < idev->cnf.rtr_solicits) {
2745 /* The wait after the last probe can be shorter */ 2780 /* The wait after the last probe can be shorter */
2746 addrconf_mod_timer(ifp, AC_RS, 2781 addrconf_mod_timer(ifp, AC_RS,
2747 (ifp->probes == ifp->idev->cnf.rtr_solicits) ? 2782 (ifp->probes == idev->cnf.rtr_solicits) ?
2748 ifp->idev->cnf.rtr_solicit_delay : 2783 idev->cnf.rtr_solicit_delay :
2749 ifp->idev->cnf.rtr_solicit_interval); 2784 idev->cnf.rtr_solicit_interval);
2750 spin_unlock(&ifp->lock); 2785 spin_unlock(&ifp->lock);
2751 2786
2752 ndisc_send_rs(ifp->idev->dev, &ifp->addr, &in6addr_linklocal_allrouters); 2787 ndisc_send_rs(idev->dev, &ifp->addr, &in6addr_linklocal_allrouters);
2753 } else { 2788 } else {
2754 spin_unlock(&ifp->lock); 2789 spin_unlock(&ifp->lock);
2755 /* 2790 /*
@@ -2757,10 +2792,11 @@ static void addrconf_rs_timer(unsigned long data)
2757 * assumption any longer. 2792 * assumption any longer.
2758 */ 2793 */
2759 printk(KERN_DEBUG "%s: no IPv6 routers present\n", 2794 printk(KERN_DEBUG "%s: no IPv6 routers present\n",
2760 ifp->idev->dev->name); 2795 idev->dev->name);
2761 } 2796 }
2762 2797
2763out: 2798out:
2799 read_unlock(&idev->lock);
2764 in6_ifa_put(ifp); 2800 in6_ifa_put(ifp);
2765} 2801}
2766 2802
@@ -2793,14 +2829,14 @@ static void addrconf_dad_start(struct inet6_ifaddr *ifp, u32 flags)
2793 read_lock_bh(&idev->lock); 2829 read_lock_bh(&idev->lock);
2794 if (ifp->dead) 2830 if (ifp->dead)
2795 goto out; 2831 goto out;
2796 spin_lock_bh(&ifp->lock);
2797 2832
2833 spin_lock(&ifp->lock);
2798 if (dev->flags&(IFF_NOARP|IFF_LOOPBACK) || 2834 if (dev->flags&(IFF_NOARP|IFF_LOOPBACK) ||
2799 idev->cnf.accept_dad < 1 || 2835 idev->cnf.accept_dad < 1 ||
2800 !(ifp->flags&IFA_F_TENTATIVE) || 2836 !(ifp->flags&IFA_F_TENTATIVE) ||
2801 ifp->flags & IFA_F_NODAD) { 2837 ifp->flags & IFA_F_NODAD) {
2802 ifp->flags &= ~(IFA_F_TENTATIVE|IFA_F_OPTIMISTIC|IFA_F_DADFAILED); 2838 ifp->flags &= ~(IFA_F_TENTATIVE|IFA_F_OPTIMISTIC|IFA_F_DADFAILED);
2803 spin_unlock_bh(&ifp->lock); 2839 spin_unlock(&ifp->lock);
2804 read_unlock_bh(&idev->lock); 2840 read_unlock_bh(&idev->lock);
2805 2841
2806 addrconf_dad_completed(ifp); 2842 addrconf_dad_completed(ifp);
@@ -2808,7 +2844,7 @@ static void addrconf_dad_start(struct inet6_ifaddr *ifp, u32 flags)
2808 } 2844 }
2809 2845
2810 if (!(idev->if_flags & IF_READY)) { 2846 if (!(idev->if_flags & IF_READY)) {
2811 spin_unlock_bh(&ifp->lock); 2847 spin_unlock(&ifp->lock);
2812 read_unlock_bh(&idev->lock); 2848 read_unlock_bh(&idev->lock);
2813 /* 2849 /*
2814 * If the device is not ready: 2850 * If the device is not ready:
@@ -2828,7 +2864,7 @@ static void addrconf_dad_start(struct inet6_ifaddr *ifp, u32 flags)
2828 ip6_ins_rt(ifp->rt); 2864 ip6_ins_rt(ifp->rt);
2829 2865
2830 addrconf_dad_kick(ifp); 2866 addrconf_dad_kick(ifp);
2831 spin_unlock_bh(&ifp->lock); 2867 spin_unlock(&ifp->lock);
2832out: 2868out:
2833 read_unlock_bh(&idev->lock); 2869 read_unlock_bh(&idev->lock);
2834} 2870}
@@ -2839,20 +2875,21 @@ static void addrconf_dad_timer(unsigned long data)
2839 struct inet6_dev *idev = ifp->idev; 2875 struct inet6_dev *idev = ifp->idev;
2840 struct in6_addr mcaddr; 2876 struct in6_addr mcaddr;
2841 2877
2842 read_lock_bh(&idev->lock); 2878 read_lock(&idev->lock);
2843 if (idev->dead) { 2879 if (idev->dead || !(idev->if_flags & IF_READY)) {
2844 read_unlock_bh(&idev->lock); 2880 read_unlock(&idev->lock);
2845 goto out; 2881 goto out;
2846 } 2882 }
2847 spin_lock_bh(&ifp->lock); 2883
2884 spin_lock(&ifp->lock);
2848 if (ifp->probes == 0) { 2885 if (ifp->probes == 0) {
2849 /* 2886 /*
2850 * DAD was successful 2887 * DAD was successful
2851 */ 2888 */
2852 2889
2853 ifp->flags &= ~(IFA_F_TENTATIVE|IFA_F_OPTIMISTIC|IFA_F_DADFAILED); 2890 ifp->flags &= ~(IFA_F_TENTATIVE|IFA_F_OPTIMISTIC|IFA_F_DADFAILED);
2854 spin_unlock_bh(&ifp->lock); 2891 spin_unlock(&ifp->lock);
2855 read_unlock_bh(&idev->lock); 2892 read_unlock(&idev->lock);
2856 2893
2857 addrconf_dad_completed(ifp); 2894 addrconf_dad_completed(ifp);
2858 2895
@@ -2861,8 +2898,8 @@ static void addrconf_dad_timer(unsigned long data)
2861 2898
2862 ifp->probes--; 2899 ifp->probes--;
2863 addrconf_mod_timer(ifp, AC_DAD, ifp->idev->nd_parms->retrans_time); 2900 addrconf_mod_timer(ifp, AC_DAD, ifp->idev->nd_parms->retrans_time);
2864 spin_unlock_bh(&ifp->lock); 2901 spin_unlock(&ifp->lock);
2865 read_unlock_bh(&idev->lock); 2902 read_unlock(&idev->lock);
2866 2903
2867 /* send a neighbour solicitation for our addr */ 2904 /* send a neighbour solicitation for our addr */
2868 addrconf_addr_solict_mult(&ifp->addr, &mcaddr); 2905 addrconf_addr_solict_mult(&ifp->addr, &mcaddr);
@@ -2909,12 +2946,12 @@ static void addrconf_dad_run(struct inet6_dev *idev) {
2909 2946
2910 read_lock_bh(&idev->lock); 2947 read_lock_bh(&idev->lock);
2911 for (ifp = idev->addr_list; ifp; ifp = ifp->if_next) { 2948 for (ifp = idev->addr_list; ifp; ifp = ifp->if_next) {
2912 spin_lock_bh(&ifp->lock); 2949 spin_lock(&ifp->lock);
2913 if (!(ifp->flags & IFA_F_TENTATIVE)) { 2950 if (!(ifp->flags & IFA_F_TENTATIVE)) {
2914 spin_unlock_bh(&ifp->lock); 2951 spin_unlock(&ifp->lock);
2915 continue; 2952 continue;
2916 } 2953 }
2917 spin_unlock_bh(&ifp->lock); 2954 spin_unlock(&ifp->lock);
2918 addrconf_dad_kick(ifp); 2955 addrconf_dad_kick(ifp);
2919 } 2956 }
2920 read_unlock_bh(&idev->lock); 2957 read_unlock_bh(&idev->lock);
@@ -3031,14 +3068,14 @@ static const struct file_operations if6_fops = {
3031 .release = seq_release_net, 3068 .release = seq_release_net,
3032}; 3069};
3033 3070
3034static int if6_proc_net_init(struct net *net) 3071static int __net_init if6_proc_net_init(struct net *net)
3035{ 3072{
3036 if (!proc_net_fops_create(net, "if_inet6", S_IRUGO, &if6_fops)) 3073 if (!proc_net_fops_create(net, "if_inet6", S_IRUGO, &if6_fops))
3037 return -ENOMEM; 3074 return -ENOMEM;
3038 return 0; 3075 return 0;
3039} 3076}
3040 3077
3041static void if6_proc_net_exit(struct net *net) 3078static void __net_exit if6_proc_net_exit(struct net *net)
3042{ 3079{
3043 proc_net_remove(net, "if_inet6"); 3080 proc_net_remove(net, "if_inet6");
3044} 3081}
@@ -3485,85 +3522,114 @@ enum addr_type_t
3485 ANYCAST_ADDR, 3522 ANYCAST_ADDR,
3486}; 3523};
3487 3524
3525/* called with rcu_read_lock() */
3526static int in6_dump_addrs(struct inet6_dev *idev, struct sk_buff *skb,
3527 struct netlink_callback *cb, enum addr_type_t type,
3528 int s_ip_idx, int *p_ip_idx)
3529{
3530 struct inet6_ifaddr *ifa;
3531 struct ifmcaddr6 *ifmca;
3532 struct ifacaddr6 *ifaca;
3533 int err = 1;
3534 int ip_idx = *p_ip_idx;
3535
3536 read_lock_bh(&idev->lock);
3537 switch (type) {
3538 case UNICAST_ADDR:
3539 /* unicast address incl. temp addr */
3540 for (ifa = idev->addr_list; ifa;
3541 ifa = ifa->if_next, ip_idx++) {
3542 if (ip_idx < s_ip_idx)
3543 continue;
3544 err = inet6_fill_ifaddr(skb, ifa,
3545 NETLINK_CB(cb->skb).pid,
3546 cb->nlh->nlmsg_seq,
3547 RTM_NEWADDR,
3548 NLM_F_MULTI);
3549 if (err <= 0)
3550 break;
3551 }
3552 break;
3553 case MULTICAST_ADDR:
3554 /* multicast address */
3555 for (ifmca = idev->mc_list; ifmca;
3556 ifmca = ifmca->next, ip_idx++) {
3557 if (ip_idx < s_ip_idx)
3558 continue;
3559 err = inet6_fill_ifmcaddr(skb, ifmca,
3560 NETLINK_CB(cb->skb).pid,
3561 cb->nlh->nlmsg_seq,
3562 RTM_GETMULTICAST,
3563 NLM_F_MULTI);
3564 if (err <= 0)
3565 break;
3566 }
3567 break;
3568 case ANYCAST_ADDR:
3569 /* anycast address */
3570 for (ifaca = idev->ac_list; ifaca;
3571 ifaca = ifaca->aca_next, ip_idx++) {
3572 if (ip_idx < s_ip_idx)
3573 continue;
3574 err = inet6_fill_ifacaddr(skb, ifaca,
3575 NETLINK_CB(cb->skb).pid,
3576 cb->nlh->nlmsg_seq,
3577 RTM_GETANYCAST,
3578 NLM_F_MULTI);
3579 if (err <= 0)
3580 break;
3581 }
3582 break;
3583 default:
3584 break;
3585 }
3586 read_unlock_bh(&idev->lock);
3587 *p_ip_idx = ip_idx;
3588 return err;
3589}
3590
3488static int inet6_dump_addr(struct sk_buff *skb, struct netlink_callback *cb, 3591static int inet6_dump_addr(struct sk_buff *skb, struct netlink_callback *cb,
3489 enum addr_type_t type) 3592 enum addr_type_t type)
3490{ 3593{
3594 struct net *net = sock_net(skb->sk);
3595 int h, s_h;
3491 int idx, ip_idx; 3596 int idx, ip_idx;
3492 int s_idx, s_ip_idx; 3597 int s_idx, s_ip_idx;
3493 int err = 1;
3494 struct net_device *dev; 3598 struct net_device *dev;
3495 struct inet6_dev *idev = NULL; 3599 struct inet6_dev *idev;
3496 struct inet6_ifaddr *ifa; 3600 struct hlist_head *head;
3497 struct ifmcaddr6 *ifmca; 3601 struct hlist_node *node;
3498 struct ifacaddr6 *ifaca;
3499 struct net *net = sock_net(skb->sk);
3500 3602
3501 s_idx = cb->args[0]; 3603 s_h = cb->args[0];
3502 s_ip_idx = ip_idx = cb->args[1]; 3604 s_idx = idx = cb->args[1];
3605 s_ip_idx = ip_idx = cb->args[2];
3503 3606
3504 idx = 0; 3607 rcu_read_lock();
3505 for_each_netdev(net, dev) { 3608 for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) {
3506 if (idx < s_idx) 3609 idx = 0;
3507 goto cont; 3610 head = &net->dev_index_head[h];
3508 if (idx > s_idx) 3611 hlist_for_each_entry_rcu(dev, node, head, index_hlist) {
3509 s_ip_idx = 0; 3612 if (idx < s_idx)
3510 ip_idx = 0; 3613 goto cont;
3511 if ((idev = in6_dev_get(dev)) == NULL) 3614 if (h > s_h || idx > s_idx)
3512 goto cont; 3615 s_ip_idx = 0;
3513 read_lock_bh(&idev->lock); 3616 ip_idx = 0;
3514 switch (type) { 3617 if ((idev = __in6_dev_get(dev)) == NULL)
3515 case UNICAST_ADDR: 3618 goto cont;
3516 /* unicast address incl. temp addr */ 3619
3517 for (ifa = idev->addr_list; ifa; 3620 if (in6_dump_addrs(idev, skb, cb, type,
3518 ifa = ifa->if_next, ip_idx++) { 3621 s_ip_idx, &ip_idx) <= 0)
3519 if (ip_idx < s_ip_idx) 3622 goto done;
3520 continue;
3521 err = inet6_fill_ifaddr(skb, ifa,
3522 NETLINK_CB(cb->skb).pid,
3523 cb->nlh->nlmsg_seq,
3524 RTM_NEWADDR,
3525 NLM_F_MULTI);
3526 }
3527 break;
3528 case MULTICAST_ADDR:
3529 /* multicast address */
3530 for (ifmca = idev->mc_list; ifmca;
3531 ifmca = ifmca->next, ip_idx++) {
3532 if (ip_idx < s_ip_idx)
3533 continue;
3534 err = inet6_fill_ifmcaddr(skb, ifmca,
3535 NETLINK_CB(cb->skb).pid,
3536 cb->nlh->nlmsg_seq,
3537 RTM_GETMULTICAST,
3538 NLM_F_MULTI);
3539 }
3540 break;
3541 case ANYCAST_ADDR:
3542 /* anycast address */
3543 for (ifaca = idev->ac_list; ifaca;
3544 ifaca = ifaca->aca_next, ip_idx++) {
3545 if (ip_idx < s_ip_idx)
3546 continue;
3547 err = inet6_fill_ifacaddr(skb, ifaca,
3548 NETLINK_CB(cb->skb).pid,
3549 cb->nlh->nlmsg_seq,
3550 RTM_GETANYCAST,
3551 NLM_F_MULTI);
3552 }
3553 break;
3554 default:
3555 break;
3556 }
3557 read_unlock_bh(&idev->lock);
3558 in6_dev_put(idev);
3559
3560 if (err <= 0)
3561 break;
3562cont: 3623cont:
3563 idx++; 3624 idx++;
3625 }
3564 } 3626 }
3565 cb->args[0] = idx; 3627done:
3566 cb->args[1] = ip_idx; 3628 rcu_read_unlock();
3629 cb->args[0] = h;
3630 cb->args[1] = idx;
3631 cb->args[2] = ip_idx;
3632
3567 return skb->len; 3633 return skb->len;
3568} 3634}
3569 3635
@@ -3708,6 +3774,7 @@ static inline void ipv6_store_devconf(struct ipv6_devconf *cnf,
3708#endif 3774#endif
3709 array[DEVCONF_DISABLE_IPV6] = cnf->disable_ipv6; 3775 array[DEVCONF_DISABLE_IPV6] = cnf->disable_ipv6;
3710 array[DEVCONF_ACCEPT_DAD] = cnf->accept_dad; 3776 array[DEVCONF_ACCEPT_DAD] = cnf->accept_dad;
3777 array[DEVCONF_FORCE_TLLAO] = cnf->force_tllao;
3711} 3778}
3712 3779
3713static inline size_t inet6_if_nlmsg_size(void) 3780static inline size_t inet6_if_nlmsg_size(void)
@@ -3726,8 +3793,8 @@ static inline size_t inet6_if_nlmsg_size(void)
3726 ); 3793 );
3727} 3794}
3728 3795
3729static inline void __snmp6_fill_stats(u64 *stats, void **mib, int items, 3796static inline void __snmp6_fill_stats(u64 *stats, void __percpu **mib,
3730 int bytes) 3797 int items, int bytes)
3731{ 3798{
3732 int i; 3799 int i;
3733 int pad = bytes - sizeof(u64) * items; 3800 int pad = bytes - sizeof(u64) * items;
@@ -3746,10 +3813,10 @@ static void snmp6_fill_stats(u64 *stats, struct inet6_dev *idev, int attrtype,
3746{ 3813{
3747 switch(attrtype) { 3814 switch(attrtype) {
3748 case IFLA_INET6_STATS: 3815 case IFLA_INET6_STATS:
3749 __snmp6_fill_stats(stats, (void **)idev->stats.ipv6, IPSTATS_MIB_MAX, bytes); 3816 __snmp6_fill_stats(stats, (void __percpu **)idev->stats.ipv6, IPSTATS_MIB_MAX, bytes);
3750 break; 3817 break;
3751 case IFLA_INET6_ICMP6STATS: 3818 case IFLA_INET6_ICMP6STATS:
3752 __snmp6_fill_stats(stats, (void **)idev->stats.icmpv6, ICMP6_MIB_MAX, bytes); 3819 __snmp6_fill_stats(stats, (void __percpu **)idev->stats.icmpv6, ICMP6_MIB_MAX, bytes);
3753 break; 3820 break;
3754 } 3821 }
3755} 3822}
@@ -3826,28 +3893,39 @@ nla_put_failure:
3826static int inet6_dump_ifinfo(struct sk_buff *skb, struct netlink_callback *cb) 3893static int inet6_dump_ifinfo(struct sk_buff *skb, struct netlink_callback *cb)
3827{ 3894{
3828 struct net *net = sock_net(skb->sk); 3895 struct net *net = sock_net(skb->sk);
3829 int idx, err; 3896 int h, s_h;
3830 int s_idx = cb->args[0]; 3897 int idx = 0, s_idx;
3831 struct net_device *dev; 3898 struct net_device *dev;
3832 struct inet6_dev *idev; 3899 struct inet6_dev *idev;
3900 struct hlist_head *head;
3901 struct hlist_node *node;
3833 3902
3834 read_lock(&dev_base_lock); 3903 s_h = cb->args[0];
3835 idx = 0; 3904 s_idx = cb->args[1];
3836 for_each_netdev(net, dev) { 3905
3837 if (idx < s_idx) 3906 rcu_read_lock();
3838 goto cont; 3907 for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) {
3839 if ((idev = in6_dev_get(dev)) == NULL) 3908 idx = 0;
3840 goto cont; 3909 head = &net->dev_index_head[h];
3841 err = inet6_fill_ifinfo(skb, idev, NETLINK_CB(cb->skb).pid, 3910 hlist_for_each_entry_rcu(dev, node, head, index_hlist) {
3842 cb->nlh->nlmsg_seq, RTM_NEWLINK, NLM_F_MULTI); 3911 if (idx < s_idx)
3843 in6_dev_put(idev); 3912 goto cont;
3844 if (err <= 0) 3913 idev = __in6_dev_get(dev);
3845 break; 3914 if (!idev)
3915 goto cont;
3916 if (inet6_fill_ifinfo(skb, idev,
3917 NETLINK_CB(cb->skb).pid,
3918 cb->nlh->nlmsg_seq,
3919 RTM_NEWLINK, NLM_F_MULTI) <= 0)
3920 goto out;
3846cont: 3921cont:
3847 idx++; 3922 idx++;
3923 }
3848 } 3924 }
3849 read_unlock(&dev_base_lock); 3925out:
3850 cb->args[0] = idx; 3926 rcu_read_unlock();
3927 cb->args[1] = idx;
3928 cb->args[0] = h;
3851 3929
3852 return skb->len; 3930 return skb->len;
3853} 3931}
@@ -3991,50 +4069,18 @@ int addrconf_sysctl_forward(ctl_table *ctl, int write,
3991{ 4069{
3992 int *valp = ctl->data; 4070 int *valp = ctl->data;
3993 int val = *valp; 4071 int val = *valp;
4072 loff_t pos = *ppos;
3994 int ret; 4073 int ret;
3995 4074
3996 ret = proc_dointvec(ctl, write, buffer, lenp, ppos); 4075 ret = proc_dointvec(ctl, write, buffer, lenp, ppos);
3997 4076
3998 if (write) 4077 if (write)
3999 ret = addrconf_fixup_forwarding(ctl, valp, val); 4078 ret = addrconf_fixup_forwarding(ctl, valp, val);
4079 if (ret)
4080 *ppos = pos;
4000 return ret; 4081 return ret;
4001} 4082}
4002 4083
4003static int addrconf_sysctl_forward_strategy(ctl_table *table,
4004 void __user *oldval,
4005 size_t __user *oldlenp,
4006 void __user *newval, size_t newlen)
4007{
4008 int *valp = table->data;
4009 int val = *valp;
4010 int new;
4011
4012 if (!newval || !newlen)
4013 return 0;
4014 if (newlen != sizeof(int))
4015 return -EINVAL;
4016 if (get_user(new, (int __user *)newval))
4017 return -EFAULT;
4018 if (new == *valp)
4019 return 0;
4020 if (oldval && oldlenp) {
4021 size_t len;
4022 if (get_user(len, oldlenp))
4023 return -EFAULT;
4024 if (len) {
4025 if (len > table->maxlen)
4026 len = table->maxlen;
4027 if (copy_to_user(oldval, valp, len))
4028 return -EFAULT;
4029 if (put_user(len, oldlenp))
4030 return -EFAULT;
4031 }
4032 }
4033
4034 *valp = new;
4035 return addrconf_fixup_forwarding(table, valp, val);
4036}
4037
4038static void dev_disable_change(struct inet6_dev *idev) 4084static void dev_disable_change(struct inet6_dev *idev)
4039{ 4085{
4040 if (!idev || !idev->dev) 4086 if (!idev || !idev->dev)
@@ -4051,9 +4097,8 @@ static void addrconf_disable_change(struct net *net, __s32 newf)
4051 struct net_device *dev; 4097 struct net_device *dev;
4052 struct inet6_dev *idev; 4098 struct inet6_dev *idev;
4053 4099
4054 read_lock(&dev_base_lock); 4100 rcu_read_lock();
4055 for_each_netdev(net, dev) { 4101 for_each_netdev_rcu(net, dev) {
4056 rcu_read_lock();
4057 idev = __in6_dev_get(dev); 4102 idev = __in6_dev_get(dev);
4058 if (idev) { 4103 if (idev) {
4059 int changed = (!idev->cnf.disable_ipv6) ^ (!newf); 4104 int changed = (!idev->cnf.disable_ipv6) ^ (!newf);
@@ -4061,9 +4106,8 @@ static void addrconf_disable_change(struct net *net, __s32 newf)
4061 if (changed) 4106 if (changed)
4062 dev_disable_change(idev); 4107 dev_disable_change(idev);
4063 } 4108 }
4064 rcu_read_unlock();
4065 } 4109 }
4066 read_unlock(&dev_base_lock); 4110 rcu_read_unlock();
4067} 4111}
4068 4112
4069static int addrconf_disable_ipv6(struct ctl_table *table, int *p, int old) 4113static int addrconf_disable_ipv6(struct ctl_table *table, int *p, int old)
@@ -4075,8 +4119,11 @@ static int addrconf_disable_ipv6(struct ctl_table *table, int *p, int old)
4075 if (p == &net->ipv6.devconf_dflt->disable_ipv6) 4119 if (p == &net->ipv6.devconf_dflt->disable_ipv6)
4076 return 0; 4120 return 0;
4077 4121
4078 if (!rtnl_trylock()) 4122 if (!rtnl_trylock()) {
4123 /* Restore the original values before restarting */
4124 *p = old;
4079 return restart_syscall(); 4125 return restart_syscall();
4126 }
4080 4127
4081 if (p == &net->ipv6.devconf_all->disable_ipv6) { 4128 if (p == &net->ipv6.devconf_all->disable_ipv6) {
4082 __s32 newf = net->ipv6.devconf_all->disable_ipv6; 4129 __s32 newf = net->ipv6.devconf_all->disable_ipv6;
@@ -4095,12 +4142,15 @@ int addrconf_sysctl_disable(ctl_table *ctl, int write,
4095{ 4142{
4096 int *valp = ctl->data; 4143 int *valp = ctl->data;
4097 int val = *valp; 4144 int val = *valp;
4145 loff_t pos = *ppos;
4098 int ret; 4146 int ret;
4099 4147
4100 ret = proc_dointvec(ctl, write, buffer, lenp, ppos); 4148 ret = proc_dointvec(ctl, write, buffer, lenp, ppos);
4101 4149
4102 if (write) 4150 if (write)
4103 ret = addrconf_disable_ipv6(ctl, valp, val); 4151 ret = addrconf_disable_ipv6(ctl, valp, val);
4152 if (ret)
4153 *ppos = pos;
4104 return ret; 4154 return ret;
4105} 4155}
4106 4156
@@ -4113,16 +4163,13 @@ static struct addrconf_sysctl_table
4113 .sysctl_header = NULL, 4163 .sysctl_header = NULL,
4114 .addrconf_vars = { 4164 .addrconf_vars = {
4115 { 4165 {
4116 .ctl_name = NET_IPV6_FORWARDING,
4117 .procname = "forwarding", 4166 .procname = "forwarding",
4118 .data = &ipv6_devconf.forwarding, 4167 .data = &ipv6_devconf.forwarding,
4119 .maxlen = sizeof(int), 4168 .maxlen = sizeof(int),
4120 .mode = 0644, 4169 .mode = 0644,
4121 .proc_handler = addrconf_sysctl_forward, 4170 .proc_handler = addrconf_sysctl_forward,
4122 .strategy = addrconf_sysctl_forward_strategy,
4123 }, 4171 },
4124 { 4172 {
4125 .ctl_name = NET_IPV6_HOP_LIMIT,
4126 .procname = "hop_limit", 4173 .procname = "hop_limit",
4127 .data = &ipv6_devconf.hop_limit, 4174 .data = &ipv6_devconf.hop_limit,
4128 .maxlen = sizeof(int), 4175 .maxlen = sizeof(int),
@@ -4130,7 +4177,6 @@ static struct addrconf_sysctl_table
4130 .proc_handler = proc_dointvec, 4177 .proc_handler = proc_dointvec,
4131 }, 4178 },
4132 { 4179 {
4133 .ctl_name = NET_IPV6_MTU,
4134 .procname = "mtu", 4180 .procname = "mtu",
4135 .data = &ipv6_devconf.mtu6, 4181 .data = &ipv6_devconf.mtu6,
4136 .maxlen = sizeof(int), 4182 .maxlen = sizeof(int),
@@ -4138,7 +4184,6 @@ static struct addrconf_sysctl_table
4138 .proc_handler = proc_dointvec, 4184 .proc_handler = proc_dointvec,
4139 }, 4185 },
4140 { 4186 {
4141 .ctl_name = NET_IPV6_ACCEPT_RA,
4142 .procname = "accept_ra", 4187 .procname = "accept_ra",
4143 .data = &ipv6_devconf.accept_ra, 4188 .data = &ipv6_devconf.accept_ra,
4144 .maxlen = sizeof(int), 4189 .maxlen = sizeof(int),
@@ -4146,7 +4191,6 @@ static struct addrconf_sysctl_table
4146 .proc_handler = proc_dointvec, 4191 .proc_handler = proc_dointvec,
4147 }, 4192 },
4148 { 4193 {
4149 .ctl_name = NET_IPV6_ACCEPT_REDIRECTS,
4150 .procname = "accept_redirects", 4194 .procname = "accept_redirects",
4151 .data = &ipv6_devconf.accept_redirects, 4195 .data = &ipv6_devconf.accept_redirects,
4152 .maxlen = sizeof(int), 4196 .maxlen = sizeof(int),
@@ -4154,7 +4198,6 @@ static struct addrconf_sysctl_table
4154 .proc_handler = proc_dointvec, 4198 .proc_handler = proc_dointvec,
4155 }, 4199 },
4156 { 4200 {
4157 .ctl_name = NET_IPV6_AUTOCONF,
4158 .procname = "autoconf", 4201 .procname = "autoconf",
4159 .data = &ipv6_devconf.autoconf, 4202 .data = &ipv6_devconf.autoconf,
4160 .maxlen = sizeof(int), 4203 .maxlen = sizeof(int),
@@ -4162,7 +4205,6 @@ static struct addrconf_sysctl_table
4162 .proc_handler = proc_dointvec, 4205 .proc_handler = proc_dointvec,
4163 }, 4206 },
4164 { 4207 {
4165 .ctl_name = NET_IPV6_DAD_TRANSMITS,
4166 .procname = "dad_transmits", 4208 .procname = "dad_transmits",
4167 .data = &ipv6_devconf.dad_transmits, 4209 .data = &ipv6_devconf.dad_transmits,
4168 .maxlen = sizeof(int), 4210 .maxlen = sizeof(int),
@@ -4170,7 +4212,6 @@ static struct addrconf_sysctl_table
4170 .proc_handler = proc_dointvec, 4212 .proc_handler = proc_dointvec,
4171 }, 4213 },
4172 { 4214 {
4173 .ctl_name = NET_IPV6_RTR_SOLICITS,
4174 .procname = "router_solicitations", 4215 .procname = "router_solicitations",
4175 .data = &ipv6_devconf.rtr_solicits, 4216 .data = &ipv6_devconf.rtr_solicits,
4176 .maxlen = sizeof(int), 4217 .maxlen = sizeof(int),
@@ -4178,25 +4219,20 @@ static struct addrconf_sysctl_table
4178 .proc_handler = proc_dointvec, 4219 .proc_handler = proc_dointvec,
4179 }, 4220 },
4180 { 4221 {
4181 .ctl_name = NET_IPV6_RTR_SOLICIT_INTERVAL,
4182 .procname = "router_solicitation_interval", 4222 .procname = "router_solicitation_interval",
4183 .data = &ipv6_devconf.rtr_solicit_interval, 4223 .data = &ipv6_devconf.rtr_solicit_interval,
4184 .maxlen = sizeof(int), 4224 .maxlen = sizeof(int),
4185 .mode = 0644, 4225 .mode = 0644,
4186 .proc_handler = proc_dointvec_jiffies, 4226 .proc_handler = proc_dointvec_jiffies,
4187 .strategy = sysctl_jiffies,
4188 }, 4227 },
4189 { 4228 {
4190 .ctl_name = NET_IPV6_RTR_SOLICIT_DELAY,
4191 .procname = "router_solicitation_delay", 4229 .procname = "router_solicitation_delay",
4192 .data = &ipv6_devconf.rtr_solicit_delay, 4230 .data = &ipv6_devconf.rtr_solicit_delay,
4193 .maxlen = sizeof(int), 4231 .maxlen = sizeof(int),
4194 .mode = 0644, 4232 .mode = 0644,
4195 .proc_handler = proc_dointvec_jiffies, 4233 .proc_handler = proc_dointvec_jiffies,
4196 .strategy = sysctl_jiffies,
4197 }, 4234 },
4198 { 4235 {
4199 .ctl_name = NET_IPV6_FORCE_MLD_VERSION,
4200 .procname = "force_mld_version", 4236 .procname = "force_mld_version",
4201 .data = &ipv6_devconf.force_mld_version, 4237 .data = &ipv6_devconf.force_mld_version,
4202 .maxlen = sizeof(int), 4238 .maxlen = sizeof(int),
@@ -4205,7 +4241,6 @@ static struct addrconf_sysctl_table
4205 }, 4241 },
4206#ifdef CONFIG_IPV6_PRIVACY 4242#ifdef CONFIG_IPV6_PRIVACY
4207 { 4243 {
4208 .ctl_name = NET_IPV6_USE_TEMPADDR,
4209 .procname = "use_tempaddr", 4244 .procname = "use_tempaddr",
4210 .data = &ipv6_devconf.use_tempaddr, 4245 .data = &ipv6_devconf.use_tempaddr,
4211 .maxlen = sizeof(int), 4246 .maxlen = sizeof(int),
@@ -4213,7 +4248,6 @@ static struct addrconf_sysctl_table
4213 .proc_handler = proc_dointvec, 4248 .proc_handler = proc_dointvec,
4214 }, 4249 },
4215 { 4250 {
4216 .ctl_name = NET_IPV6_TEMP_VALID_LFT,
4217 .procname = "temp_valid_lft", 4251 .procname = "temp_valid_lft",
4218 .data = &ipv6_devconf.temp_valid_lft, 4252 .data = &ipv6_devconf.temp_valid_lft,
4219 .maxlen = sizeof(int), 4253 .maxlen = sizeof(int),
@@ -4221,7 +4255,6 @@ static struct addrconf_sysctl_table
4221 .proc_handler = proc_dointvec, 4255 .proc_handler = proc_dointvec,
4222 }, 4256 },
4223 { 4257 {
4224 .ctl_name = NET_IPV6_TEMP_PREFERED_LFT,
4225 .procname = "temp_prefered_lft", 4258 .procname = "temp_prefered_lft",
4226 .data = &ipv6_devconf.temp_prefered_lft, 4259 .data = &ipv6_devconf.temp_prefered_lft,
4227 .maxlen = sizeof(int), 4260 .maxlen = sizeof(int),
@@ -4229,7 +4262,6 @@ static struct addrconf_sysctl_table
4229 .proc_handler = proc_dointvec, 4262 .proc_handler = proc_dointvec,
4230 }, 4263 },
4231 { 4264 {
4232 .ctl_name = NET_IPV6_REGEN_MAX_RETRY,
4233 .procname = "regen_max_retry", 4265 .procname = "regen_max_retry",
4234 .data = &ipv6_devconf.regen_max_retry, 4266 .data = &ipv6_devconf.regen_max_retry,
4235 .maxlen = sizeof(int), 4267 .maxlen = sizeof(int),
@@ -4237,7 +4269,6 @@ static struct addrconf_sysctl_table
4237 .proc_handler = proc_dointvec, 4269 .proc_handler = proc_dointvec,
4238 }, 4270 },
4239 { 4271 {
4240 .ctl_name = NET_IPV6_MAX_DESYNC_FACTOR,
4241 .procname = "max_desync_factor", 4272 .procname = "max_desync_factor",
4242 .data = &ipv6_devconf.max_desync_factor, 4273 .data = &ipv6_devconf.max_desync_factor,
4243 .maxlen = sizeof(int), 4274 .maxlen = sizeof(int),
@@ -4246,7 +4277,6 @@ static struct addrconf_sysctl_table
4246 }, 4277 },
4247#endif 4278#endif
4248 { 4279 {
4249 .ctl_name = NET_IPV6_MAX_ADDRESSES,
4250 .procname = "max_addresses", 4280 .procname = "max_addresses",
4251 .data = &ipv6_devconf.max_addresses, 4281 .data = &ipv6_devconf.max_addresses,
4252 .maxlen = sizeof(int), 4282 .maxlen = sizeof(int),
@@ -4254,7 +4284,6 @@ static struct addrconf_sysctl_table
4254 .proc_handler = proc_dointvec, 4284 .proc_handler = proc_dointvec,
4255 }, 4285 },
4256 { 4286 {
4257 .ctl_name = NET_IPV6_ACCEPT_RA_DEFRTR,
4258 .procname = "accept_ra_defrtr", 4287 .procname = "accept_ra_defrtr",
4259 .data = &ipv6_devconf.accept_ra_defrtr, 4288 .data = &ipv6_devconf.accept_ra_defrtr,
4260 .maxlen = sizeof(int), 4289 .maxlen = sizeof(int),
@@ -4262,7 +4291,6 @@ static struct addrconf_sysctl_table
4262 .proc_handler = proc_dointvec, 4291 .proc_handler = proc_dointvec,
4263 }, 4292 },
4264 { 4293 {
4265 .ctl_name = NET_IPV6_ACCEPT_RA_PINFO,
4266 .procname = "accept_ra_pinfo", 4294 .procname = "accept_ra_pinfo",
4267 .data = &ipv6_devconf.accept_ra_pinfo, 4295 .data = &ipv6_devconf.accept_ra_pinfo,
4268 .maxlen = sizeof(int), 4296 .maxlen = sizeof(int),
@@ -4271,7 +4299,6 @@ static struct addrconf_sysctl_table
4271 }, 4299 },
4272#ifdef CONFIG_IPV6_ROUTER_PREF 4300#ifdef CONFIG_IPV6_ROUTER_PREF
4273 { 4301 {
4274 .ctl_name = NET_IPV6_ACCEPT_RA_RTR_PREF,
4275 .procname = "accept_ra_rtr_pref", 4302 .procname = "accept_ra_rtr_pref",
4276 .data = &ipv6_devconf.accept_ra_rtr_pref, 4303 .data = &ipv6_devconf.accept_ra_rtr_pref,
4277 .maxlen = sizeof(int), 4304 .maxlen = sizeof(int),
@@ -4279,17 +4306,14 @@ static struct addrconf_sysctl_table
4279 .proc_handler = proc_dointvec, 4306 .proc_handler = proc_dointvec,
4280 }, 4307 },
4281 { 4308 {
4282 .ctl_name = NET_IPV6_RTR_PROBE_INTERVAL,
4283 .procname = "router_probe_interval", 4309 .procname = "router_probe_interval",
4284 .data = &ipv6_devconf.rtr_probe_interval, 4310 .data = &ipv6_devconf.rtr_probe_interval,
4285 .maxlen = sizeof(int), 4311 .maxlen = sizeof(int),
4286 .mode = 0644, 4312 .mode = 0644,
4287 .proc_handler = proc_dointvec_jiffies, 4313 .proc_handler = proc_dointvec_jiffies,
4288 .strategy = sysctl_jiffies,
4289 }, 4314 },
4290#ifdef CONFIG_IPV6_ROUTE_INFO 4315#ifdef CONFIG_IPV6_ROUTE_INFO
4291 { 4316 {
4292 .ctl_name = NET_IPV6_ACCEPT_RA_RT_INFO_MAX_PLEN,
4293 .procname = "accept_ra_rt_info_max_plen", 4317 .procname = "accept_ra_rt_info_max_plen",
4294 .data = &ipv6_devconf.accept_ra_rt_info_max_plen, 4318 .data = &ipv6_devconf.accept_ra_rt_info_max_plen,
4295 .maxlen = sizeof(int), 4319 .maxlen = sizeof(int),
@@ -4299,7 +4323,6 @@ static struct addrconf_sysctl_table
4299#endif 4323#endif
4300#endif 4324#endif
4301 { 4325 {
4302 .ctl_name = NET_IPV6_PROXY_NDP,
4303 .procname = "proxy_ndp", 4326 .procname = "proxy_ndp",
4304 .data = &ipv6_devconf.proxy_ndp, 4327 .data = &ipv6_devconf.proxy_ndp,
4305 .maxlen = sizeof(int), 4328 .maxlen = sizeof(int),
@@ -4307,7 +4330,6 @@ static struct addrconf_sysctl_table
4307 .proc_handler = proc_dointvec, 4330 .proc_handler = proc_dointvec,
4308 }, 4331 },
4309 { 4332 {
4310 .ctl_name = NET_IPV6_ACCEPT_SOURCE_ROUTE,
4311 .procname = "accept_source_route", 4333 .procname = "accept_source_route",
4312 .data = &ipv6_devconf.accept_source_route, 4334 .data = &ipv6_devconf.accept_source_route,
4313 .maxlen = sizeof(int), 4335 .maxlen = sizeof(int),
@@ -4316,7 +4338,6 @@ static struct addrconf_sysctl_table
4316 }, 4338 },
4317#ifdef CONFIG_IPV6_OPTIMISTIC_DAD 4339#ifdef CONFIG_IPV6_OPTIMISTIC_DAD
4318 { 4340 {
4319 .ctl_name = CTL_UNNUMBERED,
4320 .procname = "optimistic_dad", 4341 .procname = "optimistic_dad",
4321 .data = &ipv6_devconf.optimistic_dad, 4342 .data = &ipv6_devconf.optimistic_dad,
4322 .maxlen = sizeof(int), 4343 .maxlen = sizeof(int),
@@ -4327,7 +4348,6 @@ static struct addrconf_sysctl_table
4327#endif 4348#endif
4328#ifdef CONFIG_IPV6_MROUTE 4349#ifdef CONFIG_IPV6_MROUTE
4329 { 4350 {
4330 .ctl_name = CTL_UNNUMBERED,
4331 .procname = "mc_forwarding", 4351 .procname = "mc_forwarding",
4332 .data = &ipv6_devconf.mc_forwarding, 4352 .data = &ipv6_devconf.mc_forwarding,
4333 .maxlen = sizeof(int), 4353 .maxlen = sizeof(int),
@@ -4336,16 +4356,13 @@ static struct addrconf_sysctl_table
4336 }, 4356 },
4337#endif 4357#endif
4338 { 4358 {
4339 .ctl_name = CTL_UNNUMBERED,
4340 .procname = "disable_ipv6", 4359 .procname = "disable_ipv6",
4341 .data = &ipv6_devconf.disable_ipv6, 4360 .data = &ipv6_devconf.disable_ipv6,
4342 .maxlen = sizeof(int), 4361 .maxlen = sizeof(int),
4343 .mode = 0644, 4362 .mode = 0644,
4344 .proc_handler = addrconf_sysctl_disable, 4363 .proc_handler = addrconf_sysctl_disable,
4345 .strategy = sysctl_intvec,
4346 }, 4364 },
4347 { 4365 {
4348 .ctl_name = CTL_UNNUMBERED,
4349 .procname = "accept_dad", 4366 .procname = "accept_dad",
4350 .data = &ipv6_devconf.accept_dad, 4367 .data = &ipv6_devconf.accept_dad,
4351 .maxlen = sizeof(int), 4368 .maxlen = sizeof(int),
@@ -4353,13 +4370,20 @@ static struct addrconf_sysctl_table
4353 .proc_handler = proc_dointvec, 4370 .proc_handler = proc_dointvec,
4354 }, 4371 },
4355 { 4372 {
4356 .ctl_name = 0, /* sentinel */ 4373 .procname = "force_tllao",
4374 .data = &ipv6_devconf.force_tllao,
4375 .maxlen = sizeof(int),
4376 .mode = 0644,
4377 .proc_handler = proc_dointvec
4378 },
4379 {
4380 /* sentinel */
4357 } 4381 }
4358 }, 4382 },
4359}; 4383};
4360 4384
4361static int __addrconf_sysctl_register(struct net *net, char *dev_name, 4385static int __addrconf_sysctl_register(struct net *net, char *dev_name,
4362 int ctl_name, struct inet6_dev *idev, struct ipv6_devconf *p) 4386 struct inet6_dev *idev, struct ipv6_devconf *p)
4363{ 4387{
4364 int i; 4388 int i;
4365 struct addrconf_sysctl_table *t; 4389 struct addrconf_sysctl_table *t;
@@ -4367,9 +4391,9 @@ static int __addrconf_sysctl_register(struct net *net, char *dev_name,
4367#define ADDRCONF_CTL_PATH_DEV 3 4391#define ADDRCONF_CTL_PATH_DEV 3
4368 4392
4369 struct ctl_path addrconf_ctl_path[] = { 4393 struct ctl_path addrconf_ctl_path[] = {
4370 { .procname = "net", .ctl_name = CTL_NET, }, 4394 { .procname = "net", },
4371 { .procname = "ipv6", .ctl_name = NET_IPV6, }, 4395 { .procname = "ipv6", },
4372 { .procname = "conf", .ctl_name = NET_IPV6_CONF, }, 4396 { .procname = "conf", },
4373 { /* to be set */ }, 4397 { /* to be set */ },
4374 { }, 4398 { },
4375 }; 4399 };
@@ -4395,7 +4419,6 @@ static int __addrconf_sysctl_register(struct net *net, char *dev_name,
4395 goto free; 4419 goto free;
4396 4420
4397 addrconf_ctl_path[ADDRCONF_CTL_PATH_DEV].procname = t->dev_name; 4421 addrconf_ctl_path[ADDRCONF_CTL_PATH_DEV].procname = t->dev_name;
4398 addrconf_ctl_path[ADDRCONF_CTL_PATH_DEV].ctl_name = ctl_name;
4399 4422
4400 t->sysctl_header = register_net_sysctl_table(net, addrconf_ctl_path, 4423 t->sysctl_header = register_net_sysctl_table(net, addrconf_ctl_path,
4401 t->addrconf_vars); 4424 t->addrconf_vars);
@@ -4429,12 +4452,10 @@ static void __addrconf_sysctl_unregister(struct ipv6_devconf *p)
4429 4452
4430static void addrconf_sysctl_register(struct inet6_dev *idev) 4453static void addrconf_sysctl_register(struct inet6_dev *idev)
4431{ 4454{
4432 neigh_sysctl_register(idev->dev, idev->nd_parms, NET_IPV6, 4455 neigh_sysctl_register(idev->dev, idev->nd_parms, "ipv6",
4433 NET_IPV6_NEIGH, "ipv6", 4456 &ndisc_ifinfo_sysctl_change);
4434 &ndisc_ifinfo_sysctl_change,
4435 ndisc_ifinfo_sysctl_strategy);
4436 __addrconf_sysctl_register(dev_net(idev->dev), idev->dev->name, 4457 __addrconf_sysctl_register(dev_net(idev->dev), idev->dev->name,
4437 idev->dev->ifindex, idev, &idev->cnf); 4458 idev, &idev->cnf);
4438} 4459}
4439 4460
4440static void addrconf_sysctl_unregister(struct inet6_dev *idev) 4461static void addrconf_sysctl_unregister(struct inet6_dev *idev)
@@ -4446,7 +4467,7 @@ static void addrconf_sysctl_unregister(struct inet6_dev *idev)
4446 4467
4447#endif 4468#endif
4448 4469
4449static int addrconf_init_net(struct net *net) 4470static int __net_init addrconf_init_net(struct net *net)
4450{ 4471{
4451 int err; 4472 int err;
4452 struct ipv6_devconf *all, *dflt; 4473 struct ipv6_devconf *all, *dflt;
@@ -4455,7 +4476,7 @@ static int addrconf_init_net(struct net *net)
4455 all = &ipv6_devconf; 4476 all = &ipv6_devconf;
4456 dflt = &ipv6_devconf_dflt; 4477 dflt = &ipv6_devconf_dflt;
4457 4478
4458 if (net != &init_net) { 4479 if (!net_eq(net, &init_net)) {
4459 all = kmemdup(all, sizeof(ipv6_devconf), GFP_KERNEL); 4480 all = kmemdup(all, sizeof(ipv6_devconf), GFP_KERNEL);
4460 if (all == NULL) 4481 if (all == NULL)
4461 goto err_alloc_all; 4482 goto err_alloc_all;
@@ -4473,13 +4494,11 @@ static int addrconf_init_net(struct net *net)
4473 net->ipv6.devconf_dflt = dflt; 4494 net->ipv6.devconf_dflt = dflt;
4474 4495
4475#ifdef CONFIG_SYSCTL 4496#ifdef CONFIG_SYSCTL
4476 err = __addrconf_sysctl_register(net, "all", NET_PROTO_CONF_ALL, 4497 err = __addrconf_sysctl_register(net, "all", NULL, all);
4477 NULL, all);
4478 if (err < 0) 4498 if (err < 0)
4479 goto err_reg_all; 4499 goto err_reg_all;
4480 4500
4481 err = __addrconf_sysctl_register(net, "default", NET_PROTO_CONF_DEFAULT, 4501 err = __addrconf_sysctl_register(net, "default", NULL, dflt);
4482 NULL, dflt);
4483 if (err < 0) 4502 if (err < 0)
4484 goto err_reg_dflt; 4503 goto err_reg_dflt;
4485#endif 4504#endif
@@ -4497,13 +4516,13 @@ err_alloc_all:
4497 return err; 4516 return err;
4498} 4517}
4499 4518
4500static void addrconf_exit_net(struct net *net) 4519static void __net_exit addrconf_exit_net(struct net *net)
4501{ 4520{
4502#ifdef CONFIG_SYSCTL 4521#ifdef CONFIG_SYSCTL
4503 __addrconf_sysctl_unregister(net->ipv6.devconf_dflt); 4522 __addrconf_sysctl_unregister(net->ipv6.devconf_dflt);
4504 __addrconf_sysctl_unregister(net->ipv6.devconf_all); 4523 __addrconf_sysctl_unregister(net->ipv6.devconf_all);
4505#endif 4524#endif
4506 if (net != &init_net) { 4525 if (!net_eq(net, &init_net)) {
4507 kfree(net->ipv6.devconf_dflt); 4526 kfree(net->ipv6.devconf_dflt);
4508 kfree(net->ipv6.devconf_all); 4527 kfree(net->ipv6.devconf_all);
4509 } 4528 }
diff --git a/net/ipv6/addrconf_core.c b/net/ipv6/addrconf_core.c
index 3f82e9542eda..6b03826552e1 100644
--- a/net/ipv6/addrconf_core.c
+++ b/net/ipv6/addrconf_core.c
@@ -72,7 +72,7 @@ int __ipv6_addr_type(const struct in6_addr *addr)
72 IPV6_ADDR_SCOPE_TYPE(IPV6_ADDR_SCOPE_GLOBAL)); /* addr-select 3.3 */ 72 IPV6_ADDR_SCOPE_TYPE(IPV6_ADDR_SCOPE_GLOBAL)); /* addr-select 3.3 */
73 } 73 }
74 74
75 return (IPV6_ADDR_RESERVED | 75 return (IPV6_ADDR_UNICAST |
76 IPV6_ADDR_SCOPE_TYPE(IPV6_ADDR_SCOPE_GLOBAL)); /* addr-select 3.4 */ 76 IPV6_ADDR_SCOPE_TYPE(IPV6_ADDR_SCOPE_GLOBAL)); /* addr-select 3.4 */
77} 77}
78EXPORT_SYMBOL(__ipv6_addr_type); 78EXPORT_SYMBOL(__ipv6_addr_type);
diff --git a/net/ipv6/addrlabel.c b/net/ipv6/addrlabel.c
index 6ff73c4c126a..ae404c9a746c 100644
--- a/net/ipv6/addrlabel.c
+++ b/net/ipv6/addrlabel.c
@@ -13,6 +13,7 @@
13#include <linux/list.h> 13#include <linux/list.h>
14#include <linux/rcupdate.h> 14#include <linux/rcupdate.h>
15#include <linux/in6.h> 15#include <linux/in6.h>
16#include <linux/slab.h>
16#include <net/addrconf.h> 17#include <net/addrconf.h>
17#include <linux/if_addrlabel.h> 18#include <linux/if_addrlabel.h>
18#include <linux/netlink.h> 19#include <linux/netlink.h>
diff --git a/net/ipv6/af_inet6.c b/net/ipv6/af_inet6.c
index e127a32f9540..3f9e86b15e0d 100644
--- a/net/ipv6/af_inet6.c
+++ b/net/ipv6/af_inet6.c
@@ -36,6 +36,7 @@
36#include <linux/proc_fs.h> 36#include <linux/proc_fs.h>
37#include <linux/stat.h> 37#include <linux/stat.h>
38#include <linux/init.h> 38#include <linux/init.h>
39#include <linux/slab.h>
39 40
40#include <linux/inet.h> 41#include <linux/inet.h>
41#include <linux/netdevice.h> 42#include <linux/netdevice.h>
@@ -95,7 +96,8 @@ static __inline__ struct ipv6_pinfo *inet6_sk_generic(struct sock *sk)
95 return (struct ipv6_pinfo *)(((u8 *)sk) + offset); 96 return (struct ipv6_pinfo *)(((u8 *)sk) + offset);
96} 97}
97 98
98static int inet6_create(struct net *net, struct socket *sock, int protocol) 99static int inet6_create(struct net *net, struct socket *sock, int protocol,
100 int kern)
99{ 101{
100 struct inet_sock *inet; 102 struct inet_sock *inet;
101 struct ipv6_pinfo *np; 103 struct ipv6_pinfo *np;
@@ -158,7 +160,7 @@ lookup_protocol:
158 } 160 }
159 161
160 err = -EPERM; 162 err = -EPERM;
161 if (answer->capability > 0 && !capable(answer->capability)) 163 if (sock->type == SOCK_RAW && !kern && !capable(CAP_NET_RAW))
162 goto out_rcu_unlock; 164 goto out_rcu_unlock;
163 165
164 sock->ops = answer->ops; 166 sock->ops = answer->ops;
@@ -185,7 +187,7 @@ lookup_protocol:
185 inet->is_icsk = (INET_PROTOSW_ICSK & answer_flags) != 0; 187 inet->is_icsk = (INET_PROTOSW_ICSK & answer_flags) != 0;
186 188
187 if (SOCK_RAW == sock->type) { 189 if (SOCK_RAW == sock->type) {
188 inet->num = protocol; 190 inet->inet_num = protocol;
189 if (IPPROTO_RAW == protocol) 191 if (IPPROTO_RAW == protocol)
190 inet->hdrincl = 1; 192 inet->hdrincl = 1;
191 } 193 }
@@ -198,7 +200,7 @@ lookup_protocol:
198 200
199 inet_sk(sk)->pinet6 = np = inet6_sk_generic(sk); 201 inet_sk(sk)->pinet6 = np = inet6_sk_generic(sk);
200 np->hop_limit = -1; 202 np->hop_limit = -1;
201 np->mcast_hops = -1; 203 np->mcast_hops = IPV6_DEFAULT_MCASTHOPS;
202 np->mc_loop = 1; 204 np->mc_loop = 1;
203 np->pmtudisc = IPV6_PMTUDISC_WANT; 205 np->pmtudisc = IPV6_PMTUDISC_WANT;
204 np->ipv6only = net->ipv6.sysctl.bindv6only; 206 np->ipv6only = net->ipv6.sysctl.bindv6only;
@@ -228,12 +230,12 @@ lookup_protocol:
228 */ 230 */
229 sk_refcnt_debug_inc(sk); 231 sk_refcnt_debug_inc(sk);
230 232
231 if (inet->num) { 233 if (inet->inet_num) {
232 /* It assumes that any protocol which allows 234 /* It assumes that any protocol which allows
233 * the user to assign a number at socket 235 * the user to assign a number at socket
234 * creation time automatically shares. 236 * creation time automatically shares.
235 */ 237 */
236 inet->sport = htons(inet->num); 238 inet->inet_sport = htons(inet->inet_num);
237 sk->sk_prot->hash(sk); 239 sk->sk_prot->hash(sk);
238 } 240 }
239 if (sk->sk_prot->init) { 241 if (sk->sk_prot->init) {
@@ -281,7 +283,7 @@ int inet6_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
281 lock_sock(sk); 283 lock_sock(sk);
282 284
283 /* Check these errors (active socket, double bind). */ 285 /* Check these errors (active socket, double bind). */
284 if (sk->sk_state != TCP_CLOSE || inet->num) { 286 if (sk->sk_state != TCP_CLOSE || inet->inet_num) {
285 err = -EINVAL; 287 err = -EINVAL;
286 goto out; 288 goto out;
287 } 289 }
@@ -314,6 +316,7 @@ int inet6_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
314 if (addr_type != IPV6_ADDR_ANY) { 316 if (addr_type != IPV6_ADDR_ANY) {
315 struct net_device *dev = NULL; 317 struct net_device *dev = NULL;
316 318
319 rcu_read_lock();
317 if (addr_type & IPV6_ADDR_LINKLOCAL) { 320 if (addr_type & IPV6_ADDR_LINKLOCAL) {
318 if (addr_len >= sizeof(struct sockaddr_in6) && 321 if (addr_len >= sizeof(struct sockaddr_in6) &&
319 addr->sin6_scope_id) { 322 addr->sin6_scope_id) {
@@ -326,12 +329,12 @@ int inet6_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
326 /* Binding to link-local address requires an interface */ 329 /* Binding to link-local address requires an interface */
327 if (!sk->sk_bound_dev_if) { 330 if (!sk->sk_bound_dev_if) {
328 err = -EINVAL; 331 err = -EINVAL;
329 goto out; 332 goto out_unlock;
330 } 333 }
331 dev = dev_get_by_index(net, sk->sk_bound_dev_if); 334 dev = dev_get_by_index_rcu(net, sk->sk_bound_dev_if);
332 if (!dev) { 335 if (!dev) {
333 err = -ENODEV; 336 err = -ENODEV;
334 goto out; 337 goto out_unlock;
335 } 338 }
336 } 339 }
337 340
@@ -342,19 +345,16 @@ int inet6_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
342 if (!(addr_type & IPV6_ADDR_MULTICAST)) { 345 if (!(addr_type & IPV6_ADDR_MULTICAST)) {
343 if (!ipv6_chk_addr(net, &addr->sin6_addr, 346 if (!ipv6_chk_addr(net, &addr->sin6_addr,
344 dev, 0)) { 347 dev, 0)) {
345 if (dev)
346 dev_put(dev);
347 err = -EADDRNOTAVAIL; 348 err = -EADDRNOTAVAIL;
348 goto out; 349 goto out_unlock;
349 } 350 }
350 } 351 }
351 if (dev) 352 rcu_read_unlock();
352 dev_put(dev);
353 } 353 }
354 } 354 }
355 355
356 inet->rcv_saddr = v4addr; 356 inet->inet_rcv_saddr = v4addr;
357 inet->saddr = v4addr; 357 inet->inet_saddr = v4addr;
358 358
359 ipv6_addr_copy(&np->rcv_saddr, &addr->sin6_addr); 359 ipv6_addr_copy(&np->rcv_saddr, &addr->sin6_addr);
360 360
@@ -375,12 +375,15 @@ int inet6_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
375 } 375 }
376 if (snum) 376 if (snum)
377 sk->sk_userlocks |= SOCK_BINDPORT_LOCK; 377 sk->sk_userlocks |= SOCK_BINDPORT_LOCK;
378 inet->sport = htons(inet->num); 378 inet->inet_sport = htons(inet->inet_num);
379 inet->dport = 0; 379 inet->inet_dport = 0;
380 inet->daddr = 0; 380 inet->inet_daddr = 0;
381out: 381out:
382 release_sock(sk); 382 release_sock(sk);
383 return err; 383 return err;
384out_unlock:
385 rcu_read_unlock();
386 goto out;
384} 387}
385 388
386EXPORT_SYMBOL(inet6_bind); 389EXPORT_SYMBOL(inet6_bind);
@@ -441,12 +444,12 @@ int inet6_getname(struct socket *sock, struct sockaddr *uaddr,
441 sin->sin6_flowinfo = 0; 444 sin->sin6_flowinfo = 0;
442 sin->sin6_scope_id = 0; 445 sin->sin6_scope_id = 0;
443 if (peer) { 446 if (peer) {
444 if (!inet->dport) 447 if (!inet->inet_dport)
445 return -ENOTCONN; 448 return -ENOTCONN;
446 if (((1 << sk->sk_state) & (TCPF_CLOSE | TCPF_SYN_SENT)) && 449 if (((1 << sk->sk_state) & (TCPF_CLOSE | TCPF_SYN_SENT)) &&
447 peer == 1) 450 peer == 1)
448 return -ENOTCONN; 451 return -ENOTCONN;
449 sin->sin6_port = inet->dport; 452 sin->sin6_port = inet->inet_dport;
450 ipv6_addr_copy(&sin->sin6_addr, &np->daddr); 453 ipv6_addr_copy(&sin->sin6_addr, &np->daddr);
451 if (np->sndflow) 454 if (np->sndflow)
452 sin->sin6_flowinfo = np->flow_label; 455 sin->sin6_flowinfo = np->flow_label;
@@ -456,7 +459,7 @@ int inet6_getname(struct socket *sock, struct sockaddr *uaddr,
456 else 459 else
457 ipv6_addr_copy(&sin->sin6_addr, &np->rcv_saddr); 460 ipv6_addr_copy(&sin->sin6_addr, &np->rcv_saddr);
458 461
459 sin->sin6_port = inet->sport; 462 sin->sin6_port = inet->inet_sport;
460 } 463 }
461 if (ipv6_addr_type(&sin->sin6_addr) & IPV6_ADDR_LINKLOCAL) 464 if (ipv6_addr_type(&sin->sin6_addr) & IPV6_ADDR_LINKLOCAL)
462 sin->sin6_scope_id = sk->sk_bound_dev_if; 465 sin->sin6_scope_id = sk->sk_bound_dev_if;
@@ -552,7 +555,7 @@ const struct proto_ops inet6_dgram_ops = {
552#endif 555#endif
553}; 556};
554 557
555static struct net_proto_family inet6_family_ops = { 558static const struct net_proto_family inet6_family_ops = {
556 .family = PF_INET6, 559 .family = PF_INET6,
557 .create = inet6_create, 560 .create = inet6_create,
558 .owner = THIS_MODULE, 561 .owner = THIS_MODULE,
@@ -654,8 +657,9 @@ int inet6_sk_rebuild_header(struct sock *sk)
654 ipv6_addr_copy(&fl.fl6_src, &np->saddr); 657 ipv6_addr_copy(&fl.fl6_src, &np->saddr);
655 fl.fl6_flowlabel = np->flow_label; 658 fl.fl6_flowlabel = np->flow_label;
656 fl.oif = sk->sk_bound_dev_if; 659 fl.oif = sk->sk_bound_dev_if;
657 fl.fl_ip_dport = inet->dport; 660 fl.mark = sk->sk_mark;
658 fl.fl_ip_sport = inet->sport; 661 fl.fl_ip_dport = inet->inet_dport;
662 fl.fl_ip_sport = inet->inet_sport;
659 security_sk_classify_flow(sk, &fl); 663 security_sk_classify_flow(sk, &fl);
660 664
661 if (np->opt && np->opt->srcrt) { 665 if (np->opt && np->opt->srcrt) {
@@ -968,41 +972,41 @@ static void ipv6_packet_cleanup(void)
968 972
969static int __net_init ipv6_init_mibs(struct net *net) 973static int __net_init ipv6_init_mibs(struct net *net)
970{ 974{
971 if (snmp_mib_init((void **)net->mib.udp_stats_in6, 975 if (snmp_mib_init((void __percpu **)net->mib.udp_stats_in6,
972 sizeof (struct udp_mib)) < 0) 976 sizeof (struct udp_mib)) < 0)
973 return -ENOMEM; 977 return -ENOMEM;
974 if (snmp_mib_init((void **)net->mib.udplite_stats_in6, 978 if (snmp_mib_init((void __percpu **)net->mib.udplite_stats_in6,
975 sizeof (struct udp_mib)) < 0) 979 sizeof (struct udp_mib)) < 0)
976 goto err_udplite_mib; 980 goto err_udplite_mib;
977 if (snmp_mib_init((void **)net->mib.ipv6_statistics, 981 if (snmp_mib_init((void __percpu **)net->mib.ipv6_statistics,
978 sizeof(struct ipstats_mib)) < 0) 982 sizeof(struct ipstats_mib)) < 0)
979 goto err_ip_mib; 983 goto err_ip_mib;
980 if (snmp_mib_init((void **)net->mib.icmpv6_statistics, 984 if (snmp_mib_init((void __percpu **)net->mib.icmpv6_statistics,
981 sizeof(struct icmpv6_mib)) < 0) 985 sizeof(struct icmpv6_mib)) < 0)
982 goto err_icmp_mib; 986 goto err_icmp_mib;
983 if (snmp_mib_init((void **)net->mib.icmpv6msg_statistics, 987 if (snmp_mib_init((void __percpu **)net->mib.icmpv6msg_statistics,
984 sizeof(struct icmpv6msg_mib)) < 0) 988 sizeof(struct icmpv6msg_mib)) < 0)
985 goto err_icmpmsg_mib; 989 goto err_icmpmsg_mib;
986 return 0; 990 return 0;
987 991
988err_icmpmsg_mib: 992err_icmpmsg_mib:
989 snmp_mib_free((void **)net->mib.icmpv6_statistics); 993 snmp_mib_free((void __percpu **)net->mib.icmpv6_statistics);
990err_icmp_mib: 994err_icmp_mib:
991 snmp_mib_free((void **)net->mib.ipv6_statistics); 995 snmp_mib_free((void __percpu **)net->mib.ipv6_statistics);
992err_ip_mib: 996err_ip_mib:
993 snmp_mib_free((void **)net->mib.udplite_stats_in6); 997 snmp_mib_free((void __percpu **)net->mib.udplite_stats_in6);
994err_udplite_mib: 998err_udplite_mib:
995 snmp_mib_free((void **)net->mib.udp_stats_in6); 999 snmp_mib_free((void __percpu **)net->mib.udp_stats_in6);
996 return -ENOMEM; 1000 return -ENOMEM;
997} 1001}
998 1002
999static void __net_exit ipv6_cleanup_mibs(struct net *net) 1003static void ipv6_cleanup_mibs(struct net *net)
1000{ 1004{
1001 snmp_mib_free((void **)net->mib.udp_stats_in6); 1005 snmp_mib_free((void __percpu **)net->mib.udp_stats_in6);
1002 snmp_mib_free((void **)net->mib.udplite_stats_in6); 1006 snmp_mib_free((void __percpu **)net->mib.udplite_stats_in6);
1003 snmp_mib_free((void **)net->mib.ipv6_statistics); 1007 snmp_mib_free((void __percpu **)net->mib.ipv6_statistics);
1004 snmp_mib_free((void **)net->mib.icmpv6_statistics); 1008 snmp_mib_free((void __percpu **)net->mib.icmpv6_statistics);
1005 snmp_mib_free((void **)net->mib.icmpv6msg_statistics); 1009 snmp_mib_free((void __percpu **)net->mib.icmpv6msg_statistics);
1006} 1010}
1007 1011
1008static int __net_init inet6_net_init(struct net *net) 1012static int __net_init inet6_net_init(struct net *net)
@@ -1039,7 +1043,7 @@ out:
1039#endif 1043#endif
1040} 1044}
1041 1045
1042static void inet6_net_exit(struct net *net) 1046static void __net_exit inet6_net_exit(struct net *net)
1043{ 1047{
1044#ifdef CONFIG_PROC_FS 1048#ifdef CONFIG_PROC_FS
1045 udp6_proc_exit(net); 1049 udp6_proc_exit(net);
diff --git a/net/ipv6/ah6.c b/net/ipv6/ah6.c
index c1589e2f1dc9..ee82d4ef26ce 100644
--- a/net/ipv6/ah6.c
+++ b/net/ipv6/ah6.c
@@ -24,18 +24,93 @@
24 * This file is derived from net/ipv4/ah.c. 24 * This file is derived from net/ipv4/ah.c.
25 */ 25 */
26 26
27#include <crypto/hash.h>
27#include <linux/module.h> 28#include <linux/module.h>
29#include <linux/slab.h>
28#include <net/ip.h> 30#include <net/ip.h>
29#include <net/ah.h> 31#include <net/ah.h>
30#include <linux/crypto.h> 32#include <linux/crypto.h>
31#include <linux/pfkeyv2.h> 33#include <linux/pfkeyv2.h>
32#include <linux/spinlock.h>
33#include <linux/string.h> 34#include <linux/string.h>
35#include <linux/scatterlist.h>
34#include <net/icmp.h> 36#include <net/icmp.h>
35#include <net/ipv6.h> 37#include <net/ipv6.h>
36#include <net/protocol.h> 38#include <net/protocol.h>
37#include <net/xfrm.h> 39#include <net/xfrm.h>
38 40
41#define IPV6HDR_BASELEN 8
42
43struct tmp_ext {
44#if defined(CONFIG_IPV6_MIP6) || defined(CONFIG_IPV6_MIP6_MODULE)
45 struct in6_addr saddr;
46#endif
47 struct in6_addr daddr;
48 char hdrs[0];
49};
50
51struct ah_skb_cb {
52 struct xfrm_skb_cb xfrm;
53 void *tmp;
54};
55
56#define AH_SKB_CB(__skb) ((struct ah_skb_cb *)&((__skb)->cb[0]))
57
58static void *ah_alloc_tmp(struct crypto_ahash *ahash, int nfrags,
59 unsigned int size)
60{
61 unsigned int len;
62
63 len = size + crypto_ahash_digestsize(ahash) +
64 (crypto_ahash_alignmask(ahash) &
65 ~(crypto_tfm_ctx_alignment() - 1));
66
67 len = ALIGN(len, crypto_tfm_ctx_alignment());
68
69 len += sizeof(struct ahash_request) + crypto_ahash_reqsize(ahash);
70 len = ALIGN(len, __alignof__(struct scatterlist));
71
72 len += sizeof(struct scatterlist) * nfrags;
73
74 return kmalloc(len, GFP_ATOMIC);
75}
76
77static inline struct tmp_ext *ah_tmp_ext(void *base)
78{
79 return base + IPV6HDR_BASELEN;
80}
81
82static inline u8 *ah_tmp_auth(u8 *tmp, unsigned int offset)
83{
84 return tmp + offset;
85}
86
87static inline u8 *ah_tmp_icv(struct crypto_ahash *ahash, void *tmp,
88 unsigned int offset)
89{
90 return PTR_ALIGN((u8 *)tmp + offset, crypto_ahash_alignmask(ahash) + 1);
91}
92
93static inline struct ahash_request *ah_tmp_req(struct crypto_ahash *ahash,
94 u8 *icv)
95{
96 struct ahash_request *req;
97
98 req = (void *)PTR_ALIGN(icv + crypto_ahash_digestsize(ahash),
99 crypto_tfm_ctx_alignment());
100
101 ahash_request_set_tfm(req, ahash);
102
103 return req;
104}
105
106static inline struct scatterlist *ah_req_sg(struct crypto_ahash *ahash,
107 struct ahash_request *req)
108{
109 return (void *)ALIGN((unsigned long)(req + 1) +
110 crypto_ahash_reqsize(ahash),
111 __alignof__(struct scatterlist));
112}
113
39static int zero_out_mutable_opts(struct ipv6_opt_hdr *opthdr) 114static int zero_out_mutable_opts(struct ipv6_opt_hdr *opthdr)
40{ 115{
41 u8 *opt = (u8 *)opthdr; 116 u8 *opt = (u8 *)opthdr;
@@ -218,24 +293,85 @@ static int ipv6_clear_mutable_options(struct ipv6hdr *iph, int len, int dir)
218 return 0; 293 return 0;
219} 294}
220 295
296static void ah6_output_done(struct crypto_async_request *base, int err)
297{
298 int extlen;
299 u8 *iph_base;
300 u8 *icv;
301 struct sk_buff *skb = base->data;
302 struct xfrm_state *x = skb_dst(skb)->xfrm;
303 struct ah_data *ahp = x->data;
304 struct ipv6hdr *top_iph = ipv6_hdr(skb);
305 struct ip_auth_hdr *ah = ip_auth_hdr(skb);
306 struct tmp_ext *iph_ext;
307
308 extlen = skb_network_header_len(skb) - sizeof(struct ipv6hdr);
309 if (extlen)
310 extlen += sizeof(*iph_ext);
311
312 iph_base = AH_SKB_CB(skb)->tmp;
313 iph_ext = ah_tmp_ext(iph_base);
314 icv = ah_tmp_icv(ahp->ahash, iph_ext, extlen);
315
316 memcpy(ah->auth_data, icv, ahp->icv_trunc_len);
317 memcpy(top_iph, iph_base, IPV6HDR_BASELEN);
318
319 if (extlen) {
320#if defined(CONFIG_IPV6_MIP6) || defined(CONFIG_IPV6_MIP6_MODULE)
321 memcpy(&top_iph->saddr, iph_ext, extlen);
322#else
323 memcpy(&top_iph->daddr, iph_ext, extlen);
324#endif
325 }
326
327 err = ah->nexthdr;
328
329 kfree(AH_SKB_CB(skb)->tmp);
330 xfrm_output_resume(skb, err);
331}
332
221static int ah6_output(struct xfrm_state *x, struct sk_buff *skb) 333static int ah6_output(struct xfrm_state *x, struct sk_buff *skb)
222{ 334{
223 int err; 335 int err;
336 int nfrags;
224 int extlen; 337 int extlen;
338 u8 *iph_base;
339 u8 *icv;
340 u8 nexthdr;
341 struct sk_buff *trailer;
342 struct crypto_ahash *ahash;
343 struct ahash_request *req;
344 struct scatterlist *sg;
225 struct ipv6hdr *top_iph; 345 struct ipv6hdr *top_iph;
226 struct ip_auth_hdr *ah; 346 struct ip_auth_hdr *ah;
227 struct ah_data *ahp; 347 struct ah_data *ahp;
228 u8 nexthdr; 348 struct tmp_ext *iph_ext;
229 char tmp_base[8]; 349
230 struct { 350 ahp = x->data;
231#if defined(CONFIG_IPV6_MIP6) || defined(CONFIG_IPV6_MIP6_MODULE) 351 ahash = ahp->ahash;
232 struct in6_addr saddr; 352
233#endif 353 if ((err = skb_cow_data(skb, 0, &trailer)) < 0)
234 struct in6_addr daddr; 354 goto out;
235 char hdrs[0]; 355 nfrags = err;
236 } *tmp_ext;
237 356
238 skb_push(skb, -skb_network_offset(skb)); 357 skb_push(skb, -skb_network_offset(skb));
358 extlen = skb_network_header_len(skb) - sizeof(struct ipv6hdr);
359 if (extlen)
360 extlen += sizeof(*iph_ext);
361
362 err = -ENOMEM;
363 iph_base = ah_alloc_tmp(ahash, nfrags, IPV6HDR_BASELEN + extlen);
364 if (!iph_base)
365 goto out;
366
367 iph_ext = ah_tmp_ext(iph_base);
368 icv = ah_tmp_icv(ahash, iph_ext, extlen);
369 req = ah_tmp_req(ahash, icv);
370 sg = ah_req_sg(ahash, req);
371
372 ah = ip_auth_hdr(skb);
373 memset(ah->auth_data, 0, ahp->icv_trunc_len);
374
239 top_iph = ipv6_hdr(skb); 375 top_iph = ipv6_hdr(skb);
240 top_iph->payload_len = htons(skb->len - sizeof(*top_iph)); 376 top_iph->payload_len = htons(skb->len - sizeof(*top_iph));
241 377
@@ -245,31 +381,22 @@ static int ah6_output(struct xfrm_state *x, struct sk_buff *skb)
245 /* When there are no extension headers, we only need to save the first 381 /* When there are no extension headers, we only need to save the first
246 * 8 bytes of the base IP header. 382 * 8 bytes of the base IP header.
247 */ 383 */
248 memcpy(tmp_base, top_iph, sizeof(tmp_base)); 384 memcpy(iph_base, top_iph, IPV6HDR_BASELEN);
249 385
250 tmp_ext = NULL;
251 extlen = skb_transport_offset(skb) - sizeof(struct ipv6hdr);
252 if (extlen) { 386 if (extlen) {
253 extlen += sizeof(*tmp_ext);
254 tmp_ext = kmalloc(extlen, GFP_ATOMIC);
255 if (!tmp_ext) {
256 err = -ENOMEM;
257 goto error;
258 }
259#if defined(CONFIG_IPV6_MIP6) || defined(CONFIG_IPV6_MIP6_MODULE) 387#if defined(CONFIG_IPV6_MIP6) || defined(CONFIG_IPV6_MIP6_MODULE)
260 memcpy(tmp_ext, &top_iph->saddr, extlen); 388 memcpy(iph_ext, &top_iph->saddr, extlen);
261#else 389#else
262 memcpy(tmp_ext, &top_iph->daddr, extlen); 390 memcpy(iph_ext, &top_iph->daddr, extlen);
263#endif 391#endif
264 err = ipv6_clear_mutable_options(top_iph, 392 err = ipv6_clear_mutable_options(top_iph,
265 extlen - sizeof(*tmp_ext) + 393 extlen - sizeof(*iph_ext) +
266 sizeof(*top_iph), 394 sizeof(*top_iph),
267 XFRM_POLICY_OUT); 395 XFRM_POLICY_OUT);
268 if (err) 396 if (err)
269 goto error_free_iph; 397 goto out_free;
270 } 398 }
271 399
272 ah = ip_auth_hdr(skb);
273 ah->nexthdr = nexthdr; 400 ah->nexthdr = nexthdr;
274 401
275 top_iph->priority = 0; 402 top_iph->priority = 0;
@@ -278,36 +405,80 @@ static int ah6_output(struct xfrm_state *x, struct sk_buff *skb)
278 top_iph->flow_lbl[2] = 0; 405 top_iph->flow_lbl[2] = 0;
279 top_iph->hop_limit = 0; 406 top_iph->hop_limit = 0;
280 407
281 ahp = x->data;
282 ah->hdrlen = (XFRM_ALIGN8(sizeof(*ah) + ahp->icv_trunc_len) >> 2) - 2; 408 ah->hdrlen = (XFRM_ALIGN8(sizeof(*ah) + ahp->icv_trunc_len) >> 2) - 2;
283 409
284 ah->reserved = 0; 410 ah->reserved = 0;
285 ah->spi = x->id.spi; 411 ah->spi = x->id.spi;
286 ah->seq_no = htonl(XFRM_SKB_CB(skb)->seq.output); 412 ah->seq_no = htonl(XFRM_SKB_CB(skb)->seq.output);
287 413
288 spin_lock_bh(&x->lock); 414 sg_init_table(sg, nfrags);
289 err = ah_mac_digest(ahp, skb, ah->auth_data); 415 skb_to_sgvec(skb, sg, 0, skb->len);
290 memcpy(ah->auth_data, ahp->work_icv, ahp->icv_trunc_len);
291 spin_unlock_bh(&x->lock);
292 416
293 if (err) 417 ahash_request_set_crypt(req, sg, icv, skb->len);
294 goto error_free_iph; 418 ahash_request_set_callback(req, 0, ah6_output_done, skb);
419
420 AH_SKB_CB(skb)->tmp = iph_base;
295 421
296 memcpy(top_iph, tmp_base, sizeof(tmp_base)); 422 err = crypto_ahash_digest(req);
297 if (tmp_ext) { 423 if (err) {
424 if (err == -EINPROGRESS)
425 goto out;
426
427 if (err == -EBUSY)
428 err = NET_XMIT_DROP;
429 goto out_free;
430 }
431
432 memcpy(ah->auth_data, icv, ahp->icv_trunc_len);
433 memcpy(top_iph, iph_base, IPV6HDR_BASELEN);
434
435 if (extlen) {
298#if defined(CONFIG_IPV6_MIP6) || defined(CONFIG_IPV6_MIP6_MODULE) 436#if defined(CONFIG_IPV6_MIP6) || defined(CONFIG_IPV6_MIP6_MODULE)
299 memcpy(&top_iph->saddr, tmp_ext, extlen); 437 memcpy(&top_iph->saddr, iph_ext, extlen);
300#else 438#else
301 memcpy(&top_iph->daddr, tmp_ext, extlen); 439 memcpy(&top_iph->daddr, iph_ext, extlen);
302#endif 440#endif
303error_free_iph:
304 kfree(tmp_ext);
305 } 441 }
306 442
307error: 443out_free:
444 kfree(iph_base);
445out:
308 return err; 446 return err;
309} 447}
310 448
449static void ah6_input_done(struct crypto_async_request *base, int err)
450{
451 u8 *auth_data;
452 u8 *icv;
453 u8 *work_iph;
454 struct sk_buff *skb = base->data;
455 struct xfrm_state *x = xfrm_input_state(skb);
456 struct ah_data *ahp = x->data;
457 struct ip_auth_hdr *ah = ip_auth_hdr(skb);
458 int hdr_len = skb_network_header_len(skb);
459 int ah_hlen = (ah->hdrlen + 2) << 2;
460
461 work_iph = AH_SKB_CB(skb)->tmp;
462 auth_data = ah_tmp_auth(work_iph, hdr_len);
463 icv = ah_tmp_icv(ahp->ahash, auth_data, ahp->icv_trunc_len);
464
465 err = memcmp(icv, auth_data, ahp->icv_trunc_len) ? -EBADMSG: 0;
466 if (err)
467 goto out;
468
469 skb->network_header += ah_hlen;
470 memcpy(skb_network_header(skb), work_iph, hdr_len);
471 __skb_pull(skb, ah_hlen + hdr_len);
472 skb_set_transport_header(skb, -hdr_len);
473
474 err = ah->nexthdr;
475out:
476 kfree(AH_SKB_CB(skb)->tmp);
477 xfrm_input_resume(skb, err);
478}
479
480
481
311static int ah6_input(struct xfrm_state *x, struct sk_buff *skb) 482static int ah6_input(struct xfrm_state *x, struct sk_buff *skb)
312{ 483{
313 /* 484 /*
@@ -325,14 +496,21 @@ static int ah6_input(struct xfrm_state *x, struct sk_buff *skb)
325 * There is offset of AH before IPv6 header after the process. 496 * There is offset of AH before IPv6 header after the process.
326 */ 497 */
327 498
499 u8 *auth_data;
500 u8 *icv;
501 u8 *work_iph;
502 struct sk_buff *trailer;
503 struct crypto_ahash *ahash;
504 struct ahash_request *req;
505 struct scatterlist *sg;
328 struct ip_auth_hdr *ah; 506 struct ip_auth_hdr *ah;
329 struct ipv6hdr *ip6h; 507 struct ipv6hdr *ip6h;
330 struct ah_data *ahp; 508 struct ah_data *ahp;
331 unsigned char *tmp_hdr = NULL;
332 u16 hdr_len; 509 u16 hdr_len;
333 u16 ah_hlen; 510 u16 ah_hlen;
334 int nexthdr; 511 int nexthdr;
335 int err = -EINVAL; 512 int nfrags;
513 int err = -ENOMEM;
336 514
337 if (!pskb_may_pull(skb, sizeof(struct ip_auth_hdr))) 515 if (!pskb_may_pull(skb, sizeof(struct ip_auth_hdr)))
338 goto out; 516 goto out;
@@ -345,9 +523,11 @@ static int ah6_input(struct xfrm_state *x, struct sk_buff *skb)
345 523
346 skb->ip_summed = CHECKSUM_NONE; 524 skb->ip_summed = CHECKSUM_NONE;
347 525
348 hdr_len = skb->data - skb_network_header(skb); 526 hdr_len = skb_network_header_len(skb);
349 ah = (struct ip_auth_hdr *)skb->data; 527 ah = (struct ip_auth_hdr *)skb->data;
350 ahp = x->data; 528 ahp = x->data;
529 ahash = ahp->ahash;
530
351 nexthdr = ah->nexthdr; 531 nexthdr = ah->nexthdr;
352 ah_hlen = (ah->hdrlen + 2) << 2; 532 ah_hlen = (ah->hdrlen + 2) << 2;
353 533
@@ -358,48 +538,67 @@ static int ah6_input(struct xfrm_state *x, struct sk_buff *skb)
358 if (!pskb_may_pull(skb, ah_hlen)) 538 if (!pskb_may_pull(skb, ah_hlen))
359 goto out; 539 goto out;
360 540
361 tmp_hdr = kmemdup(skb_network_header(skb), hdr_len, GFP_ATOMIC);
362 if (!tmp_hdr)
363 goto out;
364 ip6h = ipv6_hdr(skb); 541 ip6h = ipv6_hdr(skb);
542
543 skb_push(skb, hdr_len);
544
545 if ((err = skb_cow_data(skb, 0, &trailer)) < 0)
546 goto out;
547 nfrags = err;
548
549 work_iph = ah_alloc_tmp(ahash, nfrags, hdr_len + ahp->icv_trunc_len);
550 if (!work_iph)
551 goto out;
552
553 auth_data = ah_tmp_auth(work_iph, hdr_len);
554 icv = ah_tmp_icv(ahash, auth_data, ahp->icv_trunc_len);
555 req = ah_tmp_req(ahash, icv);
556 sg = ah_req_sg(ahash, req);
557
558 memcpy(work_iph, ip6h, hdr_len);
559 memcpy(auth_data, ah->auth_data, ahp->icv_trunc_len);
560 memset(ah->auth_data, 0, ahp->icv_trunc_len);
561
365 if (ipv6_clear_mutable_options(ip6h, hdr_len, XFRM_POLICY_IN)) 562 if (ipv6_clear_mutable_options(ip6h, hdr_len, XFRM_POLICY_IN))
366 goto free_out; 563 goto out_free;
564
367 ip6h->priority = 0; 565 ip6h->priority = 0;
368 ip6h->flow_lbl[0] = 0; 566 ip6h->flow_lbl[0] = 0;
369 ip6h->flow_lbl[1] = 0; 567 ip6h->flow_lbl[1] = 0;
370 ip6h->flow_lbl[2] = 0; 568 ip6h->flow_lbl[2] = 0;
371 ip6h->hop_limit = 0; 569 ip6h->hop_limit = 0;
372 570
373 spin_lock(&x->lock); 571 sg_init_table(sg, nfrags);
374 { 572 skb_to_sgvec(skb, sg, 0, skb->len);
375 u8 auth_data[MAX_AH_AUTH_LEN];
376 573
377 memcpy(auth_data, ah->auth_data, ahp->icv_trunc_len); 574 ahash_request_set_crypt(req, sg, icv, skb->len);
378 memset(ah->auth_data, 0, ahp->icv_trunc_len); 575 ahash_request_set_callback(req, 0, ah6_input_done, skb);
379 skb_push(skb, hdr_len); 576
380 err = ah_mac_digest(ahp, skb, ah->auth_data); 577 AH_SKB_CB(skb)->tmp = work_iph;
381 if (err) 578
382 goto unlock; 579 err = crypto_ahash_digest(req);
383 if (memcmp(ahp->work_icv, auth_data, ahp->icv_trunc_len)) 580 if (err) {
384 err = -EBADMSG; 581 if (err == -EINPROGRESS)
582 goto out;
583
584 if (err == -EBUSY)
585 err = NET_XMIT_DROP;
586 goto out_free;
385 } 587 }
386unlock:
387 spin_unlock(&x->lock);
388 588
589 err = memcmp(icv, auth_data, ahp->icv_trunc_len) ? -EBADMSG: 0;
389 if (err) 590 if (err)
390 goto free_out; 591 goto out_free;
391 592
392 skb->network_header += ah_hlen; 593 skb->network_header += ah_hlen;
393 memcpy(skb_network_header(skb), tmp_hdr, hdr_len); 594 memcpy(skb_network_header(skb), work_iph, hdr_len);
394 skb->transport_header = skb->network_header; 595 skb->transport_header = skb->network_header;
395 __skb_pull(skb, ah_hlen + hdr_len); 596 __skb_pull(skb, ah_hlen + hdr_len);
396 597
397 kfree(tmp_hdr); 598 err = nexthdr;
398 599
399 return nexthdr; 600out_free:
400 601 kfree(work_iph);
401free_out:
402 kfree(tmp_hdr);
403out: 602out:
404 return err; 603 return err;
405} 604}
@@ -416,7 +615,7 @@ static void ah6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
416 type != ICMPV6_PKT_TOOBIG) 615 type != ICMPV6_PKT_TOOBIG)
417 return; 616 return;
418 617
419 x = xfrm_state_lookup(net, (xfrm_address_t *)&iph->daddr, ah->spi, IPPROTO_AH, AF_INET6); 618 x = xfrm_state_lookup(net, skb->mark, (xfrm_address_t *)&iph->daddr, ah->spi, IPPROTO_AH, AF_INET6);
420 if (!x) 619 if (!x)
421 return; 620 return;
422 621
@@ -430,7 +629,7 @@ static int ah6_init_state(struct xfrm_state *x)
430{ 629{
431 struct ah_data *ahp = NULL; 630 struct ah_data *ahp = NULL;
432 struct xfrm_algo_desc *aalg_desc; 631 struct xfrm_algo_desc *aalg_desc;
433 struct crypto_hash *tfm; 632 struct crypto_ahash *ahash;
434 633
435 if (!x->aalg) 634 if (!x->aalg)
436 goto error; 635 goto error;
@@ -442,12 +641,12 @@ static int ah6_init_state(struct xfrm_state *x)
442 if (ahp == NULL) 641 if (ahp == NULL)
443 return -ENOMEM; 642 return -ENOMEM;
444 643
445 tfm = crypto_alloc_hash(x->aalg->alg_name, 0, CRYPTO_ALG_ASYNC); 644 ahash = crypto_alloc_ahash(x->aalg->alg_name, 0, 0);
446 if (IS_ERR(tfm)) 645 if (IS_ERR(ahash))
447 goto error; 646 goto error;
448 647
449 ahp->tfm = tfm; 648 ahp->ahash = ahash;
450 if (crypto_hash_setkey(tfm, x->aalg->alg_key, 649 if (crypto_ahash_setkey(ahash, x->aalg->alg_key,
451 (x->aalg->alg_key_len + 7) / 8)) 650 (x->aalg->alg_key_len + 7) / 8))
452 goto error; 651 goto error;
453 652
@@ -461,22 +660,18 @@ static int ah6_init_state(struct xfrm_state *x)
461 BUG_ON(!aalg_desc); 660 BUG_ON(!aalg_desc);
462 661
463 if (aalg_desc->uinfo.auth.icv_fullbits/8 != 662 if (aalg_desc->uinfo.auth.icv_fullbits/8 !=
464 crypto_hash_digestsize(tfm)) { 663 crypto_ahash_digestsize(ahash)) {
465 printk(KERN_INFO "AH: %s digestsize %u != %hu\n", 664 printk(KERN_INFO "AH: %s digestsize %u != %hu\n",
466 x->aalg->alg_name, crypto_hash_digestsize(tfm), 665 x->aalg->alg_name, crypto_ahash_digestsize(ahash),
467 aalg_desc->uinfo.auth.icv_fullbits/8); 666 aalg_desc->uinfo.auth.icv_fullbits/8);
468 goto error; 667 goto error;
469 } 668 }
470 669
471 ahp->icv_full_len = aalg_desc->uinfo.auth.icv_fullbits/8; 670 ahp->icv_full_len = aalg_desc->uinfo.auth.icv_fullbits/8;
472 ahp->icv_trunc_len = aalg_desc->uinfo.auth.icv_truncbits/8; 671 ahp->icv_trunc_len = x->aalg->alg_trunc_len/8;
473 672
474 BUG_ON(ahp->icv_trunc_len > MAX_AH_AUTH_LEN); 673 BUG_ON(ahp->icv_trunc_len > MAX_AH_AUTH_LEN);
475 674
476 ahp->work_icv = kmalloc(ahp->icv_full_len, GFP_KERNEL);
477 if (!ahp->work_icv)
478 goto error;
479
480 x->props.header_len = XFRM_ALIGN8(sizeof(struct ip_auth_hdr) + 675 x->props.header_len = XFRM_ALIGN8(sizeof(struct ip_auth_hdr) +
481 ahp->icv_trunc_len); 676 ahp->icv_trunc_len);
482 switch (x->props.mode) { 677 switch (x->props.mode) {
@@ -495,8 +690,7 @@ static int ah6_init_state(struct xfrm_state *x)
495 690
496error: 691error:
497 if (ahp) { 692 if (ahp) {
498 kfree(ahp->work_icv); 693 crypto_free_ahash(ahp->ahash);
499 crypto_free_hash(ahp->tfm);
500 kfree(ahp); 694 kfree(ahp);
501 } 695 }
502 return -EINVAL; 696 return -EINVAL;
@@ -509,8 +703,7 @@ static void ah6_destroy(struct xfrm_state *x)
509 if (!ahp) 703 if (!ahp)
510 return; 704 return;
511 705
512 kfree(ahp->work_icv); 706 crypto_free_ahash(ahp->ahash);
513 crypto_free_hash(ahp->tfm);
514 kfree(ahp); 707 kfree(ahp);
515} 708}
516 709
diff --git a/net/ipv6/anycast.c b/net/ipv6/anycast.c
index 1ae58bec1de0..b5b07054508a 100644
--- a/net/ipv6/anycast.c
+++ b/net/ipv6/anycast.c
@@ -29,6 +29,7 @@
29#include <linux/init.h> 29#include <linux/init.h>
30#include <linux/proc_fs.h> 30#include <linux/proc_fs.h>
31#include <linux/seq_file.h> 31#include <linux/seq_file.h>
32#include <linux/slab.h>
32 33
33#include <net/net_namespace.h> 34#include <net/net_namespace.h>
34#include <net/sock.h> 35#include <net/sock.h>
@@ -404,13 +405,13 @@ int ipv6_chk_acast_addr(struct net *net, struct net_device *dev,
404 405
405 if (dev) 406 if (dev)
406 return ipv6_chk_acast_dev(dev, addr); 407 return ipv6_chk_acast_dev(dev, addr);
407 read_lock(&dev_base_lock); 408 rcu_read_lock();
408 for_each_netdev(net, dev) 409 for_each_netdev_rcu(net, dev)
409 if (ipv6_chk_acast_dev(dev, addr)) { 410 if (ipv6_chk_acast_dev(dev, addr)) {
410 found = 1; 411 found = 1;
411 break; 412 break;
412 } 413 }
413 read_unlock(&dev_base_lock); 414 rcu_read_unlock();
414 return found; 415 return found;
415} 416}
416 417
@@ -431,9 +432,9 @@ static inline struct ifacaddr6 *ac6_get_first(struct seq_file *seq)
431 struct net *net = seq_file_net(seq); 432 struct net *net = seq_file_net(seq);
432 433
433 state->idev = NULL; 434 state->idev = NULL;
434 for_each_netdev(net, state->dev) { 435 for_each_netdev_rcu(net, state->dev) {
435 struct inet6_dev *idev; 436 struct inet6_dev *idev;
436 idev = in6_dev_get(state->dev); 437 idev = __in6_dev_get(state->dev);
437 if (!idev) 438 if (!idev)
438 continue; 439 continue;
439 read_lock_bh(&idev->lock); 440 read_lock_bh(&idev->lock);
@@ -443,7 +444,6 @@ static inline struct ifacaddr6 *ac6_get_first(struct seq_file *seq)
443 break; 444 break;
444 } 445 }
445 read_unlock_bh(&idev->lock); 446 read_unlock_bh(&idev->lock);
446 in6_dev_put(idev);
447 } 447 }
448 return im; 448 return im;
449} 449}
@@ -454,16 +454,15 @@ static struct ifacaddr6 *ac6_get_next(struct seq_file *seq, struct ifacaddr6 *im
454 454
455 im = im->aca_next; 455 im = im->aca_next;
456 while (!im) { 456 while (!im) {
457 if (likely(state->idev != NULL)) { 457 if (likely(state->idev != NULL))
458 read_unlock_bh(&state->idev->lock); 458 read_unlock_bh(&state->idev->lock);
459 in6_dev_put(state->idev); 459
460 } 460 state->dev = next_net_device_rcu(state->dev);
461 state->dev = next_net_device(state->dev);
462 if (!state->dev) { 461 if (!state->dev) {
463 state->idev = NULL; 462 state->idev = NULL;
464 break; 463 break;
465 } 464 }
466 state->idev = in6_dev_get(state->dev); 465 state->idev = __in6_dev_get(state->dev);
467 if (!state->idev) 466 if (!state->idev)
468 continue; 467 continue;
469 read_lock_bh(&state->idev->lock); 468 read_lock_bh(&state->idev->lock);
@@ -482,29 +481,30 @@ static struct ifacaddr6 *ac6_get_idx(struct seq_file *seq, loff_t pos)
482} 481}
483 482
484static void *ac6_seq_start(struct seq_file *seq, loff_t *pos) 483static void *ac6_seq_start(struct seq_file *seq, loff_t *pos)
485 __acquires(dev_base_lock) 484 __acquires(RCU)
486{ 485{
487 read_lock(&dev_base_lock); 486 rcu_read_lock();
488 return ac6_get_idx(seq, *pos); 487 return ac6_get_idx(seq, *pos);
489} 488}
490 489
491static void *ac6_seq_next(struct seq_file *seq, void *v, loff_t *pos) 490static void *ac6_seq_next(struct seq_file *seq, void *v, loff_t *pos)
492{ 491{
493 struct ifacaddr6 *im; 492 struct ifacaddr6 *im = ac6_get_next(seq, v);
494 im = ac6_get_next(seq, v); 493
495 ++*pos; 494 ++*pos;
496 return im; 495 return im;
497} 496}
498 497
499static void ac6_seq_stop(struct seq_file *seq, void *v) 498static void ac6_seq_stop(struct seq_file *seq, void *v)
500 __releases(dev_base_lock) 499 __releases(RCU)
501{ 500{
502 struct ac6_iter_state *state = ac6_seq_private(seq); 501 struct ac6_iter_state *state = ac6_seq_private(seq);
502
503 if (likely(state->idev != NULL)) { 503 if (likely(state->idev != NULL)) {
504 read_unlock_bh(&state->idev->lock); 504 read_unlock_bh(&state->idev->lock);
505 in6_dev_put(state->idev); 505 state->idev = NULL;
506 } 506 }
507 read_unlock(&dev_base_lock); 507 rcu_read_unlock();
508} 508}
509 509
510static int ac6_seq_show(struct seq_file *seq, void *v) 510static int ac6_seq_show(struct seq_file *seq, void *v)
@@ -539,7 +539,7 @@ static const struct file_operations ac6_seq_fops = {
539 .release = seq_release_net, 539 .release = seq_release_net,
540}; 540};
541 541
542int ac6_proc_init(struct net *net) 542int __net_init ac6_proc_init(struct net *net)
543{ 543{
544 if (!proc_net_fops_create(net, "anycast6", S_IRUGO, &ac6_seq_fops)) 544 if (!proc_net_fops_create(net, "anycast6", S_IRUGO, &ac6_seq_fops))
545 return -ENOMEM; 545 return -ENOMEM;
diff --git a/net/ipv6/datagram.c b/net/ipv6/datagram.c
index e2bdc6d83a43..61573885e451 100644
--- a/net/ipv6/datagram.c
+++ b/net/ipv6/datagram.c
@@ -21,6 +21,7 @@
21#include <linux/in6.h> 21#include <linux/in6.h>
22#include <linux/ipv6.h> 22#include <linux/ipv6.h>
23#include <linux/route.h> 23#include <linux/route.h>
24#include <linux/slab.h>
24 25
25#include <net/ipv6.h> 26#include <net/ipv6.h>
26#include <net/ndisc.h> 27#include <net/ndisc.h>
@@ -98,17 +99,15 @@ ipv4_connected:
98 if (err) 99 if (err)
99 goto out; 100 goto out;
100 101
101 ipv6_addr_set(&np->daddr, 0, 0, htonl(0x0000ffff), inet->daddr); 102 ipv6_addr_set_v4mapped(inet->inet_daddr, &np->daddr);
102 103
103 if (ipv6_addr_any(&np->saddr)) { 104 if (ipv6_addr_any(&np->saddr))
104 ipv6_addr_set(&np->saddr, 0, 0, htonl(0x0000ffff), 105 ipv6_addr_set_v4mapped(inet->inet_saddr, &np->saddr);
105 inet->saddr); 106
106 } 107 if (ipv6_addr_any(&np->rcv_saddr))
108 ipv6_addr_set_v4mapped(inet->inet_rcv_saddr,
109 &np->rcv_saddr);
107 110
108 if (ipv6_addr_any(&np->rcv_saddr)) {
109 ipv6_addr_set(&np->rcv_saddr, 0, 0, htonl(0x0000ffff),
110 inet->rcv_saddr);
111 }
112 goto out; 111 goto out;
113 } 112 }
114 113
@@ -136,7 +135,7 @@ ipv4_connected:
136 ipv6_addr_copy(&np->daddr, daddr); 135 ipv6_addr_copy(&np->daddr, daddr);
137 np->flow_label = fl.fl6_flowlabel; 136 np->flow_label = fl.fl6_flowlabel;
138 137
139 inet->dport = usin->sin6_port; 138 inet->inet_dport = usin->sin6_port;
140 139
141 /* 140 /*
142 * Check for a route to destination an obtain the 141 * Check for a route to destination an obtain the
@@ -147,8 +146,9 @@ ipv4_connected:
147 ipv6_addr_copy(&fl.fl6_dst, &np->daddr); 146 ipv6_addr_copy(&fl.fl6_dst, &np->daddr);
148 ipv6_addr_copy(&fl.fl6_src, &np->saddr); 147 ipv6_addr_copy(&fl.fl6_src, &np->saddr);
149 fl.oif = sk->sk_bound_dev_if; 148 fl.oif = sk->sk_bound_dev_if;
150 fl.fl_ip_dport = inet->dport; 149 fl.mark = sk->sk_mark;
151 fl.fl_ip_sport = inet->sport; 150 fl.fl_ip_dport = inet->inet_dport;
151 fl.fl_ip_sport = inet->inet_sport;
152 152
153 if (!fl.oif && (addr_type&IPV6_ADDR_MULTICAST)) 153 if (!fl.oif && (addr_type&IPV6_ADDR_MULTICAST))
154 fl.oif = np->mcast_oif; 154 fl.oif = np->mcast_oif;
@@ -190,7 +190,7 @@ ipv4_connected:
190 190
191 if (ipv6_addr_any(&np->rcv_saddr)) { 191 if (ipv6_addr_any(&np->rcv_saddr)) {
192 ipv6_addr_copy(&np->rcv_saddr, &fl.fl6_src); 192 ipv6_addr_copy(&np->rcv_saddr, &fl.fl6_src);
193 inet->rcv_saddr = LOOPBACK4_IPV6; 193 inet->inet_rcv_saddr = LOOPBACK4_IPV6;
194 } 194 }
195 195
196 ip6_dst_store(sk, dst, 196 ip6_dst_store(sk, dst,
@@ -222,6 +222,8 @@ void ipv6_icmp_error(struct sock *sk, struct sk_buff *skb, int err,
222 if (!skb) 222 if (!skb)
223 return; 223 return;
224 224
225 skb->protocol = htons(ETH_P_IPV6);
226
225 serr = SKB_EXT_ERR(skb); 227 serr = SKB_EXT_ERR(skb);
226 serr->ee.ee_errno = err; 228 serr->ee.ee_errno = err;
227 serr->ee.ee_origin = SO_EE_ORIGIN_ICMP6; 229 serr->ee.ee_origin = SO_EE_ORIGIN_ICMP6;
@@ -255,6 +257,8 @@ void ipv6_local_error(struct sock *sk, int err, struct flowi *fl, u32 info)
255 if (!skb) 257 if (!skb)
256 return; 258 return;
257 259
260 skb->protocol = htons(ETH_P_IPV6);
261
258 skb_put(skb, sizeof(struct ipv6hdr)); 262 skb_put(skb, sizeof(struct ipv6hdr));
259 skb_reset_network_header(skb); 263 skb_reset_network_header(skb);
260 iph = ipv6_hdr(skb); 264 iph = ipv6_hdr(skb);
@@ -319,7 +323,7 @@ int ipv6_recv_error(struct sock *sk, struct msghdr *msg, int len)
319 sin->sin6_flowinfo = 0; 323 sin->sin6_flowinfo = 0;
320 sin->sin6_port = serr->port; 324 sin->sin6_port = serr->port;
321 sin->sin6_scope_id = 0; 325 sin->sin6_scope_id = 0;
322 if (serr->ee.ee_origin == SO_EE_ORIGIN_ICMP6) { 326 if (skb->protocol == htons(ETH_P_IPV6)) {
323 ipv6_addr_copy(&sin->sin6_addr, 327 ipv6_addr_copy(&sin->sin6_addr,
324 (struct in6_addr *)(nh + serr->addr_offset)); 328 (struct in6_addr *)(nh + serr->addr_offset));
325 if (np->sndflow) 329 if (np->sndflow)
@@ -329,9 +333,8 @@ int ipv6_recv_error(struct sock *sk, struct msghdr *msg, int len)
329 if (ipv6_addr_type(&sin->sin6_addr) & IPV6_ADDR_LINKLOCAL) 333 if (ipv6_addr_type(&sin->sin6_addr) & IPV6_ADDR_LINKLOCAL)
330 sin->sin6_scope_id = IP6CB(skb)->iif; 334 sin->sin6_scope_id = IP6CB(skb)->iif;
331 } else { 335 } else {
332 ipv6_addr_set(&sin->sin6_addr, 0, 0, 336 ipv6_addr_set_v4mapped(*(__be32 *)(nh + serr->addr_offset),
333 htonl(0xffff), 337 &sin->sin6_addr);
334 *(__be32 *)(nh + serr->addr_offset));
335 } 338 }
336 } 339 }
337 340
@@ -342,7 +345,7 @@ int ipv6_recv_error(struct sock *sk, struct msghdr *msg, int len)
342 sin->sin6_family = AF_INET6; 345 sin->sin6_family = AF_INET6;
343 sin->sin6_flowinfo = 0; 346 sin->sin6_flowinfo = 0;
344 sin->sin6_scope_id = 0; 347 sin->sin6_scope_id = 0;
345 if (serr->ee.ee_origin == SO_EE_ORIGIN_ICMP6) { 348 if (skb->protocol == htons(ETH_P_IPV6)) {
346 ipv6_addr_copy(&sin->sin6_addr, &ipv6_hdr(skb)->saddr); 349 ipv6_addr_copy(&sin->sin6_addr, &ipv6_hdr(skb)->saddr);
347 if (np->rxopt.all) 350 if (np->rxopt.all)
348 datagram_recv_ctl(sk, msg, skb); 351 datagram_recv_ctl(sk, msg, skb);
@@ -351,8 +354,8 @@ int ipv6_recv_error(struct sock *sk, struct msghdr *msg, int len)
351 } else { 354 } else {
352 struct inet_sock *inet = inet_sk(sk); 355 struct inet_sock *inet = inet_sk(sk);
353 356
354 ipv6_addr_set(&sin->sin6_addr, 0, 0, 357 ipv6_addr_set_v4mapped(ip_hdr(skb)->saddr,
355 htonl(0xffff), ip_hdr(skb)->saddr); 358 &sin->sin6_addr);
356 if (inet->cmsg_flags) 359 if (inet->cmsg_flags)
357 ip_cmsg_recv(msg, skb); 360 ip_cmsg_recv(msg, skb);
358 } 361 }
@@ -539,12 +542,17 @@ int datagram_send_ctl(struct net *net,
539 542
540 addr_type = __ipv6_addr_type(&src_info->ipi6_addr); 543 addr_type = __ipv6_addr_type(&src_info->ipi6_addr);
541 544
545 rcu_read_lock();
542 if (fl->oif) { 546 if (fl->oif) {
543 dev = dev_get_by_index(net, fl->oif); 547 dev = dev_get_by_index_rcu(net, fl->oif);
544 if (!dev) 548 if (!dev) {
549 rcu_read_unlock();
545 return -ENODEV; 550 return -ENODEV;
546 } else if (addr_type & IPV6_ADDR_LINKLOCAL) 551 }
552 } else if (addr_type & IPV6_ADDR_LINKLOCAL) {
553 rcu_read_unlock();
547 return -EINVAL; 554 return -EINVAL;
555 }
548 556
549 if (addr_type != IPV6_ADDR_ANY) { 557 if (addr_type != IPV6_ADDR_ANY) {
550 int strict = __ipv6_addr_src_scope(addr_type) <= IPV6_ADDR_SCOPE_LINKLOCAL; 558 int strict = __ipv6_addr_src_scope(addr_type) <= IPV6_ADDR_SCOPE_LINKLOCAL;
@@ -555,8 +563,7 @@ int datagram_send_ctl(struct net *net,
555 ipv6_addr_copy(&fl->fl6_src, &src_info->ipi6_addr); 563 ipv6_addr_copy(&fl->fl6_src, &src_info->ipi6_addr);
556 } 564 }
557 565
558 if (dev) 566 rcu_read_unlock();
559 dev_put(dev);
560 567
561 if (err) 568 if (err)
562 goto exit_f; 569 goto exit_f;
diff --git a/net/ipv6/esp6.c b/net/ipv6/esp6.c
index af597c73ebe9..ee9b93bdd6a2 100644
--- a/net/ipv6/esp6.c
+++ b/net/ipv6/esp6.c
@@ -365,7 +365,7 @@ static void esp6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
365 type != ICMPV6_PKT_TOOBIG) 365 type != ICMPV6_PKT_TOOBIG)
366 return; 366 return;
367 367
368 x = xfrm_state_lookup(net, (xfrm_address_t *)&iph->daddr, esph->spi, IPPROTO_ESP, AF_INET6); 368 x = xfrm_state_lookup(net, skb->mark, (xfrm_address_t *)&iph->daddr, esph->spi, IPPROTO_ESP, AF_INET6);
369 if (!x) 369 if (!x)
370 return; 370 return;
371 printk(KERN_DEBUG "pmtu discovery on SA ESP/%08x/%pI6\n", 371 printk(KERN_DEBUG "pmtu discovery on SA ESP/%08x/%pI6\n",
@@ -473,7 +473,7 @@ static int esp_init_authenc(struct xfrm_state *x)
473 } 473 }
474 474
475 err = crypto_aead_setauthsize( 475 err = crypto_aead_setauthsize(
476 aead, aalg_desc->uinfo.auth.icv_truncbits / 8); 476 aead, x->aalg->alg_trunc_len / 8);
477 if (err) 477 if (err)
478 goto free_key; 478 goto free_key;
479 } 479 }
diff --git a/net/ipv6/exthdrs.c b/net/ipv6/exthdrs.c
index df159fffe4bc..8a659f92d17a 100644
--- a/net/ipv6/exthdrs.c
+++ b/net/ipv6/exthdrs.c
@@ -29,6 +29,7 @@
29#include <linux/netdevice.h> 29#include <linux/netdevice.h>
30#include <linux/in6.h> 30#include <linux/in6.h>
31#include <linux/icmpv6.h> 31#include <linux/icmpv6.h>
32#include <linux/slab.h>
32 33
33#include <net/dst.h> 34#include <net/dst.h>
34#include <net/sock.h> 35#include <net/sock.h>
@@ -481,7 +482,7 @@ looped_back:
481 IP6_INC_STATS_BH(net, ip6_dst_idev(skb_dst(skb)), 482 IP6_INC_STATS_BH(net, ip6_dst_idev(skb_dst(skb)),
482 IPSTATS_MIB_INHDRERRORS); 483 IPSTATS_MIB_INHDRERRORS);
483 icmpv6_send(skb, ICMPV6_TIME_EXCEED, ICMPV6_EXC_HOPLIMIT, 484 icmpv6_send(skb, ICMPV6_TIME_EXCEED, ICMPV6_EXC_HOPLIMIT,
484 0, skb->dev); 485 0);
485 kfree_skb(skb); 486 kfree_skb(skb);
486 return -1; 487 return -1;
487 } 488 }
@@ -559,6 +560,11 @@ static inline struct inet6_dev *ipv6_skb_idev(struct sk_buff *skb)
559 return skb_dst(skb) ? ip6_dst_idev(skb_dst(skb)) : __in6_dev_get(skb->dev); 560 return skb_dst(skb) ? ip6_dst_idev(skb_dst(skb)) : __in6_dev_get(skb->dev);
560} 561}
561 562
563static inline struct net *ipv6_skb_net(struct sk_buff *skb)
564{
565 return skb_dst(skb) ? dev_net(skb_dst(skb)->dev) : dev_net(skb->dev);
566}
567
562/* Router Alert as of RFC 2711 */ 568/* Router Alert as of RFC 2711 */
563 569
564static int ipv6_hop_ra(struct sk_buff *skb, int optoff) 570static int ipv6_hop_ra(struct sk_buff *skb, int optoff)
@@ -580,8 +586,8 @@ static int ipv6_hop_ra(struct sk_buff *skb, int optoff)
580static int ipv6_hop_jumbo(struct sk_buff *skb, int optoff) 586static int ipv6_hop_jumbo(struct sk_buff *skb, int optoff)
581{ 587{
582 const unsigned char *nh = skb_network_header(skb); 588 const unsigned char *nh = skb_network_header(skb);
589 struct net *net = ipv6_skb_net(skb);
583 u32 pkt_len; 590 u32 pkt_len;
584 struct net *net = dev_net(skb_dst(skb)->dev);
585 591
586 if (nh[optoff + 1] != 4 || (optoff & 3) != 2) { 592 if (nh[optoff + 1] != 4 || (optoff & 3) != 2) {
587 LIMIT_NETDEBUG(KERN_DEBUG "ipv6_hop_jumbo: wrong jumbo opt length/alignment %d\n", 593 LIMIT_NETDEBUG(KERN_DEBUG "ipv6_hop_jumbo: wrong jumbo opt length/alignment %d\n",
diff --git a/net/ipv6/fib6_rules.c b/net/ipv6/fib6_rules.c
index 00a7a5e4ac97..5e463c43fcc2 100644
--- a/net/ipv6/fib6_rules.c
+++ b/net/ipv6/fib6_rules.c
@@ -84,18 +84,11 @@ static int fib6_rule_action(struct fib_rule *rule, struct flowi *flp,
84 if ((rule->flags & FIB_RULE_FIND_SADDR) && 84 if ((rule->flags & FIB_RULE_FIND_SADDR) &&
85 r->src.plen && !(flags & RT6_LOOKUP_F_HAS_SADDR)) { 85 r->src.plen && !(flags & RT6_LOOKUP_F_HAS_SADDR)) {
86 struct in6_addr saddr; 86 struct in6_addr saddr;
87 unsigned int srcprefs = 0;
88
89 if (flags & RT6_LOOKUP_F_SRCPREF_TMP)
90 srcprefs |= IPV6_PREFER_SRC_TMP;
91 if (flags & RT6_LOOKUP_F_SRCPREF_PUBLIC)
92 srcprefs |= IPV6_PREFER_SRC_PUBLIC;
93 if (flags & RT6_LOOKUP_F_SRCPREF_COA)
94 srcprefs |= IPV6_PREFER_SRC_COA;
95 87
96 if (ipv6_dev_get_saddr(net, 88 if (ipv6_dev_get_saddr(net,
97 ip6_dst_idev(&rt->u.dst)->dev, 89 ip6_dst_idev(&rt->u.dst)->dev,
98 &flp->fl6_dst, srcprefs, 90 &flp->fl6_dst,
91 rt6_flags2srcprefs(flags),
99 &saddr)) 92 &saddr))
100 goto again; 93 goto again;
101 if (!ipv6_prefix_equal(&saddr, &r->src.addr, 94 if (!ipv6_prefix_equal(&saddr, &r->src.addr,
@@ -262,46 +255,38 @@ static struct fib_rules_ops fib6_rules_ops_template = {
262 .fro_net = &init_net, 255 .fro_net = &init_net,
263}; 256};
264 257
265static int fib6_rules_net_init(struct net *net) 258static int __net_init fib6_rules_net_init(struct net *net)
266{ 259{
260 struct fib_rules_ops *ops;
267 int err = -ENOMEM; 261 int err = -ENOMEM;
268 262
269 net->ipv6.fib6_rules_ops = kmemdup(&fib6_rules_ops_template, 263 ops = fib_rules_register(&fib6_rules_ops_template, net);
270 sizeof(*net->ipv6.fib6_rules_ops), 264 if (IS_ERR(ops))
271 GFP_KERNEL); 265 return PTR_ERR(ops);
272 if (!net->ipv6.fib6_rules_ops) 266 net->ipv6.fib6_rules_ops = ops;
273 goto out;
274 267
275 net->ipv6.fib6_rules_ops->fro_net = net;
276 INIT_LIST_HEAD(&net->ipv6.fib6_rules_ops->rules_list);
277 268
278 err = fib_default_rule_add(net->ipv6.fib6_rules_ops, 0, 269 err = fib_default_rule_add(net->ipv6.fib6_rules_ops, 0,
279 RT6_TABLE_LOCAL, FIB_RULE_PERMANENT); 270 RT6_TABLE_LOCAL, 0);
280 if (err) 271 if (err)
281 goto out_fib6_rules_ops; 272 goto out_fib6_rules_ops;
282 273
283 err = fib_default_rule_add(net->ipv6.fib6_rules_ops, 274 err = fib_default_rule_add(net->ipv6.fib6_rules_ops,
284 0x7FFE, RT6_TABLE_MAIN, 0); 275 0x7FFE, RT6_TABLE_MAIN, 0);
285 if (err) 276 if (err)
286 goto out_fib6_default_rule_add; 277 goto out_fib6_rules_ops;
287 278
288 err = fib_rules_register(net->ipv6.fib6_rules_ops);
289 if (err)
290 goto out_fib6_default_rule_add;
291out: 279out:
292 return err; 280 return err;
293 281
294out_fib6_default_rule_add:
295 fib_rules_cleanup_ops(net->ipv6.fib6_rules_ops);
296out_fib6_rules_ops: 282out_fib6_rules_ops:
297 kfree(net->ipv6.fib6_rules_ops); 283 fib_rules_unregister(ops);
298 goto out; 284 goto out;
299} 285}
300 286
301static void fib6_rules_net_exit(struct net *net) 287static void __net_exit fib6_rules_net_exit(struct net *net)
302{ 288{
303 fib_rules_unregister(net->ipv6.fib6_rules_ops); 289 fib_rules_unregister(net->ipv6.fib6_rules_ops);
304 kfree(net->ipv6.fib6_rules_ops);
305} 290}
306 291
307static struct pernet_operations fib6_rules_net_ops = { 292static struct pernet_operations fib6_rules_net_ops = {
diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c
index f23ebbec0631..3330a4bd6157 100644
--- a/net/ipv6/icmp.c
+++ b/net/ipv6/icmp.c
@@ -40,6 +40,7 @@
40#include <linux/skbuff.h> 40#include <linux/skbuff.h>
41#include <linux/init.h> 41#include <linux/init.h>
42#include <linux/netfilter.h> 42#include <linux/netfilter.h>
43#include <linux/slab.h>
43 44
44#ifdef CONFIG_SYSCTL 45#ifdef CONFIG_SYSCTL
45#include <linux/sysctl.h> 46#include <linux/sysctl.h>
@@ -67,11 +68,6 @@
67#include <asm/uaccess.h> 68#include <asm/uaccess.h>
68#include <asm/system.h> 69#include <asm/system.h>
69 70
70DEFINE_SNMP_STAT(struct icmpv6_mib, icmpv6_statistics) __read_mostly;
71EXPORT_SYMBOL(icmpv6_statistics);
72DEFINE_SNMP_STAT(struct icmpv6msg_mib, icmpv6msg_statistics) __read_mostly;
73EXPORT_SYMBOL(icmpv6msg_statistics);
74
75/* 71/*
76 * The ICMP socket(s). This is the most convenient way to flow control 72 * The ICMP socket(s). This is the most convenient way to flow control
77 * our ICMP output as well as maintain a clean interface throughout 73 * our ICMP output as well as maintain a clean interface throughout
@@ -119,7 +115,7 @@ static __inline__ void icmpv6_xmit_unlock(struct sock *sk)
119 */ 115 */
120void icmpv6_param_prob(struct sk_buff *skb, u8 code, int pos) 116void icmpv6_param_prob(struct sk_buff *skb, u8 code, int pos)
121{ 117{
122 icmpv6_send(skb, ICMPV6_PARAMPROB, code, pos, skb->dev); 118 icmpv6_send(skb, ICMPV6_PARAMPROB, code, pos);
123 kfree_skb(skb); 119 kfree_skb(skb);
124} 120}
125 121
@@ -305,8 +301,7 @@ static inline void mip6_addr_swap(struct sk_buff *skb) {}
305/* 301/*
306 * Send an ICMP message in response to a packet in error 302 * Send an ICMP message in response to a packet in error
307 */ 303 */
308void icmpv6_send(struct sk_buff *skb, u8 type, u8 code, __u32 info, 304void icmpv6_send(struct sk_buff *skb, u8 type, u8 code, __u32 info)
309 struct net_device *dev)
310{ 305{
311 struct net *net = dev_net(skb->dev); 306 struct net *net = dev_net(skb->dev);
312 struct inet6_dev *idev = NULL; 307 struct inet6_dev *idev = NULL;
@@ -942,18 +937,16 @@ EXPORT_SYMBOL(icmpv6_err_convert);
942#ifdef CONFIG_SYSCTL 937#ifdef CONFIG_SYSCTL
943ctl_table ipv6_icmp_table_template[] = { 938ctl_table ipv6_icmp_table_template[] = {
944 { 939 {
945 .ctl_name = NET_IPV6_ICMP_RATELIMIT,
946 .procname = "ratelimit", 940 .procname = "ratelimit",
947 .data = &init_net.ipv6.sysctl.icmpv6_time, 941 .data = &init_net.ipv6.sysctl.icmpv6_time,
948 .maxlen = sizeof(int), 942 .maxlen = sizeof(int),
949 .mode = 0644, 943 .mode = 0644,
950 .proc_handler = proc_dointvec_ms_jiffies, 944 .proc_handler = proc_dointvec_ms_jiffies,
951 .strategy = sysctl_ms_jiffies
952 }, 945 },
953 { .ctl_name = 0 }, 946 { },
954}; 947};
955 948
956struct ctl_table *ipv6_icmp_sysctl_init(struct net *net) 949struct ctl_table * __net_init ipv6_icmp_sysctl_init(struct net *net)
957{ 950{
958 struct ctl_table *table; 951 struct ctl_table *table;
959 952
diff --git a/net/ipv6/inet6_connection_sock.c b/net/ipv6/inet6_connection_sock.c
index cc4797dd8325..628db24bcf22 100644
--- a/net/ipv6/inet6_connection_sock.c
+++ b/net/ipv6/inet6_connection_sock.c
@@ -17,6 +17,7 @@
17#include <linux/in6.h> 17#include <linux/in6.h>
18#include <linux/ipv6.h> 18#include <linux/ipv6.h>
19#include <linux/jhash.h> 19#include <linux/jhash.h>
20#include <linux/slab.h>
20 21
21#include <net/addrconf.h> 22#include <net/addrconf.h>
22#include <net/inet_connection_sock.h> 23#include <net/inet_connection_sock.h>
@@ -132,7 +133,7 @@ void inet6_csk_addr2sockaddr(struct sock *sk, struct sockaddr * uaddr)
132 133
133 sin6->sin6_family = AF_INET6; 134 sin6->sin6_family = AF_INET6;
134 ipv6_addr_copy(&sin6->sin6_addr, &np->daddr); 135 ipv6_addr_copy(&sin6->sin6_addr, &np->daddr);
135 sin6->sin6_port = inet_sk(sk)->dport; 136 sin6->sin6_port = inet_sk(sk)->inet_dport;
136 /* We do not store received flowlabel for TCP */ 137 /* We do not store received flowlabel for TCP */
137 sin6->sin6_flowinfo = 0; 138 sin6->sin6_flowinfo = 0;
138 sin6->sin6_scope_id = 0; 139 sin6->sin6_scope_id = 0;
@@ -168,8 +169,7 @@ struct dst_entry *__inet6_csk_dst_check(struct sock *sk, u32 cookie)
168 if (dst) { 169 if (dst) {
169 struct rt6_info *rt = (struct rt6_info *)dst; 170 struct rt6_info *rt = (struct rt6_info *)dst;
170 if (rt->rt6i_flow_cache_genid != atomic_read(&flow_cache_genid)) { 171 if (rt->rt6i_flow_cache_genid != atomic_read(&flow_cache_genid)) {
171 sk->sk_dst_cache = NULL; 172 __sk_dst_reset(sk);
172 dst_release(dst);
173 dst = NULL; 173 dst = NULL;
174 } 174 }
175 } 175 }
@@ -194,8 +194,9 @@ int inet6_csk_xmit(struct sk_buff *skb, int ipfragok)
194 fl.fl6_flowlabel = np->flow_label; 194 fl.fl6_flowlabel = np->flow_label;
195 IP6_ECN_flow_xmit(sk, fl.fl6_flowlabel); 195 IP6_ECN_flow_xmit(sk, fl.fl6_flowlabel);
196 fl.oif = sk->sk_bound_dev_if; 196 fl.oif = sk->sk_bound_dev_if;
197 fl.fl_ip_sport = inet->sport; 197 fl.mark = sk->sk_mark;
198 fl.fl_ip_dport = inet->dport; 198 fl.fl_ip_sport = inet->inet_sport;
199 fl.fl_ip_dport = inet->inet_dport;
199 security_sk_classify_flow(sk, &fl); 200 security_sk_classify_flow(sk, &fl);
200 201
201 if (np->opt && np->opt->srcrt) { 202 if (np->opt && np->opt->srcrt) {
diff --git a/net/ipv6/inet6_hashtables.c b/net/ipv6/inet6_hashtables.c
index 1bcc3431859e..633a6c266136 100644
--- a/net/ipv6/inet6_hashtables.c
+++ b/net/ipv6/inet6_hashtables.c
@@ -22,9 +22,10 @@
22#include <net/inet6_hashtables.h> 22#include <net/inet6_hashtables.h>
23#include <net/ip.h> 23#include <net/ip.h>
24 24
25void __inet6_hash(struct sock *sk) 25int __inet6_hash(struct sock *sk, struct inet_timewait_sock *tw)
26{ 26{
27 struct inet_hashinfo *hashinfo = sk->sk_prot->h.hashinfo; 27 struct inet_hashinfo *hashinfo = sk->sk_prot->h.hashinfo;
28 int twrefcnt = 0;
28 29
29 WARN_ON(!sk_unhashed(sk)); 30 WARN_ON(!sk_unhashed(sk));
30 31
@@ -45,10 +46,15 @@ void __inet6_hash(struct sock *sk)
45 lock = inet_ehash_lockp(hashinfo, hash); 46 lock = inet_ehash_lockp(hashinfo, hash);
46 spin_lock(lock); 47 spin_lock(lock);
47 __sk_nulls_add_node_rcu(sk, list); 48 __sk_nulls_add_node_rcu(sk, list);
49 if (tw) {
50 WARN_ON(sk->sk_hash != tw->tw_hash);
51 twrefcnt = inet_twsk_unhash(tw);
52 }
48 spin_unlock(lock); 53 spin_unlock(lock);
49 } 54 }
50 55
51 sock_prot_inuse_add(sock_net(sk), sk->sk_prot, 1); 56 sock_prot_inuse_add(sock_net(sk), sk->sk_prot, 1);
57 return twrefcnt;
52} 58}
53EXPORT_SYMBOL(__inet6_hash); 59EXPORT_SYMBOL(__inet6_hash);
54 60
@@ -73,7 +79,7 @@ struct sock *__inet6_lookup_established(struct net *net,
73 * have wildcards anyways. 79 * have wildcards anyways.
74 */ 80 */
75 unsigned int hash = inet6_ehashfn(net, daddr, hnum, saddr, sport); 81 unsigned int hash = inet6_ehashfn(net, daddr, hnum, saddr, sport);
76 unsigned int slot = hash & (hashinfo->ehash_size - 1); 82 unsigned int slot = hash & hashinfo->ehash_mask;
77 struct inet_ehash_bucket *head = &hashinfo->ehash[slot]; 83 struct inet_ehash_bucket *head = &hashinfo->ehash[slot];
78 84
79 85
@@ -125,7 +131,7 @@ static int inline compute_score(struct sock *sk, struct net *net,
125{ 131{
126 int score = -1; 132 int score = -1;
127 133
128 if (net_eq(sock_net(sk), net) && inet_sk(sk)->num == hnum && 134 if (net_eq(sock_net(sk), net) && inet_sk(sk)->inet_num == hnum &&
129 sk->sk_family == PF_INET6) { 135 sk->sk_family == PF_INET6) {
130 const struct ipv6_pinfo *np = inet6_sk(sk); 136 const struct ipv6_pinfo *np = inet6_sk(sk);
131 137
@@ -214,15 +220,16 @@ static int __inet6_check_established(struct inet_timewait_death_row *death_row,
214 const struct in6_addr *daddr = &np->rcv_saddr; 220 const struct in6_addr *daddr = &np->rcv_saddr;
215 const struct in6_addr *saddr = &np->daddr; 221 const struct in6_addr *saddr = &np->daddr;
216 const int dif = sk->sk_bound_dev_if; 222 const int dif = sk->sk_bound_dev_if;
217 const __portpair ports = INET_COMBINED_PORTS(inet->dport, lport); 223 const __portpair ports = INET_COMBINED_PORTS(inet->inet_dport, lport);
218 struct net *net = sock_net(sk); 224 struct net *net = sock_net(sk);
219 const unsigned int hash = inet6_ehashfn(net, daddr, lport, saddr, 225 const unsigned int hash = inet6_ehashfn(net, daddr, lport, saddr,
220 inet->dport); 226 inet->inet_dport);
221 struct inet_ehash_bucket *head = inet_ehash_bucket(hinfo, hash); 227 struct inet_ehash_bucket *head = inet_ehash_bucket(hinfo, hash);
222 spinlock_t *lock = inet_ehash_lockp(hinfo, hash); 228 spinlock_t *lock = inet_ehash_lockp(hinfo, hash);
223 struct sock *sk2; 229 struct sock *sk2;
224 const struct hlist_nulls_node *node; 230 const struct hlist_nulls_node *node;
225 struct inet_timewait_sock *tw; 231 struct inet_timewait_sock *tw;
232 int twrefcnt = 0;
226 233
227 spin_lock(lock); 234 spin_lock(lock);
228 235
@@ -248,21 +255,25 @@ static int __inet6_check_established(struct inet_timewait_death_row *death_row,
248unique: 255unique:
249 /* Must record num and sport now. Otherwise we will see 256 /* Must record num and sport now. Otherwise we will see
250 * in hash table socket with a funny identity. */ 257 * in hash table socket with a funny identity. */
251 inet->num = lport; 258 inet->inet_num = lport;
252 inet->sport = htons(lport); 259 inet->inet_sport = htons(lport);
260 sk->sk_hash = hash;
253 WARN_ON(!sk_unhashed(sk)); 261 WARN_ON(!sk_unhashed(sk));
254 __sk_nulls_add_node_rcu(sk, &head->chain); 262 __sk_nulls_add_node_rcu(sk, &head->chain);
255 sk->sk_hash = hash; 263 if (tw) {
264 twrefcnt = inet_twsk_unhash(tw);
265 NET_INC_STATS_BH(net, LINUX_MIB_TIMEWAITRECYCLED);
266 }
256 spin_unlock(lock); 267 spin_unlock(lock);
268 if (twrefcnt)
269 inet_twsk_put(tw);
257 sock_prot_inuse_add(sock_net(sk), sk->sk_prot, 1); 270 sock_prot_inuse_add(sock_net(sk), sk->sk_prot, 1);
258 271
259 if (twp != NULL) { 272 if (twp) {
260 *twp = tw; 273 *twp = tw;
261 NET_INC_STATS_BH(net, LINUX_MIB_TIMEWAITRECYCLED); 274 } else if (tw) {
262 } else if (tw != NULL) {
263 /* Silly. Should hash-dance instead... */ 275 /* Silly. Should hash-dance instead... */
264 inet_twsk_deschedule(tw, death_row); 276 inet_twsk_deschedule(tw, death_row);
265 NET_INC_STATS_BH(net, LINUX_MIB_TIMEWAITRECYCLED);
266 277
267 inet_twsk_put(tw); 278 inet_twsk_put(tw);
268 } 279 }
@@ -279,7 +290,7 @@ static inline u32 inet6_sk_port_offset(const struct sock *sk)
279 const struct ipv6_pinfo *np = inet6_sk(sk); 290 const struct ipv6_pinfo *np = inet6_sk(sk);
280 return secure_ipv6_port_ephemeral(np->rcv_saddr.s6_addr32, 291 return secure_ipv6_port_ephemeral(np->rcv_saddr.s6_addr32,
281 np->daddr.s6_addr32, 292 np->daddr.s6_addr32,
282 inet->dport); 293 inet->inet_dport);
283} 294}
284 295
285int inet6_hash_connect(struct inet_timewait_death_row *death_row, 296int inet6_hash_connect(struct inet_timewait_death_row *death_row,
diff --git a/net/ipv6/ip6_fib.c b/net/ipv6/ip6_fib.c
index 0e93ca56eb69..6b82e02158c6 100644
--- a/net/ipv6/ip6_fib.c
+++ b/net/ipv6/ip6_fib.c
@@ -26,6 +26,7 @@
26#include <linux/in6.h> 26#include <linux/in6.h>
27#include <linux/init.h> 27#include <linux/init.h>
28#include <linux/list.h> 28#include <linux/list.h>
29#include <linux/slab.h>
29 30
30#ifdef CONFIG_PROC_FS 31#ifdef CONFIG_PROC_FS
31#include <linux/proc_fs.h> 32#include <linux/proc_fs.h>
@@ -93,29 +94,20 @@ static __u32 rt_sernum;
93 94
94static void fib6_gc_timer_cb(unsigned long arg); 95static void fib6_gc_timer_cb(unsigned long arg);
95 96
96static struct fib6_walker_t fib6_walker_list = { 97static LIST_HEAD(fib6_walkers);
97 .prev = &fib6_walker_list, 98#define FOR_WALKERS(w) list_for_each_entry(w, &fib6_walkers, lh)
98 .next = &fib6_walker_list,
99};
100
101#define FOR_WALKERS(w) for ((w)=fib6_walker_list.next; (w) != &fib6_walker_list; (w)=(w)->next)
102 99
103static inline void fib6_walker_link(struct fib6_walker_t *w) 100static inline void fib6_walker_link(struct fib6_walker_t *w)
104{ 101{
105 write_lock_bh(&fib6_walker_lock); 102 write_lock_bh(&fib6_walker_lock);
106 w->next = fib6_walker_list.next; 103 list_add(&w->lh, &fib6_walkers);
107 w->prev = &fib6_walker_list;
108 w->next->prev = w;
109 w->prev->next = w;
110 write_unlock_bh(&fib6_walker_lock); 104 write_unlock_bh(&fib6_walker_lock);
111} 105}
112 106
113static inline void fib6_walker_unlink(struct fib6_walker_t *w) 107static inline void fib6_walker_unlink(struct fib6_walker_t *w)
114{ 108{
115 write_lock_bh(&fib6_walker_lock); 109 write_lock_bh(&fib6_walker_lock);
116 w->next->prev = w->prev; 110 list_del(&w->lh);
117 w->prev->next = w->next;
118 w->prev = w->next = w;
119 write_unlock_bh(&fib6_walker_lock); 111 write_unlock_bh(&fib6_walker_lock);
120} 112}
121static __inline__ u32 fib6_new_sernum(void) 113static __inline__ u32 fib6_new_sernum(void)
@@ -239,7 +231,7 @@ struct fib6_table *fib6_get_table(struct net *net, u32 id)
239 return NULL; 231 return NULL;
240} 232}
241 233
242static void fib6_tables_init(struct net *net) 234static void __net_init fib6_tables_init(struct net *net)
243{ 235{
244 fib6_link_table(net, net->ipv6.fib6_main_tbl); 236 fib6_link_table(net, net->ipv6.fib6_main_tbl);
245 fib6_link_table(net, net->ipv6.fib6_local_tbl); 237 fib6_link_table(net, net->ipv6.fib6_local_tbl);
@@ -262,7 +254,7 @@ struct dst_entry *fib6_rule_lookup(struct net *net, struct flowi *fl,
262 return (struct dst_entry *) lookup(net, net->ipv6.fib6_main_tbl, fl, flags); 254 return (struct dst_entry *) lookup(net, net->ipv6.fib6_main_tbl, fl, flags);
263} 255}
264 256
265static void fib6_tables_init(struct net *net) 257static void __net_init fib6_tables_init(struct net *net)
266{ 258{
267 fib6_link_table(net, net->ipv6.fib6_main_tbl); 259 fib6_link_table(net, net->ipv6.fib6_main_tbl);
268} 260}
@@ -319,12 +311,26 @@ static int fib6_dump_table(struct fib6_table *table, struct sk_buff *skb,
319 w->root = &table->tb6_root; 311 w->root = &table->tb6_root;
320 312
321 if (cb->args[4] == 0) { 313 if (cb->args[4] == 0) {
314 w->count = 0;
315 w->skip = 0;
316
322 read_lock_bh(&table->tb6_lock); 317 read_lock_bh(&table->tb6_lock);
323 res = fib6_walk(w); 318 res = fib6_walk(w);
324 read_unlock_bh(&table->tb6_lock); 319 read_unlock_bh(&table->tb6_lock);
325 if (res > 0) 320 if (res > 0) {
326 cb->args[4] = 1; 321 cb->args[4] = 1;
322 cb->args[5] = w->root->fn_sernum;
323 }
327 } else { 324 } else {
325 if (cb->args[5] != w->root->fn_sernum) {
326 /* Begin at the root if the tree changed */
327 cb->args[5] = w->root->fn_sernum;
328 w->state = FWS_INIT;
329 w->node = w->root;
330 w->skip = w->count;
331 } else
332 w->skip = 0;
333
328 read_lock_bh(&table->tb6_lock); 334 read_lock_bh(&table->tb6_lock);
329 res = fib6_walk_continue(w); 335 res = fib6_walk_continue(w);
330 read_unlock_bh(&table->tb6_lock); 336 read_unlock_bh(&table->tb6_lock);
@@ -1250,9 +1256,18 @@ static int fib6_walk_continue(struct fib6_walker_t *w)
1250 w->leaf = fn->leaf; 1256 w->leaf = fn->leaf;
1251 case FWS_C: 1257 case FWS_C:
1252 if (w->leaf && fn->fn_flags&RTN_RTINFO) { 1258 if (w->leaf && fn->fn_flags&RTN_RTINFO) {
1253 int err = w->func(w); 1259 int err;
1260
1261 if (w->count < w->skip) {
1262 w->count++;
1263 continue;
1264 }
1265
1266 err = w->func(w);
1254 if (err) 1267 if (err)
1255 return err; 1268 return err;
1269
1270 w->count++;
1256 continue; 1271 continue;
1257 } 1272 }
1258 w->state = FWS_U; 1273 w->state = FWS_U;
@@ -1346,6 +1361,8 @@ static void fib6_clean_tree(struct net *net, struct fib6_node *root,
1346 c.w.root = root; 1361 c.w.root = root;
1347 c.w.func = fib6_clean_node; 1362 c.w.func = fib6_clean_node;
1348 c.w.prune = prune; 1363 c.w.prune = prune;
1364 c.w.count = 0;
1365 c.w.skip = 0;
1349 c.func = func; 1366 c.func = func;
1350 c.arg = arg; 1367 c.arg = arg;
1351 c.net = net; 1368 c.net = net;
@@ -1469,7 +1486,7 @@ static void fib6_gc_timer_cb(unsigned long arg)
1469 fib6_run_gc(0, (struct net *)arg); 1486 fib6_run_gc(0, (struct net *)arg);
1470} 1487}
1471 1488
1472static int fib6_net_init(struct net *net) 1489static int __net_init fib6_net_init(struct net *net)
1473{ 1490{
1474 setup_timer(&net->ipv6.ip6_fib_timer, fib6_gc_timer_cb, (unsigned long)net); 1491 setup_timer(&net->ipv6.ip6_fib_timer, fib6_gc_timer_cb, (unsigned long)net);
1475 1492
diff --git a/net/ipv6/ip6_flowlabel.c b/net/ipv6/ip6_flowlabel.c
index 7712578bdc66..14e23216eb28 100644
--- a/net/ipv6/ip6_flowlabel.c
+++ b/net/ipv6/ip6_flowlabel.c
@@ -20,6 +20,7 @@
20#include <linux/route.h> 20#include <linux/route.h>
21#include <linux/proc_fs.h> 21#include <linux/proc_fs.h>
22#include <linux/seq_file.h> 22#include <linux/seq_file.h>
23#include <linux/slab.h>
23 24
24#include <net/net_namespace.h> 25#include <net/net_namespace.h>
25#include <net/sock.h> 26#include <net/sock.h>
@@ -67,7 +68,7 @@ static inline struct ip6_flowlabel *__fl_lookup(struct net *net, __be32 label)
67 struct ip6_flowlabel *fl; 68 struct ip6_flowlabel *fl;
68 69
69 for (fl=fl_ht[FL_HASH(label)]; fl; fl = fl->next) { 70 for (fl=fl_ht[FL_HASH(label)]; fl; fl = fl->next) {
70 if (fl->label == label && fl->fl_net == net) 71 if (fl->label == label && net_eq(fl->fl_net, net))
71 return fl; 72 return fl;
72 } 73 }
73 return NULL; 74 return NULL;
@@ -154,7 +155,7 @@ static void ip6_fl_gc(unsigned long dummy)
154 write_unlock(&ip6_fl_lock); 155 write_unlock(&ip6_fl_lock);
155} 156}
156 157
157static void ip6_fl_purge(struct net *net) 158static void __net_exit ip6_fl_purge(struct net *net)
158{ 159{
159 int i; 160 int i;
160 161
@@ -163,7 +164,8 @@ static void ip6_fl_purge(struct net *net)
163 struct ip6_flowlabel *fl, **flp; 164 struct ip6_flowlabel *fl, **flp;
164 flp = &fl_ht[i]; 165 flp = &fl_ht[i];
165 while ((fl = *flp) != NULL) { 166 while ((fl = *flp) != NULL) {
166 if (fl->fl_net == net && atomic_read(&fl->users) == 0) { 167 if (net_eq(fl->fl_net, net) &&
168 atomic_read(&fl->users) == 0) {
167 *flp = fl->next; 169 *flp = fl->next;
168 fl_free(fl); 170 fl_free(fl);
169 atomic_dec(&fl_size); 171 atomic_dec(&fl_size);
@@ -377,8 +379,8 @@ fl_create(struct net *net, struct in6_flowlabel_req *freq, char __user *optval,
377 goto done; 379 goto done;
378 fl->share = freq->flr_share; 380 fl->share = freq->flr_share;
379 addr_type = ipv6_addr_type(&freq->flr_dst); 381 addr_type = ipv6_addr_type(&freq->flr_dst);
380 if ((addr_type&IPV6_ADDR_MAPPED) 382 if ((addr_type & IPV6_ADDR_MAPPED) ||
381 || addr_type == IPV6_ADDR_ANY) { 383 addr_type == IPV6_ADDR_ANY) {
382 err = -EINVAL; 384 err = -EINVAL;
383 goto done; 385 goto done;
384 } 386 }
@@ -421,8 +423,8 @@ static int mem_check(struct sock *sk)
421 423
422 if (room <= 0 || 424 if (room <= 0 ||
423 ((count >= FL_MAX_PER_SOCK || 425 ((count >= FL_MAX_PER_SOCK ||
424 (count > 0 && room < FL_MAX_SIZE/2) || room < FL_MAX_SIZE/4) 426 (count > 0 && room < FL_MAX_SIZE/2) || room < FL_MAX_SIZE/4) &&
425 && !capable(CAP_NET_ADMIN))) 427 !capable(CAP_NET_ADMIN)))
426 return -ENOBUFS; 428 return -ENOBUFS;
427 429
428 return 0; 430 return 0;
@@ -630,7 +632,7 @@ static struct ip6_flowlabel *ip6fl_get_first(struct seq_file *seq)
630 for (state->bucket = 0; state->bucket <= FL_HASH_MASK; ++state->bucket) { 632 for (state->bucket = 0; state->bucket <= FL_HASH_MASK; ++state->bucket) {
631 fl = fl_ht[state->bucket]; 633 fl = fl_ht[state->bucket];
632 634
633 while (fl && fl->fl_net != net) 635 while (fl && !net_eq(fl->fl_net, net))
634 fl = fl->next; 636 fl = fl->next;
635 if (fl) 637 if (fl)
636 break; 638 break;
@@ -645,7 +647,7 @@ static struct ip6_flowlabel *ip6fl_get_next(struct seq_file *seq, struct ip6_flo
645 647
646 fl = fl->next; 648 fl = fl->next;
647try_again: 649try_again:
648 while (fl && fl->fl_net != net) 650 while (fl && !net_eq(fl->fl_net, net))
649 fl = fl->next; 651 fl = fl->next;
650 652
651 while (!fl) { 653 while (!fl) {
@@ -734,7 +736,7 @@ static const struct file_operations ip6fl_seq_fops = {
734 .release = seq_release_net, 736 .release = seq_release_net,
735}; 737};
736 738
737static int ip6_flowlabel_proc_init(struct net *net) 739static int __net_init ip6_flowlabel_proc_init(struct net *net)
738{ 740{
739 if (!proc_net_fops_create(net, "ip6_flowlabel", 741 if (!proc_net_fops_create(net, "ip6_flowlabel",
740 S_IRUGO, &ip6fl_seq_fops)) 742 S_IRUGO, &ip6fl_seq_fops))
@@ -742,7 +744,7 @@ static int ip6_flowlabel_proc_init(struct net *net)
742 return 0; 744 return 0;
743} 745}
744 746
745static void ip6_flowlabel_proc_fini(struct net *net) 747static void __net_exit ip6_flowlabel_proc_fini(struct net *net)
746{ 748{
747 proc_net_remove(net, "ip6_flowlabel"); 749 proc_net_remove(net, "ip6_flowlabel");
748} 750}
@@ -753,11 +755,10 @@ static inline int ip6_flowlabel_proc_init(struct net *net)
753} 755}
754static inline void ip6_flowlabel_proc_fini(struct net *net) 756static inline void ip6_flowlabel_proc_fini(struct net *net)
755{ 757{
756 return ;
757} 758}
758#endif 759#endif
759 760
760static inline void ip6_flowlabel_net_exit(struct net *net) 761static void __net_exit ip6_flowlabel_net_exit(struct net *net)
761{ 762{
762 ip6_fl_purge(net); 763 ip6_fl_purge(net);
763 ip6_flowlabel_proc_fini(net); 764 ip6_flowlabel_proc_fini(net);
diff --git a/net/ipv6/ip6_input.c b/net/ipv6/ip6_input.c
index 237e2dba6e94..6aa7ee1295c2 100644
--- a/net/ipv6/ip6_input.c
+++ b/net/ipv6/ip6_input.c
@@ -28,6 +28,7 @@
28#include <linux/in6.h> 28#include <linux/in6.h>
29#include <linux/icmpv6.h> 29#include <linux/icmpv6.h>
30#include <linux/mroute6.h> 30#include <linux/mroute6.h>
31#include <linux/slab.h>
31 32
32#include <linux/netfilter.h> 33#include <linux/netfilter.h>
33#include <linux/netfilter_ipv6.h> 34#include <linux/netfilter_ipv6.h>
@@ -216,8 +217,7 @@ resubmit:
216 IP6_INC_STATS_BH(net, idev, 217 IP6_INC_STATS_BH(net, idev,
217 IPSTATS_MIB_INUNKNOWNPROTOS); 218 IPSTATS_MIB_INUNKNOWNPROTOS);
218 icmpv6_send(skb, ICMPV6_PARAMPROB, 219 icmpv6_send(skb, ICMPV6_PARAMPROB,
219 ICMPV6_UNK_NEXTHDR, nhoff, 220 ICMPV6_UNK_NEXTHDR, nhoff);
220 skb->dev);
221 } 221 }
222 } else 222 } else
223 IP6_INC_STATS_BH(net, idev, IPSTATS_MIB_INDELIVERS); 223 IP6_INC_STATS_BH(net, idev, IPSTATS_MIB_INDELIVERS);
diff --git a/net/ipv6/ip6_output.c b/net/ipv6/ip6_output.c
index cd48801a8d6f..75d5ef830097 100644
--- a/net/ipv6/ip6_output.c
+++ b/net/ipv6/ip6_output.c
@@ -37,6 +37,7 @@
37#include <linux/tcp.h> 37#include <linux/tcp.h>
38#include <linux/route.h> 38#include <linux/route.h>
39#include <linux/module.h> 39#include <linux/module.h>
40#include <linux/slab.h>
40 41
41#include <linux/netfilter.h> 42#include <linux/netfilter.h>
42#include <linux/netfilter_ipv6.h> 43#include <linux/netfilter_ipv6.h>
@@ -107,7 +108,7 @@ static int ip6_dev_loopback_xmit(struct sk_buff *newskb)
107 newskb->ip_summed = CHECKSUM_UNNECESSARY; 108 newskb->ip_summed = CHECKSUM_UNNECESSARY;
108 WARN_ON(!skb_dst(newskb)); 109 WARN_ON(!skb_dst(newskb));
109 110
110 netif_rx(newskb); 111 netif_rx_ni(newskb);
111 return 0; 112 return 0;
112} 113}
113 114
@@ -121,10 +122,9 @@ static int ip6_output2(struct sk_buff *skb)
121 skb->dev = dev; 122 skb->dev = dev;
122 123
123 if (ipv6_addr_is_multicast(&ipv6_hdr(skb)->daddr)) { 124 if (ipv6_addr_is_multicast(&ipv6_hdr(skb)->daddr)) {
124 struct ipv6_pinfo* np = skb->sk ? inet6_sk(skb->sk) : NULL;
125 struct inet6_dev *idev = ip6_dst_idev(skb_dst(skb)); 125 struct inet6_dev *idev = ip6_dst_idev(skb_dst(skb));
126 126
127 if (!(dev->flags & IFF_LOOPBACK) && (!np || np->mc_loop) && 127 if (!(dev->flags & IFF_LOOPBACK) && sk_mc_loop(skb->sk) &&
128 ((mroute6_socket(dev_net(dev)) && 128 ((mroute6_socket(dev_net(dev)) &&
129 !(IP6CB(skb)->flags & IP6SKB_FORWARDED)) || 129 !(IP6CB(skb)->flags & IP6SKB_FORWARDED)) ||
130 ipv6_chk_mcast_addr(dev, &ipv6_hdr(skb)->daddr, 130 ipv6_chk_mcast_addr(dev, &ipv6_hdr(skb)->daddr,
@@ -268,7 +268,7 @@ int ip6_xmit(struct sock *sk, struct sk_buff *skb, struct flowi *fl,
268 if (net_ratelimit()) 268 if (net_ratelimit())
269 printk(KERN_DEBUG "IPv6: sending pkt_too_big to self\n"); 269 printk(KERN_DEBUG "IPv6: sending pkt_too_big to self\n");
270 skb->dev = dst->dev; 270 skb->dev = dst->dev;
271 icmpv6_send(skb, ICMPV6_PKT_TOOBIG, 0, mtu, skb->dev); 271 icmpv6_send(skb, ICMPV6_PKT_TOOBIG, 0, mtu);
272 IP6_INC_STATS(net, ip6_dst_idev(skb_dst(skb)), IPSTATS_MIB_FRAGFAILS); 272 IP6_INC_STATS(net, ip6_dst_idev(skb_dst(skb)), IPSTATS_MIB_FRAGFAILS);
273 kfree_skb(skb); 273 kfree_skb(skb);
274 return -EMSGSIZE; 274 return -EMSGSIZE;
@@ -403,6 +403,7 @@ int ip6_forward(struct sk_buff *skb)
403 struct ipv6hdr *hdr = ipv6_hdr(skb); 403 struct ipv6hdr *hdr = ipv6_hdr(skb);
404 struct inet6_skb_parm *opt = IP6CB(skb); 404 struct inet6_skb_parm *opt = IP6CB(skb);
405 struct net *net = dev_net(dst->dev); 405 struct net *net = dev_net(dst->dev);
406 u32 mtu;
406 407
407 if (net->ipv6.devconf_all->forwarding == 0) 408 if (net->ipv6.devconf_all->forwarding == 0)
408 goto error; 409 goto error;
@@ -442,8 +443,7 @@ int ip6_forward(struct sk_buff *skb)
442 if (hdr->hop_limit <= 1) { 443 if (hdr->hop_limit <= 1) {
443 /* Force OUTPUT device used as source address */ 444 /* Force OUTPUT device used as source address */
444 skb->dev = dst->dev; 445 skb->dev = dst->dev;
445 icmpv6_send(skb, ICMPV6_TIME_EXCEED, ICMPV6_EXC_HOPLIMIT, 446 icmpv6_send(skb, ICMPV6_TIME_EXCEED, ICMPV6_EXC_HOPLIMIT, 0);
446 0, skb->dev);
447 IP6_INC_STATS_BH(net, 447 IP6_INC_STATS_BH(net,
448 ip6_dst_idev(dst), IPSTATS_MIB_INHDRERRORS); 448 ip6_dst_idev(dst), IPSTATS_MIB_INHDRERRORS);
449 449
@@ -505,15 +505,19 @@ int ip6_forward(struct sk_buff *skb)
505 goto error; 505 goto error;
506 if (addrtype & IPV6_ADDR_LINKLOCAL) { 506 if (addrtype & IPV6_ADDR_LINKLOCAL) {
507 icmpv6_send(skb, ICMPV6_DEST_UNREACH, 507 icmpv6_send(skb, ICMPV6_DEST_UNREACH,
508 ICMPV6_NOT_NEIGHBOUR, 0, skb->dev); 508 ICMPV6_NOT_NEIGHBOUR, 0);
509 goto error; 509 goto error;
510 } 510 }
511 } 511 }
512 512
513 if (skb->len > dst_mtu(dst)) { 513 mtu = dst_mtu(dst);
514 if (mtu < IPV6_MIN_MTU)
515 mtu = IPV6_MIN_MTU;
516
517 if (skb->len > mtu) {
514 /* Again, force OUTPUT device used as source address */ 518 /* Again, force OUTPUT device used as source address */
515 skb->dev = dst->dev; 519 skb->dev = dst->dev;
516 icmpv6_send(skb, ICMPV6_PKT_TOOBIG, 0, dst_mtu(dst), skb->dev); 520 icmpv6_send(skb, ICMPV6_PKT_TOOBIG, 0, mtu);
517 IP6_INC_STATS_BH(net, 521 IP6_INC_STATS_BH(net,
518 ip6_dst_idev(dst), IPSTATS_MIB_INTOOBIGERRORS); 522 ip6_dst_idev(dst), IPSTATS_MIB_INTOOBIGERRORS);
519 IP6_INC_STATS_BH(net, 523 IP6_INC_STATS_BH(net,
@@ -623,12 +627,11 @@ static int ip6_fragment(struct sk_buff *skb, int (*output)(struct sk_buff *))
623 mtu = ip6_skb_dst_mtu(skb); 627 mtu = ip6_skb_dst_mtu(skb);
624 628
625 /* We must not fragment if the socket is set to force MTU discovery 629 /* We must not fragment if the socket is set to force MTU discovery
626 * or if the skb it not generated by a local socket. (This last 630 * or if the skb it not generated by a local socket.
627 * check should be redundant, but it's free.)
628 */ 631 */
629 if (!skb->local_df) { 632 if (!skb->local_df && skb->len > mtu) {
630 skb->dev = skb_dst(skb)->dev; 633 skb->dev = skb_dst(skb)->dev;
631 icmpv6_send(skb, ICMPV6_PKT_TOOBIG, 0, mtu, skb->dev); 634 icmpv6_send(skb, ICMPV6_PKT_TOOBIG, 0, mtu);
632 IP6_INC_STATS(net, ip6_dst_idev(skb_dst(skb)), 635 IP6_INC_STATS(net, ip6_dst_idev(skb_dst(skb)),
633 IPSTATS_MIB_FRAGFAILS); 636 IPSTATS_MIB_FRAGFAILS);
634 kfree_skb(skb); 637 kfree_skb(skb);
diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
index c595bbe1ed99..2599870747ec 100644
--- a/net/ipv6/ip6_tunnel.c
+++ b/net/ipv6/ip6_tunnel.c
@@ -37,6 +37,7 @@
37#include <linux/route.h> 37#include <linux/route.h>
38#include <linux/rtnetlink.h> 38#include <linux/rtnetlink.h>
39#include <linux/netfilter_ipv6.h> 39#include <linux/netfilter_ipv6.h>
40#include <linux/slab.h>
40 41
41#include <asm/uaccess.h> 42#include <asm/uaccess.h>
42#include <asm/atomic.h> 43#include <asm/atomic.h>
@@ -74,11 +75,10 @@ MODULE_LICENSE("GPL");
74 (addr)->s6_addr32[2] ^ (addr)->s6_addr32[3]) & \ 75 (addr)->s6_addr32[2] ^ (addr)->s6_addr32[3]) & \
75 (HASH_SIZE - 1)) 76 (HASH_SIZE - 1))
76 77
77static void ip6_fb_tnl_dev_init(struct net_device *dev);
78static void 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 __read_mostly;
82struct ip6_tnl_net { 82struct ip6_tnl_net {
83 /* the IPv6 tunnel fallback device */ 83 /* the IPv6 tunnel fallback device */
84 struct net_device *fb_tnl_dev; 84 struct net_device *fb_tnl_dev;
@@ -88,8 +88,10 @@ struct ip6_tnl_net {
88 struct ip6_tnl **tnls[2]; 88 struct ip6_tnl **tnls[2];
89}; 89};
90 90
91/* lock for the tunnel lists */ 91/*
92static DEFINE_RWLOCK(ip6_tnl_lock); 92 * Locking : hash tables are protected by RCU and a spinlock
93 */
94static DEFINE_SPINLOCK(ip6_tnl_lock);
93 95
94static inline struct dst_entry *ip6_tnl_dst_check(struct ip6_tnl *t) 96static inline struct dst_entry *ip6_tnl_dst_check(struct ip6_tnl *t)
95{ 97{
@@ -130,6 +132,9 @@ static inline void ip6_tnl_dst_store(struct ip6_tnl *t, struct dst_entry *dst)
130 * else %NULL 132 * else %NULL
131 **/ 133 **/
132 134
135#define for_each_ip6_tunnel_rcu(start) \
136 for (t = rcu_dereference(start); t; t = rcu_dereference(t->next))
137
133static struct ip6_tnl * 138static struct ip6_tnl *
134ip6_tnl_lookup(struct net *net, struct in6_addr *remote, struct in6_addr *local) 139ip6_tnl_lookup(struct net *net, struct in6_addr *remote, struct in6_addr *local)
135{ 140{
@@ -138,13 +143,14 @@ ip6_tnl_lookup(struct net *net, struct in6_addr *remote, struct in6_addr *local)
138 struct ip6_tnl *t; 143 struct ip6_tnl *t;
139 struct ip6_tnl_net *ip6n = net_generic(net, ip6_tnl_net_id); 144 struct ip6_tnl_net *ip6n = net_generic(net, ip6_tnl_net_id);
140 145
141 for (t = ip6n->tnls_r_l[h0 ^ h1]; t; t = t->next) { 146 for_each_ip6_tunnel_rcu(ip6n->tnls_r_l[h0 ^ h1]) {
142 if (ipv6_addr_equal(local, &t->parms.laddr) && 147 if (ipv6_addr_equal(local, &t->parms.laddr) &&
143 ipv6_addr_equal(remote, &t->parms.raddr) && 148 ipv6_addr_equal(remote, &t->parms.raddr) &&
144 (t->dev->flags & IFF_UP)) 149 (t->dev->flags & IFF_UP))
145 return t; 150 return t;
146 } 151 }
147 if ((t = ip6n->tnls_wc[0]) != NULL && (t->dev->flags & IFF_UP)) 152 t = rcu_dereference(ip6n->tnls_wc[0]);
153 if (t && (t->dev->flags & IFF_UP))
148 return t; 154 return t;
149 155
150 return NULL; 156 return NULL;
@@ -186,10 +192,10 @@ ip6_tnl_link(struct ip6_tnl_net *ip6n, struct ip6_tnl *t)
186{ 192{
187 struct ip6_tnl **tp = ip6_tnl_bucket(ip6n, &t->parms); 193 struct ip6_tnl **tp = ip6_tnl_bucket(ip6n, &t->parms);
188 194
195 spin_lock_bh(&ip6_tnl_lock);
189 t->next = *tp; 196 t->next = *tp;
190 write_lock_bh(&ip6_tnl_lock); 197 rcu_assign_pointer(*tp, t);
191 *tp = t; 198 spin_unlock_bh(&ip6_tnl_lock);
192 write_unlock_bh(&ip6_tnl_lock);
193} 199}
194 200
195/** 201/**
@@ -204,9 +210,9 @@ ip6_tnl_unlink(struct ip6_tnl_net *ip6n, struct ip6_tnl *t)
204 210
205 for (tp = ip6_tnl_bucket(ip6n, &t->parms); *tp; tp = &(*tp)->next) { 211 for (tp = ip6_tnl_bucket(ip6n, &t->parms); *tp; tp = &(*tp)->next) {
206 if (t == *tp) { 212 if (t == *tp) {
207 write_lock_bh(&ip6_tnl_lock); 213 spin_lock_bh(&ip6_tnl_lock);
208 *tp = t->next; 214 *tp = t->next;
209 write_unlock_bh(&ip6_tnl_lock); 215 spin_unlock_bh(&ip6_tnl_lock);
210 break; 216 break;
211 } 217 }
212 } 218 }
@@ -313,9 +319,9 @@ ip6_tnl_dev_uninit(struct net_device *dev)
313 struct ip6_tnl_net *ip6n = net_generic(net, ip6_tnl_net_id); 319 struct ip6_tnl_net *ip6n = net_generic(net, ip6_tnl_net_id);
314 320
315 if (dev == ip6n->fb_tnl_dev) { 321 if (dev == ip6n->fb_tnl_dev) {
316 write_lock_bh(&ip6_tnl_lock); 322 spin_lock_bh(&ip6_tnl_lock);
317 ip6n->tnls_wc[0] = NULL; 323 ip6n->tnls_wc[0] = NULL;
318 write_unlock_bh(&ip6_tnl_lock); 324 spin_unlock_bh(&ip6_tnl_lock);
319 } else { 325 } else {
320 ip6_tnl_unlink(ip6n, t); 326 ip6_tnl_unlink(ip6n, t);
321 } 327 }
@@ -409,7 +415,7 @@ ip6_tnl_err(struct sk_buff *skb, __u8 ipproto, struct inet6_skb_parm *opt,
409 in trouble since we might need the source address for further 415 in trouble since we might need the source address for further
410 processing of the error. */ 416 processing of the error. */
411 417
412 read_lock(&ip6_tnl_lock); 418 rcu_read_lock();
413 if ((t = ip6_tnl_lookup(dev_net(skb->dev), &ipv6h->daddr, 419 if ((t = ip6_tnl_lookup(dev_net(skb->dev), &ipv6h->daddr,
414 &ipv6h->saddr)) == NULL) 420 &ipv6h->saddr)) == NULL)
415 goto out; 421 goto out;
@@ -482,7 +488,7 @@ ip6_tnl_err(struct sk_buff *skb, __u8 ipproto, struct inet6_skb_parm *opt,
482 *msg = rel_msg; 488 *msg = rel_msg;
483 489
484out: 490out:
485 read_unlock(&ip6_tnl_lock); 491 rcu_read_unlock();
486 return err; 492 return err;
487} 493}
488 494
@@ -617,7 +623,7 @@ ip6ip6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
617 if (rt && rt->rt6i_dev) 623 if (rt && rt->rt6i_dev)
618 skb2->dev = rt->rt6i_dev; 624 skb2->dev = rt->rt6i_dev;
619 625
620 icmpv6_send(skb2, rel_type, rel_code, rel_info, skb2->dev); 626 icmpv6_send(skb2, rel_type, rel_code, rel_info);
621 627
622 if (rt) 628 if (rt)
623 dst_release(&rt->u.dst); 629 dst_release(&rt->u.dst);
@@ -652,6 +658,7 @@ static void ip6ip6_dscp_ecn_decapsulate(struct ip6_tnl *t,
652 IP6_ECN_set_ce(ipv6_hdr(skb)); 658 IP6_ECN_set_ce(ipv6_hdr(skb));
653} 659}
654 660
661/* called with rcu_read_lock() */
655static inline int ip6_tnl_rcv_ctl(struct ip6_tnl *t) 662static inline int ip6_tnl_rcv_ctl(struct ip6_tnl *t)
656{ 663{
657 struct ip6_tnl_parm *p = &t->parms; 664 struct ip6_tnl_parm *p = &t->parms;
@@ -662,15 +669,13 @@ static inline int ip6_tnl_rcv_ctl(struct ip6_tnl *t)
662 struct net_device *ldev = NULL; 669 struct net_device *ldev = NULL;
663 670
664 if (p->link) 671 if (p->link)
665 ldev = dev_get_by_index(net, p->link); 672 ldev = dev_get_by_index_rcu(net, p->link);
666 673
667 if ((ipv6_addr_is_multicast(&p->laddr) || 674 if ((ipv6_addr_is_multicast(&p->laddr) ||
668 likely(ipv6_chk_addr(net, &p->laddr, ldev, 0))) && 675 likely(ipv6_chk_addr(net, &p->laddr, ldev, 0))) &&
669 likely(!ipv6_chk_addr(net, &p->raddr, NULL, 0))) 676 likely(!ipv6_chk_addr(net, &p->raddr, NULL, 0)))
670 ret = 1; 677 ret = 1;
671 678
672 if (ldev)
673 dev_put(ldev);
674 } 679 }
675 return ret; 680 return ret;
676} 681}
@@ -693,23 +698,23 @@ static int ip6_tnl_rcv(struct sk_buff *skb, __u16 protocol,
693 struct ip6_tnl *t; 698 struct ip6_tnl *t;
694 struct ipv6hdr *ipv6h = ipv6_hdr(skb); 699 struct ipv6hdr *ipv6h = ipv6_hdr(skb);
695 700
696 read_lock(&ip6_tnl_lock); 701 rcu_read_lock();
697 702
698 if ((t = ip6_tnl_lookup(dev_net(skb->dev), &ipv6h->saddr, 703 if ((t = ip6_tnl_lookup(dev_net(skb->dev), &ipv6h->saddr,
699 &ipv6h->daddr)) != NULL) { 704 &ipv6h->daddr)) != NULL) {
700 if (t->parms.proto != ipproto && t->parms.proto != 0) { 705 if (t->parms.proto != ipproto && t->parms.proto != 0) {
701 read_unlock(&ip6_tnl_lock); 706 rcu_read_unlock();
702 goto discard; 707 goto discard;
703 } 708 }
704 709
705 if (!xfrm6_policy_check(NULL, XFRM_POLICY_IN, skb)) { 710 if (!xfrm6_policy_check(NULL, XFRM_POLICY_IN, skb)) {
706 read_unlock(&ip6_tnl_lock); 711 rcu_read_unlock();
707 goto discard; 712 goto discard;
708 } 713 }
709 714
710 if (!ip6_tnl_rcv_ctl(t)) { 715 if (!ip6_tnl_rcv_ctl(t)) {
711 t->dev->stats.rx_dropped++; 716 t->dev->stats.rx_dropped++;
712 read_unlock(&ip6_tnl_lock); 717 rcu_read_unlock();
713 goto discard; 718 goto discard;
714 } 719 }
715 secpath_reset(skb); 720 secpath_reset(skb);
@@ -727,10 +732,10 @@ static int ip6_tnl_rcv(struct sk_buff *skb, __u16 protocol,
727 t->dev->stats.rx_packets++; 732 t->dev->stats.rx_packets++;
728 t->dev->stats.rx_bytes += skb->len; 733 t->dev->stats.rx_bytes += skb->len;
729 netif_rx(skb); 734 netif_rx(skb);
730 read_unlock(&ip6_tnl_lock); 735 rcu_read_unlock();
731 return 0; 736 return 0;
732 } 737 }
733 read_unlock(&ip6_tnl_lock); 738 rcu_read_unlock();
734 return 1; 739 return 1;
735 740
736discard: 741discard:
@@ -798,8 +803,9 @@ static inline int ip6_tnl_xmit_ctl(struct ip6_tnl *t)
798 if (p->flags & IP6_TNL_F_CAP_XMIT) { 803 if (p->flags & IP6_TNL_F_CAP_XMIT) {
799 struct net_device *ldev = NULL; 804 struct net_device *ldev = NULL;
800 805
806 rcu_read_lock();
801 if (p->link) 807 if (p->link)
802 ldev = dev_get_by_index(net, p->link); 808 ldev = dev_get_by_index_rcu(net, p->link);
803 809
804 if (unlikely(!ipv6_chk_addr(net, &p->laddr, ldev, 0))) 810 if (unlikely(!ipv6_chk_addr(net, &p->laddr, ldev, 0)))
805 printk(KERN_WARNING 811 printk(KERN_WARNING
@@ -813,8 +819,7 @@ static inline int ip6_tnl_xmit_ctl(struct ip6_tnl *t)
813 p->name); 819 p->name);
814 else 820 else
815 ret = 1; 821 ret = 1;
816 if (ldev) 822 rcu_read_unlock();
817 dev_put(ldev);
818 } 823 }
819 return ret; 824 return ret;
820} 825}
@@ -1010,7 +1015,7 @@ ip6ip6_tnl_xmit(struct sk_buff *skb, struct net_device *dev)
1010 tel = (struct ipv6_tlv_tnl_enc_lim *)&skb_network_header(skb)[offset]; 1015 tel = (struct ipv6_tlv_tnl_enc_lim *)&skb_network_header(skb)[offset];
1011 if (tel->encap_limit == 0) { 1016 if (tel->encap_limit == 0) {
1012 icmpv6_send(skb, ICMPV6_PARAMPROB, 1017 icmpv6_send(skb, ICMPV6_PARAMPROB,
1013 ICMPV6_HDR_FIELD, offset + 2, skb->dev); 1018 ICMPV6_HDR_FIELD, offset + 2);
1014 return -1; 1019 return -1;
1015 } 1020 }
1016 encap_limit = tel->encap_limit - 1; 1021 encap_limit = tel->encap_limit - 1;
@@ -1029,7 +1034,7 @@ ip6ip6_tnl_xmit(struct sk_buff *skb, struct net_device *dev)
1029 err = ip6_tnl_xmit2(skb, dev, dsfield, &fl, encap_limit, &mtu); 1034 err = ip6_tnl_xmit2(skb, dev, dsfield, &fl, encap_limit, &mtu);
1030 if (err != 0) { 1035 if (err != 0) {
1031 if (err == -EMSGSIZE) 1036 if (err == -EMSGSIZE)
1032 icmpv6_send(skb, ICMPV6_PKT_TOOBIG, 0, mtu, dev); 1037 icmpv6_send(skb, ICMPV6_PKT_TOOBIG, 0, mtu);
1033 return -1; 1038 return -1;
1034 } 1039 }
1035 1040
@@ -1359,7 +1364,7 @@ static void ip6_tnl_dev_init(struct net_device *dev)
1359 * Return: 0 1364 * Return: 0
1360 **/ 1365 **/
1361 1366
1362static void ip6_fb_tnl_dev_init(struct net_device *dev) 1367static void __net_init ip6_fb_tnl_dev_init(struct net_device *dev)
1363{ 1368{
1364 struct ip6_tnl *t = netdev_priv(dev); 1369 struct ip6_tnl *t = netdev_priv(dev);
1365 struct net *net = dev_net(dev); 1370 struct net *net = dev_net(dev);
@@ -1383,33 +1388,29 @@ static struct xfrm6_tunnel ip6ip6_handler = {
1383 .priority = 1, 1388 .priority = 1,
1384}; 1389};
1385 1390
1386static void ip6_tnl_destroy_tunnels(struct ip6_tnl_net *ip6n) 1391static void __net_exit ip6_tnl_destroy_tunnels(struct ip6_tnl_net *ip6n)
1387{ 1392{
1388 int h; 1393 int h;
1389 struct ip6_tnl *t; 1394 struct ip6_tnl *t;
1395 LIST_HEAD(list);
1390 1396
1391 for (h = 0; h < HASH_SIZE; h++) { 1397 for (h = 0; h < HASH_SIZE; h++) {
1392 while ((t = ip6n->tnls_r_l[h]) != NULL) 1398 t = ip6n->tnls_r_l[h];
1393 unregister_netdevice(t->dev); 1399 while (t != NULL) {
1400 unregister_netdevice_queue(t->dev, &list);
1401 t = t->next;
1402 }
1394 } 1403 }
1395 1404
1396 t = ip6n->tnls_wc[0]; 1405 t = ip6n->tnls_wc[0];
1397 unregister_netdevice(t->dev); 1406 unregister_netdevice_queue(t->dev, &list);
1407 unregister_netdevice_many(&list);
1398} 1408}
1399 1409
1400static int ip6_tnl_init_net(struct net *net) 1410static int __net_init ip6_tnl_init_net(struct net *net)
1401{ 1411{
1412 struct ip6_tnl_net *ip6n = net_generic(net, ip6_tnl_net_id);
1402 int err; 1413 int err;
1403 struct ip6_tnl_net *ip6n;
1404
1405 err = -ENOMEM;
1406 ip6n = kzalloc(sizeof(struct ip6_tnl_net), GFP_KERNEL);
1407 if (ip6n == NULL)
1408 goto err_alloc;
1409
1410 err = net_assign_generic(net, ip6_tnl_net_id, ip6n);
1411 if (err < 0)
1412 goto err_assign;
1413 1414
1414 ip6n->tnls[0] = ip6n->tnls_wc; 1415 ip6n->tnls[0] = ip6n->tnls_wc;
1415 ip6n->tnls[1] = ip6n->tnls_r_l; 1416 ip6n->tnls[1] = ip6n->tnls_r_l;
@@ -1432,27 +1433,23 @@ static int ip6_tnl_init_net(struct net *net)
1432err_register: 1433err_register:
1433 free_netdev(ip6n->fb_tnl_dev); 1434 free_netdev(ip6n->fb_tnl_dev);
1434err_alloc_dev: 1435err_alloc_dev:
1435 /* nothing */
1436err_assign:
1437 kfree(ip6n);
1438err_alloc:
1439 return err; 1436 return err;
1440} 1437}
1441 1438
1442static void ip6_tnl_exit_net(struct net *net) 1439static void __net_exit ip6_tnl_exit_net(struct net *net)
1443{ 1440{
1444 struct ip6_tnl_net *ip6n; 1441 struct ip6_tnl_net *ip6n = net_generic(net, ip6_tnl_net_id);
1445 1442
1446 ip6n = net_generic(net, ip6_tnl_net_id);
1447 rtnl_lock(); 1443 rtnl_lock();
1448 ip6_tnl_destroy_tunnels(ip6n); 1444 ip6_tnl_destroy_tunnels(ip6n);
1449 rtnl_unlock(); 1445 rtnl_unlock();
1450 kfree(ip6n);
1451} 1446}
1452 1447
1453static struct pernet_operations ip6_tnl_net_ops = { 1448static struct pernet_operations ip6_tnl_net_ops = {
1454 .init = ip6_tnl_init_net, 1449 .init = ip6_tnl_init_net,
1455 .exit = ip6_tnl_exit_net, 1450 .exit = ip6_tnl_exit_net,
1451 .id = &ip6_tnl_net_id,
1452 .size = sizeof(struct ip6_tnl_net),
1456}; 1453};
1457 1454
1458/** 1455/**
@@ -1465,27 +1462,29 @@ static int __init ip6_tunnel_init(void)
1465{ 1462{
1466 int err; 1463 int err;
1467 1464
1468 if (xfrm6_tunnel_register(&ip4ip6_handler, AF_INET)) { 1465 err = register_pernet_device(&ip6_tnl_net_ops);
1466 if (err < 0)
1467 goto out_pernet;
1468
1469 err = xfrm6_tunnel_register(&ip4ip6_handler, AF_INET);
1470 if (err < 0) {
1469 printk(KERN_ERR "ip6_tunnel init: can't register ip4ip6\n"); 1471 printk(KERN_ERR "ip6_tunnel init: can't register ip4ip6\n");
1470 err = -EAGAIN; 1472 goto out_ip4ip6;
1471 goto out;
1472 } 1473 }
1473 1474
1474 if (xfrm6_tunnel_register(&ip6ip6_handler, AF_INET6)) { 1475 err = xfrm6_tunnel_register(&ip6ip6_handler, AF_INET6);
1476 if (err < 0) {
1475 printk(KERN_ERR "ip6_tunnel init: can't register ip6ip6\n"); 1477 printk(KERN_ERR "ip6_tunnel init: can't register ip6ip6\n");
1476 err = -EAGAIN; 1478 goto out_ip6ip6;
1477 goto unreg_ip4ip6;
1478 } 1479 }
1479 1480
1480 err = register_pernet_gen_device(&ip6_tnl_net_id, &ip6_tnl_net_ops);
1481 if (err < 0)
1482 goto err_pernet;
1483 return 0; 1481 return 0;
1484err_pernet: 1482
1485 xfrm6_tunnel_deregister(&ip6ip6_handler, AF_INET6); 1483out_ip6ip6:
1486unreg_ip4ip6:
1487 xfrm6_tunnel_deregister(&ip4ip6_handler, AF_INET); 1484 xfrm6_tunnel_deregister(&ip4ip6_handler, AF_INET);
1488out: 1485out_ip4ip6:
1486 unregister_pernet_device(&ip6_tnl_net_ops);
1487out_pernet:
1489 return err; 1488 return err;
1490} 1489}
1491 1490
@@ -1501,7 +1500,7 @@ static void __exit ip6_tunnel_cleanup(void)
1501 if (xfrm6_tunnel_deregister(&ip6ip6_handler, AF_INET6)) 1500 if (xfrm6_tunnel_deregister(&ip6ip6_handler, AF_INET6))
1502 printk(KERN_INFO "ip6_tunnel close: can't deregister ip6ip6\n"); 1501 printk(KERN_INFO "ip6_tunnel close: can't deregister ip6ip6\n");
1503 1502
1504 unregister_pernet_gen_device(ip6_tnl_net_id, &ip6_tnl_net_ops); 1503 unregister_pernet_device(&ip6_tnl_net_ops);
1505} 1504}
1506 1505
1507module_init(ip6_tunnel_init); 1506module_init(ip6_tunnel_init);
diff --git a/net/ipv6/ip6mr.c b/net/ipv6/ip6mr.c
index 716153941fc4..3e333268db89 100644
--- a/net/ipv6/ip6mr.c
+++ b/net/ipv6/ip6mr.c
@@ -33,6 +33,7 @@
33#include <linux/proc_fs.h> 33#include <linux/proc_fs.h>
34#include <linux/seq_file.h> 34#include <linux/seq_file.h>
35#include <linux/init.h> 35#include <linux/init.h>
36#include <linux/slab.h>
36#include <net/protocol.h> 37#include <net/protocol.h>
37#include <linux/skbuff.h> 38#include <linux/skbuff.h>
38#include <net/sock.h> 39#include <net/sock.h>
@@ -477,7 +478,7 @@ failure:
477 * Delete a VIF entry 478 * Delete a VIF entry
478 */ 479 */
479 480
480static int mif6_delete(struct net *net, int vifi) 481static int mif6_delete(struct net *net, int vifi, struct list_head *head)
481{ 482{
482 struct mif_device *v; 483 struct mif_device *v;
483 struct net_device *dev; 484 struct net_device *dev;
@@ -519,7 +520,7 @@ static int mif6_delete(struct net *net, int vifi)
519 in6_dev->cnf.mc_forwarding--; 520 in6_dev->cnf.mc_forwarding--;
520 521
521 if (v->flags & MIFF_REGISTER) 522 if (v->flags & MIFF_REGISTER)
522 unregister_netdevice(dev); 523 unregister_netdevice_queue(dev, head);
523 524
524 dev_put(dev); 525 dev_put(dev);
525 return 0; 526 return 0;
@@ -976,6 +977,7 @@ static int ip6mr_device_event(struct notifier_block *this,
976 struct net *net = dev_net(dev); 977 struct net *net = dev_net(dev);
977 struct mif_device *v; 978 struct mif_device *v;
978 int ct; 979 int ct;
980 LIST_HEAD(list);
979 981
980 if (event != NETDEV_UNREGISTER) 982 if (event != NETDEV_UNREGISTER)
981 return NOTIFY_DONE; 983 return NOTIFY_DONE;
@@ -983,8 +985,10 @@ static int ip6mr_device_event(struct notifier_block *this,
983 v = &net->ipv6.vif6_table[0]; 985 v = &net->ipv6.vif6_table[0];
984 for (ct = 0; ct < net->ipv6.maxvif; ct++, v++) { 986 for (ct = 0; ct < net->ipv6.maxvif; ct++, v++) {
985 if (v->dev == dev) 987 if (v->dev == dev)
986 mif6_delete(net, ct); 988 mif6_delete(net, ct, &list);
987 } 989 }
990 unregister_netdevice_many(&list);
991
988 return NOTIFY_DONE; 992 return NOTIFY_DONE;
989} 993}
990 994
@@ -1110,6 +1114,9 @@ static int ip6mr_mfc_add(struct net *net, struct mf6cctl *mfc, int mrtsock)
1110 unsigned char ttls[MAXMIFS]; 1114 unsigned char ttls[MAXMIFS];
1111 int i; 1115 int i;
1112 1116
1117 if (mfc->mf6cc_parent >= MAXMIFS)
1118 return -ENFILE;
1119
1113 memset(ttls, 255, MAXMIFS); 1120 memset(ttls, 255, MAXMIFS);
1114 for (i = 0; i < MAXMIFS; i++) { 1121 for (i = 0; i < MAXMIFS; i++) {
1115 if (IF_ISSET(i, &mfc->mf6cc_ifset)) 1122 if (IF_ISSET(i, &mfc->mf6cc_ifset))
@@ -1188,14 +1195,16 @@ static int ip6mr_mfc_add(struct net *net, struct mf6cctl *mfc, int mrtsock)
1188static void mroute_clean_tables(struct net *net) 1195static void mroute_clean_tables(struct net *net)
1189{ 1196{
1190 int i; 1197 int i;
1198 LIST_HEAD(list);
1191 1199
1192 /* 1200 /*
1193 * Shut down all active vif entries 1201 * Shut down all active vif entries
1194 */ 1202 */
1195 for (i = 0; i < net->ipv6.maxvif; i++) { 1203 for (i = 0; i < net->ipv6.maxvif; i++) {
1196 if (!(net->ipv6.vif6_table[i].flags & VIFF_STATIC)) 1204 if (!(net->ipv6.vif6_table[i].flags & VIFF_STATIC))
1197 mif6_delete(net, i); 1205 mif6_delete(net, i, &list);
1198 } 1206 }
1207 unregister_netdevice_many(&list);
1199 1208
1200 /* 1209 /*
1201 * Wipe the cache 1210 * Wipe the cache
@@ -1297,7 +1306,7 @@ int ip6_mroute_setsockopt(struct sock *sk, int optname, char __user *optval, uns
1297 switch (optname) { 1306 switch (optname) {
1298 case MRT6_INIT: 1307 case MRT6_INIT:
1299 if (sk->sk_type != SOCK_RAW || 1308 if (sk->sk_type != SOCK_RAW ||
1300 inet_sk(sk)->num != IPPROTO_ICMPV6) 1309 inet_sk(sk)->inet_num != IPPROTO_ICMPV6)
1301 return -EOPNOTSUPP; 1310 return -EOPNOTSUPP;
1302 if (optlen < sizeof(int)) 1311 if (optlen < sizeof(int))
1303 return -EINVAL; 1312 return -EINVAL;
@@ -1325,7 +1334,7 @@ int ip6_mroute_setsockopt(struct sock *sk, int optname, char __user *optval, uns
1325 if (copy_from_user(&mifi, optval, sizeof(mifi_t))) 1334 if (copy_from_user(&mifi, optval, sizeof(mifi_t)))
1326 return -EFAULT; 1335 return -EFAULT;
1327 rtnl_lock(); 1336 rtnl_lock();
1328 ret = mif6_delete(net, mifi); 1337 ret = mif6_delete(net, mifi, NULL);
1329 rtnl_unlock(); 1338 rtnl_unlock();
1330 return ret; 1339 return ret;
1331 1340
@@ -1687,17 +1696,20 @@ ip6mr_fill_mroute(struct sk_buff *skb, struct mfc6_cache *c, struct rtmsg *rtm)
1687 int ct; 1696 int ct;
1688 struct rtnexthop *nhp; 1697 struct rtnexthop *nhp;
1689 struct net *net = mfc6_net(c); 1698 struct net *net = mfc6_net(c);
1690 struct net_device *dev = net->ipv6.vif6_table[c->mf6c_parent].dev;
1691 u8 *b = skb_tail_pointer(skb); 1699 u8 *b = skb_tail_pointer(skb);
1692 struct rtattr *mp_head; 1700 struct rtattr *mp_head;
1693 1701
1694 if (dev) 1702 /* If cache is unresolved, don't try to parse IIF and OIF */
1695 RTA_PUT(skb, RTA_IIF, 4, &dev->ifindex); 1703 if (c->mf6c_parent > MAXMIFS)
1704 return -ENOENT;
1705
1706 if (MIF_EXISTS(net, c->mf6c_parent))
1707 RTA_PUT(skb, RTA_IIF, 4, &net->ipv6.vif6_table[c->mf6c_parent].dev->ifindex);
1696 1708
1697 mp_head = (struct rtattr *)skb_put(skb, RTA_LENGTH(0)); 1709 mp_head = (struct rtattr *)skb_put(skb, RTA_LENGTH(0));
1698 1710
1699 for (ct = c->mfc_un.res.minvif; ct < c->mfc_un.res.maxvif; ct++) { 1711 for (ct = c->mfc_un.res.minvif; ct < c->mfc_un.res.maxvif; ct++) {
1700 if (c->mfc_un.res.ttls[ct] < 255) { 1712 if (MIF_EXISTS(net, ct) && c->mfc_un.res.ttls[ct] < 255) {
1701 if (skb_tailroom(skb) < RTA_ALIGN(RTA_ALIGN(sizeof(*nhp)) + 4)) 1713 if (skb_tailroom(skb) < RTA_ALIGN(RTA_ALIGN(sizeof(*nhp)) + 4))
1702 goto rtattr_failure; 1714 goto rtattr_failure;
1703 nhp = (struct rtnexthop *)skb_put(skb, RTA_ALIGN(sizeof(*nhp))); 1715 nhp = (struct rtnexthop *)skb_put(skb, RTA_ALIGN(sizeof(*nhp)));
diff --git a/net/ipv6/ipcomp6.c b/net/ipv6/ipcomp6.c
index 2f2a5ca2c878..85cccd6ed0b7 100644
--- a/net/ipv6/ipcomp6.c
+++ b/net/ipv6/ipcomp6.c
@@ -53,6 +53,7 @@
53static void ipcomp6_err(struct sk_buff *skb, struct inet6_skb_parm *opt, 53static void ipcomp6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
54 u8 type, u8 code, int offset, __be32 info) 54 u8 type, u8 code, int offset, __be32 info)
55{ 55{
56 struct net *net = dev_net(skb->dev);
56 __be32 spi; 57 __be32 spi;
57 struct ipv6hdr *iph = (struct ipv6hdr*)skb->data; 58 struct ipv6hdr *iph = (struct ipv6hdr*)skb->data;
58 struct ip_comp_hdr *ipcomph = 59 struct ip_comp_hdr *ipcomph =
@@ -63,7 +64,7 @@ static void ipcomp6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
63 return; 64 return;
64 65
65 spi = htonl(ntohs(ipcomph->cpi)); 66 spi = htonl(ntohs(ipcomph->cpi));
66 x = xfrm_state_lookup(&init_net, (xfrm_address_t *)&iph->daddr, spi, IPPROTO_COMP, AF_INET6); 67 x = xfrm_state_lookup(net, skb->mark, (xfrm_address_t *)&iph->daddr, spi, IPPROTO_COMP, AF_INET6);
67 if (!x) 68 if (!x)
68 return; 69 return;
69 70
@@ -74,14 +75,15 @@ static void ipcomp6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
74 75
75static struct xfrm_state *ipcomp6_tunnel_create(struct xfrm_state *x) 76static struct xfrm_state *ipcomp6_tunnel_create(struct xfrm_state *x)
76{ 77{
78 struct net *net = xs_net(x);
77 struct xfrm_state *t = NULL; 79 struct xfrm_state *t = NULL;
78 80
79 t = xfrm_state_alloc(&init_net); 81 t = xfrm_state_alloc(net);
80 if (!t) 82 if (!t)
81 goto out; 83 goto out;
82 84
83 t->id.proto = IPPROTO_IPV6; 85 t->id.proto = IPPROTO_IPV6;
84 t->id.spi = xfrm6_tunnel_alloc_spi((xfrm_address_t *)&x->props.saddr); 86 t->id.spi = xfrm6_tunnel_alloc_spi(net, (xfrm_address_t *)&x->props.saddr);
85 if (!t->id.spi) 87 if (!t->id.spi)
86 goto error; 88 goto error;
87 89
@@ -90,6 +92,7 @@ static struct xfrm_state *ipcomp6_tunnel_create(struct xfrm_state *x)
90 t->props.family = AF_INET6; 92 t->props.family = AF_INET6;
91 t->props.mode = x->props.mode; 93 t->props.mode = x->props.mode;
92 memcpy(t->props.saddr.a6, x->props.saddr.a6, sizeof(struct in6_addr)); 94 memcpy(t->props.saddr.a6, x->props.saddr.a6, sizeof(struct in6_addr));
95 memcpy(&t->mark, &x->mark, sizeof(t->mark));
93 96
94 if (xfrm_init_state(t)) 97 if (xfrm_init_state(t))
95 goto error; 98 goto error;
@@ -108,13 +111,15 @@ error:
108 111
109static int ipcomp6_tunnel_attach(struct xfrm_state *x) 112static int ipcomp6_tunnel_attach(struct xfrm_state *x)
110{ 113{
114 struct net *net = xs_net(x);
111 int err = 0; 115 int err = 0;
112 struct xfrm_state *t = NULL; 116 struct xfrm_state *t = NULL;
113 __be32 spi; 117 __be32 spi;
118 u32 mark = x->mark.m & x->mark.v;
114 119
115 spi = xfrm6_tunnel_spi_lookup((xfrm_address_t *)&x->props.saddr); 120 spi = xfrm6_tunnel_spi_lookup(net, (xfrm_address_t *)&x->props.saddr);
116 if (spi) 121 if (spi)
117 t = xfrm_state_lookup(&init_net, (xfrm_address_t *)&x->id.daddr, 122 t = xfrm_state_lookup(net, mark, (xfrm_address_t *)&x->id.daddr,
118 spi, IPPROTO_IPV6, AF_INET6); 123 spi, IPPROTO_IPV6, AF_INET6);
119 if (!t) { 124 if (!t) {
120 t = ipcomp6_tunnel_create(x); 125 t = ipcomp6_tunnel_create(x);
@@ -154,16 +159,12 @@ static int ipcomp6_init_state(struct xfrm_state *x)
154 if (x->props.mode == XFRM_MODE_TUNNEL) { 159 if (x->props.mode == XFRM_MODE_TUNNEL) {
155 err = ipcomp6_tunnel_attach(x); 160 err = ipcomp6_tunnel_attach(x);
156 if (err) 161 if (err)
157 goto error_tunnel; 162 goto out;
158 } 163 }
159 164
160 err = 0; 165 err = 0;
161out: 166out:
162 return err; 167 return err;
163error_tunnel:
164 ipcomp_destroy(x);
165
166 goto out;
167} 168}
168 169
169static const struct xfrm_type ipcomp6_type = 170static const struct xfrm_type ipcomp6_type =
diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
index 4f7aaf6996a3..33f60fca7aa7 100644
--- a/net/ipv6/ipv6_sockglue.c
+++ b/net/ipv6/ipv6_sockglue.c
@@ -36,6 +36,7 @@
36#include <linux/init.h> 36#include <linux/init.h>
37#include <linux/sysctl.h> 37#include <linux/sysctl.h>
38#include <linux/netfilter.h> 38#include <linux/netfilter.h>
39#include <linux/slab.h>
39 40
40#include <net/sock.h> 41#include <net/sock.h>
41#include <net/snmp.h> 42#include <net/snmp.h>
@@ -64,7 +65,7 @@ int ip6_ra_control(struct sock *sk, int sel)
64 struct ip6_ra_chain *ra, *new_ra, **rap; 65 struct ip6_ra_chain *ra, *new_ra, **rap;
65 66
66 /* RA packet may be delivered ONLY to IPPROTO_RAW socket */ 67 /* RA packet may be delivered ONLY to IPPROTO_RAW socket */
67 if (sk->sk_type != SOCK_RAW || inet_sk(sk)->num != IPPROTO_RAW) 68 if (sk->sk_type != SOCK_RAW || inet_sk(sk)->inet_num != IPPROTO_RAW)
68 return -ENOPROTOOPT; 69 return -ENOPROTOOPT;
69 70
70 new_ra = (sel>=0) ? kmalloc(sizeof(*new_ra), GFP_KERNEL) : NULL; 71 new_ra = (sel>=0) ? kmalloc(sizeof(*new_ra), GFP_KERNEL) : NULL;
@@ -106,7 +107,7 @@ struct ipv6_txoptions *ipv6_update_options(struct sock *sk,
106 if (inet_sk(sk)->is_icsk) { 107 if (inet_sk(sk)->is_icsk) {
107 if (opt && 108 if (opt &&
108 !((1 << sk->sk_state) & (TCPF_LISTEN | TCPF_CLOSE)) && 109 !((1 << sk->sk_state) & (TCPF_LISTEN | TCPF_CLOSE)) &&
109 inet_sk(sk)->daddr != LOOPBACK4_IPV6) { 110 inet_sk(sk)->inet_daddr != LOOPBACK4_IPV6) {
110 struct inet_connection_sock *icsk = inet_csk(sk); 111 struct inet_connection_sock *icsk = inet_csk(sk);
111 icsk->icsk_ext_hdr_len = opt->opt_flen + opt->opt_nflen; 112 icsk->icsk_ext_hdr_len = opt->opt_flen + opt->opt_nflen;
112 icsk->icsk_sync_mss(sk, icsk->icsk_pmtu_cookie); 113 icsk->icsk_sync_mss(sk, icsk->icsk_pmtu_cookie);
@@ -234,7 +235,7 @@ static int do_ipv6_setsockopt(struct sock *sk, int level, int optname,
234 235
235 case IPV6_V6ONLY: 236 case IPV6_V6ONLY:
236 if (optlen < sizeof(int) || 237 if (optlen < sizeof(int) ||
237 inet_sk(sk)->num) 238 inet_sk(sk)->inet_num)
238 goto e_inval; 239 goto e_inval;
239 np->ipv6only = valbool; 240 np->ipv6only = valbool;
240 retv = 0; 241 retv = 0;
@@ -424,6 +425,7 @@ sticky_done:
424 425
425 fl.fl6_flowlabel = 0; 426 fl.fl6_flowlabel = 0;
426 fl.oif = sk->sk_bound_dev_if; 427 fl.oif = sk->sk_bound_dev_if;
428 fl.mark = sk->sk_mark;
427 429
428 if (optlen == 0) 430 if (optlen == 0)
429 goto update; 431 goto update;
@@ -665,7 +667,7 @@ done:
665 case IPV6_MTU_DISCOVER: 667 case IPV6_MTU_DISCOVER:
666 if (optlen < sizeof(int)) 668 if (optlen < sizeof(int))
667 goto e_inval; 669 goto e_inval;
668 if (val<0 || val>3) 670 if (val < IP_PMTUDISC_DONT || val > IP_PMTUDISC_PROBE)
669 goto e_inval; 671 goto e_inval;
670 np->pmtudisc = val; 672 np->pmtudisc = val;
671 retv = 0; 673 retv = 0;
diff --git a/net/ipv6/mcast.c b/net/ipv6/mcast.c
index f9fcf690bd5d..c483ab9fd67b 100644
--- a/net/ipv6/mcast.c
+++ b/net/ipv6/mcast.c
@@ -43,6 +43,7 @@
43#include <linux/init.h> 43#include <linux/init.h>
44#include <linux/proc_fs.h> 44#include <linux/proc_fs.h>
45#include <linux/seq_file.h> 45#include <linux/seq_file.h>
46#include <linux/slab.h>
46 47
47#include <linux/netfilter.h> 48#include <linux/netfilter.h>
48#include <linux/netfilter_ipv6.h> 49#include <linux/netfilter_ipv6.h>
@@ -793,10 +794,10 @@ static void mld_add_delrec(struct inet6_dev *idev, struct ifmcaddr6 *im)
793 } 794 }
794 spin_unlock_bh(&im->mca_lock); 795 spin_unlock_bh(&im->mca_lock);
795 796
796 write_lock_bh(&idev->mc_lock); 797 spin_lock_bh(&idev->mc_lock);
797 pmc->next = idev->mc_tomb; 798 pmc->next = idev->mc_tomb;
798 idev->mc_tomb = pmc; 799 idev->mc_tomb = pmc;
799 write_unlock_bh(&idev->mc_lock); 800 spin_unlock_bh(&idev->mc_lock);
800} 801}
801 802
802static void mld_del_delrec(struct inet6_dev *idev, struct in6_addr *pmca) 803static void mld_del_delrec(struct inet6_dev *idev, struct in6_addr *pmca)
@@ -804,7 +805,7 @@ static void mld_del_delrec(struct inet6_dev *idev, struct in6_addr *pmca)
804 struct ifmcaddr6 *pmc, *pmc_prev; 805 struct ifmcaddr6 *pmc, *pmc_prev;
805 struct ip6_sf_list *psf, *psf_next; 806 struct ip6_sf_list *psf, *psf_next;
806 807
807 write_lock_bh(&idev->mc_lock); 808 spin_lock_bh(&idev->mc_lock);
808 pmc_prev = NULL; 809 pmc_prev = NULL;
809 for (pmc=idev->mc_tomb; pmc; pmc=pmc->next) { 810 for (pmc=idev->mc_tomb; pmc; pmc=pmc->next) {
810 if (ipv6_addr_equal(&pmc->mca_addr, pmca)) 811 if (ipv6_addr_equal(&pmc->mca_addr, pmca))
@@ -817,7 +818,8 @@ static void mld_del_delrec(struct inet6_dev *idev, struct in6_addr *pmca)
817 else 818 else
818 idev->mc_tomb = pmc->next; 819 idev->mc_tomb = pmc->next;
819 } 820 }
820 write_unlock_bh(&idev->mc_lock); 821 spin_unlock_bh(&idev->mc_lock);
822
821 if (pmc) { 823 if (pmc) {
822 for (psf=pmc->mca_tomb; psf; psf=psf_next) { 824 for (psf=pmc->mca_tomb; psf; psf=psf_next) {
823 psf_next = psf->sf_next; 825 psf_next = psf->sf_next;
@@ -832,10 +834,10 @@ static void mld_clear_delrec(struct inet6_dev *idev)
832{ 834{
833 struct ifmcaddr6 *pmc, *nextpmc; 835 struct ifmcaddr6 *pmc, *nextpmc;
834 836
835 write_lock_bh(&idev->mc_lock); 837 spin_lock_bh(&idev->mc_lock);
836 pmc = idev->mc_tomb; 838 pmc = idev->mc_tomb;
837 idev->mc_tomb = NULL; 839 idev->mc_tomb = NULL;
838 write_unlock_bh(&idev->mc_lock); 840 spin_unlock_bh(&idev->mc_lock);
839 841
840 for (; pmc; pmc = nextpmc) { 842 for (; pmc; pmc = nextpmc) {
841 nextpmc = pmc->next; 843 nextpmc = pmc->next;
@@ -1696,7 +1698,7 @@ static void mld_send_cr(struct inet6_dev *idev)
1696 int type, dtype; 1698 int type, dtype;
1697 1699
1698 read_lock_bh(&idev->lock); 1700 read_lock_bh(&idev->lock);
1699 write_lock_bh(&idev->mc_lock); 1701 spin_lock(&idev->mc_lock);
1700 1702
1701 /* deleted MCA's */ 1703 /* deleted MCA's */
1702 pmc_prev = NULL; 1704 pmc_prev = NULL;
@@ -1730,7 +1732,7 @@ static void mld_send_cr(struct inet6_dev *idev)
1730 } else 1732 } else
1731 pmc_prev = pmc; 1733 pmc_prev = pmc;
1732 } 1734 }
1733 write_unlock_bh(&idev->mc_lock); 1735 spin_unlock(&idev->mc_lock);
1734 1736
1735 /* change recs */ 1737 /* change recs */
1736 for (pmc=idev->mc_list; pmc; pmc=pmc->next) { 1738 for (pmc=idev->mc_list; pmc; pmc=pmc->next) {
@@ -2311,7 +2313,7 @@ void ipv6_mc_up(struct inet6_dev *idev)
2311void ipv6_mc_init_dev(struct inet6_dev *idev) 2313void ipv6_mc_init_dev(struct inet6_dev *idev)
2312{ 2314{
2313 write_lock_bh(&idev->lock); 2315 write_lock_bh(&idev->lock);
2314 rwlock_init(&idev->mc_lock); 2316 spin_lock_init(&idev->mc_lock);
2315 idev->mc_gq_running = 0; 2317 idev->mc_gq_running = 0;
2316 setup_timer(&idev->mc_gq_timer, mld_gq_timer_expire, 2318 setup_timer(&idev->mc_gq_timer, mld_gq_timer_expire,
2317 (unsigned long)idev); 2319 (unsigned long)idev);
@@ -2375,9 +2377,9 @@ static inline struct ifmcaddr6 *igmp6_mc_get_first(struct seq_file *seq)
2375 struct net *net = seq_file_net(seq); 2377 struct net *net = seq_file_net(seq);
2376 2378
2377 state->idev = NULL; 2379 state->idev = NULL;
2378 for_each_netdev(net, state->dev) { 2380 for_each_netdev_rcu(net, state->dev) {
2379 struct inet6_dev *idev; 2381 struct inet6_dev *idev;
2380 idev = in6_dev_get(state->dev); 2382 idev = __in6_dev_get(state->dev);
2381 if (!idev) 2383 if (!idev)
2382 continue; 2384 continue;
2383 read_lock_bh(&idev->lock); 2385 read_lock_bh(&idev->lock);
@@ -2387,7 +2389,6 @@ static inline struct ifmcaddr6 *igmp6_mc_get_first(struct seq_file *seq)
2387 break; 2389 break;
2388 } 2390 }
2389 read_unlock_bh(&idev->lock); 2391 read_unlock_bh(&idev->lock);
2390 in6_dev_put(idev);
2391 } 2392 }
2392 return im; 2393 return im;
2393} 2394}
@@ -2398,16 +2399,15 @@ static struct ifmcaddr6 *igmp6_mc_get_next(struct seq_file *seq, struct ifmcaddr
2398 2399
2399 im = im->next; 2400 im = im->next;
2400 while (!im) { 2401 while (!im) {
2401 if (likely(state->idev != NULL)) { 2402 if (likely(state->idev != NULL))
2402 read_unlock_bh(&state->idev->lock); 2403 read_unlock_bh(&state->idev->lock);
2403 in6_dev_put(state->idev); 2404
2404 } 2405 state->dev = next_net_device_rcu(state->dev);
2405 state->dev = next_net_device(state->dev);
2406 if (!state->dev) { 2406 if (!state->dev) {
2407 state->idev = NULL; 2407 state->idev = NULL;
2408 break; 2408 break;
2409 } 2409 }
2410 state->idev = in6_dev_get(state->dev); 2410 state->idev = __in6_dev_get(state->dev);
2411 if (!state->idev) 2411 if (!state->idev)
2412 continue; 2412 continue;
2413 read_lock_bh(&state->idev->lock); 2413 read_lock_bh(&state->idev->lock);
@@ -2426,31 +2426,31 @@ static struct ifmcaddr6 *igmp6_mc_get_idx(struct seq_file *seq, loff_t pos)
2426} 2426}
2427 2427
2428static void *igmp6_mc_seq_start(struct seq_file *seq, loff_t *pos) 2428static void *igmp6_mc_seq_start(struct seq_file *seq, loff_t *pos)
2429 __acquires(dev_base_lock) 2429 __acquires(RCU)
2430{ 2430{
2431 read_lock(&dev_base_lock); 2431 rcu_read_lock();
2432 return igmp6_mc_get_idx(seq, *pos); 2432 return igmp6_mc_get_idx(seq, *pos);
2433} 2433}
2434 2434
2435static void *igmp6_mc_seq_next(struct seq_file *seq, void *v, loff_t *pos) 2435static void *igmp6_mc_seq_next(struct seq_file *seq, void *v, loff_t *pos)
2436{ 2436{
2437 struct ifmcaddr6 *im; 2437 struct ifmcaddr6 *im = igmp6_mc_get_next(seq, v);
2438 im = igmp6_mc_get_next(seq, v); 2438
2439 ++*pos; 2439 ++*pos;
2440 return im; 2440 return im;
2441} 2441}
2442 2442
2443static void igmp6_mc_seq_stop(struct seq_file *seq, void *v) 2443static void igmp6_mc_seq_stop(struct seq_file *seq, void *v)
2444 __releases(dev_base_lock) 2444 __releases(RCU)
2445{ 2445{
2446 struct igmp6_mc_iter_state *state = igmp6_mc_seq_private(seq); 2446 struct igmp6_mc_iter_state *state = igmp6_mc_seq_private(seq);
2447
2447 if (likely(state->idev != NULL)) { 2448 if (likely(state->idev != NULL)) {
2448 read_unlock_bh(&state->idev->lock); 2449 read_unlock_bh(&state->idev->lock);
2449 in6_dev_put(state->idev);
2450 state->idev = NULL; 2450 state->idev = NULL;
2451 } 2451 }
2452 state->dev = NULL; 2452 state->dev = NULL;
2453 read_unlock(&dev_base_lock); 2453 rcu_read_unlock();
2454} 2454}
2455 2455
2456static int igmp6_mc_seq_show(struct seq_file *seq, void *v) 2456static int igmp6_mc_seq_show(struct seq_file *seq, void *v)
@@ -2507,9 +2507,9 @@ static inline struct ip6_sf_list *igmp6_mcf_get_first(struct seq_file *seq)
2507 2507
2508 state->idev = NULL; 2508 state->idev = NULL;
2509 state->im = NULL; 2509 state->im = NULL;
2510 for_each_netdev(net, state->dev) { 2510 for_each_netdev_rcu(net, state->dev) {
2511 struct inet6_dev *idev; 2511 struct inet6_dev *idev;
2512 idev = in6_dev_get(state->dev); 2512 idev = __in6_dev_get(state->dev);
2513 if (unlikely(idev == NULL)) 2513 if (unlikely(idev == NULL))
2514 continue; 2514 continue;
2515 read_lock_bh(&idev->lock); 2515 read_lock_bh(&idev->lock);
@@ -2525,7 +2525,6 @@ static inline struct ip6_sf_list *igmp6_mcf_get_first(struct seq_file *seq)
2525 spin_unlock_bh(&im->mca_lock); 2525 spin_unlock_bh(&im->mca_lock);
2526 } 2526 }
2527 read_unlock_bh(&idev->lock); 2527 read_unlock_bh(&idev->lock);
2528 in6_dev_put(idev);
2529 } 2528 }
2530 return psf; 2529 return psf;
2531} 2530}
@@ -2539,16 +2538,15 @@ static struct ip6_sf_list *igmp6_mcf_get_next(struct seq_file *seq, struct ip6_s
2539 spin_unlock_bh(&state->im->mca_lock); 2538 spin_unlock_bh(&state->im->mca_lock);
2540 state->im = state->im->next; 2539 state->im = state->im->next;
2541 while (!state->im) { 2540 while (!state->im) {
2542 if (likely(state->idev != NULL)) { 2541 if (likely(state->idev != NULL))
2543 read_unlock_bh(&state->idev->lock); 2542 read_unlock_bh(&state->idev->lock);
2544 in6_dev_put(state->idev); 2543
2545 } 2544 state->dev = next_net_device_rcu(state->dev);
2546 state->dev = next_net_device(state->dev);
2547 if (!state->dev) { 2545 if (!state->dev) {
2548 state->idev = NULL; 2546 state->idev = NULL;
2549 goto out; 2547 goto out;
2550 } 2548 }
2551 state->idev = in6_dev_get(state->dev); 2549 state->idev = __in6_dev_get(state->dev);
2552 if (!state->idev) 2550 if (!state->idev)
2553 continue; 2551 continue;
2554 read_lock_bh(&state->idev->lock); 2552 read_lock_bh(&state->idev->lock);
@@ -2573,9 +2571,9 @@ static struct ip6_sf_list *igmp6_mcf_get_idx(struct seq_file *seq, loff_t pos)
2573} 2571}
2574 2572
2575static void *igmp6_mcf_seq_start(struct seq_file *seq, loff_t *pos) 2573static void *igmp6_mcf_seq_start(struct seq_file *seq, loff_t *pos)
2576 __acquires(dev_base_lock) 2574 __acquires(RCU)
2577{ 2575{
2578 read_lock(&dev_base_lock); 2576 rcu_read_lock();
2579 return *pos ? igmp6_mcf_get_idx(seq, *pos - 1) : SEQ_START_TOKEN; 2577 return *pos ? igmp6_mcf_get_idx(seq, *pos - 1) : SEQ_START_TOKEN;
2580} 2578}
2581 2579
@@ -2591,7 +2589,7 @@ static void *igmp6_mcf_seq_next(struct seq_file *seq, void *v, loff_t *pos)
2591} 2589}
2592 2590
2593static void igmp6_mcf_seq_stop(struct seq_file *seq, void *v) 2591static void igmp6_mcf_seq_stop(struct seq_file *seq, void *v)
2594 __releases(dev_base_lock) 2592 __releases(RCU)
2595{ 2593{
2596 struct igmp6_mcf_iter_state *state = igmp6_mcf_seq_private(seq); 2594 struct igmp6_mcf_iter_state *state = igmp6_mcf_seq_private(seq);
2597 if (likely(state->im != NULL)) { 2595 if (likely(state->im != NULL)) {
@@ -2600,11 +2598,10 @@ static void igmp6_mcf_seq_stop(struct seq_file *seq, void *v)
2600 } 2598 }
2601 if (likely(state->idev != NULL)) { 2599 if (likely(state->idev != NULL)) {
2602 read_unlock_bh(&state->idev->lock); 2600 read_unlock_bh(&state->idev->lock);
2603 in6_dev_put(state->idev);
2604 state->idev = NULL; 2601 state->idev = NULL;
2605 } 2602 }
2606 state->dev = NULL; 2603 state->dev = NULL;
2607 read_unlock(&dev_base_lock); 2604 rcu_read_unlock();
2608} 2605}
2609 2606
2610static int igmp6_mcf_seq_show(struct seq_file *seq, void *v) 2607static int igmp6_mcf_seq_show(struct seq_file *seq, void *v)
@@ -2651,7 +2648,7 @@ static const struct file_operations igmp6_mcf_seq_fops = {
2651 .release = seq_release_net, 2648 .release = seq_release_net,
2652}; 2649};
2653 2650
2654static int igmp6_proc_init(struct net *net) 2651static int __net_init igmp6_proc_init(struct net *net)
2655{ 2652{
2656 int err; 2653 int err;
2657 2654
@@ -2671,23 +2668,22 @@ out_proc_net_igmp6:
2671 goto out; 2668 goto out;
2672} 2669}
2673 2670
2674static void igmp6_proc_exit(struct net *net) 2671static void __net_exit igmp6_proc_exit(struct net *net)
2675{ 2672{
2676 proc_net_remove(net, "mcfilter6"); 2673 proc_net_remove(net, "mcfilter6");
2677 proc_net_remove(net, "igmp6"); 2674 proc_net_remove(net, "igmp6");
2678} 2675}
2679#else 2676#else
2680static int igmp6_proc_init(struct net *net) 2677static inline int igmp6_proc_init(struct net *net)
2681{ 2678{
2682 return 0; 2679 return 0;
2683} 2680}
2684static void igmp6_proc_exit(struct net *net) 2681static inline void igmp6_proc_exit(struct net *net)
2685{ 2682{
2686 ;
2687} 2683}
2688#endif 2684#endif
2689 2685
2690static int igmp6_net_init(struct net *net) 2686static int __net_init igmp6_net_init(struct net *net)
2691{ 2687{
2692 int err; 2688 int err;
2693 2689
@@ -2713,7 +2709,7 @@ out_sock_create:
2713 goto out; 2709 goto out;
2714} 2710}
2715 2711
2716static void igmp6_net_exit(struct net *net) 2712static void __net_exit igmp6_net_exit(struct net *net)
2717{ 2713{
2718 inet_ctl_sock_destroy(net->ipv6.igmp_sk); 2714 inet_ctl_sock_destroy(net->ipv6.igmp_sk);
2719 igmp6_proc_exit(net); 2715 igmp6_proc_exit(net);
diff --git a/net/ipv6/mip6.c b/net/ipv6/mip6.c
index f797e8c6f3b3..2794b6002836 100644
--- a/net/ipv6/mip6.c
+++ b/net/ipv6/mip6.c
@@ -56,7 +56,7 @@ static inline void *mip6_padn(__u8 *data, __u8 padlen)
56 56
57static inline void mip6_param_prob(struct sk_buff *skb, u8 code, int pos) 57static inline void mip6_param_prob(struct sk_buff *skb, u8 code, int pos)
58{ 58{
59 icmpv6_send(skb, ICMPV6_PARAMPROB, code, pos, skb->dev); 59 icmpv6_send(skb, ICMPV6_PARAMPROB, code, pos);
60} 60}
61 61
62static int mip6_mh_len(int type) 62static int mip6_mh_len(int type)
diff --git a/net/ipv6/ndisc.c b/net/ipv6/ndisc.c
index f74e4e2cdd06..da0a4d2adc69 100644
--- a/net/ipv6/ndisc.c
+++ b/net/ipv6/ndisc.c
@@ -59,6 +59,7 @@
59#include <linux/route.h> 59#include <linux/route.h>
60#include <linux/init.h> 60#include <linux/init.h>
61#include <linux/rcupdate.h> 61#include <linux/rcupdate.h>
62#include <linux/slab.h>
62#ifdef CONFIG_SYSCTL 63#ifdef CONFIG_SYSCTL
63#include <linux/sysctl.h> 64#include <linux/sysctl.h>
64#endif 65#endif
@@ -598,6 +599,7 @@ static void ndisc_send_na(struct net_device *dev, struct neighbour *neigh,
598 icmp6h.icmp6_solicited = solicited; 599 icmp6h.icmp6_solicited = solicited;
599 icmp6h.icmp6_override = override; 600 icmp6h.icmp6_override = override;
600 601
602 inc_opt |= ifp->idev->cnf.force_tllao;
601 __ndisc_send(dev, neigh, daddr, src_addr, 603 __ndisc_send(dev, neigh, daddr, src_addr,
602 &icmp6h, solicited_addr, 604 &icmp6h, solicited_addr,
603 inc_opt ? ND_OPT_TARGET_LL_ADDR : 0); 605 inc_opt ? ND_OPT_TARGET_LL_ADDR : 0);
@@ -1768,46 +1770,10 @@ int ndisc_ifinfo_sysctl_change(struct ctl_table *ctl, int write, void __user *bu
1768 return ret; 1770 return ret;
1769} 1771}
1770 1772
1771int ndisc_ifinfo_sysctl_strategy(ctl_table *ctl,
1772 void __user *oldval, size_t __user *oldlenp,
1773 void __user *newval, size_t newlen)
1774{
1775 struct net_device *dev = ctl->extra1;
1776 struct inet6_dev *idev;
1777 int ret;
1778
1779 if (ctl->ctl_name == NET_NEIGH_RETRANS_TIME ||
1780 ctl->ctl_name == NET_NEIGH_REACHABLE_TIME)
1781 ndisc_warn_deprecated_sysctl(ctl, "procfs", dev ? dev->name : "default");
1782
1783 switch (ctl->ctl_name) {
1784 case NET_NEIGH_REACHABLE_TIME:
1785 ret = sysctl_jiffies(ctl, oldval, oldlenp, newval, newlen);
1786 break;
1787 case NET_NEIGH_RETRANS_TIME_MS:
1788 case NET_NEIGH_REACHABLE_TIME_MS:
1789 ret = sysctl_ms_jiffies(ctl, oldval, oldlenp, newval, newlen);
1790 break;
1791 default:
1792 ret = 0;
1793 }
1794
1795 if (newval && newlen && ret > 0 &&
1796 dev && (idev = in6_dev_get(dev)) != NULL) {
1797 if (ctl->ctl_name == NET_NEIGH_REACHABLE_TIME ||
1798 ctl->ctl_name == NET_NEIGH_REACHABLE_TIME_MS)
1799 idev->nd_parms->reachable_time = neigh_rand_reach_time(idev->nd_parms->base_reachable_time);
1800 idev->tstamp = jiffies;
1801 inet6_ifinfo_notify(RTM_NEWLINK, idev);
1802 in6_dev_put(idev);
1803 }
1804
1805 return ret;
1806}
1807 1773
1808#endif 1774#endif
1809 1775
1810static int ndisc_net_init(struct net *net) 1776static int __net_init ndisc_net_init(struct net *net)
1811{ 1777{
1812 struct ipv6_pinfo *np; 1778 struct ipv6_pinfo *np;
1813 struct sock *sk; 1779 struct sock *sk;
@@ -1832,7 +1798,7 @@ static int ndisc_net_init(struct net *net)
1832 return 0; 1798 return 0;
1833} 1799}
1834 1800
1835static void ndisc_net_exit(struct net *net) 1801static void __net_exit ndisc_net_exit(struct net *net)
1836{ 1802{
1837 inet_ctl_sock_destroy(net->ipv6.ndisc_sk); 1803 inet_ctl_sock_destroy(net->ipv6.ndisc_sk);
1838} 1804}
@@ -1855,10 +1821,8 @@ int __init ndisc_init(void)
1855 neigh_table_init(&nd_tbl); 1821 neigh_table_init(&nd_tbl);
1856 1822
1857#ifdef CONFIG_SYSCTL 1823#ifdef CONFIG_SYSCTL
1858 err = neigh_sysctl_register(NULL, &nd_tbl.parms, NET_IPV6, 1824 err = neigh_sysctl_register(NULL, &nd_tbl.parms, "ipv6",
1859 NET_IPV6_NEIGH, "ipv6", 1825 &ndisc_ifinfo_sysctl_change);
1860 &ndisc_ifinfo_sysctl_change,
1861 &ndisc_ifinfo_sysctl_strategy);
1862 if (err) 1826 if (err)
1863 goto out_unregister_pernet; 1827 goto out_unregister_pernet;
1864#endif 1828#endif
diff --git a/net/ipv6/netfilter/ip6_queue.c b/net/ipv6/netfilter/ip6_queue.c
index 1cf3f0c6a959..6a68a74d14a3 100644
--- a/net/ipv6/netfilter/ip6_queue.c
+++ b/net/ipv6/netfilter/ip6_queue.c
@@ -25,6 +25,7 @@
25#include <linux/proc_fs.h> 25#include <linux/proc_fs.h>
26#include <linux/seq_file.h> 26#include <linux/seq_file.h>
27#include <linux/mutex.h> 27#include <linux/mutex.h>
28#include <linux/slab.h>
28#include <net/net_namespace.h> 29#include <net/net_namespace.h>
29#include <net/sock.h> 30#include <net/sock.h>
30#include <net/ipv6.h> 31#include <net/ipv6.h>
@@ -36,7 +37,6 @@
36 37
37#define IPQ_QMAX_DEFAULT 1024 38#define IPQ_QMAX_DEFAULT 1024
38#define IPQ_PROC_FS_NAME "ip6_queue" 39#define IPQ_PROC_FS_NAME "ip6_queue"
39#define NET_IPQ_QMAX 2088
40#define NET_IPQ_QMAX_NAME "ip6_queue_maxlen" 40#define NET_IPQ_QMAX_NAME "ip6_queue_maxlen"
41 41
42typedef int (*ipq_cmpfn)(struct nf_queue_entry *, unsigned long); 42typedef int (*ipq_cmpfn)(struct nf_queue_entry *, unsigned long);
@@ -499,10 +499,9 @@ ipq_rcv_nl_event(struct notifier_block *this,
499{ 499{
500 struct netlink_notify *n = ptr; 500 struct netlink_notify *n = ptr;
501 501
502 if (event == NETLINK_URELEASE && 502 if (event == NETLINK_URELEASE && n->protocol == NETLINK_IP6_FW) {
503 n->protocol == NETLINK_IP6_FW && n->pid) {
504 write_lock_bh(&queue_lock); 503 write_lock_bh(&queue_lock);
505 if ((n->net == &init_net) && (n->pid == peer_pid)) 504 if ((net_eq(n->net, &init_net)) && (n->pid == peer_pid))
506 __ipq_reset(); 505 __ipq_reset();
507 write_unlock_bh(&queue_lock); 506 write_unlock_bh(&queue_lock);
508 } 507 }
@@ -518,14 +517,13 @@ static struct ctl_table_header *ipq_sysctl_header;
518 517
519static ctl_table ipq_table[] = { 518static ctl_table ipq_table[] = {
520 { 519 {
521 .ctl_name = NET_IPQ_QMAX,
522 .procname = NET_IPQ_QMAX_NAME, 520 .procname = NET_IPQ_QMAX_NAME,
523 .data = &queue_maxlen, 521 .data = &queue_maxlen,
524 .maxlen = sizeof(queue_maxlen), 522 .maxlen = sizeof(queue_maxlen),
525 .mode = 0644, 523 .mode = 0644,
526 .proc_handler = proc_dointvec 524 .proc_handler = proc_dointvec
527 }, 525 },
528 { .ctl_name = 0 } 526 { }
529}; 527};
530#endif 528#endif
531 529
@@ -625,7 +623,7 @@ cleanup_netlink_notifier:
625static void __exit ip6_queue_fini(void) 623static void __exit ip6_queue_fini(void)
626{ 624{
627 nf_unregister_queue_handlers(&nfqh); 625 nf_unregister_queue_handlers(&nfqh);
628 synchronize_net(); 626
629 ipq_flush(NULL, 0); 627 ipq_flush(NULL, 0);
630 628
631#ifdef CONFIG_SYSCTL 629#ifdef CONFIG_SYSCTL
diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
index cc9f8ef303fd..9210e312edf1 100644
--- a/net/ipv6/netfilter/ip6_tables.c
+++ b/net/ipv6/netfilter/ip6_tables.c
@@ -29,6 +29,7 @@
29#include <linux/netfilter_ipv6/ip6_tables.h> 29#include <linux/netfilter_ipv6/ip6_tables.h>
30#include <linux/netfilter/x_tables.h> 30#include <linux/netfilter/x_tables.h>
31#include <net/netfilter/nf_log.h> 31#include <net/netfilter/nf_log.h>
32#include "../../netfilter/xt_repldata.h"
32 33
33MODULE_LICENSE("GPL"); 34MODULE_LICENSE("GPL");
34MODULE_AUTHOR("Netfilter Core Team <coreteam@netfilter.org>"); 35MODULE_AUTHOR("Netfilter Core Team <coreteam@netfilter.org>");
@@ -67,6 +68,12 @@ do { \
67#define inline 68#define inline
68#endif 69#endif
69 70
71void *ip6t_alloc_initial_table(const struct xt_table *info)
72{
73 return xt_alloc_initial_table(ip6t, IP6T);
74}
75EXPORT_SYMBOL_GPL(ip6t_alloc_initial_table);
76
70/* 77/*
71 We keep a set of rules for each CPU, so we can avoid write-locking 78 We keep a set of rules for each CPU, so we can avoid write-locking
72 them in the softirq when updating the counters and therefore 79 them in the softirq when updating the counters and therefore
@@ -105,9 +112,9 @@ ip6_packet_match(const struct sk_buff *skb,
105#define FWINV(bool, invflg) ((bool) ^ !!(ip6info->invflags & (invflg))) 112#define FWINV(bool, invflg) ((bool) ^ !!(ip6info->invflags & (invflg)))
106 113
107 if (FWINV(ipv6_masked_addr_cmp(&ipv6->saddr, &ip6info->smsk, 114 if (FWINV(ipv6_masked_addr_cmp(&ipv6->saddr, &ip6info->smsk,
108 &ip6info->src), IP6T_INV_SRCIP) 115 &ip6info->src), IP6T_INV_SRCIP) ||
109 || FWINV(ipv6_masked_addr_cmp(&ipv6->daddr, &ip6info->dmsk, 116 FWINV(ipv6_masked_addr_cmp(&ipv6->daddr, &ip6info->dmsk,
110 &ip6info->dst), IP6T_INV_DSTIP)) { 117 &ip6info->dst), IP6T_INV_DSTIP)) {
111 dprintf("Source or dest mismatch.\n"); 118 dprintf("Source or dest mismatch.\n");
112/* 119/*
113 dprintf("SRC: %u. Mask: %u. Target: %u.%s\n", ip->saddr, 120 dprintf("SRC: %u. Mask: %u. Target: %u.%s\n", ip->saddr,
@@ -201,7 +208,7 @@ ip6t_error(struct sk_buff *skb, const struct xt_target_param *par)
201 208
202/* Performance critical - called for every packet */ 209/* Performance critical - called for every packet */
203static inline bool 210static inline bool
204do_match(struct ip6t_entry_match *m, const struct sk_buff *skb, 211do_match(const struct ip6t_entry_match *m, const struct sk_buff *skb,
205 struct xt_match_param *par) 212 struct xt_match_param *par)
206{ 213{
207 par->match = m->u.kernel.match; 214 par->match = m->u.kernel.match;
@@ -215,7 +222,7 @@ do_match(struct ip6t_entry_match *m, const struct sk_buff *skb,
215} 222}
216 223
217static inline struct ip6t_entry * 224static inline struct ip6t_entry *
218get_entry(void *base, unsigned int offset) 225get_entry(const void *base, unsigned int offset)
219{ 226{
220 return (struct ip6t_entry *)(base + offset); 227 return (struct ip6t_entry *)(base + offset);
221} 228}
@@ -229,6 +236,12 @@ static inline bool unconditional(const struct ip6t_ip6 *ipv6)
229 return memcmp(ipv6, &uncond, sizeof(uncond)) == 0; 236 return memcmp(ipv6, &uncond, sizeof(uncond)) == 0;
230} 237}
231 238
239static inline const struct ip6t_entry_target *
240ip6t_get_target_c(const struct ip6t_entry *e)
241{
242 return ip6t_get_target((struct ip6t_entry *)e);
243}
244
232#if defined(CONFIG_NETFILTER_XT_TARGET_TRACE) || \ 245#if defined(CONFIG_NETFILTER_XT_TARGET_TRACE) || \
233 defined(CONFIG_NETFILTER_XT_TARGET_TRACE_MODULE) 246 defined(CONFIG_NETFILTER_XT_TARGET_TRACE_MODULE)
234/* This cries for unification! */ 247/* This cries for unification! */
@@ -264,11 +277,11 @@ static struct nf_loginfo trace_loginfo = {
264 277
265/* Mildly perf critical (only if packet tracing is on) */ 278/* Mildly perf critical (only if packet tracing is on) */
266static inline int 279static inline int
267get_chainname_rulenum(struct ip6t_entry *s, struct ip6t_entry *e, 280get_chainname_rulenum(const struct ip6t_entry *s, const struct ip6t_entry *e,
268 const char *hookname, const char **chainname, 281 const char *hookname, const char **chainname,
269 const char **comment, unsigned int *rulenum) 282 const char **comment, unsigned int *rulenum)
270{ 283{
271 struct ip6t_standard_target *t = (void *)ip6t_get_target(s); 284 const struct ip6t_standard_target *t = (void *)ip6t_get_target_c(s);
272 285
273 if (strcmp(t->target.u.kernel.target->name, IP6T_ERROR_TARGET) == 0) { 286 if (strcmp(t->target.u.kernel.target->name, IP6T_ERROR_TARGET) == 0) {
274 /* Head of user chain: ERROR target with chainname */ 287 /* Head of user chain: ERROR target with chainname */
@@ -277,11 +290,11 @@ get_chainname_rulenum(struct ip6t_entry *s, struct ip6t_entry *e,
277 } else if (s == e) { 290 } else if (s == e) {
278 (*rulenum)++; 291 (*rulenum)++;
279 292
280 if (s->target_offset == sizeof(struct ip6t_entry) 293 if (s->target_offset == sizeof(struct ip6t_entry) &&
281 && strcmp(t->target.u.kernel.target->name, 294 strcmp(t->target.u.kernel.target->name,
282 IP6T_STANDARD_TARGET) == 0 295 IP6T_STANDARD_TARGET) == 0 &&
283 && t->verdict < 0 296 t->verdict < 0 &&
284 && unconditional(&s->ipv6)) { 297 unconditional(&s->ipv6)) {
285 /* Tail of chains: STANDARD target (return/policy) */ 298 /* Tail of chains: STANDARD target (return/policy) */
286 *comment = *chainname == hookname 299 *comment = *chainname == hookname
287 ? comments[NF_IP6_TRACE_COMMENT_POLICY] 300 ? comments[NF_IP6_TRACE_COMMENT_POLICY]
@@ -294,17 +307,18 @@ get_chainname_rulenum(struct ip6t_entry *s, struct ip6t_entry *e,
294 return 0; 307 return 0;
295} 308}
296 309
297static void trace_packet(struct sk_buff *skb, 310static void trace_packet(const struct sk_buff *skb,
298 unsigned int hook, 311 unsigned int hook,
299 const struct net_device *in, 312 const struct net_device *in,
300 const struct net_device *out, 313 const struct net_device *out,
301 const char *tablename, 314 const char *tablename,
302 struct xt_table_info *private, 315 const struct xt_table_info *private,
303 struct ip6t_entry *e) 316 const struct ip6t_entry *e)
304{ 317{
305 void *table_base; 318 const void *table_base;
306 const struct ip6t_entry *root; 319 const struct ip6t_entry *root;
307 const char *hookname, *chainname, *comment; 320 const char *hookname, *chainname, *comment;
321 const struct ip6t_entry *iter;
308 unsigned int rulenum = 0; 322 unsigned int rulenum = 0;
309 323
310 table_base = private->entries[smp_processor_id()]; 324 table_base = private->entries[smp_processor_id()];
@@ -313,10 +327,10 @@ static void trace_packet(struct sk_buff *skb,
313 hookname = chainname = hooknames[hook]; 327 hookname = chainname = hooknames[hook];
314 comment = comments[NF_IP6_TRACE_COMMENT_RULE]; 328 comment = comments[NF_IP6_TRACE_COMMENT_RULE];
315 329
316 IP6T_ENTRY_ITERATE(root, 330 xt_entry_foreach(iter, root, private->size - private->hook_entry[hook])
317 private->size - private->hook_entry[hook], 331 if (get_chainname_rulenum(iter, e, hookname,
318 get_chainname_rulenum, 332 &chainname, &comment, &rulenum) != 0)
319 e, hookname, &chainname, &comment, &rulenum); 333 break;
320 334
321 nf_log_packet(AF_INET6, hook, skb, in, out, &trace_loginfo, 335 nf_log_packet(AF_INET6, hook, skb, in, out, &trace_loginfo,
322 "TRACE: %s:%s:%s:%u ", 336 "TRACE: %s:%s:%s:%u ",
@@ -345,9 +359,9 @@ ip6t_do_table(struct sk_buff *skb,
345 /* Initializing verdict to NF_DROP keeps gcc happy. */ 359 /* Initializing verdict to NF_DROP keeps gcc happy. */
346 unsigned int verdict = NF_DROP; 360 unsigned int verdict = NF_DROP;
347 const char *indev, *outdev; 361 const char *indev, *outdev;
348 void *table_base; 362 const void *table_base;
349 struct ip6t_entry *e, *back; 363 struct ip6t_entry *e, *back;
350 struct xt_table_info *private; 364 const struct xt_table_info *private;
351 struct xt_match_param mtpar; 365 struct xt_match_param mtpar;
352 struct xt_target_param tgpar; 366 struct xt_target_param tgpar;
353 367
@@ -378,22 +392,27 @@ ip6t_do_table(struct sk_buff *skb,
378 back = get_entry(table_base, private->underflow[hook]); 392 back = get_entry(table_base, private->underflow[hook]);
379 393
380 do { 394 do {
381 struct ip6t_entry_target *t; 395 const struct ip6t_entry_target *t;
396 const struct xt_entry_match *ematch;
382 397
383 IP_NF_ASSERT(e); 398 IP_NF_ASSERT(e);
384 IP_NF_ASSERT(back); 399 IP_NF_ASSERT(back);
385 if (!ip6_packet_match(skb, indev, outdev, &e->ipv6, 400 if (!ip6_packet_match(skb, indev, outdev, &e->ipv6,
386 &mtpar.thoff, &mtpar.fragoff, &hotdrop) || 401 &mtpar.thoff, &mtpar.fragoff, &hotdrop)) {
387 IP6T_MATCH_ITERATE(e, do_match, skb, &mtpar) != 0) { 402 no_match:
388 e = ip6t_next_entry(e); 403 e = ip6t_next_entry(e);
389 continue; 404 continue;
390 } 405 }
391 406
407 xt_ematch_foreach(ematch, e)
408 if (do_match(ematch, skb, &mtpar) != 0)
409 goto no_match;
410
392 ADD_COUNTER(e->counters, 411 ADD_COUNTER(e->counters,
393 ntohs(ipv6_hdr(skb)->payload_len) + 412 ntohs(ipv6_hdr(skb)->payload_len) +
394 sizeof(struct ipv6hdr), 1); 413 sizeof(struct ipv6hdr), 1);
395 414
396 t = ip6t_get_target(e); 415 t = ip6t_get_target_c(e);
397 IP_NF_ASSERT(t->u.kernel.target); 416 IP_NF_ASSERT(t->u.kernel.target);
398 417
399#if defined(CONFIG_NETFILTER_XT_TARGET_TRACE) || \ 418#if defined(CONFIG_NETFILTER_XT_TARGET_TRACE) || \
@@ -418,8 +437,8 @@ ip6t_do_table(struct sk_buff *skb,
418 back = get_entry(table_base, back->comefrom); 437 back = get_entry(table_base, back->comefrom);
419 continue; 438 continue;
420 } 439 }
421 if (table_base + v != ip6t_next_entry(e) 440 if (table_base + v != ip6t_next_entry(e) &&
422 && !(e->ipv6.flags & IP6T_F_GOTO)) { 441 !(e->ipv6.flags & IP6T_F_GOTO)) {
423 /* Save old back ptr in next entry */ 442 /* Save old back ptr in next entry */
424 struct ip6t_entry *next = ip6t_next_entry(e); 443 struct ip6t_entry *next = ip6t_next_entry(e);
425 next->comefrom = (void *)back - table_base; 444 next->comefrom = (void *)back - table_base;
@@ -475,7 +494,7 @@ ip6t_do_table(struct sk_buff *skb,
475/* Figures out from what hook each rule can be called: returns 0 if 494/* Figures out from what hook each rule can be called: returns 0 if
476 there are loops. Puts hook bitmask in comefrom. */ 495 there are loops. Puts hook bitmask in comefrom. */
477static int 496static int
478mark_source_chains(struct xt_table_info *newinfo, 497mark_source_chains(const struct xt_table_info *newinfo,
479 unsigned int valid_hooks, void *entry0) 498 unsigned int valid_hooks, void *entry0)
480{ 499{
481 unsigned int hook; 500 unsigned int hook;
@@ -493,8 +512,8 @@ mark_source_chains(struct xt_table_info *newinfo,
493 e->counters.pcnt = pos; 512 e->counters.pcnt = pos;
494 513
495 for (;;) { 514 for (;;) {
496 struct ip6t_standard_target *t 515 const struct ip6t_standard_target *t
497 = (void *)ip6t_get_target(e); 516 = (void *)ip6t_get_target_c(e);
498 int visited = e->comefrom & (1 << hook); 517 int visited = e->comefrom & (1 << hook);
499 518
500 if (e->comefrom & (1 << NF_INET_NUMHOOKS)) { 519 if (e->comefrom & (1 << NF_INET_NUMHOOKS)) {
@@ -505,11 +524,11 @@ mark_source_chains(struct xt_table_info *newinfo,
505 e->comefrom |= ((1 << hook) | (1 << NF_INET_NUMHOOKS)); 524 e->comefrom |= ((1 << hook) | (1 << NF_INET_NUMHOOKS));
506 525
507 /* Unconditional return/END. */ 526 /* Unconditional return/END. */
508 if ((e->target_offset == sizeof(struct ip6t_entry) 527 if ((e->target_offset == sizeof(struct ip6t_entry) &&
509 && (strcmp(t->target.u.user.name, 528 (strcmp(t->target.u.user.name,
510 IP6T_STANDARD_TARGET) == 0) 529 IP6T_STANDARD_TARGET) == 0) &&
511 && t->verdict < 0 530 t->verdict < 0 &&
512 && unconditional(&e->ipv6)) || visited) { 531 unconditional(&e->ipv6)) || visited) {
513 unsigned int oldpos, size; 532 unsigned int oldpos, size;
514 533
515 if ((strcmp(t->target.u.user.name, 534 if ((strcmp(t->target.u.user.name,
@@ -556,8 +575,8 @@ mark_source_chains(struct xt_table_info *newinfo,
556 int newpos = t->verdict; 575 int newpos = t->verdict;
557 576
558 if (strcmp(t->target.u.user.name, 577 if (strcmp(t->target.u.user.name,
559 IP6T_STANDARD_TARGET) == 0 578 IP6T_STANDARD_TARGET) == 0 &&
560 && newpos >= 0) { 579 newpos >= 0) {
561 if (newpos > newinfo->size - 580 if (newpos > newinfo->size -
562 sizeof(struct ip6t_entry)) { 581 sizeof(struct ip6t_entry)) {
563 duprintf("mark_source_chains: " 582 duprintf("mark_source_chains: "
@@ -584,27 +603,23 @@ mark_source_chains(struct xt_table_info *newinfo,
584 return 1; 603 return 1;
585} 604}
586 605
587static int 606static void cleanup_match(struct ip6t_entry_match *m, struct net *net)
588cleanup_match(struct ip6t_entry_match *m, unsigned int *i)
589{ 607{
590 struct xt_mtdtor_param par; 608 struct xt_mtdtor_param par;
591 609
592 if (i && (*i)-- == 0) 610 par.net = net;
593 return 1;
594
595 par.match = m->u.kernel.match; 611 par.match = m->u.kernel.match;
596 par.matchinfo = m->data; 612 par.matchinfo = m->data;
597 par.family = NFPROTO_IPV6; 613 par.family = NFPROTO_IPV6;
598 if (par.match->destroy != NULL) 614 if (par.match->destroy != NULL)
599 par.match->destroy(&par); 615 par.match->destroy(&par);
600 module_put(par.match->me); 616 module_put(par.match->me);
601 return 0;
602} 617}
603 618
604static int 619static int
605check_entry(struct ip6t_entry *e, const char *name) 620check_entry(const struct ip6t_entry *e, const char *name)
606{ 621{
607 struct ip6t_entry_target *t; 622 const struct ip6t_entry_target *t;
608 623
609 if (!ip6_checkentry(&e->ipv6)) { 624 if (!ip6_checkentry(&e->ipv6)) {
610 duprintf("ip_tables: ip check failed %p %s.\n", e, name); 625 duprintf("ip_tables: ip check failed %p %s.\n", e, name);
@@ -615,15 +630,14 @@ check_entry(struct ip6t_entry *e, const char *name)
615 e->next_offset) 630 e->next_offset)
616 return -EINVAL; 631 return -EINVAL;
617 632
618 t = ip6t_get_target(e); 633 t = ip6t_get_target_c(e);
619 if (e->target_offset + t->u.target_size > e->next_offset) 634 if (e->target_offset + t->u.target_size > e->next_offset)
620 return -EINVAL; 635 return -EINVAL;
621 636
622 return 0; 637 return 0;
623} 638}
624 639
625static int check_match(struct ip6t_entry_match *m, struct xt_mtchk_param *par, 640static int check_match(struct ip6t_entry_match *m, struct xt_mtchk_param *par)
626 unsigned int *i)
627{ 641{
628 const struct ip6t_ip6 *ipv6 = par->entryinfo; 642 const struct ip6t_ip6 *ipv6 = par->entryinfo;
629 int ret; 643 int ret;
@@ -638,13 +652,11 @@ static int check_match(struct ip6t_entry_match *m, struct xt_mtchk_param *par,
638 par.match->name); 652 par.match->name);
639 return ret; 653 return ret;
640 } 654 }
641 ++*i;
642 return 0; 655 return 0;
643} 656}
644 657
645static int 658static int
646find_check_match(struct ip6t_entry_match *m, struct xt_mtchk_param *par, 659find_check_match(struct ip6t_entry_match *m, struct xt_mtchk_param *par)
647 unsigned int *i)
648{ 660{
649 struct xt_match *match; 661 struct xt_match *match;
650 int ret; 662 int ret;
@@ -658,7 +670,7 @@ find_check_match(struct ip6t_entry_match *m, struct xt_mtchk_param *par,
658 } 670 }
659 m->u.kernel.match = match; 671 m->u.kernel.match = match;
660 672
661 ret = check_match(m, par, i); 673 ret = check_match(m, par);
662 if (ret) 674 if (ret)
663 goto err; 675 goto err;
664 676
@@ -668,10 +680,11 @@ err:
668 return ret; 680 return ret;
669} 681}
670 682
671static int check_target(struct ip6t_entry *e, const char *name) 683static int check_target(struct ip6t_entry *e, struct net *net, const char *name)
672{ 684{
673 struct ip6t_entry_target *t = ip6t_get_target(e); 685 struct ip6t_entry_target *t = ip6t_get_target(e);
674 struct xt_tgchk_param par = { 686 struct xt_tgchk_param par = {
687 .net = net,
675 .table = name, 688 .table = name,
676 .entryinfo = e, 689 .entryinfo = e,
677 .target = t->u.kernel.target, 690 .target = t->u.kernel.target,
@@ -693,27 +706,32 @@ static int check_target(struct ip6t_entry *e, const char *name)
693} 706}
694 707
695static int 708static int
696find_check_entry(struct ip6t_entry *e, const char *name, unsigned int size, 709find_check_entry(struct ip6t_entry *e, struct net *net, const char *name,
697 unsigned int *i) 710 unsigned int size)
698{ 711{
699 struct ip6t_entry_target *t; 712 struct ip6t_entry_target *t;
700 struct xt_target *target; 713 struct xt_target *target;
701 int ret; 714 int ret;
702 unsigned int j; 715 unsigned int j;
703 struct xt_mtchk_param mtpar; 716 struct xt_mtchk_param mtpar;
717 struct xt_entry_match *ematch;
704 718
705 ret = check_entry(e, name); 719 ret = check_entry(e, name);
706 if (ret) 720 if (ret)
707 return ret; 721 return ret;
708 722
709 j = 0; 723 j = 0;
724 mtpar.net = net;
710 mtpar.table = name; 725 mtpar.table = name;
711 mtpar.entryinfo = &e->ipv6; 726 mtpar.entryinfo = &e->ipv6;
712 mtpar.hook_mask = e->comefrom; 727 mtpar.hook_mask = e->comefrom;
713 mtpar.family = NFPROTO_IPV6; 728 mtpar.family = NFPROTO_IPV6;
714 ret = IP6T_MATCH_ITERATE(e, find_check_match, &mtpar, &j); 729 xt_ematch_foreach(ematch, e) {
715 if (ret != 0) 730 ret = find_check_match(ematch, &mtpar);
716 goto cleanup_matches; 731 if (ret != 0)
732 goto cleanup_matches;
733 ++j;
734 }
717 735
718 t = ip6t_get_target(e); 736 t = ip6t_get_target(e);
719 target = try_then_request_module(xt_find_target(AF_INET6, 737 target = try_then_request_module(xt_find_target(AF_INET6,
@@ -727,27 +745,29 @@ find_check_entry(struct ip6t_entry *e, const char *name, unsigned int size,
727 } 745 }
728 t->u.kernel.target = target; 746 t->u.kernel.target = target;
729 747
730 ret = check_target(e, name); 748 ret = check_target(e, net, name);
731 if (ret) 749 if (ret)
732 goto err; 750 goto err;
733
734 (*i)++;
735 return 0; 751 return 0;
736 err: 752 err:
737 module_put(t->u.kernel.target->me); 753 module_put(t->u.kernel.target->me);
738 cleanup_matches: 754 cleanup_matches:
739 IP6T_MATCH_ITERATE(e, cleanup_match, &j); 755 xt_ematch_foreach(ematch, e) {
756 if (j-- == 0)
757 break;
758 cleanup_match(ematch, net);
759 }
740 return ret; 760 return ret;
741} 761}
742 762
743static bool check_underflow(struct ip6t_entry *e) 763static bool check_underflow(const struct ip6t_entry *e)
744{ 764{
745 const struct ip6t_entry_target *t; 765 const struct ip6t_entry_target *t;
746 unsigned int verdict; 766 unsigned int verdict;
747 767
748 if (!unconditional(&e->ipv6)) 768 if (!unconditional(&e->ipv6))
749 return false; 769 return false;
750 t = ip6t_get_target(e); 770 t = ip6t_get_target_c(e);
751 if (strcmp(t->u.user.name, XT_STANDARD_TARGET) != 0) 771 if (strcmp(t->u.user.name, XT_STANDARD_TARGET) != 0)
752 return false; 772 return false;
753 verdict = ((struct ip6t_standard_target *)t)->verdict; 773 verdict = ((struct ip6t_standard_target *)t)->verdict;
@@ -758,17 +778,16 @@ static bool check_underflow(struct ip6t_entry *e)
758static int 778static int
759check_entry_size_and_hooks(struct ip6t_entry *e, 779check_entry_size_and_hooks(struct ip6t_entry *e,
760 struct xt_table_info *newinfo, 780 struct xt_table_info *newinfo,
761 unsigned char *base, 781 const unsigned char *base,
762 unsigned char *limit, 782 const unsigned char *limit,
763 const unsigned int *hook_entries, 783 const unsigned int *hook_entries,
764 const unsigned int *underflows, 784 const unsigned int *underflows,
765 unsigned int valid_hooks, 785 unsigned int valid_hooks)
766 unsigned int *i)
767{ 786{
768 unsigned int h; 787 unsigned int h;
769 788
770 if ((unsigned long)e % __alignof__(struct ip6t_entry) != 0 789 if ((unsigned long)e % __alignof__(struct ip6t_entry) != 0 ||
771 || (unsigned char *)e + sizeof(struct ip6t_entry) >= limit) { 790 (unsigned char *)e + sizeof(struct ip6t_entry) >= limit) {
772 duprintf("Bad offset %p\n", e); 791 duprintf("Bad offset %p\n", e);
773 return -EINVAL; 792 return -EINVAL;
774 } 793 }
@@ -800,50 +819,41 @@ check_entry_size_and_hooks(struct ip6t_entry *e,
800 /* Clear counters and comefrom */ 819 /* Clear counters and comefrom */
801 e->counters = ((struct xt_counters) { 0, 0 }); 820 e->counters = ((struct xt_counters) { 0, 0 });
802 e->comefrom = 0; 821 e->comefrom = 0;
803
804 (*i)++;
805 return 0; 822 return 0;
806} 823}
807 824
808static int 825static void cleanup_entry(struct ip6t_entry *e, struct net *net)
809cleanup_entry(struct ip6t_entry *e, unsigned int *i)
810{ 826{
811 struct xt_tgdtor_param par; 827 struct xt_tgdtor_param par;
812 struct ip6t_entry_target *t; 828 struct ip6t_entry_target *t;
813 829 struct xt_entry_match *ematch;
814 if (i && (*i)-- == 0)
815 return 1;
816 830
817 /* Cleanup all matches */ 831 /* Cleanup all matches */
818 IP6T_MATCH_ITERATE(e, cleanup_match, NULL); 832 xt_ematch_foreach(ematch, e)
833 cleanup_match(ematch, net);
819 t = ip6t_get_target(e); 834 t = ip6t_get_target(e);
820 835
836 par.net = net;
821 par.target = t->u.kernel.target; 837 par.target = t->u.kernel.target;
822 par.targinfo = t->data; 838 par.targinfo = t->data;
823 par.family = NFPROTO_IPV6; 839 par.family = NFPROTO_IPV6;
824 if (par.target->destroy != NULL) 840 if (par.target->destroy != NULL)
825 par.target->destroy(&par); 841 par.target->destroy(&par);
826 module_put(par.target->me); 842 module_put(par.target->me);
827 return 0;
828} 843}
829 844
830/* Checks and translates the user-supplied table segment (held in 845/* Checks and translates the user-supplied table segment (held in
831 newinfo) */ 846 newinfo) */
832static int 847static int
833translate_table(const char *name, 848translate_table(struct net *net, struct xt_table_info *newinfo, void *entry0,
834 unsigned int valid_hooks, 849 const struct ip6t_replace *repl)
835 struct xt_table_info *newinfo,
836 void *entry0,
837 unsigned int size,
838 unsigned int number,
839 const unsigned int *hook_entries,
840 const unsigned int *underflows)
841{ 850{
851 struct ip6t_entry *iter;
842 unsigned int i; 852 unsigned int i;
843 int ret; 853 int ret = 0;
844 854
845 newinfo->size = size; 855 newinfo->size = repl->size;
846 newinfo->number = number; 856 newinfo->number = repl->num_entries;
847 857
848 /* Init all hooks to impossible value. */ 858 /* Init all hooks to impossible value. */
849 for (i = 0; i < NF_INET_NUMHOOKS; i++) { 859 for (i = 0; i < NF_INET_NUMHOOKS; i++) {
@@ -854,49 +864,58 @@ translate_table(const char *name,
854 duprintf("translate_table: size %u\n", newinfo->size); 864 duprintf("translate_table: size %u\n", newinfo->size);
855 i = 0; 865 i = 0;
856 /* Walk through entries, checking offsets. */ 866 /* Walk through entries, checking offsets. */
857 ret = IP6T_ENTRY_ITERATE(entry0, newinfo->size, 867 xt_entry_foreach(iter, entry0, newinfo->size) {
858 check_entry_size_and_hooks, 868 ret = check_entry_size_and_hooks(iter, newinfo, entry0,
859 newinfo, 869 entry0 + repl->size,
860 entry0, 870 repl->hook_entry,
861 entry0 + size, 871 repl->underflow,
862 hook_entries, underflows, valid_hooks, &i); 872 repl->valid_hooks);
863 if (ret != 0) 873 if (ret != 0)
864 return ret; 874 return ret;
875 ++i;
876 }
865 877
866 if (i != number) { 878 if (i != repl->num_entries) {
867 duprintf("translate_table: %u not %u entries\n", 879 duprintf("translate_table: %u not %u entries\n",
868 i, number); 880 i, repl->num_entries);
869 return -EINVAL; 881 return -EINVAL;
870 } 882 }
871 883
872 /* Check hooks all assigned */ 884 /* Check hooks all assigned */
873 for (i = 0; i < NF_INET_NUMHOOKS; i++) { 885 for (i = 0; i < NF_INET_NUMHOOKS; i++) {
874 /* Only hooks which are valid */ 886 /* Only hooks which are valid */
875 if (!(valid_hooks & (1 << i))) 887 if (!(repl->valid_hooks & (1 << i)))
876 continue; 888 continue;
877 if (newinfo->hook_entry[i] == 0xFFFFFFFF) { 889 if (newinfo->hook_entry[i] == 0xFFFFFFFF) {
878 duprintf("Invalid hook entry %u %u\n", 890 duprintf("Invalid hook entry %u %u\n",
879 i, hook_entries[i]); 891 i, repl->hook_entry[i]);
880 return -EINVAL; 892 return -EINVAL;
881 } 893 }
882 if (newinfo->underflow[i] == 0xFFFFFFFF) { 894 if (newinfo->underflow[i] == 0xFFFFFFFF) {
883 duprintf("Invalid underflow %u %u\n", 895 duprintf("Invalid underflow %u %u\n",
884 i, underflows[i]); 896 i, repl->underflow[i]);
885 return -EINVAL; 897 return -EINVAL;
886 } 898 }
887 } 899 }
888 900
889 if (!mark_source_chains(newinfo, valid_hooks, entry0)) 901 if (!mark_source_chains(newinfo, repl->valid_hooks, entry0))
890 return -ELOOP; 902 return -ELOOP;
891 903
892 /* Finally, each sanity check must pass */ 904 /* Finally, each sanity check must pass */
893 i = 0; 905 i = 0;
894 ret = IP6T_ENTRY_ITERATE(entry0, newinfo->size, 906 xt_entry_foreach(iter, entry0, newinfo->size) {
895 find_check_entry, name, size, &i); 907 ret = find_check_entry(iter, net, repl->name, repl->size);
908 if (ret != 0)
909 break;
910 ++i;
911 }
896 912
897 if (ret != 0) { 913 if (ret != 0) {
898 IP6T_ENTRY_ITERATE(entry0, newinfo->size, 914 xt_entry_foreach(iter, entry0, newinfo->size) {
899 cleanup_entry, &i); 915 if (i-- == 0)
916 break;
917 cleanup_entry(iter, net);
918 }
900 return ret; 919 return ret;
901 } 920 }
902 921
@@ -909,33 +928,11 @@ translate_table(const char *name,
909 return ret; 928 return ret;
910} 929}
911 930
912/* Gets counters. */
913static inline int
914add_entry_to_counter(const struct ip6t_entry *e,
915 struct xt_counters total[],
916 unsigned int *i)
917{
918 ADD_COUNTER(total[*i], e->counters.bcnt, e->counters.pcnt);
919
920 (*i)++;
921 return 0;
922}
923
924static inline int
925set_entry_to_counter(const struct ip6t_entry *e,
926 struct ip6t_counters total[],
927 unsigned int *i)
928{
929 SET_COUNTER(total[*i], e->counters.bcnt, e->counters.pcnt);
930
931 (*i)++;
932 return 0;
933}
934
935static void 931static void
936get_counters(const struct xt_table_info *t, 932get_counters(const struct xt_table_info *t,
937 struct xt_counters counters[]) 933 struct xt_counters counters[])
938{ 934{
935 struct ip6t_entry *iter;
939 unsigned int cpu; 936 unsigned int cpu;
940 unsigned int i; 937 unsigned int i;
941 unsigned int curcpu; 938 unsigned int curcpu;
@@ -951,32 +948,32 @@ get_counters(const struct xt_table_info *t,
951 curcpu = smp_processor_id(); 948 curcpu = smp_processor_id();
952 949
953 i = 0; 950 i = 0;
954 IP6T_ENTRY_ITERATE(t->entries[curcpu], 951 xt_entry_foreach(iter, t->entries[curcpu], t->size) {
955 t->size, 952 SET_COUNTER(counters[i], iter->counters.bcnt,
956 set_entry_to_counter, 953 iter->counters.pcnt);
957 counters, 954 ++i;
958 &i); 955 }
959 956
960 for_each_possible_cpu(cpu) { 957 for_each_possible_cpu(cpu) {
961 if (cpu == curcpu) 958 if (cpu == curcpu)
962 continue; 959 continue;
963 i = 0; 960 i = 0;
964 xt_info_wrlock(cpu); 961 xt_info_wrlock(cpu);
965 IP6T_ENTRY_ITERATE(t->entries[cpu], 962 xt_entry_foreach(iter, t->entries[cpu], t->size) {
966 t->size, 963 ADD_COUNTER(counters[i], iter->counters.bcnt,
967 add_entry_to_counter, 964 iter->counters.pcnt);
968 counters, 965 ++i;
969 &i); 966 }
970 xt_info_wrunlock(cpu); 967 xt_info_wrunlock(cpu);
971 } 968 }
972 local_bh_enable(); 969 local_bh_enable();
973} 970}
974 971
975static struct xt_counters *alloc_counters(struct xt_table *table) 972static struct xt_counters *alloc_counters(const struct xt_table *table)
976{ 973{
977 unsigned int countersize; 974 unsigned int countersize;
978 struct xt_counters *counters; 975 struct xt_counters *counters;
979 struct xt_table_info *private = table->private; 976 const struct xt_table_info *private = table->private;
980 977
981 /* We need atomic snapshot of counters: rest doesn't change 978 /* We need atomic snapshot of counters: rest doesn't change
982 (other than comefrom, which userspace doesn't care 979 (other than comefrom, which userspace doesn't care
@@ -994,11 +991,11 @@ static struct xt_counters *alloc_counters(struct xt_table *table)
994 991
995static int 992static int
996copy_entries_to_user(unsigned int total_size, 993copy_entries_to_user(unsigned int total_size,
997 struct xt_table *table, 994 const struct xt_table *table,
998 void __user *userptr) 995 void __user *userptr)
999{ 996{
1000 unsigned int off, num; 997 unsigned int off, num;
1001 struct ip6t_entry *e; 998 const struct ip6t_entry *e;
1002 struct xt_counters *counters; 999 struct xt_counters *counters;
1003 const struct xt_table_info *private = table->private; 1000 const struct xt_table_info *private = table->private;
1004 int ret = 0; 1001 int ret = 0;
@@ -1050,7 +1047,7 @@ copy_entries_to_user(unsigned int total_size,
1050 } 1047 }
1051 } 1048 }
1052 1049
1053 t = ip6t_get_target(e); 1050 t = ip6t_get_target_c(e);
1054 if (copy_to_user(userptr + off + e->target_offset 1051 if (copy_to_user(userptr + off + e->target_offset
1055 + offsetof(struct ip6t_entry_target, 1052 + offsetof(struct ip6t_entry_target,
1056 u.user.name), 1053 u.user.name),
@@ -1067,7 +1064,7 @@ copy_entries_to_user(unsigned int total_size,
1067} 1064}
1068 1065
1069#ifdef CONFIG_COMPAT 1066#ifdef CONFIG_COMPAT
1070static void compat_standard_from_user(void *dst, void *src) 1067static void compat_standard_from_user(void *dst, const void *src)
1071{ 1068{
1072 int v = *(compat_int_t *)src; 1069 int v = *(compat_int_t *)src;
1073 1070
@@ -1076,7 +1073,7 @@ static void compat_standard_from_user(void *dst, void *src)
1076 memcpy(dst, &v, sizeof(v)); 1073 memcpy(dst, &v, sizeof(v));
1077} 1074}
1078 1075
1079static int compat_standard_to_user(void __user *dst, void *src) 1076static int compat_standard_to_user(void __user *dst, const void *src)
1080{ 1077{
1081 compat_int_t cv = *(int *)src; 1078 compat_int_t cv = *(int *)src;
1082 1079
@@ -1085,25 +1082,20 @@ static int compat_standard_to_user(void __user *dst, void *src)
1085 return copy_to_user(dst, &cv, sizeof(cv)) ? -EFAULT : 0; 1082 return copy_to_user(dst, &cv, sizeof(cv)) ? -EFAULT : 0;
1086} 1083}
1087 1084
1088static inline int 1085static int compat_calc_entry(const struct ip6t_entry *e,
1089compat_calc_match(struct ip6t_entry_match *m, int *size)
1090{
1091 *size += xt_compat_match_offset(m->u.kernel.match);
1092 return 0;
1093}
1094
1095static int compat_calc_entry(struct ip6t_entry *e,
1096 const struct xt_table_info *info, 1086 const struct xt_table_info *info,
1097 void *base, struct xt_table_info *newinfo) 1087 const void *base, struct xt_table_info *newinfo)
1098{ 1088{
1099 struct ip6t_entry_target *t; 1089 const struct xt_entry_match *ematch;
1090 const struct ip6t_entry_target *t;
1100 unsigned int entry_offset; 1091 unsigned int entry_offset;
1101 int off, i, ret; 1092 int off, i, ret;
1102 1093
1103 off = sizeof(struct ip6t_entry) - sizeof(struct compat_ip6t_entry); 1094 off = sizeof(struct ip6t_entry) - sizeof(struct compat_ip6t_entry);
1104 entry_offset = (void *)e - base; 1095 entry_offset = (void *)e - base;
1105 IP6T_MATCH_ITERATE(e, compat_calc_match, &off); 1096 xt_ematch_foreach(ematch, e)
1106 t = ip6t_get_target(e); 1097 off += xt_compat_match_offset(ematch->u.kernel.match);
1098 t = ip6t_get_target_c(e);
1107 off += xt_compat_target_offset(t->u.kernel.target); 1099 off += xt_compat_target_offset(t->u.kernel.target);
1108 newinfo->size -= off; 1100 newinfo->size -= off;
1109 ret = xt_compat_add_offset(AF_INET6, entry_offset, off); 1101 ret = xt_compat_add_offset(AF_INET6, entry_offset, off);
@@ -1124,7 +1116,9 @@ static int compat_calc_entry(struct ip6t_entry *e,
1124static int compat_table_info(const struct xt_table_info *info, 1116static int compat_table_info(const struct xt_table_info *info,
1125 struct xt_table_info *newinfo) 1117 struct xt_table_info *newinfo)
1126{ 1118{
1119 struct ip6t_entry *iter;
1127 void *loc_cpu_entry; 1120 void *loc_cpu_entry;
1121 int ret;
1128 1122
1129 if (!newinfo || !info) 1123 if (!newinfo || !info)
1130 return -EINVAL; 1124 return -EINVAL;
@@ -1133,13 +1127,17 @@ static int compat_table_info(const struct xt_table_info *info,
1133 memcpy(newinfo, info, offsetof(struct xt_table_info, entries)); 1127 memcpy(newinfo, info, offsetof(struct xt_table_info, entries));
1134 newinfo->initial_entries = 0; 1128 newinfo->initial_entries = 0;
1135 loc_cpu_entry = info->entries[raw_smp_processor_id()]; 1129 loc_cpu_entry = info->entries[raw_smp_processor_id()];
1136 return IP6T_ENTRY_ITERATE(loc_cpu_entry, info->size, 1130 xt_entry_foreach(iter, loc_cpu_entry, info->size) {
1137 compat_calc_entry, info, loc_cpu_entry, 1131 ret = compat_calc_entry(iter, info, loc_cpu_entry, newinfo);
1138 newinfo); 1132 if (ret != 0)
1133 return ret;
1134 }
1135 return 0;
1139} 1136}
1140#endif 1137#endif
1141 1138
1142static int get_info(struct net *net, void __user *user, int *len, int compat) 1139static int get_info(struct net *net, void __user *user,
1140 const int *len, int compat)
1143{ 1141{
1144 char name[IP6T_TABLE_MAXNAMELEN]; 1142 char name[IP6T_TABLE_MAXNAMELEN];
1145 struct xt_table *t; 1143 struct xt_table *t;
@@ -1164,10 +1162,10 @@ static int get_info(struct net *net, void __user *user, int *len, int compat)
1164 if (t && !IS_ERR(t)) { 1162 if (t && !IS_ERR(t)) {
1165 struct ip6t_getinfo info; 1163 struct ip6t_getinfo info;
1166 const struct xt_table_info *private = t->private; 1164 const struct xt_table_info *private = t->private;
1167
1168#ifdef CONFIG_COMPAT 1165#ifdef CONFIG_COMPAT
1166 struct xt_table_info tmp;
1167
1169 if (compat) { 1168 if (compat) {
1170 struct xt_table_info tmp;
1171 ret = compat_table_info(private, &tmp); 1169 ret = compat_table_info(private, &tmp);
1172 xt_compat_flush_offsets(AF_INET6); 1170 xt_compat_flush_offsets(AF_INET6);
1173 private = &tmp; 1171 private = &tmp;
@@ -1199,7 +1197,8 @@ static int get_info(struct net *net, void __user *user, int *len, int compat)
1199} 1197}
1200 1198
1201static int 1199static int
1202get_entries(struct net *net, struct ip6t_get_entries __user *uptr, int *len) 1200get_entries(struct net *net, struct ip6t_get_entries __user *uptr,
1201 const int *len)
1203{ 1202{
1204 int ret; 1203 int ret;
1205 struct ip6t_get_entries get; 1204 struct ip6t_get_entries get;
@@ -1247,6 +1246,7 @@ __do_replace(struct net *net, const char *name, unsigned int valid_hooks,
1247 struct xt_table_info *oldinfo; 1246 struct xt_table_info *oldinfo;
1248 struct xt_counters *counters; 1247 struct xt_counters *counters;
1249 const void *loc_cpu_old_entry; 1248 const void *loc_cpu_old_entry;
1249 struct ip6t_entry *iter;
1250 1250
1251 ret = 0; 1251 ret = 0;
1252 counters = vmalloc_node(num_counters * sizeof(struct xt_counters), 1252 counters = vmalloc_node(num_counters * sizeof(struct xt_counters),
@@ -1290,8 +1290,9 @@ __do_replace(struct net *net, const char *name, unsigned int valid_hooks,
1290 1290
1291 /* Decrease module usage counts and free resource */ 1291 /* Decrease module usage counts and free resource */
1292 loc_cpu_old_entry = oldinfo->entries[raw_smp_processor_id()]; 1292 loc_cpu_old_entry = oldinfo->entries[raw_smp_processor_id()];
1293 IP6T_ENTRY_ITERATE(loc_cpu_old_entry, oldinfo->size, cleanup_entry, 1293 xt_entry_foreach(iter, loc_cpu_old_entry, oldinfo->size)
1294 NULL); 1294 cleanup_entry(iter, net);
1295
1295 xt_free_table_info(oldinfo); 1296 xt_free_table_info(oldinfo);
1296 if (copy_to_user(counters_ptr, counters, 1297 if (copy_to_user(counters_ptr, counters,
1297 sizeof(struct xt_counters) * num_counters) != 0) 1298 sizeof(struct xt_counters) * num_counters) != 0)
@@ -1310,12 +1311,13 @@ __do_replace(struct net *net, const char *name, unsigned int valid_hooks,
1310} 1311}
1311 1312
1312static int 1313static int
1313do_replace(struct net *net, void __user *user, unsigned int len) 1314do_replace(struct net *net, const void __user *user, unsigned int len)
1314{ 1315{
1315 int ret; 1316 int ret;
1316 struct ip6t_replace tmp; 1317 struct ip6t_replace tmp;
1317 struct xt_table_info *newinfo; 1318 struct xt_table_info *newinfo;
1318 void *loc_cpu_entry; 1319 void *loc_cpu_entry;
1320 struct ip6t_entry *iter;
1319 1321
1320 if (copy_from_user(&tmp, user, sizeof(tmp)) != 0) 1322 if (copy_from_user(&tmp, user, sizeof(tmp)) != 0)
1321 return -EFAULT; 1323 return -EFAULT;
@@ -1336,9 +1338,7 @@ do_replace(struct net *net, void __user *user, unsigned int len)
1336 goto free_newinfo; 1338 goto free_newinfo;
1337 } 1339 }
1338 1340
1339 ret = translate_table(tmp.name, tmp.valid_hooks, 1341 ret = translate_table(net, newinfo, loc_cpu_entry, &tmp);
1340 newinfo, loc_cpu_entry, tmp.size, tmp.num_entries,
1341 tmp.hook_entry, tmp.underflow);
1342 if (ret != 0) 1342 if (ret != 0)
1343 goto free_newinfo; 1343 goto free_newinfo;
1344 1344
@@ -1351,27 +1351,15 @@ do_replace(struct net *net, void __user *user, unsigned int len)
1351 return 0; 1351 return 0;
1352 1352
1353 free_newinfo_untrans: 1353 free_newinfo_untrans:
1354 IP6T_ENTRY_ITERATE(loc_cpu_entry, newinfo->size, cleanup_entry, NULL); 1354 xt_entry_foreach(iter, loc_cpu_entry, newinfo->size)
1355 cleanup_entry(iter, net);
1355 free_newinfo: 1356 free_newinfo:
1356 xt_free_table_info(newinfo); 1357 xt_free_table_info(newinfo);
1357 return ret; 1358 return ret;
1358} 1359}
1359 1360
1360/* We're lazy, and add to the first CPU; overflow works its fey magic
1361 * and everything is OK. */
1362static int 1361static int
1363add_counter_to_entry(struct ip6t_entry *e, 1362do_add_counters(struct net *net, const void __user *user, unsigned int len,
1364 const struct xt_counters addme[],
1365 unsigned int *i)
1366{
1367 ADD_COUNTER(e->counters, addme[*i].bcnt, addme[*i].pcnt);
1368
1369 (*i)++;
1370 return 0;
1371}
1372
1373static int
1374do_add_counters(struct net *net, void __user *user, unsigned int len,
1375 int compat) 1363 int compat)
1376{ 1364{
1377 unsigned int i, curcpu; 1365 unsigned int i, curcpu;
@@ -1385,6 +1373,7 @@ do_add_counters(struct net *net, void __user *user, unsigned int len,
1385 const struct xt_table_info *private; 1373 const struct xt_table_info *private;
1386 int ret = 0; 1374 int ret = 0;
1387 const void *loc_cpu_entry; 1375 const void *loc_cpu_entry;
1376 struct ip6t_entry *iter;
1388#ifdef CONFIG_COMPAT 1377#ifdef CONFIG_COMPAT
1389 struct compat_xt_counters_info compat_tmp; 1378 struct compat_xt_counters_info compat_tmp;
1390 1379
@@ -1443,11 +1432,10 @@ do_add_counters(struct net *net, void __user *user, unsigned int len,
1443 curcpu = smp_processor_id(); 1432 curcpu = smp_processor_id();
1444 xt_info_wrlock(curcpu); 1433 xt_info_wrlock(curcpu);
1445 loc_cpu_entry = private->entries[curcpu]; 1434 loc_cpu_entry = private->entries[curcpu];
1446 IP6T_ENTRY_ITERATE(loc_cpu_entry, 1435 xt_entry_foreach(iter, loc_cpu_entry, private->size) {
1447 private->size, 1436 ADD_COUNTER(iter->counters, paddc[i].bcnt, paddc[i].pcnt);
1448 add_counter_to_entry, 1437 ++i;
1449 paddc, 1438 }
1450 &i);
1451 xt_info_wrunlock(curcpu); 1439 xt_info_wrunlock(curcpu);
1452 1440
1453 unlock_up_free: 1441 unlock_up_free:
@@ -1476,45 +1464,40 @@ struct compat_ip6t_replace {
1476static int 1464static int
1477compat_copy_entry_to_user(struct ip6t_entry *e, void __user **dstptr, 1465compat_copy_entry_to_user(struct ip6t_entry *e, void __user **dstptr,
1478 unsigned int *size, struct xt_counters *counters, 1466 unsigned int *size, struct xt_counters *counters,
1479 unsigned int *i) 1467 unsigned int i)
1480{ 1468{
1481 struct ip6t_entry_target *t; 1469 struct ip6t_entry_target *t;
1482 struct compat_ip6t_entry __user *ce; 1470 struct compat_ip6t_entry __user *ce;
1483 u_int16_t target_offset, next_offset; 1471 u_int16_t target_offset, next_offset;
1484 compat_uint_t origsize; 1472 compat_uint_t origsize;
1485 int ret; 1473 const struct xt_entry_match *ematch;
1474 int ret = 0;
1486 1475
1487 ret = -EFAULT;
1488 origsize = *size; 1476 origsize = *size;
1489 ce = (struct compat_ip6t_entry __user *)*dstptr; 1477 ce = (struct compat_ip6t_entry __user *)*dstptr;
1490 if (copy_to_user(ce, e, sizeof(struct ip6t_entry))) 1478 if (copy_to_user(ce, e, sizeof(struct ip6t_entry)) != 0 ||
1491 goto out; 1479 copy_to_user(&ce->counters, &counters[i],
1492 1480 sizeof(counters[i])) != 0)
1493 if (copy_to_user(&ce->counters, &counters[*i], sizeof(counters[*i]))) 1481 return -EFAULT;
1494 goto out;
1495 1482
1496 *dstptr += sizeof(struct compat_ip6t_entry); 1483 *dstptr += sizeof(struct compat_ip6t_entry);
1497 *size -= sizeof(struct ip6t_entry) - sizeof(struct compat_ip6t_entry); 1484 *size -= sizeof(struct ip6t_entry) - sizeof(struct compat_ip6t_entry);
1498 1485
1499 ret = IP6T_MATCH_ITERATE(e, xt_compat_match_to_user, dstptr, size); 1486 xt_ematch_foreach(ematch, e) {
1487 ret = xt_compat_match_to_user(ematch, dstptr, size);
1488 if (ret != 0)
1489 return ret;
1490 }
1500 target_offset = e->target_offset - (origsize - *size); 1491 target_offset = e->target_offset - (origsize - *size);
1501 if (ret)
1502 goto out;
1503 t = ip6t_get_target(e); 1492 t = ip6t_get_target(e);
1504 ret = xt_compat_target_to_user(t, dstptr, size); 1493 ret = xt_compat_target_to_user(t, dstptr, size);
1505 if (ret) 1494 if (ret)
1506 goto out; 1495 return ret;
1507 ret = -EFAULT;
1508 next_offset = e->next_offset - (origsize - *size); 1496 next_offset = e->next_offset - (origsize - *size);
1509 if (put_user(target_offset, &ce->target_offset)) 1497 if (put_user(target_offset, &ce->target_offset) != 0 ||
1510 goto out; 1498 put_user(next_offset, &ce->next_offset) != 0)
1511 if (put_user(next_offset, &ce->next_offset)) 1499 return -EFAULT;
1512 goto out;
1513
1514 (*i)++;
1515 return 0; 1500 return 0;
1516out:
1517 return ret;
1518} 1501}
1519 1502
1520static int 1503static int
@@ -1522,7 +1505,7 @@ compat_find_calc_match(struct ip6t_entry_match *m,
1522 const char *name, 1505 const char *name,
1523 const struct ip6t_ip6 *ipv6, 1506 const struct ip6t_ip6 *ipv6,
1524 unsigned int hookmask, 1507 unsigned int hookmask,
1525 int *size, unsigned int *i) 1508 int *size)
1526{ 1509{
1527 struct xt_match *match; 1510 struct xt_match *match;
1528 1511
@@ -1536,47 +1519,32 @@ compat_find_calc_match(struct ip6t_entry_match *m,
1536 } 1519 }
1537 m->u.kernel.match = match; 1520 m->u.kernel.match = match;
1538 *size += xt_compat_match_offset(match); 1521 *size += xt_compat_match_offset(match);
1539
1540 (*i)++;
1541 return 0;
1542}
1543
1544static int
1545compat_release_match(struct ip6t_entry_match *m, unsigned int *i)
1546{
1547 if (i && (*i)-- == 0)
1548 return 1;
1549
1550 module_put(m->u.kernel.match->me);
1551 return 0; 1522 return 0;
1552} 1523}
1553 1524
1554static int 1525static void compat_release_entry(struct compat_ip6t_entry *e)
1555compat_release_entry(struct compat_ip6t_entry *e, unsigned int *i)
1556{ 1526{
1557 struct ip6t_entry_target *t; 1527 struct ip6t_entry_target *t;
1558 1528 struct xt_entry_match *ematch;
1559 if (i && (*i)-- == 0)
1560 return 1;
1561 1529
1562 /* Cleanup all matches */ 1530 /* Cleanup all matches */
1563 COMPAT_IP6T_MATCH_ITERATE(e, compat_release_match, NULL); 1531 xt_ematch_foreach(ematch, e)
1532 module_put(ematch->u.kernel.match->me);
1564 t = compat_ip6t_get_target(e); 1533 t = compat_ip6t_get_target(e);
1565 module_put(t->u.kernel.target->me); 1534 module_put(t->u.kernel.target->me);
1566 return 0;
1567} 1535}
1568 1536
1569static int 1537static int
1570check_compat_entry_size_and_hooks(struct compat_ip6t_entry *e, 1538check_compat_entry_size_and_hooks(struct compat_ip6t_entry *e,
1571 struct xt_table_info *newinfo, 1539 struct xt_table_info *newinfo,
1572 unsigned int *size, 1540 unsigned int *size,
1573 unsigned char *base, 1541 const unsigned char *base,
1574 unsigned char *limit, 1542 const unsigned char *limit,
1575 unsigned int *hook_entries, 1543 const unsigned int *hook_entries,
1576 unsigned int *underflows, 1544 const unsigned int *underflows,
1577 unsigned int *i,
1578 const char *name) 1545 const char *name)
1579{ 1546{
1547 struct xt_entry_match *ematch;
1580 struct ip6t_entry_target *t; 1548 struct ip6t_entry_target *t;
1581 struct xt_target *target; 1549 struct xt_target *target;
1582 unsigned int entry_offset; 1550 unsigned int entry_offset;
@@ -1584,8 +1552,8 @@ check_compat_entry_size_and_hooks(struct compat_ip6t_entry *e,
1584 int ret, off, h; 1552 int ret, off, h;
1585 1553
1586 duprintf("check_compat_entry_size_and_hooks %p\n", e); 1554 duprintf("check_compat_entry_size_and_hooks %p\n", e);
1587 if ((unsigned long)e % __alignof__(struct compat_ip6t_entry) != 0 1555 if ((unsigned long)e % __alignof__(struct compat_ip6t_entry) != 0 ||
1588 || (unsigned char *)e + sizeof(struct compat_ip6t_entry) >= limit) { 1556 (unsigned char *)e + sizeof(struct compat_ip6t_entry) >= limit) {
1589 duprintf("Bad offset %p, limit = %p\n", e, limit); 1557 duprintf("Bad offset %p, limit = %p\n", e, limit);
1590 return -EINVAL; 1558 return -EINVAL;
1591 } 1559 }
@@ -1605,10 +1573,13 @@ check_compat_entry_size_and_hooks(struct compat_ip6t_entry *e,
1605 off = sizeof(struct ip6t_entry) - sizeof(struct compat_ip6t_entry); 1573 off = sizeof(struct ip6t_entry) - sizeof(struct compat_ip6t_entry);
1606 entry_offset = (void *)e - (void *)base; 1574 entry_offset = (void *)e - (void *)base;
1607 j = 0; 1575 j = 0;
1608 ret = COMPAT_IP6T_MATCH_ITERATE(e, compat_find_calc_match, name, 1576 xt_ematch_foreach(ematch, e) {
1609 &e->ipv6, e->comefrom, &off, &j); 1577 ret = compat_find_calc_match(ematch, name,
1610 if (ret != 0) 1578 &e->ipv6, e->comefrom, &off);
1611 goto release_matches; 1579 if (ret != 0)
1580 goto release_matches;
1581 ++j;
1582 }
1612 1583
1613 t = compat_ip6t_get_target(e); 1584 t = compat_ip6t_get_target(e);
1614 target = try_then_request_module(xt_find_target(AF_INET6, 1585 target = try_then_request_module(xt_find_target(AF_INET6,
@@ -1640,14 +1611,16 @@ check_compat_entry_size_and_hooks(struct compat_ip6t_entry *e,
1640 /* Clear counters and comefrom */ 1611 /* Clear counters and comefrom */
1641 memset(&e->counters, 0, sizeof(e->counters)); 1612 memset(&e->counters, 0, sizeof(e->counters));
1642 e->comefrom = 0; 1613 e->comefrom = 0;
1643
1644 (*i)++;
1645 return 0; 1614 return 0;
1646 1615
1647out: 1616out:
1648 module_put(t->u.kernel.target->me); 1617 module_put(t->u.kernel.target->me);
1649release_matches: 1618release_matches:
1650 IP6T_MATCH_ITERATE(e, compat_release_match, &j); 1619 xt_ematch_foreach(ematch, e) {
1620 if (j-- == 0)
1621 break;
1622 module_put(ematch->u.kernel.match->me);
1623 }
1651 return ret; 1624 return ret;
1652} 1625}
1653 1626
@@ -1661,6 +1634,7 @@ compat_copy_entry_from_user(struct compat_ip6t_entry *e, void **dstptr,
1661 struct ip6t_entry *de; 1634 struct ip6t_entry *de;
1662 unsigned int origsize; 1635 unsigned int origsize;
1663 int ret, h; 1636 int ret, h;
1637 struct xt_entry_match *ematch;
1664 1638
1665 ret = 0; 1639 ret = 0;
1666 origsize = *size; 1640 origsize = *size;
@@ -1671,10 +1645,11 @@ compat_copy_entry_from_user(struct compat_ip6t_entry *e, void **dstptr,
1671 *dstptr += sizeof(struct ip6t_entry); 1645 *dstptr += sizeof(struct ip6t_entry);
1672 *size += sizeof(struct ip6t_entry) - sizeof(struct compat_ip6t_entry); 1646 *size += sizeof(struct ip6t_entry) - sizeof(struct compat_ip6t_entry);
1673 1647
1674 ret = COMPAT_IP6T_MATCH_ITERATE(e, xt_compat_match_from_user, 1648 xt_ematch_foreach(ematch, e) {
1675 dstptr, size); 1649 ret = xt_compat_match_from_user(ematch, dstptr, size);
1676 if (ret) 1650 if (ret != 0)
1677 return ret; 1651 return ret;
1652 }
1678 de->target_offset = e->target_offset - (origsize - *size); 1653 de->target_offset = e->target_offset - (origsize - *size);
1679 t = compat_ip6t_get_target(e); 1654 t = compat_ip6t_get_target(e);
1680 target = t->u.kernel.target; 1655 target = t->u.kernel.target;
@@ -1690,36 +1665,44 @@ compat_copy_entry_from_user(struct compat_ip6t_entry *e, void **dstptr,
1690 return ret; 1665 return ret;
1691} 1666}
1692 1667
1693static int compat_check_entry(struct ip6t_entry *e, const char *name, 1668static int compat_check_entry(struct ip6t_entry *e, struct net *net,
1694 unsigned int *i) 1669 const char *name)
1695{ 1670{
1696 unsigned int j; 1671 unsigned int j;
1697 int ret; 1672 int ret = 0;
1698 struct xt_mtchk_param mtpar; 1673 struct xt_mtchk_param mtpar;
1674 struct xt_entry_match *ematch;
1699 1675
1700 j = 0; 1676 j = 0;
1677 mtpar.net = net;
1701 mtpar.table = name; 1678 mtpar.table = name;
1702 mtpar.entryinfo = &e->ipv6; 1679 mtpar.entryinfo = &e->ipv6;
1703 mtpar.hook_mask = e->comefrom; 1680 mtpar.hook_mask = e->comefrom;
1704 mtpar.family = NFPROTO_IPV6; 1681 mtpar.family = NFPROTO_IPV6;
1705 ret = IP6T_MATCH_ITERATE(e, check_match, &mtpar, &j); 1682 xt_ematch_foreach(ematch, e) {
1706 if (ret) 1683 ret = check_match(ematch, &mtpar);
1707 goto cleanup_matches; 1684 if (ret != 0)
1685 goto cleanup_matches;
1686 ++j;
1687 }
1708 1688
1709 ret = check_target(e, name); 1689 ret = check_target(e, net, name);
1710 if (ret) 1690 if (ret)
1711 goto cleanup_matches; 1691 goto cleanup_matches;
1712
1713 (*i)++;
1714 return 0; 1692 return 0;
1715 1693
1716 cleanup_matches: 1694 cleanup_matches:
1717 IP6T_MATCH_ITERATE(e, cleanup_match, &j); 1695 xt_ematch_foreach(ematch, e) {
1696 if (j-- == 0)
1697 break;
1698 cleanup_match(ematch, net);
1699 }
1718 return ret; 1700 return ret;
1719} 1701}
1720 1702
1721static int 1703static int
1722translate_compat_table(const char *name, 1704translate_compat_table(struct net *net,
1705 const char *name,
1723 unsigned int valid_hooks, 1706 unsigned int valid_hooks,
1724 struct xt_table_info **pinfo, 1707 struct xt_table_info **pinfo,
1725 void **pentry0, 1708 void **pentry0,
@@ -1731,8 +1714,10 @@ translate_compat_table(const char *name,
1731 unsigned int i, j; 1714 unsigned int i, j;
1732 struct xt_table_info *newinfo, *info; 1715 struct xt_table_info *newinfo, *info;
1733 void *pos, *entry0, *entry1; 1716 void *pos, *entry0, *entry1;
1717 struct compat_ip6t_entry *iter0;
1718 struct ip6t_entry *iter1;
1734 unsigned int size; 1719 unsigned int size;
1735 int ret; 1720 int ret = 0;
1736 1721
1737 info = *pinfo; 1722 info = *pinfo;
1738 entry0 = *pentry0; 1723 entry0 = *pentry0;
@@ -1749,13 +1734,17 @@ translate_compat_table(const char *name,
1749 j = 0; 1734 j = 0;
1750 xt_compat_lock(AF_INET6); 1735 xt_compat_lock(AF_INET6);
1751 /* Walk through entries, checking offsets. */ 1736 /* Walk through entries, checking offsets. */
1752 ret = COMPAT_IP6T_ENTRY_ITERATE(entry0, total_size, 1737 xt_entry_foreach(iter0, entry0, total_size) {
1753 check_compat_entry_size_and_hooks, 1738 ret = check_compat_entry_size_and_hooks(iter0, info, &size,
1754 info, &size, entry0, 1739 entry0,
1755 entry0 + total_size, 1740 entry0 + total_size,
1756 hook_entries, underflows, &j, name); 1741 hook_entries,
1757 if (ret != 0) 1742 underflows,
1758 goto out_unlock; 1743 name);
1744 if (ret != 0)
1745 goto out_unlock;
1746 ++j;
1747 }
1759 1748
1760 ret = -EINVAL; 1749 ret = -EINVAL;
1761 if (j != number) { 1750 if (j != number) {
@@ -1794,9 +1783,12 @@ translate_compat_table(const char *name,
1794 entry1 = newinfo->entries[raw_smp_processor_id()]; 1783 entry1 = newinfo->entries[raw_smp_processor_id()];
1795 pos = entry1; 1784 pos = entry1;
1796 size = total_size; 1785 size = total_size;
1797 ret = COMPAT_IP6T_ENTRY_ITERATE(entry0, total_size, 1786 xt_entry_foreach(iter0, entry0, total_size) {
1798 compat_copy_entry_from_user, 1787 ret = compat_copy_entry_from_user(iter0, &pos, &size,
1799 &pos, &size, name, newinfo, entry1); 1788 name, newinfo, entry1);
1789 if (ret != 0)
1790 break;
1791 }
1800 xt_compat_flush_offsets(AF_INET6); 1792 xt_compat_flush_offsets(AF_INET6);
1801 xt_compat_unlock(AF_INET6); 1793 xt_compat_unlock(AF_INET6);
1802 if (ret) 1794 if (ret)
@@ -1807,13 +1799,32 @@ translate_compat_table(const char *name,
1807 goto free_newinfo; 1799 goto free_newinfo;
1808 1800
1809 i = 0; 1801 i = 0;
1810 ret = IP6T_ENTRY_ITERATE(entry1, newinfo->size, compat_check_entry, 1802 xt_entry_foreach(iter1, entry1, newinfo->size) {
1811 name, &i); 1803 ret = compat_check_entry(iter1, net, name);
1804 if (ret != 0)
1805 break;
1806 ++i;
1807 }
1812 if (ret) { 1808 if (ret) {
1809 /*
1810 * The first i matches need cleanup_entry (calls ->destroy)
1811 * because they had called ->check already. The other j-i
1812 * entries need only release.
1813 */
1814 int skip = i;
1813 j -= i; 1815 j -= i;
1814 COMPAT_IP6T_ENTRY_ITERATE_CONTINUE(entry0, newinfo->size, i, 1816 xt_entry_foreach(iter0, entry0, newinfo->size) {
1815 compat_release_entry, &j); 1817 if (skip-- > 0)
1816 IP6T_ENTRY_ITERATE(entry1, newinfo->size, cleanup_entry, &i); 1818 continue;
1819 if (j-- == 0)
1820 break;
1821 compat_release_entry(iter0);
1822 }
1823 xt_entry_foreach(iter1, entry1, newinfo->size) {
1824 if (i-- == 0)
1825 break;
1826 cleanup_entry(iter1, net);
1827 }
1817 xt_free_table_info(newinfo); 1828 xt_free_table_info(newinfo);
1818 return ret; 1829 return ret;
1819 } 1830 }
@@ -1831,7 +1842,11 @@ translate_compat_table(const char *name,
1831free_newinfo: 1842free_newinfo:
1832 xt_free_table_info(newinfo); 1843 xt_free_table_info(newinfo);
1833out: 1844out:
1834 COMPAT_IP6T_ENTRY_ITERATE(entry0, total_size, compat_release_entry, &j); 1845 xt_entry_foreach(iter0, entry0, total_size) {
1846 if (j-- == 0)
1847 break;
1848 compat_release_entry(iter0);
1849 }
1835 return ret; 1850 return ret;
1836out_unlock: 1851out_unlock:
1837 xt_compat_flush_offsets(AF_INET6); 1852 xt_compat_flush_offsets(AF_INET6);
@@ -1846,6 +1861,7 @@ compat_do_replace(struct net *net, void __user *user, unsigned int len)
1846 struct compat_ip6t_replace tmp; 1861 struct compat_ip6t_replace tmp;
1847 struct xt_table_info *newinfo; 1862 struct xt_table_info *newinfo;
1848 void *loc_cpu_entry; 1863 void *loc_cpu_entry;
1864 struct ip6t_entry *iter;
1849 1865
1850 if (copy_from_user(&tmp, user, sizeof(tmp)) != 0) 1866 if (copy_from_user(&tmp, user, sizeof(tmp)) != 0)
1851 return -EFAULT; 1867 return -EFAULT;
@@ -1868,7 +1884,7 @@ compat_do_replace(struct net *net, void __user *user, unsigned int len)
1868 goto free_newinfo; 1884 goto free_newinfo;
1869 } 1885 }
1870 1886
1871 ret = translate_compat_table(tmp.name, tmp.valid_hooks, 1887 ret = translate_compat_table(net, tmp.name, tmp.valid_hooks,
1872 &newinfo, &loc_cpu_entry, tmp.size, 1888 &newinfo, &loc_cpu_entry, tmp.size,
1873 tmp.num_entries, tmp.hook_entry, 1889 tmp.num_entries, tmp.hook_entry,
1874 tmp.underflow); 1890 tmp.underflow);
@@ -1884,7 +1900,8 @@ compat_do_replace(struct net *net, void __user *user, unsigned int len)
1884 return 0; 1900 return 0;
1885 1901
1886 free_newinfo_untrans: 1902 free_newinfo_untrans:
1887 IP6T_ENTRY_ITERATE(loc_cpu_entry, newinfo->size, cleanup_entry, NULL); 1903 xt_entry_foreach(iter, loc_cpu_entry, newinfo->size)
1904 cleanup_entry(iter, net);
1888 free_newinfo: 1905 free_newinfo:
1889 xt_free_table_info(newinfo); 1906 xt_free_table_info(newinfo);
1890 return ret; 1907 return ret;
@@ -1933,6 +1950,7 @@ compat_copy_entries_to_user(unsigned int total_size, struct xt_table *table,
1933 int ret = 0; 1950 int ret = 0;
1934 const void *loc_cpu_entry; 1951 const void *loc_cpu_entry;
1935 unsigned int i = 0; 1952 unsigned int i = 0;
1953 struct ip6t_entry *iter;
1936 1954
1937 counters = alloc_counters(table); 1955 counters = alloc_counters(table);
1938 if (IS_ERR(counters)) 1956 if (IS_ERR(counters))
@@ -1945,9 +1963,12 @@ compat_copy_entries_to_user(unsigned int total_size, struct xt_table *table,
1945 loc_cpu_entry = private->entries[raw_smp_processor_id()]; 1963 loc_cpu_entry = private->entries[raw_smp_processor_id()];
1946 pos = userptr; 1964 pos = userptr;
1947 size = total_size; 1965 size = total_size;
1948 ret = IP6T_ENTRY_ITERATE(loc_cpu_entry, total_size, 1966 xt_entry_foreach(iter, loc_cpu_entry, total_size) {
1949 compat_copy_entry_to_user, 1967 ret = compat_copy_entry_to_user(iter, &pos,
1950 &pos, &size, counters, &i); 1968 &size, counters, i++);
1969 if (ret != 0)
1970 break;
1971 }
1951 1972
1952 vfree(counters); 1973 vfree(counters);
1953 return ret; 1974 return ret;
@@ -2121,11 +2142,7 @@ struct xt_table *ip6t_register_table(struct net *net,
2121 loc_cpu_entry = newinfo->entries[raw_smp_processor_id()]; 2142 loc_cpu_entry = newinfo->entries[raw_smp_processor_id()];
2122 memcpy(loc_cpu_entry, repl->entries, repl->size); 2143 memcpy(loc_cpu_entry, repl->entries, repl->size);
2123 2144
2124 ret = translate_table(table->name, table->valid_hooks, 2145 ret = translate_table(net, newinfo, loc_cpu_entry, repl);
2125 newinfo, loc_cpu_entry, repl->size,
2126 repl->num_entries,
2127 repl->hook_entry,
2128 repl->underflow);
2129 if (ret != 0) 2146 if (ret != 0)
2130 goto out_free; 2147 goto out_free;
2131 2148
@@ -2142,17 +2159,19 @@ out:
2142 return ERR_PTR(ret); 2159 return ERR_PTR(ret);
2143} 2160}
2144 2161
2145void ip6t_unregister_table(struct xt_table *table) 2162void ip6t_unregister_table(struct net *net, struct xt_table *table)
2146{ 2163{
2147 struct xt_table_info *private; 2164 struct xt_table_info *private;
2148 void *loc_cpu_entry; 2165 void *loc_cpu_entry;
2149 struct module *table_owner = table->me; 2166 struct module *table_owner = table->me;
2167 struct ip6t_entry *iter;
2150 2168
2151 private = xt_unregister_table(table); 2169 private = xt_unregister_table(table);
2152 2170
2153 /* Decrease module usage counts and free resources */ 2171 /* Decrease module usage counts and free resources */
2154 loc_cpu_entry = private->entries[raw_smp_processor_id()]; 2172 loc_cpu_entry = private->entries[raw_smp_processor_id()];
2155 IP6T_ENTRY_ITERATE(loc_cpu_entry, private->size, cleanup_entry, NULL); 2173 xt_entry_foreach(iter, loc_cpu_entry, private->size)
2174 cleanup_entry(iter, net);
2156 if (private->number > private->initial_entries) 2175 if (private->number > private->initial_entries)
2157 module_put(table_owner); 2176 module_put(table_owner);
2158 xt_free_table_info(private); 2177 xt_free_table_info(private);
diff --git a/net/ipv6/netfilter/ip6t_LOG.c b/net/ipv6/netfilter/ip6t_LOG.c
index 7018cac4fddc..b285fdf19050 100644
--- a/net/ipv6/netfilter/ip6t_LOG.c
+++ b/net/ipv6/netfilter/ip6t_LOG.c
@@ -249,8 +249,8 @@ static void dump_packet(const struct nf_loginfo *info,
249 /* Max length: 11 "URGP=65535 " */ 249 /* Max length: 11 "URGP=65535 " */
250 printk("URGP=%u ", ntohs(th->urg_ptr)); 250 printk("URGP=%u ", ntohs(th->urg_ptr));
251 251
252 if ((logflags & IP6T_LOG_TCPOPT) 252 if ((logflags & IP6T_LOG_TCPOPT) &&
253 && th->doff * 4 > sizeof(struct tcphdr)) { 253 th->doff * 4 > sizeof(struct tcphdr)) {
254 u_int8_t _opt[60 - sizeof(struct tcphdr)]; 254 u_int8_t _opt[60 - sizeof(struct tcphdr)];
255 const u_int8_t *op; 255 const u_int8_t *op;
256 unsigned int i; 256 unsigned int i;
diff --git a/net/ipv6/netfilter/ip6t_REJECT.c b/net/ipv6/netfilter/ip6t_REJECT.c
index 5a7f00cd15ce..39b50c3768e8 100644
--- a/net/ipv6/netfilter/ip6t_REJECT.c
+++ b/net/ipv6/netfilter/ip6t_REJECT.c
@@ -15,6 +15,7 @@
15 * 2 of the License, or (at your option) any later version. 15 * 2 of the License, or (at your option) any later version.
16 */ 16 */
17 17
18#include <linux/gfp.h>
18#include <linux/module.h> 19#include <linux/module.h>
19#include <linux/skbuff.h> 20#include <linux/skbuff.h>
20#include <linux/icmpv6.h> 21#include <linux/icmpv6.h>
@@ -169,7 +170,7 @@ send_unreach(struct net *net, struct sk_buff *skb_in, unsigned char code,
169 if (hooknum == NF_INET_LOCAL_OUT && skb_in->dev == NULL) 170 if (hooknum == NF_INET_LOCAL_OUT && skb_in->dev == NULL)
170 skb_in->dev = net->loopback_dev; 171 skb_in->dev = net->loopback_dev;
171 172
172 icmpv6_send(skb_in, ICMPV6_DEST_UNREACH, code, 0, NULL); 173 icmpv6_send(skb_in, ICMPV6_DEST_UNREACH, code, 0);
173} 174}
174 175
175static unsigned int 176static unsigned int
@@ -223,8 +224,8 @@ static bool reject_tg6_check(const struct xt_tgchk_param *par)
223 return false; 224 return false;
224 } else if (rejinfo->with == IP6T_TCP_RESET) { 225 } else if (rejinfo->with == IP6T_TCP_RESET) {
225 /* Must specify that it's a TCP packet */ 226 /* Must specify that it's a TCP packet */
226 if (e->ipv6.proto != IPPROTO_TCP 227 if (e->ipv6.proto != IPPROTO_TCP ||
227 || (e->ipv6.invflags & XT_INV_PROTO)) { 228 (e->ipv6.invflags & XT_INV_PROTO)) {
228 printk("ip6t_REJECT: TCP_RESET illegal for non-tcp\n"); 229 printk("ip6t_REJECT: TCP_RESET illegal for non-tcp\n");
229 return false; 230 return false;
230 } 231 }
diff --git a/net/ipv6/netfilter/ip6t_ah.c b/net/ipv6/netfilter/ip6t_ah.c
index 3a82f24746b9..ac0b7c629d78 100644
--- a/net/ipv6/netfilter/ip6t_ah.c
+++ b/net/ipv6/netfilter/ip6t_ah.c
@@ -77,17 +77,14 @@ static bool ah_mt6(const struct sk_buff *skb, const struct xt_match_param *par)
77 ahinfo->hdrres, ah->reserved, 77 ahinfo->hdrres, ah->reserved,
78 !(ahinfo->hdrres && ah->reserved)); 78 !(ahinfo->hdrres && ah->reserved));
79 79
80 return (ah != NULL) 80 return (ah != NULL) &&
81 && 81 spi_match(ahinfo->spis[0], ahinfo->spis[1],
82 spi_match(ahinfo->spis[0], ahinfo->spis[1], 82 ntohl(ah->spi),
83 ntohl(ah->spi), 83 !!(ahinfo->invflags & IP6T_AH_INV_SPI)) &&
84 !!(ahinfo->invflags & IP6T_AH_INV_SPI)) 84 (!ahinfo->hdrlen ||
85 && 85 (ahinfo->hdrlen == hdrlen) ^
86 (!ahinfo->hdrlen || 86 !!(ahinfo->invflags & IP6T_AH_INV_LEN)) &&
87 (ahinfo->hdrlen == hdrlen) ^ 87 !(ahinfo->hdrres && ah->reserved);
88 !!(ahinfo->invflags & IP6T_AH_INV_LEN))
89 &&
90 !(ahinfo->hdrres && ah->reserved);
91} 88}
92 89
93static bool ah_mt6_check(const struct xt_mtchk_param *par) 90static bool ah_mt6_check(const struct xt_mtchk_param *par)
diff --git a/net/ipv6/netfilter/ip6t_frag.c b/net/ipv6/netfilter/ip6t_frag.c
index 673aa0a5084e..7b91c2598ed5 100644
--- a/net/ipv6/netfilter/ip6t_frag.c
+++ b/net/ipv6/netfilter/ip6t_frag.c
@@ -70,41 +70,36 @@ frag_mt6(const struct sk_buff *skb, const struct xt_match_param *par)
70 pr_debug("res %02X %02X%04X %02X ", 70 pr_debug("res %02X %02X%04X %02X ",
71 fraginfo->flags & IP6T_FRAG_RES, fh->reserved, 71 fraginfo->flags & IP6T_FRAG_RES, fh->reserved,
72 ntohs(fh->frag_off) & 0x6, 72 ntohs(fh->frag_off) & 0x6,
73 !((fraginfo->flags & IP6T_FRAG_RES) 73 !((fraginfo->flags & IP6T_FRAG_RES) &&
74 && (fh->reserved || (ntohs(fh->frag_off) & 0x06)))); 74 (fh->reserved || (ntohs(fh->frag_off) & 0x06))));
75 pr_debug("first %02X %02X %02X ", 75 pr_debug("first %02X %02X %02X ",
76 fraginfo->flags & IP6T_FRAG_FST, 76 fraginfo->flags & IP6T_FRAG_FST,
77 ntohs(fh->frag_off) & ~0x7, 77 ntohs(fh->frag_off) & ~0x7,
78 !((fraginfo->flags & IP6T_FRAG_FST) 78 !((fraginfo->flags & IP6T_FRAG_FST) &&
79 && (ntohs(fh->frag_off) & ~0x7))); 79 (ntohs(fh->frag_off) & ~0x7)));
80 pr_debug("mf %02X %02X %02X ", 80 pr_debug("mf %02X %02X %02X ",
81 fraginfo->flags & IP6T_FRAG_MF, 81 fraginfo->flags & IP6T_FRAG_MF,
82 ntohs(fh->frag_off) & IP6_MF, 82 ntohs(fh->frag_off) & IP6_MF,
83 !((fraginfo->flags & IP6T_FRAG_MF) 83 !((fraginfo->flags & IP6T_FRAG_MF) &&
84 && !((ntohs(fh->frag_off) & IP6_MF)))); 84 !((ntohs(fh->frag_off) & IP6_MF))));
85 pr_debug("last %02X %02X %02X\n", 85 pr_debug("last %02X %02X %02X\n",
86 fraginfo->flags & IP6T_FRAG_NMF, 86 fraginfo->flags & IP6T_FRAG_NMF,
87 ntohs(fh->frag_off) & IP6_MF, 87 ntohs(fh->frag_off) & IP6_MF,
88 !((fraginfo->flags & IP6T_FRAG_NMF) 88 !((fraginfo->flags & IP6T_FRAG_NMF) &&
89 && (ntohs(fh->frag_off) & IP6_MF))); 89 (ntohs(fh->frag_off) & IP6_MF)));
90 90
91 return (fh != NULL) 91 return (fh != NULL) &&
92 && 92 id_match(fraginfo->ids[0], fraginfo->ids[1],
93 id_match(fraginfo->ids[0], fraginfo->ids[1], 93 ntohl(fh->identification),
94 ntohl(fh->identification), 94 !!(fraginfo->invflags & IP6T_FRAG_INV_IDS)) &&
95 !!(fraginfo->invflags & IP6T_FRAG_INV_IDS)) 95 !((fraginfo->flags & IP6T_FRAG_RES) &&
96 && 96 (fh->reserved || (ntohs(fh->frag_off) & 0x6))) &&
97 !((fraginfo->flags & IP6T_FRAG_RES) 97 !((fraginfo->flags & IP6T_FRAG_FST) &&
98 && (fh->reserved || (ntohs(fh->frag_off) & 0x6))) 98 (ntohs(fh->frag_off) & ~0x7)) &&
99 && 99 !((fraginfo->flags & IP6T_FRAG_MF) &&
100 !((fraginfo->flags & IP6T_FRAG_FST) 100 !(ntohs(fh->frag_off) & IP6_MF)) &&
101 && (ntohs(fh->frag_off) & ~0x7)) 101 !((fraginfo->flags & IP6T_FRAG_NMF) &&
102 && 102 (ntohs(fh->frag_off) & IP6_MF));
103 !((fraginfo->flags & IP6T_FRAG_MF)
104 && !(ntohs(fh->frag_off) & IP6_MF))
105 &&
106 !((fraginfo->flags & IP6T_FRAG_NMF)
107 && (ntohs(fh->frag_off) & IP6_MF));
108} 103}
109 104
110static bool frag_mt6_check(const struct xt_mtchk_param *par) 105static bool frag_mt6_check(const struct xt_mtchk_param *par)
diff --git a/net/ipv6/netfilter/ip6t_rt.c b/net/ipv6/netfilter/ip6t_rt.c
index 356b8d6f6baa..b77307fc8743 100644
--- a/net/ipv6/netfilter/ip6t_rt.c
+++ b/net/ipv6/netfilter/ip6t_rt.c
@@ -92,16 +92,13 @@ static bool rt_mt6(const struct sk_buff *skb, const struct xt_match_param *par)
92 !((rtinfo->flags & IP6T_RT_RES) && 92 !((rtinfo->flags & IP6T_RT_RES) &&
93 (((const struct rt0_hdr *)rh)->reserved))); 93 (((const struct rt0_hdr *)rh)->reserved)));
94 94
95 ret = (rh != NULL) 95 ret = (rh != NULL) &&
96 &&
97 (segsleft_match(rtinfo->segsleft[0], rtinfo->segsleft[1], 96 (segsleft_match(rtinfo->segsleft[0], rtinfo->segsleft[1],
98 rh->segments_left, 97 rh->segments_left,
99 !!(rtinfo->invflags & IP6T_RT_INV_SGS))) 98 !!(rtinfo->invflags & IP6T_RT_INV_SGS))) &&
100 &&
101 (!(rtinfo->flags & IP6T_RT_LEN) || 99 (!(rtinfo->flags & IP6T_RT_LEN) ||
102 ((rtinfo->hdrlen == hdrlen) ^ 100 ((rtinfo->hdrlen == hdrlen) ^
103 !!(rtinfo->invflags & IP6T_RT_INV_LEN))) 101 !!(rtinfo->invflags & IP6T_RT_INV_LEN))) &&
104 &&
105 (!(rtinfo->flags & IP6T_RT_TYP) || 102 (!(rtinfo->flags & IP6T_RT_TYP) ||
106 ((rtinfo->rt_type == rh->type) ^ 103 ((rtinfo->rt_type == rh->type) ^
107 !!(rtinfo->invflags & IP6T_RT_INV_TYP))); 104 !!(rtinfo->invflags & IP6T_RT_INV_TYP)));
diff --git a/net/ipv6/netfilter/ip6table_filter.c b/net/ipv6/netfilter/ip6table_filter.c
index 6f4383ad86f9..d6fc9aff3163 100644
--- a/net/ipv6/netfilter/ip6table_filter.c
+++ b/net/ipv6/netfilter/ip6table_filter.c
@@ -12,6 +12,7 @@
12#include <linux/module.h> 12#include <linux/module.h>
13#include <linux/moduleparam.h> 13#include <linux/moduleparam.h>
14#include <linux/netfilter_ipv6/ip6_tables.h> 14#include <linux/netfilter_ipv6/ip6_tables.h>
15#include <linux/slab.h>
15 16
16MODULE_LICENSE("GPL"); 17MODULE_LICENSE("GPL");
17MODULE_AUTHOR("Netfilter Core Team <coreteam@netfilter.org>"); 18MODULE_AUTHOR("Netfilter Core Team <coreteam@netfilter.org>");
@@ -21,99 +22,26 @@ MODULE_DESCRIPTION("ip6tables filter table");
21 (1 << NF_INET_FORWARD) | \ 22 (1 << NF_INET_FORWARD) | \
22 (1 << NF_INET_LOCAL_OUT)) 23 (1 << NF_INET_LOCAL_OUT))
23 24
24static struct
25{
26 struct ip6t_replace repl;
27 struct ip6t_standard entries[3];
28 struct ip6t_error term;
29} initial_table __net_initdata = {
30 .repl = {
31 .name = "filter",
32 .valid_hooks = FILTER_VALID_HOOKS,
33 .num_entries = 4,
34 .size = sizeof(struct ip6t_standard) * 3 + sizeof(struct ip6t_error),
35 .hook_entry = {
36 [NF_INET_LOCAL_IN] = 0,
37 [NF_INET_FORWARD] = sizeof(struct ip6t_standard),
38 [NF_INET_LOCAL_OUT] = sizeof(struct ip6t_standard) * 2
39 },
40 .underflow = {
41 [NF_INET_LOCAL_IN] = 0,
42 [NF_INET_FORWARD] = sizeof(struct ip6t_standard),
43 [NF_INET_LOCAL_OUT] = sizeof(struct ip6t_standard) * 2
44 },
45 },
46 .entries = {
47 IP6T_STANDARD_INIT(NF_ACCEPT), /* LOCAL_IN */
48 IP6T_STANDARD_INIT(NF_ACCEPT), /* FORWARD */
49 IP6T_STANDARD_INIT(NF_ACCEPT), /* LOCAL_OUT */
50 },
51 .term = IP6T_ERROR_INIT, /* ERROR */
52};
53
54static const struct xt_table packet_filter = { 25static const struct xt_table packet_filter = {
55 .name = "filter", 26 .name = "filter",
56 .valid_hooks = FILTER_VALID_HOOKS, 27 .valid_hooks = FILTER_VALID_HOOKS,
57 .me = THIS_MODULE, 28 .me = THIS_MODULE,
58 .af = NFPROTO_IPV6, 29 .af = NFPROTO_IPV6,
30 .priority = NF_IP6_PRI_FILTER,
59}; 31};
60 32
61/* The work comes in here from netfilter.c. */ 33/* The work comes in here from netfilter.c. */
62static unsigned int 34static unsigned int
63ip6t_in_hook(unsigned int hook, 35ip6table_filter_hook(unsigned int hook, struct sk_buff *skb,
64 struct sk_buff *skb, 36 const struct net_device *in, const struct net_device *out,
65 const struct net_device *in, 37 int (*okfn)(struct sk_buff *))
66 const struct net_device *out,
67 int (*okfn)(struct sk_buff *))
68{
69 return ip6t_do_table(skb, hook, in, out,
70 dev_net(in)->ipv6.ip6table_filter);
71}
72
73static unsigned int
74ip6t_local_out_hook(unsigned int hook,
75 struct sk_buff *skb,
76 const struct net_device *in,
77 const struct net_device *out,
78 int (*okfn)(struct sk_buff *))
79{ 38{
80#if 0 39 const struct net *net = dev_net((in != NULL) ? in : out);
81 /* root is playing with raw sockets. */
82 if (skb->len < sizeof(struct iphdr)
83 || ip_hdrlen(skb) < sizeof(struct iphdr)) {
84 if (net_ratelimit())
85 printk("ip6t_hook: happy cracking.\n");
86 return NF_ACCEPT;
87 }
88#endif
89 40
90 return ip6t_do_table(skb, hook, in, out, 41 return ip6t_do_table(skb, hook, in, out, net->ipv6.ip6table_filter);
91 dev_net(out)->ipv6.ip6table_filter);
92} 42}
93 43
94static struct nf_hook_ops ip6t_ops[] __read_mostly = { 44static struct nf_hook_ops *filter_ops __read_mostly;
95 {
96 .hook = ip6t_in_hook,
97 .owner = THIS_MODULE,
98 .pf = NFPROTO_IPV6,
99 .hooknum = NF_INET_LOCAL_IN,
100 .priority = NF_IP6_PRI_FILTER,
101 },
102 {
103 .hook = ip6t_in_hook,
104 .owner = THIS_MODULE,
105 .pf = NFPROTO_IPV6,
106 .hooknum = NF_INET_FORWARD,
107 .priority = NF_IP6_PRI_FILTER,
108 },
109 {
110 .hook = ip6t_local_out_hook,
111 .owner = THIS_MODULE,
112 .pf = NFPROTO_IPV6,
113 .hooknum = NF_INET_LOCAL_OUT,
114 .priority = NF_IP6_PRI_FILTER,
115 },
116};
117 45
118/* Default to forward because I got too much mail already. */ 46/* Default to forward because I got too much mail already. */
119static int forward = NF_ACCEPT; 47static int forward = NF_ACCEPT;
@@ -121,9 +49,18 @@ module_param(forward, bool, 0000);
121 49
122static int __net_init ip6table_filter_net_init(struct net *net) 50static int __net_init ip6table_filter_net_init(struct net *net)
123{ 51{
124 /* Register table */ 52 struct ip6t_replace *repl;
53
54 repl = ip6t_alloc_initial_table(&packet_filter);
55 if (repl == NULL)
56 return -ENOMEM;
57 /* Entry 1 is the FORWARD hook */
58 ((struct ip6t_standard *)repl->entries)[1].target.verdict =
59 -forward - 1;
60
125 net->ipv6.ip6table_filter = 61 net->ipv6.ip6table_filter =
126 ip6t_register_table(net, &packet_filter, &initial_table.repl); 62 ip6t_register_table(net, &packet_filter, repl);
63 kfree(repl);
127 if (IS_ERR(net->ipv6.ip6table_filter)) 64 if (IS_ERR(net->ipv6.ip6table_filter))
128 return PTR_ERR(net->ipv6.ip6table_filter); 65 return PTR_ERR(net->ipv6.ip6table_filter);
129 return 0; 66 return 0;
@@ -131,7 +68,7 @@ static int __net_init ip6table_filter_net_init(struct net *net)
131 68
132static void __net_exit ip6table_filter_net_exit(struct net *net) 69static void __net_exit ip6table_filter_net_exit(struct net *net)
133{ 70{
134 ip6t_unregister_table(net->ipv6.ip6table_filter); 71 ip6t_unregister_table(net, net->ipv6.ip6table_filter);
135} 72}
136 73
137static struct pernet_operations ip6table_filter_net_ops = { 74static struct pernet_operations ip6table_filter_net_ops = {
@@ -148,17 +85,16 @@ static int __init ip6table_filter_init(void)
148 return -EINVAL; 85 return -EINVAL;
149 } 86 }
150 87
151 /* Entry 1 is the FORWARD hook */
152 initial_table.entries[1].target.verdict = -forward - 1;
153
154 ret = register_pernet_subsys(&ip6table_filter_net_ops); 88 ret = register_pernet_subsys(&ip6table_filter_net_ops);
155 if (ret < 0) 89 if (ret < 0)
156 return ret; 90 return ret;
157 91
158 /* Register hooks */ 92 /* Register hooks */
159 ret = nf_register_hooks(ip6t_ops, ARRAY_SIZE(ip6t_ops)); 93 filter_ops = xt_hook_link(&packet_filter, ip6table_filter_hook);
160 if (ret < 0) 94 if (IS_ERR(filter_ops)) {
95 ret = PTR_ERR(filter_ops);
161 goto cleanup_table; 96 goto cleanup_table;
97 }
162 98
163 return ret; 99 return ret;
164 100
@@ -169,7 +105,7 @@ static int __init ip6table_filter_init(void)
169 105
170static void __exit ip6table_filter_fini(void) 106static void __exit ip6table_filter_fini(void)
171{ 107{
172 nf_unregister_hooks(ip6t_ops, ARRAY_SIZE(ip6t_ops)); 108 xt_hook_unlink(&packet_filter, filter_ops);
173 unregister_pernet_subsys(&ip6table_filter_net_ops); 109 unregister_pernet_subsys(&ip6table_filter_net_ops);
174} 110}
175 111
diff --git a/net/ipv6/netfilter/ip6table_mangle.c b/net/ipv6/netfilter/ip6table_mangle.c
index 0ad91433ed61..6a102b57f356 100644
--- a/net/ipv6/netfilter/ip6table_mangle.c
+++ b/net/ipv6/netfilter/ip6table_mangle.c
@@ -10,6 +10,7 @@
10 */ 10 */
11#include <linux/module.h> 11#include <linux/module.h>
12#include <linux/netfilter_ipv6/ip6_tables.h> 12#include <linux/netfilter_ipv6/ip6_tables.h>
13#include <linux/slab.h>
13 14
14MODULE_LICENSE("GPL"); 15MODULE_LICENSE("GPL");
15MODULE_AUTHOR("Netfilter Core Team <coreteam@netfilter.org>"); 16MODULE_AUTHOR("Netfilter Core Team <coreteam@netfilter.org>");
@@ -21,80 +22,17 @@ MODULE_DESCRIPTION("ip6tables mangle table");
21 (1 << NF_INET_LOCAL_OUT) | \ 22 (1 << NF_INET_LOCAL_OUT) | \
22 (1 << NF_INET_POST_ROUTING)) 23 (1 << NF_INET_POST_ROUTING))
23 24
24static const struct
25{
26 struct ip6t_replace repl;
27 struct ip6t_standard entries[5];
28 struct ip6t_error term;
29} initial_table __net_initdata = {
30 .repl = {
31 .name = "mangle",
32 .valid_hooks = MANGLE_VALID_HOOKS,
33 .num_entries = 6,
34 .size = sizeof(struct ip6t_standard) * 5 + sizeof(struct ip6t_error),
35 .hook_entry = {
36 [NF_INET_PRE_ROUTING] = 0,
37 [NF_INET_LOCAL_IN] = sizeof(struct ip6t_standard),
38 [NF_INET_FORWARD] = sizeof(struct ip6t_standard) * 2,
39 [NF_INET_LOCAL_OUT] = sizeof(struct ip6t_standard) * 3,
40 [NF_INET_POST_ROUTING] = sizeof(struct ip6t_standard) * 4,
41 },
42 .underflow = {
43 [NF_INET_PRE_ROUTING] = 0,
44 [NF_INET_LOCAL_IN] = sizeof(struct ip6t_standard),
45 [NF_INET_FORWARD] = sizeof(struct ip6t_standard) * 2,
46 [NF_INET_LOCAL_OUT] = sizeof(struct ip6t_standard) * 3,
47 [NF_INET_POST_ROUTING] = sizeof(struct ip6t_standard) * 4,
48 },
49 },
50 .entries = {
51 IP6T_STANDARD_INIT(NF_ACCEPT), /* PRE_ROUTING */
52 IP6T_STANDARD_INIT(NF_ACCEPT), /* LOCAL_IN */
53 IP6T_STANDARD_INIT(NF_ACCEPT), /* FORWARD */
54 IP6T_STANDARD_INIT(NF_ACCEPT), /* LOCAL_OUT */
55 IP6T_STANDARD_INIT(NF_ACCEPT), /* POST_ROUTING */
56 },
57 .term = IP6T_ERROR_INIT, /* ERROR */
58};
59
60static const struct xt_table packet_mangler = { 25static const struct xt_table packet_mangler = {
61 .name = "mangle", 26 .name = "mangle",
62 .valid_hooks = MANGLE_VALID_HOOKS, 27 .valid_hooks = MANGLE_VALID_HOOKS,
63 .me = THIS_MODULE, 28 .me = THIS_MODULE,
64 .af = NFPROTO_IPV6, 29 .af = NFPROTO_IPV6,
30 .priority = NF_IP6_PRI_MANGLE,
65}; 31};
66 32
67/* The work comes in here from netfilter.c. */
68static unsigned int
69ip6t_in_hook(unsigned int hook,
70 struct sk_buff *skb,
71 const struct net_device *in,
72 const struct net_device *out,
73 int (*okfn)(struct sk_buff *))
74{
75 return ip6t_do_table(skb, hook, in, out,
76 dev_net(in)->ipv6.ip6table_mangle);
77}
78
79static unsigned int
80ip6t_post_routing_hook(unsigned int hook,
81 struct sk_buff *skb,
82 const struct net_device *in,
83 const struct net_device *out,
84 int (*okfn)(struct sk_buff *))
85{
86 return ip6t_do_table(skb, hook, in, out,
87 dev_net(out)->ipv6.ip6table_mangle);
88}
89
90static unsigned int 33static unsigned int
91ip6t_local_out_hook(unsigned int hook, 34ip6t_mangle_out(struct sk_buff *skb, const struct net_device *out)
92 struct sk_buff *skb,
93 const struct net_device *in,
94 const struct net_device *out,
95 int (*okfn)(struct sk_buff *))
96{ 35{
97
98 unsigned int ret; 36 unsigned int ret;
99 struct in6_addr saddr, daddr; 37 struct in6_addr saddr, daddr;
100 u_int8_t hop_limit; 38 u_int8_t hop_limit;
@@ -102,8 +40,8 @@ ip6t_local_out_hook(unsigned int hook,
102 40
103#if 0 41#if 0
104 /* root is playing with raw sockets. */ 42 /* root is playing with raw sockets. */
105 if (skb->len < sizeof(struct iphdr) 43 if (skb->len < sizeof(struct iphdr) ||
106 || ip_hdrlen(skb) < sizeof(struct iphdr)) { 44 ip_hdrlen(skb) < sizeof(struct iphdr)) {
107 if (net_ratelimit()) 45 if (net_ratelimit())
108 printk("ip6t_hook: happy cracking.\n"); 46 printk("ip6t_hook: happy cracking.\n");
109 return NF_ACCEPT; 47 return NF_ACCEPT;
@@ -119,62 +57,46 @@ ip6t_local_out_hook(unsigned int hook,
119 /* flowlabel and prio (includes version, which shouldn't change either */ 57 /* flowlabel and prio (includes version, which shouldn't change either */
120 flowlabel = *((u_int32_t *)ipv6_hdr(skb)); 58 flowlabel = *((u_int32_t *)ipv6_hdr(skb));
121 59
122 ret = ip6t_do_table(skb, hook, in, out, 60 ret = ip6t_do_table(skb, NF_INET_LOCAL_OUT, NULL, out,
123 dev_net(out)->ipv6.ip6table_mangle); 61 dev_net(out)->ipv6.ip6table_mangle);
124 62
125 if (ret != NF_DROP && ret != NF_STOLEN 63 if (ret != NF_DROP && ret != NF_STOLEN &&
126 && (memcmp(&ipv6_hdr(skb)->saddr, &saddr, sizeof(saddr)) 64 (memcmp(&ipv6_hdr(skb)->saddr, &saddr, sizeof(saddr)) ||
127 || memcmp(&ipv6_hdr(skb)->daddr, &daddr, sizeof(daddr)) 65 memcmp(&ipv6_hdr(skb)->daddr, &daddr, sizeof(daddr)) ||
128 || skb->mark != mark 66 skb->mark != mark ||
129 || ipv6_hdr(skb)->hop_limit != hop_limit)) 67 ipv6_hdr(skb)->hop_limit != hop_limit))
130 return ip6_route_me_harder(skb) == 0 ? ret : NF_DROP; 68 return ip6_route_me_harder(skb) == 0 ? ret : NF_DROP;
131 69
132 return ret; 70 return ret;
133} 71}
134 72
135static struct nf_hook_ops ip6t_ops[] __read_mostly = { 73/* The work comes in here from netfilter.c. */
136 { 74static unsigned int
137 .hook = ip6t_in_hook, 75ip6table_mangle_hook(unsigned int hook, struct sk_buff *skb,
138 .owner = THIS_MODULE, 76 const struct net_device *in, const struct net_device *out,
139 .pf = NFPROTO_IPV6, 77 int (*okfn)(struct sk_buff *))
140 .hooknum = NF_INET_PRE_ROUTING, 78{
141 .priority = NF_IP6_PRI_MANGLE, 79 if (hook == NF_INET_LOCAL_OUT)
142 }, 80 return ip6t_mangle_out(skb, out);
143 { 81 if (hook == NF_INET_POST_ROUTING)
144 .hook = ip6t_in_hook, 82 return ip6t_do_table(skb, hook, in, out,
145 .owner = THIS_MODULE, 83 dev_net(out)->ipv6.ip6table_mangle);
146 .pf = NFPROTO_IPV6, 84 /* INPUT/FORWARD */
147 .hooknum = NF_INET_LOCAL_IN, 85 return ip6t_do_table(skb, hook, in, out,
148 .priority = NF_IP6_PRI_MANGLE, 86 dev_net(in)->ipv6.ip6table_mangle);
149 }, 87}
150 {
151 .hook = ip6t_in_hook,
152 .owner = THIS_MODULE,
153 .pf = NFPROTO_IPV6,
154 .hooknum = NF_INET_FORWARD,
155 .priority = NF_IP6_PRI_MANGLE,
156 },
157 {
158 .hook = ip6t_local_out_hook,
159 .owner = THIS_MODULE,
160 .pf = NFPROTO_IPV6,
161 .hooknum = NF_INET_LOCAL_OUT,
162 .priority = NF_IP6_PRI_MANGLE,
163 },
164 {
165 .hook = ip6t_post_routing_hook,
166 .owner = THIS_MODULE,
167 .pf = NFPROTO_IPV6,
168 .hooknum = NF_INET_POST_ROUTING,
169 .priority = NF_IP6_PRI_MANGLE,
170 },
171};
172 88
89static struct nf_hook_ops *mangle_ops __read_mostly;
173static int __net_init ip6table_mangle_net_init(struct net *net) 90static int __net_init ip6table_mangle_net_init(struct net *net)
174{ 91{
175 /* Register table */ 92 struct ip6t_replace *repl;
93
94 repl = ip6t_alloc_initial_table(&packet_mangler);
95 if (repl == NULL)
96 return -ENOMEM;
176 net->ipv6.ip6table_mangle = 97 net->ipv6.ip6table_mangle =
177 ip6t_register_table(net, &packet_mangler, &initial_table.repl); 98 ip6t_register_table(net, &packet_mangler, repl);
99 kfree(repl);
178 if (IS_ERR(net->ipv6.ip6table_mangle)) 100 if (IS_ERR(net->ipv6.ip6table_mangle))
179 return PTR_ERR(net->ipv6.ip6table_mangle); 101 return PTR_ERR(net->ipv6.ip6table_mangle);
180 return 0; 102 return 0;
@@ -182,7 +104,7 @@ static int __net_init ip6table_mangle_net_init(struct net *net)
182 104
183static void __net_exit ip6table_mangle_net_exit(struct net *net) 105static void __net_exit ip6table_mangle_net_exit(struct net *net)
184{ 106{
185 ip6t_unregister_table(net->ipv6.ip6table_mangle); 107 ip6t_unregister_table(net, net->ipv6.ip6table_mangle);
186} 108}
187 109
188static struct pernet_operations ip6table_mangle_net_ops = { 110static struct pernet_operations ip6table_mangle_net_ops = {
@@ -199,9 +121,11 @@ static int __init ip6table_mangle_init(void)
199 return ret; 121 return ret;
200 122
201 /* Register hooks */ 123 /* Register hooks */
202 ret = nf_register_hooks(ip6t_ops, ARRAY_SIZE(ip6t_ops)); 124 mangle_ops = xt_hook_link(&packet_mangler, ip6table_mangle_hook);
203 if (ret < 0) 125 if (IS_ERR(mangle_ops)) {
126 ret = PTR_ERR(mangle_ops);
204 goto cleanup_table; 127 goto cleanup_table;
128 }
205 129
206 return ret; 130 return ret;
207 131
@@ -212,7 +136,7 @@ static int __init ip6table_mangle_init(void)
212 136
213static void __exit ip6table_mangle_fini(void) 137static void __exit ip6table_mangle_fini(void)
214{ 138{
215 nf_unregister_hooks(ip6t_ops, ARRAY_SIZE(ip6t_ops)); 139 xt_hook_unlink(&packet_mangler, mangle_ops);
216 unregister_pernet_subsys(&ip6table_mangle_net_ops); 140 unregister_pernet_subsys(&ip6table_mangle_net_ops);
217} 141}
218 142
diff --git a/net/ipv6/netfilter/ip6table_raw.c b/net/ipv6/netfilter/ip6table_raw.c
index ed1a1180f3b3..5b9926a011bd 100644
--- a/net/ipv6/netfilter/ip6table_raw.c
+++ b/net/ipv6/netfilter/ip6table_raw.c
@@ -5,88 +5,41 @@
5 */ 5 */
6#include <linux/module.h> 6#include <linux/module.h>
7#include <linux/netfilter_ipv6/ip6_tables.h> 7#include <linux/netfilter_ipv6/ip6_tables.h>
8#include <linux/slab.h>
8 9
9#define RAW_VALID_HOOKS ((1 << NF_INET_PRE_ROUTING) | (1 << NF_INET_LOCAL_OUT)) 10#define RAW_VALID_HOOKS ((1 << NF_INET_PRE_ROUTING) | (1 << NF_INET_LOCAL_OUT))
10 11
11static const struct
12{
13 struct ip6t_replace repl;
14 struct ip6t_standard entries[2];
15 struct ip6t_error term;
16} initial_table __net_initdata = {
17 .repl = {
18 .name = "raw",
19 .valid_hooks = RAW_VALID_HOOKS,
20 .num_entries = 3,
21 .size = sizeof(struct ip6t_standard) * 2 + sizeof(struct ip6t_error),
22 .hook_entry = {
23 [NF_INET_PRE_ROUTING] = 0,
24 [NF_INET_LOCAL_OUT] = sizeof(struct ip6t_standard)
25 },
26 .underflow = {
27 [NF_INET_PRE_ROUTING] = 0,
28 [NF_INET_LOCAL_OUT] = sizeof(struct ip6t_standard)
29 },
30 },
31 .entries = {
32 IP6T_STANDARD_INIT(NF_ACCEPT), /* PRE_ROUTING */
33 IP6T_STANDARD_INIT(NF_ACCEPT), /* LOCAL_OUT */
34 },
35 .term = IP6T_ERROR_INIT, /* ERROR */
36};
37
38static const struct xt_table packet_raw = { 12static const struct xt_table packet_raw = {
39 .name = "raw", 13 .name = "raw",
40 .valid_hooks = RAW_VALID_HOOKS, 14 .valid_hooks = RAW_VALID_HOOKS,
41 .me = THIS_MODULE, 15 .me = THIS_MODULE,
42 .af = NFPROTO_IPV6, 16 .af = NFPROTO_IPV6,
17 .priority = NF_IP6_PRI_RAW,
43}; 18};
44 19
45/* The work comes in here from netfilter.c. */ 20/* The work comes in here from netfilter.c. */
46static unsigned int 21static unsigned int
47ip6t_pre_routing_hook(unsigned int hook, 22ip6table_raw_hook(unsigned int hook, struct sk_buff *skb,
48 struct sk_buff *skb, 23 const struct net_device *in, const struct net_device *out,
49 const struct net_device *in, 24 int (*okfn)(struct sk_buff *))
50 const struct net_device *out,
51 int (*okfn)(struct sk_buff *))
52{ 25{
53 return ip6t_do_table(skb, hook, in, out, 26 const struct net *net = dev_net((in != NULL) ? in : out);
54 dev_net(in)->ipv6.ip6table_raw);
55}
56 27
57static unsigned int 28 return ip6t_do_table(skb, hook, in, out, net->ipv6.ip6table_raw);
58ip6t_local_out_hook(unsigned int hook,
59 struct sk_buff *skb,
60 const struct net_device *in,
61 const struct net_device *out,
62 int (*okfn)(struct sk_buff *))
63{
64 return ip6t_do_table(skb, hook, in, out,
65 dev_net(out)->ipv6.ip6table_raw);
66} 29}
67 30
68static struct nf_hook_ops ip6t_ops[] __read_mostly = { 31static struct nf_hook_ops *rawtable_ops __read_mostly;
69 {
70 .hook = ip6t_pre_routing_hook,
71 .pf = NFPROTO_IPV6,
72 .hooknum = NF_INET_PRE_ROUTING,
73 .priority = NF_IP6_PRI_FIRST,
74 .owner = THIS_MODULE,
75 },
76 {
77 .hook = ip6t_local_out_hook,
78 .pf = NFPROTO_IPV6,
79 .hooknum = NF_INET_LOCAL_OUT,
80 .priority = NF_IP6_PRI_FIRST,
81 .owner = THIS_MODULE,
82 },
83};
84 32
85static int __net_init ip6table_raw_net_init(struct net *net) 33static int __net_init ip6table_raw_net_init(struct net *net)
86{ 34{
87 /* Register table */ 35 struct ip6t_replace *repl;
36
37 repl = ip6t_alloc_initial_table(&packet_raw);
38 if (repl == NULL)
39 return -ENOMEM;
88 net->ipv6.ip6table_raw = 40 net->ipv6.ip6table_raw =
89 ip6t_register_table(net, &packet_raw, &initial_table.repl); 41 ip6t_register_table(net, &packet_raw, repl);
42 kfree(repl);
90 if (IS_ERR(net->ipv6.ip6table_raw)) 43 if (IS_ERR(net->ipv6.ip6table_raw))
91 return PTR_ERR(net->ipv6.ip6table_raw); 44 return PTR_ERR(net->ipv6.ip6table_raw);
92 return 0; 45 return 0;
@@ -94,7 +47,7 @@ static int __net_init ip6table_raw_net_init(struct net *net)
94 47
95static void __net_exit ip6table_raw_net_exit(struct net *net) 48static void __net_exit ip6table_raw_net_exit(struct net *net)
96{ 49{
97 ip6t_unregister_table(net->ipv6.ip6table_raw); 50 ip6t_unregister_table(net, net->ipv6.ip6table_raw);
98} 51}
99 52
100static struct pernet_operations ip6table_raw_net_ops = { 53static struct pernet_operations ip6table_raw_net_ops = {
@@ -111,9 +64,11 @@ static int __init ip6table_raw_init(void)
111 return ret; 64 return ret;
112 65
113 /* Register hooks */ 66 /* Register hooks */
114 ret = nf_register_hooks(ip6t_ops, ARRAY_SIZE(ip6t_ops)); 67 rawtable_ops = xt_hook_link(&packet_raw, ip6table_raw_hook);
115 if (ret < 0) 68 if (IS_ERR(rawtable_ops)) {
69 ret = PTR_ERR(rawtable_ops);
116 goto cleanup_table; 70 goto cleanup_table;
71 }
117 72
118 return ret; 73 return ret;
119 74
@@ -124,7 +79,7 @@ static int __init ip6table_raw_init(void)
124 79
125static void __exit ip6table_raw_fini(void) 80static void __exit ip6table_raw_fini(void)
126{ 81{
127 nf_unregister_hooks(ip6t_ops, ARRAY_SIZE(ip6t_ops)); 82 xt_hook_unlink(&packet_raw, rawtable_ops);
128 unregister_pernet_subsys(&ip6table_raw_net_ops); 83 unregister_pernet_subsys(&ip6table_raw_net_ops);
129} 84}
130 85
diff --git a/net/ipv6/netfilter/ip6table_security.c b/net/ipv6/netfilter/ip6table_security.c
index 41b444c60934..91aa2b4d83c9 100644
--- a/net/ipv6/netfilter/ip6table_security.c
+++ b/net/ipv6/netfilter/ip6table_security.c
@@ -17,6 +17,7 @@
17 */ 17 */
18#include <linux/module.h> 18#include <linux/module.h>
19#include <linux/netfilter_ipv6/ip6_tables.h> 19#include <linux/netfilter_ipv6/ip6_tables.h>
20#include <linux/slab.h>
20 21
21MODULE_LICENSE("GPL"); 22MODULE_LICENSE("GPL");
22MODULE_AUTHOR("James Morris <jmorris <at> redhat.com>"); 23MODULE_AUTHOR("James Morris <jmorris <at> redhat.com>");
@@ -26,106 +27,37 @@ MODULE_DESCRIPTION("ip6tables security table, for MAC rules");
26 (1 << NF_INET_FORWARD) | \ 27 (1 << NF_INET_FORWARD) | \
27 (1 << NF_INET_LOCAL_OUT) 28 (1 << NF_INET_LOCAL_OUT)
28 29
29static const struct
30{
31 struct ip6t_replace repl;
32 struct ip6t_standard entries[3];
33 struct ip6t_error term;
34} initial_table __net_initdata = {
35 .repl = {
36 .name = "security",
37 .valid_hooks = SECURITY_VALID_HOOKS,
38 .num_entries = 4,
39 .size = sizeof(struct ip6t_standard) * 3 + sizeof(struct ip6t_error),
40 .hook_entry = {
41 [NF_INET_LOCAL_IN] = 0,
42 [NF_INET_FORWARD] = sizeof(struct ip6t_standard),
43 [NF_INET_LOCAL_OUT] = sizeof(struct ip6t_standard) * 2,
44 },
45 .underflow = {
46 [NF_INET_LOCAL_IN] = 0,
47 [NF_INET_FORWARD] = sizeof(struct ip6t_standard),
48 [NF_INET_LOCAL_OUT] = sizeof(struct ip6t_standard) * 2,
49 },
50 },
51 .entries = {
52 IP6T_STANDARD_INIT(NF_ACCEPT), /* LOCAL_IN */
53 IP6T_STANDARD_INIT(NF_ACCEPT), /* FORWARD */
54 IP6T_STANDARD_INIT(NF_ACCEPT), /* LOCAL_OUT */
55 },
56 .term = IP6T_ERROR_INIT, /* ERROR */
57};
58
59static const struct xt_table security_table = { 30static const struct xt_table security_table = {
60 .name = "security", 31 .name = "security",
61 .valid_hooks = SECURITY_VALID_HOOKS, 32 .valid_hooks = SECURITY_VALID_HOOKS,
62 .me = THIS_MODULE, 33 .me = THIS_MODULE,
63 .af = NFPROTO_IPV6, 34 .af = NFPROTO_IPV6,
35 .priority = NF_IP6_PRI_SECURITY,
64}; 36};
65 37
66static unsigned int 38static unsigned int
67ip6t_local_in_hook(unsigned int hook, 39ip6table_security_hook(unsigned int hook, struct sk_buff *skb,
68 struct sk_buff *skb, 40 const struct net_device *in,
69 const struct net_device *in, 41 const struct net_device *out,
70 const struct net_device *out, 42 int (*okfn)(struct sk_buff *))
71 int (*okfn)(struct sk_buff *))
72{
73 return ip6t_do_table(skb, hook, in, out,
74 dev_net(in)->ipv6.ip6table_security);
75}
76
77static unsigned int
78ip6t_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{ 43{
84 return ip6t_do_table(skb, hook, in, out, 44 const struct net *net = dev_net((in != NULL) ? in : out);
85 dev_net(in)->ipv6.ip6table_security);
86}
87 45
88static unsigned int 46 return ip6t_do_table(skb, hook, in, out, net->ipv6.ip6table_security);
89ip6t_local_out_hook(unsigned int hook,
90 struct sk_buff *skb,
91 const struct net_device *in,
92 const struct net_device *out,
93 int (*okfn)(struct sk_buff *))
94{
95 /* TBD: handle short packets via raw socket */
96 return ip6t_do_table(skb, hook, in, out,
97 dev_net(out)->ipv6.ip6table_security);
98} 47}
99 48
100static struct nf_hook_ops ip6t_ops[] __read_mostly = { 49static struct nf_hook_ops *sectbl_ops __read_mostly;
101 {
102 .hook = ip6t_local_in_hook,
103 .owner = THIS_MODULE,
104 .pf = NFPROTO_IPV6,
105 .hooknum = NF_INET_LOCAL_IN,
106 .priority = NF_IP6_PRI_SECURITY,
107 },
108 {
109 .hook = ip6t_forward_hook,
110 .owner = THIS_MODULE,
111 .pf = NFPROTO_IPV6,
112 .hooknum = NF_INET_FORWARD,
113 .priority = NF_IP6_PRI_SECURITY,
114 },
115 {
116 .hook = ip6t_local_out_hook,
117 .owner = THIS_MODULE,
118 .pf = NFPROTO_IPV6,
119 .hooknum = NF_INET_LOCAL_OUT,
120 .priority = NF_IP6_PRI_SECURITY,
121 },
122};
123 50
124static int __net_init ip6table_security_net_init(struct net *net) 51static int __net_init ip6table_security_net_init(struct net *net)
125{ 52{
126 net->ipv6.ip6table_security = 53 struct ip6t_replace *repl;
127 ip6t_register_table(net, &security_table, &initial_table.repl);
128 54
55 repl = ip6t_alloc_initial_table(&security_table);
56 if (repl == NULL)
57 return -ENOMEM;
58 net->ipv6.ip6table_security =
59 ip6t_register_table(net, &security_table, repl);
60 kfree(repl);
129 if (IS_ERR(net->ipv6.ip6table_security)) 61 if (IS_ERR(net->ipv6.ip6table_security))
130 return PTR_ERR(net->ipv6.ip6table_security); 62 return PTR_ERR(net->ipv6.ip6table_security);
131 63
@@ -134,7 +66,7 @@ static int __net_init ip6table_security_net_init(struct net *net)
134 66
135static void __net_exit ip6table_security_net_exit(struct net *net) 67static void __net_exit ip6table_security_net_exit(struct net *net)
136{ 68{
137 ip6t_unregister_table(net->ipv6.ip6table_security); 69 ip6t_unregister_table(net, net->ipv6.ip6table_security);
138} 70}
139 71
140static struct pernet_operations ip6table_security_net_ops = { 72static struct pernet_operations ip6table_security_net_ops = {
@@ -150,9 +82,11 @@ static int __init ip6table_security_init(void)
150 if (ret < 0) 82 if (ret < 0)
151 return ret; 83 return ret;
152 84
153 ret = nf_register_hooks(ip6t_ops, ARRAY_SIZE(ip6t_ops)); 85 sectbl_ops = xt_hook_link(&security_table, ip6table_security_hook);
154 if (ret < 0) 86 if (IS_ERR(sectbl_ops)) {
87 ret = PTR_ERR(sectbl_ops);
155 goto cleanup_table; 88 goto cleanup_table;
89 }
156 90
157 return ret; 91 return ret;
158 92
@@ -163,7 +97,7 @@ cleanup_table:
163 97
164static void __exit ip6table_security_fini(void) 98static void __exit ip6table_security_fini(void)
165{ 99{
166 nf_unregister_hooks(ip6t_ops, ARRAY_SIZE(ip6t_ops)); 100 xt_hook_unlink(&security_table, sectbl_ops);
167 unregister_pernet_subsys(&ip6table_security_net_ops); 101 unregister_pernet_subsys(&ip6table_security_net_ops);
168} 102}
169 103
diff --git a/net/ipv6/netfilter/nf_conntrack_l3proto_ipv6.c b/net/ipv6/netfilter/nf_conntrack_l3proto_ipv6.c
index 5f2ec208a8c3..996c3f41fecd 100644
--- a/net/ipv6/netfilter/nf_conntrack_l3proto_ipv6.c
+++ b/net/ipv6/netfilter/nf_conntrack_l3proto_ipv6.c
@@ -20,12 +20,14 @@
20#include <net/ipv6.h> 20#include <net/ipv6.h>
21#include <net/inet_frag.h> 21#include <net/inet_frag.h>
22 22
23#include <linux/netfilter_bridge.h>
23#include <linux/netfilter_ipv6.h> 24#include <linux/netfilter_ipv6.h>
24#include <net/netfilter/nf_conntrack.h> 25#include <net/netfilter/nf_conntrack.h>
25#include <net/netfilter/nf_conntrack_helper.h> 26#include <net/netfilter/nf_conntrack_helper.h>
26#include <net/netfilter/nf_conntrack_l4proto.h> 27#include <net/netfilter/nf_conntrack_l4proto.h>
27#include <net/netfilter/nf_conntrack_l3proto.h> 28#include <net/netfilter/nf_conntrack_l3proto.h>
28#include <net/netfilter/nf_conntrack_core.h> 29#include <net/netfilter/nf_conntrack_core.h>
30#include <net/netfilter/nf_conntrack_zones.h>
29#include <net/netfilter/ipv6/nf_conntrack_ipv6.h> 31#include <net/netfilter/ipv6/nf_conntrack_ipv6.h>
30#include <net/netfilter/nf_log.h> 32#include <net/netfilter/nf_log.h>
31 33
@@ -187,6 +189,26 @@ out:
187 return nf_conntrack_confirm(skb); 189 return nf_conntrack_confirm(skb);
188} 190}
189 191
192static enum ip6_defrag_users nf_ct6_defrag_user(unsigned int hooknum,
193 struct sk_buff *skb)
194{
195 u16 zone = NF_CT_DEFAULT_ZONE;
196
197 if (skb->nfct)
198 zone = nf_ct_zone((struct nf_conn *)skb->nfct);
199
200#ifdef CONFIG_BRIDGE_NETFILTER
201 if (skb->nf_bridge &&
202 skb->nf_bridge->mask & BRNF_NF_BRIDGE_PREROUTING)
203 return IP6_DEFRAG_CONNTRACK_BRIDGE_IN + zone;
204#endif
205 if (hooknum == NF_INET_PRE_ROUTING)
206 return IP6_DEFRAG_CONNTRACK_IN + zone;
207 else
208 return IP6_DEFRAG_CONNTRACK_OUT + zone;
209
210}
211
190static unsigned int ipv6_defrag(unsigned int hooknum, 212static unsigned int ipv6_defrag(unsigned int hooknum,
191 struct sk_buff *skb, 213 struct sk_buff *skb,
192 const struct net_device *in, 214 const struct net_device *in,
@@ -196,11 +218,10 @@ static unsigned int ipv6_defrag(unsigned int hooknum,
196 struct sk_buff *reasm; 218 struct sk_buff *reasm;
197 219
198 /* Previously seen (loopback)? */ 220 /* Previously seen (loopback)? */
199 if (skb->nfct) 221 if (skb->nfct && !nf_ct_is_template((struct nf_conn *)skb->nfct))
200 return NF_ACCEPT; 222 return NF_ACCEPT;
201 223
202 reasm = nf_ct_frag6_gather(skb); 224 reasm = nf_ct_frag6_gather(skb, nf_ct6_defrag_user(hooknum, skb));
203
204 /* queued */ 225 /* queued */
205 if (reasm == NULL) 226 if (reasm == NULL)
206 return NF_STOLEN; 227 return NF_STOLEN;
diff --git a/net/ipv6/netfilter/nf_conntrack_proto_icmpv6.c b/net/ipv6/netfilter/nf_conntrack_proto_icmpv6.c
index 642dcb127bab..9be81776415e 100644
--- a/net/ipv6/netfilter/nf_conntrack_proto_icmpv6.c
+++ b/net/ipv6/netfilter/nf_conntrack_proto_icmpv6.c
@@ -23,6 +23,7 @@
23#include <net/netfilter/nf_conntrack_tuple.h> 23#include <net/netfilter/nf_conntrack_tuple.h>
24#include <net/netfilter/nf_conntrack_l4proto.h> 24#include <net/netfilter/nf_conntrack_l4proto.h>
25#include <net/netfilter/nf_conntrack_core.h> 25#include <net/netfilter/nf_conntrack_core.h>
26#include <net/netfilter/nf_conntrack_zones.h>
26#include <net/netfilter/ipv6/nf_conntrack_icmpv6.h> 27#include <net/netfilter/ipv6/nf_conntrack_icmpv6.h>
27#include <net/netfilter/nf_log.h> 28#include <net/netfilter/nf_log.h>
28 29
@@ -128,7 +129,7 @@ static bool icmpv6_new(struct nf_conn *ct, const struct sk_buff *skb,
128} 129}
129 130
130static int 131static int
131icmpv6_error_message(struct net *net, 132icmpv6_error_message(struct net *net, struct nf_conn *tmpl,
132 struct sk_buff *skb, 133 struct sk_buff *skb,
133 unsigned int icmp6off, 134 unsigned int icmp6off,
134 enum ip_conntrack_info *ctinfo, 135 enum ip_conntrack_info *ctinfo,
@@ -137,6 +138,7 @@ icmpv6_error_message(struct net *net,
137 struct nf_conntrack_tuple intuple, origtuple; 138 struct nf_conntrack_tuple intuple, origtuple;
138 const struct nf_conntrack_tuple_hash *h; 139 const struct nf_conntrack_tuple_hash *h;
139 const struct nf_conntrack_l4proto *inproto; 140 const struct nf_conntrack_l4proto *inproto;
141 u16 zone = tmpl ? nf_ct_zone(tmpl) : NF_CT_DEFAULT_ZONE;
140 142
141 NF_CT_ASSERT(skb->nfct == NULL); 143 NF_CT_ASSERT(skb->nfct == NULL);
142 144
@@ -163,7 +165,7 @@ icmpv6_error_message(struct net *net,
163 165
164 *ctinfo = IP_CT_RELATED; 166 *ctinfo = IP_CT_RELATED;
165 167
166 h = nf_conntrack_find_get(net, &intuple); 168 h = nf_conntrack_find_get(net, zone, &intuple);
167 if (!h) { 169 if (!h) {
168 pr_debug("icmpv6_error: no match\n"); 170 pr_debug("icmpv6_error: no match\n");
169 return -NF_ACCEPT; 171 return -NF_ACCEPT;
@@ -179,7 +181,8 @@ icmpv6_error_message(struct net *net,
179} 181}
180 182
181static int 183static int
182icmpv6_error(struct net *net, struct sk_buff *skb, unsigned int dataoff, 184icmpv6_error(struct net *net, struct nf_conn *tmpl,
185 struct sk_buff *skb, unsigned int dataoff,
183 enum ip_conntrack_info *ctinfo, u_int8_t pf, unsigned int hooknum) 186 enum ip_conntrack_info *ctinfo, u_int8_t pf, unsigned int hooknum)
184{ 187{
185 const struct icmp6hdr *icmp6h; 188 const struct icmp6hdr *icmp6h;
@@ -215,7 +218,7 @@ icmpv6_error(struct net *net, struct sk_buff *skb, unsigned int dataoff,
215 if (icmp6h->icmp6_type >= 128) 218 if (icmp6h->icmp6_type >= 128)
216 return NF_ACCEPT; 219 return NF_ACCEPT;
217 220
218 return icmpv6_error_message(net, skb, dataoff, ctinfo, hooknum); 221 return icmpv6_error_message(net, tmpl, skb, dataoff, ctinfo, hooknum);
219} 222}
220 223
221#if defined(CONFIG_NF_CT_NETLINK) || defined(CONFIG_NF_CT_NETLINK_MODULE) 224#if defined(CONFIG_NF_CT_NETLINK) || defined(CONFIG_NF_CT_NETLINK_MODULE)
@@ -244,18 +247,18 @@ static const struct nla_policy icmpv6_nla_policy[CTA_PROTO_MAX+1] = {
244static int icmpv6_nlattr_to_tuple(struct nlattr *tb[], 247static int icmpv6_nlattr_to_tuple(struct nlattr *tb[],
245 struct nf_conntrack_tuple *tuple) 248 struct nf_conntrack_tuple *tuple)
246{ 249{
247 if (!tb[CTA_PROTO_ICMPV6_TYPE] 250 if (!tb[CTA_PROTO_ICMPV6_TYPE] ||
248 || !tb[CTA_PROTO_ICMPV6_CODE] 251 !tb[CTA_PROTO_ICMPV6_CODE] ||
249 || !tb[CTA_PROTO_ICMPV6_ID]) 252 !tb[CTA_PROTO_ICMPV6_ID])
250 return -EINVAL; 253 return -EINVAL;
251 254
252 tuple->dst.u.icmp.type = nla_get_u8(tb[CTA_PROTO_ICMPV6_TYPE]); 255 tuple->dst.u.icmp.type = nla_get_u8(tb[CTA_PROTO_ICMPV6_TYPE]);
253 tuple->dst.u.icmp.code = nla_get_u8(tb[CTA_PROTO_ICMPV6_CODE]); 256 tuple->dst.u.icmp.code = nla_get_u8(tb[CTA_PROTO_ICMPV6_CODE]);
254 tuple->src.u.icmp.id = nla_get_be16(tb[CTA_PROTO_ICMPV6_ID]); 257 tuple->src.u.icmp.id = nla_get_be16(tb[CTA_PROTO_ICMPV6_ID]);
255 258
256 if (tuple->dst.u.icmp.type < 128 259 if (tuple->dst.u.icmp.type < 128 ||
257 || tuple->dst.u.icmp.type - 128 >= sizeof(invmap) 260 tuple->dst.u.icmp.type - 128 >= sizeof(invmap) ||
258 || !invmap[tuple->dst.u.icmp.type - 128]) 261 !invmap[tuple->dst.u.icmp.type - 128])
259 return -EINVAL; 262 return -EINVAL;
260 263
261 return 0; 264 return 0;
@@ -277,9 +280,7 @@ static struct ctl_table icmpv6_sysctl_table[] = {
277 .mode = 0644, 280 .mode = 0644,
278 .proc_handler = proc_dointvec_jiffies, 281 .proc_handler = proc_dointvec_jiffies,
279 }, 282 },
280 { 283 { }
281 .ctl_name = 0
282 }
283}; 284};
284#endif /* CONFIG_SYSCTL */ 285#endif /* CONFIG_SYSCTL */
285 286
diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/nf_conntrack_reasm.c
index f3aba255ad9f..dd5b9bd61c62 100644
--- a/net/ipv6/netfilter/nf_conntrack_reasm.c
+++ b/net/ipv6/netfilter/nf_conntrack_reasm.c
@@ -27,6 +27,7 @@
27#include <linux/ipv6.h> 27#include <linux/ipv6.h>
28#include <linux/icmpv6.h> 28#include <linux/icmpv6.h>
29#include <linux/random.h> 29#include <linux/random.h>
30#include <linux/slab.h>
30 31
31#include <net/sock.h> 32#include <net/sock.h>
32#include <net/snmp.h> 33#include <net/snmp.h>
@@ -45,9 +46,6 @@
45#include <linux/kernel.h> 46#include <linux/kernel.h>
46#include <linux/module.h> 47#include <linux/module.h>
47 48
48#define NF_CT_FRAG6_HIGH_THRESH 262144 /* == 256*1024 */
49#define NF_CT_FRAG6_LOW_THRESH 196608 /* == 192*1024 */
50#define NF_CT_FRAG6_TIMEOUT IPV6_FRAG_TIMEOUT
51 49
52struct nf_ct_frag6_skb_cb 50struct nf_ct_frag6_skb_cb
53{ 51{
@@ -63,6 +61,7 @@ struct nf_ct_frag6_queue
63 struct inet_frag_queue q; 61 struct inet_frag_queue q;
64 62
65 __be32 id; /* fragment id */ 63 __be32 id; /* fragment id */
64 u32 user;
66 struct in6_addr saddr; 65 struct in6_addr saddr;
67 struct in6_addr daddr; 66 struct in6_addr daddr;
68 67
@@ -83,7 +82,6 @@ struct ctl_table nf_ct_ipv6_sysctl_table[] = {
83 .proc_handler = proc_dointvec_jiffies, 82 .proc_handler = proc_dointvec_jiffies,
84 }, 83 },
85 { 84 {
86 .ctl_name = NET_NF_CONNTRACK_FRAG6_LOW_THRESH,
87 .procname = "nf_conntrack_frag6_low_thresh", 85 .procname = "nf_conntrack_frag6_low_thresh",
88 .data = &nf_init_frags.low_thresh, 86 .data = &nf_init_frags.low_thresh,
89 .maxlen = sizeof(unsigned int), 87 .maxlen = sizeof(unsigned int),
@@ -91,14 +89,13 @@ struct ctl_table nf_ct_ipv6_sysctl_table[] = {
91 .proc_handler = proc_dointvec, 89 .proc_handler = proc_dointvec,
92 }, 90 },
93 { 91 {
94 .ctl_name = NET_NF_CONNTRACK_FRAG6_HIGH_THRESH,
95 .procname = "nf_conntrack_frag6_high_thresh", 92 .procname = "nf_conntrack_frag6_high_thresh",
96 .data = &nf_init_frags.high_thresh, 93 .data = &nf_init_frags.high_thresh,
97 .maxlen = sizeof(unsigned int), 94 .maxlen = sizeof(unsigned int),
98 .mode = 0644, 95 .mode = 0644,
99 .proc_handler = proc_dointvec, 96 .proc_handler = proc_dointvec,
100 }, 97 },
101 { .ctl_name = 0 } 98 { }
102}; 99};
103#endif 100#endif
104 101
@@ -170,13 +167,14 @@ out:
170/* Creation primitives. */ 167/* Creation primitives. */
171 168
172static __inline__ struct nf_ct_frag6_queue * 169static __inline__ struct nf_ct_frag6_queue *
173fq_find(__be32 id, struct in6_addr *src, struct in6_addr *dst) 170fq_find(__be32 id, u32 user, struct in6_addr *src, struct in6_addr *dst)
174{ 171{
175 struct inet_frag_queue *q; 172 struct inet_frag_queue *q;
176 struct ip6_create_arg arg; 173 struct ip6_create_arg arg;
177 unsigned int hash; 174 unsigned int hash;
178 175
179 arg.id = id; 176 arg.id = id;
177 arg.user = user;
180 arg.src = src; 178 arg.src = src;
181 arg.dst = dst; 179 arg.dst = dst;
182 180
@@ -472,7 +470,7 @@ nf_ct_frag6_reasm(struct nf_ct_frag6_queue *fq, struct net_device *dev)
472 470
473 /* all original skbs are linked into the NFCT_FRAG6_CB(head).orig */ 471 /* all original skbs are linked into the NFCT_FRAG6_CB(head).orig */
474 fp = skb_shinfo(head)->frag_list; 472 fp = skb_shinfo(head)->frag_list;
475 if (NFCT_FRAG6_CB(fp)->orig == NULL) 473 if (fp && NFCT_FRAG6_CB(fp)->orig == NULL)
476 /* at above code, head skb is divided into two skbs. */ 474 /* at above code, head skb is divided into two skbs. */
477 fp = fp->next; 475 fp = fp->next;
478 476
@@ -561,7 +559,7 @@ find_prev_fhdr(struct sk_buff *skb, u8 *prevhdrp, int *prevhoff, int *fhoff)
561 return 0; 559 return 0;
562} 560}
563 561
564struct sk_buff *nf_ct_frag6_gather(struct sk_buff *skb) 562struct sk_buff *nf_ct_frag6_gather(struct sk_buff *skb, u32 user)
565{ 563{
566 struct sk_buff *clone; 564 struct sk_buff *clone;
567 struct net_device *dev = skb->dev; 565 struct net_device *dev = skb->dev;
@@ -598,16 +596,10 @@ struct sk_buff *nf_ct_frag6_gather(struct sk_buff *skb)
598 hdr = ipv6_hdr(clone); 596 hdr = ipv6_hdr(clone);
599 fhdr = (struct frag_hdr *)skb_transport_header(clone); 597 fhdr = (struct frag_hdr *)skb_transport_header(clone);
600 598
601 if (!(fhdr->frag_off & htons(0xFFF9))) {
602 pr_debug("Invalid fragment offset\n");
603 /* It is not a fragmented frame */
604 goto ret_orig;
605 }
606
607 if (atomic_read(&nf_init_frags.mem) > nf_init_frags.high_thresh) 599 if (atomic_read(&nf_init_frags.mem) > nf_init_frags.high_thresh)
608 nf_ct_frag6_evictor(); 600 nf_ct_frag6_evictor();
609 601
610 fq = fq_find(fhdr->identification, &hdr->saddr, &hdr->daddr); 602 fq = fq_find(fhdr->identification, user, &hdr->saddr, &hdr->daddr);
611 if (fq == NULL) { 603 if (fq == NULL) {
612 pr_debug("Can't find and can't create new queue\n"); 604 pr_debug("Can't find and can't create new queue\n");
613 goto ret_orig; 605 goto ret_orig;
@@ -670,8 +662,8 @@ int nf_ct_frag6_init(void)
670 nf_frags.frag_expire = nf_ct_frag6_expire; 662 nf_frags.frag_expire = nf_ct_frag6_expire;
671 nf_frags.secret_interval = 10 * 60 * HZ; 663 nf_frags.secret_interval = 10 * 60 * HZ;
672 nf_init_frags.timeout = IPV6_FRAG_TIMEOUT; 664 nf_init_frags.timeout = IPV6_FRAG_TIMEOUT;
673 nf_init_frags.high_thresh = 256 * 1024; 665 nf_init_frags.high_thresh = IPV6_FRAG_HIGH_THRESH;
674 nf_init_frags.low_thresh = 192 * 1024; 666 nf_init_frags.low_thresh = IPV6_FRAG_LOW_THRESH;
675 inet_frags_init_net(&nf_init_frags); 667 inet_frags_init_net(&nf_init_frags);
676 inet_frags_init(&nf_frags); 668 inet_frags_init(&nf_frags);
677 669
diff --git a/net/ipv6/proc.c b/net/ipv6/proc.c
index c9605c3ad91f..58344c0fbd13 100644
--- a/net/ipv6/proc.c
+++ b/net/ipv6/proc.c
@@ -59,7 +59,7 @@ static const struct file_operations sockstat6_seq_fops = {
59 .release = single_release_net, 59 .release = single_release_net,
60}; 60};
61 61
62static struct snmp_mib snmp6_ipstats_list[] = { 62static const struct snmp_mib snmp6_ipstats_list[] = {
63/* ipv6 mib according to RFC 2465 */ 63/* ipv6 mib according to RFC 2465 */
64 SNMP_MIB_ITEM("Ip6InReceives", IPSTATS_MIB_INPKTS), 64 SNMP_MIB_ITEM("Ip6InReceives", IPSTATS_MIB_INPKTS),
65 SNMP_MIB_ITEM("Ip6InHdrErrors", IPSTATS_MIB_INHDRERRORS), 65 SNMP_MIB_ITEM("Ip6InHdrErrors", IPSTATS_MIB_INHDRERRORS),
@@ -92,7 +92,7 @@ static struct snmp_mib snmp6_ipstats_list[] = {
92 SNMP_MIB_SENTINEL 92 SNMP_MIB_SENTINEL
93}; 93};
94 94
95static struct snmp_mib snmp6_icmp6_list[] = { 95static const struct snmp_mib snmp6_icmp6_list[] = {
96/* icmpv6 mib according to RFC 2466 */ 96/* icmpv6 mib according to RFC 2466 */
97 SNMP_MIB_ITEM("Icmp6InMsgs", ICMP6_MIB_INMSGS), 97 SNMP_MIB_ITEM("Icmp6InMsgs", ICMP6_MIB_INMSGS),
98 SNMP_MIB_ITEM("Icmp6InErrors", ICMP6_MIB_INERRORS), 98 SNMP_MIB_ITEM("Icmp6InErrors", ICMP6_MIB_INERRORS),
@@ -120,7 +120,7 @@ static const char *const icmp6type2name[256] = {
120}; 120};
121 121
122 122
123static struct snmp_mib snmp6_udp6_list[] = { 123static const struct snmp_mib snmp6_udp6_list[] = {
124 SNMP_MIB_ITEM("Udp6InDatagrams", UDP_MIB_INDATAGRAMS), 124 SNMP_MIB_ITEM("Udp6InDatagrams", UDP_MIB_INDATAGRAMS),
125 SNMP_MIB_ITEM("Udp6NoPorts", UDP_MIB_NOPORTS), 125 SNMP_MIB_ITEM("Udp6NoPorts", UDP_MIB_NOPORTS),
126 SNMP_MIB_ITEM("Udp6InErrors", UDP_MIB_INERRORS), 126 SNMP_MIB_ITEM("Udp6InErrors", UDP_MIB_INERRORS),
@@ -128,7 +128,7 @@ static struct snmp_mib snmp6_udp6_list[] = {
128 SNMP_MIB_SENTINEL 128 SNMP_MIB_SENTINEL
129}; 129};
130 130
131static struct snmp_mib snmp6_udplite6_list[] = { 131static const struct snmp_mib snmp6_udplite6_list[] = {
132 SNMP_MIB_ITEM("UdpLite6InDatagrams", UDP_MIB_INDATAGRAMS), 132 SNMP_MIB_ITEM("UdpLite6InDatagrams", UDP_MIB_INDATAGRAMS),
133 SNMP_MIB_ITEM("UdpLite6NoPorts", UDP_MIB_NOPORTS), 133 SNMP_MIB_ITEM("UdpLite6NoPorts", UDP_MIB_NOPORTS),
134 SNMP_MIB_ITEM("UdpLite6InErrors", UDP_MIB_INERRORS), 134 SNMP_MIB_ITEM("UdpLite6InErrors", UDP_MIB_INERRORS),
@@ -136,7 +136,7 @@ static struct snmp_mib snmp6_udplite6_list[] = {
136 SNMP_MIB_SENTINEL 136 SNMP_MIB_SENTINEL
137}; 137};
138 138
139static void snmp6_seq_show_icmpv6msg(struct seq_file *seq, void **mib) 139static void snmp6_seq_show_icmpv6msg(struct seq_file *seq, void __percpu **mib)
140{ 140{
141 char name[32]; 141 char name[32];
142 int i; 142 int i;
@@ -170,8 +170,8 @@ static void snmp6_seq_show_icmpv6msg(struct seq_file *seq, void **mib)
170 return; 170 return;
171} 171}
172 172
173static inline void 173static void snmp6_seq_show_item(struct seq_file *seq, void __percpu **mib,
174snmp6_seq_show_item(struct seq_file *seq, void **mib, struct snmp_mib *itemlist) 174 const struct snmp_mib *itemlist)
175{ 175{
176 int i; 176 int i;
177 for (i=0; itemlist[i].name; i++) 177 for (i=0; itemlist[i].name; i++)
@@ -183,14 +183,15 @@ static int snmp6_seq_show(struct seq_file *seq, void *v)
183{ 183{
184 struct net *net = (struct net *)seq->private; 184 struct net *net = (struct net *)seq->private;
185 185
186 snmp6_seq_show_item(seq, (void **)net->mib.ipv6_statistics, 186 snmp6_seq_show_item(seq, (void __percpu **)net->mib.ipv6_statistics,
187 snmp6_ipstats_list); 187 snmp6_ipstats_list);
188 snmp6_seq_show_item(seq, (void **)net->mib.icmpv6_statistics, 188 snmp6_seq_show_item(seq, (void __percpu **)net->mib.icmpv6_statistics,
189 snmp6_icmp6_list); 189 snmp6_icmp6_list);
190 snmp6_seq_show_icmpv6msg(seq, (void **)net->mib.icmpv6msg_statistics); 190 snmp6_seq_show_icmpv6msg(seq,
191 snmp6_seq_show_item(seq, (void **)net->mib.udp_stats_in6, 191 (void __percpu **)net->mib.icmpv6msg_statistics);
192 snmp6_seq_show_item(seq, (void __percpu **)net->mib.udp_stats_in6,
192 snmp6_udp6_list); 193 snmp6_udp6_list);
193 snmp6_seq_show_item(seq, (void **)net->mib.udplite_stats_in6, 194 snmp6_seq_show_item(seq, (void __percpu **)net->mib.udplite_stats_in6,
194 snmp6_udplite6_list); 195 snmp6_udplite6_list);
195 return 0; 196 return 0;
196} 197}
@@ -213,9 +214,11 @@ static int snmp6_dev_seq_show(struct seq_file *seq, void *v)
213 struct inet6_dev *idev = (struct inet6_dev *)seq->private; 214 struct inet6_dev *idev = (struct inet6_dev *)seq->private;
214 215
215 seq_printf(seq, "%-32s\t%u\n", "ifIndex", idev->dev->ifindex); 216 seq_printf(seq, "%-32s\t%u\n", "ifIndex", idev->dev->ifindex);
216 snmp6_seq_show_item(seq, (void **)idev->stats.ipv6, snmp6_ipstats_list); 217 snmp6_seq_show_item(seq, (void __percpu **)idev->stats.ipv6,
217 snmp6_seq_show_item(seq, (void **)idev->stats.icmpv6, snmp6_icmp6_list); 218 snmp6_ipstats_list);
218 snmp6_seq_show_icmpv6msg(seq, (void **)idev->stats.icmpv6msg); 219 snmp6_seq_show_item(seq, (void __percpu **)idev->stats.icmpv6,
220 snmp6_icmp6_list);
221 snmp6_seq_show_icmpv6msg(seq, (void __percpu **)idev->stats.icmpv6msg);
219 return 0; 222 return 0;
220} 223}
221 224
@@ -259,7 +262,7 @@ int snmp6_unregister_dev(struct inet6_dev *idev)
259 struct net *net = dev_net(idev->dev); 262 struct net *net = dev_net(idev->dev);
260 if (!net->mib.proc_net_devsnmp6) 263 if (!net->mib.proc_net_devsnmp6)
261 return -ENOENT; 264 return -ENOENT;
262 if (!idev || !idev->stats.proc_dir_entry) 265 if (!idev->stats.proc_dir_entry)
263 return -EINVAL; 266 return -EINVAL;
264 remove_proc_entry(idev->stats.proc_dir_entry->name, 267 remove_proc_entry(idev->stats.proc_dir_entry->name,
265 net->mib.proc_net_devsnmp6); 268 net->mib.proc_net_devsnmp6);
@@ -267,7 +270,7 @@ int snmp6_unregister_dev(struct inet6_dev *idev)
267 return 0; 270 return 0;
268} 271}
269 272
270static int ipv6_proc_init_net(struct net *net) 273static int __net_init ipv6_proc_init_net(struct net *net)
271{ 274{
272 if (!proc_net_fops_create(net, "sockstat6", S_IRUGO, 275 if (!proc_net_fops_create(net, "sockstat6", S_IRUGO,
273 &sockstat6_seq_fops)) 276 &sockstat6_seq_fops))
@@ -288,7 +291,7 @@ proc_dev_snmp6_fail:
288 return -ENOMEM; 291 return -ENOMEM;
289} 292}
290 293
291static void ipv6_proc_exit_net(struct net *net) 294static void __net_exit ipv6_proc_exit_net(struct net *net)
292{ 295{
293 proc_net_remove(net, "sockstat6"); 296 proc_net_remove(net, "sockstat6");
294 proc_net_remove(net, "dev_snmp6"); 297 proc_net_remove(net, "dev_snmp6");
diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
index 4f24570b0869..8763b1a0814a 100644
--- a/net/ipv6/raw.c
+++ b/net/ipv6/raw.c
@@ -21,6 +21,7 @@
21#include <linux/errno.h> 21#include <linux/errno.h>
22#include <linux/types.h> 22#include <linux/types.h>
23#include <linux/socket.h> 23#include <linux/socket.h>
24#include <linux/slab.h>
24#include <linux/sockios.h> 25#include <linux/sockios.h>
25#include <linux/net.h> 26#include <linux/net.h>
26#include <linux/in6.h> 27#include <linux/in6.h>
@@ -72,7 +73,7 @@ static struct sock *__raw_v6_lookup(struct net *net, struct sock *sk,
72 int is_multicast = ipv6_addr_is_multicast(loc_addr); 73 int is_multicast = ipv6_addr_is_multicast(loc_addr);
73 74
74 sk_for_each_from(sk, node) 75 sk_for_each_from(sk, node)
75 if (inet_sk(sk)->num == num) { 76 if (inet_sk(sk)->inet_num == num) {
76 struct ipv6_pinfo *np = inet6_sk(sk); 77 struct ipv6_pinfo *np = inet6_sk(sk);
77 78
78 if (!net_eq(sock_net(sk), net)) 79 if (!net_eq(sock_net(sk), net))
@@ -249,7 +250,7 @@ static int rawv6_bind(struct sock *sk, struct sockaddr *uaddr, int addr_len)
249 250
250 /* Raw sockets are IPv6 only */ 251 /* Raw sockets are IPv6 only */
251 if (addr_type == IPV6_ADDR_MAPPED) 252 if (addr_type == IPV6_ADDR_MAPPED)
252 return(-EADDRNOTAVAIL); 253 return -EADDRNOTAVAIL;
253 254
254 lock_sock(sk); 255 lock_sock(sk);
255 256
@@ -257,6 +258,7 @@ static int rawv6_bind(struct sock *sk, struct sockaddr *uaddr, int addr_len)
257 if (sk->sk_state != TCP_CLOSE) 258 if (sk->sk_state != TCP_CLOSE)
258 goto out; 259 goto out;
259 260
261 rcu_read_lock();
260 /* Check if the address belongs to the host. */ 262 /* Check if the address belongs to the host. */
261 if (addr_type != IPV6_ADDR_ANY) { 263 if (addr_type != IPV6_ADDR_ANY) {
262 struct net_device *dev = NULL; 264 struct net_device *dev = NULL;
@@ -272,13 +274,13 @@ static int rawv6_bind(struct sock *sk, struct sockaddr *uaddr, int addr_len)
272 274
273 /* Binding to link-local address requires an interface */ 275 /* Binding to link-local address requires an interface */
274 if (!sk->sk_bound_dev_if) 276 if (!sk->sk_bound_dev_if)
275 goto out; 277 goto out_unlock;
276 278
277 dev = dev_get_by_index(sock_net(sk), sk->sk_bound_dev_if); 279 err = -ENODEV;
278 if (!dev) { 280 dev = dev_get_by_index_rcu(sock_net(sk),
279 err = -ENODEV; 281 sk->sk_bound_dev_if);
280 goto out; 282 if (!dev)
281 } 283 goto out_unlock;
282 } 284 }
283 285
284 /* ipv4 addr of the socket is invalid. Only the 286 /* ipv4 addr of the socket is invalid. Only the
@@ -289,20 +291,18 @@ static int rawv6_bind(struct sock *sk, struct sockaddr *uaddr, int addr_len)
289 err = -EADDRNOTAVAIL; 291 err = -EADDRNOTAVAIL;
290 if (!ipv6_chk_addr(sock_net(sk), &addr->sin6_addr, 292 if (!ipv6_chk_addr(sock_net(sk), &addr->sin6_addr,
291 dev, 0)) { 293 dev, 0)) {
292 if (dev) 294 goto out_unlock;
293 dev_put(dev);
294 goto out;
295 } 295 }
296 } 296 }
297 if (dev)
298 dev_put(dev);
299 } 297 }
300 298
301 inet->rcv_saddr = inet->saddr = v4addr; 299 inet->inet_rcv_saddr = inet->inet_saddr = v4addr;
302 ipv6_addr_copy(&np->rcv_saddr, &addr->sin6_addr); 300 ipv6_addr_copy(&np->rcv_saddr, &addr->sin6_addr);
303 if (!(addr_type & IPV6_ADDR_MULTICAST)) 301 if (!(addr_type & IPV6_ADDR_MULTICAST))
304 ipv6_addr_copy(&np->saddr, &addr->sin6_addr); 302 ipv6_addr_copy(&np->saddr, &addr->sin6_addr);
305 err = 0; 303 err = 0;
304out_unlock:
305 rcu_read_unlock();
306out: 306out:
307 release_sock(sk); 307 release_sock(sk);
308 return err; 308 return err;
@@ -381,8 +381,7 @@ static inline int rawv6_rcv_skb(struct sock * sk, struct sk_buff * skb)
381 } 381 }
382 382
383 /* Charge it to the socket. */ 383 /* Charge it to the socket. */
384 if (sock_queue_rcv_skb(sk,skb)<0) { 384 if (sock_queue_rcv_skb(sk, skb) < 0) {
385 atomic_inc(&sk->sk_drops);
386 kfree_skb(skb); 385 kfree_skb(skb);
387 return NET_RX_DROP; 386 return NET_RX_DROP;
388 } 387 }
@@ -416,14 +415,14 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
416 skb_network_header_len(skb)); 415 skb_network_header_len(skb));
417 if (!csum_ipv6_magic(&ipv6_hdr(skb)->saddr, 416 if (!csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
418 &ipv6_hdr(skb)->daddr, 417 &ipv6_hdr(skb)->daddr,
419 skb->len, inet->num, skb->csum)) 418 skb->len, inet->inet_num, skb->csum))
420 skb->ip_summed = CHECKSUM_UNNECESSARY; 419 skb->ip_summed = CHECKSUM_UNNECESSARY;
421 } 420 }
422 if (!skb_csum_unnecessary(skb)) 421 if (!skb_csum_unnecessary(skb))
423 skb->csum = ~csum_unfold(csum_ipv6_magic(&ipv6_hdr(skb)->saddr, 422 skb->csum = ~csum_unfold(csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
424 &ipv6_hdr(skb)->daddr, 423 &ipv6_hdr(skb)->daddr,
425 skb->len, 424 skb->len,
426 inet->num, 0)); 425 inet->inet_num, 0));
427 426
428 if (inet->hdrincl) { 427 if (inet->hdrincl) {
429 if (skb_checksum_complete(skb)) { 428 if (skb_checksum_complete(skb)) {
@@ -497,7 +496,7 @@ static int rawv6_recvmsg(struct kiocb *iocb, struct sock *sk,
497 sin6->sin6_scope_id = IP6CB(skb)->iif; 496 sin6->sin6_scope_id = IP6CB(skb)->iif;
498 } 497 }
499 498
500 sock_recv_timestamp(msg, sk, skb); 499 sock_recv_ts_and_drops(msg, sk, skb);
501 500
502 if (np->rxopt.all) 501 if (np->rxopt.all)
503 datagram_recv_ctl(sk, msg, skb); 502 datagram_recv_ctl(sk, msg, skb);
@@ -518,7 +517,6 @@ csum_copy_err:
518 as some normal condition. 517 as some normal condition.
519 */ 518 */
520 err = (flags&MSG_DONTWAIT) ? -EAGAIN : -EHOSTUNREACH; 519 err = (flags&MSG_DONTWAIT) ? -EAGAIN : -EHOSTUNREACH;
521 atomic_inc(&sk->sk_drops);
522 goto out; 520 goto out;
523} 521}
524 522
@@ -766,8 +764,8 @@ static int rawv6_sendmsg(struct kiocb *iocb, struct sock *sk,
766 proto = ntohs(sin6->sin6_port); 764 proto = ntohs(sin6->sin6_port);
767 765
768 if (!proto) 766 if (!proto)
769 proto = inet->num; 767 proto = inet->inet_num;
770 else if (proto != inet->num) 768 else if (proto != inet->inet_num)
771 return(-EINVAL); 769 return(-EINVAL);
772 770
773 if (proto > 255) 771 if (proto > 255)
@@ -800,7 +798,7 @@ static int rawv6_sendmsg(struct kiocb *iocb, struct sock *sk,
800 if (sk->sk_state != TCP_ESTABLISHED) 798 if (sk->sk_state != TCP_ESTABLISHED)
801 return -EDESTADDRREQ; 799 return -EDESTADDRREQ;
802 800
803 proto = inet->num; 801 proto = inet->inet_num;
804 daddr = &np->daddr; 802 daddr = &np->daddr;
805 fl.fl6_flowlabel = np->flow_label; 803 fl.fl6_flowlabel = np->flow_label;
806 } 804 }
@@ -967,7 +965,7 @@ static int do_rawv6_setsockopt(struct sock *sk, int level, int optname,
967 965
968 switch (optname) { 966 switch (optname) {
969 case IPV6_CHECKSUM: 967 case IPV6_CHECKSUM:
970 if (inet_sk(sk)->num == IPPROTO_ICMPV6 && 968 if (inet_sk(sk)->inet_num == IPPROTO_ICMPV6 &&
971 level == IPPROTO_IPV6) { 969 level == IPPROTO_IPV6) {
972 /* 970 /*
973 * RFC3542 tells that IPV6_CHECKSUM socket 971 * RFC3542 tells that IPV6_CHECKSUM socket
@@ -1007,7 +1005,7 @@ static int rawv6_setsockopt(struct sock *sk, int level, int optname,
1007 break; 1005 break;
1008 1006
1009 case SOL_ICMPV6: 1007 case SOL_ICMPV6:
1010 if (inet_sk(sk)->num != IPPROTO_ICMPV6) 1008 if (inet_sk(sk)->inet_num != IPPROTO_ICMPV6)
1011 return -EOPNOTSUPP; 1009 return -EOPNOTSUPP;
1012 return rawv6_seticmpfilter(sk, level, optname, optval, 1010 return rawv6_seticmpfilter(sk, level, optname, optval,
1013 optlen); 1011 optlen);
@@ -1030,7 +1028,7 @@ static int compat_rawv6_setsockopt(struct sock *sk, int level, int optname,
1030 case SOL_RAW: 1028 case SOL_RAW:
1031 break; 1029 break;
1032 case SOL_ICMPV6: 1030 case SOL_ICMPV6:
1033 if (inet_sk(sk)->num != IPPROTO_ICMPV6) 1031 if (inet_sk(sk)->inet_num != IPPROTO_ICMPV6)
1034 return -EOPNOTSUPP; 1032 return -EOPNOTSUPP;
1035 return rawv6_seticmpfilter(sk, level, optname, optval, optlen); 1033 return rawv6_seticmpfilter(sk, level, optname, optval, optlen);
1036 case SOL_IPV6: 1034 case SOL_IPV6:
@@ -1087,7 +1085,7 @@ static int rawv6_getsockopt(struct sock *sk, int level, int optname,
1087 break; 1085 break;
1088 1086
1089 case SOL_ICMPV6: 1087 case SOL_ICMPV6:
1090 if (inet_sk(sk)->num != IPPROTO_ICMPV6) 1088 if (inet_sk(sk)->inet_num != IPPROTO_ICMPV6)
1091 return -EOPNOTSUPP; 1089 return -EOPNOTSUPP;
1092 return rawv6_geticmpfilter(sk, level, optname, optval, 1090 return rawv6_geticmpfilter(sk, level, optname, optval,
1093 optlen); 1091 optlen);
@@ -1110,7 +1108,7 @@ static int compat_rawv6_getsockopt(struct sock *sk, int level, int optname,
1110 case SOL_RAW: 1108 case SOL_RAW:
1111 break; 1109 break;
1112 case SOL_ICMPV6: 1110 case SOL_ICMPV6:
1113 if (inet_sk(sk)->num != IPPROTO_ICMPV6) 1111 if (inet_sk(sk)->inet_num != IPPROTO_ICMPV6)
1114 return -EOPNOTSUPP; 1112 return -EOPNOTSUPP;
1115 return rawv6_geticmpfilter(sk, level, optname, optval, optlen); 1113 return rawv6_geticmpfilter(sk, level, optname, optval, optlen);
1116 case SOL_IPV6: 1114 case SOL_IPV6:
@@ -1157,7 +1155,7 @@ static int rawv6_ioctl(struct sock *sk, int cmd, unsigned long arg)
1157 1155
1158static void rawv6_close(struct sock *sk, long timeout) 1156static void rawv6_close(struct sock *sk, long timeout)
1159{ 1157{
1160 if (inet_sk(sk)->num == IPPROTO_RAW) 1158 if (inet_sk(sk)->inet_num == IPPROTO_RAW)
1161 ip6_ra_control(sk, -1); 1159 ip6_ra_control(sk, -1);
1162 ip6mr_sk_done(sk); 1160 ip6mr_sk_done(sk);
1163 sk_common_release(sk); 1161 sk_common_release(sk);
@@ -1176,7 +1174,7 @@ static int rawv6_init_sk(struct sock *sk)
1176{ 1174{
1177 struct raw6_sock *rp = raw6_sk(sk); 1175 struct raw6_sock *rp = raw6_sk(sk);
1178 1176
1179 switch (inet_sk(sk)->num) { 1177 switch (inet_sk(sk)->inet_num) {
1180 case IPPROTO_ICMPV6: 1178 case IPPROTO_ICMPV6:
1181 rp->checksum = 1; 1179 rp->checksum = 1;
1182 rp->offset = 2; 1180 rp->offset = 2;
@@ -1226,7 +1224,7 @@ static void raw6_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
1226 dest = &np->daddr; 1224 dest = &np->daddr;
1227 src = &np->rcv_saddr; 1225 src = &np->rcv_saddr;
1228 destp = 0; 1226 destp = 0;
1229 srcp = inet_sk(sp)->num; 1227 srcp = inet_sk(sp)->inet_num;
1230 seq_printf(seq, 1228 seq_printf(seq,
1231 "%4d: %08X%08X%08X%08X:%04X %08X%08X%08X%08X:%04X " 1229 "%4d: %08X%08X%08X%08X:%04X %08X%08X%08X%08X:%04X "
1232 "%02X %08X:%08X %02X:%08lX %08X %5d %8d %lu %d %p %d\n", 1230 "%02X %08X:%08X %02X:%08lX %08X %5d %8d %lu %d %p %d\n",
@@ -1278,7 +1276,7 @@ static const struct file_operations raw6_seq_fops = {
1278 .release = seq_release_net, 1276 .release = seq_release_net,
1279}; 1277};
1280 1278
1281static int raw6_init_net(struct net *net) 1279static int __net_init raw6_init_net(struct net *net)
1282{ 1280{
1283 if (!proc_net_fops_create(net, "raw6", S_IRUGO, &raw6_seq_fops)) 1281 if (!proc_net_fops_create(net, "raw6", S_IRUGO, &raw6_seq_fops))
1284 return -ENOMEM; 1282 return -ENOMEM;
@@ -1286,7 +1284,7 @@ static int raw6_init_net(struct net *net)
1286 return 0; 1284 return 0;
1287} 1285}
1288 1286
1289static void raw6_exit_net(struct net *net) 1287static void __net_exit raw6_exit_net(struct net *net)
1290{ 1288{
1291 proc_net_remove(net, "raw6"); 1289 proc_net_remove(net, "raw6");
1292} 1290}
@@ -1338,7 +1336,6 @@ static struct inet_protosw rawv6_protosw = {
1338 .protocol = IPPROTO_IP, /* wild card */ 1336 .protocol = IPPROTO_IP, /* wild card */
1339 .prot = &rawv6_prot, 1337 .prot = &rawv6_prot,
1340 .ops = &inet6_sockraw_ops, 1338 .ops = &inet6_sockraw_ops,
1341 .capability = CAP_NET_RAW,
1342 .no_check = UDP_CSUM_DEFAULT, 1339 .no_check = UDP_CSUM_DEFAULT,
1343 .flags = INET_PROTOSW_REUSE, 1340 .flags = INET_PROTOSW_REUSE,
1344}; 1341};
diff --git a/net/ipv6/reassembly.c b/net/ipv6/reassembly.c
index da5bd0ed83df..6d4292ff5854 100644
--- a/net/ipv6/reassembly.c
+++ b/net/ipv6/reassembly.c
@@ -41,6 +41,7 @@
41#include <linux/random.h> 41#include <linux/random.h>
42#include <linux/jhash.h> 42#include <linux/jhash.h>
43#include <linux/skbuff.h> 43#include <linux/skbuff.h>
44#include <linux/slab.h>
44 45
45#include <net/sock.h> 46#include <net/sock.h>
46#include <net/snmp.h> 47#include <net/snmp.h>
@@ -72,6 +73,7 @@ struct frag_queue
72 struct inet_frag_queue q; 73 struct inet_frag_queue q;
73 74
74 __be32 id; /* fragment id */ 75 __be32 id; /* fragment id */
76 u32 user;
75 struct in6_addr saddr; 77 struct in6_addr saddr;
76 struct in6_addr daddr; 78 struct in6_addr daddr;
77 79
@@ -141,7 +143,7 @@ int ip6_frag_match(struct inet_frag_queue *q, void *a)
141 struct ip6_create_arg *arg = a; 143 struct ip6_create_arg *arg = a;
142 144
143 fq = container_of(q, struct frag_queue, q); 145 fq = container_of(q, struct frag_queue, q);
144 return (fq->id == arg->id && 146 return (fq->id == arg->id && fq->user == arg->user &&
145 ipv6_addr_equal(&fq->saddr, arg->src) && 147 ipv6_addr_equal(&fq->saddr, arg->src) &&
146 ipv6_addr_equal(&fq->daddr, arg->dst)); 148 ipv6_addr_equal(&fq->daddr, arg->dst));
147} 149}
@@ -163,6 +165,7 @@ void ip6_frag_init(struct inet_frag_queue *q, void *a)
163 struct ip6_create_arg *arg = a; 165 struct ip6_create_arg *arg = a;
164 166
165 fq->id = arg->id; 167 fq->id = arg->id;
168 fq->user = arg->user;
166 ipv6_addr_copy(&fq->saddr, arg->src); 169 ipv6_addr_copy(&fq->saddr, arg->src);
167 ipv6_addr_copy(&fq->daddr, arg->dst); 170 ipv6_addr_copy(&fq->daddr, arg->dst);
168} 171}
@@ -208,18 +211,17 @@ static void ip6_frag_expire(unsigned long data)
208 fq_kill(fq); 211 fq_kill(fq);
209 212
210 net = container_of(fq->q.net, struct net, ipv6.frags); 213 net = container_of(fq->q.net, struct net, ipv6.frags);
211 dev = dev_get_by_index(net, fq->iif); 214 rcu_read_lock();
215 dev = dev_get_by_index_rcu(net, fq->iif);
212 if (!dev) 216 if (!dev)
213 goto out; 217 goto out_rcu_unlock;
214 218
215 rcu_read_lock();
216 IP6_INC_STATS_BH(net, __in6_dev_get(dev), IPSTATS_MIB_REASMTIMEOUT); 219 IP6_INC_STATS_BH(net, __in6_dev_get(dev), IPSTATS_MIB_REASMTIMEOUT);
217 IP6_INC_STATS_BH(net, __in6_dev_get(dev), IPSTATS_MIB_REASMFAILS); 220 IP6_INC_STATS_BH(net, __in6_dev_get(dev), IPSTATS_MIB_REASMFAILS);
218 rcu_read_unlock();
219 221
220 /* Don't send error if the first segment did not arrive. */ 222 /* Don't send error if the first segment did not arrive. */
221 if (!(fq->q.last_in & INET_FRAG_FIRST_IN) || !fq->q.fragments) 223 if (!(fq->q.last_in & INET_FRAG_FIRST_IN) || !fq->q.fragments)
222 goto out; 224 goto out_rcu_unlock;
223 225
224 /* 226 /*
225 But use as source device on which LAST ARRIVED 227 But use as source device on which LAST ARRIVED
@@ -227,23 +229,23 @@ static void ip6_frag_expire(unsigned long data)
227 pointer directly, device might already disappeared. 229 pointer directly, device might already disappeared.
228 */ 230 */
229 fq->q.fragments->dev = dev; 231 fq->q.fragments->dev = dev;
230 icmpv6_send(fq->q.fragments, ICMPV6_TIME_EXCEED, ICMPV6_EXC_FRAGTIME, 0, dev); 232 icmpv6_send(fq->q.fragments, ICMPV6_TIME_EXCEED, ICMPV6_EXC_FRAGTIME, 0);
233out_rcu_unlock:
234 rcu_read_unlock();
231out: 235out:
232 if (dev)
233 dev_put(dev);
234 spin_unlock(&fq->q.lock); 236 spin_unlock(&fq->q.lock);
235 fq_put(fq); 237 fq_put(fq);
236} 238}
237 239
238static __inline__ struct frag_queue * 240static __inline__ struct frag_queue *
239fq_find(struct net *net, __be32 id, struct in6_addr *src, struct in6_addr *dst, 241fq_find(struct net *net, __be32 id, struct in6_addr *src, struct in6_addr *dst)
240 struct inet6_dev *idev)
241{ 242{
242 struct inet_frag_queue *q; 243 struct inet_frag_queue *q;
243 struct ip6_create_arg arg; 244 struct ip6_create_arg arg;
244 unsigned int hash; 245 unsigned int hash;
245 246
246 arg.id = id; 247 arg.id = id;
248 arg.user = IP6_DEFRAG_LOCAL_DELIVER;
247 arg.src = src; 249 arg.src = src;
248 arg.dst = dst; 250 arg.dst = dst;
249 251
@@ -252,13 +254,9 @@ fq_find(struct net *net, __be32 id, struct in6_addr *src, struct in6_addr *dst,
252 254
253 q = inet_frag_find(&net->ipv6.frags, &ip6_frags, &arg, hash); 255 q = inet_frag_find(&net->ipv6.frags, &ip6_frags, &arg, hash);
254 if (q == NULL) 256 if (q == NULL)
255 goto oom; 257 return NULL;
256 258
257 return container_of(q, struct frag_queue, q); 259 return container_of(q, struct frag_queue, q);
258
259oom:
260 IP6_INC_STATS_BH(net, idev, IPSTATS_MIB_REASMFAILS);
261 return NULL;
262} 260}
263 261
264static int ip6_frag_queue(struct frag_queue *fq, struct sk_buff *skb, 262static int ip6_frag_queue(struct frag_queue *fq, struct sk_buff *skb,
@@ -604,8 +602,8 @@ static int ipv6_frag_rcv(struct sk_buff *skb)
604 if (atomic_read(&net->ipv6.frags.mem) > net->ipv6.frags.high_thresh) 602 if (atomic_read(&net->ipv6.frags.mem) > net->ipv6.frags.high_thresh)
605 ip6_evictor(net, ip6_dst_idev(skb_dst(skb))); 603 ip6_evictor(net, ip6_dst_idev(skb_dst(skb)));
606 604
607 if ((fq = fq_find(net, fhdr->identification, &hdr->saddr, &hdr->daddr, 605 fq = fq_find(net, fhdr->identification, &hdr->saddr, &hdr->daddr);
608 ip6_dst_idev(skb_dst(skb)))) != NULL) { 606 if (fq != NULL) {
609 int ret; 607 int ret;
610 608
611 spin_lock(&fq->q.lock); 609 spin_lock(&fq->q.lock);
@@ -636,7 +634,6 @@ static const struct inet6_protocol frag_protocol =
636#ifdef CONFIG_SYSCTL 634#ifdef CONFIG_SYSCTL
637static struct ctl_table ip6_frags_ns_ctl_table[] = { 635static struct ctl_table ip6_frags_ns_ctl_table[] = {
638 { 636 {
639 .ctl_name = NET_IPV6_IP6FRAG_HIGH_THRESH,
640 .procname = "ip6frag_high_thresh", 637 .procname = "ip6frag_high_thresh",
641 .data = &init_net.ipv6.frags.high_thresh, 638 .data = &init_net.ipv6.frags.high_thresh,
642 .maxlen = sizeof(int), 639 .maxlen = sizeof(int),
@@ -644,7 +641,6 @@ static struct ctl_table ip6_frags_ns_ctl_table[] = {
644 .proc_handler = proc_dointvec 641 .proc_handler = proc_dointvec
645 }, 642 },
646 { 643 {
647 .ctl_name = NET_IPV6_IP6FRAG_LOW_THRESH,
648 .procname = "ip6frag_low_thresh", 644 .procname = "ip6frag_low_thresh",
649 .data = &init_net.ipv6.frags.low_thresh, 645 .data = &init_net.ipv6.frags.low_thresh,
650 .maxlen = sizeof(int), 646 .maxlen = sizeof(int),
@@ -652,37 +648,33 @@ static struct ctl_table ip6_frags_ns_ctl_table[] = {
652 .proc_handler = proc_dointvec 648 .proc_handler = proc_dointvec
653 }, 649 },
654 { 650 {
655 .ctl_name = NET_IPV6_IP6FRAG_TIME,
656 .procname = "ip6frag_time", 651 .procname = "ip6frag_time",
657 .data = &init_net.ipv6.frags.timeout, 652 .data = &init_net.ipv6.frags.timeout,
658 .maxlen = sizeof(int), 653 .maxlen = sizeof(int),
659 .mode = 0644, 654 .mode = 0644,
660 .proc_handler = proc_dointvec_jiffies, 655 .proc_handler = proc_dointvec_jiffies,
661 .strategy = sysctl_jiffies,
662 }, 656 },
663 { } 657 { }
664}; 658};
665 659
666static struct ctl_table ip6_frags_ctl_table[] = { 660static struct ctl_table ip6_frags_ctl_table[] = {
667 { 661 {
668 .ctl_name = NET_IPV6_IP6FRAG_SECRET_INTERVAL,
669 .procname = "ip6frag_secret_interval", 662 .procname = "ip6frag_secret_interval",
670 .data = &ip6_frags.secret_interval, 663 .data = &ip6_frags.secret_interval,
671 .maxlen = sizeof(int), 664 .maxlen = sizeof(int),
672 .mode = 0644, 665 .mode = 0644,
673 .proc_handler = proc_dointvec_jiffies, 666 .proc_handler = proc_dointvec_jiffies,
674 .strategy = sysctl_jiffies
675 }, 667 },
676 { } 668 { }
677}; 669};
678 670
679static int ip6_frags_ns_sysctl_register(struct net *net) 671static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
680{ 672{
681 struct ctl_table *table; 673 struct ctl_table *table;
682 struct ctl_table_header *hdr; 674 struct ctl_table_header *hdr;
683 675
684 table = ip6_frags_ns_ctl_table; 676 table = ip6_frags_ns_ctl_table;
685 if (net != &init_net) { 677 if (!net_eq(net, &init_net)) {
686 table = kmemdup(table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL); 678 table = kmemdup(table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
687 if (table == NULL) 679 if (table == NULL)
688 goto err_alloc; 680 goto err_alloc;
@@ -700,19 +692,20 @@ static int ip6_frags_ns_sysctl_register(struct net *net)
700 return 0; 692 return 0;
701 693
702err_reg: 694err_reg:
703 if (net != &init_net) 695 if (!net_eq(net, &init_net))
704 kfree(table); 696 kfree(table);
705err_alloc: 697err_alloc:
706 return -ENOMEM; 698 return -ENOMEM;
707} 699}
708 700
709static void ip6_frags_ns_sysctl_unregister(struct net *net) 701static void __net_exit ip6_frags_ns_sysctl_unregister(struct net *net)
710{ 702{
711 struct ctl_table *table; 703 struct ctl_table *table;
712 704
713 table = net->ipv6.sysctl.frags_hdr->ctl_table_arg; 705 table = net->ipv6.sysctl.frags_hdr->ctl_table_arg;
714 unregister_net_sysctl_table(net->ipv6.sysctl.frags_hdr); 706 unregister_net_sysctl_table(net->ipv6.sysctl.frags_hdr);
715 kfree(table); 707 if (!net_eq(net, &init_net))
708 kfree(table);
716} 709}
717 710
718static struct ctl_table_header *ip6_ctl_header; 711static struct ctl_table_header *ip6_ctl_header;
@@ -748,10 +741,10 @@ static inline void ip6_frags_sysctl_unregister(void)
748} 741}
749#endif 742#endif
750 743
751static int ipv6_frags_init_net(struct net *net) 744static int __net_init ipv6_frags_init_net(struct net *net)
752{ 745{
753 net->ipv6.frags.high_thresh = 256 * 1024; 746 net->ipv6.frags.high_thresh = IPV6_FRAG_HIGH_THRESH;
754 net->ipv6.frags.low_thresh = 192 * 1024; 747 net->ipv6.frags.low_thresh = IPV6_FRAG_LOW_THRESH;
755 net->ipv6.frags.timeout = IPV6_FRAG_TIMEOUT; 748 net->ipv6.frags.timeout = IPV6_FRAG_TIMEOUT;
756 749
757 inet_frags_init_net(&net->ipv6.frags); 750 inet_frags_init_net(&net->ipv6.frags);
@@ -759,7 +752,7 @@ static int ipv6_frags_init_net(struct net *net)
759 return ip6_frags_ns_sysctl_register(net); 752 return ip6_frags_ns_sysctl_register(net);
760} 753}
761 754
762static void ipv6_frags_exit_net(struct net *net) 755static void __net_exit ipv6_frags_exit_net(struct net *net)
763{ 756{
764 ip6_frags_ns_sysctl_unregister(net); 757 ip6_frags_ns_sysctl_unregister(net);
765 inet_frags_exit_net(&net->ipv6.frags, &ip6_frags); 758 inet_frags_exit_net(&net->ipv6.frags, &ip6_frags);
diff --git a/net/ipv6/route.c b/net/ipv6/route.c
index d6fe7646a8ff..05ebd7833043 100644
--- a/net/ipv6/route.c
+++ b/net/ipv6/route.c
@@ -40,6 +40,7 @@
40#include <linux/proc_fs.h> 40#include <linux/proc_fs.h>
41#include <linux/seq_file.h> 41#include <linux/seq_file.h>
42#include <linux/nsproxy.h> 42#include <linux/nsproxy.h>
43#include <linux/slab.h>
43#include <net/net_namespace.h> 44#include <net/net_namespace.h>
44#include <net/snmp.h> 45#include <net/snmp.h>
45#include <net/ipv6.h> 46#include <net/ipv6.h>
@@ -814,20 +815,13 @@ struct dst_entry * ip6_route_output(struct net *net, struct sock *sk,
814{ 815{
815 int flags = 0; 816 int flags = 0;
816 817
817 if (rt6_need_strict(&fl->fl6_dst)) 818 if (fl->oif || rt6_need_strict(&fl->fl6_dst))
818 flags |= RT6_LOOKUP_F_IFACE; 819 flags |= RT6_LOOKUP_F_IFACE;
819 820
820 if (!ipv6_addr_any(&fl->fl6_src)) 821 if (!ipv6_addr_any(&fl->fl6_src))
821 flags |= RT6_LOOKUP_F_HAS_SADDR; 822 flags |= RT6_LOOKUP_F_HAS_SADDR;
822 else if (sk) { 823 else if (sk)
823 unsigned int prefs = inet6_sk(sk)->srcprefs; 824 flags |= rt6_srcprefs2flags(inet6_sk(sk)->srcprefs);
824 if (prefs & IPV6_PREFER_SRC_TMP)
825 flags |= RT6_LOOKUP_F_SRCPREF_TMP;
826 if (prefs & IPV6_PREFER_SRC_PUBLIC)
827 flags |= RT6_LOOKUP_F_SRCPREF_PUBLIC;
828 if (prefs & IPV6_PREFER_SRC_COA)
829 flags |= RT6_LOOKUP_F_SRCPREF_COA;
830 }
831 825
832 return fib6_rule_lookup(net, fl, flags, ip6_pol_route_output); 826 return fib6_rule_lookup(net, fl, flags, ip6_pol_route_output);
833} 827}
@@ -886,7 +880,7 @@ static struct dst_entry *ip6_dst_check(struct dst_entry *dst, u32 cookie)
886 880
887 rt = (struct rt6_info *) dst; 881 rt = (struct rt6_info *) dst;
888 882
889 if (rt && rt->rt6i_node && (rt->rt6i_node->fn_sernum == cookie)) 883 if (rt->rt6i_node && (rt->rt6i_node->fn_sernum == cookie))
890 return dst; 884 return dst;
891 885
892 return NULL; 886 return NULL;
@@ -897,19 +891,24 @@ static struct dst_entry *ip6_negative_advice(struct dst_entry *dst)
897 struct rt6_info *rt = (struct rt6_info *) dst; 891 struct rt6_info *rt = (struct rt6_info *) dst;
898 892
899 if (rt) { 893 if (rt) {
900 if (rt->rt6i_flags & RTF_CACHE) 894 if (rt->rt6i_flags & RTF_CACHE) {
901 ip6_del_rt(rt); 895 if (rt6_check_expired(rt)) {
902 else 896 ip6_del_rt(rt);
897 dst = NULL;
898 }
899 } else {
903 dst_release(dst); 900 dst_release(dst);
901 dst = NULL;
902 }
904 } 903 }
905 return NULL; 904 return dst;
906} 905}
907 906
908static void ip6_link_failure(struct sk_buff *skb) 907static void ip6_link_failure(struct sk_buff *skb)
909{ 908{
910 struct rt6_info *rt; 909 struct rt6_info *rt;
911 910
912 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_ADDR_UNREACH, 0, skb->dev); 911 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_ADDR_UNREACH, 0);
913 912
914 rt = (struct rt6_info *) skb_dst(skb); 913 rt = (struct rt6_info *) skb_dst(skb);
915 if (rt) { 914 if (rt) {
@@ -1471,9 +1470,10 @@ static struct rt6_info *ip6_route_redirect(struct in6_addr *dest,
1471 }, 1470 },
1472 }, 1471 },
1473 }, 1472 },
1474 .gateway = *gateway,
1475 }; 1473 };
1476 1474
1475 ipv6_addr_copy(&rdfl.gateway, gateway);
1476
1477 if (rt6_need_strict(dest)) 1477 if (rt6_need_strict(dest))
1478 flags |= RT6_LOOKUP_F_IFACE; 1478 flags |= RT6_LOOKUP_F_IFACE;
1479 1479
@@ -1872,7 +1872,7 @@ static int ip6_pkt_drop(struct sk_buff *skb, u8 code, int ipstats_mib_noroutes)
1872 switch (ipstats_mib_noroutes) { 1872 switch (ipstats_mib_noroutes) {
1873 case IPSTATS_MIB_INNOROUTES: 1873 case IPSTATS_MIB_INNOROUTES:
1874 type = ipv6_addr_type(&ipv6_hdr(skb)->daddr); 1874 type = ipv6_addr_type(&ipv6_hdr(skb)->daddr);
1875 if (type == IPV6_ADDR_ANY || type == IPV6_ADDR_RESERVED) { 1875 if (type == IPV6_ADDR_ANY) {
1876 IP6_INC_STATS(dev_net(dst->dev), ip6_dst_idev(dst), 1876 IP6_INC_STATS(dev_net(dst->dev), ip6_dst_idev(dst),
1877 IPSTATS_MIB_INADDRERRORS); 1877 IPSTATS_MIB_INADDRERRORS);
1878 break; 1878 break;
@@ -1883,7 +1883,7 @@ static int ip6_pkt_drop(struct sk_buff *skb, u8 code, int ipstats_mib_noroutes)
1883 ipstats_mib_noroutes); 1883 ipstats_mib_noroutes);
1884 break; 1884 break;
1885 } 1885 }
1886 icmpv6_send(skb, ICMPV6_DEST_UNREACH, code, 0, skb->dev); 1886 icmpv6_send(skb, ICMPV6_DEST_UNREACH, code, 0);
1887 kfree_skb(skb); 1887 kfree_skb(skb);
1888 return 0; 1888 return 0;
1889} 1889}
@@ -2546,7 +2546,6 @@ ctl_table ipv6_route_table_template[] = {
2546 .proc_handler = ipv6_sysctl_rtcache_flush 2546 .proc_handler = ipv6_sysctl_rtcache_flush
2547 }, 2547 },
2548 { 2548 {
2549 .ctl_name = NET_IPV6_ROUTE_GC_THRESH,
2550 .procname = "gc_thresh", 2549 .procname = "gc_thresh",
2551 .data = &ip6_dst_ops_template.gc_thresh, 2550 .data = &ip6_dst_ops_template.gc_thresh,
2552 .maxlen = sizeof(int), 2551 .maxlen = sizeof(int),
@@ -2554,7 +2553,6 @@ ctl_table ipv6_route_table_template[] = {
2554 .proc_handler = proc_dointvec, 2553 .proc_handler = proc_dointvec,
2555 }, 2554 },
2556 { 2555 {
2557 .ctl_name = NET_IPV6_ROUTE_MAX_SIZE,
2558 .procname = "max_size", 2556 .procname = "max_size",
2559 .data = &init_net.ipv6.sysctl.ip6_rt_max_size, 2557 .data = &init_net.ipv6.sysctl.ip6_rt_max_size,
2560 .maxlen = sizeof(int), 2558 .maxlen = sizeof(int),
@@ -2562,72 +2560,58 @@ ctl_table ipv6_route_table_template[] = {
2562 .proc_handler = proc_dointvec, 2560 .proc_handler = proc_dointvec,
2563 }, 2561 },
2564 { 2562 {
2565 .ctl_name = NET_IPV6_ROUTE_GC_MIN_INTERVAL,
2566 .procname = "gc_min_interval", 2563 .procname = "gc_min_interval",
2567 .data = &init_net.ipv6.sysctl.ip6_rt_gc_min_interval, 2564 .data = &init_net.ipv6.sysctl.ip6_rt_gc_min_interval,
2568 .maxlen = sizeof(int), 2565 .maxlen = sizeof(int),
2569 .mode = 0644, 2566 .mode = 0644,
2570 .proc_handler = proc_dointvec_jiffies, 2567 .proc_handler = proc_dointvec_jiffies,
2571 .strategy = sysctl_jiffies,
2572 }, 2568 },
2573 { 2569 {
2574 .ctl_name = NET_IPV6_ROUTE_GC_TIMEOUT,
2575 .procname = "gc_timeout", 2570 .procname = "gc_timeout",
2576 .data = &init_net.ipv6.sysctl.ip6_rt_gc_timeout, 2571 .data = &init_net.ipv6.sysctl.ip6_rt_gc_timeout,
2577 .maxlen = sizeof(int), 2572 .maxlen = sizeof(int),
2578 .mode = 0644, 2573 .mode = 0644,
2579 .proc_handler = proc_dointvec_jiffies, 2574 .proc_handler = proc_dointvec_jiffies,
2580 .strategy = sysctl_jiffies,
2581 }, 2575 },
2582 { 2576 {
2583 .ctl_name = NET_IPV6_ROUTE_GC_INTERVAL,
2584 .procname = "gc_interval", 2577 .procname = "gc_interval",
2585 .data = &init_net.ipv6.sysctl.ip6_rt_gc_interval, 2578 .data = &init_net.ipv6.sysctl.ip6_rt_gc_interval,
2586 .maxlen = sizeof(int), 2579 .maxlen = sizeof(int),
2587 .mode = 0644, 2580 .mode = 0644,
2588 .proc_handler = proc_dointvec_jiffies, 2581 .proc_handler = proc_dointvec_jiffies,
2589 .strategy = sysctl_jiffies,
2590 }, 2582 },
2591 { 2583 {
2592 .ctl_name = NET_IPV6_ROUTE_GC_ELASTICITY,
2593 .procname = "gc_elasticity", 2584 .procname = "gc_elasticity",
2594 .data = &init_net.ipv6.sysctl.ip6_rt_gc_elasticity, 2585 .data = &init_net.ipv6.sysctl.ip6_rt_gc_elasticity,
2595 .maxlen = sizeof(int), 2586 .maxlen = sizeof(int),
2596 .mode = 0644, 2587 .mode = 0644,
2597 .proc_handler = proc_dointvec_jiffies, 2588 .proc_handler = proc_dointvec_jiffies,
2598 .strategy = sysctl_jiffies,
2599 }, 2589 },
2600 { 2590 {
2601 .ctl_name = NET_IPV6_ROUTE_MTU_EXPIRES,
2602 .procname = "mtu_expires", 2591 .procname = "mtu_expires",
2603 .data = &init_net.ipv6.sysctl.ip6_rt_mtu_expires, 2592 .data = &init_net.ipv6.sysctl.ip6_rt_mtu_expires,
2604 .maxlen = sizeof(int), 2593 .maxlen = sizeof(int),
2605 .mode = 0644, 2594 .mode = 0644,
2606 .proc_handler = proc_dointvec_jiffies, 2595 .proc_handler = proc_dointvec_jiffies,
2607 .strategy = sysctl_jiffies,
2608 }, 2596 },
2609 { 2597 {
2610 .ctl_name = NET_IPV6_ROUTE_MIN_ADVMSS,
2611 .procname = "min_adv_mss", 2598 .procname = "min_adv_mss",
2612 .data = &init_net.ipv6.sysctl.ip6_rt_min_advmss, 2599 .data = &init_net.ipv6.sysctl.ip6_rt_min_advmss,
2613 .maxlen = sizeof(int), 2600 .maxlen = sizeof(int),
2614 .mode = 0644, 2601 .mode = 0644,
2615 .proc_handler = proc_dointvec_jiffies, 2602 .proc_handler = proc_dointvec_jiffies,
2616 .strategy = sysctl_jiffies,
2617 }, 2603 },
2618 { 2604 {
2619 .ctl_name = NET_IPV6_ROUTE_GC_MIN_INTERVAL_MS,
2620 .procname = "gc_min_interval_ms", 2605 .procname = "gc_min_interval_ms",
2621 .data = &init_net.ipv6.sysctl.ip6_rt_gc_min_interval, 2606 .data = &init_net.ipv6.sysctl.ip6_rt_gc_min_interval,
2622 .maxlen = sizeof(int), 2607 .maxlen = sizeof(int),
2623 .mode = 0644, 2608 .mode = 0644,
2624 .proc_handler = proc_dointvec_ms_jiffies, 2609 .proc_handler = proc_dointvec_ms_jiffies,
2625 .strategy = sysctl_ms_jiffies,
2626 }, 2610 },
2627 { .ctl_name = 0 } 2611 { }
2628}; 2612};
2629 2613
2630struct ctl_table *ipv6_route_sysctl_init(struct net *net) 2614struct ctl_table * __net_init ipv6_route_sysctl_init(struct net *net)
2631{ 2615{
2632 struct ctl_table *table; 2616 struct ctl_table *table;
2633 2617
@@ -2645,13 +2629,14 @@ struct ctl_table *ipv6_route_sysctl_init(struct net *net)
2645 table[6].data = &net->ipv6.sysctl.ip6_rt_gc_elasticity; 2629 table[6].data = &net->ipv6.sysctl.ip6_rt_gc_elasticity;
2646 table[7].data = &net->ipv6.sysctl.ip6_rt_mtu_expires; 2630 table[7].data = &net->ipv6.sysctl.ip6_rt_mtu_expires;
2647 table[8].data = &net->ipv6.sysctl.ip6_rt_min_advmss; 2631 table[8].data = &net->ipv6.sysctl.ip6_rt_min_advmss;
2632 table[9].data = &net->ipv6.sysctl.ip6_rt_gc_min_interval;
2648 } 2633 }
2649 2634
2650 return table; 2635 return table;
2651} 2636}
2652#endif 2637#endif
2653 2638
2654static int ip6_route_net_init(struct net *net) 2639static int __net_init ip6_route_net_init(struct net *net)
2655{ 2640{
2656 int ret = -ENOMEM; 2641 int ret = -ENOMEM;
2657 2642
@@ -2716,7 +2701,7 @@ out_ip6_dst_ops:
2716 goto out; 2701 goto out;
2717} 2702}
2718 2703
2719static void ip6_route_net_exit(struct net *net) 2704static void __net_exit ip6_route_net_exit(struct net *net)
2720{ 2705{
2721#ifdef CONFIG_PROC_FS 2706#ifdef CONFIG_PROC_FS
2722 proc_net_remove(net, "ipv6_route"); 2707 proc_net_remove(net, "ipv6_route");
diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
index dbd19a78ca73..5abae10cd884 100644
--- a/net/ipv6/sit.c
+++ b/net/ipv6/sit.c
@@ -28,6 +28,7 @@
28#include <linux/netdevice.h> 28#include <linux/netdevice.h>
29#include <linux/if_arp.h> 29#include <linux/if_arp.h>
30#include <linux/icmp.h> 30#include <linux/icmp.h>
31#include <linux/slab.h>
31#include <asm/uaccess.h> 32#include <asm/uaccess.h>
32#include <linux/init.h> 33#include <linux/init.h>
33#include <linux/netfilter_ipv4.h> 34#include <linux/netfilter_ipv4.h>
@@ -62,11 +63,10 @@
62#define HASH_SIZE 16 63#define HASH_SIZE 16
63#define HASH(addr) (((__force u32)addr^((__force u32)addr>>4))&0xF) 64#define HASH(addr) (((__force u32)addr^((__force u32)addr>>4))&0xF)
64 65
65static void ipip6_fb_tunnel_init(struct net_device *dev);
66static void 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 __read_mostly;
70struct sit_net { 70struct sit_net {
71 struct ip_tunnel *tunnels_r_l[HASH_SIZE]; 71 struct ip_tunnel *tunnels_r_l[HASH_SIZE];
72 struct ip_tunnel *tunnels_r[HASH_SIZE]; 72 struct ip_tunnel *tunnels_r[HASH_SIZE];
@@ -77,8 +77,17 @@ struct sit_net {
77 struct net_device *fb_tunnel_dev; 77 struct net_device *fb_tunnel_dev;
78}; 78};
79 79
80static DEFINE_RWLOCK(ipip6_lock); 80/*
81 * Locking : hash tables are protected by RCU and a spinlock
82 */
83static DEFINE_SPINLOCK(ipip6_lock);
84
85#define for_each_ip_tunnel_rcu(start) \
86 for (t = rcu_dereference(start); t; t = rcu_dereference(t->next))
81 87
88/*
89 * Must be invoked with rcu_read_lock
90 */
82static struct ip_tunnel * ipip6_tunnel_lookup(struct net *net, 91static struct ip_tunnel * ipip6_tunnel_lookup(struct net *net,
83 struct net_device *dev, __be32 remote, __be32 local) 92 struct net_device *dev, __be32 remote, __be32 local)
84{ 93{
@@ -87,26 +96,26 @@ static struct ip_tunnel * ipip6_tunnel_lookup(struct net *net,
87 struct ip_tunnel *t; 96 struct ip_tunnel *t;
88 struct sit_net *sitn = net_generic(net, sit_net_id); 97 struct sit_net *sitn = net_generic(net, sit_net_id);
89 98
90 for (t = sitn->tunnels_r_l[h0^h1]; t; t = t->next) { 99 for_each_ip_tunnel_rcu(sitn->tunnels_r_l[h0 ^ h1]) {
91 if (local == t->parms.iph.saddr && 100 if (local == t->parms.iph.saddr &&
92 remote == t->parms.iph.daddr && 101 remote == t->parms.iph.daddr &&
93 (!dev || !t->parms.link || dev->iflink == t->parms.link) && 102 (!dev || !t->parms.link || dev->iflink == t->parms.link) &&
94 (t->dev->flags & IFF_UP)) 103 (t->dev->flags & IFF_UP))
95 return t; 104 return t;
96 } 105 }
97 for (t = sitn->tunnels_r[h0]; t; t = t->next) { 106 for_each_ip_tunnel_rcu(sitn->tunnels_r[h0]) {
98 if (remote == t->parms.iph.daddr && 107 if (remote == t->parms.iph.daddr &&
99 (!dev || !t->parms.link || dev->iflink == t->parms.link) && 108 (!dev || !t->parms.link || dev->iflink == t->parms.link) &&
100 (t->dev->flags & IFF_UP)) 109 (t->dev->flags & IFF_UP))
101 return t; 110 return t;
102 } 111 }
103 for (t = sitn->tunnels_l[h1]; t; t = t->next) { 112 for_each_ip_tunnel_rcu(sitn->tunnels_l[h1]) {
104 if (local == t->parms.iph.saddr && 113 if (local == t->parms.iph.saddr &&
105 (!dev || !t->parms.link || dev->iflink == t->parms.link) && 114 (!dev || !t->parms.link || dev->iflink == t->parms.link) &&
106 (t->dev->flags & IFF_UP)) 115 (t->dev->flags & IFF_UP))
107 return t; 116 return t;
108 } 117 }
109 t = sitn->tunnels_wc[0]; 118 t = rcu_dereference(sitn->tunnels_wc[0]);
110 if ((t != NULL) && (t->dev->flags & IFF_UP)) 119 if ((t != NULL) && (t->dev->flags & IFF_UP))
111 return t; 120 return t;
112 return NULL; 121 return NULL;
@@ -143,9 +152,9 @@ static void ipip6_tunnel_unlink(struct sit_net *sitn, struct ip_tunnel *t)
143 152
144 for (tp = ipip6_bucket(sitn, t); *tp; tp = &(*tp)->next) { 153 for (tp = ipip6_bucket(sitn, t); *tp; tp = &(*tp)->next) {
145 if (t == *tp) { 154 if (t == *tp) {
146 write_lock_bh(&ipip6_lock); 155 spin_lock_bh(&ipip6_lock);
147 *tp = t->next; 156 *tp = t->next;
148 write_unlock_bh(&ipip6_lock); 157 spin_unlock_bh(&ipip6_lock);
149 break; 158 break;
150 } 159 }
151 } 160 }
@@ -155,10 +164,27 @@ static void ipip6_tunnel_link(struct sit_net *sitn, struct ip_tunnel *t)
155{ 164{
156 struct ip_tunnel **tp = ipip6_bucket(sitn, t); 165 struct ip_tunnel **tp = ipip6_bucket(sitn, t);
157 166
167 spin_lock_bh(&ipip6_lock);
158 t->next = *tp; 168 t->next = *tp;
159 write_lock_bh(&ipip6_lock); 169 rcu_assign_pointer(*tp, t);
160 *tp = t; 170 spin_unlock_bh(&ipip6_lock);
161 write_unlock_bh(&ipip6_lock); 171}
172
173static void ipip6_tunnel_clone_6rd(struct net_device *dev, struct sit_net *sitn)
174{
175#ifdef CONFIG_IPV6_SIT_6RD
176 struct ip_tunnel *t = netdev_priv(dev);
177
178 if (t->dev == sitn->fb_tunnel_dev) {
179 ipv6_addr_set(&t->ip6rd.prefix, htonl(0x20020000), 0, 0, 0);
180 t->ip6rd.relay_prefix = 0;
181 t->ip6rd.prefixlen = 16;
182 t->ip6rd.relay_prefixlen = 0;
183 } else {
184 struct ip_tunnel *t0 = netdev_priv(sitn->fb_tunnel_dev);
185 memcpy(&t->ip6rd, &t0->ip6rd, sizeof(t->ip6rd));
186 }
187#endif
162} 188}
163 189
164static struct ip_tunnel * ipip6_tunnel_locate(struct net *net, 190static struct ip_tunnel * ipip6_tunnel_locate(struct net *net,
@@ -204,6 +230,7 @@ static struct ip_tunnel * ipip6_tunnel_locate(struct net *net,
204 230
205 nt->parms = *parms; 231 nt->parms = *parms;
206 ipip6_tunnel_init(dev); 232 ipip6_tunnel_init(dev);
233 ipip6_tunnel_clone_6rd(dev, sitn);
207 234
208 if (parms->i_flags & SIT_ISATAP) 235 if (parms->i_flags & SIT_ISATAP)
209 dev->priv_flags |= IFF_ISATAP; 236 dev->priv_flags |= IFF_ISATAP;
@@ -222,15 +249,22 @@ failed:
222 return NULL; 249 return NULL;
223} 250}
224 251
252static DEFINE_SPINLOCK(ipip6_prl_lock);
253
254#define for_each_prl_rcu(start) \
255 for (prl = rcu_dereference(start); \
256 prl; \
257 prl = rcu_dereference(prl->next))
258
225static struct ip_tunnel_prl_entry * 259static struct ip_tunnel_prl_entry *
226__ipip6_tunnel_locate_prl(struct ip_tunnel *t, __be32 addr) 260__ipip6_tunnel_locate_prl(struct ip_tunnel *t, __be32 addr)
227{ 261{
228 struct ip_tunnel_prl_entry *p = (struct ip_tunnel_prl_entry *)NULL; 262 struct ip_tunnel_prl_entry *prl;
229 263
230 for (p = t->prl; p; p = p->next) 264 for_each_prl_rcu(t->prl)
231 if (p->addr == addr) 265 if (prl->addr == addr)
232 break; 266 break;
233 return p; 267 return prl;
234 268
235} 269}
236 270
@@ -255,7 +289,7 @@ static int ipip6_tunnel_get_prl(struct ip_tunnel *t,
255 kcalloc(cmax, sizeof(*kp), GFP_KERNEL) : 289 kcalloc(cmax, sizeof(*kp), GFP_KERNEL) :
256 NULL; 290 NULL;
257 291
258 read_lock(&ipip6_lock); 292 rcu_read_lock();
259 293
260 ca = t->prl_count < cmax ? t->prl_count : cmax; 294 ca = t->prl_count < cmax ? t->prl_count : cmax;
261 295
@@ -273,7 +307,7 @@ static int ipip6_tunnel_get_prl(struct ip_tunnel *t,
273 } 307 }
274 308
275 c = 0; 309 c = 0;
276 for (prl = t->prl; prl; prl = prl->next) { 310 for_each_prl_rcu(t->prl) {
277 if (c >= cmax) 311 if (c >= cmax)
278 break; 312 break;
279 if (kprl.addr != htonl(INADDR_ANY) && prl->addr != kprl.addr) 313 if (kprl.addr != htonl(INADDR_ANY) && prl->addr != kprl.addr)
@@ -285,7 +319,7 @@ static int ipip6_tunnel_get_prl(struct ip_tunnel *t,
285 break; 319 break;
286 } 320 }
287out: 321out:
288 read_unlock(&ipip6_lock); 322 rcu_read_unlock();
289 323
290 len = sizeof(*kp) * c; 324 len = sizeof(*kp) * c;
291 ret = 0; 325 ret = 0;
@@ -306,12 +340,14 @@ ipip6_tunnel_add_prl(struct ip_tunnel *t, struct ip_tunnel_prl *a, int chg)
306 if (a->addr == htonl(INADDR_ANY)) 340 if (a->addr == htonl(INADDR_ANY))
307 return -EINVAL; 341 return -EINVAL;
308 342
309 write_lock(&ipip6_lock); 343 spin_lock(&ipip6_prl_lock);
310 344
311 for (p = t->prl; p; p = p->next) { 345 for (p = t->prl; p; p = p->next) {
312 if (p->addr == a->addr) { 346 if (p->addr == a->addr) {
313 if (chg) 347 if (chg) {
314 goto update; 348 p->flags = a->flags;
349 goto out;
350 }
315 err = -EEXIST; 351 err = -EEXIST;
316 goto out; 352 goto out;
317 } 353 }
@@ -329,45 +365,61 @@ ipip6_tunnel_add_prl(struct ip_tunnel *t, struct ip_tunnel_prl *a, int chg)
329 } 365 }
330 366
331 p->next = t->prl; 367 p->next = t->prl;
332 t->prl = p;
333 t->prl_count++;
334update:
335 p->addr = a->addr; 368 p->addr = a->addr;
336 p->flags = a->flags; 369 p->flags = a->flags;
370 t->prl_count++;
371 rcu_assign_pointer(t->prl, p);
337out: 372out:
338 write_unlock(&ipip6_lock); 373 spin_unlock(&ipip6_prl_lock);
339 return err; 374 return err;
340} 375}
341 376
377static void prl_entry_destroy_rcu(struct rcu_head *head)
378{
379 kfree(container_of(head, struct ip_tunnel_prl_entry, rcu_head));
380}
381
382static void prl_list_destroy_rcu(struct rcu_head *head)
383{
384 struct ip_tunnel_prl_entry *p, *n;
385
386 p = container_of(head, struct ip_tunnel_prl_entry, rcu_head);
387 do {
388 n = p->next;
389 kfree(p);
390 p = n;
391 } while (p);
392}
393
342static int 394static int
343ipip6_tunnel_del_prl(struct ip_tunnel *t, struct ip_tunnel_prl *a) 395ipip6_tunnel_del_prl(struct ip_tunnel *t, struct ip_tunnel_prl *a)
344{ 396{
345 struct ip_tunnel_prl_entry *x, **p; 397 struct ip_tunnel_prl_entry *x, **p;
346 int err = 0; 398 int err = 0;
347 399
348 write_lock(&ipip6_lock); 400 spin_lock(&ipip6_prl_lock);
349 401
350 if (a && a->addr != htonl(INADDR_ANY)) { 402 if (a && a->addr != htonl(INADDR_ANY)) {
351 for (p = &t->prl; *p; p = &(*p)->next) { 403 for (p = &t->prl; *p; p = &(*p)->next) {
352 if ((*p)->addr == a->addr) { 404 if ((*p)->addr == a->addr) {
353 x = *p; 405 x = *p;
354 *p = x->next; 406 *p = x->next;
355 kfree(x); 407 call_rcu(&x->rcu_head, prl_entry_destroy_rcu);
356 t->prl_count--; 408 t->prl_count--;
357 goto out; 409 goto out;
358 } 410 }
359 } 411 }
360 err = -ENXIO; 412 err = -ENXIO;
361 } else { 413 } else {
362 while (t->prl) { 414 if (t->prl) {
415 t->prl_count = 0;
363 x = t->prl; 416 x = t->prl;
364 t->prl = t->prl->next; 417 call_rcu(&x->rcu_head, prl_list_destroy_rcu);
365 kfree(x); 418 t->prl = NULL;
366 t->prl_count--;
367 } 419 }
368 } 420 }
369out: 421out:
370 write_unlock(&ipip6_lock); 422 spin_unlock(&ipip6_prl_lock);
371 return err; 423 return err;
372} 424}
373 425
@@ -377,7 +429,7 @@ isatap_chksrc(struct sk_buff *skb, struct iphdr *iph, struct ip_tunnel *t)
377 struct ip_tunnel_prl_entry *p; 429 struct ip_tunnel_prl_entry *p;
378 int ok = 1; 430 int ok = 1;
379 431
380 read_lock(&ipip6_lock); 432 rcu_read_lock();
381 p = __ipip6_tunnel_locate_prl(t, iph->saddr); 433 p = __ipip6_tunnel_locate_prl(t, iph->saddr);
382 if (p) { 434 if (p) {
383 if (p->flags & PRL_DEFAULT) 435 if (p->flags & PRL_DEFAULT)
@@ -393,7 +445,7 @@ isatap_chksrc(struct sk_buff *skb, struct iphdr *iph, struct ip_tunnel *t)
393 else 445 else
394 ok = 0; 446 ok = 0;
395 } 447 }
396 read_unlock(&ipip6_lock); 448 rcu_read_unlock();
397 return ok; 449 return ok;
398} 450}
399 451
@@ -403,9 +455,9 @@ static void ipip6_tunnel_uninit(struct net_device *dev)
403 struct sit_net *sitn = net_generic(net, sit_net_id); 455 struct sit_net *sitn = net_generic(net, sit_net_id);
404 456
405 if (dev == sitn->fb_tunnel_dev) { 457 if (dev == sitn->fb_tunnel_dev) {
406 write_lock_bh(&ipip6_lock); 458 spin_lock_bh(&ipip6_lock);
407 sitn->tunnels_wc[0] = NULL; 459 sitn->tunnels_wc[0] = NULL;
408 write_unlock_bh(&ipip6_lock); 460 spin_unlock_bh(&ipip6_lock);
409 dev_put(dev); 461 dev_put(dev);
410 } else { 462 } else {
411 ipip6_tunnel_unlink(sitn, netdev_priv(dev)); 463 ipip6_tunnel_unlink(sitn, netdev_priv(dev));
@@ -458,7 +510,7 @@ static int ipip6_err(struct sk_buff *skb, u32 info)
458 510
459 err = -ENOENT; 511 err = -ENOENT;
460 512
461 read_lock(&ipip6_lock); 513 rcu_read_lock();
462 t = ipip6_tunnel_lookup(dev_net(skb->dev), 514 t = ipip6_tunnel_lookup(dev_net(skb->dev),
463 skb->dev, 515 skb->dev,
464 iph->daddr, 516 iph->daddr,
@@ -476,7 +528,7 @@ static int ipip6_err(struct sk_buff *skb, u32 info)
476 t->err_count = 1; 528 t->err_count = 1;
477 t->err_time = jiffies; 529 t->err_time = jiffies;
478out: 530out:
479 read_unlock(&ipip6_lock); 531 rcu_read_unlock();
480 return err; 532 return err;
481} 533}
482 534
@@ -496,7 +548,7 @@ static int ipip6_rcv(struct sk_buff *skb)
496 548
497 iph = ip_hdr(skb); 549 iph = ip_hdr(skb);
498 550
499 read_lock(&ipip6_lock); 551 rcu_read_lock();
500 tunnel = ipip6_tunnel_lookup(dev_net(skb->dev), skb->dev, 552 tunnel = ipip6_tunnel_lookup(dev_net(skb->dev), skb->dev,
501 iph->saddr, iph->daddr); 553 iph->saddr, iph->daddr);
502 if (tunnel != NULL) { 554 if (tunnel != NULL) {
@@ -510,7 +562,7 @@ static int ipip6_rcv(struct sk_buff *skb)
510 if ((tunnel->dev->priv_flags & IFF_ISATAP) && 562 if ((tunnel->dev->priv_flags & IFF_ISATAP) &&
511 !isatap_chksrc(skb, iph, tunnel)) { 563 !isatap_chksrc(skb, iph, tunnel)) {
512 tunnel->dev->stats.rx_errors++; 564 tunnel->dev->stats.rx_errors++;
513 read_unlock(&ipip6_lock); 565 rcu_read_unlock();
514 kfree_skb(skb); 566 kfree_skb(skb);
515 return 0; 567 return 0;
516 } 568 }
@@ -521,28 +573,52 @@ static int ipip6_rcv(struct sk_buff *skb)
521 nf_reset(skb); 573 nf_reset(skb);
522 ipip6_ecn_decapsulate(iph, skb); 574 ipip6_ecn_decapsulate(iph, skb);
523 netif_rx(skb); 575 netif_rx(skb);
524 read_unlock(&ipip6_lock); 576 rcu_read_unlock();
525 return 0; 577 return 0;
526 } 578 }
527 579
528 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0); 580 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
529 read_unlock(&ipip6_lock); 581 rcu_read_unlock();
530out: 582out:
531 kfree_skb(skb); 583 kfree_skb(skb);
532 return 0; 584 return 0;
533} 585}
534 586
535/* Returns the embedded IPv4 address if the IPv6 address 587/*
536 comes from 6to4 (RFC 3056) addr space */ 588 * Returns the embedded IPv4 address if the IPv6 address
537 589 * comes from 6rd / 6to4 (RFC 3056) addr space.
538static inline __be32 try_6to4(struct in6_addr *v6dst) 590 */
591static inline
592__be32 try_6rd(struct in6_addr *v6dst, struct ip_tunnel *tunnel)
539{ 593{
540 __be32 dst = 0; 594 __be32 dst = 0;
541 595
596#ifdef CONFIG_IPV6_SIT_6RD
597 if (ipv6_prefix_equal(v6dst, &tunnel->ip6rd.prefix,
598 tunnel->ip6rd.prefixlen)) {
599 unsigned pbw0, pbi0;
600 int pbi1;
601 u32 d;
602
603 pbw0 = tunnel->ip6rd.prefixlen >> 5;
604 pbi0 = tunnel->ip6rd.prefixlen & 0x1f;
605
606 d = (ntohl(v6dst->s6_addr32[pbw0]) << pbi0) >>
607 tunnel->ip6rd.relay_prefixlen;
608
609 pbi1 = pbi0 - tunnel->ip6rd.relay_prefixlen;
610 if (pbi1 > 0)
611 d |= ntohl(v6dst->s6_addr32[pbw0 + 1]) >>
612 (32 - pbi1);
613
614 dst = tunnel->ip6rd.relay_prefix | htonl(d);
615 }
616#else
542 if (v6dst->s6_addr16[0] == htons(0x2002)) { 617 if (v6dst->s6_addr16[0] == htons(0x2002)) {
543 /* 6to4 v6 addr has 16 bits prefix, 32 v4addr, 16 SLA, ... */ 618 /* 6to4 v6 addr has 16 bits prefix, 32 v4addr, 16 SLA, ... */
544 memcpy(&dst, &v6dst->s6_addr16[1], 4); 619 memcpy(&dst, &v6dst->s6_addr16[1], 4);
545 } 620 }
621#endif
546 return dst; 622 return dst;
547} 623}
548 624
@@ -555,10 +631,12 @@ static netdev_tx_t ipip6_tunnel_xmit(struct sk_buff *skb,
555 struct net_device *dev) 631 struct net_device *dev)
556{ 632{
557 struct ip_tunnel *tunnel = netdev_priv(dev); 633 struct ip_tunnel *tunnel = netdev_priv(dev);
558 struct net_device_stats *stats = &tunnel->dev->stats; 634 struct net_device_stats *stats = &dev->stats;
635 struct netdev_queue *txq = netdev_get_tx_queue(dev, 0);
559 struct iphdr *tiph = &tunnel->parms.iph; 636 struct iphdr *tiph = &tunnel->parms.iph;
560 struct ipv6hdr *iph6 = ipv6_hdr(skb); 637 struct ipv6hdr *iph6 = ipv6_hdr(skb);
561 u8 tos = tunnel->parms.iph.tos; 638 u8 tos = tunnel->parms.iph.tos;
639 __be16 df = tiph->frag_off;
562 struct rtable *rt; /* Route to the other host */ 640 struct rtable *rt; /* Route to the other host */
563 struct net_device *tdev; /* Device to other host */ 641 struct net_device *tdev; /* Device to other host */
564 struct iphdr *iph; /* Our new IP header */ 642 struct iphdr *iph; /* Our new IP header */
@@ -595,7 +673,7 @@ static netdev_tx_t ipip6_tunnel_xmit(struct sk_buff *skb,
595 } 673 }
596 674
597 if (!dst) 675 if (!dst)
598 dst = try_6to4(&iph6->daddr); 676 dst = try_6rd(&iph6->daddr, tunnel);
599 677
600 if (!dst) { 678 if (!dst) {
601 struct neighbour *neigh = NULL; 679 struct neighbour *neigh = NULL;
@@ -648,25 +726,28 @@ static netdev_tx_t ipip6_tunnel_xmit(struct sk_buff *skb,
648 goto tx_error; 726 goto tx_error;
649 } 727 }
650 728
651 if (tiph->frag_off) 729 if (df) {
652 mtu = dst_mtu(&rt->u.dst) - sizeof(struct iphdr); 730 mtu = dst_mtu(&rt->u.dst) - sizeof(struct iphdr);
653 else
654 mtu = skb_dst(skb) ? dst_mtu(skb_dst(skb)) : dev->mtu;
655 731
656 if (mtu < 68) { 732 if (mtu < 68) {
657 stats->collisions++; 733 stats->collisions++;
658 ip_rt_put(rt); 734 ip_rt_put(rt);
659 goto tx_error; 735 goto tx_error;
660 } 736 }
661 if (mtu < IPV6_MIN_MTU)
662 mtu = IPV6_MIN_MTU;
663 if (tunnel->parms.iph.daddr && skb_dst(skb))
664 skb_dst(skb)->ops->update_pmtu(skb_dst(skb), mtu);
665 737
666 if (skb->len > mtu) { 738 if (mtu < IPV6_MIN_MTU) {
667 icmpv6_send(skb, ICMPV6_PKT_TOOBIG, 0, mtu, dev); 739 mtu = IPV6_MIN_MTU;
668 ip_rt_put(rt); 740 df = 0;
669 goto tx_error; 741 }
742
743 if (tunnel->parms.iph.daddr && skb_dst(skb))
744 skb_dst(skb)->ops->update_pmtu(skb_dst(skb), mtu);
745
746 if (skb->len > mtu) {
747 icmpv6_send(skb, ICMPV6_PKT_TOOBIG, 0, mtu);
748 ip_rt_put(rt);
749 goto tx_error;
750 }
670 } 751 }
671 752
672 if (tunnel->err_count > 0) { 753 if (tunnel->err_count > 0) {
@@ -688,7 +769,7 @@ static netdev_tx_t ipip6_tunnel_xmit(struct sk_buff *skb,
688 struct sk_buff *new_skb = skb_realloc_headroom(skb, max_headroom); 769 struct sk_buff *new_skb = skb_realloc_headroom(skb, max_headroom);
689 if (!new_skb) { 770 if (!new_skb) {
690 ip_rt_put(rt); 771 ip_rt_put(rt);
691 stats->tx_dropped++; 772 txq->tx_dropped++;
692 dev_kfree_skb(skb); 773 dev_kfree_skb(skb);
693 return NETDEV_TX_OK; 774 return NETDEV_TX_OK;
694 } 775 }
@@ -714,11 +795,7 @@ static netdev_tx_t ipip6_tunnel_xmit(struct sk_buff *skb,
714 iph = ip_hdr(skb); 795 iph = ip_hdr(skb);
715 iph->version = 4; 796 iph->version = 4;
716 iph->ihl = sizeof(struct iphdr)>>2; 797 iph->ihl = sizeof(struct iphdr)>>2;
717 if (mtu > IPV6_MIN_MTU) 798 iph->frag_off = df;
718 iph->frag_off = tiph->frag_off;
719 else
720 iph->frag_off = 0;
721
722 iph->protocol = IPPROTO_IPV6; 799 iph->protocol = IPPROTO_IPV6;
723 iph->tos = INET_ECN_encapsulate(tos, ipv6_get_dsfield(iph6)); 800 iph->tos = INET_ECN_encapsulate(tos, ipv6_get_dsfield(iph6));
724 iph->daddr = rt->rt_dst; 801 iph->daddr = rt->rt_dst;
@@ -785,9 +862,15 @@ ipip6_tunnel_ioctl (struct net_device *dev, struct ifreq *ifr, int cmd)
785 struct ip_tunnel *t; 862 struct ip_tunnel *t;
786 struct net *net = dev_net(dev); 863 struct net *net = dev_net(dev);
787 struct sit_net *sitn = net_generic(net, sit_net_id); 864 struct sit_net *sitn = net_generic(net, sit_net_id);
865#ifdef CONFIG_IPV6_SIT_6RD
866 struct ip_tunnel_6rd ip6rd;
867#endif
788 868
789 switch (cmd) { 869 switch (cmd) {
790 case SIOCGETTUNNEL: 870 case SIOCGETTUNNEL:
871#ifdef CONFIG_IPV6_SIT_6RD
872 case SIOCGET6RD:
873#endif
791 t = NULL; 874 t = NULL;
792 if (dev == sitn->fb_tunnel_dev) { 875 if (dev == sitn->fb_tunnel_dev) {
793 if (copy_from_user(&p, ifr->ifr_ifru.ifru_data, sizeof(p))) { 876 if (copy_from_user(&p, ifr->ifr_ifru.ifru_data, sizeof(p))) {
@@ -798,9 +881,25 @@ ipip6_tunnel_ioctl (struct net_device *dev, struct ifreq *ifr, int cmd)
798 } 881 }
799 if (t == NULL) 882 if (t == NULL)
800 t = netdev_priv(dev); 883 t = netdev_priv(dev);
801 memcpy(&p, &t->parms, sizeof(p)); 884
802 if (copy_to_user(ifr->ifr_ifru.ifru_data, &p, sizeof(p))) 885 err = -EFAULT;
803 err = -EFAULT; 886 if (cmd == SIOCGETTUNNEL) {
887 memcpy(&p, &t->parms, sizeof(p));
888 if (copy_to_user(ifr->ifr_ifru.ifru_data, &p,
889 sizeof(p)))
890 goto done;
891#ifdef CONFIG_IPV6_SIT_6RD
892 } else {
893 ipv6_addr_copy(&ip6rd.prefix, &t->ip6rd.prefix);
894 ip6rd.relay_prefix = t->ip6rd.relay_prefix;
895 ip6rd.prefixlen = t->ip6rd.prefixlen;
896 ip6rd.relay_prefixlen = t->ip6rd.relay_prefixlen;
897 if (copy_to_user(ifr->ifr_ifru.ifru_data, &ip6rd,
898 sizeof(ip6rd)))
899 goto done;
900#endif
901 }
902 err = 0;
804 break; 903 break;
805 904
806 case SIOCADDTUNNEL: 905 case SIOCADDTUNNEL:
@@ -921,6 +1020,54 @@ ipip6_tunnel_ioctl (struct net_device *dev, struct ifreq *ifr, int cmd)
921 netdev_state_change(dev); 1020 netdev_state_change(dev);
922 break; 1021 break;
923 1022
1023#ifdef CONFIG_IPV6_SIT_6RD
1024 case SIOCADD6RD:
1025 case SIOCCHG6RD:
1026 case SIOCDEL6RD:
1027 err = -EPERM;
1028 if (!capable(CAP_NET_ADMIN))
1029 goto done;
1030
1031 err = -EFAULT;
1032 if (copy_from_user(&ip6rd, ifr->ifr_ifru.ifru_data,
1033 sizeof(ip6rd)))
1034 goto done;
1035
1036 t = netdev_priv(dev);
1037
1038 if (cmd != SIOCDEL6RD) {
1039 struct in6_addr prefix;
1040 __be32 relay_prefix;
1041
1042 err = -EINVAL;
1043 if (ip6rd.relay_prefixlen > 32 ||
1044 ip6rd.prefixlen + (32 - ip6rd.relay_prefixlen) > 64)
1045 goto done;
1046
1047 ipv6_addr_prefix(&prefix, &ip6rd.prefix,
1048 ip6rd.prefixlen);
1049 if (!ipv6_addr_equal(&prefix, &ip6rd.prefix))
1050 goto done;
1051 if (ip6rd.relay_prefixlen)
1052 relay_prefix = ip6rd.relay_prefix &
1053 htonl(0xffffffffUL <<
1054 (32 - ip6rd.relay_prefixlen));
1055 else
1056 relay_prefix = 0;
1057 if (relay_prefix != ip6rd.relay_prefix)
1058 goto done;
1059
1060 ipv6_addr_copy(&t->ip6rd.prefix, &prefix);
1061 t->ip6rd.relay_prefix = relay_prefix;
1062 t->ip6rd.prefixlen = ip6rd.prefixlen;
1063 t->ip6rd.relay_prefixlen = ip6rd.relay_prefixlen;
1064 } else
1065 ipip6_tunnel_clone_6rd(dev, sitn);
1066
1067 err = 0;
1068 break;
1069#endif
1070
924 default: 1071 default:
925 err = -EINVAL; 1072 err = -EINVAL;
926 } 1073 }
@@ -972,7 +1119,7 @@ static void ipip6_tunnel_init(struct net_device *dev)
972 ipip6_tunnel_bind_dev(dev); 1119 ipip6_tunnel_bind_dev(dev);
973} 1120}
974 1121
975static void ipip6_fb_tunnel_init(struct net_device *dev) 1122static void __net_init ipip6_fb_tunnel_init(struct net_device *dev)
976{ 1123{
977 struct ip_tunnel *tunnel = netdev_priv(dev); 1124 struct ip_tunnel *tunnel = netdev_priv(dev);
978 struct iphdr *iph = &tunnel->parms.iph; 1125 struct iphdr *iph = &tunnel->parms.iph;
@@ -997,33 +1144,27 @@ static struct xfrm_tunnel sit_handler = {
997 .priority = 1, 1144 .priority = 1,
998}; 1145};
999 1146
1000static void sit_destroy_tunnels(struct sit_net *sitn) 1147static void __net_exit sit_destroy_tunnels(struct sit_net *sitn, struct list_head *head)
1001{ 1148{
1002 int prio; 1149 int prio;
1003 1150
1004 for (prio = 1; prio < 4; prio++) { 1151 for (prio = 1; prio < 4; prio++) {
1005 int h; 1152 int h;
1006 for (h = 0; h < HASH_SIZE; h++) { 1153 for (h = 0; h < HASH_SIZE; h++) {
1007 struct ip_tunnel *t; 1154 struct ip_tunnel *t = sitn->tunnels[prio][h];
1008 while ((t = sitn->tunnels[prio][h]) != NULL) 1155
1009 unregister_netdevice(t->dev); 1156 while (t != NULL) {
1157 unregister_netdevice_queue(t->dev, head);
1158 t = t->next;
1159 }
1010 } 1160 }
1011 } 1161 }
1012} 1162}
1013 1163
1014static int sit_init_net(struct net *net) 1164static int __net_init sit_init_net(struct net *net)
1015{ 1165{
1166 struct sit_net *sitn = net_generic(net, sit_net_id);
1016 int err; 1167 int err;
1017 struct sit_net *sitn;
1018
1019 err = -ENOMEM;
1020 sitn = kzalloc(sizeof(struct sit_net), GFP_KERNEL);
1021 if (sitn == NULL)
1022 goto err_alloc;
1023
1024 err = net_assign_generic(net, sit_net_id, sitn);
1025 if (err < 0)
1026 goto err_assign;
1027 1168
1028 sitn->tunnels[0] = sitn->tunnels_wc; 1169 sitn->tunnels[0] = sitn->tunnels_wc;
1029 sitn->tunnels[1] = sitn->tunnels_l; 1170 sitn->tunnels[1] = sitn->tunnels_l;
@@ -1039,6 +1180,7 @@ static int sit_init_net(struct net *net)
1039 dev_net_set(sitn->fb_tunnel_dev, net); 1180 dev_net_set(sitn->fb_tunnel_dev, net);
1040 1181
1041 ipip6_fb_tunnel_init(sitn->fb_tunnel_dev); 1182 ipip6_fb_tunnel_init(sitn->fb_tunnel_dev);
1183 ipip6_tunnel_clone_6rd(sitn->fb_tunnel_dev, sitn);
1042 1184
1043 if ((err = register_netdev(sitn->fb_tunnel_dev))) 1185 if ((err = register_netdev(sitn->fb_tunnel_dev)))
1044 goto err_reg_dev; 1186 goto err_reg_dev;
@@ -1049,35 +1191,34 @@ err_reg_dev:
1049 dev_put(sitn->fb_tunnel_dev); 1191 dev_put(sitn->fb_tunnel_dev);
1050 free_netdev(sitn->fb_tunnel_dev); 1192 free_netdev(sitn->fb_tunnel_dev);
1051err_alloc_dev: 1193err_alloc_dev:
1052 /* nothing */
1053err_assign:
1054 kfree(sitn);
1055err_alloc:
1056 return err; 1194 return err;
1057} 1195}
1058 1196
1059static void sit_exit_net(struct net *net) 1197static void __net_exit sit_exit_net(struct net *net)
1060{ 1198{
1061 struct sit_net *sitn; 1199 struct sit_net *sitn = net_generic(net, sit_net_id);
1200 LIST_HEAD(list);
1062 1201
1063 sitn = net_generic(net, sit_net_id);
1064 rtnl_lock(); 1202 rtnl_lock();
1065 sit_destroy_tunnels(sitn); 1203 sit_destroy_tunnels(sitn, &list);
1066 unregister_netdevice(sitn->fb_tunnel_dev); 1204 unregister_netdevice_queue(sitn->fb_tunnel_dev, &list);
1205 unregister_netdevice_many(&list);
1067 rtnl_unlock(); 1206 rtnl_unlock();
1068 kfree(sitn);
1069} 1207}
1070 1208
1071static struct pernet_operations sit_net_ops = { 1209static struct pernet_operations sit_net_ops = {
1072 .init = sit_init_net, 1210 .init = sit_init_net,
1073 .exit = sit_exit_net, 1211 .exit = sit_exit_net,
1212 .id = &sit_net_id,
1213 .size = sizeof(struct sit_net),
1074}; 1214};
1075 1215
1076static void __exit sit_cleanup(void) 1216static void __exit sit_cleanup(void)
1077{ 1217{
1078 xfrm4_tunnel_deregister(&sit_handler, AF_INET6); 1218 xfrm4_tunnel_deregister(&sit_handler, AF_INET6);
1079 1219
1080 unregister_pernet_gen_device(sit_net_id, &sit_net_ops); 1220 unregister_pernet_device(&sit_net_ops);
1221 rcu_barrier(); /* Wait for completion of call_rcu()'s */
1081} 1222}
1082 1223
1083static int __init sit_init(void) 1224static int __init sit_init(void)
@@ -1086,15 +1227,14 @@ static int __init sit_init(void)
1086 1227
1087 printk(KERN_INFO "IPv6 over IPv4 tunneling driver\n"); 1228 printk(KERN_INFO "IPv6 over IPv4 tunneling driver\n");
1088 1229
1089 if (xfrm4_tunnel_register(&sit_handler, AF_INET6) < 0) { 1230 err = register_pernet_device(&sit_net_ops);
1231 if (err < 0)
1232 return err;
1233 err = xfrm4_tunnel_register(&sit_handler, AF_INET6);
1234 if (err < 0) {
1235 unregister_pernet_device(&sit_net_ops);
1090 printk(KERN_INFO "sit init: Can't add protocol\n"); 1236 printk(KERN_INFO "sit init: Can't add protocol\n");
1091 return -EAGAIN;
1092 } 1237 }
1093
1094 err = register_pernet_gen_device(&sit_net_id, &sit_net_ops);
1095 if (err < 0)
1096 xfrm4_tunnel_deregister(&sit_handler, AF_INET6);
1097
1098 return err; 1238 return err;
1099} 1239}
1100 1240
diff --git a/net/ipv6/syncookies.c b/net/ipv6/syncookies.c
index 6b6ae913b5d4..34d1f0690d7e 100644
--- a/net/ipv6/syncookies.c
+++ b/net/ipv6/syncookies.c
@@ -159,6 +159,8 @@ static inline int cookie_check(struct sk_buff *skb, __u32 cookie)
159 159
160struct sock *cookie_v6_check(struct sock *sk, struct sk_buff *skb) 160struct sock *cookie_v6_check(struct sock *sk, struct sk_buff *skb)
161{ 161{
162 struct tcp_options_received tcp_opt;
163 u8 *hash_location;
162 struct inet_request_sock *ireq; 164 struct inet_request_sock *ireq;
163 struct inet6_request_sock *ireq6; 165 struct inet6_request_sock *ireq6;
164 struct tcp_request_sock *treq; 166 struct tcp_request_sock *treq;
@@ -171,7 +173,6 @@ struct sock *cookie_v6_check(struct sock *sk, struct sk_buff *skb)
171 int mss; 173 int mss;
172 struct dst_entry *dst; 174 struct dst_entry *dst;
173 __u8 rcv_wscale; 175 __u8 rcv_wscale;
174 struct tcp_options_received tcp_opt;
175 176
176 if (!sysctl_tcp_syncookies || !th->ack) 177 if (!sysctl_tcp_syncookies || !th->ack)
177 goto out; 178 goto out;
@@ -186,7 +187,7 @@ struct sock *cookie_v6_check(struct sock *sk, struct sk_buff *skb)
186 187
187 /* check for timestamp cookie support */ 188 /* check for timestamp cookie support */
188 memset(&tcp_opt, 0, sizeof(tcp_opt)); 189 memset(&tcp_opt, 0, sizeof(tcp_opt));
189 tcp_parse_options(skb, &tcp_opt, 0); 190 tcp_parse_options(skb, &tcp_opt, &hash_location, 0);
190 191
191 if (tcp_opt.saw_tstamp) 192 if (tcp_opt.saw_tstamp)
192 cookie_check_timestamp(&tcp_opt); 193 cookie_check_timestamp(&tcp_opt);
@@ -252,8 +253,9 @@ struct sock *cookie_v6_check(struct sock *sk, struct sk_buff *skb)
252 } 253 }
253 ipv6_addr_copy(&fl.fl6_src, &ireq6->loc_addr); 254 ipv6_addr_copy(&fl.fl6_src, &ireq6->loc_addr);
254 fl.oif = sk->sk_bound_dev_if; 255 fl.oif = sk->sk_bound_dev_if;
256 fl.mark = sk->sk_mark;
255 fl.fl_ip_dport = inet_rsk(req)->rmt_port; 257 fl.fl_ip_dport = inet_rsk(req)->rmt_port;
256 fl.fl_ip_sport = inet_sk(sk)->sport; 258 fl.fl_ip_sport = inet_sk(sk)->inet_sport;
257 security_req_classify_flow(req, &fl); 259 security_req_classify_flow(req, &fl);
258 if (ip6_dst_lookup(sk, &dst, &fl)) 260 if (ip6_dst_lookup(sk, &dst, &fl))
259 goto out_free; 261 goto out_free;
@@ -267,7 +269,8 @@ struct sock *cookie_v6_check(struct sock *sk, struct sk_buff *skb)
267 req->window_clamp = tp->window_clamp ? :dst_metric(dst, RTAX_WINDOW); 269 req->window_clamp = tp->window_clamp ? :dst_metric(dst, RTAX_WINDOW);
268 tcp_select_initial_window(tcp_full_space(sk), req->mss, 270 tcp_select_initial_window(tcp_full_space(sk), req->mss,
269 &req->rcv_wnd, &req->window_clamp, 271 &req->rcv_wnd, &req->window_clamp,
270 ireq->wscale_ok, &rcv_wscale); 272 ireq->wscale_ok, &rcv_wscale,
273 dst_metric(dst, RTAX_INITRWND));
271 274
272 ireq->rcv_wscale = rcv_wscale; 275 ireq->rcv_wscale = rcv_wscale;
273 276
diff --git a/net/ipv6/sysctl_net_ipv6.c b/net/ipv6/sysctl_net_ipv6.c
index 0dc6a4e5ed4a..fa1d8f4e0051 100644
--- a/net/ipv6/sysctl_net_ipv6.c
+++ b/net/ipv6/sysctl_net_ipv6.c
@@ -9,6 +9,7 @@
9#include <linux/sysctl.h> 9#include <linux/sysctl.h>
10#include <linux/in6.h> 10#include <linux/in6.h>
11#include <linux/ipv6.h> 11#include <linux/ipv6.h>
12#include <linux/slab.h>
12#include <net/ndisc.h> 13#include <net/ndisc.h>
13#include <net/ipv6.h> 14#include <net/ipv6.h>
14#include <net/addrconf.h> 15#include <net/addrconf.h>
@@ -16,50 +17,46 @@
16 17
17static ctl_table ipv6_table_template[] = { 18static ctl_table ipv6_table_template[] = {
18 { 19 {
19 .ctl_name = NET_IPV6_ROUTE,
20 .procname = "route", 20 .procname = "route",
21 .maxlen = 0, 21 .maxlen = 0,
22 .mode = 0555, 22 .mode = 0555,
23 .child = ipv6_route_table_template 23 .child = ipv6_route_table_template
24 }, 24 },
25 { 25 {
26 .ctl_name = NET_IPV6_ICMP,
27 .procname = "icmp", 26 .procname = "icmp",
28 .maxlen = 0, 27 .maxlen = 0,
29 .mode = 0555, 28 .mode = 0555,
30 .child = ipv6_icmp_table_template 29 .child = ipv6_icmp_table_template
31 }, 30 },
32 { 31 {
33 .ctl_name = NET_IPV6_BINDV6ONLY,
34 .procname = "bindv6only", 32 .procname = "bindv6only",
35 .data = &init_net.ipv6.sysctl.bindv6only, 33 .data = &init_net.ipv6.sysctl.bindv6only,
36 .maxlen = sizeof(int), 34 .maxlen = sizeof(int),
37 .mode = 0644, 35 .mode = 0644,
38 .proc_handler = proc_dointvec 36 .proc_handler = proc_dointvec
39 }, 37 },
40 { .ctl_name = 0 } 38 { }
41}; 39};
42 40
43static ctl_table ipv6_rotable[] = { 41static ctl_table ipv6_rotable[] = {
44 { 42 {
45 .ctl_name = NET_IPV6_MLD_MAX_MSF,
46 .procname = "mld_max_msf", 43 .procname = "mld_max_msf",
47 .data = &sysctl_mld_max_msf, 44 .data = &sysctl_mld_max_msf,
48 .maxlen = sizeof(int), 45 .maxlen = sizeof(int),
49 .mode = 0644, 46 .mode = 0644,
50 .proc_handler = proc_dointvec 47 .proc_handler = proc_dointvec
51 }, 48 },
52 { .ctl_name = 0 } 49 { }
53}; 50};
54 51
55struct ctl_path net_ipv6_ctl_path[] = { 52struct ctl_path net_ipv6_ctl_path[] = {
56 { .procname = "net", .ctl_name = CTL_NET, }, 53 { .procname = "net", },
57 { .procname = "ipv6", .ctl_name = NET_IPV6, }, 54 { .procname = "ipv6", },
58 { }, 55 { },
59}; 56};
60EXPORT_SYMBOL_GPL(net_ipv6_ctl_path); 57EXPORT_SYMBOL_GPL(net_ipv6_ctl_path);
61 58
62static int ipv6_sysctl_net_init(struct net *net) 59static int __net_init ipv6_sysctl_net_init(struct net *net)
63{ 60{
64 struct ctl_table *ipv6_table; 61 struct ctl_table *ipv6_table;
65 struct ctl_table *ipv6_route_table; 62 struct ctl_table *ipv6_route_table;
@@ -102,7 +99,7 @@ out_ipv6_table:
102 goto out; 99 goto out;
103} 100}
104 101
105static void ipv6_sysctl_net_exit(struct net *net) 102static void __net_exit ipv6_sysctl_net_exit(struct net *net)
106{ 103{
107 struct ctl_table *ipv6_table; 104 struct ctl_table *ipv6_table;
108 struct ctl_table *ipv6_route_table; 105 struct ctl_table *ipv6_route_table;
diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
index 21d100b68b19..075f540ec197 100644
--- a/net/ipv6/tcp_ipv6.c
+++ b/net/ipv6/tcp_ipv6.c
@@ -38,6 +38,7 @@
38#include <linux/jhash.h> 38#include <linux/jhash.h>
39#include <linux/ipsec.h> 39#include <linux/ipsec.h>
40#include <linux/times.h> 40#include <linux/times.h>
41#include <linux/slab.h>
41 42
42#include <linux/ipv6.h> 43#include <linux/ipv6.h>
43#include <linux/icmpv6.h> 44#include <linux/icmpv6.h>
@@ -96,7 +97,7 @@ static void tcp_v6_hash(struct sock *sk)
96 return; 97 return;
97 } 98 }
98 local_bh_disable(); 99 local_bh_disable();
99 __inet6_hash(sk); 100 __inet6_hash(sk, NULL);
100 local_bh_enable(); 101 local_bh_enable();
101 } 102 }
102} 103}
@@ -226,10 +227,9 @@ static int tcp_v6_connect(struct sock *sk, struct sockaddr *uaddr,
226#endif 227#endif
227 goto failure; 228 goto failure;
228 } else { 229 } else {
229 ipv6_addr_set(&np->saddr, 0, 0, htonl(0x0000FFFF), 230 ipv6_addr_set_v4mapped(inet->inet_saddr, &np->saddr);
230 inet->saddr); 231 ipv6_addr_set_v4mapped(inet->inet_rcv_saddr,
231 ipv6_addr_set(&np->rcv_saddr, 0, 0, htonl(0x0000FFFF), 232 &np->rcv_saddr);
232 inet->rcv_saddr);
233 } 233 }
234 234
235 return err; 235 return err;
@@ -243,8 +243,9 @@ static int tcp_v6_connect(struct sock *sk, struct sockaddr *uaddr,
243 ipv6_addr_copy(&fl.fl6_src, 243 ipv6_addr_copy(&fl.fl6_src,
244 (saddr ? saddr : &np->saddr)); 244 (saddr ? saddr : &np->saddr));
245 fl.oif = sk->sk_bound_dev_if; 245 fl.oif = sk->sk_bound_dev_if;
246 fl.mark = sk->sk_mark;
246 fl.fl_ip_dport = usin->sin6_port; 247 fl.fl_ip_dport = usin->sin6_port;
247 fl.fl_ip_sport = inet->sport; 248 fl.fl_ip_sport = inet->inet_sport;
248 249
249 if (np->opt && np->opt->srcrt) { 250 if (np->opt && np->opt->srcrt) {
250 struct rt0_hdr *rt0 = (struct rt0_hdr *)np->opt->srcrt; 251 struct rt0_hdr *rt0 = (struct rt0_hdr *)np->opt->srcrt;
@@ -276,7 +277,7 @@ static int tcp_v6_connect(struct sock *sk, struct sockaddr *uaddr,
276 277
277 /* set the source address */ 278 /* set the source address */
278 ipv6_addr_copy(&np->saddr, saddr); 279 ipv6_addr_copy(&np->saddr, saddr);
279 inet->rcv_saddr = LOOPBACK4_IPV6; 280 inet->inet_rcv_saddr = LOOPBACK4_IPV6;
280 281
281 sk->sk_gso_type = SKB_GSO_TCPV6; 282 sk->sk_gso_type = SKB_GSO_TCPV6;
282 __ip6_dst_store(sk, dst, NULL, NULL); 283 __ip6_dst_store(sk, dst, NULL, NULL);
@@ -288,7 +289,7 @@ static int tcp_v6_connect(struct sock *sk, struct sockaddr *uaddr,
288 289
289 tp->rx_opt.mss_clamp = IPV6_MIN_MTU - sizeof(struct tcphdr) - sizeof(struct ipv6hdr); 290 tp->rx_opt.mss_clamp = IPV6_MIN_MTU - sizeof(struct tcphdr) - sizeof(struct ipv6hdr);
290 291
291 inet->dport = usin->sin6_port; 292 inet->inet_dport = usin->sin6_port;
292 293
293 tcp_set_state(sk, TCP_SYN_SENT); 294 tcp_set_state(sk, TCP_SYN_SENT);
294 err = inet6_hash_connect(&tcp_death_row, sk); 295 err = inet6_hash_connect(&tcp_death_row, sk);
@@ -298,8 +299,8 @@ static int tcp_v6_connect(struct sock *sk, struct sockaddr *uaddr,
298 if (!tp->write_seq) 299 if (!tp->write_seq)
299 tp->write_seq = secure_tcpv6_sequence_number(np->saddr.s6_addr32, 300 tp->write_seq = secure_tcpv6_sequence_number(np->saddr.s6_addr32,
300 np->daddr.s6_addr32, 301 np->daddr.s6_addr32,
301 inet->sport, 302 inet->inet_sport,
302 inet->dport); 303 inet->inet_dport);
303 304
304 err = tcp_connect(sk); 305 err = tcp_connect(sk);
305 if (err) 306 if (err)
@@ -311,7 +312,7 @@ late_failure:
311 tcp_set_state(sk, TCP_CLOSE); 312 tcp_set_state(sk, TCP_CLOSE);
312 __sk_dst_reset(sk); 313 __sk_dst_reset(sk);
313failure: 314failure:
314 inet->dport = 0; 315 inet->inet_dport = 0;
315 sk->sk_route_caps = 0; 316 sk->sk_route_caps = 0;
316 return err; 317 return err;
317} 318}
@@ -383,8 +384,9 @@ static void tcp_v6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
383 ipv6_addr_copy(&fl.fl6_dst, &np->daddr); 384 ipv6_addr_copy(&fl.fl6_dst, &np->daddr);
384 ipv6_addr_copy(&fl.fl6_src, &np->saddr); 385 ipv6_addr_copy(&fl.fl6_src, &np->saddr);
385 fl.oif = sk->sk_bound_dev_if; 386 fl.oif = sk->sk_bound_dev_if;
386 fl.fl_ip_dport = inet->dport; 387 fl.mark = sk->sk_mark;
387 fl.fl_ip_sport = inet->sport; 388 fl.fl_ip_dport = inet->inet_dport;
389 fl.fl_ip_sport = inet->inet_sport;
388 security_skb_classify_flow(skb, &fl); 390 security_skb_classify_flow(skb, &fl);
389 391
390 if ((err = ip6_dst_lookup(sk, &dst, &fl))) { 392 if ((err = ip6_dst_lookup(sk, &dst, &fl))) {
@@ -460,7 +462,8 @@ out:
460} 462}
461 463
462 464
463static int tcp_v6_send_synack(struct sock *sk, struct request_sock *req) 465static int tcp_v6_send_synack(struct sock *sk, struct request_sock *req,
466 struct request_values *rvp)
464{ 467{
465 struct inet6_request_sock *treq = inet6_rsk(req); 468 struct inet6_request_sock *treq = inet6_rsk(req);
466 struct ipv6_pinfo *np = inet6_sk(sk); 469 struct ipv6_pinfo *np = inet6_sk(sk);
@@ -477,6 +480,7 @@ static int tcp_v6_send_synack(struct sock *sk, struct request_sock *req)
477 ipv6_addr_copy(&fl.fl6_src, &treq->loc_addr); 480 ipv6_addr_copy(&fl.fl6_src, &treq->loc_addr);
478 fl.fl6_flowlabel = 0; 481 fl.fl6_flowlabel = 0;
479 fl.oif = treq->iif; 482 fl.oif = treq->iif;
483 fl.mark = sk->sk_mark;
480 fl.fl_ip_dport = inet_rsk(req)->rmt_port; 484 fl.fl_ip_dport = inet_rsk(req)->rmt_port;
481 fl.fl_ip_sport = inet_rsk(req)->loc_port; 485 fl.fl_ip_sport = inet_rsk(req)->loc_port;
482 security_req_classify_flow(req, &fl); 486 security_req_classify_flow(req, &fl);
@@ -497,7 +501,7 @@ static int tcp_v6_send_synack(struct sock *sk, struct request_sock *req)
497 if ((err = xfrm_lookup(sock_net(sk), &dst, &fl, sk, 0)) < 0) 501 if ((err = xfrm_lookup(sock_net(sk), &dst, &fl, sk, 0)) < 0)
498 goto done; 502 goto done;
499 503
500 skb = tcp_make_synack(sk, dst, req); 504 skb = tcp_make_synack(sk, dst, req, rvp);
501 if (skb) { 505 if (skb) {
502 struct tcphdr *th = tcp_hdr(skb); 506 struct tcphdr *th = tcp_hdr(skb);
503 507
@@ -517,6 +521,13 @@ done:
517 return err; 521 return err;
518} 522}
519 523
524static int tcp_v6_rtx_synack(struct sock *sk, struct request_sock *req,
525 struct request_values *rvp)
526{
527 TCP_INC_STATS_BH(sock_net(sk), TCP_MIB_RETRANSSEGS);
528 return tcp_v6_send_synack(sk, req, rvp);
529}
530
520static inline void syn_flood_warning(struct sk_buff *skb) 531static inline void syn_flood_warning(struct sk_buff *skb)
521{ 532{
522#ifdef CONFIG_SYN_COOKIES 533#ifdef CONFIG_SYN_COOKIES
@@ -873,7 +884,7 @@ static int tcp_v6_inbound_md5_hash (struct sock *sk, struct sk_buff *skb)
873 884
874 if (genhash || memcmp(hash_location, newhash, 16) != 0) { 885 if (genhash || memcmp(hash_location, newhash, 16) != 0) {
875 if (net_ratelimit()) { 886 if (net_ratelimit()) {
876 printk(KERN_INFO "MD5 Hash %s for (%pI6, %u)->(%pI6, %u)\n", 887 printk(KERN_INFO "MD5 Hash %s for [%pI6c]:%u->[%pI6c]:%u\n",
877 genhash ? "failed" : "mismatch", 888 genhash ? "failed" : "mismatch",
878 &ip6h->saddr, ntohs(th->source), 889 &ip6h->saddr, ntohs(th->source),
879 &ip6h->daddr, ntohs(th->dest)); 890 &ip6h->daddr, ntohs(th->dest));
@@ -887,10 +898,11 @@ static int tcp_v6_inbound_md5_hash (struct sock *sk, struct sk_buff *skb)
887struct request_sock_ops tcp6_request_sock_ops __read_mostly = { 898struct request_sock_ops tcp6_request_sock_ops __read_mostly = {
888 .family = AF_INET6, 899 .family = AF_INET6,
889 .obj_size = sizeof(struct tcp6_request_sock), 900 .obj_size = sizeof(struct tcp6_request_sock),
890 .rtx_syn_ack = tcp_v6_send_synack, 901 .rtx_syn_ack = tcp_v6_rtx_synack,
891 .send_ack = tcp_v6_reqsk_send_ack, 902 .send_ack = tcp_v6_reqsk_send_ack,
892 .destructor = tcp_v6_reqsk_destructor, 903 .destructor = tcp_v6_reqsk_destructor,
893 .send_reset = tcp_v6_send_reset 904 .send_reset = tcp_v6_send_reset,
905 .syn_ack_timeout = tcp_syn_ack_timeout,
894}; 906};
895 907
896#ifdef CONFIG_TCP_MD5SIG 908#ifdef CONFIG_TCP_MD5SIG
@@ -1003,7 +1015,7 @@ static void tcp_v6_send_response(struct sk_buff *skb, u32 seq, u32 ack, u32 win,
1003 skb_reserve(buff, MAX_HEADER + sizeof(struct ipv6hdr) + tot_len); 1015 skb_reserve(buff, MAX_HEADER + sizeof(struct ipv6hdr) + tot_len);
1004 1016
1005 t1 = (struct tcphdr *) skb_push(buff, tot_len); 1017 t1 = (struct tcphdr *) skb_push(buff, tot_len);
1006 skb_reset_transport_header(skb); 1018 skb_reset_transport_header(buff);
1007 1019
1008 /* Swap the send and the receive. */ 1020 /* Swap the send and the receive. */
1009 memset(t1, 0, sizeof(*t1)); 1021 memset(t1, 0, sizeof(*t1));
@@ -1159,11 +1171,13 @@ static struct sock *tcp_v6_hnd_req(struct sock *sk,struct sk_buff *skb)
1159 */ 1171 */
1160static int tcp_v6_conn_request(struct sock *sk, struct sk_buff *skb) 1172static int tcp_v6_conn_request(struct sock *sk, struct sk_buff *skb)
1161{ 1173{
1174 struct tcp_extend_values tmp_ext;
1175 struct tcp_options_received tmp_opt;
1176 u8 *hash_location;
1177 struct request_sock *req;
1162 struct inet6_request_sock *treq; 1178 struct inet6_request_sock *treq;
1163 struct ipv6_pinfo *np = inet6_sk(sk); 1179 struct ipv6_pinfo *np = inet6_sk(sk);
1164 struct tcp_options_received tmp_opt;
1165 struct tcp_sock *tp = tcp_sk(sk); 1180 struct tcp_sock *tp = tcp_sk(sk);
1166 struct request_sock *req = NULL;
1167 __u32 isn = TCP_SKB_CB(skb)->when; 1181 __u32 isn = TCP_SKB_CB(skb)->when;
1168#ifdef CONFIG_SYN_COOKIES 1182#ifdef CONFIG_SYN_COOKIES
1169 int want_cookie = 0; 1183 int want_cookie = 0;
@@ -1202,8 +1216,52 @@ static int tcp_v6_conn_request(struct sock *sk, struct sk_buff *skb)
1202 tcp_clear_options(&tmp_opt); 1216 tcp_clear_options(&tmp_opt);
1203 tmp_opt.mss_clamp = IPV6_MIN_MTU - sizeof(struct tcphdr) - sizeof(struct ipv6hdr); 1217 tmp_opt.mss_clamp = IPV6_MIN_MTU - sizeof(struct tcphdr) - sizeof(struct ipv6hdr);
1204 tmp_opt.user_mss = tp->rx_opt.user_mss; 1218 tmp_opt.user_mss = tp->rx_opt.user_mss;
1219 tcp_parse_options(skb, &tmp_opt, &hash_location, 0);
1220
1221 if (tmp_opt.cookie_plus > 0 &&
1222 tmp_opt.saw_tstamp &&
1223 !tp->rx_opt.cookie_out_never &&
1224 (sysctl_tcp_cookie_size > 0 ||
1225 (tp->cookie_values != NULL &&
1226 tp->cookie_values->cookie_desired > 0))) {
1227 u8 *c;
1228 u32 *d;
1229 u32 *mess = &tmp_ext.cookie_bakery[COOKIE_DIGEST_WORDS];
1230 int l = tmp_opt.cookie_plus - TCPOLEN_COOKIE_BASE;
1231
1232 if (tcp_cookie_generator(&tmp_ext.cookie_bakery[0]) != 0)
1233 goto drop_and_free;
1234
1235 /* Secret recipe starts with IP addresses */
1236 d = &ipv6_hdr(skb)->daddr.s6_addr32[0];
1237 *mess++ ^= *d++;
1238 *mess++ ^= *d++;
1239 *mess++ ^= *d++;
1240 *mess++ ^= *d++;
1241 d = &ipv6_hdr(skb)->saddr.s6_addr32[0];
1242 *mess++ ^= *d++;
1243 *mess++ ^= *d++;
1244 *mess++ ^= *d++;
1245 *mess++ ^= *d++;
1246
1247 /* plus variable length Initiator Cookie */
1248 c = (u8 *)mess;
1249 while (l-- > 0)
1250 *c++ ^= *hash_location++;
1205 1251
1206 tcp_parse_options(skb, &tmp_opt, 0); 1252#ifdef CONFIG_SYN_COOKIES
1253 want_cookie = 0; /* not our kind of cookie */
1254#endif
1255 tmp_ext.cookie_out_never = 0; /* false */
1256 tmp_ext.cookie_plus = tmp_opt.cookie_plus;
1257 } else if (!tp->rx_opt.cookie_in_always) {
1258 /* redundant indications, but ensure initialization. */
1259 tmp_ext.cookie_out_never = 1; /* true */
1260 tmp_ext.cookie_plus = 0;
1261 } else {
1262 goto drop_and_free;
1263 }
1264 tmp_ext.cookie_in_always = tp->rx_opt.cookie_in_always;
1207 1265
1208 if (want_cookie && !tmp_opt.saw_tstamp) 1266 if (want_cookie && !tmp_opt.saw_tstamp)
1209 tcp_clear_options(&tmp_opt); 1267 tcp_clear_options(&tmp_opt);
@@ -1236,23 +1294,21 @@ static int tcp_v6_conn_request(struct sock *sk, struct sk_buff *skb)
1236 1294
1237 isn = tcp_v6_init_sequence(skb); 1295 isn = tcp_v6_init_sequence(skb);
1238 } 1296 }
1239
1240 tcp_rsk(req)->snt_isn = isn; 1297 tcp_rsk(req)->snt_isn = isn;
1241 1298
1242 security_inet_conn_request(sk, skb, req); 1299 security_inet_conn_request(sk, skb, req);
1243 1300
1244 if (tcp_v6_send_synack(sk, req)) 1301 if (tcp_v6_send_synack(sk, req,
1245 goto drop; 1302 (struct request_values *)&tmp_ext) ||
1303 want_cookie)
1304 goto drop_and_free;
1246 1305
1247 if (!want_cookie) { 1306 inet6_csk_reqsk_queue_hash_add(sk, req, TCP_TIMEOUT_INIT);
1248 inet6_csk_reqsk_queue_hash_add(sk, req, TCP_TIMEOUT_INIT); 1307 return 0;
1249 return 0;
1250 }
1251 1308
1309drop_and_free:
1310 reqsk_free(req);
1252drop: 1311drop:
1253 if (req)
1254 reqsk_free(req);
1255
1256 return 0; /* don't send reset */ 1312 return 0; /* don't send reset */
1257} 1313}
1258 1314
@@ -1290,11 +1346,9 @@ static struct sock * tcp_v6_syn_recv_sock(struct sock *sk, struct sk_buff *skb,
1290 1346
1291 memcpy(newnp, np, sizeof(struct ipv6_pinfo)); 1347 memcpy(newnp, np, sizeof(struct ipv6_pinfo));
1292 1348
1293 ipv6_addr_set(&newnp->daddr, 0, 0, htonl(0x0000FFFF), 1349 ipv6_addr_set_v4mapped(newinet->inet_daddr, &newnp->daddr);
1294 newinet->daddr);
1295 1350
1296 ipv6_addr_set(&newnp->saddr, 0, 0, htonl(0x0000FFFF), 1351 ipv6_addr_set_v4mapped(newinet->inet_saddr, &newnp->saddr);
1297 newinet->saddr);
1298 1352
1299 ipv6_addr_copy(&newnp->rcv_saddr, &newnp->saddr); 1353 ipv6_addr_copy(&newnp->rcv_saddr, &newnp->saddr);
1300 1354
@@ -1345,6 +1399,7 @@ static struct sock * tcp_v6_syn_recv_sock(struct sock *sk, struct sk_buff *skb,
1345 } 1399 }
1346 ipv6_addr_copy(&fl.fl6_src, &treq->loc_addr); 1400 ipv6_addr_copy(&fl.fl6_src, &treq->loc_addr);
1347 fl.oif = sk->sk_bound_dev_if; 1401 fl.oif = sk->sk_bound_dev_if;
1402 fl.mark = sk->sk_mark;
1348 fl.fl_ip_dport = inet_rsk(req)->rmt_port; 1403 fl.fl_ip_dport = inet_rsk(req)->rmt_port;
1349 fl.fl_ip_sport = inet_rsk(req)->loc_port; 1404 fl.fl_ip_sport = inet_rsk(req)->loc_port;
1350 security_req_classify_flow(req, &fl); 1405 security_req_classify_flow(req, &fl);
@@ -1431,7 +1486,8 @@ static struct sock * tcp_v6_syn_recv_sock(struct sock *sk, struct sk_buff *skb,
1431 newtp->advmss = dst_metric(dst, RTAX_ADVMSS); 1486 newtp->advmss = dst_metric(dst, RTAX_ADVMSS);
1432 tcp_initialize_rcv_mss(newsk); 1487 tcp_initialize_rcv_mss(newsk);
1433 1488
1434 newinet->daddr = newinet->saddr = newinet->rcv_saddr = LOOPBACK4_IPV6; 1489 newinet->inet_daddr = newinet->inet_saddr = LOOPBACK4_IPV6;
1490 newinet->inet_rcv_saddr = LOOPBACK4_IPV6;
1435 1491
1436#ifdef CONFIG_TCP_MD5SIG 1492#ifdef CONFIG_TCP_MD5SIG
1437 /* Copy over the MD5 key from the original socket */ 1493 /* Copy over the MD5 key from the original socket */
@@ -1448,7 +1504,7 @@ static struct sock * tcp_v6_syn_recv_sock(struct sock *sk, struct sk_buff *skb,
1448 } 1504 }
1449#endif 1505#endif
1450 1506
1451 __inet6_hash(newsk); 1507 __inet6_hash(newsk, NULL);
1452 __inet_inherit_port(sk, newsk); 1508 __inet_inherit_port(sk, newsk);
1453 1509
1454 return newsk; 1510 return newsk;
@@ -1685,8 +1741,11 @@ process:
1685 if (!tcp_prequeue(sk, skb)) 1741 if (!tcp_prequeue(sk, skb))
1686 ret = tcp_v6_do_rcv(sk, skb); 1742 ret = tcp_v6_do_rcv(sk, skb);
1687 } 1743 }
1688 } else 1744 } else if (unlikely(sk_add_backlog(sk, skb))) {
1689 sk_add_backlog(sk, skb); 1745 bh_unlock_sock(sk);
1746 NET_INC_STATS_BH(net, LINUX_MIB_TCPBACKLOGDROP);
1747 goto discard_and_relse;
1748 }
1690 bh_unlock_sock(sk); 1749 bh_unlock_sock(sk);
1691 1750
1692 sock_put(sk); 1751 sock_put(sk);
@@ -1848,7 +1907,7 @@ static int tcp_v6_init_sock(struct sock *sk)
1848 */ 1907 */
1849 tp->snd_ssthresh = TCP_INFINITE_SSTHRESH; 1908 tp->snd_ssthresh = TCP_INFINITE_SSTHRESH;
1850 tp->snd_cwnd_clamp = ~0; 1909 tp->snd_cwnd_clamp = ~0;
1851 tp->mss_cache = 536; 1910 tp->mss_cache = TCP_MSS_DEFAULT;
1852 1911
1853 tp->reordering = sysctl_tcp_reordering; 1912 tp->reordering = sysctl_tcp_reordering;
1854 1913
@@ -1864,6 +1923,19 @@ static int tcp_v6_init_sock(struct sock *sk)
1864 tp->af_specific = &tcp_sock_ipv6_specific; 1923 tp->af_specific = &tcp_sock_ipv6_specific;
1865#endif 1924#endif
1866 1925
1926 /* TCP Cookie Transactions */
1927 if (sysctl_tcp_cookie_size > 0) {
1928 /* Default, cookies without s_data_payload. */
1929 tp->cookie_values =
1930 kzalloc(sizeof(*tp->cookie_values),
1931 sk->sk_allocation);
1932 if (tp->cookie_values != NULL)
1933 kref_init(&tp->cookie_values->kref);
1934 }
1935 /* Presumed zeroed, in order of appearance:
1936 * cookie_in_always, cookie_out_never,
1937 * s_data_constant, s_data_in, s_data_out
1938 */
1867 sk->sk_sndbuf = sysctl_tcp_wmem[1]; 1939 sk->sk_sndbuf = sysctl_tcp_wmem[1];
1868 sk->sk_rcvbuf = sysctl_tcp_rmem[1]; 1940 sk->sk_rcvbuf = sysctl_tcp_rmem[1];
1869 1941
@@ -1931,8 +2003,8 @@ static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
1931 2003
1932 dest = &np->daddr; 2004 dest = &np->daddr;
1933 src = &np->rcv_saddr; 2005 src = &np->rcv_saddr;
1934 destp = ntohs(inet->dport); 2006 destp = ntohs(inet->inet_dport);
1935 srcp = ntohs(inet->sport); 2007 srcp = ntohs(inet->inet_sport);
1936 2008
1937 if (icsk->icsk_pending == ICSK_TIME_RETRANS) { 2009 if (icsk->icsk_pending == ICSK_TIME_RETRANS) {
1938 timer_active = 1; 2010 timer_active = 1;
@@ -2045,7 +2117,7 @@ static struct tcp_seq_afinfo tcp6_seq_afinfo = {
2045 }, 2117 },
2046}; 2118};
2047 2119
2048int tcp6_proc_init(struct net *net) 2120int __net_init tcp6_proc_init(struct net *net)
2049{ 2121{
2050 return tcp_proc_register(net, &tcp6_seq_afinfo); 2122 return tcp_proc_register(net, &tcp6_seq_afinfo);
2051} 2123}
@@ -2109,27 +2181,31 @@ static struct inet_protosw tcpv6_protosw = {
2109 .protocol = IPPROTO_TCP, 2181 .protocol = IPPROTO_TCP,
2110 .prot = &tcpv6_prot, 2182 .prot = &tcpv6_prot,
2111 .ops = &inet6_stream_ops, 2183 .ops = &inet6_stream_ops,
2112 .capability = -1,
2113 .no_check = 0, 2184 .no_check = 0,
2114 .flags = INET_PROTOSW_PERMANENT | 2185 .flags = INET_PROTOSW_PERMANENT |
2115 INET_PROTOSW_ICSK, 2186 INET_PROTOSW_ICSK,
2116}; 2187};
2117 2188
2118static int tcpv6_net_init(struct net *net) 2189static int __net_init tcpv6_net_init(struct net *net)
2119{ 2190{
2120 return inet_ctl_sock_create(&net->ipv6.tcp_sk, PF_INET6, 2191 return inet_ctl_sock_create(&net->ipv6.tcp_sk, PF_INET6,
2121 SOCK_RAW, IPPROTO_TCP, net); 2192 SOCK_RAW, IPPROTO_TCP, net);
2122} 2193}
2123 2194
2124static void tcpv6_net_exit(struct net *net) 2195static void __net_exit tcpv6_net_exit(struct net *net)
2125{ 2196{
2126 inet_ctl_sock_destroy(net->ipv6.tcp_sk); 2197 inet_ctl_sock_destroy(net->ipv6.tcp_sk);
2127 inet_twsk_purge(net, &tcp_hashinfo, &tcp_death_row, AF_INET6); 2198}
2199
2200static void __net_exit tcpv6_net_exit_batch(struct list_head *net_exit_list)
2201{
2202 inet_twsk_purge(&tcp_hashinfo, &tcp_death_row, AF_INET6);
2128} 2203}
2129 2204
2130static struct pernet_operations tcpv6_net_ops = { 2205static struct pernet_operations tcpv6_net_ops = {
2131 .init = tcpv6_net_init, 2206 .init = tcpv6_net_init,
2132 .exit = tcpv6_net_exit, 2207 .exit = tcpv6_net_exit,
2208 .exit_batch = tcpv6_net_exit_batch,
2133}; 2209};
2134 2210
2135int __init tcpv6_init(void) 2211int __init tcpv6_init(void)
diff --git a/net/ipv6/tunnel6.c b/net/ipv6/tunnel6.c
index 51e2832d13a6..fc3c86a47452 100644
--- a/net/ipv6/tunnel6.c
+++ b/net/ipv6/tunnel6.c
@@ -25,6 +25,7 @@
25#include <linux/mutex.h> 25#include <linux/mutex.h>
26#include <linux/netdevice.h> 26#include <linux/netdevice.h>
27#include <linux/skbuff.h> 27#include <linux/skbuff.h>
28#include <linux/slab.h>
28#include <net/ipv6.h> 29#include <net/ipv6.h>
29#include <net/protocol.h> 30#include <net/protocol.h>
30#include <net/xfrm.h> 31#include <net/xfrm.h>
@@ -98,7 +99,7 @@ static int tunnel6_rcv(struct sk_buff *skb)
98 if (!handler->handler(skb)) 99 if (!handler->handler(skb))
99 return 0; 100 return 0;
100 101
101 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0, skb->dev); 102 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
102 103
103drop: 104drop:
104 kfree_skb(skb); 105 kfree_skb(skb);
@@ -116,7 +117,7 @@ static int tunnel46_rcv(struct sk_buff *skb)
116 if (!handler->handler(skb)) 117 if (!handler->handler(skb))
117 return 0; 118 return 0;
118 119
119 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0, skb->dev); 120 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
120 121
121drop: 122drop:
122 kfree_skb(skb); 123 kfree_skb(skb);
diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
index cf538ed5ef6a..90824852f598 100644
--- a/net/ipv6/udp.c
+++ b/net/ipv6/udp.c
@@ -34,6 +34,7 @@
34#include <linux/init.h> 34#include <linux/init.h>
35#include <linux/module.h> 35#include <linux/module.h>
36#include <linux/skbuff.h> 36#include <linux/skbuff.h>
37#include <linux/slab.h>
37#include <asm/uaccess.h> 38#include <asm/uaccess.h>
38 39
39#include <net/ndisc.h> 40#include <net/ndisc.h>
@@ -53,7 +54,7 @@ int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
53{ 54{
54 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr; 55 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
55 const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2); 56 const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
56 __be32 sk_rcv_saddr = inet_sk(sk)->rcv_saddr; 57 __be32 sk1_rcv_saddr = inet_sk(sk)->inet_rcv_saddr;
57 __be32 sk2_rcv_saddr = inet_rcv_saddr(sk2); 58 __be32 sk2_rcv_saddr = inet_rcv_saddr(sk2);
58 int sk_ipv6only = ipv6_only_sock(sk); 59 int sk_ipv6only = ipv6_only_sock(sk);
59 int sk2_ipv6only = inet_v6_ipv6only(sk2); 60 int sk2_ipv6only = inet_v6_ipv6only(sk2);
@@ -63,8 +64,8 @@ int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
63 /* if both are mapped, treat as IPv4 */ 64 /* if both are mapped, treat as IPv4 */
64 if (addr_type == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED) 65 if (addr_type == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED)
65 return (!sk2_ipv6only && 66 return (!sk2_ipv6only &&
66 (!sk_rcv_saddr || !sk2_rcv_saddr || 67 (!sk1_rcv_saddr || !sk2_rcv_saddr ||
67 sk_rcv_saddr == sk2_rcv_saddr)); 68 sk1_rcv_saddr == sk2_rcv_saddr));
68 69
69 if (addr_type2 == IPV6_ADDR_ANY && 70 if (addr_type2 == IPV6_ADDR_ANY &&
70 !(sk2_ipv6only && addr_type == IPV6_ADDR_MAPPED)) 71 !(sk2_ipv6only && addr_type == IPV6_ADDR_MAPPED))
@@ -81,9 +82,33 @@ int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
81 return 0; 82 return 0;
82} 83}
83 84
85static unsigned int udp6_portaddr_hash(struct net *net,
86 const struct in6_addr *addr6,
87 unsigned int port)
88{
89 unsigned int hash, mix = net_hash_mix(net);
90
91 if (ipv6_addr_any(addr6))
92 hash = jhash_1word(0, mix);
93 else if (ipv6_addr_v4mapped(addr6))
94 hash = jhash_1word(addr6->s6_addr32[3], mix);
95 else
96 hash = jhash2(addr6->s6_addr32, 4, mix);
97
98 return hash ^ port;
99}
100
101
84int udp_v6_get_port(struct sock *sk, unsigned short snum) 102int udp_v6_get_port(struct sock *sk, unsigned short snum)
85{ 103{
86 return udp_lib_get_port(sk, snum, ipv6_rcv_saddr_equal); 104 unsigned int hash2_nulladdr =
105 udp6_portaddr_hash(sock_net(sk), &in6addr_any, snum);
106 unsigned int hash2_partial =
107 udp6_portaddr_hash(sock_net(sk), &inet6_sk(sk)->rcv_saddr, 0);
108
109 /* precompute partial secondary hash */
110 udp_sk(sk)->udp_portaddr_hash = hash2_partial;
111 return udp_lib_get_port(sk, snum, ipv6_rcv_saddr_equal, hash2_nulladdr);
87} 112}
88 113
89static inline int compute_score(struct sock *sk, struct net *net, 114static inline int compute_score(struct sock *sk, struct net *net,
@@ -94,14 +119,14 @@ static inline int compute_score(struct sock *sk, struct net *net,
94{ 119{
95 int score = -1; 120 int score = -1;
96 121
97 if (net_eq(sock_net(sk), net) && sk->sk_hash == hnum && 122 if (net_eq(sock_net(sk), net) && udp_sk(sk)->udp_port_hash == hnum &&
98 sk->sk_family == PF_INET6) { 123 sk->sk_family == PF_INET6) {
99 struct ipv6_pinfo *np = inet6_sk(sk); 124 struct ipv6_pinfo *np = inet6_sk(sk);
100 struct inet_sock *inet = inet_sk(sk); 125 struct inet_sock *inet = inet_sk(sk);
101 126
102 score = 0; 127 score = 0;
103 if (inet->dport) { 128 if (inet->inet_dport) {
104 if (inet->dport != sport) 129 if (inet->inet_dport != sport)
105 return -1; 130 return -1;
106 score++; 131 score++;
107 } 132 }
@@ -124,6 +149,86 @@ static inline int compute_score(struct sock *sk, struct net *net,
124 return score; 149 return score;
125} 150}
126 151
152#define SCORE2_MAX (1 + 1 + 1)
153static inline int compute_score2(struct sock *sk, struct net *net,
154 const struct in6_addr *saddr, __be16 sport,
155 const struct in6_addr *daddr, unsigned short hnum,
156 int dif)
157{
158 int score = -1;
159
160 if (net_eq(sock_net(sk), net) && udp_sk(sk)->udp_port_hash == hnum &&
161 sk->sk_family == PF_INET6) {
162 struct ipv6_pinfo *np = inet6_sk(sk);
163 struct inet_sock *inet = inet_sk(sk);
164
165 if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
166 return -1;
167 score = 0;
168 if (inet->inet_dport) {
169 if (inet->inet_dport != sport)
170 return -1;
171 score++;
172 }
173 if (!ipv6_addr_any(&np->daddr)) {
174 if (!ipv6_addr_equal(&np->daddr, saddr))
175 return -1;
176 score++;
177 }
178 if (sk->sk_bound_dev_if) {
179 if (sk->sk_bound_dev_if != dif)
180 return -1;
181 score++;
182 }
183 }
184 return score;
185}
186
187
188/* called with read_rcu_lock() */
189static struct sock *udp6_lib_lookup2(struct net *net,
190 const struct in6_addr *saddr, __be16 sport,
191 const struct in6_addr *daddr, unsigned int hnum, int dif,
192 struct udp_hslot *hslot2, unsigned int slot2)
193{
194 struct sock *sk, *result;
195 struct hlist_nulls_node *node;
196 int score, badness;
197
198begin:
199 result = NULL;
200 badness = -1;
201 udp_portaddr_for_each_entry_rcu(sk, node, &hslot2->head) {
202 score = compute_score2(sk, net, saddr, sport,
203 daddr, hnum, dif);
204 if (score > badness) {
205 result = sk;
206 badness = score;
207 if (score == SCORE2_MAX)
208 goto exact_match;
209 }
210 }
211 /*
212 * if the nulls value we got at the end of this lookup is
213 * not the expected one, we must restart lookup.
214 * We probably met an item that was moved to another chain.
215 */
216 if (get_nulls_value(node) != slot2)
217 goto begin;
218
219 if (result) {
220exact_match:
221 if (unlikely(!atomic_inc_not_zero(&result->sk_refcnt)))
222 result = NULL;
223 else if (unlikely(compute_score2(result, net, saddr, sport,
224 daddr, hnum, dif) < badness)) {
225 sock_put(result);
226 goto begin;
227 }
228 }
229 return result;
230}
231
127static struct sock *__udp6_lib_lookup(struct net *net, 232static struct sock *__udp6_lib_lookup(struct net *net,
128 struct in6_addr *saddr, __be16 sport, 233 struct in6_addr *saddr, __be16 sport,
129 struct in6_addr *daddr, __be16 dport, 234 struct in6_addr *daddr, __be16 dport,
@@ -132,11 +237,35 @@ static struct sock *__udp6_lib_lookup(struct net *net,
132 struct sock *sk, *result; 237 struct sock *sk, *result;
133 struct hlist_nulls_node *node; 238 struct hlist_nulls_node *node;
134 unsigned short hnum = ntohs(dport); 239 unsigned short hnum = ntohs(dport);
135 unsigned int hash = udp_hashfn(net, hnum); 240 unsigned int hash2, slot2, slot = udp_hashfn(net, hnum, udptable->mask);
136 struct udp_hslot *hslot = &udptable->hash[hash]; 241 struct udp_hslot *hslot2, *hslot = &udptable->hash[slot];
137 int score, badness; 242 int score, badness;
138 243
139 rcu_read_lock(); 244 rcu_read_lock();
245 if (hslot->count > 10) {
246 hash2 = udp6_portaddr_hash(net, daddr, hnum);
247 slot2 = hash2 & udptable->mask;
248 hslot2 = &udptable->hash2[slot2];
249 if (hslot->count < hslot2->count)
250 goto begin;
251
252 result = udp6_lib_lookup2(net, saddr, sport,
253 daddr, hnum, dif,
254 hslot2, slot2);
255 if (!result) {
256 hash2 = udp6_portaddr_hash(net, &in6addr_any, hnum);
257 slot2 = hash2 & udptable->mask;
258 hslot2 = &udptable->hash2[slot2];
259 if (hslot->count < hslot2->count)
260 goto begin;
261
262 result = udp6_lib_lookup2(net, saddr, sport,
263 &in6addr_any, hnum, dif,
264 hslot2, slot2);
265 }
266 rcu_read_unlock();
267 return result;
268 }
140begin: 269begin:
141 result = NULL; 270 result = NULL;
142 badness = -1; 271 badness = -1;
@@ -152,7 +281,7 @@ begin:
152 * not the expected one, we must restart lookup. 281 * not the expected one, we must restart lookup.
153 * We probably met an item that was moved to another chain. 282 * We probably met an item that was moved to another chain.
154 */ 283 */
155 if (get_nulls_value(node) != hash) 284 if (get_nulls_value(node) != slot)
156 goto begin; 285 goto begin;
157 286
158 if (result) { 287 if (result) {
@@ -194,7 +323,7 @@ int udpv6_recvmsg(struct kiocb *iocb, struct sock *sk,
194 struct ipv6_pinfo *np = inet6_sk(sk); 323 struct ipv6_pinfo *np = inet6_sk(sk);
195 struct inet_sock *inet = inet_sk(sk); 324 struct inet_sock *inet = inet_sk(sk);
196 struct sk_buff *skb; 325 struct sk_buff *skb;
197 unsigned int ulen, copied; 326 unsigned int ulen;
198 int peeked; 327 int peeked;
199 int err; 328 int err;
200 int is_udplite = IS_UDPLITE(sk); 329 int is_udplite = IS_UDPLITE(sk);
@@ -213,10 +342,9 @@ try_again:
213 goto out; 342 goto out;
214 343
215 ulen = skb->len - sizeof(struct udphdr); 344 ulen = skb->len - sizeof(struct udphdr);
216 copied = len; 345 if (len > ulen)
217 if (copied > ulen) 346 len = ulen;
218 copied = ulen; 347 else if (len < ulen)
219 else if (copied < ulen)
220 msg->msg_flags |= MSG_TRUNC; 348 msg->msg_flags |= MSG_TRUNC;
221 349
222 is_udp4 = (skb->protocol == htons(ETH_P_IP)); 350 is_udp4 = (skb->protocol == htons(ETH_P_IP));
@@ -227,14 +355,14 @@ try_again:
227 * coverage checksum (UDP-Lite), do it before the copy. 355 * coverage checksum (UDP-Lite), do it before the copy.
228 */ 356 */
229 357
230 if (copied < ulen || UDP_SKB_CB(skb)->partial_cov) { 358 if (len < ulen || UDP_SKB_CB(skb)->partial_cov) {
231 if (udp_lib_checksum_complete(skb)) 359 if (udp_lib_checksum_complete(skb))
232 goto csum_copy_err; 360 goto csum_copy_err;
233 } 361 }
234 362
235 if (skb_csum_unnecessary(skb)) 363 if (skb_csum_unnecessary(skb))
236 err = skb_copy_datagram_iovec(skb, sizeof(struct udphdr), 364 err = skb_copy_datagram_iovec(skb, sizeof(struct udphdr),
237 msg->msg_iov, copied ); 365 msg->msg_iov,len);
238 else { 366 else {
239 err = skb_copy_and_csum_datagram_iovec(skb, sizeof(struct udphdr), msg->msg_iov); 367 err = skb_copy_and_csum_datagram_iovec(skb, sizeof(struct udphdr), msg->msg_iov);
240 if (err == -EINVAL) 368 if (err == -EINVAL)
@@ -252,7 +380,7 @@ try_again:
252 UDP_MIB_INDATAGRAMS, is_udplite); 380 UDP_MIB_INDATAGRAMS, is_udplite);
253 } 381 }
254 382
255 sock_recv_timestamp(msg, sk, skb); 383 sock_recv_ts_and_drops(msg, sk, skb);
256 384
257 /* Copy the address. */ 385 /* Copy the address. */
258 if (msg->msg_name) { 386 if (msg->msg_name) {
@@ -265,8 +393,8 @@ try_again:
265 sin6->sin6_scope_id = 0; 393 sin6->sin6_scope_id = 0;
266 394
267 if (is_udp4) 395 if (is_udp4)
268 ipv6_addr_set(&sin6->sin6_addr, 0, 0, 396 ipv6_addr_set_v4mapped(ip_hdr(skb)->saddr,
269 htonl(0xffff), ip_hdr(skb)->saddr); 397 &sin6->sin6_addr);
270 else { 398 else {
271 ipv6_addr_copy(&sin6->sin6_addr, 399 ipv6_addr_copy(&sin6->sin6_addr,
272 &ipv6_hdr(skb)->saddr); 400 &ipv6_hdr(skb)->saddr);
@@ -283,7 +411,7 @@ try_again:
283 datagram_recv_ctl(sk, msg, skb); 411 datagram_recv_ctl(sk, msg, skb);
284 } 412 }
285 413
286 err = copied; 414 err = len;
287 if (flags & MSG_TRUNC) 415 if (flags & MSG_TRUNC)
288 err = ulen; 416 err = ulen;
289 417
@@ -383,18 +511,18 @@ int udpv6_queue_rcv_skb(struct sock * sk, struct sk_buff *skb)
383 goto drop; 511 goto drop;
384 } 512 }
385 513
386 if ((rc = sock_queue_rcv_skb(sk,skb)) < 0) { 514 if ((rc = sock_queue_rcv_skb(sk, skb)) < 0) {
387 /* Note that an ENOMEM error is charged twice */ 515 /* Note that an ENOMEM error is charged twice */
388 if (rc == -ENOMEM) { 516 if (rc == -ENOMEM)
389 UDP6_INC_STATS_BH(sock_net(sk), 517 UDP6_INC_STATS_BH(sock_net(sk),
390 UDP_MIB_RCVBUFERRORS, is_udplite); 518 UDP_MIB_RCVBUFERRORS, is_udplite);
391 atomic_inc(&sk->sk_drops); 519 goto drop_no_sk_drops_inc;
392 }
393 goto drop;
394 } 520 }
395 521
396 return 0; 522 return 0;
397drop: 523drop:
524 atomic_inc(&sk->sk_drops);
525drop_no_sk_drops_inc:
398 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite); 526 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
399 kfree_skb(skb); 527 kfree_skb(skb);
400 return -1; 528 return -1;
@@ -415,10 +543,11 @@ static struct sock *udp_v6_mcast_next(struct net *net, struct sock *sk,
415 if (!net_eq(sock_net(s), net)) 543 if (!net_eq(sock_net(s), net))
416 continue; 544 continue;
417 545
418 if (s->sk_hash == num && s->sk_family == PF_INET6) { 546 if (udp_sk(s)->udp_port_hash == num &&
547 s->sk_family == PF_INET6) {
419 struct ipv6_pinfo *np = inet6_sk(s); 548 struct ipv6_pinfo *np = inet6_sk(s);
420 if (inet->dport) { 549 if (inet->inet_dport) {
421 if (inet->dport != rmt_port) 550 if (inet->inet_dport != rmt_port)
422 continue; 551 continue;
423 } 552 }
424 if (!ipv6_addr_any(&np->daddr) && 553 if (!ipv6_addr_any(&np->daddr) &&
@@ -440,6 +569,37 @@ static struct sock *udp_v6_mcast_next(struct net *net, struct sock *sk,
440 return NULL; 569 return NULL;
441} 570}
442 571
572static void flush_stack(struct sock **stack, unsigned int count,
573 struct sk_buff *skb, unsigned int final)
574{
575 unsigned int i;
576 struct sock *sk;
577 struct sk_buff *skb1;
578
579 for (i = 0; i < count; i++) {
580 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
581
582 sk = stack[i];
583 if (skb1) {
584 bh_lock_sock(sk);
585 if (!sock_owned_by_user(sk))
586 udpv6_queue_rcv_skb(sk, skb1);
587 else if (sk_add_backlog(sk, skb1)) {
588 kfree_skb(skb1);
589 bh_unlock_sock(sk);
590 goto drop;
591 }
592 bh_unlock_sock(sk);
593 continue;
594 }
595drop:
596 atomic_inc(&sk->sk_drops);
597 UDP6_INC_STATS_BH(sock_net(sk),
598 UDP_MIB_RCVBUFERRORS, IS_UDPLITE(sk));
599 UDP6_INC_STATS_BH(sock_net(sk),
600 UDP_MIB_INERRORS, IS_UDPLITE(sk));
601 }
602}
443/* 603/*
444 * Note: called only from the BH handler context, 604 * Note: called only from the BH handler context,
445 * so we don't need to lock the hashes. 605 * so we don't need to lock the hashes.
@@ -448,41 +608,43 @@ static int __udp6_lib_mcast_deliver(struct net *net, struct sk_buff *skb,
448 struct in6_addr *saddr, struct in6_addr *daddr, 608 struct in6_addr *saddr, struct in6_addr *daddr,
449 struct udp_table *udptable) 609 struct udp_table *udptable)
450{ 610{
451 struct sock *sk, *sk2; 611 struct sock *sk, *stack[256 / sizeof(struct sock *)];
452 const struct udphdr *uh = udp_hdr(skb); 612 const struct udphdr *uh = udp_hdr(skb);
453 struct udp_hslot *hslot = &udptable->hash[udp_hashfn(net, ntohs(uh->dest))]; 613 struct udp_hslot *hslot = udp_hashslot(udptable, net, ntohs(uh->dest));
454 int dif; 614 int dif;
615 unsigned int i, count = 0;
455 616
456 spin_lock(&hslot->lock); 617 spin_lock(&hslot->lock);
457 sk = sk_nulls_head(&hslot->head); 618 sk = sk_nulls_head(&hslot->head);
458 dif = inet6_iif(skb); 619 dif = inet6_iif(skb);
459 sk = udp_v6_mcast_next(net, sk, uh->dest, daddr, uh->source, saddr, dif); 620 sk = udp_v6_mcast_next(net, sk, uh->dest, daddr, uh->source, saddr, dif);
460 if (!sk) { 621 while (sk) {
461 kfree_skb(skb); 622 stack[count++] = sk;
462 goto out; 623 sk = udp_v6_mcast_next(net, sk_nulls_next(sk), uh->dest, daddr,
463 } 624 uh->source, saddr, dif);
464 625 if (unlikely(count == ARRAY_SIZE(stack))) {
465 sk2 = sk; 626 if (!sk)
466 while ((sk2 = udp_v6_mcast_next(net, sk_nulls_next(sk2), uh->dest, daddr, 627 break;
467 uh->source, saddr, dif))) { 628 flush_stack(stack, count, skb, ~0);
468 struct sk_buff *buff = skb_clone(skb, GFP_ATOMIC); 629 count = 0;
469 if (buff) {
470 bh_lock_sock(sk2);
471 if (!sock_owned_by_user(sk2))
472 udpv6_queue_rcv_skb(sk2, buff);
473 else
474 sk_add_backlog(sk2, buff);
475 bh_unlock_sock(sk2);
476 } 630 }
477 } 631 }
478 bh_lock_sock(sk); 632 /*
479 if (!sock_owned_by_user(sk)) 633 * before releasing the lock, we must take reference on sockets
480 udpv6_queue_rcv_skb(sk, skb); 634 */
481 else 635 for (i = 0; i < count; i++)
482 sk_add_backlog(sk, skb); 636 sock_hold(stack[i]);
483 bh_unlock_sock(sk); 637
484out:
485 spin_unlock(&hslot->lock); 638 spin_unlock(&hslot->lock);
639
640 if (count) {
641 flush_stack(stack, count, skb, count - 1);
642
643 for (i = 0; i < count; i++)
644 sock_put(stack[i]);
645 } else {
646 kfree_skb(skb);
647 }
486 return 0; 648 return 0;
487} 649}
488 650
@@ -523,12 +685,11 @@ static inline int udp6_csum_init(struct sk_buff *skb, struct udphdr *uh,
523int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable, 685int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
524 int proto) 686 int proto)
525{ 687{
688 struct net *net = dev_net(skb->dev);
526 struct sock *sk; 689 struct sock *sk;
527 struct udphdr *uh; 690 struct udphdr *uh;
528 struct net_device *dev = skb->dev;
529 struct in6_addr *saddr, *daddr; 691 struct in6_addr *saddr, *daddr;
530 u32 ulen = 0; 692 u32 ulen = 0;
531 struct net *net = dev_net(skb->dev);
532 693
533 if (!pskb_may_pull(skb, sizeof(struct udphdr))) 694 if (!pskb_may_pull(skb, sizeof(struct udphdr)))
534 goto short_packet; 695 goto short_packet;
@@ -587,7 +748,7 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
587 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, 748 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS,
588 proto == IPPROTO_UDPLITE); 749 proto == IPPROTO_UDPLITE);
589 750
590 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0, dev); 751 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
591 752
592 kfree_skb(skb); 753 kfree_skb(skb);
593 return 0; 754 return 0;
@@ -598,8 +759,12 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
598 bh_lock_sock(sk); 759 bh_lock_sock(sk);
599 if (!sock_owned_by_user(sk)) 760 if (!sock_owned_by_user(sk))
600 udpv6_queue_rcv_skb(sk, skb); 761 udpv6_queue_rcv_skb(sk, skb);
601 else 762 else if (sk_add_backlog(sk, skb)) {
602 sk_add_backlog(sk, skb); 763 atomic_inc(&sk->sk_drops);
764 bh_unlock_sock(sk);
765 sock_put(sk);
766 goto discard;
767 }
603 bh_unlock_sock(sk); 768 bh_unlock_sock(sk);
604 sock_put(sk); 769 sock_put(sk);
605 return 0; 770 return 0;
@@ -792,7 +957,7 @@ int udpv6_sendmsg(struct kiocb *iocb, struct sock *sk,
792 if (ipv6_addr_v4mapped(daddr)) { 957 if (ipv6_addr_v4mapped(daddr)) {
793 struct sockaddr_in sin; 958 struct sockaddr_in sin;
794 sin.sin_family = AF_INET; 959 sin.sin_family = AF_INET;
795 sin.sin_port = sin6 ? sin6->sin6_port : inet->dport; 960 sin.sin_port = sin6 ? sin6->sin6_port : inet->inet_dport;
796 sin.sin_addr.s_addr = daddr->s6_addr32[3]; 961 sin.sin_addr.s_addr = daddr->s6_addr32[3];
797 msg->msg_name = &sin; 962 msg->msg_name = &sin;
798 msg->msg_namelen = sizeof(sin); 963 msg->msg_namelen = sizeof(sin);
@@ -865,7 +1030,7 @@ do_udp_sendmsg:
865 if (sk->sk_state != TCP_ESTABLISHED) 1030 if (sk->sk_state != TCP_ESTABLISHED)
866 return -EDESTADDRREQ; 1031 return -EDESTADDRREQ;
867 1032
868 fl.fl_ip_dport = inet->dport; 1033 fl.fl_ip_dport = inet->inet_dport;
869 daddr = &np->daddr; 1034 daddr = &np->daddr;
870 fl.fl6_flowlabel = np->flow_label; 1035 fl.fl6_flowlabel = np->flow_label;
871 connected = 1; 1036 connected = 1;
@@ -877,6 +1042,8 @@ do_udp_sendmsg:
877 if (!fl.oif) 1042 if (!fl.oif)
878 fl.oif = np->sticky_pktinfo.ipi6_ifindex; 1043 fl.oif = np->sticky_pktinfo.ipi6_ifindex;
879 1044
1045 fl.mark = sk->sk_mark;
1046
880 if (msg->msg_controllen) { 1047 if (msg->msg_controllen) {
881 opt = &opt_space; 1048 opt = &opt_space;
882 memset(opt, 0, sizeof(struct ipv6_txoptions)); 1049 memset(opt, 0, sizeof(struct ipv6_txoptions));
@@ -909,7 +1076,7 @@ do_udp_sendmsg:
909 fl.fl6_dst.s6_addr[15] = 0x1; /* :: means loopback (BSD'ism) */ 1076 fl.fl6_dst.s6_addr[15] = 0x1; /* :: means loopback (BSD'ism) */
910 if (ipv6_addr_any(&fl.fl6_src) && !ipv6_addr_any(&np->saddr)) 1077 if (ipv6_addr_any(&fl.fl6_src) && !ipv6_addr_any(&np->saddr))
911 ipv6_addr_copy(&fl.fl6_src, &np->saddr); 1078 ipv6_addr_copy(&fl.fl6_src, &np->saddr);
912 fl.fl_ip_sport = inet->sport; 1079 fl.fl_ip_sport = inet->inet_sport;
913 1080
914 /* merge ip6_build_xmit from ip6_output */ 1081 /* merge ip6_build_xmit from ip6_output */
915 if (opt && opt->srcrt) { 1082 if (opt && opt->srcrt) {
@@ -1190,10 +1357,10 @@ static void udp6_sock_seq_show(struct seq_file *seq, struct sock *sp, int bucket
1190 1357
1191 dest = &np->daddr; 1358 dest = &np->daddr;
1192 src = &np->rcv_saddr; 1359 src = &np->rcv_saddr;
1193 destp = ntohs(inet->dport); 1360 destp = ntohs(inet->inet_dport);
1194 srcp = ntohs(inet->sport); 1361 srcp = ntohs(inet->inet_sport);
1195 seq_printf(seq, 1362 seq_printf(seq,
1196 "%4d: %08X%08X%08X%08X:%04X %08X%08X%08X%08X:%04X " 1363 "%5d: %08X%08X%08X%08X:%04X %08X%08X%08X%08X:%04X "
1197 "%02X %08X:%08X %02X:%08lX %08X %5d %8d %lu %d %p %d\n", 1364 "%02X %08X:%08X %02X:%08lX %08X %5d %8d %lu %d %p %d\n",
1198 bucket, 1365 bucket,
1199 src->s6_addr32[0], src->s6_addr32[1], 1366 src->s6_addr32[0], src->s6_addr32[1],
@@ -1236,7 +1403,7 @@ static struct udp_seq_afinfo udp6_seq_afinfo = {
1236 }, 1403 },
1237}; 1404};
1238 1405
1239int udp6_proc_init(struct net *net) 1406int __net_init udp6_proc_init(struct net *net)
1240{ 1407{
1241 return udp_proc_register(net, &udp6_seq_afinfo); 1408 return udp_proc_register(net, &udp6_seq_afinfo);
1242} 1409}
@@ -1282,7 +1449,6 @@ static struct inet_protosw udpv6_protosw = {
1282 .protocol = IPPROTO_UDP, 1449 .protocol = IPPROTO_UDP,
1283 .prot = &udpv6_prot, 1450 .prot = &udpv6_prot,
1284 .ops = &inet6_dgram_ops, 1451 .ops = &inet6_dgram_ops,
1285 .capability =-1,
1286 .no_check = UDP_CSUM_DEFAULT, 1452 .no_check = UDP_CSUM_DEFAULT,
1287 .flags = INET_PROTOSW_PERMANENT, 1453 .flags = INET_PROTOSW_PERMANENT,
1288}; 1454};
diff --git a/net/ipv6/udplite.c b/net/ipv6/udplite.c
index d737a27ee010..5f48fadc27f7 100644
--- a/net/ipv6/udplite.c
+++ b/net/ipv6/udplite.c
@@ -62,7 +62,6 @@ static struct inet_protosw udplite6_protosw = {
62 .protocol = IPPROTO_UDPLITE, 62 .protocol = IPPROTO_UDPLITE,
63 .prot = &udplitev6_prot, 63 .prot = &udplitev6_prot,
64 .ops = &inet6_dgram_ops, 64 .ops = &inet6_dgram_ops,
65 .capability = -1,
66 .no_check = 0, 65 .no_check = 0,
67 .flags = INET_PROTOSW_PERMANENT, 66 .flags = INET_PROTOSW_PERMANENT,
68}; 67};
@@ -105,12 +104,12 @@ static struct udp_seq_afinfo udplite6_seq_afinfo = {
105 }, 104 },
106}; 105};
107 106
108static int udplite6_proc_init_net(struct net *net) 107static int __net_init udplite6_proc_init_net(struct net *net)
109{ 108{
110 return udp_proc_register(net, &udplite6_seq_afinfo); 109 return udp_proc_register(net, &udplite6_seq_afinfo);
111} 110}
112 111
113static void udplite6_proc_exit_net(struct net *net) 112static void __net_exit udplite6_proc_exit_net(struct net *net)
114{ 113{
115 udp_proc_unregister(net, &udplite6_seq_afinfo); 114 udp_proc_unregister(net, &udplite6_seq_afinfo);
116} 115}
diff --git a/net/ipv6/xfrm6_input.c b/net/ipv6/xfrm6_input.c
index 9084582d236b..2bc98ede1235 100644
--- a/net/ipv6/xfrm6_input.c
+++ b/net/ipv6/xfrm6_input.c
@@ -101,7 +101,7 @@ int xfrm6_input_addr(struct sk_buff *skb, xfrm_address_t *daddr,
101 break; 101 break;
102 } 102 }
103 103
104 x = xfrm_state_lookup_byaddr(net, dst, src, proto, AF_INET6); 104 x = xfrm_state_lookup_byaddr(net, skb->mark, dst, src, proto, AF_INET6);
105 if (!x) 105 if (!x)
106 continue; 106 continue;
107 107
diff --git a/net/ipv6/xfrm6_mode_tunnel.c b/net/ipv6/xfrm6_mode_tunnel.c
index 3927832227b9..b809812c8d30 100644
--- a/net/ipv6/xfrm6_mode_tunnel.c
+++ b/net/ipv6/xfrm6_mode_tunnel.c
@@ -5,6 +5,7 @@
5 * Copyright (c) 2004-2006 Herbert Xu <herbert@gondor.apana.org.au> 5 * Copyright (c) 2004-2006 Herbert Xu <herbert@gondor.apana.org.au>
6 */ 6 */
7 7
8#include <linux/gfp.h>
8#include <linux/init.h> 9#include <linux/init.h>
9#include <linux/kernel.h> 10#include <linux/kernel.h>
10#include <linux/module.h> 11#include <linux/module.h>
diff --git a/net/ipv6/xfrm6_output.c b/net/ipv6/xfrm6_output.c
index c4f4eef032a3..0c92112dcba3 100644
--- a/net/ipv6/xfrm6_output.c
+++ b/net/ipv6/xfrm6_output.c
@@ -38,7 +38,7 @@ static int xfrm6_tunnel_check_size(struct sk_buff *skb)
38 38
39 if (!skb->local_df && skb->len > mtu) { 39 if (!skb->local_df && skb->len > mtu) {
40 skb->dev = dst->dev; 40 skb->dev = dst->dev;
41 icmpv6_send(skb, ICMPV6_PKT_TOOBIG, 0, mtu, skb->dev); 41 icmpv6_send(skb, ICMPV6_PKT_TOOBIG, 0, mtu);
42 ret = -EMSGSIZE; 42 ret = -EMSGSIZE;
43 } 43 }
44 44
diff --git a/net/ipv6/xfrm6_policy.c b/net/ipv6/xfrm6_policy.c
index 8ec3d45cd1d9..00bf7c962b7e 100644
--- a/net/ipv6/xfrm6_policy.c
+++ b/net/ipv6/xfrm6_policy.c
@@ -24,7 +24,6 @@
24#include <net/mip6.h> 24#include <net/mip6.h>
25#endif 25#endif
26 26
27static struct dst_ops xfrm6_dst_ops;
28static struct xfrm_policy_afinfo xfrm6_policy_afinfo; 27static struct xfrm_policy_afinfo xfrm6_policy_afinfo;
29 28
30static struct dst_entry *xfrm6_dst_lookup(struct net *net, int tos, 29static struct dst_entry *xfrm6_dst_lookup(struct net *net, int tos,
@@ -117,14 +116,15 @@ static int xfrm6_init_path(struct xfrm_dst *path, struct dst_entry *dst,
117 return 0; 116 return 0;
118} 117}
119 118
120static int xfrm6_fill_dst(struct xfrm_dst *xdst, struct net_device *dev) 119static int xfrm6_fill_dst(struct xfrm_dst *xdst, struct net_device *dev,
120 struct flowi *fl)
121{ 121{
122 struct rt6_info *rt = (struct rt6_info*)xdst->route; 122 struct rt6_info *rt = (struct rt6_info*)xdst->route;
123 123
124 xdst->u.dst.dev = dev; 124 xdst->u.dst.dev = dev;
125 dev_hold(dev); 125 dev_hold(dev);
126 126
127 xdst->u.rt6.rt6i_idev = in6_dev_get(rt->u.dst.dev); 127 xdst->u.rt6.rt6i_idev = in6_dev_get(dev);
128 if (!xdst->u.rt6.rt6i_idev) 128 if (!xdst->u.rt6.rt6i_idev)
129 return -ENODEV; 129 return -ENODEV;
130 130
@@ -224,8 +224,10 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
224 224
225static inline int xfrm6_garbage_collect(struct dst_ops *ops) 225static inline int xfrm6_garbage_collect(struct dst_ops *ops)
226{ 226{
227 xfrm6_policy_afinfo.garbage_collect(&init_net); 227 struct net *net = container_of(ops, struct net, xfrm.xfrm6_dst_ops);
228 return (atomic_read(&xfrm6_dst_ops.entries) > xfrm6_dst_ops.gc_thresh*2); 228
229 xfrm6_policy_afinfo.garbage_collect(net);
230 return (atomic_read(&ops->entries) > ops->gc_thresh * 2);
229} 231}
230 232
231static void xfrm6_update_pmtu(struct dst_entry *dst, u32 mtu) 233static void xfrm6_update_pmtu(struct dst_entry *dst, u32 mtu)
@@ -309,9 +311,8 @@ static void xfrm6_policy_fini(void)
309#ifdef CONFIG_SYSCTL 311#ifdef CONFIG_SYSCTL
310static struct ctl_table xfrm6_policy_table[] = { 312static struct ctl_table xfrm6_policy_table[] = {
311 { 313 {
312 .ctl_name = CTL_UNNUMBERED,
313 .procname = "xfrm6_gc_thresh", 314 .procname = "xfrm6_gc_thresh",
314 .data = &xfrm6_dst_ops.gc_thresh, 315 .data = &init_net.xfrm.xfrm6_dst_ops.gc_thresh,
315 .maxlen = sizeof(int), 316 .maxlen = sizeof(int),
316 .mode = 0644, 317 .mode = 0644,
317 .proc_handler = proc_dointvec, 318 .proc_handler = proc_dointvec,
@@ -327,13 +328,6 @@ int __init xfrm6_init(void)
327 int ret; 328 int ret;
328 unsigned int gc_thresh; 329 unsigned int gc_thresh;
329 330
330 ret = xfrm6_policy_init();
331 if (ret)
332 goto out;
333
334 ret = xfrm6_state_init();
335 if (ret)
336 goto out_policy;
337 /* 331 /*
338 * We need a good default value for the xfrm6 gc threshold. 332 * We need a good default value for the xfrm6 gc threshold.
339 * In ipv4 we set it to the route hash table size * 8, which 333 * In ipv4 we set it to the route hash table size * 8, which
@@ -347,6 +341,15 @@ int __init xfrm6_init(void)
347 */ 341 */
348 gc_thresh = FIB6_TABLE_HASHSZ * 8; 342 gc_thresh = FIB6_TABLE_HASHSZ * 8;
349 xfrm6_dst_ops.gc_thresh = (gc_thresh < 1024) ? 1024 : gc_thresh; 343 xfrm6_dst_ops.gc_thresh = (gc_thresh < 1024) ? 1024 : gc_thresh;
344
345 ret = xfrm6_policy_init();
346 if (ret)
347 goto out;
348
349 ret = xfrm6_state_init();
350 if (ret)
351 goto out_policy;
352
350#ifdef CONFIG_SYSCTL 353#ifdef CONFIG_SYSCTL
351 sysctl_hdr = register_net_sysctl_table(&init_net, net_ipv6_ctl_path, 354 sysctl_hdr = register_net_sysctl_table(&init_net, net_ipv6_ctl_path,
352 xfrm6_policy_table); 355 xfrm6_policy_table);
diff --git a/net/ipv6/xfrm6_tunnel.c b/net/ipv6/xfrm6_tunnel.c
index 81a95c00e503..2ce3a8278f26 100644
--- a/net/ipv6/xfrm6_tunnel.c
+++ b/net/ipv6/xfrm6_tunnel.c
@@ -23,41 +23,51 @@
23 */ 23 */
24#include <linux/module.h> 24#include <linux/module.h>
25#include <linux/xfrm.h> 25#include <linux/xfrm.h>
26#include <linux/list.h> 26#include <linux/slab.h>
27#include <linux/rculist.h>
27#include <net/ip.h> 28#include <net/ip.h>
28#include <net/xfrm.h> 29#include <net/xfrm.h>
29#include <net/ipv6.h> 30#include <net/ipv6.h>
30#include <linux/ipv6.h> 31#include <linux/ipv6.h>
31#include <linux/icmpv6.h> 32#include <linux/icmpv6.h>
32#include <linux/mutex.h> 33#include <linux/mutex.h>
34#include <net/netns/generic.h>
35
36#define XFRM6_TUNNEL_SPI_BYADDR_HSIZE 256
37#define XFRM6_TUNNEL_SPI_BYSPI_HSIZE 256
38
39#define XFRM6_TUNNEL_SPI_MIN 1
40#define XFRM6_TUNNEL_SPI_MAX 0xffffffff
41
42struct xfrm6_tunnel_net {
43 struct hlist_head spi_byaddr[XFRM6_TUNNEL_SPI_BYADDR_HSIZE];
44 struct hlist_head spi_byspi[XFRM6_TUNNEL_SPI_BYSPI_HSIZE];
45 u32 spi;
46};
47
48static int xfrm6_tunnel_net_id __read_mostly;
49static inline struct xfrm6_tunnel_net *xfrm6_tunnel_pernet(struct net *net)
50{
51 return net_generic(net, xfrm6_tunnel_net_id);
52}
33 53
34/* 54/*
35 * xfrm_tunnel_spi things are for allocating unique id ("spi") 55 * xfrm_tunnel_spi things are for allocating unique id ("spi")
36 * per xfrm_address_t. 56 * per xfrm_address_t.
37 */ 57 */
38struct xfrm6_tunnel_spi { 58struct xfrm6_tunnel_spi {
39 struct hlist_node list_byaddr; 59 struct hlist_node list_byaddr;
40 struct hlist_node list_byspi; 60 struct hlist_node list_byspi;
41 xfrm_address_t addr; 61 xfrm_address_t addr;
42 u32 spi; 62 u32 spi;
43 atomic_t refcnt; 63 atomic_t refcnt;
64 struct rcu_head rcu_head;
44}; 65};
45 66
46static DEFINE_RWLOCK(xfrm6_tunnel_spi_lock); 67static DEFINE_SPINLOCK(xfrm6_tunnel_spi_lock);
47
48static u32 xfrm6_tunnel_spi;
49
50#define XFRM6_TUNNEL_SPI_MIN 1
51#define XFRM6_TUNNEL_SPI_MAX 0xffffffff
52 68
53static struct kmem_cache *xfrm6_tunnel_spi_kmem __read_mostly; 69static struct kmem_cache *xfrm6_tunnel_spi_kmem __read_mostly;
54 70
55#define XFRM6_TUNNEL_SPI_BYADDR_HSIZE 256
56#define XFRM6_TUNNEL_SPI_BYSPI_HSIZE 256
57
58static struct hlist_head xfrm6_tunnel_spi_byaddr[XFRM6_TUNNEL_SPI_BYADDR_HSIZE];
59static struct hlist_head xfrm6_tunnel_spi_byspi[XFRM6_TUNNEL_SPI_BYSPI_HSIZE];
60
61static inline unsigned xfrm6_tunnel_spi_hash_byaddr(xfrm_address_t *addr) 71static inline unsigned xfrm6_tunnel_spi_hash_byaddr(xfrm_address_t *addr)
62{ 72{
63 unsigned h; 73 unsigned h;
@@ -75,49 +85,14 @@ static inline unsigned xfrm6_tunnel_spi_hash_byspi(u32 spi)
75 return spi % XFRM6_TUNNEL_SPI_BYSPI_HSIZE; 85 return spi % XFRM6_TUNNEL_SPI_BYSPI_HSIZE;
76} 86}
77 87
78 88static struct xfrm6_tunnel_spi *__xfrm6_tunnel_spi_lookup(struct net *net, xfrm_address_t *saddr)
79static int xfrm6_tunnel_spi_init(void)
80{
81 int i;
82
83 xfrm6_tunnel_spi = 0;
84 xfrm6_tunnel_spi_kmem = kmem_cache_create("xfrm6_tunnel_spi",
85 sizeof(struct xfrm6_tunnel_spi),
86 0, SLAB_HWCACHE_ALIGN,
87 NULL);
88 if (!xfrm6_tunnel_spi_kmem)
89 return -ENOMEM;
90
91 for (i = 0; i < XFRM6_TUNNEL_SPI_BYADDR_HSIZE; i++)
92 INIT_HLIST_HEAD(&xfrm6_tunnel_spi_byaddr[i]);
93 for (i = 0; i < XFRM6_TUNNEL_SPI_BYSPI_HSIZE; i++)
94 INIT_HLIST_HEAD(&xfrm6_tunnel_spi_byspi[i]);
95 return 0;
96}
97
98static void xfrm6_tunnel_spi_fini(void)
99{
100 int i;
101
102 for (i = 0; i < XFRM6_TUNNEL_SPI_BYADDR_HSIZE; i++) {
103 if (!hlist_empty(&xfrm6_tunnel_spi_byaddr[i]))
104 return;
105 }
106 for (i = 0; i < XFRM6_TUNNEL_SPI_BYSPI_HSIZE; i++) {
107 if (!hlist_empty(&xfrm6_tunnel_spi_byspi[i]))
108 return;
109 }
110 kmem_cache_destroy(xfrm6_tunnel_spi_kmem);
111 xfrm6_tunnel_spi_kmem = NULL;
112}
113
114static struct xfrm6_tunnel_spi *__xfrm6_tunnel_spi_lookup(xfrm_address_t *saddr)
115{ 89{
90 struct xfrm6_tunnel_net *xfrm6_tn = xfrm6_tunnel_pernet(net);
116 struct xfrm6_tunnel_spi *x6spi; 91 struct xfrm6_tunnel_spi *x6spi;
117 struct hlist_node *pos; 92 struct hlist_node *pos;
118 93
119 hlist_for_each_entry(x6spi, pos, 94 hlist_for_each_entry_rcu(x6spi, pos,
120 &xfrm6_tunnel_spi_byaddr[xfrm6_tunnel_spi_hash_byaddr(saddr)], 95 &xfrm6_tn->spi_byaddr[xfrm6_tunnel_spi_hash_byaddr(saddr)],
121 list_byaddr) { 96 list_byaddr) {
122 if (memcmp(&x6spi->addr, saddr, sizeof(x6spi->addr)) == 0) 97 if (memcmp(&x6spi->addr, saddr, sizeof(x6spi->addr)) == 0)
123 return x6spi; 98 return x6spi;
@@ -126,28 +101,29 @@ static struct xfrm6_tunnel_spi *__xfrm6_tunnel_spi_lookup(xfrm_address_t *saddr)
126 return NULL; 101 return NULL;
127} 102}
128 103
129__be32 xfrm6_tunnel_spi_lookup(xfrm_address_t *saddr) 104__be32 xfrm6_tunnel_spi_lookup(struct net *net, xfrm_address_t *saddr)
130{ 105{
131 struct xfrm6_tunnel_spi *x6spi; 106 struct xfrm6_tunnel_spi *x6spi;
132 u32 spi; 107 u32 spi;
133 108
134 read_lock_bh(&xfrm6_tunnel_spi_lock); 109 rcu_read_lock_bh();
135 x6spi = __xfrm6_tunnel_spi_lookup(saddr); 110 x6spi = __xfrm6_tunnel_spi_lookup(net, saddr);
136 spi = x6spi ? x6spi->spi : 0; 111 spi = x6spi ? x6spi->spi : 0;
137 read_unlock_bh(&xfrm6_tunnel_spi_lock); 112 rcu_read_unlock_bh();
138 return htonl(spi); 113 return htonl(spi);
139} 114}
140 115
141EXPORT_SYMBOL(xfrm6_tunnel_spi_lookup); 116EXPORT_SYMBOL(xfrm6_tunnel_spi_lookup);
142 117
143static int __xfrm6_tunnel_spi_check(u32 spi) 118static int __xfrm6_tunnel_spi_check(struct net *net, u32 spi)
144{ 119{
120 struct xfrm6_tunnel_net *xfrm6_tn = xfrm6_tunnel_pernet(net);
145 struct xfrm6_tunnel_spi *x6spi; 121 struct xfrm6_tunnel_spi *x6spi;
146 int index = xfrm6_tunnel_spi_hash_byspi(spi); 122 int index = xfrm6_tunnel_spi_hash_byspi(spi);
147 struct hlist_node *pos; 123 struct hlist_node *pos;
148 124
149 hlist_for_each_entry(x6spi, pos, 125 hlist_for_each_entry(x6spi, pos,
150 &xfrm6_tunnel_spi_byspi[index], 126 &xfrm6_tn->spi_byspi[index],
151 list_byspi) { 127 list_byspi) {
152 if (x6spi->spi == spi) 128 if (x6spi->spi == spi)
153 return -1; 129 return -1;
@@ -155,32 +131,33 @@ static int __xfrm6_tunnel_spi_check(u32 spi)
155 return index; 131 return index;
156} 132}
157 133
158static u32 __xfrm6_tunnel_alloc_spi(xfrm_address_t *saddr) 134static u32 __xfrm6_tunnel_alloc_spi(struct net *net, xfrm_address_t *saddr)
159{ 135{
136 struct xfrm6_tunnel_net *xfrm6_tn = xfrm6_tunnel_pernet(net);
160 u32 spi; 137 u32 spi;
161 struct xfrm6_tunnel_spi *x6spi; 138 struct xfrm6_tunnel_spi *x6spi;
162 int index; 139 int index;
163 140
164 if (xfrm6_tunnel_spi < XFRM6_TUNNEL_SPI_MIN || 141 if (xfrm6_tn->spi < XFRM6_TUNNEL_SPI_MIN ||
165 xfrm6_tunnel_spi >= XFRM6_TUNNEL_SPI_MAX) 142 xfrm6_tn->spi >= XFRM6_TUNNEL_SPI_MAX)
166 xfrm6_tunnel_spi = XFRM6_TUNNEL_SPI_MIN; 143 xfrm6_tn->spi = XFRM6_TUNNEL_SPI_MIN;
167 else 144 else
168 xfrm6_tunnel_spi++; 145 xfrm6_tn->spi++;
169 146
170 for (spi = xfrm6_tunnel_spi; spi <= XFRM6_TUNNEL_SPI_MAX; spi++) { 147 for (spi = xfrm6_tn->spi; spi <= XFRM6_TUNNEL_SPI_MAX; spi++) {
171 index = __xfrm6_tunnel_spi_check(spi); 148 index = __xfrm6_tunnel_spi_check(net, spi);
172 if (index >= 0) 149 if (index >= 0)
173 goto alloc_spi; 150 goto alloc_spi;
174 } 151 }
175 for (spi = XFRM6_TUNNEL_SPI_MIN; spi < xfrm6_tunnel_spi; spi++) { 152 for (spi = XFRM6_TUNNEL_SPI_MIN; spi < xfrm6_tn->spi; spi++) {
176 index = __xfrm6_tunnel_spi_check(spi); 153 index = __xfrm6_tunnel_spi_check(net, spi);
177 if (index >= 0) 154 if (index >= 0)
178 goto alloc_spi; 155 goto alloc_spi;
179 } 156 }
180 spi = 0; 157 spi = 0;
181 goto out; 158 goto out;
182alloc_spi: 159alloc_spi:
183 xfrm6_tunnel_spi = spi; 160 xfrm6_tn->spi = spi;
184 x6spi = kmem_cache_alloc(xfrm6_tunnel_spi_kmem, GFP_ATOMIC); 161 x6spi = kmem_cache_alloc(xfrm6_tunnel_spi_kmem, GFP_ATOMIC);
185 if (!x6spi) 162 if (!x6spi)
186 goto out; 163 goto out;
@@ -189,54 +166,61 @@ alloc_spi:
189 x6spi->spi = spi; 166 x6spi->spi = spi;
190 atomic_set(&x6spi->refcnt, 1); 167 atomic_set(&x6spi->refcnt, 1);
191 168
192 hlist_add_head(&x6spi->list_byspi, &xfrm6_tunnel_spi_byspi[index]); 169 hlist_add_head_rcu(&x6spi->list_byspi, &xfrm6_tn->spi_byspi[index]);
193 170
194 index = xfrm6_tunnel_spi_hash_byaddr(saddr); 171 index = xfrm6_tunnel_spi_hash_byaddr(saddr);
195 hlist_add_head(&x6spi->list_byaddr, &xfrm6_tunnel_spi_byaddr[index]); 172 hlist_add_head_rcu(&x6spi->list_byaddr, &xfrm6_tn->spi_byaddr[index]);
196out: 173out:
197 return spi; 174 return spi;
198} 175}
199 176
200__be32 xfrm6_tunnel_alloc_spi(xfrm_address_t *saddr) 177__be32 xfrm6_tunnel_alloc_spi(struct net *net, xfrm_address_t *saddr)
201{ 178{
202 struct xfrm6_tunnel_spi *x6spi; 179 struct xfrm6_tunnel_spi *x6spi;
203 u32 spi; 180 u32 spi;
204 181
205 write_lock_bh(&xfrm6_tunnel_spi_lock); 182 spin_lock_bh(&xfrm6_tunnel_spi_lock);
206 x6spi = __xfrm6_tunnel_spi_lookup(saddr); 183 x6spi = __xfrm6_tunnel_spi_lookup(net, saddr);
207 if (x6spi) { 184 if (x6spi) {
208 atomic_inc(&x6spi->refcnt); 185 atomic_inc(&x6spi->refcnt);
209 spi = x6spi->spi; 186 spi = x6spi->spi;
210 } else 187 } else
211 spi = __xfrm6_tunnel_alloc_spi(saddr); 188 spi = __xfrm6_tunnel_alloc_spi(net, saddr);
212 write_unlock_bh(&xfrm6_tunnel_spi_lock); 189 spin_unlock_bh(&xfrm6_tunnel_spi_lock);
213 190
214 return htonl(spi); 191 return htonl(spi);
215} 192}
216 193
217EXPORT_SYMBOL(xfrm6_tunnel_alloc_spi); 194EXPORT_SYMBOL(xfrm6_tunnel_alloc_spi);
218 195
219void xfrm6_tunnel_free_spi(xfrm_address_t *saddr) 196static void x6spi_destroy_rcu(struct rcu_head *head)
197{
198 kmem_cache_free(xfrm6_tunnel_spi_kmem,
199 container_of(head, struct xfrm6_tunnel_spi, rcu_head));
200}
201
202void xfrm6_tunnel_free_spi(struct net *net, xfrm_address_t *saddr)
220{ 203{
204 struct xfrm6_tunnel_net *xfrm6_tn = xfrm6_tunnel_pernet(net);
221 struct xfrm6_tunnel_spi *x6spi; 205 struct xfrm6_tunnel_spi *x6spi;
222 struct hlist_node *pos, *n; 206 struct hlist_node *pos, *n;
223 207
224 write_lock_bh(&xfrm6_tunnel_spi_lock); 208 spin_lock_bh(&xfrm6_tunnel_spi_lock);
225 209
226 hlist_for_each_entry_safe(x6spi, pos, n, 210 hlist_for_each_entry_safe(x6spi, pos, n,
227 &xfrm6_tunnel_spi_byaddr[xfrm6_tunnel_spi_hash_byaddr(saddr)], 211 &xfrm6_tn->spi_byaddr[xfrm6_tunnel_spi_hash_byaddr(saddr)],
228 list_byaddr) 212 list_byaddr)
229 { 213 {
230 if (memcmp(&x6spi->addr, saddr, sizeof(x6spi->addr)) == 0) { 214 if (memcmp(&x6spi->addr, saddr, sizeof(x6spi->addr)) == 0) {
231 if (atomic_dec_and_test(&x6spi->refcnt)) { 215 if (atomic_dec_and_test(&x6spi->refcnt)) {
232 hlist_del(&x6spi->list_byaddr); 216 hlist_del_rcu(&x6spi->list_byaddr);
233 hlist_del(&x6spi->list_byspi); 217 hlist_del_rcu(&x6spi->list_byspi);
234 kmem_cache_free(xfrm6_tunnel_spi_kmem, x6spi); 218 call_rcu(&x6spi->rcu_head, x6spi_destroy_rcu);
235 break; 219 break;
236 } 220 }
237 } 221 }
238 } 222 }
239 write_unlock_bh(&xfrm6_tunnel_spi_lock); 223 spin_unlock_bh(&xfrm6_tunnel_spi_lock);
240} 224}
241 225
242EXPORT_SYMBOL(xfrm6_tunnel_free_spi); 226EXPORT_SYMBOL(xfrm6_tunnel_free_spi);
@@ -254,10 +238,11 @@ static int xfrm6_tunnel_input(struct xfrm_state *x, struct sk_buff *skb)
254 238
255static int xfrm6_tunnel_rcv(struct sk_buff *skb) 239static int xfrm6_tunnel_rcv(struct sk_buff *skb)
256{ 240{
241 struct net *net = dev_net(skb->dev);
257 struct ipv6hdr *iph = ipv6_hdr(skb); 242 struct ipv6hdr *iph = ipv6_hdr(skb);
258 __be32 spi; 243 __be32 spi;
259 244
260 spi = xfrm6_tunnel_spi_lookup((xfrm_address_t *)&iph->saddr); 245 spi = xfrm6_tunnel_spi_lookup(net, (xfrm_address_t *)&iph->saddr);
261 return xfrm6_rcv_spi(skb, IPPROTO_IPV6, spi) > 0 ? : 0; 246 return xfrm6_rcv_spi(skb, IPPROTO_IPV6, spi) > 0 ? : 0;
262} 247}
263 248
@@ -317,7 +302,9 @@ static int xfrm6_tunnel_init_state(struct xfrm_state *x)
317 302
318static void xfrm6_tunnel_destroy(struct xfrm_state *x) 303static void xfrm6_tunnel_destroy(struct xfrm_state *x)
319{ 304{
320 xfrm6_tunnel_free_spi((xfrm_address_t *)&x->props.saddr); 305 struct net *net = xs_net(x);
306
307 xfrm6_tunnel_free_spi(net, (xfrm_address_t *)&x->props.saddr);
321} 308}
322 309
323static const struct xfrm_type xfrm6_tunnel_type = { 310static const struct xfrm_type xfrm6_tunnel_type = {
@@ -342,34 +329,73 @@ static struct xfrm6_tunnel xfrm46_tunnel_handler = {
342 .priority = 2, 329 .priority = 2,
343}; 330};
344 331
332static int __net_init xfrm6_tunnel_net_init(struct net *net)
333{
334 struct xfrm6_tunnel_net *xfrm6_tn = xfrm6_tunnel_pernet(net);
335 unsigned int i;
336
337 for (i = 0; i < XFRM6_TUNNEL_SPI_BYADDR_HSIZE; i++)
338 INIT_HLIST_HEAD(&xfrm6_tn->spi_byaddr[i]);
339 for (i = 0; i < XFRM6_TUNNEL_SPI_BYSPI_HSIZE; i++)
340 INIT_HLIST_HEAD(&xfrm6_tn->spi_byspi[i]);
341 xfrm6_tn->spi = 0;
342
343 return 0;
344}
345
346static void __net_exit xfrm6_tunnel_net_exit(struct net *net)
347{
348}
349
350static struct pernet_operations xfrm6_tunnel_net_ops = {
351 .init = xfrm6_tunnel_net_init,
352 .exit = xfrm6_tunnel_net_exit,
353 .id = &xfrm6_tunnel_net_id,
354 .size = sizeof(struct xfrm6_tunnel_net),
355};
356
345static int __init xfrm6_tunnel_init(void) 357static int __init xfrm6_tunnel_init(void)
346{ 358{
347 if (xfrm_register_type(&xfrm6_tunnel_type, AF_INET6) < 0) 359 int rv;
348 goto err; 360
349 if (xfrm6_tunnel_register(&xfrm6_tunnel_handler, AF_INET6)) 361 xfrm6_tunnel_spi_kmem = kmem_cache_create("xfrm6_tunnel_spi",
350 goto unreg; 362 sizeof(struct xfrm6_tunnel_spi),
351 if (xfrm6_tunnel_register(&xfrm46_tunnel_handler, AF_INET)) 363 0, SLAB_HWCACHE_ALIGN,
352 goto dereg6; 364 NULL);
353 if (xfrm6_tunnel_spi_init() < 0) 365 if (!xfrm6_tunnel_spi_kmem)
354 goto dereg46; 366 return -ENOMEM;
367 rv = register_pernet_subsys(&xfrm6_tunnel_net_ops);
368 if (rv < 0)
369 goto out_pernet;
370 rv = xfrm_register_type(&xfrm6_tunnel_type, AF_INET6);
371 if (rv < 0)
372 goto out_type;
373 rv = xfrm6_tunnel_register(&xfrm6_tunnel_handler, AF_INET6);
374 if (rv < 0)
375 goto out_xfrm6;
376 rv = xfrm6_tunnel_register(&xfrm46_tunnel_handler, AF_INET);
377 if (rv < 0)
378 goto out_xfrm46;
355 return 0; 379 return 0;
356 380
357dereg46: 381out_xfrm46:
358 xfrm6_tunnel_deregister(&xfrm46_tunnel_handler, AF_INET);
359dereg6:
360 xfrm6_tunnel_deregister(&xfrm6_tunnel_handler, AF_INET6); 382 xfrm6_tunnel_deregister(&xfrm6_tunnel_handler, AF_INET6);
361unreg: 383out_xfrm6:
362 xfrm_unregister_type(&xfrm6_tunnel_type, AF_INET6); 384 xfrm_unregister_type(&xfrm6_tunnel_type, AF_INET6);
363err: 385out_type:
364 return -EAGAIN; 386 unregister_pernet_subsys(&xfrm6_tunnel_net_ops);
387out_pernet:
388 kmem_cache_destroy(xfrm6_tunnel_spi_kmem);
389 return rv;
365} 390}
366 391
367static void __exit xfrm6_tunnel_fini(void) 392static void __exit xfrm6_tunnel_fini(void)
368{ 393{
369 xfrm6_tunnel_spi_fini();
370 xfrm6_tunnel_deregister(&xfrm46_tunnel_handler, AF_INET); 394 xfrm6_tunnel_deregister(&xfrm46_tunnel_handler, AF_INET);
371 xfrm6_tunnel_deregister(&xfrm6_tunnel_handler, AF_INET6); 395 xfrm6_tunnel_deregister(&xfrm6_tunnel_handler, AF_INET6);
372 xfrm_unregister_type(&xfrm6_tunnel_type, AF_INET6); 396 xfrm_unregister_type(&xfrm6_tunnel_type, AF_INET6);
397 unregister_pernet_subsys(&xfrm6_tunnel_net_ops);
398 kmem_cache_destroy(xfrm6_tunnel_spi_kmem);
373} 399}
374 400
375module_init(xfrm6_tunnel_init); 401module_init(xfrm6_tunnel_init);
diff --git a/net/ipx/af_ipx.c b/net/ipx/af_ipx.c
index 66c7a20011f3..da3d21c41d90 100644
--- a/net/ipx/af_ipx.c
+++ b/net/ipx/af_ipx.c
@@ -40,6 +40,7 @@
40#include <linux/net.h> 40#include <linux/net.h>
41#include <linux/netdevice.h> 41#include <linux/netdevice.h>
42#include <linux/uio.h> 42#include <linux/uio.h>
43#include <linux/slab.h>
43#include <linux/skbuff.h> 44#include <linux/skbuff.h>
44#include <linux/smp_lock.h> 45#include <linux/smp_lock.h>
45#include <linux/socket.h> 46#include <linux/socket.h>
@@ -1298,6 +1299,7 @@ static int ipx_setsockopt(struct socket *sock, int level, int optname,
1298 int opt; 1299 int opt;
1299 int rc = -EINVAL; 1300 int rc = -EINVAL;
1300 1301
1302 lock_kernel();
1301 if (optlen != sizeof(int)) 1303 if (optlen != sizeof(int))
1302 goto out; 1304 goto out;
1303 1305
@@ -1312,6 +1314,7 @@ static int ipx_setsockopt(struct socket *sock, int level, int optname,
1312 ipx_sk(sk)->type = opt; 1314 ipx_sk(sk)->type = opt;
1313 rc = 0; 1315 rc = 0;
1314out: 1316out:
1317 unlock_kernel();
1315 return rc; 1318 return rc;
1316} 1319}
1317 1320
@@ -1323,6 +1326,7 @@ static int ipx_getsockopt(struct socket *sock, int level, int optname,
1323 int len; 1326 int len;
1324 int rc = -ENOPROTOOPT; 1327 int rc = -ENOPROTOOPT;
1325 1328
1329 lock_kernel();
1326 if (!(level == SOL_IPX && optname == IPX_TYPE)) 1330 if (!(level == SOL_IPX && optname == IPX_TYPE))
1327 goto out; 1331 goto out;
1328 1332
@@ -1343,6 +1347,7 @@ static int ipx_getsockopt(struct socket *sock, int level, int optname,
1343 1347
1344 rc = 0; 1348 rc = 0;
1345out: 1349out:
1350 unlock_kernel();
1346 return rc; 1351 return rc;
1347} 1352}
1348 1353
@@ -1352,12 +1357,13 @@ static struct proto ipx_proto = {
1352 .obj_size = sizeof(struct ipx_sock), 1357 .obj_size = sizeof(struct ipx_sock),
1353}; 1358};
1354 1359
1355static int ipx_create(struct net *net, struct socket *sock, int protocol) 1360static int ipx_create(struct net *net, struct socket *sock, int protocol,
1361 int kern)
1356{ 1362{
1357 int rc = -ESOCKTNOSUPPORT; 1363 int rc = -ESOCKTNOSUPPORT;
1358 struct sock *sk; 1364 struct sock *sk;
1359 1365
1360 if (net != &init_net) 1366 if (!net_eq(net, &init_net))
1361 return -EAFNOSUPPORT; 1367 return -EAFNOSUPPORT;
1362 1368
1363 /* 1369 /*
@@ -1390,6 +1396,7 @@ static int ipx_release(struct socket *sock)
1390 if (!sk) 1396 if (!sk)
1391 goto out; 1397 goto out;
1392 1398
1399 lock_kernel();
1393 if (!sock_flag(sk, SOCK_DEAD)) 1400 if (!sock_flag(sk, SOCK_DEAD))
1394 sk->sk_state_change(sk); 1401 sk->sk_state_change(sk);
1395 1402
@@ -1397,6 +1404,7 @@ static int ipx_release(struct socket *sock)
1397 sock->sk = NULL; 1404 sock->sk = NULL;
1398 sk_refcnt_debug_release(sk); 1405 sk_refcnt_debug_release(sk);
1399 ipx_destroy_socket(sk); 1406 ipx_destroy_socket(sk);
1407 unlock_kernel();
1400out: 1408out:
1401 return 0; 1409 return 0;
1402} 1410}
@@ -1424,7 +1432,8 @@ static __be16 ipx_first_free_socketnum(struct ipx_interface *intrfc)
1424 return htons(socketNum); 1432 return htons(socketNum);
1425} 1433}
1426 1434
1427static int ipx_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len) 1435static int __ipx_bind(struct socket *sock,
1436 struct sockaddr *uaddr, int addr_len)
1428{ 1437{
1429 struct sock *sk = sock->sk; 1438 struct sock *sk = sock->sk;
1430 struct ipx_sock *ipxs = ipx_sk(sk); 1439 struct ipx_sock *ipxs = ipx_sk(sk);
@@ -1519,6 +1528,17 @@ out:
1519 return rc; 1528 return rc;
1520} 1529}
1521 1530
1531static int ipx_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
1532{
1533 int rc;
1534
1535 lock_kernel();
1536 rc = __ipx_bind(sock, uaddr, addr_len);
1537 unlock_kernel();
1538
1539 return rc;
1540}
1541
1522static int ipx_connect(struct socket *sock, struct sockaddr *uaddr, 1542static int ipx_connect(struct socket *sock, struct sockaddr *uaddr,
1523 int addr_len, int flags) 1543 int addr_len, int flags)
1524{ 1544{
@@ -1531,6 +1551,7 @@ static int ipx_connect(struct socket *sock, struct sockaddr *uaddr,
1531 sk->sk_state = TCP_CLOSE; 1551 sk->sk_state = TCP_CLOSE;
1532 sock->state = SS_UNCONNECTED; 1552 sock->state = SS_UNCONNECTED;
1533 1553
1554 lock_kernel();
1534 if (addr_len != sizeof(*addr)) 1555 if (addr_len != sizeof(*addr))
1535 goto out; 1556 goto out;
1536 addr = (struct sockaddr_ipx *)uaddr; 1557 addr = (struct sockaddr_ipx *)uaddr;
@@ -1550,7 +1571,7 @@ static int ipx_connect(struct socket *sock, struct sockaddr *uaddr,
1550 IPX_NODE_LEN); 1571 IPX_NODE_LEN);
1551#endif /* CONFIG_IPX_INTERN */ 1572#endif /* CONFIG_IPX_INTERN */
1552 1573
1553 rc = ipx_bind(sock, (struct sockaddr *)&uaddr, 1574 rc = __ipx_bind(sock, (struct sockaddr *)&uaddr,
1554 sizeof(struct sockaddr_ipx)); 1575 sizeof(struct sockaddr_ipx));
1555 if (rc) 1576 if (rc)
1556 goto out; 1577 goto out;
@@ -1577,6 +1598,7 @@ static int ipx_connect(struct socket *sock, struct sockaddr *uaddr,
1577 ipxrtr_put(rt); 1598 ipxrtr_put(rt);
1578 rc = 0; 1599 rc = 0;
1579out: 1600out:
1601 unlock_kernel();
1580 return rc; 1602 return rc;
1581} 1603}
1582 1604
@@ -1592,6 +1614,7 @@ static int ipx_getname(struct socket *sock, struct sockaddr *uaddr,
1592 1614
1593 *uaddr_len = sizeof(struct sockaddr_ipx); 1615 *uaddr_len = sizeof(struct sockaddr_ipx);
1594 1616
1617 lock_kernel();
1595 if (peer) { 1618 if (peer) {
1596 rc = -ENOTCONN; 1619 rc = -ENOTCONN;
1597 if (sk->sk_state != TCP_ESTABLISHED) 1620 if (sk->sk_state != TCP_ESTABLISHED)
@@ -1626,6 +1649,19 @@ static int ipx_getname(struct socket *sock, struct sockaddr *uaddr,
1626 1649
1627 rc = 0; 1650 rc = 0;
1628out: 1651out:
1652 unlock_kernel();
1653 return rc;
1654}
1655
1656static unsigned int ipx_datagram_poll(struct file *file, struct socket *sock,
1657 poll_table *wait)
1658{
1659 int rc;
1660
1661 lock_kernel();
1662 rc = datagram_poll(file, sock, wait);
1663 unlock_kernel();
1664
1629 return rc; 1665 return rc;
1630} 1666}
1631 1667
@@ -1700,6 +1736,7 @@ static int ipx_sendmsg(struct kiocb *iocb, struct socket *sock,
1700 int rc = -EINVAL; 1736 int rc = -EINVAL;
1701 int flags = msg->msg_flags; 1737 int flags = msg->msg_flags;
1702 1738
1739 lock_kernel();
1703 /* Socket gets bound below anyway */ 1740 /* Socket gets bound below anyway */
1704/* if (sk->sk_zapped) 1741/* if (sk->sk_zapped)
1705 return -EIO; */ /* Socket not bound */ 1742 return -EIO; */ /* Socket not bound */
@@ -1723,7 +1760,7 @@ static int ipx_sendmsg(struct kiocb *iocb, struct socket *sock,
1723 memcpy(uaddr.sipx_node, ipxs->intrfc->if_node, 1760 memcpy(uaddr.sipx_node, ipxs->intrfc->if_node,
1724 IPX_NODE_LEN); 1761 IPX_NODE_LEN);
1725#endif 1762#endif
1726 rc = ipx_bind(sock, (struct sockaddr *)&uaddr, 1763 rc = __ipx_bind(sock, (struct sockaddr *)&uaddr,
1727 sizeof(struct sockaddr_ipx)); 1764 sizeof(struct sockaddr_ipx));
1728 if (rc) 1765 if (rc)
1729 goto out; 1766 goto out;
@@ -1751,6 +1788,7 @@ static int ipx_sendmsg(struct kiocb *iocb, struct socket *sock,
1751 if (rc >= 0) 1788 if (rc >= 0)
1752 rc = len; 1789 rc = len;
1753out: 1790out:
1791 unlock_kernel();
1754 return rc; 1792 return rc;
1755} 1793}
1756 1794
@@ -1765,6 +1803,7 @@ static int ipx_recvmsg(struct kiocb *iocb, struct socket *sock,
1765 struct sk_buff *skb; 1803 struct sk_buff *skb;
1766 int copied, rc; 1804 int copied, rc;
1767 1805
1806 lock_kernel();
1768 /* put the autobinding in */ 1807 /* put the autobinding in */
1769 if (!ipxs->port) { 1808 if (!ipxs->port) {
1770 struct sockaddr_ipx uaddr; 1809 struct sockaddr_ipx uaddr;
@@ -1779,7 +1818,7 @@ static int ipx_recvmsg(struct kiocb *iocb, struct socket *sock,
1779 memcpy(uaddr.sipx_node, ipxs->intrfc->if_node, IPX_NODE_LEN); 1818 memcpy(uaddr.sipx_node, ipxs->intrfc->if_node, IPX_NODE_LEN);
1780#endif /* CONFIG_IPX_INTERN */ 1819#endif /* CONFIG_IPX_INTERN */
1781 1820
1782 rc = ipx_bind(sock, (struct sockaddr *)&uaddr, 1821 rc = __ipx_bind(sock, (struct sockaddr *)&uaddr,
1783 sizeof(struct sockaddr_ipx)); 1822 sizeof(struct sockaddr_ipx));
1784 if (rc) 1823 if (rc)
1785 goto out; 1824 goto out;
@@ -1823,6 +1862,7 @@ static int ipx_recvmsg(struct kiocb *iocb, struct socket *sock,
1823out_free: 1862out_free:
1824 skb_free_datagram(sk, skb); 1863 skb_free_datagram(sk, skb);
1825out: 1864out:
1865 unlock_kernel();
1826 return rc; 1866 return rc;
1827} 1867}
1828 1868
@@ -1834,6 +1874,7 @@ static int ipx_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
1834 struct sock *sk = sock->sk; 1874 struct sock *sk = sock->sk;
1835 void __user *argp = (void __user *)arg; 1875 void __user *argp = (void __user *)arg;
1836 1876
1877 lock_kernel();
1837 switch (cmd) { 1878 switch (cmd) {
1838 case TIOCOUTQ: 1879 case TIOCOUTQ:
1839 amount = sk->sk_sndbuf - sk_wmem_alloc_get(sk); 1880 amount = sk->sk_sndbuf - sk_wmem_alloc_get(sk);
@@ -1896,6 +1937,7 @@ static int ipx_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
1896 rc = -ENOIOCTLCMD; 1937 rc = -ENOIOCTLCMD;
1897 break; 1938 break;
1898 } 1939 }
1940 unlock_kernel();
1899 1941
1900 return rc; 1942 return rc;
1901} 1943}
@@ -1927,13 +1969,13 @@ static int ipx_compat_ioctl(struct socket *sock, unsigned int cmd, unsigned long
1927 * Socket family declarations 1969 * Socket family declarations
1928 */ 1970 */
1929 1971
1930static struct net_proto_family ipx_family_ops = { 1972static const struct net_proto_family ipx_family_ops = {
1931 .family = PF_IPX, 1973 .family = PF_IPX,
1932 .create = ipx_create, 1974 .create = ipx_create,
1933 .owner = THIS_MODULE, 1975 .owner = THIS_MODULE,
1934}; 1976};
1935 1977
1936static const struct proto_ops SOCKOPS_WRAPPED(ipx_dgram_ops) = { 1978static const struct proto_ops ipx_dgram_ops = {
1937 .family = PF_IPX, 1979 .family = PF_IPX,
1938 .owner = THIS_MODULE, 1980 .owner = THIS_MODULE,
1939 .release = ipx_release, 1981 .release = ipx_release,
@@ -1942,7 +1984,7 @@ static const struct proto_ops SOCKOPS_WRAPPED(ipx_dgram_ops) = {
1942 .socketpair = sock_no_socketpair, 1984 .socketpair = sock_no_socketpair,
1943 .accept = sock_no_accept, 1985 .accept = sock_no_accept,
1944 .getname = ipx_getname, 1986 .getname = ipx_getname,
1945 .poll = datagram_poll, 1987 .poll = ipx_datagram_poll,
1946 .ioctl = ipx_ioctl, 1988 .ioctl = ipx_ioctl,
1947#ifdef CONFIG_COMPAT 1989#ifdef CONFIG_COMPAT
1948 .compat_ioctl = ipx_compat_ioctl, 1990 .compat_ioctl = ipx_compat_ioctl,
@@ -1957,8 +1999,6 @@ static const struct proto_ops SOCKOPS_WRAPPED(ipx_dgram_ops) = {
1957 .sendpage = sock_no_sendpage, 1999 .sendpage = sock_no_sendpage,
1958}; 2000};
1959 2001
1960SOCKOPS_WRAP(ipx_dgram, PF_IPX);
1961
1962static struct packet_type ipx_8023_packet_type __read_mostly = { 2002static struct packet_type ipx_8023_packet_type __read_mostly = {
1963 .type = cpu_to_be16(ETH_P_802_3), 2003 .type = cpu_to_be16(ETH_P_802_3),
1964 .func = ipx_rcv, 2004 .func = ipx_rcv,
diff --git a/net/ipx/ipx_proc.c b/net/ipx/ipx_proc.c
index 576178482f89..26b5bfcf1d03 100644
--- a/net/ipx/ipx_proc.c
+++ b/net/ipx/ipx_proc.c
@@ -13,45 +13,15 @@
13#include <net/tcp_states.h> 13#include <net/tcp_states.h>
14#include <net/ipx.h> 14#include <net/ipx.h>
15 15
16static __inline__ struct ipx_interface *ipx_get_interface_idx(loff_t pos)
17{
18 struct ipx_interface *i;
19
20 list_for_each_entry(i, &ipx_interfaces, node)
21 if (!pos--)
22 goto out;
23 i = NULL;
24out:
25 return i;
26}
27
28static struct ipx_interface *ipx_interfaces_next(struct ipx_interface *i)
29{
30 struct ipx_interface *rc = NULL;
31
32 if (i->node.next != &ipx_interfaces)
33 rc = list_entry(i->node.next, struct ipx_interface, node);
34 return rc;
35}
36
37static void *ipx_seq_interface_start(struct seq_file *seq, loff_t *pos) 16static void *ipx_seq_interface_start(struct seq_file *seq, loff_t *pos)
38{ 17{
39 loff_t l = *pos;
40
41 spin_lock_bh(&ipx_interfaces_lock); 18 spin_lock_bh(&ipx_interfaces_lock);
42 return l ? ipx_get_interface_idx(--l) : SEQ_START_TOKEN; 19 return seq_list_start_head(&ipx_interfaces, *pos);
43} 20}
44 21
45static void *ipx_seq_interface_next(struct seq_file *seq, void *v, loff_t *pos) 22static void *ipx_seq_interface_next(struct seq_file *seq, void *v, loff_t *pos)
46{ 23{
47 struct ipx_interface *i; 24 return seq_list_next(v, &ipx_interfaces, pos);
48
49 ++*pos;
50 if (v == SEQ_START_TOKEN)
51 i = ipx_interfaces_head();
52 else
53 i = ipx_interfaces_next(v);
54 return i;
55} 25}
56 26
57static void ipx_seq_interface_stop(struct seq_file *seq, void *v) 27static void ipx_seq_interface_stop(struct seq_file *seq, void *v)
@@ -63,7 +33,7 @@ static int ipx_seq_interface_show(struct seq_file *seq, void *v)
63{ 33{
64 struct ipx_interface *i; 34 struct ipx_interface *i;
65 35
66 if (v == SEQ_START_TOKEN) { 36 if (v == &ipx_interfaces) {
67 seq_puts(seq, "Network Node_Address Primary Device " 37 seq_puts(seq, "Network Node_Address Primary Device "
68 "Frame_Type"); 38 "Frame_Type");
69#ifdef IPX_REFCNT_DEBUG 39#ifdef IPX_REFCNT_DEBUG
@@ -73,7 +43,7 @@ static int ipx_seq_interface_show(struct seq_file *seq, void *v)
73 goto out; 43 goto out;
74 } 44 }
75 45
76 i = v; 46 i = list_entry(v, struct ipx_interface, node);
77 seq_printf(seq, "%08lX ", (unsigned long int)ntohl(i->if_netnum)); 47 seq_printf(seq, "%08lX ", (unsigned long int)ntohl(i->if_netnum));
78 seq_printf(seq, "%02X%02X%02X%02X%02X%02X ", 48 seq_printf(seq, "%02X%02X%02X%02X%02X%02X ",
79 i->if_node[0], i->if_node[1], i->if_node[2], 49 i->if_node[0], i->if_node[1], i->if_node[2],
@@ -89,53 +59,15 @@ out:
89 return 0; 59 return 0;
90} 60}
91 61
92static struct ipx_route *ipx_routes_head(void)
93{
94 struct ipx_route *rc = NULL;
95
96 if (!list_empty(&ipx_routes))
97 rc = list_entry(ipx_routes.next, struct ipx_route, node);
98 return rc;
99}
100
101static struct ipx_route *ipx_routes_next(struct ipx_route *r)
102{
103 struct ipx_route *rc = NULL;
104
105 if (r->node.next != &ipx_routes)
106 rc = list_entry(r->node.next, struct ipx_route, node);
107 return rc;
108}
109
110static __inline__ struct ipx_route *ipx_get_route_idx(loff_t pos)
111{
112 struct ipx_route *r;
113
114 list_for_each_entry(r, &ipx_routes, node)
115 if (!pos--)
116 goto out;
117 r = NULL;
118out:
119 return r;
120}
121
122static void *ipx_seq_route_start(struct seq_file *seq, loff_t *pos) 62static void *ipx_seq_route_start(struct seq_file *seq, loff_t *pos)
123{ 63{
124 loff_t l = *pos;
125 read_lock_bh(&ipx_routes_lock); 64 read_lock_bh(&ipx_routes_lock);
126 return l ? ipx_get_route_idx(--l) : SEQ_START_TOKEN; 65 return seq_list_start_head(&ipx_routes, *pos);
127} 66}
128 67
129static void *ipx_seq_route_next(struct seq_file *seq, void *v, loff_t *pos) 68static void *ipx_seq_route_next(struct seq_file *seq, void *v, loff_t *pos)
130{ 69{
131 struct ipx_route *r; 70 return seq_list_next(v, &ipx_routes, pos);
132
133 ++*pos;
134 if (v == SEQ_START_TOKEN)
135 r = ipx_routes_head();
136 else
137 r = ipx_routes_next(v);
138 return r;
139} 71}
140 72
141static void ipx_seq_route_stop(struct seq_file *seq, void *v) 73static void ipx_seq_route_stop(struct seq_file *seq, void *v)
@@ -147,11 +79,13 @@ static int ipx_seq_route_show(struct seq_file *seq, void *v)
147{ 79{
148 struct ipx_route *rt; 80 struct ipx_route *rt;
149 81
150 if (v == SEQ_START_TOKEN) { 82 if (v == &ipx_routes) {
151 seq_puts(seq, "Network Router_Net Router_Node\n"); 83 seq_puts(seq, "Network Router_Net Router_Node\n");
152 goto out; 84 goto out;
153 } 85 }
154 rt = v; 86
87 rt = list_entry(v, struct ipx_route, node);
88
155 seq_printf(seq, "%08lX ", (unsigned long int)ntohl(rt->ir_net)); 89 seq_printf(seq, "%08lX ", (unsigned long int)ntohl(rt->ir_net));
156 if (rt->ir_routed) 90 if (rt->ir_routed)
157 seq_printf(seq, "%08lX %02X%02X%02X%02X%02X%02X\n", 91 seq_printf(seq, "%08lX %02X%02X%02X%02X%02X%02X\n",
@@ -226,9 +160,9 @@ static void *ipx_seq_socket_next(struct seq_file *seq, void *v, loff_t *pos)
226 spin_unlock_bh(&i->if_sklist_lock); 160 spin_unlock_bh(&i->if_sklist_lock);
227 sk = NULL; 161 sk = NULL;
228 for (;;) { 162 for (;;) {
229 i = ipx_interfaces_next(i); 163 if (i->node.next == &ipx_interfaces)
230 if (!i)
231 break; 164 break;
165 i = list_entry(i->node.next, struct ipx_interface, node);
232 spin_lock_bh(&i->if_sklist_lock); 166 spin_lock_bh(&i->if_sklist_lock);
233 if (!hlist_empty(&i->if_sklist)) { 167 if (!hlist_empty(&i->if_sklist)) {
234 sk = sk_head(&i->if_sklist); 168 sk = sk_head(&i->if_sklist);
diff --git a/net/ipx/ipx_route.c b/net/ipx/ipx_route.c
index e16c11423527..30f4519b092f 100644
--- a/net/ipx/ipx_route.c
+++ b/net/ipx/ipx_route.c
@@ -9,6 +9,7 @@
9 9
10#include <linux/list.h> 10#include <linux/list.h>
11#include <linux/route.h> 11#include <linux/route.h>
12#include <linux/slab.h>
12#include <linux/spinlock.h> 13#include <linux/spinlock.h>
13 14
14#include <net/ipx.h> 15#include <net/ipx.h>
diff --git a/net/ipx/sysctl_net_ipx.c b/net/ipx/sysctl_net_ipx.c
index 633fcab35580..bd6dca00fb85 100644
--- a/net/ipx/sysctl_net_ipx.c
+++ b/net/ipx/sysctl_net_ipx.c
@@ -18,19 +18,18 @@ extern int sysctl_ipx_pprop_broadcasting;
18 18
19static struct ctl_table ipx_table[] = { 19static struct ctl_table ipx_table[] = {
20 { 20 {
21 .ctl_name = NET_IPX_PPROP_BROADCASTING,
22 .procname = "ipx_pprop_broadcasting", 21 .procname = "ipx_pprop_broadcasting",
23 .data = &sysctl_ipx_pprop_broadcasting, 22 .data = &sysctl_ipx_pprop_broadcasting,
24 .maxlen = sizeof(int), 23 .maxlen = sizeof(int),
25 .mode = 0644, 24 .mode = 0644,
26 .proc_handler = proc_dointvec, 25 .proc_handler = proc_dointvec,
27 }, 26 },
28 { 0 }, 27 { },
29}; 28};
30 29
31static struct ctl_path ipx_path[] = { 30static struct ctl_path ipx_path[] = {
32 { .procname = "net", .ctl_name = CTL_NET, }, 31 { .procname = "net", },
33 { .procname = "ipx", .ctl_name = NET_IPX, }, 32 { .procname = "ipx", },
34 { } 33 { }
35}; 34};
36 35
diff --git a/net/irda/af_irda.c b/net/irda/af_irda.c
index dd35641835f4..2a4efcea3423 100644
--- a/net/irda/af_irda.c
+++ b/net/irda/af_irda.c
@@ -48,6 +48,7 @@
48#include <linux/smp_lock.h> 48#include <linux/smp_lock.h>
49#include <linux/socket.h> 49#include <linux/socket.h>
50#include <linux/sockios.h> 50#include <linux/sockios.h>
51#include <linux/slab.h>
51#include <linux/init.h> 52#include <linux/init.h>
52#include <linux/net.h> 53#include <linux/net.h>
53#include <linux/irda.h> 54#include <linux/irda.h>
@@ -61,7 +62,7 @@
61 62
62#include <net/irda/af_irda.h> 63#include <net/irda/af_irda.h>
63 64
64static int irda_create(struct net *net, struct socket *sock, int protocol); 65static int irda_create(struct net *net, struct socket *sock, int protocol, int kern);
65 66
66static const struct proto_ops irda_stream_ops; 67static const struct proto_ops irda_stream_ops;
67static const struct proto_ops irda_seqpacket_ops; 68static const struct proto_ops irda_seqpacket_ops;
@@ -714,11 +715,14 @@ static int irda_getname(struct socket *sock, struct sockaddr *uaddr,
714 struct sockaddr_irda saddr; 715 struct sockaddr_irda saddr;
715 struct sock *sk = sock->sk; 716 struct sock *sk = sock->sk;
716 struct irda_sock *self = irda_sk(sk); 717 struct irda_sock *self = irda_sk(sk);
718 int err;
717 719
720 lock_kernel();
718 memset(&saddr, 0, sizeof(saddr)); 721 memset(&saddr, 0, sizeof(saddr));
719 if (peer) { 722 if (peer) {
723 err = -ENOTCONN;
720 if (sk->sk_state != TCP_ESTABLISHED) 724 if (sk->sk_state != TCP_ESTABLISHED)
721 return -ENOTCONN; 725 goto out;
722 726
723 saddr.sir_family = AF_IRDA; 727 saddr.sir_family = AF_IRDA;
724 saddr.sir_lsap_sel = self->dtsap_sel; 728 saddr.sir_lsap_sel = self->dtsap_sel;
@@ -735,8 +739,10 @@ static int irda_getname(struct socket *sock, struct sockaddr *uaddr,
735 /* uaddr_len come to us uninitialised */ 739 /* uaddr_len come to us uninitialised */
736 *uaddr_len = sizeof (struct sockaddr_irda); 740 *uaddr_len = sizeof (struct sockaddr_irda);
737 memcpy(uaddr, &saddr, *uaddr_len); 741 memcpy(uaddr, &saddr, *uaddr_len);
738 742 err = 0;
739 return 0; 743out:
744 unlock_kernel();
745 return err;
740} 746}
741 747
742/* 748/*
@@ -748,21 +754,25 @@ static int irda_getname(struct socket *sock, struct sockaddr *uaddr,
748static int irda_listen(struct socket *sock, int backlog) 754static int irda_listen(struct socket *sock, int backlog)
749{ 755{
750 struct sock *sk = sock->sk; 756 struct sock *sk = sock->sk;
757 int err = -EOPNOTSUPP;
751 758
752 IRDA_DEBUG(2, "%s()\n", __func__); 759 IRDA_DEBUG(2, "%s()\n", __func__);
753 760
761 lock_kernel();
754 if ((sk->sk_type != SOCK_STREAM) && (sk->sk_type != SOCK_SEQPACKET) && 762 if ((sk->sk_type != SOCK_STREAM) && (sk->sk_type != SOCK_SEQPACKET) &&
755 (sk->sk_type != SOCK_DGRAM)) 763 (sk->sk_type != SOCK_DGRAM))
756 return -EOPNOTSUPP; 764 goto out;
757 765
758 if (sk->sk_state != TCP_LISTEN) { 766 if (sk->sk_state != TCP_LISTEN) {
759 sk->sk_max_ack_backlog = backlog; 767 sk->sk_max_ack_backlog = backlog;
760 sk->sk_state = TCP_LISTEN; 768 sk->sk_state = TCP_LISTEN;
761 769
762 return 0; 770 err = 0;
763 } 771 }
772out:
773 unlock_kernel();
764 774
765 return -EOPNOTSUPP; 775 return err;
766} 776}
767 777
768/* 778/*
@@ -783,36 +793,40 @@ static int irda_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
783 if (addr_len != sizeof(struct sockaddr_irda)) 793 if (addr_len != sizeof(struct sockaddr_irda))
784 return -EINVAL; 794 return -EINVAL;
785 795
796 lock_kernel();
786#ifdef CONFIG_IRDA_ULTRA 797#ifdef CONFIG_IRDA_ULTRA
787 /* Special care for Ultra sockets */ 798 /* Special care for Ultra sockets */
788 if ((sk->sk_type == SOCK_DGRAM) && 799 if ((sk->sk_type == SOCK_DGRAM) &&
789 (sk->sk_protocol == IRDAPROTO_ULTRA)) { 800 (sk->sk_protocol == IRDAPROTO_ULTRA)) {
790 self->pid = addr->sir_lsap_sel; 801 self->pid = addr->sir_lsap_sel;
802 err = -EOPNOTSUPP;
791 if (self->pid & 0x80) { 803 if (self->pid & 0x80) {
792 IRDA_DEBUG(0, "%s(), extension in PID not supp!\n", __func__); 804 IRDA_DEBUG(0, "%s(), extension in PID not supp!\n", __func__);
793 return -EOPNOTSUPP; 805 goto out;
794 } 806 }
795 err = irda_open_lsap(self, self->pid); 807 err = irda_open_lsap(self, self->pid);
796 if (err < 0) 808 if (err < 0)
797 return err; 809 goto out;
798 810
799 /* Pretend we are connected */ 811 /* Pretend we are connected */
800 sock->state = SS_CONNECTED; 812 sock->state = SS_CONNECTED;
801 sk->sk_state = TCP_ESTABLISHED; 813 sk->sk_state = TCP_ESTABLISHED;
814 err = 0;
802 815
803 return 0; 816 goto out;
804 } 817 }
805#endif /* CONFIG_IRDA_ULTRA */ 818#endif /* CONFIG_IRDA_ULTRA */
806 819
807 self->ias_obj = irias_new_object(addr->sir_name, jiffies); 820 self->ias_obj = irias_new_object(addr->sir_name, jiffies);
821 err = -ENOMEM;
808 if (self->ias_obj == NULL) 822 if (self->ias_obj == NULL)
809 return -ENOMEM; 823 goto out;
810 824
811 err = irda_open_tsap(self, addr->sir_lsap_sel, addr->sir_name); 825 err = irda_open_tsap(self, addr->sir_lsap_sel, addr->sir_name);
812 if (err < 0) { 826 if (err < 0) {
813 kfree(self->ias_obj->name); 827 kfree(self->ias_obj->name);
814 kfree(self->ias_obj); 828 kfree(self->ias_obj);
815 return err; 829 goto out;
816 } 830 }
817 831
818 /* Register with LM-IAS */ 832 /* Register with LM-IAS */
@@ -820,7 +834,10 @@ static int irda_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
820 self->stsap_sel, IAS_KERNEL_ATTR); 834 self->stsap_sel, IAS_KERNEL_ATTR);
821 irias_insert_object(self->ias_obj); 835 irias_insert_object(self->ias_obj);
822 836
823 return 0; 837 err = 0;
838out:
839 unlock_kernel();
840 return err;
824} 841}
825 842
826/* 843/*
@@ -839,22 +856,26 @@ static int irda_accept(struct socket *sock, struct socket *newsock, int flags)
839 856
840 IRDA_DEBUG(2, "%s()\n", __func__); 857 IRDA_DEBUG(2, "%s()\n", __func__);
841 858
842 err = irda_create(sock_net(sk), newsock, sk->sk_protocol); 859 lock_kernel();
860 err = irda_create(sock_net(sk), newsock, sk->sk_protocol, 0);
843 if (err) 861 if (err)
844 return err; 862 goto out;
845 863
864 err = -EINVAL;
846 if (sock->state != SS_UNCONNECTED) 865 if (sock->state != SS_UNCONNECTED)
847 return -EINVAL; 866 goto out;
848 867
849 if ((sk = sock->sk) == NULL) 868 if ((sk = sock->sk) == NULL)
850 return -EINVAL; 869 goto out;
851 870
871 err = -EOPNOTSUPP;
852 if ((sk->sk_type != SOCK_STREAM) && (sk->sk_type != SOCK_SEQPACKET) && 872 if ((sk->sk_type != SOCK_STREAM) && (sk->sk_type != SOCK_SEQPACKET) &&
853 (sk->sk_type != SOCK_DGRAM)) 873 (sk->sk_type != SOCK_DGRAM))
854 return -EOPNOTSUPP; 874 goto out;
855 875
876 err = -EINVAL;
856 if (sk->sk_state != TCP_LISTEN) 877 if (sk->sk_state != TCP_LISTEN)
857 return -EINVAL; 878 goto out;
858 879
859 /* 880 /*
860 * The read queue this time is holding sockets ready to use 881 * The read queue this time is holding sockets ready to use
@@ -875,18 +896,20 @@ static int irda_accept(struct socket *sock, struct socket *newsock, int flags)
875 break; 896 break;
876 897
877 /* Non blocking operation */ 898 /* Non blocking operation */
899 err = -EWOULDBLOCK;
878 if (flags & O_NONBLOCK) 900 if (flags & O_NONBLOCK)
879 return -EWOULDBLOCK; 901 goto out;
880 902
881 err = wait_event_interruptible(*(sk->sk_sleep), 903 err = wait_event_interruptible(*(sk->sk_sleep),
882 skb_peek(&sk->sk_receive_queue)); 904 skb_peek(&sk->sk_receive_queue));
883 if (err) 905 if (err)
884 return err; 906 goto out;
885 } 907 }
886 908
887 newsk = newsock->sk; 909 newsk = newsock->sk;
910 err = -EIO;
888 if (newsk == NULL) 911 if (newsk == NULL)
889 return -EIO; 912 goto out;
890 913
891 newsk->sk_state = TCP_ESTABLISHED; 914 newsk->sk_state = TCP_ESTABLISHED;
892 915
@@ -894,10 +917,11 @@ static int irda_accept(struct socket *sock, struct socket *newsock, int flags)
894 917
895 /* Now attach up the new socket */ 918 /* Now attach up the new socket */
896 new->tsap = irttp_dup(self->tsap, new); 919 new->tsap = irttp_dup(self->tsap, new);
920 err = -EPERM; /* value does not seem to make sense. -arnd */
897 if (!new->tsap) { 921 if (!new->tsap) {
898 IRDA_DEBUG(0, "%s(), dup failed!\n", __func__); 922 IRDA_DEBUG(0, "%s(), dup failed!\n", __func__);
899 kfree_skb(skb); 923 kfree_skb(skb);
900 return -1; 924 goto out;
901 } 925 }
902 926
903 new->stsap_sel = new->tsap->stsap_sel; 927 new->stsap_sel = new->tsap->stsap_sel;
@@ -921,8 +945,10 @@ static int irda_accept(struct socket *sock, struct socket *newsock, int flags)
921 newsock->state = SS_CONNECTED; 945 newsock->state = SS_CONNECTED;
922 946
923 irda_connect_response(new); 947 irda_connect_response(new);
924 948 err = 0;
925 return 0; 949out:
950 unlock_kernel();
951 return err;
926} 952}
927 953
928/* 954/*
@@ -955,28 +981,34 @@ static int irda_connect(struct socket *sock, struct sockaddr *uaddr,
955 981
956 IRDA_DEBUG(2, "%s(%p)\n", __func__, self); 982 IRDA_DEBUG(2, "%s(%p)\n", __func__, self);
957 983
984 lock_kernel();
958 /* Don't allow connect for Ultra sockets */ 985 /* Don't allow connect for Ultra sockets */
986 err = -ESOCKTNOSUPPORT;
959 if ((sk->sk_type == SOCK_DGRAM) && (sk->sk_protocol == IRDAPROTO_ULTRA)) 987 if ((sk->sk_type == SOCK_DGRAM) && (sk->sk_protocol == IRDAPROTO_ULTRA))
960 return -ESOCKTNOSUPPORT; 988 goto out;
961 989
962 if (sk->sk_state == TCP_ESTABLISHED && sock->state == SS_CONNECTING) { 990 if (sk->sk_state == TCP_ESTABLISHED && sock->state == SS_CONNECTING) {
963 sock->state = SS_CONNECTED; 991 sock->state = SS_CONNECTED;
964 return 0; /* Connect completed during a ERESTARTSYS event */ 992 err = 0;
993 goto out; /* Connect completed during a ERESTARTSYS event */
965 } 994 }
966 995
967 if (sk->sk_state == TCP_CLOSE && sock->state == SS_CONNECTING) { 996 if (sk->sk_state == TCP_CLOSE && sock->state == SS_CONNECTING) {
968 sock->state = SS_UNCONNECTED; 997 sock->state = SS_UNCONNECTED;
969 return -ECONNREFUSED; 998 err = -ECONNREFUSED;
999 goto out;
970 } 1000 }
971 1001
1002 err = -EISCONN; /* No reconnect on a seqpacket socket */
972 if (sk->sk_state == TCP_ESTABLISHED) 1003 if (sk->sk_state == TCP_ESTABLISHED)
973 return -EISCONN; /* No reconnect on a seqpacket socket */ 1004 goto out;
974 1005
975 sk->sk_state = TCP_CLOSE; 1006 sk->sk_state = TCP_CLOSE;
976 sock->state = SS_UNCONNECTED; 1007 sock->state = SS_UNCONNECTED;
977 1008
1009 err = -EINVAL;
978 if (addr_len != sizeof(struct sockaddr_irda)) 1010 if (addr_len != sizeof(struct sockaddr_irda))
979 return -EINVAL; 1011 goto out;
980 1012
981 /* Check if user supplied any destination device address */ 1013 /* Check if user supplied any destination device address */
982 if ((!addr->sir_addr) || (addr->sir_addr == DEV_ADDR_ANY)) { 1014 if ((!addr->sir_addr) || (addr->sir_addr == DEV_ADDR_ANY)) {
@@ -984,7 +1016,7 @@ static int irda_connect(struct socket *sock, struct sockaddr *uaddr,
984 err = irda_discover_daddr_and_lsap_sel(self, addr->sir_name); 1016 err = irda_discover_daddr_and_lsap_sel(self, addr->sir_name);
985 if (err) { 1017 if (err) {
986 IRDA_DEBUG(0, "%s(), auto-connect failed!\n", __func__); 1018 IRDA_DEBUG(0, "%s(), auto-connect failed!\n", __func__);
987 return err; 1019 goto out;
988 } 1020 }
989 } else { 1021 } else {
990 /* Use the one provided by the user */ 1022 /* Use the one provided by the user */
@@ -1000,7 +1032,7 @@ static int irda_connect(struct socket *sock, struct sockaddr *uaddr,
1000 err = irda_find_lsap_sel(self, addr->sir_name); 1032 err = irda_find_lsap_sel(self, addr->sir_name);
1001 if (err) { 1033 if (err) {
1002 IRDA_DEBUG(0, "%s(), connect failed!\n", __func__); 1034 IRDA_DEBUG(0, "%s(), connect failed!\n", __func__);
1003 return err; 1035 goto out;
1004 } 1036 }
1005 } else { 1037 } else {
1006 /* Directly connect to the remote LSAP 1038 /* Directly connect to the remote LSAP
@@ -1025,29 +1057,35 @@ static int irda_connect(struct socket *sock, struct sockaddr *uaddr,
1025 self->max_sdu_size_rx, NULL); 1057 self->max_sdu_size_rx, NULL);
1026 if (err) { 1058 if (err) {
1027 IRDA_DEBUG(0, "%s(), connect failed!\n", __func__); 1059 IRDA_DEBUG(0, "%s(), connect failed!\n", __func__);
1028 return err; 1060 goto out;
1029 } 1061 }
1030 1062
1031 /* Now the loop */ 1063 /* Now the loop */
1064 err = -EINPROGRESS;
1032 if (sk->sk_state != TCP_ESTABLISHED && (flags & O_NONBLOCK)) 1065 if (sk->sk_state != TCP_ESTABLISHED && (flags & O_NONBLOCK))
1033 return -EINPROGRESS; 1066 goto out;
1034 1067
1068 err = -ERESTARTSYS;
1035 if (wait_event_interruptible(*(sk->sk_sleep), 1069 if (wait_event_interruptible(*(sk->sk_sleep),
1036 (sk->sk_state != TCP_SYN_SENT))) 1070 (sk->sk_state != TCP_SYN_SENT)))
1037 return -ERESTARTSYS; 1071 goto out;
1038 1072
1039 if (sk->sk_state != TCP_ESTABLISHED) { 1073 if (sk->sk_state != TCP_ESTABLISHED) {
1040 sock->state = SS_UNCONNECTED; 1074 sock->state = SS_UNCONNECTED;
1041 err = sock_error(sk); 1075 err = sock_error(sk);
1042 return err? err : -ECONNRESET; 1076 if (!err)
1077 err = -ECONNRESET;
1078 goto out;
1043 } 1079 }
1044 1080
1045 sock->state = SS_CONNECTED; 1081 sock->state = SS_CONNECTED;
1046 1082
1047 /* At this point, IrLMP has assigned our source address */ 1083 /* At this point, IrLMP has assigned our source address */
1048 self->saddr = irttp_get_saddr(self->tsap); 1084 self->saddr = irttp_get_saddr(self->tsap);
1049 1085 err = 0;
1050 return 0; 1086out:
1087 unlock_kernel();
1088 return err;
1051} 1089}
1052 1090
1053static struct proto irda_proto = { 1091static struct proto irda_proto = {
@@ -1062,7 +1100,8 @@ static struct proto irda_proto = {
1062 * Create IrDA socket 1100 * Create IrDA socket
1063 * 1101 *
1064 */ 1102 */
1065static int irda_create(struct net *net, struct socket *sock, int protocol) 1103static int irda_create(struct net *net, struct socket *sock, int protocol,
1104 int kern)
1066{ 1105{
1067 struct sock *sk; 1106 struct sock *sk;
1068 struct irda_sock *self; 1107 struct irda_sock *self;
@@ -1192,6 +1231,7 @@ static int irda_release(struct socket *sock)
1192 if (sk == NULL) 1231 if (sk == NULL)
1193 return 0; 1232 return 0;
1194 1233
1234 lock_kernel();
1195 lock_sock(sk); 1235 lock_sock(sk);
1196 sk->sk_state = TCP_CLOSE; 1236 sk->sk_state = TCP_CLOSE;
1197 sk->sk_shutdown |= SEND_SHUTDOWN; 1237 sk->sk_shutdown |= SEND_SHUTDOWN;
@@ -1210,6 +1250,7 @@ static int irda_release(struct socket *sock)
1210 /* Destroy networking socket if we are the last reference on it, 1250 /* Destroy networking socket if we are the last reference on it,
1211 * i.e. if(sk->sk_refcnt == 0) -> sk_free(sk) */ 1251 * i.e. if(sk->sk_refcnt == 0) -> sk_free(sk) */
1212 sock_put(sk); 1252 sock_put(sk);
1253 unlock_kernel();
1213 1254
1214 /* Notes on socket locking and deallocation... - Jean II 1255 /* Notes on socket locking and deallocation... - Jean II
1215 * In theory we should put pairs of sock_hold() / sock_put() to 1256 * In theory we should put pairs of sock_hold() / sock_put() to
@@ -1257,28 +1298,37 @@ static int irda_sendmsg(struct kiocb *iocb, struct socket *sock,
1257 1298
1258 IRDA_DEBUG(4, "%s(), len=%zd\n", __func__, len); 1299 IRDA_DEBUG(4, "%s(), len=%zd\n", __func__, len);
1259 1300
1301 lock_kernel();
1260 /* Note : socket.c set MSG_EOR on SEQPACKET sockets */ 1302 /* Note : socket.c set MSG_EOR on SEQPACKET sockets */
1261 if (msg->msg_flags & ~(MSG_DONTWAIT | MSG_EOR | MSG_CMSG_COMPAT | 1303 if (msg->msg_flags & ~(MSG_DONTWAIT | MSG_EOR | MSG_CMSG_COMPAT |
1262 MSG_NOSIGNAL)) 1304 MSG_NOSIGNAL)) {
1263 return -EINVAL; 1305 err = -EINVAL;
1306 goto out;
1307 }
1264 1308
1265 if (sk->sk_shutdown & SEND_SHUTDOWN) 1309 if (sk->sk_shutdown & SEND_SHUTDOWN)
1266 goto out_err; 1310 goto out_err;
1267 1311
1268 if (sk->sk_state != TCP_ESTABLISHED) 1312 if (sk->sk_state != TCP_ESTABLISHED) {
1269 return -ENOTCONN; 1313 err = -ENOTCONN;
1314 goto out;
1315 }
1270 1316
1271 self = irda_sk(sk); 1317 self = irda_sk(sk);
1272 1318
1273 /* Check if IrTTP is wants us to slow down */ 1319 /* Check if IrTTP is wants us to slow down */
1274 1320
1275 if (wait_event_interruptible(*(sk->sk_sleep), 1321 if (wait_event_interruptible(*(sk->sk_sleep),
1276 (self->tx_flow != FLOW_STOP || sk->sk_state != TCP_ESTABLISHED))) 1322 (self->tx_flow != FLOW_STOP || sk->sk_state != TCP_ESTABLISHED))) {
1277 return -ERESTARTSYS; 1323 err = -ERESTARTSYS;
1324 goto out;
1325 }
1278 1326
1279 /* Check if we are still connected */ 1327 /* Check if we are still connected */
1280 if (sk->sk_state != TCP_ESTABLISHED) 1328 if (sk->sk_state != TCP_ESTABLISHED) {
1281 return -ENOTCONN; 1329 err = -ENOTCONN;
1330 goto out;
1331 }
1282 1332
1283 /* Check that we don't send out too big frames */ 1333 /* Check that we don't send out too big frames */
1284 if (len > self->max_data_size) { 1334 if (len > self->max_data_size) {
@@ -1310,11 +1360,16 @@ static int irda_sendmsg(struct kiocb *iocb, struct socket *sock,
1310 IRDA_DEBUG(0, "%s(), err=%d\n", __func__, err); 1360 IRDA_DEBUG(0, "%s(), err=%d\n", __func__, err);
1311 goto out_err; 1361 goto out_err;
1312 } 1362 }
1363
1364 unlock_kernel();
1313 /* Tell client how much data we actually sent */ 1365 /* Tell client how much data we actually sent */
1314 return len; 1366 return len;
1315 1367
1316 out_err: 1368out_err:
1317 return sk_stream_error(sk, msg->msg_flags, err); 1369 err = sk_stream_error(sk, msg->msg_flags, err);
1370out:
1371 unlock_kernel();
1372 return err;
1318 1373
1319} 1374}
1320 1375
@@ -1335,13 +1390,14 @@ static int irda_recvmsg_dgram(struct kiocb *iocb, struct socket *sock,
1335 1390
1336 IRDA_DEBUG(4, "%s()\n", __func__); 1391 IRDA_DEBUG(4, "%s()\n", __func__);
1337 1392
1393 lock_kernel();
1338 if ((err = sock_error(sk)) < 0) 1394 if ((err = sock_error(sk)) < 0)
1339 return err; 1395 goto out;
1340 1396
1341 skb = skb_recv_datagram(sk, flags & ~MSG_DONTWAIT, 1397 skb = skb_recv_datagram(sk, flags & ~MSG_DONTWAIT,
1342 flags & MSG_DONTWAIT, &err); 1398 flags & MSG_DONTWAIT, &err);
1343 if (!skb) 1399 if (!skb)
1344 return err; 1400 goto out;
1345 1401
1346 skb_reset_transport_header(skb); 1402 skb_reset_transport_header(skb);
1347 copied = skb->len; 1403 copied = skb->len;
@@ -1369,8 +1425,12 @@ static int irda_recvmsg_dgram(struct kiocb *iocb, struct socket *sock,
1369 irttp_flow_request(self->tsap, FLOW_START); 1425 irttp_flow_request(self->tsap, FLOW_START);
1370 } 1426 }
1371 } 1427 }
1372 1428 unlock_kernel();
1373 return copied; 1429 return copied;
1430
1431out:
1432 unlock_kernel();
1433 return err;
1374} 1434}
1375 1435
1376/* 1436/*
@@ -1388,15 +1448,19 @@ static int irda_recvmsg_stream(struct kiocb *iocb, struct socket *sock,
1388 1448
1389 IRDA_DEBUG(3, "%s()\n", __func__); 1449 IRDA_DEBUG(3, "%s()\n", __func__);
1390 1450
1451 lock_kernel();
1391 if ((err = sock_error(sk)) < 0) 1452 if ((err = sock_error(sk)) < 0)
1392 return err; 1453 goto out;
1393 1454
1455 err = -EINVAL;
1394 if (sock->flags & __SO_ACCEPTCON) 1456 if (sock->flags & __SO_ACCEPTCON)
1395 return(-EINVAL); 1457 goto out;
1396 1458
1459 err =-EOPNOTSUPP;
1397 if (flags & MSG_OOB) 1460 if (flags & MSG_OOB)
1398 return -EOPNOTSUPP; 1461 goto out;
1399 1462
1463 err = 0;
1400 target = sock_rcvlowat(sk, flags & MSG_WAITALL, size); 1464 target = sock_rcvlowat(sk, flags & MSG_WAITALL, size);
1401 timeo = sock_rcvtimeo(sk, noblock); 1465 timeo = sock_rcvtimeo(sk, noblock);
1402 1466
@@ -1408,7 +1472,7 @@ static int irda_recvmsg_stream(struct kiocb *iocb, struct socket *sock,
1408 1472
1409 if (skb == NULL) { 1473 if (skb == NULL) {
1410 DEFINE_WAIT(wait); 1474 DEFINE_WAIT(wait);
1411 int ret = 0; 1475 err = 0;
1412 1476
1413 if (copied >= target) 1477 if (copied >= target)
1414 break; 1478 break;
@@ -1418,25 +1482,25 @@ static int irda_recvmsg_stream(struct kiocb *iocb, struct socket *sock,
1418 /* 1482 /*
1419 * POSIX 1003.1g mandates this order. 1483 * POSIX 1003.1g mandates this order.
1420 */ 1484 */
1421 ret = sock_error(sk); 1485 err = sock_error(sk);
1422 if (ret) 1486 if (err)
1423 ; 1487 ;
1424 else if (sk->sk_shutdown & RCV_SHUTDOWN) 1488 else if (sk->sk_shutdown & RCV_SHUTDOWN)
1425 ; 1489 ;
1426 else if (noblock) 1490 else if (noblock)
1427 ret = -EAGAIN; 1491 err = -EAGAIN;
1428 else if (signal_pending(current)) 1492 else if (signal_pending(current))
1429 ret = sock_intr_errno(timeo); 1493 err = sock_intr_errno(timeo);
1430 else if (sk->sk_state != TCP_ESTABLISHED) 1494 else if (sk->sk_state != TCP_ESTABLISHED)
1431 ret = -ENOTCONN; 1495 err = -ENOTCONN;
1432 else if (skb_peek(&sk->sk_receive_queue) == NULL) 1496 else if (skb_peek(&sk->sk_receive_queue) == NULL)
1433 /* Wait process until data arrives */ 1497 /* Wait process until data arrives */
1434 schedule(); 1498 schedule();
1435 1499
1436 finish_wait(sk->sk_sleep, &wait); 1500 finish_wait(sk->sk_sleep, &wait);
1437 1501
1438 if (ret) 1502 if (err)
1439 return ret; 1503 goto out;
1440 if (sk->sk_shutdown & RCV_SHUTDOWN) 1504 if (sk->sk_shutdown & RCV_SHUTDOWN)
1441 break; 1505 break;
1442 1506
@@ -1489,7 +1553,9 @@ static int irda_recvmsg_stream(struct kiocb *iocb, struct socket *sock,
1489 } 1553 }
1490 } 1554 }
1491 1555
1492 return copied; 1556out:
1557 unlock_kernel();
1558 return err ? : copied;
1493} 1559}
1494 1560
1495/* 1561/*
@@ -1507,18 +1573,23 @@ static int irda_sendmsg_dgram(struct kiocb *iocb, struct socket *sock,
1507 struct sk_buff *skb; 1573 struct sk_buff *skb;
1508 int err; 1574 int err;
1509 1575
1576 lock_kernel();
1577
1510 IRDA_DEBUG(4, "%s(), len=%zd\n", __func__, len); 1578 IRDA_DEBUG(4, "%s(), len=%zd\n", __func__, len);
1511 1579
1580 err = -EINVAL;
1512 if (msg->msg_flags & ~(MSG_DONTWAIT|MSG_CMSG_COMPAT)) 1581 if (msg->msg_flags & ~(MSG_DONTWAIT|MSG_CMSG_COMPAT))
1513 return -EINVAL; 1582 goto out;
1514 1583
1515 if (sk->sk_shutdown & SEND_SHUTDOWN) { 1584 if (sk->sk_shutdown & SEND_SHUTDOWN) {
1516 send_sig(SIGPIPE, current, 0); 1585 send_sig(SIGPIPE, current, 0);
1517 return -EPIPE; 1586 err = -EPIPE;
1587 goto out;
1518 } 1588 }
1519 1589
1590 err = -ENOTCONN;
1520 if (sk->sk_state != TCP_ESTABLISHED) 1591 if (sk->sk_state != TCP_ESTABLISHED)
1521 return -ENOTCONN; 1592 goto out;
1522 1593
1523 self = irda_sk(sk); 1594 self = irda_sk(sk);
1524 1595
@@ -1535,8 +1606,9 @@ static int irda_sendmsg_dgram(struct kiocb *iocb, struct socket *sock,
1535 1606
1536 skb = sock_alloc_send_skb(sk, len + self->max_header_size, 1607 skb = sock_alloc_send_skb(sk, len + self->max_header_size,
1537 msg->msg_flags & MSG_DONTWAIT, &err); 1608 msg->msg_flags & MSG_DONTWAIT, &err);
1609 err = -ENOBUFS;
1538 if (!skb) 1610 if (!skb)
1539 return -ENOBUFS; 1611 goto out;
1540 1612
1541 skb_reserve(skb, self->max_header_size); 1613 skb_reserve(skb, self->max_header_size);
1542 skb_reset_transport_header(skb); 1614 skb_reset_transport_header(skb);
@@ -1546,7 +1618,7 @@ static int irda_sendmsg_dgram(struct kiocb *iocb, struct socket *sock,
1546 err = memcpy_fromiovec(skb_transport_header(skb), msg->msg_iov, len); 1618 err = memcpy_fromiovec(skb_transport_header(skb), msg->msg_iov, len);
1547 if (err) { 1619 if (err) {
1548 kfree_skb(skb); 1620 kfree_skb(skb);
1549 return err; 1621 goto out;
1550 } 1622 }
1551 1623
1552 /* 1624 /*
@@ -1556,9 +1628,13 @@ static int irda_sendmsg_dgram(struct kiocb *iocb, struct socket *sock,
1556 err = irttp_udata_request(self->tsap, skb); 1628 err = irttp_udata_request(self->tsap, skb);
1557 if (err) { 1629 if (err) {
1558 IRDA_DEBUG(0, "%s(), err=%d\n", __func__, err); 1630 IRDA_DEBUG(0, "%s(), err=%d\n", __func__, err);
1559 return err; 1631 goto out;
1560 } 1632 }
1633 unlock_kernel();
1561 return len; 1634 return len;
1635out:
1636 unlock_kernel();
1637 return err;
1562} 1638}
1563 1639
1564/* 1640/*
@@ -1580,12 +1656,15 @@ static int irda_sendmsg_ultra(struct kiocb *iocb, struct socket *sock,
1580 1656
1581 IRDA_DEBUG(4, "%s(), len=%zd\n", __func__, len); 1657 IRDA_DEBUG(4, "%s(), len=%zd\n", __func__, len);
1582 1658
1659 lock_kernel();
1660 err = -EINVAL;
1583 if (msg->msg_flags & ~(MSG_DONTWAIT|MSG_CMSG_COMPAT)) 1661 if (msg->msg_flags & ~(MSG_DONTWAIT|MSG_CMSG_COMPAT))
1584 return -EINVAL; 1662 goto out;
1585 1663
1664 err = -EPIPE;
1586 if (sk->sk_shutdown & SEND_SHUTDOWN) { 1665 if (sk->sk_shutdown & SEND_SHUTDOWN) {
1587 send_sig(SIGPIPE, current, 0); 1666 send_sig(SIGPIPE, current, 0);
1588 return -EPIPE; 1667 goto out;
1589 } 1668 }
1590 1669
1591 self = irda_sk(sk); 1670 self = irda_sk(sk);
@@ -1593,16 +1672,18 @@ static int irda_sendmsg_ultra(struct kiocb *iocb, struct socket *sock,
1593 /* Check if an address was specified with sendto. Jean II */ 1672 /* Check if an address was specified with sendto. Jean II */
1594 if (msg->msg_name) { 1673 if (msg->msg_name) {
1595 struct sockaddr_irda *addr = (struct sockaddr_irda *) msg->msg_name; 1674 struct sockaddr_irda *addr = (struct sockaddr_irda *) msg->msg_name;
1675 err = -EINVAL;
1596 /* Check address, extract pid. Jean II */ 1676 /* Check address, extract pid. Jean II */
1597 if (msg->msg_namelen < sizeof(*addr)) 1677 if (msg->msg_namelen < sizeof(*addr))
1598 return -EINVAL; 1678 goto out;
1599 if (addr->sir_family != AF_IRDA) 1679 if (addr->sir_family != AF_IRDA)
1600 return -EINVAL; 1680 goto out;
1601 1681
1602 pid = addr->sir_lsap_sel; 1682 pid = addr->sir_lsap_sel;
1603 if (pid & 0x80) { 1683 if (pid & 0x80) {
1604 IRDA_DEBUG(0, "%s(), extension in PID not supp!\n", __func__); 1684 IRDA_DEBUG(0, "%s(), extension in PID not supp!\n", __func__);
1605 return -EOPNOTSUPP; 1685 err = -EOPNOTSUPP;
1686 goto out;
1606 } 1687 }
1607 } else { 1688 } else {
1608 /* Check that the socket is properly bound to an Ultra 1689 /* Check that the socket is properly bound to an Ultra
@@ -1611,7 +1692,8 @@ static int irda_sendmsg_ultra(struct kiocb *iocb, struct socket *sock,
1611 (sk->sk_state != TCP_ESTABLISHED)) { 1692 (sk->sk_state != TCP_ESTABLISHED)) {
1612 IRDA_DEBUG(0, "%s(), socket not bound to Ultra PID.\n", 1693 IRDA_DEBUG(0, "%s(), socket not bound to Ultra PID.\n",
1613 __func__); 1694 __func__);
1614 return -ENOTCONN; 1695 err = -ENOTCONN;
1696 goto out;
1615 } 1697 }
1616 /* Use PID from socket */ 1698 /* Use PID from socket */
1617 bound = 1; 1699 bound = 1;
@@ -1630,8 +1712,9 @@ static int irda_sendmsg_ultra(struct kiocb *iocb, struct socket *sock,
1630 1712
1631 skb = sock_alloc_send_skb(sk, len + self->max_header_size, 1713 skb = sock_alloc_send_skb(sk, len + self->max_header_size,
1632 msg->msg_flags & MSG_DONTWAIT, &err); 1714 msg->msg_flags & MSG_DONTWAIT, &err);
1715 err = -ENOBUFS;
1633 if (!skb) 1716 if (!skb)
1634 return -ENOBUFS; 1717 goto out;
1635 1718
1636 skb_reserve(skb, self->max_header_size); 1719 skb_reserve(skb, self->max_header_size);
1637 skb_reset_transport_header(skb); 1720 skb_reset_transport_header(skb);
@@ -1641,16 +1724,16 @@ static int irda_sendmsg_ultra(struct kiocb *iocb, struct socket *sock,
1641 err = memcpy_fromiovec(skb_transport_header(skb), msg->msg_iov, len); 1724 err = memcpy_fromiovec(skb_transport_header(skb), msg->msg_iov, len);
1642 if (err) { 1725 if (err) {
1643 kfree_skb(skb); 1726 kfree_skb(skb);
1644 return err; 1727 goto out;
1645 } 1728 }
1646 1729
1647 err = irlmp_connless_data_request((bound ? self->lsap : NULL), 1730 err = irlmp_connless_data_request((bound ? self->lsap : NULL),
1648 skb, pid); 1731 skb, pid);
1649 if (err) { 1732 if (err)
1650 IRDA_DEBUG(0, "%s(), err=%d\n", __func__, err); 1733 IRDA_DEBUG(0, "%s(), err=%d\n", __func__, err);
1651 return err; 1734out:
1652 } 1735 unlock_kernel();
1653 return len; 1736 return err ? : len;
1654} 1737}
1655#endif /* CONFIG_IRDA_ULTRA */ 1738#endif /* CONFIG_IRDA_ULTRA */
1656 1739
@@ -1664,6 +1747,8 @@ static int irda_shutdown(struct socket *sock, int how)
1664 1747
1665 IRDA_DEBUG(1, "%s(%p)\n", __func__, self); 1748 IRDA_DEBUG(1, "%s(%p)\n", __func__, self);
1666 1749
1750 lock_kernel();
1751
1667 sk->sk_state = TCP_CLOSE; 1752 sk->sk_state = TCP_CLOSE;
1668 sk->sk_shutdown |= SEND_SHUTDOWN; 1753 sk->sk_shutdown |= SEND_SHUTDOWN;
1669 sk->sk_state_change(sk); 1754 sk->sk_state_change(sk);
@@ -1684,6 +1769,8 @@ static int irda_shutdown(struct socket *sock, int how)
1684 self->daddr = DEV_ADDR_ANY; /* Until we get re-connected */ 1769 self->daddr = DEV_ADDR_ANY; /* Until we get re-connected */
1685 self->saddr = 0x0; /* so IrLMP assign us any link */ 1770 self->saddr = 0x0; /* so IrLMP assign us any link */
1686 1771
1772 unlock_kernel();
1773
1687 return 0; 1774 return 0;
1688} 1775}
1689 1776
@@ -1699,6 +1786,7 @@ static unsigned int irda_poll(struct file * file, struct socket *sock,
1699 1786
1700 IRDA_DEBUG(4, "%s()\n", __func__); 1787 IRDA_DEBUG(4, "%s()\n", __func__);
1701 1788
1789 lock_kernel();
1702 poll_wait(file, sk->sk_sleep, wait); 1790 poll_wait(file, sk->sk_sleep, wait);
1703 mask = 0; 1791 mask = 0;
1704 1792
@@ -1746,18 +1834,34 @@ static unsigned int irda_poll(struct file * file, struct socket *sock,
1746 default: 1834 default:
1747 break; 1835 break;
1748 } 1836 }
1837 unlock_kernel();
1749 return mask; 1838 return mask;
1750} 1839}
1751 1840
1841static unsigned int irda_datagram_poll(struct file *file, struct socket *sock,
1842 poll_table *wait)
1843{
1844 int err;
1845
1846 lock_kernel();
1847 err = datagram_poll(file, sock, wait);
1848 unlock_kernel();
1849
1850 return err;
1851}
1852
1752/* 1853/*
1753 * Function irda_ioctl (sock, cmd, arg) 1854 * Function irda_ioctl (sock, cmd, arg)
1754 */ 1855 */
1755static int irda_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg) 1856static int irda_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
1756{ 1857{
1757 struct sock *sk = sock->sk; 1858 struct sock *sk = sock->sk;
1859 int err;
1758 1860
1759 IRDA_DEBUG(4, "%s(), cmd=%#x\n", __func__, cmd); 1861 IRDA_DEBUG(4, "%s(), cmd=%#x\n", __func__, cmd);
1760 1862
1863 lock_kernel();
1864 err = -EINVAL;
1761 switch (cmd) { 1865 switch (cmd) {
1762 case TIOCOUTQ: { 1866 case TIOCOUTQ: {
1763 long amount; 1867 long amount;
@@ -1765,9 +1869,8 @@ static int irda_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
1765 amount = sk->sk_sndbuf - sk_wmem_alloc_get(sk); 1869 amount = sk->sk_sndbuf - sk_wmem_alloc_get(sk);
1766 if (amount < 0) 1870 if (amount < 0)
1767 amount = 0; 1871 amount = 0;
1768 if (put_user(amount, (unsigned int __user *)arg)) 1872 err = put_user(amount, (unsigned int __user *)arg);
1769 return -EFAULT; 1873 break;
1770 return 0;
1771 } 1874 }
1772 1875
1773 case TIOCINQ: { 1876 case TIOCINQ: {
@@ -1776,15 +1879,14 @@ static int irda_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
1776 /* These two are safe on a single CPU system as only user tasks fiddle here */ 1879 /* These two are safe on a single CPU system as only user tasks fiddle here */
1777 if ((skb = skb_peek(&sk->sk_receive_queue)) != NULL) 1880 if ((skb = skb_peek(&sk->sk_receive_queue)) != NULL)
1778 amount = skb->len; 1881 amount = skb->len;
1779 if (put_user(amount, (unsigned int __user *)arg)) 1882 err = put_user(amount, (unsigned int __user *)arg);
1780 return -EFAULT; 1883 break;
1781 return 0;
1782 } 1884 }
1783 1885
1784 case SIOCGSTAMP: 1886 case SIOCGSTAMP:
1785 if (sk != NULL) 1887 if (sk != NULL)
1786 return sock_get_timestamp(sk, (struct timeval __user *)arg); 1888 err = sock_get_timestamp(sk, (struct timeval __user *)arg);
1787 return -EINVAL; 1889 break;
1788 1890
1789 case SIOCGIFADDR: 1891 case SIOCGIFADDR:
1790 case SIOCSIFADDR: 1892 case SIOCSIFADDR:
@@ -1796,14 +1898,14 @@ static int irda_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
1796 case SIOCSIFNETMASK: 1898 case SIOCSIFNETMASK:
1797 case SIOCGIFMETRIC: 1899 case SIOCGIFMETRIC:
1798 case SIOCSIFMETRIC: 1900 case SIOCSIFMETRIC:
1799 return -EINVAL; 1901 break;
1800 default: 1902 default:
1801 IRDA_DEBUG(1, "%s(), doing device ioctl!\n", __func__); 1903 IRDA_DEBUG(1, "%s(), doing device ioctl!\n", __func__);
1802 return -ENOIOCTLCMD; 1904 err = -ENOIOCTLCMD;
1803 } 1905 }
1906 unlock_kernel();
1804 1907
1805 /*NOTREACHED*/ 1908 return err;
1806 return 0;
1807} 1909}
1808 1910
1809#ifdef CONFIG_COMPAT 1911#ifdef CONFIG_COMPAT
@@ -1825,7 +1927,7 @@ static int irda_compat_ioctl(struct socket *sock, unsigned int cmd, unsigned lon
1825 * Set some options for the socket 1927 * Set some options for the socket
1826 * 1928 *
1827 */ 1929 */
1828static int irda_setsockopt(struct socket *sock, int level, int optname, 1930static int __irda_setsockopt(struct socket *sock, int level, int optname,
1829 char __user *optval, unsigned int optlen) 1931 char __user *optval, unsigned int optlen)
1830{ 1932{
1831 struct sock *sk = sock->sk; 1933 struct sock *sk = sock->sk;
@@ -2083,6 +2185,18 @@ static int irda_setsockopt(struct socket *sock, int level, int optname,
2083 return 0; 2185 return 0;
2084} 2186}
2085 2187
2188static int irda_setsockopt(struct socket *sock, int level, int optname,
2189 char __user *optval, unsigned int optlen)
2190{
2191 int err;
2192
2193 lock_kernel();
2194 err = __irda_setsockopt(sock, level, optname, optval, optlen);
2195 unlock_kernel();
2196
2197 return err;
2198}
2199
2086/* 2200/*
2087 * Function irda_extract_ias_value(ias_opt, ias_value) 2201 * Function irda_extract_ias_value(ias_opt, ias_value)
2088 * 2202 *
@@ -2135,7 +2249,7 @@ static int irda_extract_ias_value(struct irda_ias_set *ias_opt,
2135/* 2249/*
2136 * Function irda_getsockopt (sock, level, optname, optval, optlen) 2250 * Function irda_getsockopt (sock, level, optname, optval, optlen)
2137 */ 2251 */
2138static int irda_getsockopt(struct socket *sock, int level, int optname, 2252static int __irda_getsockopt(struct socket *sock, int level, int optname,
2139 char __user *optval, int __user *optlen) 2253 char __user *optval, int __user *optlen)
2140{ 2254{
2141 struct sock *sk = sock->sk; 2255 struct sock *sk = sock->sk;
@@ -2463,13 +2577,25 @@ bed:
2463 return 0; 2577 return 0;
2464} 2578}
2465 2579
2466static struct net_proto_family irda_family_ops = { 2580static int irda_getsockopt(struct socket *sock, int level, int optname,
2581 char __user *optval, int __user *optlen)
2582{
2583 int err;
2584
2585 lock_kernel();
2586 err = __irda_getsockopt(sock, level, optname, optval, optlen);
2587 unlock_kernel();
2588
2589 return err;
2590}
2591
2592static const struct net_proto_family irda_family_ops = {
2467 .family = PF_IRDA, 2593 .family = PF_IRDA,
2468 .create = irda_create, 2594 .create = irda_create,
2469 .owner = THIS_MODULE, 2595 .owner = THIS_MODULE,
2470}; 2596};
2471 2597
2472static const struct proto_ops SOCKOPS_WRAPPED(irda_stream_ops) = { 2598static const struct proto_ops irda_stream_ops = {
2473 .family = PF_IRDA, 2599 .family = PF_IRDA,
2474 .owner = THIS_MODULE, 2600 .owner = THIS_MODULE,
2475 .release = irda_release, 2601 .release = irda_release,
@@ -2493,7 +2619,7 @@ static const struct proto_ops SOCKOPS_WRAPPED(irda_stream_ops) = {
2493 .sendpage = sock_no_sendpage, 2619 .sendpage = sock_no_sendpage,
2494}; 2620};
2495 2621
2496static const struct proto_ops SOCKOPS_WRAPPED(irda_seqpacket_ops) = { 2622static const struct proto_ops irda_seqpacket_ops = {
2497 .family = PF_IRDA, 2623 .family = PF_IRDA,
2498 .owner = THIS_MODULE, 2624 .owner = THIS_MODULE,
2499 .release = irda_release, 2625 .release = irda_release,
@@ -2502,7 +2628,7 @@ static const struct proto_ops SOCKOPS_WRAPPED(irda_seqpacket_ops) = {
2502 .socketpair = sock_no_socketpair, 2628 .socketpair = sock_no_socketpair,
2503 .accept = irda_accept, 2629 .accept = irda_accept,
2504 .getname = irda_getname, 2630 .getname = irda_getname,
2505 .poll = datagram_poll, 2631 .poll = irda_datagram_poll,
2506 .ioctl = irda_ioctl, 2632 .ioctl = irda_ioctl,
2507#ifdef CONFIG_COMPAT 2633#ifdef CONFIG_COMPAT
2508 .compat_ioctl = irda_compat_ioctl, 2634 .compat_ioctl = irda_compat_ioctl,
@@ -2517,7 +2643,7 @@ static const struct proto_ops SOCKOPS_WRAPPED(irda_seqpacket_ops) = {
2517 .sendpage = sock_no_sendpage, 2643 .sendpage = sock_no_sendpage,
2518}; 2644};
2519 2645
2520static const struct proto_ops SOCKOPS_WRAPPED(irda_dgram_ops) = { 2646static const struct proto_ops irda_dgram_ops = {
2521 .family = PF_IRDA, 2647 .family = PF_IRDA,
2522 .owner = THIS_MODULE, 2648 .owner = THIS_MODULE,
2523 .release = irda_release, 2649 .release = irda_release,
@@ -2526,7 +2652,7 @@ static const struct proto_ops SOCKOPS_WRAPPED(irda_dgram_ops) = {
2526 .socketpair = sock_no_socketpair, 2652 .socketpair = sock_no_socketpair,
2527 .accept = irda_accept, 2653 .accept = irda_accept,
2528 .getname = irda_getname, 2654 .getname = irda_getname,
2529 .poll = datagram_poll, 2655 .poll = irda_datagram_poll,
2530 .ioctl = irda_ioctl, 2656 .ioctl = irda_ioctl,
2531#ifdef CONFIG_COMPAT 2657#ifdef CONFIG_COMPAT
2532 .compat_ioctl = irda_compat_ioctl, 2658 .compat_ioctl = irda_compat_ioctl,
@@ -2542,7 +2668,7 @@ static const struct proto_ops SOCKOPS_WRAPPED(irda_dgram_ops) = {
2542}; 2668};
2543 2669
2544#ifdef CONFIG_IRDA_ULTRA 2670#ifdef CONFIG_IRDA_ULTRA
2545static const struct proto_ops SOCKOPS_WRAPPED(irda_ultra_ops) = { 2671static const struct proto_ops irda_ultra_ops = {
2546 .family = PF_IRDA, 2672 .family = PF_IRDA,
2547 .owner = THIS_MODULE, 2673 .owner = THIS_MODULE,
2548 .release = irda_release, 2674 .release = irda_release,
@@ -2551,7 +2677,7 @@ static const struct proto_ops SOCKOPS_WRAPPED(irda_ultra_ops) = {
2551 .socketpair = sock_no_socketpair, 2677 .socketpair = sock_no_socketpair,
2552 .accept = sock_no_accept, 2678 .accept = sock_no_accept,
2553 .getname = irda_getname, 2679 .getname = irda_getname,
2554 .poll = datagram_poll, 2680 .poll = irda_datagram_poll,
2555 .ioctl = irda_ioctl, 2681 .ioctl = irda_ioctl,
2556#ifdef CONFIG_COMPAT 2682#ifdef CONFIG_COMPAT
2557 .compat_ioctl = irda_compat_ioctl, 2683 .compat_ioctl = irda_compat_ioctl,
@@ -2567,13 +2693,6 @@ static const struct proto_ops SOCKOPS_WRAPPED(irda_ultra_ops) = {
2567}; 2693};
2568#endif /* CONFIG_IRDA_ULTRA */ 2694#endif /* CONFIG_IRDA_ULTRA */
2569 2695
2570SOCKOPS_WRAP(irda_stream, PF_IRDA);
2571SOCKOPS_WRAP(irda_seqpacket, PF_IRDA);
2572SOCKOPS_WRAP(irda_dgram, PF_IRDA);
2573#ifdef CONFIG_IRDA_ULTRA
2574SOCKOPS_WRAP(irda_ultra, PF_IRDA);
2575#endif /* CONFIG_IRDA_ULTRA */
2576
2577/* 2696/*
2578 * Function irsock_init (pro) 2697 * Function irsock_init (pro)
2579 * 2698 *
diff --git a/net/irda/discovery.c b/net/irda/discovery.c
index a6f99b5a1499..c1c8ae939126 100644
--- a/net/irda/discovery.c
+++ b/net/irda/discovery.c
@@ -34,6 +34,7 @@
34#include <linux/socket.h> 34#include <linux/socket.h>
35#include <linux/fs.h> 35#include <linux/fs.h>
36#include <linux/seq_file.h> 36#include <linux/seq_file.h>
37#include <linux/slab.h>
37 38
38#include <net/irda/irda.h> 39#include <net/irda/irda.h>
39#include <net/irda/irlmp.h> 40#include <net/irda/irlmp.h>
diff --git a/net/irda/ircomm/ircomm_core.c b/net/irda/ircomm/ircomm_core.c
index 018c92941aba..e97082017f4f 100644
--- a/net/irda/ircomm/ircomm_core.c
+++ b/net/irda/ircomm/ircomm_core.c
@@ -33,6 +33,7 @@
33#include <linux/proc_fs.h> 33#include <linux/proc_fs.h>
34#include <linux/seq_file.h> 34#include <linux/seq_file.h>
35#include <linux/init.h> 35#include <linux/init.h>
36#include <linux/slab.h>
36 37
37#include <net/irda/irda.h> 38#include <net/irda/irda.h>
38#include <net/irda/irmod.h> 39#include <net/irda/irmod.h>
diff --git a/net/irda/ircomm/ircomm_lmp.c b/net/irda/ircomm/ircomm_lmp.c
index 7ba96618660e..08fb54dc8c41 100644
--- a/net/irda/ircomm/ircomm_lmp.c
+++ b/net/irda/ircomm/ircomm_lmp.c
@@ -31,6 +31,7 @@
31 ********************************************************************/ 31 ********************************************************************/
32 32
33#include <linux/init.h> 33#include <linux/init.h>
34#include <linux/gfp.h>
34 35
35#include <net/irda/irda.h> 36#include <net/irda/irda.h>
36#include <net/irda/irlmp.h> 37#include <net/irda/irlmp.h>
diff --git a/net/irda/ircomm/ircomm_param.c b/net/irda/ircomm/ircomm_param.c
index d57aefd9fe77..e2e893b474e9 100644
--- a/net/irda/ircomm/ircomm_param.c
+++ b/net/irda/ircomm/ircomm_param.c
@@ -28,6 +28,7 @@
28 * 28 *
29 ********************************************************************/ 29 ********************************************************************/
30 30
31#include <linux/gfp.h>
31#include <linux/workqueue.h> 32#include <linux/workqueue.h>
32#include <linux/interrupt.h> 33#include <linux/interrupt.h>
33 34
diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
index 811984d9324b..faa82ca2dfdc 100644
--- a/net/irda/ircomm/ircomm_tty.c
+++ b/net/irda/ircomm/ircomm_tty.c
@@ -33,6 +33,7 @@
33#include <linux/init.h> 33#include <linux/init.h>
34#include <linux/module.h> 34#include <linux/module.h>
35#include <linux/fs.h> 35#include <linux/fs.h>
36#include <linux/slab.h>
36#include <linux/sched.h> 37#include <linux/sched.h>
37#include <linux/seq_file.h> 38#include <linux/seq_file.h>
38#include <linux/termios.h> 39#include <linux/termios.h>
@@ -496,9 +497,6 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
496 497
497 IRDA_DEBUG(0, "%s()\n", __func__ ); 498 IRDA_DEBUG(0, "%s()\n", __func__ );
498 499
499 if (!tty)
500 return;
501
502 IRDA_ASSERT(self != NULL, return;); 500 IRDA_ASSERT(self != NULL, return;);
503 IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return;); 501 IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return;);
504 502
@@ -1007,9 +1005,6 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
1007 IRDA_ASSERT(self != NULL, return;); 1005 IRDA_ASSERT(self != NULL, return;);
1008 IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return;); 1006 IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return;);
1009 1007
1010 if (!tty)
1011 return;
1012
1013 /* ircomm_tty_flush_buffer(tty); */ 1008 /* ircomm_tty_flush_buffer(tty); */
1014 ircomm_tty_shutdown(self); 1009 ircomm_tty_shutdown(self);
1015 1010
diff --git a/net/irda/irda_device.c b/net/irda/irda_device.c
index bf92e1473447..25cc2e695158 100644
--- a/net/irda/irda_device.c
+++ b/net/irda/irda_device.c
@@ -41,6 +41,7 @@
41#include <linux/tty.h> 41#include <linux/tty.h>
42#include <linux/kmod.h> 42#include <linux/kmod.h>
43#include <linux/spinlock.h> 43#include <linux/spinlock.h>
44#include <linux/slab.h>
44 45
45#include <asm/ioctls.h> 46#include <asm/ioctls.h>
46#include <asm/uaccess.h> 47#include <asm/uaccess.h>
diff --git a/net/irda/iriap.c b/net/irda/iriap.c
index 294e34d3517c..79a1e5a23e10 100644
--- a/net/irda/iriap.c
+++ b/net/irda/iriap.c
@@ -31,6 +31,7 @@
31#include <linux/string.h> 31#include <linux/string.h>
32#include <linux/init.h> 32#include <linux/init.h>
33#include <linux/seq_file.h> 33#include <linux/seq_file.h>
34#include <linux/slab.h>
34 35
35#include <asm/byteorder.h> 36#include <asm/byteorder.h>
36#include <asm/unaligned.h> 37#include <asm/unaligned.h>
diff --git a/net/irda/iriap_event.c b/net/irda/iriap_event.c
index a301cbd93785..703774e29e32 100644
--- a/net/irda/iriap_event.c
+++ b/net/irda/iriap_event.c
@@ -24,6 +24,8 @@
24 * 24 *
25 ********************************************************************/ 25 ********************************************************************/
26 26
27#include <linux/slab.h>
28
27#include <net/irda/irda.h> 29#include <net/irda/irda.h>
28#include <net/irda/irlmp.h> 30#include <net/irda/irlmp.h>
29#include <net/irda/iriap.h> 31#include <net/irda/iriap.h>
diff --git a/net/irda/irias_object.c b/net/irda/irias_object.c
index 99ebb96f1386..f07ed9fd5792 100644
--- a/net/irda/irias_object.c
+++ b/net/irda/irias_object.c
@@ -22,6 +22,7 @@
22 * 22 *
23 ********************************************************************/ 23 ********************************************************************/
24 24
25#include <linux/slab.h>
25#include <linux/string.h> 26#include <linux/string.h>
26#include <linux/socket.h> 27#include <linux/socket.h>
27#include <linux/module.h> 28#include <linux/module.h>
diff --git a/net/irda/irlan/irlan_client.c b/net/irda/irlan/irlan_client.c
index 42f7d960d055..7ed3af957935 100644
--- a/net/irda/irlan/irlan_client.c
+++ b/net/irda/irlan/irlan_client.c
@@ -28,6 +28,7 @@
28 28
29#include <linux/kernel.h> 29#include <linux/kernel.h>
30#include <linux/string.h> 30#include <linux/string.h>
31#include <linux/slab.h>
31#include <linux/errno.h> 32#include <linux/errno.h>
32#include <linux/init.h> 33#include <linux/init.h>
33#include <linux/netdevice.h> 34#include <linux/netdevice.h>
diff --git a/net/irda/irlan/irlan_common.c b/net/irda/irlan/irlan_common.c
index 315ead3cb926..a788f9e9427d 100644
--- a/net/irda/irlan/irlan_common.c
+++ b/net/irda/irlan/irlan_common.c
@@ -27,6 +27,7 @@
27 27
28#include <linux/kernel.h> 28#include <linux/kernel.h>
29#include <linux/string.h> 29#include <linux/string.h>
30#include <linux/gfp.h>
30#include <linux/init.h> 31#include <linux/init.h>
31#include <linux/errno.h> 32#include <linux/errno.h>
32#include <linux/proc_fs.h> 33#include <linux/proc_fs.h>
@@ -1128,34 +1129,14 @@ int irlan_extract_param(__u8 *buf, char *name, char *value, __u16 *len)
1128 */ 1129 */
1129static void *irlan_seq_start(struct seq_file *seq, loff_t *pos) 1130static void *irlan_seq_start(struct seq_file *seq, loff_t *pos)
1130{ 1131{
1131 int i = 1;
1132 struct irlan_cb *self;
1133
1134 rcu_read_lock(); 1132 rcu_read_lock();
1135 if (*pos == 0) 1133 return seq_list_start_head(&irlans, *pos);
1136 return SEQ_START_TOKEN;
1137
1138 list_for_each_entry(self, &irlans, dev_list) {
1139 if (*pos == i)
1140 return self;
1141 ++i;
1142 }
1143 return NULL;
1144} 1134}
1145 1135
1146/* Return entry after v, and increment pos */ 1136/* Return entry after v, and increment pos */
1147static void *irlan_seq_next(struct seq_file *seq, void *v, loff_t *pos) 1137static void *irlan_seq_next(struct seq_file *seq, void *v, loff_t *pos)
1148{ 1138{
1149 struct list_head *nxt; 1139 return seq_list_next(v, &irlans, pos);
1150
1151 ++*pos;
1152 if (v == SEQ_START_TOKEN)
1153 nxt = irlans.next;
1154 else
1155 nxt = ((struct irlan_cb *)v)->dev_list.next;
1156
1157 return (nxt == &irlans) ? NULL
1158 : list_entry(nxt, struct irlan_cb, dev_list);
1159} 1140}
1160 1141
1161/* End of reading /proc file */ 1142/* End of reading /proc file */
@@ -1170,10 +1151,10 @@ static void irlan_seq_stop(struct seq_file *seq, void *v)
1170 */ 1151 */
1171static int irlan_seq_show(struct seq_file *seq, void *v) 1152static int irlan_seq_show(struct seq_file *seq, void *v)
1172{ 1153{
1173 if (v == SEQ_START_TOKEN) 1154 if (v == &irlans)
1174 seq_puts(seq, "IrLAN instances:\n"); 1155 seq_puts(seq, "IrLAN instances:\n");
1175 else { 1156 else {
1176 struct irlan_cb *self = v; 1157 struct irlan_cb *self = list_entry(v, struct irlan_cb, dev_list);
1177 1158
1178 IRDA_ASSERT(self != NULL, return -1;); 1159 IRDA_ASSERT(self != NULL, return -1;);
1179 IRDA_ASSERT(self->magic == IRLAN_MAGIC, return -1;); 1160 IRDA_ASSERT(self->magic == IRLAN_MAGIC, return -1;);
diff --git a/net/irda/irlan/irlan_eth.c b/net/irda/irlan/irlan_eth.c
index d340110f5c0c..9616c32d1076 100644
--- a/net/irda/irlan/irlan_eth.c
+++ b/net/irda/irlan/irlan_eth.c
@@ -321,14 +321,15 @@ static void irlan_eth_set_multicast_list(struct net_device *dev)
321 /* Enable promiscuous mode */ 321 /* Enable promiscuous mode */
322 IRDA_WARNING("Promiscuous mode not implemented by IrLAN!\n"); 322 IRDA_WARNING("Promiscuous mode not implemented by IrLAN!\n");
323 } 323 }
324 else if ((dev->flags & IFF_ALLMULTI) || dev->mc_count > HW_MAX_ADDRS) { 324 else if ((dev->flags & IFF_ALLMULTI) ||
325 netdev_mc_count(dev) > HW_MAX_ADDRS) {
325 /* Disable promiscuous mode, use normal mode. */ 326 /* Disable promiscuous mode, use normal mode. */
326 IRDA_DEBUG(4, "%s(), Setting multicast filter\n", __func__ ); 327 IRDA_DEBUG(4, "%s(), Setting multicast filter\n", __func__ );
327 /* hardware_set_filter(NULL); */ 328 /* hardware_set_filter(NULL); */
328 329
329 irlan_set_multicast_filter(self, TRUE); 330 irlan_set_multicast_filter(self, TRUE);
330 } 331 }
331 else if (dev->mc_count) { 332 else if (!netdev_mc_empty(dev)) {
332 IRDA_DEBUG(4, "%s(), Setting multicast filter\n", __func__ ); 333 IRDA_DEBUG(4, "%s(), Setting multicast filter\n", __func__ );
333 /* Walk the address list, and load the filter */ 334 /* Walk the address list, and load the filter */
334 /* hardware_set_filter(dev->mc_list); */ 335 /* hardware_set_filter(dev->mc_list); */
diff --git a/net/irda/irlan/irlan_provider.c b/net/irda/irlan/irlan_provider.c
index 3f81f81b2dfa..5cf5e6c872bb 100644
--- a/net/irda/irlan/irlan_provider.c
+++ b/net/irda/irlan/irlan_provider.c
@@ -34,6 +34,7 @@
34#include <linux/init.h> 34#include <linux/init.h>
35#include <linux/random.h> 35#include <linux/random.h>
36#include <linux/bitops.h> 36#include <linux/bitops.h>
37#include <linux/slab.h>
37 38
38#include <asm/system.h> 39#include <asm/system.h>
39#include <asm/byteorder.h> 40#include <asm/byteorder.h>
diff --git a/net/irda/irlap.c b/net/irda/irlap.c
index 356e65b1dc42..783c5f367d29 100644
--- a/net/irda/irlap.c
+++ b/net/irda/irlap.c
@@ -450,10 +450,10 @@ void irlap_disconnect_request(struct irlap_cb *self)
450 450
451 /* Check if we are in the right state for disconnecting */ 451 /* Check if we are in the right state for disconnecting */
452 switch (self->state) { 452 switch (self->state) {
453 case LAP_XMIT_P: /* FALLTROUGH */ 453 case LAP_XMIT_P: /* FALLTHROUGH */
454 case LAP_XMIT_S: /* FALLTROUGH */ 454 case LAP_XMIT_S: /* FALLTHROUGH */
455 case LAP_CONN: /* FALLTROUGH */ 455 case LAP_CONN: /* FALLTHROUGH */
456 case LAP_RESET_WAIT: /* FALLTROUGH */ 456 case LAP_RESET_WAIT: /* FALLTHROUGH */
457 case LAP_RESET_CHECK: 457 case LAP_RESET_CHECK:
458 irlap_do_event(self, DISCONNECT_REQUEST, NULL, NULL); 458 irlap_do_event(self, DISCONNECT_REQUEST, NULL, NULL);
459 break; 459 break;
@@ -485,9 +485,9 @@ void irlap_disconnect_indication(struct irlap_cb *self, LAP_REASON reason)
485 IRDA_DEBUG(1, "%s(), Sending reset request!\n", __func__); 485 IRDA_DEBUG(1, "%s(), Sending reset request!\n", __func__);
486 irlap_do_event(self, RESET_REQUEST, NULL, NULL); 486 irlap_do_event(self, RESET_REQUEST, NULL, NULL);
487 break; 487 break;
488 case LAP_NO_RESPONSE: /* FALLTROUGH */ 488 case LAP_NO_RESPONSE: /* FALLTHROUGH */
489 case LAP_DISC_INDICATION: /* FALLTROUGH */ 489 case LAP_DISC_INDICATION: /* FALLTHROUGH */
490 case LAP_FOUND_NONE: /* FALLTROUGH */ 490 case LAP_FOUND_NONE: /* FALLTHROUGH */
491 case LAP_MEDIA_BUSY: 491 case LAP_MEDIA_BUSY:
492 irlmp_link_disconnect_indication(self->notify.instance, self, 492 irlmp_link_disconnect_indication(self->notify.instance, self,
493 reason, NULL); 493 reason, NULL);
diff --git a/net/irda/irlap_event.c b/net/irda/irlap_event.c
index c5c51959e3ce..d434c8880745 100644
--- a/net/irda/irlap_event.c
+++ b/net/irda/irlap_event.c
@@ -29,6 +29,7 @@
29#include <linux/kernel.h> 29#include <linux/kernel.h>
30#include <linux/delay.h> 30#include <linux/delay.h>
31#include <linux/skbuff.h> 31#include <linux/skbuff.h>
32#include <linux/slab.h>
32 33
33#include <net/irda/irda.h> 34#include <net/irda/irda.h>
34#include <net/irda/irlap_event.h> 35#include <net/irda/irlap_event.h>
@@ -1741,7 +1742,7 @@ static int irlap_state_reset(struct irlap_cb *self, IRLAP_EVENT event,
1741 * Function irlap_state_xmit_s (event, skb, info) 1742 * Function irlap_state_xmit_s (event, skb, info)
1742 * 1743 *
1743 * XMIT_S, The secondary station has been given the right to transmit, 1744 * XMIT_S, The secondary station has been given the right to transmit,
1744 * and we therefor do not expect to receive any transmissions from other 1745 * and we therefore do not expect to receive any transmissions from other
1745 * stations. 1746 * stations.
1746 */ 1747 */
1747static int irlap_state_xmit_s(struct irlap_cb *self, IRLAP_EVENT event, 1748static int irlap_state_xmit_s(struct irlap_cb *self, IRLAP_EVENT event,
diff --git a/net/irda/irlap_frame.c b/net/irda/irlap_frame.c
index 7af2e74deda8..688222cbf55b 100644
--- a/net/irda/irlap_frame.c
+++ b/net/irda/irlap_frame.c
@@ -29,6 +29,7 @@
29#include <linux/if_ether.h> 29#include <linux/if_ether.h>
30#include <linux/netdevice.h> 30#include <linux/netdevice.h>
31#include <linux/irda.h> 31#include <linux/irda.h>
32#include <linux/slab.h>
32 33
33#include <net/pkt_sched.h> 34#include <net/pkt_sched.h>
34#include <net/sock.h> 35#include <net/sock.h>
diff --git a/net/irda/irlmp.c b/net/irda/irlmp.c
index 7bf5b913828b..0e7d8bde145d 100644
--- a/net/irda/irlmp.c
+++ b/net/irda/irlmp.c
@@ -105,7 +105,7 @@ int __init irlmp_init(void)
105 105
106 init_timer(&irlmp->discovery_timer); 106 init_timer(&irlmp->discovery_timer);
107 107
108 /* Do discovery every 3 seconds, conditionaly */ 108 /* Do discovery every 3 seconds, conditionally */
109 if (sysctl_discovery) 109 if (sysctl_discovery)
110 irlmp_start_discovery_timer(irlmp, 110 irlmp_start_discovery_timer(irlmp,
111 sysctl_discovery_timeout*HZ); 111 sysctl_discovery_timeout*HZ);
@@ -1842,7 +1842,7 @@ LM_REASON irlmp_convert_lap_reason( LAP_REASON lap_reason)
1842 reason = LM_CONNECT_FAILURE; 1842 reason = LM_CONNECT_FAILURE;
1843 break; 1843 break;
1844 default: 1844 default:
1845 IRDA_DEBUG(1, "%s(), Unknow IrLAP disconnect reason %d!\n", 1845 IRDA_DEBUG(1, "%s(), Unknown IrLAP disconnect reason %d!\n",
1846 __func__, lap_reason); 1846 __func__, lap_reason);
1847 reason = LM_LAP_DISCONNECT; 1847 reason = LM_LAP_DISCONNECT;
1848 break; 1848 break;
diff --git a/net/irda/irnet/irnet.h b/net/irda/irnet/irnet.h
index b001c361ad30..4300df35d37d 100644
--- a/net/irda/irnet/irnet.h
+++ b/net/irda/irnet/irnet.h
@@ -249,6 +249,7 @@
249#include <linux/poll.h> 249#include <linux/poll.h>
250#include <linux/capability.h> 250#include <linux/capability.h>
251#include <linux/ctype.h> /* isspace() */ 251#include <linux/ctype.h> /* isspace() */
252#include <linux/string.h> /* skip_spaces() */
252#include <asm/uaccess.h> 253#include <asm/uaccess.h>
253#include <linux/init.h> 254#include <linux/init.h>
254 255
diff --git a/net/irda/irnet/irnet_irda.c b/net/irda/irnet/irnet_irda.c
index cccc2e93234f..df18ab4b6c5e 100644
--- a/net/irda/irnet/irnet_irda.c
+++ b/net/irda/irnet/irnet_irda.c
@@ -11,6 +11,7 @@
11#include "irnet_irda.h" /* Private header */ 11#include "irnet_irda.h" /* Private header */
12#include <linux/sched.h> 12#include <linux/sched.h>
13#include <linux/seq_file.h> 13#include <linux/seq_file.h>
14#include <linux/slab.h>
14#include <asm/unaligned.h> 15#include <asm/unaligned.h>
15 16
16/* 17/*
@@ -1403,8 +1404,8 @@ irnet_connect_indication(void * instance,
1403 /* Socket already connecting ? On primary ? */ 1404 /* Socket already connecting ? On primary ? */
1404 if(0 1405 if(0
1405#ifdef ALLOW_SIMULT_CONNECT 1406#ifdef ALLOW_SIMULT_CONNECT
1406 || ((irttp_is_primary(server->tsap) == 1) /* primary */ 1407 || ((irttp_is_primary(server->tsap) == 1) && /* primary */
1407 && (test_and_clear_bit(0, &new->ttp_connect))) 1408 (test_and_clear_bit(0, &new->ttp_connect)))
1408#endif /* ALLOW_SIMULT_CONNECT */ 1409#endif /* ALLOW_SIMULT_CONNECT */
1409 ) 1410 )
1410 { 1411 {
diff --git a/net/irda/irnet/irnet_ppp.c b/net/irda/irnet/irnet_ppp.c
index 7dea882dbb75..6a1a202710c5 100644
--- a/net/irda/irnet/irnet_ppp.c
+++ b/net/irda/irnet/irnet_ppp.c
@@ -14,6 +14,7 @@
14 */ 14 */
15 15
16#include <linux/sched.h> 16#include <linux/sched.h>
17#include <linux/slab.h>
17#include <linux/smp_lock.h> 18#include <linux/smp_lock.h>
18#include "irnet_ppp.h" /* Private header */ 19#include "irnet_ppp.h" /* Private header */
19/* Please put other headers in irnet.h - Thanks */ 20/* Please put other headers in irnet.h - Thanks */
@@ -76,9 +77,8 @@ irnet_ctrl_write(irnet_socket * ap,
76 /* Look at the next command */ 77 /* Look at the next command */
77 start = next; 78 start = next;
78 79
79 /* Scrap whitespaces before the command */ 80 /* Scrap whitespaces before the command */
80 while(isspace(*start)) 81 start = skip_spaces(start);
81 start++;
82 82
83 /* ',' is our command separator */ 83 /* ',' is our command separator */
84 next = strchr(start, ','); 84 next = strchr(start, ',');
@@ -133,8 +133,7 @@ irnet_ctrl_write(irnet_socket * ap,
133 char * endp; 133 char * endp;
134 134
135 /* Scrap whitespaces before the command */ 135 /* Scrap whitespaces before the command */
136 while(isspace(*begp)) 136 begp = skip_spaces(begp);
137 begp++;
138 137
139 /* Convert argument to a number (last arg is the base) */ 138 /* Convert argument to a number (last arg is the base) */
140 addr = simple_strtoul(begp, &endp, 16); 139 addr = simple_strtoul(begp, &endp, 16);
@@ -700,15 +699,18 @@ dev_irnet_ioctl(
700 699
701 /* Query PPP channel and unit number */ 700 /* Query PPP channel and unit number */
702 case PPPIOCGCHAN: 701 case PPPIOCGCHAN:
702 lock_kernel();
703 if(ap->ppp_open && !put_user(ppp_channel_index(&ap->chan), 703 if(ap->ppp_open && !put_user(ppp_channel_index(&ap->chan),
704 (int __user *)argp)) 704 (int __user *)argp))
705 err = 0; 705 err = 0;
706 unlock_kernel();
706 break; 707 break;
707 case PPPIOCGUNIT: 708 case PPPIOCGUNIT:
708 lock_kernel(); 709 lock_kernel();
709 if(ap->ppp_open && !put_user(ppp_unit_number(&ap->chan), 710 if(ap->ppp_open && !put_user(ppp_unit_number(&ap->chan),
710 (int __user *)argp)) 711 (int __user *)argp))
711 err = 0; 712 err = 0;
713 unlock_kernel();
712 break; 714 break;
713 715
714 /* All these ioctls can be passed both directly and from ppp_generic, 716 /* All these ioctls can be passed both directly and from ppp_generic,
diff --git a/net/irda/irnetlink.c b/net/irda/irnetlink.c
index 476b307bd801..6c7c4b92e4f8 100644
--- a/net/irda/irnetlink.c
+++ b/net/irda/irnetlink.c
@@ -15,6 +15,7 @@
15 15
16#include <linux/socket.h> 16#include <linux/socket.h>
17#include <linux/irda.h> 17#include <linux/irda.h>
18#include <linux/gfp.h>
18#include <net/net_namespace.h> 19#include <net/net_namespace.h>
19#include <net/sock.h> 20#include <net/sock.h>
20#include <net/irda/irda.h> 21#include <net/irda/irda.h>
@@ -124,7 +125,7 @@ static int irda_nl_get_mode(struct sk_buff *skb, struct genl_info *info)
124 return ret; 125 return ret;
125} 126}
126 127
127static struct nla_policy irda_nl_policy[IRDA_NL_ATTR_MAX + 1] = { 128static const struct nla_policy irda_nl_policy[IRDA_NL_ATTR_MAX + 1] = {
128 [IRDA_NL_ATTR_IFNAME] = { .type = NLA_NUL_STRING, 129 [IRDA_NL_ATTR_IFNAME] = { .type = NLA_NUL_STRING,
129 .len = IFNAMSIZ-1 }, 130 .len = IFNAMSIZ-1 },
130 [IRDA_NL_ATTR_MODE] = { .type = NLA_U32 }, 131 [IRDA_NL_ATTR_MODE] = { .type = NLA_U32 },
diff --git a/net/irda/irqueue.c b/net/irda/irqueue.c
index ba01938becb5..849aaf0dabb5 100644
--- a/net/irda/irqueue.c
+++ b/net/irda/irqueue.c
@@ -192,6 +192,7 @@
192 * Jean II 192 * Jean II
193 */ 193 */
194#include <linux/module.h> 194#include <linux/module.h>
195#include <linux/slab.h>
195 196
196#include <net/irda/irda.h> 197#include <net/irda/irda.h>
197#include <net/irda/irqueue.h> 198#include <net/irda/irqueue.h>
diff --git a/net/irda/irsysctl.c b/net/irda/irsysctl.c
index 5c86567e5a78..d0b70dadf73b 100644
--- a/net/irda/irsysctl.c
+++ b/net/irda/irsysctl.c
@@ -113,26 +113,21 @@ static int do_discovery(ctl_table *table, int write,
113/* One file */ 113/* One file */
114static ctl_table irda_table[] = { 114static ctl_table irda_table[] = {
115 { 115 {
116 .ctl_name = NET_IRDA_DISCOVERY,
117 .procname = "discovery", 116 .procname = "discovery",
118 .data = &sysctl_discovery, 117 .data = &sysctl_discovery,
119 .maxlen = sizeof(int), 118 .maxlen = sizeof(int),
120 .mode = 0644, 119 .mode = 0644,
121 .proc_handler = do_discovery, 120 .proc_handler = do_discovery,
122 .strategy = sysctl_intvec
123 }, 121 },
124 { 122 {
125 .ctl_name = NET_IRDA_DEVNAME,
126 .procname = "devname", 123 .procname = "devname",
127 .data = sysctl_devname, 124 .data = sysctl_devname,
128 .maxlen = 65, 125 .maxlen = 65,
129 .mode = 0644, 126 .mode = 0644,
130 .proc_handler = do_devname, 127 .proc_handler = do_devname,
131 .strategy = sysctl_string
132 }, 128 },
133#ifdef CONFIG_IRDA_DEBUG 129#ifdef CONFIG_IRDA_DEBUG
134 { 130 {
135 .ctl_name = NET_IRDA_DEBUG,
136 .procname = "debug", 131 .procname = "debug",
137 .data = &irda_debug, 132 .data = &irda_debug,
138 .maxlen = sizeof(int), 133 .maxlen = sizeof(int),
@@ -142,7 +137,6 @@ static ctl_table irda_table[] = {
142#endif 137#endif
143#ifdef CONFIG_IRDA_FAST_RR 138#ifdef CONFIG_IRDA_FAST_RR
144 { 139 {
145 .ctl_name = NET_IRDA_FAST_POLL,
146 .procname = "fast_poll_increase", 140 .procname = "fast_poll_increase",
147 .data = &sysctl_fast_poll_increase, 141 .data = &sysctl_fast_poll_increase,
148 .maxlen = sizeof(int), 142 .maxlen = sizeof(int),
@@ -151,18 +145,15 @@ static ctl_table irda_table[] = {
151 }, 145 },
152#endif 146#endif
153 { 147 {
154 .ctl_name = NET_IRDA_DISCOVERY_SLOTS,
155 .procname = "discovery_slots", 148 .procname = "discovery_slots",
156 .data = &sysctl_discovery_slots, 149 .data = &sysctl_discovery_slots,
157 .maxlen = sizeof(int), 150 .maxlen = sizeof(int),
158 .mode = 0644, 151 .mode = 0644,
159 .proc_handler = proc_dointvec_minmax, 152 .proc_handler = proc_dointvec_minmax,
160 .strategy = sysctl_intvec,
161 .extra1 = &min_discovery_slots, 153 .extra1 = &min_discovery_slots,
162 .extra2 = &max_discovery_slots 154 .extra2 = &max_discovery_slots
163 }, 155 },
164 { 156 {
165 .ctl_name = NET_IRDA_DISCOVERY_TIMEOUT,
166 .procname = "discovery_timeout", 157 .procname = "discovery_timeout",
167 .data = &sysctl_discovery_timeout, 158 .data = &sysctl_discovery_timeout,
168 .maxlen = sizeof(int), 159 .maxlen = sizeof(int),
@@ -170,99 +161,83 @@ static ctl_table irda_table[] = {
170 .proc_handler = proc_dointvec 161 .proc_handler = proc_dointvec
171 }, 162 },
172 { 163 {
173 .ctl_name = NET_IRDA_SLOT_TIMEOUT,
174 .procname = "slot_timeout", 164 .procname = "slot_timeout",
175 .data = &sysctl_slot_timeout, 165 .data = &sysctl_slot_timeout,
176 .maxlen = sizeof(int), 166 .maxlen = sizeof(int),
177 .mode = 0644, 167 .mode = 0644,
178 .proc_handler = proc_dointvec_minmax, 168 .proc_handler = proc_dointvec_minmax,
179 .strategy = sysctl_intvec,
180 .extra1 = &min_slot_timeout, 169 .extra1 = &min_slot_timeout,
181 .extra2 = &max_slot_timeout 170 .extra2 = &max_slot_timeout
182 }, 171 },
183 { 172 {
184 .ctl_name = NET_IRDA_MAX_BAUD_RATE,
185 .procname = "max_baud_rate", 173 .procname = "max_baud_rate",
186 .data = &sysctl_max_baud_rate, 174 .data = &sysctl_max_baud_rate,
187 .maxlen = sizeof(int), 175 .maxlen = sizeof(int),
188 .mode = 0644, 176 .mode = 0644,
189 .proc_handler = proc_dointvec_minmax, 177 .proc_handler = proc_dointvec_minmax,
190 .strategy = sysctl_intvec,
191 .extra1 = &min_max_baud_rate, 178 .extra1 = &min_max_baud_rate,
192 .extra2 = &max_max_baud_rate 179 .extra2 = &max_max_baud_rate
193 }, 180 },
194 { 181 {
195 .ctl_name = NET_IRDA_MIN_TX_TURN_TIME,
196 .procname = "min_tx_turn_time", 182 .procname = "min_tx_turn_time",
197 .data = &sysctl_min_tx_turn_time, 183 .data = &sysctl_min_tx_turn_time,
198 .maxlen = sizeof(int), 184 .maxlen = sizeof(int),
199 .mode = 0644, 185 .mode = 0644,
200 .proc_handler = proc_dointvec_minmax, 186 .proc_handler = proc_dointvec_minmax,
201 .strategy = sysctl_intvec,
202 .extra1 = &min_min_tx_turn_time, 187 .extra1 = &min_min_tx_turn_time,
203 .extra2 = &max_min_tx_turn_time 188 .extra2 = &max_min_tx_turn_time
204 }, 189 },
205 { 190 {
206 .ctl_name = NET_IRDA_MAX_TX_DATA_SIZE,
207 .procname = "max_tx_data_size", 191 .procname = "max_tx_data_size",
208 .data = &sysctl_max_tx_data_size, 192 .data = &sysctl_max_tx_data_size,
209 .maxlen = sizeof(int), 193 .maxlen = sizeof(int),
210 .mode = 0644, 194 .mode = 0644,
211 .proc_handler = proc_dointvec_minmax, 195 .proc_handler = proc_dointvec_minmax,
212 .strategy = sysctl_intvec,
213 .extra1 = &min_max_tx_data_size, 196 .extra1 = &min_max_tx_data_size,
214 .extra2 = &max_max_tx_data_size 197 .extra2 = &max_max_tx_data_size
215 }, 198 },
216 { 199 {
217 .ctl_name = NET_IRDA_MAX_TX_WINDOW,
218 .procname = "max_tx_window", 200 .procname = "max_tx_window",
219 .data = &sysctl_max_tx_window, 201 .data = &sysctl_max_tx_window,
220 .maxlen = sizeof(int), 202 .maxlen = sizeof(int),
221 .mode = 0644, 203 .mode = 0644,
222 .proc_handler = proc_dointvec_minmax, 204 .proc_handler = proc_dointvec_minmax,
223 .strategy = sysctl_intvec,
224 .extra1 = &min_max_tx_window, 205 .extra1 = &min_max_tx_window,
225 .extra2 = &max_max_tx_window 206 .extra2 = &max_max_tx_window
226 }, 207 },
227 { 208 {
228 .ctl_name = NET_IRDA_MAX_NOREPLY_TIME,
229 .procname = "max_noreply_time", 209 .procname = "max_noreply_time",
230 .data = &sysctl_max_noreply_time, 210 .data = &sysctl_max_noreply_time,
231 .maxlen = sizeof(int), 211 .maxlen = sizeof(int),
232 .mode = 0644, 212 .mode = 0644,
233 .proc_handler = proc_dointvec_minmax, 213 .proc_handler = proc_dointvec_minmax,
234 .strategy = sysctl_intvec,
235 .extra1 = &min_max_noreply_time, 214 .extra1 = &min_max_noreply_time,
236 .extra2 = &max_max_noreply_time 215 .extra2 = &max_max_noreply_time
237 }, 216 },
238 { 217 {
239 .ctl_name = NET_IRDA_WARN_NOREPLY_TIME,
240 .procname = "warn_noreply_time", 218 .procname = "warn_noreply_time",
241 .data = &sysctl_warn_noreply_time, 219 .data = &sysctl_warn_noreply_time,
242 .maxlen = sizeof(int), 220 .maxlen = sizeof(int),
243 .mode = 0644, 221 .mode = 0644,
244 .proc_handler = proc_dointvec_minmax, 222 .proc_handler = proc_dointvec_minmax,
245 .strategy = sysctl_intvec,
246 .extra1 = &min_warn_noreply_time, 223 .extra1 = &min_warn_noreply_time,
247 .extra2 = &max_warn_noreply_time 224 .extra2 = &max_warn_noreply_time
248 }, 225 },
249 { 226 {
250 .ctl_name = NET_IRDA_LAP_KEEPALIVE_TIME,
251 .procname = "lap_keepalive_time", 227 .procname = "lap_keepalive_time",
252 .data = &sysctl_lap_keepalive_time, 228 .data = &sysctl_lap_keepalive_time,
253 .maxlen = sizeof(int), 229 .maxlen = sizeof(int),
254 .mode = 0644, 230 .mode = 0644,
255 .proc_handler = proc_dointvec_minmax, 231 .proc_handler = proc_dointvec_minmax,
256 .strategy = sysctl_intvec,
257 .extra1 = &min_lap_keepalive_time, 232 .extra1 = &min_lap_keepalive_time,
258 .extra2 = &max_lap_keepalive_time 233 .extra2 = &max_lap_keepalive_time
259 }, 234 },
260 { .ctl_name = 0 } 235 { }
261}; 236};
262 237
263static struct ctl_path irda_path[] = { 238static struct ctl_path irda_path[] = {
264 { .procname = "net", .ctl_name = CTL_NET, }, 239 { .procname = "net", },
265 { .procname = "irda", .ctl_name = NET_IRDA, }, 240 { .procname = "irda", },
266 { } 241 { }
267}; 242};
268 243
diff --git a/net/irda/irttp.c b/net/irda/irttp.c
index 9cb79f95bf63..47db1d8a0d92 100644
--- a/net/irda/irttp.c
+++ b/net/irda/irttp.c
@@ -28,6 +28,7 @@
28#include <linux/init.h> 28#include <linux/init.h>
29#include <linux/fs.h> 29#include <linux/fs.h>
30#include <linux/seq_file.h> 30#include <linux/seq_file.h>
31#include <linux/slab.h>
31 32
32#include <asm/byteorder.h> 33#include <asm/byteorder.h>
33#include <asm/unaligned.h> 34#include <asm/unaligned.h>
diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
index bada1b9c670b..c18286a2167b 100644
--- a/net/iucv/af_iucv.c
+++ b/net/iucv/af_iucv.c
@@ -221,7 +221,7 @@ static int afiucv_pm_restore_thaw(struct device *dev)
221 return 0; 221 return 0;
222} 222}
223 223
224static struct dev_pm_ops afiucv_pm_ops = { 224static const struct dev_pm_ops afiucv_pm_ops = {
225 .prepare = afiucv_pm_prepare, 225 .prepare = afiucv_pm_prepare,
226 .complete = afiucv_pm_complete, 226 .complete = afiucv_pm_complete,
227 .freeze = afiucv_pm_freeze, 227 .freeze = afiucv_pm_freeze,
@@ -428,7 +428,6 @@ static void iucv_sock_close(struct sock *sk)
428 break; 428 break;
429 429
430 default: 430 default:
431 sock_set_flag(sk, SOCK_ZAPPED);
432 /* nothing to do here */ 431 /* nothing to do here */
433 break; 432 break;
434 } 433 }
@@ -482,7 +481,8 @@ static struct sock *iucv_sock_alloc(struct socket *sock, int proto, gfp_t prio)
482} 481}
483 482
484/* Create an IUCV socket */ 483/* Create an IUCV socket */
485static int iucv_sock_create(struct net *net, struct socket *sock, int protocol) 484static int iucv_sock_create(struct net *net, struct socket *sock, int protocol,
485 int kern)
486{ 486{
487 struct sock *sk; 487 struct sock *sk;
488 488
@@ -536,7 +536,7 @@ void iucv_accept_enqueue(struct sock *parent, struct sock *sk)
536 list_add_tail(&iucv_sk(sk)->accept_q, &par->accept_q); 536 list_add_tail(&iucv_sk(sk)->accept_q, &par->accept_q);
537 spin_unlock_irqrestore(&par->accept_q_lock, flags); 537 spin_unlock_irqrestore(&par->accept_q_lock, flags);
538 iucv_sk(sk)->parent = parent; 538 iucv_sk(sk)->parent = parent;
539 parent->sk_ack_backlog++; 539 sk_acceptq_added(parent);
540} 540}
541 541
542void iucv_accept_unlink(struct sock *sk) 542void iucv_accept_unlink(struct sock *sk)
@@ -547,7 +547,7 @@ void iucv_accept_unlink(struct sock *sk)
547 spin_lock_irqsave(&par->accept_q_lock, flags); 547 spin_lock_irqsave(&par->accept_q_lock, flags);
548 list_del_init(&iucv_sk(sk)->accept_q); 548 list_del_init(&iucv_sk(sk)->accept_q);
549 spin_unlock_irqrestore(&par->accept_q_lock, flags); 549 spin_unlock_irqrestore(&par->accept_q_lock, flags);
550 iucv_sk(sk)->parent->sk_ack_backlog--; 550 sk_acceptq_removed(iucv_sk(sk)->parent);
551 iucv_sk(sk)->parent = NULL; 551 iucv_sk(sk)->parent = NULL;
552 sock_put(sk); 552 sock_put(sk);
553} 553}
@@ -1715,7 +1715,7 @@ static const struct proto_ops iucv_sock_ops = {
1715 .getsockopt = iucv_sock_getsockopt, 1715 .getsockopt = iucv_sock_getsockopt,
1716}; 1716};
1717 1717
1718static struct net_proto_family iucv_sock_family_ops = { 1718static const struct net_proto_family iucv_sock_family_ops = {
1719 .family = AF_IUCV, 1719 .family = AF_IUCV,
1720 .owner = THIS_MODULE, 1720 .owner = THIS_MODULE,
1721 .create = iucv_sock_create, 1721 .create = iucv_sock_create,
diff --git a/net/iucv/iucv.c b/net/iucv/iucv.c
index 3973d0e61e56..fd8b28361a64 100644
--- a/net/iucv/iucv.c
+++ b/net/iucv/iucv.c
@@ -93,7 +93,7 @@ static int iucv_pm_freeze(struct device *);
93static int iucv_pm_thaw(struct device *); 93static int iucv_pm_thaw(struct device *);
94static int iucv_pm_restore(struct device *); 94static int iucv_pm_restore(struct device *);
95 95
96static struct dev_pm_ops iucv_pm_ops = { 96static const struct dev_pm_ops iucv_pm_ops = {
97 .prepare = iucv_pm_prepare, 97 .prepare = iucv_pm_prepare,
98 .complete = iucv_pm_complete, 98 .complete = iucv_pm_complete,
99 .freeze = iucv_pm_freeze, 99 .freeze = iucv_pm_freeze,
@@ -1768,7 +1768,6 @@ static void iucv_tasklet_fn(unsigned long ignored)
1768 */ 1768 */
1769static void iucv_work_fn(struct work_struct *work) 1769static void iucv_work_fn(struct work_struct *work)
1770{ 1770{
1771 typedef void iucv_irq_fn(struct iucv_irq_data *);
1772 LIST_HEAD(work_queue); 1771 LIST_HEAD(work_queue);
1773 struct iucv_irq_list *p, *n; 1772 struct iucv_irq_list *p, *n;
1774 1773
@@ -1878,14 +1877,25 @@ int iucv_path_table_empty(void)
1878static int iucv_pm_freeze(struct device *dev) 1877static int iucv_pm_freeze(struct device *dev)
1879{ 1878{
1880 int cpu; 1879 int cpu;
1880 struct iucv_irq_list *p, *n;
1881 int rc = 0; 1881 int rc = 0;
1882 1882
1883#ifdef CONFIG_PM_DEBUG 1883#ifdef CONFIG_PM_DEBUG
1884 printk(KERN_WARNING "iucv_pm_freeze\n"); 1884 printk(KERN_WARNING "iucv_pm_freeze\n");
1885#endif 1885#endif
1886 if (iucv_pm_state != IUCV_PM_FREEZING) {
1887 for_each_cpu_mask_nr(cpu, iucv_irq_cpumask)
1888 smp_call_function_single(cpu, iucv_block_cpu_almost,
1889 NULL, 1);
1890 cancel_work_sync(&iucv_work);
1891 list_for_each_entry_safe(p, n, &iucv_work_queue, list) {
1892 list_del_init(&p->list);
1893 iucv_sever_pathid(p->data.ippathid,
1894 iucv_error_no_listener);
1895 kfree(p);
1896 }
1897 }
1886 iucv_pm_state = IUCV_PM_FREEZING; 1898 iucv_pm_state = IUCV_PM_FREEZING;
1887 for_each_cpu_mask_nr(cpu, iucv_irq_cpumask)
1888 smp_call_function_single(cpu, iucv_block_cpu_almost, NULL, 1);
1889 if (dev->driver && dev->driver->pm && dev->driver->pm->freeze) 1899 if (dev->driver && dev->driver->pm && dev->driver->pm->freeze)
1890 rc = dev->driver->pm->freeze(dev); 1900 rc = dev->driver->pm->freeze(dev);
1891 if (iucv_path_table_empty()) 1901 if (iucv_path_table_empty())
diff --git a/net/key/af_key.c b/net/key/af_key.c
index 4e98193dfa0f..ba9a3fcc2fed 100644
--- a/net/key/af_key.c
+++ b/net/key/af_key.c
@@ -26,6 +26,7 @@
26#include <linux/in6.h> 26#include <linux/in6.h>
27#include <linux/proc_fs.h> 27#include <linux/proc_fs.h>
28#include <linux/init.h> 28#include <linux/init.h>
29#include <linux/slab.h>
29#include <net/net_namespace.h> 30#include <net/net_namespace.h>
30#include <net/netns/generic.h> 31#include <net/netns/generic.h>
31#include <net/xfrm.h> 32#include <net/xfrm.h>
@@ -35,16 +36,16 @@
35#define _X2KEY(x) ((x) == XFRM_INF ? 0 : (x)) 36#define _X2KEY(x) ((x) == XFRM_INF ? 0 : (x))
36#define _KEY2X(x) ((x) == 0 ? XFRM_INF : (x)) 37#define _KEY2X(x) ((x) == 0 ? XFRM_INF : (x))
37 38
38static int pfkey_net_id; 39static int pfkey_net_id __read_mostly;
39struct netns_pfkey { 40struct netns_pfkey {
40 /* List of all pfkey sockets. */ 41 /* List of all pfkey sockets. */
41 struct hlist_head table; 42 struct hlist_head table;
42 atomic_t socks_nr; 43 atomic_t socks_nr;
43}; 44};
44static DECLARE_WAIT_QUEUE_HEAD(pfkey_table_wait); 45static DEFINE_MUTEX(pfkey_mutex);
45static DEFINE_RWLOCK(pfkey_table_lock);
46static atomic_t pfkey_table_users = ATOMIC_INIT(0);
47 46
47#define DUMMY_MARK 0
48static struct xfrm_mark dummy_mark = {0, 0};
48struct pfkey_sock { 49struct pfkey_sock {
49 /* struct sock must be the first member of struct pfkey_sock */ 50 /* struct sock must be the first member of struct pfkey_sock */
50 struct sock sk; 51 struct sock sk;
@@ -108,50 +109,6 @@ static void pfkey_sock_destruct(struct sock *sk)
108 atomic_dec(&net_pfkey->socks_nr); 109 atomic_dec(&net_pfkey->socks_nr);
109} 110}
110 111
111static void pfkey_table_grab(void)
112{
113 write_lock_bh(&pfkey_table_lock);
114
115 if (atomic_read(&pfkey_table_users)) {
116 DECLARE_WAITQUEUE(wait, current);
117
118 add_wait_queue_exclusive(&pfkey_table_wait, &wait);
119 for(;;) {
120 set_current_state(TASK_UNINTERRUPTIBLE);
121 if (atomic_read(&pfkey_table_users) == 0)
122 break;
123 write_unlock_bh(&pfkey_table_lock);
124 schedule();
125 write_lock_bh(&pfkey_table_lock);
126 }
127
128 __set_current_state(TASK_RUNNING);
129 remove_wait_queue(&pfkey_table_wait, &wait);
130 }
131}
132
133static __inline__ void pfkey_table_ungrab(void)
134{
135 write_unlock_bh(&pfkey_table_lock);
136 wake_up(&pfkey_table_wait);
137}
138
139static __inline__ void pfkey_lock_table(void)
140{
141 /* read_lock() synchronizes us to pfkey_table_grab */
142
143 read_lock(&pfkey_table_lock);
144 atomic_inc(&pfkey_table_users);
145 read_unlock(&pfkey_table_lock);
146}
147
148static __inline__ void pfkey_unlock_table(void)
149{
150 if (atomic_dec_and_test(&pfkey_table_users))
151 wake_up(&pfkey_table_wait);
152}
153
154
155static const struct proto_ops pfkey_ops; 112static const struct proto_ops pfkey_ops;
156 113
157static void pfkey_insert(struct sock *sk) 114static void pfkey_insert(struct sock *sk)
@@ -159,16 +116,16 @@ static void pfkey_insert(struct sock *sk)
159 struct net *net = sock_net(sk); 116 struct net *net = sock_net(sk);
160 struct netns_pfkey *net_pfkey = net_generic(net, pfkey_net_id); 117 struct netns_pfkey *net_pfkey = net_generic(net, pfkey_net_id);
161 118
162 pfkey_table_grab(); 119 mutex_lock(&pfkey_mutex);
163 sk_add_node(sk, &net_pfkey->table); 120 sk_add_node_rcu(sk, &net_pfkey->table);
164 pfkey_table_ungrab(); 121 mutex_unlock(&pfkey_mutex);
165} 122}
166 123
167static void pfkey_remove(struct sock *sk) 124static void pfkey_remove(struct sock *sk)
168{ 125{
169 pfkey_table_grab(); 126 mutex_lock(&pfkey_mutex);
170 sk_del_node_init(sk); 127 sk_del_node_init_rcu(sk);
171 pfkey_table_ungrab(); 128 mutex_unlock(&pfkey_mutex);
172} 129}
173 130
174static struct proto key_proto = { 131static struct proto key_proto = {
@@ -177,7 +134,8 @@ static struct proto key_proto = {
177 .obj_size = sizeof(struct pfkey_sock), 134 .obj_size = sizeof(struct pfkey_sock),
178}; 135};
179 136
180static int pfkey_create(struct net *net, struct socket *sock, int protocol) 137static int pfkey_create(struct net *net, struct socket *sock, int protocol,
138 int kern)
181{ 139{
182 struct netns_pfkey *net_pfkey = net_generic(net, pfkey_net_id); 140 struct netns_pfkey *net_pfkey = net_generic(net, pfkey_net_id);
183 struct sock *sk; 141 struct sock *sk;
@@ -222,6 +180,8 @@ static int pfkey_release(struct socket *sock)
222 sock_orphan(sk); 180 sock_orphan(sk);
223 sock->sk = NULL; 181 sock->sk = NULL;
224 skb_queue_purge(&sk->sk_write_queue); 182 skb_queue_purge(&sk->sk_write_queue);
183
184 synchronize_rcu();
225 sock_put(sk); 185 sock_put(sk);
226 186
227 return 0; 187 return 0;
@@ -276,8 +236,8 @@ static int pfkey_broadcast(struct sk_buff *skb, gfp_t allocation,
276 if (!skb) 236 if (!skb)
277 return -ENOMEM; 237 return -ENOMEM;
278 238
279 pfkey_lock_table(); 239 rcu_read_lock();
280 sk_for_each(sk, node, &net_pfkey->table) { 240 sk_for_each_rcu(sk, node, &net_pfkey->table) {
281 struct pfkey_sock *pfk = pfkey_sk(sk); 241 struct pfkey_sock *pfk = pfkey_sk(sk);
282 int err2; 242 int err2;
283 243
@@ -308,7 +268,7 @@ static int pfkey_broadcast(struct sk_buff *skb, gfp_t allocation,
308 if ((broadcast_flags & BROADCAST_REGISTERED) && err) 268 if ((broadcast_flags & BROADCAST_REGISTERED) && err)
309 err = err2; 269 err = err2;
310 } 270 }
311 pfkey_unlock_table(); 271 rcu_read_unlock();
312 272
313 if (one_sk != NULL) 273 if (one_sk != NULL)
314 err = pfkey_broadcast_one(skb, &skb2, allocation, one_sk); 274 err = pfkey_broadcast_one(skb, &skb2, allocation, one_sk);
@@ -690,7 +650,7 @@ static struct xfrm_state *pfkey_xfrm_state_lookup(struct net *net, struct sadb_
690 if (!xaddr) 650 if (!xaddr)
691 return NULL; 651 return NULL;
692 652
693 return xfrm_state_lookup(net, xaddr, sa->sadb_sa_spi, proto, family); 653 return xfrm_state_lookup(net, DUMMY_MARK, xaddr, sa->sadb_sa_spi, proto, family);
694} 654}
695 655
696#define PFKEY_ALIGN8(a) (1 + (((a) - 1) | (8 - 1))) 656#define PFKEY_ALIGN8(a) (1 + (((a) - 1) | (8 - 1)))
@@ -1192,6 +1152,7 @@ static struct xfrm_state * pfkey_msg2xfrm_state(struct net *net,
1192 x->aalg->alg_key_len = key->sadb_key_bits; 1152 x->aalg->alg_key_len = key->sadb_key_bits;
1193 memcpy(x->aalg->alg_key, key+1, keysize); 1153 memcpy(x->aalg->alg_key, key+1, keysize);
1194 } 1154 }
1155 x->aalg->alg_trunc_len = a->uinfo.auth.icv_truncbits;
1195 x->props.aalgo = sa->sadb_sa_auth; 1156 x->props.aalgo = sa->sadb_sa_auth;
1196 /* x->algo.flags = sa->sadb_sa_flags; */ 1157 /* x->algo.flags = sa->sadb_sa_flags; */
1197 } 1158 }
@@ -1358,7 +1319,7 @@ static int pfkey_getspi(struct sock *sk, struct sk_buff *skb, struct sadb_msg *h
1358 } 1319 }
1359 1320
1360 if (hdr->sadb_msg_seq) { 1321 if (hdr->sadb_msg_seq) {
1361 x = xfrm_find_acq_byseq(net, hdr->sadb_msg_seq); 1322 x = xfrm_find_acq_byseq(net, DUMMY_MARK, hdr->sadb_msg_seq);
1362 if (x && xfrm_addr_cmp(&x->id.daddr, xdaddr, family)) { 1323 if (x && xfrm_addr_cmp(&x->id.daddr, xdaddr, family)) {
1363 xfrm_state_put(x); 1324 xfrm_state_put(x);
1364 x = NULL; 1325 x = NULL;
@@ -1366,7 +1327,7 @@ static int pfkey_getspi(struct sock *sk, struct sk_buff *skb, struct sadb_msg *h
1366 } 1327 }
1367 1328
1368 if (!x) 1329 if (!x)
1369 x = xfrm_find_acq(net, mode, reqid, proto, xdaddr, xsaddr, 1, family); 1330 x = xfrm_find_acq(net, &dummy_mark, mode, reqid, proto, xdaddr, xsaddr, 1, family);
1370 1331
1371 if (x == NULL) 1332 if (x == NULL)
1372 return -ENOENT; 1333 return -ENOENT;
@@ -1415,7 +1376,7 @@ static int pfkey_acquire(struct sock *sk, struct sk_buff *skb, struct sadb_msg *
1415 if (hdr->sadb_msg_seq == 0 || hdr->sadb_msg_errno == 0) 1376 if (hdr->sadb_msg_seq == 0 || hdr->sadb_msg_errno == 0)
1416 return 0; 1377 return 0;
1417 1378
1418 x = xfrm_find_acq_byseq(net, hdr->sadb_msg_seq); 1379 x = xfrm_find_acq_byseq(net, DUMMY_MARK, hdr->sadb_msg_seq);
1419 if (x == NULL) 1380 if (x == NULL)
1420 return 0; 1381 return 0;
1421 1382
@@ -1710,6 +1671,23 @@ static int pfkey_register(struct sock *sk, struct sk_buff *skb, struct sadb_msg
1710 return 0; 1671 return 0;
1711} 1672}
1712 1673
1674static int unicast_flush_resp(struct sock *sk, struct sadb_msg *ihdr)
1675{
1676 struct sk_buff *skb;
1677 struct sadb_msg *hdr;
1678
1679 skb = alloc_skb(sizeof(struct sadb_msg) + 16, GFP_ATOMIC);
1680 if (!skb)
1681 return -ENOBUFS;
1682
1683 hdr = (struct sadb_msg *) skb_put(skb, sizeof(struct sadb_msg));
1684 memcpy(hdr, ihdr, sizeof(struct sadb_msg));
1685 hdr->sadb_msg_errno = (uint8_t) 0;
1686 hdr->sadb_msg_len = (sizeof(struct sadb_msg) / sizeof(uint64_t));
1687
1688 return pfkey_broadcast(skb, GFP_ATOMIC, BROADCAST_ONE, sk, sock_net(sk));
1689}
1690
1713static int key_notify_sa_flush(struct km_event *c) 1691static int key_notify_sa_flush(struct km_event *c)
1714{ 1692{
1715 struct sk_buff *skb; 1693 struct sk_buff *skb;
@@ -1738,7 +1716,7 @@ static int pfkey_flush(struct sock *sk, struct sk_buff *skb, struct sadb_msg *hd
1738 unsigned proto; 1716 unsigned proto;
1739 struct km_event c; 1717 struct km_event c;
1740 struct xfrm_audit audit_info; 1718 struct xfrm_audit audit_info;
1741 int err; 1719 int err, err2;
1742 1720
1743 proto = pfkey_satype2proto(hdr->sadb_msg_satype); 1721 proto = pfkey_satype2proto(hdr->sadb_msg_satype);
1744 if (proto == 0) 1722 if (proto == 0)
@@ -1748,8 +1726,13 @@ static int pfkey_flush(struct sock *sk, struct sk_buff *skb, struct sadb_msg *hd
1748 audit_info.sessionid = audit_get_sessionid(current); 1726 audit_info.sessionid = audit_get_sessionid(current);
1749 audit_info.secid = 0; 1727 audit_info.secid = 0;
1750 err = xfrm_state_flush(net, proto, &audit_info); 1728 err = xfrm_state_flush(net, proto, &audit_info);
1751 if (err) 1729 err2 = unicast_flush_resp(sk, hdr);
1752 return err; 1730 if (err || err2) {
1731 if (err == -ESRCH) /* empty table - go quietly */
1732 err = 0;
1733 return err ? err : err2;
1734 }
1735
1753 c.data.proto = proto; 1736 c.data.proto = proto;
1754 c.seq = hdr->sadb_msg_seq; 1737 c.seq = hdr->sadb_msg_seq;
1755 c.pid = hdr->sadb_msg_pid; 1738 c.pid = hdr->sadb_msg_pid;
@@ -2147,10 +2130,9 @@ static int key_notify_policy(struct xfrm_policy *xp, int dir, struct km_event *c
2147 int err; 2130 int err;
2148 2131
2149 out_skb = pfkey_xfrm_policy2msg_prep(xp); 2132 out_skb = pfkey_xfrm_policy2msg_prep(xp);
2150 if (IS_ERR(out_skb)) { 2133 if (IS_ERR(out_skb))
2151 err = PTR_ERR(out_skb); 2134 return PTR_ERR(out_skb);
2152 goto out; 2135
2153 }
2154 err = pfkey_xfrm_policy2msg(out_skb, xp, dir); 2136 err = pfkey_xfrm_policy2msg(out_skb, xp, dir);
2155 if (err < 0) 2137 if (err < 0)
2156 return err; 2138 return err;
@@ -2166,7 +2148,6 @@ static int key_notify_policy(struct xfrm_policy *xp, int dir, struct km_event *c
2166 out_hdr->sadb_msg_seq = c->seq; 2148 out_hdr->sadb_msg_seq = c->seq;
2167 out_hdr->sadb_msg_pid = c->pid; 2149 out_hdr->sadb_msg_pid = c->pid;
2168 pfkey_broadcast(out_skb, GFP_ATOMIC, BROADCAST_ALL, NULL, xp_net(xp)); 2150 pfkey_broadcast(out_skb, GFP_ATOMIC, BROADCAST_ALL, NULL, xp_net(xp));
2169out:
2170 return 0; 2151 return 0;
2171 2152
2172} 2153}
@@ -2344,7 +2325,7 @@ static int pfkey_spddelete(struct sock *sk, struct sk_buff *skb, struct sadb_msg
2344 return err; 2325 return err;
2345 } 2326 }
2346 2327
2347 xp = xfrm_policy_bysel_ctx(net, XFRM_POLICY_TYPE_MAIN, 2328 xp = xfrm_policy_bysel_ctx(net, DUMMY_MARK, XFRM_POLICY_TYPE_MAIN,
2348 pol->sadb_x_policy_dir - 1, &sel, pol_ctx, 2329 pol->sadb_x_policy_dir - 1, &sel, pol_ctx,
2349 1, &err); 2330 1, &err);
2350 security_xfrm_policy_free(pol_ctx); 2331 security_xfrm_policy_free(pol_ctx);
@@ -2592,8 +2573,8 @@ static int pfkey_spdget(struct sock *sk, struct sk_buff *skb, struct sadb_msg *h
2592 return -EINVAL; 2573 return -EINVAL;
2593 2574
2594 delete = (hdr->sadb_msg_type == SADB_X_SPDDELETE2); 2575 delete = (hdr->sadb_msg_type == SADB_X_SPDDELETE2);
2595 xp = xfrm_policy_byid(net, XFRM_POLICY_TYPE_MAIN, dir, 2576 xp = xfrm_policy_byid(net, DUMMY_MARK, XFRM_POLICY_TYPE_MAIN,
2596 pol->sadb_x_policy_id, delete, &err); 2577 dir, pol->sadb_x_policy_id, delete, &err);
2597 if (xp == NULL) 2578 if (xp == NULL)
2598 return -ENOENT; 2579 return -ENOENT;
2599 2580
@@ -2704,14 +2685,19 @@ static int pfkey_spdflush(struct sock *sk, struct sk_buff *skb, struct sadb_msg
2704 struct net *net = sock_net(sk); 2685 struct net *net = sock_net(sk);
2705 struct km_event c; 2686 struct km_event c;
2706 struct xfrm_audit audit_info; 2687 struct xfrm_audit audit_info;
2707 int err; 2688 int err, err2;
2708 2689
2709 audit_info.loginuid = audit_get_loginuid(current); 2690 audit_info.loginuid = audit_get_loginuid(current);
2710 audit_info.sessionid = audit_get_sessionid(current); 2691 audit_info.sessionid = audit_get_sessionid(current);
2711 audit_info.secid = 0; 2692 audit_info.secid = 0;
2712 err = xfrm_policy_flush(net, XFRM_POLICY_TYPE_MAIN, &audit_info); 2693 err = xfrm_policy_flush(net, XFRM_POLICY_TYPE_MAIN, &audit_info);
2713 if (err) 2694 err2 = unicast_flush_resp(sk, hdr);
2695 if (err || err2) {
2696 if (err == -ESRCH) /* empty table - old silent behavior */
2697 return 0;
2714 return err; 2698 return err;
2699 }
2700
2715 c.data.type = XFRM_POLICY_TYPE_MAIN; 2701 c.data.type = XFRM_POLICY_TYPE_MAIN;
2716 c.event = XFRM_MSG_FLUSHPOLICY; 2702 c.event = XFRM_MSG_FLUSHPOLICY;
2717 c.pid = hdr->sadb_msg_pid; 2703 c.pid = hdr->sadb_msg_pid;
@@ -3017,12 +3003,11 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, struct km_e
3017static u32 get_acqseq(void) 3003static u32 get_acqseq(void)
3018{ 3004{
3019 u32 res; 3005 u32 res;
3020 static u32 acqseq; 3006 static atomic_t acqseq;
3021 static DEFINE_SPINLOCK(acqseq_lock);
3022 3007
3023 spin_lock_bh(&acqseq_lock); 3008 do {
3024 res = (++acqseq ? : ++acqseq); 3009 res = atomic_inc_return(&acqseq);
3025 spin_unlock_bh(&acqseq_lock); 3010 } while (!res);
3026 return res; 3011 return res;
3027} 3012}
3028 3013
@@ -3606,7 +3591,7 @@ static int pfkey_recvmsg(struct kiocb *kiocb,
3606 if (err) 3591 if (err)
3607 goto out_free; 3592 goto out_free;
3608 3593
3609 sock_recv_timestamp(msg, sk, skb); 3594 sock_recv_ts_and_drops(msg, sk, skb);
3610 3595
3611 err = (flags & MSG_TRUNC) ? skb->len : copied; 3596 err = (flags & MSG_TRUNC) ? skb->len : copied;
3612 3597
@@ -3644,7 +3629,7 @@ static const struct proto_ops pfkey_ops = {
3644 .recvmsg = pfkey_recvmsg, 3629 .recvmsg = pfkey_recvmsg,
3645}; 3630};
3646 3631
3647static struct net_proto_family pfkey_family_ops = { 3632static const struct net_proto_family pfkey_family_ops = {
3648 .family = PF_KEY, 3633 .family = PF_KEY,
3649 .create = pfkey_create, 3634 .create = pfkey_create,
3650 .owner = THIS_MODULE, 3635 .owner = THIS_MODULE,
@@ -3653,9 +3638,8 @@ static struct net_proto_family pfkey_family_ops = {
3653#ifdef CONFIG_PROC_FS 3638#ifdef CONFIG_PROC_FS
3654static int pfkey_seq_show(struct seq_file *f, void *v) 3639static int pfkey_seq_show(struct seq_file *f, void *v)
3655{ 3640{
3656 struct sock *s; 3641 struct sock *s = sk_entry(v);
3657 3642
3658 s = (struct sock *)v;
3659 if (v == SEQ_START_TOKEN) 3643 if (v == SEQ_START_TOKEN)
3660 seq_printf(f ,"sk RefCnt Rmem Wmem User Inode\n"); 3644 seq_printf(f ,"sk RefCnt Rmem Wmem User Inode\n");
3661 else 3645 else
@@ -3674,19 +3658,9 @@ static void *pfkey_seq_start(struct seq_file *f, loff_t *ppos)
3674{ 3658{
3675 struct net *net = seq_file_net(f); 3659 struct net *net = seq_file_net(f);
3676 struct netns_pfkey *net_pfkey = net_generic(net, pfkey_net_id); 3660 struct netns_pfkey *net_pfkey = net_generic(net, pfkey_net_id);
3677 struct sock *s;
3678 struct hlist_node *node;
3679 loff_t pos = *ppos;
3680
3681 read_lock(&pfkey_table_lock);
3682 if (pos == 0)
3683 return SEQ_START_TOKEN;
3684
3685 sk_for_each(s, node, &net_pfkey->table)
3686 if (pos-- == 1)
3687 return s;
3688 3661
3689 return NULL; 3662 rcu_read_lock();
3663 return seq_hlist_start_head_rcu(&net_pfkey->table, *ppos);
3690} 3664}
3691 3665
3692static void *pfkey_seq_next(struct seq_file *f, void *v, loff_t *ppos) 3666static void *pfkey_seq_next(struct seq_file *f, void *v, loff_t *ppos)
@@ -3694,15 +3668,12 @@ static void *pfkey_seq_next(struct seq_file *f, void *v, loff_t *ppos)
3694 struct net *net = seq_file_net(f); 3668 struct net *net = seq_file_net(f);
3695 struct netns_pfkey *net_pfkey = net_generic(net, pfkey_net_id); 3669 struct netns_pfkey *net_pfkey = net_generic(net, pfkey_net_id);
3696 3670
3697 ++*ppos; 3671 return seq_hlist_next_rcu(v, &net_pfkey->table, ppos);
3698 return (v == SEQ_START_TOKEN) ?
3699 sk_head(&net_pfkey->table) :
3700 sk_next((struct sock *)v);
3701} 3672}
3702 3673
3703static void pfkey_seq_stop(struct seq_file *f, void *v) 3674static void pfkey_seq_stop(struct seq_file *f, void *v)
3704{ 3675{
3705 read_unlock(&pfkey_table_lock); 3676 rcu_read_unlock();
3706} 3677}
3707 3678
3708static const struct seq_operations pfkey_seq_ops = { 3679static const struct seq_operations pfkey_seq_ops = {
@@ -3736,17 +3707,17 @@ static int __net_init pfkey_init_proc(struct net *net)
3736 return 0; 3707 return 0;
3737} 3708}
3738 3709
3739static void pfkey_exit_proc(struct net *net) 3710static void __net_exit pfkey_exit_proc(struct net *net)
3740{ 3711{
3741 proc_net_remove(net, "pfkey"); 3712 proc_net_remove(net, "pfkey");
3742} 3713}
3743#else 3714#else
3744static int __net_init pfkey_init_proc(struct net *net) 3715static inline int pfkey_init_proc(struct net *net)
3745{ 3716{
3746 return 0; 3717 return 0;
3747} 3718}
3748 3719
3749static void pfkey_exit_proc(struct net *net) 3720static inline void pfkey_exit_proc(struct net *net)
3750{ 3721{
3751} 3722}
3752#endif 3723#endif
@@ -3764,28 +3735,14 @@ static struct xfrm_mgr pfkeyv2_mgr =
3764 3735
3765static int __net_init pfkey_net_init(struct net *net) 3736static int __net_init pfkey_net_init(struct net *net)
3766{ 3737{
3767 struct netns_pfkey *net_pfkey; 3738 struct netns_pfkey *net_pfkey = net_generic(net, pfkey_net_id);
3768 int rv; 3739 int rv;
3769 3740
3770 net_pfkey = kmalloc(sizeof(struct netns_pfkey), GFP_KERNEL);
3771 if (!net_pfkey) {
3772 rv = -ENOMEM;
3773 goto out_kmalloc;
3774 }
3775 INIT_HLIST_HEAD(&net_pfkey->table); 3741 INIT_HLIST_HEAD(&net_pfkey->table);
3776 atomic_set(&net_pfkey->socks_nr, 0); 3742 atomic_set(&net_pfkey->socks_nr, 0);
3777 rv = net_assign_generic(net, pfkey_net_id, net_pfkey); 3743
3778 if (rv < 0)
3779 goto out_assign;
3780 rv = pfkey_init_proc(net); 3744 rv = pfkey_init_proc(net);
3781 if (rv < 0)
3782 goto out_proc;
3783 return 0;
3784 3745
3785out_proc:
3786out_assign:
3787 kfree(net_pfkey);
3788out_kmalloc:
3789 return rv; 3746 return rv;
3790} 3747}
3791 3748
@@ -3795,19 +3752,20 @@ static void __net_exit pfkey_net_exit(struct net *net)
3795 3752
3796 pfkey_exit_proc(net); 3753 pfkey_exit_proc(net);
3797 BUG_ON(!hlist_empty(&net_pfkey->table)); 3754 BUG_ON(!hlist_empty(&net_pfkey->table));
3798 kfree(net_pfkey);
3799} 3755}
3800 3756
3801static struct pernet_operations pfkey_net_ops = { 3757static struct pernet_operations pfkey_net_ops = {
3802 .init = pfkey_net_init, 3758 .init = pfkey_net_init,
3803 .exit = pfkey_net_exit, 3759 .exit = pfkey_net_exit,
3760 .id = &pfkey_net_id,
3761 .size = sizeof(struct netns_pfkey),
3804}; 3762};
3805 3763
3806static void __exit ipsec_pfkey_exit(void) 3764static void __exit ipsec_pfkey_exit(void)
3807{ 3765{
3808 unregister_pernet_gen_subsys(pfkey_net_id, &pfkey_net_ops);
3809 xfrm_unregister_km(&pfkeyv2_mgr); 3766 xfrm_unregister_km(&pfkeyv2_mgr);
3810 sock_unregister(PF_KEY); 3767 sock_unregister(PF_KEY);
3768 unregister_pernet_subsys(&pfkey_net_ops);
3811 proto_unregister(&key_proto); 3769 proto_unregister(&key_proto);
3812} 3770}
3813 3771
@@ -3818,21 +3776,22 @@ static int __init ipsec_pfkey_init(void)
3818 if (err != 0) 3776 if (err != 0)
3819 goto out; 3777 goto out;
3820 3778
3821 err = sock_register(&pfkey_family_ops); 3779 err = register_pernet_subsys(&pfkey_net_ops);
3822 if (err != 0) 3780 if (err != 0)
3823 goto out_unregister_key_proto; 3781 goto out_unregister_key_proto;
3782 err = sock_register(&pfkey_family_ops);
3783 if (err != 0)
3784 goto out_unregister_pernet;
3824 err = xfrm_register_km(&pfkeyv2_mgr); 3785 err = xfrm_register_km(&pfkeyv2_mgr);
3825 if (err != 0) 3786 if (err != 0)
3826 goto out_sock_unregister; 3787 goto out_sock_unregister;
3827 err = register_pernet_gen_subsys(&pfkey_net_id, &pfkey_net_ops);
3828 if (err != 0)
3829 goto out_xfrm_unregister_km;
3830out: 3788out:
3831 return err; 3789 return err;
3832out_xfrm_unregister_km: 3790
3833 xfrm_unregister_km(&pfkeyv2_mgr);
3834out_sock_unregister: 3791out_sock_unregister:
3835 sock_unregister(PF_KEY); 3792 sock_unregister(PF_KEY);
3793out_unregister_pernet:
3794 unregister_pernet_subsys(&pfkey_net_ops);
3836out_unregister_key_proto: 3795out_unregister_key_proto:
3837 proto_unregister(&key_proto); 3796 proto_unregister(&key_proto);
3838 goto out; 3797 goto out;
diff --git a/net/lapb/lapb_iface.c b/net/lapb/lapb_iface.c
index bda96d18fd98..d5d8d555c410 100644
--- a/net/lapb/lapb_iface.c
+++ b/net/lapb/lapb_iface.c
@@ -29,6 +29,7 @@
29#include <linux/inet.h> 29#include <linux/inet.h>
30#include <linux/if_arp.h> 30#include <linux/if_arp.h>
31#include <linux/skbuff.h> 31#include <linux/skbuff.h>
32#include <linux/slab.h>
32#include <net/sock.h> 33#include <net/sock.h>
33#include <asm/uaccess.h> 34#include <asm/uaccess.h>
34#include <asm/system.h> 35#include <asm/system.h>
diff --git a/net/lapb/lapb_in.c b/net/lapb/lapb_in.c
index 6762e7c751eb..21904a002449 100644
--- a/net/lapb/lapb_in.c
+++ b/net/lapb/lapb_in.c
@@ -27,6 +27,7 @@
27#include <linux/inet.h> 27#include <linux/inet.h>
28#include <linux/netdevice.h> 28#include <linux/netdevice.h>
29#include <linux/skbuff.h> 29#include <linux/skbuff.h>
30#include <linux/slab.h>
30#include <net/sock.h> 31#include <net/sock.h>
31#include <asm/uaccess.h> 32#include <asm/uaccess.h>
32#include <asm/system.h> 33#include <asm/system.h>
diff --git a/net/lapb/lapb_out.c b/net/lapb/lapb_out.c
index 339cc5f2684f..c75a79540f9f 100644
--- a/net/lapb/lapb_out.c
+++ b/net/lapb/lapb_out.c
@@ -25,6 +25,7 @@
25#include <linux/net.h> 25#include <linux/net.h>
26#include <linux/inet.h> 26#include <linux/inet.h>
27#include <linux/skbuff.h> 27#include <linux/skbuff.h>
28#include <linux/slab.h>
28#include <net/sock.h> 29#include <net/sock.h>
29#include <asm/uaccess.h> 30#include <asm/uaccess.h>
30#include <asm/system.h> 31#include <asm/system.h>
diff --git a/net/lapb/lapb_subr.c b/net/lapb/lapb_subr.c
index b827f47ac133..43a2a7fb327b 100644
--- a/net/lapb/lapb_subr.c
+++ b/net/lapb/lapb_subr.c
@@ -24,6 +24,7 @@
24#include <linux/net.h> 24#include <linux/net.h>
25#include <linux/inet.h> 25#include <linux/inet.h>
26#include <linux/skbuff.h> 26#include <linux/skbuff.h>
27#include <linux/slab.h>
27#include <net/sock.h> 28#include <net/sock.h>
28#include <asm/uaccess.h> 29#include <asm/uaccess.h>
29#include <asm/system.h> 30#include <asm/system.h>
diff --git a/net/llc/af_llc.c b/net/llc/af_llc.c
index 7aa4fd170104..2db6a9f75913 100644
--- a/net/llc/af_llc.c
+++ b/net/llc/af_llc.c
@@ -25,6 +25,7 @@
25#include <linux/module.h> 25#include <linux/module.h>
26#include <linux/rtnetlink.h> 26#include <linux/rtnetlink.h>
27#include <linux/init.h> 27#include <linux/init.h>
28#include <linux/slab.h>
28#include <net/llc.h> 29#include <net/llc.h>
29#include <net/llc_sap.h> 30#include <net/llc_sap.h>
30#include <net/llc_pdu.h> 31#include <net/llc_pdu.h>
@@ -47,6 +48,10 @@ static int llc_ui_wait_for_busy_core(struct sock *sk, long timeout);
47#define dprintk(args...) 48#define dprintk(args...)
48#endif 49#endif
49 50
51/* Maybe we'll add some more in the future. */
52#define LLC_CMSG_PKTINFO 1
53
54
50/** 55/**
51 * llc_ui_next_link_no - return the next unused link number for a sap 56 * llc_ui_next_link_no - return the next unused link number for a sap
52 * @sap: Address of sap to get link number from. 57 * @sap: Address of sap to get link number from.
@@ -136,18 +141,22 @@ static struct proto llc_proto = {
136 .name = "LLC", 141 .name = "LLC",
137 .owner = THIS_MODULE, 142 .owner = THIS_MODULE,
138 .obj_size = sizeof(struct llc_sock), 143 .obj_size = sizeof(struct llc_sock),
144 .slab_flags = SLAB_DESTROY_BY_RCU,
139}; 145};
140 146
141/** 147/**
142 * llc_ui_create - alloc and init a new llc_ui socket 148 * llc_ui_create - alloc and init a new llc_ui socket
149 * @net: network namespace (must be default network)
143 * @sock: Socket to initialize and attach allocated sk to. 150 * @sock: Socket to initialize and attach allocated sk to.
144 * @protocol: Unused. 151 * @protocol: Unused.
152 * @kern: on behalf of kernel or userspace
145 * 153 *
146 * Allocate and initialize a new llc_ui socket, validate the user wants a 154 * Allocate and initialize a new llc_ui socket, validate the user wants a
147 * socket type we have available. 155 * socket type we have available.
148 * Returns 0 upon success, negative upon failure. 156 * Returns 0 upon success, negative upon failure.
149 */ 157 */
150static int llc_ui_create(struct net *net, struct socket *sock, int protocol) 158static int llc_ui_create(struct net *net, struct socket *sock, int protocol,
159 int kern)
151{ 160{
152 struct sock *sk; 161 struct sock *sk;
153 int rc = -ESOCKTNOSUPPORT; 162 int rc = -ESOCKTNOSUPPORT;
@@ -155,7 +164,7 @@ static int llc_ui_create(struct net *net, struct socket *sock, int protocol)
155 if (!capable(CAP_NET_RAW)) 164 if (!capable(CAP_NET_RAW))
156 return -EPERM; 165 return -EPERM;
157 166
158 if (net != &init_net) 167 if (!net_eq(net, &init_net))
159 return -EAFNOSUPPORT; 168 return -EAFNOSUPPORT;
160 169
161 if (likely(sock->type == SOCK_DGRAM || sock->type == SOCK_STREAM)) { 170 if (likely(sock->type == SOCK_DGRAM || sock->type == SOCK_STREAM)) {
@@ -189,10 +198,8 @@ static int llc_ui_release(struct socket *sock)
189 llc->laddr.lsap, llc->daddr.lsap); 198 llc->laddr.lsap, llc->daddr.lsap);
190 if (!llc_send_disc(sk)) 199 if (!llc_send_disc(sk))
191 llc_ui_wait_for_disc(sk, sk->sk_rcvtimeo); 200 llc_ui_wait_for_disc(sk, sk->sk_rcvtimeo);
192 if (!sock_flag(sk, SOCK_ZAPPED)) { 201 if (!sock_flag(sk, SOCK_ZAPPED))
193 llc_sap_put(llc->sap);
194 llc_sap_remove_socket(llc->sap, sk); 202 llc_sap_remove_socket(llc->sap, sk);
195 }
196 release_sock(sk); 203 release_sock(sk);
197 if (llc->dev) 204 if (llc->dev)
198 dev_put(llc->dev); 205 dev_put(llc->dev);
@@ -252,7 +259,14 @@ static int llc_ui_autobind(struct socket *sock, struct sockaddr_llc *addr)
252 if (!sock_flag(sk, SOCK_ZAPPED)) 259 if (!sock_flag(sk, SOCK_ZAPPED))
253 goto out; 260 goto out;
254 rc = -ENODEV; 261 rc = -ENODEV;
255 llc->dev = dev_getfirstbyhwtype(&init_net, addr->sllc_arphrd); 262 if (sk->sk_bound_dev_if) {
263 llc->dev = dev_get_by_index(&init_net, sk->sk_bound_dev_if);
264 if (llc->dev && addr->sllc_arphrd != llc->dev->type) {
265 dev_put(llc->dev);
266 llc->dev = NULL;
267 }
268 } else
269 llc->dev = dev_getfirstbyhwtype(&init_net, addr->sllc_arphrd);
256 if (!llc->dev) 270 if (!llc->dev)
257 goto out; 271 goto out;
258 rc = -EUSERS; 272 rc = -EUSERS;
@@ -303,7 +317,25 @@ static int llc_ui_bind(struct socket *sock, struct sockaddr *uaddr, int addrlen)
303 goto out; 317 goto out;
304 rc = -ENODEV; 318 rc = -ENODEV;
305 rtnl_lock(); 319 rtnl_lock();
306 llc->dev = dev_getbyhwaddr(&init_net, addr->sllc_arphrd, addr->sllc_mac); 320 if (sk->sk_bound_dev_if) {
321 llc->dev = dev_get_by_index(&init_net, sk->sk_bound_dev_if);
322 if (llc->dev) {
323 if (!addr->sllc_arphrd)
324 addr->sllc_arphrd = llc->dev->type;
325 if (llc_mac_null(addr->sllc_mac))
326 memcpy(addr->sllc_mac, llc->dev->dev_addr,
327 IFHWADDRLEN);
328 if (addr->sllc_arphrd != llc->dev->type ||
329 !llc_mac_match(addr->sllc_mac,
330 llc->dev->dev_addr)) {
331 rc = -EINVAL;
332 dev_put(llc->dev);
333 llc->dev = NULL;
334 }
335 }
336 } else
337 llc->dev = dev_getbyhwaddr(&init_net, addr->sllc_arphrd,
338 addr->sllc_mac);
307 rtnl_unlock(); 339 rtnl_unlock();
308 if (!llc->dev) 340 if (!llc->dev)
309 goto out; 341 goto out;
@@ -319,7 +351,6 @@ static int llc_ui_bind(struct socket *sock, struct sockaddr *uaddr, int addrlen)
319 rc = -EBUSY; /* some other network layer is using the sap */ 351 rc = -EBUSY; /* some other network layer is using the sap */
320 if (!sap) 352 if (!sap)
321 goto out; 353 goto out;
322 llc_sap_hold(sap);
323 } else { 354 } else {
324 struct llc_addr laddr, daddr; 355 struct llc_addr laddr, daddr;
325 struct sock *ask; 356 struct sock *ask;
@@ -588,6 +619,20 @@ static int llc_wait_data(struct sock *sk, long timeo)
588 return rc; 619 return rc;
589} 620}
590 621
622static void llc_cmsg_rcv(struct msghdr *msg, struct sk_buff *skb)
623{
624 struct llc_sock *llc = llc_sk(skb->sk);
625
626 if (llc->cmsg_flags & LLC_CMSG_PKTINFO) {
627 struct llc_pktinfo info;
628
629 info.lpi_ifindex = llc_sk(skb->sk)->dev->ifindex;
630 llc_pdu_decode_dsap(skb, &info.lpi_sap);
631 llc_pdu_decode_da(skb, info.lpi_mac);
632 put_cmsg(msg, SOL_LLC, LLC_OPT_PKTINFO, sizeof(info), &info);
633 }
634}
635
591/** 636/**
592 * llc_ui_accept - accept a new incoming connection. 637 * llc_ui_accept - accept a new incoming connection.
593 * @sock: Socket which connections arrive on. 638 * @sock: Socket which connections arrive on.
@@ -809,6 +854,8 @@ copy_uaddr:
809 memcpy(uaddr, llc_ui_skb_cb(skb), sizeof(*uaddr)); 854 memcpy(uaddr, llc_ui_skb_cb(skb), sizeof(*uaddr));
810 msg->msg_namelen = sizeof(*uaddr); 855 msg->msg_namelen = sizeof(*uaddr);
811 } 856 }
857 if (llc_sk(sk)->cmsg_flags)
858 llc_cmsg_rcv(msg, skb);
812 goto out; 859 goto out;
813} 860}
814 861
@@ -1027,6 +1074,12 @@ static int llc_ui_setsockopt(struct socket *sock, int level, int optname,
1027 goto out; 1074 goto out;
1028 llc->rw = opt; 1075 llc->rw = opt;
1029 break; 1076 break;
1077 case LLC_OPT_PKTINFO:
1078 if (opt)
1079 llc->cmsg_flags |= LLC_CMSG_PKTINFO;
1080 else
1081 llc->cmsg_flags &= ~LLC_CMSG_PKTINFO;
1082 break;
1030 default: 1083 default:
1031 rc = -ENOPROTOOPT; 1084 rc = -ENOPROTOOPT;
1032 goto out; 1085 goto out;
@@ -1080,6 +1133,9 @@ static int llc_ui_getsockopt(struct socket *sock, int level, int optname,
1080 val = llc->k; break; 1133 val = llc->k; break;
1081 case LLC_OPT_RX_WIN: 1134 case LLC_OPT_RX_WIN:
1082 val = llc->rw; break; 1135 val = llc->rw; break;
1136 case LLC_OPT_PKTINFO:
1137 val = (llc->cmsg_flags & LLC_CMSG_PKTINFO) != 0;
1138 break;
1083 default: 1139 default:
1084 rc = -ENOPROTOOPT; 1140 rc = -ENOPROTOOPT;
1085 goto out; 1141 goto out;
@@ -1092,7 +1148,7 @@ out:
1092 return rc; 1148 return rc;
1093} 1149}
1094 1150
1095static struct net_proto_family llc_ui_family_ops = { 1151static const struct net_proto_family llc_ui_family_ops = {
1096 .family = PF_LLC, 1152 .family = PF_LLC,
1097 .create = llc_ui_create, 1153 .create = llc_ui_create,
1098 .owner = THIS_MODULE, 1154 .owner = THIS_MODULE,
diff --git a/net/llc/llc_c_ac.c b/net/llc/llc_c_ac.c
index 019c780512e8..ea225bd2672c 100644
--- a/net/llc/llc_c_ac.c
+++ b/net/llc/llc_c_ac.c
@@ -18,6 +18,7 @@
18 * See the GNU General Public License for more details. 18 * See the GNU General Public License for more details.
19 */ 19 */
20#include <linux/netdevice.h> 20#include <linux/netdevice.h>
21#include <linux/slab.h>
21#include <net/llc_conn.h> 22#include <net/llc_conn.h>
22#include <net/llc_sap.h> 23#include <net/llc_sap.h>
23#include <net/sock.h> 24#include <net/sock.h>
@@ -1437,7 +1438,7 @@ static void llc_process_tmr_ev(struct sock *sk, struct sk_buff *skb)
1437 llc_conn_state_process(sk, skb); 1438 llc_conn_state_process(sk, skb);
1438 else { 1439 else {
1439 llc_set_backlog_type(skb, LLC_EVENT); 1440 llc_set_backlog_type(skb, LLC_EVENT);
1440 sk_add_backlog(sk, skb); 1441 __sk_add_backlog(sk, skb);
1441 } 1442 }
1442 } 1443 }
1443} 1444}
diff --git a/net/llc/llc_conn.c b/net/llc/llc_conn.c
index c6bab39b018e..ba137a6a224d 100644
--- a/net/llc/llc_conn.c
+++ b/net/llc/llc_conn.c
@@ -13,6 +13,7 @@
13 */ 13 */
14 14
15#include <linux/init.h> 15#include <linux/init.h>
16#include <linux/slab.h>
16#include <net/llc_sap.h> 17#include <net/llc_sap.h>
17#include <net/llc_conn.h> 18#include <net/llc_conn.h>
18#include <net/sock.h> 19#include <net/sock.h>
@@ -468,6 +469,19 @@ static int llc_exec_conn_trans_actions(struct sock *sk,
468 return rc; 469 return rc;
469} 470}
470 471
472static inline bool llc_estab_match(const struct llc_sap *sap,
473 const struct llc_addr *daddr,
474 const struct llc_addr *laddr,
475 const struct sock *sk)
476{
477 struct llc_sock *llc = llc_sk(sk);
478
479 return llc->laddr.lsap == laddr->lsap &&
480 llc->daddr.lsap == daddr->lsap &&
481 llc_mac_match(llc->laddr.mac, laddr->mac) &&
482 llc_mac_match(llc->daddr.mac, daddr->mac);
483}
484
471/** 485/**
472 * __llc_lookup_established - Finds connection for the remote/local sap/mac 486 * __llc_lookup_established - Finds connection for the remote/local sap/mac
473 * @sap: SAP 487 * @sap: SAP
@@ -484,23 +498,35 @@ static struct sock *__llc_lookup_established(struct llc_sap *sap,
484 struct llc_addr *laddr) 498 struct llc_addr *laddr)
485{ 499{
486 struct sock *rc; 500 struct sock *rc;
487 struct hlist_node *node; 501 struct hlist_nulls_node *node;
488 502 int slot = llc_sk_laddr_hashfn(sap, laddr);
489 read_lock(&sap->sk_list.lock); 503 struct hlist_nulls_head *laddr_hb = &sap->sk_laddr_hash[slot];
490 sk_for_each(rc, node, &sap->sk_list.list) { 504
491 struct llc_sock *llc = llc_sk(rc); 505 rcu_read_lock();
492 506again:
493 if (llc->laddr.lsap == laddr->lsap && 507 sk_nulls_for_each_rcu(rc, node, laddr_hb) {
494 llc->daddr.lsap == daddr->lsap && 508 if (llc_estab_match(sap, daddr, laddr, rc)) {
495 llc_mac_match(llc->laddr.mac, laddr->mac) && 509 /* Extra checks required by SLAB_DESTROY_BY_RCU */
496 llc_mac_match(llc->daddr.mac, daddr->mac)) { 510 if (unlikely(!atomic_inc_not_zero(&rc->sk_refcnt)))
497 sock_hold(rc); 511 goto again;
512 if (unlikely(llc_sk(rc)->sap != sap ||
513 !llc_estab_match(sap, daddr, laddr, rc))) {
514 sock_put(rc);
515 continue;
516 }
498 goto found; 517 goto found;
499 } 518 }
500 } 519 }
501 rc = NULL; 520 rc = NULL;
521 /*
522 * if the nulls value we got at the end of this lookup is
523 * not the expected one, we must restart lookup.
524 * We probably met an item that was moved to another chain.
525 */
526 if (unlikely(get_nulls_value(node) != slot))
527 goto again;
502found: 528found:
503 read_unlock(&sap->sk_list.lock); 529 rcu_read_unlock();
504 return rc; 530 return rc;
505} 531}
506 532
@@ -516,6 +542,53 @@ struct sock *llc_lookup_established(struct llc_sap *sap,
516 return sk; 542 return sk;
517} 543}
518 544
545static inline bool llc_listener_match(const struct llc_sap *sap,
546 const struct llc_addr *laddr,
547 const struct sock *sk)
548{
549 struct llc_sock *llc = llc_sk(sk);
550
551 return sk->sk_type == SOCK_STREAM && sk->sk_state == TCP_LISTEN &&
552 llc->laddr.lsap == laddr->lsap &&
553 llc_mac_match(llc->laddr.mac, laddr->mac);
554}
555
556static struct sock *__llc_lookup_listener(struct llc_sap *sap,
557 struct llc_addr *laddr)
558{
559 struct sock *rc;
560 struct hlist_nulls_node *node;
561 int slot = llc_sk_laddr_hashfn(sap, laddr);
562 struct hlist_nulls_head *laddr_hb = &sap->sk_laddr_hash[slot];
563
564 rcu_read_lock();
565again:
566 sk_nulls_for_each_rcu(rc, node, laddr_hb) {
567 if (llc_listener_match(sap, laddr, rc)) {
568 /* Extra checks required by SLAB_DESTROY_BY_RCU */
569 if (unlikely(!atomic_inc_not_zero(&rc->sk_refcnt)))
570 goto again;
571 if (unlikely(llc_sk(rc)->sap != sap ||
572 !llc_listener_match(sap, laddr, rc))) {
573 sock_put(rc);
574 continue;
575 }
576 goto found;
577 }
578 }
579 rc = NULL;
580 /*
581 * if the nulls value we got at the end of this lookup is
582 * not the expected one, we must restart lookup.
583 * We probably met an item that was moved to another chain.
584 */
585 if (unlikely(get_nulls_value(node) != slot))
586 goto again;
587found:
588 rcu_read_unlock();
589 return rc;
590}
591
519/** 592/**
520 * llc_lookup_listener - Finds listener for local MAC + SAP 593 * llc_lookup_listener - Finds listener for local MAC + SAP
521 * @sap: SAP 594 * @sap: SAP
@@ -529,24 +602,12 @@ struct sock *llc_lookup_established(struct llc_sap *sap,
529static struct sock *llc_lookup_listener(struct llc_sap *sap, 602static struct sock *llc_lookup_listener(struct llc_sap *sap,
530 struct llc_addr *laddr) 603 struct llc_addr *laddr)
531{ 604{
532 struct sock *rc; 605 static struct llc_addr null_addr;
533 struct hlist_node *node; 606 struct sock *rc = __llc_lookup_listener(sap, laddr);
534 607
535 read_lock(&sap->sk_list.lock); 608 if (!rc)
536 sk_for_each(rc, node, &sap->sk_list.list) { 609 rc = __llc_lookup_listener(sap, &null_addr);
537 struct llc_sock *llc = llc_sk(rc);
538 610
539 if (rc->sk_type == SOCK_STREAM && rc->sk_state == TCP_LISTEN &&
540 llc->laddr.lsap == laddr->lsap &&
541 (llc_mac_match(llc->laddr.mac, laddr->mac) ||
542 llc_mac_null(llc->laddr.mac))) {
543 sock_hold(rc);
544 goto found;
545 }
546 }
547 rc = NULL;
548found:
549 read_unlock(&sap->sk_list.lock);
550 return rc; 611 return rc;
551} 612}
552 613
@@ -647,15 +708,22 @@ static int llc_find_offset(int state, int ev_type)
647 * @sap: SAP 708 * @sap: SAP
648 * @sk: socket 709 * @sk: socket
649 * 710 *
650 * This function adds a socket to sk_list of a SAP. 711 * This function adds a socket to the hash tables of a SAP.
651 */ 712 */
652void llc_sap_add_socket(struct llc_sap *sap, struct sock *sk) 713void llc_sap_add_socket(struct llc_sap *sap, struct sock *sk)
653{ 714{
715 struct llc_sock *llc = llc_sk(sk);
716 struct hlist_head *dev_hb = llc_sk_dev_hash(sap, llc->dev->ifindex);
717 struct hlist_nulls_head *laddr_hb = llc_sk_laddr_hash(sap, &llc->laddr);
718
654 llc_sap_hold(sap); 719 llc_sap_hold(sap);
655 write_lock_bh(&sap->sk_list.lock);
656 llc_sk(sk)->sap = sap; 720 llc_sk(sk)->sap = sap;
657 sk_add_node(sk, &sap->sk_list.list); 721
658 write_unlock_bh(&sap->sk_list.lock); 722 spin_lock_bh(&sap->sk_lock);
723 sap->sk_count++;
724 sk_nulls_add_node_rcu(sk, laddr_hb);
725 hlist_add_head(&llc->dev_hash_node, dev_hb);
726 spin_unlock_bh(&sap->sk_lock);
659} 727}
660 728
661/** 729/**
@@ -663,14 +731,18 @@ void llc_sap_add_socket(struct llc_sap *sap, struct sock *sk)
663 * @sap: SAP 731 * @sap: SAP
664 * @sk: socket 732 * @sk: socket
665 * 733 *
666 * This function removes a connection from sk_list.list of a SAP if 734 * This function removes a connection from the hash tables of a SAP if
667 * the connection was in this list. 735 * the connection was in this list.
668 */ 736 */
669void llc_sap_remove_socket(struct llc_sap *sap, struct sock *sk) 737void llc_sap_remove_socket(struct llc_sap *sap, struct sock *sk)
670{ 738{
671 write_lock_bh(&sap->sk_list.lock); 739 struct llc_sock *llc = llc_sk(sk);
672 sk_del_node_init(sk); 740
673 write_unlock_bh(&sap->sk_list.lock); 741 spin_lock_bh(&sap->sk_lock);
742 sk_nulls_del_node_init_rcu(sk);
743 hlist_del(&llc->dev_hash_node);
744 sap->sk_count--;
745 spin_unlock_bh(&sap->sk_lock);
674 llc_sap_put(sap); 746 llc_sap_put(sap);
675} 747}
676 748
@@ -756,7 +828,8 @@ void llc_conn_handler(struct llc_sap *sap, struct sk_buff *skb)
756 else { 828 else {
757 dprintk("%s: adding to backlog...\n", __func__); 829 dprintk("%s: adding to backlog...\n", __func__);
758 llc_set_backlog_type(skb, LLC_PACKET); 830 llc_set_backlog_type(skb, LLC_PACKET);
759 sk_add_backlog(sk, skb); 831 if (sk_add_backlog(sk, skb))
832 goto drop_unlock;
760 } 833 }
761out: 834out:
762 bh_unlock_sock(sk); 835 bh_unlock_sock(sk);
diff --git a/net/llc/llc_core.c b/net/llc/llc_core.c
index ff4c0ab96a69..78167e81dfeb 100644
--- a/net/llc/llc_core.c
+++ b/net/llc/llc_core.c
@@ -23,7 +23,7 @@
23#include <net/llc.h> 23#include <net/llc.h>
24 24
25LIST_HEAD(llc_sap_list); 25LIST_HEAD(llc_sap_list);
26DEFINE_RWLOCK(llc_sap_list_lock); 26DEFINE_SPINLOCK(llc_sap_list_lock);
27 27
28/** 28/**
29 * llc_sap_alloc - allocates and initializes sap. 29 * llc_sap_alloc - allocates and initializes sap.
@@ -33,40 +33,19 @@ DEFINE_RWLOCK(llc_sap_list_lock);
33static struct llc_sap *llc_sap_alloc(void) 33static struct llc_sap *llc_sap_alloc(void)
34{ 34{
35 struct llc_sap *sap = kzalloc(sizeof(*sap), GFP_ATOMIC); 35 struct llc_sap *sap = kzalloc(sizeof(*sap), GFP_ATOMIC);
36 int i;
36 37
37 if (sap) { 38 if (sap) {
38 /* sap->laddr.mac - leave as a null, it's filled by bind */ 39 /* sap->laddr.mac - leave as a null, it's filled by bind */
39 sap->state = LLC_SAP_STATE_ACTIVE; 40 sap->state = LLC_SAP_STATE_ACTIVE;
40 rwlock_init(&sap->sk_list.lock); 41 spin_lock_init(&sap->sk_lock);
42 for (i = 0; i < LLC_SK_LADDR_HASH_ENTRIES; i++)
43 INIT_HLIST_NULLS_HEAD(&sap->sk_laddr_hash[i], i);
41 atomic_set(&sap->refcnt, 1); 44 atomic_set(&sap->refcnt, 1);
42 } 45 }
43 return sap; 46 return sap;
44} 47}
45 48
46/**
47 * llc_add_sap - add sap to station list
48 * @sap: Address of the sap
49 *
50 * Adds a sap to the LLC's station sap list.
51 */
52static void llc_add_sap(struct llc_sap *sap)
53{
54 list_add_tail(&sap->node, &llc_sap_list);
55}
56
57/**
58 * llc_del_sap - del sap from station list
59 * @sap: Address of the sap
60 *
61 * Removes a sap to the LLC's station sap list.
62 */
63static void llc_del_sap(struct llc_sap *sap)
64{
65 write_lock_bh(&llc_sap_list_lock);
66 list_del(&sap->node);
67 write_unlock_bh(&llc_sap_list_lock);
68}
69
70static struct llc_sap *__llc_sap_find(unsigned char sap_value) 49static struct llc_sap *__llc_sap_find(unsigned char sap_value)
71{ 50{
72 struct llc_sap* sap; 51 struct llc_sap* sap;
@@ -90,13 +69,13 @@ out:
90 */ 69 */
91struct llc_sap *llc_sap_find(unsigned char sap_value) 70struct llc_sap *llc_sap_find(unsigned char sap_value)
92{ 71{
93 struct llc_sap* sap; 72 struct llc_sap *sap;
94 73
95 read_lock_bh(&llc_sap_list_lock); 74 rcu_read_lock_bh();
96 sap = __llc_sap_find(sap_value); 75 sap = __llc_sap_find(sap_value);
97 if (sap) 76 if (sap)
98 llc_sap_hold(sap); 77 llc_sap_hold(sap);
99 read_unlock_bh(&llc_sap_list_lock); 78 rcu_read_unlock_bh();
100 return sap; 79 return sap;
101} 80}
102 81
@@ -117,7 +96,7 @@ struct llc_sap *llc_sap_open(unsigned char lsap,
117{ 96{
118 struct llc_sap *sap = NULL; 97 struct llc_sap *sap = NULL;
119 98
120 write_lock_bh(&llc_sap_list_lock); 99 spin_lock_bh(&llc_sap_list_lock);
121 if (__llc_sap_find(lsap)) /* SAP already exists */ 100 if (__llc_sap_find(lsap)) /* SAP already exists */
122 goto out; 101 goto out;
123 sap = llc_sap_alloc(); 102 sap = llc_sap_alloc();
@@ -125,9 +104,9 @@ struct llc_sap *llc_sap_open(unsigned char lsap,
125 goto out; 104 goto out;
126 sap->laddr.lsap = lsap; 105 sap->laddr.lsap = lsap;
127 sap->rcv_func = func; 106 sap->rcv_func = func;
128 llc_add_sap(sap); 107 list_add_tail_rcu(&sap->node, &llc_sap_list);
129out: 108out:
130 write_unlock_bh(&llc_sap_list_lock); 109 spin_unlock_bh(&llc_sap_list_lock);
131 return sap; 110 return sap;
132} 111}
133 112
@@ -142,8 +121,14 @@ out:
142 */ 121 */
143void llc_sap_close(struct llc_sap *sap) 122void llc_sap_close(struct llc_sap *sap)
144{ 123{
145 WARN_ON(!hlist_empty(&sap->sk_list.list)); 124 WARN_ON(sap->sk_count);
146 llc_del_sap(sap); 125
126 spin_lock_bh(&llc_sap_list_lock);
127 list_del_rcu(&sap->node);
128 spin_unlock_bh(&llc_sap_list_lock);
129
130 synchronize_rcu();
131
147 kfree(sap); 132 kfree(sap);
148} 133}
149 134
diff --git a/net/llc/llc_if.c b/net/llc/llc_if.c
index a89917130a7b..25c31c0a3fdb 100644
--- a/net/llc/llc_if.c
+++ b/net/llc/llc_if.c
@@ -11,6 +11,7 @@
11 * 11 *
12 * See the GNU General Public License for more details. 12 * See the GNU General Public License for more details.
13 */ 13 */
14#include <linux/gfp.h>
14#include <linux/module.h> 15#include <linux/module.h>
15#include <linux/kernel.h> 16#include <linux/kernel.h>
16#include <linux/netdevice.h> 17#include <linux/netdevice.h>
diff --git a/net/llc/llc_input.c b/net/llc/llc_input.c
index 57ad974e4d94..f99687439139 100644
--- a/net/llc/llc_input.c
+++ b/net/llc/llc_input.c
@@ -12,6 +12,7 @@
12 * See the GNU General Public License for more details. 12 * See the GNU General Public License for more details.
13 */ 13 */
14#include <linux/netdevice.h> 14#include <linux/netdevice.h>
15#include <linux/slab.h>
15#include <net/net_namespace.h> 16#include <net/net_namespace.h>
16#include <net/llc.h> 17#include <net/llc.h>
17#include <net/llc_pdu.h> 18#include <net/llc_pdu.h>
diff --git a/net/llc/llc_output.c b/net/llc/llc_output.c
index 754f4fedc852..b38a1079a98e 100644
--- a/net/llc/llc_output.c
+++ b/net/llc/llc_output.c
@@ -33,48 +33,19 @@
33int llc_mac_hdr_init(struct sk_buff *skb, 33int llc_mac_hdr_init(struct sk_buff *skb,
34 const unsigned char *sa, const unsigned char *da) 34 const unsigned char *sa, const unsigned char *da)
35{ 35{
36 int rc = 0; 36 int rc = -EINVAL;
37 37
38 switch (skb->dev->type) { 38 switch (skb->dev->type) {
39#ifdef CONFIG_TR 39 case ARPHRD_IEEE802_TR:
40 case ARPHRD_IEEE802_TR: {
41 struct net_device *dev = skb->dev;
42 struct trh_hdr *trh;
43
44 skb_push(skb, sizeof(*trh));
45 skb_reset_mac_header(skb);
46 trh = tr_hdr(skb);
47 trh->ac = AC;
48 trh->fc = LLC_FRAME;
49 if (sa)
50 memcpy(trh->saddr, sa, dev->addr_len);
51 else
52 memset(trh->saddr, 0, dev->addr_len);
53 if (da) {
54 memcpy(trh->daddr, da, dev->addr_len);
55 tr_source_route(skb, trh, dev);
56 skb_reset_mac_header(skb);
57 }
58 break;
59 }
60#endif
61 case ARPHRD_ETHER: 40 case ARPHRD_ETHER:
62 case ARPHRD_LOOPBACK: { 41 case ARPHRD_LOOPBACK:
63 unsigned short len = skb->len; 42 rc = dev_hard_header(skb, skb->dev, ETH_P_802_2, da, sa,
64 struct ethhdr *eth; 43 skb->len);
65 44 if (rc > 0)
66 skb_push(skb, sizeof(*eth)); 45 rc = 0;
67 skb_reset_mac_header(skb);
68 eth = eth_hdr(skb);
69 eth->h_proto = htons(len);
70 memcpy(eth->h_dest, da, ETH_ALEN);
71 memcpy(eth->h_source, sa, ETH_ALEN);
72 break; 46 break;
73 }
74 default: 47 default:
75 printk(KERN_WARNING "device type not supported: %d\n", 48 WARN(1, "device type not supported: %d\n", skb->dev->type);
76 skb->dev->type);
77 rc = -EINVAL;
78 } 49 }
79 return rc; 50 return rc;
80} 51}
diff --git a/net/llc/llc_proc.c b/net/llc/llc_proc.c
index be47ac427f6b..7af1ff2d1f19 100644
--- a/net/llc/llc_proc.c
+++ b/net/llc/llc_proc.c
@@ -32,21 +32,23 @@ static void llc_ui_format_mac(struct seq_file *seq, u8 *addr)
32 32
33static struct sock *llc_get_sk_idx(loff_t pos) 33static struct sock *llc_get_sk_idx(loff_t pos)
34{ 34{
35 struct list_head *sap_entry;
36 struct llc_sap *sap; 35 struct llc_sap *sap;
37 struct hlist_node *node;
38 struct sock *sk = NULL; 36 struct sock *sk = NULL;
39 37 int i;
40 list_for_each(sap_entry, &llc_sap_list) { 38
41 sap = list_entry(sap_entry, struct llc_sap, node); 39 list_for_each_entry_rcu(sap, &llc_sap_list, node) {
42 40 spin_lock_bh(&sap->sk_lock);
43 read_lock_bh(&sap->sk_list.lock); 41 for (i = 0; i < LLC_SK_LADDR_HASH_ENTRIES; i++) {
44 sk_for_each(sk, node, &sap->sk_list.list) { 42 struct hlist_nulls_head *head = &sap->sk_laddr_hash[i];
45 if (!pos) 43 struct hlist_nulls_node *node;
46 goto found; 44
47 --pos; 45 sk_nulls_for_each(sk, node, head) {
46 if (!pos)
47 goto found; /* keep the lock */
48 --pos;
49 }
48 } 50 }
49 read_unlock_bh(&sap->sk_list.lock); 51 spin_unlock_bh(&sap->sk_lock);
50 } 52 }
51 sk = NULL; 53 sk = NULL;
52found: 54found:
@@ -57,10 +59,23 @@ static void *llc_seq_start(struct seq_file *seq, loff_t *pos)
57{ 59{
58 loff_t l = *pos; 60 loff_t l = *pos;
59 61
60 read_lock_bh(&llc_sap_list_lock); 62 rcu_read_lock_bh();
61 return l ? llc_get_sk_idx(--l) : SEQ_START_TOKEN; 63 return l ? llc_get_sk_idx(--l) : SEQ_START_TOKEN;
62} 64}
63 65
66static struct sock *laddr_hash_next(struct llc_sap *sap, int bucket)
67{
68 struct hlist_nulls_node *node;
69 struct sock *sk = NULL;
70
71 while (++bucket < LLC_SK_LADDR_HASH_ENTRIES)
72 sk_nulls_for_each(sk, node, &sap->sk_laddr_hash[bucket])
73 goto out;
74
75out:
76 return sk;
77}
78
64static void *llc_seq_next(struct seq_file *seq, void *v, loff_t *pos) 79static void *llc_seq_next(struct seq_file *seq, void *v, loff_t *pos)
65{ 80{
66 struct sock* sk, *next; 81 struct sock* sk, *next;
@@ -73,25 +88,23 @@ static void *llc_seq_next(struct seq_file *seq, void *v, loff_t *pos)
73 goto out; 88 goto out;
74 } 89 }
75 sk = v; 90 sk = v;
76 next = sk_next(sk); 91 next = sk_nulls_next(sk);
77 if (next) { 92 if (next) {
78 sk = next; 93 sk = next;
79 goto out; 94 goto out;
80 } 95 }
81 llc = llc_sk(sk); 96 llc = llc_sk(sk);
82 sap = llc->sap; 97 sap = llc->sap;
83 read_unlock_bh(&sap->sk_list.lock); 98 sk = laddr_hash_next(sap, llc_sk_laddr_hashfn(sap, &llc->laddr));
84 sk = NULL; 99 if (sk)
85 for (;;) { 100 goto out;
86 if (sap->node.next == &llc_sap_list) 101 spin_unlock_bh(&sap->sk_lock);
87 break; 102 list_for_each_entry_continue_rcu(sap, &llc_sap_list, node) {
88 sap = list_entry(sap->node.next, struct llc_sap, node); 103 spin_lock_bh(&sap->sk_lock);
89 read_lock_bh(&sap->sk_list.lock); 104 sk = laddr_hash_next(sap, -1);
90 if (!hlist_empty(&sap->sk_list.list)) { 105 if (sk)
91 sk = sk_head(&sap->sk_list.list); 106 break; /* keep the lock */
92 break; 107 spin_unlock_bh(&sap->sk_lock);
93 }
94 read_unlock_bh(&sap->sk_list.lock);
95 } 108 }
96out: 109out:
97 return sk; 110 return sk;
@@ -104,9 +117,9 @@ static void llc_seq_stop(struct seq_file *seq, void *v)
104 struct llc_sock *llc = llc_sk(sk); 117 struct llc_sock *llc = llc_sk(sk);
105 struct llc_sap *sap = llc->sap; 118 struct llc_sap *sap = llc->sap;
106 119
107 read_unlock_bh(&sap->sk_list.lock); 120 spin_unlock_bh(&sap->sk_lock);
108 } 121 }
109 read_unlock_bh(&llc_sap_list_lock); 122 rcu_read_unlock_bh();
110} 123}
111 124
112static int llc_seq_socket_show(struct seq_file *seq, void *v) 125static int llc_seq_socket_show(struct seq_file *seq, void *v)
diff --git a/net/llc/llc_sap.c b/net/llc/llc_sap.c
index 008de1fc42ca..94e7fca75b85 100644
--- a/net/llc/llc_sap.c
+++ b/net/llc/llc_sap.c
@@ -23,6 +23,7 @@
23#include <net/sock.h> 23#include <net/sock.h>
24#include <net/tcp_states.h> 24#include <net/tcp_states.h>
25#include <linux/llc.h> 25#include <linux/llc.h>
26#include <linux/slab.h>
26 27
27static int llc_mac_header_len(unsigned short devtype) 28static int llc_mac_header_len(unsigned short devtype)
28{ 29{
@@ -30,7 +31,7 @@ static int llc_mac_header_len(unsigned short devtype)
30 case ARPHRD_ETHER: 31 case ARPHRD_ETHER:
31 case ARPHRD_LOOPBACK: 32 case ARPHRD_LOOPBACK:
32 return sizeof(struct ethhdr); 33 return sizeof(struct ethhdr);
33#ifdef CONFIG_TR 34#if defined(CONFIG_TR) || defined(CONFIG_TR_MODULE)
34 case ARPHRD_IEEE802_TR: 35 case ARPHRD_IEEE802_TR:
35 return sizeof(struct trh_hdr); 36 return sizeof(struct trh_hdr);
36#endif 37#endif
@@ -297,6 +298,17 @@ static void llc_sap_rcv(struct llc_sap *sap, struct sk_buff *skb,
297 llc_sap_state_process(sap, skb); 298 llc_sap_state_process(sap, skb);
298} 299}
299 300
301static inline bool llc_dgram_match(const struct llc_sap *sap,
302 const struct llc_addr *laddr,
303 const struct sock *sk)
304{
305 struct llc_sock *llc = llc_sk(sk);
306
307 return sk->sk_type == SOCK_DGRAM &&
308 llc->laddr.lsap == laddr->lsap &&
309 llc_mac_match(llc->laddr.mac, laddr->mac);
310}
311
300/** 312/**
301 * llc_lookup_dgram - Finds dgram socket for the local sap/mac 313 * llc_lookup_dgram - Finds dgram socket for the local sap/mac
302 * @sap: SAP 314 * @sap: SAP
@@ -309,25 +321,68 @@ static struct sock *llc_lookup_dgram(struct llc_sap *sap,
309 const struct llc_addr *laddr) 321 const struct llc_addr *laddr)
310{ 322{
311 struct sock *rc; 323 struct sock *rc;
312 struct hlist_node *node; 324 struct hlist_nulls_node *node;
313 325 int slot = llc_sk_laddr_hashfn(sap, laddr);
314 read_lock_bh(&sap->sk_list.lock); 326 struct hlist_nulls_head *laddr_hb = &sap->sk_laddr_hash[slot];
315 sk_for_each(rc, node, &sap->sk_list.list) { 327
316 struct llc_sock *llc = llc_sk(rc); 328 rcu_read_lock_bh();
317 329again:
318 if (rc->sk_type == SOCK_DGRAM && 330 sk_nulls_for_each_rcu(rc, node, laddr_hb) {
319 llc->laddr.lsap == laddr->lsap && 331 if (llc_dgram_match(sap, laddr, rc)) {
320 llc_mac_match(llc->laddr.mac, laddr->mac)) { 332 /* Extra checks required by SLAB_DESTROY_BY_RCU */
321 sock_hold(rc); 333 if (unlikely(!atomic_inc_not_zero(&rc->sk_refcnt)))
334 goto again;
335 if (unlikely(llc_sk(rc)->sap != sap ||
336 !llc_dgram_match(sap, laddr, rc))) {
337 sock_put(rc);
338 continue;
339 }
322 goto found; 340 goto found;
323 } 341 }
324 } 342 }
325 rc = NULL; 343 rc = NULL;
344 /*
345 * if the nulls value we got at the end of this lookup is
346 * not the expected one, we must restart lookup.
347 * We probably met an item that was moved to another chain.
348 */
349 if (unlikely(get_nulls_value(node) != slot))
350 goto again;
326found: 351found:
327 read_unlock_bh(&sap->sk_list.lock); 352 rcu_read_unlock_bh();
328 return rc; 353 return rc;
329} 354}
330 355
356static inline bool llc_mcast_match(const struct llc_sap *sap,
357 const struct llc_addr *laddr,
358 const struct sk_buff *skb,
359 const struct sock *sk)
360{
361 struct llc_sock *llc = llc_sk(sk);
362
363 return sk->sk_type == SOCK_DGRAM &&
364 llc->laddr.lsap == laddr->lsap &&
365 llc->dev == skb->dev;
366}
367
368static void llc_do_mcast(struct llc_sap *sap, struct sk_buff *skb,
369 struct sock **stack, int count)
370{
371 struct sk_buff *skb1;
372 int i;
373
374 for (i = 0; i < count; i++) {
375 skb1 = skb_clone(skb, GFP_ATOMIC);
376 if (!skb1) {
377 sock_put(stack[i]);
378 continue;
379 }
380
381 llc_sap_rcv(sap, skb1, stack[i]);
382 sock_put(stack[i]);
383 }
384}
385
331/** 386/**
332 * llc_sap_mcast - Deliver multicast PDU's to all matching datagram sockets. 387 * llc_sap_mcast - Deliver multicast PDU's to all matching datagram sockets.
333 * @sap: SAP 388 * @sap: SAP
@@ -340,32 +395,31 @@ static void llc_sap_mcast(struct llc_sap *sap,
340 const struct llc_addr *laddr, 395 const struct llc_addr *laddr,
341 struct sk_buff *skb) 396 struct sk_buff *skb)
342{ 397{
343 struct sock *sk; 398 int i = 0, count = 256 / sizeof(struct sock *);
399 struct sock *sk, *stack[count];
344 struct hlist_node *node; 400 struct hlist_node *node;
401 struct llc_sock *llc;
402 struct hlist_head *dev_hb = llc_sk_dev_hash(sap, skb->dev->ifindex);
345 403
346 read_lock_bh(&sap->sk_list.lock); 404 spin_lock_bh(&sap->sk_lock);
347 sk_for_each(sk, node, &sap->sk_list.list) { 405 hlist_for_each_entry(llc, node, dev_hb, dev_hash_node) {
348 struct llc_sock *llc = llc_sk(sk);
349 struct sk_buff *skb1;
350 406
351 if (sk->sk_type != SOCK_DGRAM) 407 sk = &llc->sk;
352 continue;
353 408
354 if (llc->laddr.lsap != laddr->lsap) 409 if (!llc_mcast_match(sap, laddr, skb, sk))
355 continue; 410 continue;
356 411
357 if (llc->dev != skb->dev)
358 continue;
359
360 skb1 = skb_clone(skb, GFP_ATOMIC);
361 if (!skb1)
362 break;
363
364 sock_hold(sk); 412 sock_hold(sk);
365 llc_sap_rcv(sap, skb1, sk); 413 if (i < count)
366 sock_put(sk); 414 stack[i++] = sk;
415 else {
416 llc_do_mcast(sap, skb, stack, i);
417 i = 0;
418 }
367 } 419 }
368 read_unlock_bh(&sap->sk_list.lock); 420 spin_unlock_bh(&sap->sk_lock);
421
422 llc_do_mcast(sap, skb, stack, i);
369} 423}
370 424
371 425
diff --git a/net/llc/llc_station.c b/net/llc/llc_station.c
index 83da13339490..e4dae0244d76 100644
--- a/net/llc/llc_station.c
+++ b/net/llc/llc_station.c
@@ -13,6 +13,7 @@
13 */ 13 */
14#include <linux/init.h> 14#include <linux/init.h>
15#include <linux/module.h> 15#include <linux/module.h>
16#include <linux/slab.h>
16#include <net/llc.h> 17#include <net/llc.h>
17#include <net/llc_sap.h> 18#include <net/llc_sap.h>
18#include <net/llc_conn.h> 19#include <net/llc_conn.h>
diff --git a/net/llc/sysctl_net_llc.c b/net/llc/sysctl_net_llc.c
index 57b9304d444c..e2ebe3586263 100644
--- a/net/llc/sysctl_net_llc.c
+++ b/net/llc/sysctl_net_llc.c
@@ -15,86 +15,73 @@
15 15
16static struct ctl_table llc2_timeout_table[] = { 16static struct ctl_table llc2_timeout_table[] = {
17 { 17 {
18 .ctl_name = NET_LLC2_ACK_TIMEOUT,
19 .procname = "ack", 18 .procname = "ack",
20 .data = &sysctl_llc2_ack_timeout, 19 .data = &sysctl_llc2_ack_timeout,
21 .maxlen = sizeof(long), 20 .maxlen = sizeof(long),
22 .mode = 0644, 21 .mode = 0644,
23 .proc_handler = proc_dointvec_jiffies, 22 .proc_handler = proc_dointvec_jiffies,
24 .strategy = sysctl_jiffies,
25 }, 23 },
26 { 24 {
27 .ctl_name = NET_LLC2_BUSY_TIMEOUT,
28 .procname = "busy", 25 .procname = "busy",
29 .data = &sysctl_llc2_busy_timeout, 26 .data = &sysctl_llc2_busy_timeout,
30 .maxlen = sizeof(long), 27 .maxlen = sizeof(long),
31 .mode = 0644, 28 .mode = 0644,
32 .proc_handler = proc_dointvec_jiffies, 29 .proc_handler = proc_dointvec_jiffies,
33 .strategy = sysctl_jiffies,
34 }, 30 },
35 { 31 {
36 .ctl_name = NET_LLC2_P_TIMEOUT,
37 .procname = "p", 32 .procname = "p",
38 .data = &sysctl_llc2_p_timeout, 33 .data = &sysctl_llc2_p_timeout,
39 .maxlen = sizeof(long), 34 .maxlen = sizeof(long),
40 .mode = 0644, 35 .mode = 0644,
41 .proc_handler = proc_dointvec_jiffies, 36 .proc_handler = proc_dointvec_jiffies,
42 .strategy = sysctl_jiffies,
43 }, 37 },
44 { 38 {
45 .ctl_name = NET_LLC2_REJ_TIMEOUT,
46 .procname = "rej", 39 .procname = "rej",
47 .data = &sysctl_llc2_rej_timeout, 40 .data = &sysctl_llc2_rej_timeout,
48 .maxlen = sizeof(long), 41 .maxlen = sizeof(long),
49 .mode = 0644, 42 .mode = 0644,
50 .proc_handler = proc_dointvec_jiffies, 43 .proc_handler = proc_dointvec_jiffies,
51 .strategy = sysctl_jiffies,
52 }, 44 },
53 { 0 }, 45 { },
54}; 46};
55 47
56static struct ctl_table llc_station_table[] = { 48static struct ctl_table llc_station_table[] = {
57 { 49 {
58 .ctl_name = NET_LLC_STATION_ACK_TIMEOUT,
59 .procname = "ack_timeout", 50 .procname = "ack_timeout",
60 .data = &sysctl_llc_station_ack_timeout, 51 .data = &sysctl_llc_station_ack_timeout,
61 .maxlen = sizeof(long), 52 .maxlen = sizeof(long),
62 .mode = 0644, 53 .mode = 0644,
63 .proc_handler = proc_dointvec_jiffies, 54 .proc_handler = proc_dointvec_jiffies,
64 .strategy = sysctl_jiffies,
65 }, 55 },
66 { 0 }, 56 { },
67}; 57};
68 58
69static struct ctl_table llc2_dir_timeout_table[] = { 59static struct ctl_table llc2_dir_timeout_table[] = {
70 { 60 {
71 .ctl_name = NET_LLC2,
72 .procname = "timeout", 61 .procname = "timeout",
73 .mode = 0555, 62 .mode = 0555,
74 .child = llc2_timeout_table, 63 .child = llc2_timeout_table,
75 }, 64 },
76 { 0 }, 65 { },
77}; 66};
78 67
79static struct ctl_table llc_table[] = { 68static struct ctl_table llc_table[] = {
80 { 69 {
81 .ctl_name = NET_LLC2,
82 .procname = "llc2", 70 .procname = "llc2",
83 .mode = 0555, 71 .mode = 0555,
84 .child = llc2_dir_timeout_table, 72 .child = llc2_dir_timeout_table,
85 }, 73 },
86 { 74 {
87 .ctl_name = NET_LLC_STATION,
88 .procname = "station", 75 .procname = "station",
89 .mode = 0555, 76 .mode = 0555,
90 .child = llc_station_table, 77 .child = llc_station_table,
91 }, 78 },
92 { 0 }, 79 { },
93}; 80};
94 81
95static struct ctl_path llc_path[] = { 82static struct ctl_path llc_path[] = {
96 { .procname = "net", .ctl_name = CTL_NET, }, 83 { .procname = "net", },
97 { .procname = "llc", .ctl_name = NET_LLC, }, 84 { .procname = "llc", },
98 { } 85 { }
99}; 86};
100 87
diff --git a/net/mac80211/Kconfig b/net/mac80211/Kconfig
index 4d5543af3123..a952b7f8c648 100644
--- a/net/mac80211/Kconfig
+++ b/net/mac80211/Kconfig
@@ -96,18 +96,6 @@ menuconfig MAC80211_DEBUG_MENU
96 ---help--- 96 ---help---
97 This option collects various mac80211 debug settings. 97 This option collects various mac80211 debug settings.
98 98
99config MAC80211_DEBUG_PACKET_ALIGNMENT
100 bool "Enable packet alignment debugging"
101 depends on MAC80211_DEBUG_MENU
102 ---help---
103 This option is recommended for driver authors and strongly
104 discouraged for everybody else, it will trigger a warning
105 when a driver hands mac80211 a buffer that is aligned in
106 a way that will cause problems with the IP stack on some
107 architectures.
108
109 Say N unless you're writing a mac80211 based driver.
110
111config MAC80211_NOINLINE 99config MAC80211_NOINLINE
112 bool "Do not inline TX/RX handlers" 100 bool "Do not inline TX/RX handlers"
113 depends on MAC80211_DEBUG_MENU 101 depends on MAC80211_DEBUG_MENU
@@ -194,6 +182,19 @@ config MAC80211_VERBOSE_MPL_DEBUG
194 182
195 Do not select this option. 183 Do not select this option.
196 184
185config MAC80211_VERBOSE_MHWMP_DEBUG
186 bool "Verbose mesh HWMP routing debugging"
187 depends on MAC80211_DEBUG_MENU
188 depends on MAC80211_MESH
189 ---help---
190 Selecting this option causes mac80211 to print out very
191 verbose mesh routing (HWMP) debugging messages (when mac80211
192 is taking part in a mesh network).
193 It should not be selected on production systems as those
194 messages are remotely triggerable.
195
196 Do not select this option.
197
197config MAC80211_DEBUG_COUNTERS 198config MAC80211_DEBUG_COUNTERS
198 bool "Extra statistics for TX/RX debugging" 199 bool "Extra statistics for TX/RX debugging"
199 depends on MAC80211_DEBUG_MENU 200 depends on MAC80211_DEBUG_MENU
diff --git a/net/mac80211/Makefile b/net/mac80211/Makefile
index 9f3cf7129324..04420291e7ad 100644
--- a/net/mac80211/Makefile
+++ b/net/mac80211/Makefile
@@ -2,14 +2,14 @@ obj-$(CONFIG_MAC80211) += mac80211.o
2 2
3# mac80211 objects 3# mac80211 objects
4mac80211-y := \ 4mac80211-y := \
5 main.o \ 5 main.o status.o \
6 sta_info.o \ 6 sta_info.o \
7 wep.o \ 7 wep.o \
8 wpa.o \ 8 wpa.o \
9 scan.o \ 9 scan.o offchannel.o \
10 ht.o agg-tx.o agg-rx.o \ 10 ht.o agg-tx.o agg-rx.o \
11 ibss.o \ 11 ibss.o \
12 mlme.o \ 12 mlme.o work.o \
13 iface.o \ 13 iface.o \
14 rate.o \ 14 rate.o \
15 michael.o \ 15 michael.o \
diff --git a/net/mac80211/agg-rx.c b/net/mac80211/agg-rx.c
index ce8e0e772bab..f9516a27e233 100644
--- a/net/mac80211/agg-rx.c
+++ b/net/mac80211/agg-rx.c
@@ -14,6 +14,7 @@
14 */ 14 */
15 15
16#include <linux/ieee80211.h> 16#include <linux/ieee80211.h>
17#include <linux/slab.h>
17#include <net/mac80211.h> 18#include <net/mac80211.h>
18#include "ieee80211_i.h" 19#include "ieee80211_i.h"
19#include "driver-ops.h" 20#include "driver-ops.h"
@@ -41,7 +42,7 @@ void __ieee80211_stop_rx_ba_session(struct sta_info *sta, u16 tid,
41 sta->sta.addr, tid); 42 sta->sta.addr, tid);
42#endif /* CONFIG_MAC80211_HT_DEBUG */ 43#endif /* CONFIG_MAC80211_HT_DEBUG */
43 44
44 if (drv_ampdu_action(local, IEEE80211_AMPDU_RX_STOP, 45 if (drv_ampdu_action(local, sta->sdata, IEEE80211_AMPDU_RX_STOP,
45 &sta->sta, tid, NULL)) 46 &sta->sta, tid, NULL))
46 printk(KERN_DEBUG "HW problem - can not stop rx " 47 printk(KERN_DEBUG "HW problem - can not stop rx "
47 "aggregation for tid %d\n", tid); 48 "aggregation for tid %d\n", tid);
@@ -82,12 +83,11 @@ void __ieee80211_stop_rx_ba_session(struct sta_info *sta, u16 tid,
82void ieee80211_sta_stop_rx_ba_session(struct ieee80211_sub_if_data *sdata, u8 *ra, u16 tid, 83void ieee80211_sta_stop_rx_ba_session(struct ieee80211_sub_if_data *sdata, u8 *ra, u16 tid,
83 u16 initiator, u16 reason) 84 u16 initiator, u16 reason)
84{ 85{
85 struct ieee80211_local *local = sdata->local;
86 struct sta_info *sta; 86 struct sta_info *sta;
87 87
88 rcu_read_lock(); 88 rcu_read_lock();
89 89
90 sta = sta_info_get(local, ra); 90 sta = sta_info_get(sdata, ra);
91 if (!sta) { 91 if (!sta) {
92 rcu_read_unlock(); 92 rcu_read_unlock();
93 return; 93 return;
@@ -135,7 +135,7 @@ static void ieee80211_send_addba_resp(struct ieee80211_sub_if_data *sdata, u8 *d
135 135
136 if (!skb) { 136 if (!skb) {
137 printk(KERN_DEBUG "%s: failed to allocate buffer " 137 printk(KERN_DEBUG "%s: failed to allocate buffer "
138 "for addba resp frame\n", sdata->dev->name); 138 "for addba resp frame\n", sdata->name);
139 return; 139 return;
140 } 140 }
141 141
@@ -143,10 +143,10 @@ static void ieee80211_send_addba_resp(struct ieee80211_sub_if_data *sdata, u8 *d
143 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24); 143 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
144 memset(mgmt, 0, 24); 144 memset(mgmt, 0, 24);
145 memcpy(mgmt->da, da, ETH_ALEN); 145 memcpy(mgmt->da, da, ETH_ALEN);
146 memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN); 146 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
147 if (sdata->vif.type == NL80211_IFTYPE_AP || 147 if (sdata->vif.type == NL80211_IFTYPE_AP ||
148 sdata->vif.type == NL80211_IFTYPE_AP_VLAN) 148 sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
149 memcpy(mgmt->bssid, sdata->dev->dev_addr, ETH_ALEN); 149 memcpy(mgmt->bssid, sdata->vif.addr, ETH_ALEN);
150 else if (sdata->vif.type == NL80211_IFTYPE_STATION) 150 else if (sdata->vif.type == NL80211_IFTYPE_STATION)
151 memcpy(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN); 151 memcpy(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN);
152 152
@@ -166,7 +166,7 @@ static void ieee80211_send_addba_resp(struct ieee80211_sub_if_data *sdata, u8 *d
166 mgmt->u.action.u.addba_resp.timeout = cpu_to_le16(timeout); 166 mgmt->u.action.u.addba_resp.timeout = cpu_to_le16(timeout);
167 mgmt->u.action.u.addba_resp.status = cpu_to_le16(status); 167 mgmt->u.action.u.addba_resp.status = cpu_to_le16(status);
168 168
169 ieee80211_tx_skb(sdata, skb, 1); 169 ieee80211_tx_skb(sdata, skb);
170} 170}
171 171
172void ieee80211_process_addba_request(struct ieee80211_local *local, 172void ieee80211_process_addba_request(struct ieee80211_local *local,
@@ -206,9 +206,9 @@ void ieee80211_process_addba_request(struct ieee80211_local *local,
206 * check if configuration can support the BA policy 206 * check if configuration can support the BA policy
207 * and if buffer size does not exceeds max value */ 207 * and if buffer size does not exceeds max value */
208 /* XXX: check own ht delayed BA capability?? */ 208 /* XXX: check own ht delayed BA capability?? */
209 if (((ba_policy != 1) 209 if (((ba_policy != 1) &&
210 && (!(sta->sta.ht_cap.cap & IEEE80211_HT_CAP_DELAY_BA))) 210 (!(sta->sta.ht_cap.cap & IEEE80211_HT_CAP_DELAY_BA))) ||
211 || (buf_size > IEEE80211_MAX_AMPDU_BUF)) { 211 (buf_size > IEEE80211_MAX_AMPDU_BUF)) {
212 status = WLAN_STATUS_INVALID_QOS_PARAM; 212 status = WLAN_STATUS_INVALID_QOS_PARAM;
213#ifdef CONFIG_MAC80211_HT_DEBUG 213#ifdef CONFIG_MAC80211_HT_DEBUG
214 if (net_ratelimit()) 214 if (net_ratelimit())
@@ -280,7 +280,7 @@ void ieee80211_process_addba_request(struct ieee80211_local *local,
280 goto end; 280 goto end;
281 } 281 }
282 282
283 ret = drv_ampdu_action(local, IEEE80211_AMPDU_RX_START, 283 ret = drv_ampdu_action(local, sta->sdata, IEEE80211_AMPDU_RX_START,
284 &sta->sta, tid, &start_seq_num); 284 &sta->sta, tid, &start_seq_num);
285#ifdef CONFIG_MAC80211_HT_DEBUG 285#ifdef CONFIG_MAC80211_HT_DEBUG
286 printk(KERN_DEBUG "Rx A-MPDU request on tid %d result %d\n", tid, ret); 286 printk(KERN_DEBUG "Rx A-MPDU request on tid %d result %d\n", tid, ret);
diff --git a/net/mac80211/agg-tx.c b/net/mac80211/agg-tx.c
index 89e238b001de..87782a4bb541 100644
--- a/net/mac80211/agg-tx.c
+++ b/net/mac80211/agg-tx.c
@@ -14,6 +14,7 @@
14 */ 14 */
15 15
16#include <linux/ieee80211.h> 16#include <linux/ieee80211.h>
17#include <linux/slab.h>
17#include <net/mac80211.h> 18#include <net/mac80211.h>
18#include "ieee80211_i.h" 19#include "ieee80211_i.h"
19#include "driver-ops.h" 20#include "driver-ops.h"
@@ -58,17 +59,17 @@ static void ieee80211_send_addba_request(struct ieee80211_sub_if_data *sdata,
58 59
59 if (!skb) { 60 if (!skb) {
60 printk(KERN_ERR "%s: failed to allocate buffer " 61 printk(KERN_ERR "%s: failed to allocate buffer "
61 "for addba request frame\n", sdata->dev->name); 62 "for addba request frame\n", sdata->name);
62 return; 63 return;
63 } 64 }
64 skb_reserve(skb, local->hw.extra_tx_headroom); 65 skb_reserve(skb, local->hw.extra_tx_headroom);
65 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24); 66 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
66 memset(mgmt, 0, 24); 67 memset(mgmt, 0, 24);
67 memcpy(mgmt->da, da, ETH_ALEN); 68 memcpy(mgmt->da, da, ETH_ALEN);
68 memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN); 69 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
69 if (sdata->vif.type == NL80211_IFTYPE_AP || 70 if (sdata->vif.type == NL80211_IFTYPE_AP ||
70 sdata->vif.type == NL80211_IFTYPE_AP_VLAN) 71 sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
71 memcpy(mgmt->bssid, sdata->dev->dev_addr, ETH_ALEN); 72 memcpy(mgmt->bssid, sdata->vif.addr, ETH_ALEN);
72 else if (sdata->vif.type == NL80211_IFTYPE_STATION) 73 else if (sdata->vif.type == NL80211_IFTYPE_STATION)
73 memcpy(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN); 74 memcpy(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN);
74 75
@@ -91,7 +92,7 @@ static void ieee80211_send_addba_request(struct ieee80211_sub_if_data *sdata,
91 mgmt->u.action.u.addba_req.start_seq_num = 92 mgmt->u.action.u.addba_req.start_seq_num =
92 cpu_to_le16(start_seq_num << 4); 93 cpu_to_le16(start_seq_num << 4);
93 94
94 ieee80211_tx_skb(sdata, skb, 1); 95 ieee80211_tx_skb(sdata, skb);
95} 96}
96 97
97void ieee80211_send_bar(struct ieee80211_sub_if_data *sdata, u8 *ra, u16 tid, u16 ssn) 98void ieee80211_send_bar(struct ieee80211_sub_if_data *sdata, u8 *ra, u16 tid, u16 ssn)
@@ -104,7 +105,7 @@ void ieee80211_send_bar(struct ieee80211_sub_if_data *sdata, u8 *ra, u16 tid, u1
104 skb = dev_alloc_skb(sizeof(*bar) + local->hw.extra_tx_headroom); 105 skb = dev_alloc_skb(sizeof(*bar) + local->hw.extra_tx_headroom);
105 if (!skb) { 106 if (!skb) {
106 printk(KERN_ERR "%s: failed to allocate buffer for " 107 printk(KERN_ERR "%s: failed to allocate buffer for "
107 "bar frame\n", sdata->dev->name); 108 "bar frame\n", sdata->name);
108 return; 109 return;
109 } 110 }
110 skb_reserve(skb, local->hw.extra_tx_headroom); 111 skb_reserve(skb, local->hw.extra_tx_headroom);
@@ -113,14 +114,15 @@ void ieee80211_send_bar(struct ieee80211_sub_if_data *sdata, u8 *ra, u16 tid, u1
113 bar->frame_control = cpu_to_le16(IEEE80211_FTYPE_CTL | 114 bar->frame_control = cpu_to_le16(IEEE80211_FTYPE_CTL |
114 IEEE80211_STYPE_BACK_REQ); 115 IEEE80211_STYPE_BACK_REQ);
115 memcpy(bar->ra, ra, ETH_ALEN); 116 memcpy(bar->ra, ra, ETH_ALEN);
116 memcpy(bar->ta, sdata->dev->dev_addr, ETH_ALEN); 117 memcpy(bar->ta, sdata->vif.addr, ETH_ALEN);
117 bar_control |= (u16)IEEE80211_BAR_CTRL_ACK_POLICY_NORMAL; 118 bar_control |= (u16)IEEE80211_BAR_CTRL_ACK_POLICY_NORMAL;
118 bar_control |= (u16)IEEE80211_BAR_CTRL_CBMTID_COMPRESSED_BA; 119 bar_control |= (u16)IEEE80211_BAR_CTRL_CBMTID_COMPRESSED_BA;
119 bar_control |= (u16)(tid << 12); 120 bar_control |= (u16)(tid << 12);
120 bar->control = cpu_to_le16(bar_control); 121 bar->control = cpu_to_le16(bar_control);
121 bar->start_seq_num = cpu_to_le16(ssn); 122 bar->start_seq_num = cpu_to_le16(ssn);
122 123
123 ieee80211_tx_skb(sdata, skb, 0); 124 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
125 ieee80211_tx_skb(sdata, skb);
124} 126}
125 127
126int ___ieee80211_stop_tx_ba_session(struct sta_info *sta, u16 tid, 128int ___ieee80211_stop_tx_ba_session(struct sta_info *sta, u16 tid,
@@ -143,7 +145,8 @@ int ___ieee80211_stop_tx_ba_session(struct sta_info *sta, u16 tid,
143 *state = HT_AGG_STATE_REQ_STOP_BA_MSK | 145 *state = HT_AGG_STATE_REQ_STOP_BA_MSK |
144 (initiator << HT_AGG_STATE_INITIATOR_SHIFT); 146 (initiator << HT_AGG_STATE_INITIATOR_SHIFT);
145 147
146 ret = drv_ampdu_action(local, IEEE80211_AMPDU_TX_STOP, 148 ret = drv_ampdu_action(local, sta->sdata,
149 IEEE80211_AMPDU_TX_STOP,
147 &sta->sta, tid, NULL); 150 &sta->sta, tid, NULL);
148 151
149 /* HW shall not deny going back to legacy */ 152 /* HW shall not deny going back to legacy */
@@ -177,10 +180,10 @@ static void sta_addba_resp_timer_expired(unsigned long data)
177 180
178 /* check if the TID waits for addBA response */ 181 /* check if the TID waits for addBA response */
179 spin_lock_bh(&sta->lock); 182 spin_lock_bh(&sta->lock);
180 if ((*state & (HT_ADDBA_REQUESTED_MSK | HT_ADDBA_RECEIVED_MSK)) != 183 if ((*state & (HT_ADDBA_REQUESTED_MSK | HT_ADDBA_RECEIVED_MSK |
184 HT_AGG_STATE_REQ_STOP_BA_MSK)) !=
181 HT_ADDBA_REQUESTED_MSK) { 185 HT_ADDBA_REQUESTED_MSK) {
182 spin_unlock_bh(&sta->lock); 186 spin_unlock_bh(&sta->lock);
183 *state = HT_AGG_STATE_IDLE;
184#ifdef CONFIG_MAC80211_HT_DEBUG 187#ifdef CONFIG_MAC80211_HT_DEBUG
185 printk(KERN_DEBUG "timer expired on tid %d but we are not " 188 printk(KERN_DEBUG "timer expired on tid %d but we are not "
186 "(or no longer) expecting addBA response there", 189 "(or no longer) expecting addBA response there",
@@ -202,11 +205,11 @@ static inline int ieee80211_ac_from_tid(int tid)
202 return ieee802_1d_to_ac[tid & 7]; 205 return ieee802_1d_to_ac[tid & 7];
203} 206}
204 207
205int ieee80211_start_tx_ba_session(struct ieee80211_hw *hw, u8 *ra, u16 tid) 208int ieee80211_start_tx_ba_session(struct ieee80211_sta *pubsta, u16 tid)
206{ 209{
207 struct ieee80211_local *local = hw_to_local(hw); 210 struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
208 struct sta_info *sta; 211 struct ieee80211_sub_if_data *sdata = sta->sdata;
209 struct ieee80211_sub_if_data *sdata; 212 struct ieee80211_local *local = sdata->local;
210 u8 *state; 213 u8 *state;
211 int ret = 0; 214 int ret = 0;
212 u16 start_seq_num; 215 u16 start_seq_num;
@@ -214,36 +217,32 @@ int ieee80211_start_tx_ba_session(struct ieee80211_hw *hw, u8 *ra, u16 tid)
214 if (WARN_ON(!local->ops->ampdu_action)) 217 if (WARN_ON(!local->ops->ampdu_action))
215 return -EINVAL; 218 return -EINVAL;
216 219
217 if ((tid >= STA_TID_NUM) || !(hw->flags & IEEE80211_HW_AMPDU_AGGREGATION)) 220 if ((tid >= STA_TID_NUM) ||
221 !(local->hw.flags & IEEE80211_HW_AMPDU_AGGREGATION))
218 return -EINVAL; 222 return -EINVAL;
219 223
220#ifdef CONFIG_MAC80211_HT_DEBUG 224#ifdef CONFIG_MAC80211_HT_DEBUG
221 printk(KERN_DEBUG "Open BA session requested for %pM tid %u\n", 225 printk(KERN_DEBUG "Open BA session requested for %pM tid %u\n",
222 ra, tid); 226 pubsta->addr, tid);
223#endif /* CONFIG_MAC80211_HT_DEBUG */ 227#endif /* CONFIG_MAC80211_HT_DEBUG */
224 228
225 rcu_read_lock();
226
227 sta = sta_info_get(local, ra);
228 if (!sta) {
229#ifdef CONFIG_MAC80211_HT_DEBUG
230 printk(KERN_DEBUG "Could not find the station\n");
231#endif
232 ret = -ENOENT;
233 goto unlock;
234 }
235
236 /* 229 /*
237 * The aggregation code is not prepared to handle 230 * The aggregation code is not prepared to handle
238 * anything but STA/AP due to the BSSID handling. 231 * anything but STA/AP due to the BSSID handling.
239 * IBSS could work in the code but isn't supported 232 * IBSS could work in the code but isn't supported
240 * by drivers or the standard. 233 * by drivers or the standard.
241 */ 234 */
242 if (sta->sdata->vif.type != NL80211_IFTYPE_STATION && 235 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
243 sta->sdata->vif.type != NL80211_IFTYPE_AP_VLAN && 236 sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
244 sta->sdata->vif.type != NL80211_IFTYPE_AP) { 237 sdata->vif.type != NL80211_IFTYPE_AP)
245 ret = -EINVAL; 238 return -EINVAL;
246 goto unlock; 239
240 if (test_sta_flags(sta, WLAN_STA_DISASSOC)) {
241#ifdef CONFIG_MAC80211_HT_DEBUG
242 printk(KERN_DEBUG "Disassociation is in progress. "
243 "Denying BA session request\n");
244#endif
245 return -EINVAL;
247 } 246 }
248 247
249 if (test_sta_flags(sta, WLAN_STA_SUSPEND)) { 248 if (test_sta_flags(sta, WLAN_STA_SUSPEND)) {
@@ -251,15 +250,12 @@ int ieee80211_start_tx_ba_session(struct ieee80211_hw *hw, u8 *ra, u16 tid)
251 printk(KERN_DEBUG "Suspend in progress. " 250 printk(KERN_DEBUG "Suspend in progress. "
252 "Denying BA session request\n"); 251 "Denying BA session request\n");
253#endif 252#endif
254 ret = -EINVAL; 253 return -EINVAL;
255 goto unlock;
256 } 254 }
257 255
258 spin_lock_bh(&sta->lock); 256 spin_lock_bh(&sta->lock);
259 spin_lock(&local->ampdu_lock); 257 spin_lock(&local->ampdu_lock);
260 258
261 sdata = sta->sdata;
262
263 /* we have tried too many times, receiver does not want A-MPDU */ 259 /* we have tried too many times, receiver does not want A-MPDU */
264 if (sta->ampdu_mlme.addba_req_num[tid] > HT_AGG_MAX_RETRIES) { 260 if (sta->ampdu_mlme.addba_req_num[tid] > HT_AGG_MAX_RETRIES) {
265 ret = -EBUSY; 261 ret = -EBUSY;
@@ -314,10 +310,10 @@ int ieee80211_start_tx_ba_session(struct ieee80211_hw *hw, u8 *ra, u16 tid)
314 * call back right away, it must see that the flow has begun */ 310 * call back right away, it must see that the flow has begun */
315 *state |= HT_ADDBA_REQUESTED_MSK; 311 *state |= HT_ADDBA_REQUESTED_MSK;
316 312
317 start_seq_num = sta->tid_seq[tid]; 313 start_seq_num = sta->tid_seq[tid] >> 4;
318 314
319 ret = drv_ampdu_action(local, IEEE80211_AMPDU_TX_START, 315 ret = drv_ampdu_action(local, sdata, IEEE80211_AMPDU_TX_START,
320 &sta->sta, tid, &start_seq_num); 316 pubsta, tid, &start_seq_num);
321 317
322 if (ret) { 318 if (ret) {
323#ifdef CONFIG_MAC80211_HT_DEBUG 319#ifdef CONFIG_MAC80211_HT_DEBUG
@@ -342,7 +338,7 @@ int ieee80211_start_tx_ba_session(struct ieee80211_hw *hw, u8 *ra, u16 tid)
342 sta->ampdu_mlme.dialog_token_allocator; 338 sta->ampdu_mlme.dialog_token_allocator;
343 sta->ampdu_mlme.tid_tx[tid]->ssn = start_seq_num; 339 sta->ampdu_mlme.tid_tx[tid]->ssn = start_seq_num;
344 340
345 ieee80211_send_addba_request(sta->sdata, ra, tid, 341 ieee80211_send_addba_request(sdata, pubsta->addr, tid,
346 sta->ampdu_mlme.tid_tx[tid]->dialog_token, 342 sta->ampdu_mlme.tid_tx[tid]->dialog_token,
347 sta->ampdu_mlme.tid_tx[tid]->ssn, 343 sta->ampdu_mlme.tid_tx[tid]->ssn,
348 0x40, 5000); 344 0x40, 5000);
@@ -354,7 +350,7 @@ int ieee80211_start_tx_ba_session(struct ieee80211_hw *hw, u8 *ra, u16 tid)
354#ifdef CONFIG_MAC80211_HT_DEBUG 350#ifdef CONFIG_MAC80211_HT_DEBUG
355 printk(KERN_DEBUG "activated addBA response timer on tid %d\n", tid); 351 printk(KERN_DEBUG "activated addBA response timer on tid %d\n", tid);
356#endif 352#endif
357 goto unlock; 353 return 0;
358 354
359 err_free: 355 err_free:
360 kfree(sta->ampdu_mlme.tid_tx[tid]); 356 kfree(sta->ampdu_mlme.tid_tx[tid]);
@@ -366,8 +362,6 @@ int ieee80211_start_tx_ba_session(struct ieee80211_hw *hw, u8 *ra, u16 tid)
366 err_unlock_sta: 362 err_unlock_sta:
367 spin_unlock(&local->ampdu_lock); 363 spin_unlock(&local->ampdu_lock);
368 spin_unlock_bh(&sta->lock); 364 spin_unlock_bh(&sta->lock);
369 unlock:
370 rcu_read_unlock();
371 return ret; 365 return ret;
372} 366}
373EXPORT_SYMBOL(ieee80211_start_tx_ba_session); 367EXPORT_SYMBOL(ieee80211_start_tx_ba_session);
@@ -434,13 +428,15 @@ static void ieee80211_agg_tx_operational(struct ieee80211_local *local,
434 ieee80211_agg_splice_finish(local, sta, tid); 428 ieee80211_agg_splice_finish(local, sta, tid);
435 spin_unlock(&local->ampdu_lock); 429 spin_unlock(&local->ampdu_lock);
436 430
437 drv_ampdu_action(local, IEEE80211_AMPDU_TX_OPERATIONAL, 431 drv_ampdu_action(local, sta->sdata,
432 IEEE80211_AMPDU_TX_OPERATIONAL,
438 &sta->sta, tid, NULL); 433 &sta->sta, tid, NULL);
439} 434}
440 435
441void ieee80211_start_tx_ba_cb(struct ieee80211_hw *hw, u8 *ra, u16 tid) 436void ieee80211_start_tx_ba_cb(struct ieee80211_vif *vif, u8 *ra, u16 tid)
442{ 437{
443 struct ieee80211_local *local = hw_to_local(hw); 438 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
439 struct ieee80211_local *local = sdata->local;
444 struct sta_info *sta; 440 struct sta_info *sta;
445 u8 *state; 441 u8 *state;
446 442
@@ -453,7 +449,7 @@ void ieee80211_start_tx_ba_cb(struct ieee80211_hw *hw, u8 *ra, u16 tid)
453 } 449 }
454 450
455 rcu_read_lock(); 451 rcu_read_lock();
456 sta = sta_info_get(local, ra); 452 sta = sta_info_get(sdata, ra);
457 if (!sta) { 453 if (!sta) {
458 rcu_read_unlock(); 454 rcu_read_unlock();
459#ifdef CONFIG_MAC80211_HT_DEBUG 455#ifdef CONFIG_MAC80211_HT_DEBUG
@@ -489,10 +485,11 @@ void ieee80211_start_tx_ba_cb(struct ieee80211_hw *hw, u8 *ra, u16 tid)
489} 485}
490EXPORT_SYMBOL(ieee80211_start_tx_ba_cb); 486EXPORT_SYMBOL(ieee80211_start_tx_ba_cb);
491 487
492void ieee80211_start_tx_ba_cb_irqsafe(struct ieee80211_hw *hw, 488void ieee80211_start_tx_ba_cb_irqsafe(struct ieee80211_vif *vif,
493 const u8 *ra, u16 tid) 489 const u8 *ra, u16 tid)
494{ 490{
495 struct ieee80211_local *local = hw_to_local(hw); 491 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
492 struct ieee80211_local *local = sdata->local;
496 struct ieee80211_ra_tid *ra_tid; 493 struct ieee80211_ra_tid *ra_tid;
497 struct sk_buff *skb = dev_alloc_skb(0); 494 struct sk_buff *skb = dev_alloc_skb(0);
498 495
@@ -500,13 +497,14 @@ void ieee80211_start_tx_ba_cb_irqsafe(struct ieee80211_hw *hw,
500#ifdef CONFIG_MAC80211_HT_DEBUG 497#ifdef CONFIG_MAC80211_HT_DEBUG
501 if (net_ratelimit()) 498 if (net_ratelimit())
502 printk(KERN_WARNING "%s: Not enough memory, " 499 printk(KERN_WARNING "%s: Not enough memory, "
503 "dropping start BA session", skb->dev->name); 500 "dropping start BA session", sdata->name);
504#endif 501#endif
505 return; 502 return;
506 } 503 }
507 ra_tid = (struct ieee80211_ra_tid *) &skb->cb; 504 ra_tid = (struct ieee80211_ra_tid *) &skb->cb;
508 memcpy(&ra_tid->ra, ra, ETH_ALEN); 505 memcpy(&ra_tid->ra, ra, ETH_ALEN);
509 ra_tid->tid = tid; 506 ra_tid->tid = tid;
507 ra_tid->vif = vif;
510 508
511 skb->pkt_type = IEEE80211_ADDBA_MSG; 509 skb->pkt_type = IEEE80211_ADDBA_MSG;
512 skb_queue_tail(&local->skb_queue, skb); 510 skb_queue_tail(&local->skb_queue, skb);
@@ -536,13 +534,12 @@ int __ieee80211_stop_tx_ba_session(struct sta_info *sta, u16 tid,
536 return ret; 534 return ret;
537} 535}
538 536
539int ieee80211_stop_tx_ba_session(struct ieee80211_hw *hw, 537int ieee80211_stop_tx_ba_session(struct ieee80211_sta *pubsta, u16 tid,
540 u8 *ra, u16 tid,
541 enum ieee80211_back_parties initiator) 538 enum ieee80211_back_parties initiator)
542{ 539{
543 struct ieee80211_local *local = hw_to_local(hw); 540 struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
544 struct sta_info *sta; 541 struct ieee80211_sub_if_data *sdata = sta->sdata;
545 int ret = 0; 542 struct ieee80211_local *local = sdata->local;
546 543
547 if (!local->ops->ampdu_action) 544 if (!local->ops->ampdu_action)
548 return -EINVAL; 545 return -EINVAL;
@@ -550,22 +547,14 @@ int ieee80211_stop_tx_ba_session(struct ieee80211_hw *hw,
550 if (tid >= STA_TID_NUM) 547 if (tid >= STA_TID_NUM)
551 return -EINVAL; 548 return -EINVAL;
552 549
553 rcu_read_lock(); 550 return __ieee80211_stop_tx_ba_session(sta, tid, initiator);
554 sta = sta_info_get(local, ra);
555 if (!sta) {
556 rcu_read_unlock();
557 return -ENOENT;
558 }
559
560 ret = __ieee80211_stop_tx_ba_session(sta, tid, initiator);
561 rcu_read_unlock();
562 return ret;
563} 551}
564EXPORT_SYMBOL(ieee80211_stop_tx_ba_session); 552EXPORT_SYMBOL(ieee80211_stop_tx_ba_session);
565 553
566void ieee80211_stop_tx_ba_cb(struct ieee80211_hw *hw, u8 *ra, u8 tid) 554void ieee80211_stop_tx_ba_cb(struct ieee80211_vif *vif, u8 *ra, u8 tid)
567{ 555{
568 struct ieee80211_local *local = hw_to_local(hw); 556 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
557 struct ieee80211_local *local = sdata->local;
569 struct sta_info *sta; 558 struct sta_info *sta;
570 u8 *state; 559 u8 *state;
571 560
@@ -583,7 +572,7 @@ void ieee80211_stop_tx_ba_cb(struct ieee80211_hw *hw, u8 *ra, u8 tid)
583#endif /* CONFIG_MAC80211_HT_DEBUG */ 572#endif /* CONFIG_MAC80211_HT_DEBUG */
584 573
585 rcu_read_lock(); 574 rcu_read_lock();
586 sta = sta_info_get(local, ra); 575 sta = sta_info_get(sdata, ra);
587 if (!sta) { 576 if (!sta) {
588#ifdef CONFIG_MAC80211_HT_DEBUG 577#ifdef CONFIG_MAC80211_HT_DEBUG
589 printk(KERN_DEBUG "Could not find station: %pM\n", ra); 578 printk(KERN_DEBUG "Could not find station: %pM\n", ra);
@@ -628,10 +617,11 @@ void ieee80211_stop_tx_ba_cb(struct ieee80211_hw *hw, u8 *ra, u8 tid)
628} 617}
629EXPORT_SYMBOL(ieee80211_stop_tx_ba_cb); 618EXPORT_SYMBOL(ieee80211_stop_tx_ba_cb);
630 619
631void ieee80211_stop_tx_ba_cb_irqsafe(struct ieee80211_hw *hw, 620void ieee80211_stop_tx_ba_cb_irqsafe(struct ieee80211_vif *vif,
632 const u8 *ra, u16 tid) 621 const u8 *ra, u16 tid)
633{ 622{
634 struct ieee80211_local *local = hw_to_local(hw); 623 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
624 struct ieee80211_local *local = sdata->local;
635 struct ieee80211_ra_tid *ra_tid; 625 struct ieee80211_ra_tid *ra_tid;
636 struct sk_buff *skb = dev_alloc_skb(0); 626 struct sk_buff *skb = dev_alloc_skb(0);
637 627
@@ -639,13 +629,14 @@ void ieee80211_stop_tx_ba_cb_irqsafe(struct ieee80211_hw *hw,
639#ifdef CONFIG_MAC80211_HT_DEBUG 629#ifdef CONFIG_MAC80211_HT_DEBUG
640 if (net_ratelimit()) 630 if (net_ratelimit())
641 printk(KERN_WARNING "%s: Not enough memory, " 631 printk(KERN_WARNING "%s: Not enough memory, "
642 "dropping stop BA session", skb->dev->name); 632 "dropping stop BA session", sdata->name);
643#endif 633#endif
644 return; 634 return;
645 } 635 }
646 ra_tid = (struct ieee80211_ra_tid *) &skb->cb; 636 ra_tid = (struct ieee80211_ra_tid *) &skb->cb;
647 memcpy(&ra_tid->ra, ra, ETH_ALEN); 637 memcpy(&ra_tid->ra, ra, ETH_ALEN);
648 ra_tid->tid = tid; 638 ra_tid->tid = tid;
639 ra_tid->vif = vif;
649 640
650 skb->pkt_type = IEEE80211_DELBA_MSG; 641 skb->pkt_type = IEEE80211_DELBA_MSG;
651 skb_queue_tail(&local->skb_queue, skb); 642 skb_queue_tail(&local->skb_queue, skb);
diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
index 7b5131bd6fa1..edc872e22c9b 100644
--- a/net/mac80211/cfg.c
+++ b/net/mac80211/cfg.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * mac80211 configuration hooks for cfg80211 2 * mac80211 configuration hooks for cfg80211
3 * 3 *
4 * Copyright 2006, 2007 Johannes Berg <johannes@sipsolutions.net> 4 * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
5 * 5 *
6 * This file is GPLv2 as found in COPYING. 6 * This file is GPLv2 as found in COPYING.
7 */ 7 */
@@ -9,6 +9,7 @@
9#include <linux/ieee80211.h> 9#include <linux/ieee80211.h>
10#include <linux/nl80211.h> 10#include <linux/nl80211.h>
11#include <linux/rtnetlink.h> 11#include <linux/rtnetlink.h>
12#include <linux/slab.h>
12#include <net/net_namespace.h> 13#include <net/net_namespace.h>
13#include <linux/rcupdate.h> 14#include <linux/rcupdate.h>
14#include <net/cfg80211.h> 15#include <net/cfg80211.h>
@@ -36,6 +37,15 @@ static bool nl80211_type_check(enum nl80211_iftype type)
36 } 37 }
37} 38}
38 39
40static bool nl80211_params_check(enum nl80211_iftype type,
41 struct vif_params *params)
42{
43 if (!nl80211_type_check(type))
44 return false;
45
46 return true;
47}
48
39static int ieee80211_add_iface(struct wiphy *wiphy, char *name, 49static int ieee80211_add_iface(struct wiphy *wiphy, char *name,
40 enum nl80211_iftype type, u32 *flags, 50 enum nl80211_iftype type, u32 *flags,
41 struct vif_params *params) 51 struct vif_params *params)
@@ -45,7 +55,7 @@ static int ieee80211_add_iface(struct wiphy *wiphy, char *name,
45 struct ieee80211_sub_if_data *sdata; 55 struct ieee80211_sub_if_data *sdata;
46 int err; 56 int err;
47 57
48 if (!nl80211_type_check(type)) 58 if (!nl80211_params_check(type, params))
49 return -EINVAL; 59 return -EINVAL;
50 60
51 err = ieee80211_if_add(local, name, &dev, type, params); 61 err = ieee80211_if_add(local, name, &dev, type, params);
@@ -69,17 +79,15 @@ static int ieee80211_change_iface(struct wiphy *wiphy,
69 enum nl80211_iftype type, u32 *flags, 79 enum nl80211_iftype type, u32 *flags,
70 struct vif_params *params) 80 struct vif_params *params)
71{ 81{
72 struct ieee80211_sub_if_data *sdata; 82 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
73 int ret; 83 int ret;
74 84
75 if (netif_running(dev)) 85 if (ieee80211_sdata_running(sdata))
76 return -EBUSY; 86 return -EBUSY;
77 87
78 if (!nl80211_type_check(type)) 88 if (!nl80211_params_check(type, params))
79 return -EINVAL; 89 return -EINVAL;
80 90
81 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
82
83 ret = ieee80211_if_change_type(sdata, type); 91 ret = ieee80211_if_change_type(sdata, type);
84 if (ret) 92 if (ret)
85 return ret; 93 return ret;
@@ -92,6 +100,13 @@ static int ieee80211_change_iface(struct wiphy *wiphy,
92 if (sdata->vif.type != NL80211_IFTYPE_MONITOR || !flags) 100 if (sdata->vif.type != NL80211_IFTYPE_MONITOR || !flags)
93 return 0; 101 return 0;
94 102
103 if (type == NL80211_IFTYPE_AP_VLAN &&
104 params && params->use_4addr == 0)
105 rcu_assign_pointer(sdata->u.vlan.sta, NULL);
106 else if (type == NL80211_IFTYPE_STATION &&
107 params && params->use_4addr >= 0)
108 sdata->u.mgd.use_4addr = params->use_4addr;
109
95 sdata->u.mntr_flags = *flags; 110 sdata->u.mntr_flags = *flags;
96 return 0; 111 return 0;
97} 112}
@@ -134,7 +149,7 @@ static int ieee80211_add_key(struct wiphy *wiphy, struct net_device *dev,
134 rcu_read_lock(); 149 rcu_read_lock();
135 150
136 if (mac_addr) { 151 if (mac_addr) {
137 sta = sta_info_get(sdata->local, mac_addr); 152 sta = sta_info_get_bss(sdata, mac_addr);
138 if (!sta) { 153 if (!sta) {
139 ieee80211_key_free(key); 154 ieee80211_key_free(key);
140 err = -ENOENT; 155 err = -ENOENT;
@@ -165,7 +180,7 @@ static int ieee80211_del_key(struct wiphy *wiphy, struct net_device *dev,
165 if (mac_addr) { 180 if (mac_addr) {
166 ret = -ENOENT; 181 ret = -ENOENT;
167 182
168 sta = sta_info_get(sdata->local, mac_addr); 183 sta = sta_info_get_bss(sdata, mac_addr);
169 if (!sta) 184 if (!sta)
170 goto out_unlock; 185 goto out_unlock;
171 186
@@ -212,7 +227,7 @@ static int ieee80211_get_key(struct wiphy *wiphy, struct net_device *dev,
212 rcu_read_lock(); 227 rcu_read_lock();
213 228
214 if (mac_addr) { 229 if (mac_addr) {
215 sta = sta_info_get(sdata->local, mac_addr); 230 sta = sta_info_get_bss(sdata, mac_addr);
216 if (!sta) 231 if (!sta)
217 goto out; 232 goto out;
218 233
@@ -338,7 +353,8 @@ static void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo)
338 sinfo->rx_packets = sta->rx_packets; 353 sinfo->rx_packets = sta->rx_packets;
339 sinfo->tx_packets = sta->tx_packets; 354 sinfo->tx_packets = sta->tx_packets;
340 355
341 if (sta->local->hw.flags & IEEE80211_HW_SIGNAL_DBM) { 356 if ((sta->local->hw.flags & IEEE80211_HW_SIGNAL_DBM) ||
357 (sta->local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC)) {
342 sinfo->filled |= STATION_INFO_SIGNAL; 358 sinfo->filled |= STATION_INFO_SIGNAL;
343 sinfo->signal = (s8)sta->last_signal; 359 sinfo->signal = (s8)sta->last_signal;
344 } 360 }
@@ -377,13 +393,13 @@ static void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo)
377static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev, 393static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
378 int idx, u8 *mac, struct station_info *sinfo) 394 int idx, u8 *mac, struct station_info *sinfo)
379{ 395{
380 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); 396 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
381 struct sta_info *sta; 397 struct sta_info *sta;
382 int ret = -ENOENT; 398 int ret = -ENOENT;
383 399
384 rcu_read_lock(); 400 rcu_read_lock();
385 401
386 sta = sta_info_get_by_idx(local, idx, dev); 402 sta = sta_info_get_by_idx(sdata, idx);
387 if (sta) { 403 if (sta) {
388 ret = 0; 404 ret = 0;
389 memcpy(mac, sta->sta.addr, ETH_ALEN); 405 memcpy(mac, sta->sta.addr, ETH_ALEN);
@@ -398,15 +414,13 @@ static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
398static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev, 414static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev,
399 u8 *mac, struct station_info *sinfo) 415 u8 *mac, struct station_info *sinfo)
400{ 416{
401 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); 417 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
402 struct sta_info *sta; 418 struct sta_info *sta;
403 int ret = -ENOENT; 419 int ret = -ENOENT;
404 420
405 rcu_read_lock(); 421 rcu_read_lock();
406 422
407 /* XXX: verify sta->dev == dev */ 423 sta = sta_info_get_bss(sdata, mac);
408
409 sta = sta_info_get(local, mac);
410 if (sta) { 424 if (sta) {
411 ret = 0; 425 ret = 0;
412 sta_set_sinfo(sta, sinfo); 426 sta_set_sinfo(sta, sinfo);
@@ -502,6 +516,8 @@ static int ieee80211_config_beacon(struct ieee80211_sub_if_data *sdata,
502 if (old) 516 if (old)
503 memcpy(new->tail, old->tail, new_tail_len); 517 memcpy(new->tail, old->tail, new_tail_len);
504 518
519 sdata->vif.bss_conf.dtim_period = new->dtim_period;
520
505 rcu_assign_pointer(sdata->u.ap.beacon, new); 521 rcu_assign_pointer(sdata->u.ap.beacon, new);
506 522
507 synchronize_rcu(); 523 synchronize_rcu();
@@ -715,7 +731,7 @@ static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
715 } else 731 } else
716 sdata = IEEE80211_DEV_TO_SUB_IF(dev); 732 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
717 733
718 if (compare_ether_addr(mac, dev->dev_addr) == 0) 734 if (compare_ether_addr(mac, sdata->vif.addr) == 0)
719 return -EINVAL; 735 return -EINVAL;
720 736
721 if (is_multicast_ether_addr(mac)) 737 if (is_multicast_ether_addr(mac))
@@ -734,17 +750,8 @@ static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
734 layer2_update = sdata->vif.type == NL80211_IFTYPE_AP_VLAN || 750 layer2_update = sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
735 sdata->vif.type == NL80211_IFTYPE_AP; 751 sdata->vif.type == NL80211_IFTYPE_AP;
736 752
737 rcu_read_lock(); 753 err = sta_info_insert_rcu(sta);
738
739 err = sta_info_insert(sta);
740 if (err) { 754 if (err) {
741 /* STA has been freed */
742 if (err == -EEXIST && layer2_update) {
743 /* Need to update layer 2 devices on reassociation */
744 sta = sta_info_get(local, mac);
745 if (sta)
746 ieee80211_send_layer2_update(sta);
747 }
748 rcu_read_unlock(); 755 rcu_read_unlock();
749 return err; 756 return err;
750 } 757 }
@@ -762,27 +769,13 @@ static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
762{ 769{
763 struct ieee80211_local *local = wiphy_priv(wiphy); 770 struct ieee80211_local *local = wiphy_priv(wiphy);
764 struct ieee80211_sub_if_data *sdata; 771 struct ieee80211_sub_if_data *sdata;
765 struct sta_info *sta;
766 772
767 sdata = IEEE80211_DEV_TO_SUB_IF(dev); 773 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
768 774
769 if (mac) { 775 if (mac)
770 rcu_read_lock(); 776 return sta_info_destroy_addr_bss(sdata, mac);
771
772 /* XXX: get sta belonging to dev */
773 sta = sta_info_get(local, mac);
774 if (!sta) {
775 rcu_read_unlock();
776 return -ENOENT;
777 }
778
779 sta_info_unlink(&sta);
780 rcu_read_unlock();
781
782 sta_info_destroy(sta);
783 } else
784 sta_info_flush(local, sdata);
785 777
778 sta_info_flush(local, sdata);
786 return 0; 779 return 0;
787} 780}
788 781
@@ -791,14 +784,14 @@ static int ieee80211_change_station(struct wiphy *wiphy,
791 u8 *mac, 784 u8 *mac,
792 struct station_parameters *params) 785 struct station_parameters *params)
793{ 786{
787 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
794 struct ieee80211_local *local = wiphy_priv(wiphy); 788 struct ieee80211_local *local = wiphy_priv(wiphy);
795 struct sta_info *sta; 789 struct sta_info *sta;
796 struct ieee80211_sub_if_data *vlansdata; 790 struct ieee80211_sub_if_data *vlansdata;
797 791
798 rcu_read_lock(); 792 rcu_read_lock();
799 793
800 /* XXX: get sta belonging to dev */ 794 sta = sta_info_get_bss(sdata, mac);
801 sta = sta_info_get(local, mac);
802 if (!sta) { 795 if (!sta) {
803 rcu_read_unlock(); 796 rcu_read_unlock();
804 return -ENOENT; 797 return -ENOENT;
@@ -813,6 +806,15 @@ static int ieee80211_change_station(struct wiphy *wiphy,
813 return -EINVAL; 806 return -EINVAL;
814 } 807 }
815 808
809 if (params->vlan->ieee80211_ptr->use_4addr) {
810 if (vlansdata->u.vlan.sta) {
811 rcu_read_unlock();
812 return -EBUSY;
813 }
814
815 rcu_assign_pointer(vlansdata->u.vlan.sta, sta);
816 }
817
816 sta->sdata = vlansdata; 818 sta->sdata = vlansdata;
817 ieee80211_send_layer2_update(sta); 819 ieee80211_send_layer2_update(sta);
818 } 820 }
@@ -828,7 +830,6 @@ static int ieee80211_change_station(struct wiphy *wiphy,
828static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev, 830static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
829 u8 *dst, u8 *next_hop) 831 u8 *dst, u8 *next_hop)
830{ 832{
831 struct ieee80211_local *local = wiphy_priv(wiphy);
832 struct ieee80211_sub_if_data *sdata; 833 struct ieee80211_sub_if_data *sdata;
833 struct mesh_path *mpath; 834 struct mesh_path *mpath;
834 struct sta_info *sta; 835 struct sta_info *sta;
@@ -837,7 +838,7 @@ static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
837 sdata = IEEE80211_DEV_TO_SUB_IF(dev); 838 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
838 839
839 rcu_read_lock(); 840 rcu_read_lock();
840 sta = sta_info_get(local, next_hop); 841 sta = sta_info_get(sdata, next_hop);
841 if (!sta) { 842 if (!sta) {
842 rcu_read_unlock(); 843 rcu_read_unlock();
843 return -ENOENT; 844 return -ENOENT;
@@ -876,7 +877,6 @@ static int ieee80211_change_mpath(struct wiphy *wiphy,
876 struct net_device *dev, 877 struct net_device *dev,
877 u8 *dst, u8 *next_hop) 878 u8 *dst, u8 *next_hop)
878{ 879{
879 struct ieee80211_local *local = wiphy_priv(wiphy);
880 struct ieee80211_sub_if_data *sdata; 880 struct ieee80211_sub_if_data *sdata;
881 struct mesh_path *mpath; 881 struct mesh_path *mpath;
882 struct sta_info *sta; 882 struct sta_info *sta;
@@ -885,7 +885,7 @@ static int ieee80211_change_mpath(struct wiphy *wiphy,
885 885
886 rcu_read_lock(); 886 rcu_read_lock();
887 887
888 sta = sta_info_get(local, next_hop); 888 sta = sta_info_get(sdata, next_hop);
889 if (!sta) { 889 if (!sta) {
890 rcu_read_unlock(); 890 rcu_read_unlock();
891 return -ENOENT; 891 return -ENOENT;
@@ -914,7 +914,7 @@ static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
914 pinfo->generation = mesh_paths_generation; 914 pinfo->generation = mesh_paths_generation;
915 915
916 pinfo->filled = MPATH_INFO_FRAME_QLEN | 916 pinfo->filled = MPATH_INFO_FRAME_QLEN |
917 MPATH_INFO_DSN | 917 MPATH_INFO_SN |
918 MPATH_INFO_METRIC | 918 MPATH_INFO_METRIC |
919 MPATH_INFO_EXPTIME | 919 MPATH_INFO_EXPTIME |
920 MPATH_INFO_DISCOVERY_TIMEOUT | 920 MPATH_INFO_DISCOVERY_TIMEOUT |
@@ -922,7 +922,7 @@ static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
922 MPATH_INFO_FLAGS; 922 MPATH_INFO_FLAGS;
923 923
924 pinfo->frame_qlen = mpath->frame_queue.qlen; 924 pinfo->frame_qlen = mpath->frame_queue.qlen;
925 pinfo->dsn = mpath->dsn; 925 pinfo->sn = mpath->sn;
926 pinfo->metric = mpath->metric; 926 pinfo->metric = mpath->metric;
927 if (time_before(jiffies, mpath->exp_time)) 927 if (time_before(jiffies, mpath->exp_time))
928 pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies); 928 pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies);
@@ -934,8 +934,8 @@ static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
934 pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE; 934 pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE;
935 if (mpath->flags & MESH_PATH_RESOLVING) 935 if (mpath->flags & MESH_PATH_RESOLVING)
936 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING; 936 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
937 if (mpath->flags & MESH_PATH_DSN_VALID) 937 if (mpath->flags & MESH_PATH_SN_VALID)
938 pinfo->flags |= NL80211_MPATH_FLAG_DSN_VALID; 938 pinfo->flags |= NL80211_MPATH_FLAG_SN_VALID;
939 if (mpath->flags & MESH_PATH_FIXED) 939 if (mpath->flags & MESH_PATH_FIXED)
940 pinfo->flags |= NL80211_MPATH_FLAG_FIXED; 940 pinfo->flags |= NL80211_MPATH_FLAG_FIXED;
941 if (mpath->flags & MESH_PATH_RESOLVING) 941 if (mpath->flags & MESH_PATH_RESOLVING)
@@ -1008,7 +1008,10 @@ static int ieee80211_set_mesh_params(struct wiphy *wiphy,
1008{ 1008{
1009 struct mesh_config *conf; 1009 struct mesh_config *conf;
1010 struct ieee80211_sub_if_data *sdata; 1010 struct ieee80211_sub_if_data *sdata;
1011 struct ieee80211_if_mesh *ifmsh;
1012
1011 sdata = IEEE80211_DEV_TO_SUB_IF(dev); 1013 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1014 ifmsh = &sdata->u.mesh;
1012 1015
1013 /* Set the config options which we are interested in setting */ 1016 /* Set the config options which we are interested in setting */
1014 conf = &(sdata->u.mesh.mshcfg); 1017 conf = &(sdata->u.mesh.mshcfg);
@@ -1043,6 +1046,10 @@ static int ieee80211_set_mesh_params(struct wiphy *wiphy,
1043 mask)) 1046 mask))
1044 conf->dot11MeshHWMPnetDiameterTraversalTime = 1047 conf->dot11MeshHWMPnetDiameterTraversalTime =
1045 nconf->dot11MeshHWMPnetDiameterTraversalTime; 1048 nconf->dot11MeshHWMPnetDiameterTraversalTime;
1049 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOTMODE, mask)) {
1050 conf->dot11MeshHWMPRootMode = nconf->dot11MeshHWMPRootMode;
1051 ieee80211_mesh_root_setup(ifmsh);
1052 }
1046 return 0; 1053 return 0;
1047} 1054}
1048 1055
@@ -1066,6 +1073,13 @@ static int ieee80211_change_bss(struct wiphy *wiphy,
1066 params->use_short_preamble; 1073 params->use_short_preamble;
1067 changed |= BSS_CHANGED_ERP_PREAMBLE; 1074 changed |= BSS_CHANGED_ERP_PREAMBLE;
1068 } 1075 }
1076
1077 if (!sdata->vif.bss_conf.use_short_slot &&
1078 sdata->local->hw.conf.channel->band == IEEE80211_BAND_5GHZ) {
1079 sdata->vif.bss_conf.use_short_slot = true;
1080 changed |= BSS_CHANGED_ERP_SLOT;
1081 }
1082
1069 if (params->use_short_slot_time >= 0) { 1083 if (params->use_short_slot_time >= 0) {
1070 sdata->vif.bss_conf.use_short_slot = 1084 sdata->vif.bss_conf.use_short_slot =
1071 params->use_short_slot_time; 1085 params->use_short_slot_time;
@@ -1109,6 +1123,13 @@ static int ieee80211_set_txq_params(struct wiphy *wiphy,
1109 p.cw_max = params->cwmax; 1123 p.cw_max = params->cwmax;
1110 p.cw_min = params->cwmin; 1124 p.cw_min = params->cwmin;
1111 p.txop = params->txop; 1125 p.txop = params->txop;
1126
1127 /*
1128 * Setting tx queue params disables u-apsd because it's only
1129 * called in master mode.
1130 */
1131 p.uapsd = false;
1132
1112 if (drv_conf_tx(local, params->queue, &p)) { 1133 if (drv_conf_tx(local, params->queue, &p)) {
1113 printk(KERN_DEBUG "%s: failed to set TX queue " 1134 printk(KERN_DEBUG "%s: failed to set TX queue "
1114 "parameters for queue %d\n", 1135 "parameters for queue %d\n",
@@ -1211,6 +1232,13 @@ static int ieee80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
1211 struct ieee80211_local *local = wiphy_priv(wiphy); 1232 struct ieee80211_local *local = wiphy_priv(wiphy);
1212 int err; 1233 int err;
1213 1234
1235 if (changed & WIPHY_PARAM_COVERAGE_CLASS) {
1236 err = drv_set_coverage_class(local, wiphy->coverage_class);
1237
1238 if (err)
1239 return err;
1240 }
1241
1214 if (changed & WIPHY_PARAM_RTS_THRESHOLD) { 1242 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
1215 err = drv_set_rts_threshold(local, wiphy->rts_threshold); 1243 err = drv_set_rts_threshold(local, wiphy->rts_threshold);
1216 1244
@@ -1298,6 +1326,50 @@ static int ieee80211_testmode_cmd(struct wiphy *wiphy, void *data, int len)
1298} 1326}
1299#endif 1327#endif
1300 1328
1329int __ieee80211_request_smps(struct ieee80211_sub_if_data *sdata,
1330 enum ieee80211_smps_mode smps_mode)
1331{
1332 const u8 *ap;
1333 enum ieee80211_smps_mode old_req;
1334 int err;
1335
1336 old_req = sdata->u.mgd.req_smps;
1337 sdata->u.mgd.req_smps = smps_mode;
1338
1339 if (old_req == smps_mode &&
1340 smps_mode != IEEE80211_SMPS_AUTOMATIC)
1341 return 0;
1342
1343 /*
1344 * If not associated, or current association is not an HT
1345 * association, there's no need to send an action frame.
1346 */
1347 if (!sdata->u.mgd.associated ||
1348 sdata->local->oper_channel_type == NL80211_CHAN_NO_HT) {
1349 mutex_lock(&sdata->local->iflist_mtx);
1350 ieee80211_recalc_smps(sdata->local, sdata);
1351 mutex_unlock(&sdata->local->iflist_mtx);
1352 return 0;
1353 }
1354
1355 ap = sdata->u.mgd.associated->bssid;
1356
1357 if (smps_mode == IEEE80211_SMPS_AUTOMATIC) {
1358 if (sdata->u.mgd.powersave)
1359 smps_mode = IEEE80211_SMPS_DYNAMIC;
1360 else
1361 smps_mode = IEEE80211_SMPS_OFF;
1362 }
1363
1364 /* send SM PS frame to AP */
1365 err = ieee80211_send_smps_action(sdata, smps_mode,
1366 ap, ap);
1367 if (err)
1368 sdata->u.mgd.req_smps = old_req;
1369
1370 return err;
1371}
1372
1301static int ieee80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev, 1373static int ieee80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
1302 bool enabled, int timeout) 1374 bool enabled, int timeout)
1303{ 1375{
@@ -1305,6 +1377,9 @@ static int ieee80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
1305 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); 1377 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1306 struct ieee80211_conf *conf = &local->hw.conf; 1378 struct ieee80211_conf *conf = &local->hw.conf;
1307 1379
1380 if (sdata->vif.type != NL80211_IFTYPE_STATION)
1381 return -EOPNOTSUPP;
1382
1308 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS)) 1383 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS))
1309 return -EOPNOTSUPP; 1384 return -EOPNOTSUPP;
1310 1385
@@ -1315,6 +1390,11 @@ static int ieee80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
1315 sdata->u.mgd.powersave = enabled; 1390 sdata->u.mgd.powersave = enabled;
1316 conf->dynamic_ps_timeout = timeout; 1391 conf->dynamic_ps_timeout = timeout;
1317 1392
1393 /* no change, but if automatic follow powersave */
1394 mutex_lock(&sdata->u.mgd.mtx);
1395 __ieee80211_request_smps(sdata, sdata->u.mgd.req_smps);
1396 mutex_unlock(&sdata->u.mgd.mtx);
1397
1318 if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS) 1398 if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)
1319 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS); 1399 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1320 1400
@@ -1330,39 +1410,52 @@ static int ieee80211_set_bitrate_mask(struct wiphy *wiphy,
1330{ 1410{
1331 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 1411 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1332 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); 1412 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1333 int i, err = -EINVAL; 1413 int i;
1334 u32 target_rate;
1335 struct ieee80211_supported_band *sband;
1336 1414
1337 sband = local->hw.wiphy->bands[local->hw.conf.channel->band]; 1415 /*
1416 * This _could_ be supported by providing a hook for
1417 * drivers for this function, but at this point it
1418 * doesn't seem worth bothering.
1419 */
1420 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL)
1421 return -EOPNOTSUPP;
1338 1422
1339 /* target_rate = -1, rate->fixed = 0 means auto only, so use all rates
1340 * target_rate = X, rate->fixed = 1 means only rate X
1341 * target_rate = X, rate->fixed = 0 means all rates <= X */
1342 sdata->max_ratectrl_rateidx = -1;
1343 sdata->force_unicast_rateidx = -1;
1344 1423
1345 if (mask->fixed) 1424 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
1346 target_rate = mask->fixed / 100; 1425 sdata->rc_rateidx_mask[i] = mask->control[i].legacy;
1347 else if (mask->maxrate)
1348 target_rate = mask->maxrate / 100;
1349 else
1350 return 0;
1351 1426
1352 for (i=0; i< sband->n_bitrates; i++) { 1427 return 0;
1353 struct ieee80211_rate *brate = &sband->bitrates[i]; 1428}
1354 int this_rate = brate->bitrate;
1355 1429
1356 if (target_rate == this_rate) { 1430static int ieee80211_remain_on_channel(struct wiphy *wiphy,
1357 sdata->max_ratectrl_rateidx = i; 1431 struct net_device *dev,
1358 if (mask->fixed) 1432 struct ieee80211_channel *chan,
1359 sdata->force_unicast_rateidx = i; 1433 enum nl80211_channel_type channel_type,
1360 err = 0; 1434 unsigned int duration,
1361 break; 1435 u64 *cookie)
1362 } 1436{
1363 } 1437 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1364 1438
1365 return err; 1439 return ieee80211_wk_remain_on_channel(sdata, chan, channel_type,
1440 duration, cookie);
1441}
1442
1443static int ieee80211_cancel_remain_on_channel(struct wiphy *wiphy,
1444 struct net_device *dev,
1445 u64 cookie)
1446{
1447 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1448
1449 return ieee80211_wk_cancel_remain_on_channel(sdata, cookie);
1450}
1451
1452static int ieee80211_action(struct wiphy *wiphy, struct net_device *dev,
1453 struct ieee80211_channel *chan,
1454 enum nl80211_channel_type channel_type,
1455 const u8 *buf, size_t len, u64 *cookie)
1456{
1457 return ieee80211_mgd_action(IEEE80211_DEV_TO_SUB_IF(dev), chan,
1458 channel_type, buf, len, cookie);
1366} 1459}
1367 1460
1368struct cfg80211_ops mac80211_config_ops = { 1461struct cfg80211_ops mac80211_config_ops = {
@@ -1411,4 +1504,7 @@ struct cfg80211_ops mac80211_config_ops = {
1411 CFG80211_TESTMODE_CMD(ieee80211_testmode_cmd) 1504 CFG80211_TESTMODE_CMD(ieee80211_testmode_cmd)
1412 .set_power_mgmt = ieee80211_set_power_mgmt, 1505 .set_power_mgmt = ieee80211_set_power_mgmt,
1413 .set_bitrate_mask = ieee80211_set_bitrate_mask, 1506 .set_bitrate_mask = ieee80211_set_bitrate_mask,
1507 .remain_on_channel = ieee80211_remain_on_channel,
1508 .cancel_remain_on_channel = ieee80211_cancel_remain_on_channel,
1509 .action = ieee80211_action,
1414}; 1510};
diff --git a/net/mac80211/debugfs.c b/net/mac80211/debugfs.c
index 96991b68f048..637929b65ccc 100644
--- a/net/mac80211/debugfs.c
+++ b/net/mac80211/debugfs.c
@@ -1,3 +1,4 @@
1
1/* 2/*
2 * mac80211 debugfs for wireless PHYs 3 * mac80211 debugfs for wireless PHYs
3 * 4 *
@@ -38,16 +39,10 @@ static const struct file_operations name## _ops = { \
38}; 39};
39 40
40#define DEBUGFS_ADD(name) \ 41#define DEBUGFS_ADD(name) \
41 local->debugfs.name = debugfs_create_file(#name, 0400, phyd, \ 42 debugfs_create_file(#name, 0400, phyd, local, &name## _ops);
42 local, &name## _ops);
43 43
44#define DEBUGFS_ADD_MODE(name, mode) \ 44#define DEBUGFS_ADD_MODE(name, mode) \
45 local->debugfs.name = debugfs_create_file(#name, mode, phyd, \ 45 debugfs_create_file(#name, mode, phyd, local, &name## _ops);
46 local, &name## _ops);
47
48#define DEBUGFS_DEL(name) \
49 debugfs_remove(local->debugfs.name); \
50 local->debugfs.name = NULL;
51 46
52 47
53DEBUGFS_READONLY_FILE(frequency, 20, "%d", 48DEBUGFS_READONLY_FILE(frequency, 20, "%d",
@@ -57,7 +52,7 @@ DEBUGFS_READONLY_FILE(total_ps_buffered, 20, "%d",
57DEBUGFS_READONLY_FILE(wep_iv, 20, "%#08x", 52DEBUGFS_READONLY_FILE(wep_iv, 20, "%#08x",
58 local->wep_iv & 0xffffff); 53 local->wep_iv & 0xffffff);
59DEBUGFS_READONLY_FILE(rate_ctrl_alg, 100, "%s", 54DEBUGFS_READONLY_FILE(rate_ctrl_alg, 100, "%s",
60 local->rate_ctrl ? local->rate_ctrl->ops->name : "<unset>"); 55 local->rate_ctrl ? local->rate_ctrl->ops->name : "hw/driver");
61 56
62static ssize_t tsf_read(struct file *file, char __user *user_buf, 57static ssize_t tsf_read(struct file *file, char __user *user_buf,
63 size_t count, loff_t *ppos) 58 size_t count, loff_t *ppos)
@@ -163,6 +158,130 @@ static const struct file_operations noack_ops = {
163 .open = mac80211_open_file_generic 158 .open = mac80211_open_file_generic
164}; 159};
165 160
161static ssize_t uapsd_queues_read(struct file *file, char __user *user_buf,
162 size_t count, loff_t *ppos)
163{
164 struct ieee80211_local *local = file->private_data;
165 int res;
166 char buf[10];
167
168 res = scnprintf(buf, sizeof(buf), "0x%x\n", local->uapsd_queues);
169
170 return simple_read_from_buffer(user_buf, count, ppos, buf, res);
171}
172
173static ssize_t uapsd_queues_write(struct file *file,
174 const char __user *user_buf,
175 size_t count, loff_t *ppos)
176{
177 struct ieee80211_local *local = file->private_data;
178 unsigned long val;
179 char buf[10];
180 size_t len;
181 int ret;
182
183 len = min(count, sizeof(buf) - 1);
184 if (copy_from_user(buf, user_buf, len))
185 return -EFAULT;
186 buf[len] = '\0';
187
188 ret = strict_strtoul(buf, 0, &val);
189
190 if (ret)
191 return -EINVAL;
192
193 if (val & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
194 return -ERANGE;
195
196 local->uapsd_queues = val;
197
198 return count;
199}
200
201static const struct file_operations uapsd_queues_ops = {
202 .read = uapsd_queues_read,
203 .write = uapsd_queues_write,
204 .open = mac80211_open_file_generic
205};
206
207static ssize_t uapsd_max_sp_len_read(struct file *file, char __user *user_buf,
208 size_t count, loff_t *ppos)
209{
210 struct ieee80211_local *local = file->private_data;
211 int res;
212 char buf[10];
213
214 res = scnprintf(buf, sizeof(buf), "0x%x\n", local->uapsd_max_sp_len);
215
216 return simple_read_from_buffer(user_buf, count, ppos, buf, res);
217}
218
219static ssize_t uapsd_max_sp_len_write(struct file *file,
220 const char __user *user_buf,
221 size_t count, loff_t *ppos)
222{
223 struct ieee80211_local *local = file->private_data;
224 unsigned long val;
225 char buf[10];
226 size_t len;
227 int ret;
228
229 len = min(count, sizeof(buf) - 1);
230 if (copy_from_user(buf, user_buf, len))
231 return -EFAULT;
232 buf[len] = '\0';
233
234 ret = strict_strtoul(buf, 0, &val);
235
236 if (ret)
237 return -EINVAL;
238
239 if (val & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
240 return -ERANGE;
241
242 local->uapsd_max_sp_len = val;
243
244 return count;
245}
246
247static const struct file_operations uapsd_max_sp_len_ops = {
248 .read = uapsd_max_sp_len_read,
249 .write = uapsd_max_sp_len_write,
250 .open = mac80211_open_file_generic
251};
252
253static ssize_t channel_type_read(struct file *file, char __user *user_buf,
254 size_t count, loff_t *ppos)
255{
256 struct ieee80211_local *local = file->private_data;
257 const char *buf;
258
259 switch (local->hw.conf.channel_type) {
260 case NL80211_CHAN_NO_HT:
261 buf = "no ht\n";
262 break;
263 case NL80211_CHAN_HT20:
264 buf = "ht20\n";
265 break;
266 case NL80211_CHAN_HT40MINUS:
267 buf = "ht40-\n";
268 break;
269 case NL80211_CHAN_HT40PLUS:
270 buf = "ht40+\n";
271 break;
272 default:
273 buf = "???";
274 break;
275 }
276
277 return simple_read_from_buffer(user_buf, count, ppos, buf, strlen(buf));
278}
279
280static const struct file_operations channel_type_ops = {
281 .read = channel_type_read,
282 .open = mac80211_open_file_generic
283};
284
166static ssize_t queues_read(struct file *file, char __user *user_buf, 285static ssize_t queues_read(struct file *file, char __user *user_buf,
167 size_t count, loff_t *ppos) 286 size_t count, loff_t *ppos)
168{ 287{
@@ -233,12 +352,7 @@ static const struct file_operations stats_ ##name## _ops = { \
233}; 352};
234 353
235#define DEBUGFS_STATS_ADD(name) \ 354#define DEBUGFS_STATS_ADD(name) \
236 local->debugfs.stats.name = debugfs_create_file(#name, 0400, statsd,\ 355 debugfs_create_file(#name, 0400, statsd, local, &stats_ ##name## _ops);
237 local, &stats_ ##name## _ops);
238
239#define DEBUGFS_STATS_DEL(name) \
240 debugfs_remove(local->debugfs.stats.name); \
241 local->debugfs.stats.name = NULL;
242 356
243DEBUGFS_STATS_FILE(transmitted_fragment_count, 20, "%u", 357DEBUGFS_STATS_FILE(transmitted_fragment_count, 20, "%u",
244 local->dot11TransmittedFragmentCount); 358 local->dot11TransmittedFragmentCount);
@@ -324,9 +438,11 @@ void debugfs_hw_add(struct ieee80211_local *local)
324 DEBUGFS_ADD(queues); 438 DEBUGFS_ADD(queues);
325 DEBUGFS_ADD_MODE(reset, 0200); 439 DEBUGFS_ADD_MODE(reset, 0200);
326 DEBUGFS_ADD(noack); 440 DEBUGFS_ADD(noack);
441 DEBUGFS_ADD(uapsd_queues);
442 DEBUGFS_ADD(uapsd_max_sp_len);
443 DEBUGFS_ADD(channel_type);
327 444
328 statsd = debugfs_create_dir("statistics", phyd); 445 statsd = debugfs_create_dir("statistics", phyd);
329 local->debugfs.statistics = statsd;
330 446
331 /* if the dir failed, don't put all the other things into the root! */ 447 /* if the dir failed, don't put all the other things into the root! */
332 if (!statsd) 448 if (!statsd)
@@ -367,57 +483,3 @@ void debugfs_hw_add(struct ieee80211_local *local)
367 DEBUGFS_STATS_ADD(dot11FCSErrorCount); 483 DEBUGFS_STATS_ADD(dot11FCSErrorCount);
368 DEBUGFS_STATS_ADD(dot11RTSSuccessCount); 484 DEBUGFS_STATS_ADD(dot11RTSSuccessCount);
369} 485}
370
371void debugfs_hw_del(struct ieee80211_local *local)
372{
373 DEBUGFS_DEL(frequency);
374 DEBUGFS_DEL(total_ps_buffered);
375 DEBUGFS_DEL(wep_iv);
376 DEBUGFS_DEL(tsf);
377 DEBUGFS_DEL(queues);
378 DEBUGFS_DEL(reset);
379 DEBUGFS_DEL(noack);
380
381 DEBUGFS_STATS_DEL(transmitted_fragment_count);
382 DEBUGFS_STATS_DEL(multicast_transmitted_frame_count);
383 DEBUGFS_STATS_DEL(failed_count);
384 DEBUGFS_STATS_DEL(retry_count);
385 DEBUGFS_STATS_DEL(multiple_retry_count);
386 DEBUGFS_STATS_DEL(frame_duplicate_count);
387 DEBUGFS_STATS_DEL(received_fragment_count);
388 DEBUGFS_STATS_DEL(multicast_received_frame_count);
389 DEBUGFS_STATS_DEL(transmitted_frame_count);
390 DEBUGFS_STATS_DEL(num_scans);
391#ifdef CONFIG_MAC80211_DEBUG_COUNTERS
392 DEBUGFS_STATS_DEL(tx_handlers_drop);
393 DEBUGFS_STATS_DEL(tx_handlers_queued);
394 DEBUGFS_STATS_DEL(tx_handlers_drop_unencrypted);
395 DEBUGFS_STATS_DEL(tx_handlers_drop_fragment);
396 DEBUGFS_STATS_DEL(tx_handlers_drop_wep);
397 DEBUGFS_STATS_DEL(tx_handlers_drop_not_assoc);
398 DEBUGFS_STATS_DEL(tx_handlers_drop_unauth_port);
399 DEBUGFS_STATS_DEL(rx_handlers_drop);
400 DEBUGFS_STATS_DEL(rx_handlers_queued);
401 DEBUGFS_STATS_DEL(rx_handlers_drop_nullfunc);
402 DEBUGFS_STATS_DEL(rx_handlers_drop_defrag);
403 DEBUGFS_STATS_DEL(rx_handlers_drop_short);
404 DEBUGFS_STATS_DEL(rx_handlers_drop_passive_scan);
405 DEBUGFS_STATS_DEL(tx_expand_skb_head);
406 DEBUGFS_STATS_DEL(tx_expand_skb_head_cloned);
407 DEBUGFS_STATS_DEL(rx_expand_skb_head);
408 DEBUGFS_STATS_DEL(rx_expand_skb_head2);
409 DEBUGFS_STATS_DEL(rx_handlers_fragments);
410 DEBUGFS_STATS_DEL(tx_status_drop);
411#endif
412 DEBUGFS_STATS_DEL(dot11ACKFailureCount);
413 DEBUGFS_STATS_DEL(dot11RTSFailureCount);
414 DEBUGFS_STATS_DEL(dot11FCSErrorCount);
415 DEBUGFS_STATS_DEL(dot11RTSSuccessCount);
416
417 debugfs_remove(local->debugfs.statistics);
418 local->debugfs.statistics = NULL;
419 debugfs_remove(local->debugfs.stations);
420 local->debugfs.stations = NULL;
421 debugfs_remove(local->debugfs.keys);
422 local->debugfs.keys = NULL;
423}
diff --git a/net/mac80211/debugfs.h b/net/mac80211/debugfs.h
index dd2541935c27..68e6a2050f9a 100644
--- a/net/mac80211/debugfs.h
+++ b/net/mac80211/debugfs.h
@@ -3,14 +3,12 @@
3 3
4#ifdef CONFIG_MAC80211_DEBUGFS 4#ifdef CONFIG_MAC80211_DEBUGFS
5extern void debugfs_hw_add(struct ieee80211_local *local); 5extern void debugfs_hw_add(struct ieee80211_local *local);
6extern void debugfs_hw_del(struct ieee80211_local *local);
7extern int mac80211_open_file_generic(struct inode *inode, struct file *file); 6extern int mac80211_open_file_generic(struct inode *inode, struct file *file);
8#else 7#else
9static inline void debugfs_hw_add(struct ieee80211_local *local) 8static inline void debugfs_hw_add(struct ieee80211_local *local)
10{ 9{
11 return; 10 return;
12} 11}
13static inline void debugfs_hw_del(struct ieee80211_local *local) {}
14#endif 12#endif
15 13
16#endif /* __MAC80211_DEBUGFS_H */ 14#endif /* __MAC80211_DEBUGFS_H */
diff --git a/net/mac80211/debugfs_key.c b/net/mac80211/debugfs_key.c
index 99c752588b30..97c9e46e859e 100644
--- a/net/mac80211/debugfs_key.c
+++ b/net/mac80211/debugfs_key.c
@@ -9,6 +9,7 @@
9 */ 9 */
10 10
11#include <linux/kobject.h> 11#include <linux/kobject.h>
12#include <linux/slab.h>
12#include "ieee80211_i.h" 13#include "ieee80211_i.h"
13#include "key.h" 14#include "key.h"
14#include "debugfs.h" 15#include "debugfs.h"
@@ -56,7 +57,7 @@ KEY_CONF_FILE(keyidx, D);
56KEY_CONF_FILE(hw_key_idx, D); 57KEY_CONF_FILE(hw_key_idx, D);
57KEY_FILE(flags, X); 58KEY_FILE(flags, X);
58KEY_FILE(tx_rx_count, D); 59KEY_FILE(tx_rx_count, D);
59KEY_READ(ifindex, sdata->dev->ifindex, 20, "%d\n"); 60KEY_READ(ifindex, sdata->name, IFNAMSIZ + 2, "%s\n");
60KEY_OPS(ifindex); 61KEY_OPS(ifindex);
61 62
62static ssize_t key_algorithm_read(struct file *file, 63static ssize_t key_algorithm_read(struct file *file,
@@ -225,8 +226,8 @@ static ssize_t key_key_read(struct file *file, char __user *userbuf,
225KEY_OPS(key); 226KEY_OPS(key);
226 227
227#define DEBUGFS_ADD(name) \ 228#define DEBUGFS_ADD(name) \
228 key->debugfs.name = debugfs_create_file(#name, 0400,\ 229 debugfs_create_file(#name, 0400, key->debugfs.dir, \
229 key->debugfs.dir, key, &key_##name##_ops); 230 key, &key_##name##_ops);
230 231
231void ieee80211_debugfs_key_add(struct ieee80211_key *key) 232void ieee80211_debugfs_key_add(struct ieee80211_key *key)
232 { 233 {
@@ -271,30 +272,12 @@ void ieee80211_debugfs_key_add(struct ieee80211_key *key)
271 DEBUGFS_ADD(ifindex); 272 DEBUGFS_ADD(ifindex);
272}; 273};
273 274
274#define DEBUGFS_DEL(name) \
275 debugfs_remove(key->debugfs.name); key->debugfs.name = NULL;
276
277void ieee80211_debugfs_key_remove(struct ieee80211_key *key) 275void ieee80211_debugfs_key_remove(struct ieee80211_key *key)
278{ 276{
279 if (!key) 277 if (!key)
280 return; 278 return;
281 279
282 DEBUGFS_DEL(keylen); 280 debugfs_remove_recursive(key->debugfs.dir);
283 DEBUGFS_DEL(flags);
284 DEBUGFS_DEL(keyidx);
285 DEBUGFS_DEL(hw_key_idx);
286 DEBUGFS_DEL(tx_rx_count);
287 DEBUGFS_DEL(algorithm);
288 DEBUGFS_DEL(tx_spec);
289 DEBUGFS_DEL(rx_spec);
290 DEBUGFS_DEL(replays);
291 DEBUGFS_DEL(icverrors);
292 DEBUGFS_DEL(key);
293 DEBUGFS_DEL(ifindex);
294
295 debugfs_remove(key->debugfs.stalink);
296 key->debugfs.stalink = NULL;
297 debugfs_remove(key->debugfs.dir);
298 key->debugfs.dir = NULL; 281 key->debugfs.dir = NULL;
299} 282}
300void ieee80211_debugfs_key_add_default(struct ieee80211_sub_if_data *sdata) 283void ieee80211_debugfs_key_add_default(struct ieee80211_sub_if_data *sdata)
@@ -302,7 +285,7 @@ void ieee80211_debugfs_key_add_default(struct ieee80211_sub_if_data *sdata)
302 char buf[50]; 285 char buf[50];
303 struct ieee80211_key *key; 286 struct ieee80211_key *key;
304 287
305 if (!sdata->debugfsdir) 288 if (!sdata->debugfs.dir)
306 return; 289 return;
307 290
308 /* this is running under the key lock */ 291 /* this is running under the key lock */
@@ -310,9 +293,9 @@ void ieee80211_debugfs_key_add_default(struct ieee80211_sub_if_data *sdata)
310 key = sdata->default_key; 293 key = sdata->default_key;
311 if (key) { 294 if (key) {
312 sprintf(buf, "../keys/%d", key->debugfs.cnt); 295 sprintf(buf, "../keys/%d", key->debugfs.cnt);
313 sdata->common_debugfs.default_key = 296 sdata->debugfs.default_key =
314 debugfs_create_symlink("default_key", 297 debugfs_create_symlink("default_key",
315 sdata->debugfsdir, buf); 298 sdata->debugfs.dir, buf);
316 } else 299 } else
317 ieee80211_debugfs_key_remove_default(sdata); 300 ieee80211_debugfs_key_remove_default(sdata);
318} 301}
@@ -322,8 +305,8 @@ void ieee80211_debugfs_key_remove_default(struct ieee80211_sub_if_data *sdata)
322 if (!sdata) 305 if (!sdata)
323 return; 306 return;
324 307
325 debugfs_remove(sdata->common_debugfs.default_key); 308 debugfs_remove(sdata->debugfs.default_key);
326 sdata->common_debugfs.default_key = NULL; 309 sdata->debugfs.default_key = NULL;
327} 310}
328 311
329void ieee80211_debugfs_key_add_mgmt_default(struct ieee80211_sub_if_data *sdata) 312void ieee80211_debugfs_key_add_mgmt_default(struct ieee80211_sub_if_data *sdata)
@@ -331,7 +314,7 @@ void ieee80211_debugfs_key_add_mgmt_default(struct ieee80211_sub_if_data *sdata)
331 char buf[50]; 314 char buf[50];
332 struct ieee80211_key *key; 315 struct ieee80211_key *key;
333 316
334 if (!sdata->debugfsdir) 317 if (!sdata->debugfs.dir)
335 return; 318 return;
336 319
337 /* this is running under the key lock */ 320 /* this is running under the key lock */
@@ -339,9 +322,9 @@ void ieee80211_debugfs_key_add_mgmt_default(struct ieee80211_sub_if_data *sdata)
339 key = sdata->default_mgmt_key; 322 key = sdata->default_mgmt_key;
340 if (key) { 323 if (key) {
341 sprintf(buf, "../keys/%d", key->debugfs.cnt); 324 sprintf(buf, "../keys/%d", key->debugfs.cnt);
342 sdata->common_debugfs.default_mgmt_key = 325 sdata->debugfs.default_mgmt_key =
343 debugfs_create_symlink("default_mgmt_key", 326 debugfs_create_symlink("default_mgmt_key",
344 sdata->debugfsdir, buf); 327 sdata->debugfs.dir, buf);
345 } else 328 } else
346 ieee80211_debugfs_key_remove_mgmt_default(sdata); 329 ieee80211_debugfs_key_remove_mgmt_default(sdata);
347} 330}
@@ -351,8 +334,8 @@ void ieee80211_debugfs_key_remove_mgmt_default(struct ieee80211_sub_if_data *sda
351 if (!sdata) 334 if (!sdata)
352 return; 335 return;
353 336
354 debugfs_remove(sdata->common_debugfs.default_mgmt_key); 337 debugfs_remove(sdata->debugfs.default_mgmt_key);
355 sdata->common_debugfs.default_mgmt_key = NULL; 338 sdata->debugfs.default_mgmt_key = NULL;
356} 339}
357 340
358void ieee80211_debugfs_key_sta_del(struct ieee80211_key *key, 341void ieee80211_debugfs_key_sta_del(struct ieee80211_key *key,
diff --git a/net/mac80211/debugfs_netdev.c b/net/mac80211/debugfs_netdev.c
index 61234e79022b..83d4289d954b 100644
--- a/net/mac80211/debugfs_netdev.c
+++ b/net/mac80211/debugfs_netdev.c
@@ -13,6 +13,7 @@
13#include <linux/interrupt.h> 13#include <linux/interrupt.h>
14#include <linux/netdevice.h> 14#include <linux/netdevice.h>
15#include <linux/rtnetlink.h> 15#include <linux/rtnetlink.h>
16#include <linux/slab.h>
16#include <linux/notifier.h> 17#include <linux/notifier.h>
17#include <net/mac80211.h> 18#include <net/mac80211.h>
18#include <net/cfg80211.h> 19#include <net/cfg80211.h>
@@ -41,6 +42,34 @@ static ssize_t ieee80211_if_read(
41 return ret; 42 return ret;
42} 43}
43 44
45static ssize_t ieee80211_if_write(
46 struct ieee80211_sub_if_data *sdata,
47 const char __user *userbuf,
48 size_t count, loff_t *ppos,
49 ssize_t (*write)(struct ieee80211_sub_if_data *, const char *, int))
50{
51 u8 *buf;
52 ssize_t ret;
53
54 buf = kmalloc(count, GFP_KERNEL);
55 if (!buf)
56 return -ENOMEM;
57
58 ret = -EFAULT;
59 if (copy_from_user(buf, userbuf, count))
60 goto freebuf;
61
62 ret = -ENODEV;
63 rtnl_lock();
64 if (sdata->dev->reg_state == NETREG_REGISTERED)
65 ret = (*write)(sdata, buf, count);
66 rtnl_unlock();
67
68freebuf:
69 kfree(buf);
70 return ret;
71}
72
44#define IEEE80211_IF_FMT(name, field, format_string) \ 73#define IEEE80211_IF_FMT(name, field, format_string) \
45static ssize_t ieee80211_if_fmt_##name( \ 74static ssize_t ieee80211_if_fmt_##name( \
46 const struct ieee80211_sub_if_data *sdata, char *buf, \ 75 const struct ieee80211_sub_if_data *sdata, char *buf, \
@@ -71,7 +100,7 @@ static ssize_t ieee80211_if_fmt_##name( \
71 return scnprintf(buf, buflen, "%pM\n", sdata->field); \ 100 return scnprintf(buf, buflen, "%pM\n", sdata->field); \
72} 101}
73 102
74#define __IEEE80211_IF_FILE(name) \ 103#define __IEEE80211_IF_FILE(name, _write) \
75static ssize_t ieee80211_if_read_##name(struct file *file, \ 104static ssize_t ieee80211_if_read_##name(struct file *file, \
76 char __user *userbuf, \ 105 char __user *userbuf, \
77 size_t count, loff_t *ppos) \ 106 size_t count, loff_t *ppos) \
@@ -82,22 +111,99 @@ static ssize_t ieee80211_if_read_##name(struct file *file, \
82} \ 111} \
83static const struct file_operations name##_ops = { \ 112static const struct file_operations name##_ops = { \
84 .read = ieee80211_if_read_##name, \ 113 .read = ieee80211_if_read_##name, \
114 .write = (_write), \
85 .open = mac80211_open_file_generic, \ 115 .open = mac80211_open_file_generic, \
86} 116}
87 117
118#define __IEEE80211_IF_FILE_W(name) \
119static ssize_t ieee80211_if_write_##name(struct file *file, \
120 const char __user *userbuf, \
121 size_t count, loff_t *ppos) \
122{ \
123 return ieee80211_if_write(file->private_data, userbuf, count, \
124 ppos, ieee80211_if_parse_##name); \
125} \
126__IEEE80211_IF_FILE(name, ieee80211_if_write_##name)
127
128
88#define IEEE80211_IF_FILE(name, field, format) \ 129#define IEEE80211_IF_FILE(name, field, format) \
89 IEEE80211_IF_FMT_##format(name, field) \ 130 IEEE80211_IF_FMT_##format(name, field) \
90 __IEEE80211_IF_FILE(name) 131 __IEEE80211_IF_FILE(name, NULL)
91 132
92/* common attributes */ 133/* common attributes */
93IEEE80211_IF_FILE(drop_unencrypted, drop_unencrypted, DEC); 134IEEE80211_IF_FILE(drop_unencrypted, drop_unencrypted, DEC);
94IEEE80211_IF_FILE(force_unicast_rateidx, force_unicast_rateidx, DEC); 135IEEE80211_IF_FILE(rc_rateidx_mask_2ghz, rc_rateidx_mask[IEEE80211_BAND_2GHZ],
95IEEE80211_IF_FILE(max_ratectrl_rateidx, max_ratectrl_rateidx, DEC); 136 HEX);
137IEEE80211_IF_FILE(rc_rateidx_mask_5ghz, rc_rateidx_mask[IEEE80211_BAND_5GHZ],
138 HEX);
96 139
97/* STA attributes */ 140/* STA attributes */
98IEEE80211_IF_FILE(bssid, u.mgd.bssid, MAC); 141IEEE80211_IF_FILE(bssid, u.mgd.bssid, MAC);
99IEEE80211_IF_FILE(aid, u.mgd.aid, DEC); 142IEEE80211_IF_FILE(aid, u.mgd.aid, DEC);
100IEEE80211_IF_FILE(capab, u.mgd.capab, HEX); 143
144static int ieee80211_set_smps(struct ieee80211_sub_if_data *sdata,
145 enum ieee80211_smps_mode smps_mode)
146{
147 struct ieee80211_local *local = sdata->local;
148 int err;
149
150 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_STATIC_SMPS) &&
151 smps_mode == IEEE80211_SMPS_STATIC)
152 return -EINVAL;
153
154 /* auto should be dynamic if in PS mode */
155 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS) &&
156 (smps_mode == IEEE80211_SMPS_DYNAMIC ||
157 smps_mode == IEEE80211_SMPS_AUTOMATIC))
158 return -EINVAL;
159
160 /* supported only on managed interfaces for now */
161 if (sdata->vif.type != NL80211_IFTYPE_STATION)
162 return -EOPNOTSUPP;
163
164 mutex_lock(&local->iflist_mtx);
165 err = __ieee80211_request_smps(sdata, smps_mode);
166 mutex_unlock(&local->iflist_mtx);
167
168 return err;
169}
170
171static const char *smps_modes[IEEE80211_SMPS_NUM_MODES] = {
172 [IEEE80211_SMPS_AUTOMATIC] = "auto",
173 [IEEE80211_SMPS_OFF] = "off",
174 [IEEE80211_SMPS_STATIC] = "static",
175 [IEEE80211_SMPS_DYNAMIC] = "dynamic",
176};
177
178static ssize_t ieee80211_if_fmt_smps(const struct ieee80211_sub_if_data *sdata,
179 char *buf, int buflen)
180{
181 if (sdata->vif.type != NL80211_IFTYPE_STATION)
182 return -EOPNOTSUPP;
183
184 return snprintf(buf, buflen, "request: %s\nused: %s\n",
185 smps_modes[sdata->u.mgd.req_smps],
186 smps_modes[sdata->u.mgd.ap_smps]);
187}
188
189static ssize_t ieee80211_if_parse_smps(struct ieee80211_sub_if_data *sdata,
190 const char *buf, int buflen)
191{
192 enum ieee80211_smps_mode mode;
193
194 for (mode = 0; mode < IEEE80211_SMPS_NUM_MODES; mode++) {
195 if (strncmp(buf, smps_modes[mode], buflen) == 0) {
196 int err = ieee80211_set_smps(sdata, mode);
197 if (!err)
198 return buflen;
199 return err;
200 }
201 }
202
203 return -EINVAL;
204}
205
206__IEEE80211_IF_FILE_W(smps);
101 207
102/* AP attributes */ 208/* AP attributes */
103IEEE80211_IF_FILE(num_sta_ps, u.ap.num_sta_ps, ATOMIC); 209IEEE80211_IF_FILE(num_sta_ps, u.ap.num_sta_ps, ATOMIC);
@@ -109,7 +215,7 @@ static ssize_t ieee80211_if_fmt_num_buffered_multicast(
109 return scnprintf(buf, buflen, "%u\n", 215 return scnprintf(buf, buflen, "%u\n",
110 skb_queue_len(&sdata->u.ap.ps_bc_buf)); 216 skb_queue_len(&sdata->u.ap.ps_bc_buf));
111} 217}
112__IEEE80211_IF_FILE(num_buffered_multicast); 218__IEEE80211_IF_FILE(num_buffered_multicast, NULL);
113 219
114/* WDS attributes */ 220/* WDS attributes */
115IEEE80211_IF_FILE(peer, u.wds.remote_addr, MAC); 221IEEE80211_IF_FILE(peer, u.wds.remote_addr, MAC);
@@ -149,49 +255,55 @@ IEEE80211_IF_FILE(path_refresh_time,
149 u.mesh.mshcfg.path_refresh_time, DEC); 255 u.mesh.mshcfg.path_refresh_time, DEC);
150IEEE80211_IF_FILE(min_discovery_timeout, 256IEEE80211_IF_FILE(min_discovery_timeout,
151 u.mesh.mshcfg.min_discovery_timeout, DEC); 257 u.mesh.mshcfg.min_discovery_timeout, DEC);
258IEEE80211_IF_FILE(dot11MeshHWMPRootMode,
259 u.mesh.mshcfg.dot11MeshHWMPRootMode, DEC);
152#endif 260#endif
153 261
154 262
155#define DEBUGFS_ADD(name, type)\ 263#define DEBUGFS_ADD(name) \
156 sdata->debugfs.type.name = debugfs_create_file(#name, 0400,\ 264 debugfs_create_file(#name, 0400, sdata->debugfs.dir, \
157 sdata->debugfsdir, sdata, &name##_ops); 265 sdata, &name##_ops);
266
267#define DEBUGFS_ADD_MODE(name, mode) \
268 debugfs_create_file(#name, mode, sdata->debugfs.dir, \
269 sdata, &name##_ops);
158 270
159static void add_sta_files(struct ieee80211_sub_if_data *sdata) 271static void add_sta_files(struct ieee80211_sub_if_data *sdata)
160{ 272{
161 DEBUGFS_ADD(drop_unencrypted, sta); 273 DEBUGFS_ADD(drop_unencrypted);
162 DEBUGFS_ADD(force_unicast_rateidx, sta); 274 DEBUGFS_ADD(rc_rateidx_mask_2ghz);
163 DEBUGFS_ADD(max_ratectrl_rateidx, sta); 275 DEBUGFS_ADD(rc_rateidx_mask_5ghz);
164 276
165 DEBUGFS_ADD(bssid, sta); 277 DEBUGFS_ADD(bssid);
166 DEBUGFS_ADD(aid, sta); 278 DEBUGFS_ADD(aid);
167 DEBUGFS_ADD(capab, sta); 279 DEBUGFS_ADD_MODE(smps, 0600);
168} 280}
169 281
170static void add_ap_files(struct ieee80211_sub_if_data *sdata) 282static void add_ap_files(struct ieee80211_sub_if_data *sdata)
171{ 283{
172 DEBUGFS_ADD(drop_unencrypted, ap); 284 DEBUGFS_ADD(drop_unencrypted);
173 DEBUGFS_ADD(force_unicast_rateidx, ap); 285 DEBUGFS_ADD(rc_rateidx_mask_2ghz);
174 DEBUGFS_ADD(max_ratectrl_rateidx, ap); 286 DEBUGFS_ADD(rc_rateidx_mask_5ghz);
175 287
176 DEBUGFS_ADD(num_sta_ps, ap); 288 DEBUGFS_ADD(num_sta_ps);
177 DEBUGFS_ADD(dtim_count, ap); 289 DEBUGFS_ADD(dtim_count);
178 DEBUGFS_ADD(num_buffered_multicast, ap); 290 DEBUGFS_ADD(num_buffered_multicast);
179} 291}
180 292
181static void add_wds_files(struct ieee80211_sub_if_data *sdata) 293static void add_wds_files(struct ieee80211_sub_if_data *sdata)
182{ 294{
183 DEBUGFS_ADD(drop_unencrypted, wds); 295 DEBUGFS_ADD(drop_unencrypted);
184 DEBUGFS_ADD(force_unicast_rateidx, wds); 296 DEBUGFS_ADD(rc_rateidx_mask_2ghz);
185 DEBUGFS_ADD(max_ratectrl_rateidx, wds); 297 DEBUGFS_ADD(rc_rateidx_mask_5ghz);
186 298
187 DEBUGFS_ADD(peer, wds); 299 DEBUGFS_ADD(peer);
188} 300}
189 301
190static void add_vlan_files(struct ieee80211_sub_if_data *sdata) 302static void add_vlan_files(struct ieee80211_sub_if_data *sdata)
191{ 303{
192 DEBUGFS_ADD(drop_unencrypted, vlan); 304 DEBUGFS_ADD(drop_unencrypted);
193 DEBUGFS_ADD(force_unicast_rateidx, vlan); 305 DEBUGFS_ADD(rc_rateidx_mask_2ghz);
194 DEBUGFS_ADD(max_ratectrl_rateidx, vlan); 306 DEBUGFS_ADD(rc_rateidx_mask_5ghz);
195} 307}
196 308
197static void add_monitor_files(struct ieee80211_sub_if_data *sdata) 309static void add_monitor_files(struct ieee80211_sub_if_data *sdata)
@@ -199,30 +311,32 @@ static void add_monitor_files(struct ieee80211_sub_if_data *sdata)
199} 311}
200 312
201#ifdef CONFIG_MAC80211_MESH 313#ifdef CONFIG_MAC80211_MESH
202#define MESHSTATS_ADD(name)\
203 sdata->mesh_stats.name = debugfs_create_file(#name, 0400,\
204 sdata->mesh_stats_dir, sdata, &name##_ops);
205 314
206static void add_mesh_stats(struct ieee80211_sub_if_data *sdata) 315static void add_mesh_stats(struct ieee80211_sub_if_data *sdata)
207{ 316{
208 sdata->mesh_stats_dir = debugfs_create_dir("mesh_stats", 317 struct dentry *dir = debugfs_create_dir("mesh_stats",
209 sdata->debugfsdir); 318 sdata->debugfs.dir);
319
320#define MESHSTATS_ADD(name)\
321 debugfs_create_file(#name, 0400, dir, sdata, &name##_ops);
322
210 MESHSTATS_ADD(fwded_mcast); 323 MESHSTATS_ADD(fwded_mcast);
211 MESHSTATS_ADD(fwded_unicast); 324 MESHSTATS_ADD(fwded_unicast);
212 MESHSTATS_ADD(fwded_frames); 325 MESHSTATS_ADD(fwded_frames);
213 MESHSTATS_ADD(dropped_frames_ttl); 326 MESHSTATS_ADD(dropped_frames_ttl);
214 MESHSTATS_ADD(dropped_frames_no_route); 327 MESHSTATS_ADD(dropped_frames_no_route);
215 MESHSTATS_ADD(estab_plinks); 328 MESHSTATS_ADD(estab_plinks);
329#undef MESHSTATS_ADD
216} 330}
217 331
218#define MESHPARAMS_ADD(name)\
219 sdata->mesh_config.name = debugfs_create_file(#name, 0600,\
220 sdata->mesh_config_dir, sdata, &name##_ops);
221
222static void add_mesh_config(struct ieee80211_sub_if_data *sdata) 332static void add_mesh_config(struct ieee80211_sub_if_data *sdata)
223{ 333{
224 sdata->mesh_config_dir = debugfs_create_dir("mesh_config", 334 struct dentry *dir = debugfs_create_dir("mesh_config",
225 sdata->debugfsdir); 335 sdata->debugfs.dir);
336
337#define MESHPARAMS_ADD(name) \
338 debugfs_create_file(#name, 0600, dir, sdata, &name##_ops);
339
226 MESHPARAMS_ADD(dot11MeshMaxRetries); 340 MESHPARAMS_ADD(dot11MeshMaxRetries);
227 MESHPARAMS_ADD(dot11MeshRetryTimeout); 341 MESHPARAMS_ADD(dot11MeshRetryTimeout);
228 MESHPARAMS_ADD(dot11MeshConfirmTimeout); 342 MESHPARAMS_ADD(dot11MeshConfirmTimeout);
@@ -236,12 +350,14 @@ static void add_mesh_config(struct ieee80211_sub_if_data *sdata)
236 MESHPARAMS_ADD(dot11MeshHWMPmaxPREQretries); 350 MESHPARAMS_ADD(dot11MeshHWMPmaxPREQretries);
237 MESHPARAMS_ADD(path_refresh_time); 351 MESHPARAMS_ADD(path_refresh_time);
238 MESHPARAMS_ADD(min_discovery_timeout); 352 MESHPARAMS_ADD(min_discovery_timeout);
353
354#undef MESHPARAMS_ADD
239} 355}
240#endif 356#endif
241 357
242static void add_files(struct ieee80211_sub_if_data *sdata) 358static void add_files(struct ieee80211_sub_if_data *sdata)
243{ 359{
244 if (!sdata->debugfsdir) 360 if (!sdata->debugfs.dir)
245 return; 361 return;
246 362
247 switch (sdata->vif.type) { 363 switch (sdata->vif.type) {
@@ -274,208 +390,37 @@ static void add_files(struct ieee80211_sub_if_data *sdata)
274 } 390 }
275} 391}
276 392
277#define DEBUGFS_DEL(name, type) \
278 do { \
279 debugfs_remove(sdata->debugfs.type.name); \
280 sdata->debugfs.type.name = NULL; \
281 } while (0)
282
283static void del_sta_files(struct ieee80211_sub_if_data *sdata)
284{
285 DEBUGFS_DEL(drop_unencrypted, sta);
286 DEBUGFS_DEL(force_unicast_rateidx, sta);
287 DEBUGFS_DEL(max_ratectrl_rateidx, sta);
288
289 DEBUGFS_DEL(bssid, sta);
290 DEBUGFS_DEL(aid, sta);
291 DEBUGFS_DEL(capab, sta);
292}
293
294static void del_ap_files(struct ieee80211_sub_if_data *sdata)
295{
296 DEBUGFS_DEL(drop_unencrypted, ap);
297 DEBUGFS_DEL(force_unicast_rateidx, ap);
298 DEBUGFS_DEL(max_ratectrl_rateidx, ap);
299
300 DEBUGFS_DEL(num_sta_ps, ap);
301 DEBUGFS_DEL(dtim_count, ap);
302 DEBUGFS_DEL(num_buffered_multicast, ap);
303}
304
305static void del_wds_files(struct ieee80211_sub_if_data *sdata)
306{
307 DEBUGFS_DEL(drop_unencrypted, wds);
308 DEBUGFS_DEL(force_unicast_rateidx, wds);
309 DEBUGFS_DEL(max_ratectrl_rateidx, wds);
310
311 DEBUGFS_DEL(peer, wds);
312}
313
314static void del_vlan_files(struct ieee80211_sub_if_data *sdata)
315{
316 DEBUGFS_DEL(drop_unencrypted, vlan);
317 DEBUGFS_DEL(force_unicast_rateidx, vlan);
318 DEBUGFS_DEL(max_ratectrl_rateidx, vlan);
319}
320
321static void del_monitor_files(struct ieee80211_sub_if_data *sdata)
322{
323}
324
325#ifdef CONFIG_MAC80211_MESH
326#define MESHSTATS_DEL(name) \
327 do { \
328 debugfs_remove(sdata->mesh_stats.name); \
329 sdata->mesh_stats.name = NULL; \
330 } while (0)
331
332static void del_mesh_stats(struct ieee80211_sub_if_data *sdata)
333{
334 MESHSTATS_DEL(fwded_mcast);
335 MESHSTATS_DEL(fwded_unicast);
336 MESHSTATS_DEL(fwded_frames);
337 MESHSTATS_DEL(dropped_frames_ttl);
338 MESHSTATS_DEL(dropped_frames_no_route);
339 MESHSTATS_DEL(estab_plinks);
340 debugfs_remove(sdata->mesh_stats_dir);
341 sdata->mesh_stats_dir = NULL;
342}
343
344#define MESHPARAMS_DEL(name) \
345 do { \
346 debugfs_remove(sdata->mesh_config.name); \
347 sdata->mesh_config.name = NULL; \
348 } while (0)
349
350static void del_mesh_config(struct ieee80211_sub_if_data *sdata)
351{
352 MESHPARAMS_DEL(dot11MeshMaxRetries);
353 MESHPARAMS_DEL(dot11MeshRetryTimeout);
354 MESHPARAMS_DEL(dot11MeshConfirmTimeout);
355 MESHPARAMS_DEL(dot11MeshHoldingTimeout);
356 MESHPARAMS_DEL(dot11MeshTTL);
357 MESHPARAMS_DEL(auto_open_plinks);
358 MESHPARAMS_DEL(dot11MeshMaxPeerLinks);
359 MESHPARAMS_DEL(dot11MeshHWMPactivePathTimeout);
360 MESHPARAMS_DEL(dot11MeshHWMPpreqMinInterval);
361 MESHPARAMS_DEL(dot11MeshHWMPnetDiameterTraversalTime);
362 MESHPARAMS_DEL(dot11MeshHWMPmaxPREQretries);
363 MESHPARAMS_DEL(path_refresh_time);
364 MESHPARAMS_DEL(min_discovery_timeout);
365 debugfs_remove(sdata->mesh_config_dir);
366 sdata->mesh_config_dir = NULL;
367}
368#endif
369
370static void del_files(struct ieee80211_sub_if_data *sdata)
371{
372 if (!sdata->debugfsdir)
373 return;
374
375 switch (sdata->vif.type) {
376 case NL80211_IFTYPE_MESH_POINT:
377#ifdef CONFIG_MAC80211_MESH
378 del_mesh_stats(sdata);
379 del_mesh_config(sdata);
380#endif
381 break;
382 case NL80211_IFTYPE_STATION:
383 del_sta_files(sdata);
384 break;
385 case NL80211_IFTYPE_ADHOC:
386 /* XXX */
387 break;
388 case NL80211_IFTYPE_AP:
389 del_ap_files(sdata);
390 break;
391 case NL80211_IFTYPE_WDS:
392 del_wds_files(sdata);
393 break;
394 case NL80211_IFTYPE_MONITOR:
395 del_monitor_files(sdata);
396 break;
397 case NL80211_IFTYPE_AP_VLAN:
398 del_vlan_files(sdata);
399 break;
400 default:
401 break;
402 }
403}
404
405static int notif_registered;
406
407void ieee80211_debugfs_add_netdev(struct ieee80211_sub_if_data *sdata) 393void ieee80211_debugfs_add_netdev(struct ieee80211_sub_if_data *sdata)
408{ 394{
409 char buf[10+IFNAMSIZ]; 395 char buf[10+IFNAMSIZ];
410 396
411 if (!notif_registered) 397 sprintf(buf, "netdev:%s", sdata->name);
412 return; 398 sdata->debugfs.dir = debugfs_create_dir(buf,
413
414 sprintf(buf, "netdev:%s", sdata->dev->name);
415 sdata->debugfsdir = debugfs_create_dir(buf,
416 sdata->local->hw.wiphy->debugfsdir); 399 sdata->local->hw.wiphy->debugfsdir);
417 add_files(sdata); 400 add_files(sdata);
418} 401}
419 402
420void ieee80211_debugfs_remove_netdev(struct ieee80211_sub_if_data *sdata) 403void ieee80211_debugfs_remove_netdev(struct ieee80211_sub_if_data *sdata)
421{ 404{
422 del_files(sdata); 405 if (!sdata->debugfs.dir)
423 debugfs_remove(sdata->debugfsdir); 406 return;
424 sdata->debugfsdir = NULL; 407
408 debugfs_remove_recursive(sdata->debugfs.dir);
409 sdata->debugfs.dir = NULL;
425} 410}
426 411
427static int netdev_notify(struct notifier_block *nb, 412void ieee80211_debugfs_rename_netdev(struct ieee80211_sub_if_data *sdata)
428 unsigned long state,
429 void *ndev)
430{ 413{
431 struct net_device *dev = ndev;
432 struct dentry *dir; 414 struct dentry *dir;
433 struct ieee80211_sub_if_data *sdata; 415 char buf[10 + IFNAMSIZ];
434 char buf[10+IFNAMSIZ];
435
436 if (state != NETDEV_CHANGENAME)
437 return 0;
438 416
439 if (!dev->ieee80211_ptr || !dev->ieee80211_ptr->wiphy) 417 dir = sdata->debugfs.dir;
440 return 0;
441
442 if (dev->ieee80211_ptr->wiphy->privid != mac80211_wiphy_privid)
443 return 0;
444
445 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
446
447 dir = sdata->debugfsdir;
448 418
449 if (!dir) 419 if (!dir)
450 return 0; 420 return;
451 421
452 sprintf(buf, "netdev:%s", dev->name); 422 sprintf(buf, "netdev:%s", sdata->name);
453 if (!debugfs_rename(dir->d_parent, dir, dir->d_parent, buf)) 423 if (!debugfs_rename(dir->d_parent, dir, dir->d_parent, buf))
454 printk(KERN_ERR "mac80211: debugfs: failed to rename debugfs " 424 printk(KERN_ERR "mac80211: debugfs: failed to rename debugfs "
455 "dir to %s\n", buf); 425 "dir to %s\n", buf);
456
457 return 0;
458}
459
460static struct notifier_block mac80211_debugfs_netdev_notifier = {
461 .notifier_call = netdev_notify,
462};
463
464void ieee80211_debugfs_netdev_init(void)
465{
466 int err;
467
468 err = register_netdevice_notifier(&mac80211_debugfs_netdev_notifier);
469 if (err) {
470 printk(KERN_ERR
471 "mac80211: failed to install netdev notifier,"
472 " disabling per-netdev debugfs!\n");
473 } else
474 notif_registered = 1;
475}
476
477void ieee80211_debugfs_netdev_exit(void)
478{
479 unregister_netdevice_notifier(&mac80211_debugfs_netdev_notifier);
480 notif_registered = 0;
481} 426}
diff --git a/net/mac80211/debugfs_netdev.h b/net/mac80211/debugfs_netdev.h
index 7af731f0b731..79025e79f4d6 100644
--- a/net/mac80211/debugfs_netdev.h
+++ b/net/mac80211/debugfs_netdev.h
@@ -6,8 +6,7 @@
6#ifdef CONFIG_MAC80211_DEBUGFS 6#ifdef CONFIG_MAC80211_DEBUGFS
7void ieee80211_debugfs_add_netdev(struct ieee80211_sub_if_data *sdata); 7void ieee80211_debugfs_add_netdev(struct ieee80211_sub_if_data *sdata);
8void ieee80211_debugfs_remove_netdev(struct ieee80211_sub_if_data *sdata); 8void ieee80211_debugfs_remove_netdev(struct ieee80211_sub_if_data *sdata);
9void ieee80211_debugfs_netdev_init(void); 9void ieee80211_debugfs_rename_netdev(struct ieee80211_sub_if_data *sdata);
10void ieee80211_debugfs_netdev_exit(void);
11#else 10#else
12static inline void ieee80211_debugfs_add_netdev( 11static inline void ieee80211_debugfs_add_netdev(
13 struct ieee80211_sub_if_data *sdata) 12 struct ieee80211_sub_if_data *sdata)
@@ -15,10 +14,8 @@ static inline void ieee80211_debugfs_add_netdev(
15static inline void ieee80211_debugfs_remove_netdev( 14static inline void ieee80211_debugfs_remove_netdev(
16 struct ieee80211_sub_if_data *sdata) 15 struct ieee80211_sub_if_data *sdata)
17{} 16{}
18static inline void ieee80211_debugfs_netdev_init(void) 17static inline void ieee80211_debugfs_rename_netdev(
19{} 18 struct ieee80211_sub_if_data *sdata)
20
21static inline void ieee80211_debugfs_netdev_exit(void)
22{} 19{}
23#endif 20#endif
24 21
diff --git a/net/mac80211/debugfs_sta.c b/net/mac80211/debugfs_sta.c
index 33a2e892115b..d92800bb2d2f 100644
--- a/net/mac80211/debugfs_sta.c
+++ b/net/mac80211/debugfs_sta.c
@@ -44,7 +44,7 @@ static const struct file_operations sta_ ##name## _ops = { \
44 STA_OPS(name) 44 STA_OPS(name)
45 45
46STA_FILE(aid, sta.aid, D); 46STA_FILE(aid, sta.aid, D);
47STA_FILE(dev, sdata->dev->name, S); 47STA_FILE(dev, sdata->name, S);
48STA_FILE(rx_packets, rx_packets, LU); 48STA_FILE(rx_packets, rx_packets, LU);
49STA_FILE(tx_packets, tx_packets, LU); 49STA_FILE(tx_packets, tx_packets, LU);
50STA_FILE(rx_bytes, rx_bytes, LU); 50STA_FILE(rx_bytes, rx_bytes, LU);
@@ -57,7 +57,6 @@ STA_FILE(tx_filtered, tx_filtered_count, LU);
57STA_FILE(tx_retry_failed, tx_retry_failed, LU); 57STA_FILE(tx_retry_failed, tx_retry_failed, LU);
58STA_FILE(tx_retry_count, tx_retry_count, LU); 58STA_FILE(tx_retry_count, tx_retry_count, LU);
59STA_FILE(last_signal, last_signal, D); 59STA_FILE(last_signal, last_signal, D);
60STA_FILE(last_qual, last_qual, D);
61STA_FILE(last_noise, last_noise, D); 60STA_FILE(last_noise, last_noise, D);
62STA_FILE(wep_weak_iv_count, wep_weak_iv_count, LU); 61STA_FILE(wep_weak_iv_count, wep_weak_iv_count, LU);
63 62
@@ -67,10 +66,11 @@ static ssize_t sta_flags_read(struct file *file, char __user *userbuf,
67 char buf[100]; 66 char buf[100];
68 struct sta_info *sta = file->private_data; 67 struct sta_info *sta = file->private_data;
69 u32 staflags = get_sta_flags(sta); 68 u32 staflags = get_sta_flags(sta);
70 int res = scnprintf(buf, sizeof(buf), "%s%s%s%s%s%s%s%s", 69 int res = scnprintf(buf, sizeof(buf), "%s%s%s%s%s%s%s%s%s",
71 staflags & WLAN_STA_AUTH ? "AUTH\n" : "", 70 staflags & WLAN_STA_AUTH ? "AUTH\n" : "",
72 staflags & WLAN_STA_ASSOC ? "ASSOC\n" : "", 71 staflags & WLAN_STA_ASSOC ? "ASSOC\n" : "",
73 staflags & WLAN_STA_PS ? "PS\n" : "", 72 staflags & WLAN_STA_PS_STA ? "PS (sta)\n" : "",
73 staflags & WLAN_STA_PS_DRIVER ? "PS (driver)\n" : "",
74 staflags & WLAN_STA_AUTHORIZED ? "AUTHORIZED\n" : "", 74 staflags & WLAN_STA_AUTHORIZED ? "AUTHORIZED\n" : "",
75 staflags & WLAN_STA_SHORT_PREAMBLE ? "SHORT PREAMBLE\n" : "", 75 staflags & WLAN_STA_SHORT_PREAMBLE ? "SHORT PREAMBLE\n" : "",
76 staflags & WLAN_STA_WME ? "WME\n" : "", 76 staflags & WLAN_STA_WME ? "WME\n" : "",
@@ -120,36 +120,38 @@ STA_OPS(last_seq_ctrl);
120static ssize_t sta_agg_status_read(struct file *file, char __user *userbuf, 120static ssize_t sta_agg_status_read(struct file *file, char __user *userbuf,
121 size_t count, loff_t *ppos) 121 size_t count, loff_t *ppos)
122{ 122{
123 char buf[30 + STA_TID_NUM * 70], *p = buf; 123 char buf[64 + STA_TID_NUM * 40], *p = buf;
124 int i; 124 int i;
125 struct sta_info *sta = file->private_data; 125 struct sta_info *sta = file->private_data;
126 126
127 spin_lock_bh(&sta->lock); 127 spin_lock_bh(&sta->lock);
128 p += scnprintf(p, sizeof(buf)+buf-p, "next dialog_token is %#02x\n", 128 p += scnprintf(p, sizeof(buf) + buf - p, "next dialog_token: %#02x\n",
129 sta->ampdu_mlme.dialog_token_allocator + 1); 129 sta->ampdu_mlme.dialog_token_allocator + 1);
130 p += scnprintf(p, sizeof(buf) + buf - p,
131 "TID\t\tRX\tDTKN\tSSN\t\tTX\tDTKN\tSSN\tpending\n");
130 for (i = 0; i < STA_TID_NUM; i++) { 132 for (i = 0; i < STA_TID_NUM; i++) {
131 p += scnprintf(p, sizeof(buf)+buf-p, "TID %02d:", i); 133 p += scnprintf(p, sizeof(buf) + buf - p, "%02d", i);
132 p += scnprintf(p, sizeof(buf)+buf-p, " RX=%x", 134 p += scnprintf(p, sizeof(buf) + buf - p, "\t\t%x",
133 sta->ampdu_mlme.tid_state_rx[i]); 135 sta->ampdu_mlme.tid_state_rx[i]);
134 p += scnprintf(p, sizeof(buf)+buf-p, "/DTKN=%#.2x", 136 p += scnprintf(p, sizeof(buf) + buf - p, "\t%#.2x",
135 sta->ampdu_mlme.tid_state_rx[i] ? 137 sta->ampdu_mlme.tid_state_rx[i] ?
136 sta->ampdu_mlme.tid_rx[i]->dialog_token : 0); 138 sta->ampdu_mlme.tid_rx[i]->dialog_token : 0);
137 p += scnprintf(p, sizeof(buf)+buf-p, "/SSN=%#.3x", 139 p += scnprintf(p, sizeof(buf) + buf - p, "\t%#.3x",
138 sta->ampdu_mlme.tid_state_rx[i] ? 140 sta->ampdu_mlme.tid_state_rx[i] ?
139 sta->ampdu_mlme.tid_rx[i]->ssn : 0); 141 sta->ampdu_mlme.tid_rx[i]->ssn : 0);
140 142
141 p += scnprintf(p, sizeof(buf)+buf-p, " TX=%x", 143 p += scnprintf(p, sizeof(buf) + buf - p, "\t\t%x",
142 sta->ampdu_mlme.tid_state_tx[i]); 144 sta->ampdu_mlme.tid_state_tx[i]);
143 p += scnprintf(p, sizeof(buf)+buf-p, "/DTKN=%#.2x", 145 p += scnprintf(p, sizeof(buf) + buf - p, "\t%#.2x",
144 sta->ampdu_mlme.tid_state_tx[i] ? 146 sta->ampdu_mlme.tid_state_tx[i] ?
145 sta->ampdu_mlme.tid_tx[i]->dialog_token : 0); 147 sta->ampdu_mlme.tid_tx[i]->dialog_token : 0);
146 p += scnprintf(p, sizeof(buf)+buf-p, "/SSN=%#.3x", 148 p += scnprintf(p, sizeof(buf) + buf - p, "\t%#.3x",
147 sta->ampdu_mlme.tid_state_tx[i] ? 149 sta->ampdu_mlme.tid_state_tx[i] ?
148 sta->ampdu_mlme.tid_tx[i]->ssn : 0); 150 sta->ampdu_mlme.tid_tx[i]->ssn : 0);
149 p += scnprintf(p, sizeof(buf)+buf-p, "/pending=%03d", 151 p += scnprintf(p, sizeof(buf) + buf - p, "\t%03d",
150 sta->ampdu_mlme.tid_state_tx[i] ? 152 sta->ampdu_mlme.tid_state_tx[i] ?
151 skb_queue_len(&sta->ampdu_mlme.tid_tx[i]->pending) : 0); 153 skb_queue_len(&sta->ampdu_mlme.tid_tx[i]->pending) : 0);
152 p += scnprintf(p, sizeof(buf)+buf-p, "\n"); 154 p += scnprintf(p, sizeof(buf) + buf - p, "\n");
153 } 155 }
154 spin_unlock_bh(&sta->lock); 156 spin_unlock_bh(&sta->lock);
155 157
@@ -157,14 +159,92 @@ static ssize_t sta_agg_status_read(struct file *file, char __user *userbuf,
157} 159}
158STA_OPS(agg_status); 160STA_OPS(agg_status);
159 161
162static ssize_t sta_ht_capa_read(struct file *file, char __user *userbuf,
163 size_t count, loff_t *ppos)
164{
165#define PRINT_HT_CAP(_cond, _str) \
166 do { \
167 if (_cond) \
168 p += scnprintf(p, sizeof(buf)+buf-p, "\t" _str "\n"); \
169 } while (0)
170 char buf[512], *p = buf;
171 int i;
172 struct sta_info *sta = file->private_data;
173 struct ieee80211_sta_ht_cap *htc = &sta->sta.ht_cap;
174
175 p += scnprintf(p, sizeof(buf) + buf - p, "ht %ssupported\n",
176 htc->ht_supported ? "" : "not ");
177 if (htc->ht_supported) {
178 p += scnprintf(p, sizeof(buf)+buf-p, "cap: %#.4x\n", htc->cap);
179
180 PRINT_HT_CAP((htc->cap & BIT(0)), "RX LDCP");
181 PRINT_HT_CAP((htc->cap & BIT(1)), "HT20/HT40");
182 PRINT_HT_CAP(!(htc->cap & BIT(1)), "HT20");
183
184 PRINT_HT_CAP(((htc->cap >> 2) & 0x3) == 0, "Static SM Power Save");
185 PRINT_HT_CAP(((htc->cap >> 2) & 0x3) == 1, "Dynamic SM Power Save");
186 PRINT_HT_CAP(((htc->cap >> 2) & 0x3) == 3, "SM Power Save disabled");
187
188 PRINT_HT_CAP((htc->cap & BIT(4)), "RX Greenfield");
189 PRINT_HT_CAP((htc->cap & BIT(5)), "RX HT20 SGI");
190 PRINT_HT_CAP((htc->cap & BIT(6)), "RX HT40 SGI");
191 PRINT_HT_CAP((htc->cap & BIT(7)), "TX STBC");
192
193 PRINT_HT_CAP(((htc->cap >> 8) & 0x3) == 0, "No RX STBC");
194 PRINT_HT_CAP(((htc->cap >> 8) & 0x3) == 1, "RX STBC 1-stream");
195 PRINT_HT_CAP(((htc->cap >> 8) & 0x3) == 2, "RX STBC 2-streams");
196 PRINT_HT_CAP(((htc->cap >> 8) & 0x3) == 3, "RX STBC 3-streams");
197
198 PRINT_HT_CAP((htc->cap & BIT(10)), "HT Delayed Block Ack");
199
200 PRINT_HT_CAP((htc->cap & BIT(11)), "Max AMSDU length: "
201 "3839 bytes");
202 PRINT_HT_CAP(!(htc->cap & BIT(11)), "Max AMSDU length: "
203 "7935 bytes");
204
205 /*
206 * For beacons and probe response this would mean the BSS
207 * does or does not allow the usage of DSSS/CCK HT40.
208 * Otherwise it means the STA does or does not use
209 * DSSS/CCK HT40.
210 */
211 PRINT_HT_CAP((htc->cap & BIT(12)), "DSSS/CCK HT40");
212 PRINT_HT_CAP(!(htc->cap & BIT(12)), "No DSSS/CCK HT40");
213
214 /* BIT(13) is reserved */
215
216 PRINT_HT_CAP((htc->cap & BIT(14)), "40 MHz Intolerant");
217
218 PRINT_HT_CAP((htc->cap & BIT(15)), "L-SIG TXOP protection");
219
220 p += scnprintf(p, sizeof(buf)+buf-p, "ampdu factor/density: %d/%d\n",
221 htc->ampdu_factor, htc->ampdu_density);
222 p += scnprintf(p, sizeof(buf)+buf-p, "MCS mask:");
223
224 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
225 p += scnprintf(p, sizeof(buf)+buf-p, " %.2x",
226 htc->mcs.rx_mask[i]);
227 p += scnprintf(p, sizeof(buf)+buf-p, "\n");
228
229 /* If not set this is meaningless */
230 if (le16_to_cpu(htc->mcs.rx_highest)) {
231 p += scnprintf(p, sizeof(buf)+buf-p,
232 "MCS rx highest: %d Mbps\n",
233 le16_to_cpu(htc->mcs.rx_highest));
234 }
235
236 p += scnprintf(p, sizeof(buf)+buf-p, "MCS tx params: %x\n",
237 htc->mcs.tx_params);
238 }
239
240 return simple_read_from_buffer(userbuf, count, ppos, buf, p - buf);
241}
242STA_OPS(ht_capa);
243
160#define DEBUGFS_ADD(name) \ 244#define DEBUGFS_ADD(name) \
161 sta->debugfs.name = debugfs_create_file(#name, 0400, \ 245 debugfs_create_file(#name, 0400, \
162 sta->debugfs.dir, sta, &sta_ ##name## _ops); 246 sta->debugfs.dir, sta, &sta_ ##name## _ops);
163 247
164#define DEBUGFS_DEL(name) \
165 debugfs_remove(sta->debugfs.name);\
166 sta->debugfs.name = NULL;
167
168 248
169void ieee80211_sta_debugfs_add(struct sta_info *sta) 249void ieee80211_sta_debugfs_add(struct sta_info *sta)
170{ 250{
@@ -209,36 +289,13 @@ void ieee80211_sta_debugfs_add(struct sta_info *sta)
209 DEBUGFS_ADD(tx_retry_failed); 289 DEBUGFS_ADD(tx_retry_failed);
210 DEBUGFS_ADD(tx_retry_count); 290 DEBUGFS_ADD(tx_retry_count);
211 DEBUGFS_ADD(last_signal); 291 DEBUGFS_ADD(last_signal);
212 DEBUGFS_ADD(last_qual);
213 DEBUGFS_ADD(last_noise); 292 DEBUGFS_ADD(last_noise);
214 DEBUGFS_ADD(wep_weak_iv_count); 293 DEBUGFS_ADD(wep_weak_iv_count);
294 DEBUGFS_ADD(ht_capa);
215} 295}
216 296
217void ieee80211_sta_debugfs_remove(struct sta_info *sta) 297void ieee80211_sta_debugfs_remove(struct sta_info *sta)
218{ 298{
219 DEBUGFS_DEL(flags); 299 debugfs_remove_recursive(sta->debugfs.dir);
220 DEBUGFS_DEL(num_ps_buf_frames);
221 DEBUGFS_DEL(inactive_ms);
222 DEBUGFS_DEL(last_seq_ctrl);
223 DEBUGFS_DEL(agg_status);
224 DEBUGFS_DEL(aid);
225 DEBUGFS_DEL(dev);
226 DEBUGFS_DEL(rx_packets);
227 DEBUGFS_DEL(tx_packets);
228 DEBUGFS_DEL(rx_bytes);
229 DEBUGFS_DEL(tx_bytes);
230 DEBUGFS_DEL(rx_duplicates);
231 DEBUGFS_DEL(rx_fragments);
232 DEBUGFS_DEL(rx_dropped);
233 DEBUGFS_DEL(tx_fragments);
234 DEBUGFS_DEL(tx_filtered);
235 DEBUGFS_DEL(tx_retry_failed);
236 DEBUGFS_DEL(tx_retry_count);
237 DEBUGFS_DEL(last_signal);
238 DEBUGFS_DEL(last_qual);
239 DEBUGFS_DEL(last_noise);
240 DEBUGFS_DEL(wep_weak_iv_count);
241
242 debugfs_remove(sta->debugfs.dir);
243 sta->debugfs.dir = NULL; 300 sta->debugfs.dir = NULL;
244} 301}
diff --git a/net/mac80211/driver-ops.h b/net/mac80211/driver-ops.h
index 020a94a31106..c3d844093a2f 100644
--- a/net/mac80211/driver-ops.h
+++ b/net/mac80211/driver-ops.h
@@ -14,6 +14,8 @@ static inline int drv_start(struct ieee80211_local *local)
14{ 14{
15 int ret; 15 int ret;
16 16
17 might_sleep();
18
17 local->started = true; 19 local->started = true;
18 smp_mb(); 20 smp_mb();
19 ret = local->ops->start(&local->hw); 21 ret = local->ops->start(&local->hw);
@@ -23,6 +25,8 @@ static inline int drv_start(struct ieee80211_local *local)
23 25
24static inline void drv_stop(struct ieee80211_local *local) 26static inline void drv_stop(struct ieee80211_local *local)
25{ 27{
28 might_sleep();
29
26 local->ops->stop(&local->hw); 30 local->ops->stop(&local->hw);
27 trace_drv_stop(local); 31 trace_drv_stop(local);
28 32
@@ -36,35 +40,47 @@ static inline void drv_stop(struct ieee80211_local *local)
36} 40}
37 41
38static inline int drv_add_interface(struct ieee80211_local *local, 42static inline int drv_add_interface(struct ieee80211_local *local,
39 struct ieee80211_if_init_conf *conf) 43 struct ieee80211_vif *vif)
40{ 44{
41 int ret = local->ops->add_interface(&local->hw, conf); 45 int ret;
42 trace_drv_add_interface(local, conf->mac_addr, conf->vif, ret); 46
47 might_sleep();
48
49 ret = local->ops->add_interface(&local->hw, vif);
50 trace_drv_add_interface(local, vif_to_sdata(vif), ret);
43 return ret; 51 return ret;
44} 52}
45 53
46static inline void drv_remove_interface(struct ieee80211_local *local, 54static inline void drv_remove_interface(struct ieee80211_local *local,
47 struct ieee80211_if_init_conf *conf) 55 struct ieee80211_vif *vif)
48{ 56{
49 local->ops->remove_interface(&local->hw, conf); 57 might_sleep();
50 trace_drv_remove_interface(local, conf->mac_addr, conf->vif); 58
59 local->ops->remove_interface(&local->hw, vif);
60 trace_drv_remove_interface(local, vif_to_sdata(vif));
51} 61}
52 62
53static inline int drv_config(struct ieee80211_local *local, u32 changed) 63static inline int drv_config(struct ieee80211_local *local, u32 changed)
54{ 64{
55 int ret = local->ops->config(&local->hw, changed); 65 int ret;
66
67 might_sleep();
68
69 ret = local->ops->config(&local->hw, changed);
56 trace_drv_config(local, changed, ret); 70 trace_drv_config(local, changed, ret);
57 return ret; 71 return ret;
58} 72}
59 73
60static inline void drv_bss_info_changed(struct ieee80211_local *local, 74static inline void drv_bss_info_changed(struct ieee80211_local *local,
61 struct ieee80211_vif *vif, 75 struct ieee80211_sub_if_data *sdata,
62 struct ieee80211_bss_conf *info, 76 struct ieee80211_bss_conf *info,
63 u32 changed) 77 u32 changed)
64{ 78{
79 might_sleep();
80
65 if (local->ops->bss_info_changed) 81 if (local->ops->bss_info_changed)
66 local->ops->bss_info_changed(&local->hw, vif, info, changed); 82 local->ops->bss_info_changed(&local->hw, &sdata->vif, info, changed);
67 trace_drv_bss_info_changed(local, vif, info, changed); 83 trace_drv_bss_info_changed(local, sdata, info, changed);
68} 84}
69 85
70static inline u64 drv_prepare_multicast(struct ieee80211_local *local, 86static inline u64 drv_prepare_multicast(struct ieee80211_local *local,
@@ -106,36 +122,53 @@ static inline int drv_set_tim(struct ieee80211_local *local,
106} 122}
107 123
108static inline int drv_set_key(struct ieee80211_local *local, 124static inline int drv_set_key(struct ieee80211_local *local,
109 enum set_key_cmd cmd, struct ieee80211_vif *vif, 125 enum set_key_cmd cmd,
126 struct ieee80211_sub_if_data *sdata,
110 struct ieee80211_sta *sta, 127 struct ieee80211_sta *sta,
111 struct ieee80211_key_conf *key) 128 struct ieee80211_key_conf *key)
112{ 129{
113 int ret = local->ops->set_key(&local->hw, cmd, vif, sta, key); 130 int ret;
114 trace_drv_set_key(local, cmd, vif, sta, key, ret); 131
132 might_sleep();
133
134 ret = local->ops->set_key(&local->hw, cmd, &sdata->vif, sta, key);
135 trace_drv_set_key(local, cmd, sdata, sta, key, ret);
115 return ret; 136 return ret;
116} 137}
117 138
118static inline void drv_update_tkip_key(struct ieee80211_local *local, 139static inline void drv_update_tkip_key(struct ieee80211_local *local,
140 struct ieee80211_sub_if_data *sdata,
119 struct ieee80211_key_conf *conf, 141 struct ieee80211_key_conf *conf,
120 const u8 *address, u32 iv32, 142 struct sta_info *sta, u32 iv32,
121 u16 *phase1key) 143 u16 *phase1key)
122{ 144{
145 struct ieee80211_sta *ista = NULL;
146
147 if (sta)
148 ista = &sta->sta;
149
123 if (local->ops->update_tkip_key) 150 if (local->ops->update_tkip_key)
124 local->ops->update_tkip_key(&local->hw, conf, address, 151 local->ops->update_tkip_key(&local->hw, &sdata->vif, conf,
125 iv32, phase1key); 152 ista, iv32, phase1key);
126 trace_drv_update_tkip_key(local, conf, address, iv32); 153 trace_drv_update_tkip_key(local, sdata, conf, ista, iv32);
127} 154}
128 155
129static inline int drv_hw_scan(struct ieee80211_local *local, 156static inline int drv_hw_scan(struct ieee80211_local *local,
130 struct cfg80211_scan_request *req) 157 struct cfg80211_scan_request *req)
131{ 158{
132 int ret = local->ops->hw_scan(&local->hw, req); 159 int ret;
160
161 might_sleep();
162
163 ret = local->ops->hw_scan(&local->hw, req);
133 trace_drv_hw_scan(local, req, ret); 164 trace_drv_hw_scan(local, req, ret);
134 return ret; 165 return ret;
135} 166}
136 167
137static inline void drv_sw_scan_start(struct ieee80211_local *local) 168static inline void drv_sw_scan_start(struct ieee80211_local *local)
138{ 169{
170 might_sleep();
171
139 if (local->ops->sw_scan_start) 172 if (local->ops->sw_scan_start)
140 local->ops->sw_scan_start(&local->hw); 173 local->ops->sw_scan_start(&local->hw);
141 trace_drv_sw_scan_start(local); 174 trace_drv_sw_scan_start(local);
@@ -143,6 +176,8 @@ static inline void drv_sw_scan_start(struct ieee80211_local *local)
143 176
144static inline void drv_sw_scan_complete(struct ieee80211_local *local) 177static inline void drv_sw_scan_complete(struct ieee80211_local *local)
145{ 178{
179 might_sleep();
180
146 if (local->ops->sw_scan_complete) 181 if (local->ops->sw_scan_complete)
147 local->ops->sw_scan_complete(&local->hw); 182 local->ops->sw_scan_complete(&local->hw);
148 trace_drv_sw_scan_complete(local); 183 trace_drv_sw_scan_complete(local);
@@ -153,6 +188,8 @@ static inline int drv_get_stats(struct ieee80211_local *local,
153{ 188{
154 int ret = -EOPNOTSUPP; 189 int ret = -EOPNOTSUPP;
155 190
191 might_sleep();
192
156 if (local->ops->get_stats) 193 if (local->ops->get_stats)
157 ret = local->ops->get_stats(&local->hw, stats); 194 ret = local->ops->get_stats(&local->hw, stats);
158 trace_drv_get_stats(local, stats, ret); 195 trace_drv_get_stats(local, stats, ret);
@@ -172,43 +209,93 @@ static inline int drv_set_rts_threshold(struct ieee80211_local *local,
172 u32 value) 209 u32 value)
173{ 210{
174 int ret = 0; 211 int ret = 0;
212
213 might_sleep();
214
175 if (local->ops->set_rts_threshold) 215 if (local->ops->set_rts_threshold)
176 ret = local->ops->set_rts_threshold(&local->hw, value); 216 ret = local->ops->set_rts_threshold(&local->hw, value);
177 trace_drv_set_rts_threshold(local, value, ret); 217 trace_drv_set_rts_threshold(local, value, ret);
178 return ret; 218 return ret;
179} 219}
180 220
221static inline int drv_set_coverage_class(struct ieee80211_local *local,
222 u8 value)
223{
224 int ret = 0;
225 might_sleep();
226
227 if (local->ops->set_coverage_class)
228 local->ops->set_coverage_class(&local->hw, value);
229 else
230 ret = -EOPNOTSUPP;
231
232 trace_drv_set_coverage_class(local, value, ret);
233 return ret;
234}
235
181static inline void drv_sta_notify(struct ieee80211_local *local, 236static inline void drv_sta_notify(struct ieee80211_local *local,
182 struct ieee80211_vif *vif, 237 struct ieee80211_sub_if_data *sdata,
183 enum sta_notify_cmd cmd, 238 enum sta_notify_cmd cmd,
184 struct ieee80211_sta *sta) 239 struct ieee80211_sta *sta)
185{ 240{
186 if (local->ops->sta_notify) 241 if (local->ops->sta_notify)
187 local->ops->sta_notify(&local->hw, vif, cmd, sta); 242 local->ops->sta_notify(&local->hw, &sdata->vif, cmd, sta);
188 trace_drv_sta_notify(local, vif, cmd, sta); 243 trace_drv_sta_notify(local, sdata, cmd, sta);
244}
245
246static inline int drv_sta_add(struct ieee80211_local *local,
247 struct ieee80211_sub_if_data *sdata,
248 struct ieee80211_sta *sta)
249{
250 int ret = 0;
251
252 might_sleep();
253
254 if (local->ops->sta_add)
255 ret = local->ops->sta_add(&local->hw, &sdata->vif, sta);
256 else if (local->ops->sta_notify)
257 local->ops->sta_notify(&local->hw, &sdata->vif,
258 STA_NOTIFY_ADD, sta);
259
260 trace_drv_sta_add(local, sdata, sta, ret);
261
262 return ret;
263}
264
265static inline void drv_sta_remove(struct ieee80211_local *local,
266 struct ieee80211_sub_if_data *sdata,
267 struct ieee80211_sta *sta)
268{
269 might_sleep();
270
271 if (local->ops->sta_remove)
272 local->ops->sta_remove(&local->hw, &sdata->vif, sta);
273 else if (local->ops->sta_notify)
274 local->ops->sta_notify(&local->hw, &sdata->vif,
275 STA_NOTIFY_REMOVE, sta);
276
277 trace_drv_sta_remove(local, sdata, sta);
189} 278}
190 279
191static inline int drv_conf_tx(struct ieee80211_local *local, u16 queue, 280static inline int drv_conf_tx(struct ieee80211_local *local, u16 queue,
192 const struct ieee80211_tx_queue_params *params) 281 const struct ieee80211_tx_queue_params *params)
193{ 282{
194 int ret = -EOPNOTSUPP; 283 int ret = -EOPNOTSUPP;
284
285 might_sleep();
286
195 if (local->ops->conf_tx) 287 if (local->ops->conf_tx)
196 ret = local->ops->conf_tx(&local->hw, queue, params); 288 ret = local->ops->conf_tx(&local->hw, queue, params);
197 trace_drv_conf_tx(local, queue, params, ret); 289 trace_drv_conf_tx(local, queue, params, ret);
198 return ret; 290 return ret;
199} 291}
200 292
201static inline int drv_get_tx_stats(struct ieee80211_local *local,
202 struct ieee80211_tx_queue_stats *stats)
203{
204 int ret = local->ops->get_tx_stats(&local->hw, stats);
205 trace_drv_get_tx_stats(local, stats, ret);
206 return ret;
207}
208
209static inline u64 drv_get_tsf(struct ieee80211_local *local) 293static inline u64 drv_get_tsf(struct ieee80211_local *local)
210{ 294{
211 u64 ret = -1ULL; 295 u64 ret = -1ULL;
296
297 might_sleep();
298
212 if (local->ops->get_tsf) 299 if (local->ops->get_tsf)
213 ret = local->ops->get_tsf(&local->hw); 300 ret = local->ops->get_tsf(&local->hw);
214 trace_drv_get_tsf(local, ret); 301 trace_drv_get_tsf(local, ret);
@@ -217,6 +304,8 @@ static inline u64 drv_get_tsf(struct ieee80211_local *local)
217 304
218static inline void drv_set_tsf(struct ieee80211_local *local, u64 tsf) 305static inline void drv_set_tsf(struct ieee80211_local *local, u64 tsf)
219{ 306{
307 might_sleep();
308
220 if (local->ops->set_tsf) 309 if (local->ops->set_tsf)
221 local->ops->set_tsf(&local->hw, tsf); 310 local->ops->set_tsf(&local->hw, tsf);
222 trace_drv_set_tsf(local, tsf); 311 trace_drv_set_tsf(local, tsf);
@@ -224,6 +313,8 @@ static inline void drv_set_tsf(struct ieee80211_local *local, u64 tsf)
224 313
225static inline void drv_reset_tsf(struct ieee80211_local *local) 314static inline void drv_reset_tsf(struct ieee80211_local *local)
226{ 315{
316 might_sleep();
317
227 if (local->ops->reset_tsf) 318 if (local->ops->reset_tsf)
228 local->ops->reset_tsf(&local->hw); 319 local->ops->reset_tsf(&local->hw);
229 trace_drv_reset_tsf(local); 320 trace_drv_reset_tsf(local);
@@ -232,6 +323,9 @@ static inline void drv_reset_tsf(struct ieee80211_local *local)
232static inline int drv_tx_last_beacon(struct ieee80211_local *local) 323static inline int drv_tx_last_beacon(struct ieee80211_local *local)
233{ 324{
234 int ret = 1; 325 int ret = 1;
326
327 might_sleep();
328
235 if (local->ops->tx_last_beacon) 329 if (local->ops->tx_last_beacon)
236 ret = local->ops->tx_last_beacon(&local->hw); 330 ret = local->ops->tx_last_beacon(&local->hw);
237 trace_drv_tx_last_beacon(local, ret); 331 trace_drv_tx_last_beacon(local, ret);
@@ -239,22 +333,34 @@ static inline int drv_tx_last_beacon(struct ieee80211_local *local)
239} 333}
240 334
241static inline int drv_ampdu_action(struct ieee80211_local *local, 335static inline int drv_ampdu_action(struct ieee80211_local *local,
336 struct ieee80211_sub_if_data *sdata,
242 enum ieee80211_ampdu_mlme_action action, 337 enum ieee80211_ampdu_mlme_action action,
243 struct ieee80211_sta *sta, u16 tid, 338 struct ieee80211_sta *sta, u16 tid,
244 u16 *ssn) 339 u16 *ssn)
245{ 340{
246 int ret = -EOPNOTSUPP; 341 int ret = -EOPNOTSUPP;
247 if (local->ops->ampdu_action) 342 if (local->ops->ampdu_action)
248 ret = local->ops->ampdu_action(&local->hw, action, 343 ret = local->ops->ampdu_action(&local->hw, &sdata->vif, action,
249 sta, tid, ssn); 344 sta, tid, ssn);
250 trace_drv_ampdu_action(local, action, sta, tid, ssn, ret); 345 trace_drv_ampdu_action(local, sdata, action, sta, tid, ssn, ret);
251 return ret; 346 return ret;
252} 347}
253 348
254 349
255static inline void drv_rfkill_poll(struct ieee80211_local *local) 350static inline void drv_rfkill_poll(struct ieee80211_local *local)
256{ 351{
352 might_sleep();
353
257 if (local->ops->rfkill_poll) 354 if (local->ops->rfkill_poll)
258 local->ops->rfkill_poll(&local->hw); 355 local->ops->rfkill_poll(&local->hw);
259} 356}
357
358static inline void drv_flush(struct ieee80211_local *local, bool drop)
359{
360 might_sleep();
361
362 trace_drv_flush(local, drop);
363 if (local->ops->flush)
364 local->ops->flush(&local->hw, drop);
365}
260#endif /* __MAC80211_DRIVER_OPS */ 366#endif /* __MAC80211_DRIVER_OPS */
diff --git a/net/mac80211/driver-trace.h b/net/mac80211/driver-trace.h
index 37b9051afcf3..41baf730a5c7 100644
--- a/net/mac80211/driver-trace.h
+++ b/net/mac80211/driver-trace.h
@@ -25,10 +25,12 @@ static inline void trace_ ## name(proto) {}
25#define STA_PR_FMT " sta:%pM" 25#define STA_PR_FMT " sta:%pM"
26#define STA_PR_ARG __entry->sta_addr 26#define STA_PR_ARG __entry->sta_addr
27 27
28#define VIF_ENTRY __field(enum nl80211_iftype, vif_type) __field(void *, vif) 28#define VIF_ENTRY __field(enum nl80211_iftype, vif_type) __field(void *, sdata) \
29#define VIF_ASSIGN __entry->vif_type = vif ? vif->type : 0; __entry->vif = vif 29 __string(vif_name, sdata->dev ? sdata->dev->name : "<nodev>")
30#define VIF_PR_FMT " vif:%p(%d)" 30#define VIF_ASSIGN __entry->vif_type = sdata->vif.type; __entry->sdata = sdata; \
31#define VIF_PR_ARG __entry->vif, __entry->vif_type 31 __assign_str(vif_name, sdata->dev ? sdata->dev->name : "<nodev>")
32#define VIF_PR_FMT " vif:%s(%d)"
33#define VIF_PR_ARG __get_str(vif_name), __entry->vif_type
32 34
33TRACE_EVENT(drv_start, 35TRACE_EVENT(drv_start,
34 TP_PROTO(struct ieee80211_local *local, int ret), 36 TP_PROTO(struct ieee80211_local *local, int ret),
@@ -70,11 +72,10 @@ TRACE_EVENT(drv_stop,
70 72
71TRACE_EVENT(drv_add_interface, 73TRACE_EVENT(drv_add_interface,
72 TP_PROTO(struct ieee80211_local *local, 74 TP_PROTO(struct ieee80211_local *local,
73 const u8 *addr, 75 struct ieee80211_sub_if_data *sdata,
74 struct ieee80211_vif *vif,
75 int ret), 76 int ret),
76 77
77 TP_ARGS(local, addr, vif, ret), 78 TP_ARGS(local, sdata, ret),
78 79
79 TP_STRUCT__entry( 80 TP_STRUCT__entry(
80 LOCAL_ENTRY 81 LOCAL_ENTRY
@@ -86,7 +87,7 @@ TRACE_EVENT(drv_add_interface,
86 TP_fast_assign( 87 TP_fast_assign(
87 LOCAL_ASSIGN; 88 LOCAL_ASSIGN;
88 VIF_ASSIGN; 89 VIF_ASSIGN;
89 memcpy(__entry->addr, addr, 6); 90 memcpy(__entry->addr, sdata->vif.addr, 6);
90 __entry->ret = ret; 91 __entry->ret = ret;
91 ), 92 ),
92 93
@@ -97,10 +98,9 @@ TRACE_EVENT(drv_add_interface,
97); 98);
98 99
99TRACE_EVENT(drv_remove_interface, 100TRACE_EVENT(drv_remove_interface,
100 TP_PROTO(struct ieee80211_local *local, 101 TP_PROTO(struct ieee80211_local *local, struct ieee80211_sub_if_data *sdata),
101 const u8 *addr, struct ieee80211_vif *vif),
102 102
103 TP_ARGS(local, addr, vif), 103 TP_ARGS(local, sdata),
104 104
105 TP_STRUCT__entry( 105 TP_STRUCT__entry(
106 LOCAL_ENTRY 106 LOCAL_ENTRY
@@ -111,7 +111,7 @@ TRACE_EVENT(drv_remove_interface,
111 TP_fast_assign( 111 TP_fast_assign(
112 LOCAL_ASSIGN; 112 LOCAL_ASSIGN;
113 VIF_ASSIGN; 113 VIF_ASSIGN;
114 memcpy(__entry->addr, addr, 6); 114 memcpy(__entry->addr, sdata->vif.addr, 6);
115 ), 115 ),
116 116
117 TP_printk( 117 TP_printk(
@@ -131,27 +131,47 @@ TRACE_EVENT(drv_config,
131 LOCAL_ENTRY 131 LOCAL_ENTRY
132 __field(u32, changed) 132 __field(u32, changed)
133 __field(int, ret) 133 __field(int, ret)
134 __field(u32, flags)
135 __field(int, power_level)
136 __field(int, dynamic_ps_timeout)
137 __field(int, max_sleep_period)
138 __field(u16, listen_interval)
139 __field(u8, long_frame_max_tx_count)
140 __field(u8, short_frame_max_tx_count)
141 __field(int, center_freq)
142 __field(int, channel_type)
143 __field(int, smps)
134 ), 144 ),
135 145
136 TP_fast_assign( 146 TP_fast_assign(
137 LOCAL_ASSIGN; 147 LOCAL_ASSIGN;
138 __entry->changed = changed; 148 __entry->changed = changed;
139 __entry->ret = ret; 149 __entry->ret = ret;
150 __entry->flags = local->hw.conf.flags;
151 __entry->power_level = local->hw.conf.power_level;
152 __entry->dynamic_ps_timeout = local->hw.conf.dynamic_ps_timeout;
153 __entry->max_sleep_period = local->hw.conf.max_sleep_period;
154 __entry->listen_interval = local->hw.conf.listen_interval;
155 __entry->long_frame_max_tx_count = local->hw.conf.long_frame_max_tx_count;
156 __entry->short_frame_max_tx_count = local->hw.conf.short_frame_max_tx_count;
157 __entry->center_freq = local->hw.conf.channel->center_freq;
158 __entry->channel_type = local->hw.conf.channel_type;
159 __entry->smps = local->hw.conf.smps_mode;
140 ), 160 ),
141 161
142 TP_printk( 162 TP_printk(
143 LOCAL_PR_FMT " ch:%#x ret:%d", 163 LOCAL_PR_FMT " ch:%#x freq:%d ret:%d",
144 LOCAL_PR_ARG, __entry->changed, __entry->ret 164 LOCAL_PR_ARG, __entry->changed, __entry->center_freq, __entry->ret
145 ) 165 )
146); 166);
147 167
148TRACE_EVENT(drv_bss_info_changed, 168TRACE_EVENT(drv_bss_info_changed,
149 TP_PROTO(struct ieee80211_local *local, 169 TP_PROTO(struct ieee80211_local *local,
150 struct ieee80211_vif *vif, 170 struct ieee80211_sub_if_data *sdata,
151 struct ieee80211_bss_conf *info, 171 struct ieee80211_bss_conf *info,
152 u32 changed), 172 u32 changed),
153 173
154 TP_ARGS(local, vif, info, changed), 174 TP_ARGS(local, sdata, info, changed),
155 175
156 TP_STRUCT__entry( 176 TP_STRUCT__entry(
157 LOCAL_ENTRY 177 LOCAL_ENTRY
@@ -167,6 +187,8 @@ TRACE_EVENT(drv_bss_info_changed,
167 __field(u64, timestamp) 187 __field(u64, timestamp)
168 __field(u32, basic_rates) 188 __field(u32, basic_rates)
169 __field(u32, changed) 189 __field(u32, changed)
190 __field(bool, enable_beacon)
191 __field(u16, ht_operation_mode)
170 ), 192 ),
171 193
172 TP_fast_assign( 194 TP_fast_assign(
@@ -183,6 +205,8 @@ TRACE_EVENT(drv_bss_info_changed,
183 __entry->assoc_cap = info->assoc_capability; 205 __entry->assoc_cap = info->assoc_capability;
184 __entry->timestamp = info->timestamp; 206 __entry->timestamp = info->timestamp;
185 __entry->basic_rates = info->basic_rates; 207 __entry->basic_rates = info->basic_rates;
208 __entry->enable_beacon = info->enable_beacon;
209 __entry->ht_operation_mode = info->ht_operation_mode;
186 ), 210 ),
187 211
188 TP_printk( 212 TP_printk(
@@ -271,11 +295,11 @@ TRACE_EVENT(drv_set_tim,
271 295
272TRACE_EVENT(drv_set_key, 296TRACE_EVENT(drv_set_key,
273 TP_PROTO(struct ieee80211_local *local, 297 TP_PROTO(struct ieee80211_local *local,
274 enum set_key_cmd cmd, struct ieee80211_vif *vif, 298 enum set_key_cmd cmd, struct ieee80211_sub_if_data *sdata,
275 struct ieee80211_sta *sta, 299 struct ieee80211_sta *sta,
276 struct ieee80211_key_conf *key, int ret), 300 struct ieee80211_key_conf *key, int ret),
277 301
278 TP_ARGS(local, cmd, vif, sta, key, ret), 302 TP_ARGS(local, cmd, sdata, sta, key, ret),
279 303
280 TP_STRUCT__entry( 304 TP_STRUCT__entry(
281 LOCAL_ENTRY 305 LOCAL_ENTRY
@@ -307,26 +331,29 @@ TRACE_EVENT(drv_set_key,
307 331
308TRACE_EVENT(drv_update_tkip_key, 332TRACE_EVENT(drv_update_tkip_key,
309 TP_PROTO(struct ieee80211_local *local, 333 TP_PROTO(struct ieee80211_local *local,
334 struct ieee80211_sub_if_data *sdata,
310 struct ieee80211_key_conf *conf, 335 struct ieee80211_key_conf *conf,
311 const u8 *address, u32 iv32), 336 struct ieee80211_sta *sta, u32 iv32),
312 337
313 TP_ARGS(local, conf, address, iv32), 338 TP_ARGS(local, sdata, conf, sta, iv32),
314 339
315 TP_STRUCT__entry( 340 TP_STRUCT__entry(
316 LOCAL_ENTRY 341 LOCAL_ENTRY
317 __array(u8, addr, 6) 342 VIF_ENTRY
343 STA_ENTRY
318 __field(u32, iv32) 344 __field(u32, iv32)
319 ), 345 ),
320 346
321 TP_fast_assign( 347 TP_fast_assign(
322 LOCAL_ASSIGN; 348 LOCAL_ASSIGN;
323 memcpy(__entry->addr, address, 6); 349 VIF_ASSIGN;
350 STA_ASSIGN;
324 __entry->iv32 = iv32; 351 __entry->iv32 = iv32;
325 ), 352 ),
326 353
327 TP_printk( 354 TP_printk(
328 LOCAL_PR_FMT " addr:%pM iv32:%#x", 355 LOCAL_PR_FMT VIF_PR_FMT STA_PR_FMT " iv32:%#x",
329 LOCAL_PR_ARG, __entry->addr, __entry->iv32 356 LOCAL_PR_ARG,VIF_PR_ARG,STA_PR_ARG, __entry->iv32
330 ) 357 )
331); 358);
332 359
@@ -467,13 +494,36 @@ TRACE_EVENT(drv_set_rts_threshold,
467 ) 494 )
468); 495);
469 496
497TRACE_EVENT(drv_set_coverage_class,
498 TP_PROTO(struct ieee80211_local *local, u8 value, int ret),
499
500 TP_ARGS(local, value, ret),
501
502 TP_STRUCT__entry(
503 LOCAL_ENTRY
504 __field(u8, value)
505 __field(int, ret)
506 ),
507
508 TP_fast_assign(
509 LOCAL_ASSIGN;
510 __entry->ret = ret;
511 __entry->value = value;
512 ),
513
514 TP_printk(
515 LOCAL_PR_FMT " value:%d ret:%d",
516 LOCAL_PR_ARG, __entry->value, __entry->ret
517 )
518);
519
470TRACE_EVENT(drv_sta_notify, 520TRACE_EVENT(drv_sta_notify,
471 TP_PROTO(struct ieee80211_local *local, 521 TP_PROTO(struct ieee80211_local *local,
472 struct ieee80211_vif *vif, 522 struct ieee80211_sub_if_data *sdata,
473 enum sta_notify_cmd cmd, 523 enum sta_notify_cmd cmd,
474 struct ieee80211_sta *sta), 524 struct ieee80211_sta *sta),
475 525
476 TP_ARGS(local, vif, cmd, sta), 526 TP_ARGS(local, sdata, cmd, sta),
477 527
478 TP_STRUCT__entry( 528 TP_STRUCT__entry(
479 LOCAL_ENTRY 529 LOCAL_ENTRY
@@ -495,59 +545,88 @@ TRACE_EVENT(drv_sta_notify,
495 ) 545 )
496); 546);
497 547
498TRACE_EVENT(drv_conf_tx, 548TRACE_EVENT(drv_sta_add,
499 TP_PROTO(struct ieee80211_local *local, u16 queue, 549 TP_PROTO(struct ieee80211_local *local,
500 const struct ieee80211_tx_queue_params *params, 550 struct ieee80211_sub_if_data *sdata,
501 int ret), 551 struct ieee80211_sta *sta, int ret),
502 552
503 TP_ARGS(local, queue, params, ret), 553 TP_ARGS(local, sdata, sta, ret),
504 554
505 TP_STRUCT__entry( 555 TP_STRUCT__entry(
506 LOCAL_ENTRY 556 LOCAL_ENTRY
507 __field(u16, queue) 557 VIF_ENTRY
508 __field(u16, txop) 558 STA_ENTRY
509 __field(u16, cw_min)
510 __field(u16, cw_max)
511 __field(u8, aifs)
512 __field(int, ret) 559 __field(int, ret)
513 ), 560 ),
514 561
515 TP_fast_assign( 562 TP_fast_assign(
516 LOCAL_ASSIGN; 563 LOCAL_ASSIGN;
517 __entry->queue = queue; 564 VIF_ASSIGN;
565 STA_ASSIGN;
518 __entry->ret = ret; 566 __entry->ret = ret;
519 __entry->txop = params->txop;
520 __entry->cw_max = params->cw_max;
521 __entry->cw_min = params->cw_min;
522 __entry->aifs = params->aifs;
523 ), 567 ),
524 568
525 TP_printk( 569 TP_printk(
526 LOCAL_PR_FMT " queue:%d ret:%d", 570 LOCAL_PR_FMT VIF_PR_FMT STA_PR_FMT " ret:%d",
527 LOCAL_PR_ARG, __entry->queue, __entry->ret 571 LOCAL_PR_ARG, VIF_PR_ARG, STA_PR_ARG, __entry->ret
528 ) 572 )
529); 573);
530 574
531TRACE_EVENT(drv_get_tx_stats, 575TRACE_EVENT(drv_sta_remove,
532 TP_PROTO(struct ieee80211_local *local, 576 TP_PROTO(struct ieee80211_local *local,
533 struct ieee80211_tx_queue_stats *stats, 577 struct ieee80211_sub_if_data *sdata,
578 struct ieee80211_sta *sta),
579
580 TP_ARGS(local, sdata, sta),
581
582 TP_STRUCT__entry(
583 LOCAL_ENTRY
584 VIF_ENTRY
585 STA_ENTRY
586 ),
587
588 TP_fast_assign(
589 LOCAL_ASSIGN;
590 VIF_ASSIGN;
591 STA_ASSIGN;
592 ),
593
594 TP_printk(
595 LOCAL_PR_FMT VIF_PR_FMT STA_PR_FMT,
596 LOCAL_PR_ARG, VIF_PR_ARG, STA_PR_ARG
597 )
598);
599
600TRACE_EVENT(drv_conf_tx,
601 TP_PROTO(struct ieee80211_local *local, u16 queue,
602 const struct ieee80211_tx_queue_params *params,
534 int ret), 603 int ret),
535 604
536 TP_ARGS(local, stats, ret), 605 TP_ARGS(local, queue, params, ret),
537 606
538 TP_STRUCT__entry( 607 TP_STRUCT__entry(
539 LOCAL_ENTRY 608 LOCAL_ENTRY
609 __field(u16, queue)
610 __field(u16, txop)
611 __field(u16, cw_min)
612 __field(u16, cw_max)
613 __field(u8, aifs)
540 __field(int, ret) 614 __field(int, ret)
541 ), 615 ),
542 616
543 TP_fast_assign( 617 TP_fast_assign(
544 LOCAL_ASSIGN; 618 LOCAL_ASSIGN;
619 __entry->queue = queue;
545 __entry->ret = ret; 620 __entry->ret = ret;
621 __entry->txop = params->txop;
622 __entry->cw_max = params->cw_max;
623 __entry->cw_min = params->cw_min;
624 __entry->aifs = params->aifs;
546 ), 625 ),
547 626
548 TP_printk( 627 TP_printk(
549 LOCAL_PR_FMT " ret:%d", 628 LOCAL_PR_FMT " queue:%d ret:%d",
550 LOCAL_PR_ARG, __entry->ret 629 LOCAL_PR_ARG, __entry->queue, __entry->ret
551 ) 630 )
552); 631);
553 632
@@ -634,11 +713,12 @@ TRACE_EVENT(drv_tx_last_beacon,
634 713
635TRACE_EVENT(drv_ampdu_action, 714TRACE_EVENT(drv_ampdu_action,
636 TP_PROTO(struct ieee80211_local *local, 715 TP_PROTO(struct ieee80211_local *local,
716 struct ieee80211_sub_if_data *sdata,
637 enum ieee80211_ampdu_mlme_action action, 717 enum ieee80211_ampdu_mlme_action action,
638 struct ieee80211_sta *sta, u16 tid, 718 struct ieee80211_sta *sta, u16 tid,
639 u16 *ssn, int ret), 719 u16 *ssn, int ret),
640 720
641 TP_ARGS(local, action, sta, tid, ssn, ret), 721 TP_ARGS(local, sdata, action, sta, tid, ssn, ret),
642 722
643 TP_STRUCT__entry( 723 TP_STRUCT__entry(
644 LOCAL_ENTRY 724 LOCAL_ENTRY
@@ -647,20 +727,43 @@ TRACE_EVENT(drv_ampdu_action,
647 __field(u16, tid) 727 __field(u16, tid)
648 __field(u16, ssn) 728 __field(u16, ssn)
649 __field(int, ret) 729 __field(int, ret)
730 VIF_ENTRY
650 ), 731 ),
651 732
652 TP_fast_assign( 733 TP_fast_assign(
653 LOCAL_ASSIGN; 734 LOCAL_ASSIGN;
735 VIF_ASSIGN;
654 STA_ASSIGN; 736 STA_ASSIGN;
655 __entry->ret = ret; 737 __entry->ret = ret;
656 __entry->action = action; 738 __entry->action = action;
657 __entry->tid = tid; 739 __entry->tid = tid;
658 __entry->ssn = *ssn; 740 __entry->ssn = ssn ? *ssn : 0;
741 ),
742
743 TP_printk(
744 LOCAL_PR_FMT VIF_PR_FMT STA_PR_FMT " action:%d tid:%d ret:%d",
745 LOCAL_PR_ARG, VIF_PR_ARG, STA_PR_ARG, __entry->action, __entry->tid, __entry->ret
746 )
747);
748
749TRACE_EVENT(drv_flush,
750 TP_PROTO(struct ieee80211_local *local, bool drop),
751
752 TP_ARGS(local, drop),
753
754 TP_STRUCT__entry(
755 LOCAL_ENTRY
756 __field(bool, drop)
757 ),
758
759 TP_fast_assign(
760 LOCAL_ASSIGN;
761 __entry->drop = drop;
659 ), 762 ),
660 763
661 TP_printk( 764 TP_printk(
662 LOCAL_PR_FMT STA_PR_FMT " action:%d tid:%d ret:%d", 765 LOCAL_PR_FMT " drop:%d",
663 LOCAL_PR_ARG, STA_PR_ARG, __entry->action, __entry->tid, __entry->ret 766 LOCAL_PR_ARG, __entry->drop
664 ) 767 )
665); 768);
666#endif /* !__MAC80211_DRIVER_TRACE || TRACE_HEADER_MULTI_READ */ 769#endif /* !__MAC80211_DRIVER_TRACE || TRACE_HEADER_MULTI_READ */
diff --git a/net/mac80211/ht.c b/net/mac80211/ht.c
index cdc58e61d921..bb677a73b7c9 100644
--- a/net/mac80211/ht.c
+++ b/net/mac80211/ht.c
@@ -34,9 +34,28 @@ void ieee80211_ht_cap_ie_to_sta_ht_cap(struct ieee80211_supported_band *sband,
34 34
35 ht_cap->ht_supported = true; 35 ht_cap->ht_supported = true;
36 36
37 ht_cap->cap = le16_to_cpu(ht_cap_ie->cap_info) & sband->ht_cap.cap; 37 /*
38 ht_cap->cap &= ~IEEE80211_HT_CAP_SM_PS; 38 * The bits listed in this expression should be
39 ht_cap->cap |= sband->ht_cap.cap & IEEE80211_HT_CAP_SM_PS; 39 * the same for the peer and us, if the station
40 * advertises more then we can't use those thus
41 * we mask them out.
42 */
43 ht_cap->cap = le16_to_cpu(ht_cap_ie->cap_info) &
44 (sband->ht_cap.cap |
45 ~(IEEE80211_HT_CAP_LDPC_CODING |
46 IEEE80211_HT_CAP_SUP_WIDTH_20_40 |
47 IEEE80211_HT_CAP_GRN_FLD |
48 IEEE80211_HT_CAP_SGI_20 |
49 IEEE80211_HT_CAP_SGI_40 |
50 IEEE80211_HT_CAP_DSSSCCK40));
51 /*
52 * The STBC bits are asymmetric -- if we don't have
53 * TX then mask out the peer's RX and vice versa.
54 */
55 if (!(sband->ht_cap.cap & IEEE80211_HT_CAP_TX_STBC))
56 ht_cap->cap &= ~IEEE80211_HT_CAP_RX_STBC;
57 if (!(sband->ht_cap.cap & IEEE80211_HT_CAP_RX_STBC))
58 ht_cap->cap &= ~IEEE80211_HT_CAP_TX_STBC;
40 59
41 ampdu_info = ht_cap_ie->ampdu_params_info; 60 ampdu_info = ht_cap_ie->ampdu_params_info;
42 ht_cap->ampdu_factor = 61 ht_cap->ampdu_factor =
@@ -106,7 +125,7 @@ void ieee80211_send_delba(struct ieee80211_sub_if_data *sdata,
106 125
107 if (!skb) { 126 if (!skb) {
108 printk(KERN_ERR "%s: failed to allocate buffer " 127 printk(KERN_ERR "%s: failed to allocate buffer "
109 "for delba frame\n", sdata->dev->name); 128 "for delba frame\n", sdata->name);
110 return; 129 return;
111 } 130 }
112 131
@@ -114,10 +133,10 @@ void ieee80211_send_delba(struct ieee80211_sub_if_data *sdata,
114 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24); 133 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
115 memset(mgmt, 0, 24); 134 memset(mgmt, 0, 24);
116 memcpy(mgmt->da, da, ETH_ALEN); 135 memcpy(mgmt->da, da, ETH_ALEN);
117 memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN); 136 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
118 if (sdata->vif.type == NL80211_IFTYPE_AP || 137 if (sdata->vif.type == NL80211_IFTYPE_AP ||
119 sdata->vif.type == NL80211_IFTYPE_AP_VLAN) 138 sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
120 memcpy(mgmt->bssid, sdata->dev->dev_addr, ETH_ALEN); 139 memcpy(mgmt->bssid, sdata->vif.addr, ETH_ALEN);
121 else if (sdata->vif.type == NL80211_IFTYPE_STATION) 140 else if (sdata->vif.type == NL80211_IFTYPE_STATION)
122 memcpy(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN); 141 memcpy(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN);
123 142
@@ -134,7 +153,7 @@ void ieee80211_send_delba(struct ieee80211_sub_if_data *sdata,
134 mgmt->u.action.u.delba.params = cpu_to_le16(params); 153 mgmt->u.action.u.delba.params = cpu_to_le16(params);
135 mgmt->u.action.u.delba.reason_code = cpu_to_le16(reason_code); 154 mgmt->u.action.u.delba.reason_code = cpu_to_le16(reason_code);
136 155
137 ieee80211_tx_skb(sdata, skb, 1); 156 ieee80211_tx_skb(sdata, skb);
138} 157}
139 158
140void ieee80211_process_delba(struct ieee80211_sub_if_data *sdata, 159void ieee80211_process_delba(struct ieee80211_sub_if_data *sdata,
@@ -166,3 +185,50 @@ void ieee80211_process_delba(struct ieee80211_sub_if_data *sdata,
166 spin_unlock_bh(&sta->lock); 185 spin_unlock_bh(&sta->lock);
167 } 186 }
168} 187}
188
189int ieee80211_send_smps_action(struct ieee80211_sub_if_data *sdata,
190 enum ieee80211_smps_mode smps, const u8 *da,
191 const u8 *bssid)
192{
193 struct ieee80211_local *local = sdata->local;
194 struct sk_buff *skb;
195 struct ieee80211_mgmt *action_frame;
196
197 /* 27 = header + category + action + smps mode */
198 skb = dev_alloc_skb(27 + local->hw.extra_tx_headroom);
199 if (!skb)
200 return -ENOMEM;
201
202 skb_reserve(skb, local->hw.extra_tx_headroom);
203 action_frame = (void *)skb_put(skb, 27);
204 memcpy(action_frame->da, da, ETH_ALEN);
205 memcpy(action_frame->sa, sdata->dev->dev_addr, ETH_ALEN);
206 memcpy(action_frame->bssid, bssid, ETH_ALEN);
207 action_frame->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
208 IEEE80211_STYPE_ACTION);
209 action_frame->u.action.category = WLAN_CATEGORY_HT;
210 action_frame->u.action.u.ht_smps.action = WLAN_HT_ACTION_SMPS;
211 switch (smps) {
212 case IEEE80211_SMPS_AUTOMATIC:
213 case IEEE80211_SMPS_NUM_MODES:
214 WARN_ON(1);
215 case IEEE80211_SMPS_OFF:
216 action_frame->u.action.u.ht_smps.smps_control =
217 WLAN_HT_SMPS_CONTROL_DISABLED;
218 break;
219 case IEEE80211_SMPS_STATIC:
220 action_frame->u.action.u.ht_smps.smps_control =
221 WLAN_HT_SMPS_CONTROL_STATIC;
222 break;
223 case IEEE80211_SMPS_DYNAMIC:
224 action_frame->u.action.u.ht_smps.smps_control =
225 WLAN_HT_SMPS_CONTROL_DYNAMIC;
226 break;
227 }
228
229 /* we'll do more on status of this frame */
230 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS;
231 ieee80211_tx_skb(sdata, skb);
232
233 return 0;
234}
diff --git a/net/mac80211/ibss.c b/net/mac80211/ibss.c
index f1362f32c17d..e2976da4e0d9 100644
--- a/net/mac80211/ibss.c
+++ b/net/mac80211/ibss.c
@@ -13,6 +13,7 @@
13 */ 13 */
14 14
15#include <linux/delay.h> 15#include <linux/delay.h>
16#include <linux/slab.h>
16#include <linux/if_ether.h> 17#include <linux/if_ether.h>
17#include <linux/skbuff.h> 18#include <linux/skbuff.h>
18#include <linux/if_arp.h> 19#include <linux/if_arp.h>
@@ -117,7 +118,7 @@ static void __ieee80211_sta_join_ibss(struct ieee80211_sub_if_data *sdata,
117 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | 118 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
118 IEEE80211_STYPE_PROBE_RESP); 119 IEEE80211_STYPE_PROBE_RESP);
119 memset(mgmt->da, 0xff, ETH_ALEN); 120 memset(mgmt->da, 0xff, ETH_ALEN);
120 memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN); 121 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
121 memcpy(mgmt->bssid, ifibss->bssid, ETH_ALEN); 122 memcpy(mgmt->bssid, ifibss->bssid, ETH_ALEN);
122 mgmt->u.beacon.beacon_int = cpu_to_le16(beacon_int); 123 mgmt->u.beacon.beacon_int = cpu_to_le16(beacon_int);
123 mgmt->u.beacon.timestamp = cpu_to_le64(tsf); 124 mgmt->u.beacon.timestamp = cpu_to_le64(tsf);
@@ -187,15 +188,17 @@ static void __ieee80211_sta_join_ibss(struct ieee80211_sub_if_data *sdata,
187static void ieee80211_sta_join_ibss(struct ieee80211_sub_if_data *sdata, 188static void ieee80211_sta_join_ibss(struct ieee80211_sub_if_data *sdata,
188 struct ieee80211_bss *bss) 189 struct ieee80211_bss *bss)
189{ 190{
191 struct cfg80211_bss *cbss =
192 container_of((void *)bss, struct cfg80211_bss, priv);
190 struct ieee80211_supported_band *sband; 193 struct ieee80211_supported_band *sband;
191 u32 basic_rates; 194 u32 basic_rates;
192 int i, j; 195 int i, j;
193 u16 beacon_int = bss->cbss.beacon_interval; 196 u16 beacon_int = cbss->beacon_interval;
194 197
195 if (beacon_int < 10) 198 if (beacon_int < 10)
196 beacon_int = 10; 199 beacon_int = 10;
197 200
198 sband = sdata->local->hw.wiphy->bands[bss->cbss.channel->band]; 201 sband = sdata->local->hw.wiphy->bands[cbss->channel->band];
199 202
200 basic_rates = 0; 203 basic_rates = 0;
201 204
@@ -212,12 +215,12 @@ static void ieee80211_sta_join_ibss(struct ieee80211_sub_if_data *sdata,
212 } 215 }
213 } 216 }
214 217
215 __ieee80211_sta_join_ibss(sdata, bss->cbss.bssid, 218 __ieee80211_sta_join_ibss(sdata, cbss->bssid,
216 beacon_int, 219 beacon_int,
217 bss->cbss.channel, 220 cbss->channel,
218 basic_rates, 221 basic_rates,
219 bss->cbss.capability, 222 cbss->capability,
220 bss->cbss.tsf); 223 cbss->tsf);
221} 224}
222 225
223static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata, 226static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
@@ -229,6 +232,7 @@ static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
229{ 232{
230 struct ieee80211_local *local = sdata->local; 233 struct ieee80211_local *local = sdata->local;
231 int freq; 234 int freq;
235 struct cfg80211_bss *cbss;
232 struct ieee80211_bss *bss; 236 struct ieee80211_bss *bss;
233 struct sta_info *sta; 237 struct sta_info *sta;
234 struct ieee80211_channel *channel; 238 struct ieee80211_channel *channel;
@@ -252,7 +256,7 @@ static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
252 256
253 rcu_read_lock(); 257 rcu_read_lock();
254 258
255 sta = sta_info_get(local, mgmt->sa); 259 sta = sta_info_get(sdata, mgmt->sa);
256 if (sta) { 260 if (sta) {
257 u32 prev_rates; 261 u32 prev_rates;
258 262
@@ -266,16 +270,18 @@ static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
266 printk(KERN_DEBUG "%s: updated supp_rates set " 270 printk(KERN_DEBUG "%s: updated supp_rates set "
267 "for %pM based on beacon info (0x%llx | " 271 "for %pM based on beacon info (0x%llx | "
268 "0x%llx -> 0x%llx)\n", 272 "0x%llx -> 0x%llx)\n",
269 sdata->dev->name, 273 sdata->name,
270 sta->sta.addr, 274 sta->sta.addr,
271 (unsigned long long) prev_rates, 275 (unsigned long long) prev_rates,
272 (unsigned long long) supp_rates, 276 (unsigned long long) supp_rates,
273 (unsigned long long) sta->sta.supp_rates[band]); 277 (unsigned long long) sta->sta.supp_rates[band]);
274#endif 278#endif
275 } else 279 rcu_read_unlock();
276 ieee80211_ibss_add_sta(sdata, mgmt->bssid, mgmt->sa, supp_rates); 280 } else {
277 281 rcu_read_unlock();
278 rcu_read_unlock(); 282 ieee80211_ibss_add_sta(sdata, mgmt->bssid, mgmt->sa,
283 supp_rates, GFP_KERNEL);
284 }
279 } 285 }
280 286
281 bss = ieee80211_bss_info_update(local, rx_status, mgmt, len, elems, 287 bss = ieee80211_bss_info_update(local, rx_status, mgmt, len, elems,
@@ -283,25 +289,23 @@ static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
283 if (!bss) 289 if (!bss)
284 return; 290 return;
285 291
292 cbss = container_of((void *)bss, struct cfg80211_bss, priv);
293
286 /* was just updated in ieee80211_bss_info_update */ 294 /* was just updated in ieee80211_bss_info_update */
287 beacon_timestamp = bss->cbss.tsf; 295 beacon_timestamp = cbss->tsf;
288 296
289 /* check if we need to merge IBSS */ 297 /* check if we need to merge IBSS */
290 298
291 /* merge only on beacons (???) */
292 if (!beacon)
293 goto put_bss;
294
295 /* we use a fixed BSSID */ 299 /* we use a fixed BSSID */
296 if (sdata->u.ibss.bssid) 300 if (sdata->u.ibss.fixed_bssid)
297 goto put_bss; 301 goto put_bss;
298 302
299 /* not an IBSS */ 303 /* not an IBSS */
300 if (!(bss->cbss.capability & WLAN_CAPABILITY_IBSS)) 304 if (!(cbss->capability & WLAN_CAPABILITY_IBSS))
301 goto put_bss; 305 goto put_bss;
302 306
303 /* different channel */ 307 /* different channel */
304 if (bss->cbss.channel != local->oper_channel) 308 if (cbss->channel != local->oper_channel)
305 goto put_bss; 309 goto put_bss;
306 310
307 /* different SSID */ 311 /* different SSID */
@@ -311,7 +315,7 @@ static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
311 goto put_bss; 315 goto put_bss;
312 316
313 /* same BSSID */ 317 /* same BSSID */
314 if (memcmp(bss->cbss.bssid, sdata->u.ibss.bssid, ETH_ALEN) == 0) 318 if (memcmp(cbss->bssid, sdata->u.ibss.bssid, ETH_ALEN) == 0)
315 goto put_bss; 319 goto put_bss;
316 320
317 if (rx_status->flag & RX_FLAG_TSFT) { 321 if (rx_status->flag & RX_FLAG_TSFT) {
@@ -364,10 +368,11 @@ static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
364#ifdef CONFIG_MAC80211_IBSS_DEBUG 368#ifdef CONFIG_MAC80211_IBSS_DEBUG
365 printk(KERN_DEBUG "%s: beacon TSF higher than " 369 printk(KERN_DEBUG "%s: beacon TSF higher than "
366 "local TSF - IBSS merge with BSSID %pM\n", 370 "local TSF - IBSS merge with BSSID %pM\n",
367 sdata->dev->name, mgmt->bssid); 371 sdata->name, mgmt->bssid);
368#endif 372#endif
369 ieee80211_sta_join_ibss(sdata, bss); 373 ieee80211_sta_join_ibss(sdata, bss);
370 ieee80211_ibss_add_sta(sdata, mgmt->bssid, mgmt->sa, supp_rates); 374 ieee80211_ibss_add_sta(sdata, mgmt->bssid, mgmt->sa,
375 supp_rates, GFP_KERNEL);
371 } 376 }
372 377
373 put_bss: 378 put_bss:
@@ -380,8 +385,10 @@ static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
380 * must be callable in atomic context. 385 * must be callable in atomic context.
381 */ 386 */
382struct sta_info *ieee80211_ibss_add_sta(struct ieee80211_sub_if_data *sdata, 387struct sta_info *ieee80211_ibss_add_sta(struct ieee80211_sub_if_data *sdata,
383 u8 *bssid,u8 *addr, u32 supp_rates) 388 u8 *bssid,u8 *addr, u32 supp_rates,
389 gfp_t gfp)
384{ 390{
391 struct ieee80211_if_ibss *ifibss = &sdata->u.ibss;
385 struct ieee80211_local *local = sdata->local; 392 struct ieee80211_local *local = sdata->local;
386 struct sta_info *sta; 393 struct sta_info *sta;
387 int band = local->hw.conf.channel->band; 394 int band = local->hw.conf.channel->band;
@@ -393,19 +400,22 @@ struct sta_info *ieee80211_ibss_add_sta(struct ieee80211_sub_if_data *sdata,
393 if (local->num_sta >= IEEE80211_IBSS_MAX_STA_ENTRIES) { 400 if (local->num_sta >= IEEE80211_IBSS_MAX_STA_ENTRIES) {
394 if (net_ratelimit()) 401 if (net_ratelimit())
395 printk(KERN_DEBUG "%s: No room for a new IBSS STA entry %pM\n", 402 printk(KERN_DEBUG "%s: No room for a new IBSS STA entry %pM\n",
396 sdata->dev->name, addr); 403 sdata->name, addr);
397 return NULL; 404 return NULL;
398 } 405 }
399 406
407 if (ifibss->state == IEEE80211_IBSS_MLME_SEARCH)
408 return NULL;
409
400 if (compare_ether_addr(bssid, sdata->u.ibss.bssid)) 410 if (compare_ether_addr(bssid, sdata->u.ibss.bssid))
401 return NULL; 411 return NULL;
402 412
403#ifdef CONFIG_MAC80211_VERBOSE_DEBUG 413#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
404 printk(KERN_DEBUG "%s: Adding new IBSS station %pM (dev=%s)\n", 414 printk(KERN_DEBUG "%s: Adding new IBSS station %pM (dev=%s)\n",
405 wiphy_name(local->hw.wiphy), addr, sdata->dev->name); 415 wiphy_name(local->hw.wiphy), addr, sdata->name);
406#endif 416#endif
407 417
408 sta = sta_info_alloc(sdata, addr, GFP_ATOMIC); 418 sta = sta_info_alloc(sdata, addr, gfp);
409 if (!sta) 419 if (!sta)
410 return NULL; 420 return NULL;
411 421
@@ -417,9 +427,9 @@ struct sta_info *ieee80211_ibss_add_sta(struct ieee80211_sub_if_data *sdata,
417 427
418 rate_control_rate_init(sta); 428 rate_control_rate_init(sta);
419 429
430 /* If it fails, maybe we raced another insertion? */
420 if (sta_info_insert(sta)) 431 if (sta_info_insert(sta))
421 return NULL; 432 return sta_info_get(sdata, addr);
422
423 return sta; 433 return sta;
424} 434}
425 435
@@ -445,6 +455,9 @@ static int ieee80211_sta_active_ibss(struct ieee80211_sub_if_data *sdata)
445 return active; 455 return active;
446} 456}
447 457
458/*
459 * This function is called with state == IEEE80211_IBSS_MLME_JOINED
460 */
448 461
449static void ieee80211_sta_merge_ibss(struct ieee80211_sub_if_data *sdata) 462static void ieee80211_sta_merge_ibss(struct ieee80211_sub_if_data *sdata)
450{ 463{
@@ -455,6 +468,10 @@ static void ieee80211_sta_merge_ibss(struct ieee80211_sub_if_data *sdata)
455 468
456 ieee80211_sta_expire(sdata, IEEE80211_IBSS_INACTIVITY_LIMIT); 469 ieee80211_sta_expire(sdata, IEEE80211_IBSS_INACTIVITY_LIMIT);
457 470
471 if (time_before(jiffies, ifibss->last_scan_completed +
472 IEEE80211_IBSS_MERGE_INTERVAL))
473 return;
474
458 if (ieee80211_sta_active_ibss(sdata)) 475 if (ieee80211_sta_active_ibss(sdata))
459 return; 476 return;
460 477
@@ -462,7 +479,7 @@ static void ieee80211_sta_merge_ibss(struct ieee80211_sub_if_data *sdata)
462 return; 479 return;
463 480
464 printk(KERN_DEBUG "%s: No active IBSS STAs - trying to scan for other " 481 printk(KERN_DEBUG "%s: No active IBSS STAs - trying to scan for other "
465 "IBSS networks with same SSID (merge)\n", sdata->dev->name); 482 "IBSS networks with same SSID (merge)\n", sdata->name);
466 483
467 ieee80211_request_internal_scan(sdata, ifibss->ssid, ifibss->ssid_len); 484 ieee80211_request_internal_scan(sdata, ifibss->ssid, ifibss->ssid_len);
468} 485}
@@ -484,13 +501,13 @@ static void ieee80211_sta_create_ibss(struct ieee80211_sub_if_data *sdata)
484 * random number generator get different BSSID. */ 501 * random number generator get different BSSID. */
485 get_random_bytes(bssid, ETH_ALEN); 502 get_random_bytes(bssid, ETH_ALEN);
486 for (i = 0; i < ETH_ALEN; i++) 503 for (i = 0; i < ETH_ALEN; i++)
487 bssid[i] ^= sdata->dev->dev_addr[i]; 504 bssid[i] ^= sdata->vif.addr[i];
488 bssid[0] &= ~0x01; 505 bssid[0] &= ~0x01;
489 bssid[0] |= 0x02; 506 bssid[0] |= 0x02;
490 } 507 }
491 508
492 printk(KERN_DEBUG "%s: Creating new IBSS network, BSSID %pM\n", 509 printk(KERN_DEBUG "%s: Creating new IBSS network, BSSID %pM\n",
493 sdata->dev->name, bssid); 510 sdata->name, bssid);
494 511
495 sband = local->hw.wiphy->bands[ifibss->channel->band]; 512 sband = local->hw.wiphy->bands[ifibss->channel->band];
496 513
@@ -506,11 +523,15 @@ static void ieee80211_sta_create_ibss(struct ieee80211_sub_if_data *sdata)
506 capability, 0); 523 capability, 0);
507} 524}
508 525
526/*
527 * This function is called with state == IEEE80211_IBSS_MLME_SEARCH
528 */
529
509static void ieee80211_sta_find_ibss(struct ieee80211_sub_if_data *sdata) 530static void ieee80211_sta_find_ibss(struct ieee80211_sub_if_data *sdata)
510{ 531{
511 struct ieee80211_if_ibss *ifibss = &sdata->u.ibss; 532 struct ieee80211_if_ibss *ifibss = &sdata->u.ibss;
512 struct ieee80211_local *local = sdata->local; 533 struct ieee80211_local *local = sdata->local;
513 struct ieee80211_bss *bss; 534 struct cfg80211_bss *cbss;
514 struct ieee80211_channel *chan = NULL; 535 struct ieee80211_channel *chan = NULL;
515 const u8 *bssid = NULL; 536 const u8 *bssid = NULL;
516 int active_ibss; 537 int active_ibss;
@@ -519,7 +540,7 @@ static void ieee80211_sta_find_ibss(struct ieee80211_sub_if_data *sdata)
519 active_ibss = ieee80211_sta_active_ibss(sdata); 540 active_ibss = ieee80211_sta_active_ibss(sdata);
520#ifdef CONFIG_MAC80211_IBSS_DEBUG 541#ifdef CONFIG_MAC80211_IBSS_DEBUG
521 printk(KERN_DEBUG "%s: sta_find_ibss (active_ibss=%d)\n", 542 printk(KERN_DEBUG "%s: sta_find_ibss (active_ibss=%d)\n",
522 sdata->dev->name, active_ibss); 543 sdata->name, active_ibss);
523#endif /* CONFIG_MAC80211_IBSS_DEBUG */ 544#endif /* CONFIG_MAC80211_IBSS_DEBUG */
524 545
525 if (active_ibss) 546 if (active_ibss)
@@ -534,21 +555,23 @@ static void ieee80211_sta_find_ibss(struct ieee80211_sub_if_data *sdata)
534 chan = ifibss->channel; 555 chan = ifibss->channel;
535 if (!is_zero_ether_addr(ifibss->bssid)) 556 if (!is_zero_ether_addr(ifibss->bssid))
536 bssid = ifibss->bssid; 557 bssid = ifibss->bssid;
537 bss = (void *)cfg80211_get_bss(local->hw.wiphy, chan, bssid, 558 cbss = cfg80211_get_bss(local->hw.wiphy, chan, bssid,
538 ifibss->ssid, ifibss->ssid_len, 559 ifibss->ssid, ifibss->ssid_len,
539 WLAN_CAPABILITY_IBSS | 560 WLAN_CAPABILITY_IBSS | WLAN_CAPABILITY_PRIVACY,
540 WLAN_CAPABILITY_PRIVACY, 561 capability);
541 capability); 562
563 if (cbss) {
564 struct ieee80211_bss *bss;
542 565
543 if (bss) { 566 bss = (void *)cbss->priv;
544#ifdef CONFIG_MAC80211_IBSS_DEBUG 567#ifdef CONFIG_MAC80211_IBSS_DEBUG
545 printk(KERN_DEBUG " sta_find_ibss: selected %pM current " 568 printk(KERN_DEBUG " sta_find_ibss: selected %pM current "
546 "%pM\n", bss->cbss.bssid, ifibss->bssid); 569 "%pM\n", cbss->bssid, ifibss->bssid);
547#endif /* CONFIG_MAC80211_IBSS_DEBUG */ 570#endif /* CONFIG_MAC80211_IBSS_DEBUG */
548 571
549 printk(KERN_DEBUG "%s: Selected IBSS BSSID %pM" 572 printk(KERN_DEBUG "%s: Selected IBSS BSSID %pM"
550 " based on configured SSID\n", 573 " based on configured SSID\n",
551 sdata->dev->name, bss->cbss.bssid); 574 sdata->name, cbss->bssid);
552 575
553 ieee80211_sta_join_ibss(sdata, bss); 576 ieee80211_sta_join_ibss(sdata, bss);
554 ieee80211_rx_bss_put(local, bss); 577 ieee80211_rx_bss_put(local, bss);
@@ -560,18 +583,14 @@ static void ieee80211_sta_find_ibss(struct ieee80211_sub_if_data *sdata)
560#endif /* CONFIG_MAC80211_IBSS_DEBUG */ 583#endif /* CONFIG_MAC80211_IBSS_DEBUG */
561 584
562 /* Selected IBSS not found in current scan results - try to scan */ 585 /* Selected IBSS not found in current scan results - try to scan */
563 if (ifibss->state == IEEE80211_IBSS_MLME_JOINED && 586 if (time_after(jiffies, ifibss->last_scan_completed +
564 !ieee80211_sta_active_ibss(sdata)) {
565 mod_timer(&ifibss->timer,
566 round_jiffies(jiffies + IEEE80211_IBSS_MERGE_INTERVAL));
567 } else if (time_after(jiffies, ifibss->last_scan_completed +
568 IEEE80211_SCAN_INTERVAL)) { 587 IEEE80211_SCAN_INTERVAL)) {
569 printk(KERN_DEBUG "%s: Trigger new scan to find an IBSS to " 588 printk(KERN_DEBUG "%s: Trigger new scan to find an IBSS to "
570 "join\n", sdata->dev->name); 589 "join\n", sdata->name);
571 590
572 ieee80211_request_internal_scan(sdata, ifibss->ssid, 591 ieee80211_request_internal_scan(sdata, ifibss->ssid,
573 ifibss->ssid_len); 592 ifibss->ssid_len);
574 } else if (ifibss->state != IEEE80211_IBSS_MLME_JOINED) { 593 } else {
575 int interval = IEEE80211_SCAN_INTERVAL; 594 int interval = IEEE80211_SCAN_INTERVAL;
576 595
577 if (time_after(jiffies, ifibss->ibss_join_req + 596 if (time_after(jiffies, ifibss->ibss_join_req +
@@ -581,7 +600,7 @@ static void ieee80211_sta_find_ibss(struct ieee80211_sub_if_data *sdata)
581 return; 600 return;
582 } 601 }
583 printk(KERN_DEBUG "%s: IBSS not allowed on" 602 printk(KERN_DEBUG "%s: IBSS not allowed on"
584 " %d MHz\n", sdata->dev->name, 603 " %d MHz\n", sdata->name,
585 local->hw.conf.channel->center_freq); 604 local->hw.conf.channel->center_freq);
586 605
587 /* No IBSS found - decrease scan interval and continue 606 /* No IBSS found - decrease scan interval and continue
@@ -589,7 +608,6 @@ static void ieee80211_sta_find_ibss(struct ieee80211_sub_if_data *sdata)
589 interval = IEEE80211_SCAN_INTERVAL_SLOW; 608 interval = IEEE80211_SCAN_INTERVAL_SLOW;
590 } 609 }
591 610
592 ifibss->state = IEEE80211_IBSS_MLME_SEARCH;
593 mod_timer(&ifibss->timer, 611 mod_timer(&ifibss->timer,
594 round_jiffies(jiffies + interval)); 612 round_jiffies(jiffies + interval));
595 } 613 }
@@ -615,7 +633,7 @@ static void ieee80211_rx_mgmt_probe_req(struct ieee80211_sub_if_data *sdata,
615#ifdef CONFIG_MAC80211_IBSS_DEBUG 633#ifdef CONFIG_MAC80211_IBSS_DEBUG
616 printk(KERN_DEBUG "%s: RX ProbeReq SA=%pM DA=%pM BSSID=%pM" 634 printk(KERN_DEBUG "%s: RX ProbeReq SA=%pM DA=%pM BSSID=%pM"
617 " (tx_last_beacon=%d)\n", 635 " (tx_last_beacon=%d)\n",
618 sdata->dev->name, mgmt->sa, mgmt->da, 636 sdata->name, mgmt->sa, mgmt->da,
619 mgmt->bssid, tx_last_beacon); 637 mgmt->bssid, tx_last_beacon);
620#endif /* CONFIG_MAC80211_IBSS_DEBUG */ 638#endif /* CONFIG_MAC80211_IBSS_DEBUG */
621 639
@@ -633,13 +651,13 @@ static void ieee80211_rx_mgmt_probe_req(struct ieee80211_sub_if_data *sdata,
633#ifdef CONFIG_MAC80211_IBSS_DEBUG 651#ifdef CONFIG_MAC80211_IBSS_DEBUG
634 printk(KERN_DEBUG "%s: Invalid SSID IE in ProbeReq " 652 printk(KERN_DEBUG "%s: Invalid SSID IE in ProbeReq "
635 "from %pM\n", 653 "from %pM\n",
636 sdata->dev->name, mgmt->sa); 654 sdata->name, mgmt->sa);
637#endif 655#endif
638 return; 656 return;
639 } 657 }
640 if (pos[1] != 0 && 658 if (pos[1] != 0 &&
641 (pos[1] != ifibss->ssid_len || 659 (pos[1] != ifibss->ssid_len ||
642 !memcmp(pos + 2, ifibss->ssid, ifibss->ssid_len))) { 660 memcmp(pos + 2, ifibss->ssid, ifibss->ssid_len))) {
643 /* Ignore ProbeReq for foreign SSID */ 661 /* Ignore ProbeReq for foreign SSID */
644 return; 662 return;
645 } 663 }
@@ -653,9 +671,10 @@ static void ieee80211_rx_mgmt_probe_req(struct ieee80211_sub_if_data *sdata,
653 memcpy(resp->da, mgmt->sa, ETH_ALEN); 671 memcpy(resp->da, mgmt->sa, ETH_ALEN);
654#ifdef CONFIG_MAC80211_IBSS_DEBUG 672#ifdef CONFIG_MAC80211_IBSS_DEBUG
655 printk(KERN_DEBUG "%s: Sending ProbeResp to %pM\n", 673 printk(KERN_DEBUG "%s: Sending ProbeResp to %pM\n",
656 sdata->dev->name, resp->da); 674 sdata->name, resp->da);
657#endif /* CONFIG_MAC80211_IBSS_DEBUG */ 675#endif /* CONFIG_MAC80211_IBSS_DEBUG */
658 ieee80211_tx_skb(sdata, skb, 0); 676 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
677 ieee80211_tx_skb(sdata, skb);
659} 678}
660 679
661static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_sub_if_data *sdata, 680static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_sub_if_data *sdata,
@@ -666,7 +685,7 @@ static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_sub_if_data *sdata,
666 size_t baselen; 685 size_t baselen;
667 struct ieee802_11_elems elems; 686 struct ieee802_11_elems elems;
668 687
669 if (memcmp(mgmt->da, sdata->dev->dev_addr, ETH_ALEN)) 688 if (memcmp(mgmt->da, sdata->vif.addr, ETH_ALEN))
670 return; /* ignore ProbeResp to foreign address */ 689 return; /* ignore ProbeResp to foreign address */
671 690
672 baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt; 691 baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt;
@@ -739,7 +758,7 @@ static void ieee80211_ibss_work(struct work_struct *work)
739 if (WARN_ON(local->suspended)) 758 if (WARN_ON(local->suspended))
740 return; 759 return;
741 760
742 if (!netif_running(sdata->dev)) 761 if (!ieee80211_sdata_running(sdata))
743 return; 762 return;
744 763
745 if (local->scanning) 764 if (local->scanning)
@@ -822,7 +841,7 @@ void ieee80211_ibss_notify_scan_completed(struct ieee80211_local *local)
822 841
823 mutex_lock(&local->iflist_mtx); 842 mutex_lock(&local->iflist_mtx);
824 list_for_each_entry(sdata, &local->interfaces, list) { 843 list_for_each_entry(sdata, &local->interfaces, list) {
825 if (!netif_running(sdata->dev)) 844 if (!ieee80211_sdata_running(sdata))
826 continue; 845 continue;
827 if (sdata->vif.type != NL80211_IFTYPE_ADHOC) 846 if (sdata->vif.type != NL80211_IFTYPE_ADHOC)
828 continue; 847 continue;
diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
index 10d316e455de..241533e1bc03 100644
--- a/net/mac80211/ieee80211_i.h
+++ b/net/mac80211/ieee80211_i.h
@@ -2,7 +2,7 @@
2 * Copyright 2002-2005, Instant802 Networks, Inc. 2 * Copyright 2002-2005, Instant802 Networks, Inc.
3 * Copyright 2005, Devicescape Software, Inc. 3 * Copyright 2005, Devicescape Software, Inc.
4 * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz> 4 * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz>
5 * Copyright 2007-2008 Johannes Berg <johannes@sipsolutions.net> 5 * Copyright 2007-2010 Johannes Berg <johannes@sipsolutions.net>
6 * 6 *
7 * This program is free software; you can redistribute it and/or modify 7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as 8 * it under the terms of the GNU General Public License version 2 as
@@ -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/ieee80211_radiotap.h>
26#include <net/cfg80211.h> 27#include <net/cfg80211.h>
27#include <net/mac80211.h> 28#include <net/mac80211.h>
28#include "key.h" 29#include "key.h"
@@ -57,6 +58,15 @@ struct ieee80211_local;
57 58
58#define TU_TO_EXP_TIME(x) (jiffies + usecs_to_jiffies((x) * 1024)) 59#define TU_TO_EXP_TIME(x) (jiffies + usecs_to_jiffies((x) * 1024))
59 60
61#define IEEE80211_DEFAULT_UAPSD_QUEUES \
62 (IEEE80211_WMM_IE_STA_QOSINFO_AC_BK | \
63 IEEE80211_WMM_IE_STA_QOSINFO_AC_BE | \
64 IEEE80211_WMM_IE_STA_QOSINFO_AC_VI | \
65 IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
66
67#define IEEE80211_DEFAULT_MAX_SP_LEN \
68 IEEE80211_WMM_IE_STA_QOSINFO_SP_ALL
69
60struct ieee80211_fragment_entry { 70struct ieee80211_fragment_entry {
61 unsigned long first_frag_time; 71 unsigned long first_frag_time;
62 unsigned int seq; 72 unsigned int seq;
@@ -70,9 +80,6 @@ struct ieee80211_fragment_entry {
70 80
71 81
72struct ieee80211_bss { 82struct ieee80211_bss {
73 /* Yes, this is a hack */
74 struct cfg80211_bss cbss;
75
76 /* don't want to look up all the time */ 83 /* don't want to look up all the time */
77 size_t ssid_len; 84 size_t ssid_len;
78 u8 ssid[IEEE80211_MAX_SSID_LEN]; 85 u8 ssid[IEEE80211_MAX_SSID_LEN];
@@ -80,6 +87,7 @@ struct ieee80211_bss {
80 u8 dtim_period; 87 u8 dtim_period;
81 88
82 bool wmm_used; 89 bool wmm_used;
90 bool uapsd_supported;
83 91
84 unsigned long last_probe_resp; 92 unsigned long last_probe_resp;
85 93
@@ -139,7 +147,6 @@ typedef unsigned __bitwise__ ieee80211_tx_result;
139 147
140struct ieee80211_tx_data { 148struct ieee80211_tx_data {
141 struct sk_buff *skb; 149 struct sk_buff *skb;
142 struct net_device *dev;
143 struct ieee80211_local *local; 150 struct ieee80211_local *local;
144 struct ieee80211_sub_if_data *sdata; 151 struct ieee80211_sub_if_data *sdata;
145 struct sta_info *sta; 152 struct sta_info *sta;
@@ -162,21 +169,17 @@ typedef unsigned __bitwise__ ieee80211_rx_result;
162/* frame is destined to interface currently processed (incl. multicast frames) */ 169/* frame is destined to interface currently processed (incl. multicast frames) */
163#define IEEE80211_RX_RA_MATCH BIT(1) 170#define IEEE80211_RX_RA_MATCH BIT(1)
164#define IEEE80211_RX_AMSDU BIT(2) 171#define IEEE80211_RX_AMSDU BIT(2)
165#define IEEE80211_RX_CMNTR_REPORTED BIT(3) 172#define IEEE80211_RX_FRAGMENTED BIT(3)
166#define IEEE80211_RX_FRAGMENTED BIT(4) 173/* only add flags here that do not change with subframes of an aMPDU */
167 174
168struct ieee80211_rx_data { 175struct ieee80211_rx_data {
169 struct sk_buff *skb; 176 struct sk_buff *skb;
170 struct net_device *dev;
171 struct ieee80211_local *local; 177 struct ieee80211_local *local;
172 struct ieee80211_sub_if_data *sdata; 178 struct ieee80211_sub_if_data *sdata;
173 struct sta_info *sta; 179 struct sta_info *sta;
174 struct ieee80211_key *key; 180 struct ieee80211_key *key;
175 struct ieee80211_rx_status *status;
176 struct ieee80211_rate *rate;
177 181
178 unsigned int flags; 182 unsigned int flags;
179 int sent_ps_buffered;
180 int queue; 183 int queue;
181 u32 tkip_iv32; 184 u32 tkip_iv32;
182 u16 tkip_iv16; 185 u16 tkip_iv16;
@@ -209,6 +212,9 @@ struct ieee80211_if_wds {
209 212
210struct ieee80211_if_vlan { 213struct ieee80211_if_vlan {
211 struct list_head list; 214 struct list_head list;
215
216 /* used for all tx if the VLAN is configured to 4-addr mode */
217 struct sta_info *sta;
212}; 218};
213 219
214struct mesh_stats { 220struct mesh_stats {
@@ -228,31 +234,77 @@ struct mesh_preq_queue {
228 u8 flags; 234 u8 flags;
229}; 235};
230 236
231enum ieee80211_mgd_state { 237enum ieee80211_work_type {
232 IEEE80211_MGD_STATE_IDLE, 238 IEEE80211_WORK_ABORT,
233 IEEE80211_MGD_STATE_PROBE, 239 IEEE80211_WORK_DIRECT_PROBE,
234 IEEE80211_MGD_STATE_AUTH, 240 IEEE80211_WORK_AUTH,
235 IEEE80211_MGD_STATE_ASSOC, 241 IEEE80211_WORK_ASSOC,
242 IEEE80211_WORK_REMAIN_ON_CHANNEL,
236}; 243};
237 244
238struct ieee80211_mgd_work { 245/**
246 * enum work_done_result - indicates what to do after work was done
247 *
248 * @WORK_DONE_DESTROY: This work item is no longer needed, destroy.
249 * @WORK_DONE_REQUEUE: This work item was reset to be reused, and
250 * should be requeued.
251 */
252enum work_done_result {
253 WORK_DONE_DESTROY,
254 WORK_DONE_REQUEUE,
255};
256
257struct ieee80211_work {
239 struct list_head list; 258 struct list_head list;
240 struct ieee80211_bss *bss; 259
241 int ie_len; 260 struct rcu_head rcu_head;
242 u8 prev_bssid[ETH_ALEN]; 261
243 u8 ssid[IEEE80211_MAX_SSID_LEN]; 262 struct ieee80211_sub_if_data *sdata;
244 u8 ssid_len; 263
264 enum work_done_result (*done)(struct ieee80211_work *wk,
265 struct sk_buff *skb);
266
267 struct ieee80211_channel *chan;
268 enum nl80211_channel_type chan_type;
269
245 unsigned long timeout; 270 unsigned long timeout;
246 enum ieee80211_mgd_state state; 271 enum ieee80211_work_type type;
247 u16 auth_alg, auth_transaction;
248 272
249 int tries; 273 u8 filter_ta[ETH_ALEN];
250 274
251 u8 key[WLAN_KEY_LEN_WEP104]; 275 bool started;
252 u8 key_len, key_idx; 276
277 union {
278 struct {
279 int tries;
280 u16 algorithm, transaction;
281 u8 ssid[IEEE80211_MAX_SSID_LEN];
282 u8 ssid_len;
283 u8 key[WLAN_KEY_LEN_WEP104];
284 u8 key_len, key_idx;
285 bool privacy;
286 } probe_auth;
287 struct {
288 struct cfg80211_bss *bss;
289 const u8 *supp_rates;
290 const u8 *ht_information_ie;
291 enum ieee80211_smps_mode smps;
292 int tries;
293 u16 capability;
294 u8 prev_bssid[ETH_ALEN];
295 u8 ssid[IEEE80211_MAX_SSID_LEN];
296 u8 ssid_len;
297 u8 supp_rates_len;
298 bool wmm_used, use_11n, uapsd_used;
299 } assoc;
300 struct {
301 u32 duration;
302 } remain;
303 };
253 304
305 int ie_len;
254 /* must be last */ 306 /* must be last */
255 u8 ie[0]; /* for auth or assoc frame, not probe */ 307 u8 ie[0];
256}; 308};
257 309
258/* flags used in struct ieee80211_if_managed.flags */ 310/* flags used in struct ieee80211_if_managed.flags */
@@ -260,15 +312,11 @@ enum ieee80211_sta_flags {
260 IEEE80211_STA_BEACON_POLL = BIT(0), 312 IEEE80211_STA_BEACON_POLL = BIT(0),
261 IEEE80211_STA_CONNECTION_POLL = BIT(1), 313 IEEE80211_STA_CONNECTION_POLL = BIT(1),
262 IEEE80211_STA_CONTROL_PORT = BIT(2), 314 IEEE80211_STA_CONTROL_PORT = BIT(2),
263 IEEE80211_STA_WMM_ENABLED = BIT(3),
264 IEEE80211_STA_DISABLE_11N = BIT(4), 315 IEEE80211_STA_DISABLE_11N = BIT(4),
265 IEEE80211_STA_CSA_RECEIVED = BIT(5), 316 IEEE80211_STA_CSA_RECEIVED = BIT(5),
266 IEEE80211_STA_MFP_ENABLED = BIT(6), 317 IEEE80211_STA_MFP_ENABLED = BIT(6),
267}; 318 IEEE80211_STA_UAPSD_ENABLED = BIT(7),
268 319 IEEE80211_STA_NULLFUNC_ACKED = BIT(8),
269/* flags for MLME request */
270enum ieee80211_sta_request {
271 IEEE80211_STA_REQ_SCAN,
272}; 320};
273 321
274struct ieee80211_if_managed { 322struct ieee80211_if_managed {
@@ -285,21 +333,18 @@ struct ieee80211_if_managed {
285 int probe_send_count; 333 int probe_send_count;
286 334
287 struct mutex mtx; 335 struct mutex mtx;
288 struct ieee80211_bss *associated; 336 struct cfg80211_bss *associated;
289 struct ieee80211_mgd_work *old_associate_work;
290 struct list_head work_list;
291 337
292 u8 bssid[ETH_ALEN]; 338 u8 bssid[ETH_ALEN];
293 339
294 u16 aid; 340 u16 aid;
295 u16 capab;
296 341
297 struct sk_buff_head skb_queue; 342 struct sk_buff_head skb_queue;
298 343
299 unsigned long timers_running; /* used for quiesce/restart */ 344 unsigned long timers_running; /* used for quiesce/restart */
300 bool powersave; /* powersave requested for this iface */ 345 bool powersave; /* powersave requested for this iface */
301 346 enum ieee80211_smps_mode req_smps, /* requested smps mode */
302 unsigned long request; 347 ap_smps; /* smps mode AP thinks we're in */
303 348
304 unsigned int flags; 349 unsigned int flags;
305 350
@@ -312,6 +357,8 @@ struct ieee80211_if_managed {
312 } mfp; /* management frame protection */ 357 } mfp; /* management frame protection */
313 358
314 int wmm_last_param_set; 359 int wmm_last_param_set;
360
361 u8 use_4addr;
315}; 362};
316 363
317enum ieee80211_ibss_request { 364enum ieee80211_ibss_request {
@@ -353,6 +400,7 @@ struct ieee80211_if_mesh {
353 struct work_struct work; 400 struct work_struct work;
354 struct timer_list housekeeping_timer; 401 struct timer_list housekeeping_timer;
355 struct timer_list mesh_path_timer; 402 struct timer_list mesh_path_timer;
403 struct timer_list mesh_path_root_timer;
356 struct sk_buff_head skb_queue; 404 struct sk_buff_head skb_queue;
357 405
358 unsigned long timers_running; 406 unsigned long timers_running;
@@ -362,23 +410,23 @@ struct ieee80211_if_mesh {
362 u8 mesh_id[IEEE80211_MAX_MESH_ID_LEN]; 410 u8 mesh_id[IEEE80211_MAX_MESH_ID_LEN];
363 size_t mesh_id_len; 411 size_t mesh_id_len;
364 /* Active Path Selection Protocol Identifier */ 412 /* Active Path Selection Protocol Identifier */
365 u8 mesh_pp_id[4]; 413 u8 mesh_pp_id;
366 /* Active Path Selection Metric Identifier */ 414 /* Active Path Selection Metric Identifier */
367 u8 mesh_pm_id[4]; 415 u8 mesh_pm_id;
368 /* Congestion Control Mode Identifier */ 416 /* Congestion Control Mode Identifier */
369 u8 mesh_cc_id[4]; 417 u8 mesh_cc_id;
370 /* Synchronization Protocol Identifier */ 418 /* Synchronization Protocol Identifier */
371 u8 mesh_sp_id[4]; 419 u8 mesh_sp_id;
372 /* Authentication Protocol Identifier */ 420 /* Authentication Protocol Identifier */
373 u8 mesh_auth_id[4]; 421 u8 mesh_auth_id;
374 /* Local mesh Destination Sequence Number */ 422 /* Local mesh Sequence Number */
375 u32 dsn; 423 u32 sn;
376 /* Last used PREQ ID */ 424 /* Last used PREQ ID */
377 u32 preq_id; 425 u32 preq_id;
378 atomic_t mpaths; 426 atomic_t mpaths;
379 /* Timestamp of last DSN update */ 427 /* Timestamp of last SN update */
380 unsigned long last_dsn_update; 428 unsigned long last_sn_update;
381 /* Timestamp of last DSN sent */ 429 /* Timestamp of last SN sent */
382 unsigned long last_preq; 430 unsigned long last_preq;
383 struct mesh_rmc *rmc; 431 struct mesh_rmc *rmc;
384 spinlock_t mesh_preq_queue_lock; 432 spinlock_t mesh_preq_queue_lock;
@@ -430,6 +478,8 @@ struct ieee80211_sub_if_data {
430 478
431 int drop_unencrypted; 479 int drop_unencrypted;
432 480
481 char name[IFNAMSIZ];
482
433 /* 483 /*
434 * keep track of whether the HT opmode (stored in 484 * keep track of whether the HT opmode (stored in
435 * vif.bss_info.ht_operation_mode) is valid. 485 * vif.bss_info.ht_operation_mode) is valid.
@@ -455,8 +505,8 @@ struct ieee80211_sub_if_data {
455 */ 505 */
456 struct ieee80211_if_ap *bss; 506 struct ieee80211_if_ap *bss;
457 507
458 int force_unicast_rateidx; /* forced TX rateidx for unicast frames */ 508 /* bitmap of allowed (non-MCS) rate indexes for rate control */
459 int max_ratectrl_rateidx; /* max TX rateidx for rate control */ 509 u32 rc_rateidx_mask[IEEE80211_NUM_BANDS];
460 510
461 union { 511 union {
462 struct ieee80211_if_ap ap; 512 struct ieee80211_if_ap ap;
@@ -471,74 +521,11 @@ struct ieee80211_sub_if_data {
471 } u; 521 } u;
472 522
473#ifdef CONFIG_MAC80211_DEBUGFS 523#ifdef CONFIG_MAC80211_DEBUGFS
474 struct dentry *debugfsdir;
475 union {
476 struct {
477 struct dentry *drop_unencrypted;
478 struct dentry *bssid;
479 struct dentry *aid;
480 struct dentry *capab;
481 struct dentry *force_unicast_rateidx;
482 struct dentry *max_ratectrl_rateidx;
483 } sta;
484 struct {
485 struct dentry *drop_unencrypted;
486 struct dentry *num_sta_ps;
487 struct dentry *dtim_count;
488 struct dentry *force_unicast_rateidx;
489 struct dentry *max_ratectrl_rateidx;
490 struct dentry *num_buffered_multicast;
491 } ap;
492 struct {
493 struct dentry *drop_unencrypted;
494 struct dentry *peer;
495 struct dentry *force_unicast_rateidx;
496 struct dentry *max_ratectrl_rateidx;
497 } wds;
498 struct {
499 struct dentry *drop_unencrypted;
500 struct dentry *force_unicast_rateidx;
501 struct dentry *max_ratectrl_rateidx;
502 } vlan;
503 struct {
504 struct dentry *mode;
505 } monitor;
506 } debugfs;
507 struct { 524 struct {
525 struct dentry *dir;
508 struct dentry *default_key; 526 struct dentry *default_key;
509 struct dentry *default_mgmt_key; 527 struct dentry *default_mgmt_key;
510 } common_debugfs; 528 } debugfs;
511
512#ifdef CONFIG_MAC80211_MESH
513 struct dentry *mesh_stats_dir;
514 struct {
515 struct dentry *fwded_mcast;
516 struct dentry *fwded_unicast;
517 struct dentry *fwded_frames;
518 struct dentry *dropped_frames_ttl;
519 struct dentry *dropped_frames_no_route;
520 struct dentry *estab_plinks;
521 struct timer_list mesh_path_timer;
522 } mesh_stats;
523
524 struct dentry *mesh_config_dir;
525 struct {
526 struct dentry *dot11MeshRetryTimeout;
527 struct dentry *dot11MeshConfirmTimeout;
528 struct dentry *dot11MeshHoldingTimeout;
529 struct dentry *dot11MeshMaxRetries;
530 struct dentry *dot11MeshTTL;
531 struct dentry *auto_open_plinks;
532 struct dentry *dot11MeshMaxPeerLinks;
533 struct dentry *dot11MeshHWMPactivePathTimeout;
534 struct dentry *dot11MeshHWMPpreqMinInterval;
535 struct dentry *dot11MeshHWMPnetDiameterTraversalTime;
536 struct dentry *dot11MeshHWMPmaxPREQretries;
537 struct dentry *path_refresh_time;
538 struct dentry *min_discovery_timeout;
539 } mesh_config;
540#endif
541
542#endif 529#endif
543 /* must be last, dynamically sized area in this! */ 530 /* must be last, dynamically sized area in this! */
544 struct ieee80211_vif vif; 531 struct ieee80211_vif vif;
@@ -625,6 +612,15 @@ struct ieee80211_local {
625 const struct ieee80211_ops *ops; 612 const struct ieee80211_ops *ops;
626 613
627 /* 614 /*
615 * work stuff, potentially off-channel (in the future)
616 */
617 struct mutex work_mtx;
618 struct list_head work_list;
619 struct timer_list work_timer;
620 struct work_struct work_work;
621 struct sk_buff_head work_skb_queue;
622
623 /*
628 * private workqueue to mac80211. mac80211 makes this accessible 624 * private workqueue to mac80211. mac80211 makes this accessible
629 * via ieee80211_queue_work() 625 * via ieee80211_queue_work()
630 */ 626 */
@@ -639,7 +635,6 @@ struct ieee80211_local {
639 /* number of interfaces with corresponding FIF_ flags */ 635 /* number of interfaces with corresponding FIF_ flags */
640 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll; 636 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll;
641 unsigned int filter_flags; /* FIF_* */ 637 unsigned int filter_flags; /* FIF_* */
642 struct iw_statistics wstats;
643 638
644 /* protects the aggregated multicast list and filter calls */ 639 /* protects the aggregated multicast list and filter calls */
645 spinlock_t filter_lock; 640 spinlock_t filter_lock;
@@ -647,6 +642,9 @@ struct ieee80211_local {
647 /* used for uploading changed mc list */ 642 /* used for uploading changed mc list */
648 struct work_struct reconfig_filter; 643 struct work_struct reconfig_filter;
649 644
645 /* used to reconfigure hardware SM PS */
646 struct work_struct recalc_smps;
647
650 /* aggregated multicast list */ 648 /* aggregated multicast list */
651 struct dev_addr_list *mc_list; 649 struct dev_addr_list *mc_list;
652 int mc_count; 650 int mc_count;
@@ -691,15 +689,18 @@ struct ieee80211_local {
691 689
692 /* Station data */ 690 /* Station data */
693 /* 691 /*
694 * The lock only protects the list, hash, timer and counter 692 * The mutex only protects the list and counter,
695 * against manipulation, reads are done in RCU. Additionally, 693 * reads are done in RCU.
696 * the lock protects each BSS's TIM bitmap. 694 * Additionally, the lock protects the hash table,
695 * the pending list and each BSS's TIM bitmap.
697 */ 696 */
697 struct mutex sta_mtx;
698 spinlock_t sta_lock; 698 spinlock_t sta_lock;
699 unsigned long num_sta; 699 unsigned long num_sta;
700 struct list_head sta_list; 700 struct list_head sta_list, sta_pending_list;
701 struct sta_info *sta_hash[STA_HASH_SIZE]; 701 struct sta_info *sta_hash[STA_HASH_SIZE];
702 struct timer_list sta_cleanup; 702 struct timer_list sta_cleanup;
703 struct work_struct sta_finish_work;
703 int sta_generation; 704 int sta_generation;
704 705
705 struct sk_buff_head pending[IEEE80211_MAX_QUEUES]; 706 struct sk_buff_head pending[IEEE80211_MAX_QUEUES];
@@ -738,10 +739,9 @@ struct ieee80211_local {
738 unsigned long scanning; 739 unsigned long scanning;
739 struct cfg80211_ssid scan_ssid; 740 struct cfg80211_ssid scan_ssid;
740 struct cfg80211_scan_request *int_scan_req; 741 struct cfg80211_scan_request *int_scan_req;
741 struct cfg80211_scan_request *scan_req; 742 struct cfg80211_scan_request *scan_req, *hw_scan_req;
742 struct ieee80211_channel *scan_channel; 743 struct ieee80211_channel *scan_channel;
743 const u8 *orig_ies; 744 enum ieee80211_band hw_scan_band;
744 int orig_ies_len;
745 int scan_channel_idx; 745 int scan_channel_idx;
746 int scan_ies_len; 746 int scan_ies_len;
747 747
@@ -751,6 +751,10 @@ struct ieee80211_local {
751 enum nl80211_channel_type oper_channel_type; 751 enum nl80211_channel_type oper_channel_type;
752 struct ieee80211_channel *oper_channel, *csa_channel; 752 struct ieee80211_channel *oper_channel, *csa_channel;
753 753
754 /* Temporary remain-on-channel for off-channel operations */
755 struct ieee80211_channel *tmp_channel;
756 enum nl80211_channel_type tmp_channel_type;
757
754 /* SNMP counters */ 758 /* SNMP counters */
755 /* dot11CountersTable */ 759 /* dot11CountersTable */
756 u32 dot11TransmittedFragmentCount; 760 u32 dot11TransmittedFragmentCount;
@@ -770,10 +774,6 @@ struct ieee80211_local {
770 assoc_led_name[32], radio_led_name[32]; 774 assoc_led_name[32], radio_led_name[32];
771#endif 775#endif
772 776
773#ifdef CONFIG_MAC80211_DEBUGFS
774 struct work_struct sta_debugfs_add;
775#endif
776
777#ifdef CONFIG_MAC80211_DEBUG_COUNTERS 777#ifdef CONFIG_MAC80211_DEBUG_COUNTERS
778 /* TX/RX handler statistics */ 778 /* TX/RX handler statistics */
779 unsigned int tx_handlers_drop; 779 unsigned int tx_handlers_drop;
@@ -807,7 +807,22 @@ struct ieee80211_local {
807 int wifi_wme_noack_test; 807 int wifi_wme_noack_test;
808 unsigned int wmm_acm; /* bit field of ACM bits (BIT(802.1D tag)) */ 808 unsigned int wmm_acm; /* bit field of ACM bits (BIT(802.1D tag)) */
809 809
810 /*
811 * Bitmask of enabled u-apsd queues,
812 * IEEE80211_WMM_IE_STA_QOSINFO_AC_BE & co. Needs a new association
813 * to take effect.
814 */
815 unsigned int uapsd_queues;
816
817 /*
818 * Maximum number of buffered frames AP can deliver during a
819 * service period, IEEE80211_WMM_IE_STA_QOSINFO_SP_ALL or similar.
820 * Needs a new association to take effect.
821 */
822 unsigned int uapsd_max_sp_len;
823
810 bool pspolling; 824 bool pspolling;
825 bool offchannel_ps_enabled;
811 /* 826 /*
812 * PS can only be enabled when we have exactly one managed 827 * PS can only be enabled when we have exactly one managed
813 * interface (and monitors) in PS, this then points there. 828 * interface (and monitors) in PS, this then points there.
@@ -821,58 +836,13 @@ struct ieee80211_local {
821 int user_power_level; /* in dBm */ 836 int user_power_level; /* in dBm */
822 int power_constr_level; /* in dBm */ 837 int power_constr_level; /* in dBm */
823 838
839 enum ieee80211_smps_mode smps_mode;
840
824 struct work_struct restart_work; 841 struct work_struct restart_work;
825 842
826#ifdef CONFIG_MAC80211_DEBUGFS 843#ifdef CONFIG_MAC80211_DEBUGFS
827 struct local_debugfsdentries { 844 struct local_debugfsdentries {
828 struct dentry *rcdir; 845 struct dentry *rcdir;
829 struct dentry *rcname;
830 struct dentry *frequency;
831 struct dentry *total_ps_buffered;
832 struct dentry *wep_iv;
833 struct dentry *tsf;
834 struct dentry *queues;
835 struct dentry *reset;
836 struct dentry *noack;
837 struct dentry *statistics;
838 struct local_debugfsdentries_statsdentries {
839 struct dentry *transmitted_fragment_count;
840 struct dentry *multicast_transmitted_frame_count;
841 struct dentry *failed_count;
842 struct dentry *retry_count;
843 struct dentry *multiple_retry_count;
844 struct dentry *frame_duplicate_count;
845 struct dentry *received_fragment_count;
846 struct dentry *multicast_received_frame_count;
847 struct dentry *transmitted_frame_count;
848 struct dentry *wep_undecryptable_count;
849 struct dentry *num_scans;
850#ifdef CONFIG_MAC80211_DEBUG_COUNTERS
851 struct dentry *tx_handlers_drop;
852 struct dentry *tx_handlers_queued;
853 struct dentry *tx_handlers_drop_unencrypted;
854 struct dentry *tx_handlers_drop_fragment;
855 struct dentry *tx_handlers_drop_wep;
856 struct dentry *tx_handlers_drop_not_assoc;
857 struct dentry *tx_handlers_drop_unauth_port;
858 struct dentry *rx_handlers_drop;
859 struct dentry *rx_handlers_queued;
860 struct dentry *rx_handlers_drop_nullfunc;
861 struct dentry *rx_handlers_drop_defrag;
862 struct dentry *rx_handlers_drop_short;
863 struct dentry *rx_handlers_drop_passive_scan;
864 struct dentry *tx_expand_skb_head;
865 struct dentry *tx_expand_skb_head_cloned;
866 struct dentry *rx_expand_skb_head;
867 struct dentry *rx_expand_skb_head2;
868 struct dentry *rx_handlers_fragments;
869 struct dentry *tx_status_drop;
870#endif
871 struct dentry *dot11ACKFailureCount;
872 struct dentry *dot11RTSFailureCount;
873 struct dentry *dot11FCSErrorCount;
874 struct dentry *dot11RTSSuccessCount;
875 } stats;
876 struct dentry *stations; 846 struct dentry *stations;
877 struct dentry *keys; 847 struct dentry *keys;
878 } debugfs; 848 } debugfs;
@@ -885,8 +855,9 @@ IEEE80211_DEV_TO_SUB_IF(struct net_device *dev)
885 return netdev_priv(dev); 855 return netdev_priv(dev);
886} 856}
887 857
888/* this struct represents 802.11n's RA/TID combination */ 858/* this struct represents 802.11n's RA/TID combination along with our vif */
889struct ieee80211_ra_tid { 859struct ieee80211_ra_tid {
860 struct ieee80211_vif *vif;
890 u8 ra[ETH_ALEN]; 861 u8 ra[ETH_ALEN];
891 u16 tid; 862 u16 tid;
892}; 863};
@@ -913,12 +884,13 @@ struct ieee802_11_elems {
913 u8 *wmm_param; 884 u8 *wmm_param;
914 struct ieee80211_ht_cap *ht_cap_elem; 885 struct ieee80211_ht_cap *ht_cap_elem;
915 struct ieee80211_ht_info *ht_info_elem; 886 struct ieee80211_ht_info *ht_info_elem;
916 u8 *mesh_config; 887 struct ieee80211_meshconf_ie *mesh_config;
917 u8 *mesh_id; 888 u8 *mesh_id;
918 u8 *peer_link; 889 u8 *peer_link;
919 u8 *preq; 890 u8 *preq;
920 u8 *prep; 891 u8 *prep;
921 u8 *perr; 892 u8 *perr;
893 struct ieee80211_rann_ie *rann;
922 u8 *ch_switch_elem; 894 u8 *ch_switch_elem;
923 u8 *country_elem; 895 u8 *country_elem;
924 u8 *pwr_constr_elem; 896 u8 *pwr_constr_elem;
@@ -940,7 +912,6 @@ struct ieee802_11_elems {
940 u8 ext_supp_rates_len; 912 u8 ext_supp_rates_len;
941 u8 wmm_info_len; 913 u8 wmm_info_len;
942 u8 wmm_param_len; 914 u8 wmm_param_len;
943 u8 mesh_config_len;
944 u8 mesh_id_len; 915 u8 mesh_id_len;
945 u8 peer_link_len; 916 u8 peer_link_len;
946 u8 preq_len; 917 u8 preq_len;
@@ -981,6 +952,8 @@ void ieee80211_bss_info_change_notify(struct ieee80211_sub_if_data *sdata,
981void ieee80211_configure_filter(struct ieee80211_local *local); 952void ieee80211_configure_filter(struct ieee80211_local *local);
982u32 ieee80211_reset_erp_info(struct ieee80211_sub_if_data *sdata); 953u32 ieee80211_reset_erp_info(struct ieee80211_sub_if_data *sdata);
983 954
955extern bool ieee80211_disable_40mhz_24ghz;
956
984/* STA code */ 957/* STA code */
985void ieee80211_sta_setup_sdata(struct ieee80211_sub_if_data *sdata); 958void ieee80211_sta_setup_sdata(struct ieee80211_sub_if_data *sdata);
986int ieee80211_mgd_auth(struct ieee80211_sub_if_data *sdata, 959int ieee80211_mgd_auth(struct ieee80211_sub_if_data *sdata,
@@ -993,6 +966,10 @@ int ieee80211_mgd_deauth(struct ieee80211_sub_if_data *sdata,
993int ieee80211_mgd_disassoc(struct ieee80211_sub_if_data *sdata, 966int ieee80211_mgd_disassoc(struct ieee80211_sub_if_data *sdata,
994 struct cfg80211_disassoc_request *req, 967 struct cfg80211_disassoc_request *req,
995 void *cookie); 968 void *cookie);
969int ieee80211_mgd_action(struct ieee80211_sub_if_data *sdata,
970 struct ieee80211_channel *chan,
971 enum nl80211_channel_type channel_type,
972 const u8 *buf, size_t len, u64 *cookie);
996ieee80211_rx_result ieee80211_sta_rx_mgmt(struct ieee80211_sub_if_data *sdata, 973ieee80211_rx_result ieee80211_sta_rx_mgmt(struct ieee80211_sub_if_data *sdata,
997 struct sk_buff *skb); 974 struct sk_buff *skb);
998void ieee80211_send_pspoll(struct ieee80211_local *local, 975void ieee80211_send_pspoll(struct ieee80211_local *local,
@@ -1012,7 +989,8 @@ void ieee80211_ibss_setup_sdata(struct ieee80211_sub_if_data *sdata);
1012ieee80211_rx_result 989ieee80211_rx_result
1013ieee80211_ibss_rx_mgmt(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb); 990ieee80211_ibss_rx_mgmt(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb);
1014struct sta_info *ieee80211_ibss_add_sta(struct ieee80211_sub_if_data *sdata, 991struct sta_info *ieee80211_ibss_add_sta(struct ieee80211_sub_if_data *sdata,
1015 u8 *bssid, u8 *addr, u32 supp_rates); 992 u8 *bssid, u8 *addr, u32 supp_rates,
993 gfp_t gfp);
1016int ieee80211_ibss_join(struct ieee80211_sub_if_data *sdata, 994int ieee80211_ibss_join(struct ieee80211_sub_if_data *sdata,
1017 struct cfg80211_ibss_params *params); 995 struct cfg80211_ibss_params *params);
1018int ieee80211_ibss_leave(struct ieee80211_sub_if_data *sdata); 996int ieee80211_ibss_leave(struct ieee80211_sub_if_data *sdata);
@@ -1044,7 +1022,15 @@ ieee80211_rx_bss_get(struct ieee80211_local *local, u8 *bssid, int freq,
1044void ieee80211_rx_bss_put(struct ieee80211_local *local, 1022void ieee80211_rx_bss_put(struct ieee80211_local *local,
1045 struct ieee80211_bss *bss); 1023 struct ieee80211_bss *bss);
1046 1024
1025/* off-channel helpers */
1026void ieee80211_offchannel_stop_beaconing(struct ieee80211_local *local);
1027void ieee80211_offchannel_stop_station(struct ieee80211_local *local);
1028void ieee80211_offchannel_return(struct ieee80211_local *local,
1029 bool enable_beaconing);
1030
1047/* interface handling */ 1031/* interface handling */
1032int ieee80211_iface_init(void);
1033void ieee80211_iface_exit(void);
1048int ieee80211_if_add(struct ieee80211_local *local, const char *name, 1034int ieee80211_if_add(struct ieee80211_local *local, const char *name,
1049 struct net_device **new_dev, enum nl80211_iftype type, 1035 struct net_device **new_dev, enum nl80211_iftype type,
1050 struct vif_params *params); 1036 struct vif_params *params);
@@ -1055,6 +1041,11 @@ void ieee80211_remove_interfaces(struct ieee80211_local *local);
1055u32 __ieee80211_recalc_idle(struct ieee80211_local *local); 1041u32 __ieee80211_recalc_idle(struct ieee80211_local *local);
1056void ieee80211_recalc_idle(struct ieee80211_local *local); 1042void ieee80211_recalc_idle(struct ieee80211_local *local);
1057 1043
1044static inline bool ieee80211_sdata_running(struct ieee80211_sub_if_data *sdata)
1045{
1046 return netif_running(sdata->dev);
1047}
1048
1058/* tx handling */ 1049/* tx handling */
1059void ieee80211_clear_tx_pending(struct ieee80211_local *local); 1050void ieee80211_clear_tx_pending(struct ieee80211_local *local);
1060void ieee80211_tx_pending(unsigned long data); 1051void ieee80211_tx_pending(unsigned long data);
@@ -1063,6 +1054,18 @@ netdev_tx_t ieee80211_monitor_start_xmit(struct sk_buff *skb,
1063netdev_tx_t ieee80211_subif_start_xmit(struct sk_buff *skb, 1054netdev_tx_t ieee80211_subif_start_xmit(struct sk_buff *skb,
1064 struct net_device *dev); 1055 struct net_device *dev);
1065 1056
1057/*
1058 * radiotap header for status frames
1059 */
1060struct ieee80211_tx_status_rtap_hdr {
1061 struct ieee80211_radiotap_header hdr;
1062 u8 rate;
1063 u8 padding_for_rate;
1064 __le16 tx_flags;
1065 u8 data_retries;
1066} __attribute__ ((packed));
1067
1068
1066/* HT */ 1069/* HT */
1067void ieee80211_ht_cap_ie_to_sta_ht_cap(struct ieee80211_supported_band *sband, 1070void ieee80211_ht_cap_ie_to_sta_ht_cap(struct ieee80211_supported_band *sband,
1068 struct ieee80211_ht_cap *ht_cap_ie, 1071 struct ieee80211_ht_cap *ht_cap_ie,
@@ -1071,6 +1074,9 @@ void ieee80211_send_bar(struct ieee80211_sub_if_data *sdata, u8 *ra, u16 tid, u1
1071void ieee80211_send_delba(struct ieee80211_sub_if_data *sdata, 1074void ieee80211_send_delba(struct ieee80211_sub_if_data *sdata,
1072 const u8 *da, u16 tid, 1075 const u8 *da, u16 tid,
1073 u16 initiator, u16 reason_code); 1076 u16 initiator, u16 reason_code);
1077int ieee80211_send_smps_action(struct ieee80211_sub_if_data *sdata,
1078 enum ieee80211_smps_mode smps, const u8 *da,
1079 const u8 *bssid);
1074 1080
1075void ieee80211_sta_stop_rx_ba_session(struct ieee80211_sub_if_data *sdata, u8 *da, 1081void ieee80211_sta_stop_rx_ba_session(struct ieee80211_sub_if_data *sdata, u8 *da,
1076 u16 tid, u16 initiator, u16 reason); 1082 u16 tid, u16 initiator, u16 reason);
@@ -1132,8 +1138,7 @@ void mac80211_ev_michael_mic_failure(struct ieee80211_sub_if_data *sdata, int ke
1132 struct ieee80211_hdr *hdr, const u8 *tsc, 1138 struct ieee80211_hdr *hdr, const u8 *tsc,
1133 gfp_t gfp); 1139 gfp_t gfp);
1134void ieee80211_set_wmm_default(struct ieee80211_sub_if_data *sdata); 1140void ieee80211_set_wmm_default(struct ieee80211_sub_if_data *sdata);
1135void ieee80211_tx_skb(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb, 1141void ieee80211_tx_skb(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb);
1136 int encrypt);
1137void ieee802_11_parse_elems(u8 *start, size_t len, 1142void ieee802_11_parse_elems(u8 *start, size_t len,
1138 struct ieee802_11_elems *elems); 1143 struct ieee802_11_elems *elems);
1139u32 ieee802_11_parse_elems_crc(u8 *start, size_t len, 1144u32 ieee802_11_parse_elems_crc(u8 *start, size_t len,
@@ -1170,7 +1175,8 @@ void ieee80211_send_auth(struct ieee80211_sub_if_data *sdata,
1170 u8 *extra, size_t extra_len, const u8 *bssid, 1175 u8 *extra, size_t extra_len, const u8 *bssid,
1171 const u8 *key, u8 key_len, u8 key_idx); 1176 const u8 *key, u8 key_len, u8 key_idx);
1172int ieee80211_build_preq_ies(struct ieee80211_local *local, u8 *buffer, 1177int ieee80211_build_preq_ies(struct ieee80211_local *local, u8 *buffer,
1173 const u8 *ie, size_t ie_len); 1178 const u8 *ie, size_t ie_len,
1179 enum ieee80211_band band);
1174void ieee80211_send_probe_req(struct ieee80211_sub_if_data *sdata, u8 *dst, 1180void ieee80211_send_probe_req(struct ieee80211_sub_if_data *sdata, u8 *dst,
1175 const u8 *ssid, size_t ssid_len, 1181 const u8 *ssid, size_t ssid_len,
1176 const u8 *ie, size_t ie_len); 1182 const u8 *ie, size_t ie_len);
@@ -1181,6 +1187,28 @@ void ieee80211_sta_def_wmm_params(struct ieee80211_sub_if_data *sdata,
1181u32 ieee80211_sta_get_rates(struct ieee80211_local *local, 1187u32 ieee80211_sta_get_rates(struct ieee80211_local *local,
1182 struct ieee802_11_elems *elems, 1188 struct ieee802_11_elems *elems,
1183 enum ieee80211_band band); 1189 enum ieee80211_band band);
1190int __ieee80211_request_smps(struct ieee80211_sub_if_data *sdata,
1191 enum ieee80211_smps_mode smps_mode);
1192void ieee80211_recalc_smps(struct ieee80211_local *local,
1193 struct ieee80211_sub_if_data *forsdata);
1194
1195size_t ieee80211_ie_split(const u8 *ies, size_t ielen,
1196 const u8 *ids, int n_ids, size_t offset);
1197size_t ieee80211_ie_split_vendor(const u8 *ies, size_t ielen, size_t offset);
1198
1199/* internal work items */
1200void ieee80211_work_init(struct ieee80211_local *local);
1201void ieee80211_add_work(struct ieee80211_work *wk);
1202void free_work(struct ieee80211_work *wk);
1203void ieee80211_work_purge(struct ieee80211_sub_if_data *sdata);
1204ieee80211_rx_result ieee80211_work_rx_mgmt(struct ieee80211_sub_if_data *sdata,
1205 struct sk_buff *skb);
1206int ieee80211_wk_remain_on_channel(struct ieee80211_sub_if_data *sdata,
1207 struct ieee80211_channel *chan,
1208 enum nl80211_channel_type channel_type,
1209 unsigned int duration, u64 *cookie);
1210int ieee80211_wk_cancel_remain_on_channel(
1211 struct ieee80211_sub_if_data *sdata, u64 cookie);
1184 1212
1185#ifdef CONFIG_MAC80211_NOINLINE 1213#ifdef CONFIG_MAC80211_NOINLINE
1186#define debug_noinline noinline 1214#define debug_noinline noinline
diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
index b8295cbd7e8f..e08fa8eda1b3 100644
--- a/net/mac80211/iface.c
+++ b/net/mac80211/iface.c
@@ -10,17 +10,20 @@
10 * it under the terms of the GNU General Public License version 2 as 10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation. 11 * published by the Free Software Foundation.
12 */ 12 */
13#include <linux/slab.h>
13#include <linux/kernel.h> 14#include <linux/kernel.h>
14#include <linux/if_arp.h> 15#include <linux/if_arp.h>
15#include <linux/netdevice.h> 16#include <linux/netdevice.h>
16#include <linux/rtnetlink.h> 17#include <linux/rtnetlink.h>
17#include <net/mac80211.h> 18#include <net/mac80211.h>
19#include <net/ieee80211_radiotap.h>
18#include "ieee80211_i.h" 20#include "ieee80211_i.h"
19#include "sta_info.h" 21#include "sta_info.h"
20#include "debugfs_netdev.h" 22#include "debugfs_netdev.h"
21#include "mesh.h" 23#include "mesh.h"
22#include "led.h" 24#include "led.h"
23#include "driver-ops.h" 25#include "driver-ops.h"
26#include "wme.h"
24 27
25/** 28/**
26 * DOC: Interface list locking 29 * DOC: Interface list locking
@@ -60,6 +63,23 @@ static int ieee80211_change_mtu(struct net_device *dev, int new_mtu)
60 return 0; 63 return 0;
61} 64}
62 65
66static int ieee80211_change_mac(struct net_device *dev, void *addr)
67{
68 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
69 struct sockaddr *sa = addr;
70 int ret;
71
72 if (ieee80211_sdata_running(sdata))
73 return -EBUSY;
74
75 ret = eth_mac_addr(dev, sa);
76
77 if (ret == 0)
78 memcpy(sdata->vif.addr, sa->sa_data, ETH_ALEN);
79
80 return ret;
81}
82
63static inline int identical_mac_addr_allowed(int type1, int type2) 83static inline int identical_mac_addr_allowed(int type1, int type2)
64{ 84{
65 return type1 == NL80211_IFTYPE_MONITOR || 85 return type1 == NL80211_IFTYPE_MONITOR ||
@@ -80,7 +100,6 @@ static int ieee80211_open(struct net_device *dev)
80 struct ieee80211_sub_if_data *nsdata; 100 struct ieee80211_sub_if_data *nsdata;
81 struct ieee80211_local *local = sdata->local; 101 struct ieee80211_local *local = sdata->local;
82 struct sta_info *sta; 102 struct sta_info *sta;
83 struct ieee80211_if_init_conf conf;
84 u32 changed = 0; 103 u32 changed = 0;
85 int res; 104 int res;
86 u32 hw_reconf_flags = 0; 105 u32 hw_reconf_flags = 0;
@@ -95,7 +114,7 @@ static int ieee80211_open(struct net_device *dev)
95 list_for_each_entry(nsdata, &local->interfaces, list) { 114 list_for_each_entry(nsdata, &local->interfaces, list) {
96 struct net_device *ndev = nsdata->dev; 115 struct net_device *ndev = nsdata->dev;
97 116
98 if (ndev != dev && netif_running(ndev)) { 117 if (ndev != dev && ieee80211_sdata_running(nsdata)) {
99 /* 118 /*
100 * Allow only a single IBSS interface to be up at any 119 * Allow only a single IBSS interface to be up at any
101 * time. This is restricted because beacon distribution 120 * time. This is restricted because beacon distribution
@@ -181,13 +200,15 @@ static int ieee80211_open(struct net_device *dev)
181 struct net_device *ndev = nsdata->dev; 200 struct net_device *ndev = nsdata->dev;
182 201
183 /* 202 /*
184 * No need to check netif_running since we do not allow 203 * No need to check running since we do not allow
185 * it to start up with this invalid address. 204 * it to start up with this invalid address.
186 */ 205 */
187 if (compare_ether_addr(null_addr, ndev->dev_addr) == 0) 206 if (compare_ether_addr(null_addr, ndev->dev_addr) == 0) {
188 memcpy(ndev->dev_addr, 207 memcpy(ndev->dev_addr,
189 local->hw.wiphy->perm_addr, 208 local->hw.wiphy->perm_addr,
190 ETH_ALEN); 209 ETH_ALEN);
210 memcpy(ndev->perm_addr, ndev->dev_addr, ETH_ALEN);
211 }
191 } 212 }
192 213
193 /* 214 /*
@@ -212,8 +233,8 @@ static int ieee80211_open(struct net_device *dev)
212 /* must be before the call to ieee80211_configure_filter */ 233 /* must be before the call to ieee80211_configure_filter */
213 local->monitors++; 234 local->monitors++;
214 if (local->monitors == 1) { 235 if (local->monitors == 1) {
215 local->hw.conf.flags |= IEEE80211_CONF_RADIOTAP; 236 local->hw.conf.flags |= IEEE80211_CONF_MONITOR;
216 hw_reconf_flags |= IEEE80211_CONF_CHANGE_RADIOTAP; 237 hw_reconf_flags |= IEEE80211_CONF_CHANGE_MONITOR;
217 } 238 }
218 239
219 if (sdata->u.mntr_flags & MONITOR_FLAG_FCSFAIL) 240 if (sdata->u.mntr_flags & MONITOR_FLAG_FCSFAIL)
@@ -230,10 +251,7 @@ static int ieee80211_open(struct net_device *dev)
230 ieee80211_configure_filter(local); 251 ieee80211_configure_filter(local);
231 break; 252 break;
232 default: 253 default:
233 conf.vif = &sdata->vif; 254 res = drv_add_interface(local, &sdata->vif);
234 conf.type = sdata->vif.type;
235 conf.mac_addr = dev->dev_addr;
236 res = drv_add_interface(local, &conf);
237 if (res) 255 if (res)
238 goto err_stop; 256 goto err_stop;
239 257
@@ -316,7 +334,7 @@ static int ieee80211_open(struct net_device *dev)
316 334
317 return 0; 335 return 0;
318 err_del_interface: 336 err_del_interface:
319 drv_remove_interface(local, &conf); 337 drv_remove_interface(local, &sdata->vif);
320 err_stop: 338 err_stop:
321 if (!local->open_count) 339 if (!local->open_count)
322 drv_stop(local); 340 drv_stop(local);
@@ -331,7 +349,6 @@ static int ieee80211_stop(struct net_device *dev)
331{ 349{
332 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 350 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
333 struct ieee80211_local *local = sdata->local; 351 struct ieee80211_local *local = sdata->local;
334 struct ieee80211_if_init_conf conf;
335 struct sta_info *sta; 352 struct sta_info *sta;
336 unsigned long flags; 353 unsigned long flags;
337 struct sk_buff *skb, *tmp; 354 struct sk_buff *skb, *tmp;
@@ -344,6 +361,11 @@ static int ieee80211_stop(struct net_device *dev)
344 netif_tx_stop_all_queues(dev); 361 netif_tx_stop_all_queues(dev);
345 362
346 /* 363 /*
364 * Purge work for this interface.
365 */
366 ieee80211_work_purge(sdata);
367
368 /*
347 * Now delete all active aggregation sessions. 369 * Now delete all active aggregation sessions.
348 */ 370 */
349 rcu_read_lock(); 371 rcu_read_lock();
@@ -433,8 +455,8 @@ static int ieee80211_stop(struct net_device *dev)
433 455
434 local->monitors--; 456 local->monitors--;
435 if (local->monitors == 0) { 457 if (local->monitors == 0) {
436 local->hw.conf.flags &= ~IEEE80211_CONF_RADIOTAP; 458 local->hw.conf.flags &= ~IEEE80211_CONF_MONITOR;
437 hw_reconf_flags |= IEEE80211_CONF_CHANGE_RADIOTAP; 459 hw_reconf_flags |= IEEE80211_CONF_CHANGE_MONITOR;
438 } 460 }
439 461
440 if (sdata->u.mntr_flags & MONITOR_FLAG_FCSFAIL) 462 if (sdata->u.mntr_flags & MONITOR_FLAG_FCSFAIL)
@@ -510,12 +532,9 @@ static int ieee80211_stop(struct net_device *dev)
510 BSS_CHANGED_BEACON_ENABLED); 532 BSS_CHANGED_BEACON_ENABLED);
511 } 533 }
512 534
513 conf.vif = &sdata->vif;
514 conf.type = sdata->vif.type;
515 conf.mac_addr = dev->dev_addr;
516 /* disable all keys for as long as this netdev is down */ 535 /* disable all keys for as long as this netdev is down */
517 ieee80211_disable_keys(sdata); 536 ieee80211_disable_keys(sdata);
518 drv_remove_interface(local, &conf); 537 drv_remove_interface(local, &sdata->vif);
519 } 538 }
520 539
521 sdata->bss = NULL; 540 sdata->bss = NULL;
@@ -642,6 +661,12 @@ static void ieee80211_teardown_sdata(struct net_device *dev)
642 WARN_ON(flushed); 661 WARN_ON(flushed);
643} 662}
644 663
664static u16 ieee80211_netdev_select_queue(struct net_device *dev,
665 struct sk_buff *skb)
666{
667 return ieee80211_select_queue(IEEE80211_DEV_TO_SUB_IF(dev), skb);
668}
669
645static const struct net_device_ops ieee80211_dataif_ops = { 670static const struct net_device_ops ieee80211_dataif_ops = {
646 .ndo_open = ieee80211_open, 671 .ndo_open = ieee80211_open,
647 .ndo_stop = ieee80211_stop, 672 .ndo_stop = ieee80211_stop,
@@ -649,9 +674,43 @@ static const struct net_device_ops ieee80211_dataif_ops = {
649 .ndo_start_xmit = ieee80211_subif_start_xmit, 674 .ndo_start_xmit = ieee80211_subif_start_xmit,
650 .ndo_set_multicast_list = ieee80211_set_multicast_list, 675 .ndo_set_multicast_list = ieee80211_set_multicast_list,
651 .ndo_change_mtu = ieee80211_change_mtu, 676 .ndo_change_mtu = ieee80211_change_mtu,
652 .ndo_set_mac_address = eth_mac_addr, 677 .ndo_set_mac_address = ieee80211_change_mac,
678 .ndo_select_queue = ieee80211_netdev_select_queue,
653}; 679};
654 680
681static u16 ieee80211_monitor_select_queue(struct net_device *dev,
682 struct sk_buff *skb)
683{
684 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
685 struct ieee80211_local *local = sdata->local;
686 struct ieee80211_hdr *hdr;
687 struct ieee80211_radiotap_header *rtap = (void *)skb->data;
688 u8 *p;
689
690 if (local->hw.queues < 4)
691 return 0;
692
693 if (skb->len < 4 ||
694 skb->len < le16_to_cpu(rtap->it_len) + 2 /* frame control */)
695 return 0; /* doesn't matter, frame will be dropped */
696
697 hdr = (void *)((u8 *)skb->data + le16_to_cpu(rtap->it_len));
698
699 if (!ieee80211_is_data(hdr->frame_control)) {
700 skb->priority = 7;
701 return ieee802_1d_to_ac[skb->priority];
702 }
703 if (!ieee80211_is_data_qos(hdr->frame_control)) {
704 skb->priority = 0;
705 return ieee802_1d_to_ac[skb->priority];
706 }
707
708 p = ieee80211_get_qos_ctl(hdr);
709 skb->priority = *p & IEEE80211_QOS_CTL_TAG1D_MASK;
710
711 return ieee80211_downgrade_queue(local, skb);
712}
713
655static const struct net_device_ops ieee80211_monitorif_ops = { 714static const struct net_device_ops ieee80211_monitorif_ops = {
656 .ndo_open = ieee80211_open, 715 .ndo_open = ieee80211_open,
657 .ndo_stop = ieee80211_stop, 716 .ndo_stop = ieee80211_stop,
@@ -660,6 +719,7 @@ static const struct net_device_ops ieee80211_monitorif_ops = {
660 .ndo_set_multicast_list = ieee80211_set_multicast_list, 719 .ndo_set_multicast_list = ieee80211_set_multicast_list,
661 .ndo_change_mtu = ieee80211_change_mtu, 720 .ndo_change_mtu = ieee80211_change_mtu,
662 .ndo_set_mac_address = eth_mac_addr, 721 .ndo_set_mac_address = eth_mac_addr,
722 .ndo_select_queue = ieee80211_monitor_select_queue,
663}; 723};
664 724
665static void ieee80211_if_setup(struct net_device *dev) 725static void ieee80211_if_setup(struct net_device *dev)
@@ -738,7 +798,7 @@ int ieee80211_if_change_type(struct ieee80211_sub_if_data *sdata,
738 * and goes into the requested mode. 798 * and goes into the requested mode.
739 */ 799 */
740 800
741 if (netif_running(sdata->dev)) 801 if (ieee80211_sdata_running(sdata))
742 return -EBUSY; 802 return -EBUSY;
743 803
744 /* Purge and reset type-dependent state. */ 804 /* Purge and reset type-dependent state. */
@@ -750,14 +810,12 @@ int ieee80211_if_change_type(struct ieee80211_sub_if_data *sdata,
750 ieee80211_mandatory_rates(sdata->local, 810 ieee80211_mandatory_rates(sdata->local,
751 sdata->local->hw.conf.channel->band); 811 sdata->local->hw.conf.channel->band);
752 sdata->drop_unencrypted = 0; 812 sdata->drop_unencrypted = 0;
813 if (type == NL80211_IFTYPE_STATION)
814 sdata->u.mgd.use_4addr = false;
753 815
754 return 0; 816 return 0;
755} 817}
756 818
757static struct device_type wiphy_type = {
758 .name = "wlan",
759};
760
761int ieee80211_if_add(struct ieee80211_local *local, const char *name, 819int ieee80211_if_add(struct ieee80211_local *local, const char *name,
762 struct net_device **new_dev, enum nl80211_iftype type, 820 struct net_device **new_dev, enum nl80211_iftype type,
763 struct vif_params *params) 821 struct vif_params *params)
@@ -768,8 +826,8 @@ int ieee80211_if_add(struct ieee80211_local *local, const char *name,
768 826
769 ASSERT_RTNL(); 827 ASSERT_RTNL();
770 828
771 ndev = alloc_netdev(sizeof(*sdata) + local->hw.vif_data_size, 829 ndev = alloc_netdev_mq(sizeof(*sdata) + local->hw.vif_data_size,
772 name, ieee80211_if_setup); 830 name, ieee80211_if_setup, local->hw.queues);
773 if (!ndev) 831 if (!ndev)
774 return -ENOMEM; 832 return -ENOMEM;
775 dev_net_set(ndev, wiphy_net(local->hw.wiphy)); 833 dev_net_set(ndev, wiphy_net(local->hw.wiphy));
@@ -788,12 +846,14 @@ int ieee80211_if_add(struct ieee80211_local *local, const char *name,
788 goto fail; 846 goto fail;
789 847
790 memcpy(ndev->dev_addr, local->hw.wiphy->perm_addr, ETH_ALEN); 848 memcpy(ndev->dev_addr, local->hw.wiphy->perm_addr, ETH_ALEN);
849 memcpy(ndev->perm_addr, ndev->dev_addr, ETH_ALEN);
791 SET_NETDEV_DEV(ndev, wiphy_dev(local->hw.wiphy)); 850 SET_NETDEV_DEV(ndev, wiphy_dev(local->hw.wiphy));
792 SET_NETDEV_DEVTYPE(ndev, &wiphy_type);
793 851
794 /* don't use IEEE80211_DEV_TO_SUB_IF because it checks too much */ 852 /* don't use IEEE80211_DEV_TO_SUB_IF because it checks too much */
795 sdata = netdev_priv(ndev); 853 sdata = netdev_priv(ndev);
796 ndev->ieee80211_ptr = &sdata->wdev; 854 ndev->ieee80211_ptr = &sdata->wdev;
855 memcpy(sdata->vif.addr, ndev->dev_addr, ETH_ALEN);
856 memcpy(sdata->name, ndev->name, IFNAMSIZ);
797 857
798 /* initialise type-independent data */ 858 /* initialise type-independent data */
799 sdata->wdev.wiphy = local->hw.wiphy; 859 sdata->wdev.wiphy = local->hw.wiphy;
@@ -805,12 +865,22 @@ int ieee80211_if_add(struct ieee80211_local *local, const char *name,
805 865
806 INIT_LIST_HEAD(&sdata->key_list); 866 INIT_LIST_HEAD(&sdata->key_list);
807 867
808 sdata->force_unicast_rateidx = -1; 868 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
809 sdata->max_ratectrl_rateidx = -1; 869 struct ieee80211_supported_band *sband;
870 sband = local->hw.wiphy->bands[i];
871 sdata->rc_rateidx_mask[i] =
872 sband ? (1 << sband->n_bitrates) - 1 : 0;
873 }
810 874
811 /* setup type-dependent data */ 875 /* setup type-dependent data */
812 ieee80211_setup_sdata(sdata, type); 876 ieee80211_setup_sdata(sdata, type);
813 877
878 if (params) {
879 ndev->ieee80211_ptr->use_4addr = params->use_4addr;
880 if (type == NL80211_IFTYPE_STATION)
881 sdata->u.mgd.use_4addr = params->use_4addr;
882 }
883
814 ret = register_netdevice(ndev); 884 ret = register_netdevice(ndev);
815 if (ret) 885 if (ret)
816 goto fail; 886 goto fail;
@@ -854,22 +924,18 @@ void ieee80211_if_remove(struct ieee80211_sub_if_data *sdata)
854void ieee80211_remove_interfaces(struct ieee80211_local *local) 924void ieee80211_remove_interfaces(struct ieee80211_local *local)
855{ 925{
856 struct ieee80211_sub_if_data *sdata, *tmp; 926 struct ieee80211_sub_if_data *sdata, *tmp;
927 LIST_HEAD(unreg_list);
857 928
858 ASSERT_RTNL(); 929 ASSERT_RTNL();
859 930
931 mutex_lock(&local->iflist_mtx);
860 list_for_each_entry_safe(sdata, tmp, &local->interfaces, list) { 932 list_for_each_entry_safe(sdata, tmp, &local->interfaces, list) {
861 /*
862 * we cannot hold the iflist_mtx across unregister_netdevice,
863 * but we only need to hold it for list modifications to lock
864 * out readers since we're under the RTNL here as all other
865 * writers.
866 */
867 mutex_lock(&local->iflist_mtx);
868 list_del(&sdata->list); 933 list_del(&sdata->list);
869 mutex_unlock(&local->iflist_mtx);
870 934
871 unregister_netdevice(sdata->dev); 935 unregister_netdevice_queue(sdata->dev, &unreg_list);
872 } 936 }
937 mutex_unlock(&local->iflist_mtx);
938 unregister_netdevice_many(&unreg_list);
873} 939}
874 940
875static u32 ieee80211_idle_off(struct ieee80211_local *local, 941static u32 ieee80211_idle_off(struct ieee80211_local *local,
@@ -897,6 +963,8 @@ static u32 ieee80211_idle_on(struct ieee80211_local *local)
897 wiphy_name(local->hw.wiphy)); 963 wiphy_name(local->hw.wiphy));
898#endif 964#endif
899 965
966 drv_flush(local, false);
967
900 local->hw.conf.flags |= IEEE80211_CONF_IDLE; 968 local->hw.conf.flags |= IEEE80211_CONF_IDLE;
901 return IEEE80211_CONF_CHANGE_IDLE; 969 return IEEE80211_CONF_CHANGE_IDLE;
902} 970}
@@ -906,16 +974,18 @@ u32 __ieee80211_recalc_idle(struct ieee80211_local *local)
906 struct ieee80211_sub_if_data *sdata; 974 struct ieee80211_sub_if_data *sdata;
907 int count = 0; 975 int count = 0;
908 976
977 if (!list_empty(&local->work_list))
978 return ieee80211_idle_off(local, "working");
979
909 if (local->scanning) 980 if (local->scanning)
910 return ieee80211_idle_off(local, "scanning"); 981 return ieee80211_idle_off(local, "scanning");
911 982
912 list_for_each_entry(sdata, &local->interfaces, list) { 983 list_for_each_entry(sdata, &local->interfaces, list) {
913 if (!netif_running(sdata->dev)) 984 if (!ieee80211_sdata_running(sdata))
914 continue; 985 continue;
915 /* do not count disabled managed interfaces */ 986 /* do not count disabled managed interfaces */
916 if (sdata->vif.type == NL80211_IFTYPE_STATION && 987 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
917 !sdata->u.mgd.associated && 988 !sdata->u.mgd.associated)
918 list_empty(&sdata->u.mgd.work_list))
919 continue; 989 continue;
920 /* do not count unused IBSS interfaces */ 990 /* do not count unused IBSS interfaces */
921 if (sdata->vif.type == NL80211_IFTYPE_ADHOC && 991 if (sdata->vif.type == NL80211_IFTYPE_ADHOC &&
@@ -943,3 +1013,41 @@ void ieee80211_recalc_idle(struct ieee80211_local *local)
943 if (chg) 1013 if (chg)
944 ieee80211_hw_config(local, chg); 1014 ieee80211_hw_config(local, chg);
945} 1015}
1016
1017static int netdev_notify(struct notifier_block *nb,
1018 unsigned long state,
1019 void *ndev)
1020{
1021 struct net_device *dev = ndev;
1022 struct ieee80211_sub_if_data *sdata;
1023
1024 if (state != NETDEV_CHANGENAME)
1025 return 0;
1026
1027 if (!dev->ieee80211_ptr || !dev->ieee80211_ptr->wiphy)
1028 return 0;
1029
1030 if (dev->ieee80211_ptr->wiphy->privid != mac80211_wiphy_privid)
1031 return 0;
1032
1033 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1034
1035 memcpy(sdata->name, dev->name, IFNAMSIZ);
1036
1037 ieee80211_debugfs_rename_netdev(sdata);
1038 return 0;
1039}
1040
1041static struct notifier_block mac80211_netdev_notifier = {
1042 .notifier_call = netdev_notify,
1043};
1044
1045int ieee80211_iface_init(void)
1046{
1047 return register_netdevice_notifier(&mac80211_netdev_notifier);
1048}
1049
1050void ieee80211_iface_exit(void)
1051{
1052 unregister_netdevice_notifier(&mac80211_netdev_notifier);
1053}
diff --git a/net/mac80211/key.c b/net/mac80211/key.c
index 659a42d529e3..e8f6e3b252d8 100644
--- a/net/mac80211/key.c
+++ b/net/mac80211/key.c
@@ -14,6 +14,7 @@
14#include <linux/list.h> 14#include <linux/list.h>
15#include <linux/rcupdate.h> 15#include <linux/rcupdate.h>
16#include <linux/rtnetlink.h> 16#include <linux/rtnetlink.h>
17#include <linux/slab.h>
17#include <net/mac80211.h> 18#include <net/mac80211.h>
18#include "ieee80211_i.h" 19#include "ieee80211_i.h"
19#include "driver-ops.h" 20#include "driver-ops.h"
@@ -139,7 +140,7 @@ static void ieee80211_key_enable_hw_accel(struct ieee80211_key *key)
139 struct ieee80211_sub_if_data, 140 struct ieee80211_sub_if_data,
140 u.ap); 141 u.ap);
141 142
142 ret = drv_set_key(key->local, SET_KEY, &sdata->vif, sta, &key->conf); 143 ret = drv_set_key(key->local, SET_KEY, sdata, sta, &key->conf);
143 144
144 if (!ret) { 145 if (!ret) {
145 spin_lock_bh(&todo_lock); 146 spin_lock_bh(&todo_lock);
@@ -181,7 +182,7 @@ static void ieee80211_key_disable_hw_accel(struct ieee80211_key *key)
181 struct ieee80211_sub_if_data, 182 struct ieee80211_sub_if_data,
182 u.ap); 183 u.ap);
183 184
184 ret = drv_set_key(key->local, DISABLE_KEY, &sdata->vif, 185 ret = drv_set_key(key->local, DISABLE_KEY, sdata,
185 sta, &key->conf); 186 sta, &key->conf);
186 187
187 if (ret) 188 if (ret)
@@ -421,7 +422,7 @@ void ieee80211_key_link(struct ieee80211_key *key,
421 */ 422 */
422 423
423 /* same here, the AP could be using QoS */ 424 /* same here, the AP could be using QoS */
424 ap = sta_info_get(key->local, key->sdata->u.mgd.bssid); 425 ap = sta_info_get(key->sdata, key->sdata->u.mgd.bssid);
425 if (ap) { 426 if (ap) {
426 if (test_sta_flags(ap, WLAN_STA_WME)) 427 if (test_sta_flags(ap, WLAN_STA_WME))
427 key->conf.flags |= 428 key->conf.flags |=
@@ -443,7 +444,7 @@ void ieee80211_key_link(struct ieee80211_key *key,
443 add_todo(old_key, KEY_FLAG_TODO_DELETE); 444 add_todo(old_key, KEY_FLAG_TODO_DELETE);
444 445
445 add_todo(key, KEY_FLAG_TODO_ADD_DEBUGFS); 446 add_todo(key, KEY_FLAG_TODO_ADD_DEBUGFS);
446 if (netif_running(sdata->dev)) 447 if (ieee80211_sdata_running(sdata))
447 add_todo(key, KEY_FLAG_TODO_HWACCEL_ADD); 448 add_todo(key, KEY_FLAG_TODO_HWACCEL_ADD);
448 449
449 spin_unlock_irqrestore(&sdata->local->key_lock, flags); 450 spin_unlock_irqrestore(&sdata->local->key_lock, flags);
@@ -509,7 +510,7 @@ void ieee80211_enable_keys(struct ieee80211_sub_if_data *sdata)
509{ 510{
510 ASSERT_RTNL(); 511 ASSERT_RTNL();
511 512
512 if (WARN_ON(!netif_running(sdata->dev))) 513 if (WARN_ON(!ieee80211_sdata_running(sdata)))
513 return; 514 return;
514 515
515 ieee80211_todo_for_each_key(sdata, KEY_FLAG_TODO_HWACCEL_ADD); 516 ieee80211_todo_for_each_key(sdata, KEY_FLAG_TODO_HWACCEL_ADD);
diff --git a/net/mac80211/key.h b/net/mac80211/key.h
index 9572e00f532c..bdc2968c2bbe 100644
--- a/net/mac80211/key.h
+++ b/net/mac80211/key.h
@@ -59,11 +59,17 @@ enum ieee80211_internal_key_flags {
59 KEY_FLAG_TODO_DEFMGMTKEY = BIT(6), 59 KEY_FLAG_TODO_DEFMGMTKEY = BIT(6),
60}; 60};
61 61
62enum ieee80211_internal_tkip_state {
63 TKIP_STATE_NOT_INIT,
64 TKIP_STATE_PHASE1_DONE,
65 TKIP_STATE_PHASE1_HW_UPLOADED,
66};
67
62struct tkip_ctx { 68struct tkip_ctx {
63 u32 iv32; 69 u32 iv32;
64 u16 iv16; 70 u16 iv16;
65 u16 p1k[5]; 71 u16 p1k[5];
66 int initialized; 72 enum ieee80211_internal_tkip_state state;
67}; 73};
68 74
69struct ieee80211_key { 75struct ieee80211_key {
@@ -118,18 +124,6 @@ struct ieee80211_key {
118 struct { 124 struct {
119 struct dentry *stalink; 125 struct dentry *stalink;
120 struct dentry *dir; 126 struct dentry *dir;
121 struct dentry *keylen;
122 struct dentry *flags;
123 struct dentry *keyidx;
124 struct dentry *hw_key_idx;
125 struct dentry *tx_rx_count;
126 struct dentry *algorithm;
127 struct dentry *tx_spec;
128 struct dentry *rx_spec;
129 struct dentry *replays;
130 struct dentry *icverrors;
131 struct dentry *key;
132 struct dentry *ifindex;
133 int cnt; 127 int cnt;
134 } debugfs; 128 } debugfs;
135#endif 129#endif
diff --git a/net/mac80211/led.c b/net/mac80211/led.c
index 162a643f16b6..063aad944246 100644
--- a/net/mac80211/led.c
+++ b/net/mac80211/led.c
@@ -8,6 +8,7 @@
8 8
9/* just for IFNAMSIZ */ 9/* just for IFNAMSIZ */
10#include <linux/if.h> 10#include <linux/if.h>
11#include <linux/slab.h>
11#include "led.h" 12#include "led.h"
12 13
13void ieee80211_led_rx(struct ieee80211_local *local) 14void ieee80211_led_rx(struct ieee80211_local *local)
diff --git a/net/mac80211/main.c b/net/mac80211/main.c
index 797f53942e5f..b887e484ae04 100644
--- a/net/mac80211/main.c
+++ b/net/mac80211/main.c
@@ -9,7 +9,6 @@
9 */ 9 */
10 10
11#include <net/mac80211.h> 11#include <net/mac80211.h>
12#include <net/ieee80211_radiotap.h>
13#include <linux/module.h> 12#include <linux/module.h>
14#include <linux/init.h> 13#include <linux/init.h>
15#include <linux/netdevice.h> 14#include <linux/netdevice.h>
@@ -18,7 +17,6 @@
18#include <linux/skbuff.h> 17#include <linux/skbuff.h>
19#include <linux/etherdevice.h> 18#include <linux/etherdevice.h>
20#include <linux/if_arp.h> 19#include <linux/if_arp.h>
21#include <linux/wireless.h>
22#include <linux/rtnetlink.h> 20#include <linux/rtnetlink.h>
23#include <linux/bitmap.h> 21#include <linux/bitmap.h>
24#include <linux/pm_qos_params.h> 22#include <linux/pm_qos_params.h>
@@ -30,25 +28,15 @@
30#include "rate.h" 28#include "rate.h"
31#include "mesh.h" 29#include "mesh.h"
32#include "wep.h" 30#include "wep.h"
33#include "wme.h"
34#include "aes_ccm.h"
35#include "led.h" 31#include "led.h"
36#include "cfg.h" 32#include "cfg.h"
37#include "debugfs.h" 33#include "debugfs.h"
38#include "debugfs_netdev.h"
39 34
40/*
41 * For seeing transmitted packets on monitor interfaces
42 * we have a radiotap header too.
43 */
44struct ieee80211_tx_status_rtap_hdr {
45 struct ieee80211_radiotap_header hdr;
46 u8 rate;
47 u8 padding_for_rate;
48 __le16 tx_flags;
49 u8 data_retries;
50} __attribute__ ((packed));
51 35
36bool ieee80211_disable_40mhz_24ghz;
37module_param(ieee80211_disable_40mhz_24ghz, bool, 0644);
38MODULE_PARM_DESC(ieee80211_disable_40mhz_24ghz,
39 "Disable 40MHz support in the 2.4GHz band");
52 40
53void ieee80211_configure_filter(struct ieee80211_local *local) 41void ieee80211_configure_filter(struct ieee80211_local *local)
54{ 42{
@@ -118,6 +106,9 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
118 if (scan_chan) { 106 if (scan_chan) {
119 chan = scan_chan; 107 chan = scan_chan;
120 channel_type = NL80211_CHAN_NO_HT; 108 channel_type = NL80211_CHAN_NO_HT;
109 } else if (local->tmp_channel) {
110 chan = scan_chan = local->tmp_channel;
111 channel_type = local->tmp_channel_type;
121 } else { 112 } else {
122 chan = local->oper_channel; 113 chan = local->oper_channel;
123 channel_type = local->oper_channel_type; 114 channel_type = local->oper_channel_type;
@@ -130,6 +121,18 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
130 changed |= IEEE80211_CONF_CHANGE_CHANNEL; 121 changed |= IEEE80211_CONF_CHANGE_CHANNEL;
131 } 122 }
132 123
124 if (!conf_is_ht(&local->hw.conf)) {
125 /*
126 * mac80211.h documents that this is only valid
127 * when the channel is set to an HT type, and
128 * that otherwise STATIC is used.
129 */
130 local->hw.conf.smps_mode = IEEE80211_SMPS_STATIC;
131 } else if (local->hw.conf.smps_mode != local->smps_mode) {
132 local->hw.conf.smps_mode = local->smps_mode;
133 changed |= IEEE80211_CONF_CHANGE_SMPS;
134 }
135
133 if (scan_chan) 136 if (scan_chan)
134 power = chan->max_power; 137 power = chan->max_power;
135 else 138 else
@@ -189,7 +192,7 @@ void ieee80211_bss_info_change_notify(struct ieee80211_sub_if_data *sdata,
189 } else if (sdata->vif.type == NL80211_IFTYPE_ADHOC) 192 } else if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
190 sdata->vif.bss_conf.bssid = sdata->u.ibss.bssid; 193 sdata->vif.bss_conf.bssid = sdata->u.ibss.bssid;
191 else if (sdata->vif.type == NL80211_IFTYPE_AP) 194 else if (sdata->vif.type == NL80211_IFTYPE_AP)
192 sdata->vif.bss_conf.bssid = sdata->dev->dev_addr; 195 sdata->vif.bss_conf.bssid = sdata->vif.addr;
193 else if (ieee80211_vif_is_mesh(&sdata->vif)) { 196 else if (ieee80211_vif_is_mesh(&sdata->vif)) {
194 sdata->vif.bss_conf.bssid = zero; 197 sdata->vif.bss_conf.bssid = zero;
195 } else { 198 } else {
@@ -211,7 +214,7 @@ void ieee80211_bss_info_change_notify(struct ieee80211_sub_if_data *sdata,
211 } 214 }
212 215
213 if (changed & BSS_CHANGED_BEACON_ENABLED) { 216 if (changed & BSS_CHANGED_BEACON_ENABLED) {
214 if (local->quiescing || !netif_running(sdata->dev) || 217 if (local->quiescing || !ieee80211_sdata_running(sdata) ||
215 test_bit(SCAN_SW_SCANNING, &local->scanning)) { 218 test_bit(SCAN_SW_SCANNING, &local->scanning)) {
216 sdata->vif.bss_conf.enable_beacon = false; 219 sdata->vif.bss_conf.enable_beacon = false;
217 } else { 220 } else {
@@ -222,11 +225,11 @@ void ieee80211_bss_info_change_notify(struct ieee80211_sub_if_data *sdata,
222 switch (sdata->vif.type) { 225 switch (sdata->vif.type) {
223 case NL80211_IFTYPE_AP: 226 case NL80211_IFTYPE_AP:
224 sdata->vif.bss_conf.enable_beacon = 227 sdata->vif.bss_conf.enable_beacon =
225 !!rcu_dereference(sdata->u.ap.beacon); 228 !!sdata->u.ap.beacon;
226 break; 229 break;
227 case NL80211_IFTYPE_ADHOC: 230 case NL80211_IFTYPE_ADHOC:
228 sdata->vif.bss_conf.enable_beacon = 231 sdata->vif.bss_conf.enable_beacon =
229 !!rcu_dereference(sdata->u.ibss.presp); 232 !!sdata->u.ibss.presp;
230 break; 233 break;
231 case NL80211_IFTYPE_MESH_POINT: 234 case NL80211_IFTYPE_MESH_POINT:
232 sdata->vif.bss_conf.enable_beacon = true; 235 sdata->vif.bss_conf.enable_beacon = true;
@@ -239,8 +242,7 @@ void ieee80211_bss_info_change_notify(struct ieee80211_sub_if_data *sdata,
239 } 242 }
240 } 243 }
241 244
242 drv_bss_info_changed(local, &sdata->vif, 245 drv_bss_info_changed(local, sdata, &sdata->vif.bss_conf, changed);
243 &sdata->vif.bss_conf, changed);
244} 246}
245 247
246u32 ieee80211_reset_erp_info(struct ieee80211_sub_if_data *sdata) 248u32 ieee80211_reset_erp_info(struct ieee80211_sub_if_data *sdata)
@@ -253,28 +255,6 @@ u32 ieee80211_reset_erp_info(struct ieee80211_sub_if_data *sdata)
253 BSS_CHANGED_ERP_SLOT; 255 BSS_CHANGED_ERP_SLOT;
254} 256}
255 257
256void ieee80211_tx_status_irqsafe(struct ieee80211_hw *hw,
257 struct sk_buff *skb)
258{
259 struct ieee80211_local *local = hw_to_local(hw);
260 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
261 int tmp;
262
263 skb->pkt_type = IEEE80211_TX_STATUS_MSG;
264 skb_queue_tail(info->flags & IEEE80211_TX_CTL_REQ_TX_STATUS ?
265 &local->skb_queue : &local->skb_queue_unreliable, skb);
266 tmp = skb_queue_len(&local->skb_queue) +
267 skb_queue_len(&local->skb_queue_unreliable);
268 while (tmp > IEEE80211_IRQSAFE_QUEUE_LIMIT &&
269 (skb = skb_dequeue(&local->skb_queue_unreliable))) {
270 dev_kfree_skb_irq(skb);
271 tmp--;
272 I802_DEBUG_INC(local->tx_status_drop);
273 }
274 tasklet_schedule(&local->tasklet);
275}
276EXPORT_SYMBOL(ieee80211_tx_status_irqsafe);
277
278static void ieee80211_tasklet_handler(unsigned long data) 258static void ieee80211_tasklet_handler(unsigned long data)
279{ 259{
280 struct ieee80211_local *local = (struct ieee80211_local *) data; 260 struct ieee80211_local *local = (struct ieee80211_local *) data;
@@ -296,14 +276,14 @@ static void ieee80211_tasklet_handler(unsigned long data)
296 break; 276 break;
297 case IEEE80211_DELBA_MSG: 277 case IEEE80211_DELBA_MSG:
298 ra_tid = (struct ieee80211_ra_tid *) &skb->cb; 278 ra_tid = (struct ieee80211_ra_tid *) &skb->cb;
299 ieee80211_stop_tx_ba_cb(local_to_hw(local), 279 ieee80211_stop_tx_ba_cb(ra_tid->vif, ra_tid->ra,
300 ra_tid->ra, ra_tid->tid); 280 ra_tid->tid);
301 dev_kfree_skb(skb); 281 dev_kfree_skb(skb);
302 break; 282 break;
303 case IEEE80211_ADDBA_MSG: 283 case IEEE80211_ADDBA_MSG:
304 ra_tid = (struct ieee80211_ra_tid *) &skb->cb; 284 ra_tid = (struct ieee80211_ra_tid *) &skb->cb;
305 ieee80211_start_tx_ba_cb(local_to_hw(local), 285 ieee80211_start_tx_ba_cb(ra_tid->vif, ra_tid->ra,
306 ra_tid->ra, ra_tid->tid); 286 ra_tid->tid);
307 dev_kfree_skb(skb); 287 dev_kfree_skb(skb);
308 break ; 288 break ;
309 default: 289 default:
@@ -315,299 +295,6 @@ static void ieee80211_tasklet_handler(unsigned long data)
315 } 295 }
316} 296}
317 297
318static void ieee80211_handle_filtered_frame(struct ieee80211_local *local,
319 struct sta_info *sta,
320 struct sk_buff *skb)
321{
322 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
323
324 /*
325 * XXX: This is temporary!
326 *
327 * The problem here is that when we get here, the driver will
328 * quite likely have pretty much overwritten info->control by
329 * using info->driver_data or info->rate_driver_data. Thus,
330 * when passing out the frame to the driver again, we would be
331 * passing completely bogus data since the driver would then
332 * expect a properly filled info->control. In mac80211 itself
333 * the same problem occurs, since we need info->control.vif
334 * internally.
335 *
336 * To fix this, we should send the frame through TX processing
337 * again. However, it's not that simple, since the frame will
338 * have been software-encrypted (if applicable) already, and
339 * encrypting it again doesn't do much good. So to properly do
340 * that, we not only have to skip the actual 'raw' encryption
341 * (key selection etc. still has to be done!) but also the
342 * sequence number assignment since that impacts the crypto
343 * encapsulation, of course.
344 *
345 * Hence, for now, fix the bug by just dropping the frame.
346 */
347 goto drop;
348
349 sta->tx_filtered_count++;
350
351 /*
352 * Clear the TX filter mask for this STA when sending the next
353 * packet. If the STA went to power save mode, this will happen
354 * when it wakes up for the next time.
355 */
356 set_sta_flags(sta, WLAN_STA_CLEAR_PS_FILT);
357
358 /*
359 * This code races in the following way:
360 *
361 * (1) STA sends frame indicating it will go to sleep and does so
362 * (2) hardware/firmware adds STA to filter list, passes frame up
363 * (3) hardware/firmware processes TX fifo and suppresses a frame
364 * (4) we get TX status before having processed the frame and
365 * knowing that the STA has gone to sleep.
366 *
367 * This is actually quite unlikely even when both those events are
368 * processed from interrupts coming in quickly after one another or
369 * even at the same time because we queue both TX status events and
370 * RX frames to be processed by a tasklet and process them in the
371 * same order that they were received or TX status last. Hence, there
372 * is no race as long as the frame RX is processed before the next TX
373 * status, which drivers can ensure, see below.
374 *
375 * Note that this can only happen if the hardware or firmware can
376 * actually add STAs to the filter list, if this is done by the
377 * driver in response to set_tim() (which will only reduce the race
378 * this whole filtering tries to solve, not completely solve it)
379 * this situation cannot happen.
380 *
381 * To completely solve this race drivers need to make sure that they
382 * (a) don't mix the irq-safe/not irq-safe TX status/RX processing
383 * functions and
384 * (b) always process RX events before TX status events if ordering
385 * can be unknown, for example with different interrupt status
386 * bits.
387 */
388 if (test_sta_flags(sta, WLAN_STA_PS) &&
389 skb_queue_len(&sta->tx_filtered) < STA_MAX_TX_BUFFER) {
390 skb_queue_tail(&sta->tx_filtered, skb);
391 return;
392 }
393
394 if (!test_sta_flags(sta, WLAN_STA_PS) &&
395 !(info->flags & IEEE80211_TX_INTFL_RETRIED)) {
396 /* Software retry the packet once */
397 info->flags |= IEEE80211_TX_INTFL_RETRIED;
398 ieee80211_add_pending_skb(local, skb);
399 return;
400 }
401
402 drop:
403#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
404 if (net_ratelimit())
405 printk(KERN_DEBUG "%s: dropped TX filtered frame, "
406 "queue_len=%d PS=%d @%lu\n",
407 wiphy_name(local->hw.wiphy),
408 skb_queue_len(&sta->tx_filtered),
409 !!test_sta_flags(sta, WLAN_STA_PS), jiffies);
410#endif
411 dev_kfree_skb(skb);
412}
413
414void ieee80211_tx_status(struct ieee80211_hw *hw, struct sk_buff *skb)
415{
416 struct sk_buff *skb2;
417 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
418 struct ieee80211_local *local = hw_to_local(hw);
419 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
420 u16 frag, type;
421 __le16 fc;
422 struct ieee80211_supported_band *sband;
423 struct ieee80211_tx_status_rtap_hdr *rthdr;
424 struct ieee80211_sub_if_data *sdata;
425 struct net_device *prev_dev = NULL;
426 struct sta_info *sta;
427 int retry_count = -1, i;
428
429 for (i = 0; i < IEEE80211_TX_MAX_RATES; i++) {
430 /* the HW cannot have attempted that rate */
431 if (i >= hw->max_rates) {
432 info->status.rates[i].idx = -1;
433 info->status.rates[i].count = 0;
434 }
435
436 retry_count += info->status.rates[i].count;
437 }
438 if (retry_count < 0)
439 retry_count = 0;
440
441 rcu_read_lock();
442
443 sband = local->hw.wiphy->bands[info->band];
444
445 sta = sta_info_get(local, hdr->addr1);
446
447 if (sta) {
448 if (!(info->flags & IEEE80211_TX_STAT_ACK) &&
449 test_sta_flags(sta, WLAN_STA_PS)) {
450 /*
451 * The STA is in power save mode, so assume
452 * that this TX packet failed because of that.
453 */
454 ieee80211_handle_filtered_frame(local, sta, skb);
455 rcu_read_unlock();
456 return;
457 }
458
459 fc = hdr->frame_control;
460
461 if ((info->flags & IEEE80211_TX_STAT_AMPDU_NO_BACK) &&
462 (ieee80211_is_data_qos(fc))) {
463 u16 tid, ssn;
464 u8 *qc;
465
466 qc = ieee80211_get_qos_ctl(hdr);
467 tid = qc[0] & 0xf;
468 ssn = ((le16_to_cpu(hdr->seq_ctrl) + 0x10)
469 & IEEE80211_SCTL_SEQ);
470 ieee80211_send_bar(sta->sdata, hdr->addr1,
471 tid, ssn);
472 }
473
474 if (info->flags & IEEE80211_TX_STAT_TX_FILTERED) {
475 ieee80211_handle_filtered_frame(local, sta, skb);
476 rcu_read_unlock();
477 return;
478 } else {
479 if (!(info->flags & IEEE80211_TX_STAT_ACK))
480 sta->tx_retry_failed++;
481 sta->tx_retry_count += retry_count;
482 }
483
484 rate_control_tx_status(local, sband, sta, skb);
485 if (ieee80211_vif_is_mesh(&sta->sdata->vif))
486 ieee80211s_update_metric(local, sta, skb);
487 }
488
489 rcu_read_unlock();
490
491 ieee80211_led_tx(local, 0);
492
493 /* SNMP counters
494 * Fragments are passed to low-level drivers as separate skbs, so these
495 * are actually fragments, not frames. Update frame counters only for
496 * the first fragment of the frame. */
497
498 frag = le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_FRAG;
499 type = le16_to_cpu(hdr->frame_control) & IEEE80211_FCTL_FTYPE;
500
501 if (info->flags & IEEE80211_TX_STAT_ACK) {
502 if (frag == 0) {
503 local->dot11TransmittedFrameCount++;
504 if (is_multicast_ether_addr(hdr->addr1))
505 local->dot11MulticastTransmittedFrameCount++;
506 if (retry_count > 0)
507 local->dot11RetryCount++;
508 if (retry_count > 1)
509 local->dot11MultipleRetryCount++;
510 }
511
512 /* This counter shall be incremented for an acknowledged MPDU
513 * with an individual address in the address 1 field or an MPDU
514 * with a multicast address in the address 1 field of type Data
515 * or Management. */
516 if (!is_multicast_ether_addr(hdr->addr1) ||
517 type == IEEE80211_FTYPE_DATA ||
518 type == IEEE80211_FTYPE_MGMT)
519 local->dot11TransmittedFragmentCount++;
520 } else {
521 if (frag == 0)
522 local->dot11FailedCount++;
523 }
524
525 /* this was a transmitted frame, but now we want to reuse it */
526 skb_orphan(skb);
527
528 /*
529 * This is a bit racy but we can avoid a lot of work
530 * with this test...
531 */
532 if (!local->monitors && !local->cooked_mntrs) {
533 dev_kfree_skb(skb);
534 return;
535 }
536
537 /* send frame to monitor interfaces now */
538
539 if (skb_headroom(skb) < sizeof(*rthdr)) {
540 printk(KERN_ERR "ieee80211_tx_status: headroom too small\n");
541 dev_kfree_skb(skb);
542 return;
543 }
544
545 rthdr = (struct ieee80211_tx_status_rtap_hdr *)
546 skb_push(skb, sizeof(*rthdr));
547
548 memset(rthdr, 0, sizeof(*rthdr));
549 rthdr->hdr.it_len = cpu_to_le16(sizeof(*rthdr));
550 rthdr->hdr.it_present =
551 cpu_to_le32((1 << IEEE80211_RADIOTAP_TX_FLAGS) |
552 (1 << IEEE80211_RADIOTAP_DATA_RETRIES) |
553 (1 << IEEE80211_RADIOTAP_RATE));
554
555 if (!(info->flags & IEEE80211_TX_STAT_ACK) &&
556 !is_multicast_ether_addr(hdr->addr1))
557 rthdr->tx_flags |= cpu_to_le16(IEEE80211_RADIOTAP_F_TX_FAIL);
558
559 /*
560 * XXX: Once radiotap gets the bitmap reset thing the vendor
561 * extensions proposal contains, we can actually report
562 * the whole set of tries we did.
563 */
564 if ((info->status.rates[0].flags & IEEE80211_TX_RC_USE_RTS_CTS) ||
565 (info->status.rates[0].flags & IEEE80211_TX_RC_USE_CTS_PROTECT))
566 rthdr->tx_flags |= cpu_to_le16(IEEE80211_RADIOTAP_F_TX_CTS);
567 else if (info->status.rates[0].flags & IEEE80211_TX_RC_USE_RTS_CTS)
568 rthdr->tx_flags |= cpu_to_le16(IEEE80211_RADIOTAP_F_TX_RTS);
569 if (info->status.rates[0].idx >= 0 &&
570 !(info->status.rates[0].flags & IEEE80211_TX_RC_MCS))
571 rthdr->rate = sband->bitrates[
572 info->status.rates[0].idx].bitrate / 5;
573
574 /* for now report the total retry_count */
575 rthdr->data_retries = retry_count;
576
577 /* XXX: is this sufficient for BPF? */
578 skb_set_mac_header(skb, 0);
579 skb->ip_summed = CHECKSUM_UNNECESSARY;
580 skb->pkt_type = PACKET_OTHERHOST;
581 skb->protocol = htons(ETH_P_802_2);
582 memset(skb->cb, 0, sizeof(skb->cb));
583
584 rcu_read_lock();
585 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
586 if (sdata->vif.type == NL80211_IFTYPE_MONITOR) {
587 if (!netif_running(sdata->dev))
588 continue;
589
590 if (prev_dev) {
591 skb2 = skb_clone(skb, GFP_ATOMIC);
592 if (skb2) {
593 skb2->dev = prev_dev;
594 netif_rx(skb2);
595 }
596 }
597
598 prev_dev = sdata->dev;
599 }
600 }
601 if (prev_dev) {
602 skb->dev = prev_dev;
603 netif_rx(skb);
604 skb = NULL;
605 }
606 rcu_read_unlock();
607 dev_kfree_skb(skb);
608}
609EXPORT_SYMBOL(ieee80211_tx_status);
610
611static void ieee80211_restart_work(struct work_struct *work) 298static void ieee80211_restart_work(struct work_struct *work)
612{ 299{
613 struct ieee80211_local *local = 300 struct ieee80211_local *local =
@@ -630,6 +317,16 @@ void ieee80211_restart_hw(struct ieee80211_hw *hw)
630} 317}
631EXPORT_SYMBOL(ieee80211_restart_hw); 318EXPORT_SYMBOL(ieee80211_restart_hw);
632 319
320static void ieee80211_recalc_smps_work(struct work_struct *work)
321{
322 struct ieee80211_local *local =
323 container_of(work, struct ieee80211_local, recalc_smps);
324
325 mutex_lock(&local->iflist_mtx);
326 ieee80211_recalc_smps(local, NULL);
327 mutex_unlock(&local->iflist_mtx);
328}
329
633struct ieee80211_hw *ieee80211_alloc_hw(size_t priv_data_len, 330struct ieee80211_hw *ieee80211_alloc_hw(size_t priv_data_len,
634 const struct ieee80211_ops *ops) 331 const struct ieee80211_ops *ops)
635{ 332{
@@ -659,12 +356,12 @@ struct ieee80211_hw *ieee80211_alloc_hw(size_t priv_data_len,
659 if (!wiphy) 356 if (!wiphy)
660 return NULL; 357 return NULL;
661 358
662 wiphy->netnsok = true; 359 wiphy->flags |= WIPHY_FLAG_NETNS_OK |
360 WIPHY_FLAG_4ADDR_AP |
361 WIPHY_FLAG_4ADDR_STATION;
663 wiphy->privid = mac80211_wiphy_privid; 362 wiphy->privid = mac80211_wiphy_privid;
664 363
665 /* Yes, putting cfg80211_bss into ieee80211_bss is a hack */ 364 wiphy->bss_priv_size = sizeof(struct ieee80211_bss);
666 wiphy->bss_priv_size = sizeof(struct ieee80211_bss) -
667 sizeof(struct cfg80211_bss);
668 365
669 local = wiphy_priv(wiphy); 366 local = wiphy_priv(wiphy);
670 367
@@ -687,6 +384,8 @@ struct ieee80211_hw *ieee80211_alloc_hw(size_t priv_data_len,
687 local->hw.conf.long_frame_max_tx_count = wiphy->retry_long; 384 local->hw.conf.long_frame_max_tx_count = wiphy->retry_long;
688 local->hw.conf.short_frame_max_tx_count = wiphy->retry_short; 385 local->hw.conf.short_frame_max_tx_count = wiphy->retry_short;
689 local->user_power_level = -1; 386 local->user_power_level = -1;
387 local->uapsd_queues = IEEE80211_DEFAULT_UAPSD_QUEUES;
388 local->uapsd_max_sp_len = IEEE80211_DEFAULT_MAX_SP_LEN;
690 389
691 INIT_LIST_HEAD(&local->interfaces); 390 INIT_LIST_HEAD(&local->interfaces);
692 mutex_init(&local->iflist_mtx); 391 mutex_init(&local->iflist_mtx);
@@ -698,9 +397,13 @@ struct ieee80211_hw *ieee80211_alloc_hw(size_t priv_data_len,
698 397
699 INIT_DELAYED_WORK(&local->scan_work, ieee80211_scan_work); 398 INIT_DELAYED_WORK(&local->scan_work, ieee80211_scan_work);
700 399
400 ieee80211_work_init(local);
401
701 INIT_WORK(&local->restart_work, ieee80211_restart_work); 402 INIT_WORK(&local->restart_work, ieee80211_restart_work);
702 403
703 INIT_WORK(&local->reconfig_filter, ieee80211_reconfig_filter); 404 INIT_WORK(&local->reconfig_filter, ieee80211_reconfig_filter);
405 INIT_WORK(&local->recalc_smps, ieee80211_recalc_smps_work);
406 local->smps_mode = IEEE80211_SMPS_OFF;
704 407
705 INIT_WORK(&local->dynamic_ps_enable_work, 408 INIT_WORK(&local->dynamic_ps_enable_work,
706 ieee80211_dynamic_ps_enable_work); 409 ieee80211_dynamic_ps_enable_work);
@@ -790,6 +493,10 @@ int ieee80211_register_hw(struct ieee80211_hw *hw)
790 else if (local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC) 493 else if (local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC)
791 local->hw.wiphy->signal_type = CFG80211_SIGNAL_TYPE_UNSPEC; 494 local->hw.wiphy->signal_type = CFG80211_SIGNAL_TYPE_UNSPEC;
792 495
496 WARN((local->hw.flags & IEEE80211_HW_SUPPORTS_UAPSD)
497 && (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK),
498 "U-APSD not supported with HW_PS_NULLFUNC_STACK\n");
499
793 /* 500 /*
794 * Calculate scan IE length -- we need this to alloc 501 * Calculate scan IE length -- we need this to alloc
795 * memory and to subtract from the driver limit. It 502 * memory and to subtract from the driver limit. It
@@ -844,13 +551,19 @@ int ieee80211_register_hw(struct ieee80211_hw *hw)
844 * and we need some headroom for passing the frame to monitor 551 * and we need some headroom for passing the frame to monitor
845 * interfaces, but never both at the same time. 552 * interfaces, but never both at the same time.
846 */ 553 */
554 BUILD_BUG_ON(IEEE80211_TX_STATUS_HEADROOM !=
555 sizeof(struct ieee80211_tx_status_rtap_hdr));
847 local->tx_headroom = max_t(unsigned int , local->hw.extra_tx_headroom, 556 local->tx_headroom = max_t(unsigned int , local->hw.extra_tx_headroom,
848 sizeof(struct ieee80211_tx_status_rtap_hdr)); 557 sizeof(struct ieee80211_tx_status_rtap_hdr));
849 558
850 debugfs_hw_add(local); 559 debugfs_hw_add(local);
851 560
561 /*
562 * if the driver doesn't specify a max listen interval we
563 * use 5 which should be a safe default
564 */
852 if (local->hw.max_listen_interval == 0) 565 if (local->hw.max_listen_interval == 0)
853 local->hw.max_listen_interval = 1; 566 local->hw.max_listen_interval = 5;
854 567
855 local->hw.conf.listen_interval = local->hw.max_listen_interval; 568 local->hw.conf.listen_interval = local->hw.max_listen_interval;
856 569
@@ -901,6 +614,7 @@ int ieee80211_register_hw(struct ieee80211_hw *hw)
901 i++; 614 i++;
902 } 615 }
903 } 616 }
617 local->int_scan_req->n_channels = i;
904 618
905 local->network_latency_notifier.notifier_call = 619 local->network_latency_notifier.notifier_call =
906 ieee80211_max_network_latency; 620 ieee80211_max_network_latency;
@@ -923,7 +637,6 @@ int ieee80211_register_hw(struct ieee80211_hw *hw)
923 fail_wep: 637 fail_wep:
924 sta_info_stop(local); 638 sta_info_stop(local);
925 fail_sta_info: 639 fail_sta_info:
926 debugfs_hw_del(local);
927 destroy_workqueue(local->workqueue); 640 destroy_workqueue(local->workqueue);
928 fail_workqueue: 641 fail_workqueue:
929 wiphy_unregister(local->hw.wiphy); 642 wiphy_unregister(local->hw.wiphy);
@@ -959,10 +672,9 @@ void ieee80211_unregister_hw(struct ieee80211_hw *hw)
959 ieee80211_clear_tx_pending(local); 672 ieee80211_clear_tx_pending(local);
960 sta_info_stop(local); 673 sta_info_stop(local);
961 rate_control_deinitialize(local); 674 rate_control_deinitialize(local);
962 debugfs_hw_del(local);
963 675
964 if (skb_queue_len(&local->skb_queue) 676 if (skb_queue_len(&local->skb_queue) ||
965 || skb_queue_len(&local->skb_queue_unreliable)) 677 skb_queue_len(&local->skb_queue_unreliable))
966 printk(KERN_WARNING "%s: skb_queue not empty\n", 678 printk(KERN_WARNING "%s: skb_queue not empty\n",
967 wiphy_name(local->hw.wiphy)); 679 wiphy_name(local->hw.wiphy));
968 skb_queue_purge(&local->skb_queue); 680 skb_queue_purge(&local->skb_queue);
@@ -1002,11 +714,19 @@ static int __init ieee80211_init(void)
1002 714
1003 ret = rc80211_pid_init(); 715 ret = rc80211_pid_init();
1004 if (ret) 716 if (ret)
1005 return ret; 717 goto err_pid;
1006 718
1007 ieee80211_debugfs_netdev_init(); 719 ret = ieee80211_iface_init();
720 if (ret)
721 goto err_netdev;
1008 722
1009 return 0; 723 return 0;
724 err_netdev:
725 rc80211_pid_exit();
726 err_pid:
727 rc80211_minstrel_exit();
728
729 return ret;
1010} 730}
1011 731
1012static void __exit ieee80211_exit(void) 732static void __exit ieee80211_exit(void)
@@ -1023,7 +743,7 @@ static void __exit ieee80211_exit(void)
1023 if (mesh_allocated) 743 if (mesh_allocated)
1024 ieee80211s_stop(); 744 ieee80211s_stop();
1025 745
1026 ieee80211_debugfs_netdev_exit(); 746 ieee80211_iface_exit();
1027} 747}
1028 748
1029 749
diff --git a/net/mac80211/mesh.c b/net/mac80211/mesh.c
index f7364e56f1ee..859ee5f3d941 100644
--- a/net/mac80211/mesh.c
+++ b/net/mac80211/mesh.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (c) 2008 open80211s Ltd. 2 * Copyright (c) 2008, 2009 open80211s Ltd.
3 * Authors: Luis Carlos Cobo <luisca@cozybit.com> 3 * Authors: Luis Carlos Cobo <luisca@cozybit.com>
4 * Javier Cardona <javier@cozybit.com> 4 * Javier Cardona <javier@cozybit.com>
5 * 5 *
@@ -8,24 +8,21 @@
8 * published by the Free Software Foundation. 8 * published by the Free Software Foundation.
9 */ 9 */
10 10
11#include <linux/slab.h>
11#include <asm/unaligned.h> 12#include <asm/unaligned.h>
12#include "ieee80211_i.h" 13#include "ieee80211_i.h"
13#include "mesh.h" 14#include "mesh.h"
14 15
15#define IEEE80211_MESH_PEER_INACTIVITY_LIMIT (1800 * HZ) 16#define IEEE80211_MESH_PEER_INACTIVITY_LIMIT (1800 * HZ)
16#define IEEE80211_MESH_HOUSEKEEPING_INTERVAL (60 * HZ) 17#define IEEE80211_MESH_HOUSEKEEPING_INTERVAL (60 * HZ)
18#define IEEE80211_MESH_RANN_INTERVAL (1 * HZ)
17 19
18#define PP_OFFSET 1 /* Path Selection Protocol */ 20#define MESHCONF_CAPAB_ACCEPT_PLINKS 0x01
19#define PM_OFFSET 5 /* Path Selection Metric */ 21#define MESHCONF_CAPAB_FORWARDING 0x08
20#define CC_OFFSET 9 /* Congestion Control Mode */
21#define SP_OFFSET 13 /* Synchronization Protocol */
22#define AUTH_OFFSET 17 /* Authentication Protocol */
23#define CAPAB_OFFSET 22
24#define CAPAB_ACCEPT_PLINKS 0x80
25#define CAPAB_FORWARDING 0x10
26 22
27#define TMR_RUNNING_HK 0 23#define TMR_RUNNING_HK 0
28#define TMR_RUNNING_MP 1 24#define TMR_RUNNING_MP 1
25#define TMR_RUNNING_MPR 2
29 26
30int mesh_allocated; 27int mesh_allocated;
31static struct kmem_cache *rm_cache; 28static struct kmem_cache *rm_cache;
@@ -50,7 +47,7 @@ static void ieee80211_mesh_housekeeping_timer(unsigned long data)
50 struct ieee80211_local *local = sdata->local; 47 struct ieee80211_local *local = sdata->local;
51 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; 48 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
52 49
53 ifmsh->wrkq_flags |= MESH_WORK_HOUSEKEEPING; 50 set_bit(MESH_WORK_HOUSEKEEPING, &ifmsh->wrkq_flags);
54 51
55 if (local->quiescing) { 52 if (local->quiescing) {
56 set_bit(TMR_RUNNING_HK, &ifmsh->timers_running); 53 set_bit(TMR_RUNNING_HK, &ifmsh->timers_running);
@@ -85,11 +82,11 @@ bool mesh_matches_local(struct ieee802_11_elems *ie, struct ieee80211_sub_if_dat
85 */ 82 */
86 if (ifmsh->mesh_id_len == ie->mesh_id_len && 83 if (ifmsh->mesh_id_len == ie->mesh_id_len &&
87 memcmp(ifmsh->mesh_id, ie->mesh_id, ie->mesh_id_len) == 0 && 84 memcmp(ifmsh->mesh_id, ie->mesh_id, ie->mesh_id_len) == 0 &&
88 memcmp(ifmsh->mesh_pp_id, ie->mesh_config + PP_OFFSET, 4) == 0 && 85 (ifmsh->mesh_pp_id == ie->mesh_config->meshconf_psel) &&
89 memcmp(ifmsh->mesh_pm_id, ie->mesh_config + PM_OFFSET, 4) == 0 && 86 (ifmsh->mesh_pm_id == ie->mesh_config->meshconf_pmetric) &&
90 memcmp(ifmsh->mesh_cc_id, ie->mesh_config + CC_OFFSET, 4) == 0 && 87 (ifmsh->mesh_cc_id == ie->mesh_config->meshconf_congest) &&
91 memcmp(ifmsh->mesh_sp_id, ie->mesh_config + SP_OFFSET, 4) == 0 && 88 (ifmsh->mesh_sp_id == ie->mesh_config->meshconf_synch) &&
92 memcmp(ifmsh->mesh_auth_id, ie->mesh_config + AUTH_OFFSET, 4) == 0) 89 (ifmsh->mesh_auth_id == ie->mesh_config->meshconf_auth))
93 return true; 90 return true;
94 91
95 return false; 92 return false;
@@ -102,7 +99,8 @@ bool mesh_matches_local(struct ieee802_11_elems *ie, struct ieee80211_sub_if_dat
102 */ 99 */
103bool mesh_peer_accepts_plinks(struct ieee802_11_elems *ie) 100bool mesh_peer_accepts_plinks(struct ieee802_11_elems *ie)
104{ 101{
105 return (*(ie->mesh_config + CAPAB_OFFSET) & CAPAB_ACCEPT_PLINKS) != 0; 102 return (ie->mesh_config->meshconf_cap &
103 MESHCONF_CAPAB_ACCEPT_PLINKS) != 0;
106} 104}
107 105
108/** 106/**
@@ -128,18 +126,11 @@ void mesh_accept_plinks_update(struct ieee80211_sub_if_data *sdata)
128 126
129void mesh_ids_set_default(struct ieee80211_if_mesh *sta) 127void mesh_ids_set_default(struct ieee80211_if_mesh *sta)
130{ 128{
131 u8 oui[3] = {0x00, 0x0F, 0xAC}; 129 sta->mesh_pp_id = 0; /* HWMP */
132 130 sta->mesh_pm_id = 0; /* Airtime */
133 memcpy(sta->mesh_pp_id, oui, sizeof(oui)); 131 sta->mesh_cc_id = 0; /* Disabled */
134 memcpy(sta->mesh_pm_id, oui, sizeof(oui)); 132 sta->mesh_sp_id = 0; /* Neighbor Offset */
135 memcpy(sta->mesh_cc_id, oui, sizeof(oui)); 133 sta->mesh_auth_id = 0; /* Disabled */
136 memcpy(sta->mesh_sp_id, oui, sizeof(oui));
137 memcpy(sta->mesh_auth_id, oui, sizeof(oui));
138 sta->mesh_pp_id[sizeof(oui)] = 0;
139 sta->mesh_pm_id[sizeof(oui)] = 0;
140 sta->mesh_cc_id[sizeof(oui)] = 0xff;
141 sta->mesh_sp_id[sizeof(oui)] = 0xff;
142 sta->mesh_auth_id[sizeof(oui)] = 0x0;
143} 134}
144 135
145int mesh_rmc_init(struct ieee80211_sub_if_data *sdata) 136int mesh_rmc_init(struct ieee80211_sub_if_data *sdata)
@@ -205,8 +196,8 @@ int mesh_rmc_check(u8 *sa, struct ieee80211s_hdr *mesh_hdr,
205 list_del(&p->list); 196 list_del(&p->list);
206 kmem_cache_free(rm_cache, p); 197 kmem_cache_free(rm_cache, p);
207 --entries; 198 --entries;
208 } else if ((seqnum == p->seqnum) 199 } else if ((seqnum == p->seqnum) &&
209 && (memcmp(sa, p->sa, ETH_ALEN) == 0)) 200 (memcmp(sa, p->sa, ETH_ALEN) == 0))
210 return -1; 201 return -1;
211 } 202 }
212 203
@@ -228,6 +219,7 @@ void mesh_mgmt_ies_add(struct sk_buff *skb, struct ieee80211_sub_if_data *sdata)
228 struct ieee80211_supported_band *sband; 219 struct ieee80211_supported_band *sband;
229 u8 *pos; 220 u8 *pos;
230 int len, i, rate; 221 int len, i, rate;
222 u8 neighbors;
231 223
232 sband = local->hw.wiphy->bands[local->hw.conf.channel->band]; 224 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
233 len = sband->n_bitrates; 225 len = sband->n_bitrates;
@@ -251,46 +243,49 @@ void mesh_mgmt_ies_add(struct sk_buff *skb, struct ieee80211_sub_if_data *sdata)
251 } 243 }
252 } 244 }
253 245
246 if (sband->band == IEEE80211_BAND_2GHZ) {
247 pos = skb_put(skb, 2 + 1);
248 *pos++ = WLAN_EID_DS_PARAMS;
249 *pos++ = 1;
250 *pos++ = ieee80211_frequency_to_channel(local->hw.conf.channel->center_freq);
251 }
252
254 pos = skb_put(skb, 2 + sdata->u.mesh.mesh_id_len); 253 pos = skb_put(skb, 2 + sdata->u.mesh.mesh_id_len);
255 *pos++ = WLAN_EID_MESH_ID; 254 *pos++ = WLAN_EID_MESH_ID;
256 *pos++ = sdata->u.mesh.mesh_id_len; 255 *pos++ = sdata->u.mesh.mesh_id_len;
257 if (sdata->u.mesh.mesh_id_len) 256 if (sdata->u.mesh.mesh_id_len)
258 memcpy(pos, sdata->u.mesh.mesh_id, sdata->u.mesh.mesh_id_len); 257 memcpy(pos, sdata->u.mesh.mesh_id, sdata->u.mesh.mesh_id_len);
259 258
260 pos = skb_put(skb, 2 + IEEE80211_MESH_CONFIG_LEN); 259 pos = skb_put(skb, 2 + sizeof(struct ieee80211_meshconf_ie));
261 *pos++ = WLAN_EID_MESH_CONFIG; 260 *pos++ = WLAN_EID_MESH_CONFIG;
262 *pos++ = IEEE80211_MESH_CONFIG_LEN; 261 *pos++ = sizeof(struct ieee80211_meshconf_ie);
263 /* Version */
264 *pos++ = 1;
265 262
266 /* Active path selection protocol ID */ 263 /* Active path selection protocol ID */
267 memcpy(pos, sdata->u.mesh.mesh_pp_id, 4); 264 *pos++ = sdata->u.mesh.mesh_pp_id;
268 pos += 4;
269 265
270 /* Active path selection metric ID */ 266 /* Active path selection metric ID */
271 memcpy(pos, sdata->u.mesh.mesh_pm_id, 4); 267 *pos++ = sdata->u.mesh.mesh_pm_id;
272 pos += 4;
273 268
274 /* Congestion control mode identifier */ 269 /* Congestion control mode identifier */
275 memcpy(pos, sdata->u.mesh.mesh_cc_id, 4); 270 *pos++ = sdata->u.mesh.mesh_cc_id;
276 pos += 4;
277 271
278 /* Synchronization protocol identifier */ 272 /* Synchronization protocol identifier */
279 memcpy(pos, sdata->u.mesh.mesh_sp_id, 4); 273 *pos++ = sdata->u.mesh.mesh_sp_id;
280 pos += 4;
281 274
282 /* Authentication Protocol identifier */ 275 /* Authentication Protocol identifier */
283 memcpy(pos, sdata->u.mesh.mesh_auth_id, 4); 276 *pos++ = sdata->u.mesh.mesh_auth_id;
284 pos += 4;
285 277
286 /* Mesh Formation Info */ 278 /* Mesh Formation Info - number of neighbors */
287 memset(pos, 0x00, 1); 279 neighbors = atomic_read(&sdata->u.mesh.mshstats.estab_plinks);
288 pos += 1; 280 /* Number of neighbor mesh STAs or 15 whichever is smaller */
281 neighbors = (neighbors > 15) ? 15 : neighbors;
282 *pos++ = neighbors << 1;
289 283
290 /* Mesh capability */ 284 /* Mesh capability */
291 sdata->u.mesh.accepting_plinks = mesh_plink_availables(sdata); 285 sdata->u.mesh.accepting_plinks = mesh_plink_availables(sdata);
292 *pos = CAPAB_FORWARDING; 286 *pos = MESHCONF_CAPAB_FORWARDING;
293 *pos++ |= sdata->u.mesh.accepting_plinks ? CAPAB_ACCEPT_PLINKS : 0x00; 287 *pos++ |= sdata->u.mesh.accepting_plinks ?
288 MESHCONF_CAPAB_ACCEPT_PLINKS : 0x00;
294 *pos++ = 0x00; 289 *pos++ = 0x00;
295 290
296 return; 291 return;
@@ -355,6 +350,34 @@ static void ieee80211_mesh_path_timer(unsigned long data)
355 ieee80211_queue_work(&local->hw, &ifmsh->work); 350 ieee80211_queue_work(&local->hw, &ifmsh->work);
356} 351}
357 352
353static void ieee80211_mesh_path_root_timer(unsigned long data)
354{
355 struct ieee80211_sub_if_data *sdata =
356 (struct ieee80211_sub_if_data *) data;
357 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
358 struct ieee80211_local *local = sdata->local;
359
360 set_bit(MESH_WORK_ROOT, &ifmsh->wrkq_flags);
361
362 if (local->quiescing) {
363 set_bit(TMR_RUNNING_MPR, &ifmsh->timers_running);
364 return;
365 }
366
367 ieee80211_queue_work(&local->hw, &ifmsh->work);
368}
369
370void ieee80211_mesh_root_setup(struct ieee80211_if_mesh *ifmsh)
371{
372 if (ifmsh->mshcfg.dot11MeshHWMPRootMode)
373 set_bit(MESH_WORK_ROOT, &ifmsh->wrkq_flags);
374 else {
375 clear_bit(MESH_WORK_ROOT, &ifmsh->wrkq_flags);
376 /* stop running timer */
377 del_timer_sync(&ifmsh->mesh_path_root_timer);
378 }
379}
380
358/** 381/**
359 * ieee80211_fill_mesh_addresses - fill addresses of a locally originated mesh frame 382 * ieee80211_fill_mesh_addresses - fill addresses of a locally originated mesh frame
360 * @hdr: 802.11 frame header 383 * @hdr: 802.11 frame header
@@ -365,8 +388,9 @@ static void ieee80211_mesh_path_timer(unsigned long data)
365 * 388 *
366 * Return the length of the 802.11 (does not include a mesh control header) 389 * Return the length of the 802.11 (does not include a mesh control header)
367 */ 390 */
368int ieee80211_fill_mesh_addresses(struct ieee80211_hdr *hdr, __le16 *fc, char 391int ieee80211_fill_mesh_addresses(struct ieee80211_hdr *hdr, __le16 *fc,
369 *meshda, char *meshsa) { 392 const u8 *meshda, const u8 *meshsa)
393{
370 if (is_multicast_ether_addr(meshda)) { 394 if (is_multicast_ether_addr(meshda)) {
371 *fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS); 395 *fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS);
372 /* DA TA SA */ 396 /* DA TA SA */
@@ -404,7 +428,7 @@ int ieee80211_new_mesh_header(struct ieee80211s_hdr *meshhdr,
404 char *addr5, char *addr6) 428 char *addr5, char *addr6)
405{ 429{
406 int aelen = 0; 430 int aelen = 0;
407 memset(meshhdr, 0, sizeof(meshhdr)); 431 memset(meshhdr, 0, sizeof(*meshhdr));
408 meshhdr->ttl = sdata->u.mesh.mshcfg.dot11MeshTTL; 432 meshhdr->ttl = sdata->u.mesh.mshcfg.dot11MeshTTL;
409 put_unaligned(cpu_to_le32(sdata->u.mesh.mesh_seqnum), &meshhdr->seqnum); 433 put_unaligned(cpu_to_le32(sdata->u.mesh.mesh_seqnum), &meshhdr->seqnum);
410 sdata->u.mesh.mesh_seqnum++; 434 sdata->u.mesh.mesh_seqnum++;
@@ -434,7 +458,7 @@ static void ieee80211_mesh_housekeeping(struct ieee80211_sub_if_data *sdata,
434 458
435#ifdef CONFIG_MAC80211_VERBOSE_DEBUG 459#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
436 printk(KERN_DEBUG "%s: running mesh housekeeping\n", 460 printk(KERN_DEBUG "%s: running mesh housekeeping\n",
437 sdata->dev->name); 461 sdata->name);
438#endif 462#endif
439 463
440 ieee80211_sta_expire(sdata, IEEE80211_MESH_PEER_INACTIVITY_LIMIT); 464 ieee80211_sta_expire(sdata, IEEE80211_MESH_PEER_INACTIVITY_LIMIT);
@@ -448,6 +472,15 @@ static void ieee80211_mesh_housekeeping(struct ieee80211_sub_if_data *sdata,
448 round_jiffies(jiffies + IEEE80211_MESH_HOUSEKEEPING_INTERVAL)); 472 round_jiffies(jiffies + IEEE80211_MESH_HOUSEKEEPING_INTERVAL));
449} 473}
450 474
475static void ieee80211_mesh_rootpath(struct ieee80211_sub_if_data *sdata)
476{
477 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
478
479 mesh_path_tx_root_frame(sdata);
480 mod_timer(&ifmsh->mesh_path_root_timer,
481 round_jiffies(jiffies + IEEE80211_MESH_RANN_INTERVAL));
482}
483
451#ifdef CONFIG_PM 484#ifdef CONFIG_PM
452void ieee80211_mesh_quiesce(struct ieee80211_sub_if_data *sdata) 485void ieee80211_mesh_quiesce(struct ieee80211_sub_if_data *sdata)
453{ 486{
@@ -462,6 +495,8 @@ void ieee80211_mesh_quiesce(struct ieee80211_sub_if_data *sdata)
462 set_bit(TMR_RUNNING_HK, &ifmsh->timers_running); 495 set_bit(TMR_RUNNING_HK, &ifmsh->timers_running);
463 if (del_timer_sync(&ifmsh->mesh_path_timer)) 496 if (del_timer_sync(&ifmsh->mesh_path_timer))
464 set_bit(TMR_RUNNING_MP, &ifmsh->timers_running); 497 set_bit(TMR_RUNNING_MP, &ifmsh->timers_running);
498 if (del_timer_sync(&ifmsh->mesh_path_root_timer))
499 set_bit(TMR_RUNNING_MPR, &ifmsh->timers_running);
465} 500}
466 501
467void ieee80211_mesh_restart(struct ieee80211_sub_if_data *sdata) 502void ieee80211_mesh_restart(struct ieee80211_sub_if_data *sdata)
@@ -472,6 +507,9 @@ void ieee80211_mesh_restart(struct ieee80211_sub_if_data *sdata)
472 add_timer(&ifmsh->housekeeping_timer); 507 add_timer(&ifmsh->housekeeping_timer);
473 if (test_and_clear_bit(TMR_RUNNING_MP, &ifmsh->timers_running)) 508 if (test_and_clear_bit(TMR_RUNNING_MP, &ifmsh->timers_running))
474 add_timer(&ifmsh->mesh_path_timer); 509 add_timer(&ifmsh->mesh_path_timer);
510 if (test_and_clear_bit(TMR_RUNNING_MPR, &ifmsh->timers_running))
511 add_timer(&ifmsh->mesh_path_root_timer);
512 ieee80211_mesh_root_setup(ifmsh);
475} 513}
476#endif 514#endif
477 515
@@ -480,7 +518,8 @@ void ieee80211_start_mesh(struct ieee80211_sub_if_data *sdata)
480 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; 518 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
481 struct ieee80211_local *local = sdata->local; 519 struct ieee80211_local *local = sdata->local;
482 520
483 ifmsh->wrkq_flags |= MESH_WORK_HOUSEKEEPING; 521 set_bit(MESH_WORK_HOUSEKEEPING, &ifmsh->wrkq_flags);
522 ieee80211_mesh_root_setup(ifmsh);
484 ieee80211_queue_work(&local->hw, &ifmsh->work); 523 ieee80211_queue_work(&local->hw, &ifmsh->work);
485 sdata->vif.bss_conf.beacon_int = MESH_DEFAULT_BEACON_INTERVAL; 524 sdata->vif.bss_conf.beacon_int = MESH_DEFAULT_BEACON_INTERVAL;
486 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON | 525 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON |
@@ -491,6 +530,7 @@ void ieee80211_start_mesh(struct ieee80211_sub_if_data *sdata)
491void ieee80211_stop_mesh(struct ieee80211_sub_if_data *sdata) 530void ieee80211_stop_mesh(struct ieee80211_sub_if_data *sdata)
492{ 531{
493 del_timer_sync(&sdata->u.mesh.housekeeping_timer); 532 del_timer_sync(&sdata->u.mesh.housekeeping_timer);
533 del_timer_sync(&sdata->u.mesh.mesh_path_root_timer);
494 /* 534 /*
495 * If the timer fired while we waited for it, it will have 535 * If the timer fired while we waited for it, it will have
496 * requeued the work. Now the work will be running again 536 * requeued the work. Now the work will be running again
@@ -526,7 +566,7 @@ static void ieee80211_mesh_rx_bcn_presp(struct ieee80211_sub_if_data *sdata,
526 566
527 /* ignore ProbeResp to foreign address */ 567 /* ignore ProbeResp to foreign address */
528 if (stype == IEEE80211_STYPE_PROBE_RESP && 568 if (stype == IEEE80211_STYPE_PROBE_RESP &&
529 compare_ether_addr(mgmt->da, sdata->dev->dev_addr)) 569 compare_ether_addr(mgmt->da, sdata->vif.addr))
530 return; 570 return;
531 571
532 baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt; 572 baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt;
@@ -561,7 +601,7 @@ static void ieee80211_mesh_rx_mgmt_action(struct ieee80211_sub_if_data *sdata,
561 struct ieee80211_rx_status *rx_status) 601 struct ieee80211_rx_status *rx_status)
562{ 602{
563 switch (mgmt->u.action.category) { 603 switch (mgmt->u.action.category) {
564 case PLINK_CATEGORY: 604 case MESH_PLINK_CATEGORY:
565 mesh_rx_plink_frame(sdata, mgmt, len, rx_status); 605 mesh_rx_plink_frame(sdata, mgmt, len, rx_status);
566 break; 606 break;
567 case MESH_PATH_SEL_CATEGORY: 607 case MESH_PATH_SEL_CATEGORY:
@@ -606,7 +646,7 @@ static void ieee80211_mesh_work(struct work_struct *work)
606 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; 646 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
607 struct sk_buff *skb; 647 struct sk_buff *skb;
608 648
609 if (!netif_running(sdata->dev)) 649 if (!ieee80211_sdata_running(sdata))
610 return; 650 return;
611 651
612 if (local->scanning) 652 if (local->scanning)
@@ -628,6 +668,9 @@ static void ieee80211_mesh_work(struct work_struct *work)
628 668
629 if (test_and_clear_bit(MESH_WORK_HOUSEKEEPING, &ifmsh->wrkq_flags)) 669 if (test_and_clear_bit(MESH_WORK_HOUSEKEEPING, &ifmsh->wrkq_flags))
630 ieee80211_mesh_housekeeping(sdata, ifmsh); 670 ieee80211_mesh_housekeeping(sdata, ifmsh);
671
672 if (test_and_clear_bit(MESH_WORK_ROOT, &ifmsh->wrkq_flags))
673 ieee80211_mesh_rootpath(sdata);
631} 674}
632 675
633void ieee80211_mesh_notify_scan_completed(struct ieee80211_local *local) 676void ieee80211_mesh_notify_scan_completed(struct ieee80211_local *local)
@@ -673,7 +716,7 @@ void ieee80211_mesh_init_sdata(struct ieee80211_sub_if_data *sdata)
673 MESH_MIN_DISCOVERY_TIMEOUT; 716 MESH_MIN_DISCOVERY_TIMEOUT;
674 ifmsh->accepting_plinks = true; 717 ifmsh->accepting_plinks = true;
675 ifmsh->preq_id = 0; 718 ifmsh->preq_id = 0;
676 ifmsh->dsn = 0; 719 ifmsh->sn = 0;
677 atomic_set(&ifmsh->mpaths, 0); 720 atomic_set(&ifmsh->mpaths, 0);
678 mesh_rmc_init(sdata); 721 mesh_rmc_init(sdata);
679 ifmsh->last_preq = jiffies; 722 ifmsh->last_preq = jiffies;
@@ -684,6 +727,9 @@ void ieee80211_mesh_init_sdata(struct ieee80211_sub_if_data *sdata)
684 setup_timer(&ifmsh->mesh_path_timer, 727 setup_timer(&ifmsh->mesh_path_timer,
685 ieee80211_mesh_path_timer, 728 ieee80211_mesh_path_timer,
686 (unsigned long) sdata); 729 (unsigned long) sdata);
730 setup_timer(&ifmsh->mesh_path_root_timer,
731 ieee80211_mesh_path_root_timer,
732 (unsigned long) sdata);
687 INIT_LIST_HEAD(&ifmsh->preq_queue.list); 733 INIT_LIST_HEAD(&ifmsh->preq_queue.list);
688 spin_lock_init(&ifmsh->mesh_preq_queue_lock); 734 spin_lock_init(&ifmsh->mesh_preq_queue_lock);
689} 735}
@@ -704,9 +750,6 @@ ieee80211_mesh_rx_mgmt(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb)
704 750
705 switch (fc & IEEE80211_FCTL_STYPE) { 751 switch (fc & IEEE80211_FCTL_STYPE) {
706 case IEEE80211_STYPE_ACTION: 752 case IEEE80211_STYPE_ACTION:
707 if (skb->len < IEEE80211_MIN_ACTION_SIZE)
708 return RX_DROP_MONITOR;
709 /* fall through */
710 case IEEE80211_STYPE_PROBE_RESP: 753 case IEEE80211_STYPE_PROBE_RESP:
711 case IEEE80211_STYPE_BEACON: 754 case IEEE80211_STYPE_BEACON:
712 skb_queue_tail(&ifmsh->skb_queue, skb); 755 skb_queue_tail(&ifmsh->skb_queue, skb);
diff --git a/net/mac80211/mesh.h b/net/mac80211/mesh.h
index dd1c19319f0a..85562c59d7d6 100644
--- a/net/mac80211/mesh.h
+++ b/net/mac80211/mesh.h
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (c) 2008 open80211s Ltd. 2 * Copyright (c) 2008, 2009 open80211s Ltd.
3 * Authors: Luis Carlos Cobo <luisca@cozybit.com> 3 * Authors: Luis Carlos Cobo <luisca@cozybit.com>
4 * Javier Cardona <javier@cozybit.com> 4 * Javier Cardona <javier@cozybit.com>
5 * 5 *
@@ -26,7 +26,7 @@
26 * 26 *
27 * @MESH_PATH_ACTIVE: the mesh path can be used for forwarding 27 * @MESH_PATH_ACTIVE: the mesh path can be used for forwarding
28 * @MESH_PATH_RESOLVING: the discovery process is running for this mesh path 28 * @MESH_PATH_RESOLVING: the discovery process is running for this mesh path
29 * @MESH_PATH_DSN_VALID: the mesh path contains a valid destination sequence 29 * @MESH_PATH_SN_VALID: the mesh path contains a valid destination sequence
30 * number 30 * number
31 * @MESH_PATH_FIXED: the mesh path has been manually set and should not be 31 * @MESH_PATH_FIXED: the mesh path has been manually set and should not be
32 * modified 32 * modified
@@ -38,7 +38,7 @@
38enum mesh_path_flags { 38enum mesh_path_flags {
39 MESH_PATH_ACTIVE = BIT(0), 39 MESH_PATH_ACTIVE = BIT(0),
40 MESH_PATH_RESOLVING = BIT(1), 40 MESH_PATH_RESOLVING = BIT(1),
41 MESH_PATH_DSN_VALID = BIT(2), 41 MESH_PATH_SN_VALID = BIT(2),
42 MESH_PATH_FIXED = BIT(3), 42 MESH_PATH_FIXED = BIT(3),
43 MESH_PATH_RESOLVED = BIT(4), 43 MESH_PATH_RESOLVED = BIT(4),
44}; 44};
@@ -53,11 +53,13 @@ enum mesh_path_flags {
53 * to grow. 53 * to grow.
54 * @MESH_WORK_GROW_MPP_TABLE: the mesh portals table is full and needs to 54 * @MESH_WORK_GROW_MPP_TABLE: the mesh portals table is full and needs to
55 * grow 55 * grow
56 * @MESH_WORK_ROOT: the mesh root station needs to send a frame
56 */ 57 */
57enum mesh_deferred_task_flags { 58enum mesh_deferred_task_flags {
58 MESH_WORK_HOUSEKEEPING, 59 MESH_WORK_HOUSEKEEPING,
59 MESH_WORK_GROW_MPATH_TABLE, 60 MESH_WORK_GROW_MPATH_TABLE,
60 MESH_WORK_GROW_MPP_TABLE, 61 MESH_WORK_GROW_MPP_TABLE,
62 MESH_WORK_ROOT,
61}; 63};
62 64
63/** 65/**
@@ -70,7 +72,7 @@ enum mesh_deferred_task_flags {
70 * @timer: mesh path discovery timer 72 * @timer: mesh path discovery timer
71 * @frame_queue: pending queue for frames sent to this destination while the 73 * @frame_queue: pending queue for frames sent to this destination while the
72 * path is unresolved 74 * path is unresolved
73 * @dsn: destination sequence number of the destination 75 * @sn: target sequence number
74 * @metric: current metric to this destination 76 * @metric: current metric to this destination
75 * @hop_count: hops to destination 77 * @hop_count: hops to destination
76 * @exp_time: in jiffies, when the path will expire or when it expired 78 * @exp_time: in jiffies, when the path will expire or when it expired
@@ -94,7 +96,7 @@ struct mesh_path {
94 struct timer_list timer; 96 struct timer_list timer;
95 struct sk_buff_head frame_queue; 97 struct sk_buff_head frame_queue;
96 struct rcu_head rcu; 98 struct rcu_head rcu;
97 u32 dsn; 99 u32 sn;
98 u32 metric; 100 u32 metric;
99 u8 hop_count; 101 u8 hop_count;
100 unsigned long exp_time; 102 unsigned long exp_time;
@@ -174,7 +176,7 @@ struct mesh_rmc {
174#define MESH_CFG_CMP_LEN (IEEE80211_MESH_CONFIG_LEN - 2) 176#define MESH_CFG_CMP_LEN (IEEE80211_MESH_CONFIG_LEN - 2)
175 177
176/* Default values, timeouts in ms */ 178/* Default values, timeouts in ms */
177#define MESH_TTL 5 179#define MESH_TTL 31
178#define MESH_MAX_RETR 3 180#define MESH_MAX_RETR 3
179#define MESH_RET_T 100 181#define MESH_RET_T 100
180#define MESH_CONF_T 100 182#define MESH_CONF_T 100
@@ -186,8 +188,9 @@ struct mesh_rmc {
186 */ 188 */
187#define MESH_PREQ_MIN_INT 10 189#define MESH_PREQ_MIN_INT 10
188#define MESH_DIAM_TRAVERSAL_TIME 50 190#define MESH_DIAM_TRAVERSAL_TIME 50
189/* Paths will be refreshed if they are closer than PATH_REFRESH_TIME to their 191/* A path will be refreshed if it is used PATH_REFRESH_TIME milliseconds before
190 * expiration 192 * timing out. This way it will remain ACTIVE and no data frames will be
193 * unnecesarily held in the pending queue.
191 */ 194 */
192#define MESH_PATH_REFRESH_TIME 1000 195#define MESH_PATH_REFRESH_TIME 1000
193#define MESH_MIN_DISCOVERY_TIMEOUT (2 * MESH_DIAM_TRAVERSAL_TIME) 196#define MESH_MIN_DISCOVERY_TIMEOUT (2 * MESH_DIAM_TRAVERSAL_TIME)
@@ -206,13 +209,19 @@ struct mesh_rmc {
206#define MESH_MAX_MPATHS 1024 209#define MESH_MAX_MPATHS 1024
207 210
208/* Pending ANA approval */ 211/* Pending ANA approval */
209#define PLINK_CATEGORY 30 212#define MESH_PLINK_CATEGORY 30
210#define MESH_PATH_SEL_CATEGORY 32 213#define MESH_PATH_SEL_CATEGORY 32
214#define MESH_PATH_SEL_ACTION 0
215
216/* PERR reason codes */
217#define PEER_RCODE_UNSPECIFIED 11
218#define PERR_RCODE_NO_ROUTE 12
219#define PERR_RCODE_DEST_UNREACH 13
211 220
212/* Public interfaces */ 221/* Public interfaces */
213/* Various */ 222/* Various */
214int ieee80211_fill_mesh_addresses(struct ieee80211_hdr *hdr, __le16 *fc, 223int ieee80211_fill_mesh_addresses(struct ieee80211_hdr *hdr, __le16 *fc,
215 char *da, char *sa); 224 const u8 *da, const u8 *sa);
216int ieee80211_new_mesh_header(struct ieee80211s_hdr *meshhdr, 225int ieee80211_new_mesh_header(struct ieee80211s_hdr *meshhdr,
217 struct ieee80211_sub_if_data *sdata, char *addr4, 226 struct ieee80211_sub_if_data *sdata, char *addr4,
218 char *addr5, char *addr6); 227 char *addr5, char *addr6);
@@ -234,6 +243,7 @@ ieee80211_rx_result
234ieee80211_mesh_rx_mgmt(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb); 243ieee80211_mesh_rx_mgmt(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb);
235void ieee80211_start_mesh(struct ieee80211_sub_if_data *sdata); 244void ieee80211_start_mesh(struct ieee80211_sub_if_data *sdata);
236void ieee80211_stop_mesh(struct ieee80211_sub_if_data *sdata); 245void ieee80211_stop_mesh(struct ieee80211_sub_if_data *sdata);
246void ieee80211_mesh_root_setup(struct ieee80211_if_mesh *ifmsh);
237 247
238/* Mesh paths */ 248/* Mesh paths */
239int mesh_nexthop_lookup(struct sk_buff *skb, 249int mesh_nexthop_lookup(struct sk_buff *skb,
@@ -274,8 +284,8 @@ void mesh_mpp_table_grow(void);
274u32 mesh_table_hash(u8 *addr, struct ieee80211_sub_if_data *sdata, 284u32 mesh_table_hash(u8 *addr, struct ieee80211_sub_if_data *sdata,
275 struct mesh_table *tbl); 285 struct mesh_table *tbl);
276/* Mesh paths */ 286/* Mesh paths */
277int mesh_path_error_tx(u8 *dest, __le32 dest_dsn, u8 *ra, 287int mesh_path_error_tx(u8 ttl, u8 *target, __le32 target_sn, __le16 target_rcode,
278 struct ieee80211_sub_if_data *sdata); 288 const u8 *ra, struct ieee80211_sub_if_data *sdata);
279void mesh_path_assign_nexthop(struct mesh_path *mpath, struct sta_info *sta); 289void mesh_path_assign_nexthop(struct mesh_path *mpath, struct sta_info *sta);
280void mesh_path_flush_pending(struct mesh_path *mpath); 290void mesh_path_flush_pending(struct mesh_path *mpath);
281void mesh_path_tx_pending(struct mesh_path *mpath); 291void mesh_path_tx_pending(struct mesh_path *mpath);
@@ -288,6 +298,7 @@ void mesh_path_discard_frame(struct sk_buff *skb,
288 struct ieee80211_sub_if_data *sdata); 298 struct ieee80211_sub_if_data *sdata);
289void mesh_path_quiesce(struct ieee80211_sub_if_data *sdata); 299void mesh_path_quiesce(struct ieee80211_sub_if_data *sdata);
290void mesh_path_restart(struct ieee80211_sub_if_data *sdata); 300void mesh_path_restart(struct ieee80211_sub_if_data *sdata);
301void mesh_path_tx_root_frame(struct ieee80211_sub_if_data *sdata);
291 302
292extern int mesh_paths_generation; 303extern int mesh_paths_generation;
293 304
diff --git a/net/mac80211/mesh_hwmp.c b/net/mac80211/mesh_hwmp.c
index 29b82e98effa..fefc45c4b4e8 100644
--- a/net/mac80211/mesh_hwmp.c
+++ b/net/mac80211/mesh_hwmp.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (c) 2008 open80211s Ltd. 2 * Copyright (c) 2008, 2009 open80211s Ltd.
3 * Author: Luis Carlos Cobo <luisca@cozybit.com> 3 * Author: Luis Carlos Cobo <luisca@cozybit.com>
4 * 4 *
5 * This program is free software; you can redistribute it and/or modify 5 * This program is free software; you can redistribute it and/or modify
@@ -7,8 +7,15 @@
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 */ 8 */
9 9
10#include <linux/slab.h>
10#include "mesh.h" 11#include "mesh.h"
11 12
13#ifdef CONFIG_MAC80211_VERBOSE_MHWMP_DEBUG
14#define mhwmp_dbg(fmt, args...) printk(KERN_DEBUG "Mesh HWMP: " fmt, ##args)
15#else
16#define mhwmp_dbg(fmt, args...) do { (void)(0); } while (0)
17#endif
18
12#define TEST_FRAME_LEN 8192 19#define TEST_FRAME_LEN 8192
13#define MAX_METRIC 0xffffffff 20#define MAX_METRIC 0xffffffff
14#define ARITH_SHIFT 8 21#define ARITH_SHIFT 8
@@ -21,6 +28,12 @@
21#define MP_F_DO 0x1 28#define MP_F_DO 0x1
22/* Reply and forward */ 29/* Reply and forward */
23#define MP_F_RF 0x2 30#define MP_F_RF 0x2
31/* Unknown Sequence Number */
32#define MP_F_USN 0x01
33/* Reason code Present */
34#define MP_F_RCODE 0x02
35
36static void mesh_queue_preq(struct mesh_path *, u8);
24 37
25static inline u32 u32_field_get(u8 *preq_elem, int offset, bool ae) 38static inline u32 u32_field_get(u8 *preq_elem, int offset, bool ae)
26{ 39{
@@ -29,6 +42,13 @@ static inline u32 u32_field_get(u8 *preq_elem, int offset, bool ae)
29 return get_unaligned_le32(preq_elem + offset); 42 return get_unaligned_le32(preq_elem + offset);
30} 43}
31 44
45static inline u32 u16_field_get(u8 *preq_elem, int offset, bool ae)
46{
47 if (ae)
48 offset += 6;
49 return get_unaligned_le16(preq_elem + offset);
50}
51
32/* HWMP IE processing macros */ 52/* HWMP IE processing macros */
33#define AE_F (1<<6) 53#define AE_F (1<<6)
34#define AE_F_SET(x) (*x & AE_F) 54#define AE_F_SET(x) (*x & AE_F)
@@ -37,30 +57,33 @@ static inline u32 u32_field_get(u8 *preq_elem, int offset, bool ae)
37#define PREQ_IE_TTL(x) (*(x + 2)) 57#define PREQ_IE_TTL(x) (*(x + 2))
38#define PREQ_IE_PREQ_ID(x) u32_field_get(x, 3, 0) 58#define PREQ_IE_PREQ_ID(x) u32_field_get(x, 3, 0)
39#define PREQ_IE_ORIG_ADDR(x) (x + 7) 59#define PREQ_IE_ORIG_ADDR(x) (x + 7)
40#define PREQ_IE_ORIG_DSN(x) u32_field_get(x, 13, 0); 60#define PREQ_IE_ORIG_SN(x) u32_field_get(x, 13, 0);
41#define PREQ_IE_LIFETIME(x) u32_field_get(x, 17, AE_F_SET(x)); 61#define PREQ_IE_LIFETIME(x) u32_field_get(x, 17, AE_F_SET(x));
42#define PREQ_IE_METRIC(x) u32_field_get(x, 21, AE_F_SET(x)); 62#define PREQ_IE_METRIC(x) u32_field_get(x, 21, AE_F_SET(x));
43#define PREQ_IE_DST_F(x) (*(AE_F_SET(x) ? x + 32 : x + 26)) 63#define PREQ_IE_TARGET_F(x) (*(AE_F_SET(x) ? x + 32 : x + 26))
44#define PREQ_IE_DST_ADDR(x) (AE_F_SET(x) ? x + 33 : x + 27) 64#define PREQ_IE_TARGET_ADDR(x) (AE_F_SET(x) ? x + 33 : x + 27)
45#define PREQ_IE_DST_DSN(x) u32_field_get(x, 33, AE_F_SET(x)); 65#define PREQ_IE_TARGET_SN(x) u32_field_get(x, 33, AE_F_SET(x));
46 66
47 67
48#define PREP_IE_FLAGS(x) PREQ_IE_FLAGS(x) 68#define PREP_IE_FLAGS(x) PREQ_IE_FLAGS(x)
49#define PREP_IE_HOPCOUNT(x) PREQ_IE_HOPCOUNT(x) 69#define PREP_IE_HOPCOUNT(x) PREQ_IE_HOPCOUNT(x)
50#define PREP_IE_TTL(x) PREQ_IE_TTL(x) 70#define PREP_IE_TTL(x) PREQ_IE_TTL(x)
51#define PREP_IE_ORIG_ADDR(x) (x + 3) 71#define PREP_IE_ORIG_ADDR(x) (x + 3)
52#define PREP_IE_ORIG_DSN(x) u32_field_get(x, 9, 0); 72#define PREP_IE_ORIG_SN(x) u32_field_get(x, 9, 0);
53#define PREP_IE_LIFETIME(x) u32_field_get(x, 13, AE_F_SET(x)); 73#define PREP_IE_LIFETIME(x) u32_field_get(x, 13, AE_F_SET(x));
54#define PREP_IE_METRIC(x) u32_field_get(x, 17, AE_F_SET(x)); 74#define PREP_IE_METRIC(x) u32_field_get(x, 17, AE_F_SET(x));
55#define PREP_IE_DST_ADDR(x) (AE_F_SET(x) ? x + 27 : x + 21) 75#define PREP_IE_TARGET_ADDR(x) (AE_F_SET(x) ? x + 27 : x + 21)
56#define PREP_IE_DST_DSN(x) u32_field_get(x, 27, AE_F_SET(x)); 76#define PREP_IE_TARGET_SN(x) u32_field_get(x, 27, AE_F_SET(x));
57 77
58#define PERR_IE_DST_ADDR(x) (x + 2) 78#define PERR_IE_TTL(x) (*(x))
59#define PERR_IE_DST_DSN(x) u32_field_get(x, 8, 0); 79#define PERR_IE_TARGET_FLAGS(x) (*(x + 2))
80#define PERR_IE_TARGET_ADDR(x) (x + 3)
81#define PERR_IE_TARGET_SN(x) u32_field_get(x, 9, 0);
82#define PERR_IE_TARGET_RCODE(x) u16_field_get(x, 13, 0);
60 83
61#define MSEC_TO_TU(x) (x*1000/1024) 84#define MSEC_TO_TU(x) (x*1000/1024)
62#define DSN_GT(x, y) ((long) (y) - (long) (x) < 0) 85#define SN_GT(x, y) ((long) (y) - (long) (x) < 0)
63#define DSN_LT(x, y) ((long) (x) - (long) (y) < 0) 86#define SN_LT(x, y) ((long) (x) - (long) (y) < 0)
64 87
65#define net_traversal_jiffies(s) \ 88#define net_traversal_jiffies(s) \
66 msecs_to_jiffies(s->u.mesh.mshcfg.dot11MeshHWMPnetDiameterTraversalTime) 89 msecs_to_jiffies(s->u.mesh.mshcfg.dot11MeshHWMPnetDiameterTraversalTime)
@@ -75,13 +98,17 @@ static inline u32 u32_field_get(u8 *preq_elem, int offset, bool ae)
75enum mpath_frame_type { 98enum mpath_frame_type {
76 MPATH_PREQ = 0, 99 MPATH_PREQ = 0,
77 MPATH_PREP, 100 MPATH_PREP,
78 MPATH_PERR 101 MPATH_PERR,
102 MPATH_RANN
79}; 103};
80 104
105static const u8 broadcast_addr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
106
81static int mesh_path_sel_frame_tx(enum mpath_frame_type action, u8 flags, 107static int mesh_path_sel_frame_tx(enum mpath_frame_type action, u8 flags,
82 u8 *orig_addr, __le32 orig_dsn, u8 dst_flags, u8 *dst, 108 u8 *orig_addr, __le32 orig_sn, u8 target_flags, u8 *target,
83 __le32 dst_dsn, u8 *da, u8 hop_count, u8 ttl, __le32 lifetime, 109 __le32 target_sn, const u8 *da, u8 hop_count, u8 ttl,
84 __le32 metric, __le32 preq_id, struct ieee80211_sub_if_data *sdata) 110 __le32 lifetime, __le32 metric, __le32 preq_id,
111 struct ieee80211_sub_if_data *sdata)
85{ 112{
86 struct ieee80211_local *local = sdata->local; 113 struct ieee80211_local *local = sdata->local;
87 struct sk_buff *skb = dev_alloc_skb(local->hw.extra_tx_headroom + 400); 114 struct sk_buff *skb = dev_alloc_skb(local->hw.extra_tx_headroom + 400);
@@ -102,22 +129,31 @@ static int mesh_path_sel_frame_tx(enum mpath_frame_type action, u8 flags,
102 IEEE80211_STYPE_ACTION); 129 IEEE80211_STYPE_ACTION);
103 130
104 memcpy(mgmt->da, da, ETH_ALEN); 131 memcpy(mgmt->da, da, ETH_ALEN);
105 memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN); 132 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
106 /* BSSID is left zeroed, wildcard value */ 133 /* BSSID == SA */
134 memcpy(mgmt->bssid, sdata->vif.addr, ETH_ALEN);
107 mgmt->u.action.category = MESH_PATH_SEL_CATEGORY; 135 mgmt->u.action.category = MESH_PATH_SEL_CATEGORY;
108 mgmt->u.action.u.mesh_action.action_code = action; 136 mgmt->u.action.u.mesh_action.action_code = MESH_PATH_SEL_ACTION;
109 137
110 switch (action) { 138 switch (action) {
111 case MPATH_PREQ: 139 case MPATH_PREQ:
140 mhwmp_dbg("sending PREQ to %pM\n", target);
112 ie_len = 37; 141 ie_len = 37;
113 pos = skb_put(skb, 2 + ie_len); 142 pos = skb_put(skb, 2 + ie_len);
114 *pos++ = WLAN_EID_PREQ; 143 *pos++ = WLAN_EID_PREQ;
115 break; 144 break;
116 case MPATH_PREP: 145 case MPATH_PREP:
146 mhwmp_dbg("sending PREP to %pM\n", target);
117 ie_len = 31; 147 ie_len = 31;
118 pos = skb_put(skb, 2 + ie_len); 148 pos = skb_put(skb, 2 + ie_len);
119 *pos++ = WLAN_EID_PREP; 149 *pos++ = WLAN_EID_PREP;
120 break; 150 break;
151 case MPATH_RANN:
152 mhwmp_dbg("sending RANN from %pM\n", orig_addr);
153 ie_len = sizeof(struct ieee80211_rann_ie);
154 pos = skb_put(skb, 2 + ie_len);
155 *pos++ = WLAN_EID_RANN;
156 break;
121 default: 157 default:
122 kfree_skb(skb); 158 kfree_skb(skb);
123 return -ENOTSUPP; 159 return -ENOTSUPP;
@@ -133,34 +169,40 @@ static int mesh_path_sel_frame_tx(enum mpath_frame_type action, u8 flags,
133 } 169 }
134 memcpy(pos, orig_addr, ETH_ALEN); 170 memcpy(pos, orig_addr, ETH_ALEN);
135 pos += ETH_ALEN; 171 pos += ETH_ALEN;
136 memcpy(pos, &orig_dsn, 4); 172 memcpy(pos, &orig_sn, 4);
137 pos += 4;
138 memcpy(pos, &lifetime, 4);
139 pos += 4; 173 pos += 4;
174 if (action != MPATH_RANN) {
175 memcpy(pos, &lifetime, 4);
176 pos += 4;
177 }
140 memcpy(pos, &metric, 4); 178 memcpy(pos, &metric, 4);
141 pos += 4; 179 pos += 4;
142 if (action == MPATH_PREQ) { 180 if (action == MPATH_PREQ) {
143 /* destination count */ 181 /* destination count */
144 *pos++ = 1; 182 *pos++ = 1;
145 *pos++ = dst_flags; 183 *pos++ = target_flags;
184 }
185 if (action != MPATH_RANN) {
186 memcpy(pos, target, ETH_ALEN);
187 pos += ETH_ALEN;
188 memcpy(pos, &target_sn, 4);
146 } 189 }
147 memcpy(pos, dst, ETH_ALEN);
148 pos += ETH_ALEN;
149 memcpy(pos, &dst_dsn, 4);
150 190
151 ieee80211_tx_skb(sdata, skb, 1); 191 ieee80211_tx_skb(sdata, skb);
152 return 0; 192 return 0;
153} 193}
154 194
155/** 195/**
156 * mesh_send_path error - Sends a PERR mesh management frame 196 * mesh_send_path error - Sends a PERR mesh management frame
157 * 197 *
158 * @dst: broken destination 198 * @target: broken destination
159 * @dst_dsn: dsn of the broken destination 199 * @target_sn: SN of the broken destination
200 * @target_rcode: reason code for this PERR
160 * @ra: node this frame is addressed to 201 * @ra: node this frame is addressed to
161 */ 202 */
162int mesh_path_error_tx(u8 *dst, __le32 dst_dsn, u8 *ra, 203int mesh_path_error_tx(u8 ttl, u8 *target, __le32 target_sn,
163 struct ieee80211_sub_if_data *sdata) 204 __le16 target_rcode, const u8 *ra,
205 struct ieee80211_sub_if_data *sdata)
164{ 206{
165 struct ieee80211_local *local = sdata->local; 207 struct ieee80211_local *local = sdata->local;
166 struct sk_buff *skb = dev_alloc_skb(local->hw.extra_tx_headroom + 400); 208 struct sk_buff *skb = dev_alloc_skb(local->hw.extra_tx_headroom + 400);
@@ -181,23 +223,35 @@ int mesh_path_error_tx(u8 *dst, __le32 dst_dsn, u8 *ra,
181 IEEE80211_STYPE_ACTION); 223 IEEE80211_STYPE_ACTION);
182 224
183 memcpy(mgmt->da, ra, ETH_ALEN); 225 memcpy(mgmt->da, ra, ETH_ALEN);
184 memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN); 226 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
185 /* BSSID is left zeroed, wildcard value */ 227 /* BSSID is left zeroed, wildcard value */
186 mgmt->u.action.category = MESH_PATH_SEL_CATEGORY; 228 mgmt->u.action.category = MESH_PATH_SEL_CATEGORY;
187 mgmt->u.action.u.mesh_action.action_code = MPATH_PERR; 229 mgmt->u.action.u.mesh_action.action_code = MESH_PATH_SEL_ACTION;
188 ie_len = 12; 230 ie_len = 15;
189 pos = skb_put(skb, 2 + ie_len); 231 pos = skb_put(skb, 2 + ie_len);
190 *pos++ = WLAN_EID_PERR; 232 *pos++ = WLAN_EID_PERR;
191 *pos++ = ie_len; 233 *pos++ = ie_len;
192 /* mode flags, reserved */ 234 /* ttl */
193 *pos++ = 0; 235 *pos++ = MESH_TTL;
194 /* number of destinations */ 236 /* number of destinations */
195 *pos++ = 1; 237 *pos++ = 1;
196 memcpy(pos, dst, ETH_ALEN); 238 /*
239 * flags bit, bit 1 is unset if we know the sequence number and
240 * bit 2 is set if we have a reason code
241 */
242 *pos = 0;
243 if (!target_sn)
244 *pos |= MP_F_USN;
245 if (target_rcode)
246 *pos |= MP_F_RCODE;
247 pos++;
248 memcpy(pos, target, ETH_ALEN);
197 pos += ETH_ALEN; 249 pos += ETH_ALEN;
198 memcpy(pos, &dst_dsn, 4); 250 memcpy(pos, &target_sn, 4);
251 pos += 4;
252 memcpy(pos, &target_rcode, 2);
199 253
200 ieee80211_tx_skb(sdata, skb, 1); 254 ieee80211_tx_skb(sdata, skb);
201 return 0; 255 return 0;
202} 256}
203 257
@@ -269,21 +323,20 @@ static u32 airtime_link_metric_get(struct ieee80211_local *local,
269 */ 323 */
270static u32 hwmp_route_info_get(struct ieee80211_sub_if_data *sdata, 324static u32 hwmp_route_info_get(struct ieee80211_sub_if_data *sdata,
271 struct ieee80211_mgmt *mgmt, 325 struct ieee80211_mgmt *mgmt,
272 u8 *hwmp_ie) 326 u8 *hwmp_ie, enum mpath_frame_type action)
273{ 327{
274 struct ieee80211_local *local = sdata->local; 328 struct ieee80211_local *local = sdata->local;
275 struct mesh_path *mpath; 329 struct mesh_path *mpath;
276 struct sta_info *sta; 330 struct sta_info *sta;
277 bool fresh_info; 331 bool fresh_info;
278 u8 *orig_addr, *ta; 332 u8 *orig_addr, *ta;
279 u32 orig_dsn, orig_metric; 333 u32 orig_sn, orig_metric;
280 unsigned long orig_lifetime, exp_time; 334 unsigned long orig_lifetime, exp_time;
281 u32 last_hop_metric, new_metric; 335 u32 last_hop_metric, new_metric;
282 bool process = true; 336 bool process = true;
283 u8 action = mgmt->u.action.u.mesh_action.action_code;
284 337
285 rcu_read_lock(); 338 rcu_read_lock();
286 sta = sta_info_get(local, mgmt->sa); 339 sta = sta_info_get(sdata, mgmt->sa);
287 if (!sta) { 340 if (!sta) {
288 rcu_read_unlock(); 341 rcu_read_unlock();
289 return 0; 342 return 0;
@@ -296,7 +349,7 @@ static u32 hwmp_route_info_get(struct ieee80211_sub_if_data *sdata,
296 switch (action) { 349 switch (action) {
297 case MPATH_PREQ: 350 case MPATH_PREQ:
298 orig_addr = PREQ_IE_ORIG_ADDR(hwmp_ie); 351 orig_addr = PREQ_IE_ORIG_ADDR(hwmp_ie);
299 orig_dsn = PREQ_IE_ORIG_DSN(hwmp_ie); 352 orig_sn = PREQ_IE_ORIG_SN(hwmp_ie);
300 orig_lifetime = PREQ_IE_LIFETIME(hwmp_ie); 353 orig_lifetime = PREQ_IE_LIFETIME(hwmp_ie);
301 orig_metric = PREQ_IE_METRIC(hwmp_ie); 354 orig_metric = PREQ_IE_METRIC(hwmp_ie);
302 break; 355 break;
@@ -309,7 +362,7 @@ static u32 hwmp_route_info_get(struct ieee80211_sub_if_data *sdata,
309 * information from both PREQ and PREP frames. 362 * information from both PREQ and PREP frames.
310 */ 363 */
311 orig_addr = PREP_IE_ORIG_ADDR(hwmp_ie); 364 orig_addr = PREP_IE_ORIG_ADDR(hwmp_ie);
312 orig_dsn = PREP_IE_ORIG_DSN(hwmp_ie); 365 orig_sn = PREP_IE_ORIG_SN(hwmp_ie);
313 orig_lifetime = PREP_IE_LIFETIME(hwmp_ie); 366 orig_lifetime = PREP_IE_LIFETIME(hwmp_ie);
314 orig_metric = PREP_IE_METRIC(hwmp_ie); 367 orig_metric = PREP_IE_METRIC(hwmp_ie);
315 break; 368 break;
@@ -322,7 +375,7 @@ static u32 hwmp_route_info_get(struct ieee80211_sub_if_data *sdata,
322 new_metric = MAX_METRIC; 375 new_metric = MAX_METRIC;
323 exp_time = TU_TO_EXP_TIME(orig_lifetime); 376 exp_time = TU_TO_EXP_TIME(orig_lifetime);
324 377
325 if (memcmp(orig_addr, sdata->dev->dev_addr, ETH_ALEN) == 0) { 378 if (memcmp(orig_addr, sdata->vif.addr, ETH_ALEN) == 0) {
326 /* This MP is the originator, we are not interested in this 379 /* This MP is the originator, we are not interested in this
327 * frame, except for updating transmitter's path info. 380 * frame, except for updating transmitter's path info.
328 */ 381 */
@@ -335,11 +388,11 @@ static u32 hwmp_route_info_get(struct ieee80211_sub_if_data *sdata,
335 if (mpath->flags & MESH_PATH_FIXED) 388 if (mpath->flags & MESH_PATH_FIXED)
336 fresh_info = false; 389 fresh_info = false;
337 else if ((mpath->flags & MESH_PATH_ACTIVE) && 390 else if ((mpath->flags & MESH_PATH_ACTIVE) &&
338 (mpath->flags & MESH_PATH_DSN_VALID)) { 391 (mpath->flags & MESH_PATH_SN_VALID)) {
339 if (DSN_GT(mpath->dsn, orig_dsn) || 392 if (SN_GT(mpath->sn, orig_sn) ||
340 (mpath->dsn == orig_dsn && 393 (mpath->sn == orig_sn &&
341 action == MPATH_PREQ && 394 action == MPATH_PREQ &&
342 new_metric > mpath->metric)) { 395 new_metric >= mpath->metric)) {
343 process = false; 396 process = false;
344 fresh_info = false; 397 fresh_info = false;
345 } 398 }
@@ -356,9 +409,9 @@ static u32 hwmp_route_info_get(struct ieee80211_sub_if_data *sdata,
356 409
357 if (fresh_info) { 410 if (fresh_info) {
358 mesh_path_assign_nexthop(mpath, sta); 411 mesh_path_assign_nexthop(mpath, sta);
359 mpath->flags |= MESH_PATH_DSN_VALID; 412 mpath->flags |= MESH_PATH_SN_VALID;
360 mpath->metric = new_metric; 413 mpath->metric = new_metric;
361 mpath->dsn = orig_dsn; 414 mpath->sn = orig_sn;
362 mpath->exp_time = time_after(mpath->exp_time, exp_time) 415 mpath->exp_time = time_after(mpath->exp_time, exp_time)
363 ? mpath->exp_time : exp_time; 416 ? mpath->exp_time : exp_time;
364 mesh_path_activate(mpath); 417 mesh_path_activate(mpath);
@@ -397,7 +450,7 @@ static u32 hwmp_route_info_get(struct ieee80211_sub_if_data *sdata,
397 450
398 if (fresh_info) { 451 if (fresh_info) {
399 mesh_path_assign_nexthop(mpath, sta); 452 mesh_path_assign_nexthop(mpath, sta);
400 mpath->flags &= ~MESH_PATH_DSN_VALID; 453 mpath->flags &= ~MESH_PATH_SN_VALID;
401 mpath->metric = last_hop_metric; 454 mpath->metric = last_hop_metric;
402 mpath->exp_time = time_after(mpath->exp_time, exp_time) 455 mpath->exp_time = time_after(mpath->exp_time, exp_time)
403 ? mpath->exp_time : exp_time; 456 ? mpath->exp_time : exp_time;
@@ -419,44 +472,47 @@ static void hwmp_preq_frame_process(struct ieee80211_sub_if_data *sdata,
419{ 472{
420 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; 473 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
421 struct mesh_path *mpath; 474 struct mesh_path *mpath;
422 u8 *dst_addr, *orig_addr; 475 u8 *target_addr, *orig_addr;
423 u8 dst_flags, ttl; 476 u8 target_flags, ttl;
424 u32 orig_dsn, dst_dsn, lifetime; 477 u32 orig_sn, target_sn, lifetime;
425 bool reply = false; 478 bool reply = false;
426 bool forward = true; 479 bool forward = true;
427 480
428 /* Update destination DSN, if present */ 481 /* Update target SN, if present */
429 dst_addr = PREQ_IE_DST_ADDR(preq_elem); 482 target_addr = PREQ_IE_TARGET_ADDR(preq_elem);
430 orig_addr = PREQ_IE_ORIG_ADDR(preq_elem); 483 orig_addr = PREQ_IE_ORIG_ADDR(preq_elem);
431 dst_dsn = PREQ_IE_DST_DSN(preq_elem); 484 target_sn = PREQ_IE_TARGET_SN(preq_elem);
432 orig_dsn = PREQ_IE_ORIG_DSN(preq_elem); 485 orig_sn = PREQ_IE_ORIG_SN(preq_elem);
433 dst_flags = PREQ_IE_DST_F(preq_elem); 486 target_flags = PREQ_IE_TARGET_F(preq_elem);
434 487
435 if (memcmp(dst_addr, sdata->dev->dev_addr, ETH_ALEN) == 0) { 488 mhwmp_dbg("received PREQ from %pM\n", orig_addr);
489
490 if (memcmp(target_addr, sdata->vif.addr, ETH_ALEN) == 0) {
491 mhwmp_dbg("PREQ is for us\n");
436 forward = false; 492 forward = false;
437 reply = true; 493 reply = true;
438 metric = 0; 494 metric = 0;
439 if (time_after(jiffies, ifmsh->last_dsn_update + 495 if (time_after(jiffies, ifmsh->last_sn_update +
440 net_traversal_jiffies(sdata)) || 496 net_traversal_jiffies(sdata)) ||
441 time_before(jiffies, ifmsh->last_dsn_update)) { 497 time_before(jiffies, ifmsh->last_sn_update)) {
442 dst_dsn = ++ifmsh->dsn; 498 target_sn = ++ifmsh->sn;
443 ifmsh->last_dsn_update = jiffies; 499 ifmsh->last_sn_update = jiffies;
444 } 500 }
445 } else { 501 } else {
446 rcu_read_lock(); 502 rcu_read_lock();
447 mpath = mesh_path_lookup(dst_addr, sdata); 503 mpath = mesh_path_lookup(target_addr, sdata);
448 if (mpath) { 504 if (mpath) {
449 if ((!(mpath->flags & MESH_PATH_DSN_VALID)) || 505 if ((!(mpath->flags & MESH_PATH_SN_VALID)) ||
450 DSN_LT(mpath->dsn, dst_dsn)) { 506 SN_LT(mpath->sn, target_sn)) {
451 mpath->dsn = dst_dsn; 507 mpath->sn = target_sn;
452 mpath->flags |= MESH_PATH_DSN_VALID; 508 mpath->flags |= MESH_PATH_SN_VALID;
453 } else if ((!(dst_flags & MP_F_DO)) && 509 } else if ((!(target_flags & MP_F_DO)) &&
454 (mpath->flags & MESH_PATH_ACTIVE)) { 510 (mpath->flags & MESH_PATH_ACTIVE)) {
455 reply = true; 511 reply = true;
456 metric = mpath->metric; 512 metric = mpath->metric;
457 dst_dsn = mpath->dsn; 513 target_sn = mpath->sn;
458 if (dst_flags & MP_F_RF) 514 if (target_flags & MP_F_RF)
459 dst_flags |= MP_F_DO; 515 target_flags |= MP_F_DO;
460 else 516 else
461 forward = false; 517 forward = false;
462 } 518 }
@@ -467,13 +523,14 @@ static void hwmp_preq_frame_process(struct ieee80211_sub_if_data *sdata,
467 if (reply) { 523 if (reply) {
468 lifetime = PREQ_IE_LIFETIME(preq_elem); 524 lifetime = PREQ_IE_LIFETIME(preq_elem);
469 ttl = ifmsh->mshcfg.dot11MeshTTL; 525 ttl = ifmsh->mshcfg.dot11MeshTTL;
470 if (ttl != 0) 526 if (ttl != 0) {
471 mesh_path_sel_frame_tx(MPATH_PREP, 0, dst_addr, 527 mhwmp_dbg("replying to the PREQ\n");
472 cpu_to_le32(dst_dsn), 0, orig_addr, 528 mesh_path_sel_frame_tx(MPATH_PREP, 0, target_addr,
473 cpu_to_le32(orig_dsn), mgmt->sa, 0, ttl, 529 cpu_to_le32(target_sn), 0, orig_addr,
530 cpu_to_le32(orig_sn), mgmt->sa, 0, ttl,
474 cpu_to_le32(lifetime), cpu_to_le32(metric), 531 cpu_to_le32(lifetime), cpu_to_le32(metric),
475 0, sdata); 532 0, sdata);
476 else 533 } else
477 ifmsh->mshstats.dropped_frames_ttl++; 534 ifmsh->mshstats.dropped_frames_ttl++;
478 } 535 }
479 536
@@ -487,13 +544,14 @@ static void hwmp_preq_frame_process(struct ieee80211_sub_if_data *sdata,
487 ifmsh->mshstats.dropped_frames_ttl++; 544 ifmsh->mshstats.dropped_frames_ttl++;
488 return; 545 return;
489 } 546 }
547 mhwmp_dbg("forwarding the PREQ from %pM\n", orig_addr);
490 --ttl; 548 --ttl;
491 flags = PREQ_IE_FLAGS(preq_elem); 549 flags = PREQ_IE_FLAGS(preq_elem);
492 preq_id = PREQ_IE_PREQ_ID(preq_elem); 550 preq_id = PREQ_IE_PREQ_ID(preq_elem);
493 hopcount = PREQ_IE_HOPCOUNT(preq_elem) + 1; 551 hopcount = PREQ_IE_HOPCOUNT(preq_elem) + 1;
494 mesh_path_sel_frame_tx(MPATH_PREQ, flags, orig_addr, 552 mesh_path_sel_frame_tx(MPATH_PREQ, flags, orig_addr,
495 cpu_to_le32(orig_dsn), dst_flags, dst_addr, 553 cpu_to_le32(orig_sn), target_flags, target_addr,
496 cpu_to_le32(dst_dsn), sdata->dev->broadcast, 554 cpu_to_le32(target_sn), broadcast_addr,
497 hopcount, ttl, cpu_to_le32(lifetime), 555 hopcount, ttl, cpu_to_le32(lifetime),
498 cpu_to_le32(metric), cpu_to_le32(preq_id), 556 cpu_to_le32(metric), cpu_to_le32(preq_id),
499 sdata); 557 sdata);
@@ -508,10 +566,12 @@ static void hwmp_prep_frame_process(struct ieee80211_sub_if_data *sdata,
508 u8 *prep_elem, u32 metric) 566 u8 *prep_elem, u32 metric)
509{ 567{
510 struct mesh_path *mpath; 568 struct mesh_path *mpath;
511 u8 *dst_addr, *orig_addr; 569 u8 *target_addr, *orig_addr;
512 u8 ttl, hopcount, flags; 570 u8 ttl, hopcount, flags;
513 u8 next_hop[ETH_ALEN]; 571 u8 next_hop[ETH_ALEN];
514 u32 dst_dsn, orig_dsn, lifetime; 572 u32 target_sn, orig_sn, lifetime;
573
574 mhwmp_dbg("received PREP from %pM\n", PREP_IE_ORIG_ADDR(prep_elem));
515 575
516 /* Note that we divert from the draft nomenclature and denominate 576 /* Note that we divert from the draft nomenclature and denominate
517 * destination to what the draft refers to as origininator. So in this 577 * destination to what the draft refers to as origininator. So in this
@@ -519,8 +579,8 @@ static void hwmp_prep_frame_process(struct ieee80211_sub_if_data *sdata,
519 * which corresponds with the originator of the PREQ which this PREP 579 * which corresponds with the originator of the PREQ which this PREP
520 * replies 580 * replies
521 */ 581 */
522 dst_addr = PREP_IE_DST_ADDR(prep_elem); 582 target_addr = PREP_IE_TARGET_ADDR(prep_elem);
523 if (memcmp(dst_addr, sdata->dev->dev_addr, ETH_ALEN) == 0) 583 if (memcmp(target_addr, sdata->vif.addr, ETH_ALEN) == 0)
524 /* destination, no forwarding required */ 584 /* destination, no forwarding required */
525 return; 585 return;
526 586
@@ -531,7 +591,7 @@ static void hwmp_prep_frame_process(struct ieee80211_sub_if_data *sdata,
531 } 591 }
532 592
533 rcu_read_lock(); 593 rcu_read_lock();
534 mpath = mesh_path_lookup(dst_addr, sdata); 594 mpath = mesh_path_lookup(target_addr, sdata);
535 if (mpath) 595 if (mpath)
536 spin_lock_bh(&mpath->state_lock); 596 spin_lock_bh(&mpath->state_lock);
537 else 597 else
@@ -547,13 +607,13 @@ static void hwmp_prep_frame_process(struct ieee80211_sub_if_data *sdata,
547 lifetime = PREP_IE_LIFETIME(prep_elem); 607 lifetime = PREP_IE_LIFETIME(prep_elem);
548 hopcount = PREP_IE_HOPCOUNT(prep_elem) + 1; 608 hopcount = PREP_IE_HOPCOUNT(prep_elem) + 1;
549 orig_addr = PREP_IE_ORIG_ADDR(prep_elem); 609 orig_addr = PREP_IE_ORIG_ADDR(prep_elem);
550 dst_dsn = PREP_IE_DST_DSN(prep_elem); 610 target_sn = PREP_IE_TARGET_SN(prep_elem);
551 orig_dsn = PREP_IE_ORIG_DSN(prep_elem); 611 orig_sn = PREP_IE_ORIG_SN(prep_elem);
552 612
553 mesh_path_sel_frame_tx(MPATH_PREP, flags, orig_addr, 613 mesh_path_sel_frame_tx(MPATH_PREP, flags, orig_addr,
554 cpu_to_le32(orig_dsn), 0, dst_addr, 614 cpu_to_le32(orig_sn), 0, target_addr,
555 cpu_to_le32(dst_dsn), mpath->next_hop->sta.addr, hopcount, ttl, 615 cpu_to_le32(target_sn), next_hop, hopcount,
556 cpu_to_le32(lifetime), cpu_to_le32(metric), 616 ttl, cpu_to_le32(lifetime), cpu_to_le32(metric),
557 0, sdata); 617 0, sdata);
558 rcu_read_unlock(); 618 rcu_read_unlock();
559 619
@@ -570,32 +630,96 @@ fail:
570static void hwmp_perr_frame_process(struct ieee80211_sub_if_data *sdata, 630static void hwmp_perr_frame_process(struct ieee80211_sub_if_data *sdata,
571 struct ieee80211_mgmt *mgmt, u8 *perr_elem) 631 struct ieee80211_mgmt *mgmt, u8 *perr_elem)
572{ 632{
633 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
573 struct mesh_path *mpath; 634 struct mesh_path *mpath;
574 u8 *ta, *dst_addr; 635 u8 ttl;
575 u32 dst_dsn; 636 u8 *ta, *target_addr;
637 u8 target_flags;
638 u32 target_sn;
639 u16 target_rcode;
576 640
577 ta = mgmt->sa; 641 ta = mgmt->sa;
578 dst_addr = PERR_IE_DST_ADDR(perr_elem); 642 ttl = PERR_IE_TTL(perr_elem);
579 dst_dsn = PERR_IE_DST_DSN(perr_elem); 643 if (ttl <= 1) {
644 ifmsh->mshstats.dropped_frames_ttl++;
645 return;
646 }
647 ttl--;
648 target_flags = PERR_IE_TARGET_FLAGS(perr_elem);
649 target_addr = PERR_IE_TARGET_ADDR(perr_elem);
650 target_sn = PERR_IE_TARGET_SN(perr_elem);
651 target_rcode = PERR_IE_TARGET_RCODE(perr_elem);
652
580 rcu_read_lock(); 653 rcu_read_lock();
581 mpath = mesh_path_lookup(dst_addr, sdata); 654 mpath = mesh_path_lookup(target_addr, sdata);
582 if (mpath) { 655 if (mpath) {
583 spin_lock_bh(&mpath->state_lock); 656 spin_lock_bh(&mpath->state_lock);
584 if (mpath->flags & MESH_PATH_ACTIVE && 657 if (mpath->flags & MESH_PATH_ACTIVE &&
585 memcmp(ta, mpath->next_hop->sta.addr, ETH_ALEN) == 0 && 658 memcmp(ta, mpath->next_hop->sta.addr, ETH_ALEN) == 0 &&
586 (!(mpath->flags & MESH_PATH_DSN_VALID) || 659 (!(mpath->flags & MESH_PATH_SN_VALID) ||
587 DSN_GT(dst_dsn, mpath->dsn))) { 660 SN_GT(target_sn, mpath->sn))) {
588 mpath->flags &= ~MESH_PATH_ACTIVE; 661 mpath->flags &= ~MESH_PATH_ACTIVE;
589 mpath->dsn = dst_dsn; 662 mpath->sn = target_sn;
590 spin_unlock_bh(&mpath->state_lock); 663 spin_unlock_bh(&mpath->state_lock);
591 mesh_path_error_tx(dst_addr, cpu_to_le32(dst_dsn), 664 mesh_path_error_tx(ttl, target_addr, cpu_to_le32(target_sn),
592 sdata->dev->broadcast, sdata); 665 cpu_to_le16(target_rcode),
666 broadcast_addr, sdata);
593 } else 667 } else
594 spin_unlock_bh(&mpath->state_lock); 668 spin_unlock_bh(&mpath->state_lock);
595 } 669 }
596 rcu_read_unlock(); 670 rcu_read_unlock();
597} 671}
598 672
673static void hwmp_rann_frame_process(struct ieee80211_sub_if_data *sdata,
674 struct ieee80211_mgmt *mgmt,
675 struct ieee80211_rann_ie *rann)
676{
677 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
678 struct mesh_path *mpath;
679 u8 *ta;
680 u8 ttl, flags, hopcount;
681 u8 *orig_addr;
682 u32 orig_sn, metric;
683
684 ta = mgmt->sa;
685 ttl = rann->rann_ttl;
686 if (ttl <= 1) {
687 ifmsh->mshstats.dropped_frames_ttl++;
688 return;
689 }
690 ttl--;
691 flags = rann->rann_flags;
692 orig_addr = rann->rann_addr;
693 orig_sn = rann->rann_seq;
694 hopcount = rann->rann_hopcount;
695 hopcount++;
696 metric = rann->rann_metric;
697 mhwmp_dbg("received RANN from %pM\n", orig_addr);
698
699 rcu_read_lock();
700 mpath = mesh_path_lookup(orig_addr, sdata);
701 if (!mpath) {
702 mesh_path_add(orig_addr, sdata);
703 mpath = mesh_path_lookup(orig_addr, sdata);
704 if (!mpath) {
705 rcu_read_unlock();
706 sdata->u.mesh.mshstats.dropped_frames_no_route++;
707 return;
708 }
709 mesh_queue_preq(mpath,
710 PREQ_Q_F_START | PREQ_Q_F_REFRESH);
711 }
712 if (mpath->sn < orig_sn) {
713 mesh_path_sel_frame_tx(MPATH_RANN, flags, orig_addr,
714 cpu_to_le32(orig_sn),
715 0, NULL, 0, broadcast_addr,
716 hopcount, ttl, 0,
717 cpu_to_le32(metric + mpath->metric),
718 0, sdata);
719 mpath->sn = orig_sn;
720 }
721 rcu_read_unlock();
722}
599 723
600 724
601void mesh_rx_path_sel_frame(struct ieee80211_sub_if_data *sdata, 725void mesh_rx_path_sel_frame(struct ieee80211_sub_if_data *sdata,
@@ -614,34 +738,34 @@ void mesh_rx_path_sel_frame(struct ieee80211_sub_if_data *sdata,
614 ieee802_11_parse_elems(mgmt->u.action.u.mesh_action.variable, 738 ieee802_11_parse_elems(mgmt->u.action.u.mesh_action.variable,
615 len - baselen, &elems); 739 len - baselen, &elems);
616 740
617 switch (mgmt->u.action.u.mesh_action.action_code) { 741 if (elems.preq) {
618 case MPATH_PREQ: 742 if (elems.preq_len != 37)
619 if (!elems.preq || elems.preq_len != 37)
620 /* Right now we support just 1 destination and no AE */ 743 /* Right now we support just 1 destination and no AE */
621 return; 744 return;
622 last_hop_metric = hwmp_route_info_get(sdata, mgmt, elems.preq); 745 last_hop_metric = hwmp_route_info_get(sdata, mgmt, elems.preq,
623 if (!last_hop_metric) 746 MPATH_PREQ);
624 return; 747 if (last_hop_metric)
625 hwmp_preq_frame_process(sdata, mgmt, elems.preq, last_hop_metric); 748 hwmp_preq_frame_process(sdata, mgmt, elems.preq,
626 break; 749 last_hop_metric);
627 case MPATH_PREP: 750 }
628 if (!elems.prep || elems.prep_len != 31) 751 if (elems.prep) {
752 if (elems.prep_len != 31)
629 /* Right now we support no AE */ 753 /* Right now we support no AE */
630 return; 754 return;
631 last_hop_metric = hwmp_route_info_get(sdata, mgmt, elems.prep); 755 last_hop_metric = hwmp_route_info_get(sdata, mgmt, elems.prep,
632 if (!last_hop_metric) 756 MPATH_PREP);
633 return; 757 if (last_hop_metric)
634 hwmp_prep_frame_process(sdata, mgmt, elems.prep, last_hop_metric); 758 hwmp_prep_frame_process(sdata, mgmt, elems.prep,
635 break; 759 last_hop_metric);
636 case MPATH_PERR: 760 }
637 if (!elems.perr || elems.perr_len != 12) 761 if (elems.perr) {
762 if (elems.perr_len != 15)
638 /* Right now we support only one destination per PERR */ 763 /* Right now we support only one destination per PERR */
639 return; 764 return;
640 hwmp_perr_frame_process(sdata, mgmt, elems.perr); 765 hwmp_perr_frame_process(sdata, mgmt, elems.perr);
641 default:
642 return;
643 } 766 }
644 767 if (elems.rann)
768 hwmp_rann_frame_process(sdata, mgmt, elems.rann);
645} 769}
646 770
647/** 771/**
@@ -661,7 +785,7 @@ static void mesh_queue_preq(struct mesh_path *mpath, u8 flags)
661 785
662 preq_node = kmalloc(sizeof(struct mesh_preq_queue), GFP_ATOMIC); 786 preq_node = kmalloc(sizeof(struct mesh_preq_queue), GFP_ATOMIC);
663 if (!preq_node) { 787 if (!preq_node) {
664 printk(KERN_DEBUG "Mesh HWMP: could not allocate PREQ node\n"); 788 mhwmp_dbg("could not allocate PREQ node\n");
665 return; 789 return;
666 } 790 }
667 791
@@ -670,7 +794,7 @@ static void mesh_queue_preq(struct mesh_path *mpath, u8 flags)
670 spin_unlock(&ifmsh->mesh_preq_queue_lock); 794 spin_unlock(&ifmsh->mesh_preq_queue_lock);
671 kfree(preq_node); 795 kfree(preq_node);
672 if (printk_ratelimit()) 796 if (printk_ratelimit())
673 printk(KERN_DEBUG "Mesh HWMP: PREQ node queue full\n"); 797 mhwmp_dbg("PREQ node queue full\n");
674 return; 798 return;
675 } 799 }
676 800
@@ -705,7 +829,7 @@ void mesh_path_start_discovery(struct ieee80211_sub_if_data *sdata)
705 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; 829 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
706 struct mesh_preq_queue *preq_node; 830 struct mesh_preq_queue *preq_node;
707 struct mesh_path *mpath; 831 struct mesh_path *mpath;
708 u8 ttl, dst_flags; 832 u8 ttl, target_flags;
709 u32 lifetime; 833 u32 lifetime;
710 834
711 spin_lock_bh(&ifmsh->mesh_preq_queue_lock); 835 spin_lock_bh(&ifmsh->mesh_preq_queue_lock);
@@ -747,11 +871,11 @@ void mesh_path_start_discovery(struct ieee80211_sub_if_data *sdata)
747 871
748 ifmsh->last_preq = jiffies; 872 ifmsh->last_preq = jiffies;
749 873
750 if (time_after(jiffies, ifmsh->last_dsn_update + 874 if (time_after(jiffies, ifmsh->last_sn_update +
751 net_traversal_jiffies(sdata)) || 875 net_traversal_jiffies(sdata)) ||
752 time_before(jiffies, ifmsh->last_dsn_update)) { 876 time_before(jiffies, ifmsh->last_sn_update)) {
753 ++ifmsh->dsn; 877 ++ifmsh->sn;
754 sdata->u.mesh.last_dsn_update = jiffies; 878 sdata->u.mesh.last_sn_update = jiffies;
755 } 879 }
756 lifetime = default_lifetime(sdata); 880 lifetime = default_lifetime(sdata);
757 ttl = sdata->u.mesh.mshcfg.dot11MeshTTL; 881 ttl = sdata->u.mesh.mshcfg.dot11MeshTTL;
@@ -762,14 +886,14 @@ void mesh_path_start_discovery(struct ieee80211_sub_if_data *sdata)
762 } 886 }
763 887
764 if (preq_node->flags & PREQ_Q_F_REFRESH) 888 if (preq_node->flags & PREQ_Q_F_REFRESH)
765 dst_flags = MP_F_DO; 889 target_flags = MP_F_DO;
766 else 890 else
767 dst_flags = MP_F_RF; 891 target_flags = MP_F_RF;
768 892
769 spin_unlock_bh(&mpath->state_lock); 893 spin_unlock_bh(&mpath->state_lock);
770 mesh_path_sel_frame_tx(MPATH_PREQ, 0, sdata->dev->dev_addr, 894 mesh_path_sel_frame_tx(MPATH_PREQ, 0, sdata->vif.addr,
771 cpu_to_le32(ifmsh->dsn), dst_flags, mpath->dst, 895 cpu_to_le32(ifmsh->sn), target_flags, mpath->dst,
772 cpu_to_le32(mpath->dsn), sdata->dev->broadcast, 0, 896 cpu_to_le32(mpath->sn), broadcast_addr, 0,
773 ttl, cpu_to_le32(lifetime), 0, 897 ttl, cpu_to_le32(lifetime), 0,
774 cpu_to_le32(ifmsh->preq_id++), sdata); 898 cpu_to_le32(ifmsh->preq_id++), sdata);
775 mod_timer(&mpath->timer, jiffies + mpath->discovery_timeout); 899 mod_timer(&mpath->timer, jiffies + mpath->discovery_timeout);
@@ -796,15 +920,15 @@ int mesh_nexthop_lookup(struct sk_buff *skb,
796 struct sk_buff *skb_to_free = NULL; 920 struct sk_buff *skb_to_free = NULL;
797 struct mesh_path *mpath; 921 struct mesh_path *mpath;
798 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; 922 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
799 u8 *dst_addr = hdr->addr3; 923 u8 *target_addr = hdr->addr3;
800 int err = 0; 924 int err = 0;
801 925
802 rcu_read_lock(); 926 rcu_read_lock();
803 mpath = mesh_path_lookup(dst_addr, sdata); 927 mpath = mesh_path_lookup(target_addr, sdata);
804 928
805 if (!mpath) { 929 if (!mpath) {
806 mesh_path_add(dst_addr, sdata); 930 mesh_path_add(target_addr, sdata);
807 mpath = mesh_path_lookup(dst_addr, sdata); 931 mpath = mesh_path_lookup(target_addr, sdata);
808 if (!mpath) { 932 if (!mpath) {
809 sdata->u.mesh.mshstats.dropped_frames_no_route++; 933 sdata->u.mesh.mshstats.dropped_frames_no_route++;
810 err = -ENOSPC; 934 err = -ENOSPC;
@@ -813,17 +937,16 @@ int mesh_nexthop_lookup(struct sk_buff *skb,
813 } 937 }
814 938
815 if (mpath->flags & MESH_PATH_ACTIVE) { 939 if (mpath->flags & MESH_PATH_ACTIVE) {
816 if (time_after(jiffies, mpath->exp_time + 940 if (time_after(jiffies,
817 msecs_to_jiffies(sdata->u.mesh.mshcfg.path_refresh_time)) 941 mpath->exp_time -
818 && !memcmp(sdata->dev->dev_addr, hdr->addr4, 942 msecs_to_jiffies(sdata->u.mesh.mshcfg.path_refresh_time)) &&
819 ETH_ALEN) 943 !memcmp(sdata->vif.addr, hdr->addr4, ETH_ALEN) &&
820 && !(mpath->flags & MESH_PATH_RESOLVING) 944 !(mpath->flags & MESH_PATH_RESOLVING) &&
821 && !(mpath->flags & MESH_PATH_FIXED)) { 945 !(mpath->flags & MESH_PATH_FIXED)) {
822 mesh_queue_preq(mpath, 946 mesh_queue_preq(mpath,
823 PREQ_Q_F_START | PREQ_Q_F_REFRESH); 947 PREQ_Q_F_START | PREQ_Q_F_REFRESH);
824 } 948 }
825 memcpy(hdr->addr1, mpath->next_hop->sta.addr, 949 memcpy(hdr->addr1, mpath->next_hop->sta.addr, ETH_ALEN);
826 ETH_ALEN);
827 } else { 950 } else {
828 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); 951 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
829 if (!(mpath->flags & MESH_PATH_RESOLVING)) { 952 if (!(mpath->flags & MESH_PATH_RESOLVING)) {
@@ -882,3 +1005,14 @@ void mesh_path_timer(unsigned long data)
882endmpathtimer: 1005endmpathtimer:
883 rcu_read_unlock(); 1006 rcu_read_unlock();
884} 1007}
1008
1009void
1010mesh_path_tx_root_frame(struct ieee80211_sub_if_data *sdata)
1011{
1012 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
1013
1014 mesh_path_sel_frame_tx(MPATH_RANN, 0, sdata->vif.addr,
1015 cpu_to_le32(++ifmsh->sn),
1016 0, NULL, 0, broadcast_addr,
1017 0, MESH_TTL, 0, 0, 0, sdata);
1018}
diff --git a/net/mac80211/mesh_pathtbl.c b/net/mac80211/mesh_pathtbl.c
index 751c4d0e2b36..181ffd6efd81 100644
--- a/net/mac80211/mesh_pathtbl.c
+++ b/net/mac80211/mesh_pathtbl.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (c) 2008 open80211s Ltd. 2 * Copyright (c) 2008, 2009 open80211s Ltd.
3 * Author: Luis Carlos Cobo <luisca@cozybit.com> 3 * Author: Luis Carlos Cobo <luisca@cozybit.com>
4 * 4 *
5 * This program is free software; you can redistribute it and/or modify 5 * This program is free software; you can redistribute it and/or modify
@@ -10,6 +10,7 @@
10#include <linux/etherdevice.h> 10#include <linux/etherdevice.h>
11#include <linux/list.h> 11#include <linux/list.h>
12#include <linux/random.h> 12#include <linux/random.h>
13#include <linux/slab.h>
13#include <linux/spinlock.h> 14#include <linux/spinlock.h>
14#include <linux/string.h> 15#include <linux/string.h>
15#include <net/mac80211.h> 16#include <net/mac80211.h>
@@ -244,7 +245,7 @@ struct mesh_path *mesh_path_lookup_by_idx(int idx, struct ieee80211_sub_if_data
244 * @addr: destination address of the path (ETH_ALEN length) 245 * @addr: destination address of the path (ETH_ALEN length)
245 * @sdata: local subif 246 * @sdata: local subif
246 * 247 *
247 * Returns: 0 on sucess 248 * Returns: 0 on success
248 * 249 *
249 * State: the initial state of the new path is set to 0 250 * State: the initial state of the new path is set to 0
250 */ 251 */
@@ -260,7 +261,7 @@ int mesh_path_add(u8 *dst, struct ieee80211_sub_if_data *sdata)
260 int err = 0; 261 int err = 0;
261 u32 hash_idx; 262 u32 hash_idx;
262 263
263 if (memcmp(dst, sdata->dev->dev_addr, ETH_ALEN) == 0) 264 if (memcmp(dst, sdata->vif.addr, ETH_ALEN) == 0)
264 /* never add ourselves as neighbours */ 265 /* never add ourselves as neighbours */
265 return -ENOTSUPP; 266 return -ENOTSUPP;
266 267
@@ -377,7 +378,7 @@ int mpp_path_add(u8 *dst, u8 *mpp, struct ieee80211_sub_if_data *sdata)
377 int err = 0; 378 int err = 0;
378 u32 hash_idx; 379 u32 hash_idx;
379 380
380 if (memcmp(dst, sdata->dev->dev_addr, ETH_ALEN) == 0) 381 if (memcmp(dst, sdata->vif.addr, ETH_ALEN) == 0)
381 /* never add ourselves as neighbours */ 382 /* never add ourselves as neighbours */
382 return -ENOTSUPP; 383 return -ENOTSUPP;
383 384
@@ -449,6 +450,7 @@ err_path_alloc:
449 */ 450 */
450void mesh_plink_broken(struct sta_info *sta) 451void mesh_plink_broken(struct sta_info *sta)
451{ 452{
453 static const u8 bcast[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
452 struct mesh_path *mpath; 454 struct mesh_path *mpath;
453 struct mpath_node *node; 455 struct mpath_node *node;
454 struct hlist_node *p; 456 struct hlist_node *p;
@@ -463,11 +465,12 @@ void mesh_plink_broken(struct sta_info *sta)
463 mpath->flags & MESH_PATH_ACTIVE && 465 mpath->flags & MESH_PATH_ACTIVE &&
464 !(mpath->flags & MESH_PATH_FIXED)) { 466 !(mpath->flags & MESH_PATH_FIXED)) {
465 mpath->flags &= ~MESH_PATH_ACTIVE; 467 mpath->flags &= ~MESH_PATH_ACTIVE;
466 ++mpath->dsn; 468 ++mpath->sn;
467 spin_unlock_bh(&mpath->state_lock); 469 spin_unlock_bh(&mpath->state_lock);
468 mesh_path_error_tx(mpath->dst, 470 mesh_path_error_tx(MESH_TTL, mpath->dst,
469 cpu_to_le32(mpath->dsn), 471 cpu_to_le32(mpath->sn),
470 sdata->dev->broadcast, sdata); 472 cpu_to_le16(PERR_RCODE_DEST_UNREACH),
473 bcast, sdata);
471 } else 474 } else
472 spin_unlock_bh(&mpath->state_lock); 475 spin_unlock_bh(&mpath->state_lock);
473 } 476 }
@@ -530,7 +533,7 @@ static void mesh_path_node_reclaim(struct rcu_head *rp)
530 * @addr: dst address (ETH_ALEN length) 533 * @addr: dst address (ETH_ALEN length)
531 * @sdata: local subif 534 * @sdata: local subif
532 * 535 *
533 * Returns: 0 if succesful 536 * Returns: 0 if successful
534 */ 537 */
535int mesh_path_del(u8 *addr, struct ieee80211_sub_if_data *sdata) 538int mesh_path_del(u8 *addr, struct ieee80211_sub_if_data *sdata)
536{ 539{
@@ -601,17 +604,18 @@ void mesh_path_discard_frame(struct sk_buff *skb,
601{ 604{
602 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; 605 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
603 struct mesh_path *mpath; 606 struct mesh_path *mpath;
604 u32 dsn = 0; 607 u32 sn = 0;
605 608
606 if (memcmp(hdr->addr4, sdata->dev->dev_addr, ETH_ALEN) != 0) { 609 if (memcmp(hdr->addr4, sdata->vif.addr, ETH_ALEN) != 0) {
607 u8 *ra, *da; 610 u8 *ra, *da;
608 611
609 da = hdr->addr3; 612 da = hdr->addr3;
610 ra = hdr->addr1; 613 ra = hdr->addr1;
611 mpath = mesh_path_lookup(da, sdata); 614 mpath = mesh_path_lookup(da, sdata);
612 if (mpath) 615 if (mpath)
613 dsn = ++mpath->dsn; 616 sn = ++mpath->sn;
614 mesh_path_error_tx(skb->data, cpu_to_le32(dsn), ra, sdata); 617 mesh_path_error_tx(MESH_TTL, skb->data, cpu_to_le32(sn),
618 cpu_to_le16(PERR_RCODE_NO_ROUTE), ra, sdata);
615 } 619 }
616 620
617 kfree_skb(skb); 621 kfree_skb(skb);
@@ -646,7 +650,7 @@ void mesh_path_fix_nexthop(struct mesh_path *mpath, struct sta_info *next_hop)
646{ 650{
647 spin_lock_bh(&mpath->state_lock); 651 spin_lock_bh(&mpath->state_lock);
648 mesh_path_assign_nexthop(mpath, next_hop); 652 mesh_path_assign_nexthop(mpath, next_hop);
649 mpath->dsn = 0xffff; 653 mpath->sn = 0xffff;
650 mpath->metric = 0; 654 mpath->metric = 0;
651 mpath->hop_count = 0; 655 mpath->hop_count = 0;
652 mpath->exp_time = 0; 656 mpath->exp_time = 0;
diff --git a/net/mac80211/mesh_plink.c b/net/mac80211/mesh_plink.c
index ffcbad75e09b..7b7080e2b49f 100644
--- a/net/mac80211/mesh_plink.c
+++ b/net/mac80211/mesh_plink.c
@@ -1,11 +1,12 @@
1/* 1/*
2 * Copyright (c) 2008 open80211s Ltd. 2 * Copyright (c) 2008, 2009 open80211s Ltd.
3 * Author: Luis Carlos Cobo <luisca@cozybit.com> 3 * Author: Luis Carlos Cobo <luisca@cozybit.com>
4 * 4 *
5 * This program is free software; you can redistribute it and/or modify 5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as 6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 */ 8 */
9#include <linux/gfp.h>
9#include <linux/kernel.h> 10#include <linux/kernel.h>
10#include <linux/random.h> 11#include <linux/random.h>
11#include "ieee80211_i.h" 12#include "ieee80211_i.h"
@@ -18,9 +19,8 @@
18#define mpl_dbg(fmt, args...) do { (void)(0); } while (0) 19#define mpl_dbg(fmt, args...) do { (void)(0); } while (0)
19#endif 20#endif
20 21
21#define PLINK_GET_FRAME_SUBTYPE(p) (p) 22#define PLINK_GET_LLID(p) (p + 4)
22#define PLINK_GET_LLID(p) (p + 1) 23#define PLINK_GET_PLID(p) (p + 6)
23#define PLINK_GET_PLID(p) (p + 3)
24 24
25#define mod_plink_timer(s, t) (mod_timer(&s->plink_timer, \ 25#define mod_plink_timer(s, t) (mod_timer(&s->plink_timer, \
26 jiffies + HZ * t / 1000)) 26 jiffies + HZ * t / 1000))
@@ -65,6 +65,7 @@ void mesh_plink_inc_estab_count(struct ieee80211_sub_if_data *sdata)
65{ 65{
66 atomic_inc(&sdata->u.mesh.mshstats.estab_plinks); 66 atomic_inc(&sdata->u.mesh.mshstats.estab_plinks);
67 mesh_accept_plinks_update(sdata); 67 mesh_accept_plinks_update(sdata);
68 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON);
68} 69}
69 70
70static inline 71static inline
@@ -72,12 +73,13 @@ void mesh_plink_dec_estab_count(struct ieee80211_sub_if_data *sdata)
72{ 73{
73 atomic_dec(&sdata->u.mesh.mshstats.estab_plinks); 74 atomic_dec(&sdata->u.mesh.mshstats.estab_plinks);
74 mesh_accept_plinks_update(sdata); 75 mesh_accept_plinks_update(sdata);
76 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON);
75} 77}
76 78
77/** 79/**
78 * mesh_plink_fsm_restart - restart a mesh peer link finite state machine 80 * mesh_plink_fsm_restart - restart a mesh peer link finite state machine
79 * 81 *
80 * @sta: mes peer link to restart 82 * @sta: mesh peer link to restart
81 * 83 *
82 * Locking: this function must be called holding sta->lock 84 * Locking: this function must be called holding sta->lock
83 */ 85 */
@@ -101,7 +103,7 @@ static struct sta_info *mesh_plink_alloc(struct ieee80211_sub_if_data *sdata,
101 if (local->num_sta >= MESH_MAX_PLINKS) 103 if (local->num_sta >= MESH_MAX_PLINKS)
102 return NULL; 104 return NULL;
103 105
104 sta = sta_info_alloc(sdata, hw_addr, GFP_ATOMIC); 106 sta = sta_info_alloc(sdata, hw_addr, GFP_KERNEL);
105 if (!sta) 107 if (!sta)
106 return NULL; 108 return NULL;
107 109
@@ -152,6 +154,7 @@ static int mesh_plink_frame_tx(struct ieee80211_sub_if_data *sdata,
152 struct sk_buff *skb = dev_alloc_skb(local->hw.extra_tx_headroom + 400); 154 struct sk_buff *skb = dev_alloc_skb(local->hw.extra_tx_headroom + 400);
153 struct ieee80211_mgmt *mgmt; 155 struct ieee80211_mgmt *mgmt;
154 bool include_plid = false; 156 bool include_plid = false;
157 static const u8 meshpeeringproto[] = { 0x00, 0x0F, 0xAC, 0x2A };
155 u8 *pos; 158 u8 *pos;
156 int ie_len; 159 int ie_len;
157 160
@@ -167,9 +170,9 @@ static int mesh_plink_frame_tx(struct ieee80211_sub_if_data *sdata,
167 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | 170 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
168 IEEE80211_STYPE_ACTION); 171 IEEE80211_STYPE_ACTION);
169 memcpy(mgmt->da, da, ETH_ALEN); 172 memcpy(mgmt->da, da, ETH_ALEN);
170 memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN); 173 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
171 /* BSSID is left zeroed, wildcard value */ 174 /* BSSID is left zeroed, wildcard value */
172 mgmt->u.action.category = PLINK_CATEGORY; 175 mgmt->u.action.category = MESH_PLINK_CATEGORY;
173 mgmt->u.action.u.plink_action.action_code = action; 176 mgmt->u.action.u.plink_action.action_code = action;
174 177
175 if (action == PLINK_CLOSE) 178 if (action == PLINK_CLOSE)
@@ -179,7 +182,8 @@ static int mesh_plink_frame_tx(struct ieee80211_sub_if_data *sdata,
179 if (action == PLINK_CONFIRM) { 182 if (action == PLINK_CONFIRM) {
180 pos = skb_put(skb, 4); 183 pos = skb_put(skb, 4);
181 /* two-byte status code followed by two-byte AID */ 184 /* two-byte status code followed by two-byte AID */
182 memset(pos, 0, 4); 185 memset(pos, 0, 2);
186 memcpy(pos + 2, &plid, 2);
183 } 187 }
184 mesh_mgmt_ies_add(skb, sdata); 188 mesh_mgmt_ies_add(skb, sdata);
185 } 189 }
@@ -187,18 +191,18 @@ static int mesh_plink_frame_tx(struct ieee80211_sub_if_data *sdata,
187 /* Add Peer Link Management element */ 191 /* Add Peer Link Management element */
188 switch (action) { 192 switch (action) {
189 case PLINK_OPEN: 193 case PLINK_OPEN:
190 ie_len = 3; 194 ie_len = 6;
191 break; 195 break;
192 case PLINK_CONFIRM: 196 case PLINK_CONFIRM:
193 ie_len = 5; 197 ie_len = 8;
194 include_plid = true; 198 include_plid = true;
195 break; 199 break;
196 case PLINK_CLOSE: 200 case PLINK_CLOSE:
197 default: 201 default:
198 if (!plid) 202 if (!plid)
199 ie_len = 5; 203 ie_len = 8;
200 else { 204 else {
201 ie_len = 7; 205 ie_len = 10;
202 include_plid = true; 206 include_plid = true;
203 } 207 }
204 break; 208 break;
@@ -207,7 +211,8 @@ static int mesh_plink_frame_tx(struct ieee80211_sub_if_data *sdata,
207 pos = skb_put(skb, 2 + ie_len); 211 pos = skb_put(skb, 2 + ie_len);
208 *pos++ = WLAN_EID_PEER_LINK; 212 *pos++ = WLAN_EID_PEER_LINK;
209 *pos++ = ie_len; 213 *pos++ = ie_len;
210 *pos++ = action; 214 memcpy(pos, meshpeeringproto, sizeof(meshpeeringproto));
215 pos += 4;
211 memcpy(pos, &llid, 2); 216 memcpy(pos, &llid, 2);
212 if (include_plid) { 217 if (include_plid) {
213 pos += 2; 218 pos += 2;
@@ -218,7 +223,7 @@ static int mesh_plink_frame_tx(struct ieee80211_sub_if_data *sdata,
218 memcpy(pos, &reason, 2); 223 memcpy(pos, &reason, 2);
219 } 224 }
220 225
221 ieee80211_tx_skb(sdata, skb, 1); 226 ieee80211_tx_skb(sdata, skb);
222 return 0; 227 return 0;
223} 228}
224 229
@@ -230,14 +235,14 @@ void mesh_neighbour_update(u8 *hw_addr, u32 rates, struct ieee80211_sub_if_data
230 235
231 rcu_read_lock(); 236 rcu_read_lock();
232 237
233 sta = sta_info_get(local, hw_addr); 238 sta = sta_info_get(sdata, hw_addr);
234 if (!sta) { 239 if (!sta) {
240 rcu_read_unlock();
241
235 sta = mesh_plink_alloc(sdata, hw_addr, rates); 242 sta = mesh_plink_alloc(sdata, hw_addr, rates);
236 if (!sta) { 243 if (!sta)
237 rcu_read_unlock();
238 return; 244 return;
239 } 245 if (sta_info_insert_rcu(sta)) {
240 if (sta_info_insert(sta)) {
241 rcu_read_unlock(); 246 rcu_read_unlock();
242 return; 247 return;
243 } 248 }
@@ -395,6 +400,17 @@ void mesh_rx_plink_frame(struct ieee80211_sub_if_data *sdata, struct ieee80211_m
395 u8 ie_len; 400 u8 ie_len;
396 u8 *baseaddr; 401 u8 *baseaddr;
397 __le16 plid, llid, reason; 402 __le16 plid, llid, reason;
403#ifdef CONFIG_MAC80211_VERBOSE_MPL_DEBUG
404 static const char *mplstates[] = {
405 [PLINK_LISTEN] = "LISTEN",
406 [PLINK_OPN_SNT] = "OPN-SNT",
407 [PLINK_OPN_RCVD] = "OPN-RCVD",
408 [PLINK_CNF_RCVD] = "CNF_RCVD",
409 [PLINK_ESTAB] = "ESTAB",
410 [PLINK_HOLDING] = "HOLDING",
411 [PLINK_BLOCKED] = "BLOCKED"
412 };
413#endif
398 414
399 /* need action_code, aux */ 415 /* need action_code, aux */
400 if (len < IEEE80211_MIN_ACTION_SIZE + 3) 416 if (len < IEEE80211_MIN_ACTION_SIZE + 3)
@@ -417,12 +433,13 @@ void mesh_rx_plink_frame(struct ieee80211_sub_if_data *sdata, struct ieee80211_m
417 return; 433 return;
418 } 434 }
419 435
420 ftype = *((u8 *)PLINK_GET_FRAME_SUBTYPE(elems.peer_link)); 436 ftype = mgmt->u.action.u.plink_action.action_code;
421 ie_len = elems.peer_link_len; 437 ie_len = elems.peer_link_len;
422 if ((ftype == PLINK_OPEN && ie_len != 3) || 438 if ((ftype == PLINK_OPEN && ie_len != 6) ||
423 (ftype == PLINK_CONFIRM && ie_len != 5) || 439 (ftype == PLINK_CONFIRM && ie_len != 8) ||
424 (ftype == PLINK_CLOSE && ie_len != 5 && ie_len != 7)) { 440 (ftype == PLINK_CLOSE && ie_len != 8 && ie_len != 10)) {
425 mpl_dbg("Mesh plink: incorrect plink ie length\n"); 441 mpl_dbg("Mesh plink: incorrect plink ie length %d %d\n",
442 ftype, ie_len);
426 return; 443 return;
427 } 444 }
428 445
@@ -434,12 +451,12 @@ void mesh_rx_plink_frame(struct ieee80211_sub_if_data *sdata, struct ieee80211_m
434 * from the point of view of this host. 451 * from the point of view of this host.
435 */ 452 */
436 memcpy(&plid, PLINK_GET_LLID(elems.peer_link), 2); 453 memcpy(&plid, PLINK_GET_LLID(elems.peer_link), 2);
437 if (ftype == PLINK_CONFIRM || (ftype == PLINK_CLOSE && ie_len == 7)) 454 if (ftype == PLINK_CONFIRM || (ftype == PLINK_CLOSE && ie_len == 10))
438 memcpy(&llid, PLINK_GET_PLID(elems.peer_link), 2); 455 memcpy(&llid, PLINK_GET_PLID(elems.peer_link), 2);
439 456
440 rcu_read_lock(); 457 rcu_read_lock();
441 458
442 sta = sta_info_get(local, mgmt->sa); 459 sta = sta_info_get(sdata, mgmt->sa);
443 if (!sta && ftype != PLINK_OPEN) { 460 if (!sta && ftype != PLINK_OPEN) {
444 mpl_dbg("Mesh plink: cls or cnf from unknown peer\n"); 461 mpl_dbg("Mesh plink: cls or cnf from unknown peer\n");
445 rcu_read_unlock(); 462 rcu_read_unlock();
@@ -469,9 +486,11 @@ void mesh_rx_plink_frame(struct ieee80211_sub_if_data *sdata, struct ieee80211_m
469 } else if (!sta) { 486 } else if (!sta) {
470 /* ftype == PLINK_OPEN */ 487 /* ftype == PLINK_OPEN */
471 u32 rates; 488 u32 rates;
489
490 rcu_read_unlock();
491
472 if (!mesh_plink_free_count(sdata)) { 492 if (!mesh_plink_free_count(sdata)) {
473 mpl_dbg("Mesh plink error: no more free plinks\n"); 493 mpl_dbg("Mesh plink error: no more free plinks\n");
474 rcu_read_unlock();
475 return; 494 return;
476 } 495 }
477 496
@@ -479,10 +498,9 @@ void mesh_rx_plink_frame(struct ieee80211_sub_if_data *sdata, struct ieee80211_m
479 sta = mesh_plink_alloc(sdata, mgmt->sa, rates); 498 sta = mesh_plink_alloc(sdata, mgmt->sa, rates);
480 if (!sta) { 499 if (!sta) {
481 mpl_dbg("Mesh plink error: plink table full\n"); 500 mpl_dbg("Mesh plink error: plink table full\n");
482 rcu_read_unlock();
483 return; 501 return;
484 } 502 }
485 if (sta_info_insert(sta)) { 503 if (sta_info_insert_rcu(sta)) {
486 rcu_read_unlock(); 504 rcu_read_unlock();
487 return; 505 return;
488 } 506 }
@@ -532,8 +550,8 @@ void mesh_rx_plink_frame(struct ieee80211_sub_if_data *sdata, struct ieee80211_m
532 } 550 }
533 } 551 }
534 552
535 mpl_dbg("Mesh plink (peer, state, llid, plid, event): %pM %d %d %d %d\n", 553 mpl_dbg("Mesh plink (peer, state, llid, plid, event): %pM %s %d %d %d\n",
536 mgmt->sa, sta->plink_state, 554 mgmt->sa, mplstates[sta->plink_state],
537 le16_to_cpu(sta->llid), le16_to_cpu(sta->plid), 555 le16_to_cpu(sta->llid), le16_to_cpu(sta->plid),
538 event); 556 event);
539 reason = 0; 557 reason = 0;
@@ -727,7 +745,7 @@ void mesh_rx_plink_frame(struct ieee80211_sub_if_data *sdata, struct ieee80211_m
727 break; 745 break;
728 default: 746 default:
729 /* should not get here, PLINK_BLOCKED is dealt with at the 747 /* should not get here, PLINK_BLOCKED is dealt with at the
730 * beggining of the function 748 * beginning of the function
731 */ 749 */
732 spin_unlock_bh(&sta->lock); 750 spin_unlock_bh(&sta->lock);
733 break; 751 break;
diff --git a/net/mac80211/mlme.c b/net/mac80211/mlme.c
index dc5049d58c51..875c8dec940a 100644
--- a/net/mac80211/mlme.c
+++ b/net/mac80211/mlme.c
@@ -19,6 +19,7 @@
19#include <linux/rtnetlink.h> 19#include <linux/rtnetlink.h>
20#include <linux/pm_qos_params.h> 20#include <linux/pm_qos_params.h>
21#include <linux/crc32.h> 21#include <linux/crc32.h>
22#include <linux/slab.h>
22#include <net/mac80211.h> 23#include <net/mac80211.h>
23#include <asm/unaligned.h> 24#include <asm/unaligned.h>
24 25
@@ -27,10 +28,6 @@
27#include "rate.h" 28#include "rate.h"
28#include "led.h" 29#include "led.h"
29 30
30#define IEEE80211_AUTH_TIMEOUT (HZ / 5)
31#define IEEE80211_AUTH_MAX_TRIES 3
32#define IEEE80211_ASSOC_TIMEOUT (HZ / 5)
33#define IEEE80211_ASSOC_MAX_TRIES 3
34#define IEEE80211_MAX_PROBE_TRIES 5 31#define IEEE80211_MAX_PROBE_TRIES 5
35 32
36/* 33/*
@@ -75,11 +72,8 @@ enum rx_mgmt_action {
75 /* caller must call cfg80211_send_disassoc() */ 72 /* caller must call cfg80211_send_disassoc() */
76 RX_MGMT_CFG80211_DISASSOC, 73 RX_MGMT_CFG80211_DISASSOC,
77 74
78 /* caller must call cfg80211_auth_timeout() & free work */ 75 /* caller must tell cfg80211 about internal error */
79 RX_MGMT_CFG80211_AUTH_TO, 76 RX_MGMT_CFG80211_ASSOC_ERROR,
80
81 /* caller must call cfg80211_assoc_timeout() & free work */
82 RX_MGMT_CFG80211_ASSOC_TO,
83}; 77};
84 78
85/* utils */ 79/* utils */
@@ -122,27 +116,6 @@ static int ecw2cw(int ecw)
122 return (1 << ecw) - 1; 116 return (1 << ecw) - 1;
123} 117}
124 118
125static int ieee80211_compatible_rates(struct ieee80211_bss *bss,
126 struct ieee80211_supported_band *sband,
127 u32 *rates)
128{
129 int i, j, count;
130 *rates = 0;
131 count = 0;
132 for (i = 0; i < bss->supp_rates_len; i++) {
133 int rate = (bss->supp_rates[i] & 0x7F) * 5;
134
135 for (j = 0; j < sband->n_bitrates; j++)
136 if (sband->bitrates[j].bitrate == rate) {
137 *rates |= BIT(j);
138 count++;
139 break;
140 }
141 }
142
143 return count;
144}
145
146/* 119/*
147 * ieee80211_enable_ht should be called only after the operating band 120 * ieee80211_enable_ht should be called only after the operating band
148 * has been determined as ht configuration depends on the hw's 121 * has been determined as ht configuration depends on the hw's
@@ -195,6 +168,8 @@ static u32 ieee80211_enable_ht(struct ieee80211_sub_if_data *sdata,
195 ht_changed = conf_is_ht(&local->hw.conf) != enable_ht || 168 ht_changed = conf_is_ht(&local->hw.conf) != enable_ht ||
196 channel_type != local->hw.conf.channel_type; 169 channel_type != local->hw.conf.channel_type;
197 170
171 if (local->tmp_channel)
172 local->tmp_channel_type = channel_type;
198 local->oper_channel_type = channel_type; 173 local->oper_channel_type = channel_type;
199 174
200 if (ht_changed) { 175 if (ht_changed) {
@@ -202,10 +177,11 @@ static u32 ieee80211_enable_ht(struct ieee80211_sub_if_data *sdata,
202 ieee80211_hw_config(local, 0); 177 ieee80211_hw_config(local, 0);
203 178
204 rcu_read_lock(); 179 rcu_read_lock();
205 sta = sta_info_get(local, bssid); 180 sta = sta_info_get(sdata, bssid);
206 if (sta) 181 if (sta)
207 rate_control_rate_update(local, sband, sta, 182 rate_control_rate_update(local, sband, sta,
208 IEEE80211_RC_HT_CHANGED); 183 IEEE80211_RC_HT_CHANGED,
184 local->oper_channel_type);
209 rcu_read_unlock(); 185 rcu_read_unlock();
210 } 186 }
211 187
@@ -228,208 +204,6 @@ static u32 ieee80211_enable_ht(struct ieee80211_sub_if_data *sdata,
228 204
229/* frame sending functions */ 205/* frame sending functions */
230 206
231static void ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata,
232 struct ieee80211_mgd_work *wk)
233{
234 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
235 struct ieee80211_local *local = sdata->local;
236 struct sk_buff *skb;
237 struct ieee80211_mgmt *mgmt;
238 u8 *pos;
239 const u8 *ies, *ht_ie;
240 int i, len, count, rates_len, supp_rates_len;
241 u16 capab;
242 int wmm = 0;
243 struct ieee80211_supported_band *sband;
244 u32 rates = 0;
245
246 skb = dev_alloc_skb(local->hw.extra_tx_headroom +
247 sizeof(*mgmt) + 200 + wk->ie_len +
248 wk->ssid_len);
249 if (!skb) {
250 printk(KERN_DEBUG "%s: failed to allocate buffer for assoc "
251 "frame\n", sdata->dev->name);
252 return;
253 }
254 skb_reserve(skb, local->hw.extra_tx_headroom);
255
256 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
257
258 capab = ifmgd->capab;
259
260 if (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ) {
261 if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE))
262 capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
263 if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE))
264 capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
265 }
266
267 if (wk->bss->cbss.capability & WLAN_CAPABILITY_PRIVACY)
268 capab |= WLAN_CAPABILITY_PRIVACY;
269 if (wk->bss->wmm_used)
270 wmm = 1;
271
272 /* get all rates supported by the device and the AP as
273 * some APs don't like getting a superset of their rates
274 * in the association request (e.g. D-Link DAP 1353 in
275 * b-only mode) */
276 rates_len = ieee80211_compatible_rates(wk->bss, sband, &rates);
277
278 if ((wk->bss->cbss.capability & WLAN_CAPABILITY_SPECTRUM_MGMT) &&
279 (local->hw.flags & IEEE80211_HW_SPECTRUM_MGMT))
280 capab |= WLAN_CAPABILITY_SPECTRUM_MGMT;
281
282 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
283 memset(mgmt, 0, 24);
284 memcpy(mgmt->da, wk->bss->cbss.bssid, ETH_ALEN);
285 memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN);
286 memcpy(mgmt->bssid, wk->bss->cbss.bssid, ETH_ALEN);
287
288 if (!is_zero_ether_addr(wk->prev_bssid)) {
289 skb_put(skb, 10);
290 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
291 IEEE80211_STYPE_REASSOC_REQ);
292 mgmt->u.reassoc_req.capab_info = cpu_to_le16(capab);
293 mgmt->u.reassoc_req.listen_interval =
294 cpu_to_le16(local->hw.conf.listen_interval);
295 memcpy(mgmt->u.reassoc_req.current_ap, wk->prev_bssid,
296 ETH_ALEN);
297 } else {
298 skb_put(skb, 4);
299 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
300 IEEE80211_STYPE_ASSOC_REQ);
301 mgmt->u.assoc_req.capab_info = cpu_to_le16(capab);
302 mgmt->u.assoc_req.listen_interval =
303 cpu_to_le16(local->hw.conf.listen_interval);
304 }
305
306 /* SSID */
307 ies = pos = skb_put(skb, 2 + wk->ssid_len);
308 *pos++ = WLAN_EID_SSID;
309 *pos++ = wk->ssid_len;
310 memcpy(pos, wk->ssid, wk->ssid_len);
311
312 /* add all rates which were marked to be used above */
313 supp_rates_len = rates_len;
314 if (supp_rates_len > 8)
315 supp_rates_len = 8;
316
317 len = sband->n_bitrates;
318 pos = skb_put(skb, supp_rates_len + 2);
319 *pos++ = WLAN_EID_SUPP_RATES;
320 *pos++ = supp_rates_len;
321
322 count = 0;
323 for (i = 0; i < sband->n_bitrates; i++) {
324 if (BIT(i) & rates) {
325 int rate = sband->bitrates[i].bitrate;
326 *pos++ = (u8) (rate / 5);
327 if (++count == 8)
328 break;
329 }
330 }
331
332 if (rates_len > count) {
333 pos = skb_put(skb, rates_len - count + 2);
334 *pos++ = WLAN_EID_EXT_SUPP_RATES;
335 *pos++ = rates_len - count;
336
337 for (i++; i < sband->n_bitrates; i++) {
338 if (BIT(i) & rates) {
339 int rate = sband->bitrates[i].bitrate;
340 *pos++ = (u8) (rate / 5);
341 }
342 }
343 }
344
345 if (capab & WLAN_CAPABILITY_SPECTRUM_MGMT) {
346 /* 1. power capabilities */
347 pos = skb_put(skb, 4);
348 *pos++ = WLAN_EID_PWR_CAPABILITY;
349 *pos++ = 2;
350 *pos++ = 0; /* min tx power */
351 *pos++ = local->hw.conf.channel->max_power; /* max tx power */
352
353 /* 2. supported channels */
354 /* TODO: get this in reg domain format */
355 pos = skb_put(skb, 2 * sband->n_channels + 2);
356 *pos++ = WLAN_EID_SUPPORTED_CHANNELS;
357 *pos++ = 2 * sband->n_channels;
358 for (i = 0; i < sband->n_channels; i++) {
359 *pos++ = ieee80211_frequency_to_channel(
360 sband->channels[i].center_freq);
361 *pos++ = 1; /* one channel in the subband*/
362 }
363 }
364
365 if (wk->ie_len && wk->ie) {
366 pos = skb_put(skb, wk->ie_len);
367 memcpy(pos, wk->ie, wk->ie_len);
368 }
369
370 if (wmm && (ifmgd->flags & IEEE80211_STA_WMM_ENABLED)) {
371 pos = skb_put(skb, 9);
372 *pos++ = WLAN_EID_VENDOR_SPECIFIC;
373 *pos++ = 7; /* len */
374 *pos++ = 0x00; /* Microsoft OUI 00:50:F2 */
375 *pos++ = 0x50;
376 *pos++ = 0xf2;
377 *pos++ = 2; /* WME */
378 *pos++ = 0; /* WME info */
379 *pos++ = 1; /* WME ver */
380 *pos++ = 0;
381 }
382
383 /* wmm support is a must to HT */
384 /*
385 * IEEE802.11n does not allow TKIP/WEP as pairwise
386 * ciphers in HT mode. We still associate in non-ht
387 * mode (11a/b/g) if any one of these ciphers is
388 * configured as pairwise.
389 */
390 if (wmm && (ifmgd->flags & IEEE80211_STA_WMM_ENABLED) &&
391 sband->ht_cap.ht_supported &&
392 (ht_ie = ieee80211_bss_get_ie(&wk->bss->cbss, WLAN_EID_HT_INFORMATION)) &&
393 ht_ie[1] >= sizeof(struct ieee80211_ht_info) &&
394 (!(ifmgd->flags & IEEE80211_STA_DISABLE_11N))) {
395 struct ieee80211_ht_info *ht_info =
396 (struct ieee80211_ht_info *)(ht_ie + 2);
397 u16 cap = sband->ht_cap.cap;
398 __le16 tmp;
399 u32 flags = local->hw.conf.channel->flags;
400
401 switch (ht_info->ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) {
402 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
403 if (flags & IEEE80211_CHAN_NO_HT40PLUS) {
404 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
405 cap &= ~IEEE80211_HT_CAP_SGI_40;
406 }
407 break;
408 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
409 if (flags & IEEE80211_CHAN_NO_HT40MINUS) {
410 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
411 cap &= ~IEEE80211_HT_CAP_SGI_40;
412 }
413 break;
414 }
415
416 tmp = cpu_to_le16(cap);
417 pos = skb_put(skb, sizeof(struct ieee80211_ht_cap)+2);
418 *pos++ = WLAN_EID_HT_CAPABILITY;
419 *pos++ = sizeof(struct ieee80211_ht_cap);
420 memset(pos, 0, sizeof(struct ieee80211_ht_cap));
421 memcpy(pos, &tmp, sizeof(u16));
422 pos += sizeof(u16);
423 /* TODO: needs a define here for << 2 */
424 *pos++ = sband->ht_cap.ampdu_factor |
425 (sband->ht_cap.ampdu_density << 2);
426 memcpy(pos, &sband->ht_cap.mcs, sizeof(sband->ht_cap.mcs));
427 }
428
429 ieee80211_tx_skb(sdata, skb, 0);
430}
431
432
433static void ieee80211_send_deauth_disassoc(struct ieee80211_sub_if_data *sdata, 207static void ieee80211_send_deauth_disassoc(struct ieee80211_sub_if_data *sdata,
434 const u8 *bssid, u16 stype, u16 reason, 208 const u8 *bssid, u16 stype, u16 reason,
435 void *cookie) 209 void *cookie)
@@ -442,7 +216,7 @@ static void ieee80211_send_deauth_disassoc(struct ieee80211_sub_if_data *sdata,
442 skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*mgmt)); 216 skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*mgmt));
443 if (!skb) { 217 if (!skb) {
444 printk(KERN_DEBUG "%s: failed to allocate buffer for " 218 printk(KERN_DEBUG "%s: failed to allocate buffer for "
445 "deauth/disassoc frame\n", sdata->dev->name); 219 "deauth/disassoc frame\n", sdata->name);
446 return; 220 return;
447 } 221 }
448 skb_reserve(skb, local->hw.extra_tx_headroom); 222 skb_reserve(skb, local->hw.extra_tx_headroom);
@@ -450,7 +224,7 @@ static void ieee80211_send_deauth_disassoc(struct ieee80211_sub_if_data *sdata,
450 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24); 224 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
451 memset(mgmt, 0, 24); 225 memset(mgmt, 0, 24);
452 memcpy(mgmt->da, bssid, ETH_ALEN); 226 memcpy(mgmt->da, bssid, ETH_ALEN);
453 memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN); 227 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
454 memcpy(mgmt->bssid, bssid, ETH_ALEN); 228 memcpy(mgmt->bssid, bssid, ETH_ALEN);
455 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | stype); 229 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | stype);
456 skb_put(skb, 2); 230 skb_put(skb, 2);
@@ -458,41 +232,35 @@ static void ieee80211_send_deauth_disassoc(struct ieee80211_sub_if_data *sdata,
458 mgmt->u.deauth.reason_code = cpu_to_le16(reason); 232 mgmt->u.deauth.reason_code = cpu_to_le16(reason);
459 233
460 if (stype == IEEE80211_STYPE_DEAUTH) 234 if (stype == IEEE80211_STYPE_DEAUTH)
461 cfg80211_send_deauth(sdata->dev, (u8 *)mgmt, skb->len, cookie); 235 if (cookie)
236 __cfg80211_send_deauth(sdata->dev, (u8 *)mgmt, skb->len);
237 else
238 cfg80211_send_deauth(sdata->dev, (u8 *)mgmt, skb->len);
462 else 239 else
463 cfg80211_send_disassoc(sdata->dev, (u8 *)mgmt, skb->len, cookie); 240 if (cookie)
464 ieee80211_tx_skb(sdata, skb, ifmgd->flags & IEEE80211_STA_MFP_ENABLED); 241 __cfg80211_send_disassoc(sdata->dev, (u8 *)mgmt, skb->len);
242 else
243 cfg80211_send_disassoc(sdata->dev, (u8 *)mgmt, skb->len);
244 if (!(ifmgd->flags & IEEE80211_STA_MFP_ENABLED))
245 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
246 ieee80211_tx_skb(sdata, skb);
465} 247}
466 248
467void ieee80211_send_pspoll(struct ieee80211_local *local, 249void ieee80211_send_pspoll(struct ieee80211_local *local,
468 struct ieee80211_sub_if_data *sdata) 250 struct ieee80211_sub_if_data *sdata)
469{ 251{
470 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
471 struct ieee80211_pspoll *pspoll; 252 struct ieee80211_pspoll *pspoll;
472 struct sk_buff *skb; 253 struct sk_buff *skb;
473 u16 fc;
474 254
475 skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*pspoll)); 255 skb = ieee80211_pspoll_get(&local->hw, &sdata->vif);
476 if (!skb) { 256 if (!skb)
477 printk(KERN_DEBUG "%s: failed to allocate buffer for "
478 "pspoll frame\n", sdata->dev->name);
479 return; 257 return;
480 }
481 skb_reserve(skb, local->hw.extra_tx_headroom);
482
483 pspoll = (struct ieee80211_pspoll *) skb_put(skb, sizeof(*pspoll));
484 memset(pspoll, 0, sizeof(*pspoll));
485 fc = IEEE80211_FTYPE_CTL | IEEE80211_STYPE_PSPOLL | IEEE80211_FCTL_PM;
486 pspoll->frame_control = cpu_to_le16(fc);
487 pspoll->aid = cpu_to_le16(ifmgd->aid);
488 258
489 /* aid in PS-Poll has its two MSBs each set to 1 */ 259 pspoll = (struct ieee80211_pspoll *) skb->data;
490 pspoll->aid |= cpu_to_le16(1 << 15 | 1 << 14); 260 pspoll->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
491 261
492 memcpy(pspoll->bssid, ifmgd->bssid, ETH_ALEN); 262 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
493 memcpy(pspoll->ta, sdata->dev->dev_addr, ETH_ALEN); 263 ieee80211_tx_skb(sdata, skb);
494
495 ieee80211_tx_skb(sdata, skb, 0);
496} 264}
497 265
498void ieee80211_send_nullfunc(struct ieee80211_local *local, 266void ieee80211_send_nullfunc(struct ieee80211_local *local,
@@ -500,32 +268,50 @@ void ieee80211_send_nullfunc(struct ieee80211_local *local,
500 int powersave) 268 int powersave)
501{ 269{
502 struct sk_buff *skb; 270 struct sk_buff *skb;
271 struct ieee80211_hdr_3addr *nullfunc;
272
273 skb = ieee80211_nullfunc_get(&local->hw, &sdata->vif);
274 if (!skb)
275 return;
276
277 nullfunc = (struct ieee80211_hdr_3addr *) skb->data;
278 if (powersave)
279 nullfunc->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
280
281 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
282 ieee80211_tx_skb(sdata, skb);
283}
284
285static void ieee80211_send_4addr_nullfunc(struct ieee80211_local *local,
286 struct ieee80211_sub_if_data *sdata)
287{
288 struct sk_buff *skb;
503 struct ieee80211_hdr *nullfunc; 289 struct ieee80211_hdr *nullfunc;
504 __le16 fc; 290 __le16 fc;
505 291
506 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION)) 292 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
507 return; 293 return;
508 294
509 skb = dev_alloc_skb(local->hw.extra_tx_headroom + 24); 295 skb = dev_alloc_skb(local->hw.extra_tx_headroom + 30);
510 if (!skb) { 296 if (!skb) {
511 printk(KERN_DEBUG "%s: failed to allocate buffer for nullfunc " 297 printk(KERN_DEBUG "%s: failed to allocate buffer for 4addr "
512 "frame\n", sdata->dev->name); 298 "nullfunc frame\n", sdata->name);
513 return; 299 return;
514 } 300 }
515 skb_reserve(skb, local->hw.extra_tx_headroom); 301 skb_reserve(skb, local->hw.extra_tx_headroom);
516 302
517 nullfunc = (struct ieee80211_hdr *) skb_put(skb, 24); 303 nullfunc = (struct ieee80211_hdr *) skb_put(skb, 30);
518 memset(nullfunc, 0, 24); 304 memset(nullfunc, 0, 30);
519 fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC | 305 fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC |
520 IEEE80211_FCTL_TODS); 306 IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS);
521 if (powersave)
522 fc |= cpu_to_le16(IEEE80211_FCTL_PM);
523 nullfunc->frame_control = fc; 307 nullfunc->frame_control = fc;
524 memcpy(nullfunc->addr1, sdata->u.mgd.bssid, ETH_ALEN); 308 memcpy(nullfunc->addr1, sdata->u.mgd.bssid, ETH_ALEN);
525 memcpy(nullfunc->addr2, sdata->dev->dev_addr, ETH_ALEN); 309 memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
526 memcpy(nullfunc->addr3, sdata->u.mgd.bssid, ETH_ALEN); 310 memcpy(nullfunc->addr3, sdata->u.mgd.bssid, ETH_ALEN);
311 memcpy(nullfunc->addr4, sdata->vif.addr, ETH_ALEN);
527 312
528 ieee80211_tx_skb(sdata, skb, 0); 313 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
314 ieee80211_tx_skb(sdata, skb);
529} 315}
530 316
531/* spectrum management related things */ 317/* spectrum management related things */
@@ -535,7 +321,7 @@ static void ieee80211_chswitch_work(struct work_struct *work)
535 container_of(work, struct ieee80211_sub_if_data, u.mgd.chswitch_work); 321 container_of(work, struct ieee80211_sub_if_data, u.mgd.chswitch_work);
536 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 322 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
537 323
538 if (!netif_running(sdata->dev)) 324 if (!ieee80211_sdata_running(sdata))
539 return; 325 return;
540 326
541 mutex_lock(&ifmgd->mtx); 327 mutex_lock(&ifmgd->mtx);
@@ -546,7 +332,7 @@ static void ieee80211_chswitch_work(struct work_struct *work)
546 ieee80211_hw_config(sdata->local, IEEE80211_CONF_CHANGE_CHANNEL); 332 ieee80211_hw_config(sdata->local, IEEE80211_CONF_CHANGE_CHANNEL);
547 333
548 /* XXX: shouldn't really modify cfg80211-owned data! */ 334 /* XXX: shouldn't really modify cfg80211-owned data! */
549 ifmgd->associated->cbss.channel = sdata->local->oper_channel; 335 ifmgd->associated->channel = sdata->local->oper_channel;
550 336
551 ieee80211_wake_queues_by_reason(&sdata->local->hw, 337 ieee80211_wake_queues_by_reason(&sdata->local->hw,
552 IEEE80211_QUEUE_STOP_REASON_CSA); 338 IEEE80211_QUEUE_STOP_REASON_CSA);
@@ -573,6 +359,8 @@ void ieee80211_sta_process_chanswitch(struct ieee80211_sub_if_data *sdata,
573 struct ieee80211_channel_sw_ie *sw_elem, 359 struct ieee80211_channel_sw_ie *sw_elem,
574 struct ieee80211_bss *bss) 360 struct ieee80211_bss *bss)
575{ 361{
362 struct cfg80211_bss *cbss =
363 container_of((void *)bss, struct cfg80211_bss, priv);
576 struct ieee80211_channel *new_ch; 364 struct ieee80211_channel *new_ch;
577 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 365 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
578 int new_freq = ieee80211_channel_to_frequency(sw_elem->new_ch_num); 366 int new_freq = ieee80211_channel_to_frequency(sw_elem->new_ch_num);
@@ -606,7 +394,7 @@ void ieee80211_sta_process_chanswitch(struct ieee80211_sub_if_data *sdata,
606 mod_timer(&ifmgd->chswitch_timer, 394 mod_timer(&ifmgd->chswitch_timer,
607 jiffies + 395 jiffies +
608 msecs_to_jiffies(sw_elem->count * 396 msecs_to_jiffies(sw_elem->count *
609 bss->cbss.beacon_interval)); 397 cbss->beacon_interval));
610 } 398 }
611} 399}
612 400
@@ -650,6 +438,11 @@ static void ieee80211_enable_ps(struct ieee80211_local *local,
650 } else { 438 } else {
651 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) 439 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
652 ieee80211_send_nullfunc(local, sdata, 1); 440 ieee80211_send_nullfunc(local, sdata, 1);
441
442 if ((local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) &&
443 (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS))
444 return;
445
653 conf->flags |= IEEE80211_CONF_PS; 446 conf->flags |= IEEE80211_CONF_PS;
654 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS); 447 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
655 } 448 }
@@ -680,8 +473,13 @@ void ieee80211_recalc_ps(struct ieee80211_local *local, s32 latency)
680 return; 473 return;
681 } 474 }
682 475
476 if (!list_empty(&local->work_list)) {
477 local->ps_sdata = NULL;
478 goto change;
479 }
480
683 list_for_each_entry(sdata, &local->interfaces, list) { 481 list_for_each_entry(sdata, &local->interfaces, list) {
684 if (!netif_running(sdata->dev)) 482 if (!ieee80211_sdata_running(sdata))
685 continue; 483 continue;
686 if (sdata->vif.type != NL80211_IFTYPE_STATION) 484 if (sdata->vif.type != NL80211_IFTYPE_STATION)
687 continue; 485 continue;
@@ -690,7 +488,8 @@ void ieee80211_recalc_ps(struct ieee80211_local *local, s32 latency)
690 } 488 }
691 489
692 if (count == 1 && found->u.mgd.powersave && 490 if (count == 1 && found->u.mgd.powersave &&
693 found->u.mgd.associated && list_empty(&found->u.mgd.work_list) && 491 found->u.mgd.associated &&
492 found->u.mgd.associated->beacon_ies &&
694 !(found->u.mgd.flags & (IEEE80211_STA_BEACON_POLL | 493 !(found->u.mgd.flags & (IEEE80211_STA_BEACON_POLL |
695 IEEE80211_STA_CONNECTION_POLL))) { 494 IEEE80211_STA_CONNECTION_POLL))) {
696 s32 beaconint_us; 495 s32 beaconint_us;
@@ -704,20 +503,29 @@ void ieee80211_recalc_ps(struct ieee80211_local *local, s32 latency)
704 if (beaconint_us > latency) { 503 if (beaconint_us > latency) {
705 local->ps_sdata = NULL; 504 local->ps_sdata = NULL;
706 } else { 505 } else {
707 u8 dtimper = found->vif.bss_conf.dtim_period; 506 struct ieee80211_bss *bss;
708 int maxslp = 1; 507 int maxslp = 1;
508 u8 dtimper;
509
510 bss = (void *)found->u.mgd.associated->priv;
511 dtimper = bss->dtim_period;
709 512
710 if (dtimper > 1) 513 /* If the TIM IE is invalid, pretend the value is 1 */
514 if (!dtimper)
515 dtimper = 1;
516 else if (dtimper > 1)
711 maxslp = min_t(int, dtimper, 517 maxslp = min_t(int, dtimper,
712 latency / beaconint_us); 518 latency / beaconint_us);
713 519
714 local->hw.conf.max_sleep_period = maxslp; 520 local->hw.conf.max_sleep_period = maxslp;
521 local->hw.conf.ps_dtim_period = dtimper;
715 local->ps_sdata = found; 522 local->ps_sdata = found;
716 } 523 }
717 } else { 524 } else {
718 local->ps_sdata = NULL; 525 local->ps_sdata = NULL;
719 } 526 }
720 527
528 change:
721 ieee80211_change_ps(local); 529 ieee80211_change_ps(local);
722} 530}
723 531
@@ -742,6 +550,7 @@ void ieee80211_dynamic_ps_enable_work(struct work_struct *work)
742 container_of(work, struct ieee80211_local, 550 container_of(work, struct ieee80211_local,
743 dynamic_ps_enable_work); 551 dynamic_ps_enable_work);
744 struct ieee80211_sub_if_data *sdata = local->ps_sdata; 552 struct ieee80211_sub_if_data *sdata = local->ps_sdata;
553 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
745 554
746 /* can only happen when PS was just disabled anyway */ 555 /* can only happen when PS was just disabled anyway */
747 if (!sdata) 556 if (!sdata)
@@ -750,11 +559,17 @@ void ieee80211_dynamic_ps_enable_work(struct work_struct *work)
750 if (local->hw.conf.flags & IEEE80211_CONF_PS) 559 if (local->hw.conf.flags & IEEE80211_CONF_PS)
751 return; 560 return;
752 561
753 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) 562 if ((local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) &&
563 (!(ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)))
754 ieee80211_send_nullfunc(local, sdata, 1); 564 ieee80211_send_nullfunc(local, sdata, 1);
755 565
756 local->hw.conf.flags |= IEEE80211_CONF_PS; 566 if (!((local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS) &&
757 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS); 567 (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)) ||
568 (ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)) {
569 ifmgd->flags &= ~IEEE80211_STA_NULLFUNC_ACKED;
570 local->hw.conf.flags |= IEEE80211_CONF_PS;
571 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
572 }
758} 573}
759 574
760void ieee80211_dynamic_ps_timer(unsigned long data) 575void ieee80211_dynamic_ps_timer(unsigned long data)
@@ -775,9 +590,9 @@ static void ieee80211_sta_wmm_params(struct ieee80211_local *local,
775 struct ieee80211_tx_queue_params params; 590 struct ieee80211_tx_queue_params params;
776 size_t left; 591 size_t left;
777 int count; 592 int count;
778 u8 *pos; 593 u8 *pos, uapsd_queues = 0;
779 594
780 if (!(ifmgd->flags & IEEE80211_STA_WMM_ENABLED)) 595 if (local->hw.queues < 4)
781 return; 596 return;
782 597
783 if (!wmm_param) 598 if (!wmm_param)
@@ -785,6 +600,10 @@ static void ieee80211_sta_wmm_params(struct ieee80211_local *local,
785 600
786 if (wmm_param_len < 8 || wmm_param[5] /* version */ != 1) 601 if (wmm_param_len < 8 || wmm_param[5] /* version */ != 1)
787 return; 602 return;
603
604 if (ifmgd->flags & IEEE80211_STA_UAPSD_ENABLED)
605 uapsd_queues = local->uapsd_queues;
606
788 count = wmm_param[6] & 0x0f; 607 count = wmm_param[6] & 0x0f;
789 if (count == ifmgd->wmm_last_param_set) 608 if (count == ifmgd->wmm_last_param_set)
790 return; 609 return;
@@ -799,6 +618,7 @@ static void ieee80211_sta_wmm_params(struct ieee80211_local *local,
799 for (; left >= 4; left -= 4, pos += 4) { 618 for (; left >= 4; left -= 4, pos += 4) {
800 int aci = (pos[0] >> 5) & 0x03; 619 int aci = (pos[0] >> 5) & 0x03;
801 int acm = (pos[0] >> 4) & 0x01; 620 int acm = (pos[0] >> 4) & 0x01;
621 bool uapsd = false;
802 int queue; 622 int queue;
803 623
804 switch (aci) { 624 switch (aci) {
@@ -806,22 +626,30 @@ static void ieee80211_sta_wmm_params(struct ieee80211_local *local,
806 queue = 3; 626 queue = 3;
807 if (acm) 627 if (acm)
808 local->wmm_acm |= BIT(1) | BIT(2); /* BK/- */ 628 local->wmm_acm |= BIT(1) | BIT(2); /* BK/- */
629 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
630 uapsd = true;
809 break; 631 break;
810 case 2: /* AC_VI */ 632 case 2: /* AC_VI */
811 queue = 1; 633 queue = 1;
812 if (acm) 634 if (acm)
813 local->wmm_acm |= BIT(4) | BIT(5); /* CL/VI */ 635 local->wmm_acm |= BIT(4) | BIT(5); /* CL/VI */
636 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
637 uapsd = true;
814 break; 638 break;
815 case 3: /* AC_VO */ 639 case 3: /* AC_VO */
816 queue = 0; 640 queue = 0;
817 if (acm) 641 if (acm)
818 local->wmm_acm |= BIT(6) | BIT(7); /* VO/NC */ 642 local->wmm_acm |= BIT(6) | BIT(7); /* VO/NC */
643 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
644 uapsd = true;
819 break; 645 break;
820 case 0: /* AC_BE */ 646 case 0: /* AC_BE */
821 default: 647 default:
822 queue = 2; 648 queue = 2;
823 if (acm) 649 if (acm)
824 local->wmm_acm |= BIT(0) | BIT(3); /* BE/EE */ 650 local->wmm_acm |= BIT(0) | BIT(3); /* BE/EE */
651 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
652 uapsd = true;
825 break; 653 break;
826 } 654 }
827 655
@@ -829,11 +657,14 @@ static void ieee80211_sta_wmm_params(struct ieee80211_local *local,
829 params.cw_max = ecw2cw((pos[1] & 0xf0) >> 4); 657 params.cw_max = ecw2cw((pos[1] & 0xf0) >> 4);
830 params.cw_min = ecw2cw(pos[1] & 0x0f); 658 params.cw_min = ecw2cw(pos[1] & 0x0f);
831 params.txop = get_unaligned_le16(pos + 2); 659 params.txop = get_unaligned_le16(pos + 2);
660 params.uapsd = uapsd;
661
832#ifdef CONFIG_MAC80211_VERBOSE_DEBUG 662#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
833 printk(KERN_DEBUG "%s: WMM queue=%d aci=%d acm=%d aifs=%d " 663 printk(KERN_DEBUG "%s: WMM queue=%d aci=%d acm=%d aifs=%d "
834 "cWmin=%d cWmax=%d txop=%d\n", 664 "cWmin=%d cWmax=%d txop=%d uapsd=%d\n",
835 wiphy_name(local->hw.wiphy), queue, aci, acm, 665 wiphy_name(local->hw.wiphy), queue, aci, acm,
836 params.aifs, params.cw_min, params.cw_max, params.txop); 666 params.aifs, params.cw_min, params.cw_max, params.txop,
667 params.uapsd);
837#endif 668#endif
838 if (drv_conf_tx(local, queue, &params) && local->ops->conf_tx) 669 if (drv_conf_tx(local, queue, &params) && local->ops->conf_tx)
839 printk(KERN_DEBUG "%s: failed to set TX queue " 670 printk(KERN_DEBUG "%s: failed to set TX queue "
@@ -860,6 +691,8 @@ static u32 ieee80211_handle_bss_capability(struct ieee80211_sub_if_data *sdata,
860 } 691 }
861 692
862 use_short_slot = !!(capab & WLAN_CAPABILITY_SHORT_SLOT_TIME); 693 use_short_slot = !!(capab & WLAN_CAPABILITY_SHORT_SLOT_TIME);
694 if (sdata->local->hw.conf.channel->band == IEEE80211_BAND_5GHZ)
695 use_short_slot = true;
863 696
864 if (use_protection != bss_conf->use_cts_prot) { 697 if (use_protection != bss_conf->use_cts_prot) {
865 bss_conf->use_cts_prot = use_protection; 698 bss_conf->use_cts_prot = use_protection;
@@ -880,30 +713,36 @@ static u32 ieee80211_handle_bss_capability(struct ieee80211_sub_if_data *sdata,
880} 713}
881 714
882static void ieee80211_set_associated(struct ieee80211_sub_if_data *sdata, 715static void ieee80211_set_associated(struct ieee80211_sub_if_data *sdata,
883 struct ieee80211_mgd_work *wk, 716 struct cfg80211_bss *cbss,
884 u32 bss_info_changed) 717 u32 bss_info_changed)
885{ 718{
719 struct ieee80211_bss *bss = (void *)cbss->priv;
886 struct ieee80211_local *local = sdata->local; 720 struct ieee80211_local *local = sdata->local;
887 struct ieee80211_bss *bss = wk->bss;
888 721
889 bss_info_changed |= BSS_CHANGED_ASSOC; 722 bss_info_changed |= BSS_CHANGED_ASSOC;
890 /* set timing information */ 723 /* set timing information */
891 sdata->vif.bss_conf.beacon_int = bss->cbss.beacon_interval; 724 sdata->vif.bss_conf.beacon_int = cbss->beacon_interval;
892 sdata->vif.bss_conf.timestamp = bss->cbss.tsf; 725 sdata->vif.bss_conf.timestamp = cbss->tsf;
893 sdata->vif.bss_conf.dtim_period = bss->dtim_period;
894 726
895 bss_info_changed |= BSS_CHANGED_BEACON_INT; 727 bss_info_changed |= BSS_CHANGED_BEACON_INT;
896 bss_info_changed |= ieee80211_handle_bss_capability(sdata, 728 bss_info_changed |= ieee80211_handle_bss_capability(sdata,
897 bss->cbss.capability, bss->has_erp_value, bss->erp_value); 729 cbss->capability, bss->has_erp_value, bss->erp_value);
898 730
899 sdata->u.mgd.associated = bss; 731 sdata->u.mgd.associated = cbss;
900 sdata->u.mgd.old_associate_work = wk; 732 memcpy(sdata->u.mgd.bssid, cbss->bssid, ETH_ALEN);
901 memcpy(sdata->u.mgd.bssid, bss->cbss.bssid, ETH_ALEN);
902 733
903 /* just to be sure */ 734 /* just to be sure */
904 sdata->u.mgd.flags &= ~(IEEE80211_STA_CONNECTION_POLL | 735 sdata->u.mgd.flags &= ~(IEEE80211_STA_CONNECTION_POLL |
905 IEEE80211_STA_BEACON_POLL); 736 IEEE80211_STA_BEACON_POLL);
906 737
738 /*
739 * Always handle WMM once after association regardless
740 * of the first value the AP uses. Setting -1 here has
741 * that effect because the AP values is an unsigned
742 * 4-bit value.
743 */
744 sdata->u.mgd.wmm_last_param_set = -1;
745
907 ieee80211_led_assoc(local, 1); 746 ieee80211_led_assoc(local, 1);
908 747
909 sdata->vif.bss_conf.assoc = 1; 748 sdata->vif.bss_conf.assoc = 1;
@@ -921,99 +760,14 @@ static void ieee80211_set_associated(struct ieee80211_sub_if_data *sdata,
921 760
922 mutex_lock(&local->iflist_mtx); 761 mutex_lock(&local->iflist_mtx);
923 ieee80211_recalc_ps(local, -1); 762 ieee80211_recalc_ps(local, -1);
763 ieee80211_recalc_smps(local, sdata);
924 mutex_unlock(&local->iflist_mtx); 764 mutex_unlock(&local->iflist_mtx);
925 765
926 netif_tx_start_all_queues(sdata->dev); 766 netif_tx_start_all_queues(sdata->dev);
927 netif_carrier_on(sdata->dev); 767 netif_carrier_on(sdata->dev);
928} 768}
929 769
930static enum rx_mgmt_action __must_check 770static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata)
931ieee80211_direct_probe(struct ieee80211_sub_if_data *sdata,
932 struct ieee80211_mgd_work *wk)
933{
934 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
935 struct ieee80211_local *local = sdata->local;
936
937 wk->tries++;
938 if (wk->tries > IEEE80211_AUTH_MAX_TRIES) {
939 printk(KERN_DEBUG "%s: direct probe to AP %pM timed out\n",
940 sdata->dev->name, wk->bss->cbss.bssid);
941
942 /*
943 * Most likely AP is not in the range so remove the
944 * bss struct for that AP.
945 */
946 cfg80211_unlink_bss(local->hw.wiphy, &wk->bss->cbss);
947
948 /*
949 * We might have a pending scan which had no chance to run yet
950 * due to work needing to be done. Hence, queue the STAs work
951 * again for that.
952 */
953 ieee80211_queue_work(&local->hw, &ifmgd->work);
954 return RX_MGMT_CFG80211_AUTH_TO;
955 }
956
957 printk(KERN_DEBUG "%s: direct probe to AP %pM (try %d)\n",
958 sdata->dev->name, wk->bss->cbss.bssid,
959 wk->tries);
960
961 /*
962 * Direct probe is sent to broadcast address as some APs
963 * will not answer to direct packet in unassociated state.
964 */
965 ieee80211_send_probe_req(sdata, NULL, wk->ssid, wk->ssid_len, NULL, 0);
966
967 wk->timeout = jiffies + IEEE80211_AUTH_TIMEOUT;
968 run_again(ifmgd, wk->timeout);
969
970 return RX_MGMT_NONE;
971}
972
973
974static enum rx_mgmt_action __must_check
975ieee80211_authenticate(struct ieee80211_sub_if_data *sdata,
976 struct ieee80211_mgd_work *wk)
977{
978 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
979 struct ieee80211_local *local = sdata->local;
980
981 wk->tries++;
982 if (wk->tries > IEEE80211_AUTH_MAX_TRIES) {
983 printk(KERN_DEBUG "%s: authentication with AP %pM"
984 " timed out\n",
985 sdata->dev->name, wk->bss->cbss.bssid);
986
987 /*
988 * Most likely AP is not in the range so remove the
989 * bss struct for that AP.
990 */
991 cfg80211_unlink_bss(local->hw.wiphy, &wk->bss->cbss);
992
993 /*
994 * We might have a pending scan which had no chance to run yet
995 * due to work needing to be done. Hence, queue the STAs work
996 * again for that.
997 */
998 ieee80211_queue_work(&local->hw, &ifmgd->work);
999 return RX_MGMT_CFG80211_AUTH_TO;
1000 }
1001
1002 printk(KERN_DEBUG "%s: authenticate with AP %pM (try %d)\n",
1003 sdata->dev->name, wk->bss->cbss.bssid, wk->tries);
1004
1005 ieee80211_send_auth(sdata, 1, wk->auth_alg, wk->ie, wk->ie_len,
1006 wk->bss->cbss.bssid, NULL, 0, 0);
1007 wk->auth_transaction = 2;
1008
1009 wk->timeout = jiffies + IEEE80211_AUTH_TIMEOUT;
1010 run_again(ifmgd, wk->timeout);
1011
1012 return RX_MGMT_NONE;
1013}
1014
1015static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata,
1016 bool deauth)
1017{ 771{
1018 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 772 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1019 struct ieee80211_local *local = sdata->local; 773 struct ieee80211_local *local = sdata->local;
@@ -1026,21 +780,11 @@ static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata,
1026 if (WARN_ON(!ifmgd->associated)) 780 if (WARN_ON(!ifmgd->associated))
1027 return; 781 return;
1028 782
1029 memcpy(bssid, ifmgd->associated->cbss.bssid, ETH_ALEN); 783 memcpy(bssid, ifmgd->associated->bssid, ETH_ALEN);
1030 784
1031 ifmgd->associated = NULL; 785 ifmgd->associated = NULL;
1032 memset(ifmgd->bssid, 0, ETH_ALEN); 786 memset(ifmgd->bssid, 0, ETH_ALEN);
1033 787
1034 if (deauth) {
1035 kfree(ifmgd->old_associate_work);
1036 ifmgd->old_associate_work = NULL;
1037 } else {
1038 struct ieee80211_mgd_work *wk = ifmgd->old_associate_work;
1039
1040 wk->state = IEEE80211_MGD_STATE_IDLE;
1041 list_add(&wk->list, &ifmgd->work_list);
1042 }
1043
1044 /* 788 /*
1045 * we need to commit the associated = NULL change because the 789 * we need to commit the associated = NULL change because the
1046 * scan code uses that to determine whether this iface should 790 * scan code uses that to determine whether this iface should
@@ -1059,9 +803,11 @@ static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata,
1059 netif_carrier_off(sdata->dev); 803 netif_carrier_off(sdata->dev);
1060 804
1061 rcu_read_lock(); 805 rcu_read_lock();
1062 sta = sta_info_get(local, bssid); 806 sta = sta_info_get(sdata, bssid);
1063 if (sta) 807 if (sta) {
808 set_sta_flags(sta, WLAN_STA_DISASSOC);
1064 ieee80211_sta_tear_down_BA_sessions(sta); 809 ieee80211_sta_tear_down_BA_sessions(sta);
810 }
1065 rcu_read_unlock(); 811 rcu_read_unlock();
1066 812
1067 changed |= ieee80211_reset_erp_info(sdata); 813 changed |= ieee80211_reset_erp_info(sdata);
@@ -1072,8 +818,6 @@ static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata,
1072 818
1073 ieee80211_set_wmm_default(sdata); 819 ieee80211_set_wmm_default(sdata);
1074 820
1075 ieee80211_recalc_idle(local);
1076
1077 /* channel(_type) changes are handled by ieee80211_hw_config */ 821 /* channel(_type) changes are handled by ieee80211_hw_config */
1078 local->oper_channel_type = NL80211_CHAN_NO_HT; 822 local->oper_channel_type = NL80211_CHAN_NO_HT;
1079 823
@@ -1096,57 +840,7 @@ static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata,
1096 changed |= BSS_CHANGED_BSSID; 840 changed |= BSS_CHANGED_BSSID;
1097 ieee80211_bss_info_change_notify(sdata, changed); 841 ieee80211_bss_info_change_notify(sdata, changed);
1098 842
1099 rcu_read_lock(); 843 sta_info_destroy_addr(sdata, bssid);
1100
1101 sta = sta_info_get(local, bssid);
1102 if (!sta) {
1103 rcu_read_unlock();
1104 return;
1105 }
1106
1107 sta_info_unlink(&sta);
1108
1109 rcu_read_unlock();
1110
1111 sta_info_destroy(sta);
1112}
1113
1114static enum rx_mgmt_action __must_check
1115ieee80211_associate(struct ieee80211_sub_if_data *sdata,
1116 struct ieee80211_mgd_work *wk)
1117{
1118 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1119 struct ieee80211_local *local = sdata->local;
1120
1121 wk->tries++;
1122 if (wk->tries > IEEE80211_ASSOC_MAX_TRIES) {
1123 printk(KERN_DEBUG "%s: association with AP %pM"
1124 " timed out\n",
1125 sdata->dev->name, wk->bss->cbss.bssid);
1126
1127 /*
1128 * Most likely AP is not in the range so remove the
1129 * bss struct for that AP.
1130 */
1131 cfg80211_unlink_bss(local->hw.wiphy, &wk->bss->cbss);
1132
1133 /*
1134 * We might have a pending scan which had no chance to run yet
1135 * due to work needing to be done. Hence, queue the STAs work
1136 * again for that.
1137 */
1138 ieee80211_queue_work(&local->hw, &ifmgd->work);
1139 return RX_MGMT_CFG80211_ASSOC_TO;
1140 }
1141
1142 printk(KERN_DEBUG "%s: associate with AP %pM (try %d)\n",
1143 sdata->dev->name, wk->bss->cbss.bssid, wk->tries);
1144 ieee80211_send_assoc(sdata, wk);
1145
1146 wk->timeout = jiffies + IEEE80211_ASSOC_TIMEOUT;
1147 run_again(ifmgd, wk->timeout);
1148
1149 return RX_MGMT_NONE;
1150} 844}
1151 845
1152void ieee80211_sta_rx_notify(struct ieee80211_sub_if_data *sdata, 846void ieee80211_sta_rx_notify(struct ieee80211_sub_if_data *sdata,
@@ -1172,8 +866,8 @@ static void ieee80211_mgd_probe_ap_send(struct ieee80211_sub_if_data *sdata)
1172 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 866 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1173 const u8 *ssid; 867 const u8 *ssid;
1174 868
1175 ssid = ieee80211_bss_get_ie(&ifmgd->associated->cbss, WLAN_EID_SSID); 869 ssid = ieee80211_bss_get_ie(ifmgd->associated, WLAN_EID_SSID);
1176 ieee80211_send_probe_req(sdata, ifmgd->associated->cbss.bssid, 870 ieee80211_send_probe_req(sdata, ifmgd->associated->bssid,
1177 ssid + 2, ssid[1], NULL, 0); 871 ssid + 2, ssid[1], NULL, 0);
1178 872
1179 ifmgd->probe_send_count++; 873 ifmgd->probe_send_count++;
@@ -1187,12 +881,15 @@ static void ieee80211_mgd_probe_ap(struct ieee80211_sub_if_data *sdata,
1187 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 881 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1188 bool already = false; 882 bool already = false;
1189 883
1190 if (!netif_running(sdata->dev)) 884 if (!ieee80211_sdata_running(sdata))
1191 return; 885 return;
1192 886
1193 if (sdata->local->scanning) 887 if (sdata->local->scanning)
1194 return; 888 return;
1195 889
890 if (sdata->local->tmp_channel)
891 return;
892
1196 mutex_lock(&ifmgd->mtx); 893 mutex_lock(&ifmgd->mtx);
1197 894
1198 if (!ifmgd->associated) 895 if (!ifmgd->associated)
@@ -1201,7 +898,7 @@ static void ieee80211_mgd_probe_ap(struct ieee80211_sub_if_data *sdata,
1201#ifdef CONFIG_MAC80211_VERBOSE_DEBUG 898#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
1202 if (beacon && net_ratelimit()) 899 if (beacon && net_ratelimit())
1203 printk(KERN_DEBUG "%s: detected beacon loss from AP " 900 printk(KERN_DEBUG "%s: detected beacon loss from AP "
1204 "- sending probe request\n", sdata->dev->name); 901 "- sending probe request\n", sdata->name);
1205#endif 902#endif
1206 903
1207 /* 904 /*
@@ -1254,88 +951,8 @@ void ieee80211_beacon_loss(struct ieee80211_vif *vif)
1254} 951}
1255EXPORT_SYMBOL(ieee80211_beacon_loss); 952EXPORT_SYMBOL(ieee80211_beacon_loss);
1256 953
1257static void ieee80211_auth_completed(struct ieee80211_sub_if_data *sdata,
1258 struct ieee80211_mgd_work *wk)
1259{
1260 wk->state = IEEE80211_MGD_STATE_IDLE;
1261 printk(KERN_DEBUG "%s: authenticated\n", sdata->dev->name);
1262}
1263
1264
1265static void ieee80211_auth_challenge(struct ieee80211_sub_if_data *sdata,
1266 struct ieee80211_mgd_work *wk,
1267 struct ieee80211_mgmt *mgmt,
1268 size_t len)
1269{
1270 u8 *pos;
1271 struct ieee802_11_elems elems;
1272
1273 pos = mgmt->u.auth.variable;
1274 ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems);
1275 if (!elems.challenge)
1276 return;
1277 ieee80211_send_auth(sdata, 3, wk->auth_alg,
1278 elems.challenge - 2, elems.challenge_len + 2,
1279 wk->bss->cbss.bssid,
1280 wk->key, wk->key_len, wk->key_idx);
1281 wk->auth_transaction = 4;
1282}
1283
1284static enum rx_mgmt_action __must_check
1285ieee80211_rx_mgmt_auth(struct ieee80211_sub_if_data *sdata,
1286 struct ieee80211_mgd_work *wk,
1287 struct ieee80211_mgmt *mgmt, size_t len)
1288{
1289 u16 auth_alg, auth_transaction, status_code;
1290
1291 if (wk->state != IEEE80211_MGD_STATE_AUTH)
1292 return RX_MGMT_NONE;
1293
1294 if (len < 24 + 6)
1295 return RX_MGMT_NONE;
1296
1297 if (memcmp(wk->bss->cbss.bssid, mgmt->sa, ETH_ALEN) != 0)
1298 return RX_MGMT_NONE;
1299
1300 if (memcmp(wk->bss->cbss.bssid, mgmt->bssid, ETH_ALEN) != 0)
1301 return RX_MGMT_NONE;
1302
1303 auth_alg = le16_to_cpu(mgmt->u.auth.auth_alg);
1304 auth_transaction = le16_to_cpu(mgmt->u.auth.auth_transaction);
1305 status_code = le16_to_cpu(mgmt->u.auth.status_code);
1306
1307 if (auth_alg != wk->auth_alg ||
1308 auth_transaction != wk->auth_transaction)
1309 return RX_MGMT_NONE;
1310
1311 if (status_code != WLAN_STATUS_SUCCESS) {
1312 list_del(&wk->list);
1313 kfree(wk);
1314 return RX_MGMT_CFG80211_AUTH;
1315 }
1316
1317 switch (wk->auth_alg) {
1318 case WLAN_AUTH_OPEN:
1319 case WLAN_AUTH_LEAP:
1320 case WLAN_AUTH_FT:
1321 ieee80211_auth_completed(sdata, wk);
1322 return RX_MGMT_CFG80211_AUTH;
1323 case WLAN_AUTH_SHARED_KEY:
1324 if (wk->auth_transaction == 4) {
1325 ieee80211_auth_completed(sdata, wk);
1326 return RX_MGMT_CFG80211_AUTH;
1327 } else
1328 ieee80211_auth_challenge(sdata, wk, mgmt, len);
1329 break;
1330 }
1331
1332 return RX_MGMT_NONE;
1333}
1334
1335
1336static enum rx_mgmt_action __must_check 954static enum rx_mgmt_action __must_check
1337ieee80211_rx_mgmt_deauth(struct ieee80211_sub_if_data *sdata, 955ieee80211_rx_mgmt_deauth(struct ieee80211_sub_if_data *sdata,
1338 struct ieee80211_mgd_work *wk,
1339 struct ieee80211_mgmt *mgmt, size_t len) 956 struct ieee80211_mgmt *mgmt, size_t len)
1340{ 957{
1341 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 958 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
@@ -1347,22 +964,15 @@ ieee80211_rx_mgmt_deauth(struct ieee80211_sub_if_data *sdata,
1347 964
1348 ASSERT_MGD_MTX(ifmgd); 965 ASSERT_MGD_MTX(ifmgd);
1349 966
1350 if (wk) 967 bssid = ifmgd->associated->bssid;
1351 bssid = wk->bss->cbss.bssid;
1352 else
1353 bssid = ifmgd->associated->cbss.bssid;
1354 968
1355 reason_code = le16_to_cpu(mgmt->u.deauth.reason_code); 969 reason_code = le16_to_cpu(mgmt->u.deauth.reason_code);
1356 970
1357 printk(KERN_DEBUG "%s: deauthenticated from %pM (Reason: %u)\n", 971 printk(KERN_DEBUG "%s: deauthenticated from %pM (Reason: %u)\n",
1358 sdata->dev->name, bssid, reason_code); 972 sdata->name, bssid, reason_code);
1359 973
1360 if (!wk) { 974 ieee80211_set_disassoc(sdata);
1361 ieee80211_set_disassoc(sdata, true); 975 ieee80211_recalc_idle(sdata->local);
1362 } else {
1363 list_del(&wk->list);
1364 kfree(wk);
1365 }
1366 976
1367 return RX_MGMT_CFG80211_DEAUTH; 977 return RX_MGMT_CFG80211_DEAUTH;
1368} 978}
@@ -1383,122 +993,72 @@ ieee80211_rx_mgmt_disassoc(struct ieee80211_sub_if_data *sdata,
1383 if (WARN_ON(!ifmgd->associated)) 993 if (WARN_ON(!ifmgd->associated))
1384 return RX_MGMT_NONE; 994 return RX_MGMT_NONE;
1385 995
1386 if (WARN_ON(memcmp(ifmgd->associated->cbss.bssid, mgmt->sa, ETH_ALEN))) 996 if (WARN_ON(memcmp(ifmgd->associated->bssid, mgmt->sa, ETH_ALEN)))
1387 return RX_MGMT_NONE; 997 return RX_MGMT_NONE;
1388 998
1389 reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code); 999 reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code);
1390 1000
1391 printk(KERN_DEBUG "%s: disassociated from %pM (Reason: %u)\n", 1001 printk(KERN_DEBUG "%s: disassociated from %pM (Reason: %u)\n",
1392 sdata->dev->name, mgmt->sa, reason_code); 1002 sdata->name, mgmt->sa, reason_code);
1393 1003
1394 ieee80211_set_disassoc(sdata, false); 1004 ieee80211_set_disassoc(sdata);
1005 ieee80211_recalc_idle(sdata->local);
1395 return RX_MGMT_CFG80211_DISASSOC; 1006 return RX_MGMT_CFG80211_DISASSOC;
1396} 1007}
1397 1008
1398 1009
1399static enum rx_mgmt_action __must_check 1010static bool ieee80211_assoc_success(struct ieee80211_work *wk,
1400ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata, 1011 struct ieee80211_mgmt *mgmt, size_t len)
1401 struct ieee80211_mgd_work *wk,
1402 struct ieee80211_mgmt *mgmt, size_t len,
1403 bool reassoc)
1404{ 1012{
1013 struct ieee80211_sub_if_data *sdata = wk->sdata;
1405 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 1014 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1406 struct ieee80211_local *local = sdata->local; 1015 struct ieee80211_local *local = sdata->local;
1407 struct ieee80211_supported_band *sband; 1016 struct ieee80211_supported_band *sband;
1408 struct sta_info *sta; 1017 struct sta_info *sta;
1018 struct cfg80211_bss *cbss = wk->assoc.bss;
1019 u8 *pos;
1409 u32 rates, basic_rates; 1020 u32 rates, basic_rates;
1410 u16 capab_info, status_code, aid; 1021 u16 capab_info, aid;
1411 struct ieee802_11_elems elems; 1022 struct ieee802_11_elems elems;
1412 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf; 1023 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
1413 u8 *pos;
1414 u32 changed = 0; 1024 u32 changed = 0;
1415 int i, j; 1025 int i, j, err;
1416 bool have_higher_than_11mbit = false, newsta = false; 1026 bool have_higher_than_11mbit = false;
1417 u16 ap_ht_cap_flags; 1027 u16 ap_ht_cap_flags;
1418 1028
1419 /* 1029 /* AssocResp and ReassocResp have identical structure */
1420 * AssocResp and ReassocResp have identical structure, so process both
1421 * of them in this function.
1422 */
1423
1424 if (len < 24 + 6)
1425 return RX_MGMT_NONE;
1426
1427 if (memcmp(wk->bss->cbss.bssid, mgmt->sa, ETH_ALEN) != 0)
1428 return RX_MGMT_NONE;
1429 1030
1430 capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
1431 status_code = le16_to_cpu(mgmt->u.assoc_resp.status_code);
1432 aid = le16_to_cpu(mgmt->u.assoc_resp.aid); 1031 aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
1433 1032 capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
1434 printk(KERN_DEBUG "%s: RX %sssocResp from %pM (capab=0x%x "
1435 "status=%d aid=%d)\n",
1436 sdata->dev->name, reassoc ? "Rea" : "A", mgmt->sa,
1437 capab_info, status_code, (u16)(aid & ~(BIT(15) | BIT(14))));
1438
1439 pos = mgmt->u.assoc_resp.variable;
1440 ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems);
1441
1442 if (status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY &&
1443 elems.timeout_int && elems.timeout_int_len == 5 &&
1444 elems.timeout_int[0] == WLAN_TIMEOUT_ASSOC_COMEBACK) {
1445 u32 tu, ms;
1446 tu = get_unaligned_le32(elems.timeout_int + 1);
1447 ms = tu * 1024 / 1000;
1448 printk(KERN_DEBUG "%s: AP rejected association temporarily; "
1449 "comeback duration %u TU (%u ms)\n",
1450 sdata->dev->name, tu, ms);
1451 wk->timeout = jiffies + msecs_to_jiffies(ms);
1452 if (ms > IEEE80211_ASSOC_TIMEOUT)
1453 run_again(ifmgd, jiffies + msecs_to_jiffies(ms));
1454 return RX_MGMT_NONE;
1455 }
1456
1457 if (status_code != WLAN_STATUS_SUCCESS) {
1458 printk(KERN_DEBUG "%s: AP denied association (code=%d)\n",
1459 sdata->dev->name, status_code);
1460 wk->state = IEEE80211_MGD_STATE_IDLE;
1461 return RX_MGMT_CFG80211_ASSOC;
1462 }
1463 1033
1464 if ((aid & (BIT(15) | BIT(14))) != (BIT(15) | BIT(14))) 1034 if ((aid & (BIT(15) | BIT(14))) != (BIT(15) | BIT(14)))
1465 printk(KERN_DEBUG "%s: invalid aid value %d; bits 15:14 not " 1035 printk(KERN_DEBUG "%s: invalid aid value %d; bits 15:14 not "
1466 "set\n", sdata->dev->name, aid); 1036 "set\n", sdata->name, aid);
1467 aid &= ~(BIT(15) | BIT(14)); 1037 aid &= ~(BIT(15) | BIT(14));
1468 1038
1039 pos = mgmt->u.assoc_resp.variable;
1040 ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems);
1041
1469 if (!elems.supp_rates) { 1042 if (!elems.supp_rates) {
1470 printk(KERN_DEBUG "%s: no SuppRates element in AssocResp\n", 1043 printk(KERN_DEBUG "%s: no SuppRates element in AssocResp\n",
1471 sdata->dev->name); 1044 sdata->name);
1472 return RX_MGMT_NONE; 1045 return false;
1473 } 1046 }
1474 1047
1475 printk(KERN_DEBUG "%s: associated\n", sdata->dev->name);
1476 ifmgd->aid = aid; 1048 ifmgd->aid = aid;
1477 1049
1478 rcu_read_lock(); 1050 sta = sta_info_alloc(sdata, cbss->bssid, GFP_KERNEL);
1479
1480 /* Add STA entry for the AP */
1481 sta = sta_info_get(local, wk->bss->cbss.bssid);
1482 if (!sta) { 1051 if (!sta) {
1483 newsta = true; 1052 printk(KERN_DEBUG "%s: failed to alloc STA entry for"
1484 1053 " the AP\n", sdata->name);
1485 rcu_read_unlock(); 1054 return false;
1486
1487 sta = sta_info_alloc(sdata, wk->bss->cbss.bssid, GFP_KERNEL);
1488 if (!sta) {
1489 printk(KERN_DEBUG "%s: failed to alloc STA entry for"
1490 " the AP\n", sdata->dev->name);
1491 return RX_MGMT_NONE;
1492 }
1493
1494 set_sta_flags(sta, WLAN_STA_AUTH | WLAN_STA_ASSOC |
1495 WLAN_STA_ASSOC_AP);
1496 if (!(ifmgd->flags & IEEE80211_STA_CONTROL_PORT))
1497 set_sta_flags(sta, WLAN_STA_AUTHORIZED);
1498
1499 rcu_read_lock();
1500 } 1055 }
1501 1056
1057 set_sta_flags(sta, WLAN_STA_AUTH | WLAN_STA_ASSOC |
1058 WLAN_STA_ASSOC_AP);
1059 if (!(ifmgd->flags & IEEE80211_STA_CONTROL_PORT))
1060 set_sta_flags(sta, WLAN_STA_AUTHORIZED);
1061
1502 rates = 0; 1062 rates = 0;
1503 basic_rates = 0; 1063 basic_rates = 0;
1504 sband = local->hw.wiphy->bands[local->hw.conf.channel->band]; 1064 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
@@ -1561,40 +1121,40 @@ ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
1561 if (elems.wmm_param) 1121 if (elems.wmm_param)
1562 set_sta_flags(sta, WLAN_STA_WME); 1122 set_sta_flags(sta, WLAN_STA_WME);
1563 1123
1564 if (newsta) { 1124 err = sta_info_insert(sta);
1565 int err = sta_info_insert(sta); 1125 sta = NULL;
1566 if (err) { 1126 if (err) {
1567 printk(KERN_DEBUG "%s: failed to insert STA entry for" 1127 printk(KERN_DEBUG "%s: failed to insert STA entry for"
1568 " the AP (error %d)\n", sdata->dev->name, err); 1128 " the AP (error %d)\n", sdata->name, err);
1569 rcu_read_unlock(); 1129 return false;
1570 return RX_MGMT_NONE;
1571 }
1572 } 1130 }
1573 1131
1574 rcu_read_unlock();
1575
1576 if (elems.wmm_param) 1132 if (elems.wmm_param)
1577 ieee80211_sta_wmm_params(local, ifmgd, elems.wmm_param, 1133 ieee80211_sta_wmm_params(local, ifmgd, elems.wmm_param,
1578 elems.wmm_param_len); 1134 elems.wmm_param_len);
1579 else 1135 else
1580 ieee80211_set_wmm_default(sdata); 1136 ieee80211_set_wmm_default(sdata);
1581 1137
1138 local->oper_channel = wk->chan;
1139
1582 if (elems.ht_info_elem && elems.wmm_param && 1140 if (elems.ht_info_elem && elems.wmm_param &&
1583 (ifmgd->flags & IEEE80211_STA_WMM_ENABLED) && 1141 (sdata->local->hw.queues >= 4) &&
1584 !(ifmgd->flags & IEEE80211_STA_DISABLE_11N)) 1142 !(ifmgd->flags & IEEE80211_STA_DISABLE_11N))
1585 changed |= ieee80211_enable_ht(sdata, elems.ht_info_elem, 1143 changed |= ieee80211_enable_ht(sdata, elems.ht_info_elem,
1586 wk->bss->cbss.bssid, 1144 cbss->bssid, ap_ht_cap_flags);
1587 ap_ht_cap_flags);
1588
1589 /* delete work item -- must be before set_associated for PS */
1590 list_del(&wk->list);
1591 1145
1592 /* set AID and assoc capability, 1146 /* set AID and assoc capability,
1593 * ieee80211_set_associated() will tell the driver */ 1147 * ieee80211_set_associated() will tell the driver */
1594 bss_conf->aid = aid; 1148 bss_conf->aid = aid;
1595 bss_conf->assoc_capability = capab_info; 1149 bss_conf->assoc_capability = capab_info;
1596 /* this will take ownership of wk */ 1150 ieee80211_set_associated(sdata, cbss, changed);
1597 ieee80211_set_associated(sdata, wk, changed); 1151
1152 /*
1153 * If we're using 4-addr mode, let the AP know that we're
1154 * doing so, so that it can create the STA VLAN on its side
1155 */
1156 if (ifmgd->use_4addr)
1157 ieee80211_send_4addr_nullfunc(local, sdata);
1598 1158
1599 /* 1159 /*
1600 * Start timer to probe the connection to the AP now. 1160 * Start timer to probe the connection to the AP now.
@@ -1603,7 +1163,7 @@ ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
1603 ieee80211_sta_rx_notify(sdata, (struct ieee80211_hdr *)mgmt); 1163 ieee80211_sta_rx_notify(sdata, (struct ieee80211_hdr *)mgmt);
1604 mod_beacon_timer(sdata); 1164 mod_beacon_timer(sdata);
1605 1165
1606 return RX_MGMT_CFG80211_ASSOC; 1166 return true;
1607} 1167}
1608 1168
1609 1169
@@ -1618,6 +1178,13 @@ static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
1618 int freq; 1178 int freq;
1619 struct ieee80211_bss *bss; 1179 struct ieee80211_bss *bss;
1620 struct ieee80211_channel *channel; 1180 struct ieee80211_channel *channel;
1181 bool need_ps = false;
1182
1183 if (sdata->u.mgd.associated) {
1184 bss = (void *)sdata->u.mgd.associated->priv;
1185 /* not previously set so we may need to recalc */
1186 need_ps = !bss->dtim_period;
1187 }
1621 1188
1622 if (elems->ds_params && elems->ds_params_len == 1) 1189 if (elems->ds_params && elems->ds_params_len == 1)
1623 freq = ieee80211_channel_to_frequency(elems->ds_params[0]); 1190 freq = ieee80211_channel_to_frequency(elems->ds_params[0]);
@@ -1637,8 +1204,14 @@ static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
1637 if (!sdata->u.mgd.associated) 1204 if (!sdata->u.mgd.associated)
1638 return; 1205 return;
1639 1206
1207 if (need_ps) {
1208 mutex_lock(&local->iflist_mtx);
1209 ieee80211_recalc_ps(local, -1);
1210 mutex_unlock(&local->iflist_mtx);
1211 }
1212
1640 if (elems->ch_switch_elem && (elems->ch_switch_elem_len == 3) && 1213 if (elems->ch_switch_elem && (elems->ch_switch_elem_len == 3) &&
1641 (memcmp(mgmt->bssid, sdata->u.mgd.associated->cbss.bssid, 1214 (memcmp(mgmt->bssid, sdata->u.mgd.associated->bssid,
1642 ETH_ALEN) == 0)) { 1215 ETH_ALEN) == 0)) {
1643 struct ieee80211_channel_sw_ie *sw_elem = 1216 struct ieee80211_channel_sw_ie *sw_elem =
1644 (struct ieee80211_channel_sw_ie *)elems->ch_switch_elem; 1217 (struct ieee80211_channel_sw_ie *)elems->ch_switch_elem;
@@ -1648,19 +1221,19 @@ static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
1648 1221
1649 1222
1650static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_sub_if_data *sdata, 1223static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_sub_if_data *sdata,
1651 struct ieee80211_mgd_work *wk, 1224 struct sk_buff *skb)
1652 struct ieee80211_mgmt *mgmt, size_t len,
1653 struct ieee80211_rx_status *rx_status)
1654{ 1225{
1226 struct ieee80211_mgmt *mgmt = (void *)skb->data;
1655 struct ieee80211_if_managed *ifmgd; 1227 struct ieee80211_if_managed *ifmgd;
1656 size_t baselen; 1228 struct ieee80211_rx_status *rx_status = (void *) skb->cb;
1229 size_t baselen, len = skb->len;
1657 struct ieee802_11_elems elems; 1230 struct ieee802_11_elems elems;
1658 1231
1659 ifmgd = &sdata->u.mgd; 1232 ifmgd = &sdata->u.mgd;
1660 1233
1661 ASSERT_MGD_MTX(ifmgd); 1234 ASSERT_MGD_MTX(ifmgd);
1662 1235
1663 if (memcmp(mgmt->da, sdata->dev->dev_addr, ETH_ALEN)) 1236 if (memcmp(mgmt->da, sdata->vif.addr, ETH_ALEN))
1664 return; /* ignore ProbeResp to foreign address */ 1237 return; /* ignore ProbeResp to foreign address */
1665 1238
1666 baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt; 1239 baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt;
@@ -1672,17 +1245,8 @@ static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_sub_if_data *sdata,
1672 1245
1673 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems, false); 1246 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems, false);
1674 1247
1675 /* direct probe may be part of the association flow */
1676 if (wk && wk->state == IEEE80211_MGD_STATE_PROBE) {
1677 printk(KERN_DEBUG "%s: direct probe responded\n",
1678 sdata->dev->name);
1679 wk->tries = 0;
1680 wk->state = IEEE80211_MGD_STATE_AUTH;
1681 WARN_ON(ieee80211_authenticate(sdata, wk) != RX_MGMT_NONE);
1682 }
1683
1684 if (ifmgd->associated && 1248 if (ifmgd->associated &&
1685 memcmp(mgmt->bssid, ifmgd->associated->cbss.bssid, ETH_ALEN) == 0 && 1249 memcmp(mgmt->bssid, ifmgd->associated->bssid, ETH_ALEN) == 0 &&
1686 ifmgd->flags & (IEEE80211_STA_BEACON_POLL | 1250 ifmgd->flags & (IEEE80211_STA_BEACON_POLL |
1687 IEEE80211_STA_CONNECTION_POLL)) { 1251 IEEE80211_STA_CONNECTION_POLL)) {
1688 ifmgd->flags &= ~(IEEE80211_STA_CONNECTION_POLL | 1252 ifmgd->flags &= ~(IEEE80211_STA_CONNECTION_POLL |
@@ -1755,7 +1319,7 @@ static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata,
1755 if (!ifmgd->associated) 1319 if (!ifmgd->associated)
1756 return; 1320 return;
1757 1321
1758 bssid = ifmgd->associated->cbss.bssid; 1322 bssid = ifmgd->associated->bssid;
1759 1323
1760 /* 1324 /*
1761 * And in theory even frames from a different AP we were just 1325 * And in theory even frames from a different AP we were just
@@ -1768,7 +1332,7 @@ static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata,
1768#ifdef CONFIG_MAC80211_VERBOSE_DEBUG 1332#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
1769 if (net_ratelimit()) { 1333 if (net_ratelimit()) {
1770 printk(KERN_DEBUG "%s: cancelling probereq poll due " 1334 printk(KERN_DEBUG "%s: cancelling probereq poll due "
1771 "to a received beacon\n", sdata->dev->name); 1335 "to a received beacon\n", sdata->name);
1772 } 1336 }
1773#endif 1337#endif
1774 ifmgd->flags &= ~IEEE80211_STA_BEACON_POLL; 1338 ifmgd->flags &= ~IEEE80211_STA_BEACON_POLL;
@@ -1846,7 +1410,7 @@ static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata,
1846 1410
1847 rcu_read_lock(); 1411 rcu_read_lock();
1848 1412
1849 sta = sta_info_get(local, bssid); 1413 sta = sta_info_get(sdata, bssid);
1850 if (WARN_ON(!sta)) { 1414 if (WARN_ON(!sta)) {
1851 rcu_read_unlock(); 1415 rcu_read_unlock();
1852 return; 1416 return;
@@ -1892,12 +1456,8 @@ ieee80211_rx_result ieee80211_sta_rx_mgmt(struct ieee80211_sub_if_data *sdata,
1892 fc = le16_to_cpu(mgmt->frame_control); 1456 fc = le16_to_cpu(mgmt->frame_control);
1893 1457
1894 switch (fc & IEEE80211_FCTL_STYPE) { 1458 switch (fc & IEEE80211_FCTL_STYPE) {
1895 case IEEE80211_STYPE_PROBE_REQ:
1896 case IEEE80211_STYPE_PROBE_RESP: 1459 case IEEE80211_STYPE_PROBE_RESP:
1897 case IEEE80211_STYPE_BEACON: 1460 case IEEE80211_STYPE_BEACON:
1898 case IEEE80211_STYPE_AUTH:
1899 case IEEE80211_STYPE_ASSOC_RESP:
1900 case IEEE80211_STYPE_REASSOC_RESP:
1901 case IEEE80211_STYPE_DEAUTH: 1461 case IEEE80211_STYPE_DEAUTH:
1902 case IEEE80211_STYPE_DISASSOC: 1462 case IEEE80211_STYPE_DISASSOC:
1903 case IEEE80211_STYPE_ACTION: 1463 case IEEE80211_STYPE_ACTION:
@@ -1915,7 +1475,6 @@ static void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
1915 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 1475 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1916 struct ieee80211_rx_status *rx_status; 1476 struct ieee80211_rx_status *rx_status;
1917 struct ieee80211_mgmt *mgmt; 1477 struct ieee80211_mgmt *mgmt;
1918 struct ieee80211_mgd_work *wk;
1919 enum rx_mgmt_action rma = RX_MGMT_NONE; 1478 enum rx_mgmt_action rma = RX_MGMT_NONE;
1920 u16 fc; 1479 u16 fc;
1921 1480
@@ -1926,29 +1485,28 @@ static void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
1926 mutex_lock(&ifmgd->mtx); 1485 mutex_lock(&ifmgd->mtx);
1927 1486
1928 if (ifmgd->associated && 1487 if (ifmgd->associated &&
1929 memcmp(ifmgd->associated->cbss.bssid, mgmt->bssid, 1488 memcmp(ifmgd->associated->bssid, mgmt->bssid, ETH_ALEN) == 0) {
1930 ETH_ALEN) == 0) {
1931 switch (fc & IEEE80211_FCTL_STYPE) { 1489 switch (fc & IEEE80211_FCTL_STYPE) {
1932 case IEEE80211_STYPE_BEACON: 1490 case IEEE80211_STYPE_BEACON:
1933 ieee80211_rx_mgmt_beacon(sdata, mgmt, skb->len, 1491 ieee80211_rx_mgmt_beacon(sdata, mgmt, skb->len,
1934 rx_status); 1492 rx_status);
1935 break; 1493 break;
1936 case IEEE80211_STYPE_PROBE_RESP: 1494 case IEEE80211_STYPE_PROBE_RESP:
1937 ieee80211_rx_mgmt_probe_resp(sdata, NULL, mgmt, 1495 ieee80211_rx_mgmt_probe_resp(sdata, skb);
1938 skb->len, rx_status);
1939 break; 1496 break;
1940 case IEEE80211_STYPE_DEAUTH: 1497 case IEEE80211_STYPE_DEAUTH:
1941 rma = ieee80211_rx_mgmt_deauth(sdata, NULL, 1498 rma = ieee80211_rx_mgmt_deauth(sdata, mgmt, skb->len);
1942 mgmt, skb->len);
1943 break; 1499 break;
1944 case IEEE80211_STYPE_DISASSOC: 1500 case IEEE80211_STYPE_DISASSOC:
1945 rma = ieee80211_rx_mgmt_disassoc(sdata, mgmt, skb->len); 1501 rma = ieee80211_rx_mgmt_disassoc(sdata, mgmt, skb->len);
1946 break; 1502 break;
1947 case IEEE80211_STYPE_ACTION: 1503 case IEEE80211_STYPE_ACTION:
1948 /* XXX: differentiate, can only happen for CSA now! */ 1504 if (mgmt->u.action.category != WLAN_CATEGORY_SPECTRUM_MGMT)
1505 break;
1506
1949 ieee80211_sta_process_chanswitch(sdata, 1507 ieee80211_sta_process_chanswitch(sdata,
1950 &mgmt->u.action.u.chan_switch.sw_elem, 1508 &mgmt->u.action.u.chan_switch.sw_elem,
1951 ifmgd->associated); 1509 (void *)ifmgd->associated->priv);
1952 break; 1510 break;
1953 } 1511 }
1954 mutex_unlock(&ifmgd->mtx); 1512 mutex_unlock(&ifmgd->mtx);
@@ -1958,12 +1516,10 @@ static void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
1958 /* no action */ 1516 /* no action */
1959 break; 1517 break;
1960 case RX_MGMT_CFG80211_DEAUTH: 1518 case RX_MGMT_CFG80211_DEAUTH:
1961 cfg80211_send_deauth(sdata->dev, (u8 *)mgmt, skb->len, 1519 cfg80211_send_deauth(sdata->dev, (u8 *)mgmt, skb->len);
1962 NULL);
1963 break; 1520 break;
1964 case RX_MGMT_CFG80211_DISASSOC: 1521 case RX_MGMT_CFG80211_DISASSOC:
1965 cfg80211_send_disassoc(sdata->dev, (u8 *)mgmt, skb->len, 1522 cfg80211_send_disassoc(sdata->dev, (u8 *)mgmt, skb->len);
1966 NULL);
1967 break; 1523 break;
1968 default: 1524 default:
1969 WARN(1, "unexpected: %d", rma); 1525 WARN(1, "unexpected: %d", rma);
@@ -1971,58 +1527,11 @@ static void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
1971 goto out; 1527 goto out;
1972 } 1528 }
1973 1529
1974 list_for_each_entry(wk, &ifmgd->work_list, list) {
1975 if (memcmp(wk->bss->cbss.bssid, mgmt->bssid, ETH_ALEN) != 0)
1976 continue;
1977
1978 switch (fc & IEEE80211_FCTL_STYPE) {
1979 case IEEE80211_STYPE_PROBE_RESP:
1980 ieee80211_rx_mgmt_probe_resp(sdata, wk, mgmt, skb->len,
1981 rx_status);
1982 break;
1983 case IEEE80211_STYPE_AUTH:
1984 rma = ieee80211_rx_mgmt_auth(sdata, wk, mgmt, skb->len);
1985 break;
1986 case IEEE80211_STYPE_ASSOC_RESP:
1987 rma = ieee80211_rx_mgmt_assoc_resp(sdata, wk, mgmt,
1988 skb->len, false);
1989 break;
1990 case IEEE80211_STYPE_REASSOC_RESP:
1991 rma = ieee80211_rx_mgmt_assoc_resp(sdata, wk, mgmt,
1992 skb->len, true);
1993 break;
1994 case IEEE80211_STYPE_DEAUTH:
1995 rma = ieee80211_rx_mgmt_deauth(sdata, wk, mgmt,
1996 skb->len);
1997 break;
1998 }
1999 /*
2000 * We've processed this frame for that work, so it can't
2001 * belong to another work struct.
2002 * NB: this is also required for correctness because the
2003 * called functions can free 'wk', and for 'rma'!
2004 */
2005 break;
2006 }
2007
2008 mutex_unlock(&ifmgd->mtx); 1530 mutex_unlock(&ifmgd->mtx);
2009 1531
2010 switch (rma) { 1532 if (skb->len >= 24 + 2 /* mgmt + deauth reason */ &&
2011 case RX_MGMT_NONE: 1533 (fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_DEAUTH)
2012 /* no action */ 1534 cfg80211_send_deauth(sdata->dev, (u8 *)mgmt, skb->len);
2013 break;
2014 case RX_MGMT_CFG80211_AUTH:
2015 cfg80211_send_rx_auth(sdata->dev, (u8 *) mgmt, skb->len);
2016 break;
2017 case RX_MGMT_CFG80211_ASSOC:
2018 cfg80211_send_rx_assoc(sdata->dev, (u8 *) mgmt, skb->len);
2019 break;
2020 case RX_MGMT_CFG80211_DEAUTH:
2021 cfg80211_send_deauth(sdata->dev, (u8 *)mgmt, skb->len, NULL);
2022 break;
2023 default:
2024 WARN(1, "unexpected: %d", rma);
2025 }
2026 1535
2027 out: 1536 out:
2028 kfree_skb(skb); 1537 kfree_skb(skb);
@@ -2050,12 +1559,8 @@ static void ieee80211_sta_work(struct work_struct *work)
2050 struct ieee80211_local *local = sdata->local; 1559 struct ieee80211_local *local = sdata->local;
2051 struct ieee80211_if_managed *ifmgd; 1560 struct ieee80211_if_managed *ifmgd;
2052 struct sk_buff *skb; 1561 struct sk_buff *skb;
2053 struct ieee80211_mgd_work *wk, *tmp;
2054 LIST_HEAD(free_work);
2055 enum rx_mgmt_action rma;
2056 bool anybusy = false;
2057 1562
2058 if (!netif_running(sdata->dev)) 1563 if (!ieee80211_sdata_running(sdata))
2059 return; 1564 return;
2060 1565
2061 if (local->scanning) 1566 if (local->scanning)
@@ -2086,7 +1591,7 @@ static void ieee80211_sta_work(struct work_struct *work)
2086 ifmgd->associated) { 1591 ifmgd->associated) {
2087 u8 bssid[ETH_ALEN]; 1592 u8 bssid[ETH_ALEN];
2088 1593
2089 memcpy(bssid, ifmgd->associated->cbss.bssid, ETH_ALEN); 1594 memcpy(bssid, ifmgd->associated->bssid, ETH_ALEN);
2090 if (time_is_after_jiffies(ifmgd->probe_timeout)) 1595 if (time_is_after_jiffies(ifmgd->probe_timeout))
2091 run_again(ifmgd, ifmgd->probe_timeout); 1596 run_again(ifmgd, ifmgd->probe_timeout);
2092 1597
@@ -2108,7 +1613,8 @@ static void ieee80211_sta_work(struct work_struct *work)
2108 printk(KERN_DEBUG "No probe response from AP %pM" 1613 printk(KERN_DEBUG "No probe response from AP %pM"
2109 " after %dms, disconnecting.\n", 1614 " after %dms, disconnecting.\n",
2110 bssid, (1000 * IEEE80211_PROBE_WAIT)/HZ); 1615 bssid, (1000 * IEEE80211_PROBE_WAIT)/HZ);
2111 ieee80211_set_disassoc(sdata, true); 1616 ieee80211_set_disassoc(sdata);
1617 ieee80211_recalc_idle(local);
2112 mutex_unlock(&ifmgd->mtx); 1618 mutex_unlock(&ifmgd->mtx);
2113 /* 1619 /*
2114 * must be outside lock due to cfg80211, 1620 * must be outside lock due to cfg80211,
@@ -2122,87 +1628,7 @@ static void ieee80211_sta_work(struct work_struct *work)
2122 } 1628 }
2123 } 1629 }
2124 1630
2125
2126 ieee80211_recalc_idle(local);
2127
2128 list_for_each_entry_safe(wk, tmp, &ifmgd->work_list, list) {
2129 if (time_is_after_jiffies(wk->timeout)) {
2130 /*
2131 * This work item isn't supposed to be worked on
2132 * right now, but take care to adjust the timer
2133 * properly.
2134 */
2135 run_again(ifmgd, wk->timeout);
2136 continue;
2137 }
2138
2139 switch (wk->state) {
2140 default:
2141 WARN_ON(1);
2142 /* fall through */
2143 case IEEE80211_MGD_STATE_IDLE:
2144 /* nothing */
2145 rma = RX_MGMT_NONE;
2146 break;
2147 case IEEE80211_MGD_STATE_PROBE:
2148 rma = ieee80211_direct_probe(sdata, wk);
2149 break;
2150 case IEEE80211_MGD_STATE_AUTH:
2151 rma = ieee80211_authenticate(sdata, wk);
2152 break;
2153 case IEEE80211_MGD_STATE_ASSOC:
2154 rma = ieee80211_associate(sdata, wk);
2155 break;
2156 }
2157
2158 switch (rma) {
2159 case RX_MGMT_NONE:
2160 /* no action required */
2161 break;
2162 case RX_MGMT_CFG80211_AUTH_TO:
2163 case RX_MGMT_CFG80211_ASSOC_TO:
2164 list_del(&wk->list);
2165 list_add(&wk->list, &free_work);
2166 wk->tries = rma; /* small abuse but only local */
2167 break;
2168 default:
2169 WARN(1, "unexpected: %d", rma);
2170 }
2171 }
2172
2173 list_for_each_entry(wk, &ifmgd->work_list, list) {
2174 if (wk->state != IEEE80211_MGD_STATE_IDLE) {
2175 anybusy = true;
2176 break;
2177 }
2178 }
2179 if (!anybusy &&
2180 test_and_clear_bit(IEEE80211_STA_REQ_SCAN, &ifmgd->request))
2181 ieee80211_queue_delayed_work(&local->hw,
2182 &local->scan_work,
2183 round_jiffies_relative(0));
2184
2185 mutex_unlock(&ifmgd->mtx); 1631 mutex_unlock(&ifmgd->mtx);
2186
2187 list_for_each_entry_safe(wk, tmp, &free_work, list) {
2188 switch (wk->tries) {
2189 case RX_MGMT_CFG80211_AUTH_TO:
2190 cfg80211_send_auth_timeout(sdata->dev,
2191 wk->bss->cbss.bssid);
2192 break;
2193 case RX_MGMT_CFG80211_ASSOC_TO:
2194 cfg80211_send_assoc_timeout(sdata->dev,
2195 wk->bss->cbss.bssid);
2196 break;
2197 default:
2198 WARN(1, "unexpected: %d", wk->tries);
2199 }
2200
2201 list_del(&wk->list);
2202 kfree(wk);
2203 }
2204
2205 ieee80211_recalc_idle(local);
2206} 1632}
2207 1633
2208static void ieee80211_sta_bcn_mon_timer(unsigned long data) 1634static void ieee80211_sta_bcn_mon_timer(unsigned long data)
@@ -2311,14 +1737,14 @@ void ieee80211_sta_setup_sdata(struct ieee80211_sub_if_data *sdata)
2311 (unsigned long) sdata); 1737 (unsigned long) sdata);
2312 skb_queue_head_init(&ifmgd->skb_queue); 1738 skb_queue_head_init(&ifmgd->skb_queue);
2313 1739
2314 INIT_LIST_HEAD(&ifmgd->work_list);
2315
2316 ifmgd->capab = WLAN_CAPABILITY_ESS;
2317 ifmgd->flags = 0; 1740 ifmgd->flags = 0;
2318 if (sdata->local->hw.queues >= 4)
2319 ifmgd->flags |= IEEE80211_STA_WMM_ENABLED;
2320 1741
2321 mutex_init(&ifmgd->mtx); 1742 mutex_init(&ifmgd->mtx);
1743
1744 if (sdata->local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS)
1745 ifmgd->req_smps = IEEE80211_SMPS_AUTOMATIC;
1746 else
1747 ifmgd->req_smps = IEEE80211_SMPS_OFF;
2322} 1748}
2323 1749
2324/* scan finished notification */ 1750/* scan finished notification */
@@ -2349,12 +1775,34 @@ int ieee80211_max_network_latency(struct notifier_block *nb,
2349} 1775}
2350 1776
2351/* config hooks */ 1777/* config hooks */
1778static enum work_done_result
1779ieee80211_probe_auth_done(struct ieee80211_work *wk,
1780 struct sk_buff *skb)
1781{
1782 if (!skb) {
1783 cfg80211_send_auth_timeout(wk->sdata->dev, wk->filter_ta);
1784 return WORK_DONE_DESTROY;
1785 }
1786
1787 if (wk->type == IEEE80211_WORK_AUTH) {
1788 cfg80211_send_rx_auth(wk->sdata->dev, skb->data, skb->len);
1789 return WORK_DONE_DESTROY;
1790 }
1791
1792 mutex_lock(&wk->sdata->u.mgd.mtx);
1793 ieee80211_rx_mgmt_probe_resp(wk->sdata, skb);
1794 mutex_unlock(&wk->sdata->u.mgd.mtx);
1795
1796 wk->type = IEEE80211_WORK_AUTH;
1797 wk->probe_auth.tries = 0;
1798 return WORK_DONE_REQUEUE;
1799}
1800
2352int ieee80211_mgd_auth(struct ieee80211_sub_if_data *sdata, 1801int ieee80211_mgd_auth(struct ieee80211_sub_if_data *sdata,
2353 struct cfg80211_auth_request *req) 1802 struct cfg80211_auth_request *req)
2354{ 1803{
2355 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2356 const u8 *ssid; 1804 const u8 *ssid;
2357 struct ieee80211_mgd_work *wk; 1805 struct ieee80211_work *wk;
2358 u16 auth_alg; 1806 u16 auth_alg;
2359 1807
2360 switch (req->auth_type) { 1808 switch (req->auth_type) {
@@ -2378,7 +1826,7 @@ int ieee80211_mgd_auth(struct ieee80211_sub_if_data *sdata,
2378 if (!wk) 1826 if (!wk)
2379 return -ENOMEM; 1827 return -ENOMEM;
2380 1828
2381 wk->bss = (void *)req->bss; 1829 memcpy(wk->filter_ta, req->bss->bssid, ETH_ALEN);
2382 1830
2383 if (req->ie && req->ie_len) { 1831 if (req->ie && req->ie_len) {
2384 memcpy(wk->ie, req->ie, req->ie_len); 1832 memcpy(wk->ie, req->ie, req->ie_len);
@@ -2386,68 +1834,95 @@ int ieee80211_mgd_auth(struct ieee80211_sub_if_data *sdata,
2386 } 1834 }
2387 1835
2388 if (req->key && req->key_len) { 1836 if (req->key && req->key_len) {
2389 wk->key_len = req->key_len; 1837 wk->probe_auth.key_len = req->key_len;
2390 wk->key_idx = req->key_idx; 1838 wk->probe_auth.key_idx = req->key_idx;
2391 memcpy(wk->key, req->key, req->key_len); 1839 memcpy(wk->probe_auth.key, req->key, req->key_len);
2392 } 1840 }
2393 1841
2394 ssid = ieee80211_bss_get_ie(req->bss, WLAN_EID_SSID); 1842 ssid = ieee80211_bss_get_ie(req->bss, WLAN_EID_SSID);
2395 memcpy(wk->ssid, ssid + 2, ssid[1]); 1843 memcpy(wk->probe_auth.ssid, ssid + 2, ssid[1]);
2396 wk->ssid_len = ssid[1]; 1844 wk->probe_auth.ssid_len = ssid[1];
2397 1845
2398 wk->state = IEEE80211_MGD_STATE_PROBE; 1846 wk->probe_auth.algorithm = auth_alg;
2399 wk->auth_alg = auth_alg; 1847 wk->probe_auth.privacy = req->bss->capability & WLAN_CAPABILITY_PRIVACY;
2400 wk->timeout = jiffies; /* run right away */
2401 1848
2402 /* 1849 /* if we already have a probe, don't probe again */
2403 * XXX: if still associated need to tell AP that we're going 1850 if (req->bss->proberesp_ies)
2404 * to sleep and then change channel etc. 1851 wk->type = IEEE80211_WORK_AUTH;
2405 */ 1852 else
2406 sdata->local->oper_channel = req->bss->channel; 1853 wk->type = IEEE80211_WORK_DIRECT_PROBE;
2407 ieee80211_hw_config(sdata->local, 0); 1854 wk->chan = req->bss->channel;
2408 1855 wk->sdata = sdata;
2409 mutex_lock(&ifmgd->mtx); 1856 wk->done = ieee80211_probe_auth_done;
2410 list_add(&wk->list, &sdata->u.mgd.work_list);
2411 mutex_unlock(&ifmgd->mtx);
2412 1857
2413 ieee80211_queue_work(&sdata->local->hw, &sdata->u.mgd.work); 1858 ieee80211_add_work(wk);
2414 return 0; 1859 return 0;
2415} 1860}
2416 1861
2417int ieee80211_mgd_assoc(struct ieee80211_sub_if_data *sdata, 1862static enum work_done_result ieee80211_assoc_done(struct ieee80211_work *wk,
2418 struct cfg80211_assoc_request *req) 1863 struct sk_buff *skb)
2419{ 1864{
2420 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 1865 struct ieee80211_mgmt *mgmt;
2421 struct ieee80211_mgd_work *wk, *found = NULL; 1866 u16 status;
2422 int i, err;
2423 1867
2424 mutex_lock(&ifmgd->mtx); 1868 if (!skb) {
1869 cfg80211_send_assoc_timeout(wk->sdata->dev, wk->filter_ta);
1870 return WORK_DONE_DESTROY;
1871 }
2425 1872
2426 list_for_each_entry(wk, &ifmgd->work_list, list) { 1873 mgmt = (void *)skb->data;
2427 if (&wk->bss->cbss == req->bss && 1874 status = le16_to_cpu(mgmt->u.assoc_resp.status_code);
2428 wk->state == IEEE80211_MGD_STATE_IDLE) { 1875
2429 found = wk; 1876 if (status == WLAN_STATUS_SUCCESS) {
2430 break; 1877 mutex_lock(&wk->sdata->u.mgd.mtx);
1878 if (!ieee80211_assoc_success(wk, mgmt, skb->len)) {
1879 mutex_unlock(&wk->sdata->u.mgd.mtx);
1880 /* oops -- internal error -- send timeout for now */
1881 cfg80211_send_assoc_timeout(wk->sdata->dev,
1882 wk->filter_ta);
1883 return WORK_DONE_DESTROY;
2431 } 1884 }
1885 mutex_unlock(&wk->sdata->u.mgd.mtx);
2432 } 1886 }
2433 1887
2434 if (!found) { 1888 cfg80211_send_rx_assoc(wk->sdata->dev, skb->data, skb->len);
2435 err = -ENOLINK; 1889 return WORK_DONE_DESTROY;
2436 goto out; 1890}
2437 }
2438 1891
2439 list_del(&found->list); 1892int ieee80211_mgd_assoc(struct ieee80211_sub_if_data *sdata,
1893 struct cfg80211_assoc_request *req)
1894{
1895 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1896 struct ieee80211_bss *bss = (void *)req->bss->priv;
1897 struct ieee80211_work *wk;
1898 const u8 *ssid;
1899 int i;
2440 1900
2441 wk = krealloc(found, sizeof(*wk) + req->ie_len, GFP_KERNEL); 1901 mutex_lock(&ifmgd->mtx);
2442 if (!wk) { 1902 if (ifmgd->associated) {
2443 list_add(&found->list, &ifmgd->work_list); 1903 if (!req->prev_bssid ||
2444 err = -ENOMEM; 1904 memcmp(req->prev_bssid, ifmgd->associated->bssid,
2445 goto out; 1905 ETH_ALEN)) {
1906 /*
1907 * We are already associated and the request was not a
1908 * reassociation request from the current BSS, so
1909 * reject it.
1910 */
1911 mutex_unlock(&ifmgd->mtx);
1912 return -EALREADY;
1913 }
1914
1915 /* Trying to reassociate - clear previous association state */
1916 ieee80211_set_disassoc(sdata);
2446 } 1917 }
1918 mutex_unlock(&ifmgd->mtx);
2447 1919
2448 list_add(&wk->list, &ifmgd->work_list); 1920 wk = kzalloc(sizeof(*wk) + req->ie_len, GFP_KERNEL);
1921 if (!wk)
1922 return -ENOMEM;
2449 1923
2450 ifmgd->flags &= ~IEEE80211_STA_DISABLE_11N; 1924 ifmgd->flags &= ~IEEE80211_STA_DISABLE_11N;
1925 ifmgd->flags &= ~IEEE80211_STA_NULLFUNC_ACKED;
2451 1926
2452 for (i = 0; i < req->crypto.n_ciphers_pairwise; i++) 1927 for (i = 0; i < req->crypto.n_ciphers_pairwise; i++)
2453 if (req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP40 || 1928 if (req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP40 ||
@@ -2455,8 +1930,6 @@ int ieee80211_mgd_assoc(struct ieee80211_sub_if_data *sdata,
2455 req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP104) 1930 req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP104)
2456 ifmgd->flags |= IEEE80211_STA_DISABLE_11N; 1931 ifmgd->flags |= IEEE80211_STA_DISABLE_11N;
2457 1932
2458 sdata->local->oper_channel = req->bss->channel;
2459 ieee80211_hw_config(sdata->local, 0);
2460 1933
2461 if (req->ie && req->ie_len) { 1934 if (req->ie && req->ie_len) {
2462 memcpy(wk->ie, req->ie, req->ie_len); 1935 memcpy(wk->ie, req->ie, req->ie_len);
@@ -2464,12 +1937,55 @@ int ieee80211_mgd_assoc(struct ieee80211_sub_if_data *sdata,
2464 } else 1937 } else
2465 wk->ie_len = 0; 1938 wk->ie_len = 0;
2466 1939
1940 wk->assoc.bss = req->bss;
1941
1942 memcpy(wk->filter_ta, req->bss->bssid, ETH_ALEN);
1943
1944 /* new association always uses requested smps mode */
1945 if (ifmgd->req_smps == IEEE80211_SMPS_AUTOMATIC) {
1946 if (ifmgd->powersave)
1947 ifmgd->ap_smps = IEEE80211_SMPS_DYNAMIC;
1948 else
1949 ifmgd->ap_smps = IEEE80211_SMPS_OFF;
1950 } else
1951 ifmgd->ap_smps = ifmgd->req_smps;
1952
1953 wk->assoc.smps = ifmgd->ap_smps;
1954 /*
1955 * IEEE802.11n does not allow TKIP/WEP as pairwise ciphers in HT mode.
1956 * We still associate in non-HT mode (11a/b/g) if any one of these
1957 * ciphers is configured as pairwise.
1958 * We can set this to true for non-11n hardware, that'll be checked
1959 * separately along with the peer capabilities.
1960 */
1961 wk->assoc.use_11n = !(ifmgd->flags & IEEE80211_STA_DISABLE_11N);
1962 wk->assoc.capability = req->bss->capability;
1963 wk->assoc.wmm_used = bss->wmm_used;
1964 wk->assoc.supp_rates = bss->supp_rates;
1965 wk->assoc.supp_rates_len = bss->supp_rates_len;
1966 wk->assoc.ht_information_ie =
1967 ieee80211_bss_get_ie(req->bss, WLAN_EID_HT_INFORMATION);
1968
1969 if (bss->wmm_used && bss->uapsd_supported &&
1970 (sdata->local->hw.flags & IEEE80211_HW_SUPPORTS_UAPSD)) {
1971 wk->assoc.uapsd_used = true;
1972 ifmgd->flags |= IEEE80211_STA_UAPSD_ENABLED;
1973 } else {
1974 wk->assoc.uapsd_used = false;
1975 ifmgd->flags &= ~IEEE80211_STA_UAPSD_ENABLED;
1976 }
1977
1978 ssid = ieee80211_bss_get_ie(req->bss, WLAN_EID_SSID);
1979 memcpy(wk->assoc.ssid, ssid + 2, ssid[1]);
1980 wk->assoc.ssid_len = ssid[1];
1981
2467 if (req->prev_bssid) 1982 if (req->prev_bssid)
2468 memcpy(wk->prev_bssid, req->prev_bssid, ETH_ALEN); 1983 memcpy(wk->assoc.prev_bssid, req->prev_bssid, ETH_ALEN);
2469 1984
2470 wk->state = IEEE80211_MGD_STATE_ASSOC; 1985 wk->type = IEEE80211_WORK_ASSOC;
2471 wk->tries = 0; 1986 wk->chan = req->bss->channel;
2472 wk->timeout = jiffies; /* run right away */ 1987 wk->sdata = sdata;
1988 wk->done = ieee80211_assoc_done;
2473 1989
2474 if (req->use_mfp) { 1990 if (req->use_mfp) {
2475 ifmgd->mfp = IEEE80211_MFP_REQUIRED; 1991 ifmgd->mfp = IEEE80211_MFP_REQUIRED;
@@ -2484,57 +2000,73 @@ int ieee80211_mgd_assoc(struct ieee80211_sub_if_data *sdata,
2484 else 2000 else
2485 ifmgd->flags &= ~IEEE80211_STA_CONTROL_PORT; 2001 ifmgd->flags &= ~IEEE80211_STA_CONTROL_PORT;
2486 2002
2487 ieee80211_queue_work(&sdata->local->hw, &sdata->u.mgd.work); 2003 ieee80211_add_work(wk);
2488 2004 return 0;
2489 err = 0;
2490
2491 out:
2492 mutex_unlock(&ifmgd->mtx);
2493 return err;
2494} 2005}
2495 2006
2496int ieee80211_mgd_deauth(struct ieee80211_sub_if_data *sdata, 2007int ieee80211_mgd_deauth(struct ieee80211_sub_if_data *sdata,
2497 struct cfg80211_deauth_request *req, 2008 struct cfg80211_deauth_request *req,
2498 void *cookie) 2009 void *cookie)
2499{ 2010{
2011 struct ieee80211_local *local = sdata->local;
2500 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 2012 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2501 struct ieee80211_mgd_work *wk; 2013 struct ieee80211_work *wk;
2502 const u8 *bssid = NULL; 2014 const u8 *bssid = req->bss->bssid;
2503 2015
2504 mutex_lock(&ifmgd->mtx); 2016 mutex_lock(&ifmgd->mtx);
2505 2017
2506 if (ifmgd->associated && &ifmgd->associated->cbss == req->bss) { 2018 if (ifmgd->associated == req->bss) {
2507 bssid = req->bss->bssid; 2019 bssid = req->bss->bssid;
2508 ieee80211_set_disassoc(sdata, true); 2020 ieee80211_set_disassoc(sdata);
2509 } else list_for_each_entry(wk, &ifmgd->work_list, list) { 2021 mutex_unlock(&ifmgd->mtx);
2510 if (&wk->bss->cbss == req->bss) { 2022 } else {
2511 bssid = req->bss->bssid; 2023 bool not_auth_yet = false;
2512 list_del(&wk->list); 2024
2513 kfree(wk); 2025 mutex_unlock(&ifmgd->mtx);
2026
2027 mutex_lock(&local->work_mtx);
2028 list_for_each_entry(wk, &local->work_list, list) {
2029 if (wk->sdata != sdata)
2030 continue;
2031
2032 if (wk->type != IEEE80211_WORK_DIRECT_PROBE &&
2033 wk->type != IEEE80211_WORK_AUTH &&
2034 wk->type != IEEE80211_WORK_ASSOC)
2035 continue;
2036
2037 if (memcmp(req->bss->bssid, wk->filter_ta, ETH_ALEN))
2038 continue;
2039
2040 not_auth_yet = wk->type == IEEE80211_WORK_DIRECT_PROBE;
2041 list_del_rcu(&wk->list);
2042 free_work(wk);
2514 break; 2043 break;
2515 } 2044 }
2516 } 2045 mutex_unlock(&local->work_mtx);
2517 2046
2518 /* 2047 /*
2519 * cfg80211 should catch this ... but it's racy since 2048 * If somebody requests authentication and we haven't
2520 * we can receive a deauth frame, process it, hand it 2049 * sent out an auth frame yet there's no need to send
2521 * to cfg80211 while that's in a locked section already 2050 * out a deauth frame either. If the state was PROBE,
2522 * trying to tell us that the user wants to disconnect. 2051 * then this is the case. If it's AUTH we have sent a
2523 */ 2052 * frame, and if it's IDLE we have completed the auth
2524 if (!bssid) { 2053 * process already.
2525 mutex_unlock(&ifmgd->mtx); 2054 */
2526 return -ENOLINK; 2055 if (not_auth_yet) {
2056 __cfg80211_auth_canceled(sdata->dev, bssid);
2057 return 0;
2058 }
2527 } 2059 }
2528 2060
2529 mutex_unlock(&ifmgd->mtx);
2530
2531 printk(KERN_DEBUG "%s: deauthenticating from %pM by local choice (reason=%d)\n", 2061 printk(KERN_DEBUG "%s: deauthenticating from %pM by local choice (reason=%d)\n",
2532 sdata->dev->name, bssid, req->reason_code); 2062 sdata->name, bssid, req->reason_code);
2533 2063
2534 ieee80211_send_deauth_disassoc(sdata, bssid, 2064 ieee80211_send_deauth_disassoc(sdata, bssid,
2535 IEEE80211_STYPE_DEAUTH, req->reason_code, 2065 IEEE80211_STYPE_DEAUTH, req->reason_code,
2536 cookie); 2066 cookie);
2537 2067
2068 ieee80211_recalc_idle(sdata->local);
2069
2538 return 0; 2070 return 0;
2539} 2071}
2540 2072
@@ -2552,20 +2084,58 @@ int ieee80211_mgd_disassoc(struct ieee80211_sub_if_data *sdata,
2552 * to cfg80211 while that's in a locked section already 2084 * to cfg80211 while that's in a locked section already
2553 * trying to tell us that the user wants to disconnect. 2085 * trying to tell us that the user wants to disconnect.
2554 */ 2086 */
2555 if (&ifmgd->associated->cbss != req->bss) { 2087 if (ifmgd->associated != req->bss) {
2556 mutex_unlock(&ifmgd->mtx); 2088 mutex_unlock(&ifmgd->mtx);
2557 return -ENOLINK; 2089 return -ENOLINK;
2558 } 2090 }
2559 2091
2560 printk(KERN_DEBUG "%s: disassociating from %pM by local choice (reason=%d)\n", 2092 printk(KERN_DEBUG "%s: disassociating from %pM by local choice (reason=%d)\n",
2561 sdata->dev->name, req->bss->bssid, req->reason_code); 2093 sdata->name, req->bss->bssid, req->reason_code);
2562 2094
2563 ieee80211_set_disassoc(sdata, false); 2095 ieee80211_set_disassoc(sdata);
2564 2096
2565 mutex_unlock(&ifmgd->mtx); 2097 mutex_unlock(&ifmgd->mtx);
2566 2098
2567 ieee80211_send_deauth_disassoc(sdata, req->bss->bssid, 2099 ieee80211_send_deauth_disassoc(sdata, req->bss->bssid,
2568 IEEE80211_STYPE_DISASSOC, req->reason_code, 2100 IEEE80211_STYPE_DISASSOC, req->reason_code,
2569 cookie); 2101 cookie);
2102
2103 ieee80211_recalc_idle(sdata->local);
2104
2105 return 0;
2106}
2107
2108int ieee80211_mgd_action(struct ieee80211_sub_if_data *sdata,
2109 struct ieee80211_channel *chan,
2110 enum nl80211_channel_type channel_type,
2111 const u8 *buf, size_t len, u64 *cookie)
2112{
2113 struct ieee80211_local *local = sdata->local;
2114 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2115 struct sk_buff *skb;
2116
2117 /* Check that we are on the requested channel for transmission */
2118 if ((chan != local->tmp_channel ||
2119 channel_type != local->tmp_channel_type) &&
2120 (chan != local->oper_channel ||
2121 channel_type != local->oper_channel_type))
2122 return -EBUSY;
2123
2124 skb = dev_alloc_skb(local->hw.extra_tx_headroom + len);
2125 if (!skb)
2126 return -ENOMEM;
2127 skb_reserve(skb, local->hw.extra_tx_headroom);
2128
2129 memcpy(skb_put(skb, len), buf, len);
2130
2131 if (!(ifmgd->flags & IEEE80211_STA_MFP_ENABLED))
2132 IEEE80211_SKB_CB(skb)->flags |=
2133 IEEE80211_TX_INTFL_DONT_ENCRYPT;
2134 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_NL80211_FRAME_TX |
2135 IEEE80211_TX_CTL_REQ_TX_STATUS;
2136 skb->dev = sdata->dev;
2137 ieee80211_tx_skb(sdata, skb);
2138
2139 *cookie = (unsigned long) skb;
2570 return 0; 2140 return 0;
2571} 2141}
diff --git a/net/mac80211/offchannel.c b/net/mac80211/offchannel.c
new file mode 100644
index 000000000000..c36b1911987a
--- /dev/null
+++ b/net/mac80211/offchannel.c
@@ -0,0 +1,170 @@
1/*
2 * Off-channel operation helpers
3 *
4 * Copyright 2003, Jouni Malinen <jkmaline@cc.hut.fi>
5 * Copyright 2004, Instant802 Networks, Inc.
6 * Copyright 2005, Devicescape Software, Inc.
7 * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz>
8 * Copyright 2007, Michael Wu <flamingice@sourmilk.net>
9 * Copyright 2009 Johannes Berg <johannes@sipsolutions.net>
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
14 */
15#include <net/mac80211.h>
16#include "ieee80211_i.h"
17
18/*
19 * inform AP that we will go to sleep so that it will buffer the frames
20 * while we scan
21 */
22static void ieee80211_offchannel_ps_enable(struct ieee80211_sub_if_data *sdata)
23{
24 struct ieee80211_local *local = sdata->local;
25
26 local->offchannel_ps_enabled = false;
27
28 /* FIXME: what to do when local->pspolling is true? */
29
30 del_timer_sync(&local->dynamic_ps_timer);
31 cancel_work_sync(&local->dynamic_ps_enable_work);
32
33 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
34 local->offchannel_ps_enabled = true;
35 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
36 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
37 }
38
39 if (!(local->offchannel_ps_enabled) ||
40 !(local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK))
41 /*
42 * If power save was enabled, no need to send a nullfunc
43 * frame because AP knows that we are sleeping. But if the
44 * hardware is creating the nullfunc frame for power save
45 * status (ie. IEEE80211_HW_PS_NULLFUNC_STACK is not
46 * enabled) and power save was enabled, the firmware just
47 * sent a null frame with power save disabled. So we need
48 * to send a new nullfunc frame to inform the AP that we
49 * are again sleeping.
50 */
51 ieee80211_send_nullfunc(local, sdata, 1);
52}
53
54/* inform AP that we are awake again, unless power save is enabled */
55static void ieee80211_offchannel_ps_disable(struct ieee80211_sub_if_data *sdata)
56{
57 struct ieee80211_local *local = sdata->local;
58
59 if (!local->ps_sdata)
60 ieee80211_send_nullfunc(local, sdata, 0);
61 else if (local->offchannel_ps_enabled) {
62 /*
63 * In !IEEE80211_HW_PS_NULLFUNC_STACK case the hardware
64 * will send a nullfunc frame with the powersave bit set
65 * even though the AP already knows that we are sleeping.
66 * This could be avoided by sending a null frame with power
67 * save bit disabled before enabling the power save, but
68 * this doesn't gain anything.
69 *
70 * When IEEE80211_HW_PS_NULLFUNC_STACK is enabled, no need
71 * to send a nullfunc frame because AP already knows that
72 * we are sleeping, let's just enable power save mode in
73 * hardware.
74 */
75 local->hw.conf.flags |= IEEE80211_CONF_PS;
76 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
77 } else if (local->hw.conf.dynamic_ps_timeout > 0) {
78 /*
79 * If IEEE80211_CONF_PS was not set and the dynamic_ps_timer
80 * had been running before leaving the operating channel,
81 * restart the timer now and send a nullfunc frame to inform
82 * the AP that we are awake.
83 */
84 ieee80211_send_nullfunc(local, sdata, 0);
85 mod_timer(&local->dynamic_ps_timer, jiffies +
86 msecs_to_jiffies(local->hw.conf.dynamic_ps_timeout));
87 }
88}
89
90void ieee80211_offchannel_stop_beaconing(struct ieee80211_local *local)
91{
92 struct ieee80211_sub_if_data *sdata;
93
94 mutex_lock(&local->iflist_mtx);
95 list_for_each_entry(sdata, &local->interfaces, list) {
96 if (!ieee80211_sdata_running(sdata))
97 continue;
98
99 /* disable beaconing */
100 if (sdata->vif.type == NL80211_IFTYPE_AP ||
101 sdata->vif.type == NL80211_IFTYPE_ADHOC ||
102 sdata->vif.type == NL80211_IFTYPE_MESH_POINT)
103 ieee80211_bss_info_change_notify(
104 sdata, BSS_CHANGED_BEACON_ENABLED);
105
106 /*
107 * only handle non-STA interfaces here, STA interfaces
108 * are handled in ieee80211_offchannel_stop_station(),
109 * e.g., from the background scan state machine.
110 *
111 * In addition, do not stop monitor interface to allow it to be
112 * used from user space controlled off-channel operations.
113 */
114 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
115 sdata->vif.type != NL80211_IFTYPE_MONITOR)
116 netif_tx_stop_all_queues(sdata->dev);
117 }
118 mutex_unlock(&local->iflist_mtx);
119}
120
121void ieee80211_offchannel_stop_station(struct ieee80211_local *local)
122{
123 struct ieee80211_sub_if_data *sdata;
124
125 /*
126 * notify the AP about us leaving the channel and stop all STA interfaces
127 */
128 mutex_lock(&local->iflist_mtx);
129 list_for_each_entry(sdata, &local->interfaces, list) {
130 if (!ieee80211_sdata_running(sdata))
131 continue;
132
133 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
134 netif_tx_stop_all_queues(sdata->dev);
135 if (sdata->u.mgd.associated)
136 ieee80211_offchannel_ps_enable(sdata);
137 }
138 }
139 mutex_unlock(&local->iflist_mtx);
140}
141
142void ieee80211_offchannel_return(struct ieee80211_local *local,
143 bool enable_beaconing)
144{
145 struct ieee80211_sub_if_data *sdata;
146
147 mutex_lock(&local->iflist_mtx);
148 list_for_each_entry(sdata, &local->interfaces, list) {
149 if (!ieee80211_sdata_running(sdata))
150 continue;
151
152 /* Tell AP we're back */
153 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
154 if (sdata->u.mgd.associated)
155 ieee80211_offchannel_ps_disable(sdata);
156 }
157
158 if (sdata->vif.type != NL80211_IFTYPE_MONITOR)
159 netif_tx_wake_all_queues(sdata->dev);
160
161 /* re-enable beaconing */
162 if (enable_beaconing &&
163 (sdata->vif.type == NL80211_IFTYPE_AP ||
164 sdata->vif.type == NL80211_IFTYPE_ADHOC ||
165 sdata->vif.type == NL80211_IFTYPE_MESH_POINT))
166 ieee80211_bss_info_change_notify(
167 sdata, BSS_CHANGED_BEACON_ENABLED);
168 }
169 mutex_unlock(&local->iflist_mtx);
170}
diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
index e535f1c988fe..0e64484e861c 100644
--- a/net/mac80211/pm.c
+++ b/net/mac80211/pm.c
@@ -10,9 +10,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw)
10{ 10{
11 struct ieee80211_local *local = hw_to_local(hw); 11 struct ieee80211_local *local = hw_to_local(hw);
12 struct ieee80211_sub_if_data *sdata; 12 struct ieee80211_sub_if_data *sdata;
13 struct ieee80211_if_init_conf conf;
14 struct sta_info *sta; 13 struct sta_info *sta;
15 unsigned long flags;
16 14
17 ieee80211_scan_cancel(local); 15 ieee80211_scan_cancel(local);
18 16
@@ -56,22 +54,21 @@ int __ieee80211_suspend(struct ieee80211_hw *hw)
56 rcu_read_unlock(); 54 rcu_read_unlock();
57 55
58 /* remove STAs */ 56 /* remove STAs */
59 spin_lock_irqsave(&local->sta_lock, flags); 57 mutex_lock(&local->sta_mtx);
60 list_for_each_entry(sta, &local->sta_list, list) { 58 list_for_each_entry(sta, &local->sta_list, list) {
61 if (local->ops->sta_notify) { 59 if (sta->uploaded) {
62 sdata = sta->sdata; 60 sdata = sta->sdata;
63 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN) 61 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
64 sdata = container_of(sdata->bss, 62 sdata = container_of(sdata->bss,
65 struct ieee80211_sub_if_data, 63 struct ieee80211_sub_if_data,
66 u.ap); 64 u.ap);
67 65
68 drv_sta_notify(local, &sdata->vif, STA_NOTIFY_REMOVE, 66 drv_sta_remove(local, sdata, &sta->sta);
69 &sta->sta);
70 } 67 }
71 68
72 mesh_plink_quiesce(sta); 69 mesh_plink_quiesce(sta);
73 } 70 }
74 spin_unlock_irqrestore(&local->sta_lock, flags); 71 mutex_unlock(&local->sta_mtx);
75 72
76 /* remove all interfaces */ 73 /* remove all interfaces */
77 list_for_each_entry(sdata, &local->interfaces, list) { 74 list_for_each_entry(sdata, &local->interfaces, list) {
@@ -93,17 +90,14 @@ int __ieee80211_suspend(struct ieee80211_hw *hw)
93 break; 90 break;
94 } 91 }
95 92
96 if (!netif_running(sdata->dev)) 93 if (!ieee80211_sdata_running(sdata))
97 continue; 94 continue;
98 95
99 /* disable beaconing */ 96 /* disable beaconing */
100 ieee80211_bss_info_change_notify(sdata, 97 ieee80211_bss_info_change_notify(sdata,
101 BSS_CHANGED_BEACON_ENABLED); 98 BSS_CHANGED_BEACON_ENABLED);
102 99
103 conf.vif = &sdata->vif; 100 drv_remove_interface(local, &sdata->vif);
104 conf.type = sdata->vif.type;
105 conf.mac_addr = sdata->dev->dev_addr;
106 drv_remove_interface(local, &conf);
107 } 101 }
108 102
109 /* stop hardware - this must stop RX */ 103 /* stop hardware - this must stop RX */
diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
index b33efc4fc267..6d0bd198af19 100644
--- a/net/mac80211/rate.c
+++ b/net/mac80211/rate.c
@@ -10,6 +10,7 @@
10 10
11#include <linux/kernel.h> 11#include <linux/kernel.h>
12#include <linux/rtnetlink.h> 12#include <linux/rtnetlink.h>
13#include <linux/slab.h>
13#include "rate.h" 14#include "rate.h"
14#include "ieee80211_i.h" 15#include "ieee80211_i.h"
15#include "debugfs.h" 16#include "debugfs.h"
@@ -145,7 +146,7 @@ static const struct file_operations rcname_ops = {
145}; 146};
146#endif 147#endif
147 148
148struct rate_control_ref *rate_control_alloc(const char *name, 149static struct rate_control_ref *rate_control_alloc(const char *name,
149 struct ieee80211_local *local) 150 struct ieee80211_local *local)
150{ 151{
151 struct dentry *debugfsdir = NULL; 152 struct dentry *debugfsdir = NULL;
@@ -163,8 +164,7 @@ struct rate_control_ref *rate_control_alloc(const char *name,
163#ifdef CONFIG_MAC80211_DEBUGFS 164#ifdef CONFIG_MAC80211_DEBUGFS
164 debugfsdir = debugfs_create_dir("rc", local->hw.wiphy->debugfsdir); 165 debugfsdir = debugfs_create_dir("rc", local->hw.wiphy->debugfsdir);
165 local->debugfs.rcdir = debugfsdir; 166 local->debugfs.rcdir = debugfsdir;
166 local->debugfs.rcname = debugfs_create_file("name", 0400, debugfsdir, 167 debugfs_create_file("name", 0400, debugfsdir, ref, &rcname_ops);
167 ref, &rcname_ops);
168#endif 168#endif
169 169
170 ref->priv = ref->ops->alloc(&local->hw, debugfsdir); 170 ref->priv = ref->ops->alloc(&local->hw, debugfsdir);
@@ -188,9 +188,7 @@ static void rate_control_release(struct kref *kref)
188 ctrl_ref->ops->free(ctrl_ref->priv); 188 ctrl_ref->ops->free(ctrl_ref->priv);
189 189
190#ifdef CONFIG_MAC80211_DEBUGFS 190#ifdef CONFIG_MAC80211_DEBUGFS
191 debugfs_remove(ctrl_ref->local->debugfs.rcname); 191 debugfs_remove_recursive(ctrl_ref->local->debugfs.rcdir);
192 ctrl_ref->local->debugfs.rcname = NULL;
193 debugfs_remove(ctrl_ref->local->debugfs.rcdir);
194 ctrl_ref->local->debugfs.rcdir = NULL; 192 ctrl_ref->local->debugfs.rcdir = NULL;
195#endif 193#endif
196 194
@@ -210,6 +208,27 @@ static bool rc_no_data_or_no_ack(struct ieee80211_tx_rate_control *txrc)
210 return ((info->flags & IEEE80211_TX_CTL_NO_ACK) || !ieee80211_is_data(fc)); 208 return ((info->flags & IEEE80211_TX_CTL_NO_ACK) || !ieee80211_is_data(fc));
211} 209}
212 210
211static void rc_send_low_broadcast(s8 *idx, u32 basic_rates, u8 max_rate_idx)
212{
213 u8 i;
214
215 if (basic_rates == 0)
216 return; /* assume basic rates unknown and accept rate */
217 if (*idx < 0)
218 return;
219 if (basic_rates & (1 << *idx))
220 return; /* selected rate is a basic rate */
221
222 for (i = *idx + 1; i <= max_rate_idx; i++) {
223 if (basic_rates & (1 << i)) {
224 *idx = i;
225 return;
226 }
227 }
228
229 /* could not find a basic rate; use original selection */
230}
231
213bool rate_control_send_low(struct ieee80211_sta *sta, 232bool rate_control_send_low(struct ieee80211_sta *sta,
214 void *priv_sta, 233 void *priv_sta,
215 struct ieee80211_tx_rate_control *txrc) 234 struct ieee80211_tx_rate_control *txrc)
@@ -221,12 +240,48 @@ bool rate_control_send_low(struct ieee80211_sta *sta,
221 info->control.rates[0].count = 240 info->control.rates[0].count =
222 (info->flags & IEEE80211_TX_CTL_NO_ACK) ? 241 (info->flags & IEEE80211_TX_CTL_NO_ACK) ?
223 1 : txrc->hw->max_rate_tries; 242 1 : txrc->hw->max_rate_tries;
243 if (!sta && txrc->ap)
244 rc_send_low_broadcast(&info->control.rates[0].idx,
245 txrc->bss_conf->basic_rates,
246 txrc->sband->n_bitrates);
224 return true; 247 return true;
225 } 248 }
226 return false; 249 return false;
227} 250}
228EXPORT_SYMBOL(rate_control_send_low); 251EXPORT_SYMBOL(rate_control_send_low);
229 252
253static void rate_idx_match_mask(struct ieee80211_tx_rate *rate,
254 int n_bitrates, u32 mask)
255{
256 int j;
257
258 /* See whether the selected rate or anything below it is allowed. */
259 for (j = rate->idx; j >= 0; j--) {
260 if (mask & (1 << j)) {
261 /* Okay, found a suitable rate. Use it. */
262 rate->idx = j;
263 return;
264 }
265 }
266
267 /* Try to find a higher rate that would be allowed */
268 for (j = rate->idx + 1; j < n_bitrates; j++) {
269 if (mask & (1 << j)) {
270 /* Okay, found a suitable rate. Use it. */
271 rate->idx = j;
272 return;
273 }
274 }
275
276 /*
277 * Uh.. No suitable rate exists. This should not really happen with
278 * sane TX rate mask configurations. However, should someone manage to
279 * configure supported rates and TX rate mask in incompatible way,
280 * allow the frame to be transmitted with whatever the rate control
281 * selected.
282 */
283}
284
230void rate_control_get_rate(struct ieee80211_sub_if_data *sdata, 285void rate_control_get_rate(struct ieee80211_sub_if_data *sdata,
231 struct sta_info *sta, 286 struct sta_info *sta,
232 struct ieee80211_tx_rate_control *txrc) 287 struct ieee80211_tx_rate_control *txrc)
@@ -236,6 +291,7 @@ void rate_control_get_rate(struct ieee80211_sub_if_data *sdata,
236 struct ieee80211_sta *ista = NULL; 291 struct ieee80211_sta *ista = NULL;
237 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(txrc->skb); 292 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(txrc->skb);
238 int i; 293 int i;
294 u32 mask;
239 295
240 if (sta) { 296 if (sta) {
241 ista = &sta->sta; 297 ista = &sta->sta;
@@ -248,23 +304,34 @@ void rate_control_get_rate(struct ieee80211_sub_if_data *sdata,
248 info->control.rates[i].count = 1; 304 info->control.rates[i].count = 1;
249 } 305 }
250 306
251 if (sta && sdata->force_unicast_rateidx > -1) { 307 if (sdata->local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL)
252 info->control.rates[0].idx = sdata->force_unicast_rateidx; 308 return;
253 } else { 309
254 ref->ops->get_rate(ref->priv, ista, priv_sta, txrc); 310 ref->ops->get_rate(ref->priv, ista, priv_sta, txrc);
255 info->flags |= IEEE80211_TX_INTFL_RCALGO;
256 }
257 311
258 /* 312 /*
259 * try to enforce the maximum rate the user wanted 313 * Try to enforce the rateidx mask the user wanted. skip this if the
314 * default mask (allow all rates) is used to save some processing for
315 * the common case.
260 */ 316 */
261 if (sdata->max_ratectrl_rateidx > -1) 317 mask = sdata->rc_rateidx_mask[info->band];
318 if (mask != (1 << txrc->sband->n_bitrates) - 1) {
319 if (sta) {
320 /* Filter out rates that the STA does not support */
321 mask &= sta->sta.supp_rates[info->band];
322 }
323 /*
324 * Make sure the rate index selected for each TX rate is
325 * included in the configured mask and change the rate indexes
326 * if needed.
327 */
262 for (i = 0; i < IEEE80211_TX_MAX_RATES; i++) { 328 for (i = 0; i < IEEE80211_TX_MAX_RATES; i++) {
329 /* Rate masking supports only legacy rates for now */
263 if (info->control.rates[i].flags & IEEE80211_TX_RC_MCS) 330 if (info->control.rates[i].flags & IEEE80211_TX_RC_MCS)
264 continue; 331 continue;
265 info->control.rates[i].idx = 332 rate_idx_match_mask(&info->control.rates[i],
266 min_t(s8, info->control.rates[i].idx, 333 txrc->sband->n_bitrates, mask);
267 sdata->max_ratectrl_rateidx); 334 }
268 } 335 }
269 336
270 BUG_ON(info->control.rates[0].idx < 0); 337 BUG_ON(info->control.rates[0].idx < 0);
@@ -287,9 +354,16 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
287 struct rate_control_ref *ref, *old; 354 struct rate_control_ref *ref, *old;
288 355
289 ASSERT_RTNL(); 356 ASSERT_RTNL();
357
290 if (local->open_count) 358 if (local->open_count)
291 return -EBUSY; 359 return -EBUSY;
292 360
361 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
362 if (WARN_ON(!local->ops->set_rts_threshold))
363 return -EINVAL;
364 return 0;
365 }
366
293 ref = rate_control_alloc(name, local); 367 ref = rate_control_alloc(name, local);
294 if (!ref) { 368 if (!ref) {
295 printk(KERN_WARNING "%s: Failed to select rate control " 369 printk(KERN_WARNING "%s: Failed to select rate control "
@@ -308,7 +382,6 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
308 "algorithm '%s'\n", wiphy_name(local->hw.wiphy), 382 "algorithm '%s'\n", wiphy_name(local->hw.wiphy),
309 ref->ops->name); 383 ref->ops->name);
310 384
311
312 return 0; 385 return 0;
313} 386}
314 387
@@ -317,6 +390,10 @@ void rate_control_deinitialize(struct ieee80211_local *local)
317 struct rate_control_ref *ref; 390 struct rate_control_ref *ref;
318 391
319 ref = local->rate_ctrl; 392 ref = local->rate_ctrl;
393
394 if (!ref)
395 return;
396
320 local->rate_ctrl = NULL; 397 local->rate_ctrl = NULL;
321 rate_control_put(ref); 398 rate_control_put(ref);
322} 399}
diff --git a/net/mac80211/rate.h b/net/mac80211/rate.h
index 2ab5ad9e71ce..065a96190e32 100644
--- a/net/mac80211/rate.h
+++ b/net/mac80211/rate.h
@@ -26,10 +26,6 @@ struct rate_control_ref {
26 struct kref kref; 26 struct kref kref;
27}; 27};
28 28
29/* Get a reference to the rate control algorithm. If `name' is NULL, get the
30 * first available algorithm. */
31struct rate_control_ref *rate_control_alloc(const char *name,
32 struct ieee80211_local *local);
33void rate_control_get_rate(struct ieee80211_sub_if_data *sdata, 29void rate_control_get_rate(struct ieee80211_sub_if_data *sdata,
34 struct sta_info *sta, 30 struct sta_info *sta,
35 struct ieee80211_tx_rate_control *txrc); 31 struct ieee80211_tx_rate_control *txrc);
@@ -44,10 +40,11 @@ static inline void rate_control_tx_status(struct ieee80211_local *local,
44 struct rate_control_ref *ref = local->rate_ctrl; 40 struct rate_control_ref *ref = local->rate_ctrl;
45 struct ieee80211_sta *ista = &sta->sta; 41 struct ieee80211_sta *ista = &sta->sta;
46 void *priv_sta = sta->rate_ctrl_priv; 42 void *priv_sta = sta->rate_ctrl_priv;
47 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
48 43
49 if (likely(info->flags & IEEE80211_TX_INTFL_RCALGO)) 44 if (!ref)
50 ref->ops->tx_status(ref->priv, sband, ista, priv_sta, skb); 45 return;
46
47 ref->ops->tx_status(ref->priv, sband, ista, priv_sta, skb);
51} 48}
52 49
53 50
@@ -59,6 +56,9 @@ static inline void rate_control_rate_init(struct sta_info *sta)
59 void *priv_sta = sta->rate_ctrl_priv; 56 void *priv_sta = sta->rate_ctrl_priv;
60 struct ieee80211_supported_band *sband; 57 struct ieee80211_supported_band *sband;
61 58
59 if (!ref)
60 return;
61
62 sband = local->hw.wiphy->bands[local->hw.conf.channel->band]; 62 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
63 63
64 ref->ops->rate_init(ref->priv, sband, ista, priv_sta); 64 ref->ops->rate_init(ref->priv, sband, ista, priv_sta);
@@ -66,15 +66,16 @@ static inline void rate_control_rate_init(struct sta_info *sta)
66 66
67static inline void rate_control_rate_update(struct ieee80211_local *local, 67static inline void rate_control_rate_update(struct ieee80211_local *local,
68 struct ieee80211_supported_band *sband, 68 struct ieee80211_supported_band *sband,
69 struct sta_info *sta, u32 changed) 69 struct sta_info *sta, u32 changed,
70 enum nl80211_channel_type oper_chan_type)
70{ 71{
71 struct rate_control_ref *ref = local->rate_ctrl; 72 struct rate_control_ref *ref = local->rate_ctrl;
72 struct ieee80211_sta *ista = &sta->sta; 73 struct ieee80211_sta *ista = &sta->sta;
73 void *priv_sta = sta->rate_ctrl_priv; 74 void *priv_sta = sta->rate_ctrl_priv;
74 75
75 if (ref->ops->rate_update) 76 if (ref && ref->ops->rate_update)
76 ref->ops->rate_update(ref->priv, sband, ista, 77 ref->ops->rate_update(ref->priv, sband, ista,
77 priv_sta, changed); 78 priv_sta, changed, oper_chan_type);
78} 79}
79 80
80static inline void *rate_control_alloc_sta(struct rate_control_ref *ref, 81static inline void *rate_control_alloc_sta(struct rate_control_ref *ref,
@@ -97,7 +98,7 @@ static inline void rate_control_add_sta_debugfs(struct sta_info *sta)
97{ 98{
98#ifdef CONFIG_MAC80211_DEBUGFS 99#ifdef CONFIG_MAC80211_DEBUGFS
99 struct rate_control_ref *ref = sta->rate_ctrl; 100 struct rate_control_ref *ref = sta->rate_ctrl;
100 if (sta->debugfs.dir && ref->ops->add_sta_debugfs) 101 if (ref && sta->debugfs.dir && ref->ops->add_sta_debugfs)
101 ref->ops->add_sta_debugfs(ref->priv, sta->rate_ctrl_priv, 102 ref->ops->add_sta_debugfs(ref->priv, sta->rate_ctrl_priv,
102 sta->debugfs.dir); 103 sta->debugfs.dir);
103#endif 104#endif
@@ -107,12 +108,13 @@ static inline void rate_control_remove_sta_debugfs(struct sta_info *sta)
107{ 108{
108#ifdef CONFIG_MAC80211_DEBUGFS 109#ifdef CONFIG_MAC80211_DEBUGFS
109 struct rate_control_ref *ref = sta->rate_ctrl; 110 struct rate_control_ref *ref = sta->rate_ctrl;
110 if (ref->ops->remove_sta_debugfs) 111 if (ref && ref->ops->remove_sta_debugfs)
111 ref->ops->remove_sta_debugfs(ref->priv, sta->rate_ctrl_priv); 112 ref->ops->remove_sta_debugfs(ref->priv, sta->rate_ctrl_priv);
112#endif 113#endif
113} 114}
114 115
115/* functions for rate control related to a device */ 116/* Get a reference to the rate control algorithm. If `name' is NULL, get the
117 * first available algorithm. */
116int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local, 118int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
117 const char *name); 119 const char *name);
118void rate_control_deinitialize(struct ieee80211_local *local); 120void rate_control_deinitialize(struct ieee80211_local *local);
diff --git a/net/mac80211/rc80211_minstrel.c b/net/mac80211/rc80211_minstrel.c
index 6e5d68b4e427..818abfae9007 100644
--- a/net/mac80211/rc80211_minstrel.c
+++ b/net/mac80211/rc80211_minstrel.c
@@ -50,6 +50,7 @@
50#include <linux/debugfs.h> 50#include <linux/debugfs.h>
51#include <linux/random.h> 51#include <linux/random.h>
52#include <linux/ieee80211.h> 52#include <linux/ieee80211.h>
53#include <linux/slab.h>
53#include <net/mac80211.h> 54#include <net/mac80211.h>
54#include "rate.h" 55#include "rate.h"
55#include "rc80211_minstrel.h" 56#include "rc80211_minstrel.h"
diff --git a/net/mac80211/rc80211_minstrel_debugfs.c b/net/mac80211/rc80211_minstrel_debugfs.c
index a715d9454f64..0e1f12b1b6dd 100644
--- a/net/mac80211/rc80211_minstrel_debugfs.c
+++ b/net/mac80211/rc80211_minstrel_debugfs.c
@@ -49,6 +49,7 @@
49#include <linux/skbuff.h> 49#include <linux/skbuff.h>
50#include <linux/debugfs.h> 50#include <linux/debugfs.h>
51#include <linux/ieee80211.h> 51#include <linux/ieee80211.h>
52#include <linux/slab.h>
52#include <net/mac80211.h> 53#include <net/mac80211.h>
53#include "rc80211_minstrel.h" 54#include "rc80211_minstrel.h"
54 55
diff --git a/net/mac80211/rc80211_pid_algo.c b/net/mac80211/rc80211_pid_algo.c
index 699d3ed869c4..aeda65466f3e 100644
--- a/net/mac80211/rc80211_pid_algo.c
+++ b/net/mac80211/rc80211_pid_algo.c
@@ -13,6 +13,7 @@
13#include <linux/types.h> 13#include <linux/types.h>
14#include <linux/skbuff.h> 14#include <linux/skbuff.h>
15#include <linux/debugfs.h> 15#include <linux/debugfs.h>
16#include <linux/slab.h>
16#include <net/mac80211.h> 17#include <net/mac80211.h>
17#include "rate.h" 18#include "rate.h"
18#include "mesh.h" 19#include "mesh.h"
@@ -157,9 +158,7 @@ static void rate_control_pid_sample(struct rc_pid_info *pinfo,
157 158
158 /* In case nothing happened during the previous control interval, turn 159 /* In case nothing happened during the previous control interval, turn
159 * the sharpening factor on. */ 160 * the sharpening factor on. */
160 period = (HZ * pinfo->sampling_period + 500) / 1000; 161 period = msecs_to_jiffies(pinfo->sampling_period);
161 if (!period)
162 period = 1;
163 if (jiffies - spinfo->last_sample > 2 * period) 162 if (jiffies - spinfo->last_sample > 2 * period)
164 spinfo->sharp_cnt = pinfo->sharpen_duration; 163 spinfo->sharp_cnt = pinfo->sharpen_duration;
165 164
@@ -190,7 +189,7 @@ static void rate_control_pid_sample(struct rc_pid_info *pinfo,
190 rate_control_pid_normalize(pinfo, sband->n_bitrates); 189 rate_control_pid_normalize(pinfo, sband->n_bitrates);
191 190
192 /* Compute the proportional, integral and derivative errors. */ 191 /* Compute the proportional, integral and derivative errors. */
193 err_prop = (pinfo->target << RC_PID_ARITH_SHIFT) - pf; 192 err_prop = (pinfo->target - pf) << RC_PID_ARITH_SHIFT;
194 193
195 err_avg = spinfo->err_avg_sc >> pinfo->smoothing_shift; 194 err_avg = spinfo->err_avg_sc >> pinfo->smoothing_shift;
196 spinfo->err_avg_sc = spinfo->err_avg_sc - err_avg + err_prop; 195 spinfo->err_avg_sc = spinfo->err_avg_sc - err_avg + err_prop;
@@ -252,9 +251,7 @@ static void rate_control_pid_tx_status(void *priv, struct ieee80211_supported_ba
252 } 251 }
253 252
254 /* Update PID controller state. */ 253 /* Update PID controller state. */
255 period = (HZ * pinfo->sampling_period + 500) / 1000; 254 period = msecs_to_jiffies(pinfo->sampling_period);
256 if (!period)
257 period = 1;
258 if (time_after(jiffies, spinfo->last_sample + period)) 255 if (time_after(jiffies, spinfo->last_sample + period))
259 rate_control_pid_sample(pinfo, sband, sta, spinfo); 256 rate_control_pid_sample(pinfo, sband, sta, spinfo);
260} 257}
diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
index 45667054a5f3..47438b4a9af5 100644
--- a/net/mac80211/rc80211_pid_debugfs.c
+++ b/net/mac80211/rc80211_pid_debugfs.c
@@ -12,6 +12,7 @@
12#include <linux/netdevice.h> 12#include <linux/netdevice.h>
13#include <linux/types.h> 13#include <linux/types.h>
14#include <linux/skbuff.h> 14#include <linux/skbuff.h>
15#include <linux/slab.h>
15 16
16#include <net/mac80211.h> 17#include <net/mac80211.h>
17#include "rate.h" 18#include "rate.h"
diff --git a/net/mac80211/rx.c b/net/mac80211/rx.c
index 7170bf4565a8..04ea07f0e78a 100644
--- a/net/mac80211/rx.c
+++ b/net/mac80211/rx.c
@@ -2,7 +2,7 @@
2 * Copyright 2002-2005, Instant802 Networks, Inc. 2 * Copyright 2002-2005, Instant802 Networks, Inc.
3 * Copyright 2005-2006, Devicescape Software, Inc. 3 * Copyright 2005-2006, Devicescape Software, Inc.
4 * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz> 4 * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz>
5 * Copyright 2007 Johannes Berg <johannes@sipsolutions.net> 5 * Copyright 2007-2010 Johannes Berg <johannes@sipsolutions.net>
6 * 6 *
7 * This program is free software; you can redistribute it and/or modify 7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as 8 * it under the terms of the GNU General Public License version 2 as
@@ -10,6 +10,7 @@
10 */ 10 */
11 11
12#include <linux/jiffies.h> 12#include <linux/jiffies.h>
13#include <linux/slab.h>
13#include <linux/kernel.h> 14#include <linux/kernel.h>
14#include <linux/skbuff.h> 15#include <linux/skbuff.h>
15#include <linux/netdevice.h> 16#include <linux/netdevice.h>
@@ -27,11 +28,6 @@
27#include "tkip.h" 28#include "tkip.h"
28#include "wme.h" 29#include "wme.h"
29 30
30static u8 ieee80211_sta_manage_reorder_buf(struct ieee80211_hw *hw,
31 struct tid_ampdu_rx *tid_agg_rx,
32 struct sk_buff *skb,
33 u16 mpdu_seq_num,
34 int bar_req);
35/* 31/*
36 * monitor mode reception 32 * monitor mode reception
37 * 33 *
@@ -39,11 +35,8 @@ static u8 ieee80211_sta_manage_reorder_buf(struct ieee80211_hw *hw,
39 * only useful for monitoring. 35 * only useful for monitoring.
40 */ 36 */
41static struct sk_buff *remove_monitor_info(struct ieee80211_local *local, 37static struct sk_buff *remove_monitor_info(struct ieee80211_local *local,
42 struct sk_buff *skb, 38 struct sk_buff *skb)
43 int rtap_len)
44{ 39{
45 skb_pull(skb, rtap_len);
46
47 if (local->hw.flags & IEEE80211_HW_RX_INCLUDES_FCS) { 40 if (local->hw.flags & IEEE80211_HW_RX_INCLUDES_FCS) {
48 if (likely(skb->len > FCS_LEN)) 41 if (likely(skb->len > FCS_LEN))
49 skb_trim(skb, skb->len - FCS_LEN); 42 skb_trim(skb, skb->len - FCS_LEN);
@@ -59,15 +52,14 @@ static struct sk_buff *remove_monitor_info(struct ieee80211_local *local,
59} 52}
60 53
61static inline int should_drop_frame(struct sk_buff *skb, 54static inline int should_drop_frame(struct sk_buff *skb,
62 int present_fcs_len, 55 int present_fcs_len)
63 int radiotap_len)
64{ 56{
65 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb); 57 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
66 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; 58 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
67 59
68 if (status->flag & (RX_FLAG_FAILED_FCS_CRC | RX_FLAG_FAILED_PLCP_CRC)) 60 if (status->flag & (RX_FLAG_FAILED_FCS_CRC | RX_FLAG_FAILED_PLCP_CRC))
69 return 1; 61 return 1;
70 if (unlikely(skb->len < 16 + present_fcs_len + radiotap_len)) 62 if (unlikely(skb->len < 16 + present_fcs_len))
71 return 1; 63 return 1;
72 if (ieee80211_is_ctl(hdr->frame_control) && 64 if (ieee80211_is_ctl(hdr->frame_control) &&
73 !ieee80211_is_pspoll(hdr->frame_control) && 65 !ieee80211_is_pspoll(hdr->frame_control) &&
@@ -95,10 +87,6 @@ ieee80211_rx_radiotap_len(struct ieee80211_local *local,
95 if (len & 1) /* padding for RX_FLAGS if necessary */ 87 if (len & 1) /* padding for RX_FLAGS if necessary */
96 len++; 88 len++;
97 89
98 /* make sure radiotap starts at a naturally aligned address */
99 if (len % 8)
100 len = roundup(len, 8);
101
102 return len; 90 return len;
103} 91}
104 92
@@ -116,6 +104,7 @@ ieee80211_add_rx_radiotap_header(struct ieee80211_local *local,
116 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb); 104 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
117 struct ieee80211_radiotap_header *rthdr; 105 struct ieee80211_radiotap_header *rthdr;
118 unsigned char *pos; 106 unsigned char *pos;
107 u16 rx_flags = 0;
119 108
120 rthdr = (struct ieee80211_radiotap_header *)skb_push(skb, rtap_len); 109 rthdr = (struct ieee80211_radiotap_header *)skb_push(skb, rtap_len);
121 memset(rthdr, 0, rtap_len); 110 memset(rthdr, 0, rtap_len);
@@ -134,7 +123,7 @@ ieee80211_add_rx_radiotap_header(struct ieee80211_local *local,
134 123
135 /* IEEE80211_RADIOTAP_TSFT */ 124 /* IEEE80211_RADIOTAP_TSFT */
136 if (status->flag & RX_FLAG_TSFT) { 125 if (status->flag & RX_FLAG_TSFT) {
137 *(__le64 *)pos = cpu_to_le64(status->mactime); 126 put_unaligned_le64(status->mactime, pos);
138 rthdr->it_present |= 127 rthdr->it_present |=
139 cpu_to_le32(1 << IEEE80211_RADIOTAP_TSFT); 128 cpu_to_le32(1 << IEEE80211_RADIOTAP_TSFT);
140 pos += 8; 129 pos += 8;
@@ -166,17 +155,20 @@ ieee80211_add_rx_radiotap_header(struct ieee80211_local *local,
166 pos++; 155 pos++;
167 156
168 /* IEEE80211_RADIOTAP_CHANNEL */ 157 /* IEEE80211_RADIOTAP_CHANNEL */
169 *(__le16 *)pos = cpu_to_le16(status->freq); 158 put_unaligned_le16(status->freq, pos);
170 pos += 2; 159 pos += 2;
171 if (status->band == IEEE80211_BAND_5GHZ) 160 if (status->band == IEEE80211_BAND_5GHZ)
172 *(__le16 *)pos = cpu_to_le16(IEEE80211_CHAN_OFDM | 161 put_unaligned_le16(IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ,
173 IEEE80211_CHAN_5GHZ); 162 pos);
163 else if (status->flag & RX_FLAG_HT)
164 put_unaligned_le16(IEEE80211_CHAN_DYN | IEEE80211_CHAN_2GHZ,
165 pos);
174 else if (rate->flags & IEEE80211_RATE_ERP_G) 166 else if (rate->flags & IEEE80211_RATE_ERP_G)
175 *(__le16 *)pos = cpu_to_le16(IEEE80211_CHAN_OFDM | 167 put_unaligned_le16(IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ,
176 IEEE80211_CHAN_2GHZ); 168 pos);
177 else 169 else
178 *(__le16 *)pos = cpu_to_le16(IEEE80211_CHAN_CCK | 170 put_unaligned_le16(IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ,
179 IEEE80211_CHAN_2GHZ); 171 pos);
180 pos += 2; 172 pos += 2;
181 173
182 /* IEEE80211_RADIOTAP_DBM_ANTSIGNAL */ 174 /* IEEE80211_RADIOTAP_DBM_ANTSIGNAL */
@@ -205,10 +197,11 @@ ieee80211_add_rx_radiotap_header(struct ieee80211_local *local,
205 197
206 /* IEEE80211_RADIOTAP_RX_FLAGS */ 198 /* IEEE80211_RADIOTAP_RX_FLAGS */
207 /* ensure 2 byte alignment for the 2 byte field as required */ 199 /* ensure 2 byte alignment for the 2 byte field as required */
208 if ((pos - (unsigned char *)rthdr) & 1) 200 if ((pos - (u8 *)rthdr) & 1)
209 pos++; 201 pos++;
210 if (status->flag & RX_FLAG_FAILED_PLCP_CRC) 202 if (status->flag & RX_FLAG_FAILED_PLCP_CRC)
211 *(__le16 *)pos |= cpu_to_le16(IEEE80211_RADIOTAP_F_RX_BADPLCP); 203 rx_flags |= IEEE80211_RADIOTAP_F_RX_BADPLCP;
204 put_unaligned_le16(rx_flags, pos);
212 pos += 2; 205 pos += 2;
213} 206}
214 207
@@ -227,7 +220,6 @@ ieee80211_rx_monitor(struct ieee80211_local *local, struct sk_buff *origskb,
227 struct sk_buff *skb, *skb2; 220 struct sk_buff *skb, *skb2;
228 struct net_device *prev_dev = NULL; 221 struct net_device *prev_dev = NULL;
229 int present_fcs_len = 0; 222 int present_fcs_len = 0;
230 int rtap_len = 0;
231 223
232 /* 224 /*
233 * First, we may need to make a copy of the skb because 225 * First, we may need to make a copy of the skb because
@@ -237,25 +229,23 @@ ieee80211_rx_monitor(struct ieee80211_local *local, struct sk_buff *origskb,
237 * We don't need to, of course, if we aren't going to return 229 * We don't need to, of course, if we aren't going to return
238 * the SKB because it has a bad FCS/PLCP checksum. 230 * the SKB because it has a bad FCS/PLCP checksum.
239 */ 231 */
240 if (status->flag & RX_FLAG_RADIOTAP) 232
241 rtap_len = ieee80211_get_radiotap_len(origskb->data); 233 /* room for the radiotap header based on driver features */
242 else 234 needed_headroom = ieee80211_rx_radiotap_len(local, status);
243 /* room for the radiotap header based on driver features */
244 needed_headroom = ieee80211_rx_radiotap_len(local, status);
245 235
246 if (local->hw.flags & IEEE80211_HW_RX_INCLUDES_FCS) 236 if (local->hw.flags & IEEE80211_HW_RX_INCLUDES_FCS)
247 present_fcs_len = FCS_LEN; 237 present_fcs_len = FCS_LEN;
248 238
249 if (!local->monitors) { 239 if (!local->monitors) {
250 if (should_drop_frame(origskb, present_fcs_len, rtap_len)) { 240 if (should_drop_frame(origskb, present_fcs_len)) {
251 dev_kfree_skb(origskb); 241 dev_kfree_skb(origskb);
252 return NULL; 242 return NULL;
253 } 243 }
254 244
255 return remove_monitor_info(local, origskb, rtap_len); 245 return remove_monitor_info(local, origskb);
256 } 246 }
257 247
258 if (should_drop_frame(origskb, present_fcs_len, rtap_len)) { 248 if (should_drop_frame(origskb, present_fcs_len)) {
259 /* only need to expand headroom if necessary */ 249 /* only need to expand headroom if necessary */
260 skb = origskb; 250 skb = origskb;
261 origskb = NULL; 251 origskb = NULL;
@@ -279,16 +269,14 @@ ieee80211_rx_monitor(struct ieee80211_local *local, struct sk_buff *origskb,
279 */ 269 */
280 skb = skb_copy_expand(origskb, needed_headroom, 0, GFP_ATOMIC); 270 skb = skb_copy_expand(origskb, needed_headroom, 0, GFP_ATOMIC);
281 271
282 origskb = remove_monitor_info(local, origskb, rtap_len); 272 origskb = remove_monitor_info(local, origskb);
283 273
284 if (!skb) 274 if (!skb)
285 return origskb; 275 return origskb;
286 } 276 }
287 277
288 /* if necessary, prepend radiotap information */ 278 /* prepend radiotap information */
289 if (!(status->flag & RX_FLAG_RADIOTAP)) 279 ieee80211_add_rx_radiotap_header(local, skb, rate, needed_headroom);
290 ieee80211_add_rx_radiotap_header(local, skb, rate,
291 needed_headroom);
292 280
293 skb_reset_mac_header(skb); 281 skb_reset_mac_header(skb);
294 skb->ip_summed = CHECKSUM_UNNECESSARY; 282 skb->ip_summed = CHECKSUM_UNNECESSARY;
@@ -296,15 +284,15 @@ ieee80211_rx_monitor(struct ieee80211_local *local, struct sk_buff *origskb,
296 skb->protocol = htons(ETH_P_802_2); 284 skb->protocol = htons(ETH_P_802_2);
297 285
298 list_for_each_entry_rcu(sdata, &local->interfaces, list) { 286 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
299 if (!netif_running(sdata->dev))
300 continue;
301
302 if (sdata->vif.type != NL80211_IFTYPE_MONITOR) 287 if (sdata->vif.type != NL80211_IFTYPE_MONITOR)
303 continue; 288 continue;
304 289
305 if (sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES) 290 if (sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES)
306 continue; 291 continue;
307 292
293 if (!ieee80211_sdata_running(sdata))
294 continue;
295
308 if (prev_dev) { 296 if (prev_dev) {
309 skb2 = skb_clone(skb, GFP_ATOMIC); 297 skb2 = skb_clone(skb, GFP_ATOMIC);
310 if (skb2) { 298 if (skb2) {
@@ -374,7 +362,9 @@ static void ieee80211_parse_qos(struct ieee80211_rx_data *rx)
374 * boundary. In the case of regular frames, this simply means aligning the 362 * boundary. In the case of regular frames, this simply means aligning the
375 * payload to a four-byte boundary (because either the IP header is directly 363 * payload to a four-byte boundary (because either the IP header is directly
376 * contained, or IV/RFC1042 headers that have a length divisible by four are 364 * contained, or IV/RFC1042 headers that have a length divisible by four are
377 * in front of it). 365 * in front of it). If the payload data is not properly aligned and the
366 * architecture doesn't support efficient unaligned operations, mac80211
367 * will align the data.
378 * 368 *
379 * With A-MSDU frames, however, the payload data address must yield two modulo 369 * With A-MSDU frames, however, the payload data address must yield two modulo
380 * four because there are 14-byte 802.3 headers within the A-MSDU frames that 370 * four because there are 14-byte 802.3 headers within the A-MSDU frames that
@@ -388,25 +378,10 @@ static void ieee80211_parse_qos(struct ieee80211_rx_data *rx)
388 */ 378 */
389static void ieee80211_verify_alignment(struct ieee80211_rx_data *rx) 379static void ieee80211_verify_alignment(struct ieee80211_rx_data *rx)
390{ 380{
391 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data; 381#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
392 int hdrlen; 382 WARN_ONCE((unsigned long)rx->skb->data & 1,
393 383 "unaligned packet at 0x%p\n", rx->skb->data);
394#ifndef CONFIG_MAC80211_DEBUG_PACKET_ALIGNMENT
395 return;
396#endif 384#endif
397
398 if (WARN_ONCE((unsigned long)rx->skb->data & 1,
399 "unaligned packet at 0x%p\n", rx->skb->data))
400 return;
401
402 if (!ieee80211_is_data_present(hdr->frame_control))
403 return;
404
405 hdrlen = ieee80211_hdrlen(hdr->frame_control);
406 if (rx->flags & IEEE80211_RX_AMSDU)
407 hdrlen += ETH_HLEN;
408 WARN_ONCE(((unsigned long)(rx->skb->data + hdrlen)) & 3,
409 "unaligned IP payload at 0x%p\n", rx->skb->data + hdrlen);
410} 385}
411 386
412 387
@@ -489,7 +464,7 @@ ieee80211_rx_mesh_check(struct ieee80211_rx_data *rx)
489{ 464{
490 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data; 465 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
491 unsigned int hdrlen = ieee80211_hdrlen(hdr->frame_control); 466 unsigned int hdrlen = ieee80211_hdrlen(hdr->frame_control);
492 char *dev_addr = rx->dev->dev_addr; 467 char *dev_addr = rx->sdata->vif.addr;
493 468
494 if (ieee80211_is_data(hdr->frame_control)) { 469 if (ieee80211_is_data(hdr->frame_control)) {
495 if (is_multicast_ether_addr(hdr->addr1)) { 470 if (is_multicast_ether_addr(hdr->addr1)) {
@@ -518,7 +493,7 @@ ieee80211_rx_mesh_check(struct ieee80211_rx_data *rx)
518 493
519 if (ieee80211_is_action(hdr->frame_control)) { 494 if (ieee80211_is_action(hdr->frame_control)) {
520 mgmt = (struct ieee80211_mgmt *)hdr; 495 mgmt = (struct ieee80211_mgmt *)hdr;
521 if (mgmt->u.action.category != PLINK_CATEGORY) 496 if (mgmt->u.action.category != MESH_PLINK_CATEGORY)
522 return RX_DROP_MONITOR; 497 return RX_DROP_MONITOR;
523 return RX_CONTINUE; 498 return RX_CONTINUE;
524 } 499 }
@@ -543,6 +518,242 @@ ieee80211_rx_mesh_check(struct ieee80211_rx_data *rx)
543 return RX_CONTINUE; 518 return RX_CONTINUE;
544} 519}
545 520
521#define SEQ_MODULO 0x1000
522#define SEQ_MASK 0xfff
523
524static inline int seq_less(u16 sq1, u16 sq2)
525{
526 return ((sq1 - sq2) & SEQ_MASK) > (SEQ_MODULO >> 1);
527}
528
529static inline u16 seq_inc(u16 sq)
530{
531 return (sq + 1) & SEQ_MASK;
532}
533
534static inline u16 seq_sub(u16 sq1, u16 sq2)
535{
536 return (sq1 - sq2) & SEQ_MASK;
537}
538
539
540static void ieee80211_release_reorder_frame(struct ieee80211_hw *hw,
541 struct tid_ampdu_rx *tid_agg_rx,
542 int index,
543 struct sk_buff_head *frames)
544{
545 struct ieee80211_supported_band *sband;
546 struct ieee80211_rate *rate = NULL;
547 struct sk_buff *skb = tid_agg_rx->reorder_buf[index];
548 struct ieee80211_rx_status *status;
549
550 if (!skb)
551 goto no_frame;
552
553 status = IEEE80211_SKB_RXCB(skb);
554
555 /* release the reordered frames to stack */
556 sband = hw->wiphy->bands[status->band];
557 if (!(status->flag & RX_FLAG_HT))
558 rate = &sband->bitrates[status->rate_idx];
559 tid_agg_rx->stored_mpdu_num--;
560 tid_agg_rx->reorder_buf[index] = NULL;
561 __skb_queue_tail(frames, skb);
562
563no_frame:
564 tid_agg_rx->head_seq_num = seq_inc(tid_agg_rx->head_seq_num);
565}
566
567static void ieee80211_release_reorder_frames(struct ieee80211_hw *hw,
568 struct tid_ampdu_rx *tid_agg_rx,
569 u16 head_seq_num,
570 struct sk_buff_head *frames)
571{
572 int index;
573
574 while (seq_less(tid_agg_rx->head_seq_num, head_seq_num)) {
575 index = seq_sub(tid_agg_rx->head_seq_num, tid_agg_rx->ssn) %
576 tid_agg_rx->buf_size;
577 ieee80211_release_reorder_frame(hw, tid_agg_rx, index, frames);
578 }
579}
580
581/*
582 * Timeout (in jiffies) for skb's that are waiting in the RX reorder buffer. If
583 * the skb was added to the buffer longer than this time ago, the earlier
584 * frames that have not yet been received are assumed to be lost and the skb
585 * can be released for processing. This may also release other skb's from the
586 * reorder buffer if there are no additional gaps between the frames.
587 */
588#define HT_RX_REORDER_BUF_TIMEOUT (HZ / 10)
589
590/*
591 * As this function belongs to the RX path it must be under
592 * rcu_read_lock protection. It returns false if the frame
593 * can be processed immediately, true if it was consumed.
594 */
595static bool ieee80211_sta_manage_reorder_buf(struct ieee80211_hw *hw,
596 struct tid_ampdu_rx *tid_agg_rx,
597 struct sk_buff *skb,
598 struct sk_buff_head *frames)
599{
600 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
601 u16 sc = le16_to_cpu(hdr->seq_ctrl);
602 u16 mpdu_seq_num = (sc & IEEE80211_SCTL_SEQ) >> 4;
603 u16 head_seq_num, buf_size;
604 int index;
605
606 buf_size = tid_agg_rx->buf_size;
607 head_seq_num = tid_agg_rx->head_seq_num;
608
609 /* frame with out of date sequence number */
610 if (seq_less(mpdu_seq_num, head_seq_num)) {
611 dev_kfree_skb(skb);
612 return true;
613 }
614
615 /*
616 * If frame the sequence number exceeds our buffering window
617 * size release some previous frames to make room for this one.
618 */
619 if (!seq_less(mpdu_seq_num, head_seq_num + buf_size)) {
620 head_seq_num = seq_inc(seq_sub(mpdu_seq_num, buf_size));
621 /* release stored frames up to new head to stack */
622 ieee80211_release_reorder_frames(hw, tid_agg_rx, head_seq_num,
623 frames);
624 }
625
626 /* Now the new frame is always in the range of the reordering buffer */
627
628 index = seq_sub(mpdu_seq_num, tid_agg_rx->ssn) % tid_agg_rx->buf_size;
629
630 /* check if we already stored this frame */
631 if (tid_agg_rx->reorder_buf[index]) {
632 dev_kfree_skb(skb);
633 return true;
634 }
635
636 /*
637 * If the current MPDU is in the right order and nothing else
638 * is stored we can process it directly, no need to buffer it.
639 */
640 if (mpdu_seq_num == tid_agg_rx->head_seq_num &&
641 tid_agg_rx->stored_mpdu_num == 0) {
642 tid_agg_rx->head_seq_num = seq_inc(tid_agg_rx->head_seq_num);
643 return false;
644 }
645
646 /* put the frame in the reordering buffer */
647 tid_agg_rx->reorder_buf[index] = skb;
648 tid_agg_rx->reorder_time[index] = jiffies;
649 tid_agg_rx->stored_mpdu_num++;
650 /* release the buffer until next missing frame */
651 index = seq_sub(tid_agg_rx->head_seq_num, tid_agg_rx->ssn) %
652 tid_agg_rx->buf_size;
653 if (!tid_agg_rx->reorder_buf[index] &&
654 tid_agg_rx->stored_mpdu_num > 1) {
655 /*
656 * No buffers ready to be released, but check whether any
657 * frames in the reorder buffer have timed out.
658 */
659 int j;
660 int skipped = 1;
661 for (j = (index + 1) % tid_agg_rx->buf_size; j != index;
662 j = (j + 1) % tid_agg_rx->buf_size) {
663 if (!tid_agg_rx->reorder_buf[j]) {
664 skipped++;
665 continue;
666 }
667 if (!time_after(jiffies, tid_agg_rx->reorder_time[j] +
668 HT_RX_REORDER_BUF_TIMEOUT))
669 break;
670
671#ifdef CONFIG_MAC80211_HT_DEBUG
672 if (net_ratelimit())
673 printk(KERN_DEBUG "%s: release an RX reorder "
674 "frame due to timeout on earlier "
675 "frames\n",
676 wiphy_name(hw->wiphy));
677#endif
678 ieee80211_release_reorder_frame(hw, tid_agg_rx,
679 j, frames);
680
681 /*
682 * Increment the head seq# also for the skipped slots.
683 */
684 tid_agg_rx->head_seq_num =
685 (tid_agg_rx->head_seq_num + skipped) & SEQ_MASK;
686 skipped = 0;
687 }
688 } else while (tid_agg_rx->reorder_buf[index]) {
689 ieee80211_release_reorder_frame(hw, tid_agg_rx, index, frames);
690 index = seq_sub(tid_agg_rx->head_seq_num, tid_agg_rx->ssn) %
691 tid_agg_rx->buf_size;
692 }
693
694 return true;
695}
696
697/*
698 * Reorder MPDUs from A-MPDUs, keeping them on a buffer. Returns
699 * true if the MPDU was buffered, false if it should be processed.
700 */
701static void ieee80211_rx_reorder_ampdu(struct ieee80211_rx_data *rx,
702 struct sk_buff_head *frames)
703{
704 struct sk_buff *skb = rx->skb;
705 struct ieee80211_local *local = rx->local;
706 struct ieee80211_hw *hw = &local->hw;
707 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
708 struct sta_info *sta = rx->sta;
709 struct tid_ampdu_rx *tid_agg_rx;
710 u16 sc;
711 int tid;
712
713 if (!ieee80211_is_data_qos(hdr->frame_control))
714 goto dont_reorder;
715
716 /*
717 * filter the QoS data rx stream according to
718 * STA/TID and check if this STA/TID is on aggregation
719 */
720
721 if (!sta)
722 goto dont_reorder;
723
724 tid = *ieee80211_get_qos_ctl(hdr) & IEEE80211_QOS_CTL_TID_MASK;
725
726 if (sta->ampdu_mlme.tid_state_rx[tid] != HT_AGG_STATE_OPERATIONAL)
727 goto dont_reorder;
728
729 tid_agg_rx = sta->ampdu_mlme.tid_rx[tid];
730
731 /* qos null data frames are excluded */
732 if (unlikely(hdr->frame_control & cpu_to_le16(IEEE80211_STYPE_NULLFUNC)))
733 goto dont_reorder;
734
735 /* new, potentially un-ordered, ampdu frame - process it */
736
737 /* reset session timer */
738 if (tid_agg_rx->timeout)
739 mod_timer(&tid_agg_rx->session_timer,
740 TU_TO_EXP_TIME(tid_agg_rx->timeout));
741
742 /* if this mpdu is fragmented - terminate rx aggregation session */
743 sc = le16_to_cpu(hdr->seq_ctrl);
744 if (sc & IEEE80211_SCTL_FRAG) {
745 ieee80211_sta_stop_rx_ba_session(sta->sdata, sta->sta.addr,
746 tid, 0, WLAN_REASON_QSTA_REQUIRE_SETUP);
747 dev_kfree_skb(skb);
748 return;
749 }
750
751 if (ieee80211_sta_manage_reorder_buf(hw, tid_agg_rx, skb, frames))
752 return;
753
754 dont_reorder:
755 __skb_queue_tail(frames, skb);
756}
546 757
547static ieee80211_rx_result debug_noinline 758static ieee80211_rx_result debug_noinline
548ieee80211_rx_h_check(struct ieee80211_rx_data *rx) 759ieee80211_rx_h_check(struct ieee80211_rx_data *rx)
@@ -603,7 +814,9 @@ ieee80211_rx_h_check(struct ieee80211_rx_data *rx)
603static ieee80211_rx_result debug_noinline 814static ieee80211_rx_result debug_noinline
604ieee80211_rx_h_decrypt(struct ieee80211_rx_data *rx) 815ieee80211_rx_h_decrypt(struct ieee80211_rx_data *rx)
605{ 816{
606 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data; 817 struct sk_buff *skb = rx->skb;
818 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
819 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
607 int keyidx; 820 int keyidx;
608 int hdrlen; 821 int hdrlen;
609 ieee80211_rx_result result = RX_DROP_UNUSABLE; 822 ieee80211_rx_result result = RX_DROP_UNUSABLE;
@@ -644,6 +857,9 @@ ieee80211_rx_h_decrypt(struct ieee80211_rx_data *rx)
644 if (!(rx->flags & IEEE80211_RX_RA_MATCH)) 857 if (!(rx->flags & IEEE80211_RX_RA_MATCH))
645 return RX_CONTINUE; 858 return RX_CONTINUE;
646 859
860 /* start without a key */
861 rx->key = NULL;
862
647 if (rx->sta) 863 if (rx->sta)
648 stakey = rcu_dereference(rx->sta->key); 864 stakey = rcu_dereference(rx->sta->key);
649 865
@@ -657,8 +873,8 @@ ieee80211_rx_h_decrypt(struct ieee80211_rx_data *rx)
657 return RX_CONTINUE; 873 return RX_CONTINUE;
658 } else if (mmie_keyidx >= 0) { 874 } else if (mmie_keyidx >= 0) {
659 /* Broadcast/multicast robust management frame / BIP */ 875 /* Broadcast/multicast robust management frame / BIP */
660 if ((rx->status->flag & RX_FLAG_DECRYPTED) && 876 if ((status->flag & RX_FLAG_DECRYPTED) &&
661 (rx->status->flag & RX_FLAG_IV_STRIPPED)) 877 (status->flag & RX_FLAG_IV_STRIPPED))
662 return RX_CONTINUE; 878 return RX_CONTINUE;
663 879
664 if (mmie_keyidx < NUM_DEFAULT_KEYS || 880 if (mmie_keyidx < NUM_DEFAULT_KEYS ||
@@ -690,8 +906,8 @@ ieee80211_rx_h_decrypt(struct ieee80211_rx_data *rx)
690 * we somehow allow the driver to tell us which key 906 * we somehow allow the driver to tell us which key
691 * the hardware used if this flag is set? 907 * the hardware used if this flag is set?
692 */ 908 */
693 if ((rx->status->flag & RX_FLAG_DECRYPTED) && 909 if ((status->flag & RX_FLAG_DECRYPTED) &&
694 (rx->status->flag & RX_FLAG_IV_STRIPPED)) 910 (status->flag & RX_FLAG_IV_STRIPPED))
695 return RX_CONTINUE; 911 return RX_CONTINUE;
696 912
697 hdrlen = ieee80211_hdrlen(hdr->frame_control); 913 hdrlen = ieee80211_hdrlen(hdr->frame_control);
@@ -727,8 +943,8 @@ ieee80211_rx_h_decrypt(struct ieee80211_rx_data *rx)
727 /* Check for weak IVs if possible */ 943 /* Check for weak IVs if possible */
728 if (rx->sta && rx->key->conf.alg == ALG_WEP && 944 if (rx->sta && rx->key->conf.alg == ALG_WEP &&
729 ieee80211_is_data(hdr->frame_control) && 945 ieee80211_is_data(hdr->frame_control) &&
730 (!(rx->status->flag & RX_FLAG_IV_STRIPPED) || 946 (!(status->flag & RX_FLAG_IV_STRIPPED) ||
731 !(rx->status->flag & RX_FLAG_DECRYPTED)) && 947 !(status->flag & RX_FLAG_DECRYPTED)) &&
732 ieee80211_wep_is_weak_iv(rx->skb, rx->key)) 948 ieee80211_wep_is_weak_iv(rx->skb, rx->key))
733 rx->sta->wep_weak_iv_count++; 949 rx->sta->wep_weak_iv_count++;
734 950
@@ -748,7 +964,7 @@ ieee80211_rx_h_decrypt(struct ieee80211_rx_data *rx)
748 } 964 }
749 965
750 /* either the frame has been decrypted or will be dropped */ 966 /* either the frame has been decrypted or will be dropped */
751 rx->status->flag |= RX_FLAG_DECRYPTED; 967 status->flag |= RX_FLAG_DECRYPTED;
752 968
753 return result; 969 return result;
754} 970}
@@ -792,53 +1008,45 @@ static void ap_sta_ps_start(struct sta_info *sta)
792 struct ieee80211_local *local = sdata->local; 1008 struct ieee80211_local *local = sdata->local;
793 1009
794 atomic_inc(&sdata->bss->num_sta_ps); 1010 atomic_inc(&sdata->bss->num_sta_ps);
795 set_sta_flags(sta, WLAN_STA_PS); 1011 set_sta_flags(sta, WLAN_STA_PS_STA);
796 drv_sta_notify(local, &sdata->vif, STA_NOTIFY_SLEEP, &sta->sta); 1012 drv_sta_notify(local, sdata, STA_NOTIFY_SLEEP, &sta->sta);
797#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG 1013#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
798 printk(KERN_DEBUG "%s: STA %pM aid %d enters power save mode\n", 1014 printk(KERN_DEBUG "%s: STA %pM aid %d enters power save mode\n",
799 sdata->dev->name, sta->sta.addr, sta->sta.aid); 1015 sdata->name, sta->sta.addr, sta->sta.aid);
800#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */ 1016#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
801} 1017}
802 1018
803static int ap_sta_ps_end(struct sta_info *sta) 1019static void ap_sta_ps_end(struct sta_info *sta)
804{ 1020{
805 struct ieee80211_sub_if_data *sdata = sta->sdata; 1021 struct ieee80211_sub_if_data *sdata = sta->sdata;
806 struct ieee80211_local *local = sdata->local;
807 int sent, buffered;
808 1022
809 atomic_dec(&sdata->bss->num_sta_ps); 1023 atomic_dec(&sdata->bss->num_sta_ps);
810 1024
811 clear_sta_flags(sta, WLAN_STA_PS); 1025 clear_sta_flags(sta, WLAN_STA_PS_STA);
812 drv_sta_notify(local, &sdata->vif, STA_NOTIFY_AWAKE, &sta->sta);
813
814 if (!skb_queue_empty(&sta->ps_tx_buf))
815 sta_info_clear_tim_bit(sta);
816 1026
817#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG 1027#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
818 printk(KERN_DEBUG "%s: STA %pM aid %d exits power save mode\n", 1028 printk(KERN_DEBUG "%s: STA %pM aid %d exits power save mode\n",
819 sdata->dev->name, sta->sta.addr, sta->sta.aid); 1029 sdata->name, sta->sta.addr, sta->sta.aid);
820#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */ 1030#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
821 1031
822 /* Send all buffered frames to the station */ 1032 if (test_sta_flags(sta, WLAN_STA_PS_DRIVER)) {
823 sent = ieee80211_add_pending_skbs(local, &sta->tx_filtered);
824 buffered = ieee80211_add_pending_skbs(local, &sta->ps_tx_buf);
825 sent += buffered;
826 local->total_ps_buffered -= buffered;
827
828#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG 1033#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
829 printk(KERN_DEBUG "%s: STA %pM aid %d sending %d filtered/%d PS frames " 1034 printk(KERN_DEBUG "%s: STA %pM aid %d driver-ps-blocked\n",
830 "since STA not sleeping anymore\n", sdata->dev->name, 1035 sdata->name, sta->sta.addr, sta->sta.aid);
831 sta->sta.addr, sta->sta.aid, sent - buffered, buffered);
832#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */ 1036#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
1037 return;
1038 }
833 1039
834 return sent; 1040 ieee80211_sta_ps_deliver_wakeup(sta);
835} 1041}
836 1042
837static ieee80211_rx_result debug_noinline 1043static ieee80211_rx_result debug_noinline
838ieee80211_rx_h_sta_process(struct ieee80211_rx_data *rx) 1044ieee80211_rx_h_sta_process(struct ieee80211_rx_data *rx)
839{ 1045{
840 struct sta_info *sta = rx->sta; 1046 struct sta_info *sta = rx->sta;
841 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data; 1047 struct sk_buff *skb = rx->skb;
1048 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
1049 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
842 1050
843 if (!sta) 1051 if (!sta)
844 return RX_CONTINUE; 1052 return RX_CONTINUE;
@@ -869,9 +1077,8 @@ ieee80211_rx_h_sta_process(struct ieee80211_rx_data *rx)
869 1077
870 sta->rx_fragments++; 1078 sta->rx_fragments++;
871 sta->rx_bytes += rx->skb->len; 1079 sta->rx_bytes += rx->skb->len;
872 sta->last_signal = rx->status->signal; 1080 sta->last_signal = status->signal;
873 sta->last_qual = rx->status->qual; 1081 sta->last_noise = status->noise;
874 sta->last_noise = rx->status->noise;
875 1082
876 /* 1083 /*
877 * Change STA power saving mode only at the end of a frame 1084 * Change STA power saving mode only at the end of a frame
@@ -880,7 +1087,7 @@ ieee80211_rx_h_sta_process(struct ieee80211_rx_data *rx)
880 if (!ieee80211_has_morefrags(hdr->frame_control) && 1087 if (!ieee80211_has_morefrags(hdr->frame_control) &&
881 (rx->sdata->vif.type == NL80211_IFTYPE_AP || 1088 (rx->sdata->vif.type == NL80211_IFTYPE_AP ||
882 rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN)) { 1089 rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN)) {
883 if (test_sta_flags(sta, WLAN_STA_PS)) { 1090 if (test_sta_flags(sta, WLAN_STA_PS_STA)) {
884 /* 1091 /*
885 * Ignore doze->wake transitions that are 1092 * Ignore doze->wake transitions that are
886 * indicated by non-data frames, the standard 1093 * indicated by non-data frames, the standard
@@ -891,19 +1098,36 @@ ieee80211_rx_h_sta_process(struct ieee80211_rx_data *rx)
891 */ 1098 */
892 if (ieee80211_is_data(hdr->frame_control) && 1099 if (ieee80211_is_data(hdr->frame_control) &&
893 !ieee80211_has_pm(hdr->frame_control)) 1100 !ieee80211_has_pm(hdr->frame_control))
894 rx->sent_ps_buffered += ap_sta_ps_end(sta); 1101 ap_sta_ps_end(sta);
895 } else { 1102 } else {
896 if (ieee80211_has_pm(hdr->frame_control)) 1103 if (ieee80211_has_pm(hdr->frame_control))
897 ap_sta_ps_start(sta); 1104 ap_sta_ps_start(sta);
898 } 1105 }
899 } 1106 }
900 1107
901 /* Drop data::nullfunc frames silently, since they are used only to 1108 /*
902 * control station power saving mode. */ 1109 * Drop (qos-)data::nullfunc frames silently, since they
903 if (ieee80211_is_nullfunc(hdr->frame_control)) { 1110 * are used only to control station power saving mode.
1111 */
1112 if (ieee80211_is_nullfunc(hdr->frame_control) ||
1113 ieee80211_is_qos_nullfunc(hdr->frame_control)) {
904 I802_DEBUG_INC(rx->local->rx_handlers_drop_nullfunc); 1114 I802_DEBUG_INC(rx->local->rx_handlers_drop_nullfunc);
905 /* Update counter and free packet here to avoid counting this 1115
906 * as a dropped packed. */ 1116 /*
1117 * If we receive a 4-addr nullfunc frame from a STA
1118 * that was not moved to a 4-addr STA vlan yet, drop
1119 * the frame to the monitor interface, to make sure
1120 * that hostapd sees it
1121 */
1122 if (ieee80211_has_a4(hdr->frame_control) &&
1123 (rx->sdata->vif.type == NL80211_IFTYPE_AP ||
1124 (rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
1125 !rx->sdata->u.vlan.sta)))
1126 return RX_DROP_MONITOR;
1127 /*
1128 * Update counter and free packet here to avoid
1129 * counting this as a dropped packed.
1130 */
907 sta->rx_packets++; 1131 sta->rx_packets++;
908 dev_kfree_skb(rx->skb); 1132 dev_kfree_skb(rx->skb);
909 return RX_QUEUED; 1133 return RX_QUEUED;
@@ -932,7 +1156,7 @@ ieee80211_reassemble_add(struct ieee80211_sub_if_data *sdata,
932 printk(KERN_DEBUG "%s: RX reassembly removed oldest " 1156 printk(KERN_DEBUG "%s: RX reassembly removed oldest "
933 "fragment entry (idx=%d age=%lu seq=%d last_frag=%d " 1157 "fragment entry (idx=%d age=%lu seq=%d last_frag=%d "
934 "addr1=%pM addr2=%pM\n", 1158 "addr1=%pM addr2=%pM\n",
935 sdata->dev->name, idx, 1159 sdata->name, idx,
936 jiffies - entry->first_frag_time, entry->seq, 1160 jiffies - entry->first_frag_time, entry->seq,
937 entry->last_frag, hdr->addr1, hdr->addr2); 1161 entry->last_frag, hdr->addr1, hdr->addr2);
938#endif 1162#endif
@@ -1103,9 +1327,7 @@ ieee80211_rx_h_defragment(struct ieee80211_rx_data *rx)
1103static ieee80211_rx_result debug_noinline 1327static ieee80211_rx_result debug_noinline
1104ieee80211_rx_h_ps_poll(struct ieee80211_rx_data *rx) 1328ieee80211_rx_h_ps_poll(struct ieee80211_rx_data *rx)
1105{ 1329{
1106 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(rx->dev); 1330 struct ieee80211_sub_if_data *sdata = rx->sdata;
1107 struct sk_buff *skb;
1108 int no_pending_pkts;
1109 __le16 fc = ((struct ieee80211_hdr *)rx->skb->data)->frame_control; 1331 __le16 fc = ((struct ieee80211_hdr *)rx->skb->data)->frame_control;
1110 1332
1111 if (likely(!rx->sta || !ieee80211_is_pspoll(fc) || 1333 if (likely(!rx->sta || !ieee80211_is_pspoll(fc) ||
@@ -1116,56 +1338,10 @@ ieee80211_rx_h_ps_poll(struct ieee80211_rx_data *rx)
1116 (sdata->vif.type != NL80211_IFTYPE_AP_VLAN)) 1338 (sdata->vif.type != NL80211_IFTYPE_AP_VLAN))
1117 return RX_DROP_UNUSABLE; 1339 return RX_DROP_UNUSABLE;
1118 1340
1119 skb = skb_dequeue(&rx->sta->tx_filtered); 1341 if (!test_sta_flags(rx->sta, WLAN_STA_PS_DRIVER))
1120 if (!skb) { 1342 ieee80211_sta_ps_deliver_poll_response(rx->sta);
1121 skb = skb_dequeue(&rx->sta->ps_tx_buf); 1343 else
1122 if (skb) 1344 set_sta_flags(rx->sta, WLAN_STA_PSPOLL);
1123 rx->local->total_ps_buffered--;
1124 }
1125 no_pending_pkts = skb_queue_empty(&rx->sta->tx_filtered) &&
1126 skb_queue_empty(&rx->sta->ps_tx_buf);
1127
1128 if (skb) {
1129 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1130 struct ieee80211_hdr *hdr =
1131 (struct ieee80211_hdr *) skb->data;
1132
1133 /*
1134 * Tell TX path to send this frame even though the STA may
1135 * still remain is PS mode after this frame exchange.
1136 */
1137 info->flags |= IEEE80211_TX_CTL_PSPOLL_RESPONSE;
1138
1139#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
1140 printk(KERN_DEBUG "STA %pM aid %d: PS Poll (entries after %d)\n",
1141 rx->sta->sta.addr, rx->sta->sta.aid,
1142 skb_queue_len(&rx->sta->ps_tx_buf));
1143#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
1144
1145 /* Use MoreData flag to indicate whether there are more
1146 * buffered frames for this STA */
1147 if (no_pending_pkts)
1148 hdr->frame_control &= cpu_to_le16(~IEEE80211_FCTL_MOREDATA);
1149 else
1150 hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_MOREDATA);
1151
1152 ieee80211_add_pending_skb(rx->local, skb);
1153
1154 if (no_pending_pkts)
1155 sta_info_clear_tim_bit(rx->sta);
1156#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
1157 } else if (!rx->sent_ps_buffered) {
1158 /*
1159 * FIXME: This can be the result of a race condition between
1160 * us expiring a frame and the station polling for it.
1161 * Should we send it a null-func frame indicating we
1162 * have nothing buffered for it?
1163 */
1164 printk(KERN_DEBUG "%s: STA %pM sent PS Poll even "
1165 "though there are no buffered frames for it\n",
1166 rx->dev->name, rx->sta->sta.addr);
1167#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
1168 }
1169 1345
1170 /* Free PS Poll skb here instead of returning RX_DROP that would 1346 /* Free PS Poll skb here instead of returning RX_DROP that would
1171 * count as an dropped frame. */ 1347 * count as an dropped frame. */
@@ -1206,11 +1382,14 @@ ieee80211_802_1x_port_control(struct ieee80211_rx_data *rx)
1206static int 1382static int
1207ieee80211_drop_unencrypted(struct ieee80211_rx_data *rx, __le16 fc) 1383ieee80211_drop_unencrypted(struct ieee80211_rx_data *rx, __le16 fc)
1208{ 1384{
1385 struct sk_buff *skb = rx->skb;
1386 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
1387
1209 /* 1388 /*
1210 * Pass through unencrypted frames if the hardware has 1389 * Pass through unencrypted frames if the hardware has
1211 * decrypted them already. 1390 * decrypted them already.
1212 */ 1391 */
1213 if (rx->status->flag & RX_FLAG_DECRYPTED) 1392 if (status->flag & RX_FLAG_DECRYPTED)
1214 return 0; 1393 return 0;
1215 1394
1216 /* Drop unencrypted frames if key is set. */ 1395 /* Drop unencrypted frames if key is set. */
@@ -1219,13 +1398,28 @@ ieee80211_drop_unencrypted(struct ieee80211_rx_data *rx, __le16 fc)
1219 ieee80211_is_data(fc) && 1398 ieee80211_is_data(fc) &&
1220 (rx->key || rx->sdata->drop_unencrypted))) 1399 (rx->key || rx->sdata->drop_unencrypted)))
1221 return -EACCES; 1400 return -EACCES;
1401
1402 return 0;
1403}
1404
1405static int
1406ieee80211_drop_unencrypted_mgmt(struct ieee80211_rx_data *rx)
1407{
1408 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
1409 __le16 fc = hdr->frame_control;
1410 int res;
1411
1412 res = ieee80211_drop_unencrypted(rx, fc);
1413 if (unlikely(res))
1414 return res;
1415
1222 if (rx->sta && test_sta_flags(rx->sta, WLAN_STA_MFP)) { 1416 if (rx->sta && test_sta_flags(rx->sta, WLAN_STA_MFP)) {
1223 if (unlikely(ieee80211_is_unicast_robust_mgmt_frame(rx->skb) && 1417 if (unlikely(ieee80211_is_unicast_robust_mgmt_frame(rx->skb) &&
1224 rx->key)) 1418 rx->key))
1225 return -EACCES; 1419 return -EACCES;
1226 /* BIP does not use Protected field, so need to check MMIE */ 1420 /* BIP does not use Protected field, so need to check MMIE */
1227 if (unlikely(ieee80211_is_multicast_robust_mgmt_frame(rx->skb) 1421 if (unlikely(ieee80211_is_multicast_robust_mgmt_frame(rx->skb) &&
1228 && ieee80211_get_mmie_keyidx(rx->skb) < 0 && 1422 ieee80211_get_mmie_keyidx(rx->skb) < 0 &&
1229 rx->key)) 1423 rx->key))
1230 return -EACCES; 1424 return -EACCES;
1231 /* 1425 /*
@@ -1244,10 +1438,19 @@ ieee80211_drop_unencrypted(struct ieee80211_rx_data *rx, __le16 fc)
1244static int 1438static int
1245__ieee80211_data_to_8023(struct ieee80211_rx_data *rx) 1439__ieee80211_data_to_8023(struct ieee80211_rx_data *rx)
1246{ 1440{
1247 struct net_device *dev = rx->dev; 1441 struct ieee80211_sub_if_data *sdata = rx->sdata;
1248 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 1442 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
1443
1444 if (ieee80211_has_a4(hdr->frame_control) &&
1445 sdata->vif.type == NL80211_IFTYPE_AP_VLAN && !sdata->u.vlan.sta)
1446 return -1;
1249 1447
1250 return ieee80211_data_to_8023(rx->skb, dev->dev_addr, sdata->vif.type); 1448 if (is_multicast_ether_addr(hdr->addr1) &&
1449 ((sdata->vif.type == NL80211_IFTYPE_AP_VLAN && sdata->u.vlan.sta) ||
1450 (sdata->vif.type == NL80211_IFTYPE_STATION && sdata->u.mgd.use_4addr)))
1451 return -1;
1452
1453 return ieee80211_data_to_8023(rx->skb, sdata->vif.addr, sdata->vif.type);
1251} 1454}
1252 1455
1253/* 1456/*
@@ -1264,7 +1467,7 @@ static bool ieee80211_frame_allowed(struct ieee80211_rx_data *rx, __le16 fc)
1264 * of whether the frame was encrypted or not. 1467 * of whether the frame was encrypted or not.
1265 */ 1468 */
1266 if (ehdr->h_proto == htons(ETH_P_PAE) && 1469 if (ehdr->h_proto == htons(ETH_P_PAE) &&
1267 (compare_ether_addr(ehdr->h_dest, rx->dev->dev_addr) == 0 || 1470 (compare_ether_addr(ehdr->h_dest, rx->sdata->vif.addr) == 0 ||
1268 compare_ether_addr(ehdr->h_dest, pae_group_addr) == 0)) 1471 compare_ether_addr(ehdr->h_dest, pae_group_addr) == 0))
1269 return true; 1472 return true;
1270 1473
@@ -1281,10 +1484,9 @@ static bool ieee80211_frame_allowed(struct ieee80211_rx_data *rx, __le16 fc)
1281static void 1484static void
1282ieee80211_deliver_skb(struct ieee80211_rx_data *rx) 1485ieee80211_deliver_skb(struct ieee80211_rx_data *rx)
1283{ 1486{
1284 struct net_device *dev = rx->dev; 1487 struct ieee80211_sub_if_data *sdata = rx->sdata;
1285 struct ieee80211_local *local = rx->local; 1488 struct net_device *dev = sdata->dev;
1286 struct sk_buff *skb, *xmit_skb; 1489 struct sk_buff *skb, *xmit_skb;
1287 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1288 struct ethhdr *ehdr = (struct ethhdr *) rx->skb->data; 1490 struct ethhdr *ehdr = (struct ethhdr *) rx->skb->data;
1289 struct sta_info *dsta; 1491 struct sta_info *dsta;
1290 1492
@@ -1294,7 +1496,8 @@ ieee80211_deliver_skb(struct ieee80211_rx_data *rx)
1294 if ((sdata->vif.type == NL80211_IFTYPE_AP || 1496 if ((sdata->vif.type == NL80211_IFTYPE_AP ||
1295 sdata->vif.type == NL80211_IFTYPE_AP_VLAN) && 1497 sdata->vif.type == NL80211_IFTYPE_AP_VLAN) &&
1296 !(sdata->flags & IEEE80211_SDATA_DONT_BRIDGE_PACKETS) && 1498 !(sdata->flags & IEEE80211_SDATA_DONT_BRIDGE_PACKETS) &&
1297 (rx->flags & IEEE80211_RX_RA_MATCH)) { 1499 (rx->flags & IEEE80211_RX_RA_MATCH) &&
1500 (sdata->vif.type != NL80211_IFTYPE_AP_VLAN || !sdata->u.vlan.sta)) {
1298 if (is_multicast_ether_addr(ehdr->h_dest)) { 1501 if (is_multicast_ether_addr(ehdr->h_dest)) {
1299 /* 1502 /*
1300 * send multicast frames both to higher layers in 1503 * send multicast frames both to higher layers in
@@ -1305,8 +1508,8 @@ ieee80211_deliver_skb(struct ieee80211_rx_data *rx)
1305 printk(KERN_DEBUG "%s: failed to clone " 1508 printk(KERN_DEBUG "%s: failed to clone "
1306 "multicast frame\n", dev->name); 1509 "multicast frame\n", dev->name);
1307 } else { 1510 } else {
1308 dsta = sta_info_get(local, skb->data); 1511 dsta = sta_info_get(sdata, skb->data);
1309 if (dsta && dsta->sdata->dev == dev) { 1512 if (dsta) {
1310 /* 1513 /*
1311 * The destination station is associated to 1514 * The destination station is associated to
1312 * this AP (in this VLAN), so send the frame 1515 * this AP (in this VLAN), so send the frame
@@ -1322,7 +1525,7 @@ ieee80211_deliver_skb(struct ieee80211_rx_data *rx)
1322 if (skb) { 1525 if (skb) {
1323 int align __maybe_unused; 1526 int align __maybe_unused;
1324 1527
1325#if defined(CONFIG_MAC80211_DEBUG_PACKET_ALIGNMENT) || !defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) 1528#ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
1326 /* 1529 /*
1327 * 'align' will only take the values 0 or 2 here 1530 * 'align' will only take the values 0 or 2 here
1328 * since all frames are required to be aligned 1531 * since all frames are required to be aligned
@@ -1337,10 +1540,10 @@ ieee80211_deliver_skb(struct ieee80211_rx_data *rx)
1337 skb = NULL; 1540 skb = NULL;
1338 } else { 1541 } else {
1339 u8 *data = skb->data; 1542 u8 *data = skb->data;
1340 size_t len = skb->len; 1543 size_t len = skb_headlen(skb);
1341 u8 *new = __skb_push(skb, align); 1544 skb->data -= align;
1342 memmove(new, data, len); 1545 memmove(skb->data, data, len);
1343 __skb_trim(skb, len); 1546 skb_set_tail_pointer(skb, len);
1344 } 1547 }
1345 } 1548 }
1346#endif 1549#endif
@@ -1365,17 +1568,11 @@ ieee80211_deliver_skb(struct ieee80211_rx_data *rx)
1365static ieee80211_rx_result debug_noinline 1568static ieee80211_rx_result debug_noinline
1366ieee80211_rx_h_amsdu(struct ieee80211_rx_data *rx) 1569ieee80211_rx_h_amsdu(struct ieee80211_rx_data *rx)
1367{ 1570{
1368 struct net_device *dev = rx->dev; 1571 struct net_device *dev = rx->sdata->dev;
1369 struct ieee80211_local *local = rx->local; 1572 struct sk_buff *skb = rx->skb;
1370 u16 ethertype;
1371 u8 *payload;
1372 struct sk_buff *skb = rx->skb, *frame = NULL;
1373 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; 1573 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1374 __le16 fc = hdr->frame_control; 1574 __le16 fc = hdr->frame_control;
1375 const struct ethhdr *eth; 1575 struct sk_buff_head frame_list;
1376 int remaining, err;
1377 u8 dst[ETH_ALEN];
1378 u8 src[ETH_ALEN];
1379 1576
1380 if (unlikely(!ieee80211_is_data(fc))) 1577 if (unlikely(!ieee80211_is_data(fc)))
1381 return RX_CONTINUE; 1578 return RX_CONTINUE;
@@ -1386,94 +1583,34 @@ ieee80211_rx_h_amsdu(struct ieee80211_rx_data *rx)
1386 if (!(rx->flags & IEEE80211_RX_AMSDU)) 1583 if (!(rx->flags & IEEE80211_RX_AMSDU))
1387 return RX_CONTINUE; 1584 return RX_CONTINUE;
1388 1585
1389 err = __ieee80211_data_to_8023(rx); 1586 if (ieee80211_has_a4(hdr->frame_control) &&
1390 if (unlikely(err)) 1587 rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
1588 !rx->sdata->u.vlan.sta)
1391 return RX_DROP_UNUSABLE; 1589 return RX_DROP_UNUSABLE;
1392 1590
1393 skb->dev = dev; 1591 if (is_multicast_ether_addr(hdr->addr1) &&
1394 1592 ((rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
1395 dev->stats.rx_packets++; 1593 rx->sdata->u.vlan.sta) ||
1396 dev->stats.rx_bytes += skb->len; 1594 (rx->sdata->vif.type == NL80211_IFTYPE_STATION &&
1397 1595 rx->sdata->u.mgd.use_4addr)))
1398 /* skip the wrapping header */
1399 eth = (struct ethhdr *) skb_pull(skb, sizeof(struct ethhdr));
1400 if (!eth)
1401 return RX_DROP_UNUSABLE; 1596 return RX_DROP_UNUSABLE;
1402 1597
1403 while (skb != frame) { 1598 skb->dev = dev;
1404 u8 padding; 1599 __skb_queue_head_init(&frame_list);
1405 __be16 len = eth->h_proto;
1406 unsigned int subframe_len = sizeof(struct ethhdr) + ntohs(len);
1407
1408 remaining = skb->len;
1409 memcpy(dst, eth->h_dest, ETH_ALEN);
1410 memcpy(src, eth->h_source, ETH_ALEN);
1411
1412 padding = ((4 - subframe_len) & 0x3);
1413 /* the last MSDU has no padding */
1414 if (subframe_len > remaining)
1415 return RX_DROP_UNUSABLE;
1416 1600
1417 skb_pull(skb, sizeof(struct ethhdr)); 1601 ieee80211_amsdu_to_8023s(skb, &frame_list, dev->dev_addr,
1418 /* if last subframe reuse skb */ 1602 rx->sdata->vif.type,
1419 if (remaining <= subframe_len + padding) 1603 rx->local->hw.extra_tx_headroom);
1420 frame = skb;
1421 else {
1422 /*
1423 * Allocate and reserve two bytes more for payload
1424 * alignment since sizeof(struct ethhdr) is 14.
1425 */
1426 frame = dev_alloc_skb(
1427 ALIGN(local->hw.extra_tx_headroom, 4) +
1428 subframe_len + 2);
1429
1430 if (frame == NULL)
1431 return RX_DROP_UNUSABLE;
1432
1433 skb_reserve(frame,
1434 ALIGN(local->hw.extra_tx_headroom, 4) +
1435 sizeof(struct ethhdr) + 2);
1436 memcpy(skb_put(frame, ntohs(len)), skb->data,
1437 ntohs(len));
1438
1439 eth = (struct ethhdr *) skb_pull(skb, ntohs(len) +
1440 padding);
1441 if (!eth) {
1442 dev_kfree_skb(frame);
1443 return RX_DROP_UNUSABLE;
1444 }
1445 }
1446 1604
1447 skb_reset_network_header(frame); 1605 while (!skb_queue_empty(&frame_list)) {
1448 frame->dev = dev; 1606 rx->skb = __skb_dequeue(&frame_list);
1449 frame->priority = skb->priority;
1450 rx->skb = frame;
1451
1452 payload = frame->data;
1453 ethertype = (payload[6] << 8) | payload[7];
1454
1455 if (likely((compare_ether_addr(payload, rfc1042_header) == 0 &&
1456 ethertype != ETH_P_AARP && ethertype != ETH_P_IPX) ||
1457 compare_ether_addr(payload,
1458 bridge_tunnel_header) == 0)) {
1459 /* remove RFC1042 or Bridge-Tunnel
1460 * encapsulation and replace EtherType */
1461 skb_pull(frame, 6);
1462 memcpy(skb_push(frame, ETH_ALEN), src, ETH_ALEN);
1463 memcpy(skb_push(frame, ETH_ALEN), dst, ETH_ALEN);
1464 } else {
1465 memcpy(skb_push(frame, sizeof(__be16)),
1466 &len, sizeof(__be16));
1467 memcpy(skb_push(frame, ETH_ALEN), src, ETH_ALEN);
1468 memcpy(skb_push(frame, ETH_ALEN), dst, ETH_ALEN);
1469 }
1470 1607
1471 if (!ieee80211_frame_allowed(rx, fc)) { 1608 if (!ieee80211_frame_allowed(rx, fc)) {
1472 if (skb == frame) /* last frame */ 1609 dev_kfree_skb(rx->skb);
1473 return RX_DROP_UNUSABLE;
1474 dev_kfree_skb(frame);
1475 continue; 1610 continue;
1476 } 1611 }
1612 dev->stats.rx_packets++;
1613 dev->stats.rx_bytes += rx->skb->len;
1477 1614
1478 ieee80211_deliver_skb(rx); 1615 ieee80211_deliver_skb(rx);
1479 } 1616 }
@@ -1490,12 +1627,11 @@ ieee80211_rx_h_mesh_fwding(struct ieee80211_rx_data *rx)
1490 unsigned int hdrlen; 1627 unsigned int hdrlen;
1491 struct sk_buff *skb = rx->skb, *fwd_skb; 1628 struct sk_buff *skb = rx->skb, *fwd_skb;
1492 struct ieee80211_local *local = rx->local; 1629 struct ieee80211_local *local = rx->local;
1493 struct ieee80211_sub_if_data *sdata; 1630 struct ieee80211_sub_if_data *sdata = rx->sdata;
1494 1631
1495 hdr = (struct ieee80211_hdr *) skb->data; 1632 hdr = (struct ieee80211_hdr *) skb->data;
1496 hdrlen = ieee80211_hdrlen(hdr->frame_control); 1633 hdrlen = ieee80211_hdrlen(hdr->frame_control);
1497 mesh_hdr = (struct ieee80211s_hdr *) (skb->data + hdrlen); 1634 mesh_hdr = (struct ieee80211s_hdr *) (skb->data + hdrlen);
1498 sdata = IEEE80211_DEV_TO_SUB_IF(rx->dev);
1499 1635
1500 if (!ieee80211_is_data(hdr->frame_control)) 1636 if (!ieee80211_is_data(hdr->frame_control))
1501 return RX_CONTINUE; 1637 return RX_CONTINUE;
@@ -1504,19 +1640,27 @@ ieee80211_rx_h_mesh_fwding(struct ieee80211_rx_data *rx)
1504 /* illegal frame */ 1640 /* illegal frame */
1505 return RX_DROP_MONITOR; 1641 return RX_DROP_MONITOR;
1506 1642
1507 if (!is_multicast_ether_addr(hdr->addr1) && 1643 if (mesh_hdr->flags & MESH_FLAGS_AE) {
1508 (mesh_hdr->flags & MESH_FLAGS_AE_A5_A6)) {
1509 struct mesh_path *mppath; 1644 struct mesh_path *mppath;
1645 char *proxied_addr;
1646 char *mpp_addr;
1647
1648 if (is_multicast_ether_addr(hdr->addr1)) {
1649 mpp_addr = hdr->addr3;
1650 proxied_addr = mesh_hdr->eaddr1;
1651 } else {
1652 mpp_addr = hdr->addr4;
1653 proxied_addr = mesh_hdr->eaddr2;
1654 }
1510 1655
1511 rcu_read_lock(); 1656 rcu_read_lock();
1512 mppath = mpp_path_lookup(mesh_hdr->eaddr2, sdata); 1657 mppath = mpp_path_lookup(proxied_addr, sdata);
1513 if (!mppath) { 1658 if (!mppath) {
1514 mpp_path_add(mesh_hdr->eaddr2, hdr->addr4, sdata); 1659 mpp_path_add(proxied_addr, mpp_addr, sdata);
1515 } else { 1660 } else {
1516 spin_lock_bh(&mppath->state_lock); 1661 spin_lock_bh(&mppath->state_lock);
1517 mppath->exp_time = jiffies; 1662 if (compare_ether_addr(mppath->mpp, mpp_addr) != 0)
1518 if (compare_ether_addr(mppath->mpp, hdr->addr4) != 0) 1663 memcpy(mppath->mpp, mpp_addr, ETH_ALEN);
1519 memcpy(mppath->mpp, hdr->addr4, ETH_ALEN);
1520 spin_unlock_bh(&mppath->state_lock); 1664 spin_unlock_bh(&mppath->state_lock);
1521 } 1665 }
1522 rcu_read_unlock(); 1666 rcu_read_unlock();
@@ -1524,7 +1668,7 @@ ieee80211_rx_h_mesh_fwding(struct ieee80211_rx_data *rx)
1524 1668
1525 /* Frame has reached destination. Don't forward */ 1669 /* Frame has reached destination. Don't forward */
1526 if (!is_multicast_ether_addr(hdr->addr1) && 1670 if (!is_multicast_ether_addr(hdr->addr1) &&
1527 compare_ether_addr(rx->dev->dev_addr, hdr->addr3) == 0) 1671 compare_ether_addr(sdata->vif.addr, hdr->addr3) == 0)
1528 return RX_CONTINUE; 1672 return RX_CONTINUE;
1529 1673
1530 mesh_hdr->ttl--; 1674 mesh_hdr->ttl--;
@@ -1541,15 +1685,17 @@ ieee80211_rx_h_mesh_fwding(struct ieee80211_rx_data *rx)
1541 1685
1542 if (!fwd_skb && net_ratelimit()) 1686 if (!fwd_skb && net_ratelimit())
1543 printk(KERN_DEBUG "%s: failed to clone mesh frame\n", 1687 printk(KERN_DEBUG "%s: failed to clone mesh frame\n",
1544 rx->dev->name); 1688 sdata->name);
1545 1689
1546 fwd_hdr = (struct ieee80211_hdr *) fwd_skb->data; 1690 fwd_hdr = (struct ieee80211_hdr *) fwd_skb->data;
1547 memcpy(fwd_hdr->addr2, rx->dev->dev_addr, ETH_ALEN); 1691 memcpy(fwd_hdr->addr2, sdata->vif.addr, ETH_ALEN);
1548 info = IEEE80211_SKB_CB(fwd_skb); 1692 info = IEEE80211_SKB_CB(fwd_skb);
1549 memset(info, 0, sizeof(*info)); 1693 memset(info, 0, sizeof(*info));
1550 info->flags |= IEEE80211_TX_INTFL_NEED_TXPROCESSING; 1694 info->flags |= IEEE80211_TX_INTFL_NEED_TXPROCESSING;
1551 info->control.vif = &rx->sdata->vif; 1695 info->control.vif = &rx->sdata->vif;
1552 ieee80211_select_queue(local, fwd_skb); 1696 skb_set_queue_mapping(skb,
1697 ieee80211_select_queue(rx->sdata, fwd_skb));
1698 ieee80211_set_qos_hdr(local, skb);
1553 if (is_multicast_ether_addr(fwd_hdr->addr1)) 1699 if (is_multicast_ether_addr(fwd_hdr->addr1))
1554 IEEE80211_IFSTA_MESH_CTR_INC(&sdata->u.mesh, 1700 IEEE80211_IFSTA_MESH_CTR_INC(&sdata->u.mesh,
1555 fwded_mcast); 1701 fwded_mcast);
@@ -1578,7 +1724,7 @@ ieee80211_rx_h_mesh_fwding(struct ieee80211_rx_data *rx)
1578 } 1724 }
1579 1725
1580 if (is_multicast_ether_addr(hdr->addr1) || 1726 if (is_multicast_ether_addr(hdr->addr1) ||
1581 rx->dev->flags & IFF_PROMISC) 1727 sdata->dev->flags & IFF_PROMISC)
1582 return RX_CONTINUE; 1728 return RX_CONTINUE;
1583 else 1729 else
1584 return RX_DROP_MONITOR; 1730 return RX_DROP_MONITOR;
@@ -1588,7 +1734,9 @@ ieee80211_rx_h_mesh_fwding(struct ieee80211_rx_data *rx)
1588static ieee80211_rx_result debug_noinline 1734static ieee80211_rx_result debug_noinline
1589ieee80211_rx_h_data(struct ieee80211_rx_data *rx) 1735ieee80211_rx_h_data(struct ieee80211_rx_data *rx)
1590{ 1736{
1591 struct net_device *dev = rx->dev; 1737 struct ieee80211_sub_if_data *sdata = rx->sdata;
1738 struct ieee80211_local *local = rx->local;
1739 struct net_device *dev = sdata->dev;
1592 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data; 1740 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
1593 __le16 fc = hdr->frame_control; 1741 __le16 fc = hdr->frame_control;
1594 int err; 1742 int err;
@@ -1599,6 +1747,14 @@ ieee80211_rx_h_data(struct ieee80211_rx_data *rx)
1599 if (unlikely(!ieee80211_is_data_present(hdr->frame_control))) 1747 if (unlikely(!ieee80211_is_data_present(hdr->frame_control)))
1600 return RX_DROP_MONITOR; 1748 return RX_DROP_MONITOR;
1601 1749
1750 /*
1751 * Allow the cooked monitor interface of an AP to see 4-addr frames so
1752 * that a 4-addr station can be detected and moved into a separate VLAN
1753 */
1754 if (ieee80211_has_a4(hdr->frame_control) &&
1755 sdata->vif.type == NL80211_IFTYPE_AP)
1756 return RX_DROP_MONITOR;
1757
1602 err = __ieee80211_data_to_8023(rx); 1758 err = __ieee80211_data_to_8023(rx);
1603 if (unlikely(err)) 1759 if (unlikely(err))
1604 return RX_DROP_UNUSABLE; 1760 return RX_DROP_UNUSABLE;
@@ -1611,13 +1767,20 @@ ieee80211_rx_h_data(struct ieee80211_rx_data *rx)
1611 dev->stats.rx_packets++; 1767 dev->stats.rx_packets++;
1612 dev->stats.rx_bytes += rx->skb->len; 1768 dev->stats.rx_bytes += rx->skb->len;
1613 1769
1770 if (ieee80211_is_data(hdr->frame_control) &&
1771 !is_multicast_ether_addr(hdr->addr1) &&
1772 local->hw.conf.dynamic_ps_timeout > 0 && local->ps_sdata) {
1773 mod_timer(&local->dynamic_ps_timer, jiffies +
1774 msecs_to_jiffies(local->hw.conf.dynamic_ps_timeout));
1775 }
1776
1614 ieee80211_deliver_skb(rx); 1777 ieee80211_deliver_skb(rx);
1615 1778
1616 return RX_QUEUED; 1779 return RX_QUEUED;
1617} 1780}
1618 1781
1619static ieee80211_rx_result debug_noinline 1782static ieee80211_rx_result debug_noinline
1620ieee80211_rx_h_ctrl(struct ieee80211_rx_data *rx) 1783ieee80211_rx_h_ctrl(struct ieee80211_rx_data *rx, struct sk_buff_head *frames)
1621{ 1784{
1622 struct ieee80211_local *local = rx->local; 1785 struct ieee80211_local *local = rx->local;
1623 struct ieee80211_hw *hw = &local->hw; 1786 struct ieee80211_hw *hw = &local->hw;
@@ -1632,11 +1795,11 @@ ieee80211_rx_h_ctrl(struct ieee80211_rx_data *rx)
1632 1795
1633 if (ieee80211_is_back_req(bar->frame_control)) { 1796 if (ieee80211_is_back_req(bar->frame_control)) {
1634 if (!rx->sta) 1797 if (!rx->sta)
1635 return RX_CONTINUE; 1798 return RX_DROP_MONITOR;
1636 tid = le16_to_cpu(bar->control) >> 12; 1799 tid = le16_to_cpu(bar->control) >> 12;
1637 if (rx->sta->ampdu_mlme.tid_state_rx[tid] 1800 if (rx->sta->ampdu_mlme.tid_state_rx[tid]
1638 != HT_AGG_STATE_OPERATIONAL) 1801 != HT_AGG_STATE_OPERATIONAL)
1639 return RX_CONTINUE; 1802 return RX_DROP_MONITOR;
1640 tid_agg_rx = rx->sta->ampdu_mlme.tid_rx[tid]; 1803 tid_agg_rx = rx->sta->ampdu_mlme.tid_rx[tid];
1641 1804
1642 start_seq_num = le16_to_cpu(bar->start_seq_num) >> 4; 1805 start_seq_num = le16_to_cpu(bar->start_seq_num) >> 4;
@@ -1646,13 +1809,11 @@ ieee80211_rx_h_ctrl(struct ieee80211_rx_data *rx)
1646 mod_timer(&tid_agg_rx->session_timer, 1809 mod_timer(&tid_agg_rx->session_timer,
1647 TU_TO_EXP_TIME(tid_agg_rx->timeout)); 1810 TU_TO_EXP_TIME(tid_agg_rx->timeout));
1648 1811
1649 /* manage reordering buffer according to requested */ 1812 /* release stored frames up to start of BAR */
1650 /* sequence number */ 1813 ieee80211_release_reorder_frames(hw, tid_agg_rx, start_seq_num,
1651 rcu_read_lock(); 1814 frames);
1652 ieee80211_sta_manage_reorder_buf(hw, tid_agg_rx, NULL, 1815 kfree_skb(skb);
1653 start_seq_num, 1); 1816 return RX_QUEUED;
1654 rcu_read_unlock();
1655 return RX_DROP_UNUSABLE;
1656 } 1817 }
1657 1818
1658 return RX_CONTINUE; 1819 return RX_CONTINUE;
@@ -1666,7 +1827,7 @@ static void ieee80211_process_sa_query_req(struct ieee80211_sub_if_data *sdata,
1666 struct sk_buff *skb; 1827 struct sk_buff *skb;
1667 struct ieee80211_mgmt *resp; 1828 struct ieee80211_mgmt *resp;
1668 1829
1669 if (compare_ether_addr(mgmt->da, sdata->dev->dev_addr) != 0) { 1830 if (compare_ether_addr(mgmt->da, sdata->vif.addr) != 0) {
1670 /* Not to own unicast address */ 1831 /* Not to own unicast address */
1671 return; 1832 return;
1672 } 1833 }
@@ -1690,7 +1851,7 @@ static void ieee80211_process_sa_query_req(struct ieee80211_sub_if_data *sdata,
1690 resp = (struct ieee80211_mgmt *) skb_put(skb, 24); 1851 resp = (struct ieee80211_mgmt *) skb_put(skb, 24);
1691 memset(resp, 0, 24); 1852 memset(resp, 0, 24);
1692 memcpy(resp->da, mgmt->sa, ETH_ALEN); 1853 memcpy(resp->da, mgmt->sa, ETH_ALEN);
1693 memcpy(resp->sa, sdata->dev->dev_addr, ETH_ALEN); 1854 memcpy(resp->sa, sdata->vif.addr, ETH_ALEN);
1694 memcpy(resp->bssid, sdata->u.mgd.bssid, ETH_ALEN); 1855 memcpy(resp->bssid, sdata->u.mgd.bssid, ETH_ALEN);
1695 resp->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | 1856 resp->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
1696 IEEE80211_STYPE_ACTION); 1857 IEEE80211_STYPE_ACTION);
@@ -1701,32 +1862,34 @@ static void ieee80211_process_sa_query_req(struct ieee80211_sub_if_data *sdata,
1701 mgmt->u.action.u.sa_query.trans_id, 1862 mgmt->u.action.u.sa_query.trans_id,
1702 WLAN_SA_QUERY_TR_ID_LEN); 1863 WLAN_SA_QUERY_TR_ID_LEN);
1703 1864
1704 ieee80211_tx_skb(sdata, skb, 1); 1865 ieee80211_tx_skb(sdata, skb);
1705} 1866}
1706 1867
1707static ieee80211_rx_result debug_noinline 1868static ieee80211_rx_result debug_noinline
1708ieee80211_rx_h_action(struct ieee80211_rx_data *rx) 1869ieee80211_rx_h_action(struct ieee80211_rx_data *rx)
1709{ 1870{
1710 struct ieee80211_local *local = rx->local; 1871 struct ieee80211_local *local = rx->local;
1711 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(rx->dev); 1872 struct ieee80211_sub_if_data *sdata = rx->sdata;
1712 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) rx->skb->data; 1873 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) rx->skb->data;
1874 struct sk_buff *nskb;
1875 struct ieee80211_rx_status *status;
1713 int len = rx->skb->len; 1876 int len = rx->skb->len;
1714 1877
1715 if (!ieee80211_is_action(mgmt->frame_control)) 1878 if (!ieee80211_is_action(mgmt->frame_control))
1716 return RX_CONTINUE; 1879 return RX_CONTINUE;
1717 1880
1718 if (!rx->sta) 1881 /* drop too small frames */
1719 return RX_DROP_MONITOR; 1882 if (len < IEEE80211_MIN_ACTION_SIZE)
1883 return RX_DROP_UNUSABLE;
1720 1884
1721 if (!(rx->flags & IEEE80211_RX_RA_MATCH)) 1885 if (!rx->sta && mgmt->u.action.category != WLAN_CATEGORY_PUBLIC)
1722 return RX_DROP_MONITOR; 1886 return RX_DROP_UNUSABLE;
1723 1887
1724 if (ieee80211_drop_unencrypted(rx, mgmt->frame_control)) 1888 if (!(rx->flags & IEEE80211_RX_RA_MATCH))
1725 return RX_DROP_MONITOR; 1889 return RX_DROP_UNUSABLE;
1726 1890
1727 /* all categories we currently handle have action_code */ 1891 if (ieee80211_drop_unencrypted_mgmt(rx))
1728 if (len < IEEE80211_MIN_ACTION_SIZE + 1) 1892 return RX_DROP_UNUSABLE;
1729 return RX_DROP_MONITOR;
1730 1893
1731 switch (mgmt->u.action.category) { 1894 switch (mgmt->u.action.category) {
1732 case WLAN_CATEGORY_BACK: 1895 case WLAN_CATEGORY_BACK:
@@ -1739,7 +1902,11 @@ ieee80211_rx_h_action(struct ieee80211_rx_data *rx)
1739 if (sdata->vif.type != NL80211_IFTYPE_STATION && 1902 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
1740 sdata->vif.type != NL80211_IFTYPE_AP_VLAN && 1903 sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
1741 sdata->vif.type != NL80211_IFTYPE_AP) 1904 sdata->vif.type != NL80211_IFTYPE_AP)
1742 return RX_DROP_MONITOR; 1905 break;
1906
1907 /* verify action_code is present */
1908 if (len < IEEE80211_MIN_ACTION_SIZE + 1)
1909 break;
1743 1910
1744 switch (mgmt->u.action.u.addba_req.action_code) { 1911 switch (mgmt->u.action.u.addba_req.action_code) {
1745 case WLAN_ACTION_ADDBA_REQ: 1912 case WLAN_ACTION_ADDBA_REQ:
@@ -1747,45 +1914,49 @@ ieee80211_rx_h_action(struct ieee80211_rx_data *rx)
1747 sizeof(mgmt->u.action.u.addba_req))) 1914 sizeof(mgmt->u.action.u.addba_req)))
1748 return RX_DROP_MONITOR; 1915 return RX_DROP_MONITOR;
1749 ieee80211_process_addba_request(local, rx->sta, mgmt, len); 1916 ieee80211_process_addba_request(local, rx->sta, mgmt, len);
1750 break; 1917 goto handled;
1751 case WLAN_ACTION_ADDBA_RESP: 1918 case WLAN_ACTION_ADDBA_RESP:
1752 if (len < (IEEE80211_MIN_ACTION_SIZE + 1919 if (len < (IEEE80211_MIN_ACTION_SIZE +
1753 sizeof(mgmt->u.action.u.addba_resp))) 1920 sizeof(mgmt->u.action.u.addba_resp)))
1754 return RX_DROP_MONITOR; 1921 break;
1755 ieee80211_process_addba_resp(local, rx->sta, mgmt, len); 1922 ieee80211_process_addba_resp(local, rx->sta, mgmt, len);
1756 break; 1923 goto handled;
1757 case WLAN_ACTION_DELBA: 1924 case WLAN_ACTION_DELBA:
1758 if (len < (IEEE80211_MIN_ACTION_SIZE + 1925 if (len < (IEEE80211_MIN_ACTION_SIZE +
1759 sizeof(mgmt->u.action.u.delba))) 1926 sizeof(mgmt->u.action.u.delba)))
1760 return RX_DROP_MONITOR; 1927 break;
1761 ieee80211_process_delba(sdata, rx->sta, mgmt, len); 1928 ieee80211_process_delba(sdata, rx->sta, mgmt, len);
1762 break; 1929 goto handled;
1763 } 1930 }
1764 break; 1931 break;
1765 case WLAN_CATEGORY_SPECTRUM_MGMT: 1932 case WLAN_CATEGORY_SPECTRUM_MGMT:
1766 if (local->hw.conf.channel->band != IEEE80211_BAND_5GHZ) 1933 if (local->hw.conf.channel->band != IEEE80211_BAND_5GHZ)
1767 return RX_DROP_MONITOR; 1934 break;
1768 1935
1769 if (sdata->vif.type != NL80211_IFTYPE_STATION) 1936 if (sdata->vif.type != NL80211_IFTYPE_STATION)
1770 return RX_DROP_MONITOR; 1937 break;
1938
1939 /* verify action_code is present */
1940 if (len < IEEE80211_MIN_ACTION_SIZE + 1)
1941 break;
1771 1942
1772 switch (mgmt->u.action.u.measurement.action_code) { 1943 switch (mgmt->u.action.u.measurement.action_code) {
1773 case WLAN_ACTION_SPCT_MSR_REQ: 1944 case WLAN_ACTION_SPCT_MSR_REQ:
1774 if (len < (IEEE80211_MIN_ACTION_SIZE + 1945 if (len < (IEEE80211_MIN_ACTION_SIZE +
1775 sizeof(mgmt->u.action.u.measurement))) 1946 sizeof(mgmt->u.action.u.measurement)))
1776 return RX_DROP_MONITOR; 1947 break;
1777 ieee80211_process_measurement_req(sdata, mgmt, len); 1948 ieee80211_process_measurement_req(sdata, mgmt, len);
1778 break; 1949 goto handled;
1779 case WLAN_ACTION_SPCT_CHL_SWITCH: 1950 case WLAN_ACTION_SPCT_CHL_SWITCH:
1780 if (len < (IEEE80211_MIN_ACTION_SIZE + 1951 if (len < (IEEE80211_MIN_ACTION_SIZE +
1781 sizeof(mgmt->u.action.u.chan_switch))) 1952 sizeof(mgmt->u.action.u.chan_switch)))
1782 return RX_DROP_MONITOR; 1953 break;
1783 1954
1784 if (sdata->vif.type != NL80211_IFTYPE_STATION) 1955 if (sdata->vif.type != NL80211_IFTYPE_STATION)
1785 return RX_DROP_MONITOR; 1956 break;
1786 1957
1787 if (memcmp(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN)) 1958 if (memcmp(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN))
1788 return RX_DROP_MONITOR; 1959 break;
1789 1960
1790 return ieee80211_sta_rx_mgmt(sdata, rx->skb); 1961 return ieee80211_sta_rx_mgmt(sdata, rx->skb);
1791 } 1962 }
@@ -1793,26 +1964,69 @@ ieee80211_rx_h_action(struct ieee80211_rx_data *rx)
1793 case WLAN_CATEGORY_SA_QUERY: 1964 case WLAN_CATEGORY_SA_QUERY:
1794 if (len < (IEEE80211_MIN_ACTION_SIZE + 1965 if (len < (IEEE80211_MIN_ACTION_SIZE +
1795 sizeof(mgmt->u.action.u.sa_query))) 1966 sizeof(mgmt->u.action.u.sa_query)))
1796 return RX_DROP_MONITOR; 1967 break;
1968
1797 switch (mgmt->u.action.u.sa_query.action) { 1969 switch (mgmt->u.action.u.sa_query.action) {
1798 case WLAN_ACTION_SA_QUERY_REQUEST: 1970 case WLAN_ACTION_SA_QUERY_REQUEST:
1799 if (sdata->vif.type != NL80211_IFTYPE_STATION) 1971 if (sdata->vif.type != NL80211_IFTYPE_STATION)
1800 return RX_DROP_MONITOR; 1972 break;
1801 ieee80211_process_sa_query_req(sdata, mgmt, len); 1973 ieee80211_process_sa_query_req(sdata, mgmt, len);
1802 break; 1974 goto handled;
1803 case WLAN_ACTION_SA_QUERY_RESPONSE:
1804 /*
1805 * SA Query response is currently only used in AP mode
1806 * and it is processed in user space.
1807 */
1808 return RX_CONTINUE;
1809 } 1975 }
1810 break; 1976 break;
1811 default: 1977 case MESH_PLINK_CATEGORY:
1812 return RX_CONTINUE; 1978 case MESH_PATH_SEL_CATEGORY:
1979 if (ieee80211_vif_is_mesh(&sdata->vif))
1980 return ieee80211_mesh_rx_mgmt(sdata, rx->skb);
1981 break;
1813 } 1982 }
1814 1983
1815 rx->sta->rx_packets++; 1984 /*
1985 * For AP mode, hostapd is responsible for handling any action
1986 * frames that we didn't handle, including returning unknown
1987 * ones. For all other modes we will return them to the sender,
1988 * setting the 0x80 bit in the action category, as required by
1989 * 802.11-2007 7.3.1.11.
1990 */
1991 if (sdata->vif.type == NL80211_IFTYPE_AP ||
1992 sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
1993 return RX_DROP_MONITOR;
1994
1995 /*
1996 * Getting here means the kernel doesn't know how to handle
1997 * it, but maybe userspace does ... include returned frames
1998 * so userspace can register for those to know whether ones
1999 * it transmitted were processed or returned.
2000 */
2001 status = IEEE80211_SKB_RXCB(rx->skb);
2002
2003 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
2004 cfg80211_rx_action(rx->sdata->dev, status->freq,
2005 rx->skb->data, rx->skb->len,
2006 GFP_ATOMIC))
2007 goto handled;
2008
2009 /* do not return rejected action frames */
2010 if (mgmt->u.action.category & 0x80)
2011 return RX_DROP_UNUSABLE;
2012
2013 nskb = skb_copy_expand(rx->skb, local->hw.extra_tx_headroom, 0,
2014 GFP_ATOMIC);
2015 if (nskb) {
2016 struct ieee80211_mgmt *mgmt = (void *)nskb->data;
2017
2018 mgmt->u.action.category |= 0x80;
2019 memcpy(mgmt->da, mgmt->sa, ETH_ALEN);
2020 memcpy(mgmt->sa, rx->sdata->vif.addr, ETH_ALEN);
2021
2022 memset(nskb->cb, 0, sizeof(nskb->cb));
2023
2024 ieee80211_tx_skb(rx->sdata, nskb);
2025 }
2026
2027 handled:
2028 if (rx->sta)
2029 rx->sta->rx_packets++;
1816 dev_kfree_skb(rx->skb); 2030 dev_kfree_skb(rx->skb);
1817 return RX_QUEUED; 2031 return RX_QUEUED;
1818} 2032}
@@ -1820,14 +2034,18 @@ ieee80211_rx_h_action(struct ieee80211_rx_data *rx)
1820static ieee80211_rx_result debug_noinline 2034static ieee80211_rx_result debug_noinline
1821ieee80211_rx_h_mgmt(struct ieee80211_rx_data *rx) 2035ieee80211_rx_h_mgmt(struct ieee80211_rx_data *rx)
1822{ 2036{
1823 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(rx->dev); 2037 struct ieee80211_sub_if_data *sdata = rx->sdata;
1824 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) rx->skb->data; 2038 ieee80211_rx_result rxs;
1825 2039
1826 if (!(rx->flags & IEEE80211_RX_RA_MATCH)) 2040 if (!(rx->flags & IEEE80211_RX_RA_MATCH))
1827 return RX_DROP_MONITOR; 2041 return RX_DROP_MONITOR;
1828 2042
1829 if (ieee80211_drop_unencrypted(rx, mgmt->frame_control)) 2043 if (ieee80211_drop_unencrypted_mgmt(rx))
1830 return RX_DROP_MONITOR; 2044 return RX_DROP_UNUSABLE;
2045
2046 rxs = ieee80211_work_rx_mgmt(rx->sdata, rx->skb);
2047 if (rxs != RX_CONTINUE)
2048 return rxs;
1831 2049
1832 if (ieee80211_vif_is_mesh(&sdata->vif)) 2050 if (ieee80211_vif_is_mesh(&sdata->vif))
1833 return ieee80211_mesh_rx_mgmt(sdata, rx->skb); 2051 return ieee80211_mesh_rx_mgmt(sdata, rx->skb);
@@ -1858,11 +2076,11 @@ static void ieee80211_rx_michael_mic_report(struct ieee80211_hdr *hdr,
1858 * Some hardware seem to generate incorrect Michael MIC 2076 * Some hardware seem to generate incorrect Michael MIC
1859 * reports; ignore them to avoid triggering countermeasures. 2077 * reports; ignore them to avoid triggering countermeasures.
1860 */ 2078 */
1861 goto ignore; 2079 return;
1862 } 2080 }
1863 2081
1864 if (!ieee80211_has_protected(hdr->frame_control)) 2082 if (!ieee80211_has_protected(hdr->frame_control))
1865 goto ignore; 2083 return;
1866 2084
1867 if (rx->sdata->vif.type == NL80211_IFTYPE_AP && keyidx) { 2085 if (rx->sdata->vif.type == NL80211_IFTYPE_AP && keyidx) {
1868 /* 2086 /*
@@ -1871,37 +2089,35 @@ static void ieee80211_rx_michael_mic_report(struct ieee80211_hdr *hdr,
1871 * group keys and only the AP is sending real multicast 2089 * group keys and only the AP is sending real multicast
1872 * frames in the BSS. 2090 * frames in the BSS.
1873 */ 2091 */
1874 goto ignore; 2092 return;
1875 } 2093 }
1876 2094
1877 if (!ieee80211_is_data(hdr->frame_control) && 2095 if (!ieee80211_is_data(hdr->frame_control) &&
1878 !ieee80211_is_auth(hdr->frame_control)) 2096 !ieee80211_is_auth(hdr->frame_control))
1879 goto ignore; 2097 return;
1880 2098
1881 mac80211_ev_michael_mic_failure(rx->sdata, keyidx, hdr, NULL, 2099 mac80211_ev_michael_mic_failure(rx->sdata, keyidx, hdr, NULL,
1882 GFP_ATOMIC); 2100 GFP_ATOMIC);
1883 ignore:
1884 dev_kfree_skb(rx->skb);
1885 rx->skb = NULL;
1886} 2101}
1887 2102
1888/* TODO: use IEEE80211_RX_FRAGMENTED */ 2103/* TODO: use IEEE80211_RX_FRAGMENTED */
1889static void ieee80211_rx_cooked_monitor(struct ieee80211_rx_data *rx) 2104static void ieee80211_rx_cooked_monitor(struct ieee80211_rx_data *rx,
2105 struct ieee80211_rate *rate)
1890{ 2106{
1891 struct ieee80211_sub_if_data *sdata; 2107 struct ieee80211_sub_if_data *sdata;
1892 struct ieee80211_local *local = rx->local; 2108 struct ieee80211_local *local = rx->local;
1893 struct ieee80211_rtap_hdr { 2109 struct ieee80211_rtap_hdr {
1894 struct ieee80211_radiotap_header hdr; 2110 struct ieee80211_radiotap_header hdr;
1895 u8 flags; 2111 u8 flags;
1896 u8 rate; 2112 u8 rate_or_pad;
1897 __le16 chan_freq; 2113 __le16 chan_freq;
1898 __le16 chan_flags; 2114 __le16 chan_flags;
1899 } __attribute__ ((packed)) *rthdr; 2115 } __attribute__ ((packed)) *rthdr;
1900 struct sk_buff *skb = rx->skb, *skb2; 2116 struct sk_buff *skb = rx->skb, *skb2;
1901 struct net_device *prev_dev = NULL; 2117 struct net_device *prev_dev = NULL;
1902 struct ieee80211_rx_status *status = rx->status; 2118 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
1903 2119
1904 if (rx->flags & IEEE80211_RX_CMNTR_REPORTED) 2120 if (status->flag & RX_FLAG_INTERNAL_CMTR)
1905 goto out_free_skb; 2121 goto out_free_skb;
1906 2122
1907 if (skb_headroom(skb) < sizeof(*rthdr) && 2123 if (skb_headroom(skb) < sizeof(*rthdr) &&
@@ -1913,10 +2129,13 @@ static void ieee80211_rx_cooked_monitor(struct ieee80211_rx_data *rx)
1913 rthdr->hdr.it_len = cpu_to_le16(sizeof(*rthdr)); 2129 rthdr->hdr.it_len = cpu_to_le16(sizeof(*rthdr));
1914 rthdr->hdr.it_present = 2130 rthdr->hdr.it_present =
1915 cpu_to_le32((1 << IEEE80211_RADIOTAP_FLAGS) | 2131 cpu_to_le32((1 << IEEE80211_RADIOTAP_FLAGS) |
1916 (1 << IEEE80211_RADIOTAP_RATE) |
1917 (1 << IEEE80211_RADIOTAP_CHANNEL)); 2132 (1 << IEEE80211_RADIOTAP_CHANNEL));
1918 2133
1919 rthdr->rate = rx->rate->bitrate / 5; 2134 if (rate) {
2135 rthdr->rate_or_pad = rate->bitrate / 5;
2136 rthdr->hdr.it_present |=
2137 cpu_to_le32(1 << IEEE80211_RADIOTAP_RATE);
2138 }
1920 rthdr->chan_freq = cpu_to_le16(status->freq); 2139 rthdr->chan_freq = cpu_to_le16(status->freq);
1921 2140
1922 if (status->band == IEEE80211_BAND_5GHZ) 2141 if (status->band == IEEE80211_BAND_5GHZ)
@@ -1932,7 +2151,7 @@ static void ieee80211_rx_cooked_monitor(struct ieee80211_rx_data *rx)
1932 skb->protocol = htons(ETH_P_802_2); 2151 skb->protocol = htons(ETH_P_802_2);
1933 2152
1934 list_for_each_entry_rcu(sdata, &local->interfaces, list) { 2153 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
1935 if (!netif_running(sdata->dev)) 2154 if (!ieee80211_sdata_running(sdata))
1936 continue; 2155 continue;
1937 2156
1938 if (sdata->vif.type != NL80211_IFTYPE_MONITOR || 2157 if (sdata->vif.type != NL80211_IFTYPE_MONITOR ||
@@ -1959,7 +2178,7 @@ static void ieee80211_rx_cooked_monitor(struct ieee80211_rx_data *rx)
1959 } else 2178 } else
1960 goto out_free_skb; 2179 goto out_free_skb;
1961 2180
1962 rx->flags |= IEEE80211_RX_CMNTR_REPORTED; 2181 status->flag |= RX_FLAG_INTERNAL_CMTR;
1963 return; 2182 return;
1964 2183
1965 out_free_skb: 2184 out_free_skb:
@@ -1969,62 +2188,87 @@ static void ieee80211_rx_cooked_monitor(struct ieee80211_rx_data *rx)
1969 2188
1970static void ieee80211_invoke_rx_handlers(struct ieee80211_sub_if_data *sdata, 2189static void ieee80211_invoke_rx_handlers(struct ieee80211_sub_if_data *sdata,
1971 struct ieee80211_rx_data *rx, 2190 struct ieee80211_rx_data *rx,
1972 struct sk_buff *skb) 2191 struct sk_buff *skb,
2192 struct ieee80211_rate *rate)
1973{ 2193{
2194 struct sk_buff_head reorder_release;
1974 ieee80211_rx_result res = RX_DROP_MONITOR; 2195 ieee80211_rx_result res = RX_DROP_MONITOR;
1975 2196
2197 __skb_queue_head_init(&reorder_release);
2198
1976 rx->skb = skb; 2199 rx->skb = skb;
1977 rx->sdata = sdata; 2200 rx->sdata = sdata;
1978 rx->dev = sdata->dev;
1979 2201
1980#define CALL_RXH(rxh) \ 2202#define CALL_RXH(rxh) \
1981 do { \ 2203 do { \
1982 res = rxh(rx); \ 2204 res = rxh(rx); \
1983 if (res != RX_CONTINUE) \ 2205 if (res != RX_CONTINUE) \
1984 goto rxh_done; \ 2206 goto rxh_next; \
1985 } while (0); 2207 } while (0);
1986 2208
2209 /*
2210 * NB: the rxh_next label works even if we jump
2211 * to it from here because then the list will
2212 * be empty, which is a trivial check
2213 */
1987 CALL_RXH(ieee80211_rx_h_passive_scan) 2214 CALL_RXH(ieee80211_rx_h_passive_scan)
1988 CALL_RXH(ieee80211_rx_h_check) 2215 CALL_RXH(ieee80211_rx_h_check)
1989 CALL_RXH(ieee80211_rx_h_decrypt) 2216
1990 CALL_RXH(ieee80211_rx_h_check_more_data) 2217 ieee80211_rx_reorder_ampdu(rx, &reorder_release);
1991 CALL_RXH(ieee80211_rx_h_sta_process) 2218
1992 CALL_RXH(ieee80211_rx_h_defragment) 2219 while ((skb = __skb_dequeue(&reorder_release))) {
1993 CALL_RXH(ieee80211_rx_h_ps_poll) 2220 /*
1994 CALL_RXH(ieee80211_rx_h_michael_mic_verify) 2221 * all the other fields are valid across frames
1995 /* must be after MMIC verify so header is counted in MPDU mic */ 2222 * that belong to an aMPDU since they are on the
1996 CALL_RXH(ieee80211_rx_h_remove_qos_control) 2223 * same TID from the same station
1997 CALL_RXH(ieee80211_rx_h_amsdu) 2224 */
2225 rx->skb = skb;
2226
2227 CALL_RXH(ieee80211_rx_h_decrypt)
2228 CALL_RXH(ieee80211_rx_h_check_more_data)
2229 CALL_RXH(ieee80211_rx_h_sta_process)
2230 CALL_RXH(ieee80211_rx_h_defragment)
2231 CALL_RXH(ieee80211_rx_h_ps_poll)
2232 CALL_RXH(ieee80211_rx_h_michael_mic_verify)
2233 /* must be after MMIC verify so header is counted in MPDU mic */
2234 CALL_RXH(ieee80211_rx_h_remove_qos_control)
2235 CALL_RXH(ieee80211_rx_h_amsdu)
1998#ifdef CONFIG_MAC80211_MESH 2236#ifdef CONFIG_MAC80211_MESH
1999 if (ieee80211_vif_is_mesh(&sdata->vif)) 2237 if (ieee80211_vif_is_mesh(&sdata->vif))
2000 CALL_RXH(ieee80211_rx_h_mesh_fwding); 2238 CALL_RXH(ieee80211_rx_h_mesh_fwding);
2001#endif 2239#endif
2002 CALL_RXH(ieee80211_rx_h_data) 2240 CALL_RXH(ieee80211_rx_h_data)
2003 CALL_RXH(ieee80211_rx_h_ctrl) 2241
2004 CALL_RXH(ieee80211_rx_h_action) 2242 /* special treatment -- needs the queue */
2005 CALL_RXH(ieee80211_rx_h_mgmt) 2243 res = ieee80211_rx_h_ctrl(rx, &reorder_release);
2244 if (res != RX_CONTINUE)
2245 goto rxh_next;
2246
2247 CALL_RXH(ieee80211_rx_h_action)
2248 CALL_RXH(ieee80211_rx_h_mgmt)
2006 2249
2007#undef CALL_RXH 2250#undef CALL_RXH
2008 2251
2009 rxh_done: 2252 rxh_next:
2010 switch (res) { 2253 switch (res) {
2011 case RX_DROP_MONITOR: 2254 case RX_DROP_MONITOR:
2012 I802_DEBUG_INC(sdata->local->rx_handlers_drop); 2255 I802_DEBUG_INC(sdata->local->rx_handlers_drop);
2013 if (rx->sta) 2256 if (rx->sta)
2014 rx->sta->rx_dropped++; 2257 rx->sta->rx_dropped++;
2015 /* fall through */ 2258 /* fall through */
2016 case RX_CONTINUE: 2259 case RX_CONTINUE:
2017 ieee80211_rx_cooked_monitor(rx); 2260 ieee80211_rx_cooked_monitor(rx, rate);
2018 break; 2261 break;
2019 case RX_DROP_UNUSABLE: 2262 case RX_DROP_UNUSABLE:
2020 I802_DEBUG_INC(sdata->local->rx_handlers_drop); 2263 I802_DEBUG_INC(sdata->local->rx_handlers_drop);
2021 if (rx->sta) 2264 if (rx->sta)
2022 rx->sta->rx_dropped++; 2265 rx->sta->rx_dropped++;
2023 dev_kfree_skb(rx->skb); 2266 dev_kfree_skb(rx->skb);
2024 break; 2267 break;
2025 case RX_QUEUED: 2268 case RX_QUEUED:
2026 I802_DEBUG_INC(sdata->local->rx_handlers_queued); 2269 I802_DEBUG_INC(sdata->local->rx_handlers_queued);
2027 break; 2270 break;
2271 }
2028 } 2272 }
2029} 2273}
2030 2274
@@ -2034,15 +2278,17 @@ static int prepare_for_handlers(struct ieee80211_sub_if_data *sdata,
2034 struct ieee80211_rx_data *rx, 2278 struct ieee80211_rx_data *rx,
2035 struct ieee80211_hdr *hdr) 2279 struct ieee80211_hdr *hdr)
2036{ 2280{
2037 u8 *bssid = ieee80211_get_bssid(hdr, rx->skb->len, sdata->vif.type); 2281 struct sk_buff *skb = rx->skb;
2282 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
2283 u8 *bssid = ieee80211_get_bssid(hdr, skb->len, sdata->vif.type);
2038 int multicast = is_multicast_ether_addr(hdr->addr1); 2284 int multicast = is_multicast_ether_addr(hdr->addr1);
2039 2285
2040 switch (sdata->vif.type) { 2286 switch (sdata->vif.type) {
2041 case NL80211_IFTYPE_STATION: 2287 case NL80211_IFTYPE_STATION:
2042 if (!bssid) 2288 if (!bssid && !sdata->u.mgd.use_4addr)
2043 return 0; 2289 return 0;
2044 if (!multicast && 2290 if (!multicast &&
2045 compare_ether_addr(sdata->dev->dev_addr, hdr->addr1) != 0) { 2291 compare_ether_addr(sdata->vif.addr, hdr->addr1) != 0) {
2046 if (!(sdata->dev->flags & IFF_PROMISC)) 2292 if (!(sdata->dev->flags & IFF_PROMISC))
2047 return 0; 2293 return 0;
2048 rx->flags &= ~IEEE80211_RX_RA_MATCH; 2294 rx->flags &= ~IEEE80211_RX_RA_MATCH;
@@ -2059,24 +2305,24 @@ static int prepare_for_handlers(struct ieee80211_sub_if_data *sdata,
2059 return 0; 2305 return 0;
2060 rx->flags &= ~IEEE80211_RX_RA_MATCH; 2306 rx->flags &= ~IEEE80211_RX_RA_MATCH;
2061 } else if (!multicast && 2307 } else if (!multicast &&
2062 compare_ether_addr(sdata->dev->dev_addr, 2308 compare_ether_addr(sdata->vif.addr,
2063 hdr->addr1) != 0) { 2309 hdr->addr1) != 0) {
2064 if (!(sdata->dev->flags & IFF_PROMISC)) 2310 if (!(sdata->dev->flags & IFF_PROMISC))
2065 return 0; 2311 return 0;
2066 rx->flags &= ~IEEE80211_RX_RA_MATCH; 2312 rx->flags &= ~IEEE80211_RX_RA_MATCH;
2067 } else if (!rx->sta) { 2313 } else if (!rx->sta) {
2068 int rate_idx; 2314 int rate_idx;
2069 if (rx->status->flag & RX_FLAG_HT) 2315 if (status->flag & RX_FLAG_HT)
2070 rate_idx = 0; /* TODO: HT rates */ 2316 rate_idx = 0; /* TODO: HT rates */
2071 else 2317 else
2072 rate_idx = rx->status->rate_idx; 2318 rate_idx = status->rate_idx;
2073 rx->sta = ieee80211_ibss_add_sta(sdata, bssid, hdr->addr2, 2319 rx->sta = ieee80211_ibss_add_sta(sdata, bssid,
2074 BIT(rate_idx)); 2320 hdr->addr2, BIT(rate_idx), GFP_ATOMIC);
2075 } 2321 }
2076 break; 2322 break;
2077 case NL80211_IFTYPE_MESH_POINT: 2323 case NL80211_IFTYPE_MESH_POINT:
2078 if (!multicast && 2324 if (!multicast &&
2079 compare_ether_addr(sdata->dev->dev_addr, 2325 compare_ether_addr(sdata->vif.addr,
2080 hdr->addr1) != 0) { 2326 hdr->addr1) != 0) {
2081 if (!(sdata->dev->flags & IFF_PROMISC)) 2327 if (!(sdata->dev->flags & IFF_PROMISC))
2082 return 0; 2328 return 0;
@@ -2087,11 +2333,11 @@ static int prepare_for_handlers(struct ieee80211_sub_if_data *sdata,
2087 case NL80211_IFTYPE_AP_VLAN: 2333 case NL80211_IFTYPE_AP_VLAN:
2088 case NL80211_IFTYPE_AP: 2334 case NL80211_IFTYPE_AP:
2089 if (!bssid) { 2335 if (!bssid) {
2090 if (compare_ether_addr(sdata->dev->dev_addr, 2336 if (compare_ether_addr(sdata->vif.addr,
2091 hdr->addr1)) 2337 hdr->addr1))
2092 return 0; 2338 return 0;
2093 } else if (!ieee80211_bssid_match(bssid, 2339 } else if (!ieee80211_bssid_match(bssid,
2094 sdata->dev->dev_addr)) { 2340 sdata->vif.addr)) {
2095 if (!(rx->flags & IEEE80211_RX_IN_SCAN)) 2341 if (!(rx->flags & IEEE80211_RX_IN_SCAN))
2096 return 0; 2342 return 0;
2097 rx->flags &= ~IEEE80211_RX_RA_MATCH; 2343 rx->flags &= ~IEEE80211_RX_RA_MATCH;
@@ -2104,8 +2350,6 @@ static int prepare_for_handlers(struct ieee80211_sub_if_data *sdata,
2104 return 0; 2350 return 0;
2105 break; 2351 break;
2106 case NL80211_IFTYPE_MONITOR: 2352 case NL80211_IFTYPE_MONITOR:
2107 /* take everything */
2108 break;
2109 case NL80211_IFTYPE_UNSPECIFIED: 2353 case NL80211_IFTYPE_UNSPECIFIED:
2110 case __NL80211_IFTYPE_AFTER_LAST: 2354 case __NL80211_IFTYPE_AFTER_LAST:
2111 /* should never get here */ 2355 /* should never get here */
@@ -2132,29 +2376,17 @@ static void __ieee80211_rx_handle_packet(struct ieee80211_hw *hw,
2132 int prepares; 2376 int prepares;
2133 struct ieee80211_sub_if_data *prev = NULL; 2377 struct ieee80211_sub_if_data *prev = NULL;
2134 struct sk_buff *skb_new; 2378 struct sk_buff *skb_new;
2379 struct sta_info *sta, *tmp;
2380 bool found_sta = false;
2135 2381
2136 hdr = (struct ieee80211_hdr *)skb->data; 2382 hdr = (struct ieee80211_hdr *)skb->data;
2137 memset(&rx, 0, sizeof(rx)); 2383 memset(&rx, 0, sizeof(rx));
2138 rx.skb = skb; 2384 rx.skb = skb;
2139 rx.local = local; 2385 rx.local = local;
2140 2386
2141 rx.status = status;
2142 rx.rate = rate;
2143
2144 if (ieee80211_is_data(hdr->frame_control) || ieee80211_is_mgmt(hdr->frame_control)) 2387 if (ieee80211_is_data(hdr->frame_control) || ieee80211_is_mgmt(hdr->frame_control))
2145 local->dot11ReceivedFragmentCount++; 2388 local->dot11ReceivedFragmentCount++;
2146 2389
2147 rx.sta = sta_info_get(local, hdr->addr2);
2148 if (rx.sta) {
2149 rx.sdata = rx.sta->sdata;
2150 rx.dev = rx.sta->sdata->dev;
2151 }
2152
2153 if ((status->flag & RX_FLAG_MMIC_ERROR)) {
2154 ieee80211_rx_michael_mic_report(hdr, &rx);
2155 return;
2156 }
2157
2158 if (unlikely(test_bit(SCAN_HW_SCANNING, &local->scanning) || 2390 if (unlikely(test_bit(SCAN_HW_SCANNING, &local->scanning) ||
2159 test_bit(SCAN_OFF_CHANNEL, &local->scanning))) 2391 test_bit(SCAN_OFF_CHANNEL, &local->scanning)))
2160 rx.flags |= IEEE80211_RX_IN_SCAN; 2392 rx.flags |= IEEE80211_RX_IN_SCAN;
@@ -2162,284 +2394,92 @@ static void __ieee80211_rx_handle_packet(struct ieee80211_hw *hw,
2162 ieee80211_parse_qos(&rx); 2394 ieee80211_parse_qos(&rx);
2163 ieee80211_verify_alignment(&rx); 2395 ieee80211_verify_alignment(&rx);
2164 2396
2165 skb = rx.skb; 2397 if (ieee80211_is_data(hdr->frame_control)) {
2166 2398 for_each_sta_info(local, hdr->addr2, sta, tmp) {
2167 if (rx.sdata && ieee80211_is_data(hdr->frame_control)) { 2399 rx.sta = sta;
2168 rx.flags |= IEEE80211_RX_RA_MATCH; 2400 found_sta = true;
2169 prepares = prepare_for_handlers(rx.sdata, &rx, hdr); 2401 rx.sdata = sta->sdata;
2170 if (prepares) 2402
2171 prev = rx.sdata; 2403 rx.flags |= IEEE80211_RX_RA_MATCH;
2172 } else list_for_each_entry_rcu(sdata, &local->interfaces, list) { 2404 prepares = prepare_for_handlers(rx.sdata, &rx, hdr);
2173 if (!netif_running(sdata->dev)) 2405 if (prepares) {
2174 continue; 2406 if (status->flag & RX_FLAG_MMIC_ERROR) {
2175 2407 if (rx.flags & IEEE80211_RX_RA_MATCH)
2176 if (sdata->vif.type == NL80211_IFTYPE_MONITOR || 2408 ieee80211_rx_michael_mic_report(hdr, &rx);
2177 sdata->vif.type == NL80211_IFTYPE_AP_VLAN) 2409 } else
2178 continue; 2410 prev = rx.sdata;
2179 2411 }
2180 rx.flags |= IEEE80211_RX_RA_MATCH;
2181 prepares = prepare_for_handlers(sdata, &rx, hdr);
2182
2183 if (!prepares)
2184 continue;
2185
2186 /*
2187 * frame is destined for this interface, but if it's not
2188 * also for the previous one we handle that after the
2189 * loop to avoid copying the SKB once too much
2190 */
2191
2192 if (!prev) {
2193 prev = sdata;
2194 continue;
2195 }
2196
2197 /*
2198 * frame was destined for the previous interface
2199 * so invoke RX handlers for it
2200 */
2201
2202 skb_new = skb_copy(skb, GFP_ATOMIC);
2203 if (!skb_new) {
2204 if (net_ratelimit())
2205 printk(KERN_DEBUG "%s: failed to copy "
2206 "multicast frame for %s\n",
2207 wiphy_name(local->hw.wiphy),
2208 prev->dev->name);
2209 continue;
2210 }
2211 ieee80211_invoke_rx_handlers(prev, &rx, skb_new);
2212 prev = sdata;
2213 }
2214 if (prev)
2215 ieee80211_invoke_rx_handlers(prev, &rx, skb);
2216 else
2217 dev_kfree_skb(skb);
2218}
2219
2220#define SEQ_MODULO 0x1000
2221#define SEQ_MASK 0xfff
2222
2223static inline int seq_less(u16 sq1, u16 sq2)
2224{
2225 return ((sq1 - sq2) & SEQ_MASK) > (SEQ_MODULO >> 1);
2226}
2227
2228static inline u16 seq_inc(u16 sq)
2229{
2230 return (sq + 1) & SEQ_MASK;
2231}
2232
2233static inline u16 seq_sub(u16 sq1, u16 sq2)
2234{
2235 return (sq1 - sq2) & SEQ_MASK;
2236}
2237
2238
2239static void ieee80211_release_reorder_frame(struct ieee80211_hw *hw,
2240 struct tid_ampdu_rx *tid_agg_rx,
2241 int index)
2242{
2243 struct ieee80211_supported_band *sband;
2244 struct ieee80211_rate *rate;
2245 struct sk_buff *skb = tid_agg_rx->reorder_buf[index];
2246 struct ieee80211_rx_status *status;
2247
2248 if (!skb)
2249 goto no_frame;
2250
2251 status = IEEE80211_SKB_RXCB(skb);
2252
2253 /* release the reordered frames to stack */
2254 sband = hw->wiphy->bands[status->band];
2255 if (status->flag & RX_FLAG_HT)
2256 rate = sband->bitrates; /* TODO: HT rates */
2257 else
2258 rate = &sband->bitrates[status->rate_idx];
2259 __ieee80211_rx_handle_packet(hw, skb, rate);
2260 tid_agg_rx->stored_mpdu_num--;
2261 tid_agg_rx->reorder_buf[index] = NULL;
2262
2263no_frame:
2264 tid_agg_rx->head_seq_num = seq_inc(tid_agg_rx->head_seq_num);
2265}
2266
2267
2268/*
2269 * Timeout (in jiffies) for skb's that are waiting in the RX reorder buffer. If
2270 * the skb was added to the buffer longer than this time ago, the earlier
2271 * frames that have not yet been received are assumed to be lost and the skb
2272 * can be released for processing. This may also release other skb's from the
2273 * reorder buffer if there are no additional gaps between the frames.
2274 */
2275#define HT_RX_REORDER_BUF_TIMEOUT (HZ / 10)
2276
2277/*
2278 * As it function blongs to Rx path it must be called with
2279 * the proper rcu_read_lock protection for its flow.
2280 */
2281static u8 ieee80211_sta_manage_reorder_buf(struct ieee80211_hw *hw,
2282 struct tid_ampdu_rx *tid_agg_rx,
2283 struct sk_buff *skb,
2284 u16 mpdu_seq_num,
2285 int bar_req)
2286{
2287 u16 head_seq_num, buf_size;
2288 int index;
2289
2290 buf_size = tid_agg_rx->buf_size;
2291 head_seq_num = tid_agg_rx->head_seq_num;
2292
2293 /* frame with out of date sequence number */
2294 if (seq_less(mpdu_seq_num, head_seq_num)) {
2295 dev_kfree_skb(skb);
2296 return 1;
2297 }
2298
2299 /* if frame sequence number exceeds our buffering window size or
2300 * block Ack Request arrived - release stored frames */
2301 if ((!seq_less(mpdu_seq_num, head_seq_num + buf_size)) || (bar_req)) {
2302 /* new head to the ordering buffer */
2303 if (bar_req)
2304 head_seq_num = mpdu_seq_num;
2305 else
2306 head_seq_num =
2307 seq_inc(seq_sub(mpdu_seq_num, buf_size));
2308 /* release stored frames up to new head to stack */
2309 while (seq_less(tid_agg_rx->head_seq_num, head_seq_num)) {
2310 index = seq_sub(tid_agg_rx->head_seq_num,
2311 tid_agg_rx->ssn)
2312 % tid_agg_rx->buf_size;
2313 ieee80211_release_reorder_frame(hw, tid_agg_rx,
2314 index);
2315 } 2412 }
2316 if (bar_req)
2317 return 1;
2318 }
2319
2320 /* now the new frame is always in the range of the reordering */
2321 /* buffer window */
2322 index = seq_sub(mpdu_seq_num, tid_agg_rx->ssn)
2323 % tid_agg_rx->buf_size;
2324 /* check if we already stored this frame */
2325 if (tid_agg_rx->reorder_buf[index]) {
2326 dev_kfree_skb(skb);
2327 return 1;
2328 } 2413 }
2329 2414 if (!found_sta) {
2330 /* if arrived mpdu is in the right order and nothing else stored */ 2415 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
2331 /* release it immediately */ 2416 if (!ieee80211_sdata_running(sdata))
2332 if (mpdu_seq_num == tid_agg_rx->head_seq_num &&
2333 tid_agg_rx->stored_mpdu_num == 0) {
2334 tid_agg_rx->head_seq_num =
2335 seq_inc(tid_agg_rx->head_seq_num);
2336 return 0;
2337 }
2338
2339 /* put the frame in the reordering buffer */
2340 tid_agg_rx->reorder_buf[index] = skb;
2341 tid_agg_rx->reorder_time[index] = jiffies;
2342 tid_agg_rx->stored_mpdu_num++;
2343 /* release the buffer until next missing frame */
2344 index = seq_sub(tid_agg_rx->head_seq_num, tid_agg_rx->ssn)
2345 % tid_agg_rx->buf_size;
2346 if (!tid_agg_rx->reorder_buf[index] &&
2347 tid_agg_rx->stored_mpdu_num > 1) {
2348 /*
2349 * No buffers ready to be released, but check whether any
2350 * frames in the reorder buffer have timed out.
2351 */
2352 int j;
2353 int skipped = 1;
2354 for (j = (index + 1) % tid_agg_rx->buf_size; j != index;
2355 j = (j + 1) % tid_agg_rx->buf_size) {
2356 if (tid_agg_rx->reorder_buf[j] == NULL) {
2357 skipped++;
2358 continue; 2417 continue;
2359 }
2360 if (!time_after(jiffies, tid_agg_rx->reorder_time[j] +
2361 HZ / 10))
2362 break;
2363 2418
2364#ifdef CONFIG_MAC80211_HT_DEBUG 2419 if (sdata->vif.type == NL80211_IFTYPE_MONITOR ||
2365 if (net_ratelimit()) 2420 sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
2366 printk(KERN_DEBUG "%s: release an RX reorder " 2421 continue;
2367 "frame due to timeout on earlier "
2368 "frames\n",
2369 wiphy_name(hw->wiphy));
2370#endif
2371 ieee80211_release_reorder_frame(hw, tid_agg_rx, j);
2372 2422
2373 /* 2423 /*
2374 * Increment the head seq# also for the skipped slots. 2424 * frame is destined for this interface, but if it's
2425 * not also for the previous one we handle that after
2426 * the loop to avoid copying the SKB once too much
2375 */ 2427 */
2376 tid_agg_rx->head_seq_num =
2377 (tid_agg_rx->head_seq_num + skipped) &
2378 SEQ_MASK;
2379 skipped = 0;
2380 }
2381 } else while (tid_agg_rx->reorder_buf[index]) {
2382 ieee80211_release_reorder_frame(hw, tid_agg_rx, index);
2383 index = seq_sub(tid_agg_rx->head_seq_num,
2384 tid_agg_rx->ssn) % tid_agg_rx->buf_size;
2385 }
2386 return 1;
2387}
2388 2428
2389static u8 ieee80211_rx_reorder_ampdu(struct ieee80211_local *local, 2429 if (!prev) {
2390 struct sk_buff *skb) 2430 prev = sdata;
2391{ 2431 continue;
2392 struct ieee80211_hw *hw = &local->hw; 2432 }
2393 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
2394 struct sta_info *sta;
2395 struct tid_ampdu_rx *tid_agg_rx;
2396 u16 sc;
2397 u16 mpdu_seq_num;
2398 u8 ret = 0;
2399 int tid;
2400 2433
2401 sta = sta_info_get(local, hdr->addr2); 2434 rx.sta = sta_info_get_bss(prev, hdr->addr2);
2402 if (!sta)
2403 return ret;
2404 2435
2405 /* filter the QoS data rx stream according to 2436 rx.flags |= IEEE80211_RX_RA_MATCH;
2406 * STA/TID and check if this STA/TID is on aggregation */ 2437 prepares = prepare_for_handlers(prev, &rx, hdr);
2407 if (!ieee80211_is_data_qos(hdr->frame_control))
2408 goto end_reorder;
2409 2438
2410 tid = *ieee80211_get_qos_ctl(hdr) & IEEE80211_QOS_CTL_TID_MASK; 2439 if (!prepares)
2440 goto next;
2411 2441
2412 if (sta->ampdu_mlme.tid_state_rx[tid] != HT_AGG_STATE_OPERATIONAL) 2442 if (status->flag & RX_FLAG_MMIC_ERROR) {
2413 goto end_reorder; 2443 rx.sdata = prev;
2444 if (rx.flags & IEEE80211_RX_RA_MATCH)
2445 ieee80211_rx_michael_mic_report(hdr,
2446 &rx);
2447 goto next;
2448 }
2414 2449
2415 tid_agg_rx = sta->ampdu_mlme.tid_rx[tid]; 2450 /*
2451 * frame was destined for the previous interface
2452 * so invoke RX handlers for it
2453 */
2416 2454
2417 /* qos null data frames are excluded */ 2455 skb_new = skb_copy(skb, GFP_ATOMIC);
2418 if (unlikely(hdr->frame_control & cpu_to_le16(IEEE80211_STYPE_NULLFUNC))) 2456 if (!skb_new) {
2419 goto end_reorder; 2457 if (net_ratelimit())
2458 printk(KERN_DEBUG "%s: failed to copy "
2459 "multicast frame for %s\n",
2460 wiphy_name(local->hw.wiphy),
2461 prev->name);
2462 goto next;
2463 }
2464 ieee80211_invoke_rx_handlers(prev, &rx, skb_new, rate);
2465next:
2466 prev = sdata;
2467 }
2420 2468
2421 /* new un-ordered ampdu frame - process it */ 2469 if (prev) {
2470 rx.sta = sta_info_get_bss(prev, hdr->addr2);
2422 2471
2423 /* reset session timer */ 2472 rx.flags |= IEEE80211_RX_RA_MATCH;
2424 if (tid_agg_rx->timeout) 2473 prepares = prepare_for_handlers(prev, &rx, hdr);
2425 mod_timer(&tid_agg_rx->session_timer,
2426 TU_TO_EXP_TIME(tid_agg_rx->timeout));
2427 2474
2428 /* if this mpdu is fragmented - terminate rx aggregation session */ 2475 if (!prepares)
2429 sc = le16_to_cpu(hdr->seq_ctrl); 2476 prev = NULL;
2430 if (sc & IEEE80211_SCTL_FRAG) { 2477 }
2431 ieee80211_sta_stop_rx_ba_session(sta->sdata, sta->sta.addr,
2432 tid, 0, WLAN_REASON_QSTA_REQUIRE_SETUP);
2433 ret = 1;
2434 goto end_reorder;
2435 } 2478 }
2436 2479 if (prev)
2437 /* according to mpdu sequence number deal with reordering buffer */ 2480 ieee80211_invoke_rx_handlers(prev, &rx, skb, rate);
2438 mpdu_seq_num = (sc & IEEE80211_SCTL_SEQ) >> 4; 2481 else
2439 ret = ieee80211_sta_manage_reorder_buf(hw, tid_agg_rx, skb, 2482 dev_kfree_skb(skb);
2440 mpdu_seq_num, 0);
2441 end_reorder:
2442 return ret;
2443} 2483}
2444 2484
2445/* 2485/*
@@ -2481,14 +2521,22 @@ void ieee80211_rx(struct ieee80211_hw *hw, struct sk_buff *skb)
2481 goto drop; 2521 goto drop;
2482 2522
2483 if (status->flag & RX_FLAG_HT) { 2523 if (status->flag & RX_FLAG_HT) {
2484 /* rate_idx is MCS index */ 2524 /*
2485 if (WARN_ON(status->rate_idx < 0 || 2525 * rate_idx is MCS index, which can be [0-76] as documented on:
2486 status->rate_idx >= 76)) 2526 *
2527 * http://wireless.kernel.org/en/developers/Documentation/ieee80211/802.11n
2528 *
2529 * Anything else would be some sort of driver or hardware error.
2530 * The driver should catch hardware errors.
2531 */
2532 if (WARN((status->rate_idx < 0 ||
2533 status->rate_idx > 76),
2534 "Rate marked as an HT rate but passed "
2535 "status->rate_idx is not "
2536 "an MCS index [0-76]: %d (0x%02x)\n",
2537 status->rate_idx,
2538 status->rate_idx))
2487 goto drop; 2539 goto drop;
2488 /* HT rates are not in the table - use the highest legacy rate
2489 * for now since other parts of mac80211 may not yet be fully
2490 * MCS aware. */
2491 rate = &sband->bitrates[sband->n_bitrates - 1];
2492 } else { 2540 } else {
2493 if (WARN_ON(status->rate_idx < 0 || 2541 if (WARN_ON(status->rate_idx < 0 ||
2494 status->rate_idx >= sband->n_bitrates)) 2542 status->rate_idx >= sband->n_bitrates))
@@ -2515,20 +2563,7 @@ void ieee80211_rx(struct ieee80211_hw *hw, struct sk_buff *skb)
2515 return; 2563 return;
2516 } 2564 }
2517 2565
2518 /* 2566 __ieee80211_rx_handle_packet(hw, skb, rate);
2519 * In theory, the block ack reordering should happen after duplicate
2520 * removal (ieee80211_rx_h_check(), which is an RX handler). As such,
2521 * the call to ieee80211_rx_reorder_ampdu() should really be moved to
2522 * happen as a new RX handler between ieee80211_rx_h_check and
2523 * ieee80211_rx_h_decrypt. This cleanup may eventually happen, but for
2524 * the time being, the call can be here since RX reorder buf processing
2525 * will implicitly skip duplicates. We could, in theory at least,
2526 * process frames that ieee80211_rx_h_passive_scan would drop (e.g.,
2527 * frames from other than operational channel), but that should not
2528 * happen in normal networks.
2529 */
2530 if (!ieee80211_rx_reorder_ampdu(local, skb))
2531 __ieee80211_rx_handle_packet(hw, skb, rate);
2532 2567
2533 rcu_read_unlock(); 2568 rcu_read_unlock();
2534 2569
diff --git a/net/mac80211/scan.c b/net/mac80211/scan.c
index 71e10cabf811..85507bd9e341 100644
--- a/net/mac80211/scan.c
+++ b/net/mac80211/scan.c
@@ -12,11 +12,9 @@
12 * published by the Free Software Foundation. 12 * published by the Free Software Foundation.
13 */ 13 */
14 14
15/* TODO: figure out how to avoid that the "current BSS" expires */
16
17#include <linux/wireless.h>
18#include <linux/if_arp.h> 15#include <linux/if_arp.h>
19#include <linux/rtnetlink.h> 16#include <linux/rtnetlink.h>
17#include <linux/slab.h>
20#include <net/mac80211.h> 18#include <net/mac80211.h>
21 19
22#include "ieee80211_i.h" 20#include "ieee80211_i.h"
@@ -31,16 +29,19 @@ struct ieee80211_bss *
31ieee80211_rx_bss_get(struct ieee80211_local *local, u8 *bssid, int freq, 29ieee80211_rx_bss_get(struct ieee80211_local *local, u8 *bssid, int freq,
32 u8 *ssid, u8 ssid_len) 30 u8 *ssid, u8 ssid_len)
33{ 31{
34 return (void *)cfg80211_get_bss(local->hw.wiphy, 32 struct cfg80211_bss *cbss;
35 ieee80211_get_channel(local->hw.wiphy, 33
36 freq), 34 cbss = cfg80211_get_bss(local->hw.wiphy,
37 bssid, ssid, ssid_len, 35 ieee80211_get_channel(local->hw.wiphy, freq),
38 0, 0); 36 bssid, ssid, ssid_len, 0, 0);
37 if (!cbss)
38 return NULL;
39 return (void *)cbss->priv;
39} 40}
40 41
41static void ieee80211_rx_bss_free(struct cfg80211_bss *cbss) 42static void ieee80211_rx_bss_free(struct cfg80211_bss *cbss)
42{ 43{
43 struct ieee80211_bss *bss = (void *)cbss; 44 struct ieee80211_bss *bss = (void *)cbss->priv;
44 45
45 kfree(bss_mesh_id(bss)); 46 kfree(bss_mesh_id(bss));
46 kfree(bss_mesh_cfg(bss)); 47 kfree(bss_mesh_cfg(bss));
@@ -49,7 +50,26 @@ static void ieee80211_rx_bss_free(struct cfg80211_bss *cbss)
49void ieee80211_rx_bss_put(struct ieee80211_local *local, 50void ieee80211_rx_bss_put(struct ieee80211_local *local,
50 struct ieee80211_bss *bss) 51 struct ieee80211_bss *bss)
51{ 52{
52 cfg80211_put_bss((struct cfg80211_bss *)bss); 53 if (!bss)
54 return;
55 cfg80211_put_bss(container_of((void *)bss, struct cfg80211_bss, priv));
56}
57
58static bool is_uapsd_supported(struct ieee802_11_elems *elems)
59{
60 u8 qos_info;
61
62 if (elems->wmm_info && elems->wmm_info_len == 7
63 && elems->wmm_info[5] == 1)
64 qos_info = elems->wmm_info[6];
65 else if (elems->wmm_param && elems->wmm_param_len == 24
66 && elems->wmm_param[5] == 1)
67 qos_info = elems->wmm_param[6];
68 else
69 /* no valid wmm information or parameter element found */
70 return false;
71
72 return qos_info & IEEE80211_WMM_IE_AP_QOSINFO_UAPSD;
53} 73}
54 74
55struct ieee80211_bss * 75struct ieee80211_bss *
@@ -61,6 +81,7 @@ ieee80211_bss_info_update(struct ieee80211_local *local,
61 struct ieee80211_channel *channel, 81 struct ieee80211_channel *channel,
62 bool beacon) 82 bool beacon)
63{ 83{
84 struct cfg80211_bss *cbss;
64 struct ieee80211_bss *bss; 85 struct ieee80211_bss *bss;
65 int clen; 86 int clen;
66 s32 signal = 0; 87 s32 signal = 0;
@@ -70,13 +91,14 @@ ieee80211_bss_info_update(struct ieee80211_local *local,
70 else if (local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC) 91 else if (local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC)
71 signal = (rx_status->signal * 100) / local->hw.max_signal; 92 signal = (rx_status->signal * 100) / local->hw.max_signal;
72 93
73 bss = (void *)cfg80211_inform_bss_frame(local->hw.wiphy, channel, 94 cbss = cfg80211_inform_bss_frame(local->hw.wiphy, channel,
74 mgmt, len, signal, GFP_ATOMIC); 95 mgmt, len, signal, GFP_ATOMIC);
75 96
76 if (!bss) 97 if (!cbss)
77 return NULL; 98 return NULL;
78 99
79 bss->cbss.free_priv = ieee80211_rx_bss_free; 100 cbss->free_priv = ieee80211_rx_bss_free;
101 bss = (void *)cbss->priv;
80 102
81 /* save the ERP value so that it is available at association time */ 103 /* save the ERP value so that it is available at association time */
82 if (elems->erp_info && elems->erp_info_len >= 1) { 104 if (elems->erp_info && elems->erp_info_len >= 1) {
@@ -90,10 +112,6 @@ ieee80211_bss_info_update(struct ieee80211_local *local,
90 bss->dtim_period = tim_ie->dtim_period; 112 bss->dtim_period = tim_ie->dtim_period;
91 } 113 }
92 114
93 /* set default value for buggy AP/no TIM element */
94 if (bss->dtim_period == 0)
95 bss->dtim_period = 1;
96
97 bss->supp_rates_len = 0; 115 bss->supp_rates_len = 0;
98 if (elems->supp_rates) { 116 if (elems->supp_rates) {
99 clen = IEEE80211_MAX_SUPP_RATES - bss->supp_rates_len; 117 clen = IEEE80211_MAX_SUPP_RATES - bss->supp_rates_len;
@@ -113,6 +131,7 @@ ieee80211_bss_info_update(struct ieee80211_local *local,
113 } 131 }
114 132
115 bss->wmm_used = elems->wmm_param || elems->wmm_info; 133 bss->wmm_used = elems->wmm_param || elems->wmm_info;
134 bss->uapsd_supported = is_uapsd_supported(elems);
116 135
117 if (!beacon) 136 if (!beacon)
118 bss->last_probe_resp = jiffies; 137 bss->last_probe_resp = jiffies;
@@ -149,7 +168,7 @@ ieee80211_scan_rx(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb)
149 presp = ieee80211_is_probe_resp(fc); 168 presp = ieee80211_is_probe_resp(fc);
150 if (presp) { 169 if (presp) {
151 /* ignore ProbeResp to foreign address */ 170 /* ignore ProbeResp to foreign address */
152 if (memcmp(mgmt->da, sdata->dev->dev_addr, ETH_ALEN)) 171 if (memcmp(mgmt->da, sdata->vif.addr, ETH_ALEN))
153 return RX_DROP_MONITOR; 172 return RX_DROP_MONITOR;
154 173
155 presp = true; 174 presp = true;
@@ -189,100 +208,76 @@ ieee80211_scan_rx(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb)
189 return RX_QUEUED; 208 return RX_QUEUED;
190} 209}
191 210
192/* 211/* return false if no more work */
193 * inform AP that we will go to sleep so that it will buffer the frames 212static bool ieee80211_prep_hw_scan(struct ieee80211_local *local)
194 * while we scan
195 */
196static void ieee80211_scan_ps_enable(struct ieee80211_sub_if_data *sdata)
197{ 213{
198 struct ieee80211_local *local = sdata->local; 214 struct cfg80211_scan_request *req = local->scan_req;
199 bool ps = false; 215 enum ieee80211_band band;
216 int i, ielen, n_chans;
200 217
201 /* FIXME: what to do when local->pspolling is true? */ 218 do {
219 if (local->hw_scan_band == IEEE80211_NUM_BANDS)
220 return false;
221
222 band = local->hw_scan_band;
223 n_chans = 0;
224 for (i = 0; i < req->n_channels; i++) {
225 if (req->channels[i]->band == band) {
226 local->hw_scan_req->channels[n_chans] =
227 req->channels[i];
228 n_chans++;
229 }
230 }
202 231
203 del_timer_sync(&local->dynamic_ps_timer); 232 local->hw_scan_band++;
204 cancel_work_sync(&local->dynamic_ps_enable_work); 233 } while (!n_chans);
205 234
206 if (local->hw.conf.flags & IEEE80211_CONF_PS) { 235 local->hw_scan_req->n_channels = n_chans;
207 ps = true;
208 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
209 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
210 }
211 236
212 if (!ps || !(local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)) 237 ielen = ieee80211_build_preq_ies(local, (u8 *)local->hw_scan_req->ie,
213 /* 238 req->ie, req->ie_len, band);
214 * If power save was enabled, no need to send a nullfunc 239 local->hw_scan_req->ie_len = ielen;
215 * frame because AP knows that we are sleeping. But if the
216 * hardware is creating the nullfunc frame for power save
217 * status (ie. IEEE80211_HW_PS_NULLFUNC_STACK is not
218 * enabled) and power save was enabled, the firmware just
219 * sent a null frame with power save disabled. So we need
220 * to send a new nullfunc frame to inform the AP that we
221 * are again sleeping.
222 */
223 ieee80211_send_nullfunc(local, sdata, 1);
224}
225
226/* inform AP that we are awake again, unless power save is enabled */
227static void ieee80211_scan_ps_disable(struct ieee80211_sub_if_data *sdata)
228{
229 struct ieee80211_local *local = sdata->local;
230
231 if (!local->ps_sdata)
232 ieee80211_send_nullfunc(local, sdata, 0);
233 else {
234 /*
235 * In !IEEE80211_HW_PS_NULLFUNC_STACK case the hardware
236 * will send a nullfunc frame with the powersave bit set
237 * even though the AP already knows that we are sleeping.
238 * This could be avoided by sending a null frame with power
239 * save bit disabled before enabling the power save, but
240 * this doesn't gain anything.
241 *
242 * When IEEE80211_HW_PS_NULLFUNC_STACK is enabled, no need
243 * to send a nullfunc frame because AP already knows that
244 * we are sleeping, let's just enable power save mode in
245 * hardware.
246 */
247 local->hw.conf.flags |= IEEE80211_CONF_PS;
248 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
249 }
250}
251 240
252static void ieee80211_restore_scan_ies(struct ieee80211_local *local) 241 return true;
253{
254 kfree(local->scan_req->ie);
255 local->scan_req->ie = local->orig_ies;
256 local->scan_req->ie_len = local->orig_ies_len;
257} 242}
258 243
259void ieee80211_scan_completed(struct ieee80211_hw *hw, bool aborted) 244void ieee80211_scan_completed(struct ieee80211_hw *hw, bool aborted)
260{ 245{
261 struct ieee80211_local *local = hw_to_local(hw); 246 struct ieee80211_local *local = hw_to_local(hw);
262 struct ieee80211_sub_if_data *sdata;
263 bool was_hw_scan; 247 bool was_hw_scan;
264 248
265 mutex_lock(&local->scan_mtx); 249 mutex_lock(&local->scan_mtx);
266 250
267 if (WARN_ON(!local->scanning)) { 251 /*
252 * It's ok to abort a not-yet-running scan (that
253 * we have one at all will be verified by checking
254 * local->scan_req next), but not to complete it
255 * successfully.
256 */
257 if (WARN_ON(!local->scanning && !aborted))
258 aborted = true;
259
260 if (WARN_ON(!local->scan_req)) {
268 mutex_unlock(&local->scan_mtx); 261 mutex_unlock(&local->scan_mtx);
269 return; 262 return;
270 } 263 }
271 264
272 if (WARN_ON(!local->scan_req)) { 265 was_hw_scan = test_bit(SCAN_HW_SCANNING, &local->scanning);
266 if (was_hw_scan && !aborted && ieee80211_prep_hw_scan(local)) {
267 ieee80211_queue_delayed_work(&local->hw,
268 &local->scan_work, 0);
273 mutex_unlock(&local->scan_mtx); 269 mutex_unlock(&local->scan_mtx);
274 return; 270 return;
275 } 271 }
276 272
277 if (test_bit(SCAN_HW_SCANNING, &local->scanning)) 273 kfree(local->hw_scan_req);
278 ieee80211_restore_scan_ies(local); 274 local->hw_scan_req = NULL;
279 275
280 if (local->scan_req != local->int_scan_req) 276 if (local->scan_req != local->int_scan_req)
281 cfg80211_scan_done(local->scan_req, aborted); 277 cfg80211_scan_done(local->scan_req, aborted);
282 local->scan_req = NULL; 278 local->scan_req = NULL;
283 local->scan_sdata = NULL; 279 local->scan_sdata = NULL;
284 280
285 was_hw_scan = test_bit(SCAN_HW_SCANNING, &local->scanning);
286 local->scanning = 0; 281 local->scanning = 0;
287 local->scan_channel = NULL; 282 local->scan_channel = NULL;
288 283
@@ -297,41 +292,19 @@ void ieee80211_scan_completed(struct ieee80211_hw *hw, bool aborted)
297 292
298 drv_sw_scan_complete(local); 293 drv_sw_scan_complete(local);
299 294
300 mutex_lock(&local->iflist_mtx); 295 ieee80211_offchannel_return(local, true);
301 list_for_each_entry(sdata, &local->interfaces, list) {
302 if (!netif_running(sdata->dev))
303 continue;
304
305 /* Tell AP we're back */
306 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
307 if (sdata->u.mgd.associated) {
308 ieee80211_scan_ps_disable(sdata);
309 netif_tx_wake_all_queues(sdata->dev);
310 }
311 } else
312 netif_tx_wake_all_queues(sdata->dev);
313
314 /* re-enable beaconing */
315 if (sdata->vif.type == NL80211_IFTYPE_AP ||
316 sdata->vif.type == NL80211_IFTYPE_ADHOC ||
317 sdata->vif.type == NL80211_IFTYPE_MESH_POINT)
318 ieee80211_bss_info_change_notify(
319 sdata, BSS_CHANGED_BEACON_ENABLED);
320 }
321 mutex_unlock(&local->iflist_mtx);
322 296
323 done: 297 done:
324 ieee80211_recalc_idle(local); 298 ieee80211_recalc_idle(local);
325 ieee80211_mlme_notify_scan_completed(local); 299 ieee80211_mlme_notify_scan_completed(local);
326 ieee80211_ibss_notify_scan_completed(local); 300 ieee80211_ibss_notify_scan_completed(local);
327 ieee80211_mesh_notify_scan_completed(local); 301 ieee80211_mesh_notify_scan_completed(local);
302 ieee80211_queue_work(&local->hw, &local->work_work);
328} 303}
329EXPORT_SYMBOL(ieee80211_scan_completed); 304EXPORT_SYMBOL(ieee80211_scan_completed);
330 305
331static int ieee80211_start_sw_scan(struct ieee80211_local *local) 306static int ieee80211_start_sw_scan(struct ieee80211_local *local)
332{ 307{
333 struct ieee80211_sub_if_data *sdata;
334
335 /* 308 /*
336 * Hardware/driver doesn't support hw_scan, so use software 309 * Hardware/driver doesn't support hw_scan, so use software
337 * scanning instead. First send a nullfunc frame with power save 310 * scanning instead. First send a nullfunc frame with power save
@@ -347,33 +320,15 @@ static int ieee80211_start_sw_scan(struct ieee80211_local *local)
347 */ 320 */
348 drv_sw_scan_start(local); 321 drv_sw_scan_start(local);
349 322
350 mutex_lock(&local->iflist_mtx); 323 ieee80211_offchannel_stop_beaconing(local);
351 list_for_each_entry(sdata, &local->interfaces, list) {
352 if (!netif_running(sdata->dev))
353 continue;
354
355 /* disable beaconing */
356 if (sdata->vif.type == NL80211_IFTYPE_AP ||
357 sdata->vif.type == NL80211_IFTYPE_ADHOC ||
358 sdata->vif.type == NL80211_IFTYPE_MESH_POINT)
359 ieee80211_bss_info_change_notify(
360 sdata, BSS_CHANGED_BEACON_ENABLED);
361
362 /*
363 * only handle non-STA interfaces here, STA interfaces
364 * are handled in the scan state machine
365 */
366 if (sdata->vif.type != NL80211_IFTYPE_STATION)
367 netif_tx_stop_all_queues(sdata->dev);
368 }
369 mutex_unlock(&local->iflist_mtx);
370 324
371 local->next_scan_state = SCAN_DECISION; 325 local->next_scan_state = SCAN_DECISION;
372 local->scan_channel_idx = 0; 326 local->scan_channel_idx = 0;
373 327
328 drv_flush(local, false);
329
374 ieee80211_configure_filter(local); 330 ieee80211_configure_filter(local);
375 331
376 /* TODO: start scan as soon as all nullfunc frames are ACKed */
377 ieee80211_queue_delayed_work(&local->hw, 332 ieee80211_queue_delayed_work(&local->hw,
378 &local->scan_work, 333 &local->scan_work,
379 IEEE80211_CHANNEL_TIME); 334 IEEE80211_CHANNEL_TIME);
@@ -386,68 +341,80 @@ static int __ieee80211_start_scan(struct ieee80211_sub_if_data *sdata,
386 struct cfg80211_scan_request *req) 341 struct cfg80211_scan_request *req)
387{ 342{
388 struct ieee80211_local *local = sdata->local; 343 struct ieee80211_local *local = sdata->local;
389 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
390 int rc; 344 int rc;
391 345
392 if (local->scan_req) 346 if (local->scan_req)
393 return -EBUSY; 347 return -EBUSY;
394 348
349 if (!list_empty(&local->work_list)) {
350 /* wait for the work to finish/time out */
351 local->scan_req = req;
352 local->scan_sdata = sdata;
353 return 0;
354 }
355
395 if (local->ops->hw_scan) { 356 if (local->ops->hw_scan) {
396 u8 *ies; 357 u8 *ies;
397 int ielen;
398 358
399 ies = kmalloc(2 + IEEE80211_MAX_SSID_LEN + 359 local->hw_scan_req = kmalloc(
400 local->scan_ies_len + req->ie_len, GFP_KERNEL); 360 sizeof(*local->hw_scan_req) +
401 if (!ies) 361 req->n_channels * sizeof(req->channels[0]) +
362 2 + IEEE80211_MAX_SSID_LEN + local->scan_ies_len +
363 req->ie_len, GFP_KERNEL);
364 if (!local->hw_scan_req)
402 return -ENOMEM; 365 return -ENOMEM;
403 366
404 ielen = ieee80211_build_preq_ies(local, ies, 367 local->hw_scan_req->ssids = req->ssids;
405 req->ie, req->ie_len); 368 local->hw_scan_req->n_ssids = req->n_ssids;
406 local->orig_ies = req->ie; 369 ies = (u8 *)local->hw_scan_req +
407 local->orig_ies_len = req->ie_len; 370 sizeof(*local->hw_scan_req) +
408 req->ie = ies; 371 req->n_channels * sizeof(req->channels[0]);
409 req->ie_len = ielen; 372 local->hw_scan_req->ie = ies;
373
374 local->hw_scan_band = 0;
375
376 /*
377 * After allocating local->hw_scan_req, we must
378 * go through until ieee80211_prep_hw_scan(), so
379 * anything that might be changed here and leave
380 * this function early must not go after this
381 * allocation.
382 */
410 } 383 }
411 384
412 local->scan_req = req; 385 local->scan_req = req;
413 local->scan_sdata = sdata; 386 local->scan_sdata = sdata;
414 387
415 if (req != local->int_scan_req &&
416 sdata->vif.type == NL80211_IFTYPE_STATION &&
417 !list_empty(&ifmgd->work_list)) {
418 /* actually wait for the work it's doing to finish/time out */
419 set_bit(IEEE80211_STA_REQ_SCAN, &ifmgd->request);
420 return 0;
421 }
422
423 if (local->ops->hw_scan) 388 if (local->ops->hw_scan)
424 __set_bit(SCAN_HW_SCANNING, &local->scanning); 389 __set_bit(SCAN_HW_SCANNING, &local->scanning);
425 else 390 else
426 __set_bit(SCAN_SW_SCANNING, &local->scanning); 391 __set_bit(SCAN_SW_SCANNING, &local->scanning);
392
427 /* 393 /*
428 * Kicking off the scan need not be protected, 394 * Kicking off the scan need not be protected,
429 * only the scan variable stuff, since now 395 * only the scan variable stuff, since now
430 * local->scan_req is assigned and other callers 396 * local->scan_req is assigned and other callers
431 * will abort their scan attempts. 397 * will abort their scan attempts.
432 * 398 *
433 * This avoids getting a scan_mtx -> iflist_mtx 399 * This avoids too many locking dependencies
434 * dependency, so that the scan completed calls 400 * so that the scan completed calls have more
435 * have more locking freedom. 401 * locking freedom.
436 */ 402 */
437 403
438 ieee80211_recalc_idle(local); 404 ieee80211_recalc_idle(local);
439 mutex_unlock(&local->scan_mtx); 405 mutex_unlock(&local->scan_mtx);
440 406
441 if (local->ops->hw_scan) 407 if (local->ops->hw_scan) {
442 rc = drv_hw_scan(local, local->scan_req); 408 WARN_ON(!ieee80211_prep_hw_scan(local));
443 else 409 rc = drv_hw_scan(local, local->hw_scan_req);
410 } else
444 rc = ieee80211_start_sw_scan(local); 411 rc = ieee80211_start_sw_scan(local);
445 412
446 mutex_lock(&local->scan_mtx); 413 mutex_lock(&local->scan_mtx);
447 414
448 if (rc) { 415 if (rc) {
449 if (local->ops->hw_scan) 416 kfree(local->hw_scan_req);
450 ieee80211_restore_scan_ies(local); 417 local->hw_scan_req = NULL;
451 local->scanning = 0; 418 local->scanning = 0;
452 419
453 ieee80211_recalc_idle(local); 420 ieee80211_recalc_idle(local);
@@ -474,7 +441,7 @@ static int ieee80211_scan_state_decision(struct ieee80211_local *local,
474 /* check if at least one STA interface is associated */ 441 /* check if at least one STA interface is associated */
475 mutex_lock(&local->iflist_mtx); 442 mutex_lock(&local->iflist_mtx);
476 list_for_each_entry(sdata, &local->interfaces, list) { 443 list_for_each_entry(sdata, &local->interfaces, list) {
477 if (!netif_running(sdata->dev)) 444 if (!ieee80211_sdata_running(sdata))
478 continue; 445 continue;
479 446
480 if (sdata->vif.type == NL80211_IFTYPE_STATION) { 447 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
@@ -512,56 +479,35 @@ static int ieee80211_scan_state_decision(struct ieee80211_local *local,
512static void ieee80211_scan_state_leave_oper_channel(struct ieee80211_local *local, 479static void ieee80211_scan_state_leave_oper_channel(struct ieee80211_local *local,
513 unsigned long *next_delay) 480 unsigned long *next_delay)
514{ 481{
515 struct ieee80211_sub_if_data *sdata; 482 ieee80211_offchannel_stop_station(local);
483
484 __set_bit(SCAN_OFF_CHANNEL, &local->scanning);
516 485
517 /* 486 /*
518 * notify the AP about us leaving the channel and stop all STA interfaces 487 * What if the nullfunc frames didn't arrive?
519 */ 488 */
520 mutex_lock(&local->iflist_mtx); 489 drv_flush(local, false);
521 list_for_each_entry(sdata, &local->interfaces, list) { 490 if (local->ops->flush)
522 if (!netif_running(sdata->dev)) 491 *next_delay = 0;
523 continue; 492 else
524 493 *next_delay = HZ / 10;
525 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
526 netif_tx_stop_all_queues(sdata->dev);
527 if (sdata->u.mgd.associated)
528 ieee80211_scan_ps_enable(sdata);
529 }
530 }
531 mutex_unlock(&local->iflist_mtx);
532
533 __set_bit(SCAN_OFF_CHANNEL, &local->scanning);
534 494
535 /* advance to the next channel to be scanned */ 495 /* advance to the next channel to be scanned */
536 *next_delay = HZ / 10;
537 local->next_scan_state = SCAN_SET_CHANNEL; 496 local->next_scan_state = SCAN_SET_CHANNEL;
538} 497}
539 498
540static void ieee80211_scan_state_enter_oper_channel(struct ieee80211_local *local, 499static void ieee80211_scan_state_enter_oper_channel(struct ieee80211_local *local,
541 unsigned long *next_delay) 500 unsigned long *next_delay)
542{ 501{
543 struct ieee80211_sub_if_data *sdata = local->scan_sdata;
544
545 /* switch back to the operating channel */ 502 /* switch back to the operating channel */
546 local->scan_channel = NULL; 503 local->scan_channel = NULL;
547 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL); 504 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL);
548 505
549 /* 506 /*
550 * notify the AP about us being back and restart all STA interfaces 507 * Only re-enable station mode interface now; beaconing will be
508 * re-enabled once the full scan has been completed.
551 */ 509 */
552 mutex_lock(&local->iflist_mtx); 510 ieee80211_offchannel_return(local, false);
553 list_for_each_entry(sdata, &local->interfaces, list) {
554 if (!netif_running(sdata->dev))
555 continue;
556
557 /* Tell AP we're back */
558 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
559 if (sdata->u.mgd.associated)
560 ieee80211_scan_ps_disable(sdata);
561 netif_tx_wake_all_queues(sdata->dev);
562 }
563 }
564 mutex_unlock(&local->iflist_mtx);
565 511
566 __clear_bit(SCAN_OFF_CHANNEL, &local->scanning); 512 __clear_bit(SCAN_OFF_CHANNEL, &local->scanning);
567 513
@@ -574,23 +520,14 @@ static void ieee80211_scan_state_set_channel(struct ieee80211_local *local,
574{ 520{
575 int skip; 521 int skip;
576 struct ieee80211_channel *chan; 522 struct ieee80211_channel *chan;
577 struct ieee80211_sub_if_data *sdata = local->scan_sdata;
578 523
579 skip = 0; 524 skip = 0;
580 chan = local->scan_req->channels[local->scan_channel_idx]; 525 chan = local->scan_req->channels[local->scan_channel_idx];
581 526
582 if (chan->flags & IEEE80211_CHAN_DISABLED || 527 local->scan_channel = chan;
583 (sdata->vif.type == NL80211_IFTYPE_ADHOC && 528 if (ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL))
584 chan->flags & IEEE80211_CHAN_NO_IBSS))
585 skip = 1; 529 skip = 1;
586 530
587 if (!skip) {
588 local->scan_channel = chan;
589 if (ieee80211_hw_config(local,
590 IEEE80211_CONF_CHANGE_CHANNEL))
591 skip = 1;
592 }
593
594 /* advance state machine to next channel/band */ 531 /* advance state machine to next channel/band */
595 local->scan_channel_idx++; 532 local->scan_channel_idx++;
596 533
@@ -656,6 +593,14 @@ void ieee80211_scan_work(struct work_struct *work)
656 return; 593 return;
657 } 594 }
658 595
596 if (local->hw_scan_req) {
597 int rc = drv_hw_scan(local, local->hw_scan_req);
598 mutex_unlock(&local->scan_mtx);
599 if (rc)
600 ieee80211_scan_completed(&local->hw, true);
601 return;
602 }
603
659 if (local->scan_req && !local->scanning) { 604 if (local->scan_req && !local->scanning) {
660 struct cfg80211_scan_request *req = local->scan_req; 605 struct cfg80211_scan_request *req = local->scan_req;
661 int rc; 606 int rc;
@@ -676,7 +621,7 @@ void ieee80211_scan_work(struct work_struct *work)
676 /* 621 /*
677 * Avoid re-scheduling when the sdata is going away. 622 * Avoid re-scheduling when the sdata is going away.
678 */ 623 */
679 if (!netif_running(sdata->dev)) { 624 if (!ieee80211_sdata_running(sdata)) {
680 ieee80211_scan_completed(&local->hw, true); 625 ieee80211_scan_completed(&local->hw, true);
681 return; 626 return;
682 } 627 }
diff --git a/net/mac80211/spectmgmt.c b/net/mac80211/spectmgmt.c
index 68953033403d..7733f66ee2c4 100644
--- a/net/mac80211/spectmgmt.c
+++ b/net/mac80211/spectmgmt.c
@@ -35,7 +35,7 @@ static void ieee80211_send_refuse_measurement_request(struct ieee80211_sub_if_da
35 35
36 if (!skb) { 36 if (!skb) {
37 printk(KERN_ERR "%s: failed to allocate buffer for " 37 printk(KERN_ERR "%s: failed to allocate buffer for "
38 "measurement report frame\n", sdata->dev->name); 38 "measurement report frame\n", sdata->name);
39 return; 39 return;
40 } 40 }
41 41
@@ -43,7 +43,7 @@ static void ieee80211_send_refuse_measurement_request(struct ieee80211_sub_if_da
43 msr_report = (struct ieee80211_mgmt *)skb_put(skb, 24); 43 msr_report = (struct ieee80211_mgmt *)skb_put(skb, 24);
44 memset(msr_report, 0, 24); 44 memset(msr_report, 0, 24);
45 memcpy(msr_report->da, da, ETH_ALEN); 45 memcpy(msr_report->da, da, ETH_ALEN);
46 memcpy(msr_report->sa, sdata->dev->dev_addr, ETH_ALEN); 46 memcpy(msr_report->sa, sdata->vif.addr, ETH_ALEN);
47 memcpy(msr_report->bssid, bssid, ETH_ALEN); 47 memcpy(msr_report->bssid, bssid, ETH_ALEN);
48 msr_report->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | 48 msr_report->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
49 IEEE80211_STYPE_ACTION); 49 IEEE80211_STYPE_ACTION);
@@ -65,7 +65,7 @@ static void ieee80211_send_refuse_measurement_request(struct ieee80211_sub_if_da
65 IEEE80211_SPCT_MSR_RPRT_MODE_REFUSED; 65 IEEE80211_SPCT_MSR_RPRT_MODE_REFUSED;
66 msr_report->u.action.u.measurement.msr_elem.type = request_ie->type; 66 msr_report->u.action.u.measurement.msr_elem.type = request_ie->type;
67 67
68 ieee80211_tx_skb(sdata, skb, 1); 68 ieee80211_tx_skb(sdata, skb);
69} 69}
70 70
71void ieee80211_process_measurement_req(struct ieee80211_sub_if_data *sdata, 71void ieee80211_process_measurement_req(struct ieee80211_sub_if_data *sdata,
diff --git a/net/mac80211/sta_info.c b/net/mac80211/sta_info.c
index 594f2318c3d8..fb12cec4d333 100644
--- a/net/mac80211/sta_info.c
+++ b/net/mac80211/sta_info.c
@@ -32,49 +32,33 @@
32 * for faster lookup and a list for iteration. They are managed using 32 * for faster lookup and a list for iteration. They are managed using
33 * RCU, i.e. access to the list and hash table is protected by RCU. 33 * RCU, i.e. access to the list and hash table is protected by RCU.
34 * 34 *
35 * Upon allocating a STA info structure with sta_info_alloc(), the caller owns 35 * Upon allocating a STA info structure with sta_info_alloc(), the caller
36 * that structure. It must then either destroy it using sta_info_destroy() 36 * owns that structure. It must then insert it into the hash table using
37 * (which is pretty useless) or insert it into the hash table using 37 * either sta_info_insert() or sta_info_insert_rcu(); only in the latter
38 * sta_info_insert() which demotes the reference from ownership to a regular 38 * case (which acquires an rcu read section but must not be called from
39 * RCU-protected reference; if the function is called without protection by an 39 * within one) will the pointer still be valid after the call. Note that
40 * RCU critical section the reference is instantly invalidated. Note that the 40 * the caller may not do much with the STA info before inserting it, in
41 * caller may not do much with the STA info before inserting it, in particular, 41 * particular, it may not start any mesh peer link management or add
42 * it may not start any mesh peer link management or add encryption keys. 42 * encryption keys.
43 * 43 *
44 * When the insertion fails (sta_info_insert()) returns non-zero), the 44 * When the insertion fails (sta_info_insert()) returns non-zero), the
45 * structure will have been freed by sta_info_insert()! 45 * structure will have been freed by sta_info_insert()!
46 * 46 *
47 * sta entries are added by mac80211 when you establish a link with a 47 * Station entries are added by mac80211 when you establish a link with a
48 * peer. This means different things for the different type of interfaces 48 * peer. This means different things for the different type of interfaces
49 * we support. For a regular station this mean we add the AP sta when we 49 * we support. For a regular station this mean we add the AP sta when we
50 * receive an assocation response from the AP. For IBSS this occurs when 50 * receive an assocation response from the AP. For IBSS this occurs when
51 * we receive a probe response or a beacon from target IBSS network. For 51 * get to know about a peer on the same IBSS. For WDS we add the sta for
52 * WDS we add the sta for the peer imediately upon device open. When using 52 * the peer imediately upon device open. When using AP mode we add stations
53 * AP mode we add stations for each respective station upon request from 53 * for each respective station upon request from userspace through nl80211.
54 * userspace through nl80211.
55 * 54 *
56 * Because there are debugfs entries for each station, and adding those 55 * In order to remove a STA info structure, various sta_info_destroy_*()
57 * must be able to sleep, it is also possible to "pin" a station entry, 56 * calls are available.
58 * that means it can be removed from the hash table but not be freed.
59 * See the comment in __sta_info_unlink() for more information, this is
60 * an internal capability only.
61 * 57 *
62 * In order to remove a STA info structure, the caller needs to first 58 * There is no concept of ownership on a STA entry, each structure is
63 * unlink it (sta_info_unlink()) from the list and hash tables and 59 * owned by the global hash table/list until it is removed. All users of
64 * then destroy it; sta_info_destroy() will wait for an RCU grace period 60 * the structure need to be RCU protected so that the structure won't be
65 * to elapse before actually freeing it. Due to the pinning and the 61 * freed before they are done using it.
66 * possibility of multiple callers trying to remove the same STA info at
67 * the same time, sta_info_unlink() can clear the STA info pointer it is
68 * passed to indicate that the STA info is owned by somebody else now.
69 *
70 * If sta_info_unlink() did not clear the pointer then the caller owns
71 * the STA info structure now and is responsible of destroying it with
72 * a call to sta_info_destroy().
73 *
74 * In all other cases, there is no concept of ownership on a STA entry,
75 * each structure is owned by the global hash table/list until it is
76 * removed. All users of the structure need to be RCU protected so that
77 * the structure won't be freed before they are done using it.
78 */ 62 */
79 63
80/* Caller must hold local->sta_lock */ 64/* Caller must hold local->sta_lock */
@@ -103,27 +87,64 @@ static int sta_info_hash_del(struct ieee80211_local *local,
103} 87}
104 88
105/* protected by RCU */ 89/* protected by RCU */
106struct sta_info *sta_info_get(struct ieee80211_local *local, const u8 *addr) 90struct sta_info *sta_info_get(struct ieee80211_sub_if_data *sdata,
91 const u8 *addr)
107{ 92{
93 struct ieee80211_local *local = sdata->local;
94 struct sta_info *sta;
95
96 sta = rcu_dereference_check(local->sta_hash[STA_HASH(addr)],
97 rcu_read_lock_held() ||
98 lockdep_is_held(&local->sta_lock) ||
99 lockdep_is_held(&local->sta_mtx));
100 while (sta) {
101 if (sta->sdata == sdata &&
102 memcmp(sta->sta.addr, addr, ETH_ALEN) == 0)
103 break;
104 sta = rcu_dereference_check(sta->hnext,
105 rcu_read_lock_held() ||
106 lockdep_is_held(&local->sta_lock) ||
107 lockdep_is_held(&local->sta_mtx));
108 }
109 return sta;
110}
111
112/*
113 * Get sta info either from the specified interface
114 * or from one of its vlans
115 */
116struct sta_info *sta_info_get_bss(struct ieee80211_sub_if_data *sdata,
117 const u8 *addr)
118{
119 struct ieee80211_local *local = sdata->local;
108 struct sta_info *sta; 120 struct sta_info *sta;
109 121
110 sta = rcu_dereference(local->sta_hash[STA_HASH(addr)]); 122 sta = rcu_dereference_check(local->sta_hash[STA_HASH(addr)],
123 rcu_read_lock_held() ||
124 lockdep_is_held(&local->sta_lock) ||
125 lockdep_is_held(&local->sta_mtx));
111 while (sta) { 126 while (sta) {
112 if (memcmp(sta->sta.addr, addr, ETH_ALEN) == 0) 127 if ((sta->sdata == sdata ||
128 sta->sdata->bss == sdata->bss) &&
129 memcmp(sta->sta.addr, addr, ETH_ALEN) == 0)
113 break; 130 break;
114 sta = rcu_dereference(sta->hnext); 131 sta = rcu_dereference_check(sta->hnext,
132 rcu_read_lock_held() ||
133 lockdep_is_held(&local->sta_lock) ||
134 lockdep_is_held(&local->sta_mtx));
115 } 135 }
116 return sta; 136 return sta;
117} 137}
118 138
119struct sta_info *sta_info_get_by_idx(struct ieee80211_local *local, int idx, 139struct sta_info *sta_info_get_by_idx(struct ieee80211_sub_if_data *sdata,
120 struct net_device *dev) 140 int idx)
121{ 141{
142 struct ieee80211_local *local = sdata->local;
122 struct sta_info *sta; 143 struct sta_info *sta;
123 int i = 0; 144 int i = 0;
124 145
125 list_for_each_entry_rcu(sta, &local->sta_list, list) { 146 list_for_each_entry_rcu(sta, &local->sta_list, list) {
126 if (dev && dev != sta->sdata->dev) 147 if (sdata != sta->sdata)
127 continue; 148 continue;
128 if (i < idx) { 149 if (i < idx) {
129 ++i; 150 ++i;
@@ -147,8 +168,10 @@ struct sta_info *sta_info_get_by_idx(struct ieee80211_local *local, int idx,
147static void __sta_info_free(struct ieee80211_local *local, 168static void __sta_info_free(struct ieee80211_local *local,
148 struct sta_info *sta) 169 struct sta_info *sta)
149{ 170{
150 rate_control_free_sta(sta); 171 if (sta->rate_ctrl) {
151 rate_control_put(sta->rate_ctrl); 172 rate_control_free_sta(sta);
173 rate_control_put(sta->rate_ctrl);
174 }
152 175
153#ifdef CONFIG_MAC80211_VERBOSE_DEBUG 176#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
154 printk(KERN_DEBUG "%s: Destroyed STA %pM\n", 177 printk(KERN_DEBUG "%s: Destroyed STA %pM\n",
@@ -158,105 +181,44 @@ static void __sta_info_free(struct ieee80211_local *local,
158 kfree(sta); 181 kfree(sta);
159} 182}
160 183
161void sta_info_destroy(struct sta_info *sta) 184/* Caller must hold local->sta_lock */
185static void sta_info_hash_add(struct ieee80211_local *local,
186 struct sta_info *sta)
162{ 187{
163 struct ieee80211_local *local; 188 sta->hnext = local->sta_hash[STA_HASH(sta->sta.addr)];
164 struct sk_buff *skb; 189 rcu_assign_pointer(local->sta_hash[STA_HASH(sta->sta.addr)], sta);
165 int i; 190}
166
167 might_sleep();
168
169 if (!sta)
170 return;
171
172 local = sta->local;
173
174 rate_control_remove_sta_debugfs(sta);
175 ieee80211_sta_debugfs_remove(sta);
176
177#ifdef CONFIG_MAC80211_MESH
178 if (ieee80211_vif_is_mesh(&sta->sdata->vif))
179 mesh_plink_deactivate(sta);
180#endif
181
182 /*
183 * We have only unlinked the key, and actually destroying it
184 * may mean it is removed from hardware which requires that
185 * the key->sta pointer is still valid, so flush the key todo
186 * list here.
187 *
188 * ieee80211_key_todo() will synchronize_rcu() so after this
189 * nothing can reference this sta struct any more.
190 */
191 ieee80211_key_todo();
192
193#ifdef CONFIG_MAC80211_MESH
194 if (ieee80211_vif_is_mesh(&sta->sdata->vif))
195 del_timer_sync(&sta->plink_timer);
196#endif
197
198 while ((skb = skb_dequeue(&sta->ps_tx_buf)) != NULL) {
199 local->total_ps_buffered--;
200 dev_kfree_skb_any(skb);
201 }
202 191
203 while ((skb = skb_dequeue(&sta->tx_filtered)) != NULL) 192static void sta_unblock(struct work_struct *wk)
204 dev_kfree_skb_any(skb); 193{
194 struct sta_info *sta;
205 195
206 for (i = 0; i < STA_TID_NUM; i++) { 196 sta = container_of(wk, struct sta_info, drv_unblock_wk);
207 struct tid_ampdu_rx *tid_rx;
208 struct tid_ampdu_tx *tid_tx;
209 197
210 spin_lock_bh(&sta->lock); 198 if (sta->dead)
211 tid_rx = sta->ampdu_mlme.tid_rx[i]; 199 return;
212 /* Make sure timer won't free the tid_rx struct, see below */
213 if (tid_rx)
214 tid_rx->shutdown = true;
215 200
216 spin_unlock_bh(&sta->lock); 201 if (!test_sta_flags(sta, WLAN_STA_PS_STA))
202 ieee80211_sta_ps_deliver_wakeup(sta);
203 else if (test_and_clear_sta_flags(sta, WLAN_STA_PSPOLL))
204 ieee80211_sta_ps_deliver_poll_response(sta);
205}
217 206
218 /* 207static int sta_prepare_rate_control(struct ieee80211_local *local,
219 * Outside spinlock - shutdown is true now so that the timer 208 struct sta_info *sta, gfp_t gfp)
220 * won't free tid_rx, we have to do that now. Can't let the 209{
221 * timer do it because we have to sync the timer outside the 210 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL)
222 * lock that it takes itself. 211 return 0;
223 */
224 if (tid_rx) {
225 del_timer_sync(&tid_rx->session_timer);
226 kfree(tid_rx);
227 }
228 212
229 /* 213 sta->rate_ctrl = rate_control_get(local->rate_ctrl);
230 * No need to do such complications for TX agg sessions, the 214 sta->rate_ctrl_priv = rate_control_alloc_sta(sta->rate_ctrl,
231 * path leading to freeing the tid_tx struct goes via a call 215 &sta->sta, gfp);
232 * from the driver, and thus needs to look up the sta struct 216 if (!sta->rate_ctrl_priv) {
233 * again, which cannot be found when we get here. Hence, we 217 rate_control_put(sta->rate_ctrl);
234 * just need to delete the timer and free the aggregation 218 return -ENOMEM;
235 * info; we won't be telling the peer about it then but that
236 * doesn't matter if we're not talking to it again anyway.
237 */
238 tid_tx = sta->ampdu_mlme.tid_tx[i];
239 if (tid_tx) {
240 del_timer_sync(&tid_tx->addba_resp_timer);
241 /*
242 * STA removed while aggregation session being
243 * started? Bit odd, but purge frames anyway.
244 */
245 skb_queue_purge(&tid_tx->pending);
246 kfree(tid_tx);
247 }
248 } 219 }
249 220
250 __sta_info_free(local, sta); 221 return 0;
251}
252
253
254/* Caller must hold local->sta_lock */
255static void sta_info_hash_add(struct ieee80211_local *local,
256 struct sta_info *sta)
257{
258 sta->hnext = local->sta_hash[STA_HASH(sta->sta.addr)];
259 rcu_assign_pointer(local->sta_hash[STA_HASH(sta->sta.addr)], sta);
260} 222}
261 223
262struct sta_info *sta_info_alloc(struct ieee80211_sub_if_data *sdata, 224struct sta_info *sta_info_alloc(struct ieee80211_sub_if_data *sdata,
@@ -272,16 +234,13 @@ struct sta_info *sta_info_alloc(struct ieee80211_sub_if_data *sdata,
272 234
273 spin_lock_init(&sta->lock); 235 spin_lock_init(&sta->lock);
274 spin_lock_init(&sta->flaglock); 236 spin_lock_init(&sta->flaglock);
237 INIT_WORK(&sta->drv_unblock_wk, sta_unblock);
275 238
276 memcpy(sta->sta.addr, addr, ETH_ALEN); 239 memcpy(sta->sta.addr, addr, ETH_ALEN);
277 sta->local = local; 240 sta->local = local;
278 sta->sdata = sdata; 241 sta->sdata = sdata;
279 242
280 sta->rate_ctrl = rate_control_get(local->rate_ctrl); 243 if (sta_prepare_rate_control(local, sta, gfp)) {
281 sta->rate_ctrl_priv = rate_control_alloc_sta(sta->rate_ctrl,
282 &sta->sta, gfp);
283 if (!sta->rate_ctrl_priv) {
284 rate_control_put(sta->rate_ctrl);
285 kfree(sta); 244 kfree(sta);
286 return NULL; 245 return NULL;
287 } 246 }
@@ -318,7 +277,93 @@ struct sta_info *sta_info_alloc(struct ieee80211_sub_if_data *sdata,
318 return sta; 277 return sta;
319} 278}
320 279
321int sta_info_insert(struct sta_info *sta) 280static int sta_info_finish_insert(struct sta_info *sta, bool async)
281{
282 struct ieee80211_local *local = sta->local;
283 struct ieee80211_sub_if_data *sdata = sta->sdata;
284 struct station_info sinfo;
285 unsigned long flags;
286 int err = 0;
287
288 WARN_ON(!mutex_is_locked(&local->sta_mtx));
289
290 /* notify driver */
291 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
292 sdata = container_of(sdata->bss,
293 struct ieee80211_sub_if_data,
294 u.ap);
295 err = drv_sta_add(local, sdata, &sta->sta);
296 if (err) {
297 if (!async)
298 return err;
299 printk(KERN_DEBUG "%s: failed to add IBSS STA %pM to driver (%d)"
300 " - keeping it anyway.\n",
301 sdata->name, sta->sta.addr, err);
302 } else {
303 sta->uploaded = true;
304#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
305 if (async)
306 printk(KERN_DEBUG "%s: Finished adding IBSS STA %pM\n",
307 wiphy_name(local->hw.wiphy), sta->sta.addr);
308#endif
309 }
310
311 sdata = sta->sdata;
312
313 if (!async) {
314 local->num_sta++;
315 local->sta_generation++;
316 smp_mb();
317
318 /* make the station visible */
319 spin_lock_irqsave(&local->sta_lock, flags);
320 sta_info_hash_add(local, sta);
321 spin_unlock_irqrestore(&local->sta_lock, flags);
322 }
323
324 list_add(&sta->list, &local->sta_list);
325
326 ieee80211_sta_debugfs_add(sta);
327 rate_control_add_sta_debugfs(sta);
328
329 sinfo.filled = 0;
330 sinfo.generation = local->sta_generation;
331 cfg80211_new_sta(sdata->dev, sta->sta.addr, &sinfo, GFP_KERNEL);
332
333
334 return 0;
335}
336
337static void sta_info_finish_pending(struct ieee80211_local *local)
338{
339 struct sta_info *sta;
340 unsigned long flags;
341
342 spin_lock_irqsave(&local->sta_lock, flags);
343 while (!list_empty(&local->sta_pending_list)) {
344 sta = list_first_entry(&local->sta_pending_list,
345 struct sta_info, list);
346 list_del(&sta->list);
347 spin_unlock_irqrestore(&local->sta_lock, flags);
348
349 sta_info_finish_insert(sta, true);
350
351 spin_lock_irqsave(&local->sta_lock, flags);
352 }
353 spin_unlock_irqrestore(&local->sta_lock, flags);
354}
355
356static void sta_info_finish_work(struct work_struct *work)
357{
358 struct ieee80211_local *local =
359 container_of(work, struct ieee80211_local, sta_finish_work);
360
361 mutex_lock(&local->sta_mtx);
362 sta_info_finish_pending(local);
363 mutex_unlock(&local->sta_mtx);
364}
365
366int sta_info_insert_rcu(struct sta_info *sta) __acquires(RCU)
322{ 367{
323 struct ieee80211_local *local = sta->local; 368 struct ieee80211_local *local = sta->local;
324 struct ieee80211_sub_if_data *sdata = sta->sdata; 369 struct ieee80211_sub_if_data *sdata = sta->sdata;
@@ -330,38 +375,90 @@ int sta_info_insert(struct sta_info *sta)
330 * something inserts a STA (on one CPU) without holding the RTNL 375 * something inserts a STA (on one CPU) without holding the RTNL
331 * and another CPU turns off the net device. 376 * and another CPU turns off the net device.
332 */ 377 */
333 if (unlikely(!netif_running(sdata->dev))) { 378 if (unlikely(!ieee80211_sdata_running(sdata))) {
334 err = -ENETDOWN; 379 err = -ENETDOWN;
380 rcu_read_lock();
335 goto out_free; 381 goto out_free;
336 } 382 }
337 383
338 if (WARN_ON(compare_ether_addr(sta->sta.addr, sdata->dev->dev_addr) == 0 || 384 if (WARN_ON(compare_ether_addr(sta->sta.addr, sdata->vif.addr) == 0 ||
339 is_multicast_ether_addr(sta->sta.addr))) { 385 is_multicast_ether_addr(sta->sta.addr))) {
340 err = -EINVAL; 386 err = -EINVAL;
387 rcu_read_lock();
341 goto out_free; 388 goto out_free;
342 } 389 }
343 390
391 /*
392 * In ad-hoc mode, we sometimes need to insert stations
393 * from tasklet context from the RX path. To avoid races,
394 * always do so in that case -- see the comment below.
395 */
396 if (sdata->vif.type == NL80211_IFTYPE_ADHOC) {
397 spin_lock_irqsave(&local->sta_lock, flags);
398 /* check if STA exists already */
399 if (sta_info_get_bss(sdata, sta->sta.addr)) {
400 spin_unlock_irqrestore(&local->sta_lock, flags);
401 rcu_read_lock();
402 err = -EEXIST;
403 goto out_free;
404 }
405
406 local->num_sta++;
407 local->sta_generation++;
408 smp_mb();
409 sta_info_hash_add(local, sta);
410
411 list_add_tail(&sta->list, &local->sta_pending_list);
412
413 rcu_read_lock();
414 spin_unlock_irqrestore(&local->sta_lock, flags);
415
416#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
417 printk(KERN_DEBUG "%s: Added IBSS STA %pM\n",
418 wiphy_name(local->hw.wiphy), sta->sta.addr);
419#endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
420
421 ieee80211_queue_work(&local->hw, &local->sta_finish_work);
422
423 return 0;
424 }
425
426 /*
427 * On first glance, this will look racy, because the code
428 * below this point, which inserts a station with sleeping,
429 * unlocks the sta_lock between checking existence in the
430 * hash table and inserting into it.
431 *
432 * However, it is not racy against itself because it keeps
433 * the mutex locked. It still seems to race against the
434 * above code that atomically inserts the station... That,
435 * however, is not true because the above code can only
436 * be invoked for IBSS interfaces, and the below code will
437 * not be -- and the two do not race against each other as
438 * the hash table also keys off the interface.
439 */
440
441 might_sleep();
442
443 mutex_lock(&local->sta_mtx);
444
344 spin_lock_irqsave(&local->sta_lock, flags); 445 spin_lock_irqsave(&local->sta_lock, flags);
345 /* check if STA exists already */ 446 /* check if STA exists already */
346 if (sta_info_get(local, sta->sta.addr)) { 447 if (sta_info_get_bss(sdata, sta->sta.addr)) {
347 spin_unlock_irqrestore(&local->sta_lock, flags); 448 spin_unlock_irqrestore(&local->sta_lock, flags);
449 mutex_unlock(&local->sta_mtx);
450 rcu_read_lock();
348 err = -EEXIST; 451 err = -EEXIST;
349 goto out_free; 452 goto out_free;
350 } 453 }
351 list_add(&sta->list, &local->sta_list);
352 local->sta_generation++;
353 local->num_sta++;
354 sta_info_hash_add(local, sta);
355 454
356 /* notify driver */ 455 spin_unlock_irqrestore(&local->sta_lock, flags);
357 if (local->ops->sta_notify) {
358 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
359 sdata = container_of(sdata->bss,
360 struct ieee80211_sub_if_data,
361 u.ap);
362 456
363 drv_sta_notify(local, &sdata->vif, STA_NOTIFY_ADD, &sta->sta); 457 err = sta_info_finish_insert(sta, false);
364 sdata = sta->sdata; 458 if (err) {
459 mutex_unlock(&local->sta_mtx);
460 rcu_read_lock();
461 goto out_free;
365 } 462 }
366 463
367#ifdef CONFIG_MAC80211_VERBOSE_DEBUG 464#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
@@ -369,18 +466,9 @@ int sta_info_insert(struct sta_info *sta)
369 wiphy_name(local->hw.wiphy), sta->sta.addr); 466 wiphy_name(local->hw.wiphy), sta->sta.addr);
370#endif /* CONFIG_MAC80211_VERBOSE_DEBUG */ 467#endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
371 468
372 spin_unlock_irqrestore(&local->sta_lock, flags); 469 /* move reference to rcu-protected */
373 470 rcu_read_lock();
374#ifdef CONFIG_MAC80211_DEBUGFS 471 mutex_unlock(&local->sta_mtx);
375 /*
376 * Debugfs entry adding might sleep, so schedule process
377 * context task for adding entry for STAs that do not yet
378 * have one.
379 * NOTE: due to auto-freeing semantics this may only be done
380 * if the insertion is successful!
381 */
382 schedule_work(&local->sta_debugfs_add);
383#endif
384 472
385 if (ieee80211_vif_is_mesh(&sdata->vif)) 473 if (ieee80211_vif_is_mesh(&sdata->vif))
386 mesh_accept_plinks_update(sdata); 474 mesh_accept_plinks_update(sdata);
@@ -392,6 +480,15 @@ int sta_info_insert(struct sta_info *sta)
392 return err; 480 return err;
393} 481}
394 482
483int sta_info_insert(struct sta_info *sta)
484{
485 int err = sta_info_insert_rcu(sta);
486
487 rcu_read_unlock();
488
489 return err;
490}
491
395static inline void __bss_tim_set(struct ieee80211_if_ap *bss, u16 aid) 492static inline void __bss_tim_set(struct ieee80211_if_ap *bss, u16 aid)
396{ 493{
397 /* 494 /*
@@ -460,103 +557,6 @@ void sta_info_clear_tim_bit(struct sta_info *sta)
460 spin_unlock_irqrestore(&sta->local->sta_lock, flags); 557 spin_unlock_irqrestore(&sta->local->sta_lock, flags);
461} 558}
462 559
463static void __sta_info_unlink(struct sta_info **sta)
464{
465 struct ieee80211_local *local = (*sta)->local;
466 struct ieee80211_sub_if_data *sdata = (*sta)->sdata;
467 /*
468 * pull caller's reference if we're already gone.
469 */
470 if (sta_info_hash_del(local, *sta)) {
471 *sta = NULL;
472 return;
473 }
474
475 if ((*sta)->key) {
476 ieee80211_key_free((*sta)->key);
477 WARN_ON((*sta)->key);
478 }
479
480 list_del(&(*sta)->list);
481
482 if (test_and_clear_sta_flags(*sta, WLAN_STA_PS)) {
483 BUG_ON(!sdata->bss);
484
485 atomic_dec(&sdata->bss->num_sta_ps);
486 __sta_info_clear_tim_bit(sdata->bss, *sta);
487 }
488
489 local->num_sta--;
490 local->sta_generation++;
491
492 if (local->ops->sta_notify) {
493 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
494 sdata = container_of(sdata->bss,
495 struct ieee80211_sub_if_data,
496 u.ap);
497
498 drv_sta_notify(local, &sdata->vif, STA_NOTIFY_REMOVE,
499 &(*sta)->sta);
500 sdata = (*sta)->sdata;
501 }
502
503 if (ieee80211_vif_is_mesh(&sdata->vif)) {
504 mesh_accept_plinks_update(sdata);
505#ifdef CONFIG_MAC80211_MESH
506 del_timer(&(*sta)->plink_timer);
507#endif
508 }
509
510#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
511 printk(KERN_DEBUG "%s: Removed STA %pM\n",
512 wiphy_name(local->hw.wiphy), (*sta)->sta.addr);
513#endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
514
515 /*
516 * Finally, pull caller's reference if the STA is pinned by the
517 * task that is adding the debugfs entries. In that case, we
518 * leave the STA "to be freed".
519 *
520 * The rules are not trivial, but not too complex either:
521 * (1) pin_status is only modified under the sta_lock
522 * (2) STAs may only be pinned under the RTNL so that
523 * sta_info_flush() is guaranteed to actually destroy
524 * all STAs that are active for a given interface, this
525 * is required for correctness because otherwise we
526 * could notify a driver that an interface is going
527 * away and only after that (!) notify it about a STA
528 * on that interface going away.
529 * (3) sta_info_debugfs_add_work() will set the status
530 * to PINNED when it found an item that needs a new
531 * debugfs directory created. In that case, that item
532 * must not be freed although all *RCU* users are done
533 * with it. Hence, we tell the caller of _unlink()
534 * that the item is already gone (as can happen when
535 * two tasks try to unlink/destroy at the same time)
536 * (4) We set the pin_status to DESTROY here when we
537 * find such an item.
538 * (5) sta_info_debugfs_add_work() will reset the pin_status
539 * from PINNED to NORMAL when it is done with the item,
540 * but will check for DESTROY before resetting it in
541 * which case it will free the item.
542 */
543 if ((*sta)->pin_status == STA_INFO_PIN_STAT_PINNED) {
544 (*sta)->pin_status = STA_INFO_PIN_STAT_DESTROY;
545 *sta = NULL;
546 return;
547 }
548}
549
550void sta_info_unlink(struct sta_info **sta)
551{
552 struct ieee80211_local *local = (*sta)->local;
553 unsigned long flags;
554
555 spin_lock_irqsave(&local->sta_lock, flags);
556 __sta_info_unlink(sta);
557 spin_unlock_irqrestore(&local->sta_lock, flags);
558}
559
560static int sta_info_buffer_expired(struct sta_info *sta, 560static int sta_info_buffer_expired(struct sta_info *sta,
561 struct sk_buff *skb) 561 struct sk_buff *skb)
562{ 562{
@@ -613,109 +613,209 @@ static void sta_info_cleanup_expire_buffered(struct ieee80211_local *local,
613 } 613 }
614} 614}
615 615
616 616static int __must_check __sta_info_destroy(struct sta_info *sta)
617static void sta_info_cleanup(unsigned long data)
618{ 617{
619 struct ieee80211_local *local = (struct ieee80211_local *) data; 618 struct ieee80211_local *local;
620 struct sta_info *sta; 619 struct ieee80211_sub_if_data *sdata;
620 struct sk_buff *skb;
621 unsigned long flags;
622 int ret, i;
621 623
622 rcu_read_lock(); 624 might_sleep();
623 list_for_each_entry_rcu(sta, &local->sta_list, list)
624 sta_info_cleanup_expire_buffered(local, sta);
625 rcu_read_unlock();
626 625
627 if (local->quiescing) 626 if (!sta)
628 return; 627 return -ENOENT;
629 628
630 local->sta_cleanup.expires = 629 local = sta->local;
631 round_jiffies(jiffies + STA_INFO_CLEANUP_INTERVAL); 630 sdata = sta->sdata;
632 add_timer(&local->sta_cleanup);
633}
634 631
635#ifdef CONFIG_MAC80211_DEBUGFS 632 spin_lock_irqsave(&local->sta_lock, flags);
636/* 633 ret = sta_info_hash_del(local, sta);
637 * See comment in __sta_info_unlink, 634 /* this might still be the pending list ... which is fine */
638 * caller must hold local->sta_lock. 635 if (!ret)
639 */ 636 list_del(&sta->list);
640static void __sta_info_pin(struct sta_info *sta) 637 spin_unlock_irqrestore(&local->sta_lock, flags);
641{ 638 if (ret)
642 WARN_ON(sta->pin_status != STA_INFO_PIN_STAT_NORMAL); 639 return ret;
643 sta->pin_status = STA_INFO_PIN_STAT_PINNED; 640
641 if (sta->key) {
642 ieee80211_key_free(sta->key);
643 /*
644 * We have only unlinked the key, and actually destroying it
645 * may mean it is removed from hardware which requires that
646 * the key->sta pointer is still valid, so flush the key todo
647 * list here.
648 *
649 * ieee80211_key_todo() will synchronize_rcu() so after this
650 * nothing can reference this sta struct any more.
651 */
652 ieee80211_key_todo();
653
654 WARN_ON(sta->key);
655 }
656
657 sta->dead = true;
658
659 if (test_and_clear_sta_flags(sta,
660 WLAN_STA_PS_STA | WLAN_STA_PS_DRIVER)) {
661 BUG_ON(!sdata->bss);
662
663 atomic_dec(&sdata->bss->num_sta_ps);
664 __sta_info_clear_tim_bit(sdata->bss, sta);
665 }
666
667 local->num_sta--;
668 local->sta_generation++;
669
670 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
671 rcu_assign_pointer(sdata->u.vlan.sta, NULL);
672
673 if (sta->uploaded) {
674 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
675 sdata = container_of(sdata->bss,
676 struct ieee80211_sub_if_data,
677 u.ap);
678 drv_sta_remove(local, sdata, &sta->sta);
679 sdata = sta->sdata;
680 }
681
682#ifdef CONFIG_MAC80211_MESH
683 if (ieee80211_vif_is_mesh(&sdata->vif)) {
684 mesh_accept_plinks_update(sdata);
685 del_timer(&sta->plink_timer);
686 }
687#endif
688
689#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
690 printk(KERN_DEBUG "%s: Removed STA %pM\n",
691 wiphy_name(local->hw.wiphy), sta->sta.addr);
692#endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
693 cancel_work_sync(&sta->drv_unblock_wk);
694
695 rate_control_remove_sta_debugfs(sta);
696 ieee80211_sta_debugfs_remove(sta);
697
698#ifdef CONFIG_MAC80211_MESH
699 if (ieee80211_vif_is_mesh(&sta->sdata->vif)) {
700 mesh_plink_deactivate(sta);
701 del_timer_sync(&sta->plink_timer);
702 }
703#endif
704
705 while ((skb = skb_dequeue(&sta->ps_tx_buf)) != NULL) {
706 local->total_ps_buffered--;
707 dev_kfree_skb_any(skb);
708 }
709
710 while ((skb = skb_dequeue(&sta->tx_filtered)) != NULL)
711 dev_kfree_skb_any(skb);
712
713 for (i = 0; i < STA_TID_NUM; i++) {
714 struct tid_ampdu_rx *tid_rx;
715 struct tid_ampdu_tx *tid_tx;
716
717 spin_lock_bh(&sta->lock);
718 tid_rx = sta->ampdu_mlme.tid_rx[i];
719 /* Make sure timer won't free the tid_rx struct, see below */
720 if (tid_rx)
721 tid_rx->shutdown = true;
722
723 spin_unlock_bh(&sta->lock);
724
725 /*
726 * Outside spinlock - shutdown is true now so that the timer
727 * won't free tid_rx, we have to do that now. Can't let the
728 * timer do it because we have to sync the timer outside the
729 * lock that it takes itself.
730 */
731 if (tid_rx) {
732 del_timer_sync(&tid_rx->session_timer);
733 kfree(tid_rx);
734 }
735
736 /*
737 * No need to do such complications for TX agg sessions, the
738 * path leading to freeing the tid_tx struct goes via a call
739 * from the driver, and thus needs to look up the sta struct
740 * again, which cannot be found when we get here. Hence, we
741 * just need to delete the timer and free the aggregation
742 * info; we won't be telling the peer about it then but that
743 * doesn't matter if we're not talking to it again anyway.
744 */
745 tid_tx = sta->ampdu_mlme.tid_tx[i];
746 if (tid_tx) {
747 del_timer_sync(&tid_tx->addba_resp_timer);
748 /*
749 * STA removed while aggregation session being
750 * started? Bit odd, but purge frames anyway.
751 */
752 skb_queue_purge(&tid_tx->pending);
753 kfree(tid_tx);
754 }
755 }
756
757 __sta_info_free(local, sta);
758
759 return 0;
644} 760}
645 761
646/* 762int sta_info_destroy_addr(struct ieee80211_sub_if_data *sdata, const u8 *addr)
647 * See comment in __sta_info_unlink, returns sta if it
648 * needs to be destroyed.
649 */
650static struct sta_info *__sta_info_unpin(struct sta_info *sta)
651{ 763{
652 struct sta_info *ret = NULL; 764 struct sta_info *sta;
653 unsigned long flags; 765 int ret;
654 766
655 spin_lock_irqsave(&sta->local->sta_lock, flags); 767 mutex_lock(&sdata->local->sta_mtx);
656 WARN_ON(sta->pin_status != STA_INFO_PIN_STAT_DESTROY && 768 sta = sta_info_get(sdata, addr);
657 sta->pin_status != STA_INFO_PIN_STAT_PINNED); 769 ret = __sta_info_destroy(sta);
658 if (sta->pin_status == STA_INFO_PIN_STAT_DESTROY) 770 mutex_unlock(&sdata->local->sta_mtx);
659 ret = sta;
660 sta->pin_status = STA_INFO_PIN_STAT_NORMAL;
661 spin_unlock_irqrestore(&sta->local->sta_lock, flags);
662 771
663 return ret; 772 return ret;
664} 773}
665 774
666static void sta_info_debugfs_add_work(struct work_struct *work) 775int sta_info_destroy_addr_bss(struct ieee80211_sub_if_data *sdata,
776 const u8 *addr)
667{ 777{
668 struct ieee80211_local *local = 778 struct sta_info *sta;
669 container_of(work, struct ieee80211_local, sta_debugfs_add); 779 int ret;
670 struct sta_info *sta, *tmp;
671 unsigned long flags;
672 780
673 /* We need to keep the RTNL across the whole pinned status. */ 781 mutex_lock(&sdata->local->sta_mtx);
674 rtnl_lock(); 782 sta = sta_info_get_bss(sdata, addr);
675 while (1) { 783 ret = __sta_info_destroy(sta);
676 sta = NULL; 784 mutex_unlock(&sdata->local->sta_mtx);
677 785
678 spin_lock_irqsave(&local->sta_lock, flags); 786 return ret;
679 list_for_each_entry(tmp, &local->sta_list, list) { 787}
680 /*
681 * debugfs.add_has_run will be set by
682 * ieee80211_sta_debugfs_add regardless
683 * of what else it does.
684 */
685 if (!tmp->debugfs.add_has_run) {
686 sta = tmp;
687 __sta_info_pin(sta);
688 break;
689 }
690 }
691 spin_unlock_irqrestore(&local->sta_lock, flags);
692 788
693 if (!sta) 789static void sta_info_cleanup(unsigned long data)
694 break; 790{
791 struct ieee80211_local *local = (struct ieee80211_local *) data;
792 struct sta_info *sta;
695 793
696 ieee80211_sta_debugfs_add(sta); 794 rcu_read_lock();
697 rate_control_add_sta_debugfs(sta); 795 list_for_each_entry_rcu(sta, &local->sta_list, list)
796 sta_info_cleanup_expire_buffered(local, sta);
797 rcu_read_unlock();
698 798
699 sta = __sta_info_unpin(sta); 799 if (local->quiescing)
700 sta_info_destroy(sta); 800 return;
701 } 801
702 rtnl_unlock(); 802 local->sta_cleanup.expires =
803 round_jiffies(jiffies + STA_INFO_CLEANUP_INTERVAL);
804 add_timer(&local->sta_cleanup);
703} 805}
704#endif
705 806
706void sta_info_init(struct ieee80211_local *local) 807void sta_info_init(struct ieee80211_local *local)
707{ 808{
708 spin_lock_init(&local->sta_lock); 809 spin_lock_init(&local->sta_lock);
810 mutex_init(&local->sta_mtx);
709 INIT_LIST_HEAD(&local->sta_list); 811 INIT_LIST_HEAD(&local->sta_list);
812 INIT_LIST_HEAD(&local->sta_pending_list);
813 INIT_WORK(&local->sta_finish_work, sta_info_finish_work);
710 814
711 setup_timer(&local->sta_cleanup, sta_info_cleanup, 815 setup_timer(&local->sta_cleanup, sta_info_cleanup,
712 (unsigned long)local); 816 (unsigned long)local);
713 local->sta_cleanup.expires = 817 local->sta_cleanup.expires =
714 round_jiffies(jiffies + STA_INFO_CLEANUP_INTERVAL); 818 round_jiffies(jiffies + STA_INFO_CLEANUP_INTERVAL);
715
716#ifdef CONFIG_MAC80211_DEBUGFS
717 INIT_WORK(&local->sta_debugfs_add, sta_info_debugfs_add_work);
718#endif
719} 819}
720 820
721int sta_info_start(struct ieee80211_local *local) 821int sta_info_start(struct ieee80211_local *local)
@@ -727,16 +827,6 @@ int sta_info_start(struct ieee80211_local *local)
727void sta_info_stop(struct ieee80211_local *local) 827void sta_info_stop(struct ieee80211_local *local)
728{ 828{
729 del_timer(&local->sta_cleanup); 829 del_timer(&local->sta_cleanup);
730#ifdef CONFIG_MAC80211_DEBUGFS
731 /*
732 * Make sure the debugfs adding work isn't pending after this
733 * because we're about to be destroyed. It doesn't matter
734 * whether it ran or not since we're going to flush all STAs
735 * anyway.
736 */
737 cancel_work_sync(&local->sta_debugfs_add);
738#endif
739
740 sta_info_flush(local, NULL); 830 sta_info_flush(local, NULL);
741} 831}
742 832
@@ -752,26 +842,19 @@ int sta_info_flush(struct ieee80211_local *local,
752 struct ieee80211_sub_if_data *sdata) 842 struct ieee80211_sub_if_data *sdata)
753{ 843{
754 struct sta_info *sta, *tmp; 844 struct sta_info *sta, *tmp;
755 LIST_HEAD(tmp_list);
756 int ret = 0; 845 int ret = 0;
757 unsigned long flags;
758 846
759 might_sleep(); 847 might_sleep();
760 848
761 spin_lock_irqsave(&local->sta_lock, flags); 849 mutex_lock(&local->sta_mtx);
850
851 sta_info_finish_pending(local);
852
762 list_for_each_entry_safe(sta, tmp, &local->sta_list, list) { 853 list_for_each_entry_safe(sta, tmp, &local->sta_list, list) {
763 if (!sdata || sdata == sta->sdata) { 854 if (!sdata || sdata == sta->sdata)
764 __sta_info_unlink(&sta); 855 WARN_ON(__sta_info_destroy(sta));
765 if (sta) {
766 list_add_tail(&sta->list, &tmp_list);
767 ret++;
768 }
769 }
770 } 856 }
771 spin_unlock_irqrestore(&local->sta_lock, flags); 857 mutex_unlock(&local->sta_mtx);
772
773 list_for_each_entry_safe(sta, tmp, &tmp_list, list)
774 sta_info_destroy(sta);
775 858
776 return ret; 859 return ret;
777} 860}
@@ -781,33 +864,137 @@ void ieee80211_sta_expire(struct ieee80211_sub_if_data *sdata,
781{ 864{
782 struct ieee80211_local *local = sdata->local; 865 struct ieee80211_local *local = sdata->local;
783 struct sta_info *sta, *tmp; 866 struct sta_info *sta, *tmp;
784 LIST_HEAD(tmp_list);
785 unsigned long flags;
786 867
787 spin_lock_irqsave(&local->sta_lock, flags); 868 mutex_lock(&local->sta_mtx);
788 list_for_each_entry_safe(sta, tmp, &local->sta_list, list) 869 list_for_each_entry_safe(sta, tmp, &local->sta_list, list)
789 if (time_after(jiffies, sta->last_rx + exp_time)) { 870 if (time_after(jiffies, sta->last_rx + exp_time)) {
790#ifdef CONFIG_MAC80211_IBSS_DEBUG 871#ifdef CONFIG_MAC80211_IBSS_DEBUG
791 printk(KERN_DEBUG "%s: expiring inactive STA %pM\n", 872 printk(KERN_DEBUG "%s: expiring inactive STA %pM\n",
792 sdata->dev->name, sta->sta.addr); 873 sdata->name, sta->sta.addr);
793#endif 874#endif
794 __sta_info_unlink(&sta); 875 WARN_ON(__sta_info_destroy(sta));
795 if (sta)
796 list_add(&sta->list, &tmp_list);
797 } 876 }
798 spin_unlock_irqrestore(&local->sta_lock, flags); 877 mutex_unlock(&local->sta_mtx);
878}
879
880struct ieee80211_sta *ieee80211_find_sta_by_hw(struct ieee80211_hw *hw,
881 const u8 *addr)
882{
883 struct sta_info *sta, *nxt;
799 884
800 list_for_each_entry_safe(sta, tmp, &tmp_list, list) 885 /* Just return a random station ... first in list ... */
801 sta_info_destroy(sta); 886 for_each_sta_info(hw_to_local(hw), addr, sta, nxt)
887 return &sta->sta;
888 return NULL;
802} 889}
890EXPORT_SYMBOL_GPL(ieee80211_find_sta_by_hw);
803 891
804struct ieee80211_sta *ieee80211_find_sta(struct ieee80211_hw *hw, 892struct ieee80211_sta *ieee80211_find_sta(struct ieee80211_vif *vif,
805 const u8 *addr) 893 const u8 *addr)
806{ 894{
807 struct sta_info *sta = sta_info_get(hw_to_local(hw), addr); 895 struct ieee80211_sub_if_data *sdata;
808 896
809 if (!sta) 897 if (!vif)
810 return NULL; 898 return NULL;
811 return &sta->sta; 899
900 sdata = vif_to_sdata(vif);
901
902 return ieee80211_find_sta_by_hw(&sdata->local->hw, addr);
812} 903}
813EXPORT_SYMBOL(ieee80211_find_sta); 904EXPORT_SYMBOL(ieee80211_find_sta);
905
906/* powersave support code */
907void ieee80211_sta_ps_deliver_wakeup(struct sta_info *sta)
908{
909 struct ieee80211_sub_if_data *sdata = sta->sdata;
910 struct ieee80211_local *local = sdata->local;
911 int sent, buffered;
912
913 drv_sta_notify(local, sdata, STA_NOTIFY_AWAKE, &sta->sta);
914
915 if (!skb_queue_empty(&sta->ps_tx_buf))
916 sta_info_clear_tim_bit(sta);
917
918 /* Send all buffered frames to the station */
919 sent = ieee80211_add_pending_skbs(local, &sta->tx_filtered);
920 buffered = ieee80211_add_pending_skbs(local, &sta->ps_tx_buf);
921 sent += buffered;
922 local->total_ps_buffered -= buffered;
923
924#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
925 printk(KERN_DEBUG "%s: STA %pM aid %d sending %d filtered/%d PS frames "
926 "since STA not sleeping anymore\n", sdata->name,
927 sta->sta.addr, sta->sta.aid, sent - buffered, buffered);
928#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
929}
930
931void ieee80211_sta_ps_deliver_poll_response(struct sta_info *sta)
932{
933 struct ieee80211_sub_if_data *sdata = sta->sdata;
934 struct ieee80211_local *local = sdata->local;
935 struct sk_buff *skb;
936 int no_pending_pkts;
937
938 skb = skb_dequeue(&sta->tx_filtered);
939 if (!skb) {
940 skb = skb_dequeue(&sta->ps_tx_buf);
941 if (skb)
942 local->total_ps_buffered--;
943 }
944 no_pending_pkts = skb_queue_empty(&sta->tx_filtered) &&
945 skb_queue_empty(&sta->ps_tx_buf);
946
947 if (skb) {
948 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
949 struct ieee80211_hdr *hdr =
950 (struct ieee80211_hdr *) skb->data;
951
952 /*
953 * Tell TX path to send this frame even though the STA may
954 * still remain is PS mode after this frame exchange.
955 */
956 info->flags |= IEEE80211_TX_CTL_PSPOLL_RESPONSE;
957
958#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
959 printk(KERN_DEBUG "STA %pM aid %d: PS Poll (entries after %d)\n",
960 sta->sta.addr, sta->sta.aid,
961 skb_queue_len(&sta->ps_tx_buf));
962#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
963
964 /* Use MoreData flag to indicate whether there are more
965 * buffered frames for this STA */
966 if (no_pending_pkts)
967 hdr->frame_control &= cpu_to_le16(~IEEE80211_FCTL_MOREDATA);
968 else
969 hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_MOREDATA);
970
971 ieee80211_add_pending_skb(local, skb);
972
973 if (no_pending_pkts)
974 sta_info_clear_tim_bit(sta);
975#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
976 } else {
977 /*
978 * FIXME: This can be the result of a race condition between
979 * us expiring a frame and the station polling for it.
980 * Should we send it a null-func frame indicating we
981 * have nothing buffered for it?
982 */
983 printk(KERN_DEBUG "%s: STA %pM sent PS Poll even "
984 "though there are no buffered frames for it\n",
985 sdata->name, sta->sta.addr);
986#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
987 }
988}
989
990void ieee80211_sta_block_awake(struct ieee80211_hw *hw,
991 struct ieee80211_sta *pubsta, bool block)
992{
993 struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
994
995 if (block)
996 set_sta_flags(sta, WLAN_STA_PS_DRIVER);
997 else
998 ieee80211_queue_work(hw, &sta->drv_unblock_wk);
999}
1000EXPORT_SYMBOL(ieee80211_sta_block_awake);
diff --git a/net/mac80211/sta_info.h b/net/mac80211/sta_info.h
index ccc3adf962c7..822d84522937 100644
--- a/net/mac80211/sta_info.h
+++ b/net/mac80211/sta_info.h
@@ -12,6 +12,7 @@
12#include <linux/list.h> 12#include <linux/list.h>
13#include <linux/types.h> 13#include <linux/types.h>
14#include <linux/if_ether.h> 14#include <linux/if_ether.h>
15#include <linux/workqueue.h>
15#include "key.h" 16#include "key.h"
16 17
17/** 18/**
@@ -21,7 +22,7 @@
21 * 22 *
22 * @WLAN_STA_AUTH: Station is authenticated. 23 * @WLAN_STA_AUTH: Station is authenticated.
23 * @WLAN_STA_ASSOC: Station is associated. 24 * @WLAN_STA_ASSOC: Station is associated.
24 * @WLAN_STA_PS: Station is in power-save mode 25 * @WLAN_STA_PS_STA: Station is in power-save mode
25 * @WLAN_STA_AUTHORIZED: Station is authorized to send/receive traffic. 26 * @WLAN_STA_AUTHORIZED: Station is authorized to send/receive traffic.
26 * This bit is always checked so needs to be enabled for all stations 27 * This bit is always checked so needs to be enabled for all stations
27 * when virtual port control is not in use. 28 * when virtual port control is not in use.
@@ -36,11 +37,19 @@
36 * @WLAN_STA_MFP: Management frame protection is used with this STA. 37 * @WLAN_STA_MFP: Management frame protection is used with this STA.
37 * @WLAN_STA_SUSPEND: Set/cleared during a suspend/resume cycle. 38 * @WLAN_STA_SUSPEND: Set/cleared during a suspend/resume cycle.
38 * Used to deny ADDBA requests (both TX and RX). 39 * Used to deny ADDBA requests (both TX and RX).
40 * @WLAN_STA_PS_DRIVER: driver requires keeping this station in
41 * power-save mode logically to flush frames that might still
42 * be in the queues
43 * @WLAN_STA_PSPOLL: Station sent PS-poll while driver was keeping
44 * station in power-save mode, reply when the driver unblocks.
45 * @WLAN_STA_DISASSOC: Disassociation in progress.
46 * This is used to reject TX BA session requests when disassociation
47 * is in progress.
39 */ 48 */
40enum ieee80211_sta_info_flags { 49enum ieee80211_sta_info_flags {
41 WLAN_STA_AUTH = 1<<0, 50 WLAN_STA_AUTH = 1<<0,
42 WLAN_STA_ASSOC = 1<<1, 51 WLAN_STA_ASSOC = 1<<1,
43 WLAN_STA_PS = 1<<2, 52 WLAN_STA_PS_STA = 1<<2,
44 WLAN_STA_AUTHORIZED = 1<<3, 53 WLAN_STA_AUTHORIZED = 1<<3,
45 WLAN_STA_SHORT_PREAMBLE = 1<<4, 54 WLAN_STA_SHORT_PREAMBLE = 1<<4,
46 WLAN_STA_ASSOC_AP = 1<<5, 55 WLAN_STA_ASSOC_AP = 1<<5,
@@ -48,7 +57,10 @@ enum ieee80211_sta_info_flags {
48 WLAN_STA_WDS = 1<<7, 57 WLAN_STA_WDS = 1<<7,
49 WLAN_STA_CLEAR_PS_FILT = 1<<9, 58 WLAN_STA_CLEAR_PS_FILT = 1<<9,
50 WLAN_STA_MFP = 1<<10, 59 WLAN_STA_MFP = 1<<10,
51 WLAN_STA_SUSPEND = 1<<11 60 WLAN_STA_SUSPEND = 1<<11,
61 WLAN_STA_PS_DRIVER = 1<<12,
62 WLAN_STA_PSPOLL = 1<<13,
63 WLAN_STA_DISASSOC = 1<<14,
52}; 64};
53 65
54#define STA_TID_NUM 16 66#define STA_TID_NUM 16
@@ -154,11 +166,6 @@ struct sta_ampdu_mlme {
154}; 166};
155 167
156 168
157/* see __sta_info_unlink */
158#define STA_INFO_PIN_STAT_NORMAL 0
159#define STA_INFO_PIN_STAT_PINNED 1
160#define STA_INFO_PIN_STAT_DESTROY 2
161
162/** 169/**
163 * struct sta_info - STA information 170 * struct sta_info - STA information
164 * 171 *
@@ -177,8 +184,8 @@ struct sta_ampdu_mlme {
177 * @lock: used for locking all fields that require locking, see comments 184 * @lock: used for locking all fields that require locking, see comments
178 * in the header file. 185 * in the header file.
179 * @flaglock: spinlock for flags accesses 186 * @flaglock: spinlock for flags accesses
187 * @drv_unblock_wk: used for driver PS unblocking
180 * @listen_interval: listen interval of this station, when we're acting as AP 188 * @listen_interval: listen interval of this station, when we're acting as AP
181 * @pin_status: used internally for pinning a STA struct into memory
182 * @flags: STA flags, see &enum ieee80211_sta_info_flags 189 * @flags: STA flags, see &enum ieee80211_sta_info_flags
183 * @ps_tx_buf: buffer of frames to transmit to this station 190 * @ps_tx_buf: buffer of frames to transmit to this station
184 * when it leaves power saving state 191 * when it leaves power saving state
@@ -193,7 +200,6 @@ struct sta_ampdu_mlme {
193 * @rx_fragments: number of received MPDUs 200 * @rx_fragments: number of received MPDUs
194 * @rx_dropped: number of dropped MPDUs from this STA 201 * @rx_dropped: number of dropped MPDUs from this STA
195 * @last_signal: signal of last received frame from this STA 202 * @last_signal: signal of last received frame from this STA
196 * @last_qual: qual of last received frame from this STA
197 * @last_noise: noise of last received frame from this STA 203 * @last_noise: noise of last received frame from this STA
198 * @last_seq_ctrl: last received seq/frag number from this STA (per RX queue) 204 * @last_seq_ctrl: last received seq/frag number from this STA (per RX queue)
199 * @tx_filtered_count: number of frames the hardware filtered for this STA 205 * @tx_filtered_count: number of frames the hardware filtered for this STA
@@ -217,6 +223,8 @@ struct sta_ampdu_mlme {
217 * @plink_timer_was_running: used by suspend/resume to restore timers 223 * @plink_timer_was_running: used by suspend/resume to restore timers
218 * @debugfs: debug filesystem info 224 * @debugfs: debug filesystem info
219 * @sta: station information we share with the driver 225 * @sta: station information we share with the driver
226 * @dead: set to true when sta is unlinked
227 * @uploaded: set to true when sta is uploaded to the driver
220 */ 228 */
221struct sta_info { 229struct sta_info {
222 /* General information, mostly static */ 230 /* General information, mostly static */
@@ -230,13 +238,13 @@ struct sta_info {
230 spinlock_t lock; 238 spinlock_t lock;
231 spinlock_t flaglock; 239 spinlock_t flaglock;
232 240
241 struct work_struct drv_unblock_wk;
242
233 u16 listen_interval; 243 u16 listen_interval;
234 244
235 /* 245 bool dead;
236 * for use by the internal lifetime management, 246
237 * see __sta_info_unlink 247 bool uploaded;
238 */
239 u8 pin_status;
240 248
241 /* 249 /*
242 * frequently updated, locked with own spinlock (flaglock), 250 * frequently updated, locked with own spinlock (flaglock),
@@ -259,7 +267,6 @@ struct sta_info {
259 unsigned long rx_fragments; 267 unsigned long rx_fragments;
260 unsigned long rx_dropped; 268 unsigned long rx_dropped;
261 int last_signal; 269 int last_signal;
262 int last_qual;
263 int last_noise; 270 int last_noise;
264 __le16 last_seq_ctrl[NUM_RX_DATA_QUEUES]; 271 __le16 last_seq_ctrl[NUM_RX_DATA_QUEUES];
265 272
@@ -301,28 +308,6 @@ struct sta_info {
301#ifdef CONFIG_MAC80211_DEBUGFS 308#ifdef CONFIG_MAC80211_DEBUGFS
302 struct sta_info_debugfsdentries { 309 struct sta_info_debugfsdentries {
303 struct dentry *dir; 310 struct dentry *dir;
304 struct dentry *flags;
305 struct dentry *num_ps_buf_frames;
306 struct dentry *inactive_ms;
307 struct dentry *last_seq_ctrl;
308 struct dentry *agg_status;
309 struct dentry *aid;
310 struct dentry *dev;
311 struct dentry *rx_packets;
312 struct dentry *tx_packets;
313 struct dentry *rx_bytes;
314 struct dentry *tx_bytes;
315 struct dentry *rx_duplicates;
316 struct dentry *rx_fragments;
317 struct dentry *rx_dropped;
318 struct dentry *tx_fragments;
319 struct dentry *tx_filtered;
320 struct dentry *tx_retry_failed;
321 struct dentry *tx_retry_count;
322 struct dentry *last_signal;
323 struct dentry *last_qual;
324 struct dentry *last_noise;
325 struct dentry *wep_weak_iv_count;
326 bool add_has_run; 311 bool add_has_run;
327 } debugfs; 312 } debugfs;
328#endif 313#endif
@@ -413,14 +398,42 @@ static inline u32 get_sta_flags(struct sta_info *sta)
413#define STA_INFO_CLEANUP_INTERVAL (10 * HZ) 398#define STA_INFO_CLEANUP_INTERVAL (10 * HZ)
414 399
415/* 400/*
416 * Get a STA info, must have be under RCU read lock. 401 * Get a STA info, must be under RCU read lock.
417 */ 402 */
418struct sta_info *sta_info_get(struct ieee80211_local *local, const u8 *addr); 403struct sta_info *sta_info_get(struct ieee80211_sub_if_data *sdata,
404 const u8 *addr);
405
406struct sta_info *sta_info_get_bss(struct ieee80211_sub_if_data *sdata,
407 const u8 *addr);
408
409static inline
410void for_each_sta_info_type_check(struct ieee80211_local *local,
411 const u8 *addr,
412 struct sta_info *sta,
413 struct sta_info *nxt)
414{
415}
416
417#define for_each_sta_info(local, _addr, sta, nxt) \
418 for ( /* initialise loop */ \
419 sta = rcu_dereference(local->sta_hash[STA_HASH(_addr)]),\
420 nxt = sta ? rcu_dereference(sta->hnext) : NULL; \
421 /* typecheck */ \
422 for_each_sta_info_type_check(local, (_addr), sta, nxt), \
423 /* continue condition */ \
424 sta; \
425 /* advance loop */ \
426 sta = nxt, \
427 nxt = sta ? rcu_dereference(sta->hnext) : NULL \
428 ) \
429 /* compare address and run code only if it matches */ \
430 if (memcmp(sta->sta.addr, (_addr), ETH_ALEN) == 0)
431
419/* 432/*
420 * Get STA info by index, BROKEN! 433 * Get STA info by index, BROKEN!
421 */ 434 */
422struct sta_info *sta_info_get_by_idx(struct ieee80211_local *local, int idx, 435struct sta_info *sta_info_get_by_idx(struct ieee80211_sub_if_data *sdata,
423 struct net_device *dev); 436 int idx);
424/* 437/*
425 * Create a new STA info, caller owns returned structure 438 * Create a new STA info, caller owns returned structure
426 * until sta_info_insert(). 439 * until sta_info_insert().
@@ -431,18 +444,19 @@ struct sta_info *sta_info_alloc(struct ieee80211_sub_if_data *sdata,
431 * Insert STA info into hash table/list, returns zero or a 444 * Insert STA info into hash table/list, returns zero or a
432 * -EEXIST if (if the same MAC address is already present). 445 * -EEXIST if (if the same MAC address is already present).
433 * 446 *
434 * Calling this without RCU protection makes the caller 447 * Calling the non-rcu version makes the caller relinquish,
435 * relinquish its reference to @sta. 448 * the _rcu version calls read_lock_rcu() and must be called
449 * without it held.
436 */ 450 */
437int sta_info_insert(struct sta_info *sta); 451int sta_info_insert(struct sta_info *sta);
438/* 452int sta_info_insert_rcu(struct sta_info *sta) __acquires(RCU);
439 * Unlink a STA info from the hash table/list. 453int sta_info_insert_atomic(struct sta_info *sta);
440 * This can NULL the STA pointer if somebody else 454
441 * has already unlinked it. 455int sta_info_destroy_addr(struct ieee80211_sub_if_data *sdata,
442 */ 456 const u8 *addr);
443void sta_info_unlink(struct sta_info **sta); 457int sta_info_destroy_addr_bss(struct ieee80211_sub_if_data *sdata,
458 const u8 *addr);
444 459
445void sta_info_destroy(struct sta_info *sta);
446void sta_info_set_tim_bit(struct sta_info *sta); 460void sta_info_set_tim_bit(struct sta_info *sta);
447void sta_info_clear_tim_bit(struct sta_info *sta); 461void sta_info_clear_tim_bit(struct sta_info *sta);
448 462
@@ -454,4 +468,7 @@ int sta_info_flush(struct ieee80211_local *local,
454void ieee80211_sta_expire(struct ieee80211_sub_if_data *sdata, 468void ieee80211_sta_expire(struct ieee80211_sub_if_data *sdata,
455 unsigned long exp_time); 469 unsigned long exp_time);
456 470
471void ieee80211_sta_ps_deliver_wakeup(struct sta_info *sta);
472void ieee80211_sta_ps_deliver_poll_response(struct sta_info *sta);
473
457#endif /* STA_INFO_H */ 474#endif /* STA_INFO_H */
diff --git a/net/mac80211/status.c b/net/mac80211/status.c
new file mode 100644
index 000000000000..56d5b9a6ec5b
--- /dev/null
+++ b/net/mac80211/status.c
@@ -0,0 +1,388 @@
1/*
2 * Copyright 2002-2005, Instant802 Networks, Inc.
3 * Copyright 2005-2006, Devicescape Software, Inc.
4 * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz>
5 * Copyright 2008-2010 Johannes Berg <johannes@sipsolutions.net>
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.
10 */
11
12#include <net/mac80211.h>
13#include "ieee80211_i.h"
14#include "rate.h"
15#include "mesh.h"
16#include "led.h"
17
18
19void ieee80211_tx_status_irqsafe(struct ieee80211_hw *hw,
20 struct sk_buff *skb)
21{
22 struct ieee80211_local *local = hw_to_local(hw);
23 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
24 int tmp;
25
26 skb->pkt_type = IEEE80211_TX_STATUS_MSG;
27 skb_queue_tail(info->flags & IEEE80211_TX_CTL_REQ_TX_STATUS ?
28 &local->skb_queue : &local->skb_queue_unreliable, skb);
29 tmp = skb_queue_len(&local->skb_queue) +
30 skb_queue_len(&local->skb_queue_unreliable);
31 while (tmp > IEEE80211_IRQSAFE_QUEUE_LIMIT &&
32 (skb = skb_dequeue(&local->skb_queue_unreliable))) {
33 dev_kfree_skb_irq(skb);
34 tmp--;
35 I802_DEBUG_INC(local->tx_status_drop);
36 }
37 tasklet_schedule(&local->tasklet);
38}
39EXPORT_SYMBOL(ieee80211_tx_status_irqsafe);
40
41static void ieee80211_handle_filtered_frame(struct ieee80211_local *local,
42 struct sta_info *sta,
43 struct sk_buff *skb)
44{
45 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
46
47 /*
48 * This skb 'survived' a round-trip through the driver, and
49 * hopefully the driver didn't mangle it too badly. However,
50 * we can definitely not rely on the the control information
51 * being correct. Clear it so we don't get junk there, and
52 * indicate that it needs new processing, but must not be
53 * modified/encrypted again.
54 */
55 memset(&info->control, 0, sizeof(info->control));
56
57 info->control.jiffies = jiffies;
58 info->control.vif = &sta->sdata->vif;
59 info->flags |= IEEE80211_TX_INTFL_NEED_TXPROCESSING |
60 IEEE80211_TX_INTFL_RETRANSMISSION;
61
62 sta->tx_filtered_count++;
63
64 /*
65 * Clear the TX filter mask for this STA when sending the next
66 * packet. If the STA went to power save mode, this will happen
67 * when it wakes up for the next time.
68 */
69 set_sta_flags(sta, WLAN_STA_CLEAR_PS_FILT);
70
71 /*
72 * This code races in the following way:
73 *
74 * (1) STA sends frame indicating it will go to sleep and does so
75 * (2) hardware/firmware adds STA to filter list, passes frame up
76 * (3) hardware/firmware processes TX fifo and suppresses a frame
77 * (4) we get TX status before having processed the frame and
78 * knowing that the STA has gone to sleep.
79 *
80 * This is actually quite unlikely even when both those events are
81 * processed from interrupts coming in quickly after one another or
82 * even at the same time because we queue both TX status events and
83 * RX frames to be processed by a tasklet and process them in the
84 * same order that they were received or TX status last. Hence, there
85 * is no race as long as the frame RX is processed before the next TX
86 * status, which drivers can ensure, see below.
87 *
88 * Note that this can only happen if the hardware or firmware can
89 * actually add STAs to the filter list, if this is done by the
90 * driver in response to set_tim() (which will only reduce the race
91 * this whole filtering tries to solve, not completely solve it)
92 * this situation cannot happen.
93 *
94 * To completely solve this race drivers need to make sure that they
95 * (a) don't mix the irq-safe/not irq-safe TX status/RX processing
96 * functions and
97 * (b) always process RX events before TX status events if ordering
98 * can be unknown, for example with different interrupt status
99 * bits.
100 */
101 if (test_sta_flags(sta, WLAN_STA_PS_STA) &&
102 skb_queue_len(&sta->tx_filtered) < STA_MAX_TX_BUFFER) {
103 skb_queue_tail(&sta->tx_filtered, skb);
104 return;
105 }
106
107 if (!test_sta_flags(sta, WLAN_STA_PS_STA) &&
108 !(info->flags & IEEE80211_TX_INTFL_RETRIED)) {
109 /* Software retry the packet once */
110 info->flags |= IEEE80211_TX_INTFL_RETRIED;
111 ieee80211_add_pending_skb(local, skb);
112 return;
113 }
114
115#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
116 if (net_ratelimit())
117 printk(KERN_DEBUG "%s: dropped TX filtered frame, "
118 "queue_len=%d PS=%d @%lu\n",
119 wiphy_name(local->hw.wiphy),
120 skb_queue_len(&sta->tx_filtered),
121 !!test_sta_flags(sta, WLAN_STA_PS_STA), jiffies);
122#endif
123 dev_kfree_skb(skb);
124}
125
126static void ieee80211_frame_acked(struct sta_info *sta, struct sk_buff *skb)
127{
128 struct ieee80211_mgmt *mgmt = (void *) skb->data;
129 struct ieee80211_local *local = sta->local;
130 struct ieee80211_sub_if_data *sdata = sta->sdata;
131
132 if (ieee80211_is_action(mgmt->frame_control) &&
133 sdata->vif.type == NL80211_IFTYPE_STATION &&
134 mgmt->u.action.category == WLAN_CATEGORY_HT &&
135 mgmt->u.action.u.ht_smps.action == WLAN_HT_ACTION_SMPS) {
136 /*
137 * This update looks racy, but isn't -- if we come
138 * here we've definitely got a station that we're
139 * talking to, and on a managed interface that can
140 * only be the AP. And the only other place updating
141 * this variable is before we're associated.
142 */
143 switch (mgmt->u.action.u.ht_smps.smps_control) {
144 case WLAN_HT_SMPS_CONTROL_DYNAMIC:
145 sta->sdata->u.mgd.ap_smps = IEEE80211_SMPS_DYNAMIC;
146 break;
147 case WLAN_HT_SMPS_CONTROL_STATIC:
148 sta->sdata->u.mgd.ap_smps = IEEE80211_SMPS_STATIC;
149 break;
150 case WLAN_HT_SMPS_CONTROL_DISABLED:
151 default: /* shouldn't happen since we don't send that */
152 sta->sdata->u.mgd.ap_smps = IEEE80211_SMPS_OFF;
153 break;
154 }
155
156 ieee80211_queue_work(&local->hw, &local->recalc_smps);
157 }
158}
159
160void ieee80211_tx_status(struct ieee80211_hw *hw, struct sk_buff *skb)
161{
162 struct sk_buff *skb2;
163 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
164 struct ieee80211_local *local = hw_to_local(hw);
165 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
166 u16 frag, type;
167 __le16 fc;
168 struct ieee80211_supported_band *sband;
169 struct ieee80211_tx_status_rtap_hdr *rthdr;
170 struct ieee80211_sub_if_data *sdata;
171 struct net_device *prev_dev = NULL;
172 struct sta_info *sta, *tmp;
173 int retry_count = -1, i;
174 bool injected;
175
176 for (i = 0; i < IEEE80211_TX_MAX_RATES; i++) {
177 /* the HW cannot have attempted that rate */
178 if (i >= hw->max_rates) {
179 info->status.rates[i].idx = -1;
180 info->status.rates[i].count = 0;
181 }
182
183 retry_count += info->status.rates[i].count;
184 }
185 if (retry_count < 0)
186 retry_count = 0;
187
188 rcu_read_lock();
189
190 sband = local->hw.wiphy->bands[info->band];
191 fc = hdr->frame_control;
192
193 for_each_sta_info(local, hdr->addr1, sta, tmp) {
194 /* skip wrong virtual interface */
195 if (memcmp(hdr->addr2, sta->sdata->vif.addr, ETH_ALEN))
196 continue;
197
198 if (!(info->flags & IEEE80211_TX_STAT_ACK) &&
199 test_sta_flags(sta, WLAN_STA_PS_STA)) {
200 /*
201 * The STA is in power save mode, so assume
202 * that this TX packet failed because of that.
203 */
204 ieee80211_handle_filtered_frame(local, sta, skb);
205 rcu_read_unlock();
206 return;
207 }
208
209 if ((info->flags & IEEE80211_TX_STAT_AMPDU_NO_BACK) &&
210 (ieee80211_is_data_qos(fc))) {
211 u16 tid, ssn;
212 u8 *qc;
213
214 qc = ieee80211_get_qos_ctl(hdr);
215 tid = qc[0] & 0xf;
216 ssn = ((le16_to_cpu(hdr->seq_ctrl) + 0x10)
217 & IEEE80211_SCTL_SEQ);
218 ieee80211_send_bar(sta->sdata, hdr->addr1,
219 tid, ssn);
220 }
221
222 if (info->flags & IEEE80211_TX_STAT_TX_FILTERED) {
223 ieee80211_handle_filtered_frame(local, sta, skb);
224 rcu_read_unlock();
225 return;
226 } else {
227 if (!(info->flags & IEEE80211_TX_STAT_ACK))
228 sta->tx_retry_failed++;
229 sta->tx_retry_count += retry_count;
230 }
231
232 rate_control_tx_status(local, sband, sta, skb);
233 if (ieee80211_vif_is_mesh(&sta->sdata->vif))
234 ieee80211s_update_metric(local, sta, skb);
235
236 if (!(info->flags & IEEE80211_TX_CTL_INJECTED) &&
237 (info->flags & IEEE80211_TX_STAT_ACK))
238 ieee80211_frame_acked(sta, skb);
239 }
240
241 rcu_read_unlock();
242
243 ieee80211_led_tx(local, 0);
244
245 /* SNMP counters
246 * Fragments are passed to low-level drivers as separate skbs, so these
247 * are actually fragments, not frames. Update frame counters only for
248 * the first fragment of the frame. */
249
250 frag = le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_FRAG;
251 type = le16_to_cpu(hdr->frame_control) & IEEE80211_FCTL_FTYPE;
252
253 if (info->flags & IEEE80211_TX_STAT_ACK) {
254 if (frag == 0) {
255 local->dot11TransmittedFrameCount++;
256 if (is_multicast_ether_addr(hdr->addr1))
257 local->dot11MulticastTransmittedFrameCount++;
258 if (retry_count > 0)
259 local->dot11RetryCount++;
260 if (retry_count > 1)
261 local->dot11MultipleRetryCount++;
262 }
263
264 /* This counter shall be incremented for an acknowledged MPDU
265 * with an individual address in the address 1 field or an MPDU
266 * with a multicast address in the address 1 field of type Data
267 * or Management. */
268 if (!is_multicast_ether_addr(hdr->addr1) ||
269 type == IEEE80211_FTYPE_DATA ||
270 type == IEEE80211_FTYPE_MGMT)
271 local->dot11TransmittedFragmentCount++;
272 } else {
273 if (frag == 0)
274 local->dot11FailedCount++;
275 }
276
277 if (ieee80211_is_nullfunc(fc) && ieee80211_has_pm(fc) &&
278 (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS) &&
279 !(info->flags & IEEE80211_TX_CTL_INJECTED) &&
280 local->ps_sdata && !(local->scanning)) {
281 if (info->flags & IEEE80211_TX_STAT_ACK) {
282 local->ps_sdata->u.mgd.flags |=
283 IEEE80211_STA_NULLFUNC_ACKED;
284 ieee80211_queue_work(&local->hw,
285 &local->dynamic_ps_enable_work);
286 } else
287 mod_timer(&local->dynamic_ps_timer, jiffies +
288 msecs_to_jiffies(10));
289 }
290
291 if (info->flags & IEEE80211_TX_INTFL_NL80211_FRAME_TX)
292 cfg80211_action_tx_status(
293 skb->dev, (unsigned long) skb, skb->data, skb->len,
294 !!(info->flags & IEEE80211_TX_STAT_ACK), GFP_ATOMIC);
295
296 /* this was a transmitted frame, but now we want to reuse it */
297 skb_orphan(skb);
298
299 /*
300 * This is a bit racy but we can avoid a lot of work
301 * with this test...
302 */
303 if (!local->monitors && !local->cooked_mntrs) {
304 dev_kfree_skb(skb);
305 return;
306 }
307
308 /* send frame to monitor interfaces now */
309
310 if (skb_headroom(skb) < sizeof(*rthdr)) {
311 printk(KERN_ERR "ieee80211_tx_status: headroom too small\n");
312 dev_kfree_skb(skb);
313 return;
314 }
315
316 rthdr = (struct ieee80211_tx_status_rtap_hdr *)
317 skb_push(skb, sizeof(*rthdr));
318
319 memset(rthdr, 0, sizeof(*rthdr));
320 rthdr->hdr.it_len = cpu_to_le16(sizeof(*rthdr));
321 rthdr->hdr.it_present =
322 cpu_to_le32((1 << IEEE80211_RADIOTAP_TX_FLAGS) |
323 (1 << IEEE80211_RADIOTAP_DATA_RETRIES) |
324 (1 << IEEE80211_RADIOTAP_RATE));
325
326 if (!(info->flags & IEEE80211_TX_STAT_ACK) &&
327 !is_multicast_ether_addr(hdr->addr1))
328 rthdr->tx_flags |= cpu_to_le16(IEEE80211_RADIOTAP_F_TX_FAIL);
329
330 /*
331 * XXX: Once radiotap gets the bitmap reset thing the vendor
332 * extensions proposal contains, we can actually report
333 * the whole set of tries we did.
334 */
335 if ((info->status.rates[0].flags & IEEE80211_TX_RC_USE_RTS_CTS) ||
336 (info->status.rates[0].flags & IEEE80211_TX_RC_USE_CTS_PROTECT))
337 rthdr->tx_flags |= cpu_to_le16(IEEE80211_RADIOTAP_F_TX_CTS);
338 else if (info->status.rates[0].flags & IEEE80211_TX_RC_USE_RTS_CTS)
339 rthdr->tx_flags |= cpu_to_le16(IEEE80211_RADIOTAP_F_TX_RTS);
340 if (info->status.rates[0].idx >= 0 &&
341 !(info->status.rates[0].flags & IEEE80211_TX_RC_MCS))
342 rthdr->rate = sband->bitrates[
343 info->status.rates[0].idx].bitrate / 5;
344
345 /* for now report the total retry_count */
346 rthdr->data_retries = retry_count;
347
348 /* Need to make a copy before skb->cb gets cleared */
349 injected = !!(info->flags & IEEE80211_TX_CTL_INJECTED);
350
351 /* XXX: is this sufficient for BPF? */
352 skb_set_mac_header(skb, 0);
353 skb->ip_summed = CHECKSUM_UNNECESSARY;
354 skb->pkt_type = PACKET_OTHERHOST;
355 skb->protocol = htons(ETH_P_802_2);
356 memset(skb->cb, 0, sizeof(skb->cb));
357
358 rcu_read_lock();
359 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
360 if (sdata->vif.type == NL80211_IFTYPE_MONITOR) {
361 if (!ieee80211_sdata_running(sdata))
362 continue;
363
364 if ((sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES) &&
365 !injected &&
366 (type == IEEE80211_FTYPE_DATA))
367 continue;
368
369 if (prev_dev) {
370 skb2 = skb_clone(skb, GFP_ATOMIC);
371 if (skb2) {
372 skb2->dev = prev_dev;
373 netif_rx(skb2);
374 }
375 }
376
377 prev_dev = sdata->dev;
378 }
379 }
380 if (prev_dev) {
381 skb->dev = prev_dev;
382 netif_rx(skb);
383 skb = NULL;
384 }
385 rcu_read_unlock();
386 dev_kfree_skb(skb);
387}
388EXPORT_SYMBOL(ieee80211_tx_status);
diff --git a/net/mac80211/tkip.c b/net/mac80211/tkip.c
index 964b7faa7f17..7ef491e9d66d 100644
--- a/net/mac80211/tkip.c
+++ b/net/mac80211/tkip.c
@@ -100,7 +100,7 @@ static void tkip_mixing_phase1(const u8 *tk, struct tkip_ctx *ctx,
100 p1k[3] += tkipS(p1k[2] ^ get_unaligned_le16(tk + 12 + j)); 100 p1k[3] += tkipS(p1k[2] ^ get_unaligned_le16(tk + 12 + j));
101 p1k[4] += tkipS(p1k[3] ^ get_unaligned_le16(tk + 0 + j)) + i; 101 p1k[4] += tkipS(p1k[3] ^ get_unaligned_le16(tk + 0 + j)) + i;
102 } 102 }
103 ctx->initialized = 1; 103 ctx->state = TKIP_STATE_PHASE1_DONE;
104} 104}
105 105
106static void tkip_mixing_phase2(const u8 *tk, struct tkip_ctx *ctx, 106static void tkip_mixing_phase2(const u8 *tk, struct tkip_ctx *ctx,
@@ -183,7 +183,7 @@ void ieee80211_get_tkip_key(struct ieee80211_key_conf *keyconf,
183 /* Update the p1k only when the iv16 in the packet wraps around, this 183 /* Update the p1k only when the iv16 in the packet wraps around, this
184 * might occur after the wrap around of iv16 in the key in case of 184 * might occur after the wrap around of iv16 in the key in case of
185 * fragmented packets. */ 185 * fragmented packets. */
186 if (iv16 == 0 || !ctx->initialized) 186 if (iv16 == 0 || ctx->state == TKIP_STATE_NOT_INIT)
187 tkip_mixing_phase1(tk, ctx, hdr->addr2, iv32); 187 tkip_mixing_phase1(tk, ctx, hdr->addr2, iv32);
188 188
189 if (type == IEEE80211_TKIP_P1_KEY) { 189 if (type == IEEE80211_TKIP_P1_KEY) {
@@ -195,11 +195,13 @@ void ieee80211_get_tkip_key(struct ieee80211_key_conf *keyconf,
195} 195}
196EXPORT_SYMBOL(ieee80211_get_tkip_key); 196EXPORT_SYMBOL(ieee80211_get_tkip_key);
197 197
198/* Encrypt packet payload with TKIP using @key. @pos is a pointer to the 198/*
199 * Encrypt packet payload with TKIP using @key. @pos is a pointer to the
199 * beginning of the buffer containing payload. This payload must include 200 * beginning of the buffer containing payload. This payload must include
200 * headroom of eight octets for IV and Ext. IV and taildroom of four octets 201 * the IV/Ext.IV and space for (taildroom) four octets for ICV.
201 * for ICV. @payload_len is the length of payload (_not_ including extra 202 * @payload_len is the length of payload (_not_ including IV/ICV length).
202 * headroom and tailroom). @ta is the transmitter addresses. */ 203 * @ta is the transmitter addresses.
204 */
203void ieee80211_tkip_encrypt_data(struct crypto_blkcipher *tfm, 205void ieee80211_tkip_encrypt_data(struct crypto_blkcipher *tfm,
204 struct ieee80211_key *key, 206 struct ieee80211_key *key,
205 u8 *pos, size_t payload_len, u8 *ta) 207 u8 *pos, size_t payload_len, u8 *ta)
@@ -209,12 +211,11 @@ void ieee80211_tkip_encrypt_data(struct crypto_blkcipher *tfm,
209 const u8 *tk = &key->conf.key[NL80211_TKIP_DATA_OFFSET_ENCR_KEY]; 211 const u8 *tk = &key->conf.key[NL80211_TKIP_DATA_OFFSET_ENCR_KEY];
210 212
211 /* Calculate per-packet key */ 213 /* Calculate per-packet key */
212 if (ctx->iv16 == 0 || !ctx->initialized) 214 if (ctx->iv16 == 0 || ctx->state == TKIP_STATE_NOT_INIT)
213 tkip_mixing_phase1(tk, ctx, ta, ctx->iv32); 215 tkip_mixing_phase1(tk, ctx, ta, ctx->iv32);
214 216
215 tkip_mixing_phase2(tk, ctx, ctx->iv16, rc4key); 217 tkip_mixing_phase2(tk, ctx, ctx->iv16, rc4key);
216 218
217 pos = ieee80211_tkip_add_iv(pos, key, key->u.tkip.tx.iv16);
218 ieee80211_wep_encrypt_data(tfm, rc4key, 16, pos, payload_len); 219 ieee80211_wep_encrypt_data(tfm, rc4key, 16, pos, payload_len);
219} 220}
220 221
@@ -259,7 +260,7 @@ int ieee80211_tkip_decrypt_data(struct crypto_blkcipher *tfm,
259 if ((keyid >> 6) != key->conf.keyidx) 260 if ((keyid >> 6) != key->conf.keyidx)
260 return TKIP_DECRYPT_INVALID_KEYIDX; 261 return TKIP_DECRYPT_INVALID_KEYIDX;
261 262
262 if (key->u.tkip.rx[queue].initialized && 263 if (key->u.tkip.rx[queue].state != TKIP_STATE_NOT_INIT &&
263 (iv32 < key->u.tkip.rx[queue].iv32 || 264 (iv32 < key->u.tkip.rx[queue].iv32 ||
264 (iv32 == key->u.tkip.rx[queue].iv32 && 265 (iv32 == key->u.tkip.rx[queue].iv32 &&
265 iv16 <= key->u.tkip.rx[queue].iv16))) { 266 iv16 <= key->u.tkip.rx[queue].iv16))) {
@@ -275,11 +276,11 @@ int ieee80211_tkip_decrypt_data(struct crypto_blkcipher *tfm,
275 276
276 if (only_iv) { 277 if (only_iv) {
277 res = TKIP_DECRYPT_OK; 278 res = TKIP_DECRYPT_OK;
278 key->u.tkip.rx[queue].initialized = 1; 279 key->u.tkip.rx[queue].state = TKIP_STATE_PHASE1_HW_UPLOADED;
279 goto done; 280 goto done;
280 } 281 }
281 282
282 if (!key->u.tkip.rx[queue].initialized || 283 if (key->u.tkip.rx[queue].state == TKIP_STATE_NOT_INIT ||
283 key->u.tkip.rx[queue].iv32 != iv32) { 284 key->u.tkip.rx[queue].iv32 != iv32) {
284 /* IV16 wrapped around - perform TKIP phase 1 */ 285 /* IV16 wrapped around - perform TKIP phase 1 */
285 tkip_mixing_phase1(tk, &key->u.tkip.rx[queue], ta, iv32); 286 tkip_mixing_phase1(tk, &key->u.tkip.rx[queue], ta, iv32);
@@ -299,18 +300,18 @@ int ieee80211_tkip_decrypt_data(struct crypto_blkcipher *tfm,
299 printk("\n"); 300 printk("\n");
300 } 301 }
301#endif 302#endif
302 if (key->local->ops->update_tkip_key && 303 }
303 key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE) { 304 if (key->local->ops->update_tkip_key &&
304 u8 bcast[ETH_ALEN] = 305 key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE &&
305 {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; 306 key->u.tkip.rx[queue].state != TKIP_STATE_PHASE1_HW_UPLOADED) {
306 u8 *sta_addr = key->sta->sta.addr; 307 struct ieee80211_sub_if_data *sdata = key->sdata;
307 308
308 if (is_multicast_ether_addr(ra)) 309 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
309 sta_addr = bcast; 310 sdata = container_of(key->sdata->bss,
310 311 struct ieee80211_sub_if_data, u.ap);
311 drv_update_tkip_key(key->local, &key->conf, sta_addr, 312 drv_update_tkip_key(key->local, sdata, &key->conf, key->sta,
312 iv32, key->u.tkip.rx[queue].p1k); 313 iv32, key->u.tkip.rx[queue].p1k);
313 } 314 key->u.tkip.rx[queue].state = TKIP_STATE_PHASE1_HW_UPLOADED;
314 } 315 }
315 316
316 tkip_mixing_phase2(tk, &key->u.tkip.rx[queue], iv16, rc4key); 317 tkip_mixing_phase2(tk, &key->u.tkip.rx[queue], iv16, rc4key);
diff --git a/net/mac80211/tx.c b/net/mac80211/tx.c
index eaa4118de988..cfc473e1b050 100644
--- a/net/mac80211/tx.c
+++ b/net/mac80211/tx.c
@@ -180,6 +180,71 @@ static int inline is_ieee80211_device(struct ieee80211_local *local,
180} 180}
181 181
182/* tx handlers */ 182/* tx handlers */
183static ieee80211_tx_result debug_noinline
184ieee80211_tx_h_dynamic_ps(struct ieee80211_tx_data *tx)
185{
186 struct ieee80211_local *local = tx->local;
187 struct ieee80211_if_managed *ifmgd;
188
189 /* driver doesn't support power save */
190 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS))
191 return TX_CONTINUE;
192
193 /* hardware does dynamic power save */
194 if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)
195 return TX_CONTINUE;
196
197 /* dynamic power save disabled */
198 if (local->hw.conf.dynamic_ps_timeout <= 0)
199 return TX_CONTINUE;
200
201 /* we are scanning, don't enable power save */
202 if (local->scanning)
203 return TX_CONTINUE;
204
205 if (!local->ps_sdata)
206 return TX_CONTINUE;
207
208 /* No point if we're going to suspend */
209 if (local->quiescing)
210 return TX_CONTINUE;
211
212 /* dynamic ps is supported only in managed mode */
213 if (tx->sdata->vif.type != NL80211_IFTYPE_STATION)
214 return TX_CONTINUE;
215
216 ifmgd = &tx->sdata->u.mgd;
217
218 /*
219 * Don't wakeup from power save if u-apsd is enabled, voip ac has
220 * u-apsd enabled and the frame is in voip class. This effectively
221 * means that even if all access categories have u-apsd enabled, in
222 * practise u-apsd is only used with the voip ac. This is a
223 * workaround for the case when received voip class packets do not
224 * have correct qos tag for some reason, due the network or the
225 * peer application.
226 *
227 * Note: local->uapsd_queues access is racy here. If the value is
228 * changed via debugfs, user needs to reassociate manually to have
229 * everything in sync.
230 */
231 if ((ifmgd->flags & IEEE80211_STA_UAPSD_ENABLED)
232 && (local->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
233 && skb_get_queue_mapping(tx->skb) == 0)
234 return TX_CONTINUE;
235
236 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
237 ieee80211_stop_queues_by_reason(&local->hw,
238 IEEE80211_QUEUE_STOP_REASON_PS);
239 ieee80211_queue_work(&local->hw,
240 &local->dynamic_ps_disable_work);
241 }
242
243 mod_timer(&local->dynamic_ps_timer, jiffies +
244 msecs_to_jiffies(local->hw.conf.dynamic_ps_timeout));
245
246 return TX_CONTINUE;
247}
183 248
184static ieee80211_tx_result debug_noinline 249static ieee80211_tx_result debug_noinline
185ieee80211_tx_h_check_assoc(struct ieee80211_tx_data *tx) 250ieee80211_tx_h_check_assoc(struct ieee80211_tx_data *tx)
@@ -223,7 +288,7 @@ ieee80211_tx_h_check_assoc(struct ieee80211_tx_data *tx)
223#ifdef CONFIG_MAC80211_VERBOSE_DEBUG 288#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
224 printk(KERN_DEBUG "%s: dropped data frame to not " 289 printk(KERN_DEBUG "%s: dropped data frame to not "
225 "associated station %pM\n", 290 "associated station %pM\n",
226 tx->dev->name, hdr->addr1); 291 tx->sdata->name, hdr->addr1);
227#endif /* CONFIG_MAC80211_VERBOSE_DEBUG */ 292#endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
228 I802_DEBUG_INC(tx->local->tx_handlers_drop_not_assoc); 293 I802_DEBUG_INC(tx->local->tx_handlers_drop_not_assoc);
229 return TX_DROP; 294 return TX_DROP;
@@ -317,12 +382,11 @@ ieee80211_tx_h_multicast_ps_buf(struct ieee80211_tx_data *tx)
317 if (!atomic_read(&tx->sdata->bss->num_sta_ps)) 382 if (!atomic_read(&tx->sdata->bss->num_sta_ps))
318 return TX_CONTINUE; 383 return TX_CONTINUE;
319 384
320 /* buffered in hardware */ 385 info->flags |= IEEE80211_TX_CTL_SEND_AFTER_DTIM;
321 if (!(tx->local->hw.flags & IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING)) {
322 info->flags |= IEEE80211_TX_CTL_SEND_AFTER_DTIM;
323 386
387 /* device releases frame after DTIM beacon */
388 if (!(tx->local->hw.flags & IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING))
324 return TX_CONTINUE; 389 return TX_CONTINUE;
325 }
326 390
327 /* buffered in mac80211 */ 391 /* buffered in mac80211 */
328 if (tx->local->total_ps_buffered >= TOTAL_MAX_TX_BUFFER) 392 if (tx->local->total_ps_buffered >= TOTAL_MAX_TX_BUFFER)
@@ -332,7 +396,7 @@ ieee80211_tx_h_multicast_ps_buf(struct ieee80211_tx_data *tx)
332#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG 396#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
333 if (net_ratelimit()) 397 if (net_ratelimit())
334 printk(KERN_DEBUG "%s: BC TX buffer full - dropping the oldest frame\n", 398 printk(KERN_DEBUG "%s: BC TX buffer full - dropping the oldest frame\n",
335 tx->dev->name); 399 tx->sdata->name);
336#endif 400#endif
337 dev_kfree_skb(skb_dequeue(&tx->sdata->bss->ps_bc_buf)); 401 dev_kfree_skb(skb_dequeue(&tx->sdata->bss->ps_bc_buf));
338 } else 402 } else
@@ -367,15 +431,16 @@ ieee80211_tx_h_unicast_ps_buf(struct ieee80211_tx_data *tx)
367 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data; 431 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data;
368 u32 staflags; 432 u32 staflags;
369 433
370 if (unlikely(!sta || ieee80211_is_probe_resp(hdr->frame_control) 434 if (unlikely(!sta ||
371 || ieee80211_is_auth(hdr->frame_control) 435 ieee80211_is_probe_resp(hdr->frame_control) ||
372 || ieee80211_is_assoc_resp(hdr->frame_control) 436 ieee80211_is_auth(hdr->frame_control) ||
373 || ieee80211_is_reassoc_resp(hdr->frame_control))) 437 ieee80211_is_assoc_resp(hdr->frame_control) ||
438 ieee80211_is_reassoc_resp(hdr->frame_control)))
374 return TX_CONTINUE; 439 return TX_CONTINUE;
375 440
376 staflags = get_sta_flags(sta); 441 staflags = get_sta_flags(sta);
377 442
378 if (unlikely((staflags & WLAN_STA_PS) && 443 if (unlikely((staflags & (WLAN_STA_PS_STA | WLAN_STA_PS_DRIVER)) &&
379 !(info->flags & IEEE80211_TX_CTL_PSPOLL_RESPONSE))) { 444 !(info->flags & IEEE80211_TX_CTL_PSPOLL_RESPONSE))) {
380#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG 445#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
381 printk(KERN_DEBUG "STA %pM aid %d: PS buffer (entries " 446 printk(KERN_DEBUG "STA %pM aid %d: PS buffer (entries "
@@ -391,15 +456,20 @@ ieee80211_tx_h_unicast_ps_buf(struct ieee80211_tx_data *tx)
391 if (net_ratelimit()) { 456 if (net_ratelimit()) {
392 printk(KERN_DEBUG "%s: STA %pM TX " 457 printk(KERN_DEBUG "%s: STA %pM TX "
393 "buffer full - dropping oldest frame\n", 458 "buffer full - dropping oldest frame\n",
394 tx->dev->name, sta->sta.addr); 459 tx->sdata->name, sta->sta.addr);
395 } 460 }
396#endif 461#endif
397 dev_kfree_skb(old); 462 dev_kfree_skb(old);
398 } else 463 } else
399 tx->local->total_ps_buffered++; 464 tx->local->total_ps_buffered++;
400 465
401 /* Queue frame to be sent after STA sends an PS Poll frame */ 466 /*
402 if (skb_queue_empty(&sta->ps_tx_buf)) 467 * Queue frame to be sent after STA wakes up/polls,
468 * but don't set the TIM bit if the driver is blocking
469 * wakeup or poll response transmissions anyway.
470 */
471 if (skb_queue_empty(&sta->ps_tx_buf) &&
472 !(staflags & WLAN_STA_PS_DRIVER))
403 sta_info_set_tim_bit(sta); 473 sta_info_set_tim_bit(sta);
404 474
405 info->control.jiffies = jiffies; 475 info->control.jiffies = jiffies;
@@ -409,9 +479,9 @@ ieee80211_tx_h_unicast_ps_buf(struct ieee80211_tx_data *tx)
409 return TX_QUEUED; 479 return TX_QUEUED;
410 } 480 }
411#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG 481#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
412 else if (unlikely(test_sta_flags(sta, WLAN_STA_PS))) { 482 else if (unlikely(staflags & WLAN_STA_PS_STA)) {
413 printk(KERN_DEBUG "%s: STA %pM in PS mode, but pspoll " 483 printk(KERN_DEBUG "%s: STA %pM in PS mode, but pspoll "
414 "set -> send frame\n", tx->dev->name, 484 "set -> send frame\n", tx->sdata->name,
415 sta->sta.addr); 485 sta->sta.addr);
416 } 486 }
417#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */ 487#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
@@ -459,6 +529,8 @@ ieee80211_tx_h_select_key(struct ieee80211_tx_data *tx)
459 tx->key = NULL; 529 tx->key = NULL;
460 530
461 if (tx->key) { 531 if (tx->key) {
532 bool skip_hw = false;
533
462 tx->key->tx_rx_count++; 534 tx->key->tx_rx_count++;
463 /* TODO: add threshold stuff again */ 535 /* TODO: add threshold stuff again */
464 536
@@ -475,16 +547,32 @@ ieee80211_tx_h_select_key(struct ieee80211_tx_data *tx)
475 !ieee80211_use_mfp(hdr->frame_control, tx->sta, 547 !ieee80211_use_mfp(hdr->frame_control, tx->sta,
476 tx->skb)) 548 tx->skb))
477 tx->key = NULL; 549 tx->key = NULL;
550 else
551 skip_hw = (tx->key->conf.flags &
552 IEEE80211_KEY_FLAG_SW_MGMT) &&
553 ieee80211_is_mgmt(hdr->frame_control);
478 break; 554 break;
479 case ALG_AES_CMAC: 555 case ALG_AES_CMAC:
480 if (!ieee80211_is_mgmt(hdr->frame_control)) 556 if (!ieee80211_is_mgmt(hdr->frame_control))
481 tx->key = NULL; 557 tx->key = NULL;
482 break; 558 break;
483 } 559 }
560
561 if (!skip_hw && tx->key &&
562 tx->key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE)
563 info->control.hw_key = &tx->key->conf;
484 } 564 }
485 565
486 if (!tx->key || !(tx->key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE)) 566 return TX_CONTINUE;
487 info->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT; 567}
568
569static ieee80211_tx_result debug_noinline
570ieee80211_tx_h_sta(struct ieee80211_tx_data *tx)
571{
572 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
573
574 if (tx->sta && tx->sta->uploaded)
575 info->control.sta = &tx->sta->sta;
488 576
489 return TX_CONTINUE; 577 return TX_CONTINUE;
490} 578}
@@ -514,7 +602,12 @@ ieee80211_tx_h_rate_ctrl(struct ieee80211_tx_data *tx)
514 txrc.bss_conf = &tx->sdata->vif.bss_conf; 602 txrc.bss_conf = &tx->sdata->vif.bss_conf;
515 txrc.skb = tx->skb; 603 txrc.skb = tx->skb;
516 txrc.reported_rate.idx = -1; 604 txrc.reported_rate.idx = -1;
517 txrc.max_rate_idx = tx->sdata->max_ratectrl_rateidx; 605 txrc.rate_idx_mask = tx->sdata->rc_rateidx_mask[tx->channel->band];
606 if (txrc.rate_idx_mask == (1 << sband->n_bitrates) - 1)
607 txrc.max_rate_idx = -1;
608 else
609 txrc.max_rate_idx = fls(txrc.rate_idx_mask) - 1;
610 txrc.ap = tx->sdata->vif.type == NL80211_IFTYPE_AP;
518 611
519 /* set up RTS protection if desired */ 612 /* set up RTS protection if desired */
520 if (len > tx->local->hw.wiphy->rts_threshold) { 613 if (len > tx->local->hw.wiphy->rts_threshold) {
@@ -544,7 +637,7 @@ ieee80211_tx_h_rate_ctrl(struct ieee80211_tx_data *tx)
544 "%s: Dropped data frame as no usable bitrate found while " 637 "%s: Dropped data frame as no usable bitrate found while "
545 "scanning and associated. Target station: " 638 "scanning and associated. Target station: "
546 "%pM on %d GHz band\n", 639 "%pM on %d GHz band\n",
547 tx->dev->name, hdr->addr1, 640 tx->sdata->name, hdr->addr1,
548 tx->channel->band ? 5 : 2)) 641 tx->channel->band ? 5 : 2))
549 return TX_DROP; 642 return TX_DROP;
550 643
@@ -659,17 +752,6 @@ ieee80211_tx_h_rate_ctrl(struct ieee80211_tx_data *tx)
659} 752}
660 753
661static ieee80211_tx_result debug_noinline 754static ieee80211_tx_result debug_noinline
662ieee80211_tx_h_misc(struct ieee80211_tx_data *tx)
663{
664 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
665
666 if (tx->sta)
667 info->control.sta = &tx->sta->sta;
668
669 return TX_CONTINUE;
670}
671
672static ieee80211_tx_result debug_noinline
673ieee80211_tx_h_sequence(struct ieee80211_tx_data *tx) 755ieee80211_tx_h_sequence(struct ieee80211_tx_data *tx)
674{ 756{
675 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb); 757 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
@@ -928,7 +1010,8 @@ static bool __ieee80211_parse_tx_radiotap(struct ieee80211_tx_data *tx,
928 (struct ieee80211_radiotap_header *) skb->data; 1010 (struct ieee80211_radiotap_header *) skb->data;
929 struct ieee80211_supported_band *sband; 1011 struct ieee80211_supported_band *sband;
930 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); 1012 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
931 int ret = ieee80211_radiotap_iterator_init(&iterator, rthdr, skb->len); 1013 int ret = ieee80211_radiotap_iterator_init(&iterator, rthdr, skb->len,
1014 NULL);
932 1015
933 sband = tx->local->hw.wiphy->bands[tx->channel->band]; 1016 sband = tx->local->hw.wiphy->bands[tx->channel->band];
934 1017
@@ -964,7 +1047,7 @@ static bool __ieee80211_parse_tx_radiotap(struct ieee80211_tx_data *tx,
964 * because it will be recomputed and added 1047 * because it will be recomputed and added
965 * on transmission 1048 * on transmission
966 */ 1049 */
967 if (skb->len < (iterator.max_length + FCS_LEN)) 1050 if (skb->len < (iterator._max_length + FCS_LEN))
968 return false; 1051 return false;
969 1052
970 skb_trim(skb, skb->len - FCS_LEN); 1053 skb_trim(skb, skb->len - FCS_LEN);
@@ -991,10 +1074,10 @@ static bool __ieee80211_parse_tx_radiotap(struct ieee80211_tx_data *tx,
991 1074
992 /* 1075 /*
993 * remove the radiotap header 1076 * remove the radiotap header
994 * iterator->max_length was sanity-checked against 1077 * iterator->_max_length was sanity-checked against
995 * skb->len by iterator init 1078 * skb->len by iterator init
996 */ 1079 */
997 skb_pull(skb, iterator.max_length); 1080 skb_pull(skb, iterator._max_length);
998 1081
999 return true; 1082 return true;
1000} 1083}
@@ -1016,7 +1099,6 @@ ieee80211_tx_prepare(struct ieee80211_sub_if_data *sdata,
1016 1099
1017 memset(tx, 0, sizeof(*tx)); 1100 memset(tx, 0, sizeof(*tx));
1018 tx->skb = skb; 1101 tx->skb = skb;
1019 tx->dev = sdata->dev; /* use original interface */
1020 tx->local = local; 1102 tx->local = local;
1021 tx->sdata = sdata; 1103 tx->sdata = sdata;
1022 tx->channel = local->hw.conf.channel; 1104 tx->channel = local->hw.conf.channel;
@@ -1027,7 +1109,7 @@ ieee80211_tx_prepare(struct ieee80211_sub_if_data *sdata,
1027 tx->flags |= IEEE80211_TX_FRAGMENTED; 1109 tx->flags |= IEEE80211_TX_FRAGMENTED;
1028 1110
1029 /* process and remove the injection radiotap header */ 1111 /* process and remove the injection radiotap header */
1030 if (unlikely(info->flags & IEEE80211_TX_CTL_INJECTED)) { 1112 if (unlikely(info->flags & IEEE80211_TX_INTFL_HAS_RADIOTAP)) {
1031 if (!__ieee80211_parse_tx_radiotap(tx, skb)) 1113 if (!__ieee80211_parse_tx_radiotap(tx, skb))
1032 return TX_DROP; 1114 return TX_DROP;
1033 1115
@@ -1036,6 +1118,7 @@ ieee80211_tx_prepare(struct ieee80211_sub_if_data *sdata,
1036 * the radiotap header that was present and pre-filled 1118 * the radiotap header that was present and pre-filled
1037 * 'tx' with tx control information. 1119 * 'tx' with tx control information.
1038 */ 1120 */
1121 info->flags &= ~IEEE80211_TX_INTFL_HAS_RADIOTAP;
1039 } 1122 }
1040 1123
1041 /* 1124 /*
@@ -1047,7 +1130,15 @@ ieee80211_tx_prepare(struct ieee80211_sub_if_data *sdata,
1047 1130
1048 hdr = (struct ieee80211_hdr *) skb->data; 1131 hdr = (struct ieee80211_hdr *) skb->data;
1049 1132
1050 tx->sta = sta_info_get(local, hdr->addr1); 1133 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN) {
1134 tx->sta = rcu_dereference(sdata->u.vlan.sta);
1135 if (!tx->sta && sdata->dev->ieee80211_ptr->use_4addr)
1136 return TX_DROP;
1137 } else if (info->flags & IEEE80211_TX_CTL_INJECTED) {
1138 tx->sta = sta_info_get_bss(sdata, hdr->addr1);
1139 }
1140 if (!tx->sta)
1141 tx->sta = sta_info_get(sdata, hdr->addr1);
1051 1142
1052 if (tx->sta && ieee80211_is_data_qos(hdr->frame_control) && 1143 if (tx->sta && ieee80211_is_data_qos(hdr->frame_control) &&
1053 (local->hw.flags & IEEE80211_HW_AMPDU_AGGREGATION)) { 1144 (local->hw.flags & IEEE80211_HW_AMPDU_AGGREGATION)) {
@@ -1199,25 +1290,34 @@ static int __ieee80211_tx(struct ieee80211_local *local,
1199static int invoke_tx_handlers(struct ieee80211_tx_data *tx) 1290static int invoke_tx_handlers(struct ieee80211_tx_data *tx)
1200{ 1291{
1201 struct sk_buff *skb = tx->skb; 1292 struct sk_buff *skb = tx->skb;
1293 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1202 ieee80211_tx_result res = TX_DROP; 1294 ieee80211_tx_result res = TX_DROP;
1203 1295
1204#define CALL_TXH(txh) \ 1296#define CALL_TXH(txh) \
1205 res = txh(tx); \ 1297 do { \
1206 if (res != TX_CONTINUE) \ 1298 res = txh(tx); \
1299 if (res != TX_CONTINUE) \
1300 goto txh_done; \
1301 } while (0)
1302
1303 CALL_TXH(ieee80211_tx_h_dynamic_ps);
1304 CALL_TXH(ieee80211_tx_h_check_assoc);
1305 CALL_TXH(ieee80211_tx_h_ps_buf);
1306 CALL_TXH(ieee80211_tx_h_select_key);
1307 CALL_TXH(ieee80211_tx_h_sta);
1308 if (!(tx->local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL))
1309 CALL_TXH(ieee80211_tx_h_rate_ctrl);
1310
1311 if (unlikely(info->flags & IEEE80211_TX_INTFL_RETRANSMISSION))
1207 goto txh_done; 1312 goto txh_done;
1208 1313
1209 CALL_TXH(ieee80211_tx_h_check_assoc) 1314 CALL_TXH(ieee80211_tx_h_michael_mic_add);
1210 CALL_TXH(ieee80211_tx_h_ps_buf) 1315 CALL_TXH(ieee80211_tx_h_sequence);
1211 CALL_TXH(ieee80211_tx_h_select_key) 1316 CALL_TXH(ieee80211_tx_h_fragment);
1212 CALL_TXH(ieee80211_tx_h_michael_mic_add)
1213 CALL_TXH(ieee80211_tx_h_rate_ctrl)
1214 CALL_TXH(ieee80211_tx_h_misc)
1215 CALL_TXH(ieee80211_tx_h_sequence)
1216 CALL_TXH(ieee80211_tx_h_fragment)
1217 /* handlers after fragment must be aware of tx info fragmentation! */ 1317 /* handlers after fragment must be aware of tx info fragmentation! */
1218 CALL_TXH(ieee80211_tx_h_stats) 1318 CALL_TXH(ieee80211_tx_h_stats);
1219 CALL_TXH(ieee80211_tx_h_encrypt) 1319 CALL_TXH(ieee80211_tx_h_encrypt);
1220 CALL_TXH(ieee80211_tx_h_calculate_duration) 1320 CALL_TXH(ieee80211_tx_h_calculate_duration);
1221#undef CALL_TXH 1321#undef CALL_TXH
1222 1322
1223 txh_done: 1323 txh_done:
@@ -1397,29 +1497,14 @@ static void ieee80211_xmit(struct ieee80211_sub_if_data *sdata,
1397 int headroom; 1497 int headroom;
1398 bool may_encrypt; 1498 bool may_encrypt;
1399 1499
1400 dev_hold(sdata->dev); 1500 rcu_read_lock();
1401
1402 if ((local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) &&
1403 local->hw.conf.dynamic_ps_timeout > 0 &&
1404 !(local->scanning) && local->ps_sdata) {
1405 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
1406 ieee80211_stop_queues_by_reason(&local->hw,
1407 IEEE80211_QUEUE_STOP_REASON_PS);
1408 ieee80211_queue_work(&local->hw,
1409 &local->dynamic_ps_disable_work);
1410 }
1411
1412 mod_timer(&local->dynamic_ps_timer, jiffies +
1413 msecs_to_jiffies(local->hw.conf.dynamic_ps_timeout));
1414 }
1415
1416 info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS;
1417 1501
1418 if (unlikely(sdata->vif.type == NL80211_IFTYPE_MONITOR)) { 1502 if (unlikely(sdata->vif.type == NL80211_IFTYPE_MONITOR)) {
1419 int hdrlen; 1503 int hdrlen;
1420 u16 len_rthdr; 1504 u16 len_rthdr;
1421 1505
1422 info->flags |= IEEE80211_TX_CTL_INJECTED; 1506 info->flags |= IEEE80211_TX_CTL_INJECTED |
1507 IEEE80211_TX_INTFL_HAS_RADIOTAP;
1423 1508
1424 len_rthdr = ieee80211_get_radiotap_len(skb->data); 1509 len_rthdr = ieee80211_get_radiotap_len(skb->data);
1425 hdr = (struct ieee80211_hdr *)(skb->data + len_rthdr); 1510 hdr = (struct ieee80211_hdr *)(skb->data + len_rthdr);
@@ -1437,22 +1522,18 @@ static void ieee80211_xmit(struct ieee80211_sub_if_data *sdata,
1437 * support we will need a different mechanism. 1522 * support we will need a different mechanism.
1438 */ 1523 */
1439 1524
1440 rcu_read_lock();
1441 list_for_each_entry_rcu(tmp_sdata, &local->interfaces, 1525 list_for_each_entry_rcu(tmp_sdata, &local->interfaces,
1442 list) { 1526 list) {
1443 if (!netif_running(tmp_sdata->dev)) 1527 if (!ieee80211_sdata_running(tmp_sdata))
1444 continue; 1528 continue;
1445 if (tmp_sdata->vif.type != NL80211_IFTYPE_AP) 1529 if (tmp_sdata->vif.type != NL80211_IFTYPE_AP)
1446 continue; 1530 continue;
1447 if (compare_ether_addr(tmp_sdata->dev->dev_addr, 1531 if (compare_ether_addr(tmp_sdata->vif.addr,
1448 hdr->addr2) == 0) { 1532 hdr->addr2) == 0) {
1449 dev_hold(tmp_sdata->dev);
1450 dev_put(sdata->dev);
1451 sdata = tmp_sdata; 1533 sdata = tmp_sdata;
1452 break; 1534 break;
1453 } 1535 }
1454 } 1536 }
1455 rcu_read_unlock();
1456 } 1537 }
1457 } 1538 }
1458 1539
@@ -1466,7 +1547,7 @@ static void ieee80211_xmit(struct ieee80211_sub_if_data *sdata,
1466 1547
1467 if (ieee80211_skb_resize(local, skb, headroom, may_encrypt)) { 1548 if (ieee80211_skb_resize(local, skb, headroom, may_encrypt)) {
1468 dev_kfree_skb(skb); 1549 dev_kfree_skb(skb);
1469 dev_put(sdata->dev); 1550 rcu_read_unlock();
1470 return; 1551 return;
1471 } 1552 }
1472 1553
@@ -1477,13 +1558,13 @@ static void ieee80211_xmit(struct ieee80211_sub_if_data *sdata,
1477 !is_multicast_ether_addr(hdr->addr1)) 1558 !is_multicast_ether_addr(hdr->addr1))
1478 if (mesh_nexthop_lookup(skb, sdata)) { 1559 if (mesh_nexthop_lookup(skb, sdata)) {
1479 /* skb queued: don't free */ 1560 /* skb queued: don't free */
1480 dev_put(sdata->dev); 1561 rcu_read_unlock();
1481 return; 1562 return;
1482 } 1563 }
1483 1564
1484 ieee80211_select_queue(local, skb); 1565 ieee80211_set_qos_hdr(local, skb);
1485 ieee80211_tx(sdata, skb, false); 1566 ieee80211_tx(sdata, skb, false);
1486 dev_put(sdata->dev); 1567 rcu_read_unlock();
1487} 1568}
1488 1569
1489netdev_tx_t ieee80211_monitor_start_xmit(struct sk_buff *skb, 1570netdev_tx_t ieee80211_monitor_start_xmit(struct sk_buff *skb,
@@ -1547,6 +1628,8 @@ netdev_tx_t ieee80211_monitor_start_xmit(struct sk_buff *skb,
1547 1628
1548 memset(info, 0, sizeof(*info)); 1629 memset(info, 0, sizeof(*info));
1549 1630
1631 info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS;
1632
1550 /* pass the radiotap header up to xmit */ 1633 /* pass the radiotap header up to xmit */
1551 ieee80211_xmit(IEEE80211_DEV_TO_SUB_IF(dev), skb); 1634 ieee80211_xmit(IEEE80211_DEV_TO_SUB_IF(dev), skb);
1552 return NETDEV_TX_OK; 1635 return NETDEV_TX_OK;
@@ -1585,7 +1668,7 @@ netdev_tx_t ieee80211_subif_start_xmit(struct sk_buff *skb,
1585 const u8 *encaps_data; 1668 const u8 *encaps_data;
1586 int encaps_len, skip_header_bytes; 1669 int encaps_len, skip_header_bytes;
1587 int nh_pos, h_pos; 1670 int nh_pos, h_pos;
1588 struct sta_info *sta; 1671 struct sta_info *sta = NULL;
1589 u32 sta_flags = 0; 1672 u32 sta_flags = 0;
1590 1673
1591 if (unlikely(skb->len < ETH_HLEN)) { 1674 if (unlikely(skb->len < ETH_HLEN)) {
@@ -1602,12 +1685,28 @@ netdev_tx_t ieee80211_subif_start_xmit(struct sk_buff *skb,
1602 fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_DATA); 1685 fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_DATA);
1603 1686
1604 switch (sdata->vif.type) { 1687 switch (sdata->vif.type) {
1605 case NL80211_IFTYPE_AP:
1606 case NL80211_IFTYPE_AP_VLAN: 1688 case NL80211_IFTYPE_AP_VLAN:
1689 rcu_read_lock();
1690 sta = rcu_dereference(sdata->u.vlan.sta);
1691 if (sta) {
1692 fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS);
1693 /* RA TA DA SA */
1694 memcpy(hdr.addr1, sta->sta.addr, ETH_ALEN);
1695 memcpy(hdr.addr2, sdata->vif.addr, ETH_ALEN);
1696 memcpy(hdr.addr3, skb->data, ETH_ALEN);
1697 memcpy(hdr.addr4, skb->data + ETH_ALEN, ETH_ALEN);
1698 hdrlen = 30;
1699 sta_flags = get_sta_flags(sta);
1700 }
1701 rcu_read_unlock();
1702 if (sta)
1703 break;
1704 /* fall through */
1705 case NL80211_IFTYPE_AP:
1607 fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS); 1706 fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS);
1608 /* DA BSSID SA */ 1707 /* DA BSSID SA */
1609 memcpy(hdr.addr1, skb->data, ETH_ALEN); 1708 memcpy(hdr.addr1, skb->data, ETH_ALEN);
1610 memcpy(hdr.addr2, dev->dev_addr, ETH_ALEN); 1709 memcpy(hdr.addr2, sdata->vif.addr, ETH_ALEN);
1611 memcpy(hdr.addr3, skb->data + ETH_ALEN, ETH_ALEN); 1710 memcpy(hdr.addr3, skb->data + ETH_ALEN, ETH_ALEN);
1612 hdrlen = 24; 1711 hdrlen = 24;
1613 break; 1712 break;
@@ -1615,7 +1714,7 @@ netdev_tx_t ieee80211_subif_start_xmit(struct sk_buff *skb,
1615 fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS); 1714 fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS);
1616 /* RA TA DA SA */ 1715 /* RA TA DA SA */
1617 memcpy(hdr.addr1, sdata->u.wds.remote_addr, ETH_ALEN); 1716 memcpy(hdr.addr1, sdata->u.wds.remote_addr, ETH_ALEN);
1618 memcpy(hdr.addr2, dev->dev_addr, ETH_ALEN); 1717 memcpy(hdr.addr2, sdata->vif.addr, ETH_ALEN);
1619 memcpy(hdr.addr3, skb->data, ETH_ALEN); 1718 memcpy(hdr.addr3, skb->data, ETH_ALEN);
1620 memcpy(hdr.addr4, skb->data + ETH_ALEN, ETH_ALEN); 1719 memcpy(hdr.addr4, skb->data + ETH_ALEN, ETH_ALEN);
1621 hdrlen = 30; 1720 hdrlen = 30;
@@ -1629,8 +1728,8 @@ netdev_tx_t ieee80211_subif_start_xmit(struct sk_buff *skb,
1629 goto fail; 1728 goto fail;
1630 } 1729 }
1631 1730
1632 if (compare_ether_addr(dev->dev_addr, 1731 if (compare_ether_addr(sdata->vif.addr,
1633 skb->data + ETH_ALEN) == 0) { 1732 skb->data + ETH_ALEN) == 0) {
1634 hdrlen = ieee80211_fill_mesh_addresses(&hdr, &fc, 1733 hdrlen = ieee80211_fill_mesh_addresses(&hdr, &fc,
1635 skb->data, skb->data + ETH_ALEN); 1734 skb->data, skb->data + ETH_ALEN);
1636 meshhdrlen = ieee80211_new_mesh_header(&mesh_hdr, 1735 meshhdrlen = ieee80211_new_mesh_header(&mesh_hdr,
@@ -1639,24 +1738,28 @@ netdev_tx_t ieee80211_subif_start_xmit(struct sk_buff *skb,
1639 /* packet from other interface */ 1738 /* packet from other interface */
1640 struct mesh_path *mppath; 1739 struct mesh_path *mppath;
1641 int is_mesh_mcast = 1; 1740 int is_mesh_mcast = 1;
1642 char *mesh_da; 1741 const u8 *mesh_da;
1643 1742
1644 rcu_read_lock(); 1743 rcu_read_lock();
1645 if (is_multicast_ether_addr(skb->data)) 1744 if (is_multicast_ether_addr(skb->data))
1646 /* DA TA mSA AE:SA */ 1745 /* DA TA mSA AE:SA */
1647 mesh_da = skb->data; 1746 mesh_da = skb->data;
1648 else { 1747 else {
1748 static const u8 bcast[ETH_ALEN] =
1749 { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
1750
1649 mppath = mpp_path_lookup(skb->data, sdata); 1751 mppath = mpp_path_lookup(skb->data, sdata);
1650 if (mppath) { 1752 if (mppath) {
1651 /* RA TA mDA mSA AE:DA SA */ 1753 /* RA TA mDA mSA AE:DA SA */
1652 mesh_da = mppath->mpp; 1754 mesh_da = mppath->mpp;
1653 is_mesh_mcast = 0; 1755 is_mesh_mcast = 0;
1654 } else 1756 } else {
1655 /* DA TA mSA AE:SA */ 1757 /* DA TA mSA AE:SA */
1656 mesh_da = dev->broadcast; 1758 mesh_da = bcast;
1759 }
1657 } 1760 }
1658 hdrlen = ieee80211_fill_mesh_addresses(&hdr, &fc, 1761 hdrlen = ieee80211_fill_mesh_addresses(&hdr, &fc,
1659 mesh_da, dev->dev_addr); 1762 mesh_da, sdata->vif.addr);
1660 rcu_read_unlock(); 1763 rcu_read_unlock();
1661 if (is_mesh_mcast) 1764 if (is_mesh_mcast)
1662 meshhdrlen = 1765 meshhdrlen =
@@ -1677,12 +1780,21 @@ netdev_tx_t ieee80211_subif_start_xmit(struct sk_buff *skb,
1677 break; 1780 break;
1678#endif 1781#endif
1679 case NL80211_IFTYPE_STATION: 1782 case NL80211_IFTYPE_STATION:
1680 fc |= cpu_to_le16(IEEE80211_FCTL_TODS);
1681 /* BSSID SA DA */
1682 memcpy(hdr.addr1, sdata->u.mgd.bssid, ETH_ALEN); 1783 memcpy(hdr.addr1, sdata->u.mgd.bssid, ETH_ALEN);
1683 memcpy(hdr.addr2, skb->data + ETH_ALEN, ETH_ALEN); 1784 if (sdata->u.mgd.use_4addr && ethertype != ETH_P_PAE) {
1684 memcpy(hdr.addr3, skb->data, ETH_ALEN); 1785 fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS);
1685 hdrlen = 24; 1786 /* RA TA DA SA */
1787 memcpy(hdr.addr2, sdata->vif.addr, ETH_ALEN);
1788 memcpy(hdr.addr3, skb->data, ETH_ALEN);
1789 memcpy(hdr.addr4, skb->data + ETH_ALEN, ETH_ALEN);
1790 hdrlen = 30;
1791 } else {
1792 fc |= cpu_to_le16(IEEE80211_FCTL_TODS);
1793 /* BSSID SA DA */
1794 memcpy(hdr.addr2, skb->data + ETH_ALEN, ETH_ALEN);
1795 memcpy(hdr.addr3, skb->data, ETH_ALEN);
1796 hdrlen = 24;
1797 }
1686 break; 1798 break;
1687 case NL80211_IFTYPE_ADHOC: 1799 case NL80211_IFTYPE_ADHOC:
1688 /* DA SA BSSID */ 1800 /* DA SA BSSID */
@@ -1703,9 +1815,8 @@ netdev_tx_t ieee80211_subif_start_xmit(struct sk_buff *skb,
1703 */ 1815 */
1704 if (!is_multicast_ether_addr(hdr.addr1)) { 1816 if (!is_multicast_ether_addr(hdr.addr1)) {
1705 rcu_read_lock(); 1817 rcu_read_lock();
1706 sta = sta_info_get(local, hdr.addr1); 1818 sta = sta_info_get(sdata, hdr.addr1);
1707 /* XXX: in the future, use sdata to look up the sta */ 1819 if (sta)
1708 if (sta && sta->sdata == sdata)
1709 sta_flags = get_sta_flags(sta); 1820 sta_flags = get_sta_flags(sta);
1710 rcu_read_unlock(); 1821 rcu_read_unlock();
1711 } 1822 }
@@ -1724,7 +1835,7 @@ netdev_tx_t ieee80211_subif_start_xmit(struct sk_buff *skb,
1724 unlikely(!is_multicast_ether_addr(hdr.addr1) && 1835 unlikely(!is_multicast_ether_addr(hdr.addr1) &&
1725 !(sta_flags & WLAN_STA_AUTHORIZED) && 1836 !(sta_flags & WLAN_STA_AUTHORIZED) &&
1726 !(ethertype == ETH_P_PAE && 1837 !(ethertype == ETH_P_PAE &&
1727 compare_ether_addr(dev->dev_addr, 1838 compare_ether_addr(sdata->vif.addr,
1728 skb->data + ETH_ALEN) == 0))) { 1839 skb->data + ETH_ALEN) == 0))) {
1729#ifdef CONFIG_MAC80211_VERBOSE_DEBUG 1840#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
1730 if (net_ratelimit()) 1841 if (net_ratelimit())
@@ -1864,7 +1975,7 @@ static bool ieee80211_tx_pending_skb(struct ieee80211_local *local,
1864 ieee80211_tx(sdata, skb, true); 1975 ieee80211_tx(sdata, skb, true);
1865 } else { 1976 } else {
1866 hdr = (struct ieee80211_hdr *)skb->data; 1977 hdr = (struct ieee80211_hdr *)skb->data;
1867 sta = sta_info_get(local, hdr->addr1); 1978 sta = sta_info_get(sdata, hdr->addr1);
1868 1979
1869 ret = __ieee80211_tx(local, &skb, sta, true); 1980 ret = __ieee80211_tx(local, &skb, sta, true);
1870 if (ret != IEEE80211_TX_OK) 1981 if (ret != IEEE80211_TX_OK)
@@ -1880,6 +1991,7 @@ static bool ieee80211_tx_pending_skb(struct ieee80211_local *local,
1880void ieee80211_tx_pending(unsigned long data) 1991void ieee80211_tx_pending(unsigned long data)
1881{ 1992{
1882 struct ieee80211_local *local = (struct ieee80211_local *)data; 1993 struct ieee80211_local *local = (struct ieee80211_local *)data;
1994 struct ieee80211_sub_if_data *sdata;
1883 unsigned long flags; 1995 unsigned long flags;
1884 int i; 1996 int i;
1885 bool txok; 1997 bool txok;
@@ -1907,12 +2019,10 @@ void ieee80211_tx_pending(unsigned long data)
1907 } 2019 }
1908 2020
1909 sdata = vif_to_sdata(info->control.vif); 2021 sdata = vif_to_sdata(info->control.vif);
1910 dev_hold(sdata->dev);
1911 spin_unlock_irqrestore(&local->queue_stop_reason_lock, 2022 spin_unlock_irqrestore(&local->queue_stop_reason_lock,
1912 flags); 2023 flags);
1913 2024
1914 txok = ieee80211_tx_pending_skb(local, skb); 2025 txok = ieee80211_tx_pending_skb(local, skb);
1915 dev_put(sdata->dev);
1916 if (!txok) 2026 if (!txok)
1917 __skb_queue_head(&local->pending[i], skb); 2027 __skb_queue_head(&local->pending[i], skb);
1918 spin_lock_irqsave(&local->queue_stop_reason_lock, 2028 spin_lock_irqsave(&local->queue_stop_reason_lock,
@@ -1920,6 +2030,11 @@ void ieee80211_tx_pending(unsigned long data)
1920 if (!txok) 2030 if (!txok)
1921 break; 2031 break;
1922 } 2032 }
2033
2034 if (skb_queue_empty(&local->pending[i]))
2035 list_for_each_entry_rcu(sdata, &local->interfaces, list)
2036 netif_tx_wake_queue(
2037 netdev_get_tx_queue(sdata->dev, i));
1923 } 2038 }
1924 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags); 2039 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
1925 2040
@@ -1990,8 +2105,9 @@ static void ieee80211_beacon_add_tim(struct ieee80211_if_ap *bss,
1990 } 2105 }
1991} 2106}
1992 2107
1993struct sk_buff *ieee80211_beacon_get(struct ieee80211_hw *hw, 2108struct sk_buff *ieee80211_beacon_get_tim(struct ieee80211_hw *hw,
1994 struct ieee80211_vif *vif) 2109 struct ieee80211_vif *vif,
2110 u16 *tim_offset, u16 *tim_length)
1995{ 2111{
1996 struct ieee80211_local *local = hw_to_local(hw); 2112 struct ieee80211_local *local = hw_to_local(hw);
1997 struct sk_buff *skb = NULL; 2113 struct sk_buff *skb = NULL;
@@ -2001,6 +2117,7 @@ struct sk_buff *ieee80211_beacon_get(struct ieee80211_hw *hw,
2001 struct beacon_data *beacon; 2117 struct beacon_data *beacon;
2002 struct ieee80211_supported_band *sband; 2118 struct ieee80211_supported_band *sband;
2003 enum ieee80211_band band = local->hw.conf.channel->band; 2119 enum ieee80211_band band = local->hw.conf.channel->band;
2120 struct ieee80211_tx_rate_control txrc;
2004 2121
2005 sband = local->hw.wiphy->bands[band]; 2122 sband = local->hw.wiphy->bands[band];
2006 2123
@@ -2008,6 +2125,11 @@ struct sk_buff *ieee80211_beacon_get(struct ieee80211_hw *hw,
2008 2125
2009 sdata = vif_to_sdata(vif); 2126 sdata = vif_to_sdata(vif);
2010 2127
2128 if (tim_offset)
2129 *tim_offset = 0;
2130 if (tim_length)
2131 *tim_length = 0;
2132
2011 if (sdata->vif.type == NL80211_IFTYPE_AP) { 2133 if (sdata->vif.type == NL80211_IFTYPE_AP) {
2012 ap = &sdata->u.ap; 2134 ap = &sdata->u.ap;
2013 beacon = rcu_dereference(ap->beacon); 2135 beacon = rcu_dereference(ap->beacon);
@@ -2043,6 +2165,11 @@ struct sk_buff *ieee80211_beacon_get(struct ieee80211_hw *hw,
2043 spin_unlock_irqrestore(&local->sta_lock, flags); 2165 spin_unlock_irqrestore(&local->sta_lock, flags);
2044 } 2166 }
2045 2167
2168 if (tim_offset)
2169 *tim_offset = beacon->head_len;
2170 if (tim_length)
2171 *tim_length = skb->len - beacon->head_len;
2172
2046 if (beacon->tail) 2173 if (beacon->tail)
2047 memcpy(skb_put(skb, beacon->tail_len), 2174 memcpy(skb_put(skb, beacon->tail_len),
2048 beacon->tail, beacon->tail_len); 2175 beacon->tail, beacon->tail_len);
@@ -2079,8 +2206,8 @@ struct sk_buff *ieee80211_beacon_get(struct ieee80211_hw *hw,
2079 mgmt->frame_control = 2206 mgmt->frame_control =
2080 cpu_to_le16(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_BEACON); 2207 cpu_to_le16(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_BEACON);
2081 memset(mgmt->da, 0xff, ETH_ALEN); 2208 memset(mgmt->da, 0xff, ETH_ALEN);
2082 memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN); 2209 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
2083 /* BSSID is left zeroed, wildcard value */ 2210 memcpy(mgmt->bssid, sdata->vif.addr, ETH_ALEN);
2084 mgmt->u.beacon.beacon_int = 2211 mgmt->u.beacon.beacon_int =
2085 cpu_to_le16(sdata->vif.bss_conf.beacon_int); 2212 cpu_to_le16(sdata->vif.bss_conf.beacon_int);
2086 mgmt->u.beacon.capab_info = 0x0; /* 0x0 for MPs */ 2213 mgmt->u.beacon.capab_info = 0x0; /* 0x0 for MPs */
@@ -2098,28 +2225,160 @@ struct sk_buff *ieee80211_beacon_get(struct ieee80211_hw *hw,
2098 info = IEEE80211_SKB_CB(skb); 2225 info = IEEE80211_SKB_CB(skb);
2099 2226
2100 info->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT; 2227 info->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
2228 info->flags |= IEEE80211_TX_CTL_NO_ACK;
2101 info->band = band; 2229 info->band = band;
2102 /* 2230
2103 * XXX: For now, always use the lowest rate 2231 memset(&txrc, 0, sizeof(txrc));
2104 */ 2232 txrc.hw = hw;
2105 info->control.rates[0].idx = 0; 2233 txrc.sband = sband;
2106 info->control.rates[0].count = 1; 2234 txrc.bss_conf = &sdata->vif.bss_conf;
2107 info->control.rates[1].idx = -1; 2235 txrc.skb = skb;
2108 info->control.rates[2].idx = -1; 2236 txrc.reported_rate.idx = -1;
2109 info->control.rates[3].idx = -1; 2237 txrc.rate_idx_mask = sdata->rc_rateidx_mask[band];
2110 info->control.rates[4].idx = -1; 2238 if (txrc.rate_idx_mask == (1 << sband->n_bitrates) - 1)
2111 BUILD_BUG_ON(IEEE80211_TX_MAX_RATES != 5); 2239 txrc.max_rate_idx = -1;
2240 else
2241 txrc.max_rate_idx = fls(txrc.rate_idx_mask) - 1;
2242 txrc.ap = true;
2243 rate_control_get_rate(sdata, NULL, &txrc);
2112 2244
2113 info->control.vif = vif; 2245 info->control.vif = vif;
2114 2246
2115 info->flags |= IEEE80211_TX_CTL_NO_ACK;
2116 info->flags |= IEEE80211_TX_CTL_CLEAR_PS_FILT; 2247 info->flags |= IEEE80211_TX_CTL_CLEAR_PS_FILT;
2117 info->flags |= IEEE80211_TX_CTL_ASSIGN_SEQ; 2248 info->flags |= IEEE80211_TX_CTL_ASSIGN_SEQ;
2118 out: 2249 out:
2119 rcu_read_unlock(); 2250 rcu_read_unlock();
2120 return skb; 2251 return skb;
2121} 2252}
2122EXPORT_SYMBOL(ieee80211_beacon_get); 2253EXPORT_SYMBOL(ieee80211_beacon_get_tim);
2254
2255struct sk_buff *ieee80211_pspoll_get(struct ieee80211_hw *hw,
2256 struct ieee80211_vif *vif)
2257{
2258 struct ieee80211_sub_if_data *sdata;
2259 struct ieee80211_if_managed *ifmgd;
2260 struct ieee80211_pspoll *pspoll;
2261 struct ieee80211_local *local;
2262 struct sk_buff *skb;
2263
2264 if (WARN_ON(vif->type != NL80211_IFTYPE_STATION))
2265 return NULL;
2266
2267 sdata = vif_to_sdata(vif);
2268 ifmgd = &sdata->u.mgd;
2269 local = sdata->local;
2270
2271 skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*pspoll));
2272 if (!skb) {
2273 printk(KERN_DEBUG "%s: failed to allocate buffer for "
2274 "pspoll template\n", sdata->name);
2275 return NULL;
2276 }
2277 skb_reserve(skb, local->hw.extra_tx_headroom);
2278
2279 pspoll = (struct ieee80211_pspoll *) skb_put(skb, sizeof(*pspoll));
2280 memset(pspoll, 0, sizeof(*pspoll));
2281 pspoll->frame_control = cpu_to_le16(IEEE80211_FTYPE_CTL |
2282 IEEE80211_STYPE_PSPOLL);
2283 pspoll->aid = cpu_to_le16(ifmgd->aid);
2284
2285 /* aid in PS-Poll has its two MSBs each set to 1 */
2286 pspoll->aid |= cpu_to_le16(1 << 15 | 1 << 14);
2287
2288 memcpy(pspoll->bssid, ifmgd->bssid, ETH_ALEN);
2289 memcpy(pspoll->ta, vif->addr, ETH_ALEN);
2290
2291 return skb;
2292}
2293EXPORT_SYMBOL(ieee80211_pspoll_get);
2294
2295struct sk_buff *ieee80211_nullfunc_get(struct ieee80211_hw *hw,
2296 struct ieee80211_vif *vif)
2297{
2298 struct ieee80211_hdr_3addr *nullfunc;
2299 struct ieee80211_sub_if_data *sdata;
2300 struct ieee80211_if_managed *ifmgd;
2301 struct ieee80211_local *local;
2302 struct sk_buff *skb;
2303
2304 if (WARN_ON(vif->type != NL80211_IFTYPE_STATION))
2305 return NULL;
2306
2307 sdata = vif_to_sdata(vif);
2308 ifmgd = &sdata->u.mgd;
2309 local = sdata->local;
2310
2311 skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*nullfunc));
2312 if (!skb) {
2313 printk(KERN_DEBUG "%s: failed to allocate buffer for nullfunc "
2314 "template\n", sdata->name);
2315 return NULL;
2316 }
2317 skb_reserve(skb, local->hw.extra_tx_headroom);
2318
2319 nullfunc = (struct ieee80211_hdr_3addr *) skb_put(skb,
2320 sizeof(*nullfunc));
2321 memset(nullfunc, 0, sizeof(*nullfunc));
2322 nullfunc->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
2323 IEEE80211_STYPE_NULLFUNC |
2324 IEEE80211_FCTL_TODS);
2325 memcpy(nullfunc->addr1, ifmgd->bssid, ETH_ALEN);
2326 memcpy(nullfunc->addr2, vif->addr, ETH_ALEN);
2327 memcpy(nullfunc->addr3, ifmgd->bssid, ETH_ALEN);
2328
2329 return skb;
2330}
2331EXPORT_SYMBOL(ieee80211_nullfunc_get);
2332
2333struct sk_buff *ieee80211_probereq_get(struct ieee80211_hw *hw,
2334 struct ieee80211_vif *vif,
2335 const u8 *ssid, size_t ssid_len,
2336 const u8 *ie, size_t ie_len)
2337{
2338 struct ieee80211_sub_if_data *sdata;
2339 struct ieee80211_local *local;
2340 struct ieee80211_hdr_3addr *hdr;
2341 struct sk_buff *skb;
2342 size_t ie_ssid_len;
2343 u8 *pos;
2344
2345 sdata = vif_to_sdata(vif);
2346 local = sdata->local;
2347 ie_ssid_len = 2 + ssid_len;
2348
2349 skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*hdr) +
2350 ie_ssid_len + ie_len);
2351 if (!skb) {
2352 printk(KERN_DEBUG "%s: failed to allocate buffer for probe "
2353 "request template\n", sdata->name);
2354 return NULL;
2355 }
2356
2357 skb_reserve(skb, local->hw.extra_tx_headroom);
2358
2359 hdr = (struct ieee80211_hdr_3addr *) skb_put(skb, sizeof(*hdr));
2360 memset(hdr, 0, sizeof(*hdr));
2361 hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
2362 IEEE80211_STYPE_PROBE_REQ);
2363 memset(hdr->addr1, 0xff, ETH_ALEN);
2364 memcpy(hdr->addr2, vif->addr, ETH_ALEN);
2365 memset(hdr->addr3, 0xff, ETH_ALEN);
2366
2367 pos = skb_put(skb, ie_ssid_len);
2368 *pos++ = WLAN_EID_SSID;
2369 *pos++ = ssid_len;
2370 if (ssid)
2371 memcpy(pos, ssid, ssid_len);
2372 pos += ssid_len;
2373
2374 if (ie) {
2375 pos = skb_put(skb, ie_len);
2376 memcpy(pos, ie, ie_len);
2377 }
2378
2379 return skb;
2380}
2381EXPORT_SYMBOL(ieee80211_probereq_get);
2123 2382
2124void ieee80211_rts_get(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 2383void ieee80211_rts_get(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
2125 const void *frame, size_t frame_len, 2384 const void *frame, size_t frame_len,
@@ -2214,16 +2473,14 @@ ieee80211_get_buffered_bc(struct ieee80211_hw *hw,
2214} 2473}
2215EXPORT_SYMBOL(ieee80211_get_buffered_bc); 2474EXPORT_SYMBOL(ieee80211_get_buffered_bc);
2216 2475
2217void ieee80211_tx_skb(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb, 2476void ieee80211_tx_skb(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb)
2218 int encrypt)
2219{ 2477{
2220 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
2221 skb_set_mac_header(skb, 0); 2478 skb_set_mac_header(skb, 0);
2222 skb_set_network_header(skb, 0); 2479 skb_set_network_header(skb, 0);
2223 skb_set_transport_header(skb, 0); 2480 skb_set_transport_header(skb, 0);
2224 2481
2225 if (!encrypt) 2482 /* send all internal mgmt frames on VO */
2226 info->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT; 2483 skb_set_queue_mapping(skb, 0);
2227 2484
2228 /* 2485 /*
2229 * The other path calling ieee80211_xmit is from the tasklet, 2486 * The other path calling ieee80211_xmit is from the tasklet,
diff --git a/net/mac80211/util.c b/net/mac80211/util.c
index e6c08da8da26..53af57047435 100644
--- a/net/mac80211/util.c
+++ b/net/mac80211/util.c
@@ -18,7 +18,6 @@
18#include <linux/skbuff.h> 18#include <linux/skbuff.h>
19#include <linux/etherdevice.h> 19#include <linux/etherdevice.h>
20#include <linux/if_arp.h> 20#include <linux/if_arp.h>
21#include <linux/wireless.h>
22#include <linux/bitmap.h> 21#include <linux/bitmap.h>
23#include <linux/crc32.h> 22#include <linux/crc32.h>
24#include <net/net_namespace.h> 23#include <net/net_namespace.h>
@@ -269,6 +268,7 @@ static void __ieee80211_wake_queue(struct ieee80211_hw *hw, int queue,
269 enum queue_stop_reason reason) 268 enum queue_stop_reason reason)
270{ 269{
271 struct ieee80211_local *local = hw_to_local(hw); 270 struct ieee80211_local *local = hw_to_local(hw);
271 struct ieee80211_sub_if_data *sdata;
272 272
273 if (WARN_ON(queue >= hw->queues)) 273 if (WARN_ON(queue >= hw->queues))
274 return; 274 return;
@@ -279,7 +279,12 @@ static void __ieee80211_wake_queue(struct ieee80211_hw *hw, int queue,
279 /* someone still has this queue stopped */ 279 /* someone still has this queue stopped */
280 return; 280 return;
281 281
282 if (!skb_queue_empty(&local->pending[queue])) 282 if (skb_queue_empty(&local->pending[queue])) {
283 rcu_read_lock();
284 list_for_each_entry_rcu(sdata, &local->interfaces, list)
285 netif_tx_wake_queue(netdev_get_tx_queue(sdata->dev, queue));
286 rcu_read_unlock();
287 } else
283 tasklet_schedule(&local->tx_pending_tasklet); 288 tasklet_schedule(&local->tx_pending_tasklet);
284} 289}
285 290
@@ -305,11 +310,17 @@ static void __ieee80211_stop_queue(struct ieee80211_hw *hw, int queue,
305 enum queue_stop_reason reason) 310 enum queue_stop_reason reason)
306{ 311{
307 struct ieee80211_local *local = hw_to_local(hw); 312 struct ieee80211_local *local = hw_to_local(hw);
313 struct ieee80211_sub_if_data *sdata;
308 314
309 if (WARN_ON(queue >= hw->queues)) 315 if (WARN_ON(queue >= hw->queues))
310 return; 316 return;
311 317
312 __set_bit(reason, &local->queue_stop_reasons[queue]); 318 __set_bit(reason, &local->queue_stop_reasons[queue]);
319
320 rcu_read_lock();
321 list_for_each_entry_rcu(sdata, &local->interfaces, list)
322 netif_tx_stop_queue(netdev_get_tx_queue(sdata->dev, queue));
323 rcu_read_unlock();
313} 324}
314 325
315void ieee80211_stop_queue_by_reason(struct ieee80211_hw *hw, int queue, 326void ieee80211_stop_queue_by_reason(struct ieee80211_hw *hw, int queue,
@@ -468,8 +479,8 @@ void ieee80211_iterate_active_interfaces(
468 case NL80211_IFTYPE_MESH_POINT: 479 case NL80211_IFTYPE_MESH_POINT:
469 break; 480 break;
470 } 481 }
471 if (netif_running(sdata->dev)) 482 if (ieee80211_sdata_running(sdata))
472 iterator(data, sdata->dev->dev_addr, 483 iterator(data, sdata->vif.addr,
473 &sdata->vif); 484 &sdata->vif);
474 } 485 }
475 486
@@ -502,8 +513,8 @@ void ieee80211_iterate_active_interfaces_atomic(
502 case NL80211_IFTYPE_MESH_POINT: 513 case NL80211_IFTYPE_MESH_POINT:
503 break; 514 break;
504 } 515 }
505 if (netif_running(sdata->dev)) 516 if (ieee80211_sdata_running(sdata))
506 iterator(data, sdata->dev->dev_addr, 517 iterator(data, sdata->vif.addr,
507 &sdata->vif); 518 &sdata->vif);
508 } 519 }
509 520
@@ -579,7 +590,7 @@ u32 ieee802_11_parse_elems_crc(u8 *start, size_t len,
579 if (elen > left) 590 if (elen > left)
580 break; 591 break;
581 592
582 if (calc_crc && id < 64 && (filter & BIT(id))) 593 if (calc_crc && id < 64 && (filter & (1ULL << id)))
583 crc = crc32_be(crc, pos - 2, elen + 2); 594 crc = crc32_be(crc, pos - 2, elen + 2);
584 595
585 switch (id) { 596 switch (id) {
@@ -666,8 +677,8 @@ u32 ieee802_11_parse_elems_crc(u8 *start, size_t len,
666 elems->mesh_id_len = elen; 677 elems->mesh_id_len = elen;
667 break; 678 break;
668 case WLAN_EID_MESH_CONFIG: 679 case WLAN_EID_MESH_CONFIG:
669 elems->mesh_config = pos; 680 if (elen >= sizeof(struct ieee80211_meshconf_ie))
670 elems->mesh_config_len = elen; 681 elems->mesh_config = (void *)pos;
671 break; 682 break;
672 case WLAN_EID_PEER_LINK: 683 case WLAN_EID_PEER_LINK:
673 elems->peer_link = pos; 684 elems->peer_link = pos;
@@ -685,6 +696,10 @@ u32 ieee802_11_parse_elems_crc(u8 *start, size_t len,
685 elems->perr = pos; 696 elems->perr = pos;
686 elems->perr_len = elen; 697 elems->perr_len = elen;
687 break; 698 break;
699 case WLAN_EID_RANN:
700 if (elen >= sizeof(struct ieee80211_rann_ie))
701 elems->rann = (void *)pos;
702 break;
688 case WLAN_EID_CHANNEL_SWITCH: 703 case WLAN_EID_CHANNEL_SWITCH:
689 elems->ch_switch_elem = pos; 704 elems->ch_switch_elem = pos;
690 elems->ch_switch_elem_len = elen; 705 elems->ch_switch_elem_len = elen;
@@ -777,6 +792,8 @@ void ieee80211_set_wmm_default(struct ieee80211_sub_if_data *sdata)
777 break; 792 break;
778 } 793 }
779 794
795 qparam.uapsd = false;
796
780 drv_conf_tx(local, queue, &qparam); 797 drv_conf_tx(local, queue, &qparam);
781 } 798 }
782} 799}
@@ -844,7 +861,7 @@ void ieee80211_send_auth(struct ieee80211_sub_if_data *sdata,
844 sizeof(*mgmt) + 6 + extra_len); 861 sizeof(*mgmt) + 6 + extra_len);
845 if (!skb) { 862 if (!skb) {
846 printk(KERN_DEBUG "%s: failed to allocate buffer for auth " 863 printk(KERN_DEBUG "%s: failed to allocate buffer for auth "
847 "frame\n", sdata->dev->name); 864 "frame\n", sdata->name);
848 return; 865 return;
849 } 866 }
850 skb_reserve(skb, local->hw.extra_tx_headroom); 867 skb_reserve(skb, local->hw.extra_tx_headroom);
@@ -854,7 +871,7 @@ void ieee80211_send_auth(struct ieee80211_sub_if_data *sdata,
854 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | 871 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
855 IEEE80211_STYPE_AUTH); 872 IEEE80211_STYPE_AUTH);
856 memcpy(mgmt->da, bssid, ETH_ALEN); 873 memcpy(mgmt->da, bssid, ETH_ALEN);
857 memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN); 874 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
858 memcpy(mgmt->bssid, bssid, ETH_ALEN); 875 memcpy(mgmt->bssid, bssid, ETH_ALEN);
859 mgmt->u.auth.auth_alg = cpu_to_le16(auth_alg); 876 mgmt->u.auth.auth_alg = cpu_to_le16(auth_alg);
860 mgmt->u.auth.auth_transaction = cpu_to_le16(transaction); 877 mgmt->u.auth.auth_transaction = cpu_to_le16(transaction);
@@ -868,50 +885,96 @@ void ieee80211_send_auth(struct ieee80211_sub_if_data *sdata,
868 WARN_ON(err); 885 WARN_ON(err);
869 } 886 }
870 887
871 ieee80211_tx_skb(sdata, skb, 0); 888 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
889 ieee80211_tx_skb(sdata, skb);
872} 890}
873 891
874int ieee80211_build_preq_ies(struct ieee80211_local *local, u8 *buffer, 892int ieee80211_build_preq_ies(struct ieee80211_local *local, u8 *buffer,
875 const u8 *ie, size_t ie_len) 893 const u8 *ie, size_t ie_len,
894 enum ieee80211_band band)
876{ 895{
877 struct ieee80211_supported_band *sband; 896 struct ieee80211_supported_band *sband;
878 u8 *pos, *supp_rates_len, *esupp_rates_len = NULL; 897 u8 *pos;
879 int i; 898 size_t offset = 0, noffset;
899 int supp_rates_len, i;
880 900
881 sband = local->hw.wiphy->bands[local->hw.conf.channel->band]; 901 sband = local->hw.wiphy->bands[band];
882 902
883 pos = buffer; 903 pos = buffer;
884 904
905 supp_rates_len = min_t(int, sband->n_bitrates, 8);
906
885 *pos++ = WLAN_EID_SUPP_RATES; 907 *pos++ = WLAN_EID_SUPP_RATES;
886 supp_rates_len = pos; 908 *pos++ = supp_rates_len;
887 *pos++ = 0;
888
889 for (i = 0; i < sband->n_bitrates; i++) {
890 struct ieee80211_rate *rate = &sband->bitrates[i];
891
892 if (esupp_rates_len) {
893 *esupp_rates_len += 1;
894 } else if (*supp_rates_len == 8) {
895 *pos++ = WLAN_EID_EXT_SUPP_RATES;
896 esupp_rates_len = pos;
897 *pos++ = 1;
898 } else
899 *supp_rates_len += 1;
900 909
901 *pos++ = rate->bitrate / 5; 910 for (i = 0; i < supp_rates_len; i++) {
911 int rate = sband->bitrates[i].bitrate;
912 *pos++ = (u8) (rate / 5);
913 }
914
915 /* insert "request information" if in custom IEs */
916 if (ie && ie_len) {
917 static const u8 before_extrates[] = {
918 WLAN_EID_SSID,
919 WLAN_EID_SUPP_RATES,
920 WLAN_EID_REQUEST,
921 };
922 noffset = ieee80211_ie_split(ie, ie_len,
923 before_extrates,
924 ARRAY_SIZE(before_extrates),
925 offset);
926 memcpy(pos, ie + offset, noffset - offset);
927 pos += noffset - offset;
928 offset = noffset;
929 }
930
931 if (sband->n_bitrates > i) {
932 *pos++ = WLAN_EID_EXT_SUPP_RATES;
933 *pos++ = sband->n_bitrates - i;
934
935 for (; i < sband->n_bitrates; i++) {
936 int rate = sband->bitrates[i].bitrate;
937 *pos++ = (u8) (rate / 5);
938 }
939 }
940
941 /* insert custom IEs that go before HT */
942 if (ie && ie_len) {
943 static const u8 before_ht[] = {
944 WLAN_EID_SSID,
945 WLAN_EID_SUPP_RATES,
946 WLAN_EID_REQUEST,
947 WLAN_EID_EXT_SUPP_RATES,
948 WLAN_EID_DS_PARAMS,
949 WLAN_EID_SUPPORTED_REGULATORY_CLASSES,
950 };
951 noffset = ieee80211_ie_split(ie, ie_len,
952 before_ht, ARRAY_SIZE(before_ht),
953 offset);
954 memcpy(pos, ie + offset, noffset - offset);
955 pos += noffset - offset;
956 offset = noffset;
902 } 957 }
903 958
904 if (sband->ht_cap.ht_supported) { 959 if (sband->ht_cap.ht_supported) {
905 __le16 tmp = cpu_to_le16(sband->ht_cap.cap); 960 u16 cap = sband->ht_cap.cap;
961 __le16 tmp;
962
963 if (ieee80211_disable_40mhz_24ghz &&
964 sband->band == IEEE80211_BAND_2GHZ) {
965 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
966 cap &= ~IEEE80211_HT_CAP_SGI_40;
967 }
906 968
907 *pos++ = WLAN_EID_HT_CAPABILITY; 969 *pos++ = WLAN_EID_HT_CAPABILITY;
908 *pos++ = sizeof(struct ieee80211_ht_cap); 970 *pos++ = sizeof(struct ieee80211_ht_cap);
909 memset(pos, 0, sizeof(struct ieee80211_ht_cap)); 971 memset(pos, 0, sizeof(struct ieee80211_ht_cap));
972 tmp = cpu_to_le16(cap);
910 memcpy(pos, &tmp, sizeof(u16)); 973 memcpy(pos, &tmp, sizeof(u16));
911 pos += sizeof(u16); 974 pos += sizeof(u16);
912 /* TODO: needs a define here for << 2 */
913 *pos++ = sband->ht_cap.ampdu_factor | 975 *pos++ = sband->ht_cap.ampdu_factor |
914 (sband->ht_cap.ampdu_density << 2); 976 (sband->ht_cap.ampdu_density <<
977 IEEE80211_HT_AMPDU_PARM_DENSITY_SHIFT);
915 memcpy(pos, &sband->ht_cap.mcs, sizeof(sband->ht_cap.mcs)); 978 memcpy(pos, &sband->ht_cap.mcs, sizeof(sband->ht_cap.mcs));
916 pos += sizeof(sband->ht_cap.mcs); 979 pos += sizeof(sband->ht_cap.mcs);
917 pos += 2 + 4 + 1; /* ext info, BF cap, antsel */ 980 pos += 2 + 4 + 1; /* ext info, BF cap, antsel */
@@ -922,9 +985,11 @@ int ieee80211_build_preq_ies(struct ieee80211_local *local, u8 *buffer,
922 * that calculates local->scan_ies_len. 985 * that calculates local->scan_ies_len.
923 */ 986 */
924 987
925 if (ie) { 988 /* add any remaining custom IEs */
926 memcpy(pos, ie, ie_len); 989 if (ie && ie_len) {
927 pos += ie_len; 990 noffset = ie_len;
991 memcpy(pos, ie + offset, noffset - offset);
992 pos += noffset - offset;
928 } 993 }
929 994
930 return pos - buffer; 995 return pos - buffer;
@@ -937,38 +1002,33 @@ void ieee80211_send_probe_req(struct ieee80211_sub_if_data *sdata, u8 *dst,
937 struct ieee80211_local *local = sdata->local; 1002 struct ieee80211_local *local = sdata->local;
938 struct sk_buff *skb; 1003 struct sk_buff *skb;
939 struct ieee80211_mgmt *mgmt; 1004 struct ieee80211_mgmt *mgmt;
940 u8 *pos; 1005 size_t buf_len;
941 1006 u8 *buf;
942 skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*mgmt) + 200 + 1007
943 ie_len); 1008 /* FIXME: come up with a proper value */
944 if (!skb) { 1009 buf = kmalloc(200 + ie_len, GFP_KERNEL);
945 printk(KERN_DEBUG "%s: failed to allocate buffer for probe " 1010 if (!buf) {
946 "request\n", sdata->dev->name); 1011 printk(KERN_DEBUG "%s: failed to allocate temporary IE "
1012 "buffer\n", sdata->name);
947 return; 1013 return;
948 } 1014 }
949 skb_reserve(skb, local->hw.extra_tx_headroom);
950 1015
951 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24); 1016 buf_len = ieee80211_build_preq_ies(local, buf, ie, ie_len,
952 memset(mgmt, 0, 24); 1017 local->hw.conf.channel->band);
953 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | 1018
954 IEEE80211_STYPE_PROBE_REQ); 1019 skb = ieee80211_probereq_get(&local->hw, &sdata->vif,
955 memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN); 1020 ssid, ssid_len,
1021 buf, buf_len);
1022
956 if (dst) { 1023 if (dst) {
1024 mgmt = (struct ieee80211_mgmt *) skb->data;
957 memcpy(mgmt->da, dst, ETH_ALEN); 1025 memcpy(mgmt->da, dst, ETH_ALEN);
958 memcpy(mgmt->bssid, dst, ETH_ALEN); 1026 memcpy(mgmt->bssid, dst, ETH_ALEN);
959 } else {
960 memset(mgmt->da, 0xff, ETH_ALEN);
961 memset(mgmt->bssid, 0xff, ETH_ALEN);
962 } 1027 }
963 pos = skb_put(skb, 2 + ssid_len);
964 *pos++ = WLAN_EID_SSID;
965 *pos++ = ssid_len;
966 memcpy(pos, ssid, ssid_len);
967 pos += ssid_len;
968 1028
969 skb_put(skb, ieee80211_build_preq_ies(local, pos, ie, ie_len)); 1029 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
970 1030 ieee80211_tx_skb(sdata, skb);
971 ieee80211_tx_skb(sdata, skb, 0); 1031 kfree(buf);
972} 1032}
973 1033
974u32 ieee80211_sta_get_rates(struct ieee80211_local *local, 1034u32 ieee80211_sta_get_rates(struct ieee80211_local *local,
@@ -1012,18 +1072,16 @@ void ieee80211_stop_device(struct ieee80211_local *local)
1012 ieee80211_led_radio(local, false); 1072 ieee80211_led_radio(local, false);
1013 1073
1014 cancel_work_sync(&local->reconfig_filter); 1074 cancel_work_sync(&local->reconfig_filter);
1015 drv_stop(local);
1016 1075
1017 flush_workqueue(local->workqueue); 1076 flush_workqueue(local->workqueue);
1077 drv_stop(local);
1018} 1078}
1019 1079
1020int ieee80211_reconfig(struct ieee80211_local *local) 1080int ieee80211_reconfig(struct ieee80211_local *local)
1021{ 1081{
1022 struct ieee80211_hw *hw = &local->hw; 1082 struct ieee80211_hw *hw = &local->hw;
1023 struct ieee80211_sub_if_data *sdata; 1083 struct ieee80211_sub_if_data *sdata;
1024 struct ieee80211_if_init_conf conf;
1025 struct sta_info *sta; 1084 struct sta_info *sta;
1026 unsigned long flags;
1027 int res; 1085 int res;
1028 1086
1029 if (local->suspended) 1087 if (local->suspended)
@@ -1031,7 +1089,19 @@ int ieee80211_reconfig(struct ieee80211_local *local)
1031 1089
1032 /* restart hardware */ 1090 /* restart hardware */
1033 if (local->open_count) { 1091 if (local->open_count) {
1092 /*
1093 * Upon resume hardware can sometimes be goofy due to
1094 * various platform / driver / bus issues, so restarting
1095 * the device may at times not work immediately. Propagate
1096 * the error.
1097 */
1034 res = drv_start(local); 1098 res = drv_start(local);
1099 if (res) {
1100 WARN(local->suspended, "Hardware became unavailable "
1101 "upon resume. This could be a software issue "
1102 "prior to suspend or a hardware issue.\n");
1103 return res;
1104 }
1035 1105
1036 ieee80211_led_radio(local, true); 1106 ieee80211_led_radio(local, true);
1037 } 1107 }
@@ -1040,29 +1110,24 @@ int ieee80211_reconfig(struct ieee80211_local *local)
1040 list_for_each_entry(sdata, &local->interfaces, list) { 1110 list_for_each_entry(sdata, &local->interfaces, list) {
1041 if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN && 1111 if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
1042 sdata->vif.type != NL80211_IFTYPE_MONITOR && 1112 sdata->vif.type != NL80211_IFTYPE_MONITOR &&
1043 netif_running(sdata->dev)) { 1113 ieee80211_sdata_running(sdata))
1044 conf.vif = &sdata->vif; 1114 res = drv_add_interface(local, &sdata->vif);
1045 conf.type = sdata->vif.type;
1046 conf.mac_addr = sdata->dev->dev_addr;
1047 res = drv_add_interface(local, &conf);
1048 }
1049 } 1115 }
1050 1116
1051 /* add STAs back */ 1117 /* add STAs back */
1052 if (local->ops->sta_notify) { 1118 mutex_lock(&local->sta_mtx);
1053 spin_lock_irqsave(&local->sta_lock, flags); 1119 list_for_each_entry(sta, &local->sta_list, list) {
1054 list_for_each_entry(sta, &local->sta_list, list) { 1120 if (sta->uploaded) {
1055 sdata = sta->sdata; 1121 sdata = sta->sdata;
1056 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN) 1122 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
1057 sdata = container_of(sdata->bss, 1123 sdata = container_of(sdata->bss,
1058 struct ieee80211_sub_if_data, 1124 struct ieee80211_sub_if_data,
1059 u.ap); 1125 u.ap);
1060 1126
1061 drv_sta_notify(local, &sdata->vif, STA_NOTIFY_ADD, 1127 WARN_ON(drv_sta_add(local, sdata, &sta->sta));
1062 &sta->sta);
1063 } 1128 }
1064 spin_unlock_irqrestore(&local->sta_lock, flags);
1065 } 1129 }
1130 mutex_unlock(&local->sta_mtx);
1066 1131
1067 /* Clear Suspend state so that ADDBA requests can be processed */ 1132 /* Clear Suspend state so that ADDBA requests can be processed */
1068 1133
@@ -1087,7 +1152,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
1087 /* Finally also reconfigure all the BSS information */ 1152 /* Finally also reconfigure all the BSS information */
1088 list_for_each_entry(sdata, &local->interfaces, list) { 1153 list_for_each_entry(sdata, &local->interfaces, list) {
1089 u32 changed = ~0; 1154 u32 changed = ~0;
1090 if (!netif_running(sdata->dev)) 1155 if (!ieee80211_sdata_running(sdata))
1091 continue; 1156 continue;
1092 switch (sdata->vif.type) { 1157 switch (sdata->vif.type) {
1093 case NL80211_IFTYPE_STATION: 1158 case NL80211_IFTYPE_STATION:
@@ -1113,9 +1178,17 @@ int ieee80211_reconfig(struct ieee80211_local *local)
1113 } 1178 }
1114 } 1179 }
1115 1180
1181 rcu_read_lock();
1182 if (hw->flags & IEEE80211_HW_AMPDU_AGGREGATION) {
1183 list_for_each_entry_rcu(sta, &local->sta_list, list) {
1184 ieee80211_sta_tear_down_BA_sessions(sta);
1185 }
1186 }
1187 rcu_read_unlock();
1188
1116 /* add back keys */ 1189 /* add back keys */
1117 list_for_each_entry(sdata, &local->interfaces, list) 1190 list_for_each_entry(sdata, &local->interfaces, list)
1118 if (netif_running(sdata->dev)) 1191 if (ieee80211_sdata_running(sdata))
1119 ieee80211_enable_keys(sdata); 1192 ieee80211_enable_keys(sdata);
1120 1193
1121 ieee80211_wake_queues_by_reason(hw, 1194 ieee80211_wake_queues_by_reason(hw,
@@ -1152,13 +1225,143 @@ int ieee80211_reconfig(struct ieee80211_local *local)
1152 1225
1153 add_timer(&local->sta_cleanup); 1226 add_timer(&local->sta_cleanup);
1154 1227
1155 spin_lock_irqsave(&local->sta_lock, flags); 1228 mutex_lock(&local->sta_mtx);
1156 list_for_each_entry(sta, &local->sta_list, list) 1229 list_for_each_entry(sta, &local->sta_list, list)
1157 mesh_plink_restart(sta); 1230 mesh_plink_restart(sta);
1158 spin_unlock_irqrestore(&local->sta_lock, flags); 1231 mutex_unlock(&local->sta_mtx);
1159#else 1232#else
1160 WARN_ON(1); 1233 WARN_ON(1);
1161#endif 1234#endif
1162 return 0; 1235 return 0;
1163} 1236}
1164 1237
1238static int check_mgd_smps(struct ieee80211_if_managed *ifmgd,
1239 enum ieee80211_smps_mode *smps_mode)
1240{
1241 if (ifmgd->associated) {
1242 *smps_mode = ifmgd->ap_smps;
1243
1244 if (*smps_mode == IEEE80211_SMPS_AUTOMATIC) {
1245 if (ifmgd->powersave)
1246 *smps_mode = IEEE80211_SMPS_DYNAMIC;
1247 else
1248 *smps_mode = IEEE80211_SMPS_OFF;
1249 }
1250
1251 return 1;
1252 }
1253
1254 return 0;
1255}
1256
1257/* must hold iflist_mtx */
1258void ieee80211_recalc_smps(struct ieee80211_local *local,
1259 struct ieee80211_sub_if_data *forsdata)
1260{
1261 struct ieee80211_sub_if_data *sdata;
1262 enum ieee80211_smps_mode smps_mode = IEEE80211_SMPS_OFF;
1263 int count = 0;
1264
1265 if (forsdata)
1266 WARN_ON(!mutex_is_locked(&forsdata->u.mgd.mtx));
1267
1268 WARN_ON(!mutex_is_locked(&local->iflist_mtx));
1269
1270 /*
1271 * This function could be improved to handle multiple
1272 * interfaces better, but right now it makes any
1273 * non-station interfaces force SM PS to be turned
1274 * off. If there are multiple station interfaces it
1275 * could also use the best possible mode, e.g. if
1276 * one is in static and the other in dynamic then
1277 * dynamic is ok.
1278 */
1279
1280 list_for_each_entry(sdata, &local->interfaces, list) {
1281 if (!netif_running(sdata->dev))
1282 continue;
1283 if (sdata->vif.type != NL80211_IFTYPE_STATION)
1284 goto set;
1285 if (sdata != forsdata) {
1286 /*
1287 * This nested is ok -- we are holding the iflist_mtx
1288 * so can't get here twice or so. But it's required
1289 * since normally we acquire it first and then the
1290 * iflist_mtx.
1291 */
1292 mutex_lock_nested(&sdata->u.mgd.mtx, SINGLE_DEPTH_NESTING);
1293 count += check_mgd_smps(&sdata->u.mgd, &smps_mode);
1294 mutex_unlock(&sdata->u.mgd.mtx);
1295 } else
1296 count += check_mgd_smps(&sdata->u.mgd, &smps_mode);
1297
1298 if (count > 1) {
1299 smps_mode = IEEE80211_SMPS_OFF;
1300 break;
1301 }
1302 }
1303
1304 if (smps_mode == local->smps_mode)
1305 return;
1306
1307 set:
1308 local->smps_mode = smps_mode;
1309 /* changed flag is auto-detected for this */
1310 ieee80211_hw_config(local, 0);
1311}
1312
1313static bool ieee80211_id_in_list(const u8 *ids, int n_ids, u8 id)
1314{
1315 int i;
1316
1317 for (i = 0; i < n_ids; i++)
1318 if (ids[i] == id)
1319 return true;
1320 return false;
1321}
1322
1323/**
1324 * ieee80211_ie_split - split an IE buffer according to ordering
1325 *
1326 * @ies: the IE buffer
1327 * @ielen: the length of the IE buffer
1328 * @ids: an array with element IDs that are allowed before
1329 * the split
1330 * @n_ids: the size of the element ID array
1331 * @offset: offset where to start splitting in the buffer
1332 *
1333 * This function splits an IE buffer by updating the @offset
1334 * variable to point to the location where the buffer should be
1335 * split.
1336 *
1337 * It assumes that the given IE buffer is well-formed, this
1338 * has to be guaranteed by the caller!
1339 *
1340 * It also assumes that the IEs in the buffer are ordered
1341 * correctly, if not the result of using this function will not
1342 * be ordered correctly either, i.e. it does no reordering.
1343 *
1344 * The function returns the offset where the next part of the
1345 * buffer starts, which may be @ielen if the entire (remainder)
1346 * of the buffer should be used.
1347 */
1348size_t ieee80211_ie_split(const u8 *ies, size_t ielen,
1349 const u8 *ids, int n_ids, size_t offset)
1350{
1351 size_t pos = offset;
1352
1353 while (pos < ielen && ieee80211_id_in_list(ids, n_ids, ies[pos]))
1354 pos += 2 + ies[pos + 1];
1355
1356 return pos;
1357}
1358
1359size_t ieee80211_ie_split_vendor(const u8 *ies, size_t ielen, size_t offset)
1360{
1361 size_t pos = offset;
1362
1363 while (pos < ielen && ies[pos] != WLAN_EID_VENDOR_SPECIFIC)
1364 pos += 2 + ies[pos + 1];
1365
1366 return pos;
1367}
diff --git a/net/mac80211/wep.c b/net/mac80211/wep.c
index 8a980f136941..5f3a4113bda1 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 <linux/slab.h>
20#include <asm/unaligned.h> 21#include <asm/unaligned.h>
21 22
22#include <net/mac80211.h> 23#include <net/mac80211.h>
@@ -281,16 +282,18 @@ bool ieee80211_wep_is_weak_iv(struct sk_buff *skb, struct ieee80211_key *key)
281ieee80211_rx_result 282ieee80211_rx_result
282ieee80211_crypto_wep_decrypt(struct ieee80211_rx_data *rx) 283ieee80211_crypto_wep_decrypt(struct ieee80211_rx_data *rx)
283{ 284{
284 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data; 285 struct sk_buff *skb = rx->skb;
286 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
287 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
285 288
286 if (!ieee80211_is_data(hdr->frame_control) && 289 if (!ieee80211_is_data(hdr->frame_control) &&
287 !ieee80211_is_auth(hdr->frame_control)) 290 !ieee80211_is_auth(hdr->frame_control))
288 return RX_CONTINUE; 291 return RX_CONTINUE;
289 292
290 if (!(rx->status->flag & RX_FLAG_DECRYPTED)) { 293 if (!(status->flag & RX_FLAG_DECRYPTED)) {
291 if (ieee80211_wep_decrypt(rx->local, rx->skb, rx->key)) 294 if (ieee80211_wep_decrypt(rx->local, rx->skb, rx->key))
292 return RX_DROP_UNUSABLE; 295 return RX_DROP_UNUSABLE;
293 } else if (!(rx->status->flag & RX_FLAG_IV_STRIPPED)) { 296 } else if (!(status->flag & RX_FLAG_IV_STRIPPED)) {
294 ieee80211_wep_remove_iv(rx->local, rx->skb, rx->key); 297 ieee80211_wep_remove_iv(rx->local, rx->skb, rx->key);
295 /* remove ICV */ 298 /* remove ICV */
296 skb_trim(rx->skb, rx->skb->len - WEP_ICV_LEN); 299 skb_trim(rx->skb, rx->skb->len - WEP_ICV_LEN);
@@ -303,20 +306,19 @@ static int wep_encrypt_skb(struct ieee80211_tx_data *tx, struct sk_buff *skb)
303{ 306{
304 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); 307 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
305 308
306 if (!(tx->key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE)) { 309 if (!info->control.hw_key) {
307 if (ieee80211_wep_encrypt(tx->local, skb, tx->key->conf.key, 310 if (ieee80211_wep_encrypt(tx->local, skb, tx->key->conf.key,
308 tx->key->conf.keylen, 311 tx->key->conf.keylen,
309 tx->key->conf.keyidx)) 312 tx->key->conf.keyidx))
310 return -1; 313 return -1;
311 } else { 314 } else if (info->control.hw_key->flags &
312 info->control.hw_key = &tx->key->conf; 315 IEEE80211_KEY_FLAG_GENERATE_IV) {
313 if (tx->key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV) { 316 if (!ieee80211_wep_add_iv(tx->local, skb,
314 if (!ieee80211_wep_add_iv(tx->local, skb, 317 tx->key->conf.keylen,
315 tx->key->conf.keylen, 318 tx->key->conf.keyidx))
316 tx->key->conf.keyidx)) 319 return -1;
317 return -1;
318 }
319 } 320 }
321
320 return 0; 322 return 0;
321} 323}
322 324
diff --git a/net/mac80211/wme.c b/net/mac80211/wme.c
index b19b7696f3a2..34e6d02da779 100644
--- a/net/mac80211/wme.c
+++ b/net/mac80211/wme.c
@@ -44,22 +44,69 @@ static int wme_downgrade_ac(struct sk_buff *skb)
44} 44}
45 45
46 46
47/* Indicate which queue to use. */ 47/* Indicate which queue to use. */
48static u16 classify80211(struct ieee80211_local *local, struct sk_buff *skb) 48u16 ieee80211_select_queue(struct ieee80211_sub_if_data *sdata,
49 struct sk_buff *skb)
49{ 50{
50 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; 51 struct ieee80211_local *local = sdata->local;
52 struct sta_info *sta = NULL;
53 u32 sta_flags = 0;
54 const u8 *ra = NULL;
55 bool qos = false;
51 56
52 if (!ieee80211_is_data(hdr->frame_control)) { 57 if (local->hw.queues < 4 || skb->len < 6) {
53 /* management frames go on AC_VO queue, but are sent 58 skb->priority = 0; /* required for correct WPA/11i MIC */
54 * without QoS control fields */ 59 return min_t(u16, local->hw.queues - 1,
55 return 0; 60 ieee802_1d_to_ac[skb->priority]);
61 }
62
63 rcu_read_lock();
64 switch (sdata->vif.type) {
65 case NL80211_IFTYPE_AP_VLAN:
66 rcu_read_lock();
67 sta = rcu_dereference(sdata->u.vlan.sta);
68 if (sta)
69 sta_flags = get_sta_flags(sta);
70 rcu_read_unlock();
71 if (sta)
72 break;
73 case NL80211_IFTYPE_AP:
74 ra = skb->data;
75 break;
76 case NL80211_IFTYPE_WDS:
77 ra = sdata->u.wds.remote_addr;
78 break;
79#ifdef CONFIG_MAC80211_MESH
80 case NL80211_IFTYPE_MESH_POINT:
81 /*
82 * XXX: This is clearly broken ... but already was before,
83 * because ieee80211_fill_mesh_addresses() would clear A1
84 * except for multicast addresses.
85 */
86 break;
87#endif
88 case NL80211_IFTYPE_STATION:
89 ra = sdata->u.mgd.bssid;
90 break;
91 case NL80211_IFTYPE_ADHOC:
92 ra = skb->data;
93 break;
94 default:
95 break;
56 } 96 }
57 97
58 if (0 /* injected */) { 98 if (!sta && ra && !is_multicast_ether_addr(ra)) {
59 /* use AC from radiotap */ 99 sta = sta_info_get(sdata, ra);
100 if (sta)
101 sta_flags = get_sta_flags(sta);
60 } 102 }
61 103
62 if (!ieee80211_is_data_qos(hdr->frame_control)) { 104 if (sta_flags & WLAN_STA_WME)
105 qos = true;
106
107 rcu_read_unlock();
108
109 if (!qos) {
63 skb->priority = 0; /* required for correct WPA/11i MIC */ 110 skb->priority = 0; /* required for correct WPA/11i MIC */
64 return ieee802_1d_to_ac[skb->priority]; 111 return ieee802_1d_to_ac[skb->priority];
65 } 112 }
@@ -68,6 +115,12 @@ static u16 classify80211(struct ieee80211_local *local, struct sk_buff *skb)
68 * data frame has */ 115 * data frame has */
69 skb->priority = cfg80211_classify8021d(skb); 116 skb->priority = cfg80211_classify8021d(skb);
70 117
118 return ieee80211_downgrade_queue(local, skb);
119}
120
121u16 ieee80211_downgrade_queue(struct ieee80211_local *local,
122 struct sk_buff *skb)
123{
71 /* in case we are a client verify acm is not set for this ac */ 124 /* in case we are a client verify acm is not set for this ac */
72 while (unlikely(local->wmm_acm & BIT(skb->priority))) { 125 while (unlikely(local->wmm_acm & BIT(skb->priority))) {
73 if (wme_downgrade_ac(skb)) { 126 if (wme_downgrade_ac(skb)) {
@@ -85,24 +138,17 @@ static u16 classify80211(struct ieee80211_local *local, struct sk_buff *skb)
85 return ieee802_1d_to_ac[skb->priority]; 138 return ieee802_1d_to_ac[skb->priority];
86} 139}
87 140
88void ieee80211_select_queue(struct ieee80211_local *local, struct sk_buff *skb) 141void ieee80211_set_qos_hdr(struct ieee80211_local *local, struct sk_buff *skb)
89{ 142{
90 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; 143 struct ieee80211_hdr *hdr = (void *)skb->data;
91 u16 queue; 144
92 u8 tid; 145 /* Fill in the QoS header if there is one. */
93
94 queue = classify80211(local, skb);
95 if (unlikely(queue >= local->hw.queues))
96 queue = local->hw.queues - 1;
97
98 /*
99 * Now we know the 1d priority, fill in the QoS header if
100 * there is one (and we haven't done this before).
101 */
102 if (ieee80211_is_data_qos(hdr->frame_control)) { 146 if (ieee80211_is_data_qos(hdr->frame_control)) {
103 u8 *p = ieee80211_get_qos_ctl(hdr); 147 u8 *p = ieee80211_get_qos_ctl(hdr);
104 u8 ack_policy = 0; 148 u8 ack_policy = 0, tid;
149
105 tid = skb->priority & IEEE80211_QOS_CTL_TAG1D_MASK; 150 tid = skb->priority & IEEE80211_QOS_CTL_TAG1D_MASK;
151
106 if (unlikely(local->wifi_wme_noack_test)) 152 if (unlikely(local->wifi_wme_noack_test))
107 ack_policy |= QOS_CONTROL_ACK_POLICY_NOACK << 153 ack_policy |= QOS_CONTROL_ACK_POLICY_NOACK <<
108 QOS_CONTROL_ACK_POLICY_SHIFT; 154 QOS_CONTROL_ACK_POLICY_SHIFT;
@@ -110,6 +156,4 @@ void ieee80211_select_queue(struct ieee80211_local *local, struct sk_buff *skb)
110 *p++ = ack_policy | tid; 156 *p++ = ack_policy | tid;
111 *p = 0; 157 *p = 0;
112 } 158 }
113
114 skb_set_queue_mapping(skb, queue);
115} 159}
diff --git a/net/mac80211/wme.h b/net/mac80211/wme.h
index d4fd87ca5118..6053b1c9feee 100644
--- a/net/mac80211/wme.h
+++ b/net/mac80211/wme.h
@@ -20,7 +20,11 @@
20 20
21extern const int ieee802_1d_to_ac[8]; 21extern const int ieee802_1d_to_ac[8];
22 22
23void ieee80211_select_queue(struct ieee80211_local *local, 23u16 ieee80211_select_queue(struct ieee80211_sub_if_data *sdata,
24 struct sk_buff *skb); 24 struct sk_buff *skb);
25void ieee80211_set_qos_hdr(struct ieee80211_local *local, struct sk_buff *skb);
26u16 ieee80211_downgrade_queue(struct ieee80211_local *local,
27 struct sk_buff *skb);
28
25 29
26#endif /* _WME_H */ 30#endif /* _WME_H */
diff --git a/net/mac80211/work.c b/net/mac80211/work.c
new file mode 100644
index 000000000000..15e1ba931b87
--- /dev/null
+++ b/net/mac80211/work.c
@@ -0,0 +1,1101 @@
1/*
2 * mac80211 work implementation
3 *
4 * Copyright 2003-2008, Jouni Malinen <j@w1.fi>
5 * Copyright 2004, Instant802 Networks, Inc.
6 * Copyright 2005, Devicescape Software, Inc.
7 * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz>
8 * Copyright 2007, Michael Wu <flamingice@sourmilk.net>
9 * Copyright 2009, Johannes Berg <johannes@sipsolutions.net>
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
14 */
15
16#include <linux/delay.h>
17#include <linux/if_ether.h>
18#include <linux/skbuff.h>
19#include <linux/if_arp.h>
20#include <linux/etherdevice.h>
21#include <linux/crc32.h>
22#include <linux/slab.h>
23#include <net/mac80211.h>
24#include <asm/unaligned.h>
25
26#include "ieee80211_i.h"
27#include "rate.h"
28
29#define IEEE80211_AUTH_TIMEOUT (HZ / 5)
30#define IEEE80211_AUTH_MAX_TRIES 3
31#define IEEE80211_ASSOC_TIMEOUT (HZ / 5)
32#define IEEE80211_ASSOC_MAX_TRIES 3
33#define IEEE80211_MAX_PROBE_TRIES 5
34
35enum work_action {
36 WORK_ACT_NONE,
37 WORK_ACT_TIMEOUT,
38 WORK_ACT_DONE,
39};
40
41
42/* utils */
43static inline void ASSERT_WORK_MTX(struct ieee80211_local *local)
44{
45 WARN_ON(!mutex_is_locked(&local->work_mtx));
46}
47
48/*
49 * We can have multiple work items (and connection probing)
50 * scheduling this timer, but we need to take care to only
51 * reschedule it when it should fire _earlier_ than it was
52 * asked for before, or if it's not pending right now. This
53 * function ensures that. Note that it then is required to
54 * run this function for all timeouts after the first one
55 * has happened -- the work that runs from this timer will
56 * do that.
57 */
58static void run_again(struct ieee80211_local *local,
59 unsigned long timeout)
60{
61 ASSERT_WORK_MTX(local);
62
63 if (!timer_pending(&local->work_timer) ||
64 time_before(timeout, local->work_timer.expires))
65 mod_timer(&local->work_timer, timeout);
66}
67
68static void work_free_rcu(struct rcu_head *head)
69{
70 struct ieee80211_work *wk =
71 container_of(head, struct ieee80211_work, rcu_head);
72
73 kfree(wk);
74}
75
76void free_work(struct ieee80211_work *wk)
77{
78 call_rcu(&wk->rcu_head, work_free_rcu);
79}
80
81static int ieee80211_compatible_rates(const u8 *supp_rates, int supp_rates_len,
82 struct ieee80211_supported_band *sband,
83 u32 *rates)
84{
85 int i, j, count;
86 *rates = 0;
87 count = 0;
88 for (i = 0; i < supp_rates_len; i++) {
89 int rate = (supp_rates[i] & 0x7F) * 5;
90
91 for (j = 0; j < sband->n_bitrates; j++)
92 if (sband->bitrates[j].bitrate == rate) {
93 *rates |= BIT(j);
94 count++;
95 break;
96 }
97 }
98
99 return count;
100}
101
102/* frame sending functions */
103
104static void ieee80211_add_ht_ie(struct sk_buff *skb, const u8 *ht_info_ie,
105 struct ieee80211_supported_band *sband,
106 struct ieee80211_channel *channel,
107 enum ieee80211_smps_mode smps)
108{
109 struct ieee80211_ht_info *ht_info;
110 u8 *pos;
111 u32 flags = channel->flags;
112 u16 cap = sband->ht_cap.cap;
113 __le16 tmp;
114
115 if (!sband->ht_cap.ht_supported)
116 return;
117
118 if (!ht_info_ie)
119 return;
120
121 if (ht_info_ie[1] < sizeof(struct ieee80211_ht_info))
122 return;
123
124 ht_info = (struct ieee80211_ht_info *)(ht_info_ie + 2);
125
126 /* determine capability flags */
127
128 if (ieee80211_disable_40mhz_24ghz &&
129 sband->band == IEEE80211_BAND_2GHZ) {
130 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
131 cap &= ~IEEE80211_HT_CAP_SGI_40;
132 }
133
134 switch (ht_info->ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) {
135 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
136 if (flags & IEEE80211_CHAN_NO_HT40PLUS) {
137 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
138 cap &= ~IEEE80211_HT_CAP_SGI_40;
139 }
140 break;
141 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
142 if (flags & IEEE80211_CHAN_NO_HT40MINUS) {
143 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
144 cap &= ~IEEE80211_HT_CAP_SGI_40;
145 }
146 break;
147 }
148
149 /* set SM PS mode properly */
150 cap &= ~IEEE80211_HT_CAP_SM_PS;
151 switch (smps) {
152 case IEEE80211_SMPS_AUTOMATIC:
153 case IEEE80211_SMPS_NUM_MODES:
154 WARN_ON(1);
155 case IEEE80211_SMPS_OFF:
156 cap |= WLAN_HT_CAP_SM_PS_DISABLED <<
157 IEEE80211_HT_CAP_SM_PS_SHIFT;
158 break;
159 case IEEE80211_SMPS_STATIC:
160 cap |= WLAN_HT_CAP_SM_PS_STATIC <<
161 IEEE80211_HT_CAP_SM_PS_SHIFT;
162 break;
163 case IEEE80211_SMPS_DYNAMIC:
164 cap |= WLAN_HT_CAP_SM_PS_DYNAMIC <<
165 IEEE80211_HT_CAP_SM_PS_SHIFT;
166 break;
167 }
168
169 /* reserve and fill IE */
170
171 pos = skb_put(skb, sizeof(struct ieee80211_ht_cap) + 2);
172 *pos++ = WLAN_EID_HT_CAPABILITY;
173 *pos++ = sizeof(struct ieee80211_ht_cap);
174 memset(pos, 0, sizeof(struct ieee80211_ht_cap));
175
176 /* capability flags */
177 tmp = cpu_to_le16(cap);
178 memcpy(pos, &tmp, sizeof(u16));
179 pos += sizeof(u16);
180
181 /* AMPDU parameters */
182 *pos++ = sband->ht_cap.ampdu_factor |
183 (sband->ht_cap.ampdu_density <<
184 IEEE80211_HT_AMPDU_PARM_DENSITY_SHIFT);
185
186 /* MCS set */
187 memcpy(pos, &sband->ht_cap.mcs, sizeof(sband->ht_cap.mcs));
188 pos += sizeof(sband->ht_cap.mcs);
189
190 /* extended capabilities */
191 pos += sizeof(__le16);
192
193 /* BF capabilities */
194 pos += sizeof(__le32);
195
196 /* antenna selection */
197 pos += sizeof(u8);
198}
199
200static void ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata,
201 struct ieee80211_work *wk)
202{
203 struct ieee80211_local *local = sdata->local;
204 struct sk_buff *skb;
205 struct ieee80211_mgmt *mgmt;
206 u8 *pos, qos_info;
207 const u8 *ies;
208 size_t offset = 0, noffset;
209 int i, len, count, rates_len, supp_rates_len;
210 u16 capab;
211 struct ieee80211_supported_band *sband;
212 u32 rates = 0;
213
214 sband = local->hw.wiphy->bands[wk->chan->band];
215
216 /*
217 * Get all rates supported by the device and the AP as
218 * some APs don't like getting a superset of their rates
219 * in the association request (e.g. D-Link DAP 1353 in
220 * b-only mode)...
221 */
222 rates_len = ieee80211_compatible_rates(wk->assoc.supp_rates,
223 wk->assoc.supp_rates_len,
224 sband, &rates);
225
226 skb = alloc_skb(local->hw.extra_tx_headroom +
227 sizeof(*mgmt) + /* bit too much but doesn't matter */
228 2 + wk->assoc.ssid_len + /* SSID */
229 4 + rates_len + /* (extended) rates */
230 4 + /* power capability */
231 2 + 2 * sband->n_channels + /* supported channels */
232 2 + sizeof(struct ieee80211_ht_cap) + /* HT */
233 wk->ie_len + /* extra IEs */
234 9, /* WMM */
235 GFP_KERNEL);
236 if (!skb) {
237 printk(KERN_DEBUG "%s: failed to allocate buffer for assoc "
238 "frame\n", sdata->name);
239 return;
240 }
241 skb_reserve(skb, local->hw.extra_tx_headroom);
242
243 capab = WLAN_CAPABILITY_ESS;
244
245 if (sband->band == IEEE80211_BAND_2GHZ) {
246 if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE))
247 capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
248 if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE))
249 capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
250 }
251
252 if (wk->assoc.capability & WLAN_CAPABILITY_PRIVACY)
253 capab |= WLAN_CAPABILITY_PRIVACY;
254
255 if ((wk->assoc.capability & WLAN_CAPABILITY_SPECTRUM_MGMT) &&
256 (local->hw.flags & IEEE80211_HW_SPECTRUM_MGMT))
257 capab |= WLAN_CAPABILITY_SPECTRUM_MGMT;
258
259 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
260 memset(mgmt, 0, 24);
261 memcpy(mgmt->da, wk->filter_ta, ETH_ALEN);
262 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
263 memcpy(mgmt->bssid, wk->filter_ta, ETH_ALEN);
264
265 if (!is_zero_ether_addr(wk->assoc.prev_bssid)) {
266 skb_put(skb, 10);
267 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
268 IEEE80211_STYPE_REASSOC_REQ);
269 mgmt->u.reassoc_req.capab_info = cpu_to_le16(capab);
270 mgmt->u.reassoc_req.listen_interval =
271 cpu_to_le16(local->hw.conf.listen_interval);
272 memcpy(mgmt->u.reassoc_req.current_ap, wk->assoc.prev_bssid,
273 ETH_ALEN);
274 } else {
275 skb_put(skb, 4);
276 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
277 IEEE80211_STYPE_ASSOC_REQ);
278 mgmt->u.assoc_req.capab_info = cpu_to_le16(capab);
279 mgmt->u.assoc_req.listen_interval =
280 cpu_to_le16(local->hw.conf.listen_interval);
281 }
282
283 /* SSID */
284 ies = pos = skb_put(skb, 2 + wk->assoc.ssid_len);
285 *pos++ = WLAN_EID_SSID;
286 *pos++ = wk->assoc.ssid_len;
287 memcpy(pos, wk->assoc.ssid, wk->assoc.ssid_len);
288
289 /* add all rates which were marked to be used above */
290 supp_rates_len = rates_len;
291 if (supp_rates_len > 8)
292 supp_rates_len = 8;
293
294 len = sband->n_bitrates;
295 pos = skb_put(skb, supp_rates_len + 2);
296 *pos++ = WLAN_EID_SUPP_RATES;
297 *pos++ = supp_rates_len;
298
299 count = 0;
300 for (i = 0; i < sband->n_bitrates; i++) {
301 if (BIT(i) & rates) {
302 int rate = sband->bitrates[i].bitrate;
303 *pos++ = (u8) (rate / 5);
304 if (++count == 8)
305 break;
306 }
307 }
308
309 if (rates_len > count) {
310 pos = skb_put(skb, rates_len - count + 2);
311 *pos++ = WLAN_EID_EXT_SUPP_RATES;
312 *pos++ = rates_len - count;
313
314 for (i++; i < sband->n_bitrates; i++) {
315 if (BIT(i) & rates) {
316 int rate = sband->bitrates[i].bitrate;
317 *pos++ = (u8) (rate / 5);
318 }
319 }
320 }
321
322 if (capab & WLAN_CAPABILITY_SPECTRUM_MGMT) {
323 /* 1. power capabilities */
324 pos = skb_put(skb, 4);
325 *pos++ = WLAN_EID_PWR_CAPABILITY;
326 *pos++ = 2;
327 *pos++ = 0; /* min tx power */
328 *pos++ = wk->chan->max_power; /* max tx power */
329
330 /* 2. supported channels */
331 /* TODO: get this in reg domain format */
332 pos = skb_put(skb, 2 * sband->n_channels + 2);
333 *pos++ = WLAN_EID_SUPPORTED_CHANNELS;
334 *pos++ = 2 * sband->n_channels;
335 for (i = 0; i < sband->n_channels; i++) {
336 *pos++ = ieee80211_frequency_to_channel(
337 sband->channels[i].center_freq);
338 *pos++ = 1; /* one channel in the subband*/
339 }
340 }
341
342 /* if present, add any custom IEs that go before HT */
343 if (wk->ie_len && wk->ie) {
344 static const u8 before_ht[] = {
345 WLAN_EID_SSID,
346 WLAN_EID_SUPP_RATES,
347 WLAN_EID_EXT_SUPP_RATES,
348 WLAN_EID_PWR_CAPABILITY,
349 WLAN_EID_SUPPORTED_CHANNELS,
350 WLAN_EID_RSN,
351 WLAN_EID_QOS_CAPA,
352 WLAN_EID_RRM_ENABLED_CAPABILITIES,
353 WLAN_EID_MOBILITY_DOMAIN,
354 WLAN_EID_SUPPORTED_REGULATORY_CLASSES,
355 };
356 noffset = ieee80211_ie_split(wk->ie, wk->ie_len,
357 before_ht, ARRAY_SIZE(before_ht),
358 offset);
359 pos = skb_put(skb, noffset - offset);
360 memcpy(pos, wk->ie + offset, noffset - offset);
361 offset = noffset;
362 }
363
364 if (wk->assoc.use_11n && wk->assoc.wmm_used &&
365 local->hw.queues >= 4)
366 ieee80211_add_ht_ie(skb, wk->assoc.ht_information_ie,
367 sband, wk->chan, wk->assoc.smps);
368
369 /* if present, add any custom non-vendor IEs that go after HT */
370 if (wk->ie_len && wk->ie) {
371 noffset = ieee80211_ie_split_vendor(wk->ie, wk->ie_len,
372 offset);
373 pos = skb_put(skb, noffset - offset);
374 memcpy(pos, wk->ie + offset, noffset - offset);
375 offset = noffset;
376 }
377
378 if (wk->assoc.wmm_used && local->hw.queues >= 4) {
379 if (wk->assoc.uapsd_used) {
380 qos_info = local->uapsd_queues;
381 qos_info |= (local->uapsd_max_sp_len <<
382 IEEE80211_WMM_IE_STA_QOSINFO_SP_SHIFT);
383 } else {
384 qos_info = 0;
385 }
386
387 pos = skb_put(skb, 9);
388 *pos++ = WLAN_EID_VENDOR_SPECIFIC;
389 *pos++ = 7; /* len */
390 *pos++ = 0x00; /* Microsoft OUI 00:50:F2 */
391 *pos++ = 0x50;
392 *pos++ = 0xf2;
393 *pos++ = 2; /* WME */
394 *pos++ = 0; /* WME info */
395 *pos++ = 1; /* WME ver */
396 *pos++ = qos_info;
397 }
398
399 /* add any remaining custom (i.e. vendor specific here) IEs */
400 if (wk->ie_len && wk->ie) {
401 noffset = wk->ie_len;
402 pos = skb_put(skb, noffset - offset);
403 memcpy(pos, wk->ie + offset, noffset - offset);
404 }
405
406 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
407 ieee80211_tx_skb(sdata, skb);
408}
409
410static void ieee80211_remove_auth_bss(struct ieee80211_local *local,
411 struct ieee80211_work *wk)
412{
413 struct cfg80211_bss *cbss;
414 u16 capa_val = WLAN_CAPABILITY_ESS;
415
416 if (wk->probe_auth.privacy)
417 capa_val |= WLAN_CAPABILITY_PRIVACY;
418
419 cbss = cfg80211_get_bss(local->hw.wiphy, wk->chan, wk->filter_ta,
420 wk->probe_auth.ssid, wk->probe_auth.ssid_len,
421 WLAN_CAPABILITY_ESS | WLAN_CAPABILITY_PRIVACY,
422 capa_val);
423 if (!cbss)
424 return;
425
426 cfg80211_unlink_bss(local->hw.wiphy, cbss);
427 cfg80211_put_bss(cbss);
428}
429
430static enum work_action __must_check
431ieee80211_direct_probe(struct ieee80211_work *wk)
432{
433 struct ieee80211_sub_if_data *sdata = wk->sdata;
434 struct ieee80211_local *local = sdata->local;
435
436 wk->probe_auth.tries++;
437 if (wk->probe_auth.tries > IEEE80211_AUTH_MAX_TRIES) {
438 printk(KERN_DEBUG "%s: direct probe to %pM timed out\n",
439 sdata->name, wk->filter_ta);
440
441 /*
442 * Most likely AP is not in the range so remove the
443 * bss struct for that AP.
444 */
445 ieee80211_remove_auth_bss(local, wk);
446
447 return WORK_ACT_TIMEOUT;
448 }
449
450 printk(KERN_DEBUG "%s: direct probe to %pM (try %d)\n",
451 sdata->name, wk->filter_ta, wk->probe_auth.tries);
452
453 /*
454 * Direct probe is sent to broadcast address as some APs
455 * will not answer to direct packet in unassociated state.
456 */
457 ieee80211_send_probe_req(sdata, NULL, wk->probe_auth.ssid,
458 wk->probe_auth.ssid_len, NULL, 0);
459
460 wk->timeout = jiffies + IEEE80211_AUTH_TIMEOUT;
461 run_again(local, wk->timeout);
462
463 return WORK_ACT_NONE;
464}
465
466
467static enum work_action __must_check
468ieee80211_authenticate(struct ieee80211_work *wk)
469{
470 struct ieee80211_sub_if_data *sdata = wk->sdata;
471 struct ieee80211_local *local = sdata->local;
472
473 wk->probe_auth.tries++;
474 if (wk->probe_auth.tries > IEEE80211_AUTH_MAX_TRIES) {
475 printk(KERN_DEBUG "%s: authentication with %pM"
476 " timed out\n", sdata->name, wk->filter_ta);
477
478 /*
479 * Most likely AP is not in the range so remove the
480 * bss struct for that AP.
481 */
482 ieee80211_remove_auth_bss(local, wk);
483
484 return WORK_ACT_TIMEOUT;
485 }
486
487 printk(KERN_DEBUG "%s: authenticate with %pM (try %d)\n",
488 sdata->name, wk->filter_ta, wk->probe_auth.tries);
489
490 ieee80211_send_auth(sdata, 1, wk->probe_auth.algorithm, wk->ie,
491 wk->ie_len, wk->filter_ta, NULL, 0, 0);
492 wk->probe_auth.transaction = 2;
493
494 wk->timeout = jiffies + IEEE80211_AUTH_TIMEOUT;
495 run_again(local, wk->timeout);
496
497 return WORK_ACT_NONE;
498}
499
500static enum work_action __must_check
501ieee80211_associate(struct ieee80211_work *wk)
502{
503 struct ieee80211_sub_if_data *sdata = wk->sdata;
504 struct ieee80211_local *local = sdata->local;
505
506 wk->assoc.tries++;
507 if (wk->assoc.tries > IEEE80211_ASSOC_MAX_TRIES) {
508 printk(KERN_DEBUG "%s: association with %pM"
509 " timed out\n",
510 sdata->name, wk->filter_ta);
511
512 /*
513 * Most likely AP is not in the range so remove the
514 * bss struct for that AP.
515 */
516 if (wk->assoc.bss)
517 cfg80211_unlink_bss(local->hw.wiphy, wk->assoc.bss);
518
519 return WORK_ACT_TIMEOUT;
520 }
521
522 printk(KERN_DEBUG "%s: associate with %pM (try %d)\n",
523 sdata->name, wk->filter_ta, wk->assoc.tries);
524 ieee80211_send_assoc(sdata, wk);
525
526 wk->timeout = jiffies + IEEE80211_ASSOC_TIMEOUT;
527 run_again(local, wk->timeout);
528
529 return WORK_ACT_NONE;
530}
531
532static enum work_action __must_check
533ieee80211_remain_on_channel_timeout(struct ieee80211_work *wk)
534{
535 /*
536 * First time we run, do nothing -- the generic code will
537 * have switched to the right channel etc.
538 */
539 if (!wk->started) {
540 wk->timeout = jiffies + msecs_to_jiffies(wk->remain.duration);
541
542 cfg80211_ready_on_channel(wk->sdata->dev, (unsigned long) wk,
543 wk->chan, wk->chan_type,
544 wk->remain.duration, GFP_KERNEL);
545
546 return WORK_ACT_NONE;
547 }
548
549 return WORK_ACT_TIMEOUT;
550}
551
552static void ieee80211_auth_challenge(struct ieee80211_work *wk,
553 struct ieee80211_mgmt *mgmt,
554 size_t len)
555{
556 struct ieee80211_sub_if_data *sdata = wk->sdata;
557 u8 *pos;
558 struct ieee802_11_elems elems;
559
560 pos = mgmt->u.auth.variable;
561 ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems);
562 if (!elems.challenge)
563 return;
564 ieee80211_send_auth(sdata, 3, wk->probe_auth.algorithm,
565 elems.challenge - 2, elems.challenge_len + 2,
566 wk->filter_ta, wk->probe_auth.key,
567 wk->probe_auth.key_len, wk->probe_auth.key_idx);
568 wk->probe_auth.transaction = 4;
569}
570
571static enum work_action __must_check
572ieee80211_rx_mgmt_auth(struct ieee80211_work *wk,
573 struct ieee80211_mgmt *mgmt, size_t len)
574{
575 u16 auth_alg, auth_transaction, status_code;
576
577 if (wk->type != IEEE80211_WORK_AUTH)
578 return WORK_ACT_NONE;
579
580 if (len < 24 + 6)
581 return WORK_ACT_NONE;
582
583 auth_alg = le16_to_cpu(mgmt->u.auth.auth_alg);
584 auth_transaction = le16_to_cpu(mgmt->u.auth.auth_transaction);
585 status_code = le16_to_cpu(mgmt->u.auth.status_code);
586
587 if (auth_alg != wk->probe_auth.algorithm ||
588 auth_transaction != wk->probe_auth.transaction)
589 return WORK_ACT_NONE;
590
591 if (status_code != WLAN_STATUS_SUCCESS) {
592 printk(KERN_DEBUG "%s: %pM denied authentication (status %d)\n",
593 wk->sdata->name, mgmt->sa, status_code);
594 return WORK_ACT_DONE;
595 }
596
597 switch (wk->probe_auth.algorithm) {
598 case WLAN_AUTH_OPEN:
599 case WLAN_AUTH_LEAP:
600 case WLAN_AUTH_FT:
601 break;
602 case WLAN_AUTH_SHARED_KEY:
603 if (wk->probe_auth.transaction != 4) {
604 ieee80211_auth_challenge(wk, mgmt, len);
605 /* need another frame */
606 return WORK_ACT_NONE;
607 }
608 break;
609 default:
610 WARN_ON(1);
611 return WORK_ACT_NONE;
612 }
613
614 printk(KERN_DEBUG "%s: authenticated\n", wk->sdata->name);
615 return WORK_ACT_DONE;
616}
617
618static enum work_action __must_check
619ieee80211_rx_mgmt_assoc_resp(struct ieee80211_work *wk,
620 struct ieee80211_mgmt *mgmt, size_t len,
621 bool reassoc)
622{
623 struct ieee80211_sub_if_data *sdata = wk->sdata;
624 struct ieee80211_local *local = sdata->local;
625 u16 capab_info, status_code, aid;
626 struct ieee802_11_elems elems;
627 u8 *pos;
628
629 /*
630 * AssocResp and ReassocResp have identical structure, so process both
631 * of them in this function.
632 */
633
634 if (len < 24 + 6)
635 return WORK_ACT_NONE;
636
637 capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
638 status_code = le16_to_cpu(mgmt->u.assoc_resp.status_code);
639 aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
640
641 printk(KERN_DEBUG "%s: RX %sssocResp from %pM (capab=0x%x "
642 "status=%d aid=%d)\n",
643 sdata->name, reassoc ? "Rea" : "A", mgmt->sa,
644 capab_info, status_code, (u16)(aid & ~(BIT(15) | BIT(14))));
645
646 pos = mgmt->u.assoc_resp.variable;
647 ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems);
648
649 if (status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY &&
650 elems.timeout_int && elems.timeout_int_len == 5 &&
651 elems.timeout_int[0] == WLAN_TIMEOUT_ASSOC_COMEBACK) {
652 u32 tu, ms;
653 tu = get_unaligned_le32(elems.timeout_int + 1);
654 ms = tu * 1024 / 1000;
655 printk(KERN_DEBUG "%s: %pM rejected association temporarily; "
656 "comeback duration %u TU (%u ms)\n",
657 sdata->name, mgmt->sa, tu, ms);
658 wk->timeout = jiffies + msecs_to_jiffies(ms);
659 if (ms > IEEE80211_ASSOC_TIMEOUT)
660 run_again(local, wk->timeout);
661 return WORK_ACT_NONE;
662 }
663
664 if (status_code != WLAN_STATUS_SUCCESS)
665 printk(KERN_DEBUG "%s: %pM denied association (code=%d)\n",
666 sdata->name, mgmt->sa, status_code);
667 else
668 printk(KERN_DEBUG "%s: associated\n", sdata->name);
669
670 return WORK_ACT_DONE;
671}
672
673static enum work_action __must_check
674ieee80211_rx_mgmt_probe_resp(struct ieee80211_work *wk,
675 struct ieee80211_mgmt *mgmt, size_t len,
676 struct ieee80211_rx_status *rx_status)
677{
678 struct ieee80211_sub_if_data *sdata = wk->sdata;
679 struct ieee80211_local *local = sdata->local;
680 size_t baselen;
681
682 ASSERT_WORK_MTX(local);
683
684 baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt;
685 if (baselen > len)
686 return WORK_ACT_NONE;
687
688 printk(KERN_DEBUG "%s: direct probe responded\n", sdata->name);
689 return WORK_ACT_DONE;
690}
691
692static void ieee80211_work_rx_queued_mgmt(struct ieee80211_local *local,
693 struct sk_buff *skb)
694{
695 struct ieee80211_rx_status *rx_status;
696 struct ieee80211_mgmt *mgmt;
697 struct ieee80211_work *wk;
698 enum work_action rma = WORK_ACT_NONE;
699 u16 fc;
700
701 rx_status = (struct ieee80211_rx_status *) skb->cb;
702 mgmt = (struct ieee80211_mgmt *) skb->data;
703 fc = le16_to_cpu(mgmt->frame_control);
704
705 mutex_lock(&local->work_mtx);
706
707 list_for_each_entry(wk, &local->work_list, list) {
708 const u8 *bssid = NULL;
709
710 switch (wk->type) {
711 case IEEE80211_WORK_DIRECT_PROBE:
712 case IEEE80211_WORK_AUTH:
713 case IEEE80211_WORK_ASSOC:
714 bssid = wk->filter_ta;
715 break;
716 default:
717 continue;
718 }
719
720 /*
721 * Before queuing, we already verified mgmt->sa,
722 * so this is needed just for matching.
723 */
724 if (compare_ether_addr(bssid, mgmt->bssid))
725 continue;
726
727 switch (fc & IEEE80211_FCTL_STYPE) {
728 case IEEE80211_STYPE_PROBE_RESP:
729 rma = ieee80211_rx_mgmt_probe_resp(wk, mgmt, skb->len,
730 rx_status);
731 break;
732 case IEEE80211_STYPE_AUTH:
733 rma = ieee80211_rx_mgmt_auth(wk, mgmt, skb->len);
734 break;
735 case IEEE80211_STYPE_ASSOC_RESP:
736 rma = ieee80211_rx_mgmt_assoc_resp(wk, mgmt,
737 skb->len, false);
738 break;
739 case IEEE80211_STYPE_REASSOC_RESP:
740 rma = ieee80211_rx_mgmt_assoc_resp(wk, mgmt,
741 skb->len, true);
742 break;
743 default:
744 WARN_ON(1);
745 }
746 /*
747 * We've processed this frame for that work, so it can't
748 * belong to another work struct.
749 * NB: this is also required for correctness for 'rma'!
750 */
751 break;
752 }
753
754 switch (rma) {
755 case WORK_ACT_NONE:
756 break;
757 case WORK_ACT_DONE:
758 list_del_rcu(&wk->list);
759 break;
760 default:
761 WARN(1, "unexpected: %d", rma);
762 }
763
764 mutex_unlock(&local->work_mtx);
765
766 if (rma != WORK_ACT_DONE)
767 goto out;
768
769 switch (wk->done(wk, skb)) {
770 case WORK_DONE_DESTROY:
771 free_work(wk);
772 break;
773 case WORK_DONE_REQUEUE:
774 synchronize_rcu();
775 wk->started = false; /* restart */
776 mutex_lock(&local->work_mtx);
777 list_add_tail(&wk->list, &local->work_list);
778 mutex_unlock(&local->work_mtx);
779 }
780
781 out:
782 kfree_skb(skb);
783}
784
785static void ieee80211_work_timer(unsigned long data)
786{
787 struct ieee80211_local *local = (void *) data;
788
789 if (local->quiescing)
790 return;
791
792 ieee80211_queue_work(&local->hw, &local->work_work);
793}
794
795static void ieee80211_work_work(struct work_struct *work)
796{
797 struct ieee80211_local *local =
798 container_of(work, struct ieee80211_local, work_work);
799 struct sk_buff *skb;
800 struct ieee80211_work *wk, *tmp;
801 LIST_HEAD(free_work);
802 enum work_action rma;
803 bool remain_off_channel = false;
804
805 if (local->scanning)
806 return;
807
808 /*
809 * ieee80211_queue_work() should have picked up most cases,
810 * here we'll pick the the rest.
811 */
812 if (WARN(local->suspended, "work scheduled while going to suspend\n"))
813 return;
814
815 /* first process frames to avoid timing out while a frame is pending */
816 while ((skb = skb_dequeue(&local->work_skb_queue)))
817 ieee80211_work_rx_queued_mgmt(local, skb);
818
819 ieee80211_recalc_idle(local);
820
821 mutex_lock(&local->work_mtx);
822
823 list_for_each_entry_safe(wk, tmp, &local->work_list, list) {
824 bool started = wk->started;
825
826 /* mark work as started if it's on the current off-channel */
827 if (!started && local->tmp_channel &&
828 wk->chan == local->tmp_channel &&
829 wk->chan_type == local->tmp_channel_type) {
830 started = true;
831 wk->timeout = jiffies;
832 }
833
834 if (!started && !local->tmp_channel) {
835 /*
836 * TODO: could optimize this by leaving the
837 * station vifs in awake mode if they
838 * happen to be on the same channel as
839 * the requested channel
840 */
841 ieee80211_offchannel_stop_beaconing(local);
842 ieee80211_offchannel_stop_station(local);
843
844 local->tmp_channel = wk->chan;
845 local->tmp_channel_type = wk->chan_type;
846 ieee80211_hw_config(local, 0);
847 started = true;
848 wk->timeout = jiffies;
849 }
850
851 /* don't try to work with items that aren't started */
852 if (!started)
853 continue;
854
855 if (time_is_after_jiffies(wk->timeout)) {
856 /*
857 * This work item isn't supposed to be worked on
858 * right now, but take care to adjust the timer
859 * properly.
860 */
861 run_again(local, wk->timeout);
862 continue;
863 }
864
865 switch (wk->type) {
866 default:
867 WARN_ON(1);
868 /* nothing */
869 rma = WORK_ACT_NONE;
870 break;
871 case IEEE80211_WORK_ABORT:
872 rma = WORK_ACT_TIMEOUT;
873 break;
874 case IEEE80211_WORK_DIRECT_PROBE:
875 rma = ieee80211_direct_probe(wk);
876 break;
877 case IEEE80211_WORK_AUTH:
878 rma = ieee80211_authenticate(wk);
879 break;
880 case IEEE80211_WORK_ASSOC:
881 rma = ieee80211_associate(wk);
882 break;
883 case IEEE80211_WORK_REMAIN_ON_CHANNEL:
884 rma = ieee80211_remain_on_channel_timeout(wk);
885 break;
886 }
887
888 wk->started = started;
889
890 switch (rma) {
891 case WORK_ACT_NONE:
892 /* might have changed the timeout */
893 run_again(local, wk->timeout);
894 break;
895 case WORK_ACT_TIMEOUT:
896 list_del_rcu(&wk->list);
897 synchronize_rcu();
898 list_add(&wk->list, &free_work);
899 break;
900 default:
901 WARN(1, "unexpected: %d", rma);
902 }
903 }
904
905 list_for_each_entry(wk, &local->work_list, list) {
906 if (!wk->started)
907 continue;
908 if (wk->chan != local->tmp_channel)
909 continue;
910 if (wk->chan_type != local->tmp_channel_type)
911 continue;
912 remain_off_channel = true;
913 }
914
915 if (!remain_off_channel && local->tmp_channel) {
916 local->tmp_channel = NULL;
917 ieee80211_hw_config(local, 0);
918 ieee80211_offchannel_return(local, true);
919 /* give connection some time to breathe */
920 run_again(local, jiffies + HZ/2);
921 }
922
923 if (list_empty(&local->work_list) && local->scan_req)
924 ieee80211_queue_delayed_work(&local->hw,
925 &local->scan_work,
926 round_jiffies_relative(0));
927
928 mutex_unlock(&local->work_mtx);
929
930 ieee80211_recalc_idle(local);
931
932 list_for_each_entry_safe(wk, tmp, &free_work, list) {
933 wk->done(wk, NULL);
934 list_del(&wk->list);
935 kfree(wk);
936 }
937}
938
939void ieee80211_add_work(struct ieee80211_work *wk)
940{
941 struct ieee80211_local *local;
942
943 if (WARN_ON(!wk->chan))
944 return;
945
946 if (WARN_ON(!wk->sdata))
947 return;
948
949 if (WARN_ON(!wk->done))
950 return;
951
952 if (WARN_ON(!ieee80211_sdata_running(wk->sdata)))
953 return;
954
955 wk->started = false;
956
957 local = wk->sdata->local;
958 mutex_lock(&local->work_mtx);
959 list_add_tail(&wk->list, &local->work_list);
960 mutex_unlock(&local->work_mtx);
961
962 ieee80211_queue_work(&local->hw, &local->work_work);
963}
964
965void ieee80211_work_init(struct ieee80211_local *local)
966{
967 mutex_init(&local->work_mtx);
968 INIT_LIST_HEAD(&local->work_list);
969 setup_timer(&local->work_timer, ieee80211_work_timer,
970 (unsigned long)local);
971 INIT_WORK(&local->work_work, ieee80211_work_work);
972 skb_queue_head_init(&local->work_skb_queue);
973}
974
975void ieee80211_work_purge(struct ieee80211_sub_if_data *sdata)
976{
977 struct ieee80211_local *local = sdata->local;
978 struct ieee80211_work *wk;
979
980 mutex_lock(&local->work_mtx);
981 list_for_each_entry(wk, &local->work_list, list) {
982 if (wk->sdata != sdata)
983 continue;
984 wk->type = IEEE80211_WORK_ABORT;
985 wk->started = true;
986 wk->timeout = jiffies;
987 }
988 mutex_unlock(&local->work_mtx);
989
990 /* run cleanups etc. */
991 ieee80211_work_work(&local->work_work);
992
993 mutex_lock(&local->work_mtx);
994 list_for_each_entry(wk, &local->work_list, list) {
995 if (wk->sdata != sdata)
996 continue;
997 WARN_ON(1);
998 break;
999 }
1000 mutex_unlock(&local->work_mtx);
1001}
1002
1003ieee80211_rx_result ieee80211_work_rx_mgmt(struct ieee80211_sub_if_data *sdata,
1004 struct sk_buff *skb)
1005{
1006 struct ieee80211_local *local = sdata->local;
1007 struct ieee80211_mgmt *mgmt;
1008 struct ieee80211_work *wk;
1009 u16 fc;
1010
1011 if (skb->len < 24)
1012 return RX_DROP_MONITOR;
1013
1014 mgmt = (struct ieee80211_mgmt *) skb->data;
1015 fc = le16_to_cpu(mgmt->frame_control);
1016
1017 list_for_each_entry_rcu(wk, &local->work_list, list) {
1018 if (sdata != wk->sdata)
1019 continue;
1020 if (compare_ether_addr(wk->filter_ta, mgmt->sa))
1021 continue;
1022 if (compare_ether_addr(wk->filter_ta, mgmt->bssid))
1023 continue;
1024
1025 switch (fc & IEEE80211_FCTL_STYPE) {
1026 case IEEE80211_STYPE_AUTH:
1027 case IEEE80211_STYPE_PROBE_RESP:
1028 case IEEE80211_STYPE_ASSOC_RESP:
1029 case IEEE80211_STYPE_REASSOC_RESP:
1030 skb_queue_tail(&local->work_skb_queue, skb);
1031 ieee80211_queue_work(&local->hw, &local->work_work);
1032 return RX_QUEUED;
1033 }
1034 }
1035
1036 return RX_CONTINUE;
1037}
1038
1039static enum work_done_result ieee80211_remain_done(struct ieee80211_work *wk,
1040 struct sk_buff *skb)
1041{
1042 /*
1043 * We are done serving the remain-on-channel command.
1044 */
1045 cfg80211_remain_on_channel_expired(wk->sdata->dev, (unsigned long) wk,
1046 wk->chan, wk->chan_type,
1047 GFP_KERNEL);
1048
1049 return WORK_DONE_DESTROY;
1050}
1051
1052int ieee80211_wk_remain_on_channel(struct ieee80211_sub_if_data *sdata,
1053 struct ieee80211_channel *chan,
1054 enum nl80211_channel_type channel_type,
1055 unsigned int duration, u64 *cookie)
1056{
1057 struct ieee80211_work *wk;
1058
1059 wk = kzalloc(sizeof(*wk), GFP_KERNEL);
1060 if (!wk)
1061 return -ENOMEM;
1062
1063 wk->type = IEEE80211_WORK_REMAIN_ON_CHANNEL;
1064 wk->chan = chan;
1065 wk->chan_type = channel_type;
1066 wk->sdata = sdata;
1067 wk->done = ieee80211_remain_done;
1068
1069 wk->remain.duration = duration;
1070
1071 *cookie = (unsigned long) wk;
1072
1073 ieee80211_add_work(wk);
1074
1075 return 0;
1076}
1077
1078int ieee80211_wk_cancel_remain_on_channel(struct ieee80211_sub_if_data *sdata,
1079 u64 cookie)
1080{
1081 struct ieee80211_local *local = sdata->local;
1082 struct ieee80211_work *wk, *tmp;
1083 bool found = false;
1084
1085 mutex_lock(&local->work_mtx);
1086 list_for_each_entry_safe(wk, tmp, &local->work_list, list) {
1087 if ((unsigned long) wk == cookie) {
1088 wk->timeout = jiffies;
1089 found = true;
1090 break;
1091 }
1092 }
1093 mutex_unlock(&local->work_mtx);
1094
1095 if (!found)
1096 return -ENOENT;
1097
1098 ieee80211_queue_work(&local->hw, &local->work_work);
1099
1100 return 0;
1101}
diff --git a/net/mac80211/wpa.c b/net/mac80211/wpa.c
index 70778694877b..0adbcc941ac9 100644
--- a/net/mac80211/wpa.c
+++ b/net/mac80211/wpa.c
@@ -9,10 +9,10 @@
9 9
10#include <linux/netdevice.h> 10#include <linux/netdevice.h>
11#include <linux/types.h> 11#include <linux/types.h>
12#include <linux/slab.h>
13#include <linux/skbuff.h> 12#include <linux/skbuff.h>
14#include <linux/compiler.h> 13#include <linux/compiler.h>
15#include <linux/ieee80211.h> 14#include <linux/ieee80211.h>
15#include <linux/gfp.h>
16#include <asm/unaligned.h> 16#include <asm/unaligned.h>
17#include <net/mac80211.h> 17#include <net/mac80211.h>
18 18
@@ -31,8 +31,8 @@ ieee80211_tx_h_michael_mic_add(struct ieee80211_tx_data *tx)
31 unsigned int hdrlen; 31 unsigned int hdrlen;
32 struct ieee80211_hdr *hdr; 32 struct ieee80211_hdr *hdr;
33 struct sk_buff *skb = tx->skb; 33 struct sk_buff *skb = tx->skb;
34 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
34 int authenticator; 35 int authenticator;
35 int wpa_test = 0;
36 int tail; 36 int tail;
37 37
38 hdr = (struct ieee80211_hdr *)skb->data; 38 hdr = (struct ieee80211_hdr *)skb->data;
@@ -47,16 +47,15 @@ ieee80211_tx_h_michael_mic_add(struct ieee80211_tx_data *tx)
47 data = skb->data + hdrlen; 47 data = skb->data + hdrlen;
48 data_len = skb->len - hdrlen; 48 data_len = skb->len - hdrlen;
49 49
50 if ((tx->key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE) && 50 if (info->control.hw_key &&
51 !(tx->flags & IEEE80211_TX_FRAGMENTED) && 51 !(tx->flags & IEEE80211_TX_FRAGMENTED) &&
52 !(tx->key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_MMIC) && 52 !(tx->key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_MMIC)) {
53 !wpa_test) { 53 /* hwaccel - with no need for SW-generated MMIC */
54 /* hwaccel - with no need for preallocated room for MMIC */
55 return TX_CONTINUE; 54 return TX_CONTINUE;
56 } 55 }
57 56
58 tail = MICHAEL_MIC_LEN; 57 tail = MICHAEL_MIC_LEN;
59 if (!(tx->key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE)) 58 if (!info->control.hw_key)
60 tail += TKIP_ICV_LEN; 59 tail += TKIP_ICV_LEN;
61 60
62 if (WARN_ON(skb_tailroom(skb) < tail || 61 if (WARN_ON(skb_tailroom(skb) < tail ||
@@ -85,16 +84,16 @@ ieee80211_rx_h_michael_mic_verify(struct ieee80211_rx_data *rx)
85 u8 *data, *key = NULL, key_offset; 84 u8 *data, *key = NULL, key_offset;
86 size_t data_len; 85 size_t data_len;
87 unsigned int hdrlen; 86 unsigned int hdrlen;
88 struct ieee80211_hdr *hdr;
89 u8 mic[MICHAEL_MIC_LEN]; 87 u8 mic[MICHAEL_MIC_LEN];
90 struct sk_buff *skb = rx->skb; 88 struct sk_buff *skb = rx->skb;
89 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
90 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
91 int authenticator = 1, wpa_test = 0; 91 int authenticator = 1, wpa_test = 0;
92 92
93 /* No way to verify the MIC if the hardware stripped it */ 93 /* No way to verify the MIC if the hardware stripped it */
94 if (rx->status->flag & RX_FLAG_MMIC_STRIPPED) 94 if (status->flag & RX_FLAG_MMIC_STRIPPED)
95 return RX_CONTINUE; 95 return RX_CONTINUE;
96 96
97 hdr = (struct ieee80211_hdr *)skb->data;
98 if (!rx->key || rx->key->conf.alg != ALG_TKIP || 97 if (!rx->key || rx->key->conf.alg != ALG_TKIP ||
99 !ieee80211_has_protected(hdr->frame_control) || 98 !ieee80211_has_protected(hdr->frame_control) ||
100 !ieee80211_is_data_present(hdr->frame_control)) 99 !ieee80211_is_data_present(hdr->frame_control))
@@ -147,17 +146,16 @@ static int tkip_encrypt_skb(struct ieee80211_tx_data *tx, struct sk_buff *skb)
147 int len, tail; 146 int len, tail;
148 u8 *pos; 147 u8 *pos;
149 148
150 if ((tx->key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE) && 149 if (info->control.hw_key &&
151 !(tx->key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV)) { 150 !(info->control.hw_key->flags & IEEE80211_KEY_FLAG_GENERATE_IV)) {
152 /* hwaccel - with no need for preallocated room for IV/ICV */ 151 /* hwaccel - with no need for software-generated IV */
153 info->control.hw_key = &tx->key->conf;
154 return 0; 152 return 0;
155 } 153 }
156 154
157 hdrlen = ieee80211_hdrlen(hdr->frame_control); 155 hdrlen = ieee80211_hdrlen(hdr->frame_control);
158 len = skb->len - hdrlen; 156 len = skb->len - hdrlen;
159 157
160 if (tx->key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE) 158 if (info->control.hw_key)
161 tail = 0; 159 tail = 0;
162 else 160 else
163 tail = TKIP_ICV_LEN; 161 tail = TKIP_ICV_LEN;
@@ -175,13 +173,11 @@ static int tkip_encrypt_skb(struct ieee80211_tx_data *tx, struct sk_buff *skb)
175 if (key->u.tkip.tx.iv16 == 0) 173 if (key->u.tkip.tx.iv16 == 0)
176 key->u.tkip.tx.iv32++; 174 key->u.tkip.tx.iv32++;
177 175
178 if (tx->key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE) { 176 pos = ieee80211_tkip_add_iv(pos, key, key->u.tkip.tx.iv16);
179 /* hwaccel - with preallocated room for IV */
180 ieee80211_tkip_add_iv(pos, key, key->u.tkip.tx.iv16);
181 177
182 info->control.hw_key = &tx->key->conf; 178 /* hwaccel - with software IV */
179 if (info->control.hw_key)
183 return 0; 180 return 0;
184 }
185 181
186 /* Add room for ICV */ 182 /* Add room for ICV */
187 skb_put(skb, TKIP_ICV_LEN); 183 skb_put(skb, TKIP_ICV_LEN);
@@ -216,6 +212,7 @@ ieee80211_crypto_tkip_decrypt(struct ieee80211_rx_data *rx)
216 int hdrlen, res, hwaccel = 0, wpa_test = 0; 212 int hdrlen, res, hwaccel = 0, wpa_test = 0;
217 struct ieee80211_key *key = rx->key; 213 struct ieee80211_key *key = rx->key;
218 struct sk_buff *skb = rx->skb; 214 struct sk_buff *skb = rx->skb;
215 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
219 216
220 hdrlen = ieee80211_hdrlen(hdr->frame_control); 217 hdrlen = ieee80211_hdrlen(hdr->frame_control);
221 218
@@ -225,8 +222,8 @@ ieee80211_crypto_tkip_decrypt(struct ieee80211_rx_data *rx)
225 if (!rx->sta || skb->len - hdrlen < 12) 222 if (!rx->sta || skb->len - hdrlen < 12)
226 return RX_DROP_UNUSABLE; 223 return RX_DROP_UNUSABLE;
227 224
228 if (rx->status->flag & RX_FLAG_DECRYPTED) { 225 if (status->flag & RX_FLAG_DECRYPTED) {
229 if (rx->status->flag & RX_FLAG_IV_STRIPPED) { 226 if (status->flag & RX_FLAG_IV_STRIPPED) {
230 /* 227 /*
231 * Hardware took care of all processing, including 228 * Hardware took care of all processing, including
232 * replay protection, and stripped the ICV/IV so 229 * replay protection, and stripped the ICV/IV so
@@ -362,24 +359,20 @@ static int ccmp_encrypt_skb(struct ieee80211_tx_data *tx, struct sk_buff *skb)
362 int hdrlen, len, tail; 359 int hdrlen, len, tail;
363 u8 *pos, *pn; 360 u8 *pos, *pn;
364 int i; 361 int i;
365 bool skip_hw;
366
367 skip_hw = (tx->key->conf.flags & IEEE80211_KEY_FLAG_SW_MGMT) &&
368 ieee80211_is_mgmt(hdr->frame_control);
369 362
370 if ((tx->key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE) && 363 if (info->control.hw_key &&
371 !(tx->key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV) && 364 !(info->control.hw_key->flags & IEEE80211_KEY_FLAG_GENERATE_IV)) {
372 !skip_hw) { 365 /*
373 /* hwaccel - with no need for preallocated room for CCMP 366 * hwaccel has no need for preallocated room for CCMP
374 * header or MIC fields */ 367 * header or MIC fields
375 info->control.hw_key = &tx->key->conf; 368 */
376 return 0; 369 return 0;
377 } 370 }
378 371
379 hdrlen = ieee80211_hdrlen(hdr->frame_control); 372 hdrlen = ieee80211_hdrlen(hdr->frame_control);
380 len = skb->len - hdrlen; 373 len = skb->len - hdrlen;
381 374
382 if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE) 375 if (info->control.hw_key)
383 tail = 0; 376 tail = 0;
384 else 377 else
385 tail = CCMP_MIC_LEN; 378 tail = CCMP_MIC_LEN;
@@ -404,11 +397,9 @@ static int ccmp_encrypt_skb(struct ieee80211_tx_data *tx, struct sk_buff *skb)
404 397
405 ccmp_pn2hdr(pos, pn, key->conf.keyidx); 398 ccmp_pn2hdr(pos, pn, key->conf.keyidx);
406 399
407 if ((key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE) && !skip_hw) { 400 /* hwaccel - with software CCMP header */
408 /* hwaccel - with preallocated room for CCMP header */ 401 if (info->control.hw_key)
409 info->control.hw_key = &tx->key->conf;
410 return 0; 402 return 0;
411 }
412 403
413 pos += CCMP_HDR_LEN; 404 pos += CCMP_HDR_LEN;
414 ccmp_special_blocks(skb, pn, key->u.ccmp.tx_crypto_buf, 0); 405 ccmp_special_blocks(skb, pn, key->u.ccmp.tx_crypto_buf, 0);
@@ -442,6 +433,7 @@ ieee80211_crypto_ccmp_decrypt(struct ieee80211_rx_data *rx)
442 int hdrlen; 433 int hdrlen;
443 struct ieee80211_key *key = rx->key; 434 struct ieee80211_key *key = rx->key;
444 struct sk_buff *skb = rx->skb; 435 struct sk_buff *skb = rx->skb;
436 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
445 u8 pn[CCMP_PN_LEN]; 437 u8 pn[CCMP_PN_LEN];
446 int data_len; 438 int data_len;
447 439
@@ -455,8 +447,8 @@ ieee80211_crypto_ccmp_decrypt(struct ieee80211_rx_data *rx)
455 if (!rx->sta || data_len < 0) 447 if (!rx->sta || data_len < 0)
456 return RX_DROP_UNUSABLE; 448 return RX_DROP_UNUSABLE;
457 449
458 if ((rx->status->flag & RX_FLAG_DECRYPTED) && 450 if ((status->flag & RX_FLAG_DECRYPTED) &&
459 (rx->status->flag & RX_FLAG_IV_STRIPPED)) 451 (status->flag & RX_FLAG_IV_STRIPPED))
460 return RX_CONTINUE; 452 return RX_CONTINUE;
461 453
462 ccmp_hdr2pn(pn, skb->data + hdrlen); 454 ccmp_hdr2pn(pn, skb->data + hdrlen);
@@ -466,7 +458,7 @@ ieee80211_crypto_ccmp_decrypt(struct ieee80211_rx_data *rx)
466 return RX_DROP_UNUSABLE; 458 return RX_DROP_UNUSABLE;
467 } 459 }
468 460
469 if (!(rx->status->flag & RX_FLAG_DECRYPTED)) { 461 if (!(status->flag & RX_FLAG_DECRYPTED)) {
470 /* hardware didn't decrypt/verify MIC */ 462 /* hardware didn't decrypt/verify MIC */
471 ccmp_special_blocks(skb, pn, key->u.ccmp.rx_crypto_buf, 1); 463 ccmp_special_blocks(skb, pn, key->u.ccmp.rx_crypto_buf, 1);
472 464
@@ -523,11 +515,8 @@ ieee80211_crypto_aes_cmac_encrypt(struct ieee80211_tx_data *tx)
523 u8 *pn, aad[20]; 515 u8 *pn, aad[20];
524 int i; 516 int i;
525 517
526 if (tx->key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE) { 518 if (info->control.hw_key)
527 /* hwaccel */
528 info->control.hw_key = &tx->key->conf;
529 return 0; 519 return 0;
530 }
531 520
532 if (WARN_ON(skb_tailroom(skb) < sizeof(*mmie))) 521 if (WARN_ON(skb_tailroom(skb) < sizeof(*mmie)))
533 return TX_DROP; 522 return TX_DROP;
@@ -563,6 +552,7 @@ ieee80211_rx_result
563ieee80211_crypto_aes_cmac_decrypt(struct ieee80211_rx_data *rx) 552ieee80211_crypto_aes_cmac_decrypt(struct ieee80211_rx_data *rx)
564{ 553{
565 struct sk_buff *skb = rx->skb; 554 struct sk_buff *skb = rx->skb;
555 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
566 struct ieee80211_key *key = rx->key; 556 struct ieee80211_key *key = rx->key;
567 struct ieee80211_mmie *mmie; 557 struct ieee80211_mmie *mmie;
568 u8 aad[20], mic[8], ipn[6]; 558 u8 aad[20], mic[8], ipn[6];
@@ -571,8 +561,8 @@ ieee80211_crypto_aes_cmac_decrypt(struct ieee80211_rx_data *rx)
571 if (!ieee80211_is_mgmt(hdr->frame_control)) 561 if (!ieee80211_is_mgmt(hdr->frame_control))
572 return RX_CONTINUE; 562 return RX_CONTINUE;
573 563
574 if ((rx->status->flag & RX_FLAG_DECRYPTED) && 564 if ((status->flag & RX_FLAG_DECRYPTED) &&
575 (rx->status->flag & RX_FLAG_IV_STRIPPED)) 565 (status->flag & RX_FLAG_IV_STRIPPED))
576 return RX_CONTINUE; 566 return RX_CONTINUE;
577 567
578 if (skb->len < 24 + sizeof(*mmie)) 568 if (skb->len < 24 + sizeof(*mmie))
@@ -591,7 +581,7 @@ ieee80211_crypto_aes_cmac_decrypt(struct ieee80211_rx_data *rx)
591 return RX_DROP_UNUSABLE; 581 return RX_DROP_UNUSABLE;
592 } 582 }
593 583
594 if (!(rx->status->flag & RX_FLAG_DECRYPTED)) { 584 if (!(status->flag & RX_FLAG_DECRYPTED)) {
595 /* hardware didn't decrypt/verify MIC */ 585 /* hardware didn't decrypt/verify MIC */
596 bip_aad(skb, aad); 586 bip_aad(skb, aad);
597 ieee80211_aes_cmac(key->u.aes_cmac.tfm, 587 ieee80211_aes_cmac(key->u.aes_cmac.tfm,
diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
index 634d14affc8d..18d77b5c351a 100644
--- a/net/netfilter/Kconfig
+++ b/net/netfilter/Kconfig
@@ -83,6 +83,19 @@ config NF_CONNTRACK_SECMARK
83 83
84 If unsure, say 'N'. 84 If unsure, say 'N'.
85 85
86config NF_CONNTRACK_ZONES
87 bool 'Connection tracking zones'
88 depends on NETFILTER_ADVANCED
89 depends on NETFILTER_XT_TARGET_CT
90 help
91 This option enables support for connection tracking zones.
92 Normally, each connection needs to have a unique system wide
93 identity. Connection tracking zones allow to have multiple
94 connections using the same identity, as long as they are
95 contained in different zones.
96
97 If unsure, say `N'.
98
86config NF_CONNTRACK_EVENTS 99config NF_CONNTRACK_EVENTS
87 bool "Connection tracking events" 100 bool "Connection tracking events"
88 depends on NETFILTER_ADVANCED 101 depends on NETFILTER_ADVANCED
@@ -341,6 +354,18 @@ config NETFILTER_XT_TARGET_CONNSECMARK
341 354
342 To compile it as a module, choose M here. If unsure, say N. 355 To compile it as a module, choose M here. If unsure, say N.
343 356
357config NETFILTER_XT_TARGET_CT
358 tristate '"CT" target support'
359 depends on NF_CONNTRACK
360 depends on IP_NF_RAW || IP6_NF_RAW
361 depends on NETFILTER_ADVANCED
362 help
363 This options adds a `CT' target, which allows to specify initial
364 connection tracking parameters like events to be delivered and
365 the helper to be used.
366
367 To compile it as a module, choose M here. If unsure, say N.
368
344config NETFILTER_XT_TARGET_DSCP 369config NETFILTER_XT_TARGET_DSCP
345 tristate '"DSCP" and "TOS" target support' 370 tristate '"DSCP" and "TOS" target support'
346 depends on IP_NF_MANGLE || IP6_NF_MANGLE 371 depends on IP_NF_MANGLE || IP6_NF_MANGLE
diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
index 49f62ee4e9ff..f873644f02f6 100644
--- a/net/netfilter/Makefile
+++ b/net/netfilter/Makefile
@@ -44,6 +44,7 @@ obj-$(CONFIG_NETFILTER_XTABLES) += x_tables.o xt_tcpudp.o
44obj-$(CONFIG_NETFILTER_XT_TARGET_CLASSIFY) += xt_CLASSIFY.o 44obj-$(CONFIG_NETFILTER_XT_TARGET_CLASSIFY) += xt_CLASSIFY.o
45obj-$(CONFIG_NETFILTER_XT_TARGET_CONNMARK) += xt_CONNMARK.o 45obj-$(CONFIG_NETFILTER_XT_TARGET_CONNMARK) += xt_CONNMARK.o
46obj-$(CONFIG_NETFILTER_XT_TARGET_CONNSECMARK) += xt_CONNSECMARK.o 46obj-$(CONFIG_NETFILTER_XT_TARGET_CONNSECMARK) += xt_CONNSECMARK.o
47obj-$(CONFIG_NETFILTER_XT_TARGET_CT) += xt_CT.o
47obj-$(CONFIG_NETFILTER_XT_TARGET_DSCP) += xt_DSCP.o 48obj-$(CONFIG_NETFILTER_XT_TARGET_DSCP) += xt_DSCP.o
48obj-$(CONFIG_NETFILTER_XT_TARGET_HL) += xt_HL.o 49obj-$(CONFIG_NETFILTER_XT_TARGET_HL) += xt_HL.o
49obj-$(CONFIG_NETFILTER_XT_TARGET_LED) += xt_LED.o 50obj-$(CONFIG_NETFILTER_XT_TARGET_LED) += xt_LED.o
diff --git a/net/netfilter/core.c b/net/netfilter/core.c
index 5bb34737501f..78b505d33bfb 100644
--- a/net/netfilter/core.c
+++ b/net/netfilter/core.c
@@ -19,6 +19,7 @@
19#include <linux/inetdevice.h> 19#include <linux/inetdevice.h>
20#include <linux/proc_fs.h> 20#include <linux/proc_fs.h>
21#include <linux/mutex.h> 21#include <linux/mutex.h>
22#include <linux/slab.h>
22#include <net/net_namespace.h> 23#include <net/net_namespace.h>
23#include <net/sock.h> 24#include <net/sock.h>
24 25
@@ -273,8 +274,8 @@ void __init netfilter_init(void)
273 274
274#ifdef CONFIG_SYSCTL 275#ifdef CONFIG_SYSCTL
275struct ctl_path nf_net_netfilter_sysctl_path[] = { 276struct ctl_path nf_net_netfilter_sysctl_path[] = {
276 { .procname = "net", .ctl_name = CTL_NET, }, 277 { .procname = "net", },
277 { .procname = "netfilter", .ctl_name = NET_NETFILTER, }, 278 { .procname = "netfilter", },
278 { } 279 { }
279}; 280};
280EXPORT_SYMBOL_GPL(nf_net_netfilter_sysctl_path); 281EXPORT_SYMBOL_GPL(nf_net_netfilter_sysctl_path);
diff --git a/net/netfilter/ipvs/Kconfig b/net/netfilter/ipvs/Kconfig
index 79a698052218..712ccad13344 100644
--- a/net/netfilter/ipvs/Kconfig
+++ b/net/netfilter/ipvs/Kconfig
@@ -68,6 +68,10 @@ config IP_VS_TAB_BITS
68 each hash entry uses 8 bytes, so you can estimate how much memory is 68 each hash entry uses 8 bytes, so you can estimate how much memory is
69 needed for your box. 69 needed for your box.
70 70
71 You can overwrite this number setting conn_tab_bits module parameter
72 or by appending ip_vs.conn_tab_bits=? to the kernel command line
73 if IP VS was compiled built-in.
74
71comment "IPVS transport protocol load balancing support" 75comment "IPVS transport protocol load balancing support"
72 76
73config IP_VS_PROTO_TCP 77config IP_VS_PROTO_TCP
@@ -100,6 +104,13 @@ config IP_VS_PROTO_AH
100 This option enables support for load balancing AH (Authentication 104 This option enables support for load balancing AH (Authentication
101 Header) transport protocol. Say Y if unsure. 105 Header) transport protocol. Say Y if unsure.
102 106
107config IP_VS_PROTO_SCTP
108 bool "SCTP load balancing support"
109 select LIBCRC32C
110 ---help---
111 This option enables support for load balancing SCTP transport
112 protocol. Say Y if unsure.
113
103comment "IPVS scheduler" 114comment "IPVS scheduler"
104 115
105config IP_VS_RR 116config IP_VS_RR
@@ -112,7 +123,8 @@ config IP_VS_RR
112 module, choose M here. If unsure, say N. 123 module, choose M here. If unsure, say N.
113 124
114config IP_VS_WRR 125config IP_VS_WRR
115 tristate "weighted round-robin scheduling" 126 tristate "weighted round-robin scheduling"
127 select GCD
116 ---help--- 128 ---help---
117 The weighted robin-robin scheduling algorithm directs network 129 The weighted robin-robin scheduling algorithm directs network
118 connections to different real servers based on server weights 130 connections to different real servers based on server weights
diff --git a/net/netfilter/ipvs/Makefile b/net/netfilter/ipvs/Makefile
index 73a46fe1fe4c..e3baefd7066e 100644
--- a/net/netfilter/ipvs/Makefile
+++ b/net/netfilter/ipvs/Makefile
@@ -7,6 +7,7 @@ ip_vs_proto-objs-y :=
7ip_vs_proto-objs-$(CONFIG_IP_VS_PROTO_TCP) += ip_vs_proto_tcp.o 7ip_vs_proto-objs-$(CONFIG_IP_VS_PROTO_TCP) += ip_vs_proto_tcp.o
8ip_vs_proto-objs-$(CONFIG_IP_VS_PROTO_UDP) += ip_vs_proto_udp.o 8ip_vs_proto-objs-$(CONFIG_IP_VS_PROTO_UDP) += ip_vs_proto_udp.o
9ip_vs_proto-objs-$(CONFIG_IP_VS_PROTO_AH_ESP) += ip_vs_proto_ah_esp.o 9ip_vs_proto-objs-$(CONFIG_IP_VS_PROTO_AH_ESP) += ip_vs_proto_ah_esp.o
10ip_vs_proto-objs-$(CONFIG_IP_VS_PROTO_SCTP) += ip_vs_proto_sctp.o
10 11
11ip_vs-objs := ip_vs_conn.o ip_vs_core.o ip_vs_ctl.o ip_vs_sched.o \ 12ip_vs-objs := ip_vs_conn.o ip_vs_core.o ip_vs_ctl.o ip_vs_sched.o \
12 ip_vs_xmit.o ip_vs_app.o ip_vs_sync.o \ 13 ip_vs_xmit.o ip_vs_app.o ip_vs_sync.o \
diff --git a/net/netfilter/ipvs/ip_vs_app.c b/net/netfilter/ipvs/ip_vs_app.c
index 3c7e42735b60..1cb0e834f8ff 100644
--- a/net/netfilter/ipvs/ip_vs_app.c
+++ b/net/netfilter/ipvs/ip_vs_app.c
@@ -27,6 +27,7 @@
27#include <linux/in.h> 27#include <linux/in.h>
28#include <linux/ip.h> 28#include <linux/ip.h>
29#include <linux/netfilter.h> 29#include <linux/netfilter.h>
30#include <linux/slab.h>
30#include <net/net_namespace.h> 31#include <net/net_namespace.h>
31#include <net/protocol.h> 32#include <net/protocol.h>
32#include <net/tcp.h> 33#include <net/tcp.h>
diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
index 27c30cf933da..d8f7e8ef67b4 100644
--- a/net/netfilter/ipvs/ip_vs_conn.c
+++ b/net/netfilter/ipvs/ip_vs_conn.c
@@ -32,6 +32,7 @@
32#include <linux/module.h> 32#include <linux/module.h>
33#include <linux/vmalloc.h> 33#include <linux/vmalloc.h>
34#include <linux/proc_fs.h> /* for proc_net_* */ 34#include <linux/proc_fs.h> /* for proc_net_* */
35#include <linux/slab.h>
35#include <linux/seq_file.h> 36#include <linux/seq_file.h>
36#include <linux/jhash.h> 37#include <linux/jhash.h>
37#include <linux/random.h> 38#include <linux/random.h>
@@ -40,6 +41,21 @@
40#include <net/ip_vs.h> 41#include <net/ip_vs.h>
41 42
42 43
44#ifndef CONFIG_IP_VS_TAB_BITS
45#define CONFIG_IP_VS_TAB_BITS 12
46#endif
47
48/*
49 * Connection hash size. Default is what was selected at compile time.
50*/
51int ip_vs_conn_tab_bits = CONFIG_IP_VS_TAB_BITS;
52module_param_named(conn_tab_bits, ip_vs_conn_tab_bits, int, 0444);
53MODULE_PARM_DESC(conn_tab_bits, "Set connections' hash size");
54
55/* size and mask values */
56int ip_vs_conn_tab_size;
57int ip_vs_conn_tab_mask;
58
43/* 59/*
44 * Connection hash table: for input and output packets lookups of IPVS 60 * Connection hash table: for input and output packets lookups of IPVS
45 */ 61 */
@@ -125,11 +141,11 @@ static unsigned int ip_vs_conn_hashkey(int af, unsigned proto,
125 if (af == AF_INET6) 141 if (af == AF_INET6)
126 return jhash_3words(jhash(addr, 16, ip_vs_conn_rnd), 142 return jhash_3words(jhash(addr, 16, ip_vs_conn_rnd),
127 (__force u32)port, proto, ip_vs_conn_rnd) 143 (__force u32)port, proto, ip_vs_conn_rnd)
128 & IP_VS_CONN_TAB_MASK; 144 & ip_vs_conn_tab_mask;
129#endif 145#endif
130 return jhash_3words((__force u32)addr->ip, (__force u32)port, proto, 146 return jhash_3words((__force u32)addr->ip, (__force u32)port, proto,
131 ip_vs_conn_rnd) 147 ip_vs_conn_rnd)
132 & IP_VS_CONN_TAB_MASK; 148 & ip_vs_conn_tab_mask;
133} 149}
134 150
135 151
@@ -760,7 +776,7 @@ static void *ip_vs_conn_array(struct seq_file *seq, loff_t pos)
760 int idx; 776 int idx;
761 struct ip_vs_conn *cp; 777 struct ip_vs_conn *cp;
762 778
763 for(idx = 0; idx < IP_VS_CONN_TAB_SIZE; idx++) { 779 for (idx = 0; idx < ip_vs_conn_tab_size; idx++) {
764 ct_read_lock_bh(idx); 780 ct_read_lock_bh(idx);
765 list_for_each_entry(cp, &ip_vs_conn_tab[idx], c_list) { 781 list_for_each_entry(cp, &ip_vs_conn_tab[idx], c_list) {
766 if (pos-- == 0) { 782 if (pos-- == 0) {
@@ -797,7 +813,7 @@ static void *ip_vs_conn_seq_next(struct seq_file *seq, void *v, loff_t *pos)
797 idx = l - ip_vs_conn_tab; 813 idx = l - ip_vs_conn_tab;
798 ct_read_unlock_bh(idx); 814 ct_read_unlock_bh(idx);
799 815
800 while (++idx < IP_VS_CONN_TAB_SIZE) { 816 while (++idx < ip_vs_conn_tab_size) {
801 ct_read_lock_bh(idx); 817 ct_read_lock_bh(idx);
802 list_for_each_entry(cp, &ip_vs_conn_tab[idx], c_list) { 818 list_for_each_entry(cp, &ip_vs_conn_tab[idx], c_list) {
803 seq->private = &ip_vs_conn_tab[idx]; 819 seq->private = &ip_vs_conn_tab[idx];
@@ -976,8 +992,8 @@ void ip_vs_random_dropentry(void)
976 /* 992 /*
977 * Randomly scan 1/32 of the whole table every second 993 * Randomly scan 1/32 of the whole table every second
978 */ 994 */
979 for (idx = 0; idx < (IP_VS_CONN_TAB_SIZE>>5); idx++) { 995 for (idx = 0; idx < (ip_vs_conn_tab_size>>5); idx++) {
980 unsigned hash = net_random() & IP_VS_CONN_TAB_MASK; 996 unsigned hash = net_random() & ip_vs_conn_tab_mask;
981 997
982 /* 998 /*
983 * Lock is actually needed in this loop. 999 * Lock is actually needed in this loop.
@@ -1029,7 +1045,7 @@ static void ip_vs_conn_flush(void)
1029 struct ip_vs_conn *cp; 1045 struct ip_vs_conn *cp;
1030 1046
1031 flush_again: 1047 flush_again:
1032 for (idx=0; idx<IP_VS_CONN_TAB_SIZE; idx++) { 1048 for (idx = 0; idx < ip_vs_conn_tab_size; idx++) {
1033 /* 1049 /*
1034 * Lock is actually needed in this loop. 1050 * Lock is actually needed in this loop.
1035 */ 1051 */
@@ -1060,10 +1076,15 @@ int __init ip_vs_conn_init(void)
1060{ 1076{
1061 int idx; 1077 int idx;
1062 1078
1079 /* Compute size and mask */
1080 ip_vs_conn_tab_size = 1 << ip_vs_conn_tab_bits;
1081 ip_vs_conn_tab_mask = ip_vs_conn_tab_size - 1;
1082
1063 /* 1083 /*
1064 * Allocate the connection hash table and initialize its list heads 1084 * Allocate the connection hash table and initialize its list heads
1065 */ 1085 */
1066 ip_vs_conn_tab = vmalloc(IP_VS_CONN_TAB_SIZE*sizeof(struct list_head)); 1086 ip_vs_conn_tab = vmalloc(ip_vs_conn_tab_size *
1087 sizeof(struct list_head));
1067 if (!ip_vs_conn_tab) 1088 if (!ip_vs_conn_tab)
1068 return -ENOMEM; 1089 return -ENOMEM;
1069 1090
@@ -1078,12 +1099,12 @@ int __init ip_vs_conn_init(void)
1078 1099
1079 pr_info("Connection hash table configured " 1100 pr_info("Connection hash table configured "
1080 "(size=%d, memory=%ldKbytes)\n", 1101 "(size=%d, memory=%ldKbytes)\n",
1081 IP_VS_CONN_TAB_SIZE, 1102 ip_vs_conn_tab_size,
1082 (long)(IP_VS_CONN_TAB_SIZE*sizeof(struct list_head))/1024); 1103 (long)(ip_vs_conn_tab_size*sizeof(struct list_head))/1024);
1083 IP_VS_DBG(0, "Each connection entry needs %Zd bytes at least\n", 1104 IP_VS_DBG(0, "Each connection entry needs %Zd bytes at least\n",
1084 sizeof(struct ip_vs_conn)); 1105 sizeof(struct ip_vs_conn));
1085 1106
1086 for (idx = 0; idx < IP_VS_CONN_TAB_SIZE; idx++) { 1107 for (idx = 0; idx < ip_vs_conn_tab_size; idx++) {
1087 INIT_LIST_HEAD(&ip_vs_conn_tab[idx]); 1108 INIT_LIST_HEAD(&ip_vs_conn_tab[idx]);
1088 } 1109 }
1089 1110
diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
index b95699f00545..1cd6e3fd058b 100644
--- a/net/netfilter/ipvs/ip_vs_core.c
+++ b/net/netfilter/ipvs/ip_vs_core.c
@@ -31,7 +31,9 @@
31#include <linux/kernel.h> 31#include <linux/kernel.h>
32#include <linux/ip.h> 32#include <linux/ip.h>
33#include <linux/tcp.h> 33#include <linux/tcp.h>
34#include <linux/sctp.h>
34#include <linux/icmp.h> 35#include <linux/icmp.h>
36#include <linux/slab.h>
35 37
36#include <net/ip.h> 38#include <net/ip.h>
37#include <net/tcp.h> 39#include <net/tcp.h>
@@ -81,6 +83,8 @@ const char *ip_vs_proto_name(unsigned proto)
81 return "UDP"; 83 return "UDP";
82 case IPPROTO_TCP: 84 case IPPROTO_TCP:
83 return "TCP"; 85 return "TCP";
86 case IPPROTO_SCTP:
87 return "SCTP";
84 case IPPROTO_ICMP: 88 case IPPROTO_ICMP:
85 return "ICMP"; 89 return "ICMP";
86#ifdef CONFIG_IP_VS_IPV6 90#ifdef CONFIG_IP_VS_IPV6
@@ -512,8 +516,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
512 */ 516 */
513#ifdef CONFIG_IP_VS_IPV6 517#ifdef CONFIG_IP_VS_IPV6
514 if (svc->af == AF_INET6) 518 if (svc->af == AF_INET6)
515 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0, 519 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
516 skb->dev);
517 else 520 else
518#endif 521#endif
519 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0); 522 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
@@ -589,8 +592,9 @@ void ip_vs_nat_icmp(struct sk_buff *skb, struct ip_vs_protocol *pp,
589 ip_send_check(ciph); 592 ip_send_check(ciph);
590 } 593 }
591 594
592 /* the TCP/UDP port */ 595 /* the TCP/UDP/SCTP port */
593 if (IPPROTO_TCP == ciph->protocol || IPPROTO_UDP == ciph->protocol) { 596 if (IPPROTO_TCP == ciph->protocol || IPPROTO_UDP == ciph->protocol ||
597 IPPROTO_SCTP == ciph->protocol) {
594 __be16 *ports = (void *)ciph + ciph->ihl*4; 598 __be16 *ports = (void *)ciph + ciph->ihl*4;
595 599
596 if (inout) 600 if (inout)
@@ -630,8 +634,9 @@ void ip_vs_nat_icmp_v6(struct sk_buff *skb, struct ip_vs_protocol *pp,
630 ciph->saddr = cp->daddr.in6; 634 ciph->saddr = cp->daddr.in6;
631 } 635 }
632 636
633 /* the TCP/UDP port */ 637 /* the TCP/UDP/SCTP port */
634 if (IPPROTO_TCP == ciph->nexthdr || IPPROTO_UDP == ciph->nexthdr) { 638 if (IPPROTO_TCP == ciph->nexthdr || IPPROTO_UDP == ciph->nexthdr ||
639 IPPROTO_SCTP == ciph->nexthdr) {
635 __be16 *ports = (void *)ciph + sizeof(struct ipv6hdr); 640 __be16 *ports = (void *)ciph + sizeof(struct ipv6hdr);
636 641
637 if (inout) 642 if (inout)
@@ -679,7 +684,8 @@ static int handle_response_icmp(int af, struct sk_buff *skb,
679 goto out; 684 goto out;
680 } 685 }
681 686
682 if (IPPROTO_TCP == protocol || IPPROTO_UDP == protocol) 687 if (IPPROTO_TCP == protocol || IPPROTO_UDP == protocol ||
688 IPPROTO_SCTP == protocol)
683 offset += 2 * sizeof(__u16); 689 offset += 2 * sizeof(__u16);
684 if (!skb_make_writable(skb, offset)) 690 if (!skb_make_writable(skb, offset))
685 goto out; 691 goto out;
@@ -857,6 +863,21 @@ static int ip_vs_out_icmp_v6(struct sk_buff *skb, int *related)
857} 863}
858#endif 864#endif
859 865
866/*
867 * Check if sctp chunc is ABORT chunk
868 */
869static inline int is_sctp_abort(const struct sk_buff *skb, int nh_len)
870{
871 sctp_chunkhdr_t *sch, schunk;
872 sch = skb_header_pointer(skb, nh_len + sizeof(sctp_sctphdr_t),
873 sizeof(schunk), &schunk);
874 if (sch == NULL)
875 return 0;
876 if (sch->type == SCTP_CID_ABORT)
877 return 1;
878 return 0;
879}
880
860static inline int is_tcp_reset(const struct sk_buff *skb, int nh_len) 881static inline int is_tcp_reset(const struct sk_buff *skb, int nh_len)
861{ 882{
862 struct tcphdr _tcph, *th; 883 struct tcphdr _tcph, *th;
@@ -999,7 +1020,8 @@ ip_vs_out(unsigned int hooknum, struct sk_buff *skb,
999 if (unlikely(!cp)) { 1020 if (unlikely(!cp)) {
1000 if (sysctl_ip_vs_nat_icmp_send && 1021 if (sysctl_ip_vs_nat_icmp_send &&
1001 (pp->protocol == IPPROTO_TCP || 1022 (pp->protocol == IPPROTO_TCP ||
1002 pp->protocol == IPPROTO_UDP)) { 1023 pp->protocol == IPPROTO_UDP ||
1024 pp->protocol == IPPROTO_SCTP)) {
1003 __be16 _ports[2], *pptr; 1025 __be16 _ports[2], *pptr;
1004 1026
1005 pptr = skb_header_pointer(skb, iph.len, 1027 pptr = skb_header_pointer(skb, iph.len,
@@ -1014,14 +1036,19 @@ ip_vs_out(unsigned int hooknum, struct sk_buff *skb,
1014 * existing entry if it is not RST 1036 * existing entry if it is not RST
1015 * packet or not TCP packet. 1037 * packet or not TCP packet.
1016 */ 1038 */
1017 if (iph.protocol != IPPROTO_TCP 1039 if ((iph.protocol != IPPROTO_TCP &&
1018 || !is_tcp_reset(skb, iph.len)) { 1040 iph.protocol != IPPROTO_SCTP)
1041 || ((iph.protocol == IPPROTO_TCP
1042 && !is_tcp_reset(skb, iph.len))
1043 || (iph.protocol == IPPROTO_SCTP
1044 && !is_sctp_abort(skb,
1045 iph.len)))) {
1019#ifdef CONFIG_IP_VS_IPV6 1046#ifdef CONFIG_IP_VS_IPV6
1020 if (af == AF_INET6) 1047 if (af == AF_INET6)
1021 icmpv6_send(skb, 1048 icmpv6_send(skb,
1022 ICMPV6_DEST_UNREACH, 1049 ICMPV6_DEST_UNREACH,
1023 ICMPV6_PORT_UNREACH, 1050 ICMPV6_PORT_UNREACH,
1024 0, skb->dev); 1051 0);
1025 else 1052 else
1026#endif 1053#endif
1027 icmp_send(skb, 1054 icmp_send(skb,
@@ -1235,7 +1262,8 @@ ip_vs_in_icmp_v6(struct sk_buff *skb, int *related, unsigned int hooknum)
1235 1262
1236 /* do the statistics and put it back */ 1263 /* do the statistics and put it back */
1237 ip_vs_in_stats(cp, skb); 1264 ip_vs_in_stats(cp, skb);
1238 if (IPPROTO_TCP == cih->nexthdr || IPPROTO_UDP == cih->nexthdr) 1265 if (IPPROTO_TCP == cih->nexthdr || IPPROTO_UDP == cih->nexthdr ||
1266 IPPROTO_SCTP == cih->nexthdr)
1239 offset += 2 * sizeof(__u16); 1267 offset += 2 * sizeof(__u16);
1240 verdict = ip_vs_icmp_xmit_v6(skb, cp, pp, offset); 1268 verdict = ip_vs_icmp_xmit_v6(skb, cp, pp, offset);
1241 /* do not touch skb anymore */ 1269 /* do not touch skb anymore */
@@ -1358,6 +1386,21 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb,
1358 * encorage the standby servers to update the connections timeout 1386 * encorage the standby servers to update the connections timeout
1359 */ 1387 */
1360 pkts = atomic_add_return(1, &cp->in_pkts); 1388 pkts = atomic_add_return(1, &cp->in_pkts);
1389 if (af == AF_INET && (ip_vs_sync_state & IP_VS_STATE_MASTER) &&
1390 cp->protocol == IPPROTO_SCTP) {
1391 if ((cp->state == IP_VS_SCTP_S_ESTABLISHED &&
1392 (atomic_read(&cp->in_pkts) %
1393 sysctl_ip_vs_sync_threshold[1]
1394 == sysctl_ip_vs_sync_threshold[0])) ||
1395 (cp->old_state != cp->state &&
1396 ((cp->state == IP_VS_SCTP_S_CLOSED) ||
1397 (cp->state == IP_VS_SCTP_S_SHUT_ACK_CLI) ||
1398 (cp->state == IP_VS_SCTP_S_SHUT_ACK_SER)))) {
1399 ip_vs_sync_conn(cp);
1400 goto out;
1401 }
1402 }
1403
1361 if (af == AF_INET && 1404 if (af == AF_INET &&
1362 (ip_vs_sync_state & IP_VS_STATE_MASTER) && 1405 (ip_vs_sync_state & IP_VS_STATE_MASTER) &&
1363 (((cp->protocol != IPPROTO_TCP || 1406 (((cp->protocol != IPPROTO_TCP ||
@@ -1366,9 +1409,11 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb,
1366 == sysctl_ip_vs_sync_threshold[0])) || 1409 == sysctl_ip_vs_sync_threshold[0])) ||
1367 ((cp->protocol == IPPROTO_TCP) && (cp->old_state != cp->state) && 1410 ((cp->protocol == IPPROTO_TCP) && (cp->old_state != cp->state) &&
1368 ((cp->state == IP_VS_TCP_S_FIN_WAIT) || 1411 ((cp->state == IP_VS_TCP_S_FIN_WAIT) ||
1412 (cp->state == IP_VS_TCP_S_CLOSE) ||
1369 (cp->state == IP_VS_TCP_S_CLOSE_WAIT) || 1413 (cp->state == IP_VS_TCP_S_CLOSE_WAIT) ||
1370 (cp->state == IP_VS_TCP_S_TIME_WAIT))))) 1414 (cp->state == IP_VS_TCP_S_TIME_WAIT)))))
1371 ip_vs_sync_conn(cp); 1415 ip_vs_sync_conn(cp);
1416out:
1372 cp->old_state = cp->state; 1417 cp->old_state = cp->state;
1373 1418
1374 ip_vs_conn_put(cp); 1419 ip_vs_conn_put(cp);
diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
index 446e9bd4b4bc..36dc1d88c2fa 100644
--- a/net/netfilter/ipvs/ip_vs_ctl.c
+++ b/net/netfilter/ipvs/ip_vs_ctl.c
@@ -31,6 +31,7 @@
31#include <linux/workqueue.h> 31#include <linux/workqueue.h>
32#include <linux/swap.h> 32#include <linux/swap.h>
33#include <linux/seq_file.h> 33#include <linux/seq_file.h>
34#include <linux/slab.h>
34 35
35#include <linux/netfilter.h> 36#include <linux/netfilter.h>
36#include <linux/netfilter_ipv4.h> 37#include <linux/netfilter_ipv4.h>
@@ -1706,12 +1707,12 @@ static struct ctl_table vs_vars[] = {
1706 .mode = 0644, 1707 .mode = 0644,
1707 .proc_handler = proc_dointvec, 1708 .proc_handler = proc_dointvec,
1708 }, 1709 },
1709 { .ctl_name = 0 } 1710 { }
1710}; 1711};
1711 1712
1712const struct ctl_path net_vs_ctl_path[] = { 1713const struct ctl_path net_vs_ctl_path[] = {
1713 { .procname = "net", .ctl_name = CTL_NET, }, 1714 { .procname = "net", },
1714 { .procname = "ipv4", .ctl_name = NET_IPV4, }, 1715 { .procname = "ipv4", },
1715 { .procname = "vs", }, 1716 { .procname = "vs", },
1716 { } 1717 { }
1717}; 1718};
@@ -1843,7 +1844,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
1843 if (v == SEQ_START_TOKEN) { 1844 if (v == SEQ_START_TOKEN) {
1844 seq_printf(seq, 1845 seq_printf(seq,
1845 "IP Virtual Server version %d.%d.%d (size=%d)\n", 1846 "IP Virtual Server version %d.%d.%d (size=%d)\n",
1846 NVERSION(IP_VS_VERSION_CODE), IP_VS_CONN_TAB_SIZE); 1847 NVERSION(IP_VS_VERSION_CODE), ip_vs_conn_tab_size);
1847 seq_puts(seq, 1848 seq_puts(seq,
1848 "Prot LocalAddress:Port Scheduler Flags\n"); 1849 "Prot LocalAddress:Port Scheduler Flags\n");
1849 seq_puts(seq, 1850 seq_puts(seq,
@@ -2077,6 +2078,10 @@ do_ip_vs_set_ctl(struct sock *sk, int cmd, void __user *user, unsigned int len)
2077 if (!capable(CAP_NET_ADMIN)) 2078 if (!capable(CAP_NET_ADMIN))
2078 return -EPERM; 2079 return -EPERM;
2079 2080
2081 if (cmd < IP_VS_BASE_CTL || cmd > IP_VS_SO_SET_MAX)
2082 return -EINVAL;
2083 if (len < 0 || len > MAX_ARG_LEN)
2084 return -EINVAL;
2080 if (len != set_arglen[SET_CMDID(cmd)]) { 2085 if (len != set_arglen[SET_CMDID(cmd)]) {
2081 pr_err("set_ctl: len %u != %u\n", 2086 pr_err("set_ctl: len %u != %u\n",
2082 len, set_arglen[SET_CMDID(cmd)]); 2087 len, set_arglen[SET_CMDID(cmd)]);
@@ -2128,8 +2133,9 @@ do_ip_vs_set_ctl(struct sock *sk, int cmd, void __user *user, unsigned int len)
2128 } 2133 }
2129 } 2134 }
2130 2135
2131 /* Check for valid protocol: TCP or UDP, even for fwmark!=0 */ 2136 /* Check for valid protocol: TCP or UDP or SCTP, even for fwmark!=0 */
2132 if (usvc.protocol != IPPROTO_TCP && usvc.protocol != IPPROTO_UDP) { 2137 if (usvc.protocol != IPPROTO_TCP && usvc.protocol != IPPROTO_UDP &&
2138 usvc.protocol != IPPROTO_SCTP) {
2133 pr_err("set_ctl: invalid protocol: %d %pI4:%d %s\n", 2139 pr_err("set_ctl: invalid protocol: %d %pI4:%d %s\n",
2134 usvc.protocol, &usvc.addr.ip, 2140 usvc.protocol, &usvc.addr.ip,
2135 ntohs(usvc.port), usvc.sched_name); 2141 ntohs(usvc.port), usvc.sched_name);
@@ -2352,17 +2358,25 @@ do_ip_vs_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
2352{ 2358{
2353 unsigned char arg[128]; 2359 unsigned char arg[128];
2354 int ret = 0; 2360 int ret = 0;
2361 unsigned int copylen;
2355 2362
2356 if (!capable(CAP_NET_ADMIN)) 2363 if (!capable(CAP_NET_ADMIN))
2357 return -EPERM; 2364 return -EPERM;
2358 2365
2366 if (cmd < IP_VS_BASE_CTL || cmd > IP_VS_SO_GET_MAX)
2367 return -EINVAL;
2368
2359 if (*len < get_arglen[GET_CMDID(cmd)]) { 2369 if (*len < get_arglen[GET_CMDID(cmd)]) {
2360 pr_err("get_ctl: len %u < %u\n", 2370 pr_err("get_ctl: len %u < %u\n",
2361 *len, get_arglen[GET_CMDID(cmd)]); 2371 *len, get_arglen[GET_CMDID(cmd)]);
2362 return -EINVAL; 2372 return -EINVAL;
2363 } 2373 }
2364 2374
2365 if (copy_from_user(arg, user, get_arglen[GET_CMDID(cmd)]) != 0) 2375 copylen = get_arglen[GET_CMDID(cmd)];
2376 if (copylen > 128)
2377 return -EINVAL;
2378
2379 if (copy_from_user(arg, user, copylen) != 0)
2366 return -EFAULT; 2380 return -EFAULT;
2367 2381
2368 if (mutex_lock_interruptible(&__ip_vs_mutex)) 2382 if (mutex_lock_interruptible(&__ip_vs_mutex))
@@ -2374,7 +2388,7 @@ do_ip_vs_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
2374 char buf[64]; 2388 char buf[64];
2375 2389
2376 sprintf(buf, "IP Virtual Server version %d.%d.%d (size=%d)", 2390 sprintf(buf, "IP Virtual Server version %d.%d.%d (size=%d)",
2377 NVERSION(IP_VS_VERSION_CODE), IP_VS_CONN_TAB_SIZE); 2391 NVERSION(IP_VS_VERSION_CODE), ip_vs_conn_tab_size);
2378 if (copy_to_user(user, buf, strlen(buf)+1) != 0) { 2392 if (copy_to_user(user, buf, strlen(buf)+1) != 0) {
2379 ret = -EFAULT; 2393 ret = -EFAULT;
2380 goto out; 2394 goto out;
@@ -2387,7 +2401,7 @@ do_ip_vs_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
2387 { 2401 {
2388 struct ip_vs_getinfo info; 2402 struct ip_vs_getinfo info;
2389 info.version = IP_VS_VERSION_CODE; 2403 info.version = IP_VS_VERSION_CODE;
2390 info.size = IP_VS_CONN_TAB_SIZE; 2404 info.size = ip_vs_conn_tab_size;
2391 info.num_services = ip_vs_num_services; 2405 info.num_services = ip_vs_num_services;
2392 if (copy_to_user(user, &info, sizeof(info)) != 0) 2406 if (copy_to_user(user, &info, sizeof(info)) != 0)
2393 ret = -EFAULT; 2407 ret = -EFAULT;
@@ -2714,6 +2728,8 @@ static int ip_vs_genl_parse_service(struct ip_vs_service_user_kern *usvc,
2714 if (!(nla_af && (nla_fwmark || (nla_port && nla_protocol && nla_addr)))) 2728 if (!(nla_af && (nla_fwmark || (nla_port && nla_protocol && nla_addr))))
2715 return -EINVAL; 2729 return -EINVAL;
2716 2730
2731 memset(usvc, 0, sizeof(*usvc));
2732
2717 usvc->af = nla_get_u16(nla_af); 2733 usvc->af = nla_get_u16(nla_af);
2718#ifdef CONFIG_IP_VS_IPV6 2734#ifdef CONFIG_IP_VS_IPV6
2719 if (usvc->af != AF_INET && usvc->af != AF_INET6) 2735 if (usvc->af != AF_INET && usvc->af != AF_INET6)
@@ -2901,6 +2917,8 @@ static int ip_vs_genl_parse_dest(struct ip_vs_dest_user_kern *udest,
2901 if (!(nla_addr && nla_port)) 2917 if (!(nla_addr && nla_port))
2902 return -EINVAL; 2918 return -EINVAL;
2903 2919
2920 memset(udest, 0, sizeof(*udest));
2921
2904 nla_memcpy(&udest->addr, nla_addr, sizeof(udest->addr)); 2922 nla_memcpy(&udest->addr, nla_addr, sizeof(udest->addr));
2905 udest->port = nla_get_u16(nla_port); 2923 udest->port = nla_get_u16(nla_port);
2906 2924
@@ -3227,7 +3245,7 @@ static int ip_vs_genl_get_cmd(struct sk_buff *skb, struct genl_info *info)
3227 case IPVS_CMD_GET_INFO: 3245 case IPVS_CMD_GET_INFO:
3228 NLA_PUT_U32(msg, IPVS_INFO_ATTR_VERSION, IP_VS_VERSION_CODE); 3246 NLA_PUT_U32(msg, IPVS_INFO_ATTR_VERSION, IP_VS_VERSION_CODE);
3229 NLA_PUT_U32(msg, IPVS_INFO_ATTR_CONN_TAB_SIZE, 3247 NLA_PUT_U32(msg, IPVS_INFO_ATTR_CONN_TAB_SIZE,
3230 IP_VS_CONN_TAB_SIZE); 3248 ip_vs_conn_tab_size);
3231 break; 3249 break;
3232 } 3250 }
3233 3251
diff --git a/net/netfilter/ipvs/ip_vs_dh.c b/net/netfilter/ipvs/ip_vs_dh.c
index fe3e18834b91..95fd0d14200b 100644
--- a/net/netfilter/ipvs/ip_vs_dh.c
+++ b/net/netfilter/ipvs/ip_vs_dh.c
@@ -39,6 +39,7 @@
39#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt 39#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
40 40
41#include <linux/ip.h> 41#include <linux/ip.h>
42#include <linux/slab.h>
42#include <linux/module.h> 43#include <linux/module.h>
43#include <linux/kernel.h> 44#include <linux/kernel.h>
44#include <linux/skbuff.h> 45#include <linux/skbuff.h>
diff --git a/net/netfilter/ipvs/ip_vs_est.c b/net/netfilter/ipvs/ip_vs_est.c
index 702b53ca937c..ff28801962e0 100644
--- a/net/netfilter/ipvs/ip_vs_est.c
+++ b/net/netfilter/ipvs/ip_vs_est.c
@@ -17,7 +17,6 @@
17 17
18#include <linux/kernel.h> 18#include <linux/kernel.h>
19#include <linux/jiffies.h> 19#include <linux/jiffies.h>
20#include <linux/slab.h>
21#include <linux/types.h> 20#include <linux/types.h>
22#include <linux/interrupt.h> 21#include <linux/interrupt.h>
23#include <linux/sysctl.h> 22#include <linux/sysctl.h>
diff --git a/net/netfilter/ipvs/ip_vs_ftp.c b/net/netfilter/ipvs/ip_vs_ftp.c
index 33e2c799cba7..2c7f185dfae4 100644
--- a/net/netfilter/ipvs/ip_vs_ftp.c
+++ b/net/netfilter/ipvs/ip_vs_ftp.c
@@ -32,6 +32,7 @@
32#include <linux/in.h> 32#include <linux/in.h>
33#include <linux/ip.h> 33#include <linux/ip.h>
34#include <linux/netfilter.h> 34#include <linux/netfilter.h>
35#include <linux/gfp.h>
35#include <net/protocol.h> 36#include <net/protocol.h>
36#include <net/tcp.h> 37#include <net/tcp.h>
37#include <asm/unaligned.h> 38#include <asm/unaligned.h>
@@ -208,7 +209,7 @@ static int ip_vs_ftp_out(struct ip_vs_app *app, struct ip_vs_conn *cp,
208 */ 209 */
209 from.ip = n_cp->vaddr.ip; 210 from.ip = n_cp->vaddr.ip;
210 port = n_cp->vport; 211 port = n_cp->vport;
211 sprintf(buf, "%d,%d,%d,%d,%d,%d", NIPQUAD(from.ip), 212 sprintf(buf, "%u,%u,%u,%u,%u,%u", NIPQUAD(from.ip),
212 (ntohs(port)>>8)&255, ntohs(port)&255); 213 (ntohs(port)>>8)&255, ntohs(port)&255);
213 buf_len = strlen(buf); 214 buf_len = strlen(buf);
214 215
diff --git a/net/netfilter/ipvs/ip_vs_lblc.c b/net/netfilter/ipvs/ip_vs_lblc.c
index c1757f3620cd..94a45213faa6 100644
--- a/net/netfilter/ipvs/ip_vs_lblc.c
+++ b/net/netfilter/ipvs/ip_vs_lblc.c
@@ -43,6 +43,7 @@
43#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt 43#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
44 44
45#include <linux/ip.h> 45#include <linux/ip.h>
46#include <linux/slab.h>
46#include <linux/module.h> 47#include <linux/module.h>
47#include <linux/kernel.h> 48#include <linux/kernel.h>
48#include <linux/skbuff.h> 49#include <linux/skbuff.h>
@@ -121,7 +122,7 @@ static ctl_table vs_vars_table[] = {
121 .mode = 0644, 122 .mode = 0644,
122 .proc_handler = proc_dointvec_jiffies, 123 .proc_handler = proc_dointvec_jiffies,
123 }, 124 },
124 { .ctl_name = 0 } 125 { }
125}; 126};
126 127
127static struct ctl_table_header * sysctl_header; 128static struct ctl_table_header * sysctl_header;
diff --git a/net/netfilter/ipvs/ip_vs_lblcr.c b/net/netfilter/ipvs/ip_vs_lblcr.c
index 715b57f9540d..535dc2b419d8 100644
--- a/net/netfilter/ipvs/ip_vs_lblcr.c
+++ b/net/netfilter/ipvs/ip_vs_lblcr.c
@@ -45,6 +45,8 @@
45#include <linux/kernel.h> 45#include <linux/kernel.h>
46#include <linux/skbuff.h> 46#include <linux/skbuff.h>
47#include <linux/jiffies.h> 47#include <linux/jiffies.h>
48#include <linux/list.h>
49#include <linux/slab.h>
48 50
49/* for sysctl */ 51/* for sysctl */
50#include <linux/fs.h> 52#include <linux/fs.h>
@@ -85,25 +87,25 @@ static int sysctl_ip_vs_lblcr_expiration = 24*60*60*HZ;
85/* 87/*
86 * IPVS destination set structure and operations 88 * IPVS destination set structure and operations
87 */ 89 */
88struct ip_vs_dest_list { 90struct ip_vs_dest_set_elem {
89 struct ip_vs_dest_list *next; /* list link */ 91 struct list_head list; /* list link */
90 struct ip_vs_dest *dest; /* destination server */ 92 struct ip_vs_dest *dest; /* destination server */
91}; 93};
92 94
93struct ip_vs_dest_set { 95struct ip_vs_dest_set {
94 atomic_t size; /* set size */ 96 atomic_t size; /* set size */
95 unsigned long lastmod; /* last modified time */ 97 unsigned long lastmod; /* last modified time */
96 struct ip_vs_dest_list *list; /* destination list */ 98 struct list_head list; /* destination list */
97 rwlock_t lock; /* lock for this list */ 99 rwlock_t lock; /* lock for this list */
98}; 100};
99 101
100 102
101static struct ip_vs_dest_list * 103static struct ip_vs_dest_set_elem *
102ip_vs_dest_set_insert(struct ip_vs_dest_set *set, struct ip_vs_dest *dest) 104ip_vs_dest_set_insert(struct ip_vs_dest_set *set, struct ip_vs_dest *dest)
103{ 105{
104 struct ip_vs_dest_list *e; 106 struct ip_vs_dest_set_elem *e;
105 107
106 for (e=set->list; e!=NULL; e=e->next) { 108 list_for_each_entry(e, &set->list, list) {
107 if (e->dest == dest) 109 if (e->dest == dest)
108 /* already existed */ 110 /* already existed */
109 return NULL; 111 return NULL;
@@ -118,9 +120,7 @@ ip_vs_dest_set_insert(struct ip_vs_dest_set *set, struct ip_vs_dest *dest)
118 atomic_inc(&dest->refcnt); 120 atomic_inc(&dest->refcnt);
119 e->dest = dest; 121 e->dest = dest;
120 122
121 /* link it to the list */ 123 list_add(&e->list, &set->list);
122 e->next = set->list;
123 set->list = e;
124 atomic_inc(&set->size); 124 atomic_inc(&set->size);
125 125
126 set->lastmod = jiffies; 126 set->lastmod = jiffies;
@@ -130,34 +130,33 @@ ip_vs_dest_set_insert(struct ip_vs_dest_set *set, struct ip_vs_dest *dest)
130static void 130static void
131ip_vs_dest_set_erase(struct ip_vs_dest_set *set, struct ip_vs_dest *dest) 131ip_vs_dest_set_erase(struct ip_vs_dest_set *set, struct ip_vs_dest *dest)
132{ 132{
133 struct ip_vs_dest_list *e, **ep; 133 struct ip_vs_dest_set_elem *e;
134 134
135 for (ep=&set->list, e=*ep; e!=NULL; e=*ep) { 135 list_for_each_entry(e, &set->list, list) {
136 if (e->dest == dest) { 136 if (e->dest == dest) {
137 /* HIT */ 137 /* HIT */
138 *ep = e->next;
139 atomic_dec(&set->size); 138 atomic_dec(&set->size);
140 set->lastmod = jiffies; 139 set->lastmod = jiffies;
141 atomic_dec(&e->dest->refcnt); 140 atomic_dec(&e->dest->refcnt);
141 list_del(&e->list);
142 kfree(e); 142 kfree(e);
143 break; 143 break;
144 } 144 }
145 ep = &e->next;
146 } 145 }
147} 146}
148 147
149static void ip_vs_dest_set_eraseall(struct ip_vs_dest_set *set) 148static void ip_vs_dest_set_eraseall(struct ip_vs_dest_set *set)
150{ 149{
151 struct ip_vs_dest_list *e, **ep; 150 struct ip_vs_dest_set_elem *e, *ep;
152 151
153 write_lock(&set->lock); 152 write_lock(&set->lock);
154 for (ep=&set->list, e=*ep; e!=NULL; e=*ep) { 153 list_for_each_entry_safe(e, ep, &set->list, list) {
155 *ep = e->next;
156 /* 154 /*
157 * We don't kfree dest because it is refered either 155 * We don't kfree dest because it is refered either
158 * by its service or by the trash dest list. 156 * by its service or by the trash dest list.
159 */ 157 */
160 atomic_dec(&e->dest->refcnt); 158 atomic_dec(&e->dest->refcnt);
159 list_del(&e->list);
161 kfree(e); 160 kfree(e);
162 } 161 }
163 write_unlock(&set->lock); 162 write_unlock(&set->lock);
@@ -166,7 +165,7 @@ static void ip_vs_dest_set_eraseall(struct ip_vs_dest_set *set)
166/* get weighted least-connection node in the destination set */ 165/* get weighted least-connection node in the destination set */
167static inline struct ip_vs_dest *ip_vs_dest_set_min(struct ip_vs_dest_set *set) 166static inline struct ip_vs_dest *ip_vs_dest_set_min(struct ip_vs_dest_set *set)
168{ 167{
169 register struct ip_vs_dest_list *e; 168 register struct ip_vs_dest_set_elem *e;
170 struct ip_vs_dest *dest, *least; 169 struct ip_vs_dest *dest, *least;
171 int loh, doh; 170 int loh, doh;
172 171
@@ -174,7 +173,7 @@ static inline struct ip_vs_dest *ip_vs_dest_set_min(struct ip_vs_dest_set *set)
174 return NULL; 173 return NULL;
175 174
176 /* select the first destination server, whose weight > 0 */ 175 /* select the first destination server, whose weight > 0 */
177 for (e=set->list; e!=NULL; e=e->next) { 176 list_for_each_entry(e, &set->list, list) {
178 least = e->dest; 177 least = e->dest;
179 if (least->flags & IP_VS_DEST_F_OVERLOAD) 178 if (least->flags & IP_VS_DEST_F_OVERLOAD)
180 continue; 179 continue;
@@ -190,7 +189,7 @@ static inline struct ip_vs_dest *ip_vs_dest_set_min(struct ip_vs_dest_set *set)
190 189
191 /* find the destination with the weighted least load */ 190 /* find the destination with the weighted least load */
192 nextstage: 191 nextstage:
193 for (e=e->next; e!=NULL; e=e->next) { 192 list_for_each_entry(e, &set->list, list) {
194 dest = e->dest; 193 dest = e->dest;
195 if (dest->flags & IP_VS_DEST_F_OVERLOAD) 194 if (dest->flags & IP_VS_DEST_F_OVERLOAD)
196 continue; 195 continue;
@@ -220,7 +219,7 @@ static inline struct ip_vs_dest *ip_vs_dest_set_min(struct ip_vs_dest_set *set)
220/* get weighted most-connection node in the destination set */ 219/* get weighted most-connection node in the destination set */
221static inline struct ip_vs_dest *ip_vs_dest_set_max(struct ip_vs_dest_set *set) 220static inline struct ip_vs_dest *ip_vs_dest_set_max(struct ip_vs_dest_set *set)
222{ 221{
223 register struct ip_vs_dest_list *e; 222 register struct ip_vs_dest_set_elem *e;
224 struct ip_vs_dest *dest, *most; 223 struct ip_vs_dest *dest, *most;
225 int moh, doh; 224 int moh, doh;
226 225
@@ -228,7 +227,7 @@ static inline struct ip_vs_dest *ip_vs_dest_set_max(struct ip_vs_dest_set *set)
228 return NULL; 227 return NULL;
229 228
230 /* select the first destination server, whose weight > 0 */ 229 /* select the first destination server, whose weight > 0 */
231 for (e=set->list; e!=NULL; e=e->next) { 230 list_for_each_entry(e, &set->list, list) {
232 most = e->dest; 231 most = e->dest;
233 if (atomic_read(&most->weight) > 0) { 232 if (atomic_read(&most->weight) > 0) {
234 moh = atomic_read(&most->activeconns) * 50 233 moh = atomic_read(&most->activeconns) * 50
@@ -240,7 +239,7 @@ static inline struct ip_vs_dest *ip_vs_dest_set_max(struct ip_vs_dest_set *set)
240 239
241 /* find the destination with the weighted most load */ 240 /* find the destination with the weighted most load */
242 nextstage: 241 nextstage:
243 for (e=e->next; e!=NULL; e=e->next) { 242 list_for_each_entry(e, &set->list, list) {
244 dest = e->dest; 243 dest = e->dest;
245 doh = atomic_read(&dest->activeconns) * 50 244 doh = atomic_read(&dest->activeconns) * 50
246 + atomic_read(&dest->inactconns); 245 + atomic_read(&dest->inactconns);
@@ -302,7 +301,7 @@ static ctl_table vs_vars_table[] = {
302 .mode = 0644, 301 .mode = 0644,
303 .proc_handler = proc_dointvec_jiffies, 302 .proc_handler = proc_dointvec_jiffies,
304 }, 303 },
305 { .ctl_name = 0 } 304 { }
306}; 305};
307 306
308static struct ctl_table_header * sysctl_header; 307static struct ctl_table_header * sysctl_header;
@@ -389,7 +388,7 @@ ip_vs_lblcr_new(struct ip_vs_lblcr_table *tbl, const union nf_inet_addr *daddr,
389 388
390 /* initilize its dest set */ 389 /* initilize its dest set */
391 atomic_set(&(en->set.size), 0); 390 atomic_set(&(en->set.size), 0);
392 en->set.list = NULL; 391 INIT_LIST_HEAD(&en->set.list);
393 rwlock_init(&en->set.lock); 392 rwlock_init(&en->set.lock);
394 393
395 ip_vs_lblcr_hash(tbl, en); 394 ip_vs_lblcr_hash(tbl, en);
diff --git a/net/netfilter/ipvs/ip_vs_proto.c b/net/netfilter/ipvs/ip_vs_proto.c
index 3e7671674549..7fc49f4cf5ad 100644
--- a/net/netfilter/ipvs/ip_vs_proto.c
+++ b/net/netfilter/ipvs/ip_vs_proto.c
@@ -19,6 +19,7 @@
19#include <linux/module.h> 19#include <linux/module.h>
20#include <linux/kernel.h> 20#include <linux/kernel.h>
21#include <linux/skbuff.h> 21#include <linux/skbuff.h>
22#include <linux/gfp.h>
22#include <linux/in.h> 23#include <linux/in.h>
23#include <linux/ip.h> 24#include <linux/ip.h>
24#include <net/protocol.h> 25#include <net/protocol.h>
@@ -257,6 +258,9 @@ int __init ip_vs_protocol_init(void)
257#ifdef CONFIG_IP_VS_PROTO_UDP 258#ifdef CONFIG_IP_VS_PROTO_UDP
258 REGISTER_PROTOCOL(&ip_vs_protocol_udp); 259 REGISTER_PROTOCOL(&ip_vs_protocol_udp);
259#endif 260#endif
261#ifdef CONFIG_IP_VS_PROTO_SCTP
262 REGISTER_PROTOCOL(&ip_vs_protocol_sctp);
263#endif
260#ifdef CONFIG_IP_VS_PROTO_AH 264#ifdef CONFIG_IP_VS_PROTO_AH
261 REGISTER_PROTOCOL(&ip_vs_protocol_ah); 265 REGISTER_PROTOCOL(&ip_vs_protocol_ah);
262#endif 266#endif
diff --git a/net/netfilter/ipvs/ip_vs_proto_sctp.c b/net/netfilter/ipvs/ip_vs_proto_sctp.c
new file mode 100644
index 000000000000..c9a3f7a21d53
--- /dev/null
+++ b/net/netfilter/ipvs/ip_vs_proto_sctp.c
@@ -0,0 +1,1183 @@
1#include <linux/kernel.h>
2#include <linux/ip.h>
3#include <linux/sctp.h>
4#include <net/ip.h>
5#include <net/ip6_checksum.h>
6#include <linux/netfilter.h>
7#include <linux/netfilter_ipv4.h>
8#include <net/sctp/checksum.h>
9#include <net/ip_vs.h>
10
11
12static struct ip_vs_conn *
13sctp_conn_in_get(int af,
14 const struct sk_buff *skb,
15 struct ip_vs_protocol *pp,
16 const struct ip_vs_iphdr *iph,
17 unsigned int proto_off,
18 int inverse)
19{
20 __be16 _ports[2], *pptr;
21
22 pptr = skb_header_pointer(skb, proto_off, sizeof(_ports), _ports);
23 if (pptr == NULL)
24 return NULL;
25
26 if (likely(!inverse))
27 return ip_vs_conn_in_get(af, iph->protocol,
28 &iph->saddr, pptr[0],
29 &iph->daddr, pptr[1]);
30 else
31 return ip_vs_conn_in_get(af, iph->protocol,
32 &iph->daddr, pptr[1],
33 &iph->saddr, pptr[0]);
34}
35
36static struct ip_vs_conn *
37sctp_conn_out_get(int af,
38 const struct sk_buff *skb,
39 struct ip_vs_protocol *pp,
40 const struct ip_vs_iphdr *iph,
41 unsigned int proto_off,
42 int inverse)
43{
44 __be16 _ports[2], *pptr;
45
46 pptr = skb_header_pointer(skb, proto_off, sizeof(_ports), _ports);
47 if (pptr == NULL)
48 return NULL;
49
50 if (likely(!inverse))
51 return ip_vs_conn_out_get(af, iph->protocol,
52 &iph->saddr, pptr[0],
53 &iph->daddr, pptr[1]);
54 else
55 return ip_vs_conn_out_get(af, iph->protocol,
56 &iph->daddr, pptr[1],
57 &iph->saddr, pptr[0]);
58}
59
60static int
61sctp_conn_schedule(int af, struct sk_buff *skb, struct ip_vs_protocol *pp,
62 int *verdict, struct ip_vs_conn **cpp)
63{
64 struct ip_vs_service *svc;
65 sctp_chunkhdr_t _schunkh, *sch;
66 sctp_sctphdr_t *sh, _sctph;
67 struct ip_vs_iphdr iph;
68
69 ip_vs_fill_iphdr(af, skb_network_header(skb), &iph);
70
71 sh = skb_header_pointer(skb, iph.len, sizeof(_sctph), &_sctph);
72 if (sh == NULL)
73 return 0;
74
75 sch = skb_header_pointer(skb, iph.len + sizeof(sctp_sctphdr_t),
76 sizeof(_schunkh), &_schunkh);
77 if (sch == NULL)
78 return 0;
79
80 if ((sch->type == SCTP_CID_INIT) &&
81 (svc = ip_vs_service_get(af, skb->mark, iph.protocol,
82 &iph.daddr, sh->dest))) {
83 if (ip_vs_todrop()) {
84 /*
85 * It seems that we are very loaded.
86 * We have to drop this packet :(
87 */
88 ip_vs_service_put(svc);
89 *verdict = NF_DROP;
90 return 0;
91 }
92 /*
93 * Let the virtual server select a real server for the
94 * incoming connection, and create a connection entry.
95 */
96 *cpp = ip_vs_schedule(svc, skb);
97 if (!*cpp) {
98 *verdict = ip_vs_leave(svc, skb, pp);
99 return 0;
100 }
101 ip_vs_service_put(svc);
102 }
103
104 return 1;
105}
106
107static int
108sctp_snat_handler(struct sk_buff *skb,
109 struct ip_vs_protocol *pp, struct ip_vs_conn *cp)
110{
111 sctp_sctphdr_t *sctph;
112 unsigned int sctphoff;
113 __be32 crc32;
114
115#ifdef CONFIG_IP_VS_IPV6
116 if (cp->af == AF_INET6)
117 sctphoff = sizeof(struct ipv6hdr);
118 else
119#endif
120 sctphoff = ip_hdrlen(skb);
121
122 /* csum_check requires unshared skb */
123 if (!skb_make_writable(skb, sctphoff + sizeof(*sctph)))
124 return 0;
125
126 if (unlikely(cp->app != NULL)) {
127 /* Some checks before mangling */
128 if (pp->csum_check && !pp->csum_check(cp->af, skb, pp))
129 return 0;
130
131 /* Call application helper if needed */
132 if (!ip_vs_app_pkt_out(cp, skb))
133 return 0;
134 }
135
136 sctph = (void *) skb_network_header(skb) + sctphoff;
137 sctph->source = cp->vport;
138
139 /* Calculate the checksum */
140 crc32 = sctp_start_cksum((u8 *) sctph, skb_headlen(skb) - sctphoff);
141 for (skb = skb_shinfo(skb)->frag_list; skb; skb = skb->next)
142 crc32 = sctp_update_cksum((u8 *) skb->data, skb_headlen(skb),
143 crc32);
144 crc32 = sctp_end_cksum(crc32);
145 sctph->checksum = crc32;
146
147 return 1;
148}
149
150static int
151sctp_dnat_handler(struct sk_buff *skb,
152 struct ip_vs_protocol *pp, struct ip_vs_conn *cp)
153{
154
155 sctp_sctphdr_t *sctph;
156 unsigned int sctphoff;
157 __be32 crc32;
158
159#ifdef CONFIG_IP_VS_IPV6
160 if (cp->af == AF_INET6)
161 sctphoff = sizeof(struct ipv6hdr);
162 else
163#endif
164 sctphoff = ip_hdrlen(skb);
165
166 /* csum_check requires unshared skb */
167 if (!skb_make_writable(skb, sctphoff + sizeof(*sctph)))
168 return 0;
169
170 if (unlikely(cp->app != NULL)) {
171 /* Some checks before mangling */
172 if (pp->csum_check && !pp->csum_check(cp->af, skb, pp))
173 return 0;
174
175 /* Call application helper if needed */
176 if (!ip_vs_app_pkt_out(cp, skb))
177 return 0;
178 }
179
180 sctph = (void *) skb_network_header(skb) + sctphoff;
181 sctph->dest = cp->dport;
182
183 /* Calculate the checksum */
184 crc32 = sctp_start_cksum((u8 *) sctph, skb_headlen(skb) - sctphoff);
185 for (skb = skb_shinfo(skb)->frag_list; skb; skb = skb->next)
186 crc32 = sctp_update_cksum((u8 *) skb->data, skb_headlen(skb),
187 crc32);
188 crc32 = sctp_end_cksum(crc32);
189 sctph->checksum = crc32;
190
191 return 1;
192}
193
194static int
195sctp_csum_check(int af, struct sk_buff *skb, struct ip_vs_protocol *pp)
196{
197 struct sk_buff *list = skb_shinfo(skb)->frag_list;
198 unsigned int sctphoff;
199 struct sctphdr *sh, _sctph;
200 __le32 cmp;
201 __le32 val;
202 __u32 tmp;
203
204#ifdef CONFIG_IP_VS_IPV6
205 if (af == AF_INET6)
206 sctphoff = sizeof(struct ipv6hdr);
207 else
208#endif
209 sctphoff = ip_hdrlen(skb);
210
211 sh = skb_header_pointer(skb, sctphoff, sizeof(_sctph), &_sctph);
212 if (sh == NULL)
213 return 0;
214
215 cmp = sh->checksum;
216
217 tmp = sctp_start_cksum((__u8 *) sh, skb_headlen(skb));
218 for (; list; list = list->next)
219 tmp = sctp_update_cksum((__u8 *) list->data,
220 skb_headlen(list), tmp);
221
222 val = sctp_end_cksum(tmp);
223
224 if (val != cmp) {
225 /* CRC failure, dump it. */
226 IP_VS_DBG_RL_PKT(0, pp, skb, 0,
227 "Failed checksum for");
228 return 0;
229 }
230 return 1;
231}
232
233struct ipvs_sctp_nextstate {
234 int next_state;
235};
236enum ipvs_sctp_event_t {
237 IP_VS_SCTP_EVE_DATA_CLI,
238 IP_VS_SCTP_EVE_DATA_SER,
239 IP_VS_SCTP_EVE_INIT_CLI,
240 IP_VS_SCTP_EVE_INIT_SER,
241 IP_VS_SCTP_EVE_INIT_ACK_CLI,
242 IP_VS_SCTP_EVE_INIT_ACK_SER,
243 IP_VS_SCTP_EVE_COOKIE_ECHO_CLI,
244 IP_VS_SCTP_EVE_COOKIE_ECHO_SER,
245 IP_VS_SCTP_EVE_COOKIE_ACK_CLI,
246 IP_VS_SCTP_EVE_COOKIE_ACK_SER,
247 IP_VS_SCTP_EVE_ABORT_CLI,
248 IP_VS_SCTP_EVE__ABORT_SER,
249 IP_VS_SCTP_EVE_SHUT_CLI,
250 IP_VS_SCTP_EVE_SHUT_SER,
251 IP_VS_SCTP_EVE_SHUT_ACK_CLI,
252 IP_VS_SCTP_EVE_SHUT_ACK_SER,
253 IP_VS_SCTP_EVE_SHUT_COM_CLI,
254 IP_VS_SCTP_EVE_SHUT_COM_SER,
255 IP_VS_SCTP_EVE_LAST
256};
257
258static enum ipvs_sctp_event_t sctp_events[255] = {
259 IP_VS_SCTP_EVE_DATA_CLI,
260 IP_VS_SCTP_EVE_INIT_CLI,
261 IP_VS_SCTP_EVE_INIT_ACK_CLI,
262 IP_VS_SCTP_EVE_DATA_CLI,
263 IP_VS_SCTP_EVE_DATA_CLI,
264 IP_VS_SCTP_EVE_DATA_CLI,
265 IP_VS_SCTP_EVE_ABORT_CLI,
266 IP_VS_SCTP_EVE_SHUT_CLI,
267 IP_VS_SCTP_EVE_SHUT_ACK_CLI,
268 IP_VS_SCTP_EVE_DATA_CLI,
269 IP_VS_SCTP_EVE_COOKIE_ECHO_CLI,
270 IP_VS_SCTP_EVE_COOKIE_ACK_CLI,
271 IP_VS_SCTP_EVE_DATA_CLI,
272 IP_VS_SCTP_EVE_DATA_CLI,
273 IP_VS_SCTP_EVE_SHUT_COM_CLI,
274};
275
276static struct ipvs_sctp_nextstate
277 sctp_states_table[IP_VS_SCTP_S_LAST][IP_VS_SCTP_EVE_LAST] = {
278 /*
279 * STATE : IP_VS_SCTP_S_NONE
280 */
281 /*next state *//*event */
282 {{IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_DATA_CLI */ },
283 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_DATA_SER */ },
284 {IP_VS_SCTP_S_INIT_CLI /* IP_VS_SCTP_EVE_INIT_CLI */ },
285 {IP_VS_SCTP_S_INIT_SER /* IP_VS_SCTP_EVE_INIT_SER */ },
286 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_INIT_ACK_CLI */ },
287 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_INIT_ACK_SER */ },
288 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_COOKIE_ECHO_CLI */ },
289 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_COOKIE_ECHO_SER */ },
290 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_COOKIE_ACK_CLI */ },
291 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_COOKIE_ACK_SER */ },
292 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_ABORT_CLI */ },
293 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_ABORT_SER */ },
294 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_SHUT_CLI */ },
295 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_SHUT_SER */ },
296 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_SHUT_ACK_CLI */ },
297 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_SHUT_ACK_SER */ },
298 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_SHUT_COM_CLI */ },
299 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_SHUT_COM_SER */ },
300 },
301 /*
302 * STATE : IP_VS_SCTP_S_INIT_CLI
303 * Cient sent INIT and is waiting for reply from server(In ECHO_WAIT)
304 */
305 {{IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_DATA_CLI */ },
306 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_DATA_SER */ },
307 {IP_VS_SCTP_S_INIT_CLI /* IP_VS_SCTP_EVE_INIT_CLI */ },
308 {IP_VS_SCTP_S_INIT_SER /* IP_VS_SCTP_EVE_INIT_SER */ },
309 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_INIT_ACK_CLI */ },
310 {IP_VS_SCTP_S_INIT_ACK_SER /* IP_VS_SCTP_EVE_INIT_ACK_SER */ },
311 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_ECHO_CLI */ },
312 {IP_VS_SCTP_S_INIT_CLI /* IP_VS_SCTP_EVE_ECHO_SER */ },
313 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_COOKIE_ACK_CLI */ },
314 {IP_VS_SCTP_S_INIT_CLI /* IP_VS_SCTP_EVE_COOKIE_ACK_SER */ },
315 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_ABORT_CLI */ },
316 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_ABORT_SER */ },
317 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_SHUT_CLI */ },
318 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_SHUT_SER */ },
319 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_SHUT_ACK_CLI */ },
320 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_SHUT_ACK_SER */ },
321 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_SHUT_COM_CLI */ },
322 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_SHUT_COM_SER */ }
323 },
324 /*
325 * State : IP_VS_SCTP_S_INIT_SER
326 * Server sent INIT and waiting for INIT ACK from the client
327 */
328 {{IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_DATA_CLI */ },
329 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_DATA_SER */ },
330 {IP_VS_SCTP_S_INIT_CLI /* IP_VS_SCTP_EVE_INIT_CLI */ },
331 {IP_VS_SCTP_S_INIT_SER /* IP_VS_SCTP_EVE_INIT_SER */ },
332 {IP_VS_SCTP_S_INIT_ACK_CLI /* IP_VS_SCTP_EVE_INIT_ACK_CLI */ },
333 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_INIT_ACK_SER */ },
334 {IP_VS_SCTP_S_INIT_SER /* IP_VS_SCTP_EVE_COOKIE_ECHO_CLI */ },
335 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_COOKIE_ECHO_SER */ },
336 {IP_VS_SCTP_S_INIT_SER /* IP_VS_SCTP_EVE_COOKIE_ACK_CLI */ },
337 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_COOKIE_ACK_SER */ },
338 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_ABORT_CLI */ },
339 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_ABORT_SER */ },
340 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_SHUT_CLI */ },
341 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_SHUT_SER */ },
342 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_SHUT_ACK_CLI */ },
343 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_SHUT_ACK_SER */ },
344 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_SHUT_COM_CLI */ },
345 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_SHUT_COM_SER */ }
346 },
347 /*
348 * State : IP_VS_SCTP_S_INIT_ACK_CLI
349 * Client sent INIT ACK and waiting for ECHO from the server
350 */
351 {{IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_DATA_CLI */ },
352 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_DATA_SER */ },
353 /*
354 * We have got an INIT from client. From the spec.“Upon receipt of
355 * an INIT in the COOKIE-WAIT state, an endpoint MUST respond with
356 * an INIT ACK using the same parameters it sent in its original
357 * INIT chunk (including its Initiate Tag, unchanged”).
358 */
359 {IP_VS_SCTP_S_INIT_CLI /* IP_VS_SCTP_EVE_INIT_CLI */ },
360 {IP_VS_SCTP_S_INIT_SER /* IP_VS_SCTP_EVE_INIT_SER */ },
361 /*
362 * INIT_ACK has been resent by the client, let us stay is in
363 * the same state
364 */
365 {IP_VS_SCTP_S_INIT_ACK_CLI /* IP_VS_SCTP_EVE_INIT_ACK_CLI */ },
366 /*
367 * INIT_ACK sent by the server, close the connection
368 */
369 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_INIT_ACK_SER */ },
370 /*
371 * ECHO by client, it should not happen, close the connection
372 */
373 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_COOKIE_ECHO_CLI */ },
374 /*
375 * ECHO by server, this is what we are expecting, move to ECHO_SER
376 */
377 {IP_VS_SCTP_S_ECHO_SER /* IP_VS_SCTP_EVE_COOKIE_ECHO_SER */ },
378 /*
379 * COOKIE ACK from client, it should not happen, close the connection
380 */
381 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_COOKIE_ACK_CLI */ },
382 /*
383 * Unexpected COOKIE ACK from server, staty in the same state
384 */
385 {IP_VS_SCTP_S_INIT_ACK_CLI /* IP_VS_SCTP_EVE_COOKIE_ACK_SER */ },
386 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_ABORT_CLI */ },
387 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_ABORT_SER */ },
388 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_SHUT_CLI */ },
389 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_SHUT_SER */ },
390 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_SHUT_ACK_CLI */ },
391 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_SHUT_ACK_SER */ },
392 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_SHUT_COM_CLI */ },
393 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_SHUT_COM_SER */ }
394 },
395 /*
396 * State : IP_VS_SCTP_S_INIT_ACK_SER
397 * Server sent INIT ACK and waiting for ECHO from the client
398 */
399 {{IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_DATA_CLI */ },
400 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_DATA_SER */ },
401 /*
402 * We have got an INIT from client. From the spec.“Upon receipt of
403 * an INIT in the COOKIE-WAIT state, an endpoint MUST respond with
404 * an INIT ACK using the same parameters it sent in its original
405 * INIT chunk (including its Initiate Tag, unchanged”).
406 */
407 {IP_VS_SCTP_S_INIT_CLI /* IP_VS_SCTP_EVE_INIT_CLI */ },
408 {IP_VS_SCTP_S_INIT_SER /* IP_VS_SCTP_EVE_INIT_SER */ },
409 /*
410 * Unexpected INIT_ACK by the client, let us close the connection
411 */
412 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_INIT_ACK_CLI */ },
413 /*
414 * INIT_ACK resent by the server, let us move to same state
415 */
416 {IP_VS_SCTP_S_INIT_ACK_SER /* IP_VS_SCTP_EVE_INIT_ACK_SER */ },
417 /*
418 * Client send the ECHO, this is what we are expecting,
419 * move to ECHO_CLI
420 */
421 {IP_VS_SCTP_S_ECHO_CLI /* IP_VS_SCTP_EVE_COOKIE_ECHO_CLI */ },
422 /*
423 * ECHO received from the server, Not sure what to do,
424 * let us close it
425 */
426 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_COOKIE_ECHO_SER */ },
427 /*
428 * COOKIE ACK from client, let us stay in the same state
429 */
430 {IP_VS_SCTP_S_INIT_ACK_SER /* IP_VS_SCTP_EVE_COOKIE_ACK_CLI */ },
431 /*
432 * COOKIE ACK from server, hmm... this should not happen, lets close
433 * the connection.
434 */
435 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_COOKIE_ACK_SER */ },
436 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_ABORT_CLI */ },
437 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_ABORT_SER */ },
438 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_SHUT_CLI */ },
439 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_SHUT_SER */ },
440 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_SHUT_ACK_CLI */ },
441 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_SHUT_ACK_SER */ },
442 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_SHUT_COM_CLI */ },
443 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_SHUT_COM_SER */ }
444 },
445 /*
446 * State : IP_VS_SCTP_S_ECHO_CLI
447 * Cient sent ECHO and waiting COOKEI ACK from the Server
448 */
449 {{IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_DATA_CLI */ },
450 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_DATA_SER */ },
451 /*
452 * We have got an INIT from client. From the spec.“Upon receipt of
453 * an INIT in the COOKIE-WAIT state, an endpoint MUST respond with
454 * an INIT ACK using the same parameters it sent in its original
455 * INIT chunk (including its Initiate Tag, unchanged”).
456 */
457 {IP_VS_SCTP_S_INIT_CLI /* IP_VS_SCTP_EVE_INIT_CLI */ },
458 {IP_VS_SCTP_S_INIT_SER /* IP_VS_SCTP_EVE_INIT_SER */ },
459 /*
460 * INIT_ACK has been by the client, let us close the connection
461 */
462 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_INIT_ACK_CLI */ },
463 /*
464 * INIT_ACK sent by the server, Unexpected INIT ACK, spec says,
465 * “If an INIT ACK is received by an endpoint in any state other
466 * than the COOKIE-WAIT state, the endpoint should discard the
467 * INIT ACK chunk”. Stay in the same state
468 */
469 {IP_VS_SCTP_S_ECHO_CLI /* IP_VS_SCTP_EVE_INIT_ACK_SER */ },
470 /*
471 * Client resent the ECHO, let us stay in the same state
472 */
473 {IP_VS_SCTP_S_ECHO_CLI /* IP_VS_SCTP_EVE_COOKIE_ECHO_CLI */ },
474 /*
475 * ECHO received from the server, Not sure what to do,
476 * let us close it
477 */
478 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_COOKIE_ECHO_SER */ },
479 /*
480 * COOKIE ACK from client, this shoud not happen, let's close the
481 * connection
482 */
483 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_COOKIE_ACK_CLI */ },
484 /*
485 * COOKIE ACK from server, this is what we are awaiting,lets move to
486 * ESTABLISHED.
487 */
488 {IP_VS_SCTP_S_ESTABLISHED /* IP_VS_SCTP_EVE_COOKIE_ACK_SER */ },
489 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_ABORT_CLI */ },
490 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_ABORT_SER */ },
491 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_SHUT_CLI */ },
492 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_SHUT_SER */ },
493 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_SHUT_ACK_CLI */ },
494 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_SHUT_ACK_SER */ },
495 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_SHUT_COM_CLI */ },
496 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_SHUT_COM_SER */ }
497 },
498 /*
499 * State : IP_VS_SCTP_S_ECHO_SER
500 * Server sent ECHO and waiting COOKEI ACK from the client
501 */
502 {{IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_DATA_CLI */ },
503 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_DATA_SER */ },
504 /*
505 * We have got an INIT from client. From the spec.“Upon receipt of
506 * an INIT in the COOKIE-WAIT state, an endpoint MUST respond with
507 * an INIT ACK using the same parameters it sent in its original
508 * INIT chunk (including its Initiate Tag, unchanged”).
509 */
510 {IP_VS_SCTP_S_INIT_CLI /* IP_VS_SCTP_EVE_INIT_CLI */ },
511 {IP_VS_SCTP_S_INIT_SER /* IP_VS_SCTP_EVE_INIT_SER */ },
512 /*
513 * INIT_ACK sent by the server, Unexpected INIT ACK, spec says,
514 * “If an INIT ACK is received by an endpoint in any state other
515 * than the COOKIE-WAIT state, the endpoint should discard the
516 * INIT ACK chunk”. Stay in the same state
517 */
518 {IP_VS_SCTP_S_ECHO_SER /* IP_VS_SCTP_EVE_INIT_ACK_CLI */ },
519 /*
520 * INIT_ACK has been by the server, let us close the connection
521 */
522 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_INIT_ACK_SER */ },
523 /*
524 * Client sent the ECHO, not sure what to do, let's close the
525 * connection.
526 */
527 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_COOKIE_ECHO_CLI */ },
528 /*
529 * ECHO resent by the server, stay in the same state
530 */
531 {IP_VS_SCTP_S_ECHO_SER /* IP_VS_SCTP_EVE_COOKIE_ECHO_SER */ },
532 /*
533 * COOKIE ACK from client, this is what we are expecting, let's move
534 * to ESTABLISHED.
535 */
536 {IP_VS_SCTP_S_ESTABLISHED /* IP_VS_SCTP_EVE_COOKIE_ACK_CLI */ },
537 /*
538 * COOKIE ACK from server, this should not happen, lets close the
539 * connection.
540 */
541 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_COOKIE_ACK_SER */ },
542 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_ABORT_CLI */ },
543 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_ABORT_SER */ },
544 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_SHUT_CLI */ },
545 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_SHUT_SER */ },
546 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_SHUT_ACK_CLI */ },
547 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_SHUT_ACK_SER */ },
548 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_SHUT_COM_CLI */ },
549 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_SHUT_COM_SER */ }
550 },
551 /*
552 * State : IP_VS_SCTP_S_ESTABLISHED
553 * Association established
554 */
555 {{IP_VS_SCTP_S_ESTABLISHED /* IP_VS_SCTP_EVE_DATA_CLI */ },
556 {IP_VS_SCTP_S_ESTABLISHED /* IP_VS_SCTP_EVE_DATA_SER */ },
557 /*
558 * We have got an INIT from client. From the spec.“Upon receipt of
559 * an INIT in the COOKIE-WAIT state, an endpoint MUST respond with
560 * an INIT ACK using the same parameters it sent in its original
561 * INIT chunk (including its Initiate Tag, unchanged”).
562 */
563 {IP_VS_SCTP_S_INIT_CLI /* IP_VS_SCTP_EVE_INIT_CLI */ },
564 {IP_VS_SCTP_S_INIT_SER /* IP_VS_SCTP_EVE_INIT_SER */ },
565 /*
566 * INIT_ACK sent by the server, Unexpected INIT ACK, spec says,
567 * “If an INIT ACK is received by an endpoint in any state other
568 * than the COOKIE-WAIT state, the endpoint should discard the
569 * INIT ACK chunk”. Stay in the same state
570 */
571 {IP_VS_SCTP_S_ESTABLISHED /* IP_VS_SCTP_EVE_INIT_ACK_CLI */ },
572 {IP_VS_SCTP_S_ESTABLISHED /* IP_VS_SCTP_EVE_INIT_ACK_SER */ },
573 /*
574 * Client sent ECHO, Spec(sec 5.2.4) says it may be handled by the
575 * peer and peer shall move to the ESTABISHED. if it doesn't handle
576 * it will send ERROR chunk. So, stay in the same state
577 */
578 {IP_VS_SCTP_S_ESTABLISHED /* IP_VS_SCTP_EVE_COOKIE_ECHO_CLI */ },
579 {IP_VS_SCTP_S_ESTABLISHED /* IP_VS_SCTP_EVE_COOKIE_ECHO_SER */ },
580 /*
581 * COOKIE ACK from client, not sure what to do stay in the same state
582 */
583 {IP_VS_SCTP_S_ESTABLISHED /* IP_VS_SCTP_EVE_COOKIE_ACK_CLI */ },
584 {IP_VS_SCTP_S_ESTABLISHED /* IP_VS_SCTP_EVE_COOKIE_ACK_SER */ },
585 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_ABORT_CLI */ },
586 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_ABORT_SER */ },
587 /*
588 * SHUTDOWN from the client, move to SHUDDOWN_CLI
589 */
590 {IP_VS_SCTP_S_SHUT_CLI /* IP_VS_SCTP_EVE_SHUT_CLI */ },
591 /*
592 * SHUTDOWN from the server, move to SHUTDOWN_SER
593 */
594 {IP_VS_SCTP_S_SHUT_SER /* IP_VS_SCTP_EVE_SHUT_SER */ },
595 /*
596 * client sent SHUDTDOWN_ACK, this should not happen, let's close
597 * the connection
598 */
599 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_SHUT_ACK_CLI */ },
600 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_SHUT_ACK_SER */ },
601 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_SHUT_COM_CLI */ },
602 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_SHUT_COM_SER */ }
603 },
604 /*
605 * State : IP_VS_SCTP_S_SHUT_CLI
606 * SHUTDOWN sent from the client, waitinf for SHUT ACK from the server
607 */
608 /*
609 * We recieved the data chuck, keep the state unchanged. I assume
610 * that still data chuncks can be received by both the peers in
611 * SHUDOWN state
612 */
613
614 {{IP_VS_SCTP_S_SHUT_CLI /* IP_VS_SCTP_EVE_DATA_CLI */ },
615 {IP_VS_SCTP_S_SHUT_CLI /* IP_VS_SCTP_EVE_DATA_SER */ },
616 /*
617 * We have got an INIT from client. From the spec.“Upon receipt of
618 * an INIT in the COOKIE-WAIT state, an endpoint MUST respond with
619 * an INIT ACK using the same parameters it sent in its original
620 * INIT chunk (including its Initiate Tag, unchanged”).
621 */
622 {IP_VS_SCTP_S_INIT_CLI /* IP_VS_SCTP_EVE_INIT_CLI */ },
623 {IP_VS_SCTP_S_INIT_SER /* IP_VS_SCTP_EVE_INIT_SER */ },
624 /*
625 * INIT_ACK sent by the server, Unexpected INIT ACK, spec says,
626 * “If an INIT ACK is received by an endpoint in any state other
627 * than the COOKIE-WAIT state, the endpoint should discard the
628 * INIT ACK chunk”. Stay in the same state
629 */
630 {IP_VS_SCTP_S_SHUT_CLI /* IP_VS_SCTP_EVE_INIT_ACK_CLI */ },
631 {IP_VS_SCTP_S_SHUT_CLI /* IP_VS_SCTP_EVE_INIT_ACK_SER */ },
632 /*
633 * Client sent ECHO, Spec(sec 5.2.4) says it may be handled by the
634 * peer and peer shall move to the ESTABISHED. if it doesn't handle
635 * it will send ERROR chunk. So, stay in the same state
636 */
637 {IP_VS_SCTP_S_ESTABLISHED /* IP_VS_SCTP_EVE_COOKIE_ECHO_CLI */ },
638 {IP_VS_SCTP_S_ESTABLISHED /* IP_VS_SCTP_EVE_COOKIE_ECHO_SER */ },
639 /*
640 * COOKIE ACK from client, not sure what to do stay in the same state
641 */
642 {IP_VS_SCTP_S_SHUT_CLI /* IP_VS_SCTP_EVE_COOKIE_ACK_CLI */ },
643 {IP_VS_SCTP_S_SHUT_CLI /* IP_VS_SCTP_EVE_COOKIE_ACK_SER */ },
644 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_ABORT_CLI */ },
645 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_ABORT_SER */ },
646 /*
647 * SHUTDOWN resent from the client, move to SHUDDOWN_CLI
648 */
649 {IP_VS_SCTP_S_SHUT_CLI /* IP_VS_SCTP_EVE_SHUT_CLI */ },
650 /*
651 * SHUTDOWN from the server, move to SHUTDOWN_SER
652 */
653 {IP_VS_SCTP_S_SHUT_SER /* IP_VS_SCTP_EVE_SHUT_SER */ },
654 /*
655 * client sent SHUDTDOWN_ACK, this should not happen, let's close
656 * the connection
657 */
658 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_SHUT_ACK_CLI */ },
659 /*
660 * Server sent SHUTDOWN ACK, this is what we are expecting, let's move
661 * to SHUDOWN_ACK_SER
662 */
663 {IP_VS_SCTP_S_SHUT_ACK_SER /* IP_VS_SCTP_EVE_SHUT_ACK_SER */ },
664 /*
665 * SHUTDOWN COM from client, this should not happen, let's close the
666 * connection
667 */
668 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_SHUT_COM_CLI */ },
669 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_SHUT_COM_SER */ }
670 },
671 /*
672 * State : IP_VS_SCTP_S_SHUT_SER
673 * SHUTDOWN sent from the server, waitinf for SHUTDOWN ACK from client
674 */
675 /*
676 * We recieved the data chuck, keep the state unchanged. I assume
677 * that still data chuncks can be received by both the peers in
678 * SHUDOWN state
679 */
680
681 {{IP_VS_SCTP_S_SHUT_SER /* IP_VS_SCTP_EVE_DATA_CLI */ },
682 {IP_VS_SCTP_S_SHUT_SER /* IP_VS_SCTP_EVE_DATA_SER */ },
683 /*
684 * We have got an INIT from client. From the spec.“Upon receipt of
685 * an INIT in the COOKIE-WAIT state, an endpoint MUST respond with
686 * an INIT ACK using the same parameters it sent in its original
687 * INIT chunk (including its Initiate Tag, unchanged”).
688 */
689 {IP_VS_SCTP_S_INIT_CLI /* IP_VS_SCTP_EVE_INIT_CLI */ },
690 {IP_VS_SCTP_S_INIT_SER /* IP_VS_SCTP_EVE_INIT_SER */ },
691 /*
692 * INIT_ACK sent by the server, Unexpected INIT ACK, spec says,
693 * “If an INIT ACK is received by an endpoint in any state other
694 * than the COOKIE-WAIT state, the endpoint should discard the
695 * INIT ACK chunk”. Stay in the same state
696 */
697 {IP_VS_SCTP_S_SHUT_SER /* IP_VS_SCTP_EVE_INIT_ACK_CLI */ },
698 {IP_VS_SCTP_S_SHUT_SER /* IP_VS_SCTP_EVE_INIT_ACK_SER */ },
699 /*
700 * Client sent ECHO, Spec(sec 5.2.4) says it may be handled by the
701 * peer and peer shall move to the ESTABISHED. if it doesn't handle
702 * it will send ERROR chunk. So, stay in the same state
703 */
704 {IP_VS_SCTP_S_ESTABLISHED /* IP_VS_SCTP_EVE_COOKIE_ECHO_CLI */ },
705 {IP_VS_SCTP_S_ESTABLISHED /* IP_VS_SCTP_EVE_COOKIE_ECHO_SER */ },
706 /*
707 * COOKIE ACK from client, not sure what to do stay in the same state
708 */
709 {IP_VS_SCTP_S_SHUT_SER /* IP_VS_SCTP_EVE_COOKIE_ACK_CLI */ },
710 {IP_VS_SCTP_S_SHUT_SER /* IP_VS_SCTP_EVE_COOKIE_ACK_SER */ },
711 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_ABORT_CLI */ },
712 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_ABORT_SER */ },
713 /*
714 * SHUTDOWN resent from the client, move to SHUDDOWN_CLI
715 */
716 {IP_VS_SCTP_S_SHUT_CLI /* IP_VS_SCTP_EVE_SHUT_CLI */ },
717 /*
718 * SHUTDOWN resent from the server, move to SHUTDOWN_SER
719 */
720 {IP_VS_SCTP_S_SHUT_SER /* IP_VS_SCTP_EVE_SHUT_SER */ },
721 /*
722 * client sent SHUDTDOWN_ACK, this is what we are expecting, let's
723 * move to SHUT_ACK_CLI
724 */
725 {IP_VS_SCTP_S_SHUT_ACK_CLI /* IP_VS_SCTP_EVE_SHUT_ACK_CLI */ },
726 /*
727 * Server sent SHUTDOWN ACK, this should not happen, let's close the
728 * connection
729 */
730 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_SHUT_ACK_SER */ },
731 /*
732 * SHUTDOWN COM from client, this should not happen, let's close the
733 * connection
734 */
735 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_SHUT_COM_CLI */ },
736 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_SHUT_COM_SER */ }
737 },
738
739 /*
740 * State : IP_VS_SCTP_S_SHUT_ACK_CLI
741 * SHUTDOWN ACK from the client, awaiting for SHUTDOWN COM from server
742 */
743 /*
744 * We recieved the data chuck, keep the state unchanged. I assume
745 * that still data chuncks can be received by both the peers in
746 * SHUDOWN state
747 */
748
749 {{IP_VS_SCTP_S_SHUT_ACK_CLI /* IP_VS_SCTP_EVE_DATA_CLI */ },
750 {IP_VS_SCTP_S_SHUT_ACK_CLI /* IP_VS_SCTP_EVE_DATA_SER */ },
751 /*
752 * We have got an INIT from client. From the spec.“Upon receipt of
753 * an INIT in the COOKIE-WAIT state, an endpoint MUST respond with
754 * an INIT ACK using the same parameters it sent in its original
755 * INIT chunk (including its Initiate Tag, unchanged”).
756 */
757 {IP_VS_SCTP_S_INIT_CLI /* IP_VS_SCTP_EVE_INIT_CLI */ },
758 {IP_VS_SCTP_S_INIT_SER /* IP_VS_SCTP_EVE_INIT_SER */ },
759 /*
760 * INIT_ACK sent by the server, Unexpected INIT ACK, spec says,
761 * “If an INIT ACK is received by an endpoint in any state other
762 * than the COOKIE-WAIT state, the endpoint should discard the
763 * INIT ACK chunk”. Stay in the same state
764 */
765 {IP_VS_SCTP_S_SHUT_ACK_CLI /* IP_VS_SCTP_EVE_INIT_ACK_CLI */ },
766 {IP_VS_SCTP_S_SHUT_ACK_CLI /* IP_VS_SCTP_EVE_INIT_ACK_SER */ },
767 /*
768 * Client sent ECHO, Spec(sec 5.2.4) says it may be handled by the
769 * peer and peer shall move to the ESTABISHED. if it doesn't handle
770 * it will send ERROR chunk. So, stay in the same state
771 */
772 {IP_VS_SCTP_S_ESTABLISHED /* IP_VS_SCTP_EVE_COOKIE_ECHO_CLI */ },
773 {IP_VS_SCTP_S_ESTABLISHED /* IP_VS_SCTP_EVE_COOKIE_ECHO_SER */ },
774 /*
775 * COOKIE ACK from client, not sure what to do stay in the same state
776 */
777 {IP_VS_SCTP_S_SHUT_ACK_CLI /* IP_VS_SCTP_EVE_COOKIE_ACK_CLI */ },
778 {IP_VS_SCTP_S_SHUT_ACK_CLI /* IP_VS_SCTP_EVE_COOKIE_ACK_SER */ },
779 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_ABORT_CLI */ },
780 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_ABORT_SER */ },
781 /*
782 * SHUTDOWN sent from the client, move to SHUDDOWN_CLI
783 */
784 {IP_VS_SCTP_S_SHUT_CLI /* IP_VS_SCTP_EVE_SHUT_CLI */ },
785 /*
786 * SHUTDOWN sent from the server, move to SHUTDOWN_SER
787 */
788 {IP_VS_SCTP_S_SHUT_SER /* IP_VS_SCTP_EVE_SHUT_SER */ },
789 /*
790 * client resent SHUDTDOWN_ACK, let's stay in the same state
791 */
792 {IP_VS_SCTP_S_SHUT_ACK_CLI /* IP_VS_SCTP_EVE_SHUT_ACK_CLI */ },
793 /*
794 * Server sent SHUTDOWN ACK, this should not happen, let's close the
795 * connection
796 */
797 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_SHUT_ACK_SER */ },
798 /*
799 * SHUTDOWN COM from client, this should not happen, let's close the
800 * connection
801 */
802 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_SHUT_COM_CLI */ },
803 /*
804 * SHUTDOWN COMPLETE from server this is what we are expecting.
805 */
806 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_SHUT_COM_SER */ }
807 },
808
809 /*
810 * State : IP_VS_SCTP_S_SHUT_ACK_SER
811 * SHUTDOWN ACK from the server, awaiting for SHUTDOWN COM from client
812 */
813 /*
814 * We recieved the data chuck, keep the state unchanged. I assume
815 * that still data chuncks can be received by both the peers in
816 * SHUDOWN state
817 */
818
819 {{IP_VS_SCTP_S_SHUT_ACK_SER /* IP_VS_SCTP_EVE_DATA_CLI */ },
820 {IP_VS_SCTP_S_SHUT_ACK_SER /* IP_VS_SCTP_EVE_DATA_SER */ },
821 /*
822 * We have got an INIT from client. From the spec.“Upon receipt of
823 * an INIT in the COOKIE-WAIT state, an endpoint MUST respond with
824 * an INIT ACK using the same parameters it sent in its original
825 * INIT chunk (including its Initiate Tag, unchanged”).
826 */
827 {IP_VS_SCTP_S_INIT_CLI /* IP_VS_SCTP_EVE_INIT_CLI */ },
828 {IP_VS_SCTP_S_INIT_SER /* IP_VS_SCTP_EVE_INIT_SER */ },
829 /*
830 * INIT_ACK sent by the server, Unexpected INIT ACK, spec says,
831 * “If an INIT ACK is received by an endpoint in any state other
832 * than the COOKIE-WAIT state, the endpoint should discard the
833 * INIT ACK chunk”. Stay in the same state
834 */
835 {IP_VS_SCTP_S_SHUT_ACK_SER /* IP_VS_SCTP_EVE_INIT_ACK_CLI */ },
836 {IP_VS_SCTP_S_SHUT_ACK_SER /* IP_VS_SCTP_EVE_INIT_ACK_SER */ },
837 /*
838 * Client sent ECHO, Spec(sec 5.2.4) says it may be handled by the
839 * peer and peer shall move to the ESTABISHED. if it doesn't handle
840 * it will send ERROR chunk. So, stay in the same state
841 */
842 {IP_VS_SCTP_S_ESTABLISHED /* IP_VS_SCTP_EVE_COOKIE_ECHO_CLI */ },
843 {IP_VS_SCTP_S_ESTABLISHED /* IP_VS_SCTP_EVE_COOKIE_ECHO_SER */ },
844 /*
845 * COOKIE ACK from client, not sure what to do stay in the same state
846 */
847 {IP_VS_SCTP_S_SHUT_ACK_SER /* IP_VS_SCTP_EVE_COOKIE_ACK_CLI */ },
848 {IP_VS_SCTP_S_SHUT_ACK_SER /* IP_VS_SCTP_EVE_COOKIE_ACK_SER */ },
849 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_ABORT_CLI */ },
850 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_ABORT_SER */ },
851 /*
852 * SHUTDOWN sent from the client, move to SHUDDOWN_CLI
853 */
854 {IP_VS_SCTP_S_SHUT_CLI /* IP_VS_SCTP_EVE_SHUT_CLI */ },
855 /*
856 * SHUTDOWN sent from the server, move to SHUTDOWN_SER
857 */
858 {IP_VS_SCTP_S_SHUT_SER /* IP_VS_SCTP_EVE_SHUT_SER */ },
859 /*
860 * client sent SHUDTDOWN_ACK, this should not happen let's close
861 * the connection.
862 */
863 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_SHUT_ACK_CLI */ },
864 /*
865 * Server resent SHUTDOWN ACK, stay in the same state
866 */
867 {IP_VS_SCTP_S_SHUT_ACK_SER /* IP_VS_SCTP_EVE_SHUT_ACK_SER */ },
868 /*
869 * SHUTDOWN COM from client, this what we are expecting, let's close
870 * the connection
871 */
872 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_SHUT_COM_CLI */ },
873 /*
874 * SHUTDOWN COMPLETE from server this should not happen.
875 */
876 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_SHUT_COM_SER */ }
877 },
878 /*
879 * State : IP_VS_SCTP_S_CLOSED
880 */
881 {{IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_DATA_CLI */ },
882 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_DATA_SER */ },
883 {IP_VS_SCTP_S_INIT_CLI /* IP_VS_SCTP_EVE_INIT_CLI */ },
884 {IP_VS_SCTP_S_INIT_SER /* IP_VS_SCTP_EVE_INIT_SER */ },
885 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_INIT_ACK_CLI */ },
886 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_INIT_ACK_SER */ },
887 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_COOKIE_ECHO_CLI */ },
888 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_COOKIE_ECHO_SER */ },
889 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_COOKIE_ACK_CLI */ },
890 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_COOKIE_ACK_SER */ },
891 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_ABORT_CLI */ },
892 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_ABORT_SER */ },
893 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_SHUT_CLI */ },
894 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_SHUT_SER */ },
895 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_SHUT_ACK_CLI */ },
896 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_SHUT_ACK_SER */ },
897 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_SHUT_COM_CLI */ },
898 {IP_VS_SCTP_S_CLOSED /* IP_VS_SCTP_EVE_SHUT_COM_SER */ }
899 }
900};
901
902/*
903 * Timeout table[state]
904 */
905static int sctp_timeouts[IP_VS_SCTP_S_LAST + 1] = {
906 [IP_VS_SCTP_S_NONE] = 2 * HZ,
907 [IP_VS_SCTP_S_INIT_CLI] = 1 * 60 * HZ,
908 [IP_VS_SCTP_S_INIT_SER] = 1 * 60 * HZ,
909 [IP_VS_SCTP_S_INIT_ACK_CLI] = 1 * 60 * HZ,
910 [IP_VS_SCTP_S_INIT_ACK_SER] = 1 * 60 * HZ,
911 [IP_VS_SCTP_S_ECHO_CLI] = 1 * 60 * HZ,
912 [IP_VS_SCTP_S_ECHO_SER] = 1 * 60 * HZ,
913 [IP_VS_SCTP_S_ESTABLISHED] = 15 * 60 * HZ,
914 [IP_VS_SCTP_S_SHUT_CLI] = 1 * 60 * HZ,
915 [IP_VS_SCTP_S_SHUT_SER] = 1 * 60 * HZ,
916 [IP_VS_SCTP_S_SHUT_ACK_CLI] = 1 * 60 * HZ,
917 [IP_VS_SCTP_S_SHUT_ACK_SER] = 1 * 60 * HZ,
918 [IP_VS_SCTP_S_CLOSED] = 10 * HZ,
919 [IP_VS_SCTP_S_LAST] = 2 * HZ,
920};
921
922static const char *sctp_state_name_table[IP_VS_SCTP_S_LAST + 1] = {
923 [IP_VS_SCTP_S_NONE] = "NONE",
924 [IP_VS_SCTP_S_INIT_CLI] = "INIT_CLI",
925 [IP_VS_SCTP_S_INIT_SER] = "INIT_SER",
926 [IP_VS_SCTP_S_INIT_ACK_CLI] = "INIT_ACK_CLI",
927 [IP_VS_SCTP_S_INIT_ACK_SER] = "INIT_ACK_SER",
928 [IP_VS_SCTP_S_ECHO_CLI] = "COOKIE_ECHO_CLI",
929 [IP_VS_SCTP_S_ECHO_SER] = "COOKIE_ECHO_SER",
930 [IP_VS_SCTP_S_ESTABLISHED] = "ESTABISHED",
931 [IP_VS_SCTP_S_SHUT_CLI] = "SHUTDOWN_CLI",
932 [IP_VS_SCTP_S_SHUT_SER] = "SHUTDOWN_SER",
933 [IP_VS_SCTP_S_SHUT_ACK_CLI] = "SHUTDOWN_ACK_CLI",
934 [IP_VS_SCTP_S_SHUT_ACK_SER] = "SHUTDOWN_ACK_SER",
935 [IP_VS_SCTP_S_CLOSED] = "CLOSED",
936 [IP_VS_SCTP_S_LAST] = "BUG!"
937};
938
939
940static const char *sctp_state_name(int state)
941{
942 if (state >= IP_VS_SCTP_S_LAST)
943 return "ERR!";
944 if (sctp_state_name_table[state])
945 return sctp_state_name_table[state];
946 return "?";
947}
948
949static void sctp_timeout_change(struct ip_vs_protocol *pp, int flags)
950{
951}
952
953static int
954sctp_set_state_timeout(struct ip_vs_protocol *pp, char *sname, int to)
955{
956
957return ip_vs_set_state_timeout(pp->timeout_table, IP_VS_SCTP_S_LAST,
958 sctp_state_name_table, sname, to);
959}
960
961static inline int
962set_sctp_state(struct ip_vs_protocol *pp, struct ip_vs_conn *cp,
963 int direction, const struct sk_buff *skb)
964{
965 sctp_chunkhdr_t _sctpch, *sch;
966 unsigned char chunk_type;
967 int event, next_state;
968 int ihl;
969
970#ifdef CONFIG_IP_VS_IPV6
971 ihl = cp->af == AF_INET ? ip_hdrlen(skb) : sizeof(struct ipv6hdr);
972#else
973 ihl = ip_hdrlen(skb);
974#endif
975
976 sch = skb_header_pointer(skb, ihl + sizeof(sctp_sctphdr_t),
977 sizeof(_sctpch), &_sctpch);
978 if (sch == NULL)
979 return 0;
980
981 chunk_type = sch->type;
982 /*
983 * Section 3: Multiple chunks can be bundled into one SCTP packet
984 * up to the MTU size, except for the INIT, INIT ACK, and
985 * SHUTDOWN COMPLETE chunks. These chunks MUST NOT be bundled with
986 * any other chunk in a packet.
987 *
988 * Section 3.3.7: DATA chunks MUST NOT be bundled with ABORT. Control
989 * chunks (except for INIT, INIT ACK, and SHUTDOWN COMPLETE) MAY be
990 * bundled with an ABORT, but they MUST be placed before the ABORT
991 * in the SCTP packet or they will be ignored by the receiver.
992 */
993 if ((sch->type == SCTP_CID_COOKIE_ECHO) ||
994 (sch->type == SCTP_CID_COOKIE_ACK)) {
995 sch = skb_header_pointer(skb, (ihl + sizeof(sctp_sctphdr_t) +
996 sch->length), sizeof(_sctpch), &_sctpch);
997 if (sch) {
998 if (sch->type == SCTP_CID_ABORT)
999 chunk_type = sch->type;
1000 }
1001 }
1002
1003 event = sctp_events[chunk_type];
1004
1005 /*
1006 * If the direction is IP_VS_DIR_OUTPUT, this event is from server
1007 */
1008 if (direction == IP_VS_DIR_OUTPUT)
1009 event++;
1010 /*
1011 * get next state
1012 */
1013 next_state = sctp_states_table[cp->state][event].next_state;
1014
1015 if (next_state != cp->state) {
1016 struct ip_vs_dest *dest = cp->dest;
1017
1018 IP_VS_DBG_BUF(8, "%s %s %s:%d->"
1019 "%s:%d state: %s->%s conn->refcnt:%d\n",
1020 pp->name,
1021 ((direction == IP_VS_DIR_OUTPUT) ?
1022 "output " : "input "),
1023 IP_VS_DBG_ADDR(cp->af, &cp->daddr),
1024 ntohs(cp->dport),
1025 IP_VS_DBG_ADDR(cp->af, &cp->caddr),
1026 ntohs(cp->cport),
1027 sctp_state_name(cp->state),
1028 sctp_state_name(next_state),
1029 atomic_read(&cp->refcnt));
1030 if (dest) {
1031 if (!(cp->flags & IP_VS_CONN_F_INACTIVE) &&
1032 (next_state != IP_VS_SCTP_S_ESTABLISHED)) {
1033 atomic_dec(&dest->activeconns);
1034 atomic_inc(&dest->inactconns);
1035 cp->flags |= IP_VS_CONN_F_INACTIVE;
1036 } else if ((cp->flags & IP_VS_CONN_F_INACTIVE) &&
1037 (next_state == IP_VS_SCTP_S_ESTABLISHED)) {
1038 atomic_inc(&dest->activeconns);
1039 atomic_dec(&dest->inactconns);
1040 cp->flags &= ~IP_VS_CONN_F_INACTIVE;
1041 }
1042 }
1043 }
1044
1045 cp->timeout = pp->timeout_table[cp->state = next_state];
1046
1047 return 1;
1048}
1049
1050static int
1051sctp_state_transition(struct ip_vs_conn *cp, int direction,
1052 const struct sk_buff *skb, struct ip_vs_protocol *pp)
1053{
1054 int ret = 0;
1055
1056 spin_lock(&cp->lock);
1057 ret = set_sctp_state(pp, cp, direction, skb);
1058 spin_unlock(&cp->lock);
1059
1060 return ret;
1061}
1062
1063/*
1064 * Hash table for SCTP application incarnations
1065 */
1066#define SCTP_APP_TAB_BITS 4
1067#define SCTP_APP_TAB_SIZE (1 << SCTP_APP_TAB_BITS)
1068#define SCTP_APP_TAB_MASK (SCTP_APP_TAB_SIZE - 1)
1069
1070static struct list_head sctp_apps[SCTP_APP_TAB_SIZE];
1071static DEFINE_SPINLOCK(sctp_app_lock);
1072
1073static inline __u16 sctp_app_hashkey(__be16 port)
1074{
1075 return (((__force u16)port >> SCTP_APP_TAB_BITS) ^ (__force u16)port)
1076 & SCTP_APP_TAB_MASK;
1077}
1078
1079static int sctp_register_app(struct ip_vs_app *inc)
1080{
1081 struct ip_vs_app *i;
1082 __u16 hash;
1083 __be16 port = inc->port;
1084 int ret = 0;
1085
1086 hash = sctp_app_hashkey(port);
1087
1088 spin_lock_bh(&sctp_app_lock);
1089 list_for_each_entry(i, &sctp_apps[hash], p_list) {
1090 if (i->port == port) {
1091 ret = -EEXIST;
1092 goto out;
1093 }
1094 }
1095 list_add(&inc->p_list, &sctp_apps[hash]);
1096 atomic_inc(&ip_vs_protocol_sctp.appcnt);
1097out:
1098 spin_unlock_bh(&sctp_app_lock);
1099
1100 return ret;
1101}
1102
1103static void sctp_unregister_app(struct ip_vs_app *inc)
1104{
1105 spin_lock_bh(&sctp_app_lock);
1106 atomic_dec(&ip_vs_protocol_sctp.appcnt);
1107 list_del(&inc->p_list);
1108 spin_unlock_bh(&sctp_app_lock);
1109}
1110
1111static int sctp_app_conn_bind(struct ip_vs_conn *cp)
1112{
1113 int hash;
1114 struct ip_vs_app *inc;
1115 int result = 0;
1116
1117 /* Default binding: bind app only for NAT */
1118 if (IP_VS_FWD_METHOD(cp) != IP_VS_CONN_F_MASQ)
1119 return 0;
1120 /* Lookup application incarnations and bind the right one */
1121 hash = sctp_app_hashkey(cp->vport);
1122
1123 spin_lock(&sctp_app_lock);
1124 list_for_each_entry(inc, &sctp_apps[hash], p_list) {
1125 if (inc->port == cp->vport) {
1126 if (unlikely(!ip_vs_app_inc_get(inc)))
1127 break;
1128 spin_unlock(&sctp_app_lock);
1129
1130 IP_VS_DBG_BUF(9, "%s: Binding conn %s:%u->"
1131 "%s:%u to app %s on port %u\n",
1132 __func__,
1133 IP_VS_DBG_ADDR(cp->af, &cp->caddr),
1134 ntohs(cp->cport),
1135 IP_VS_DBG_ADDR(cp->af, &cp->vaddr),
1136 ntohs(cp->vport),
1137 inc->name, ntohs(inc->port));
1138 cp->app = inc;
1139 if (inc->init_conn)
1140 result = inc->init_conn(inc, cp);
1141 goto out;
1142 }
1143 }
1144 spin_unlock(&sctp_app_lock);
1145out:
1146 return result;
1147}
1148
1149static void ip_vs_sctp_init(struct ip_vs_protocol *pp)
1150{
1151 IP_VS_INIT_HASH_TABLE(sctp_apps);
1152 pp->timeout_table = sctp_timeouts;
1153}
1154
1155
1156static void ip_vs_sctp_exit(struct ip_vs_protocol *pp)
1157{
1158
1159}
1160
1161struct ip_vs_protocol ip_vs_protocol_sctp = {
1162 .name = "SCTP",
1163 .protocol = IPPROTO_SCTP,
1164 .num_states = IP_VS_SCTP_S_LAST,
1165 .dont_defrag = 0,
1166 .appcnt = ATOMIC_INIT(0),
1167 .init = ip_vs_sctp_init,
1168 .exit = ip_vs_sctp_exit,
1169 .register_app = sctp_register_app,
1170 .unregister_app = sctp_unregister_app,
1171 .conn_schedule = sctp_conn_schedule,
1172 .conn_in_get = sctp_conn_in_get,
1173 .conn_out_get = sctp_conn_out_get,
1174 .snat_handler = sctp_snat_handler,
1175 .dnat_handler = sctp_dnat_handler,
1176 .csum_check = sctp_csum_check,
1177 .state_name = sctp_state_name,
1178 .state_transition = sctp_state_transition,
1179 .app_conn_bind = sctp_app_conn_bind,
1180 .debug_packet = ip_vs_tcpudp_debug_packet,
1181 .timeout_change = sctp_timeout_change,
1182 .set_state_timeout = sctp_set_state_timeout,
1183};
diff --git a/net/netfilter/ipvs/ip_vs_sh.c b/net/netfilter/ipvs/ip_vs_sh.c
index 8e6cfd36e6f0..e6cc174fbc06 100644
--- a/net/netfilter/ipvs/ip_vs_sh.c
+++ b/net/netfilter/ipvs/ip_vs_sh.c
@@ -36,6 +36,7 @@
36#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt 36#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
37 37
38#include <linux/ip.h> 38#include <linux/ip.h>
39#include <linux/slab.h>
39#include <linux/module.h> 40#include <linux/module.h>
40#include <linux/kernel.h> 41#include <linux/kernel.h>
41#include <linux/skbuff.h> 42#include <linux/skbuff.h>
diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
index e177f0dc2084..8fb0ae616761 100644
--- a/net/netfilter/ipvs/ip_vs_sync.c
+++ b/net/netfilter/ipvs/ip_vs_sync.c
@@ -400,6 +400,11 @@ static void ip_vs_process_message(const char *buffer, const size_t buflen)
400 flags |= IP_VS_CONN_F_INACTIVE; 400 flags |= IP_VS_CONN_F_INACTIVE;
401 else 401 else
402 flags &= ~IP_VS_CONN_F_INACTIVE; 402 flags &= ~IP_VS_CONN_F_INACTIVE;
403 } else if (s->protocol == IPPROTO_SCTP) {
404 if (state != IP_VS_SCTP_S_ESTABLISHED)
405 flags |= IP_VS_CONN_F_INACTIVE;
406 else
407 flags &= ~IP_VS_CONN_F_INACTIVE;
403 } 408 }
404 cp = ip_vs_conn_new(AF_INET, s->protocol, 409 cp = ip_vs_conn_new(AF_INET, s->protocol,
405 (union nf_inet_addr *)&s->caddr, 410 (union nf_inet_addr *)&s->caddr,
@@ -434,6 +439,15 @@ static void ip_vs_process_message(const char *buffer, const size_t buflen)
434 atomic_dec(&dest->inactconns); 439 atomic_dec(&dest->inactconns);
435 cp->flags &= ~IP_VS_CONN_F_INACTIVE; 440 cp->flags &= ~IP_VS_CONN_F_INACTIVE;
436 } 441 }
442 } else if ((cp->dest) && (cp->protocol == IPPROTO_SCTP) &&
443 (cp->state != state)) {
444 dest = cp->dest;
445 if (!(cp->flags & IP_VS_CONN_F_INACTIVE) &&
446 (state != IP_VS_SCTP_S_ESTABLISHED)) {
447 atomic_dec(&dest->activeconns);
448 atomic_inc(&dest->inactconns);
449 cp->flags &= ~IP_VS_CONN_F_INACTIVE;
450 }
437 } 451 }
438 452
439 if (opt) 453 if (opt)
diff --git a/net/netfilter/ipvs/ip_vs_wrr.c b/net/netfilter/ipvs/ip_vs_wrr.c
index 6182e8ea0be7..30db633f88f1 100644
--- a/net/netfilter/ipvs/ip_vs_wrr.c
+++ b/net/netfilter/ipvs/ip_vs_wrr.c
@@ -23,7 +23,9 @@
23 23
24#include <linux/module.h> 24#include <linux/module.h>
25#include <linux/kernel.h> 25#include <linux/kernel.h>
26#include <linux/slab.h>
26#include <linux/net.h> 27#include <linux/net.h>
28#include <linux/gcd.h>
27 29
28#include <net/ip_vs.h> 30#include <net/ip_vs.h>
29 31
@@ -38,20 +40,6 @@ struct ip_vs_wrr_mark {
38}; 40};
39 41
40 42
41/*
42 * Get the gcd of server weights
43 */
44static int gcd(int a, int b)
45{
46 int c;
47
48 while ((c = a % b)) {
49 a = b;
50 b = c;
51 }
52 return b;
53}
54
55static int ip_vs_wrr_gcd_weight(struct ip_vs_service *svc) 43static int ip_vs_wrr_gcd_weight(struct ip_vs_service *svc)
56{ 44{
57 struct ip_vs_dest *dest; 45 struct ip_vs_dest *dest;
diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
index 30b3189bd29c..e450cd6f4eb5 100644
--- a/net/netfilter/ipvs/ip_vs_xmit.c
+++ b/net/netfilter/ipvs/ip_vs_xmit.c
@@ -17,6 +17,7 @@
17#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt 17#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
18 18
19#include <linux/kernel.h> 19#include <linux/kernel.h>
20#include <linux/slab.h>
20#include <linux/tcp.h> /* for tcphdr */ 21#include <linux/tcp.h> /* for tcphdr */
21#include <net/ip.h> 22#include <net/ip.h>
22#include <net/tcp.h> /* for csum_tcpudp_magic */ 23#include <net/tcp.h> /* for csum_tcpudp_magic */
@@ -311,7 +312,7 @@ ip_vs_bypass_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
311 mtu = dst_mtu(&rt->u.dst); 312 mtu = dst_mtu(&rt->u.dst);
312 if (skb->len > mtu) { 313 if (skb->len > mtu) {
313 dst_release(&rt->u.dst); 314 dst_release(&rt->u.dst);
314 icmpv6_send(skb, ICMPV6_PKT_TOOBIG, 0, mtu, skb->dev); 315 icmpv6_send(skb, ICMPV6_PKT_TOOBIG, 0, mtu);
315 IP_VS_DBG_RL("%s(): frag needed\n", __func__); 316 IP_VS_DBG_RL("%s(): frag needed\n", __func__);
316 goto tx_error; 317 goto tx_error;
317 } 318 }
@@ -454,7 +455,7 @@ ip_vs_nat_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
454 mtu = dst_mtu(&rt->u.dst); 455 mtu = dst_mtu(&rt->u.dst);
455 if (skb->len > mtu) { 456 if (skb->len > mtu) {
456 dst_release(&rt->u.dst); 457 dst_release(&rt->u.dst);
457 icmpv6_send(skb, ICMPV6_PKT_TOOBIG, 0, mtu, skb->dev); 458 icmpv6_send(skb, ICMPV6_PKT_TOOBIG, 0, mtu);
458 IP_VS_DBG_RL_PKT(0, pp, skb, 0, 459 IP_VS_DBG_RL_PKT(0, pp, skb, 0,
459 "ip_vs_nat_xmit_v6(): frag needed for"); 460 "ip_vs_nat_xmit_v6(): frag needed for");
460 goto tx_error; 461 goto tx_error;
@@ -672,7 +673,7 @@ ip_vs_tunnel_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
672 skb_dst(skb)->ops->update_pmtu(skb_dst(skb), mtu); 673 skb_dst(skb)->ops->update_pmtu(skb_dst(skb), mtu);
673 674
674 if (mtu < ntohs(old_iph->payload_len) + sizeof(struct ipv6hdr)) { 675 if (mtu < ntohs(old_iph->payload_len) + sizeof(struct ipv6hdr)) {
675 icmpv6_send(skb, ICMPV6_PKT_TOOBIG, 0, mtu, skb->dev); 676 icmpv6_send(skb, ICMPV6_PKT_TOOBIG, 0, mtu);
676 dst_release(&rt->u.dst); 677 dst_release(&rt->u.dst);
677 IP_VS_DBG_RL("%s(): frag needed\n", __func__); 678 IP_VS_DBG_RL("%s(): frag needed\n", __func__);
678 goto tx_error; 679 goto tx_error;
@@ -814,7 +815,7 @@ ip_vs_dr_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
814 /* MTU checking */ 815 /* MTU checking */
815 mtu = dst_mtu(&rt->u.dst); 816 mtu = dst_mtu(&rt->u.dst);
816 if (skb->len > mtu) { 817 if (skb->len > mtu) {
817 icmpv6_send(skb, ICMPV6_PKT_TOOBIG, 0, mtu, skb->dev); 818 icmpv6_send(skb, ICMPV6_PKT_TOOBIG, 0, mtu);
818 dst_release(&rt->u.dst); 819 dst_release(&rt->u.dst);
819 IP_VS_DBG_RL("%s(): frag needed\n", __func__); 820 IP_VS_DBG_RL("%s(): frag needed\n", __func__);
820 goto tx_error; 821 goto tx_error;
@@ -965,7 +966,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
965 mtu = dst_mtu(&rt->u.dst); 966 mtu = dst_mtu(&rt->u.dst);
966 if (skb->len > mtu) { 967 if (skb->len > mtu) {
967 dst_release(&rt->u.dst); 968 dst_release(&rt->u.dst);
968 icmpv6_send(skb, ICMPV6_PKT_TOOBIG, 0, mtu, skb->dev); 969 icmpv6_send(skb, ICMPV6_PKT_TOOBIG, 0, mtu);
969 IP_VS_DBG_RL("%s(): frag needed\n", __func__); 970 IP_VS_DBG_RL("%s(): frag needed\n", __func__);
970 goto tx_error; 971 goto tx_error;
971 } 972 }
diff --git a/net/netfilter/nf_conntrack_acct.c b/net/netfilter/nf_conntrack_acct.c
index 4a1d94aac20b..ab81b380eae6 100644
--- a/net/netfilter/nf_conntrack_acct.c
+++ b/net/netfilter/nf_conntrack_acct.c
@@ -9,6 +9,7 @@
9 */ 9 */
10 10
11#include <linux/netfilter.h> 11#include <linux/netfilter.h>
12#include <linux/slab.h>
12#include <linux/kernel.h> 13#include <linux/kernel.h>
13#include <linux/moduleparam.h> 14#include <linux/moduleparam.h>
14 15
@@ -30,7 +31,6 @@ MODULE_PARM_DESC(acct, "Enable connection tracking flow accounting.");
30#ifdef CONFIG_SYSCTL 31#ifdef CONFIG_SYSCTL
31static struct ctl_table acct_sysctl_table[] = { 32static struct ctl_table acct_sysctl_table[] = {
32 { 33 {
33 .ctl_name = CTL_UNNUMBERED,
34 .procname = "nf_conntrack_acct", 34 .procname = "nf_conntrack_acct",
35 .data = &init_net.ct.sysctl_acct, 35 .data = &init_net.ct.sysctl_acct,
36 .maxlen = sizeof(unsigned int), 36 .maxlen = sizeof(unsigned int),
diff --git a/net/netfilter/nf_conntrack_amanda.c b/net/netfilter/nf_conntrack_amanda.c
index 07d9d8857e5d..372e80f07a81 100644
--- a/net/netfilter/nf_conntrack_amanda.c
+++ b/net/netfilter/nf_conntrack_amanda.c
@@ -16,6 +16,7 @@
16#include <linux/in.h> 16#include <linux/in.h>
17#include <linux/udp.h> 17#include <linux/udp.h>
18#include <linux/netfilter.h> 18#include <linux/netfilter.h>
19#include <linux/gfp.h>
19 20
20#include <net/netfilter/nf_conntrack.h> 21#include <net/netfilter/nf_conntrack.h>
21#include <net/netfilter/nf_conntrack_expect.h> 22#include <net/netfilter/nf_conntrack_expect.h>
diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
index b9168c1864ca..0c9bbe93cc16 100644
--- a/net/netfilter/nf_conntrack_core.c
+++ b/net/netfilter/nf_conntrack_core.c
@@ -30,6 +30,7 @@
30#include <linux/netdevice.h> 30#include <linux/netdevice.h>
31#include <linux/socket.h> 31#include <linux/socket.h>
32#include <linux/mm.h> 32#include <linux/mm.h>
33#include <linux/nsproxy.h>
33#include <linux/rculist_nulls.h> 34#include <linux/rculist_nulls.h>
34 35
35#include <net/netfilter/nf_conntrack.h> 36#include <net/netfilter/nf_conntrack.h>
@@ -41,6 +42,7 @@
41#include <net/netfilter/nf_conntrack_extend.h> 42#include <net/netfilter/nf_conntrack_extend.h>
42#include <net/netfilter/nf_conntrack_acct.h> 43#include <net/netfilter/nf_conntrack_acct.h>
43#include <net/netfilter/nf_conntrack_ecache.h> 44#include <net/netfilter/nf_conntrack_ecache.h>
45#include <net/netfilter/nf_conntrack_zones.h>
44#include <net/netfilter/nf_nat.h> 46#include <net/netfilter/nf_nat.h>
45#include <net/netfilter/nf_nat_core.h> 47#include <net/netfilter/nf_nat_core.h>
46 48
@@ -63,13 +65,11 @@ EXPORT_SYMBOL_GPL(nf_conntrack_max);
63struct nf_conn nf_conntrack_untracked __read_mostly; 65struct nf_conn nf_conntrack_untracked __read_mostly;
64EXPORT_SYMBOL_GPL(nf_conntrack_untracked); 66EXPORT_SYMBOL_GPL(nf_conntrack_untracked);
65 67
66static struct kmem_cache *nf_conntrack_cachep __read_mostly;
67
68static int nf_conntrack_hash_rnd_initted; 68static int nf_conntrack_hash_rnd_initted;
69static unsigned int nf_conntrack_hash_rnd; 69static unsigned int nf_conntrack_hash_rnd;
70 70
71static u_int32_t __hash_conntrack(const struct nf_conntrack_tuple *tuple, 71static u_int32_t __hash_conntrack(const struct nf_conntrack_tuple *tuple,
72 unsigned int size, unsigned int rnd) 72 u16 zone, unsigned int size, unsigned int rnd)
73{ 73{
74 unsigned int n; 74 unsigned int n;
75 u_int32_t h; 75 u_int32_t h;
@@ -80,15 +80,16 @@ static u_int32_t __hash_conntrack(const struct nf_conntrack_tuple *tuple,
80 */ 80 */
81 n = (sizeof(tuple->src) + sizeof(tuple->dst.u3)) / sizeof(u32); 81 n = (sizeof(tuple->src) + sizeof(tuple->dst.u3)) / sizeof(u32);
82 h = jhash2((u32 *)tuple, n, 82 h = jhash2((u32 *)tuple, n,
83 rnd ^ (((__force __u16)tuple->dst.u.all << 16) | 83 zone ^ rnd ^ (((__force __u16)tuple->dst.u.all << 16) |
84 tuple->dst.protonum)); 84 tuple->dst.protonum));
85 85
86 return ((u64)h * size) >> 32; 86 return ((u64)h * size) >> 32;
87} 87}
88 88
89static inline u_int32_t hash_conntrack(const struct nf_conntrack_tuple *tuple) 89static inline u_int32_t hash_conntrack(const struct net *net, u16 zone,
90 const struct nf_conntrack_tuple *tuple)
90{ 91{
91 return __hash_conntrack(tuple, nf_conntrack_htable_size, 92 return __hash_conntrack(tuple, zone, net->ct.htable_size,
92 nf_conntrack_hash_rnd); 93 nf_conntrack_hash_rnd);
93} 94}
94 95
@@ -292,11 +293,12 @@ static void death_by_timeout(unsigned long ul_conntrack)
292 * - Caller must lock nf_conntrack_lock before calling this function 293 * - Caller must lock nf_conntrack_lock before calling this function
293 */ 294 */
294struct nf_conntrack_tuple_hash * 295struct nf_conntrack_tuple_hash *
295__nf_conntrack_find(struct net *net, const struct nf_conntrack_tuple *tuple) 296__nf_conntrack_find(struct net *net, u16 zone,
297 const struct nf_conntrack_tuple *tuple)
296{ 298{
297 struct nf_conntrack_tuple_hash *h; 299 struct nf_conntrack_tuple_hash *h;
298 struct hlist_nulls_node *n; 300 struct hlist_nulls_node *n;
299 unsigned int hash = hash_conntrack(tuple); 301 unsigned int hash = hash_conntrack(net, zone, tuple);
300 302
301 /* Disable BHs the entire time since we normally need to disable them 303 /* Disable BHs the entire time since we normally need to disable them
302 * at least once for the stats anyway. 304 * at least once for the stats anyway.
@@ -304,7 +306,8 @@ __nf_conntrack_find(struct net *net, const struct nf_conntrack_tuple *tuple)
304 local_bh_disable(); 306 local_bh_disable();
305begin: 307begin:
306 hlist_nulls_for_each_entry_rcu(h, n, &net->ct.hash[hash], hnnode) { 308 hlist_nulls_for_each_entry_rcu(h, n, &net->ct.hash[hash], hnnode) {
307 if (nf_ct_tuple_equal(tuple, &h->tuple)) { 309 if (nf_ct_tuple_equal(tuple, &h->tuple) &&
310 nf_ct_zone(nf_ct_tuplehash_to_ctrack(h)) == zone) {
308 NF_CT_STAT_INC(net, found); 311 NF_CT_STAT_INC(net, found);
309 local_bh_enable(); 312 local_bh_enable();
310 return h; 313 return h;
@@ -326,21 +329,23 @@ EXPORT_SYMBOL_GPL(__nf_conntrack_find);
326 329
327/* Find a connection corresponding to a tuple. */ 330/* Find a connection corresponding to a tuple. */
328struct nf_conntrack_tuple_hash * 331struct nf_conntrack_tuple_hash *
329nf_conntrack_find_get(struct net *net, const struct nf_conntrack_tuple *tuple) 332nf_conntrack_find_get(struct net *net, u16 zone,
333 const struct nf_conntrack_tuple *tuple)
330{ 334{
331 struct nf_conntrack_tuple_hash *h; 335 struct nf_conntrack_tuple_hash *h;
332 struct nf_conn *ct; 336 struct nf_conn *ct;
333 337
334 rcu_read_lock(); 338 rcu_read_lock();
335begin: 339begin:
336 h = __nf_conntrack_find(net, tuple); 340 h = __nf_conntrack_find(net, zone, tuple);
337 if (h) { 341 if (h) {
338 ct = nf_ct_tuplehash_to_ctrack(h); 342 ct = nf_ct_tuplehash_to_ctrack(h);
339 if (unlikely(nf_ct_is_dying(ct) || 343 if (unlikely(nf_ct_is_dying(ct) ||
340 !atomic_inc_not_zero(&ct->ct_general.use))) 344 !atomic_inc_not_zero(&ct->ct_general.use)))
341 h = NULL; 345 h = NULL;
342 else { 346 else {
343 if (unlikely(!nf_ct_tuple_equal(tuple, &h->tuple))) { 347 if (unlikely(!nf_ct_tuple_equal(tuple, &h->tuple) ||
348 nf_ct_zone(ct) != zone)) {
344 nf_ct_put(ct); 349 nf_ct_put(ct);
345 goto begin; 350 goto begin;
346 } 351 }
@@ -366,10 +371,13 @@ static void __nf_conntrack_hash_insert(struct nf_conn *ct,
366 371
367void nf_conntrack_hash_insert(struct nf_conn *ct) 372void nf_conntrack_hash_insert(struct nf_conn *ct)
368{ 373{
374 struct net *net = nf_ct_net(ct);
369 unsigned int hash, repl_hash; 375 unsigned int hash, repl_hash;
376 u16 zone;
370 377
371 hash = hash_conntrack(&ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple); 378 zone = nf_ct_zone(ct);
372 repl_hash = hash_conntrack(&ct->tuplehash[IP_CT_DIR_REPLY].tuple); 379 hash = hash_conntrack(net, zone, &ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple);
380 repl_hash = hash_conntrack(net, zone, &ct->tuplehash[IP_CT_DIR_REPLY].tuple);
373 381
374 __nf_conntrack_hash_insert(ct, hash, repl_hash); 382 __nf_conntrack_hash_insert(ct, hash, repl_hash);
375} 383}
@@ -386,6 +394,7 @@ __nf_conntrack_confirm(struct sk_buff *skb)
386 struct hlist_nulls_node *n; 394 struct hlist_nulls_node *n;
387 enum ip_conntrack_info ctinfo; 395 enum ip_conntrack_info ctinfo;
388 struct net *net; 396 struct net *net;
397 u16 zone;
389 398
390 ct = nf_ct_get(skb, &ctinfo); 399 ct = nf_ct_get(skb, &ctinfo);
391 net = nf_ct_net(ct); 400 net = nf_ct_net(ct);
@@ -397,8 +406,9 @@ __nf_conntrack_confirm(struct sk_buff *skb)
397 if (CTINFO2DIR(ctinfo) != IP_CT_DIR_ORIGINAL) 406 if (CTINFO2DIR(ctinfo) != IP_CT_DIR_ORIGINAL)
398 return NF_ACCEPT; 407 return NF_ACCEPT;
399 408
400 hash = hash_conntrack(&ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple); 409 zone = nf_ct_zone(ct);
401 repl_hash = hash_conntrack(&ct->tuplehash[IP_CT_DIR_REPLY].tuple); 410 hash = hash_conntrack(net, zone, &ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple);
411 repl_hash = hash_conntrack(net, zone, &ct->tuplehash[IP_CT_DIR_REPLY].tuple);
402 412
403 /* We're not in hash table, and we refuse to set up related 413 /* We're not in hash table, and we refuse to set up related
404 connections for unconfirmed conns. But packet copies and 414 connections for unconfirmed conns. But packet copies and
@@ -417,11 +427,13 @@ __nf_conntrack_confirm(struct sk_buff *skb)
417 not in the hash. If there is, we lost race. */ 427 not in the hash. If there is, we lost race. */
418 hlist_nulls_for_each_entry(h, n, &net->ct.hash[hash], hnnode) 428 hlist_nulls_for_each_entry(h, n, &net->ct.hash[hash], hnnode)
419 if (nf_ct_tuple_equal(&ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple, 429 if (nf_ct_tuple_equal(&ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple,
420 &h->tuple)) 430 &h->tuple) &&
431 zone == nf_ct_zone(nf_ct_tuplehash_to_ctrack(h)))
421 goto out; 432 goto out;
422 hlist_nulls_for_each_entry(h, n, &net->ct.hash[repl_hash], hnnode) 433 hlist_nulls_for_each_entry(h, n, &net->ct.hash[repl_hash], hnnode)
423 if (nf_ct_tuple_equal(&ct->tuplehash[IP_CT_DIR_REPLY].tuple, 434 if (nf_ct_tuple_equal(&ct->tuplehash[IP_CT_DIR_REPLY].tuple,
424 &h->tuple)) 435 &h->tuple) &&
436 zone == nf_ct_zone(nf_ct_tuplehash_to_ctrack(h)))
425 goto out; 437 goto out;
426 438
427 /* Remove from unconfirmed list */ 439 /* Remove from unconfirmed list */
@@ -468,15 +480,19 @@ nf_conntrack_tuple_taken(const struct nf_conntrack_tuple *tuple,
468 struct net *net = nf_ct_net(ignored_conntrack); 480 struct net *net = nf_ct_net(ignored_conntrack);
469 struct nf_conntrack_tuple_hash *h; 481 struct nf_conntrack_tuple_hash *h;
470 struct hlist_nulls_node *n; 482 struct hlist_nulls_node *n;
471 unsigned int hash = hash_conntrack(tuple); 483 struct nf_conn *ct;
484 u16 zone = nf_ct_zone(ignored_conntrack);
485 unsigned int hash = hash_conntrack(net, zone, tuple);
472 486
473 /* Disable BHs the entire time since we need to disable them at 487 /* Disable BHs the entire time since we need to disable them at
474 * least once for the stats anyway. 488 * least once for the stats anyway.
475 */ 489 */
476 rcu_read_lock_bh(); 490 rcu_read_lock_bh();
477 hlist_nulls_for_each_entry_rcu(h, n, &net->ct.hash[hash], hnnode) { 491 hlist_nulls_for_each_entry_rcu(h, n, &net->ct.hash[hash], hnnode) {
478 if (nf_ct_tuplehash_to_ctrack(h) != ignored_conntrack && 492 ct = nf_ct_tuplehash_to_ctrack(h);
479 nf_ct_tuple_equal(tuple, &h->tuple)) { 493 if (ct != ignored_conntrack &&
494 nf_ct_tuple_equal(tuple, &h->tuple) &&
495 nf_ct_zone(ct) == zone) {
480 NF_CT_STAT_INC(net, found); 496 NF_CT_STAT_INC(net, found);
481 rcu_read_unlock_bh(); 497 rcu_read_unlock_bh();
482 return 1; 498 return 1;
@@ -503,7 +519,7 @@ static noinline int early_drop(struct net *net, unsigned int hash)
503 int dropped = 0; 519 int dropped = 0;
504 520
505 rcu_read_lock(); 521 rcu_read_lock();
506 for (i = 0; i < nf_conntrack_htable_size; i++) { 522 for (i = 0; i < net->ct.htable_size; i++) {
507 hlist_nulls_for_each_entry_rcu(h, n, &net->ct.hash[hash], 523 hlist_nulls_for_each_entry_rcu(h, n, &net->ct.hash[hash],
508 hnnode) { 524 hnnode) {
509 tmp = nf_ct_tuplehash_to_ctrack(h); 525 tmp = nf_ct_tuplehash_to_ctrack(h);
@@ -512,12 +528,18 @@ static noinline int early_drop(struct net *net, unsigned int hash)
512 cnt++; 528 cnt++;
513 } 529 }
514 530
515 if (ct && unlikely(nf_ct_is_dying(ct) || 531 if (ct != NULL) {
516 !atomic_inc_not_zero(&ct->ct_general.use))) 532 if (likely(!nf_ct_is_dying(ct) &&
517 ct = NULL; 533 atomic_inc_not_zero(&ct->ct_general.use)))
518 if (ct || cnt >= NF_CT_EVICTION_RANGE) 534 break;
535 else
536 ct = NULL;
537 }
538
539 if (cnt >= NF_CT_EVICTION_RANGE)
519 break; 540 break;
520 hash = (hash + 1) % nf_conntrack_htable_size; 541
542 hash = (hash + 1) % net->ct.htable_size;
521 } 543 }
522 rcu_read_unlock(); 544 rcu_read_unlock();
523 545
@@ -533,7 +555,7 @@ static noinline int early_drop(struct net *net, unsigned int hash)
533 return dropped; 555 return dropped;
534} 556}
535 557
536struct nf_conn *nf_conntrack_alloc(struct net *net, 558struct nf_conn *nf_conntrack_alloc(struct net *net, u16 zone,
537 const struct nf_conntrack_tuple *orig, 559 const struct nf_conntrack_tuple *orig,
538 const struct nf_conntrack_tuple *repl, 560 const struct nf_conntrack_tuple *repl,
539 gfp_t gfp) 561 gfp_t gfp)
@@ -551,7 +573,7 @@ struct nf_conn *nf_conntrack_alloc(struct net *net,
551 573
552 if (nf_conntrack_max && 574 if (nf_conntrack_max &&
553 unlikely(atomic_read(&net->ct.count) > nf_conntrack_max)) { 575 unlikely(atomic_read(&net->ct.count) > nf_conntrack_max)) {
554 unsigned int hash = hash_conntrack(orig); 576 unsigned int hash = hash_conntrack(net, zone, orig);
555 if (!early_drop(net, hash)) { 577 if (!early_drop(net, hash)) {
556 atomic_dec(&net->ct.count); 578 atomic_dec(&net->ct.count);
557 if (net_ratelimit()) 579 if (net_ratelimit())
@@ -566,7 +588,7 @@ struct nf_conn *nf_conntrack_alloc(struct net *net,
566 * Do not use kmem_cache_zalloc(), as this cache uses 588 * Do not use kmem_cache_zalloc(), as this cache uses
567 * SLAB_DESTROY_BY_RCU. 589 * SLAB_DESTROY_BY_RCU.
568 */ 590 */
569 ct = kmem_cache_alloc(nf_conntrack_cachep, gfp); 591 ct = kmem_cache_alloc(net->ct.nf_conntrack_cachep, gfp);
570 if (ct == NULL) { 592 if (ct == NULL) {
571 pr_debug("nf_conntrack_alloc: Can't alloc conntrack.\n"); 593 pr_debug("nf_conntrack_alloc: Can't alloc conntrack.\n");
572 atomic_dec(&net->ct.count); 594 atomic_dec(&net->ct.count);
@@ -588,13 +610,28 @@ struct nf_conn *nf_conntrack_alloc(struct net *net,
588#ifdef CONFIG_NET_NS 610#ifdef CONFIG_NET_NS
589 ct->ct_net = net; 611 ct->ct_net = net;
590#endif 612#endif
591 613#ifdef CONFIG_NF_CONNTRACK_ZONES
614 if (zone) {
615 struct nf_conntrack_zone *nf_ct_zone;
616
617 nf_ct_zone = nf_ct_ext_add(ct, NF_CT_EXT_ZONE, GFP_ATOMIC);
618 if (!nf_ct_zone)
619 goto out_free;
620 nf_ct_zone->id = zone;
621 }
622#endif
592 /* 623 /*
593 * changes to lookup keys must be done before setting refcnt to 1 624 * changes to lookup keys must be done before setting refcnt to 1
594 */ 625 */
595 smp_wmb(); 626 smp_wmb();
596 atomic_set(&ct->ct_general.use, 1); 627 atomic_set(&ct->ct_general.use, 1);
597 return ct; 628 return ct;
629
630#ifdef CONFIG_NF_CONNTRACK_ZONES
631out_free:
632 kmem_cache_free(net->ct.nf_conntrack_cachep, ct);
633 return ERR_PTR(-ENOMEM);
634#endif
598} 635}
599EXPORT_SYMBOL_GPL(nf_conntrack_alloc); 636EXPORT_SYMBOL_GPL(nf_conntrack_alloc);
600 637
@@ -605,14 +642,14 @@ void nf_conntrack_free(struct nf_conn *ct)
605 nf_ct_ext_destroy(ct); 642 nf_ct_ext_destroy(ct);
606 atomic_dec(&net->ct.count); 643 atomic_dec(&net->ct.count);
607 nf_ct_ext_free(ct); 644 nf_ct_ext_free(ct);
608 kmem_cache_free(nf_conntrack_cachep, ct); 645 kmem_cache_free(net->ct.nf_conntrack_cachep, ct);
609} 646}
610EXPORT_SYMBOL_GPL(nf_conntrack_free); 647EXPORT_SYMBOL_GPL(nf_conntrack_free);
611 648
612/* Allocate a new conntrack: we return -ENOMEM if classification 649/* Allocate a new conntrack: we return -ENOMEM if classification
613 failed due to stress. Otherwise it really is unclassifiable. */ 650 failed due to stress. Otherwise it really is unclassifiable. */
614static struct nf_conntrack_tuple_hash * 651static struct nf_conntrack_tuple_hash *
615init_conntrack(struct net *net, 652init_conntrack(struct net *net, struct nf_conn *tmpl,
616 const struct nf_conntrack_tuple *tuple, 653 const struct nf_conntrack_tuple *tuple,
617 struct nf_conntrack_l3proto *l3proto, 654 struct nf_conntrack_l3proto *l3proto,
618 struct nf_conntrack_l4proto *l4proto, 655 struct nf_conntrack_l4proto *l4proto,
@@ -622,14 +659,16 @@ init_conntrack(struct net *net,
622 struct nf_conn *ct; 659 struct nf_conn *ct;
623 struct nf_conn_help *help; 660 struct nf_conn_help *help;
624 struct nf_conntrack_tuple repl_tuple; 661 struct nf_conntrack_tuple repl_tuple;
662 struct nf_conntrack_ecache *ecache;
625 struct nf_conntrack_expect *exp; 663 struct nf_conntrack_expect *exp;
664 u16 zone = tmpl ? nf_ct_zone(tmpl) : NF_CT_DEFAULT_ZONE;
626 665
627 if (!nf_ct_invert_tuple(&repl_tuple, tuple, l3proto, l4proto)) { 666 if (!nf_ct_invert_tuple(&repl_tuple, tuple, l3proto, l4proto)) {
628 pr_debug("Can't invert tuple.\n"); 667 pr_debug("Can't invert tuple.\n");
629 return NULL; 668 return NULL;
630 } 669 }
631 670
632 ct = nf_conntrack_alloc(net, tuple, &repl_tuple, GFP_ATOMIC); 671 ct = nf_conntrack_alloc(net, zone, tuple, &repl_tuple, GFP_ATOMIC);
633 if (IS_ERR(ct)) { 672 if (IS_ERR(ct)) {
634 pr_debug("Can't allocate conntrack.\n"); 673 pr_debug("Can't allocate conntrack.\n");
635 return (struct nf_conntrack_tuple_hash *)ct; 674 return (struct nf_conntrack_tuple_hash *)ct;
@@ -642,10 +681,14 @@ init_conntrack(struct net *net,
642 } 681 }
643 682
644 nf_ct_acct_ext_add(ct, GFP_ATOMIC); 683 nf_ct_acct_ext_add(ct, GFP_ATOMIC);
645 nf_ct_ecache_ext_add(ct, GFP_ATOMIC); 684
685 ecache = tmpl ? nf_ct_ecache_find(tmpl) : NULL;
686 nf_ct_ecache_ext_add(ct, ecache ? ecache->ctmask : 0,
687 ecache ? ecache->expmask : 0,
688 GFP_ATOMIC);
646 689
647 spin_lock_bh(&nf_conntrack_lock); 690 spin_lock_bh(&nf_conntrack_lock);
648 exp = nf_ct_find_expectation(net, tuple); 691 exp = nf_ct_find_expectation(net, zone, tuple);
649 if (exp) { 692 if (exp) {
650 pr_debug("conntrack: expectation arrives ct=%p exp=%p\n", 693 pr_debug("conntrack: expectation arrives ct=%p exp=%p\n",
651 ct, exp); 694 ct, exp);
@@ -667,7 +710,7 @@ init_conntrack(struct net *net,
667 nf_conntrack_get(&ct->master->ct_general); 710 nf_conntrack_get(&ct->master->ct_general);
668 NF_CT_STAT_INC(net, expect_new); 711 NF_CT_STAT_INC(net, expect_new);
669 } else { 712 } else {
670 __nf_ct_try_assign_helper(ct, GFP_ATOMIC); 713 __nf_ct_try_assign_helper(ct, tmpl, GFP_ATOMIC);
671 NF_CT_STAT_INC(net, new); 714 NF_CT_STAT_INC(net, new);
672 } 715 }
673 716
@@ -688,7 +731,7 @@ init_conntrack(struct net *net,
688 731
689/* On success, returns conntrack ptr, sets skb->nfct and ctinfo */ 732/* On success, returns conntrack ptr, sets skb->nfct and ctinfo */
690static inline struct nf_conn * 733static inline struct nf_conn *
691resolve_normal_ct(struct net *net, 734resolve_normal_ct(struct net *net, struct nf_conn *tmpl,
692 struct sk_buff *skb, 735 struct sk_buff *skb,
693 unsigned int dataoff, 736 unsigned int dataoff,
694 u_int16_t l3num, 737 u_int16_t l3num,
@@ -701,6 +744,7 @@ resolve_normal_ct(struct net *net,
701 struct nf_conntrack_tuple tuple; 744 struct nf_conntrack_tuple tuple;
702 struct nf_conntrack_tuple_hash *h; 745 struct nf_conntrack_tuple_hash *h;
703 struct nf_conn *ct; 746 struct nf_conn *ct;
747 u16 zone = tmpl ? nf_ct_zone(tmpl) : NF_CT_DEFAULT_ZONE;
704 748
705 if (!nf_ct_get_tuple(skb, skb_network_offset(skb), 749 if (!nf_ct_get_tuple(skb, skb_network_offset(skb),
706 dataoff, l3num, protonum, &tuple, l3proto, 750 dataoff, l3num, protonum, &tuple, l3proto,
@@ -710,9 +754,10 @@ resolve_normal_ct(struct net *net,
710 } 754 }
711 755
712 /* look for tuple match */ 756 /* look for tuple match */
713 h = nf_conntrack_find_get(net, &tuple); 757 h = nf_conntrack_find_get(net, zone, &tuple);
714 if (!h) { 758 if (!h) {
715 h = init_conntrack(net, &tuple, l3proto, l4proto, skb, dataoff); 759 h = init_conntrack(net, tmpl, &tuple, l3proto, l4proto,
760 skb, dataoff);
716 if (!h) 761 if (!h)
717 return NULL; 762 return NULL;
718 if (IS_ERR(h)) 763 if (IS_ERR(h))
@@ -749,7 +794,7 @@ unsigned int
749nf_conntrack_in(struct net *net, u_int8_t pf, unsigned int hooknum, 794nf_conntrack_in(struct net *net, u_int8_t pf, unsigned int hooknum,
750 struct sk_buff *skb) 795 struct sk_buff *skb)
751{ 796{
752 struct nf_conn *ct; 797 struct nf_conn *ct, *tmpl = NULL;
753 enum ip_conntrack_info ctinfo; 798 enum ip_conntrack_info ctinfo;
754 struct nf_conntrack_l3proto *l3proto; 799 struct nf_conntrack_l3proto *l3proto;
755 struct nf_conntrack_l4proto *l4proto; 800 struct nf_conntrack_l4proto *l4proto;
@@ -758,10 +803,14 @@ nf_conntrack_in(struct net *net, u_int8_t pf, unsigned int hooknum,
758 int set_reply = 0; 803 int set_reply = 0;
759 int ret; 804 int ret;
760 805
761 /* Previously seen (loopback or untracked)? Ignore. */
762 if (skb->nfct) { 806 if (skb->nfct) {
763 NF_CT_STAT_INC_ATOMIC(net, ignore); 807 /* Previously seen (loopback or untracked)? Ignore. */
764 return NF_ACCEPT; 808 tmpl = (struct nf_conn *)skb->nfct;
809 if (!nf_ct_is_template(tmpl)) {
810 NF_CT_STAT_INC_ATOMIC(net, ignore);
811 return NF_ACCEPT;
812 }
813 skb->nfct = NULL;
765 } 814 }
766 815
767 /* rcu_read_lock()ed by nf_hook_slow */ 816 /* rcu_read_lock()ed by nf_hook_slow */
@@ -772,7 +821,8 @@ nf_conntrack_in(struct net *net, u_int8_t pf, unsigned int hooknum,
772 pr_debug("not prepared to track yet or error occured\n"); 821 pr_debug("not prepared to track yet or error occured\n");
773 NF_CT_STAT_INC_ATOMIC(net, error); 822 NF_CT_STAT_INC_ATOMIC(net, error);
774 NF_CT_STAT_INC_ATOMIC(net, invalid); 823 NF_CT_STAT_INC_ATOMIC(net, invalid);
775 return -ret; 824 ret = -ret;
825 goto out;
776 } 826 }
777 827
778 l4proto = __nf_ct_l4proto_find(pf, protonum); 828 l4proto = __nf_ct_l4proto_find(pf, protonum);
@@ -781,26 +831,30 @@ nf_conntrack_in(struct net *net, u_int8_t pf, unsigned int hooknum,
781 * inverse of the return code tells to the netfilter 831 * inverse of the return code tells to the netfilter
782 * core what to do with the packet. */ 832 * core what to do with the packet. */
783 if (l4proto->error != NULL) { 833 if (l4proto->error != NULL) {
784 ret = l4proto->error(net, skb, dataoff, &ctinfo, pf, hooknum); 834 ret = l4proto->error(net, tmpl, skb, dataoff, &ctinfo,
835 pf, hooknum);
785 if (ret <= 0) { 836 if (ret <= 0) {
786 NF_CT_STAT_INC_ATOMIC(net, error); 837 NF_CT_STAT_INC_ATOMIC(net, error);
787 NF_CT_STAT_INC_ATOMIC(net, invalid); 838 NF_CT_STAT_INC_ATOMIC(net, invalid);
788 return -ret; 839 ret = -ret;
840 goto out;
789 } 841 }
790 } 842 }
791 843
792 ct = resolve_normal_ct(net, skb, dataoff, pf, protonum, 844 ct = resolve_normal_ct(net, tmpl, skb, dataoff, pf, protonum,
793 l3proto, l4proto, &set_reply, &ctinfo); 845 l3proto, l4proto, &set_reply, &ctinfo);
794 if (!ct) { 846 if (!ct) {
795 /* Not valid part of a connection */ 847 /* Not valid part of a connection */
796 NF_CT_STAT_INC_ATOMIC(net, invalid); 848 NF_CT_STAT_INC_ATOMIC(net, invalid);
797 return NF_ACCEPT; 849 ret = NF_ACCEPT;
850 goto out;
798 } 851 }
799 852
800 if (IS_ERR(ct)) { 853 if (IS_ERR(ct)) {
801 /* Too stressed to deal. */ 854 /* Too stressed to deal. */
802 NF_CT_STAT_INC_ATOMIC(net, drop); 855 NF_CT_STAT_INC_ATOMIC(net, drop);
803 return NF_DROP; 856 ret = NF_DROP;
857 goto out;
804 } 858 }
805 859
806 NF_CT_ASSERT(skb->nfct); 860 NF_CT_ASSERT(skb->nfct);
@@ -815,11 +869,15 @@ nf_conntrack_in(struct net *net, u_int8_t pf, unsigned int hooknum,
815 NF_CT_STAT_INC_ATOMIC(net, invalid); 869 NF_CT_STAT_INC_ATOMIC(net, invalid);
816 if (ret == -NF_DROP) 870 if (ret == -NF_DROP)
817 NF_CT_STAT_INC_ATOMIC(net, drop); 871 NF_CT_STAT_INC_ATOMIC(net, drop);
818 return -ret; 872 ret = -ret;
873 goto out;
819 } 874 }
820 875
821 if (set_reply && !test_and_set_bit(IPS_SEEN_REPLY_BIT, &ct->status)) 876 if (set_reply && !test_and_set_bit(IPS_SEEN_REPLY_BIT, &ct->status))
822 nf_conntrack_event_cache(IPCT_STATUS, ct); 877 nf_conntrack_event_cache(IPCT_REPLY, ct);
878out:
879 if (tmpl)
880 nf_ct_put(tmpl);
823 881
824 return ret; 882 return ret;
825} 883}
@@ -858,7 +916,7 @@ void nf_conntrack_alter_reply(struct nf_conn *ct,
858 return; 916 return;
859 917
860 rcu_read_lock(); 918 rcu_read_lock();
861 __nf_ct_try_assign_helper(ct, GFP_ATOMIC); 919 __nf_ct_try_assign_helper(ct, NULL, GFP_ATOMIC);
862 rcu_read_unlock(); 920 rcu_read_unlock();
863} 921}
864EXPORT_SYMBOL_GPL(nf_conntrack_alter_reply); 922EXPORT_SYMBOL_GPL(nf_conntrack_alter_reply);
@@ -932,6 +990,14 @@ bool __nf_ct_kill_acct(struct nf_conn *ct,
932} 990}
933EXPORT_SYMBOL_GPL(__nf_ct_kill_acct); 991EXPORT_SYMBOL_GPL(__nf_ct_kill_acct);
934 992
993#ifdef CONFIG_NF_CONNTRACK_ZONES
994static struct nf_ct_ext_type nf_ct_zone_extend __read_mostly = {
995 .len = sizeof(struct nf_conntrack_zone),
996 .align = __alignof__(struct nf_conntrack_zone),
997 .id = NF_CT_EXT_ZONE,
998};
999#endif
1000
935#if defined(CONFIG_NF_CT_NETLINK) || defined(CONFIG_NF_CT_NETLINK_MODULE) 1001#if defined(CONFIG_NF_CT_NETLINK) || defined(CONFIG_NF_CT_NETLINK_MODULE)
936 1002
937#include <linux/netfilter/nfnetlink.h> 1003#include <linux/netfilter/nfnetlink.h>
@@ -1008,7 +1074,7 @@ get_next_corpse(struct net *net, int (*iter)(struct nf_conn *i, void *data),
1008 struct hlist_nulls_node *n; 1074 struct hlist_nulls_node *n;
1009 1075
1010 spin_lock_bh(&nf_conntrack_lock); 1076 spin_lock_bh(&nf_conntrack_lock);
1011 for (; *bucket < nf_conntrack_htable_size; (*bucket)++) { 1077 for (; *bucket < net->ct.htable_size; (*bucket)++) {
1012 hlist_nulls_for_each_entry(h, n, &net->ct.hash[*bucket], hnnode) { 1078 hlist_nulls_for_each_entry(h, n, &net->ct.hash[*bucket], hnnode) {
1013 ct = nf_ct_tuplehash_to_ctrack(h); 1079 ct = nf_ct_tuplehash_to_ctrack(h);
1014 if (iter(ct, data)) 1080 if (iter(ct, data))
@@ -1107,9 +1173,15 @@ static void nf_ct_release_dying_list(struct net *net)
1107 1173
1108static void nf_conntrack_cleanup_init_net(void) 1174static void nf_conntrack_cleanup_init_net(void)
1109{ 1175{
1176 /* wait until all references to nf_conntrack_untracked are dropped */
1177 while (atomic_read(&nf_conntrack_untracked.ct_general.use) > 1)
1178 schedule();
1179
1110 nf_conntrack_helper_fini(); 1180 nf_conntrack_helper_fini();
1111 nf_conntrack_proto_fini(); 1181 nf_conntrack_proto_fini();
1112 kmem_cache_destroy(nf_conntrack_cachep); 1182#ifdef CONFIG_NF_CONNTRACK_ZONES
1183 nf_ct_extend_unregister(&nf_ct_zone_extend);
1184#endif
1113} 1185}
1114 1186
1115static void nf_conntrack_cleanup_net(struct net *net) 1187static void nf_conntrack_cleanup_net(struct net *net)
@@ -1121,15 +1193,14 @@ static void nf_conntrack_cleanup_net(struct net *net)
1121 schedule(); 1193 schedule();
1122 goto i_see_dead_people; 1194 goto i_see_dead_people;
1123 } 1195 }
1124 /* wait until all references to nf_conntrack_untracked are dropped */
1125 while (atomic_read(&nf_conntrack_untracked.ct_general.use) > 1)
1126 schedule();
1127 1196
1128 nf_ct_free_hashtable(net->ct.hash, net->ct.hash_vmalloc, 1197 nf_ct_free_hashtable(net->ct.hash, net->ct.hash_vmalloc,
1129 nf_conntrack_htable_size); 1198 net->ct.htable_size);
1130 nf_conntrack_ecache_fini(net); 1199 nf_conntrack_ecache_fini(net);
1131 nf_conntrack_acct_fini(net); 1200 nf_conntrack_acct_fini(net);
1132 nf_conntrack_expect_fini(net); 1201 nf_conntrack_expect_fini(net);
1202 kmem_cache_destroy(net->ct.nf_conntrack_cachep);
1203 kfree(net->ct.slabname);
1133 free_percpu(net->ct.stat); 1204 free_percpu(net->ct.stat);
1134} 1205}
1135 1206
@@ -1184,9 +1255,12 @@ int nf_conntrack_set_hashsize(const char *val, struct kernel_param *kp)
1184{ 1255{
1185 int i, bucket, vmalloced, old_vmalloced; 1256 int i, bucket, vmalloced, old_vmalloced;
1186 unsigned int hashsize, old_size; 1257 unsigned int hashsize, old_size;
1187 int rnd;
1188 struct hlist_nulls_head *hash, *old_hash; 1258 struct hlist_nulls_head *hash, *old_hash;
1189 struct nf_conntrack_tuple_hash *h; 1259 struct nf_conntrack_tuple_hash *h;
1260 struct nf_conn *ct;
1261
1262 if (current->nsproxy->net_ns != &init_net)
1263 return -EOPNOTSUPP;
1190 1264
1191 /* On boot, we can set this without any fancy locking. */ 1265 /* On boot, we can set this without any fancy locking. */
1192 if (!nf_conntrack_htable_size) 1266 if (!nf_conntrack_htable_size)
@@ -1200,33 +1274,31 @@ int nf_conntrack_set_hashsize(const char *val, struct kernel_param *kp)
1200 if (!hash) 1274 if (!hash)
1201 return -ENOMEM; 1275 return -ENOMEM;
1202 1276
1203 /* We have to rehahs for the new table anyway, so we also can
1204 * use a newrandom seed */
1205 get_random_bytes(&rnd, sizeof(rnd));
1206
1207 /* Lookups in the old hash might happen in parallel, which means we 1277 /* Lookups in the old hash might happen in parallel, which means we
1208 * might get false negatives during connection lookup. New connections 1278 * might get false negatives during connection lookup. New connections
1209 * created because of a false negative won't make it into the hash 1279 * created because of a false negative won't make it into the hash
1210 * though since that required taking the lock. 1280 * though since that required taking the lock.
1211 */ 1281 */
1212 spin_lock_bh(&nf_conntrack_lock); 1282 spin_lock_bh(&nf_conntrack_lock);
1213 for (i = 0; i < nf_conntrack_htable_size; i++) { 1283 for (i = 0; i < init_net.ct.htable_size; i++) {
1214 while (!hlist_nulls_empty(&init_net.ct.hash[i])) { 1284 while (!hlist_nulls_empty(&init_net.ct.hash[i])) {
1215 h = hlist_nulls_entry(init_net.ct.hash[i].first, 1285 h = hlist_nulls_entry(init_net.ct.hash[i].first,
1216 struct nf_conntrack_tuple_hash, hnnode); 1286 struct nf_conntrack_tuple_hash, hnnode);
1287 ct = nf_ct_tuplehash_to_ctrack(h);
1217 hlist_nulls_del_rcu(&h->hnnode); 1288 hlist_nulls_del_rcu(&h->hnnode);
1218 bucket = __hash_conntrack(&h->tuple, hashsize, rnd); 1289 bucket = __hash_conntrack(&h->tuple, nf_ct_zone(ct),
1290 hashsize,
1291 nf_conntrack_hash_rnd);
1219 hlist_nulls_add_head_rcu(&h->hnnode, &hash[bucket]); 1292 hlist_nulls_add_head_rcu(&h->hnnode, &hash[bucket]);
1220 } 1293 }
1221 } 1294 }
1222 old_size = nf_conntrack_htable_size; 1295 old_size = init_net.ct.htable_size;
1223 old_vmalloced = init_net.ct.hash_vmalloc; 1296 old_vmalloced = init_net.ct.hash_vmalloc;
1224 old_hash = init_net.ct.hash; 1297 old_hash = init_net.ct.hash;
1225 1298
1226 nf_conntrack_htable_size = hashsize; 1299 init_net.ct.htable_size = nf_conntrack_htable_size = hashsize;
1227 init_net.ct.hash_vmalloc = vmalloced; 1300 init_net.ct.hash_vmalloc = vmalloced;
1228 init_net.ct.hash = hash; 1301 init_net.ct.hash = hash;
1229 nf_conntrack_hash_rnd = rnd;
1230 spin_unlock_bh(&nf_conntrack_lock); 1302 spin_unlock_bh(&nf_conntrack_lock);
1231 1303
1232 nf_ct_free_hashtable(old_hash, old_vmalloced, old_size); 1304 nf_ct_free_hashtable(old_hash, old_vmalloced, old_size);
@@ -1265,15 +1337,6 @@ static int nf_conntrack_init_init_net(void)
1265 NF_CONNTRACK_VERSION, nf_conntrack_htable_size, 1337 NF_CONNTRACK_VERSION, nf_conntrack_htable_size,
1266 nf_conntrack_max); 1338 nf_conntrack_max);
1267 1339
1268 nf_conntrack_cachep = kmem_cache_create("nf_conntrack",
1269 sizeof(struct nf_conn),
1270 0, SLAB_DESTROY_BY_RCU, NULL);
1271 if (!nf_conntrack_cachep) {
1272 printk(KERN_ERR "Unable to create nf_conn slab cache\n");
1273 ret = -ENOMEM;
1274 goto err_cache;
1275 }
1276
1277 ret = nf_conntrack_proto_init(); 1340 ret = nf_conntrack_proto_init();
1278 if (ret < 0) 1341 if (ret < 0)
1279 goto err_proto; 1342 goto err_proto;
@@ -1282,13 +1345,28 @@ static int nf_conntrack_init_init_net(void)
1282 if (ret < 0) 1345 if (ret < 0)
1283 goto err_helper; 1346 goto err_helper;
1284 1347
1348#ifdef CONFIG_NF_CONNTRACK_ZONES
1349 ret = nf_ct_extend_register(&nf_ct_zone_extend);
1350 if (ret < 0)
1351 goto err_extend;
1352#endif
1353 /* Set up fake conntrack: to never be deleted, not in any hashes */
1354#ifdef CONFIG_NET_NS
1355 nf_conntrack_untracked.ct_net = &init_net;
1356#endif
1357 atomic_set(&nf_conntrack_untracked.ct_general.use, 1);
1358 /* - and look it like as a confirmed connection */
1359 set_bit(IPS_CONFIRMED_BIT, &nf_conntrack_untracked.status);
1360
1285 return 0; 1361 return 0;
1286 1362
1363#ifdef CONFIG_NF_CONNTRACK_ZONES
1364err_extend:
1365 nf_conntrack_helper_fini();
1366#endif
1287err_helper: 1367err_helper:
1288 nf_conntrack_proto_fini(); 1368 nf_conntrack_proto_fini();
1289err_proto: 1369err_proto:
1290 kmem_cache_destroy(nf_conntrack_cachep);
1291err_cache:
1292 return ret; 1370 return ret;
1293} 1371}
1294 1372
@@ -1310,7 +1388,24 @@ static int nf_conntrack_init_net(struct net *net)
1310 ret = -ENOMEM; 1388 ret = -ENOMEM;
1311 goto err_stat; 1389 goto err_stat;
1312 } 1390 }
1313 net->ct.hash = nf_ct_alloc_hashtable(&nf_conntrack_htable_size, 1391
1392 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
1393 if (!net->ct.slabname) {
1394 ret = -ENOMEM;
1395 goto err_slabname;
1396 }
1397
1398 net->ct.nf_conntrack_cachep = kmem_cache_create(net->ct.slabname,
1399 sizeof(struct nf_conn), 0,
1400 SLAB_DESTROY_BY_RCU, NULL);
1401 if (!net->ct.nf_conntrack_cachep) {
1402 printk(KERN_ERR "Unable to create nf_conn slab cache\n");
1403 ret = -ENOMEM;
1404 goto err_cache;
1405 }
1406
1407 net->ct.htable_size = nf_conntrack_htable_size;
1408 net->ct.hash = nf_ct_alloc_hashtable(&net->ct.htable_size,
1314 &net->ct.hash_vmalloc, 1); 1409 &net->ct.hash_vmalloc, 1);
1315 if (!net->ct.hash) { 1410 if (!net->ct.hash) {
1316 ret = -ENOMEM; 1411 ret = -ENOMEM;
@@ -1327,15 +1422,6 @@ static int nf_conntrack_init_net(struct net *net)
1327 if (ret < 0) 1422 if (ret < 0)
1328 goto err_ecache; 1423 goto err_ecache;
1329 1424
1330 /* Set up fake conntrack:
1331 - to never be deleted, not in any hashes */
1332#ifdef CONFIG_NET_NS
1333 nf_conntrack_untracked.ct_net = &init_net;
1334#endif
1335 atomic_set(&nf_conntrack_untracked.ct_general.use, 1);
1336 /* - and look it like as a confirmed connection */
1337 set_bit(IPS_CONFIRMED_BIT, &nf_conntrack_untracked.status);
1338
1339 return 0; 1425 return 0;
1340 1426
1341err_ecache: 1427err_ecache:
@@ -1344,8 +1430,12 @@ err_acct:
1344 nf_conntrack_expect_fini(net); 1430 nf_conntrack_expect_fini(net);
1345err_expect: 1431err_expect:
1346 nf_ct_free_hashtable(net->ct.hash, net->ct.hash_vmalloc, 1432 nf_ct_free_hashtable(net->ct.hash, net->ct.hash_vmalloc,
1347 nf_conntrack_htable_size); 1433 net->ct.htable_size);
1348err_hash: 1434err_hash:
1435 kmem_cache_destroy(net->ct.nf_conntrack_cachep);
1436err_cache:
1437 kfree(net->ct.slabname);
1438err_slabname:
1349 free_percpu(net->ct.stat); 1439 free_percpu(net->ct.stat);
1350err_stat: 1440err_stat:
1351 return ret; 1441 return ret;
diff --git a/net/netfilter/nf_conntrack_ecache.c b/net/netfilter/nf_conntrack_ecache.c
index aee560b4768d..f516961a83b4 100644
--- a/net/netfilter/nf_conntrack_ecache.c
+++ b/net/netfilter/nf_conntrack_ecache.c
@@ -18,6 +18,7 @@
18#include <linux/percpu.h> 18#include <linux/percpu.h>
19#include <linux/kernel.h> 19#include <linux/kernel.h>
20#include <linux/netdevice.h> 20#include <linux/netdevice.h>
21#include <linux/slab.h>
21 22
22#include <net/netfilter/nf_conntrack.h> 23#include <net/netfilter/nf_conntrack.h>
23#include <net/netfilter/nf_conntrack_core.h> 24#include <net/netfilter/nf_conntrack_core.h>
@@ -151,7 +152,6 @@ static int nf_ct_events_retry_timeout __read_mostly = 15*HZ;
151#ifdef CONFIG_SYSCTL 152#ifdef CONFIG_SYSCTL
152static struct ctl_table event_sysctl_table[] = { 153static struct ctl_table event_sysctl_table[] = {
153 { 154 {
154 .ctl_name = CTL_UNNUMBERED,
155 .procname = "nf_conntrack_events", 155 .procname = "nf_conntrack_events",
156 .data = &init_net.ct.sysctl_events, 156 .data = &init_net.ct.sysctl_events,
157 .maxlen = sizeof(unsigned int), 157 .maxlen = sizeof(unsigned int),
@@ -159,7 +159,6 @@ static struct ctl_table event_sysctl_table[] = {
159 .proc_handler = proc_dointvec, 159 .proc_handler = proc_dointvec,
160 }, 160 },
161 { 161 {
162 .ctl_name = CTL_UNNUMBERED,
163 .procname = "nf_conntrack_events_retry_timeout", 162 .procname = "nf_conntrack_events_retry_timeout",
164 .data = &init_net.ct.sysctl_events_retry_timeout, 163 .data = &init_net.ct.sysctl_events_retry_timeout,
165 .maxlen = sizeof(unsigned int), 164 .maxlen = sizeof(unsigned int),
diff --git a/net/netfilter/nf_conntrack_expect.c b/net/netfilter/nf_conntrack_expect.c
index 2032dfe25ca8..acb29ccaa41f 100644
--- a/net/netfilter/nf_conntrack_expect.c
+++ b/net/netfilter/nf_conntrack_expect.c
@@ -27,6 +27,7 @@
27#include <net/netfilter/nf_conntrack_expect.h> 27#include <net/netfilter/nf_conntrack_expect.h>
28#include <net/netfilter/nf_conntrack_helper.h> 28#include <net/netfilter/nf_conntrack_helper.h>
29#include <net/netfilter/nf_conntrack_tuple.h> 29#include <net/netfilter/nf_conntrack_tuple.h>
30#include <net/netfilter/nf_conntrack_zones.h>
30 31
31unsigned int nf_ct_expect_hsize __read_mostly; 32unsigned int nf_ct_expect_hsize __read_mostly;
32EXPORT_SYMBOL_GPL(nf_ct_expect_hsize); 33EXPORT_SYMBOL_GPL(nf_ct_expect_hsize);
@@ -84,7 +85,8 @@ static unsigned int nf_ct_expect_dst_hash(const struct nf_conntrack_tuple *tuple
84} 85}
85 86
86struct nf_conntrack_expect * 87struct nf_conntrack_expect *
87__nf_ct_expect_find(struct net *net, const struct nf_conntrack_tuple *tuple) 88__nf_ct_expect_find(struct net *net, u16 zone,
89 const struct nf_conntrack_tuple *tuple)
88{ 90{
89 struct nf_conntrack_expect *i; 91 struct nf_conntrack_expect *i;
90 struct hlist_node *n; 92 struct hlist_node *n;
@@ -95,7 +97,8 @@ __nf_ct_expect_find(struct net *net, const struct nf_conntrack_tuple *tuple)
95 97
96 h = nf_ct_expect_dst_hash(tuple); 98 h = nf_ct_expect_dst_hash(tuple);
97 hlist_for_each_entry_rcu(i, n, &net->ct.expect_hash[h], hnode) { 99 hlist_for_each_entry_rcu(i, n, &net->ct.expect_hash[h], hnode) {
98 if (nf_ct_tuple_mask_cmp(tuple, &i->tuple, &i->mask)) 100 if (nf_ct_tuple_mask_cmp(tuple, &i->tuple, &i->mask) &&
101 nf_ct_zone(i->master) == zone)
99 return i; 102 return i;
100 } 103 }
101 return NULL; 104 return NULL;
@@ -104,12 +107,13 @@ EXPORT_SYMBOL_GPL(__nf_ct_expect_find);
104 107
105/* Just find a expectation corresponding to a tuple. */ 108/* Just find a expectation corresponding to a tuple. */
106struct nf_conntrack_expect * 109struct nf_conntrack_expect *
107nf_ct_expect_find_get(struct net *net, const struct nf_conntrack_tuple *tuple) 110nf_ct_expect_find_get(struct net *net, u16 zone,
111 const struct nf_conntrack_tuple *tuple)
108{ 112{
109 struct nf_conntrack_expect *i; 113 struct nf_conntrack_expect *i;
110 114
111 rcu_read_lock(); 115 rcu_read_lock();
112 i = __nf_ct_expect_find(net, tuple); 116 i = __nf_ct_expect_find(net, zone, tuple);
113 if (i && !atomic_inc_not_zero(&i->use)) 117 if (i && !atomic_inc_not_zero(&i->use))
114 i = NULL; 118 i = NULL;
115 rcu_read_unlock(); 119 rcu_read_unlock();
@@ -121,7 +125,8 @@ EXPORT_SYMBOL_GPL(nf_ct_expect_find_get);
121/* If an expectation for this connection is found, it gets delete from 125/* If an expectation for this connection is found, it gets delete from
122 * global list then returned. */ 126 * global list then returned. */
123struct nf_conntrack_expect * 127struct nf_conntrack_expect *
124nf_ct_find_expectation(struct net *net, const struct nf_conntrack_tuple *tuple) 128nf_ct_find_expectation(struct net *net, u16 zone,
129 const struct nf_conntrack_tuple *tuple)
125{ 130{
126 struct nf_conntrack_expect *i, *exp = NULL; 131 struct nf_conntrack_expect *i, *exp = NULL;
127 struct hlist_node *n; 132 struct hlist_node *n;
@@ -133,7 +138,8 @@ nf_ct_find_expectation(struct net *net, const struct nf_conntrack_tuple *tuple)
133 h = nf_ct_expect_dst_hash(tuple); 138 h = nf_ct_expect_dst_hash(tuple);
134 hlist_for_each_entry(i, n, &net->ct.expect_hash[h], hnode) { 139 hlist_for_each_entry(i, n, &net->ct.expect_hash[h], hnode) {
135 if (!(i->flags & NF_CT_EXPECT_INACTIVE) && 140 if (!(i->flags & NF_CT_EXPECT_INACTIVE) &&
136 nf_ct_tuple_mask_cmp(tuple, &i->tuple, &i->mask)) { 141 nf_ct_tuple_mask_cmp(tuple, &i->tuple, &i->mask) &&
142 nf_ct_zone(i->master) == zone) {
137 exp = i; 143 exp = i;
138 break; 144 break;
139 } 145 }
@@ -202,9 +208,10 @@ static inline int expect_clash(const struct nf_conntrack_expect *a,
202static inline int expect_matches(const struct nf_conntrack_expect *a, 208static inline int expect_matches(const struct nf_conntrack_expect *a,
203 const struct nf_conntrack_expect *b) 209 const struct nf_conntrack_expect *b)
204{ 210{
205 return a->master == b->master && a->class == b->class 211 return a->master == b->master && a->class == b->class &&
206 && nf_ct_tuple_equal(&a->tuple, &b->tuple) 212 nf_ct_tuple_equal(&a->tuple, &b->tuple) &&
207 && nf_ct_tuple_mask_equal(&a->mask, &b->mask); 213 nf_ct_tuple_mask_equal(&a->mask, &b->mask) &&
214 nf_ct_zone(a->master) == nf_ct_zone(b->master);
208} 215}
209 216
210/* Generally a bad idea to call this: could have matched already. */ 217/* Generally a bad idea to call this: could have matched already. */
@@ -232,7 +239,6 @@ struct nf_conntrack_expect *nf_ct_expect_alloc(struct nf_conn *me)
232 239
233 new->master = me; 240 new->master = me;
234 atomic_set(&new->use, 1); 241 atomic_set(&new->use, 1);
235 INIT_RCU_HEAD(&new->rcu);
236 return new; 242 return new;
237} 243}
238EXPORT_SYMBOL_GPL(nf_ct_expect_alloc); 244EXPORT_SYMBOL_GPL(nf_ct_expect_alloc);
@@ -500,6 +506,7 @@ static void exp_seq_stop(struct seq_file *seq, void *v)
500static int exp_seq_show(struct seq_file *s, void *v) 506static int exp_seq_show(struct seq_file *s, void *v)
501{ 507{
502 struct nf_conntrack_expect *expect; 508 struct nf_conntrack_expect *expect;
509 struct nf_conntrack_helper *helper;
503 struct hlist_node *n = v; 510 struct hlist_node *n = v;
504 char *delim = ""; 511 char *delim = "";
505 512
@@ -525,6 +532,14 @@ static int exp_seq_show(struct seq_file *s, void *v)
525 if (expect->flags & NF_CT_EXPECT_INACTIVE) 532 if (expect->flags & NF_CT_EXPECT_INACTIVE)
526 seq_printf(s, "%sINACTIVE", delim); 533 seq_printf(s, "%sINACTIVE", delim);
527 534
535 helper = rcu_dereference(nfct_help(expect->master)->helper);
536 if (helper) {
537 seq_printf(s, "%s%s", expect->flags ? " " : "", helper->name);
538 if (helper->expect_policy[expect->class].name)
539 seq_printf(s, "/%s",
540 helper->expect_policy[expect->class].name);
541 }
542
528 return seq_putc(s, '\n'); 543 return seq_putc(s, '\n');
529} 544}
530 545
@@ -569,7 +584,7 @@ static void exp_proc_remove(struct net *net)
569#endif /* CONFIG_PROC_FS */ 584#endif /* CONFIG_PROC_FS */
570} 585}
571 586
572module_param_named(expect_hashsize, nf_ct_expect_hsize, uint, 0600); 587module_param_named(expect_hashsize, nf_ct_expect_hsize, uint, 0400);
573 588
574int nf_conntrack_expect_init(struct net *net) 589int nf_conntrack_expect_init(struct net *net)
575{ 590{
@@ -577,7 +592,7 @@ int nf_conntrack_expect_init(struct net *net)
577 592
578 if (net_eq(net, &init_net)) { 593 if (net_eq(net, &init_net)) {
579 if (!nf_ct_expect_hsize) { 594 if (!nf_ct_expect_hsize) {
580 nf_ct_expect_hsize = nf_conntrack_htable_size / 256; 595 nf_ct_expect_hsize = net->ct.htable_size / 256;
581 if (!nf_ct_expect_hsize) 596 if (!nf_ct_expect_hsize)
582 nf_ct_expect_hsize = 1; 597 nf_ct_expect_hsize = 1;
583 } 598 }
diff --git a/net/netfilter/nf_conntrack_extend.c b/net/netfilter/nf_conntrack_extend.c
index fef95be334bd..fdc8fb4ae10f 100644
--- a/net/netfilter/nf_conntrack_extend.c
+++ b/net/netfilter/nf_conntrack_extend.c
@@ -59,7 +59,6 @@ nf_ct_ext_create(struct nf_ct_ext **ext, enum nf_ct_ext_id id, gfp_t gfp)
59 if (!*ext) 59 if (!*ext)
60 return NULL; 60 return NULL;
61 61
62 INIT_RCU_HEAD(&(*ext)->rcu);
63 (*ext)->offset[id] = off; 62 (*ext)->offset[id] = off;
64 (*ext)->len = len; 63 (*ext)->len = len;
65 64
diff --git a/net/netfilter/nf_conntrack_ftp.c b/net/netfilter/nf_conntrack_ftp.c
index 5509dd1f14cf..2ae3169e7633 100644
--- a/net/netfilter/nf_conntrack_ftp.c
+++ b/net/netfilter/nf_conntrack_ftp.c
@@ -13,6 +13,7 @@
13#include <linux/moduleparam.h> 13#include <linux/moduleparam.h>
14#include <linux/netfilter.h> 14#include <linux/netfilter.h>
15#include <linux/ip.h> 15#include <linux/ip.h>
16#include <linux/slab.h>
16#include <linux/ipv6.h> 17#include <linux/ipv6.h>
17#include <linux/ctype.h> 18#include <linux/ctype.h>
18#include <linux/inet.h> 19#include <linux/inet.h>
@@ -243,8 +244,8 @@ static int try_epsv_response(const char *data, size_t dlen,
243 /* Three delimiters. */ 244 /* Three delimiters. */
244 if (dlen <= 3) return 0; 245 if (dlen <= 3) return 0;
245 delim = data[0]; 246 delim = data[0];
246 if (isdigit(delim) || delim < 33 || delim > 126 247 if (isdigit(delim) || delim < 33 || delim > 126 ||
247 || data[1] != delim || data[2] != delim) 248 data[1] != delim || data[2] != delim)
248 return 0; 249 return 0;
249 250
250 return get_port(data, 3, dlen, delim, &cmd->u.tcp.port); 251 return get_port(data, 3, dlen, delim, &cmd->u.tcp.port);
@@ -323,24 +324,24 @@ static void update_nl_seq(struct nf_conn *ct, u32 nl_seq,
323 struct nf_ct_ftp_master *info, int dir, 324 struct nf_ct_ftp_master *info, int dir,
324 struct sk_buff *skb) 325 struct sk_buff *skb)
325{ 326{
326 unsigned int i, oldest = NUM_SEQ_TO_REMEMBER; 327 unsigned int i, oldest;
327 328
328 /* Look for oldest: if we find exact match, we're done. */ 329 /* Look for oldest: if we find exact match, we're done. */
329 for (i = 0; i < info->seq_aft_nl_num[dir]; i++) { 330 for (i = 0; i < info->seq_aft_nl_num[dir]; i++) {
330 if (info->seq_aft_nl[dir][i] == nl_seq) 331 if (info->seq_aft_nl[dir][i] == nl_seq)
331 return; 332 return;
332
333 if (oldest == info->seq_aft_nl_num[dir] ||
334 before(info->seq_aft_nl[dir][i],
335 info->seq_aft_nl[dir][oldest]))
336 oldest = i;
337 } 333 }
338 334
339 if (info->seq_aft_nl_num[dir] < NUM_SEQ_TO_REMEMBER) { 335 if (info->seq_aft_nl_num[dir] < NUM_SEQ_TO_REMEMBER) {
340 info->seq_aft_nl[dir][info->seq_aft_nl_num[dir]++] = nl_seq; 336 info->seq_aft_nl[dir][info->seq_aft_nl_num[dir]++] = nl_seq;
341 } else if (oldest != NUM_SEQ_TO_REMEMBER && 337 } else {
342 after(nl_seq, info->seq_aft_nl[dir][oldest])) { 338 if (before(info->seq_aft_nl[dir][0], info->seq_aft_nl[dir][1]))
343 info->seq_aft_nl[dir][oldest] = nl_seq; 339 oldest = 0;
340 else
341 oldest = 1;
342
343 if (after(nl_seq, info->seq_aft_nl[dir][oldest]))
344 info->seq_aft_nl[dir][oldest] = nl_seq;
344 } 345 }
345} 346}
346 347
@@ -366,8 +367,8 @@ static int help(struct sk_buff *skb,
366 typeof(nf_nat_ftp_hook) nf_nat_ftp; 367 typeof(nf_nat_ftp_hook) nf_nat_ftp;
367 368
368 /* Until there's been traffic both ways, don't look in packets. */ 369 /* Until there's been traffic both ways, don't look in packets. */
369 if (ctinfo != IP_CT_ESTABLISHED 370 if (ctinfo != IP_CT_ESTABLISHED &&
370 && ctinfo != IP_CT_ESTABLISHED+IP_CT_IS_REPLY) { 371 ctinfo != IP_CT_ESTABLISHED + IP_CT_IS_REPLY) {
371 pr_debug("ftp: Conntrackinfo = %u\n", ctinfo); 372 pr_debug("ftp: Conntrackinfo = %u\n", ctinfo);
372 return NF_ACCEPT; 373 return NF_ACCEPT;
373 } 374 }
diff --git a/net/netfilter/nf_conntrack_h323_main.c b/net/netfilter/nf_conntrack_h323_main.c
index 66369490230e..a487c8038044 100644
--- a/net/netfilter/nf_conntrack_h323_main.c
+++ b/net/netfilter/nf_conntrack_h323_main.c
@@ -17,6 +17,7 @@
17#include <linux/inet.h> 17#include <linux/inet.h>
18#include <linux/in.h> 18#include <linux/in.h>
19#include <linux/ip.h> 19#include <linux/ip.h>
20#include <linux/slab.h>
20#include <linux/udp.h> 21#include <linux/udp.h>
21#include <linux/tcp.h> 22#include <linux/tcp.h>
22#include <linux/skbuff.h> 23#include <linux/skbuff.h>
@@ -29,6 +30,7 @@
29#include <net/netfilter/nf_conntrack_expect.h> 30#include <net/netfilter/nf_conntrack_expect.h>
30#include <net/netfilter/nf_conntrack_ecache.h> 31#include <net/netfilter/nf_conntrack_ecache.h>
31#include <net/netfilter/nf_conntrack_helper.h> 32#include <net/netfilter/nf_conntrack_helper.h>
33#include <net/netfilter/nf_conntrack_zones.h>
32#include <linux/netfilter/nf_conntrack_h323.h> 34#include <linux/netfilter/nf_conntrack_h323.h>
33 35
34/* Parameters */ 36/* Parameters */
@@ -1216,7 +1218,7 @@ static struct nf_conntrack_expect *find_expect(struct nf_conn *ct,
1216 tuple.dst.u.tcp.port = port; 1218 tuple.dst.u.tcp.port = port;
1217 tuple.dst.protonum = IPPROTO_TCP; 1219 tuple.dst.protonum = IPPROTO_TCP;
1218 1220
1219 exp = __nf_ct_expect_find(net, &tuple); 1221 exp = __nf_ct_expect_find(net, nf_ct_zone(ct), &tuple);
1220 if (exp && exp->master == ct) 1222 if (exp && exp->master == ct)
1221 return exp; 1223 return exp;
1222 return NULL; 1224 return NULL;
diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c
index 65c2a7bc3afc..59e1a4cd4e8b 100644
--- a/net/netfilter/nf_conntrack_helper.c
+++ b/net/netfilter/nf_conntrack_helper.c
@@ -15,7 +15,6 @@
15#include <linux/skbuff.h> 15#include <linux/skbuff.h>
16#include <linux/vmalloc.h> 16#include <linux/vmalloc.h>
17#include <linux/stddef.h> 17#include <linux/stddef.h>
18#include <linux/slab.h>
19#include <linux/random.h> 18#include <linux/random.h>
20#include <linux/err.h> 19#include <linux/err.h>
21#include <linux/kernel.h> 20#include <linux/kernel.h>
@@ -65,7 +64,7 @@ __nf_ct_helper_find(const struct nf_conntrack_tuple *tuple)
65} 64}
66 65
67struct nf_conntrack_helper * 66struct nf_conntrack_helper *
68__nf_conntrack_helper_find_byname(const char *name) 67__nf_conntrack_helper_find(const char *name, u16 l3num, u8 protonum)
69{ 68{
70 struct nf_conntrack_helper *h; 69 struct nf_conntrack_helper *h;
71 struct hlist_node *n; 70 struct hlist_node *n;
@@ -73,13 +72,34 @@ __nf_conntrack_helper_find_byname(const char *name)
73 72
74 for (i = 0; i < nf_ct_helper_hsize; i++) { 73 for (i = 0; i < nf_ct_helper_hsize; i++) {
75 hlist_for_each_entry_rcu(h, n, &nf_ct_helper_hash[i], hnode) { 74 hlist_for_each_entry_rcu(h, n, &nf_ct_helper_hash[i], hnode) {
76 if (!strcmp(h->name, name)) 75 if (!strcmp(h->name, name) &&
76 h->tuple.src.l3num == l3num &&
77 h->tuple.dst.protonum == protonum)
77 return h; 78 return h;
78 } 79 }
79 } 80 }
80 return NULL; 81 return NULL;
81} 82}
82EXPORT_SYMBOL_GPL(__nf_conntrack_helper_find_byname); 83EXPORT_SYMBOL_GPL(__nf_conntrack_helper_find);
84
85struct nf_conntrack_helper *
86nf_conntrack_helper_try_module_get(const char *name, u16 l3num, u8 protonum)
87{
88 struct nf_conntrack_helper *h;
89
90 h = __nf_conntrack_helper_find(name, l3num, protonum);
91#ifdef CONFIG_MODULES
92 if (h == NULL) {
93 if (request_module("nfct-helper-%s", name) == 0)
94 h = __nf_conntrack_helper_find(name, l3num, protonum);
95 }
96#endif
97 if (h != NULL && !try_module_get(h->me))
98 h = NULL;
99
100 return h;
101}
102EXPORT_SYMBOL_GPL(nf_conntrack_helper_try_module_get);
83 103
84struct nf_conn_help *nf_ct_helper_ext_add(struct nf_conn *ct, gfp_t gfp) 104struct nf_conn_help *nf_ct_helper_ext_add(struct nf_conn *ct, gfp_t gfp)
85{ 105{
@@ -94,13 +114,22 @@ struct nf_conn_help *nf_ct_helper_ext_add(struct nf_conn *ct, gfp_t gfp)
94} 114}
95EXPORT_SYMBOL_GPL(nf_ct_helper_ext_add); 115EXPORT_SYMBOL_GPL(nf_ct_helper_ext_add);
96 116
97int __nf_ct_try_assign_helper(struct nf_conn *ct, gfp_t flags) 117int __nf_ct_try_assign_helper(struct nf_conn *ct, struct nf_conn *tmpl,
118 gfp_t flags)
98{ 119{
120 struct nf_conntrack_helper *helper = NULL;
121 struct nf_conn_help *help;
99 int ret = 0; 122 int ret = 0;
100 struct nf_conntrack_helper *helper;
101 struct nf_conn_help *help = nfct_help(ct);
102 123
103 helper = __nf_ct_helper_find(&ct->tuplehash[IP_CT_DIR_REPLY].tuple); 124 if (tmpl != NULL) {
125 help = nfct_help(tmpl);
126 if (help != NULL)
127 helper = help->helper;
128 }
129
130 help = nfct_help(ct);
131 if (helper == NULL)
132 helper = __nf_ct_helper_find(&ct->tuplehash[IP_CT_DIR_REPLY].tuple);
104 if (helper == NULL) { 133 if (helper == NULL) {
105 if (help) 134 if (help)
106 rcu_assign_pointer(help->helper, NULL); 135 rcu_assign_pointer(help->helper, NULL);
@@ -192,7 +221,7 @@ static void __nf_conntrack_helper_unregister(struct nf_conntrack_helper *me,
192 /* Get rid of expecteds, set helpers to NULL. */ 221 /* Get rid of expecteds, set helpers to NULL. */
193 hlist_nulls_for_each_entry(h, nn, &net->ct.unconfirmed, hnnode) 222 hlist_nulls_for_each_entry(h, nn, &net->ct.unconfirmed, hnnode)
194 unhelp(h, me); 223 unhelp(h, me);
195 for (i = 0; i < nf_conntrack_htable_size; i++) { 224 for (i = 0; i < net->ct.htable_size; i++) {
196 hlist_nulls_for_each_entry(h, nn, &net->ct.hash[i], hnnode) 225 hlist_nulls_for_each_entry(h, nn, &net->ct.hash[i], hnnode)
197 unhelp(h, me); 226 unhelp(h, me);
198 } 227 }
diff --git a/net/netfilter/nf_conntrack_irc.c b/net/netfilter/nf_conntrack_irc.c
index 8bd98c84f77e..7673930ca342 100644
--- a/net/netfilter/nf_conntrack_irc.c
+++ b/net/netfilter/nf_conntrack_irc.c
@@ -15,6 +15,7 @@
15#include <linux/ip.h> 15#include <linux/ip.h>
16#include <linux/tcp.h> 16#include <linux/tcp.h>
17#include <linux/netfilter.h> 17#include <linux/netfilter.h>
18#include <linux/slab.h>
18 19
19#include <net/netfilter/nf_conntrack.h> 20#include <net/netfilter/nf_conntrack.h>
20#include <net/netfilter/nf_conntrack_expect.h> 21#include <net/netfilter/nf_conntrack_expect.h>
diff --git a/net/netfilter/nf_conntrack_netlink.c b/net/netfilter/nf_conntrack_netlink.c
index 59d8064eb522..afc52f2ee4ac 100644
--- a/net/netfilter/nf_conntrack_netlink.c
+++ b/net/netfilter/nf_conntrack_netlink.c
@@ -27,9 +27,11 @@
27#include <linux/netlink.h> 27#include <linux/netlink.h>
28#include <linux/spinlock.h> 28#include <linux/spinlock.h>
29#include <linux/interrupt.h> 29#include <linux/interrupt.h>
30#include <linux/slab.h>
30 31
31#include <linux/netfilter.h> 32#include <linux/netfilter.h>
32#include <net/netlink.h> 33#include <net/netlink.h>
34#include <net/sock.h>
33#include <net/netfilter/nf_conntrack.h> 35#include <net/netfilter/nf_conntrack.h>
34#include <net/netfilter/nf_conntrack_core.h> 36#include <net/netfilter/nf_conntrack_core.h>
35#include <net/netfilter/nf_conntrack_expect.h> 37#include <net/netfilter/nf_conntrack_expect.h>
@@ -38,6 +40,7 @@
38#include <net/netfilter/nf_conntrack_l4proto.h> 40#include <net/netfilter/nf_conntrack_l4proto.h>
39#include <net/netfilter/nf_conntrack_tuple.h> 41#include <net/netfilter/nf_conntrack_tuple.h>
40#include <net/netfilter/nf_conntrack_acct.h> 42#include <net/netfilter/nf_conntrack_acct.h>
43#include <net/netfilter/nf_conntrack_zones.h>
41#ifdef CONFIG_NF_NAT_NEEDED 44#ifdef CONFIG_NF_NAT_NEEDED
42#include <net/netfilter/nf_nat_core.h> 45#include <net/netfilter/nf_nat_core.h>
43#include <net/netfilter/nf_nat_protocol.h> 46#include <net/netfilter/nf_nat_protocol.h>
@@ -378,6 +381,9 @@ ctnetlink_fill_info(struct sk_buff *skb, u32 pid, u32 seq,
378 goto nla_put_failure; 381 goto nla_put_failure;
379 nla_nest_end(skb, nest_parms); 382 nla_nest_end(skb, nest_parms);
380 383
384 if (nf_ct_zone(ct))
385 NLA_PUT_BE16(skb, CTA_ZONE, htons(nf_ct_zone(ct)));
386
381 if (ctnetlink_dump_status(skb, ct) < 0 || 387 if (ctnetlink_dump_status(skb, ct) < 0 ||
382 ctnetlink_dump_timeout(skb, ct) < 0 || 388 ctnetlink_dump_timeout(skb, ct) < 0 ||
383 ctnetlink_dump_counters(skb, ct, IP_CT_DIR_ORIGINAL) < 0 || 389 ctnetlink_dump_counters(skb, ct, IP_CT_DIR_ORIGINAL) < 0 ||
@@ -456,6 +462,7 @@ ctnetlink_nlmsg_size(const struct nf_conn *ct)
456static int 462static int
457ctnetlink_conntrack_event(unsigned int events, struct nf_ct_event *item) 463ctnetlink_conntrack_event(unsigned int events, struct nf_ct_event *item)
458{ 464{
465 struct net *net;
459 struct nlmsghdr *nlh; 466 struct nlmsghdr *nlh;
460 struct nfgenmsg *nfmsg; 467 struct nfgenmsg *nfmsg;
461 struct nlattr *nest_parms; 468 struct nlattr *nest_parms;
@@ -482,7 +489,8 @@ ctnetlink_conntrack_event(unsigned int events, struct nf_ct_event *item)
482 } else 489 } else
483 return 0; 490 return 0;
484 491
485 if (!item->report && !nfnetlink_has_listeners(group)) 492 net = nf_ct_net(ct);
493 if (!item->report && !nfnetlink_has_listeners(net, group))
486 return 0; 494 return 0;
487 495
488 skb = nlmsg_new(ctnetlink_nlmsg_size(ct), GFP_ATOMIC); 496 skb = nlmsg_new(ctnetlink_nlmsg_size(ct), GFP_ATOMIC);
@@ -514,6 +522,9 @@ ctnetlink_conntrack_event(unsigned int events, struct nf_ct_event *item)
514 goto nla_put_failure; 522 goto nla_put_failure;
515 nla_nest_end(skb, nest_parms); 523 nla_nest_end(skb, nest_parms);
516 524
525 if (nf_ct_zone(ct))
526 NLA_PUT_BE16(skb, CTA_ZONE, htons(nf_ct_zone(ct)));
527
517 if (ctnetlink_dump_id(skb, ct) < 0) 528 if (ctnetlink_dump_id(skb, ct) < 0)
518 goto nla_put_failure; 529 goto nla_put_failure;
519 530
@@ -559,7 +570,8 @@ ctnetlink_conntrack_event(unsigned int events, struct nf_ct_event *item)
559 rcu_read_unlock(); 570 rcu_read_unlock();
560 571
561 nlmsg_end(skb, nlh); 572 nlmsg_end(skb, nlh);
562 err = nfnetlink_send(skb, item->pid, group, item->report, GFP_ATOMIC); 573 err = nfnetlink_send(skb, net, item->pid, group, item->report,
574 GFP_ATOMIC);
563 if (err == -ENOBUFS || err == -EAGAIN) 575 if (err == -ENOBUFS || err == -EAGAIN)
564 return -ENOBUFS; 576 return -ENOBUFS;
565 577
@@ -571,7 +583,9 @@ nla_put_failure:
571nlmsg_failure: 583nlmsg_failure:
572 kfree_skb(skb); 584 kfree_skb(skb);
573errout: 585errout:
574 nfnetlink_set_err(0, group, -ENOBUFS); 586 if (nfnetlink_set_err(net, 0, group, -ENOBUFS) > 0)
587 return -ENOBUFS;
588
575 return 0; 589 return 0;
576} 590}
577#endif /* CONFIG_NF_CONNTRACK_EVENTS */ 591#endif /* CONFIG_NF_CONNTRACK_EVENTS */
@@ -586,6 +600,7 @@ static int ctnetlink_done(struct netlink_callback *cb)
586static int 600static int
587ctnetlink_dump_table(struct sk_buff *skb, struct netlink_callback *cb) 601ctnetlink_dump_table(struct sk_buff *skb, struct netlink_callback *cb)
588{ 602{
603 struct net *net = sock_net(skb->sk);
589 struct nf_conn *ct, *last; 604 struct nf_conn *ct, *last;
590 struct nf_conntrack_tuple_hash *h; 605 struct nf_conntrack_tuple_hash *h;
591 struct hlist_nulls_node *n; 606 struct hlist_nulls_node *n;
@@ -594,9 +609,9 @@ ctnetlink_dump_table(struct sk_buff *skb, struct netlink_callback *cb)
594 609
595 rcu_read_lock(); 610 rcu_read_lock();
596 last = (struct nf_conn *)cb->args[1]; 611 last = (struct nf_conn *)cb->args[1];
597 for (; cb->args[0] < nf_conntrack_htable_size; cb->args[0]++) { 612 for (; cb->args[0] < net->ct.htable_size; cb->args[0]++) {
598restart: 613restart:
599 hlist_nulls_for_each_entry_rcu(h, n, &init_net.ct.hash[cb->args[0]], 614 hlist_nulls_for_each_entry_rcu(h, n, &net->ct.hash[cb->args[0]],
600 hnnode) { 615 hnnode) {
601 if (NF_CT_DIRECTION(h) != IP_CT_DIR_ORIGINAL) 616 if (NF_CT_DIRECTION(h) != IP_CT_DIR_ORIGINAL)
602 continue; 617 continue;
@@ -703,6 +718,11 @@ ctnetlink_parse_tuple_proto(struct nlattr *attr,
703 return ret; 718 return ret;
704} 719}
705 720
721static const struct nla_policy tuple_nla_policy[CTA_TUPLE_MAX+1] = {
722 [CTA_TUPLE_IP] = { .type = NLA_NESTED },
723 [CTA_TUPLE_PROTO] = { .type = NLA_NESTED },
724};
725
706static int 726static int
707ctnetlink_parse_tuple(const struct nlattr * const cda[], 727ctnetlink_parse_tuple(const struct nlattr * const cda[],
708 struct nf_conntrack_tuple *tuple, 728 struct nf_conntrack_tuple *tuple,
@@ -713,7 +733,7 @@ ctnetlink_parse_tuple(const struct nlattr * const cda[],
713 733
714 memset(tuple, 0, sizeof(*tuple)); 734 memset(tuple, 0, sizeof(*tuple));
715 735
716 nla_parse_nested(tb, CTA_TUPLE_MAX, cda[type], NULL); 736 nla_parse_nested(tb, CTA_TUPLE_MAX, cda[type], tuple_nla_policy);
717 737
718 if (!tb[CTA_TUPLE_IP]) 738 if (!tb[CTA_TUPLE_IP])
719 return -EINVAL; 739 return -EINVAL;
@@ -740,12 +760,31 @@ ctnetlink_parse_tuple(const struct nlattr * const cda[],
740 return 0; 760 return 0;
741} 761}
742 762
763static int
764ctnetlink_parse_zone(const struct nlattr *attr, u16 *zone)
765{
766 if (attr)
767#ifdef CONFIG_NF_CONNTRACK_ZONES
768 *zone = ntohs(nla_get_be16(attr));
769#else
770 return -EOPNOTSUPP;
771#endif
772 else
773 *zone = 0;
774
775 return 0;
776}
777
778static const struct nla_policy help_nla_policy[CTA_HELP_MAX+1] = {
779 [CTA_HELP_NAME] = { .type = NLA_NUL_STRING },
780};
781
743static inline int 782static inline int
744ctnetlink_parse_help(const struct nlattr *attr, char **helper_name) 783ctnetlink_parse_help(const struct nlattr *attr, char **helper_name)
745{ 784{
746 struct nlattr *tb[CTA_HELP_MAX+1]; 785 struct nlattr *tb[CTA_HELP_MAX+1];
747 786
748 nla_parse_nested(tb, CTA_HELP_MAX, attr, NULL); 787 nla_parse_nested(tb, CTA_HELP_MAX, attr, help_nla_policy);
749 788
750 if (!tb[CTA_HELP_NAME]) 789 if (!tb[CTA_HELP_NAME])
751 return -EINVAL; 790 return -EINVAL;
@@ -756,11 +795,18 @@ ctnetlink_parse_help(const struct nlattr *attr, char **helper_name)
756} 795}
757 796
758static const struct nla_policy ct_nla_policy[CTA_MAX+1] = { 797static const struct nla_policy ct_nla_policy[CTA_MAX+1] = {
798 [CTA_TUPLE_ORIG] = { .type = NLA_NESTED },
799 [CTA_TUPLE_REPLY] = { .type = NLA_NESTED },
759 [CTA_STATUS] = { .type = NLA_U32 }, 800 [CTA_STATUS] = { .type = NLA_U32 },
801 [CTA_PROTOINFO] = { .type = NLA_NESTED },
802 [CTA_HELP] = { .type = NLA_NESTED },
803 [CTA_NAT_SRC] = { .type = NLA_NESTED },
760 [CTA_TIMEOUT] = { .type = NLA_U32 }, 804 [CTA_TIMEOUT] = { .type = NLA_U32 },
761 [CTA_MARK] = { .type = NLA_U32 }, 805 [CTA_MARK] = { .type = NLA_U32 },
762 [CTA_USE] = { .type = NLA_U32 },
763 [CTA_ID] = { .type = NLA_U32 }, 806 [CTA_ID] = { .type = NLA_U32 },
807 [CTA_NAT_DST] = { .type = NLA_NESTED },
808 [CTA_TUPLE_MASTER] = { .type = NLA_NESTED },
809 [CTA_ZONE] = { .type = NLA_U16 },
764}; 810};
765 811
766static int 812static int
@@ -768,12 +814,18 @@ ctnetlink_del_conntrack(struct sock *ctnl, struct sk_buff *skb,
768 const struct nlmsghdr *nlh, 814 const struct nlmsghdr *nlh,
769 const struct nlattr * const cda[]) 815 const struct nlattr * const cda[])
770{ 816{
817 struct net *net = sock_net(ctnl);
771 struct nf_conntrack_tuple_hash *h; 818 struct nf_conntrack_tuple_hash *h;
772 struct nf_conntrack_tuple tuple; 819 struct nf_conntrack_tuple tuple;
773 struct nf_conn *ct; 820 struct nf_conn *ct;
774 struct nfgenmsg *nfmsg = nlmsg_data(nlh); 821 struct nfgenmsg *nfmsg = nlmsg_data(nlh);
775 u_int8_t u3 = nfmsg->nfgen_family; 822 u_int8_t u3 = nfmsg->nfgen_family;
776 int err = 0; 823 u16 zone;
824 int err;
825
826 err = ctnetlink_parse_zone(cda[CTA_ZONE], &zone);
827 if (err < 0)
828 return err;
777 829
778 if (cda[CTA_TUPLE_ORIG]) 830 if (cda[CTA_TUPLE_ORIG])
779 err = ctnetlink_parse_tuple(cda, &tuple, CTA_TUPLE_ORIG, u3); 831 err = ctnetlink_parse_tuple(cda, &tuple, CTA_TUPLE_ORIG, u3);
@@ -781,7 +833,7 @@ ctnetlink_del_conntrack(struct sock *ctnl, struct sk_buff *skb,
781 err = ctnetlink_parse_tuple(cda, &tuple, CTA_TUPLE_REPLY, u3); 833 err = ctnetlink_parse_tuple(cda, &tuple, CTA_TUPLE_REPLY, u3);
782 else { 834 else {
783 /* Flush the whole table */ 835 /* Flush the whole table */
784 nf_conntrack_flush_report(&init_net, 836 nf_conntrack_flush_report(net,
785 NETLINK_CB(skb).pid, 837 NETLINK_CB(skb).pid,
786 nlmsg_report(nlh)); 838 nlmsg_report(nlh));
787 return 0; 839 return 0;
@@ -790,7 +842,7 @@ ctnetlink_del_conntrack(struct sock *ctnl, struct sk_buff *skb,
790 if (err < 0) 842 if (err < 0)
791 return err; 843 return err;
792 844
793 h = nf_conntrack_find_get(&init_net, &tuple); 845 h = nf_conntrack_find_get(net, zone, &tuple);
794 if (!h) 846 if (!h)
795 return -ENOENT; 847 return -ENOENT;
796 848
@@ -828,18 +880,24 @@ ctnetlink_get_conntrack(struct sock *ctnl, struct sk_buff *skb,
828 const struct nlmsghdr *nlh, 880 const struct nlmsghdr *nlh,
829 const struct nlattr * const cda[]) 881 const struct nlattr * const cda[])
830{ 882{
883 struct net *net = sock_net(ctnl);
831 struct nf_conntrack_tuple_hash *h; 884 struct nf_conntrack_tuple_hash *h;
832 struct nf_conntrack_tuple tuple; 885 struct nf_conntrack_tuple tuple;
833 struct nf_conn *ct; 886 struct nf_conn *ct;
834 struct sk_buff *skb2 = NULL; 887 struct sk_buff *skb2 = NULL;
835 struct nfgenmsg *nfmsg = nlmsg_data(nlh); 888 struct nfgenmsg *nfmsg = nlmsg_data(nlh);
836 u_int8_t u3 = nfmsg->nfgen_family; 889 u_int8_t u3 = nfmsg->nfgen_family;
837 int err = 0; 890 u16 zone;
891 int err;
838 892
839 if (nlh->nlmsg_flags & NLM_F_DUMP) 893 if (nlh->nlmsg_flags & NLM_F_DUMP)
840 return netlink_dump_start(ctnl, skb, nlh, ctnetlink_dump_table, 894 return netlink_dump_start(ctnl, skb, nlh, ctnetlink_dump_table,
841 ctnetlink_done); 895 ctnetlink_done);
842 896
897 err = ctnetlink_parse_zone(cda[CTA_ZONE], &zone);
898 if (err < 0)
899 return err;
900
843 if (cda[CTA_TUPLE_ORIG]) 901 if (cda[CTA_TUPLE_ORIG])
844 err = ctnetlink_parse_tuple(cda, &tuple, CTA_TUPLE_ORIG, u3); 902 err = ctnetlink_parse_tuple(cda, &tuple, CTA_TUPLE_ORIG, u3);
845 else if (cda[CTA_TUPLE_REPLY]) 903 else if (cda[CTA_TUPLE_REPLY])
@@ -850,7 +908,7 @@ ctnetlink_get_conntrack(struct sock *ctnl, struct sk_buff *skb,
850 if (err < 0) 908 if (err < 0)
851 return err; 909 return err;
852 910
853 h = nf_conntrack_find_get(&init_net, &tuple); 911 h = nf_conntrack_find_get(net, zone, &tuple);
854 if (!h) 912 if (!h)
855 return -ENOENT; 913 return -ENOENT;
856 914
@@ -994,7 +1052,8 @@ ctnetlink_change_helper(struct nf_conn *ct, const struct nlattr * const cda[])
994 return 0; 1052 return 0;
995 } 1053 }
996 1054
997 helper = __nf_conntrack_helper_find_byname(helpname); 1055 helper = __nf_conntrack_helper_find(helpname, nf_ct_l3num(ct),
1056 nf_ct_protonum(ct));
998 if (helper == NULL) { 1057 if (helper == NULL) {
999#ifdef CONFIG_MODULES 1058#ifdef CONFIG_MODULES
1000 spin_unlock_bh(&nf_conntrack_lock); 1059 spin_unlock_bh(&nf_conntrack_lock);
@@ -1005,7 +1064,8 @@ ctnetlink_change_helper(struct nf_conn *ct, const struct nlattr * const cda[])
1005 } 1064 }
1006 1065
1007 spin_lock_bh(&nf_conntrack_lock); 1066 spin_lock_bh(&nf_conntrack_lock);
1008 helper = __nf_conntrack_helper_find_byname(helpname); 1067 helper = __nf_conntrack_helper_find(helpname, nf_ct_l3num(ct),
1068 nf_ct_protonum(ct));
1009 if (helper) 1069 if (helper)
1010 return -EAGAIN; 1070 return -EAGAIN;
1011#endif 1071#endif
@@ -1020,9 +1080,8 @@ ctnetlink_change_helper(struct nf_conn *ct, const struct nlattr * const cda[])
1020 /* need to zero data of old helper */ 1080 /* need to zero data of old helper */
1021 memset(&help->help, 0, sizeof(help->help)); 1081 memset(&help->help, 0, sizeof(help->help));
1022 } else { 1082 } else {
1023 help = nf_ct_helper_ext_add(ct, GFP_ATOMIC); 1083 /* we cannot set a helper for an existing conntrack */
1024 if (help == NULL) 1084 return -EOPNOTSUPP;
1025 return -ENOMEM;
1026 } 1085 }
1027 1086
1028 rcu_assign_pointer(help->helper, helper); 1087 rcu_assign_pointer(help->helper, helper);
@@ -1044,6 +1103,12 @@ ctnetlink_change_timeout(struct nf_conn *ct, const struct nlattr * const cda[])
1044 return 0; 1103 return 0;
1045} 1104}
1046 1105
1106static const struct nla_policy protoinfo_policy[CTA_PROTOINFO_MAX+1] = {
1107 [CTA_PROTOINFO_TCP] = { .type = NLA_NESTED },
1108 [CTA_PROTOINFO_DCCP] = { .type = NLA_NESTED },
1109 [CTA_PROTOINFO_SCTP] = { .type = NLA_NESTED },
1110};
1111
1047static inline int 1112static inline int
1048ctnetlink_change_protoinfo(struct nf_conn *ct, const struct nlattr * const cda[]) 1113ctnetlink_change_protoinfo(struct nf_conn *ct, const struct nlattr * const cda[])
1049{ 1114{
@@ -1052,7 +1117,7 @@ ctnetlink_change_protoinfo(struct nf_conn *ct, const struct nlattr * const cda[]
1052 struct nf_conntrack_l4proto *l4proto; 1117 struct nf_conntrack_l4proto *l4proto;
1053 int err = 0; 1118 int err = 0;
1054 1119
1055 nla_parse_nested(tb, CTA_PROTOINFO_MAX, attr, NULL); 1120 nla_parse_nested(tb, CTA_PROTOINFO_MAX, attr, protoinfo_policy);
1056 1121
1057 rcu_read_lock(); 1122 rcu_read_lock();
1058 l4proto = __nf_ct_l4proto_find(nf_ct_l3num(ct), nf_ct_protonum(ct)); 1123 l4proto = __nf_ct_l4proto_find(nf_ct_l3num(ct), nf_ct_protonum(ct));
@@ -1064,12 +1129,18 @@ ctnetlink_change_protoinfo(struct nf_conn *ct, const struct nlattr * const cda[]
1064} 1129}
1065 1130
1066#ifdef CONFIG_NF_NAT_NEEDED 1131#ifdef CONFIG_NF_NAT_NEEDED
1132static const struct nla_policy nat_seq_policy[CTA_NAT_SEQ_MAX+1] = {
1133 [CTA_NAT_SEQ_CORRECTION_POS] = { .type = NLA_U32 },
1134 [CTA_NAT_SEQ_OFFSET_BEFORE] = { .type = NLA_U32 },
1135 [CTA_NAT_SEQ_OFFSET_AFTER] = { .type = NLA_U32 },
1136};
1137
1067static inline int 1138static inline int
1068change_nat_seq_adj(struct nf_nat_seq *natseq, const struct nlattr * const attr) 1139change_nat_seq_adj(struct nf_nat_seq *natseq, const struct nlattr * const attr)
1069{ 1140{
1070 struct nlattr *cda[CTA_NAT_SEQ_MAX+1]; 1141 struct nlattr *cda[CTA_NAT_SEQ_MAX+1];
1071 1142
1072 nla_parse_nested(cda, CTA_NAT_SEQ_MAX, attr, NULL); 1143 nla_parse_nested(cda, CTA_NAT_SEQ_MAX, attr, nat_seq_policy);
1073 1144
1074 if (!cda[CTA_NAT_SEQ_CORRECTION_POS]) 1145 if (!cda[CTA_NAT_SEQ_CORRECTION_POS])
1075 return -EINVAL; 1146 return -EINVAL;
@@ -1175,7 +1246,8 @@ ctnetlink_change_conntrack(struct nf_conn *ct,
1175} 1246}
1176 1247
1177static struct nf_conn * 1248static struct nf_conn *
1178ctnetlink_create_conntrack(const struct nlattr * const cda[], 1249ctnetlink_create_conntrack(struct net *net, u16 zone,
1250 const struct nlattr * const cda[],
1179 struct nf_conntrack_tuple *otuple, 1251 struct nf_conntrack_tuple *otuple,
1180 struct nf_conntrack_tuple *rtuple, 1252 struct nf_conntrack_tuple *rtuple,
1181 u8 u3) 1253 u8 u3)
@@ -1184,7 +1256,7 @@ ctnetlink_create_conntrack(const struct nlattr * const cda[],
1184 int err = -EINVAL; 1256 int err = -EINVAL;
1185 struct nf_conntrack_helper *helper; 1257 struct nf_conntrack_helper *helper;
1186 1258
1187 ct = nf_conntrack_alloc(&init_net, otuple, rtuple, GFP_ATOMIC); 1259 ct = nf_conntrack_alloc(net, zone, otuple, rtuple, GFP_ATOMIC);
1188 if (IS_ERR(ct)) 1260 if (IS_ERR(ct))
1189 return ERR_PTR(-ENOMEM); 1261 return ERR_PTR(-ENOMEM);
1190 1262
@@ -1193,7 +1265,6 @@ ctnetlink_create_conntrack(const struct nlattr * const cda[],
1193 ct->timeout.expires = ntohl(nla_get_be32(cda[CTA_TIMEOUT])); 1265 ct->timeout.expires = ntohl(nla_get_be32(cda[CTA_TIMEOUT]));
1194 1266
1195 ct->timeout.expires = jiffies + ct->timeout.expires * HZ; 1267 ct->timeout.expires = jiffies + ct->timeout.expires * HZ;
1196 ct->status |= IPS_CONFIRMED;
1197 1268
1198 rcu_read_lock(); 1269 rcu_read_lock();
1199 if (cda[CTA_HELP]) { 1270 if (cda[CTA_HELP]) {
@@ -1203,7 +1274,8 @@ ctnetlink_create_conntrack(const struct nlattr * const cda[],
1203 if (err < 0) 1274 if (err < 0)
1204 goto err2; 1275 goto err2;
1205 1276
1206 helper = __nf_conntrack_helper_find_byname(helpname); 1277 helper = __nf_conntrack_helper_find(helpname, nf_ct_l3num(ct),
1278 nf_ct_protonum(ct));
1207 if (helper == NULL) { 1279 if (helper == NULL) {
1208 rcu_read_unlock(); 1280 rcu_read_unlock();
1209#ifdef CONFIG_MODULES 1281#ifdef CONFIG_MODULES
@@ -1213,7 +1285,9 @@ ctnetlink_create_conntrack(const struct nlattr * const cda[],
1213 } 1285 }
1214 1286
1215 rcu_read_lock(); 1287 rcu_read_lock();
1216 helper = __nf_conntrack_helper_find_byname(helpname); 1288 helper = __nf_conntrack_helper_find(helpname,
1289 nf_ct_l3num(ct),
1290 nf_ct_protonum(ct));
1217 if (helper) { 1291 if (helper) {
1218 err = -EAGAIN; 1292 err = -EAGAIN;
1219 goto err2; 1293 goto err2;
@@ -1236,19 +1310,24 @@ ctnetlink_create_conntrack(const struct nlattr * const cda[],
1236 } 1310 }
1237 } else { 1311 } else {
1238 /* try an implicit helper assignation */ 1312 /* try an implicit helper assignation */
1239 err = __nf_ct_try_assign_helper(ct, GFP_ATOMIC); 1313 err = __nf_ct_try_assign_helper(ct, NULL, GFP_ATOMIC);
1240 if (err < 0) 1314 if (err < 0)
1241 goto err2; 1315 goto err2;
1242 } 1316 }
1243 1317
1244 if (cda[CTA_STATUS]) { 1318 if (cda[CTA_NAT_SRC] || cda[CTA_NAT_DST]) {
1245 err = ctnetlink_change_status(ct, cda); 1319 err = ctnetlink_change_nat(ct, cda);
1246 if (err < 0) 1320 if (err < 0)
1247 goto err2; 1321 goto err2;
1248 } 1322 }
1249 1323
1250 if (cda[CTA_NAT_SRC] || cda[CTA_NAT_DST]) { 1324 nf_ct_acct_ext_add(ct, GFP_ATOMIC);
1251 err = ctnetlink_change_nat(ct, cda); 1325 nf_ct_ecache_ext_add(ct, 0, 0, GFP_ATOMIC);
1326 /* we must add conntrack extensions before confirmation. */
1327 ct->status |= IPS_CONFIRMED;
1328
1329 if (cda[CTA_STATUS]) {
1330 err = ctnetlink_change_status(ct, cda);
1252 if (err < 0) 1331 if (err < 0)
1253 goto err2; 1332 goto err2;
1254 } 1333 }
@@ -1267,9 +1346,6 @@ ctnetlink_create_conntrack(const struct nlattr * const cda[],
1267 goto err2; 1346 goto err2;
1268 } 1347 }
1269 1348
1270 nf_ct_acct_ext_add(ct, GFP_ATOMIC);
1271 nf_ct_ecache_ext_add(ct, GFP_ATOMIC);
1272
1273#if defined(CONFIG_NF_CONNTRACK_MARK) 1349#if defined(CONFIG_NF_CONNTRACK_MARK)
1274 if (cda[CTA_MARK]) 1350 if (cda[CTA_MARK])
1275 ct->mark = ntohl(nla_get_be32(cda[CTA_MARK])); 1351 ct->mark = ntohl(nla_get_be32(cda[CTA_MARK]));
@@ -1285,7 +1361,7 @@ ctnetlink_create_conntrack(const struct nlattr * const cda[],
1285 if (err < 0) 1361 if (err < 0)
1286 goto err2; 1362 goto err2;
1287 1363
1288 master_h = nf_conntrack_find_get(&init_net, &master); 1364 master_h = nf_conntrack_find_get(net, zone, &master);
1289 if (master_h == NULL) { 1365 if (master_h == NULL) {
1290 err = -ENOENT; 1366 err = -ENOENT;
1291 goto err2; 1367 goto err2;
@@ -1313,11 +1389,17 @@ ctnetlink_new_conntrack(struct sock *ctnl, struct sk_buff *skb,
1313 const struct nlmsghdr *nlh, 1389 const struct nlmsghdr *nlh,
1314 const struct nlattr * const cda[]) 1390 const struct nlattr * const cda[])
1315{ 1391{
1392 struct net *net = sock_net(ctnl);
1316 struct nf_conntrack_tuple otuple, rtuple; 1393 struct nf_conntrack_tuple otuple, rtuple;
1317 struct nf_conntrack_tuple_hash *h = NULL; 1394 struct nf_conntrack_tuple_hash *h = NULL;
1318 struct nfgenmsg *nfmsg = nlmsg_data(nlh); 1395 struct nfgenmsg *nfmsg = nlmsg_data(nlh);
1319 u_int8_t u3 = nfmsg->nfgen_family; 1396 u_int8_t u3 = nfmsg->nfgen_family;
1320 int err = 0; 1397 u16 zone;
1398 int err;
1399
1400 err = ctnetlink_parse_zone(cda[CTA_ZONE], &zone);
1401 if (err < 0)
1402 return err;
1321 1403
1322 if (cda[CTA_TUPLE_ORIG]) { 1404 if (cda[CTA_TUPLE_ORIG]) {
1323 err = ctnetlink_parse_tuple(cda, &otuple, CTA_TUPLE_ORIG, u3); 1405 err = ctnetlink_parse_tuple(cda, &otuple, CTA_TUPLE_ORIG, u3);
@@ -1333,9 +1415,9 @@ ctnetlink_new_conntrack(struct sock *ctnl, struct sk_buff *skb,
1333 1415
1334 spin_lock_bh(&nf_conntrack_lock); 1416 spin_lock_bh(&nf_conntrack_lock);
1335 if (cda[CTA_TUPLE_ORIG]) 1417 if (cda[CTA_TUPLE_ORIG])
1336 h = __nf_conntrack_find(&init_net, &otuple); 1418 h = __nf_conntrack_find(net, zone, &otuple);
1337 else if (cda[CTA_TUPLE_REPLY]) 1419 else if (cda[CTA_TUPLE_REPLY])
1338 h = __nf_conntrack_find(&init_net, &rtuple); 1420 h = __nf_conntrack_find(net, zone, &rtuple);
1339 1421
1340 if (h == NULL) { 1422 if (h == NULL) {
1341 err = -ENOENT; 1423 err = -ENOENT;
@@ -1343,7 +1425,7 @@ ctnetlink_new_conntrack(struct sock *ctnl, struct sk_buff *skb,
1343 struct nf_conn *ct; 1425 struct nf_conn *ct;
1344 enum ip_conntrack_events events; 1426 enum ip_conntrack_events events;
1345 1427
1346 ct = ctnetlink_create_conntrack(cda, &otuple, 1428 ct = ctnetlink_create_conntrack(net, zone, cda, &otuple,
1347 &rtuple, u3); 1429 &rtuple, u3);
1348 if (IS_ERR(ct)) { 1430 if (IS_ERR(ct)) {
1349 err = PTR_ERR(ct); 1431 err = PTR_ERR(ct);
@@ -1357,7 +1439,8 @@ ctnetlink_new_conntrack(struct sock *ctnl, struct sk_buff *skb,
1357 else 1439 else
1358 events = IPCT_NEW; 1440 events = IPCT_NEW;
1359 1441
1360 nf_conntrack_eventmask_report((1 << IPCT_STATUS) | 1442 nf_conntrack_eventmask_report((1 << IPCT_REPLY) |
1443 (1 << IPCT_ASSURED) |
1361 (1 << IPCT_HELPER) | 1444 (1 << IPCT_HELPER) |
1362 (1 << IPCT_PROTOINFO) | 1445 (1 << IPCT_PROTOINFO) |
1363 (1 << IPCT_NATSEQADJ) | 1446 (1 << IPCT_NATSEQADJ) |
@@ -1382,7 +1465,8 @@ ctnetlink_new_conntrack(struct sock *ctnl, struct sk_buff *skb,
1382 if (err == 0) { 1465 if (err == 0) {
1383 nf_conntrack_get(&ct->ct_general); 1466 nf_conntrack_get(&ct->ct_general);
1384 spin_unlock_bh(&nf_conntrack_lock); 1467 spin_unlock_bh(&nf_conntrack_lock);
1385 nf_conntrack_eventmask_report((1 << IPCT_STATUS) | 1468 nf_conntrack_eventmask_report((1 << IPCT_REPLY) |
1469 (1 << IPCT_ASSURED) |
1386 (1 << IPCT_HELPER) | 1470 (1 << IPCT_HELPER) |
1387 (1 << IPCT_PROTOINFO) | 1471 (1 << IPCT_PROTOINFO) |
1388 (1 << IPCT_NATSEQADJ) | 1472 (1 << IPCT_NATSEQADJ) |
@@ -1437,8 +1521,9 @@ ctnetlink_exp_dump_mask(struct sk_buff *skb,
1437 struct nlattr *nest_parms; 1521 struct nlattr *nest_parms;
1438 1522
1439 memset(&m, 0xFF, sizeof(m)); 1523 memset(&m, 0xFF, sizeof(m));
1440 m.src.u.all = mask->src.u.all;
1441 memcpy(&m.src.u3, &mask->src.u3, sizeof(m.src.u3)); 1524 memcpy(&m.src.u3, &mask->src.u3, sizeof(m.src.u3));
1525 m.src.u.all = mask->src.u.all;
1526 m.dst.protonum = tuple->dst.protonum;
1442 1527
1443 nest_parms = nla_nest_start(skb, CTA_EXPECT_MASK | NLA_F_NESTED); 1528 nest_parms = nla_nest_start(skb, CTA_EXPECT_MASK | NLA_F_NESTED);
1444 if (!nest_parms) 1529 if (!nest_parms)
@@ -1468,6 +1553,7 @@ ctnetlink_exp_dump_expect(struct sk_buff *skb,
1468 const struct nf_conntrack_expect *exp) 1553 const struct nf_conntrack_expect *exp)
1469{ 1554{
1470 struct nf_conn *master = exp->master; 1555 struct nf_conn *master = exp->master;
1556 struct nf_conntrack_helper *helper;
1471 long timeout = (exp->timeout.expires - jiffies) / HZ; 1557 long timeout = (exp->timeout.expires - jiffies) / HZ;
1472 1558
1473 if (timeout < 0) 1559 if (timeout < 0)
@@ -1484,6 +1570,9 @@ ctnetlink_exp_dump_expect(struct sk_buff *skb,
1484 1570
1485 NLA_PUT_BE32(skb, CTA_EXPECT_TIMEOUT, htonl(timeout)); 1571 NLA_PUT_BE32(skb, CTA_EXPECT_TIMEOUT, htonl(timeout));
1486 NLA_PUT_BE32(skb, CTA_EXPECT_ID, htonl((unsigned long)exp)); 1572 NLA_PUT_BE32(skb, CTA_EXPECT_ID, htonl((unsigned long)exp));
1573 helper = rcu_dereference(nfct_help(master)->helper);
1574 if (helper)
1575 NLA_PUT_STRING(skb, CTA_EXPECT_HELP_NAME, helper->name);
1487 1576
1488 return 0; 1577 return 0;
1489 1578
@@ -1525,9 +1614,10 @@ nla_put_failure:
1525static int 1614static int
1526ctnetlink_expect_event(unsigned int events, struct nf_exp_event *item) 1615ctnetlink_expect_event(unsigned int events, struct nf_exp_event *item)
1527{ 1616{
1617 struct nf_conntrack_expect *exp = item->exp;
1618 struct net *net = nf_ct_exp_net(exp);
1528 struct nlmsghdr *nlh; 1619 struct nlmsghdr *nlh;
1529 struct nfgenmsg *nfmsg; 1620 struct nfgenmsg *nfmsg;
1530 struct nf_conntrack_expect *exp = item->exp;
1531 struct sk_buff *skb; 1621 struct sk_buff *skb;
1532 unsigned int type; 1622 unsigned int type;
1533 int flags = 0; 1623 int flags = 0;
@@ -1539,7 +1629,7 @@ ctnetlink_expect_event(unsigned int events, struct nf_exp_event *item)
1539 return 0; 1629 return 0;
1540 1630
1541 if (!item->report && 1631 if (!item->report &&
1542 !nfnetlink_has_listeners(NFNLGRP_CONNTRACK_EXP_NEW)) 1632 !nfnetlink_has_listeners(net, NFNLGRP_CONNTRACK_EXP_NEW))
1543 return 0; 1633 return 0;
1544 1634
1545 skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); 1635 skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
@@ -1562,7 +1652,7 @@ ctnetlink_expect_event(unsigned int events, struct nf_exp_event *item)
1562 rcu_read_unlock(); 1652 rcu_read_unlock();
1563 1653
1564 nlmsg_end(skb, nlh); 1654 nlmsg_end(skb, nlh);
1565 nfnetlink_send(skb, item->pid, NFNLGRP_CONNTRACK_EXP_NEW, 1655 nfnetlink_send(skb, net, item->pid, NFNLGRP_CONNTRACK_EXP_NEW,
1566 item->report, GFP_ATOMIC); 1656 item->report, GFP_ATOMIC);
1567 return 0; 1657 return 0;
1568 1658
@@ -1572,7 +1662,7 @@ nla_put_failure:
1572nlmsg_failure: 1662nlmsg_failure:
1573 kfree_skb(skb); 1663 kfree_skb(skb);
1574errout: 1664errout:
1575 nfnetlink_set_err(0, 0, -ENOBUFS); 1665 nfnetlink_set_err(net, 0, 0, -ENOBUFS);
1576 return 0; 1666 return 0;
1577} 1667}
1578#endif 1668#endif
@@ -1586,7 +1676,7 @@ static int ctnetlink_exp_done(struct netlink_callback *cb)
1586static int 1676static int
1587ctnetlink_exp_dump_table(struct sk_buff *skb, struct netlink_callback *cb) 1677ctnetlink_exp_dump_table(struct sk_buff *skb, struct netlink_callback *cb)
1588{ 1678{
1589 struct net *net = &init_net; 1679 struct net *net = sock_net(skb->sk);
1590 struct nf_conntrack_expect *exp, *last; 1680 struct nf_conntrack_expect *exp, *last;
1591 struct nfgenmsg *nfmsg = nlmsg_data(cb->nlh); 1681 struct nfgenmsg *nfmsg = nlmsg_data(cb->nlh);
1592 struct hlist_node *n; 1682 struct hlist_node *n;
@@ -1630,8 +1720,12 @@ out:
1630} 1720}
1631 1721
1632static const struct nla_policy exp_nla_policy[CTA_EXPECT_MAX+1] = { 1722static const struct nla_policy exp_nla_policy[CTA_EXPECT_MAX+1] = {
1723 [CTA_EXPECT_MASTER] = { .type = NLA_NESTED },
1724 [CTA_EXPECT_TUPLE] = { .type = NLA_NESTED },
1725 [CTA_EXPECT_MASK] = { .type = NLA_NESTED },
1633 [CTA_EXPECT_TIMEOUT] = { .type = NLA_U32 }, 1726 [CTA_EXPECT_TIMEOUT] = { .type = NLA_U32 },
1634 [CTA_EXPECT_ID] = { .type = NLA_U32 }, 1727 [CTA_EXPECT_ID] = { .type = NLA_U32 },
1728 [CTA_EXPECT_HELP_NAME] = { .type = NLA_NUL_STRING },
1635}; 1729};
1636 1730
1637static int 1731static int
@@ -1639,12 +1733,14 @@ ctnetlink_get_expect(struct sock *ctnl, struct sk_buff *skb,
1639 const struct nlmsghdr *nlh, 1733 const struct nlmsghdr *nlh,
1640 const struct nlattr * const cda[]) 1734 const struct nlattr * const cda[])
1641{ 1735{
1736 struct net *net = sock_net(ctnl);
1642 struct nf_conntrack_tuple tuple; 1737 struct nf_conntrack_tuple tuple;
1643 struct nf_conntrack_expect *exp; 1738 struct nf_conntrack_expect *exp;
1644 struct sk_buff *skb2; 1739 struct sk_buff *skb2;
1645 struct nfgenmsg *nfmsg = nlmsg_data(nlh); 1740 struct nfgenmsg *nfmsg = nlmsg_data(nlh);
1646 u_int8_t u3 = nfmsg->nfgen_family; 1741 u_int8_t u3 = nfmsg->nfgen_family;
1647 int err = 0; 1742 u16 zone;
1743 int err;
1648 1744
1649 if (nlh->nlmsg_flags & NLM_F_DUMP) { 1745 if (nlh->nlmsg_flags & NLM_F_DUMP) {
1650 return netlink_dump_start(ctnl, skb, nlh, 1746 return netlink_dump_start(ctnl, skb, nlh,
@@ -1652,6 +1748,10 @@ ctnetlink_get_expect(struct sock *ctnl, struct sk_buff *skb,
1652 ctnetlink_exp_done); 1748 ctnetlink_exp_done);
1653 } 1749 }
1654 1750
1751 err = ctnetlink_parse_zone(cda[CTA_EXPECT_ZONE], &zone);
1752 if (err < 0)
1753 return err;
1754
1655 if (cda[CTA_EXPECT_MASTER]) 1755 if (cda[CTA_EXPECT_MASTER])
1656 err = ctnetlink_parse_tuple(cda, &tuple, CTA_EXPECT_MASTER, u3); 1756 err = ctnetlink_parse_tuple(cda, &tuple, CTA_EXPECT_MASTER, u3);
1657 else 1757 else
@@ -1660,7 +1760,7 @@ ctnetlink_get_expect(struct sock *ctnl, struct sk_buff *skb,
1660 if (err < 0) 1760 if (err < 0)
1661 return err; 1761 return err;
1662 1762
1663 exp = nf_ct_expect_find_get(&init_net, &tuple); 1763 exp = nf_ct_expect_find_get(net, zone, &tuple);
1664 if (!exp) 1764 if (!exp)
1665 return -ENOENT; 1765 return -ENOENT;
1666 1766
@@ -1700,23 +1800,28 @@ ctnetlink_del_expect(struct sock *ctnl, struct sk_buff *skb,
1700 const struct nlmsghdr *nlh, 1800 const struct nlmsghdr *nlh,
1701 const struct nlattr * const cda[]) 1801 const struct nlattr * const cda[])
1702{ 1802{
1803 struct net *net = sock_net(ctnl);
1703 struct nf_conntrack_expect *exp; 1804 struct nf_conntrack_expect *exp;
1704 struct nf_conntrack_tuple tuple; 1805 struct nf_conntrack_tuple tuple;
1705 struct nf_conntrack_helper *h;
1706 struct nfgenmsg *nfmsg = nlmsg_data(nlh); 1806 struct nfgenmsg *nfmsg = nlmsg_data(nlh);
1707 struct hlist_node *n, *next; 1807 struct hlist_node *n, *next;
1708 u_int8_t u3 = nfmsg->nfgen_family; 1808 u_int8_t u3 = nfmsg->nfgen_family;
1709 unsigned int i; 1809 unsigned int i;
1810 u16 zone;
1710 int err; 1811 int err;
1711 1812
1712 if (cda[CTA_EXPECT_TUPLE]) { 1813 if (cda[CTA_EXPECT_TUPLE]) {
1713 /* delete a single expect by tuple */ 1814 /* delete a single expect by tuple */
1815 err = ctnetlink_parse_zone(cda[CTA_EXPECT_ZONE], &zone);
1816 if (err < 0)
1817 return err;
1818
1714 err = ctnetlink_parse_tuple(cda, &tuple, CTA_EXPECT_TUPLE, u3); 1819 err = ctnetlink_parse_tuple(cda, &tuple, CTA_EXPECT_TUPLE, u3);
1715 if (err < 0) 1820 if (err < 0)
1716 return err; 1821 return err;
1717 1822
1718 /* bump usage count to 2 */ 1823 /* bump usage count to 2 */
1719 exp = nf_ct_expect_find_get(&init_net, &tuple); 1824 exp = nf_ct_expect_find_get(net, zone, &tuple);
1720 if (!exp) 1825 if (!exp)
1721 return -ENOENT; 1826 return -ENOENT;
1722 1827
@@ -1739,18 +1844,13 @@ ctnetlink_del_expect(struct sock *ctnl, struct sk_buff *skb,
1739 1844
1740 /* delete all expectations for this helper */ 1845 /* delete all expectations for this helper */
1741 spin_lock_bh(&nf_conntrack_lock); 1846 spin_lock_bh(&nf_conntrack_lock);
1742 h = __nf_conntrack_helper_find_byname(name);
1743 if (!h) {
1744 spin_unlock_bh(&nf_conntrack_lock);
1745 return -EOPNOTSUPP;
1746 }
1747 for (i = 0; i < nf_ct_expect_hsize; i++) { 1847 for (i = 0; i < nf_ct_expect_hsize; i++) {
1748 hlist_for_each_entry_safe(exp, n, next, 1848 hlist_for_each_entry_safe(exp, n, next,
1749 &init_net.ct.expect_hash[i], 1849 &net->ct.expect_hash[i],
1750 hnode) { 1850 hnode) {
1751 m_help = nfct_help(exp->master); 1851 m_help = nfct_help(exp->master);
1752 if (m_help->helper == h 1852 if (!strcmp(m_help->helper->name, name) &&
1753 && del_timer(&exp->timeout)) { 1853 del_timer(&exp->timeout)) {
1754 nf_ct_unlink_expect(exp); 1854 nf_ct_unlink_expect(exp);
1755 nf_ct_expect_put(exp); 1855 nf_ct_expect_put(exp);
1756 } 1856 }
@@ -1762,7 +1862,7 @@ ctnetlink_del_expect(struct sock *ctnl, struct sk_buff *skb,
1762 spin_lock_bh(&nf_conntrack_lock); 1862 spin_lock_bh(&nf_conntrack_lock);
1763 for (i = 0; i < nf_ct_expect_hsize; i++) { 1863 for (i = 0; i < nf_ct_expect_hsize; i++) {
1764 hlist_for_each_entry_safe(exp, n, next, 1864 hlist_for_each_entry_safe(exp, n, next,
1765 &init_net.ct.expect_hash[i], 1865 &net->ct.expect_hash[i],
1766 hnode) { 1866 hnode) {
1767 if (del_timer(&exp->timeout)) { 1867 if (del_timer(&exp->timeout)) {
1768 nf_ct_unlink_expect(exp); 1868 nf_ct_unlink_expect(exp);
@@ -1783,7 +1883,9 @@ ctnetlink_change_expect(struct nf_conntrack_expect *x,
1783} 1883}
1784 1884
1785static int 1885static int
1786ctnetlink_create_expect(const struct nlattr * const cda[], u_int8_t u3, 1886ctnetlink_create_expect(struct net *net, u16 zone,
1887 const struct nlattr * const cda[],
1888 u_int8_t u3,
1787 u32 pid, int report) 1889 u32 pid, int report)
1788{ 1890{
1789 struct nf_conntrack_tuple tuple, mask, master_tuple; 1891 struct nf_conntrack_tuple tuple, mask, master_tuple;
@@ -1805,7 +1907,7 @@ ctnetlink_create_expect(const struct nlattr * const cda[], u_int8_t u3,
1805 return err; 1907 return err;
1806 1908
1807 /* Look for master conntrack of this expectation */ 1909 /* Look for master conntrack of this expectation */
1808 h = nf_conntrack_find_get(&init_net, &master_tuple); 1910 h = nf_conntrack_find_get(net, zone, &master_tuple);
1809 if (!h) 1911 if (!h)
1810 return -ENOENT; 1912 return -ENOENT;
1811 ct = nf_ct_tuplehash_to_ctrack(h); 1913 ct = nf_ct_tuplehash_to_ctrack(h);
@@ -1845,29 +1947,35 @@ ctnetlink_new_expect(struct sock *ctnl, struct sk_buff *skb,
1845 const struct nlmsghdr *nlh, 1947 const struct nlmsghdr *nlh,
1846 const struct nlattr * const cda[]) 1948 const struct nlattr * const cda[])
1847{ 1949{
1950 struct net *net = sock_net(ctnl);
1848 struct nf_conntrack_tuple tuple; 1951 struct nf_conntrack_tuple tuple;
1849 struct nf_conntrack_expect *exp; 1952 struct nf_conntrack_expect *exp;
1850 struct nfgenmsg *nfmsg = nlmsg_data(nlh); 1953 struct nfgenmsg *nfmsg = nlmsg_data(nlh);
1851 u_int8_t u3 = nfmsg->nfgen_family; 1954 u_int8_t u3 = nfmsg->nfgen_family;
1852 int err = 0; 1955 u16 zone;
1956 int err;
1853 1957
1854 if (!cda[CTA_EXPECT_TUPLE] 1958 if (!cda[CTA_EXPECT_TUPLE]
1855 || !cda[CTA_EXPECT_MASK] 1959 || !cda[CTA_EXPECT_MASK]
1856 || !cda[CTA_EXPECT_MASTER]) 1960 || !cda[CTA_EXPECT_MASTER])
1857 return -EINVAL; 1961 return -EINVAL;
1858 1962
1963 err = ctnetlink_parse_zone(cda[CTA_EXPECT_ZONE], &zone);
1964 if (err < 0)
1965 return err;
1966
1859 err = ctnetlink_parse_tuple(cda, &tuple, CTA_EXPECT_TUPLE, u3); 1967 err = ctnetlink_parse_tuple(cda, &tuple, CTA_EXPECT_TUPLE, u3);
1860 if (err < 0) 1968 if (err < 0)
1861 return err; 1969 return err;
1862 1970
1863 spin_lock_bh(&nf_conntrack_lock); 1971 spin_lock_bh(&nf_conntrack_lock);
1864 exp = __nf_ct_expect_find(&init_net, &tuple); 1972 exp = __nf_ct_expect_find(net, zone, &tuple);
1865 1973
1866 if (!exp) { 1974 if (!exp) {
1867 spin_unlock_bh(&nf_conntrack_lock); 1975 spin_unlock_bh(&nf_conntrack_lock);
1868 err = -ENOENT; 1976 err = -ENOENT;
1869 if (nlh->nlmsg_flags & NLM_F_CREATE) { 1977 if (nlh->nlmsg_flags & NLM_F_CREATE) {
1870 err = ctnetlink_create_expect(cda, 1978 err = ctnetlink_create_expect(net, zone, cda,
1871 u3, 1979 u3,
1872 NETLINK_CB(skb).pid, 1980 NETLINK_CB(skb).pid,
1873 nlmsg_report(nlh)); 1981 nlmsg_report(nlh));
diff --git a/net/netfilter/nf_conntrack_pptp.c b/net/netfilter/nf_conntrack_pptp.c
index 3807ac7faf4c..088944824e13 100644
--- a/net/netfilter/nf_conntrack_pptp.c
+++ b/net/netfilter/nf_conntrack_pptp.c
@@ -28,6 +28,7 @@
28#include <net/netfilter/nf_conntrack.h> 28#include <net/netfilter/nf_conntrack.h>
29#include <net/netfilter/nf_conntrack_core.h> 29#include <net/netfilter/nf_conntrack_core.h>
30#include <net/netfilter/nf_conntrack_helper.h> 30#include <net/netfilter/nf_conntrack_helper.h>
31#include <net/netfilter/nf_conntrack_zones.h>
31#include <linux/netfilter/nf_conntrack_proto_gre.h> 32#include <linux/netfilter/nf_conntrack_proto_gre.h>
32#include <linux/netfilter/nf_conntrack_pptp.h> 33#include <linux/netfilter/nf_conntrack_pptp.h>
33 34
@@ -123,7 +124,7 @@ static void pptp_expectfn(struct nf_conn *ct,
123 pr_debug("trying to unexpect other dir: "); 124 pr_debug("trying to unexpect other dir: ");
124 nf_ct_dump_tuple(&inv_t); 125 nf_ct_dump_tuple(&inv_t);
125 126
126 exp_other = nf_ct_expect_find_get(net, &inv_t); 127 exp_other = nf_ct_expect_find_get(net, nf_ct_zone(ct), &inv_t);
127 if (exp_other) { 128 if (exp_other) {
128 /* delete other expectation. */ 129 /* delete other expectation. */
129 pr_debug("found\n"); 130 pr_debug("found\n");
@@ -136,17 +137,18 @@ static void pptp_expectfn(struct nf_conn *ct,
136 rcu_read_unlock(); 137 rcu_read_unlock();
137} 138}
138 139
139static int destroy_sibling_or_exp(struct net *net, 140static int destroy_sibling_or_exp(struct net *net, struct nf_conn *ct,
140 const struct nf_conntrack_tuple *t) 141 const struct nf_conntrack_tuple *t)
141{ 142{
142 const struct nf_conntrack_tuple_hash *h; 143 const struct nf_conntrack_tuple_hash *h;
143 struct nf_conntrack_expect *exp; 144 struct nf_conntrack_expect *exp;
144 struct nf_conn *sibling; 145 struct nf_conn *sibling;
146 u16 zone = nf_ct_zone(ct);
145 147
146 pr_debug("trying to timeout ct or exp for tuple "); 148 pr_debug("trying to timeout ct or exp for tuple ");
147 nf_ct_dump_tuple(t); 149 nf_ct_dump_tuple(t);
148 150
149 h = nf_conntrack_find_get(net, t); 151 h = nf_conntrack_find_get(net, zone, t);
150 if (h) { 152 if (h) {
151 sibling = nf_ct_tuplehash_to_ctrack(h); 153 sibling = nf_ct_tuplehash_to_ctrack(h);
152 pr_debug("setting timeout of conntrack %p to 0\n", sibling); 154 pr_debug("setting timeout of conntrack %p to 0\n", sibling);
@@ -157,7 +159,7 @@ static int destroy_sibling_or_exp(struct net *net,
157 nf_ct_put(sibling); 159 nf_ct_put(sibling);
158 return 1; 160 return 1;
159 } else { 161 } else {
160 exp = nf_ct_expect_find_get(net, t); 162 exp = nf_ct_expect_find_get(net, zone, t);
161 if (exp) { 163 if (exp) {
162 pr_debug("unexpect_related of expect %p\n", exp); 164 pr_debug("unexpect_related of expect %p\n", exp);
163 nf_ct_unexpect_related(exp); 165 nf_ct_unexpect_related(exp);
@@ -182,7 +184,7 @@ static void pptp_destroy_siblings(struct nf_conn *ct)
182 t.dst.protonum = IPPROTO_GRE; 184 t.dst.protonum = IPPROTO_GRE;
183 t.src.u.gre.key = help->help.ct_pptp_info.pns_call_id; 185 t.src.u.gre.key = help->help.ct_pptp_info.pns_call_id;
184 t.dst.u.gre.key = help->help.ct_pptp_info.pac_call_id; 186 t.dst.u.gre.key = help->help.ct_pptp_info.pac_call_id;
185 if (!destroy_sibling_or_exp(net, &t)) 187 if (!destroy_sibling_or_exp(net, ct, &t))
186 pr_debug("failed to timeout original pns->pac ct/exp\n"); 188 pr_debug("failed to timeout original pns->pac ct/exp\n");
187 189
188 /* try reply (pac->pns) tuple */ 190 /* try reply (pac->pns) tuple */
@@ -190,7 +192,7 @@ static void pptp_destroy_siblings(struct nf_conn *ct)
190 t.dst.protonum = IPPROTO_GRE; 192 t.dst.protonum = IPPROTO_GRE;
191 t.src.u.gre.key = help->help.ct_pptp_info.pac_call_id; 193 t.src.u.gre.key = help->help.ct_pptp_info.pac_call_id;
192 t.dst.u.gre.key = help->help.ct_pptp_info.pns_call_id; 194 t.dst.u.gre.key = help->help.ct_pptp_info.pns_call_id;
193 if (!destroy_sibling_or_exp(net, &t)) 195 if (!destroy_sibling_or_exp(net, ct, &t))
194 pr_debug("failed to timeout reply pac->pns ct/exp\n"); 196 pr_debug("failed to timeout reply pac->pns ct/exp\n");
195} 197}
196 198
diff --git a/net/netfilter/nf_conntrack_proto.c b/net/netfilter/nf_conntrack_proto.c
index 1a4568bf7ea5..a44fa75b5178 100644
--- a/net/netfilter/nf_conntrack_proto.c
+++ b/net/netfilter/nf_conntrack_proto.c
@@ -12,6 +12,7 @@
12#include <linux/types.h> 12#include <linux/types.h>
13#include <linux/netfilter.h> 13#include <linux/netfilter.h>
14#include <linux/module.h> 14#include <linux/module.h>
15#include <linux/slab.h>
15#include <linux/mutex.h> 16#include <linux/mutex.h>
16#include <linux/skbuff.h> 17#include <linux/skbuff.h>
17#include <linux/vmalloc.h> 18#include <linux/vmalloc.h>
diff --git a/net/netfilter/nf_conntrack_proto_dccp.c b/net/netfilter/nf_conntrack_proto_dccp.c
index 1b816a2ea813..5292560d6d4a 100644
--- a/net/netfilter/nf_conntrack_proto_dccp.c
+++ b/net/netfilter/nf_conntrack_proto_dccp.c
@@ -15,6 +15,7 @@
15#include <linux/spinlock.h> 15#include <linux/spinlock.h>
16#include <linux/skbuff.h> 16#include <linux/skbuff.h>
17#include <linux/dccp.h> 17#include <linux/dccp.h>
18#include <linux/slab.h>
18 19
19#include <net/net_namespace.h> 20#include <net/net_namespace.h>
20#include <net/netns/generic.h> 21#include <net/netns/generic.h>
@@ -384,7 +385,7 @@ dccp_state_table[CT_DCCP_ROLE_MAX + 1][DCCP_PKT_SYNCACK + 1][CT_DCCP_MAX + 1] =
384}; 385};
385 386
386/* this module per-net specifics */ 387/* this module per-net specifics */
387static int dccp_net_id; 388static int dccp_net_id __read_mostly;
388struct dccp_net { 389struct dccp_net {
389 int dccp_loose; 390 int dccp_loose;
390 unsigned int dccp_timeout[CT_DCCP_MAX + 1]; 391 unsigned int dccp_timeout[CT_DCCP_MAX + 1];
@@ -561,8 +562,9 @@ static int dccp_packet(struct nf_conn *ct, const struct sk_buff *skb,
561 return NF_ACCEPT; 562 return NF_ACCEPT;
562} 563}
563 564
564static int dccp_error(struct net *net, struct sk_buff *skb, 565static int dccp_error(struct net *net, struct nf_conn *tmpl,
565 unsigned int dataoff, enum ip_conntrack_info *ctinfo, 566 struct sk_buff *skb, unsigned int dataoff,
567 enum ip_conntrack_info *ctinfo,
566 u_int8_t pf, unsigned int hooknum) 568 u_int8_t pf, unsigned int hooknum)
567{ 569{
568 struct dccp_hdr _dh, *dh; 570 struct dccp_hdr _dh, *dh;
@@ -703,64 +705,54 @@ static int dccp_nlattr_size(void)
703/* template, data assigned later */ 705/* template, data assigned later */
704static struct ctl_table dccp_sysctl_table[] = { 706static struct ctl_table dccp_sysctl_table[] = {
705 { 707 {
706 .ctl_name = CTL_UNNUMBERED,
707 .procname = "nf_conntrack_dccp_timeout_request", 708 .procname = "nf_conntrack_dccp_timeout_request",
708 .maxlen = sizeof(unsigned int), 709 .maxlen = sizeof(unsigned int),
709 .mode = 0644, 710 .mode = 0644,
710 .proc_handler = proc_dointvec_jiffies, 711 .proc_handler = proc_dointvec_jiffies,
711 }, 712 },
712 { 713 {
713 .ctl_name = CTL_UNNUMBERED,
714 .procname = "nf_conntrack_dccp_timeout_respond", 714 .procname = "nf_conntrack_dccp_timeout_respond",
715 .maxlen = sizeof(unsigned int), 715 .maxlen = sizeof(unsigned int),
716 .mode = 0644, 716 .mode = 0644,
717 .proc_handler = proc_dointvec_jiffies, 717 .proc_handler = proc_dointvec_jiffies,
718 }, 718 },
719 { 719 {
720 .ctl_name = CTL_UNNUMBERED,
721 .procname = "nf_conntrack_dccp_timeout_partopen", 720 .procname = "nf_conntrack_dccp_timeout_partopen",
722 .maxlen = sizeof(unsigned int), 721 .maxlen = sizeof(unsigned int),
723 .mode = 0644, 722 .mode = 0644,
724 .proc_handler = proc_dointvec_jiffies, 723 .proc_handler = proc_dointvec_jiffies,
725 }, 724 },
726 { 725 {
727 .ctl_name = CTL_UNNUMBERED,
728 .procname = "nf_conntrack_dccp_timeout_open", 726 .procname = "nf_conntrack_dccp_timeout_open",
729 .maxlen = sizeof(unsigned int), 727 .maxlen = sizeof(unsigned int),
730 .mode = 0644, 728 .mode = 0644,
731 .proc_handler = proc_dointvec_jiffies, 729 .proc_handler = proc_dointvec_jiffies,
732 }, 730 },
733 { 731 {
734 .ctl_name = CTL_UNNUMBERED,
735 .procname = "nf_conntrack_dccp_timeout_closereq", 732 .procname = "nf_conntrack_dccp_timeout_closereq",
736 .maxlen = sizeof(unsigned int), 733 .maxlen = sizeof(unsigned int),
737 .mode = 0644, 734 .mode = 0644,
738 .proc_handler = proc_dointvec_jiffies, 735 .proc_handler = proc_dointvec_jiffies,
739 }, 736 },
740 { 737 {
741 .ctl_name = CTL_UNNUMBERED,
742 .procname = "nf_conntrack_dccp_timeout_closing", 738 .procname = "nf_conntrack_dccp_timeout_closing",
743 .maxlen = sizeof(unsigned int), 739 .maxlen = sizeof(unsigned int),
744 .mode = 0644, 740 .mode = 0644,
745 .proc_handler = proc_dointvec_jiffies, 741 .proc_handler = proc_dointvec_jiffies,
746 }, 742 },
747 { 743 {
748 .ctl_name = CTL_UNNUMBERED,
749 .procname = "nf_conntrack_dccp_timeout_timewait", 744 .procname = "nf_conntrack_dccp_timeout_timewait",
750 .maxlen = sizeof(unsigned int), 745 .maxlen = sizeof(unsigned int),
751 .mode = 0644, 746 .mode = 0644,
752 .proc_handler = proc_dointvec_jiffies, 747 .proc_handler = proc_dointvec_jiffies,
753 }, 748 },
754 { 749 {
755 .ctl_name = CTL_UNNUMBERED,
756 .procname = "nf_conntrack_dccp_loose", 750 .procname = "nf_conntrack_dccp_loose",
757 .maxlen = sizeof(int), 751 .maxlen = sizeof(int),
758 .mode = 0644, 752 .mode = 0644,
759 .proc_handler = proc_dointvec, 753 .proc_handler = proc_dointvec,
760 }, 754 },
761 { 755 { }
762 .ctl_name = 0,
763 }
764}; 756};
765#endif /* CONFIG_SYSCTL */ 757#endif /* CONFIG_SYSCTL */
766 758
@@ -810,12 +802,7 @@ static struct nf_conntrack_l4proto dccp_proto6 __read_mostly = {
810 802
811static __net_init int dccp_net_init(struct net *net) 803static __net_init int dccp_net_init(struct net *net)
812{ 804{
813 struct dccp_net *dn; 805 struct dccp_net *dn = dccp_pernet(net);
814 int err;
815
816 dn = kmalloc(sizeof(*dn), GFP_KERNEL);
817 if (!dn)
818 return -ENOMEM;
819 806
820 /* default values */ 807 /* default values */
821 dn->dccp_loose = 1; 808 dn->dccp_loose = 1;
@@ -827,16 +814,11 @@ static __net_init int dccp_net_init(struct net *net)
827 dn->dccp_timeout[CT_DCCP_CLOSING] = 64 * HZ; 814 dn->dccp_timeout[CT_DCCP_CLOSING] = 64 * HZ;
828 dn->dccp_timeout[CT_DCCP_TIMEWAIT] = 2 * DCCP_MSL; 815 dn->dccp_timeout[CT_DCCP_TIMEWAIT] = 2 * DCCP_MSL;
829 816
830 err = net_assign_generic(net, dccp_net_id, dn);
831 if (err)
832 goto out;
833
834#ifdef CONFIG_SYSCTL 817#ifdef CONFIG_SYSCTL
835 err = -ENOMEM;
836 dn->sysctl_table = kmemdup(dccp_sysctl_table, 818 dn->sysctl_table = kmemdup(dccp_sysctl_table,
837 sizeof(dccp_sysctl_table), GFP_KERNEL); 819 sizeof(dccp_sysctl_table), GFP_KERNEL);
838 if (!dn->sysctl_table) 820 if (!dn->sysctl_table)
839 goto out; 821 return -ENOMEM;
840 822
841 dn->sysctl_table[0].data = &dn->dccp_timeout[CT_DCCP_REQUEST]; 823 dn->sysctl_table[0].data = &dn->dccp_timeout[CT_DCCP_REQUEST];
842 dn->sysctl_table[1].data = &dn->dccp_timeout[CT_DCCP_RESPOND]; 824 dn->sysctl_table[1].data = &dn->dccp_timeout[CT_DCCP_RESPOND];
@@ -851,15 +833,11 @@ static __net_init int dccp_net_init(struct net *net)
851 nf_net_netfilter_sysctl_path, dn->sysctl_table); 833 nf_net_netfilter_sysctl_path, dn->sysctl_table);
852 if (!dn->sysctl_header) { 834 if (!dn->sysctl_header) {
853 kfree(dn->sysctl_table); 835 kfree(dn->sysctl_table);
854 goto out; 836 return -ENOMEM;
855 } 837 }
856#endif 838#endif
857 839
858 return 0; 840 return 0;
859
860out:
861 kfree(dn);
862 return err;
863} 841}
864 842
865static __net_exit void dccp_net_exit(struct net *net) 843static __net_exit void dccp_net_exit(struct net *net)
@@ -869,21 +847,20 @@ static __net_exit void dccp_net_exit(struct net *net)
869 unregister_net_sysctl_table(dn->sysctl_header); 847 unregister_net_sysctl_table(dn->sysctl_header);
870 kfree(dn->sysctl_table); 848 kfree(dn->sysctl_table);
871#endif 849#endif
872 kfree(dn);
873
874 net_assign_generic(net, dccp_net_id, NULL);
875} 850}
876 851
877static struct pernet_operations dccp_net_ops = { 852static struct pernet_operations dccp_net_ops = {
878 .init = dccp_net_init, 853 .init = dccp_net_init,
879 .exit = dccp_net_exit, 854 .exit = dccp_net_exit,
855 .id = &dccp_net_id,
856 .size = sizeof(struct dccp_net),
880}; 857};
881 858
882static int __init nf_conntrack_proto_dccp_init(void) 859static int __init nf_conntrack_proto_dccp_init(void)
883{ 860{
884 int err; 861 int err;
885 862
886 err = register_pernet_gen_subsys(&dccp_net_id, &dccp_net_ops); 863 err = register_pernet_subsys(&dccp_net_ops);
887 if (err < 0) 864 if (err < 0)
888 goto err1; 865 goto err1;
889 866
@@ -899,14 +876,14 @@ static int __init nf_conntrack_proto_dccp_init(void)
899err3: 876err3:
900 nf_conntrack_l4proto_unregister(&dccp_proto4); 877 nf_conntrack_l4proto_unregister(&dccp_proto4);
901err2: 878err2:
902 unregister_pernet_gen_subsys(dccp_net_id, &dccp_net_ops); 879 unregister_pernet_subsys(&dccp_net_ops);
903err1: 880err1:
904 return err; 881 return err;
905} 882}
906 883
907static void __exit nf_conntrack_proto_dccp_fini(void) 884static void __exit nf_conntrack_proto_dccp_fini(void)
908{ 885{
909 unregister_pernet_gen_subsys(dccp_net_id, &dccp_net_ops); 886 unregister_pernet_subsys(&dccp_net_ops);
910 nf_conntrack_l4proto_unregister(&dccp_proto6); 887 nf_conntrack_l4proto_unregister(&dccp_proto6);
911 nf_conntrack_l4proto_unregister(&dccp_proto4); 888 nf_conntrack_l4proto_unregister(&dccp_proto4);
912} 889}
diff --git a/net/netfilter/nf_conntrack_proto_generic.c b/net/netfilter/nf_conntrack_proto_generic.c
index 829374f426c4..e2091d0c7a2f 100644
--- a/net/netfilter/nf_conntrack_proto_generic.c
+++ b/net/netfilter/nf_conntrack_proto_generic.c
@@ -69,9 +69,7 @@ static struct ctl_table generic_sysctl_table[] = {
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
74 }
75}; 73};
76#ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT 74#ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
77static struct ctl_table generic_compat_sysctl_table[] = { 75static struct ctl_table generic_compat_sysctl_table[] = {
@@ -82,9 +80,7 @@ static struct ctl_table generic_compat_sysctl_table[] = {
82 .mode = 0644, 80 .mode = 0644,
83 .proc_handler = proc_dointvec_jiffies, 81 .proc_handler = proc_dointvec_jiffies,
84 }, 82 },
85 { 83 { }
86 .ctl_name = 0
87 }
88}; 84};
89#endif /* CONFIG_NF_CONNTRACK_PROC_COMPAT */ 85#endif /* CONFIG_NF_CONNTRACK_PROC_COMPAT */
90#endif /* CONFIG_SYSCTL */ 86#endif /* CONFIG_SYSCTL */
diff --git a/net/netfilter/nf_conntrack_proto_gre.c b/net/netfilter/nf_conntrack_proto_gre.c
index a54a0af0edba..cf616e55ca41 100644
--- a/net/netfilter/nf_conntrack_proto_gre.c
+++ b/net/netfilter/nf_conntrack_proto_gre.c
@@ -31,6 +31,7 @@
31#include <linux/in.h> 31#include <linux/in.h>
32#include <linux/netdevice.h> 32#include <linux/netdevice.h>
33#include <linux/skbuff.h> 33#include <linux/skbuff.h>
34#include <linux/slab.h>
34#include <net/dst.h> 35#include <net/dst.h>
35#include <net/net_namespace.h> 36#include <net/net_namespace.h>
36#include <net/netns/generic.h> 37#include <net/netns/generic.h>
@@ -43,7 +44,7 @@
43#define GRE_TIMEOUT (30 * HZ) 44#define GRE_TIMEOUT (30 * HZ)
44#define GRE_STREAM_TIMEOUT (180 * HZ) 45#define GRE_STREAM_TIMEOUT (180 * HZ)
45 46
46static int proto_gre_net_id; 47static int proto_gre_net_id __read_mostly;
47struct netns_proto_gre { 48struct netns_proto_gre {
48 rwlock_t keymap_lock; 49 rwlock_t keymap_lock;
49 struct list_head keymap_list; 50 struct list_head keymap_list;
@@ -241,7 +242,7 @@ static int gre_packet(struct nf_conn *ct,
241 ct->proto.gre.stream_timeout); 242 ct->proto.gre.stream_timeout);
242 /* Also, more likely to be important, and not a probe. */ 243 /* Also, more likely to be important, and not a probe. */
243 set_bit(IPS_ASSURED_BIT, &ct->status); 244 set_bit(IPS_ASSURED_BIT, &ct->status);
244 nf_conntrack_event_cache(IPCT_STATUS, ct); 245 nf_conntrack_event_cache(IPCT_ASSURED, ct);
245 } else 246 } else
246 nf_ct_refresh_acct(ct, ctinfo, skb, 247 nf_ct_refresh_acct(ct, ctinfo, skb,
247 ct->proto.gre.timeout); 248 ct->proto.gre.timeout);
@@ -300,32 +301,24 @@ static struct nf_conntrack_l4proto nf_conntrack_l4proto_gre4 __read_mostly = {
300 301
301static int proto_gre_net_init(struct net *net) 302static int proto_gre_net_init(struct net *net)
302{ 303{
303 struct netns_proto_gre *net_gre; 304 struct netns_proto_gre *net_gre = net_generic(net, proto_gre_net_id);
304 int rv;
305 305
306 net_gre = kmalloc(sizeof(struct netns_proto_gre), GFP_KERNEL);
307 if (!net_gre)
308 return -ENOMEM;
309 rwlock_init(&net_gre->keymap_lock); 306 rwlock_init(&net_gre->keymap_lock);
310 INIT_LIST_HEAD(&net_gre->keymap_list); 307 INIT_LIST_HEAD(&net_gre->keymap_list);
311 308
312 rv = net_assign_generic(net, proto_gre_net_id, net_gre); 309 return 0;
313 if (rv < 0)
314 kfree(net_gre);
315 return rv;
316} 310}
317 311
318static void proto_gre_net_exit(struct net *net) 312static void proto_gre_net_exit(struct net *net)
319{ 313{
320 struct netns_proto_gre *net_gre = net_generic(net, proto_gre_net_id);
321
322 nf_ct_gre_keymap_flush(net); 314 nf_ct_gre_keymap_flush(net);
323 kfree(net_gre);
324} 315}
325 316
326static struct pernet_operations proto_gre_net_ops = { 317static struct pernet_operations proto_gre_net_ops = {
327 .init = proto_gre_net_init, 318 .init = proto_gre_net_init,
328 .exit = proto_gre_net_exit, 319 .exit = proto_gre_net_exit,
320 .id = &proto_gre_net_id,
321 .size = sizeof(struct netns_proto_gre),
329}; 322};
330 323
331static int __init nf_ct_proto_gre_init(void) 324static int __init nf_ct_proto_gre_init(void)
@@ -335,7 +328,7 @@ static int __init nf_ct_proto_gre_init(void)
335 rv = nf_conntrack_l4proto_register(&nf_conntrack_l4proto_gre4); 328 rv = nf_conntrack_l4proto_register(&nf_conntrack_l4proto_gre4);
336 if (rv < 0) 329 if (rv < 0)
337 return rv; 330 return rv;
338 rv = register_pernet_gen_subsys(&proto_gre_net_id, &proto_gre_net_ops); 331 rv = register_pernet_subsys(&proto_gre_net_ops);
339 if (rv < 0) 332 if (rv < 0)
340 nf_conntrack_l4proto_unregister(&nf_conntrack_l4proto_gre4); 333 nf_conntrack_l4proto_unregister(&nf_conntrack_l4proto_gre4);
341 return rv; 334 return rv;
@@ -344,7 +337,7 @@ static int __init nf_ct_proto_gre_init(void)
344static void __exit nf_ct_proto_gre_fini(void) 337static void __exit nf_ct_proto_gre_fini(void)
345{ 338{
346 nf_conntrack_l4proto_unregister(&nf_conntrack_l4proto_gre4); 339 nf_conntrack_l4proto_unregister(&nf_conntrack_l4proto_gre4);
347 unregister_pernet_gen_subsys(proto_gre_net_id, &proto_gre_net_ops); 340 unregister_pernet_subsys(&proto_gre_net_ops);
348} 341}
349 342
350module_init(nf_ct_proto_gre_init); 343module_init(nf_ct_proto_gre_init);
diff --git a/net/netfilter/nf_conntrack_proto_sctp.c b/net/netfilter/nf_conntrack_proto_sctp.c
index c10e6f36e31e..b68ff15ed979 100644
--- a/net/netfilter/nf_conntrack_proto_sctp.c
+++ b/net/netfilter/nf_conntrack_proto_sctp.c
@@ -377,7 +377,7 @@ static int sctp_packet(struct nf_conn *ct,
377 new_state == SCTP_CONNTRACK_ESTABLISHED) { 377 new_state == SCTP_CONNTRACK_ESTABLISHED) {
378 pr_debug("Setting assured bit\n"); 378 pr_debug("Setting assured bit\n");
379 set_bit(IPS_ASSURED_BIT, &ct->status); 379 set_bit(IPS_ASSURED_BIT, &ct->status);
380 nf_conntrack_event_cache(IPCT_STATUS, ct); 380 nf_conntrack_event_cache(IPCT_ASSURED, ct);
381 } 381 }
382 382
383 return NF_ACCEPT; 383 return NF_ACCEPT;
@@ -595,9 +595,7 @@ static struct ctl_table sctp_sysctl_table[] = {
595 .mode = 0644, 595 .mode = 0644,
596 .proc_handler = proc_dointvec_jiffies, 596 .proc_handler = proc_dointvec_jiffies,
597 }, 597 },
598 { 598 { }
599 .ctl_name = 0
600 }
601}; 599};
602 600
603#ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT 601#ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
@@ -651,9 +649,7 @@ static struct ctl_table sctp_compat_sysctl_table[] = {
651 .mode = 0644, 649 .mode = 0644,
652 .proc_handler = proc_dointvec_jiffies, 650 .proc_handler = proc_dointvec_jiffies,
653 }, 651 },
654 { 652 { }
655 .ctl_name = 0
656 }
657}; 653};
658#endif /* CONFIG_NF_CONNTRACK_PROC_COMPAT */ 654#endif /* CONFIG_NF_CONNTRACK_PROC_COMPAT */
659#endif 655#endif
diff --git a/net/netfilter/nf_conntrack_proto_tcp.c b/net/netfilter/nf_conntrack_proto_tcp.c
index ba2b76937283..9dd8cd4fb6e6 100644
--- a/net/netfilter/nf_conntrack_proto_tcp.c
+++ b/net/netfilter/nf_conntrack_proto_tcp.c
@@ -760,7 +760,7 @@ static const u8 tcp_valid_flags[(TH_FIN|TH_SYN|TH_RST|TH_ACK|TH_URG) + 1] =
760}; 760};
761 761
762/* Protect conntrack agaist broken packets. Code taken from ipt_unclean.c. */ 762/* Protect conntrack agaist broken packets. Code taken from ipt_unclean.c. */
763static int tcp_error(struct net *net, 763static int tcp_error(struct net *net, struct nf_conn *tmpl,
764 struct sk_buff *skb, 764 struct sk_buff *skb,
765 unsigned int dataoff, 765 unsigned int dataoff,
766 enum ip_conntrack_info *ctinfo, 766 enum ip_conntrack_info *ctinfo,
@@ -896,23 +896,54 @@ static int tcp_packet(struct nf_conn *ct,
896 /* b) This SYN/ACK acknowledges a SYN that we earlier 896 /* b) This SYN/ACK acknowledges a SYN that we earlier
897 * ignored as invalid. This means that the client and 897 * ignored as invalid. This means that the client and
898 * the server are both in sync, while the firewall is 898 * the server are both in sync, while the firewall is
899 * not. We kill this session and block the SYN/ACK so 899 * not. We get in sync from the previously annotated
900 * that the client cannot but retransmit its SYN and 900 * values.
901 * thus initiate a clean new session.
902 */ 901 */
903 spin_unlock_bh(&ct->lock); 902 old_state = TCP_CONNTRACK_SYN_SENT;
904 if (LOG_INVALID(net, IPPROTO_TCP)) 903 new_state = TCP_CONNTRACK_SYN_RECV;
905 nf_log_packet(pf, 0, skb, NULL, NULL, NULL, 904 ct->proto.tcp.seen[ct->proto.tcp.last_dir].td_end =
906 "nf_ct_tcp: killing out of sync session "); 905 ct->proto.tcp.last_end;
907 nf_ct_kill(ct); 906 ct->proto.tcp.seen[ct->proto.tcp.last_dir].td_maxend =
908 return NF_DROP; 907 ct->proto.tcp.last_end;
908 ct->proto.tcp.seen[ct->proto.tcp.last_dir].td_maxwin =
909 ct->proto.tcp.last_win == 0 ?
910 1 : ct->proto.tcp.last_win;
911 ct->proto.tcp.seen[ct->proto.tcp.last_dir].td_scale =
912 ct->proto.tcp.last_wscale;
913 ct->proto.tcp.seen[ct->proto.tcp.last_dir].flags =
914 ct->proto.tcp.last_flags;
915 memset(&ct->proto.tcp.seen[dir], 0,
916 sizeof(struct ip_ct_tcp_state));
917 break;
909 } 918 }
910 ct->proto.tcp.last_index = index; 919 ct->proto.tcp.last_index = index;
911 ct->proto.tcp.last_dir = dir; 920 ct->proto.tcp.last_dir = dir;
912 ct->proto.tcp.last_seq = ntohl(th->seq); 921 ct->proto.tcp.last_seq = ntohl(th->seq);
913 ct->proto.tcp.last_end = 922 ct->proto.tcp.last_end =
914 segment_seq_plus_len(ntohl(th->seq), skb->len, dataoff, th); 923 segment_seq_plus_len(ntohl(th->seq), skb->len, dataoff, th);
915 924 ct->proto.tcp.last_win = ntohs(th->window);
925
926 /* a) This is a SYN in ORIGINAL. The client and the server
927 * may be in sync but we are not. In that case, we annotate
928 * the TCP options and let the packet go through. If it is a
929 * valid SYN packet, the server will reply with a SYN/ACK, and
930 * then we'll get in sync. Otherwise, the server ignores it. */
931 if (index == TCP_SYN_SET && dir == IP_CT_DIR_ORIGINAL) {
932 struct ip_ct_tcp_state seen = {};
933
934 ct->proto.tcp.last_flags =
935 ct->proto.tcp.last_wscale = 0;
936 tcp_options(skb, dataoff, th, &seen);
937 if (seen.flags & IP_CT_TCP_FLAG_WINDOW_SCALE) {
938 ct->proto.tcp.last_flags |=
939 IP_CT_TCP_FLAG_WINDOW_SCALE;
940 ct->proto.tcp.last_wscale = seen.td_scale;
941 }
942 if (seen.flags & IP_CT_TCP_FLAG_SACK_PERM) {
943 ct->proto.tcp.last_flags |=
944 IP_CT_TCP_FLAG_SACK_PERM;
945 }
946 }
916 spin_unlock_bh(&ct->lock); 947 spin_unlock_bh(&ct->lock);
917 if (LOG_INVALID(net, IPPROTO_TCP)) 948 if (LOG_INVALID(net, IPPROTO_TCP))
918 nf_log_packet(pf, 0, skb, NULL, NULL, NULL, 949 nf_log_packet(pf, 0, skb, NULL, NULL, NULL,
@@ -1014,7 +1045,7 @@ static int tcp_packet(struct nf_conn *ct,
1014 after SYN_RECV or a valid answer for a picked up 1045 after SYN_RECV or a valid answer for a picked up
1015 connection. */ 1046 connection. */
1016 set_bit(IPS_ASSURED_BIT, &ct->status); 1047 set_bit(IPS_ASSURED_BIT, &ct->status);
1017 nf_conntrack_event_cache(IPCT_STATUS, ct); 1048 nf_conntrack_event_cache(IPCT_ASSURED, ct);
1018 } 1049 }
1019 nf_ct_refresh_acct(ct, ctinfo, skb, timeout); 1050 nf_ct_refresh_acct(ct, ctinfo, skb, timeout);
1020 1051
@@ -1291,7 +1322,6 @@ static struct ctl_table tcp_sysctl_table[] = {
1291 .proc_handler = proc_dointvec_jiffies, 1322 .proc_handler = proc_dointvec_jiffies,
1292 }, 1323 },
1293 { 1324 {
1294 .ctl_name = NET_NF_CONNTRACK_TCP_LOOSE,
1295 .procname = "nf_conntrack_tcp_loose", 1325 .procname = "nf_conntrack_tcp_loose",
1296 .data = &nf_ct_tcp_loose, 1326 .data = &nf_ct_tcp_loose,
1297 .maxlen = sizeof(unsigned int), 1327 .maxlen = sizeof(unsigned int),
@@ -1299,7 +1329,6 @@ static struct ctl_table tcp_sysctl_table[] = {
1299 .proc_handler = proc_dointvec, 1329 .proc_handler = proc_dointvec,
1300 }, 1330 },
1301 { 1331 {
1302 .ctl_name = NET_NF_CONNTRACK_TCP_BE_LIBERAL,
1303 .procname = "nf_conntrack_tcp_be_liberal", 1332 .procname = "nf_conntrack_tcp_be_liberal",
1304 .data = &nf_ct_tcp_be_liberal, 1333 .data = &nf_ct_tcp_be_liberal,
1305 .maxlen = sizeof(unsigned int), 1334 .maxlen = sizeof(unsigned int),
@@ -1307,16 +1336,13 @@ static struct ctl_table tcp_sysctl_table[] = {
1307 .proc_handler = proc_dointvec, 1336 .proc_handler = proc_dointvec,
1308 }, 1337 },
1309 { 1338 {
1310 .ctl_name = NET_NF_CONNTRACK_TCP_MAX_RETRANS,
1311 .procname = "nf_conntrack_tcp_max_retrans", 1339 .procname = "nf_conntrack_tcp_max_retrans",
1312 .data = &nf_ct_tcp_max_retrans, 1340 .data = &nf_ct_tcp_max_retrans,
1313 .maxlen = sizeof(unsigned int), 1341 .maxlen = sizeof(unsigned int),
1314 .mode = 0644, 1342 .mode = 0644,
1315 .proc_handler = proc_dointvec, 1343 .proc_handler = proc_dointvec,
1316 }, 1344 },
1317 { 1345 { }
1318 .ctl_name = 0
1319 }
1320}; 1346};
1321 1347
1322#ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT 1348#ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
@@ -1392,7 +1418,6 @@ static struct ctl_table tcp_compat_sysctl_table[] = {
1392 .proc_handler = proc_dointvec_jiffies, 1418 .proc_handler = proc_dointvec_jiffies,
1393 }, 1419 },
1394 { 1420 {
1395 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_LOOSE,
1396 .procname = "ip_conntrack_tcp_loose", 1421 .procname = "ip_conntrack_tcp_loose",
1397 .data = &nf_ct_tcp_loose, 1422 .data = &nf_ct_tcp_loose,
1398 .maxlen = sizeof(unsigned int), 1423 .maxlen = sizeof(unsigned int),
@@ -1400,7 +1425,6 @@ static struct ctl_table tcp_compat_sysctl_table[] = {
1400 .proc_handler = proc_dointvec, 1425 .proc_handler = proc_dointvec,
1401 }, 1426 },
1402 { 1427 {
1403 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_BE_LIBERAL,
1404 .procname = "ip_conntrack_tcp_be_liberal", 1428 .procname = "ip_conntrack_tcp_be_liberal",
1405 .data = &nf_ct_tcp_be_liberal, 1429 .data = &nf_ct_tcp_be_liberal,
1406 .maxlen = sizeof(unsigned int), 1430 .maxlen = sizeof(unsigned int),
@@ -1408,16 +1432,13 @@ static struct ctl_table tcp_compat_sysctl_table[] = {
1408 .proc_handler = proc_dointvec, 1432 .proc_handler = proc_dointvec,
1409 }, 1433 },
1410 { 1434 {
1411 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_MAX_RETRANS,
1412 .procname = "ip_conntrack_tcp_max_retrans", 1435 .procname = "ip_conntrack_tcp_max_retrans",
1413 .data = &nf_ct_tcp_max_retrans, 1436 .data = &nf_ct_tcp_max_retrans,
1414 .maxlen = sizeof(unsigned int), 1437 .maxlen = sizeof(unsigned int),
1415 .mode = 0644, 1438 .mode = 0644,
1416 .proc_handler = proc_dointvec, 1439 .proc_handler = proc_dointvec,
1417 }, 1440 },
1418 { 1441 { }
1419 .ctl_name = 0
1420 }
1421}; 1442};
1422#endif /* CONFIG_NF_CONNTRACK_PROC_COMPAT */ 1443#endif /* CONFIG_NF_CONNTRACK_PROC_COMPAT */
1423#endif /* CONFIG_SYSCTL */ 1444#endif /* CONFIG_SYSCTL */
diff --git a/net/netfilter/nf_conntrack_proto_udp.c b/net/netfilter/nf_conntrack_proto_udp.c
index 70809d117b91..8289088b8218 100644
--- a/net/netfilter/nf_conntrack_proto_udp.c
+++ b/net/netfilter/nf_conntrack_proto_udp.c
@@ -77,7 +77,7 @@ static int udp_packet(struct nf_conn *ct,
77 nf_ct_refresh_acct(ct, ctinfo, skb, nf_ct_udp_timeout_stream); 77 nf_ct_refresh_acct(ct, ctinfo, skb, nf_ct_udp_timeout_stream);
78 /* Also, more likely to be important, and not a probe */ 78 /* Also, more likely to be important, and not a probe */
79 if (!test_and_set_bit(IPS_ASSURED_BIT, &ct->status)) 79 if (!test_and_set_bit(IPS_ASSURED_BIT, &ct->status))
80 nf_conntrack_event_cache(IPCT_STATUS, ct); 80 nf_conntrack_event_cache(IPCT_ASSURED, ct);
81 } else 81 } else
82 nf_ct_refresh_acct(ct, ctinfo, skb, nf_ct_udp_timeout); 82 nf_ct_refresh_acct(ct, ctinfo, skb, nf_ct_udp_timeout);
83 83
@@ -91,8 +91,8 @@ static bool udp_new(struct nf_conn *ct, const struct sk_buff *skb,
91 return true; 91 return true;
92} 92}
93 93
94static int udp_error(struct net *net, struct sk_buff *skb, unsigned int dataoff, 94static int udp_error(struct net *net, struct nf_conn *tmpl, struct sk_buff *skb,
95 enum ip_conntrack_info *ctinfo, 95 unsigned int dataoff, enum ip_conntrack_info *ctinfo,
96 u_int8_t pf, 96 u_int8_t pf,
97 unsigned int hooknum) 97 unsigned int hooknum)
98{ 98{
@@ -154,9 +154,7 @@ static struct ctl_table udp_sysctl_table[] = {
154 .mode = 0644, 154 .mode = 0644,
155 .proc_handler = proc_dointvec_jiffies, 155 .proc_handler = proc_dointvec_jiffies,
156 }, 156 },
157 { 157 { }
158 .ctl_name = 0
159 }
160}; 158};
161#ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT 159#ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
162static struct ctl_table udp_compat_sysctl_table[] = { 160static struct ctl_table udp_compat_sysctl_table[] = {
@@ -174,9 +172,7 @@ static struct ctl_table udp_compat_sysctl_table[] = {
174 .mode = 0644, 172 .mode = 0644,
175 .proc_handler = proc_dointvec_jiffies, 173 .proc_handler = proc_dointvec_jiffies,
176 }, 174 },
177 { 175 { }
178 .ctl_name = 0
179 }
180}; 176};
181#endif /* CONFIG_NF_CONNTRACK_PROC_COMPAT */ 177#endif /* CONFIG_NF_CONNTRACK_PROC_COMPAT */
182#endif /* CONFIG_SYSCTL */ 178#endif /* CONFIG_SYSCTL */
diff --git a/net/netfilter/nf_conntrack_proto_udplite.c b/net/netfilter/nf_conntrack_proto_udplite.c
index 0badedc542d3..263b5a72588d 100644
--- a/net/netfilter/nf_conntrack_proto_udplite.c
+++ b/net/netfilter/nf_conntrack_proto_udplite.c
@@ -75,7 +75,7 @@ static int udplite_packet(struct nf_conn *ct,
75 nf_ct_udplite_timeout_stream); 75 nf_ct_udplite_timeout_stream);
76 /* Also, more likely to be important, and not a probe */ 76 /* Also, more likely to be important, and not a probe */
77 if (!test_and_set_bit(IPS_ASSURED_BIT, &ct->status)) 77 if (!test_and_set_bit(IPS_ASSURED_BIT, &ct->status))
78 nf_conntrack_event_cache(IPCT_STATUS, ct); 78 nf_conntrack_event_cache(IPCT_ASSURED, ct);
79 } else 79 } else
80 nf_ct_refresh_acct(ct, ctinfo, skb, nf_ct_udplite_timeout); 80 nf_ct_refresh_acct(ct, ctinfo, skb, nf_ct_udplite_timeout);
81 81
@@ -89,7 +89,7 @@ static bool udplite_new(struct nf_conn *ct, const struct sk_buff *skb,
89 return true; 89 return true;
90} 90}
91 91
92static int udplite_error(struct net *net, 92static int udplite_error(struct net *net, struct nf_conn *tmpl,
93 struct sk_buff *skb, 93 struct sk_buff *skb,
94 unsigned int dataoff, 94 unsigned int dataoff,
95 enum ip_conntrack_info *ctinfo, 95 enum ip_conntrack_info *ctinfo,
@@ -146,7 +146,6 @@ static unsigned int udplite_sysctl_table_users;
146static struct ctl_table_header *udplite_sysctl_header; 146static struct ctl_table_header *udplite_sysctl_header;
147static struct ctl_table udplite_sysctl_table[] = { 147static struct ctl_table udplite_sysctl_table[] = {
148 { 148 {
149 .ctl_name = CTL_UNNUMBERED,
150 .procname = "nf_conntrack_udplite_timeout", 149 .procname = "nf_conntrack_udplite_timeout",
151 .data = &nf_ct_udplite_timeout, 150 .data = &nf_ct_udplite_timeout,
152 .maxlen = sizeof(unsigned int), 151 .maxlen = sizeof(unsigned int),
@@ -154,16 +153,13 @@ static struct ctl_table udplite_sysctl_table[] = {
154 .proc_handler = proc_dointvec_jiffies, 153 .proc_handler = proc_dointvec_jiffies,
155 }, 154 },
156 { 155 {
157 .ctl_name = CTL_UNNUMBERED,
158 .procname = "nf_conntrack_udplite_timeout_stream", 156 .procname = "nf_conntrack_udplite_timeout_stream",
159 .data = &nf_ct_udplite_timeout_stream, 157 .data = &nf_ct_udplite_timeout_stream,
160 .maxlen = sizeof(unsigned int), 158 .maxlen = sizeof(unsigned int),
161 .mode = 0644, 159 .mode = 0644,
162 .proc_handler = proc_dointvec_jiffies, 160 .proc_handler = proc_dointvec_jiffies,
163 }, 161 },
164 { 162 { }
165 .ctl_name = 0
166 }
167}; 163};
168#endif /* CONFIG_SYSCTL */ 164#endif /* CONFIG_SYSCTL */
169 165
diff --git a/net/netfilter/nf_conntrack_sane.c b/net/netfilter/nf_conntrack_sane.c
index dcfecbb81c46..d9e27734b2a2 100644
--- a/net/netfilter/nf_conntrack_sane.c
+++ b/net/netfilter/nf_conntrack_sane.c
@@ -20,6 +20,7 @@
20#include <linux/module.h> 20#include <linux/module.h>
21#include <linux/moduleparam.h> 21#include <linux/moduleparam.h>
22#include <linux/netfilter.h> 22#include <linux/netfilter.h>
23#include <linux/slab.h>
23#include <linux/in.h> 24#include <linux/in.h>
24#include <linux/tcp.h> 25#include <linux/tcp.h>
25#include <net/netfilter/nf_conntrack.h> 26#include <net/netfilter/nf_conntrack.h>
diff --git a/net/netfilter/nf_conntrack_sip.c b/net/netfilter/nf_conntrack_sip.c
index 4b572163784b..c6cd1b84eddd 100644
--- a/net/netfilter/nf_conntrack_sip.c
+++ b/net/netfilter/nf_conntrack_sip.c
@@ -16,12 +16,14 @@
16#include <linux/inet.h> 16#include <linux/inet.h>
17#include <linux/in.h> 17#include <linux/in.h>
18#include <linux/udp.h> 18#include <linux/udp.h>
19#include <linux/tcp.h>
19#include <linux/netfilter.h> 20#include <linux/netfilter.h>
20 21
21#include <net/netfilter/nf_conntrack.h> 22#include <net/netfilter/nf_conntrack.h>
22#include <net/netfilter/nf_conntrack_core.h> 23#include <net/netfilter/nf_conntrack_core.h>
23#include <net/netfilter/nf_conntrack_expect.h> 24#include <net/netfilter/nf_conntrack_expect.h>
24#include <net/netfilter/nf_conntrack_helper.h> 25#include <net/netfilter/nf_conntrack_helper.h>
26#include <net/netfilter/nf_conntrack_zones.h>
25#include <linux/netfilter/nf_conntrack_sip.h> 27#include <linux/netfilter/nf_conntrack_sip.h>
26 28
27MODULE_LICENSE("GPL"); 29MODULE_LICENSE("GPL");
@@ -50,12 +52,16 @@ module_param(sip_direct_media, int, 0600);
50MODULE_PARM_DESC(sip_direct_media, "Expect Media streams between signalling " 52MODULE_PARM_DESC(sip_direct_media, "Expect Media streams between signalling "
51 "endpoints only (default 1)"); 53 "endpoints only (default 1)");
52 54
53unsigned int (*nf_nat_sip_hook)(struct sk_buff *skb, 55unsigned int (*nf_nat_sip_hook)(struct sk_buff *skb, unsigned int dataoff,
54 const char **dptr, 56 const char **dptr,
55 unsigned int *datalen) __read_mostly; 57 unsigned int *datalen) __read_mostly;
56EXPORT_SYMBOL_GPL(nf_nat_sip_hook); 58EXPORT_SYMBOL_GPL(nf_nat_sip_hook);
57 59
60void (*nf_nat_sip_seq_adjust_hook)(struct sk_buff *skb, s16 off) __read_mostly;
61EXPORT_SYMBOL_GPL(nf_nat_sip_seq_adjust_hook);
62
58unsigned int (*nf_nat_sip_expect_hook)(struct sk_buff *skb, 63unsigned int (*nf_nat_sip_expect_hook)(struct sk_buff *skb,
64 unsigned int dataoff,
59 const char **dptr, 65 const char **dptr,
60 unsigned int *datalen, 66 unsigned int *datalen,
61 struct nf_conntrack_expect *exp, 67 struct nf_conntrack_expect *exp,
@@ -63,17 +69,17 @@ unsigned int (*nf_nat_sip_expect_hook)(struct sk_buff *skb,
63 unsigned int matchlen) __read_mostly; 69 unsigned int matchlen) __read_mostly;
64EXPORT_SYMBOL_GPL(nf_nat_sip_expect_hook); 70EXPORT_SYMBOL_GPL(nf_nat_sip_expect_hook);
65 71
66unsigned int (*nf_nat_sdp_addr_hook)(struct sk_buff *skb, 72unsigned int (*nf_nat_sdp_addr_hook)(struct sk_buff *skb, unsigned int dataoff,
67 const char **dptr, 73 const char **dptr,
68 unsigned int dataoff,
69 unsigned int *datalen, 74 unsigned int *datalen,
75 unsigned int sdpoff,
70 enum sdp_header_types type, 76 enum sdp_header_types type,
71 enum sdp_header_types term, 77 enum sdp_header_types term,
72 const union nf_inet_addr *addr) 78 const union nf_inet_addr *addr)
73 __read_mostly; 79 __read_mostly;
74EXPORT_SYMBOL_GPL(nf_nat_sdp_addr_hook); 80EXPORT_SYMBOL_GPL(nf_nat_sdp_addr_hook);
75 81
76unsigned int (*nf_nat_sdp_port_hook)(struct sk_buff *skb, 82unsigned int (*nf_nat_sdp_port_hook)(struct sk_buff *skb, unsigned int dataoff,
77 const char **dptr, 83 const char **dptr,
78 unsigned int *datalen, 84 unsigned int *datalen,
79 unsigned int matchoff, 85 unsigned int matchoff,
@@ -82,14 +88,15 @@ unsigned int (*nf_nat_sdp_port_hook)(struct sk_buff *skb,
82EXPORT_SYMBOL_GPL(nf_nat_sdp_port_hook); 88EXPORT_SYMBOL_GPL(nf_nat_sdp_port_hook);
83 89
84unsigned int (*nf_nat_sdp_session_hook)(struct sk_buff *skb, 90unsigned int (*nf_nat_sdp_session_hook)(struct sk_buff *skb,
85 const char **dptr,
86 unsigned int dataoff, 91 unsigned int dataoff,
92 const char **dptr,
87 unsigned int *datalen, 93 unsigned int *datalen,
94 unsigned int sdpoff,
88 const union nf_inet_addr *addr) 95 const union nf_inet_addr *addr)
89 __read_mostly; 96 __read_mostly;
90EXPORT_SYMBOL_GPL(nf_nat_sdp_session_hook); 97EXPORT_SYMBOL_GPL(nf_nat_sdp_session_hook);
91 98
92unsigned int (*nf_nat_sdp_media_hook)(struct sk_buff *skb, 99unsigned int (*nf_nat_sdp_media_hook)(struct sk_buff *skb, unsigned int dataoff,
93 const char **dptr, 100 const char **dptr,
94 unsigned int *datalen, 101 unsigned int *datalen,
95 struct nf_conntrack_expect *rtp_exp, 102 struct nf_conntrack_expect *rtp_exp,
@@ -236,12 +243,13 @@ int ct_sip_parse_request(const struct nf_conn *ct,
236 return 0; 243 return 0;
237 244
238 /* Find SIP URI */ 245 /* Find SIP URI */
239 limit -= strlen("sip:"); 246 for (; dptr < limit - strlen("sip:"); dptr++) {
240 for (; dptr < limit; dptr++) {
241 if (*dptr == '\r' || *dptr == '\n') 247 if (*dptr == '\r' || *dptr == '\n')
242 return -1; 248 return -1;
243 if (strnicmp(dptr, "sip:", strlen("sip:")) == 0) 249 if (strnicmp(dptr, "sip:", strlen("sip:")) == 0) {
250 dptr += strlen("sip:");
244 break; 251 break;
252 }
245 } 253 }
246 if (!skp_epaddr_len(ct, dptr, limit, &shift)) 254 if (!skp_epaddr_len(ct, dptr, limit, &shift))
247 return 0; 255 return 0;
@@ -276,7 +284,7 @@ EXPORT_SYMBOL_GPL(ct_sip_parse_request);
276 * tabs, spaces and continuation lines, which are treated as a single whitespace 284 * tabs, spaces and continuation lines, which are treated as a single whitespace
277 * character. 285 * character.
278 * 286 *
279 * Some headers may appear multiple times. A comma seperated list of values is 287 * Some headers may appear multiple times. A comma separated list of values is
280 * equivalent to multiple headers. 288 * equivalent to multiple headers.
281 */ 289 */
282static const struct sip_header ct_sip_hdrs[] = { 290static const struct sip_header ct_sip_hdrs[] = {
@@ -284,7 +292,8 @@ static const struct sip_header ct_sip_hdrs[] = {
284 [SIP_HDR_FROM] = SIP_HDR("From", "f", "sip:", skp_epaddr_len), 292 [SIP_HDR_FROM] = SIP_HDR("From", "f", "sip:", skp_epaddr_len),
285 [SIP_HDR_TO] = SIP_HDR("To", "t", "sip:", skp_epaddr_len), 293 [SIP_HDR_TO] = SIP_HDR("To", "t", "sip:", skp_epaddr_len),
286 [SIP_HDR_CONTACT] = SIP_HDR("Contact", "m", "sip:", skp_epaddr_len), 294 [SIP_HDR_CONTACT] = SIP_HDR("Contact", "m", "sip:", skp_epaddr_len),
287 [SIP_HDR_VIA] = SIP_HDR("Via", "v", "UDP ", epaddr_len), 295 [SIP_HDR_VIA_UDP] = SIP_HDR("Via", "v", "UDP ", epaddr_len),
296 [SIP_HDR_VIA_TCP] = SIP_HDR("Via", "v", "TCP ", epaddr_len),
288 [SIP_HDR_EXPIRES] = SIP_HDR("Expires", NULL, NULL, digits_len), 297 [SIP_HDR_EXPIRES] = SIP_HDR("Expires", NULL, NULL, digits_len),
289 [SIP_HDR_CONTENT_LENGTH] = SIP_HDR("Content-Length", "l", NULL, digits_len), 298 [SIP_HDR_CONTENT_LENGTH] = SIP_HDR("Content-Length", "l", NULL, digits_len),
290}; 299};
@@ -376,7 +385,7 @@ int ct_sip_get_header(const struct nf_conn *ct, const char *dptr,
376 dptr += hdr->len; 385 dptr += hdr->len;
377 else if (hdr->cname && limit - dptr >= hdr->clen + 1 && 386 else if (hdr->cname && limit - dptr >= hdr->clen + 1 &&
378 strnicmp(dptr, hdr->cname, hdr->clen) == 0 && 387 strnicmp(dptr, hdr->cname, hdr->clen) == 0 &&
379 !isalpha(*(dptr + hdr->clen + 1))) 388 !isalpha(*(dptr + hdr->clen)))
380 dptr += hdr->clen; 389 dptr += hdr->clen;
381 else 390 else
382 continue; 391 continue;
@@ -412,7 +421,7 @@ int ct_sip_get_header(const struct nf_conn *ct, const char *dptr,
412} 421}
413EXPORT_SYMBOL_GPL(ct_sip_get_header); 422EXPORT_SYMBOL_GPL(ct_sip_get_header);
414 423
415/* Get next header field in a list of comma seperated values */ 424/* Get next header field in a list of comma separated values */
416static int ct_sip_next_header(const struct nf_conn *ct, const char *dptr, 425static int ct_sip_next_header(const struct nf_conn *ct, const char *dptr,
417 unsigned int dataoff, unsigned int datalen, 426 unsigned int dataoff, unsigned int datalen,
418 enum sip_header_types type, 427 enum sip_header_types type,
@@ -516,6 +525,33 @@ int ct_sip_parse_header_uri(const struct nf_conn *ct, const char *dptr,
516} 525}
517EXPORT_SYMBOL_GPL(ct_sip_parse_header_uri); 526EXPORT_SYMBOL_GPL(ct_sip_parse_header_uri);
518 527
528static int ct_sip_parse_param(const struct nf_conn *ct, const char *dptr,
529 unsigned int dataoff, unsigned int datalen,
530 const char *name,
531 unsigned int *matchoff, unsigned int *matchlen)
532{
533 const char *limit = dptr + datalen;
534 const char *start;
535 const char *end;
536
537 limit = ct_sip_header_search(dptr + dataoff, limit, ",", strlen(","));
538 if (!limit)
539 limit = dptr + datalen;
540
541 start = ct_sip_header_search(dptr + dataoff, limit, name, strlen(name));
542 if (!start)
543 return 0;
544 start += strlen(name);
545
546 end = ct_sip_header_search(start, limit, ";", strlen(";"));
547 if (!end)
548 end = limit;
549
550 *matchoff = start - dptr;
551 *matchlen = end - start;
552 return 1;
553}
554
519/* Parse address from header parameter and return address, offset and length */ 555/* Parse address from header parameter and return address, offset and length */
520int ct_sip_parse_address_param(const struct nf_conn *ct, const char *dptr, 556int ct_sip_parse_address_param(const struct nf_conn *ct, const char *dptr,
521 unsigned int dataoff, unsigned int datalen, 557 unsigned int dataoff, unsigned int datalen,
@@ -574,6 +610,29 @@ int ct_sip_parse_numerical_param(const struct nf_conn *ct, const char *dptr,
574} 610}
575EXPORT_SYMBOL_GPL(ct_sip_parse_numerical_param); 611EXPORT_SYMBOL_GPL(ct_sip_parse_numerical_param);
576 612
613static int ct_sip_parse_transport(struct nf_conn *ct, const char *dptr,
614 unsigned int dataoff, unsigned int datalen,
615 u8 *proto)
616{
617 unsigned int matchoff, matchlen;
618
619 if (ct_sip_parse_param(ct, dptr, dataoff, datalen, "transport=",
620 &matchoff, &matchlen)) {
621 if (!strnicmp(dptr + matchoff, "TCP", strlen("TCP")))
622 *proto = IPPROTO_TCP;
623 else if (!strnicmp(dptr + matchoff, "UDP", strlen("UDP")))
624 *proto = IPPROTO_UDP;
625 else
626 return 0;
627
628 if (*proto != nf_ct_protonum(ct))
629 return 0;
630 } else
631 *proto = nf_ct_protonum(ct);
632
633 return 1;
634}
635
577/* SDP header parsing: a SDP session description contains an ordered set of 636/* SDP header parsing: a SDP session description contains an ordered set of
578 * headers, starting with a section containing general session parameters, 637 * headers, starting with a section containing general session parameters,
579 * optionally followed by multiple media descriptions. 638 * optionally followed by multiple media descriptions.
@@ -682,7 +741,7 @@ static int ct_sip_parse_sdp_addr(const struct nf_conn *ct, const char *dptr,
682 741
683static int refresh_signalling_expectation(struct nf_conn *ct, 742static int refresh_signalling_expectation(struct nf_conn *ct,
684 union nf_inet_addr *addr, 743 union nf_inet_addr *addr,
685 __be16 port, 744 u8 proto, __be16 port,
686 unsigned int expires) 745 unsigned int expires)
687{ 746{
688 struct nf_conn_help *help = nfct_help(ct); 747 struct nf_conn_help *help = nfct_help(ct);
@@ -694,6 +753,7 @@ static int refresh_signalling_expectation(struct nf_conn *ct,
694 hlist_for_each_entry_safe(exp, n, next, &help->expectations, lnode) { 753 hlist_for_each_entry_safe(exp, n, next, &help->expectations, lnode) {
695 if (exp->class != SIP_EXPECT_SIGNALLING || 754 if (exp->class != SIP_EXPECT_SIGNALLING ||
696 !nf_inet_addr_cmp(&exp->tuple.dst.u3, addr) || 755 !nf_inet_addr_cmp(&exp->tuple.dst.u3, addr) ||
756 exp->tuple.dst.protonum != proto ||
697 exp->tuple.dst.u.udp.port != port) 757 exp->tuple.dst.u.udp.port != port)
698 continue; 758 continue;
699 if (!del_timer(&exp->timeout)) 759 if (!del_timer(&exp->timeout))
@@ -728,7 +788,7 @@ static void flush_expectations(struct nf_conn *ct, bool media)
728 spin_unlock_bh(&nf_conntrack_lock); 788 spin_unlock_bh(&nf_conntrack_lock);
729} 789}
730 790
731static int set_expected_rtp_rtcp(struct sk_buff *skb, 791static int set_expected_rtp_rtcp(struct sk_buff *skb, unsigned int dataoff,
732 const char **dptr, unsigned int *datalen, 792 const char **dptr, unsigned int *datalen,
733 union nf_inet_addr *daddr, __be16 port, 793 union nf_inet_addr *daddr, __be16 port,
734 enum sip_expectation_classes class, 794 enum sip_expectation_classes class,
@@ -777,7 +837,7 @@ static int set_expected_rtp_rtcp(struct sk_buff *skb,
777 837
778 rcu_read_lock(); 838 rcu_read_lock();
779 do { 839 do {
780 exp = __nf_ct_expect_find(net, &tuple); 840 exp = __nf_ct_expect_find(net, nf_ct_zone(ct), &tuple);
781 841
782 if (!exp || exp->master == ct || 842 if (!exp || exp->master == ct ||
783 nfct_help(exp->master)->helper != nfct_help(ct)->helper || 843 nfct_help(exp->master)->helper != nfct_help(ct)->helper ||
@@ -805,7 +865,7 @@ static int set_expected_rtp_rtcp(struct sk_buff *skb,
805 if (direct_rtp) { 865 if (direct_rtp) {
806 nf_nat_sdp_port = rcu_dereference(nf_nat_sdp_port_hook); 866 nf_nat_sdp_port = rcu_dereference(nf_nat_sdp_port_hook);
807 if (nf_nat_sdp_port && 867 if (nf_nat_sdp_port &&
808 !nf_nat_sdp_port(skb, dptr, datalen, 868 !nf_nat_sdp_port(skb, dataoff, dptr, datalen,
809 mediaoff, medialen, ntohs(rtp_port))) 869 mediaoff, medialen, ntohs(rtp_port)))
810 goto err1; 870 goto err1;
811 } 871 }
@@ -827,7 +887,8 @@ static int set_expected_rtp_rtcp(struct sk_buff *skb,
827 887
828 nf_nat_sdp_media = rcu_dereference(nf_nat_sdp_media_hook); 888 nf_nat_sdp_media = rcu_dereference(nf_nat_sdp_media_hook);
829 if (nf_nat_sdp_media && ct->status & IPS_NAT_MASK && !direct_rtp) 889 if (nf_nat_sdp_media && ct->status & IPS_NAT_MASK && !direct_rtp)
830 ret = nf_nat_sdp_media(skb, dptr, datalen, rtp_exp, rtcp_exp, 890 ret = nf_nat_sdp_media(skb, dataoff, dptr, datalen,
891 rtp_exp, rtcp_exp,
831 mediaoff, medialen, daddr); 892 mediaoff, medialen, daddr);
832 else { 893 else {
833 if (nf_ct_expect_related(rtp_exp) == 0) { 894 if (nf_ct_expect_related(rtp_exp) == 0) {
@@ -847,6 +908,7 @@ err1:
847static const struct sdp_media_type sdp_media_types[] = { 908static const struct sdp_media_type sdp_media_types[] = {
848 SDP_MEDIA_TYPE("audio ", SIP_EXPECT_AUDIO), 909 SDP_MEDIA_TYPE("audio ", SIP_EXPECT_AUDIO),
849 SDP_MEDIA_TYPE("video ", SIP_EXPECT_VIDEO), 910 SDP_MEDIA_TYPE("video ", SIP_EXPECT_VIDEO),
911 SDP_MEDIA_TYPE("image ", SIP_EXPECT_IMAGE),
850}; 912};
851 913
852static const struct sdp_media_type *sdp_media_type(const char *dptr, 914static const struct sdp_media_type *sdp_media_type(const char *dptr,
@@ -866,13 +928,12 @@ static const struct sdp_media_type *sdp_media_type(const char *dptr,
866 return NULL; 928 return NULL;
867} 929}
868 930
869static int process_sdp(struct sk_buff *skb, 931static int process_sdp(struct sk_buff *skb, unsigned int dataoff,
870 const char **dptr, unsigned int *datalen, 932 const char **dptr, unsigned int *datalen,
871 unsigned int cseq) 933 unsigned int cseq)
872{ 934{
873 enum ip_conntrack_info ctinfo; 935 enum ip_conntrack_info ctinfo;
874 struct nf_conn *ct = nf_ct_get(skb, &ctinfo); 936 struct nf_conn *ct = nf_ct_get(skb, &ctinfo);
875 struct nf_conn_help *help = nfct_help(ct);
876 unsigned int matchoff, matchlen; 937 unsigned int matchoff, matchlen;
877 unsigned int mediaoff, medialen; 938 unsigned int mediaoff, medialen;
878 unsigned int sdpoff; 939 unsigned int sdpoff;
@@ -941,7 +1002,7 @@ static int process_sdp(struct sk_buff *skb,
941 else 1002 else
942 return NF_DROP; 1003 return NF_DROP;
943 1004
944 ret = set_expected_rtp_rtcp(skb, dptr, datalen, 1005 ret = set_expected_rtp_rtcp(skb, dataoff, dptr, datalen,
945 &rtp_addr, htons(port), t->class, 1006 &rtp_addr, htons(port), t->class,
946 mediaoff, medialen); 1007 mediaoff, medialen);
947 if (ret != NF_ACCEPT) 1008 if (ret != NF_ACCEPT)
@@ -949,8 +1010,9 @@ static int process_sdp(struct sk_buff *skb,
949 1010
950 /* Update media connection address if present */ 1011 /* Update media connection address if present */
951 if (maddr_len && nf_nat_sdp_addr && ct->status & IPS_NAT_MASK) { 1012 if (maddr_len && nf_nat_sdp_addr && ct->status & IPS_NAT_MASK) {
952 ret = nf_nat_sdp_addr(skb, dptr, mediaoff, datalen, 1013 ret = nf_nat_sdp_addr(skb, dataoff, dptr, datalen,
953 c_hdr, SDP_HDR_MEDIA, &rtp_addr); 1014 mediaoff, c_hdr, SDP_HDR_MEDIA,
1015 &rtp_addr);
954 if (ret != NF_ACCEPT) 1016 if (ret != NF_ACCEPT)
955 return ret; 1017 return ret;
956 } 1018 }
@@ -960,14 +1022,12 @@ static int process_sdp(struct sk_buff *skb,
960 /* Update session connection and owner addresses */ 1022 /* Update session connection and owner addresses */
961 nf_nat_sdp_session = rcu_dereference(nf_nat_sdp_session_hook); 1023 nf_nat_sdp_session = rcu_dereference(nf_nat_sdp_session_hook);
962 if (nf_nat_sdp_session && ct->status & IPS_NAT_MASK) 1024 if (nf_nat_sdp_session && ct->status & IPS_NAT_MASK)
963 ret = nf_nat_sdp_session(skb, dptr, sdpoff, datalen, &rtp_addr); 1025 ret = nf_nat_sdp_session(skb, dataoff, dptr, datalen, sdpoff,
964 1026 &rtp_addr);
965 if (ret == NF_ACCEPT && i > 0)
966 help->help.ct_sip_info.invite_cseq = cseq;
967 1027
968 return ret; 1028 return ret;
969} 1029}
970static int process_invite_response(struct sk_buff *skb, 1030static int process_invite_response(struct sk_buff *skb, unsigned int dataoff,
971 const char **dptr, unsigned int *datalen, 1031 const char **dptr, unsigned int *datalen,
972 unsigned int cseq, unsigned int code) 1032 unsigned int cseq, unsigned int code)
973{ 1033{
@@ -977,13 +1037,13 @@ static int process_invite_response(struct sk_buff *skb,
977 1037
978 if ((code >= 100 && code <= 199) || 1038 if ((code >= 100 && code <= 199) ||
979 (code >= 200 && code <= 299)) 1039 (code >= 200 && code <= 299))
980 return process_sdp(skb, dptr, datalen, cseq); 1040 return process_sdp(skb, dataoff, dptr, datalen, cseq);
981 else if (help->help.ct_sip_info.invite_cseq == cseq) 1041 else if (help->help.ct_sip_info.invite_cseq == cseq)
982 flush_expectations(ct, true); 1042 flush_expectations(ct, true);
983 return NF_ACCEPT; 1043 return NF_ACCEPT;
984} 1044}
985 1045
986static int process_update_response(struct sk_buff *skb, 1046static int process_update_response(struct sk_buff *skb, unsigned int dataoff,
987 const char **dptr, unsigned int *datalen, 1047 const char **dptr, unsigned int *datalen,
988 unsigned int cseq, unsigned int code) 1048 unsigned int cseq, unsigned int code)
989{ 1049{
@@ -993,13 +1053,13 @@ static int process_update_response(struct sk_buff *skb,
993 1053
994 if ((code >= 100 && code <= 199) || 1054 if ((code >= 100 && code <= 199) ||
995 (code >= 200 && code <= 299)) 1055 (code >= 200 && code <= 299))
996 return process_sdp(skb, dptr, datalen, cseq); 1056 return process_sdp(skb, dataoff, dptr, datalen, cseq);
997 else if (help->help.ct_sip_info.invite_cseq == cseq) 1057 else if (help->help.ct_sip_info.invite_cseq == cseq)
998 flush_expectations(ct, true); 1058 flush_expectations(ct, true);
999 return NF_ACCEPT; 1059 return NF_ACCEPT;
1000} 1060}
1001 1061
1002static int process_prack_response(struct sk_buff *skb, 1062static int process_prack_response(struct sk_buff *skb, unsigned int dataoff,
1003 const char **dptr, unsigned int *datalen, 1063 const char **dptr, unsigned int *datalen,
1004 unsigned int cseq, unsigned int code) 1064 unsigned int cseq, unsigned int code)
1005{ 1065{
@@ -1009,13 +1069,29 @@ static int process_prack_response(struct sk_buff *skb,
1009 1069
1010 if ((code >= 100 && code <= 199) || 1070 if ((code >= 100 && code <= 199) ||
1011 (code >= 200 && code <= 299)) 1071 (code >= 200 && code <= 299))
1012 return process_sdp(skb, dptr, datalen, cseq); 1072 return process_sdp(skb, dataoff, dptr, datalen, cseq);
1013 else if (help->help.ct_sip_info.invite_cseq == cseq) 1073 else if (help->help.ct_sip_info.invite_cseq == cseq)
1014 flush_expectations(ct, true); 1074 flush_expectations(ct, true);
1015 return NF_ACCEPT; 1075 return NF_ACCEPT;
1016} 1076}
1017 1077
1018static int process_bye_request(struct sk_buff *skb, 1078static int process_invite_request(struct sk_buff *skb, unsigned int dataoff,
1079 const char **dptr, unsigned int *datalen,
1080 unsigned int cseq)
1081{
1082 enum ip_conntrack_info ctinfo;
1083 struct nf_conn *ct = nf_ct_get(skb, &ctinfo);
1084 struct nf_conn_help *help = nfct_help(ct);
1085 unsigned int ret;
1086
1087 flush_expectations(ct, true);
1088 ret = process_sdp(skb, dataoff, dptr, datalen, cseq);
1089 if (ret == NF_ACCEPT)
1090 help->help.ct_sip_info.invite_cseq = cseq;
1091 return ret;
1092}
1093
1094static int process_bye_request(struct sk_buff *skb, unsigned int dataoff,
1019 const char **dptr, unsigned int *datalen, 1095 const char **dptr, unsigned int *datalen,
1020 unsigned int cseq) 1096 unsigned int cseq)
1021{ 1097{
@@ -1030,7 +1106,7 @@ static int process_bye_request(struct sk_buff *skb,
1030 * signalling connections. The expectation is marked inactive and is activated 1106 * signalling connections. The expectation is marked inactive and is activated
1031 * when receiving a response indicating success from the registrar. 1107 * when receiving a response indicating success from the registrar.
1032 */ 1108 */
1033static int process_register_request(struct sk_buff *skb, 1109static int process_register_request(struct sk_buff *skb, unsigned int dataoff,
1034 const char **dptr, unsigned int *datalen, 1110 const char **dptr, unsigned int *datalen,
1035 unsigned int cseq) 1111 unsigned int cseq)
1036{ 1112{
@@ -1042,6 +1118,7 @@ static int process_register_request(struct sk_buff *skb,
1042 struct nf_conntrack_expect *exp; 1118 struct nf_conntrack_expect *exp;
1043 union nf_inet_addr *saddr, daddr; 1119 union nf_inet_addr *saddr, daddr;
1044 __be16 port; 1120 __be16 port;
1121 u8 proto;
1045 unsigned int expires = 0; 1122 unsigned int expires = 0;
1046 int ret; 1123 int ret;
1047 typeof(nf_nat_sip_expect_hook) nf_nat_sip_expect; 1124 typeof(nf_nat_sip_expect_hook) nf_nat_sip_expect;
@@ -1074,6 +1151,10 @@ static int process_register_request(struct sk_buff *skb,
1074 if (!nf_inet_addr_cmp(&ct->tuplehash[dir].tuple.src.u3, &daddr)) 1151 if (!nf_inet_addr_cmp(&ct->tuplehash[dir].tuple.src.u3, &daddr))
1075 return NF_ACCEPT; 1152 return NF_ACCEPT;
1076 1153
1154 if (ct_sip_parse_transport(ct, *dptr, matchoff + matchlen, *datalen,
1155 &proto) == 0)
1156 return NF_ACCEPT;
1157
1077 if (ct_sip_parse_numerical_param(ct, *dptr, 1158 if (ct_sip_parse_numerical_param(ct, *dptr,
1078 matchoff + matchlen, *datalen, 1159 matchoff + matchlen, *datalen,
1079 "expires=", NULL, NULL, &expires) < 0) 1160 "expires=", NULL, NULL, &expires) < 0)
@@ -1093,14 +1174,14 @@ static int process_register_request(struct sk_buff *skb,
1093 saddr = &ct->tuplehash[!dir].tuple.src.u3; 1174 saddr = &ct->tuplehash[!dir].tuple.src.u3;
1094 1175
1095 nf_ct_expect_init(exp, SIP_EXPECT_SIGNALLING, nf_ct_l3num(ct), 1176 nf_ct_expect_init(exp, SIP_EXPECT_SIGNALLING, nf_ct_l3num(ct),
1096 saddr, &daddr, IPPROTO_UDP, NULL, &port); 1177 saddr, &daddr, proto, NULL, &port);
1097 exp->timeout.expires = sip_timeout * HZ; 1178 exp->timeout.expires = sip_timeout * HZ;
1098 exp->helper = nfct_help(ct)->helper; 1179 exp->helper = nfct_help(ct)->helper;
1099 exp->flags = NF_CT_EXPECT_PERMANENT | NF_CT_EXPECT_INACTIVE; 1180 exp->flags = NF_CT_EXPECT_PERMANENT | NF_CT_EXPECT_INACTIVE;
1100 1181
1101 nf_nat_sip_expect = rcu_dereference(nf_nat_sip_expect_hook); 1182 nf_nat_sip_expect = rcu_dereference(nf_nat_sip_expect_hook);
1102 if (nf_nat_sip_expect && ct->status & IPS_NAT_MASK) 1183 if (nf_nat_sip_expect && ct->status & IPS_NAT_MASK)
1103 ret = nf_nat_sip_expect(skb, dptr, datalen, exp, 1184 ret = nf_nat_sip_expect(skb, dataoff, dptr, datalen, exp,
1104 matchoff, matchlen); 1185 matchoff, matchlen);
1105 else { 1186 else {
1106 if (nf_ct_expect_related(exp) != 0) 1187 if (nf_ct_expect_related(exp) != 0)
@@ -1116,7 +1197,7 @@ store_cseq:
1116 return ret; 1197 return ret;
1117} 1198}
1118 1199
1119static int process_register_response(struct sk_buff *skb, 1200static int process_register_response(struct sk_buff *skb, unsigned int dataoff,
1120 const char **dptr, unsigned int *datalen, 1201 const char **dptr, unsigned int *datalen,
1121 unsigned int cseq, unsigned int code) 1202 unsigned int cseq, unsigned int code)
1122{ 1203{
@@ -1126,7 +1207,8 @@ static int process_register_response(struct sk_buff *skb,
1126 enum ip_conntrack_dir dir = CTINFO2DIR(ctinfo); 1207 enum ip_conntrack_dir dir = CTINFO2DIR(ctinfo);
1127 union nf_inet_addr addr; 1208 union nf_inet_addr addr;
1128 __be16 port; 1209 __be16 port;
1129 unsigned int matchoff, matchlen, dataoff = 0; 1210 u8 proto;
1211 unsigned int matchoff, matchlen, coff = 0;
1130 unsigned int expires = 0; 1212 unsigned int expires = 0;
1131 int in_contact = 0, ret; 1213 int in_contact = 0, ret;
1132 1214
@@ -1153,7 +1235,7 @@ static int process_register_response(struct sk_buff *skb,
1153 while (1) { 1235 while (1) {
1154 unsigned int c_expires = expires; 1236 unsigned int c_expires = expires;
1155 1237
1156 ret = ct_sip_parse_header_uri(ct, *dptr, &dataoff, *datalen, 1238 ret = ct_sip_parse_header_uri(ct, *dptr, &coff, *datalen,
1157 SIP_HDR_CONTACT, &in_contact, 1239 SIP_HDR_CONTACT, &in_contact,
1158 &matchoff, &matchlen, 1240 &matchoff, &matchlen,
1159 &addr, &port); 1241 &addr, &port);
@@ -1166,6 +1248,10 @@ static int process_register_response(struct sk_buff *skb,
1166 if (!nf_inet_addr_cmp(&ct->tuplehash[dir].tuple.dst.u3, &addr)) 1248 if (!nf_inet_addr_cmp(&ct->tuplehash[dir].tuple.dst.u3, &addr))
1167 continue; 1249 continue;
1168 1250
1251 if (ct_sip_parse_transport(ct, *dptr, matchoff + matchlen,
1252 *datalen, &proto) == 0)
1253 continue;
1254
1169 ret = ct_sip_parse_numerical_param(ct, *dptr, 1255 ret = ct_sip_parse_numerical_param(ct, *dptr,
1170 matchoff + matchlen, 1256 matchoff + matchlen,
1171 *datalen, "expires=", 1257 *datalen, "expires=",
@@ -1174,7 +1260,8 @@ static int process_register_response(struct sk_buff *skb,
1174 return NF_DROP; 1260 return NF_DROP;
1175 if (c_expires == 0) 1261 if (c_expires == 0)
1176 break; 1262 break;
1177 if (refresh_signalling_expectation(ct, &addr, port, c_expires)) 1263 if (refresh_signalling_expectation(ct, &addr, proto, port,
1264 c_expires))
1178 return NF_ACCEPT; 1265 return NF_ACCEPT;
1179 } 1266 }
1180 1267
@@ -1184,7 +1271,7 @@ flush:
1184} 1271}
1185 1272
1186static const struct sip_handler sip_handlers[] = { 1273static const struct sip_handler sip_handlers[] = {
1187 SIP_HANDLER("INVITE", process_sdp, process_invite_response), 1274 SIP_HANDLER("INVITE", process_invite_request, process_invite_response),
1188 SIP_HANDLER("UPDATE", process_sdp, process_update_response), 1275 SIP_HANDLER("UPDATE", process_sdp, process_update_response),
1189 SIP_HANDLER("ACK", process_sdp, NULL), 1276 SIP_HANDLER("ACK", process_sdp, NULL),
1190 SIP_HANDLER("PRACK", process_sdp, process_prack_response), 1277 SIP_HANDLER("PRACK", process_sdp, process_prack_response),
@@ -1192,13 +1279,13 @@ static const struct sip_handler sip_handlers[] = {
1192 SIP_HANDLER("REGISTER", process_register_request, process_register_response), 1279 SIP_HANDLER("REGISTER", process_register_request, process_register_response),
1193}; 1280};
1194 1281
1195static int process_sip_response(struct sk_buff *skb, 1282static int process_sip_response(struct sk_buff *skb, unsigned int dataoff,
1196 const char **dptr, unsigned int *datalen) 1283 const char **dptr, unsigned int *datalen)
1197{ 1284{
1198 enum ip_conntrack_info ctinfo; 1285 enum ip_conntrack_info ctinfo;
1199 struct nf_conn *ct = nf_ct_get(skb, &ctinfo); 1286 struct nf_conn *ct = nf_ct_get(skb, &ctinfo);
1200 unsigned int matchoff, matchlen; 1287 unsigned int matchoff, matchlen, matchend;
1201 unsigned int code, cseq, dataoff, i; 1288 unsigned int code, cseq, i;
1202 1289
1203 if (*datalen < strlen("SIP/2.0 200")) 1290 if (*datalen < strlen("SIP/2.0 200"))
1204 return NF_ACCEPT; 1291 return NF_ACCEPT;
@@ -1212,7 +1299,7 @@ static int process_sip_response(struct sk_buff *skb,
1212 cseq = simple_strtoul(*dptr + matchoff, NULL, 10); 1299 cseq = simple_strtoul(*dptr + matchoff, NULL, 10);
1213 if (!cseq) 1300 if (!cseq)
1214 return NF_DROP; 1301 return NF_DROP;
1215 dataoff = matchoff + matchlen + 1; 1302 matchend = matchoff + matchlen + 1;
1216 1303
1217 for (i = 0; i < ARRAY_SIZE(sip_handlers); i++) { 1304 for (i = 0; i < ARRAY_SIZE(sip_handlers); i++) {
1218 const struct sip_handler *handler; 1305 const struct sip_handler *handler;
@@ -1220,15 +1307,16 @@ static int process_sip_response(struct sk_buff *skb,
1220 handler = &sip_handlers[i]; 1307 handler = &sip_handlers[i];
1221 if (handler->response == NULL) 1308 if (handler->response == NULL)
1222 continue; 1309 continue;
1223 if (*datalen < dataoff + handler->len || 1310 if (*datalen < matchend + handler->len ||
1224 strnicmp(*dptr + dataoff, handler->method, handler->len)) 1311 strnicmp(*dptr + matchend, handler->method, handler->len))
1225 continue; 1312 continue;
1226 return handler->response(skb, dptr, datalen, cseq, code); 1313 return handler->response(skb, dataoff, dptr, datalen,
1314 cseq, code);
1227 } 1315 }
1228 return NF_ACCEPT; 1316 return NF_ACCEPT;
1229} 1317}
1230 1318
1231static int process_sip_request(struct sk_buff *skb, 1319static int process_sip_request(struct sk_buff *skb, unsigned int dataoff,
1232 const char **dptr, unsigned int *datalen) 1320 const char **dptr, unsigned int *datalen)
1233{ 1321{
1234 enum ip_conntrack_info ctinfo; 1322 enum ip_conntrack_info ctinfo;
@@ -1253,69 +1341,157 @@ static int process_sip_request(struct sk_buff *skb,
1253 if (!cseq) 1341 if (!cseq)
1254 return NF_DROP; 1342 return NF_DROP;
1255 1343
1256 return handler->request(skb, dptr, datalen, cseq); 1344 return handler->request(skb, dataoff, dptr, datalen, cseq);
1257 } 1345 }
1258 return NF_ACCEPT; 1346 return NF_ACCEPT;
1259} 1347}
1260 1348
1261static int sip_help(struct sk_buff *skb, 1349static int process_sip_msg(struct sk_buff *skb, struct nf_conn *ct,
1262 unsigned int protoff, 1350 unsigned int dataoff, const char **dptr,
1263 struct nf_conn *ct, 1351 unsigned int *datalen)
1264 enum ip_conntrack_info ctinfo) 1352{
1353 typeof(nf_nat_sip_hook) nf_nat_sip;
1354 int ret;
1355
1356 if (strnicmp(*dptr, "SIP/2.0 ", strlen("SIP/2.0 ")) != 0)
1357 ret = process_sip_request(skb, dataoff, dptr, datalen);
1358 else
1359 ret = process_sip_response(skb, dataoff, dptr, datalen);
1360
1361 if (ret == NF_ACCEPT && ct->status & IPS_NAT_MASK) {
1362 nf_nat_sip = rcu_dereference(nf_nat_sip_hook);
1363 if (nf_nat_sip && !nf_nat_sip(skb, dataoff, dptr, datalen))
1364 ret = NF_DROP;
1365 }
1366
1367 return ret;
1368}
1369
1370static int sip_help_tcp(struct sk_buff *skb, unsigned int protoff,
1371 struct nf_conn *ct, enum ip_conntrack_info ctinfo)
1265{ 1372{
1373 struct tcphdr *th, _tcph;
1266 unsigned int dataoff, datalen; 1374 unsigned int dataoff, datalen;
1267 const char *dptr; 1375 unsigned int matchoff, matchlen, clen;
1376 unsigned int msglen, origlen;
1377 const char *dptr, *end;
1378 s16 diff, tdiff = 0;
1268 int ret; 1379 int ret;
1269 typeof(nf_nat_sip_hook) nf_nat_sip; 1380 typeof(nf_nat_sip_seq_adjust_hook) nf_nat_sip_seq_adjust;
1381
1382 if (ctinfo != IP_CT_ESTABLISHED &&
1383 ctinfo != IP_CT_ESTABLISHED + IP_CT_IS_REPLY)
1384 return NF_ACCEPT;
1270 1385
1271 /* No Data ? */ 1386 /* No Data ? */
1272 dataoff = protoff + sizeof(struct udphdr); 1387 th = skb_header_pointer(skb, protoff, sizeof(_tcph), &_tcph);
1388 if (th == NULL)
1389 return NF_ACCEPT;
1390 dataoff = protoff + th->doff * 4;
1273 if (dataoff >= skb->len) 1391 if (dataoff >= skb->len)
1274 return NF_ACCEPT; 1392 return NF_ACCEPT;
1275 1393
1276 nf_ct_refresh(ct, skb, sip_timeout * HZ); 1394 nf_ct_refresh(ct, skb, sip_timeout * HZ);
1277 1395
1278 if (!skb_is_nonlinear(skb)) 1396 if (skb_is_nonlinear(skb)) {
1279 dptr = skb->data + dataoff;
1280 else {
1281 pr_debug("Copy of skbuff not supported yet.\n"); 1397 pr_debug("Copy of skbuff not supported yet.\n");
1282 return NF_ACCEPT; 1398 return NF_ACCEPT;
1283 } 1399 }
1284 1400
1401 dptr = skb->data + dataoff;
1285 datalen = skb->len - dataoff; 1402 datalen = skb->len - dataoff;
1286 if (datalen < strlen("SIP/2.0 200")) 1403 if (datalen < strlen("SIP/2.0 200"))
1287 return NF_ACCEPT; 1404 return NF_ACCEPT;
1288 1405
1289 if (strnicmp(dptr, "SIP/2.0 ", strlen("SIP/2.0 ")) != 0) 1406 while (1) {
1290 ret = process_sip_request(skb, &dptr, &datalen); 1407 if (ct_sip_get_header(ct, dptr, 0, datalen,
1291 else 1408 SIP_HDR_CONTENT_LENGTH,
1292 ret = process_sip_response(skb, &dptr, &datalen); 1409 &matchoff, &matchlen) <= 0)
1410 break;
1411
1412 clen = simple_strtoul(dptr + matchoff, (char **)&end, 10);
1413 if (dptr + matchoff == end)
1414 break;
1415
1416 if (end + strlen("\r\n\r\n") > dptr + datalen)
1417 break;
1418 if (end[0] != '\r' || end[1] != '\n' ||
1419 end[2] != '\r' || end[3] != '\n')
1420 break;
1421 end += strlen("\r\n\r\n") + clen;
1422
1423 msglen = origlen = end - dptr;
1424
1425 ret = process_sip_msg(skb, ct, dataoff, &dptr, &msglen);
1426 if (ret != NF_ACCEPT)
1427 break;
1428 diff = msglen - origlen;
1429 tdiff += diff;
1430
1431 dataoff += msglen;
1432 dptr += msglen;
1433 datalen = datalen + diff - msglen;
1434 }
1293 1435
1294 if (ret == NF_ACCEPT && ct->status & IPS_NAT_MASK) { 1436 if (ret == NF_ACCEPT && ct->status & IPS_NAT_MASK) {
1295 nf_nat_sip = rcu_dereference(nf_nat_sip_hook); 1437 nf_nat_sip_seq_adjust = rcu_dereference(nf_nat_sip_seq_adjust_hook);
1296 if (nf_nat_sip && !nf_nat_sip(skb, &dptr, &datalen)) 1438 if (nf_nat_sip_seq_adjust)
1297 ret = NF_DROP; 1439 nf_nat_sip_seq_adjust(skb, tdiff);
1298 } 1440 }
1299 1441
1300 return ret; 1442 return ret;
1301} 1443}
1302 1444
1303static struct nf_conntrack_helper sip[MAX_PORTS][2] __read_mostly; 1445static int sip_help_udp(struct sk_buff *skb, unsigned int protoff,
1304static char sip_names[MAX_PORTS][2][sizeof("sip-65535")] __read_mostly; 1446 struct nf_conn *ct, enum ip_conntrack_info ctinfo)
1447{
1448 unsigned int dataoff, datalen;
1449 const char *dptr;
1450
1451 /* No Data ? */
1452 dataoff = protoff + sizeof(struct udphdr);
1453 if (dataoff >= skb->len)
1454 return NF_ACCEPT;
1455
1456 nf_ct_refresh(ct, skb, sip_timeout * HZ);
1457
1458 if (skb_is_nonlinear(skb)) {
1459 pr_debug("Copy of skbuff not supported yet.\n");
1460 return NF_ACCEPT;
1461 }
1462
1463 dptr = skb->data + dataoff;
1464 datalen = skb->len - dataoff;
1465 if (datalen < strlen("SIP/2.0 200"))
1466 return NF_ACCEPT;
1467
1468 return process_sip_msg(skb, ct, dataoff, &dptr, &datalen);
1469}
1470
1471static struct nf_conntrack_helper sip[MAX_PORTS][4] __read_mostly;
1472static char sip_names[MAX_PORTS][4][sizeof("sip-65535")] __read_mostly;
1305 1473
1306static const struct nf_conntrack_expect_policy sip_exp_policy[SIP_EXPECT_MAX + 1] = { 1474static const struct nf_conntrack_expect_policy sip_exp_policy[SIP_EXPECT_MAX + 1] = {
1307 [SIP_EXPECT_SIGNALLING] = { 1475 [SIP_EXPECT_SIGNALLING] = {
1476 .name = "signalling",
1308 .max_expected = 1, 1477 .max_expected = 1,
1309 .timeout = 3 * 60, 1478 .timeout = 3 * 60,
1310 }, 1479 },
1311 [SIP_EXPECT_AUDIO] = { 1480 [SIP_EXPECT_AUDIO] = {
1481 .name = "audio",
1312 .max_expected = 2 * IP_CT_DIR_MAX, 1482 .max_expected = 2 * IP_CT_DIR_MAX,
1313 .timeout = 3 * 60, 1483 .timeout = 3 * 60,
1314 }, 1484 },
1315 [SIP_EXPECT_VIDEO] = { 1485 [SIP_EXPECT_VIDEO] = {
1486 .name = "video",
1316 .max_expected = 2 * IP_CT_DIR_MAX, 1487 .max_expected = 2 * IP_CT_DIR_MAX,
1317 .timeout = 3 * 60, 1488 .timeout = 3 * 60,
1318 }, 1489 },
1490 [SIP_EXPECT_IMAGE] = {
1491 .name = "image",
1492 .max_expected = IP_CT_DIR_MAX,
1493 .timeout = 3 * 60,
1494 },
1319}; 1495};
1320 1496
1321static void nf_conntrack_sip_fini(void) 1497static void nf_conntrack_sip_fini(void)
@@ -1323,7 +1499,7 @@ static void nf_conntrack_sip_fini(void)
1323 int i, j; 1499 int i, j;
1324 1500
1325 for (i = 0; i < ports_c; i++) { 1501 for (i = 0; i < ports_c; i++) {
1326 for (j = 0; j < 2; j++) { 1502 for (j = 0; j < ARRAY_SIZE(sip[i]); j++) {
1327 if (sip[i][j].me == NULL) 1503 if (sip[i][j].me == NULL)
1328 continue; 1504 continue;
1329 nf_conntrack_helper_unregister(&sip[i][j]); 1505 nf_conntrack_helper_unregister(&sip[i][j]);
@@ -1343,14 +1519,24 @@ static int __init nf_conntrack_sip_init(void)
1343 memset(&sip[i], 0, sizeof(sip[i])); 1519 memset(&sip[i], 0, sizeof(sip[i]));
1344 1520
1345 sip[i][0].tuple.src.l3num = AF_INET; 1521 sip[i][0].tuple.src.l3num = AF_INET;
1346 sip[i][1].tuple.src.l3num = AF_INET6; 1522 sip[i][0].tuple.dst.protonum = IPPROTO_UDP;
1347 for (j = 0; j < 2; j++) { 1523 sip[i][0].help = sip_help_udp;
1348 sip[i][j].tuple.dst.protonum = IPPROTO_UDP; 1524 sip[i][1].tuple.src.l3num = AF_INET;
1525 sip[i][1].tuple.dst.protonum = IPPROTO_TCP;
1526 sip[i][1].help = sip_help_tcp;
1527
1528 sip[i][2].tuple.src.l3num = AF_INET6;
1529 sip[i][2].tuple.dst.protonum = IPPROTO_UDP;
1530 sip[i][2].help = sip_help_udp;
1531 sip[i][3].tuple.src.l3num = AF_INET6;
1532 sip[i][3].tuple.dst.protonum = IPPROTO_TCP;
1533 sip[i][3].help = sip_help_tcp;
1534
1535 for (j = 0; j < ARRAY_SIZE(sip[i]); j++) {
1349 sip[i][j].tuple.src.u.udp.port = htons(ports[i]); 1536 sip[i][j].tuple.src.u.udp.port = htons(ports[i]);
1350 sip[i][j].expect_policy = sip_exp_policy; 1537 sip[i][j].expect_policy = sip_exp_policy;
1351 sip[i][j].expect_class_max = SIP_EXPECT_MAX; 1538 sip[i][j].expect_class_max = SIP_EXPECT_MAX;
1352 sip[i][j].me = THIS_MODULE; 1539 sip[i][j].me = THIS_MODULE;
1353 sip[i][j].help = sip_help;
1354 1540
1355 tmpname = &sip_names[i][j][0]; 1541 tmpname = &sip_names[i][j][0];
1356 if (ports[i] == SIP_PORT) 1542 if (ports[i] == SIP_PORT)
diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c
index 193515381970..faa8eb3722b9 100644
--- a/net/netfilter/nf_conntrack_standalone.c
+++ b/net/netfilter/nf_conntrack_standalone.c
@@ -8,6 +8,7 @@
8 8
9#include <linux/types.h> 9#include <linux/types.h>
10#include <linux/netfilter.h> 10#include <linux/netfilter.h>
11#include <linux/slab.h>
11#include <linux/module.h> 12#include <linux/module.h>
12#include <linux/skbuff.h> 13#include <linux/skbuff.h>
13#include <linux/proc_fs.h> 14#include <linux/proc_fs.h>
@@ -26,6 +27,7 @@
26#include <net/netfilter/nf_conntrack_expect.h> 27#include <net/netfilter/nf_conntrack_expect.h>
27#include <net/netfilter/nf_conntrack_helper.h> 28#include <net/netfilter/nf_conntrack_helper.h>
28#include <net/netfilter/nf_conntrack_acct.h> 29#include <net/netfilter/nf_conntrack_acct.h>
30#include <net/netfilter/nf_conntrack_zones.h>
29 31
30MODULE_LICENSE("GPL"); 32MODULE_LICENSE("GPL");
31 33
@@ -51,7 +53,7 @@ static struct hlist_nulls_node *ct_get_first(struct seq_file *seq)
51 struct hlist_nulls_node *n; 53 struct hlist_nulls_node *n;
52 54
53 for (st->bucket = 0; 55 for (st->bucket = 0;
54 st->bucket < nf_conntrack_htable_size; 56 st->bucket < net->ct.htable_size;
55 st->bucket++) { 57 st->bucket++) {
56 n = rcu_dereference(net->ct.hash[st->bucket].first); 58 n = rcu_dereference(net->ct.hash[st->bucket].first);
57 if (!is_a_nulls(n)) 59 if (!is_a_nulls(n))
@@ -69,7 +71,7 @@ static struct hlist_nulls_node *ct_get_next(struct seq_file *seq,
69 head = rcu_dereference(head->next); 71 head = rcu_dereference(head->next);
70 while (is_a_nulls(head)) { 72 while (is_a_nulls(head)) {
71 if (likely(get_nulls_value(head) == st->bucket)) { 73 if (likely(get_nulls_value(head) == st->bucket)) {
72 if (++st->bucket >= nf_conntrack_htable_size) 74 if (++st->bucket >= net->ct.htable_size)
73 return NULL; 75 return NULL;
74 } 76 }
75 head = rcu_dereference(net->ct.hash[st->bucket].first); 77 head = rcu_dereference(net->ct.hash[st->bucket].first);
@@ -171,6 +173,11 @@ static int ct_seq_show(struct seq_file *s, void *v)
171 goto release; 173 goto release;
172#endif 174#endif
173 175
176#ifdef CONFIG_NF_CONNTRACK_ZONES
177 if (seq_printf(s, "zone=%u ", nf_ct_zone(ct)))
178 goto release;
179#endif
180
174 if (seq_printf(s, "use=%u\n", atomic_read(&ct->ct_general.use))) 181 if (seq_printf(s, "use=%u\n", atomic_read(&ct->ct_general.use)))
175 goto release; 182 goto release;
176 183
@@ -340,7 +347,6 @@ static struct ctl_table_header *nf_ct_netfilter_header;
340 347
341static ctl_table nf_ct_sysctl_table[] = { 348static ctl_table nf_ct_sysctl_table[] = {
342 { 349 {
343 .ctl_name = NET_NF_CONNTRACK_MAX,
344 .procname = "nf_conntrack_max", 350 .procname = "nf_conntrack_max",
345 .data = &nf_conntrack_max, 351 .data = &nf_conntrack_max,
346 .maxlen = sizeof(int), 352 .maxlen = sizeof(int),
@@ -348,7 +354,6 @@ static ctl_table nf_ct_sysctl_table[] = {
348 .proc_handler = proc_dointvec, 354 .proc_handler = proc_dointvec,
349 }, 355 },
350 { 356 {
351 .ctl_name = NET_NF_CONNTRACK_COUNT,
352 .procname = "nf_conntrack_count", 357 .procname = "nf_conntrack_count",
353 .data = &init_net.ct.count, 358 .data = &init_net.ct.count,
354 .maxlen = sizeof(int), 359 .maxlen = sizeof(int),
@@ -356,15 +361,13 @@ static ctl_table nf_ct_sysctl_table[] = {
356 .proc_handler = proc_dointvec, 361 .proc_handler = proc_dointvec,
357 }, 362 },
358 { 363 {
359 .ctl_name = NET_NF_CONNTRACK_BUCKETS,
360 .procname = "nf_conntrack_buckets", 364 .procname = "nf_conntrack_buckets",
361 .data = &nf_conntrack_htable_size, 365 .data = &init_net.ct.htable_size,
362 .maxlen = sizeof(unsigned int), 366 .maxlen = sizeof(unsigned int),
363 .mode = 0444, 367 .mode = 0444,
364 .proc_handler = proc_dointvec, 368 .proc_handler = proc_dointvec,
365 }, 369 },
366 { 370 {
367 .ctl_name = NET_NF_CONNTRACK_CHECKSUM,
368 .procname = "nf_conntrack_checksum", 371 .procname = "nf_conntrack_checksum",
369 .data = &init_net.ct.sysctl_checksum, 372 .data = &init_net.ct.sysctl_checksum,
370 .maxlen = sizeof(unsigned int), 373 .maxlen = sizeof(unsigned int),
@@ -372,43 +375,39 @@ static ctl_table nf_ct_sysctl_table[] = {
372 .proc_handler = proc_dointvec, 375 .proc_handler = proc_dointvec,
373 }, 376 },
374 { 377 {
375 .ctl_name = NET_NF_CONNTRACK_LOG_INVALID,
376 .procname = "nf_conntrack_log_invalid", 378 .procname = "nf_conntrack_log_invalid",
377 .data = &init_net.ct.sysctl_log_invalid, 379 .data = &init_net.ct.sysctl_log_invalid,
378 .maxlen = sizeof(unsigned int), 380 .maxlen = sizeof(unsigned int),
379 .mode = 0644, 381 .mode = 0644,
380 .proc_handler = proc_dointvec_minmax, 382 .proc_handler = proc_dointvec_minmax,
381 .strategy = sysctl_intvec,
382 .extra1 = &log_invalid_proto_min, 383 .extra1 = &log_invalid_proto_min,
383 .extra2 = &log_invalid_proto_max, 384 .extra2 = &log_invalid_proto_max,
384 }, 385 },
385 { 386 {
386 .ctl_name = CTL_UNNUMBERED,
387 .procname = "nf_conntrack_expect_max", 387 .procname = "nf_conntrack_expect_max",
388 .data = &nf_ct_expect_max, 388 .data = &nf_ct_expect_max,
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 { .ctl_name = 0 } 393 { }
394}; 394};
395 395
396#define NET_NF_CONNTRACK_MAX 2089 396#define NET_NF_CONNTRACK_MAX 2089
397 397
398static ctl_table nf_ct_netfilter_table[] = { 398static ctl_table nf_ct_netfilter_table[] = {
399 { 399 {
400 .ctl_name = NET_NF_CONNTRACK_MAX,
401 .procname = "nf_conntrack_max", 400 .procname = "nf_conntrack_max",
402 .data = &nf_conntrack_max, 401 .data = &nf_conntrack_max,
403 .maxlen = sizeof(int), 402 .maxlen = sizeof(int),
404 .mode = 0644, 403 .mode = 0644,
405 .proc_handler = proc_dointvec, 404 .proc_handler = proc_dointvec,
406 }, 405 },
407 { .ctl_name = 0 } 406 { }
408}; 407};
409 408
410static struct ctl_path nf_ct_path[] = { 409static struct ctl_path nf_ct_path[] = {
411 { .procname = "net", .ctl_name = CTL_NET, }, 410 { .procname = "net", },
412 { } 411 { }
413}; 412};
414 413
@@ -429,6 +428,7 @@ static int nf_conntrack_standalone_init_sysctl(struct net *net)
429 goto out_kmemdup; 428 goto out_kmemdup;
430 429
431 table[1].data = &net->ct.count; 430 table[1].data = &net->ct.count;
431 table[2].data = &net->ct.htable_size;
432 table[3].data = &net->ct.sysctl_checksum; 432 table[3].data = &net->ct.sysctl_checksum;
433 table[4].data = &net->ct.sysctl_log_invalid; 433 table[4].data = &net->ct.sysctl_log_invalid;
434 434
diff --git a/net/netfilter/nf_log.c b/net/netfilter/nf_log.c
index d65d3481919c..015725a5cd50 100644
--- a/net/netfilter/nf_log.c
+++ b/net/netfilter/nf_log.c
@@ -208,9 +208,9 @@ static const struct file_operations nflog_file_ops = {
208 208
209#ifdef CONFIG_SYSCTL 209#ifdef CONFIG_SYSCTL
210static struct ctl_path nf_log_sysctl_path[] = { 210static struct ctl_path nf_log_sysctl_path[] = {
211 { .procname = "net", .ctl_name = CTL_NET, }, 211 { .procname = "net", },
212 { .procname = "netfilter", .ctl_name = NET_NETFILTER, }, 212 { .procname = "netfilter", },
213 { .procname = "nf_log", .ctl_name = CTL_UNNUMBERED, }, 213 { .procname = "nf_log", },
214 { } 214 { }
215}; 215};
216 216
@@ -265,7 +265,6 @@ static __init int netfilter_log_sysctl_init(void)
265 265
266 for (i = NFPROTO_UNSPEC; i < NFPROTO_NUMPROTO; i++) { 266 for (i = NFPROTO_UNSPEC; i < NFPROTO_NUMPROTO; i++) {
267 snprintf(nf_log_sysctl_fnames[i-NFPROTO_UNSPEC], 3, "%d", i); 267 snprintf(nf_log_sysctl_fnames[i-NFPROTO_UNSPEC], 3, "%d", i);
268 nf_log_sysctl_table[i].ctl_name = CTL_UNNUMBERED;
269 nf_log_sysctl_table[i].procname = 268 nf_log_sysctl_table[i].procname =
270 nf_log_sysctl_fnames[i-NFPROTO_UNSPEC]; 269 nf_log_sysctl_fnames[i-NFPROTO_UNSPEC];
271 nf_log_sysctl_table[i].data = NULL; 270 nf_log_sysctl_table[i].data = NULL;
diff --git a/net/netfilter/nf_queue.c b/net/netfilter/nf_queue.c
index 3a6fd77f7761..c49ef219899e 100644
--- a/net/netfilter/nf_queue.c
+++ b/net/netfilter/nf_queue.c
@@ -1,4 +1,5 @@
1#include <linux/kernel.h> 1#include <linux/kernel.h>
2#include <linux/slab.h>
2#include <linux/init.h> 3#include <linux/init.h>
3#include <linux/module.h> 4#include <linux/module.h>
4#include <linux/proc_fs.h> 5#include <linux/proc_fs.h>
@@ -265,7 +266,6 @@ void nf_reinject(struct nf_queue_entry *entry, unsigned int verdict)
265 local_bh_disable(); 266 local_bh_disable();
266 entry->okfn(skb); 267 entry->okfn(skb);
267 local_bh_enable(); 268 local_bh_enable();
268 case NF_STOLEN:
269 break; 269 break;
270 case NF_QUEUE: 270 case NF_QUEUE:
271 if (!__nf_queue(skb, elem, entry->pf, entry->hook, 271 if (!__nf_queue(skb, elem, entry->pf, entry->hook,
@@ -273,6 +273,7 @@ void nf_reinject(struct nf_queue_entry *entry, unsigned int verdict)
273 verdict >> NF_VERDICT_BITS)) 273 verdict >> NF_VERDICT_BITS))
274 goto next_hook; 274 goto next_hook;
275 break; 275 break;
276 case NF_STOLEN:
276 default: 277 default:
277 kfree_skb(skb); 278 kfree_skb(skb);
278 } 279 }
diff --git a/net/netfilter/nfnetlink.c b/net/netfilter/nfnetlink.c
index eedc0c1ac7a4..6afa3d52ea5f 100644
--- a/net/netfilter/nfnetlink.c
+++ b/net/netfilter/nfnetlink.c
@@ -40,7 +40,6 @@ MODULE_ALIAS_NET_PF_PROTO(PF_NETLINK, NETLINK_NETFILTER);
40 40
41static char __initdata nfversion[] = "0.30"; 41static char __initdata nfversion[] = "0.30";
42 42
43static struct sock *nfnl = NULL;
44static const struct nfnetlink_subsystem *subsys_table[NFNL_SUBSYS_COUNT]; 43static const struct nfnetlink_subsystem *subsys_table[NFNL_SUBSYS_COUNT];
45static DEFINE_MUTEX(nfnl_mutex); 44static DEFINE_MUTEX(nfnl_mutex);
46 45
@@ -101,34 +100,35 @@ nfnetlink_find_client(u_int16_t type, const struct nfnetlink_subsystem *ss)
101 return &ss->cb[cb_id]; 100 return &ss->cb[cb_id];
102} 101}
103 102
104int nfnetlink_has_listeners(unsigned int group) 103int nfnetlink_has_listeners(struct net *net, unsigned int group)
105{ 104{
106 return netlink_has_listeners(nfnl, group); 105 return netlink_has_listeners(net->nfnl, group);
107} 106}
108EXPORT_SYMBOL_GPL(nfnetlink_has_listeners); 107EXPORT_SYMBOL_GPL(nfnetlink_has_listeners);
109 108
110int nfnetlink_send(struct sk_buff *skb, u32 pid, 109int nfnetlink_send(struct sk_buff *skb, struct net *net, u32 pid,
111 unsigned group, int echo, gfp_t flags) 110 unsigned group, int echo, gfp_t flags)
112{ 111{
113 return nlmsg_notify(nfnl, skb, pid, group, echo, flags); 112 return nlmsg_notify(net->nfnl, skb, pid, group, echo, flags);
114} 113}
115EXPORT_SYMBOL_GPL(nfnetlink_send); 114EXPORT_SYMBOL_GPL(nfnetlink_send);
116 115
117void nfnetlink_set_err(u32 pid, u32 group, int error) 116int nfnetlink_set_err(struct net *net, u32 pid, u32 group, int error)
118{ 117{
119 netlink_set_err(nfnl, pid, group, error); 118 return netlink_set_err(net->nfnl, pid, group, error);
120} 119}
121EXPORT_SYMBOL_GPL(nfnetlink_set_err); 120EXPORT_SYMBOL_GPL(nfnetlink_set_err);
122 121
123int nfnetlink_unicast(struct sk_buff *skb, u_int32_t pid, int flags) 122int nfnetlink_unicast(struct sk_buff *skb, struct net *net, u_int32_t pid, int flags)
124{ 123{
125 return netlink_unicast(nfnl, skb, pid, flags); 124 return netlink_unicast(net->nfnl, skb, pid, flags);
126} 125}
127EXPORT_SYMBOL_GPL(nfnetlink_unicast); 126EXPORT_SYMBOL_GPL(nfnetlink_unicast);
128 127
129/* Process one complete nfnetlink message. */ 128/* Process one complete nfnetlink message. */
130static int nfnetlink_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh) 129static int nfnetlink_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
131{ 130{
131 struct net *net = sock_net(skb->sk);
132 const struct nfnl_callback *nc; 132 const struct nfnl_callback *nc;
133 const struct nfnetlink_subsystem *ss; 133 const struct nfnetlink_subsystem *ss;
134 int type, err; 134 int type, err;
@@ -170,7 +170,7 @@ replay:
170 if (err < 0) 170 if (err < 0)
171 return err; 171 return err;
172 172
173 err = nc->call(nfnl, skb, nlh, (const struct nlattr **)cda); 173 err = nc->call(net->nfnl, skb, nlh, (const struct nlattr **)cda);
174 if (err == -EAGAIN) 174 if (err == -EAGAIN)
175 goto replay; 175 goto replay;
176 return err; 176 return err;
@@ -184,26 +184,45 @@ static void nfnetlink_rcv(struct sk_buff *skb)
184 nfnl_unlock(); 184 nfnl_unlock();
185} 185}
186 186
187static void __exit nfnetlink_exit(void) 187static int __net_init nfnetlink_net_init(struct net *net)
188{ 188{
189 printk("Removing netfilter NETLINK layer.\n"); 189 struct sock *nfnl;
190 netlink_kernel_release(nfnl); 190
191 return; 191 nfnl = netlink_kernel_create(net, NETLINK_NETFILTER, NFNLGRP_MAX,
192 nfnetlink_rcv, NULL, THIS_MODULE);
193 if (!nfnl)
194 return -ENOMEM;
195 net->nfnl_stash = nfnl;
196 rcu_assign_pointer(net->nfnl, nfnl);
197 return 0;
192} 198}
193 199
194static int __init nfnetlink_init(void) 200static void __net_exit nfnetlink_net_exit_batch(struct list_head *net_exit_list)
195{ 201{
196 printk("Netfilter messages via NETLINK v%s.\n", nfversion); 202 struct net *net;
197 203
198 nfnl = netlink_kernel_create(&init_net, NETLINK_NETFILTER, NFNLGRP_MAX, 204 list_for_each_entry(net, net_exit_list, exit_list)
199 nfnetlink_rcv, NULL, THIS_MODULE); 205 rcu_assign_pointer(net->nfnl, NULL);
200 if (!nfnl) { 206 synchronize_net();
201 printk(KERN_ERR "cannot initialize nfnetlink!\n"); 207 list_for_each_entry(net, net_exit_list, exit_list)
202 return -ENOMEM; 208 netlink_kernel_release(net->nfnl_stash);
203 } 209}
204 210
205 return 0; 211static struct pernet_operations nfnetlink_net_ops = {
212 .init = nfnetlink_net_init,
213 .exit_batch = nfnetlink_net_exit_batch,
214};
215
216static int __init nfnetlink_init(void)
217{
218 printk("Netfilter messages via NETLINK v%s.\n", nfversion);
219 return register_pernet_subsys(&nfnetlink_net_ops);
206} 220}
207 221
222static void __exit nfnetlink_exit(void)
223{
224 printk("Removing netfilter NETLINK layer.\n");
225 unregister_pernet_subsys(&nfnetlink_net_ops);
226}
208module_init(nfnetlink_init); 227module_init(nfnetlink_init);
209module_exit(nfnetlink_exit); 228module_exit(nfnetlink_exit);
diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
index f900dc3194af..203643fb2c52 100644
--- a/net/netfilter/nfnetlink_log.c
+++ b/net/netfilter/nfnetlink_log.c
@@ -28,6 +28,7 @@
28#include <linux/list.h> 28#include <linux/list.h>
29#include <linux/jhash.h> 29#include <linux/jhash.h>
30#include <linux/random.h> 30#include <linux/random.h>
31#include <linux/slab.h>
31#include <net/sock.h> 32#include <net/sock.h>
32#include <net/netfilter/nf_log.h> 33#include <net/netfilter/nf_log.h>
33#include <net/netfilter/nfnetlink_log.h> 34#include <net/netfilter/nfnetlink_log.h>
@@ -323,7 +324,8 @@ __nfulnl_send(struct nfulnl_instance *inst)
323 NLMSG_DONE, 324 NLMSG_DONE,
324 sizeof(struct nfgenmsg)); 325 sizeof(struct nfgenmsg));
325 326
326 status = nfnetlink_unicast(inst->skb, inst->peer_pid, MSG_DONTWAIT); 327 status = nfnetlink_unicast(inst->skb, &init_net, inst->peer_pid,
328 MSG_DONTWAIT);
327 329
328 inst->qlen = 0; 330 inst->qlen = 0;
329 inst->skb = NULL; 331 inst->skb = NULL;
@@ -666,8 +668,7 @@ nfulnl_rcv_nl_event(struct notifier_block *this,
666{ 668{
667 struct netlink_notify *n = ptr; 669 struct netlink_notify *n = ptr;
668 670
669 if (event == NETLINK_URELEASE && 671 if (event == NETLINK_URELEASE && n->protocol == NETLINK_NETFILTER) {
670 n->protocol == NETLINK_NETFILTER && n->pid) {
671 int i; 672 int i;
672 673
673 /* destroy all instances for this pid */ 674 /* destroy all instances for this pid */
@@ -678,7 +679,7 @@ nfulnl_rcv_nl_event(struct notifier_block *this,
678 struct hlist_head *head = &instance_table[i]; 679 struct hlist_head *head = &instance_table[i];
679 680
680 hlist_for_each_entry_safe(inst, tmp, t2, head, hlist) { 681 hlist_for_each_entry_safe(inst, tmp, t2, head, hlist) {
681 if ((n->net == &init_net) && 682 if ((net_eq(n->net, &init_net)) &&
682 (n->pid == inst->peer_pid)) 683 (n->pid == inst->peer_pid))
683 __instance_destroy(inst); 684 __instance_destroy(inst);
684 } 685 }
@@ -768,7 +769,7 @@ nfulnl_recv_config(struct sock *ctnl, struct sk_buff *skb,
768 } 769 }
769 770
770 instance_destroy(inst); 771 instance_destroy(inst);
771 goto out; 772 goto out_put;
772 default: 773 default:
773 ret = -ENOTSUPP; 774 ret = -ENOTSUPP;
774 break; 775 break;
diff --git a/net/netfilter/nfnetlink_queue.c b/net/netfilter/nfnetlink_queue.c
index 7a9dec9fb822..e70a6ef1f4f2 100644
--- a/net/netfilter/nfnetlink_queue.c
+++ b/net/netfilter/nfnetlink_queue.c
@@ -18,6 +18,7 @@
18#include <linux/skbuff.h> 18#include <linux/skbuff.h>
19#include <linux/init.h> 19#include <linux/init.h>
20#include <linux/spinlock.h> 20#include <linux/spinlock.h>
21#include <linux/slab.h>
21#include <linux/notifier.h> 22#include <linux/notifier.h>
22#include <linux/netdevice.h> 23#include <linux/netdevice.h>
23#include <linux/netfilter.h> 24#include <linux/netfilter.h>
@@ -112,7 +113,6 @@ instance_create(u_int16_t queue_num, int pid)
112 inst->copy_mode = NFQNL_COPY_NONE; 113 inst->copy_mode = NFQNL_COPY_NONE;
113 spin_lock_init(&inst->lock); 114 spin_lock_init(&inst->lock);
114 INIT_LIST_HEAD(&inst->queue_list); 115 INIT_LIST_HEAD(&inst->queue_list);
115 INIT_RCU_HEAD(&inst->rcu);
116 116
117 if (!try_module_get(THIS_MODULE)) { 117 if (!try_module_get(THIS_MODULE)) {
118 err = -EAGAIN; 118 err = -EAGAIN;
@@ -414,13 +414,13 @@ nfqnl_enqueue_packet(struct nf_queue_entry *entry, unsigned int queuenum)
414 queue->queue_dropped++; 414 queue->queue_dropped++;
415 if (net_ratelimit()) 415 if (net_ratelimit())
416 printk(KERN_WARNING "nf_queue: full at %d entries, " 416 printk(KERN_WARNING "nf_queue: full at %d entries, "
417 "dropping packets(s). Dropped: %d\n", 417 "dropping packets(s).\n",
418 queue->queue_total, queue->queue_dropped); 418 queue->queue_total);
419 goto err_out_free_nskb; 419 goto err_out_free_nskb;
420 } 420 }
421 421
422 /* nfnetlink_unicast will either free the nskb or add it to a socket */ 422 /* nfnetlink_unicast will either free the nskb or add it to a socket */
423 err = nfnetlink_unicast(nskb, queue->peer_pid, MSG_DONTWAIT); 423 err = nfnetlink_unicast(nskb, &init_net, queue->peer_pid, MSG_DONTWAIT);
424 if (err < 0) { 424 if (err < 0) {
425 queue->queue_user_dropped++; 425 queue->queue_user_dropped++;
426 goto err_out_unlock; 426 goto err_out_unlock;
@@ -574,8 +574,7 @@ nfqnl_rcv_nl_event(struct notifier_block *this,
574{ 574{
575 struct netlink_notify *n = ptr; 575 struct netlink_notify *n = ptr;
576 576
577 if (event == NETLINK_URELEASE && 577 if (event == NETLINK_URELEASE && n->protocol == NETLINK_NETFILTER) {
578 n->protocol == NETLINK_NETFILTER && n->pid) {
579 int i; 578 int i;
580 579
581 /* destroy all instances for this pid */ 580 /* destroy all instances for this pid */
diff --git a/net/netfilter/x_tables.c b/net/netfilter/x_tables.c
index f01955cce314..665f5beef6ad 100644
--- a/net/netfilter/x_tables.c
+++ b/net/netfilter/x_tables.c
@@ -22,11 +22,14 @@
22#include <linux/vmalloc.h> 22#include <linux/vmalloc.h>
23#include <linux/mutex.h> 23#include <linux/mutex.h>
24#include <linux/mm.h> 24#include <linux/mm.h>
25#include <linux/slab.h>
25#include <net/net_namespace.h> 26#include <net/net_namespace.h>
26 27
27#include <linux/netfilter/x_tables.h> 28#include <linux/netfilter/x_tables.h>
28#include <linux/netfilter_arp.h> 29#include <linux/netfilter_arp.h>
29 30#include <linux/netfilter_ipv4/ip_tables.h>
31#include <linux/netfilter_ipv6/ip6_tables.h>
32#include <linux/netfilter_arp/arp_tables.h>
30 33
31MODULE_LICENSE("GPL"); 34MODULE_LICENSE("GPL");
32MODULE_AUTHOR("Harald Welte <laforge@netfilter.org>"); 35MODULE_AUTHOR("Harald Welte <laforge@netfilter.org>");
@@ -37,7 +40,7 @@ MODULE_DESCRIPTION("{ip,ip6,arp,eb}_tables backend module");
37struct compat_delta { 40struct compat_delta {
38 struct compat_delta *next; 41 struct compat_delta *next;
39 unsigned int offset; 42 unsigned int offset;
40 short delta; 43 int delta;
41}; 44};
42 45
43struct xt_af { 46struct xt_af {
@@ -364,8 +367,10 @@ int xt_check_match(struct xt_mtchk_param *par,
364 * ebt_among is exempt from centralized matchsize checking 367 * ebt_among is exempt from centralized matchsize checking
365 * because it uses a dynamic-size data set. 368 * because it uses a dynamic-size data set.
366 */ 369 */
367 pr_err("%s_tables: %s match: invalid size %Zu != %u\n", 370 pr_err("%s_tables: %s.%u match: invalid size "
371 "%u (kernel) != (user) %u\n",
368 xt_prefix[par->family], par->match->name, 372 xt_prefix[par->family], par->match->name,
373 par->match->revision,
369 XT_ALIGN(par->match->matchsize), size); 374 XT_ALIGN(par->match->matchsize), size);
370 return -EINVAL; 375 return -EINVAL;
371 } 376 }
@@ -435,10 +440,10 @@ void xt_compat_flush_offsets(u_int8_t af)
435} 440}
436EXPORT_SYMBOL_GPL(xt_compat_flush_offsets); 441EXPORT_SYMBOL_GPL(xt_compat_flush_offsets);
437 442
438short xt_compat_calc_jump(u_int8_t af, unsigned int offset) 443int xt_compat_calc_jump(u_int8_t af, unsigned int offset)
439{ 444{
440 struct compat_delta *tmp; 445 struct compat_delta *tmp;
441 short delta; 446 int delta;
442 447
443 for (tmp = xt[af].compat_offsets, delta = 0; tmp; tmp = tmp->next) 448 for (tmp = xt[af].compat_offsets, delta = 0; tmp; tmp = tmp->next)
444 if (tmp->offset < offset) 449 if (tmp->offset < offset)
@@ -481,8 +486,8 @@ int xt_compat_match_from_user(struct xt_entry_match *m, void **dstptr,
481} 486}
482EXPORT_SYMBOL_GPL(xt_compat_match_from_user); 487EXPORT_SYMBOL_GPL(xt_compat_match_from_user);
483 488
484int xt_compat_match_to_user(struct xt_entry_match *m, void __user **dstptr, 489int xt_compat_match_to_user(const struct xt_entry_match *m,
485 unsigned int *size) 490 void __user **dstptr, unsigned int *size)
486{ 491{
487 const struct xt_match *match = m->u.kernel.match; 492 const struct xt_match *match = m->u.kernel.match;
488 struct compat_xt_entry_match __user *cm = *dstptr; 493 struct compat_xt_entry_match __user *cm = *dstptr;
@@ -514,8 +519,10 @@ int xt_check_target(struct xt_tgchk_param *par,
514 unsigned int size, u_int8_t proto, bool inv_proto) 519 unsigned int size, u_int8_t proto, bool inv_proto)
515{ 520{
516 if (XT_ALIGN(par->target->targetsize) != size) { 521 if (XT_ALIGN(par->target->targetsize) != size) {
517 pr_err("%s_tables: %s target: invalid size %Zu != %u\n", 522 pr_err("%s_tables: %s.%u target: invalid size "
523 "%u (kernel) != (user) %u\n",
518 xt_prefix[par->family], par->target->name, 524 xt_prefix[par->family], par->target->name,
525 par->target->revision,
519 XT_ALIGN(par->target->targetsize), size); 526 XT_ALIGN(par->target->targetsize), size);
520 return -EINVAL; 527 return -EINVAL;
521 } 528 }
@@ -582,8 +589,8 @@ void xt_compat_target_from_user(struct xt_entry_target *t, void **dstptr,
582} 589}
583EXPORT_SYMBOL_GPL(xt_compat_target_from_user); 590EXPORT_SYMBOL_GPL(xt_compat_target_from_user);
584 591
585int xt_compat_target_to_user(struct xt_entry_target *t, void __user **dstptr, 592int xt_compat_target_to_user(const struct xt_entry_target *t,
586 unsigned int *size) 593 void __user **dstptr, unsigned int *size)
587{ 594{
588 const struct xt_target *target = t->u.kernel.target; 595 const struct xt_target *target = t->u.kernel.target;
589 struct compat_xt_entry_target __user *ct = *dstptr; 596 struct compat_xt_entry_target __user *ct = *dstptr;
@@ -1091,6 +1098,60 @@ static const struct file_operations xt_target_ops = {
1091 1098
1092#endif /* CONFIG_PROC_FS */ 1099#endif /* CONFIG_PROC_FS */
1093 1100
1101/**
1102 * xt_hook_link - set up hooks for a new table
1103 * @table: table with metadata needed to set up hooks
1104 * @fn: Hook function
1105 *
1106 * This function will take care of creating and registering the necessary
1107 * Netfilter hooks for XT tables.
1108 */
1109struct nf_hook_ops *xt_hook_link(const struct xt_table *table, nf_hookfn *fn)
1110{
1111 unsigned int hook_mask = table->valid_hooks;
1112 uint8_t i, num_hooks = hweight32(hook_mask);
1113 uint8_t hooknum;
1114 struct nf_hook_ops *ops;
1115 int ret;
1116
1117 ops = kmalloc(sizeof(*ops) * num_hooks, GFP_KERNEL);
1118 if (ops == NULL)
1119 return ERR_PTR(-ENOMEM);
1120
1121 for (i = 0, hooknum = 0; i < num_hooks && hook_mask != 0;
1122 hook_mask >>= 1, ++hooknum) {
1123 if (!(hook_mask & 1))
1124 continue;
1125 ops[i].hook = fn;
1126 ops[i].owner = table->me;
1127 ops[i].pf = table->af;
1128 ops[i].hooknum = hooknum;
1129 ops[i].priority = table->priority;
1130 ++i;
1131 }
1132
1133 ret = nf_register_hooks(ops, num_hooks);
1134 if (ret < 0) {
1135 kfree(ops);
1136 return ERR_PTR(ret);
1137 }
1138
1139 return ops;
1140}
1141EXPORT_SYMBOL_GPL(xt_hook_link);
1142
1143/**
1144 * xt_hook_unlink - remove hooks for a table
1145 * @ops: nf_hook_ops array as returned by nf_hook_link
1146 * @hook_mask: the very same mask that was passed to nf_hook_link
1147 */
1148void xt_hook_unlink(const struct xt_table *table, struct nf_hook_ops *ops)
1149{
1150 nf_unregister_hooks(ops, hweight32(table->valid_hooks));
1151 kfree(ops);
1152}
1153EXPORT_SYMBOL_GPL(xt_hook_unlink);
1154
1094int xt_proto_init(struct net *net, u_int8_t af) 1155int xt_proto_init(struct net *net, u_int8_t af)
1095{ 1156{
1096#ifdef CONFIG_PROC_FS 1157#ifdef CONFIG_PROC_FS
diff --git a/net/netfilter/xt_CT.c b/net/netfilter/xt_CT.c
new file mode 100644
index 000000000000..ee18b231b950
--- /dev/null
+++ b/net/netfilter/xt_CT.c
@@ -0,0 +1,165 @@
1/*
2 * Copyright (c) 2010 Patrick McHardy <kaber@trash.net>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 */
8
9#include <linux/module.h>
10#include <linux/gfp.h>
11#include <linux/skbuff.h>
12#include <linux/selinux.h>
13#include <linux/netfilter_ipv4/ip_tables.h>
14#include <linux/netfilter_ipv6/ip6_tables.h>
15#include <linux/netfilter/x_tables.h>
16#include <linux/netfilter/xt_CT.h>
17#include <net/netfilter/nf_conntrack.h>
18#include <net/netfilter/nf_conntrack_helper.h>
19#include <net/netfilter/nf_conntrack_ecache.h>
20#include <net/netfilter/nf_conntrack_zones.h>
21
22static unsigned int xt_ct_target(struct sk_buff *skb,
23 const struct xt_target_param *par)
24{
25 const struct xt_ct_target_info *info = par->targinfo;
26 struct nf_conn *ct = info->ct;
27
28 /* Previously seen (loopback)? Ignore. */
29 if (skb->nfct != NULL)
30 return XT_CONTINUE;
31
32 atomic_inc(&ct->ct_general.use);
33 skb->nfct = &ct->ct_general;
34 skb->nfctinfo = IP_CT_NEW;
35
36 return XT_CONTINUE;
37}
38
39static u8 xt_ct_find_proto(const struct xt_tgchk_param *par)
40{
41 if (par->family == AF_INET) {
42 const struct ipt_entry *e = par->entryinfo;
43
44 if (e->ip.invflags & IPT_INV_PROTO)
45 return 0;
46 return e->ip.proto;
47 } else if (par->family == AF_INET6) {
48 const struct ip6t_entry *e = par->entryinfo;
49
50 if (e->ipv6.invflags & IP6T_INV_PROTO)
51 return 0;
52 return e->ipv6.proto;
53 } else
54 return 0;
55}
56
57static bool xt_ct_tg_check(const struct xt_tgchk_param *par)
58{
59 struct xt_ct_target_info *info = par->targinfo;
60 struct nf_conntrack_tuple t;
61 struct nf_conn_help *help;
62 struct nf_conn *ct;
63 u8 proto;
64
65 if (info->flags & ~XT_CT_NOTRACK)
66 return false;
67
68 if (info->flags & XT_CT_NOTRACK) {
69 ct = &nf_conntrack_untracked;
70 atomic_inc(&ct->ct_general.use);
71 goto out;
72 }
73
74#ifndef CONFIG_NF_CONNTRACK_ZONES
75 if (info->zone)
76 goto err1;
77#endif
78
79 if (nf_ct_l3proto_try_module_get(par->family) < 0)
80 goto err1;
81
82 memset(&t, 0, sizeof(t));
83 ct = nf_conntrack_alloc(par->net, info->zone, &t, &t, GFP_KERNEL);
84 if (IS_ERR(ct))
85 goto err2;
86
87 if ((info->ct_events || info->exp_events) &&
88 !nf_ct_ecache_ext_add(ct, info->ct_events, info->exp_events,
89 GFP_KERNEL))
90 goto err3;
91
92 if (info->helper[0]) {
93 proto = xt_ct_find_proto(par);
94 if (!proto)
95 goto err3;
96
97 help = nf_ct_helper_ext_add(ct, GFP_KERNEL);
98 if (help == NULL)
99 goto err3;
100
101 help->helper = nf_conntrack_helper_try_module_get(info->helper,
102 par->family,
103 proto);
104 if (help->helper == NULL)
105 goto err3;
106 }
107
108 __set_bit(IPS_TEMPLATE_BIT, &ct->status);
109 __set_bit(IPS_CONFIRMED_BIT, &ct->status);
110out:
111 info->ct = ct;
112 return true;
113
114err3:
115 nf_conntrack_free(ct);
116err2:
117 nf_ct_l3proto_module_put(par->family);
118err1:
119 return false;
120}
121
122static void xt_ct_tg_destroy(const struct xt_tgdtor_param *par)
123{
124 struct xt_ct_target_info *info = par->targinfo;
125 struct nf_conn *ct = info->ct;
126 struct nf_conn_help *help;
127
128 if (ct != &nf_conntrack_untracked) {
129 help = nfct_help(ct);
130 if (help)
131 module_put(help->helper->me);
132
133 nf_ct_l3proto_module_put(par->family);
134 }
135 nf_ct_put(info->ct);
136}
137
138static struct xt_target xt_ct_tg __read_mostly = {
139 .name = "CT",
140 .family = NFPROTO_UNSPEC,
141 .targetsize = XT_ALIGN(sizeof(struct xt_ct_target_info)),
142 .checkentry = xt_ct_tg_check,
143 .destroy = xt_ct_tg_destroy,
144 .target = xt_ct_target,
145 .table = "raw",
146 .me = THIS_MODULE,
147};
148
149static int __init xt_ct_tg_init(void)
150{
151 return xt_register_target(&xt_ct_tg);
152}
153
154static void __exit xt_ct_tg_exit(void)
155{
156 xt_unregister_target(&xt_ct_tg);
157}
158
159module_init(xt_ct_tg_init);
160module_exit(xt_ct_tg_exit);
161
162MODULE_LICENSE("GPL");
163MODULE_DESCRIPTION("Xtables: connection tracking target");
164MODULE_ALIAS("ipt_CT");
165MODULE_ALIAS("ip6t_CT");
diff --git a/net/netfilter/xt_LED.c b/net/netfilter/xt_LED.c
index 8ff7843bb921..3271c8e52153 100644
--- a/net/netfilter/xt_LED.c
+++ b/net/netfilter/xt_LED.c
@@ -22,6 +22,7 @@
22#include <linux/module.h> 22#include <linux/module.h>
23#include <linux/skbuff.h> 23#include <linux/skbuff.h>
24#include <linux/netfilter/x_tables.h> 24#include <linux/netfilter/x_tables.h>
25#include <linux/slab.h>
25#include <linux/leds.h> 26#include <linux/leds.h>
26#include <linux/mutex.h> 27#include <linux/mutex.h>
27 28
diff --git a/net/netfilter/xt_NFQUEUE.c b/net/netfilter/xt_NFQUEUE.c
index f28f6a5fc02d..12dcd7007c3e 100644
--- a/net/netfilter/xt_NFQUEUE.c
+++ b/net/netfilter/xt_NFQUEUE.c
@@ -28,6 +28,7 @@ MODULE_ALIAS("ip6t_NFQUEUE");
28MODULE_ALIAS("arpt_NFQUEUE"); 28MODULE_ALIAS("arpt_NFQUEUE");
29 29
30static u32 jhash_initval __read_mostly; 30static u32 jhash_initval __read_mostly;
31static bool rnd_inited __read_mostly;
31 32
32static unsigned int 33static unsigned int
33nfqueue_tg(struct sk_buff *skb, const struct xt_target_param *par) 34nfqueue_tg(struct sk_buff *skb, const struct xt_target_param *par)
@@ -90,6 +91,10 @@ static bool nfqueue_tg_v1_check(const struct xt_tgchk_param *par)
90 const struct xt_NFQ_info_v1 *info = par->targinfo; 91 const struct xt_NFQ_info_v1 *info = par->targinfo;
91 u32 maxid; 92 u32 maxid;
92 93
94 if (unlikely(!rnd_inited)) {
95 get_random_bytes(&jhash_initval, sizeof(jhash_initval));
96 rnd_inited = true;
97 }
93 if (info->queues_total == 0) { 98 if (info->queues_total == 0) {
94 pr_err("NFQUEUE: number of total queues is 0\n"); 99 pr_err("NFQUEUE: number of total queues is 0\n");
95 return false; 100 return false;
@@ -135,7 +140,6 @@ static struct xt_target nfqueue_tg_reg[] __read_mostly = {
135 140
136static int __init nfqueue_tg_init(void) 141static int __init nfqueue_tg_init(void)
137{ 142{
138 get_random_bytes(&jhash_initval, sizeof(jhash_initval));
139 return xt_register_targets(nfqueue_tg_reg, ARRAY_SIZE(nfqueue_tg_reg)); 143 return xt_register_targets(nfqueue_tg_reg, ARRAY_SIZE(nfqueue_tg_reg));
140} 144}
141 145
diff --git a/net/netfilter/xt_RATEEST.c b/net/netfilter/xt_RATEEST.c
index d80b8192e0d4..d16d55df4f61 100644
--- a/net/netfilter/xt_RATEEST.c
+++ b/net/netfilter/xt_RATEEST.c
@@ -11,6 +11,7 @@
11#include <linux/jhash.h> 11#include <linux/jhash.h>
12#include <linux/rtnetlink.h> 12#include <linux/rtnetlink.h>
13#include <linux/random.h> 13#include <linux/random.h>
14#include <linux/slab.h>
14#include <net/gen_stats.h> 15#include <net/gen_stats.h>
15#include <net/netlink.h> 16#include <net/netlink.h>
16 17
@@ -23,6 +24,7 @@ static DEFINE_MUTEX(xt_rateest_mutex);
23#define RATEEST_HSIZE 16 24#define RATEEST_HSIZE 16
24static struct hlist_head rateest_hash[RATEEST_HSIZE] __read_mostly; 25static struct hlist_head rateest_hash[RATEEST_HSIZE] __read_mostly;
25static unsigned int jhash_rnd __read_mostly; 26static unsigned int jhash_rnd __read_mostly;
27static bool rnd_inited __read_mostly;
26 28
27static unsigned int xt_rateest_hash(const char *name) 29static unsigned int xt_rateest_hash(const char *name)
28{ 30{
@@ -93,6 +95,11 @@ static bool xt_rateest_tg_checkentry(const struct xt_tgchk_param *par)
93 struct gnet_estimator est; 95 struct gnet_estimator est;
94 } cfg; 96 } cfg;
95 97
98 if (unlikely(!rnd_inited)) {
99 get_random_bytes(&jhash_rnd, sizeof(jhash_rnd));
100 rnd_inited = true;
101 }
102
96 est = xt_rateest_lookup(info->name); 103 est = xt_rateest_lookup(info->name);
97 if (est) { 104 if (est) {
98 /* 105 /*
@@ -164,7 +171,6 @@ static int __init xt_rateest_tg_init(void)
164 for (i = 0; i < ARRAY_SIZE(rateest_hash); i++) 171 for (i = 0; i < ARRAY_SIZE(rateest_hash); i++)
165 INIT_HLIST_HEAD(&rateest_hash[i]); 172 INIT_HLIST_HEAD(&rateest_hash[i]);
166 173
167 get_random_bytes(&jhash_rnd, sizeof(jhash_rnd));
168 return xt_register_target(&xt_rateest_tg_reg); 174 return xt_register_target(&xt_rateest_tg_reg);
169} 175}
170 176
diff --git a/net/netfilter/xt_TCPMSS.c b/net/netfilter/xt_TCPMSS.c
index eda64c1cb1e5..c5f4b9919e9a 100644
--- a/net/netfilter/xt_TCPMSS.c
+++ b/net/netfilter/xt_TCPMSS.c
@@ -11,6 +11,7 @@
11#include <linux/module.h> 11#include <linux/module.h>
12#include <linux/skbuff.h> 12#include <linux/skbuff.h>
13#include <linux/ip.h> 13#include <linux/ip.h>
14#include <linux/gfp.h>
14#include <linux/ipv6.h> 15#include <linux/ipv6.h>
15#include <linux/tcp.h> 16#include <linux/tcp.h>
16#include <net/dst.h> 17#include <net/dst.h>
@@ -60,17 +61,9 @@ tcpmss_mangle_packet(struct sk_buff *skb,
60 tcplen = skb->len - tcphoff; 61 tcplen = skb->len - tcphoff;
61 tcph = (struct tcphdr *)(skb_network_header(skb) + tcphoff); 62 tcph = (struct tcphdr *)(skb_network_header(skb) + tcphoff);
62 63
63 /* Since it passed flags test in tcp match, we know it is is 64 /* Header cannot be larger than the packet */
64 not a fragment, and has data >= tcp header length. SYN 65 if (tcplen < tcph->doff*4)
65 packets should not contain data: if they did, then we risk
66 running over MTU, sending Frag Needed and breaking things
67 badly. --RR */
68 if (tcplen != tcph->doff*4) {
69 if (net_ratelimit())
70 printk(KERN_ERR "xt_TCPMSS: bad length (%u bytes)\n",
71 skb->len);
72 return -1; 66 return -1;
73 }
74 67
75 if (info->mss == XT_TCPMSS_CLAMP_PMTU) { 68 if (info->mss == XT_TCPMSS_CLAMP_PMTU) {
76 if (dst_mtu(skb_dst(skb)) <= minlen) { 69 if (dst_mtu(skb_dst(skb)) <= minlen) {
@@ -115,6 +108,12 @@ tcpmss_mangle_packet(struct sk_buff *skb,
115 } 108 }
116 } 109 }
117 110
111 /* There is data after the header so the option can't be added
112 without moving it, and doing so may make the SYN packet
113 itself too large. Accept the packet unmodified instead. */
114 if (tcplen > tcph->doff*4)
115 return 0;
116
118 /* 117 /*
119 * MSS Option not found ?! add it.. 118 * MSS Option not found ?! add it..
120 */ 119 */
@@ -241,6 +240,7 @@ static bool tcpmss_tg4_check(const struct xt_tgchk_param *par)
241{ 240{
242 const struct xt_tcpmss_info *info = par->targinfo; 241 const struct xt_tcpmss_info *info = par->targinfo;
243 const struct ipt_entry *e = par->entryinfo; 242 const struct ipt_entry *e = par->entryinfo;
243 const struct xt_entry_match *ematch;
244 244
245 if (info->mss == XT_TCPMSS_CLAMP_PMTU && 245 if (info->mss == XT_TCPMSS_CLAMP_PMTU &&
246 (par->hook_mask & ~((1 << NF_INET_FORWARD) | 246 (par->hook_mask & ~((1 << NF_INET_FORWARD) |
@@ -250,8 +250,9 @@ static bool tcpmss_tg4_check(const struct xt_tgchk_param *par)
250 "FORWARD, OUTPUT and POSTROUTING hooks\n"); 250 "FORWARD, OUTPUT and POSTROUTING hooks\n");
251 return false; 251 return false;
252 } 252 }
253 if (IPT_MATCH_ITERATE(e, find_syn_match)) 253 xt_ematch_foreach(ematch, e)
254 return true; 254 if (find_syn_match(ematch))
255 return true;
255 printk("xt_TCPMSS: Only works on TCP SYN packets\n"); 256 printk("xt_TCPMSS: Only works on TCP SYN packets\n");
256 return false; 257 return false;
257} 258}
@@ -261,6 +262,7 @@ static bool tcpmss_tg6_check(const struct xt_tgchk_param *par)
261{ 262{
262 const struct xt_tcpmss_info *info = par->targinfo; 263 const struct xt_tcpmss_info *info = par->targinfo;
263 const struct ip6t_entry *e = par->entryinfo; 264 const struct ip6t_entry *e = par->entryinfo;
265 const struct xt_entry_match *ematch;
264 266
265 if (info->mss == XT_TCPMSS_CLAMP_PMTU && 267 if (info->mss == XT_TCPMSS_CLAMP_PMTU &&
266 (par->hook_mask & ~((1 << NF_INET_FORWARD) | 268 (par->hook_mask & ~((1 << NF_INET_FORWARD) |
@@ -270,8 +272,9 @@ static bool tcpmss_tg6_check(const struct xt_tgchk_param *par)
270 "FORWARD, OUTPUT and POSTROUTING hooks\n"); 272 "FORWARD, OUTPUT and POSTROUTING hooks\n");
271 return false; 273 return false;
272 } 274 }
273 if (IP6T_MATCH_ITERATE(e, find_syn_match)) 275 xt_ematch_foreach(ematch, e)
274 return true; 276 if (find_syn_match(ematch))
277 return true;
275 printk("xt_TCPMSS: Only works on TCP SYN packets\n"); 278 printk("xt_TCPMSS: Only works on TCP SYN packets\n");
276 return false; 279 return false;
277} 280}
diff --git a/net/netfilter/xt_connlimit.c b/net/netfilter/xt_connlimit.c
index 38f03f75a636..388ca4596098 100644
--- a/net/netfilter/xt_connlimit.c
+++ b/net/netfilter/xt_connlimit.c
@@ -17,6 +17,7 @@
17#include <linux/ip.h> 17#include <linux/ip.h>
18#include <linux/ipv6.h> 18#include <linux/ipv6.h>
19#include <linux/jhash.h> 19#include <linux/jhash.h>
20#include <linux/slab.h>
20#include <linux/list.h> 21#include <linux/list.h>
21#include <linux/module.h> 22#include <linux/module.h>
22#include <linux/random.h> 23#include <linux/random.h>
@@ -28,6 +29,7 @@
28#include <net/netfilter/nf_conntrack.h> 29#include <net/netfilter/nf_conntrack.h>
29#include <net/netfilter/nf_conntrack_core.h> 30#include <net/netfilter/nf_conntrack_core.h>
30#include <net/netfilter/nf_conntrack_tuple.h> 31#include <net/netfilter/nf_conntrack_tuple.h>
32#include <net/netfilter/nf_conntrack_zones.h>
31 33
32/* we will save the tuples of all connections we care about */ 34/* we will save the tuples of all connections we care about */
33struct xt_connlimit_conn { 35struct xt_connlimit_conn {
@@ -40,15 +42,11 @@ struct xt_connlimit_data {
40 spinlock_t lock; 42 spinlock_t lock;
41}; 43};
42 44
43static u_int32_t connlimit_rnd; 45static u_int32_t connlimit_rnd __read_mostly;
44static bool connlimit_rnd_inited; 46static bool connlimit_rnd_inited __read_mostly;
45 47
46static inline unsigned int connlimit_iphash(__be32 addr) 48static inline unsigned int connlimit_iphash(__be32 addr)
47{ 49{
48 if (unlikely(!connlimit_rnd_inited)) {
49 get_random_bytes(&connlimit_rnd, sizeof(connlimit_rnd));
50 connlimit_rnd_inited = true;
51 }
52 return jhash_1word((__force __u32)addr, connlimit_rnd) & 0xFF; 50 return jhash_1word((__force __u32)addr, connlimit_rnd) & 0xFF;
53} 51}
54 52
@@ -59,11 +57,6 @@ connlimit_iphash6(const union nf_inet_addr *addr,
59 union nf_inet_addr res; 57 union nf_inet_addr res;
60 unsigned int i; 58 unsigned int i;
61 59
62 if (unlikely(!connlimit_rnd_inited)) {
63 get_random_bytes(&connlimit_rnd, sizeof(connlimit_rnd));
64 connlimit_rnd_inited = true;
65 }
66
67 for (i = 0; i < ARRAY_SIZE(addr->ip6); ++i) 60 for (i = 0; i < ARRAY_SIZE(addr->ip6); ++i)
68 res.ip6[i] = addr->ip6[i] & mask->ip6[i]; 61 res.ip6[i] = addr->ip6[i] & mask->ip6[i];
69 62
@@ -99,7 +92,8 @@ same_source_net(const union nf_inet_addr *addr,
99 } 92 }
100} 93}
101 94
102static int count_them(struct xt_connlimit_data *data, 95static int count_them(struct net *net,
96 struct xt_connlimit_data *data,
103 const struct nf_conntrack_tuple *tuple, 97 const struct nf_conntrack_tuple *tuple,
104 const union nf_inet_addr *addr, 98 const union nf_inet_addr *addr,
105 const union nf_inet_addr *mask, 99 const union nf_inet_addr *mask,
@@ -122,7 +116,8 @@ static int count_them(struct xt_connlimit_data *data,
122 116
123 /* check the saved connections */ 117 /* check the saved connections */
124 list_for_each_entry_safe(conn, tmp, hash, list) { 118 list_for_each_entry_safe(conn, tmp, hash, list) {
125 found = nf_conntrack_find_get(&init_net, &conn->tuple); 119 found = nf_conntrack_find_get(net, NF_CT_DEFAULT_ZONE,
120 &conn->tuple);
126 found_ct = NULL; 121 found_ct = NULL;
127 122
128 if (found != NULL) 123 if (found != NULL)
@@ -180,6 +175,7 @@ static int count_them(struct xt_connlimit_data *data,
180static bool 175static bool
181connlimit_mt(const struct sk_buff *skb, const struct xt_match_param *par) 176connlimit_mt(const struct sk_buff *skb, const struct xt_match_param *par)
182{ 177{
178 struct net *net = dev_net(par->in ? par->in : par->out);
183 const struct xt_connlimit_info *info = par->matchinfo; 179 const struct xt_connlimit_info *info = par->matchinfo;
184 union nf_inet_addr addr; 180 union nf_inet_addr addr;
185 struct nf_conntrack_tuple tuple; 181 struct nf_conntrack_tuple tuple;
@@ -204,7 +200,7 @@ connlimit_mt(const struct sk_buff *skb, const struct xt_match_param *par)
204 } 200 }
205 201
206 spin_lock_bh(&info->data->lock); 202 spin_lock_bh(&info->data->lock);
207 connections = count_them(info->data, tuple_ptr, &addr, 203 connections = count_them(net, info->data, tuple_ptr, &addr,
208 &info->mask, par->family); 204 &info->mask, par->family);
209 spin_unlock_bh(&info->data->lock); 205 spin_unlock_bh(&info->data->lock);
210 206
@@ -226,6 +222,10 @@ static bool connlimit_mt_check(const struct xt_mtchk_param *par)
226 struct xt_connlimit_info *info = par->matchinfo; 222 struct xt_connlimit_info *info = par->matchinfo;
227 unsigned int i; 223 unsigned int i;
228 224
225 if (unlikely(!connlimit_rnd_inited)) {
226 get_random_bytes(&connlimit_rnd, sizeof(connlimit_rnd));
227 connlimit_rnd_inited = true;
228 }
229 if (nf_ct_l3proto_try_module_get(par->family) < 0) { 229 if (nf_ct_l3proto_try_module_get(par->family) < 0) {
230 printk(KERN_WARNING "cannot load conntrack support for " 230 printk(KERN_WARNING "cannot load conntrack support for "
231 "address family %u\n", par->family); 231 "address family %u\n", par->family);
diff --git a/net/netfilter/xt_conntrack.c b/net/netfilter/xt_conntrack.c
index 6dc4652f2fe8..ae66305f0fe5 100644
--- a/net/netfilter/xt_conntrack.c
+++ b/net/netfilter/xt_conntrack.c
@@ -113,7 +113,8 @@ ct_proto_port_check(const struct xt_conntrack_mtinfo2 *info,
113} 113}
114 114
115static bool 115static bool
116conntrack_mt(const struct sk_buff *skb, const struct xt_match_param *par) 116conntrack_mt(const struct sk_buff *skb, const struct xt_match_param *par,
117 u16 state_mask, u16 status_mask)
117{ 118{
118 const struct xt_conntrack_mtinfo2 *info = par->matchinfo; 119 const struct xt_conntrack_mtinfo2 *info = par->matchinfo;
119 enum ip_conntrack_info ctinfo; 120 enum ip_conntrack_info ctinfo;
@@ -136,7 +137,7 @@ conntrack_mt(const struct sk_buff *skb, const struct xt_match_param *par)
136 if (test_bit(IPS_DST_NAT_BIT, &ct->status)) 137 if (test_bit(IPS_DST_NAT_BIT, &ct->status))
137 statebit |= XT_CONNTRACK_STATE_DNAT; 138 statebit |= XT_CONNTRACK_STATE_DNAT;
138 } 139 }
139 if (!!(info->state_mask & statebit) ^ 140 if (!!(state_mask & statebit) ^
140 !(info->invert_flags & XT_CONNTRACK_STATE)) 141 !(info->invert_flags & XT_CONNTRACK_STATE))
141 return false; 142 return false;
142 } 143 }
@@ -172,7 +173,7 @@ conntrack_mt(const struct sk_buff *skb, const struct xt_match_param *par)
172 return false; 173 return false;
173 174
174 if ((info->match_flags & XT_CONNTRACK_STATUS) && 175 if ((info->match_flags & XT_CONNTRACK_STATUS) &&
175 (!!(info->status_mask & ct->status) ^ 176 (!!(status_mask & ct->status) ^
176 !(info->invert_flags & XT_CONNTRACK_STATUS))) 177 !(info->invert_flags & XT_CONNTRACK_STATUS)))
177 return false; 178 return false;
178 179
@@ -192,11 +193,17 @@ conntrack_mt(const struct sk_buff *skb, const struct xt_match_param *par)
192static bool 193static bool
193conntrack_mt_v1(const struct sk_buff *skb, const struct xt_match_param *par) 194conntrack_mt_v1(const struct sk_buff *skb, const struct xt_match_param *par)
194{ 195{
195 const struct xt_conntrack_mtinfo2 *const *info = par->matchinfo; 196 const struct xt_conntrack_mtinfo1 *info = par->matchinfo;
196 struct xt_match_param newpar = *par;
197 197
198 newpar.matchinfo = *info; 198 return conntrack_mt(skb, par, info->state_mask, info->status_mask);
199 return conntrack_mt(skb, &newpar); 199}
200
201static bool
202conntrack_mt_v2(const struct sk_buff *skb, const struct xt_match_param *par)
203{
204 const struct xt_conntrack_mtinfo2 *info = par->matchinfo;
205
206 return conntrack_mt(skb, par, info->state_mask, info->status_mask);
200} 207}
201 208
202static bool conntrack_mt_check(const struct xt_mtchk_param *par) 209static bool conntrack_mt_check(const struct xt_mtchk_param *par)
@@ -209,45 +216,11 @@ static bool conntrack_mt_check(const struct xt_mtchk_param *par)
209 return true; 216 return true;
210} 217}
211 218
212static bool conntrack_mt_check_v1(const struct xt_mtchk_param *par)
213{
214 struct xt_conntrack_mtinfo1 *info = par->matchinfo;
215 struct xt_conntrack_mtinfo2 *up;
216 int ret = conntrack_mt_check(par);
217
218 if (ret < 0)
219 return ret;
220
221 up = kmalloc(sizeof(*up), GFP_KERNEL);
222 if (up == NULL) {
223 nf_ct_l3proto_module_put(par->family);
224 return -ENOMEM;
225 }
226
227 /*
228 * The strategy here is to minimize the overhead of v1 matching,
229 * by prebuilding a v2 struct and putting the pointer into the
230 * v1 dataspace.
231 */
232 memcpy(up, info, offsetof(typeof(*info), state_mask));
233 up->state_mask = info->state_mask;
234 up->status_mask = info->status_mask;
235 *(void **)info = up;
236 return true;
237}
238
239static void conntrack_mt_destroy(const struct xt_mtdtor_param *par) 219static void conntrack_mt_destroy(const struct xt_mtdtor_param *par)
240{ 220{
241 nf_ct_l3proto_module_put(par->family); 221 nf_ct_l3proto_module_put(par->family);
242} 222}
243 223
244static void conntrack_mt_destroy_v1(const struct xt_mtdtor_param *par)
245{
246 struct xt_conntrack_mtinfo2 **info = par->matchinfo;
247 kfree(*info);
248 conntrack_mt_destroy(par);
249}
250
251static struct xt_match conntrack_mt_reg[] __read_mostly = { 224static struct xt_match conntrack_mt_reg[] __read_mostly = {
252 { 225 {
253 .name = "conntrack", 226 .name = "conntrack",
@@ -255,8 +228,8 @@ static struct xt_match conntrack_mt_reg[] __read_mostly = {
255 .family = NFPROTO_UNSPEC, 228 .family = NFPROTO_UNSPEC,
256 .matchsize = sizeof(struct xt_conntrack_mtinfo1), 229 .matchsize = sizeof(struct xt_conntrack_mtinfo1),
257 .match = conntrack_mt_v1, 230 .match = conntrack_mt_v1,
258 .checkentry = conntrack_mt_check_v1, 231 .checkentry = conntrack_mt_check,
259 .destroy = conntrack_mt_destroy_v1, 232 .destroy = conntrack_mt_destroy,
260 .me = THIS_MODULE, 233 .me = THIS_MODULE,
261 }, 234 },
262 { 235 {
@@ -264,7 +237,7 @@ static struct xt_match conntrack_mt_reg[] __read_mostly = {
264 .revision = 2, 237 .revision = 2,
265 .family = NFPROTO_UNSPEC, 238 .family = NFPROTO_UNSPEC,
266 .matchsize = sizeof(struct xt_conntrack_mtinfo2), 239 .matchsize = sizeof(struct xt_conntrack_mtinfo2),
267 .match = conntrack_mt, 240 .match = conntrack_mt_v2,
268 .checkentry = conntrack_mt_check, 241 .checkentry = conntrack_mt_check,
269 .destroy = conntrack_mt_destroy, 242 .destroy = conntrack_mt_destroy,
270 .me = THIS_MODULE, 243 .me = THIS_MODULE,
diff --git a/net/netfilter/xt_dccp.c b/net/netfilter/xt_dccp.c
index 0989f29ade2e..395af5943ffd 100644
--- a/net/netfilter/xt_dccp.c
+++ b/net/netfilter/xt_dccp.c
@@ -10,6 +10,7 @@
10 10
11#include <linux/module.h> 11#include <linux/module.h>
12#include <linux/skbuff.h> 12#include <linux/skbuff.h>
13#include <linux/slab.h>
13#include <linux/spinlock.h> 14#include <linux/spinlock.h>
14#include <net/ip.h> 15#include <net/ip.h>
15#include <linux/dccp.h> 16#include <linux/dccp.h>
diff --git a/net/netfilter/xt_hashlimit.c b/net/netfilter/xt_hashlimit.c
index dd16e404424f..215a64835de8 100644
--- a/net/netfilter/xt_hashlimit.c
+++ b/net/netfilter/xt_hashlimit.c
@@ -1,6 +1,6 @@
1/* 1/*
2 * xt_hashlimit - Netfilter module to limit the number of packets per time 2 * xt_hashlimit - Netfilter module to limit the number of packets per time
3 * seperately for each hashbucket (sourceip/sourceport/dstip/dstport) 3 * separately for each hashbucket (sourceip/sourceport/dstip/dstport)
4 * 4 *
5 * (C) 2003-2004 by Harald Welte <laforge@netfilter.org> 5 * (C) 2003-2004 by Harald Welte <laforge@netfilter.org>
6 * Copyright © CC Computer Consultants GmbH, 2007 - 2008 6 * Copyright © CC Computer Consultants GmbH, 2007 - 2008
@@ -26,6 +26,7 @@
26#endif 26#endif
27 27
28#include <net/net_namespace.h> 28#include <net/net_namespace.h>
29#include <net/netns/generic.h>
29 30
30#include <linux/netfilter/x_tables.h> 31#include <linux/netfilter/x_tables.h>
31#include <linux/netfilter_ipv4/ip_tables.h> 32#include <linux/netfilter_ipv4/ip_tables.h>
@@ -40,9 +41,19 @@ MODULE_DESCRIPTION("Xtables: per hash-bucket rate-limit match");
40MODULE_ALIAS("ipt_hashlimit"); 41MODULE_ALIAS("ipt_hashlimit");
41MODULE_ALIAS("ip6t_hashlimit"); 42MODULE_ALIAS("ip6t_hashlimit");
42 43
44struct hashlimit_net {
45 struct hlist_head htables;
46 struct proc_dir_entry *ipt_hashlimit;
47 struct proc_dir_entry *ip6t_hashlimit;
48};
49
50static int hashlimit_net_id;
51static inline struct hashlimit_net *hashlimit_pernet(struct net *net)
52{
53 return net_generic(net, hashlimit_net_id);
54}
55
43/* need to declare this at the top */ 56/* need to declare this at the top */
44static struct proc_dir_entry *hashlimit_procdir4;
45static struct proc_dir_entry *hashlimit_procdir6;
46static const struct file_operations dl_file_ops; 57static const struct file_operations dl_file_ops;
47 58
48/* hash table crap */ 59/* hash table crap */
@@ -79,27 +90,26 @@ struct dsthash_ent {
79 90
80struct xt_hashlimit_htable { 91struct xt_hashlimit_htable {
81 struct hlist_node node; /* global list of all htables */ 92 struct hlist_node node; /* global list of all htables */
82 atomic_t use; 93 int use;
83 u_int8_t family; 94 u_int8_t family;
95 bool rnd_initialized;
84 96
85 struct hashlimit_cfg1 cfg; /* config */ 97 struct hashlimit_cfg1 cfg; /* config */
86 98
87 /* used internally */ 99 /* used internally */
88 spinlock_t lock; /* lock for list_head */ 100 spinlock_t lock; /* lock for list_head */
89 u_int32_t rnd; /* random seed for hash */ 101 u_int32_t rnd; /* random seed for hash */
90 int rnd_initialized;
91 unsigned int count; /* number entries in table */ 102 unsigned int count; /* number entries in table */
92 struct timer_list timer; /* timer for gc */ 103 struct timer_list timer; /* timer for gc */
93 104
94 /* seq_file stuff */ 105 /* seq_file stuff */
95 struct proc_dir_entry *pde; 106 struct proc_dir_entry *pde;
107 struct net *net;
96 108
97 struct hlist_head hash[0]; /* hashtable itself */ 109 struct hlist_head hash[0]; /* hashtable itself */
98}; 110};
99 111
100static DEFINE_SPINLOCK(hashlimit_lock); /* protects htables list */ 112static DEFINE_MUTEX(hashlimit_mutex); /* protects htables list */
101static DEFINE_MUTEX(hlimit_mutex); /* additional checkentry protection */
102static HLIST_HEAD(hashlimit_htables);
103static struct kmem_cache *hashlimit_cachep __read_mostly; 113static struct kmem_cache *hashlimit_cachep __read_mostly;
104 114
105static inline bool dst_cmp(const struct dsthash_ent *ent, 115static inline bool dst_cmp(const struct dsthash_ent *ent,
@@ -150,7 +160,7 @@ dsthash_alloc_init(struct xt_hashlimit_htable *ht,
150 * the first hashtable entry */ 160 * the first hashtable entry */
151 if (!ht->rnd_initialized) { 161 if (!ht->rnd_initialized) {
152 get_random_bytes(&ht->rnd, sizeof(ht->rnd)); 162 get_random_bytes(&ht->rnd, sizeof(ht->rnd));
153 ht->rnd_initialized = 1; 163 ht->rnd_initialized = true;
154 } 164 }
155 165
156 if (ht->cfg.max && ht->count >= ht->cfg.max) { 166 if (ht->cfg.max && ht->count >= ht->cfg.max) {
@@ -185,8 +195,9 @@ dsthash_free(struct xt_hashlimit_htable *ht, struct dsthash_ent *ent)
185} 195}
186static void htable_gc(unsigned long htlong); 196static void htable_gc(unsigned long htlong);
187 197
188static int htable_create_v0(struct xt_hashlimit_info *minfo, u_int8_t family) 198static int htable_create_v0(struct net *net, struct xt_hashlimit_info *minfo, u_int8_t family)
189{ 199{
200 struct hashlimit_net *hashlimit_net = hashlimit_pernet(net);
190 struct xt_hashlimit_htable *hinfo; 201 struct xt_hashlimit_htable *hinfo;
191 unsigned int size; 202 unsigned int size;
192 unsigned int i; 203 unsigned int i;
@@ -232,33 +243,34 @@ static int htable_create_v0(struct xt_hashlimit_info *minfo, u_int8_t family)
232 for (i = 0; i < hinfo->cfg.size; i++) 243 for (i = 0; i < hinfo->cfg.size; i++)
233 INIT_HLIST_HEAD(&hinfo->hash[i]); 244 INIT_HLIST_HEAD(&hinfo->hash[i]);
234 245
235 atomic_set(&hinfo->use, 1); 246 hinfo->use = 1;
236 hinfo->count = 0; 247 hinfo->count = 0;
237 hinfo->family = family; 248 hinfo->family = family;
238 hinfo->rnd_initialized = 0; 249 hinfo->rnd_initialized = false;
239 spin_lock_init(&hinfo->lock); 250 spin_lock_init(&hinfo->lock);
240 hinfo->pde = proc_create_data(minfo->name, 0, 251 hinfo->pde = proc_create_data(minfo->name, 0,
241 (family == NFPROTO_IPV4) ? 252 (family == NFPROTO_IPV4) ?
242 hashlimit_procdir4 : hashlimit_procdir6, 253 hashlimit_net->ipt_hashlimit : hashlimit_net->ip6t_hashlimit,
243 &dl_file_ops, hinfo); 254 &dl_file_ops, hinfo);
244 if (!hinfo->pde) { 255 if (!hinfo->pde) {
245 vfree(hinfo); 256 vfree(hinfo);
246 return -1; 257 return -1;
247 } 258 }
259 hinfo->net = net;
248 260
249 setup_timer(&hinfo->timer, htable_gc, (unsigned long )hinfo); 261 setup_timer(&hinfo->timer, htable_gc, (unsigned long )hinfo);
250 hinfo->timer.expires = jiffies + msecs_to_jiffies(hinfo->cfg.gc_interval); 262 hinfo->timer.expires = jiffies + msecs_to_jiffies(hinfo->cfg.gc_interval);
251 add_timer(&hinfo->timer); 263 add_timer(&hinfo->timer);
252 264
253 spin_lock_bh(&hashlimit_lock); 265 hlist_add_head(&hinfo->node, &hashlimit_net->htables);
254 hlist_add_head(&hinfo->node, &hashlimit_htables);
255 spin_unlock_bh(&hashlimit_lock);
256 266
257 return 0; 267 return 0;
258} 268}
259 269
260static int htable_create(struct xt_hashlimit_mtinfo1 *minfo, u_int8_t family) 270static int htable_create(struct net *net, struct xt_hashlimit_mtinfo1 *minfo,
271 u_int8_t family)
261{ 272{
273 struct hashlimit_net *hashlimit_net = hashlimit_pernet(net);
262 struct xt_hashlimit_htable *hinfo; 274 struct xt_hashlimit_htable *hinfo;
263 unsigned int size; 275 unsigned int size;
264 unsigned int i; 276 unsigned int i;
@@ -293,28 +305,27 @@ static int htable_create(struct xt_hashlimit_mtinfo1 *minfo, u_int8_t family)
293 for (i = 0; i < hinfo->cfg.size; i++) 305 for (i = 0; i < hinfo->cfg.size; i++)
294 INIT_HLIST_HEAD(&hinfo->hash[i]); 306 INIT_HLIST_HEAD(&hinfo->hash[i]);
295 307
296 atomic_set(&hinfo->use, 1); 308 hinfo->use = 1;
297 hinfo->count = 0; 309 hinfo->count = 0;
298 hinfo->family = family; 310 hinfo->family = family;
299 hinfo->rnd_initialized = 0; 311 hinfo->rnd_initialized = false;
300 spin_lock_init(&hinfo->lock); 312 spin_lock_init(&hinfo->lock);
301 313
302 hinfo->pde = proc_create_data(minfo->name, 0, 314 hinfo->pde = proc_create_data(minfo->name, 0,
303 (family == NFPROTO_IPV4) ? 315 (family == NFPROTO_IPV4) ?
304 hashlimit_procdir4 : hashlimit_procdir6, 316 hashlimit_net->ipt_hashlimit : hashlimit_net->ip6t_hashlimit,
305 &dl_file_ops, hinfo); 317 &dl_file_ops, hinfo);
306 if (hinfo->pde == NULL) { 318 if (hinfo->pde == NULL) {
307 vfree(hinfo); 319 vfree(hinfo);
308 return -1; 320 return -1;
309 } 321 }
322 hinfo->net = net;
310 323
311 setup_timer(&hinfo->timer, htable_gc, (unsigned long)hinfo); 324 setup_timer(&hinfo->timer, htable_gc, (unsigned long)hinfo);
312 hinfo->timer.expires = jiffies + msecs_to_jiffies(hinfo->cfg.gc_interval); 325 hinfo->timer.expires = jiffies + msecs_to_jiffies(hinfo->cfg.gc_interval);
313 add_timer(&hinfo->timer); 326 add_timer(&hinfo->timer);
314 327
315 spin_lock_bh(&hashlimit_lock); 328 hlist_add_head(&hinfo->node, &hashlimit_net->htables);
316 hlist_add_head(&hinfo->node, &hashlimit_htables);
317 spin_unlock_bh(&hashlimit_lock);
318 329
319 return 0; 330 return 0;
320} 331}
@@ -364,43 +375,46 @@ static void htable_gc(unsigned long htlong)
364 375
365static void htable_destroy(struct xt_hashlimit_htable *hinfo) 376static void htable_destroy(struct xt_hashlimit_htable *hinfo)
366{ 377{
378 struct hashlimit_net *hashlimit_net = hashlimit_pernet(hinfo->net);
379 struct proc_dir_entry *parent;
380
367 del_timer_sync(&hinfo->timer); 381 del_timer_sync(&hinfo->timer);
368 382
369 /* remove proc entry */ 383 if (hinfo->family == NFPROTO_IPV4)
370 remove_proc_entry(hinfo->pde->name, 384 parent = hashlimit_net->ipt_hashlimit;
371 hinfo->family == NFPROTO_IPV4 ? hashlimit_procdir4 : 385 else
372 hashlimit_procdir6); 386 parent = hashlimit_net->ip6t_hashlimit;
387 remove_proc_entry(hinfo->pde->name, parent);
373 htable_selective_cleanup(hinfo, select_all); 388 htable_selective_cleanup(hinfo, select_all);
374 vfree(hinfo); 389 vfree(hinfo);
375} 390}
376 391
377static struct xt_hashlimit_htable *htable_find_get(const char *name, 392static struct xt_hashlimit_htable *htable_find_get(struct net *net,
393 const char *name,
378 u_int8_t family) 394 u_int8_t family)
379{ 395{
396 struct hashlimit_net *hashlimit_net = hashlimit_pernet(net);
380 struct xt_hashlimit_htable *hinfo; 397 struct xt_hashlimit_htable *hinfo;
381 struct hlist_node *pos; 398 struct hlist_node *pos;
382 399
383 spin_lock_bh(&hashlimit_lock); 400 hlist_for_each_entry(hinfo, pos, &hashlimit_net->htables, node) {
384 hlist_for_each_entry(hinfo, pos, &hashlimit_htables, node) {
385 if (!strcmp(name, hinfo->pde->name) && 401 if (!strcmp(name, hinfo->pde->name) &&
386 hinfo->family == family) { 402 hinfo->family == family) {
387 atomic_inc(&hinfo->use); 403 hinfo->use++;
388 spin_unlock_bh(&hashlimit_lock);
389 return hinfo; 404 return hinfo;
390 } 405 }
391 } 406 }
392 spin_unlock_bh(&hashlimit_lock);
393 return NULL; 407 return NULL;
394} 408}
395 409
396static void htable_put(struct xt_hashlimit_htable *hinfo) 410static void htable_put(struct xt_hashlimit_htable *hinfo)
397{ 411{
398 if (atomic_dec_and_test(&hinfo->use)) { 412 mutex_lock(&hashlimit_mutex);
399 spin_lock_bh(&hashlimit_lock); 413 if (--hinfo->use == 0) {
400 hlist_del(&hinfo->node); 414 hlist_del(&hinfo->node);
401 spin_unlock_bh(&hashlimit_lock);
402 htable_destroy(hinfo); 415 htable_destroy(hinfo);
403 } 416 }
417 mutex_unlock(&hashlimit_mutex);
404} 418}
405 419
406/* The algorithm used is the Simple Token Bucket Filter (TBF) 420/* The algorithm used is the Simple Token Bucket Filter (TBF)
@@ -479,6 +493,7 @@ static void hashlimit_ipv6_mask(__be32 *i, unsigned int p)
479 case 64 ... 95: 493 case 64 ... 95:
480 i[2] = maskl(i[2], p - 64); 494 i[2] = maskl(i[2], p - 64);
481 i[3] = 0; 495 i[3] = 0;
496 break;
482 case 96 ... 127: 497 case 96 ... 127:
483 i[3] = maskl(i[3], p - 96); 498 i[3] = maskl(i[3], p - 96);
484 break; 499 break;
@@ -665,6 +680,7 @@ hashlimit_mt(const struct sk_buff *skb, const struct xt_match_param *par)
665 680
666static bool hashlimit_mt_check_v0(const struct xt_mtchk_param *par) 681static bool hashlimit_mt_check_v0(const struct xt_mtchk_param *par)
667{ 682{
683 struct net *net = par->net;
668 struct xt_hashlimit_info *r = par->matchinfo; 684 struct xt_hashlimit_info *r = par->matchinfo;
669 685
670 /* Check for overflow. */ 686 /* Check for overflow. */
@@ -687,25 +703,20 @@ static bool hashlimit_mt_check_v0(const struct xt_mtchk_param *par)
687 if (r->name[sizeof(r->name) - 1] != '\0') 703 if (r->name[sizeof(r->name) - 1] != '\0')
688 return false; 704 return false;
689 705
690 /* This is the best we've got: We cannot release and re-grab lock, 706 mutex_lock(&hashlimit_mutex);
691 * since checkentry() is called before x_tables.c grabs xt_mutex. 707 r->hinfo = htable_find_get(net, r->name, par->match->family);
692 * We also cannot grab the hashtable spinlock, since htable_create will 708 if (!r->hinfo && htable_create_v0(net, r, par->match->family) != 0) {
693 * call vmalloc, and that can sleep. And we cannot just re-search 709 mutex_unlock(&hashlimit_mutex);
694 * the list of htable's in htable_create(), since then we would
695 * create duplicate proc files. -HW */
696 mutex_lock(&hlimit_mutex);
697 r->hinfo = htable_find_get(r->name, par->match->family);
698 if (!r->hinfo && htable_create_v0(r, par->match->family) != 0) {
699 mutex_unlock(&hlimit_mutex);
700 return false; 710 return false;
701 } 711 }
702 mutex_unlock(&hlimit_mutex); 712 mutex_unlock(&hashlimit_mutex);
703 713
704 return true; 714 return true;
705} 715}
706 716
707static bool hashlimit_mt_check(const struct xt_mtchk_param *par) 717static bool hashlimit_mt_check(const struct xt_mtchk_param *par)
708{ 718{
719 struct net *net = par->net;
709 struct xt_hashlimit_mtinfo1 *info = par->matchinfo; 720 struct xt_hashlimit_mtinfo1 *info = par->matchinfo;
710 721
711 /* Check for overflow. */ 722 /* Check for overflow. */
@@ -728,19 +739,13 @@ static bool hashlimit_mt_check(const struct xt_mtchk_param *par)
728 return false; 739 return false;
729 } 740 }
730 741
731 /* This is the best we've got: We cannot release and re-grab lock, 742 mutex_lock(&hashlimit_mutex);
732 * since checkentry() is called before x_tables.c grabs xt_mutex. 743 info->hinfo = htable_find_get(net, info->name, par->match->family);
733 * We also cannot grab the hashtable spinlock, since htable_create will 744 if (!info->hinfo && htable_create(net, info, par->match->family) != 0) {
734 * call vmalloc, and that can sleep. And we cannot just re-search 745 mutex_unlock(&hashlimit_mutex);
735 * the list of htable's in htable_create(), since then we would
736 * create duplicate proc files. -HW */
737 mutex_lock(&hlimit_mutex);
738 info->hinfo = htable_find_get(info->name, par->match->family);
739 if (!info->hinfo && htable_create(info, par->match->family) != 0) {
740 mutex_unlock(&hlimit_mutex);
741 return false; 746 return false;
742 } 747 }
743 mutex_unlock(&hlimit_mutex); 748 mutex_unlock(&hashlimit_mutex);
744 return true; 749 return true;
745} 750}
746 751
@@ -767,7 +772,7 @@ struct compat_xt_hashlimit_info {
767 compat_uptr_t master; 772 compat_uptr_t master;
768}; 773};
769 774
770static void hashlimit_mt_compat_from_user(void *dst, void *src) 775static void hashlimit_mt_compat_from_user(void *dst, const void *src)
771{ 776{
772 int off = offsetof(struct compat_xt_hashlimit_info, hinfo); 777 int off = offsetof(struct compat_xt_hashlimit_info, hinfo);
773 778
@@ -775,7 +780,7 @@ static void hashlimit_mt_compat_from_user(void *dst, void *src)
775 memset(dst + off, 0, sizeof(struct compat_xt_hashlimit_info) - off); 780 memset(dst + off, 0, sizeof(struct compat_xt_hashlimit_info) - off);
776} 781}
777 782
778static int hashlimit_mt_compat_to_user(void __user *dst, void *src) 783static int hashlimit_mt_compat_to_user(void __user *dst, const void *src)
779{ 784{
780 int off = offsetof(struct compat_xt_hashlimit_info, hinfo); 785 int off = offsetof(struct compat_xt_hashlimit_info, hinfo);
781 786
@@ -841,8 +846,7 @@ static struct xt_match hashlimit_mt_reg[] __read_mostly = {
841static void *dl_seq_start(struct seq_file *s, loff_t *pos) 846static void *dl_seq_start(struct seq_file *s, loff_t *pos)
842 __acquires(htable->lock) 847 __acquires(htable->lock)
843{ 848{
844 struct proc_dir_entry *pde = s->private; 849 struct xt_hashlimit_htable *htable = s->private;
845 struct xt_hashlimit_htable *htable = pde->data;
846 unsigned int *bucket; 850 unsigned int *bucket;
847 851
848 spin_lock_bh(&htable->lock); 852 spin_lock_bh(&htable->lock);
@@ -859,8 +863,7 @@ static void *dl_seq_start(struct seq_file *s, loff_t *pos)
859 863
860static void *dl_seq_next(struct seq_file *s, void *v, loff_t *pos) 864static void *dl_seq_next(struct seq_file *s, void *v, loff_t *pos)
861{ 865{
862 struct proc_dir_entry *pde = s->private; 866 struct xt_hashlimit_htable *htable = s->private;
863 struct xt_hashlimit_htable *htable = pde->data;
864 unsigned int *bucket = (unsigned int *)v; 867 unsigned int *bucket = (unsigned int *)v;
865 868
866 *pos = ++(*bucket); 869 *pos = ++(*bucket);
@@ -874,11 +877,11 @@ static void *dl_seq_next(struct seq_file *s, void *v, loff_t *pos)
874static void dl_seq_stop(struct seq_file *s, void *v) 877static void dl_seq_stop(struct seq_file *s, void *v)
875 __releases(htable->lock) 878 __releases(htable->lock)
876{ 879{
877 struct proc_dir_entry *pde = s->private; 880 struct xt_hashlimit_htable *htable = s->private;
878 struct xt_hashlimit_htable *htable = pde->data;
879 unsigned int *bucket = (unsigned int *)v; 881 unsigned int *bucket = (unsigned int *)v;
880 882
881 kfree(bucket); 883 if (!IS_ERR(bucket))
884 kfree(bucket);
882 spin_unlock_bh(&htable->lock); 885 spin_unlock_bh(&htable->lock);
883} 886}
884 887
@@ -917,8 +920,7 @@ static int dl_seq_real_show(struct dsthash_ent *ent, u_int8_t family,
917 920
918static int dl_seq_show(struct seq_file *s, void *v) 921static int dl_seq_show(struct seq_file *s, void *v)
919{ 922{
920 struct proc_dir_entry *pde = s->private; 923 struct xt_hashlimit_htable *htable = s->private;
921 struct xt_hashlimit_htable *htable = pde->data;
922 unsigned int *bucket = (unsigned int *)v; 924 unsigned int *bucket = (unsigned int *)v;
923 struct dsthash_ent *ent; 925 struct dsthash_ent *ent;
924 struct hlist_node *pos; 926 struct hlist_node *pos;
@@ -944,7 +946,7 @@ static int dl_proc_open(struct inode *inode, struct file *file)
944 946
945 if (!ret) { 947 if (!ret) {
946 struct seq_file *sf = file->private_data; 948 struct seq_file *sf = file->private_data;
947 sf->private = PDE(inode); 949 sf->private = PDE(inode)->data;
948 } 950 }
949 return ret; 951 return ret;
950} 952}
@@ -957,10 +959,61 @@ static const struct file_operations dl_file_ops = {
957 .release = seq_release 959 .release = seq_release
958}; 960};
959 961
962static int __net_init hashlimit_proc_net_init(struct net *net)
963{
964 struct hashlimit_net *hashlimit_net = hashlimit_pernet(net);
965
966 hashlimit_net->ipt_hashlimit = proc_mkdir("ipt_hashlimit", net->proc_net);
967 if (!hashlimit_net->ipt_hashlimit)
968 return -ENOMEM;
969#if defined(CONFIG_IP6_NF_IPTABLES) || defined(CONFIG_IP6_NF_IPTABLES_MODULE)
970 hashlimit_net->ip6t_hashlimit = proc_mkdir("ip6t_hashlimit", net->proc_net);
971 if (!hashlimit_net->ip6t_hashlimit) {
972 proc_net_remove(net, "ipt_hashlimit");
973 return -ENOMEM;
974 }
975#endif
976 return 0;
977}
978
979static void __net_exit hashlimit_proc_net_exit(struct net *net)
980{
981 proc_net_remove(net, "ipt_hashlimit");
982#if defined(CONFIG_IP6_NF_IPTABLES) || defined(CONFIG_IP6_NF_IPTABLES_MODULE)
983 proc_net_remove(net, "ip6t_hashlimit");
984#endif
985}
986
987static int __net_init hashlimit_net_init(struct net *net)
988{
989 struct hashlimit_net *hashlimit_net = hashlimit_pernet(net);
990
991 INIT_HLIST_HEAD(&hashlimit_net->htables);
992 return hashlimit_proc_net_init(net);
993}
994
995static void __net_exit hashlimit_net_exit(struct net *net)
996{
997 struct hashlimit_net *hashlimit_net = hashlimit_pernet(net);
998
999 BUG_ON(!hlist_empty(&hashlimit_net->htables));
1000 hashlimit_proc_net_exit(net);
1001}
1002
1003static struct pernet_operations hashlimit_net_ops = {
1004 .init = hashlimit_net_init,
1005 .exit = hashlimit_net_exit,
1006 .id = &hashlimit_net_id,
1007 .size = sizeof(struct hashlimit_net),
1008};
1009
960static int __init hashlimit_mt_init(void) 1010static int __init hashlimit_mt_init(void)
961{ 1011{
962 int err; 1012 int err;
963 1013
1014 err = register_pernet_subsys(&hashlimit_net_ops);
1015 if (err < 0)
1016 return err;
964 err = xt_register_matches(hashlimit_mt_reg, 1017 err = xt_register_matches(hashlimit_mt_reg,
965 ARRAY_SIZE(hashlimit_mt_reg)); 1018 ARRAY_SIZE(hashlimit_mt_reg));
966 if (err < 0) 1019 if (err < 0)
@@ -974,41 +1027,21 @@ static int __init hashlimit_mt_init(void)
974 printk(KERN_ERR "xt_hashlimit: unable to create slab cache\n"); 1027 printk(KERN_ERR "xt_hashlimit: unable to create slab cache\n");
975 goto err2; 1028 goto err2;
976 } 1029 }
977 hashlimit_procdir4 = proc_mkdir("ipt_hashlimit", init_net.proc_net); 1030 return 0;
978 if (!hashlimit_procdir4) { 1031
979 printk(KERN_ERR "xt_hashlimit: unable to create proc dir "
980 "entry\n");
981 goto err3;
982 }
983 err = 0;
984#if defined(CONFIG_IP6_NF_IPTABLES) || defined(CONFIG_IP6_NF_IPTABLES_MODULE)
985 hashlimit_procdir6 = proc_mkdir("ip6t_hashlimit", init_net.proc_net);
986 if (!hashlimit_procdir6) {
987 printk(KERN_ERR "xt_hashlimit: unable to create proc dir "
988 "entry\n");
989 err = -ENOMEM;
990 }
991#endif
992 if (!err)
993 return 0;
994 remove_proc_entry("ipt_hashlimit", init_net.proc_net);
995err3:
996 kmem_cache_destroy(hashlimit_cachep);
997err2: 1032err2:
998 xt_unregister_matches(hashlimit_mt_reg, ARRAY_SIZE(hashlimit_mt_reg)); 1033 xt_unregister_matches(hashlimit_mt_reg, ARRAY_SIZE(hashlimit_mt_reg));
999err1: 1034err1:
1035 unregister_pernet_subsys(&hashlimit_net_ops);
1000 return err; 1036 return err;
1001 1037
1002} 1038}
1003 1039
1004static void __exit hashlimit_mt_exit(void) 1040static void __exit hashlimit_mt_exit(void)
1005{ 1041{
1006 remove_proc_entry("ipt_hashlimit", init_net.proc_net);
1007#if defined(CONFIG_IP6_NF_IPTABLES) || defined(CONFIG_IP6_NF_IPTABLES_MODULE)
1008 remove_proc_entry("ip6t_hashlimit", init_net.proc_net);
1009#endif
1010 kmem_cache_destroy(hashlimit_cachep); 1042 kmem_cache_destroy(hashlimit_cachep);
1011 xt_unregister_matches(hashlimit_mt_reg, ARRAY_SIZE(hashlimit_mt_reg)); 1043 xt_unregister_matches(hashlimit_mt_reg, ARRAY_SIZE(hashlimit_mt_reg));
1044 unregister_pernet_subsys(&hashlimit_net_ops);
1012} 1045}
1013 1046
1014module_init(hashlimit_mt_init); 1047module_init(hashlimit_mt_init);
diff --git a/net/netfilter/xt_limit.c b/net/netfilter/xt_limit.c
index 2773be6a71dd..e5d7e1ffb1a4 100644
--- a/net/netfilter/xt_limit.c
+++ b/net/netfilter/xt_limit.c
@@ -6,6 +6,7 @@
6 * published by the Free Software Foundation. 6 * published by the Free Software Foundation.
7 */ 7 */
8 8
9#include <linux/slab.h>
9#include <linux/module.h> 10#include <linux/module.h>
10#include <linux/skbuff.h> 11#include <linux/skbuff.h>
11#include <linux/spinlock.h> 12#include <linux/spinlock.h>
@@ -148,7 +149,7 @@ struct compat_xt_rateinfo {
148 149
149/* To keep the full "prev" timestamp, the upper 32 bits are stored in the 150/* To keep the full "prev" timestamp, the upper 32 bits are stored in the
150 * master pointer, which does not need to be preserved. */ 151 * master pointer, which does not need to be preserved. */
151static void limit_mt_compat_from_user(void *dst, void *src) 152static void limit_mt_compat_from_user(void *dst, const void *src)
152{ 153{
153 const struct compat_xt_rateinfo *cm = src; 154 const struct compat_xt_rateinfo *cm = src;
154 struct xt_rateinfo m = { 155 struct xt_rateinfo m = {
@@ -162,7 +163,7 @@ static void limit_mt_compat_from_user(void *dst, void *src)
162 memcpy(dst, &m, sizeof(m)); 163 memcpy(dst, &m, sizeof(m));
163} 164}
164 165
165static int limit_mt_compat_to_user(void __user *dst, void *src) 166static int limit_mt_compat_to_user(void __user *dst, const void *src)
166{ 167{
167 const struct xt_rateinfo *m = src; 168 const struct xt_rateinfo *m = src;
168 struct compat_xt_rateinfo cm = { 169 struct compat_xt_rateinfo cm = {
diff --git a/net/netfilter/xt_osf.c b/net/netfilter/xt_osf.c
index 4d1a41bbd5d7..4169e200588d 100644
--- a/net/netfilter/xt_osf.c
+++ b/net/netfilter/xt_osf.c
@@ -334,7 +334,7 @@ static bool xt_osf_match_packet(const struct sk_buff *skb,
334 if (info->flags & XT_OSF_LOG) 334 if (info->flags & XT_OSF_LOG)
335 nf_log_packet(p->family, p->hooknum, skb, 335 nf_log_packet(p->family, p->hooknum, skb,
336 p->in, p->out, NULL, 336 p->in, p->out, NULL,
337 "%s [%s:%s] : %pi4:%d -> %pi4:%d hops=%d\n", 337 "%s [%s:%s] : %pI4:%d -> %pI4:%d hops=%d\n",
338 f->genre, f->version, f->subtype, 338 f->genre, f->version, f->subtype,
339 &ip->saddr, ntohs(tcp->source), 339 &ip->saddr, ntohs(tcp->source),
340 &ip->daddr, ntohs(tcp->dest), 340 &ip->daddr, ntohs(tcp->dest),
@@ -349,7 +349,7 @@ static bool xt_osf_match_packet(const struct sk_buff *skb,
349 349
350 if (!fcount && (info->flags & XT_OSF_LOG)) 350 if (!fcount && (info->flags & XT_OSF_LOG))
351 nf_log_packet(p->family, p->hooknum, skb, p->in, p->out, NULL, 351 nf_log_packet(p->family, p->hooknum, skb, p->in, p->out, NULL,
352 "Remote OS is not known: %pi4:%u -> %pi4:%u\n", 352 "Remote OS is not known: %pI4:%u -> %pI4:%u\n",
353 &ip->saddr, ntohs(tcp->source), 353 &ip->saddr, ntohs(tcp->source),
354 &ip->daddr, ntohs(tcp->dest)); 354 &ip->daddr, ntohs(tcp->dest));
355 355
diff --git a/net/netfilter/xt_quota.c b/net/netfilter/xt_quota.c
index 390b7d09fe51..2d5562498c43 100644
--- a/net/netfilter/xt_quota.c
+++ b/net/netfilter/xt_quota.c
@@ -4,6 +4,7 @@
4 * Sam Johnston <samj@samj.net> 4 * Sam Johnston <samj@samj.net>
5 */ 5 */
6#include <linux/skbuff.h> 6#include <linux/skbuff.h>
7#include <linux/slab.h>
7#include <linux/spinlock.h> 8#include <linux/spinlock.h>
8 9
9#include <linux/netfilter/x_tables.h> 10#include <linux/netfilter/x_tables.h>
diff --git a/net/netfilter/xt_recent.c b/net/netfilter/xt_recent.c
index eb0ceb846527..834b736857cb 100644
--- a/net/netfilter/xt_recent.c
+++ b/net/netfilter/xt_recent.c
@@ -27,7 +27,9 @@
27#include <linux/bitops.h> 27#include <linux/bitops.h>
28#include <linux/skbuff.h> 28#include <linux/skbuff.h>
29#include <linux/inet.h> 29#include <linux/inet.h>
30#include <linux/slab.h>
30#include <net/net_namespace.h> 31#include <net/net_namespace.h>
32#include <net/netns/generic.h>
31 33
32#include <linux/netfilter/x_tables.h> 34#include <linux/netfilter/x_tables.h>
33#include <linux/netfilter/xt_recent.h> 35#include <linux/netfilter/xt_recent.h>
@@ -52,7 +54,7 @@ module_param(ip_list_perms, uint, 0400);
52module_param(ip_list_uid, uint, 0400); 54module_param(ip_list_uid, uint, 0400);
53module_param(ip_list_gid, uint, 0400); 55module_param(ip_list_gid, uint, 0400);
54MODULE_PARM_DESC(ip_list_tot, "number of IPs to remember per list"); 56MODULE_PARM_DESC(ip_list_tot, "number of IPs to remember per list");
55MODULE_PARM_DESC(ip_pkt_list_tot, "number of packets per IP to remember (max. 255)"); 57MODULE_PARM_DESC(ip_pkt_list_tot, "number of packets per IP address to remember (max. 255)");
56MODULE_PARM_DESC(ip_list_hash_size, "size of hash table used to look up IPs"); 58MODULE_PARM_DESC(ip_list_hash_size, "size of hash table used to look up IPs");
57MODULE_PARM_DESC(ip_list_perms, "permissions on /proc/net/xt_recent/* files"); 59MODULE_PARM_DESC(ip_list_perms, "permissions on /proc/net/xt_recent/* files");
58MODULE_PARM_DESC(ip_list_uid,"owner of /proc/net/xt_recent/* files"); 60MODULE_PARM_DESC(ip_list_uid,"owner of /proc/net/xt_recent/* files");
@@ -78,37 +80,40 @@ struct recent_table {
78 struct list_head iphash[0]; 80 struct list_head iphash[0];
79}; 81};
80 82
81static LIST_HEAD(tables); 83struct recent_net {
84 struct list_head tables;
85#ifdef CONFIG_PROC_FS
86 struct proc_dir_entry *xt_recent;
87#ifdef CONFIG_NETFILTER_XT_MATCH_RECENT_PROC_COMPAT
88 struct proc_dir_entry *ipt_recent;
89#endif
90#endif
91};
92
93static int recent_net_id;
94static inline struct recent_net *recent_pernet(struct net *net)
95{
96 return net_generic(net, recent_net_id);
97}
98
82static DEFINE_SPINLOCK(recent_lock); 99static DEFINE_SPINLOCK(recent_lock);
83static DEFINE_MUTEX(recent_mutex); 100static DEFINE_MUTEX(recent_mutex);
84 101
85#ifdef CONFIG_PROC_FS 102#ifdef CONFIG_PROC_FS
86#ifdef CONFIG_NETFILTER_XT_MATCH_RECENT_PROC_COMPAT
87static struct proc_dir_entry *proc_old_dir;
88#endif
89static struct proc_dir_entry *recent_proc_dir;
90static const struct file_operations recent_old_fops, recent_mt_fops; 103static const struct file_operations recent_old_fops, recent_mt_fops;
91#endif 104#endif
92 105
93static u_int32_t hash_rnd; 106static u_int32_t hash_rnd __read_mostly;
94static bool hash_rnd_initted; 107static bool hash_rnd_inited __read_mostly;
95 108
96static unsigned int recent_entry_hash4(const union nf_inet_addr *addr) 109static inline unsigned int recent_entry_hash4(const union nf_inet_addr *addr)
97{ 110{
98 if (!hash_rnd_initted) {
99 get_random_bytes(&hash_rnd, sizeof(hash_rnd));
100 hash_rnd_initted = true;
101 }
102 return jhash_1word((__force u32)addr->ip, hash_rnd) & 111 return jhash_1word((__force u32)addr->ip, hash_rnd) &
103 (ip_list_hash_size - 1); 112 (ip_list_hash_size - 1);
104} 113}
105 114
106static unsigned int recent_entry_hash6(const union nf_inet_addr *addr) 115static inline unsigned int recent_entry_hash6(const union nf_inet_addr *addr)
107{ 116{
108 if (!hash_rnd_initted) {
109 get_random_bytes(&hash_rnd, sizeof(hash_rnd));
110 hash_rnd_initted = true;
111 }
112 return jhash2((u32 *)addr->ip6, ARRAY_SIZE(addr->ip6), hash_rnd) & 117 return jhash2((u32 *)addr->ip6, ARRAY_SIZE(addr->ip6), hash_rnd) &
113 (ip_list_hash_size - 1); 118 (ip_list_hash_size - 1);
114} 119}
@@ -173,18 +178,19 @@ recent_entry_init(struct recent_table *t, const union nf_inet_addr *addr,
173 178
174static void recent_entry_update(struct recent_table *t, struct recent_entry *e) 179static void recent_entry_update(struct recent_table *t, struct recent_entry *e)
175{ 180{
181 e->index %= ip_pkt_list_tot;
176 e->stamps[e->index++] = jiffies; 182 e->stamps[e->index++] = jiffies;
177 if (e->index > e->nstamps) 183 if (e->index > e->nstamps)
178 e->nstamps = e->index; 184 e->nstamps = e->index;
179 e->index %= ip_pkt_list_tot;
180 list_move_tail(&e->lru_list, &t->lru_list); 185 list_move_tail(&e->lru_list, &t->lru_list);
181} 186}
182 187
183static struct recent_table *recent_table_lookup(const char *name) 188static struct recent_table *recent_table_lookup(struct recent_net *recent_net,
189 const char *name)
184{ 190{
185 struct recent_table *t; 191 struct recent_table *t;
186 192
187 list_for_each_entry(t, &tables, list) 193 list_for_each_entry(t, &recent_net->tables, list)
188 if (!strcmp(t->name, name)) 194 if (!strcmp(t->name, name))
189 return t; 195 return t;
190 return NULL; 196 return NULL;
@@ -203,6 +209,8 @@ static void recent_table_flush(struct recent_table *t)
203static bool 209static bool
204recent_mt(const struct sk_buff *skb, const struct xt_match_param *par) 210recent_mt(const struct sk_buff *skb, const struct xt_match_param *par)
205{ 211{
212 struct net *net = dev_net(par->in ? par->in : par->out);
213 struct recent_net *recent_net = recent_pernet(net);
206 const struct xt_recent_mtinfo *info = par->matchinfo; 214 const struct xt_recent_mtinfo *info = par->matchinfo;
207 struct recent_table *t; 215 struct recent_table *t;
208 struct recent_entry *e; 216 struct recent_entry *e;
@@ -235,7 +243,7 @@ recent_mt(const struct sk_buff *skb, const struct xt_match_param *par)
235 ttl++; 243 ttl++;
236 244
237 spin_lock_bh(&recent_lock); 245 spin_lock_bh(&recent_lock);
238 t = recent_table_lookup(info->name); 246 t = recent_table_lookup(recent_net, info->name);
239 e = recent_entry_lookup(t, &addr, par->match->family, 247 e = recent_entry_lookup(t, &addr, par->match->family,
240 (info->check_set & XT_RECENT_TTL) ? ttl : 0); 248 (info->check_set & XT_RECENT_TTL) ? ttl : 0);
241 if (e == NULL) { 249 if (e == NULL) {
@@ -260,7 +268,7 @@ recent_mt(const struct sk_buff *skb, const struct xt_match_param *par)
260 for (i = 0; i < e->nstamps; i++) { 268 for (i = 0; i < e->nstamps; i++) {
261 if (info->seconds && time_after(time, e->stamps[i])) 269 if (info->seconds && time_after(time, e->stamps[i]))
262 continue; 270 continue;
263 if (++hits >= info->hit_count) { 271 if (!info->hit_count || ++hits >= info->hit_count) {
264 ret = !ret; 272 ret = !ret;
265 break; 273 break;
266 } 274 }
@@ -279,6 +287,7 @@ out:
279 287
280static bool recent_mt_check(const struct xt_mtchk_param *par) 288static bool recent_mt_check(const struct xt_mtchk_param *par)
281{ 289{
290 struct recent_net *recent_net = recent_pernet(par->net);
282 const struct xt_recent_mtinfo *info = par->matchinfo; 291 const struct xt_recent_mtinfo *info = par->matchinfo;
283 struct recent_table *t; 292 struct recent_table *t;
284#ifdef CONFIG_PROC_FS 293#ifdef CONFIG_PROC_FS
@@ -287,6 +296,10 @@ static bool recent_mt_check(const struct xt_mtchk_param *par)
287 unsigned i; 296 unsigned i;
288 bool ret = false; 297 bool ret = false;
289 298
299 if (unlikely(!hash_rnd_inited)) {
300 get_random_bytes(&hash_rnd, sizeof(hash_rnd));
301 hash_rnd_inited = true;
302 }
290 if (hweight8(info->check_set & 303 if (hweight8(info->check_set &
291 (XT_RECENT_SET | XT_RECENT_REMOVE | 304 (XT_RECENT_SET | XT_RECENT_REMOVE |
292 XT_RECENT_CHECK | XT_RECENT_UPDATE)) != 1) 305 XT_RECENT_CHECK | XT_RECENT_UPDATE)) != 1)
@@ -294,14 +307,18 @@ static bool recent_mt_check(const struct xt_mtchk_param *par)
294 if ((info->check_set & (XT_RECENT_SET | XT_RECENT_REMOVE)) && 307 if ((info->check_set & (XT_RECENT_SET | XT_RECENT_REMOVE)) &&
295 (info->seconds || info->hit_count)) 308 (info->seconds || info->hit_count))
296 return false; 309 return false;
297 if (info->hit_count > ip_pkt_list_tot) 310 if (info->hit_count > ip_pkt_list_tot) {
311 pr_info(KBUILD_MODNAME ": hitcount (%u) is larger than "
312 "packets to be remembered (%u)\n",
313 info->hit_count, ip_pkt_list_tot);
298 return false; 314 return false;
315 }
299 if (info->name[0] == '\0' || 316 if (info->name[0] == '\0' ||
300 strnlen(info->name, XT_RECENT_NAME_LEN) == XT_RECENT_NAME_LEN) 317 strnlen(info->name, XT_RECENT_NAME_LEN) == XT_RECENT_NAME_LEN)
301 return false; 318 return false;
302 319
303 mutex_lock(&recent_mutex); 320 mutex_lock(&recent_mutex);
304 t = recent_table_lookup(info->name); 321 t = recent_table_lookup(recent_net, info->name);
305 if (t != NULL) { 322 if (t != NULL) {
306 t->refcnt++; 323 t->refcnt++;
307 ret = true; 324 ret = true;
@@ -318,7 +335,7 @@ static bool recent_mt_check(const struct xt_mtchk_param *par)
318 for (i = 0; i < ip_list_hash_size; i++) 335 for (i = 0; i < ip_list_hash_size; i++)
319 INIT_LIST_HEAD(&t->iphash[i]); 336 INIT_LIST_HEAD(&t->iphash[i]);
320#ifdef CONFIG_PROC_FS 337#ifdef CONFIG_PROC_FS
321 pde = proc_create_data(t->name, ip_list_perms, recent_proc_dir, 338 pde = proc_create_data(t->name, ip_list_perms, recent_net->xt_recent,
322 &recent_mt_fops, t); 339 &recent_mt_fops, t);
323 if (pde == NULL) { 340 if (pde == NULL) {
324 kfree(t); 341 kfree(t);
@@ -327,10 +344,10 @@ static bool recent_mt_check(const struct xt_mtchk_param *par)
327 pde->uid = ip_list_uid; 344 pde->uid = ip_list_uid;
328 pde->gid = ip_list_gid; 345 pde->gid = ip_list_gid;
329#ifdef CONFIG_NETFILTER_XT_MATCH_RECENT_PROC_COMPAT 346#ifdef CONFIG_NETFILTER_XT_MATCH_RECENT_PROC_COMPAT
330 pde = proc_create_data(t->name, ip_list_perms, proc_old_dir, 347 pde = proc_create_data(t->name, ip_list_perms, recent_net->ipt_recent,
331 &recent_old_fops, t); 348 &recent_old_fops, t);
332 if (pde == NULL) { 349 if (pde == NULL) {
333 remove_proc_entry(t->name, proc_old_dir); 350 remove_proc_entry(t->name, recent_net->xt_recent);
334 kfree(t); 351 kfree(t);
335 goto out; 352 goto out;
336 } 353 }
@@ -339,7 +356,7 @@ static bool recent_mt_check(const struct xt_mtchk_param *par)
339#endif 356#endif
340#endif 357#endif
341 spin_lock_bh(&recent_lock); 358 spin_lock_bh(&recent_lock);
342 list_add_tail(&t->list, &tables); 359 list_add_tail(&t->list, &recent_net->tables);
343 spin_unlock_bh(&recent_lock); 360 spin_unlock_bh(&recent_lock);
344 ret = true; 361 ret = true;
345out: 362out:
@@ -349,20 +366,21 @@ out:
349 366
350static void recent_mt_destroy(const struct xt_mtdtor_param *par) 367static void recent_mt_destroy(const struct xt_mtdtor_param *par)
351{ 368{
369 struct recent_net *recent_net = recent_pernet(par->net);
352 const struct xt_recent_mtinfo *info = par->matchinfo; 370 const struct xt_recent_mtinfo *info = par->matchinfo;
353 struct recent_table *t; 371 struct recent_table *t;
354 372
355 mutex_lock(&recent_mutex); 373 mutex_lock(&recent_mutex);
356 t = recent_table_lookup(info->name); 374 t = recent_table_lookup(recent_net, info->name);
357 if (--t->refcnt == 0) { 375 if (--t->refcnt == 0) {
358 spin_lock_bh(&recent_lock); 376 spin_lock_bh(&recent_lock);
359 list_del(&t->list); 377 list_del(&t->list);
360 spin_unlock_bh(&recent_lock); 378 spin_unlock_bh(&recent_lock);
361#ifdef CONFIG_PROC_FS 379#ifdef CONFIG_PROC_FS
362#ifdef CONFIG_NETFILTER_XT_MATCH_RECENT_PROC_COMPAT 380#ifdef CONFIG_NETFILTER_XT_MATCH_RECENT_PROC_COMPAT
363 remove_proc_entry(t->name, proc_old_dir); 381 remove_proc_entry(t->name, recent_net->ipt_recent);
364#endif 382#endif
365 remove_proc_entry(t->name, recent_proc_dir); 383 remove_proc_entry(t->name, recent_net->xt_recent);
366#endif 384#endif
367 recent_table_flush(t); 385 recent_table_flush(t);
368 kfree(t); 386 kfree(t);
@@ -482,8 +500,7 @@ static ssize_t recent_old_proc_write(struct file *file,
482 if (copy_from_user(buf, input, size)) 500 if (copy_from_user(buf, input, size))
483 return -EFAULT; 501 return -EFAULT;
484 502
485 while (isspace(*c)) 503 c = skip_spaces(c);
486 c++;
487 504
488 if (size - (c - buf) < 5) 505 if (size - (c - buf) < 5)
489 return c - buf; 506 return c - buf;
@@ -612,8 +629,65 @@ static const struct file_operations recent_mt_fops = {
612 .release = seq_release_private, 629 .release = seq_release_private,
613 .owner = THIS_MODULE, 630 .owner = THIS_MODULE,
614}; 631};
632
633static int __net_init recent_proc_net_init(struct net *net)
634{
635 struct recent_net *recent_net = recent_pernet(net);
636
637 recent_net->xt_recent = proc_mkdir("xt_recent", net->proc_net);
638 if (!recent_net->xt_recent)
639 return -ENOMEM;
640#ifdef CONFIG_NETFILTER_XT_MATCH_RECENT_PROC_COMPAT
641 recent_net->ipt_recent = proc_mkdir("ipt_recent", net->proc_net);
642 if (!recent_net->ipt_recent) {
643 proc_net_remove(net, "xt_recent");
644 return -ENOMEM;
645 }
646#endif
647 return 0;
648}
649
650static void __net_exit recent_proc_net_exit(struct net *net)
651{
652#ifdef CONFIG_NETFILTER_XT_MATCH_RECENT_PROC_COMPAT
653 proc_net_remove(net, "ipt_recent");
654#endif
655 proc_net_remove(net, "xt_recent");
656}
657#else
658static inline int recent_proc_net_init(struct net *net)
659{
660 return 0;
661}
662
663static inline void recent_proc_net_exit(struct net *net)
664{
665}
615#endif /* CONFIG_PROC_FS */ 666#endif /* CONFIG_PROC_FS */
616 667
668static int __net_init recent_net_init(struct net *net)
669{
670 struct recent_net *recent_net = recent_pernet(net);
671
672 INIT_LIST_HEAD(&recent_net->tables);
673 return recent_proc_net_init(net);
674}
675
676static void __net_exit recent_net_exit(struct net *net)
677{
678 struct recent_net *recent_net = recent_pernet(net);
679
680 BUG_ON(!list_empty(&recent_net->tables));
681 recent_proc_net_exit(net);
682}
683
684static struct pernet_operations recent_net_ops = {
685 .init = recent_net_init,
686 .exit = recent_net_exit,
687 .id = &recent_net_id,
688 .size = sizeof(struct recent_net),
689};
690
617static struct xt_match recent_mt_reg[] __read_mostly = { 691static struct xt_match recent_mt_reg[] __read_mostly = {
618 { 692 {
619 .name = "recent", 693 .name = "recent",
@@ -645,39 +719,19 @@ static int __init recent_mt_init(void)
645 return -EINVAL; 719 return -EINVAL;
646 ip_list_hash_size = 1 << fls(ip_list_tot); 720 ip_list_hash_size = 1 << fls(ip_list_tot);
647 721
648 err = xt_register_matches(recent_mt_reg, ARRAY_SIZE(recent_mt_reg)); 722 err = register_pernet_subsys(&recent_net_ops);
649#ifdef CONFIG_PROC_FS
650 if (err) 723 if (err)
651 return err; 724 return err;
652 recent_proc_dir = proc_mkdir("xt_recent", init_net.proc_net); 725 err = xt_register_matches(recent_mt_reg, ARRAY_SIZE(recent_mt_reg));
653 if (recent_proc_dir == NULL) { 726 if (err)
654 xt_unregister_matches(recent_mt_reg, ARRAY_SIZE(recent_mt_reg)); 727 unregister_pernet_subsys(&recent_net_ops);
655 err = -ENOMEM;
656 }
657#ifdef CONFIG_NETFILTER_XT_MATCH_RECENT_PROC_COMPAT
658 if (err < 0)
659 return err;
660 proc_old_dir = proc_mkdir("ipt_recent", init_net.proc_net);
661 if (proc_old_dir == NULL) {
662 remove_proc_entry("xt_recent", init_net.proc_net);
663 xt_unregister_matches(recent_mt_reg, ARRAY_SIZE(recent_mt_reg));
664 err = -ENOMEM;
665 }
666#endif
667#endif
668 return err; 728 return err;
669} 729}
670 730
671static void __exit recent_mt_exit(void) 731static void __exit recent_mt_exit(void)
672{ 732{
673 BUG_ON(!list_empty(&tables));
674 xt_unregister_matches(recent_mt_reg, ARRAY_SIZE(recent_mt_reg)); 733 xt_unregister_matches(recent_mt_reg, ARRAY_SIZE(recent_mt_reg));
675#ifdef CONFIG_PROC_FS 734 unregister_pernet_subsys(&recent_net_ops);
676#ifdef CONFIG_NETFILTER_XT_MATCH_RECENT_PROC_COMPAT
677 remove_proc_entry("ipt_recent", init_net.proc_net);
678#endif
679 remove_proc_entry("xt_recent", init_net.proc_net);
680#endif
681} 735}
682 736
683module_init(recent_mt_init); 737module_init(recent_mt_init);
diff --git a/net/netfilter/xt_repldata.h b/net/netfilter/xt_repldata.h
new file mode 100644
index 000000000000..6efe4e5a81c6
--- /dev/null
+++ b/net/netfilter/xt_repldata.h
@@ -0,0 +1,35 @@
1/*
2 * Today's hack: quantum tunneling in structs
3 *
4 * 'entries' and 'term' are never anywhere referenced by word in code. In fact,
5 * they serve as the hanging-off data accessed through repl.data[].
6 */
7
8#define xt_alloc_initial_table(type, typ2) ({ \
9 unsigned int hook_mask = info->valid_hooks; \
10 unsigned int nhooks = hweight32(hook_mask); \
11 unsigned int bytes = 0, hooknum = 0, i = 0; \
12 struct { \
13 struct type##_replace repl; \
14 struct type##_standard entries[nhooks]; \
15 struct type##_error term; \
16 } *tbl = kzalloc(sizeof(*tbl), GFP_KERNEL); \
17 if (tbl == NULL) \
18 return NULL; \
19 strncpy(tbl->repl.name, info->name, sizeof(tbl->repl.name)); \
20 tbl->term = (struct type##_error)typ2##_ERROR_INIT; \
21 tbl->repl.valid_hooks = hook_mask; \
22 tbl->repl.num_entries = nhooks + 1; \
23 tbl->repl.size = nhooks * sizeof(struct type##_standard) + \
24 sizeof(struct type##_error); \
25 for (; hook_mask != 0; hook_mask >>= 1, ++hooknum) { \
26 if (!(hook_mask & 1)) \
27 continue; \
28 tbl->repl.hook_entry[hooknum] = bytes; \
29 tbl->repl.underflow[hooknum] = bytes; \
30 tbl->entries[i++] = (struct type##_standard) \
31 typ2##_STANDARD_INIT(NF_ACCEPT); \
32 bytes += sizeof(struct type##_standard); \
33 } \
34 tbl; \
35})
diff --git a/net/netfilter/xt_socket.c b/net/netfilter/xt_socket.c
index ebf00ad5b194..6a902564d24f 100644
--- a/net/netfilter/xt_socket.c
+++ b/net/netfilter/xt_socket.c
@@ -149,7 +149,7 @@ socket_match(const struct sk_buff *skb, const struct xt_match_param *par,
149 149
150 /* Ignore sockets listening on INADDR_ANY */ 150 /* Ignore sockets listening on INADDR_ANY */
151 wildcard = (sk->sk_state != TCP_TIME_WAIT && 151 wildcard = (sk->sk_state != TCP_TIME_WAIT &&
152 inet_sk(sk)->rcv_saddr == 0); 152 inet_sk(sk)->inet_rcv_saddr == 0);
153 153
154 /* Ignore non-transparent sockets, 154 /* Ignore non-transparent sockets,
155 if XT_SOCKET_TRANSPARENT is used */ 155 if XT_SOCKET_TRANSPARENT is used */
@@ -192,7 +192,8 @@ static struct xt_match socket_mt_reg[] __read_mostly = {
192 .revision = 0, 192 .revision = 0,
193 .family = NFPROTO_IPV4, 193 .family = NFPROTO_IPV4,
194 .match = socket_mt_v0, 194 .match = socket_mt_v0,
195 .hooks = 1 << NF_INET_PRE_ROUTING, 195 .hooks = (1 << NF_INET_PRE_ROUTING) |
196 (1 << NF_INET_LOCAL_IN),
196 .me = THIS_MODULE, 197 .me = THIS_MODULE,
197 }, 198 },
198 { 199 {
@@ -201,7 +202,8 @@ static struct xt_match socket_mt_reg[] __read_mostly = {
201 .family = NFPROTO_IPV4, 202 .family = NFPROTO_IPV4,
202 .match = socket_mt_v1, 203 .match = socket_mt_v1,
203 .matchsize = sizeof(struct xt_socket_mtinfo1), 204 .matchsize = sizeof(struct xt_socket_mtinfo1),
204 .hooks = 1 << NF_INET_PRE_ROUTING, 205 .hooks = (1 << NF_INET_PRE_ROUTING) |
206 (1 << NF_INET_LOCAL_IN),
205 .me = THIS_MODULE, 207 .me = THIS_MODULE,
206 }, 208 },
207}; 209};
diff --git a/net/netfilter/xt_statistic.c b/net/netfilter/xt_statistic.c
index d8c0f8f1a78e..937ce0633e99 100644
--- a/net/netfilter/xt_statistic.c
+++ b/net/netfilter/xt_statistic.c
@@ -12,6 +12,7 @@
12#include <linux/spinlock.h> 12#include <linux/spinlock.h>
13#include <linux/skbuff.h> 13#include <linux/skbuff.h>
14#include <linux/net.h> 14#include <linux/net.h>
15#include <linux/slab.h>
15 16
16#include <linux/netfilter/xt_statistic.h> 17#include <linux/netfilter/xt_statistic.h>
17#include <linux/netfilter/x_tables.h> 18#include <linux/netfilter/x_tables.h>
diff --git a/net/netfilter/xt_string.c b/net/netfilter/xt_string.c
index b4d774111311..96801ffd8af8 100644
--- a/net/netfilter/xt_string.c
+++ b/net/netfilter/xt_string.c
@@ -7,6 +7,7 @@
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 */ 8 */
9 9
10#include <linux/gfp.h>
10#include <linux/init.h> 11#include <linux/init.h>
11#include <linux/module.h> 12#include <linux/module.h>
12#include <linux/kernel.h> 13#include <linux/kernel.h>
diff --git a/net/netlabel/netlabel_cipso_v4.c b/net/netlabel/netlabel_cipso_v4.c
index e639298bc9c8..5f14c8462e30 100644
--- a/net/netlabel/netlabel_cipso_v4.c
+++ b/net/netlabel/netlabel_cipso_v4.c
@@ -33,6 +33,7 @@
33#include <linux/string.h> 33#include <linux/string.h>
34#include <linux/skbuff.h> 34#include <linux/skbuff.h>
35#include <linux/audit.h> 35#include <linux/audit.h>
36#include <linux/slab.h>
36#include <net/sock.h> 37#include <net/sock.h>
37#include <net/netlink.h> 38#include <net/netlink.h>
38#include <net/genetlink.h> 39#include <net/genetlink.h>
diff --git a/net/netlabel/netlabel_domainhash.c b/net/netlabel/netlabel_domainhash.c
index 7a10bbe02c13..d37b7f80fa37 100644
--- a/net/netlabel/netlabel_domainhash.c
+++ b/net/netlabel/netlabel_domainhash.c
@@ -35,6 +35,7 @@
35#include <linux/spinlock.h> 35#include <linux/spinlock.h>
36#include <linux/string.h> 36#include <linux/string.h>
37#include <linux/audit.h> 37#include <linux/audit.h>
38#include <linux/slab.h>
38#include <net/netlabel.h> 39#include <net/netlabel.h>
39#include <net/cipso_ipv4.h> 40#include <net/cipso_ipv4.h>
40#include <asm/bug.h> 41#include <asm/bug.h>
@@ -50,9 +51,12 @@ struct netlbl_domhsh_tbl {
50}; 51};
51 52
52/* Domain hash table */ 53/* Domain hash table */
53/* XXX - updates should be so rare that having one spinlock for the entire 54/* updates should be so rare that having one spinlock for the entire hash table
54 * hash table should be okay */ 55 * should be okay */
55static DEFINE_SPINLOCK(netlbl_domhsh_lock); 56static DEFINE_SPINLOCK(netlbl_domhsh_lock);
57#define netlbl_domhsh_rcu_deref(p) \
58 rcu_dereference_check(p, rcu_read_lock_held() || \
59 lockdep_is_held(&netlbl_domhsh_lock))
56static struct netlbl_domhsh_tbl *netlbl_domhsh = NULL; 60static struct netlbl_domhsh_tbl *netlbl_domhsh = NULL;
57static struct netlbl_dom_map *netlbl_domhsh_def = NULL; 61static struct netlbl_dom_map *netlbl_domhsh_def = NULL;
58 62
@@ -106,7 +110,8 @@ static void netlbl_domhsh_free_entry(struct rcu_head *entry)
106 * Description: 110 * Description:
107 * This is the hashing function for the domain hash table, it returns the 111 * This is the hashing function for the domain hash table, it returns the
108 * correct bucket number for the domain. The caller is responsibile for 112 * correct bucket number for the domain. The caller is responsibile for
109 * calling the rcu_read_[un]lock() functions. 113 * ensuring that the hash table is protected with either a RCU read lock or the
114 * hash table lock.
110 * 115 *
111 */ 116 */
112static u32 netlbl_domhsh_hash(const char *key) 117static u32 netlbl_domhsh_hash(const char *key)
@@ -120,7 +125,7 @@ static u32 netlbl_domhsh_hash(const char *key)
120 125
121 for (iter = 0, val = 0, len = strlen(key); iter < len; iter++) 126 for (iter = 0, val = 0, len = strlen(key); iter < len; iter++)
122 val = (val << 4 | (val >> (8 * sizeof(u32) - 4))) ^ key[iter]; 127 val = (val << 4 | (val >> (8 * sizeof(u32) - 4))) ^ key[iter];
123 return val & (rcu_dereference(netlbl_domhsh)->size - 1); 128 return val & (netlbl_domhsh_rcu_deref(netlbl_domhsh)->size - 1);
124} 129}
125 130
126/** 131/**
@@ -130,7 +135,8 @@ static u32 netlbl_domhsh_hash(const char *key)
130 * Description: 135 * Description:
131 * Searches the domain hash table and returns a pointer to the hash table 136 * Searches the domain hash table and returns a pointer to the hash table
132 * entry if found, otherwise NULL is returned. The caller is responsibile for 137 * entry if found, otherwise NULL is returned. The caller is responsibile for
133 * the rcu hash table locks (i.e. the caller much call rcu_read_[un]lock()). 138 * ensuring that the hash table is protected with either a RCU read lock or the
139 * hash table lock.
134 * 140 *
135 */ 141 */
136static struct netlbl_dom_map *netlbl_domhsh_search(const char *domain) 142static struct netlbl_dom_map *netlbl_domhsh_search(const char *domain)
@@ -141,7 +147,7 @@ static struct netlbl_dom_map *netlbl_domhsh_search(const char *domain)
141 147
142 if (domain != NULL) { 148 if (domain != NULL) {
143 bkt = netlbl_domhsh_hash(domain); 149 bkt = netlbl_domhsh_hash(domain);
144 bkt_list = &rcu_dereference(netlbl_domhsh)->tbl[bkt]; 150 bkt_list = &netlbl_domhsh_rcu_deref(netlbl_domhsh)->tbl[bkt];
145 list_for_each_entry_rcu(iter, bkt_list, list) 151 list_for_each_entry_rcu(iter, bkt_list, list)
146 if (iter->valid && strcmp(iter->domain, domain) == 0) 152 if (iter->valid && strcmp(iter->domain, domain) == 0)
147 return iter; 153 return iter;
@@ -159,8 +165,8 @@ static struct netlbl_dom_map *netlbl_domhsh_search(const char *domain)
159 * Searches the domain hash table and returns a pointer to the hash table 165 * Searches the domain hash table and returns a pointer to the hash table
160 * entry if an exact match is found, if an exact match is not present in the 166 * entry if an exact match is found, if an exact match is not present in the
161 * hash table then the default entry is returned if valid otherwise NULL is 167 * hash table then the default entry is returned if valid otherwise NULL is
162 * returned. The caller is responsibile for the rcu hash table locks 168 * returned. The caller is responsibile ensuring that the hash table is
163 * (i.e. the caller much call rcu_read_[un]lock()). 169 * protected with either a RCU read lock or the hash table lock.
164 * 170 *
165 */ 171 */
166static struct netlbl_dom_map *netlbl_domhsh_search_def(const char *domain) 172static struct netlbl_dom_map *netlbl_domhsh_search_def(const char *domain)
@@ -169,7 +175,7 @@ static struct netlbl_dom_map *netlbl_domhsh_search_def(const char *domain)
169 175
170 entry = netlbl_domhsh_search(domain); 176 entry = netlbl_domhsh_search(domain);
171 if (entry == NULL) { 177 if (entry == NULL) {
172 entry = rcu_dereference(netlbl_domhsh_def); 178 entry = netlbl_domhsh_rcu_deref(netlbl_domhsh_def);
173 if (entry != NULL && !entry->valid) 179 if (entry != NULL && !entry->valid)
174 entry = NULL; 180 entry = NULL;
175 } 181 }
@@ -306,8 +312,11 @@ int netlbl_domhsh_add(struct netlbl_dom_map *entry,
306 struct netlbl_af6list *tmp6; 312 struct netlbl_af6list *tmp6;
307#endif /* IPv6 */ 313#endif /* IPv6 */
308 314
315 /* XXX - we can remove this RCU read lock as the spinlock protects the
316 * entire function, but before we do we need to fixup the
317 * netlbl_af[4,6]list RCU functions to do "the right thing" with
318 * respect to rcu_dereference() when only a spinlock is held. */
309 rcu_read_lock(); 319 rcu_read_lock();
310
311 spin_lock(&netlbl_domhsh_lock); 320 spin_lock(&netlbl_domhsh_lock);
312 if (entry->domain != NULL) 321 if (entry->domain != NULL)
313 entry_old = netlbl_domhsh_search(entry->domain); 322 entry_old = netlbl_domhsh_search(entry->domain);
@@ -315,7 +324,6 @@ int netlbl_domhsh_add(struct netlbl_dom_map *entry,
315 entry_old = netlbl_domhsh_search_def(entry->domain); 324 entry_old = netlbl_domhsh_search_def(entry->domain);
316 if (entry_old == NULL) { 325 if (entry_old == NULL) {
317 entry->valid = 1; 326 entry->valid = 1;
318 INIT_RCU_HEAD(&entry->rcu);
319 327
320 if (entry->domain != NULL) { 328 if (entry->domain != NULL) {
321 u32 bkt = netlbl_domhsh_hash(entry->domain); 329 u32 bkt = netlbl_domhsh_hash(entry->domain);
@@ -682,7 +690,7 @@ struct netlbl_domaddr6_map *netlbl_domhsh_getentry_af6(const char *domain,
682 * buckets and @skip_chain entries. For each entry in the table call 690 * buckets and @skip_chain entries. For each entry in the table call
683 * @callback, if @callback returns a negative value stop 'walking' through the 691 * @callback, if @callback returns a negative value stop 'walking' through the
684 * table and return. Updates the values in @skip_bkt and @skip_chain on 692 * table and return. Updates the values in @skip_bkt and @skip_chain on
685 * return. Returns zero on succcess, negative values on failure. 693 * return. Returns zero on success, negative values on failure.
686 * 694 *
687 */ 695 */
688int netlbl_domhsh_walk(u32 *skip_bkt, 696int netlbl_domhsh_walk(u32 *skip_bkt,
diff --git a/net/netlabel/netlabel_kapi.c b/net/netlabel/netlabel_kapi.c
index 6ce00205f342..1b83e0009d8d 100644
--- a/net/netlabel/netlabel_kapi.c
+++ b/net/netlabel/netlabel_kapi.c
@@ -30,6 +30,7 @@
30 30
31#include <linux/init.h> 31#include <linux/init.h>
32#include <linux/types.h> 32#include <linux/types.h>
33#include <linux/slab.h>
33#include <linux/audit.h> 34#include <linux/audit.h>
34#include <linux/in.h> 35#include <linux/in.h>
35#include <linux/in6.h> 36#include <linux/in6.h>
diff --git a/net/netlabel/netlabel_mgmt.c b/net/netlabel/netlabel_mgmt.c
index 8203623e65ad..998e85e895d0 100644
--- a/net/netlabel/netlabel_mgmt.c
+++ b/net/netlabel/netlabel_mgmt.c
@@ -34,6 +34,7 @@
34#include <linux/skbuff.h> 34#include <linux/skbuff.h>
35#include <linux/in.h> 35#include <linux/in.h>
36#include <linux/in6.h> 36#include <linux/in6.h>
37#include <linux/slab.h>
37#include <net/sock.h> 38#include <net/sock.h>
38#include <net/netlink.h> 39#include <net/netlink.h>
39#include <net/genetlink.h> 40#include <net/genetlink.h>
diff --git a/net/netlabel/netlabel_unlabeled.c b/net/netlabel/netlabel_unlabeled.c
index fb357f010189..a3d64aabe2f7 100644
--- a/net/netlabel/netlabel_unlabeled.c
+++ b/net/netlabel/netlabel_unlabeled.c
@@ -43,6 +43,7 @@
43#include <linux/notifier.h> 43#include <linux/notifier.h>
44#include <linux/netdevice.h> 44#include <linux/netdevice.h>
45#include <linux/security.h> 45#include <linux/security.h>
46#include <linux/slab.h>
46#include <net/sock.h> 47#include <net/sock.h>
47#include <net/netlink.h> 48#include <net/netlink.h>
48#include <net/genetlink.h> 49#include <net/genetlink.h>
@@ -114,6 +115,9 @@ struct netlbl_unlhsh_walk_arg {
114/* updates should be so rare that having one spinlock for the entire 115/* updates should be so rare that having one spinlock for the entire
115 * hash table should be okay */ 116 * hash table should be okay */
116static DEFINE_SPINLOCK(netlbl_unlhsh_lock); 117static DEFINE_SPINLOCK(netlbl_unlhsh_lock);
118#define netlbl_unlhsh_rcu_deref(p) \
119 rcu_dereference_check(p, rcu_read_lock_held() || \
120 lockdep_is_held(&netlbl_unlhsh_lock))
117static struct netlbl_unlhsh_tbl *netlbl_unlhsh = NULL; 121static struct netlbl_unlhsh_tbl *netlbl_unlhsh = NULL;
118static struct netlbl_unlhsh_iface *netlbl_unlhsh_def = NULL; 122static struct netlbl_unlhsh_iface *netlbl_unlhsh_def = NULL;
119 123
@@ -235,15 +239,13 @@ static void netlbl_unlhsh_free_iface(struct rcu_head *entry)
235 * Description: 239 * Description:
236 * This is the hashing function for the unlabeled hash table, it returns the 240 * This is the hashing function for the unlabeled hash table, it returns the
237 * bucket number for the given device/interface. The caller is responsible for 241 * bucket number for the given device/interface. The caller is responsible for
238 * calling the rcu_read_[un]lock() functions. 242 * ensuring that the hash table is protected with either a RCU read lock or
243 * the hash table lock.
239 * 244 *
240 */ 245 */
241static u32 netlbl_unlhsh_hash(int ifindex) 246static u32 netlbl_unlhsh_hash(int ifindex)
242{ 247{
243 /* this is taken _almost_ directly from 248 return ifindex & (netlbl_unlhsh_rcu_deref(netlbl_unlhsh)->size - 1);
244 * security/selinux/netif.c:sel_netif_hasfn() as they do pretty much
245 * the same thing */
246 return ifindex & (rcu_dereference(netlbl_unlhsh)->size - 1);
247} 249}
248 250
249/** 251/**
@@ -253,7 +255,8 @@ static u32 netlbl_unlhsh_hash(int ifindex)
253 * Description: 255 * Description:
254 * Searches the unlabeled connection hash table and returns a pointer to the 256 * Searches the unlabeled connection hash table and returns a pointer to the
255 * interface entry which matches @ifindex, otherwise NULL is returned. The 257 * interface entry which matches @ifindex, otherwise NULL is returned. The
256 * caller is responsible for calling the rcu_read_[un]lock() functions. 258 * caller is responsible for ensuring that the hash table is protected with
259 * either a RCU read lock or the hash table lock.
257 * 260 *
258 */ 261 */
259static struct netlbl_unlhsh_iface *netlbl_unlhsh_search_iface(int ifindex) 262static struct netlbl_unlhsh_iface *netlbl_unlhsh_search_iface(int ifindex)
@@ -263,7 +266,7 @@ static struct netlbl_unlhsh_iface *netlbl_unlhsh_search_iface(int ifindex)
263 struct netlbl_unlhsh_iface *iter; 266 struct netlbl_unlhsh_iface *iter;
264 267
265 bkt = netlbl_unlhsh_hash(ifindex); 268 bkt = netlbl_unlhsh_hash(ifindex);
266 bkt_list = &rcu_dereference(netlbl_unlhsh)->tbl[bkt]; 269 bkt_list = &netlbl_unlhsh_rcu_deref(netlbl_unlhsh)->tbl[bkt];
267 list_for_each_entry_rcu(iter, bkt_list, list) 270 list_for_each_entry_rcu(iter, bkt_list, list)
268 if (iter->valid && iter->ifindex == ifindex) 271 if (iter->valid && iter->ifindex == ifindex)
269 return iter; 272 return iter;
@@ -272,33 +275,6 @@ static struct netlbl_unlhsh_iface *netlbl_unlhsh_search_iface(int ifindex)
272} 275}
273 276
274/** 277/**
275 * netlbl_unlhsh_search_iface_def - Search for a matching interface entry
276 * @ifindex: the network interface
277 *
278 * Description:
279 * Searches the unlabeled connection hash table and returns a pointer to the
280 * interface entry which matches @ifindex. If an exact match can not be found
281 * and there is a valid default entry, the default entry is returned, otherwise
282 * NULL is returned. The caller is responsible for calling the
283 * rcu_read_[un]lock() functions.
284 *
285 */
286static struct netlbl_unlhsh_iface *netlbl_unlhsh_search_iface_def(int ifindex)
287{
288 struct netlbl_unlhsh_iface *entry;
289
290 entry = netlbl_unlhsh_search_iface(ifindex);
291 if (entry != NULL)
292 return entry;
293
294 entry = rcu_dereference(netlbl_unlhsh_def);
295 if (entry != NULL && entry->valid)
296 return entry;
297
298 return NULL;
299}
300
301/**
302 * netlbl_unlhsh_add_addr4 - Add a new IPv4 address entry to the hash table 278 * netlbl_unlhsh_add_addr4 - Add a new IPv4 address entry to the hash table
303 * @iface: the associated interface entry 279 * @iface: the associated interface entry
304 * @addr: IPv4 address in network byte order 280 * @addr: IPv4 address in network byte order
@@ -308,8 +284,7 @@ static struct netlbl_unlhsh_iface *netlbl_unlhsh_search_iface_def(int ifindex)
308 * Description: 284 * Description:
309 * Add a new address entry into the unlabeled connection hash table using the 285 * Add a new address entry into the unlabeled connection hash table using the
310 * interface entry specified by @iface. On success zero is returned, otherwise 286 * interface entry specified by @iface. On success zero is returned, otherwise
311 * a negative value is returned. The caller is responsible for calling the 287 * a negative value is returned.
312 * rcu_read_[un]lock() functions.
313 * 288 *
314 */ 289 */
315static int netlbl_unlhsh_add_addr4(struct netlbl_unlhsh_iface *iface, 290static int netlbl_unlhsh_add_addr4(struct netlbl_unlhsh_iface *iface,
@@ -327,7 +302,6 @@ static int netlbl_unlhsh_add_addr4(struct netlbl_unlhsh_iface *iface,
327 entry->list.addr = addr->s_addr & mask->s_addr; 302 entry->list.addr = addr->s_addr & mask->s_addr;
328 entry->list.mask = mask->s_addr; 303 entry->list.mask = mask->s_addr;
329 entry->list.valid = 1; 304 entry->list.valid = 1;
330 INIT_RCU_HEAD(&entry->rcu);
331 entry->secid = secid; 305 entry->secid = secid;
332 306
333 spin_lock(&netlbl_unlhsh_lock); 307 spin_lock(&netlbl_unlhsh_lock);
@@ -350,8 +324,7 @@ static int netlbl_unlhsh_add_addr4(struct netlbl_unlhsh_iface *iface,
350 * Description: 324 * Description:
351 * Add a new address entry into the unlabeled connection hash table using the 325 * Add a new address entry into the unlabeled connection hash table using the
352 * interface entry specified by @iface. On success zero is returned, otherwise 326 * interface entry specified by @iface. On success zero is returned, otherwise
353 * a negative value is returned. The caller is responsible for calling the 327 * a negative value is returned.
354 * rcu_read_[un]lock() functions.
355 * 328 *
356 */ 329 */
357static int netlbl_unlhsh_add_addr6(struct netlbl_unlhsh_iface *iface, 330static int netlbl_unlhsh_add_addr6(struct netlbl_unlhsh_iface *iface,
@@ -373,7 +346,6 @@ static int netlbl_unlhsh_add_addr6(struct netlbl_unlhsh_iface *iface,
373 entry->list.addr.s6_addr32[3] &= mask->s6_addr32[3]; 346 entry->list.addr.s6_addr32[3] &= mask->s6_addr32[3];
374 ipv6_addr_copy(&entry->list.mask, mask); 347 ipv6_addr_copy(&entry->list.mask, mask);
375 entry->list.valid = 1; 348 entry->list.valid = 1;
376 INIT_RCU_HEAD(&entry->rcu);
377 entry->secid = secid; 349 entry->secid = secid;
378 350
379 spin_lock(&netlbl_unlhsh_lock); 351 spin_lock(&netlbl_unlhsh_lock);
@@ -393,8 +365,7 @@ static int netlbl_unlhsh_add_addr6(struct netlbl_unlhsh_iface *iface,
393 * Description: 365 * Description:
394 * Add a new, empty, interface entry into the unlabeled connection hash table. 366 * Add a new, empty, interface entry into the unlabeled connection hash table.
395 * On success a pointer to the new interface entry is returned, on failure NULL 367 * On success a pointer to the new interface entry is returned, on failure NULL
396 * is returned. The caller is responsible for calling the rcu_read_[un]lock() 368 * is returned.
397 * functions.
398 * 369 *
399 */ 370 */
400static struct netlbl_unlhsh_iface *netlbl_unlhsh_add_iface(int ifindex) 371static struct netlbl_unlhsh_iface *netlbl_unlhsh_add_iface(int ifindex)
@@ -410,7 +381,6 @@ static struct netlbl_unlhsh_iface *netlbl_unlhsh_add_iface(int ifindex)
410 INIT_LIST_HEAD(&iface->addr4_list); 381 INIT_LIST_HEAD(&iface->addr4_list);
411 INIT_LIST_HEAD(&iface->addr6_list); 382 INIT_LIST_HEAD(&iface->addr6_list);
412 iface->valid = 1; 383 iface->valid = 1;
413 INIT_RCU_HEAD(&iface->rcu);
414 384
415 spin_lock(&netlbl_unlhsh_lock); 385 spin_lock(&netlbl_unlhsh_lock);
416 if (ifindex > 0) { 386 if (ifindex > 0) {
@@ -418,10 +388,10 @@ static struct netlbl_unlhsh_iface *netlbl_unlhsh_add_iface(int ifindex)
418 if (netlbl_unlhsh_search_iface(ifindex) != NULL) 388 if (netlbl_unlhsh_search_iface(ifindex) != NULL)
419 goto add_iface_failure; 389 goto add_iface_failure;
420 list_add_tail_rcu(&iface->list, 390 list_add_tail_rcu(&iface->list,
421 &rcu_dereference(netlbl_unlhsh)->tbl[bkt]); 391 &netlbl_unlhsh_rcu_deref(netlbl_unlhsh)->tbl[bkt]);
422 } else { 392 } else {
423 INIT_LIST_HEAD(&iface->list); 393 INIT_LIST_HEAD(&iface->list);
424 if (rcu_dereference(netlbl_unlhsh_def) != NULL) 394 if (netlbl_unlhsh_rcu_deref(netlbl_unlhsh_def) != NULL)
425 goto add_iface_failure; 395 goto add_iface_failure;
426 rcu_assign_pointer(netlbl_unlhsh_def, iface); 396 rcu_assign_pointer(netlbl_unlhsh_def, iface);
427 } 397 }
@@ -472,13 +442,12 @@ int netlbl_unlhsh_add(struct net *net,
472 442
473 rcu_read_lock(); 443 rcu_read_lock();
474 if (dev_name != NULL) { 444 if (dev_name != NULL) {
475 dev = dev_get_by_name(net, dev_name); 445 dev = dev_get_by_name_rcu(net, dev_name);
476 if (dev == NULL) { 446 if (dev == NULL) {
477 ret_val = -ENODEV; 447 ret_val = -ENODEV;
478 goto unlhsh_add_return; 448 goto unlhsh_add_return;
479 } 449 }
480 ifindex = dev->ifindex; 450 ifindex = dev->ifindex;
481 dev_put(dev);
482 iface = netlbl_unlhsh_search_iface(ifindex); 451 iface = netlbl_unlhsh_search_iface(ifindex);
483 } else { 452 } else {
484 ifindex = 0; 453 ifindex = 0;
@@ -552,8 +521,7 @@ unlhsh_add_return:
552 * 521 *
553 * Description: 522 * Description:
554 * Remove an IP address entry from the unlabeled connection hash table. 523 * Remove an IP address entry from the unlabeled connection hash table.
555 * Returns zero on success, negative values on failure. The caller is 524 * Returns zero on success, negative values on failure.
556 * responsible for calling the rcu_read_[un]lock() functions.
557 * 525 *
558 */ 526 */
559static int netlbl_unlhsh_remove_addr4(struct net *net, 527static int netlbl_unlhsh_remove_addr4(struct net *net,
@@ -615,8 +583,7 @@ static int netlbl_unlhsh_remove_addr4(struct net *net,
615 * 583 *
616 * Description: 584 * Description:
617 * Remove an IP address entry from the unlabeled connection hash table. 585 * Remove an IP address entry from the unlabeled connection hash table.
618 * Returns zero on success, negative values on failure. The caller is 586 * Returns zero on success, negative values on failure.
619 * responsible for calling the rcu_read_[un]lock() functions.
620 * 587 *
621 */ 588 */
622static int netlbl_unlhsh_remove_addr6(struct net *net, 589static int netlbl_unlhsh_remove_addr6(struct net *net,
@@ -737,13 +704,12 @@ int netlbl_unlhsh_remove(struct net *net,
737 704
738 rcu_read_lock(); 705 rcu_read_lock();
739 if (dev_name != NULL) { 706 if (dev_name != NULL) {
740 dev = dev_get_by_name(net, dev_name); 707 dev = dev_get_by_name_rcu(net, dev_name);
741 if (dev == NULL) { 708 if (dev == NULL) {
742 ret_val = -ENODEV; 709 ret_val = -ENODEV;
743 goto unlhsh_remove_return; 710 goto unlhsh_remove_return;
744 } 711 }
745 iface = netlbl_unlhsh_search_iface(dev->ifindex); 712 iface = netlbl_unlhsh_search_iface(dev->ifindex);
746 dev_put(dev);
747 } else 713 } else
748 iface = rcu_dereference(netlbl_unlhsh_def); 714 iface = rcu_dereference(netlbl_unlhsh_def);
749 if (iface == NULL) { 715 if (iface == NULL) {
@@ -1552,8 +1518,10 @@ int netlbl_unlabel_getattr(const struct sk_buff *skb,
1552 struct netlbl_unlhsh_iface *iface; 1518 struct netlbl_unlhsh_iface *iface;
1553 1519
1554 rcu_read_lock(); 1520 rcu_read_lock();
1555 iface = netlbl_unlhsh_search_iface_def(skb->iif); 1521 iface = netlbl_unlhsh_search_iface(skb->skb_iif);
1556 if (iface == NULL) 1522 if (iface == NULL)
1523 iface = rcu_dereference(netlbl_unlhsh_def);
1524 if (iface == NULL || !iface->valid)
1557 goto unlabel_getattr_nolabel; 1525 goto unlabel_getattr_nolabel;
1558 switch (family) { 1526 switch (family) {
1559 case PF_INET: { 1527 case PF_INET: {
diff --git a/net/netlabel/netlabel_user.c b/net/netlabel/netlabel_user.c
index 68706b4e3bf8..a3fd75ac3fa5 100644
--- a/net/netlabel/netlabel_user.c
+++ b/net/netlabel/netlabel_user.c
@@ -35,6 +35,7 @@
35#include <linux/audit.h> 35#include <linux/audit.h>
36#include <linux/tty.h> 36#include <linux/tty.h>
37#include <linux/security.h> 37#include <linux/security.h>
38#include <linux/gfp.h>
38#include <net/sock.h> 39#include <net/sock.h>
39#include <net/netlink.h> 40#include <net/netlink.h>
40#include <net/genetlink.h> 41#include <net/genetlink.h>
diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
index 19e98007691c..795424396aff 100644
--- a/net/netlink/af_netlink.c
+++ b/net/netlink/af_netlink.c
@@ -428,7 +428,8 @@ static int __netlink_create(struct net *net, struct socket *sock,
428 return 0; 428 return 0;
429} 429}
430 430
431static int netlink_create(struct net *net, struct socket *sock, int protocol) 431static int netlink_create(struct net *net, struct socket *sock, int protocol,
432 int kern)
432{ 433{
433 struct module *module = NULL; 434 struct module *module = NULL;
434 struct mutex *cb_mutex; 435 struct mutex *cb_mutex;
@@ -454,9 +455,14 @@ static int netlink_create(struct net *net, struct socket *sock, int protocol)
454 if (nl_table[protocol].registered && 455 if (nl_table[protocol].registered &&
455 try_module_get(nl_table[protocol].module)) 456 try_module_get(nl_table[protocol].module))
456 module = nl_table[protocol].module; 457 module = nl_table[protocol].module;
458 else
459 err = -EPROTONOSUPPORT;
457 cb_mutex = nl_table[protocol].cb_mutex; 460 cb_mutex = nl_table[protocol].cb_mutex;
458 netlink_unlock_table(); 461 netlink_unlock_table();
459 462
463 if (err < 0)
464 goto out;
465
460 err = __netlink_create(net, sock, cb_mutex, protocol); 466 err = __netlink_create(net, sock, cb_mutex, protocol);
461 if (err < 0) 467 if (err < 0)
462 goto out_module; 468 goto out_module;
@@ -497,7 +503,7 @@ static int netlink_release(struct socket *sock)
497 503
498 skb_queue_purge(&sk->sk_write_queue); 504 skb_queue_purge(&sk->sk_write_queue);
499 505
500 if (nlk->pid && !nlk->subscriptions) { 506 if (nlk->pid) {
501 struct netlink_notify n = { 507 struct netlink_notify n = {
502 .net = sock_net(sk), 508 .net = sock_net(sk),
503 .protocol = sk->sk_protocol, 509 .protocol = sk->sk_protocol,
@@ -677,6 +683,9 @@ static int netlink_connect(struct socket *sock, struct sockaddr *addr,
677 struct netlink_sock *nlk = nlk_sk(sk); 683 struct netlink_sock *nlk = nlk_sk(sk);
678 struct sockaddr_nl *nladdr = (struct sockaddr_nl *)addr; 684 struct sockaddr_nl *nladdr = (struct sockaddr_nl *)addr;
679 685
686 if (alen < sizeof(addr->sa_family))
687 return -EINVAL;
688
680 if (addr->sa_family == AF_UNSPEC) { 689 if (addr->sa_family == AF_UNSPEC) {
681 sk->sk_state = NETLINK_UNCONNECTED; 690 sk->sk_state = NETLINK_UNCONNECTED;
682 nlk->dst_pid = 0; 691 nlk->dst_pid = 0;
@@ -707,7 +716,7 @@ static int netlink_getname(struct socket *sock, struct sockaddr *addr,
707{ 716{
708 struct sock *sk = sock->sk; 717 struct sock *sk = sock->sk;
709 struct netlink_sock *nlk = nlk_sk(sk); 718 struct netlink_sock *nlk = nlk_sk(sk);
710 struct sockaddr_nl *nladdr = (struct sockaddr_nl *)addr; 719 DECLARE_SOCKADDR(struct sockaddr_nl *, nladdr, addr);
711 720
712 nladdr->nl_family = AF_NETLINK; 721 nladdr->nl_family = AF_NETLINK;
713 nladdr->nl_pad = 0; 722 nladdr->nl_pad = 0;
@@ -1087,21 +1096,27 @@ static inline int do_one_set_err(struct sock *sk,
1087 struct netlink_set_err_data *p) 1096 struct netlink_set_err_data *p)
1088{ 1097{
1089 struct netlink_sock *nlk = nlk_sk(sk); 1098 struct netlink_sock *nlk = nlk_sk(sk);
1099 int ret = 0;
1090 1100
1091 if (sk == p->exclude_sk) 1101 if (sk == p->exclude_sk)
1092 goto out; 1102 goto out;
1093 1103
1094 if (sock_net(sk) != sock_net(p->exclude_sk)) 1104 if (!net_eq(sock_net(sk), sock_net(p->exclude_sk)))
1095 goto out; 1105 goto out;
1096 1106
1097 if (nlk->pid == p->pid || p->group - 1 >= nlk->ngroups || 1107 if (nlk->pid == p->pid || p->group - 1 >= nlk->ngroups ||
1098 !test_bit(p->group - 1, nlk->groups)) 1108 !test_bit(p->group - 1, nlk->groups))
1099 goto out; 1109 goto out;
1100 1110
1111 if (p->code == ENOBUFS && nlk->flags & NETLINK_RECV_NO_ENOBUFS) {
1112 ret = 1;
1113 goto out;
1114 }
1115
1101 sk->sk_err = p->code; 1116 sk->sk_err = p->code;
1102 sk->sk_error_report(sk); 1117 sk->sk_error_report(sk);
1103out: 1118out:
1104 return 0; 1119 return ret;
1105} 1120}
1106 1121
1107/** 1122/**
@@ -1110,12 +1125,16 @@ out:
1110 * @pid: the PID of a process that we want to skip (if any) 1125 * @pid: the PID of a process that we want to skip (if any)
1111 * @groups: the broadcast group that will notice the error 1126 * @groups: the broadcast group that will notice the error
1112 * @code: error code, must be negative (as usual in kernelspace) 1127 * @code: error code, must be negative (as usual in kernelspace)
1128 *
1129 * This function returns the number of broadcast listeners that have set the
1130 * NETLINK_RECV_NO_ENOBUFS socket option.
1113 */ 1131 */
1114void netlink_set_err(struct sock *ssk, u32 pid, u32 group, int code) 1132int netlink_set_err(struct sock *ssk, u32 pid, u32 group, int code)
1115{ 1133{
1116 struct netlink_set_err_data info; 1134 struct netlink_set_err_data info;
1117 struct hlist_node *node; 1135 struct hlist_node *node;
1118 struct sock *sk; 1136 struct sock *sk;
1137 int ret = 0;
1119 1138
1120 info.exclude_sk = ssk; 1139 info.exclude_sk = ssk;
1121 info.pid = pid; 1140 info.pid = pid;
@@ -1126,9 +1145,10 @@ void netlink_set_err(struct sock *ssk, u32 pid, u32 group, int code)
1126 read_lock(&nl_table_lock); 1145 read_lock(&nl_table_lock);
1127 1146
1128 sk_for_each_bound(sk, node, &nl_table[ssk->sk_protocol].mc_list) 1147 sk_for_each_bound(sk, node, &nl_table[ssk->sk_protocol].mc_list)
1129 do_one_set_err(sk, &info); 1148 ret += do_one_set_err(sk, &info);
1130 1149
1131 read_unlock(&nl_table_lock); 1150 read_unlock(&nl_table_lock);
1151 return ret;
1132} 1152}
1133EXPORT_SYMBOL(netlink_set_err); 1153EXPORT_SYMBOL(netlink_set_err);
1134 1154
@@ -1972,12 +1992,12 @@ static int netlink_seq_show(struct seq_file *seq, void *v)
1972 if (v == SEQ_START_TOKEN) 1992 if (v == SEQ_START_TOKEN)
1973 seq_puts(seq, 1993 seq_puts(seq,
1974 "sk Eth Pid Groups " 1994 "sk Eth Pid Groups "
1975 "Rmem Wmem Dump Locks Drops\n"); 1995 "Rmem Wmem Dump Locks Drops Inode\n");
1976 else { 1996 else {
1977 struct sock *s = v; 1997 struct sock *s = v;
1978 struct netlink_sock *nlk = nlk_sk(s); 1998 struct netlink_sock *nlk = nlk_sk(s);
1979 1999
1980 seq_printf(seq, "%p %-3d %-6d %08x %-8d %-8d %p %-8d %-8d\n", 2000 seq_printf(seq, "%p %-3d %-6d %08x %-8d %-8d %p %-8d %-8d %-8lu\n",
1981 s, 2001 s,
1982 s->sk_protocol, 2002 s->sk_protocol,
1983 nlk->pid, 2003 nlk->pid,
@@ -1986,7 +2006,8 @@ static int netlink_seq_show(struct seq_file *seq, void *v)
1986 sk_wmem_alloc_get(s), 2006 sk_wmem_alloc_get(s),
1987 nlk->cb, 2007 nlk->cb,
1988 atomic_read(&s->sk_refcnt), 2008 atomic_read(&s->sk_refcnt),
1989 atomic_read(&s->sk_drops) 2009 atomic_read(&s->sk_drops),
2010 sock_i_ino(s)
1990 ); 2011 );
1991 2012
1992 } 2013 }
@@ -2050,7 +2071,7 @@ static const struct proto_ops netlink_ops = {
2050 .sendpage = sock_no_sendpage, 2071 .sendpage = sock_no_sendpage,
2051}; 2072};
2052 2073
2053static struct net_proto_family netlink_family_ops = { 2074static const struct net_proto_family netlink_family_ops = {
2054 .family = PF_NETLINK, 2075 .family = PF_NETLINK,
2055 .create = netlink_create, 2076 .create = netlink_create,
2056 .owner = THIS_MODULE, /* for consistency 8) */ 2077 .owner = THIS_MODULE, /* for consistency 8) */
diff --git a/net/netlink/genetlink.c b/net/netlink/genetlink.c
index 44ff3f3810fa..06438fa2b1e5 100644
--- a/net/netlink/genetlink.c
+++ b/net/netlink/genetlink.c
@@ -8,6 +8,7 @@
8 8
9#include <linux/module.h> 9#include <linux/module.h>
10#include <linux/kernel.h> 10#include <linux/kernel.h>
11#include <linux/slab.h>
11#include <linux/errno.h> 12#include <linux/errno.h>
12#include <linux/types.h> 13#include <linux/types.h>
13#include <linux/socket.h> 14#include <linux/socket.h>
@@ -97,25 +98,17 @@ static struct genl_ops *genl_get_cmd(u8 cmd, struct genl_family *family)
97*/ 98*/
98static inline u16 genl_generate_id(void) 99static inline u16 genl_generate_id(void)
99{ 100{
100 static u16 id_gen_idx; 101 static u16 id_gen_idx = GENL_MIN_ID;
101 int overflowed = 0; 102 int i;
102 103
103 do { 104 for (i = 0; i <= GENL_MAX_ID - GENL_MIN_ID; i++) {
104 if (id_gen_idx == 0) 105 if (!genl_family_find_byid(id_gen_idx))
106 return id_gen_idx;
107 if (++id_gen_idx > GENL_MAX_ID)
105 id_gen_idx = GENL_MIN_ID; 108 id_gen_idx = GENL_MIN_ID;
109 }
106 110
107 if (++id_gen_idx > GENL_MAX_ID) { 111 return 0;
108 if (!overflowed) {
109 overflowed = 1;
110 id_gen_idx = 0;
111 continue;
112 } else
113 return 0;
114 }
115
116 } while (genl_family_find_byid(id_gen_idx));
117
118 return id_gen_idx;
119} 112}
120 113
121static struct genl_multicast_group notify_grp; 114static struct genl_multicast_group notify_grp;
@@ -374,11 +367,6 @@ int genl_register_family(struct genl_family *family)
374 goto errout_locked; 367 goto errout_locked;
375 } 368 }
376 369
377 if (genl_family_find_byid(family->id)) {
378 err = -EEXIST;
379 goto errout_locked;
380 }
381
382 if (family->id == GENL_ID_GENERATE) { 370 if (family->id == GENL_ID_GENERATE) {
383 u16 newid = genl_generate_id(); 371 u16 newid = genl_generate_id();
384 372
@@ -388,6 +376,9 @@ int genl_register_family(struct genl_family *family)
388 } 376 }
389 377
390 family->id = newid; 378 family->id = newid;
379 } else if (genl_family_find_byid(family->id)) {
380 err = -EEXIST;
381 goto errout_locked;
391 } 382 }
392 383
393 if (family->maxattr) { 384 if (family->maxattr) {
@@ -691,9 +682,7 @@ static int ctrl_dumpfamily(struct sk_buff *skb, struct netlink_callback *cb)
691 int chains_to_skip = cb->args[0]; 682 int chains_to_skip = cb->args[0];
692 int fams_to_skip = cb->args[1]; 683 int fams_to_skip = cb->args[1];
693 684
694 for (i = 0; i < GENL_FAM_TAB_SIZE; i++) { 685 for (i = chains_to_skip; i < GENL_FAM_TAB_SIZE; i++) {
695 if (i < chains_to_skip)
696 continue;
697 n = 0; 686 n = 0;
698 list_for_each_entry(rt, genl_family_chain(i), family_list) { 687 list_for_each_entry(rt, genl_family_chain(i), family_list) {
699 if (!rt->netnsok && !net_eq(net, &init_net)) 688 if (!rt->netnsok && !net_eq(net, &init_net))
diff --git a/net/netrom/af_netrom.c b/net/netrom/af_netrom.c
index 7a834952f67f..fa07f044b599 100644
--- a/net/netrom/af_netrom.c
+++ b/net/netrom/af_netrom.c
@@ -15,6 +15,7 @@
15#include <linux/types.h> 15#include <linux/types.h>
16#include <linux/socket.h> 16#include <linux/socket.h>
17#include <linux/in.h> 17#include <linux/in.h>
18#include <linux/slab.h>
18#include <linux/kernel.h> 19#include <linux/kernel.h>
19#include <linux/sched.h> 20#include <linux/sched.h>
20#include <linux/timer.h> 21#include <linux/timer.h>
@@ -425,12 +426,13 @@ static struct proto nr_proto = {
425 .obj_size = sizeof(struct nr_sock), 426 .obj_size = sizeof(struct nr_sock),
426}; 427};
427 428
428static int nr_create(struct net *net, struct socket *sock, int protocol) 429static int nr_create(struct net *net, struct socket *sock, int protocol,
430 int kern)
429{ 431{
430 struct sock *sk; 432 struct sock *sk;
431 struct nr_sock *nr; 433 struct nr_sock *nr;
432 434
433 if (net != &init_net) 435 if (!net_eq(net, &init_net))
434 return -EAFNOSUPPORT; 436 return -EAFNOSUPPORT;
435 437
436 if (sock->type != SOCK_SEQPACKET || protocol != 0) 438 if (sock->type != SOCK_SEQPACKET || protocol != 0)
@@ -1266,28 +1268,13 @@ static int nr_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
1266 1268
1267static void *nr_info_start(struct seq_file *seq, loff_t *pos) 1269static void *nr_info_start(struct seq_file *seq, loff_t *pos)
1268{ 1270{
1269 struct sock *s;
1270 struct hlist_node *node;
1271 int i = 1;
1272
1273 spin_lock_bh(&nr_list_lock); 1271 spin_lock_bh(&nr_list_lock);
1274 if (*pos == 0) 1272 return seq_hlist_start_head(&nr_list, *pos);
1275 return SEQ_START_TOKEN;
1276
1277 sk_for_each(s, node, &nr_list) {
1278 if (i == *pos)
1279 return s;
1280 ++i;
1281 }
1282 return NULL;
1283} 1273}
1284 1274
1285static void *nr_info_next(struct seq_file *seq, void *v, loff_t *pos) 1275static void *nr_info_next(struct seq_file *seq, void *v, loff_t *pos)
1286{ 1276{
1287 ++*pos; 1277 return seq_hlist_next(v, &nr_list, pos);
1288
1289 return (v == SEQ_START_TOKEN) ? sk_head(&nr_list)
1290 : sk_next((struct sock *)v);
1291} 1278}
1292 1279
1293static void nr_info_stop(struct seq_file *seq, void *v) 1280static void nr_info_stop(struct seq_file *seq, void *v)
@@ -1297,7 +1284,7 @@ static void nr_info_stop(struct seq_file *seq, void *v)
1297 1284
1298static int nr_info_show(struct seq_file *seq, void *v) 1285static int nr_info_show(struct seq_file *seq, void *v)
1299{ 1286{
1300 struct sock *s = v; 1287 struct sock *s = sk_entry(v);
1301 struct net_device *dev; 1288 struct net_device *dev;
1302 struct nr_sock *nr; 1289 struct nr_sock *nr;
1303 const char *devname; 1290 const char *devname;
@@ -1372,7 +1359,7 @@ static const struct file_operations nr_info_fops = {
1372}; 1359};
1373#endif /* CONFIG_PROC_FS */ 1360#endif /* CONFIG_PROC_FS */
1374 1361
1375static struct net_proto_family nr_family_ops = { 1362static const struct net_proto_family nr_family_ops = {
1376 .family = PF_NETROM, 1363 .family = PF_NETROM,
1377 .create = nr_create, 1364 .create = nr_create,
1378 .owner = THIS_MODULE, 1365 .owner = THIS_MODULE,
diff --git a/net/netrom/nr_dev.c b/net/netrom/nr_dev.c
index 7aa11b01b2e2..64e6dde9749d 100644
--- a/net/netrom/nr_dev.c
+++ b/net/netrom/nr_dev.c
@@ -19,6 +19,7 @@
19#include <linux/fcntl.h> 19#include <linux/fcntl.h>
20#include <linux/in.h> 20#include <linux/in.h>
21#include <linux/if_ether.h> /* For the statistics structure. */ 21#include <linux/if_ether.h> /* For the statistics structure. */
22#include <linux/slab.h>
22 23
23#include <asm/system.h> 24#include <asm/system.h>
24#include <asm/uaccess.h> 25#include <asm/uaccess.h>
diff --git a/net/netrom/nr_in.c b/net/netrom/nr_in.c
index 68176483617f..6d4ef6d65b3d 100644
--- a/net/netrom/nr_in.c
+++ b/net/netrom/nr_in.c
@@ -16,6 +16,7 @@
16#include <linux/string.h> 16#include <linux/string.h>
17#include <linux/sockios.h> 17#include <linux/sockios.h>
18#include <linux/net.h> 18#include <linux/net.h>
19#include <linux/slab.h>
19#include <net/ax25.h> 20#include <net/ax25.h>
20#include <linux/inet.h> 21#include <linux/inet.h>
21#include <linux/netdevice.h> 22#include <linux/netdevice.h>
diff --git a/net/netrom/nr_loopback.c b/net/netrom/nr_loopback.c
index f324d5df4186..94d4e922af53 100644
--- a/net/netrom/nr_loopback.c
+++ b/net/netrom/nr_loopback.c
@@ -7,6 +7,7 @@
7 * Copyright Tomi Manninen OH2BNS (oh2bns@sral.fi) 7 * Copyright Tomi Manninen OH2BNS (oh2bns@sral.fi)
8 */ 8 */
9#include <linux/types.h> 9#include <linux/types.h>
10#include <linux/slab.h>
10#include <linux/socket.h> 11#include <linux/socket.h>
11#include <linux/timer.h> 12#include <linux/timer.h>
12#include <net/ax25.h> 13#include <net/ax25.h>
diff --git a/net/netrom/nr_out.c b/net/netrom/nr_out.c
index e3e6c44e1890..607fddb4fdbb 100644
--- a/net/netrom/nr_out.c
+++ b/net/netrom/nr_out.c
@@ -16,6 +16,7 @@
16#include <linux/string.h> 16#include <linux/string.h>
17#include <linux/sockios.h> 17#include <linux/sockios.h>
18#include <linux/net.h> 18#include <linux/net.h>
19#include <linux/slab.h>
19#include <net/ax25.h> 20#include <net/ax25.h>
20#include <linux/inet.h> 21#include <linux/inet.h>
21#include <linux/netdevice.h> 22#include <linux/netdevice.h>
diff --git a/net/netrom/nr_route.c b/net/netrom/nr_route.c
index 4eb1ac9a7679..44059d0c8dd1 100644
--- a/net/netrom/nr_route.c
+++ b/net/netrom/nr_route.c
@@ -17,6 +17,7 @@
17#include <linux/string.h> 17#include <linux/string.h>
18#include <linux/sockios.h> 18#include <linux/sockios.h>
19#include <linux/net.h> 19#include <linux/net.h>
20#include <linux/slab.h>
20#include <net/ax25.h> 21#include <net/ax25.h>
21#include <linux/inet.h> 22#include <linux/inet.h>
22#include <linux/netdevice.h> 23#include <linux/netdevice.h>
@@ -597,15 +598,15 @@ struct net_device *nr_dev_first(void)
597{ 598{
598 struct net_device *dev, *first = NULL; 599 struct net_device *dev, *first = NULL;
599 600
600 read_lock(&dev_base_lock); 601 rcu_read_lock();
601 for_each_netdev(&init_net, dev) { 602 for_each_netdev_rcu(&init_net, dev) {
602 if ((dev->flags & IFF_UP) && dev->type == ARPHRD_NETROM) 603 if ((dev->flags & IFF_UP) && dev->type == ARPHRD_NETROM)
603 if (first == NULL || strncmp(dev->name, first->name, 3) < 0) 604 if (first == NULL || strncmp(dev->name, first->name, 3) < 0)
604 first = dev; 605 first = dev;
605 } 606 }
606 if (first) 607 if (first)
607 dev_hold(first); 608 dev_hold(first);
608 read_unlock(&dev_base_lock); 609 rcu_read_unlock();
609 610
610 return first; 611 return first;
611} 612}
@@ -617,16 +618,17 @@ struct net_device *nr_dev_get(ax25_address *addr)
617{ 618{
618 struct net_device *dev; 619 struct net_device *dev;
619 620
620 read_lock(&dev_base_lock); 621 rcu_read_lock();
621 for_each_netdev(&init_net, dev) { 622 for_each_netdev_rcu(&init_net, dev) {
622 if ((dev->flags & IFF_UP) && dev->type == ARPHRD_NETROM && ax25cmp(addr, (ax25_address *)dev->dev_addr) == 0) { 623 if ((dev->flags & IFF_UP) && dev->type == ARPHRD_NETROM &&
624 ax25cmp(addr, (ax25_address *)dev->dev_addr) == 0) {
623 dev_hold(dev); 625 dev_hold(dev);
624 goto out; 626 goto out;
625 } 627 }
626 } 628 }
627 dev = NULL; 629 dev = NULL;
628out: 630out:
629 read_unlock(&dev_base_lock); 631 rcu_read_unlock();
630 return dev; 632 return dev;
631} 633}
632 634
@@ -842,12 +844,13 @@ int nr_route_frame(struct sk_buff *skb, ax25_cb *ax25)
842 dptr = skb_push(skb, 1); 844 dptr = skb_push(skb, 1);
843 *dptr = AX25_P_NETROM; 845 *dptr = AX25_P_NETROM;
844 846
845 ax25s = ax25_send_frame(skb, 256, (ax25_address *)dev->dev_addr, &nr_neigh->callsign, nr_neigh->digipeat, nr_neigh->dev); 847 ax25s = nr_neigh->ax25;
846 if (nr_neigh->ax25 && ax25s) { 848 nr_neigh->ax25 = ax25_send_frame(skb, 256,
847 /* We were already holding this ax25_cb */ 849 (ax25_address *)dev->dev_addr,
850 &nr_neigh->callsign,
851 nr_neigh->digipeat, nr_neigh->dev);
852 if (ax25s)
848 ax25_cb_put(ax25s); 853 ax25_cb_put(ax25s);
849 }
850 nr_neigh->ax25 = ax25s;
851 854
852 dev_put(dev); 855 dev_put(dev);
853 ret = (nr_neigh->ax25 != NULL); 856 ret = (nr_neigh->ax25 != NULL);
@@ -861,33 +864,13 @@ int nr_route_frame(struct sk_buff *skb, ax25_cb *ax25)
861 864
862static void *nr_node_start(struct seq_file *seq, loff_t *pos) 865static void *nr_node_start(struct seq_file *seq, loff_t *pos)
863{ 866{
864 struct nr_node *nr_node;
865 struct hlist_node *node;
866 int i = 1;
867
868 spin_lock_bh(&nr_node_list_lock); 867 spin_lock_bh(&nr_node_list_lock);
869 if (*pos == 0) 868 return seq_hlist_start_head(&nr_node_list, *pos);
870 return SEQ_START_TOKEN;
871
872 nr_node_for_each(nr_node, node, &nr_node_list) {
873 if (i == *pos)
874 return nr_node;
875 ++i;
876 }
877
878 return NULL;
879} 869}
880 870
881static void *nr_node_next(struct seq_file *seq, void *v, loff_t *pos) 871static void *nr_node_next(struct seq_file *seq, void *v, loff_t *pos)
882{ 872{
883 struct hlist_node *node; 873 return seq_hlist_next(v, &nr_node_list, pos);
884 ++*pos;
885
886 node = (v == SEQ_START_TOKEN)
887 ? nr_node_list.first
888 : ((struct nr_node *)v)->node_node.next;
889
890 return hlist_entry(node, struct nr_node, node_node);
891} 874}
892 875
893static void nr_node_stop(struct seq_file *seq, void *v) 876static void nr_node_stop(struct seq_file *seq, void *v)
@@ -904,7 +887,9 @@ static int nr_node_show(struct seq_file *seq, void *v)
904 seq_puts(seq, 887 seq_puts(seq,
905 "callsign mnemonic w n qual obs neigh qual obs neigh qual obs neigh\n"); 888 "callsign mnemonic w n qual obs neigh qual obs neigh qual obs neigh\n");
906 else { 889 else {
907 struct nr_node *nr_node = v; 890 struct nr_node *nr_node = hlist_entry(v, struct nr_node,
891 node_node);
892
908 nr_node_lock(nr_node); 893 nr_node_lock(nr_node);
909 seq_printf(seq, "%-9s %-7s %d %d", 894 seq_printf(seq, "%-9s %-7s %d %d",
910 ax2asc(buf, &nr_node->callsign), 895 ax2asc(buf, &nr_node->callsign),
@@ -947,31 +932,13 @@ const struct file_operations nr_nodes_fops = {
947 932
948static void *nr_neigh_start(struct seq_file *seq, loff_t *pos) 933static void *nr_neigh_start(struct seq_file *seq, loff_t *pos)
949{ 934{
950 struct nr_neigh *nr_neigh;
951 struct hlist_node *node;
952 int i = 1;
953
954 spin_lock_bh(&nr_neigh_list_lock); 935 spin_lock_bh(&nr_neigh_list_lock);
955 if (*pos == 0) 936 return seq_hlist_start_head(&nr_neigh_list, *pos);
956 return SEQ_START_TOKEN;
957
958 nr_neigh_for_each(nr_neigh, node, &nr_neigh_list) {
959 if (i == *pos)
960 return nr_neigh;
961 }
962 return NULL;
963} 937}
964 938
965static void *nr_neigh_next(struct seq_file *seq, void *v, loff_t *pos) 939static void *nr_neigh_next(struct seq_file *seq, void *v, loff_t *pos)
966{ 940{
967 struct hlist_node *node; 941 return seq_hlist_next(v, &nr_neigh_list, pos);
968 ++*pos;
969
970 node = (v == SEQ_START_TOKEN)
971 ? nr_neigh_list.first
972 : ((struct nr_neigh *)v)->neigh_node.next;
973
974 return hlist_entry(node, struct nr_neigh, neigh_node);
975} 942}
976 943
977static void nr_neigh_stop(struct seq_file *seq, void *v) 944static void nr_neigh_stop(struct seq_file *seq, void *v)
@@ -987,8 +954,9 @@ static int nr_neigh_show(struct seq_file *seq, void *v)
987 if (v == SEQ_START_TOKEN) 954 if (v == SEQ_START_TOKEN)
988 seq_puts(seq, "addr callsign dev qual lock count failed digipeaters\n"); 955 seq_puts(seq, "addr callsign dev qual lock count failed digipeaters\n");
989 else { 956 else {
990 struct nr_neigh *nr_neigh = v; 957 struct nr_neigh *nr_neigh;
991 958
959 nr_neigh = hlist_entry(v, struct nr_neigh, neigh_node);
992 seq_printf(seq, "%05d %-9s %-4s %3d %d %3d %3d", 960 seq_printf(seq, "%05d %-9s %-4s %3d %d %3d %3d",
993 nr_neigh->number, 961 nr_neigh->number,
994 ax2asc(buf, &nr_neigh->callsign), 962 ax2asc(buf, &nr_neigh->callsign),
diff --git a/net/netrom/nr_subr.c b/net/netrom/nr_subr.c
index 04e7d0d2fd8f..6a947ae50dbd 100644
--- a/net/netrom/nr_subr.c
+++ b/net/netrom/nr_subr.c
@@ -15,6 +15,7 @@
15#include <linux/string.h> 15#include <linux/string.h>
16#include <linux/sockios.h> 16#include <linux/sockios.h>
17#include <linux/net.h> 17#include <linux/net.h>
18#include <linux/slab.h>
18#include <net/ax25.h> 19#include <net/ax25.h>
19#include <linux/inet.h> 20#include <linux/inet.h>
20#include <linux/netdevice.h> 21#include <linux/netdevice.h>
diff --git a/net/netrom/sysctl_net_netrom.c b/net/netrom/sysctl_net_netrom.c
index 7b49591fe87c..1e0fa9e57aac 100644
--- a/net/netrom/sysctl_net_netrom.c
+++ b/net/netrom/sysctl_net_netrom.c
@@ -36,143 +36,119 @@ static struct ctl_table_header *nr_table_header;
36 36
37static ctl_table nr_table[] = { 37static ctl_table nr_table[] = {
38 { 38 {
39 .ctl_name = NET_NETROM_DEFAULT_PATH_QUALITY,
40 .procname = "default_path_quality", 39 .procname = "default_path_quality",
41 .data = &sysctl_netrom_default_path_quality, 40 .data = &sysctl_netrom_default_path_quality,
42 .maxlen = sizeof(int), 41 .maxlen = sizeof(int),
43 .mode = 0644, 42 .mode = 0644,
44 .proc_handler = proc_dointvec_minmax, 43 .proc_handler = proc_dointvec_minmax,
45 .strategy = sysctl_intvec,
46 .extra1 = &min_quality, 44 .extra1 = &min_quality,
47 .extra2 = &max_quality 45 .extra2 = &max_quality
48 }, 46 },
49 { 47 {
50 .ctl_name = NET_NETROM_OBSOLESCENCE_COUNT_INITIALISER,
51 .procname = "obsolescence_count_initialiser", 48 .procname = "obsolescence_count_initialiser",
52 .data = &sysctl_netrom_obsolescence_count_initialiser, 49 .data = &sysctl_netrom_obsolescence_count_initialiser,
53 .maxlen = sizeof(int), 50 .maxlen = sizeof(int),
54 .mode = 0644, 51 .mode = 0644,
55 .proc_handler = proc_dointvec_minmax, 52 .proc_handler = proc_dointvec_minmax,
56 .strategy = sysctl_intvec,
57 .extra1 = &min_obs, 53 .extra1 = &min_obs,
58 .extra2 = &max_obs 54 .extra2 = &max_obs
59 }, 55 },
60 { 56 {
61 .ctl_name = NET_NETROM_NETWORK_TTL_INITIALISER,
62 .procname = "network_ttl_initialiser", 57 .procname = "network_ttl_initialiser",
63 .data = &sysctl_netrom_network_ttl_initialiser, 58 .data = &sysctl_netrom_network_ttl_initialiser,
64 .maxlen = sizeof(int), 59 .maxlen = sizeof(int),
65 .mode = 0644, 60 .mode = 0644,
66 .proc_handler = proc_dointvec_minmax, 61 .proc_handler = proc_dointvec_minmax,
67 .strategy = sysctl_intvec,
68 .extra1 = &min_ttl, 62 .extra1 = &min_ttl,
69 .extra2 = &max_ttl 63 .extra2 = &max_ttl
70 }, 64 },
71 { 65 {
72 .ctl_name = NET_NETROM_TRANSPORT_TIMEOUT,
73 .procname = "transport_timeout", 66 .procname = "transport_timeout",
74 .data = &sysctl_netrom_transport_timeout, 67 .data = &sysctl_netrom_transport_timeout,
75 .maxlen = sizeof(int), 68 .maxlen = sizeof(int),
76 .mode = 0644, 69 .mode = 0644,
77 .proc_handler = proc_dointvec_minmax, 70 .proc_handler = proc_dointvec_minmax,
78 .strategy = sysctl_intvec,
79 .extra1 = &min_t1, 71 .extra1 = &min_t1,
80 .extra2 = &max_t1 72 .extra2 = &max_t1
81 }, 73 },
82 { 74 {
83 .ctl_name = NET_NETROM_TRANSPORT_MAXIMUM_TRIES,
84 .procname = "transport_maximum_tries", 75 .procname = "transport_maximum_tries",
85 .data = &sysctl_netrom_transport_maximum_tries, 76 .data = &sysctl_netrom_transport_maximum_tries,
86 .maxlen = sizeof(int), 77 .maxlen = sizeof(int),
87 .mode = 0644, 78 .mode = 0644,
88 .proc_handler = proc_dointvec_minmax, 79 .proc_handler = proc_dointvec_minmax,
89 .strategy = sysctl_intvec,
90 .extra1 = &min_n2, 80 .extra1 = &min_n2,
91 .extra2 = &max_n2 81 .extra2 = &max_n2
92 }, 82 },
93 { 83 {
94 .ctl_name = NET_NETROM_TRANSPORT_ACKNOWLEDGE_DELAY,
95 .procname = "transport_acknowledge_delay", 84 .procname = "transport_acknowledge_delay",
96 .data = &sysctl_netrom_transport_acknowledge_delay, 85 .data = &sysctl_netrom_transport_acknowledge_delay,
97 .maxlen = sizeof(int), 86 .maxlen = sizeof(int),
98 .mode = 0644, 87 .mode = 0644,
99 .proc_handler = proc_dointvec_minmax, 88 .proc_handler = proc_dointvec_minmax,
100 .strategy = sysctl_intvec,
101 .extra1 = &min_t2, 89 .extra1 = &min_t2,
102 .extra2 = &max_t2 90 .extra2 = &max_t2
103 }, 91 },
104 { 92 {
105 .ctl_name = NET_NETROM_TRANSPORT_BUSY_DELAY,
106 .procname = "transport_busy_delay", 93 .procname = "transport_busy_delay",
107 .data = &sysctl_netrom_transport_busy_delay, 94 .data = &sysctl_netrom_transport_busy_delay,
108 .maxlen = sizeof(int), 95 .maxlen = sizeof(int),
109 .mode = 0644, 96 .mode = 0644,
110 .proc_handler = proc_dointvec_minmax, 97 .proc_handler = proc_dointvec_minmax,
111 .strategy = sysctl_intvec,
112 .extra1 = &min_t4, 98 .extra1 = &min_t4,
113 .extra2 = &max_t4 99 .extra2 = &max_t4
114 }, 100 },
115 { 101 {
116 .ctl_name = NET_NETROM_TRANSPORT_REQUESTED_WINDOW_SIZE,
117 .procname = "transport_requested_window_size", 102 .procname = "transport_requested_window_size",
118 .data = &sysctl_netrom_transport_requested_window_size, 103 .data = &sysctl_netrom_transport_requested_window_size,
119 .maxlen = sizeof(int), 104 .maxlen = sizeof(int),
120 .mode = 0644, 105 .mode = 0644,
121 .proc_handler = proc_dointvec_minmax, 106 .proc_handler = proc_dointvec_minmax,
122 .strategy = sysctl_intvec,
123 .extra1 = &min_window, 107 .extra1 = &min_window,
124 .extra2 = &max_window 108 .extra2 = &max_window
125 }, 109 },
126 { 110 {
127 .ctl_name = NET_NETROM_TRANSPORT_NO_ACTIVITY_TIMEOUT,
128 .procname = "transport_no_activity_timeout", 111 .procname = "transport_no_activity_timeout",
129 .data = &sysctl_netrom_transport_no_activity_timeout, 112 .data = &sysctl_netrom_transport_no_activity_timeout,
130 .maxlen = sizeof(int), 113 .maxlen = sizeof(int),
131 .mode = 0644, 114 .mode = 0644,
132 .proc_handler = proc_dointvec_minmax, 115 .proc_handler = proc_dointvec_minmax,
133 .strategy = sysctl_intvec,
134 .extra1 = &min_idle, 116 .extra1 = &min_idle,
135 .extra2 = &max_idle 117 .extra2 = &max_idle
136 }, 118 },
137 { 119 {
138 .ctl_name = NET_NETROM_ROUTING_CONTROL,
139 .procname = "routing_control", 120 .procname = "routing_control",
140 .data = &sysctl_netrom_routing_control, 121 .data = &sysctl_netrom_routing_control,
141 .maxlen = sizeof(int), 122 .maxlen = sizeof(int),
142 .mode = 0644, 123 .mode = 0644,
143 .proc_handler = proc_dointvec_minmax, 124 .proc_handler = proc_dointvec_minmax,
144 .strategy = sysctl_intvec,
145 .extra1 = &min_route, 125 .extra1 = &min_route,
146 .extra2 = &max_route 126 .extra2 = &max_route
147 }, 127 },
148 { 128 {
149 .ctl_name = NET_NETROM_LINK_FAILS_COUNT,
150 .procname = "link_fails_count", 129 .procname = "link_fails_count",
151 .data = &sysctl_netrom_link_fails_count, 130 .data = &sysctl_netrom_link_fails_count,
152 .maxlen = sizeof(int), 131 .maxlen = sizeof(int),
153 .mode = 0644, 132 .mode = 0644,
154 .proc_handler = proc_dointvec_minmax, 133 .proc_handler = proc_dointvec_minmax,
155 .strategy = sysctl_intvec,
156 .extra1 = &min_fails, 134 .extra1 = &min_fails,
157 .extra2 = &max_fails 135 .extra2 = &max_fails
158 }, 136 },
159 { 137 {
160 .ctl_name = NET_NETROM_RESET,
161 .procname = "reset", 138 .procname = "reset",
162 .data = &sysctl_netrom_reset_circuit, 139 .data = &sysctl_netrom_reset_circuit,
163 .maxlen = sizeof(int), 140 .maxlen = sizeof(int),
164 .mode = 0644, 141 .mode = 0644,
165 .proc_handler = proc_dointvec_minmax, 142 .proc_handler = proc_dointvec_minmax,
166 .strategy = sysctl_intvec,
167 .extra1 = &min_reset, 143 .extra1 = &min_reset,
168 .extra2 = &max_reset 144 .extra2 = &max_reset
169 }, 145 },
170 { .ctl_name = 0 } 146 { }
171}; 147};
172 148
173static struct ctl_path nr_path[] = { 149static struct ctl_path nr_path[] = {
174 { .procname = "net", .ctl_name = CTL_NET, }, 150 { .procname = "net", },
175 { .procname = "netrom", .ctl_name = NET_NETROM, }, 151 { .procname = "netrom", },
176 { } 152 { }
177}; 153};
178 154
diff --git a/net/packet/Kconfig b/net/packet/Kconfig
index 34ff93ff894d..0060e3b396b7 100644
--- a/net/packet/Kconfig
+++ b/net/packet/Kconfig
@@ -14,13 +14,3 @@ config PACKET
14 be called af_packet. 14 be called af_packet.
15 15
16 If unsure, say Y. 16 If unsure, say Y.
17
18config PACKET_MMAP
19 bool "Packet socket: mmapped IO"
20 depends on PACKET
21 help
22 If you say Y here, the Packet protocol driver will use an IO
23 mechanism that results in faster communication.
24
25 If unsure, say N.
26
diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
index f2d116a5cb35..243946d4809d 100644
--- a/net/packet/af_packet.c
+++ b/net/packet/af_packet.c
@@ -60,6 +60,7 @@
60#include <linux/wireless.h> 60#include <linux/wireless.h>
61#include <linux/kernel.h> 61#include <linux/kernel.h>
62#include <linux/kmod.h> 62#include <linux/kmod.h>
63#include <linux/slab.h>
63#include <net/net_namespace.h> 64#include <net/net_namespace.h>
64#include <net/ip.h> 65#include <net/ip.h>
65#include <net/protocol.h> 66#include <net/protocol.h>
@@ -79,6 +80,8 @@
79#include <linux/module.h> 80#include <linux/module.h>
80#include <linux/init.h> 81#include <linux/init.h>
81#include <linux/mutex.h> 82#include <linux/mutex.h>
83#include <linux/if_vlan.h>
84#include <linux/virtio_net.h>
82 85
83#ifdef CONFIG_INET 86#ifdef CONFIG_INET
84#include <net/inet_common.h> 87#include <net/inet_common.h>
@@ -155,7 +158,6 @@ struct packet_mreq_max {
155 unsigned char mr_address[MAX_ADDR_LEN]; 158 unsigned char mr_address[MAX_ADDR_LEN];
156}; 159};
157 160
158#ifdef CONFIG_PACKET_MMAP
159static int packet_set_ring(struct sock *sk, struct tpacket_req *req, 161static int packet_set_ring(struct sock *sk, struct tpacket_req *req,
160 int closing, int tx_ring); 162 int closing, int tx_ring);
161 163
@@ -175,7 +177,6 @@ struct packet_ring_buffer {
175 177
176struct packet_sock; 178struct packet_sock;
177static int tpacket_snd(struct packet_sock *po, struct msghdr *msg); 179static int tpacket_snd(struct packet_sock *po, struct msghdr *msg);
178#endif
179 180
180static void packet_flush_mclist(struct sock *sk); 181static void packet_flush_mclist(struct sock *sk);
181 182
@@ -183,27 +184,24 @@ struct packet_sock {
183 /* struct sock has to be the first member of packet_sock */ 184 /* struct sock has to be the first member of packet_sock */
184 struct sock sk; 185 struct sock sk;
185 struct tpacket_stats stats; 186 struct tpacket_stats stats;
186#ifdef CONFIG_PACKET_MMAP
187 struct packet_ring_buffer rx_ring; 187 struct packet_ring_buffer rx_ring;
188 struct packet_ring_buffer tx_ring; 188 struct packet_ring_buffer tx_ring;
189 int copy_thresh; 189 int copy_thresh;
190#endif
191 struct packet_type prot_hook;
192 spinlock_t bind_lock; 190 spinlock_t bind_lock;
193 struct mutex pg_vec_lock; 191 struct mutex pg_vec_lock;
194 unsigned int running:1, /* prot_hook is attached*/ 192 unsigned int running:1, /* prot_hook is attached*/
195 auxdata:1, 193 auxdata:1,
196 origdev:1; 194 origdev:1,
195 has_vnet_hdr:1;
197 int ifindex; /* bound device */ 196 int ifindex; /* bound device */
198 __be16 num; 197 __be16 num;
199 struct packet_mclist *mclist; 198 struct packet_mclist *mclist;
200#ifdef CONFIG_PACKET_MMAP
201 atomic_t mapped; 199 atomic_t mapped;
202 enum tpacket_versions tp_version; 200 enum tpacket_versions tp_version;
203 unsigned int tp_hdrlen; 201 unsigned int tp_hdrlen;
204 unsigned int tp_reserve; 202 unsigned int tp_reserve;
205 unsigned int tp_loss:1; 203 unsigned int tp_loss:1;
206#endif 204 struct packet_type prot_hook ____cacheline_aligned_in_smp;
207}; 205};
208 206
209struct packet_skb_cb { 207struct packet_skb_cb {
@@ -216,8 +214,6 @@ struct packet_skb_cb {
216 214
217#define PACKET_SKB_CB(__skb) ((struct packet_skb_cb *)((__skb)->cb)) 215#define PACKET_SKB_CB(__skb) ((struct packet_skb_cb *)((__skb)->cb))
218 216
219#ifdef CONFIG_PACKET_MMAP
220
221static void __packet_set_status(struct packet_sock *po, void *frame, int status) 217static void __packet_set_status(struct packet_sock *po, void *frame, int status)
222{ 218{
223 union { 219 union {
@@ -312,8 +308,6 @@ static inline void packet_increment_head(struct packet_ring_buffer *buff)
312 buff->head = buff->head != buff->frame_max ? buff->head+1 : 0; 308 buff->head = buff->head != buff->frame_max ? buff->head+1 : 0;
313} 309}
314 310
315#endif
316
317static inline struct packet_sock *pkt_sk(struct sock *sk) 311static inline struct packet_sock *pkt_sk(struct sock *sk)
318{ 312{
319 return (struct packet_sock *)sk; 313 return (struct packet_sock *)sk;
@@ -364,7 +358,7 @@ static int packet_rcv_spkt(struct sk_buff *skb, struct net_device *dev,
364 if (skb->pkt_type == PACKET_LOOPBACK) 358 if (skb->pkt_type == PACKET_LOOPBACK)
365 goto out; 359 goto out;
366 360
367 if (dev_net(dev) != sock_net(sk)) 361 if (!net_eq(dev_net(dev), sock_net(sk)))
368 goto out; 362 goto out;
369 363
370 skb = skb_share_check(skb, GFP_ATOMIC); 364 skb = skb_share_check(skb, GFP_ATOMIC);
@@ -414,7 +408,7 @@ static int packet_sendmsg_spkt(struct kiocb *iocb, struct socket *sock,
414{ 408{
415 struct sock *sk = sock->sk; 409 struct sock *sk = sock->sk;
416 struct sockaddr_pkt *saddr = (struct sockaddr_pkt *)msg->msg_name; 410 struct sockaddr_pkt *saddr = (struct sockaddr_pkt *)msg->msg_name;
417 struct sk_buff *skb; 411 struct sk_buff *skb = NULL;
418 struct net_device *dev; 412 struct net_device *dev;
419 __be16 proto = 0; 413 __be16 proto = 0;
420 int err; 414 int err;
@@ -436,7 +430,9 @@ static int packet_sendmsg_spkt(struct kiocb *iocb, struct socket *sock,
436 */ 430 */
437 431
438 saddr->spkt_device[13] = 0; 432 saddr->spkt_device[13] = 0;
439 dev = dev_get_by_name(sock_net(sk), saddr->spkt_device); 433retry:
434 rcu_read_lock();
435 dev = dev_get_by_name_rcu(sock_net(sk), saddr->spkt_device);
440 err = -ENODEV; 436 err = -ENODEV;
441 if (dev == NULL) 437 if (dev == NULL)
442 goto out_unlock; 438 goto out_unlock;
@@ -454,58 +450,48 @@ static int packet_sendmsg_spkt(struct kiocb *iocb, struct socket *sock,
454 if (len > dev->mtu + dev->hard_header_len) 450 if (len > dev->mtu + dev->hard_header_len)
455 goto out_unlock; 451 goto out_unlock;
456 452
457 err = -ENOBUFS; 453 if (!skb) {
458 skb = sock_wmalloc(sk, len + LL_RESERVED_SPACE(dev), 0, GFP_KERNEL); 454 size_t reserved = LL_RESERVED_SPACE(dev);
459 455 unsigned int hhlen = dev->header_ops ? dev->hard_header_len : 0;
460 /* 456
461 * If the write buffer is full, then tough. At this level the user 457 rcu_read_unlock();
462 * gets to deal with the problem - do your own algorithmic backoffs. 458 skb = sock_wmalloc(sk, len + reserved, 0, GFP_KERNEL);
463 * That's far more flexible. 459 if (skb == NULL)
464 */ 460 return -ENOBUFS;
465 461 /* FIXME: Save some space for broken drivers that write a hard
466 if (skb == NULL) 462 * header at transmission time by themselves. PPP is the notable
467 goto out_unlock; 463 * one here. This should really be fixed at the driver level.
468 464 */
469 /* 465 skb_reserve(skb, reserved);
470 * Fill it in 466 skb_reset_network_header(skb);
471 */ 467
472 468 /* Try to align data part correctly */
473 /* FIXME: Save some space for broken drivers that write a 469 if (hhlen) {
474 * hard header at transmission time by themselves. PPP is the 470 skb->data -= hhlen;
475 * notable one here. This should really be fixed at the driver level. 471 skb->tail -= hhlen;
476 */ 472 if (len < hhlen)
477 skb_reserve(skb, LL_RESERVED_SPACE(dev)); 473 skb_reset_network_header(skb);
478 skb_reset_network_header(skb); 474 }
479 475 err = memcpy_fromiovec(skb_put(skb, len), msg->msg_iov, len);
480 /* Try to align data part correctly */ 476 if (err)
481 if (dev->header_ops) { 477 goto out_free;
482 skb->data -= dev->hard_header_len; 478 goto retry;
483 skb->tail -= dev->hard_header_len;
484 if (len < dev->hard_header_len)
485 skb_reset_network_header(skb);
486 } 479 }
487 480
488 /* Returns -EFAULT on error */ 481
489 err = memcpy_fromiovec(skb_put(skb, len), msg->msg_iov, len);
490 skb->protocol = proto; 482 skb->protocol = proto;
491 skb->dev = dev; 483 skb->dev = dev;
492 skb->priority = sk->sk_priority; 484 skb->priority = sk->sk_priority;
493 if (err) 485 skb->mark = sk->sk_mark;
494 goto out_free;
495
496 /*
497 * Now send it
498 */
499 486
500 dev_queue_xmit(skb); 487 dev_queue_xmit(skb);
501 dev_put(dev); 488 rcu_read_unlock();
502 return len; 489 return len;
503 490
491out_unlock:
492 rcu_read_unlock();
504out_free: 493out_free:
505 kfree_skb(skb); 494 kfree_skb(skb);
506out_unlock:
507 if (dev)
508 dev_put(dev);
509 return err; 495 return err;
510} 496}
511 497
@@ -515,7 +501,7 @@ static inline unsigned int run_filter(struct sk_buff *skb, struct sock *sk,
515 struct sk_filter *filter; 501 struct sk_filter *filter;
516 502
517 rcu_read_lock_bh(); 503 rcu_read_lock_bh();
518 filter = rcu_dereference(sk->sk_filter); 504 filter = rcu_dereference_bh(sk->sk_filter);
519 if (filter != NULL) 505 if (filter != NULL)
520 res = sk_run_filter(skb, filter->insns, filter->len); 506 res = sk_run_filter(skb, filter->insns, filter->len);
521 rcu_read_unlock_bh(); 507 rcu_read_unlock_bh();
@@ -551,7 +537,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
551 sk = pt->af_packet_priv; 537 sk = pt->af_packet_priv;
552 po = pkt_sk(sk); 538 po = pkt_sk(sk);
553 539
554 if (dev_net(dev) != sock_net(sk)) 540 if (!net_eq(dev_net(dev), sock_net(sk)))
555 goto drop; 541 goto drop;
556 542
557 skb->dev = dev; 543 skb->dev = dev;
@@ -626,15 +612,14 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
626 612
627 spin_lock(&sk->sk_receive_queue.lock); 613 spin_lock(&sk->sk_receive_queue.lock);
628 po->stats.tp_packets++; 614 po->stats.tp_packets++;
615 skb->dropcount = atomic_read(&sk->sk_drops);
629 __skb_queue_tail(&sk->sk_receive_queue, skb); 616 __skb_queue_tail(&sk->sk_receive_queue, skb);
630 spin_unlock(&sk->sk_receive_queue.lock); 617 spin_unlock(&sk->sk_receive_queue.lock);
631 sk->sk_data_ready(sk, skb->len); 618 sk->sk_data_ready(sk, skb->len);
632 return 0; 619 return 0;
633 620
634drop_n_acct: 621drop_n_acct:
635 spin_lock(&sk->sk_receive_queue.lock); 622 po->stats.tp_drops = atomic_inc_return(&sk->sk_drops);
636 po->stats.tp_drops++;
637 spin_unlock(&sk->sk_receive_queue.lock);
638 623
639drop_n_restore: 624drop_n_restore:
640 if (skb_head != skb->data && skb_shared(skb)) { 625 if (skb_head != skb->data && skb_shared(skb)) {
@@ -646,7 +631,6 @@ drop:
646 return 0; 631 return 0;
647} 632}
648 633
649#ifdef CONFIG_PACKET_MMAP
650static int tpacket_rcv(struct sk_buff *skb, struct net_device *dev, 634static int tpacket_rcv(struct sk_buff *skb, struct net_device *dev,
651 struct packet_type *pt, struct net_device *orig_dev) 635 struct packet_type *pt, struct net_device *orig_dev)
652{ 636{
@@ -673,7 +657,7 @@ static int tpacket_rcv(struct sk_buff *skb, struct net_device *dev,
673 sk = pt->af_packet_priv; 657 sk = pt->af_packet_priv;
674 po = pkt_sk(sk); 658 po = pkt_sk(sk);
675 659
676 if (dev_net(dev) != sock_net(sk)) 660 if (!net_eq(dev_net(dev), sock_net(sk)))
677 goto drop; 661 goto drop;
678 662
679 if (dev->header_ops) { 663 if (dev->header_ops) {
@@ -766,7 +750,7 @@ static int tpacket_rcv(struct sk_buff *skb, struct net_device *dev,
766 getnstimeofday(&ts); 750 getnstimeofday(&ts);
767 h.h2->tp_sec = ts.tv_sec; 751 h.h2->tp_sec = ts.tv_sec;
768 h.h2->tp_nsec = ts.tv_nsec; 752 h.h2->tp_nsec = ts.tv_nsec;
769 h.h2->tp_vlan_tci = skb->vlan_tci; 753 h.h2->tp_vlan_tci = vlan_tx_tag_get(skb);
770 hdrlen = sizeof(*h.h2); 754 hdrlen = sizeof(*h.h2);
771 break; 755 break;
772 default: 756 default:
@@ -856,6 +840,7 @@ static int tpacket_fill_skb(struct packet_sock *po, struct sk_buff *skb,
856 skb->protocol = proto; 840 skb->protocol = proto;
857 skb->dev = dev; 841 skb->dev = dev;
858 skb->priority = po->sk.sk_priority; 842 skb->priority = po->sk.sk_priority;
843 skb->mark = po->sk.sk_mark;
859 skb_shinfo(skb)->destructor_arg = ph.raw; 844 skb_shinfo(skb)->destructor_arg = ph.raw;
860 845
861 switch (po->tp_version) { 846 switch (po->tp_version) {
@@ -1028,20 +1013,30 @@ static int tpacket_snd(struct packet_sock *po, struct msghdr *msg)
1028 1013
1029 status = TP_STATUS_SEND_REQUEST; 1014 status = TP_STATUS_SEND_REQUEST;
1030 err = dev_queue_xmit(skb); 1015 err = dev_queue_xmit(skb);
1031 if (unlikely(err > 0 && (err = net_xmit_errno(err)) != 0)) 1016 if (unlikely(err > 0)) {
1032 goto out_xmit; 1017 err = net_xmit_errno(err);
1018 if (err && __packet_get_status(po, ph) ==
1019 TP_STATUS_AVAILABLE) {
1020 /* skb was destructed already */
1021 skb = NULL;
1022 goto out_status;
1023 }
1024 /*
1025 * skb was dropped but not destructed yet;
1026 * let's treat it like congestion or err < 0
1027 */
1028 err = 0;
1029 }
1033 packet_increment_head(&po->tx_ring); 1030 packet_increment_head(&po->tx_ring);
1034 len_sum += tp_len; 1031 len_sum += tp_len;
1035 } while (likely((ph != NULL) || ((!(msg->msg_flags & MSG_DONTWAIT)) 1032 } while (likely((ph != NULL) ||
1036 && (atomic_read(&po->tx_ring.pending)))) 1033 ((!(msg->msg_flags & MSG_DONTWAIT)) &&
1037 ); 1034 (atomic_read(&po->tx_ring.pending))))
1035 );
1038 1036
1039 err = len_sum; 1037 err = len_sum;
1040 goto out_put; 1038 goto out_put;
1041 1039
1042out_xmit:
1043 skb->destructor = sock_wfree;
1044 atomic_dec(&po->tx_ring.pending);
1045out_status: 1040out_status:
1046 __packet_set_status(po, ph, status); 1041 __packet_set_status(po, ph, status);
1047 kfree_skb(skb); 1042 kfree_skb(skb);
@@ -1051,7 +1046,30 @@ out:
1051 mutex_unlock(&po->pg_vec_lock); 1046 mutex_unlock(&po->pg_vec_lock);
1052 return err; 1047 return err;
1053} 1048}
1054#endif 1049
1050static inline struct sk_buff *packet_alloc_skb(struct sock *sk, size_t prepad,
1051 size_t reserve, size_t len,
1052 size_t linear, int noblock,
1053 int *err)
1054{
1055 struct sk_buff *skb;
1056
1057 /* Under a page? Don't bother with paged skb. */
1058 if (prepad + len < PAGE_SIZE || !linear)
1059 linear = len;
1060
1061 skb = sock_alloc_send_pskb(sk, prepad + linear, len - linear, noblock,
1062 err);
1063 if (!skb)
1064 return NULL;
1065
1066 skb_reserve(skb, reserve);
1067 skb_put(skb, linear);
1068 skb->data_len = len - linear;
1069 skb->len += len - linear;
1070
1071 return skb;
1072}
1055 1073
1056static int packet_snd(struct socket *sock, 1074static int packet_snd(struct socket *sock,
1057 struct msghdr *msg, size_t len) 1075 struct msghdr *msg, size_t len)
@@ -1063,14 +1081,17 @@ static int packet_snd(struct socket *sock,
1063 __be16 proto; 1081 __be16 proto;
1064 unsigned char *addr; 1082 unsigned char *addr;
1065 int ifindex, err, reserve = 0; 1083 int ifindex, err, reserve = 0;
1084 struct virtio_net_hdr vnet_hdr = { 0 };
1085 int offset = 0;
1086 int vnet_hdr_len;
1087 struct packet_sock *po = pkt_sk(sk);
1088 unsigned short gso_type = 0;
1066 1089
1067 /* 1090 /*
1068 * Get and verify the address. 1091 * Get and verify the address.
1069 */ 1092 */
1070 1093
1071 if (saddr == NULL) { 1094 if (saddr == NULL) {
1072 struct packet_sock *po = pkt_sk(sk);
1073
1074 ifindex = po->ifindex; 1095 ifindex = po->ifindex;
1075 proto = po->num; 1096 proto = po->num;
1076 addr = NULL; 1097 addr = NULL;
@@ -1097,31 +1118,100 @@ static int packet_snd(struct socket *sock,
1097 if (!(dev->flags & IFF_UP)) 1118 if (!(dev->flags & IFF_UP))
1098 goto out_unlock; 1119 goto out_unlock;
1099 1120
1121 if (po->has_vnet_hdr) {
1122 vnet_hdr_len = sizeof(vnet_hdr);
1123
1124 err = -EINVAL;
1125 if (len < vnet_hdr_len)
1126 goto out_unlock;
1127
1128 len -= vnet_hdr_len;
1129
1130 err = memcpy_fromiovec((void *)&vnet_hdr, msg->msg_iov,
1131 vnet_hdr_len);
1132 if (err < 0)
1133 goto out_unlock;
1134
1135 if ((vnet_hdr.flags & VIRTIO_NET_HDR_F_NEEDS_CSUM) &&
1136 (vnet_hdr.csum_start + vnet_hdr.csum_offset + 2 >
1137 vnet_hdr.hdr_len))
1138 vnet_hdr.hdr_len = vnet_hdr.csum_start +
1139 vnet_hdr.csum_offset + 2;
1140
1141 err = -EINVAL;
1142 if (vnet_hdr.hdr_len > len)
1143 goto out_unlock;
1144
1145 if (vnet_hdr.gso_type != VIRTIO_NET_HDR_GSO_NONE) {
1146 switch (vnet_hdr.gso_type & ~VIRTIO_NET_HDR_GSO_ECN) {
1147 case VIRTIO_NET_HDR_GSO_TCPV4:
1148 gso_type = SKB_GSO_TCPV4;
1149 break;
1150 case VIRTIO_NET_HDR_GSO_TCPV6:
1151 gso_type = SKB_GSO_TCPV6;
1152 break;
1153 case VIRTIO_NET_HDR_GSO_UDP:
1154 gso_type = SKB_GSO_UDP;
1155 break;
1156 default:
1157 goto out_unlock;
1158 }
1159
1160 if (vnet_hdr.gso_type & VIRTIO_NET_HDR_GSO_ECN)
1161 gso_type |= SKB_GSO_TCP_ECN;
1162
1163 if (vnet_hdr.gso_size == 0)
1164 goto out_unlock;
1165
1166 }
1167 }
1168
1100 err = -EMSGSIZE; 1169 err = -EMSGSIZE;
1101 if (len > dev->mtu+reserve) 1170 if (!gso_type && (len > dev->mtu+reserve))
1102 goto out_unlock; 1171 goto out_unlock;
1103 1172
1104 skb = sock_alloc_send_skb(sk, len + LL_ALLOCATED_SPACE(dev), 1173 err = -ENOBUFS;
1105 msg->msg_flags & MSG_DONTWAIT, &err); 1174 skb = packet_alloc_skb(sk, LL_ALLOCATED_SPACE(dev),
1175 LL_RESERVED_SPACE(dev), len, vnet_hdr.hdr_len,
1176 msg->msg_flags & MSG_DONTWAIT, &err);
1106 if (skb == NULL) 1177 if (skb == NULL)
1107 goto out_unlock; 1178 goto out_unlock;
1108 1179
1109 skb_reserve(skb, LL_RESERVED_SPACE(dev)); 1180 skb_set_network_header(skb, reserve);
1110 skb_reset_network_header(skb);
1111 1181
1112 err = -EINVAL; 1182 err = -EINVAL;
1113 if (sock->type == SOCK_DGRAM && 1183 if (sock->type == SOCK_DGRAM &&
1114 dev_hard_header(skb, dev, ntohs(proto), addr, NULL, len) < 0) 1184 (offset = dev_hard_header(skb, dev, ntohs(proto), addr, NULL, len)) < 0)
1115 goto out_free; 1185 goto out_free;
1116 1186
1117 /* Returns -EFAULT on error */ 1187 /* Returns -EFAULT on error */
1118 err = memcpy_fromiovec(skb_put(skb, len), msg->msg_iov, len); 1188 err = skb_copy_datagram_from_iovec(skb, offset, msg->msg_iov, 0, len);
1119 if (err) 1189 if (err)
1120 goto out_free; 1190 goto out_free;
1121 1191
1122 skb->protocol = proto; 1192 skb->protocol = proto;
1123 skb->dev = dev; 1193 skb->dev = dev;
1124 skb->priority = sk->sk_priority; 1194 skb->priority = sk->sk_priority;
1195 skb->mark = sk->sk_mark;
1196
1197 if (po->has_vnet_hdr) {
1198 if (vnet_hdr.flags & VIRTIO_NET_HDR_F_NEEDS_CSUM) {
1199 if (!skb_partial_csum_set(skb, vnet_hdr.csum_start,
1200 vnet_hdr.csum_offset)) {
1201 err = -EINVAL;
1202 goto out_free;
1203 }
1204 }
1205
1206 skb_shinfo(skb)->gso_size = vnet_hdr.gso_size;
1207 skb_shinfo(skb)->gso_type = gso_type;
1208
1209 /* Header must be checked, and gso_segs computed. */
1210 skb_shinfo(skb)->gso_type |= SKB_GSO_DODGY;
1211 skb_shinfo(skb)->gso_segs = 0;
1212
1213 len += vnet_hdr_len;
1214 }
1125 1215
1126 /* 1216 /*
1127 * Now send it 1217 * Now send it
@@ -1147,13 +1237,11 @@ out:
1147static int packet_sendmsg(struct kiocb *iocb, struct socket *sock, 1237static int packet_sendmsg(struct kiocb *iocb, struct socket *sock,
1148 struct msghdr *msg, size_t len) 1238 struct msghdr *msg, size_t len)
1149{ 1239{
1150#ifdef CONFIG_PACKET_MMAP
1151 struct sock *sk = sock->sk; 1240 struct sock *sk = sock->sk;
1152 struct packet_sock *po = pkt_sk(sk); 1241 struct packet_sock *po = pkt_sk(sk);
1153 if (po->tx_ring.pg_vec) 1242 if (po->tx_ring.pg_vec)
1154 return tpacket_snd(po, msg); 1243 return tpacket_snd(po, msg);
1155 else 1244 else
1156#endif
1157 return packet_snd(sock, msg, len); 1245 return packet_snd(sock, msg, len);
1158} 1246}
1159 1247
@@ -1167,9 +1255,7 @@ static int packet_release(struct socket *sock)
1167 struct sock *sk = sock->sk; 1255 struct sock *sk = sock->sk;
1168 struct packet_sock *po; 1256 struct packet_sock *po;
1169 struct net *net; 1257 struct net *net;
1170#ifdef CONFIG_PACKET_MMAP
1171 struct tpacket_req req; 1258 struct tpacket_req req;
1172#endif
1173 1259
1174 if (!sk) 1260 if (!sk)
1175 return 0; 1261 return 0;
@@ -1177,28 +1263,25 @@ static int packet_release(struct socket *sock)
1177 net = sock_net(sk); 1263 net = sock_net(sk);
1178 po = pkt_sk(sk); 1264 po = pkt_sk(sk);
1179 1265
1180 write_lock_bh(&net->packet.sklist_lock); 1266 spin_lock_bh(&net->packet.sklist_lock);
1181 sk_del_node_init(sk); 1267 sk_del_node_init_rcu(sk);
1182 sock_prot_inuse_add(net, sk->sk_prot, -1); 1268 sock_prot_inuse_add(net, sk->sk_prot, -1);
1183 write_unlock_bh(&net->packet.sklist_lock); 1269 spin_unlock_bh(&net->packet.sklist_lock);
1184
1185 /*
1186 * Unhook packet receive handler.
1187 */
1188 1270
1271 spin_lock(&po->bind_lock);
1189 if (po->running) { 1272 if (po->running) {
1190 /* 1273 /*
1191 * Remove the protocol hook 1274 * Remove from protocol table
1192 */ 1275 */
1193 dev_remove_pack(&po->prot_hook);
1194 po->running = 0; 1276 po->running = 0;
1195 po->num = 0; 1277 po->num = 0;
1278 __dev_remove_pack(&po->prot_hook);
1196 __sock_put(sk); 1279 __sock_put(sk);
1197 } 1280 }
1281 spin_unlock(&po->bind_lock);
1198 1282
1199 packet_flush_mclist(sk); 1283 packet_flush_mclist(sk);
1200 1284
1201#ifdef CONFIG_PACKET_MMAP
1202 memset(&req, 0, sizeof(req)); 1285 memset(&req, 0, sizeof(req));
1203 1286
1204 if (po->rx_ring.pg_vec) 1287 if (po->rx_ring.pg_vec)
@@ -1206,12 +1289,11 @@ static int packet_release(struct socket *sock)
1206 1289
1207 if (po->tx_ring.pg_vec) 1290 if (po->tx_ring.pg_vec)
1208 packet_set_ring(sk, &req, 1, 1); 1291 packet_set_ring(sk, &req, 1, 1);
1209#endif
1210 1292
1293 synchronize_net();
1211 /* 1294 /*
1212 * Now the socket is dead. No more input will appear. 1295 * Now the socket is dead. No more input will appear.
1213 */ 1296 */
1214
1215 sock_orphan(sk); 1297 sock_orphan(sk);
1216 sock->sk = NULL; 1298 sock->sk = NULL;
1217 1299
@@ -1341,7 +1423,8 @@ static struct proto packet_proto = {
1341 * Create a packet of type SOCK_PACKET. 1423 * Create a packet of type SOCK_PACKET.
1342 */ 1424 */
1343 1425
1344static int packet_create(struct net *net, struct socket *sock, int protocol) 1426static int packet_create(struct net *net, struct socket *sock, int protocol,
1427 int kern)
1345{ 1428{
1346 struct sock *sk; 1429 struct sock *sk;
1347 struct packet_sock *po; 1430 struct packet_sock *po;
@@ -1394,10 +1477,11 @@ static int packet_create(struct net *net, struct socket *sock, int protocol)
1394 po->running = 1; 1477 po->running = 1;
1395 } 1478 }
1396 1479
1397 write_lock_bh(&net->packet.sklist_lock); 1480 spin_lock_bh(&net->packet.sklist_lock);
1398 sk_add_node(sk, &net->packet.sklist); 1481 sk_add_node_rcu(sk, &net->packet.sklist);
1399 sock_prot_inuse_add(net, &packet_proto, 1); 1482 sock_prot_inuse_add(net, &packet_proto, 1);
1400 write_unlock_bh(&net->packet.sklist_lock); 1483 spin_unlock_bh(&net->packet.sklist_lock);
1484
1401 return 0; 1485 return 0;
1402out: 1486out:
1403 return err; 1487 return err;
@@ -1415,6 +1499,7 @@ static int packet_recvmsg(struct kiocb *iocb, struct socket *sock,
1415 struct sk_buff *skb; 1499 struct sk_buff *skb;
1416 int copied, err; 1500 int copied, err;
1417 struct sockaddr_ll *sll; 1501 struct sockaddr_ll *sll;
1502 int vnet_hdr_len = 0;
1418 1503
1419 err = -EINVAL; 1504 err = -EINVAL;
1420 if (flags & ~(MSG_PEEK|MSG_DONTWAIT|MSG_TRUNC|MSG_CMSG_COMPAT)) 1505 if (flags & ~(MSG_PEEK|MSG_DONTWAIT|MSG_TRUNC|MSG_CMSG_COMPAT))
@@ -1446,6 +1531,48 @@ static int packet_recvmsg(struct kiocb *iocb, struct socket *sock,
1446 if (skb == NULL) 1531 if (skb == NULL)
1447 goto out; 1532 goto out;
1448 1533
1534 if (pkt_sk(sk)->has_vnet_hdr) {
1535 struct virtio_net_hdr vnet_hdr = { 0 };
1536
1537 err = -EINVAL;
1538 vnet_hdr_len = sizeof(vnet_hdr);
1539 if ((len -= vnet_hdr_len) < 0)
1540 goto out_free;
1541
1542 if (skb_is_gso(skb)) {
1543 struct skb_shared_info *sinfo = skb_shinfo(skb);
1544
1545 /* This is a hint as to how much should be linear. */
1546 vnet_hdr.hdr_len = skb_headlen(skb);
1547 vnet_hdr.gso_size = sinfo->gso_size;
1548 if (sinfo->gso_type & SKB_GSO_TCPV4)
1549 vnet_hdr.gso_type = VIRTIO_NET_HDR_GSO_TCPV4;
1550 else if (sinfo->gso_type & SKB_GSO_TCPV6)
1551 vnet_hdr.gso_type = VIRTIO_NET_HDR_GSO_TCPV6;
1552 else if (sinfo->gso_type & SKB_GSO_UDP)
1553 vnet_hdr.gso_type = VIRTIO_NET_HDR_GSO_UDP;
1554 else if (sinfo->gso_type & SKB_GSO_FCOE)
1555 goto out_free;
1556 else
1557 BUG();
1558 if (sinfo->gso_type & SKB_GSO_TCP_ECN)
1559 vnet_hdr.gso_type |= VIRTIO_NET_HDR_GSO_ECN;
1560 } else
1561 vnet_hdr.gso_type = VIRTIO_NET_HDR_GSO_NONE;
1562
1563 if (skb->ip_summed == CHECKSUM_PARTIAL) {
1564 vnet_hdr.flags = VIRTIO_NET_HDR_F_NEEDS_CSUM;
1565 vnet_hdr.csum_start = skb->csum_start -
1566 skb_headroom(skb);
1567 vnet_hdr.csum_offset = skb->csum_offset;
1568 } /* else everything is zero */
1569
1570 err = memcpy_toiovec(msg->msg_iov, (void *)&vnet_hdr,
1571 vnet_hdr_len);
1572 if (err < 0)
1573 goto out_free;
1574 }
1575
1449 /* 1576 /*
1450 * If the address length field is there to be filled in, we fill 1577 * If the address length field is there to be filled in, we fill
1451 * it in now. 1578 * it in now.
@@ -1472,7 +1599,7 @@ static int packet_recvmsg(struct kiocb *iocb, struct socket *sock,
1472 if (err) 1599 if (err)
1473 goto out_free; 1600 goto out_free;
1474 1601
1475 sock_recv_timestamp(msg, sk, skb); 1602 sock_recv_ts_and_drops(msg, sk, skb);
1476 1603
1477 if (msg->msg_name) 1604 if (msg->msg_name)
1478 memcpy(msg->msg_name, &PACKET_SKB_CB(skb)->sa, 1605 memcpy(msg->msg_name, &PACKET_SKB_CB(skb)->sa,
@@ -1488,7 +1615,7 @@ static int packet_recvmsg(struct kiocb *iocb, struct socket *sock,
1488 aux.tp_snaplen = skb->len; 1615 aux.tp_snaplen = skb->len;
1489 aux.tp_mac = 0; 1616 aux.tp_mac = 0;
1490 aux.tp_net = skb_network_offset(skb); 1617 aux.tp_net = skb_network_offset(skb);
1491 aux.tp_vlan_tci = skb->vlan_tci; 1618 aux.tp_vlan_tci = vlan_tx_tag_get(skb);
1492 1619
1493 put_cmsg(msg, SOL_PACKET, PACKET_AUXDATA, sizeof(aux), &aux); 1620 put_cmsg(msg, SOL_PACKET, PACKET_AUXDATA, sizeof(aux), &aux);
1494 } 1621 }
@@ -1497,7 +1624,7 @@ static int packet_recvmsg(struct kiocb *iocb, struct socket *sock,
1497 * Free or return the buffer as appropriate. Again this 1624 * Free or return the buffer as appropriate. Again this
1498 * hides all the races and re-entrancy issues from us. 1625 * hides all the races and re-entrancy issues from us.
1499 */ 1626 */
1500 err = (flags&MSG_TRUNC) ? skb->len : copied; 1627 err = vnet_hdr_len + ((flags&MSG_TRUNC) ? skb->len : copied);
1501 1628
1502out_free: 1629out_free:
1503 skb_free_datagram(sk, skb); 1630 skb_free_datagram(sk, skb);
@@ -1515,12 +1642,13 @@ static int packet_getname_spkt(struct socket *sock, struct sockaddr *uaddr,
1515 return -EOPNOTSUPP; 1642 return -EOPNOTSUPP;
1516 1643
1517 uaddr->sa_family = AF_PACKET; 1644 uaddr->sa_family = AF_PACKET;
1518 dev = dev_get_by_index(sock_net(sk), pkt_sk(sk)->ifindex); 1645 rcu_read_lock();
1519 if (dev) { 1646 dev = dev_get_by_index_rcu(sock_net(sk), pkt_sk(sk)->ifindex);
1647 if (dev)
1520 strlcpy(uaddr->sa_data, dev->name, 15); 1648 strlcpy(uaddr->sa_data, dev->name, 15);
1521 dev_put(dev); 1649 else
1522 } else
1523 memset(uaddr->sa_data, 0, 14); 1650 memset(uaddr->sa_data, 0, 14);
1651 rcu_read_unlock();
1524 *uaddr_len = sizeof(*uaddr); 1652 *uaddr_len = sizeof(*uaddr);
1525 1653
1526 return 0; 1654 return 0;
@@ -1532,7 +1660,7 @@ static int packet_getname(struct socket *sock, struct sockaddr *uaddr,
1532 struct net_device *dev; 1660 struct net_device *dev;
1533 struct sock *sk = sock->sk; 1661 struct sock *sk = sock->sk;
1534 struct packet_sock *po = pkt_sk(sk); 1662 struct packet_sock *po = pkt_sk(sk);
1535 struct sockaddr_ll *sll = (struct sockaddr_ll *)uaddr; 1663 DECLARE_SOCKADDR(struct sockaddr_ll *, sll, uaddr);
1536 1664
1537 if (peer) 1665 if (peer)
1538 return -EOPNOTSUPP; 1666 return -EOPNOTSUPP;
@@ -1540,16 +1668,17 @@ static int packet_getname(struct socket *sock, struct sockaddr *uaddr,
1540 sll->sll_family = AF_PACKET; 1668 sll->sll_family = AF_PACKET;
1541 sll->sll_ifindex = po->ifindex; 1669 sll->sll_ifindex = po->ifindex;
1542 sll->sll_protocol = po->num; 1670 sll->sll_protocol = po->num;
1543 dev = dev_get_by_index(sock_net(sk), po->ifindex); 1671 rcu_read_lock();
1672 dev = dev_get_by_index_rcu(sock_net(sk), po->ifindex);
1544 if (dev) { 1673 if (dev) {
1545 sll->sll_hatype = dev->type; 1674 sll->sll_hatype = dev->type;
1546 sll->sll_halen = dev->addr_len; 1675 sll->sll_halen = dev->addr_len;
1547 memcpy(sll->sll_addr, dev->dev_addr, dev->addr_len); 1676 memcpy(sll->sll_addr, dev->dev_addr, dev->addr_len);
1548 dev_put(dev);
1549 } else { 1677 } else {
1550 sll->sll_hatype = 0; /* Bad: we have no ARPHRD_UNSPEC */ 1678 sll->sll_hatype = 0; /* Bad: we have no ARPHRD_UNSPEC */
1551 sll->sll_halen = 0; 1679 sll->sll_halen = 0;
1552 } 1680 }
1681 rcu_read_unlock();
1553 *uaddr_len = offsetof(struct sockaddr_ll, sll_addr) + sll->sll_halen; 1682 *uaddr_len = offsetof(struct sockaddr_ll, sll_addr) + sll->sll_halen;
1554 1683
1555 return 0; 1684 return 0;
@@ -1560,6 +1689,8 @@ static int packet_dev_mc(struct net_device *dev, struct packet_mclist *i,
1560{ 1689{
1561 switch (i->type) { 1690 switch (i->type) {
1562 case PACKET_MR_MULTICAST: 1691 case PACKET_MR_MULTICAST:
1692 if (i->alen != dev->addr_len)
1693 return -EINVAL;
1563 if (what > 0) 1694 if (what > 0)
1564 return dev_mc_add(dev, i->addr, i->alen, 0); 1695 return dev_mc_add(dev, i->addr, i->alen, 0);
1565 else 1696 else
@@ -1572,6 +1703,8 @@ static int packet_dev_mc(struct net_device *dev, struct packet_mclist *i,
1572 return dev_set_allmulti(dev, what); 1703 return dev_set_allmulti(dev, what);
1573 break; 1704 break;
1574 case PACKET_MR_UNICAST: 1705 case PACKET_MR_UNICAST:
1706 if (i->alen != dev->addr_len)
1707 return -EINVAL;
1575 if (what > 0) 1708 if (what > 0)
1576 return dev_unicast_add(dev, i->addr); 1709 return dev_unicast_add(dev, i->addr);
1577 else 1710 else
@@ -1659,11 +1792,9 @@ static int packet_mc_drop(struct sock *sk, struct packet_mreq_max *mreq)
1659 if (--ml->count == 0) { 1792 if (--ml->count == 0) {
1660 struct net_device *dev; 1793 struct net_device *dev;
1661 *mlp = ml->next; 1794 *mlp = ml->next;
1662 dev = dev_get_by_index(sock_net(sk), ml->ifindex); 1795 dev = __dev_get_by_index(sock_net(sk), ml->ifindex);
1663 if (dev) { 1796 if (dev)
1664 packet_dev_mc(dev, ml, -1); 1797 packet_dev_mc(dev, ml, -1);
1665 dev_put(dev);
1666 }
1667 kfree(ml); 1798 kfree(ml);
1668 } 1799 }
1669 rtnl_unlock(); 1800 rtnl_unlock();
@@ -1687,11 +1818,9 @@ static void packet_flush_mclist(struct sock *sk)
1687 struct net_device *dev; 1818 struct net_device *dev;
1688 1819
1689 po->mclist = ml->next; 1820 po->mclist = ml->next;
1690 dev = dev_get_by_index(sock_net(sk), ml->ifindex); 1821 dev = __dev_get_by_index(sock_net(sk), ml->ifindex);
1691 if (dev != NULL) { 1822 if (dev != NULL)
1692 packet_dev_mc(dev, ml, -1); 1823 packet_dev_mc(dev, ml, -1);
1693 dev_put(dev);
1694 }
1695 kfree(ml); 1824 kfree(ml);
1696 } 1825 }
1697 rtnl_unlock(); 1826 rtnl_unlock();
@@ -1729,7 +1858,6 @@ packet_setsockopt(struct socket *sock, int level, int optname, char __user *optv
1729 return ret; 1858 return ret;
1730 } 1859 }
1731 1860
1732#ifdef CONFIG_PACKET_MMAP
1733 case PACKET_RX_RING: 1861 case PACKET_RX_RING:
1734 case PACKET_TX_RING: 1862 case PACKET_TX_RING:
1735 { 1863 {
@@ -1737,6 +1865,8 @@ packet_setsockopt(struct socket *sock, int level, int optname, char __user *optv
1737 1865
1738 if (optlen < sizeof(req)) 1866 if (optlen < sizeof(req))
1739 return -EINVAL; 1867 return -EINVAL;
1868 if (pkt_sk(sk)->has_vnet_hdr)
1869 return -EINVAL;
1740 if (copy_from_user(&req, optval, sizeof(req))) 1870 if (copy_from_user(&req, optval, sizeof(req)))
1741 return -EFAULT; 1871 return -EFAULT;
1742 return packet_set_ring(sk, &req, 0, optname == PACKET_TX_RING); 1872 return packet_set_ring(sk, &req, 0, optname == PACKET_TX_RING);
@@ -1798,7 +1928,6 @@ packet_setsockopt(struct socket *sock, int level, int optname, char __user *optv
1798 po->tp_loss = !!val; 1928 po->tp_loss = !!val;
1799 return 0; 1929 return 0;
1800 } 1930 }
1801#endif
1802 case PACKET_AUXDATA: 1931 case PACKET_AUXDATA:
1803 { 1932 {
1804 int val; 1933 int val;
@@ -1823,6 +1952,22 @@ packet_setsockopt(struct socket *sock, int level, int optname, char __user *optv
1823 po->origdev = !!val; 1952 po->origdev = !!val;
1824 return 0; 1953 return 0;
1825 } 1954 }
1955 case PACKET_VNET_HDR:
1956 {
1957 int val;
1958
1959 if (sock->type != SOCK_RAW)
1960 return -EINVAL;
1961 if (po->rx_ring.pg_vec || po->tx_ring.pg_vec)
1962 return -EBUSY;
1963 if (optlen < sizeof(val))
1964 return -EINVAL;
1965 if (copy_from_user(&val, optval, sizeof(val)))
1966 return -EFAULT;
1967
1968 po->has_vnet_hdr = !!val;
1969 return 0;
1970 }
1826 default: 1971 default:
1827 return -ENOPROTOOPT; 1972 return -ENOPROTOOPT;
1828 } 1973 }
@@ -1873,7 +2018,13 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
1873 2018
1874 data = &val; 2019 data = &val;
1875 break; 2020 break;
1876#ifdef CONFIG_PACKET_MMAP 2021 case PACKET_VNET_HDR:
2022 if (len > sizeof(int))
2023 len = sizeof(int);
2024 val = po->has_vnet_hdr;
2025
2026 data = &val;
2027 break;
1877 case PACKET_VERSION: 2028 case PACKET_VERSION:
1878 if (len > sizeof(int)) 2029 if (len > sizeof(int))
1879 len = sizeof(int); 2030 len = sizeof(int);
@@ -1909,7 +2060,6 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
1909 val = po->tp_loss; 2060 val = po->tp_loss;
1910 data = &val; 2061 data = &val;
1911 break; 2062 break;
1912#endif
1913 default: 2063 default:
1914 return -ENOPROTOOPT; 2064 return -ENOPROTOOPT;
1915 } 2065 }
@@ -1929,8 +2079,8 @@ static int packet_notifier(struct notifier_block *this, unsigned long msg, void
1929 struct net_device *dev = data; 2079 struct net_device *dev = data;
1930 struct net *net = dev_net(dev); 2080 struct net *net = dev_net(dev);
1931 2081
1932 read_lock(&net->packet.sklist_lock); 2082 rcu_read_lock();
1933 sk_for_each(sk, node, &net->packet.sklist) { 2083 sk_for_each_rcu(sk, node, &net->packet.sklist) {
1934 struct packet_sock *po = pkt_sk(sk); 2084 struct packet_sock *po = pkt_sk(sk);
1935 2085
1936 switch (msg) { 2086 switch (msg) {
@@ -1958,18 +2108,19 @@ static int packet_notifier(struct notifier_block *this, unsigned long msg, void
1958 } 2108 }
1959 break; 2109 break;
1960 case NETDEV_UP: 2110 case NETDEV_UP:
1961 spin_lock(&po->bind_lock); 2111 if (dev->ifindex == po->ifindex) {
1962 if (dev->ifindex == po->ifindex && po->num && 2112 spin_lock(&po->bind_lock);
1963 !po->running) { 2113 if (po->num && !po->running) {
1964 dev_add_pack(&po->prot_hook); 2114 dev_add_pack(&po->prot_hook);
1965 sock_hold(sk); 2115 sock_hold(sk);
1966 po->running = 1; 2116 po->running = 1;
2117 }
2118 spin_unlock(&po->bind_lock);
1967 } 2119 }
1968 spin_unlock(&po->bind_lock);
1969 break; 2120 break;
1970 } 2121 }
1971 } 2122 }
1972 read_unlock(&net->packet.sklist_lock); 2123 rcu_read_unlock();
1973 return NOTIFY_DONE; 2124 return NOTIFY_DONE;
1974} 2125}
1975 2126
@@ -2018,8 +2169,6 @@ static int packet_ioctl(struct socket *sock, unsigned int cmd,
2018 case SIOCGIFDSTADDR: 2169 case SIOCGIFDSTADDR:
2019 case SIOCSIFDSTADDR: 2170 case SIOCSIFDSTADDR:
2020 case SIOCSIFFLAGS: 2171 case SIOCSIFFLAGS:
2021 if (!net_eq(sock_net(sk), &init_net))
2022 return -ENOIOCTLCMD;
2023 return inet_dgram_ops.ioctl(sock, cmd, arg); 2172 return inet_dgram_ops.ioctl(sock, cmd, arg);
2024#endif 2173#endif
2025 2174
@@ -2029,11 +2178,6 @@ static int packet_ioctl(struct socket *sock, unsigned int cmd,
2029 return 0; 2178 return 0;
2030} 2179}
2031 2180
2032#ifndef CONFIG_PACKET_MMAP
2033#define packet_mmap sock_no_mmap
2034#define packet_poll datagram_poll
2035#else
2036
2037static unsigned int packet_poll(struct file *file, struct socket *sock, 2181static unsigned int packet_poll(struct file *file, struct socket *sock,
2038 poll_table *wait) 2182 poll_table *wait)
2039{ 2183{
@@ -2315,8 +2459,6 @@ out:
2315 mutex_unlock(&po->pg_vec_lock); 2459 mutex_unlock(&po->pg_vec_lock);
2316 return err; 2460 return err;
2317} 2461}
2318#endif
2319
2320 2462
2321static const struct proto_ops packet_ops_spkt = { 2463static const struct proto_ops packet_ops_spkt = {
2322 .family = PF_PACKET, 2464 .family = PF_PACKET,
@@ -2360,7 +2502,7 @@ static const struct proto_ops packet_ops = {
2360 .sendpage = sock_no_sendpage, 2502 .sendpage = sock_no_sendpage,
2361}; 2503};
2362 2504
2363static struct net_proto_family packet_family_ops = { 2505static const struct net_proto_family packet_family_ops = {
2364 .family = PF_PACKET, 2506 .family = PF_PACKET,
2365 .create = packet_create, 2507 .create = packet_create,
2366 .owner = THIS_MODULE, 2508 .owner = THIS_MODULE,
@@ -2371,40 +2513,26 @@ static struct notifier_block packet_netdev_notifier = {
2371}; 2513};
2372 2514
2373#ifdef CONFIG_PROC_FS 2515#ifdef CONFIG_PROC_FS
2374static inline struct sock *packet_seq_idx(struct net *net, loff_t off)
2375{
2376 struct sock *s;
2377 struct hlist_node *node;
2378
2379 sk_for_each(s, node, &net->packet.sklist) {
2380 if (!off--)
2381 return s;
2382 }
2383 return NULL;
2384}
2385 2516
2386static void *packet_seq_start(struct seq_file *seq, loff_t *pos) 2517static void *packet_seq_start(struct seq_file *seq, loff_t *pos)
2387 __acquires(seq_file_net(seq)->packet.sklist_lock) 2518 __acquires(RCU)
2388{ 2519{
2389 struct net *net = seq_file_net(seq); 2520 struct net *net = seq_file_net(seq);
2390 read_lock(&net->packet.sklist_lock); 2521
2391 return *pos ? packet_seq_idx(net, *pos - 1) : SEQ_START_TOKEN; 2522 rcu_read_lock();
2523 return seq_hlist_start_head_rcu(&net->packet.sklist, *pos);
2392} 2524}
2393 2525
2394static void *packet_seq_next(struct seq_file *seq, void *v, loff_t *pos) 2526static void *packet_seq_next(struct seq_file *seq, void *v, loff_t *pos)
2395{ 2527{
2396 struct net *net = seq_file_net(seq); 2528 struct net *net = seq_file_net(seq);
2397 ++*pos; 2529 return seq_hlist_next_rcu(v, &net->packet.sklist, pos);
2398 return (v == SEQ_START_TOKEN)
2399 ? sk_head(&net->packet.sklist)
2400 : sk_next((struct sock *)v) ;
2401} 2530}
2402 2531
2403static void packet_seq_stop(struct seq_file *seq, void *v) 2532static void packet_seq_stop(struct seq_file *seq, void *v)
2404 __releases(seq_file_net(seq)->packet.sklist_lock) 2533 __releases(RCU)
2405{ 2534{
2406 struct net *net = seq_file_net(seq); 2535 rcu_read_unlock();
2407 read_unlock(&net->packet.sklist_lock);
2408} 2536}
2409 2537
2410static int packet_seq_show(struct seq_file *seq, void *v) 2538static int packet_seq_show(struct seq_file *seq, void *v)
@@ -2412,7 +2540,7 @@ static int packet_seq_show(struct seq_file *seq, void *v)
2412 if (v == SEQ_START_TOKEN) 2540 if (v == SEQ_START_TOKEN)
2413 seq_puts(seq, "sk RefCnt Type Proto Iface R Rmem User Inode\n"); 2541 seq_puts(seq, "sk RefCnt Type Proto Iface R Rmem User Inode\n");
2414 else { 2542 else {
2415 struct sock *s = v; 2543 struct sock *s = sk_entry(v);
2416 const struct packet_sock *po = pkt_sk(s); 2544 const struct packet_sock *po = pkt_sk(s);
2417 2545
2418 seq_printf(seq, 2546 seq_printf(seq,
@@ -2454,9 +2582,9 @@ static const struct file_operations packet_seq_fops = {
2454 2582
2455#endif 2583#endif
2456 2584
2457static int packet_net_init(struct net *net) 2585static int __net_init packet_net_init(struct net *net)
2458{ 2586{
2459 rwlock_init(&net->packet.sklist_lock); 2587 spin_lock_init(&net->packet.sklist_lock);
2460 INIT_HLIST_HEAD(&net->packet.sklist); 2588 INIT_HLIST_HEAD(&net->packet.sklist);
2461 2589
2462 if (!proc_net_fops_create(net, "packet", 0, &packet_seq_fops)) 2590 if (!proc_net_fops_create(net, "packet", 0, &packet_seq_fops))
@@ -2465,7 +2593,7 @@ static int packet_net_init(struct net *net)
2465 return 0; 2593 return 0;
2466} 2594}
2467 2595
2468static void packet_net_exit(struct net *net) 2596static void __net_exit packet_net_exit(struct net *net)
2469{ 2597{
2470 proc_net_remove(net, "packet"); 2598 proc_net_remove(net, "packet");
2471} 2599}
diff --git a/net/phonet/af_phonet.c b/net/phonet/af_phonet.c
index f60c0c2aacba..73aee7f2fcdc 100644
--- a/net/phonet/af_phonet.c
+++ b/net/phonet/af_phonet.c
@@ -25,6 +25,7 @@
25 25
26#include <linux/kernel.h> 26#include <linux/kernel.h>
27#include <linux/module.h> 27#include <linux/module.h>
28#include <linux/slab.h>
28#include <asm/unaligned.h> 29#include <asm/unaligned.h>
29#include <net/sock.h> 30#include <net/sock.h>
30 31
@@ -35,7 +36,6 @@
35 36
36/* Transport protocol registration */ 37/* Transport protocol registration */
37static struct phonet_protocol *proto_tab[PHONET_NPROTO] __read_mostly; 38static struct phonet_protocol *proto_tab[PHONET_NPROTO] __read_mostly;
38static DEFINE_SPINLOCK(proto_tab_lock);
39 39
40static struct phonet_protocol *phonet_proto_get(int protocol) 40static struct phonet_protocol *phonet_proto_get(int protocol)
41{ 41{
@@ -44,11 +44,11 @@ static struct phonet_protocol *phonet_proto_get(int protocol)
44 if (protocol >= PHONET_NPROTO) 44 if (protocol >= PHONET_NPROTO)
45 return NULL; 45 return NULL;
46 46
47 spin_lock(&proto_tab_lock); 47 rcu_read_lock();
48 pp = proto_tab[protocol]; 48 pp = rcu_dereference(proto_tab[protocol]);
49 if (pp && !try_module_get(pp->prot->owner)) 49 if (pp && !try_module_get(pp->prot->owner))
50 pp = NULL; 50 pp = NULL;
51 spin_unlock(&proto_tab_lock); 51 rcu_read_unlock();
52 52
53 return pp; 53 return pp;
54} 54}
@@ -60,7 +60,8 @@ static inline void phonet_proto_put(struct phonet_protocol *pp)
60 60
61/* protocol family functions */ 61/* protocol family functions */
62 62
63static int pn_socket_create(struct net *net, struct socket *sock, int protocol) 63static int pn_socket_create(struct net *net, struct socket *sock, int protocol,
64 int kern)
64{ 65{
65 struct sock *sk; 66 struct sock *sk;
66 struct pn_sock *pn; 67 struct pn_sock *pn;
@@ -118,7 +119,7 @@ out:
118 return err; 119 return err;
119} 120}
120 121
121static struct net_proto_family phonet_proto_family = { 122static const struct net_proto_family phonet_proto_family = {
122 .family = PF_PHONET, 123 .family = PF_PHONET,
123 .create = pn_socket_create, 124 .create = pn_socket_create,
124 .owner = THIS_MODULE, 125 .owner = THIS_MODULE,
@@ -190,9 +191,8 @@ static int pn_send(struct sk_buff *skb, struct net_device *dev,
190 skb->priority = 0; 191 skb->priority = 0;
191 skb->dev = dev; 192 skb->dev = dev;
192 193
193 if (pn_addr(src) == pn_addr(dst)) { 194 if (skb->pkt_type == PACKET_LOOPBACK) {
194 skb_reset_mac_header(skb); 195 skb_reset_mac_header(skb);
195 skb->pkt_type = PACKET_LOOPBACK;
196 skb_orphan(skb); 196 skb_orphan(skb);
197 if (irq) 197 if (irq)
198 netif_rx(skb); 198 netif_rx(skb);
@@ -222,6 +222,9 @@ static int pn_raw_send(const void *data, int len, struct net_device *dev,
222 if (skb == NULL) 222 if (skb == NULL)
223 return -ENOMEM; 223 return -ENOMEM;
224 224
225 if (phonet_address_lookup(dev_net(dev), pn_addr(dst)) == 0)
226 skb->pkt_type = PACKET_LOOPBACK;
227
225 skb_reserve(skb, MAX_PHONET_HEADER); 228 skb_reserve(skb, MAX_PHONET_HEADER);
226 __skb_put(skb, len); 229 __skb_put(skb, len);
227 skb_copy_to_linear_data(skb, data, len); 230 skb_copy_to_linear_data(skb, data, len);
@@ -235,6 +238,7 @@ static int pn_raw_send(const void *data, int len, struct net_device *dev,
235int pn_skb_send(struct sock *sk, struct sk_buff *skb, 238int pn_skb_send(struct sock *sk, struct sk_buff *skb,
236 const struct sockaddr_pn *target) 239 const struct sockaddr_pn *target)
237{ 240{
241 struct net *net = sock_net(sk);
238 struct net_device *dev; 242 struct net_device *dev;
239 struct pn_sock *pn = pn_sk(sk); 243 struct pn_sock *pn = pn_sk(sk);
240 int err; 244 int err;
@@ -243,9 +247,13 @@ int pn_skb_send(struct sock *sk, struct sk_buff *skb,
243 247
244 err = -EHOSTUNREACH; 248 err = -EHOSTUNREACH;
245 if (sk->sk_bound_dev_if) 249 if (sk->sk_bound_dev_if)
246 dev = dev_get_by_index(sock_net(sk), sk->sk_bound_dev_if); 250 dev = dev_get_by_index(net, sk->sk_bound_dev_if);
247 else 251 else if (phonet_address_lookup(net, daddr) == 0) {
248 dev = phonet_device_get(sock_net(sk)); 252 dev = phonet_device_get(net);
253 skb->pkt_type = PACKET_LOOPBACK;
254 } else
255 dev = phonet_route_output(net, daddr);
256
249 if (!dev || !(dev->flags & IFF_UP)) 257 if (!dev || !(dev->flags & IFF_UP))
250 goto drop; 258 goto drop;
251 259
@@ -369,6 +377,12 @@ static int phonet_rcv(struct sk_buff *skb, struct net_device *dev,
369 377
370 pn_skb_get_dst_sockaddr(skb, &sa); 378 pn_skb_get_dst_sockaddr(skb, &sa);
371 379
380 /* check if this is broadcasted */
381 if (pn_sockaddr_get_addr(&sa) == PNADDR_BROADCAST) {
382 pn_deliver_sock_broadcast(net, skb);
383 goto out;
384 }
385
372 /* check if we are the destination */ 386 /* check if we are the destination */
373 if (phonet_address_lookup(net, pn_sockaddr_get_addr(&sa)) == 0) { 387 if (phonet_address_lookup(net, pn_sockaddr_get_addr(&sa)) == 0) {
374 /* Phonet packet input */ 388 /* Phonet packet input */
@@ -381,6 +395,38 @@ static int phonet_rcv(struct sk_buff *skb, struct net_device *dev,
381 send_obj_unreachable(skb); 395 send_obj_unreachable(skb);
382 send_reset_indications(skb); 396 send_reset_indications(skb);
383 } 397 }
398 } else if (unlikely(skb->pkt_type == PACKET_LOOPBACK))
399 goto out; /* Race between address deletion and loopback */
400 else {
401 /* Phonet packet routing */
402 struct net_device *out_dev;
403
404 out_dev = phonet_route_output(net, pn_sockaddr_get_addr(&sa));
405 if (!out_dev) {
406 LIMIT_NETDEBUG(KERN_WARNING"No Phonet route to %02X\n",
407 pn_sockaddr_get_addr(&sa));
408 goto out;
409 }
410
411 __skb_push(skb, sizeof(struct phonethdr));
412 skb->dev = out_dev;
413 if (out_dev == dev) {
414 LIMIT_NETDEBUG(KERN_ERR"Phonet loop to %02X on %s\n",
415 pn_sockaddr_get_addr(&sa), dev->name);
416 goto out_dev;
417 }
418 /* Some drivers (e.g. TUN) do not allocate HW header space */
419 if (skb_cow_head(skb, out_dev->hard_header_len))
420 goto out_dev;
421
422 if (dev_hard_header(skb, out_dev, ETH_P_PHONET, NULL, NULL,
423 skb->len) < 0)
424 goto out_dev;
425 dev_queue_xmit(skb);
426 dev_put(out_dev);
427 return NET_RX_SUCCESS;
428out_dev:
429 dev_put(out_dev);
384 } 430 }
385 431
386out: 432out:
@@ -393,6 +439,8 @@ static struct packet_type phonet_packet_type __read_mostly = {
393 .func = phonet_rcv, 439 .func = phonet_rcv,
394}; 440};
395 441
442static DEFINE_MUTEX(proto_tab_lock);
443
396int __init_or_module phonet_proto_register(int protocol, 444int __init_or_module phonet_proto_register(int protocol,
397 struct phonet_protocol *pp) 445 struct phonet_protocol *pp)
398{ 446{
@@ -405,12 +453,12 @@ int __init_or_module phonet_proto_register(int protocol,
405 if (err) 453 if (err)
406 return err; 454 return err;
407 455
408 spin_lock(&proto_tab_lock); 456 mutex_lock(&proto_tab_lock);
409 if (proto_tab[protocol]) 457 if (proto_tab[protocol])
410 err = -EBUSY; 458 err = -EBUSY;
411 else 459 else
412 proto_tab[protocol] = pp; 460 rcu_assign_pointer(proto_tab[protocol], pp);
413 spin_unlock(&proto_tab_lock); 461 mutex_unlock(&proto_tab_lock);
414 462
415 return err; 463 return err;
416} 464}
@@ -418,10 +466,11 @@ EXPORT_SYMBOL(phonet_proto_register);
418 466
419void phonet_proto_unregister(int protocol, struct phonet_protocol *pp) 467void phonet_proto_unregister(int protocol, struct phonet_protocol *pp)
420{ 468{
421 spin_lock(&proto_tab_lock); 469 mutex_lock(&proto_tab_lock);
422 BUG_ON(proto_tab[protocol] != pp); 470 BUG_ON(proto_tab[protocol] != pp);
423 proto_tab[protocol] = NULL; 471 rcu_assign_pointer(proto_tab[protocol], NULL);
424 spin_unlock(&proto_tab_lock); 472 mutex_unlock(&proto_tab_lock);
473 synchronize_rcu();
425 proto_unregister(pp->prot); 474 proto_unregister(pp->prot);
426} 475}
427EXPORT_SYMBOL(phonet_proto_unregister); 476EXPORT_SYMBOL(phonet_proto_unregister);
@@ -435,6 +484,7 @@ static int __init phonet_init(void)
435 if (err) 484 if (err)
436 return err; 485 return err;
437 486
487 pn_sock_init();
438 err = sock_register(&phonet_proto_family); 488 err = sock_register(&phonet_proto_family);
439 if (err) { 489 if (err) {
440 printk(KERN_ALERT 490 printk(KERN_ALERT
diff --git a/net/phonet/datagram.c b/net/phonet/datagram.c
index ef5c75c372e4..1bd38db4fe1e 100644
--- a/net/phonet/datagram.c
+++ b/net/phonet/datagram.c
@@ -24,6 +24,7 @@
24 */ 24 */
25 25
26#include <linux/kernel.h> 26#include <linux/kernel.h>
27#include <linux/slab.h>
27#include <linux/socket.h> 28#include <linux/socket.h>
28#include <asm/ioctls.h> 29#include <asm/ioctls.h>
29#include <net/sock.h> 30#include <net/sock.h>
@@ -75,7 +76,8 @@ static int pn_sendmsg(struct kiocb *iocb, struct sock *sk,
75 struct sk_buff *skb; 76 struct sk_buff *skb;
76 int err; 77 int err;
77 78
78 if (msg->msg_flags & MSG_OOB) 79 if (msg->msg_flags & ~(MSG_DONTWAIT|MSG_EOR|MSG_NOSIGNAL|
80 MSG_CMSG_COMPAT))
79 return -EOPNOTSUPP; 81 return -EOPNOTSUPP;
80 82
81 if (msg->msg_name == NULL) 83 if (msg->msg_name == NULL)
@@ -119,7 +121,8 @@ static int pn_recvmsg(struct kiocb *iocb, struct sock *sk,
119 int rval = -EOPNOTSUPP; 121 int rval = -EOPNOTSUPP;
120 int copylen; 122 int copylen;
121 123
122 if (flags & MSG_OOB) 124 if (flags & ~(MSG_PEEK|MSG_TRUNC|MSG_DONTWAIT|MSG_NOSIGNAL|
125 MSG_CMSG_COMPAT))
123 goto out_nofree; 126 goto out_nofree;
124 127
125 if (addr_len) 128 if (addr_len)
@@ -159,11 +162,9 @@ out_nofree:
159static int pn_backlog_rcv(struct sock *sk, struct sk_buff *skb) 162static int pn_backlog_rcv(struct sock *sk, struct sk_buff *skb)
160{ 163{
161 int err = sock_queue_rcv_skb(sk, skb); 164 int err = sock_queue_rcv_skb(sk, skb);
162 if (err < 0) { 165
166 if (err < 0)
163 kfree_skb(skb); 167 kfree_skb(skb);
164 if (err == -ENOMEM)
165 atomic_inc(&sk->sk_drops);
166 }
167 return err ? NET_RX_DROP : NET_RX_SUCCESS; 168 return err ? NET_RX_DROP : NET_RX_SUCCESS;
168} 169}
169 170
diff --git a/net/phonet/pep-gprs.c b/net/phonet/pep-gprs.c
index d183509d3fa6..d01208968c83 100644
--- a/net/phonet/pep-gprs.c
+++ b/net/phonet/pep-gprs.c
@@ -96,11 +96,11 @@ static int gprs_recv(struct gprs_dev *gp, struct sk_buff *skb)
96 goto drop; 96 goto drop;
97 } 97 }
98 98
99 if (likely(skb_headroom(skb) & 3)) { 99 if (skb_headroom(skb) & 3) {
100 struct sk_buff *rskb, *fs; 100 struct sk_buff *rskb, *fs;
101 int flen = 0; 101 int flen = 0;
102 102
103 /* Phonet Pipe data header is misaligned (3 bytes), 103 /* Phonet Pipe data header may be misaligned (3 bytes),
104 * 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
105 * socket buffer. The network stack will pull what it needs, 105 * socket buffer. The network stack will pull what it needs,
106 * but at least, the whole IP payload is not memcpy'd. */ 106 * but at least, the whole IP payload is not memcpy'd. */
diff --git a/net/phonet/pep.c b/net/phonet/pep.c
index 5f32d217535b..e2a95762abd3 100644
--- a/net/phonet/pep.c
+++ b/net/phonet/pep.c
@@ -23,6 +23,7 @@
23 */ 23 */
24 24
25#include <linux/kernel.h> 25#include <linux/kernel.h>
26#include <linux/slab.h>
26#include <linux/socket.h> 27#include <linux/socket.h>
27#include <net/sock.h> 28#include <net/sock.h>
28#include <net/tcp_states.h> 29#include <net/tcp_states.h>
@@ -354,14 +355,15 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
354 queue = &pn->ctrlreq_queue; 355 queue = &pn->ctrlreq_queue;
355 goto queue; 356 goto queue;
356 357
358 case PNS_PIPE_ALIGNED_DATA:
359 __skb_pull(skb, 1);
360 /* fall through */
357 case PNS_PIPE_DATA: 361 case PNS_PIPE_DATA:
358 __skb_pull(skb, 3); /* Pipe data header */ 362 __skb_pull(skb, 3); /* Pipe data header */
359 if (!pn_flow_safe(pn->rx_fc)) { 363 if (!pn_flow_safe(pn->rx_fc)) {
360 err = sock_queue_rcv_skb(sk, skb); 364 err = sock_queue_rcv_skb(sk, skb);
361 if (!err) 365 if (!err)
362 return 0; 366 return 0;
363 if (err == -ENOMEM)
364 atomic_inc(&sk->sk_drops);
365 break; 367 break;
366 } 368 }
367 369
@@ -443,6 +445,7 @@ static int pep_connreq_rcv(struct sock *sk, struct sk_buff *skb)
443 struct sockaddr_pn dst; 445 struct sockaddr_pn dst;
444 u16 peer_type; 446 u16 peer_type;
445 u8 pipe_handle, enabled, n_sb; 447 u8 pipe_handle, enabled, n_sb;
448 u8 aligned = 0;
446 449
447 if (!pskb_pull(skb, sizeof(*hdr) + 4)) 450 if (!pskb_pull(skb, sizeof(*hdr) + 4))
448 return -EINVAL; 451 return -EINVAL;
@@ -481,6 +484,9 @@ static int pep_connreq_rcv(struct sock *sk, struct sk_buff *skb)
481 return -EINVAL; 484 return -EINVAL;
482 peer_type = (peer_type & 0xff00) | data[0]; 485 peer_type = (peer_type & 0xff00) | data[0];
483 break; 486 break;
487 case PN_PIPE_SB_ALIGNED_DATA:
488 aligned = data[0] != 0;
489 break;
484 } 490 }
485 n_sb--; 491 n_sb--;
486 } 492 }
@@ -512,6 +518,7 @@ static int pep_connreq_rcv(struct sock *sk, struct sk_buff *skb)
512 newpn->rx_credits = 0; 518 newpn->rx_credits = 0;
513 newpn->rx_fc = newpn->tx_fc = PN_LEGACY_FLOW_CONTROL; 519 newpn->rx_fc = newpn->tx_fc = PN_LEGACY_FLOW_CONTROL;
514 newpn->init_enable = enabled; 520 newpn->init_enable = enabled;
521 newpn->aligned = aligned;
515 522
516 BUG_ON(!skb_queue_empty(&newsk->sk_receive_queue)); 523 BUG_ON(!skb_queue_empty(&newsk->sk_receive_queue));
517 skb_queue_head(&newsk->sk_receive_queue, skb); 524 skb_queue_head(&newsk->sk_receive_queue, skb);
@@ -716,8 +723,8 @@ static int pep_ioctl(struct sock *sk, int cmd, unsigned long arg)
716 return -EINVAL; 723 return -EINVAL;
717 724
718 lock_sock(sk); 725 lock_sock(sk);
719 if (sock_flag(sk, SOCK_URGINLINE) 726 if (sock_flag(sk, SOCK_URGINLINE) &&
720 && !skb_queue_empty(&pn->ctrlreq_queue)) 727 !skb_queue_empty(&pn->ctrlreq_queue))
721 answ = skb_peek(&pn->ctrlreq_queue)->len; 728 answ = skb_peek(&pn->ctrlreq_queue)->len;
722 else if (!skb_queue_empty(&sk->sk_receive_queue)) 729 else if (!skb_queue_empty(&sk->sk_receive_queue))
723 answ = skb_peek(&sk->sk_receive_queue)->len; 730 answ = skb_peek(&sk->sk_receive_queue)->len;
@@ -831,11 +838,15 @@ static int pipe_skb_send(struct sock *sk, struct sk_buff *skb)
831 return -ENOBUFS; 838 return -ENOBUFS;
832 } 839 }
833 840
834 skb_push(skb, 3); 841 skb_push(skb, 3 + pn->aligned);
835 skb_reset_transport_header(skb); 842 skb_reset_transport_header(skb);
836 ph = pnp_hdr(skb); 843 ph = pnp_hdr(skb);
837 ph->utid = 0; 844 ph->utid = 0;
838 ph->message_id = PNS_PIPE_DATA; 845 if (pn->aligned) {
846 ph->message_id = PNS_PIPE_ALIGNED_DATA;
847 ph->data[0] = 0; /* padding */
848 } else
849 ph->message_id = PNS_PIPE_DATA;
839 ph->pipe_handle = pn->pipe_handle; 850 ph->pipe_handle = pn->pipe_handle;
840 851
841 return pn_skb_send(sk, skb, &pipe_srv); 852 return pn_skb_send(sk, skb, &pipe_srv);
@@ -845,14 +856,26 @@ static int pep_sendmsg(struct kiocb *iocb, struct sock *sk,
845 struct msghdr *msg, size_t len) 856 struct msghdr *msg, size_t len)
846{ 857{
847 struct pep_sock *pn = pep_sk(sk); 858 struct pep_sock *pn = pep_sk(sk);
848 struct sk_buff *skb = NULL; 859 struct sk_buff *skb;
849 long timeo; 860 long timeo;
850 int flags = msg->msg_flags; 861 int flags = msg->msg_flags;
851 int err, done; 862 int err, done;
852 863
853 if (msg->msg_flags & MSG_OOB || !(msg->msg_flags & MSG_EOR)) 864 if ((msg->msg_flags & ~(MSG_DONTWAIT|MSG_EOR|MSG_NOSIGNAL|
865 MSG_CMSG_COMPAT)) ||
866 !(msg->msg_flags & MSG_EOR))
854 return -EOPNOTSUPP; 867 return -EOPNOTSUPP;
855 868
869 skb = sock_alloc_send_skb(sk, MAX_PNPIPE_HEADER + len,
870 flags & MSG_DONTWAIT, &err);
871 if (!skb)
872 return -ENOBUFS;
873
874 skb_reserve(skb, MAX_PHONET_HEADER + 3);
875 err = memcpy_fromiovec(skb_put(skb, len), msg->msg_iov, len);
876 if (err < 0)
877 goto outfree;
878
856 lock_sock(sk); 879 lock_sock(sk);
857 timeo = sock_sndtimeo(sk, flags & MSG_DONTWAIT); 880 timeo = sock_sndtimeo(sk, flags & MSG_DONTWAIT);
858 if ((1 << sk->sk_state) & (TCPF_LISTEN|TCPF_CLOSE)) { 881 if ((1 << sk->sk_state) & (TCPF_LISTEN|TCPF_CLOSE)) {
@@ -896,28 +919,13 @@ disabled:
896 goto disabled; 919 goto disabled;
897 } 920 }
898 921
899 if (!skb) {
900 skb = sock_alloc_send_skb(sk, MAX_PNPIPE_HEADER + len,
901 flags & MSG_DONTWAIT, &err);
902 if (skb == NULL)
903 goto out;
904 skb_reserve(skb, MAX_PHONET_HEADER + 3);
905
906 if (sk->sk_state != TCP_ESTABLISHED ||
907 !atomic_read(&pn->tx_credits))
908 goto disabled; /* sock_alloc_send_skb might sleep */
909 }
910
911 err = memcpy_fromiovec(skb_put(skb, len), msg->msg_iov, len);
912 if (err < 0)
913 goto out;
914
915 err = pipe_skb_send(sk, skb); 922 err = pipe_skb_send(sk, skb);
916 if (err >= 0) 923 if (err >= 0)
917 err = len; /* success! */ 924 err = len; /* success! */
918 skb = NULL; 925 skb = NULL;
919out: 926out:
920 release_sock(sk); 927 release_sock(sk);
928outfree:
921 kfree_skb(skb); 929 kfree_skb(skb);
922 return err; 930 return err;
923} 931}
@@ -934,6 +942,9 @@ int pep_write(struct sock *sk, struct sk_buff *skb)
934 struct sk_buff *rskb, *fs; 942 struct sk_buff *rskb, *fs;
935 int flen = 0; 943 int flen = 0;
936 944
945 if (pep_sk(sk)->aligned)
946 return pipe_skb_send(sk, skb);
947
937 rskb = alloc_skb(MAX_PNPIPE_HEADER, GFP_ATOMIC); 948 rskb = alloc_skb(MAX_PNPIPE_HEADER, GFP_ATOMIC);
938 if (!rskb) { 949 if (!rskb) {
939 kfree_skb(skb); 950 kfree_skb(skb);
@@ -973,6 +984,10 @@ static int pep_recvmsg(struct kiocb *iocb, struct sock *sk,
973 struct sk_buff *skb; 984 struct sk_buff *skb;
974 int err; 985 int err;
975 986
987 if (flags & ~(MSG_OOB|MSG_PEEK|MSG_TRUNC|MSG_DONTWAIT|MSG_WAITALL|
988 MSG_NOSIGNAL|MSG_CMSG_COMPAT))
989 return -EOPNOTSUPP;
990
976 if (unlikely(1 << sk->sk_state & (TCPF_LISTEN | TCPF_CLOSE))) 991 if (unlikely(1 << sk->sk_state & (TCPF_LISTEN | TCPF_CLOSE)))
977 return -ENOTCONN; 992 return -ENOTCONN;
978 993
@@ -980,6 +995,8 @@ static int pep_recvmsg(struct kiocb *iocb, struct sock *sk,
980 /* Dequeue and acknowledge control request */ 995 /* Dequeue and acknowledge control request */
981 struct pep_sock *pn = pep_sk(sk); 996 struct pep_sock *pn = pep_sk(sk);
982 997
998 if (flags & MSG_PEEK)
999 return -EOPNOTSUPP;
983 skb = skb_dequeue(&pn->ctrlreq_queue); 1000 skb = skb_dequeue(&pn->ctrlreq_queue);
984 if (skb) { 1001 if (skb) {
985 pep_ctrlreq_error(sk, skb, PN_PIPE_NO_ERROR, 1002 pep_ctrlreq_error(sk, skb, PN_PIPE_NO_ERROR,
diff --git a/net/phonet/pn_dev.c b/net/phonet/pn_dev.c
index 5f42f30dd168..9b4ced6e0968 100644
--- a/net/phonet/pn_dev.c
+++ b/net/phonet/pn_dev.c
@@ -25,6 +25,7 @@
25 25
26#include <linux/kernel.h> 26#include <linux/kernel.h>
27#include <linux/net.h> 27#include <linux/net.h>
28#include <linux/slab.h>
28#include <linux/netdevice.h> 29#include <linux/netdevice.h>
29#include <linux/phonet.h> 30#include <linux/phonet.h>
30#include <linux/proc_fs.h> 31#include <linux/proc_fs.h>
@@ -33,11 +34,17 @@
33#include <net/netns/generic.h> 34#include <net/netns/generic.h>
34#include <net/phonet/pn_dev.h> 35#include <net/phonet/pn_dev.h>
35 36
37struct phonet_routes {
38 struct mutex lock;
39 struct net_device *table[64];
40};
41
36struct phonet_net { 42struct phonet_net {
37 struct phonet_device_list pndevs; 43 struct phonet_device_list pndevs;
44 struct phonet_routes routes;
38}; 45};
39 46
40int phonet_net_id; 47int phonet_net_id __read_mostly;
41 48
42struct phonet_device_list *phonet_device_list(struct net *net) 49struct phonet_device_list *phonet_device_list(struct net *net)
43{ 50{
@@ -55,7 +62,8 @@ static struct phonet_device *__phonet_device_alloc(struct net_device *dev)
55 pnd->netdev = dev; 62 pnd->netdev = dev;
56 bitmap_zero(pnd->addrs, 64); 63 bitmap_zero(pnd->addrs, 64);
57 64
58 list_add(&pnd->list, &pndevs->list); 65 BUG_ON(!mutex_is_locked(&pndevs->lock));
66 list_add_rcu(&pnd->list, &pndevs->list);
59 return pnd; 67 return pnd;
60} 68}
61 69
@@ -64,6 +72,7 @@ static struct phonet_device *__phonet_get(struct net_device *dev)
64 struct phonet_device_list *pndevs = phonet_device_list(dev_net(dev)); 72 struct phonet_device_list *pndevs = phonet_device_list(dev_net(dev));
65 struct phonet_device *pnd; 73 struct phonet_device *pnd;
66 74
75 BUG_ON(!mutex_is_locked(&pndevs->lock));
67 list_for_each_entry(pnd, &pndevs->list, list) { 76 list_for_each_entry(pnd, &pndevs->list, list) {
68 if (pnd->netdev == dev) 77 if (pnd->netdev == dev)
69 return pnd; 78 return pnd;
@@ -71,6 +80,18 @@ static struct phonet_device *__phonet_get(struct net_device *dev)
71 return NULL; 80 return NULL;
72} 81}
73 82
83static struct phonet_device *__phonet_get_rcu(struct net_device *dev)
84{
85 struct phonet_device_list *pndevs = phonet_device_list(dev_net(dev));
86 struct phonet_device *pnd;
87
88 list_for_each_entry_rcu(pnd, &pndevs->list, list) {
89 if (pnd->netdev == dev)
90 return pnd;
91 }
92 return NULL;
93}
94
74static void phonet_device_destroy(struct net_device *dev) 95static void phonet_device_destroy(struct net_device *dev)
75{ 96{
76 struct phonet_device_list *pndevs = phonet_device_list(dev_net(dev)); 97 struct phonet_device_list *pndevs = phonet_device_list(dev_net(dev));
@@ -78,17 +99,16 @@ static void phonet_device_destroy(struct net_device *dev)
78 99
79 ASSERT_RTNL(); 100 ASSERT_RTNL();
80 101
81 spin_lock_bh(&pndevs->lock); 102 mutex_lock(&pndevs->lock);
82 pnd = __phonet_get(dev); 103 pnd = __phonet_get(dev);
83 if (pnd) 104 if (pnd)
84 list_del(&pnd->list); 105 list_del_rcu(&pnd->list);
85 spin_unlock_bh(&pndevs->lock); 106 mutex_unlock(&pndevs->lock);
86 107
87 if (pnd) { 108 if (pnd) {
88 u8 addr; 109 u8 addr;
89 110
90 for (addr = find_first_bit(pnd->addrs, 64); addr < 64; 111 for_each_set_bit(addr, pnd->addrs, 64)
91 addr = find_next_bit(pnd->addrs, 64, 1+addr))
92 phonet_address_notify(RTM_DELADDR, dev, addr); 112 phonet_address_notify(RTM_DELADDR, dev, addr);
93 kfree(pnd); 113 kfree(pnd);
94 } 114 }
@@ -100,8 +120,8 @@ struct net_device *phonet_device_get(struct net *net)
100 struct phonet_device *pnd; 120 struct phonet_device *pnd;
101 struct net_device *dev = NULL; 121 struct net_device *dev = NULL;
102 122
103 spin_lock_bh(&pndevs->lock); 123 rcu_read_lock();
104 list_for_each_entry(pnd, &pndevs->list, list) { 124 list_for_each_entry_rcu(pnd, &pndevs->list, list) {
105 dev = pnd->netdev; 125 dev = pnd->netdev;
106 BUG_ON(!dev); 126 BUG_ON(!dev);
107 127
@@ -112,7 +132,7 @@ struct net_device *phonet_device_get(struct net *net)
112 } 132 }
113 if (dev) 133 if (dev)
114 dev_hold(dev); 134 dev_hold(dev);
115 spin_unlock_bh(&pndevs->lock); 135 rcu_read_unlock();
116 return dev; 136 return dev;
117} 137}
118 138
@@ -122,7 +142,7 @@ int phonet_address_add(struct net_device *dev, u8 addr)
122 struct phonet_device *pnd; 142 struct phonet_device *pnd;
123 int err = 0; 143 int err = 0;
124 144
125 spin_lock_bh(&pndevs->lock); 145 mutex_lock(&pndevs->lock);
126 /* Find or create Phonet-specific device data */ 146 /* Find or create Phonet-specific device data */
127 pnd = __phonet_get(dev); 147 pnd = __phonet_get(dev);
128 if (pnd == NULL) 148 if (pnd == NULL)
@@ -131,7 +151,7 @@ int phonet_address_add(struct net_device *dev, u8 addr)
131 err = -ENOMEM; 151 err = -ENOMEM;
132 else if (test_and_set_bit(addr >> 2, pnd->addrs)) 152 else if (test_and_set_bit(addr >> 2, pnd->addrs))
133 err = -EEXIST; 153 err = -EEXIST;
134 spin_unlock_bh(&pndevs->lock); 154 mutex_unlock(&pndevs->lock);
135 return err; 155 return err;
136} 156}
137 157
@@ -141,36 +161,56 @@ int phonet_address_del(struct net_device *dev, u8 addr)
141 struct phonet_device *pnd; 161 struct phonet_device *pnd;
142 int err = 0; 162 int err = 0;
143 163
144 spin_lock_bh(&pndevs->lock); 164 mutex_lock(&pndevs->lock);
145 pnd = __phonet_get(dev); 165 pnd = __phonet_get(dev);
146 if (!pnd || !test_and_clear_bit(addr >> 2, pnd->addrs)) 166 if (!pnd || !test_and_clear_bit(addr >> 2, pnd->addrs)) {
147 err = -EADDRNOTAVAIL; 167 err = -EADDRNOTAVAIL;
148 else if (bitmap_empty(pnd->addrs, 64)) { 168 pnd = NULL;
149 list_del(&pnd->list); 169 } else if (bitmap_empty(pnd->addrs, 64))
170 list_del_rcu(&pnd->list);
171 else
172 pnd = NULL;
173 mutex_unlock(&pndevs->lock);
174
175 if (pnd) {
176 synchronize_rcu();
150 kfree(pnd); 177 kfree(pnd);
151 } 178 }
152 spin_unlock_bh(&pndevs->lock);
153 return err; 179 return err;
154} 180}
155 181
156/* Gets a source address toward a destination, through a interface. */ 182/* Gets a source address toward a destination, through a interface. */
157u8 phonet_address_get(struct net_device *dev, u8 addr) 183u8 phonet_address_get(struct net_device *dev, u8 daddr)
158{ 184{
159 struct phonet_device_list *pndevs = phonet_device_list(dev_net(dev));
160 struct phonet_device *pnd; 185 struct phonet_device *pnd;
186 u8 saddr;
161 187
162 spin_lock_bh(&pndevs->lock); 188 rcu_read_lock();
163 pnd = __phonet_get(dev); 189 pnd = __phonet_get_rcu(dev);
164 if (pnd) { 190 if (pnd) {
165 BUG_ON(bitmap_empty(pnd->addrs, 64)); 191 BUG_ON(bitmap_empty(pnd->addrs, 64));
166 192
167 /* Use same source address as destination, if possible */ 193 /* Use same source address as destination, if possible */
168 if (!test_bit(addr >> 2, pnd->addrs)) 194 if (test_bit(daddr >> 2, pnd->addrs))
169 addr = find_first_bit(pnd->addrs, 64) << 2; 195 saddr = daddr;
196 else
197 saddr = find_first_bit(pnd->addrs, 64) << 2;
170 } else 198 } else
171 addr = PN_NO_ADDR; 199 saddr = PN_NO_ADDR;
172 spin_unlock_bh(&pndevs->lock); 200 rcu_read_unlock();
173 return addr; 201
202 if (saddr == PN_NO_ADDR) {
203 /* Fallback to another device */
204 struct net_device *def_dev;
205
206 def_dev = phonet_device_get(dev_net(dev));
207 if (def_dev) {
208 if (def_dev != dev)
209 saddr = phonet_address_get(def_dev, daddr);
210 dev_put(def_dev);
211 }
212 }
213 return saddr;
174} 214}
175 215
176int phonet_address_lookup(struct net *net, u8 addr) 216int phonet_address_lookup(struct net *net, u8 addr)
@@ -179,8 +219,8 @@ int phonet_address_lookup(struct net *net, u8 addr)
179 struct phonet_device *pnd; 219 struct phonet_device *pnd;
180 int err = -EADDRNOTAVAIL; 220 int err = -EADDRNOTAVAIL;
181 221
182 spin_lock_bh(&pndevs->lock); 222 rcu_read_lock();
183 list_for_each_entry(pnd, &pndevs->list, list) { 223 list_for_each_entry_rcu(pnd, &pndevs->list, list) {
184 /* Don't allow unregistering devices! */ 224 /* Don't allow unregistering devices! */
185 if ((pnd->netdev->reg_state != NETREG_REGISTERED) || 225 if ((pnd->netdev->reg_state != NETREG_REGISTERED) ||
186 ((pnd->netdev->flags & IFF_UP)) != IFF_UP) 226 ((pnd->netdev->flags & IFF_UP)) != IFF_UP)
@@ -192,7 +232,7 @@ int phonet_address_lookup(struct net *net, u8 addr)
192 } 232 }
193 } 233 }
194found: 234found:
195 spin_unlock_bh(&pndevs->lock); 235 rcu_read_unlock();
196 return err; 236 return err;
197} 237}
198 238
@@ -219,6 +259,32 @@ static int phonet_device_autoconf(struct net_device *dev)
219 return 0; 259 return 0;
220} 260}
221 261
262static void phonet_route_autodel(struct net_device *dev)
263{
264 struct phonet_net *pnn = net_generic(dev_net(dev), phonet_net_id);
265 unsigned i;
266 DECLARE_BITMAP(deleted, 64);
267
268 /* Remove left-over Phonet routes */
269 bitmap_zero(deleted, 64);
270 mutex_lock(&pnn->routes.lock);
271 for (i = 0; i < 64; i++)
272 if (dev == pnn->routes.table[i]) {
273 rcu_assign_pointer(pnn->routes.table[i], NULL);
274 set_bit(i, deleted);
275 }
276 mutex_unlock(&pnn->routes.lock);
277
278 if (bitmap_empty(deleted, 64))
279 return; /* short-circuit RCU */
280 synchronize_rcu();
281 for (i = find_first_bit(deleted, 64); i < 64;
282 i = find_next_bit(deleted, 64, i + 1)) {
283 rtm_phonet_notify(RTM_DELROUTE, dev, i);
284 dev_put(dev);
285 }
286}
287
222/* notify Phonet of device events */ 288/* notify Phonet of device events */
223static int phonet_device_notify(struct notifier_block *me, unsigned long what, 289static int phonet_device_notify(struct notifier_block *me, unsigned long what,
224 void *arg) 290 void *arg)
@@ -232,6 +298,7 @@ static int phonet_device_notify(struct notifier_block *me, unsigned long what,
232 break; 298 break;
233 case NETDEV_UNREGISTER: 299 case NETDEV_UNREGISTER:
234 phonet_device_destroy(dev); 300 phonet_device_destroy(dev);
301 phonet_route_autodel(dev);
235 break; 302 break;
236 } 303 }
237 return 0; 304 return 0;
@@ -244,46 +311,52 @@ static struct notifier_block phonet_device_notifier = {
244}; 311};
245 312
246/* Per-namespace Phonet devices handling */ 313/* Per-namespace Phonet devices handling */
247static int phonet_init_net(struct net *net) 314static int __net_init phonet_init_net(struct net *net)
248{ 315{
249 struct phonet_net *pnn = kmalloc(sizeof(*pnn), GFP_KERNEL); 316 struct phonet_net *pnn = net_generic(net, phonet_net_id);
250 if (!pnn)
251 return -ENOMEM;
252 317
253 if (!proc_net_fops_create(net, "phonet", 0, &pn_sock_seq_fops)) { 318 if (!proc_net_fops_create(net, "phonet", 0, &pn_sock_seq_fops))
254 kfree(pnn);
255 return -ENOMEM; 319 return -ENOMEM;
256 }
257 320
258 INIT_LIST_HEAD(&pnn->pndevs.list); 321 INIT_LIST_HEAD(&pnn->pndevs.list);
259 spin_lock_init(&pnn->pndevs.lock); 322 mutex_init(&pnn->pndevs.lock);
260 net_assign_generic(net, phonet_net_id, pnn); 323 mutex_init(&pnn->routes.lock);
261 return 0; 324 return 0;
262} 325}
263 326
264static void phonet_exit_net(struct net *net) 327static void __net_exit phonet_exit_net(struct net *net)
265{ 328{
266 struct phonet_net *pnn = net_generic(net, phonet_net_id); 329 struct phonet_net *pnn = net_generic(net, phonet_net_id);
267 struct net_device *dev; 330 struct net_device *dev;
331 unsigned i;
268 332
269 rtnl_lock(); 333 rtnl_lock();
270 for_each_netdev(net, dev) 334 for_each_netdev(net, dev)
271 phonet_device_destroy(dev); 335 phonet_device_destroy(dev);
336
337 for (i = 0; i < 64; i++) {
338 dev = pnn->routes.table[i];
339 if (dev) {
340 rtm_phonet_notify(RTM_DELROUTE, dev, i);
341 dev_put(dev);
342 }
343 }
272 rtnl_unlock(); 344 rtnl_unlock();
273 345
274 proc_net_remove(net, "phonet"); 346 proc_net_remove(net, "phonet");
275 kfree(pnn);
276} 347}
277 348
278static struct pernet_operations phonet_net_ops = { 349static struct pernet_operations phonet_net_ops = {
279 .init = phonet_init_net, 350 .init = phonet_init_net,
280 .exit = phonet_exit_net, 351 .exit = phonet_exit_net,
352 .id = &phonet_net_id,
353 .size = sizeof(struct phonet_net),
281}; 354};
282 355
283/* Initialize Phonet devices list */ 356/* Initialize Phonet devices list */
284int __init phonet_device_init(void) 357int __init phonet_device_init(void)
285{ 358{
286 int err = register_pernet_gen_device(&phonet_net_id, &phonet_net_ops); 359 int err = register_pernet_device(&phonet_net_ops);
287 if (err) 360 if (err)
288 return err; 361 return err;
289 362
@@ -298,5 +371,75 @@ void phonet_device_exit(void)
298{ 371{
299 rtnl_unregister_all(PF_PHONET); 372 rtnl_unregister_all(PF_PHONET);
300 unregister_netdevice_notifier(&phonet_device_notifier); 373 unregister_netdevice_notifier(&phonet_device_notifier);
301 unregister_pernet_gen_device(phonet_net_id, &phonet_net_ops); 374 unregister_pernet_device(&phonet_net_ops);
375}
376
377int phonet_route_add(struct net_device *dev, u8 daddr)
378{
379 struct phonet_net *pnn = net_generic(dev_net(dev), phonet_net_id);
380 struct phonet_routes *routes = &pnn->routes;
381 int err = -EEXIST;
382
383 daddr = daddr >> 2;
384 mutex_lock(&routes->lock);
385 if (routes->table[daddr] == NULL) {
386 rcu_assign_pointer(routes->table[daddr], dev);
387 dev_hold(dev);
388 err = 0;
389 }
390 mutex_unlock(&routes->lock);
391 return err;
392}
393
394int phonet_route_del(struct net_device *dev, u8 daddr)
395{
396 struct phonet_net *pnn = net_generic(dev_net(dev), phonet_net_id);
397 struct phonet_routes *routes = &pnn->routes;
398
399 daddr = daddr >> 2;
400 mutex_lock(&routes->lock);
401 if (dev == routes->table[daddr])
402 rcu_assign_pointer(routes->table[daddr], NULL);
403 else
404 dev = NULL;
405 mutex_unlock(&routes->lock);
406
407 if (!dev)
408 return -ENOENT;
409 synchronize_rcu();
410 dev_put(dev);
411 return 0;
412}
413
414struct net_device *phonet_route_get(struct net *net, u8 daddr)
415{
416 struct phonet_net *pnn = net_generic(net, phonet_net_id);
417 struct phonet_routes *routes = &pnn->routes;
418 struct net_device *dev;
419
420 ASSERT_RTNL(); /* no need to hold the device */
421
422 daddr >>= 2;
423 rcu_read_lock();
424 dev = rcu_dereference(routes->table[daddr]);
425 rcu_read_unlock();
426 return dev;
427}
428
429struct net_device *phonet_route_output(struct net *net, u8 daddr)
430{
431 struct phonet_net *pnn = net_generic(net, phonet_net_id);
432 struct phonet_routes *routes = &pnn->routes;
433 struct net_device *dev;
434
435 daddr >>= 2;
436 rcu_read_lock();
437 dev = rcu_dereference(routes->table[daddr]);
438 if (dev)
439 dev_hold(dev);
440 rcu_read_unlock();
441
442 if (!dev)
443 dev = phonet_device_get(net); /* Default route */
444 return dev;
302} 445}
diff --git a/net/phonet/pn_netlink.c b/net/phonet/pn_netlink.c
index d21fd3576610..58b3b1f991ed 100644
--- a/net/phonet/pn_netlink.c
+++ b/net/phonet/pn_netlink.c
@@ -26,9 +26,12 @@
26#include <linux/kernel.h> 26#include <linux/kernel.h>
27#include <linux/netlink.h> 27#include <linux/netlink.h>
28#include <linux/phonet.h> 28#include <linux/phonet.h>
29#include <linux/slab.h>
29#include <net/sock.h> 30#include <net/sock.h>
30#include <net/phonet/pn_dev.h> 31#include <net/phonet/pn_dev.h>
31 32
33/* Device address handling */
34
32static int fill_addr(struct sk_buff *skb, struct net_device *dev, u8 addr, 35static int fill_addr(struct sk_buff *skb, struct net_device *dev, u8 addr,
33 u32 pid, u32 seq, int event); 36 u32 pid, u32 seq, int event);
34 37
@@ -51,8 +54,7 @@ void phonet_address_notify(int event, struct net_device *dev, u8 addr)
51 RTNLGRP_PHONET_IFADDR, NULL, GFP_KERNEL); 54 RTNLGRP_PHONET_IFADDR, NULL, GFP_KERNEL);
52 return; 55 return;
53errout: 56errout:
54 if (err < 0) 57 rtnl_set_sk_err(dev_net(dev), RTNLGRP_PHONET_IFADDR, err);
55 rtnl_set_sk_err(dev_net(dev), RTNLGRP_PHONET_IFADDR, err);
56} 58}
57 59
58static const struct nla_policy ifa_phonet_policy[IFA_MAX+1] = { 60static const struct nla_policy ifa_phonet_policy[IFA_MAX+1] = {
@@ -130,8 +132,8 @@ static int getaddr_dumpit(struct sk_buff *skb, struct netlink_callback *cb)
130 int addr_idx = 0, addr_start_idx = cb->args[1]; 132 int addr_idx = 0, addr_start_idx = cb->args[1];
131 133
132 pndevs = phonet_device_list(sock_net(skb->sk)); 134 pndevs = phonet_device_list(sock_net(skb->sk));
133 spin_lock_bh(&pndevs->lock); 135 rcu_read_lock();
134 list_for_each_entry(pnd, &pndevs->list, list) { 136 list_for_each_entry_rcu(pnd, &pndevs->list, list) {
135 u8 addr; 137 u8 addr;
136 138
137 if (dev_idx > dev_start_idx) 139 if (dev_idx > dev_start_idx)
@@ -140,8 +142,7 @@ static int getaddr_dumpit(struct sk_buff *skb, struct netlink_callback *cb)
140 continue; 142 continue;
141 143
142 addr_idx = 0; 144 addr_idx = 0;
143 for (addr = find_first_bit(pnd->addrs, 64); addr < 64; 145 for_each_set_bit(addr, pnd->addrs, 64) {
144 addr = find_next_bit(pnd->addrs, 64, 1+addr)) {
145 if (addr_idx++ < addr_start_idx) 146 if (addr_idx++ < addr_start_idx)
146 continue; 147 continue;
147 148
@@ -153,13 +154,137 @@ static int getaddr_dumpit(struct sk_buff *skb, struct netlink_callback *cb)
153 } 154 }
154 155
155out: 156out:
156 spin_unlock_bh(&pndevs->lock); 157 rcu_read_unlock();
157 cb->args[0] = dev_idx; 158 cb->args[0] = dev_idx;
158 cb->args[1] = addr_idx; 159 cb->args[1] = addr_idx;
159 160
160 return skb->len; 161 return skb->len;
161} 162}
162 163
164/* Routes handling */
165
166static int fill_route(struct sk_buff *skb, struct net_device *dev, u8 dst,
167 u32 pid, u32 seq, int event)
168{
169 struct rtmsg *rtm;
170 struct nlmsghdr *nlh;
171
172 nlh = nlmsg_put(skb, pid, seq, event, sizeof(*rtm), 0);
173 if (nlh == NULL)
174 return -EMSGSIZE;
175
176 rtm = nlmsg_data(nlh);
177 rtm->rtm_family = AF_PHONET;
178 rtm->rtm_dst_len = 6;
179 rtm->rtm_src_len = 0;
180 rtm->rtm_tos = 0;
181 rtm->rtm_table = RT_TABLE_MAIN;
182 rtm->rtm_protocol = RTPROT_STATIC;
183 rtm->rtm_scope = RT_SCOPE_UNIVERSE;
184 rtm->rtm_type = RTN_UNICAST;
185 rtm->rtm_flags = 0;
186 NLA_PUT_U8(skb, RTA_DST, dst);
187 NLA_PUT_U32(skb, RTA_OIF, dev->ifindex);
188 return nlmsg_end(skb, nlh);
189
190nla_put_failure:
191 nlmsg_cancel(skb, nlh);
192 return -EMSGSIZE;
193}
194
195void rtm_phonet_notify(int event, struct net_device *dev, u8 dst)
196{
197 struct sk_buff *skb;
198 int err = -ENOBUFS;
199
200 skb = nlmsg_new(NLMSG_ALIGN(sizeof(struct ifaddrmsg)) +
201 nla_total_size(1) + nla_total_size(4), GFP_KERNEL);
202 if (skb == NULL)
203 goto errout;
204 err = fill_route(skb, dev, dst, 0, 0, event);
205 if (err < 0) {
206 WARN_ON(err == -EMSGSIZE);
207 kfree_skb(skb);
208 goto errout;
209 }
210 rtnl_notify(skb, dev_net(dev), 0,
211 RTNLGRP_PHONET_ROUTE, NULL, GFP_KERNEL);
212 return;
213errout:
214 rtnl_set_sk_err(dev_net(dev), RTNLGRP_PHONET_ROUTE, err);
215}
216
217static const struct nla_policy rtm_phonet_policy[RTA_MAX+1] = {
218 [RTA_DST] = { .type = NLA_U8 },
219 [RTA_OIF] = { .type = NLA_U32 },
220};
221
222static int route_doit(struct sk_buff *skb, struct nlmsghdr *nlh, void *attr)
223{
224 struct net *net = sock_net(skb->sk);
225 struct nlattr *tb[RTA_MAX+1];
226 struct net_device *dev;
227 struct rtmsg *rtm;
228 int err;
229 u8 dst;
230
231 if (!capable(CAP_SYS_ADMIN))
232 return -EPERM;
233
234 ASSERT_RTNL();
235
236 err = nlmsg_parse(nlh, sizeof(*rtm), tb, RTA_MAX, rtm_phonet_policy);
237 if (err < 0)
238 return err;
239
240 rtm = nlmsg_data(nlh);
241 if (rtm->rtm_table != RT_TABLE_MAIN || rtm->rtm_type != RTN_UNICAST)
242 return -EINVAL;
243 if (tb[RTA_DST] == NULL || tb[RTA_OIF] == NULL)
244 return -EINVAL;
245 dst = nla_get_u8(tb[RTA_DST]);
246 if (dst & 3) /* Phonet addresses only have 6 high-order bits */
247 return -EINVAL;
248
249 dev = __dev_get_by_index(net, nla_get_u32(tb[RTA_OIF]));
250 if (dev == NULL)
251 return -ENODEV;
252
253 if (nlh->nlmsg_type == RTM_NEWROUTE)
254 err = phonet_route_add(dev, dst);
255 else
256 err = phonet_route_del(dev, dst);
257 if (!err)
258 rtm_phonet_notify(nlh->nlmsg_type, dev, dst);
259 return err;
260}
261
262static int route_dumpit(struct sk_buff *skb, struct netlink_callback *cb)
263{
264 struct net *net = sock_net(skb->sk);
265 u8 addr, addr_idx = 0, addr_start_idx = cb->args[0];
266
267 for (addr = 0; addr < 64; addr++) {
268 struct net_device *dev;
269
270 dev = phonet_route_get(net, addr << 2);
271 if (!dev)
272 continue;
273
274 if (addr_idx++ < addr_start_idx)
275 continue;
276 if (fill_route(skb, dev, addr << 2, NETLINK_CB(cb->skb).pid,
277 cb->nlh->nlmsg_seq, RTM_NEWROUTE))
278 goto out;
279 }
280
281out:
282 cb->args[0] = addr_idx;
283 cb->args[1] = 0;
284
285 return skb->len;
286}
287
163int __init phonet_netlink_register(void) 288int __init phonet_netlink_register(void)
164{ 289{
165 int err = __rtnl_register(PF_PHONET, RTM_NEWADDR, addr_doit, NULL); 290 int err = __rtnl_register(PF_PHONET, RTM_NEWADDR, addr_doit, NULL);
@@ -169,5 +294,8 @@ int __init phonet_netlink_register(void)
169 /* Further __rtnl_register() cannot fail */ 294 /* Further __rtnl_register() cannot fail */
170 __rtnl_register(PF_PHONET, RTM_DELADDR, addr_doit, NULL); 295 __rtnl_register(PF_PHONET, RTM_DELADDR, addr_doit, NULL);
171 __rtnl_register(PF_PHONET, RTM_GETADDR, NULL, getaddr_dumpit); 296 __rtnl_register(PF_PHONET, RTM_GETADDR, NULL, getaddr_dumpit);
297 __rtnl_register(PF_PHONET, RTM_NEWROUTE, route_doit, NULL);
298 __rtnl_register(PF_PHONET, RTM_DELROUTE, route_doit, NULL);
299 __rtnl_register(PF_PHONET, RTM_GETROUTE, NULL, route_dumpit);
172 return 0; 300 return 0;
173} 301}
diff --git a/net/phonet/socket.c b/net/phonet/socket.c
index aa5b5a972bff..c785bfd0744f 100644
--- a/net/phonet/socket.c
+++ b/net/phonet/socket.c
@@ -23,6 +23,7 @@
23 * 02110-1301 USA 23 * 02110-1301 USA
24 */ 24 */
25 25
26#include <linux/gfp.h>
26#include <linux/kernel.h> 27#include <linux/kernel.h>
27#include <linux/net.h> 28#include <linux/net.h>
28#include <linux/poll.h> 29#include <linux/poll.h>
@@ -45,13 +46,28 @@ static int pn_socket_release(struct socket *sock)
45 return 0; 46 return 0;
46} 47}
47 48
49#define PN_HASHSIZE 16
50#define PN_HASHMASK (PN_HASHSIZE-1)
51
52
48static struct { 53static struct {
49 struct hlist_head hlist; 54 struct hlist_head hlist[PN_HASHSIZE];
50 spinlock_t lock; 55 spinlock_t lock;
51} pnsocks = { 56} pnsocks;
52 .hlist = HLIST_HEAD_INIT, 57
53 .lock = __SPIN_LOCK_UNLOCKED(pnsocks.lock), 58void __init pn_sock_init(void)
54}; 59{
60 unsigned i;
61
62 for (i = 0; i < PN_HASHSIZE; i++)
63 INIT_HLIST_HEAD(pnsocks.hlist + i);
64 spin_lock_init(&pnsocks.lock);
65}
66
67static struct hlist_head *pn_hash_list(u16 obj)
68{
69 return pnsocks.hlist + (obj & PN_HASHMASK);
70}
55 71
56/* 72/*
57 * Find address based on socket address, match only certain fields. 73 * Find address based on socket address, match only certain fields.
@@ -64,10 +80,11 @@ struct sock *pn_find_sock_by_sa(struct net *net, const struct sockaddr_pn *spn)
64 struct sock *rval = NULL; 80 struct sock *rval = NULL;
65 u16 obj = pn_sockaddr_get_object(spn); 81 u16 obj = pn_sockaddr_get_object(spn);
66 u8 res = spn->spn_resource; 82 u8 res = spn->spn_resource;
83 struct hlist_head *hlist = pn_hash_list(obj);
67 84
68 spin_lock_bh(&pnsocks.lock); 85 spin_lock_bh(&pnsocks.lock);
69 86
70 sk_for_each(sknode, node, &pnsocks.hlist) { 87 sk_for_each(sknode, node, hlist) {
71 struct pn_sock *pn = pn_sk(sknode); 88 struct pn_sock *pn = pn_sk(sknode);
72 BUG_ON(!pn->sobject); /* unbound socket */ 89 BUG_ON(!pn->sobject); /* unbound socket */
73 90
@@ -82,8 +99,8 @@ struct sock *pn_find_sock_by_sa(struct net *net, const struct sockaddr_pn *spn)
82 if (pn->resource != res) 99 if (pn->resource != res)
83 continue; 100 continue;
84 } 101 }
85 if (pn_addr(pn->sobject) 102 if (pn_addr(pn->sobject) &&
86 && pn_addr(pn->sobject) != pn_addr(obj)) 103 pn_addr(pn->sobject) != pn_addr(obj))
87 continue; 104 continue;
88 105
89 rval = sknode; 106 rval = sknode;
@@ -94,13 +111,44 @@ struct sock *pn_find_sock_by_sa(struct net *net, const struct sockaddr_pn *spn)
94 spin_unlock_bh(&pnsocks.lock); 111 spin_unlock_bh(&pnsocks.lock);
95 112
96 return rval; 113 return rval;
114}
115
116/* Deliver a broadcast packet (only in bottom-half) */
117void pn_deliver_sock_broadcast(struct net *net, struct sk_buff *skb)
118{
119 struct hlist_head *hlist = pnsocks.hlist;
120 unsigned h;
121
122 spin_lock(&pnsocks.lock);
123 for (h = 0; h < PN_HASHSIZE; h++) {
124 struct hlist_node *node;
125 struct sock *sknode;
126
127 sk_for_each(sknode, node, hlist) {
128 struct sk_buff *clone;
129
130 if (!net_eq(sock_net(sknode), net))
131 continue;
132 if (!sock_flag(sknode, SOCK_BROADCAST))
133 continue;
97 134
135 clone = skb_clone(skb, GFP_ATOMIC);
136 if (clone) {
137 sock_hold(sknode);
138 sk_receive_skb(sknode, clone, 0);
139 }
140 }
141 hlist++;
142 }
143 spin_unlock(&pnsocks.lock);
98} 144}
99 145
100void pn_sock_hash(struct sock *sk) 146void pn_sock_hash(struct sock *sk)
101{ 147{
148 struct hlist_head *hlist = pn_hash_list(pn_sk(sk)->sobject);
149
102 spin_lock_bh(&pnsocks.lock); 150 spin_lock_bh(&pnsocks.lock);
103 sk_add_node(sk, &pnsocks.hlist); 151 sk_add_node(sk, hlist);
104 spin_unlock_bh(&pnsocks.lock); 152 spin_unlock_bh(&pnsocks.lock);
105} 153}
106EXPORT_SYMBOL(pn_sock_hash); 154EXPORT_SYMBOL(pn_sock_hash);
@@ -416,15 +464,20 @@ EXPORT_SYMBOL(pn_sock_get_port);
416static struct sock *pn_sock_get_idx(struct seq_file *seq, loff_t pos) 464static struct sock *pn_sock_get_idx(struct seq_file *seq, loff_t pos)
417{ 465{
418 struct net *net = seq_file_net(seq); 466 struct net *net = seq_file_net(seq);
467 struct hlist_head *hlist = pnsocks.hlist;
419 struct hlist_node *node; 468 struct hlist_node *node;
420 struct sock *sknode; 469 struct sock *sknode;
470 unsigned h;
421 471
422 sk_for_each(sknode, node, &pnsocks.hlist) { 472 for (h = 0; h < PN_HASHSIZE; h++) {
423 if (!net_eq(net, sock_net(sknode))) 473 sk_for_each(sknode, node, hlist) {
424 continue; 474 if (!net_eq(net, sock_net(sknode)))
425 if (!pos) 475 continue;
426 return sknode; 476 if (!pos)
427 pos--; 477 return sknode;
478 pos--;
479 }
480 hlist++;
428 } 481 }
429 return NULL; 482 return NULL;
430} 483}
diff --git a/net/phonet/sysctl.c b/net/phonet/sysctl.c
index 2220f3322326..cea1c7dbdae2 100644
--- a/net/phonet/sysctl.c
+++ b/net/phonet/sysctl.c
@@ -84,20 +84,18 @@ static int proc_local_port_range(ctl_table *table, int write,
84 84
85static struct ctl_table phonet_table[] = { 85static struct ctl_table phonet_table[] = {
86 { 86 {
87 .ctl_name = CTL_UNNUMBERED,
88 .procname = "local_port_range", 87 .procname = "local_port_range",
89 .data = &local_port_range, 88 .data = &local_port_range,
90 .maxlen = sizeof(local_port_range), 89 .maxlen = sizeof(local_port_range),
91 .mode = 0644, 90 .mode = 0644,
92 .proc_handler = proc_local_port_range, 91 .proc_handler = proc_local_port_range,
93 .strategy = NULL,
94 }, 92 },
95 { .ctl_name = 0 } 93 { }
96}; 94};
97 95
98static struct ctl_path phonet_ctl_path[] = { 96static struct ctl_path phonet_ctl_path[] = {
99 { .procname = "net", .ctl_name = CTL_NET, }, 97 { .procname = "net", },
100 { .procname = "phonet", .ctl_name = CTL_UNNUMBERED, }, 98 { .procname = "phonet", },
101 { }, 99 { },
102}; 100};
103 101
diff --git a/net/rds/af_rds.c b/net/rds/af_rds.c
index 98e05382fd3c..f81862baf4d0 100644
--- a/net/rds/af_rds.c
+++ b/net/rds/af_rds.c
@@ -33,6 +33,7 @@
33#include <linux/module.h> 33#include <linux/module.h>
34#include <linux/errno.h> 34#include <linux/errno.h>
35#include <linux/kernel.h> 35#include <linux/kernel.h>
36#include <linux/gfp.h>
36#include <linux/in.h> 37#include <linux/in.h>
37#include <linux/poll.h> 38#include <linux/poll.h>
38#include <net/sock.h> 39#include <net/sock.h>
@@ -174,8 +175,8 @@ static unsigned int rds_poll(struct file *file, struct socket *sock,
174 mask |= (POLLIN | POLLRDNORM); 175 mask |= (POLLIN | POLLRDNORM);
175 spin_unlock(&rs->rs_lock); 176 spin_unlock(&rs->rs_lock);
176 } 177 }
177 if (!list_empty(&rs->rs_recv_queue) 178 if (!list_empty(&rs->rs_recv_queue) ||
178 || !list_empty(&rs->rs_notify_queue)) 179 !list_empty(&rs->rs_notify_queue))
179 mask |= (POLLIN | POLLRDNORM); 180 mask |= (POLLIN | POLLRDNORM);
180 if (rs->rs_snd_bytes < rds_sk_sndbuf(rs)) 181 if (rs->rs_snd_bytes < rds_sk_sndbuf(rs))
181 mask |= (POLLOUT | POLLWRNORM); 182 mask |= (POLLOUT | POLLWRNORM);
@@ -265,6 +266,9 @@ static int rds_setsockopt(struct socket *sock, int level, int optname,
265 case RDS_GET_MR: 266 case RDS_GET_MR:
266 ret = rds_get_mr(rs, optval, optlen); 267 ret = rds_get_mr(rs, optval, optlen);
267 break; 268 break;
269 case RDS_GET_MR_FOR_DEST:
270 ret = rds_get_mr_for_dest(rs, optval, optlen);
271 break;
268 case RDS_FREE_MR: 272 case RDS_FREE_MR:
269 ret = rds_free_mr(rs, optval, optlen); 273 ret = rds_free_mr(rs, optval, optlen);
270 break; 274 break;
@@ -305,8 +309,8 @@ static int rds_getsockopt(struct socket *sock, int level, int optname,
305 if (len < sizeof(int)) 309 if (len < sizeof(int))
306 ret = -EINVAL; 310 ret = -EINVAL;
307 else 311 else
308 if (put_user(rs->rs_recverr, (int __user *) optval) 312 if (put_user(rs->rs_recverr, (int __user *) optval) ||
309 || put_user(sizeof(int), optlen)) 313 put_user(sizeof(int), optlen))
310 ret = -EFAULT; 314 ret = -EFAULT;
311 else 315 else
312 ret = 0; 316 ret = 0;
@@ -407,7 +411,8 @@ static int __rds_create(struct socket *sock, struct sock *sk, int protocol)
407 return 0; 411 return 0;
408} 412}
409 413
410static int rds_create(struct net *net, struct socket *sock, int protocol) 414static int rds_create(struct net *net, struct socket *sock, int protocol,
415 int kern)
411{ 416{
412 struct sock *sk; 417 struct sock *sk;
413 418
@@ -431,7 +436,7 @@ void rds_sock_put(struct rds_sock *rs)
431 sock_put(rds_rs_to_sk(rs)); 436 sock_put(rds_rs_to_sk(rs));
432} 437}
433 438
434static struct net_proto_family rds_family_ops = { 439static const struct net_proto_family rds_family_ops = {
435 .family = AF_RDS, 440 .family = AF_RDS,
436 .create = rds_create, 441 .create = rds_create,
437 .owner = THIS_MODULE, 442 .owner = THIS_MODULE,
diff --git a/net/rds/cong.c b/net/rds/cong.c
index dd2711df640b..f1da27ceb064 100644
--- a/net/rds/cong.c
+++ b/net/rds/cong.c
@@ -30,6 +30,7 @@
30 * SOFTWARE. 30 * SOFTWARE.
31 * 31 *
32 */ 32 */
33#include <linux/slab.h>
33#include <linux/types.h> 34#include <linux/types.h>
34#include <linux/rbtree.h> 35#include <linux/rbtree.h>
35 36
@@ -218,6 +219,8 @@ void rds_cong_queue_updates(struct rds_cong_map *map)
218 spin_lock_irqsave(&rds_cong_lock, flags); 219 spin_lock_irqsave(&rds_cong_lock, flags);
219 220
220 list_for_each_entry(conn, &map->m_conn_list, c_map_item) { 221 list_for_each_entry(conn, &map->m_conn_list, c_map_item) {
222 if (conn->c_loopback)
223 continue;
221 if (!test_and_set_bit(0, &conn->c_map_queued)) { 224 if (!test_and_set_bit(0, &conn->c_map_queued)) {
222 rds_stats_inc(s_cong_update_queued); 225 rds_stats_inc(s_cong_update_queued);
223 queue_delayed_work(rds_wq, &conn->c_send_w, 0); 226 queue_delayed_work(rds_wq, &conn->c_send_w, 0);
diff --git a/net/rds/connection.c b/net/rds/connection.c
index cc8b568c0c84..7619b671ca28 100644
--- a/net/rds/connection.c
+++ b/net/rds/connection.c
@@ -32,6 +32,7 @@
32 */ 32 */
33#include <linux/kernel.h> 33#include <linux/kernel.h>
34#include <linux/list.h> 34#include <linux/list.h>
35#include <linux/slab.h>
35#include <net/inet_hashtables.h> 36#include <net/inet_hashtables.h>
36 37
37#include "rds.h" 38#include "rds.h"
@@ -133,10 +134,8 @@ static struct rds_connection *__rds_conn_create(__be32 laddr, __be32 faddr,
133 134
134 spin_lock_irqsave(&rds_conn_lock, flags); 135 spin_lock_irqsave(&rds_conn_lock, flags);
135 conn = rds_conn_lookup(head, laddr, faddr, trans); 136 conn = rds_conn_lookup(head, laddr, faddr, trans);
136 if (conn 137 if (conn && conn->c_loopback && conn->c_trans != &rds_loop_transport &&
137 && conn->c_loopback 138 !is_outgoing) {
138 && conn->c_trans != &rds_loop_transport
139 && !is_outgoing) {
140 /* This is a looped back IB connection, and we're 139 /* This is a looped back IB connection, and we're
141 * called by the code handling the incoming connect. 140 * called by the code handling the incoming connect.
142 * We need a second connection object into which we 141 * We need a second connection object into which we
diff --git a/net/rds/ib.c b/net/rds/ib.c
index 536ebe5d3f6b..8f2d6dd7700a 100644
--- a/net/rds/ib.c
+++ b/net/rds/ib.c
@@ -37,6 +37,7 @@
37#include <linux/inetdevice.h> 37#include <linux/inetdevice.h>
38#include <linux/if_arp.h> 38#include <linux/if_arp.h>
39#include <linux/delay.h> 39#include <linux/delay.h>
40#include <linux/slab.h>
40 41
41#include "rds.h" 42#include "rds.h"
42#include "ib.h" 43#include "ib.h"
@@ -182,8 +183,8 @@ static int rds_ib_conn_info_visitor(struct rds_connection *conn,
182 ic = conn->c_transport_data; 183 ic = conn->c_transport_data;
183 dev_addr = &ic->i_cm_id->route.addr.dev_addr; 184 dev_addr = &ic->i_cm_id->route.addr.dev_addr;
184 185
185 ib_addr_get_sgid(dev_addr, (union ib_gid *) &iinfo->src_gid); 186 rdma_addr_get_sgid(dev_addr, (union ib_gid *) &iinfo->src_gid);
186 ib_addr_get_dgid(dev_addr, (union ib_gid *) &iinfo->dst_gid); 187 rdma_addr_get_dgid(dev_addr, (union ib_gid *) &iinfo->dst_gid);
187 188
188 rds_ibdev = ib_get_client_data(ic->i_cm_id->device, &rds_ib_client); 189 rds_ibdev = ib_get_client_data(ic->i_cm_id->device, &rds_ib_client);
189 iinfo->max_send_wr = ic->i_send_ring.w_nr; 190 iinfo->max_send_wr = ic->i_send_ring.w_nr;
diff --git a/net/rds/ib.h b/net/rds/ib.h
index 1378b854cac0..64df4e79b29f 100644
--- a/net/rds/ib.h
+++ b/net/rds/ib.h
@@ -98,6 +98,7 @@ struct rds_ib_connection {
98 struct rds_ib_send_work *i_sends; 98 struct rds_ib_send_work *i_sends;
99 99
100 /* rx */ 100 /* rx */
101 struct tasklet_struct i_recv_tasklet;
101 struct mutex i_recv_mutex; 102 struct mutex i_recv_mutex;
102 struct rds_ib_work_ring i_recv_ring; 103 struct rds_ib_work_ring i_recv_ring;
103 struct rds_ib_incoming *i_ibinc; 104 struct rds_ib_incoming *i_ibinc;
@@ -303,6 +304,7 @@ void rds_ib_inc_free(struct rds_incoming *inc);
303int rds_ib_inc_copy_to_user(struct rds_incoming *inc, struct iovec *iov, 304int rds_ib_inc_copy_to_user(struct rds_incoming *inc, struct iovec *iov,
304 size_t size); 305 size_t size);
305void rds_ib_recv_cq_comp_handler(struct ib_cq *cq, void *context); 306void rds_ib_recv_cq_comp_handler(struct ib_cq *cq, void *context);
307void rds_ib_recv_tasklet_fn(unsigned long data);
306void rds_ib_recv_init_ring(struct rds_ib_connection *ic); 308void rds_ib_recv_init_ring(struct rds_ib_connection *ic);
307void rds_ib_recv_clear_ring(struct rds_ib_connection *ic); 309void rds_ib_recv_clear_ring(struct rds_ib_connection *ic);
308void rds_ib_recv_init_ack(struct rds_ib_connection *ic); 310void rds_ib_recv_init_ack(struct rds_ib_connection *ic);
diff --git a/net/rds/ib_cm.c b/net/rds/ib_cm.c
index c2d372f13dbb..88d0856cb797 100644
--- a/net/rds/ib_cm.c
+++ b/net/rds/ib_cm.c
@@ -32,6 +32,7 @@
32 */ 32 */
33#include <linux/kernel.h> 33#include <linux/kernel.h>
34#include <linux/in.h> 34#include <linux/in.h>
35#include <linux/slab.h>
35#include <linux/vmalloc.h> 36#include <linux/vmalloc.h>
36 37
37#include "rds.h" 38#include "rds.h"
@@ -377,8 +378,8 @@ static u32 rds_ib_protocol_compatible(struct rdma_cm_event *event)
377 } 378 }
378 379
379 /* Even if len is crap *now* I still want to check it. -ASG */ 380 /* Even if len is crap *now* I still want to check it. -ASG */
380 if (event->param.conn.private_data_len < sizeof (*dp) 381 if (event->param.conn.private_data_len < sizeof (*dp) ||
381 || dp->dp_protocol_major == 0) 382 dp->dp_protocol_major == 0)
382 return RDS_PROTOCOL_3_0; 383 return RDS_PROTOCOL_3_0;
383 384
384 common = be16_to_cpu(dp->dp_protocol_minor_mask) & RDS_IB_SUPPORTED_PROTOCOLS; 385 common = be16_to_cpu(dp->dp_protocol_minor_mask) & RDS_IB_SUPPORTED_PROTOCOLS;
@@ -694,6 +695,8 @@ int rds_ib_conn_alloc(struct rds_connection *conn, gfp_t gfp)
694 return -ENOMEM; 695 return -ENOMEM;
695 696
696 INIT_LIST_HEAD(&ic->ib_node); 697 INIT_LIST_HEAD(&ic->ib_node);
698 tasklet_init(&ic->i_recv_tasklet, rds_ib_recv_tasklet_fn,
699 (unsigned long) ic);
697 mutex_init(&ic->i_recv_mutex); 700 mutex_init(&ic->i_recv_mutex);
698#ifndef KERNEL_HAS_ATOMIC64 701#ifndef KERNEL_HAS_ATOMIC64
699 spin_lock_init(&ic->i_ack_lock); 702 spin_lock_init(&ic->i_ack_lock);
diff --git a/net/rds/ib_rdma.c b/net/rds/ib_rdma.c
index ef3ab5b7283e..059989fdb7d7 100644
--- a/net/rds/ib_rdma.c
+++ b/net/rds/ib_rdma.c
@@ -31,6 +31,7 @@
31 * 31 *
32 */ 32 */
33#include <linux/kernel.h> 33#include <linux/kernel.h>
34#include <linux/slab.h>
34 35
35#include "rds.h" 36#include "rds.h"
36#include "rdma.h" 37#include "rdma.h"
@@ -187,11 +188,8 @@ void __rds_ib_destroy_conns(struct list_head *list, spinlock_t *list_lock)
187 INIT_LIST_HEAD(list); 188 INIT_LIST_HEAD(list);
188 spin_unlock_irq(list_lock); 189 spin_unlock_irq(list_lock);
189 190
190 list_for_each_entry_safe(ic, _ic, &tmp_list, ib_node) { 191 list_for_each_entry_safe(ic, _ic, &tmp_list, ib_node)
191 if (ic->conn->c_passive)
192 rds_conn_destroy(ic->conn->c_passive);
193 rds_conn_destroy(ic->conn); 192 rds_conn_destroy(ic->conn);
194 }
195} 193}
196 194
197struct rds_ib_mr_pool *rds_ib_create_mr_pool(struct rds_ib_device *rds_ibdev) 195struct rds_ib_mr_pool *rds_ib_create_mr_pool(struct rds_ib_device *rds_ibdev)
@@ -573,8 +571,8 @@ void rds_ib_free_mr(void *trans_private, int invalidate)
573 spin_unlock_irqrestore(&pool->list_lock, flags); 571 spin_unlock_irqrestore(&pool->list_lock, flags);
574 572
575 /* If we've pinned too many pages, request a flush */ 573 /* If we've pinned too many pages, request a flush */
576 if (atomic_read(&pool->free_pinned) >= pool->max_free_pinned 574 if (atomic_read(&pool->free_pinned) >= pool->max_free_pinned ||
577 || atomic_read(&pool->dirty_count) >= pool->max_items / 10) 575 atomic_read(&pool->dirty_count) >= pool->max_items / 10)
578 queue_work(rds_wq, &pool->flush_worker); 576 queue_work(rds_wq, &pool->flush_worker);
579 577
580 if (invalidate) { 578 if (invalidate) {
diff --git a/net/rds/ib_recv.c b/net/rds/ib_recv.c
index cd7a6cfcab03..c7dd11b835f0 100644
--- a/net/rds/ib_recv.c
+++ b/net/rds/ib_recv.c
@@ -31,6 +31,7 @@
31 * 31 *
32 */ 32 */
33#include <linux/kernel.h> 33#include <linux/kernel.h>
34#include <linux/slab.h>
34#include <linux/pci.h> 35#include <linux/pci.h>
35#include <linux/dma-mapping.h> 36#include <linux/dma-mapping.h>
36#include <rdma/rdma_cm.h> 37#include <rdma/rdma_cm.h>
@@ -143,15 +144,16 @@ static int rds_ib_recv_refill_one(struct rds_connection *conn,
143 int ret = -ENOMEM; 144 int ret = -ENOMEM;
144 145
145 if (recv->r_ibinc == NULL) { 146 if (recv->r_ibinc == NULL) {
146 if (atomic_read(&rds_ib_allocation) >= rds_ib_sysctl_max_recv_allocation) { 147 if (!atomic_add_unless(&rds_ib_allocation, 1, rds_ib_sysctl_max_recv_allocation)) {
147 rds_ib_stats_inc(s_ib_rx_alloc_limit); 148 rds_ib_stats_inc(s_ib_rx_alloc_limit);
148 goto out; 149 goto out;
149 } 150 }
150 recv->r_ibinc = kmem_cache_alloc(rds_ib_incoming_slab, 151 recv->r_ibinc = kmem_cache_alloc(rds_ib_incoming_slab,
151 kptr_gfp); 152 kptr_gfp);
152 if (recv->r_ibinc == NULL) 153 if (recv->r_ibinc == NULL) {
154 atomic_dec(&rds_ib_allocation);
153 goto out; 155 goto out;
154 atomic_inc(&rds_ib_allocation); 156 }
155 INIT_LIST_HEAD(&recv->r_ibinc->ii_frags); 157 INIT_LIST_HEAD(&recv->r_ibinc->ii_frags);
156 rds_inc_init(&recv->r_ibinc->ii_inc, conn, conn->c_faddr); 158 rds_inc_init(&recv->r_ibinc->ii_inc, conn, conn->c_faddr);
157 } 159 }
@@ -229,8 +231,8 @@ int rds_ib_recv_refill(struct rds_connection *conn, gfp_t kptr_gfp,
229 int ret = 0; 231 int ret = 0;
230 u32 pos; 232 u32 pos;
231 233
232 while ((prefill || rds_conn_up(conn)) 234 while ((prefill || rds_conn_up(conn)) &&
233 && rds_ib_ring_alloc(&ic->i_recv_ring, 1, &pos)) { 235 rds_ib_ring_alloc(&ic->i_recv_ring, 1, &pos)) {
234 if (pos >= ic->i_recv_ring.w_nr) { 236 if (pos >= ic->i_recv_ring.w_nr) {
235 printk(KERN_NOTICE "Argh - ring alloc returned pos=%u\n", 237 printk(KERN_NOTICE "Argh - ring alloc returned pos=%u\n",
236 pos); 238 pos);
@@ -770,10 +772,10 @@ static void rds_ib_process_recv(struct rds_connection *conn,
770 hdr = &ibinc->ii_inc.i_hdr; 772 hdr = &ibinc->ii_inc.i_hdr;
771 /* We can't just use memcmp here; fragments of a 773 /* We can't just use memcmp here; fragments of a
772 * single message may carry different ACKs */ 774 * single message may carry different ACKs */
773 if (hdr->h_sequence != ihdr->h_sequence 775 if (hdr->h_sequence != ihdr->h_sequence ||
774 || hdr->h_len != ihdr->h_len 776 hdr->h_len != ihdr->h_len ||
775 || hdr->h_sport != ihdr->h_sport 777 hdr->h_sport != ihdr->h_sport ||
776 || hdr->h_dport != ihdr->h_dport) { 778 hdr->h_dport != ihdr->h_dport) {
777 rds_ib_conn_error(conn, 779 rds_ib_conn_error(conn,
778 "fragment header mismatch; forcing reconnect\n"); 780 "fragment header mismatch; forcing reconnect\n");
779 return; 781 return;
@@ -824,17 +826,22 @@ void rds_ib_recv_cq_comp_handler(struct ib_cq *cq, void *context)
824{ 826{
825 struct rds_connection *conn = context; 827 struct rds_connection *conn = context;
826 struct rds_ib_connection *ic = conn->c_transport_data; 828 struct rds_ib_connection *ic = conn->c_transport_data;
827 struct ib_wc wc;
828 struct rds_ib_ack_state state = { 0, };
829 struct rds_ib_recv_work *recv;
830 829
831 rdsdebug("conn %p cq %p\n", conn, cq); 830 rdsdebug("conn %p cq %p\n", conn, cq);
832 831
833 rds_ib_stats_inc(s_ib_rx_cq_call); 832 rds_ib_stats_inc(s_ib_rx_cq_call);
834 833
835 ib_req_notify_cq(cq, IB_CQ_SOLICITED); 834 tasklet_schedule(&ic->i_recv_tasklet);
835}
836
837static inline void rds_poll_cq(struct rds_ib_connection *ic,
838 struct rds_ib_ack_state *state)
839{
840 struct rds_connection *conn = ic->conn;
841 struct ib_wc wc;
842 struct rds_ib_recv_work *recv;
836 843
837 while (ib_poll_cq(cq, 1, &wc) > 0) { 844 while (ib_poll_cq(ic->i_recv_cq, 1, &wc) > 0) {
838 rdsdebug("wc wr_id 0x%llx status %u byte_len %u imm_data %u\n", 845 rdsdebug("wc wr_id 0x%llx status %u byte_len %u imm_data %u\n",
839 (unsigned long long)wc.wr_id, wc.status, wc.byte_len, 846 (unsigned long long)wc.wr_id, wc.status, wc.byte_len,
840 be32_to_cpu(wc.ex.imm_data)); 847 be32_to_cpu(wc.ex.imm_data));
@@ -852,7 +859,7 @@ void rds_ib_recv_cq_comp_handler(struct ib_cq *cq, void *context)
852 if (rds_conn_up(conn) || rds_conn_connecting(conn)) { 859 if (rds_conn_up(conn) || rds_conn_connecting(conn)) {
853 /* We expect errors as the qp is drained during shutdown */ 860 /* We expect errors as the qp is drained during shutdown */
854 if (wc.status == IB_WC_SUCCESS) { 861 if (wc.status == IB_WC_SUCCESS) {
855 rds_ib_process_recv(conn, recv, wc.byte_len, &state); 862 rds_ib_process_recv(conn, recv, wc.byte_len, state);
856 } else { 863 } else {
857 rds_ib_conn_error(conn, "recv completion on " 864 rds_ib_conn_error(conn, "recv completion on "
858 "%pI4 had status %u, disconnecting and " 865 "%pI4 had status %u, disconnecting and "
@@ -863,6 +870,17 @@ void rds_ib_recv_cq_comp_handler(struct ib_cq *cq, void *context)
863 870
864 rds_ib_ring_free(&ic->i_recv_ring, 1); 871 rds_ib_ring_free(&ic->i_recv_ring, 1);
865 } 872 }
873}
874
875void rds_ib_recv_tasklet_fn(unsigned long data)
876{
877 struct rds_ib_connection *ic = (struct rds_ib_connection *) data;
878 struct rds_connection *conn = ic->conn;
879 struct rds_ib_ack_state state = { 0, };
880
881 rds_poll_cq(ic, &state);
882 ib_req_notify_cq(ic->i_recv_cq, IB_CQ_SOLICITED);
883 rds_poll_cq(ic, &state);
866 884
867 if (state.ack_next_valid) 885 if (state.ack_next_valid)
868 rds_ib_set_ack(ic, state.ack_next, state.ack_required); 886 rds_ib_set_ack(ic, state.ack_next, state.ack_required);
diff --git a/net/rds/ib_send.c b/net/rds/ib_send.c
index 23bf830db2d5..a10fab6886d1 100644
--- a/net/rds/ib_send.c
+++ b/net/rds/ib_send.c
@@ -252,8 +252,8 @@ void rds_ib_send_cq_comp_handler(struct ib_cq *cq, void *context)
252 252
253 rds_ib_ring_free(&ic->i_send_ring, completed); 253 rds_ib_ring_free(&ic->i_send_ring, completed);
254 254
255 if (test_and_clear_bit(RDS_LL_SEND_FULL, &conn->c_flags) 255 if (test_and_clear_bit(RDS_LL_SEND_FULL, &conn->c_flags) ||
256 || test_bit(0, &conn->c_map_queued)) 256 test_bit(0, &conn->c_map_queued))
257 queue_delayed_work(rds_wq, &conn->c_send_w, 0); 257 queue_delayed_work(rds_wq, &conn->c_send_w, 0);
258 258
259 /* We expect errors as the qp is drained during shutdown */ 259 /* We expect errors as the qp is drained during shutdown */
diff --git a/net/rds/ib_sysctl.c b/net/rds/ib_sysctl.c
index 84b5ffcb280f..03f01cb4e0fe 100644
--- a/net/rds/ib_sysctl.c
+++ b/net/rds/ib_sysctl.c
@@ -67,68 +67,62 @@ unsigned int rds_ib_sysctl_flow_control = 0;
67 67
68ctl_table rds_ib_sysctl_table[] = { 68ctl_table rds_ib_sysctl_table[] = {
69 { 69 {
70 .ctl_name = CTL_UNNUMBERED,
71 .procname = "max_send_wr", 70 .procname = "max_send_wr",
72 .data = &rds_ib_sysctl_max_send_wr, 71 .data = &rds_ib_sysctl_max_send_wr,
73 .maxlen = sizeof(unsigned long), 72 .maxlen = sizeof(unsigned long),
74 .mode = 0644, 73 .mode = 0644,
75 .proc_handler = &proc_doulongvec_minmax, 74 .proc_handler = proc_doulongvec_minmax,
76 .extra1 = &rds_ib_sysctl_max_wr_min, 75 .extra1 = &rds_ib_sysctl_max_wr_min,
77 .extra2 = &rds_ib_sysctl_max_wr_max, 76 .extra2 = &rds_ib_sysctl_max_wr_max,
78 }, 77 },
79 { 78 {
80 .ctl_name = CTL_UNNUMBERED,
81 .procname = "max_recv_wr", 79 .procname = "max_recv_wr",
82 .data = &rds_ib_sysctl_max_recv_wr, 80 .data = &rds_ib_sysctl_max_recv_wr,
83 .maxlen = sizeof(unsigned long), 81 .maxlen = sizeof(unsigned long),
84 .mode = 0644, 82 .mode = 0644,
85 .proc_handler = &proc_doulongvec_minmax, 83 .proc_handler = proc_doulongvec_minmax,
86 .extra1 = &rds_ib_sysctl_max_wr_min, 84 .extra1 = &rds_ib_sysctl_max_wr_min,
87 .extra2 = &rds_ib_sysctl_max_wr_max, 85 .extra2 = &rds_ib_sysctl_max_wr_max,
88 }, 86 },
89 { 87 {
90 .ctl_name = CTL_UNNUMBERED,
91 .procname = "max_unsignaled_wr", 88 .procname = "max_unsignaled_wr",
92 .data = &rds_ib_sysctl_max_unsig_wrs, 89 .data = &rds_ib_sysctl_max_unsig_wrs,
93 .maxlen = sizeof(unsigned long), 90 .maxlen = sizeof(unsigned long),
94 .mode = 0644, 91 .mode = 0644,
95 .proc_handler = &proc_doulongvec_minmax, 92 .proc_handler = proc_doulongvec_minmax,
96 .extra1 = &rds_ib_sysctl_max_unsig_wr_min, 93 .extra1 = &rds_ib_sysctl_max_unsig_wr_min,
97 .extra2 = &rds_ib_sysctl_max_unsig_wr_max, 94 .extra2 = &rds_ib_sysctl_max_unsig_wr_max,
98 }, 95 },
99 { 96 {
100 .ctl_name = CTL_UNNUMBERED,
101 .procname = "max_unsignaled_bytes", 97 .procname = "max_unsignaled_bytes",
102 .data = &rds_ib_sysctl_max_unsig_bytes, 98 .data = &rds_ib_sysctl_max_unsig_bytes,
103 .maxlen = sizeof(unsigned long), 99 .maxlen = sizeof(unsigned long),
104 .mode = 0644, 100 .mode = 0644,
105 .proc_handler = &proc_doulongvec_minmax, 101 .proc_handler = proc_doulongvec_minmax,
106 .extra1 = &rds_ib_sysctl_max_unsig_bytes_min, 102 .extra1 = &rds_ib_sysctl_max_unsig_bytes_min,
107 .extra2 = &rds_ib_sysctl_max_unsig_bytes_max, 103 .extra2 = &rds_ib_sysctl_max_unsig_bytes_max,
108 }, 104 },
109 { 105 {
110 .ctl_name = CTL_UNNUMBERED,
111 .procname = "max_recv_allocation", 106 .procname = "max_recv_allocation",
112 .data = &rds_ib_sysctl_max_recv_allocation, 107 .data = &rds_ib_sysctl_max_recv_allocation,
113 .maxlen = sizeof(unsigned long), 108 .maxlen = sizeof(unsigned long),
114 .mode = 0644, 109 .mode = 0644,
115 .proc_handler = &proc_doulongvec_minmax, 110 .proc_handler = proc_doulongvec_minmax,
116 }, 111 },
117 { 112 {
118 .ctl_name = CTL_UNNUMBERED,
119 .procname = "flow_control", 113 .procname = "flow_control",
120 .data = &rds_ib_sysctl_flow_control, 114 .data = &rds_ib_sysctl_flow_control,
121 .maxlen = sizeof(rds_ib_sysctl_flow_control), 115 .maxlen = sizeof(rds_ib_sysctl_flow_control),
122 .mode = 0644, 116 .mode = 0644,
123 .proc_handler = &proc_dointvec, 117 .proc_handler = proc_dointvec,
124 }, 118 },
125 { .ctl_name = 0} 119 { }
126}; 120};
127 121
128static struct ctl_path rds_ib_sysctl_path[] = { 122static struct ctl_path rds_ib_sysctl_path[] = {
129 { .procname = "net", .ctl_name = CTL_NET, }, 123 { .procname = "net", },
130 { .procname = "rds", .ctl_name = CTL_UNNUMBERED, }, 124 { .procname = "rds", },
131 { .procname = "ib", .ctl_name = CTL_UNNUMBERED, }, 125 { .procname = "ib", },
132 { } 126 { }
133}; 127};
134 128
diff --git a/net/rds/info.c b/net/rds/info.c
index 814a91a6f4a7..c45c4173a44d 100644
--- a/net/rds/info.c
+++ b/net/rds/info.c
@@ -32,6 +32,7 @@
32 */ 32 */
33#include <linux/percpu.h> 33#include <linux/percpu.h>
34#include <linux/seq_file.h> 34#include <linux/seq_file.h>
35#include <linux/slab.h>
35#include <linux/proc_fs.h> 36#include <linux/proc_fs.h>
36 37
37#include "rds.h" 38#include "rds.h"
diff --git a/net/rds/iw.c b/net/rds/iw.c
index db224f7c2937..c8f3d3525cb9 100644
--- a/net/rds/iw.c
+++ b/net/rds/iw.c
@@ -37,6 +37,7 @@
37#include <linux/inetdevice.h> 37#include <linux/inetdevice.h>
38#include <linux/if_arp.h> 38#include <linux/if_arp.h>
39#include <linux/delay.h> 39#include <linux/delay.h>
40#include <linux/slab.h>
40 41
41#include "rds.h" 42#include "rds.h"
42#include "iw.h" 43#include "iw.h"
@@ -184,8 +185,8 @@ static int rds_iw_conn_info_visitor(struct rds_connection *conn,
184 ic = conn->c_transport_data; 185 ic = conn->c_transport_data;
185 dev_addr = &ic->i_cm_id->route.addr.dev_addr; 186 dev_addr = &ic->i_cm_id->route.addr.dev_addr;
186 187
187 ib_addr_get_sgid(dev_addr, (union ib_gid *) &iinfo->src_gid); 188 rdma_addr_get_sgid(dev_addr, (union ib_gid *) &iinfo->src_gid);
188 ib_addr_get_dgid(dev_addr, (union ib_gid *) &iinfo->dst_gid); 189 rdma_addr_get_dgid(dev_addr, (union ib_gid *) &iinfo->dst_gid);
189 190
190 rds_iwdev = ib_get_client_data(ic->i_cm_id->device, &rds_iw_client); 191 rds_iwdev = ib_get_client_data(ic->i_cm_id->device, &rds_iw_client);
191 iinfo->max_send_wr = ic->i_send_ring.w_nr; 192 iinfo->max_send_wr = ic->i_send_ring.w_nr;
diff --git a/net/rds/iw.h b/net/rds/iw.h
index dd72b62bd506..eef2f0c28476 100644
--- a/net/rds/iw.h
+++ b/net/rds/iw.h
@@ -119,6 +119,7 @@ struct rds_iw_connection {
119 struct rds_iw_send_work *i_sends; 119 struct rds_iw_send_work *i_sends;
120 120
121 /* rx */ 121 /* rx */
122 struct tasklet_struct i_recv_tasklet;
122 struct mutex i_recv_mutex; 123 struct mutex i_recv_mutex;
123 struct rds_iw_work_ring i_recv_ring; 124 struct rds_iw_work_ring i_recv_ring;
124 struct rds_iw_incoming *i_iwinc; 125 struct rds_iw_incoming *i_iwinc;
@@ -330,6 +331,7 @@ void rds_iw_inc_free(struct rds_incoming *inc);
330int rds_iw_inc_copy_to_user(struct rds_incoming *inc, struct iovec *iov, 331int rds_iw_inc_copy_to_user(struct rds_incoming *inc, struct iovec *iov,
331 size_t size); 332 size_t size);
332void rds_iw_recv_cq_comp_handler(struct ib_cq *cq, void *context); 333void rds_iw_recv_cq_comp_handler(struct ib_cq *cq, void *context);
334void rds_iw_recv_tasklet_fn(unsigned long data);
333void rds_iw_recv_init_ring(struct rds_iw_connection *ic); 335void rds_iw_recv_init_ring(struct rds_iw_connection *ic);
334void rds_iw_recv_clear_ring(struct rds_iw_connection *ic); 336void rds_iw_recv_clear_ring(struct rds_iw_connection *ic);
335void rds_iw_recv_init_ack(struct rds_iw_connection *ic); 337void rds_iw_recv_init_ack(struct rds_iw_connection *ic);
diff --git a/net/rds/iw_cm.c b/net/rds/iw_cm.c
index a416b0d492b1..3e9460f935d8 100644
--- a/net/rds/iw_cm.c
+++ b/net/rds/iw_cm.c
@@ -32,6 +32,7 @@
32 */ 32 */
33#include <linux/kernel.h> 33#include <linux/kernel.h>
34#include <linux/in.h> 34#include <linux/in.h>
35#include <linux/slab.h>
35#include <linux/vmalloc.h> 36#include <linux/vmalloc.h>
36 37
37#include "rds.h" 38#include "rds.h"
@@ -696,6 +697,8 @@ int rds_iw_conn_alloc(struct rds_connection *conn, gfp_t gfp)
696 return -ENOMEM; 697 return -ENOMEM;
697 698
698 INIT_LIST_HEAD(&ic->iw_node); 699 INIT_LIST_HEAD(&ic->iw_node);
700 tasklet_init(&ic->i_recv_tasklet, rds_iw_recv_tasklet_fn,
701 (unsigned long) ic);
699 mutex_init(&ic->i_recv_mutex); 702 mutex_init(&ic->i_recv_mutex);
700#ifndef KERNEL_HAS_ATOMIC64 703#ifndef KERNEL_HAS_ATOMIC64
701 spin_lock_init(&ic->i_ack_lock); 704 spin_lock_init(&ic->i_ack_lock);
diff --git a/net/rds/iw_rdma.c b/net/rds/iw_rdma.c
index de4a1b16bf7b..13dc1862d862 100644
--- a/net/rds/iw_rdma.c
+++ b/net/rds/iw_rdma.c
@@ -31,6 +31,7 @@
31 * 31 *
32 */ 32 */
33#include <linux/kernel.h> 33#include <linux/kernel.h>
34#include <linux/slab.h>
34 35
35#include "rds.h" 36#include "rds.h"
36#include "rdma.h" 37#include "rdma.h"
@@ -245,11 +246,8 @@ void __rds_iw_destroy_conns(struct list_head *list, spinlock_t *list_lock)
245 INIT_LIST_HEAD(list); 246 INIT_LIST_HEAD(list);
246 spin_unlock_irq(list_lock); 247 spin_unlock_irq(list_lock);
247 248
248 list_for_each_entry_safe(ic, _ic, &tmp_list, iw_node) { 249 list_for_each_entry_safe(ic, _ic, &tmp_list, iw_node)
249 if (ic->conn->c_passive)
250 rds_conn_destroy(ic->conn->c_passive);
251 rds_conn_destroy(ic->conn); 250 rds_conn_destroy(ic->conn);
252 }
253} 251}
254 252
255static void rds_iw_set_scatterlist(struct rds_iw_scatterlist *sg, 253static void rds_iw_set_scatterlist(struct rds_iw_scatterlist *sg,
@@ -576,8 +574,8 @@ void rds_iw_free_mr(void *trans_private, int invalidate)
576 rds_iw_free_fastreg(pool, ibmr); 574 rds_iw_free_fastreg(pool, ibmr);
577 575
578 /* If we've pinned too many pages, request a flush */ 576 /* If we've pinned too many pages, request a flush */
579 if (atomic_read(&pool->free_pinned) >= pool->max_free_pinned 577 if (atomic_read(&pool->free_pinned) >= pool->max_free_pinned ||
580 || atomic_read(&pool->dirty_count) >= pool->max_items / 10) 578 atomic_read(&pool->dirty_count) >= pool->max_items / 10)
581 queue_work(rds_wq, &pool->flush_worker); 579 queue_work(rds_wq, &pool->flush_worker);
582 580
583 if (invalidate) { 581 if (invalidate) {
diff --git a/net/rds/iw_recv.c b/net/rds/iw_recv.c
index 8683f5f66c4b..da43ee840ca3 100644
--- a/net/rds/iw_recv.c
+++ b/net/rds/iw_recv.c
@@ -31,6 +31,7 @@
31 * 31 *
32 */ 32 */
33#include <linux/kernel.h> 33#include <linux/kernel.h>
34#include <linux/slab.h>
34#include <linux/pci.h> 35#include <linux/pci.h>
35#include <linux/dma-mapping.h> 36#include <linux/dma-mapping.h>
36#include <rdma/rdma_cm.h> 37#include <rdma/rdma_cm.h>
@@ -143,15 +144,16 @@ static int rds_iw_recv_refill_one(struct rds_connection *conn,
143 int ret = -ENOMEM; 144 int ret = -ENOMEM;
144 145
145 if (recv->r_iwinc == NULL) { 146 if (recv->r_iwinc == NULL) {
146 if (atomic_read(&rds_iw_allocation) >= rds_iw_sysctl_max_recv_allocation) { 147 if (!atomic_add_unless(&rds_iw_allocation, 1, rds_iw_sysctl_max_recv_allocation)) {
147 rds_iw_stats_inc(s_iw_rx_alloc_limit); 148 rds_iw_stats_inc(s_iw_rx_alloc_limit);
148 goto out; 149 goto out;
149 } 150 }
150 recv->r_iwinc = kmem_cache_alloc(rds_iw_incoming_slab, 151 recv->r_iwinc = kmem_cache_alloc(rds_iw_incoming_slab,
151 kptr_gfp); 152 kptr_gfp);
152 if (recv->r_iwinc == NULL) 153 if (recv->r_iwinc == NULL) {
154 atomic_dec(&rds_iw_allocation);
153 goto out; 155 goto out;
154 atomic_inc(&rds_iw_allocation); 156 }
155 INIT_LIST_HEAD(&recv->r_iwinc->ii_frags); 157 INIT_LIST_HEAD(&recv->r_iwinc->ii_frags);
156 rds_inc_init(&recv->r_iwinc->ii_inc, conn, conn->c_faddr); 158 rds_inc_init(&recv->r_iwinc->ii_inc, conn, conn->c_faddr);
157 } 159 }
@@ -229,8 +231,8 @@ int rds_iw_recv_refill(struct rds_connection *conn, gfp_t kptr_gfp,
229 int ret = 0; 231 int ret = 0;
230 u32 pos; 232 u32 pos;
231 233
232 while ((prefill || rds_conn_up(conn)) 234 while ((prefill || rds_conn_up(conn)) &&
233 && rds_iw_ring_alloc(&ic->i_recv_ring, 1, &pos)) { 235 rds_iw_ring_alloc(&ic->i_recv_ring, 1, &pos)) {
234 if (pos >= ic->i_recv_ring.w_nr) { 236 if (pos >= ic->i_recv_ring.w_nr) {
235 printk(KERN_NOTICE "Argh - ring alloc returned pos=%u\n", 237 printk(KERN_NOTICE "Argh - ring alloc returned pos=%u\n",
236 pos); 238 pos);
@@ -729,10 +731,10 @@ static void rds_iw_process_recv(struct rds_connection *conn,
729 hdr = &iwinc->ii_inc.i_hdr; 731 hdr = &iwinc->ii_inc.i_hdr;
730 /* We can't just use memcmp here; fragments of a 732 /* We can't just use memcmp here; fragments of a
731 * single message may carry different ACKs */ 733 * single message may carry different ACKs */
732 if (hdr->h_sequence != ihdr->h_sequence 734 if (hdr->h_sequence != ihdr->h_sequence ||
733 || hdr->h_len != ihdr->h_len 735 hdr->h_len != ihdr->h_len ||
734 || hdr->h_sport != ihdr->h_sport 736 hdr->h_sport != ihdr->h_sport ||
735 || hdr->h_dport != ihdr->h_dport) { 737 hdr->h_dport != ihdr->h_dport) {
736 rds_iw_conn_error(conn, 738 rds_iw_conn_error(conn,
737 "fragment header mismatch; forcing reconnect\n"); 739 "fragment header mismatch; forcing reconnect\n");
738 return; 740 return;
@@ -783,17 +785,22 @@ void rds_iw_recv_cq_comp_handler(struct ib_cq *cq, void *context)
783{ 785{
784 struct rds_connection *conn = context; 786 struct rds_connection *conn = context;
785 struct rds_iw_connection *ic = conn->c_transport_data; 787 struct rds_iw_connection *ic = conn->c_transport_data;
786 struct ib_wc wc;
787 struct rds_iw_ack_state state = { 0, };
788 struct rds_iw_recv_work *recv;
789 788
790 rdsdebug("conn %p cq %p\n", conn, cq); 789 rdsdebug("conn %p cq %p\n", conn, cq);
791 790
792 rds_iw_stats_inc(s_iw_rx_cq_call); 791 rds_iw_stats_inc(s_iw_rx_cq_call);
793 792
794 ib_req_notify_cq(cq, IB_CQ_SOLICITED); 793 tasklet_schedule(&ic->i_recv_tasklet);
794}
795
796static inline void rds_poll_cq(struct rds_iw_connection *ic,
797 struct rds_iw_ack_state *state)
798{
799 struct rds_connection *conn = ic->conn;
800 struct ib_wc wc;
801 struct rds_iw_recv_work *recv;
795 802
796 while (ib_poll_cq(cq, 1, &wc) > 0) { 803 while (ib_poll_cq(ic->i_recv_cq, 1, &wc) > 0) {
797 rdsdebug("wc wr_id 0x%llx status %u byte_len %u imm_data %u\n", 804 rdsdebug("wc wr_id 0x%llx status %u byte_len %u imm_data %u\n",
798 (unsigned long long)wc.wr_id, wc.status, wc.byte_len, 805 (unsigned long long)wc.wr_id, wc.status, wc.byte_len,
799 be32_to_cpu(wc.ex.imm_data)); 806 be32_to_cpu(wc.ex.imm_data));
@@ -811,7 +818,7 @@ void rds_iw_recv_cq_comp_handler(struct ib_cq *cq, void *context)
811 if (rds_conn_up(conn) || rds_conn_connecting(conn)) { 818 if (rds_conn_up(conn) || rds_conn_connecting(conn)) {
812 /* We expect errors as the qp is drained during shutdown */ 819 /* We expect errors as the qp is drained during shutdown */
813 if (wc.status == IB_WC_SUCCESS) { 820 if (wc.status == IB_WC_SUCCESS) {
814 rds_iw_process_recv(conn, recv, wc.byte_len, &state); 821 rds_iw_process_recv(conn, recv, wc.byte_len, state);
815 } else { 822 } else {
816 rds_iw_conn_error(conn, "recv completion on " 823 rds_iw_conn_error(conn, "recv completion on "
817 "%pI4 had status %u, disconnecting and " 824 "%pI4 had status %u, disconnecting and "
@@ -822,6 +829,17 @@ void rds_iw_recv_cq_comp_handler(struct ib_cq *cq, void *context)
822 829
823 rds_iw_ring_free(&ic->i_recv_ring, 1); 830 rds_iw_ring_free(&ic->i_recv_ring, 1);
824 } 831 }
832}
833
834void rds_iw_recv_tasklet_fn(unsigned long data)
835{
836 struct rds_iw_connection *ic = (struct rds_iw_connection *) data;
837 struct rds_connection *conn = ic->conn;
838 struct rds_iw_ack_state state = { 0, };
839
840 rds_poll_cq(ic, &state);
841 ib_req_notify_cq(ic->i_recv_cq, IB_CQ_SOLICITED);
842 rds_poll_cq(ic, &state);
825 843
826 if (state.ack_next_valid) 844 if (state.ack_next_valid)
827 rds_iw_set_ack(ic, state.ack_next, state.ack_required); 845 rds_iw_set_ack(ic, state.ack_next, state.ack_required);
diff --git a/net/rds/iw_send.c b/net/rds/iw_send.c
index 1f5abe3cf2b4..1379e9d66a78 100644
--- a/net/rds/iw_send.c
+++ b/net/rds/iw_send.c
@@ -288,8 +288,8 @@ void rds_iw_send_cq_comp_handler(struct ib_cq *cq, void *context)
288 288
289 rds_iw_ring_free(&ic->i_send_ring, completed); 289 rds_iw_ring_free(&ic->i_send_ring, completed);
290 290
291 if (test_and_clear_bit(RDS_LL_SEND_FULL, &conn->c_flags) 291 if (test_and_clear_bit(RDS_LL_SEND_FULL, &conn->c_flags) ||
292 || test_bit(0, &conn->c_map_queued)) 292 test_bit(0, &conn->c_map_queued))
293 queue_delayed_work(rds_wq, &conn->c_send_w, 0); 293 queue_delayed_work(rds_wq, &conn->c_send_w, 0);
294 294
295 /* We expect errors as the qp is drained during shutdown */ 295 /* We expect errors as the qp is drained during shutdown */
@@ -519,8 +519,7 @@ int rds_iw_xmit(struct rds_connection *conn, struct rds_message *rm,
519 BUG_ON(hdr_off != 0 && hdr_off != sizeof(struct rds_header)); 519 BUG_ON(hdr_off != 0 && hdr_off != sizeof(struct rds_header));
520 520
521 /* Fastreg support */ 521 /* Fastreg support */
522 if (rds_rdma_cookie_key(rm->m_rdma_cookie) 522 if (rds_rdma_cookie_key(rm->m_rdma_cookie) && !ic->i_fastreg_posted) {
523 && !ic->i_fastreg_posted) {
524 ret = -EAGAIN; 523 ret = -EAGAIN;
525 goto out; 524 goto out;
526 } 525 }
diff --git a/net/rds/iw_sysctl.c b/net/rds/iw_sysctl.c
index 9590678cd616..1c4428a61a02 100644
--- a/net/rds/iw_sysctl.c
+++ b/net/rds/iw_sysctl.c
@@ -57,68 +57,62 @@ unsigned int rds_iw_sysctl_flow_control = 1;
57 57
58ctl_table rds_iw_sysctl_table[] = { 58ctl_table rds_iw_sysctl_table[] = {
59 { 59 {
60 .ctl_name = CTL_UNNUMBERED,
61 .procname = "max_send_wr", 60 .procname = "max_send_wr",
62 .data = &rds_iw_sysctl_max_send_wr, 61 .data = &rds_iw_sysctl_max_send_wr,
63 .maxlen = sizeof(unsigned long), 62 .maxlen = sizeof(unsigned long),
64 .mode = 0644, 63 .mode = 0644,
65 .proc_handler = &proc_doulongvec_minmax, 64 .proc_handler = proc_doulongvec_minmax,
66 .extra1 = &rds_iw_sysctl_max_wr_min, 65 .extra1 = &rds_iw_sysctl_max_wr_min,
67 .extra2 = &rds_iw_sysctl_max_wr_max, 66 .extra2 = &rds_iw_sysctl_max_wr_max,
68 }, 67 },
69 { 68 {
70 .ctl_name = CTL_UNNUMBERED,
71 .procname = "max_recv_wr", 69 .procname = "max_recv_wr",
72 .data = &rds_iw_sysctl_max_recv_wr, 70 .data = &rds_iw_sysctl_max_recv_wr,
73 .maxlen = sizeof(unsigned long), 71 .maxlen = sizeof(unsigned long),
74 .mode = 0644, 72 .mode = 0644,
75 .proc_handler = &proc_doulongvec_minmax, 73 .proc_handler = proc_doulongvec_minmax,
76 .extra1 = &rds_iw_sysctl_max_wr_min, 74 .extra1 = &rds_iw_sysctl_max_wr_min,
77 .extra2 = &rds_iw_sysctl_max_wr_max, 75 .extra2 = &rds_iw_sysctl_max_wr_max,
78 }, 76 },
79 { 77 {
80 .ctl_name = CTL_UNNUMBERED,
81 .procname = "max_unsignaled_wr", 78 .procname = "max_unsignaled_wr",
82 .data = &rds_iw_sysctl_max_unsig_wrs, 79 .data = &rds_iw_sysctl_max_unsig_wrs,
83 .maxlen = sizeof(unsigned long), 80 .maxlen = sizeof(unsigned long),
84 .mode = 0644, 81 .mode = 0644,
85 .proc_handler = &proc_doulongvec_minmax, 82 .proc_handler = proc_doulongvec_minmax,
86 .extra1 = &rds_iw_sysctl_max_unsig_wr_min, 83 .extra1 = &rds_iw_sysctl_max_unsig_wr_min,
87 .extra2 = &rds_iw_sysctl_max_unsig_wr_max, 84 .extra2 = &rds_iw_sysctl_max_unsig_wr_max,
88 }, 85 },
89 { 86 {
90 .ctl_name = CTL_UNNUMBERED,
91 .procname = "max_unsignaled_bytes", 87 .procname = "max_unsignaled_bytes",
92 .data = &rds_iw_sysctl_max_unsig_bytes, 88 .data = &rds_iw_sysctl_max_unsig_bytes,
93 .maxlen = sizeof(unsigned long), 89 .maxlen = sizeof(unsigned long),
94 .mode = 0644, 90 .mode = 0644,
95 .proc_handler = &proc_doulongvec_minmax, 91 .proc_handler = proc_doulongvec_minmax,
96 .extra1 = &rds_iw_sysctl_max_unsig_bytes_min, 92 .extra1 = &rds_iw_sysctl_max_unsig_bytes_min,
97 .extra2 = &rds_iw_sysctl_max_unsig_bytes_max, 93 .extra2 = &rds_iw_sysctl_max_unsig_bytes_max,
98 }, 94 },
99 { 95 {
100 .ctl_name = CTL_UNNUMBERED,
101 .procname = "max_recv_allocation", 96 .procname = "max_recv_allocation",
102 .data = &rds_iw_sysctl_max_recv_allocation, 97 .data = &rds_iw_sysctl_max_recv_allocation,
103 .maxlen = sizeof(unsigned long), 98 .maxlen = sizeof(unsigned long),
104 .mode = 0644, 99 .mode = 0644,
105 .proc_handler = &proc_doulongvec_minmax, 100 .proc_handler = proc_doulongvec_minmax,
106 }, 101 },
107 { 102 {
108 .ctl_name = CTL_UNNUMBERED,
109 .procname = "flow_control", 103 .procname = "flow_control",
110 .data = &rds_iw_sysctl_flow_control, 104 .data = &rds_iw_sysctl_flow_control,
111 .maxlen = sizeof(rds_iw_sysctl_flow_control), 105 .maxlen = sizeof(rds_iw_sysctl_flow_control),
112 .mode = 0644, 106 .mode = 0644,
113 .proc_handler = &proc_dointvec, 107 .proc_handler = proc_dointvec,
114 }, 108 },
115 { .ctl_name = 0} 109 { }
116}; 110};
117 111
118static struct ctl_path rds_iw_sysctl_path[] = { 112static struct ctl_path rds_iw_sysctl_path[] = {
119 { .procname = "net", .ctl_name = CTL_NET, }, 113 { .procname = "net", },
120 { .procname = "rds", .ctl_name = CTL_UNNUMBERED, }, 114 { .procname = "rds", },
121 { .procname = "iw", .ctl_name = CTL_UNNUMBERED, }, 115 { .procname = "iw", },
122 { } 116 { }
123}; 117};
124 118
diff --git a/net/rds/loop.c b/net/rds/loop.c
index 4a61997f554d..0d7a159158b8 100644
--- a/net/rds/loop.c
+++ b/net/rds/loop.c
@@ -31,6 +31,7 @@
31 * 31 *
32 */ 32 */
33#include <linux/kernel.h> 33#include <linux/kernel.h>
34#include <linux/slab.h>
34#include <linux/in.h> 35#include <linux/in.h>
35 36
36#include "rds.h" 37#include "rds.h"
diff --git a/net/rds/message.c b/net/rds/message.c
index ca50a8ec9742..9a1d67e001ba 100644
--- a/net/rds/message.c
+++ b/net/rds/message.c
@@ -31,6 +31,7 @@
31 * 31 *
32 */ 32 */
33#include <linux/kernel.h> 33#include <linux/kernel.h>
34#include <linux/slab.h>
34 35
35#include "rds.h" 36#include "rds.h"
36#include "rdma.h" 37#include "rdma.h"
@@ -122,8 +123,7 @@ int rds_message_add_extension(struct rds_header *hdr,
122 if (hdr->h_exthdr[0] != RDS_EXTHDR_NONE) 123 if (hdr->h_exthdr[0] != RDS_EXTHDR_NONE)
123 return 0; 124 return 0;
124 125
125 if (type >= __RDS_EXTHDR_MAX 126 if (type >= __RDS_EXTHDR_MAX || len != rds_exthdr_size[type])
126 || len != rds_exthdr_size[type])
127 return 0; 127 return 0;
128 128
129 if (ext_len >= RDS_HEADER_EXT_SPACE) 129 if (ext_len >= RDS_HEADER_EXT_SPACE)
diff --git a/net/rds/page.c b/net/rds/page.c
index 36790122dfd4..595a952d4b17 100644
--- a/net/rds/page.c
+++ b/net/rds/page.c
@@ -31,6 +31,7 @@
31 * 31 *
32 */ 32 */
33#include <linux/highmem.h> 33#include <linux/highmem.h>
34#include <linux/gfp.h>
34 35
35#include "rds.h" 36#include "rds.h"
36 37
diff --git a/net/rds/rdma.c b/net/rds/rdma.c
index 8dc83d2caa58..5ce9437cad67 100644
--- a/net/rds/rdma.c
+++ b/net/rds/rdma.c
@@ -31,6 +31,7 @@
31 * 31 *
32 */ 32 */
33#include <linux/pagemap.h> 33#include <linux/pagemap.h>
34#include <linux/slab.h>
34#include <linux/rbtree.h> 35#include <linux/rbtree.h>
35#include <linux/dma-mapping.h> /* for DMA_*_DEVICE */ 36#include <linux/dma-mapping.h> /* for DMA_*_DEVICE */
36 37
@@ -317,6 +318,30 @@ int rds_get_mr(struct rds_sock *rs, char __user *optval, int optlen)
317 return __rds_rdma_map(rs, &args, NULL, NULL); 318 return __rds_rdma_map(rs, &args, NULL, NULL);
318} 319}
319 320
321int rds_get_mr_for_dest(struct rds_sock *rs, char __user *optval, int optlen)
322{
323 struct rds_get_mr_for_dest_args args;
324 struct rds_get_mr_args new_args;
325
326 if (optlen != sizeof(struct rds_get_mr_for_dest_args))
327 return -EINVAL;
328
329 if (copy_from_user(&args, (struct rds_get_mr_for_dest_args __user *)optval,
330 sizeof(struct rds_get_mr_for_dest_args)))
331 return -EFAULT;
332
333 /*
334 * Initially, just behave like get_mr().
335 * TODO: Implement get_mr as wrapper around this
336 * and deprecate it.
337 */
338 new_args.vec = args.vec;
339 new_args.cookie_addr = args.cookie_addr;
340 new_args.flags = args.flags;
341
342 return __rds_rdma_map(rs, &new_args, NULL, NULL);
343}
344
320/* 345/*
321 * Free the MR indicated by the given R_Key 346 * Free the MR indicated by the given R_Key
322 */ 347 */
@@ -607,8 +632,8 @@ int rds_cmsg_rdma_args(struct rds_sock *rs, struct rds_message *rm,
607{ 632{
608 struct rds_rdma_op *op; 633 struct rds_rdma_op *op;
609 634
610 if (cmsg->cmsg_len < CMSG_LEN(sizeof(struct rds_rdma_args)) 635 if (cmsg->cmsg_len < CMSG_LEN(sizeof(struct rds_rdma_args)) ||
611 || rm->m_rdma_op != NULL) 636 rm->m_rdma_op != NULL)
612 return -EINVAL; 637 return -EINVAL;
613 638
614 op = rds_rdma_prepare(rs, CMSG_DATA(cmsg)); 639 op = rds_rdma_prepare(rs, CMSG_DATA(cmsg));
@@ -631,8 +656,8 @@ int rds_cmsg_rdma_dest(struct rds_sock *rs, struct rds_message *rm,
631 u32 r_key; 656 u32 r_key;
632 int err = 0; 657 int err = 0;
633 658
634 if (cmsg->cmsg_len < CMSG_LEN(sizeof(rds_rdma_cookie_t)) 659 if (cmsg->cmsg_len < CMSG_LEN(sizeof(rds_rdma_cookie_t)) ||
635 || rm->m_rdma_cookie != 0) 660 rm->m_rdma_cookie != 0)
636 return -EINVAL; 661 return -EINVAL;
637 662
638 memcpy(&rm->m_rdma_cookie, CMSG_DATA(cmsg), sizeof(rm->m_rdma_cookie)); 663 memcpy(&rm->m_rdma_cookie, CMSG_DATA(cmsg), sizeof(rm->m_rdma_cookie));
@@ -668,8 +693,8 @@ int rds_cmsg_rdma_dest(struct rds_sock *rs, struct rds_message *rm,
668int rds_cmsg_rdma_map(struct rds_sock *rs, struct rds_message *rm, 693int rds_cmsg_rdma_map(struct rds_sock *rs, struct rds_message *rm,
669 struct cmsghdr *cmsg) 694 struct cmsghdr *cmsg)
670{ 695{
671 if (cmsg->cmsg_len < CMSG_LEN(sizeof(struct rds_get_mr_args)) 696 if (cmsg->cmsg_len < CMSG_LEN(sizeof(struct rds_get_mr_args)) ||
672 || rm->m_rdma_cookie != 0) 697 rm->m_rdma_cookie != 0)
673 return -EINVAL; 698 return -EINVAL;
674 699
675 return __rds_rdma_map(rs, CMSG_DATA(cmsg), &rm->m_rdma_cookie, &rm->m_rdma_mr); 700 return __rds_rdma_map(rs, CMSG_DATA(cmsg), &rm->m_rdma_cookie, &rm->m_rdma_mr);
diff --git a/net/rds/rdma.h b/net/rds/rdma.h
index 425512098b0b..909c39835a5d 100644
--- a/net/rds/rdma.h
+++ b/net/rds/rdma.h
@@ -61,6 +61,7 @@ static inline u32 rds_rdma_cookie_offset(rds_rdma_cookie_t cookie)
61} 61}
62 62
63int rds_get_mr(struct rds_sock *rs, char __user *optval, int optlen); 63int rds_get_mr(struct rds_sock *rs, char __user *optval, int optlen);
64int rds_get_mr_for_dest(struct rds_sock *rs, char __user *optval, int optlen);
64int rds_free_mr(struct rds_sock *rs, char __user *optval, int optlen); 65int rds_free_mr(struct rds_sock *rs, char __user *optval, int optlen);
65void rds_rdma_drop_keys(struct rds_sock *rs); 66void rds_rdma_drop_keys(struct rds_sock *rs);
66int rds_cmsg_rdma_args(struct rds_sock *rs, struct rds_message *rm, 67int rds_cmsg_rdma_args(struct rds_sock *rs, struct rds_message *rm,
diff --git a/net/rds/rdma_transport.c b/net/rds/rdma_transport.c
index 9ece910ea394..7b155081b4dc 100644
--- a/net/rds/rdma_transport.c
+++ b/net/rds/rdma_transport.c
@@ -134,7 +134,7 @@ static int __init rds_rdma_listen_init(void)
134 ret = PTR_ERR(cm_id); 134 ret = PTR_ERR(cm_id);
135 printk(KERN_ERR "RDS/RDMA: failed to setup listener, " 135 printk(KERN_ERR "RDS/RDMA: failed to setup listener, "
136 "rdma_create_id() returned %d\n", ret); 136 "rdma_create_id() returned %d\n", ret);
137 goto out; 137 return ret;
138 } 138 }
139 139
140 sin.sin_family = AF_INET, 140 sin.sin_family = AF_INET,
diff --git a/net/rds/recv.c b/net/rds/recv.c
index fdff33c7b432..e2a2b9344f7b 100644
--- a/net/rds/recv.c
+++ b/net/rds/recv.c
@@ -31,6 +31,7 @@
31 * 31 *
32 */ 32 */
33#include <linux/kernel.h> 33#include <linux/kernel.h>
34#include <linux/slab.h>
34#include <net/sock.h> 35#include <net/sock.h>
35#include <linux/in.h> 36#include <linux/in.h>
36 37
@@ -195,8 +196,8 @@ void rds_recv_incoming(struct rds_connection *conn, __be32 saddr, __be32 daddr,
195 * XXX we could spend more on the wire to get more robust failure 196 * XXX we could spend more on the wire to get more robust failure
196 * detection, arguably worth it to avoid data corruption. 197 * detection, arguably worth it to avoid data corruption.
197 */ 198 */
198 if (be64_to_cpu(inc->i_hdr.h_sequence) < conn->c_next_rx_seq 199 if (be64_to_cpu(inc->i_hdr.h_sequence) < conn->c_next_rx_seq &&
199 && (inc->i_hdr.h_flags & RDS_FLAG_RETRANSMITTED)) { 200 (inc->i_hdr.h_flags & RDS_FLAG_RETRANSMITTED)) {
200 rds_stats_inc(s_recv_drop_old_seq); 201 rds_stats_inc(s_recv_drop_old_seq);
201 goto out; 202 goto out;
202 } 203 }
@@ -432,10 +433,9 @@ int rds_recvmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *msg,
432 } 433 }
433 434
434 timeo = wait_event_interruptible_timeout(*sk->sk_sleep, 435 timeo = wait_event_interruptible_timeout(*sk->sk_sleep,
435 (!list_empty(&rs->rs_notify_queue) 436 (!list_empty(&rs->rs_notify_queue) ||
436 || rs->rs_cong_notify 437 rs->rs_cong_notify ||
437 || rds_next_incoming(rs, &inc)), 438 rds_next_incoming(rs, &inc)), timeo);
438 timeo);
439 rdsdebug("recvmsg woke inc %p timeo %ld\n", inc, 439 rdsdebug("recvmsg woke inc %p timeo %ld\n", inc,
440 timeo); 440 timeo);
441 if (timeo > 0 || timeo == MAX_SCHEDULE_TIMEOUT) 441 if (timeo > 0 || timeo == MAX_SCHEDULE_TIMEOUT)
diff --git a/net/rds/send.c b/net/rds/send.c
index 28c88ff3d038..f04b929ded92 100644
--- a/net/rds/send.c
+++ b/net/rds/send.c
@@ -31,6 +31,7 @@
31 * 31 *
32 */ 32 */
33#include <linux/kernel.h> 33#include <linux/kernel.h>
34#include <linux/gfp.h>
34#include <net/sock.h> 35#include <net/sock.h>
35#include <linux/in.h> 36#include <linux/in.h>
36#include <linux/list.h> 37#include <linux/list.h>
@@ -235,8 +236,8 @@ int rds_send_xmit(struct rds_connection *conn)
235 * connection. 236 * connection.
236 * Therefore, we never retransmit messages with RDMA ops. 237 * Therefore, we never retransmit messages with RDMA ops.
237 */ 238 */
238 if (rm->m_rdma_op 239 if (rm->m_rdma_op &&
239 && test_bit(RDS_MSG_RETRANSMITTED, &rm->m_flags)) { 240 test_bit(RDS_MSG_RETRANSMITTED, &rm->m_flags)) {
240 spin_lock_irqsave(&conn->c_lock, flags); 241 spin_lock_irqsave(&conn->c_lock, flags);
241 if (test_and_clear_bit(RDS_MSG_ON_CONN, &rm->m_flags)) 242 if (test_and_clear_bit(RDS_MSG_ON_CONN, &rm->m_flags))
242 list_move(&rm->m_conn_item, &to_be_dropped); 243 list_move(&rm->m_conn_item, &to_be_dropped);
@@ -247,8 +248,8 @@ int rds_send_xmit(struct rds_connection *conn)
247 248
248 /* Require an ACK every once in a while */ 249 /* Require an ACK every once in a while */
249 len = ntohl(rm->m_inc.i_hdr.h_len); 250 len = ntohl(rm->m_inc.i_hdr.h_len);
250 if (conn->c_unacked_packets == 0 251 if (conn->c_unacked_packets == 0 ||
251 || conn->c_unacked_bytes < len) { 252 conn->c_unacked_bytes < len) {
252 __set_bit(RDS_MSG_ACK_REQUIRED, &rm->m_flags); 253 __set_bit(RDS_MSG_ACK_REQUIRED, &rm->m_flags);
253 254
254 conn->c_unacked_packets = rds_sysctl_max_unacked_packets; 255 conn->c_unacked_packets = rds_sysctl_max_unacked_packets;
@@ -418,8 +419,8 @@ void rds_rdma_send_complete(struct rds_message *rm, int status)
418 spin_lock(&rm->m_rs_lock); 419 spin_lock(&rm->m_rs_lock);
419 420
420 ro = rm->m_rdma_op; 421 ro = rm->m_rdma_op;
421 if (test_bit(RDS_MSG_ON_SOCK, &rm->m_flags) 422 if (test_bit(RDS_MSG_ON_SOCK, &rm->m_flags) &&
422 && ro && ro->r_notify && ro->r_notifier) { 423 ro && ro->r_notify && ro->r_notifier) {
423 notifier = ro->r_notifier; 424 notifier = ro->r_notifier;
424 rs = rm->m_rs; 425 rs = rm->m_rs;
425 sock_hold(rds_rs_to_sk(rs)); 426 sock_hold(rds_rs_to_sk(rs));
@@ -549,8 +550,7 @@ void rds_send_remove_from_sock(struct list_head *messages, int status)
549 list_del_init(&rm->m_sock_item); 550 list_del_init(&rm->m_sock_item);
550 rds_send_sndbuf_remove(rs, rm); 551 rds_send_sndbuf_remove(rs, rm);
551 552
552 if (ro && ro->r_notifier 553 if (ro && ro->r_notifier && (status || ro->r_notify)) {
553 && (status || ro->r_notify)) {
554 notifier = ro->r_notifier; 554 notifier = ro->r_notifier;
555 list_add_tail(&notifier->n_list, 555 list_add_tail(&notifier->n_list,
556 &rs->rs_notify_queue); 556 &rs->rs_notify_queue);
@@ -877,8 +877,8 @@ int rds_sendmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *msg,
877 if (ret) 877 if (ret)
878 goto out; 878 goto out;
879 879
880 if ((rm->m_rdma_cookie || rm->m_rdma_op) 880 if ((rm->m_rdma_cookie || rm->m_rdma_op) &&
881 && conn->c_trans->xmit_rdma == NULL) { 881 conn->c_trans->xmit_rdma == NULL) {
882 if (printk_ratelimit()) 882 if (printk_ratelimit())
883 printk(KERN_NOTICE "rdma_op %p conn xmit_rdma %p\n", 883 printk(KERN_NOTICE "rdma_op %p conn xmit_rdma %p\n",
884 rm->m_rdma_op, conn->c_trans->xmit_rdma); 884 rm->m_rdma_op, conn->c_trans->xmit_rdma);
@@ -890,8 +890,8 @@ int rds_sendmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *msg,
890 * have scheduled a delayed reconnect however - in this case 890 * have scheduled a delayed reconnect however - in this case
891 * we should not interfere. 891 * we should not interfere.
892 */ 892 */
893 if (rds_conn_state(conn) == RDS_CONN_DOWN 893 if (rds_conn_state(conn) == RDS_CONN_DOWN &&
894 && !test_and_set_bit(RDS_RECONNECT_PENDING, &conn->c_flags)) 894 !test_and_set_bit(RDS_RECONNECT_PENDING, &conn->c_flags))
895 queue_delayed_work(rds_wq, &conn->c_conn_w, 0); 895 queue_delayed_work(rds_wq, &conn->c_conn_w, 0);
896 896
897 ret = rds_cong_wait(conn->c_fcong, dport, nonblock, rs); 897 ret = rds_cong_wait(conn->c_fcong, dport, nonblock, rs);
@@ -973,8 +973,8 @@ rds_send_pong(struct rds_connection *conn, __be16 dport)
973 * have scheduled a delayed reconnect however - in this case 973 * have scheduled a delayed reconnect however - in this case
974 * we should not interfere. 974 * we should not interfere.
975 */ 975 */
976 if (rds_conn_state(conn) == RDS_CONN_DOWN 976 if (rds_conn_state(conn) == RDS_CONN_DOWN &&
977 && !test_and_set_bit(RDS_RECONNECT_PENDING, &conn->c_flags)) 977 !test_and_set_bit(RDS_RECONNECT_PENDING, &conn->c_flags))
978 queue_delayed_work(rds_wq, &conn->c_conn_w, 0); 978 queue_delayed_work(rds_wq, &conn->c_conn_w, 0);
979 979
980 ret = rds_cong_wait(conn->c_fcong, dport, 1, NULL); 980 ret = rds_cong_wait(conn->c_fcong, dport, 1, NULL);
diff --git a/net/rds/sysctl.c b/net/rds/sysctl.c
index 307dc5c1be15..7829a20325d3 100644
--- a/net/rds/sysctl.c
+++ b/net/rds/sysctl.c
@@ -51,55 +51,50 @@ unsigned int rds_sysctl_ping_enable = 1;
51 51
52static ctl_table rds_sysctl_rds_table[] = { 52static ctl_table rds_sysctl_rds_table[] = {
53 { 53 {
54 .ctl_name = CTL_UNNUMBERED,
55 .procname = "reconnect_min_delay_ms", 54 .procname = "reconnect_min_delay_ms",
56 .data = &rds_sysctl_reconnect_min_jiffies, 55 .data = &rds_sysctl_reconnect_min_jiffies,
57 .maxlen = sizeof(unsigned long), 56 .maxlen = sizeof(unsigned long),
58 .mode = 0644, 57 .mode = 0644,
59 .proc_handler = &proc_doulongvec_ms_jiffies_minmax, 58 .proc_handler = proc_doulongvec_ms_jiffies_minmax,
60 .extra1 = &rds_sysctl_reconnect_min, 59 .extra1 = &rds_sysctl_reconnect_min,
61 .extra2 = &rds_sysctl_reconnect_max_jiffies, 60 .extra2 = &rds_sysctl_reconnect_max_jiffies,
62 }, 61 },
63 { 62 {
64 .ctl_name = CTL_UNNUMBERED,
65 .procname = "reconnect_max_delay_ms", 63 .procname = "reconnect_max_delay_ms",
66 .data = &rds_sysctl_reconnect_max_jiffies, 64 .data = &rds_sysctl_reconnect_max_jiffies,
67 .maxlen = sizeof(unsigned long), 65 .maxlen = sizeof(unsigned long),
68 .mode = 0644, 66 .mode = 0644,
69 .proc_handler = &proc_doulongvec_ms_jiffies_minmax, 67 .proc_handler = proc_doulongvec_ms_jiffies_minmax,
70 .extra1 = &rds_sysctl_reconnect_min_jiffies, 68 .extra1 = &rds_sysctl_reconnect_min_jiffies,
71 .extra2 = &rds_sysctl_reconnect_max, 69 .extra2 = &rds_sysctl_reconnect_max,
72 }, 70 },
73 { 71 {
74 .ctl_name = CTL_UNNUMBERED,
75 .procname = "max_unacked_packets", 72 .procname = "max_unacked_packets",
76 .data = &rds_sysctl_max_unacked_packets, 73 .data = &rds_sysctl_max_unacked_packets,
77 .maxlen = sizeof(unsigned long), 74 .maxlen = sizeof(unsigned long),
78 .mode = 0644, 75 .mode = 0644,
79 .proc_handler = &proc_dointvec, 76 .proc_handler = proc_dointvec,
80 }, 77 },
81 { 78 {
82 .ctl_name = CTL_UNNUMBERED,
83 .procname = "max_unacked_bytes", 79 .procname = "max_unacked_bytes",
84 .data = &rds_sysctl_max_unacked_bytes, 80 .data = &rds_sysctl_max_unacked_bytes,
85 .maxlen = sizeof(unsigned long), 81 .maxlen = sizeof(unsigned long),
86 .mode = 0644, 82 .mode = 0644,
87 .proc_handler = &proc_dointvec, 83 .proc_handler = proc_dointvec,
88 }, 84 },
89 { 85 {
90 .ctl_name = CTL_UNNUMBERED,
91 .procname = "ping_enable", 86 .procname = "ping_enable",
92 .data = &rds_sysctl_ping_enable, 87 .data = &rds_sysctl_ping_enable,
93 .maxlen = sizeof(int), 88 .maxlen = sizeof(int),
94 .mode = 0644, 89 .mode = 0644,
95 .proc_handler = &proc_dointvec, 90 .proc_handler = proc_dointvec,
96 }, 91 },
97 { .ctl_name = 0} 92 { }
98}; 93};
99 94
100static struct ctl_path rds_sysctl_path[] = { 95static struct ctl_path rds_sysctl_path[] = {
101 { .procname = "net", .ctl_name = CTL_NET, }, 96 { .procname = "net", },
102 { .procname = "rds", .ctl_name = CTL_UNNUMBERED, }, 97 { .procname = "rds", },
103 { } 98 { }
104}; 99};
105 100
diff --git a/net/rds/tcp.c b/net/rds/tcp.c
index b5198aee45d3..babf4577ff7d 100644
--- a/net/rds/tcp.c
+++ b/net/rds/tcp.c
@@ -31,6 +31,7 @@
31 * 31 *
32 */ 32 */
33#include <linux/kernel.h> 33#include <linux/kernel.h>
34#include <linux/slab.h>
34#include <linux/in.h> 35#include <linux/in.h>
35#include <net/tcp.h> 36#include <net/tcp.h>
36 37
diff --git a/net/rds/tcp_connect.c b/net/rds/tcp_connect.c
index 211522f9a9a2..056256285987 100644
--- a/net/rds/tcp_connect.c
+++ b/net/rds/tcp_connect.c
@@ -90,8 +90,8 @@ int rds_tcp_conn_connect(struct rds_connection *conn)
90 90
91 ret = sock->ops->bind(sock, (struct sockaddr *)&src, sizeof(src)); 91 ret = sock->ops->bind(sock, (struct sockaddr *)&src, sizeof(src));
92 if (ret) { 92 if (ret) {
93 rdsdebug("bind failed with %d at address %u.%u.%u.%u\n", 93 rdsdebug("bind failed with %d at address %pI4\n",
94 ret, NIPQUAD(conn->c_laddr)); 94 ret, &conn->c_laddr);
95 goto out; 95 goto out;
96 } 96 }
97 97
@@ -108,8 +108,7 @@ int rds_tcp_conn_connect(struct rds_connection *conn)
108 O_NONBLOCK); 108 O_NONBLOCK);
109 sock = NULL; 109 sock = NULL;
110 110
111 rdsdebug("connect to address %u.%u.%u.%u returned %d\n", 111 rdsdebug("connect to address %pI4 returned %d\n", &conn->c_faddr, ret);
112 NIPQUAD(conn->c_faddr), ret);
113 if (ret == -EINPROGRESS) 112 if (ret == -EINPROGRESS)
114 ret = 0; 113 ret = 0;
115 114
diff --git a/net/rds/tcp_listen.c b/net/rds/tcp_listen.c
index 24b743eb0b1b..975183fe6950 100644
--- a/net/rds/tcp_listen.c
+++ b/net/rds/tcp_listen.c
@@ -31,6 +31,7 @@
31 * 31 *
32 */ 32 */
33#include <linux/kernel.h> 33#include <linux/kernel.h>
34#include <linux/gfp.h>
34#include <linux/in.h> 35#include <linux/in.h>
35#include <net/tcp.h> 36#include <net/tcp.h>
36 37
@@ -66,12 +67,12 @@ static int rds_tcp_accept_one(struct socket *sock)
66 67
67 inet = inet_sk(new_sock->sk); 68 inet = inet_sk(new_sock->sk);
68 69
69 rdsdebug("accepted tcp %u.%u.%u.%u:%u -> %u.%u.%u.%u:%u\n", 70 rdsdebug("accepted tcp %pI4:%u -> %pI4:%u\n",
70 NIPQUAD(inet->saddr), ntohs(inet->sport), 71 &inet->inet_saddr, ntohs(inet->inet_sport),
71 NIPQUAD(inet->daddr), ntohs(inet->dport)); 72 &inet->inet_daddr, ntohs(inet->inet_dport));
72 73
73 conn = rds_conn_create(inet->saddr, inet->daddr, &rds_tcp_transport, 74 conn = rds_conn_create(inet->inet_saddr, inet->inet_daddr,
74 GFP_KERNEL); 75 &rds_tcp_transport, GFP_KERNEL);
75 if (IS_ERR(conn)) { 76 if (IS_ERR(conn)) {
76 ret = PTR_ERR(conn); 77 ret = PTR_ERR(conn);
77 goto out; 78 goto out;
diff --git a/net/rds/tcp_recv.c b/net/rds/tcp_recv.c
index c00dafffbb5a..e08ec912d8b0 100644
--- a/net/rds/tcp_recv.c
+++ b/net/rds/tcp_recv.c
@@ -31,6 +31,7 @@
31 * 31 *
32 */ 32 */
33#include <linux/kernel.h> 33#include <linux/kernel.h>
34#include <linux/slab.h>
34#include <net/tcp.h> 35#include <net/tcp.h>
35 36
36#include "rds.h" 37#include "rds.h"
diff --git a/net/rds/tcp_send.c b/net/rds/tcp_send.c
index ab545e0cd5d6..34fdcc059e54 100644
--- a/net/rds/tcp_send.c
+++ b/net/rds/tcp_send.c
@@ -193,9 +193,9 @@ out:
193 rds_tcp_stats_inc(s_tcp_sndbuf_full); 193 rds_tcp_stats_inc(s_tcp_sndbuf_full);
194 ret = 0; 194 ret = 0;
195 } else { 195 } else {
196 printk(KERN_WARNING "RDS/tcp: send to %u.%u.%u.%u " 196 printk(KERN_WARNING "RDS/tcp: send to %pI4 "
197 "returned %d, disconnecting and reconnecting\n", 197 "returned %d, disconnecting and reconnecting\n",
198 NIPQUAD(conn->c_faddr), ret); 198 &conn->c_faddr, ret);
199 rds_conn_drop(conn); 199 rds_conn_drop(conn);
200 } 200 }
201 } 201 }
diff --git a/net/rds/threads.c b/net/rds/threads.c
index dd7e0cad1e7c..00fa10e59af8 100644
--- a/net/rds/threads.c
+++ b/net/rds/threads.c
@@ -170,8 +170,8 @@ void rds_shutdown_worker(struct work_struct *work)
170 * handler is supposed to check for state DISCONNECTING 170 * handler is supposed to check for state DISCONNECTING
171 */ 171 */
172 mutex_lock(&conn->c_cm_lock); 172 mutex_lock(&conn->c_cm_lock);
173 if (!rds_conn_transition(conn, RDS_CONN_UP, RDS_CONN_DISCONNECTING) 173 if (!rds_conn_transition(conn, RDS_CONN_UP, RDS_CONN_DISCONNECTING) &&
174 && !rds_conn_transition(conn, RDS_CONN_ERROR, RDS_CONN_DISCONNECTING)) { 174 !rds_conn_transition(conn, RDS_CONN_ERROR, RDS_CONN_DISCONNECTING)) {
175 rds_conn_error(conn, "shutdown called in state %d\n", 175 rds_conn_error(conn, "shutdown called in state %d\n",
176 atomic_read(&conn->c_state)); 176 atomic_read(&conn->c_state));
177 mutex_unlock(&conn->c_cm_lock); 177 mutex_unlock(&conn->c_cm_lock);
diff --git a/net/rfkill/core.c b/net/rfkill/core.c
index a001f7c1f711..a9fa86f65983 100644
--- a/net/rfkill/core.c
+++ b/net/rfkill/core.c
@@ -33,6 +33,7 @@
33#include <linux/wait.h> 33#include <linux/wait.h>
34#include <linux/poll.h> 34#include <linux/poll.h>
35#include <linux/fs.h> 35#include <linux/fs.h>
36#include <linux/slab.h>
36 37
37#include "rfkill.h" 38#include "rfkill.h"
38 39
@@ -579,6 +580,8 @@ static ssize_t rfkill_name_show(struct device *dev,
579 580
580static const char *rfkill_get_type_str(enum rfkill_type type) 581static const char *rfkill_get_type_str(enum rfkill_type type)
581{ 582{
583 BUILD_BUG_ON(NUM_RFKILL_TYPES != RFKILL_TYPE_FM + 1);
584
582 switch (type) { 585 switch (type) {
583 case RFKILL_TYPE_WLAN: 586 case RFKILL_TYPE_WLAN:
584 return "wlan"; 587 return "wlan";
@@ -592,11 +595,11 @@ static const char *rfkill_get_type_str(enum rfkill_type type)
592 return "wwan"; 595 return "wwan";
593 case RFKILL_TYPE_GPS: 596 case RFKILL_TYPE_GPS:
594 return "gps"; 597 return "gps";
598 case RFKILL_TYPE_FM:
599 return "fm";
595 default: 600 default:
596 BUG(); 601 BUG();
597 } 602 }
598
599 BUILD_BUG_ON(NUM_RFKILL_TYPES != RFKILL_TYPE_GPS + 1);
600} 603}
601 604
602static ssize_t rfkill_type_show(struct device *dev, 605static ssize_t rfkill_type_show(struct device *dev,
diff --git a/net/rfkill/input.c b/net/rfkill/input.c
index a7295ad5f9cb..3713d7ecab96 100644
--- a/net/rfkill/input.c
+++ b/net/rfkill/input.c
@@ -212,6 +212,9 @@ static void rfkill_event(struct input_handle *handle, unsigned int type,
212 case KEY_WIMAX: 212 case KEY_WIMAX:
213 rfkill_schedule_toggle(RFKILL_TYPE_WIMAX); 213 rfkill_schedule_toggle(RFKILL_TYPE_WIMAX);
214 break; 214 break;
215 case KEY_RFKILL:
216 rfkill_schedule_toggle(RFKILL_TYPE_ALL);
217 break;
215 } 218 }
216 } else if (type == EV_SW && code == SW_RFKILL_ALL) 219 } else if (type == EV_SW && code == SW_RFKILL_ALL)
217 rfkill_schedule_evsw_rfkillall(data); 220 rfkill_schedule_evsw_rfkillall(data);
@@ -295,6 +298,11 @@ static const struct input_device_id rfkill_ids[] = {
295 .keybit = { [BIT_WORD(KEY_WIMAX)] = BIT_MASK(KEY_WIMAX) }, 298 .keybit = { [BIT_WORD(KEY_WIMAX)] = BIT_MASK(KEY_WIMAX) },
296 }, 299 },
297 { 300 {
301 .flags = INPUT_DEVICE_ID_MATCH_EVBIT | INPUT_DEVICE_ID_MATCH_KEYBIT,
302 .evbit = { BIT_MASK(EV_KEY) },
303 .keybit = { [BIT_WORD(KEY_RFKILL)] = BIT_MASK(KEY_RFKILL) },
304 },
305 {
298 .flags = INPUT_DEVICE_ID_MATCH_EVBIT | INPUT_DEVICE_ID_MATCH_SWBIT, 306 .flags = INPUT_DEVICE_ID_MATCH_EVBIT | INPUT_DEVICE_ID_MATCH_SWBIT,
299 .evbit = { BIT(EV_SW) }, 307 .evbit = { BIT(EV_SW) },
300 .swbit = { [BIT_WORD(SW_RFKILL_ALL)] = BIT_MASK(SW_RFKILL_ALL) }, 308 .swbit = { [BIT_WORD(SW_RFKILL_ALL)] = BIT_MASK(SW_RFKILL_ALL) },
diff --git a/net/rose/af_rose.c b/net/rose/af_rose.c
index 502cce76621d..4fb711a035f4 100644
--- a/net/rose/af_rose.c
+++ b/net/rose/af_rose.c
@@ -18,6 +18,7 @@
18#include <linux/types.h> 18#include <linux/types.h>
19#include <linux/socket.h> 19#include <linux/socket.h>
20#include <linux/in.h> 20#include <linux/in.h>
21#include <linux/slab.h>
21#include <linux/kernel.h> 22#include <linux/kernel.h>
22#include <linux/sched.h> 23#include <linux/sched.h>
23#include <linux/spinlock.h> 24#include <linux/spinlock.h>
@@ -512,12 +513,13 @@ static struct proto rose_proto = {
512 .obj_size = sizeof(struct rose_sock), 513 .obj_size = sizeof(struct rose_sock),
513}; 514};
514 515
515static int rose_create(struct net *net, struct socket *sock, int protocol) 516static int rose_create(struct net *net, struct socket *sock, int protocol,
517 int kern)
516{ 518{
517 struct sock *sk; 519 struct sock *sk;
518 struct rose_sock *rose; 520 struct rose_sock *rose;
519 521
520 if (net != &init_net) 522 if (!net_eq(net, &init_net))
521 return -EAFNOSUPPORT; 523 return -EAFNOSUPPORT;
522 524
523 if (sock->type != SOCK_SEQPACKET || protocol != 0) 525 if (sock->type != SOCK_SEQPACKET || protocol != 0)
@@ -1403,29 +1405,13 @@ static int rose_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
1403static void *rose_info_start(struct seq_file *seq, loff_t *pos) 1405static void *rose_info_start(struct seq_file *seq, loff_t *pos)
1404 __acquires(rose_list_lock) 1406 __acquires(rose_list_lock)
1405{ 1407{
1406 int i;
1407 struct sock *s;
1408 struct hlist_node *node;
1409
1410 spin_lock_bh(&rose_list_lock); 1408 spin_lock_bh(&rose_list_lock);
1411 if (*pos == 0) 1409 return seq_hlist_start_head(&rose_list, *pos);
1412 return SEQ_START_TOKEN;
1413
1414 i = 1;
1415 sk_for_each(s, node, &rose_list) {
1416 if (i == *pos)
1417 return s;
1418 ++i;
1419 }
1420 return NULL;
1421} 1410}
1422 1411
1423static void *rose_info_next(struct seq_file *seq, void *v, loff_t *pos) 1412static void *rose_info_next(struct seq_file *seq, void *v, loff_t *pos)
1424{ 1413{
1425 ++*pos; 1414 return seq_hlist_next(v, &rose_list, pos);
1426
1427 return (v == SEQ_START_TOKEN) ? sk_head(&rose_list)
1428 : sk_next((struct sock *)v);
1429} 1415}
1430 1416
1431static void rose_info_stop(struct seq_file *seq, void *v) 1417static void rose_info_stop(struct seq_file *seq, void *v)
@@ -1443,7 +1429,7 @@ static int rose_info_show(struct seq_file *seq, void *v)
1443 "dest_addr dest_call src_addr src_call dev lci neigh st vs vr va t t1 t2 t3 hb idle Snd-Q Rcv-Q inode\n"); 1429 "dest_addr dest_call src_addr src_call dev lci neigh st vs vr va t t1 t2 t3 hb idle Snd-Q Rcv-Q inode\n");
1444 1430
1445 else { 1431 else {
1446 struct sock *s = v; 1432 struct sock *s = sk_entry(v);
1447 struct rose_sock *rose = rose_sk(s); 1433 struct rose_sock *rose = rose_sk(s);
1448 const char *devname, *callsign; 1434 const char *devname, *callsign;
1449 const struct net_device *dev = rose->device; 1435 const struct net_device *dev = rose->device;
@@ -1509,7 +1495,7 @@ static const struct file_operations rose_info_fops = {
1509}; 1495};
1510#endif /* CONFIG_PROC_FS */ 1496#endif /* CONFIG_PROC_FS */
1511 1497
1512static struct net_proto_family rose_family_ops = { 1498static const struct net_proto_family rose_family_ops = {
1513 .family = PF_ROSE, 1499 .family = PF_ROSE,
1514 .create = rose_create, 1500 .create = rose_create,
1515 .owner = THIS_MODULE, 1501 .owner = THIS_MODULE,
diff --git a/net/rose/rose_dev.c b/net/rose/rose_dev.c
index 424b893d1450..178ff4f73c85 100644
--- a/net/rose/rose_dev.c
+++ b/net/rose/rose_dev.c
@@ -19,6 +19,7 @@
19#include <linux/fcntl.h> 19#include <linux/fcntl.h>
20#include <linux/in.h> 20#include <linux/in.h>
21#include <linux/if_ether.h> 21#include <linux/if_ether.h>
22#include <linux/slab.h>
22 23
23#include <asm/system.h> 24#include <asm/system.h>
24#include <asm/io.h> 25#include <asm/io.h>
diff --git a/net/rose/rose_link.c b/net/rose/rose_link.c
index bd86a63960ce..a750a28e0221 100644
--- a/net/rose/rose_link.c
+++ b/net/rose/rose_link.c
@@ -16,6 +16,7 @@
16#include <linux/string.h> 16#include <linux/string.h>
17#include <linux/sockios.h> 17#include <linux/sockios.h>
18#include <linux/net.h> 18#include <linux/net.h>
19#include <linux/slab.h>
19#include <net/ax25.h> 20#include <net/ax25.h>
20#include <linux/inet.h> 21#include <linux/inet.h>
21#include <linux/netdevice.h> 22#include <linux/netdevice.h>
@@ -101,13 +102,17 @@ static void rose_t0timer_expiry(unsigned long param)
101static int rose_send_frame(struct sk_buff *skb, struct rose_neigh *neigh) 102static int rose_send_frame(struct sk_buff *skb, struct rose_neigh *neigh)
102{ 103{
103 ax25_address *rose_call; 104 ax25_address *rose_call;
105 ax25_cb *ax25s;
104 106
105 if (ax25cmp(&rose_callsign, &null_ax25_address) == 0) 107 if (ax25cmp(&rose_callsign, &null_ax25_address) == 0)
106 rose_call = (ax25_address *)neigh->dev->dev_addr; 108 rose_call = (ax25_address *)neigh->dev->dev_addr;
107 else 109 else
108 rose_call = &rose_callsign; 110 rose_call = &rose_callsign;
109 111
112 ax25s = neigh->ax25;
110 neigh->ax25 = ax25_send_frame(skb, 260, rose_call, &neigh->callsign, neigh->digipeat, neigh->dev); 113 neigh->ax25 = ax25_send_frame(skb, 260, rose_call, &neigh->callsign, neigh->digipeat, neigh->dev);
114 if (ax25s)
115 ax25_cb_put(ax25s);
111 116
112 return (neigh->ax25 != NULL); 117 return (neigh->ax25 != NULL);
113} 118}
@@ -120,13 +125,17 @@ static int rose_send_frame(struct sk_buff *skb, struct rose_neigh *neigh)
120static int rose_link_up(struct rose_neigh *neigh) 125static int rose_link_up(struct rose_neigh *neigh)
121{ 126{
122 ax25_address *rose_call; 127 ax25_address *rose_call;
128 ax25_cb *ax25s;
123 129
124 if (ax25cmp(&rose_callsign, &null_ax25_address) == 0) 130 if (ax25cmp(&rose_callsign, &null_ax25_address) == 0)
125 rose_call = (ax25_address *)neigh->dev->dev_addr; 131 rose_call = (ax25_address *)neigh->dev->dev_addr;
126 else 132 else
127 rose_call = &rose_callsign; 133 rose_call = &rose_callsign;
128 134
135 ax25s = neigh->ax25;
129 neigh->ax25 = ax25_find_cb(rose_call, &neigh->callsign, neigh->digipeat, neigh->dev); 136 neigh->ax25 = ax25_find_cb(rose_call, &neigh->callsign, neigh->digipeat, neigh->dev);
137 if (ax25s)
138 ax25_cb_put(ax25s);
130 139
131 return (neigh->ax25 != NULL); 140 return (neigh->ax25 != NULL);
132} 141}
diff --git a/net/rose/rose_loopback.c b/net/rose/rose_loopback.c
index 114df6eec8c3..ae4a9d99aec7 100644
--- a/net/rose/rose_loopback.c
+++ b/net/rose/rose_loopback.c
@@ -7,6 +7,7 @@
7 * Copyright (C) Jonathan Naylor G4KLX (g4klx@g4klx.demon.co.uk) 7 * Copyright (C) Jonathan Naylor G4KLX (g4klx@g4klx.demon.co.uk)
8 */ 8 */
9#include <linux/types.h> 9#include <linux/types.h>
10#include <linux/slab.h>
10#include <linux/socket.h> 11#include <linux/socket.h>
11#include <linux/timer.h> 12#include <linux/timer.h>
12#include <net/ax25.h> 13#include <net/ax25.h>
@@ -75,7 +76,7 @@ static void rose_loopback_timer(unsigned long param)
75 lci_i = ((skb->data[0] << 8) & 0xF00) + ((skb->data[1] << 0) & 0x0FF); 76 lci_i = ((skb->data[0] << 8) & 0xF00) + ((skb->data[1] << 0) & 0x0FF);
76 frametype = skb->data[2]; 77 frametype = skb->data[2];
77 dest = (rose_address *)(skb->data + 4); 78 dest = (rose_address *)(skb->data + 4);
78 lci_o = 0xFFF - lci_i; 79 lci_o = ROSE_DEFAULT_MAXVC + 1 - lci_i;
79 80
80 skb_reset_transport_header(skb); 81 skb_reset_transport_header(skb);
81 82
diff --git a/net/rose/rose_out.c b/net/rose/rose_out.c
index 69820f93414b..4ebf33afbe47 100644
--- a/net/rose/rose_out.c
+++ b/net/rose/rose_out.c
@@ -15,6 +15,7 @@
15#include <linux/string.h> 15#include <linux/string.h>
16#include <linux/sockios.h> 16#include <linux/sockios.h>
17#include <linux/net.h> 17#include <linux/net.h>
18#include <linux/gfp.h>
18#include <net/ax25.h> 19#include <net/ax25.h>
19#include <linux/inet.h> 20#include <linux/inet.h>
20#include <linux/netdevice.h> 21#include <linux/netdevice.h>
diff --git a/net/rose/rose_route.c b/net/rose/rose_route.c
index f3e21989b88c..cbc244a128bd 100644
--- a/net/rose/rose_route.c
+++ b/net/rose/rose_route.c
@@ -16,6 +16,7 @@
16#include <linux/string.h> 16#include <linux/string.h>
17#include <linux/sockios.h> 17#include <linux/sockios.h>
18#include <linux/net.h> 18#include <linux/net.h>
19#include <linux/slab.h>
19#include <net/ax25.h> 20#include <net/ax25.h>
20#include <linux/inet.h> 21#include <linux/inet.h>
21#include <linux/netdevice.h> 22#include <linux/netdevice.h>
@@ -77,8 +78,9 @@ static int __must_check rose_add_node(struct rose_route_struct *rose_route,
77 78
78 rose_neigh = rose_neigh_list; 79 rose_neigh = rose_neigh_list;
79 while (rose_neigh != NULL) { 80 while (rose_neigh != NULL) {
80 if (ax25cmp(&rose_route->neighbour, &rose_neigh->callsign) == 0 81 if (ax25cmp(&rose_route->neighbour,
81 && rose_neigh->dev == dev) 82 &rose_neigh->callsign) == 0 &&
83 rose_neigh->dev == dev)
82 break; 84 break;
83 rose_neigh = rose_neigh->next; 85 rose_neigh = rose_neigh->next;
84 } 86 }
@@ -234,6 +236,8 @@ static void rose_remove_neigh(struct rose_neigh *rose_neigh)
234 236
235 if ((s = rose_neigh_list) == rose_neigh) { 237 if ((s = rose_neigh_list) == rose_neigh) {
236 rose_neigh_list = rose_neigh->next; 238 rose_neigh_list = rose_neigh->next;
239 if (rose_neigh->ax25)
240 ax25_cb_put(rose_neigh->ax25);
237 kfree(rose_neigh->digipeat); 241 kfree(rose_neigh->digipeat);
238 kfree(rose_neigh); 242 kfree(rose_neigh);
239 return; 243 return;
@@ -242,6 +246,8 @@ static void rose_remove_neigh(struct rose_neigh *rose_neigh)
242 while (s != NULL && s->next != NULL) { 246 while (s != NULL && s->next != NULL) {
243 if (s->next == rose_neigh) { 247 if (s->next == rose_neigh) {
244 s->next = rose_neigh->next; 248 s->next = rose_neigh->next;
249 if (rose_neigh->ax25)
250 ax25_cb_put(rose_neigh->ax25);
245 kfree(rose_neigh->digipeat); 251 kfree(rose_neigh->digipeat);
246 kfree(rose_neigh); 252 kfree(rose_neigh);
247 return; 253 return;
@@ -311,8 +317,9 @@ static int rose_del_node(struct rose_route_struct *rose_route,
311 317
312 rose_neigh = rose_neigh_list; 318 rose_neigh = rose_neigh_list;
313 while (rose_neigh != NULL) { 319 while (rose_neigh != NULL) {
314 if (ax25cmp(&rose_route->neighbour, &rose_neigh->callsign) == 0 320 if (ax25cmp(&rose_route->neighbour,
315 && rose_neigh->dev == dev) 321 &rose_neigh->callsign) == 0 &&
322 rose_neigh->dev == dev)
316 break; 323 break;
317 rose_neigh = rose_neigh->next; 324 rose_neigh = rose_neigh->next;
318 } 325 }
@@ -600,13 +607,13 @@ struct net_device *rose_dev_first(void)
600{ 607{
601 struct net_device *dev, *first = NULL; 608 struct net_device *dev, *first = NULL;
602 609
603 read_lock(&dev_base_lock); 610 rcu_read_lock();
604 for_each_netdev(&init_net, dev) { 611 for_each_netdev_rcu(&init_net, dev) {
605 if ((dev->flags & IFF_UP) && dev->type == ARPHRD_ROSE) 612 if ((dev->flags & IFF_UP) && dev->type == ARPHRD_ROSE)
606 if (first == NULL || strncmp(dev->name, first->name, 3) < 0) 613 if (first == NULL || strncmp(dev->name, first->name, 3) < 0)
607 first = dev; 614 first = dev;
608 } 615 }
609 read_unlock(&dev_base_lock); 616 rcu_read_unlock();
610 617
611 return first; 618 return first;
612} 619}
@@ -618,8 +625,8 @@ struct net_device *rose_dev_get(rose_address *addr)
618{ 625{
619 struct net_device *dev; 626 struct net_device *dev;
620 627
621 read_lock(&dev_base_lock); 628 rcu_read_lock();
622 for_each_netdev(&init_net, dev) { 629 for_each_netdev_rcu(&init_net, dev) {
623 if ((dev->flags & IFF_UP) && dev->type == ARPHRD_ROSE && rosecmp(addr, (rose_address *)dev->dev_addr) == 0) { 630 if ((dev->flags & IFF_UP) && dev->type == ARPHRD_ROSE && rosecmp(addr, (rose_address *)dev->dev_addr) == 0) {
624 dev_hold(dev); 631 dev_hold(dev);
625 goto out; 632 goto out;
@@ -627,7 +634,7 @@ struct net_device *rose_dev_get(rose_address *addr)
627 } 634 }
628 dev = NULL; 635 dev = NULL;
629out: 636out:
630 read_unlock(&dev_base_lock); 637 rcu_read_unlock();
631 return dev; 638 return dev;
632} 639}
633 640
@@ -635,14 +642,14 @@ static int rose_dev_exists(rose_address *addr)
635{ 642{
636 struct net_device *dev; 643 struct net_device *dev;
637 644
638 read_lock(&dev_base_lock); 645 rcu_read_lock();
639 for_each_netdev(&init_net, dev) { 646 for_each_netdev_rcu(&init_net, dev) {
640 if ((dev->flags & IFF_UP) && dev->type == ARPHRD_ROSE && rosecmp(addr, (rose_address *)dev->dev_addr) == 0) 647 if ((dev->flags & IFF_UP) && dev->type == ARPHRD_ROSE && rosecmp(addr, (rose_address *)dev->dev_addr) == 0)
641 goto out; 648 goto out;
642 } 649 }
643 dev = NULL; 650 dev = NULL;
644out: 651out:
645 read_unlock(&dev_base_lock); 652 rcu_read_unlock();
646 return dev != NULL; 653 return dev != NULL;
647} 654}
648 655
@@ -810,6 +817,7 @@ void rose_link_failed(ax25_cb *ax25, int reason)
810 817
811 if (rose_neigh != NULL) { 818 if (rose_neigh != NULL) {
812 rose_neigh->ax25 = NULL; 819 rose_neigh->ax25 = NULL;
820 ax25_cb_put(ax25);
813 821
814 rose_del_route_by_neigh(rose_neigh); 822 rose_del_route_by_neigh(rose_neigh);
815 rose_kill_by_neigh(rose_neigh); 823 rose_kill_by_neigh(rose_neigh);
diff --git a/net/rose/rose_subr.c b/net/rose/rose_subr.c
index b05108f382da..1734abba26a2 100644
--- a/net/rose/rose_subr.c
+++ b/net/rose/rose_subr.c
@@ -15,6 +15,7 @@
15#include <linux/string.h> 15#include <linux/string.h>
16#include <linux/sockios.h> 16#include <linux/sockios.h>
17#include <linux/net.h> 17#include <linux/net.h>
18#include <linux/slab.h>
18#include <net/ax25.h> 19#include <net/ax25.h>
19#include <linux/inet.h> 20#include <linux/inet.h>
20#include <linux/netdevice.h> 21#include <linux/netdevice.h>
diff --git a/net/rose/sysctl_net_rose.c b/net/rose/sysctl_net_rose.c
index 3bfe504faf86..df6d9dac2186 100644
--- a/net/rose/sysctl_net_rose.c
+++ b/net/rose/sysctl_net_rose.c
@@ -26,121 +26,101 @@ static struct ctl_table_header *rose_table_header;
26 26
27static ctl_table rose_table[] = { 27static ctl_table rose_table[] = {
28 { 28 {
29 .ctl_name = NET_ROSE_RESTART_REQUEST_TIMEOUT,
30 .procname = "restart_request_timeout", 29 .procname = "restart_request_timeout",
31 .data = &sysctl_rose_restart_request_timeout, 30 .data = &sysctl_rose_restart_request_timeout,
32 .maxlen = sizeof(int), 31 .maxlen = sizeof(int),
33 .mode = 0644, 32 .mode = 0644,
34 .proc_handler = proc_dointvec_minmax, 33 .proc_handler = proc_dointvec_minmax,
35 .strategy = sysctl_intvec,
36 .extra1 = &min_timer, 34 .extra1 = &min_timer,
37 .extra2 = &max_timer 35 .extra2 = &max_timer
38 }, 36 },
39 { 37 {
40 .ctl_name = NET_ROSE_CALL_REQUEST_TIMEOUT,
41 .procname = "call_request_timeout", 38 .procname = "call_request_timeout",
42 .data = &sysctl_rose_call_request_timeout, 39 .data = &sysctl_rose_call_request_timeout,
43 .maxlen = sizeof(int), 40 .maxlen = sizeof(int),
44 .mode = 0644, 41 .mode = 0644,
45 .proc_handler = proc_dointvec_minmax, 42 .proc_handler = proc_dointvec_minmax,
46 .strategy = sysctl_intvec,
47 .extra1 = &min_timer, 43 .extra1 = &min_timer,
48 .extra2 = &max_timer 44 .extra2 = &max_timer
49 }, 45 },
50 { 46 {
51 .ctl_name = NET_ROSE_RESET_REQUEST_TIMEOUT,
52 .procname = "reset_request_timeout", 47 .procname = "reset_request_timeout",
53 .data = &sysctl_rose_reset_request_timeout, 48 .data = &sysctl_rose_reset_request_timeout,
54 .maxlen = sizeof(int), 49 .maxlen = sizeof(int),
55 .mode = 0644, 50 .mode = 0644,
56 .proc_handler = proc_dointvec_minmax, 51 .proc_handler = proc_dointvec_minmax,
57 .strategy = sysctl_intvec,
58 .extra1 = &min_timer, 52 .extra1 = &min_timer,
59 .extra2 = &max_timer 53 .extra2 = &max_timer
60 }, 54 },
61 { 55 {
62 .ctl_name = NET_ROSE_CLEAR_REQUEST_TIMEOUT,
63 .procname = "clear_request_timeout", 56 .procname = "clear_request_timeout",
64 .data = &sysctl_rose_clear_request_timeout, 57 .data = &sysctl_rose_clear_request_timeout,
65 .maxlen = sizeof(int), 58 .maxlen = sizeof(int),
66 .mode = 0644, 59 .mode = 0644,
67 .proc_handler = proc_dointvec_minmax, 60 .proc_handler = proc_dointvec_minmax,
68 .strategy = sysctl_intvec,
69 .extra1 = &min_timer, 61 .extra1 = &min_timer,
70 .extra2 = &max_timer 62 .extra2 = &max_timer
71 }, 63 },
72 { 64 {
73 .ctl_name = NET_ROSE_NO_ACTIVITY_TIMEOUT,
74 .procname = "no_activity_timeout", 65 .procname = "no_activity_timeout",
75 .data = &sysctl_rose_no_activity_timeout, 66 .data = &sysctl_rose_no_activity_timeout,
76 .maxlen = sizeof(int), 67 .maxlen = sizeof(int),
77 .mode = 0644, 68 .mode = 0644,
78 .proc_handler = proc_dointvec_minmax, 69 .proc_handler = proc_dointvec_minmax,
79 .strategy = sysctl_intvec,
80 .extra1 = &min_idle, 70 .extra1 = &min_idle,
81 .extra2 = &max_idle 71 .extra2 = &max_idle
82 }, 72 },
83 { 73 {
84 .ctl_name = NET_ROSE_ACK_HOLD_BACK_TIMEOUT,
85 .procname = "acknowledge_hold_back_timeout", 74 .procname = "acknowledge_hold_back_timeout",
86 .data = &sysctl_rose_ack_hold_back_timeout, 75 .data = &sysctl_rose_ack_hold_back_timeout,
87 .maxlen = sizeof(int), 76 .maxlen = sizeof(int),
88 .mode = 0644, 77 .mode = 0644,
89 .proc_handler = proc_dointvec_minmax, 78 .proc_handler = proc_dointvec_minmax,
90 .strategy = sysctl_intvec,
91 .extra1 = &min_timer, 79 .extra1 = &min_timer,
92 .extra2 = &max_timer 80 .extra2 = &max_timer
93 }, 81 },
94 { 82 {
95 .ctl_name = NET_ROSE_ROUTING_CONTROL,
96 .procname = "routing_control", 83 .procname = "routing_control",
97 .data = &sysctl_rose_routing_control, 84 .data = &sysctl_rose_routing_control,
98 .maxlen = sizeof(int), 85 .maxlen = sizeof(int),
99 .mode = 0644, 86 .mode = 0644,
100 .proc_handler = proc_dointvec_minmax, 87 .proc_handler = proc_dointvec_minmax,
101 .strategy = sysctl_intvec,
102 .extra1 = &min_route, 88 .extra1 = &min_route,
103 .extra2 = &max_route 89 .extra2 = &max_route
104 }, 90 },
105 { 91 {
106 .ctl_name = NET_ROSE_LINK_FAIL_TIMEOUT,
107 .procname = "link_fail_timeout", 92 .procname = "link_fail_timeout",
108 .data = &sysctl_rose_link_fail_timeout, 93 .data = &sysctl_rose_link_fail_timeout,
109 .maxlen = sizeof(int), 94 .maxlen = sizeof(int),
110 .mode = 0644, 95 .mode = 0644,
111 .proc_handler = proc_dointvec_minmax, 96 .proc_handler = proc_dointvec_minmax,
112 .strategy = sysctl_intvec,
113 .extra1 = &min_ftimer, 97 .extra1 = &min_ftimer,
114 .extra2 = &max_ftimer 98 .extra2 = &max_ftimer
115 }, 99 },
116 { 100 {
117 .ctl_name = NET_ROSE_MAX_VCS,
118 .procname = "maximum_virtual_circuits", 101 .procname = "maximum_virtual_circuits",
119 .data = &sysctl_rose_maximum_vcs, 102 .data = &sysctl_rose_maximum_vcs,
120 .maxlen = sizeof(int), 103 .maxlen = sizeof(int),
121 .mode = 0644, 104 .mode = 0644,
122 .proc_handler = proc_dointvec_minmax, 105 .proc_handler = proc_dointvec_minmax,
123 .strategy = sysctl_intvec,
124 .extra1 = &min_maxvcs, 106 .extra1 = &min_maxvcs,
125 .extra2 = &max_maxvcs 107 .extra2 = &max_maxvcs
126 }, 108 },
127 { 109 {
128 .ctl_name = NET_ROSE_WINDOW_SIZE,
129 .procname = "window_size", 110 .procname = "window_size",
130 .data = &sysctl_rose_window_size, 111 .data = &sysctl_rose_window_size,
131 .maxlen = sizeof(int), 112 .maxlen = sizeof(int),
132 .mode = 0644, 113 .mode = 0644,
133 .proc_handler = proc_dointvec_minmax, 114 .proc_handler = proc_dointvec_minmax,
134 .strategy = sysctl_intvec,
135 .extra1 = &min_window, 115 .extra1 = &min_window,
136 .extra2 = &max_window 116 .extra2 = &max_window
137 }, 117 },
138 { .ctl_name = 0 } 118 { }
139}; 119};
140 120
141static struct ctl_path rose_path[] = { 121static struct ctl_path rose_path[] = {
142 { .procname = "net", .ctl_name = CTL_NET, }, 122 { .procname = "net", },
143 { .procname = "rose", .ctl_name = NET_ROSE, }, 123 { .procname = "rose", },
144 { } 124 { }
145}; 125};
146 126
diff --git a/net/rxrpc/af_rxrpc.c b/net/rxrpc/af_rxrpc.c
index a86afceaa94f..c060095b27ce 100644
--- a/net/rxrpc/af_rxrpc.c
+++ b/net/rxrpc/af_rxrpc.c
@@ -11,6 +11,7 @@
11 11
12#include <linux/module.h> 12#include <linux/module.h>
13#include <linux/net.h> 13#include <linux/net.h>
14#include <linux/slab.h>
14#include <linux/skbuff.h> 15#include <linux/skbuff.h>
15#include <linux/poll.h> 16#include <linux/poll.h>
16#include <linux/proc_fs.h> 17#include <linux/proc_fs.h>
@@ -608,14 +609,15 @@ static unsigned int rxrpc_poll(struct file *file, struct socket *sock,
608/* 609/*
609 * create an RxRPC socket 610 * create an RxRPC socket
610 */ 611 */
611static int rxrpc_create(struct net *net, struct socket *sock, int protocol) 612static int rxrpc_create(struct net *net, struct socket *sock, int protocol,
613 int kern)
612{ 614{
613 struct rxrpc_sock *rx; 615 struct rxrpc_sock *rx;
614 struct sock *sk; 616 struct sock *sk;
615 617
616 _enter("%p,%d", sock, protocol); 618 _enter("%p,%d", sock, protocol);
617 619
618 if (net != &init_net) 620 if (!net_eq(net, &init_net))
619 return -EAFNOSUPPORT; 621 return -EAFNOSUPPORT;
620 622
621 /* we support transport protocol UDP only */ 623 /* we support transport protocol UDP only */
@@ -777,7 +779,7 @@ static struct proto rxrpc_proto = {
777 .max_header = sizeof(struct rxrpc_header), 779 .max_header = sizeof(struct rxrpc_header),
778}; 780};
779 781
780static struct net_proto_family rxrpc_family_ops = { 782static const struct net_proto_family rxrpc_family_ops = {
781 .family = PF_RXRPC, 783 .family = PF_RXRPC,
782 .create = rxrpc_create, 784 .create = rxrpc_create,
783 .owner = THIS_MODULE, 785 .owner = THIS_MODULE,
diff --git a/net/rxrpc/ar-accept.c b/net/rxrpc/ar-accept.c
index 77228f28fa36..6d79310fcaae 100644
--- a/net/rxrpc/ar-accept.c
+++ b/net/rxrpc/ar-accept.c
@@ -17,6 +17,7 @@
17#include <linux/in.h> 17#include <linux/in.h>
18#include <linux/in6.h> 18#include <linux/in6.h>
19#include <linux/icmp.h> 19#include <linux/icmp.h>
20#include <linux/gfp.h>
20#include <net/sock.h> 21#include <net/sock.h>
21#include <net/af_rxrpc.h> 22#include <net/af_rxrpc.h>
22#include <net/ip.h> 23#include <net/ip.h>
@@ -88,6 +89,11 @@ static int rxrpc_accept_incoming_call(struct rxrpc_local *local,
88 89
89 /* get a notification message to send to the server app */ 90 /* get a notification message to send to the server app */
90 notification = alloc_skb(0, GFP_NOFS); 91 notification = alloc_skb(0, GFP_NOFS);
92 if (!notification) {
93 _debug("no memory");
94 ret = -ENOMEM;
95 goto error_nofree;
96 }
91 rxrpc_new_skb(notification); 97 rxrpc_new_skb(notification);
92 notification->mark = RXRPC_SKB_MARK_NEW_CALL; 98 notification->mark = RXRPC_SKB_MARK_NEW_CALL;
93 99
@@ -189,6 +195,7 @@ invalid_service:
189 ret = -ECONNREFUSED; 195 ret = -ECONNREFUSED;
190error: 196error:
191 rxrpc_free_skb(notification); 197 rxrpc_free_skb(notification);
198error_nofree:
192 _leave(" = %d", ret); 199 _leave(" = %d", ret);
193 return ret; 200 return ret;
194} 201}
diff --git a/net/rxrpc/ar-ack.c b/net/rxrpc/ar-ack.c
index b4a220977031..2714da167fb8 100644
--- a/net/rxrpc/ar-ack.c
+++ b/net/rxrpc/ar-ack.c
@@ -13,6 +13,7 @@
13#include <linux/circ_buf.h> 13#include <linux/circ_buf.h>
14#include <linux/net.h> 14#include <linux/net.h>
15#include <linux/skbuff.h> 15#include <linux/skbuff.h>
16#include <linux/slab.h>
16#include <linux/udp.h> 17#include <linux/udp.h>
17#include <net/sock.h> 18#include <net/sock.h>
18#include <net/af_rxrpc.h> 19#include <net/af_rxrpc.h>
diff --git a/net/rxrpc/ar-call.c b/net/rxrpc/ar-call.c
index bc0019f704fe..909d092de9f4 100644
--- a/net/rxrpc/ar-call.c
+++ b/net/rxrpc/ar-call.c
@@ -9,6 +9,7 @@
9 * 2 of the License, or (at your option) any later version. 9 * 2 of the License, or (at your option) any later version.
10 */ 10 */
11 11
12#include <linux/slab.h>
12#include <linux/module.h> 13#include <linux/module.h>
13#include <linux/circ_buf.h> 14#include <linux/circ_buf.h>
14#include <net/sock.h> 15#include <net/sock.h>
diff --git a/net/rxrpc/ar-connection.c b/net/rxrpc/ar-connection.c
index 9f1ce841a0bb..4106ca95ec86 100644
--- a/net/rxrpc/ar-connection.c
+++ b/net/rxrpc/ar-connection.c
@@ -10,6 +10,7 @@
10 */ 10 */
11 11
12#include <linux/module.h> 12#include <linux/module.h>
13#include <linux/slab.h>
13#include <linux/net.h> 14#include <linux/net.h>
14#include <linux/skbuff.h> 15#include <linux/skbuff.h>
15#include <linux/crypto.h> 16#include <linux/crypto.h>
diff --git a/net/rxrpc/ar-input.c b/net/rxrpc/ar-input.c
index f98c8027e5c1..89315009bab1 100644
--- a/net/rxrpc/ar-input.c
+++ b/net/rxrpc/ar-input.c
@@ -17,6 +17,7 @@
17#include <linux/in.h> 17#include <linux/in.h>
18#include <linux/in6.h> 18#include <linux/in6.h>
19#include <linux/icmp.h> 19#include <linux/icmp.h>
20#include <linux/gfp.h>
20#include <net/sock.h> 21#include <net/sock.h>
21#include <net/af_rxrpc.h> 22#include <net/af_rxrpc.h>
22#include <net/ip.h> 23#include <net/ip.h>
diff --git a/net/rxrpc/ar-key.c b/net/rxrpc/ar-key.c
index 74697b200496..5ee16f0353fe 100644
--- a/net/rxrpc/ar-key.c
+++ b/net/rxrpc/ar-key.c
@@ -18,6 +18,7 @@
18#include <linux/key-type.h> 18#include <linux/key-type.h>
19#include <linux/crypto.h> 19#include <linux/crypto.h>
20#include <linux/ctype.h> 20#include <linux/ctype.h>
21#include <linux/slab.h>
21#include <net/sock.h> 22#include <net/sock.h>
22#include <net/af_rxrpc.h> 23#include <net/af_rxrpc.h>
23#include <keys/rxrpc-type.h> 24#include <keys/rxrpc-type.h>
diff --git a/net/rxrpc/ar-local.c b/net/rxrpc/ar-local.c
index 807535ff29b5..87f7135d238b 100644
--- a/net/rxrpc/ar-local.c
+++ b/net/rxrpc/ar-local.c
@@ -12,6 +12,7 @@
12#include <linux/module.h> 12#include <linux/module.h>
13#include <linux/net.h> 13#include <linux/net.h>
14#include <linux/skbuff.h> 14#include <linux/skbuff.h>
15#include <linux/slab.h>
15#include <net/sock.h> 16#include <net/sock.h>
16#include <net/af_rxrpc.h> 17#include <net/af_rxrpc.h>
17#include "ar-internal.h" 18#include "ar-internal.h"
diff --git a/net/rxrpc/ar-output.c b/net/rxrpc/ar-output.c
index cc9102c5b588..5f22e263eda7 100644
--- a/net/rxrpc/ar-output.c
+++ b/net/rxrpc/ar-output.c
@@ -10,6 +10,7 @@
10 */ 10 */
11 11
12#include <linux/net.h> 12#include <linux/net.h>
13#include <linux/gfp.h>
13#include <linux/skbuff.h> 14#include <linux/skbuff.h>
14#include <linux/circ_buf.h> 15#include <linux/circ_buf.h>
15#include <net/sock.h> 16#include <net/sock.h>
diff --git a/net/rxrpc/ar-peer.c b/net/rxrpc/ar-peer.c
index edc026c1eb76..f0f85b0123f7 100644
--- a/net/rxrpc/ar-peer.c
+++ b/net/rxrpc/ar-peer.c
@@ -16,6 +16,7 @@
16#include <linux/in.h> 16#include <linux/in.h>
17#include <linux/in6.h> 17#include <linux/in6.h>
18#include <linux/icmp.h> 18#include <linux/icmp.h>
19#include <linux/slab.h>
19#include <net/sock.h> 20#include <net/sock.h>
20#include <net/af_rxrpc.h> 21#include <net/af_rxrpc.h>
21#include <net/ip.h> 22#include <net/ip.h>
diff --git a/net/rxrpc/ar-recvmsg.c b/net/rxrpc/ar-recvmsg.c
index a39bf97f8830..60c2b94e6b54 100644
--- a/net/rxrpc/ar-recvmsg.c
+++ b/net/rxrpc/ar-recvmsg.c
@@ -146,7 +146,7 @@ int rxrpc_recvmsg(struct kiocb *iocb, struct socket *sock,
146 memcpy(msg->msg_name, 146 memcpy(msg->msg_name,
147 &call->conn->trans->peer->srx, 147 &call->conn->trans->peer->srx,
148 sizeof(call->conn->trans->peer->srx)); 148 sizeof(call->conn->trans->peer->srx));
149 sock_recv_timestamp(msg, &rx->sk, skb); 149 sock_recv_ts_and_drops(msg, &rx->sk, skb);
150 } 150 }
151 151
152 /* receive the message */ 152 /* receive the message */
diff --git a/net/rxrpc/ar-transport.c b/net/rxrpc/ar-transport.c
index 0936e1acc30e..5e0226fe587e 100644
--- a/net/rxrpc/ar-transport.c
+++ b/net/rxrpc/ar-transport.c
@@ -12,6 +12,7 @@
12#include <linux/module.h> 12#include <linux/module.h>
13#include <linux/net.h> 13#include <linux/net.h>
14#include <linux/skbuff.h> 14#include <linux/skbuff.h>
15#include <linux/slab.h>
15#include <net/sock.h> 16#include <net/sock.h>
16#include <net/af_rxrpc.h> 17#include <net/af_rxrpc.h>
17#include "ar-internal.h" 18#include "ar-internal.h"
diff --git a/net/rxrpc/rxkad.c b/net/rxrpc/rxkad.c
index 713ac593e2e9..7635107726ce 100644
--- a/net/rxrpc/rxkad.c
+++ b/net/rxrpc/rxkad.c
@@ -16,6 +16,7 @@
16#include <linux/crypto.h> 16#include <linux/crypto.h>
17#include <linux/scatterlist.h> 17#include <linux/scatterlist.h>
18#include <linux/ctype.h> 18#include <linux/ctype.h>
19#include <linux/slab.h>
19#include <net/sock.h> 20#include <net/sock.h>
20#include <net/af_rxrpc.h> 21#include <net/af_rxrpc.h>
21#include <keys/rxrpc-type.h> 22#include <keys/rxrpc-type.h>
diff --git a/net/sched/Kconfig b/net/sched/Kconfig
index 929218a47620..2f691fb180d1 100644
--- a/net/sched/Kconfig
+++ b/net/sched/Kconfig
@@ -328,13 +328,16 @@ config NET_CLS_FLOW
328 module will be called cls_flow. 328 module will be called cls_flow.
329 329
330config NET_CLS_CGROUP 330config NET_CLS_CGROUP
331 bool "Control Group Classifier" 331 tristate "Control Group Classifier"
332 select NET_CLS 332 select NET_CLS
333 depends on CGROUPS 333 depends on CGROUPS
334 ---help--- 334 ---help---
335 Say Y here if you want to classify packets based on the control 335 Say Y here if you want to classify packets based on the control
336 cgroup of their process. 336 cgroup of their process.
337 337
338 To compile this code as a module, choose M here: the
339 module will be called cls_cgroup.
340
338config NET_EMATCH 341config NET_EMATCH
339 bool "Extended Matches" 342 bool "Extended Matches"
340 select NET_CLS 343 select NET_CLS
@@ -433,7 +436,7 @@ config NET_ACT_POLICE
433 module. 436 module.
434 437
435 To compile this code as a module, choose M here: the 438 To compile this code as a module, choose M here: the
436 module will be called police. 439 module will be called act_police.
437 440
438config NET_ACT_GACT 441config NET_ACT_GACT
439 tristate "Generic actions" 442 tristate "Generic actions"
@@ -443,7 +446,7 @@ config NET_ACT_GACT
443 accepting packets. 446 accepting packets.
444 447
445 To compile this code as a module, choose M here: the 448 To compile this code as a module, choose M here: the
446 module will be called gact. 449 module will be called act_gact.
447 450
448config GACT_PROB 451config GACT_PROB
449 bool "Probability support" 452 bool "Probability support"
@@ -459,7 +462,7 @@ config NET_ACT_MIRRED
459 other devices. 462 other devices.
460 463
461 To compile this code as a module, choose M here: the 464 To compile this code as a module, choose M here: the
462 module will be called mirred. 465 module will be called act_mirred.
463 466
464config NET_ACT_IPT 467config NET_ACT_IPT
465 tristate "IPtables targets" 468 tristate "IPtables targets"
@@ -469,7 +472,7 @@ config NET_ACT_IPT
469 classification. 472 classification.
470 473
471 To compile this code as a module, choose M here: the 474 To compile this code as a module, choose M here: the
472 module will be called ipt. 475 module will be called act_ipt.
473 476
474config NET_ACT_NAT 477config NET_ACT_NAT
475 tristate "Stateless NAT" 478 tristate "Stateless NAT"
@@ -479,7 +482,7 @@ config NET_ACT_NAT
479 netfilter for NAT unless you know what you are doing. 482 netfilter for NAT unless you know what you are doing.
480 483
481 To compile this code as a module, choose M here: the 484 To compile this code as a module, choose M here: the
482 module will be called nat. 485 module will be called act_nat.
483 486
484config NET_ACT_PEDIT 487config NET_ACT_PEDIT
485 tristate "Packet Editing" 488 tristate "Packet Editing"
@@ -488,7 +491,7 @@ config NET_ACT_PEDIT
488 Say Y here if you want to mangle the content of packets. 491 Say Y here if you want to mangle the content of packets.
489 492
490 To compile this code as a module, choose M here: the 493 To compile this code as a module, choose M here: the
491 module will be called pedit. 494 module will be called act_pedit.
492 495
493config NET_ACT_SIMP 496config NET_ACT_SIMP
494 tristate "Simple Example (Debug)" 497 tristate "Simple Example (Debug)"
@@ -502,7 +505,7 @@ config NET_ACT_SIMP
502 If unsure, say N. 505 If unsure, say N.
503 506
504 To compile this code as a module, choose M here: the 507 To compile this code as a module, choose M here: the
505 module will be called simple. 508 module will be called act_simple.
506 509
507config NET_ACT_SKBEDIT 510config NET_ACT_SKBEDIT
508 tristate "SKB Editing" 511 tristate "SKB Editing"
@@ -513,7 +516,7 @@ config NET_ACT_SKBEDIT
513 If unsure, say N. 516 If unsure, say N.
514 517
515 To compile this code as a module, choose M here: the 518 To compile this code as a module, choose M here: the
516 module will be called skbedit. 519 module will be called act_skbedit.
517 520
518config NET_CLS_IND 521config NET_CLS_IND
519 bool "Incoming device classification" 522 bool "Incoming device classification"
diff --git a/net/sched/act_api.c b/net/sched/act_api.c
index 2dfb3e7a040d..d8e0171d9a4b 100644
--- a/net/sched/act_api.c
+++ b/net/sched/act_api.c
@@ -15,6 +15,7 @@
15#include <linux/kernel.h> 15#include <linux/kernel.h>
16#include <linux/string.h> 16#include <linux/string.h>
17#include <linux/errno.h> 17#include <linux/errno.h>
18#include <linux/slab.h>
18#include <linux/skbuff.h> 19#include <linux/skbuff.h>
19#include <linux/init.h> 20#include <linux/init.h>
20#include <linux/kmod.h> 21#include <linux/kmod.h>
@@ -598,7 +599,7 @@ int tcf_action_copy_stats(struct sk_buff *skb, struct tc_action *a,
598 goto errout; 599 goto errout;
599 600
600 /* compat_mode being true specifies a call that is supposed 601 /* compat_mode being true specifies a call that is supposed
601 * to add additional backward compatiblity statistic TLVs. 602 * to add additional backward compatibility statistic TLVs.
602 */ 603 */
603 if (compat_mode) { 604 if (compat_mode) {
604 if (a->type == TCA_OLD_COMPAT) 605 if (a->type == TCA_OLD_COMPAT)
@@ -618,7 +619,8 @@ int tcf_action_copy_stats(struct sk_buff *skb, struct tc_action *a,
618 goto errout; 619 goto errout;
619 620
620 if (gnet_stats_copy_basic(&d, &h->tcf_bstats) < 0 || 621 if (gnet_stats_copy_basic(&d, &h->tcf_bstats) < 0 ||
621 gnet_stats_copy_rate_est(&d, &h->tcf_rate_est) < 0 || 622 gnet_stats_copy_rate_est(&d, &h->tcf_bstats,
623 &h->tcf_rate_est) < 0 ||
622 gnet_stats_copy_queue(&d, &h->tcf_qstats) < 0) 624 gnet_stats_copy_queue(&d, &h->tcf_qstats) < 0)
623 goto errout; 625 goto errout;
624 626
@@ -968,7 +970,7 @@ static int tc_ctl_action(struct sk_buff *skb, struct nlmsghdr *n, void *arg)
968 u32 pid = skb ? NETLINK_CB(skb).pid : 0; 970 u32 pid = skb ? NETLINK_CB(skb).pid : 0;
969 int ret = 0, ovr = 0; 971 int ret = 0, ovr = 0;
970 972
971 if (net != &init_net) 973 if (!net_eq(net, &init_net))
972 return -EINVAL; 974 return -EINVAL;
973 975
974 ret = nlmsg_parse(n, sizeof(struct tcamsg), tca, TCA_ACT_MAX, NULL); 976 ret = nlmsg_parse(n, sizeof(struct tcamsg), tca, TCA_ACT_MAX, NULL);
@@ -1051,7 +1053,7 @@ tc_dump_action(struct sk_buff *skb, struct netlink_callback *cb)
1051 struct tcamsg *t = (struct tcamsg *) NLMSG_DATA(cb->nlh); 1053 struct tcamsg *t = (struct tcamsg *) NLMSG_DATA(cb->nlh);
1052 struct nlattr *kind = find_dump_kind(cb->nlh); 1054 struct nlattr *kind = find_dump_kind(cb->nlh);
1053 1055
1054 if (net != &init_net) 1056 if (!net_eq(net, &init_net))
1055 return 0; 1057 return 0;
1056 1058
1057 if (kind == NULL) { 1059 if (kind == NULL) {
diff --git a/net/sched/act_ipt.c b/net/sched/act_ipt.c
index 082c520b0def..da27a170b6b7 100644
--- a/net/sched/act_ipt.c
+++ b/net/sched/act_ipt.c
@@ -19,6 +19,7 @@
19#include <linux/rtnetlink.h> 19#include <linux/rtnetlink.h>
20#include <linux/module.h> 20#include <linux/module.h>
21#include <linux/init.h> 21#include <linux/init.h>
22#include <linux/slab.h>
22#include <net/netlink.h> 23#include <net/netlink.h>
23#include <net/pkt_sched.h> 24#include <net/pkt_sched.h>
24#include <linux/tc_act/tc_ipt.h> 25#include <linux/tc_act/tc_ipt.h>
diff --git a/net/sched/act_mirred.c b/net/sched/act_mirred.c
index b9aaab4e0354..c046682054eb 100644
--- a/net/sched/act_mirred.c
+++ b/net/sched/act_mirred.c
@@ -20,6 +20,7 @@
20#include <linux/rtnetlink.h> 20#include <linux/rtnetlink.h>
21#include <linux/module.h> 21#include <linux/module.h>
22#include <linux/init.h> 22#include <linux/init.h>
23#include <linux/gfp.h>
23#include <net/net_namespace.h> 24#include <net/net_namespace.h>
24#include <net/netlink.h> 25#include <net/netlink.h>
25#include <net/pkt_sched.h> 26#include <net/pkt_sched.h>
@@ -65,48 +66,53 @@ static int tcf_mirred_init(struct nlattr *nla, struct nlattr *est,
65 struct tc_mirred *parm; 66 struct tc_mirred *parm;
66 struct tcf_mirred *m; 67 struct tcf_mirred *m;
67 struct tcf_common *pc; 68 struct tcf_common *pc;
68 struct net_device *dev = NULL; 69 struct net_device *dev;
69 int ret = 0, err; 70 int ret, ok_push = 0;
70 int ok_push = 0;
71 71
72 if (nla == NULL) 72 if (nla == NULL)
73 return -EINVAL; 73 return -EINVAL;
74 74 ret = nla_parse_nested(tb, TCA_MIRRED_MAX, nla, mirred_policy);
75 err = nla_parse_nested(tb, TCA_MIRRED_MAX, nla, mirred_policy); 75 if (ret < 0)
76 if (err < 0) 76 return ret;
77 return err;
78
79 if (tb[TCA_MIRRED_PARMS] == NULL) 77 if (tb[TCA_MIRRED_PARMS] == NULL)
80 return -EINVAL; 78 return -EINVAL;
81 parm = nla_data(tb[TCA_MIRRED_PARMS]); 79 parm = nla_data(tb[TCA_MIRRED_PARMS]);
82 80 switch (parm->eaction) {
81 case TCA_EGRESS_MIRROR:
82 case TCA_EGRESS_REDIR:
83 break;
84 default:
85 return -EINVAL;
86 }
83 if (parm->ifindex) { 87 if (parm->ifindex) {
84 dev = __dev_get_by_index(&init_net, parm->ifindex); 88 dev = __dev_get_by_index(&init_net, parm->ifindex);
85 if (dev == NULL) 89 if (dev == NULL)
86 return -ENODEV; 90 return -ENODEV;
87 switch (dev->type) { 91 switch (dev->type) {
88 case ARPHRD_TUNNEL: 92 case ARPHRD_TUNNEL:
89 case ARPHRD_TUNNEL6: 93 case ARPHRD_TUNNEL6:
90 case ARPHRD_SIT: 94 case ARPHRD_SIT:
91 case ARPHRD_IPGRE: 95 case ARPHRD_IPGRE:
92 case ARPHRD_VOID: 96 case ARPHRD_VOID:
93 case ARPHRD_NONE: 97 case ARPHRD_NONE:
94 ok_push = 0; 98 ok_push = 0;
95 break; 99 break;
96 default: 100 default:
97 ok_push = 1; 101 ok_push = 1;
98 break; 102 break;
99 } 103 }
104 } else {
105 dev = NULL;
100 } 106 }
101 107
102 pc = tcf_hash_check(parm->index, a, bind, &mirred_hash_info); 108 pc = tcf_hash_check(parm->index, a, bind, &mirred_hash_info);
103 if (!pc) { 109 if (!pc) {
104 if (!parm->ifindex) 110 if (dev == NULL)
105 return -EINVAL; 111 return -EINVAL;
106 pc = tcf_hash_create(parm->index, est, a, sizeof(*m), bind, 112 pc = tcf_hash_create(parm->index, est, a, sizeof(*m), bind,
107 &mirred_idx_gen, &mirred_hash_info); 113 &mirred_idx_gen, &mirred_hash_info);
108 if (IS_ERR(pc)) 114 if (IS_ERR(pc))
109 return PTR_ERR(pc); 115 return PTR_ERR(pc);
110 ret = ACT_P_CREATED; 116 ret = ACT_P_CREATED;
111 } else { 117 } else {
112 if (!ovr) { 118 if (!ovr) {
@@ -119,12 +125,12 @@ static int tcf_mirred_init(struct nlattr *nla, struct nlattr *est,
119 spin_lock_bh(&m->tcf_lock); 125 spin_lock_bh(&m->tcf_lock);
120 m->tcf_action = parm->action; 126 m->tcf_action = parm->action;
121 m->tcfm_eaction = parm->eaction; 127 m->tcfm_eaction = parm->eaction;
122 if (parm->ifindex) { 128 if (dev != NULL) {
123 m->tcfm_ifindex = parm->ifindex; 129 m->tcfm_ifindex = parm->ifindex;
124 if (ret != ACT_P_CREATED) 130 if (ret != ACT_P_CREATED)
125 dev_put(m->tcfm_dev); 131 dev_put(m->tcfm_dev);
126 m->tcfm_dev = dev;
127 dev_hold(dev); 132 dev_hold(dev);
133 m->tcfm_dev = dev;
128 m->tcfm_ok_push = ok_push; 134 m->tcfm_ok_push = ok_push;
129 } 135 }
130 spin_unlock_bh(&m->tcf_lock); 136 spin_unlock_bh(&m->tcf_lock);
@@ -148,57 +154,57 @@ static int tcf_mirred(struct sk_buff *skb, struct tc_action *a,
148{ 154{
149 struct tcf_mirred *m = a->priv; 155 struct tcf_mirred *m = a->priv;
150 struct net_device *dev; 156 struct net_device *dev;
151 struct sk_buff *skb2 = NULL; 157 struct sk_buff *skb2;
152 u32 at = G_TC_AT(skb->tc_verd); 158 u32 at;
159 int retval, err = 1;
153 160
154 spin_lock(&m->tcf_lock); 161 spin_lock(&m->tcf_lock);
155
156 dev = m->tcfm_dev;
157 m->tcf_tm.lastuse = jiffies; 162 m->tcf_tm.lastuse = jiffies;
158 163
159 if (!(dev->flags&IFF_UP) ) { 164 dev = m->tcfm_dev;
165 if (!(dev->flags & IFF_UP)) {
160 if (net_ratelimit()) 166 if (net_ratelimit())
161 printk("mirred to Houston: device %s is gone!\n", 167 printk("mirred to Houston: device %s is gone!\n",
162 dev->name); 168 dev->name);
163bad_mirred: 169 goto out;
164 if (skb2 != NULL)
165 kfree_skb(skb2);
166 m->tcf_qstats.overlimits++;
167 m->tcf_bstats.bytes += qdisc_pkt_len(skb);
168 m->tcf_bstats.packets++;
169 spin_unlock(&m->tcf_lock);
170 /* should we be asking for packet to be dropped?
171 * may make sense for redirect case only
172 */
173 return TC_ACT_SHOT;
174 } 170 }
175 171
176 skb2 = skb_act_clone(skb, GFP_ATOMIC); 172 skb2 = skb_act_clone(skb, GFP_ATOMIC);
177 if (skb2 == NULL) 173 if (skb2 == NULL)
178 goto bad_mirred; 174 goto out;
179 if (m->tcfm_eaction != TCA_EGRESS_MIRROR &&
180 m->tcfm_eaction != TCA_EGRESS_REDIR) {
181 if (net_ratelimit())
182 printk("tcf_mirred unknown action %d\n",
183 m->tcfm_eaction);
184 goto bad_mirred;
185 }
186 175
187 m->tcf_bstats.bytes += qdisc_pkt_len(skb2); 176 m->tcf_bstats.bytes += qdisc_pkt_len(skb2);
188 m->tcf_bstats.packets++; 177 m->tcf_bstats.packets++;
189 if (!(at & AT_EGRESS)) 178 at = G_TC_AT(skb->tc_verd);
179 if (!(at & AT_EGRESS)) {
190 if (m->tcfm_ok_push) 180 if (m->tcfm_ok_push)
191 skb_push(skb2, skb2->dev->hard_header_len); 181 skb_push(skb2, skb2->dev->hard_header_len);
182 }
192 183
193 /* mirror is always swallowed */ 184 /* mirror is always swallowed */
194 if (m->tcfm_eaction != TCA_EGRESS_MIRROR) 185 if (m->tcfm_eaction != TCA_EGRESS_MIRROR)
195 skb2->tc_verd = SET_TC_FROM(skb2->tc_verd, at); 186 skb2->tc_verd = SET_TC_FROM(skb2->tc_verd, at);
196 187
197 skb2->dev = dev; 188 skb2->dev = dev;
198 skb2->iif = skb->dev->ifindex; 189 skb2->skb_iif = skb->dev->ifindex;
199 dev_queue_xmit(skb2); 190 dev_queue_xmit(skb2);
191 err = 0;
192
193out:
194 if (err) {
195 m->tcf_qstats.overlimits++;
196 m->tcf_bstats.bytes += qdisc_pkt_len(skb);
197 m->tcf_bstats.packets++;
198 /* should we be asking for packet to be dropped?
199 * may make sense for redirect case only
200 */
201 retval = TC_ACT_SHOT;
202 } else {
203 retval = m->tcf_action;
204 }
200 spin_unlock(&m->tcf_lock); 205 spin_unlock(&m->tcf_lock);
201 return m->tcf_action; 206
207 return retval;
202} 208}
203 209
204static int tcf_mirred_dump(struct sk_buff *skb, struct tc_action *a, int bind, int ref) 210static int tcf_mirred_dump(struct sk_buff *skb, struct tc_action *a, int bind, int ref)
diff --git a/net/sched/act_pedit.c b/net/sched/act_pedit.c
index 6b0359a500e6..b7dcfedc802e 100644
--- a/net/sched/act_pedit.c
+++ b/net/sched/act_pedit.c
@@ -17,6 +17,7 @@
17#include <linux/rtnetlink.h> 17#include <linux/rtnetlink.h>
18#include <linux/module.h> 18#include <linux/module.h>
19#include <linux/init.h> 19#include <linux/init.h>
20#include <linux/slab.h>
20#include <net/netlink.h> 21#include <net/netlink.h>
21#include <net/pkt_sched.h> 22#include <net/pkt_sched.h>
22#include <linux/tc_act/tc_pedit.h> 23#include <linux/tc_act/tc_pedit.h>
diff --git a/net/sched/act_police.c b/net/sched/act_police.c
index 723964c3ee4f..654f73dff7c1 100644
--- a/net/sched/act_police.c
+++ b/net/sched/act_police.c
@@ -18,6 +18,7 @@
18#include <linux/skbuff.h> 18#include <linux/skbuff.h>
19#include <linux/rtnetlink.h> 19#include <linux/rtnetlink.h>
20#include <linux/init.h> 20#include <linux/init.h>
21#include <linux/slab.h>
21#include <net/act_api.h> 22#include <net/act_api.h>
22#include <net/netlink.h> 23#include <net/netlink.h>
23 24
diff --git a/net/sched/act_simple.c b/net/sched/act_simple.c
index 8daa1ebc7413..622ca809c15c 100644
--- a/net/sched/act_simple.c
+++ b/net/sched/act_simple.c
@@ -11,6 +11,7 @@
11 */ 11 */
12 12
13#include <linux/module.h> 13#include <linux/module.h>
14#include <linux/slab.h>
14#include <linux/init.h> 15#include <linux/init.h>
15#include <linux/kernel.h> 16#include <linux/kernel.h>
16#include <linux/skbuff.h> 17#include <linux/skbuff.h>
diff --git a/net/sched/act_skbedit.c b/net/sched/act_skbedit.c
index 4ab916b8074b..e9607fe55b58 100644
--- a/net/sched/act_skbedit.c
+++ b/net/sched/act_skbedit.c
@@ -54,6 +54,8 @@ static int tcf_skbedit(struct sk_buff *skb, struct tc_action *a,
54 if (d->flags & SKBEDIT_F_QUEUE_MAPPING && 54 if (d->flags & SKBEDIT_F_QUEUE_MAPPING &&
55 skb->dev->real_num_tx_queues > d->queue_mapping) 55 skb->dev->real_num_tx_queues > d->queue_mapping)
56 skb_set_queue_mapping(skb, d->queue_mapping); 56 skb_set_queue_mapping(skb, d->queue_mapping);
57 if (d->flags & SKBEDIT_F_MARK)
58 skb->mark = d->mark;
57 59
58 spin_unlock(&d->tcf_lock); 60 spin_unlock(&d->tcf_lock);
59 return d->tcf_action; 61 return d->tcf_action;
@@ -63,6 +65,7 @@ static const struct nla_policy skbedit_policy[TCA_SKBEDIT_MAX + 1] = {
63 [TCA_SKBEDIT_PARMS] = { .len = sizeof(struct tc_skbedit) }, 65 [TCA_SKBEDIT_PARMS] = { .len = sizeof(struct tc_skbedit) },
64 [TCA_SKBEDIT_PRIORITY] = { .len = sizeof(u32) }, 66 [TCA_SKBEDIT_PRIORITY] = { .len = sizeof(u32) },
65 [TCA_SKBEDIT_QUEUE_MAPPING] = { .len = sizeof(u16) }, 67 [TCA_SKBEDIT_QUEUE_MAPPING] = { .len = sizeof(u16) },
68 [TCA_SKBEDIT_MARK] = { .len = sizeof(u32) },
66}; 69};
67 70
68static int tcf_skbedit_init(struct nlattr *nla, struct nlattr *est, 71static int tcf_skbedit_init(struct nlattr *nla, struct nlattr *est,
@@ -72,7 +75,7 @@ static int tcf_skbedit_init(struct nlattr *nla, struct nlattr *est,
72 struct tc_skbedit *parm; 75 struct tc_skbedit *parm;
73 struct tcf_skbedit *d; 76 struct tcf_skbedit *d;
74 struct tcf_common *pc; 77 struct tcf_common *pc;
75 u32 flags = 0, *priority = NULL; 78 u32 flags = 0, *priority = NULL, *mark = NULL;
76 u16 *queue_mapping = NULL; 79 u16 *queue_mapping = NULL;
77 int ret = 0, err; 80 int ret = 0, err;
78 81
@@ -95,6 +98,12 @@ static int tcf_skbedit_init(struct nlattr *nla, struct nlattr *est,
95 flags |= SKBEDIT_F_QUEUE_MAPPING; 98 flags |= SKBEDIT_F_QUEUE_MAPPING;
96 queue_mapping = nla_data(tb[TCA_SKBEDIT_QUEUE_MAPPING]); 99 queue_mapping = nla_data(tb[TCA_SKBEDIT_QUEUE_MAPPING]);
97 } 100 }
101
102 if (tb[TCA_SKBEDIT_MARK] != NULL) {
103 flags |= SKBEDIT_F_MARK;
104 mark = nla_data(tb[TCA_SKBEDIT_MARK]);
105 }
106
98 if (!flags) 107 if (!flags)
99 return -EINVAL; 108 return -EINVAL;
100 109
@@ -124,6 +133,9 @@ static int tcf_skbedit_init(struct nlattr *nla, struct nlattr *est,
124 d->priority = *priority; 133 d->priority = *priority;
125 if (flags & SKBEDIT_F_QUEUE_MAPPING) 134 if (flags & SKBEDIT_F_QUEUE_MAPPING)
126 d->queue_mapping = *queue_mapping; 135 d->queue_mapping = *queue_mapping;
136 if (flags & SKBEDIT_F_MARK)
137 d->mark = *mark;
138
127 d->tcf_action = parm->action; 139 d->tcf_action = parm->action;
128 140
129 spin_unlock_bh(&d->tcf_lock); 141 spin_unlock_bh(&d->tcf_lock);
@@ -161,6 +173,9 @@ static inline int tcf_skbedit_dump(struct sk_buff *skb, struct tc_action *a,
161 if (d->flags & SKBEDIT_F_QUEUE_MAPPING) 173 if (d->flags & SKBEDIT_F_QUEUE_MAPPING)
162 NLA_PUT(skb, TCA_SKBEDIT_QUEUE_MAPPING, 174 NLA_PUT(skb, TCA_SKBEDIT_QUEUE_MAPPING,
163 sizeof(d->queue_mapping), &d->queue_mapping); 175 sizeof(d->queue_mapping), &d->queue_mapping);
176 if (d->flags & SKBEDIT_F_MARK)
177 NLA_PUT(skb, TCA_SKBEDIT_MARK, sizeof(d->mark),
178 &d->mark);
164 t.install = jiffies_to_clock_t(jiffies - d->tcf_tm.install); 179 t.install = jiffies_to_clock_t(jiffies - d->tcf_tm.install);
165 t.lastuse = jiffies_to_clock_t(jiffies - d->tcf_tm.lastuse); 180 t.lastuse = jiffies_to_clock_t(jiffies - d->tcf_tm.lastuse);
166 t.expires = jiffies_to_clock_t(d->tcf_tm.expires); 181 t.expires = jiffies_to_clock_t(d->tcf_tm.expires);
diff --git a/net/sched/cls_api.c b/net/sched/cls_api.c
index 7cf6c0fbc7a6..f082b27ff46d 100644
--- a/net/sched/cls_api.c
+++ b/net/sched/cls_api.c
@@ -24,6 +24,7 @@
24#include <linux/kmod.h> 24#include <linux/kmod.h>
25#include <linux/netlink.h> 25#include <linux/netlink.h>
26#include <linux/err.h> 26#include <linux/err.h>
27#include <linux/slab.h>
27#include <net/net_namespace.h> 28#include <net/net_namespace.h>
28#include <net/sock.h> 29#include <net/sock.h>
29#include <net/netlink.h> 30#include <net/netlink.h>
@@ -137,7 +138,7 @@ static int tc_ctl_tfilter(struct sk_buff *skb, struct nlmsghdr *n, void *arg)
137 int err; 138 int err;
138 int tp_created = 0; 139 int tp_created = 0;
139 140
140 if (net != &init_net) 141 if (!net_eq(net, &init_net))
141 return -EINVAL; 142 return -EINVAL;
142 143
143replay: 144replay:
@@ -404,6 +405,7 @@ static int tcf_node_dump(struct tcf_proto *tp, unsigned long n,
404 a->cb->nlh->nlmsg_seq, NLM_F_MULTI, RTM_NEWTFILTER); 405 a->cb->nlh->nlmsg_seq, NLM_F_MULTI, RTM_NEWTFILTER);
405} 406}
406 407
408/* called with RTNL */
407static int tc_dump_tfilter(struct sk_buff *skb, struct netlink_callback *cb) 409static int tc_dump_tfilter(struct sk_buff *skb, struct netlink_callback *cb)
408{ 410{
409 struct net *net = sock_net(skb->sk); 411 struct net *net = sock_net(skb->sk);
@@ -417,12 +419,12 @@ static int tc_dump_tfilter(struct sk_buff *skb, struct netlink_callback *cb)
417 const struct Qdisc_class_ops *cops; 419 const struct Qdisc_class_ops *cops;
418 struct tcf_dump_args arg; 420 struct tcf_dump_args arg;
419 421
420 if (net != &init_net) 422 if (!net_eq(net, &init_net))
421 return 0; 423 return 0;
422 424
423 if (cb->nlh->nlmsg_len < NLMSG_LENGTH(sizeof(*tcm))) 425 if (cb->nlh->nlmsg_len < NLMSG_LENGTH(sizeof(*tcm)))
424 return skb->len; 426 return skb->len;
425 if ((dev = dev_get_by_index(&init_net, tcm->tcm_ifindex)) == NULL) 427 if ((dev = __dev_get_by_index(&init_net, tcm->tcm_ifindex)) == NULL)
426 return skb->len; 428 return skb->len;
427 429
428 if (!tcm->tcm_parent) 430 if (!tcm->tcm_parent)
@@ -484,7 +486,6 @@ errout:
484 if (cl) 486 if (cl)
485 cops->put(q, cl); 487 cops->put(q, cl);
486out: 488out:
487 dev_put(dev);
488 return skb->len; 489 return skb->len;
489} 490}
490 491
diff --git a/net/sched/cls_basic.c b/net/sched/cls_basic.c
index 4e2bda854119..efd4f95fd050 100644
--- a/net/sched/cls_basic.c
+++ b/net/sched/cls_basic.c
@@ -10,6 +10,7 @@
10 */ 10 */
11 11
12#include <linux/module.h> 12#include <linux/module.h>
13#include <linux/slab.h>
13#include <linux/types.h> 14#include <linux/types.h>
14#include <linux/kernel.h> 15#include <linux/kernel.h>
15#include <linux/string.h> 16#include <linux/string.h>
diff --git a/net/sched/cls_cgroup.c b/net/sched/cls_cgroup.c
index e4877ca6727c..221180384fd7 100644
--- a/net/sched/cls_cgroup.c
+++ b/net/sched/cls_cgroup.c
@@ -10,6 +10,7 @@
10 */ 10 */
11 11
12#include <linux/module.h> 12#include <linux/module.h>
13#include <linux/slab.h>
13#include <linux/types.h> 14#include <linux/types.h>
14#include <linux/string.h> 15#include <linux/string.h>
15#include <linux/errno.h> 16#include <linux/errno.h>
@@ -24,6 +25,25 @@ struct cgroup_cls_state
24 u32 classid; 25 u32 classid;
25}; 26};
26 27
28static struct cgroup_subsys_state *cgrp_create(struct cgroup_subsys *ss,
29 struct cgroup *cgrp);
30static void cgrp_destroy(struct cgroup_subsys *ss, struct cgroup *cgrp);
31static int cgrp_populate(struct cgroup_subsys *ss, struct cgroup *cgrp);
32
33struct cgroup_subsys net_cls_subsys = {
34 .name = "net_cls",
35 .create = cgrp_create,
36 .destroy = cgrp_destroy,
37 .populate = cgrp_populate,
38#ifdef CONFIG_NET_CLS_CGROUP
39 .subsys_id = net_cls_subsys_id,
40#else
41#define net_cls_subsys_id net_cls_subsys.subsys_id
42#endif
43 .module = THIS_MODULE,
44};
45
46
27static inline struct cgroup_cls_state *cgrp_cls_state(struct cgroup *cgrp) 47static inline struct cgroup_cls_state *cgrp_cls_state(struct cgroup *cgrp)
28{ 48{
29 return container_of(cgroup_subsys_state(cgrp, net_cls_subsys_id), 49 return container_of(cgroup_subsys_state(cgrp, net_cls_subsys_id),
@@ -79,14 +99,6 @@ static int cgrp_populate(struct cgroup_subsys *ss, struct cgroup *cgrp)
79 return cgroup_add_files(cgrp, ss, ss_files, ARRAY_SIZE(ss_files)); 99 return cgroup_add_files(cgrp, ss, ss_files, ARRAY_SIZE(ss_files));
80} 100}
81 101
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 102struct cls_cgroup_head
91{ 103{
92 u32 handle; 104 u32 handle;
@@ -277,12 +289,19 @@ static struct tcf_proto_ops cls_cgroup_ops __read_mostly = {
277 289
278static int __init init_cgroup_cls(void) 290static int __init init_cgroup_cls(void)
279{ 291{
280 return register_tcf_proto_ops(&cls_cgroup_ops); 292 int ret = register_tcf_proto_ops(&cls_cgroup_ops);
293 if (ret)
294 return ret;
295 ret = cgroup_load_subsys(&net_cls_subsys);
296 if (ret)
297 unregister_tcf_proto_ops(&cls_cgroup_ops);
298 return ret;
281} 299}
282 300
283static void __exit exit_cgroup_cls(void) 301static void __exit exit_cgroup_cls(void)
284{ 302{
285 unregister_tcf_proto_ops(&cls_cgroup_ops); 303 unregister_tcf_proto_ops(&cls_cgroup_ops);
304 cgroup_unload_subsys(&net_cls_subsys);
286} 305}
287 306
288module_init(init_cgroup_cls); 307module_init(init_cgroup_cls);
diff --git a/net/sched/cls_flow.c b/net/sched/cls_flow.c
index 9402a7fd3785..6ed61b10e002 100644
--- a/net/sched/cls_flow.c
+++ b/net/sched/cls_flow.c
@@ -20,6 +20,7 @@
20#include <linux/ip.h> 20#include <linux/ip.h>
21#include <linux/ipv6.h> 21#include <linux/ipv6.h>
22#include <linux/if_vlan.h> 22#include <linux/if_vlan.h>
23#include <linux/slab.h>
23 24
24#include <net/pkt_cls.h> 25#include <net/pkt_cls.h>
25#include <net/ip.h> 26#include <net/ip.h>
@@ -171,7 +172,7 @@ static u32 flow_get_proto_dst(const struct sk_buff *skb)
171 172
172static u32 flow_get_iif(const struct sk_buff *skb) 173static u32 flow_get_iif(const struct sk_buff *skb)
173{ 174{
174 return skb->iif; 175 return skb->skb_iif;
175} 176}
176 177
177static u32 flow_get_priority(const struct sk_buff *skb) 178static u32 flow_get_priority(const struct sk_buff *skb)
diff --git a/net/sched/cls_fw.c b/net/sched/cls_fw.c
index 6d6e87585fb1..93b0a7b6f9b4 100644
--- a/net/sched/cls_fw.c
+++ b/net/sched/cls_fw.c
@@ -19,6 +19,7 @@
19 */ 19 */
20 20
21#include <linux/module.h> 21#include <linux/module.h>
22#include <linux/slab.h>
22#include <linux/types.h> 23#include <linux/types.h>
23#include <linux/kernel.h> 24#include <linux/kernel.h>
24#include <linux/string.h> 25#include <linux/string.h>
diff --git a/net/sched/cls_route.c b/net/sched/cls_route.c
index dd872d5383ef..694dcd85dec8 100644
--- a/net/sched/cls_route.c
+++ b/net/sched/cls_route.c
@@ -10,6 +10,7 @@
10 */ 10 */
11 11
12#include <linux/module.h> 12#include <linux/module.h>
13#include <linux/slab.h>
13#include <linux/types.h> 14#include <linux/types.h>
14#include <linux/kernel.h> 15#include <linux/kernel.h>
15#include <linux/string.h> 16#include <linux/string.h>
diff --git a/net/sched/cls_rsvp.h b/net/sched/cls_rsvp.h
index 7034ea4530e5..dd9414e44200 100644
--- a/net/sched/cls_rsvp.h
+++ b/net/sched/cls_rsvp.h
@@ -170,21 +170,23 @@ restart:
170 for (s = sht[h1]; s; s = s->next) { 170 for (s = sht[h1]; s; s = s->next) {
171 if (dst[RSVP_DST_LEN-1] == s->dst[RSVP_DST_LEN-1] && 171 if (dst[RSVP_DST_LEN-1] == s->dst[RSVP_DST_LEN-1] &&
172 protocol == s->protocol && 172 protocol == s->protocol &&
173 !(s->dpi.mask & (*(u32*)(xprt+s->dpi.offset)^s->dpi.key)) 173 !(s->dpi.mask &
174 (*(u32*)(xprt+s->dpi.offset)^s->dpi.key)) &&
174#if RSVP_DST_LEN == 4 175#if RSVP_DST_LEN == 4
175 && dst[0] == s->dst[0] 176 dst[0] == s->dst[0] &&
176 && dst[1] == s->dst[1] 177 dst[1] == s->dst[1] &&
177 && dst[2] == s->dst[2] 178 dst[2] == s->dst[2] &&
178#endif 179#endif
179 && tunnelid == s->tunnelid) { 180 tunnelid == s->tunnelid) {
180 181
181 for (f = s->ht[h2]; f; f = f->next) { 182 for (f = s->ht[h2]; f; f = f->next) {
182 if (src[RSVP_DST_LEN-1] == f->src[RSVP_DST_LEN-1] && 183 if (src[RSVP_DST_LEN-1] == f->src[RSVP_DST_LEN-1] &&
183 !(f->spi.mask & (*(u32*)(xprt+f->spi.offset)^f->spi.key)) 184 !(f->spi.mask & (*(u32*)(xprt+f->spi.offset)^f->spi.key))
184#if RSVP_DST_LEN == 4 185#if RSVP_DST_LEN == 4
185 && src[0] == f->src[0] 186 &&
186 && src[1] == f->src[1] 187 src[0] == f->src[0] &&
187 && src[2] == f->src[2] 188 src[1] == f->src[1] &&
189 src[2] == f->src[2]
188#endif 190#endif
189 ) { 191 ) {
190 *res = f->res; 192 *res = f->res;
@@ -493,13 +495,13 @@ static int rsvp_change(struct tcf_proto *tp, unsigned long base,
493 for (sp = &data->ht[h1]; (s=*sp) != NULL; sp = &s->next) { 495 for (sp = &data->ht[h1]; (s=*sp) != NULL; sp = &s->next) {
494 if (dst[RSVP_DST_LEN-1] == s->dst[RSVP_DST_LEN-1] && 496 if (dst[RSVP_DST_LEN-1] == s->dst[RSVP_DST_LEN-1] &&
495 pinfo && pinfo->protocol == s->protocol && 497 pinfo && pinfo->protocol == s->protocol &&
496 memcmp(&pinfo->dpi, &s->dpi, sizeof(s->dpi)) == 0 498 memcmp(&pinfo->dpi, &s->dpi, sizeof(s->dpi)) == 0 &&
497#if RSVP_DST_LEN == 4 499#if RSVP_DST_LEN == 4
498 && dst[0] == s->dst[0] 500 dst[0] == s->dst[0] &&
499 && dst[1] == s->dst[1] 501 dst[1] == s->dst[1] &&
500 && dst[2] == s->dst[2] 502 dst[2] == s->dst[2] &&
501#endif 503#endif
502 && pinfo->tunnelid == s->tunnelid) { 504 pinfo->tunnelid == s->tunnelid) {
503 505
504insert: 506insert:
505 /* OK, we found appropriate session */ 507 /* OK, we found appropriate session */
diff --git a/net/sched/cls_tcindex.c b/net/sched/cls_tcindex.c
index e806f2314b5e..20ef330bb918 100644
--- a/net/sched/cls_tcindex.c
+++ b/net/sched/cls_tcindex.c
@@ -9,6 +9,7 @@
9#include <linux/kernel.h> 9#include <linux/kernel.h>
10#include <linux/skbuff.h> 10#include <linux/skbuff.h>
11#include <linux/errno.h> 11#include <linux/errno.h>
12#include <linux/slab.h>
12#include <net/act_api.h> 13#include <net/act_api.h>
13#include <net/netlink.h> 14#include <net/netlink.h>
14#include <net/pkt_cls.h> 15#include <net/pkt_cls.h>
diff --git a/net/sched/cls_u32.c b/net/sched/cls_u32.c
index 07372f60bee3..17c5dfc67320 100644
--- a/net/sched/cls_u32.c
+++ b/net/sched/cls_u32.c
@@ -31,6 +31,7 @@
31 */ 31 */
32 32
33#include <linux/module.h> 33#include <linux/module.h>
34#include <linux/slab.h>
34#include <linux/types.h> 35#include <linux/types.h>
35#include <linux/kernel.h> 36#include <linux/kernel.h>
36#include <linux/string.h> 37#include <linux/string.h>
diff --git a/net/sched/em_meta.c b/net/sched/em_meta.c
index 18d85d259104..3bcac8aa333c 100644
--- a/net/sched/em_meta.c
+++ b/net/sched/em_meta.c
@@ -58,6 +58,7 @@
58 * only available if that subsystem is enabled in the kernel. 58 * only available if that subsystem is enabled in the kernel.
59 */ 59 */
60 60
61#include <linux/slab.h>
61#include <linux/module.h> 62#include <linux/module.h>
62#include <linux/types.h> 63#include <linux/types.h>
63#include <linux/kernel.h> 64#include <linux/kernel.h>
@@ -303,17 +304,18 @@ META_COLLECTOR(var_sk_bound_if)
303{ 304{
304 SKIP_NONLOCAL(skb); 305 SKIP_NONLOCAL(skb);
305 306
306 if (skb->sk->sk_bound_dev_if == 0) { 307 if (skb->sk->sk_bound_dev_if == 0) {
307 dst->value = (unsigned long) "any"; 308 dst->value = (unsigned long) "any";
308 dst->len = 3; 309 dst->len = 3;
309 } else { 310 } else {
310 struct net_device *dev; 311 struct net_device *dev;
311 312
312 dev = dev_get_by_index(&init_net, skb->sk->sk_bound_dev_if); 313 rcu_read_lock();
314 dev = dev_get_by_index_rcu(sock_net(skb->sk),
315 skb->sk->sk_bound_dev_if);
313 *err = var_dev(dev, dst); 316 *err = var_dev(dev, dst);
314 if (dev) 317 rcu_read_unlock();
315 dev_put(dev); 318 }
316 }
317} 319}
318 320
319META_COLLECTOR(int_sk_refcnt) 321META_COLLECTOR(int_sk_refcnt)
diff --git a/net/sched/em_nbyte.c b/net/sched/em_nbyte.c
index 370a1b2ea317..1a4176aee6e5 100644
--- a/net/sched/em_nbyte.c
+++ b/net/sched/em_nbyte.c
@@ -9,6 +9,7 @@
9 * Authors: Thomas Graf <tgraf@suug.ch> 9 * Authors: Thomas Graf <tgraf@suug.ch>
10 */ 10 */
11 11
12#include <linux/gfp.h>
12#include <linux/module.h> 13#include <linux/module.h>
13#include <linux/types.h> 14#include <linux/types.h>
14#include <linux/kernel.h> 15#include <linux/kernel.h>
diff --git a/net/sched/em_text.c b/net/sched/em_text.c
index 853c5ead87fd..763253257411 100644
--- a/net/sched/em_text.c
+++ b/net/sched/em_text.c
@@ -9,6 +9,7 @@
9 * Authors: Thomas Graf <tgraf@suug.ch> 9 * Authors: Thomas Graf <tgraf@suug.ch>
10 */ 10 */
11 11
12#include <linux/slab.h>
12#include <linux/module.h> 13#include <linux/module.h>
13#include <linux/types.h> 14#include <linux/types.h>
14#include <linux/kernel.h> 15#include <linux/kernel.h>
diff --git a/net/sched/ematch.c b/net/sched/ematch.c
index aab59409728b..e782bdeedc58 100644
--- a/net/sched/ematch.c
+++ b/net/sched/ematch.c
@@ -82,6 +82,7 @@
82 */ 82 */
83 83
84#include <linux/module.h> 84#include <linux/module.h>
85#include <linux/slab.h>
85#include <linux/types.h> 86#include <linux/types.h>
86#include <linux/kernel.h> 87#include <linux/kernel.h>
87#include <linux/errno.h> 88#include <linux/errno.h>
diff --git a/net/sched/sch_api.c b/net/sched/sch_api.c
index 903e4188b6ca..145268ca57cf 100644
--- a/net/sched/sch_api.c
+++ b/net/sched/sch_api.c
@@ -28,6 +28,7 @@
28#include <linux/list.h> 28#include <linux/list.h>
29#include <linux/hrtimer.h> 29#include <linux/hrtimer.h>
30#include <linux/lockdep.h> 30#include <linux/lockdep.h>
31#include <linux/slab.h>
31 32
32#include <net/net_namespace.h> 33#include <net/net_namespace.h>
33#include <net/sock.h> 34#include <net/sock.h>
@@ -947,7 +948,7 @@ static int tc_get_qdisc(struct sk_buff *skb, struct nlmsghdr *n, void *arg)
947 struct Qdisc *p = NULL; 948 struct Qdisc *p = NULL;
948 int err; 949 int err;
949 950
950 if (net != &init_net) 951 if (!net_eq(net, &init_net))
951 return -EINVAL; 952 return -EINVAL;
952 953
953 if ((dev = __dev_get_by_index(&init_net, tcm->tcm_ifindex)) == NULL) 954 if ((dev = __dev_get_by_index(&init_net, tcm->tcm_ifindex)) == NULL)
@@ -1009,7 +1010,7 @@ static int tc_modify_qdisc(struct sk_buff *skb, struct nlmsghdr *n, void *arg)
1009 struct Qdisc *q, *p; 1010 struct Qdisc *q, *p;
1010 int err; 1011 int err;
1011 1012
1012 if (net != &init_net) 1013 if (!net_eq(net, &init_net))
1013 return -EINVAL; 1014 return -EINVAL;
1014 1015
1015replay: 1016replay:
@@ -1179,7 +1180,7 @@ static int tc_fill_qdisc(struct sk_buff *skb, struct Qdisc *q, u32 clid,
1179 goto nla_put_failure; 1180 goto nla_put_failure;
1180 1181
1181 if (gnet_stats_copy_basic(&d, &q->bstats) < 0 || 1182 if (gnet_stats_copy_basic(&d, &q->bstats) < 0 ||
1182 gnet_stats_copy_rate_est(&d, &q->rate_est) < 0 || 1183 gnet_stats_copy_rate_est(&d, &q->bstats, &q->rate_est) < 0 ||
1183 gnet_stats_copy_queue(&d, &q->qstats) < 0) 1184 gnet_stats_copy_queue(&d, &q->qstats) < 0)
1184 goto nla_put_failure; 1185 goto nla_put_failure;
1185 1186
@@ -1274,14 +1275,15 @@ static int tc_dump_qdisc(struct sk_buff *skb, struct netlink_callback *cb)
1274 int s_idx, s_q_idx; 1275 int s_idx, s_q_idx;
1275 struct net_device *dev; 1276 struct net_device *dev;
1276 1277
1277 if (net != &init_net) 1278 if (!net_eq(net, &init_net))
1278 return 0; 1279 return 0;
1279 1280
1280 s_idx = cb->args[0]; 1281 s_idx = cb->args[0];
1281 s_q_idx = q_idx = cb->args[1]; 1282 s_q_idx = q_idx = cb->args[1];
1282 read_lock(&dev_base_lock); 1283
1284 rcu_read_lock();
1283 idx = 0; 1285 idx = 0;
1284 for_each_netdev(&init_net, dev) { 1286 for_each_netdev_rcu(&init_net, dev) {
1285 struct netdev_queue *dev_queue; 1287 struct netdev_queue *dev_queue;
1286 1288
1287 if (idx < s_idx) 1289 if (idx < s_idx)
@@ -1302,7 +1304,7 @@ cont:
1302 } 1304 }
1303 1305
1304done: 1306done:
1305 read_unlock(&dev_base_lock); 1307 rcu_read_unlock();
1306 1308
1307 cb->args[0] = idx; 1309 cb->args[0] = idx;
1308 cb->args[1] = q_idx; 1310 cb->args[1] = q_idx;
@@ -1333,7 +1335,7 @@ static int tc_ctl_tclass(struct sk_buff *skb, struct nlmsghdr *n, void *arg)
1333 u32 qid = TC_H_MAJ(clid); 1335 u32 qid = TC_H_MAJ(clid);
1334 int err; 1336 int err;
1335 1337
1336 if (net != &init_net) 1338 if (!net_eq(net, &init_net))
1337 return -EINVAL; 1339 return -EINVAL;
1338 1340
1339 if ((dev = __dev_get_by_index(&init_net, tcm->tcm_ifindex)) == NULL) 1341 if ((dev = __dev_get_by_index(&init_net, tcm->tcm_ifindex)) == NULL)
@@ -1575,7 +1577,7 @@ static int tc_dump_tclass(struct sk_buff *skb, struct netlink_callback *cb)
1575 struct net_device *dev; 1577 struct net_device *dev;
1576 int t, s_t; 1578 int t, s_t;
1577 1579
1578 if (net != &init_net) 1580 if (!net_eq(net, &init_net))
1579 return 0; 1581 return 0;
1580 1582
1581 if (cb->nlh->nlmsg_len < NLMSG_LENGTH(sizeof(*tcm))) 1583 if (cb->nlh->nlmsg_len < NLMSG_LENGTH(sizeof(*tcm)))
@@ -1706,6 +1708,7 @@ static int __init pktsched_init(void)
1706{ 1708{
1707 register_qdisc(&pfifo_qdisc_ops); 1709 register_qdisc(&pfifo_qdisc_ops);
1708 register_qdisc(&bfifo_qdisc_ops); 1710 register_qdisc(&bfifo_qdisc_ops);
1711 register_qdisc(&pfifo_head_drop_qdisc_ops);
1709 register_qdisc(&mq_qdisc_ops); 1712 register_qdisc(&mq_qdisc_ops);
1710 proc_net_fops_create(&init_net, "psched", 0, &psched_fops); 1713 proc_net_fops_create(&init_net, "psched", 0, &psched_fops);
1711 1714
diff --git a/net/sched/sch_atm.c b/net/sched/sch_atm.c
index ab82f145f689..fcbb86a486a2 100644
--- a/net/sched/sch_atm.c
+++ b/net/sched/sch_atm.c
@@ -3,6 +3,7 @@
3/* Written 1998-2000 by Werner Almesberger, EPFL ICA */ 3/* Written 1998-2000 by Werner Almesberger, EPFL ICA */
4 4
5#include <linux/module.h> 5#include <linux/module.h>
6#include <linux/slab.h>
6#include <linux/init.h> 7#include <linux/init.h>
7#include <linux/string.h> 8#include <linux/string.h>
8#include <linux/errno.h> 9#include <linux/errno.h>
diff --git a/net/sched/sch_cbq.c b/net/sched/sch_cbq.c
index 5b132c473264..28c01ef5abc8 100644
--- a/net/sched/sch_cbq.c
+++ b/net/sched/sch_cbq.c
@@ -11,6 +11,7 @@
11 */ 11 */
12 12
13#include <linux/module.h> 13#include <linux/module.h>
14#include <linux/slab.h>
14#include <linux/types.h> 15#include <linux/types.h>
15#include <linux/kernel.h> 16#include <linux/kernel.h>
16#include <linux/string.h> 17#include <linux/string.h>
@@ -1609,7 +1610,7 @@ cbq_dump_class_stats(struct Qdisc *sch, unsigned long arg,
1609 cl->xstats.undertime = cl->undertime - q->now; 1610 cl->xstats.undertime = cl->undertime - q->now;
1610 1611
1611 if (gnet_stats_copy_basic(d, &cl->bstats) < 0 || 1612 if (gnet_stats_copy_basic(d, &cl->bstats) < 0 ||
1612 gnet_stats_copy_rate_est(d, &cl->rate_est) < 0 || 1613 gnet_stats_copy_rate_est(d, &cl->bstats, &cl->rate_est) < 0 ||
1613 gnet_stats_copy_queue(d, &cl->qstats) < 0) 1614 gnet_stats_copy_queue(d, &cl->qstats) < 0)
1614 return -1; 1615 return -1;
1615 1616
diff --git a/net/sched/sch_drr.c b/net/sched/sch_drr.c
index 5a888af7e5da..b74046a95397 100644
--- a/net/sched/sch_drr.c
+++ b/net/sched/sch_drr.c
@@ -9,6 +9,7 @@
9 */ 9 */
10 10
11#include <linux/module.h> 11#include <linux/module.h>
12#include <linux/slab.h>
12#include <linux/init.h> 13#include <linux/init.h>
13#include <linux/errno.h> 14#include <linux/errno.h>
14#include <linux/netdevice.h> 15#include <linux/netdevice.h>
@@ -280,7 +281,7 @@ static int drr_dump_class_stats(struct Qdisc *sch, unsigned long arg,
280 } 281 }
281 282
282 if (gnet_stats_copy_basic(d, &cl->bstats) < 0 || 283 if (gnet_stats_copy_basic(d, &cl->bstats) < 0 ||
283 gnet_stats_copy_rate_est(d, &cl->rate_est) < 0 || 284 gnet_stats_copy_rate_est(d, &cl->bstats, &cl->rate_est) < 0 ||
284 gnet_stats_copy_queue(d, &cl->qdisc->qstats) < 0) 285 gnet_stats_copy_queue(d, &cl->qdisc->qstats) < 0)
285 return -1; 286 return -1;
286 287
diff --git a/net/sched/sch_dsmark.c b/net/sched/sch_dsmark.c
index d303daa45d49..63d41f86679c 100644
--- a/net/sched/sch_dsmark.c
+++ b/net/sched/sch_dsmark.c
@@ -5,6 +5,7 @@
5 5
6#include <linux/module.h> 6#include <linux/module.h>
7#include <linux/init.h> 7#include <linux/init.h>
8#include <linux/slab.h>
8#include <linux/types.h> 9#include <linux/types.h>
9#include <linux/string.h> 10#include <linux/string.h>
10#include <linux/errno.h> 11#include <linux/errno.h>
diff --git a/net/sched/sch_fifo.c b/net/sched/sch_fifo.c
index 69188e8358b4..5948bafa8ce2 100644
--- a/net/sched/sch_fifo.c
+++ b/net/sched/sch_fifo.c
@@ -10,6 +10,7 @@
10 */ 10 */
11 11
12#include <linux/module.h> 12#include <linux/module.h>
13#include <linux/slab.h>
13#include <linux/types.h> 14#include <linux/types.h>
14#include <linux/kernel.h> 15#include <linux/kernel.h>
15#include <linux/errno.h> 16#include <linux/errno.h>
@@ -43,6 +44,26 @@ static int pfifo_enqueue(struct sk_buff *skb, struct Qdisc* sch)
43 return qdisc_reshape_fail(skb, sch); 44 return qdisc_reshape_fail(skb, sch);
44} 45}
45 46
47static int pfifo_tail_enqueue(struct sk_buff *skb, struct Qdisc* sch)
48{
49 struct sk_buff *skb_head;
50 struct fifo_sched_data *q = qdisc_priv(sch);
51
52 if (likely(skb_queue_len(&sch->q) < q->limit))
53 return qdisc_enqueue_tail(skb, sch);
54
55 /* queue full, remove one skb to fulfill the limit */
56 skb_head = qdisc_dequeue_head(sch);
57 sch->bstats.bytes -= qdisc_pkt_len(skb_head);
58 sch->bstats.packets--;
59 sch->qstats.drops++;
60 kfree_skb(skb_head);
61
62 qdisc_enqueue_tail(skb, sch);
63
64 return NET_XMIT_CN;
65}
66
46static int fifo_init(struct Qdisc *sch, struct nlattr *opt) 67static int fifo_init(struct Qdisc *sch, struct nlattr *opt)
47{ 68{
48 struct fifo_sched_data *q = qdisc_priv(sch); 69 struct fifo_sched_data *q = qdisc_priv(sch);
@@ -108,6 +129,20 @@ struct Qdisc_ops bfifo_qdisc_ops __read_mostly = {
108}; 129};
109EXPORT_SYMBOL(bfifo_qdisc_ops); 130EXPORT_SYMBOL(bfifo_qdisc_ops);
110 131
132struct Qdisc_ops pfifo_head_drop_qdisc_ops __read_mostly = {
133 .id = "pfifo_head_drop",
134 .priv_size = sizeof(struct fifo_sched_data),
135 .enqueue = pfifo_tail_enqueue,
136 .dequeue = qdisc_dequeue_head,
137 .peek = qdisc_peek_head,
138 .drop = qdisc_queue_drop_head,
139 .init = fifo_init,
140 .reset = qdisc_reset_queue,
141 .change = fifo_init,
142 .dump = fifo_dump,
143 .owner = THIS_MODULE,
144};
145
111/* Pass size change message down to embedded FIFO */ 146/* Pass size change message down to embedded FIFO */
112int fifo_set_limit(struct Qdisc *q, unsigned int limit) 147int fifo_set_limit(struct Qdisc *q, unsigned int limit)
113{ 148{
diff --git a/net/sched/sch_generic.c b/net/sched/sch_generic.c
index 4ae6aa562f2b..ff4dd53eeff0 100644
--- a/net/sched/sch_generic.c
+++ b/net/sched/sch_generic.c
@@ -24,6 +24,7 @@
24#include <linux/init.h> 24#include <linux/init.h>
25#include <linux/rcupdate.h> 25#include <linux/rcupdate.h>
26#include <linux/list.h> 26#include <linux/list.h>
27#include <linux/slab.h>
27#include <net/pkt_sched.h> 28#include <net/pkt_sched.h>
28 29
29/* Main transmission queue. */ 30/* Main transmission queue. */
@@ -119,32 +120,26 @@ int sch_direct_xmit(struct sk_buff *skb, struct Qdisc *q,
119 spin_unlock(root_lock); 120 spin_unlock(root_lock);
120 121
121 HARD_TX_LOCK(dev, txq, smp_processor_id()); 122 HARD_TX_LOCK(dev, txq, smp_processor_id());
122 if (!netif_tx_queue_stopped(txq) && 123 if (!netif_tx_queue_stopped(txq) && !netif_tx_queue_frozen(txq))
123 !netif_tx_queue_frozen(txq))
124 ret = dev_hard_start_xmit(skb, dev, txq); 124 ret = dev_hard_start_xmit(skb, dev, txq);
125
125 HARD_TX_UNLOCK(dev, txq); 126 HARD_TX_UNLOCK(dev, txq);
126 127
127 spin_lock(root_lock); 128 spin_lock(root_lock);
128 129
129 switch (ret) { 130 if (dev_xmit_complete(ret)) {
130 case NETDEV_TX_OK: 131 /* Driver sent out skb successfully or skb was consumed */
131 /* Driver sent out skb successfully */
132 ret = qdisc_qlen(q); 132 ret = qdisc_qlen(q);
133 break; 133 } else if (ret == NETDEV_TX_LOCKED) {
134
135 case NETDEV_TX_LOCKED:
136 /* Driver try lock failed */ 134 /* Driver try lock failed */
137 ret = handle_dev_cpu_collision(skb, txq, q); 135 ret = handle_dev_cpu_collision(skb, txq, q);
138 break; 136 } else {
139
140 default:
141 /* Driver returned NETDEV_TX_BUSY - requeue skb */ 137 /* Driver returned NETDEV_TX_BUSY - requeue skb */
142 if (unlikely (ret != NETDEV_TX_BUSY && net_ratelimit())) 138 if (unlikely (ret != NETDEV_TX_BUSY && net_ratelimit()))
143 printk(KERN_WARNING "BUG %s code %d qlen %d\n", 139 printk(KERN_WARNING "BUG %s code %d qlen %d\n",
144 dev->name, ret, q->q.qlen); 140 dev->name, ret, q->q.qlen);
145 141
146 ret = dev_requeue_skb(skb, q); 142 ret = dev_requeue_skb(skb, q);
147 break;
148 } 143 }
149 144
150 if (ret && (netif_tx_queue_stopped(txq) || 145 if (ret && (netif_tx_queue_stopped(txq) ||
diff --git a/net/sched/sch_gred.c b/net/sched/sch_gred.c
index 40408d595c08..51dcc2aa5c92 100644
--- a/net/sched/sch_gred.c
+++ b/net/sched/sch_gred.c
@@ -18,6 +18,7 @@
18 * For all the glorious comments look at include/net/red.h 18 * For all the glorious comments look at include/net/red.h
19 */ 19 */
20 20
21#include <linux/slab.h>
21#include <linux/module.h> 22#include <linux/module.h>
22#include <linux/types.h> 23#include <linux/types.h>
23#include <linux/kernel.h> 24#include <linux/kernel.h>
diff --git a/net/sched/sch_hfsc.c b/net/sched/sch_hfsc.c
index 2c5c76be18f8..b38b39c60752 100644
--- a/net/sched/sch_hfsc.c
+++ b/net/sched/sch_hfsc.c
@@ -1375,7 +1375,7 @@ hfsc_dump_class_stats(struct Qdisc *sch, unsigned long arg,
1375 xstats.rtwork = cl->cl_cumul; 1375 xstats.rtwork = cl->cl_cumul;
1376 1376
1377 if (gnet_stats_copy_basic(d, &cl->bstats) < 0 || 1377 if (gnet_stats_copy_basic(d, &cl->bstats) < 0 ||
1378 gnet_stats_copy_rate_est(d, &cl->rate_est) < 0 || 1378 gnet_stats_copy_rate_est(d, &cl->bstats, &cl->rate_est) < 0 ||
1379 gnet_stats_copy_queue(d, &cl->qstats) < 0) 1379 gnet_stats_copy_queue(d, &cl->qstats) < 0)
1380 return -1; 1380 return -1;
1381 1381
diff --git a/net/sched/sch_htb.c b/net/sched/sch_htb.c
index 85acab9dc6fd..0b52b8de562c 100644
--- a/net/sched/sch_htb.c
+++ b/net/sched/sch_htb.c
@@ -36,6 +36,7 @@
36#include <linux/compiler.h> 36#include <linux/compiler.h>
37#include <linux/rbtree.h> 37#include <linux/rbtree.h>
38#include <linux/workqueue.h> 38#include <linux/workqueue.h>
39#include <linux/slab.h>
39#include <net/netlink.h> 40#include <net/netlink.h>
40#include <net/pkt_sched.h> 41#include <net/pkt_sched.h>
41 42
@@ -1105,7 +1106,7 @@ htb_dump_class_stats(struct Qdisc *sch, unsigned long arg, struct gnet_dump *d)
1105 cl->xstats.ctokens = cl->ctokens; 1106 cl->xstats.ctokens = cl->ctokens;
1106 1107
1107 if (gnet_stats_copy_basic(d, &cl->bstats) < 0 || 1108 if (gnet_stats_copy_basic(d, &cl->bstats) < 0 ||
1108 gnet_stats_copy_rate_est(d, &cl->rate_est) < 0 || 1109 gnet_stats_copy_rate_est(d, NULL, &cl->rate_est) < 0 ||
1109 gnet_stats_copy_queue(d, &cl->qstats) < 0) 1110 gnet_stats_copy_queue(d, &cl->qstats) < 0)
1110 return -1; 1111 return -1;
1111 1112
@@ -1344,8 +1345,8 @@ static int htb_change_class(struct Qdisc *sch, u32 classid,
1344 }; 1345 };
1345 1346
1346 /* check for valid classid */ 1347 /* check for valid classid */
1347 if (!classid || TC_H_MAJ(classid ^ sch->handle) 1348 if (!classid || TC_H_MAJ(classid ^ sch->handle) ||
1348 || htb_find(classid, sch)) 1349 htb_find(classid, sch))
1349 goto failure; 1350 goto failure;
1350 1351
1351 /* check maximal depth */ 1352 /* check maximal depth */
diff --git a/net/sched/sch_mq.c b/net/sched/sch_mq.c
index d1dea3d5dc92..b2aba3f5e6fa 100644
--- a/net/sched/sch_mq.c
+++ b/net/sched/sch_mq.c
@@ -9,6 +9,7 @@
9 */ 9 */
10 10
11#include <linux/types.h> 11#include <linux/types.h>
12#include <linux/slab.h>
12#include <linux/kernel.h> 13#include <linux/kernel.h>
13#include <linux/string.h> 14#include <linux/string.h>
14#include <linux/errno.h> 15#include <linux/errno.h>
diff --git a/net/sched/sch_multiq.c b/net/sched/sch_multiq.c
index 7db2c88ce585..c50876cd8704 100644
--- a/net/sched/sch_multiq.c
+++ b/net/sched/sch_multiq.c
@@ -18,6 +18,7 @@
18 */ 18 */
19 19
20#include <linux/module.h> 20#include <linux/module.h>
21#include <linux/slab.h>
21#include <linux/types.h> 22#include <linux/types.h>
22#include <linux/kernel.h> 23#include <linux/kernel.h>
23#include <linux/string.h> 24#include <linux/string.h>
diff --git a/net/sched/sch_netem.c b/net/sched/sch_netem.c
index 2b88295cb7b7..4714ff162bbd 100644
--- a/net/sched/sch_netem.c
+++ b/net/sched/sch_netem.c
@@ -14,6 +14,7 @@
14 */ 14 */
15 15
16#include <linux/module.h> 16#include <linux/module.h>
17#include <linux/slab.h>
17#include <linux/types.h> 18#include <linux/types.h>
18#include <linux/kernel.h> 19#include <linux/kernel.h>
19#include <linux/errno.h> 20#include <linux/errno.h>
@@ -199,9 +200,9 @@ static int netem_enqueue(struct sk_buff *skb, struct Qdisc *sch)
199 * do it now in software before we mangle it. 200 * do it now in software before we mangle it.
200 */ 201 */
201 if (q->corrupt && q->corrupt >= get_crandom(&q->corrupt_cor)) { 202 if (q->corrupt && q->corrupt >= get_crandom(&q->corrupt_cor)) {
202 if (!(skb = skb_unshare(skb, GFP_ATOMIC)) 203 if (!(skb = skb_unshare(skb, GFP_ATOMIC)) ||
203 || (skb->ip_summed == CHECKSUM_PARTIAL 204 (skb->ip_summed == CHECKSUM_PARTIAL &&
204 && skb_checksum_help(skb))) { 205 skb_checksum_help(skb))) {
205 sch->qstats.drops++; 206 sch->qstats.drops++;
206 return NET_XMIT_DROP; 207 return NET_XMIT_DROP;
207 } 208 }
@@ -210,9 +211,9 @@ static int netem_enqueue(struct sk_buff *skb, struct Qdisc *sch)
210 } 211 }
211 212
212 cb = netem_skb_cb(skb); 213 cb = netem_skb_cb(skb);
213 if (q->gap == 0 /* not doing reordering */ 214 if (q->gap == 0 || /* not doing reordering */
214 || q->counter < q->gap /* inside last reordering gap */ 215 q->counter < q->gap || /* inside last reordering gap */
215 || q->reorder < get_crandom(&q->reorder_cor)) { 216 q->reorder < get_crandom(&q->reorder_cor)) {
216 psched_time_t now; 217 psched_time_t now;
217 psched_tdiff_t delay; 218 psched_tdiff_t delay;
218 219
diff --git a/net/sched/sch_prio.c b/net/sched/sch_prio.c
index 93285cecb246..81672e0c1b25 100644
--- a/net/sched/sch_prio.c
+++ b/net/sched/sch_prio.c
@@ -12,6 +12,7 @@
12 */ 12 */
13 13
14#include <linux/module.h> 14#include <linux/module.h>
15#include <linux/slab.h>
15#include <linux/types.h> 16#include <linux/types.h>
16#include <linux/kernel.h> 17#include <linux/kernel.h>
17#include <linux/string.h> 18#include <linux/string.h>
diff --git a/net/sched/sch_sfq.c b/net/sched/sch_sfq.c
index cb21380c0605..c5a9ac566007 100644
--- a/net/sched/sch_sfq.c
+++ b/net/sched/sch_sfq.c
@@ -20,6 +20,7 @@
20#include <linux/ipv6.h> 20#include <linux/ipv6.h>
21#include <linux/skbuff.h> 21#include <linux/skbuff.h>
22#include <linux/jhash.h> 22#include <linux/jhash.h>
23#include <linux/slab.h>
23#include <net/ip.h> 24#include <net/ip.h>
24#include <net/netlink.h> 25#include <net/netlink.h>
25#include <net/pkt_sched.h> 26#include <net/pkt_sched.h>
diff --git a/net/sched/sch_teql.c b/net/sched/sch_teql.c
index 5a002c247231..3415b6ce1c0a 100644
--- a/net/sched/sch_teql.c
+++ b/net/sched/sch_teql.c
@@ -11,6 +11,7 @@
11#include <linux/module.h> 11#include <linux/module.h>
12#include <linux/types.h> 12#include <linux/types.h>
13#include <linux/kernel.h> 13#include <linux/kernel.h>
14#include <linux/slab.h>
14#include <linux/string.h> 15#include <linux/string.h>
15#include <linux/errno.h> 16#include <linux/errno.h>
16#include <linux/if_arp.h> 17#include <linux/if_arp.h>
@@ -190,10 +191,13 @@ static int teql_qdisc_init(struct Qdisc *sch, struct nlattr *opt)
190 191
191 if (m->slaves) { 192 if (m->slaves) {
192 if (m->dev->flags & IFF_UP) { 193 if (m->dev->flags & IFF_UP) {
193 if ((m->dev->flags&IFF_POINTOPOINT && !(dev->flags&IFF_POINTOPOINT)) 194 if ((m->dev->flags & IFF_POINTOPOINT &&
194 || (m->dev->flags&IFF_BROADCAST && !(dev->flags&IFF_BROADCAST)) 195 !(dev->flags & IFF_POINTOPOINT)) ||
195 || (m->dev->flags&IFF_MULTICAST && !(dev->flags&IFF_MULTICAST)) 196 (m->dev->flags & IFF_BROADCAST &&
196 || dev->mtu < m->dev->mtu) 197 !(dev->flags & IFF_BROADCAST)) ||
198 (m->dev->flags & IFF_MULTICAST &&
199 !(dev->flags & IFF_MULTICAST)) ||
200 dev->mtu < m->dev->mtu)
197 return -EINVAL; 201 return -EINVAL;
198 } else { 202 } else {
199 if (!(dev->flags&IFF_POINTOPOINT)) 203 if (!(dev->flags&IFF_POINTOPOINT))
diff --git a/net/sctp/associola.c b/net/sctp/associola.c
index 7eed77a39d0d..99c93ee98ad9 100644
--- a/net/sctp/associola.c
+++ b/net/sctp/associola.c
@@ -63,6 +63,12 @@
63static void sctp_assoc_bh_rcv(struct work_struct *work); 63static void sctp_assoc_bh_rcv(struct work_struct *work);
64static void sctp_assoc_free_asconf_acks(struct sctp_association *asoc); 64static void sctp_assoc_free_asconf_acks(struct sctp_association *asoc);
65 65
66/* Keep track of the new idr low so that we don't re-use association id
67 * numbers too fast. It is protected by they idr spin lock is in the
68 * range of 1 - INT_MAX.
69 */
70static u32 idr_low = 1;
71
66 72
67/* 1st Level Abstractions. */ 73/* 1st Level Abstractions. */
68 74
@@ -167,7 +173,7 @@ static struct sctp_association *sctp_association_init(struct sctp_association *a
167 asoc->timeouts[SCTP_EVENT_TIMEOUT_HEARTBEAT] = 0; 173 asoc->timeouts[SCTP_EVENT_TIMEOUT_HEARTBEAT] = 0;
168 asoc->timeouts[SCTP_EVENT_TIMEOUT_SACK] = asoc->sackdelay; 174 asoc->timeouts[SCTP_EVENT_TIMEOUT_SACK] = asoc->sackdelay;
169 asoc->timeouts[SCTP_EVENT_TIMEOUT_AUTOCLOSE] = 175 asoc->timeouts[SCTP_EVENT_TIMEOUT_AUTOCLOSE] =
170 sp->autoclose * HZ; 176 (unsigned long)sp->autoclose * HZ;
171 177
172 /* Initilizes the timers */ 178 /* Initilizes the timers */
173 for (i = SCTP_EVENT_TIMEOUT_NONE; i < SCTP_NUM_TIMEOUT_TYPES; ++i) 179 for (i = SCTP_EVENT_TIMEOUT_NONE; i < SCTP_NUM_TIMEOUT_TYPES; ++i)
@@ -512,7 +518,13 @@ void sctp_assoc_set_primary(struct sctp_association *asoc,
512 * to this destination address earlier. The sender MUST set 518 * to this destination address earlier. The sender MUST set
513 * CYCLING_CHANGEOVER to indicate that this switch is a 519 * CYCLING_CHANGEOVER to indicate that this switch is a
514 * double switch to the same destination address. 520 * double switch to the same destination address.
521 *
522 * Really, only bother is we have data queued or outstanding on
523 * the association.
515 */ 524 */
525 if (!asoc->outqueue.outstanding_bytes && !asoc->outqueue.out_qlen)
526 return;
527
516 if (transport->cacc.changeover_active) 528 if (transport->cacc.changeover_active)
517 transport->cacc.cycling_changeover = changeover; 529 transport->cacc.cycling_changeover = changeover;
518 530
@@ -732,6 +744,7 @@ struct sctp_transport *sctp_assoc_add_peer(struct sctp_association *asoc,
732 744
733 peer->partial_bytes_acked = 0; 745 peer->partial_bytes_acked = 0;
734 peer->flight_size = 0; 746 peer->flight_size = 0;
747 peer->burst_limited = 0;
735 748
736 /* Set the transport's RTO.initial value */ 749 /* Set the transport's RTO.initial value */
737 peer->rto = asoc->rto_initial; 750 peer->rto = asoc->rto_initial;
@@ -1181,8 +1194,10 @@ void sctp_assoc_update(struct sctp_association *asoc,
1181 /* Remove any peer addresses not present in the new association. */ 1194 /* Remove any peer addresses not present in the new association. */
1182 list_for_each_safe(pos, temp, &asoc->peer.transport_addr_list) { 1195 list_for_each_safe(pos, temp, &asoc->peer.transport_addr_list) {
1183 trans = list_entry(pos, struct sctp_transport, transports); 1196 trans = list_entry(pos, struct sctp_transport, transports);
1184 if (!sctp_assoc_lookup_paddr(new, &trans->ipaddr)) 1197 if (!sctp_assoc_lookup_paddr(new, &trans->ipaddr)) {
1185 sctp_assoc_del_peer(asoc, &trans->ipaddr); 1198 sctp_assoc_rm_peer(asoc, trans);
1199 continue;
1200 }
1186 1201
1187 if (asoc->state >= SCTP_STATE_ESTABLISHED) 1202 if (asoc->state >= SCTP_STATE_ESTABLISHED)
1188 sctp_transport_reset(trans); 1203 sctp_transport_reset(trans);
@@ -1377,8 +1392,9 @@ static inline int sctp_peer_needs_update(struct sctp_association *asoc)
1377 case SCTP_STATE_SHUTDOWN_RECEIVED: 1392 case SCTP_STATE_SHUTDOWN_RECEIVED:
1378 case SCTP_STATE_SHUTDOWN_SENT: 1393 case SCTP_STATE_SHUTDOWN_SENT:
1379 if ((asoc->rwnd > asoc->a_rwnd) && 1394 if ((asoc->rwnd > asoc->a_rwnd) &&
1380 ((asoc->rwnd - asoc->a_rwnd) >= 1395 ((asoc->rwnd - asoc->a_rwnd) >= max_t(__u32,
1381 min_t(__u32, (asoc->base.sk->sk_rcvbuf >> 1), asoc->pathmtu))) 1396 (asoc->base.sk->sk_rcvbuf >> sctp_rwnd_upd_shift),
1397 asoc->pathmtu)))
1382 return 1; 1398 return 1;
1383 break; 1399 break;
1384 default: 1400 default:
@@ -1545,7 +1561,12 @@ retry:
1545 1561
1546 spin_lock_bh(&sctp_assocs_id_lock); 1562 spin_lock_bh(&sctp_assocs_id_lock);
1547 error = idr_get_new_above(&sctp_assocs_id, (void *)asoc, 1563 error = idr_get_new_above(&sctp_assocs_id, (void *)asoc,
1548 1, &assoc_id); 1564 idr_low, &assoc_id);
1565 if (!error) {
1566 idr_low = assoc_id + 1;
1567 if (idr_low == INT_MAX)
1568 idr_low = 1;
1569 }
1549 spin_unlock_bh(&sctp_assocs_id_lock); 1570 spin_unlock_bh(&sctp_assocs_id_lock);
1550 if (error == -EAGAIN) 1571 if (error == -EAGAIN)
1551 goto retry; 1572 goto retry;
diff --git a/net/sctp/auth.c b/net/sctp/auth.c
index 56935bbc1496..86366390038a 100644
--- a/net/sctp/auth.c
+++ b/net/sctp/auth.c
@@ -34,6 +34,7 @@
34 * be incorporated into the next SCTP release. 34 * be incorporated into the next SCTP release.
35 */ 35 */
36 36
37#include <linux/slab.h>
37#include <linux/types.h> 38#include <linux/types.h>
38#include <linux/crypto.h> 39#include <linux/crypto.h>
39#include <linux/scatterlist.h> 40#include <linux/scatterlist.h>
diff --git a/net/sctp/bind_addr.c b/net/sctp/bind_addr.c
index 13a6fba41077..faf71d179e46 100644
--- a/net/sctp/bind_addr.c
+++ b/net/sctp/bind_addr.c
@@ -43,6 +43,7 @@
43 */ 43 */
44 44
45#include <linux/types.h> 45#include <linux/types.h>
46#include <linux/slab.h>
46#include <linux/in.h> 47#include <linux/in.h>
47#include <net/sock.h> 48#include <net/sock.h>
48#include <net/ipv6.h> 49#include <net/ipv6.h>
@@ -186,7 +187,6 @@ int sctp_add_bind_addr(struct sctp_bind_addr *bp, union sctp_addr *new,
186 addr->valid = 1; 187 addr->valid = 1;
187 188
188 INIT_LIST_HEAD(&addr->list); 189 INIT_LIST_HEAD(&addr->list);
189 INIT_RCU_HEAD(&addr->rcu);
190 190
191 /* We always hold a socket lock when calling this function, 191 /* We always hold a socket lock when calling this function,
192 * and that acts as a writer synchronizing lock. 192 * and that acts as a writer synchronizing lock.
diff --git a/net/sctp/chunk.c b/net/sctp/chunk.c
index acf7c4d128f7..3eab6db59a37 100644
--- a/net/sctp/chunk.c
+++ b/net/sctp/chunk.c
@@ -42,6 +42,7 @@
42#include <linux/net.h> 42#include <linux/net.h>
43#include <linux/inet.h> 43#include <linux/inet.h>
44#include <linux/skbuff.h> 44#include <linux/skbuff.h>
45#include <linux/slab.h>
45#include <net/sock.h> 46#include <net/sock.h>
46#include <net/sctp/sctp.h> 47#include <net/sctp/sctp.h>
47#include <net/sctp/sm.h> 48#include <net/sctp/sm.h>
@@ -263,9 +264,18 @@ struct sctp_datamsg *sctp_datamsg_from_user(struct sctp_association *asoc,
263 if (0 == i) 264 if (0 == i)
264 frag |= SCTP_DATA_FIRST_FRAG; 265 frag |= SCTP_DATA_FIRST_FRAG;
265 266
266 if ((i == (whole - 1)) && !over) 267 if ((i == (whole - 1)) && !over) {
267 frag |= SCTP_DATA_LAST_FRAG; 268 frag |= SCTP_DATA_LAST_FRAG;
268 269
270 /* The application requests to set the I-bit of the
271 * last DATA chunk of a user message when providing
272 * the user message to the SCTP implementation.
273 */
274 if ((sinfo->sinfo_flags & SCTP_EOF) ||
275 (sinfo->sinfo_flags & SCTP_SACK_IMMEDIATELY))
276 frag |= SCTP_DATA_SACK_IMM;
277 }
278
269 chunk = sctp_make_datafrag_empty(asoc, sinfo, len, frag, 0); 279 chunk = sctp_make_datafrag_empty(asoc, sinfo, len, frag, 0);
270 280
271 if (!chunk) 281 if (!chunk)
@@ -297,6 +307,10 @@ struct sctp_datamsg *sctp_datamsg_from_user(struct sctp_association *asoc,
297 else 307 else
298 frag = SCTP_DATA_LAST_FRAG; 308 frag = SCTP_DATA_LAST_FRAG;
299 309
310 if ((sinfo->sinfo_flags & SCTP_EOF) ||
311 (sinfo->sinfo_flags & SCTP_SACK_IMMEDIATELY))
312 frag |= SCTP_DATA_SACK_IMM;
313
300 chunk = sctp_make_datafrag_empty(asoc, sinfo, over, frag, 0); 314 chunk = sctp_make_datafrag_empty(asoc, sinfo, over, frag, 0);
301 315
302 if (!chunk) 316 if (!chunk)
diff --git a/net/sctp/endpointola.c b/net/sctp/endpointola.c
index 905fda582b92..7ec09ba03a1c 100644
--- a/net/sctp/endpointola.c
+++ b/net/sctp/endpointola.c
@@ -144,6 +144,7 @@ static struct sctp_endpoint *sctp_endpoint_init(struct sctp_endpoint *ep,
144 /* Use SCTP specific send buffer space queues. */ 144 /* Use SCTP specific send buffer space queues. */
145 ep->sndbuf_policy = sctp_sndbuf_policy; 145 ep->sndbuf_policy = sctp_sndbuf_policy;
146 146
147 sk->sk_data_ready = sctp_data_ready;
147 sk->sk_write_space = sctp_write_space; 148 sk->sk_write_space = sctp_write_space;
148 sock_set_flag(sk, SOCK_USE_WRITE_QUEUE); 149 sock_set_flag(sk, SOCK_USE_WRITE_QUEUE);
149 150
diff --git a/net/sctp/input.c b/net/sctp/input.c
index c0c973e67add..ea2192444ce6 100644
--- a/net/sctp/input.c
+++ b/net/sctp/input.c
@@ -53,6 +53,7 @@
53#include <linux/socket.h> 53#include <linux/socket.h>
54#include <linux/ip.h> 54#include <linux/ip.h>
55#include <linux/time.h> /* For struct timeval */ 55#include <linux/time.h> /* For struct timeval */
56#include <linux/slab.h>
56#include <net/ip.h> 57#include <net/ip.h>
57#include <net/icmp.h> 58#include <net/icmp.h>
58#include <net/snmp.h> 59#include <net/snmp.h>
@@ -75,7 +76,7 @@ static struct sctp_association *__sctp_lookup_association(
75 const union sctp_addr *peer, 76 const union sctp_addr *peer,
76 struct sctp_transport **pt); 77 struct sctp_transport **pt);
77 78
78static void sctp_add_backlog(struct sock *sk, struct sk_buff *skb); 79static int sctp_add_backlog(struct sock *sk, struct sk_buff *skb);
79 80
80 81
81/* Calculate the SCTP checksum of an SCTP packet. */ 82/* Calculate the SCTP checksum of an SCTP packet. */
@@ -265,8 +266,13 @@ int sctp_rcv(struct sk_buff *skb)
265 } 266 }
266 267
267 if (sock_owned_by_user(sk)) { 268 if (sock_owned_by_user(sk)) {
269 if (sctp_add_backlog(sk, skb)) {
270 sctp_bh_unlock_sock(sk);
271 sctp_chunk_free(chunk);
272 skb = NULL; /* sctp_chunk_free already freed the skb */
273 goto discard_release;
274 }
268 SCTP_INC_STATS_BH(SCTP_MIB_IN_PKT_BACKLOG); 275 SCTP_INC_STATS_BH(SCTP_MIB_IN_PKT_BACKLOG);
269 sctp_add_backlog(sk, skb);
270 } else { 276 } else {
271 SCTP_INC_STATS_BH(SCTP_MIB_IN_PKT_SOFTIRQ); 277 SCTP_INC_STATS_BH(SCTP_MIB_IN_PKT_SOFTIRQ);
272 sctp_inq_push(&chunk->rcvr->inqueue, chunk); 278 sctp_inq_push(&chunk->rcvr->inqueue, chunk);
@@ -336,8 +342,10 @@ int sctp_backlog_rcv(struct sock *sk, struct sk_buff *skb)
336 sctp_bh_lock_sock(sk); 342 sctp_bh_lock_sock(sk);
337 343
338 if (sock_owned_by_user(sk)) { 344 if (sock_owned_by_user(sk)) {
339 sk_add_backlog(sk, skb); 345 if (sk_add_backlog(sk, skb))
340 backloged = 1; 346 sctp_chunk_free(chunk);
347 else
348 backloged = 1;
341 } else 349 } else
342 sctp_inq_push(inqueue, chunk); 350 sctp_inq_push(inqueue, chunk);
343 351
@@ -362,22 +370,27 @@ done:
362 return 0; 370 return 0;
363} 371}
364 372
365static void sctp_add_backlog(struct sock *sk, struct sk_buff *skb) 373static int sctp_add_backlog(struct sock *sk, struct sk_buff *skb)
366{ 374{
367 struct sctp_chunk *chunk = SCTP_INPUT_CB(skb)->chunk; 375 struct sctp_chunk *chunk = SCTP_INPUT_CB(skb)->chunk;
368 struct sctp_ep_common *rcvr = chunk->rcvr; 376 struct sctp_ep_common *rcvr = chunk->rcvr;
377 int ret;
369 378
370 /* Hold the assoc/ep while hanging on the backlog queue. 379 ret = sk_add_backlog(sk, skb);
371 * This way, we know structures we need will not disappear from us 380 if (!ret) {
372 */ 381 /* Hold the assoc/ep while hanging on the backlog queue.
373 if (SCTP_EP_TYPE_ASSOCIATION == rcvr->type) 382 * This way, we know structures we need will not disappear
374 sctp_association_hold(sctp_assoc(rcvr)); 383 * from us
375 else if (SCTP_EP_TYPE_SOCKET == rcvr->type) 384 */
376 sctp_endpoint_hold(sctp_ep(rcvr)); 385 if (SCTP_EP_TYPE_ASSOCIATION == rcvr->type)
377 else 386 sctp_association_hold(sctp_assoc(rcvr));
378 BUG(); 387 else if (SCTP_EP_TYPE_SOCKET == rcvr->type)
388 sctp_endpoint_hold(sctp_ep(rcvr));
389 else
390 BUG();
391 }
392 return ret;
379 393
380 sk_add_backlog(sk, skb);
381} 394}
382 395
383/* Handle icmp frag needed error. */ 396/* Handle icmp frag needed error. */
@@ -427,11 +440,25 @@ void sctp_icmp_proto_unreachable(struct sock *sk,
427{ 440{
428 SCTP_DEBUG_PRINTK("%s\n", __func__); 441 SCTP_DEBUG_PRINTK("%s\n", __func__);
429 442
430 sctp_do_sm(SCTP_EVENT_T_OTHER, 443 if (sock_owned_by_user(sk)) {
431 SCTP_ST_OTHER(SCTP_EVENT_ICMP_PROTO_UNREACH), 444 if (timer_pending(&t->proto_unreach_timer))
432 asoc->state, asoc->ep, asoc, t, 445 return;
433 GFP_ATOMIC); 446 else {
447 if (!mod_timer(&t->proto_unreach_timer,
448 jiffies + (HZ/20)))
449 sctp_association_hold(asoc);
450 }
451
452 } else {
453 if (timer_pending(&t->proto_unreach_timer) &&
454 del_timer(&t->proto_unreach_timer))
455 sctp_association_put(asoc);
434 456
457 sctp_do_sm(SCTP_EVENT_T_OTHER,
458 SCTP_ST_OTHER(SCTP_EVENT_ICMP_PROTO_UNREACH),
459 asoc->state, asoc->ep, asoc, t,
460 GFP_ATOMIC);
461 }
435} 462}
436 463
437/* Common lookup code for icmp/icmpv6 error handler. */ 464/* Common lookup code for icmp/icmpv6 error handler. */
diff --git a/net/sctp/inqueue.c b/net/sctp/inqueue.c
index bbf5dd2a97c4..ccb6dc48d15b 100644
--- a/net/sctp/inqueue.c
+++ b/net/sctp/inqueue.c
@@ -46,6 +46,7 @@
46#include <net/sctp/sctp.h> 46#include <net/sctp/sctp.h>
47#include <net/sctp/sm.h> 47#include <net/sctp/sm.h>
48#include <linux/interrupt.h> 48#include <linux/interrupt.h>
49#include <linux/slab.h>
49 50
50/* Initialize an SCTP inqueue. */ 51/* Initialize an SCTP inqueue. */
51void sctp_inq_init(struct sctp_inq *queue) 52void sctp_inq_init(struct sctp_inq *queue)
diff --git a/net/sctp/ipv6.c b/net/sctp/ipv6.c
index bb280e60e00a..9fb5d37c37ad 100644
--- a/net/sctp/ipv6.c
+++ b/net/sctp/ipv6.c
@@ -58,6 +58,7 @@
58#include <linux/netdevice.h> 58#include <linux/netdevice.h>
59#include <linux/init.h> 59#include <linux/init.h>
60#include <linux/ipsec.h> 60#include <linux/ipsec.h>
61#include <linux/slab.h>
61 62
62#include <linux/ipv6.h> 63#include <linux/ipv6.h>
63#include <linux/icmpv6.h> 64#include <linux/icmpv6.h>
@@ -381,7 +382,6 @@ static void sctp_v6_copy_addrlist(struct list_head *addrlist,
381 addr->a.v6.sin6_scope_id = dev->ifindex; 382 addr->a.v6.sin6_scope_id = dev->ifindex;
382 addr->valid = 1; 383 addr->valid = 1;
383 INIT_LIST_HEAD(&addr->list); 384 INIT_LIST_HEAD(&addr->list);
384 INIT_RCU_HEAD(&addr->rcu);
385 list_add_tail(&addr->list, addrlist); 385 list_add_tail(&addr->list, addrlist);
386 } 386 }
387 } 387 }
@@ -837,15 +837,16 @@ static int sctp_inet6_bind_verify(struct sctp_sock *opt, union sctp_addr *addr)
837 if (type & IPV6_ADDR_LINKLOCAL) { 837 if (type & IPV6_ADDR_LINKLOCAL) {
838 if (!addr->v6.sin6_scope_id) 838 if (!addr->v6.sin6_scope_id)
839 return 0; 839 return 0;
840 dev = dev_get_by_index(&init_net, addr->v6.sin6_scope_id); 840 rcu_read_lock();
841 if (!dev) 841 dev = dev_get_by_index_rcu(&init_net,
842 return 0; 842 addr->v6.sin6_scope_id);
843 if (!ipv6_chk_addr(&init_net, &addr->v6.sin6_addr, 843 if (!dev ||
844 !ipv6_chk_addr(&init_net, &addr->v6.sin6_addr,
844 dev, 0)) { 845 dev, 0)) {
845 dev_put(dev); 846 rcu_read_unlock();
846 return 0; 847 return 0;
847 } 848 }
848 dev_put(dev); 849 rcu_read_unlock();
849 } else if (type == IPV6_ADDR_MAPPED) { 850 } else if (type == IPV6_ADDR_MAPPED) {
850 if (!opt->v4mapped) 851 if (!opt->v4mapped)
851 return 0; 852 return 0;
@@ -873,10 +874,12 @@ static int sctp_inet6_send_verify(struct sctp_sock *opt, union sctp_addr *addr)
873 if (type & IPV6_ADDR_LINKLOCAL) { 874 if (type & IPV6_ADDR_LINKLOCAL) {
874 if (!addr->v6.sin6_scope_id) 875 if (!addr->v6.sin6_scope_id)
875 return 0; 876 return 0;
876 dev = dev_get_by_index(&init_net, addr->v6.sin6_scope_id); 877 rcu_read_lock();
878 dev = dev_get_by_index_rcu(&init_net,
879 addr->v6.sin6_scope_id);
880 rcu_read_unlock();
877 if (!dev) 881 if (!dev)
878 return 0; 882 return 0;
879 dev_put(dev);
880 } 883 }
881 af = opt->pf->af; 884 af = opt->pf->af;
882 } 885 }
@@ -930,7 +933,6 @@ static struct inet_protosw sctpv6_seqpacket_protosw = {
930 .protocol = IPPROTO_SCTP, 933 .protocol = IPPROTO_SCTP,
931 .prot = &sctpv6_prot, 934 .prot = &sctpv6_prot,
932 .ops = &inet6_seqpacket_ops, 935 .ops = &inet6_seqpacket_ops,
933 .capability = -1,
934 .no_check = 0, 936 .no_check = 0,
935 .flags = SCTP_PROTOSW_FLAG 937 .flags = SCTP_PROTOSW_FLAG
936}; 938};
@@ -939,7 +941,6 @@ static struct inet_protosw sctpv6_stream_protosw = {
939 .protocol = IPPROTO_SCTP, 941 .protocol = IPPROTO_SCTP,
940 .prot = &sctpv6_prot, 942 .prot = &sctpv6_prot,
941 .ops = &inet6_seqpacket_ops, 943 .ops = &inet6_seqpacket_ops,
942 .capability = -1,
943 .no_check = 0, 944 .no_check = 0,
944 .flags = SCTP_PROTOSW_FLAG, 945 .flags = SCTP_PROTOSW_FLAG,
945}; 946};
diff --git a/net/sctp/output.c b/net/sctp/output.c
index 5cbda8f1ddfd..fad261d41ec2 100644
--- a/net/sctp/output.c
+++ b/net/sctp/output.c
@@ -48,6 +48,7 @@
48#include <linux/ip.h> 48#include <linux/ip.h>
49#include <linux/ipv6.h> 49#include <linux/ipv6.h>
50#include <linux/init.h> 50#include <linux/init.h>
51#include <linux/slab.h>
51#include <net/inet_ecn.h> 52#include <net/inet_ecn.h>
52#include <net/ip.h> 53#include <net/ip.h>
53#include <net/icmp.h> 54#include <net/icmp.h>
@@ -429,23 +430,22 @@ int sctp_packet_transmit(struct sctp_packet *packet)
429 list_del_init(&chunk->list); 430 list_del_init(&chunk->list);
430 if (sctp_chunk_is_data(chunk)) { 431 if (sctp_chunk_is_data(chunk)) {
431 432
432 if (!chunk->has_tsn) { 433 if (!chunk->resent) {
433 sctp_chunk_assign_ssn(chunk);
434 sctp_chunk_assign_tsn(chunk);
435 434
436 /* 6.3.1 C4) When data is in flight and when allowed 435 /* 6.3.1 C4) When data is in flight and when allowed
437 * by rule C5, a new RTT measurement MUST be made each 436 * by rule C5, a new RTT measurement MUST be made each
438 * round trip. Furthermore, new RTT measurements 437 * round trip. Furthermore, new RTT measurements
439 * SHOULD be made no more than once per round-trip 438 * SHOULD be made no more than once per round-trip
440 * for a given destination transport address. 439 * for a given destination transport address.
441 */ 440 */
442 441
443 if (!tp->rto_pending) { 442 if (!tp->rto_pending) {
444 chunk->rtt_in_progress = 1; 443 chunk->rtt_in_progress = 1;
445 tp->rto_pending = 1; 444 tp->rto_pending = 1;
446 } 445 }
447 } else 446 }
448 chunk->resent = 1; 447
448 chunk->resent = 1;
449 449
450 has_data = 1; 450 has_data = 1;
451 } 451 }
@@ -557,8 +557,6 @@ int sctp_packet_transmit(struct sctp_packet *packet)
557 struct timer_list *timer; 557 struct timer_list *timer;
558 unsigned long timeout; 558 unsigned long timeout;
559 559
560 tp->last_time_used = jiffies;
561
562 /* Restart the AUTOCLOSE timer when sending data. */ 560 /* Restart the AUTOCLOSE timer when sending data. */
563 if (sctp_state(asoc, ESTABLISHED) && asoc->autoclose) { 561 if (sctp_state(asoc, ESTABLISHED) && asoc->autoclose) {
564 timer = &asoc->timers[SCTP_EVENT_TIMEOUT_AUTOCLOSE]; 562 timer = &asoc->timers[SCTP_EVENT_TIMEOUT_AUTOCLOSE];
@@ -617,7 +615,6 @@ static sctp_xmit_t sctp_packet_can_append_data(struct sctp_packet *packet,
617 sctp_xmit_t retval = SCTP_XMIT_OK; 615 sctp_xmit_t retval = SCTP_XMIT_OK;
618 size_t datasize, rwnd, inflight, flight_size; 616 size_t datasize, rwnd, inflight, flight_size;
619 struct sctp_transport *transport = packet->transport; 617 struct sctp_transport *transport = packet->transport;
620 __u32 max_burst_bytes;
621 struct sctp_association *asoc = transport->asoc; 618 struct sctp_association *asoc = transport->asoc;
622 struct sctp_outq *q = &asoc->outqueue; 619 struct sctp_outq *q = &asoc->outqueue;
623 620
@@ -650,28 +647,6 @@ static sctp_xmit_t sctp_packet_can_append_data(struct sctp_packet *packet,
650 } 647 }
651 } 648 }
652 649
653 /* sctpimpguide-05 2.14.2
654 * D) When the time comes for the sender to
655 * transmit new DATA chunks, the protocol parameter Max.Burst MUST
656 * first be applied to limit how many new DATA chunks may be sent.
657 * The limit is applied by adjusting cwnd as follows:
658 * if ((flightsize + Max.Burst * MTU) < cwnd)
659 * cwnd = flightsize + Max.Burst * MTU
660 */
661 max_burst_bytes = asoc->max_burst * asoc->pathmtu;
662 if ((flight_size + max_burst_bytes) < transport->cwnd) {
663 transport->cwnd = flight_size + max_burst_bytes;
664 SCTP_DEBUG_PRINTK("%s: cwnd limited by max_burst: "
665 "transport: %p, cwnd: %d, "
666 "ssthresh: %d, flight_size: %d, "
667 "pba: %d\n",
668 __func__, transport,
669 transport->cwnd,
670 transport->ssthresh,
671 transport->flight_size,
672 transport->partial_bytes_acked);
673 }
674
675 /* RFC 2960 6.1 Transmission of DATA Chunks 650 /* RFC 2960 6.1 Transmission of DATA Chunks
676 * 651 *
677 * B) At any given time, the sender MUST NOT transmit new data 652 * B) At any given time, the sender MUST NOT transmit new data
@@ -747,6 +722,8 @@ static void sctp_packet_append_data(struct sctp_packet *packet,
747 /* Has been accepted for transmission. */ 722 /* Has been accepted for transmission. */
748 if (!asoc->peer.prsctp_capable) 723 if (!asoc->peer.prsctp_capable)
749 chunk->msg->can_abandon = 0; 724 chunk->msg->can_abandon = 0;
725 sctp_chunk_assign_tsn(chunk);
726 sctp_chunk_assign_ssn(chunk);
750} 727}
751 728
752static sctp_xmit_t sctp_packet_will_fit(struct sctp_packet *packet, 729static sctp_xmit_t sctp_packet_will_fit(struct sctp_packet *packet,
diff --git a/net/sctp/outqueue.c b/net/sctp/outqueue.c
index 23e5e97aa617..abfc0b8dee74 100644
--- a/net/sctp/outqueue.c
+++ b/net/sctp/outqueue.c
@@ -50,6 +50,7 @@
50#include <linux/list.h> /* For struct list_head */ 50#include <linux/list.h> /* For struct list_head */
51#include <linux/socket.h> 51#include <linux/socket.h>
52#include <linux/ip.h> 52#include <linux/ip.h>
53#include <linux/slab.h>
53#include <net/sock.h> /* For skb_set_owner_w */ 54#include <net/sock.h> /* For skb_set_owner_w */
54 55
55#include <net/sctp/sctp.h> 56#include <net/sctp/sctp.h>
@@ -191,8 +192,8 @@ static inline int sctp_cacc_skip(struct sctp_transport *primary,
191 __u32 tsn) 192 __u32 tsn)
192{ 193{
193 if (primary->cacc.changeover_active && 194 if (primary->cacc.changeover_active &&
194 (sctp_cacc_skip_3_1(primary, transport, count_of_newacks) 195 (sctp_cacc_skip_3_1(primary, transport, count_of_newacks) ||
195 || sctp_cacc_skip_3_2(primary, tsn))) 196 sctp_cacc_skip_3_2(primary, tsn)))
196 return 1; 197 return 1;
197 return 0; 198 return 0;
198} 199}
@@ -921,6 +922,14 @@ static int sctp_outq_flush(struct sctp_outq *q, int rtx_timeout)
921 goto sctp_flush_out; 922 goto sctp_flush_out;
922 } 923 }
923 924
925 /* Apply Max.Burst limitation to the current transport in
926 * case it will be used for new data. We are going to
927 * rest it before we return, but we want to apply the limit
928 * to the currently queued data.
929 */
930 if (transport)
931 sctp_transport_burst_limited(transport);
932
924 /* Finally, transmit new packets. */ 933 /* Finally, transmit new packets. */
925 while ((chunk = sctp_outq_dequeue_data(q)) != NULL) { 934 while ((chunk = sctp_outq_dequeue_data(q)) != NULL) {
926 /* RFC 2960 6.5 Every DATA chunk MUST carry a valid 935 /* RFC 2960 6.5 Every DATA chunk MUST carry a valid
@@ -966,6 +975,10 @@ static int sctp_outq_flush(struct sctp_outq *q, int rtx_timeout)
966 packet = &transport->packet; 975 packet = &transport->packet;
967 sctp_packet_config(packet, vtag, 976 sctp_packet_config(packet, vtag,
968 asoc->peer.ecn_capable); 977 asoc->peer.ecn_capable);
978 /* We've switched transports, so apply the
979 * Burst limit to the new transport.
980 */
981 sctp_transport_burst_limited(transport);
969 } 982 }
970 983
971 SCTP_DEBUG_PRINTK("sctp_outq_flush(%p, %p[%s]), ", 984 SCTP_DEBUG_PRINTK("sctp_outq_flush(%p, %p[%s]), ",
@@ -1001,6 +1014,13 @@ static int sctp_outq_flush(struct sctp_outq *q, int rtx_timeout)
1001 break; 1014 break;
1002 1015
1003 case SCTP_XMIT_OK: 1016 case SCTP_XMIT_OK:
1017 /* The sender is in the SHUTDOWN-PENDING state,
1018 * The sender MAY set the I-bit in the DATA
1019 * chunk header.
1020 */
1021 if (asoc->state == SCTP_STATE_SHUTDOWN_PENDING)
1022 chunk->chunk_hdr->flags |= SCTP_DATA_SACK_IMM;
1023
1004 break; 1024 break;
1005 1025
1006 default: 1026 default:
@@ -1053,6 +1073,9 @@ sctp_flush_out:
1053 packet = &t->packet; 1073 packet = &t->packet;
1054 if (!sctp_packet_empty(packet)) 1074 if (!sctp_packet_empty(packet))
1055 error = sctp_packet_transmit(packet); 1075 error = sctp_packet_transmit(packet);
1076
1077 /* Clear the burst limited state, if any */
1078 sctp_transport_burst_reset(t);
1056 } 1079 }
1057 1080
1058 return error; 1081 return error;
diff --git a/net/sctp/primitive.c b/net/sctp/primitive.c
index 8cb4f060bce6..534c7eae9d15 100644
--- a/net/sctp/primitive.c
+++ b/net/sctp/primitive.c
@@ -50,6 +50,7 @@
50#include <linux/socket.h> 50#include <linux/socket.h>
51#include <linux/ip.h> 51#include <linux/ip.h>
52#include <linux/time.h> /* For struct timeval */ 52#include <linux/time.h> /* For struct timeval */
53#include <linux/gfp.h>
53#include <net/sock.h> 54#include <net/sock.h>
54#include <net/sctp/sctp.h> 55#include <net/sctp/sctp.h>
55#include <net/sctp/sm.h> 56#include <net/sctp/sm.h>
diff --git a/net/sctp/proc.c b/net/sctp/proc.c
index d093cbfeaac4..784bcc9a979d 100644
--- a/net/sctp/proc.c
+++ b/net/sctp/proc.c
@@ -40,7 +40,7 @@
40#include <net/sctp/sctp.h> 40#include <net/sctp/sctp.h>
41#include <net/ip.h> /* for snmp_fold_field */ 41#include <net/ip.h> /* for snmp_fold_field */
42 42
43static struct snmp_mib sctp_snmp_list[] = { 43static const struct snmp_mib sctp_snmp_list[] = {
44 SNMP_MIB_ITEM("SctpCurrEstab", SCTP_MIB_CURRESTAB), 44 SNMP_MIB_ITEM("SctpCurrEstab", SCTP_MIB_CURRESTAB),
45 SNMP_MIB_ITEM("SctpActiveEstabs", SCTP_MIB_ACTIVEESTABS), 45 SNMP_MIB_ITEM("SctpActiveEstabs", SCTP_MIB_ACTIVEESTABS),
46 SNMP_MIB_ITEM("SctpPassiveEstabs", SCTP_MIB_PASSIVEESTABS), 46 SNMP_MIB_ITEM("SctpPassiveEstabs", SCTP_MIB_PASSIVEESTABS),
@@ -83,7 +83,7 @@ static int sctp_snmp_seq_show(struct seq_file *seq, void *v)
83 83
84 for (i = 0; sctp_snmp_list[i].name != NULL; i++) 84 for (i = 0; sctp_snmp_list[i].name != NULL; i++)
85 seq_printf(seq, "%-32s\t%ld\n", sctp_snmp_list[i].name, 85 seq_printf(seq, "%-32s\t%ld\n", sctp_snmp_list[i].name,
86 snmp_fold_field((void **)sctp_statistics, 86 snmp_fold_field((void __percpu **)sctp_statistics,
87 sctp_snmp_list[i].entry)); 87 sctp_snmp_list[i].entry));
88 88
89 return 0; 89 return 0;
diff --git a/net/sctp/protocol.c b/net/sctp/protocol.c
index 612dc878e05c..a56f98e82f92 100644
--- a/net/sctp/protocol.c
+++ b/net/sctp/protocol.c
@@ -54,6 +54,7 @@
54#include <linux/bootmem.h> 54#include <linux/bootmem.h>
55#include <linux/highmem.h> 55#include <linux/highmem.h>
56#include <linux/swap.h> 56#include <linux/swap.h>
57#include <linux/slab.h>
57#include <net/net_namespace.h> 58#include <net/net_namespace.h>
58#include <net/protocol.h> 59#include <net/protocol.h>
59#include <net/ip.h> 60#include <net/ip.h>
@@ -188,7 +189,6 @@ static void sctp_v4_copy_addrlist(struct list_head *addrlist,
188 addr->a.v4.sin_addr.s_addr = ifa->ifa_local; 189 addr->a.v4.sin_addr.s_addr = ifa->ifa_local;
189 addr->valid = 1; 190 addr->valid = 1;
190 INIT_LIST_HEAD(&addr->list); 191 INIT_LIST_HEAD(&addr->list);
191 INIT_RCU_HEAD(&addr->rcu);
192 list_add_tail(&addr->list, addrlist); 192 list_add_tail(&addr->list, addrlist);
193 } 193 }
194 } 194 }
@@ -205,14 +205,14 @@ static void sctp_get_local_addr_list(void)
205 struct list_head *pos; 205 struct list_head *pos;
206 struct sctp_af *af; 206 struct sctp_af *af;
207 207
208 read_lock(&dev_base_lock); 208 rcu_read_lock();
209 for_each_netdev(&init_net, dev) { 209 for_each_netdev_rcu(&init_net, dev) {
210 __list_for_each(pos, &sctp_address_families) { 210 __list_for_each(pos, &sctp_address_families) {
211 af = list_entry(pos, struct sctp_af, list); 211 af = list_entry(pos, struct sctp_af, list);
212 af->copy_addrlist(&sctp_local_addr_list, dev); 212 af->copy_addrlist(&sctp_local_addr_list, dev);
213 } 213 }
214 } 214 }
215 read_unlock(&dev_base_lock); 215 rcu_read_unlock();
216} 216}
217 217
218/* Free the existing local addresses. */ 218/* Free the existing local addresses. */
@@ -296,19 +296,19 @@ static void sctp_v4_from_sk(union sctp_addr *addr, struct sock *sk)
296{ 296{
297 addr->v4.sin_family = AF_INET; 297 addr->v4.sin_family = AF_INET;
298 addr->v4.sin_port = 0; 298 addr->v4.sin_port = 0;
299 addr->v4.sin_addr.s_addr = inet_sk(sk)->rcv_saddr; 299 addr->v4.sin_addr.s_addr = inet_sk(sk)->inet_rcv_saddr;
300} 300}
301 301
302/* Initialize sk->sk_rcv_saddr from sctp_addr. */ 302/* Initialize sk->sk_rcv_saddr from sctp_addr. */
303static void sctp_v4_to_sk_saddr(union sctp_addr *addr, struct sock *sk) 303static void sctp_v4_to_sk_saddr(union sctp_addr *addr, struct sock *sk)
304{ 304{
305 inet_sk(sk)->rcv_saddr = addr->v4.sin_addr.s_addr; 305 inet_sk(sk)->inet_rcv_saddr = addr->v4.sin_addr.s_addr;
306} 306}
307 307
308/* Initialize sk->sk_daddr from sctp_addr. */ 308/* Initialize sk->sk_daddr from sctp_addr. */
309static void sctp_v4_to_sk_daddr(union sctp_addr *addr, struct sock *sk) 309static void sctp_v4_to_sk_daddr(union sctp_addr *addr, struct sock *sk)
310{ 310{
311 inet_sk(sk)->daddr = addr->v4.sin_addr.s_addr; 311 inet_sk(sk)->inet_daddr = addr->v4.sin_addr.s_addr;
312} 312}
313 313
314/* Initialize a sctp_addr from an address parameter. */ 314/* Initialize a sctp_addr from an address parameter. */
@@ -598,7 +598,7 @@ static struct sock *sctp_v4_create_accept_sk(struct sock *sk,
598 598
599 newinet = inet_sk(newsk); 599 newinet = inet_sk(newsk);
600 600
601 newinet->daddr = asoc->peer.primary_addr.v4.sin_addr.s_addr; 601 newinet->inet_daddr = asoc->peer.primary_addr.v4.sin_addr.s_addr;
602 602
603 sk_refcnt_debug_inc(newsk); 603 sk_refcnt_debug_inc(newsk);
604 604
@@ -909,7 +909,6 @@ static struct inet_protosw sctp_seqpacket_protosw = {
909 .protocol = IPPROTO_SCTP, 909 .protocol = IPPROTO_SCTP,
910 .prot = &sctp_prot, 910 .prot = &sctp_prot,
911 .ops = &inet_seqpacket_ops, 911 .ops = &inet_seqpacket_ops,
912 .capability = -1,
913 .no_check = 0, 912 .no_check = 0,
914 .flags = SCTP_PROTOSW_FLAG 913 .flags = SCTP_PROTOSW_FLAG
915}; 914};
@@ -918,7 +917,6 @@ static struct inet_protosw sctp_stream_protosw = {
918 .protocol = IPPROTO_SCTP, 917 .protocol = IPPROTO_SCTP,
919 .prot = &sctp_prot, 918 .prot = &sctp_prot,
920 .ops = &inet_seqpacket_ops, 919 .ops = &inet_seqpacket_ops,
921 .capability = -1,
922 .no_check = 0, 920 .no_check = 0,
923 .flags = SCTP_PROTOSW_FLAG 921 .flags = SCTP_PROTOSW_FLAG
924}; 922};
@@ -998,12 +996,13 @@ int sctp_register_pf(struct sctp_pf *pf, sa_family_t family)
998 996
999static inline int init_sctp_mibs(void) 997static inline int init_sctp_mibs(void)
1000{ 998{
1001 return snmp_mib_init((void**)sctp_statistics, sizeof(struct sctp_mib)); 999 return snmp_mib_init((void __percpu **)sctp_statistics,
1000 sizeof(struct sctp_mib));
1002} 1001}
1003 1002
1004static inline void cleanup_sctp_mibs(void) 1003static inline void cleanup_sctp_mibs(void)
1005{ 1004{
1006 snmp_mib_free((void**)sctp_statistics); 1005 snmp_mib_free((void __percpu **)sctp_statistics);
1007} 1006}
1008 1007
1009static void sctp_v4_pf_init(void) 1008static void sctp_v4_pf_init(void)
@@ -1260,6 +1259,9 @@ SCTP_STATIC __init int sctp_init(void)
1260 /* Set SCOPE policy to enabled */ 1259 /* Set SCOPE policy to enabled */
1261 sctp_scope_policy = SCTP_SCOPE_POLICY_ENABLE; 1260 sctp_scope_policy = SCTP_SCOPE_POLICY_ENABLE;
1262 1261
1262 /* Set the default rwnd update threshold */
1263 sctp_rwnd_upd_shift = SCTP_DEFAULT_RWND_SHIFT;
1264
1263 sctp_sysctl_register(); 1265 sctp_sysctl_register();
1264 1266
1265 INIT_LIST_HEAD(&sctp_address_families); 1267 INIT_LIST_HEAD(&sctp_address_families);
diff --git a/net/sctp/sm_make_chunk.c b/net/sctp/sm_make_chunk.c
index 9d881a61ac02..30c1767186b8 100644
--- a/net/sctp/sm_make_chunk.c
+++ b/net/sctp/sm_make_chunk.c
@@ -58,6 +58,7 @@
58#include <linux/inet.h> 58#include <linux/inet.h>
59#include <linux/scatterlist.h> 59#include <linux/scatterlist.h>
60#include <linux/crypto.h> 60#include <linux/crypto.h>
61#include <linux/slab.h>
61#include <net/sock.h> 62#include <net/sock.h>
62 63
63#include <linux/skbuff.h> 64#include <linux/skbuff.h>
@@ -107,7 +108,7 @@ static const struct sctp_paramhdr prsctp_param = {
107 cpu_to_be16(sizeof(struct sctp_paramhdr)), 108 cpu_to_be16(sizeof(struct sctp_paramhdr)),
108}; 109};
109 110
110/* A helper to initialize to initialize an op error inside a 111/* A helper to initialize an op error inside a
111 * provided chunk, as most cause codes will be embedded inside an 112 * provided chunk, as most cause codes will be embedded inside an
112 * abort chunk. 113 * abort chunk.
113 */ 114 */
@@ -124,6 +125,29 @@ void sctp_init_cause(struct sctp_chunk *chunk, __be16 cause_code,
124 chunk->subh.err_hdr = sctp_addto_chunk(chunk, sizeof(sctp_errhdr_t), &err); 125 chunk->subh.err_hdr = sctp_addto_chunk(chunk, sizeof(sctp_errhdr_t), &err);
125} 126}
126 127
128/* A helper to initialize an op error inside a
129 * provided chunk, as most cause codes will be embedded inside an
130 * abort chunk. Differs from sctp_init_cause in that it won't oops
131 * if there isn't enough space in the op error chunk
132 */
133int sctp_init_cause_fixed(struct sctp_chunk *chunk, __be16 cause_code,
134 size_t paylen)
135{
136 sctp_errhdr_t err;
137 __u16 len;
138
139 /* Cause code constants are now defined in network order. */
140 err.cause = cause_code;
141 len = sizeof(sctp_errhdr_t) + paylen;
142 err.length = htons(len);
143
144 if (skb_tailroom(chunk->skb) > len)
145 return -ENOSPC;
146 chunk->subh.err_hdr = sctp_addto_chunk_fixed(chunk,
147 sizeof(sctp_errhdr_t),
148 &err);
149 return 0;
150}
127/* 3.3.2 Initiation (INIT) (1) 151/* 3.3.2 Initiation (INIT) (1)
128 * 152 *
129 * This chunk is used to initiate a SCTP association between two 153 * This chunk is used to initiate a SCTP association between two
@@ -207,7 +231,8 @@ struct sctp_chunk *sctp_make_init(const struct sctp_association *asoc,
207 sp = sctp_sk(asoc->base.sk); 231 sp = sctp_sk(asoc->base.sk);
208 num_types = sp->pf->supported_addrs(sp, types); 232 num_types = sp->pf->supported_addrs(sp, types);
209 233
210 chunksize = sizeof(init) + addrs_len + SCTP_SAT_LEN(num_types); 234 chunksize = sizeof(init) + addrs_len;
235 chunksize += WORD_ROUND(SCTP_SAT_LEN(num_types));
211 chunksize += sizeof(ecap_param); 236 chunksize += sizeof(ecap_param);
212 237
213 if (sctp_prsctp_enable) 238 if (sctp_prsctp_enable)
@@ -237,14 +262,14 @@ struct sctp_chunk *sctp_make_init(const struct sctp_association *asoc,
237 /* Add HMACS parameter length if any were defined */ 262 /* Add HMACS parameter length if any were defined */
238 auth_hmacs = (sctp_paramhdr_t *)asoc->c.auth_hmacs; 263 auth_hmacs = (sctp_paramhdr_t *)asoc->c.auth_hmacs;
239 if (auth_hmacs->length) 264 if (auth_hmacs->length)
240 chunksize += ntohs(auth_hmacs->length); 265 chunksize += WORD_ROUND(ntohs(auth_hmacs->length));
241 else 266 else
242 auth_hmacs = NULL; 267 auth_hmacs = NULL;
243 268
244 /* Add CHUNKS parameter length */ 269 /* Add CHUNKS parameter length */
245 auth_chunks = (sctp_paramhdr_t *)asoc->c.auth_chunks; 270 auth_chunks = (sctp_paramhdr_t *)asoc->c.auth_chunks;
246 if (auth_chunks->length) 271 if (auth_chunks->length)
247 chunksize += ntohs(auth_chunks->length); 272 chunksize += WORD_ROUND(ntohs(auth_chunks->length));
248 else 273 else
249 auth_chunks = NULL; 274 auth_chunks = NULL;
250 275
@@ -254,7 +279,8 @@ struct sctp_chunk *sctp_make_init(const struct sctp_association *asoc,
254 279
255 /* If we have any extensions to report, account for that */ 280 /* If we have any extensions to report, account for that */
256 if (num_ext) 281 if (num_ext)
257 chunksize += sizeof(sctp_supported_ext_param_t) + num_ext; 282 chunksize += WORD_ROUND(sizeof(sctp_supported_ext_param_t) +
283 num_ext);
258 284
259 /* RFC 2960 3.3.2 Initiation (INIT) (1) 285 /* RFC 2960 3.3.2 Initiation (INIT) (1)
260 * 286 *
@@ -396,13 +422,13 @@ struct sctp_chunk *sctp_make_init_ack(const struct sctp_association *asoc,
396 422
397 auth_hmacs = (sctp_paramhdr_t *)asoc->c.auth_hmacs; 423 auth_hmacs = (sctp_paramhdr_t *)asoc->c.auth_hmacs;
398 if (auth_hmacs->length) 424 if (auth_hmacs->length)
399 chunksize += ntohs(auth_hmacs->length); 425 chunksize += WORD_ROUND(ntohs(auth_hmacs->length));
400 else 426 else
401 auth_hmacs = NULL; 427 auth_hmacs = NULL;
402 428
403 auth_chunks = (sctp_paramhdr_t *)asoc->c.auth_chunks; 429 auth_chunks = (sctp_paramhdr_t *)asoc->c.auth_chunks;
404 if (auth_chunks->length) 430 if (auth_chunks->length)
405 chunksize += ntohs(auth_chunks->length); 431 chunksize += WORD_ROUND(ntohs(auth_chunks->length));
406 else 432 else
407 auth_chunks = NULL; 433 auth_chunks = NULL;
408 434
@@ -411,7 +437,8 @@ struct sctp_chunk *sctp_make_init_ack(const struct sctp_association *asoc,
411 } 437 }
412 438
413 if (num_ext) 439 if (num_ext)
414 chunksize += sizeof(sctp_supported_ext_param_t) + num_ext; 440 chunksize += WORD_ROUND(sizeof(sctp_supported_ext_param_t) +
441 num_ext);
415 442
416 /* Now allocate and fill out the chunk. */ 443 /* Now allocate and fill out the chunk. */
417 retval = sctp_make_chunk(asoc, SCTP_CID_INIT_ACK, 0, chunksize); 444 retval = sctp_make_chunk(asoc, SCTP_CID_INIT_ACK, 0, chunksize);
@@ -987,7 +1014,10 @@ static void *sctp_addto_param(struct sctp_chunk *chunk, int len,
987 1014
988 target = skb_put(chunk->skb, len); 1015 target = skb_put(chunk->skb, len);
989 1016
990 memcpy(target, data, len); 1017 if (data)
1018 memcpy(target, data, len);
1019 else
1020 memset(target, 0, len);
991 1021
992 /* Adjust the chunk length field. */ 1022 /* Adjust the chunk length field. */
993 chunk->chunk_hdr->length = htons(chunklen + len); 1023 chunk->chunk_hdr->length = htons(chunklen + len);
@@ -1125,20 +1155,40 @@ nodata:
1125 return retval; 1155 return retval;
1126} 1156}
1127 1157
1158/* Create an Operation Error chunk of a fixed size,
1159 * specifically, max(asoc->pathmtu, SCTP_DEFAULT_MAXSEGMENT)
1160 * This is a helper function to allocate an error chunk for
1161 * for those invalid parameter codes in which we may not want
1162 * to report all the errors, if the incomming chunk is large
1163 */
1164static inline struct sctp_chunk *sctp_make_op_error_fixed(
1165 const struct sctp_association *asoc,
1166 const struct sctp_chunk *chunk)
1167{
1168 size_t size = asoc ? asoc->pathmtu : 0;
1169
1170 if (!size)
1171 size = SCTP_DEFAULT_MAXSEGMENT;
1172
1173 return sctp_make_op_error_space(asoc, chunk, size);
1174}
1175
1128/* Create an Operation Error chunk. */ 1176/* Create an Operation Error chunk. */
1129struct sctp_chunk *sctp_make_op_error(const struct sctp_association *asoc, 1177struct sctp_chunk *sctp_make_op_error(const struct sctp_association *asoc,
1130 const struct sctp_chunk *chunk, 1178 const struct sctp_chunk *chunk,
1131 __be16 cause_code, const void *payload, 1179 __be16 cause_code, const void *payload,
1132 size_t paylen) 1180 size_t paylen, size_t reserve_tail)
1133{ 1181{
1134 struct sctp_chunk *retval; 1182 struct sctp_chunk *retval;
1135 1183
1136 retval = sctp_make_op_error_space(asoc, chunk, paylen); 1184 retval = sctp_make_op_error_space(asoc, chunk, paylen + reserve_tail);
1137 if (!retval) 1185 if (!retval)
1138 goto nodata; 1186 goto nodata;
1139 1187
1140 sctp_init_cause(retval, cause_code, paylen); 1188 sctp_init_cause(retval, cause_code, paylen + reserve_tail);
1141 sctp_addto_chunk(retval, paylen, payload); 1189 sctp_addto_chunk(retval, paylen, payload);
1190 if (reserve_tail)
1191 sctp_addto_param(retval, reserve_tail, NULL);
1142 1192
1143nodata: 1193nodata:
1144 return retval; 1194 return retval;
@@ -1365,6 +1415,18 @@ void *sctp_addto_chunk(struct sctp_chunk *chunk, int len, const void *data)
1365 return target; 1415 return target;
1366} 1416}
1367 1417
1418/* Append bytes to the end of a chunk. Returns NULL if there isn't sufficient
1419 * space in the chunk
1420 */
1421void *sctp_addto_chunk_fixed(struct sctp_chunk *chunk,
1422 int len, const void *data)
1423{
1424 if (skb_tailroom(chunk->skb) > len)
1425 return sctp_addto_chunk(chunk, len, data);
1426 else
1427 return NULL;
1428}
1429
1368/* Append bytes from user space to the end of a chunk. Will panic if 1430/* Append bytes from user space to the end of a chunk. Will panic if
1369 * chunk is not big enough. 1431 * chunk is not big enough.
1370 * Returns a kernel err value. 1432 * Returns a kernel err value.
@@ -1968,13 +2030,12 @@ static sctp_ierror_t sctp_process_unk_param(const struct sctp_association *asoc,
1968 * returning multiple unknown parameters. 2030 * returning multiple unknown parameters.
1969 */ 2031 */
1970 if (NULL == *errp) 2032 if (NULL == *errp)
1971 *errp = sctp_make_op_error_space(asoc, chunk, 2033 *errp = sctp_make_op_error_fixed(asoc, chunk);
1972 ntohs(chunk->chunk_hdr->length));
1973 2034
1974 if (*errp) { 2035 if (*errp) {
1975 sctp_init_cause(*errp, SCTP_ERROR_UNKNOWN_PARAM, 2036 sctp_init_cause_fixed(*errp, SCTP_ERROR_UNKNOWN_PARAM,
1976 WORD_ROUND(ntohs(param.p->length))); 2037 WORD_ROUND(ntohs(param.p->length)));
1977 sctp_addto_chunk(*errp, 2038 sctp_addto_chunk_fixed(*errp,
1978 WORD_ROUND(ntohs(param.p->length)), 2039 WORD_ROUND(ntohs(param.p->length)),
1979 param.v); 2040 param.v);
1980 } else { 2041 } else {
@@ -3309,21 +3370,6 @@ int sctp_process_asconf_ack(struct sctp_association *asoc,
3309 sctp_chunk_free(asconf); 3370 sctp_chunk_free(asconf);
3310 asoc->addip_last_asconf = NULL; 3371 asoc->addip_last_asconf = NULL;
3311 3372
3312 /* Send the next asconf chunk from the addip chunk queue. */
3313 if (!list_empty(&asoc->addip_chunk_list)) {
3314 struct list_head *entry = asoc->addip_chunk_list.next;
3315 asconf = list_entry(entry, struct sctp_chunk, list);
3316
3317 list_del_init(entry);
3318
3319 /* Hold the chunk until an ASCONF_ACK is received. */
3320 sctp_chunk_hold(asconf);
3321 if (sctp_primitive_ASCONF(asoc, asconf))
3322 sctp_chunk_free(asconf);
3323 else
3324 asoc->addip_last_asconf = asconf;
3325 }
3326
3327 return retval; 3373 return retval;
3328} 3374}
3329 3375
diff --git a/net/sctp/sm_sideeffect.c b/net/sctp/sm_sideeffect.c
index efa516b47e81..eb1f42f45fdd 100644
--- a/net/sctp/sm_sideeffect.c
+++ b/net/sctp/sm_sideeffect.c
@@ -51,6 +51,7 @@
51#include <linux/types.h> 51#include <linux/types.h>
52#include <linux/socket.h> 52#include <linux/socket.h>
53#include <linux/ip.h> 53#include <linux/ip.h>
54#include <linux/gfp.h>
54#include <net/sock.h> 55#include <net/sock.h>
55#include <net/sctp/sctp.h> 56#include <net/sctp/sctp.h>
56#include <net/sctp/sm.h> 57#include <net/sctp/sm.h>
@@ -217,8 +218,7 @@ static int sctp_gen_sack(struct sctp_association *asoc, int force,
217 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART, 218 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
218 SCTP_TO(SCTP_EVENT_TIMEOUT_SACK)); 219 SCTP_TO(SCTP_EVENT_TIMEOUT_SACK));
219 } else { 220 } else {
220 if (asoc->a_rwnd > asoc->rwnd) 221 asoc->a_rwnd = asoc->rwnd;
221 asoc->a_rwnd = asoc->rwnd;
222 sack = sctp_make_sack(asoc); 222 sack = sctp_make_sack(asoc);
223 if (!sack) 223 if (!sack)
224 goto nomem; 224 goto nomem;
@@ -397,6 +397,41 @@ out_unlock:
397 sctp_transport_put(transport); 397 sctp_transport_put(transport);
398} 398}
399 399
400/* Handle the timeout of the ICMP protocol unreachable timer. Trigger
401 * the correct state machine transition that will close the association.
402 */
403void sctp_generate_proto_unreach_event(unsigned long data)
404{
405 struct sctp_transport *transport = (struct sctp_transport *) data;
406 struct sctp_association *asoc = transport->asoc;
407
408 sctp_bh_lock_sock(asoc->base.sk);
409 if (sock_owned_by_user(asoc->base.sk)) {
410 SCTP_DEBUG_PRINTK("%s:Sock is busy.\n", __func__);
411
412 /* Try again later. */
413 if (!mod_timer(&transport->proto_unreach_timer,
414 jiffies + (HZ/20)))
415 sctp_association_hold(asoc);
416 goto out_unlock;
417 }
418
419 /* Is this structure just waiting around for us to actually
420 * get destroyed?
421 */
422 if (asoc->base.dead)
423 goto out_unlock;
424
425 sctp_do_sm(SCTP_EVENT_T_OTHER,
426 SCTP_ST_OTHER(SCTP_EVENT_ICMP_PROTO_UNREACH),
427 asoc->state, asoc->ep, asoc, transport, GFP_ATOMIC);
428
429out_unlock:
430 sctp_bh_unlock_sock(asoc->base.sk);
431 sctp_association_put(asoc);
432}
433
434
400/* Inject a SACK Timeout event into the state machine. */ 435/* Inject a SACK Timeout event into the state machine. */
401static void sctp_generate_sack_event(unsigned long data) 436static void sctp_generate_sack_event(unsigned long data)
402{ 437{
@@ -476,7 +511,7 @@ static void sctp_do_8_2_transport_strike(struct sctp_association *asoc,
476 * used to provide an upper bound to this doubling operation. 511 * used to provide an upper bound to this doubling operation.
477 * 512 *
478 * Special Case: the first HB doesn't trigger exponential backoff. 513 * Special Case: the first HB doesn't trigger exponential backoff.
479 * The first unacknowleged HB triggers it. We do this with a flag 514 * The first unacknowledged HB triggers it. We do this with a flag
480 * that indicates that we have an outstanding HB. 515 * that indicates that we have an outstanding HB.
481 */ 516 */
482 if (!is_hb || transport->hb_sent) { 517 if (!is_hb || transport->hb_sent) {
@@ -718,7 +753,7 @@ static void sctp_cmd_new_state(sctp_cmd_seq_t *cmds,
718 753
719 if (sctp_style(sk, TCP)) { 754 if (sctp_style(sk, TCP)) {
720 /* Change the sk->sk_state of a TCP-style socket that has 755 /* Change the sk->sk_state of a TCP-style socket that has
721 * sucessfully completed a connect() call. 756 * successfully completed a connect() call.
722 */ 757 */
723 if (sctp_state(asoc, ESTABLISHED) && sctp_sstate(sk, CLOSED)) 758 if (sctp_state(asoc, ESTABLISHED) && sctp_sstate(sk, CLOSED))
724 sk->sk_state = SCTP_SS_ESTABLISHED; 759 sk->sk_state = SCTP_SS_ESTABLISHED;
@@ -962,6 +997,29 @@ static int sctp_cmd_send_msg(struct sctp_association *asoc,
962} 997}
963 998
964 999
1000/* Sent the next ASCONF packet currently stored in the association.
1001 * This happens after the ASCONF_ACK was succeffully processed.
1002 */
1003static void sctp_cmd_send_asconf(struct sctp_association *asoc)
1004{
1005 /* Send the next asconf chunk from the addip chunk
1006 * queue.
1007 */
1008 if (!list_empty(&asoc->addip_chunk_list)) {
1009 struct list_head *entry = asoc->addip_chunk_list.next;
1010 struct sctp_chunk *asconf = list_entry(entry,
1011 struct sctp_chunk, list);
1012 list_del_init(entry);
1013
1014 /* Hold the chunk until an ASCONF_ACK is received. */
1015 sctp_chunk_hold(asconf);
1016 if (sctp_primitive_ASCONF(asoc, asconf))
1017 sctp_chunk_free(asconf);
1018 else
1019 asoc->addip_last_asconf = asconf;
1020 }
1021}
1022
965 1023
966/* These three macros allow us to pull the debugging code out of the 1024/* These three macros allow us to pull the debugging code out of the
967 * main flow of sctp_do_sm() to keep attention focused on the real 1025 * main flow of sctp_do_sm() to keep attention focused on the real
@@ -1417,6 +1475,8 @@ static int sctp_cmd_interpreter(sctp_event_t event_type,
1417 asoc->init_last_sent_to = t; 1475 asoc->init_last_sent_to = t;
1418 chunk->transport = t; 1476 chunk->transport = t;
1419 t->init_sent_count++; 1477 t->init_sent_count++;
1478 /* Set the new transport as primary */
1479 sctp_assoc_set_primary(asoc, t);
1420 break; 1480 break;
1421 1481
1422 case SCTP_CMD_INIT_RESTART: 1482 case SCTP_CMD_INIT_RESTART:
@@ -1615,6 +1675,9 @@ static int sctp_cmd_interpreter(sctp_event_t event_type,
1615 } 1675 }
1616 error = sctp_cmd_send_msg(asoc, cmd->obj.msg); 1676 error = sctp_cmd_send_msg(asoc, cmd->obj.msg);
1617 break; 1677 break;
1678 case SCTP_CMD_SEND_NEXT_ASCONF:
1679 sctp_cmd_send_asconf(asoc);
1680 break;
1618 default: 1681 default:
1619 printk(KERN_WARNING "Impossible command: %u, %p\n", 1682 printk(KERN_WARNING "Impossible command: %u, %p\n",
1620 cmd->verb, cmd->obj.ptr); 1683 cmd->verb, cmd->obj.ptr);
diff --git a/net/sctp/sm_statefuns.c b/net/sctp/sm_statefuns.c
index d4df45022ffa..24b2cd555637 100644
--- a/net/sctp/sm_statefuns.c
+++ b/net/sctp/sm_statefuns.c
@@ -56,6 +56,7 @@
56#include <linux/ipv6.h> 56#include <linux/ipv6.h>
57#include <linux/net.h> 57#include <linux/net.h>
58#include <linux/inet.h> 58#include <linux/inet.h>
59#include <linux/slab.h>
59#include <net/sock.h> 60#include <net/sock.h>
60#include <net/inet_ecn.h> 61#include <net/inet_ecn.h>
61#include <linux/skbuff.h> 62#include <linux/skbuff.h>
@@ -996,14 +997,15 @@ sctp_disposition_t sctp_sf_sendbeat_8_3(const struct sctp_endpoint *ep,
996 sctp_sf_heartbeat(ep, asoc, type, arg, 997 sctp_sf_heartbeat(ep, asoc, type, arg,
997 commands)) 998 commands))
998 return SCTP_DISPOSITION_NOMEM; 999 return SCTP_DISPOSITION_NOMEM;
1000
999 /* Set transport error counter and association error counter 1001 /* Set transport error counter and association error counter
1000 * when sending heartbeat. 1002 * when sending heartbeat.
1001 */ 1003 */
1002 sctp_add_cmd_sf(commands, SCTP_CMD_TRANSPORT_IDLE,
1003 SCTP_TRANSPORT(transport));
1004 sctp_add_cmd_sf(commands, SCTP_CMD_TRANSPORT_HB_SENT, 1004 sctp_add_cmd_sf(commands, SCTP_CMD_TRANSPORT_HB_SENT,
1005 SCTP_TRANSPORT(transport)); 1005 SCTP_TRANSPORT(transport));
1006 } 1006 }
1007 sctp_add_cmd_sf(commands, SCTP_CMD_TRANSPORT_IDLE,
1008 SCTP_TRANSPORT(transport));
1007 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMER_UPDATE, 1009 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMER_UPDATE,
1008 SCTP_TRANSPORT(transport)); 1010 SCTP_TRANSPORT(transport));
1009 1011
@@ -1720,7 +1722,7 @@ static sctp_disposition_t sctp_sf_do_dupcook_a(const struct sctp_endpoint *ep,
1720 1722
1721 err = sctp_make_op_error(asoc, chunk, 1723 err = sctp_make_op_error(asoc, chunk,
1722 SCTP_ERROR_COOKIE_IN_SHUTDOWN, 1724 SCTP_ERROR_COOKIE_IN_SHUTDOWN,
1723 NULL, 0); 1725 NULL, 0, 0);
1724 if (err) 1726 if (err)
1725 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, 1727 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
1726 SCTP_CHUNK(err)); 1728 SCTP_CHUNK(err));
@@ -2868,6 +2870,7 @@ sctp_disposition_t sctp_sf_eat_data_6_2(const struct sctp_endpoint *ep,
2868 sctp_cmd_seq_t *commands) 2870 sctp_cmd_seq_t *commands)
2869{ 2871{
2870 struct sctp_chunk *chunk = arg; 2872 struct sctp_chunk *chunk = arg;
2873 sctp_arg_t force = SCTP_NOFORCE();
2871 int error; 2874 int error;
2872 2875
2873 if (!sctp_vtag_verify(chunk, asoc)) { 2876 if (!sctp_vtag_verify(chunk, asoc)) {
@@ -2901,6 +2904,9 @@ sctp_disposition_t sctp_sf_eat_data_6_2(const struct sctp_endpoint *ep,
2901 BUG(); 2904 BUG();
2902 } 2905 }
2903 2906
2907 if (chunk->chunk_hdr->flags & SCTP_DATA_SACK_IMM)
2908 force = SCTP_FORCE();
2909
2904 if (asoc->autoclose) { 2910 if (asoc->autoclose) {
2905 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART, 2911 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
2906 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE)); 2912 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE));
@@ -2929,7 +2935,7 @@ sctp_disposition_t sctp_sf_eat_data_6_2(const struct sctp_endpoint *ep,
2929 * more aggressive than the following algorithms allow. 2935 * more aggressive than the following algorithms allow.
2930 */ 2936 */
2931 if (chunk->end_of_packet) 2937 if (chunk->end_of_packet)
2932 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_NOFORCE()); 2938 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, force);
2933 2939
2934 return SCTP_DISPOSITION_CONSUME; 2940 return SCTP_DISPOSITION_CONSUME;
2935 2941
@@ -2954,7 +2960,7 @@ discard_force:
2954 2960
2955discard_noforce: 2961discard_noforce:
2956 if (chunk->end_of_packet) 2962 if (chunk->end_of_packet)
2957 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_NOFORCE()); 2963 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, force);
2958 2964
2959 return SCTP_DISPOSITION_DISCARD; 2965 return SCTP_DISPOSITION_DISCARD;
2960consume: 2966consume:
@@ -3572,7 +3578,7 @@ sctp_disposition_t sctp_sf_do_asconf(const struct sctp_endpoint *ep,
3572 * To do this properly, we'll set the destination address of the chunk 3578 * To do this properly, we'll set the destination address of the chunk
3573 * and at the transmit time, will try look up the transport to use. 3579 * and at the transmit time, will try look up the transport to use.
3574 * Since ASCONFs may be bundled, the correct transport may not be 3580 * Since ASCONFs may be bundled, the correct transport may not be
3575 * created untill we process the entire packet, thus this workaround. 3581 * created until we process the entire packet, thus this workaround.
3576 */ 3582 */
3577 asconf_ack->dest = chunk->source; 3583 asconf_ack->dest = chunk->source;
3578 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(asconf_ack)); 3584 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(asconf_ack));
@@ -3670,8 +3676,14 @@ sctp_disposition_t sctp_sf_do_asconf_ack(const struct sctp_endpoint *ep,
3670 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO)); 3676 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO));
3671 3677
3672 if (!sctp_process_asconf_ack((struct sctp_association *)asoc, 3678 if (!sctp_process_asconf_ack((struct sctp_association *)asoc,
3673 asconf_ack)) 3679 asconf_ack)) {
3680 /* Successfully processed ASCONF_ACK. We can
3681 * release the next asconf if we have one.
3682 */
3683 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_NEXT_ASCONF,
3684 SCTP_NULL());
3674 return SCTP_DISPOSITION_CONSUME; 3685 return SCTP_DISPOSITION_CONSUME;
3686 }
3675 3687
3676 abort = sctp_make_abort(asoc, asconf_ack, 3688 abort = sctp_make_abort(asoc, asconf_ack,
3677 sizeof(sctp_errhdr_t)); 3689 sizeof(sctp_errhdr_t));
@@ -3973,7 +3985,7 @@ sctp_disposition_t sctp_sf_eat_auth(const struct sctp_endpoint *ep,
3973 err_chunk = sctp_make_op_error(asoc, chunk, 3985 err_chunk = sctp_make_op_error(asoc, chunk,
3974 SCTP_ERROR_UNSUP_HMAC, 3986 SCTP_ERROR_UNSUP_HMAC,
3975 &auth_hdr->hmac_id, 3987 &auth_hdr->hmac_id,
3976 sizeof(__u16)); 3988 sizeof(__u16), 0);
3977 if (err_chunk) { 3989 if (err_chunk) {
3978 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, 3990 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
3979 SCTP_CHUNK(err_chunk)); 3991 SCTP_CHUNK(err_chunk));
@@ -4065,7 +4077,8 @@ sctp_disposition_t sctp_sf_unk_chunk(const struct sctp_endpoint *ep,
4065 hdr = unk_chunk->chunk_hdr; 4077 hdr = unk_chunk->chunk_hdr;
4066 err_chunk = sctp_make_op_error(asoc, unk_chunk, 4078 err_chunk = sctp_make_op_error(asoc, unk_chunk,
4067 SCTP_ERROR_UNKNOWN_CHUNK, hdr, 4079 SCTP_ERROR_UNKNOWN_CHUNK, hdr,
4068 WORD_ROUND(ntohs(hdr->length))); 4080 WORD_ROUND(ntohs(hdr->length)),
4081 0);
4069 if (err_chunk) { 4082 if (err_chunk) {
4070 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, 4083 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
4071 SCTP_CHUNK(err_chunk)); 4084 SCTP_CHUNK(err_chunk));
@@ -4084,7 +4097,8 @@ sctp_disposition_t sctp_sf_unk_chunk(const struct sctp_endpoint *ep,
4084 hdr = unk_chunk->chunk_hdr; 4097 hdr = unk_chunk->chunk_hdr;
4085 err_chunk = sctp_make_op_error(asoc, unk_chunk, 4098 err_chunk = sctp_make_op_error(asoc, unk_chunk,
4086 SCTP_ERROR_UNKNOWN_CHUNK, hdr, 4099 SCTP_ERROR_UNKNOWN_CHUNK, hdr,
4087 WORD_ROUND(ntohs(hdr->length))); 4100 WORD_ROUND(ntohs(hdr->length)),
4101 0);
4088 if (err_chunk) { 4102 if (err_chunk) {
4089 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, 4103 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
4090 SCTP_CHUNK(err_chunk)); 4104 SCTP_CHUNK(err_chunk));
@@ -6048,7 +6062,8 @@ static int sctp_eat_data(const struct sctp_association *asoc,
6048 6062
6049 err = sctp_make_op_error(asoc, chunk, SCTP_ERROR_INV_STRM, 6063 err = sctp_make_op_error(asoc, chunk, SCTP_ERROR_INV_STRM,
6050 &data_hdr->stream, 6064 &data_hdr->stream,
6051 sizeof(data_hdr->stream)); 6065 sizeof(data_hdr->stream),
6066 sizeof(u16));
6052 if (err) 6067 if (err)
6053 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, 6068 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
6054 SCTP_CHUNK(err)); 6069 SCTP_CHUNK(err));
diff --git a/net/sctp/socket.c b/net/sctp/socket.c
index 3a95fcb17a9e..44a1ab03a3f0 100644
--- a/net/sctp/socket.c
+++ b/net/sctp/socket.c
@@ -67,6 +67,7 @@
67#include <linux/poll.h> 67#include <linux/poll.h>
68#include <linux/init.h> 68#include <linux/init.h>
69#include <linux/crypto.h> 69#include <linux/crypto.h>
70#include <linux/slab.h>
70 71
71#include <net/ip.h> 72#include <net/ip.h>
72#include <net/icmp.h> 73#include <net/icmp.h>
@@ -394,7 +395,7 @@ SCTP_STATIC int sctp_do_bind(struct sock *sk, union sctp_addr *addr, int len)
394 395
395 /* Refresh ephemeral port. */ 396 /* Refresh ephemeral port. */
396 if (!bp->port) 397 if (!bp->port)
397 bp->port = inet_sk(sk)->num; 398 bp->port = inet_sk(sk)->inet_num;
398 399
399 /* Add the address to the bind address list. 400 /* Add the address to the bind address list.
400 * Use GFP_ATOMIC since BHs will be disabled. 401 * Use GFP_ATOMIC since BHs will be disabled.
@@ -403,7 +404,7 @@ SCTP_STATIC int sctp_do_bind(struct sock *sk, union sctp_addr *addr, int len)
403 404
404 /* Copy back into socket for getsockname() use. */ 405 /* Copy back into socket for getsockname() use. */
405 if (!ret) { 406 if (!ret) {
406 inet_sk(sk)->sport = htons(inet_sk(sk)->num); 407 inet_sk(sk)->inet_sport = htons(inet_sk(sk)->inet_num);
407 af->to_sk_saddr(addr, sk); 408 af->to_sk_saddr(addr, sk);
408 } 409 }
409 410
@@ -1117,7 +1118,7 @@ static int __sctp_connect(struct sock* sk,
1117 } 1118 }
1118 1119
1119 /* Initialize sk's dport and daddr for getpeername() */ 1120 /* Initialize sk's dport and daddr for getpeername() */
1120 inet_sk(sk)->dport = htons(asoc->peer.port); 1121 inet_sk(sk)->inet_dport = htons(asoc->peer.port);
1121 af = sctp_get_af_specific(sa_addr->sa.sa_family); 1122 af = sctp_get_af_specific(sa_addr->sa.sa_family);
1122 af->to_sk_daddr(sa_addr, sk); 1123 af->to_sk_daddr(sa_addr, sk);
1123 sk->sk_err = 0; 1124 sk->sk_err = 0;
@@ -1968,7 +1969,7 @@ SCTP_STATIC int sctp_recvmsg(struct kiocb *iocb, struct sock *sk,
1968 if (err) 1969 if (err)
1969 goto out_free; 1970 goto out_free;
1970 1971
1971 sock_recv_timestamp(msg, sk, skb); 1972 sock_recv_ts_and_drops(msg, sk, skb);
1972 if (sctp_ulpevent_is_notification(event)) { 1973 if (sctp_ulpevent_is_notification(event)) {
1973 msg->msg_flags |= MSG_NOTIFICATION; 1974 msg->msg_flags |= MSG_NOTIFICATION;
1974 sp->pf->event_msgname(event, msg->msg_name, addr_len); 1975 sp->pf->event_msgname(event, msg->msg_name, addr_len);
@@ -2086,6 +2087,8 @@ static int sctp_setsockopt_autoclose(struct sock *sk, char __user *optval,
2086 return -EINVAL; 2087 return -EINVAL;
2087 if (copy_from_user(&sp->autoclose, optval, optlen)) 2088 if (copy_from_user(&sp->autoclose, optval, optlen))
2088 return -EFAULT; 2089 return -EFAULT;
2090 /* make sure it won't exceed MAX_SCHEDULE_TIMEOUT */
2091 sp->autoclose = min_t(long, sp->autoclose, MAX_SCHEDULE_TIMEOUT / HZ);
2089 2092
2090 return 0; 2093 return 0;
2091} 2094}
@@ -2311,11 +2314,10 @@ static int sctp_apply_peer_addr_params(struct sctp_paddrparams *params,
2311 } 2314 }
2312 } 2315 }
2313 2316
2314 /* Note that unless the spp_flag is set to SPP_PMTUD_ENABLE the value 2317 /* Note that a value of zero indicates the current setting should be
2315 * of this field is ignored. Note also that a value of zero 2318 left unchanged.
2316 * indicates the current setting should be left unchanged.
2317 */ 2319 */
2318 if ((params->spp_flags & SPP_PMTUD_ENABLE) && params->spp_pathmaxrxt) { 2320 if (params->spp_pathmaxrxt) {
2319 if (trans) { 2321 if (trans) {
2320 trans->pathmaxrxt = params->spp_pathmaxrxt; 2322 trans->pathmaxrxt = params->spp_pathmaxrxt;
2321 } else if (asoc) { 2323 } else if (asoc) {
@@ -2354,8 +2356,8 @@ static int sctp_setsockopt_peer_addr_params(struct sock *sk,
2354 pmtud_change == SPP_PMTUD || 2356 pmtud_change == SPP_PMTUD ||
2355 sackdelay_change == SPP_SACKDELAY || 2357 sackdelay_change == SPP_SACKDELAY ||
2356 params.spp_sackdelay > 500 || 2358 params.spp_sackdelay > 500 ||
2357 (params.spp_pathmtu 2359 (params.spp_pathmtu &&
2358 && params.spp_pathmtu < SCTP_DEFAULT_MINSEGMENT)) 2360 params.spp_pathmtu < SCTP_DEFAULT_MINSEGMENT))
2359 return -EINVAL; 2361 return -EINVAL;
2360 2362
2361 /* If an address other than INADDR_ANY is specified, and 2363 /* If an address other than INADDR_ANY is specified, and
@@ -3717,9 +3719,12 @@ SCTP_STATIC int sctp_init_sock(struct sock *sk)
3717 sp->hmac = NULL; 3719 sp->hmac = NULL;
3718 3720
3719 SCTP_DBG_OBJCNT_INC(sock); 3721 SCTP_DBG_OBJCNT_INC(sock);
3720 percpu_counter_inc(&sctp_sockets_allocated); 3722
3723 /* Set socket backlog limit. */
3724 sk->sk_backlog.limit = sysctl_sctp_rmem[1];
3721 3725
3722 local_bh_disable(); 3726 local_bh_disable();
3727 percpu_counter_inc(&sctp_sockets_allocated);
3723 sock_prot_inuse_add(sock_net(sk), sk->sk_prot, 1); 3728 sock_prot_inuse_add(sock_net(sk), sk->sk_prot, 1);
3724 local_bh_enable(); 3729 local_bh_enable();
3725 3730
@@ -3736,8 +3741,8 @@ SCTP_STATIC void sctp_destroy_sock(struct sock *sk)
3736 /* Release our hold on the endpoint. */ 3741 /* Release our hold on the endpoint. */
3737 ep = sctp_sk(sk)->ep; 3742 ep = sctp_sk(sk)->ep;
3738 sctp_endpoint_free(ep); 3743 sctp_endpoint_free(ep);
3739 percpu_counter_dec(&sctp_sockets_allocated);
3740 local_bh_disable(); 3744 local_bh_disable();
3745 percpu_counter_dec(&sctp_sockets_allocated);
3741 sock_prot_inuse_add(sock_net(sk), sk->sk_prot, -1); 3746 sock_prot_inuse_add(sock_net(sk), sk->sk_prot, -1);
3742 local_bh_enable(); 3747 local_bh_enable();
3743} 3748}
@@ -4349,90 +4354,6 @@ static int sctp_getsockopt_initmsg(struct sock *sk, int len, char __user *optval
4349 return 0; 4354 return 0;
4350} 4355}
4351 4356
4352static int sctp_getsockopt_peer_addrs_num_old(struct sock *sk, int len,
4353 char __user *optval,
4354 int __user *optlen)
4355{
4356 sctp_assoc_t id;
4357 struct sctp_association *asoc;
4358 struct list_head *pos;
4359 int cnt = 0;
4360
4361 if (len < sizeof(sctp_assoc_t))
4362 return -EINVAL;
4363
4364 if (copy_from_user(&id, optval, sizeof(sctp_assoc_t)))
4365 return -EFAULT;
4366
4367 printk(KERN_WARNING "SCTP: Use of SCTP_GET_PEER_ADDRS_NUM_OLD "
4368 "socket option deprecated\n");
4369 /* For UDP-style sockets, id specifies the association to query. */
4370 asoc = sctp_id2assoc(sk, id);
4371 if (!asoc)
4372 return -EINVAL;
4373
4374 list_for_each(pos, &asoc->peer.transport_addr_list) {
4375 cnt ++;
4376 }
4377
4378 return cnt;
4379}
4380
4381/*
4382 * Old API for getting list of peer addresses. Does not work for 32-bit
4383 * programs running on a 64-bit kernel
4384 */
4385static int sctp_getsockopt_peer_addrs_old(struct sock *sk, int len,
4386 char __user *optval,
4387 int __user *optlen)
4388{
4389 struct sctp_association *asoc;
4390 int cnt = 0;
4391 struct sctp_getaddrs_old getaddrs;
4392 struct sctp_transport *from;
4393 void __user *to;
4394 union sctp_addr temp;
4395 struct sctp_sock *sp = sctp_sk(sk);
4396 int addrlen;
4397
4398 if (len < sizeof(struct sctp_getaddrs_old))
4399 return -EINVAL;
4400
4401 len = sizeof(struct sctp_getaddrs_old);
4402
4403 if (copy_from_user(&getaddrs, optval, len))
4404 return -EFAULT;
4405
4406 if (getaddrs.addr_num <= 0) return -EINVAL;
4407
4408 printk(KERN_WARNING "SCTP: Use of SCTP_GET_PEER_ADDRS_OLD "
4409 "socket option deprecated\n");
4410
4411 /* For UDP-style sockets, id specifies the association to query. */
4412 asoc = sctp_id2assoc(sk, getaddrs.assoc_id);
4413 if (!asoc)
4414 return -EINVAL;
4415
4416 to = (void __user *)getaddrs.addrs;
4417 list_for_each_entry(from, &asoc->peer.transport_addr_list,
4418 transports) {
4419 memcpy(&temp, &from->ipaddr, sizeof(temp));
4420 sctp_get_pf_specific(sk->sk_family)->addr_v4map(sp, &temp);
4421 addrlen = sctp_get_af_specific(sk->sk_family)->sockaddr_len;
4422 if (copy_to_user(to, &temp, addrlen))
4423 return -EFAULT;
4424 to += addrlen ;
4425 cnt ++;
4426 if (cnt >= getaddrs.addr_num) break;
4427 }
4428 getaddrs.addr_num = cnt;
4429 if (put_user(len, optlen))
4430 return -EFAULT;
4431 if (copy_to_user(optval, &getaddrs, len))
4432 return -EFAULT;
4433
4434 return 0;
4435}
4436 4357
4437static int sctp_getsockopt_peer_addrs(struct sock *sk, int len, 4358static int sctp_getsockopt_peer_addrs(struct sock *sk, int len,
4438 char __user *optval, int __user *optlen) 4359 char __user *optval, int __user *optlen)
@@ -4485,125 +4406,6 @@ static int sctp_getsockopt_peer_addrs(struct sock *sk, int len,
4485 return 0; 4406 return 0;
4486} 4407}
4487 4408
4488static int sctp_getsockopt_local_addrs_num_old(struct sock *sk, int len,
4489 char __user *optval,
4490 int __user *optlen)
4491{
4492 sctp_assoc_t id;
4493 struct sctp_bind_addr *bp;
4494 struct sctp_association *asoc;
4495 struct sctp_sockaddr_entry *addr;
4496 int cnt = 0;
4497
4498 if (len < sizeof(sctp_assoc_t))
4499 return -EINVAL;
4500
4501 if (copy_from_user(&id, optval, sizeof(sctp_assoc_t)))
4502 return -EFAULT;
4503
4504 printk(KERN_WARNING "SCTP: Use of SCTP_GET_LOCAL_ADDRS_NUM_OLD "
4505 "socket option deprecated\n");
4506
4507 /*
4508 * For UDP-style sockets, id specifies the association to query.
4509 * If the id field is set to the value '0' then the locally bound
4510 * addresses are returned without regard to any particular
4511 * association.
4512 */
4513 if (0 == id) {
4514 bp = &sctp_sk(sk)->ep->base.bind_addr;
4515 } else {
4516 asoc = sctp_id2assoc(sk, id);
4517 if (!asoc)
4518 return -EINVAL;
4519 bp = &asoc->base.bind_addr;
4520 }
4521
4522 /* If the endpoint is bound to 0.0.0.0 or ::0, count the valid
4523 * addresses from the global local address list.
4524 */
4525 if (sctp_list_single_entry(&bp->address_list)) {
4526 addr = list_entry(bp->address_list.next,
4527 struct sctp_sockaddr_entry, list);
4528 if (sctp_is_any(sk, &addr->a)) {
4529 rcu_read_lock();
4530 list_for_each_entry_rcu(addr,
4531 &sctp_local_addr_list, list) {
4532 if (!addr->valid)
4533 continue;
4534
4535 if ((PF_INET == sk->sk_family) &&
4536 (AF_INET6 == addr->a.sa.sa_family))
4537 continue;
4538
4539 if ((PF_INET6 == sk->sk_family) &&
4540 inet_v6_ipv6only(sk) &&
4541 (AF_INET == addr->a.sa.sa_family))
4542 continue;
4543
4544 cnt++;
4545 }
4546 rcu_read_unlock();
4547 } else {
4548 cnt = 1;
4549 }
4550 goto done;
4551 }
4552
4553 /* Protection on the bound address list is not needed,
4554 * since in the socket option context we hold the socket lock,
4555 * so there is no way that the bound address list can change.
4556 */
4557 list_for_each_entry(addr, &bp->address_list, list) {
4558 cnt ++;
4559 }
4560done:
4561 return cnt;
4562}
4563
4564/* Helper function that copies local addresses to user and returns the number
4565 * of addresses copied.
4566 */
4567static int sctp_copy_laddrs_old(struct sock *sk, __u16 port,
4568 int max_addrs, void *to,
4569 int *bytes_copied)
4570{
4571 struct sctp_sockaddr_entry *addr;
4572 union sctp_addr temp;
4573 int cnt = 0;
4574 int addrlen;
4575
4576 rcu_read_lock();
4577 list_for_each_entry_rcu(addr, &sctp_local_addr_list, list) {
4578 if (!addr->valid)
4579 continue;
4580
4581 if ((PF_INET == sk->sk_family) &&
4582 (AF_INET6 == addr->a.sa.sa_family))
4583 continue;
4584 if ((PF_INET6 == sk->sk_family) &&
4585 inet_v6_ipv6only(sk) &&
4586 (AF_INET == addr->a.sa.sa_family))
4587 continue;
4588 memcpy(&temp, &addr->a, sizeof(temp));
4589 if (!temp.v4.sin_port)
4590 temp.v4.sin_port = htons(port);
4591
4592 sctp_get_pf_specific(sk->sk_family)->addr_v4map(sctp_sk(sk),
4593 &temp);
4594 addrlen = sctp_get_af_specific(temp.sa.sa_family)->sockaddr_len;
4595 memcpy(to, &temp, addrlen);
4596
4597 to += addrlen;
4598 *bytes_copied += addrlen;
4599 cnt ++;
4600 if (cnt >= max_addrs) break;
4601 }
4602 rcu_read_unlock();
4603
4604 return cnt;
4605}
4606
4607static int sctp_copy_laddrs(struct sock *sk, __u16 port, void *to, 4409static int sctp_copy_laddrs(struct sock *sk, __u16 port, void *to,
4608 size_t space_left, int *bytes_copied) 4410 size_t space_left, int *bytes_copied)
4609{ 4411{
@@ -4647,112 +4449,6 @@ static int sctp_copy_laddrs(struct sock *sk, __u16 port, void *to,
4647 return cnt; 4449 return cnt;
4648} 4450}
4649 4451
4650/* Old API for getting list of local addresses. Does not work for 32-bit
4651 * programs running on a 64-bit kernel
4652 */
4653static int sctp_getsockopt_local_addrs_old(struct sock *sk, int len,
4654 char __user *optval, int __user *optlen)
4655{
4656 struct sctp_bind_addr *bp;
4657 struct sctp_association *asoc;
4658 int cnt = 0;
4659 struct sctp_getaddrs_old getaddrs;
4660 struct sctp_sockaddr_entry *addr;
4661 void __user *to;
4662 union sctp_addr temp;
4663 struct sctp_sock *sp = sctp_sk(sk);
4664 int addrlen;
4665 int err = 0;
4666 void *addrs;
4667 void *buf;
4668 int bytes_copied = 0;
4669
4670 if (len < sizeof(struct sctp_getaddrs_old))
4671 return -EINVAL;
4672
4673 len = sizeof(struct sctp_getaddrs_old);
4674 if (copy_from_user(&getaddrs, optval, len))
4675 return -EFAULT;
4676
4677 if (getaddrs.addr_num <= 0 ||
4678 getaddrs.addr_num >= (INT_MAX / sizeof(union sctp_addr)))
4679 return -EINVAL;
4680
4681 printk(KERN_WARNING "SCTP: Use of SCTP_GET_LOCAL_ADDRS_OLD "
4682 "socket option deprecated\n");
4683
4684 /*
4685 * For UDP-style sockets, id specifies the association to query.
4686 * If the id field is set to the value '0' then the locally bound
4687 * addresses are returned without regard to any particular
4688 * association.
4689 */
4690 if (0 == getaddrs.assoc_id) {
4691 bp = &sctp_sk(sk)->ep->base.bind_addr;
4692 } else {
4693 asoc = sctp_id2assoc(sk, getaddrs.assoc_id);
4694 if (!asoc)
4695 return -EINVAL;
4696 bp = &asoc->base.bind_addr;
4697 }
4698
4699 to = getaddrs.addrs;
4700
4701 /* Allocate space for a local instance of packed array to hold all
4702 * the data. We store addresses here first and then put write them
4703 * to the user in one shot.
4704 */
4705 addrs = kmalloc(sizeof(union sctp_addr) * getaddrs.addr_num,
4706 GFP_KERNEL);
4707 if (!addrs)
4708 return -ENOMEM;
4709
4710 /* If the endpoint is bound to 0.0.0.0 or ::0, get the valid
4711 * addresses from the global local address list.
4712 */
4713 if (sctp_list_single_entry(&bp->address_list)) {
4714 addr = list_entry(bp->address_list.next,
4715 struct sctp_sockaddr_entry, list);
4716 if (sctp_is_any(sk, &addr->a)) {
4717 cnt = sctp_copy_laddrs_old(sk, bp->port,
4718 getaddrs.addr_num,
4719 addrs, &bytes_copied);
4720 goto copy_getaddrs;
4721 }
4722 }
4723
4724 buf = addrs;
4725 /* Protection on the bound address list is not needed since
4726 * in the socket option context we hold a socket lock and
4727 * thus the bound address list can't change.
4728 */
4729 list_for_each_entry(addr, &bp->address_list, list) {
4730 memcpy(&temp, &addr->a, sizeof(temp));
4731 sctp_get_pf_specific(sk->sk_family)->addr_v4map(sp, &temp);
4732 addrlen = sctp_get_af_specific(temp.sa.sa_family)->sockaddr_len;
4733 memcpy(buf, &temp, addrlen);
4734 buf += addrlen;
4735 bytes_copied += addrlen;
4736 cnt ++;
4737 if (cnt >= getaddrs.addr_num) break;
4738 }
4739
4740copy_getaddrs:
4741 /* copy the entire address list into the user provided space */
4742 if (copy_to_user(to, addrs, bytes_copied)) {
4743 err = -EFAULT;
4744 goto error;
4745 }
4746
4747 /* copy the leading structure back to user */
4748 getaddrs.addr_num = cnt;
4749 if (copy_to_user(optval, &getaddrs, len))
4750 err = -EFAULT;
4751
4752error:
4753 kfree(addrs);
4754 return err;
4755}
4756 4452
4757static int sctp_getsockopt_local_addrs(struct sock *sk, int len, 4453static int sctp_getsockopt_local_addrs(struct sock *sk, int len,
4758 char __user *optval, int __user *optlen) 4454 char __user *optval, int __user *optlen)
@@ -5603,22 +5299,6 @@ SCTP_STATIC int sctp_getsockopt(struct sock *sk, int level, int optname,
5603 case SCTP_INITMSG: 5299 case SCTP_INITMSG:
5604 retval = sctp_getsockopt_initmsg(sk, len, optval, optlen); 5300 retval = sctp_getsockopt_initmsg(sk, len, optval, optlen);
5605 break; 5301 break;
5606 case SCTP_GET_PEER_ADDRS_NUM_OLD:
5607 retval = sctp_getsockopt_peer_addrs_num_old(sk, len, optval,
5608 optlen);
5609 break;
5610 case SCTP_GET_LOCAL_ADDRS_NUM_OLD:
5611 retval = sctp_getsockopt_local_addrs_num_old(sk, len, optval,
5612 optlen);
5613 break;
5614 case SCTP_GET_PEER_ADDRS_OLD:
5615 retval = sctp_getsockopt_peer_addrs_old(sk, len, optval,
5616 optlen);
5617 break;
5618 case SCTP_GET_LOCAL_ADDRS_OLD:
5619 retval = sctp_getsockopt_local_addrs_old(sk, len, optval,
5620 optlen);
5621 break;
5622 case SCTP_GET_PEER_ADDRS: 5302 case SCTP_GET_PEER_ADDRS:
5623 retval = sctp_getsockopt_peer_addrs(sk, len, optval, 5303 retval = sctp_getsockopt_peer_addrs(sk, len, optval,
5624 optlen); 5304 optlen);
@@ -5861,7 +5541,7 @@ pp_not_found:
5861 */ 5541 */
5862success: 5542success:
5863 if (!sctp_sk(sk)->bind_hash) { 5543 if (!sctp_sk(sk)->bind_hash) {
5864 inet_sk(sk)->num = snum; 5544 inet_sk(sk)->inet_num = snum;
5865 sk_add_bind_node(sk, &pp->owner); 5545 sk_add_bind_node(sk, &pp->owner);
5866 sctp_sk(sk)->bind_hash = pp; 5546 sctp_sk(sk)->bind_hash = pp;
5867 } 5547 }
@@ -5933,7 +5613,7 @@ SCTP_STATIC int sctp_listen_start(struct sock *sk, int backlog)
5933 if (sctp_autobind(sk)) 5613 if (sctp_autobind(sk))
5934 return -EAGAIN; 5614 return -EAGAIN;
5935 } else { 5615 } else {
5936 if (sctp_get_port(sk, inet_sk(sk)->num)) { 5616 if (sctp_get_port(sk, inet_sk(sk)->inet_num)) {
5937 sk->sk_state = SCTP_SS_CLOSED; 5617 sk->sk_state = SCTP_SS_CLOSED;
5938 return -EADDRINUSE; 5618 return -EADDRINUSE;
5939 } 5619 }
@@ -6104,14 +5784,14 @@ static void sctp_bucket_destroy(struct sctp_bind_bucket *pp)
6104static inline void __sctp_put_port(struct sock *sk) 5784static inline void __sctp_put_port(struct sock *sk)
6105{ 5785{
6106 struct sctp_bind_hashbucket *head = 5786 struct sctp_bind_hashbucket *head =
6107 &sctp_port_hashtable[sctp_phashfn(inet_sk(sk)->num)]; 5787 &sctp_port_hashtable[sctp_phashfn(inet_sk(sk)->inet_num)];
6108 struct sctp_bind_bucket *pp; 5788 struct sctp_bind_bucket *pp;
6109 5789
6110 sctp_spin_lock(&head->lock); 5790 sctp_spin_lock(&head->lock);
6111 pp = sctp_sk(sk)->bind_hash; 5791 pp = sctp_sk(sk)->bind_hash;
6112 __sk_del_bind_node(sk); 5792 __sk_del_bind_node(sk);
6113 sctp_sk(sk)->bind_hash = NULL; 5793 sctp_sk(sk)->bind_hash = NULL;
6114 inet_sk(sk)->num = 0; 5794 inet_sk(sk)->inet_num = 0;
6115 sctp_bucket_destroy(pp); 5795 sctp_bucket_destroy(pp);
6116 sctp_spin_unlock(&head->lock); 5796 sctp_spin_unlock(&head->lock);
6117} 5797}
@@ -6138,7 +5818,7 @@ static int sctp_autobind(struct sock *sk)
6138 /* Initialize a local sockaddr structure to INADDR_ANY. */ 5818 /* Initialize a local sockaddr structure to INADDR_ANY. */
6139 af = sctp_sk(sk)->pf->af; 5819 af = sctp_sk(sk)->pf->af;
6140 5820
6141 port = htons(inet_sk(sk)->num); 5821 port = htons(inet_sk(sk)->inet_num);
6142 af->inaddr_any(&autoaddr, port); 5822 af->inaddr_any(&autoaddr, port);
6143 5823
6144 return sctp_do_bind(sk, &autoaddr, af->sockaddr_len); 5824 return sctp_do_bind(sk, &autoaddr, af->sockaddr_len);
@@ -6509,6 +6189,16 @@ do_nonblock:
6509 goto out; 6189 goto out;
6510} 6190}
6511 6191
6192void sctp_data_ready(struct sock *sk, int len)
6193{
6194 read_lock_bh(&sk->sk_callback_lock);
6195 if (sk_has_sleeper(sk))
6196 wake_up_interruptible_sync_poll(sk->sk_sleep, POLLIN |
6197 POLLRDNORM | POLLRDBAND);
6198 sk_wake_async(sk, SOCK_WAKE_WAITD, POLL_IN);
6199 read_unlock_bh(&sk->sk_callback_lock);
6200}
6201
6512/* If socket sndbuf has changed, wake up all per association waiters. */ 6202/* If socket sndbuf has changed, wake up all per association waiters. */
6513void sctp_write_space(struct sock *sk) 6203void sctp_write_space(struct sock *sk)
6514{ 6204{
@@ -6683,7 +6373,7 @@ void sctp_copy_sock(struct sock *newsk, struct sock *sk,
6683 struct sctp_association *asoc) 6373 struct sctp_association *asoc)
6684{ 6374{
6685 struct inet_sock *inet = inet_sk(sk); 6375 struct inet_sock *inet = inet_sk(sk);
6686 struct inet_sock *newinet = inet_sk(newsk); 6376 struct inet_sock *newinet;
6687 6377
6688 newsk->sk_type = sk->sk_type; 6378 newsk->sk_type = sk->sk_type;
6689 newsk->sk_bound_dev_if = sk->sk_bound_dev_if; 6379 newsk->sk_bound_dev_if = sk->sk_bound_dev_if;
@@ -6707,12 +6397,12 @@ void sctp_copy_sock(struct sock *newsk, struct sock *sk,
6707 /* Initialize sk's sport, dport, rcv_saddr and daddr for 6397 /* Initialize sk's sport, dport, rcv_saddr and daddr for
6708 * getsockname() and getpeername() 6398 * getsockname() and getpeername()
6709 */ 6399 */
6710 newinet->sport = inet->sport; 6400 newinet->inet_sport = inet->inet_sport;
6711 newinet->saddr = inet->saddr; 6401 newinet->inet_saddr = inet->inet_saddr;
6712 newinet->rcv_saddr = inet->rcv_saddr; 6402 newinet->inet_rcv_saddr = inet->inet_rcv_saddr;
6713 newinet->dport = htons(asoc->peer.port); 6403 newinet->inet_dport = htons(asoc->peer.port);
6714 newinet->pmtudisc = inet->pmtudisc; 6404 newinet->pmtudisc = inet->pmtudisc;
6715 newinet->id = asoc->next_tsn ^ jiffies; 6405 newinet->inet_id = asoc->next_tsn ^ jiffies;
6716 6406
6717 newinet->uc_ttl = inet->uc_ttl; 6407 newinet->uc_ttl = inet->uc_ttl;
6718 newinet->mc_loop = 1; 6408 newinet->mc_loop = 1;
@@ -6751,13 +6441,13 @@ static void sctp_sock_migrate(struct sock *oldsk, struct sock *newsk,
6751 newsp->hmac = NULL; 6441 newsp->hmac = NULL;
6752 6442
6753 /* Hook this new socket in to the bind_hash list. */ 6443 /* Hook this new socket in to the bind_hash list. */
6754 head = &sctp_port_hashtable[sctp_phashfn(inet_sk(oldsk)->num)]; 6444 head = &sctp_port_hashtable[sctp_phashfn(inet_sk(oldsk)->inet_num)];
6755 sctp_local_bh_disable(); 6445 sctp_local_bh_disable();
6756 sctp_spin_lock(&head->lock); 6446 sctp_spin_lock(&head->lock);
6757 pp = sctp_sk(oldsk)->bind_hash; 6447 pp = sctp_sk(oldsk)->bind_hash;
6758 sk_add_bind_node(newsk, &pp->owner); 6448 sk_add_bind_node(newsk, &pp->owner);
6759 sctp_sk(newsk)->bind_hash = pp; 6449 sctp_sk(newsk)->bind_hash = pp;
6760 inet_sk(newsk)->num = inet_sk(oldsk)->num; 6450 inet_sk(newsk)->inet_num = inet_sk(oldsk)->inet_num;
6761 sctp_spin_unlock(&head->lock); 6451 sctp_spin_unlock(&head->lock);
6762 sctp_local_bh_enable(); 6452 sctp_local_bh_enable();
6763 6453
diff --git a/net/sctp/ssnmap.c b/net/sctp/ssnmap.c
index 737d330e5ffc..442ad4ed6315 100644
--- a/net/sctp/ssnmap.c
+++ b/net/sctp/ssnmap.c
@@ -37,6 +37,7 @@
37 */ 37 */
38 38
39#include <linux/types.h> 39#include <linux/types.h>
40#include <linux/slab.h>
40#include <net/sctp/sctp.h> 41#include <net/sctp/sctp.h>
41#include <net/sctp/sm.h> 42#include <net/sctp/sm.h>
42 43
diff --git a/net/sctp/sysctl.c b/net/sctp/sysctl.c
index ab7151da120f..832590bbe0c0 100644
--- a/net/sctp/sysctl.c
+++ b/net/sctp/sysctl.c
@@ -52,6 +52,7 @@ static int int_max = INT_MAX;
52static int sack_timer_min = 1; 52static int sack_timer_min = 1;
53static int sack_timer_max = 500; 53static int sack_timer_max = 500;
54static int addr_scope_max = 3; /* check sctp_scope_policy_t in include/net/sctp/constants.h for max entries */ 54static int addr_scope_max = 3; /* check sctp_scope_policy_t in include/net/sctp/constants.h for max entries */
55static int rwnd_scale_max = 16;
55 56
56extern int sysctl_sctp_mem[3]; 57extern int sysctl_sctp_mem[3];
57extern int sysctl_sctp_rmem[3]; 58extern int sysctl_sctp_rmem[3];
@@ -59,180 +60,145 @@ extern int sysctl_sctp_wmem[3];
59 60
60static ctl_table sctp_table[] = { 61static ctl_table sctp_table[] = {
61 { 62 {
62 .ctl_name = NET_SCTP_RTO_INITIAL,
63 .procname = "rto_initial", 63 .procname = "rto_initial",
64 .data = &sctp_rto_initial, 64 .data = &sctp_rto_initial,
65 .maxlen = sizeof(unsigned int), 65 .maxlen = sizeof(unsigned int),
66 .mode = 0644, 66 .mode = 0644,
67 .proc_handler = proc_dointvec_minmax, 67 .proc_handler = proc_dointvec_minmax,
68 .strategy = sysctl_intvec,
69 .extra1 = &one, 68 .extra1 = &one,
70 .extra2 = &timer_max 69 .extra2 = &timer_max
71 }, 70 },
72 { 71 {
73 .ctl_name = NET_SCTP_RTO_MIN,
74 .procname = "rto_min", 72 .procname = "rto_min",
75 .data = &sctp_rto_min, 73 .data = &sctp_rto_min,
76 .maxlen = sizeof(unsigned int), 74 .maxlen = sizeof(unsigned int),
77 .mode = 0644, 75 .mode = 0644,
78 .proc_handler = proc_dointvec_minmax, 76 .proc_handler = proc_dointvec_minmax,
79 .strategy = sysctl_intvec,
80 .extra1 = &one, 77 .extra1 = &one,
81 .extra2 = &timer_max 78 .extra2 = &timer_max
82 }, 79 },
83 { 80 {
84 .ctl_name = NET_SCTP_RTO_MAX,
85 .procname = "rto_max", 81 .procname = "rto_max",
86 .data = &sctp_rto_max, 82 .data = &sctp_rto_max,
87 .maxlen = sizeof(unsigned int), 83 .maxlen = sizeof(unsigned int),
88 .mode = 0644, 84 .mode = 0644,
89 .proc_handler = proc_dointvec_minmax, 85 .proc_handler = proc_dointvec_minmax,
90 .strategy = sysctl_intvec,
91 .extra1 = &one, 86 .extra1 = &one,
92 .extra2 = &timer_max 87 .extra2 = &timer_max
93 }, 88 },
94 { 89 {
95 .ctl_name = NET_SCTP_VALID_COOKIE_LIFE,
96 .procname = "valid_cookie_life", 90 .procname = "valid_cookie_life",
97 .data = &sctp_valid_cookie_life, 91 .data = &sctp_valid_cookie_life,
98 .maxlen = sizeof(unsigned int), 92 .maxlen = sizeof(unsigned int),
99 .mode = 0644, 93 .mode = 0644,
100 .proc_handler = proc_dointvec_minmax, 94 .proc_handler = proc_dointvec_minmax,
101 .strategy = sysctl_intvec,
102 .extra1 = &one, 95 .extra1 = &one,
103 .extra2 = &timer_max 96 .extra2 = &timer_max
104 }, 97 },
105 { 98 {
106 .ctl_name = NET_SCTP_MAX_BURST,
107 .procname = "max_burst", 99 .procname = "max_burst",
108 .data = &sctp_max_burst, 100 .data = &sctp_max_burst,
109 .maxlen = sizeof(int), 101 .maxlen = sizeof(int),
110 .mode = 0644, 102 .mode = 0644,
111 .proc_handler = proc_dointvec_minmax, 103 .proc_handler = proc_dointvec_minmax,
112 .strategy = sysctl_intvec,
113 .extra1 = &zero, 104 .extra1 = &zero,
114 .extra2 = &int_max 105 .extra2 = &int_max
115 }, 106 },
116 { 107 {
117 .ctl_name = NET_SCTP_ASSOCIATION_MAX_RETRANS,
118 .procname = "association_max_retrans", 108 .procname = "association_max_retrans",
119 .data = &sctp_max_retrans_association, 109 .data = &sctp_max_retrans_association,
120 .maxlen = sizeof(int), 110 .maxlen = sizeof(int),
121 .mode = 0644, 111 .mode = 0644,
122 .proc_handler = proc_dointvec_minmax, 112 .proc_handler = proc_dointvec_minmax,
123 .strategy = sysctl_intvec,
124 .extra1 = &one, 113 .extra1 = &one,
125 .extra2 = &int_max 114 .extra2 = &int_max
126 }, 115 },
127 { 116 {
128 .ctl_name = NET_SCTP_SNDBUF_POLICY,
129 .procname = "sndbuf_policy", 117 .procname = "sndbuf_policy",
130 .data = &sctp_sndbuf_policy, 118 .data = &sctp_sndbuf_policy,
131 .maxlen = sizeof(int), 119 .maxlen = sizeof(int),
132 .mode = 0644, 120 .mode = 0644,
133 .proc_handler = proc_dointvec, 121 .proc_handler = proc_dointvec,
134 .strategy = sysctl_intvec
135 }, 122 },
136 { 123 {
137 .ctl_name = NET_SCTP_RCVBUF_POLICY,
138 .procname = "rcvbuf_policy", 124 .procname = "rcvbuf_policy",
139 .data = &sctp_rcvbuf_policy, 125 .data = &sctp_rcvbuf_policy,
140 .maxlen = sizeof(int), 126 .maxlen = sizeof(int),
141 .mode = 0644, 127 .mode = 0644,
142 .proc_handler = proc_dointvec, 128 .proc_handler = proc_dointvec,
143 .strategy = sysctl_intvec
144 }, 129 },
145 { 130 {
146 .ctl_name = NET_SCTP_PATH_MAX_RETRANS,
147 .procname = "path_max_retrans", 131 .procname = "path_max_retrans",
148 .data = &sctp_max_retrans_path, 132 .data = &sctp_max_retrans_path,
149 .maxlen = sizeof(int), 133 .maxlen = sizeof(int),
150 .mode = 0644, 134 .mode = 0644,
151 .proc_handler = proc_dointvec_minmax, 135 .proc_handler = proc_dointvec_minmax,
152 .strategy = sysctl_intvec,
153 .extra1 = &one, 136 .extra1 = &one,
154 .extra2 = &int_max 137 .extra2 = &int_max
155 }, 138 },
156 { 139 {
157 .ctl_name = NET_SCTP_MAX_INIT_RETRANSMITS,
158 .procname = "max_init_retransmits", 140 .procname = "max_init_retransmits",
159 .data = &sctp_max_retrans_init, 141 .data = &sctp_max_retrans_init,
160 .maxlen = sizeof(int), 142 .maxlen = sizeof(int),
161 .mode = 0644, 143 .mode = 0644,
162 .proc_handler = proc_dointvec_minmax, 144 .proc_handler = proc_dointvec_minmax,
163 .strategy = sysctl_intvec,
164 .extra1 = &one, 145 .extra1 = &one,
165 .extra2 = &int_max 146 .extra2 = &int_max
166 }, 147 },
167 { 148 {
168 .ctl_name = NET_SCTP_HB_INTERVAL,
169 .procname = "hb_interval", 149 .procname = "hb_interval",
170 .data = &sctp_hb_interval, 150 .data = &sctp_hb_interval,
171 .maxlen = sizeof(unsigned int), 151 .maxlen = sizeof(unsigned int),
172 .mode = 0644, 152 .mode = 0644,
173 .proc_handler = proc_dointvec_minmax, 153 .proc_handler = proc_dointvec_minmax,
174 .strategy = sysctl_intvec,
175 .extra1 = &one, 154 .extra1 = &one,
176 .extra2 = &timer_max 155 .extra2 = &timer_max
177 }, 156 },
178 { 157 {
179 .ctl_name = NET_SCTP_PRESERVE_ENABLE,
180 .procname = "cookie_preserve_enable", 158 .procname = "cookie_preserve_enable",
181 .data = &sctp_cookie_preserve_enable, 159 .data = &sctp_cookie_preserve_enable,
182 .maxlen = sizeof(int), 160 .maxlen = sizeof(int),
183 .mode = 0644, 161 .mode = 0644,
184 .proc_handler = proc_dointvec, 162 .proc_handler = proc_dointvec,
185 .strategy = sysctl_intvec
186 }, 163 },
187 { 164 {
188 .ctl_name = NET_SCTP_RTO_ALPHA,
189 .procname = "rto_alpha_exp_divisor", 165 .procname = "rto_alpha_exp_divisor",
190 .data = &sctp_rto_alpha, 166 .data = &sctp_rto_alpha,
191 .maxlen = sizeof(int), 167 .maxlen = sizeof(int),
192 .mode = 0444, 168 .mode = 0444,
193 .proc_handler = proc_dointvec, 169 .proc_handler = proc_dointvec,
194 .strategy = sysctl_intvec
195 }, 170 },
196 { 171 {
197 .ctl_name = NET_SCTP_RTO_BETA,
198 .procname = "rto_beta_exp_divisor", 172 .procname = "rto_beta_exp_divisor",
199 .data = &sctp_rto_beta, 173 .data = &sctp_rto_beta,
200 .maxlen = sizeof(int), 174 .maxlen = sizeof(int),
201 .mode = 0444, 175 .mode = 0444,
202 .proc_handler = proc_dointvec, 176 .proc_handler = proc_dointvec,
203 .strategy = sysctl_intvec
204 }, 177 },
205 { 178 {
206 .ctl_name = NET_SCTP_ADDIP_ENABLE,
207 .procname = "addip_enable", 179 .procname = "addip_enable",
208 .data = &sctp_addip_enable, 180 .data = &sctp_addip_enable,
209 .maxlen = sizeof(int), 181 .maxlen = sizeof(int),
210 .mode = 0644, 182 .mode = 0644,
211 .proc_handler = proc_dointvec, 183 .proc_handler = proc_dointvec,
212 .strategy = sysctl_intvec
213 }, 184 },
214 { 185 {
215 .ctl_name = NET_SCTP_PRSCTP_ENABLE,
216 .procname = "prsctp_enable", 186 .procname = "prsctp_enable",
217 .data = &sctp_prsctp_enable, 187 .data = &sctp_prsctp_enable,
218 .maxlen = sizeof(int), 188 .maxlen = sizeof(int),
219 .mode = 0644, 189 .mode = 0644,
220 .proc_handler = proc_dointvec, 190 .proc_handler = proc_dointvec,
221 .strategy = sysctl_intvec
222 }, 191 },
223 { 192 {
224 .ctl_name = NET_SCTP_SACK_TIMEOUT,
225 .procname = "sack_timeout", 193 .procname = "sack_timeout",
226 .data = &sctp_sack_timeout, 194 .data = &sctp_sack_timeout,
227 .maxlen = sizeof(int), 195 .maxlen = sizeof(int),
228 .mode = 0644, 196 .mode = 0644,
229 .proc_handler = proc_dointvec_minmax, 197 .proc_handler = proc_dointvec_minmax,
230 .strategy = sysctl_intvec,
231 .extra1 = &sack_timer_min, 198 .extra1 = &sack_timer_min,
232 .extra2 = &sack_timer_max, 199 .extra2 = &sack_timer_max,
233 }, 200 },
234 { 201 {
235 .ctl_name = CTL_UNNUMBERED,
236 .procname = "sctp_mem", 202 .procname = "sctp_mem",
237 .data = &sysctl_sctp_mem, 203 .data = &sysctl_sctp_mem,
238 .maxlen = sizeof(sysctl_sctp_mem), 204 .maxlen = sizeof(sysctl_sctp_mem),
@@ -240,7 +206,6 @@ static ctl_table sctp_table[] = {
240 .proc_handler = proc_dointvec, 206 .proc_handler = proc_dointvec,
241 }, 207 },
242 { 208 {
243 .ctl_name = CTL_UNNUMBERED,
244 .procname = "sctp_rmem", 209 .procname = "sctp_rmem",
245 .data = &sysctl_sctp_rmem, 210 .data = &sysctl_sctp_rmem,
246 .maxlen = sizeof(sysctl_sctp_rmem), 211 .maxlen = sizeof(sysctl_sctp_rmem),
@@ -248,7 +213,6 @@ static ctl_table sctp_table[] = {
248 .proc_handler = proc_dointvec, 213 .proc_handler = proc_dointvec,
249 }, 214 },
250 { 215 {
251 .ctl_name = CTL_UNNUMBERED,
252 .procname = "sctp_wmem", 216 .procname = "sctp_wmem",
253 .data = &sysctl_sctp_wmem, 217 .data = &sysctl_sctp_wmem,
254 .maxlen = sizeof(sysctl_sctp_wmem), 218 .maxlen = sizeof(sysctl_sctp_wmem),
@@ -256,40 +220,44 @@ static ctl_table sctp_table[] = {
256 .proc_handler = proc_dointvec, 220 .proc_handler = proc_dointvec,
257 }, 221 },
258 { 222 {
259 .ctl_name = CTL_UNNUMBERED,
260 .procname = "auth_enable", 223 .procname = "auth_enable",
261 .data = &sctp_auth_enable, 224 .data = &sctp_auth_enable,
262 .maxlen = sizeof(int), 225 .maxlen = sizeof(int),
263 .mode = 0644, 226 .mode = 0644,
264 .proc_handler = proc_dointvec, 227 .proc_handler = proc_dointvec,
265 .strategy = sysctl_intvec
266 }, 228 },
267 { 229 {
268 .ctl_name = CTL_UNNUMBERED,
269 .procname = "addip_noauth_enable", 230 .procname = "addip_noauth_enable",
270 .data = &sctp_addip_noauth, 231 .data = &sctp_addip_noauth,
271 .maxlen = sizeof(int), 232 .maxlen = sizeof(int),
272 .mode = 0644, 233 .mode = 0644,
273 .proc_handler = proc_dointvec, 234 .proc_handler = proc_dointvec,
274 .strategy = sysctl_intvec
275 }, 235 },
276 { 236 {
277 .ctl_name = CTL_UNNUMBERED,
278 .procname = "addr_scope_policy", 237 .procname = "addr_scope_policy",
279 .data = &sctp_scope_policy, 238 .data = &sctp_scope_policy,
280 .maxlen = sizeof(int), 239 .maxlen = sizeof(int),
281 .mode = 0644, 240 .mode = 0644,
282 .proc_handler = &proc_dointvec_minmax, 241 .proc_handler = proc_dointvec_minmax,
283 .strategy = &sysctl_intvec,
284 .extra1 = &zero, 242 .extra1 = &zero,
285 .extra2 = &addr_scope_max, 243 .extra2 = &addr_scope_max,
286 }, 244 },
287 { .ctl_name = 0 } 245 {
246 .procname = "rwnd_update_shift",
247 .data = &sctp_rwnd_upd_shift,
248 .maxlen = sizeof(int),
249 .mode = 0644,
250 .proc_handler = &proc_dointvec_minmax,
251 .extra1 = &one,
252 .extra2 = &rwnd_scale_max,
253 },
254
255 { /* sentinel */ }
288}; 256};
289 257
290static struct ctl_path sctp_path[] = { 258static struct ctl_path sctp_path[] = {
291 { .procname = "net", .ctl_name = CTL_NET, }, 259 { .procname = "net", },
292 { .procname = "sctp", .ctl_name = NET_SCTP, }, 260 { .procname = "sctp", },
293 { } 261 { }
294}; 262};
295 263
diff --git a/net/sctp/transport.c b/net/sctp/transport.c
index 37a1184d789f..165d54e07fcd 100644
--- a/net/sctp/transport.c
+++ b/net/sctp/transport.c
@@ -48,6 +48,7 @@
48 * be incorporated into the next SCTP release. 48 * be incorporated into the next SCTP release.
49 */ 49 */
50 50
51#include <linux/slab.h>
51#include <linux/types.h> 52#include <linux/types.h>
52#include <linux/random.h> 53#include <linux/random.h>
53#include <net/sctp/sctp.h> 54#include <net/sctp/sctp.h>
@@ -83,7 +84,6 @@ static struct sctp_transport *sctp_transport_init(struct sctp_transport *peer,
83 peer->fast_recovery = 0; 84 peer->fast_recovery = 0;
84 85
85 peer->last_time_heard = jiffies; 86 peer->last_time_heard = jiffies;
86 peer->last_time_used = jiffies;
87 peer->last_time_ecne_reduced = jiffies; 87 peer->last_time_ecne_reduced = jiffies;
88 88
89 peer->init_sent_count = 0; 89 peer->init_sent_count = 0;
@@ -108,6 +108,8 @@ static struct sctp_transport *sctp_transport_init(struct sctp_transport *peer,
108 (unsigned long)peer); 108 (unsigned long)peer);
109 setup_timer(&peer->hb_timer, sctp_generate_heartbeat_event, 109 setup_timer(&peer->hb_timer, sctp_generate_heartbeat_event,
110 (unsigned long)peer); 110 (unsigned long)peer);
111 setup_timer(&peer->proto_unreach_timer,
112 sctp_generate_proto_unreach_event, (unsigned long)peer);
111 113
112 /* Initialize the 64-bit random nonce sent with heartbeat. */ 114 /* Initialize the 64-bit random nonce sent with heartbeat. */
113 get_random_bytes(&peer->hb_nonce, sizeof(peer->hb_nonce)); 115 get_random_bytes(&peer->hb_nonce, sizeof(peer->hb_nonce));
@@ -171,6 +173,10 @@ void sctp_transport_free(struct sctp_transport *transport)
171 del_timer(&transport->T3_rtx_timer)) 173 del_timer(&transport->T3_rtx_timer))
172 sctp_transport_put(transport); 174 sctp_transport_put(transport);
173 175
176 /* Delete the ICMP proto unreachable timer if it's active. */
177 if (timer_pending(&transport->proto_unreach_timer) &&
178 del_timer(&transport->proto_unreach_timer))
179 sctp_association_put(transport->asoc);
174 180
175 sctp_transport_put(transport); 181 sctp_transport_put(transport);
176} 182}
@@ -564,10 +570,8 @@ void sctp_transport_lower_cwnd(struct sctp_transport *transport,
564 * to be done every RTO interval, we do it every hearbeat 570 * to be done every RTO interval, we do it every hearbeat
565 * interval. 571 * interval.
566 */ 572 */
567 if (time_after(jiffies, transport->last_time_used + 573 transport->cwnd = max(transport->cwnd/2,
568 transport->rto)) 574 4*transport->asoc->pathmtu);
569 transport->cwnd = max(transport->cwnd/2,
570 4*transport->asoc->pathmtu);
571 break; 575 break;
572 } 576 }
573 577
@@ -578,6 +582,43 @@ void sctp_transport_lower_cwnd(struct sctp_transport *transport,
578 transport->cwnd, transport->ssthresh); 582 transport->cwnd, transport->ssthresh);
579} 583}
580 584
585/* Apply Max.Burst limit to the congestion window:
586 * sctpimpguide-05 2.14.2
587 * D) When the time comes for the sender to
588 * transmit new DATA chunks, the protocol parameter Max.Burst MUST
589 * first be applied to limit how many new DATA chunks may be sent.
590 * The limit is applied by adjusting cwnd as follows:
591 * if ((flightsize+ Max.Burst * MTU) < cwnd)
592 * cwnd = flightsize + Max.Burst * MTU
593 */
594
595void sctp_transport_burst_limited(struct sctp_transport *t)
596{
597 struct sctp_association *asoc = t->asoc;
598 u32 old_cwnd = t->cwnd;
599 u32 max_burst_bytes;
600
601 if (t->burst_limited)
602 return;
603
604 max_burst_bytes = t->flight_size + (asoc->max_burst * asoc->pathmtu);
605 if (max_burst_bytes < old_cwnd) {
606 t->cwnd = max_burst_bytes;
607 t->burst_limited = old_cwnd;
608 }
609}
610
611/* Restore the old cwnd congestion window, after the burst had it's
612 * desired effect.
613 */
614void sctp_transport_burst_reset(struct sctp_transport *t)
615{
616 if (t->burst_limited) {
617 t->cwnd = t->burst_limited;
618 t->burst_limited = 0;
619 }
620}
621
581/* What is the next timeout value for this transport? */ 622/* What is the next timeout value for this transport? */
582unsigned long sctp_transport_timeout(struct sctp_transport *t) 623unsigned long sctp_transport_timeout(struct sctp_transport *t)
583{ 624{
@@ -600,6 +641,7 @@ void sctp_transport_reset(struct sctp_transport *t)
600 * (see Section 6.2.1) 641 * (see Section 6.2.1)
601 */ 642 */
602 t->cwnd = min(4*asoc->pathmtu, max_t(__u32, 2*asoc->pathmtu, 4380)); 643 t->cwnd = min(4*asoc->pathmtu, max_t(__u32, 2*asoc->pathmtu, 4380));
644 t->burst_limited = 0;
603 t->ssthresh = asoc->peer.i.a_rwnd; 645 t->ssthresh = asoc->peer.i.a_rwnd;
604 t->rto = asoc->rto_initial; 646 t->rto = asoc->rto_initial;
605 t->rtt = 0; 647 t->rtt = 0;
diff --git a/net/sctp/tsnmap.c b/net/sctp/tsnmap.c
index 9bd64565021a..747d5412c463 100644
--- a/net/sctp/tsnmap.c
+++ b/net/sctp/tsnmap.c
@@ -42,6 +42,7 @@
42 * be incorporated into the next SCTP release. 42 * be incorporated into the next SCTP release.
43 */ 43 */
44 44
45#include <linux/slab.h>
45#include <linux/types.h> 46#include <linux/types.h>
46#include <linux/bitmap.h> 47#include <linux/bitmap.h>
47#include <net/sctp/sctp.h> 48#include <net/sctp/sctp.h>
diff --git a/net/sctp/ulpevent.c b/net/sctp/ulpevent.c
index 8b3560fd876d..aa72e89c3ee1 100644
--- a/net/sctp/ulpevent.c
+++ b/net/sctp/ulpevent.c
@@ -43,6 +43,7 @@
43 * be incorporated into the next SCTP release. 43 * be incorporated into the next SCTP release.
44 */ 44 */
45 45
46#include <linux/slab.h>
46#include <linux/types.h> 47#include <linux/types.h>
47#include <linux/skbuff.h> 48#include <linux/skbuff.h>
48#include <net/sctp/structs.h> 49#include <net/sctp/structs.h>
diff --git a/net/sctp/ulpqueue.c b/net/sctp/ulpqueue.c
index 7b23803343cc..3a448536f0b6 100644
--- a/net/sctp/ulpqueue.c
+++ b/net/sctp/ulpqueue.c
@@ -41,6 +41,7 @@
41 * be incorporated into the next SCTP release. 41 * be incorporated into the next SCTP release.
42 */ 42 */
43 43
44#include <linux/slab.h>
44#include <linux/types.h> 45#include <linux/types.h>
45#include <linux/skbuff.h> 46#include <linux/skbuff.h>
46#include <net/sock.h> 47#include <net/sock.h>
diff --git a/net/socket.c b/net/socket.c
index 75655365b5fd..5e8d0af3c0e7 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -87,6 +87,7 @@
87#include <linux/wireless.h> 87#include <linux/wireless.h>
88#include <linux/nsproxy.h> 88#include <linux/nsproxy.h>
89#include <linux/magic.h> 89#include <linux/magic.h>
90#include <linux/slab.h>
90 91
91#include <asm/uaccess.h> 92#include <asm/uaccess.h>
92#include <asm/unistd.h> 93#include <asm/unistd.h>
@@ -97,6 +98,12 @@
97#include <net/sock.h> 98#include <net/sock.h>
98#include <linux/netfilter.h> 99#include <linux/netfilter.h>
99 100
101#include <linux/if_tun.h>
102#include <linux/ipv6_route.h>
103#include <linux/route.h>
104#include <linux/sockios.h>
105#include <linux/atalk.h>
106
100static int sock_no_open(struct inode *irrelevant, struct file *dontcare); 107static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
101static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov, 108static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
102 unsigned long nr_segs, loff_t pos); 109 unsigned long nr_segs, loff_t pos);
@@ -306,18 +313,6 @@ static struct file_system_type sock_fs_type = {
306 .kill_sb = kill_anon_super, 313 .kill_sb = kill_anon_super,
307}; 314};
308 315
309static int sockfs_delete_dentry(struct dentry *dentry)
310{
311 /*
312 * At creation time, we pretended this dentry was hashed
313 * (by clearing DCACHE_UNHASHED bit in d_flags)
314 * At delete time, we restore the truth : not hashed.
315 * (so that dput() can proceed correctly)
316 */
317 dentry->d_flags |= DCACHE_UNHASHED;
318 return 0;
319}
320
321/* 316/*
322 * sockfs_dname() is called from d_path(). 317 * sockfs_dname() is called from d_path().
323 */ 318 */
@@ -328,7 +323,6 @@ static char *sockfs_dname(struct dentry *dentry, char *buffer, int buflen)
328} 323}
329 324
330static const struct dentry_operations sockfs_dentry_operations = { 325static const struct dentry_operations sockfs_dentry_operations = {
331 .d_delete = sockfs_delete_dentry,
332 .d_dname = sockfs_dname, 326 .d_dname = sockfs_dname,
333}; 327};
334 328
@@ -349,68 +343,55 @@ static const struct dentry_operations sockfs_dentry_operations = {
349 * but we take care of internal coherence yet. 343 * but we take care of internal coherence yet.
350 */ 344 */
351 345
352static int sock_alloc_fd(struct file **filep, int flags) 346static int sock_alloc_file(struct socket *sock, struct file **f, int flags)
353{ 347{
348 struct qstr name = { .name = "" };
349 struct path path;
350 struct file *file;
354 int fd; 351 int fd;
355 352
356 fd = get_unused_fd_flags(flags); 353 fd = get_unused_fd_flags(flags);
357 if (likely(fd >= 0)) { 354 if (unlikely(fd < 0))
358 struct file *file = get_empty_filp(); 355 return fd;
359
360 *filep = file;
361 if (unlikely(!file)) {
362 put_unused_fd(fd);
363 return -ENFILE;
364 }
365 } else
366 *filep = NULL;
367 return fd;
368}
369
370static int sock_attach_fd(struct socket *sock, struct file *file, int flags)
371{
372 struct dentry *dentry;
373 struct qstr name = { .name = "" };
374 356
375 dentry = d_alloc(sock_mnt->mnt_sb->s_root, &name); 357 path.dentry = d_alloc(sock_mnt->mnt_sb->s_root, &name);
376 if (unlikely(!dentry)) 358 if (unlikely(!path.dentry)) {
359 put_unused_fd(fd);
377 return -ENOMEM; 360 return -ENOMEM;
361 }
362 path.mnt = mntget(sock_mnt);
378 363
379 dentry->d_op = &sockfs_dentry_operations; 364 path.dentry->d_op = &sockfs_dentry_operations;
380 /* 365 d_instantiate(path.dentry, SOCK_INODE(sock));
381 * We dont want to push this dentry into global dentry hash table. 366 SOCK_INODE(sock)->i_fop = &socket_file_ops;
382 * We pretend dentry is already hashed, by unsetting DCACHE_UNHASHED
383 * This permits a working /proc/$pid/fd/XXX on sockets
384 */
385 dentry->d_flags &= ~DCACHE_UNHASHED;
386 d_instantiate(dentry, SOCK_INODE(sock));
387 367
388 sock->file = file; 368 file = alloc_file(&path, FMODE_READ | FMODE_WRITE,
389 init_file(file, sock_mnt, dentry, FMODE_READ | FMODE_WRITE,
390 &socket_file_ops); 369 &socket_file_ops);
391 SOCK_INODE(sock)->i_fop = &socket_file_ops; 370 if (unlikely(!file)) {
371 /* drop dentry, keep inode */
372 atomic_inc(&path.dentry->d_inode->i_count);
373 path_put(&path);
374 put_unused_fd(fd);
375 return -ENFILE;
376 }
377
378 sock->file = file;
392 file->f_flags = O_RDWR | (flags & O_NONBLOCK); 379 file->f_flags = O_RDWR | (flags & O_NONBLOCK);
393 file->f_pos = 0; 380 file->f_pos = 0;
394 file->private_data = sock; 381 file->private_data = sock;
395 382
396 return 0; 383 *f = file;
384 return fd;
397} 385}
398 386
399int sock_map_fd(struct socket *sock, int flags) 387int sock_map_fd(struct socket *sock, int flags)
400{ 388{
401 struct file *newfile; 389 struct file *newfile;
402 int fd = sock_alloc_fd(&newfile, flags); 390 int fd = sock_alloc_file(sock, &newfile, flags);
403
404 if (likely(fd >= 0)) {
405 int err = sock_attach_fd(sock, newfile, flags);
406 391
407 if (unlikely(err < 0)) { 392 if (likely(fd >= 0))
408 put_filp(newfile);
409 put_unused_fd(fd);
410 return err;
411 }
412 fd_install(fd, newfile); 393 fd_install(fd, newfile);
413 } 394
414 return fd; 395 return fd;
415} 396}
416 397
@@ -668,10 +649,24 @@ void __sock_recv_timestamp(struct msghdr *msg, struct sock *sk,
668 649
669EXPORT_SYMBOL_GPL(__sock_recv_timestamp); 650EXPORT_SYMBOL_GPL(__sock_recv_timestamp);
670 651
671static inline int __sock_recvmsg(struct kiocb *iocb, struct socket *sock, 652inline void sock_recv_drops(struct msghdr *msg, struct sock *sk, struct sk_buff *skb)
672 struct msghdr *msg, size_t size, int flags) 653{
654 if (sock_flag(sk, SOCK_RXQ_OVFL) && skb && skb->dropcount)
655 put_cmsg(msg, SOL_SOCKET, SO_RXQ_OVFL,
656 sizeof(__u32), &skb->dropcount);
657}
658
659void sock_recv_ts_and_drops(struct msghdr *msg, struct sock *sk,
660 struct sk_buff *skb)
661{
662 sock_recv_timestamp(msg, sk, skb);
663 sock_recv_drops(msg, sk, skb);
664}
665EXPORT_SYMBOL_GPL(sock_recv_ts_and_drops);
666
667static inline int __sock_recvmsg_nosec(struct kiocb *iocb, struct socket *sock,
668 struct msghdr *msg, size_t size, int flags)
673{ 669{
674 int err;
675 struct sock_iocb *si = kiocb_to_siocb(iocb); 670 struct sock_iocb *si = kiocb_to_siocb(iocb);
676 671
677 si->sock = sock; 672 si->sock = sock;
@@ -680,13 +675,17 @@ static inline int __sock_recvmsg(struct kiocb *iocb, struct socket *sock,
680 si->size = size; 675 si->size = size;
681 si->flags = flags; 676 si->flags = flags;
682 677
683 err = security_socket_recvmsg(sock, msg, size, flags);
684 if (err)
685 return err;
686
687 return sock->ops->recvmsg(iocb, sock, msg, size, flags); 678 return sock->ops->recvmsg(iocb, sock, msg, size, flags);
688} 679}
689 680
681static inline int __sock_recvmsg(struct kiocb *iocb, struct socket *sock,
682 struct msghdr *msg, size_t size, int flags)
683{
684 int err = security_socket_recvmsg(sock, msg, size, flags);
685
686 return err ?: __sock_recvmsg_nosec(iocb, sock, msg, size, flags);
687}
688
690int sock_recvmsg(struct socket *sock, struct msghdr *msg, 689int sock_recvmsg(struct socket *sock, struct msghdr *msg,
691 size_t size, int flags) 690 size_t size, int flags)
692{ 691{
@@ -702,6 +701,21 @@ int sock_recvmsg(struct socket *sock, struct msghdr *msg,
702 return ret; 701 return ret;
703} 702}
704 703
704static int sock_recvmsg_nosec(struct socket *sock, struct msghdr *msg,
705 size_t size, int flags)
706{
707 struct kiocb iocb;
708 struct sock_iocb siocb;
709 int ret;
710
711 init_sync_kiocb(&iocb, NULL);
712 iocb.private = &siocb;
713 ret = __sock_recvmsg_nosec(&iocb, sock, msg, size, flags);
714 if (-EIOCBQUEUED == ret)
715 ret = wait_on_sync_kiocb(&iocb);
716 return ret;
717}
718
705int kernel_recvmsg(struct socket *sock, struct msghdr *msg, 719int kernel_recvmsg(struct socket *sock, struct msghdr *msg,
706 struct kvec *vec, size_t num, size_t size, int flags) 720 struct kvec *vec, size_t num, size_t size, int flags)
707{ 721{
@@ -886,6 +900,24 @@ void dlci_ioctl_set(int (*hook) (unsigned int, void __user *))
886 900
887EXPORT_SYMBOL(dlci_ioctl_set); 901EXPORT_SYMBOL(dlci_ioctl_set);
888 902
903static long sock_do_ioctl(struct net *net, struct socket *sock,
904 unsigned int cmd, unsigned long arg)
905{
906 int err;
907 void __user *argp = (void __user *)arg;
908
909 err = sock->ops->ioctl(sock, cmd, arg);
910
911 /*
912 * If this ioctl is unknown try to hand it down
913 * to the NIC driver.
914 */
915 if (err == -ENOIOCTLCMD)
916 err = dev_ioctl(net, cmd, argp);
917
918 return err;
919}
920
889/* 921/*
890 * With an ioctl, arg may well be a user mode pointer, but we don't know 922 * With an ioctl, arg may well be a user mode pointer, but we don't know
891 * what to do with it - that's up to the protocol still. 923 * what to do with it - that's up to the protocol still.
@@ -905,11 +937,11 @@ static long sock_ioctl(struct file *file, unsigned cmd, unsigned long arg)
905 if (cmd >= SIOCDEVPRIVATE && cmd <= (SIOCDEVPRIVATE + 15)) { 937 if (cmd >= SIOCDEVPRIVATE && cmd <= (SIOCDEVPRIVATE + 15)) {
906 err = dev_ioctl(net, cmd, argp); 938 err = dev_ioctl(net, cmd, argp);
907 } else 939 } else
908#ifdef CONFIG_WIRELESS_EXT 940#ifdef CONFIG_WEXT_CORE
909 if (cmd >= SIOCIWFIRST && cmd <= SIOCIWLAST) { 941 if (cmd >= SIOCIWFIRST && cmd <= SIOCIWLAST) {
910 err = dev_ioctl(net, cmd, argp); 942 err = dev_ioctl(net, cmd, argp);
911 } else 943 } else
912#endif /* CONFIG_WIRELESS_EXT */ 944#endif
913 switch (cmd) { 945 switch (cmd) {
914 case FIOSETOWN: 946 case FIOSETOWN:
915 case SIOCSPGRP: 947 case SIOCSPGRP:
@@ -959,14 +991,7 @@ static long sock_ioctl(struct file *file, unsigned cmd, unsigned long arg)
959 mutex_unlock(&dlci_ioctl_mutex); 991 mutex_unlock(&dlci_ioctl_mutex);
960 break; 992 break;
961 default: 993 default:
962 err = sock->ops->ioctl(sock, cmd, arg); 994 err = sock_do_ioctl(net, sock, cmd, arg);
963
964 /*
965 * If this ioctl is unknown try to hand it down
966 * to the NIC driver.
967 */
968 if (err == -ENOIOCTLCMD)
969 err = dev_ioctl(net, cmd, argp);
970 break; 995 break;
971 } 996 }
972 return err; 997 return err;
@@ -1100,11 +1125,14 @@ static int sock_fasync(int fd, struct file *filp, int on)
1100 fna->fa_next = sock->fasync_list; 1125 fna->fa_next = sock->fasync_list;
1101 write_lock_bh(&sk->sk_callback_lock); 1126 write_lock_bh(&sk->sk_callback_lock);
1102 sock->fasync_list = fna; 1127 sock->fasync_list = fna;
1128 sock_set_flag(sk, SOCK_FASYNC);
1103 write_unlock_bh(&sk->sk_callback_lock); 1129 write_unlock_bh(&sk->sk_callback_lock);
1104 } else { 1130 } else {
1105 if (fa != NULL) { 1131 if (fa != NULL) {
1106 write_lock_bh(&sk->sk_callback_lock); 1132 write_lock_bh(&sk->sk_callback_lock);
1107 *prev = fa->fa_next; 1133 *prev = fa->fa_next;
1134 if (!sock->fasync_list)
1135 sock_reset_flag(sk, SOCK_FASYNC);
1108 write_unlock_bh(&sk->sk_callback_lock); 1136 write_unlock_bh(&sk->sk_callback_lock);
1109 kfree(fa); 1137 kfree(fa);
1110 } 1138 }
@@ -1216,7 +1244,7 @@ static int __sock_create(struct net *net, int family, int type, int protocol,
1216 /* Now protected by module ref count */ 1244 /* Now protected by module ref count */
1217 rcu_read_unlock(); 1245 rcu_read_unlock();
1218 1246
1219 err = pf->create(net, sock, protocol); 1247 err = pf->create(net, sock, protocol, kern);
1220 if (err < 0) 1248 if (err < 0)
1221 goto out_module_put; 1249 goto out_module_put;
1222 1250
@@ -1337,29 +1365,19 @@ SYSCALL_DEFINE4(socketpair, int, family, int, type, int, protocol,
1337 if (err < 0) 1365 if (err < 0)
1338 goto out_release_both; 1366 goto out_release_both;
1339 1367
1340 fd1 = sock_alloc_fd(&newfile1, flags & O_CLOEXEC); 1368 fd1 = sock_alloc_file(sock1, &newfile1, flags);
1341 if (unlikely(fd1 < 0)) { 1369 if (unlikely(fd1 < 0)) {
1342 err = fd1; 1370 err = fd1;
1343 goto out_release_both; 1371 goto out_release_both;
1344 } 1372 }
1345 1373
1346 fd2 = sock_alloc_fd(&newfile2, flags & O_CLOEXEC); 1374 fd2 = sock_alloc_file(sock2, &newfile2, flags);
1347 if (unlikely(fd2 < 0)) { 1375 if (unlikely(fd2 < 0)) {
1348 err = fd2; 1376 err = fd2;
1349 put_filp(newfile1);
1350 put_unused_fd(fd1);
1351 goto out_release_both;
1352 }
1353
1354 err = sock_attach_fd(sock1, newfile1, flags & O_NONBLOCK);
1355 if (unlikely(err < 0)) {
1356 goto out_fd2;
1357 }
1358
1359 err = sock_attach_fd(sock2, newfile2, flags & O_NONBLOCK);
1360 if (unlikely(err < 0)) {
1361 fput(newfile1); 1377 fput(newfile1);
1362 goto out_fd1; 1378 put_unused_fd(fd1);
1379 sock_release(sock2);
1380 goto out;
1363 } 1381 }
1364 1382
1365 audit_fd_pair(fd1, fd2); 1383 audit_fd_pair(fd1, fd2);
@@ -1385,16 +1403,6 @@ out_release_1:
1385 sock_release(sock1); 1403 sock_release(sock1);
1386out: 1404out:
1387 return err; 1405 return err;
1388
1389out_fd2:
1390 put_filp(newfile1);
1391 sock_release(sock1);
1392out_fd1:
1393 put_filp(newfile2);
1394 sock_release(sock2);
1395 put_unused_fd(fd1);
1396 put_unused_fd(fd2);
1397 goto out;
1398} 1406}
1399 1407
1400/* 1408/*
@@ -1498,17 +1506,13 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
1498 */ 1506 */
1499 __module_get(newsock->ops->owner); 1507 __module_get(newsock->ops->owner);
1500 1508
1501 newfd = sock_alloc_fd(&newfile, flags & O_CLOEXEC); 1509 newfd = sock_alloc_file(newsock, &newfile, flags);
1502 if (unlikely(newfd < 0)) { 1510 if (unlikely(newfd < 0)) {
1503 err = newfd; 1511 err = newfd;
1504 sock_release(newsock); 1512 sock_release(newsock);
1505 goto out_put; 1513 goto out_put;
1506 } 1514 }
1507 1515
1508 err = sock_attach_fd(newsock, newfile, flags & O_NONBLOCK);
1509 if (err < 0)
1510 goto out_fd_simple;
1511
1512 err = security_socket_accept(sock, newsock); 1516 err = security_socket_accept(sock, newsock);
1513 if (err) 1517 if (err)
1514 goto out_fd; 1518 goto out_fd;
@@ -1538,11 +1542,6 @@ out_put:
1538 fput_light(sock->file, fput_needed); 1542 fput_light(sock->file, fput_needed);
1539out: 1543out:
1540 return err; 1544 return err;
1541out_fd_simple:
1542 sock_release(newsock);
1543 put_filp(newfile);
1544 put_unused_fd(newfd);
1545 goto out_put;
1546out_fd: 1545out_fd:
1547 fput(newfile); 1546 fput(newfile);
1548 put_unused_fd(newfd); 1547 put_unused_fd(newfd);
@@ -1965,22 +1964,15 @@ out:
1965 return err; 1964 return err;
1966} 1965}
1967 1966
1968/* 1967static int __sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
1969 * BSD recvmsg interface 1968 struct msghdr *msg_sys, unsigned flags, int nosec)
1970 */
1971
1972SYSCALL_DEFINE3(recvmsg, int, fd, struct msghdr __user *, msg,
1973 unsigned int, flags)
1974{ 1969{
1975 struct compat_msghdr __user *msg_compat = 1970 struct compat_msghdr __user *msg_compat =
1976 (struct compat_msghdr __user *)msg; 1971 (struct compat_msghdr __user *)msg;
1977 struct socket *sock;
1978 struct iovec iovstack[UIO_FASTIOV]; 1972 struct iovec iovstack[UIO_FASTIOV];
1979 struct iovec *iov = iovstack; 1973 struct iovec *iov = iovstack;
1980 struct msghdr msg_sys;
1981 unsigned long cmsg_ptr; 1974 unsigned long cmsg_ptr;
1982 int err, iov_size, total_len, len; 1975 int err, iov_size, total_len, len;
1983 int fput_needed;
1984 1976
1985 /* kernel mode address */ 1977 /* kernel mode address */
1986 struct sockaddr_storage addr; 1978 struct sockaddr_storage addr;
@@ -1990,27 +1982,23 @@ SYSCALL_DEFINE3(recvmsg, int, fd, struct msghdr __user *, msg,
1990 int __user *uaddr_len; 1982 int __user *uaddr_len;
1991 1983
1992 if (MSG_CMSG_COMPAT & flags) { 1984 if (MSG_CMSG_COMPAT & flags) {
1993 if (get_compat_msghdr(&msg_sys, msg_compat)) 1985 if (get_compat_msghdr(msg_sys, msg_compat))
1994 return -EFAULT; 1986 return -EFAULT;
1995 } 1987 }
1996 else if (copy_from_user(&msg_sys, msg, sizeof(struct msghdr))) 1988 else if (copy_from_user(msg_sys, msg, sizeof(struct msghdr)))
1997 return -EFAULT; 1989 return -EFAULT;
1998 1990
1999 sock = sockfd_lookup_light(fd, &err, &fput_needed);
2000 if (!sock)
2001 goto out;
2002
2003 err = -EMSGSIZE; 1991 err = -EMSGSIZE;
2004 if (msg_sys.msg_iovlen > UIO_MAXIOV) 1992 if (msg_sys->msg_iovlen > UIO_MAXIOV)
2005 goto out_put; 1993 goto out;
2006 1994
2007 /* Check whether to allocate the iovec area */ 1995 /* Check whether to allocate the iovec area */
2008 err = -ENOMEM; 1996 err = -ENOMEM;
2009 iov_size = msg_sys.msg_iovlen * sizeof(struct iovec); 1997 iov_size = msg_sys->msg_iovlen * sizeof(struct iovec);
2010 if (msg_sys.msg_iovlen > UIO_FASTIOV) { 1998 if (msg_sys->msg_iovlen > UIO_FASTIOV) {
2011 iov = sock_kmalloc(sock->sk, iov_size, GFP_KERNEL); 1999 iov = sock_kmalloc(sock->sk, iov_size, GFP_KERNEL);
2012 if (!iov) 2000 if (!iov)
2013 goto out_put; 2001 goto out;
2014 } 2002 }
2015 2003
2016 /* 2004 /*
@@ -2018,46 +2006,47 @@ SYSCALL_DEFINE3(recvmsg, int, fd, struct msghdr __user *, msg,
2018 * kernel msghdr to use the kernel address space) 2006 * kernel msghdr to use the kernel address space)
2019 */ 2007 */
2020 2008
2021 uaddr = (__force void __user *)msg_sys.msg_name; 2009 uaddr = (__force void __user *)msg_sys->msg_name;
2022 uaddr_len = COMPAT_NAMELEN(msg); 2010 uaddr_len = COMPAT_NAMELEN(msg);
2023 if (MSG_CMSG_COMPAT & flags) { 2011 if (MSG_CMSG_COMPAT & flags) {
2024 err = verify_compat_iovec(&msg_sys, iov, 2012 err = verify_compat_iovec(msg_sys, iov,
2025 (struct sockaddr *)&addr, 2013 (struct sockaddr *)&addr,
2026 VERIFY_WRITE); 2014 VERIFY_WRITE);
2027 } else 2015 } else
2028 err = verify_iovec(&msg_sys, iov, 2016 err = verify_iovec(msg_sys, iov,
2029 (struct sockaddr *)&addr, 2017 (struct sockaddr *)&addr,
2030 VERIFY_WRITE); 2018 VERIFY_WRITE);
2031 if (err < 0) 2019 if (err < 0)
2032 goto out_freeiov; 2020 goto out_freeiov;
2033 total_len = err; 2021 total_len = err;
2034 2022
2035 cmsg_ptr = (unsigned long)msg_sys.msg_control; 2023 cmsg_ptr = (unsigned long)msg_sys->msg_control;
2036 msg_sys.msg_flags = flags & (MSG_CMSG_CLOEXEC|MSG_CMSG_COMPAT); 2024 msg_sys->msg_flags = flags & (MSG_CMSG_CLOEXEC|MSG_CMSG_COMPAT);
2037 2025
2038 if (sock->file->f_flags & O_NONBLOCK) 2026 if (sock->file->f_flags & O_NONBLOCK)
2039 flags |= MSG_DONTWAIT; 2027 flags |= MSG_DONTWAIT;
2040 err = sock_recvmsg(sock, &msg_sys, total_len, flags); 2028 err = (nosec ? sock_recvmsg_nosec : sock_recvmsg)(sock, msg_sys,
2029 total_len, flags);
2041 if (err < 0) 2030 if (err < 0)
2042 goto out_freeiov; 2031 goto out_freeiov;
2043 len = err; 2032 len = err;
2044 2033
2045 if (uaddr != NULL) { 2034 if (uaddr != NULL) {
2046 err = move_addr_to_user((struct sockaddr *)&addr, 2035 err = move_addr_to_user((struct sockaddr *)&addr,
2047 msg_sys.msg_namelen, uaddr, 2036 msg_sys->msg_namelen, uaddr,
2048 uaddr_len); 2037 uaddr_len);
2049 if (err < 0) 2038 if (err < 0)
2050 goto out_freeiov; 2039 goto out_freeiov;
2051 } 2040 }
2052 err = __put_user((msg_sys.msg_flags & ~MSG_CMSG_COMPAT), 2041 err = __put_user((msg_sys->msg_flags & ~MSG_CMSG_COMPAT),
2053 COMPAT_FLAGS(msg)); 2042 COMPAT_FLAGS(msg));
2054 if (err) 2043 if (err)
2055 goto out_freeiov; 2044 goto out_freeiov;
2056 if (MSG_CMSG_COMPAT & flags) 2045 if (MSG_CMSG_COMPAT & flags)
2057 err = __put_user((unsigned long)msg_sys.msg_control - cmsg_ptr, 2046 err = __put_user((unsigned long)msg_sys->msg_control - cmsg_ptr,
2058 &msg_compat->msg_controllen); 2047 &msg_compat->msg_controllen);
2059 else 2048 else
2060 err = __put_user((unsigned long)msg_sys.msg_control - cmsg_ptr, 2049 err = __put_user((unsigned long)msg_sys->msg_control - cmsg_ptr,
2061 &msg->msg_controllen); 2050 &msg->msg_controllen);
2062 if (err) 2051 if (err)
2063 goto out_freeiov; 2052 goto out_freeiov;
@@ -2066,21 +2055,166 @@ SYSCALL_DEFINE3(recvmsg, int, fd, struct msghdr __user *, msg,
2066out_freeiov: 2055out_freeiov:
2067 if (iov != iovstack) 2056 if (iov != iovstack)
2068 sock_kfree_s(sock->sk, iov, iov_size); 2057 sock_kfree_s(sock->sk, iov, iov_size);
2069out_put: 2058out:
2059 return err;
2060}
2061
2062/*
2063 * BSD recvmsg interface
2064 */
2065
2066SYSCALL_DEFINE3(recvmsg, int, fd, struct msghdr __user *, msg,
2067 unsigned int, flags)
2068{
2069 int fput_needed, err;
2070 struct msghdr msg_sys;
2071 struct socket *sock = sockfd_lookup_light(fd, &err, &fput_needed);
2072
2073 if (!sock)
2074 goto out;
2075
2076 err = __sys_recvmsg(sock, msg, &msg_sys, flags, 0);
2077
2070 fput_light(sock->file, fput_needed); 2078 fput_light(sock->file, fput_needed);
2071out: 2079out:
2072 return err; 2080 return err;
2073} 2081}
2074 2082
2075#ifdef __ARCH_WANT_SYS_SOCKETCALL 2083/*
2084 * Linux recvmmsg interface
2085 */
2086
2087int __sys_recvmmsg(int fd, struct mmsghdr __user *mmsg, unsigned int vlen,
2088 unsigned int flags, struct timespec *timeout)
2089{
2090 int fput_needed, err, datagrams;
2091 struct socket *sock;
2092 struct mmsghdr __user *entry;
2093 struct compat_mmsghdr __user *compat_entry;
2094 struct msghdr msg_sys;
2095 struct timespec end_time;
2096
2097 if (timeout &&
2098 poll_select_set_timeout(&end_time, timeout->tv_sec,
2099 timeout->tv_nsec))
2100 return -EINVAL;
2101
2102 datagrams = 0;
2103
2104 sock = sockfd_lookup_light(fd, &err, &fput_needed);
2105 if (!sock)
2106 return err;
2107
2108 err = sock_error(sock->sk);
2109 if (err)
2110 goto out_put;
2111
2112 entry = mmsg;
2113 compat_entry = (struct compat_mmsghdr __user *)mmsg;
2114
2115 while (datagrams < vlen) {
2116 /*
2117 * No need to ask LSM for more than the first datagram.
2118 */
2119 if (MSG_CMSG_COMPAT & flags) {
2120 err = __sys_recvmsg(sock, (struct msghdr __user *)compat_entry,
2121 &msg_sys, flags, datagrams);
2122 if (err < 0)
2123 break;
2124 err = __put_user(err, &compat_entry->msg_len);
2125 ++compat_entry;
2126 } else {
2127 err = __sys_recvmsg(sock, (struct msghdr __user *)entry,
2128 &msg_sys, flags, datagrams);
2129 if (err < 0)
2130 break;
2131 err = put_user(err, &entry->msg_len);
2132 ++entry;
2133 }
2076 2134
2135 if (err)
2136 break;
2137 ++datagrams;
2138
2139 /* MSG_WAITFORONE turns on MSG_DONTWAIT after one packet */
2140 if (flags & MSG_WAITFORONE)
2141 flags |= MSG_DONTWAIT;
2142
2143 if (timeout) {
2144 ktime_get_ts(timeout);
2145 *timeout = timespec_sub(end_time, *timeout);
2146 if (timeout->tv_sec < 0) {
2147 timeout->tv_sec = timeout->tv_nsec = 0;
2148 break;
2149 }
2150
2151 /* Timeout, return less than vlen datagrams */
2152 if (timeout->tv_nsec == 0 && timeout->tv_sec == 0)
2153 break;
2154 }
2155
2156 /* Out of band data, return right away */
2157 if (msg_sys.msg_flags & MSG_OOB)
2158 break;
2159 }
2160
2161out_put:
2162 fput_light(sock->file, fput_needed);
2163
2164 if (err == 0)
2165 return datagrams;
2166
2167 if (datagrams != 0) {
2168 /*
2169 * We may return less entries than requested (vlen) if the
2170 * sock is non block and there aren't enough datagrams...
2171 */
2172 if (err != -EAGAIN) {
2173 /*
2174 * ... or if recvmsg returns an error after we
2175 * received some datagrams, where we record the
2176 * error to return on the next call or if the
2177 * app asks about it using getsockopt(SO_ERROR).
2178 */
2179 sock->sk->sk_err = -err;
2180 }
2181
2182 return datagrams;
2183 }
2184
2185 return err;
2186}
2187
2188SYSCALL_DEFINE5(recvmmsg, int, fd, struct mmsghdr __user *, mmsg,
2189 unsigned int, vlen, unsigned int, flags,
2190 struct timespec __user *, timeout)
2191{
2192 int datagrams;
2193 struct timespec timeout_sys;
2194
2195 if (!timeout)
2196 return __sys_recvmmsg(fd, mmsg, vlen, flags, NULL);
2197
2198 if (copy_from_user(&timeout_sys, timeout, sizeof(timeout_sys)))
2199 return -EFAULT;
2200
2201 datagrams = __sys_recvmmsg(fd, mmsg, vlen, flags, &timeout_sys);
2202
2203 if (datagrams > 0 &&
2204 copy_to_user(timeout, &timeout_sys, sizeof(timeout_sys)))
2205 datagrams = -EFAULT;
2206
2207 return datagrams;
2208}
2209
2210#ifdef __ARCH_WANT_SYS_SOCKETCALL
2077/* Argument list sizes for sys_socketcall */ 2211/* Argument list sizes for sys_socketcall */
2078#define AL(x) ((x) * sizeof(unsigned long)) 2212#define AL(x) ((x) * sizeof(unsigned long))
2079static const unsigned char nargs[19]={ 2213static const unsigned char nargs[20] = {
2080 AL(0),AL(3),AL(3),AL(3),AL(2),AL(3), 2214 AL(0),AL(3),AL(3),AL(3),AL(2),AL(3),
2081 AL(3),AL(3),AL(4),AL(4),AL(4),AL(6), 2215 AL(3),AL(3),AL(4),AL(4),AL(4),AL(6),
2082 AL(6),AL(2),AL(5),AL(5),AL(3),AL(3), 2216 AL(6),AL(2),AL(5),AL(5),AL(3),AL(3),
2083 AL(4) 2217 AL(4),AL(5)
2084}; 2218};
2085 2219
2086#undef AL 2220#undef AL
@@ -2100,7 +2234,7 @@ SYSCALL_DEFINE2(socketcall, int, call, unsigned long __user *, args)
2100 int err; 2234 int err;
2101 unsigned int len; 2235 unsigned int len;
2102 2236
2103 if (call < 1 || call > SYS_ACCEPT4) 2237 if (call < 1 || call > SYS_RECVMMSG)
2104 return -EINVAL; 2238 return -EINVAL;
2105 2239
2106 len = nargs[call]; 2240 len = nargs[call];
@@ -2178,6 +2312,10 @@ SYSCALL_DEFINE2(socketcall, int, call, unsigned long __user *, args)
2178 case SYS_RECVMSG: 2312 case SYS_RECVMSG:
2179 err = sys_recvmsg(a0, (struct msghdr __user *)a1, a[2]); 2313 err = sys_recvmsg(a0, (struct msghdr __user *)a1, a[2]);
2180 break; 2314 break;
2315 case SYS_RECVMMSG:
2316 err = sys_recvmmsg(a0, (struct mmsghdr __user *)a1, a[2], a[3],
2317 (struct timespec __user *)a[4]);
2318 break;
2181 case SYS_ACCEPT4: 2319 case SYS_ACCEPT4:
2182 err = sys_accept4(a0, (struct sockaddr __user *)a1, 2320 err = sys_accept4(a0, (struct sockaddr __user *)a1,
2183 (int __user *)a[2], a[3]); 2321 (int __user *)a[2], a[3]);
@@ -2300,6 +2438,552 @@ void socket_seq_show(struct seq_file *seq)
2300#endif /* CONFIG_PROC_FS */ 2438#endif /* CONFIG_PROC_FS */
2301 2439
2302#ifdef CONFIG_COMPAT 2440#ifdef CONFIG_COMPAT
2441static int do_siocgstamp(struct net *net, struct socket *sock,
2442 unsigned int cmd, struct compat_timeval __user *up)
2443{
2444 mm_segment_t old_fs = get_fs();
2445 struct timeval ktv;
2446 int err;
2447
2448 set_fs(KERNEL_DS);
2449 err = sock_do_ioctl(net, sock, cmd, (unsigned long)&ktv);
2450 set_fs(old_fs);
2451 if (!err) {
2452 err = put_user(ktv.tv_sec, &up->tv_sec);
2453 err |= __put_user(ktv.tv_usec, &up->tv_usec);
2454 }
2455 return err;
2456}
2457
2458static int do_siocgstampns(struct net *net, struct socket *sock,
2459 unsigned int cmd, struct compat_timespec __user *up)
2460{
2461 mm_segment_t old_fs = get_fs();
2462 struct timespec kts;
2463 int err;
2464
2465 set_fs(KERNEL_DS);
2466 err = sock_do_ioctl(net, sock, cmd, (unsigned long)&kts);
2467 set_fs(old_fs);
2468 if (!err) {
2469 err = put_user(kts.tv_sec, &up->tv_sec);
2470 err |= __put_user(kts.tv_nsec, &up->tv_nsec);
2471 }
2472 return err;
2473}
2474
2475static int dev_ifname32(struct net *net, struct compat_ifreq __user *uifr32)
2476{
2477 struct ifreq __user *uifr;
2478 int err;
2479
2480 uifr = compat_alloc_user_space(sizeof(struct ifreq));
2481 if (copy_in_user(uifr, uifr32, sizeof(struct compat_ifreq)))
2482 return -EFAULT;
2483
2484 err = dev_ioctl(net, SIOCGIFNAME, uifr);
2485 if (err)
2486 return err;
2487
2488 if (copy_in_user(uifr32, uifr, sizeof(struct compat_ifreq)))
2489 return -EFAULT;
2490
2491 return 0;
2492}
2493
2494static int dev_ifconf(struct net *net, struct compat_ifconf __user *uifc32)
2495{
2496 struct compat_ifconf ifc32;
2497 struct ifconf ifc;
2498 struct ifconf __user *uifc;
2499 struct compat_ifreq __user *ifr32;
2500 struct ifreq __user *ifr;
2501 unsigned int i, j;
2502 int err;
2503
2504 if (copy_from_user(&ifc32, uifc32, sizeof(struct compat_ifconf)))
2505 return -EFAULT;
2506
2507 if (ifc32.ifcbuf == 0) {
2508 ifc32.ifc_len = 0;
2509 ifc.ifc_len = 0;
2510 ifc.ifc_req = NULL;
2511 uifc = compat_alloc_user_space(sizeof(struct ifconf));
2512 } else {
2513 size_t len =((ifc32.ifc_len / sizeof (struct compat_ifreq)) + 1) *
2514 sizeof (struct ifreq);
2515 uifc = compat_alloc_user_space(sizeof(struct ifconf) + len);
2516 ifc.ifc_len = len;
2517 ifr = ifc.ifc_req = (void __user *)(uifc + 1);
2518 ifr32 = compat_ptr(ifc32.ifcbuf);
2519 for (i = 0; i < ifc32.ifc_len; i += sizeof (struct compat_ifreq)) {
2520 if (copy_in_user(ifr, ifr32, sizeof(struct compat_ifreq)))
2521 return -EFAULT;
2522 ifr++;
2523 ifr32++;
2524 }
2525 }
2526 if (copy_to_user(uifc, &ifc, sizeof(struct ifconf)))
2527 return -EFAULT;
2528
2529 err = dev_ioctl(net, SIOCGIFCONF, uifc);
2530 if (err)
2531 return err;
2532
2533 if (copy_from_user(&ifc, uifc, sizeof(struct ifconf)))
2534 return -EFAULT;
2535
2536 ifr = ifc.ifc_req;
2537 ifr32 = compat_ptr(ifc32.ifcbuf);
2538 for (i = 0, j = 0;
2539 i + sizeof (struct compat_ifreq) <= ifc32.ifc_len && j < ifc.ifc_len;
2540 i += sizeof (struct compat_ifreq), j += sizeof (struct ifreq)) {
2541 if (copy_in_user(ifr32, ifr, sizeof (struct compat_ifreq)))
2542 return -EFAULT;
2543 ifr32++;
2544 ifr++;
2545 }
2546
2547 if (ifc32.ifcbuf == 0) {
2548 /* Translate from 64-bit structure multiple to
2549 * a 32-bit one.
2550 */
2551 i = ifc.ifc_len;
2552 i = ((i / sizeof(struct ifreq)) * sizeof(struct compat_ifreq));
2553 ifc32.ifc_len = i;
2554 } else {
2555 ifc32.ifc_len = i;
2556 }
2557 if (copy_to_user(uifc32, &ifc32, sizeof(struct compat_ifconf)))
2558 return -EFAULT;
2559
2560 return 0;
2561}
2562
2563static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
2564{
2565 struct ifreq __user *ifr;
2566 u32 data;
2567 void __user *datap;
2568
2569 ifr = compat_alloc_user_space(sizeof(*ifr));
2570
2571 if (copy_in_user(&ifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
2572 return -EFAULT;
2573
2574 if (get_user(data, &ifr32->ifr_ifru.ifru_data))
2575 return -EFAULT;
2576
2577 datap = compat_ptr(data);
2578 if (put_user(datap, &ifr->ifr_ifru.ifru_data))
2579 return -EFAULT;
2580
2581 return dev_ioctl(net, SIOCETHTOOL, ifr);
2582}
2583
2584static int compat_siocwandev(struct net *net, struct compat_ifreq __user *uifr32)
2585{
2586 void __user *uptr;
2587 compat_uptr_t uptr32;
2588 struct ifreq __user *uifr;
2589
2590 uifr = compat_alloc_user_space(sizeof (*uifr));
2591 if (copy_in_user(uifr, uifr32, sizeof(struct compat_ifreq)))
2592 return -EFAULT;
2593
2594 if (get_user(uptr32, &uifr32->ifr_settings.ifs_ifsu))
2595 return -EFAULT;
2596
2597 uptr = compat_ptr(uptr32);
2598
2599 if (put_user(uptr, &uifr->ifr_settings.ifs_ifsu.raw_hdlc))
2600 return -EFAULT;
2601
2602 return dev_ioctl(net, SIOCWANDEV, uifr);
2603}
2604
2605static int bond_ioctl(struct net *net, unsigned int cmd,
2606 struct compat_ifreq __user *ifr32)
2607{
2608 struct ifreq kifr;
2609 struct ifreq __user *uifr;
2610 mm_segment_t old_fs;
2611 int err;
2612 u32 data;
2613 void __user *datap;
2614
2615 switch (cmd) {
2616 case SIOCBONDENSLAVE:
2617 case SIOCBONDRELEASE:
2618 case SIOCBONDSETHWADDR:
2619 case SIOCBONDCHANGEACTIVE:
2620 if (copy_from_user(&kifr, ifr32, sizeof(struct compat_ifreq)))
2621 return -EFAULT;
2622
2623 old_fs = get_fs();
2624 set_fs (KERNEL_DS);
2625 err = dev_ioctl(net, cmd, &kifr);
2626 set_fs (old_fs);
2627
2628 return err;
2629 case SIOCBONDSLAVEINFOQUERY:
2630 case SIOCBONDINFOQUERY:
2631 uifr = compat_alloc_user_space(sizeof(*uifr));
2632 if (copy_in_user(&uifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
2633 return -EFAULT;
2634
2635 if (get_user(data, &ifr32->ifr_ifru.ifru_data))
2636 return -EFAULT;
2637
2638 datap = compat_ptr(data);
2639 if (put_user(datap, &uifr->ifr_ifru.ifru_data))
2640 return -EFAULT;
2641
2642 return dev_ioctl(net, cmd, uifr);
2643 default:
2644 return -EINVAL;
2645 };
2646}
2647
2648static int siocdevprivate_ioctl(struct net *net, unsigned int cmd,
2649 struct compat_ifreq __user *u_ifreq32)
2650{
2651 struct ifreq __user *u_ifreq64;
2652 char tmp_buf[IFNAMSIZ];
2653 void __user *data64;
2654 u32 data32;
2655
2656 if (copy_from_user(&tmp_buf[0], &(u_ifreq32->ifr_ifrn.ifrn_name[0]),
2657 IFNAMSIZ))
2658 return -EFAULT;
2659 if (__get_user(data32, &u_ifreq32->ifr_ifru.ifru_data))
2660 return -EFAULT;
2661 data64 = compat_ptr(data32);
2662
2663 u_ifreq64 = compat_alloc_user_space(sizeof(*u_ifreq64));
2664
2665 /* Don't check these user accesses, just let that get trapped
2666 * in the ioctl handler instead.
2667 */
2668 if (copy_to_user(&u_ifreq64->ifr_ifrn.ifrn_name[0], &tmp_buf[0],
2669 IFNAMSIZ))
2670 return -EFAULT;
2671 if (__put_user(data64, &u_ifreq64->ifr_ifru.ifru_data))
2672 return -EFAULT;
2673
2674 return dev_ioctl(net, cmd, u_ifreq64);
2675}
2676
2677static int dev_ifsioc(struct net *net, struct socket *sock,
2678 unsigned int cmd, struct compat_ifreq __user *uifr32)
2679{
2680 struct ifreq __user *uifr;
2681 int err;
2682
2683 uifr = compat_alloc_user_space(sizeof(*uifr));
2684 if (copy_in_user(uifr, uifr32, sizeof(*uifr32)))
2685 return -EFAULT;
2686
2687 err = sock_do_ioctl(net, sock, cmd, (unsigned long)uifr);
2688
2689 if (!err) {
2690 switch (cmd) {
2691 case SIOCGIFFLAGS:
2692 case SIOCGIFMETRIC:
2693 case SIOCGIFMTU:
2694 case SIOCGIFMEM:
2695 case SIOCGIFHWADDR:
2696 case SIOCGIFINDEX:
2697 case SIOCGIFADDR:
2698 case SIOCGIFBRDADDR:
2699 case SIOCGIFDSTADDR:
2700 case SIOCGIFNETMASK:
2701 case SIOCGIFPFLAGS:
2702 case SIOCGIFTXQLEN:
2703 case SIOCGMIIPHY:
2704 case SIOCGMIIREG:
2705 if (copy_in_user(uifr32, uifr, sizeof(*uifr32)))
2706 err = -EFAULT;
2707 break;
2708 }
2709 }
2710 return err;
2711}
2712
2713static int compat_sioc_ifmap(struct net *net, unsigned int cmd,
2714 struct compat_ifreq __user *uifr32)
2715{
2716 struct ifreq ifr;
2717 struct compat_ifmap __user *uifmap32;
2718 mm_segment_t old_fs;
2719 int err;
2720
2721 uifmap32 = &uifr32->ifr_ifru.ifru_map;
2722 err = copy_from_user(&ifr, uifr32, sizeof(ifr.ifr_name));
2723 err |= __get_user(ifr.ifr_map.mem_start, &uifmap32->mem_start);
2724 err |= __get_user(ifr.ifr_map.mem_end, &uifmap32->mem_end);
2725 err |= __get_user(ifr.ifr_map.base_addr, &uifmap32->base_addr);
2726 err |= __get_user(ifr.ifr_map.irq, &uifmap32->irq);
2727 err |= __get_user(ifr.ifr_map.dma, &uifmap32->dma);
2728 err |= __get_user(ifr.ifr_map.port, &uifmap32->port);
2729 if (err)
2730 return -EFAULT;
2731
2732 old_fs = get_fs();
2733 set_fs (KERNEL_DS);
2734 err = dev_ioctl(net, cmd, (void __user *)&ifr);
2735 set_fs (old_fs);
2736
2737 if (cmd == SIOCGIFMAP && !err) {
2738 err = copy_to_user(uifr32, &ifr, sizeof(ifr.ifr_name));
2739 err |= __put_user(ifr.ifr_map.mem_start, &uifmap32->mem_start);
2740 err |= __put_user(ifr.ifr_map.mem_end, &uifmap32->mem_end);
2741 err |= __put_user(ifr.ifr_map.base_addr, &uifmap32->base_addr);
2742 err |= __put_user(ifr.ifr_map.irq, &uifmap32->irq);
2743 err |= __put_user(ifr.ifr_map.dma, &uifmap32->dma);
2744 err |= __put_user(ifr.ifr_map.port, &uifmap32->port);
2745 if (err)
2746 err = -EFAULT;
2747 }
2748 return err;
2749}
2750
2751static int compat_siocshwtstamp(struct net *net, struct compat_ifreq __user *uifr32)
2752{
2753 void __user *uptr;
2754 compat_uptr_t uptr32;
2755 struct ifreq __user *uifr;
2756
2757 uifr = compat_alloc_user_space(sizeof (*uifr));
2758 if (copy_in_user(uifr, uifr32, sizeof(struct compat_ifreq)))
2759 return -EFAULT;
2760
2761 if (get_user(uptr32, &uifr32->ifr_data))
2762 return -EFAULT;
2763
2764 uptr = compat_ptr(uptr32);
2765
2766 if (put_user(uptr, &uifr->ifr_data))
2767 return -EFAULT;
2768
2769 return dev_ioctl(net, SIOCSHWTSTAMP, uifr);
2770}
2771
2772struct rtentry32 {
2773 u32 rt_pad1;
2774 struct sockaddr rt_dst; /* target address */
2775 struct sockaddr rt_gateway; /* gateway addr (RTF_GATEWAY) */
2776 struct sockaddr rt_genmask; /* target network mask (IP) */
2777 unsigned short rt_flags;
2778 short rt_pad2;
2779 u32 rt_pad3;
2780 unsigned char rt_tos;
2781 unsigned char rt_class;
2782 short rt_pad4;
2783 short rt_metric; /* +1 for binary compatibility! */
2784 /* char * */ u32 rt_dev; /* forcing the device at add */
2785 u32 rt_mtu; /* per route MTU/Window */
2786 u32 rt_window; /* Window clamping */
2787 unsigned short rt_irtt; /* Initial RTT */
2788};
2789
2790struct in6_rtmsg32 {
2791 struct in6_addr rtmsg_dst;
2792 struct in6_addr rtmsg_src;
2793 struct in6_addr rtmsg_gateway;
2794 u32 rtmsg_type;
2795 u16 rtmsg_dst_len;
2796 u16 rtmsg_src_len;
2797 u32 rtmsg_metric;
2798 u32 rtmsg_info;
2799 u32 rtmsg_flags;
2800 s32 rtmsg_ifindex;
2801};
2802
2803static int routing_ioctl(struct net *net, struct socket *sock,
2804 unsigned int cmd, void __user *argp)
2805{
2806 int ret;
2807 void *r = NULL;
2808 struct in6_rtmsg r6;
2809 struct rtentry r4;
2810 char devname[16];
2811 u32 rtdev;
2812 mm_segment_t old_fs = get_fs();
2813
2814 if (sock && sock->sk && sock->sk->sk_family == AF_INET6) { /* ipv6 */
2815 struct in6_rtmsg32 __user *ur6 = argp;
2816 ret = copy_from_user (&r6.rtmsg_dst, &(ur6->rtmsg_dst),
2817 3 * sizeof(struct in6_addr));
2818 ret |= __get_user (r6.rtmsg_type, &(ur6->rtmsg_type));
2819 ret |= __get_user (r6.rtmsg_dst_len, &(ur6->rtmsg_dst_len));
2820 ret |= __get_user (r6.rtmsg_src_len, &(ur6->rtmsg_src_len));
2821 ret |= __get_user (r6.rtmsg_metric, &(ur6->rtmsg_metric));
2822 ret |= __get_user (r6.rtmsg_info, &(ur6->rtmsg_info));
2823 ret |= __get_user (r6.rtmsg_flags, &(ur6->rtmsg_flags));
2824 ret |= __get_user (r6.rtmsg_ifindex, &(ur6->rtmsg_ifindex));
2825
2826 r = (void *) &r6;
2827 } else { /* ipv4 */
2828 struct rtentry32 __user *ur4 = argp;
2829 ret = copy_from_user (&r4.rt_dst, &(ur4->rt_dst),
2830 3 * sizeof(struct sockaddr));
2831 ret |= __get_user (r4.rt_flags, &(ur4->rt_flags));
2832 ret |= __get_user (r4.rt_metric, &(ur4->rt_metric));
2833 ret |= __get_user (r4.rt_mtu, &(ur4->rt_mtu));
2834 ret |= __get_user (r4.rt_window, &(ur4->rt_window));
2835 ret |= __get_user (r4.rt_irtt, &(ur4->rt_irtt));
2836 ret |= __get_user (rtdev, &(ur4->rt_dev));
2837 if (rtdev) {
2838 ret |= copy_from_user (devname, compat_ptr(rtdev), 15);
2839 r4.rt_dev = devname; devname[15] = 0;
2840 } else
2841 r4.rt_dev = NULL;
2842
2843 r = (void *) &r4;
2844 }
2845
2846 if (ret) {
2847 ret = -EFAULT;
2848 goto out;
2849 }
2850
2851 set_fs (KERNEL_DS);
2852 ret = sock_do_ioctl(net, sock, cmd, (unsigned long) r);
2853 set_fs (old_fs);
2854
2855out:
2856 return ret;
2857}
2858
2859/* Since old style bridge ioctl's endup using SIOCDEVPRIVATE
2860 * for some operations; this forces use of the newer bridge-utils that
2861 * use compatiable ioctls
2862 */
2863static int old_bridge_ioctl(compat_ulong_t __user *argp)
2864{
2865 compat_ulong_t tmp;
2866
2867 if (get_user(tmp, argp))
2868 return -EFAULT;
2869 if (tmp == BRCTL_GET_VERSION)
2870 return BRCTL_VERSION + 1;
2871 return -EINVAL;
2872}
2873
2874static int compat_sock_ioctl_trans(struct file *file, struct socket *sock,
2875 unsigned int cmd, unsigned long arg)
2876{
2877 void __user *argp = compat_ptr(arg);
2878 struct sock *sk = sock->sk;
2879 struct net *net = sock_net(sk);
2880
2881 if (cmd >= SIOCDEVPRIVATE && cmd <= (SIOCDEVPRIVATE + 15))
2882 return siocdevprivate_ioctl(net, cmd, argp);
2883
2884 switch (cmd) {
2885 case SIOCSIFBR:
2886 case SIOCGIFBR:
2887 return old_bridge_ioctl(argp);
2888 case SIOCGIFNAME:
2889 return dev_ifname32(net, argp);
2890 case SIOCGIFCONF:
2891 return dev_ifconf(net, argp);
2892 case SIOCETHTOOL:
2893 return ethtool_ioctl(net, argp);
2894 case SIOCWANDEV:
2895 return compat_siocwandev(net, argp);
2896 case SIOCGIFMAP:
2897 case SIOCSIFMAP:
2898 return compat_sioc_ifmap(net, cmd, argp);
2899 case SIOCBONDENSLAVE:
2900 case SIOCBONDRELEASE:
2901 case SIOCBONDSETHWADDR:
2902 case SIOCBONDSLAVEINFOQUERY:
2903 case SIOCBONDINFOQUERY:
2904 case SIOCBONDCHANGEACTIVE:
2905 return bond_ioctl(net, cmd, argp);
2906 case SIOCADDRT:
2907 case SIOCDELRT:
2908 return routing_ioctl(net, sock, cmd, argp);
2909 case SIOCGSTAMP:
2910 return do_siocgstamp(net, sock, cmd, argp);
2911 case SIOCGSTAMPNS:
2912 return do_siocgstampns(net, sock, cmd, argp);
2913 case SIOCSHWTSTAMP:
2914 return compat_siocshwtstamp(net, argp);
2915
2916 case FIOSETOWN:
2917 case SIOCSPGRP:
2918 case FIOGETOWN:
2919 case SIOCGPGRP:
2920 case SIOCBRADDBR:
2921 case SIOCBRDELBR:
2922 case SIOCGIFVLAN:
2923 case SIOCSIFVLAN:
2924 case SIOCADDDLCI:
2925 case SIOCDELDLCI:
2926 return sock_ioctl(file, cmd, arg);
2927
2928 case SIOCGIFFLAGS:
2929 case SIOCSIFFLAGS:
2930 case SIOCGIFMETRIC:
2931 case SIOCSIFMETRIC:
2932 case SIOCGIFMTU:
2933 case SIOCSIFMTU:
2934 case SIOCGIFMEM:
2935 case SIOCSIFMEM:
2936 case SIOCGIFHWADDR:
2937 case SIOCSIFHWADDR:
2938 case SIOCADDMULTI:
2939 case SIOCDELMULTI:
2940 case SIOCGIFINDEX:
2941 case SIOCGIFADDR:
2942 case SIOCSIFADDR:
2943 case SIOCSIFHWBROADCAST:
2944 case SIOCDIFADDR:
2945 case SIOCGIFBRDADDR:
2946 case SIOCSIFBRDADDR:
2947 case SIOCGIFDSTADDR:
2948 case SIOCSIFDSTADDR:
2949 case SIOCGIFNETMASK:
2950 case SIOCSIFNETMASK:
2951 case SIOCSIFPFLAGS:
2952 case SIOCGIFPFLAGS:
2953 case SIOCGIFTXQLEN:
2954 case SIOCSIFTXQLEN:
2955 case SIOCBRADDIF:
2956 case SIOCBRDELIF:
2957 case SIOCSIFNAME:
2958 case SIOCGMIIPHY:
2959 case SIOCGMIIREG:
2960 case SIOCSMIIREG:
2961 return dev_ifsioc(net, sock, cmd, argp);
2962
2963 case SIOCSARP:
2964 case SIOCGARP:
2965 case SIOCDARP:
2966 case SIOCATMARK:
2967 return sock_do_ioctl(net, sock, cmd, arg);
2968 }
2969
2970 /* Prevent warning from compat_sys_ioctl, these always
2971 * result in -EINVAL in the native case anyway. */
2972 switch (cmd) {
2973 case SIOCRTMSG:
2974 case SIOCGIFCOUNT:
2975 case SIOCSRARP:
2976 case SIOCGRARP:
2977 case SIOCDRARP:
2978 case SIOCSIFLINK:
2979 case SIOCGIFSLAVE:
2980 case SIOCSIFSLAVE:
2981 return -EINVAL;
2982 }
2983
2984 return -ENOIOCTLCMD;
2985}
2986
2303static long compat_sock_ioctl(struct file *file, unsigned cmd, 2987static long compat_sock_ioctl(struct file *file, unsigned cmd,
2304 unsigned long arg) 2988 unsigned long arg)
2305{ 2989{
@@ -2318,6 +3002,9 @@ static long compat_sock_ioctl(struct file *file, unsigned cmd,
2318 (cmd >= SIOCIWFIRST && cmd <= SIOCIWLAST)) 3002 (cmd >= SIOCIWFIRST && cmd <= SIOCIWLAST))
2319 ret = compat_wext_handle_ioctl(net, cmd, arg); 3003 ret = compat_wext_handle_ioctl(net, cmd, arg);
2320 3004
3005 if (ret == -ENOIOCTLCMD)
3006 ret = compat_sock_ioctl_trans(file, sock, cmd, arg);
3007
2321 return ret; 3008 return ret;
2322} 3009}
2323#endif 3010#endif
diff --git a/net/sunrpc/addr.c b/net/sunrpc/addr.c
index c7450c8f0a7c..1419d0cdbbac 100644
--- a/net/sunrpc/addr.c
+++ b/net/sunrpc/addr.c
@@ -18,6 +18,7 @@
18 18
19#include <net/ipv6.h> 19#include <net/ipv6.h>
20#include <linux/sunrpc/clnt.h> 20#include <linux/sunrpc/clnt.h>
21#include <linux/slab.h>
21 22
22#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) 23#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
23 24
@@ -55,16 +56,8 @@ static size_t rpc_ntop6_noscopeid(const struct sockaddr *sap,
55 56
56 /* 57 /*
57 * RFC 4291, Section 2.2.1 58 * RFC 4291, Section 2.2.1
58 *
59 * To keep the result as short as possible, especially
60 * since we don't shorthand, we don't want leading zeros
61 * in each halfword, so avoid %pI6.
62 */ 59 */
63 return snprintf(buf, buflen, "%x:%x:%x:%x:%x:%x:%x:%x", 60 return snprintf(buf, buflen, "%pI6c", addr);
64 ntohs(addr->s6_addr16[0]), ntohs(addr->s6_addr16[1]),
65 ntohs(addr->s6_addr16[2]), ntohs(addr->s6_addr16[3]),
66 ntohs(addr->s6_addr16[4]), ntohs(addr->s6_addr16[5]),
67 ntohs(addr->s6_addr16[6]), ntohs(addr->s6_addr16[7]));
68} 61}
69 62
70static size_t rpc_ntop6(const struct sockaddr *sap, 63static size_t rpc_ntop6(const struct sockaddr *sap,
@@ -79,8 +72,9 @@ static size_t rpc_ntop6(const struct sockaddr *sap,
79 if (unlikely(len == 0)) 72 if (unlikely(len == 0))
80 return len; 73 return len;
81 74
82 if (!(ipv6_addr_type(&sin6->sin6_addr) & IPV6_ADDR_LINKLOCAL) && 75 if (!(ipv6_addr_type(&sin6->sin6_addr) & IPV6_ADDR_LINKLOCAL))
83 !(ipv6_addr_type(&sin6->sin6_addr) & IPV6_ADDR_SITELOCAL)) 76 return len;
77 if (sin6->sin6_scope_id == 0)
84 return len; 78 return len;
85 79
86 rc = snprintf(scopebuf, sizeof(scopebuf), "%c%u", 80 rc = snprintf(scopebuf, sizeof(scopebuf), "%c%u",
@@ -173,8 +167,7 @@ static int rpc_parse_scope_id(const char *buf, const size_t buflen,
173 if (*delim != IPV6_SCOPE_DELIMITER) 167 if (*delim != IPV6_SCOPE_DELIMITER)
174 return 0; 168 return 0;
175 169
176 if (!(ipv6_addr_type(&sin6->sin6_addr) & IPV6_ADDR_LINKLOCAL) && 170 if (!(ipv6_addr_type(&sin6->sin6_addr) & IPV6_ADDR_LINKLOCAL))
177 !(ipv6_addr_type(&sin6->sin6_addr) & IPV6_ADDR_SITELOCAL))
178 return 0; 171 return 0;
179 172
180 len = (buf + buflen) - delim - 1; 173 len = (buf + buflen) - delim - 1;
diff --git a/net/sunrpc/auth.c b/net/sunrpc/auth.c
index 54a4e042f104..95afe79dd9d7 100644
--- a/net/sunrpc/auth.c
+++ b/net/sunrpc/auth.c
@@ -123,16 +123,19 @@ rpcauth_unhash_cred_locked(struct rpc_cred *cred)
123 clear_bit(RPCAUTH_CRED_HASHED, &cred->cr_flags); 123 clear_bit(RPCAUTH_CRED_HASHED, &cred->cr_flags);
124} 124}
125 125
126static void 126static int
127rpcauth_unhash_cred(struct rpc_cred *cred) 127rpcauth_unhash_cred(struct rpc_cred *cred)
128{ 128{
129 spinlock_t *cache_lock; 129 spinlock_t *cache_lock;
130 int ret;
130 131
131 cache_lock = &cred->cr_auth->au_credcache->lock; 132 cache_lock = &cred->cr_auth->au_credcache->lock;
132 spin_lock(cache_lock); 133 spin_lock(cache_lock);
133 if (atomic_read(&cred->cr_count) == 0) 134 ret = atomic_read(&cred->cr_count) == 0;
135 if (ret)
134 rpcauth_unhash_cred_locked(cred); 136 rpcauth_unhash_cred_locked(cred);
135 spin_unlock(cache_lock); 137 spin_unlock(cache_lock);
138 return ret;
136} 139}
137 140
138/* 141/*
@@ -234,7 +237,7 @@ rpcauth_prune_expired(struct list_head *free, int nr_to_scan)
234 list_for_each_entry_safe(cred, next, &cred_unused, cr_lru) { 237 list_for_each_entry_safe(cred, next, &cred_unused, cr_lru) {
235 238
236 /* Enforce a 60 second garbage collection moratorium */ 239 /* Enforce a 60 second garbage collection moratorium */
237 if (time_in_range_open(cred->cr_expire, expired, jiffies) && 240 if (time_in_range(cred->cr_expire, expired, jiffies) &&
238 test_bit(RPCAUTH_CRED_HASHED, &cred->cr_flags) != 0) 241 test_bit(RPCAUTH_CRED_HASHED, &cred->cr_flags) != 0)
239 continue; 242 continue;
240 243
@@ -332,9 +335,9 @@ rpcauth_lookup_credcache(struct rpc_auth *auth, struct auth_cred * acred,
332 list_add_tail(&new->cr_lru, &free); 335 list_add_tail(&new->cr_lru, &free);
333 spin_unlock(&cache->lock); 336 spin_unlock(&cache->lock);
334found: 337found:
335 if (test_bit(RPCAUTH_CRED_NEW, &cred->cr_flags) 338 if (test_bit(RPCAUTH_CRED_NEW, &cred->cr_flags) &&
336 && cred->cr_ops->cr_init != NULL 339 cred->cr_ops->cr_init != NULL &&
337 && !(flags & RPCAUTH_LOOKUP_NEW)) { 340 !(flags & RPCAUTH_LOOKUP_NEW)) {
338 int res = cred->cr_ops->cr_init(auth, cred); 341 int res = cred->cr_ops->cr_init(auth, cred);
339 if (res < 0) { 342 if (res < 0) {
340 put_rpccred(cred); 343 put_rpccred(cred);
@@ -446,31 +449,35 @@ void
446put_rpccred(struct rpc_cred *cred) 449put_rpccred(struct rpc_cred *cred)
447{ 450{
448 /* Fast path for unhashed credentials */ 451 /* Fast path for unhashed credentials */
449 if (test_bit(RPCAUTH_CRED_HASHED, &cred->cr_flags) != 0) 452 if (test_bit(RPCAUTH_CRED_HASHED, &cred->cr_flags) == 0) {
450 goto need_lock; 453 if (atomic_dec_and_test(&cred->cr_count))
451 454 cred->cr_ops->crdestroy(cred);
452 if (!atomic_dec_and_test(&cred->cr_count))
453 return; 455 return;
454 goto out_destroy; 456 }
455need_lock: 457
456 if (!atomic_dec_and_lock(&cred->cr_count, &rpc_credcache_lock)) 458 if (!atomic_dec_and_lock(&cred->cr_count, &rpc_credcache_lock))
457 return; 459 return;
458 if (!list_empty(&cred->cr_lru)) { 460 if (!list_empty(&cred->cr_lru)) {
459 number_cred_unused--; 461 number_cred_unused--;
460 list_del_init(&cred->cr_lru); 462 list_del_init(&cred->cr_lru);
461 } 463 }
462 if (test_bit(RPCAUTH_CRED_UPTODATE, &cred->cr_flags) == 0)
463 rpcauth_unhash_cred(cred);
464 if (test_bit(RPCAUTH_CRED_HASHED, &cred->cr_flags) != 0) { 464 if (test_bit(RPCAUTH_CRED_HASHED, &cred->cr_flags) != 0) {
465 cred->cr_expire = jiffies; 465 if (test_bit(RPCAUTH_CRED_UPTODATE, &cred->cr_flags) != 0) {
466 list_add_tail(&cred->cr_lru, &cred_unused); 466 cred->cr_expire = jiffies;
467 number_cred_unused++; 467 list_add_tail(&cred->cr_lru, &cred_unused);
468 spin_unlock(&rpc_credcache_lock); 468 number_cred_unused++;
469 return; 469 goto out_nodestroy;
470 }
471 if (!rpcauth_unhash_cred(cred)) {
472 /* We were hashed and someone looked us up... */
473 goto out_nodestroy;
474 }
470 } 475 }
471 spin_unlock(&rpc_credcache_lock); 476 spin_unlock(&rpc_credcache_lock);
472out_destroy:
473 cred->cr_ops->crdestroy(cred); 477 cred->cr_ops->crdestroy(cred);
478 return;
479out_nodestroy:
480 spin_unlock(&rpc_credcache_lock);
474} 481}
475EXPORT_SYMBOL_GPL(put_rpccred); 482EXPORT_SYMBOL_GPL(put_rpccred);
476 483
diff --git a/net/sunrpc/auth_generic.c b/net/sunrpc/auth_generic.c
index bf88bf8e9365..8f623b0f03dd 100644
--- a/net/sunrpc/auth_generic.c
+++ b/net/sunrpc/auth_generic.c
@@ -5,6 +5,7 @@
5 */ 5 */
6 6
7#include <linux/err.h> 7#include <linux/err.h>
8#include <linux/slab.h>
8#include <linux/types.h> 9#include <linux/types.h>
9#include <linux/module.h> 10#include <linux/module.h>
10#include <linux/sched.h> 11#include <linux/sched.h>
diff --git a/net/sunrpc/auth_gss/auth_gss.c b/net/sunrpc/auth_gss/auth_gss.c
index fc6a43ccd950..c389ccf6437d 100644
--- a/net/sunrpc/auth_gss/auth_gss.c
+++ b/net/sunrpc/auth_gss/auth_gss.c
@@ -206,8 +206,14 @@ gss_fill_context(const void *p, const void *end, struct gss_cl_ctx *ctx, struct
206 ctx->gc_win = window_size; 206 ctx->gc_win = window_size;
207 /* gssd signals an error by passing ctx->gc_win = 0: */ 207 /* gssd signals an error by passing ctx->gc_win = 0: */
208 if (ctx->gc_win == 0) { 208 if (ctx->gc_win == 0) {
209 /* in which case, p points to an error code which we ignore */ 209 /*
210 p = ERR_PTR(-EACCES); 210 * in which case, p points to an error code. Anything other
211 * than -EKEYEXPIRED gets converted to -EACCES.
212 */
213 p = simple_get_bytes(p, end, &ret, sizeof(ret));
214 if (!IS_ERR(p))
215 p = (ret == -EKEYEXPIRED) ? ERR_PTR(-EKEYEXPIRED) :
216 ERR_PTR(-EACCES);
211 goto err; 217 goto err;
212 } 218 }
213 /* copy the opaque wire context */ 219 /* copy the opaque wire context */
@@ -304,7 +310,7 @@ __gss_find_upcall(struct rpc_inode *rpci, uid_t uid)
304 * to that upcall instead of adding the new upcall. 310 * to that upcall instead of adding the new upcall.
305 */ 311 */
306static inline struct gss_upcall_msg * 312static inline struct gss_upcall_msg *
307gss_add_msg(struct gss_auth *gss_auth, struct gss_upcall_msg *gss_msg) 313gss_add_msg(struct gss_upcall_msg *gss_msg)
308{ 314{
309 struct rpc_inode *rpci = gss_msg->inode; 315 struct rpc_inode *rpci = gss_msg->inode;
310 struct inode *inode = &rpci->vfs_inode; 316 struct inode *inode = &rpci->vfs_inode;
@@ -445,7 +451,7 @@ gss_setup_upcall(struct rpc_clnt *clnt, struct gss_auth *gss_auth, struct rpc_cr
445 gss_new = gss_alloc_msg(gss_auth, uid, clnt, gss_cred->gc_machine_cred); 451 gss_new = gss_alloc_msg(gss_auth, uid, clnt, gss_cred->gc_machine_cred);
446 if (IS_ERR(gss_new)) 452 if (IS_ERR(gss_new))
447 return gss_new; 453 return gss_new;
448 gss_msg = gss_add_msg(gss_auth, gss_new); 454 gss_msg = gss_add_msg(gss_new);
449 if (gss_msg == gss_new) { 455 if (gss_msg == gss_new) {
450 struct inode *inode = &gss_new->inode->vfs_inode; 456 struct inode *inode = &gss_new->inode->vfs_inode;
451 int res = rpc_queue_upcall(inode, &gss_new->msg); 457 int res = rpc_queue_upcall(inode, &gss_new->msg);
@@ -485,7 +491,7 @@ gss_refresh_upcall(struct rpc_task *task)
485 dprintk("RPC: %5u gss_refresh_upcall for uid %u\n", task->tk_pid, 491 dprintk("RPC: %5u gss_refresh_upcall for uid %u\n", task->tk_pid,
486 cred->cr_uid); 492 cred->cr_uid);
487 gss_msg = gss_setup_upcall(task->tk_client, gss_auth, cred); 493 gss_msg = gss_setup_upcall(task->tk_client, gss_auth, cred);
488 if (IS_ERR(gss_msg) == -EAGAIN) { 494 if (PTR_ERR(gss_msg) == -EAGAIN) {
489 /* XXX: warning on the first, under the assumption we 495 /* XXX: warning on the first, under the assumption we
490 * shouldn't normally hit this case on a refresh. */ 496 * shouldn't normally hit this case on a refresh. */
491 warn_gssd(); 497 warn_gssd();
@@ -644,7 +650,23 @@ gss_pipe_downcall(struct file *filp, const char __user *src, size_t mlen)
644 p = gss_fill_context(p, end, ctx, gss_msg->auth->mech); 650 p = gss_fill_context(p, end, ctx, gss_msg->auth->mech);
645 if (IS_ERR(p)) { 651 if (IS_ERR(p)) {
646 err = PTR_ERR(p); 652 err = PTR_ERR(p);
647 gss_msg->msg.errno = (err == -EAGAIN) ? -EAGAIN : -EACCES; 653 switch (err) {
654 case -EACCES:
655 case -EKEYEXPIRED:
656 gss_msg->msg.errno = err;
657 err = mlen;
658 break;
659 case -EFAULT:
660 case -ENOMEM:
661 case -EINVAL:
662 case -ENOSYS:
663 gss_msg->msg.errno = -EAGAIN;
664 break;
665 default:
666 printk(KERN_CRIT "%s: bad return from "
667 "gss_fill_context: %zd\n", __func__, err);
668 BUG();
669 }
648 goto err_release_msg; 670 goto err_release_msg;
649 } 671 }
650 gss_msg->ctx = gss_get_ctx(ctx); 672 gss_msg->ctx = gss_get_ctx(ctx);
@@ -1258,9 +1280,8 @@ alloc_enc_pages(struct rpc_rqst *rqstp)
1258 rqstp->rq_release_snd_buf = priv_release_snd_buf; 1280 rqstp->rq_release_snd_buf = priv_release_snd_buf;
1259 return 0; 1281 return 0;
1260out_free: 1282out_free:
1261 for (i--; i >= 0; i--) { 1283 rqstp->rq_enc_pages_num = i;
1262 __free_page(rqstp->rq_enc_pages[i]); 1284 priv_release_snd_buf(rqstp);
1263 }
1264out: 1285out:
1265 return -EAGAIN; 1286 return -EAGAIN;
1266} 1287}
diff --git a/net/sunrpc/auth_gss/gss_generic_token.c b/net/sunrpc/auth_gss/gss_generic_token.c
index c0ba39c4f5f2..310b78e99456 100644
--- a/net/sunrpc/auth_gss/gss_generic_token.c
+++ b/net/sunrpc/auth_gss/gss_generic_token.c
@@ -33,7 +33,6 @@
33 33
34#include <linux/types.h> 34#include <linux/types.h>
35#include <linux/module.h> 35#include <linux/module.h>
36#include <linux/slab.h>
37#include <linux/string.h> 36#include <linux/string.h>
38#include <linux/sunrpc/sched.h> 37#include <linux/sunrpc/sched.h>
39#include <linux/sunrpc/gss_asn1.h> 38#include <linux/sunrpc/gss_asn1.h>
diff --git a/net/sunrpc/auth_gss/gss_krb5_crypto.c b/net/sunrpc/auth_gss/gss_krb5_crypto.c
index c93fca204558..e9b636176687 100644
--- a/net/sunrpc/auth_gss/gss_krb5_crypto.c
+++ b/net/sunrpc/auth_gss/gss_krb5_crypto.c
@@ -37,7 +37,6 @@
37#include <linux/err.h> 37#include <linux/err.h>
38#include <linux/types.h> 38#include <linux/types.h>
39#include <linux/mm.h> 39#include <linux/mm.h>
40#include <linux/slab.h>
41#include <linux/scatterlist.h> 40#include <linux/scatterlist.h>
42#include <linux/crypto.h> 41#include <linux/crypto.h>
43#include <linux/highmem.h> 42#include <linux/highmem.h>
diff --git a/net/sunrpc/auth_gss/gss_krb5_mech.c b/net/sunrpc/auth_gss/gss_krb5_mech.c
index ef45eba22485..2deb0ed72ff4 100644
--- a/net/sunrpc/auth_gss/gss_krb5_mech.c
+++ b/net/sunrpc/auth_gss/gss_krb5_mech.c
@@ -131,8 +131,10 @@ gss_import_sec_context_kerberos(const void *p,
131 struct krb5_ctx *ctx; 131 struct krb5_ctx *ctx;
132 int tmp; 132 int tmp;
133 133
134 if (!(ctx = kzalloc(sizeof(*ctx), GFP_NOFS))) 134 if (!(ctx = kzalloc(sizeof(*ctx), GFP_NOFS))) {
135 p = ERR_PTR(-ENOMEM);
135 goto out_err; 136 goto out_err;
137 }
136 138
137 p = simple_get_bytes(p, end, &ctx->initiate, sizeof(ctx->initiate)); 139 p = simple_get_bytes(p, end, &ctx->initiate, sizeof(ctx->initiate));
138 if (IS_ERR(p)) 140 if (IS_ERR(p))
diff --git a/net/sunrpc/auth_gss/gss_krb5_seal.c b/net/sunrpc/auth_gss/gss_krb5_seal.c
index b8f42ef7178e..88fe6e75ed7e 100644
--- a/net/sunrpc/auth_gss/gss_krb5_seal.c
+++ b/net/sunrpc/auth_gss/gss_krb5_seal.c
@@ -59,7 +59,6 @@
59 */ 59 */
60 60
61#include <linux/types.h> 61#include <linux/types.h>
62#include <linux/slab.h>
63#include <linux/jiffies.h> 62#include <linux/jiffies.h>
64#include <linux/sunrpc/gss_krb5.h> 63#include <linux/sunrpc/gss_krb5.h>
65#include <linux/random.h> 64#include <linux/random.h>
diff --git a/net/sunrpc/auth_gss/gss_krb5_seqnum.c b/net/sunrpc/auth_gss/gss_krb5_seqnum.c
index f160be6c1a46..6331cd6866ec 100644
--- a/net/sunrpc/auth_gss/gss_krb5_seqnum.c
+++ b/net/sunrpc/auth_gss/gss_krb5_seqnum.c
@@ -32,7 +32,6 @@
32 */ 32 */
33 33
34#include <linux/types.h> 34#include <linux/types.h>
35#include <linux/slab.h>
36#include <linux/sunrpc/gss_krb5.h> 35#include <linux/sunrpc/gss_krb5.h>
37#include <linux/crypto.h> 36#include <linux/crypto.h>
38 37
@@ -75,8 +74,8 @@ krb5_get_seq_num(struct crypto_blkcipher *key,
75 if ((code = krb5_decrypt(key, cksum, buf, plain, 8))) 74 if ((code = krb5_decrypt(key, cksum, buf, plain, 8)))
76 return code; 75 return code;
77 76
78 if ((plain[4] != plain[5]) || (plain[4] != plain[6]) 77 if ((plain[4] != plain[5]) || (plain[4] != plain[6]) ||
79 || (plain[4] != plain[7])) 78 (plain[4] != plain[7]))
80 return (s32)KG_BAD_SEQ; 79 return (s32)KG_BAD_SEQ;
81 80
82 *direction = plain[4]; 81 *direction = plain[4];
diff --git a/net/sunrpc/auth_gss/gss_krb5_unseal.c b/net/sunrpc/auth_gss/gss_krb5_unseal.c
index 066ec73c84d6..ce6c247edad0 100644
--- a/net/sunrpc/auth_gss/gss_krb5_unseal.c
+++ b/net/sunrpc/auth_gss/gss_krb5_unseal.c
@@ -58,7 +58,6 @@
58 */ 58 */
59 59
60#include <linux/types.h> 60#include <linux/types.h>
61#include <linux/slab.h>
62#include <linux/jiffies.h> 61#include <linux/jiffies.h>
63#include <linux/sunrpc/gss_krb5.h> 62#include <linux/sunrpc/gss_krb5.h>
64#include <linux/crypto.h> 63#include <linux/crypto.h>
diff --git a/net/sunrpc/auth_gss/gss_krb5_wrap.c b/net/sunrpc/auth_gss/gss_krb5_wrap.c
index ae8e69b59c4c..a6e905637e03 100644
--- a/net/sunrpc/auth_gss/gss_krb5_wrap.c
+++ b/net/sunrpc/auth_gss/gss_krb5_wrap.c
@@ -1,5 +1,4 @@
1#include <linux/types.h> 1#include <linux/types.h>
2#include <linux/slab.h>
3#include <linux/jiffies.h> 2#include <linux/jiffies.h>
4#include <linux/sunrpc/gss_krb5.h> 3#include <linux/sunrpc/gss_krb5.h>
5#include <linux/random.h> 4#include <linux/random.h>
diff --git a/net/sunrpc/auth_gss/gss_mech_switch.c b/net/sunrpc/auth_gss/gss_mech_switch.c
index 6efbb0cd3c7c..76e4c6f4ac3c 100644
--- a/net/sunrpc/auth_gss/gss_mech_switch.c
+++ b/net/sunrpc/auth_gss/gss_mech_switch.c
@@ -252,7 +252,7 @@ gss_import_sec_context(const void *input_token, size_t bufsize,
252 struct gss_ctx **ctx_id) 252 struct gss_ctx **ctx_id)
253{ 253{
254 if (!(*ctx_id = kzalloc(sizeof(**ctx_id), GFP_KERNEL))) 254 if (!(*ctx_id = kzalloc(sizeof(**ctx_id), GFP_KERNEL)))
255 return GSS_S_FAILURE; 255 return -ENOMEM;
256 (*ctx_id)->mech_type = gss_mech_get(mech); 256 (*ctx_id)->mech_type = gss_mech_get(mech);
257 257
258 return mech->gm_ops 258 return mech->gm_ops
diff --git a/net/sunrpc/auth_gss/gss_spkm3_seal.c b/net/sunrpc/auth_gss/gss_spkm3_seal.c
index c832712f8d55..5a3a65a0e2b4 100644
--- a/net/sunrpc/auth_gss/gss_spkm3_seal.c
+++ b/net/sunrpc/auth_gss/gss_spkm3_seal.c
@@ -34,7 +34,6 @@
34 */ 34 */
35 35
36#include <linux/types.h> 36#include <linux/types.h>
37#include <linux/slab.h>
38#include <linux/jiffies.h> 37#include <linux/jiffies.h>
39#include <linux/sunrpc/gss_spkm3.h> 38#include <linux/sunrpc/gss_spkm3.h>
40#include <linux/random.h> 39#include <linux/random.h>
diff --git a/net/sunrpc/auth_gss/svcauth_gss.c b/net/sunrpc/auth_gss/svcauth_gss.c
index f6c51e562a02..b81e790ef9f4 100644
--- a/net/sunrpc/auth_gss/svcauth_gss.c
+++ b/net/sunrpc/auth_gss/svcauth_gss.c
@@ -37,6 +37,7 @@
37 * 37 *
38 */ 38 */
39 39
40#include <linux/slab.h>
40#include <linux/types.h> 41#include <linux/types.h>
41#include <linux/module.h> 42#include <linux/module.h>
42#include <linux/pagemap.h> 43#include <linux/pagemap.h>
@@ -105,8 +106,8 @@ static int rsi_match(struct cache_head *a, struct cache_head *b)
105{ 106{
106 struct rsi *item = container_of(a, struct rsi, h); 107 struct rsi *item = container_of(a, struct rsi, h);
107 struct rsi *tmp = container_of(b, struct rsi, h); 108 struct rsi *tmp = container_of(b, struct rsi, h);
108 return netobj_equal(&item->in_handle, &tmp->in_handle) 109 return netobj_equal(&item->in_handle, &tmp->in_handle) &&
109 && netobj_equal(&item->in_token, &tmp->in_token); 110 netobj_equal(&item->in_token, &tmp->in_token);
110} 111}
111 112
112static int dup_to_netobj(struct xdr_netobj *dst, char *src, int len) 113static int dup_to_netobj(struct xdr_netobj *dst, char *src, int len)
diff --git a/net/sunrpc/auth_unix.c b/net/sunrpc/auth_unix.c
index 46b2647c5bd2..aac2f8b4ee21 100644
--- a/net/sunrpc/auth_unix.c
+++ b/net/sunrpc/auth_unix.c
@@ -6,6 +6,7 @@
6 * Copyright (C) 1996, Olaf Kirch <okir@monad.swb.de> 6 * Copyright (C) 1996, Olaf Kirch <okir@monad.swb.de>
7 */ 7 */
8 8
9#include <linux/slab.h>
9#include <linux/types.h> 10#include <linux/types.h>
10#include <linux/sched.h> 11#include <linux/sched.h>
11#include <linux/module.h> 12#include <linux/module.h>
diff --git a/net/sunrpc/backchannel_rqst.c b/net/sunrpc/backchannel_rqst.c
index 553621fb2c41..cf06af3b63c6 100644
--- a/net/sunrpc/backchannel_rqst.c
+++ b/net/sunrpc/backchannel_rqst.c
@@ -22,6 +22,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22******************************************************************************/ 22******************************************************************************/
23 23
24#include <linux/tcp.h> 24#include <linux/tcp.h>
25#include <linux/slab.h>
25#include <linux/sunrpc/xprt.h> 26#include <linux/sunrpc/xprt.h>
26 27
27#ifdef RPC_DEBUG 28#ifdef RPC_DEBUG
diff --git a/net/sunrpc/bc_svc.c b/net/sunrpc/bc_svc.c
index 13f214f53120..f0c05d3311c1 100644
--- a/net/sunrpc/bc_svc.c
+++ b/net/sunrpc/bc_svc.c
@@ -37,21 +37,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 37
38#define RPCDBG_FACILITY RPCDBG_SVCDSP 38#define RPCDBG_FACILITY RPCDBG_SVCDSP
39 39
40void bc_release_request(struct rpc_task *task)
41{
42 struct rpc_rqst *req = task->tk_rqstp;
43
44 dprintk("RPC: bc_release_request: task= %p\n", task);
45
46 /*
47 * Release this request only if it's a backchannel
48 * preallocated request
49 */
50 if (!bc_prealloc(req))
51 return;
52 xprt_free_bc_request(req);
53}
54
55/* Empty callback ops */ 40/* Empty callback ops */
56static const struct rpc_call_ops nfs41_callback_ops = { 41static const struct rpc_call_ops nfs41_callback_ops = {
57}; 42};
diff --git a/net/sunrpc/cache.c b/net/sunrpc/cache.c
index d6eee291a0e2..39bddba53ba1 100644
--- a/net/sunrpc/cache.c
+++ b/net/sunrpc/cache.c
@@ -401,9 +401,8 @@ static int cache_clean(void)
401 for (; ch; cp= & ch->next, ch= *cp) { 401 for (; ch; cp= & ch->next, ch= *cp) {
402 if (current_detail->nextcheck > ch->expiry_time) 402 if (current_detail->nextcheck > ch->expiry_time)
403 current_detail->nextcheck = ch->expiry_time+1; 403 current_detail->nextcheck = ch->expiry_time+1;
404 if (ch->expiry_time >= get_seconds() 404 if (ch->expiry_time >= get_seconds() &&
405 && ch->last_refresh >= current_detail->flush_time 405 ch->last_refresh >= current_detail->flush_time)
406 )
407 continue; 406 continue;
408 if (test_and_clear_bit(CACHE_PENDING, &ch->flags)) 407 if (test_and_clear_bit(CACHE_PENDING, &ch->flags))
409 cache_dequeue(current_detail, ch); 408 cache_dequeue(current_detail, ch);
diff --git a/net/sunrpc/clnt.c b/net/sunrpc/clnt.c
index 38829e20500b..19c9983d5360 100644
--- a/net/sunrpc/clnt.c
+++ b/net/sunrpc/clnt.c
@@ -79,7 +79,7 @@ static void call_connect_status(struct rpc_task *task);
79 79
80static __be32 *rpc_encode_header(struct rpc_task *task); 80static __be32 *rpc_encode_header(struct rpc_task *task);
81static __be32 *rpc_verify_header(struct rpc_task *task); 81static __be32 *rpc_verify_header(struct rpc_task *task);
82static int rpc_ping(struct rpc_clnt *clnt, int flags); 82static int rpc_ping(struct rpc_clnt *clnt);
83 83
84static void rpc_register_client(struct rpc_clnt *clnt) 84static void rpc_register_client(struct rpc_clnt *clnt)
85{ 85{
@@ -340,7 +340,7 @@ struct rpc_clnt *rpc_create(struct rpc_create_args *args)
340 return clnt; 340 return clnt;
341 341
342 if (!(args->flags & RPC_CLNT_CREATE_NOPING)) { 342 if (!(args->flags & RPC_CLNT_CREATE_NOPING)) {
343 int err = rpc_ping(clnt, RPC_TASK_SOFT); 343 int err = rpc_ping(clnt);
344 if (err != 0) { 344 if (err != 0) {
345 rpc_shutdown_client(clnt); 345 rpc_shutdown_client(clnt);
346 return ERR_PTR(err); 346 return ERR_PTR(err);
@@ -528,7 +528,7 @@ struct rpc_clnt *rpc_bind_new_program(struct rpc_clnt *old,
528 clnt->cl_prog = program->number; 528 clnt->cl_prog = program->number;
529 clnt->cl_vers = version->number; 529 clnt->cl_vers = version->number;
530 clnt->cl_stats = program->stats; 530 clnt->cl_stats = program->stats;
531 err = rpc_ping(clnt, RPC_TASK_SOFT); 531 err = rpc_ping(clnt);
532 if (err != 0) { 532 if (err != 0) {
533 rpc_shutdown_client(clnt); 533 rpc_shutdown_client(clnt);
534 clnt = ERR_PTR(err); 534 clnt = ERR_PTR(err);
@@ -659,6 +659,7 @@ struct rpc_task *rpc_run_bc_task(struct rpc_rqst *req,
659 task = rpc_new_task(&task_setup_data); 659 task = rpc_new_task(&task_setup_data);
660 if (!task) { 660 if (!task) {
661 xprt_free_bc_request(req); 661 xprt_free_bc_request(req);
662 task = ERR_PTR(-ENOMEM);
662 goto out; 663 goto out;
663 } 664 }
664 task->tk_rqstp = req; 665 task->tk_rqstp = req;
@@ -1060,7 +1061,7 @@ call_bind_status(struct rpc_task *task)
1060 goto retry_timeout; 1061 goto retry_timeout;
1061 case -EPFNOSUPPORT: 1062 case -EPFNOSUPPORT:
1062 /* server doesn't support any rpcbind version we know of */ 1063 /* server doesn't support any rpcbind version we know of */
1063 dprintk("RPC: %5u remote rpcbind service unavailable\n", 1064 dprintk("RPC: %5u unrecognized remote rpcbind service\n",
1064 task->tk_pid); 1065 task->tk_pid);
1065 break; 1066 break;
1066 case -EPROTONOSUPPORT: 1067 case -EPROTONOSUPPORT:
@@ -1069,6 +1070,21 @@ call_bind_status(struct rpc_task *task)
1069 task->tk_status = 0; 1070 task->tk_status = 0;
1070 task->tk_action = call_bind; 1071 task->tk_action = call_bind;
1071 return; 1072 return;
1073 case -ECONNREFUSED: /* connection problems */
1074 case -ECONNRESET:
1075 case -ENOTCONN:
1076 case -EHOSTDOWN:
1077 case -EHOSTUNREACH:
1078 case -ENETUNREACH:
1079 case -EPIPE:
1080 dprintk("RPC: %5u remote rpcbind unreachable: %d\n",
1081 task->tk_pid, task->tk_status);
1082 if (!RPC_IS_SOFTCONN(task)) {
1083 rpc_delay(task, 5*HZ);
1084 goto retry_timeout;
1085 }
1086 status = task->tk_status;
1087 break;
1072 default: 1088 default:
1073 dprintk("RPC: %5u unrecognized rpcbind error (%d)\n", 1089 dprintk("RPC: %5u unrecognized rpcbind error (%d)\n",
1074 task->tk_pid, -task->tk_status); 1090 task->tk_pid, -task->tk_status);
@@ -1180,11 +1196,25 @@ static void
1180call_transmit_status(struct rpc_task *task) 1196call_transmit_status(struct rpc_task *task)
1181{ 1197{
1182 task->tk_action = call_status; 1198 task->tk_action = call_status;
1199
1200 /*
1201 * Common case: success. Force the compiler to put this
1202 * test first.
1203 */
1204 if (task->tk_status == 0) {
1205 xprt_end_transmit(task);
1206 rpc_task_force_reencode(task);
1207 return;
1208 }
1209
1183 switch (task->tk_status) { 1210 switch (task->tk_status) {
1184 case -EAGAIN: 1211 case -EAGAIN:
1185 break; 1212 break;
1186 default: 1213 default:
1214 dprint_status(task);
1187 xprt_end_transmit(task); 1215 xprt_end_transmit(task);
1216 rpc_task_force_reencode(task);
1217 break;
1188 /* 1218 /*
1189 * Special cases: if we've been waiting on the 1219 * Special cases: if we've been waiting on the
1190 * socket's write_space() callback, or if the 1220 * socket's write_space() callback, or if the
@@ -1192,11 +1222,16 @@ call_transmit_status(struct rpc_task *task)
1192 * then hold onto the transport lock. 1222 * then hold onto the transport lock.
1193 */ 1223 */
1194 case -ECONNREFUSED: 1224 case -ECONNREFUSED:
1195 case -ECONNRESET:
1196 case -ENOTCONN:
1197 case -EHOSTDOWN: 1225 case -EHOSTDOWN:
1198 case -EHOSTUNREACH: 1226 case -EHOSTUNREACH:
1199 case -ENETUNREACH: 1227 case -ENETUNREACH:
1228 if (RPC_IS_SOFTCONN(task)) {
1229 xprt_end_transmit(task);
1230 rpc_exit(task, task->tk_status);
1231 break;
1232 }
1233 case -ECONNRESET:
1234 case -ENOTCONN:
1200 case -EPIPE: 1235 case -EPIPE:
1201 rpc_task_force_reencode(task); 1236 rpc_task_force_reencode(task);
1202 } 1237 }
@@ -1346,6 +1381,10 @@ call_timeout(struct rpc_task *task)
1346 dprintk("RPC: %5u call_timeout (major)\n", task->tk_pid); 1381 dprintk("RPC: %5u call_timeout (major)\n", task->tk_pid);
1347 task->tk_timeouts++; 1382 task->tk_timeouts++;
1348 1383
1384 if (RPC_IS_SOFTCONN(task)) {
1385 rpc_exit(task, -ETIMEDOUT);
1386 return;
1387 }
1349 if (RPC_IS_SOFT(task)) { 1388 if (RPC_IS_SOFT(task)) {
1350 if (clnt->cl_chatty) 1389 if (clnt->cl_chatty)
1351 printk(KERN_NOTICE "%s: server %s not responding, timed out\n", 1390 printk(KERN_NOTICE "%s: server %s not responding, timed out\n",
@@ -1675,14 +1714,14 @@ static struct rpc_procinfo rpcproc_null = {
1675 .p_decode = rpcproc_decode_null, 1714 .p_decode = rpcproc_decode_null,
1676}; 1715};
1677 1716
1678static int rpc_ping(struct rpc_clnt *clnt, int flags) 1717static int rpc_ping(struct rpc_clnt *clnt)
1679{ 1718{
1680 struct rpc_message msg = { 1719 struct rpc_message msg = {
1681 .rpc_proc = &rpcproc_null, 1720 .rpc_proc = &rpcproc_null,
1682 }; 1721 };
1683 int err; 1722 int err;
1684 msg.rpc_cred = authnull_ops.lookup_cred(NULL, NULL, 0); 1723 msg.rpc_cred = authnull_ops.lookup_cred(NULL, NULL, 0);
1685 err = rpc_call_sync(clnt, &msg, flags); 1724 err = rpc_call_sync(clnt, &msg, RPC_TASK_SOFT | RPC_TASK_SOFTCONN);
1686 put_rpccred(msg.rpc_cred); 1725 put_rpccred(msg.rpc_cred);
1687 return err; 1726 return err;
1688} 1727}
diff --git a/net/sunrpc/rpc_pipe.c b/net/sunrpc/rpc_pipe.c
index 49278f830367..20e30c6f8355 100644
--- a/net/sunrpc/rpc_pipe.c
+++ b/net/sunrpc/rpc_pipe.c
@@ -78,7 +78,7 @@ rpc_timeout_upcall_queue(struct work_struct *work)
78} 78}
79 79
80/** 80/**
81 * rpc_queue_upcall 81 * rpc_queue_upcall - queue an upcall message to userspace
82 * @inode: inode of upcall pipe on which to queue given message 82 * @inode: inode of upcall pipe on which to queue given message
83 * @msg: message to queue 83 * @msg: message to queue
84 * 84 *
@@ -587,6 +587,8 @@ static struct dentry *__rpc_lookup_create_exclusive(struct dentry *parent,
587 struct dentry *dentry; 587 struct dentry *dentry;
588 588
589 dentry = __rpc_lookup_create(parent, name); 589 dentry = __rpc_lookup_create(parent, name);
590 if (IS_ERR(dentry))
591 return dentry;
590 if (dentry->d_inode == NULL) 592 if (dentry->d_inode == NULL)
591 return dentry; 593 return dentry;
592 dput(dentry); 594 dput(dentry);
@@ -999,19 +1001,14 @@ rpc_fill_super(struct super_block *sb, void *data, int silent)
999 inode = rpc_get_inode(sb, S_IFDIR | 0755); 1001 inode = rpc_get_inode(sb, S_IFDIR | 0755);
1000 if (!inode) 1002 if (!inode)
1001 return -ENOMEM; 1003 return -ENOMEM;
1002 root = d_alloc_root(inode); 1004 sb->s_root = root = d_alloc_root(inode);
1003 if (!root) { 1005 if (!root) {
1004 iput(inode); 1006 iput(inode);
1005 return -ENOMEM; 1007 return -ENOMEM;
1006 } 1008 }
1007 if (rpc_populate(root, files, RPCAUTH_lockd, RPCAUTH_RootEOF, NULL)) 1009 if (rpc_populate(root, files, RPCAUTH_lockd, RPCAUTH_RootEOF, NULL))
1008 goto out; 1010 return -ENOMEM;
1009 sb->s_root = root;
1010 return 0; 1011 return 0;
1011out:
1012 d_genocide(root);
1013 dput(root);
1014 return -ENOMEM;
1015} 1012}
1016 1013
1017static int 1014static int
diff --git a/net/sunrpc/rpcb_clnt.c b/net/sunrpc/rpcb_clnt.c
index 830faf4d9997..121105355f60 100644
--- a/net/sunrpc/rpcb_clnt.c
+++ b/net/sunrpc/rpcb_clnt.c
@@ -20,6 +20,8 @@
20#include <linux/in6.h> 20#include <linux/in6.h>
21#include <linux/kernel.h> 21#include <linux/kernel.h>
22#include <linux/errno.h> 22#include <linux/errno.h>
23#include <linux/mutex.h>
24#include <linux/slab.h>
23#include <net/ipv6.h> 25#include <net/ipv6.h>
24 26
25#include <linux/sunrpc/clnt.h> 27#include <linux/sunrpc/clnt.h>
@@ -110,6 +112,9 @@ static void rpcb_getport_done(struct rpc_task *, void *);
110static void rpcb_map_release(void *data); 112static void rpcb_map_release(void *data);
111static struct rpc_program rpcb_program; 113static struct rpc_program rpcb_program;
112 114
115static struct rpc_clnt * rpcb_local_clnt;
116static struct rpc_clnt * rpcb_local_clnt4;
117
113struct rpcbind_args { 118struct rpcbind_args {
114 struct rpc_xprt * r_xprt; 119 struct rpc_xprt * r_xprt;
115 120
@@ -163,21 +168,60 @@ static const struct sockaddr_in rpcb_inaddr_loopback = {
163 .sin_port = htons(RPCBIND_PORT), 168 .sin_port = htons(RPCBIND_PORT),
164}; 169};
165 170
166static struct rpc_clnt *rpcb_create_local(struct sockaddr *addr, 171static DEFINE_MUTEX(rpcb_create_local_mutex);
167 size_t addrlen, u32 version) 172
173/*
174 * Returns zero on success, otherwise a negative errno value
175 * is returned.
176 */
177static int rpcb_create_local(void)
168{ 178{
169 struct rpc_create_args args = { 179 struct rpc_create_args args = {
170 .protocol = XPRT_TRANSPORT_UDP, 180 .protocol = XPRT_TRANSPORT_TCP,
171 .address = addr, 181 .address = (struct sockaddr *)&rpcb_inaddr_loopback,
172 .addrsize = addrlen, 182 .addrsize = sizeof(rpcb_inaddr_loopback),
173 .servername = "localhost", 183 .servername = "localhost",
174 .program = &rpcb_program, 184 .program = &rpcb_program,
175 .version = version, 185 .version = RPCBVERS_2,
176 .authflavor = RPC_AUTH_UNIX, 186 .authflavor = RPC_AUTH_UNIX,
177 .flags = RPC_CLNT_CREATE_NOPING, 187 .flags = RPC_CLNT_CREATE_NOPING,
178 }; 188 };
189 struct rpc_clnt *clnt, *clnt4;
190 int result = 0;
191
192 if (rpcb_local_clnt)
193 return result;
194
195 mutex_lock(&rpcb_create_local_mutex);
196 if (rpcb_local_clnt)
197 goto out;
198
199 clnt = rpc_create(&args);
200 if (IS_ERR(clnt)) {
201 dprintk("RPC: failed to create local rpcbind "
202 "client (errno %ld).\n", PTR_ERR(clnt));
203 result = -PTR_ERR(clnt);
204 goto out;
205 }
179 206
180 return rpc_create(&args); 207 /*
208 * This results in an RPC ping. On systems running portmapper,
209 * the v4 ping will fail. Proceed anyway, but disallow rpcb
210 * v4 upcalls.
211 */
212 clnt4 = rpc_bind_new_program(clnt, &rpcb_program, RPCBVERS_4);
213 if (IS_ERR(clnt4)) {
214 dprintk("RPC: failed to create local rpcbind v4 "
215 "cleint (errno %ld).\n", PTR_ERR(clnt4));
216 clnt4 = NULL;
217 }
218
219 rpcb_local_clnt = clnt;
220 rpcb_local_clnt4 = clnt4;
221
222out:
223 mutex_unlock(&rpcb_create_local_mutex);
224 return result;
181} 225}
182 226
183static struct rpc_clnt *rpcb_create(char *hostname, struct sockaddr *srvaddr, 227static struct rpc_clnt *rpcb_create(char *hostname, struct sockaddr *srvaddr,
@@ -209,22 +253,13 @@ static struct rpc_clnt *rpcb_create(char *hostname, struct sockaddr *srvaddr,
209 return rpc_create(&args); 253 return rpc_create(&args);
210} 254}
211 255
212static int rpcb_register_call(const u32 version, struct rpc_message *msg) 256static int rpcb_register_call(struct rpc_clnt *clnt, struct rpc_message *msg)
213{ 257{
214 struct sockaddr *addr = (struct sockaddr *)&rpcb_inaddr_loopback;
215 size_t addrlen = sizeof(rpcb_inaddr_loopback);
216 struct rpc_clnt *rpcb_clnt;
217 int result, error = 0; 258 int result, error = 0;
218 259
219 msg->rpc_resp = &result; 260 msg->rpc_resp = &result;
220 261
221 rpcb_clnt = rpcb_create_local(addr, addrlen, version); 262 error = rpc_call_sync(clnt, msg, RPC_TASK_SOFTCONN);
222 if (!IS_ERR(rpcb_clnt)) {
223 error = rpc_call_sync(rpcb_clnt, msg, 0);
224 rpc_shutdown_client(rpcb_clnt);
225 } else
226 error = PTR_ERR(rpcb_clnt);
227
228 if (error < 0) { 263 if (error < 0) {
229 dprintk("RPC: failed to contact local rpcbind " 264 dprintk("RPC: failed to contact local rpcbind "
230 "server (errno %d).\n", -error); 265 "server (errno %d).\n", -error);
@@ -279,6 +314,11 @@ int rpcb_register(u32 prog, u32 vers, int prot, unsigned short port)
279 struct rpc_message msg = { 314 struct rpc_message msg = {
280 .rpc_argp = &map, 315 .rpc_argp = &map,
281 }; 316 };
317 int error;
318
319 error = rpcb_create_local();
320 if (error)
321 return error;
282 322
283 dprintk("RPC: %sregistering (%u, %u, %d, %u) with local " 323 dprintk("RPC: %sregistering (%u, %u, %d, %u) with local "
284 "rpcbind\n", (port ? "" : "un"), 324 "rpcbind\n", (port ? "" : "un"),
@@ -288,7 +328,7 @@ int rpcb_register(u32 prog, u32 vers, int prot, unsigned short port)
288 if (port) 328 if (port)
289 msg.rpc_proc = &rpcb_procedures2[RPCBPROC_SET]; 329 msg.rpc_proc = &rpcb_procedures2[RPCBPROC_SET];
290 330
291 return rpcb_register_call(RPCBVERS_2, &msg); 331 return rpcb_register_call(rpcb_local_clnt, &msg);
292} 332}
293 333
294/* 334/*
@@ -313,7 +353,7 @@ static int rpcb_register_inet4(const struct sockaddr *sap,
313 if (port) 353 if (port)
314 msg->rpc_proc = &rpcb_procedures4[RPCBPROC_SET]; 354 msg->rpc_proc = &rpcb_procedures4[RPCBPROC_SET];
315 355
316 result = rpcb_register_call(RPCBVERS_4, msg); 356 result = rpcb_register_call(rpcb_local_clnt4, msg);
317 kfree(map->r_addr); 357 kfree(map->r_addr);
318 return result; 358 return result;
319} 359}
@@ -340,7 +380,7 @@ static int rpcb_register_inet6(const struct sockaddr *sap,
340 if (port) 380 if (port)
341 msg->rpc_proc = &rpcb_procedures4[RPCBPROC_SET]; 381 msg->rpc_proc = &rpcb_procedures4[RPCBPROC_SET];
342 382
343 result = rpcb_register_call(RPCBVERS_4, msg); 383 result = rpcb_register_call(rpcb_local_clnt4, msg);
344 kfree(map->r_addr); 384 kfree(map->r_addr);
345 return result; 385 return result;
346} 386}
@@ -356,7 +396,7 @@ static int rpcb_unregister_all_protofamilies(struct rpc_message *msg)
356 map->r_addr = ""; 396 map->r_addr = "";
357 msg->rpc_proc = &rpcb_procedures4[RPCBPROC_UNSET]; 397 msg->rpc_proc = &rpcb_procedures4[RPCBPROC_UNSET];
358 398
359 return rpcb_register_call(RPCBVERS_4, msg); 399 return rpcb_register_call(rpcb_local_clnt4, msg);
360} 400}
361 401
362/** 402/**
@@ -414,6 +454,13 @@ int rpcb_v4_register(const u32 program, const u32 version,
414 struct rpc_message msg = { 454 struct rpc_message msg = {
415 .rpc_argp = &map, 455 .rpc_argp = &map,
416 }; 456 };
457 int error;
458
459 error = rpcb_create_local();
460 if (error)
461 return error;
462 if (rpcb_local_clnt4 == NULL)
463 return -EPROTONOSUPPORT;
417 464
418 if (address == NULL) 465 if (address == NULL)
419 return rpcb_unregister_all_protofamilies(&msg); 466 return rpcb_unregister_all_protofamilies(&msg);
@@ -491,7 +538,7 @@ static struct rpc_task *rpcb_call_async(struct rpc_clnt *rpcb_clnt, struct rpcbi
491 .rpc_message = &msg, 538 .rpc_message = &msg,
492 .callback_ops = &rpcb_getport_ops, 539 .callback_ops = &rpcb_getport_ops,
493 .callback_data = map, 540 .callback_data = map,
494 .flags = RPC_TASK_ASYNC, 541 .flags = RPC_TASK_ASYNC | RPC_TASK_SOFTCONN,
495 }; 542 };
496 543
497 return rpc_run_task(&task_setup_data); 544 return rpc_run_task(&task_setup_data);
@@ -1027,3 +1074,15 @@ static struct rpc_program rpcb_program = {
1027 .version = rpcb_version, 1074 .version = rpcb_version,
1028 .stats = &rpcb_stats, 1075 .stats = &rpcb_stats,
1029}; 1076};
1077
1078/**
1079 * cleanup_rpcb_clnt - remove xprtsock's sysctls, unregister
1080 *
1081 */
1082void cleanup_rpcb_clnt(void)
1083{
1084 if (rpcb_local_clnt4)
1085 rpc_shutdown_client(rpcb_local_clnt4);
1086 if (rpcb_local_clnt)
1087 rpc_shutdown_client(rpcb_local_clnt);
1088}
diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c
index cef74ba0666c..aae6907fd546 100644
--- a/net/sunrpc/sched.c
+++ b/net/sunrpc/sched.c
@@ -210,6 +210,7 @@ void rpc_init_priority_wait_queue(struct rpc_wait_queue *queue, const char *qnam
210{ 210{
211 __rpc_init_priority_wait_queue(queue, qname, RPC_NR_PRIORITY); 211 __rpc_init_priority_wait_queue(queue, qname, RPC_NR_PRIORITY);
212} 212}
213EXPORT_SYMBOL_GPL(rpc_init_priority_wait_queue);
213 214
214void rpc_init_wait_queue(struct rpc_wait_queue *queue, const char *qname) 215void rpc_init_wait_queue(struct rpc_wait_queue *queue, const char *qname)
215{ 216{
@@ -385,6 +386,20 @@ static void rpc_wake_up_task_queue_locked(struct rpc_wait_queue *queue, struct r
385} 386}
386 387
387/* 388/*
389 * Tests whether rpc queue is empty
390 */
391int rpc_queue_empty(struct rpc_wait_queue *queue)
392{
393 int res;
394
395 spin_lock_bh(&queue->lock);
396 res = queue->qlen;
397 spin_unlock_bh(&queue->lock);
398 return (res == 0);
399}
400EXPORT_SYMBOL_GPL(rpc_queue_empty);
401
402/*
388 * Wake up a task on a specific queue 403 * Wake up a task on a specific queue
389 */ 404 */
390void rpc_wake_up_queued_task(struct rpc_wait_queue *queue, struct rpc_task *task) 405void rpc_wake_up_queued_task(struct rpc_wait_queue *queue, struct rpc_task *task)
diff --git a/net/sunrpc/socklib.c b/net/sunrpc/socklib.c
index a661a3acb37e..10b4319ebbca 100644
--- a/net/sunrpc/socklib.c
+++ b/net/sunrpc/socklib.c
@@ -8,6 +8,7 @@
8 8
9#include <linux/compiler.h> 9#include <linux/compiler.h>
10#include <linux/netdevice.h> 10#include <linux/netdevice.h>
11#include <linux/gfp.h>
11#include <linux/skbuff.h> 12#include <linux/skbuff.h>
12#include <linux/types.h> 13#include <linux/types.h>
13#include <linux/pagemap.h> 14#include <linux/pagemap.h>
diff --git a/net/sunrpc/stats.c b/net/sunrpc/stats.c
index 1b4e6791ecf3..5785d2037f45 100644
--- a/net/sunrpc/stats.c
+++ b/net/sunrpc/stats.c
@@ -13,6 +13,7 @@
13 */ 13 */
14 14
15#include <linux/module.h> 15#include <linux/module.h>
16#include <linux/slab.h>
16 17
17#include <linux/init.h> 18#include <linux/init.h>
18#include <linux/kernel.h> 19#include <linux/kernel.h>
diff --git a/net/sunrpc/sunrpc_syms.c b/net/sunrpc/sunrpc_syms.c
index 8cce92189019..f438347d817b 100644
--- a/net/sunrpc/sunrpc_syms.c
+++ b/net/sunrpc/sunrpc_syms.c
@@ -24,6 +24,8 @@
24 24
25extern struct cache_detail ip_map_cache, unix_gid_cache; 25extern struct cache_detail ip_map_cache, unix_gid_cache;
26 26
27extern void cleanup_rpcb_clnt(void);
28
27static int __init 29static int __init
28init_sunrpc(void) 30init_sunrpc(void)
29{ 31{
@@ -53,6 +55,7 @@ out:
53static void __exit 55static void __exit
54cleanup_sunrpc(void) 56cleanup_sunrpc(void)
55{ 57{
58 cleanup_rpcb_clnt();
56 rpcauth_remove_module(); 59 rpcauth_remove_module();
57 cleanup_socket_xprt(); 60 cleanup_socket_xprt();
58 svc_cleanup_xprt_sock(); 61 svc_cleanup_xprt_sock();
diff --git a/net/sunrpc/svc.c b/net/sunrpc/svc.c
index 952f206ff307..d9017d64597e 100644
--- a/net/sunrpc/svc.c
+++ b/net/sunrpc/svc.c
@@ -19,6 +19,7 @@
19#include <linux/interrupt.h> 19#include <linux/interrupt.h>
20#include <linux/module.h> 20#include <linux/module.h>
21#include <linux/kthread.h> 21#include <linux/kthread.h>
22#include <linux/slab.h>
22 23
23#include <linux/sunrpc/types.h> 24#include <linux/sunrpc/types.h>
24#include <linux/sunrpc/xdr.h> 25#include <linux/sunrpc/xdr.h>
@@ -133,7 +134,7 @@ svc_pool_map_choose_mode(void)
133 return SVC_POOL_PERNODE; 134 return SVC_POOL_PERNODE;
134 } 135 }
135 136
136 node = any_online_node(node_online_map); 137 node = first_online_node;
137 if (nr_cpus_node(node) > 2) { 138 if (nr_cpus_node(node) > 2) {
138 /* 139 /*
139 * Non-trivial SMP, or CONFIG_NUMA on 140 * Non-trivial SMP, or CONFIG_NUMA on
@@ -506,6 +507,10 @@ svc_init_buffer(struct svc_rqst *rqstp, unsigned int size)
506{ 507{
507 unsigned int pages, arghi; 508 unsigned int pages, arghi;
508 509
510 /* bc_xprt uses fore channel allocated buffers */
511 if (svc_is_backchannel(rqstp))
512 return 1;
513
509 pages = size / PAGE_SIZE + 1; /* extra page as we hold both request and reply. 514 pages = size / PAGE_SIZE + 1; /* extra page as we hold both request and reply.
510 * We assume one is at most one page 515 * We assume one is at most one page
511 */ 516 */
@@ -1103,8 +1108,9 @@ svc_process_common(struct svc_rqst *rqstp, struct kvec *argv, struct kvec *resv)
1103 procp->pc_release(rqstp, NULL, rqstp->rq_resp); 1108 procp->pc_release(rqstp, NULL, rqstp->rq_resp);
1104 goto dropit; 1109 goto dropit;
1105 } 1110 }
1106 if (*statp == rpc_success && (xdr = procp->pc_encode) 1111 if (*statp == rpc_success &&
1107 && !xdr(rqstp, resv->iov_base+resv->iov_len, rqstp->rq_resp)) { 1112 (xdr = procp->pc_encode) &&
1113 !xdr(rqstp, resv->iov_base+resv->iov_len, rqstp->rq_resp)) {
1108 dprintk("svc: failed to encode reply\n"); 1114 dprintk("svc: failed to encode reply\n");
1109 /* serv->sv_stats->rpcsystemerr++; */ 1115 /* serv->sv_stats->rpcsystemerr++; */
1110 *statp = rpc_system_err; 1116 *statp = rpc_system_err;
diff --git a/net/sunrpc/svc_xprt.c b/net/sunrpc/svc_xprt.c
index df124f78ee48..061b2e0f9118 100644
--- a/net/sunrpc/svc_xprt.c
+++ b/net/sunrpc/svc_xprt.c
@@ -9,6 +9,7 @@
9#include <linux/errno.h> 9#include <linux/errno.h>
10#include <linux/freezer.h> 10#include <linux/freezer.h>
11#include <linux/kthread.h> 11#include <linux/kthread.h>
12#include <linux/slab.h>
12#include <net/sock.h> 13#include <net/sock.h>
13#include <linux/sunrpc/stats.h> 14#include <linux/sunrpc/stats.h>
14#include <linux/sunrpc/svc_xprt.h> 15#include <linux/sunrpc/svc_xprt.h>
@@ -16,8 +17,6 @@
16 17
17#define RPCDBG_FACILITY RPCDBG_SVCXPRT 18#define RPCDBG_FACILITY RPCDBG_SVCXPRT
18 19
19#define SVC_MAX_WAKING 5
20
21static struct svc_deferred_req *svc_deferred_dequeue(struct svc_xprt *xprt); 20static struct svc_deferred_req *svc_deferred_dequeue(struct svc_xprt *xprt);
22static int svc_deferred_recv(struct svc_rqst *rqstp); 21static int svc_deferred_recv(struct svc_rqst *rqstp);
23static struct cache_deferred_req *svc_defer(struct cache_req *req); 22static struct cache_deferred_req *svc_defer(struct cache_req *req);
@@ -129,8 +128,8 @@ static void svc_xprt_free(struct kref *kref)
129 struct svc_xprt *xprt = 128 struct svc_xprt *xprt =
130 container_of(kref, struct svc_xprt, xpt_ref); 129 container_of(kref, struct svc_xprt, xpt_ref);
131 struct module *owner = xprt->xpt_class->xcl_owner; 130 struct module *owner = xprt->xpt_class->xcl_owner;
132 if (test_bit(XPT_CACHE_AUTH, &xprt->xpt_flags) 131 if (test_bit(XPT_CACHE_AUTH, &xprt->xpt_flags) &&
133 && xprt->xpt_auth_cache != NULL) 132 xprt->xpt_auth_cache != NULL)
134 svcauth_unix_info_release(xprt->xpt_auth_cache); 133 svcauth_unix_info_release(xprt->xpt_auth_cache);
135 xprt->xpt_ops->xpo_free(xprt); 134 xprt->xpt_ops->xpo_free(xprt);
136 module_put(owner); 135 module_put(owner);
@@ -175,11 +174,13 @@ static struct svc_xprt *__svc_xpo_create(struct svc_xprt_class *xcl,
175 .sin_addr.s_addr = htonl(INADDR_ANY), 174 .sin_addr.s_addr = htonl(INADDR_ANY),
176 .sin_port = htons(port), 175 .sin_port = htons(port),
177 }; 176 };
177#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
178 struct sockaddr_in6 sin6 = { 178 struct sockaddr_in6 sin6 = {
179 .sin6_family = AF_INET6, 179 .sin6_family = AF_INET6,
180 .sin6_addr = IN6ADDR_ANY_INIT, 180 .sin6_addr = IN6ADDR_ANY_INIT,
181 .sin6_port = htons(port), 181 .sin6_port = htons(port),
182 }; 182 };
183#endif /* defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) */
183 struct sockaddr *sap; 184 struct sockaddr *sap;
184 size_t len; 185 size_t len;
185 186
@@ -188,10 +189,12 @@ static struct svc_xprt *__svc_xpo_create(struct svc_xprt_class *xcl,
188 sap = (struct sockaddr *)&sin; 189 sap = (struct sockaddr *)&sin;
189 len = sizeof(sin); 190 len = sizeof(sin);
190 break; 191 break;
192#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
191 case PF_INET6: 193 case PF_INET6:
192 sap = (struct sockaddr *)&sin6; 194 sap = (struct sockaddr *)&sin6;
193 len = sizeof(sin6); 195 len = sizeof(sin6);
194 break; 196 break;
197#endif /* defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) */
195 default: 198 default:
196 return ERR_PTR(-EAFNOSUPPORT); 199 return ERR_PTR(-EAFNOSUPPORT);
197 } 200 }
@@ -233,7 +236,10 @@ int svc_create_xprt(struct svc_serv *serv, const char *xprt_name,
233 err: 236 err:
234 spin_unlock(&svc_xprt_class_lock); 237 spin_unlock(&svc_xprt_class_lock);
235 dprintk("svc: transport %s not found\n", xprt_name); 238 dprintk("svc: transport %s not found\n", xprt_name);
236 return -ENOENT; 239
240 /* This errno is exposed to user space. Provide a reasonable
241 * perror msg for a bad transport. */
242 return -EPROTONOSUPPORT;
237} 243}
238EXPORT_SYMBOL_GPL(svc_create_xprt); 244EXPORT_SYMBOL_GPL(svc_create_xprt);
239 245
@@ -306,7 +312,6 @@ void svc_xprt_enqueue(struct svc_xprt *xprt)
306 struct svc_pool *pool; 312 struct svc_pool *pool;
307 struct svc_rqst *rqstp; 313 struct svc_rqst *rqstp;
308 int cpu; 314 int cpu;
309 int thread_avail;
310 315
311 if (!(xprt->xpt_flags & 316 if (!(xprt->xpt_flags &
312 ((1<<XPT_CONN)|(1<<XPT_DATA)|(1<<XPT_CLOSE)|(1<<XPT_DEFERRED)))) 317 ((1<<XPT_CONN)|(1<<XPT_DATA)|(1<<XPT_CLOSE)|(1<<XPT_DEFERRED))))
@@ -318,6 +323,12 @@ void svc_xprt_enqueue(struct svc_xprt *xprt)
318 323
319 spin_lock_bh(&pool->sp_lock); 324 spin_lock_bh(&pool->sp_lock);
320 325
326 if (!list_empty(&pool->sp_threads) &&
327 !list_empty(&pool->sp_sockets))
328 printk(KERN_ERR
329 "svc_xprt_enqueue: "
330 "threads and transports both waiting??\n");
331
321 if (test_bit(XPT_DEAD, &xprt->xpt_flags)) { 332 if (test_bit(XPT_DEAD, &xprt->xpt_flags)) {
322 /* Don't enqueue dead transports */ 333 /* Don't enqueue dead transports */
323 dprintk("svc: transport %p is dead, not enqueued\n", xprt); 334 dprintk("svc: transport %p is dead, not enqueued\n", xprt);
@@ -358,15 +369,7 @@ void svc_xprt_enqueue(struct svc_xprt *xprt)
358 } 369 }
359 370
360 process: 371 process:
361 /* Work out whether threads are available */ 372 if (!list_empty(&pool->sp_threads)) {
362 thread_avail = !list_empty(&pool->sp_threads); /* threads are asleep */
363 if (pool->sp_nwaking >= SVC_MAX_WAKING) {
364 /* too many threads are runnable and trying to wake up */
365 thread_avail = 0;
366 pool->sp_stats.overloads_avoided++;
367 }
368
369 if (thread_avail) {
370 rqstp = list_entry(pool->sp_threads.next, 373 rqstp = list_entry(pool->sp_threads.next,
371 struct svc_rqst, 374 struct svc_rqst,
372 rq_list); 375 rq_list);
@@ -381,8 +384,6 @@ void svc_xprt_enqueue(struct svc_xprt *xprt)
381 svc_xprt_get(xprt); 384 svc_xprt_get(xprt);
382 rqstp->rq_reserved = serv->sv_max_mesg; 385 rqstp->rq_reserved = serv->sv_max_mesg;
383 atomic_add(rqstp->rq_reserved, &xprt->xpt_reserved); 386 atomic_add(rqstp->rq_reserved, &xprt->xpt_reserved);
384 rqstp->rq_waking = 1;
385 pool->sp_nwaking++;
386 pool->sp_stats.threads_woken++; 387 pool->sp_stats.threads_woken++;
387 BUG_ON(xprt->xpt_pool != pool); 388 BUG_ON(xprt->xpt_pool != pool);
388 wake_up(&rqstp->rq_wait); 389 wake_up(&rqstp->rq_wait);
@@ -651,11 +652,6 @@ int svc_recv(struct svc_rqst *rqstp, long timeout)
651 return -EINTR; 652 return -EINTR;
652 653
653 spin_lock_bh(&pool->sp_lock); 654 spin_lock_bh(&pool->sp_lock);
654 if (rqstp->rq_waking) {
655 rqstp->rq_waking = 0;
656 pool->sp_nwaking--;
657 BUG_ON(pool->sp_nwaking < 0);
658 }
659 xprt = svc_xprt_dequeue(pool); 655 xprt = svc_xprt_dequeue(pool);
660 if (xprt) { 656 if (xprt) {
661 rqstp->rq_xprt = xprt; 657 rqstp->rq_xprt = xprt;
@@ -711,7 +707,10 @@ int svc_recv(struct svc_rqst *rqstp, long timeout)
711 spin_unlock_bh(&pool->sp_lock); 707 spin_unlock_bh(&pool->sp_lock);
712 708
713 len = 0; 709 len = 0;
714 if (test_bit(XPT_LISTENER, &xprt->xpt_flags)) { 710 if (test_bit(XPT_CLOSE, &xprt->xpt_flags)) {
711 dprintk("svc_recv: found XPT_CLOSE\n");
712 svc_delete_xprt(xprt);
713 } else if (test_bit(XPT_LISTENER, &xprt->xpt_flags)) {
715 struct svc_xprt *newxpt; 714 struct svc_xprt *newxpt;
716 newxpt = xprt->xpt_ops->xpo_accept(xprt); 715 newxpt = xprt->xpt_ops->xpo_accept(xprt);
717 if (newxpt) { 716 if (newxpt) {
@@ -737,7 +736,7 @@ int svc_recv(struct svc_rqst *rqstp, long timeout)
737 svc_xprt_received(newxpt); 736 svc_xprt_received(newxpt);
738 } 737 }
739 svc_xprt_received(xprt); 738 svc_xprt_received(xprt);
740 } else if (!test_bit(XPT_CLOSE, &xprt->xpt_flags)) { 739 } else {
741 dprintk("svc: server %p, pool %u, transport %p, inuse=%d\n", 740 dprintk("svc: server %p, pool %u, transport %p, inuse=%d\n",
742 rqstp, pool->sp_id, xprt, 741 rqstp, pool->sp_id, xprt,
743 atomic_read(&xprt->xpt_ref.refcount)); 742 atomic_read(&xprt->xpt_ref.refcount));
@@ -750,11 +749,6 @@ int svc_recv(struct svc_rqst *rqstp, long timeout)
750 dprintk("svc: got len=%d\n", len); 749 dprintk("svc: got len=%d\n", len);
751 } 750 }
752 751
753 if (test_bit(XPT_CLOSE, &xprt->xpt_flags)) {
754 dprintk("svc_recv: found XPT_CLOSE\n");
755 svc_delete_xprt(xprt);
756 }
757
758 /* No data, incomplete (TCP) read, or accept() */ 752 /* No data, incomplete (TCP) read, or accept() */
759 if (len == 0 || len == -EAGAIN) { 753 if (len == 0 || len == -EAGAIN) {
760 rqstp->rq_res.len = 0; 754 rqstp->rq_res.len = 0;
@@ -846,8 +840,8 @@ static void svc_age_temp_xprts(unsigned long closure)
846 * through, close it. */ 840 * through, close it. */
847 if (!test_and_set_bit(XPT_OLD, &xprt->xpt_flags)) 841 if (!test_and_set_bit(XPT_OLD, &xprt->xpt_flags))
848 continue; 842 continue;
849 if (atomic_read(&xprt->xpt_ref.refcount) > 1 843 if (atomic_read(&xprt->xpt_ref.refcount) > 1 ||
850 || test_bit(XPT_BUSY, &xprt->xpt_flags)) 844 test_bit(XPT_BUSY, &xprt->xpt_flags))
851 continue; 845 continue;
852 svc_xprt_get(xprt); 846 svc_xprt_get(xprt);
853 list_move(le, &to_be_aged); 847 list_move(le, &to_be_aged);
@@ -900,11 +894,8 @@ void svc_delete_xprt(struct svc_xprt *xprt)
900 if (test_bit(XPT_TEMP, &xprt->xpt_flags)) 894 if (test_bit(XPT_TEMP, &xprt->xpt_flags))
901 serv->sv_tmpcnt--; 895 serv->sv_tmpcnt--;
902 896
903 for (dr = svc_deferred_dequeue(xprt); dr; 897 while ((dr = svc_deferred_dequeue(xprt)) != NULL)
904 dr = svc_deferred_dequeue(xprt)) {
905 svc_xprt_put(xprt);
906 kfree(dr); 898 kfree(dr);
907 }
908 899
909 svc_xprt_put(xprt); 900 svc_xprt_put(xprt);
910 spin_unlock_bh(&serv->sv_lock); 901 spin_unlock_bh(&serv->sv_lock);
@@ -1204,16 +1195,15 @@ static int svc_pool_stats_show(struct seq_file *m, void *p)
1204 struct svc_pool *pool = p; 1195 struct svc_pool *pool = p;
1205 1196
1206 if (p == SEQ_START_TOKEN) { 1197 if (p == SEQ_START_TOKEN) {
1207 seq_puts(m, "# pool packets-arrived sockets-enqueued threads-woken overloads-avoided threads-timedout\n"); 1198 seq_puts(m, "# pool packets-arrived sockets-enqueued threads-woken threads-timedout\n");
1208 return 0; 1199 return 0;
1209 } 1200 }
1210 1201
1211 seq_printf(m, "%u %lu %lu %lu %lu %lu\n", 1202 seq_printf(m, "%u %lu %lu %lu %lu\n",
1212 pool->sp_id, 1203 pool->sp_id,
1213 pool->sp_stats.packets, 1204 pool->sp_stats.packets,
1214 pool->sp_stats.sockets_queued, 1205 pool->sp_stats.sockets_queued,
1215 pool->sp_stats.threads_woken, 1206 pool->sp_stats.threads_woken,
1216 pool->sp_stats.overloads_avoided,
1217 pool->sp_stats.threads_timedout); 1207 pool->sp_stats.threads_timedout);
1218 1208
1219 return 0; 1209 return 0;
diff --git a/net/sunrpc/svcauth.c b/net/sunrpc/svcauth.c
index e64109b02aee..4e9393c24687 100644
--- a/net/sunrpc/svcauth.c
+++ b/net/sunrpc/svcauth.c
@@ -46,8 +46,8 @@ svc_authenticate(struct svc_rqst *rqstp, __be32 *authp)
46 dprintk("svc: svc_authenticate (%d)\n", flavor); 46 dprintk("svc: svc_authenticate (%d)\n", flavor);
47 47
48 spin_lock(&authtab_lock); 48 spin_lock(&authtab_lock);
49 if (flavor >= RPC_AUTH_MAXFLAVOR || !(aops = authtab[flavor]) 49 if (flavor >= RPC_AUTH_MAXFLAVOR || !(aops = authtab[flavor]) ||
50 || !try_module_get(aops->owner)) { 50 !try_module_get(aops->owner)) {
51 spin_unlock(&authtab_lock); 51 spin_unlock(&authtab_lock);
52 *authp = rpc_autherr_badcred; 52 *authp = rpc_autherr_badcred;
53 return SVC_DENIED; 53 return SVC_DENIED;
diff --git a/net/sunrpc/svcauth_unix.c b/net/sunrpc/svcauth_unix.c
index 117f68a8aa40..207311610988 100644
--- a/net/sunrpc/svcauth_unix.c
+++ b/net/sunrpc/svcauth_unix.c
@@ -10,11 +10,13 @@
10#include <linux/seq_file.h> 10#include <linux/seq_file.h>
11#include <linux/hash.h> 11#include <linux/hash.h>
12#include <linux/string.h> 12#include <linux/string.h>
13#include <linux/slab.h>
13#include <net/sock.h> 14#include <net/sock.h>
14#include <net/ipv6.h> 15#include <net/ipv6.h>
15#include <linux/kernel.h> 16#include <linux/kernel.h>
16#define RPCDBG_FACILITY RPCDBG_AUTH 17#define RPCDBG_FACILITY RPCDBG_AUTH
17 18
19#include <linux/sunrpc/clnt.h>
18 20
19/* 21/*
20 * AUTHUNIX and AUTHNULL credentials are both handled here. 22 * AUTHUNIX and AUTHNULL credentials are both handled here.
@@ -125,8 +127,8 @@ static int ip_map_match(struct cache_head *corig, struct cache_head *cnew)
125{ 127{
126 struct ip_map *orig = container_of(corig, struct ip_map, h); 128 struct ip_map *orig = container_of(corig, struct ip_map, h);
127 struct ip_map *new = container_of(cnew, struct ip_map, h); 129 struct ip_map *new = container_of(cnew, struct ip_map, h);
128 return strcmp(orig->m_class, new->m_class) == 0 130 return strcmp(orig->m_class, new->m_class) == 0 &&
129 && ipv6_addr_equal(&orig->m_addr, &new->m_addr); 131 ipv6_addr_equal(&orig->m_addr, &new->m_addr);
130} 132}
131static void ip_map_init(struct cache_head *cnew, struct cache_head *citem) 133static void ip_map_init(struct cache_head *cnew, struct cache_head *citem)
132{ 134{
@@ -187,10 +189,13 @@ static int ip_map_parse(struct cache_detail *cd,
187 * for scratch: */ 189 * for scratch: */
188 char *buf = mesg; 190 char *buf = mesg;
189 int len; 191 int len;
190 int b1, b2, b3, b4, b5, b6, b7, b8;
191 char c;
192 char class[8]; 192 char class[8];
193 struct in6_addr addr; 193 union {
194 struct sockaddr sa;
195 struct sockaddr_in s4;
196 struct sockaddr_in6 s6;
197 } address;
198 struct sockaddr_in6 sin6;
194 int err; 199 int err;
195 200
196 struct ip_map *ipmp; 201 struct ip_map *ipmp;
@@ -209,24 +214,24 @@ static int ip_map_parse(struct cache_detail *cd,
209 len = qword_get(&mesg, buf, mlen); 214 len = qword_get(&mesg, buf, mlen);
210 if (len <= 0) return -EINVAL; 215 if (len <= 0) return -EINVAL;
211 216
212 if (sscanf(buf, "%u.%u.%u.%u%c", &b1, &b2, &b3, &b4, &c) == 4) { 217 if (rpc_pton(buf, len, &address.sa, sizeof(address)) == 0)
213 addr.s6_addr32[0] = 0; 218 return -EINVAL;
214 addr.s6_addr32[1] = 0; 219 switch (address.sa.sa_family) {
215 addr.s6_addr32[2] = htonl(0xffff); 220 case AF_INET:
216 addr.s6_addr32[3] = 221 /* Form a mapped IPv4 address in sin6 */
217 htonl((((((b1<<8)|b2)<<8)|b3)<<8)|b4); 222 memset(&sin6, 0, sizeof(sin6));
218 } else if (sscanf(buf, "%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x%c", 223 sin6.sin6_family = AF_INET6;
219 &b1, &b2, &b3, &b4, &b5, &b6, &b7, &b8, &c) == 8) { 224 sin6.sin6_addr.s6_addr32[2] = htonl(0xffff);
220 addr.s6_addr16[0] = htons(b1); 225 sin6.sin6_addr.s6_addr32[3] = address.s4.sin_addr.s_addr;
221 addr.s6_addr16[1] = htons(b2); 226 break;
222 addr.s6_addr16[2] = htons(b3); 227#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
223 addr.s6_addr16[3] = htons(b4); 228 case AF_INET6:
224 addr.s6_addr16[4] = htons(b5); 229 memcpy(&sin6, &address.s6, sizeof(sin6));
225 addr.s6_addr16[5] = htons(b6); 230 break;
226 addr.s6_addr16[6] = htons(b7); 231#endif
227 addr.s6_addr16[7] = htons(b8); 232 default:
228 } else
229 return -EINVAL; 233 return -EINVAL;
234 }
230 235
231 expiry = get_expiry(&mesg); 236 expiry = get_expiry(&mesg);
232 if (expiry ==0) 237 if (expiry ==0)
@@ -243,7 +248,8 @@ static int ip_map_parse(struct cache_detail *cd,
243 } else 248 } else
244 dom = NULL; 249 dom = NULL;
245 250
246 ipmp = ip_map_lookup(class, &addr); 251 /* IPv6 scope IDs are ignored for now */
252 ipmp = ip_map_lookup(class, &sin6.sin6_addr);
247 if (ipmp) { 253 if (ipmp) {
248 err = ip_map_update(ipmp, 254 err = ip_map_update(ipmp,
249 container_of(dom, struct unix_domain, h), 255 container_of(dom, struct unix_domain, h),
@@ -619,7 +625,7 @@ static int unix_gid_show(struct seq_file *m,
619 else 625 else
620 glen = 0; 626 glen = 0;
621 627
622 seq_printf(m, "%d %d:", ug->uid, glen); 628 seq_printf(m, "%u %d:", ug->uid, glen);
623 for (i = 0; i < glen; i++) 629 for (i = 0; i < glen; i++)
624 seq_printf(m, " %d", GROUP_AT(ug->gi, i)); 630 seq_printf(m, " %d", GROUP_AT(ug->gi, i));
625 seq_printf(m, "\n"); 631 seq_printf(m, "\n");
@@ -655,23 +661,25 @@ static struct unix_gid *unix_gid_lookup(uid_t uid)
655 return NULL; 661 return NULL;
656} 662}
657 663
658static int unix_gid_find(uid_t uid, struct group_info **gip, 664static struct group_info *unix_gid_find(uid_t uid, struct svc_rqst *rqstp)
659 struct svc_rqst *rqstp)
660{ 665{
661 struct unix_gid *ug = unix_gid_lookup(uid); 666 struct unix_gid *ug;
667 struct group_info *gi;
668 int ret;
669
670 ug = unix_gid_lookup(uid);
662 if (!ug) 671 if (!ug)
663 return -EAGAIN; 672 return ERR_PTR(-EAGAIN);
664 switch (cache_check(&unix_gid_cache, &ug->h, &rqstp->rq_chandle)) { 673 ret = cache_check(&unix_gid_cache, &ug->h, &rqstp->rq_chandle);
674 switch (ret) {
665 case -ENOENT: 675 case -ENOENT:
666 *gip = NULL; 676 return ERR_PTR(-ENOENT);
667 return 0;
668 case 0: 677 case 0:
669 *gip = ug->gi; 678 gi = get_group_info(ug->gi);
670 get_group_info(*gip);
671 cache_put(&ug->h, &unix_gid_cache); 679 cache_put(&ug->h, &unix_gid_cache);
672 return 0; 680 return gi;
673 default: 681 default:
674 return -EAGAIN; 682 return ERR_PTR(-EAGAIN);
675 } 683 }
676} 684}
677 685
@@ -681,13 +689,14 @@ svcauth_unix_set_client(struct svc_rqst *rqstp)
681 struct sockaddr_in *sin; 689 struct sockaddr_in *sin;
682 struct sockaddr_in6 *sin6, sin6_storage; 690 struct sockaddr_in6 *sin6, sin6_storage;
683 struct ip_map *ipm; 691 struct ip_map *ipm;
692 struct group_info *gi;
693 struct svc_cred *cred = &rqstp->rq_cred;
684 694
685 switch (rqstp->rq_addr.ss_family) { 695 switch (rqstp->rq_addr.ss_family) {
686 case AF_INET: 696 case AF_INET:
687 sin = svc_addr_in(rqstp); 697 sin = svc_addr_in(rqstp);
688 sin6 = &sin6_storage; 698 sin6 = &sin6_storage;
689 ipv6_addr_set(&sin6->sin6_addr, 0, 0, 699 ipv6_addr_set_v4mapped(sin->sin_addr.s_addr, &sin6->sin6_addr);
690 htonl(0x0000FFFF), sin->sin_addr.s_addr);
691 break; 700 break;
692 case AF_INET6: 701 case AF_INET6:
693 sin6 = svc_addr_in6(rqstp); 702 sin6 = svc_addr_in6(rqstp);
@@ -722,6 +731,17 @@ svcauth_unix_set_client(struct svc_rqst *rqstp)
722 ip_map_cached_put(rqstp, ipm); 731 ip_map_cached_put(rqstp, ipm);
723 break; 732 break;
724 } 733 }
734
735 gi = unix_gid_find(cred->cr_uid, rqstp);
736 switch (PTR_ERR(gi)) {
737 case -EAGAIN:
738 return SVC_DROP;
739 case -ENOENT:
740 break;
741 default:
742 put_group_info(cred->cr_group_info);
743 cred->cr_group_info = gi;
744 }
725 return SVC_OK; 745 return SVC_OK;
726} 746}
727 747
@@ -818,19 +838,11 @@ svcauth_unix_accept(struct svc_rqst *rqstp, __be32 *authp)
818 slen = svc_getnl(argv); /* gids length */ 838 slen = svc_getnl(argv); /* gids length */
819 if (slen > 16 || (len -= (slen + 2)*4) < 0) 839 if (slen > 16 || (len -= (slen + 2)*4) < 0)
820 goto badcred; 840 goto badcred;
821 if (unix_gid_find(cred->cr_uid, &cred->cr_group_info, rqstp) 841 cred->cr_group_info = groups_alloc(slen);
822 == -EAGAIN) 842 if (cred->cr_group_info == NULL)
823 return SVC_DROP; 843 return SVC_DROP;
824 if (cred->cr_group_info == NULL) { 844 for (i = 0; i < slen; i++)
825 cred->cr_group_info = groups_alloc(slen); 845 GROUP_AT(cred->cr_group_info, i) = svc_getnl(argv);
826 if (cred->cr_group_info == NULL)
827 return SVC_DROP;
828 for (i = 0; i < slen; i++)
829 GROUP_AT(cred->cr_group_info, i) = svc_getnl(argv);
830 } else {
831 for (i = 0; i < slen ; i++)
832 svc_getnl(argv);
833 }
834 if (svc_getu32(argv) != htonl(RPC_AUTH_NULL) || svc_getu32(argv) != 0) { 846 if (svc_getu32(argv) != htonl(RPC_AUTH_NULL) || svc_getu32(argv) != 0) {
835 *authp = rpc_autherr_badverf; 847 *authp = rpc_autherr_badverf;
836 return SVC_DENIED; 848 return SVC_DENIED;
diff --git a/net/sunrpc/svcsock.c b/net/sunrpc/svcsock.c
index 1c246a4f491e..a29f259204e6 100644
--- a/net/sunrpc/svcsock.c
+++ b/net/sunrpc/svcsock.c
@@ -272,14 +272,14 @@ static int svc_one_sock_name(struct svc_sock *svsk, char *buf, int remaining)
272 case PF_INET: 272 case PF_INET:
273 len = snprintf(buf, remaining, "ipv4 %s %pI4 %d\n", 273 len = snprintf(buf, remaining, "ipv4 %s %pI4 %d\n",
274 proto_name, 274 proto_name,
275 &inet_sk(sk)->rcv_saddr, 275 &inet_sk(sk)->inet_rcv_saddr,
276 inet_sk(sk)->num); 276 inet_sk(sk)->inet_num);
277 break; 277 break;
278 case PF_INET6: 278 case PF_INET6:
279 len = snprintf(buf, remaining, "ipv6 %s %pI6 %d\n", 279 len = snprintf(buf, remaining, "ipv6 %s %pI6 %d\n",
280 proto_name, 280 proto_name,
281 &inet6_sk(sk)->rcv_saddr, 281 &inet6_sk(sk)->rcv_saddr,
282 inet_sk(sk)->num); 282 inet_sk(sk)->inet_num);
283 break; 283 break;
284 default: 284 default:
285 len = snprintf(buf, remaining, "*unknown-%d*\n", 285 len = snprintf(buf, remaining, "*unknown-%d*\n",
@@ -968,6 +968,7 @@ static int svc_tcp_recv_record(struct svc_sock *svsk, struct svc_rqst *rqstp)
968 return len; 968 return len;
969 err_delete: 969 err_delete:
970 set_bit(XPT_CLOSE, &svsk->sk_xprt.xpt_flags); 970 set_bit(XPT_CLOSE, &svsk->sk_xprt.xpt_flags);
971 svc_xprt_received(&svsk->sk_xprt);
971 err_again: 972 err_again:
972 return -EAGAIN; 973 return -EAGAIN;
973} 974}
@@ -1311,7 +1312,7 @@ static struct svc_sock *svc_setup_socket(struct svc_serv *serv,
1311 /* Register socket with portmapper */ 1312 /* Register socket with portmapper */
1312 if (*errp >= 0 && pmap_register) 1313 if (*errp >= 0 && pmap_register)
1313 *errp = svc_register(serv, inet->sk_family, inet->sk_protocol, 1314 *errp = svc_register(serv, inet->sk_family, inet->sk_protocol,
1314 ntohs(inet_sk(inet)->sport)); 1315 ntohs(inet_sk(inet)->inet_sport));
1315 1316
1316 if (*errp < 0) { 1317 if (*errp < 0) {
1317 kfree(svsk); 1318 kfree(svsk);
@@ -1357,7 +1358,7 @@ int svc_addsock(struct svc_serv *serv, const int fd, char *name_return,
1357 1358
1358 if (!so) 1359 if (!so)
1359 return err; 1360 return err;
1360 if (so->sk->sk_family != AF_INET) 1361 if ((so->sk->sk_family != PF_INET) && (so->sk->sk_family != PF_INET6))
1361 err = -EAFNOSUPPORT; 1362 err = -EAFNOSUPPORT;
1362 else if (so->sk->sk_protocol != IPPROTO_TCP && 1363 else if (so->sk->sk_protocol != IPPROTO_TCP &&
1363 so->sk->sk_protocol != IPPROTO_UDP) 1364 so->sk->sk_protocol != IPPROTO_UDP)
diff --git a/net/sunrpc/sysctl.c b/net/sunrpc/sysctl.c
index 42f9748ae093..e65dcc613339 100644
--- a/net/sunrpc/sysctl.c
+++ b/net/sunrpc/sysctl.c
@@ -139,46 +139,45 @@ static ctl_table debug_table[] = {
139 .data = &rpc_debug, 139 .data = &rpc_debug,
140 .maxlen = sizeof(int), 140 .maxlen = sizeof(int),
141 .mode = 0644, 141 .mode = 0644,
142 .proc_handler = &proc_dodebug 142 .proc_handler = proc_dodebug
143 }, 143 },
144 { 144 {
145 .procname = "nfs_debug", 145 .procname = "nfs_debug",
146 .data = &nfs_debug, 146 .data = &nfs_debug,
147 .maxlen = sizeof(int), 147 .maxlen = sizeof(int),
148 .mode = 0644, 148 .mode = 0644,
149 .proc_handler = &proc_dodebug 149 .proc_handler = proc_dodebug
150 }, 150 },
151 { 151 {
152 .procname = "nfsd_debug", 152 .procname = "nfsd_debug",
153 .data = &nfsd_debug, 153 .data = &nfsd_debug,
154 .maxlen = sizeof(int), 154 .maxlen = sizeof(int),
155 .mode = 0644, 155 .mode = 0644,
156 .proc_handler = &proc_dodebug 156 .proc_handler = proc_dodebug
157 }, 157 },
158 { 158 {
159 .procname = "nlm_debug", 159 .procname = "nlm_debug",
160 .data = &nlm_debug, 160 .data = &nlm_debug,
161 .maxlen = sizeof(int), 161 .maxlen = sizeof(int),
162 .mode = 0644, 162 .mode = 0644,
163 .proc_handler = &proc_dodebug 163 .proc_handler = proc_dodebug
164 }, 164 },
165 { 165 {
166 .procname = "transports", 166 .procname = "transports",
167 .maxlen = 256, 167 .maxlen = 256,
168 .mode = 0444, 168 .mode = 0444,
169 .proc_handler = &proc_do_xprt, 169 .proc_handler = proc_do_xprt,
170 }, 170 },
171 { .ctl_name = 0 } 171 { }
172}; 172};
173 173
174static ctl_table sunrpc_table[] = { 174static ctl_table sunrpc_table[] = {
175 { 175 {
176 .ctl_name = CTL_SUNRPC,
177 .procname = "sunrpc", 176 .procname = "sunrpc",
178 .mode = 0555, 177 .mode = 0555,
179 .child = debug_table 178 .child = debug_table
180 }, 179 },
181 { .ctl_name = 0 } 180 { }
182}; 181};
183 182
184#endif 183#endif
diff --git a/net/sunrpc/xdr.c b/net/sunrpc/xdr.c
index 8bd690c48b69..2763fde88499 100644
--- a/net/sunrpc/xdr.c
+++ b/net/sunrpc/xdr.c
@@ -7,6 +7,7 @@
7 */ 7 */
8 8
9#include <linux/module.h> 9#include <linux/module.h>
10#include <linux/slab.h>
10#include <linux/types.h> 11#include <linux/types.h>
11#include <linux/string.h> 12#include <linux/string.h>
12#include <linux/kernel.h> 13#include <linux/kernel.h>
diff --git a/net/sunrpc/xprt.c b/net/sunrpc/xprt.c
index fd46d42afa89..42f09ade0044 100644
--- a/net/sunrpc/xprt.c
+++ b/net/sunrpc/xprt.c
@@ -46,6 +46,7 @@
46 46
47#include <linux/sunrpc/clnt.h> 47#include <linux/sunrpc/clnt.h>
48#include <linux/sunrpc/metrics.h> 48#include <linux/sunrpc/metrics.h>
49#include <linux/sunrpc/bc_xprt.h>
49 50
50#include "sunrpc.h" 51#include "sunrpc.h"
51 52
@@ -700,6 +701,10 @@ void xprt_connect(struct rpc_task *task)
700 } 701 }
701 if (!xprt_lock_write(xprt, task)) 702 if (!xprt_lock_write(xprt, task))
702 return; 703 return;
704
705 if (test_and_clear_bit(XPRT_CLOSE_WAIT, &xprt->state))
706 xprt->ops->close(xprt);
707
703 if (xprt_connected(xprt)) 708 if (xprt_connected(xprt))
704 xprt_release_write(xprt, task); 709 xprt_release_write(xprt, task);
705 else { 710 else {
@@ -1028,21 +1033,16 @@ void xprt_release(struct rpc_task *task)
1028 if (req->rq_release_snd_buf) 1033 if (req->rq_release_snd_buf)
1029 req->rq_release_snd_buf(req); 1034 req->rq_release_snd_buf(req);
1030 1035
1031 /*
1032 * Early exit if this is a backchannel preallocated request.
1033 * There is no need to have it added to the RPC slot list.
1034 */
1035 if (is_bc_request)
1036 return;
1037
1038 memset(req, 0, sizeof(*req)); /* mark unused */
1039
1040 dprintk("RPC: %5u release request %p\n", task->tk_pid, req); 1036 dprintk("RPC: %5u release request %p\n", task->tk_pid, req);
1037 if (likely(!is_bc_request)) {
1038 memset(req, 0, sizeof(*req)); /* mark unused */
1041 1039
1042 spin_lock(&xprt->reserve_lock); 1040 spin_lock(&xprt->reserve_lock);
1043 list_add(&req->rq_list, &xprt->free); 1041 list_add(&req->rq_list, &xprt->free);
1044 rpc_wake_up_next(&xprt->backlog); 1042 rpc_wake_up_next(&xprt->backlog);
1045 spin_unlock(&xprt->reserve_lock); 1043 spin_unlock(&xprt->reserve_lock);
1044 } else
1045 xprt_free_bc_request(req);
1046} 1046}
1047 1047
1048/** 1048/**
diff --git a/net/sunrpc/xprtrdma/svc_rdma.c b/net/sunrpc/xprtrdma/svc_rdma.c
index 35fb68b9c8ec..d718b8fa9525 100644
--- a/net/sunrpc/xprtrdma/svc_rdma.c
+++ b/net/sunrpc/xprtrdma/svc_rdma.c
@@ -40,6 +40,7 @@
40 */ 40 */
41#include <linux/module.h> 41#include <linux/module.h>
42#include <linux/init.h> 42#include <linux/init.h>
43#include <linux/slab.h>
43#include <linux/fs.h> 44#include <linux/fs.h>
44#include <linux/sysctl.h> 45#include <linux/sysctl.h>
45#include <linux/sunrpc/clnt.h> 46#include <linux/sunrpc/clnt.h>
@@ -120,8 +121,7 @@ static ctl_table svcrdma_parm_table[] = {
120 .data = &svcrdma_max_requests, 121 .data = &svcrdma_max_requests,
121 .maxlen = sizeof(unsigned int), 122 .maxlen = sizeof(unsigned int),
122 .mode = 0644, 123 .mode = 0644,
123 .proc_handler = &proc_dointvec_minmax, 124 .proc_handler = proc_dointvec_minmax,
124 .strategy = &sysctl_intvec,
125 .extra1 = &min_max_requests, 125 .extra1 = &min_max_requests,
126 .extra2 = &max_max_requests 126 .extra2 = &max_max_requests
127 }, 127 },
@@ -130,8 +130,7 @@ static ctl_table svcrdma_parm_table[] = {
130 .data = &svcrdma_max_req_size, 130 .data = &svcrdma_max_req_size,
131 .maxlen = sizeof(unsigned int), 131 .maxlen = sizeof(unsigned int),
132 .mode = 0644, 132 .mode = 0644,
133 .proc_handler = &proc_dointvec_minmax, 133 .proc_handler = proc_dointvec_minmax,
134 .strategy = &sysctl_intvec,
135 .extra1 = &min_max_inline, 134 .extra1 = &min_max_inline,
136 .extra2 = &max_max_inline 135 .extra2 = &max_max_inline
137 }, 136 },
@@ -140,8 +139,7 @@ static ctl_table svcrdma_parm_table[] = {
140 .data = &svcrdma_ord, 139 .data = &svcrdma_ord,
141 .maxlen = sizeof(unsigned int), 140 .maxlen = sizeof(unsigned int),
142 .mode = 0644, 141 .mode = 0644,
143 .proc_handler = &proc_dointvec_minmax, 142 .proc_handler = proc_dointvec_minmax,
144 .strategy = &sysctl_intvec,
145 .extra1 = &min_ord, 143 .extra1 = &min_ord,
146 .extra2 = &max_ord, 144 .extra2 = &max_ord,
147 }, 145 },
@@ -151,67 +149,65 @@ static ctl_table svcrdma_parm_table[] = {
151 .data = &rdma_stat_read, 149 .data = &rdma_stat_read,
152 .maxlen = sizeof(atomic_t), 150 .maxlen = sizeof(atomic_t),
153 .mode = 0644, 151 .mode = 0644,
154 .proc_handler = &read_reset_stat, 152 .proc_handler = read_reset_stat,
155 }, 153 },
156 { 154 {
157 .procname = "rdma_stat_recv", 155 .procname = "rdma_stat_recv",
158 .data = &rdma_stat_recv, 156 .data = &rdma_stat_recv,
159 .maxlen = sizeof(atomic_t), 157 .maxlen = sizeof(atomic_t),
160 .mode = 0644, 158 .mode = 0644,
161 .proc_handler = &read_reset_stat, 159 .proc_handler = read_reset_stat,
162 }, 160 },
163 { 161 {
164 .procname = "rdma_stat_write", 162 .procname = "rdma_stat_write",
165 .data = &rdma_stat_write, 163 .data = &rdma_stat_write,
166 .maxlen = sizeof(atomic_t), 164 .maxlen = sizeof(atomic_t),
167 .mode = 0644, 165 .mode = 0644,
168 .proc_handler = &read_reset_stat, 166 .proc_handler = read_reset_stat,
169 }, 167 },
170 { 168 {
171 .procname = "rdma_stat_sq_starve", 169 .procname = "rdma_stat_sq_starve",
172 .data = &rdma_stat_sq_starve, 170 .data = &rdma_stat_sq_starve,
173 .maxlen = sizeof(atomic_t), 171 .maxlen = sizeof(atomic_t),
174 .mode = 0644, 172 .mode = 0644,
175 .proc_handler = &read_reset_stat, 173 .proc_handler = read_reset_stat,
176 }, 174 },
177 { 175 {
178 .procname = "rdma_stat_rq_starve", 176 .procname = "rdma_stat_rq_starve",
179 .data = &rdma_stat_rq_starve, 177 .data = &rdma_stat_rq_starve,
180 .maxlen = sizeof(atomic_t), 178 .maxlen = sizeof(atomic_t),
181 .mode = 0644, 179 .mode = 0644,
182 .proc_handler = &read_reset_stat, 180 .proc_handler = read_reset_stat,
183 }, 181 },
184 { 182 {
185 .procname = "rdma_stat_rq_poll", 183 .procname = "rdma_stat_rq_poll",
186 .data = &rdma_stat_rq_poll, 184 .data = &rdma_stat_rq_poll,
187 .maxlen = sizeof(atomic_t), 185 .maxlen = sizeof(atomic_t),
188 .mode = 0644, 186 .mode = 0644,
189 .proc_handler = &read_reset_stat, 187 .proc_handler = read_reset_stat,
190 }, 188 },
191 { 189 {
192 .procname = "rdma_stat_rq_prod", 190 .procname = "rdma_stat_rq_prod",
193 .data = &rdma_stat_rq_prod, 191 .data = &rdma_stat_rq_prod,
194 .maxlen = sizeof(atomic_t), 192 .maxlen = sizeof(atomic_t),
195 .mode = 0644, 193 .mode = 0644,
196 .proc_handler = &read_reset_stat, 194 .proc_handler = read_reset_stat,
197 }, 195 },
198 { 196 {
199 .procname = "rdma_stat_sq_poll", 197 .procname = "rdma_stat_sq_poll",
200 .data = &rdma_stat_sq_poll, 198 .data = &rdma_stat_sq_poll,
201 .maxlen = sizeof(atomic_t), 199 .maxlen = sizeof(atomic_t),
202 .mode = 0644, 200 .mode = 0644,
203 .proc_handler = &read_reset_stat, 201 .proc_handler = read_reset_stat,
204 }, 202 },
205 { 203 {
206 .procname = "rdma_stat_sq_prod", 204 .procname = "rdma_stat_sq_prod",
207 .data = &rdma_stat_sq_prod, 205 .data = &rdma_stat_sq_prod,
208 .maxlen = sizeof(atomic_t), 206 .maxlen = sizeof(atomic_t),
209 .mode = 0644, 207 .mode = 0644,
210 .proc_handler = &read_reset_stat, 208 .proc_handler = read_reset_stat,
211 },
212 {
213 .ctl_name = 0,
214 }, 209 },
210 { },
215}; 211};
216 212
217static ctl_table svcrdma_table[] = { 213static ctl_table svcrdma_table[] = {
@@ -220,21 +216,16 @@ static ctl_table svcrdma_table[] = {
220 .mode = 0555, 216 .mode = 0555,
221 .child = svcrdma_parm_table 217 .child = svcrdma_parm_table
222 }, 218 },
223 { 219 { },
224 .ctl_name = 0,
225 },
226}; 220};
227 221
228static ctl_table svcrdma_root_table[] = { 222static ctl_table svcrdma_root_table[] = {
229 { 223 {
230 .ctl_name = CTL_SUNRPC,
231 .procname = "sunrpc", 224 .procname = "sunrpc",
232 .mode = 0555, 225 .mode = 0555,
233 .child = svcrdma_table 226 .child = svcrdma_table
234 }, 227 },
235 { 228 { },
236 .ctl_name = 0,
237 },
238}; 229};
239 230
240void svc_rdma_cleanup(void) 231void svc_rdma_cleanup(void)
diff --git a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
index 9e884383134f..f92e37eb413c 100644
--- a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
+++ b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
@@ -337,10 +337,9 @@ static int rdma_set_ctxt_sge(struct svcxprt_rdma *xprt,
337 337
338static int rdma_read_max_sge(struct svcxprt_rdma *xprt, int sge_count) 338static int rdma_read_max_sge(struct svcxprt_rdma *xprt, int sge_count)
339{ 339{
340 if ((RDMA_TRANSPORT_IWARP == 340 if ((rdma_node_get_transport(xprt->sc_cm_id->device->node_type) ==
341 rdma_node_get_transport(xprt->sc_cm_id-> 341 RDMA_TRANSPORT_IWARP) &&
342 device->node_type)) 342 sge_count > 1)
343 && sge_count > 1)
344 return 1; 343 return 1;
345 else 344 else
346 return min_t(int, sge_count, xprt->sc_max_sge); 345 return min_t(int, sge_count, xprt->sc_max_sge);
diff --git a/net/sunrpc/xprtrdma/svc_rdma_sendto.c b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
index f11be72a1a80..b15e1ebb2bfa 100644
--- a/net/sunrpc/xprtrdma/svc_rdma_sendto.c
+++ b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
@@ -54,7 +54,7 @@
54 * Assumptions: 54 * Assumptions:
55 * - head[0] is physically contiguous. 55 * - head[0] is physically contiguous.
56 * - tail[0] is physically contiguous. 56 * - tail[0] is physically contiguous.
57 * - pages[] is not physically or virtually contigous and consists of 57 * - pages[] is not physically or virtually contiguous and consists of
58 * PAGE_SIZE elements. 58 * PAGE_SIZE elements.
59 * 59 *
60 * Output: 60 * Output:
diff --git a/net/sunrpc/xprtrdma/svc_rdma_transport.c b/net/sunrpc/xprtrdma/svc_rdma_transport.c
index 3fa5751af0ec..edea15a54e51 100644
--- a/net/sunrpc/xprtrdma/svc_rdma_transport.c
+++ b/net/sunrpc/xprtrdma/svc_rdma_transport.c
@@ -43,6 +43,7 @@
43#include <linux/sunrpc/debug.h> 43#include <linux/sunrpc/debug.h>
44#include <linux/sunrpc/rpc_rdma.h> 44#include <linux/sunrpc/rpc_rdma.h>
45#include <linux/sched.h> 45#include <linux/sched.h>
46#include <linux/slab.h>
46#include <linux/spinlock.h> 47#include <linux/spinlock.h>
47#include <rdma/ib_verbs.h> 48#include <rdma/ib_verbs.h>
48#include <rdma/rdma_cm.h> 49#include <rdma/rdma_cm.h>
@@ -678,7 +679,10 @@ static struct svc_xprt *svc_rdma_create(struct svc_serv *serv,
678 int ret; 679 int ret;
679 680
680 dprintk("svcrdma: Creating RDMA socket\n"); 681 dprintk("svcrdma: Creating RDMA socket\n");
681 682 if (sa->sa_family != AF_INET) {
683 dprintk("svcrdma: Address family %d is not supported.\n", sa->sa_family);
684 return ERR_PTR(-EAFNOSUPPORT);
685 }
682 cma_xprt = rdma_create_xprt(serv, 1); 686 cma_xprt = rdma_create_xprt(serv, 1);
683 if (!cma_xprt) 687 if (!cma_xprt)
684 return ERR_PTR(-ENOMEM); 688 return ERR_PTR(-ENOMEM);
diff --git a/net/sunrpc/xprtrdma/transport.c b/net/sunrpc/xprtrdma/transport.c
index 9a63f669ece4..187257b1d880 100644
--- a/net/sunrpc/xprtrdma/transport.c
+++ b/net/sunrpc/xprtrdma/transport.c
@@ -49,6 +49,7 @@
49 49
50#include <linux/module.h> 50#include <linux/module.h>
51#include <linux/init.h> 51#include <linux/init.h>
52#include <linux/slab.h>
52#include <linux/seq_file.h> 53#include <linux/seq_file.h>
53 54
54#include "xprt_rdma.h" 55#include "xprt_rdma.h"
@@ -86,79 +87,63 @@ static struct ctl_table_header *sunrpc_table_header;
86 87
87static ctl_table xr_tunables_table[] = { 88static ctl_table xr_tunables_table[] = {
88 { 89 {
89 .ctl_name = CTL_UNNUMBERED,
90 .procname = "rdma_slot_table_entries", 90 .procname = "rdma_slot_table_entries",
91 .data = &xprt_rdma_slot_table_entries, 91 .data = &xprt_rdma_slot_table_entries,
92 .maxlen = sizeof(unsigned int), 92 .maxlen = sizeof(unsigned int),
93 .mode = 0644, 93 .mode = 0644,
94 .proc_handler = &proc_dointvec_minmax, 94 .proc_handler = proc_dointvec_minmax,
95 .strategy = &sysctl_intvec,
96 .extra1 = &min_slot_table_size, 95 .extra1 = &min_slot_table_size,
97 .extra2 = &max_slot_table_size 96 .extra2 = &max_slot_table_size
98 }, 97 },
99 { 98 {
100 .ctl_name = CTL_UNNUMBERED,
101 .procname = "rdma_max_inline_read", 99 .procname = "rdma_max_inline_read",
102 .data = &xprt_rdma_max_inline_read, 100 .data = &xprt_rdma_max_inline_read,
103 .maxlen = sizeof(unsigned int), 101 .maxlen = sizeof(unsigned int),
104 .mode = 0644, 102 .mode = 0644,
105 .proc_handler = &proc_dointvec, 103 .proc_handler = proc_dointvec,
106 .strategy = &sysctl_intvec,
107 }, 104 },
108 { 105 {
109 .ctl_name = CTL_UNNUMBERED,
110 .procname = "rdma_max_inline_write", 106 .procname = "rdma_max_inline_write",
111 .data = &xprt_rdma_max_inline_write, 107 .data = &xprt_rdma_max_inline_write,
112 .maxlen = sizeof(unsigned int), 108 .maxlen = sizeof(unsigned int),
113 .mode = 0644, 109 .mode = 0644,
114 .proc_handler = &proc_dointvec, 110 .proc_handler = proc_dointvec,
115 .strategy = &sysctl_intvec,
116 }, 111 },
117 { 112 {
118 .ctl_name = CTL_UNNUMBERED,
119 .procname = "rdma_inline_write_padding", 113 .procname = "rdma_inline_write_padding",
120 .data = &xprt_rdma_inline_write_padding, 114 .data = &xprt_rdma_inline_write_padding,
121 .maxlen = sizeof(unsigned int), 115 .maxlen = sizeof(unsigned int),
122 .mode = 0644, 116 .mode = 0644,
123 .proc_handler = &proc_dointvec_minmax, 117 .proc_handler = proc_dointvec_minmax,
124 .strategy = &sysctl_intvec,
125 .extra1 = &zero, 118 .extra1 = &zero,
126 .extra2 = &max_padding, 119 .extra2 = &max_padding,
127 }, 120 },
128 { 121 {
129 .ctl_name = CTL_UNNUMBERED,
130 .procname = "rdma_memreg_strategy", 122 .procname = "rdma_memreg_strategy",
131 .data = &xprt_rdma_memreg_strategy, 123 .data = &xprt_rdma_memreg_strategy,
132 .maxlen = sizeof(unsigned int), 124 .maxlen = sizeof(unsigned int),
133 .mode = 0644, 125 .mode = 0644,
134 .proc_handler = &proc_dointvec_minmax, 126 .proc_handler = proc_dointvec_minmax,
135 .strategy = &sysctl_intvec,
136 .extra1 = &min_memreg, 127 .extra1 = &min_memreg,
137 .extra2 = &max_memreg, 128 .extra2 = &max_memreg,
138 }, 129 },
139 { 130 {
140 .ctl_name = CTL_UNNUMBERED,
141 .procname = "rdma_pad_optimize", 131 .procname = "rdma_pad_optimize",
142 .data = &xprt_rdma_pad_optimize, 132 .data = &xprt_rdma_pad_optimize,
143 .maxlen = sizeof(unsigned int), 133 .maxlen = sizeof(unsigned int),
144 .mode = 0644, 134 .mode = 0644,
145 .proc_handler = &proc_dointvec, 135 .proc_handler = proc_dointvec,
146 },
147 {
148 .ctl_name = 0,
149 }, 136 },
137 { },
150}; 138};
151 139
152static ctl_table sunrpc_table[] = { 140static ctl_table sunrpc_table[] = {
153 { 141 {
154 .ctl_name = CTL_SUNRPC,
155 .procname = "sunrpc", 142 .procname = "sunrpc",
156 .mode = 0555, 143 .mode = 0555,
157 .child = xr_tunables_table 144 .child = xr_tunables_table
158 }, 145 },
159 { 146 { },
160 .ctl_name = 0,
161 },
162}; 147};
163 148
164#endif 149#endif
@@ -176,16 +161,15 @@ xprt_rdma_format_addresses(struct rpc_xprt *xprt)
176 (void)rpc_ntop(sap, buf, sizeof(buf)); 161 (void)rpc_ntop(sap, buf, sizeof(buf));
177 xprt->address_strings[RPC_DISPLAY_ADDR] = kstrdup(buf, GFP_KERNEL); 162 xprt->address_strings[RPC_DISPLAY_ADDR] = kstrdup(buf, GFP_KERNEL);
178 163
179 (void)snprintf(buf, sizeof(buf), "%u", rpc_get_port(sap)); 164 snprintf(buf, sizeof(buf), "%u", rpc_get_port(sap));
180 xprt->address_strings[RPC_DISPLAY_PORT] = kstrdup(buf, GFP_KERNEL); 165 xprt->address_strings[RPC_DISPLAY_PORT] = kstrdup(buf, GFP_KERNEL);
181 166
182 xprt->address_strings[RPC_DISPLAY_PROTO] = "rdma"; 167 xprt->address_strings[RPC_DISPLAY_PROTO] = "rdma";
183 168
184 (void)snprintf(buf, sizeof(buf), "%02x%02x%02x%02x", 169 snprintf(buf, sizeof(buf), "%08x", ntohl(sin->sin_addr.s_addr));
185 NIPQUAD(sin->sin_addr.s_addr));
186 xprt->address_strings[RPC_DISPLAY_HEX_ADDR] = kstrdup(buf, GFP_KERNEL); 170 xprt->address_strings[RPC_DISPLAY_HEX_ADDR] = kstrdup(buf, GFP_KERNEL);
187 171
188 (void)snprintf(buf, sizeof(buf), "%4hx", rpc_get_port(sap)); 172 snprintf(buf, sizeof(buf), "%4hx", rpc_get_port(sap));
189 xprt->address_strings[RPC_DISPLAY_HEX_PORT] = kstrdup(buf, GFP_KERNEL); 173 xprt->address_strings[RPC_DISPLAY_HEX_PORT] = kstrdup(buf, GFP_KERNEL);
190 174
191 /* netid */ 175 /* netid */
diff --git a/net/sunrpc/xprtrdma/verbs.c b/net/sunrpc/xprtrdma/verbs.c
index 465aafc2007f..27015c6d8eb5 100644
--- a/net/sunrpc/xprtrdma/verbs.c
+++ b/net/sunrpc/xprtrdma/verbs.c
@@ -48,6 +48,7 @@
48 */ 48 */
49 49
50#include <linux/pci.h> /* for Tavor hack below */ 50#include <linux/pci.h> /* for Tavor hack below */
51#include <linux/slab.h>
51 52
52#include "xprt_rdma.h" 53#include "xprt_rdma.h"
53 54
@@ -878,8 +879,8 @@ if (strnicmp(ia->ri_id->device->dma_device->bus->name, "pci", 3) == 0) {
878 * others indicate a transport condition which has already 879 * others indicate a transport condition which has already
879 * undergone a best-effort. 880 * undergone a best-effort.
880 */ 881 */
881 if (ep->rep_connected == -ECONNREFUSED 882 if (ep->rep_connected == -ECONNREFUSED &&
882 && ++retry_count <= RDMA_CONNECT_RETRY_MAX) { 883 ++retry_count <= RDMA_CONNECT_RETRY_MAX) {
883 dprintk("RPC: %s: non-peer_reject, retry\n", __func__); 884 dprintk("RPC: %s: non-peer_reject, retry\n", __func__);
884 goto retry; 885 goto retry;
885 } 886 }
diff --git a/net/sunrpc/xprtsock.c b/net/sunrpc/xprtsock.c
index 37c5475ba258..9847c30b5001 100644
--- a/net/sunrpc/xprtsock.c
+++ b/net/sunrpc/xprtsock.c
@@ -81,46 +81,38 @@ static struct ctl_table_header *sunrpc_table_header;
81 */ 81 */
82static ctl_table xs_tunables_table[] = { 82static ctl_table xs_tunables_table[] = {
83 { 83 {
84 .ctl_name = CTL_SLOTTABLE_UDP,
85 .procname = "udp_slot_table_entries", 84 .procname = "udp_slot_table_entries",
86 .data = &xprt_udp_slot_table_entries, 85 .data = &xprt_udp_slot_table_entries,
87 .maxlen = sizeof(unsigned int), 86 .maxlen = sizeof(unsigned int),
88 .mode = 0644, 87 .mode = 0644,
89 .proc_handler = &proc_dointvec_minmax, 88 .proc_handler = proc_dointvec_minmax,
90 .strategy = &sysctl_intvec,
91 .extra1 = &min_slot_table_size, 89 .extra1 = &min_slot_table_size,
92 .extra2 = &max_slot_table_size 90 .extra2 = &max_slot_table_size
93 }, 91 },
94 { 92 {
95 .ctl_name = CTL_SLOTTABLE_TCP,
96 .procname = "tcp_slot_table_entries", 93 .procname = "tcp_slot_table_entries",
97 .data = &xprt_tcp_slot_table_entries, 94 .data = &xprt_tcp_slot_table_entries,
98 .maxlen = sizeof(unsigned int), 95 .maxlen = sizeof(unsigned int),
99 .mode = 0644, 96 .mode = 0644,
100 .proc_handler = &proc_dointvec_minmax, 97 .proc_handler = proc_dointvec_minmax,
101 .strategy = &sysctl_intvec,
102 .extra1 = &min_slot_table_size, 98 .extra1 = &min_slot_table_size,
103 .extra2 = &max_slot_table_size 99 .extra2 = &max_slot_table_size
104 }, 100 },
105 { 101 {
106 .ctl_name = CTL_MIN_RESVPORT,
107 .procname = "min_resvport", 102 .procname = "min_resvport",
108 .data = &xprt_min_resvport, 103 .data = &xprt_min_resvport,
109 .maxlen = sizeof(unsigned int), 104 .maxlen = sizeof(unsigned int),
110 .mode = 0644, 105 .mode = 0644,
111 .proc_handler = &proc_dointvec_minmax, 106 .proc_handler = proc_dointvec_minmax,
112 .strategy = &sysctl_intvec,
113 .extra1 = &xprt_min_resvport_limit, 107 .extra1 = &xprt_min_resvport_limit,
114 .extra2 = &xprt_max_resvport_limit 108 .extra2 = &xprt_max_resvport_limit
115 }, 109 },
116 { 110 {
117 .ctl_name = CTL_MAX_RESVPORT,
118 .procname = "max_resvport", 111 .procname = "max_resvport",
119 .data = &xprt_max_resvport, 112 .data = &xprt_max_resvport,
120 .maxlen = sizeof(unsigned int), 113 .maxlen = sizeof(unsigned int),
121 .mode = 0644, 114 .mode = 0644,
122 .proc_handler = &proc_dointvec_minmax, 115 .proc_handler = proc_dointvec_minmax,
123 .strategy = &sysctl_intvec,
124 .extra1 = &xprt_min_resvport_limit, 116 .extra1 = &xprt_min_resvport_limit,
125 .extra2 = &xprt_max_resvport_limit 117 .extra2 = &xprt_max_resvport_limit
126 }, 118 },
@@ -129,24 +121,18 @@ static ctl_table xs_tunables_table[] = {
129 .data = &xs_tcp_fin_timeout, 121 .data = &xs_tcp_fin_timeout,
130 .maxlen = sizeof(xs_tcp_fin_timeout), 122 .maxlen = sizeof(xs_tcp_fin_timeout),
131 .mode = 0644, 123 .mode = 0644,
132 .proc_handler = &proc_dointvec_jiffies, 124 .proc_handler = proc_dointvec_jiffies,
133 .strategy = sysctl_jiffies
134 },
135 {
136 .ctl_name = 0,
137 }, 125 },
126 { },
138}; 127};
139 128
140static ctl_table sunrpc_table[] = { 129static ctl_table sunrpc_table[] = {
141 { 130 {
142 .ctl_name = CTL_SUNRPC,
143 .procname = "sunrpc", 131 .procname = "sunrpc",
144 .mode = 0555, 132 .mode = 0555,
145 .child = xs_tunables_table 133 .child = xs_tunables_table
146 }, 134 },
147 { 135 { },
148 .ctl_name = 0,
149 },
150}; 136};
151 137
152#endif 138#endif
@@ -311,12 +297,11 @@ static void xs_format_common_peer_addresses(struct rpc_xprt *xprt)
311 switch (sap->sa_family) { 297 switch (sap->sa_family) {
312 case AF_INET: 298 case AF_INET:
313 sin = xs_addr_in(xprt); 299 sin = xs_addr_in(xprt);
314 (void)snprintf(buf, sizeof(buf), "%02x%02x%02x%02x", 300 snprintf(buf, sizeof(buf), "%08x", ntohl(sin->sin_addr.s_addr));
315 NIPQUAD(sin->sin_addr.s_addr));
316 break; 301 break;
317 case AF_INET6: 302 case AF_INET6:
318 sin6 = xs_addr_in6(xprt); 303 sin6 = xs_addr_in6(xprt);
319 (void)snprintf(buf, sizeof(buf), "%pi6", &sin6->sin6_addr); 304 snprintf(buf, sizeof(buf), "%pi6", &sin6->sin6_addr);
320 break; 305 break;
321 default: 306 default:
322 BUG(); 307 BUG();
@@ -329,10 +314,10 @@ static void xs_format_common_peer_ports(struct rpc_xprt *xprt)
329 struct sockaddr *sap = xs_addr(xprt); 314 struct sockaddr *sap = xs_addr(xprt);
330 char buf[128]; 315 char buf[128];
331 316
332 (void)snprintf(buf, sizeof(buf), "%u", rpc_get_port(sap)); 317 snprintf(buf, sizeof(buf), "%u", rpc_get_port(sap));
333 xprt->address_strings[RPC_DISPLAY_PORT] = kstrdup(buf, GFP_KERNEL); 318 xprt->address_strings[RPC_DISPLAY_PORT] = kstrdup(buf, GFP_KERNEL);
334 319
335 (void)snprintf(buf, sizeof(buf), "%4hx", rpc_get_port(sap)); 320 snprintf(buf, sizeof(buf), "%4hx", rpc_get_port(sap));
336 xprt->address_strings[RPC_DISPLAY_HEX_PORT] = kstrdup(buf, GFP_KERNEL); 321 xprt->address_strings[RPC_DISPLAY_HEX_PORT] = kstrdup(buf, GFP_KERNEL);
337} 322}
338 323
@@ -563,8 +548,6 @@ static int xs_udp_send_request(struct rpc_task *task)
563 /* Still some bytes left; set up for a retry later. */ 548 /* Still some bytes left; set up for a retry later. */
564 status = -EAGAIN; 549 status = -EAGAIN;
565 } 550 }
566 if (!transport->sock)
567 goto out;
568 551
569 switch (status) { 552 switch (status) {
570 case -ENOTSOCK: 553 case -ENOTSOCK:
@@ -584,7 +567,7 @@ static int xs_udp_send_request(struct rpc_task *task)
584 * prompts ECONNREFUSED. */ 567 * prompts ECONNREFUSED. */
585 clear_bit(SOCK_ASYNC_NOSPACE, &transport->sock->flags); 568 clear_bit(SOCK_ASYNC_NOSPACE, &transport->sock->flags);
586 } 569 }
587out: 570
588 return status; 571 return status;
589} 572}
590 573
@@ -666,8 +649,6 @@ static int xs_tcp_send_request(struct rpc_task *task)
666 status = -EAGAIN; 649 status = -EAGAIN;
667 break; 650 break;
668 } 651 }
669 if (!transport->sock)
670 goto out;
671 652
672 switch (status) { 653 switch (status) {
673 case -ENOTSOCK: 654 case -ENOTSOCK:
@@ -687,7 +668,7 @@ static int xs_tcp_send_request(struct rpc_task *task)
687 case -ENOTCONN: 668 case -ENOTCONN:
688 clear_bit(SOCK_ASYNC_NOSPACE, &transport->sock->flags); 669 clear_bit(SOCK_ASYNC_NOSPACE, &transport->sock->flags);
689 } 670 }
690out: 671
691 return status; 672 return status;
692} 673}
693 674
@@ -1926,6 +1907,11 @@ static void xs_tcp_setup_socket(struct rpc_xprt *xprt,
1926 case -EALREADY: 1907 case -EALREADY:
1927 xprt_clear_connecting(xprt); 1908 xprt_clear_connecting(xprt);
1928 return; 1909 return;
1910 case -EINVAL:
1911 /* Happens, for instance, if the user specified a link
1912 * local IPv6 address without a scope-id.
1913 */
1914 goto out;
1929 } 1915 }
1930out_eagain: 1916out_eagain:
1931 status = -EAGAIN; 1917 status = -EAGAIN;
@@ -2033,7 +2019,7 @@ static void xs_connect(struct rpc_task *task)
2033 if (xprt_test_and_set_connecting(xprt)) 2019 if (xprt_test_and_set_connecting(xprt))
2034 return; 2020 return;
2035 2021
2036 if (transport->sock != NULL) { 2022 if (transport->sock != NULL && !RPC_IS_SOFTCONN(task)) {
2037 dprintk("RPC: xs_connect delayed xprt %p for %lu " 2023 dprintk("RPC: xs_connect delayed xprt %p for %lu "
2038 "seconds\n", 2024 "seconds\n",
2039 xprt, xprt->reestablish_timeout / HZ); 2025 xprt, xprt->reestablish_timeout / HZ);
@@ -2114,7 +2100,7 @@ static void xs_tcp_print_stats(struct rpc_xprt *xprt, struct seq_file *seq)
2114 * we allocate pages instead doing a kmalloc like rpc_malloc is because we want 2100 * we allocate pages instead doing a kmalloc like rpc_malloc is because we want
2115 * to use the server side send routines. 2101 * to use the server side send routines.
2116 */ 2102 */
2117void *bc_malloc(struct rpc_task *task, size_t size) 2103static void *bc_malloc(struct rpc_task *task, size_t size)
2118{ 2104{
2119 struct page *page; 2105 struct page *page;
2120 struct rpc_buffer *buf; 2106 struct rpc_buffer *buf;
@@ -2134,7 +2120,7 @@ void *bc_malloc(struct rpc_task *task, size_t size)
2134/* 2120/*
2135 * Free the space allocated in the bc_alloc routine 2121 * Free the space allocated in the bc_alloc routine
2136 */ 2122 */
2137void bc_free(void *buffer) 2123static void bc_free(void *buffer)
2138{ 2124{
2139 struct rpc_buffer *buf; 2125 struct rpc_buffer *buf;
2140 2126
@@ -2265,9 +2251,6 @@ static struct rpc_xprt_ops xs_tcp_ops = {
2265 .buf_free = rpc_free, 2251 .buf_free = rpc_free,
2266 .send_request = xs_tcp_send_request, 2252 .send_request = xs_tcp_send_request,
2267 .set_retrans_timeout = xprt_set_retrans_timeout_def, 2253 .set_retrans_timeout = xprt_set_retrans_timeout_def,
2268#if defined(CONFIG_NFS_V4_1)
2269 .release_request = bc_release_request,
2270#endif /* CONFIG_NFS_V4_1 */
2271 .close = xs_tcp_close, 2254 .close = xs_tcp_close,
2272 .destroy = xs_destroy, 2255 .destroy = xs_destroy,
2273 .print_stats = xs_tcp_print_stats, 2256 .print_stats = xs_tcp_print_stats,
diff --git a/net/sysctl_net.c b/net/sysctl_net.c
index 0b15d7250c40..53196009160a 100644
--- a/net/sysctl_net.c
+++ b/net/sysctl_net.c
@@ -71,7 +71,7 @@ static struct ctl_table_root net_sysctl_ro_root = {
71 .permissions = net_ctl_ro_header_perms, 71 .permissions = net_ctl_ro_header_perms,
72}; 72};
73 73
74static int sysctl_net_init(struct net *net) 74static int __net_init sysctl_net_init(struct net *net)
75{ 75{
76 setup_sysctl_set(&net->sysctls, 76 setup_sysctl_set(&net->sysctls,
77 &net_sysctl_ro_root.default_set, 77 &net_sysctl_ro_root.default_set,
@@ -79,7 +79,7 @@ static int sysctl_net_init(struct net *net)
79 return 0; 79 return 0;
80} 80}
81 81
82static void sysctl_net_exit(struct net *net) 82static void __net_exit sysctl_net_exit(struct net *net)
83{ 83{
84 WARN_ON(!list_empty(&net->sysctls.list)); 84 WARN_ON(!list_empty(&net->sysctls.list));
85 return; 85 return;
diff --git a/net/tipc/Kconfig b/net/tipc/Kconfig
index 3b30d1130b61..b74f78d0c033 100644
--- a/net/tipc/Kconfig
+++ b/net/tipc/Kconfig
@@ -10,7 +10,7 @@ menuconfig TIPC
10 specially designed for intra cluster communication. This protocol 10 specially designed for intra cluster communication. This protocol
11 originates from Ericsson where it has been used in carrier grade 11 originates from Ericsson where it has been used in carrier grade
12 cluster applications for many years. 12 cluster applications for many years.
13 13
14 For more information about TIPC, see http://tipc.sourceforge.net. 14 For more information about TIPC, see http://tipc.sourceforge.net.
15 15
16 This protocol support is also available as a module ( = code which 16 This protocol support is also available as a module ( = code which
@@ -23,91 +23,76 @@ menuconfig TIPC
23if TIPC 23if TIPC
24 24
25config TIPC_ADVANCED 25config TIPC_ADVANCED
26 bool "TIPC: Advanced configuration" 26 bool "Advanced TIPC configuration"
27 default n 27 default n
28 help 28 help
29 Saying Y here will open some advanced configuration 29 Saying Y here will open some advanced configuration for TIPC.
30 for TIPC. Most users do not need to bother, so if 30 Most users do not need to bother; if unsure, just say N.
31 unsure, just say N.
32 31
33config TIPC_ZONES 32config TIPC_ZONES
34 int "Maximum number of zones in network" 33 int "Maximum number of zones in a network"
35 depends on TIPC_ADVANCED 34 depends on TIPC_ADVANCED
35 range 1 255
36 default "3" 36 default "3"
37 help 37 help
38 Max number of zones inside TIPC network. Max supported value 38 Specifies how many zones can be supported in a TIPC network.
39 is 255 zones, minimum is 1 39 Can range from 1 to 255 zones; default is 3.
40 40
41 Default is 3 zones in a network; setting this to higher 41 Setting this to a smaller value saves some memory;
42 allows more zones but might use more memory. 42 setting it to a higher value allows for more zones.
43 43
44config TIPC_CLUSTERS 44config TIPC_CLUSTERS
45 int "Maximum number of clusters in a zone" 45 int "Maximum number of clusters in a zone"
46 depends on TIPC_ADVANCED 46 depends on TIPC_ADVANCED
47 range 1 1
47 default "1" 48 default "1"
48 help 49 help
49 ***Only 1 (one cluster in a zone) is supported by current code. 50 Specifies how many clusters can be supported in a TIPC zone.
50 Any value set here will be overridden.***
51
52 (Max number of clusters inside TIPC zone. Max supported
53 value is 4095 clusters, minimum is 1.
54 51
55 Default is 1; setting this to smaller value might save 52 *** Currently TIPC only supports a single cluster per zone. ***
56 some memory, setting it to higher
57 allows more clusters and might consume more memory.)
58 53
59config TIPC_NODES 54config TIPC_NODES
60 int "Maximum number of nodes in cluster" 55 int "Maximum number of nodes in a cluster"
61 depends on TIPC_ADVANCED 56 depends on TIPC_ADVANCED
57 range 8 2047
62 default "255" 58 default "255"
63 help 59 help
64 Maximum number of nodes inside a TIPC cluster. Maximum 60 Specifies how many nodes can be supported in a TIPC cluster.
65 supported value is 2047 nodes, minimum is 8. 61 Can range from 8 to 2047 nodes; default is 255.
66
67 Setting this to a smaller value saves some memory,
68 setting it to higher allows more nodes.
69
70config TIPC_SLAVE_NODES
71 int "Maximum number of slave nodes in cluster"
72 depends on TIPC_ADVANCED
73 default "0"
74 help
75 ***This capability is not supported by current code.***
76
77 Maximum number of slave nodes inside a TIPC cluster. Maximum
78 supported value is 2047 nodes, minimum is 0.
79 62
80 Setting this to a smaller value saves some memory, 63 Setting this to a smaller value saves some memory;
81 setting it to higher allows more nodes. 64 setting it to higher allows for more nodes.
82 65
83config TIPC_PORTS 66config TIPC_PORTS
84 int "Maximum number of ports in a node" 67 int "Maximum number of ports in a node"
85 depends on TIPC_ADVANCED 68 depends on TIPC_ADVANCED
69 range 127 65535
86 default "8191" 70 default "8191"
87 help 71 help
88 Maximum number of ports within a node. Maximum 72 Specifies how many ports can be supported by a node.
89 supported value is 64535 nodes, minimum is 127. 73 Can range from 127 to 65535 ports; default is 8191.
90 74
91 Setting this to a smaller value saves some memory, 75 Setting this to a smaller value saves some memory,
92 setting it to higher allows more ports. 76 setting it to higher allows for more ports.
93 77
94config TIPC_LOG 78config TIPC_LOG
95 int "Size of log buffer" 79 int "Size of log buffer"
96 depends on TIPC_ADVANCED 80 depends on TIPC_ADVANCED
97 default 0 81 range 0 32768
82 default "0"
98 help 83 help
99 Size (in bytes) of TIPC's internal log buffer, which records the 84 Size (in bytes) of TIPC's internal log buffer, which records the
100 occurrence of significant events. Maximum supported value 85 occurrence of significant events. Can range from 0 to 32768 bytes;
101 is 32768 bytes, minimum is 0. 86 default is 0.
102 87
103 There is no need to enable the log buffer unless the node will be 88 There is no need to enable the log buffer unless the node will be
104 managed remotely via TIPC. 89 managed remotely via TIPC.
105 90
106config TIPC_DEBUG 91config TIPC_DEBUG
107 bool "Enable debugging support" 92 bool "Enable debug messages"
108 default n 93 default n
109 help 94 help
110 This will enable debugging of TIPC. 95 This enables debugging of TIPC.
111 96
112 Only say Y here if you are having trouble with TIPC. It will 97 Only say Y here if you are having trouble with TIPC. It will
113 enable the display of detailed information about what is going on. 98 enable the display of detailed information about what is going on.
diff --git a/net/tipc/bearer.c b/net/tipc/bearer.c
index 327011fcc407..78091375ca12 100644
--- a/net/tipc/bearer.c
+++ b/net/tipc/bearer.c
@@ -45,10 +45,10 @@
45 45
46#define MAX_ADDR_STR 32 46#define MAX_ADDR_STR 32
47 47
48static struct media *media_list = NULL; 48static struct media media_list[MAX_MEDIA];
49static u32 media_count = 0; 49static u32 media_count = 0;
50 50
51struct bearer *tipc_bearers = NULL; 51struct bearer tipc_bearers[MAX_BEARERS];
52 52
53/** 53/**
54 * media_name_valid - validate media name 54 * media_name_valid - validate media name
@@ -108,9 +108,11 @@ int tipc_register_media(u32 media_type,
108 int res = -EINVAL; 108 int res = -EINVAL;
109 109
110 write_lock_bh(&tipc_net_lock); 110 write_lock_bh(&tipc_net_lock);
111 if (!media_list)
112 goto exit;
113 111
112 if (tipc_mode != TIPC_NET_MODE) {
113 warn("Media <%s> rejected, not in networked mode yet\n", name);
114 goto exit;
115 }
114 if (!media_name_valid(name)) { 116 if (!media_name_valid(name)) {
115 warn("Media <%s> rejected, illegal name\n", name); 117 warn("Media <%s> rejected, illegal name\n", name);
116 goto exit; 118 goto exit;
@@ -660,33 +662,10 @@ int tipc_disable_bearer(const char *name)
660 662
661 663
662 664
663int tipc_bearer_init(void)
664{
665 int res;
666
667 write_lock_bh(&tipc_net_lock);
668 tipc_bearers = kcalloc(MAX_BEARERS, sizeof(struct bearer), GFP_ATOMIC);
669 media_list = kcalloc(MAX_MEDIA, sizeof(struct media), GFP_ATOMIC);
670 if (tipc_bearers && media_list) {
671 res = 0;
672 } else {
673 kfree(tipc_bearers);
674 kfree(media_list);
675 tipc_bearers = NULL;
676 media_list = NULL;
677 res = -ENOMEM;
678 }
679 write_unlock_bh(&tipc_net_lock);
680 return res;
681}
682
683void tipc_bearer_stop(void) 665void tipc_bearer_stop(void)
684{ 666{
685 u32 i; 667 u32 i;
686 668
687 if (!tipc_bearers)
688 return;
689
690 for (i = 0; i < MAX_BEARERS; i++) { 669 for (i = 0; i < MAX_BEARERS; i++) {
691 if (tipc_bearers[i].active) 670 if (tipc_bearers[i].active)
692 tipc_bearers[i].publ.blocked = 1; 671 tipc_bearers[i].publ.blocked = 1;
@@ -695,10 +674,6 @@ void tipc_bearer_stop(void)
695 if (tipc_bearers[i].active) 674 if (tipc_bearers[i].active)
696 bearer_disable(tipc_bearers[i].publ.name); 675 bearer_disable(tipc_bearers[i].publ.name);
697 } 676 }
698 kfree(tipc_bearers);
699 kfree(media_list);
700 tipc_bearers = NULL;
701 media_list = NULL;
702 media_count = 0; 677 media_count = 0;
703} 678}
704 679
diff --git a/net/tipc/bearer.h b/net/tipc/bearer.h
index ca5734892713..000228e93f9e 100644
--- a/net/tipc/bearer.h
+++ b/net/tipc/bearer.h
@@ -114,7 +114,7 @@ struct bearer_name {
114 114
115struct link; 115struct link;
116 116
117extern struct bearer *tipc_bearers; 117extern struct bearer tipc_bearers[];
118 118
119void tipc_media_addr_printf(struct print_buf *pb, struct tipc_media_addr *a); 119void tipc_media_addr_printf(struct print_buf *pb, struct tipc_media_addr *a);
120struct sk_buff *tipc_media_get_names(void); 120struct sk_buff *tipc_media_get_names(void);
diff --git a/net/tipc/cluster.c b/net/tipc/cluster.c
index 689fdefe9d04..a7eac00cd363 100644
--- a/net/tipc/cluster.c
+++ b/net/tipc/cluster.c
@@ -437,11 +437,11 @@ void tipc_cltr_recv_routing_table(struct sk_buff *buf)
437 break; 437 break;
438 case ROUTE_ADDITION: 438 case ROUTE_ADDITION:
439 if (!is_slave(tipc_own_addr)) { 439 if (!is_slave(tipc_own_addr)) {
440 assert(!in_own_cluster(c_ptr->addr) 440 assert(!in_own_cluster(c_ptr->addr) ||
441 || is_slave(rem_node)); 441 is_slave(rem_node));
442 } else { 442 } else {
443 assert(in_own_cluster(c_ptr->addr) 443 assert(in_own_cluster(c_ptr->addr) &&
444 && !is_slave(rem_node)); 444 !is_slave(rem_node));
445 } 445 }
446 n_ptr = c_ptr->nodes[tipc_node(rem_node)]; 446 n_ptr = c_ptr->nodes[tipc_node(rem_node)];
447 if (!n_ptr) 447 if (!n_ptr)
@@ -451,11 +451,11 @@ void tipc_cltr_recv_routing_table(struct sk_buff *buf)
451 break; 451 break;
452 case ROUTE_REMOVAL: 452 case ROUTE_REMOVAL:
453 if (!is_slave(tipc_own_addr)) { 453 if (!is_slave(tipc_own_addr)) {
454 assert(!in_own_cluster(c_ptr->addr) 454 assert(!in_own_cluster(c_ptr->addr) ||
455 || is_slave(rem_node)); 455 is_slave(rem_node));
456 } else { 456 } else {
457 assert(in_own_cluster(c_ptr->addr) 457 assert(in_own_cluster(c_ptr->addr) &&
458 && !is_slave(rem_node)); 458 !is_slave(rem_node));
459 } 459 }
460 n_ptr = c_ptr->nodes[tipc_node(rem_node)]; 460 n_ptr = c_ptr->nodes[tipc_node(rem_node)];
461 if (n_ptr) 461 if (n_ptr)
diff --git a/net/tipc/core.c b/net/tipc/core.c
index 3256bd7d398f..52c571fedbe0 100644
--- a/net/tipc/core.c
+++ b/net/tipc/core.c
@@ -189,11 +189,11 @@ static int __init tipc_init(void)
189 tipc_remote_management = 1; 189 tipc_remote_management = 1;
190 tipc_max_publications = 10000; 190 tipc_max_publications = 10000;
191 tipc_max_subscriptions = 2000; 191 tipc_max_subscriptions = 2000;
192 tipc_max_ports = delimit(CONFIG_TIPC_PORTS, 127, 65536); 192 tipc_max_ports = CONFIG_TIPC_PORTS;
193 tipc_max_zones = delimit(CONFIG_TIPC_ZONES, 1, 255); 193 tipc_max_zones = CONFIG_TIPC_ZONES;
194 tipc_max_clusters = delimit(CONFIG_TIPC_CLUSTERS, 1, 1); 194 tipc_max_clusters = CONFIG_TIPC_CLUSTERS;
195 tipc_max_nodes = delimit(CONFIG_TIPC_NODES, 8, 2047); 195 tipc_max_nodes = CONFIG_TIPC_NODES;
196 tipc_max_slaves = delimit(CONFIG_TIPC_SLAVE_NODES, 0, 2047); 196 tipc_max_slaves = CONFIG_TIPC_SLAVE_NODES;
197 tipc_net_id = 4711; 197 tipc_net_id = 4711;
198 198
199 if ((res = tipc_core_start())) 199 if ((res = tipc_core_start()))
diff --git a/net/tipc/core.h b/net/tipc/core.h
index a881f92a8537..c58a1d16563a 100644
--- a/net/tipc/core.h
+++ b/net/tipc/core.h
@@ -56,6 +56,7 @@
56#include <linux/netdevice.h> 56#include <linux/netdevice.h>
57#include <linux/in.h> 57#include <linux/in.h>
58#include <linux/list.h> 58#include <linux/list.h>
59#include <linux/slab.h>
59#include <linux/vmalloc.h> 60#include <linux/vmalloc.h>
60 61
61/* 62/*
diff --git a/net/tipc/eth_media.c b/net/tipc/eth_media.c
index 524ba5696d4d..6230d16020c4 100644
--- a/net/tipc/eth_media.c
+++ b/net/tipc/eth_media.c
@@ -38,6 +38,7 @@
38#include <net/tipc/tipc_bearer.h> 38#include <net/tipc/tipc_bearer.h>
39#include <net/tipc/tipc_msg.h> 39#include <net/tipc/tipc_msg.h>
40#include <linux/netdevice.h> 40#include <linux/netdevice.h>
41#include <linux/slab.h>
41#include <net/net_namespace.h> 42#include <net/net_namespace.h>
42 43
43#define MAX_ETH_BEARERS 2 44#define MAX_ETH_BEARERS 2
diff --git a/net/tipc/link.c b/net/tipc/link.c
index dd4c18b9a35b..1a7e4665af80 100644
--- a/net/tipc/link.c
+++ b/net/tipc/link.c
@@ -378,8 +378,8 @@ static void link_timeout(struct link *l_ptr)
378 struct tipc_msg *msg = buf_msg(l_ptr->first_out); 378 struct tipc_msg *msg = buf_msg(l_ptr->first_out);
379 u32 length = msg_size(msg); 379 u32 length = msg_size(msg);
380 380
381 if ((msg_user(msg) == MSG_FRAGMENTER) 381 if ((msg_user(msg) == MSG_FRAGMENTER) &&
382 && (msg_type(msg) == FIRST_FRAGMENT)) { 382 (msg_type(msg) == FIRST_FRAGMENT)) {
383 length = msg_size(msg_get_wrapped(msg)); 383 length = msg_size(msg_get_wrapped(msg));
384 } 384 }
385 if (length) { 385 if (length) {
@@ -1882,6 +1882,15 @@ void tipc_recv_msg(struct sk_buff *head, struct tipc_bearer *tb_ptr)
1882 (msg_destnode(msg) != tipc_own_addr))) 1882 (msg_destnode(msg) != tipc_own_addr)))
1883 goto cont; 1883 goto cont;
1884 1884
1885 /* Discard non-routeable messages destined for another node */
1886
1887 if (unlikely(!msg_isdata(msg) &&
1888 (msg_destnode(msg) != tipc_own_addr))) {
1889 if ((msg_user(msg) != CONN_MANAGER) &&
1890 (msg_user(msg) != MSG_FRAGMENTER))
1891 goto cont;
1892 }
1893
1885 /* Locate unicast link endpoint that should handle message */ 1894 /* Locate unicast link endpoint that should handle message */
1886 1895
1887 n_ptr = tipc_node_find(msg_prevnode(msg)); 1896 n_ptr = tipc_node_find(msg_prevnode(msg));
@@ -2788,8 +2797,8 @@ int tipc_link_recv_fragment(struct sk_buff **pending, struct sk_buff **fb,
2788 2797
2789 /* Is there an incomplete message waiting for this fragment? */ 2798 /* Is there an incomplete message waiting for this fragment? */
2790 2799
2791 while (pbuf && ((msg_seqno(buf_msg(pbuf)) != long_msg_seq_no) 2800 while (pbuf && ((msg_seqno(buf_msg(pbuf)) != long_msg_seq_no) ||
2792 || (msg_orignode(fragm) != msg_orignode(buf_msg(pbuf))))) { 2801 (msg_orignode(fragm) != msg_orignode(buf_msg(pbuf))))) {
2793 prev = pbuf; 2802 prev = pbuf;
2794 pbuf = pbuf->next; 2803 pbuf = pbuf->next;
2795 } 2804 }
@@ -3325,8 +3334,8 @@ static void link_print(struct link *l_ptr, struct print_buf *buf,
3325 (l_ptr->last_out)), l_ptr->out_queue_size); 3334 (l_ptr->last_out)), l_ptr->out_queue_size);
3326 if ((mod(msg_seqno(buf_msg(l_ptr->last_out)) - 3335 if ((mod(msg_seqno(buf_msg(l_ptr->last_out)) -
3327 msg_seqno(buf_msg(l_ptr->first_out))) 3336 msg_seqno(buf_msg(l_ptr->first_out)))
3328 != (l_ptr->out_queue_size - 1)) 3337 != (l_ptr->out_queue_size - 1)) ||
3329 || (l_ptr->last_out->next != NULL)) { 3338 (l_ptr->last_out->next != NULL)) {
3330 tipc_printf(buf, "\nSend queue inconsistency\n"); 3339 tipc_printf(buf, "\nSend queue inconsistency\n");
3331 tipc_printf(buf, "first_out= %x ", l_ptr->first_out); 3340 tipc_printf(buf, "first_out= %x ", l_ptr->first_out);
3332 tipc_printf(buf, "next_out= %x ", l_ptr->next_out); 3341 tipc_printf(buf, "next_out= %x ", l_ptr->next_out);
diff --git a/net/tipc/net.c b/net/tipc/net.c
index 7906608bf510..f25b1cdb64eb 100644
--- a/net/tipc/net.c
+++ b/net/tipc/net.c
@@ -116,7 +116,8 @@
116*/ 116*/
117 117
118DEFINE_RWLOCK(tipc_net_lock); 118DEFINE_RWLOCK(tipc_net_lock);
119struct network tipc_net = { NULL }; 119struct _zone *tipc_zones[256] = { NULL, };
120struct network tipc_net = { tipc_zones };
120 121
121struct tipc_node *tipc_net_select_remote_node(u32 addr, u32 ref) 122struct tipc_node *tipc_net_select_remote_node(u32 addr, u32 ref)
122{ 123{
@@ -158,28 +159,12 @@ void tipc_net_send_external_routes(u32 dest)
158 } 159 }
159} 160}
160 161
161static int net_init(void)
162{
163 memset(&tipc_net, 0, sizeof(tipc_net));
164 tipc_net.zones = kcalloc(tipc_max_zones + 1, sizeof(struct _zone *), GFP_ATOMIC);
165 if (!tipc_net.zones) {
166 return -ENOMEM;
167 }
168 return 0;
169}
170
171static void net_stop(void) 162static void net_stop(void)
172{ 163{
173 u32 z_num; 164 u32 z_num;
174 165
175 if (!tipc_net.zones) 166 for (z_num = 1; z_num <= tipc_max_zones; z_num++)
176 return;
177
178 for (z_num = 1; z_num <= tipc_max_zones; z_num++) {
179 tipc_zone_delete(tipc_net.zones[z_num]); 167 tipc_zone_delete(tipc_net.zones[z_num]);
180 }
181 kfree(tipc_net.zones);
182 tipc_net.zones = NULL;
183} 168}
184 169
185static void net_route_named_msg(struct sk_buff *buf) 170static void net_route_named_msg(struct sk_buff *buf)
@@ -282,9 +267,7 @@ int tipc_net_start(u32 addr)
282 tipc_named_reinit(); 267 tipc_named_reinit();
283 tipc_port_reinit(); 268 tipc_port_reinit();
284 269
285 if ((res = tipc_bearer_init()) || 270 if ((res = tipc_cltr_init()) ||
286 (res = net_init()) ||
287 (res = tipc_cltr_init()) ||
288 (res = tipc_bclink_init())) { 271 (res = tipc_bclink_init())) {
289 return res; 272 return res;
290 } 273 }
diff --git a/net/tipc/ref.c b/net/tipc/ref.c
index 414fc34b8bea..8dea66500cf5 100644
--- a/net/tipc/ref.c
+++ b/net/tipc/ref.c
@@ -153,11 +153,11 @@ void tipc_ref_table_stop(void)
153 153
154u32 tipc_ref_acquire(void *object, spinlock_t **lock) 154u32 tipc_ref_acquire(void *object, spinlock_t **lock)
155{ 155{
156 struct reference *entry;
157 u32 index; 156 u32 index;
158 u32 index_mask; 157 u32 index_mask;
159 u32 next_plus_upper; 158 u32 next_plus_upper;
160 u32 ref; 159 u32 ref;
160 struct reference *entry = NULL;
161 161
162 if (!object) { 162 if (!object) {
163 err("Attempt to acquire reference to non-existent object\n"); 163 err("Attempt to acquire reference to non-existent object\n");
@@ -175,30 +175,36 @@ u32 tipc_ref_acquire(void *object, spinlock_t **lock)
175 index = tipc_ref_table.first_free; 175 index = tipc_ref_table.first_free;
176 entry = &(tipc_ref_table.entries[index]); 176 entry = &(tipc_ref_table.entries[index]);
177 index_mask = tipc_ref_table.index_mask; 177 index_mask = tipc_ref_table.index_mask;
178 /* take lock in case a previous user of entry still holds it */
179 spin_lock_bh(&entry->lock);
180 next_plus_upper = entry->ref; 178 next_plus_upper = entry->ref;
181 tipc_ref_table.first_free = next_plus_upper & index_mask; 179 tipc_ref_table.first_free = next_plus_upper & index_mask;
182 ref = (next_plus_upper & ~index_mask) + index; 180 ref = (next_plus_upper & ~index_mask) + index;
183 entry->ref = ref;
184 entry->object = object;
185 *lock = &entry->lock;
186 } 181 }
187 else if (tipc_ref_table.init_point < tipc_ref_table.capacity) { 182 else if (tipc_ref_table.init_point < tipc_ref_table.capacity) {
188 index = tipc_ref_table.init_point++; 183 index = tipc_ref_table.init_point++;
189 entry = &(tipc_ref_table.entries[index]); 184 entry = &(tipc_ref_table.entries[index]);
190 spin_lock_init(&entry->lock); 185 spin_lock_init(&entry->lock);
191 spin_lock_bh(&entry->lock);
192 ref = tipc_ref_table.start_mask + index; 186 ref = tipc_ref_table.start_mask + index;
193 entry->ref = ref;
194 entry->object = object;
195 *lock = &entry->lock;
196 } 187 }
197 else { 188 else {
198 ref = 0; 189 ref = 0;
199 } 190 }
200 write_unlock_bh(&ref_table_lock); 191 write_unlock_bh(&ref_table_lock);
201 192
193 /*
194 * Grab the lock so no one else can modify this entry
195 * While we assign its ref value & object pointer
196 */
197 if (entry) {
198 spin_lock_bh(&entry->lock);
199 entry->ref = ref;
200 entry->object = object;
201 *lock = &entry->lock;
202 /*
203 * keep it locked, the caller is responsible
204 * for unlocking this when they're done with it
205 */
206 }
207
202 return ref; 208 return ref;
203} 209}
204 210
diff --git a/net/tipc/socket.c b/net/tipc/socket.c
index e6d9abf7440e..cfb20b80b3a1 100644
--- a/net/tipc/socket.c
+++ b/net/tipc/socket.c
@@ -40,9 +40,9 @@
40#include <linux/socket.h> 40#include <linux/socket.h>
41#include <linux/errno.h> 41#include <linux/errno.h>
42#include <linux/mm.h> 42#include <linux/mm.h>
43#include <linux/slab.h>
44#include <linux/poll.h> 43#include <linux/poll.h>
45#include <linux/fcntl.h> 44#include <linux/fcntl.h>
45#include <linux/gfp.h>
46#include <asm/string.h> 46#include <asm/string.h>
47#include <asm/atomic.h> 47#include <asm/atomic.h>
48#include <net/sock.h> 48#include <net/sock.h>
@@ -177,6 +177,7 @@ static void reject_rx_queue(struct sock *sk)
177 * @net: network namespace (must be default network) 177 * @net: network namespace (must be default network)
178 * @sock: pre-allocated socket structure 178 * @sock: pre-allocated socket structure
179 * @protocol: protocol indicator (must be 0) 179 * @protocol: protocol indicator (must be 0)
180 * @kern: caused by kernel or by userspace?
180 * 181 *
181 * This routine creates additional data structures used by the TIPC socket, 182 * This routine creates additional data structures used by the TIPC socket,
182 * initializes them, and links them together. 183 * initializes them, and links them together.
@@ -184,7 +185,8 @@ static void reject_rx_queue(struct sock *sk)
184 * Returns 0 on success, errno otherwise 185 * Returns 0 on success, errno otherwise
185 */ 186 */
186 187
187static int tipc_create(struct net *net, struct socket *sock, int protocol) 188static int tipc_create(struct net *net, struct socket *sock, int protocol,
189 int kern)
188{ 190{
189 const struct proto_ops *ops; 191 const struct proto_ops *ops;
190 socket_state state; 192 socket_state state;
@@ -193,7 +195,7 @@ static int tipc_create(struct net *net, struct socket *sock, int protocol)
193 195
194 /* Validate arguments */ 196 /* Validate arguments */
195 197
196 if (net != &init_net) 198 if (!net_eq(net, &init_net))
197 return -EAFNOSUPPORT; 199 return -EAFNOSUPPORT;
198 200
199 if (unlikely(protocol != 0)) 201 if (unlikely(protocol != 0))
@@ -1134,13 +1136,11 @@ restart:
1134 1136
1135 /* Loop around if more data is required */ 1137 /* Loop around if more data is required */
1136 1138
1137 if ((sz_copied < buf_len) /* didn't get all requested data */ 1139 if ((sz_copied < buf_len) && /* didn't get all requested data */
1138 && (!skb_queue_empty(&sk->sk_receive_queue) || 1140 (!skb_queue_empty(&sk->sk_receive_queue) ||
1139 (flags & MSG_WAITALL)) 1141 (flags & MSG_WAITALL)) && /* and more is ready or required */
1140 /* ... and more is ready or required */ 1142 (!(flags & MSG_PEEK)) && /* and aren't just peeking at data */
1141 && (!(flags & MSG_PEEK)) /* ... and aren't just peeking at data */ 1143 (!err)) /* and haven't reached a FIN */
1142 && (!err) /* ... and haven't reached a FIN */
1143 )
1144 goto restart; 1144 goto restart;
1145 1145
1146exit: 1146exit:
@@ -1322,8 +1322,10 @@ static u32 dispatch(struct tipc_port *tport, struct sk_buff *buf)
1322 if (!sock_owned_by_user(sk)) { 1322 if (!sock_owned_by_user(sk)) {
1323 res = filter_rcv(sk, buf); 1323 res = filter_rcv(sk, buf);
1324 } else { 1324 } else {
1325 sk_add_backlog(sk, buf); 1325 if (sk_add_backlog(sk, buf))
1326 res = TIPC_OK; 1326 res = TIPC_ERR_OVERLOAD;
1327 else
1328 res = TIPC_OK;
1327 } 1329 }
1328 bh_unlock_sock(sk); 1330 bh_unlock_sock(sk);
1329 1331
@@ -1528,7 +1530,7 @@ static int accept(struct socket *sock, struct socket *new_sock, int flags)
1528 1530
1529 buf = skb_peek(&sk->sk_receive_queue); 1531 buf = skb_peek(&sk->sk_receive_queue);
1530 1532
1531 res = tipc_create(sock_net(sock->sk), new_sock, 0); 1533 res = tipc_create(sock_net(sock->sk), new_sock, 0, 0);
1532 if (!res) { 1534 if (!res) {
1533 struct sock *new_sk = new_sock->sk; 1535 struct sock *new_sk = new_sock->sk;
1534 struct tipc_sock *new_tsock = tipc_sk(new_sk); 1536 struct tipc_sock *new_tsock = tipc_sk(new_sk);
diff --git a/net/tipc/subscr.c b/net/tipc/subscr.c
index 0747d8a9232f..ff123e56114a 100644
--- a/net/tipc/subscr.c
+++ b/net/tipc/subscr.c
@@ -76,19 +76,6 @@ struct top_srv {
76static struct top_srv topsrv = { 0 }; 76static struct top_srv topsrv = { 0 };
77 77
78/** 78/**
79 * htohl - convert value to endianness used by destination
80 * @in: value to convert
81 * @swap: non-zero if endianness must be reversed
82 *
83 * Returns converted value
84 */
85
86static u32 htohl(u32 in, int swap)
87{
88 return swap ? swab32(in) : in;
89}
90
91/**
92 * subscr_send_event - send a message containing a tipc_event to the subscriber 79 * subscr_send_event - send a message containing a tipc_event to the subscriber
93 * 80 *
94 * Note: Must not hold subscriber's server port lock, since tipc_send() will 81 * Note: Must not hold subscriber's server port lock, since tipc_send() will
@@ -107,11 +94,11 @@ static void subscr_send_event(struct subscription *sub,
107 msg_sect.iov_base = (void *)&sub->evt; 94 msg_sect.iov_base = (void *)&sub->evt;
108 msg_sect.iov_len = sizeof(struct tipc_event); 95 msg_sect.iov_len = sizeof(struct tipc_event);
109 96
110 sub->evt.event = htohl(event, sub->swap); 97 sub->evt.event = htonl(event);
111 sub->evt.found_lower = htohl(found_lower, sub->swap); 98 sub->evt.found_lower = htonl(found_lower);
112 sub->evt.found_upper = htohl(found_upper, sub->swap); 99 sub->evt.found_upper = htonl(found_upper);
113 sub->evt.port.ref = htohl(port_ref, sub->swap); 100 sub->evt.port.ref = htonl(port_ref);
114 sub->evt.port.node = htohl(node, sub->swap); 101 sub->evt.port.node = htonl(node);
115 tipc_send(sub->server_ref, 1, &msg_sect); 102 tipc_send(sub->server_ref, 1, &msg_sect);
116} 103}
117 104
@@ -287,16 +274,23 @@ static void subscr_cancel(struct tipc_subscr *s,
287{ 274{
288 struct subscription *sub; 275 struct subscription *sub;
289 struct subscription *sub_temp; 276 struct subscription *sub_temp;
277 __u32 type, lower, upper;
290 int found = 0; 278 int found = 0;
291 279
292 /* Find first matching subscription, exit if not found */ 280 /* Find first matching subscription, exit if not found */
293 281
282 type = ntohl(s->seq.type);
283 lower = ntohl(s->seq.lower);
284 upper = ntohl(s->seq.upper);
285
294 list_for_each_entry_safe(sub, sub_temp, &subscriber->subscription_list, 286 list_for_each_entry_safe(sub, sub_temp, &subscriber->subscription_list,
295 subscription_list) { 287 subscription_list) {
296 if (!memcmp(s, &sub->evt.s, sizeof(struct tipc_subscr))) { 288 if ((type == sub->seq.type) &&
297 found = 1; 289 (lower == sub->seq.lower) &&
298 break; 290 (upper == sub->seq.upper)) {
299 } 291 found = 1;
292 break;
293 }
300 } 294 }
301 if (!found) 295 if (!found)
302 return; 296 return;
@@ -325,16 +319,10 @@ static struct subscription *subscr_subscribe(struct tipc_subscr *s,
325 struct subscriber *subscriber) 319 struct subscriber *subscriber)
326{ 320{
327 struct subscription *sub; 321 struct subscription *sub;
328 int swap;
329
330 /* Determine subscriber's endianness */
331
332 swap = !(s->filter & (TIPC_SUB_PORTS | TIPC_SUB_SERVICE));
333 322
334 /* Detect & process a subscription cancellation request */ 323 /* Detect & process a subscription cancellation request */
335 324
336 if (s->filter & htohl(TIPC_SUB_CANCEL, swap)) { 325 if (ntohl(s->filter) & TIPC_SUB_CANCEL) {
337 s->filter &= ~htohl(TIPC_SUB_CANCEL, swap);
338 subscr_cancel(s, subscriber); 326 subscr_cancel(s, subscriber);
339 return NULL; 327 return NULL;
340 } 328 }
@@ -359,14 +347,14 @@ static struct subscription *subscr_subscribe(struct tipc_subscr *s,
359 347
360 /* Initialize subscription object */ 348 /* Initialize subscription object */
361 349
362 sub->seq.type = htohl(s->seq.type, swap); 350 sub->seq.type = ntohl(s->seq.type);
363 sub->seq.lower = htohl(s->seq.lower, swap); 351 sub->seq.lower = ntohl(s->seq.lower);
364 sub->seq.upper = htohl(s->seq.upper, swap); 352 sub->seq.upper = ntohl(s->seq.upper);
365 sub->timeout = htohl(s->timeout, swap); 353 sub->timeout = ntohl(s->timeout);
366 sub->filter = htohl(s->filter, swap); 354 sub->filter = ntohl(s->filter);
367 if ((!(sub->filter & TIPC_SUB_PORTS) 355 if ((!(sub->filter & TIPC_SUB_PORTS) ==
368 == !(sub->filter & TIPC_SUB_SERVICE)) 356 !(sub->filter & TIPC_SUB_SERVICE)) ||
369 || (sub->seq.lower > sub->seq.upper)) { 357 (sub->seq.lower > sub->seq.upper)) {
370 warn("Subscription rejected, illegal request\n"); 358 warn("Subscription rejected, illegal request\n");
371 kfree(sub); 359 kfree(sub);
372 subscr_terminate(subscriber); 360 subscr_terminate(subscriber);
@@ -376,7 +364,6 @@ static struct subscription *subscr_subscribe(struct tipc_subscr *s,
376 INIT_LIST_HEAD(&sub->nameseq_list); 364 INIT_LIST_HEAD(&sub->nameseq_list);
377 list_add(&sub->subscription_list, &subscriber->subscription_list); 365 list_add(&sub->subscription_list, &subscriber->subscription_list);
378 sub->server_ref = subscriber->port_ref; 366 sub->server_ref = subscriber->port_ref;
379 sub->swap = swap;
380 memcpy(&sub->evt.s, s, sizeof(struct tipc_subscr)); 367 memcpy(&sub->evt.s, s, sizeof(struct tipc_subscr));
381 atomic_inc(&topsrv.subscription_count); 368 atomic_inc(&topsrv.subscription_count);
382 if (sub->timeout != TIPC_WAIT_FOREVER) { 369 if (sub->timeout != TIPC_WAIT_FOREVER) {
diff --git a/net/tipc/subscr.h b/net/tipc/subscr.h
index 45d89bf4d202..c20f496d95b2 100644
--- a/net/tipc/subscr.h
+++ b/net/tipc/subscr.h
@@ -53,7 +53,6 @@ typedef void (*tipc_subscr_event) (struct subscription *sub,
53 * @nameseq_list: adjacent subscriptions in name sequence's subscription list 53 * @nameseq_list: adjacent subscriptions in name sequence's subscription list
54 * @subscription_list: adjacent subscriptions in subscriber's subscription list 54 * @subscription_list: adjacent subscriptions in subscriber's subscription list
55 * @server_ref: object reference of server port associated with subscription 55 * @server_ref: object reference of server port associated with subscription
56 * @swap: indicates if subscriber uses opposite endianness in its messages
57 * @evt: template for events generated by subscription 56 * @evt: template for events generated by subscription
58 */ 57 */
59 58
@@ -66,7 +65,6 @@ struct subscription {
66 struct list_head nameseq_list; 65 struct list_head nameseq_list;
67 struct list_head subscription_list; 66 struct list_head subscription_list;
68 u32 server_ref; 67 u32 server_ref;
69 int swap;
70 struct tipc_event evt; 68 struct tipc_event evt;
71}; 69};
72 70
diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
index fc820cd75453..3d9122e78f41 100644
--- a/net/unix/af_unix.c
+++ b/net/unix/af_unix.c
@@ -144,7 +144,7 @@ static inline void unix_set_secdata(struct scm_cookie *scm, struct sk_buff *skb)
144/* 144/*
145 * SMP locking strategy: 145 * SMP locking strategy:
146 * hash table is protected with spinlock unix_table_lock 146 * hash table is protected with spinlock unix_table_lock
147 * each socket state is protected by separate rwlock. 147 * each socket state is protected by separate spin lock.
148 */ 148 */
149 149
150static inline unsigned unix_hash_fold(__wsum n) 150static inline unsigned unix_hash_fold(__wsum n)
@@ -621,7 +621,8 @@ out:
621 return sk; 621 return sk;
622} 622}
623 623
624static int unix_create(struct net *net, struct socket *sock, int protocol) 624static int unix_create(struct net *net, struct socket *sock, int protocol,
625 int kern)
625{ 626{
626 if (protocol && protocol != PF_UNIX) 627 if (protocol && protocol != PF_UNIX)
627 return -EPROTONOSUPPORT; 628 return -EPROTONOSUPPORT;
@@ -1032,8 +1033,8 @@ static int unix_stream_connect(struct socket *sock, struct sockaddr *uaddr,
1032 goto out; 1033 goto out;
1033 addr_len = err; 1034 addr_len = err;
1034 1035
1035 if (test_bit(SOCK_PASSCRED, &sock->flags) 1036 if (test_bit(SOCK_PASSCRED, &sock->flags) && !u->addr &&
1036 && !u->addr && (err = unix_autobind(sock)) != 0) 1037 (err = unix_autobind(sock)) != 0)
1037 goto out; 1038 goto out;
1038 1039
1039 timeo = sock_sndtimeo(sk, flags & O_NONBLOCK); 1040 timeo = sock_sndtimeo(sk, flags & O_NONBLOCK);
@@ -1258,7 +1259,7 @@ static int unix_getname(struct socket *sock, struct sockaddr *uaddr, int *uaddr_
1258{ 1259{
1259 struct sock *sk = sock->sk; 1260 struct sock *sk = sock->sk;
1260 struct unix_sock *u; 1261 struct unix_sock *u;
1261 struct sockaddr_un *sunaddr = (struct sockaddr_un *)uaddr; 1262 DECLARE_SOCKADDR(struct sockaddr_un *, sunaddr, uaddr);
1262 int err = 0; 1263 int err = 0;
1263 1264
1264 if (peer) { 1265 if (peer) {
@@ -1377,8 +1378,8 @@ static int unix_dgram_sendmsg(struct kiocb *kiocb, struct socket *sock,
1377 goto out; 1378 goto out;
1378 } 1379 }
1379 1380
1380 if (test_bit(SOCK_PASSCRED, &sock->flags) 1381 if (test_bit(SOCK_PASSCRED, &sock->flags) && !u->addr
1381 && !u->addr && (err = unix_autobind(sock)) != 0) 1382 && (err = unix_autobind(sock)) != 0)
1382 goto out; 1383 goto out;
1383 1384
1384 err = -EMSGSIZE; 1385 err = -EMSGSIZE;
@@ -2216,14 +2217,14 @@ static const struct file_operations unix_seq_fops = {
2216 2217
2217#endif 2218#endif
2218 2219
2219static struct net_proto_family unix_family_ops = { 2220static const struct net_proto_family unix_family_ops = {
2220 .family = PF_UNIX, 2221 .family = PF_UNIX,
2221 .create = unix_create, 2222 .create = unix_create,
2222 .owner = THIS_MODULE, 2223 .owner = THIS_MODULE,
2223}; 2224};
2224 2225
2225 2226
2226static int unix_net_init(struct net *net) 2227static int __net_init unix_net_init(struct net *net)
2227{ 2228{
2228 int error = -ENOMEM; 2229 int error = -ENOMEM;
2229 2230
@@ -2242,7 +2243,7 @@ out:
2242 return error; 2243 return error;
2243} 2244}
2244 2245
2245static void unix_net_exit(struct net *net) 2246static void __net_exit unix_net_exit(struct net *net)
2246{ 2247{
2247 unix_sysctl_unregister(net); 2248 unix_sysctl_unregister(net);
2248 proc_net_remove(net, "unix"); 2249 proc_net_remove(net, "unix");
diff --git a/net/unix/garbage.c b/net/unix/garbage.c
index 19c17e4a0c8b..14c22c3768da 100644
--- a/net/unix/garbage.c
+++ b/net/unix/garbage.c
@@ -74,7 +74,6 @@
74#include <linux/un.h> 74#include <linux/un.h>
75#include <linux/net.h> 75#include <linux/net.h>
76#include <linux/fs.h> 76#include <linux/fs.h>
77#include <linux/slab.h>
78#include <linux/skbuff.h> 77#include <linux/skbuff.h>
79#include <linux/netdevice.h> 78#include <linux/netdevice.h>
80#include <linux/file.h> 79#include <linux/file.h>
diff --git a/net/unix/sysctl_net_unix.c b/net/unix/sysctl_net_unix.c
index 83c093077ebc..397cffebb3b6 100644
--- a/net/unix/sysctl_net_unix.c
+++ b/net/unix/sysctl_net_unix.c
@@ -10,29 +10,29 @@
10 */ 10 */
11 11
12#include <linux/mm.h> 12#include <linux/mm.h>
13#include <linux/slab.h>
13#include <linux/sysctl.h> 14#include <linux/sysctl.h>
14 15
15#include <net/af_unix.h> 16#include <net/af_unix.h>
16 17
17static ctl_table unix_table[] = { 18static ctl_table unix_table[] = {
18 { 19 {
19 .ctl_name = NET_UNIX_MAX_DGRAM_QLEN,
20 .procname = "max_dgram_qlen", 20 .procname = "max_dgram_qlen",
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 { }
27}; 27};
28 28
29static struct ctl_path unix_path[] = { 29static struct ctl_path unix_path[] = {
30 { .procname = "net", .ctl_name = CTL_NET, }, 30 { .procname = "net", },
31 { .procname = "unix", .ctl_name = NET_UNIX, }, 31 { .procname = "unix", },
32 { }, 32 { },
33}; 33};
34 34
35int unix_sysctl_register(struct net *net) 35int __net_init unix_sysctl_register(struct net *net)
36{ 36{
37 struct ctl_table *table; 37 struct ctl_table *table;
38 38
diff --git a/net/wimax/op-msg.c b/net/wimax/op-msg.c
index d631a17186bc..d5b7c3779c43 100644
--- a/net/wimax/op-msg.c
+++ b/net/wimax/op-msg.c
@@ -72,6 +72,7 @@
72 * wimax_msg_send() 72 * wimax_msg_send()
73 */ 73 */
74#include <linux/device.h> 74#include <linux/device.h>
75#include <linux/slab.h>
75#include <net/genetlink.h> 76#include <net/genetlink.h>
76#include <linux/netdevice.h> 77#include <linux/netdevice.h>
77#include <linux/wimax.h> 78#include <linux/wimax.h>
@@ -320,8 +321,7 @@ int wimax_msg(struct wimax_dev *wimax_dev, const char *pipe_name,
320EXPORT_SYMBOL_GPL(wimax_msg); 321EXPORT_SYMBOL_GPL(wimax_msg);
321 322
322 323
323static const 324static const struct nla_policy wimax_gnl_msg_policy[WIMAX_GNL_ATTR_MAX + 1] = {
324struct nla_policy wimax_gnl_msg_policy[WIMAX_GNL_ATTR_MAX + 1] = {
325 [WIMAX_GNL_MSG_IFIDX] = { 325 [WIMAX_GNL_MSG_IFIDX] = {
326 .type = NLA_U32, 326 .type = NLA_U32,
327 }, 327 },
@@ -388,6 +388,8 @@ int wimax_gnl_doit_msg_from_user(struct sk_buff *skb, struct genl_info *info)
388 } 388 }
389 mutex_lock(&wimax_dev->mutex); 389 mutex_lock(&wimax_dev->mutex);
390 result = wimax_dev_is_ready(wimax_dev); 390 result = wimax_dev_is_ready(wimax_dev);
391 if (result == -ENOMEDIUM)
392 result = 0;
391 if (result < 0) 393 if (result < 0)
392 goto error_not_ready; 394 goto error_not_ready;
393 result = -ENOSYS; 395 result = -ENOSYS;
diff --git a/net/wimax/op-reset.c b/net/wimax/op-reset.c
index ca269178c4d4..4dc82a54ba30 100644
--- a/net/wimax/op-reset.c
+++ b/net/wimax/op-reset.c
@@ -62,7 +62,7 @@
62 * Called when wanting to reset the device for any reason. Device is 62 * Called when wanting to reset the device for any reason. Device is
63 * taken back to power on status. 63 * taken back to power on status.
64 * 64 *
65 * This call blocks; on succesful return, the device has completed the 65 * This call blocks; on successful return, the device has completed the
66 * reset process and is ready to operate. 66 * reset process and is ready to operate.
67 */ 67 */
68int wimax_reset(struct wimax_dev *wimax_dev) 68int wimax_reset(struct wimax_dev *wimax_dev)
@@ -91,8 +91,7 @@ int wimax_reset(struct wimax_dev *wimax_dev)
91EXPORT_SYMBOL(wimax_reset); 91EXPORT_SYMBOL(wimax_reset);
92 92
93 93
94static const 94static const struct nla_policy wimax_gnl_reset_policy[WIMAX_GNL_ATTR_MAX + 1] = {
95struct nla_policy wimax_gnl_reset_policy[WIMAX_GNL_ATTR_MAX + 1] = {
96 [WIMAX_GNL_RESET_IFIDX] = { 95 [WIMAX_GNL_RESET_IFIDX] = {
97 .type = NLA_U32, 96 .type = NLA_U32,
98 }, 97 },
diff --git a/net/wimax/op-rfkill.c b/net/wimax/op-rfkill.c
index 70ef4df863b9..e978c7136c97 100644
--- a/net/wimax/op-rfkill.c
+++ b/net/wimax/op-rfkill.c
@@ -107,8 +107,8 @@ void wimax_report_rfkill_hw(struct wimax_dev *wimax_dev,
107 107
108 if (state != wimax_dev->rf_hw) { 108 if (state != wimax_dev->rf_hw) {
109 wimax_dev->rf_hw = state; 109 wimax_dev->rf_hw = state;
110 if (wimax_dev->rf_hw == WIMAX_RF_ON 110 if (wimax_dev->rf_hw == WIMAX_RF_ON &&
111 && wimax_dev->rf_sw == WIMAX_RF_ON) 111 wimax_dev->rf_sw == WIMAX_RF_ON)
112 wimax_state = WIMAX_ST_READY; 112 wimax_state = WIMAX_ST_READY;
113 else 113 else
114 wimax_state = WIMAX_ST_RADIO_OFF; 114 wimax_state = WIMAX_ST_RADIO_OFF;
@@ -163,8 +163,8 @@ void wimax_report_rfkill_sw(struct wimax_dev *wimax_dev,
163 163
164 if (state != wimax_dev->rf_sw) { 164 if (state != wimax_dev->rf_sw) {
165 wimax_dev->rf_sw = state; 165 wimax_dev->rf_sw = state;
166 if (wimax_dev->rf_hw == WIMAX_RF_ON 166 if (wimax_dev->rf_hw == WIMAX_RF_ON &&
167 && wimax_dev->rf_sw == WIMAX_RF_ON) 167 wimax_dev->rf_sw == WIMAX_RF_ON)
168 wimax_state = WIMAX_ST_READY; 168 wimax_state = WIMAX_ST_READY;
169 else 169 else
170 wimax_state = WIMAX_ST_RADIO_OFF; 170 wimax_state = WIMAX_ST_RADIO_OFF;
@@ -305,8 +305,15 @@ int wimax_rfkill(struct wimax_dev *wimax_dev, enum wimax_rf_state state)
305 d_fnstart(3, dev, "(wimax_dev %p state %u)\n", wimax_dev, state); 305 d_fnstart(3, dev, "(wimax_dev %p state %u)\n", wimax_dev, state);
306 mutex_lock(&wimax_dev->mutex); 306 mutex_lock(&wimax_dev->mutex);
307 result = wimax_dev_is_ready(wimax_dev); 307 result = wimax_dev_is_ready(wimax_dev);
308 if (result < 0) 308 if (result < 0) {
309 /* While initializing, < 1.4.3 wimax-tools versions use
310 * this call to check if the device is a valid WiMAX
311 * device; so we allow it to proceed always,
312 * considering the radios are all off. */
313 if (result == -ENOMEDIUM && state == WIMAX_RF_QUERY)
314 result = WIMAX_RF_OFF << 1 | WIMAX_RF_OFF;
309 goto error_not_ready; 315 goto error_not_ready;
316 }
310 switch (state) { 317 switch (state) {
311 case WIMAX_RF_ON: 318 case WIMAX_RF_ON:
312 case WIMAX_RF_OFF: 319 case WIMAX_RF_OFF:
@@ -355,6 +362,7 @@ int wimax_rfkill_add(struct wimax_dev *wimax_dev)
355 362
356 wimax_dev->rfkill = rfkill; 363 wimax_dev->rfkill = rfkill;
357 364
365 rfkill_init_sw_state(rfkill, 1);
358 result = rfkill_register(wimax_dev->rfkill); 366 result = rfkill_register(wimax_dev->rfkill);
359 if (result < 0) 367 if (result < 0)
360 goto error_rfkill_register; 368 goto error_rfkill_register;
@@ -402,8 +410,7 @@ void wimax_rfkill_rm(struct wimax_dev *wimax_dev)
402 * just query). 410 * just query).
403 */ 411 */
404 412
405static const 413static const struct nla_policy wimax_gnl_rfkill_policy[WIMAX_GNL_ATTR_MAX + 1] = {
406struct nla_policy wimax_gnl_rfkill_policy[WIMAX_GNL_ATTR_MAX + 1] = {
407 [WIMAX_GNL_RFKILL_IFIDX] = { 414 [WIMAX_GNL_RFKILL_IFIDX] = {
408 .type = NLA_U32, 415 .type = NLA_U32,
409 }, 416 },
diff --git a/net/wimax/op-state-get.c b/net/wimax/op-state-get.c
index a76b8fcb056d..11ad3356eb56 100644
--- a/net/wimax/op-state-get.c
+++ b/net/wimax/op-state-get.c
@@ -33,8 +33,7 @@
33#include "debug-levels.h" 33#include "debug-levels.h"
34 34
35 35
36static const 36static const struct nla_policy wimax_gnl_state_get_policy[WIMAX_GNL_ATTR_MAX + 1] = {
37struct nla_policy wimax_gnl_state_get_policy[WIMAX_GNL_ATTR_MAX + 1] = {
38 [WIMAX_GNL_STGET_IFIDX] = { 37 [WIMAX_GNL_STGET_IFIDX] = {
39 .type = NLA_U32, 38 .type = NLA_U32,
40 }, 39 },
diff --git a/net/wimax/stack.c b/net/wimax/stack.c
index 79fb7d7c640f..1ed65dbdab03 100644
--- a/net/wimax/stack.c
+++ b/net/wimax/stack.c
@@ -51,6 +51,7 @@
51 * wimax_rfkill_rm() 51 * wimax_rfkill_rm()
52 */ 52 */
53#include <linux/device.h> 53#include <linux/device.h>
54#include <linux/gfp.h>
54#include <net/genetlink.h> 55#include <net/genetlink.h>
55#include <linux/netdevice.h> 56#include <linux/netdevice.h>
56#include <linux/wimax.h> 57#include <linux/wimax.h>
@@ -60,6 +61,14 @@
60#define D_SUBMODULE stack 61#define D_SUBMODULE stack
61#include "debug-levels.h" 62#include "debug-levels.h"
62 63
64static char wimax_debug_params[128];
65module_param_string(debug, wimax_debug_params, sizeof(wimax_debug_params),
66 0644);
67MODULE_PARM_DESC(debug,
68 "String of space-separated NAME:VALUE pairs, where NAMEs "
69 "are the different debug submodules and VALUE are the "
70 "initial debug value to set.");
71
63/* 72/*
64 * Authoritative source for the RE_STATE_CHANGE attribute policy 73 * Authoritative source for the RE_STATE_CHANGE attribute policy
65 * 74 *
@@ -67,8 +76,7 @@
67 * close to where the data is generated. 76 * close to where the data is generated.
68 */ 77 */
69/* 78/*
70static const 79static const struct nla_policy wimax_gnl_re_status_change[WIMAX_GNL_ATTR_MAX + 1] = {
71struct nla_policy wimax_gnl_re_status_change[WIMAX_GNL_ATTR_MAX + 1] = {
72 [WIMAX_GNL_STCH_STATE_OLD] = { .type = NLA_U8 }, 80 [WIMAX_GNL_STCH_STATE_OLD] = { .type = NLA_U8 },
73 [WIMAX_GNL_STCH_STATE_NEW] = { .type = NLA_U8 }, 81 [WIMAX_GNL_STCH_STATE_NEW] = { .type = NLA_U8 },
74}; 82};
@@ -562,6 +570,9 @@ int __init wimax_subsys_init(void)
562 int result, cnt; 570 int result, cnt;
563 571
564 d_fnstart(4, NULL, "()\n"); 572 d_fnstart(4, NULL, "()\n");
573 d_parse_params(D_LEVEL, D_LEVEL_SIZE, wimax_debug_params,
574 "wimax.debug");
575
565 snprintf(wimax_gnl_family.name, sizeof(wimax_gnl_family.name), 576 snprintf(wimax_gnl_family.name, sizeof(wimax_gnl_family.name),
566 "WiMAX"); 577 "WiMAX");
567 result = genl_register_family(&wimax_gnl_family); 578 result = genl_register_family(&wimax_gnl_family);
diff --git a/net/wireless/.gitignore b/net/wireless/.gitignore
new file mode 100644
index 000000000000..c33451b896d9
--- /dev/null
+++ b/net/wireless/.gitignore
@@ -0,0 +1 @@
regdb.c
diff --git a/net/wireless/Kconfig b/net/wireless/Kconfig
index abf7ca3f9ff9..d0ee29063e5d 100644
--- a/net/wireless/Kconfig
+++ b/net/wireless/Kconfig
@@ -1,3 +1,21 @@
1config WIRELESS_EXT
2 bool
3
4config WEXT_CORE
5 def_bool y
6 depends on CFG80211_WEXT || WIRELESS_EXT
7
8config WEXT_PROC
9 def_bool y
10 depends on PROC_FS
11 depends on WEXT_CORE
12
13config WEXT_SPY
14 bool
15
16config WEXT_PRIV
17 bool
18
1config CFG80211 19config CFG80211
2 tristate "cfg80211 - wireless configuration API" 20 tristate "cfg80211 - wireless configuration API"
3 depends on RFKILL || !RFKILL 21 depends on RFKILL || !RFKILL
@@ -67,47 +85,44 @@ config CFG80211_DEFAULT_PS
67 applications instead -- they need to register their network 85 applications instead -- they need to register their network
68 latency requirement, see Documentation/power/pm_qos_interface.txt. 86 latency requirement, see Documentation/power/pm_qos_interface.txt.
69 87
70config CFG80211_DEFAULT_PS_VALUE
71 int
72 default 1 if CFG80211_DEFAULT_PS
73 default 0
74
75config CFG80211_DEBUGFS 88config CFG80211_DEBUGFS
76 bool "cfg80211 DebugFS entries" 89 bool "cfg80211 DebugFS entries"
77 depends on CFG80211 && DEBUG_FS 90 depends on CFG80211
91 depends on DEBUG_FS
78 ---help--- 92 ---help---
79 You can enable this if you want to debugfs entries for cfg80211. 93 You can enable this if you want to debugfs entries for cfg80211.
80 94
81 If unsure, say N. 95 If unsure, say N.
82 96
83config WIRELESS_OLD_REGULATORY 97config CFG80211_INTERNAL_REGDB
84 bool "Old wireless static regulatory definitions" 98 bool "use statically compiled regulatory rules database" if EMBEDDED
85 default n 99 default n
100 depends on CFG80211
86 ---help--- 101 ---help---
87 This option enables the old static regulatory information 102 This option generates an internal data structure representing
88 and uses it within the new framework. This option is available 103 the wireless regulatory rules described in net/wireless/db.txt
89 for historical reasons and it is advised to leave it off. 104 and includes code to query that database. This is an alternative
105 to using CRDA for defining regulatory rules for the kernel.
90 106
91 For details see: 107 For details see:
92 108
93 http://wireless.kernel.org/en/developers/Regulatory 109 http://wireless.kernel.org/en/developers/Regulatory
94 110
95 Say N and if you say Y, please tell us why. The default is N. 111 Most distributions have a CRDA package. So if unsure, say N.
96 112
97config WIRELESS_EXT 113config CFG80211_WEXT
98 bool "Wireless extensions" 114 bool "cfg80211 wireless extensions compatibility"
115 depends on CFG80211
116 select WEXT_CORE
99 default y 117 default y
100 ---help--- 118 help
101 This option enables the legacy wireless extensions 119 Enable this option if you need old userspace for wireless
102 (wireless network interface configuration via ioctls.) 120 extensions with cfg80211-based drivers.
103
104 Say Y unless you've upgraded all your userspace to use
105 nl80211 instead of wireless extensions.
106 121
107config WIRELESS_EXT_SYSFS 122config WIRELESS_EXT_SYSFS
108 bool "Wireless extensions sysfs files" 123 bool "Wireless extensions sysfs files"
109 default y 124 default y
110 depends on WIRELESS_EXT && SYSFS 125 depends on WEXT_CORE && SYSFS
111 help 126 help
112 This option enables the deprecated wireless statistics 127 This option enables the deprecated wireless statistics
113 files in /sys/class/net/*/wireless/. The same information 128 files in /sys/class/net/*/wireless/. The same information
diff --git a/net/wireless/Makefile b/net/wireless/Makefile
index 3ecaa9179977..e77e508126fa 100644
--- a/net/wireless/Makefile
+++ b/net/wireless/Makefile
@@ -1,13 +1,23 @@
1obj-$(CONFIG_WIRELESS_EXT) += wext.o
2obj-$(CONFIG_CFG80211) += cfg80211.o 1obj-$(CONFIG_CFG80211) += cfg80211.o
3obj-$(CONFIG_LIB80211) += lib80211.o 2obj-$(CONFIG_LIB80211) += lib80211.o
4obj-$(CONFIG_LIB80211_CRYPT_WEP) += lib80211_crypt_wep.o 3obj-$(CONFIG_LIB80211_CRYPT_WEP) += lib80211_crypt_wep.o
5obj-$(CONFIG_LIB80211_CRYPT_CCMP) += lib80211_crypt_ccmp.o 4obj-$(CONFIG_LIB80211_CRYPT_CCMP) += lib80211_crypt_ccmp.o
6obj-$(CONFIG_LIB80211_CRYPT_TKIP) += lib80211_crypt_tkip.o 5obj-$(CONFIG_LIB80211_CRYPT_TKIP) += lib80211_crypt_tkip.o
7 6
7obj-$(CONFIG_WEXT_CORE) += wext-core.o
8obj-$(CONFIG_WEXT_PROC) += wext-proc.o
9obj-$(CONFIG_WEXT_SPY) += wext-spy.o
10obj-$(CONFIG_WEXT_PRIV) += wext-priv.o
11
8cfg80211-y += core.o sysfs.o radiotap.o util.o reg.o scan.o nl80211.o 12cfg80211-y += core.o sysfs.o radiotap.o util.o reg.o scan.o nl80211.o
9cfg80211-y += mlme.o ibss.o sme.o chan.o 13cfg80211-y += mlme.o ibss.o sme.o chan.o ethtool.o
10cfg80211-$(CONFIG_CFG80211_DEBUGFS) += debugfs.o 14cfg80211-$(CONFIG_CFG80211_DEBUGFS) += debugfs.o
11cfg80211-$(CONFIG_WIRELESS_EXT) += wext-compat.o wext-sme.o 15cfg80211-$(CONFIG_CFG80211_WEXT) += wext-compat.o wext-sme.o
16cfg80211-$(CONFIG_CFG80211_INTERNAL_REGDB) += regdb.o
12 17
13ccflags-y += -D__CHECK_ENDIAN__ 18ccflags-y += -D__CHECK_ENDIAN__
19
20$(obj)/regdb.c: $(src)/db.txt $(src)/genregdb.awk
21 @$(AWK) -f $(srctree)/$(src)/genregdb.awk < $< > $@
22
23clean-files := regdb.c
diff --git a/net/wireless/chan.c b/net/wireless/chan.c
index a46ac6c9b365..bf1737fc9a7e 100644
--- a/net/wireless/chan.c
+++ b/net/wireless/chan.c
@@ -41,44 +41,57 @@ rdev_fixed_channel(struct cfg80211_registered_device *rdev,
41 return result; 41 return result;
42} 42}
43 43
44int rdev_set_freq(struct cfg80211_registered_device *rdev, 44struct ieee80211_channel *
45 struct wireless_dev *for_wdev, 45rdev_freq_to_chan(struct cfg80211_registered_device *rdev,
46 int freq, enum nl80211_channel_type channel_type) 46 int freq, enum nl80211_channel_type channel_type)
47{ 47{
48 struct ieee80211_channel *chan; 48 struct ieee80211_channel *chan;
49 struct ieee80211_sta_ht_cap *ht_cap; 49 struct ieee80211_sta_ht_cap *ht_cap;
50 int result;
51
52 if (rdev_fixed_channel(rdev, for_wdev))
53 return -EBUSY;
54
55 if (!rdev->ops->set_channel)
56 return -EOPNOTSUPP;
57 50
58 chan = ieee80211_get_channel(&rdev->wiphy, freq); 51 chan = ieee80211_get_channel(&rdev->wiphy, freq);
59 52
60 /* Primary channel not allowed */ 53 /* Primary channel not allowed */
61 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) 54 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED)
62 return -EINVAL; 55 return NULL;
63 56
64 if (channel_type == NL80211_CHAN_HT40MINUS && 57 if (channel_type == NL80211_CHAN_HT40MINUS &&
65 chan->flags & IEEE80211_CHAN_NO_HT40MINUS) 58 chan->flags & IEEE80211_CHAN_NO_HT40MINUS)
66 return -EINVAL; 59 return NULL;
67 else if (channel_type == NL80211_CHAN_HT40PLUS && 60 else if (channel_type == NL80211_CHAN_HT40PLUS &&
68 chan->flags & IEEE80211_CHAN_NO_HT40PLUS) 61 chan->flags & IEEE80211_CHAN_NO_HT40PLUS)
69 return -EINVAL; 62 return NULL;
70 63
71 ht_cap = &rdev->wiphy.bands[chan->band]->ht_cap; 64 ht_cap = &rdev->wiphy.bands[chan->band]->ht_cap;
72 65
73 if (channel_type != NL80211_CHAN_NO_HT) { 66 if (channel_type != NL80211_CHAN_NO_HT) {
74 if (!ht_cap->ht_supported) 67 if (!ht_cap->ht_supported)
75 return -EINVAL; 68 return NULL;
76 69
77 if (!(ht_cap->cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) || 70 if (!(ht_cap->cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) ||
78 ht_cap->cap & IEEE80211_HT_CAP_40MHZ_INTOLERANT) 71 ht_cap->cap & IEEE80211_HT_CAP_40MHZ_INTOLERANT)
79 return -EINVAL; 72 return NULL;
80 } 73 }
81 74
75 return chan;
76}
77
78int rdev_set_freq(struct cfg80211_registered_device *rdev,
79 struct wireless_dev *for_wdev,
80 int freq, enum nl80211_channel_type channel_type)
81{
82 struct ieee80211_channel *chan;
83 int result;
84
85 if (rdev_fixed_channel(rdev, for_wdev))
86 return -EBUSY;
87
88 if (!rdev->ops->set_channel)
89 return -EOPNOTSUPP;
90
91 chan = rdev_freq_to_chan(rdev, freq, channel_type);
92 if (!chan)
93 return -EINVAL;
94
82 result = rdev->ops->set_channel(&rdev->wiphy, chan, channel_type); 95 result = rdev->ops->set_channel(&rdev->wiphy, chan, channel_type);
83 if (result) 96 if (result)
84 return result; 97 return result;
diff --git a/net/wireless/core.c b/net/wireless/core.c
index a595f712b5bf..6ac70c101523 100644
--- a/net/wireless/core.c
+++ b/net/wireless/core.c
@@ -1,13 +1,14 @@
1/* 1/*
2 * This is the linux wireless configuration interface. 2 * This is the linux wireless configuration interface.
3 * 3 *
4 * Copyright 2006-2009 Johannes Berg <johannes@sipsolutions.net> 4 * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
5 */ 5 */
6 6
7#include <linux/if.h> 7#include <linux/if.h>
8#include <linux/module.h> 8#include <linux/module.h>
9#include <linux/err.h> 9#include <linux/err.h>
10#include <linux/list.h> 10#include <linux/list.h>
11#include <linux/slab.h>
11#include <linux/nl80211.h> 12#include <linux/nl80211.h>
12#include <linux/debugfs.h> 13#include <linux/debugfs.h>
13#include <linux/notifier.h> 14#include <linux/notifier.h>
@@ -22,6 +23,7 @@
22#include "sysfs.h" 23#include "sysfs.h"
23#include "debugfs.h" 24#include "debugfs.h"
24#include "wext-compat.h" 25#include "wext-compat.h"
26#include "ethtool.h"
25 27
26/* name for sysfs, %d is appended */ 28/* name for sysfs, %d is appended */
27#define PHY_NAME "phy" 29#define PHY_NAME "phy"
@@ -30,20 +32,18 @@ MODULE_AUTHOR("Johannes Berg");
30MODULE_LICENSE("GPL"); 32MODULE_LICENSE("GPL");
31MODULE_DESCRIPTION("wireless configuration support"); 33MODULE_DESCRIPTION("wireless configuration support");
32 34
33/* RCU might be appropriate here since we usually 35/* RCU-protected (and cfg80211_mutex for writers) */
34 * only read the list, and that can happen quite
35 * often because we need to do it for each command */
36LIST_HEAD(cfg80211_rdev_list); 36LIST_HEAD(cfg80211_rdev_list);
37int cfg80211_rdev_list_generation; 37int cfg80211_rdev_list_generation;
38 38
39/*
40 * This is used to protect the cfg80211_rdev_list
41 */
42DEFINE_MUTEX(cfg80211_mutex); 39DEFINE_MUTEX(cfg80211_mutex);
43 40
44/* for debugfs */ 41/* for debugfs */
45static struct dentry *ieee80211_debugfs_dir; 42static struct dentry *ieee80211_debugfs_dir;
46 43
44/* for the cleanup, scan and event works */
45struct workqueue_struct *cfg80211_wq;
46
47/* requires cfg80211_mutex to be held! */ 47/* requires cfg80211_mutex to be held! */
48struct cfg80211_registered_device *cfg80211_rdev_by_wiphy_idx(int wiphy_idx) 48struct cfg80211_registered_device *cfg80211_rdev_by_wiphy_idx(int wiphy_idx)
49{ 49{
@@ -230,7 +230,7 @@ int cfg80211_switch_netns(struct cfg80211_registered_device *rdev,
230 struct wireless_dev *wdev; 230 struct wireless_dev *wdev;
231 int err = 0; 231 int err = 0;
232 232
233 if (!rdev->wiphy.netnsok) 233 if (!(rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK))
234 return -EOPNOTSUPP; 234 return -EOPNOTSUPP;
235 235
236 list_for_each_entry(wdev, &rdev->netdev_list, list) { 236 list_for_each_entry(wdev, &rdev->netdev_list, list) {
@@ -359,11 +359,17 @@ struct wiphy *wiphy_new(const struct cfg80211_ops *ops, int sizeof_priv)
359 INIT_LIST_HEAD(&rdev->bss_list); 359 INIT_LIST_HEAD(&rdev->bss_list);
360 INIT_WORK(&rdev->scan_done_wk, __cfg80211_scan_done); 360 INIT_WORK(&rdev->scan_done_wk, __cfg80211_scan_done);
361 361
362#ifdef CONFIG_CFG80211_WEXT
363 rdev->wiphy.wext = &cfg80211_wext_handler;
364#endif
365
362 device_initialize(&rdev->wiphy.dev); 366 device_initialize(&rdev->wiphy.dev);
363 rdev->wiphy.dev.class = &ieee80211_class; 367 rdev->wiphy.dev.class = &ieee80211_class;
364 rdev->wiphy.dev.platform_data = rdev; 368 rdev->wiphy.dev.platform_data = rdev;
365 369
366 rdev->wiphy.ps_default = CONFIG_CFG80211_DEFAULT_PS_VALUE; 370#ifdef CONFIG_CFG80211_DEFAULT_PS
371 rdev->wiphy.flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT;
372#endif
367 373
368 wiphy_net_set(&rdev->wiphy, &init_net); 374 wiphy_net_set(&rdev->wiphy, &init_net);
369 375
@@ -392,6 +398,7 @@ struct wiphy *wiphy_new(const struct cfg80211_ops *ops, int sizeof_priv)
392 rdev->wiphy.retry_long = 4; 398 rdev->wiphy.retry_long = 4;
393 rdev->wiphy.frag_threshold = (u32) -1; 399 rdev->wiphy.frag_threshold = (u32) -1;
394 rdev->wiphy.rts_threshold = (u32) -1; 400 rdev->wiphy.rts_threshold = (u32) -1;
401 rdev->wiphy.coverage_class = 0;
395 402
396 return &rdev->wiphy; 403 return &rdev->wiphy;
397} 404}
@@ -407,6 +414,18 @@ int wiphy_register(struct wiphy *wiphy)
407 int i; 414 int i;
408 u16 ifmodes = wiphy->interface_modes; 415 u16 ifmodes = wiphy->interface_modes;
409 416
417 if (WARN_ON(wiphy->addresses && !wiphy->n_addresses))
418 return -EINVAL;
419
420 if (WARN_ON(wiphy->addresses &&
421 !is_zero_ether_addr(wiphy->perm_addr) &&
422 memcmp(wiphy->perm_addr, wiphy->addresses[0].addr,
423 ETH_ALEN)))
424 return -EINVAL;
425
426 if (wiphy->addresses)
427 memcpy(wiphy->perm_addr, wiphy->addresses[0].addr, ETH_ALEN);
428
410 /* sanity check ifmodes */ 429 /* sanity check ifmodes */
411 WARN_ON(!ifmodes); 430 WARN_ON(!ifmodes);
412 ifmodes &= ((1 << __NL80211_IFTYPE_AFTER_LAST) - 1) & ~1; 431 ifmodes &= ((1 << __NL80211_IFTYPE_AFTER_LAST) - 1) & ~1;
@@ -466,7 +485,7 @@ int wiphy_register(struct wiphy *wiphy)
466 /* set up regulatory info */ 485 /* set up regulatory info */
467 wiphy_update_regulatory(wiphy, NL80211_REGDOM_SET_BY_CORE); 486 wiphy_update_regulatory(wiphy, NL80211_REGDOM_SET_BY_CORE);
468 487
469 list_add(&rdev->list, &cfg80211_rdev_list); 488 list_add_rcu(&rdev->list, &cfg80211_rdev_list);
470 cfg80211_rdev_list_generation++; 489 cfg80211_rdev_list_generation++;
471 490
472 mutex_unlock(&cfg80211_mutex); 491 mutex_unlock(&cfg80211_mutex);
@@ -478,7 +497,7 @@ int wiphy_register(struct wiphy *wiphy)
478 if (IS_ERR(rdev->wiphy.debugfsdir)) 497 if (IS_ERR(rdev->wiphy.debugfsdir))
479 rdev->wiphy.debugfsdir = NULL; 498 rdev->wiphy.debugfsdir = NULL;
480 499
481 if (wiphy->custom_regulatory) { 500 if (wiphy->flags & WIPHY_FLAG_CUSTOM_REGULATORY) {
482 struct regulatory_request request; 501 struct regulatory_request request;
483 502
484 request.wiphy_idx = get_wiphy_idx(wiphy); 503 request.wiphy_idx = get_wiphy_idx(wiphy);
@@ -542,8 +561,9 @@ void wiphy_unregister(struct wiphy *wiphy)
542 * First remove the hardware from everywhere, this makes 561 * First remove the hardware from everywhere, this makes
543 * it impossible to find from userspace. 562 * it impossible to find from userspace.
544 */ 563 */
545 cfg80211_debugfs_rdev_del(rdev); 564 debugfs_remove_recursive(rdev->wiphy.debugfsdir);
546 list_del(&rdev->list); 565 list_del_rcu(&rdev->list);
566 synchronize_rcu();
547 567
548 /* 568 /*
549 * Try to grab rdev->mtx. If a command is still in progress, 569 * Try to grab rdev->mtx. If a command is still in progress,
@@ -565,7 +585,6 @@ void wiphy_unregister(struct wiphy *wiphy)
565 585
566 cfg80211_rdev_list_generation++; 586 cfg80211_rdev_list_generation++;
567 device_del(&rdev->wiphy.dev); 587 device_del(&rdev->wiphy.dev);
568 debugfs_remove(rdev->wiphy.debugfsdir);
569 588
570 mutex_unlock(&cfg80211_mutex); 589 mutex_unlock(&cfg80211_mutex);
571 590
@@ -626,6 +645,10 @@ static void wdev_cleanup_work(struct work_struct *work)
626 dev_put(wdev->netdev); 645 dev_put(wdev->netdev);
627} 646}
628 647
648static struct device_type wiphy_type = {
649 .name = "wlan",
650};
651
629static int cfg80211_netdev_notifier_call(struct notifier_block * nb, 652static int cfg80211_netdev_notifier_call(struct notifier_block * nb,
630 unsigned long state, 653 unsigned long state,
631 void *ndev) 654 void *ndev)
@@ -642,6 +665,9 @@ static int cfg80211_netdev_notifier_call(struct notifier_block * nb,
642 WARN_ON(wdev->iftype == NL80211_IFTYPE_UNSPECIFIED); 665 WARN_ON(wdev->iftype == NL80211_IFTYPE_UNSPECIFIED);
643 666
644 switch (state) { 667 switch (state) {
668 case NETDEV_POST_INIT:
669 SET_NETDEV_DEVTYPE(dev, &wiphy_type);
670 break;
645 case NETDEV_REGISTER: 671 case NETDEV_REGISTER:
646 /* 672 /*
647 * NB: cannot take rdev->mtx here because this may be 673 * NB: cannot take rdev->mtx here because this may be
@@ -652,8 +678,11 @@ static int cfg80211_netdev_notifier_call(struct notifier_block * nb,
652 INIT_WORK(&wdev->cleanup_work, wdev_cleanup_work); 678 INIT_WORK(&wdev->cleanup_work, wdev_cleanup_work);
653 INIT_LIST_HEAD(&wdev->event_list); 679 INIT_LIST_HEAD(&wdev->event_list);
654 spin_lock_init(&wdev->event_lock); 680 spin_lock_init(&wdev->event_lock);
681 INIT_LIST_HEAD(&wdev->action_registrations);
682 spin_lock_init(&wdev->action_registrations_lock);
683
655 mutex_lock(&rdev->devlist_mtx); 684 mutex_lock(&rdev->devlist_mtx);
656 list_add(&wdev->list, &rdev->netdev_list); 685 list_add_rcu(&wdev->list, &rdev->netdev_list);
657 rdev->devlist_generation++; 686 rdev->devlist_generation++;
658 /* can only change netns with wiphy */ 687 /* can only change netns with wiphy */
659 dev->features |= NETIF_F_NETNS_LOCAL; 688 dev->features |= NETIF_F_NETNS_LOCAL;
@@ -666,22 +695,31 @@ static int cfg80211_netdev_notifier_call(struct notifier_block * nb,
666 wdev->netdev = dev; 695 wdev->netdev = dev;
667 wdev->sme_state = CFG80211_SME_IDLE; 696 wdev->sme_state = CFG80211_SME_IDLE;
668 mutex_unlock(&rdev->devlist_mtx); 697 mutex_unlock(&rdev->devlist_mtx);
669#ifdef CONFIG_WIRELESS_EXT 698#ifdef CONFIG_CFG80211_WEXT
670 if (!dev->wireless_handlers)
671 dev->wireless_handlers = &cfg80211_wext_handler;
672 wdev->wext.default_key = -1; 699 wdev->wext.default_key = -1;
673 wdev->wext.default_mgmt_key = -1; 700 wdev->wext.default_mgmt_key = -1;
674 wdev->wext.connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; 701 wdev->wext.connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
675 wdev->wext.ps = wdev->wiphy->ps_default; 702#endif
676 wdev->wext.ps_timeout = 100; 703
704 if (wdev->wiphy->flags & WIPHY_FLAG_PS_ON_BY_DEFAULT)
705 wdev->ps = true;
706 else
707 wdev->ps = false;
708 wdev->ps_timeout = 100;
677 if (rdev->ops->set_power_mgmt) 709 if (rdev->ops->set_power_mgmt)
678 if (rdev->ops->set_power_mgmt(wdev->wiphy, dev, 710 if (rdev->ops->set_power_mgmt(wdev->wiphy, dev,
679 wdev->wext.ps, 711 wdev->ps,
680 wdev->wext.ps_timeout)) { 712 wdev->ps_timeout)) {
681 /* assume this means it's off */ 713 /* assume this means it's off */
682 wdev->wext.ps = false; 714 wdev->ps = false;
683 } 715 }
684#endif 716
717 if (!dev->ethtool_ops)
718 dev->ethtool_ops = &cfg80211_ethtool_ops;
719
720 if ((wdev->iftype == NL80211_IFTYPE_STATION ||
721 wdev->iftype == NL80211_IFTYPE_ADHOC) && !wdev->use_4addr)
722 dev->priv_flags |= IFF_DONT_BRIDGE;
685 break; 723 break;
686 case NETDEV_GOING_DOWN: 724 case NETDEV_GOING_DOWN:
687 switch (wdev->iftype) { 725 switch (wdev->iftype) {
@@ -690,7 +728,7 @@ static int cfg80211_netdev_notifier_call(struct notifier_block * nb,
690 break; 728 break;
691 case NL80211_IFTYPE_STATION: 729 case NL80211_IFTYPE_STATION:
692 wdev_lock(wdev); 730 wdev_lock(wdev);
693#ifdef CONFIG_WIRELESS_EXT 731#ifdef CONFIG_CFG80211_WEXT
694 kfree(wdev->wext.ie); 732 kfree(wdev->wext.ie);
695 wdev->wext.ie = NULL; 733 wdev->wext.ie = NULL;
696 wdev->wext.ie_len = 0; 734 wdev->wext.ie_len = 0;
@@ -707,7 +745,7 @@ static int cfg80211_netdev_notifier_call(struct notifier_block * nb,
707 break; 745 break;
708 case NETDEV_DOWN: 746 case NETDEV_DOWN:
709 dev_hold(dev); 747 dev_hold(dev);
710 schedule_work(&wdev->cleanup_work); 748 queue_work(cfg80211_wq, &wdev->cleanup_work);
711 break; 749 break;
712 case NETDEV_UP: 750 case NETDEV_UP:
713 /* 751 /*
@@ -722,9 +760,9 @@ static int cfg80211_netdev_notifier_call(struct notifier_block * nb,
722 mutex_unlock(&rdev->devlist_mtx); 760 mutex_unlock(&rdev->devlist_mtx);
723 dev_put(dev); 761 dev_put(dev);
724 } 762 }
725#ifdef CONFIG_WIRELESS_EXT
726 cfg80211_lock_rdev(rdev); 763 cfg80211_lock_rdev(rdev);
727 mutex_lock(&rdev->devlist_mtx); 764 mutex_lock(&rdev->devlist_mtx);
765#ifdef CONFIG_CFG80211_WEXT
728 wdev_lock(wdev); 766 wdev_lock(wdev);
729 switch (wdev->iftype) { 767 switch (wdev->iftype) {
730 case NL80211_IFTYPE_ADHOC: 768 case NL80211_IFTYPE_ADHOC:
@@ -737,10 +775,10 @@ static int cfg80211_netdev_notifier_call(struct notifier_block * nb,
737 break; 775 break;
738 } 776 }
739 wdev_unlock(wdev); 777 wdev_unlock(wdev);
778#endif
740 rdev->opencount++; 779 rdev->opencount++;
741 mutex_unlock(&rdev->devlist_mtx); 780 mutex_unlock(&rdev->devlist_mtx);
742 cfg80211_unlock_rdev(rdev); 781 cfg80211_unlock_rdev(rdev);
743#endif
744 break; 782 break;
745 case NETDEV_UNREGISTER: 783 case NETDEV_UNREGISTER:
746 /* 784 /*
@@ -758,13 +796,22 @@ static int cfg80211_netdev_notifier_call(struct notifier_block * nb,
758 */ 796 */
759 if (!list_empty(&wdev->list)) { 797 if (!list_empty(&wdev->list)) {
760 sysfs_remove_link(&dev->dev.kobj, "phy80211"); 798 sysfs_remove_link(&dev->dev.kobj, "phy80211");
761 list_del_init(&wdev->list); 799 list_del_rcu(&wdev->list);
762 rdev->devlist_generation++; 800 rdev->devlist_generation++;
763#ifdef CONFIG_WIRELESS_EXT 801 cfg80211_mlme_purge_actions(wdev);
802#ifdef CONFIG_CFG80211_WEXT
764 kfree(wdev->wext.keys); 803 kfree(wdev->wext.keys);
765#endif 804#endif
766 } 805 }
767 mutex_unlock(&rdev->devlist_mtx); 806 mutex_unlock(&rdev->devlist_mtx);
807 /*
808 * synchronise (so that we won't find this netdev
809 * from other code any more) and then clear the list
810 * head so that the above code can safely check for
811 * !list_empty() to avoid double-cleanup.
812 */
813 synchronize_rcu();
814 INIT_LIST_HEAD(&wdev->list);
768 break; 815 break;
769 case NETDEV_PRE_UP: 816 case NETDEV_PRE_UP:
770 if (!(wdev->wiphy->interface_modes & BIT(wdev->iftype))) 817 if (!(wdev->wiphy->interface_modes & BIT(wdev->iftype)))
@@ -825,8 +872,14 @@ static int __init cfg80211_init(void)
825 if (err) 872 if (err)
826 goto out_fail_reg; 873 goto out_fail_reg;
827 874
875 cfg80211_wq = create_singlethread_workqueue("cfg80211");
876 if (!cfg80211_wq)
877 goto out_fail_wq;
878
828 return 0; 879 return 0;
829 880
881out_fail_wq:
882 regulatory_exit();
830out_fail_reg: 883out_fail_reg:
831 debugfs_remove(ieee80211_debugfs_dir); 884 debugfs_remove(ieee80211_debugfs_dir);
832out_fail_nl80211: 885out_fail_nl80211:
@@ -848,5 +901,6 @@ static void cfg80211_exit(void)
848 wiphy_sysfs_exit(); 901 wiphy_sysfs_exit();
849 regulatory_exit(); 902 regulatory_exit();
850 unregister_pernet_device(&cfg80211_pernet_ops); 903 unregister_pernet_device(&cfg80211_pernet_ops);
904 destroy_workqueue(cfg80211_wq);
851} 905}
852module_exit(cfg80211_exit); 906module_exit(cfg80211_exit);
diff --git a/net/wireless/core.h b/net/wireless/core.h
index 68b321997d4c..d52da913145a 100644
--- a/net/wireless/core.h
+++ b/net/wireless/core.h
@@ -1,7 +1,7 @@
1/* 1/*
2 * Wireless configuration interface internals. 2 * Wireless configuration interface internals.
3 * 3 *
4 * Copyright 2006-2009 Johannes Berg <johannes@sipsolutions.net> 4 * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
5 */ 5 */
6#ifndef __NET_WIRELESS_CORE_H 6#ifndef __NET_WIRELESS_CORE_H
7#define __NET_WIRELESS_CORE_H 7#define __NET_WIRELESS_CORE_H
@@ -48,6 +48,7 @@ struct cfg80211_registered_device {
48 48
49 /* associate netdev list */ 49 /* associate netdev list */
50 struct mutex devlist_mtx; 50 struct mutex devlist_mtx;
51 /* protected by devlist_mtx or RCU */
51 struct list_head netdev_list; 52 struct list_head netdev_list;
52 int devlist_generation; 53 int devlist_generation;
53 int opencount; /* also protected by devlist_mtx */ 54 int opencount; /* also protected by devlist_mtx */
@@ -72,17 +73,6 @@ struct cfg80211_registered_device {
72 /* current channel */ 73 /* current channel */
73 struct ieee80211_channel *channel; 74 struct ieee80211_channel *channel;
74 75
75#ifdef CONFIG_CFG80211_DEBUGFS
76 /* Debugfs entries */
77 struct wiphy_debugfsdentries {
78 struct dentry *rts_threshold;
79 struct dentry *fragmentation_threshold;
80 struct dentry *short_retry_limit;
81 struct dentry *long_retry_limit;
82 struct dentry *ht40allow_map;
83 } debugfs;
84#endif
85
86 /* must be last because of the way we do wiphy_priv(), 76 /* must be last because of the way we do wiphy_priv(),
87 * and it should at least be aligned to NETDEV_ALIGN */ 77 * and it should at least be aligned to NETDEV_ALIGN */
88 struct wiphy wiphy __attribute__((__aligned__(NETDEV_ALIGN))); 78 struct wiphy wiphy __attribute__((__aligned__(NETDEV_ALIGN)));
@@ -102,6 +92,8 @@ bool wiphy_idx_valid(int wiphy_idx)
102 return (wiphy_idx >= 0); 92 return (wiphy_idx >= 0);
103} 93}
104 94
95
96extern struct workqueue_struct *cfg80211_wq;
105extern struct mutex cfg80211_mutex; 97extern struct mutex cfg80211_mutex;
106extern struct list_head cfg80211_rdev_list; 98extern struct list_head cfg80211_rdev_list;
107extern int cfg80211_rdev_list_generation; 99extern int cfg80211_rdev_list_generation;
@@ -120,7 +112,8 @@ struct cfg80211_internal_bss {
120 unsigned long ts; 112 unsigned long ts;
121 struct kref ref; 113 struct kref ref;
122 atomic_t hold; 114 atomic_t hold;
123 bool ies_allocated; 115 bool beacon_ies_allocated;
116 bool proberesp_ies_allocated;
124 117
125 /* must be last because of priv member */ 118 /* must be last because of priv member */
126 struct cfg80211_bss pub; 119 struct cfg80211_bss pub;
@@ -284,6 +277,8 @@ int cfg80211_join_ibss(struct cfg80211_registered_device *rdev,
284 struct cfg80211_ibss_params *params, 277 struct cfg80211_ibss_params *params,
285 struct cfg80211_cached_keys *connkeys); 278 struct cfg80211_cached_keys *connkeys);
286void cfg80211_clear_ibss(struct net_device *dev, bool nowext); 279void cfg80211_clear_ibss(struct net_device *dev, bool nowext);
280int __cfg80211_leave_ibss(struct cfg80211_registered_device *rdev,
281 struct net_device *dev, bool nowext);
287int cfg80211_leave_ibss(struct cfg80211_registered_device *rdev, 282int cfg80211_leave_ibss(struct cfg80211_registered_device *rdev,
288 struct net_device *dev, bool nowext); 283 struct net_device *dev, bool nowext);
289void __cfg80211_ibss_joined(struct net_device *dev, const u8 *bssid); 284void __cfg80211_ibss_joined(struct net_device *dev, const u8 *bssid);
@@ -334,6 +329,15 @@ void __cfg80211_connect_result(struct net_device *dev, const u8 *bssid,
334 const u8 *resp_ie, size_t resp_ie_len, 329 const u8 *resp_ie, size_t resp_ie_len,
335 u16 status, bool wextev, 330 u16 status, bool wextev,
336 struct cfg80211_bss *bss); 331 struct cfg80211_bss *bss);
332int cfg80211_mlme_register_action(struct wireless_dev *wdev, u32 snd_pid,
333 const u8 *match_data, int match_len);
334void cfg80211_mlme_unregister_actions(struct wireless_dev *wdev, u32 nlpid);
335void cfg80211_mlme_purge_actions(struct wireless_dev *wdev);
336int cfg80211_mlme_action(struct cfg80211_registered_device *rdev,
337 struct net_device *dev,
338 struct ieee80211_channel *chan,
339 enum nl80211_channel_type channel_type,
340 const u8 *buf, size_t len, u64 *cookie);
337 341
338/* SME */ 342/* SME */
339int __cfg80211_connect(struct cfg80211_registered_device *rdev, 343int __cfg80211_connect(struct cfg80211_registered_device *rdev,
@@ -381,10 +385,15 @@ void cfg80211_process_rdev_events(struct cfg80211_registered_device *rdev);
381struct ieee80211_channel * 385struct ieee80211_channel *
382rdev_fixed_channel(struct cfg80211_registered_device *rdev, 386rdev_fixed_channel(struct cfg80211_registered_device *rdev,
383 struct wireless_dev *for_wdev); 387 struct wireless_dev *for_wdev);
388struct ieee80211_channel *
389rdev_freq_to_chan(struct cfg80211_registered_device *rdev,
390 int freq, enum nl80211_channel_type channel_type);
384int rdev_set_freq(struct cfg80211_registered_device *rdev, 391int rdev_set_freq(struct cfg80211_registered_device *rdev,
385 struct wireless_dev *for_wdev, 392 struct wireless_dev *for_wdev,
386 int freq, enum nl80211_channel_type channel_type); 393 int freq, enum nl80211_channel_type channel_type);
387 394
395u16 cfg80211_calculate_bitrate(struct rate_info *rate);
396
388#ifdef CONFIG_CFG80211_DEVELOPER_WARNINGS 397#ifdef CONFIG_CFG80211_DEVELOPER_WARNINGS
389#define CFG80211_DEV_WARN_ON(cond) WARN_ON(cond) 398#define CFG80211_DEV_WARN_ON(cond) WARN_ON(cond)
390#else 399#else
diff --git a/net/wireless/db.txt b/net/wireless/db.txt
new file mode 100644
index 000000000000..a2fc3a09ccdc
--- /dev/null
+++ b/net/wireless/db.txt
@@ -0,0 +1,17 @@
1#
2# This file is a placeholder to prevent accidental build breakage if someone
3# enables CONFIG_CFG80211_INTERNAL_REGDB. Almost no one actually needs to
4# enable that build option.
5#
6# You should be using CRDA instead. It is even better if you use the CRDA
7# package provided by your distribution, since they will probably keep it
8# up-to-date on your behalf.
9#
10# If you _really_ intend to use CONFIG_CFG80211_INTERNAL_REGDB then you will
11# need to replace this file with one containing appropriately formatted
12# regulatory rules that cover the regulatory domains you will be using. Your
13# best option is to extract the db.txt file from the wireless-regdb git
14# repository:
15#
16# git://git.kernel.org/pub/scm/linux/kernel/git/linville/wireless-regdb.git
17#
diff --git a/net/wireless/debugfs.c b/net/wireless/debugfs.c
index 13d93d84f902..a4991a3efec0 100644
--- a/net/wireless/debugfs.c
+++ b/net/wireless/debugfs.c
@@ -9,6 +9,7 @@
9 * published by the Free Software Foundation. 9 * published by the Free Software Foundation.
10 */ 10 */
11 11
12#include <linux/slab.h>
12#include "core.h" 13#include "core.h"
13#include "debugfs.h" 14#include "debugfs.h"
14 15
@@ -104,11 +105,7 @@ static const struct file_operations ht40allow_map_ops = {
104}; 105};
105 106
106#define DEBUGFS_ADD(name) \ 107#define DEBUGFS_ADD(name) \
107 rdev->debugfs.name = debugfs_create_file(#name, S_IRUGO, phyd, \ 108 debugfs_create_file(#name, S_IRUGO, phyd, &rdev->wiphy, &name## _ops);
108 &rdev->wiphy, &name## _ops);
109#define DEBUGFS_DEL(name) \
110 debugfs_remove(rdev->debugfs.name); \
111 rdev->debugfs.name = NULL;
112 109
113void cfg80211_debugfs_rdev_add(struct cfg80211_registered_device *rdev) 110void cfg80211_debugfs_rdev_add(struct cfg80211_registered_device *rdev)
114{ 111{
@@ -120,12 +117,3 @@ void cfg80211_debugfs_rdev_add(struct cfg80211_registered_device *rdev)
120 DEBUGFS_ADD(long_retry_limit); 117 DEBUGFS_ADD(long_retry_limit);
121 DEBUGFS_ADD(ht40allow_map); 118 DEBUGFS_ADD(ht40allow_map);
122} 119}
123
124void cfg80211_debugfs_rdev_del(struct cfg80211_registered_device *rdev)
125{
126 DEBUGFS_DEL(rts_threshold);
127 DEBUGFS_DEL(fragmentation_threshold);
128 DEBUGFS_DEL(short_retry_limit);
129 DEBUGFS_DEL(long_retry_limit);
130 DEBUGFS_DEL(ht40allow_map);
131}
diff --git a/net/wireless/debugfs.h b/net/wireless/debugfs.h
index 6419b6d6ce3e..74fdd3811427 100644
--- a/net/wireless/debugfs.h
+++ b/net/wireless/debugfs.h
@@ -3,12 +3,9 @@
3 3
4#ifdef CONFIG_CFG80211_DEBUGFS 4#ifdef CONFIG_CFG80211_DEBUGFS
5void cfg80211_debugfs_rdev_add(struct cfg80211_registered_device *rdev); 5void cfg80211_debugfs_rdev_add(struct cfg80211_registered_device *rdev);
6void cfg80211_debugfs_rdev_del(struct cfg80211_registered_device *rdev);
7#else 6#else
8static inline 7static inline
9void cfg80211_debugfs_rdev_add(struct cfg80211_registered_device *rdev) {} 8void cfg80211_debugfs_rdev_add(struct cfg80211_registered_device *rdev) {}
10static inline
11void cfg80211_debugfs_rdev_del(struct cfg80211_registered_device *rdev) {}
12#endif 9#endif
13 10
14#endif /* __CFG80211_DEBUGFS_H */ 11#endif /* __CFG80211_DEBUGFS_H */
diff --git a/net/wireless/ethtool.c b/net/wireless/ethtool.c
new file mode 100644
index 000000000000..ca4c825be93d
--- /dev/null
+++ b/net/wireless/ethtool.c
@@ -0,0 +1,45 @@
1#include <linux/utsname.h>
2#include <net/cfg80211.h>
3#include "ethtool.h"
4
5static void cfg80211_get_drvinfo(struct net_device *dev,
6 struct ethtool_drvinfo *info)
7{
8 struct wireless_dev *wdev = dev->ieee80211_ptr;
9
10 strlcpy(info->driver, wiphy_dev(wdev->wiphy)->driver->name,
11 sizeof(info->driver));
12
13 strlcpy(info->version, init_utsname()->release, sizeof(info->version));
14
15 if (wdev->wiphy->fw_version[0])
16 strncpy(info->fw_version, wdev->wiphy->fw_version,
17 sizeof(info->fw_version));
18 else
19 strncpy(info->fw_version, "N/A", sizeof(info->fw_version));
20
21 strlcpy(info->bus_info, dev_name(wiphy_dev(wdev->wiphy)),
22 sizeof(info->bus_info));
23}
24
25static int cfg80211_get_regs_len(struct net_device *dev)
26{
27 /* For now, return 0... */
28 return 0;
29}
30
31static void cfg80211_get_regs(struct net_device *dev, struct ethtool_regs *regs,
32 void *data)
33{
34 struct wireless_dev *wdev = dev->ieee80211_ptr;
35
36 regs->version = wdev->wiphy->hw_version;
37 regs->len = 0;
38}
39
40const struct ethtool_ops cfg80211_ethtool_ops = {
41 .get_drvinfo = cfg80211_get_drvinfo,
42 .get_regs_len = cfg80211_get_regs_len,
43 .get_regs = cfg80211_get_regs,
44 .get_link = ethtool_op_get_link,
45};
diff --git a/net/wireless/ethtool.h b/net/wireless/ethtool.h
new file mode 100644
index 000000000000..695ecad20bd6
--- /dev/null
+++ b/net/wireless/ethtool.h
@@ -0,0 +1,6 @@
1#ifndef __CFG80211_ETHTOOL__
2#define __CFG80211_ETHTOOL__
3
4extern const struct ethtool_ops cfg80211_ethtool_ops;
5
6#endif /* __CFG80211_ETHTOOL__ */
diff --git a/net/wireless/genregdb.awk b/net/wireless/genregdb.awk
new file mode 100644
index 000000000000..3cc9e69880a8
--- /dev/null
+++ b/net/wireless/genregdb.awk
@@ -0,0 +1,118 @@
1#!/usr/bin/awk -f
2#
3# genregdb.awk -- generate regdb.c from db.txt
4#
5# Actually, it reads from stdin (presumed to be db.txt) and writes
6# to stdout (presumed to be regdb.c), but close enough...
7#
8# Copyright 2009 John W. Linville <linville@tuxdriver.com>
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.
13#
14
15BEGIN {
16 active = 0
17 rules = 0;
18 print "/*"
19 print " * DO NOT EDIT -- file generated from data in db.txt"
20 print " */"
21 print ""
22 print "#include <linux/nl80211.h>"
23 print "#include <net/cfg80211.h>"
24 print ""
25 regdb = "const struct ieee80211_regdomain *reg_regdb[] = {\n"
26}
27
28/^[ \t]*#/ {
29 # Ignore
30}
31
32!active && /^[ \t]*$/ {
33 # Ignore
34}
35
36!active && /country/ {
37 country=$2
38 sub(/:/, "", country)
39 printf "static const struct ieee80211_regdomain regdom_%s = {\n", country
40 printf "\t.alpha2 = \"%s\",\n", country
41 printf "\t.reg_rules = {\n"
42 active = 1
43 regdb = regdb "\t&regdom_" country ",\n"
44}
45
46active && /^[ \t]*\(/ {
47 start = $1
48 sub(/\(/, "", start)
49 end = $3
50 bw = $5
51 sub(/\),/, "", bw)
52 gain = $6
53 sub(/\(/, "", gain)
54 sub(/,/, "", gain)
55 power = $7
56 sub(/\)/, "", power)
57 sub(/,/, "", power)
58 # power might be in mW...
59 units = $8
60 sub(/\)/, "", units)
61 sub(/,/, "", units)
62 if (units == "mW") {
63 if (power == 100) {
64 power = 20
65 } else if (power == 200) {
66 power = 23
67 } else if (power == 500) {
68 power = 27
69 } else if (power == 1000) {
70 power = 30
71 } else {
72 print "Unknown power value in database!"
73 }
74 }
75 flagstr = ""
76 for (i=8; i<=NF; i++)
77 flagstr = flagstr $i
78 split(flagstr, flagarray, ",")
79 flags = ""
80 for (arg in flagarray) {
81 if (flagarray[arg] == "NO-OFDM") {
82 flags = flags "\n\t\t\tNL80211_RRF_NO_OFDM | "
83 } else if (flagarray[arg] == "NO-CCK") {
84 flags = flags "\n\t\t\tNL80211_RRF_NO_CCK | "
85 } else if (flagarray[arg] == "NO-INDOOR") {
86 flags = flags "\n\t\t\tNL80211_RRF_NO_INDOOR | "
87 } else if (flagarray[arg] == "NO-OUTDOOR") {
88 flags = flags "\n\t\t\tNL80211_RRF_NO_OUTDOOR | "
89 } else if (flagarray[arg] == "DFS") {
90 flags = flags "\n\t\t\tNL80211_RRF_DFS | "
91 } else if (flagarray[arg] == "PTP-ONLY") {
92 flags = flags "\n\t\t\tNL80211_RRF_PTP_ONLY | "
93 } else if (flagarray[arg] == "PTMP-ONLY") {
94 flags = flags "\n\t\t\tNL80211_RRF_PTMP_ONLY | "
95 } else if (flagarray[arg] == "PASSIVE-SCAN") {
96 flags = flags "\n\t\t\tNL80211_RRF_PASSIVE_SCAN | "
97 } else if (flagarray[arg] == "NO-IBSS") {
98 flags = flags "\n\t\t\tNL80211_RRF_NO_IBSS | "
99 }
100 }
101 flags = flags "0"
102 printf "\t\tREG_RULE(%d, %d, %d, %d, %d, %s),\n", start, end, bw, gain, power, flags
103 rules++
104}
105
106active && /^[ \t]*$/ {
107 active = 0
108 printf "\t},\n"
109 printf "\t.n_reg_rules = %d\n", rules
110 printf "};\n\n"
111 rules = 0;
112}
113
114END {
115 print regdb "};"
116 print ""
117 print "int reg_regdb_size = ARRAY_SIZE(reg_regdb);"
118}
diff --git a/net/wireless/ibss.c b/net/wireless/ibss.c
index c88338911979..6a5acf750174 100644
--- a/net/wireless/ibss.c
+++ b/net/wireless/ibss.c
@@ -6,6 +6,7 @@
6 6
7#include <linux/etherdevice.h> 7#include <linux/etherdevice.h>
8#include <linux/if_arp.h> 8#include <linux/if_arp.h>
9#include <linux/slab.h>
9#include <net/cfg80211.h> 10#include <net/cfg80211.h>
10#include "wext-compat.h" 11#include "wext-compat.h"
11#include "nl80211.h" 12#include "nl80211.h"
@@ -15,7 +16,7 @@ void __cfg80211_ibss_joined(struct net_device *dev, const u8 *bssid)
15{ 16{
16 struct wireless_dev *wdev = dev->ieee80211_ptr; 17 struct wireless_dev *wdev = dev->ieee80211_ptr;
17 struct cfg80211_bss *bss; 18 struct cfg80211_bss *bss;
18#ifdef CONFIG_WIRELESS_EXT 19#ifdef CONFIG_CFG80211_WEXT
19 union iwreq_data wrqu; 20 union iwreq_data wrqu;
20#endif 21#endif
21 22
@@ -44,7 +45,7 @@ void __cfg80211_ibss_joined(struct net_device *dev, const u8 *bssid)
44 45
45 nl80211_send_ibss_bssid(wiphy_to_dev(wdev->wiphy), dev, bssid, 46 nl80211_send_ibss_bssid(wiphy_to_dev(wdev->wiphy), dev, bssid,
46 GFP_KERNEL); 47 GFP_KERNEL);
47#ifdef CONFIG_WIRELESS_EXT 48#ifdef CONFIG_CFG80211_WEXT
48 memset(&wrqu, 0, sizeof(wrqu)); 49 memset(&wrqu, 0, sizeof(wrqu));
49 memcpy(wrqu.ap_addr.sa_data, bssid, ETH_ALEN); 50 memcpy(wrqu.ap_addr.sa_data, bssid, ETH_ALEN);
50 wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL); 51 wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL);
@@ -70,7 +71,7 @@ void cfg80211_ibss_joined(struct net_device *dev, const u8 *bssid, gfp_t gfp)
70 spin_lock_irqsave(&wdev->event_lock, flags); 71 spin_lock_irqsave(&wdev->event_lock, flags);
71 list_add_tail(&ev->list, &wdev->event_list); 72 list_add_tail(&ev->list, &wdev->event_list);
72 spin_unlock_irqrestore(&wdev->event_lock, flags); 73 spin_unlock_irqrestore(&wdev->event_lock, flags);
73 schedule_work(&rdev->event_work); 74 queue_work(cfg80211_wq, &rdev->event_work);
74} 75}
75EXPORT_SYMBOL(cfg80211_ibss_joined); 76EXPORT_SYMBOL(cfg80211_ibss_joined);
76 77
@@ -96,7 +97,7 @@ int __cfg80211_join_ibss(struct cfg80211_registered_device *rdev,
96 kfree(wdev->connect_keys); 97 kfree(wdev->connect_keys);
97 wdev->connect_keys = connkeys; 98 wdev->connect_keys = connkeys;
98 99
99#ifdef CONFIG_WIRELESS_EXT 100#ifdef CONFIG_CFG80211_WEXT
100 wdev->wext.ibss.channel = params->channel; 101 wdev->wext.ibss.channel = params->channel;
101#endif 102#endif
102 err = rdev->ops->join_ibss(&rdev->wiphy, dev, params); 103 err = rdev->ops->join_ibss(&rdev->wiphy, dev, params);
@@ -154,7 +155,7 @@ static void __cfg80211_clear_ibss(struct net_device *dev, bool nowext)
154 155
155 wdev->current_bss = NULL; 156 wdev->current_bss = NULL;
156 wdev->ssid_len = 0; 157 wdev->ssid_len = 0;
157#ifdef CONFIG_WIRELESS_EXT 158#ifdef CONFIG_CFG80211_WEXT
158 if (!nowext) 159 if (!nowext)
159 wdev->wext.ibss.ssid_len = 0; 160 wdev->wext.ibss.ssid_len = 0;
160#endif 161#endif
@@ -169,8 +170,8 @@ void cfg80211_clear_ibss(struct net_device *dev, bool nowext)
169 wdev_unlock(wdev); 170 wdev_unlock(wdev);
170} 171}
171 172
172static int __cfg80211_leave_ibss(struct cfg80211_registered_device *rdev, 173int __cfg80211_leave_ibss(struct cfg80211_registered_device *rdev,
173 struct net_device *dev, bool nowext) 174 struct net_device *dev, bool nowext)
174{ 175{
175 struct wireless_dev *wdev = dev->ieee80211_ptr; 176 struct wireless_dev *wdev = dev->ieee80211_ptr;
176 int err; 177 int err;
@@ -203,7 +204,7 @@ int cfg80211_leave_ibss(struct cfg80211_registered_device *rdev,
203 return err; 204 return err;
204} 205}
205 206
206#ifdef CONFIG_WIRELESS_EXT 207#ifdef CONFIG_CFG80211_WEXT
207int cfg80211_ibss_wext_join(struct cfg80211_registered_device *rdev, 208int cfg80211_ibss_wext_join(struct cfg80211_registered_device *rdev,
208 struct wireless_dev *wdev) 209 struct wireless_dev *wdev)
209{ 210{
diff --git a/net/wireless/lib80211_crypt_ccmp.c b/net/wireless/lib80211_crypt_ccmp.c
index 2301dc1edc4c..b7fa31d5fd13 100644
--- a/net/wireless/lib80211_crypt_ccmp.c
+++ b/net/wireless/lib80211_crypt_ccmp.c
@@ -237,7 +237,6 @@ static int lib80211_ccmp_encrypt(struct sk_buff *skb, int hdr_len, void *priv)
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);
241 hdr = (struct ieee80211_hdr *)skb->data; 240 hdr = (struct ieee80211_hdr *)skb->data;
242 ccmp_init_blocks(key->tfm, hdr, key->tx_pn, data_len, b0, b, s0); 241 ccmp_init_blocks(key->tfm, hdr, key->tx_pn, data_len, b0, b, s0);
243 242
@@ -257,6 +256,7 @@ static int lib80211_ccmp_encrypt(struct sk_buff *skb, int hdr_len, void *priv)
257 pos += len; 256 pos += len;
258 } 257 }
259 258
259 mic = skb_put(skb, CCMP_MIC_LEN);
260 for (i = 0; i < CCMP_MIC_LEN; i++) 260 for (i = 0; i < CCMP_MIC_LEN; i++)
261 mic[i] = b[i] ^ s0[i]; 261 mic[i] = b[i] ^ s0[i];
262 262
diff --git a/net/wireless/lib80211_crypt_tkip.c b/net/wireless/lib80211_crypt_tkip.c
index c36287399d7e..8cbdb32ff316 100644
--- a/net/wireless/lib80211_crypt_tkip.c
+++ b/net/wireless/lib80211_crypt_tkip.c
@@ -36,6 +36,8 @@ MODULE_AUTHOR("Jouni Malinen");
36MODULE_DESCRIPTION("lib80211 crypt: TKIP"); 36MODULE_DESCRIPTION("lib80211 crypt: TKIP");
37MODULE_LICENSE("GPL"); 37MODULE_LICENSE("GPL");
38 38
39#define TKIP_HDR_LEN 8
40
39struct lib80211_tkip_data { 41struct lib80211_tkip_data {
40#define TKIP_KEY_LEN 32 42#define TKIP_KEY_LEN 32
41 u8 key[TKIP_KEY_LEN]; 43 u8 key[TKIP_KEY_LEN];
@@ -314,13 +316,12 @@ static int lib80211_tkip_hdr(struct sk_buff *skb, int hdr_len,
314 u8 * rc4key, int keylen, void *priv) 316 u8 * rc4key, int keylen, void *priv)
315{ 317{
316 struct lib80211_tkip_data *tkey = priv; 318 struct lib80211_tkip_data *tkey = priv;
317 int len;
318 u8 *pos; 319 u8 *pos;
319 struct ieee80211_hdr *hdr; 320 struct ieee80211_hdr *hdr;
320 321
321 hdr = (struct ieee80211_hdr *)skb->data; 322 hdr = (struct ieee80211_hdr *)skb->data;
322 323
323 if (skb_headroom(skb) < 8 || skb->len < hdr_len) 324 if (skb_headroom(skb) < TKIP_HDR_LEN || skb->len < hdr_len)
324 return -1; 325 return -1;
325 326
326 if (rc4key == NULL || keylen < 16) 327 if (rc4key == NULL || keylen < 16)
@@ -333,9 +334,8 @@ static int lib80211_tkip_hdr(struct sk_buff *skb, int hdr_len,
333 } 334 }
334 tkip_mixing_phase2(rc4key, tkey->key, tkey->tx_ttak, tkey->tx_iv16); 335 tkip_mixing_phase2(rc4key, tkey->key, tkey->tx_ttak, tkey->tx_iv16);
335 336
336 len = skb->len - hdr_len; 337 pos = skb_push(skb, TKIP_HDR_LEN);
337 pos = skb_push(skb, 8); 338 memmove(pos, pos + TKIP_HDR_LEN, hdr_len);
338 memmove(pos, pos + 8, hdr_len);
339 pos += hdr_len; 339 pos += hdr_len;
340 340
341 *pos++ = *rc4key; 341 *pos++ = *rc4key;
@@ -353,7 +353,7 @@ static int lib80211_tkip_hdr(struct sk_buff *skb, int hdr_len,
353 tkey->tx_iv32++; 353 tkey->tx_iv32++;
354 } 354 }
355 355
356 return 8; 356 return TKIP_HDR_LEN;
357} 357}
358 358
359static int lib80211_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)
@@ -384,9 +384,8 @@ static int lib80211_tkip_encrypt(struct sk_buff *skb, int hdr_len, void *priv)
384 if ((lib80211_tkip_hdr(skb, hdr_len, rc4key, 16, priv)) < 0) 384 if ((lib80211_tkip_hdr(skb, hdr_len, rc4key, 16, priv)) < 0)
385 return -1; 385 return -1;
386 386
387 icv = skb_put(skb, 4);
388
389 crc = ~crc32_le(~0, pos, len); 387 crc = ~crc32_le(~0, pos, len);
388 icv = skb_put(skb, 4);
390 icv[0] = crc; 389 icv[0] = crc;
391 icv[1] = crc >> 8; 390 icv[1] = crc >> 8;
392 icv[2] = crc >> 16; 391 icv[2] = crc >> 16;
@@ -434,7 +433,7 @@ static int lib80211_tkip_decrypt(struct sk_buff *skb, int hdr_len, void *priv)
434 return -1; 433 return -1;
435 } 434 }
436 435
437 if (skb->len < hdr_len + 8 + 4) 436 if (skb->len < hdr_len + TKIP_HDR_LEN + 4)
438 return -1; 437 return -1;
439 438
440 pos = skb->data + hdr_len; 439 pos = skb->data + hdr_len;
@@ -462,7 +461,7 @@ static int lib80211_tkip_decrypt(struct sk_buff *skb, int hdr_len, void *priv)
462 } 461 }
463 iv16 = (pos[0] << 8) | pos[2]; 462 iv16 = (pos[0] << 8) | pos[2];
464 iv32 = pos[4] | (pos[5] << 8) | (pos[6] << 16) | (pos[7] << 24); 463 iv32 = pos[4] | (pos[5] << 8) | (pos[6] << 16) | (pos[7] << 24);
465 pos += 8; 464 pos += TKIP_HDR_LEN;
466 465
467 if (tkip_replay_check(iv32, iv16, tkey->rx_iv32, tkey->rx_iv16)) { 466 if (tkip_replay_check(iv32, iv16, tkey->rx_iv32, tkey->rx_iv16)) {
468#ifdef CONFIG_LIB80211_DEBUG 467#ifdef CONFIG_LIB80211_DEBUG
@@ -523,8 +522,8 @@ static int lib80211_tkip_decrypt(struct sk_buff *skb, int hdr_len, void *priv)
523 tkey->rx_iv16_new = iv16; 522 tkey->rx_iv16_new = iv16;
524 523
525 /* Remove IV and ICV */ 524 /* Remove IV and ICV */
526 memmove(skb->data + 8, skb->data, hdr_len); 525 memmove(skb->data + TKIP_HDR_LEN, skb->data, hdr_len);
527 skb_pull(skb, 8); 526 skb_pull(skb, TKIP_HDR_LEN);
528 skb_trim(skb, skb->len - 4); 527 skb_trim(skb, skb->len - 4);
529 528
530 return keyidx; 529 return keyidx;
diff --git a/net/wireless/mlme.c b/net/wireless/mlme.c
index 0a6b7a0eca6b..22139fa46115 100644
--- a/net/wireless/mlme.c
+++ b/net/wireless/mlme.c
@@ -8,6 +8,7 @@
8#include <linux/module.h> 8#include <linux/module.h>
9#include <linux/netdevice.h> 9#include <linux/netdevice.h>
10#include <linux/nl80211.h> 10#include <linux/nl80211.h>
11#include <linux/slab.h>
11#include <linux/wireless.h> 12#include <linux/wireless.h>
12#include <net/cfg80211.h> 13#include <net/cfg80211.h>
13#include <net/iw_handler.h> 14#include <net/iw_handler.h>
@@ -62,7 +63,6 @@ void cfg80211_send_rx_assoc(struct net_device *dev, const u8 *buf, size_t len)
62 u8 *ie = mgmt->u.assoc_resp.variable; 63 u8 *ie = mgmt->u.assoc_resp.variable;
63 int i, ieoffs = offsetof(struct ieee80211_mgmt, u.assoc_resp.variable); 64 int i, ieoffs = offsetof(struct ieee80211_mgmt, u.assoc_resp.variable);
64 struct cfg80211_internal_bss *bss = NULL; 65 struct cfg80211_internal_bss *bss = NULL;
65 bool need_connect_result = true;
66 66
67 wdev_lock(wdev); 67 wdev_lock(wdev);
68 68
@@ -94,10 +94,20 @@ void cfg80211_send_rx_assoc(struct net_device *dev, const u8 *buf, size_t len)
94 } 94 }
95 } 95 }
96 96
97 WARN_ON(!bss); 97 /*
98 * We might be coming here because the driver reported
99 * a successful association at the same time as the
100 * user requested a deauth. In that case, we will have
101 * removed the BSS from the auth_bsses list due to the
102 * deauth request when the assoc response makes it. If
103 * the two code paths acquire the lock the other way
104 * around, that's just the standard situation of a
105 * deauth being requested while connected.
106 */
107 if (!bss)
108 goto out;
98 } else if (wdev->conn) { 109 } else if (wdev->conn) {
99 cfg80211_sme_failed_assoc(wdev); 110 cfg80211_sme_failed_assoc(wdev);
100 need_connect_result = false;
101 /* 111 /*
102 * do not call connect_result() now because the 112 * do not call connect_result() now because the
103 * sme will schedule work that does it later. 113 * sme will schedule work that does it later.
@@ -130,7 +140,7 @@ void cfg80211_send_rx_assoc(struct net_device *dev, const u8 *buf, size_t len)
130} 140}
131EXPORT_SYMBOL(cfg80211_send_rx_assoc); 141EXPORT_SYMBOL(cfg80211_send_rx_assoc);
132 142
133static void __cfg80211_send_deauth(struct net_device *dev, 143void __cfg80211_send_deauth(struct net_device *dev,
134 const u8 *buf, size_t len) 144 const u8 *buf, size_t len)
135{ 145{
136 struct wireless_dev *wdev = dev->ieee80211_ptr; 146 struct wireless_dev *wdev = dev->ieee80211_ptr;
@@ -139,25 +149,23 @@ static void __cfg80211_send_deauth(struct net_device *dev,
139 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)buf; 149 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)buf;
140 const u8 *bssid = mgmt->bssid; 150 const u8 *bssid = mgmt->bssid;
141 int i; 151 int i;
142 bool done = false; 152 bool found = false;
143 153
144 ASSERT_WDEV_LOCK(wdev); 154 ASSERT_WDEV_LOCK(wdev);
145 155
146 nl80211_send_deauth(rdev, dev, buf, len, GFP_KERNEL);
147
148 if (wdev->current_bss && 156 if (wdev->current_bss &&
149 memcmp(wdev->current_bss->pub.bssid, bssid, ETH_ALEN) == 0) { 157 memcmp(wdev->current_bss->pub.bssid, bssid, ETH_ALEN) == 0) {
150 done = true;
151 cfg80211_unhold_bss(wdev->current_bss); 158 cfg80211_unhold_bss(wdev->current_bss);
152 cfg80211_put_bss(&wdev->current_bss->pub); 159 cfg80211_put_bss(&wdev->current_bss->pub);
153 wdev->current_bss = NULL; 160 wdev->current_bss = NULL;
161 found = true;
154 } else for (i = 0; i < MAX_AUTH_BSSES; i++) { 162 } else for (i = 0; i < MAX_AUTH_BSSES; i++) {
155 if (wdev->auth_bsses[i] && 163 if (wdev->auth_bsses[i] &&
156 memcmp(wdev->auth_bsses[i]->pub.bssid, bssid, ETH_ALEN) == 0) { 164 memcmp(wdev->auth_bsses[i]->pub.bssid, bssid, ETH_ALEN) == 0) {
157 cfg80211_unhold_bss(wdev->auth_bsses[i]); 165 cfg80211_unhold_bss(wdev->auth_bsses[i]);
158 cfg80211_put_bss(&wdev->auth_bsses[i]->pub); 166 cfg80211_put_bss(&wdev->auth_bsses[i]->pub);
159 wdev->auth_bsses[i] = NULL; 167 wdev->auth_bsses[i] = NULL;
160 done = true; 168 found = true;
161 break; 169 break;
162 } 170 }
163 if (wdev->authtry_bsses[i] && 171 if (wdev->authtry_bsses[i] &&
@@ -165,12 +173,15 @@ static void __cfg80211_send_deauth(struct net_device *dev,
165 cfg80211_unhold_bss(wdev->authtry_bsses[i]); 173 cfg80211_unhold_bss(wdev->authtry_bsses[i]);
166 cfg80211_put_bss(&wdev->authtry_bsses[i]->pub); 174 cfg80211_put_bss(&wdev->authtry_bsses[i]->pub);
167 wdev->authtry_bsses[i] = NULL; 175 wdev->authtry_bsses[i] = NULL;
168 done = true; 176 found = true;
169 break; 177 break;
170 } 178 }
171 } 179 }
172 180
173 WARN_ON(!done); 181 if (!found)
182 return;
183
184 nl80211_send_deauth(rdev, dev, buf, len, GFP_KERNEL);
174 185
175 if (wdev->sme_state == CFG80211_SME_CONNECTED) { 186 if (wdev->sme_state == CFG80211_SME_CONNECTED) {
176 u16 reason_code; 187 u16 reason_code;
@@ -186,27 +197,19 @@ static void __cfg80211_send_deauth(struct net_device *dev,
186 false, NULL); 197 false, NULL);
187 } 198 }
188} 199}
200EXPORT_SYMBOL(__cfg80211_send_deauth);
189 201
190 202void cfg80211_send_deauth(struct net_device *dev, const u8 *buf, size_t len)
191void cfg80211_send_deauth(struct net_device *dev, const u8 *buf, size_t len,
192 void *cookie)
193{ 203{
194 struct wireless_dev *wdev = dev->ieee80211_ptr; 204 struct wireless_dev *wdev = dev->ieee80211_ptr;
195 205
196 BUG_ON(cookie && wdev != cookie); 206 wdev_lock(wdev);
197 207 __cfg80211_send_deauth(dev, buf, len);
198 if (cookie) { 208 wdev_unlock(wdev);
199 /* called within callback */
200 __cfg80211_send_deauth(dev, buf, len);
201 } else {
202 wdev_lock(wdev);
203 __cfg80211_send_deauth(dev, buf, len);
204 wdev_unlock(wdev);
205 }
206} 209}
207EXPORT_SYMBOL(cfg80211_send_deauth); 210EXPORT_SYMBOL(cfg80211_send_deauth);
208 211
209static void __cfg80211_send_disassoc(struct net_device *dev, 212void __cfg80211_send_disassoc(struct net_device *dev,
210 const u8 *buf, size_t len) 213 const u8 *buf, size_t len)
211{ 214{
212 struct wireless_dev *wdev = dev->ieee80211_ptr; 215 struct wireless_dev *wdev = dev->ieee80211_ptr;
@@ -247,40 +250,24 @@ static void __cfg80211_send_disassoc(struct net_device *dev,
247 from_ap = memcmp(mgmt->sa, dev->dev_addr, ETH_ALEN) != 0; 250 from_ap = memcmp(mgmt->sa, dev->dev_addr, ETH_ALEN) != 0;
248 __cfg80211_disconnected(dev, NULL, 0, reason_code, from_ap); 251 __cfg80211_disconnected(dev, NULL, 0, reason_code, from_ap);
249} 252}
253EXPORT_SYMBOL(__cfg80211_send_disassoc);
250 254
251void cfg80211_send_disassoc(struct net_device *dev, const u8 *buf, size_t len, 255void cfg80211_send_disassoc(struct net_device *dev, const u8 *buf, size_t len)
252 void *cookie)
253{ 256{
254 struct wireless_dev *wdev = dev->ieee80211_ptr; 257 struct wireless_dev *wdev = dev->ieee80211_ptr;
255 258
256 BUG_ON(cookie && wdev != cookie); 259 wdev_lock(wdev);
257 260 __cfg80211_send_disassoc(dev, buf, len);
258 if (cookie) { 261 wdev_unlock(wdev);
259 /* called within callback */
260 __cfg80211_send_disassoc(dev, buf, len);
261 } else {
262 wdev_lock(wdev);
263 __cfg80211_send_disassoc(dev, buf, len);
264 wdev_unlock(wdev);
265 }
266} 262}
267EXPORT_SYMBOL(cfg80211_send_disassoc); 263EXPORT_SYMBOL(cfg80211_send_disassoc);
268 264
269void cfg80211_send_auth_timeout(struct net_device *dev, const u8 *addr) 265static void __cfg80211_auth_remove(struct wireless_dev *wdev, const u8 *addr)
270{ 266{
271 struct wireless_dev *wdev = dev->ieee80211_ptr;
272 struct wiphy *wiphy = wdev->wiphy;
273 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
274 int i; 267 int i;
275 bool done = false; 268 bool done = false;
276 269
277 wdev_lock(wdev); 270 ASSERT_WDEV_LOCK(wdev);
278
279 nl80211_send_auth_timeout(rdev, dev, addr, GFP_KERNEL);
280 if (wdev->sme_state == CFG80211_SME_CONNECTING)
281 __cfg80211_connect_result(dev, addr, NULL, 0, NULL, 0,
282 WLAN_STATUS_UNSPECIFIED_FAILURE,
283 false, NULL);
284 271
285 for (i = 0; addr && i < MAX_AUTH_BSSES; i++) { 272 for (i = 0; addr && i < MAX_AUTH_BSSES; i++) {
286 if (wdev->authtry_bsses[i] && 273 if (wdev->authtry_bsses[i] &&
@@ -295,6 +282,29 @@ void cfg80211_send_auth_timeout(struct net_device *dev, const u8 *addr)
295 } 282 }
296 283
297 WARN_ON(!done); 284 WARN_ON(!done);
285}
286
287void __cfg80211_auth_canceled(struct net_device *dev, const u8 *addr)
288{
289 __cfg80211_auth_remove(dev->ieee80211_ptr, addr);
290}
291EXPORT_SYMBOL(__cfg80211_auth_canceled);
292
293void cfg80211_send_auth_timeout(struct net_device *dev, const u8 *addr)
294{
295 struct wireless_dev *wdev = dev->ieee80211_ptr;
296 struct wiphy *wiphy = wdev->wiphy;
297 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
298
299 wdev_lock(wdev);
300
301 nl80211_send_auth_timeout(rdev, dev, addr, GFP_KERNEL);
302 if (wdev->sme_state == CFG80211_SME_CONNECTING)
303 __cfg80211_connect_result(dev, addr, NULL, 0, NULL, 0,
304 WLAN_STATUS_UNSPECIFIED_FAILURE,
305 false, NULL);
306
307 __cfg80211_auth_remove(wdev, addr);
298 308
299 wdev_unlock(wdev); 309 wdev_unlock(wdev);
300} 310}
@@ -340,7 +350,7 @@ void cfg80211_michael_mic_failure(struct net_device *dev, const u8 *addr,
340{ 350{
341 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; 351 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
342 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); 352 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
343#ifdef CONFIG_WIRELESS_EXT 353#ifdef CONFIG_CFG80211_WEXT
344 union iwreq_data wrqu; 354 union iwreq_data wrqu;
345 char *buf = kmalloc(128, gfp); 355 char *buf = kmalloc(128, gfp);
346 356
@@ -469,12 +479,23 @@ int __cfg80211_mlme_assoc(struct cfg80211_registered_device *rdev,
469 struct cfg80211_assoc_request req; 479 struct cfg80211_assoc_request req;
470 struct cfg80211_internal_bss *bss; 480 struct cfg80211_internal_bss *bss;
471 int i, err, slot = -1; 481 int i, err, slot = -1;
482 bool was_connected = false;
472 483
473 ASSERT_WDEV_LOCK(wdev); 484 ASSERT_WDEV_LOCK(wdev);
474 485
475 memset(&req, 0, sizeof(req)); 486 memset(&req, 0, sizeof(req));
476 487
477 if (wdev->current_bss) 488 if (wdev->current_bss && prev_bssid &&
489 memcmp(wdev->current_bss->pub.bssid, prev_bssid, ETH_ALEN) == 0) {
490 /*
491 * Trying to reassociate: Allow this to proceed and let the old
492 * association to be dropped when the new one is completed.
493 */
494 if (wdev->sme_state == CFG80211_SME_CONNECTED) {
495 was_connected = true;
496 wdev->sme_state = CFG80211_SME_CONNECTING;
497 }
498 } else if (wdev->current_bss)
478 return -EALREADY; 499 return -EALREADY;
479 500
480 req.ie = ie; 501 req.ie = ie;
@@ -484,8 +505,11 @@ int __cfg80211_mlme_assoc(struct cfg80211_registered_device *rdev,
484 req.prev_bssid = prev_bssid; 505 req.prev_bssid = prev_bssid;
485 req.bss = cfg80211_get_bss(&rdev->wiphy, chan, bssid, ssid, ssid_len, 506 req.bss = cfg80211_get_bss(&rdev->wiphy, chan, bssid, ssid, ssid_len,
486 WLAN_CAPABILITY_ESS, WLAN_CAPABILITY_ESS); 507 WLAN_CAPABILITY_ESS, WLAN_CAPABILITY_ESS);
487 if (!req.bss) 508 if (!req.bss) {
509 if (was_connected)
510 wdev->sme_state = CFG80211_SME_CONNECTED;
488 return -ENOENT; 511 return -ENOENT;
512 }
489 513
490 bss = bss_from_pub(req.bss); 514 bss = bss_from_pub(req.bss);
491 515
@@ -503,6 +527,8 @@ int __cfg80211_mlme_assoc(struct cfg80211_registered_device *rdev,
503 527
504 err = rdev->ops->assoc(&rdev->wiphy, dev, &req); 528 err = rdev->ops->assoc(&rdev->wiphy, dev, &req);
505 out: 529 out:
530 if (err && was_connected)
531 wdev->sme_state = CFG80211_SME_CONNECTED;
506 /* still a reference in wdev->auth_bsses[slot] */ 532 /* still a reference in wdev->auth_bsses[slot] */
507 cfg80211_put_bss(req.bss); 533 cfg80211_put_bss(req.bss);
508 return err; 534 return err;
@@ -666,3 +692,206 @@ void cfg80211_mlme_down(struct cfg80211_registered_device *rdev,
666 } 692 }
667 } 693 }
668} 694}
695
696void cfg80211_ready_on_channel(struct net_device *dev, u64 cookie,
697 struct ieee80211_channel *chan,
698 enum nl80211_channel_type channel_type,
699 unsigned int duration, gfp_t gfp)
700{
701 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
702 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
703
704 nl80211_send_remain_on_channel(rdev, dev, cookie, chan, channel_type,
705 duration, gfp);
706}
707EXPORT_SYMBOL(cfg80211_ready_on_channel);
708
709void cfg80211_remain_on_channel_expired(struct net_device *dev,
710 u64 cookie,
711 struct ieee80211_channel *chan,
712 enum nl80211_channel_type channel_type,
713 gfp_t gfp)
714{
715 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
716 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
717
718 nl80211_send_remain_on_channel_cancel(rdev, dev, cookie, chan,
719 channel_type, gfp);
720}
721EXPORT_SYMBOL(cfg80211_remain_on_channel_expired);
722
723void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr,
724 struct station_info *sinfo, gfp_t gfp)
725{
726 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
727 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
728
729 nl80211_send_sta_event(rdev, dev, mac_addr, sinfo, gfp);
730}
731EXPORT_SYMBOL(cfg80211_new_sta);
732
733struct cfg80211_action_registration {
734 struct list_head list;
735
736 u32 nlpid;
737
738 int match_len;
739
740 u8 match[];
741};
742
743int cfg80211_mlme_register_action(struct wireless_dev *wdev, u32 snd_pid,
744 const u8 *match_data, int match_len)
745{
746 struct cfg80211_action_registration *reg, *nreg;
747 int err = 0;
748
749 nreg = kzalloc(sizeof(*reg) + match_len, GFP_KERNEL);
750 if (!nreg)
751 return -ENOMEM;
752
753 spin_lock_bh(&wdev->action_registrations_lock);
754
755 list_for_each_entry(reg, &wdev->action_registrations, list) {
756 int mlen = min(match_len, reg->match_len);
757
758 if (memcmp(reg->match, match_data, mlen) == 0) {
759 err = -EALREADY;
760 break;
761 }
762 }
763
764 if (err) {
765 kfree(nreg);
766 goto out;
767 }
768
769 memcpy(nreg->match, match_data, match_len);
770 nreg->match_len = match_len;
771 nreg->nlpid = snd_pid;
772 list_add(&nreg->list, &wdev->action_registrations);
773
774 out:
775 spin_unlock_bh(&wdev->action_registrations_lock);
776 return err;
777}
778
779void cfg80211_mlme_unregister_actions(struct wireless_dev *wdev, u32 nlpid)
780{
781 struct cfg80211_action_registration *reg, *tmp;
782
783 spin_lock_bh(&wdev->action_registrations_lock);
784
785 list_for_each_entry_safe(reg, tmp, &wdev->action_registrations, list) {
786 if (reg->nlpid == nlpid) {
787 list_del(&reg->list);
788 kfree(reg);
789 }
790 }
791
792 spin_unlock_bh(&wdev->action_registrations_lock);
793}
794
795void cfg80211_mlme_purge_actions(struct wireless_dev *wdev)
796{
797 struct cfg80211_action_registration *reg, *tmp;
798
799 spin_lock_bh(&wdev->action_registrations_lock);
800
801 list_for_each_entry_safe(reg, tmp, &wdev->action_registrations, list) {
802 list_del(&reg->list);
803 kfree(reg);
804 }
805
806 spin_unlock_bh(&wdev->action_registrations_lock);
807}
808
809int cfg80211_mlme_action(struct cfg80211_registered_device *rdev,
810 struct net_device *dev,
811 struct ieee80211_channel *chan,
812 enum nl80211_channel_type channel_type,
813 const u8 *buf, size_t len, u64 *cookie)
814{
815 struct wireless_dev *wdev = dev->ieee80211_ptr;
816 const struct ieee80211_mgmt *mgmt;
817
818 if (rdev->ops->action == NULL)
819 return -EOPNOTSUPP;
820 if (len < 24 + 1)
821 return -EINVAL;
822
823 mgmt = (const struct ieee80211_mgmt *) buf;
824 if (!ieee80211_is_action(mgmt->frame_control))
825 return -EINVAL;
826 if (mgmt->u.action.category != WLAN_CATEGORY_PUBLIC) {
827 /* Verify that we are associated with the destination AP */
828 if (!wdev->current_bss ||
829 memcmp(wdev->current_bss->pub.bssid, mgmt->bssid,
830 ETH_ALEN) != 0 ||
831 memcmp(wdev->current_bss->pub.bssid, mgmt->da,
832 ETH_ALEN) != 0)
833 return -ENOTCONN;
834 }
835
836 if (memcmp(mgmt->sa, dev->dev_addr, ETH_ALEN) != 0)
837 return -EINVAL;
838
839 /* Transmit the Action frame as requested by user space */
840 return rdev->ops->action(&rdev->wiphy, dev, chan, channel_type,
841 buf, len, cookie);
842}
843
844bool cfg80211_rx_action(struct net_device *dev, int freq, const u8 *buf,
845 size_t len, gfp_t gfp)
846{
847 struct wireless_dev *wdev = dev->ieee80211_ptr;
848 struct wiphy *wiphy = wdev->wiphy;
849 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
850 struct cfg80211_action_registration *reg;
851 const u8 *action_data;
852 int action_data_len;
853 bool result = false;
854
855 /* frame length - min size excluding category */
856 action_data_len = len - (IEEE80211_MIN_ACTION_SIZE - 1);
857
858 /* action data starts with category */
859 action_data = buf + IEEE80211_MIN_ACTION_SIZE - 1;
860
861 spin_lock_bh(&wdev->action_registrations_lock);
862
863 list_for_each_entry(reg, &wdev->action_registrations, list) {
864 if (reg->match_len > action_data_len)
865 continue;
866
867 if (memcmp(reg->match, action_data, reg->match_len))
868 continue;
869
870 /* found match! */
871
872 /* Indicate the received Action frame to user space */
873 if (nl80211_send_action(rdev, dev, reg->nlpid, freq,
874 buf, len, gfp))
875 continue;
876
877 result = true;
878 break;
879 }
880
881 spin_unlock_bh(&wdev->action_registrations_lock);
882
883 return result;
884}
885EXPORT_SYMBOL(cfg80211_rx_action);
886
887void cfg80211_action_tx_status(struct net_device *dev, u64 cookie,
888 const u8 *buf, size_t len, bool ack, gfp_t gfp)
889{
890 struct wireless_dev *wdev = dev->ieee80211_ptr;
891 struct wiphy *wiphy = wdev->wiphy;
892 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
893
894 /* Indicate TX status of the Action frame to user space */
895 nl80211_send_action_tx_status(rdev, dev, cookie, buf, len, ack, gfp);
896}
897EXPORT_SYMBOL(cfg80211_action_tx_status);
diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c
index ca3c92a0a14f..030cf153bea2 100644
--- a/net/wireless/nl80211.c
+++ b/net/wireless/nl80211.c
@@ -1,12 +1,13 @@
1/* 1/*
2 * This is the new netlink-based wireless configuration interface. 2 * This is the new netlink-based wireless configuration interface.
3 * 3 *
4 * Copyright 2006-2009 Johannes Berg <johannes@sipsolutions.net> 4 * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
5 */ 5 */
6 6
7#include <linux/if.h> 7#include <linux/if.h>
8#include <linux/module.h> 8#include <linux/module.h>
9#include <linux/err.h> 9#include <linux/err.h>
10#include <linux/slab.h>
10#include <linux/list.h> 11#include <linux/list.h>
11#include <linux/if_ether.h> 12#include <linux/if_ether.h>
12#include <linux/ieee80211.h> 13#include <linux/ieee80211.h>
@@ -58,7 +59,7 @@ static int get_rdev_dev_by_info_ifindex(struct genl_info *info,
58} 59}
59 60
60/* policy for the attributes */ 61/* policy for the attributes */
61static struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] __read_mostly = { 62static const struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] = {
62 [NL80211_ATTR_WIPHY] = { .type = NLA_U32 }, 63 [NL80211_ATTR_WIPHY] = { .type = NLA_U32 },
63 [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING, 64 [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING,
64 .len = 20-1 }, 65 .len = 20-1 },
@@ -69,6 +70,7 @@ static struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] __read_mostly = {
69 [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 }, 70 [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 },
70 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 }, 71 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 },
71 [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 }, 72 [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 },
73 [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 },
72 74
73 [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 }, 75 [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 },
74 [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 }, 76 [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 },
@@ -138,11 +140,20 @@ static struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] __read_mostly = {
138 [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 }, 140 [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 },
139 [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 }, 141 [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 },
140 [NL80211_ATTR_PID] = { .type = NLA_U32 }, 142 [NL80211_ATTR_PID] = { .type = NLA_U32 },
143 [NL80211_ATTR_4ADDR] = { .type = NLA_U8 },
144 [NL80211_ATTR_PMKID] = { .type = NLA_BINARY,
145 .len = WLAN_PMKID_LEN },
146 [NL80211_ATTR_DURATION] = { .type = NLA_U32 },
147 [NL80211_ATTR_COOKIE] = { .type = NLA_U64 },
148 [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED },
149 [NL80211_ATTR_FRAME] = { .type = NLA_BINARY,
150 .len = IEEE80211_MAX_DATA_LEN },
151 [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, },
152 [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 },
141}; 153};
142 154
143/* policy for the attributes */ 155/* policy for the attributes */
144static struct nla_policy 156static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = {
145nl80211_key_policy[NL80211_KEY_MAX + 1] __read_mostly = {
146 [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, 157 [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN },
147 [NL80211_KEY_IDX] = { .type = NLA_U8 }, 158 [NL80211_KEY_IDX] = { .type = NLA_U8 },
148 [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, 159 [NL80211_KEY_CIPHER] = { .type = NLA_U32 },
@@ -151,6 +162,26 @@ nl80211_key_policy[NL80211_KEY_MAX + 1] __read_mostly = {
151 [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, 162 [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG },
152}; 163};
153 164
165/* ifidx get helper */
166static int nl80211_get_ifidx(struct netlink_callback *cb)
167{
168 int res;
169
170 res = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
171 nl80211_fam.attrbuf, nl80211_fam.maxattr,
172 nl80211_policy);
173 if (res)
174 return res;
175
176 if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX])
177 return -EINVAL;
178
179 res = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]);
180 if (!res)
181 return -EINVAL;
182 return res;
183}
184
154/* IE validation */ 185/* IE validation */
155static bool is_valid_ie_attr(const struct nlattr *attr) 186static bool is_valid_ie_attr(const struct nlattr *attr)
156{ 187{
@@ -419,6 +450,8 @@ static int nl80211_send_wiphy(struct sk_buff *msg, u32 pid, u32 seq, int flags,
419 dev->wiphy.frag_threshold); 450 dev->wiphy.frag_threshold);
420 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, 451 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
421 dev->wiphy.rts_threshold); 452 dev->wiphy.rts_threshold);
453 NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
454 dev->wiphy.coverage_class);
422 455
423 NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, 456 NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
424 dev->wiphy.max_scan_ssids); 457 dev->wiphy.max_scan_ssids);
@@ -429,6 +462,9 @@ static int nl80211_send_wiphy(struct sk_buff *msg, u32 pid, u32 seq, int flags,
429 sizeof(u32) * dev->wiphy.n_cipher_suites, 462 sizeof(u32) * dev->wiphy.n_cipher_suites,
430 dev->wiphy.cipher_suites); 463 dev->wiphy.cipher_suites);
431 464
465 NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
466 dev->wiphy.max_num_pmkids);
467
432 nl_modes = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_IFTYPES); 468 nl_modes = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_IFTYPES);
433 if (!nl_modes) 469 if (!nl_modes)
434 goto nla_put_failure; 470 goto nla_put_failure;
@@ -540,7 +576,13 @@ static int nl80211_send_wiphy(struct sk_buff *msg, u32 pid, u32 seq, int flags,
540 CMD(deauth, DEAUTHENTICATE); 576 CMD(deauth, DEAUTHENTICATE);
541 CMD(disassoc, DISASSOCIATE); 577 CMD(disassoc, DISASSOCIATE);
542 CMD(join_ibss, JOIN_IBSS); 578 CMD(join_ibss, JOIN_IBSS);
543 if (dev->wiphy.netnsok) { 579 CMD(set_pmksa, SET_PMKSA);
580 CMD(del_pmksa, DEL_PMKSA);
581 CMD(flush_pmksa, FLUSH_PMKSA);
582 CMD(remain_on_channel, REMAIN_ON_CHANNEL);
583 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
584 CMD(action, ACTION);
585 if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
544 i++; 586 i++;
545 NLA_PUT_U32(msg, i, NL80211_CMD_SET_WIPHY_NETNS); 587 NLA_PUT_U32(msg, i, NL80211_CMD_SET_WIPHY_NETNS);
546 } 588 }
@@ -652,6 +694,7 @@ static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
652 u32 changed; 694 u32 changed;
653 u8 retry_short = 0, retry_long = 0; 695 u8 retry_short = 0, retry_long = 0;
654 u32 frag_threshold = 0, rts_threshold = 0; 696 u32 frag_threshold = 0, rts_threshold = 0;
697 u8 coverage_class = 0;
655 698
656 rtnl_lock(); 699 rtnl_lock();
657 700
@@ -774,9 +817,16 @@ static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
774 changed |= WIPHY_PARAM_RTS_THRESHOLD; 817 changed |= WIPHY_PARAM_RTS_THRESHOLD;
775 } 818 }
776 819
820 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
821 coverage_class = nla_get_u8(
822 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
823 changed |= WIPHY_PARAM_COVERAGE_CLASS;
824 }
825
777 if (changed) { 826 if (changed) {
778 u8 old_retry_short, old_retry_long; 827 u8 old_retry_short, old_retry_long;
779 u32 old_frag_threshold, old_rts_threshold; 828 u32 old_frag_threshold, old_rts_threshold;
829 u8 old_coverage_class;
780 830
781 if (!rdev->ops->set_wiphy_params) { 831 if (!rdev->ops->set_wiphy_params) {
782 result = -EOPNOTSUPP; 832 result = -EOPNOTSUPP;
@@ -787,6 +837,7 @@ static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
787 old_retry_long = rdev->wiphy.retry_long; 837 old_retry_long = rdev->wiphy.retry_long;
788 old_frag_threshold = rdev->wiphy.frag_threshold; 838 old_frag_threshold = rdev->wiphy.frag_threshold;
789 old_rts_threshold = rdev->wiphy.rts_threshold; 839 old_rts_threshold = rdev->wiphy.rts_threshold;
840 old_coverage_class = rdev->wiphy.coverage_class;
790 841
791 if (changed & WIPHY_PARAM_RETRY_SHORT) 842 if (changed & WIPHY_PARAM_RETRY_SHORT)
792 rdev->wiphy.retry_short = retry_short; 843 rdev->wiphy.retry_short = retry_short;
@@ -796,6 +847,8 @@ static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
796 rdev->wiphy.frag_threshold = frag_threshold; 847 rdev->wiphy.frag_threshold = frag_threshold;
797 if (changed & WIPHY_PARAM_RTS_THRESHOLD) 848 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
798 rdev->wiphy.rts_threshold = rts_threshold; 849 rdev->wiphy.rts_threshold = rts_threshold;
850 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
851 rdev->wiphy.coverage_class = coverage_class;
799 852
800 result = rdev->ops->set_wiphy_params(&rdev->wiphy, changed); 853 result = rdev->ops->set_wiphy_params(&rdev->wiphy, changed);
801 if (result) { 854 if (result) {
@@ -803,6 +856,7 @@ static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
803 rdev->wiphy.retry_long = old_retry_long; 856 rdev->wiphy.retry_long = old_retry_long;
804 rdev->wiphy.frag_threshold = old_frag_threshold; 857 rdev->wiphy.frag_threshold = old_frag_threshold;
805 rdev->wiphy.rts_threshold = old_rts_threshold; 858 rdev->wiphy.rts_threshold = old_rts_threshold;
859 rdev->wiphy.coverage_class = old_coverage_class;
806 } 860 }
807 } 861 }
808 862
@@ -947,6 +1001,32 @@ static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
947 return 0; 1001 return 0;
948} 1002}
949 1003
1004static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
1005 struct net_device *netdev, u8 use_4addr,
1006 enum nl80211_iftype iftype)
1007{
1008 if (!use_4addr) {
1009 if (netdev && netdev->br_port)
1010 return -EBUSY;
1011 return 0;
1012 }
1013
1014 switch (iftype) {
1015 case NL80211_IFTYPE_AP_VLAN:
1016 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
1017 return 0;
1018 break;
1019 case NL80211_IFTYPE_STATION:
1020 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
1021 return 0;
1022 break;
1023 default:
1024 break;
1025 }
1026
1027 return -EOPNOTSUPP;
1028}
1029
950static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) 1030static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
951{ 1031{
952 struct cfg80211_registered_device *rdev; 1032 struct cfg80211_registered_device *rdev;
@@ -987,6 +1067,16 @@ static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
987 change = true; 1067 change = true;
988 } 1068 }
989 1069
1070 if (info->attrs[NL80211_ATTR_4ADDR]) {
1071 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
1072 change = true;
1073 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
1074 if (err)
1075 goto unlock;
1076 } else {
1077 params.use_4addr = -1;
1078 }
1079
990 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { 1080 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
991 if (ntype != NL80211_IFTYPE_MONITOR) { 1081 if (ntype != NL80211_IFTYPE_MONITOR) {
992 err = -EINVAL; 1082 err = -EINVAL;
@@ -1006,6 +1096,9 @@ static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
1006 else 1096 else
1007 err = 0; 1097 err = 0;
1008 1098
1099 if (!err && params.use_4addr != -1)
1100 dev->ieee80211_ptr->use_4addr = params.use_4addr;
1101
1009 unlock: 1102 unlock:
1010 dev_put(dev); 1103 dev_put(dev);
1011 cfg80211_unlock_rdev(rdev); 1104 cfg80211_unlock_rdev(rdev);
@@ -1053,6 +1146,13 @@ static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
1053 params.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); 1146 params.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
1054 } 1147 }
1055 1148
1149 if (info->attrs[NL80211_ATTR_4ADDR]) {
1150 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
1151 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
1152 if (err)
1153 goto unlock;
1154 }
1155
1056 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? 1156 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
1057 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, 1157 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
1058 &flags); 1158 &flags);
@@ -1264,7 +1364,7 @@ static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
1264 if (!err) 1364 if (!err)
1265 err = func(&rdev->wiphy, dev, key.idx); 1365 err = func(&rdev->wiphy, dev, key.idx);
1266 1366
1267#ifdef CONFIG_WIRELESS_EXT 1367#ifdef CONFIG_CFG80211_WEXT
1268 if (!err) { 1368 if (!err) {
1269 if (func == rdev->ops->set_default_key) 1369 if (func == rdev->ops->set_default_key)
1270 dev->ieee80211_ptr->wext.default_key = key.idx; 1370 dev->ieee80211_ptr->wext.default_key = key.idx;
@@ -1365,7 +1465,7 @@ static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
1365 if (!err) 1465 if (!err)
1366 err = rdev->ops->del_key(&rdev->wiphy, dev, key.idx, mac_addr); 1466 err = rdev->ops->del_key(&rdev->wiphy, dev, key.idx, mac_addr);
1367 1467
1368#ifdef CONFIG_WIRELESS_EXT 1468#ifdef CONFIG_CFG80211_WEXT
1369 if (!err) { 1469 if (!err) {
1370 if (key.idx == dev->ieee80211_ptr->wext.default_key) 1470 if (key.idx == dev->ieee80211_ptr->wext.default_key)
1371 dev->ieee80211_ptr->wext.default_key = -1; 1471 dev->ieee80211_ptr->wext.default_key = -1;
@@ -1562,42 +1662,9 @@ static int parse_station_flags(struct genl_info *info,
1562 return 0; 1662 return 0;
1563} 1663}
1564 1664
1565static u16 nl80211_calculate_bitrate(struct rate_info *rate)
1566{
1567 int modulation, streams, bitrate;
1568
1569 if (!(rate->flags & RATE_INFO_FLAGS_MCS))
1570 return rate->legacy;
1571
1572 /* the formula below does only work for MCS values smaller than 32 */
1573 if (rate->mcs >= 32)
1574 return 0;
1575
1576 modulation = rate->mcs & 7;
1577 streams = (rate->mcs >> 3) + 1;
1578
1579 bitrate = (rate->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH) ?
1580 13500000 : 6500000;
1581
1582 if (modulation < 4)
1583 bitrate *= (modulation + 1);
1584 else if (modulation == 4)
1585 bitrate *= (modulation + 2);
1586 else
1587 bitrate *= (modulation + 3);
1588
1589 bitrate *= streams;
1590
1591 if (rate->flags & RATE_INFO_FLAGS_SHORT_GI)
1592 bitrate = (bitrate / 9) * 10;
1593
1594 /* do NOT round down here */
1595 return (bitrate + 50000) / 100000;
1596}
1597
1598static int nl80211_send_station(struct sk_buff *msg, u32 pid, u32 seq, 1665static int nl80211_send_station(struct sk_buff *msg, u32 pid, u32 seq,
1599 int flags, struct net_device *dev, 1666 int flags, struct net_device *dev,
1600 u8 *mac_addr, struct station_info *sinfo) 1667 const u8 *mac_addr, struct station_info *sinfo)
1601{ 1668{
1602 void *hdr; 1669 void *hdr;
1603 struct nlattr *sinfoattr, *txrate; 1670 struct nlattr *sinfoattr, *txrate;
@@ -1641,8 +1708,8 @@ static int nl80211_send_station(struct sk_buff *msg, u32 pid, u32 seq,
1641 if (!txrate) 1708 if (!txrate)
1642 goto nla_put_failure; 1709 goto nla_put_failure;
1643 1710
1644 /* nl80211_calculate_bitrate will return 0 for mcs >= 32 */ 1711 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
1645 bitrate = nl80211_calculate_bitrate(&sinfo->txrate); 1712 bitrate = cfg80211_calculate_bitrate(&sinfo->txrate);
1646 if (bitrate > 0) 1713 if (bitrate > 0)
1647 NLA_PUT_U16(msg, NL80211_RATE_INFO_BITRATE, bitrate); 1714 NLA_PUT_U16(msg, NL80211_RATE_INFO_BITRATE, bitrate);
1648 1715
@@ -1682,20 +1749,10 @@ static int nl80211_dump_station(struct sk_buff *skb,
1682 int sta_idx = cb->args[1]; 1749 int sta_idx = cb->args[1];
1683 int err; 1750 int err;
1684 1751
1685 if (!ifidx) { 1752 if (!ifidx)
1686 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, 1753 ifidx = nl80211_get_ifidx(cb);
1687 nl80211_fam.attrbuf, nl80211_fam.maxattr, 1754 if (ifidx < 0)
1688 nl80211_policy); 1755 return ifidx;
1689 if (err)
1690 return err;
1691
1692 if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX])
1693 return -EINVAL;
1694
1695 ifidx = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]);
1696 if (!ifidx)
1697 return -EINVAL;
1698 }
1699 1756
1700 rtnl_lock(); 1757 rtnl_lock();
1701 1758
@@ -1800,7 +1857,7 @@ static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
1800} 1857}
1801 1858
1802/* 1859/*
1803 * Get vlan interface making sure it is on the right wiphy. 1860 * Get vlan interface making sure it is running and on the right wiphy.
1804 */ 1861 */
1805static int get_vlan(struct genl_info *info, 1862static int get_vlan(struct genl_info *info,
1806 struct cfg80211_registered_device *rdev, 1863 struct cfg80211_registered_device *rdev,
@@ -1818,6 +1875,8 @@ static int get_vlan(struct genl_info *info,
1818 return -EINVAL; 1875 return -EINVAL;
1819 if ((*vlan)->ieee80211_ptr->wiphy != &rdev->wiphy) 1876 if ((*vlan)->ieee80211_ptr->wiphy != &rdev->wiphy)
1820 return -EINVAL; 1877 return -EINVAL;
1878 if (!netif_running(*vlan))
1879 return -ENETDOWN;
1821 } 1880 }
1822 return 0; 1881 return 0;
1823} 1882}
@@ -1956,6 +2015,9 @@ static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
1956 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) 2015 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
1957 return -EINVAL; 2016 return -EINVAL;
1958 2017
2018 if (!info->attrs[NL80211_ATTR_STA_AID])
2019 return -EINVAL;
2020
1959 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); 2021 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
1960 params.supported_rates = 2022 params.supported_rates =
1961 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); 2023 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
@@ -1964,11 +2026,9 @@ static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
1964 params.listen_interval = 2026 params.listen_interval =
1965 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); 2027 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
1966 2028
1967 if (info->attrs[NL80211_ATTR_STA_AID]) { 2029 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
1968 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); 2030 if (!params.aid || params.aid > IEEE80211_MAX_AID)
1969 if (!params.aid || params.aid > IEEE80211_MAX_AID) 2031 return -EINVAL;
1970 return -EINVAL;
1971 }
1972 2032
1973 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) 2033 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
1974 params.ht_capa = 2034 params.ht_capa =
@@ -1983,6 +2043,12 @@ static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
1983 if (err) 2043 if (err)
1984 goto out_rtnl; 2044 goto out_rtnl;
1985 2045
2046 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
2047 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN) {
2048 err = -EINVAL;
2049 goto out;
2050 }
2051
1986 err = get_vlan(info, rdev, &params.vlan); 2052 err = get_vlan(info, rdev, &params.vlan);
1987 if (err) 2053 if (err)
1988 goto out; 2054 goto out;
@@ -1990,35 +2056,6 @@ static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
1990 /* validate settings */ 2056 /* validate settings */
1991 err = 0; 2057 err = 0;
1992 2058
1993 switch (dev->ieee80211_ptr->iftype) {
1994 case NL80211_IFTYPE_AP:
1995 case NL80211_IFTYPE_AP_VLAN:
1996 /* all ok but must have AID */
1997 if (!params.aid)
1998 err = -EINVAL;
1999 break;
2000 case NL80211_IFTYPE_MESH_POINT:
2001 /* disallow things mesh doesn't support */
2002 if (params.vlan)
2003 err = -EINVAL;
2004 if (params.aid)
2005 err = -EINVAL;
2006 if (params.ht_capa)
2007 err = -EINVAL;
2008 if (params.listen_interval >= 0)
2009 err = -EINVAL;
2010 if (params.supported_rates)
2011 err = -EINVAL;
2012 if (params.sta_flags_mask)
2013 err = -EINVAL;
2014 break;
2015 default:
2016 err = -EINVAL;
2017 }
2018
2019 if (err)
2020 goto out;
2021
2022 if (!rdev->ops->add_station) { 2059 if (!rdev->ops->add_station) {
2023 err = -EOPNOTSUPP; 2060 err = -EOPNOTSUPP;
2024 goto out; 2061 goto out;
@@ -2059,8 +2096,7 @@ static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
2059 goto out_rtnl; 2096 goto out_rtnl;
2060 2097
2061 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && 2098 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
2062 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && 2099 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN) {
2063 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) {
2064 err = -EINVAL; 2100 err = -EINVAL;
2065 goto out; 2101 goto out;
2066 } 2102 }
@@ -2105,9 +2141,9 @@ static int nl80211_send_mpath(struct sk_buff *msg, u32 pid, u32 seq,
2105 if (pinfo->filled & MPATH_INFO_FRAME_QLEN) 2141 if (pinfo->filled & MPATH_INFO_FRAME_QLEN)
2106 NLA_PUT_U32(msg, NL80211_MPATH_INFO_FRAME_QLEN, 2142 NLA_PUT_U32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
2107 pinfo->frame_qlen); 2143 pinfo->frame_qlen);
2108 if (pinfo->filled & MPATH_INFO_DSN) 2144 if (pinfo->filled & MPATH_INFO_SN)
2109 NLA_PUT_U32(msg, NL80211_MPATH_INFO_DSN, 2145 NLA_PUT_U32(msg, NL80211_MPATH_INFO_SN,
2110 pinfo->dsn); 2146 pinfo->sn);
2111 if (pinfo->filled & MPATH_INFO_METRIC) 2147 if (pinfo->filled & MPATH_INFO_METRIC)
2112 NLA_PUT_U32(msg, NL80211_MPATH_INFO_METRIC, 2148 NLA_PUT_U32(msg, NL80211_MPATH_INFO_METRIC,
2113 pinfo->metric); 2149 pinfo->metric);
@@ -2145,20 +2181,10 @@ static int nl80211_dump_mpath(struct sk_buff *skb,
2145 int path_idx = cb->args[1]; 2181 int path_idx = cb->args[1];
2146 int err; 2182 int err;
2147 2183
2148 if (!ifidx) { 2184 if (!ifidx)
2149 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, 2185 ifidx = nl80211_get_ifidx(cb);
2150 nl80211_fam.attrbuf, nl80211_fam.maxattr, 2186 if (ifidx < 0)
2151 nl80211_policy); 2187 return ifidx;
2152 if (err)
2153 return err;
2154
2155 if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX])
2156 return -EINVAL;
2157
2158 ifidx = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]);
2159 if (!ifidx)
2160 return -EINVAL;
2161 }
2162 2188
2163 rtnl_lock(); 2189 rtnl_lock();
2164 2190
@@ -2457,8 +2483,7 @@ static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
2457 return err; 2483 return err;
2458} 2484}
2459 2485
2460static const struct nla_policy 2486static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
2461 reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
2462 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, 2487 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
2463 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, 2488 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
2464 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, 2489 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
@@ -2526,12 +2551,6 @@ static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
2526 2551
2527 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); 2552 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
2528 2553
2529#ifdef CONFIG_WIRELESS_OLD_REGULATORY
2530 /* We ignore world regdom requests with the old regdom setup */
2531 if (is_world_regdom(data))
2532 return -EINVAL;
2533#endif
2534
2535 r = regulatory_hint_user(data); 2554 r = regulatory_hint_user(data);
2536 2555
2537 return r; 2556 return r;
@@ -2605,6 +2624,8 @@ static int nl80211_get_mesh_params(struct sk_buff *skb,
2605 cur_params.dot11MeshHWMPpreqMinInterval); 2624 cur_params.dot11MeshHWMPpreqMinInterval);
2606 NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, 2625 NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
2607 cur_params.dot11MeshHWMPnetDiameterTraversalTime); 2626 cur_params.dot11MeshHWMPnetDiameterTraversalTime);
2627 NLA_PUT_U8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
2628 cur_params.dot11MeshHWMPRootMode);
2608 nla_nest_end(msg, pinfoattr); 2629 nla_nest_end(msg, pinfoattr);
2609 genlmsg_end(msg, hdr); 2630 genlmsg_end(msg, hdr);
2610 err = genlmsg_reply(msg, info); 2631 err = genlmsg_reply(msg, info);
@@ -2631,8 +2652,7 @@ do {\
2631 } \ 2652 } \
2632} while (0);\ 2653} while (0);\
2633 2654
2634static struct nla_policy 2655static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
2635nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] __read_mostly = {
2636 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, 2656 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
2637 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, 2657 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
2638 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, 2658 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
@@ -2715,6 +2735,10 @@ static int nl80211_set_mesh_params(struct sk_buff *skb, struct genl_info *info)
2715 dot11MeshHWMPnetDiameterTraversalTime, 2735 dot11MeshHWMPnetDiameterTraversalTime,
2716 mask, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, 2736 mask, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
2717 nla_get_u16); 2737 nla_get_u16);
2738 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
2739 dot11MeshHWMPRootMode, mask,
2740 NL80211_MESHCONF_HWMP_ROOTMODE,
2741 nla_get_u8);
2718 2742
2719 /* Apply changes */ 2743 /* Apply changes */
2720 err = rdev->ops->set_mesh_params(&rdev->wiphy, dev, &cfg, mask); 2744 err = rdev->ops->set_mesh_params(&rdev->wiphy, dev, &cfg, mask);
@@ -2988,7 +3012,6 @@ static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
2988 goto out; 3012 goto out;
2989 } 3013 }
2990 3014
2991 request->n_channels = n_channels;
2992 if (n_ssids) 3015 if (n_ssids)
2993 request->ssids = (void *)&request->channels[n_channels]; 3016 request->ssids = (void *)&request->channels[n_channels];
2994 request->n_ssids = n_ssids; 3017 request->n_ssids = n_ssids;
@@ -2999,32 +3022,53 @@ static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
2999 request->ie = (void *)(request->channels + n_channels); 3022 request->ie = (void *)(request->channels + n_channels);
3000 } 3023 }
3001 3024
3025 i = 0;
3002 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { 3026 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
3003 /* user specified, bail out if channel not found */ 3027 /* user specified, bail out if channel not found */
3004 request->n_channels = n_channels;
3005 i = 0;
3006 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { 3028 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
3007 request->channels[i] = ieee80211_get_channel(wiphy, nla_get_u32(attr)); 3029 struct ieee80211_channel *chan;
3008 if (!request->channels[i]) { 3030
3031 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
3032
3033 if (!chan) {
3009 err = -EINVAL; 3034 err = -EINVAL;
3010 goto out_free; 3035 goto out_free;
3011 } 3036 }
3037
3038 /* ignore disabled channels */
3039 if (chan->flags & IEEE80211_CHAN_DISABLED)
3040 continue;
3041
3042 request->channels[i] = chan;
3012 i++; 3043 i++;
3013 } 3044 }
3014 } else { 3045 } else {
3015 /* all channels */ 3046 /* all channels */
3016 i = 0;
3017 for (band = 0; band < IEEE80211_NUM_BANDS; band++) { 3047 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
3018 int j; 3048 int j;
3019 if (!wiphy->bands[band]) 3049 if (!wiphy->bands[band])
3020 continue; 3050 continue;
3021 for (j = 0; j < wiphy->bands[band]->n_channels; j++) { 3051 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
3022 request->channels[i] = &wiphy->bands[band]->channels[j]; 3052 struct ieee80211_channel *chan;
3053
3054 chan = &wiphy->bands[band]->channels[j];
3055
3056 if (chan->flags & IEEE80211_CHAN_DISABLED)
3057 continue;
3058
3059 request->channels[i] = chan;
3023 i++; 3060 i++;
3024 } 3061 }
3025 } 3062 }
3026 } 3063 }
3027 3064
3065 if (!i) {
3066 err = -EINVAL;
3067 goto out_free;
3068 }
3069
3070 request->n_channels = i;
3071
3028 i = 0; 3072 i = 0;
3029 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { 3073 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
3030 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { 3074 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
@@ -3099,12 +3143,18 @@ static int nl80211_send_bss(struct sk_buff *msg, u32 pid, u32 seq, int flags,
3099 NLA_PUT(msg, NL80211_BSS_INFORMATION_ELEMENTS, 3143 NLA_PUT(msg, NL80211_BSS_INFORMATION_ELEMENTS,
3100 res->len_information_elements, 3144 res->len_information_elements,
3101 res->information_elements); 3145 res->information_elements);
3146 if (res->beacon_ies && res->len_beacon_ies &&
3147 res->beacon_ies != res->information_elements)
3148 NLA_PUT(msg, NL80211_BSS_BEACON_IES,
3149 res->len_beacon_ies, res->beacon_ies);
3102 if (res->tsf) 3150 if (res->tsf)
3103 NLA_PUT_U64(msg, NL80211_BSS_TSF, res->tsf); 3151 NLA_PUT_U64(msg, NL80211_BSS_TSF, res->tsf);
3104 if (res->beacon_interval) 3152 if (res->beacon_interval)
3105 NLA_PUT_U16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval); 3153 NLA_PUT_U16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval);
3106 NLA_PUT_U16(msg, NL80211_BSS_CAPABILITY, res->capability); 3154 NLA_PUT_U16(msg, NL80211_BSS_CAPABILITY, res->capability);
3107 NLA_PUT_U32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq); 3155 NLA_PUT_U32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq);
3156 NLA_PUT_U32(msg, NL80211_BSS_SEEN_MS_AGO,
3157 jiffies_to_msecs(jiffies - intbss->ts));
3108 3158
3109 switch (rdev->wiphy.signal_type) { 3159 switch (rdev->wiphy.signal_type) {
3110 case CFG80211_SIGNAL_TYPE_MBM: 3160 case CFG80211_SIGNAL_TYPE_MBM:
@@ -3159,21 +3209,11 @@ static int nl80211_dump_scan(struct sk_buff *skb,
3159 int start = cb->args[1], idx = 0; 3209 int start = cb->args[1], idx = 0;
3160 int err; 3210 int err;
3161 3211
3162 if (!ifidx) { 3212 if (!ifidx)
3163 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, 3213 ifidx = nl80211_get_ifidx(cb);
3164 nl80211_fam.attrbuf, nl80211_fam.maxattr, 3214 if (ifidx < 0)
3165 nl80211_policy); 3215 return ifidx;
3166 if (err) 3216 cb->args[0] = ifidx;
3167 return err;
3168
3169 if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX])
3170 return -EINVAL;
3171
3172 ifidx = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]);
3173 if (!ifidx)
3174 return -EINVAL;
3175 cb->args[0] = ifidx;
3176 }
3177 3217
3178 dev = dev_get_by_index(sock_net(skb->sk), ifidx); 3218 dev = dev_get_by_index(sock_net(skb->sk), ifidx);
3179 if (!dev) 3219 if (!dev)
@@ -3216,6 +3256,106 @@ static int nl80211_dump_scan(struct sk_buff *skb,
3216 return err; 3256 return err;
3217} 3257}
3218 3258
3259static int nl80211_send_survey(struct sk_buff *msg, u32 pid, u32 seq,
3260 int flags, struct net_device *dev,
3261 struct survey_info *survey)
3262{
3263 void *hdr;
3264 struct nlattr *infoattr;
3265
3266 /* Survey without a channel doesn't make sense */
3267 if (!survey->channel)
3268 return -EINVAL;
3269
3270 hdr = nl80211hdr_put(msg, pid, seq, flags,
3271 NL80211_CMD_NEW_SURVEY_RESULTS);
3272 if (!hdr)
3273 return -ENOMEM;
3274
3275 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
3276
3277 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
3278 if (!infoattr)
3279 goto nla_put_failure;
3280
3281 NLA_PUT_U32(msg, NL80211_SURVEY_INFO_FREQUENCY,
3282 survey->channel->center_freq);
3283 if (survey->filled & SURVEY_INFO_NOISE_DBM)
3284 NLA_PUT_U8(msg, NL80211_SURVEY_INFO_NOISE,
3285 survey->noise);
3286
3287 nla_nest_end(msg, infoattr);
3288
3289 return genlmsg_end(msg, hdr);
3290
3291 nla_put_failure:
3292 genlmsg_cancel(msg, hdr);
3293 return -EMSGSIZE;
3294}
3295
3296static int nl80211_dump_survey(struct sk_buff *skb,
3297 struct netlink_callback *cb)
3298{
3299 struct survey_info survey;
3300 struct cfg80211_registered_device *dev;
3301 struct net_device *netdev;
3302 int ifidx = cb->args[0];
3303 int survey_idx = cb->args[1];
3304 int res;
3305
3306 if (!ifidx)
3307 ifidx = nl80211_get_ifidx(cb);
3308 if (ifidx < 0)
3309 return ifidx;
3310 cb->args[0] = ifidx;
3311
3312 rtnl_lock();
3313
3314 netdev = __dev_get_by_index(sock_net(skb->sk), ifidx);
3315 if (!netdev) {
3316 res = -ENODEV;
3317 goto out_rtnl;
3318 }
3319
3320 dev = cfg80211_get_dev_from_ifindex(sock_net(skb->sk), ifidx);
3321 if (IS_ERR(dev)) {
3322 res = PTR_ERR(dev);
3323 goto out_rtnl;
3324 }
3325
3326 if (!dev->ops->dump_survey) {
3327 res = -EOPNOTSUPP;
3328 goto out_err;
3329 }
3330
3331 while (1) {
3332 res = dev->ops->dump_survey(&dev->wiphy, netdev, survey_idx,
3333 &survey);
3334 if (res == -ENOENT)
3335 break;
3336 if (res)
3337 goto out_err;
3338
3339 if (nl80211_send_survey(skb,
3340 NETLINK_CB(cb->skb).pid,
3341 cb->nlh->nlmsg_seq, NLM_F_MULTI,
3342 netdev,
3343 &survey) < 0)
3344 goto out;
3345 survey_idx++;
3346 }
3347
3348 out:
3349 cb->args[1] = survey_idx;
3350 res = skb->len;
3351 out_err:
3352 cfg80211_unlock_rdev(dev);
3353 out_rtnl:
3354 rtnl_unlock();
3355
3356 return res;
3357}
3358
3219static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type) 3359static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type)
3220{ 3360{
3221 return auth_type <= NL80211_AUTHTYPE_MAX; 3361 return auth_type <= NL80211_AUTHTYPE_MAX;
@@ -3411,6 +3551,7 @@ static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
3411{ 3551{
3412 struct cfg80211_registered_device *rdev; 3552 struct cfg80211_registered_device *rdev;
3413 struct net_device *dev; 3553 struct net_device *dev;
3554 struct wireless_dev *wdev;
3414 struct cfg80211_crypto_settings crypto; 3555 struct cfg80211_crypto_settings crypto;
3415 struct ieee80211_channel *chan, *fixedchan; 3556 struct ieee80211_channel *chan, *fixedchan;
3416 const u8 *bssid, *ssid, *ie = NULL, *prev_bssid = NULL; 3557 const u8 *bssid, *ssid, *ie = NULL, *prev_bssid = NULL;
@@ -3456,7 +3597,8 @@ static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
3456 } 3597 }
3457 3598
3458 mutex_lock(&rdev->devlist_mtx); 3599 mutex_lock(&rdev->devlist_mtx);
3459 fixedchan = rdev_fixed_channel(rdev, NULL); 3600 wdev = dev->ieee80211_ptr;
3601 fixedchan = rdev_fixed_channel(rdev, wdev);
3460 if (fixedchan && chan != fixedchan) { 3602 if (fixedchan && chan != fixedchan) {
3461 err = -EBUSY; 3603 err = -EBUSY;
3462 mutex_unlock(&rdev->devlist_mtx); 3604 mutex_unlock(&rdev->devlist_mtx);
@@ -4054,6 +4196,589 @@ static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
4054 return err; 4196 return err;
4055} 4197}
4056 4198
4199static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
4200{
4201 struct cfg80211_registered_device *rdev;
4202 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
4203 struct cfg80211_pmksa *pmksa) = NULL;
4204 int err;
4205 struct net_device *dev;
4206 struct cfg80211_pmksa pmksa;
4207
4208 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
4209
4210 if (!info->attrs[NL80211_ATTR_MAC])
4211 return -EINVAL;
4212
4213 if (!info->attrs[NL80211_ATTR_PMKID])
4214 return -EINVAL;
4215
4216 rtnl_lock();
4217
4218 err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev);
4219 if (err)
4220 goto out_rtnl;
4221
4222 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
4223 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
4224
4225 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION) {
4226 err = -EOPNOTSUPP;
4227 goto out;
4228 }
4229
4230 switch (info->genlhdr->cmd) {
4231 case NL80211_CMD_SET_PMKSA:
4232 rdev_ops = rdev->ops->set_pmksa;
4233 break;
4234 case NL80211_CMD_DEL_PMKSA:
4235 rdev_ops = rdev->ops->del_pmksa;
4236 break;
4237 default:
4238 WARN_ON(1);
4239 break;
4240 }
4241
4242 if (!rdev_ops) {
4243 err = -EOPNOTSUPP;
4244 goto out;
4245 }
4246
4247 err = rdev_ops(&rdev->wiphy, dev, &pmksa);
4248
4249 out:
4250 cfg80211_unlock_rdev(rdev);
4251 dev_put(dev);
4252 out_rtnl:
4253 rtnl_unlock();
4254
4255 return err;
4256}
4257
4258static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
4259{
4260 struct cfg80211_registered_device *rdev;
4261 int err;
4262 struct net_device *dev;
4263
4264 rtnl_lock();
4265
4266 err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev);
4267 if (err)
4268 goto out_rtnl;
4269
4270 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION) {
4271 err = -EOPNOTSUPP;
4272 goto out;
4273 }
4274
4275 if (!rdev->ops->flush_pmksa) {
4276 err = -EOPNOTSUPP;
4277 goto out;
4278 }
4279
4280 err = rdev->ops->flush_pmksa(&rdev->wiphy, dev);
4281
4282 out:
4283 cfg80211_unlock_rdev(rdev);
4284 dev_put(dev);
4285 out_rtnl:
4286 rtnl_unlock();
4287
4288 return err;
4289
4290}
4291
4292static int nl80211_remain_on_channel(struct sk_buff *skb,
4293 struct genl_info *info)
4294{
4295 struct cfg80211_registered_device *rdev;
4296 struct net_device *dev;
4297 struct ieee80211_channel *chan;
4298 struct sk_buff *msg;
4299 void *hdr;
4300 u64 cookie;
4301 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
4302 u32 freq, duration;
4303 int err;
4304
4305 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
4306 !info->attrs[NL80211_ATTR_DURATION])
4307 return -EINVAL;
4308
4309 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
4310
4311 /*
4312 * We should be on that channel for at least one jiffie,
4313 * and more than 5 seconds seems excessive.
4314 */
4315 if (!duration || !msecs_to_jiffies(duration) || duration > 5000)
4316 return -EINVAL;
4317
4318 rtnl_lock();
4319
4320 err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev);
4321 if (err)
4322 goto unlock_rtnl;
4323
4324 if (!rdev->ops->remain_on_channel) {
4325 err = -EOPNOTSUPP;
4326 goto out;
4327 }
4328
4329 if (!netif_running(dev)) {
4330 err = -ENETDOWN;
4331 goto out;
4332 }
4333
4334 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
4335 channel_type = nla_get_u32(
4336 info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
4337 if (channel_type != NL80211_CHAN_NO_HT &&
4338 channel_type != NL80211_CHAN_HT20 &&
4339 channel_type != NL80211_CHAN_HT40PLUS &&
4340 channel_type != NL80211_CHAN_HT40MINUS)
4341 err = -EINVAL;
4342 goto out;
4343 }
4344
4345 freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
4346 chan = rdev_freq_to_chan(rdev, freq, channel_type);
4347 if (chan == NULL) {
4348 err = -EINVAL;
4349 goto out;
4350 }
4351
4352 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
4353 if (!msg) {
4354 err = -ENOMEM;
4355 goto out;
4356 }
4357
4358 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
4359 NL80211_CMD_REMAIN_ON_CHANNEL);
4360
4361 if (IS_ERR(hdr)) {
4362 err = PTR_ERR(hdr);
4363 goto free_msg;
4364 }
4365
4366 err = rdev->ops->remain_on_channel(&rdev->wiphy, dev, chan,
4367 channel_type, duration, &cookie);
4368
4369 if (err)
4370 goto free_msg;
4371
4372 NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie);
4373
4374 genlmsg_end(msg, hdr);
4375 err = genlmsg_reply(msg, info);
4376 goto out;
4377
4378 nla_put_failure:
4379 err = -ENOBUFS;
4380 free_msg:
4381 nlmsg_free(msg);
4382 out:
4383 cfg80211_unlock_rdev(rdev);
4384 dev_put(dev);
4385 unlock_rtnl:
4386 rtnl_unlock();
4387 return err;
4388}
4389
4390static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
4391 struct genl_info *info)
4392{
4393 struct cfg80211_registered_device *rdev;
4394 struct net_device *dev;
4395 u64 cookie;
4396 int err;
4397
4398 if (!info->attrs[NL80211_ATTR_COOKIE])
4399 return -EINVAL;
4400
4401 rtnl_lock();
4402
4403 err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev);
4404 if (err)
4405 goto unlock_rtnl;
4406
4407 if (!rdev->ops->cancel_remain_on_channel) {
4408 err = -EOPNOTSUPP;
4409 goto out;
4410 }
4411
4412 if (!netif_running(dev)) {
4413 err = -ENETDOWN;
4414 goto out;
4415 }
4416
4417 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
4418
4419 err = rdev->ops->cancel_remain_on_channel(&rdev->wiphy, dev, cookie);
4420
4421 out:
4422 cfg80211_unlock_rdev(rdev);
4423 dev_put(dev);
4424 unlock_rtnl:
4425 rtnl_unlock();
4426 return err;
4427}
4428
4429static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
4430 u8 *rates, u8 rates_len)
4431{
4432 u8 i;
4433 u32 mask = 0;
4434
4435 for (i = 0; i < rates_len; i++) {
4436 int rate = (rates[i] & 0x7f) * 5;
4437 int ridx;
4438 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
4439 struct ieee80211_rate *srate =
4440 &sband->bitrates[ridx];
4441 if (rate == srate->bitrate) {
4442 mask |= 1 << ridx;
4443 break;
4444 }
4445 }
4446 if (ridx == sband->n_bitrates)
4447 return 0; /* rate not found */
4448 }
4449
4450 return mask;
4451}
4452
4453static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
4454 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
4455 .len = NL80211_MAX_SUPP_RATES },
4456};
4457
4458static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
4459 struct genl_info *info)
4460{
4461 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
4462 struct cfg80211_registered_device *rdev;
4463 struct cfg80211_bitrate_mask mask;
4464 int err, rem, i;
4465 struct net_device *dev;
4466 struct nlattr *tx_rates;
4467 struct ieee80211_supported_band *sband;
4468
4469 if (info->attrs[NL80211_ATTR_TX_RATES] == NULL)
4470 return -EINVAL;
4471
4472 rtnl_lock();
4473
4474 err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev);
4475 if (err)
4476 goto unlock_rtnl;
4477
4478 if (!rdev->ops->set_bitrate_mask) {
4479 err = -EOPNOTSUPP;
4480 goto unlock;
4481 }
4482
4483 memset(&mask, 0, sizeof(mask));
4484 /* Default to all rates enabled */
4485 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
4486 sband = rdev->wiphy.bands[i];
4487 mask.control[i].legacy =
4488 sband ? (1 << sband->n_bitrates) - 1 : 0;
4489 }
4490
4491 /*
4492 * The nested attribute uses enum nl80211_band as the index. This maps
4493 * directly to the enum ieee80211_band values used in cfg80211.
4494 */
4495 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem)
4496 {
4497 enum ieee80211_band band = nla_type(tx_rates);
4498 if (band < 0 || band >= IEEE80211_NUM_BANDS) {
4499 err = -EINVAL;
4500 goto unlock;
4501 }
4502 sband = rdev->wiphy.bands[band];
4503 if (sband == NULL) {
4504 err = -EINVAL;
4505 goto unlock;
4506 }
4507 nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
4508 nla_len(tx_rates), nl80211_txattr_policy);
4509 if (tb[NL80211_TXRATE_LEGACY]) {
4510 mask.control[band].legacy = rateset_to_mask(
4511 sband,
4512 nla_data(tb[NL80211_TXRATE_LEGACY]),
4513 nla_len(tb[NL80211_TXRATE_LEGACY]));
4514 if (mask.control[band].legacy == 0) {
4515 err = -EINVAL;
4516 goto unlock;
4517 }
4518 }
4519 }
4520
4521 err = rdev->ops->set_bitrate_mask(&rdev->wiphy, dev, NULL, &mask);
4522
4523 unlock:
4524 dev_put(dev);
4525 cfg80211_unlock_rdev(rdev);
4526 unlock_rtnl:
4527 rtnl_unlock();
4528 return err;
4529}
4530
4531static int nl80211_register_action(struct sk_buff *skb, struct genl_info *info)
4532{
4533 struct cfg80211_registered_device *rdev;
4534 struct net_device *dev;
4535 int err;
4536
4537 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
4538 return -EINVAL;
4539
4540 if (nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]) < 1)
4541 return -EINVAL;
4542
4543 rtnl_lock();
4544
4545 err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev);
4546 if (err)
4547 goto unlock_rtnl;
4548
4549 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION) {
4550 err = -EOPNOTSUPP;
4551 goto out;
4552 }
4553
4554 /* not much point in registering if we can't reply */
4555 if (!rdev->ops->action) {
4556 err = -EOPNOTSUPP;
4557 goto out;
4558 }
4559
4560 err = cfg80211_mlme_register_action(dev->ieee80211_ptr, info->snd_pid,
4561 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
4562 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
4563 out:
4564 cfg80211_unlock_rdev(rdev);
4565 dev_put(dev);
4566 unlock_rtnl:
4567 rtnl_unlock();
4568 return err;
4569}
4570
4571static int nl80211_action(struct sk_buff *skb, struct genl_info *info)
4572{
4573 struct cfg80211_registered_device *rdev;
4574 struct net_device *dev;
4575 struct ieee80211_channel *chan;
4576 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
4577 u32 freq;
4578 int err;
4579 void *hdr;
4580 u64 cookie;
4581 struct sk_buff *msg;
4582
4583 if (!info->attrs[NL80211_ATTR_FRAME] ||
4584 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
4585 return -EINVAL;
4586
4587 rtnl_lock();
4588
4589 err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev);
4590 if (err)
4591 goto unlock_rtnl;
4592
4593 if (!rdev->ops->action) {
4594 err = -EOPNOTSUPP;
4595 goto out;
4596 }
4597
4598 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION) {
4599 err = -EOPNOTSUPP;
4600 goto out;
4601 }
4602
4603 if (!netif_running(dev)) {
4604 err = -ENETDOWN;
4605 goto out;
4606 }
4607
4608 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
4609 channel_type = nla_get_u32(
4610 info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
4611 if (channel_type != NL80211_CHAN_NO_HT &&
4612 channel_type != NL80211_CHAN_HT20 &&
4613 channel_type != NL80211_CHAN_HT40PLUS &&
4614 channel_type != NL80211_CHAN_HT40MINUS)
4615 err = -EINVAL;
4616 goto out;
4617 }
4618
4619 freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
4620 chan = rdev_freq_to_chan(rdev, freq, channel_type);
4621 if (chan == NULL) {
4622 err = -EINVAL;
4623 goto out;
4624 }
4625
4626 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
4627 if (!msg) {
4628 err = -ENOMEM;
4629 goto out;
4630 }
4631
4632 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
4633 NL80211_CMD_ACTION);
4634
4635 if (IS_ERR(hdr)) {
4636 err = PTR_ERR(hdr);
4637 goto free_msg;
4638 }
4639 err = cfg80211_mlme_action(rdev, dev, chan, channel_type,
4640 nla_data(info->attrs[NL80211_ATTR_FRAME]),
4641 nla_len(info->attrs[NL80211_ATTR_FRAME]),
4642 &cookie);
4643 if (err)
4644 goto free_msg;
4645
4646 NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie);
4647
4648 genlmsg_end(msg, hdr);
4649 err = genlmsg_reply(msg, info);
4650 goto out;
4651
4652 nla_put_failure:
4653 err = -ENOBUFS;
4654 free_msg:
4655 nlmsg_free(msg);
4656 out:
4657 cfg80211_unlock_rdev(rdev);
4658 dev_put(dev);
4659unlock_rtnl:
4660 rtnl_unlock();
4661 return err;
4662}
4663
4664static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
4665{
4666 struct cfg80211_registered_device *rdev;
4667 struct wireless_dev *wdev;
4668 struct net_device *dev;
4669 u8 ps_state;
4670 bool state;
4671 int err;
4672
4673 if (!info->attrs[NL80211_ATTR_PS_STATE]) {
4674 err = -EINVAL;
4675 goto out;
4676 }
4677
4678 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
4679
4680 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) {
4681 err = -EINVAL;
4682 goto out;
4683 }
4684
4685 rtnl_lock();
4686
4687 err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev);
4688 if (err)
4689 goto unlock_rdev;
4690
4691 wdev = dev->ieee80211_ptr;
4692
4693 if (!rdev->ops->set_power_mgmt) {
4694 err = -EOPNOTSUPP;
4695 goto unlock_rdev;
4696 }
4697
4698 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
4699
4700 if (state == wdev->ps)
4701 goto unlock_rdev;
4702
4703 wdev->ps = state;
4704
4705 if (rdev->ops->set_power_mgmt(wdev->wiphy, dev, wdev->ps,
4706 wdev->ps_timeout))
4707 /* assume this means it's off */
4708 wdev->ps = false;
4709
4710unlock_rdev:
4711 cfg80211_unlock_rdev(rdev);
4712 dev_put(dev);
4713 rtnl_unlock();
4714
4715out:
4716 return err;
4717}
4718
4719static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
4720{
4721 struct cfg80211_registered_device *rdev;
4722 enum nl80211_ps_state ps_state;
4723 struct wireless_dev *wdev;
4724 struct net_device *dev;
4725 struct sk_buff *msg;
4726 void *hdr;
4727 int err;
4728
4729 rtnl_lock();
4730
4731 err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev);
4732 if (err)
4733 goto unlock_rtnl;
4734
4735 wdev = dev->ieee80211_ptr;
4736
4737 if (!rdev->ops->set_power_mgmt) {
4738 err = -EOPNOTSUPP;
4739 goto out;
4740 }
4741
4742 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
4743 if (!msg) {
4744 err = -ENOMEM;
4745 goto out;
4746 }
4747
4748 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
4749 NL80211_CMD_GET_POWER_SAVE);
4750 if (!hdr) {
4751 err = -ENOMEM;
4752 goto free_msg;
4753 }
4754
4755 if (wdev->ps)
4756 ps_state = NL80211_PS_ENABLED;
4757 else
4758 ps_state = NL80211_PS_DISABLED;
4759
4760 NLA_PUT_U32(msg, NL80211_ATTR_PS_STATE, ps_state);
4761
4762 genlmsg_end(msg, hdr);
4763 err = genlmsg_reply(msg, info);
4764 goto out;
4765
4766nla_put_failure:
4767 err = -ENOBUFS;
4768
4769free_msg:
4770 nlmsg_free(msg);
4771
4772out:
4773 cfg80211_unlock_rdev(rdev);
4774 dev_put(dev);
4775
4776unlock_rtnl:
4777 rtnl_unlock();
4778
4779 return err;
4780}
4781
4057static struct genl_ops nl80211_ops[] = { 4782static struct genl_ops nl80211_ops[] = {
4058 { 4783 {
4059 .cmd = NL80211_CMD_GET_WIPHY, 4784 .cmd = NL80211_CMD_GET_WIPHY,
@@ -4293,7 +5018,73 @@ static struct genl_ops nl80211_ops[] = {
4293 .policy = nl80211_policy, 5018 .policy = nl80211_policy,
4294 .flags = GENL_ADMIN_PERM, 5019 .flags = GENL_ADMIN_PERM,
4295 }, 5020 },
5021 {
5022 .cmd = NL80211_CMD_GET_SURVEY,
5023 .policy = nl80211_policy,
5024 .dumpit = nl80211_dump_survey,
5025 },
5026 {
5027 .cmd = NL80211_CMD_SET_PMKSA,
5028 .doit = nl80211_setdel_pmksa,
5029 .policy = nl80211_policy,
5030 .flags = GENL_ADMIN_PERM,
5031 },
5032 {
5033 .cmd = NL80211_CMD_DEL_PMKSA,
5034 .doit = nl80211_setdel_pmksa,
5035 .policy = nl80211_policy,
5036 .flags = GENL_ADMIN_PERM,
5037 },
5038 {
5039 .cmd = NL80211_CMD_FLUSH_PMKSA,
5040 .doit = nl80211_flush_pmksa,
5041 .policy = nl80211_policy,
5042 .flags = GENL_ADMIN_PERM,
5043 },
5044 {
5045 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
5046 .doit = nl80211_remain_on_channel,
5047 .policy = nl80211_policy,
5048 .flags = GENL_ADMIN_PERM,
5049 },
5050 {
5051 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
5052 .doit = nl80211_cancel_remain_on_channel,
5053 .policy = nl80211_policy,
5054 .flags = GENL_ADMIN_PERM,
5055 },
5056 {
5057 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
5058 .doit = nl80211_set_tx_bitrate_mask,
5059 .policy = nl80211_policy,
5060 .flags = GENL_ADMIN_PERM,
5061 },
5062 {
5063 .cmd = NL80211_CMD_REGISTER_ACTION,
5064 .doit = nl80211_register_action,
5065 .policy = nl80211_policy,
5066 .flags = GENL_ADMIN_PERM,
5067 },
5068 {
5069 .cmd = NL80211_CMD_ACTION,
5070 .doit = nl80211_action,
5071 .policy = nl80211_policy,
5072 .flags = GENL_ADMIN_PERM,
5073 },
5074 {
5075 .cmd = NL80211_CMD_SET_POWER_SAVE,
5076 .doit = nl80211_set_power_save,
5077 .policy = nl80211_policy,
5078 .flags = GENL_ADMIN_PERM,
5079 },
5080 {
5081 .cmd = NL80211_CMD_GET_POWER_SAVE,
5082 .doit = nl80211_get_power_save,
5083 .policy = nl80211_policy,
5084 /* can be retrieved by unprivileged users */
5085 },
4296}; 5086};
5087
4297static struct genl_multicast_group nl80211_mlme_mcgrp = { 5088static struct genl_multicast_group nl80211_mlme_mcgrp = {
4298 .name = "mlme", 5089 .name = "mlme",
4299}; 5090};
@@ -4881,6 +5672,193 @@ nla_put_failure:
4881 nlmsg_free(msg); 5672 nlmsg_free(msg);
4882} 5673}
4883 5674
5675static void nl80211_send_remain_on_chan_event(
5676 int cmd, struct cfg80211_registered_device *rdev,
5677 struct net_device *netdev, u64 cookie,
5678 struct ieee80211_channel *chan,
5679 enum nl80211_channel_type channel_type,
5680 unsigned int duration, gfp_t gfp)
5681{
5682 struct sk_buff *msg;
5683 void *hdr;
5684
5685 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
5686 if (!msg)
5687 return;
5688
5689 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
5690 if (!hdr) {
5691 nlmsg_free(msg);
5692 return;
5693 }
5694
5695 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
5696 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
5697 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq);
5698 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, channel_type);
5699 NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie);
5700
5701 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL)
5702 NLA_PUT_U32(msg, NL80211_ATTR_DURATION, duration);
5703
5704 if (genlmsg_end(msg, hdr) < 0) {
5705 nlmsg_free(msg);
5706 return;
5707 }
5708
5709 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
5710 nl80211_mlme_mcgrp.id, gfp);
5711 return;
5712
5713 nla_put_failure:
5714 genlmsg_cancel(msg, hdr);
5715 nlmsg_free(msg);
5716}
5717
5718void nl80211_send_remain_on_channel(struct cfg80211_registered_device *rdev,
5719 struct net_device *netdev, u64 cookie,
5720 struct ieee80211_channel *chan,
5721 enum nl80211_channel_type channel_type,
5722 unsigned int duration, gfp_t gfp)
5723{
5724 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
5725 rdev, netdev, cookie, chan,
5726 channel_type, duration, gfp);
5727}
5728
5729void nl80211_send_remain_on_channel_cancel(
5730 struct cfg80211_registered_device *rdev, struct net_device *netdev,
5731 u64 cookie, struct ieee80211_channel *chan,
5732 enum nl80211_channel_type channel_type, gfp_t gfp)
5733{
5734 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
5735 rdev, netdev, cookie, chan,
5736 channel_type, 0, gfp);
5737}
5738
5739void nl80211_send_sta_event(struct cfg80211_registered_device *rdev,
5740 struct net_device *dev, const u8 *mac_addr,
5741 struct station_info *sinfo, gfp_t gfp)
5742{
5743 struct sk_buff *msg;
5744
5745 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
5746 if (!msg)
5747 return;
5748
5749 if (nl80211_send_station(msg, 0, 0, 0, dev, mac_addr, sinfo) < 0) {
5750 nlmsg_free(msg);
5751 return;
5752 }
5753
5754 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
5755 nl80211_mlme_mcgrp.id, gfp);
5756}
5757
5758int nl80211_send_action(struct cfg80211_registered_device *rdev,
5759 struct net_device *netdev, u32 nlpid,
5760 int freq, const u8 *buf, size_t len, gfp_t gfp)
5761{
5762 struct sk_buff *msg;
5763 void *hdr;
5764 int err;
5765
5766 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
5767 if (!msg)
5768 return -ENOMEM;
5769
5770 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ACTION);
5771 if (!hdr) {
5772 nlmsg_free(msg);
5773 return -ENOMEM;
5774 }
5775
5776 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
5777 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
5778 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, freq);
5779 NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf);
5780
5781 err = genlmsg_end(msg, hdr);
5782 if (err < 0) {
5783 nlmsg_free(msg);
5784 return err;
5785 }
5786
5787 err = genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid);
5788 if (err < 0)
5789 return err;
5790 return 0;
5791
5792 nla_put_failure:
5793 genlmsg_cancel(msg, hdr);
5794 nlmsg_free(msg);
5795 return -ENOBUFS;
5796}
5797
5798void nl80211_send_action_tx_status(struct cfg80211_registered_device *rdev,
5799 struct net_device *netdev, u64 cookie,
5800 const u8 *buf, size_t len, bool ack,
5801 gfp_t gfp)
5802{
5803 struct sk_buff *msg;
5804 void *hdr;
5805
5806 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
5807 if (!msg)
5808 return;
5809
5810 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ACTION_TX_STATUS);
5811 if (!hdr) {
5812 nlmsg_free(msg);
5813 return;
5814 }
5815
5816 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
5817 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
5818 NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf);
5819 NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie);
5820 if (ack)
5821 NLA_PUT_FLAG(msg, NL80211_ATTR_ACK);
5822
5823 if (genlmsg_end(msg, hdr) < 0) {
5824 nlmsg_free(msg);
5825 return;
5826 }
5827
5828 genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp);
5829 return;
5830
5831 nla_put_failure:
5832 genlmsg_cancel(msg, hdr);
5833 nlmsg_free(msg);
5834}
5835
5836static int nl80211_netlink_notify(struct notifier_block * nb,
5837 unsigned long state,
5838 void *_notify)
5839{
5840 struct netlink_notify *notify = _notify;
5841 struct cfg80211_registered_device *rdev;
5842 struct wireless_dev *wdev;
5843
5844 if (state != NETLINK_URELEASE)
5845 return NOTIFY_DONE;
5846
5847 rcu_read_lock();
5848
5849 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list)
5850 list_for_each_entry_rcu(wdev, &rdev->netdev_list, list)
5851 cfg80211_mlme_unregister_actions(wdev, notify->pid);
5852
5853 rcu_read_unlock();
5854
5855 return NOTIFY_DONE;
5856}
5857
5858static struct notifier_block nl80211_netlink_notifier = {
5859 .notifier_call = nl80211_netlink_notify,
5860};
5861
4884/* initialisation/exit functions */ 5862/* initialisation/exit functions */
4885 5863
4886int nl80211_init(void) 5864int nl80211_init(void)
@@ -4914,6 +5892,10 @@ int nl80211_init(void)
4914 goto err_out; 5892 goto err_out;
4915#endif 5893#endif
4916 5894
5895 err = netlink_register_notifier(&nl80211_netlink_notifier);
5896 if (err)
5897 goto err_out;
5898
4917 return 0; 5899 return 0;
4918 err_out: 5900 err_out:
4919 genl_unregister_family(&nl80211_fam); 5901 genl_unregister_family(&nl80211_fam);
@@ -4922,5 +5904,6 @@ int nl80211_init(void)
4922 5904
4923void nl80211_exit(void) 5905void nl80211_exit(void)
4924{ 5906{
5907 netlink_unregister_notifier(&nl80211_netlink_notifier);
4925 genl_unregister_family(&nl80211_fam); 5908 genl_unregister_family(&nl80211_fam);
4926} 5909}
diff --git a/net/wireless/nl80211.h b/net/wireless/nl80211.h
index 44cc2a76a1b0..4ca511102c6c 100644
--- a/net/wireless/nl80211.h
+++ b/net/wireless/nl80211.h
@@ -59,4 +59,27 @@ void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
59 struct net_device *netdev, const u8 *bssid, 59 struct net_device *netdev, const u8 *bssid,
60 gfp_t gfp); 60 gfp_t gfp);
61 61
62void nl80211_send_remain_on_channel(struct cfg80211_registered_device *rdev,
63 struct net_device *netdev,
64 u64 cookie,
65 struct ieee80211_channel *chan,
66 enum nl80211_channel_type channel_type,
67 unsigned int duration, gfp_t gfp);
68void nl80211_send_remain_on_channel_cancel(
69 struct cfg80211_registered_device *rdev, struct net_device *netdev,
70 u64 cookie, struct ieee80211_channel *chan,
71 enum nl80211_channel_type channel_type, gfp_t gfp);
72
73void nl80211_send_sta_event(struct cfg80211_registered_device *rdev,
74 struct net_device *dev, const u8 *mac_addr,
75 struct station_info *sinfo, gfp_t gfp);
76
77int nl80211_send_action(struct cfg80211_registered_device *rdev,
78 struct net_device *netdev, u32 nlpid, int freq,
79 const u8 *buf, size_t len, gfp_t gfp);
80void nl80211_send_action_tx_status(struct cfg80211_registered_device *rdev,
81 struct net_device *netdev, u64 cookie,
82 const u8 *buf, size_t len, bool ack,
83 gfp_t gfp);
84
62#endif /* __NET_WIRELESS_NL80211_H */ 85#endif /* __NET_WIRELESS_NL80211_H */
diff --git a/net/wireless/radiotap.c b/net/wireless/radiotap.c
index f591871a7b4f..1332c445d1c7 100644
--- a/net/wireless/radiotap.c
+++ b/net/wireless/radiotap.c
@@ -2,6 +2,16 @@
2 * Radiotap parser 2 * Radiotap parser
3 * 3 *
4 * Copyright 2007 Andy Green <andy@warmcat.com> 4 * Copyright 2007 Andy Green <andy@warmcat.com>
5 * Copyright 2009 Johannes Berg <johannes@sipsolutions.net>
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.
10 *
11 * Alternatively, this software may be distributed under the terms of BSD
12 * license.
13 *
14 * See COPYING for more details.
5 */ 15 */
6 16
7#include <net/cfg80211.h> 17#include <net/cfg80211.h>
@@ -10,6 +20,35 @@
10 20
11/* function prototypes and related defs are in include/net/cfg80211.h */ 21/* function prototypes and related defs are in include/net/cfg80211.h */
12 22
23static const struct radiotap_align_size rtap_namespace_sizes[] = {
24 [IEEE80211_RADIOTAP_TSFT] = { .align = 8, .size = 8, },
25 [IEEE80211_RADIOTAP_FLAGS] = { .align = 1, .size = 1, },
26 [IEEE80211_RADIOTAP_RATE] = { .align = 1, .size = 1, },
27 [IEEE80211_RADIOTAP_CHANNEL] = { .align = 2, .size = 4, },
28 [IEEE80211_RADIOTAP_FHSS] = { .align = 2, .size = 2, },
29 [IEEE80211_RADIOTAP_DBM_ANTSIGNAL] = { .align = 1, .size = 1, },
30 [IEEE80211_RADIOTAP_DBM_ANTNOISE] = { .align = 1, .size = 1, },
31 [IEEE80211_RADIOTAP_LOCK_QUALITY] = { .align = 2, .size = 2, },
32 [IEEE80211_RADIOTAP_TX_ATTENUATION] = { .align = 2, .size = 2, },
33 [IEEE80211_RADIOTAP_DB_TX_ATTENUATION] = { .align = 2, .size = 2, },
34 [IEEE80211_RADIOTAP_DBM_TX_POWER] = { .align = 1, .size = 1, },
35 [IEEE80211_RADIOTAP_ANTENNA] = { .align = 1, .size = 1, },
36 [IEEE80211_RADIOTAP_DB_ANTSIGNAL] = { .align = 1, .size = 1, },
37 [IEEE80211_RADIOTAP_DB_ANTNOISE] = { .align = 1, .size = 1, },
38 [IEEE80211_RADIOTAP_RX_FLAGS] = { .align = 2, .size = 2, },
39 [IEEE80211_RADIOTAP_TX_FLAGS] = { .align = 2, .size = 2, },
40 [IEEE80211_RADIOTAP_RTS_RETRIES] = { .align = 1, .size = 1, },
41 [IEEE80211_RADIOTAP_DATA_RETRIES] = { .align = 1, .size = 1, },
42 /*
43 * add more here as they are defined in radiotap.h
44 */
45};
46
47static const struct ieee80211_radiotap_namespace radiotap_ns = {
48 .n_bits = sizeof(rtap_namespace_sizes) / sizeof(rtap_namespace_sizes[0]),
49 .align_size = rtap_namespace_sizes,
50};
51
13/** 52/**
14 * ieee80211_radiotap_iterator_init - radiotap parser iterator initialization 53 * ieee80211_radiotap_iterator_init - radiotap parser iterator initialization
15 * @iterator: radiotap_iterator to initialize 54 * @iterator: radiotap_iterator to initialize
@@ -50,9 +89,9 @@
50 */ 89 */
51 90
52int ieee80211_radiotap_iterator_init( 91int ieee80211_radiotap_iterator_init(
53 struct ieee80211_radiotap_iterator *iterator, 92 struct ieee80211_radiotap_iterator *iterator,
54 struct ieee80211_radiotap_header *radiotap_header, 93 struct ieee80211_radiotap_header *radiotap_header,
55 int max_length) 94 int max_length, const struct ieee80211_radiotap_vendor_namespaces *vns)
56{ 95{
57 /* Linux only supports version 0 radiotap format */ 96 /* Linux only supports version 0 radiotap format */
58 if (radiotap_header->it_version) 97 if (radiotap_header->it_version)
@@ -62,19 +101,24 @@ int ieee80211_radiotap_iterator_init(
62 if (max_length < get_unaligned_le16(&radiotap_header->it_len)) 101 if (max_length < get_unaligned_le16(&radiotap_header->it_len))
63 return -EINVAL; 102 return -EINVAL;
64 103
65 iterator->rtheader = radiotap_header; 104 iterator->_rtheader = radiotap_header;
66 iterator->max_length = get_unaligned_le16(&radiotap_header->it_len); 105 iterator->_max_length = get_unaligned_le16(&radiotap_header->it_len);
67 iterator->arg_index = 0; 106 iterator->_arg_index = 0;
68 iterator->bitmap_shifter = get_unaligned_le32(&radiotap_header->it_present); 107 iterator->_bitmap_shifter = get_unaligned_le32(&radiotap_header->it_present);
69 iterator->arg = (u8 *)radiotap_header + sizeof(*radiotap_header); 108 iterator->_arg = (uint8_t *)radiotap_header + sizeof(*radiotap_header);
70 iterator->this_arg = NULL; 109 iterator->_reset_on_ext = 0;
110 iterator->_next_bitmap = &radiotap_header->it_present;
111 iterator->_next_bitmap++;
112 iterator->_vns = vns;
113 iterator->current_namespace = &radiotap_ns;
114 iterator->is_radiotap_ns = 1;
71 115
72 /* find payload start allowing for extended bitmap(s) */ 116 /* find payload start allowing for extended bitmap(s) */
73 117
74 if (unlikely(iterator->bitmap_shifter & (1<<IEEE80211_RADIOTAP_EXT))) { 118 if (iterator->_bitmap_shifter & (1<<IEEE80211_RADIOTAP_EXT)) {
75 while (get_unaligned_le32(iterator->arg) & 119 while (get_unaligned_le32(iterator->_arg) &
76 (1 << IEEE80211_RADIOTAP_EXT)) { 120 (1 << IEEE80211_RADIOTAP_EXT)) {
77 iterator->arg += sizeof(u32); 121 iterator->_arg += sizeof(uint32_t);
78 122
79 /* 123 /*
80 * check for insanity where the present bitmaps 124 * check for insanity where the present bitmaps
@@ -82,12 +126,13 @@ int ieee80211_radiotap_iterator_init(
82 * stated radiotap header length 126 * stated radiotap header length
83 */ 127 */
84 128
85 if (((ulong)iterator->arg - 129 if ((unsigned long)iterator->_arg -
86 (ulong)iterator->rtheader) > iterator->max_length) 130 (unsigned long)iterator->_rtheader >
131 (unsigned long)iterator->_max_length)
87 return -EINVAL; 132 return -EINVAL;
88 } 133 }
89 134
90 iterator->arg += sizeof(u32); 135 iterator->_arg += sizeof(uint32_t);
91 136
92 /* 137 /*
93 * no need to check again for blowing past stated radiotap 138 * no need to check again for blowing past stated radiotap
@@ -96,12 +141,36 @@ int ieee80211_radiotap_iterator_init(
96 */ 141 */
97 } 142 }
98 143
144 iterator->this_arg = iterator->_arg;
145
99 /* we are all initialized happily */ 146 /* we are all initialized happily */
100 147
101 return 0; 148 return 0;
102} 149}
103EXPORT_SYMBOL(ieee80211_radiotap_iterator_init); 150EXPORT_SYMBOL(ieee80211_radiotap_iterator_init);
104 151
152static void find_ns(struct ieee80211_radiotap_iterator *iterator,
153 uint32_t oui, uint8_t subns)
154{
155 int i;
156
157 iterator->current_namespace = NULL;
158
159 if (!iterator->_vns)
160 return;
161
162 for (i = 0; i < iterator->_vns->n_ns; i++) {
163 if (iterator->_vns->ns[i].oui != oui)
164 continue;
165 if (iterator->_vns->ns[i].subns != subns)
166 continue;
167
168 iterator->current_namespace = &iterator->_vns->ns[i];
169 break;
170 }
171}
172
173
105 174
106/** 175/**
107 * ieee80211_radiotap_iterator_next - return next radiotap parser iterator arg 176 * ieee80211_radiotap_iterator_next - return next radiotap parser iterator arg
@@ -127,99 +196,80 @@ EXPORT_SYMBOL(ieee80211_radiotap_iterator_init);
127 */ 196 */
128 197
129int ieee80211_radiotap_iterator_next( 198int ieee80211_radiotap_iterator_next(
130 struct ieee80211_radiotap_iterator *iterator) 199 struct ieee80211_radiotap_iterator *iterator)
131{ 200{
132 201 while (1) {
133 /*
134 * small length lookup table for all radiotap types we heard of
135 * starting from b0 in the bitmap, so we can walk the payload
136 * area of the radiotap header
137 *
138 * There is a requirement to pad args, so that args
139 * of a given length must begin at a boundary of that length
140 * -- but note that compound args are allowed (eg, 2 x u16
141 * for IEEE80211_RADIOTAP_CHANNEL) so total arg length is not
142 * a reliable indicator of alignment requirement.
143 *
144 * upper nybble: content alignment for arg
145 * lower nybble: content length for arg
146 */
147
148 static const u8 rt_sizes[] = {
149 [IEEE80211_RADIOTAP_TSFT] = 0x88,
150 [IEEE80211_RADIOTAP_FLAGS] = 0x11,
151 [IEEE80211_RADIOTAP_RATE] = 0x11,
152 [IEEE80211_RADIOTAP_CHANNEL] = 0x24,
153 [IEEE80211_RADIOTAP_FHSS] = 0x22,
154 [IEEE80211_RADIOTAP_DBM_ANTSIGNAL] = 0x11,
155 [IEEE80211_RADIOTAP_DBM_ANTNOISE] = 0x11,
156 [IEEE80211_RADIOTAP_LOCK_QUALITY] = 0x22,
157 [IEEE80211_RADIOTAP_TX_ATTENUATION] = 0x22,
158 [IEEE80211_RADIOTAP_DB_TX_ATTENUATION] = 0x22,
159 [IEEE80211_RADIOTAP_DBM_TX_POWER] = 0x11,
160 [IEEE80211_RADIOTAP_ANTENNA] = 0x11,
161 [IEEE80211_RADIOTAP_DB_ANTSIGNAL] = 0x11,
162 [IEEE80211_RADIOTAP_DB_ANTNOISE] = 0x11,
163 [IEEE80211_RADIOTAP_RX_FLAGS] = 0x22,
164 [IEEE80211_RADIOTAP_TX_FLAGS] = 0x22,
165 [IEEE80211_RADIOTAP_RTS_RETRIES] = 0x11,
166 [IEEE80211_RADIOTAP_DATA_RETRIES] = 0x11,
167 /*
168 * add more here as they are defined in
169 * include/net/ieee80211_radiotap.h
170 */
171 };
172
173 /*
174 * for every radiotap entry we can at
175 * least skip (by knowing the length)...
176 */
177
178 while (iterator->arg_index < sizeof(rt_sizes)) {
179 int hit = 0; 202 int hit = 0;
180 int pad; 203 int pad, align, size, subns, vnslen;
204 uint32_t oui;
181 205
182 if (!(iterator->bitmap_shifter & 1)) 206 /* if no more EXT bits, that's it */
207 if ((iterator->_arg_index % 32) == IEEE80211_RADIOTAP_EXT &&
208 !(iterator->_bitmap_shifter & 1))
209 return -ENOENT;
210
211 if (!(iterator->_bitmap_shifter & 1))
183 goto next_entry; /* arg not present */ 212 goto next_entry; /* arg not present */
184 213
214 /* get alignment/size of data */
215 switch (iterator->_arg_index % 32) {
216 case IEEE80211_RADIOTAP_RADIOTAP_NAMESPACE:
217 case IEEE80211_RADIOTAP_EXT:
218 align = 1;
219 size = 0;
220 break;
221 case IEEE80211_RADIOTAP_VENDOR_NAMESPACE:
222 align = 2;
223 size = 6;
224 break;
225 default:
226 if (!iterator->current_namespace ||
227 iterator->_arg_index >= iterator->current_namespace->n_bits) {
228 if (iterator->current_namespace == &radiotap_ns)
229 return -ENOENT;
230 align = 0;
231 } else {
232 align = iterator->current_namespace->align_size[iterator->_arg_index].align;
233 size = iterator->current_namespace->align_size[iterator->_arg_index].size;
234 }
235 if (!align) {
236 /* skip all subsequent data */
237 iterator->_arg = iterator->_next_ns_data;
238 /* give up on this namespace */
239 iterator->current_namespace = NULL;
240 goto next_entry;
241 }
242 break;
243 }
244
185 /* 245 /*
186 * arg is present, account for alignment padding 246 * arg is present, account for alignment padding
187 * 8-bit args can be at any alignment
188 * 16-bit args must start on 16-bit boundary
189 * 32-bit args must start on 32-bit boundary
190 * 64-bit args must start on 64-bit boundary
191 * 247 *
192 * note that total arg size can differ from alignment of 248 * Note that these alignments are relative to the start
193 * elements inside arg, so we use upper nybble of length 249 * of the radiotap header. There is no guarantee
194 * table to base alignment on
195 *
196 * also note: these alignments are ** relative to the
197 * start of the radiotap header **. There is no guarantee
198 * that the radiotap header itself is aligned on any 250 * that the radiotap header itself is aligned on any
199 * kind of boundary. 251 * kind of boundary.
200 * 252 *
201 * the above is why get_unaligned() is used to dereference 253 * The above is why get_unaligned() is used to dereference
202 * multibyte elements from the radiotap area 254 * multibyte elements from the radiotap area.
203 */ 255 */
204 256
205 pad = (((ulong)iterator->arg) - 257 pad = ((unsigned long)iterator->_arg -
206 ((ulong)iterator->rtheader)) & 258 (unsigned long)iterator->_rtheader) & (align - 1);
207 ((rt_sizes[iterator->arg_index] >> 4) - 1);
208 259
209 if (pad) 260 if (pad)
210 iterator->arg += 261 iterator->_arg += align - pad;
211 (rt_sizes[iterator->arg_index] >> 4) - pad;
212 262
213 /* 263 /*
214 * this is what we will return to user, but we need to 264 * this is what we will return to user, but we need to
215 * move on first so next call has something fresh to test 265 * move on first so next call has something fresh to test
216 */ 266 */
217 iterator->this_arg_index = iterator->arg_index; 267 iterator->this_arg_index = iterator->_arg_index;
218 iterator->this_arg = iterator->arg; 268 iterator->this_arg = iterator->_arg;
219 hit = 1; 269 iterator->this_arg_size = size;
220 270
221 /* internally move on the size of this arg */ 271 /* internally move on the size of this arg */
222 iterator->arg += rt_sizes[iterator->arg_index] & 0x0f; 272 iterator->_arg += size;
223 273
224 /* 274 /*
225 * check for insanity where we are given a bitmap that 275 * check for insanity where we are given a bitmap that
@@ -228,32 +278,73 @@ int ieee80211_radiotap_iterator_next(
228 * max_length on the last arg, never exceeding it. 278 * max_length on the last arg, never exceeding it.
229 */ 279 */
230 280
231 if (((ulong)iterator->arg - (ulong)iterator->rtheader) > 281 if ((unsigned long)iterator->_arg -
232 iterator->max_length) 282 (unsigned long)iterator->_rtheader >
283 (unsigned long)iterator->_max_length)
233 return -EINVAL; 284 return -EINVAL;
234 285
235 next_entry: 286 /* these special ones are valid in each bitmap word */
236 iterator->arg_index++; 287 switch (iterator->_arg_index % 32) {
237 if (unlikely((iterator->arg_index & 31) == 0)) { 288 case IEEE80211_RADIOTAP_VENDOR_NAMESPACE:
238 /* completed current u32 bitmap */ 289 iterator->_bitmap_shifter >>= 1;
239 if (iterator->bitmap_shifter & 1) { 290 iterator->_arg_index++;
240 /* b31 was set, there is more */ 291
241 /* move to next u32 bitmap */ 292 iterator->_reset_on_ext = 1;
242 iterator->bitmap_shifter = 293
243 get_unaligned_le32(iterator->next_bitmap); 294 vnslen = get_unaligned_le16(iterator->this_arg + 4);
244 iterator->next_bitmap++; 295 iterator->_next_ns_data = iterator->_arg + vnslen;
245 } else 296 oui = (*iterator->this_arg << 16) |
246 /* no more bitmaps: end */ 297 (*(iterator->this_arg + 1) << 8) |
247 iterator->arg_index = sizeof(rt_sizes); 298 *(iterator->this_arg + 2);
248 } else /* just try the next bit */ 299 subns = *(iterator->this_arg + 3);
249 iterator->bitmap_shifter >>= 1; 300
301 find_ns(iterator, oui, subns);
302
303 iterator->is_radiotap_ns = 0;
304 /* allow parsers to show this information */
305 iterator->this_arg_index =
306 IEEE80211_RADIOTAP_VENDOR_NAMESPACE;
307 iterator->this_arg_size += vnslen;
308 if ((unsigned long)iterator->this_arg +
309 iterator->this_arg_size -
310 (unsigned long)iterator->_rtheader >
311 (unsigned long)(unsigned long)iterator->_max_length)
312 return -EINVAL;
313 hit = 1;
314 break;
315 case IEEE80211_RADIOTAP_RADIOTAP_NAMESPACE:
316 iterator->_bitmap_shifter >>= 1;
317 iterator->_arg_index++;
318
319 iterator->_reset_on_ext = 1;
320 iterator->current_namespace = &radiotap_ns;
321 iterator->is_radiotap_ns = 1;
322 break;
323 case IEEE80211_RADIOTAP_EXT:
324 /*
325 * bit 31 was set, there is more
326 * -- move to next u32 bitmap
327 */
328 iterator->_bitmap_shifter =
329 get_unaligned_le32(iterator->_next_bitmap);
330 iterator->_next_bitmap++;
331 if (iterator->_reset_on_ext)
332 iterator->_arg_index = 0;
333 else
334 iterator->_arg_index++;
335 iterator->_reset_on_ext = 0;
336 break;
337 default:
338 /* we've got a hit! */
339 hit = 1;
340 next_entry:
341 iterator->_bitmap_shifter >>= 1;
342 iterator->_arg_index++;
343 }
250 344
251 /* if we found a valid arg earlier, return it now */ 345 /* if we found a valid arg earlier, return it now */
252 if (hit) 346 if (hit)
253 return 0; 347 return 0;
254 } 348 }
255
256 /* we don't know how to handle any more args, we're done */
257 return -ENOENT;
258} 349}
259EXPORT_SYMBOL(ieee80211_radiotap_iterator_next); 350EXPORT_SYMBOL(ieee80211_radiotap_iterator_next);
diff --git a/net/wireless/reg.c b/net/wireless/reg.c
index f256dfffbf46..422da20d1e5b 100644
--- a/net/wireless/reg.c
+++ b/net/wireless/reg.c
@@ -33,6 +33,7 @@
33 * 33 *
34 */ 34 */
35#include <linux/kernel.h> 35#include <linux/kernel.h>
36#include <linux/slab.h>
36#include <linux/list.h> 37#include <linux/list.h>
37#include <linux/random.h> 38#include <linux/random.h>
38#include <linux/nl80211.h> 39#include <linux/nl80211.h>
@@ -40,8 +41,18 @@
40#include <net/cfg80211.h> 41#include <net/cfg80211.h>
41#include "core.h" 42#include "core.h"
42#include "reg.h" 43#include "reg.h"
44#include "regdb.h"
43#include "nl80211.h" 45#include "nl80211.h"
44 46
47#ifdef CONFIG_CFG80211_REG_DEBUG
48#define REG_DBG_PRINT(format, args...) \
49 do { \
50 printk(KERN_DEBUG format , ## args); \
51 } while (0)
52#else
53#define REG_DBG_PRINT(args...)
54#endif
55
45/* Receipt of information from last regulatory request */ 56/* Receipt of information from last regulatory request */
46static struct regulatory_request *last_request; 57static struct regulatory_request *last_request;
47 58
@@ -124,107 +135,11 @@ static const struct ieee80211_regdomain *cfg80211_world_regdom =
124 &world_regdom; 135 &world_regdom;
125 136
126static char *ieee80211_regdom = "00"; 137static char *ieee80211_regdom = "00";
138static char user_alpha2[2];
127 139
128module_param(ieee80211_regdom, charp, 0444); 140module_param(ieee80211_regdom, charp, 0444);
129MODULE_PARM_DESC(ieee80211_regdom, "IEEE 802.11 regulatory domain code"); 141MODULE_PARM_DESC(ieee80211_regdom, "IEEE 802.11 regulatory domain code");
130 142
131#ifdef CONFIG_WIRELESS_OLD_REGULATORY
132/*
133 * We assume 40 MHz bandwidth for the old regulatory work.
134 * We make emphasis we are using the exact same frequencies
135 * as before
136 */
137
138static const struct ieee80211_regdomain us_regdom = {
139 .n_reg_rules = 6,
140 .alpha2 = "US",
141 .reg_rules = {
142 /* IEEE 802.11b/g, channels 1..11 */
143 REG_RULE(2412-10, 2462+10, 40, 6, 27, 0),
144 /* IEEE 802.11a, channel 36 */
145 REG_RULE(5180-10, 5180+10, 40, 6, 23, 0),
146 /* IEEE 802.11a, channel 40 */
147 REG_RULE(5200-10, 5200+10, 40, 6, 23, 0),
148 /* IEEE 802.11a, channel 44 */
149 REG_RULE(5220-10, 5220+10, 40, 6, 23, 0),
150 /* IEEE 802.11a, channels 48..64 */
151 REG_RULE(5240-10, 5320+10, 40, 6, 23, 0),
152 /* IEEE 802.11a, channels 149..165, outdoor */
153 REG_RULE(5745-10, 5825+10, 40, 6, 30, 0),
154 }
155};
156
157static const struct ieee80211_regdomain jp_regdom = {
158 .n_reg_rules = 3,
159 .alpha2 = "JP",
160 .reg_rules = {
161 /* IEEE 802.11b/g, channels 1..14 */
162 REG_RULE(2412-10, 2484+10, 40, 6, 20, 0),
163 /* IEEE 802.11a, channels 34..48 */
164 REG_RULE(5170-10, 5240+10, 40, 6, 20,
165 NL80211_RRF_PASSIVE_SCAN),
166 /* IEEE 802.11a, channels 52..64 */
167 REG_RULE(5260-10, 5320+10, 40, 6, 20,
168 NL80211_RRF_NO_IBSS |
169 NL80211_RRF_DFS),
170 }
171};
172
173static const struct ieee80211_regdomain eu_regdom = {
174 .n_reg_rules = 6,
175 /*
176 * This alpha2 is bogus, we leave it here just for stupid
177 * backward compatibility
178 */
179 .alpha2 = "EU",
180 .reg_rules = {
181 /* IEEE 802.11b/g, channels 1..13 */
182 REG_RULE(2412-10, 2472+10, 40, 6, 20, 0),
183 /* IEEE 802.11a, channel 36 */
184 REG_RULE(5180-10, 5180+10, 40, 6, 23,
185 NL80211_RRF_PASSIVE_SCAN),
186 /* IEEE 802.11a, channel 40 */
187 REG_RULE(5200-10, 5200+10, 40, 6, 23,
188 NL80211_RRF_PASSIVE_SCAN),
189 /* IEEE 802.11a, channel 44 */
190 REG_RULE(5220-10, 5220+10, 40, 6, 23,
191 NL80211_RRF_PASSIVE_SCAN),
192 /* IEEE 802.11a, channels 48..64 */
193 REG_RULE(5240-10, 5320+10, 40, 6, 20,
194 NL80211_RRF_NO_IBSS |
195 NL80211_RRF_DFS),
196 /* IEEE 802.11a, channels 100..140 */
197 REG_RULE(5500-10, 5700+10, 40, 6, 30,
198 NL80211_RRF_NO_IBSS |
199 NL80211_RRF_DFS),
200 }
201};
202
203static const struct ieee80211_regdomain *static_regdom(char *alpha2)
204{
205 if (alpha2[0] == 'U' && alpha2[1] == 'S')
206 return &us_regdom;
207 if (alpha2[0] == 'J' && alpha2[1] == 'P')
208 return &jp_regdom;
209 if (alpha2[0] == 'E' && alpha2[1] == 'U')
210 return &eu_regdom;
211 /* Default, as per the old rules */
212 return &us_regdom;
213}
214
215static bool is_old_static_regdom(const struct ieee80211_regdomain *rd)
216{
217 if (rd == &us_regdom || rd == &jp_regdom || rd == &eu_regdom)
218 return true;
219 return false;
220}
221#else
222static inline bool is_old_static_regdom(const struct ieee80211_regdomain *rd)
223{
224 return false;
225}
226#endif
227
228static void reset_regdomains(void) 143static void reset_regdomains(void)
229{ 144{
230 /* avoid freeing static information or freeing something twice */ 145 /* avoid freeing static information or freeing something twice */
@@ -234,8 +149,6 @@ static void reset_regdomains(void)
234 cfg80211_world_regdom = NULL; 149 cfg80211_world_regdom = NULL;
235 if (cfg80211_regdomain == &world_regdom) 150 if (cfg80211_regdomain == &world_regdom)
236 cfg80211_regdomain = NULL; 151 cfg80211_regdomain = NULL;
237 if (is_old_static_regdom(cfg80211_regdomain))
238 cfg80211_regdomain = NULL;
239 152
240 kfree(cfg80211_regdomain); 153 kfree(cfg80211_regdomain);
241 kfree(cfg80211_world_regdom); 154 kfree(cfg80211_world_regdom);
@@ -341,6 +254,27 @@ static bool regdom_changes(const char *alpha2)
341 return true; 254 return true;
342} 255}
343 256
257/*
258 * The NL80211_REGDOM_SET_BY_USER regdom alpha2 is cached, this lets
259 * you know if a valid regulatory hint with NL80211_REGDOM_SET_BY_USER
260 * has ever been issued.
261 */
262static bool is_user_regdom_saved(void)
263{
264 if (user_alpha2[0] == '9' && user_alpha2[1] == '7')
265 return false;
266
267 /* This would indicate a mistake on the design */
268 if (WARN((!is_world_regdom(user_alpha2) &&
269 !is_an_alpha2(user_alpha2)),
270 "Unexpected user alpha2: %c%c\n",
271 user_alpha2[0],
272 user_alpha2[1]))
273 return false;
274
275 return true;
276}
277
344/** 278/**
345 * country_ie_integrity_changes - tells us if the country IE has changed 279 * country_ie_integrity_changes - tells us if the country IE has changed
346 * @checksum: checksum of country IE of fields we are interested in 280 * @checksum: checksum of country IE of fields we are interested in
@@ -360,6 +294,96 @@ static bool country_ie_integrity_changes(u32 checksum)
360 return false; 294 return false;
361} 295}
362 296
297static int reg_copy_regd(const struct ieee80211_regdomain **dst_regd,
298 const struct ieee80211_regdomain *src_regd)
299{
300 struct ieee80211_regdomain *regd;
301 int size_of_regd = 0;
302 unsigned int i;
303
304 size_of_regd = sizeof(struct ieee80211_regdomain) +
305 ((src_regd->n_reg_rules + 1) * sizeof(struct ieee80211_reg_rule));
306
307 regd = kzalloc(size_of_regd, GFP_KERNEL);
308 if (!regd)
309 return -ENOMEM;
310
311 memcpy(regd, src_regd, sizeof(struct ieee80211_regdomain));
312
313 for (i = 0; i < src_regd->n_reg_rules; i++)
314 memcpy(&regd->reg_rules[i], &src_regd->reg_rules[i],
315 sizeof(struct ieee80211_reg_rule));
316
317 *dst_regd = regd;
318 return 0;
319}
320
321#ifdef CONFIG_CFG80211_INTERNAL_REGDB
322struct reg_regdb_search_request {
323 char alpha2[2];
324 struct list_head list;
325};
326
327static LIST_HEAD(reg_regdb_search_list);
328static DEFINE_MUTEX(reg_regdb_search_mutex);
329
330static void reg_regdb_search(struct work_struct *work)
331{
332 struct reg_regdb_search_request *request;
333 const struct ieee80211_regdomain *curdom, *regdom;
334 int i, r;
335
336 mutex_lock(&reg_regdb_search_mutex);
337 while (!list_empty(&reg_regdb_search_list)) {
338 request = list_first_entry(&reg_regdb_search_list,
339 struct reg_regdb_search_request,
340 list);
341 list_del(&request->list);
342
343 for (i=0; i<reg_regdb_size; i++) {
344 curdom = reg_regdb[i];
345
346 if (!memcmp(request->alpha2, curdom->alpha2, 2)) {
347 r = reg_copy_regd(&regdom, curdom);
348 if (r)
349 break;
350 mutex_lock(&cfg80211_mutex);
351 set_regdom(regdom);
352 mutex_unlock(&cfg80211_mutex);
353 break;
354 }
355 }
356
357 kfree(request);
358 }
359 mutex_unlock(&reg_regdb_search_mutex);
360}
361
362static DECLARE_WORK(reg_regdb_work, reg_regdb_search);
363
364static void reg_regdb_query(const char *alpha2)
365{
366 struct reg_regdb_search_request *request;
367
368 if (!alpha2)
369 return;
370
371 request = kzalloc(sizeof(struct reg_regdb_search_request), GFP_KERNEL);
372 if (!request)
373 return;
374
375 memcpy(request->alpha2, alpha2, 2);
376
377 mutex_lock(&reg_regdb_search_mutex);
378 list_add_tail(&request->list, &reg_regdb_search_list);
379 mutex_unlock(&reg_regdb_search_mutex);
380
381 schedule_work(&reg_regdb_work);
382}
383#else
384static inline void reg_regdb_query(const char *alpha2) {}
385#endif /* CONFIG_CFG80211_INTERNAL_REGDB */
386
363/* 387/*
364 * This lets us keep regulatory code which is updated on a regulatory 388 * This lets us keep regulatory code which is updated on a regulatory
365 * basis in userspace. 389 * basis in userspace.
@@ -379,6 +403,9 @@ static int call_crda(const char *alpha2)
379 printk(KERN_INFO "cfg80211: Calling CRDA to update world " 403 printk(KERN_INFO "cfg80211: Calling CRDA to update world "
380 "regulatory domain\n"); 404 "regulatory domain\n");
381 405
406 /* query internal regulatory database (if it exists) */
407 reg_regdb_query(alpha2);
408
382 country_env[8] = alpha2[0]; 409 country_env[8] = alpha2[0];
383 country_env[9] = alpha2[1]; 410 country_env[9] = alpha2[1];
384 411
@@ -479,12 +506,212 @@ static bool freq_in_rule_band(const struct ieee80211_freq_range *freq_range,
479} 506}
480 507
481/* 508/*
509 * This is a work around for sanity checking ieee80211_channel_to_frequency()'s
510 * work. ieee80211_channel_to_frequency() can for example currently provide a
511 * 2 GHz channel when in fact a 5 GHz channel was desired. An example would be
512 * an AP providing channel 8 on a country IE triplet when it sent this on the
513 * 5 GHz band, that channel is designed to be channel 8 on 5 GHz, not a 2 GHz
514 * channel.
515 *
516 * This can be removed once ieee80211_channel_to_frequency() takes in a band.
517 */
518static bool chan_in_band(int chan, enum ieee80211_band band)
519{
520 int center_freq = ieee80211_channel_to_frequency(chan);
521
522 switch (band) {
523 case IEEE80211_BAND_2GHZ:
524 if (center_freq <= 2484)
525 return true;
526 return false;
527 case IEEE80211_BAND_5GHZ:
528 if (center_freq >= 5005)
529 return true;
530 return false;
531 default:
532 return false;
533 }
534}
535
536/*
537 * Some APs may send a country IE triplet for each channel they
538 * support and while this is completely overkill and silly we still
539 * need to support it. We avoid making a single rule for each channel
540 * though and to help us with this we use this helper to find the
541 * actual subband end channel. These type of country IE triplet
542 * scenerios are handled then, all yielding two regulaotry rules from
543 * parsing a country IE:
544 *
545 * [1]
546 * [2]
547 * [36]
548 * [40]
549 *
550 * [1]
551 * [2-4]
552 * [5-12]
553 * [36]
554 * [40-44]
555 *
556 * [1-4]
557 * [5-7]
558 * [36-44]
559 * [48-64]
560 *
561 * [36-36]
562 * [40-40]
563 * [44-44]
564 * [48-48]
565 * [52-52]
566 * [56-56]
567 * [60-60]
568 * [64-64]
569 * [100-100]
570 * [104-104]
571 * [108-108]
572 * [112-112]
573 * [116-116]
574 * [120-120]
575 * [124-124]
576 * [128-128]
577 * [132-132]
578 * [136-136]
579 * [140-140]
580 *
581 * Returns 0 if the IE has been found to be invalid in the middle
582 * somewhere.
583 */
584static int max_subband_chan(enum ieee80211_band band,
585 int orig_cur_chan,
586 int orig_end_channel,
587 s8 orig_max_power,
588 u8 **country_ie,
589 u8 *country_ie_len)
590{
591 u8 *triplets_start = *country_ie;
592 u8 len_at_triplet = *country_ie_len;
593 int end_subband_chan = orig_end_channel;
594
595 /*
596 * We'll deal with padding for the caller unless
597 * its not immediate and we don't process any channels
598 */
599 if (*country_ie_len == 1) {
600 *country_ie += 1;
601 *country_ie_len -= 1;
602 return orig_end_channel;
603 }
604
605 /* Move to the next triplet and then start search */
606 *country_ie += 3;
607 *country_ie_len -= 3;
608
609 if (!chan_in_band(orig_cur_chan, band))
610 return 0;
611
612 while (*country_ie_len >= 3) {
613 int end_channel = 0;
614 struct ieee80211_country_ie_triplet *triplet =
615 (struct ieee80211_country_ie_triplet *) *country_ie;
616 int cur_channel = 0, next_expected_chan;
617
618 /* means last triplet is completely unrelated to this one */
619 if (triplet->ext.reg_extension_id >=
620 IEEE80211_COUNTRY_EXTENSION_ID) {
621 *country_ie -= 3;
622 *country_ie_len += 3;
623 break;
624 }
625
626 if (triplet->chans.first_channel == 0) {
627 *country_ie += 1;
628 *country_ie_len -= 1;
629 if (*country_ie_len != 0)
630 return 0;
631 break;
632 }
633
634 if (triplet->chans.num_channels == 0)
635 return 0;
636
637 /* Monitonically increasing channel order */
638 if (triplet->chans.first_channel <= end_subband_chan)
639 return 0;
640
641 if (!chan_in_band(triplet->chans.first_channel, band))
642 return 0;
643
644 /* 2 GHz */
645 if (triplet->chans.first_channel <= 14) {
646 end_channel = triplet->chans.first_channel +
647 triplet->chans.num_channels - 1;
648 }
649 else {
650 end_channel = triplet->chans.first_channel +
651 (4 * (triplet->chans.num_channels - 1));
652 }
653
654 if (!chan_in_band(end_channel, band))
655 return 0;
656
657 if (orig_max_power != triplet->chans.max_power) {
658 *country_ie -= 3;
659 *country_ie_len += 3;
660 break;
661 }
662
663 cur_channel = triplet->chans.first_channel;
664
665 /* The key is finding the right next expected channel */
666 if (band == IEEE80211_BAND_2GHZ)
667 next_expected_chan = end_subband_chan + 1;
668 else
669 next_expected_chan = end_subband_chan + 4;
670
671 if (cur_channel != next_expected_chan) {
672 *country_ie -= 3;
673 *country_ie_len += 3;
674 break;
675 }
676
677 end_subband_chan = end_channel;
678
679 /* Move to the next one */
680 *country_ie += 3;
681 *country_ie_len -= 3;
682
683 /*
684 * Padding needs to be dealt with if we processed
685 * some channels.
686 */
687 if (*country_ie_len == 1) {
688 *country_ie += 1;
689 *country_ie_len -= 1;
690 break;
691 }
692
693 /* If seen, the IE is invalid */
694 if (*country_ie_len == 2)
695 return 0;
696 }
697
698 if (end_subband_chan == orig_end_channel) {
699 *country_ie = triplets_start;
700 *country_ie_len = len_at_triplet;
701 return orig_end_channel;
702 }
703
704 return end_subband_chan;
705}
706
707/*
482 * Converts a country IE to a regulatory domain. A regulatory domain 708 * Converts a country IE to a regulatory domain. A regulatory domain
483 * structure has a lot of information which the IE doesn't yet have, 709 * structure has a lot of information which the IE doesn't yet have,
484 * so for the other values we use upper max values as we will intersect 710 * so for the other values we use upper max values as we will intersect
485 * with our userspace regulatory agent to get lower bounds. 711 * with our userspace regulatory agent to get lower bounds.
486 */ 712 */
487static struct ieee80211_regdomain *country_ie_2_rd( 713static struct ieee80211_regdomain *country_ie_2_rd(
714 enum ieee80211_band band,
488 u8 *country_ie, 715 u8 *country_ie,
489 u8 country_ie_len, 716 u8 country_ie_len,
490 u32 *checksum) 717 u32 *checksum)
@@ -546,10 +773,29 @@ static struct ieee80211_regdomain *country_ie_2_rd(
546 continue; 773 continue;
547 } 774 }
548 775
776 /*
777 * APs can add padding to make length divisible
778 * by two, required by the spec.
779 */
780 if (triplet->chans.first_channel == 0) {
781 country_ie++;
782 country_ie_len--;
783 /* This is expected to be at the very end only */
784 if (country_ie_len != 0)
785 return NULL;
786 break;
787 }
788
789 if (triplet->chans.num_channels == 0)
790 return NULL;
791
792 if (!chan_in_band(triplet->chans.first_channel, band))
793 return NULL;
794
549 /* 2 GHz */ 795 /* 2 GHz */
550 if (triplet->chans.first_channel <= 14) 796 if (band == IEEE80211_BAND_2GHZ)
551 end_channel = triplet->chans.first_channel + 797 end_channel = triplet->chans.first_channel +
552 triplet->chans.num_channels; 798 triplet->chans.num_channels - 1;
553 else 799 else
554 /* 800 /*
555 * 5 GHz -- For example in country IEs if the first 801 * 5 GHz -- For example in country IEs if the first
@@ -564,6 +810,24 @@ static struct ieee80211_regdomain *country_ie_2_rd(
564 (4 * (triplet->chans.num_channels - 1)); 810 (4 * (triplet->chans.num_channels - 1));
565 811
566 cur_channel = triplet->chans.first_channel; 812 cur_channel = triplet->chans.first_channel;
813
814 /*
815 * Enhancement for APs that send a triplet for every channel
816 * or for whatever reason sends triplets with multiple channels
817 * separated when in fact they should be together.
818 */
819 end_channel = max_subband_chan(band,
820 cur_channel,
821 end_channel,
822 triplet->chans.max_power,
823 &country_ie,
824 &country_ie_len);
825 if (!end_channel)
826 return NULL;
827
828 if (!chan_in_band(end_channel, band))
829 return NULL;
830
567 cur_sub_max_channel = end_channel; 831 cur_sub_max_channel = end_channel;
568 832
569 /* Basic sanity check */ 833 /* Basic sanity check */
@@ -594,10 +858,13 @@ static struct ieee80211_regdomain *country_ie_2_rd(
594 858
595 last_sub_max_channel = cur_sub_max_channel; 859 last_sub_max_channel = cur_sub_max_channel;
596 860
597 country_ie += 3;
598 country_ie_len -= 3;
599 num_rules++; 861 num_rules++;
600 862
863 if (country_ie_len >= 3) {
864 country_ie += 3;
865 country_ie_len -= 3;
866 }
867
601 /* 868 /*
602 * Note: this is not a IEEE requirement but 869 * Note: this is not a IEEE requirement but
603 * simply a memory requirement 870 * simply a memory requirement
@@ -640,6 +907,12 @@ static struct ieee80211_regdomain *country_ie_2_rd(
640 continue; 907 continue;
641 } 908 }
642 909
910 if (triplet->chans.first_channel == 0) {
911 country_ie++;
912 country_ie_len--;
913 break;
914 }
915
643 reg_rule = &rd->reg_rules[i]; 916 reg_rule = &rd->reg_rules[i];
644 freq_range = &reg_rule->freq_range; 917 freq_range = &reg_rule->freq_range;
645 power_rule = &reg_rule->power_rule; 918 power_rule = &reg_rule->power_rule;
@@ -647,13 +920,20 @@ static struct ieee80211_regdomain *country_ie_2_rd(
647 reg_rule->flags = flags; 920 reg_rule->flags = flags;
648 921
649 /* 2 GHz */ 922 /* 2 GHz */
650 if (triplet->chans.first_channel <= 14) 923 if (band == IEEE80211_BAND_2GHZ)
651 end_channel = triplet->chans.first_channel + 924 end_channel = triplet->chans.first_channel +
652 triplet->chans.num_channels; 925 triplet->chans.num_channels -1;
653 else 926 else
654 end_channel = triplet->chans.first_channel + 927 end_channel = triplet->chans.first_channel +
655 (4 * (triplet->chans.num_channels - 1)); 928 (4 * (triplet->chans.num_channels - 1));
656 929
930 end_channel = max_subband_chan(band,
931 triplet->chans.first_channel,
932 end_channel,
933 triplet->chans.max_power,
934 &country_ie,
935 &country_ie_len);
936
657 /* 937 /*
658 * The +10 is since the regulatory domain expects 938 * The +10 is since the regulatory domain expects
659 * the actual band edge, not the center of freq for 939 * the actual band edge, not the center of freq for
@@ -674,12 +954,15 @@ static struct ieee80211_regdomain *country_ie_2_rd(
674 */ 954 */
675 freq_range->max_bandwidth_khz = MHZ_TO_KHZ(40); 955 freq_range->max_bandwidth_khz = MHZ_TO_KHZ(40);
676 power_rule->max_antenna_gain = DBI_TO_MBI(100); 956 power_rule->max_antenna_gain = DBI_TO_MBI(100);
677 power_rule->max_eirp = DBM_TO_MBM(100); 957 power_rule->max_eirp = DBM_TO_MBM(triplet->chans.max_power);
678 958
679 country_ie += 3;
680 country_ie_len -= 3;
681 i++; 959 i++;
682 960
961 if (country_ie_len >= 3) {
962 country_ie += 3;
963 country_ie_len -= 3;
964 }
965
683 BUG_ON(i > NL80211_MAX_SUPP_REG_RULES); 966 BUG_ON(i > NL80211_MAX_SUPP_REG_RULES);
684 } 967 }
685 968
@@ -975,25 +1258,21 @@ static void handle_channel(struct wiphy *wiphy, enum ieee80211_band band,
975 if (r == -ERANGE && 1258 if (r == -ERANGE &&
976 last_request->initiator == 1259 last_request->initiator ==
977 NL80211_REGDOM_SET_BY_COUNTRY_IE) { 1260 NL80211_REGDOM_SET_BY_COUNTRY_IE) {
978#ifdef CONFIG_CFG80211_REG_DEBUG 1261 REG_DBG_PRINT("cfg80211: Leaving channel %d MHz "
979 printk(KERN_DEBUG "cfg80211: Leaving channel %d MHz "
980 "intact on %s - no rule found in band on " 1262 "intact on %s - no rule found in band on "
981 "Country IE\n", 1263 "Country IE\n",
982 chan->center_freq, wiphy_name(wiphy)); 1264 chan->center_freq, wiphy_name(wiphy));
983#endif
984 } else { 1265 } else {
985 /* 1266 /*
986 * In this case we know the country IE has at least one reg rule 1267 * In this case we know the country IE has at least one reg rule
987 * for the band so we respect its band definitions 1268 * for the band so we respect its band definitions
988 */ 1269 */
989#ifdef CONFIG_CFG80211_REG_DEBUG
990 if (last_request->initiator == 1270 if (last_request->initiator ==
991 NL80211_REGDOM_SET_BY_COUNTRY_IE) 1271 NL80211_REGDOM_SET_BY_COUNTRY_IE)
992 printk(KERN_DEBUG "cfg80211: Disabling " 1272 REG_DBG_PRINT("cfg80211: Disabling "
993 "channel %d MHz on %s due to " 1273 "channel %d MHz on %s due to "
994 "Country IE\n", 1274 "Country IE\n",
995 chan->center_freq, wiphy_name(wiphy)); 1275 chan->center_freq, wiphy_name(wiphy));
996#endif
997 flags |= IEEE80211_CHAN_DISABLED; 1276 flags |= IEEE80211_CHAN_DISABLED;
998 chan->flags = flags; 1277 chan->flags = flags;
999 } 1278 }
@@ -1008,7 +1287,7 @@ static void handle_channel(struct wiphy *wiphy, enum ieee80211_band band,
1008 1287
1009 if (last_request->initiator == NL80211_REGDOM_SET_BY_DRIVER && 1288 if (last_request->initiator == NL80211_REGDOM_SET_BY_DRIVER &&
1010 request_wiphy && request_wiphy == wiphy && 1289 request_wiphy && request_wiphy == wiphy &&
1011 request_wiphy->strict_regulatory) { 1290 request_wiphy->flags & WIPHY_FLAG_STRICT_REGULATORY) {
1012 /* 1291 /*
1013 * This gaurantees the driver's requested regulatory domain 1292 * This gaurantees the driver's requested regulatory domain
1014 * will always be used as a base for further regulatory 1293 * will always be used as a base for further regulatory
@@ -1051,13 +1330,13 @@ static bool ignore_reg_update(struct wiphy *wiphy,
1051 if (!last_request) 1330 if (!last_request)
1052 return true; 1331 return true;
1053 if (initiator == NL80211_REGDOM_SET_BY_CORE && 1332 if (initiator == NL80211_REGDOM_SET_BY_CORE &&
1054 wiphy->custom_regulatory) 1333 wiphy->flags & WIPHY_FLAG_CUSTOM_REGULATORY)
1055 return true; 1334 return true;
1056 /* 1335 /*
1057 * wiphy->regd will be set once the device has its own 1336 * wiphy->regd will be set once the device has its own
1058 * desired regulatory domain set 1337 * desired regulatory domain set
1059 */ 1338 */
1060 if (wiphy->strict_regulatory && !wiphy->regd && 1339 if (wiphy->flags & WIPHY_FLAG_STRICT_REGULATORY && !wiphy->regd &&
1061 !is_world_regdom(last_request->alpha2)) 1340 !is_world_regdom(last_request->alpha2))
1062 return true; 1341 return true;
1063 return false; 1342 return false;
@@ -1093,7 +1372,7 @@ static void handle_reg_beacon(struct wiphy *wiphy,
1093 1372
1094 chan->beacon_found = true; 1373 chan->beacon_found = true;
1095 1374
1096 if (wiphy->disable_beacon_hints) 1375 if (wiphy->flags & WIPHY_FLAG_DISABLE_BEACON_HINTS)
1097 return; 1376 return;
1098 1377
1099 chan_before.center_freq = chan->center_freq; 1378 chan_before.center_freq = chan->center_freq;
@@ -1164,7 +1443,7 @@ static bool reg_is_world_roaming(struct wiphy *wiphy)
1164 return true; 1443 return true;
1165 if (last_request && 1444 if (last_request &&
1166 last_request->initiator != NL80211_REGDOM_SET_BY_COUNTRY_IE && 1445 last_request->initiator != NL80211_REGDOM_SET_BY_COUNTRY_IE &&
1167 wiphy->custom_regulatory) 1446 wiphy->flags & WIPHY_FLAG_CUSTOM_REGULATORY)
1168 return true; 1447 return true;
1169 return false; 1448 return false;
1170} 1449}
@@ -1367,30 +1646,6 @@ void wiphy_apply_custom_regulatory(struct wiphy *wiphy,
1367} 1646}
1368EXPORT_SYMBOL(wiphy_apply_custom_regulatory); 1647EXPORT_SYMBOL(wiphy_apply_custom_regulatory);
1369 1648
1370static int reg_copy_regd(const struct ieee80211_regdomain **dst_regd,
1371 const struct ieee80211_regdomain *src_regd)
1372{
1373 struct ieee80211_regdomain *regd;
1374 int size_of_regd = 0;
1375 unsigned int i;
1376
1377 size_of_regd = sizeof(struct ieee80211_regdomain) +
1378 ((src_regd->n_reg_rules + 1) * sizeof(struct ieee80211_reg_rule));
1379
1380 regd = kzalloc(size_of_regd, GFP_KERNEL);
1381 if (!regd)
1382 return -ENOMEM;
1383
1384 memcpy(regd, src_regd, sizeof(struct ieee80211_regdomain));
1385
1386 for (i = 0; i < src_regd->n_reg_rules; i++)
1387 memcpy(&regd->reg_rules[i], &src_regd->reg_rules[i],
1388 sizeof(struct ieee80211_reg_rule));
1389
1390 *dst_regd = regd;
1391 return 0;
1392}
1393
1394/* 1649/*
1395 * Return value which can be used by ignore_request() to indicate 1650 * Return value which can be used by ignore_request() to indicate
1396 * it has been determined we should intersect two regulatory domains 1651 * it has been determined we should intersect two regulatory domains
@@ -1412,7 +1667,7 @@ static int ignore_request(struct wiphy *wiphy,
1412 1667
1413 switch (pending_request->initiator) { 1668 switch (pending_request->initiator) {
1414 case NL80211_REGDOM_SET_BY_CORE: 1669 case NL80211_REGDOM_SET_BY_CORE:
1415 return -EINVAL; 1670 return 0;
1416 case NL80211_REGDOM_SET_BY_COUNTRY_IE: 1671 case NL80211_REGDOM_SET_BY_COUNTRY_IE:
1417 1672
1418 last_wiphy = wiphy_idx_to_wiphy(last_request->wiphy_idx); 1673 last_wiphy = wiphy_idx_to_wiphy(last_request->wiphy_idx);
@@ -1443,8 +1698,6 @@ static int ignore_request(struct wiphy *wiphy,
1443 return REG_INTERSECT; 1698 return REG_INTERSECT;
1444 case NL80211_REGDOM_SET_BY_DRIVER: 1699 case NL80211_REGDOM_SET_BY_DRIVER:
1445 if (last_request->initiator == NL80211_REGDOM_SET_BY_CORE) { 1700 if (last_request->initiator == NL80211_REGDOM_SET_BY_CORE) {
1446 if (is_old_static_regdom(cfg80211_regdomain))
1447 return 0;
1448 if (regdom_changes(pending_request->alpha2)) 1701 if (regdom_changes(pending_request->alpha2))
1449 return 0; 1702 return 0;
1450 return -EALREADY; 1703 return -EALREADY;
@@ -1481,8 +1734,7 @@ static int ignore_request(struct wiphy *wiphy,
1481 return -EAGAIN; 1734 return -EAGAIN;
1482 } 1735 }
1483 1736
1484 if (!is_old_static_regdom(cfg80211_regdomain) && 1737 if (!regdom_changes(pending_request->alpha2))
1485 !regdom_changes(pending_request->alpha2))
1486 return -EALREADY; 1738 return -EALREADY;
1487 1739
1488 return 0; 1740 return 0;
@@ -1554,6 +1806,11 @@ new_request:
1554 1806
1555 pending_request = NULL; 1807 pending_request = NULL;
1556 1808
1809 if (last_request->initiator == NL80211_REGDOM_SET_BY_USER) {
1810 user_alpha2[0] = last_request->alpha2[0];
1811 user_alpha2[1] = last_request->alpha2[1];
1812 }
1813
1557 /* When r == REG_INTERSECT we do need to call CRDA */ 1814 /* When r == REG_INTERSECT we do need to call CRDA */
1558 if (r < 0) { 1815 if (r < 0) {
1559 /* 1816 /*
@@ -1591,7 +1848,8 @@ static void reg_process_hint(struct regulatory_request *reg_request)
1591 1848
1592 r = __regulatory_hint(wiphy, reg_request); 1849 r = __regulatory_hint(wiphy, reg_request);
1593 /* This is required so that the orig_* parameters are saved */ 1850 /* This is required so that the orig_* parameters are saved */
1594 if (r == -EALREADY && wiphy && wiphy->strict_regulatory) 1851 if (r == -EALREADY && wiphy &&
1852 wiphy->flags & WIPHY_FLAG_STRICT_REGULATORY)
1595 wiphy_update_regulatory(wiphy, reg_request->initiator); 1853 wiphy_update_regulatory(wiphy, reg_request->initiator);
1596out: 1854out:
1597 mutex_unlock(&reg_mutex); 1855 mutex_unlock(&reg_mutex);
@@ -1672,12 +1930,16 @@ static void queue_regulatory_request(struct regulatory_request *request)
1672 schedule_work(&reg_work); 1930 schedule_work(&reg_work);
1673} 1931}
1674 1932
1675/* Core regulatory hint -- happens once during cfg80211_init() */ 1933/*
1934 * Core regulatory hint -- happens during cfg80211_init()
1935 * and when we restore regulatory settings.
1936 */
1676static int regulatory_hint_core(const char *alpha2) 1937static int regulatory_hint_core(const char *alpha2)
1677{ 1938{
1678 struct regulatory_request *request; 1939 struct regulatory_request *request;
1679 1940
1680 BUG_ON(last_request); 1941 kfree(last_request);
1942 last_request = NULL;
1681 1943
1682 request = kzalloc(sizeof(struct regulatory_request), 1944 request = kzalloc(sizeof(struct regulatory_request),
1683 GFP_KERNEL); 1945 GFP_KERNEL);
@@ -1688,14 +1950,12 @@ static int regulatory_hint_core(const char *alpha2)
1688 request->alpha2[1] = alpha2[1]; 1950 request->alpha2[1] = alpha2[1];
1689 request->initiator = NL80211_REGDOM_SET_BY_CORE; 1951 request->initiator = NL80211_REGDOM_SET_BY_CORE;
1690 1952
1691 queue_regulatory_request(request);
1692
1693 /* 1953 /*
1694 * This ensures last_request is populated once modules 1954 * This ensures last_request is populated once modules
1695 * come swinging in and calling regulatory hints and 1955 * come swinging in and calling regulatory hints and
1696 * wiphy_apply_custom_regulatory(). 1956 * wiphy_apply_custom_regulatory().
1697 */ 1957 */
1698 flush_scheduled_work(); 1958 reg_process_hint(request);
1699 1959
1700 return 0; 1960 return 0;
1701} 1961}
@@ -1714,7 +1974,7 @@ int regulatory_hint_user(const char *alpha2)
1714 request->wiphy_idx = WIPHY_IDX_STALE; 1974 request->wiphy_idx = WIPHY_IDX_STALE;
1715 request->alpha2[0] = alpha2[0]; 1975 request->alpha2[0] = alpha2[0];
1716 request->alpha2[1] = alpha2[1]; 1976 request->alpha2[1] = alpha2[1];
1717 request->initiator = NL80211_REGDOM_SET_BY_USER, 1977 request->initiator = NL80211_REGDOM_SET_BY_USER;
1718 1978
1719 queue_regulatory_request(request); 1979 queue_regulatory_request(request);
1720 1980
@@ -1782,8 +2042,9 @@ static bool reg_same_country_ie_hint(struct wiphy *wiphy,
1782 * therefore cannot iterate over the rdev list here. 2042 * therefore cannot iterate over the rdev list here.
1783 */ 2043 */
1784void regulatory_hint_11d(struct wiphy *wiphy, 2044void regulatory_hint_11d(struct wiphy *wiphy,
1785 u8 *country_ie, 2045 enum ieee80211_band band,
1786 u8 country_ie_len) 2046 u8 *country_ie,
2047 u8 country_ie_len)
1787{ 2048{
1788 struct ieee80211_regdomain *rd = NULL; 2049 struct ieee80211_regdomain *rd = NULL;
1789 char alpha2[2]; 2050 char alpha2[2];
@@ -1829,9 +2090,11 @@ void regulatory_hint_11d(struct wiphy *wiphy,
1829 wiphy_idx_valid(last_request->wiphy_idx))) 2090 wiphy_idx_valid(last_request->wiphy_idx)))
1830 goto out; 2091 goto out;
1831 2092
1832 rd = country_ie_2_rd(country_ie, country_ie_len, &checksum); 2093 rd = country_ie_2_rd(band, country_ie, country_ie_len, &checksum);
1833 if (!rd) 2094 if (!rd) {
2095 REG_DBG_PRINT("cfg80211: Ignoring bogus country IE\n");
1834 goto out; 2096 goto out;
2097 }
1835 2098
1836 /* 2099 /*
1837 * This will not happen right now but we leave it here for the 2100 * This will not happen right now but we leave it here for the
@@ -1874,6 +2137,123 @@ out:
1874 mutex_unlock(&reg_mutex); 2137 mutex_unlock(&reg_mutex);
1875} 2138}
1876 2139
2140static void restore_alpha2(char *alpha2, bool reset_user)
2141{
2142 /* indicates there is no alpha2 to consider for restoration */
2143 alpha2[0] = '9';
2144 alpha2[1] = '7';
2145
2146 /* The user setting has precedence over the module parameter */
2147 if (is_user_regdom_saved()) {
2148 /* Unless we're asked to ignore it and reset it */
2149 if (reset_user) {
2150 REG_DBG_PRINT("cfg80211: Restoring regulatory settings "
2151 "including user preference\n");
2152 user_alpha2[0] = '9';
2153 user_alpha2[1] = '7';
2154
2155 /*
2156 * If we're ignoring user settings, we still need to
2157 * check the module parameter to ensure we put things
2158 * back as they were for a full restore.
2159 */
2160 if (!is_world_regdom(ieee80211_regdom)) {
2161 REG_DBG_PRINT("cfg80211: Keeping preference on "
2162 "module parameter ieee80211_regdom: %c%c\n",
2163 ieee80211_regdom[0],
2164 ieee80211_regdom[1]);
2165 alpha2[0] = ieee80211_regdom[0];
2166 alpha2[1] = ieee80211_regdom[1];
2167 }
2168 } else {
2169 REG_DBG_PRINT("cfg80211: Restoring regulatory settings "
2170 "while preserving user preference for: %c%c\n",
2171 user_alpha2[0],
2172 user_alpha2[1]);
2173 alpha2[0] = user_alpha2[0];
2174 alpha2[1] = user_alpha2[1];
2175 }
2176 } else if (!is_world_regdom(ieee80211_regdom)) {
2177 REG_DBG_PRINT("cfg80211: Keeping preference on "
2178 "module parameter ieee80211_regdom: %c%c\n",
2179 ieee80211_regdom[0],
2180 ieee80211_regdom[1]);
2181 alpha2[0] = ieee80211_regdom[0];
2182 alpha2[1] = ieee80211_regdom[1];
2183 } else
2184 REG_DBG_PRINT("cfg80211: Restoring regulatory settings\n");
2185}
2186
2187/*
2188 * Restoring regulatory settings involves ingoring any
2189 * possibly stale country IE information and user regulatory
2190 * settings if so desired, this includes any beacon hints
2191 * learned as we could have traveled outside to another country
2192 * after disconnection. To restore regulatory settings we do
2193 * exactly what we did at bootup:
2194 *
2195 * - send a core regulatory hint
2196 * - send a user regulatory hint if applicable
2197 *
2198 * Device drivers that send a regulatory hint for a specific country
2199 * keep their own regulatory domain on wiphy->regd so that does does
2200 * not need to be remembered.
2201 */
2202static void restore_regulatory_settings(bool reset_user)
2203{
2204 char alpha2[2];
2205 struct reg_beacon *reg_beacon, *btmp;
2206
2207 mutex_lock(&cfg80211_mutex);
2208 mutex_lock(&reg_mutex);
2209
2210 reset_regdomains();
2211 restore_alpha2(alpha2, reset_user);
2212
2213 /* Clear beacon hints */
2214 spin_lock_bh(&reg_pending_beacons_lock);
2215 if (!list_empty(&reg_pending_beacons)) {
2216 list_for_each_entry_safe(reg_beacon, btmp,
2217 &reg_pending_beacons, list) {
2218 list_del(&reg_beacon->list);
2219 kfree(reg_beacon);
2220 }
2221 }
2222 spin_unlock_bh(&reg_pending_beacons_lock);
2223
2224 if (!list_empty(&reg_beacon_list)) {
2225 list_for_each_entry_safe(reg_beacon, btmp,
2226 &reg_beacon_list, list) {
2227 list_del(&reg_beacon->list);
2228 kfree(reg_beacon);
2229 }
2230 }
2231
2232 /* First restore to the basic regulatory settings */
2233 cfg80211_regdomain = cfg80211_world_regdom;
2234
2235 mutex_unlock(&reg_mutex);
2236 mutex_unlock(&cfg80211_mutex);
2237
2238 regulatory_hint_core(cfg80211_regdomain->alpha2);
2239
2240 /*
2241 * This restores the ieee80211_regdom module parameter
2242 * preference or the last user requested regulatory
2243 * settings, user regulatory settings takes precedence.
2244 */
2245 if (is_an_alpha2(alpha2))
2246 regulatory_hint_user(user_alpha2);
2247}
2248
2249
2250void regulatory_hint_disconnect(void)
2251{
2252 REG_DBG_PRINT("cfg80211: All devices are disconnected, going to "
2253 "restore regulatory settings\n");
2254 restore_regulatory_settings(false);
2255}
2256
1877static bool freq_is_chan_12_13_14(u16 freq) 2257static bool freq_is_chan_12_13_14(u16 freq)
1878{ 2258{
1879 if (freq == ieee80211_channel_to_frequency(12) || 2259 if (freq == ieee80211_channel_to_frequency(12) ||
@@ -1899,13 +2279,12 @@ int regulatory_hint_found_beacon(struct wiphy *wiphy,
1899 if (!reg_beacon) 2279 if (!reg_beacon)
1900 return -ENOMEM; 2280 return -ENOMEM;
1901 2281
1902#ifdef CONFIG_CFG80211_REG_DEBUG 2282 REG_DBG_PRINT("cfg80211: Found new beacon on "
1903 printk(KERN_DEBUG "cfg80211: Found new beacon on " 2283 "frequency: %d MHz (Ch %d) on %s\n",
1904 "frequency: %d MHz (Ch %d) on %s\n", 2284 beacon_chan->center_freq,
1905 beacon_chan->center_freq, 2285 ieee80211_frequency_to_channel(beacon_chan->center_freq),
1906 ieee80211_frequency_to_channel(beacon_chan->center_freq), 2286 wiphy_name(wiphy));
1907 wiphy_name(wiphy)); 2287
1908#endif
1909 memcpy(&reg_beacon->chan, beacon_chan, 2288 memcpy(&reg_beacon->chan, beacon_chan,
1910 sizeof(struct ieee80211_channel)); 2289 sizeof(struct ieee80211_channel));
1911 2290
@@ -1930,7 +2309,7 @@ static void print_rd_rules(const struct ieee80211_regdomain *rd)
1930 const struct ieee80211_freq_range *freq_range = NULL; 2309 const struct ieee80211_freq_range *freq_range = NULL;
1931 const struct ieee80211_power_rule *power_rule = NULL; 2310 const struct ieee80211_power_rule *power_rule = NULL;
1932 2311
1933 printk(KERN_INFO "\t(start_freq - end_freq @ bandwidth), " 2312 printk(KERN_INFO " (start_freq - end_freq @ bandwidth), "
1934 "(max_antenna_gain, max_eirp)\n"); 2313 "(max_antenna_gain, max_eirp)\n");
1935 2314
1936 for (i = 0; i < rd->n_reg_rules; i++) { 2315 for (i = 0; i < rd->n_reg_rules; i++) {
@@ -1943,7 +2322,7 @@ static void print_rd_rules(const struct ieee80211_regdomain *rd)
1943 * in certain regions 2322 * in certain regions
1944 */ 2323 */
1945 if (power_rule->max_antenna_gain) 2324 if (power_rule->max_antenna_gain)
1946 printk(KERN_INFO "\t(%d KHz - %d KHz @ %d KHz), " 2325 printk(KERN_INFO " (%d KHz - %d KHz @ %d KHz), "
1947 "(%d mBi, %d mBm)\n", 2326 "(%d mBi, %d mBm)\n",
1948 freq_range->start_freq_khz, 2327 freq_range->start_freq_khz,
1949 freq_range->end_freq_khz, 2328 freq_range->end_freq_khz,
@@ -1951,7 +2330,7 @@ static void print_rd_rules(const struct ieee80211_regdomain *rd)
1951 power_rule->max_antenna_gain, 2330 power_rule->max_antenna_gain,
1952 power_rule->max_eirp); 2331 power_rule->max_eirp);
1953 else 2332 else
1954 printk(KERN_INFO "\t(%d KHz - %d KHz @ %d KHz), " 2333 printk(KERN_INFO " (%d KHz - %d KHz @ %d KHz), "
1955 "(N/A, %d mBm)\n", 2334 "(N/A, %d mBm)\n",
1956 freq_range->start_freq_khz, 2335 freq_range->start_freq_khz,
1957 freq_range->end_freq_khz, 2336 freq_range->end_freq_khz,
@@ -2063,8 +2442,7 @@ static int __set_regdom(const struct ieee80211_regdomain *rd)
2063 * If someone else asked us to change the rd lets only bother 2442 * If someone else asked us to change the rd lets only bother
2064 * checking if the alpha2 changes if CRDA was already called 2443 * checking if the alpha2 changes if CRDA was already called
2065 */ 2444 */
2066 if (!is_old_static_regdom(cfg80211_regdomain) && 2445 if (!regdom_changes(rd->alpha2))
2067 !regdom_changes(rd->alpha2))
2068 return -EINVAL; 2446 return -EINVAL;
2069 } 2447 }
2070 2448
@@ -2263,15 +2641,11 @@ int regulatory_init(void)
2263 spin_lock_init(&reg_requests_lock); 2641 spin_lock_init(&reg_requests_lock);
2264 spin_lock_init(&reg_pending_beacons_lock); 2642 spin_lock_init(&reg_pending_beacons_lock);
2265 2643
2266#ifdef CONFIG_WIRELESS_OLD_REGULATORY
2267 cfg80211_regdomain = static_regdom(ieee80211_regdom);
2268
2269 printk(KERN_INFO "cfg80211: Using static regulatory domain info\n");
2270 print_regdomain_info(cfg80211_regdomain);
2271#else
2272 cfg80211_regdomain = cfg80211_world_regdom; 2644 cfg80211_regdomain = cfg80211_world_regdom;
2273 2645
2274#endif 2646 user_alpha2[0] = '9';
2647 user_alpha2[1] = '7';
2648
2275 /* We always try to get an update for the static regdomain */ 2649 /* We always try to get an update for the static regdomain */
2276 err = regulatory_hint_core(cfg80211_regdomain->alpha2); 2650 err = regulatory_hint_core(cfg80211_regdomain->alpha2);
2277 if (err) { 2651 if (err) {
diff --git a/net/wireless/reg.h b/net/wireless/reg.h
index 3362c7c069b2..b26224a9f3bc 100644
--- a/net/wireless/reg.h
+++ b/net/wireless/reg.h
@@ -41,15 +41,44 @@ int regulatory_hint_found_beacon(struct wiphy *wiphy,
41 * regulatory_hint_11d - hints a country IE as a regulatory domain 41 * regulatory_hint_11d - hints a country IE as a regulatory domain
42 * @wiphy: the wireless device giving the hint (used only for reporting 42 * @wiphy: the wireless device giving the hint (used only for reporting
43 * conflicts) 43 * conflicts)
44 * @band: the band on which the country IE was received on. This determines
45 * the band we'll process the country IE channel triplets for.
44 * @country_ie: pointer to the country IE 46 * @country_ie: pointer to the country IE
45 * @country_ie_len: length of the country IE 47 * @country_ie_len: length of the country IE
46 * 48 *
47 * We will intersect the rd with the what CRDA tells us should apply 49 * We will intersect the rd with the what CRDA tells us should apply
48 * for the alpha2 this country IE belongs to, this prevents APs from 50 * for the alpha2 this country IE belongs to, this prevents APs from
49 * sending us incorrect or outdated information against a country. 51 * sending us incorrect or outdated information against a country.
52 *
53 * The AP is expected to provide Country IE channel triplets for the
54 * band it is on. It is technically possible for APs to send channel
55 * country IE triplets even for channels outside of the band they are
56 * in but for that they would have to use the regulatory extension
57 * in combination with a triplet but this behaviour is currently
58 * not observed. For this reason if a triplet is seen with channel
59 * information for a band the BSS is not present in it will be ignored.
50 */ 60 */
51void regulatory_hint_11d(struct wiphy *wiphy, 61void regulatory_hint_11d(struct wiphy *wiphy,
62 enum ieee80211_band band,
52 u8 *country_ie, 63 u8 *country_ie,
53 u8 country_ie_len); 64 u8 country_ie_len);
54 65
66/**
67 * regulatory_hint_disconnect - informs all devices have been disconneted
68 *
69 * Regulotory rules can be enhanced further upon scanning and upon
70 * connection to an AP. These rules become stale if we disconnect
71 * and go to another country, whether or not we suspend and resume.
72 * If we suspend, go to another country and resume we'll automatically
73 * get disconnected shortly after resuming and things will be reset as well.
74 * This routine is a helper to restore regulatory settings to how they were
75 * prior to our first connect attempt. This includes ignoring country IE and
76 * beacon regulatory hints. The ieee80211_regdom module parameter will always
77 * be respected but if a user had set the regulatory domain that will take
78 * precedence.
79 *
80 * Must be called from process context.
81 */
82void regulatory_hint_disconnect(void);
83
55#endif /* __NET_WIRELESS_REG_H */ 84#endif /* __NET_WIRELESS_REG_H */
diff --git a/net/wireless/regdb.h b/net/wireless/regdb.h
new file mode 100644
index 000000000000..818222c92513
--- /dev/null
+++ b/net/wireless/regdb.h
@@ -0,0 +1,7 @@
1#ifndef __REGDB_H__
2#define __REGDB_H__
3
4extern const struct ieee80211_regdomain *reg_regdb[];
5extern int reg_regdb_size;
6
7#endif /* __REGDB_H__ */
diff --git a/net/wireless/scan.c b/net/wireless/scan.c
index e5f92ee758f4..a026c6d56bd3 100644
--- a/net/wireless/scan.c
+++ b/net/wireless/scan.c
@@ -4,6 +4,7 @@
4 * Copyright 2008 Johannes Berg <johannes@sipsolutions.net> 4 * Copyright 2008 Johannes Berg <johannes@sipsolutions.net>
5 */ 5 */
6#include <linux/kernel.h> 6#include <linux/kernel.h>
7#include <linux/slab.h>
7#include <linux/module.h> 8#include <linux/module.h>
8#include <linux/netdevice.h> 9#include <linux/netdevice.h>
9#include <linux/wireless.h> 10#include <linux/wireless.h>
@@ -22,7 +23,7 @@ void ___cfg80211_scan_done(struct cfg80211_registered_device *rdev, bool leak)
22{ 23{
23 struct cfg80211_scan_request *request; 24 struct cfg80211_scan_request *request;
24 struct net_device *dev; 25 struct net_device *dev;
25#ifdef CONFIG_WIRELESS_EXT 26#ifdef CONFIG_CFG80211_WEXT
26 union iwreq_data wrqu; 27 union iwreq_data wrqu;
27#endif 28#endif
28 29
@@ -47,7 +48,7 @@ void ___cfg80211_scan_done(struct cfg80211_registered_device *rdev, bool leak)
47 else 48 else
48 nl80211_send_scan_done(rdev, dev); 49 nl80211_send_scan_done(rdev, dev);
49 50
50#ifdef CONFIG_WIRELESS_EXT 51#ifdef CONFIG_CFG80211_WEXT
51 if (!request->aborted) { 52 if (!request->aborted) {
52 memset(&wrqu, 0, sizeof(wrqu)); 53 memset(&wrqu, 0, sizeof(wrqu));
53 54
@@ -88,7 +89,7 @@ void cfg80211_scan_done(struct cfg80211_scan_request *request, bool aborted)
88 WARN_ON(request != wiphy_to_dev(request->wiphy)->scan_req); 89 WARN_ON(request != wiphy_to_dev(request->wiphy)->scan_req);
89 90
90 request->aborted = aborted; 91 request->aborted = aborted;
91 schedule_work(&wiphy_to_dev(request->wiphy)->scan_done_wk); 92 queue_work(cfg80211_wq, &wiphy_to_dev(request->wiphy)->scan_done_wk);
92} 93}
93EXPORT_SYMBOL(cfg80211_scan_done); 94EXPORT_SYMBOL(cfg80211_scan_done);
94 95
@@ -100,8 +101,10 @@ static void bss_release(struct kref *ref)
100 if (bss->pub.free_priv) 101 if (bss->pub.free_priv)
101 bss->pub.free_priv(&bss->pub); 102 bss->pub.free_priv(&bss->pub);
102 103
103 if (bss->ies_allocated) 104 if (bss->beacon_ies_allocated)
104 kfree(bss->pub.information_elements); 105 kfree(bss->pub.beacon_ies);
106 if (bss->proberesp_ies_allocated)
107 kfree(bss->pub.proberesp_ies);
105 108
106 BUG_ON(atomic_read(&bss->hold)); 109 BUG_ON(atomic_read(&bss->hold));
107 110
@@ -141,9 +144,9 @@ void cfg80211_bss_expire(struct cfg80211_registered_device *dev)
141 dev->bss_generation++; 144 dev->bss_generation++;
142} 145}
143 146
144static u8 *find_ie(u8 num, u8 *ies, int len) 147const u8 *cfg80211_find_ie(u8 eid, const u8 *ies, int len)
145{ 148{
146 while (len > 2 && ies[0] != num) { 149 while (len > 2 && ies[0] != eid) {
147 len -= ies[1] + 2; 150 len -= ies[1] + 2;
148 ies += ies[1] + 2; 151 ies += ies[1] + 2;
149 } 152 }
@@ -153,11 +156,12 @@ static u8 *find_ie(u8 num, u8 *ies, int len)
153 return NULL; 156 return NULL;
154 return ies; 157 return ies;
155} 158}
159EXPORT_SYMBOL(cfg80211_find_ie);
156 160
157static int cmp_ies(u8 num, u8 *ies1, size_t len1, u8 *ies2, size_t len2) 161static int cmp_ies(u8 num, u8 *ies1, size_t len1, u8 *ies2, size_t len2)
158{ 162{
159 const u8 *ie1 = find_ie(num, ies1, len1); 163 const u8 *ie1 = cfg80211_find_ie(num, ies1, len1);
160 const u8 *ie2 = find_ie(num, ies2, len2); 164 const u8 *ie2 = cfg80211_find_ie(num, ies2, len2);
161 int r; 165 int r;
162 166
163 if (!ie1 && !ie2) 167 if (!ie1 && !ie2)
@@ -183,9 +187,9 @@ static bool is_bss(struct cfg80211_bss *a,
183 if (!ssid) 187 if (!ssid)
184 return true; 188 return true;
185 189
186 ssidie = find_ie(WLAN_EID_SSID, 190 ssidie = cfg80211_find_ie(WLAN_EID_SSID,
187 a->information_elements, 191 a->information_elements,
188 a->len_information_elements); 192 a->len_information_elements);
189 if (!ssidie) 193 if (!ssidie)
190 return false; 194 return false;
191 if (ssidie[1] != ssid_len) 195 if (ssidie[1] != ssid_len)
@@ -202,9 +206,9 @@ static bool is_mesh(struct cfg80211_bss *a,
202 if (!is_zero_ether_addr(a->bssid)) 206 if (!is_zero_ether_addr(a->bssid))
203 return false; 207 return false;
204 208
205 ie = find_ie(WLAN_EID_MESH_ID, 209 ie = cfg80211_find_ie(WLAN_EID_MESH_ID,
206 a->information_elements, 210 a->information_elements,
207 a->len_information_elements); 211 a->len_information_elements);
208 if (!ie) 212 if (!ie)
209 return false; 213 return false;
210 if (ie[1] != meshidlen) 214 if (ie[1] != meshidlen)
@@ -212,12 +216,12 @@ static bool is_mesh(struct cfg80211_bss *a,
212 if (memcmp(ie + 2, meshid, meshidlen)) 216 if (memcmp(ie + 2, meshid, meshidlen))
213 return false; 217 return false;
214 218
215 ie = find_ie(WLAN_EID_MESH_CONFIG, 219 ie = cfg80211_find_ie(WLAN_EID_MESH_CONFIG,
216 a->information_elements, 220 a->information_elements,
217 a->len_information_elements); 221 a->len_information_elements);
218 if (!ie) 222 if (!ie)
219 return false; 223 return false;
220 if (ie[1] != IEEE80211_MESH_CONFIG_LEN) 224 if (ie[1] != sizeof(struct ieee80211_meshconf_ie))
221 return false; 225 return false;
222 226
223 /* 227 /*
@@ -225,7 +229,8 @@ static bool is_mesh(struct cfg80211_bss *a,
225 * comparing since that may differ between stations taking 229 * comparing since that may differ between stations taking
226 * part in the same mesh. 230 * part in the same mesh.
227 */ 231 */
228 return memcmp(ie + 2, meshcfg, IEEE80211_MESH_CONFIG_LEN - 2) == 0; 232 return memcmp(ie + 2, meshcfg,
233 sizeof(struct ieee80211_meshconf_ie) - 2) == 0;
229} 234}
230 235
231static int cmp_bss(struct cfg80211_bss *a, 236static int cmp_bss(struct cfg80211_bss *a,
@@ -374,8 +379,7 @@ rb_find_bss(struct cfg80211_registered_device *dev,
374 379
375static struct cfg80211_internal_bss * 380static struct cfg80211_internal_bss *
376cfg80211_bss_update(struct cfg80211_registered_device *dev, 381cfg80211_bss_update(struct cfg80211_registered_device *dev,
377 struct cfg80211_internal_bss *res, 382 struct cfg80211_internal_bss *res)
378 bool overwrite)
379{ 383{
380 struct cfg80211_internal_bss *found = NULL; 384 struct cfg80211_internal_bss *found = NULL;
381 const u8 *meshid, *meshcfg; 385 const u8 *meshid, *meshcfg;
@@ -393,13 +397,14 @@ cfg80211_bss_update(struct cfg80211_registered_device *dev,
393 397
394 if (is_zero_ether_addr(res->pub.bssid)) { 398 if (is_zero_ether_addr(res->pub.bssid)) {
395 /* must be mesh, verify */ 399 /* must be mesh, verify */
396 meshid = find_ie(WLAN_EID_MESH_ID, res->pub.information_elements, 400 meshid = cfg80211_find_ie(WLAN_EID_MESH_ID,
397 res->pub.len_information_elements); 401 res->pub.information_elements,
398 meshcfg = find_ie(WLAN_EID_MESH_CONFIG, 402 res->pub.len_information_elements);
399 res->pub.information_elements, 403 meshcfg = cfg80211_find_ie(WLAN_EID_MESH_CONFIG,
400 res->pub.len_information_elements); 404 res->pub.information_elements,
405 res->pub.len_information_elements);
401 if (!meshid || !meshcfg || 406 if (!meshid || !meshcfg ||
402 meshcfg[1] != IEEE80211_MESH_CONFIG_LEN) { 407 meshcfg[1] != sizeof(struct ieee80211_meshconf_ie)) {
403 /* bogus mesh */ 408 /* bogus mesh */
404 kref_put(&res->ref, bss_release); 409 kref_put(&res->ref, bss_release);
405 return NULL; 410 return NULL;
@@ -417,28 +422,64 @@ cfg80211_bss_update(struct cfg80211_registered_device *dev,
417 found->pub.capability = res->pub.capability; 422 found->pub.capability = res->pub.capability;
418 found->ts = res->ts; 423 found->ts = res->ts;
419 424
420 /* overwrite IEs */ 425 /* Update IEs */
421 if (overwrite) { 426 if (res->pub.proberesp_ies) {
422 size_t used = dev->wiphy.bss_priv_size + sizeof(*res); 427 size_t used = dev->wiphy.bss_priv_size + sizeof(*res);
423 size_t ielen = res->pub.len_information_elements; 428 size_t ielen = res->pub.len_proberesp_ies;
429
430 if (found->pub.proberesp_ies &&
431 !found->proberesp_ies_allocated &&
432 ksize(found) >= used + ielen) {
433 memcpy(found->pub.proberesp_ies,
434 res->pub.proberesp_ies, ielen);
435 found->pub.len_proberesp_ies = ielen;
436 } else {
437 u8 *ies = found->pub.proberesp_ies;
438
439 if (found->proberesp_ies_allocated)
440 ies = krealloc(ies, ielen, GFP_ATOMIC);
441 else
442 ies = kmalloc(ielen, GFP_ATOMIC);
424 443
425 if (!found->ies_allocated && ksize(found) >= used + ielen) { 444 if (ies) {
426 memcpy(found->pub.information_elements, 445 memcpy(ies, res->pub.proberesp_ies,
427 res->pub.information_elements, ielen); 446 ielen);
428 found->pub.len_information_elements = ielen; 447 found->proberesp_ies_allocated = true;
448 found->pub.proberesp_ies = ies;
449 found->pub.len_proberesp_ies = ielen;
450 }
451 }
452
453 /* Override possible earlier Beacon frame IEs */
454 found->pub.information_elements =
455 found->pub.proberesp_ies;
456 found->pub.len_information_elements =
457 found->pub.len_proberesp_ies;
458 }
459 if (res->pub.beacon_ies) {
460 size_t used = dev->wiphy.bss_priv_size + sizeof(*res);
461 size_t ielen = res->pub.len_beacon_ies;
462
463 if (found->pub.beacon_ies &&
464 !found->beacon_ies_allocated &&
465 ksize(found) >= used + ielen) {
466 memcpy(found->pub.beacon_ies,
467 res->pub.beacon_ies, ielen);
468 found->pub.len_beacon_ies = ielen;
429 } else { 469 } else {
430 u8 *ies = found->pub.information_elements; 470 u8 *ies = found->pub.beacon_ies;
431 471
432 if (found->ies_allocated) 472 if (found->beacon_ies_allocated)
433 ies = krealloc(ies, ielen, GFP_ATOMIC); 473 ies = krealloc(ies, ielen, GFP_ATOMIC);
434 else 474 else
435 ies = kmalloc(ielen, GFP_ATOMIC); 475 ies = kmalloc(ielen, GFP_ATOMIC);
436 476
437 if (ies) { 477 if (ies) {
438 memcpy(ies, res->pub.information_elements, ielen); 478 memcpy(ies, res->pub.beacon_ies,
439 found->ies_allocated = true; 479 ielen);
440 found->pub.information_elements = ies; 480 found->beacon_ies_allocated = true;
441 found->pub.len_information_elements = ielen; 481 found->pub.beacon_ies = ies;
482 found->pub.len_beacon_ies = ielen;
442 } 483 }
443 } 484 }
444 } 485 }
@@ -488,14 +529,26 @@ cfg80211_inform_bss(struct wiphy *wiphy,
488 res->pub.tsf = timestamp; 529 res->pub.tsf = timestamp;
489 res->pub.beacon_interval = beacon_interval; 530 res->pub.beacon_interval = beacon_interval;
490 res->pub.capability = capability; 531 res->pub.capability = capability;
491 /* point to after the private area */ 532 /*
492 res->pub.information_elements = (u8 *)res + sizeof(*res) + privsz; 533 * Since we do not know here whether the IEs are from a Beacon or Probe
493 memcpy(res->pub.information_elements, ie, ielen); 534 * Response frame, we need to pick one of the options and only use it
494 res->pub.len_information_elements = ielen; 535 * with the driver that does not provide the full Beacon/Probe Response
536 * frame. Use Beacon frame pointer to avoid indicating that this should
537 * override the information_elements pointer should we have received an
538 * earlier indication of Probe Response data.
539 *
540 * The initial buffer for the IEs is allocated with the BSS entry and
541 * is located after the private area.
542 */
543 res->pub.beacon_ies = (u8 *)res + sizeof(*res) + privsz;
544 memcpy(res->pub.beacon_ies, ie, ielen);
545 res->pub.len_beacon_ies = ielen;
546 res->pub.information_elements = res->pub.beacon_ies;
547 res->pub.len_information_elements = res->pub.len_beacon_ies;
495 548
496 kref_init(&res->ref); 549 kref_init(&res->ref);
497 550
498 res = cfg80211_bss_update(wiphy_to_dev(wiphy), res, 0); 551 res = cfg80211_bss_update(wiphy_to_dev(wiphy), res);
499 if (!res) 552 if (!res)
500 return NULL; 553 return NULL;
501 554
@@ -516,7 +569,6 @@ cfg80211_inform_bss_frame(struct wiphy *wiphy,
516 struct cfg80211_internal_bss *res; 569 struct cfg80211_internal_bss *res;
517 size_t ielen = len - offsetof(struct ieee80211_mgmt, 570 size_t ielen = len - offsetof(struct ieee80211_mgmt,
518 u.probe_resp.variable); 571 u.probe_resp.variable);
519 bool overwrite;
520 size_t privsz = wiphy->bss_priv_size; 572 size_t privsz = wiphy->bss_priv_size;
521 573
522 if (WARN_ON(wiphy->signal_type == NL80211_BSS_SIGNAL_UNSPEC && 574 if (WARN_ON(wiphy->signal_type == NL80211_BSS_SIGNAL_UNSPEC &&
@@ -537,16 +589,28 @@ cfg80211_inform_bss_frame(struct wiphy *wiphy,
537 res->pub.tsf = le64_to_cpu(mgmt->u.probe_resp.timestamp); 589 res->pub.tsf = le64_to_cpu(mgmt->u.probe_resp.timestamp);
538 res->pub.beacon_interval = le16_to_cpu(mgmt->u.probe_resp.beacon_int); 590 res->pub.beacon_interval = le16_to_cpu(mgmt->u.probe_resp.beacon_int);
539 res->pub.capability = le16_to_cpu(mgmt->u.probe_resp.capab_info); 591 res->pub.capability = le16_to_cpu(mgmt->u.probe_resp.capab_info);
540 /* point to after the private area */ 592 /*
541 res->pub.information_elements = (u8 *)res + sizeof(*res) + privsz; 593 * The initial buffer for the IEs is allocated with the BSS entry and
542 memcpy(res->pub.information_elements, mgmt->u.probe_resp.variable, ielen); 594 * is located after the private area.
543 res->pub.len_information_elements = ielen; 595 */
596 if (ieee80211_is_probe_resp(mgmt->frame_control)) {
597 res->pub.proberesp_ies = (u8 *) res + sizeof(*res) + privsz;
598 memcpy(res->pub.proberesp_ies, mgmt->u.probe_resp.variable,
599 ielen);
600 res->pub.len_proberesp_ies = ielen;
601 res->pub.information_elements = res->pub.proberesp_ies;
602 res->pub.len_information_elements = res->pub.len_proberesp_ies;
603 } else {
604 res->pub.beacon_ies = (u8 *) res + sizeof(*res) + privsz;
605 memcpy(res->pub.beacon_ies, mgmt->u.beacon.variable, ielen);
606 res->pub.len_beacon_ies = ielen;
607 res->pub.information_elements = res->pub.beacon_ies;
608 res->pub.len_information_elements = res->pub.len_beacon_ies;
609 }
544 610
545 kref_init(&res->ref); 611 kref_init(&res->ref);
546 612
547 overwrite = ieee80211_is_probe_resp(mgmt->frame_control); 613 res = cfg80211_bss_update(wiphy_to_dev(wiphy), res);
548
549 res = cfg80211_bss_update(wiphy_to_dev(wiphy), res, overwrite);
550 if (!res) 614 if (!res)
551 return NULL; 615 return NULL;
552 616
@@ -592,7 +656,7 @@ void cfg80211_unlink_bss(struct wiphy *wiphy, struct cfg80211_bss *pub)
592} 656}
593EXPORT_SYMBOL(cfg80211_unlink_bss); 657EXPORT_SYMBOL(cfg80211_unlink_bss);
594 658
595#ifdef CONFIG_WIRELESS_EXT 659#ifdef CONFIG_CFG80211_WEXT
596int cfg80211_wext_siwscan(struct net_device *dev, 660int cfg80211_wext_siwscan(struct net_device *dev,
597 struct iw_request_info *info, 661 struct iw_request_info *info,
598 union iwreq_data *wrqu, char *extra) 662 union iwreq_data *wrqu, char *extra)
@@ -600,7 +664,7 @@ int cfg80211_wext_siwscan(struct net_device *dev,
600 struct cfg80211_registered_device *rdev; 664 struct cfg80211_registered_device *rdev;
601 struct wiphy *wiphy; 665 struct wiphy *wiphy;
602 struct iw_scan_req *wreq = NULL; 666 struct iw_scan_req *wreq = NULL;
603 struct cfg80211_scan_request *creq; 667 struct cfg80211_scan_request *creq = NULL;
604 int i, err, n_channels = 0; 668 int i, err, n_channels = 0;
605 enum ieee80211_band band; 669 enum ieee80211_band band;
606 670
@@ -650,9 +714,15 @@ int cfg80211_wext_siwscan(struct net_device *dev,
650 i = 0; 714 i = 0;
651 for (band = 0; band < IEEE80211_NUM_BANDS; band++) { 715 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
652 int j; 716 int j;
717
653 if (!wiphy->bands[band]) 718 if (!wiphy->bands[band])
654 continue; 719 continue;
720
655 for (j = 0; j < wiphy->bands[band]->n_channels; j++) { 721 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
722 /* ignore disabled channels */
723 if (wiphy->bands[band]->channels[j].flags &
724 IEEE80211_CHAN_DISABLED)
725 continue;
656 726
657 /* If we have a wireless request structure and the 727 /* If we have a wireless request structure and the
658 * wireless request specifies frequencies, then search 728 * wireless request specifies frequencies, then search
@@ -687,8 +757,10 @@ int cfg80211_wext_siwscan(struct net_device *dev,
687 /* translate "Scan for SSID" request */ 757 /* translate "Scan for SSID" request */
688 if (wreq) { 758 if (wreq) {
689 if (wrqu->data.flags & IW_SCAN_THIS_ESSID) { 759 if (wrqu->data.flags & IW_SCAN_THIS_ESSID) {
690 if (wreq->essid_len > IEEE80211_MAX_SSID_LEN) 760 if (wreq->essid_len > IEEE80211_MAX_SSID_LEN) {
691 return -EINVAL; 761 err = -EINVAL;
762 goto out;
763 }
692 memcpy(creq->ssids[0].ssid, wreq->essid, wreq->essid_len); 764 memcpy(creq->ssids[0].ssid, wreq->essid, wreq->essid_len);
693 creq->ssids[0].ssid_len = wreq->essid_len; 765 creq->ssids[0].ssid_len = wreq->essid_len;
694 } 766 }
@@ -700,12 +772,15 @@ int cfg80211_wext_siwscan(struct net_device *dev,
700 err = rdev->ops->scan(wiphy, dev, creq); 772 err = rdev->ops->scan(wiphy, dev, creq);
701 if (err) { 773 if (err) {
702 rdev->scan_req = NULL; 774 rdev->scan_req = NULL;
703 kfree(creq); 775 /* creq will be freed below */
704 } else { 776 } else {
705 nl80211_send_scan_start(rdev, dev); 777 nl80211_send_scan_start(rdev, dev);
778 /* creq now owned by driver */
779 creq = NULL;
706 dev_hold(dev); 780 dev_hold(dev);
707 } 781 }
708 out: 782 out:
783 kfree(creq);
709 cfg80211_unlock_rdev(rdev); 784 cfg80211_unlock_rdev(rdev);
710 return err; 785 return err;
711} 786}
@@ -859,7 +934,7 @@ ieee80211_bss(struct wiphy *wiphy, struct iw_request_info *info,
859 break; 934 break;
860 case WLAN_EID_MESH_CONFIG: 935 case WLAN_EID_MESH_CONFIG:
861 ismesh = true; 936 ismesh = true;
862 if (ie[1] != IEEE80211_MESH_CONFIG_LEN) 937 if (ie[1] != sizeof(struct ieee80211_meshconf_ie))
863 break; 938 break;
864 buf = kmalloc(50, GFP_ATOMIC); 939 buf = kmalloc(50, GFP_ATOMIC);
865 if (!buf) 940 if (!buf)
@@ -867,35 +942,40 @@ ieee80211_bss(struct wiphy *wiphy, struct iw_request_info *info,
867 cfg = ie + 2; 942 cfg = ie + 2;
868 memset(&iwe, 0, sizeof(iwe)); 943 memset(&iwe, 0, sizeof(iwe));
869 iwe.cmd = IWEVCUSTOM; 944 iwe.cmd = IWEVCUSTOM;
870 sprintf(buf, "Mesh network (version %d)", cfg[0]); 945 sprintf(buf, "Mesh Network Path Selection Protocol ID: "
946 "0x%02X", cfg[0]);
947 iwe.u.data.length = strlen(buf);
948 current_ev = iwe_stream_add_point(info, current_ev,
949 end_buf,
950 &iwe, buf);
951 sprintf(buf, "Path Selection Metric ID: 0x%02X",
952 cfg[1]);
953 iwe.u.data.length = strlen(buf);
954 current_ev = iwe_stream_add_point(info, current_ev,
955 end_buf,
956 &iwe, buf);
957 sprintf(buf, "Congestion Control Mode ID: 0x%02X",
958 cfg[2]);
871 iwe.u.data.length = strlen(buf); 959 iwe.u.data.length = strlen(buf);
872 current_ev = iwe_stream_add_point(info, current_ev, 960 current_ev = iwe_stream_add_point(info, current_ev,
873 end_buf, 961 end_buf,
874 &iwe, buf); 962 &iwe, buf);
875 sprintf(buf, "Path Selection Protocol ID: " 963 sprintf(buf, "Synchronization ID: 0x%02X", cfg[3]);
876 "0x%02X%02X%02X%02X", cfg[1], cfg[2], cfg[3],
877 cfg[4]);
878 iwe.u.data.length = strlen(buf); 964 iwe.u.data.length = strlen(buf);
879 current_ev = iwe_stream_add_point(info, current_ev, 965 current_ev = iwe_stream_add_point(info, current_ev,
880 end_buf, 966 end_buf,
881 &iwe, buf); 967 &iwe, buf);
882 sprintf(buf, "Path Selection Metric ID: " 968 sprintf(buf, "Authentication ID: 0x%02X", cfg[4]);
883 "0x%02X%02X%02X%02X", cfg[5], cfg[6], cfg[7],
884 cfg[8]);
885 iwe.u.data.length = strlen(buf); 969 iwe.u.data.length = strlen(buf);
886 current_ev = iwe_stream_add_point(info, current_ev, 970 current_ev = iwe_stream_add_point(info, current_ev,
887 end_buf, 971 end_buf,
888 &iwe, buf); 972 &iwe, buf);
889 sprintf(buf, "Congestion Control Mode ID: " 973 sprintf(buf, "Formation Info: 0x%02X", cfg[5]);
890 "0x%02X%02X%02X%02X", cfg[9], cfg[10],
891 cfg[11], cfg[12]);
892 iwe.u.data.length = strlen(buf); 974 iwe.u.data.length = strlen(buf);
893 current_ev = iwe_stream_add_point(info, current_ev, 975 current_ev = iwe_stream_add_point(info, current_ev,
894 end_buf, 976 end_buf,
895 &iwe, buf); 977 &iwe, buf);
896 sprintf(buf, "Channel Precedence: " 978 sprintf(buf, "Capabilities: 0x%02X", cfg[6]);
897 "0x%02X%02X%02X%02X", cfg[13], cfg[14],
898 cfg[15], cfg[16]);
899 iwe.u.data.length = strlen(buf); 979 iwe.u.data.length = strlen(buf);
900 current_ev = iwe_stream_add_point(info, current_ev, 980 current_ev = iwe_stream_add_point(info, current_ev,
901 end_buf, 981 end_buf,
@@ -925,8 +1005,8 @@ ieee80211_bss(struct wiphy *wiphy, struct iw_request_info *info,
925 ie += ie[1] + 2; 1005 ie += ie[1] + 2;
926 } 1006 }
927 1007
928 if (bss->pub.capability & (WLAN_CAPABILITY_ESS | WLAN_CAPABILITY_IBSS) 1008 if (bss->pub.capability & (WLAN_CAPABILITY_ESS | WLAN_CAPABILITY_IBSS) ||
929 || ismesh) { 1009 ismesh) {
930 memset(&iwe, 0, sizeof(iwe)); 1010 memset(&iwe, 0, sizeof(iwe));
931 iwe.cmd = SIOCGIWMODE; 1011 iwe.cmd = SIOCGIWMODE;
932 if (ismesh) 1012 if (ismesh)
diff --git a/net/wireless/sme.c b/net/wireless/sme.c
index 9f0b2800a9d7..f4dfd5f5f2ea 100644
--- a/net/wireless/sme.c
+++ b/net/wireless/sme.c
@@ -7,6 +7,7 @@
7 7
8#include <linux/etherdevice.h> 8#include <linux/etherdevice.h>
9#include <linux/if_arp.h> 9#include <linux/if_arp.h>
10#include <linux/slab.h>
10#include <linux/workqueue.h> 11#include <linux/workqueue.h>
11#include <linux/wireless.h> 12#include <linux/wireless.h>
12#include <net/iw_handler.h> 13#include <net/iw_handler.h>
@@ -34,6 +35,44 @@ struct cfg80211_conn {
34 bool auto_auth, prev_bssid_valid; 35 bool auto_auth, prev_bssid_valid;
35}; 36};
36 37
38bool cfg80211_is_all_idle(void)
39{
40 struct cfg80211_registered_device *rdev;
41 struct wireless_dev *wdev;
42 bool is_all_idle = true;
43
44 mutex_lock(&cfg80211_mutex);
45
46 /*
47 * All devices must be idle as otherwise if you are actively
48 * scanning some new beacon hints could be learned and would
49 * count as new regulatory hints.
50 */
51 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
52 cfg80211_lock_rdev(rdev);
53 list_for_each_entry(wdev, &rdev->netdev_list, list) {
54 wdev_lock(wdev);
55 if (wdev->sme_state != CFG80211_SME_IDLE)
56 is_all_idle = false;
57 wdev_unlock(wdev);
58 }
59 cfg80211_unlock_rdev(rdev);
60 }
61
62 mutex_unlock(&cfg80211_mutex);
63
64 return is_all_idle;
65}
66
67static void disconnect_work(struct work_struct *work)
68{
69 if (!cfg80211_is_all_idle())
70 return;
71
72 regulatory_hint_disconnect();
73}
74
75static DECLARE_WORK(cfg80211_disconnect_work, disconnect_work);
37 76
38static int cfg80211_conn_scan(struct wireless_dev *wdev) 77static int cfg80211_conn_scan(struct wireless_dev *wdev)
39{ 78{
@@ -365,7 +404,7 @@ void __cfg80211_connect_result(struct net_device *dev, const u8 *bssid,
365{ 404{
366 struct wireless_dev *wdev = dev->ieee80211_ptr; 405 struct wireless_dev *wdev = dev->ieee80211_ptr;
367 u8 *country_ie; 406 u8 *country_ie;
368#ifdef CONFIG_WIRELESS_EXT 407#ifdef CONFIG_CFG80211_WEXT
369 union iwreq_data wrqu; 408 union iwreq_data wrqu;
370#endif 409#endif
371 410
@@ -382,7 +421,7 @@ void __cfg80211_connect_result(struct net_device *dev, const u8 *bssid,
382 resp_ie, resp_ie_len, 421 resp_ie, resp_ie_len,
383 status, GFP_KERNEL); 422 status, GFP_KERNEL);
384 423
385#ifdef CONFIG_WIRELESS_EXT 424#ifdef CONFIG_CFG80211_WEXT
386 if (wextev) { 425 if (wextev) {
387 if (req_ie && status == WLAN_STATUS_SUCCESS) { 426 if (req_ie && status == WLAN_STATUS_SUCCESS) {
388 memset(&wrqu, 0, sizeof(wrqu)); 427 memset(&wrqu, 0, sizeof(wrqu));
@@ -454,6 +493,7 @@ void __cfg80211_connect_result(struct net_device *dev, const u8 *bssid,
454 * - and country_ie[1] which is the IE length 493 * - and country_ie[1] which is the IE length
455 */ 494 */
456 regulatory_hint_11d(wdev->wiphy, 495 regulatory_hint_11d(wdev->wiphy,
496 bss->channel->band,
457 country_ie + 2, 497 country_ie + 2,
458 country_ie[1]); 498 country_ie[1]);
459} 499}
@@ -488,7 +528,7 @@ void cfg80211_connect_result(struct net_device *dev, const u8 *bssid,
488 spin_lock_irqsave(&wdev->event_lock, flags); 528 spin_lock_irqsave(&wdev->event_lock, flags);
489 list_add_tail(&ev->list, &wdev->event_list); 529 list_add_tail(&ev->list, &wdev->event_list);
490 spin_unlock_irqrestore(&wdev->event_lock, flags); 530 spin_unlock_irqrestore(&wdev->event_lock, flags);
491 schedule_work(&rdev->event_work); 531 queue_work(cfg80211_wq, &rdev->event_work);
492} 532}
493EXPORT_SYMBOL(cfg80211_connect_result); 533EXPORT_SYMBOL(cfg80211_connect_result);
494 534
@@ -497,7 +537,7 @@ void __cfg80211_roamed(struct wireless_dev *wdev, const u8 *bssid,
497 const u8 *resp_ie, size_t resp_ie_len) 537 const u8 *resp_ie, size_t resp_ie_len)
498{ 538{
499 struct cfg80211_bss *bss; 539 struct cfg80211_bss *bss;
500#ifdef CONFIG_WIRELESS_EXT 540#ifdef CONFIG_CFG80211_WEXT
501 union iwreq_data wrqu; 541 union iwreq_data wrqu;
502#endif 542#endif
503 543
@@ -532,7 +572,7 @@ void __cfg80211_roamed(struct wireless_dev *wdev, const u8 *bssid,
532 req_ie, req_ie_len, resp_ie, resp_ie_len, 572 req_ie, req_ie_len, resp_ie, resp_ie_len,
533 GFP_KERNEL); 573 GFP_KERNEL);
534 574
535#ifdef CONFIG_WIRELESS_EXT 575#ifdef CONFIG_CFG80211_WEXT
536 if (req_ie) { 576 if (req_ie) {
537 memset(&wrqu, 0, sizeof(wrqu)); 577 memset(&wrqu, 0, sizeof(wrqu));
538 wrqu.data.length = req_ie_len; 578 wrqu.data.length = req_ie_len;
@@ -583,7 +623,7 @@ void cfg80211_roamed(struct net_device *dev, const u8 *bssid,
583 spin_lock_irqsave(&wdev->event_lock, flags); 623 spin_lock_irqsave(&wdev->event_lock, flags);
584 list_add_tail(&ev->list, &wdev->event_list); 624 list_add_tail(&ev->list, &wdev->event_list);
585 spin_unlock_irqrestore(&wdev->event_lock, flags); 625 spin_unlock_irqrestore(&wdev->event_lock, flags);
586 schedule_work(&rdev->event_work); 626 queue_work(cfg80211_wq, &rdev->event_work);
587} 627}
588EXPORT_SYMBOL(cfg80211_roamed); 628EXPORT_SYMBOL(cfg80211_roamed);
589 629
@@ -593,7 +633,7 @@ void __cfg80211_disconnected(struct net_device *dev, const u8 *ie,
593 struct wireless_dev *wdev = dev->ieee80211_ptr; 633 struct wireless_dev *wdev = dev->ieee80211_ptr;
594 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); 634 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
595 int i; 635 int i;
596#ifdef CONFIG_WIRELESS_EXT 636#ifdef CONFIG_CFG80211_WEXT
597 union iwreq_data wrqu; 637 union iwreq_data wrqu;
598#endif 638#endif
599 639
@@ -651,11 +691,14 @@ void __cfg80211_disconnected(struct net_device *dev, const u8 *ie,
651 for (i = 0; i < 6; i++) 691 for (i = 0; i < 6; i++)
652 rdev->ops->del_key(wdev->wiphy, dev, i, NULL); 692 rdev->ops->del_key(wdev->wiphy, dev, i, NULL);
653 693
654#ifdef CONFIG_WIRELESS_EXT 694#ifdef CONFIG_CFG80211_WEXT
655 memset(&wrqu, 0, sizeof(wrqu)); 695 memset(&wrqu, 0, sizeof(wrqu));
656 wrqu.ap_addr.sa_family = ARPHRD_ETHER; 696 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
657 wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL); 697 wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL);
698 wdev->wext.connect.ssid_len = 0;
658#endif 699#endif
700
701 schedule_work(&cfg80211_disconnect_work);
659} 702}
660 703
661void cfg80211_disconnected(struct net_device *dev, u16 reason, 704void cfg80211_disconnected(struct net_device *dev, u16 reason,
@@ -681,7 +724,7 @@ void cfg80211_disconnected(struct net_device *dev, u16 reason,
681 spin_lock_irqsave(&wdev->event_lock, flags); 724 spin_lock_irqsave(&wdev->event_lock, flags);
682 list_add_tail(&ev->list, &wdev->event_list); 725 list_add_tail(&ev->list, &wdev->event_list);
683 spin_unlock_irqrestore(&wdev->event_lock, flags); 726 spin_unlock_irqrestore(&wdev->event_lock, flags);
684 schedule_work(&rdev->event_work); 727 queue_work(cfg80211_wq, &rdev->event_work);
685} 728}
686EXPORT_SYMBOL(cfg80211_disconnected); 729EXPORT_SYMBOL(cfg80211_disconnected);
687 730
diff --git a/net/wireless/sysfs.c b/net/wireless/sysfs.c
index efe3c5c92b2d..9f2cef3e0ca0 100644
--- a/net/wireless/sysfs.c
+++ b/net/wireless/sysfs.c
@@ -33,10 +33,30 @@ static ssize_t name ## _show(struct device *dev, \
33 33
34SHOW_FMT(index, "%d", wiphy_idx); 34SHOW_FMT(index, "%d", wiphy_idx);
35SHOW_FMT(macaddress, "%pM", wiphy.perm_addr); 35SHOW_FMT(macaddress, "%pM", wiphy.perm_addr);
36SHOW_FMT(address_mask, "%pM", wiphy.addr_mask);
37
38static ssize_t addresses_show(struct device *dev,
39 struct device_attribute *attr,
40 char *buf)
41{
42 struct wiphy *wiphy = &dev_to_rdev(dev)->wiphy;
43 char *start = buf;
44 int i;
45
46 if (!wiphy->addresses)
47 return sprintf(buf, "%pM\n", wiphy->perm_addr);
48
49 for (i = 0; i < wiphy->n_addresses; i++)
50 buf += sprintf(buf, "%pM\n", &wiphy->addresses[i].addr);
51
52 return buf - start;
53}
36 54
37static struct device_attribute ieee80211_dev_attrs[] = { 55static struct device_attribute ieee80211_dev_attrs[] = {
38 __ATTR_RO(index), 56 __ATTR_RO(index),
39 __ATTR_RO(macaddress), 57 __ATTR_RO(macaddress),
58 __ATTR_RO(address_mask),
59 __ATTR_RO(addresses),
40 {} 60 {}
41}; 61};
42 62
diff --git a/net/wireless/util.c b/net/wireless/util.c
index 3fc2df86278f..d3574a4eb3ba 100644
--- a/net/wireless/util.c
+++ b/net/wireless/util.c
@@ -5,6 +5,7 @@
5 */ 5 */
6#include <linux/bitops.h> 6#include <linux/bitops.h>
7#include <linux/etherdevice.h> 7#include <linux/etherdevice.h>
8#include <linux/slab.h>
8#include <net/cfg80211.h> 9#include <net/cfg80211.h>
9#include <net/ip.h> 10#include <net/ip.h>
10#include "core.h" 11#include "core.h"
@@ -227,8 +228,11 @@ unsigned int ieee80211_hdrlen(__le16 fc)
227 if (ieee80211_is_data(fc)) { 228 if (ieee80211_is_data(fc)) {
228 if (ieee80211_has_a4(fc)) 229 if (ieee80211_has_a4(fc))
229 hdrlen = 30; 230 hdrlen = 30;
230 if (ieee80211_is_data_qos(fc)) 231 if (ieee80211_is_data_qos(fc)) {
231 hdrlen += IEEE80211_QOS_CTL_LEN; 232 hdrlen += IEEE80211_QOS_CTL_LEN;
233 if (ieee80211_has_order(fc))
234 hdrlen += IEEE80211_HT_CTL_LEN;
235 }
232 goto out; 236 goto out;
233 } 237 }
234 238
@@ -285,7 +289,7 @@ static int ieee80211_get_mesh_hdrlen(struct ieee80211s_hdr *meshhdr)
285 } 289 }
286} 290}
287 291
288int ieee80211_data_to_8023(struct sk_buff *skb, u8 *addr, 292int ieee80211_data_to_8023(struct sk_buff *skb, const u8 *addr,
289 enum nl80211_iftype iftype) 293 enum nl80211_iftype iftype)
290{ 294{
291 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; 295 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
@@ -320,7 +324,9 @@ int ieee80211_data_to_8023(struct sk_buff *skb, u8 *addr,
320 break; 324 break;
321 case cpu_to_le16(IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS): 325 case cpu_to_le16(IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS):
322 if (unlikely(iftype != NL80211_IFTYPE_WDS && 326 if (unlikely(iftype != NL80211_IFTYPE_WDS &&
323 iftype != NL80211_IFTYPE_MESH_POINT)) 327 iftype != NL80211_IFTYPE_MESH_POINT &&
328 iftype != NL80211_IFTYPE_AP_VLAN &&
329 iftype != NL80211_IFTYPE_STATION))
324 return -1; 330 return -1;
325 if (iftype == NL80211_IFTYPE_MESH_POINT) { 331 if (iftype == NL80211_IFTYPE_MESH_POINT) {
326 struct ieee80211s_hdr *meshdr = 332 struct ieee80211s_hdr *meshdr =
@@ -381,7 +387,7 @@ int ieee80211_data_to_8023(struct sk_buff *skb, u8 *addr,
381} 387}
382EXPORT_SYMBOL(ieee80211_data_to_8023); 388EXPORT_SYMBOL(ieee80211_data_to_8023);
383 389
384int ieee80211_data_from_8023(struct sk_buff *skb, u8 *addr, 390int ieee80211_data_from_8023(struct sk_buff *skb, const u8 *addr,
385 enum nl80211_iftype iftype, u8 *bssid, bool qos) 391 enum nl80211_iftype iftype, u8 *bssid, bool qos)
386{ 392{
387 struct ieee80211_hdr hdr; 393 struct ieee80211_hdr hdr;
@@ -495,6 +501,101 @@ int ieee80211_data_from_8023(struct sk_buff *skb, u8 *addr,
495} 501}
496EXPORT_SYMBOL(ieee80211_data_from_8023); 502EXPORT_SYMBOL(ieee80211_data_from_8023);
497 503
504
505void ieee80211_amsdu_to_8023s(struct sk_buff *skb, struct sk_buff_head *list,
506 const u8 *addr, enum nl80211_iftype iftype,
507 const unsigned int extra_headroom)
508{
509 struct sk_buff *frame = NULL;
510 u16 ethertype;
511 u8 *payload;
512 const struct ethhdr *eth;
513 int remaining, err;
514 u8 dst[ETH_ALEN], src[ETH_ALEN];
515
516 err = ieee80211_data_to_8023(skb, addr, iftype);
517 if (err)
518 goto out;
519
520 /* skip the wrapping header */
521 eth = (struct ethhdr *) skb_pull(skb, sizeof(struct ethhdr));
522 if (!eth)
523 goto out;
524
525 while (skb != frame) {
526 u8 padding;
527 __be16 len = eth->h_proto;
528 unsigned int subframe_len = sizeof(struct ethhdr) + ntohs(len);
529
530 remaining = skb->len;
531 memcpy(dst, eth->h_dest, ETH_ALEN);
532 memcpy(src, eth->h_source, ETH_ALEN);
533
534 padding = (4 - subframe_len) & 0x3;
535 /* the last MSDU has no padding */
536 if (subframe_len > remaining)
537 goto purge;
538
539 skb_pull(skb, sizeof(struct ethhdr));
540 /* reuse skb for the last subframe */
541 if (remaining <= subframe_len + padding)
542 frame = skb;
543 else {
544 unsigned int hlen = ALIGN(extra_headroom, 4);
545 /*
546 * Allocate and reserve two bytes more for payload
547 * alignment since sizeof(struct ethhdr) is 14.
548 */
549 frame = dev_alloc_skb(hlen + subframe_len + 2);
550 if (!frame)
551 goto purge;
552
553 skb_reserve(frame, hlen + sizeof(struct ethhdr) + 2);
554 memcpy(skb_put(frame, ntohs(len)), skb->data,
555 ntohs(len));
556
557 eth = (struct ethhdr *)skb_pull(skb, ntohs(len) +
558 padding);
559 if (!eth) {
560 dev_kfree_skb(frame);
561 goto purge;
562 }
563 }
564
565 skb_reset_network_header(frame);
566 frame->dev = skb->dev;
567 frame->priority = skb->priority;
568
569 payload = frame->data;
570 ethertype = (payload[6] << 8) | payload[7];
571
572 if (likely((compare_ether_addr(payload, rfc1042_header) == 0 &&
573 ethertype != ETH_P_AARP && ethertype != ETH_P_IPX) ||
574 compare_ether_addr(payload,
575 bridge_tunnel_header) == 0)) {
576 /* remove RFC1042 or Bridge-Tunnel
577 * encapsulation and replace EtherType */
578 skb_pull(frame, 6);
579 memcpy(skb_push(frame, ETH_ALEN), src, ETH_ALEN);
580 memcpy(skb_push(frame, ETH_ALEN), dst, ETH_ALEN);
581 } else {
582 memcpy(skb_push(frame, sizeof(__be16)), &len,
583 sizeof(__be16));
584 memcpy(skb_push(frame, ETH_ALEN), src, ETH_ALEN);
585 memcpy(skb_push(frame, ETH_ALEN), dst, ETH_ALEN);
586 }
587 __skb_queue_tail(list, frame);
588 }
589
590 return;
591
592 purge:
593 __skb_queue_purge(list);
594 out:
595 dev_kfree_skb(skb);
596}
597EXPORT_SYMBOL(ieee80211_amsdu_to_8023s);
598
498/* Given a data frame determine the 802.1p/1d tag to use. */ 599/* Given a data frame determine the 802.1p/1d tag to use. */
499unsigned int cfg80211_classify8021d(struct sk_buff *skb) 600unsigned int cfg80211_classify8021d(struct sk_buff *skb)
500{ 601{
@@ -656,7 +757,14 @@ int cfg80211_change_iface(struct cfg80211_registered_device *rdev,
656 !(rdev->wiphy.interface_modes & (1 << ntype))) 757 !(rdev->wiphy.interface_modes & (1 << ntype)))
657 return -EOPNOTSUPP; 758 return -EOPNOTSUPP;
658 759
760 /* if it's part of a bridge, reject changing type to station/ibss */
761 if (dev->br_port && (ntype == NL80211_IFTYPE_ADHOC ||
762 ntype == NL80211_IFTYPE_STATION))
763 return -EBUSY;
764
659 if (ntype != otype) { 765 if (ntype != otype) {
766 dev->ieee80211_ptr->use_4addr = false;
767
660 switch (otype) { 768 switch (otype) {
661 case NL80211_IFTYPE_ADHOC: 769 case NL80211_IFTYPE_ADHOC:
662 cfg80211_leave_ibss(rdev, dev, false); 770 cfg80211_leave_ibss(rdev, dev, false);
@@ -680,5 +788,67 @@ int cfg80211_change_iface(struct cfg80211_registered_device *rdev,
680 788
681 WARN_ON(!err && dev->ieee80211_ptr->iftype != ntype); 789 WARN_ON(!err && dev->ieee80211_ptr->iftype != ntype);
682 790
791 if (!err && params && params->use_4addr != -1)
792 dev->ieee80211_ptr->use_4addr = params->use_4addr;
793
794 if (!err) {
795 dev->priv_flags &= ~IFF_DONT_BRIDGE;
796 switch (ntype) {
797 case NL80211_IFTYPE_STATION:
798 if (dev->ieee80211_ptr->use_4addr)
799 break;
800 /* fall through */
801 case NL80211_IFTYPE_ADHOC:
802 dev->priv_flags |= IFF_DONT_BRIDGE;
803 break;
804 case NL80211_IFTYPE_AP:
805 case NL80211_IFTYPE_AP_VLAN:
806 case NL80211_IFTYPE_WDS:
807 case NL80211_IFTYPE_MESH_POINT:
808 /* bridging OK */
809 break;
810 case NL80211_IFTYPE_MONITOR:
811 /* monitor can't bridge anyway */
812 break;
813 case NL80211_IFTYPE_UNSPECIFIED:
814 case __NL80211_IFTYPE_AFTER_LAST:
815 /* not happening */
816 break;
817 }
818 }
819
683 return err; 820 return err;
684} 821}
822
823u16 cfg80211_calculate_bitrate(struct rate_info *rate)
824{
825 int modulation, streams, bitrate;
826
827 if (!(rate->flags & RATE_INFO_FLAGS_MCS))
828 return rate->legacy;
829
830 /* the formula below does only work for MCS values smaller than 32 */
831 if (rate->mcs >= 32)
832 return 0;
833
834 modulation = rate->mcs & 7;
835 streams = (rate->mcs >> 3) + 1;
836
837 bitrate = (rate->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH) ?
838 13500000 : 6500000;
839
840 if (modulation < 4)
841 bitrate *= (modulation + 1);
842 else if (modulation == 4)
843 bitrate *= (modulation + 2);
844 else
845 bitrate *= (modulation + 3);
846
847 bitrate *= streams;
848
849 if (rate->flags & RATE_INFO_FLAGS_SHORT_GI)
850 bitrate = (bitrate / 9) * 10;
851
852 /* do NOT round down here */
853 return (bitrate + 50000) / 100000;
854}
diff --git a/net/wireless/wext-compat.c b/net/wireless/wext-compat.c
index 561a45cf2a6a..a60a2773b497 100644
--- a/net/wireless/wext-compat.c
+++ b/net/wireless/wext-compat.c
@@ -12,6 +12,7 @@
12#include <linux/nl80211.h> 12#include <linux/nl80211.h>
13#include <linux/if_arp.h> 13#include <linux/if_arp.h>
14#include <linux/etherdevice.h> 14#include <linux/etherdevice.h>
15#include <linux/slab.h>
15#include <net/iw_handler.h> 16#include <net/iw_handler.h>
16#include <net/cfg80211.h> 17#include <net/cfg80211.h>
17#include "wext-compat.h" 18#include "wext-compat.h"
@@ -437,6 +438,7 @@ static int __cfg80211_set_encryption(struct cfg80211_registered_device *rdev,
437{ 438{
438 struct wireless_dev *wdev = dev->ieee80211_ptr; 439 struct wireless_dev *wdev = dev->ieee80211_ptr;
439 int err, i; 440 int err, i;
441 bool rejoin = false;
440 442
441 if (!wdev->wext.keys) { 443 if (!wdev->wext.keys) {
442 wdev->wext.keys = kzalloc(sizeof(*wdev->wext.keys), 444 wdev->wext.keys = kzalloc(sizeof(*wdev->wext.keys),
@@ -466,8 +468,25 @@ static int __cfg80211_set_encryption(struct cfg80211_registered_device *rdev,
466 468
467 if (remove) { 469 if (remove) {
468 err = 0; 470 err = 0;
469 if (wdev->current_bss) 471 if (wdev->current_bss) {
472 /*
473 * If removing the current TX key, we will need to
474 * join a new IBSS without the privacy bit clear.
475 */
476 if (idx == wdev->wext.default_key &&
477 wdev->iftype == NL80211_IFTYPE_ADHOC) {
478 __cfg80211_leave_ibss(rdev, wdev->netdev, true);
479 rejoin = true;
480 }
470 err = rdev->ops->del_key(&rdev->wiphy, dev, idx, addr); 481 err = rdev->ops->del_key(&rdev->wiphy, dev, idx, addr);
482 }
483 wdev->wext.connect.privacy = false;
484 /*
485 * Applications using wireless extensions expect to be
486 * able to delete keys that don't exist, so allow that.
487 */
488 if (err == -ENOENT)
489 err = 0;
471 if (!err) { 490 if (!err) {
472 if (!addr) { 491 if (!addr) {
473 wdev->wext.keys->params[idx].key_len = 0; 492 wdev->wext.keys->params[idx].key_len = 0;
@@ -478,12 +497,9 @@ static int __cfg80211_set_encryption(struct cfg80211_registered_device *rdev,
478 else if (idx == wdev->wext.default_mgmt_key) 497 else if (idx == wdev->wext.default_mgmt_key)
479 wdev->wext.default_mgmt_key = -1; 498 wdev->wext.default_mgmt_key = -1;
480 } 499 }
481 /* 500
482 * Applications using wireless extensions expect to be 501 if (!err && rejoin)
483 * able to delete keys that don't exist, so allow that. 502 err = cfg80211_ibss_wext_join(rdev, wdev);
484 */
485 if (err == -ENOENT)
486 return 0;
487 503
488 return err; 504 return err;
489 } 505 }
@@ -511,11 +527,25 @@ static int __cfg80211_set_encryption(struct cfg80211_registered_device *rdev,
511 if ((params->cipher == WLAN_CIPHER_SUITE_WEP40 || 527 if ((params->cipher == WLAN_CIPHER_SUITE_WEP40 ||
512 params->cipher == WLAN_CIPHER_SUITE_WEP104) && 528 params->cipher == WLAN_CIPHER_SUITE_WEP104) &&
513 (tx_key || (!addr && wdev->wext.default_key == -1))) { 529 (tx_key || (!addr && wdev->wext.default_key == -1))) {
514 if (wdev->current_bss) 530 if (wdev->current_bss) {
531 /*
532 * If we are getting a new TX key from not having
533 * had one before we need to join a new IBSS with
534 * the privacy bit set.
535 */
536 if (wdev->iftype == NL80211_IFTYPE_ADHOC &&
537 wdev->wext.default_key == -1) {
538 __cfg80211_leave_ibss(rdev, wdev->netdev, true);
539 rejoin = true;
540 }
515 err = rdev->ops->set_default_key(&rdev->wiphy, 541 err = rdev->ops->set_default_key(&rdev->wiphy,
516 dev, idx); 542 dev, idx);
517 if (!err) 543 }
544 if (!err) {
518 wdev->wext.default_key = idx; 545 wdev->wext.default_key = idx;
546 if (rejoin)
547 err = cfg80211_ibss_wext_join(rdev, wdev);
548 }
519 return err; 549 return err;
520 } 550 }
521 551
@@ -539,10 +569,13 @@ static int cfg80211_set_encryption(struct cfg80211_registered_device *rdev,
539{ 569{
540 int err; 570 int err;
541 571
572 /* devlist mutex needed for possible IBSS re-join */
573 mutex_lock(&rdev->devlist_mtx);
542 wdev_lock(dev->ieee80211_ptr); 574 wdev_lock(dev->ieee80211_ptr);
543 err = __cfg80211_set_encryption(rdev, dev, addr, remove, 575 err = __cfg80211_set_encryption(rdev, dev, addr, remove,
544 tx_key, idx, params); 576 tx_key, idx, params);
545 wdev_unlock(dev->ieee80211_ptr); 577 wdev_unlock(dev->ieee80211_ptr);
578 mutex_unlock(&rdev->devlist_mtx);
546 579
547 return err; 580 return err;
548} 581}
@@ -904,8 +937,6 @@ static int cfg80211_set_auth_alg(struct wireless_dev *wdev,
904 937
905static int cfg80211_set_wpa_version(struct wireless_dev *wdev, u32 wpa_versions) 938static int cfg80211_set_wpa_version(struct wireless_dev *wdev, u32 wpa_versions)
906{ 939{
907 wdev->wext.connect.crypto.wpa_versions = 0;
908
909 if (wpa_versions & ~(IW_AUTH_WPA_VERSION_WPA | 940 if (wpa_versions & ~(IW_AUTH_WPA_VERSION_WPA |
910 IW_AUTH_WPA_VERSION_WPA2| 941 IW_AUTH_WPA_VERSION_WPA2|
911 IW_AUTH_WPA_VERSION_DISABLED)) 942 IW_AUTH_WPA_VERSION_DISABLED))
@@ -933,8 +964,6 @@ static int cfg80211_set_wpa_version(struct wireless_dev *wdev, u32 wpa_versions)
933 964
934static int cfg80211_set_cipher_group(struct wireless_dev *wdev, u32 cipher) 965static int cfg80211_set_cipher_group(struct wireless_dev *wdev, u32 cipher)
935{ 966{
936 wdev->wext.connect.crypto.cipher_group = 0;
937
938 if (cipher & IW_AUTH_CIPHER_WEP40) 967 if (cipher & IW_AUTH_CIPHER_WEP40)
939 wdev->wext.connect.crypto.cipher_group = 968 wdev->wext.connect.crypto.cipher_group =
940 WLAN_CIPHER_SUITE_WEP40; 969 WLAN_CIPHER_SUITE_WEP40;
@@ -950,6 +979,8 @@ static int cfg80211_set_cipher_group(struct wireless_dev *wdev, u32 cipher)
950 else if (cipher & IW_AUTH_CIPHER_AES_CMAC) 979 else if (cipher & IW_AUTH_CIPHER_AES_CMAC)
951 wdev->wext.connect.crypto.cipher_group = 980 wdev->wext.connect.crypto.cipher_group =
952 WLAN_CIPHER_SUITE_AES_CMAC; 981 WLAN_CIPHER_SUITE_AES_CMAC;
982 else if (cipher & IW_AUTH_CIPHER_NONE)
983 wdev->wext.connect.crypto.cipher_group = 0;
953 else 984 else
954 return -EINVAL; 985 return -EINVAL;
955 986
@@ -1069,8 +1100,8 @@ int cfg80211_wext_siwpower(struct net_device *dev,
1069{ 1100{
1070 struct wireless_dev *wdev = dev->ieee80211_ptr; 1101 struct wireless_dev *wdev = dev->ieee80211_ptr;
1071 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); 1102 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
1072 bool ps = wdev->wext.ps; 1103 bool ps = wdev->ps;
1073 int timeout = wdev->wext.ps_timeout; 1104 int timeout = wdev->ps_timeout;
1074 int err; 1105 int err;
1075 1106
1076 if (wdev->iftype != NL80211_IFTYPE_STATION) 1107 if (wdev->iftype != NL80211_IFTYPE_STATION)
@@ -1103,8 +1134,8 @@ int cfg80211_wext_siwpower(struct net_device *dev,
1103 if (err) 1134 if (err)
1104 return err; 1135 return err;
1105 1136
1106 wdev->wext.ps = ps; 1137 wdev->ps = ps;
1107 wdev->wext.ps_timeout = timeout; 1138 wdev->ps_timeout = timeout;
1108 1139
1109 return 0; 1140 return 0;
1110 1141
@@ -1117,7 +1148,7 @@ int cfg80211_wext_giwpower(struct net_device *dev,
1117{ 1148{
1118 struct wireless_dev *wdev = dev->ieee80211_ptr; 1149 struct wireless_dev *wdev = dev->ieee80211_ptr;
1119 1150
1120 wrq->disabled = !wdev->wext.ps; 1151 wrq->disabled = !wdev->ps;
1121 1152
1122 return 0; 1153 return 0;
1123} 1154}
@@ -1174,21 +1205,47 @@ int cfg80211_wext_siwrate(struct net_device *dev,
1174 struct wireless_dev *wdev = dev->ieee80211_ptr; 1205 struct wireless_dev *wdev = dev->ieee80211_ptr;
1175 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); 1206 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
1176 struct cfg80211_bitrate_mask mask; 1207 struct cfg80211_bitrate_mask mask;
1208 u32 fixed, maxrate;
1209 struct ieee80211_supported_band *sband;
1210 int band, ridx;
1211 bool match = false;
1177 1212
1178 if (!rdev->ops->set_bitrate_mask) 1213 if (!rdev->ops->set_bitrate_mask)
1179 return -EOPNOTSUPP; 1214 return -EOPNOTSUPP;
1180 1215
1181 mask.fixed = 0; 1216 memset(&mask, 0, sizeof(mask));
1182 mask.maxrate = 0; 1217 fixed = 0;
1218 maxrate = (u32)-1;
1183 1219
1184 if (rate->value < 0) { 1220 if (rate->value < 0) {
1185 /* nothing */ 1221 /* nothing */
1186 } else if (rate->fixed) { 1222 } else if (rate->fixed) {
1187 mask.fixed = rate->value / 1000; /* kbps */ 1223 fixed = rate->value / 100000;
1188 } else { 1224 } else {
1189 mask.maxrate = rate->value / 1000; /* kbps */ 1225 maxrate = rate->value / 100000;
1190 } 1226 }
1191 1227
1228 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1229 sband = wdev->wiphy->bands[band];
1230 if (sband == NULL)
1231 continue;
1232 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
1233 struct ieee80211_rate *srate = &sband->bitrates[ridx];
1234 if (fixed == srate->bitrate) {
1235 mask.control[band].legacy = 1 << ridx;
1236 match = true;
1237 break;
1238 }
1239 if (srate->bitrate <= maxrate) {
1240 mask.control[band].legacy |= 1 << ridx;
1241 match = true;
1242 }
1243 }
1244 }
1245
1246 if (!match)
1247 return -EINVAL;
1248
1192 return rdev->ops->set_bitrate_mask(wdev->wiphy, dev, NULL, &mask); 1249 return rdev->ops->set_bitrate_mask(wdev->wiphy, dev, NULL, &mask);
1193} 1250}
1194EXPORT_SYMBOL_GPL(cfg80211_wext_siwrate); 1251EXPORT_SYMBOL_GPL(cfg80211_wext_siwrate);
@@ -1227,10 +1284,7 @@ int cfg80211_wext_giwrate(struct net_device *dev,
1227 if (!(sinfo.filled & STATION_INFO_TX_BITRATE)) 1284 if (!(sinfo.filled & STATION_INFO_TX_BITRATE))
1228 return -EOPNOTSUPP; 1285 return -EOPNOTSUPP;
1229 1286
1230 rate->value = 0; 1287 rate->value = 100000 * cfg80211_calculate_bitrate(&sinfo.txrate);
1231
1232 if (!(sinfo.txrate.flags & RATE_INFO_FLAGS_MCS))
1233 rate->value = 100000 * sinfo.txrate.legacy;
1234 1288
1235 return 0; 1289 return 0;
1236} 1290}
@@ -1372,6 +1426,47 @@ int cfg80211_wext_giwessid(struct net_device *dev,
1372} 1426}
1373EXPORT_SYMBOL_GPL(cfg80211_wext_giwessid); 1427EXPORT_SYMBOL_GPL(cfg80211_wext_giwessid);
1374 1428
1429int cfg80211_wext_siwpmksa(struct net_device *dev,
1430 struct iw_request_info *info,
1431 struct iw_point *data, char *extra)
1432{
1433 struct wireless_dev *wdev = dev->ieee80211_ptr;
1434 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
1435 struct cfg80211_pmksa cfg_pmksa;
1436 struct iw_pmksa *pmksa = (struct iw_pmksa *)extra;
1437
1438 memset(&cfg_pmksa, 0, sizeof(struct cfg80211_pmksa));
1439
1440 if (wdev->iftype != NL80211_IFTYPE_STATION)
1441 return -EINVAL;
1442
1443 cfg_pmksa.bssid = pmksa->bssid.sa_data;
1444 cfg_pmksa.pmkid = pmksa->pmkid;
1445
1446 switch (pmksa->cmd) {
1447 case IW_PMKSA_ADD:
1448 if (!rdev->ops->set_pmksa)
1449 return -EOPNOTSUPP;
1450
1451 return rdev->ops->set_pmksa(&rdev->wiphy, dev, &cfg_pmksa);
1452
1453 case IW_PMKSA_REMOVE:
1454 if (!rdev->ops->del_pmksa)
1455 return -EOPNOTSUPP;
1456
1457 return rdev->ops->del_pmksa(&rdev->wiphy, dev, &cfg_pmksa);
1458
1459 case IW_PMKSA_FLUSH:
1460 if (!rdev->ops->flush_pmksa)
1461 return -EOPNOTSUPP;
1462
1463 return rdev->ops->flush_pmksa(&rdev->wiphy, dev);
1464
1465 default:
1466 return -EOPNOTSUPP;
1467 }
1468}
1469
1375static const iw_handler cfg80211_handlers[] = { 1470static const iw_handler cfg80211_handlers[] = {
1376 [IW_IOCTL_IDX(SIOCGIWNAME)] = (iw_handler) cfg80211_wext_giwname, 1471 [IW_IOCTL_IDX(SIOCGIWNAME)] = (iw_handler) cfg80211_wext_giwname,
1377 [IW_IOCTL_IDX(SIOCSIWFREQ)] = (iw_handler) cfg80211_wext_siwfreq, 1472 [IW_IOCTL_IDX(SIOCSIWFREQ)] = (iw_handler) cfg80211_wext_siwfreq,
@@ -1404,6 +1499,7 @@ static const iw_handler cfg80211_handlers[] = {
1404 [IW_IOCTL_IDX(SIOCSIWAUTH)] = (iw_handler) cfg80211_wext_siwauth, 1499 [IW_IOCTL_IDX(SIOCSIWAUTH)] = (iw_handler) cfg80211_wext_siwauth,
1405 [IW_IOCTL_IDX(SIOCGIWAUTH)] = (iw_handler) cfg80211_wext_giwauth, 1500 [IW_IOCTL_IDX(SIOCGIWAUTH)] = (iw_handler) cfg80211_wext_giwauth,
1406 [IW_IOCTL_IDX(SIOCSIWENCODEEXT)]= (iw_handler) cfg80211_wext_siwencodeext, 1501 [IW_IOCTL_IDX(SIOCSIWENCODEEXT)]= (iw_handler) cfg80211_wext_siwencodeext,
1502 [IW_IOCTL_IDX(SIOCSIWPMKSA)] = (iw_handler) cfg80211_wext_siwpmksa,
1407}; 1503};
1408 1504
1409const struct iw_handler_def cfg80211_wext_handler = { 1505const struct iw_handler_def cfg80211_wext_handler = {
diff --git a/net/wireless/wext.c b/net/wireless/wext-core.c
index 60fe57761ca9..4f5a47091fde 100644
--- a/net/wireless/wext.c
+++ b/net/wireless/wext-core.c
@@ -1,112 +1,29 @@
1/* 1/*
2 * This file implement the Wireless Extensions APIs. 2 * This file implement the Wireless Extensions core API.
3 * 3 *
4 * Authors : Jean Tourrilhes - HPL - <jt@hpl.hp.com> 4 * Authors : Jean Tourrilhes - HPL - <jt@hpl.hp.com>
5 * Copyright (c) 1997-2007 Jean Tourrilhes, All Rights Reserved. 5 * Copyright (c) 1997-2007 Jean Tourrilhes, All Rights Reserved.
6 * Copyright 2009 Johannes Berg <johannes@sipsolutions.net>
6 * 7 *
7 * (As all part of the Linux kernel, this file is GPL) 8 * (As all part of the Linux kernel, this file is GPL)
8 */ 9 */
9 10#include <linux/kernel.h>
10/************************** DOCUMENTATION **************************/ 11#include <linux/netdevice.h>
11/* 12#include <linux/rtnetlink.h>
12 * API definition : 13#include <linux/slab.h>
13 * -------------- 14#include <linux/wireless.h>
14 * See <linux/wireless.h> for details of the APIs and the rest. 15#include <linux/uaccess.h>
15 * 16#include <net/cfg80211.h>
16 * History : 17#include <net/iw_handler.h>
17 * -------
18 *
19 * v1 - 5.12.01 - Jean II
20 * o Created this file.
21 *
22 * v2 - 13.12.01 - Jean II
23 * o Move /proc/net/wireless stuff from net/core/dev.c to here
24 * o Make Wireless Extension IOCTLs go through here
25 * o Added iw_handler handling ;-)
26 * o Added standard ioctl description
27 * o Initial dumb commit strategy based on orinoco.c
28 *
29 * v3 - 19.12.01 - Jean II
30 * o Make sure we don't go out of standard_ioctl[] in ioctl_standard_call
31 * o Add event dispatcher function
32 * o Add event description
33 * o Propagate events as rtnetlink IFLA_WIRELESS option
34 * o Generate event on selected SET requests
35 *
36 * v4 - 18.04.02 - Jean II
37 * o Fix stupid off by one in iw_ioctl_description : IW_ESSID_MAX_SIZE + 1
38 *
39 * v5 - 21.06.02 - Jean II
40 * o Add IW_PRIV_TYPE_ADDR in priv_type_size (+cleanup)
41 * o Reshuffle IW_HEADER_TYPE_XXX to map IW_PRIV_TYPE_XXX changes
42 * o Add IWEVCUSTOM for driver specific event/scanning token
43 * o Turn on WE_STRICT_WRITE by default + kernel warning
44 * o Fix WE_STRICT_WRITE in ioctl_export_private() (32 => iw_num)
45 * o Fix off-by-one in test (extra_size <= IFNAMSIZ)
46 *
47 * v6 - 9.01.03 - Jean II
48 * o Add common spy support : iw_handler_set_spy(), wireless_spy_update()
49 * o Add enhanced spy support : iw_handler_set_thrspy() and event.
50 * o Add WIRELESS_EXT version display in /proc/net/wireless
51 *
52 * v6 - 18.06.04 - Jean II
53 * o Change get_spydata() method for added safety
54 * o Remove spy #ifdef, they are always on -> cleaner code
55 * o Allow any size GET request if user specifies length > max
56 * and if request has IW_DESCR_FLAG_NOMAX flag or is SIOCGIWPRIV
57 * o Start migrating get_wireless_stats to struct iw_handler_def
58 * o Add wmb() in iw_handler_set_spy() for non-coherent archs/cpus
59 * Based on patch from Pavel Roskin <proski@gnu.org> :
60 * o Fix kernel data leak to user space in private handler handling
61 *
62 * v7 - 18.3.05 - Jean II
63 * o Remove (struct iw_point *)->pointer from events and streams
64 * o Remove spy_offset from struct iw_handler_def
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
67 * o Don't lose INVALID/DBM flags when clearing UPDATED flags (iwstats)
68 *
69 * v8 - 17.02.06 - Jean II
70 * o RtNetlink requests support (SET/GET)
71 *
72 * v8b - 03.08.06 - Herbert Xu
73 * o Fix Wireless Event locking issues.
74 *
75 * v9 - 14.3.06 - Jean II
76 * o Change length in ESSID and NICK to strlen() instead of strlen()+1
77 * o Make standard_ioctl_num and standard_event_num unsigned
78 * o Remove (struct net_device *)->get_wireless_stats()
79 *
80 * v10 - 16.3.07 - Jean II
81 * o Prevent leaking of kernel space in stream on 64 bits.
82 */
83
84/***************************** INCLUDES *****************************/
85
86#include <linux/module.h>
87#include <linux/types.h> /* off_t */
88#include <linux/netdevice.h> /* struct ifreq, dev_get_by_name() */
89#include <linux/proc_fs.h>
90#include <linux/rtnetlink.h> /* rtnetlink stuff */
91#include <linux/seq_file.h>
92#include <linux/init.h> /* for __init */
93#include <linux/if_arp.h> /* ARPHRD_ETHER */
94#include <linux/etherdevice.h> /* compare_ether_addr */
95#include <linux/interrupt.h>
96#include <net/net_namespace.h>
97
98#include <linux/wireless.h> /* Pretty obvious */
99#include <net/iw_handler.h> /* New driver API */
100#include <net/netlink.h> 18#include <net/netlink.h>
101#include <net/wext.h> 19#include <net/wext.h>
20#include <net/net_namespace.h>
21
22typedef int (*wext_ioctl_func)(struct net_device *, struct iwreq *,
23 unsigned int, struct iw_request_info *,
24 iw_handler);
102 25
103#include <asm/uaccess.h> /* copy_to_user() */
104 26
105/************************* GLOBAL VARIABLES *************************/
106/*
107 * You should not use global variables, because of re-entrancy.
108 * On our case, it's only const, so it's OK...
109 */
110/* 27/*
111 * Meta-data about all the standard Wireless Extension request we 28 * Meta-data about all the standard Wireless Extension request we
112 * know about. 29 * know about.
@@ -390,18 +307,6 @@ static const struct iw_ioctl_description standard_event[] = {
390}; 307};
391static const unsigned standard_event_num = ARRAY_SIZE(standard_event); 308static const unsigned standard_event_num = ARRAY_SIZE(standard_event);
392 309
393/* Size (in bytes) of the various private data types */
394static const char iw_priv_type_size[] = {
395 0, /* IW_PRIV_TYPE_NONE */
396 1, /* IW_PRIV_TYPE_BYTE */
397 1, /* IW_PRIV_TYPE_CHAR */
398 0, /* Not defined */
399 sizeof(__u32), /* IW_PRIV_TYPE_INT */
400 sizeof(struct iw_freq), /* IW_PRIV_TYPE_FLOAT */
401 sizeof(struct sockaddr), /* IW_PRIV_TYPE_ADDR */
402 0, /* Not defined */
403};
404
405/* Size (in bytes) of various events */ 310/* Size (in bytes) of various events */
406static const int event_type_size[] = { 311static const int event_type_size[] = {
407 IW_EV_LCP_LEN, /* IW_HEADER_TYPE_NULL */ 312 IW_EV_LCP_LEN, /* IW_HEADER_TYPE_NULL */
@@ -433,323 +338,346 @@ static const int compat_event_type_size[] = {
433}; 338};
434#endif 339#endif
435 340
436/************************ COMMON SUBROUTINES ************************/
437/*
438 * Stuff that may be used in various place or doesn't fit in one
439 * of the section below.
440 */
441
442/* ---------------------------------------------------------------- */
443/*
444 * Return the driver handler associated with a specific Wireless Extension.
445 */
446static iw_handler get_handler(struct net_device *dev, unsigned int cmd)
447{
448 /* Don't "optimise" the following variable, it will crash */
449 unsigned int index; /* *MUST* be unsigned */
450 341
451 /* Check if we have some wireless handlers defined */ 342/* IW event code */
452 if (dev->wireless_handlers == NULL)
453 return NULL;
454
455 /* Try as a standard command */
456 index = cmd - SIOCIWFIRST;
457 if (index < dev->wireless_handlers->num_standard)
458 return dev->wireless_handlers->standard[index];
459
460 /* Try as a private command */
461 index = cmd - SIOCIWFIRSTPRIV;
462 if (index < dev->wireless_handlers->num_private)
463 return dev->wireless_handlers->private[index];
464 343
465 /* Not found */ 344static int __net_init wext_pernet_init(struct net *net)
466 return NULL;
467}
468
469/* ---------------------------------------------------------------- */
470/*
471 * Get statistics out of the driver
472 */
473struct iw_statistics *get_wireless_stats(struct net_device *dev)
474{ 345{
475 /* New location */ 346 skb_queue_head_init(&net->wext_nlevents);
476 if ((dev->wireless_handlers != NULL) && 347 return 0;
477 (dev->wireless_handlers->get_wireless_stats != NULL))
478 return dev->wireless_handlers->get_wireless_stats(dev);
479
480 /* Not found */
481 return NULL;
482} 348}
483 349
484/* ---------------------------------------------------------------- */ 350static void __net_exit wext_pernet_exit(struct net *net)
485/*
486 * Call the commit handler in the driver
487 * (if exist and if conditions are right)
488 *
489 * Note : our current commit strategy is currently pretty dumb,
490 * but we will be able to improve on that...
491 * The goal is to try to agreagate as many changes as possible
492 * before doing the commit. Drivers that will define a commit handler
493 * are usually those that need a reset after changing parameters, so
494 * we want to minimise the number of reset.
495 * A cool idea is to use a timer : at each "set" command, we re-set the
496 * timer, when the timer eventually fires, we call the driver.
497 * Hopefully, more on that later.
498 *
499 * Also, I'm waiting to see how many people will complain about the
500 * netif_running(dev) test. I'm open on that one...
501 * Hopefully, the driver will remember to do a commit in "open()" ;-)
502 */
503static int call_commit_handler(struct net_device *dev)
504{ 351{
505 if ((netif_running(dev)) && 352 skb_queue_purge(&net->wext_nlevents);
506 (dev->wireless_handlers->standard[0] != NULL))
507 /* Call the commit handler on the driver */
508 return dev->wireless_handlers->standard[0](dev, NULL,
509 NULL, NULL);
510 else
511 return 0; /* Command completed successfully */
512} 353}
513 354
514/* ---------------------------------------------------------------- */ 355static struct pernet_operations wext_pernet_ops = {
515/* 356 .init = wext_pernet_init,
516 * Calculate size of private arguments 357 .exit = wext_pernet_exit,
517 */ 358};
518static int get_priv_size(__u16 args)
519{
520 int num = args & IW_PRIV_SIZE_MASK;
521 int type = (args & IW_PRIV_TYPE_MASK) >> 12;
522 359
523 return num * iw_priv_type_size[type]; 360static int __init wireless_nlevent_init(void)
361{
362 return register_pernet_subsys(&wext_pernet_ops);
524} 363}
525 364
526/* ---------------------------------------------------------------- */ 365subsys_initcall(wireless_nlevent_init);
527/* 366
528 * Re-calculate the size of private arguments 367/* Process events generated by the wireless layer or the driver. */
529 */ 368static void wireless_nlevent_process(struct work_struct *work)
530static int adjust_priv_size(__u16 args, struct iw_point *iwp)
531{ 369{
532 int num = iwp->length; 370 struct sk_buff *skb;
533 int max = args & IW_PRIV_SIZE_MASK; 371 struct net *net;
534 int type = (args & IW_PRIV_TYPE_MASK) >> 12;
535 372
536 /* Make sure the driver doesn't goof up */ 373 rtnl_lock();
537 if (max < num) 374
538 num = max; 375 for_each_net(net) {
376 while ((skb = skb_dequeue(&net->wext_nlevents)))
377 rtnl_notify(skb, net, 0, RTNLGRP_LINK, NULL,
378 GFP_KERNEL);
379 }
539 380
540 return num * iw_priv_type_size[type]; 381 rtnl_unlock();
541} 382}
542 383
543/* ---------------------------------------------------------------- */ 384static DECLARE_WORK(wireless_nlevent_work, wireless_nlevent_process);
544/* 385
545 * Standard Wireless Handler : get wireless stats 386static struct nlmsghdr *rtnetlink_ifinfo_prep(struct net_device *dev,
546 * Allow programatic access to /proc/net/wireless even if /proc 387 struct sk_buff *skb)
547 * doesn't exist... Also more efficient...
548 */
549static int iw_handler_get_iwstats(struct net_device * dev,
550 struct iw_request_info * info,
551 union iwreq_data * wrqu,
552 char * extra)
553{ 388{
554 /* Get stats from the driver */ 389 struct ifinfomsg *r;
555 struct iw_statistics *stats; 390 struct nlmsghdr *nlh;
556 391
557 stats = get_wireless_stats(dev); 392 nlh = nlmsg_put(skb, 0, 0, RTM_NEWLINK, sizeof(*r), 0);
558 if (stats) { 393 if (!nlh)
559 /* Copy statistics to extra */ 394 return NULL;
560 memcpy(extra, stats, sizeof(struct iw_statistics));
561 wrqu->data.length = sizeof(struct iw_statistics);
562 395
563 /* Check if we need to clear the updated flag */ 396 r = nlmsg_data(nlh);
564 if (wrqu->data.flags != 0) 397 r->ifi_family = AF_UNSPEC;
565 stats->qual.updated &= ~IW_QUAL_ALL_UPDATED; 398 r->__ifi_pad = 0;
566 return 0; 399 r->ifi_type = dev->type;
567 } else 400 r->ifi_index = dev->ifindex;
568 return -EOPNOTSUPP; 401 r->ifi_flags = dev_get_flags(dev);
402 r->ifi_change = 0; /* Wireless changes don't affect those flags */
403
404 NLA_PUT_STRING(skb, IFLA_IFNAME, dev->name);
405
406 return nlh;
407 nla_put_failure:
408 nlmsg_cancel(skb, nlh);
409 return NULL;
569} 410}
570 411
571/* ---------------------------------------------------------------- */ 412
572/* 413/*
573 * Standard Wireless Handler : get iwpriv definitions 414 * Main event dispatcher. Called from other parts and drivers.
574 * Export the driver private handler definition 415 * Send the event on the appropriate channels.
575 * They will be picked up by tools like iwpriv... 416 * May be called from interrupt context.
576 */ 417 */
577static int iw_handler_get_private(struct net_device * dev, 418void wireless_send_event(struct net_device * dev,
578 struct iw_request_info * info, 419 unsigned int cmd,
579 union iwreq_data * wrqu, 420 union iwreq_data * wrqu,
580 char * extra) 421 const char * extra)
581{ 422{
582 /* Check if the driver has something to export */ 423 const struct iw_ioctl_description * descr = NULL;
583 if ((dev->wireless_handlers->num_private_args == 0) || 424 int extra_len = 0;
584 (dev->wireless_handlers->private_args == NULL)) 425 struct iw_event *event; /* Mallocated whole event */
585 return -EOPNOTSUPP; 426 int event_len; /* Its size */
427 int hdr_len; /* Size of the event header */
428 int wrqu_off = 0; /* Offset in wrqu */
429 /* Don't "optimise" the following variable, it will crash */
430 unsigned cmd_index; /* *MUST* be unsigned */
431 struct sk_buff *skb;
432 struct nlmsghdr *nlh;
433 struct nlattr *nla;
434#ifdef CONFIG_COMPAT
435 struct __compat_iw_event *compat_event;
436 struct compat_iw_point compat_wrqu;
437 struct sk_buff *compskb;
438#endif
586 439
587 /* Check if there is enough buffer up there */ 440 /*
588 if (wrqu->data.length < dev->wireless_handlers->num_private_args) { 441 * Nothing in the kernel sends scan events with data, be safe.
589 /* User space can't know in advance how large the buffer 442 * This is necessary because we cannot fix up scan event data
590 * needs to be. Give it a hint, so that we can support 443 * for compat, due to being contained in 'extra', but normally
591 * any size buffer we want somewhat efficiently... */ 444 * applications are required to retrieve the scan data anyway
592 wrqu->data.length = dev->wireless_handlers->num_private_args; 445 * and no data is included in the event, this codifies that
593 return -E2BIG; 446 * practice.
447 */
448 if (WARN_ON(cmd == SIOCGIWSCAN && extra))
449 extra = NULL;
450
451 /* Get the description of the Event */
452 if (cmd <= SIOCIWLAST) {
453 cmd_index = cmd - SIOCIWFIRST;
454 if (cmd_index < standard_ioctl_num)
455 descr = &(standard_ioctl[cmd_index]);
456 } else {
457 cmd_index = cmd - IWEVFIRST;
458 if (cmd_index < standard_event_num)
459 descr = &(standard_event[cmd_index]);
460 }
461 /* Don't accept unknown events */
462 if (descr == NULL) {
463 /* Note : we don't return an error to the driver, because
464 * the driver would not know what to do about it. It can't
465 * return an error to the user, because the event is not
466 * initiated by a user request.
467 * The best the driver could do is to log an error message.
468 * We will do it ourselves instead...
469 */
470 printk(KERN_ERR "%s (WE) : Invalid/Unknown Wireless Event (0x%04X)\n",
471 dev->name, cmd);
472 return;
594 } 473 }
595 474
596 /* Set the number of available ioctls. */ 475 /* Check extra parameters and set extra_len */
597 wrqu->data.length = dev->wireless_handlers->num_private_args; 476 if (descr->header_type == IW_HEADER_TYPE_POINT) {
477 /* Check if number of token fits within bounds */
478 if (wrqu->data.length > descr->max_tokens) {
479 printk(KERN_ERR "%s (WE) : Wireless Event too big (%d)\n", dev->name, wrqu->data.length);
480 return;
481 }
482 if (wrqu->data.length < descr->min_tokens) {
483 printk(KERN_ERR "%s (WE) : Wireless Event too small (%d)\n", dev->name, wrqu->data.length);
484 return;
485 }
486 /* Calculate extra_len - extra is NULL for restricted events */
487 if (extra != NULL)
488 extra_len = wrqu->data.length * descr->token_size;
489 /* Always at an offset in wrqu */
490 wrqu_off = IW_EV_POINT_OFF;
491 }
598 492
599 /* Copy structure to the user buffer. */ 493 /* Total length of the event */
600 memcpy(extra, dev->wireless_handlers->private_args, 494 hdr_len = event_type_size[descr->header_type];
601 sizeof(struct iw_priv_args) * wrqu->data.length); 495 event_len = hdr_len + extra_len;
602 496
603 return 0; 497 /*
604} 498 * The problem for 64/32 bit.
499 *
500 * On 64-bit, a regular event is laid out as follows:
501 * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
502 * | event.len | event.cmd | p a d d i n g |
503 * | wrqu data ... (with the correct size) |
504 *
505 * This padding exists because we manipulate event->u,
506 * and 'event' is not packed.
507 *
508 * An iw_point event is laid out like this instead:
509 * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
510 * | event.len | event.cmd | p a d d i n g |
511 * | iwpnt.len | iwpnt.flg | p a d d i n g |
512 * | extra data ...
513 *
514 * The second padding exists because struct iw_point is extended,
515 * but this depends on the platform...
516 *
517 * On 32-bit, all the padding shouldn't be there.
518 */
605 519
520 skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
521 if (!skb)
522 return;
606 523
607/******************** /proc/net/wireless SUPPORT ********************/ 524 /* Send via the RtNetlink event channel */
608/* 525 nlh = rtnetlink_ifinfo_prep(dev, skb);
609 * The /proc/net/wireless file is a human readable user-space interface 526 if (WARN_ON(!nlh)) {
610 * exporting various wireless specific statistics from the wireless devices. 527 kfree_skb(skb);
611 * This is the most popular part of the Wireless Extensions ;-) 528 return;
612 * 529 }
613 * This interface is a pure clone of /proc/net/dev (in net/core/dev.c).
614 * The content of the file is basically the content of "struct iw_statistics".
615 */
616 530
617#ifdef CONFIG_PROC_FS 531 /* Add the wireless events in the netlink packet */
532 nla = nla_reserve(skb, IFLA_WIRELESS, event_len);
533 if (!nla) {
534 kfree_skb(skb);
535 return;
536 }
537 event = nla_data(nla);
618 538
619/* ---------------------------------------------------------------- */ 539 /* Fill event - first clear to avoid data leaking */
620/* 540 memset(event, 0, hdr_len);
621 * Print one entry (line) of /proc/net/wireless 541 event->len = event_len;
622 */ 542 event->cmd = cmd;
623static void wireless_seq_printf_stats(struct seq_file *seq, 543 memcpy(&event->u, ((char *) wrqu) + wrqu_off, hdr_len - IW_EV_LCP_LEN);
624 struct net_device *dev) 544 if (extra_len)
625{ 545 memcpy(((char *) event) + hdr_len, extra, extra_len);
626 /* Get stats from the driver */
627 struct iw_statistics *stats = get_wireless_stats(dev);
628 static struct iw_statistics nullstats = {};
629 546
630 /* show device if it's wireless regardless of current stats */ 547 nlmsg_end(skb, nlh);
631 if (!stats && dev->wireless_handlers) 548#ifdef CONFIG_COMPAT
632 stats = &nullstats; 549 hdr_len = compat_event_type_size[descr->header_type];
550 event_len = hdr_len + extra_len;
633 551
634 if (stats) { 552 compskb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
635 seq_printf(seq, "%6s: %04x %3d%c %3d%c %3d%c %6d %6d %6d " 553 if (!compskb) {
636 "%6d %6d %6d\n", 554 kfree_skb(skb);
637 dev->name, stats->status, stats->qual.qual, 555 return;
638 stats->qual.updated & IW_QUAL_QUAL_UPDATED
639 ? '.' : ' ',
640 ((__s32) stats->qual.level) -
641 ((stats->qual.updated & IW_QUAL_DBM) ? 0x100 : 0),
642 stats->qual.updated & IW_QUAL_LEVEL_UPDATED
643 ? '.' : ' ',
644 ((__s32) stats->qual.noise) -
645 ((stats->qual.updated & IW_QUAL_DBM) ? 0x100 : 0),
646 stats->qual.updated & IW_QUAL_NOISE_UPDATED
647 ? '.' : ' ',
648 stats->discard.nwid, stats->discard.code,
649 stats->discard.fragment, stats->discard.retries,
650 stats->discard.misc, stats->miss.beacon);
651
652 if (stats != &nullstats)
653 stats->qual.updated &= ~IW_QUAL_ALL_UPDATED;
654 } 556 }
655}
656 557
657/* ---------------------------------------------------------------- */ 558 /* Send via the RtNetlink event channel */
658/* 559 nlh = rtnetlink_ifinfo_prep(dev, compskb);
659 * Print info for /proc/net/wireless (print all entries) 560 if (WARN_ON(!nlh)) {
660 */ 561 kfree_skb(skb);
661static int wireless_dev_seq_show(struct seq_file *seq, void *v) 562 kfree_skb(compskb);
662{ 563 return;
663 might_sleep(); 564 }
664 565
665 if (v == SEQ_START_TOKEN) 566 /* Add the wireless events in the netlink packet */
666 seq_printf(seq, "Inter-| sta-| Quality | Discarded " 567 nla = nla_reserve(compskb, IFLA_WIRELESS, event_len);
667 "packets | Missed | WE\n" 568 if (!nla) {
668 " face | tus | link level noise | nwid " 569 kfree_skb(skb);
669 "crypt frag retry misc | beacon | %d\n", 570 kfree_skb(compskb);
670 WIRELESS_EXT); 571 return;
671 else 572 }
672 wireless_seq_printf_stats(seq, v); 573 compat_event = nla_data(nla);
673 return 0; 574
575 compat_event->len = event_len;
576 compat_event->cmd = cmd;
577 if (descr->header_type == IW_HEADER_TYPE_POINT) {
578 compat_wrqu.length = wrqu->data.length;
579 compat_wrqu.flags = wrqu->data.flags;
580 memcpy(&compat_event->pointer,
581 ((char *) &compat_wrqu) + IW_EV_COMPAT_POINT_OFF,
582 hdr_len - IW_EV_COMPAT_LCP_LEN);
583 if (extra_len)
584 memcpy(((char *) compat_event) + hdr_len,
585 extra, extra_len);
586 } else {
587 /* extra_len must be zero, so no if (extra) needed */
588 memcpy(&compat_event->pointer, wrqu,
589 hdr_len - IW_EV_COMPAT_LCP_LEN);
590 }
591
592 nlmsg_end(compskb, nlh);
593
594 skb_shinfo(skb)->frag_list = compskb;
595#endif
596 skb_queue_tail(&dev_net(dev)->wext_nlevents, skb);
597 schedule_work(&wireless_nlevent_work);
674} 598}
599EXPORT_SYMBOL(wireless_send_event);
600
601
602
603/* IW handlers */
675 604
676static void *wireless_dev_seq_start(struct seq_file *seq, loff_t *pos) 605struct iw_statistics *get_wireless_stats(struct net_device *dev)
677{ 606{
678 struct net *net = seq_file_net(seq); 607#ifdef CONFIG_WIRELESS_EXT
679 loff_t off; 608 if ((dev->wireless_handlers != NULL) &&
680 struct net_device *dev; 609 (dev->wireless_handlers->get_wireless_stats != NULL))
610 return dev->wireless_handlers->get_wireless_stats(dev);
611#endif
681 612
682 rtnl_lock(); 613#ifdef CONFIG_CFG80211_WEXT
683 if (!*pos) 614 if (dev->ieee80211_ptr && dev->ieee80211_ptr &&
684 return SEQ_START_TOKEN; 615 dev->ieee80211_ptr->wiphy &&
616 dev->ieee80211_ptr->wiphy->wext &&
617 dev->ieee80211_ptr->wiphy->wext->get_wireless_stats)
618 return dev->ieee80211_ptr->wiphy->wext->get_wireless_stats(dev);
619#endif
685 620
686 off = 1; 621 /* not found */
687 for_each_netdev(net, dev)
688 if (off++ == *pos)
689 return dev;
690 return NULL; 622 return NULL;
691} 623}
692 624
693static void *wireless_dev_seq_next(struct seq_file *seq, void *v, loff_t *pos) 625static int iw_handler_get_iwstats(struct net_device * dev,
626 struct iw_request_info * info,
627 union iwreq_data * wrqu,
628 char * extra)
694{ 629{
695 struct net *net = seq_file_net(seq); 630 /* Get stats from the driver */
631 struct iw_statistics *stats;
696 632
697 ++*pos; 633 stats = get_wireless_stats(dev);
634 if (stats) {
635 /* Copy statistics to extra */
636 memcpy(extra, stats, sizeof(struct iw_statistics));
637 wrqu->data.length = sizeof(struct iw_statistics);
698 638
699 return v == SEQ_START_TOKEN ? 639 /* Check if we need to clear the updated flag */
700 first_net_device(net) : next_net_device(v); 640 if (wrqu->data.flags != 0)
641 stats->qual.updated &= ~IW_QUAL_ALL_UPDATED;
642 return 0;
643 } else
644 return -EOPNOTSUPP;
701} 645}
702 646
703static void wireless_dev_seq_stop(struct seq_file *seq, void *v) 647static iw_handler get_handler(struct net_device *dev, unsigned int cmd)
704{ 648{
705 rtnl_unlock(); 649 /* Don't "optimise" the following variable, it will crash */
706} 650 unsigned int index; /* *MUST* be unsigned */
707 651 const struct iw_handler_def *handlers = NULL;
708static const struct seq_operations wireless_seq_ops = {
709 .start = wireless_dev_seq_start,
710 .next = wireless_dev_seq_next,
711 .stop = wireless_dev_seq_stop,
712 .show = wireless_dev_seq_show,
713};
714 652
715static int seq_open_wireless(struct inode *inode, struct file *file) 653#ifdef CONFIG_CFG80211_WEXT
716{ 654 if (dev->ieee80211_ptr && dev->ieee80211_ptr->wiphy)
717 return seq_open_net(inode, file, &wireless_seq_ops, 655 handlers = dev->ieee80211_ptr->wiphy->wext;
718 sizeof(struct seq_net_private)); 656#endif
719} 657#ifdef CONFIG_WIRELESS_EXT
658 if (dev->wireless_handlers)
659 handlers = dev->wireless_handlers;
660#endif
720 661
721static const struct file_operations wireless_seq_fops = { 662 if (!handlers)
722 .owner = THIS_MODULE, 663 return NULL;
723 .open = seq_open_wireless,
724 .read = seq_read,
725 .llseek = seq_lseek,
726 .release = seq_release_net,
727};
728 664
729int wext_proc_init(struct net *net) 665 /* Try as a standard command */
730{ 666 index = cmd - SIOCIWFIRST;
731 /* Create /proc/net/wireless entry */ 667 if (index < handlers->num_standard)
732 if (!proc_net_fops_create(net, "wireless", S_IRUGO, &wireless_seq_fops)) 668 return handlers->standard[index];
733 return -ENOMEM;
734 669
735 return 0; 670#ifdef CONFIG_WEXT_PRIV
736} 671 /* Try as a private command */
672 index = cmd - SIOCIWFIRSTPRIV;
673 if (index < handlers->num_private)
674 return handlers->private[index];
675#endif
737 676
738void wext_proc_exit(struct net *net) 677 /* Not found */
739{ 678 return NULL;
740 proc_net_remove(net, "wireless");
741} 679}
742#endif /* CONFIG_PROC_FS */
743 680
744/************************** IOCTL SUPPORT **************************/
745/*
746 * The original user space API to configure all those Wireless Extensions
747 * is through IOCTLs.
748 * In there, we check if we need to call the new driver API (iw_handler)
749 * or just call the driver ioctl handler.
750 */
751
752/* ---------------------------------------------------------------- */
753static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd, 681static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
754 const struct iw_ioctl_description *descr, 682 const struct iw_ioctl_description *descr,
755 iw_handler handler, struct net_device *dev, 683 iw_handler handler, struct net_device *dev,
@@ -875,7 +803,8 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
875 } 803 }
876 804
877 /* Generate an event to notify listeners of the change */ 805 /* Generate an event to notify listeners of the change */
878 if ((descr->flags & IW_DESCR_FLAG_EVENT) && err == -EIWCOMMIT) { 806 if ((descr->flags & IW_DESCR_FLAG_EVENT) &&
807 ((err == 0) || (err == -EIWCOMMIT))) {
879 union iwreq_data *data = (union iwreq_data *) iwp; 808 union iwreq_data *data = (union iwreq_data *) iwp;
880 809
881 if (descr->flags & IW_DESCR_FLAG_RESTRICT) 810 if (descr->flags & IW_DESCR_FLAG_RESTRICT)
@@ -893,188 +822,39 @@ out:
893} 822}
894 823
895/* 824/*
896 * Wrapper to call a standard Wireless Extension handler. 825 * Call the commit handler in the driver
897 * We do various checks and also take care of moving data between 826 * (if exist and if conditions are right)
898 * user space and kernel space. 827 *
899 */ 828 * Note : our current commit strategy is currently pretty dumb,
900static int ioctl_standard_call(struct net_device * dev, 829 * but we will be able to improve on that...
901 struct iwreq *iwr, 830 * The goal is to try to agreagate as many changes as possible
902 unsigned int cmd, 831 * before doing the commit. Drivers that will define a commit handler
903 struct iw_request_info *info, 832 * are usually those that need a reset after changing parameters, so
904 iw_handler handler) 833 * we want to minimise the number of reset.
905{ 834 * A cool idea is to use a timer : at each "set" command, we re-set the
906 const struct iw_ioctl_description * descr; 835 * timer, when the timer eventually fires, we call the driver.
907 int ret = -EINVAL; 836 * Hopefully, more on that later.
908
909 /* Get the description of the IOCTL */
910 if ((cmd - SIOCIWFIRST) >= standard_ioctl_num)
911 return -EOPNOTSUPP;
912 descr = &(standard_ioctl[cmd - SIOCIWFIRST]);
913
914 /* Check if we have a pointer to user space data or not */
915 if (descr->header_type != IW_HEADER_TYPE_POINT) {
916
917 /* No extra arguments. Trivial to handle */
918 ret = handler(dev, info, &(iwr->u), NULL);
919
920 /* Generate an event to notify listeners of the change */
921 if ((descr->flags & IW_DESCR_FLAG_EVENT) &&
922 ((ret == 0) || (ret == -EIWCOMMIT)))
923 wireless_send_event(dev, cmd, &(iwr->u), NULL);
924 } else {
925 ret = ioctl_standard_iw_point(&iwr->u.data, cmd, descr,
926 handler, dev, info);
927 }
928
929 /* Call commit handler if needed and defined */
930 if (ret == -EIWCOMMIT)
931 ret = call_commit_handler(dev);
932
933 /* Here, we will generate the appropriate event if needed */
934
935 return ret;
936}
937
938/* ---------------------------------------------------------------- */
939/*
940 * Wrapper to call a private Wireless Extension handler.
941 * We do various checks and also take care of moving data between
942 * user space and kernel space.
943 * It's not as nice and slimline as the standard wrapper. The cause
944 * is struct iw_priv_args, which was not really designed for the
945 * job we are going here.
946 * 837 *
947 * IMPORTANT : This function prevent to set and get data on the same 838 * Also, I'm waiting to see how many people will complain about the
948 * IOCTL and enforce the SET/GET convention. Not doing it would be 839 * netif_running(dev) test. I'm open on that one...
949 * far too hairy... 840 * Hopefully, the driver will remember to do a commit in "open()" ;-)
950 * If you need to set and get data at the same time, please don't use
951 * a iw_handler but process it in your ioctl handler (i.e. use the
952 * old driver API).
953 */ 841 */
954static int get_priv_descr_and_size(struct net_device *dev, unsigned int cmd, 842int call_commit_handler(struct net_device *dev)
955 const struct iw_priv_args **descrp)
956{
957 const struct iw_priv_args *descr;
958 int i, extra_size;
959
960 descr = NULL;
961 for (i = 0; i < dev->wireless_handlers->num_private_args; i++) {
962 if (cmd == dev->wireless_handlers->private_args[i].cmd) {
963 descr = &dev->wireless_handlers->private_args[i];
964 break;
965 }
966 }
967
968 extra_size = 0;
969 if (descr) {
970 if (IW_IS_SET(cmd)) {
971 int offset = 0; /* For sub-ioctls */
972 /* Check for sub-ioctl handler */
973 if (descr->name[0] == '\0')
974 /* Reserve one int for sub-ioctl index */
975 offset = sizeof(__u32);
976
977 /* Size of set arguments */
978 extra_size = get_priv_size(descr->set_args);
979
980 /* Does it fits in iwr ? */
981 if ((descr->set_args & IW_PRIV_SIZE_FIXED) &&
982 ((extra_size + offset) <= IFNAMSIZ))
983 extra_size = 0;
984 } else {
985 /* Size of get arguments */
986 extra_size = get_priv_size(descr->get_args);
987
988 /* Does it fits in iwr ? */
989 if ((descr->get_args & IW_PRIV_SIZE_FIXED) &&
990 (extra_size <= IFNAMSIZ))
991 extra_size = 0;
992 }
993 }
994 *descrp = descr;
995 return extra_size;
996}
997
998static int ioctl_private_iw_point(struct iw_point *iwp, unsigned int cmd,
999 const struct iw_priv_args *descr,
1000 iw_handler handler, struct net_device *dev,
1001 struct iw_request_info *info, int extra_size)
1002{
1003 char *extra;
1004 int err;
1005
1006 /* Check what user space is giving us */
1007 if (IW_IS_SET(cmd)) {
1008 if (!iwp->pointer && iwp->length != 0)
1009 return -EFAULT;
1010
1011 if (iwp->length > (descr->set_args & IW_PRIV_SIZE_MASK))
1012 return -E2BIG;
1013 } else if (!iwp->pointer)
1014 return -EFAULT;
1015
1016 extra = kmalloc(extra_size, GFP_KERNEL);
1017 if (!extra)
1018 return -ENOMEM;
1019
1020 /* If it is a SET, get all the extra data in here */
1021 if (IW_IS_SET(cmd) && (iwp->length != 0)) {
1022 if (copy_from_user(extra, iwp->pointer, extra_size)) {
1023 err = -EFAULT;
1024 goto out;
1025 }
1026 }
1027
1028 /* Call the handler */
1029 err = handler(dev, info, (union iwreq_data *) iwp, extra);
1030
1031 /* If we have something to return to the user */
1032 if (!err && IW_IS_GET(cmd)) {
1033 /* Adjust for the actual length if it's variable,
1034 * avoid leaking kernel bits outside.
1035 */
1036 if (!(descr->get_args & IW_PRIV_SIZE_FIXED))
1037 extra_size = adjust_priv_size(descr->get_args, iwp);
1038
1039 if (copy_to_user(iwp->pointer, extra, extra_size))
1040 err = -EFAULT;
1041 }
1042
1043out:
1044 kfree(extra);
1045 return err;
1046}
1047
1048static int ioctl_private_call(struct net_device *dev, struct iwreq *iwr,
1049 unsigned int cmd, struct iw_request_info *info,
1050 iw_handler handler)
1051{ 843{
1052 int extra_size = 0, ret = -EINVAL; 844#ifdef CONFIG_WIRELESS_EXT
1053 const struct iw_priv_args *descr; 845 if ((netif_running(dev)) &&
1054 846 (dev->wireless_handlers->standard[0] != NULL))
1055 extra_size = get_priv_descr_and_size(dev, cmd, &descr); 847 /* Call the commit handler on the driver */
1056 848 return dev->wireless_handlers->standard[0](dev, NULL,
1057 /* Check if we have a pointer to user space data or not. */ 849 NULL, NULL);
1058 if (extra_size == 0) { 850 else
1059 /* No extra arguments. Trivial to handle */ 851 return 0; /* Command completed successfully */
1060 ret = handler(dev, info, &(iwr->u), (char *) &(iwr->u)); 852#else
1061 } else { 853 /* cfg80211 has no commit */
1062 ret = ioctl_private_iw_point(&iwr->u.data, cmd, descr, 854 return 0;
1063 handler, dev, info, extra_size); 855#endif
1064 }
1065
1066 /* Call commit handler if needed and defined */
1067 if (ret == -EIWCOMMIT)
1068 ret = call_commit_handler(dev);
1069
1070 return ret;
1071} 856}
1072 857
1073/* ---------------------------------------------------------------- */
1074typedef int (*wext_ioctl_func)(struct net_device *, struct iwreq *,
1075 unsigned int, struct iw_request_info *,
1076 iw_handler);
1077
1078/* 858/*
1079 * Main IOCTl dispatcher. 859 * Main IOCTl dispatcher.
1080 * Check the type of IOCTL and call the appropriate wrapper... 860 * Check the type of IOCTL and call the appropriate wrapper...
@@ -1103,9 +883,11 @@ static int wireless_process_ioctl(struct net *net, struct ifreq *ifr,
1103 return standard(dev, iwr, cmd, info, 883 return standard(dev, iwr, cmd, info,
1104 &iw_handler_get_iwstats); 884 &iw_handler_get_iwstats);
1105 885
886#ifdef CONFIG_WEXT_PRIV
1106 if (cmd == SIOCGIWPRIV && dev->wireless_handlers) 887 if (cmd == SIOCGIWPRIV && dev->wireless_handlers)
1107 return standard(dev, iwr, cmd, info, 888 return standard(dev, iwr, cmd, info,
1108 &iw_handler_get_private); 889 iw_handler_get_private);
890#endif
1109 891
1110 /* Basic check */ 892 /* Basic check */
1111 if (!netif_device_present(dev)) 893 if (!netif_device_present(dev))
@@ -1117,7 +899,7 @@ static int wireless_process_ioctl(struct net *net, struct ifreq *ifr,
1117 /* Standard and private are not the same */ 899 /* Standard and private are not the same */
1118 if (cmd < SIOCIWFIRSTPRIV) 900 if (cmd < SIOCIWFIRSTPRIV)
1119 return standard(dev, iwr, cmd, info, handler); 901 return standard(dev, iwr, cmd, info, handler);
1120 else 902 else if (private)
1121 return private(dev, iwr, cmd, info, handler); 903 return private(dev, iwr, cmd, info, handler);
1122 } 904 }
1123 /* Old driver API : call driver ioctl handler */ 905 /* Old driver API : call driver ioctl handler */
@@ -1131,8 +913,9 @@ static int wireless_process_ioctl(struct net *net, struct ifreq *ifr,
1131 */ 913 */
1132static int wext_permission_check(unsigned int cmd) 914static int wext_permission_check(unsigned int cmd)
1133{ 915{
1134 if ((IW_IS_SET(cmd) || cmd == SIOCGIWENCODE || cmd == SIOCGIWENCODEEXT) 916 if ((IW_IS_SET(cmd) || cmd == SIOCGIWENCODE ||
1135 && !capable(CAP_NET_ADMIN)) 917 cmd == SIOCGIWENCODEEXT) &&
918 !capable(CAP_NET_ADMIN))
1136 return -EPERM; 919 return -EPERM;
1137 920
1138 return 0; 921 return 0;
@@ -1157,6 +940,50 @@ static int wext_ioctl_dispatch(struct net *net, struct ifreq *ifr,
1157 return ret; 940 return ret;
1158} 941}
1159 942
943/*
944 * Wrapper to call a standard Wireless Extension handler.
945 * We do various checks and also take care of moving data between
946 * user space and kernel space.
947 */
948static int ioctl_standard_call(struct net_device * dev,
949 struct iwreq *iwr,
950 unsigned int cmd,
951 struct iw_request_info *info,
952 iw_handler handler)
953{
954 const struct iw_ioctl_description * descr;
955 int ret = -EINVAL;
956
957 /* Get the description of the IOCTL */
958 if ((cmd - SIOCIWFIRST) >= standard_ioctl_num)
959 return -EOPNOTSUPP;
960 descr = &(standard_ioctl[cmd - SIOCIWFIRST]);
961
962 /* Check if we have a pointer to user space data or not */
963 if (descr->header_type != IW_HEADER_TYPE_POINT) {
964
965 /* No extra arguments. Trivial to handle */
966 ret = handler(dev, info, &(iwr->u), NULL);
967
968 /* Generate an event to notify listeners of the change */
969 if ((descr->flags & IW_DESCR_FLAG_EVENT) &&
970 ((ret == 0) || (ret == -EIWCOMMIT)))
971 wireless_send_event(dev, cmd, &(iwr->u), NULL);
972 } else {
973 ret = ioctl_standard_iw_point(&iwr->u.data, cmd, descr,
974 handler, dev, info);
975 }
976
977 /* Call commit handler if needed and defined */
978 if (ret == -EIWCOMMIT)
979 ret = call_commit_handler(dev);
980
981 /* Here, we will generate the appropriate event if needed */
982
983 return ret;
984}
985
986
1160int wext_handle_ioctl(struct net *net, struct ifreq *ifr, unsigned int cmd, 987int wext_handle_ioctl(struct net *net, struct ifreq *ifr, unsigned int cmd,
1161 void __user *arg) 988 void __user *arg)
1162{ 989{
@@ -1205,43 +1032,6 @@ static int compat_standard_call(struct net_device *dev,
1205 return err; 1032 return err;
1206} 1033}
1207 1034
1208static int compat_private_call(struct net_device *dev, struct iwreq *iwr,
1209 unsigned int cmd, struct iw_request_info *info,
1210 iw_handler handler)
1211{
1212 const struct iw_priv_args *descr;
1213 int ret, extra_size;
1214
1215 extra_size = get_priv_descr_and_size(dev, cmd, &descr);
1216
1217 /* Check if we have a pointer to user space data or not. */
1218 if (extra_size == 0) {
1219 /* No extra arguments. Trivial to handle */
1220 ret = handler(dev, info, &(iwr->u), (char *) &(iwr->u));
1221 } else {
1222 struct compat_iw_point *iwp_compat;
1223 struct iw_point iwp;
1224
1225 iwp_compat = (struct compat_iw_point *) &iwr->u.data;
1226 iwp.pointer = compat_ptr(iwp_compat->pointer);
1227 iwp.length = iwp_compat->length;
1228 iwp.flags = iwp_compat->flags;
1229
1230 ret = ioctl_private_iw_point(&iwp, cmd, descr,
1231 handler, dev, info, extra_size);
1232
1233 iwp_compat->pointer = ptr_to_compat(iwp.pointer);
1234 iwp_compat->length = iwp.length;
1235 iwp_compat->flags = iwp.flags;
1236 }
1237
1238 /* Call commit handler if needed and defined */
1239 if (ret == -EIWCOMMIT)
1240 ret = call_commit_handler(dev);
1241
1242 return ret;
1243}
1244
1245int compat_wext_handle_ioctl(struct net *net, unsigned int cmd, 1035int compat_wext_handle_ioctl(struct net *net, unsigned int cmd,
1246 unsigned long arg) 1036 unsigned long arg)
1247{ 1037{
@@ -1274,502 +1064,3 @@ int compat_wext_handle_ioctl(struct net *net, unsigned int cmd,
1274 return ret; 1064 return ret;
1275} 1065}
1276#endif 1066#endif
1277
1278static int __net_init wext_pernet_init(struct net *net)
1279{
1280 skb_queue_head_init(&net->wext_nlevents);
1281 return 0;
1282}
1283
1284static void __net_exit wext_pernet_exit(struct net *net)
1285{
1286 skb_queue_purge(&net->wext_nlevents);
1287}
1288
1289static struct pernet_operations wext_pernet_ops = {
1290 .init = wext_pernet_init,
1291 .exit = wext_pernet_exit,
1292};
1293
1294static int __init wireless_nlevent_init(void)
1295{
1296 return register_pernet_subsys(&wext_pernet_ops);
1297}
1298
1299subsys_initcall(wireless_nlevent_init);
1300
1301/* Process events generated by the wireless layer or the driver. */
1302static void wireless_nlevent_process(struct work_struct *work)
1303{
1304 struct sk_buff *skb;
1305 struct net *net;
1306
1307 rtnl_lock();
1308
1309 for_each_net(net) {
1310 while ((skb = skb_dequeue(&net->wext_nlevents)))
1311 rtnl_notify(skb, net, 0, RTNLGRP_LINK, NULL,
1312 GFP_KERNEL);
1313 }
1314
1315 rtnl_unlock();
1316}
1317
1318static DECLARE_WORK(wireless_nlevent_work, wireless_nlevent_process);
1319
1320static struct nlmsghdr *rtnetlink_ifinfo_prep(struct net_device *dev,
1321 struct sk_buff *skb)
1322{
1323 struct ifinfomsg *r;
1324 struct nlmsghdr *nlh;
1325
1326 nlh = nlmsg_put(skb, 0, 0, RTM_NEWLINK, sizeof(*r), 0);
1327 if (!nlh)
1328 return NULL;
1329
1330 r = nlmsg_data(nlh);
1331 r->ifi_family = AF_UNSPEC;
1332 r->__ifi_pad = 0;
1333 r->ifi_type = dev->type;
1334 r->ifi_index = dev->ifindex;
1335 r->ifi_flags = dev_get_flags(dev);
1336 r->ifi_change = 0; /* Wireless changes don't affect those flags */
1337
1338 NLA_PUT_STRING(skb, IFLA_IFNAME, dev->name);
1339
1340 return nlh;
1341 nla_put_failure:
1342 nlmsg_cancel(skb, nlh);
1343 return NULL;
1344}
1345
1346
1347/*
1348 * Main event dispatcher. Called from other parts and drivers.
1349 * Send the event on the appropriate channels.
1350 * May be called from interrupt context.
1351 */
1352void wireless_send_event(struct net_device * dev,
1353 unsigned int cmd,
1354 union iwreq_data * wrqu,
1355 const char * extra)
1356{
1357 const struct iw_ioctl_description * descr = NULL;
1358 int extra_len = 0;
1359 struct iw_event *event; /* Mallocated whole event */
1360 int event_len; /* Its size */
1361 int hdr_len; /* Size of the event header */
1362 int wrqu_off = 0; /* Offset in wrqu */
1363 /* Don't "optimise" the following variable, it will crash */
1364 unsigned cmd_index; /* *MUST* be unsigned */
1365 struct sk_buff *skb;
1366 struct nlmsghdr *nlh;
1367 struct nlattr *nla;
1368#ifdef CONFIG_COMPAT
1369 struct __compat_iw_event *compat_event;
1370 struct compat_iw_point compat_wrqu;
1371 struct sk_buff *compskb;
1372#endif
1373
1374 /*
1375 * Nothing in the kernel sends scan events with data, be safe.
1376 * This is necessary because we cannot fix up scan event data
1377 * for compat, due to being contained in 'extra', but normally
1378 * applications are required to retrieve the scan data anyway
1379 * and no data is included in the event, this codifies that
1380 * practice.
1381 */
1382 if (WARN_ON(cmd == SIOCGIWSCAN && extra))
1383 extra = NULL;
1384
1385 /* Get the description of the Event */
1386 if (cmd <= SIOCIWLAST) {
1387 cmd_index = cmd - SIOCIWFIRST;
1388 if (cmd_index < standard_ioctl_num)
1389 descr = &(standard_ioctl[cmd_index]);
1390 } else {
1391 cmd_index = cmd - IWEVFIRST;
1392 if (cmd_index < standard_event_num)
1393 descr = &(standard_event[cmd_index]);
1394 }
1395 /* Don't accept unknown events */
1396 if (descr == NULL) {
1397 /* Note : we don't return an error to the driver, because
1398 * the driver would not know what to do about it. It can't
1399 * return an error to the user, because the event is not
1400 * initiated by a user request.
1401 * The best the driver could do is to log an error message.
1402 * We will do it ourselves instead...
1403 */
1404 printk(KERN_ERR "%s (WE) : Invalid/Unknown Wireless Event (0x%04X)\n",
1405 dev->name, cmd);
1406 return;
1407 }
1408
1409 /* Check extra parameters and set extra_len */
1410 if (descr->header_type == IW_HEADER_TYPE_POINT) {
1411 /* Check if number of token fits within bounds */
1412 if (wrqu->data.length > descr->max_tokens) {
1413 printk(KERN_ERR "%s (WE) : Wireless Event too big (%d)\n", dev->name, wrqu->data.length);
1414 return;
1415 }
1416 if (wrqu->data.length < descr->min_tokens) {
1417 printk(KERN_ERR "%s (WE) : Wireless Event too small (%d)\n", dev->name, wrqu->data.length);
1418 return;
1419 }
1420 /* Calculate extra_len - extra is NULL for restricted events */
1421 if (extra != NULL)
1422 extra_len = wrqu->data.length * descr->token_size;
1423 /* Always at an offset in wrqu */
1424 wrqu_off = IW_EV_POINT_OFF;
1425 }
1426
1427 /* Total length of the event */
1428 hdr_len = event_type_size[descr->header_type];
1429 event_len = hdr_len + extra_len;
1430
1431 /*
1432 * The problem for 64/32 bit.
1433 *
1434 * On 64-bit, a regular event is laid out as follows:
1435 * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
1436 * | event.len | event.cmd | p a d d i n g |
1437 * | wrqu data ... (with the correct size) |
1438 *
1439 * This padding exists because we manipulate event->u,
1440 * and 'event' is not packed.
1441 *
1442 * An iw_point event is laid out like this instead:
1443 * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
1444 * | event.len | event.cmd | p a d d i n g |
1445 * | iwpnt.len | iwpnt.flg | p a d d i n g |
1446 * | extra data ...
1447 *
1448 * The second padding exists because struct iw_point is extended,
1449 * but this depends on the platform...
1450 *
1451 * On 32-bit, all the padding shouldn't be there.
1452 */
1453
1454 skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
1455 if (!skb)
1456 return;
1457
1458 /* Send via the RtNetlink event channel */
1459 nlh = rtnetlink_ifinfo_prep(dev, skb);
1460 if (WARN_ON(!nlh)) {
1461 kfree_skb(skb);
1462 return;
1463 }
1464
1465 /* Add the wireless events in the netlink packet */
1466 nla = nla_reserve(skb, IFLA_WIRELESS, event_len);
1467 if (!nla) {
1468 kfree_skb(skb);
1469 return;
1470 }
1471 event = nla_data(nla);
1472
1473 /* Fill event - first clear to avoid data leaking */
1474 memset(event, 0, hdr_len);
1475 event->len = event_len;
1476 event->cmd = cmd;
1477 memcpy(&event->u, ((char *) wrqu) + wrqu_off, hdr_len - IW_EV_LCP_LEN);
1478 if (extra_len)
1479 memcpy(((char *) event) + hdr_len, extra, extra_len);
1480
1481 nlmsg_end(skb, nlh);
1482#ifdef CONFIG_COMPAT
1483 hdr_len = compat_event_type_size[descr->header_type];
1484 event_len = hdr_len + extra_len;
1485
1486 compskb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
1487 if (!compskb) {
1488 kfree_skb(skb);
1489 return;
1490 }
1491
1492 /* Send via the RtNetlink event channel */
1493 nlh = rtnetlink_ifinfo_prep(dev, compskb);
1494 if (WARN_ON(!nlh)) {
1495 kfree_skb(skb);
1496 kfree_skb(compskb);
1497 return;
1498 }
1499
1500 /* Add the wireless events in the netlink packet */
1501 nla = nla_reserve(compskb, IFLA_WIRELESS, event_len);
1502 if (!nla) {
1503 kfree_skb(skb);
1504 kfree_skb(compskb);
1505 return;
1506 }
1507 compat_event = nla_data(nla);
1508
1509 compat_event->len = event_len;
1510 compat_event->cmd = cmd;
1511 if (descr->header_type == IW_HEADER_TYPE_POINT) {
1512 compat_wrqu.length = wrqu->data.length;
1513 compat_wrqu.flags = wrqu->data.flags;
1514 memcpy(&compat_event->pointer,
1515 ((char *) &compat_wrqu) + IW_EV_COMPAT_POINT_OFF,
1516 hdr_len - IW_EV_COMPAT_LCP_LEN);
1517 if (extra_len)
1518 memcpy(((char *) compat_event) + hdr_len,
1519 extra, extra_len);
1520 } else {
1521 /* extra_len must be zero, so no if (extra) needed */
1522 memcpy(&compat_event->pointer, wrqu,
1523 hdr_len - IW_EV_COMPAT_LCP_LEN);
1524 }
1525
1526 nlmsg_end(compskb, nlh);
1527
1528 skb_shinfo(skb)->frag_list = compskb;
1529#endif
1530 skb_queue_tail(&dev_net(dev)->wext_nlevents, skb);
1531 schedule_work(&wireless_nlevent_work);
1532}
1533EXPORT_SYMBOL(wireless_send_event);
1534
1535/********************** ENHANCED IWSPY SUPPORT **********************/
1536/*
1537 * In the old days, the driver was handling spy support all by itself.
1538 * Now, the driver can delegate this task to Wireless Extensions.
1539 * It needs to use those standard spy iw_handler in struct iw_handler_def,
1540 * push data to us via wireless_spy_update() and include struct iw_spy_data
1541 * in its private part (and export it in net_device->wireless_data->spy_data).
1542 * One of the main advantage of centralising spy support here is that
1543 * it becomes much easier to improve and extend it without having to touch
1544 * the drivers. One example is the addition of the Spy-Threshold events.
1545 */
1546
1547/* ---------------------------------------------------------------- */
1548/*
1549 * Return the pointer to the spy data in the driver.
1550 * Because this is called on the Rx path via wireless_spy_update(),
1551 * we want it to be efficient...
1552 */
1553static inline struct iw_spy_data *get_spydata(struct net_device *dev)
1554{
1555 /* This is the new way */
1556 if (dev->wireless_data)
1557 return dev->wireless_data->spy_data;
1558 return NULL;
1559}
1560
1561/*------------------------------------------------------------------*/
1562/*
1563 * Standard Wireless Handler : set Spy List
1564 */
1565int iw_handler_set_spy(struct net_device * dev,
1566 struct iw_request_info * info,
1567 union iwreq_data * wrqu,
1568 char * extra)
1569{
1570 struct iw_spy_data * spydata = get_spydata(dev);
1571 struct sockaddr * address = (struct sockaddr *) extra;
1572
1573 /* Make sure driver is not buggy or using the old API */
1574 if (!spydata)
1575 return -EOPNOTSUPP;
1576
1577 /* Disable spy collection while we copy the addresses.
1578 * While we copy addresses, any call to wireless_spy_update()
1579 * will NOP. This is OK, as anyway the addresses are changing. */
1580 spydata->spy_number = 0;
1581
1582 /* We want to operate without locking, because wireless_spy_update()
1583 * most likely will happen in the interrupt handler, and therefore
1584 * have its own locking constraints and needs performance.
1585 * The rtnl_lock() make sure we don't race with the other iw_handlers.
1586 * This make sure wireless_spy_update() "see" that the spy list
1587 * is temporarily disabled. */
1588 smp_wmb();
1589
1590 /* Are there are addresses to copy? */
1591 if (wrqu->data.length > 0) {
1592 int i;
1593
1594 /* Copy addresses */
1595 for (i = 0; i < wrqu->data.length; i++)
1596 memcpy(spydata->spy_address[i], address[i].sa_data,
1597 ETH_ALEN);
1598 /* Reset stats */
1599 memset(spydata->spy_stat, 0,
1600 sizeof(struct iw_quality) * IW_MAX_SPY);
1601 }
1602
1603 /* Make sure above is updated before re-enabling */
1604 smp_wmb();
1605
1606 /* Enable addresses */
1607 spydata->spy_number = wrqu->data.length;
1608
1609 return 0;
1610}
1611EXPORT_SYMBOL(iw_handler_set_spy);
1612
1613/*------------------------------------------------------------------*/
1614/*
1615 * Standard Wireless Handler : get Spy List
1616 */
1617int iw_handler_get_spy(struct net_device * dev,
1618 struct iw_request_info * info,
1619 union iwreq_data * wrqu,
1620 char * extra)
1621{
1622 struct iw_spy_data * spydata = get_spydata(dev);
1623 struct sockaddr * address = (struct sockaddr *) extra;
1624 int i;
1625
1626 /* Make sure driver is not buggy or using the old API */
1627 if (!spydata)
1628 return -EOPNOTSUPP;
1629
1630 wrqu->data.length = spydata->spy_number;
1631
1632 /* Copy addresses. */
1633 for (i = 0; i < spydata->spy_number; i++) {
1634 memcpy(address[i].sa_data, spydata->spy_address[i], ETH_ALEN);
1635 address[i].sa_family = AF_UNIX;
1636 }
1637 /* Copy stats to the user buffer (just after). */
1638 if (spydata->spy_number > 0)
1639 memcpy(extra + (sizeof(struct sockaddr) *spydata->spy_number),
1640 spydata->spy_stat,
1641 sizeof(struct iw_quality) * spydata->spy_number);
1642 /* Reset updated flags. */
1643 for (i = 0; i < spydata->spy_number; i++)
1644 spydata->spy_stat[i].updated &= ~IW_QUAL_ALL_UPDATED;
1645 return 0;
1646}
1647EXPORT_SYMBOL(iw_handler_get_spy);
1648
1649/*------------------------------------------------------------------*/
1650/*
1651 * Standard Wireless Handler : set spy threshold
1652 */
1653int iw_handler_set_thrspy(struct net_device * dev,
1654 struct iw_request_info *info,
1655 union iwreq_data * wrqu,
1656 char * extra)
1657{
1658 struct iw_spy_data * spydata = get_spydata(dev);
1659 struct iw_thrspy * threshold = (struct iw_thrspy *) extra;
1660
1661 /* Make sure driver is not buggy or using the old API */
1662 if (!spydata)
1663 return -EOPNOTSUPP;
1664
1665 /* Just do it */
1666 memcpy(&(spydata->spy_thr_low), &(threshold->low),
1667 2 * sizeof(struct iw_quality));
1668
1669 /* Clear flag */
1670 memset(spydata->spy_thr_under, '\0', sizeof(spydata->spy_thr_under));
1671
1672 return 0;
1673}
1674EXPORT_SYMBOL(iw_handler_set_thrspy);
1675
1676/*------------------------------------------------------------------*/
1677/*
1678 * Standard Wireless Handler : get spy threshold
1679 */
1680int iw_handler_get_thrspy(struct net_device * dev,
1681 struct iw_request_info *info,
1682 union iwreq_data * wrqu,
1683 char * extra)
1684{
1685 struct iw_spy_data * spydata = get_spydata(dev);
1686 struct iw_thrspy * threshold = (struct iw_thrspy *) extra;
1687
1688 /* Make sure driver is not buggy or using the old API */
1689 if (!spydata)
1690 return -EOPNOTSUPP;
1691
1692 /* Just do it */
1693 memcpy(&(threshold->low), &(spydata->spy_thr_low),
1694 2 * sizeof(struct iw_quality));
1695
1696 return 0;
1697}
1698EXPORT_SYMBOL(iw_handler_get_thrspy);
1699
1700/*------------------------------------------------------------------*/
1701/*
1702 * Prepare and send a Spy Threshold event
1703 */
1704static void iw_send_thrspy_event(struct net_device * dev,
1705 struct iw_spy_data * spydata,
1706 unsigned char * address,
1707 struct iw_quality * wstats)
1708{
1709 union iwreq_data wrqu;
1710 struct iw_thrspy threshold;
1711
1712 /* Init */
1713 wrqu.data.length = 1;
1714 wrqu.data.flags = 0;
1715 /* Copy address */
1716 memcpy(threshold.addr.sa_data, address, ETH_ALEN);
1717 threshold.addr.sa_family = ARPHRD_ETHER;
1718 /* Copy stats */
1719 memcpy(&(threshold.qual), wstats, sizeof(struct iw_quality));
1720 /* Copy also thresholds */
1721 memcpy(&(threshold.low), &(spydata->spy_thr_low),
1722 2 * sizeof(struct iw_quality));
1723
1724 /* Send event to user space */
1725 wireless_send_event(dev, SIOCGIWTHRSPY, &wrqu, (char *) &threshold);
1726}
1727
1728/* ---------------------------------------------------------------- */
1729/*
1730 * Call for the driver to update the spy data.
1731 * For now, the spy data is a simple array. As the size of the array is
1732 * small, this is good enough. If we wanted to support larger number of
1733 * spy addresses, we should use something more efficient...
1734 */
1735void wireless_spy_update(struct net_device * dev,
1736 unsigned char * address,
1737 struct iw_quality * wstats)
1738{
1739 struct iw_spy_data * spydata = get_spydata(dev);
1740 int i;
1741 int match = -1;
1742
1743 /* Make sure driver is not buggy or using the old API */
1744 if (!spydata)
1745 return;
1746
1747 /* Update all records that match */
1748 for (i = 0; i < spydata->spy_number; i++)
1749 if (!compare_ether_addr(address, spydata->spy_address[i])) {
1750 memcpy(&(spydata->spy_stat[i]), wstats,
1751 sizeof(struct iw_quality));
1752 match = i;
1753 }
1754
1755 /* Generate an event if we cross the spy threshold.
1756 * To avoid event storms, we have a simple hysteresis : we generate
1757 * event only when we go under the low threshold or above the
1758 * high threshold. */
1759 if (match >= 0) {
1760 if (spydata->spy_thr_under[match]) {
1761 if (wstats->level > spydata->spy_thr_high.level) {
1762 spydata->spy_thr_under[match] = 0;
1763 iw_send_thrspy_event(dev, spydata,
1764 address, wstats);
1765 }
1766 } else {
1767 if (wstats->level < spydata->spy_thr_low.level) {
1768 spydata->spy_thr_under[match] = 1;
1769 iw_send_thrspy_event(dev, spydata,
1770 address, wstats);
1771 }
1772 }
1773 }
1774}
1775EXPORT_SYMBOL(wireless_spy_update);
diff --git a/net/wireless/wext-priv.c b/net/wireless/wext-priv.c
new file mode 100644
index 000000000000..3feb28e41c53
--- /dev/null
+++ b/net/wireless/wext-priv.c
@@ -0,0 +1,249 @@
1/*
2 * This file implement the Wireless Extensions priv API.
3 *
4 * Authors : Jean Tourrilhes - HPL - <jt@hpl.hp.com>
5 * Copyright (c) 1997-2007 Jean Tourrilhes, All Rights Reserved.
6 * Copyright 2009 Johannes Berg <johannes@sipsolutions.net>
7 *
8 * (As all part of the Linux kernel, this file is GPL)
9 */
10#include <linux/slab.h>
11#include <linux/wireless.h>
12#include <linux/netdevice.h>
13#include <net/iw_handler.h>
14#include <net/wext.h>
15
16int iw_handler_get_private(struct net_device * dev,
17 struct iw_request_info * info,
18 union iwreq_data * wrqu,
19 char * extra)
20{
21 /* Check if the driver has something to export */
22 if ((dev->wireless_handlers->num_private_args == 0) ||
23 (dev->wireless_handlers->private_args == NULL))
24 return -EOPNOTSUPP;
25
26 /* Check if there is enough buffer up there */
27 if (wrqu->data.length < dev->wireless_handlers->num_private_args) {
28 /* User space can't know in advance how large the buffer
29 * needs to be. Give it a hint, so that we can support
30 * any size buffer we want somewhat efficiently... */
31 wrqu->data.length = dev->wireless_handlers->num_private_args;
32 return -E2BIG;
33 }
34
35 /* Set the number of available ioctls. */
36 wrqu->data.length = dev->wireless_handlers->num_private_args;
37
38 /* Copy structure to the user buffer. */
39 memcpy(extra, dev->wireless_handlers->private_args,
40 sizeof(struct iw_priv_args) * wrqu->data.length);
41
42 return 0;
43}
44
45/* Size (in bytes) of the various private data types */
46static const char iw_priv_type_size[] = {
47 0, /* IW_PRIV_TYPE_NONE */
48 1, /* IW_PRIV_TYPE_BYTE */
49 1, /* IW_PRIV_TYPE_CHAR */
50 0, /* Not defined */
51 sizeof(__u32), /* IW_PRIV_TYPE_INT */
52 sizeof(struct iw_freq), /* IW_PRIV_TYPE_FLOAT */
53 sizeof(struct sockaddr), /* IW_PRIV_TYPE_ADDR */
54 0, /* Not defined */
55};
56
57static int get_priv_size(__u16 args)
58{
59 int num = args & IW_PRIV_SIZE_MASK;
60 int type = (args & IW_PRIV_TYPE_MASK) >> 12;
61
62 return num * iw_priv_type_size[type];
63}
64
65static int adjust_priv_size(__u16 args, struct iw_point *iwp)
66{
67 int num = iwp->length;
68 int max = args & IW_PRIV_SIZE_MASK;
69 int type = (args & IW_PRIV_TYPE_MASK) >> 12;
70
71 /* Make sure the driver doesn't goof up */
72 if (max < num)
73 num = max;
74
75 return num * iw_priv_type_size[type];
76}
77
78/*
79 * Wrapper to call a private Wireless Extension handler.
80 * We do various checks and also take care of moving data between
81 * user space and kernel space.
82 * It's not as nice and slimline as the standard wrapper. The cause
83 * is struct iw_priv_args, which was not really designed for the
84 * job we are going here.
85 *
86 * IMPORTANT : This function prevent to set and get data on the same
87 * IOCTL and enforce the SET/GET convention. Not doing it would be
88 * far too hairy...
89 * If you need to set and get data at the same time, please don't use
90 * a iw_handler but process it in your ioctl handler (i.e. use the
91 * old driver API).
92 */
93static int get_priv_descr_and_size(struct net_device *dev, unsigned int cmd,
94 const struct iw_priv_args **descrp)
95{
96 const struct iw_priv_args *descr;
97 int i, extra_size;
98
99 descr = NULL;
100 for (i = 0; i < dev->wireless_handlers->num_private_args; i++) {
101 if (cmd == dev->wireless_handlers->private_args[i].cmd) {
102 descr = &dev->wireless_handlers->private_args[i];
103 break;
104 }
105 }
106
107 extra_size = 0;
108 if (descr) {
109 if (IW_IS_SET(cmd)) {
110 int offset = 0; /* For sub-ioctls */
111 /* Check for sub-ioctl handler */
112 if (descr->name[0] == '\0')
113 /* Reserve one int for sub-ioctl index */
114 offset = sizeof(__u32);
115
116 /* Size of set arguments */
117 extra_size = get_priv_size(descr->set_args);
118
119 /* Does it fits in iwr ? */
120 if ((descr->set_args & IW_PRIV_SIZE_FIXED) &&
121 ((extra_size + offset) <= IFNAMSIZ))
122 extra_size = 0;
123 } else {
124 /* Size of get arguments */
125 extra_size = get_priv_size(descr->get_args);
126
127 /* Does it fits in iwr ? */
128 if ((descr->get_args & IW_PRIV_SIZE_FIXED) &&
129 (extra_size <= IFNAMSIZ))
130 extra_size = 0;
131 }
132 }
133 *descrp = descr;
134 return extra_size;
135}
136
137static int ioctl_private_iw_point(struct iw_point *iwp, unsigned int cmd,
138 const struct iw_priv_args *descr,
139 iw_handler handler, struct net_device *dev,
140 struct iw_request_info *info, int extra_size)
141{
142 char *extra;
143 int err;
144
145 /* Check what user space is giving us */
146 if (IW_IS_SET(cmd)) {
147 if (!iwp->pointer && iwp->length != 0)
148 return -EFAULT;
149
150 if (iwp->length > (descr->set_args & IW_PRIV_SIZE_MASK))
151 return -E2BIG;
152 } else if (!iwp->pointer)
153 return -EFAULT;
154
155 extra = kmalloc(extra_size, GFP_KERNEL);
156 if (!extra)
157 return -ENOMEM;
158
159 /* If it is a SET, get all the extra data in here */
160 if (IW_IS_SET(cmd) && (iwp->length != 0)) {
161 if (copy_from_user(extra, iwp->pointer, extra_size)) {
162 err = -EFAULT;
163 goto out;
164 }
165 }
166
167 /* Call the handler */
168 err = handler(dev, info, (union iwreq_data *) iwp, extra);
169
170 /* If we have something to return to the user */
171 if (!err && IW_IS_GET(cmd)) {
172 /* Adjust for the actual length if it's variable,
173 * avoid leaking kernel bits outside.
174 */
175 if (!(descr->get_args & IW_PRIV_SIZE_FIXED))
176 extra_size = adjust_priv_size(descr->get_args, iwp);
177
178 if (copy_to_user(iwp->pointer, extra, extra_size))
179 err = -EFAULT;
180 }
181
182out:
183 kfree(extra);
184 return err;
185}
186
187int ioctl_private_call(struct net_device *dev, struct iwreq *iwr,
188 unsigned int cmd, struct iw_request_info *info,
189 iw_handler handler)
190{
191 int extra_size = 0, ret = -EINVAL;
192 const struct iw_priv_args *descr;
193
194 extra_size = get_priv_descr_and_size(dev, cmd, &descr);
195
196 /* Check if we have a pointer to user space data or not. */
197 if (extra_size == 0) {
198 /* No extra arguments. Trivial to handle */
199 ret = handler(dev, info, &(iwr->u), (char *) &(iwr->u));
200 } else {
201 ret = ioctl_private_iw_point(&iwr->u.data, cmd, descr,
202 handler, dev, info, extra_size);
203 }
204
205 /* Call commit handler if needed and defined */
206 if (ret == -EIWCOMMIT)
207 ret = call_commit_handler(dev);
208
209 return ret;
210}
211
212#ifdef CONFIG_COMPAT
213int compat_private_call(struct net_device *dev, struct iwreq *iwr,
214 unsigned int cmd, struct iw_request_info *info,
215 iw_handler handler)
216{
217 const struct iw_priv_args *descr;
218 int ret, extra_size;
219
220 extra_size = get_priv_descr_and_size(dev, cmd, &descr);
221
222 /* Check if we have a pointer to user space data or not. */
223 if (extra_size == 0) {
224 /* No extra arguments. Trivial to handle */
225 ret = handler(dev, info, &(iwr->u), (char *) &(iwr->u));
226 } else {
227 struct compat_iw_point *iwp_compat;
228 struct iw_point iwp;
229
230 iwp_compat = (struct compat_iw_point *) &iwr->u.data;
231 iwp.pointer = compat_ptr(iwp_compat->pointer);
232 iwp.length = iwp_compat->length;
233 iwp.flags = iwp_compat->flags;
234
235 ret = ioctl_private_iw_point(&iwp, cmd, descr,
236 handler, dev, info, extra_size);
237
238 iwp_compat->pointer = ptr_to_compat(iwp.pointer);
239 iwp_compat->length = iwp.length;
240 iwp_compat->flags = iwp.flags;
241 }
242
243 /* Call commit handler if needed and defined */
244 if (ret == -EIWCOMMIT)
245 ret = call_commit_handler(dev);
246
247 return ret;
248}
249#endif
diff --git a/net/wireless/wext-proc.c b/net/wireless/wext-proc.c
new file mode 100644
index 000000000000..8bafa31fa9f8
--- /dev/null
+++ b/net/wireless/wext-proc.c
@@ -0,0 +1,155 @@
1/*
2 * This file implement the Wireless Extensions proc API.
3 *
4 * Authors : Jean Tourrilhes - HPL - <jt@hpl.hp.com>
5 * Copyright (c) 1997-2007 Jean Tourrilhes, All Rights Reserved.
6 *
7 * (As all part of the Linux kernel, this file is GPL)
8 */
9
10/*
11 * The /proc/net/wireless file is a human readable user-space interface
12 * exporting various wireless specific statistics from the wireless devices.
13 * This is the most popular part of the Wireless Extensions ;-)
14 *
15 * This interface is a pure clone of /proc/net/dev (in net/core/dev.c).
16 * The content of the file is basically the content of "struct iw_statistics".
17 */
18
19#include <linux/module.h>
20#include <linux/proc_fs.h>
21#include <linux/seq_file.h>
22#include <linux/wireless.h>
23#include <linux/netdevice.h>
24#include <linux/rtnetlink.h>
25#include <net/iw_handler.h>
26#include <net/wext.h>
27
28
29static void wireless_seq_printf_stats(struct seq_file *seq,
30 struct net_device *dev)
31{
32 /* Get stats from the driver */
33 struct iw_statistics *stats = get_wireless_stats(dev);
34 static struct iw_statistics nullstats = {};
35
36 /* show device if it's wireless regardless of current stats */
37 if (!stats) {
38#ifdef CONFIG_WIRELESS_EXT
39 if (dev->wireless_handlers)
40 stats = &nullstats;
41#endif
42#ifdef CONFIG_CFG80211
43 if (dev->ieee80211_ptr)
44 stats = &nullstats;
45#endif
46 }
47
48 if (stats) {
49 seq_printf(seq, "%6s: %04x %3d%c %3d%c %3d%c %6d %6d %6d "
50 "%6d %6d %6d\n",
51 dev->name, stats->status, stats->qual.qual,
52 stats->qual.updated & IW_QUAL_QUAL_UPDATED
53 ? '.' : ' ',
54 ((__s32) stats->qual.level) -
55 ((stats->qual.updated & IW_QUAL_DBM) ? 0x100 : 0),
56 stats->qual.updated & IW_QUAL_LEVEL_UPDATED
57 ? '.' : ' ',
58 ((__s32) stats->qual.noise) -
59 ((stats->qual.updated & IW_QUAL_DBM) ? 0x100 : 0),
60 stats->qual.updated & IW_QUAL_NOISE_UPDATED
61 ? '.' : ' ',
62 stats->discard.nwid, stats->discard.code,
63 stats->discard.fragment, stats->discard.retries,
64 stats->discard.misc, stats->miss.beacon);
65
66 if (stats != &nullstats)
67 stats->qual.updated &= ~IW_QUAL_ALL_UPDATED;
68 }
69}
70
71/* ---------------------------------------------------------------- */
72/*
73 * Print info for /proc/net/wireless (print all entries)
74 */
75static int wireless_dev_seq_show(struct seq_file *seq, void *v)
76{
77 might_sleep();
78
79 if (v == SEQ_START_TOKEN)
80 seq_printf(seq, "Inter-| sta-| Quality | Discarded "
81 "packets | Missed | WE\n"
82 " face | tus | link level noise | nwid "
83 "crypt frag retry misc | beacon | %d\n",
84 WIRELESS_EXT);
85 else
86 wireless_seq_printf_stats(seq, v);
87 return 0;
88}
89
90static void *wireless_dev_seq_start(struct seq_file *seq, loff_t *pos)
91{
92 struct net *net = seq_file_net(seq);
93 loff_t off;
94 struct net_device *dev;
95
96 rtnl_lock();
97 if (!*pos)
98 return SEQ_START_TOKEN;
99
100 off = 1;
101 for_each_netdev(net, dev)
102 if (off++ == *pos)
103 return dev;
104 return NULL;
105}
106
107static void *wireless_dev_seq_next(struct seq_file *seq, void *v, loff_t *pos)
108{
109 struct net *net = seq_file_net(seq);
110
111 ++*pos;
112
113 return v == SEQ_START_TOKEN ?
114 first_net_device(net) : next_net_device(v);
115}
116
117static void wireless_dev_seq_stop(struct seq_file *seq, void *v)
118{
119 rtnl_unlock();
120}
121
122static const struct seq_operations wireless_seq_ops = {
123 .start = wireless_dev_seq_start,
124 .next = wireless_dev_seq_next,
125 .stop = wireless_dev_seq_stop,
126 .show = wireless_dev_seq_show,
127};
128
129static int seq_open_wireless(struct inode *inode, struct file *file)
130{
131 return seq_open_net(inode, file, &wireless_seq_ops,
132 sizeof(struct seq_net_private));
133}
134
135static const struct file_operations wireless_seq_fops = {
136 .owner = THIS_MODULE,
137 .open = seq_open_wireless,
138 .read = seq_read,
139 .llseek = seq_lseek,
140 .release = seq_release_net,
141};
142
143int __net_init wext_proc_init(struct net *net)
144{
145 /* Create /proc/net/wireless entry */
146 if (!proc_net_fops_create(net, "wireless", S_IRUGO, &wireless_seq_fops))
147 return -ENOMEM;
148
149 return 0;
150}
151
152void __net_exit wext_proc_exit(struct net *net)
153{
154 proc_net_remove(net, "wireless");
155}
diff --git a/net/wireless/wext-sme.c b/net/wireless/wext-sme.c
index 5615a8802536..d5c6140f4cb8 100644
--- a/net/wireless/wext-sme.c
+++ b/net/wireless/wext-sme.c
@@ -7,6 +7,7 @@
7 7
8#include <linux/etherdevice.h> 8#include <linux/etherdevice.h>
9#include <linux/if_arp.h> 9#include <linux/if_arp.h>
10#include <linux/slab.h>
10#include <net/cfg80211.h> 11#include <net/cfg80211.h>
11#include "wext-compat.h" 12#include "wext-compat.h"
12#include "nl80211.h" 13#include "nl80211.h"
diff --git a/net/wireless/wext-spy.c b/net/wireless/wext-spy.c
new file mode 100644
index 000000000000..6dcfe65a2d1a
--- /dev/null
+++ b/net/wireless/wext-spy.c
@@ -0,0 +1,231 @@
1/*
2 * This file implement the Wireless Extensions spy API.
3 *
4 * Authors : Jean Tourrilhes - HPL - <jt@hpl.hp.com>
5 * Copyright (c) 1997-2007 Jean Tourrilhes, All Rights Reserved.
6 *
7 * (As all part of the Linux kernel, this file is GPL)
8 */
9
10#include <linux/wireless.h>
11#include <linux/netdevice.h>
12#include <linux/etherdevice.h>
13#include <net/iw_handler.h>
14#include <net/arp.h>
15#include <net/wext.h>
16
17static inline struct iw_spy_data *get_spydata(struct net_device *dev)
18{
19 /* This is the new way */
20 if (dev->wireless_data)
21 return dev->wireless_data->spy_data;
22 return NULL;
23}
24
25int iw_handler_set_spy(struct net_device * dev,
26 struct iw_request_info * info,
27 union iwreq_data * wrqu,
28 char * extra)
29{
30 struct iw_spy_data * spydata = get_spydata(dev);
31 struct sockaddr * address = (struct sockaddr *) extra;
32
33 /* Make sure driver is not buggy or using the old API */
34 if (!spydata)
35 return -EOPNOTSUPP;
36
37 /* Disable spy collection while we copy the addresses.
38 * While we copy addresses, any call to wireless_spy_update()
39 * will NOP. This is OK, as anyway the addresses are changing. */
40 spydata->spy_number = 0;
41
42 /* We want to operate without locking, because wireless_spy_update()
43 * most likely will happen in the interrupt handler, and therefore
44 * have its own locking constraints and needs performance.
45 * The rtnl_lock() make sure we don't race with the other iw_handlers.
46 * This make sure wireless_spy_update() "see" that the spy list
47 * is temporarily disabled. */
48 smp_wmb();
49
50 /* Are there are addresses to copy? */
51 if (wrqu->data.length > 0) {
52 int i;
53
54 /* Copy addresses */
55 for (i = 0; i < wrqu->data.length; i++)
56 memcpy(spydata->spy_address[i], address[i].sa_data,
57 ETH_ALEN);
58 /* Reset stats */
59 memset(spydata->spy_stat, 0,
60 sizeof(struct iw_quality) * IW_MAX_SPY);
61 }
62
63 /* Make sure above is updated before re-enabling */
64 smp_wmb();
65
66 /* Enable addresses */
67 spydata->spy_number = wrqu->data.length;
68
69 return 0;
70}
71EXPORT_SYMBOL(iw_handler_set_spy);
72
73int iw_handler_get_spy(struct net_device * dev,
74 struct iw_request_info * info,
75 union iwreq_data * wrqu,
76 char * extra)
77{
78 struct iw_spy_data * spydata = get_spydata(dev);
79 struct sockaddr * address = (struct sockaddr *) extra;
80 int i;
81
82 /* Make sure driver is not buggy or using the old API */
83 if (!spydata)
84 return -EOPNOTSUPP;
85
86 wrqu->data.length = spydata->spy_number;
87
88 /* Copy addresses. */
89 for (i = 0; i < spydata->spy_number; i++) {
90 memcpy(address[i].sa_data, spydata->spy_address[i], ETH_ALEN);
91 address[i].sa_family = AF_UNIX;
92 }
93 /* Copy stats to the user buffer (just after). */
94 if (spydata->spy_number > 0)
95 memcpy(extra + (sizeof(struct sockaddr) *spydata->spy_number),
96 spydata->spy_stat,
97 sizeof(struct iw_quality) * spydata->spy_number);
98 /* Reset updated flags. */
99 for (i = 0; i < spydata->spy_number; i++)
100 spydata->spy_stat[i].updated &= ~IW_QUAL_ALL_UPDATED;
101 return 0;
102}
103EXPORT_SYMBOL(iw_handler_get_spy);
104
105/*------------------------------------------------------------------*/
106/*
107 * Standard Wireless Handler : set spy threshold
108 */
109int iw_handler_set_thrspy(struct net_device * dev,
110 struct iw_request_info *info,
111 union iwreq_data * wrqu,
112 char * extra)
113{
114 struct iw_spy_data * spydata = get_spydata(dev);
115 struct iw_thrspy * threshold = (struct iw_thrspy *) extra;
116
117 /* Make sure driver is not buggy or using the old API */
118 if (!spydata)
119 return -EOPNOTSUPP;
120
121 /* Just do it */
122 memcpy(&(spydata->spy_thr_low), &(threshold->low),
123 2 * sizeof(struct iw_quality));
124
125 /* Clear flag */
126 memset(spydata->spy_thr_under, '\0', sizeof(spydata->spy_thr_under));
127
128 return 0;
129}
130EXPORT_SYMBOL(iw_handler_set_thrspy);
131
132/*------------------------------------------------------------------*/
133/*
134 * Standard Wireless Handler : get spy threshold
135 */
136int iw_handler_get_thrspy(struct net_device * dev,
137 struct iw_request_info *info,
138 union iwreq_data * wrqu,
139 char * extra)
140{
141 struct iw_spy_data * spydata = get_spydata(dev);
142 struct iw_thrspy * threshold = (struct iw_thrspy *) extra;
143
144 /* Make sure driver is not buggy or using the old API */
145 if (!spydata)
146 return -EOPNOTSUPP;
147
148 /* Just do it */
149 memcpy(&(threshold->low), &(spydata->spy_thr_low),
150 2 * sizeof(struct iw_quality));
151
152 return 0;
153}
154EXPORT_SYMBOL(iw_handler_get_thrspy);
155
156/*------------------------------------------------------------------*/
157/*
158 * Prepare and send a Spy Threshold event
159 */
160static void iw_send_thrspy_event(struct net_device * dev,
161 struct iw_spy_data * spydata,
162 unsigned char * address,
163 struct iw_quality * wstats)
164{
165 union iwreq_data wrqu;
166 struct iw_thrspy threshold;
167
168 /* Init */
169 wrqu.data.length = 1;
170 wrqu.data.flags = 0;
171 /* Copy address */
172 memcpy(threshold.addr.sa_data, address, ETH_ALEN);
173 threshold.addr.sa_family = ARPHRD_ETHER;
174 /* Copy stats */
175 memcpy(&(threshold.qual), wstats, sizeof(struct iw_quality));
176 /* Copy also thresholds */
177 memcpy(&(threshold.low), &(spydata->spy_thr_low),
178 2 * sizeof(struct iw_quality));
179
180 /* Send event to user space */
181 wireless_send_event(dev, SIOCGIWTHRSPY, &wrqu, (char *) &threshold);
182}
183
184/* ---------------------------------------------------------------- */
185/*
186 * Call for the driver to update the spy data.
187 * For now, the spy data is a simple array. As the size of the array is
188 * small, this is good enough. If we wanted to support larger number of
189 * spy addresses, we should use something more efficient...
190 */
191void wireless_spy_update(struct net_device * dev,
192 unsigned char * address,
193 struct iw_quality * wstats)
194{
195 struct iw_spy_data * spydata = get_spydata(dev);
196 int i;
197 int match = -1;
198
199 /* Make sure driver is not buggy or using the old API */
200 if (!spydata)
201 return;
202
203 /* Update all records that match */
204 for (i = 0; i < spydata->spy_number; i++)
205 if (!compare_ether_addr(address, spydata->spy_address[i])) {
206 memcpy(&(spydata->spy_stat[i]), wstats,
207 sizeof(struct iw_quality));
208 match = i;
209 }
210
211 /* Generate an event if we cross the spy threshold.
212 * To avoid event storms, we have a simple hysteresis : we generate
213 * event only when we go under the low threshold or above the
214 * high threshold. */
215 if (match >= 0) {
216 if (spydata->spy_thr_under[match]) {
217 if (wstats->level > spydata->spy_thr_high.level) {
218 spydata->spy_thr_under[match] = 0;
219 iw_send_thrspy_event(dev, spydata,
220 address, wstats);
221 }
222 } else {
223 if (wstats->level < spydata->spy_thr_low.level) {
224 spydata->spy_thr_under[match] = 1;
225 iw_send_thrspy_event(dev, spydata,
226 address, wstats);
227 }
228 }
229 }
230}
231EXPORT_SYMBOL(wireless_spy_update);
diff --git a/net/x25/af_x25.c b/net/x25/af_x25.c
index 7fa9c7ad3d3b..36e84e13c6aa 100644
--- a/net/x25/af_x25.c
+++ b/net/x25/af_x25.c
@@ -47,6 +47,7 @@
47#include <linux/netdevice.h> 47#include <linux/netdevice.h>
48#include <linux/if_arp.h> 48#include <linux/if_arp.h>
49#include <linux/skbuff.h> 49#include <linux/skbuff.h>
50#include <linux/slab.h>
50#include <net/sock.h> 51#include <net/sock.h>
51#include <net/tcp_states.h> 52#include <net/tcp_states.h>
52#include <asm/uaccess.h> 53#include <asm/uaccess.h>
@@ -55,6 +56,7 @@
55#include <linux/notifier.h> 56#include <linux/notifier.h>
56#include <linux/init.h> 57#include <linux/init.h>
57#include <linux/compat.h> 58#include <linux/compat.h>
59#include <linux/ctype.h>
58 60
59#include <net/x25.h> 61#include <net/x25.h>
60#include <net/compat.h> 62#include <net/compat.h>
@@ -81,6 +83,41 @@ struct compat_x25_subscrip_struct {
81}; 83};
82#endif 84#endif
83 85
86
87int x25_parse_address_block(struct sk_buff *skb,
88 struct x25_address *called_addr,
89 struct x25_address *calling_addr)
90{
91 unsigned char len;
92 int needed;
93 int rc;
94
95 if (skb->len < 1) {
96 /* packet has no address block */
97 rc = 0;
98 goto empty;
99 }
100
101 len = *skb->data;
102 needed = 1 + (len >> 4) + (len & 0x0f);
103
104 if (skb->len < needed) {
105 /* packet is too short to hold the addresses it claims
106 to hold */
107 rc = -1;
108 goto empty;
109 }
110
111 return x25_addr_ntoa(skb->data, called_addr, calling_addr);
112
113empty:
114 *called_addr->x25_addr = 0;
115 *calling_addr->x25_addr = 0;
116
117 return rc;
118}
119
120
84int x25_addr_ntoa(unsigned char *p, struct x25_address *called_addr, 121int x25_addr_ntoa(unsigned char *p, struct x25_address *called_addr,
85 struct x25_address *calling_addr) 122 struct x25_address *calling_addr)
86{ 123{
@@ -365,6 +402,7 @@ static void __x25_destroy_socket(struct sock *sk)
365 /* 402 /*
366 * Queue the unaccepted socket for death 403 * Queue the unaccepted socket for death
367 */ 404 */
405 skb->sk->sk_state = TCP_LISTEN;
368 sock_set_flag(skb->sk, SOCK_DEAD); 406 sock_set_flag(skb->sk, SOCK_DEAD);
369 x25_start_heartbeat(skb->sk); 407 x25_start_heartbeat(skb->sk);
370 x25_sk(skb->sk)->state = X25_STATE_0; 408 x25_sk(skb->sk)->state = X25_STATE_0;
@@ -415,6 +453,7 @@ static int x25_setsockopt(struct socket *sock, int level, int optname,
415 struct sock *sk = sock->sk; 453 struct sock *sk = sock->sk;
416 int rc = -ENOPROTOOPT; 454 int rc = -ENOPROTOOPT;
417 455
456 lock_kernel();
418 if (level != SOL_X25 || optname != X25_QBITINCL) 457 if (level != SOL_X25 || optname != X25_QBITINCL)
419 goto out; 458 goto out;
420 459
@@ -429,6 +468,7 @@ static int x25_setsockopt(struct socket *sock, int level, int optname,
429 x25_sk(sk)->qbitincl = !!opt; 468 x25_sk(sk)->qbitincl = !!opt;
430 rc = 0; 469 rc = 0;
431out: 470out:
471 unlock_kernel();
432 return rc; 472 return rc;
433} 473}
434 474
@@ -438,6 +478,7 @@ static int x25_getsockopt(struct socket *sock, int level, int optname,
438 struct sock *sk = sock->sk; 478 struct sock *sk = sock->sk;
439 int val, len, rc = -ENOPROTOOPT; 479 int val, len, rc = -ENOPROTOOPT;
440 480
481 lock_kernel();
441 if (level != SOL_X25 || optname != X25_QBITINCL) 482 if (level != SOL_X25 || optname != X25_QBITINCL)
442 goto out; 483 goto out;
443 484
@@ -458,6 +499,7 @@ static int x25_getsockopt(struct socket *sock, int level, int optname,
458 val = x25_sk(sk)->qbitincl; 499 val = x25_sk(sk)->qbitincl;
459 rc = copy_to_user(optval, &val, len) ? -EFAULT : 0; 500 rc = copy_to_user(optval, &val, len) ? -EFAULT : 0;
460out: 501out:
502 unlock_kernel();
461 return rc; 503 return rc;
462} 504}
463 505
@@ -466,12 +508,14 @@ static int x25_listen(struct socket *sock, int backlog)
466 struct sock *sk = sock->sk; 508 struct sock *sk = sock->sk;
467 int rc = -EOPNOTSUPP; 509 int rc = -EOPNOTSUPP;
468 510
511 lock_kernel();
469 if (sk->sk_state != TCP_LISTEN) { 512 if (sk->sk_state != TCP_LISTEN) {
470 memset(&x25_sk(sk)->dest_addr, 0, X25_ADDR_LEN); 513 memset(&x25_sk(sk)->dest_addr, 0, X25_ADDR_LEN);
471 sk->sk_max_ack_backlog = backlog; 514 sk->sk_max_ack_backlog = backlog;
472 sk->sk_state = TCP_LISTEN; 515 sk->sk_state = TCP_LISTEN;
473 rc = 0; 516 rc = 0;
474 } 517 }
518 unlock_kernel();
475 519
476 return rc; 520 return rc;
477} 521}
@@ -501,19 +545,25 @@ out:
501 return sk; 545 return sk;
502} 546}
503 547
504static int x25_create(struct net *net, struct socket *sock, int protocol) 548static int x25_create(struct net *net, struct socket *sock, int protocol,
549 int kern)
505{ 550{
506 struct sock *sk; 551 struct sock *sk;
507 struct x25_sock *x25; 552 struct x25_sock *x25;
508 int rc = -ESOCKTNOSUPPORT; 553 int rc = -EAFNOSUPPORT;
509 554
510 if (net != &init_net) 555 if (!net_eq(net, &init_net))
511 return -EAFNOSUPPORT; 556 goto out;
512 557
513 if (sock->type != SOCK_SEQPACKET || protocol) 558 rc = -ESOCKTNOSUPPORT;
559 if (sock->type != SOCK_SEQPACKET)
514 goto out; 560 goto out;
515 561
516 rc = -ENOMEM; 562 rc = -EINVAL;
563 if (protocol)
564 goto out;
565
566 rc = -ENOBUFS;
517 if ((sk = x25_alloc_socket(net)) == NULL) 567 if ((sk = x25_alloc_socket(net)) == NULL)
518 goto out; 568 goto out;
519 569
@@ -540,7 +590,8 @@ static int x25_create(struct net *net, struct socket *sock, int protocol)
540 x25->facilities.winsize_out = X25_DEFAULT_WINDOW_SIZE; 590 x25->facilities.winsize_out = X25_DEFAULT_WINDOW_SIZE;
541 x25->facilities.pacsize_in = X25_DEFAULT_PACKET_SIZE; 591 x25->facilities.pacsize_in = X25_DEFAULT_PACKET_SIZE;
542 x25->facilities.pacsize_out = X25_DEFAULT_PACKET_SIZE; 592 x25->facilities.pacsize_out = X25_DEFAULT_PACKET_SIZE;
543 x25->facilities.throughput = X25_DEFAULT_THROUGHPUT; 593 x25->facilities.throughput = 0; /* by default don't negotiate
594 throughput */
544 x25->facilities.reverse = X25_DEFAULT_REVERSE; 595 x25->facilities.reverse = X25_DEFAULT_REVERSE;
545 x25->dte_facilities.calling_len = 0; 596 x25->dte_facilities.calling_len = 0;
546 x25->dte_facilities.called_len = 0; 597 x25->dte_facilities.called_len = 0;
@@ -597,6 +648,7 @@ static int x25_release(struct socket *sock)
597 struct sock *sk = sock->sk; 648 struct sock *sk = sock->sk;
598 struct x25_sock *x25; 649 struct x25_sock *x25;
599 650
651 lock_kernel();
600 if (!sk) 652 if (!sk)
601 goto out; 653 goto out;
602 654
@@ -627,6 +679,7 @@ static int x25_release(struct socket *sock)
627 679
628 sock_orphan(sk); 680 sock_orphan(sk);
629out: 681out:
682 unlock_kernel();
630 return 0; 683 return 0;
631} 684}
632 685
@@ -634,18 +687,31 @@ static int x25_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
634{ 687{
635 struct sock *sk = sock->sk; 688 struct sock *sk = sock->sk;
636 struct sockaddr_x25 *addr = (struct sockaddr_x25 *)uaddr; 689 struct sockaddr_x25 *addr = (struct sockaddr_x25 *)uaddr;
690 int len, i, rc = 0;
637 691
692 lock_kernel();
638 if (!sock_flag(sk, SOCK_ZAPPED) || 693 if (!sock_flag(sk, SOCK_ZAPPED) ||
639 addr_len != sizeof(struct sockaddr_x25) || 694 addr_len != sizeof(struct sockaddr_x25) ||
640 addr->sx25_family != AF_X25) 695 addr->sx25_family != AF_X25) {
641 return -EINVAL; 696 rc = -EINVAL;
697 goto out;
698 }
699
700 len = strlen(addr->sx25_addr.x25_addr);
701 for (i = 0; i < len; i++) {
702 if (!isdigit(addr->sx25_addr.x25_addr[i])) {
703 rc = -EINVAL;
704 goto out;
705 }
706 }
642 707
643 x25_sk(sk)->source_addr = addr->sx25_addr; 708 x25_sk(sk)->source_addr = addr->sx25_addr;
644 x25_insert_socket(sk); 709 x25_insert_socket(sk);
645 sock_reset_flag(sk, SOCK_ZAPPED); 710 sock_reset_flag(sk, SOCK_ZAPPED);
646 SOCK_DEBUG(sk, "x25_bind: socket is bound\n"); 711 SOCK_DEBUG(sk, "x25_bind: socket is bound\n");
647 712out:
648 return 0; 713 unlock_kernel();
714 return rc;
649} 715}
650 716
651static int x25_wait_for_connection_establishment(struct sock *sk) 717static int x25_wait_for_connection_establishment(struct sock *sk)
@@ -686,6 +752,7 @@ static int x25_connect(struct socket *sock, struct sockaddr *uaddr,
686 struct x25_route *rt; 752 struct x25_route *rt;
687 int rc = 0; 753 int rc = 0;
688 754
755 lock_kernel();
689 lock_sock(sk); 756 lock_sock(sk);
690 if (sk->sk_state == TCP_ESTABLISHED && sock->state == SS_CONNECTING) { 757 if (sk->sk_state == TCP_ESTABLISHED && sock->state == SS_CONNECTING) {
691 sock->state = SS_CONNECTED; 758 sock->state = SS_CONNECTED;
@@ -763,6 +830,7 @@ out_put_route:
763 x25_route_put(rt); 830 x25_route_put(rt);
764out: 831out:
765 release_sock(sk); 832 release_sock(sk);
833 unlock_kernel();
766 return rc; 834 return rc;
767} 835}
768 836
@@ -802,6 +870,7 @@ static int x25_accept(struct socket *sock, struct socket *newsock, int flags)
802 struct sk_buff *skb; 870 struct sk_buff *skb;
803 int rc = -EINVAL; 871 int rc = -EINVAL;
804 872
873 lock_kernel();
805 if (!sk || sk->sk_state != TCP_LISTEN) 874 if (!sk || sk->sk_state != TCP_LISTEN)
806 goto out; 875 goto out;
807 876
@@ -829,6 +898,7 @@ static int x25_accept(struct socket *sock, struct socket *newsock, int flags)
829out2: 898out2:
830 release_sock(sk); 899 release_sock(sk);
831out: 900out:
901 unlock_kernel();
832 return rc; 902 return rc;
833} 903}
834 904
@@ -838,10 +908,14 @@ static int x25_getname(struct socket *sock, struct sockaddr *uaddr,
838 struct sockaddr_x25 *sx25 = (struct sockaddr_x25 *)uaddr; 908 struct sockaddr_x25 *sx25 = (struct sockaddr_x25 *)uaddr;
839 struct sock *sk = sock->sk; 909 struct sock *sk = sock->sk;
840 struct x25_sock *x25 = x25_sk(sk); 910 struct x25_sock *x25 = x25_sk(sk);
911 int rc = 0;
841 912
913 lock_kernel();
842 if (peer) { 914 if (peer) {
843 if (sk->sk_state != TCP_ESTABLISHED) 915 if (sk->sk_state != TCP_ESTABLISHED) {
844 return -ENOTCONN; 916 rc = -ENOTCONN;
917 goto out;
918 }
845 sx25->sx25_addr = x25->dest_addr; 919 sx25->sx25_addr = x25->dest_addr;
846 } else 920 } else
847 sx25->sx25_addr = x25->source_addr; 921 sx25->sx25_addr = x25->source_addr;
@@ -849,7 +923,21 @@ static int x25_getname(struct socket *sock, struct sockaddr *uaddr,
849 sx25->sx25_family = AF_X25; 923 sx25->sx25_family = AF_X25;
850 *uaddr_len = sizeof(*sx25); 924 *uaddr_len = sizeof(*sx25);
851 925
852 return 0; 926out:
927 unlock_kernel();
928 return rc;
929}
930
931static unsigned int x25_datagram_poll(struct file *file, struct socket *sock,
932 poll_table *wait)
933{
934 int rc;
935
936 lock_kernel();
937 rc = datagram_poll(file, sock, wait);
938 unlock_kernel();
939
940 return rc;
853} 941}
854 942
855int x25_rx_call_request(struct sk_buff *skb, struct x25_neigh *nb, 943int x25_rx_call_request(struct sk_buff *skb, struct x25_neigh *nb,
@@ -871,16 +959,26 @@ int x25_rx_call_request(struct sk_buff *skb, struct x25_neigh *nb,
871 /* 959 /*
872 * Extract the X.25 addresses and convert them to ASCII strings, 960 * Extract the X.25 addresses and convert them to ASCII strings,
873 * and remove them. 961 * and remove them.
962 *
963 * Address block is mandatory in call request packets
874 */ 964 */
875 addr_len = x25_addr_ntoa(skb->data, &source_addr, &dest_addr); 965 addr_len = x25_parse_address_block(skb, &source_addr, &dest_addr);
966 if (addr_len <= 0)
967 goto out_clear_request;
876 skb_pull(skb, addr_len); 968 skb_pull(skb, addr_len);
877 969
878 /* 970 /*
879 * Get the length of the facilities, skip past them for the moment 971 * Get the length of the facilities, skip past them for the moment
880 * get the call user data because this is needed to determine 972 * get the call user data because this is needed to determine
881 * the correct listener 973 * the correct listener
974 *
975 * Facilities length is mandatory in call request packets
882 */ 976 */
977 if (skb->len < 1)
978 goto out_clear_request;
883 len = skb->data[0] + 1; 979 len = skb->data[0] + 1;
980 if (skb->len < len)
981 goto out_clear_request;
884 skb_pull(skb,len); 982 skb_pull(skb,len);
885 983
886 /* 984 /*
@@ -1002,6 +1100,7 @@ static int x25_sendmsg(struct kiocb *iocb, struct socket *sock,
1002 size_t size; 1100 size_t size;
1003 int qbit = 0, rc = -EINVAL; 1101 int qbit = 0, rc = -EINVAL;
1004 1102
1103 lock_kernel();
1005 if (msg->msg_flags & ~(MSG_DONTWAIT|MSG_OOB|MSG_EOR|MSG_CMSG_COMPAT)) 1104 if (msg->msg_flags & ~(MSG_DONTWAIT|MSG_OOB|MSG_EOR|MSG_CMSG_COMPAT))
1006 goto out; 1105 goto out;
1007 1106
@@ -1166,6 +1265,7 @@ static int x25_sendmsg(struct kiocb *iocb, struct socket *sock,
1166 release_sock(sk); 1265 release_sock(sk);
1167 rc = len; 1266 rc = len;
1168out: 1267out:
1268 unlock_kernel();
1169 return rc; 1269 return rc;
1170out_kfree_skb: 1270out_kfree_skb:
1171 kfree_skb(skb); 1271 kfree_skb(skb);
@@ -1186,6 +1286,7 @@ static int x25_recvmsg(struct kiocb *iocb, struct socket *sock,
1186 unsigned char *asmptr; 1286 unsigned char *asmptr;
1187 int rc = -ENOTCONN; 1287 int rc = -ENOTCONN;
1188 1288
1289 lock_kernel();
1189 /* 1290 /*
1190 * This works for seqpacket too. The receiver has ordered the queue for 1291 * This works for seqpacket too. The receiver has ordered the queue for
1191 * us! We do one quick check first though 1292 * us! We do one quick check first though
@@ -1259,6 +1360,7 @@ static int x25_recvmsg(struct kiocb *iocb, struct socket *sock,
1259out_free_dgram: 1360out_free_dgram:
1260 skb_free_datagram(sk, skb); 1361 skb_free_datagram(sk, skb);
1261out: 1362out:
1363 unlock_kernel();
1262 return rc; 1364 return rc;
1263} 1365}
1264 1366
@@ -1270,6 +1372,7 @@ static int x25_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
1270 void __user *argp = (void __user *)arg; 1372 void __user *argp = (void __user *)arg;
1271 int rc; 1373 int rc;
1272 1374
1375 lock_kernel();
1273 switch (cmd) { 1376 switch (cmd) {
1274 case TIOCOUTQ: { 1377 case TIOCOUTQ: {
1275 int amount = sk->sk_sndbuf - sk_wmem_alloc_get(sk); 1378 int amount = sk->sk_sndbuf - sk_wmem_alloc_get(sk);
@@ -1359,11 +1462,22 @@ static int x25_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
1359 if (facilities.winsize_in < 1 || 1462 if (facilities.winsize_in < 1 ||
1360 facilities.winsize_in > 127) 1463 facilities.winsize_in > 127)
1361 break; 1464 break;
1362 if (facilities.throughput < 0x03 || 1465 if (facilities.throughput) {
1363 facilities.throughput > 0xDD) 1466 int out = facilities.throughput & 0xf0;
1364 break; 1467 int in = facilities.throughput & 0x0f;
1468 if (!out)
1469 facilities.throughput |=
1470 X25_DEFAULT_THROUGHPUT << 4;
1471 else if (out < 0x30 || out > 0xD0)
1472 break;
1473 if (!in)
1474 facilities.throughput |=
1475 X25_DEFAULT_THROUGHPUT;
1476 else if (in < 0x03 || in > 0x0D)
1477 break;
1478 }
1365 if (facilities.reverse && 1479 if (facilities.reverse &&
1366 (facilities.reverse | 0x81)!= 0x81) 1480 (facilities.reverse & 0x81) != 0x81)
1367 break; 1481 break;
1368 x25->facilities = facilities; 1482 x25->facilities = facilities;
1369 rc = 0; 1483 rc = 0;
@@ -1430,6 +1544,17 @@ static int x25_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
1430 break; 1544 break;
1431 } 1545 }
1432 1546
1547 case SIOCX25SCAUSEDIAG: {
1548 struct x25_causediag causediag;
1549 rc = -EFAULT;
1550 if (copy_from_user(&causediag, argp, sizeof(causediag)))
1551 break;
1552 x25->causediag = causediag;
1553 rc = 0;
1554 break;
1555
1556 }
1557
1433 case SIOCX25SCUDMATCHLEN: { 1558 case SIOCX25SCUDMATCHLEN: {
1434 struct x25_subaddr sub_addr; 1559 struct x25_subaddr sub_addr;
1435 rc = -EINVAL; 1560 rc = -EINVAL;
@@ -1472,11 +1597,12 @@ static int x25_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
1472 rc = -ENOIOCTLCMD; 1597 rc = -ENOIOCTLCMD;
1473 break; 1598 break;
1474 } 1599 }
1600 unlock_kernel();
1475 1601
1476 return rc; 1602 return rc;
1477} 1603}
1478 1604
1479static struct net_proto_family x25_family_ops = { 1605static const struct net_proto_family x25_family_ops = {
1480 .family = AF_X25, 1606 .family = AF_X25,
1481 .create = x25_create, 1607 .create = x25_create,
1482 .owner = THIS_MODULE, 1608 .owner = THIS_MODULE,
@@ -1542,15 +1668,19 @@ static int compat_x25_ioctl(struct socket *sock, unsigned int cmd,
1542 break; 1668 break;
1543 case SIOCGSTAMP: 1669 case SIOCGSTAMP:
1544 rc = -EINVAL; 1670 rc = -EINVAL;
1671 lock_kernel();
1545 if (sk) 1672 if (sk)
1546 rc = compat_sock_get_timestamp(sk, 1673 rc = compat_sock_get_timestamp(sk,
1547 (struct timeval __user*)argp); 1674 (struct timeval __user*)argp);
1675 unlock_kernel();
1548 break; 1676 break;
1549 case SIOCGSTAMPNS: 1677 case SIOCGSTAMPNS:
1550 rc = -EINVAL; 1678 rc = -EINVAL;
1679 lock_kernel();
1551 if (sk) 1680 if (sk)
1552 rc = compat_sock_get_timestampns(sk, 1681 rc = compat_sock_get_timestampns(sk,
1553 (struct timespec __user*)argp); 1682 (struct timespec __user*)argp);
1683 unlock_kernel();
1554 break; 1684 break;
1555 case SIOCGIFADDR: 1685 case SIOCGIFADDR:
1556 case SIOCSIFADDR: 1686 case SIOCSIFADDR:
@@ -1569,16 +1699,22 @@ static int compat_x25_ioctl(struct socket *sock, unsigned int cmd,
1569 rc = -EPERM; 1699 rc = -EPERM;
1570 if (!capable(CAP_NET_ADMIN)) 1700 if (!capable(CAP_NET_ADMIN))
1571 break; 1701 break;
1702 lock_kernel();
1572 rc = x25_route_ioctl(cmd, argp); 1703 rc = x25_route_ioctl(cmd, argp);
1704 unlock_kernel();
1573 break; 1705 break;
1574 case SIOCX25GSUBSCRIP: 1706 case SIOCX25GSUBSCRIP:
1707 lock_kernel();
1575 rc = compat_x25_subscr_ioctl(cmd, argp); 1708 rc = compat_x25_subscr_ioctl(cmd, argp);
1709 unlock_kernel();
1576 break; 1710 break;
1577 case SIOCX25SSUBSCRIP: 1711 case SIOCX25SSUBSCRIP:
1578 rc = -EPERM; 1712 rc = -EPERM;
1579 if (!capable(CAP_NET_ADMIN)) 1713 if (!capable(CAP_NET_ADMIN))
1580 break; 1714 break;
1715 lock_kernel();
1581 rc = compat_x25_subscr_ioctl(cmd, argp); 1716 rc = compat_x25_subscr_ioctl(cmd, argp);
1717 unlock_kernel();
1582 break; 1718 break;
1583 case SIOCX25GFACILITIES: 1719 case SIOCX25GFACILITIES:
1584 case SIOCX25SFACILITIES: 1720 case SIOCX25SFACILITIES:
@@ -1587,6 +1723,7 @@ static int compat_x25_ioctl(struct socket *sock, unsigned int cmd,
1587 case SIOCX25GCALLUSERDATA: 1723 case SIOCX25GCALLUSERDATA:
1588 case SIOCX25SCALLUSERDATA: 1724 case SIOCX25SCALLUSERDATA:
1589 case SIOCX25GCAUSEDIAG: 1725 case SIOCX25GCAUSEDIAG:
1726 case SIOCX25SCAUSEDIAG:
1590 case SIOCX25SCUDMATCHLEN: 1727 case SIOCX25SCUDMATCHLEN:
1591 case SIOCX25CALLACCPTAPPRV: 1728 case SIOCX25CALLACCPTAPPRV:
1592 case SIOCX25SENDCALLACCPT: 1729 case SIOCX25SENDCALLACCPT:
@@ -1600,7 +1737,7 @@ static int compat_x25_ioctl(struct socket *sock, unsigned int cmd,
1600} 1737}
1601#endif 1738#endif
1602 1739
1603static const struct proto_ops SOCKOPS_WRAPPED(x25_proto_ops) = { 1740static const struct proto_ops x25_proto_ops = {
1604 .family = AF_X25, 1741 .family = AF_X25,
1605 .owner = THIS_MODULE, 1742 .owner = THIS_MODULE,
1606 .release = x25_release, 1743 .release = x25_release,
@@ -1609,7 +1746,7 @@ static const struct proto_ops SOCKOPS_WRAPPED(x25_proto_ops) = {
1609 .socketpair = sock_no_socketpair, 1746 .socketpair = sock_no_socketpair,
1610 .accept = x25_accept, 1747 .accept = x25_accept,
1611 .getname = x25_getname, 1748 .getname = x25_getname,
1612 .poll = datagram_poll, 1749 .poll = x25_datagram_poll,
1613 .ioctl = x25_ioctl, 1750 .ioctl = x25_ioctl,
1614#ifdef CONFIG_COMPAT 1751#ifdef CONFIG_COMPAT
1615 .compat_ioctl = compat_x25_ioctl, 1752 .compat_ioctl = compat_x25_ioctl,
@@ -1624,8 +1761,6 @@ static const struct proto_ops SOCKOPS_WRAPPED(x25_proto_ops) = {
1624 .sendpage = sock_no_sendpage, 1761 .sendpage = sock_no_sendpage,
1625}; 1762};
1626 1763
1627SOCKOPS_WRAP(x25_proto, AF_X25);
1628
1629static struct packet_type x25_packet_type __read_mostly = { 1764static struct packet_type x25_packet_type __read_mostly = {
1630 .type = cpu_to_be16(ETH_P_X25), 1765 .type = cpu_to_be16(ETH_P_X25),
1631 .func = x25_lapb_receive_frame, 1766 .func = x25_lapb_receive_frame,
@@ -1659,20 +1794,31 @@ static int __init x25_init(void)
1659 if (rc != 0) 1794 if (rc != 0)
1660 goto out; 1795 goto out;
1661 1796
1662 sock_register(&x25_family_ops); 1797 rc = sock_register(&x25_family_ops);
1798 if (rc != 0)
1799 goto out_proto;
1663 1800
1664 dev_add_pack(&x25_packet_type); 1801 dev_add_pack(&x25_packet_type);
1665 1802
1666 register_netdevice_notifier(&x25_dev_notifier); 1803 rc = register_netdevice_notifier(&x25_dev_notifier);
1804 if (rc != 0)
1805 goto out_sock;
1667 1806
1668 printk(KERN_INFO "X.25 for Linux Version 0.2\n"); 1807 printk(KERN_INFO "X.25 for Linux Version 0.2\n");
1669 1808
1670#ifdef CONFIG_SYSCTL
1671 x25_register_sysctl(); 1809 x25_register_sysctl();
1672#endif 1810 rc = x25_proc_init();
1673 x25_proc_init(); 1811 if (rc != 0)
1812 goto out_dev;
1674out: 1813out:
1675 return rc; 1814 return rc;
1815out_dev:
1816 unregister_netdevice_notifier(&x25_dev_notifier);
1817out_sock:
1818 sock_unregister(AF_X25);
1819out_proto:
1820 proto_unregister(&x25_proto);
1821 goto out;
1676} 1822}
1677module_init(x25_init); 1823module_init(x25_init);
1678 1824
@@ -1682,9 +1828,7 @@ static void __exit x25_exit(void)
1682 x25_link_free(); 1828 x25_link_free();
1683 x25_route_free(); 1829 x25_route_free();
1684 1830
1685#ifdef CONFIG_SYSCTL
1686 x25_unregister_sysctl(); 1831 x25_unregister_sysctl();
1687#endif
1688 1832
1689 unregister_netdevice_notifier(&x25_dev_notifier); 1833 unregister_netdevice_notifier(&x25_dev_notifier);
1690 1834
diff --git a/net/x25/sysctl_net_x25.c b/net/x25/sysctl_net_x25.c
index a5d3416522de..d2efd29f434e 100644
--- a/net/x25/sysctl_net_x25.c
+++ b/net/x25/sysctl_net_x25.c
@@ -19,62 +19,51 @@ static struct ctl_table_header *x25_table_header;
19 19
20static struct ctl_table x25_table[] = { 20static struct ctl_table x25_table[] = {
21 { 21 {
22 .ctl_name = NET_X25_RESTART_REQUEST_TIMEOUT,
23 .procname = "restart_request_timeout", 22 .procname = "restart_request_timeout",
24 .data = &sysctl_x25_restart_request_timeout, 23 .data = &sysctl_x25_restart_request_timeout,
25 .maxlen = sizeof(int), 24 .maxlen = sizeof(int),
26 .mode = 0644, 25 .mode = 0644,
27 .proc_handler = proc_dointvec_minmax, 26 .proc_handler = proc_dointvec_minmax,
28 .strategy = sysctl_intvec,
29 .extra1 = &min_timer, 27 .extra1 = &min_timer,
30 .extra2 = &max_timer, 28 .extra2 = &max_timer,
31 }, 29 },
32 { 30 {
33 .ctl_name = NET_X25_CALL_REQUEST_TIMEOUT,
34 .procname = "call_request_timeout", 31 .procname = "call_request_timeout",
35 .data = &sysctl_x25_call_request_timeout, 32 .data = &sysctl_x25_call_request_timeout,
36 .maxlen = sizeof(int), 33 .maxlen = sizeof(int),
37 .mode = 0644, 34 .mode = 0644,
38 .proc_handler = proc_dointvec_minmax, 35 .proc_handler = proc_dointvec_minmax,
39 .strategy = sysctl_intvec,
40 .extra1 = &min_timer, 36 .extra1 = &min_timer,
41 .extra2 = &max_timer, 37 .extra2 = &max_timer,
42 }, 38 },
43 { 39 {
44 .ctl_name = NET_X25_RESET_REQUEST_TIMEOUT,
45 .procname = "reset_request_timeout", 40 .procname = "reset_request_timeout",
46 .data = &sysctl_x25_reset_request_timeout, 41 .data = &sysctl_x25_reset_request_timeout,
47 .maxlen = sizeof(int), 42 .maxlen = sizeof(int),
48 .mode = 0644, 43 .mode = 0644,
49 .proc_handler = proc_dointvec_minmax, 44 .proc_handler = proc_dointvec_minmax,
50 .strategy = sysctl_intvec,
51 .extra1 = &min_timer, 45 .extra1 = &min_timer,
52 .extra2 = &max_timer, 46 .extra2 = &max_timer,
53 }, 47 },
54 { 48 {
55 .ctl_name = NET_X25_CLEAR_REQUEST_TIMEOUT,
56 .procname = "clear_request_timeout", 49 .procname = "clear_request_timeout",
57 .data = &sysctl_x25_clear_request_timeout, 50 .data = &sysctl_x25_clear_request_timeout,
58 .maxlen = sizeof(int), 51 .maxlen = sizeof(int),
59 .mode = 0644, 52 .mode = 0644,
60 .proc_handler = proc_dointvec_minmax, 53 .proc_handler = proc_dointvec_minmax,
61 .strategy = sysctl_intvec,
62 .extra1 = &min_timer, 54 .extra1 = &min_timer,
63 .extra2 = &max_timer, 55 .extra2 = &max_timer,
64 }, 56 },
65 { 57 {
66 .ctl_name = NET_X25_ACK_HOLD_BACK_TIMEOUT,
67 .procname = "acknowledgement_hold_back_timeout", 58 .procname = "acknowledgement_hold_back_timeout",
68 .data = &sysctl_x25_ack_holdback_timeout, 59 .data = &sysctl_x25_ack_holdback_timeout,
69 .maxlen = sizeof(int), 60 .maxlen = sizeof(int),
70 .mode = 0644, 61 .mode = 0644,
71 .proc_handler = proc_dointvec_minmax, 62 .proc_handler = proc_dointvec_minmax,
72 .strategy = sysctl_intvec,
73 .extra1 = &min_timer, 63 .extra1 = &min_timer,
74 .extra2 = &max_timer, 64 .extra2 = &max_timer,
75 }, 65 },
76 { 66 {
77 .ctl_name = NET_X25_FORWARD,
78 .procname = "x25_forward", 67 .procname = "x25_forward",
79 .data = &sysctl_x25_forward, 68 .data = &sysctl_x25_forward,
80 .maxlen = sizeof(int), 69 .maxlen = sizeof(int),
@@ -85,8 +74,8 @@ static struct ctl_table x25_table[] = {
85}; 74};
86 75
87static struct ctl_path x25_path[] = { 76static struct ctl_path x25_path[] = {
88 { .procname = "net", .ctl_name = CTL_NET, }, 77 { .procname = "net", },
89 { .procname = "x25", .ctl_name = NET_X25, }, 78 { .procname = "x25", },
90 { } 79 { }
91}; 80};
92 81
diff --git a/net/x25/x25_dev.c b/net/x25/x25_dev.c
index 3e1efe534645..b9ef682230a0 100644
--- a/net/x25/x25_dev.c
+++ b/net/x25/x25_dev.c
@@ -20,6 +20,7 @@
20#include <linux/kernel.h> 20#include <linux/kernel.h>
21#include <linux/netdevice.h> 21#include <linux/netdevice.h>
22#include <linux/skbuff.h> 22#include <linux/skbuff.h>
23#include <linux/slab.h>
23#include <net/sock.h> 24#include <net/sock.h>
24#include <linux/if_arp.h> 25#include <linux/if_arp.h>
25#include <net/x25.h> 26#include <net/x25.h>
@@ -53,7 +54,7 @@ static int x25_receive_data(struct sk_buff *skb, struct x25_neigh *nb)
53 if (!sock_owned_by_user(sk)) { 54 if (!sock_owned_by_user(sk)) {
54 queued = x25_process_rx_frame(sk, skb); 55 queued = x25_process_rx_frame(sk, skb);
55 } else { 56 } else {
56 sk_add_backlog(sk, skb); 57 queued = !sk_add_backlog(sk, skb);
57 } 58 }
58 bh_unlock_sock(sk); 59 bh_unlock_sock(sk);
59 sock_put(sk); 60 sock_put(sk);
diff --git a/net/x25/x25_facilities.c b/net/x25/x25_facilities.c
index a21f6646eb3a..771bab00754b 100644
--- a/net/x25/x25_facilities.c
+++ b/net/x25/x25_facilities.c
@@ -35,7 +35,7 @@ int x25_parse_facilities(struct sk_buff *skb, struct x25_facilities *facilities,
35 struct x25_dte_facilities *dte_facs, unsigned long *vc_fac_mask) 35 struct x25_dte_facilities *dte_facs, unsigned long *vc_fac_mask)
36{ 36{
37 unsigned char *p = skb->data; 37 unsigned char *p = skb->data;
38 unsigned int len = *p++; 38 unsigned int len;
39 39
40 *vc_fac_mask = 0; 40 *vc_fac_mask = 0;
41 41
@@ -50,6 +50,14 @@ int x25_parse_facilities(struct sk_buff *skb, struct x25_facilities *facilities,
50 memset(dte_facs->called_ae, '\0', sizeof(dte_facs->called_ae)); 50 memset(dte_facs->called_ae, '\0', sizeof(dte_facs->called_ae));
51 memset(dte_facs->calling_ae, '\0', sizeof(dte_facs->calling_ae)); 51 memset(dte_facs->calling_ae, '\0', sizeof(dte_facs->calling_ae));
52 52
53 if (skb->len < 1)
54 return 0;
55
56 len = *p++;
57
58 if (len >= skb->len)
59 return -1;
60
53 while (len > 0) { 61 while (len > 0) {
54 switch (*p & X25_FAC_CLASS_MASK) { 62 switch (*p & X25_FAC_CLASS_MASK) {
55 case X25_FAC_CLASS_A: 63 case X25_FAC_CLASS_A:
@@ -247,6 +255,8 @@ int x25_negotiate_facilities(struct sk_buff *skb, struct sock *sk,
247 memcpy(new, ours, sizeof(*new)); 255 memcpy(new, ours, sizeof(*new));
248 256
249 len = x25_parse_facilities(skb, &theirs, dte, &x25->vc_facil_mask); 257 len = x25_parse_facilities(skb, &theirs, dte, &x25->vc_facil_mask);
258 if (len < 0)
259 return len;
250 260
251 /* 261 /*
252 * They want reverse charging, we won't accept it. 262 * They want reverse charging, we won't accept it.
@@ -259,9 +269,18 @@ int x25_negotiate_facilities(struct sk_buff *skb, struct sock *sk,
259 new->reverse = theirs.reverse; 269 new->reverse = theirs.reverse;
260 270
261 if (theirs.throughput) { 271 if (theirs.throughput) {
262 if (theirs.throughput < ours->throughput) { 272 int theirs_in = theirs.throughput & 0x0f;
263 SOCK_DEBUG(sk, "X.25: throughput negotiated down\n"); 273 int theirs_out = theirs.throughput & 0xf0;
264 new->throughput = theirs.throughput; 274 int ours_in = ours->throughput & 0x0f;
275 int ours_out = ours->throughput & 0xf0;
276 if (!ours_in || theirs_in < ours_in) {
277 SOCK_DEBUG(sk, "X.25: inbound throughput negotiated\n");
278 new->throughput = (new->throughput & 0xf0) | theirs_in;
279 }
280 if (!ours_out || theirs_out < ours_out) {
281 SOCK_DEBUG(sk,
282 "X.25: outbound throughput negotiated\n");
283 new->throughput = (new->throughput & 0x0f) | theirs_out;
265 } 284 }
266 } 285 }
267 286
diff --git a/net/x25/x25_forward.c b/net/x25/x25_forward.c
index 056a55f3a871..25a810793968 100644
--- a/net/x25/x25_forward.c
+++ b/net/x25/x25_forward.c
@@ -10,6 +10,7 @@
10 */ 10 */
11#include <linux/if_arp.h> 11#include <linux/if_arp.h>
12#include <linux/init.h> 12#include <linux/init.h>
13#include <linux/slab.h>
13#include <net/x25.h> 14#include <net/x25.h>
14 15
15LIST_HEAD(x25_forward_list); 16LIST_HEAD(x25_forward_list);
diff --git a/net/x25/x25_in.c b/net/x25/x25_in.c
index 7d7c3abf38b5..372ac226e648 100644
--- a/net/x25/x25_in.c
+++ b/net/x25/x25_in.c
@@ -23,6 +23,7 @@
23 * i-frames. 23 * i-frames.
24 */ 24 */
25 25
26#include <linux/slab.h>
26#include <linux/errno.h> 27#include <linux/errno.h>
27#include <linux/kernel.h> 28#include <linux/kernel.h>
28#include <linux/string.h> 29#include <linux/string.h>
@@ -89,6 +90,7 @@ static int x25_queue_rx_frame(struct sock *sk, struct sk_buff *skb, int more)
89static int x25_state1_machine(struct sock *sk, struct sk_buff *skb, int frametype) 90static int x25_state1_machine(struct sock *sk, struct sk_buff *skb, int frametype)
90{ 91{
91 struct x25_address source_addr, dest_addr; 92 struct x25_address source_addr, dest_addr;
93 int len;
92 94
93 switch (frametype) { 95 switch (frametype) {
94 case X25_CALL_ACCEPTED: { 96 case X25_CALL_ACCEPTED: {
@@ -106,15 +108,21 @@ static int x25_state1_machine(struct sock *sk, struct sk_buff *skb, int frametyp
106 * Parse the data in the frame. 108 * Parse the data in the frame.
107 */ 109 */
108 skb_pull(skb, X25_STD_MIN_LEN); 110 skb_pull(skb, X25_STD_MIN_LEN);
109 skb_pull(skb, x25_addr_ntoa(skb->data, &source_addr, &dest_addr)); 111
110 skb_pull(skb, 112 len = x25_parse_address_block(skb, &source_addr,
111 x25_parse_facilities(skb, &x25->facilities, 113 &dest_addr);
114 if (len > 0)
115 skb_pull(skb, len);
116
117 len = x25_parse_facilities(skb, &x25->facilities,
112 &x25->dte_facilities, 118 &x25->dte_facilities,
113 &x25->vc_facil_mask)); 119 &x25->vc_facil_mask);
120 if (len > 0)
121 skb_pull(skb, len);
114 /* 122 /*
115 * Copy any Call User Data. 123 * Copy any Call User Data.
116 */ 124 */
117 if (skb->len >= 0) { 125 if (skb->len > 0) {
118 skb_copy_from_linear_data(skb, 126 skb_copy_from_linear_data(skb,
119 x25->calluserdata.cuddata, 127 x25->calluserdata.cuddata,
120 skb->len); 128 skb->len);
diff --git a/net/x25/x25_link.c b/net/x25/x25_link.c
index e4e1b6e49538..73e7b954ad28 100644
--- a/net/x25/x25_link.c
+++ b/net/x25/x25_link.c
@@ -24,6 +24,7 @@
24#include <linux/kernel.h> 24#include <linux/kernel.h>
25#include <linux/jiffies.h> 25#include <linux/jiffies.h>
26#include <linux/timer.h> 26#include <linux/timer.h>
27#include <linux/slab.h>
27#include <linux/netdevice.h> 28#include <linux/netdevice.h>
28#include <linux/skbuff.h> 29#include <linux/skbuff.h>
29#include <asm/uaccess.h> 30#include <asm/uaccess.h>
diff --git a/net/x25/x25_out.c b/net/x25/x25_out.c
index 2b96b52114d6..52351a26b6fc 100644
--- a/net/x25/x25_out.c
+++ b/net/x25/x25_out.c
@@ -22,6 +22,7 @@
22 * needed cleaned seq-number fields. 22 * needed cleaned seq-number fields.
23 */ 23 */
24 24
25#include <linux/slab.h>
25#include <linux/socket.h> 26#include <linux/socket.h>
26#include <linux/kernel.h> 27#include <linux/kernel.h>
27#include <linux/string.h> 28#include <linux/string.h>
diff --git a/net/x25/x25_proc.c b/net/x25/x25_proc.c
index 0a04e62e0e18..7ff373792324 100644
--- a/net/x25/x25_proc.c
+++ b/net/x25/x25_proc.c
@@ -25,49 +25,17 @@
25#include <net/x25.h> 25#include <net/x25.h>
26 26
27#ifdef CONFIG_PROC_FS 27#ifdef CONFIG_PROC_FS
28static __inline__ struct x25_route *x25_get_route_idx(loff_t pos)
29{
30 struct list_head *route_entry;
31 struct x25_route *rt = NULL;
32
33 list_for_each(route_entry, &x25_route_list) {
34 rt = list_entry(route_entry, struct x25_route, node);
35 if (!pos--)
36 goto found;
37 }
38 rt = NULL;
39found:
40 return rt;
41}
42 28
43static void *x25_seq_route_start(struct seq_file *seq, loff_t *pos) 29static void *x25_seq_route_start(struct seq_file *seq, loff_t *pos)
44 __acquires(x25_route_list_lock) 30 __acquires(x25_route_list_lock)
45{ 31{
46 loff_t l = *pos;
47
48 read_lock_bh(&x25_route_list_lock); 32 read_lock_bh(&x25_route_list_lock);
49 return l ? x25_get_route_idx(--l) : SEQ_START_TOKEN; 33 return seq_list_start_head(&x25_route_list, *pos);
50} 34}
51 35
52static void *x25_seq_route_next(struct seq_file *seq, void *v, loff_t *pos) 36static void *x25_seq_route_next(struct seq_file *seq, void *v, loff_t *pos)
53{ 37{
54 struct x25_route *rt; 38 return seq_list_next(v, &x25_route_list, pos);
55
56 ++*pos;
57 if (v == SEQ_START_TOKEN) {
58 rt = NULL;
59 if (!list_empty(&x25_route_list))
60 rt = list_entry(x25_route_list.next,
61 struct x25_route, node);
62 goto out;
63 }
64 rt = v;
65 if (rt->node.next != &x25_route_list)
66 rt = list_entry(rt->node.next, struct x25_route, node);
67 else
68 rt = NULL;
69out:
70 return rt;
71} 39}
72 40
73static void x25_seq_route_stop(struct seq_file *seq, void *v) 41static void x25_seq_route_stop(struct seq_file *seq, void *v)
@@ -78,9 +46,9 @@ static void x25_seq_route_stop(struct seq_file *seq, void *v)
78 46
79static int x25_seq_route_show(struct seq_file *seq, void *v) 47static int x25_seq_route_show(struct seq_file *seq, void *v)
80{ 48{
81 struct x25_route *rt; 49 struct x25_route *rt = list_entry(v, struct x25_route, node);
82 50
83 if (v == SEQ_START_TOKEN) { 51 if (v == &x25_route_list) {
84 seq_puts(seq, "Address Digits Device\n"); 52 seq_puts(seq, "Address Digits Device\n");
85 goto out; 53 goto out;
86 } 54 }
@@ -93,40 +61,16 @@ out:
93 return 0; 61 return 0;
94} 62}
95 63
96static __inline__ struct sock *x25_get_socket_idx(loff_t pos)
97{
98 struct sock *s;
99 struct hlist_node *node;
100
101 sk_for_each(s, node, &x25_list)
102 if (!pos--)
103 goto found;
104 s = NULL;
105found:
106 return s;
107}
108
109static void *x25_seq_socket_start(struct seq_file *seq, loff_t *pos) 64static void *x25_seq_socket_start(struct seq_file *seq, loff_t *pos)
110 __acquires(x25_list_lock) 65 __acquires(x25_list_lock)
111{ 66{
112 loff_t l = *pos;
113
114 read_lock_bh(&x25_list_lock); 67 read_lock_bh(&x25_list_lock);
115 return l ? x25_get_socket_idx(--l) : SEQ_START_TOKEN; 68 return seq_hlist_start_head(&x25_list, *pos);
116} 69}
117 70
118static void *x25_seq_socket_next(struct seq_file *seq, void *v, loff_t *pos) 71static void *x25_seq_socket_next(struct seq_file *seq, void *v, loff_t *pos)
119{ 72{
120 struct sock *s; 73 return seq_hlist_next(v, &x25_list, pos);
121
122 ++*pos;
123 if (v == SEQ_START_TOKEN) {
124 s = sk_head(&x25_list);
125 goto out;
126 }
127 s = sk_next(v);
128out:
129 return s;
130} 74}
131 75
132static void x25_seq_socket_stop(struct seq_file *seq, void *v) 76static void x25_seq_socket_stop(struct seq_file *seq, void *v)
@@ -148,7 +92,7 @@ static int x25_seq_socket_show(struct seq_file *seq, void *v)
148 goto out; 92 goto out;
149 } 93 }
150 94
151 s = v; 95 s = sk_entry(v);
152 x25 = x25_sk(s); 96 x25 = x25_sk(s);
153 97
154 if (!x25->neighbour || (dev = x25->neighbour->dev) == NULL) 98 if (!x25->neighbour || (dev = x25->neighbour->dev) == NULL)
@@ -170,51 +114,16 @@ out:
170 return 0; 114 return 0;
171} 115}
172 116
173static __inline__ struct x25_forward *x25_get_forward_idx(loff_t pos)
174{
175 struct x25_forward *f;
176 struct list_head *entry;
177
178 list_for_each(entry, &x25_forward_list) {
179 f = list_entry(entry, struct x25_forward, node);
180 if (!pos--)
181 goto found;
182 }
183
184 f = NULL;
185found:
186 return f;
187}
188
189static void *x25_seq_forward_start(struct seq_file *seq, loff_t *pos) 117static void *x25_seq_forward_start(struct seq_file *seq, loff_t *pos)
190 __acquires(x25_forward_list_lock) 118 __acquires(x25_forward_list_lock)
191{ 119{
192 loff_t l = *pos;
193
194 read_lock_bh(&x25_forward_list_lock); 120 read_lock_bh(&x25_forward_list_lock);
195 return l ? x25_get_forward_idx(--l) : SEQ_START_TOKEN; 121 return seq_list_start_head(&x25_forward_list, *pos);
196} 122}
197 123
198static void *x25_seq_forward_next(struct seq_file *seq, void *v, loff_t *pos) 124static void *x25_seq_forward_next(struct seq_file *seq, void *v, loff_t *pos)
199{ 125{
200 struct x25_forward *f; 126 return seq_list_next(v, &x25_forward_list, pos);
201
202 ++*pos;
203 if (v == SEQ_START_TOKEN) {
204 f = NULL;
205 if (!list_empty(&x25_forward_list))
206 f = list_entry(x25_forward_list.next,
207 struct x25_forward, node);
208 goto out;
209 }
210 f = v;
211 if (f->node.next != &x25_forward_list)
212 f = list_entry(f->node.next, struct x25_forward, node);
213 else
214 f = NULL;
215out:
216 return f;
217
218} 127}
219 128
220static void x25_seq_forward_stop(struct seq_file *seq, void *v) 129static void x25_seq_forward_stop(struct seq_file *seq, void *v)
@@ -225,9 +134,9 @@ static void x25_seq_forward_stop(struct seq_file *seq, void *v)
225 134
226static int x25_seq_forward_show(struct seq_file *seq, void *v) 135static int x25_seq_forward_show(struct seq_file *seq, void *v)
227{ 136{
228 struct x25_forward *f; 137 struct x25_forward *f = list_entry(v, struct x25_forward, node);
229 138
230 if (v == SEQ_START_TOKEN) { 139 if (v == &x25_forward_list) {
231 seq_printf(seq, "lci dev1 dev2\n"); 140 seq_printf(seq, "lci dev1 dev2\n");
232 goto out; 141 goto out;
233 } 142 }
@@ -236,7 +145,6 @@ static int x25_seq_forward_show(struct seq_file *seq, void *v)
236 145
237 seq_printf(seq, "%d %-10s %-10s\n", 146 seq_printf(seq, "%d %-10s %-10s\n",
238 f->lci, f->dev1->name, f->dev2->name); 147 f->lci, f->dev1->name, f->dev2->name);
239
240out: 148out:
241 return 0; 149 return 0;
242} 150}
diff --git a/net/x25/x25_route.c b/net/x25/x25_route.c
index 2c999ccf504a..97d77c532d8c 100644
--- a/net/x25/x25_route.c
+++ b/net/x25/x25_route.c
@@ -19,6 +19,7 @@
19 19
20#include <linux/if_arp.h> 20#include <linux/if_arp.h>
21#include <linux/init.h> 21#include <linux/init.h>
22#include <linux/slab.h>
22#include <net/x25.h> 23#include <net/x25.h>
23 24
24LIST_HEAD(x25_route_list); 25LIST_HEAD(x25_route_list);
@@ -136,8 +137,10 @@ struct net_device *x25_dev_get(char *devname)
136#if defined(CONFIG_LLC) || defined(CONFIG_LLC_MODULE) 137#if defined(CONFIG_LLC) || defined(CONFIG_LLC_MODULE)
137 && dev->type != ARPHRD_ETHER 138 && dev->type != ARPHRD_ETHER
138#endif 139#endif
139 ))) 140 ))){
140 dev_put(dev); 141 dev_put(dev);
142 dev = NULL;
143 }
141 144
142 return dev; 145 return dev;
143} 146}
@@ -190,7 +193,7 @@ int x25_route_ioctl(unsigned int cmd, void __user *arg)
190 goto out; 193 goto out;
191 194
192 rc = -EINVAL; 195 rc = -EINVAL;
193 if (rt.sigdigits < 0 || rt.sigdigits > 15) 196 if (rt.sigdigits > 15)
194 goto out; 197 goto out;
195 198
196 dev = x25_dev_get(rt.device); 199 dev = x25_dev_get(rt.device);
diff --git a/net/x25/x25_subr.c b/net/x25/x25_subr.c
index 511a5986af3e..dc20cf12f39b 100644
--- a/net/x25/x25_subr.c
+++ b/net/x25/x25_subr.c
@@ -23,6 +23,7 @@
23 * restriction on response. 23 * restriction on response.
24 */ 24 */
25 25
26#include <linux/slab.h>
26#include <linux/kernel.h> 27#include <linux/kernel.h>
27#include <linux/string.h> 28#include <linux/string.h>
28#include <linux/skbuff.h> 29#include <linux/skbuff.h>
@@ -225,6 +226,12 @@ void x25_write_internal(struct sock *sk, int frametype)
225 break; 226 break;
226 227
227 case X25_CLEAR_REQUEST: 228 case X25_CLEAR_REQUEST:
229 dptr = skb_put(skb, 3);
230 *dptr++ = frametype;
231 *dptr++ = x25->causediag.cause;
232 *dptr++ = x25->causediag.diagnostic;
233 break;
234
228 case X25_RESET_REQUEST: 235 case X25_RESET_REQUEST:
229 dptr = skb_put(skb, 3); 236 dptr = skb_put(skb, 3);
230 *dptr++ = frametype; 237 *dptr++ = frametype;
diff --git a/net/xfrm/xfrm_algo.c b/net/xfrm/xfrm_algo.c
index faf54c6bf96b..8b4d6e3246e5 100644
--- a/net/xfrm/xfrm_algo.c
+++ b/net/xfrm/xfrm_algo.c
@@ -125,6 +125,22 @@ static struct xfrm_algo_desc aead_list[] = {
125 .sadb_alg_maxbits = 256 125 .sadb_alg_maxbits = 256
126 } 126 }
127}, 127},
128{
129 .name = "rfc4543(gcm(aes))",
130
131 .uinfo = {
132 .aead = {
133 .icv_truncbits = 128,
134 }
135 },
136
137 .desc = {
138 .sadb_alg_id = SADB_X_EALG_NULL_AES_GMAC,
139 .sadb_alg_ivlen = 8,
140 .sadb_alg_minbits = 128,
141 .sadb_alg_maxbits = 256
142 }
143},
128}; 144};
129 145
130static struct xfrm_algo_desc aalg_list[] = { 146static struct xfrm_algo_desc aalg_list[] = {
@@ -200,6 +216,40 @@ static struct xfrm_algo_desc aalg_list[] = {
200 } 216 }
201}, 217},
202{ 218{
219 .name = "hmac(sha384)",
220
221 .uinfo = {
222 .auth = {
223 .icv_truncbits = 192,
224 .icv_fullbits = 384,
225 }
226 },
227
228 .desc = {
229 .sadb_alg_id = SADB_X_AALG_SHA2_384HMAC,
230 .sadb_alg_ivlen = 0,
231 .sadb_alg_minbits = 384,
232 .sadb_alg_maxbits = 384
233 }
234},
235{
236 .name = "hmac(sha512)",
237
238 .uinfo = {
239 .auth = {
240 .icv_truncbits = 256,
241 .icv_fullbits = 512,
242 }
243 },
244
245 .desc = {
246 .sadb_alg_id = SADB_X_AALG_SHA2_512HMAC,
247 .sadb_alg_ivlen = 0,
248 .sadb_alg_minbits = 512,
249 .sadb_alg_maxbits = 512
250 }
251},
252{
203 .name = "hmac(rmd160)", 253 .name = "hmac(rmd160)",
204 .compat = "rmd160", 254 .compat = "rmd160",
205 255
@@ -365,6 +415,7 @@ static struct xfrm_algo_desc ealg_list[] = {
365}, 415},
366{ 416{
367 .name = "cbc(camellia)", 417 .name = "cbc(camellia)",
418 .compat = "camellia",
368 419
369 .uinfo = { 420 .uinfo = {
370 .encr = { 421 .encr = {
@@ -689,84 +740,6 @@ int xfrm_count_enc_supported(void)
689} 740}
690EXPORT_SYMBOL_GPL(xfrm_count_enc_supported); 741EXPORT_SYMBOL_GPL(xfrm_count_enc_supported);
691 742
692/* Move to common area: it is shared with AH. */
693
694int skb_icv_walk(const struct sk_buff *skb, struct hash_desc *desc,
695 int offset, int len, icv_update_fn_t icv_update)
696{
697 int start = skb_headlen(skb);
698 int i, copy = start - offset;
699 struct sk_buff *frag_iter;
700 struct scatterlist sg;
701 int err;
702
703 /* Checksum header. */
704 if (copy > 0) {
705 if (copy > len)
706 copy = len;
707
708 sg_init_one(&sg, skb->data + offset, copy);
709
710 err = icv_update(desc, &sg, copy);
711 if (unlikely(err))
712 return err;
713
714 if ((len -= copy) == 0)
715 return 0;
716 offset += copy;
717 }
718
719 for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
720 int end;
721
722 WARN_ON(start > offset + len);
723
724 end = start + skb_shinfo(skb)->frags[i].size;
725 if ((copy = end - offset) > 0) {
726 skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
727
728 if (copy > len)
729 copy = len;
730
731 sg_init_table(&sg, 1);
732 sg_set_page(&sg, frag->page, copy,
733 frag->page_offset + offset-start);
734
735 err = icv_update(desc, &sg, copy);
736 if (unlikely(err))
737 return err;
738
739 if (!(len -= copy))
740 return 0;
741 offset += copy;
742 }
743 start = end;
744 }
745
746 skb_walk_frags(skb, frag_iter) {
747 int end;
748
749 WARN_ON(start > offset + len);
750
751 end = start + frag_iter->len;
752 if ((copy = end - offset) > 0) {
753 if (copy > len)
754 copy = len;
755 err = skb_icv_walk(frag_iter, desc, offset-start,
756 copy, icv_update);
757 if (unlikely(err))
758 return err;
759 if ((len -= copy) == 0)
760 return 0;
761 offset += copy;
762 }
763 start = end;
764 }
765 BUG_ON(len);
766 return 0;
767}
768EXPORT_SYMBOL_GPL(skb_icv_walk);
769
770#if defined(CONFIG_INET_ESP) || defined(CONFIG_INET_ESP_MODULE) || defined(CONFIG_INET6_ESP) || defined(CONFIG_INET6_ESP_MODULE) 743#if defined(CONFIG_INET_ESP) || defined(CONFIG_INET_ESP_MODULE) || defined(CONFIG_INET6_ESP) || defined(CONFIG_INET6_ESP_MODULE)
771 744
772void *pskb_put(struct sk_buff *skb, struct sk_buff *tail, int len) 745void *pskb_put(struct sk_buff *skb, struct sk_buff *tail, int len)
diff --git a/net/xfrm/xfrm_input.c b/net/xfrm/xfrm_input.c
index e0009c17d809..45f1c98d4fce 100644
--- a/net/xfrm/xfrm_input.c
+++ b/net/xfrm/xfrm_input.c
@@ -152,7 +152,7 @@ int xfrm_input(struct sk_buff *skb, int nexthdr, __be32 spi, int encap_type)
152 goto drop; 152 goto drop;
153 } 153 }
154 154
155 x = xfrm_state_lookup(net, daddr, spi, nexthdr, family); 155 x = xfrm_state_lookup(net, skb->mark, daddr, spi, nexthdr, family);
156 if (x == NULL) { 156 if (x == NULL) {
157 XFRM_INC_STATS(net, LINUX_MIB_XFRMINNOSTATES); 157 XFRM_INC_STATS(net, LINUX_MIB_XFRMINNOSTATES);
158 xfrm_audit_state_notfound(skb, family, spi, seq); 158 xfrm_audit_state_notfound(skb, family, spi, seq);
diff --git a/net/xfrm/xfrm_ipcomp.c b/net/xfrm/xfrm_ipcomp.c
index 42cd18391f46..fc91ad7ee26e 100644
--- a/net/xfrm/xfrm_ipcomp.c
+++ b/net/xfrm/xfrm_ipcomp.c
@@ -17,11 +17,11 @@
17 17
18#include <linux/crypto.h> 18#include <linux/crypto.h>
19#include <linux/err.h> 19#include <linux/err.h>
20#include <linux/gfp.h>
21#include <linux/list.h> 20#include <linux/list.h>
22#include <linux/module.h> 21#include <linux/module.h>
23#include <linux/mutex.h> 22#include <linux/mutex.h>
24#include <linux/percpu.h> 23#include <linux/percpu.h>
24#include <linux/slab.h>
25#include <linux/smp.h> 25#include <linux/smp.h>
26#include <linux/vmalloc.h> 26#include <linux/vmalloc.h>
27#include <net/ip.h> 27#include <net/ip.h>
@@ -30,12 +30,12 @@
30 30
31struct ipcomp_tfms { 31struct ipcomp_tfms {
32 struct list_head list; 32 struct list_head list;
33 struct crypto_comp **tfms; 33 struct crypto_comp * __percpu *tfms;
34 int users; 34 int users;
35}; 35};
36 36
37static DEFINE_MUTEX(ipcomp_resource_mutex); 37static DEFINE_MUTEX(ipcomp_resource_mutex);
38static void **ipcomp_scratches; 38static void * __percpu *ipcomp_scratches;
39static int ipcomp_scratch_users; 39static int ipcomp_scratch_users;
40static LIST_HEAD(ipcomp_tfms_list); 40static LIST_HEAD(ipcomp_tfms_list);
41 41
@@ -200,7 +200,7 @@ EXPORT_SYMBOL_GPL(ipcomp_output);
200static void ipcomp_free_scratches(void) 200static void ipcomp_free_scratches(void)
201{ 201{
202 int i; 202 int i;
203 void **scratches; 203 void * __percpu *scratches;
204 204
205 if (--ipcomp_scratch_users) 205 if (--ipcomp_scratch_users)
206 return; 206 return;
@@ -215,10 +215,10 @@ static void ipcomp_free_scratches(void)
215 free_percpu(scratches); 215 free_percpu(scratches);
216} 216}
217 217
218static void **ipcomp_alloc_scratches(void) 218static void * __percpu *ipcomp_alloc_scratches(void)
219{ 219{
220 int i; 220 int i;
221 void **scratches; 221 void * __percpu *scratches;
222 222
223 if (ipcomp_scratch_users++) 223 if (ipcomp_scratch_users++)
224 return ipcomp_scratches; 224 return ipcomp_scratches;
@@ -239,7 +239,7 @@ static void **ipcomp_alloc_scratches(void)
239 return scratches; 239 return scratches;
240} 240}
241 241
242static void ipcomp_free_tfms(struct crypto_comp **tfms) 242static void ipcomp_free_tfms(struct crypto_comp * __percpu *tfms)
243{ 243{
244 struct ipcomp_tfms *pos; 244 struct ipcomp_tfms *pos;
245 int cpu; 245 int cpu;
@@ -267,10 +267,10 @@ static void ipcomp_free_tfms(struct crypto_comp **tfms)
267 free_percpu(tfms); 267 free_percpu(tfms);
268} 268}
269 269
270static struct crypto_comp **ipcomp_alloc_tfms(const char *alg_name) 270static struct crypto_comp * __percpu *ipcomp_alloc_tfms(const char *alg_name)
271{ 271{
272 struct ipcomp_tfms *pos; 272 struct ipcomp_tfms *pos;
273 struct crypto_comp **tfms; 273 struct crypto_comp * __percpu *tfms;
274 int cpu; 274 int cpu;
275 275
276 /* This can be any valid CPU ID so we don't need locking. */ 276 /* This can be any valid CPU ID so we don't need locking. */
diff --git a/net/xfrm/xfrm_output.c b/net/xfrm/xfrm_output.c
index b9fe13138c07..6a329158bdfa 100644
--- a/net/xfrm/xfrm_output.c
+++ b/net/xfrm/xfrm_output.c
@@ -14,6 +14,7 @@
14#include <linux/netdevice.h> 14#include <linux/netdevice.h>
15#include <linux/netfilter.h> 15#include <linux/netfilter.h>
16#include <linux/skbuff.h> 16#include <linux/skbuff.h>
17#include <linux/slab.h>
17#include <linux/spinlock.h> 18#include <linux/spinlock.h>
18#include <net/dst.h> 19#include <net/dst.h>
19#include <net/xfrm.h> 20#include <net/xfrm.h>
diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
index cb81ca35b0d6..843e066649cb 100644
--- a/net/xfrm/xfrm_policy.c
+++ b/net/xfrm/xfrm_policy.c
@@ -469,16 +469,16 @@ static inline int xfrm_byidx_should_resize(struct net *net, int total)
469 return 0; 469 return 0;
470} 470}
471 471
472void xfrm_spd_getinfo(struct xfrmk_spdinfo *si) 472void xfrm_spd_getinfo(struct net *net, struct xfrmk_spdinfo *si)
473{ 473{
474 read_lock_bh(&xfrm_policy_lock); 474 read_lock_bh(&xfrm_policy_lock);
475 si->incnt = init_net.xfrm.policy_count[XFRM_POLICY_IN]; 475 si->incnt = net->xfrm.policy_count[XFRM_POLICY_IN];
476 si->outcnt = init_net.xfrm.policy_count[XFRM_POLICY_OUT]; 476 si->outcnt = net->xfrm.policy_count[XFRM_POLICY_OUT];
477 si->fwdcnt = init_net.xfrm.policy_count[XFRM_POLICY_FWD]; 477 si->fwdcnt = net->xfrm.policy_count[XFRM_POLICY_FWD];
478 si->inscnt = init_net.xfrm.policy_count[XFRM_POLICY_IN+XFRM_POLICY_MAX]; 478 si->inscnt = net->xfrm.policy_count[XFRM_POLICY_IN+XFRM_POLICY_MAX];
479 si->outscnt = init_net.xfrm.policy_count[XFRM_POLICY_OUT+XFRM_POLICY_MAX]; 479 si->outscnt = net->xfrm.policy_count[XFRM_POLICY_OUT+XFRM_POLICY_MAX];
480 si->fwdscnt = init_net.xfrm.policy_count[XFRM_POLICY_FWD+XFRM_POLICY_MAX]; 480 si->fwdscnt = net->xfrm.policy_count[XFRM_POLICY_FWD+XFRM_POLICY_MAX];
481 si->spdhcnt = init_net.xfrm.policy_idx_hmask; 481 si->spdhcnt = net->xfrm.policy_idx_hmask;
482 si->spdhmcnt = xfrm_policy_hashmax; 482 si->spdhmcnt = xfrm_policy_hashmax;
483 read_unlock_bh(&xfrm_policy_lock); 483 read_unlock_bh(&xfrm_policy_lock);
484} 484}
@@ -556,6 +556,7 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl)
556 struct hlist_head *chain; 556 struct hlist_head *chain;
557 struct hlist_node *entry, *newpos; 557 struct hlist_node *entry, *newpos;
558 struct dst_entry *gc_list; 558 struct dst_entry *gc_list;
559 u32 mark = policy->mark.v & policy->mark.m;
559 560
560 write_lock_bh(&xfrm_policy_lock); 561 write_lock_bh(&xfrm_policy_lock);
561 chain = policy_hash_bysel(net, &policy->selector, policy->family, dir); 562 chain = policy_hash_bysel(net, &policy->selector, policy->family, dir);
@@ -564,6 +565,7 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl)
564 hlist_for_each_entry(pol, entry, chain, bydst) { 565 hlist_for_each_entry(pol, entry, chain, bydst) {
565 if (pol->type == policy->type && 566 if (pol->type == policy->type &&
566 !selector_cmp(&pol->selector, &policy->selector) && 567 !selector_cmp(&pol->selector, &policy->selector) &&
568 (mark & pol->mark.m) == pol->mark.v &&
567 xfrm_sec_ctx_match(pol->security, policy->security) && 569 xfrm_sec_ctx_match(pol->security, policy->security) &&
568 !WARN_ON(delpol)) { 570 !WARN_ON(delpol)) {
569 if (excl) { 571 if (excl) {
@@ -635,8 +637,8 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl)
635} 637}
636EXPORT_SYMBOL(xfrm_policy_insert); 638EXPORT_SYMBOL(xfrm_policy_insert);
637 639
638struct xfrm_policy *xfrm_policy_bysel_ctx(struct net *net, u8 type, int dir, 640struct xfrm_policy *xfrm_policy_bysel_ctx(struct net *net, u32 mark, u8 type,
639 struct xfrm_selector *sel, 641 int dir, struct xfrm_selector *sel,
640 struct xfrm_sec_ctx *ctx, int delete, 642 struct xfrm_sec_ctx *ctx, int delete,
641 int *err) 643 int *err)
642{ 644{
@@ -650,6 +652,7 @@ struct xfrm_policy *xfrm_policy_bysel_ctx(struct net *net, u8 type, int dir,
650 ret = NULL; 652 ret = NULL;
651 hlist_for_each_entry(pol, entry, chain, bydst) { 653 hlist_for_each_entry(pol, entry, chain, bydst) {
652 if (pol->type == type && 654 if (pol->type == type &&
655 (mark & pol->mark.m) == pol->mark.v &&
653 !selector_cmp(sel, &pol->selector) && 656 !selector_cmp(sel, &pol->selector) &&
654 xfrm_sec_ctx_match(ctx, pol->security)) { 657 xfrm_sec_ctx_match(ctx, pol->security)) {
655 xfrm_pol_hold(pol); 658 xfrm_pol_hold(pol);
@@ -676,8 +679,8 @@ struct xfrm_policy *xfrm_policy_bysel_ctx(struct net *net, u8 type, int dir,
676} 679}
677EXPORT_SYMBOL(xfrm_policy_bysel_ctx); 680EXPORT_SYMBOL(xfrm_policy_bysel_ctx);
678 681
679struct xfrm_policy *xfrm_policy_byid(struct net *net, u8 type, int dir, u32 id, 682struct xfrm_policy *xfrm_policy_byid(struct net *net, u32 mark, u8 type,
680 int delete, int *err) 683 int dir, u32 id, int delete, int *err)
681{ 684{
682 struct xfrm_policy *pol, *ret; 685 struct xfrm_policy *pol, *ret;
683 struct hlist_head *chain; 686 struct hlist_head *chain;
@@ -692,7 +695,8 @@ struct xfrm_policy *xfrm_policy_byid(struct net *net, u8 type, int dir, u32 id,
692 chain = net->xfrm.policy_byidx + idx_hash(net, id); 695 chain = net->xfrm.policy_byidx + idx_hash(net, id);
693 ret = NULL; 696 ret = NULL;
694 hlist_for_each_entry(pol, entry, chain, byidx) { 697 hlist_for_each_entry(pol, entry, chain, byidx) {
695 if (pol->type == type && pol->index == id) { 698 if (pol->type == type && pol->index == id &&
699 (mark & pol->mark.m) == pol->mark.v) {
696 xfrm_pol_hold(pol); 700 xfrm_pol_hold(pol);
697 if (delete) { 701 if (delete) {
698 *err = security_xfrm_policy_delete( 702 *err = security_xfrm_policy_delete(
@@ -771,7 +775,8 @@ xfrm_policy_flush_secctx_check(struct net *net, u8 type, struct xfrm_audit *audi
771 775
772int xfrm_policy_flush(struct net *net, u8 type, struct xfrm_audit *audit_info) 776int xfrm_policy_flush(struct net *net, u8 type, struct xfrm_audit *audit_info)
773{ 777{
774 int dir, err = 0; 778 int dir, err = 0, cnt = 0;
779 struct xfrm_policy *dp;
775 780
776 write_lock_bh(&xfrm_policy_lock); 781 write_lock_bh(&xfrm_policy_lock);
777 782
@@ -789,8 +794,10 @@ int xfrm_policy_flush(struct net *net, u8 type, struct xfrm_audit *audit_info)
789 &net->xfrm.policy_inexact[dir], bydst) { 794 &net->xfrm.policy_inexact[dir], bydst) {
790 if (pol->type != type) 795 if (pol->type != type)
791 continue; 796 continue;
792 __xfrm_policy_unlink(pol, dir); 797 dp = __xfrm_policy_unlink(pol, dir);
793 write_unlock_bh(&xfrm_policy_lock); 798 write_unlock_bh(&xfrm_policy_lock);
799 if (dp)
800 cnt++;
794 801
795 xfrm_audit_policy_delete(pol, 1, audit_info->loginuid, 802 xfrm_audit_policy_delete(pol, 1, audit_info->loginuid,
796 audit_info->sessionid, 803 audit_info->sessionid,
@@ -809,8 +816,10 @@ int xfrm_policy_flush(struct net *net, u8 type, struct xfrm_audit *audit_info)
809 bydst) { 816 bydst) {
810 if (pol->type != type) 817 if (pol->type != type)
811 continue; 818 continue;
812 __xfrm_policy_unlink(pol, dir); 819 dp = __xfrm_policy_unlink(pol, dir);
813 write_unlock_bh(&xfrm_policy_lock); 820 write_unlock_bh(&xfrm_policy_lock);
821 if (dp)
822 cnt++;
814 823
815 xfrm_audit_policy_delete(pol, 1, 824 xfrm_audit_policy_delete(pol, 1,
816 audit_info->loginuid, 825 audit_info->loginuid,
@@ -824,6 +833,8 @@ int xfrm_policy_flush(struct net *net, u8 type, struct xfrm_audit *audit_info)
824 } 833 }
825 834
826 } 835 }
836 if (!cnt)
837 err = -ESRCH;
827 atomic_inc(&flow_cache_genid); 838 atomic_inc(&flow_cache_genid);
828out: 839out:
829 write_unlock_bh(&xfrm_policy_lock); 840 write_unlock_bh(&xfrm_policy_lock);
@@ -909,6 +920,7 @@ static int xfrm_policy_match(struct xfrm_policy *pol, struct flowi *fl,
909 int match, ret = -ESRCH; 920 int match, ret = -ESRCH;
910 921
911 if (pol->family != family || 922 if (pol->family != family ||
923 (fl->mark & pol->mark.m) != pol->mark.v ||
912 pol->type != type) 924 pol->type != type)
913 return ret; 925 return ret;
914 926
@@ -1033,6 +1045,10 @@ static struct xfrm_policy *xfrm_sk_policy_lookup(struct sock *sk, int dir, struc
1033 int err = 0; 1045 int err = 0;
1034 1046
1035 if (match) { 1047 if (match) {
1048 if ((sk->sk_mark & pol->mark.m) != pol->mark.v) {
1049 pol = NULL;
1050 goto out;
1051 }
1036 err = security_xfrm_policy_lookup(pol->security, 1052 err = security_xfrm_policy_lookup(pol->security,
1037 fl->secid, 1053 fl->secid,
1038 policy_to_flow_dir(dir)); 1054 policy_to_flow_dir(dir));
@@ -1045,6 +1061,7 @@ static struct xfrm_policy *xfrm_sk_policy_lookup(struct sock *sk, int dir, struc
1045 } else 1061 } else
1046 pol = NULL; 1062 pol = NULL;
1047 } 1063 }
1064out:
1048 read_unlock_bh(&xfrm_policy_lock); 1065 read_unlock_bh(&xfrm_policy_lock);
1049 return pol; 1066 return pol;
1050} 1067}
@@ -1137,6 +1154,7 @@ static struct xfrm_policy *clone_policy(struct xfrm_policy *old, int dir)
1137 } 1154 }
1138 newp->lft = old->lft; 1155 newp->lft = old->lft;
1139 newp->curlft = old->curlft; 1156 newp->curlft = old->curlft;
1157 newp->mark = old->mark;
1140 newp->action = old->action; 1158 newp->action = old->action;
1141 newp->flags = old->flags; 1159 newp->flags = old->flags;
1142 newp->xfrm_nr = old->xfrm_nr; 1160 newp->xfrm_nr = old->xfrm_nr;
@@ -1309,15 +1327,28 @@ static inline int xfrm_get_tos(struct flowi *fl, int family)
1309 return tos; 1327 return tos;
1310} 1328}
1311 1329
1312static inline struct xfrm_dst *xfrm_alloc_dst(int family) 1330static inline struct xfrm_dst *xfrm_alloc_dst(struct net *net, int family)
1313{ 1331{
1314 struct xfrm_policy_afinfo *afinfo = xfrm_policy_get_afinfo(family); 1332 struct xfrm_policy_afinfo *afinfo = xfrm_policy_get_afinfo(family);
1333 struct dst_ops *dst_ops;
1315 struct xfrm_dst *xdst; 1334 struct xfrm_dst *xdst;
1316 1335
1317 if (!afinfo) 1336 if (!afinfo)
1318 return ERR_PTR(-EINVAL); 1337 return ERR_PTR(-EINVAL);
1319 1338
1320 xdst = dst_alloc(afinfo->dst_ops) ?: ERR_PTR(-ENOBUFS); 1339 switch (family) {
1340 case AF_INET:
1341 dst_ops = &net->xfrm.xfrm4_dst_ops;
1342 break;
1343#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
1344 case AF_INET6:
1345 dst_ops = &net->xfrm.xfrm6_dst_ops;
1346 break;
1347#endif
1348 default:
1349 BUG();
1350 }
1351 xdst = dst_alloc(dst_ops) ?: ERR_PTR(-ENOBUFS);
1321 1352
1322 xfrm_policy_put_afinfo(afinfo); 1353 xfrm_policy_put_afinfo(afinfo);
1323 1354
@@ -1341,7 +1372,8 @@ static inline int xfrm_init_path(struct xfrm_dst *path, struct dst_entry *dst,
1341 return err; 1372 return err;
1342} 1373}
1343 1374
1344static inline int xfrm_fill_dst(struct xfrm_dst *xdst, struct net_device *dev) 1375static inline int xfrm_fill_dst(struct xfrm_dst *xdst, struct net_device *dev,
1376 struct flowi *fl)
1345{ 1377{
1346 struct xfrm_policy_afinfo *afinfo = 1378 struct xfrm_policy_afinfo *afinfo =
1347 xfrm_policy_get_afinfo(xdst->u.dst.ops->family); 1379 xfrm_policy_get_afinfo(xdst->u.dst.ops->family);
@@ -1350,7 +1382,7 @@ static inline int xfrm_fill_dst(struct xfrm_dst *xdst, struct net_device *dev)
1350 if (!afinfo) 1382 if (!afinfo)
1351 return -EINVAL; 1383 return -EINVAL;
1352 1384
1353 err = afinfo->fill_dst(xdst, dev); 1385 err = afinfo->fill_dst(xdst, dev, fl);
1354 1386
1355 xfrm_policy_put_afinfo(afinfo); 1387 xfrm_policy_put_afinfo(afinfo);
1356 1388
@@ -1366,6 +1398,7 @@ static struct dst_entry *xfrm_bundle_create(struct xfrm_policy *policy,
1366 struct flowi *fl, 1398 struct flowi *fl,
1367 struct dst_entry *dst) 1399 struct dst_entry *dst)
1368{ 1400{
1401 struct net *net = xp_net(policy);
1369 unsigned long now = jiffies; 1402 unsigned long now = jiffies;
1370 struct net_device *dev; 1403 struct net_device *dev;
1371 struct dst_entry *dst_prev = NULL; 1404 struct dst_entry *dst_prev = NULL;
@@ -1389,7 +1422,7 @@ static struct dst_entry *xfrm_bundle_create(struct xfrm_policy *policy,
1389 dst_hold(dst); 1422 dst_hold(dst);
1390 1423
1391 for (; i < nx; i++) { 1424 for (; i < nx; i++) {
1392 struct xfrm_dst *xdst = xfrm_alloc_dst(family); 1425 struct xfrm_dst *xdst = xfrm_alloc_dst(net, family);
1393 struct dst_entry *dst1 = &xdst->u.dst; 1426 struct dst_entry *dst1 = &xdst->u.dst;
1394 1427
1395 err = PTR_ERR(xdst); 1428 err = PTR_ERR(xdst);
@@ -1445,7 +1478,7 @@ static struct dst_entry *xfrm_bundle_create(struct xfrm_policy *policy,
1445 if (!dev) 1478 if (!dev)
1446 goto free_dst; 1479 goto free_dst;
1447 1480
1448 /* Copy neighbout for reachability confirmation */ 1481 /* Copy neighbour for reachability confirmation */
1449 dst0->neighbour = neigh_clone(dst->neighbour); 1482 dst0->neighbour = neigh_clone(dst->neighbour);
1450 1483
1451 xfrm_init_path((struct xfrm_dst *)dst0, dst, nfheader_len); 1484 xfrm_init_path((struct xfrm_dst *)dst0, dst, nfheader_len);
@@ -1454,7 +1487,7 @@ static struct dst_entry *xfrm_bundle_create(struct xfrm_policy *policy,
1454 for (dst_prev = dst0; dst_prev != dst; dst_prev = dst_prev->child) { 1487 for (dst_prev = dst0; dst_prev != dst; dst_prev = dst_prev->child) {
1455 struct xfrm_dst *xdst = (struct xfrm_dst *)dst_prev; 1488 struct xfrm_dst *xdst = (struct xfrm_dst *)dst_prev;
1456 1489
1457 err = xfrm_fill_dst(xdst, dev); 1490 err = xfrm_fill_dst(xdst, dev, fl);
1458 if (err) 1491 if (err)
1459 goto free_dst; 1492 goto free_dst;
1460 1493
@@ -2031,8 +2064,7 @@ int __xfrm_route_forward(struct sk_buff *skb, unsigned short family)
2031 int res; 2064 int res;
2032 2065
2033 if (xfrm_decode_session(skb, &fl, family) < 0) { 2066 if (xfrm_decode_session(skb, &fl, family) < 0) {
2034 /* XXX: we should have something like FWDHDRERROR here. */ 2067 XFRM_INC_STATS(net, LINUX_MIB_XFRMFWDHDRERROR);
2035 XFRM_INC_STATS(net, LINUX_MIB_XFRMINHDRERROR);
2036 return 0; 2068 return 0;
2037 } 2069 }
2038 2070
@@ -2279,6 +2311,7 @@ EXPORT_SYMBOL(xfrm_bundle_ok);
2279 2311
2280int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo) 2312int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo)
2281{ 2313{
2314 struct net *net;
2282 int err = 0; 2315 int err = 0;
2283 if (unlikely(afinfo == NULL)) 2316 if (unlikely(afinfo == NULL))
2284 return -EINVAL; 2317 return -EINVAL;
@@ -2302,6 +2335,27 @@ int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo)
2302 xfrm_policy_afinfo[afinfo->family] = afinfo; 2335 xfrm_policy_afinfo[afinfo->family] = afinfo;
2303 } 2336 }
2304 write_unlock_bh(&xfrm_policy_afinfo_lock); 2337 write_unlock_bh(&xfrm_policy_afinfo_lock);
2338
2339 rtnl_lock();
2340 for_each_net(net) {
2341 struct dst_ops *xfrm_dst_ops;
2342
2343 switch (afinfo->family) {
2344 case AF_INET:
2345 xfrm_dst_ops = &net->xfrm.xfrm4_dst_ops;
2346 break;
2347#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
2348 case AF_INET6:
2349 xfrm_dst_ops = &net->xfrm.xfrm6_dst_ops;
2350 break;
2351#endif
2352 default:
2353 BUG();
2354 }
2355 *xfrm_dst_ops = *afinfo->dst_ops;
2356 }
2357 rtnl_unlock();
2358
2305 return err; 2359 return err;
2306} 2360}
2307EXPORT_SYMBOL(xfrm_policy_register_afinfo); 2361EXPORT_SYMBOL(xfrm_policy_register_afinfo);
@@ -2332,6 +2386,22 @@ int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo)
2332} 2386}
2333EXPORT_SYMBOL(xfrm_policy_unregister_afinfo); 2387EXPORT_SYMBOL(xfrm_policy_unregister_afinfo);
2334 2388
2389static void __net_init xfrm_dst_ops_init(struct net *net)
2390{
2391 struct xfrm_policy_afinfo *afinfo;
2392
2393 read_lock_bh(&xfrm_policy_afinfo_lock);
2394 afinfo = xfrm_policy_afinfo[AF_INET];
2395 if (afinfo)
2396 net->xfrm.xfrm4_dst_ops = *afinfo->dst_ops;
2397#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
2398 afinfo = xfrm_policy_afinfo[AF_INET6];
2399 if (afinfo)
2400 net->xfrm.xfrm6_dst_ops = *afinfo->dst_ops;
2401#endif
2402 read_unlock_bh(&xfrm_policy_afinfo_lock);
2403}
2404
2335static struct xfrm_policy_afinfo *xfrm_policy_get_afinfo(unsigned short family) 2405static struct xfrm_policy_afinfo *xfrm_policy_get_afinfo(unsigned short family)
2336{ 2406{
2337 struct xfrm_policy_afinfo *afinfo; 2407 struct xfrm_policy_afinfo *afinfo;
@@ -2369,19 +2439,19 @@ static int __net_init xfrm_statistics_init(struct net *net)
2369{ 2439{
2370 int rv; 2440 int rv;
2371 2441
2372 if (snmp_mib_init((void **)net->mib.xfrm_statistics, 2442 if (snmp_mib_init((void __percpu **)net->mib.xfrm_statistics,
2373 sizeof(struct linux_xfrm_mib)) < 0) 2443 sizeof(struct linux_xfrm_mib)) < 0)
2374 return -ENOMEM; 2444 return -ENOMEM;
2375 rv = xfrm_proc_init(net); 2445 rv = xfrm_proc_init(net);
2376 if (rv < 0) 2446 if (rv < 0)
2377 snmp_mib_free((void **)net->mib.xfrm_statistics); 2447 snmp_mib_free((void __percpu **)net->mib.xfrm_statistics);
2378 return rv; 2448 return rv;
2379} 2449}
2380 2450
2381static void xfrm_statistics_fini(struct net *net) 2451static void xfrm_statistics_fini(struct net *net)
2382{ 2452{
2383 xfrm_proc_fini(net); 2453 xfrm_proc_fini(net);
2384 snmp_mib_free((void **)net->mib.xfrm_statistics); 2454 snmp_mib_free((void __percpu **)net->mib.xfrm_statistics);
2385} 2455}
2386#else 2456#else
2387static int __net_init xfrm_statistics_init(struct net *net) 2457static int __net_init xfrm_statistics_init(struct net *net)
@@ -2494,6 +2564,7 @@ static int __net_init xfrm_net_init(struct net *net)
2494 rv = xfrm_policy_init(net); 2564 rv = xfrm_policy_init(net);
2495 if (rv < 0) 2565 if (rv < 0)
2496 goto out_policy; 2566 goto out_policy;
2567 xfrm_dst_ops_init(net);
2497 rv = xfrm_sysctl_init(net); 2568 rv = xfrm_sysctl_init(net);
2498 if (rv < 0) 2569 if (rv < 0)
2499 goto out_sysctl; 2570 goto out_sysctl;
diff --git a/net/xfrm/xfrm_proc.c b/net/xfrm/xfrm_proc.c
index fef8db553e8d..58d9ae005597 100644
--- a/net/xfrm/xfrm_proc.c
+++ b/net/xfrm/xfrm_proc.c
@@ -15,7 +15,7 @@
15#include <net/snmp.h> 15#include <net/snmp.h>
16#include <net/xfrm.h> 16#include <net/xfrm.h>
17 17
18static struct snmp_mib xfrm_mib_list[] = { 18static const struct snmp_mib xfrm_mib_list[] = {
19 SNMP_MIB_ITEM("XfrmInError", LINUX_MIB_XFRMINERROR), 19 SNMP_MIB_ITEM("XfrmInError", LINUX_MIB_XFRMINERROR),
20 SNMP_MIB_ITEM("XfrmInBufferError", LINUX_MIB_XFRMINBUFFERERROR), 20 SNMP_MIB_ITEM("XfrmInBufferError", LINUX_MIB_XFRMINBUFFERERROR),
21 SNMP_MIB_ITEM("XfrmInHdrError", LINUX_MIB_XFRMINHDRERROR), 21 SNMP_MIB_ITEM("XfrmInHdrError", LINUX_MIB_XFRMINHDRERROR),
@@ -41,6 +41,7 @@ static struct snmp_mib xfrm_mib_list[] = {
41 SNMP_MIB_ITEM("XfrmOutPolBlock", LINUX_MIB_XFRMOUTPOLBLOCK), 41 SNMP_MIB_ITEM("XfrmOutPolBlock", LINUX_MIB_XFRMOUTPOLBLOCK),
42 SNMP_MIB_ITEM("XfrmOutPolDead", LINUX_MIB_XFRMOUTPOLDEAD), 42 SNMP_MIB_ITEM("XfrmOutPolDead", LINUX_MIB_XFRMOUTPOLDEAD),
43 SNMP_MIB_ITEM("XfrmOutPolError", LINUX_MIB_XFRMOUTPOLERROR), 43 SNMP_MIB_ITEM("XfrmOutPolError", LINUX_MIB_XFRMOUTPOLERROR),
44 SNMP_MIB_ITEM("XfrmFwdHdrError", LINUX_MIB_XFRMFWDHDRERROR),
44 SNMP_MIB_SENTINEL 45 SNMP_MIB_SENTINEL
45}; 46};
46 47
@@ -50,7 +51,8 @@ static int xfrm_statistics_seq_show(struct seq_file *seq, void *v)
50 int i; 51 int i;
51 for (i=0; xfrm_mib_list[i].name; i++) 52 for (i=0; xfrm_mib_list[i].name; i++)
52 seq_printf(seq, "%-24s\t%lu\n", xfrm_mib_list[i].name, 53 seq_printf(seq, "%-24s\t%lu\n", xfrm_mib_list[i].name,
53 snmp_fold_field((void **)net->mib.xfrm_statistics, 54 snmp_fold_field((void __percpu **)
55 net->mib.xfrm_statistics,
54 xfrm_mib_list[i].entry)); 56 xfrm_mib_list[i].entry));
55 return 0; 57 return 0;
56} 58}
diff --git a/net/xfrm/xfrm_state.c b/net/xfrm/xfrm_state.c
index f2f7c638083e..add77ecb8ac4 100644
--- a/net/xfrm/xfrm_state.c
+++ b/net/xfrm/xfrm_state.c
@@ -21,6 +21,10 @@
21#include <linux/cache.h> 21#include <linux/cache.h>
22#include <linux/audit.h> 22#include <linux/audit.h>
23#include <asm/uaccess.h> 23#include <asm/uaccess.h>
24#include <linux/ktime.h>
25#include <linux/slab.h>
26#include <linux/interrupt.h>
27#include <linux/kernel.h>
24 28
25#include "xfrm_hash.h" 29#include "xfrm_hash.h"
26 30
@@ -352,7 +356,7 @@ static void xfrm_put_mode(struct xfrm_mode *mode)
352 356
353static void xfrm_state_gc_destroy(struct xfrm_state *x) 357static void xfrm_state_gc_destroy(struct xfrm_state *x)
354{ 358{
355 del_timer_sync(&x->timer); 359 tasklet_hrtimer_cancel(&x->mtimer);
356 del_timer_sync(&x->rtimer); 360 del_timer_sync(&x->rtimer);
357 kfree(x->aalg); 361 kfree(x->aalg);
358 kfree(x->ealg); 362 kfree(x->ealg);
@@ -398,9 +402,10 @@ static inline unsigned long make_jiffies(long secs)
398 return secs*HZ; 402 return secs*HZ;
399} 403}
400 404
401static void xfrm_timer_handler(unsigned long data) 405static enum hrtimer_restart xfrm_timer_handler(struct hrtimer * me)
402{ 406{
403 struct xfrm_state *x = (struct xfrm_state*)data; 407 struct tasklet_hrtimer *thr = container_of(me, struct tasklet_hrtimer, timer);
408 struct xfrm_state *x = container_of(thr, struct xfrm_state, mtimer);
404 struct net *net = xs_net(x); 409 struct net *net = xs_net(x);
405 unsigned long now = get_seconds(); 410 unsigned long now = get_seconds();
406 long next = LONG_MAX; 411 long next = LONG_MAX;
@@ -451,8 +456,9 @@ static void xfrm_timer_handler(unsigned long data)
451 if (warn) 456 if (warn)
452 km_state_expired(x, 0, 0); 457 km_state_expired(x, 0, 0);
453resched: 458resched:
454 if (next != LONG_MAX) 459 if (next != LONG_MAX){
455 mod_timer(&x->timer, jiffies + make_jiffies(next)); 460 tasklet_hrtimer_start(&x->mtimer, ktime_set(next, 0), HRTIMER_MODE_REL);
461 }
456 462
457 goto out; 463 goto out;
458 464
@@ -474,6 +480,7 @@ expired:
474 480
475out: 481out:
476 spin_unlock(&x->lock); 482 spin_unlock(&x->lock);
483 return HRTIMER_NORESTART;
477} 484}
478 485
479static void xfrm_replay_timer_handler(unsigned long data); 486static void xfrm_replay_timer_handler(unsigned long data);
@@ -492,7 +499,7 @@ struct xfrm_state *xfrm_state_alloc(struct net *net)
492 INIT_HLIST_NODE(&x->bydst); 499 INIT_HLIST_NODE(&x->bydst);
493 INIT_HLIST_NODE(&x->bysrc); 500 INIT_HLIST_NODE(&x->bysrc);
494 INIT_HLIST_NODE(&x->byspi); 501 INIT_HLIST_NODE(&x->byspi);
495 setup_timer(&x->timer, xfrm_timer_handler, (unsigned long)x); 502 tasklet_hrtimer_init(&x->mtimer, xfrm_timer_handler, CLOCK_REALTIME, HRTIMER_MODE_ABS);
496 setup_timer(&x->rtimer, xfrm_replay_timer_handler, 503 setup_timer(&x->rtimer, xfrm_replay_timer_handler,
497 (unsigned long)x); 504 (unsigned long)x);
498 x->curlft.add_time = get_seconds(); 505 x->curlft.add_time = get_seconds();
@@ -597,13 +604,14 @@ xfrm_state_flush_secctx_check(struct net *net, u8 proto, struct xfrm_audit *audi
597 604
598int xfrm_state_flush(struct net *net, u8 proto, struct xfrm_audit *audit_info) 605int xfrm_state_flush(struct net *net, u8 proto, struct xfrm_audit *audit_info)
599{ 606{
600 int i, err = 0; 607 int i, err = 0, cnt = 0;
601 608
602 spin_lock_bh(&xfrm_state_lock); 609 spin_lock_bh(&xfrm_state_lock);
603 err = xfrm_state_flush_secctx_check(net, proto, audit_info); 610 err = xfrm_state_flush_secctx_check(net, proto, audit_info);
604 if (err) 611 if (err)
605 goto out; 612 goto out;
606 613
614 err = -ESRCH;
607 for (i = 0; i <= net->xfrm.state_hmask; i++) { 615 for (i = 0; i <= net->xfrm.state_hmask; i++) {
608 struct hlist_node *entry; 616 struct hlist_node *entry;
609 struct xfrm_state *x; 617 struct xfrm_state *x;
@@ -620,13 +628,16 @@ restart:
620 audit_info->sessionid, 628 audit_info->sessionid,
621 audit_info->secid); 629 audit_info->secid);
622 xfrm_state_put(x); 630 xfrm_state_put(x);
631 if (!err)
632 cnt++;
623 633
624 spin_lock_bh(&xfrm_state_lock); 634 spin_lock_bh(&xfrm_state_lock);
625 goto restart; 635 goto restart;
626 } 636 }
627 } 637 }
628 } 638 }
629 err = 0; 639 if (cnt)
640 err = 0;
630 641
631out: 642out:
632 spin_unlock_bh(&xfrm_state_lock); 643 spin_unlock_bh(&xfrm_state_lock);
@@ -635,11 +646,11 @@ out:
635} 646}
636EXPORT_SYMBOL(xfrm_state_flush); 647EXPORT_SYMBOL(xfrm_state_flush);
637 648
638void xfrm_sad_getinfo(struct xfrmk_sadinfo *si) 649void xfrm_sad_getinfo(struct net *net, struct xfrmk_sadinfo *si)
639{ 650{
640 spin_lock_bh(&xfrm_state_lock); 651 spin_lock_bh(&xfrm_state_lock);
641 si->sadcnt = init_net.xfrm.state_num; 652 si->sadcnt = net->xfrm.state_num;
642 si->sadhcnt = init_net.xfrm.state_hmask; 653 si->sadhcnt = net->xfrm.state_hmask;
643 si->sadhmcnt = xfrm_state_hashmax; 654 si->sadhmcnt = xfrm_state_hashmax;
644 spin_unlock_bh(&xfrm_state_lock); 655 spin_unlock_bh(&xfrm_state_lock);
645} 656}
@@ -659,7 +670,7 @@ xfrm_init_tempsel(struct xfrm_state *x, struct flowi *fl,
659 return 0; 670 return 0;
660} 671}
661 672
662static struct xfrm_state *__xfrm_state_lookup(struct net *net, xfrm_address_t *daddr, __be32 spi, u8 proto, unsigned short family) 673static struct xfrm_state *__xfrm_state_lookup(struct net *net, u32 mark, xfrm_address_t *daddr, __be32 spi, u8 proto, unsigned short family)
663{ 674{
664 unsigned int h = xfrm_spi_hash(net, daddr, spi, proto, family); 675 unsigned int h = xfrm_spi_hash(net, daddr, spi, proto, family);
665 struct xfrm_state *x; 676 struct xfrm_state *x;
@@ -672,6 +683,8 @@ static struct xfrm_state *__xfrm_state_lookup(struct net *net, xfrm_address_t *d
672 xfrm_addr_cmp(&x->id.daddr, daddr, family)) 683 xfrm_addr_cmp(&x->id.daddr, daddr, family))
673 continue; 684 continue;
674 685
686 if ((mark & x->mark.m) != x->mark.v)
687 continue;
675 xfrm_state_hold(x); 688 xfrm_state_hold(x);
676 return x; 689 return x;
677 } 690 }
@@ -679,7 +692,7 @@ static struct xfrm_state *__xfrm_state_lookup(struct net *net, xfrm_address_t *d
679 return NULL; 692 return NULL;
680} 693}
681 694
682static struct xfrm_state *__xfrm_state_lookup_byaddr(struct net *net, xfrm_address_t *daddr, xfrm_address_t *saddr, u8 proto, unsigned short family) 695static struct xfrm_state *__xfrm_state_lookup_byaddr(struct net *net, u32 mark, xfrm_address_t *daddr, xfrm_address_t *saddr, u8 proto, unsigned short family)
683{ 696{
684 unsigned int h = xfrm_src_hash(net, daddr, saddr, family); 697 unsigned int h = xfrm_src_hash(net, daddr, saddr, family);
685 struct xfrm_state *x; 698 struct xfrm_state *x;
@@ -692,6 +705,8 @@ static struct xfrm_state *__xfrm_state_lookup_byaddr(struct net *net, xfrm_addre
692 xfrm_addr_cmp(&x->props.saddr, saddr, family)) 705 xfrm_addr_cmp(&x->props.saddr, saddr, family))
693 continue; 706 continue;
694 707
708 if ((mark & x->mark.m) != x->mark.v)
709 continue;
695 xfrm_state_hold(x); 710 xfrm_state_hold(x);
696 return x; 711 return x;
697 } 712 }
@@ -703,12 +718,14 @@ static inline struct xfrm_state *
703__xfrm_state_locate(struct xfrm_state *x, int use_spi, int family) 718__xfrm_state_locate(struct xfrm_state *x, int use_spi, int family)
704{ 719{
705 struct net *net = xs_net(x); 720 struct net *net = xs_net(x);
721 u32 mark = x->mark.v & x->mark.m;
706 722
707 if (use_spi) 723 if (use_spi)
708 return __xfrm_state_lookup(net, &x->id.daddr, x->id.spi, 724 return __xfrm_state_lookup(net, mark, &x->id.daddr,
709 x->id.proto, family); 725 x->id.spi, x->id.proto, family);
710 else 726 else
711 return __xfrm_state_lookup_byaddr(net, &x->id.daddr, 727 return __xfrm_state_lookup_byaddr(net, mark,
728 &x->id.daddr,
712 &x->props.saddr, 729 &x->props.saddr,
713 x->id.proto, family); 730 x->id.proto, family);
714} 731}
@@ -773,6 +790,7 @@ xfrm_state_find(xfrm_address_t *daddr, xfrm_address_t *saddr,
773 int acquire_in_progress = 0; 790 int acquire_in_progress = 0;
774 int error = 0; 791 int error = 0;
775 struct xfrm_state *best = NULL; 792 struct xfrm_state *best = NULL;
793 u32 mark = pol->mark.v & pol->mark.m;
776 794
777 to_put = NULL; 795 to_put = NULL;
778 796
@@ -781,6 +799,7 @@ xfrm_state_find(xfrm_address_t *daddr, xfrm_address_t *saddr,
781 hlist_for_each_entry(x, entry, net->xfrm.state_bydst+h, bydst) { 799 hlist_for_each_entry(x, entry, net->xfrm.state_bydst+h, bydst) {
782 if (x->props.family == family && 800 if (x->props.family == family &&
783 x->props.reqid == tmpl->reqid && 801 x->props.reqid == tmpl->reqid &&
802 (mark & x->mark.m) == x->mark.v &&
784 !(x->props.flags & XFRM_STATE_WILDRECV) && 803 !(x->props.flags & XFRM_STATE_WILDRECV) &&
785 xfrm_state_addr_check(x, daddr, saddr, family) && 804 xfrm_state_addr_check(x, daddr, saddr, family) &&
786 tmpl->mode == x->props.mode && 805 tmpl->mode == x->props.mode &&
@@ -796,6 +815,7 @@ xfrm_state_find(xfrm_address_t *daddr, xfrm_address_t *saddr,
796 hlist_for_each_entry(x, entry, net->xfrm.state_bydst+h_wildcard, bydst) { 815 hlist_for_each_entry(x, entry, net->xfrm.state_bydst+h_wildcard, bydst) {
797 if (x->props.family == family && 816 if (x->props.family == family &&
798 x->props.reqid == tmpl->reqid && 817 x->props.reqid == tmpl->reqid &&
818 (mark & x->mark.m) == x->mark.v &&
799 !(x->props.flags & XFRM_STATE_WILDRECV) && 819 !(x->props.flags & XFRM_STATE_WILDRECV) &&
800 xfrm_state_addr_check(x, daddr, saddr, family) && 820 xfrm_state_addr_check(x, daddr, saddr, family) &&
801 tmpl->mode == x->props.mode && 821 tmpl->mode == x->props.mode &&
@@ -809,7 +829,7 @@ found:
809 x = best; 829 x = best;
810 if (!x && !error && !acquire_in_progress) { 830 if (!x && !error && !acquire_in_progress) {
811 if (tmpl->id.spi && 831 if (tmpl->id.spi &&
812 (x0 = __xfrm_state_lookup(net, daddr, tmpl->id.spi, 832 (x0 = __xfrm_state_lookup(net, mark, daddr, tmpl->id.spi,
813 tmpl->id.proto, family)) != NULL) { 833 tmpl->id.proto, family)) != NULL) {
814 to_put = x0; 834 to_put = x0;
815 error = -EEXIST; 835 error = -EEXIST;
@@ -823,6 +843,7 @@ found:
823 /* Initialize temporary selector matching only 843 /* Initialize temporary selector matching only
824 * to current session. */ 844 * to current session. */
825 xfrm_init_tempsel(x, fl, tmpl, daddr, saddr, family); 845 xfrm_init_tempsel(x, fl, tmpl, daddr, saddr, family);
846 memcpy(&x->mark, &pol->mark, sizeof(x->mark));
826 847
827 error = security_xfrm_state_alloc_acquire(x, pol->security, fl->secid); 848 error = security_xfrm_state_alloc_acquire(x, pol->security, fl->secid);
828 if (error) { 849 if (error) {
@@ -843,8 +864,7 @@ found:
843 hlist_add_head(&x->byspi, net->xfrm.state_byspi+h); 864 hlist_add_head(&x->byspi, net->xfrm.state_byspi+h);
844 } 865 }
845 x->lft.hard_add_expires_seconds = net->xfrm.sysctl_acq_expires; 866 x->lft.hard_add_expires_seconds = net->xfrm.sysctl_acq_expires;
846 x->timer.expires = jiffies + net->xfrm.sysctl_acq_expires*HZ; 867 tasklet_hrtimer_start(&x->mtimer, ktime_set(net->xfrm.sysctl_acq_expires, 0), HRTIMER_MODE_REL);
847 add_timer(&x->timer);
848 net->xfrm.state_num++; 868 net->xfrm.state_num++;
849 xfrm_hash_grow_check(net, x->bydst.next != NULL); 869 xfrm_hash_grow_check(net, x->bydst.next != NULL);
850 } else { 870 } else {
@@ -866,7 +886,7 @@ out:
866} 886}
867 887
868struct xfrm_state * 888struct xfrm_state *
869xfrm_stateonly_find(struct net *net, 889xfrm_stateonly_find(struct net *net, u32 mark,
870 xfrm_address_t *daddr, xfrm_address_t *saddr, 890 xfrm_address_t *daddr, xfrm_address_t *saddr,
871 unsigned short family, u8 mode, u8 proto, u32 reqid) 891 unsigned short family, u8 mode, u8 proto, u32 reqid)
872{ 892{
@@ -879,6 +899,7 @@ xfrm_stateonly_find(struct net *net,
879 hlist_for_each_entry(x, entry, net->xfrm.state_bydst+h, bydst) { 899 hlist_for_each_entry(x, entry, net->xfrm.state_bydst+h, bydst) {
880 if (x->props.family == family && 900 if (x->props.family == family &&
881 x->props.reqid == reqid && 901 x->props.reqid == reqid &&
902 (mark & x->mark.m) == x->mark.v &&
882 !(x->props.flags & XFRM_STATE_WILDRECV) && 903 !(x->props.flags & XFRM_STATE_WILDRECV) &&
883 xfrm_state_addr_check(x, daddr, saddr, family) && 904 xfrm_state_addr_check(x, daddr, saddr, family) &&
884 mode == x->props.mode && 905 mode == x->props.mode &&
@@ -921,7 +942,7 @@ static void __xfrm_state_insert(struct xfrm_state *x)
921 hlist_add_head(&x->byspi, net->xfrm.state_byspi+h); 942 hlist_add_head(&x->byspi, net->xfrm.state_byspi+h);
922 } 943 }
923 944
924 mod_timer(&x->timer, jiffies + HZ); 945 tasklet_hrtimer_start(&x->mtimer, ktime_set(1, 0), HRTIMER_MODE_REL);
925 if (x->replay_maxage) 946 if (x->replay_maxage)
926 mod_timer(&x->rtimer, jiffies + x->replay_maxage); 947 mod_timer(&x->rtimer, jiffies + x->replay_maxage);
927 948
@@ -941,11 +962,13 @@ static void __xfrm_state_bump_genids(struct xfrm_state *xnew)
941 struct xfrm_state *x; 962 struct xfrm_state *x;
942 struct hlist_node *entry; 963 struct hlist_node *entry;
943 unsigned int h; 964 unsigned int h;
965 u32 mark = xnew->mark.v & xnew->mark.m;
944 966
945 h = xfrm_dst_hash(net, &xnew->id.daddr, &xnew->props.saddr, reqid, family); 967 h = xfrm_dst_hash(net, &xnew->id.daddr, &xnew->props.saddr, reqid, family);
946 hlist_for_each_entry(x, entry, net->xfrm.state_bydst+h, bydst) { 968 hlist_for_each_entry(x, entry, net->xfrm.state_bydst+h, bydst) {
947 if (x->props.family == family && 969 if (x->props.family == family &&
948 x->props.reqid == reqid && 970 x->props.reqid == reqid &&
971 (mark & x->mark.m) == x->mark.v &&
949 !xfrm_addr_cmp(&x->id.daddr, &xnew->id.daddr, family) && 972 !xfrm_addr_cmp(&x->id.daddr, &xnew->id.daddr, family) &&
950 !xfrm_addr_cmp(&x->props.saddr, &xnew->props.saddr, family)) 973 !xfrm_addr_cmp(&x->props.saddr, &xnew->props.saddr, family))
951 x->genid = xfrm_state_genid; 974 x->genid = xfrm_state_genid;
@@ -962,11 +985,12 @@ void xfrm_state_insert(struct xfrm_state *x)
962EXPORT_SYMBOL(xfrm_state_insert); 985EXPORT_SYMBOL(xfrm_state_insert);
963 986
964/* xfrm_state_lock is held */ 987/* xfrm_state_lock is held */
965static 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) 988static struct xfrm_state *__find_acq_core(struct net *net, struct xfrm_mark *m, unsigned short family, u8 mode, u32 reqid, u8 proto, xfrm_address_t *daddr, xfrm_address_t *saddr, int create)
966{ 989{
967 unsigned int h = xfrm_dst_hash(net, daddr, saddr, reqid, family); 990 unsigned int h = xfrm_dst_hash(net, daddr, saddr, reqid, family);
968 struct hlist_node *entry; 991 struct hlist_node *entry;
969 struct xfrm_state *x; 992 struct xfrm_state *x;
993 u32 mark = m->v & m->m;
970 994
971 hlist_for_each_entry(x, entry, net->xfrm.state_bydst+h, bydst) { 995 hlist_for_each_entry(x, entry, net->xfrm.state_bydst+h, bydst) {
972 if (x->props.reqid != reqid || 996 if (x->props.reqid != reqid ||
@@ -975,6 +999,7 @@ static struct xfrm_state *__find_acq_core(struct net *net, unsigned short family
975 x->km.state != XFRM_STATE_ACQ || 999 x->km.state != XFRM_STATE_ACQ ||
976 x->id.spi != 0 || 1000 x->id.spi != 0 ||
977 x->id.proto != proto || 1001 x->id.proto != proto ||
1002 (mark & x->mark.m) != x->mark.v ||
978 xfrm_addr_cmp(&x->id.daddr, daddr, family) || 1003 xfrm_addr_cmp(&x->id.daddr, daddr, family) ||
979 xfrm_addr_cmp(&x->props.saddr, saddr, family)) 1004 xfrm_addr_cmp(&x->props.saddr, saddr, family))
980 continue; 1005 continue;
@@ -1017,10 +1042,11 @@ static struct xfrm_state *__find_acq_core(struct net *net, unsigned short family
1017 x->props.family = family; 1042 x->props.family = family;
1018 x->props.mode = mode; 1043 x->props.mode = mode;
1019 x->props.reqid = reqid; 1044 x->props.reqid = reqid;
1045 x->mark.v = m->v;
1046 x->mark.m = m->m;
1020 x->lft.hard_add_expires_seconds = net->xfrm.sysctl_acq_expires; 1047 x->lft.hard_add_expires_seconds = net->xfrm.sysctl_acq_expires;
1021 xfrm_state_hold(x); 1048 xfrm_state_hold(x);
1022 x->timer.expires = jiffies + net->xfrm.sysctl_acq_expires*HZ; 1049 tasklet_hrtimer_start(&x->mtimer, ktime_set(net->xfrm.sysctl_acq_expires, 0), HRTIMER_MODE_REL);
1023 add_timer(&x->timer);
1024 list_add(&x->km.all, &net->xfrm.state_all); 1050 list_add(&x->km.all, &net->xfrm.state_all);
1025 hlist_add_head(&x->bydst, net->xfrm.state_bydst+h); 1051 hlist_add_head(&x->bydst, net->xfrm.state_bydst+h);
1026 h = xfrm_src_hash(net, daddr, saddr, family); 1052 h = xfrm_src_hash(net, daddr, saddr, family);
@@ -1034,7 +1060,7 @@ static struct xfrm_state *__find_acq_core(struct net *net, unsigned short family
1034 return x; 1060 return x;
1035} 1061}
1036 1062
1037static struct xfrm_state *__xfrm_find_acq_byseq(struct net *net, u32 seq); 1063static struct xfrm_state *__xfrm_find_acq_byseq(struct net *net, u32 mark, u32 seq);
1038 1064
1039int xfrm_state_add(struct xfrm_state *x) 1065int xfrm_state_add(struct xfrm_state *x)
1040{ 1066{
@@ -1042,6 +1068,7 @@ int xfrm_state_add(struct xfrm_state *x)
1042 struct xfrm_state *x1, *to_put; 1068 struct xfrm_state *x1, *to_put;
1043 int family; 1069 int family;
1044 int err; 1070 int err;
1071 u32 mark = x->mark.v & x->mark.m;
1045 int use_spi = xfrm_id_proto_match(x->id.proto, IPSEC_PROTO_ANY); 1072 int use_spi = xfrm_id_proto_match(x->id.proto, IPSEC_PROTO_ANY);
1046 1073
1047 family = x->props.family; 1074 family = x->props.family;
@@ -1059,7 +1086,7 @@ int xfrm_state_add(struct xfrm_state *x)
1059 } 1086 }
1060 1087
1061 if (use_spi && x->km.seq) { 1088 if (use_spi && x->km.seq) {
1062 x1 = __xfrm_find_acq_byseq(net, x->km.seq); 1089 x1 = __xfrm_find_acq_byseq(net, mark, x->km.seq);
1063 if (x1 && ((x1->id.proto != x->id.proto) || 1090 if (x1 && ((x1->id.proto != x->id.proto) ||
1064 xfrm_addr_cmp(&x1->id.daddr, &x->id.daddr, family))) { 1091 xfrm_addr_cmp(&x1->id.daddr, &x->id.daddr, family))) {
1065 to_put = x1; 1092 to_put = x1;
@@ -1068,8 +1095,8 @@ int xfrm_state_add(struct xfrm_state *x)
1068 } 1095 }
1069 1096
1070 if (use_spi && !x1) 1097 if (use_spi && !x1)
1071 x1 = __find_acq_core(net, family, x->props.mode, x->props.reqid, 1098 x1 = __find_acq_core(net, &x->mark, family, x->props.mode,
1072 x->id.proto, 1099 x->props.reqid, x->id.proto,
1073 &x->id.daddr, &x->props.saddr, 0); 1100 &x->id.daddr, &x->props.saddr, 0);
1074 1101
1075 __xfrm_state_bump_genids(x); 1102 __xfrm_state_bump_genids(x);
@@ -1098,7 +1125,7 @@ static struct xfrm_state *xfrm_state_clone(struct xfrm_state *orig, int *errp)
1098 int err = -ENOMEM; 1125 int err = -ENOMEM;
1099 struct xfrm_state *x = xfrm_state_alloc(net); 1126 struct xfrm_state *x = xfrm_state_alloc(net);
1100 if (!x) 1127 if (!x)
1101 goto error; 1128 goto out;
1102 1129
1103 memcpy(&x->id, &orig->id, sizeof(x->id)); 1130 memcpy(&x->id, &orig->id, sizeof(x->id));
1104 memcpy(&x->sel, &orig->sel, sizeof(x->sel)); 1131 memcpy(&x->sel, &orig->sel, sizeof(x->sel));
@@ -1110,7 +1137,7 @@ static struct xfrm_state *xfrm_state_clone(struct xfrm_state *orig, int *errp)
1110 x->props.saddr = orig->props.saddr; 1137 x->props.saddr = orig->props.saddr;
1111 1138
1112 if (orig->aalg) { 1139 if (orig->aalg) {
1113 x->aalg = xfrm_algo_clone(orig->aalg); 1140 x->aalg = xfrm_algo_auth_clone(orig->aalg);
1114 if (!x->aalg) 1141 if (!x->aalg)
1115 goto error; 1142 goto error;
1116 } 1143 }
@@ -1143,6 +1170,8 @@ static struct xfrm_state *xfrm_state_clone(struct xfrm_state *orig, int *errp)
1143 goto error; 1170 goto error;
1144 } 1171 }
1145 1172
1173 memcpy(&x->mark, &orig->mark, sizeof(x->mark));
1174
1146 err = xfrm_init_state(x); 1175 err = xfrm_init_state(x);
1147 if (err) 1176 if (err)
1148 goto error; 1177 goto error;
@@ -1156,16 +1185,10 @@ static struct xfrm_state *xfrm_state_clone(struct xfrm_state *orig, int *errp)
1156 return x; 1185 return x;
1157 1186
1158 error: 1187 error:
1188 xfrm_state_put(x);
1189out:
1159 if (errp) 1190 if (errp)
1160 *errp = err; 1191 *errp = err;
1161 if (x) {
1162 kfree(x->aalg);
1163 kfree(x->ealg);
1164 kfree(x->calg);
1165 kfree(x->encap);
1166 kfree(x->coaddr);
1167 }
1168 kfree(x);
1169 return NULL; 1192 return NULL;
1170} 1193}
1171 1194
@@ -1300,7 +1323,7 @@ out:
1300 memcpy(&x1->lft, &x->lft, sizeof(x1->lft)); 1323 memcpy(&x1->lft, &x->lft, sizeof(x1->lft));
1301 x1->km.dying = 0; 1324 x1->km.dying = 0;
1302 1325
1303 mod_timer(&x1->timer, jiffies + HZ); 1326 tasklet_hrtimer_start(&x1->mtimer, ktime_set(1, 0), HRTIMER_MODE_REL);
1304 if (x1->curlft.use_time) 1327 if (x1->curlft.use_time)
1305 xfrm_state_check_expire(x1); 1328 xfrm_state_check_expire(x1);
1306 1329
@@ -1325,7 +1348,7 @@ int xfrm_state_check_expire(struct xfrm_state *x)
1325 if (x->curlft.bytes >= x->lft.hard_byte_limit || 1348 if (x->curlft.bytes >= x->lft.hard_byte_limit ||
1326 x->curlft.packets >= x->lft.hard_packet_limit) { 1349 x->curlft.packets >= x->lft.hard_packet_limit) {
1327 x->km.state = XFRM_STATE_EXPIRED; 1350 x->km.state = XFRM_STATE_EXPIRED;
1328 mod_timer(&x->timer, jiffies); 1351 tasklet_hrtimer_start(&x->mtimer, ktime_set(0,0), HRTIMER_MODE_REL);
1329 return -EINVAL; 1352 return -EINVAL;
1330 } 1353 }
1331 1354
@@ -1340,41 +1363,41 @@ int xfrm_state_check_expire(struct xfrm_state *x)
1340EXPORT_SYMBOL(xfrm_state_check_expire); 1363EXPORT_SYMBOL(xfrm_state_check_expire);
1341 1364
1342struct xfrm_state * 1365struct xfrm_state *
1343xfrm_state_lookup(struct net *net, xfrm_address_t *daddr, __be32 spi, u8 proto, 1366xfrm_state_lookup(struct net *net, u32 mark, xfrm_address_t *daddr, __be32 spi,
1344 unsigned short family) 1367 u8 proto, unsigned short family)
1345{ 1368{
1346 struct xfrm_state *x; 1369 struct xfrm_state *x;
1347 1370
1348 spin_lock_bh(&xfrm_state_lock); 1371 spin_lock_bh(&xfrm_state_lock);
1349 x = __xfrm_state_lookup(net, daddr, spi, proto, family); 1372 x = __xfrm_state_lookup(net, mark, daddr, spi, proto, family);
1350 spin_unlock_bh(&xfrm_state_lock); 1373 spin_unlock_bh(&xfrm_state_lock);
1351 return x; 1374 return x;
1352} 1375}
1353EXPORT_SYMBOL(xfrm_state_lookup); 1376EXPORT_SYMBOL(xfrm_state_lookup);
1354 1377
1355struct xfrm_state * 1378struct xfrm_state *
1356xfrm_state_lookup_byaddr(struct net *net, 1379xfrm_state_lookup_byaddr(struct net *net, u32 mark,
1357 xfrm_address_t *daddr, xfrm_address_t *saddr, 1380 xfrm_address_t *daddr, xfrm_address_t *saddr,
1358 u8 proto, unsigned short family) 1381 u8 proto, unsigned short family)
1359{ 1382{
1360 struct xfrm_state *x; 1383 struct xfrm_state *x;
1361 1384
1362 spin_lock_bh(&xfrm_state_lock); 1385 spin_lock_bh(&xfrm_state_lock);
1363 x = __xfrm_state_lookup_byaddr(net, daddr, saddr, proto, family); 1386 x = __xfrm_state_lookup_byaddr(net, mark, daddr, saddr, proto, family);
1364 spin_unlock_bh(&xfrm_state_lock); 1387 spin_unlock_bh(&xfrm_state_lock);
1365 return x; 1388 return x;
1366} 1389}
1367EXPORT_SYMBOL(xfrm_state_lookup_byaddr); 1390EXPORT_SYMBOL(xfrm_state_lookup_byaddr);
1368 1391
1369struct xfrm_state * 1392struct xfrm_state *
1370xfrm_find_acq(struct net *net, u8 mode, u32 reqid, u8 proto, 1393xfrm_find_acq(struct net *net, struct xfrm_mark *mark, u8 mode, u32 reqid, u8 proto,
1371 xfrm_address_t *daddr, xfrm_address_t *saddr, 1394 xfrm_address_t *daddr, xfrm_address_t *saddr,
1372 int create, unsigned short family) 1395 int create, unsigned short family)
1373{ 1396{
1374 struct xfrm_state *x; 1397 struct xfrm_state *x;
1375 1398
1376 spin_lock_bh(&xfrm_state_lock); 1399 spin_lock_bh(&xfrm_state_lock);
1377 x = __find_acq_core(net, family, mode, reqid, proto, daddr, saddr, create); 1400 x = __find_acq_core(net, mark, family, mode, reqid, proto, daddr, saddr, create);
1378 spin_unlock_bh(&xfrm_state_lock); 1401 spin_unlock_bh(&xfrm_state_lock);
1379 1402
1380 return x; 1403 return x;
@@ -1421,7 +1444,7 @@ EXPORT_SYMBOL(xfrm_state_sort);
1421 1444
1422/* Silly enough, but I'm lazy to build resolution list */ 1445/* Silly enough, but I'm lazy to build resolution list */
1423 1446
1424static struct xfrm_state *__xfrm_find_acq_byseq(struct net *net, u32 seq) 1447static struct xfrm_state *__xfrm_find_acq_byseq(struct net *net, u32 mark, u32 seq)
1425{ 1448{
1426 int i; 1449 int i;
1427 1450
@@ -1431,6 +1454,7 @@ static struct xfrm_state *__xfrm_find_acq_byseq(struct net *net, u32 seq)
1431 1454
1432 hlist_for_each_entry(x, entry, net->xfrm.state_bydst+i, bydst) { 1455 hlist_for_each_entry(x, entry, net->xfrm.state_bydst+i, bydst) {
1433 if (x->km.seq == seq && 1456 if (x->km.seq == seq &&
1457 (mark & x->mark.m) == x->mark.v &&
1434 x->km.state == XFRM_STATE_ACQ) { 1458 x->km.state == XFRM_STATE_ACQ) {
1435 xfrm_state_hold(x); 1459 xfrm_state_hold(x);
1436 return x; 1460 return x;
@@ -1440,12 +1464,12 @@ static struct xfrm_state *__xfrm_find_acq_byseq(struct net *net, u32 seq)
1440 return NULL; 1464 return NULL;
1441} 1465}
1442 1466
1443struct xfrm_state *xfrm_find_acq_byseq(struct net *net, u32 seq) 1467struct xfrm_state *xfrm_find_acq_byseq(struct net *net, u32 mark, u32 seq)
1444{ 1468{
1445 struct xfrm_state *x; 1469 struct xfrm_state *x;
1446 1470
1447 spin_lock_bh(&xfrm_state_lock); 1471 spin_lock_bh(&xfrm_state_lock);
1448 x = __xfrm_find_acq_byseq(net, seq); 1472 x = __xfrm_find_acq_byseq(net, mark, seq);
1449 spin_unlock_bh(&xfrm_state_lock); 1473 spin_unlock_bh(&xfrm_state_lock);
1450 return x; 1474 return x;
1451} 1475}
@@ -1454,12 +1478,12 @@ EXPORT_SYMBOL(xfrm_find_acq_byseq);
1454u32 xfrm_get_acqseq(void) 1478u32 xfrm_get_acqseq(void)
1455{ 1479{
1456 u32 res; 1480 u32 res;
1457 static u32 acqseq; 1481 static atomic_t acqseq;
1458 static DEFINE_SPINLOCK(acqseq_lock); 1482
1483 do {
1484 res = atomic_inc_return(&acqseq);
1485 } while (!res);
1459 1486
1460 spin_lock_bh(&acqseq_lock);
1461 res = (++acqseq ? : ++acqseq);
1462 spin_unlock_bh(&acqseq_lock);
1463 return res; 1487 return res;
1464} 1488}
1465EXPORT_SYMBOL(xfrm_get_acqseq); 1489EXPORT_SYMBOL(xfrm_get_acqseq);
@@ -1472,6 +1496,7 @@ int xfrm_alloc_spi(struct xfrm_state *x, u32 low, u32 high)
1472 int err = -ENOENT; 1496 int err = -ENOENT;
1473 __be32 minspi = htonl(low); 1497 __be32 minspi = htonl(low);
1474 __be32 maxspi = htonl(high); 1498 __be32 maxspi = htonl(high);
1499 u32 mark = x->mark.v & x->mark.m;
1475 1500
1476 spin_lock_bh(&x->lock); 1501 spin_lock_bh(&x->lock);
1477 if (x->km.state == XFRM_STATE_DEAD) 1502 if (x->km.state == XFRM_STATE_DEAD)
@@ -1484,7 +1509,7 @@ int xfrm_alloc_spi(struct xfrm_state *x, u32 low, u32 high)
1484 err = -ENOENT; 1509 err = -ENOENT;
1485 1510
1486 if (minspi == maxspi) { 1511 if (minspi == maxspi) {
1487 x0 = xfrm_state_lookup(net, &x->id.daddr, minspi, x->id.proto, x->props.family); 1512 x0 = xfrm_state_lookup(net, mark, &x->id.daddr, minspi, x->id.proto, x->props.family);
1488 if (x0) { 1513 if (x0) {
1489 xfrm_state_put(x0); 1514 xfrm_state_put(x0);
1490 goto unlock; 1515 goto unlock;
@@ -1494,7 +1519,7 @@ int xfrm_alloc_spi(struct xfrm_state *x, u32 low, u32 high)
1494 u32 spi = 0; 1519 u32 spi = 0;
1495 for (h=0; h<high-low+1; h++) { 1520 for (h=0; h<high-low+1; h++) {
1496 spi = low + net_random()%(high-low+1); 1521 spi = low + net_random()%(high-low+1);
1497 x0 = xfrm_state_lookup(net, &x->id.daddr, htonl(spi), x->id.proto, x->props.family); 1522 x0 = xfrm_state_lookup(net, mark, &x->id.daddr, htonl(spi), x->id.proto, x->props.family);
1498 if (x0 == NULL) { 1523 if (x0 == NULL) {
1499 x->id.spi = htonl(spi); 1524 x->id.spi = htonl(spi);
1500 break; 1525 break;
diff --git a/net/xfrm/xfrm_sysctl.c b/net/xfrm/xfrm_sysctl.c
index 2e6ffb66f06f..05640bc9594b 100644
--- a/net/xfrm/xfrm_sysctl.c
+++ b/net/xfrm/xfrm_sysctl.c
@@ -1,8 +1,9 @@
1#include <linux/sysctl.h> 1#include <linux/sysctl.h>
2#include <linux/slab.h>
2#include <net/net_namespace.h> 3#include <net/net_namespace.h>
3#include <net/xfrm.h> 4#include <net/xfrm.h>
4 5
5static void __xfrm_sysctl_init(struct net *net) 6static void __net_init __xfrm_sysctl_init(struct net *net)
6{ 7{
7 net->xfrm.sysctl_aevent_etime = XFRM_AE_ETIME; 8 net->xfrm.sysctl_aevent_etime = XFRM_AE_ETIME;
8 net->xfrm.sysctl_aevent_rseqth = XFRM_AE_SEQT_SIZE; 9 net->xfrm.sysctl_aevent_rseqth = XFRM_AE_SEQT_SIZE;
@@ -13,28 +14,24 @@ static void __xfrm_sysctl_init(struct net *net)
13#ifdef CONFIG_SYSCTL 14#ifdef CONFIG_SYSCTL
14static struct ctl_table xfrm_table[] = { 15static struct ctl_table xfrm_table[] = {
15 { 16 {
16 .ctl_name = NET_CORE_AEVENT_ETIME,
17 .procname = "xfrm_aevent_etime", 17 .procname = "xfrm_aevent_etime",
18 .maxlen = sizeof(u32), 18 .maxlen = sizeof(u32),
19 .mode = 0644, 19 .mode = 0644,
20 .proc_handler = proc_dointvec 20 .proc_handler = proc_dointvec
21 }, 21 },
22 { 22 {
23 .ctl_name = NET_CORE_AEVENT_RSEQTH,
24 .procname = "xfrm_aevent_rseqth", 23 .procname = "xfrm_aevent_rseqth",
25 .maxlen = sizeof(u32), 24 .maxlen = sizeof(u32),
26 .mode = 0644, 25 .mode = 0644,
27 .proc_handler = proc_dointvec 26 .proc_handler = proc_dointvec
28 }, 27 },
29 { 28 {
30 .ctl_name = CTL_UNNUMBERED,
31 .procname = "xfrm_larval_drop", 29 .procname = "xfrm_larval_drop",
32 .maxlen = sizeof(int), 30 .maxlen = sizeof(int),
33 .mode = 0644, 31 .mode = 0644,
34 .proc_handler = proc_dointvec 32 .proc_handler = proc_dointvec
35 }, 33 },
36 { 34 {
37 .ctl_name = CTL_UNNUMBERED,
38 .procname = "xfrm_acq_expires", 35 .procname = "xfrm_acq_expires",
39 .maxlen = sizeof(int), 36 .maxlen = sizeof(int),
40 .mode = 0644, 37 .mode = 0644,
@@ -68,7 +65,7 @@ out_kmemdup:
68 return -ENOMEM; 65 return -ENOMEM;
69} 66}
70 67
71void xfrm_sysctl_fini(struct net *net) 68void __net_exit xfrm_sysctl_fini(struct net *net)
72{ 69{
73 struct ctl_table *table; 70 struct ctl_table *table;
74 71
diff --git a/net/xfrm/xfrm_user.c b/net/xfrm/xfrm_user.c
index b95a2d64eb59..6106b72826d3 100644
--- a/net/xfrm/xfrm_user.c
+++ b/net/xfrm/xfrm_user.c
@@ -62,6 +62,22 @@ static int verify_one_alg(struct nlattr **attrs, enum xfrm_attr_type_t type)
62 return 0; 62 return 0;
63} 63}
64 64
65static int verify_auth_trunc(struct nlattr **attrs)
66{
67 struct nlattr *rt = attrs[XFRMA_ALG_AUTH_TRUNC];
68 struct xfrm_algo_auth *algp;
69
70 if (!rt)
71 return 0;
72
73 algp = nla_data(rt);
74 if (nla_len(rt) < xfrm_alg_auth_len(algp))
75 return -EINVAL;
76
77 algp->alg_name[CRYPTO_MAX_ALG_NAME - 1] = '\0';
78 return 0;
79}
80
65static int verify_aead(struct nlattr **attrs) 81static int verify_aead(struct nlattr **attrs)
66{ 82{
67 struct nlattr *rt = attrs[XFRMA_ALG_AEAD]; 83 struct nlattr *rt = attrs[XFRMA_ALG_AEAD];
@@ -128,7 +144,8 @@ static int verify_newsa_info(struct xfrm_usersa_info *p,
128 err = -EINVAL; 144 err = -EINVAL;
129 switch (p->id.proto) { 145 switch (p->id.proto) {
130 case IPPROTO_AH: 146 case IPPROTO_AH:
131 if (!attrs[XFRMA_ALG_AUTH] || 147 if ((!attrs[XFRMA_ALG_AUTH] &&
148 !attrs[XFRMA_ALG_AUTH_TRUNC]) ||
132 attrs[XFRMA_ALG_AEAD] || 149 attrs[XFRMA_ALG_AEAD] ||
133 attrs[XFRMA_ALG_CRYPT] || 150 attrs[XFRMA_ALG_CRYPT] ||
134 attrs[XFRMA_ALG_COMP]) 151 attrs[XFRMA_ALG_COMP])
@@ -139,10 +156,12 @@ static int verify_newsa_info(struct xfrm_usersa_info *p,
139 if (attrs[XFRMA_ALG_COMP]) 156 if (attrs[XFRMA_ALG_COMP])
140 goto out; 157 goto out;
141 if (!attrs[XFRMA_ALG_AUTH] && 158 if (!attrs[XFRMA_ALG_AUTH] &&
159 !attrs[XFRMA_ALG_AUTH_TRUNC] &&
142 !attrs[XFRMA_ALG_CRYPT] && 160 !attrs[XFRMA_ALG_CRYPT] &&
143 !attrs[XFRMA_ALG_AEAD]) 161 !attrs[XFRMA_ALG_AEAD])
144 goto out; 162 goto out;
145 if ((attrs[XFRMA_ALG_AUTH] || 163 if ((attrs[XFRMA_ALG_AUTH] ||
164 attrs[XFRMA_ALG_AUTH_TRUNC] ||
146 attrs[XFRMA_ALG_CRYPT]) && 165 attrs[XFRMA_ALG_CRYPT]) &&
147 attrs[XFRMA_ALG_AEAD]) 166 attrs[XFRMA_ALG_AEAD])
148 goto out; 167 goto out;
@@ -152,6 +171,7 @@ static int verify_newsa_info(struct xfrm_usersa_info *p,
152 if (!attrs[XFRMA_ALG_COMP] || 171 if (!attrs[XFRMA_ALG_COMP] ||
153 attrs[XFRMA_ALG_AEAD] || 172 attrs[XFRMA_ALG_AEAD] ||
154 attrs[XFRMA_ALG_AUTH] || 173 attrs[XFRMA_ALG_AUTH] ||
174 attrs[XFRMA_ALG_AUTH_TRUNC] ||
155 attrs[XFRMA_ALG_CRYPT]) 175 attrs[XFRMA_ALG_CRYPT])
156 goto out; 176 goto out;
157 break; 177 break;
@@ -161,6 +181,7 @@ static int verify_newsa_info(struct xfrm_usersa_info *p,
161 case IPPROTO_ROUTING: 181 case IPPROTO_ROUTING:
162 if (attrs[XFRMA_ALG_COMP] || 182 if (attrs[XFRMA_ALG_COMP] ||
163 attrs[XFRMA_ALG_AUTH] || 183 attrs[XFRMA_ALG_AUTH] ||
184 attrs[XFRMA_ALG_AUTH_TRUNC] ||
164 attrs[XFRMA_ALG_AEAD] || 185 attrs[XFRMA_ALG_AEAD] ||
165 attrs[XFRMA_ALG_CRYPT] || 186 attrs[XFRMA_ALG_CRYPT] ||
166 attrs[XFRMA_ENCAP] || 187 attrs[XFRMA_ENCAP] ||
@@ -176,6 +197,8 @@ static int verify_newsa_info(struct xfrm_usersa_info *p,
176 197
177 if ((err = verify_aead(attrs))) 198 if ((err = verify_aead(attrs)))
178 goto out; 199 goto out;
200 if ((err = verify_auth_trunc(attrs)))
201 goto out;
179 if ((err = verify_one_alg(attrs, XFRMA_ALG_AUTH))) 202 if ((err = verify_one_alg(attrs, XFRMA_ALG_AUTH)))
180 goto out; 203 goto out;
181 if ((err = verify_one_alg(attrs, XFRMA_ALG_CRYPT))) 204 if ((err = verify_one_alg(attrs, XFRMA_ALG_CRYPT)))
@@ -229,6 +252,66 @@ static int attach_one_algo(struct xfrm_algo **algpp, u8 *props,
229 return 0; 252 return 0;
230} 253}
231 254
255static int attach_auth(struct xfrm_algo_auth **algpp, u8 *props,
256 struct nlattr *rta)
257{
258 struct xfrm_algo *ualg;
259 struct xfrm_algo_auth *p;
260 struct xfrm_algo_desc *algo;
261
262 if (!rta)
263 return 0;
264
265 ualg = nla_data(rta);
266
267 algo = xfrm_aalg_get_byname(ualg->alg_name, 1);
268 if (!algo)
269 return -ENOSYS;
270 *props = algo->desc.sadb_alg_id;
271
272 p = kmalloc(sizeof(*p) + (ualg->alg_key_len + 7) / 8, GFP_KERNEL);
273 if (!p)
274 return -ENOMEM;
275
276 strcpy(p->alg_name, algo->name);
277 p->alg_key_len = ualg->alg_key_len;
278 p->alg_trunc_len = algo->uinfo.auth.icv_truncbits;
279 memcpy(p->alg_key, ualg->alg_key, (ualg->alg_key_len + 7) / 8);
280
281 *algpp = p;
282 return 0;
283}
284
285static int attach_auth_trunc(struct xfrm_algo_auth **algpp, u8 *props,
286 struct nlattr *rta)
287{
288 struct xfrm_algo_auth *p, *ualg;
289 struct xfrm_algo_desc *algo;
290
291 if (!rta)
292 return 0;
293
294 ualg = nla_data(rta);
295
296 algo = xfrm_aalg_get_byname(ualg->alg_name, 1);
297 if (!algo)
298 return -ENOSYS;
299 if (ualg->alg_trunc_len > algo->uinfo.auth.icv_fullbits)
300 return -EINVAL;
301 *props = algo->desc.sadb_alg_id;
302
303 p = kmemdup(ualg, xfrm_alg_auth_len(ualg), GFP_KERNEL);
304 if (!p)
305 return -ENOMEM;
306
307 strcpy(p->alg_name, algo->name);
308 if (!p->alg_trunc_len)
309 p->alg_trunc_len = algo->uinfo.auth.icv_truncbits;
310
311 *algpp = p;
312 return 0;
313}
314
232static int attach_aead(struct xfrm_algo_aead **algpp, u8 *props, 315static int attach_aead(struct xfrm_algo_aead **algpp, u8 *props,
233 struct nlattr *rta) 316 struct nlattr *rta)
234{ 317{
@@ -332,10 +415,14 @@ static struct xfrm_state *xfrm_state_construct(struct net *net,
332 if ((err = attach_aead(&x->aead, &x->props.ealgo, 415 if ((err = attach_aead(&x->aead, &x->props.ealgo,
333 attrs[XFRMA_ALG_AEAD]))) 416 attrs[XFRMA_ALG_AEAD])))
334 goto error; 417 goto error;
335 if ((err = attach_one_algo(&x->aalg, &x->props.aalgo, 418 if ((err = attach_auth_trunc(&x->aalg, &x->props.aalgo,
336 xfrm_aalg_get_byname, 419 attrs[XFRMA_ALG_AUTH_TRUNC])))
337 attrs[XFRMA_ALG_AUTH])))
338 goto error; 420 goto error;
421 if (!x->props.aalgo) {
422 if ((err = attach_auth(&x->aalg, &x->props.aalgo,
423 attrs[XFRMA_ALG_AUTH])))
424 goto error;
425 }
339 if ((err = attach_one_algo(&x->ealg, &x->props.ealgo, 426 if ((err = attach_one_algo(&x->ealg, &x->props.ealgo,
340 xfrm_ealg_get_byname, 427 xfrm_ealg_get_byname,
341 attrs[XFRMA_ALG_CRYPT]))) 428 attrs[XFRMA_ALG_CRYPT])))
@@ -359,6 +446,8 @@ static struct xfrm_state *xfrm_state_construct(struct net *net,
359 goto error; 446 goto error;
360 } 447 }
361 448
449 xfrm_mark_get(attrs, &x->mark);
450
362 err = xfrm_init_state(x); 451 err = xfrm_init_state(x);
363 if (err) 452 if (err)
364 goto error; 453 goto error;
@@ -439,11 +528,13 @@ static struct xfrm_state *xfrm_user_state_lookup(struct net *net,
439 int *errp) 528 int *errp)
440{ 529{
441 struct xfrm_state *x = NULL; 530 struct xfrm_state *x = NULL;
531 struct xfrm_mark m;
442 int err; 532 int err;
533 u32 mark = xfrm_mark_get(attrs, &m);
443 534
444 if (xfrm_id_proto_match(p->proto, IPSEC_PROTO_ANY)) { 535 if (xfrm_id_proto_match(p->proto, IPSEC_PROTO_ANY)) {
445 err = -ESRCH; 536 err = -ESRCH;
446 x = xfrm_state_lookup(net, &p->daddr, p->spi, p->proto, p->family); 537 x = xfrm_state_lookup(net, mark, &p->daddr, p->spi, p->proto, p->family);
447 } else { 538 } else {
448 xfrm_address_t *saddr = NULL; 539 xfrm_address_t *saddr = NULL;
449 540
@@ -454,7 +545,8 @@ static struct xfrm_state *xfrm_user_state_lookup(struct net *net,
454 } 545 }
455 546
456 err = -ESRCH; 547 err = -ESRCH;
457 x = xfrm_state_lookup_byaddr(net, &p->daddr, saddr, 548 x = xfrm_state_lookup_byaddr(net, mark,
549 &p->daddr, saddr,
458 p->proto, p->family); 550 p->proto, p->family);
459 } 551 }
460 552
@@ -548,6 +640,24 @@ static int copy_sec_ctx(struct xfrm_sec_ctx *s, struct sk_buff *skb)
548 return 0; 640 return 0;
549} 641}
550 642
643static int copy_to_user_auth(struct xfrm_algo_auth *auth, struct sk_buff *skb)
644{
645 struct xfrm_algo *algo;
646 struct nlattr *nla;
647
648 nla = nla_reserve(skb, XFRMA_ALG_AUTH,
649 sizeof(*algo) + (auth->alg_key_len + 7) / 8);
650 if (!nla)
651 return -EMSGSIZE;
652
653 algo = nla_data(nla);
654 strcpy(algo->alg_name, auth->alg_name);
655 memcpy(algo->alg_key, auth->alg_key, (auth->alg_key_len + 7) / 8);
656 algo->alg_key_len = auth->alg_key_len;
657
658 return 0;
659}
660
551/* Don't change this without updating xfrm_sa_len! */ 661/* Don't change this without updating xfrm_sa_len! */
552static int copy_to_user_state_extra(struct xfrm_state *x, 662static int copy_to_user_state_extra(struct xfrm_state *x,
553 struct xfrm_usersa_info *p, 663 struct xfrm_usersa_info *p,
@@ -563,8 +673,13 @@ static int copy_to_user_state_extra(struct xfrm_state *x,
563 673
564 if (x->aead) 674 if (x->aead)
565 NLA_PUT(skb, XFRMA_ALG_AEAD, aead_len(x->aead), x->aead); 675 NLA_PUT(skb, XFRMA_ALG_AEAD, aead_len(x->aead), x->aead);
566 if (x->aalg) 676 if (x->aalg) {
567 NLA_PUT(skb, XFRMA_ALG_AUTH, xfrm_alg_len(x->aalg), x->aalg); 677 if (copy_to_user_auth(x->aalg, skb))
678 goto nla_put_failure;
679
680 NLA_PUT(skb, XFRMA_ALG_AUTH_TRUNC,
681 xfrm_alg_auth_len(x->aalg), x->aalg);
682 }
568 if (x->ealg) 683 if (x->ealg)
569 NLA_PUT(skb, XFRMA_ALG_CRYPT, xfrm_alg_len(x->ealg), x->ealg); 684 NLA_PUT(skb, XFRMA_ALG_CRYPT, xfrm_alg_len(x->ealg), x->ealg);
570 if (x->calg) 685 if (x->calg)
@@ -573,6 +688,9 @@ static int copy_to_user_state_extra(struct xfrm_state *x,
573 if (x->encap) 688 if (x->encap)
574 NLA_PUT(skb, XFRMA_ENCAP, sizeof(*x->encap), x->encap); 689 NLA_PUT(skb, XFRMA_ENCAP, sizeof(*x->encap), x->encap);
575 690
691 if (xfrm_mark_put(skb, &x->mark))
692 goto nla_put_failure;
693
576 if (x->security && copy_sec_ctx(x->security, skb) < 0) 694 if (x->security && copy_sec_ctx(x->security, skb) < 0)
577 goto nla_put_failure; 695 goto nla_put_failure;
578 696
@@ -671,7 +789,8 @@ static inline size_t xfrm_spdinfo_msgsize(void)
671 + nla_total_size(sizeof(struct xfrmu_spdhinfo)); 789 + nla_total_size(sizeof(struct xfrmu_spdhinfo));
672} 790}
673 791
674static int build_spdinfo(struct sk_buff *skb, u32 pid, u32 seq, u32 flags) 792static int build_spdinfo(struct sk_buff *skb, struct net *net,
793 u32 pid, u32 seq, u32 flags)
675{ 794{
676 struct xfrmk_spdinfo si; 795 struct xfrmk_spdinfo si;
677 struct xfrmu_spdinfo spc; 796 struct xfrmu_spdinfo spc;
@@ -685,7 +804,7 @@ static int build_spdinfo(struct sk_buff *skb, u32 pid, u32 seq, u32 flags)
685 804
686 f = nlmsg_data(nlh); 805 f = nlmsg_data(nlh);
687 *f = flags; 806 *f = flags;
688 xfrm_spd_getinfo(&si); 807 xfrm_spd_getinfo(net, &si);
689 spc.incnt = si.incnt; 808 spc.incnt = si.incnt;
690 spc.outcnt = si.outcnt; 809 spc.outcnt = si.outcnt;
691 spc.fwdcnt = si.fwdcnt; 810 spc.fwdcnt = si.fwdcnt;
@@ -718,7 +837,7 @@ static int xfrm_get_spdinfo(struct sk_buff *skb, struct nlmsghdr *nlh,
718 if (r_skb == NULL) 837 if (r_skb == NULL)
719 return -ENOMEM; 838 return -ENOMEM;
720 839
721 if (build_spdinfo(r_skb, spid, seq, *flags) < 0) 840 if (build_spdinfo(r_skb, net, spid, seq, *flags) < 0)
722 BUG(); 841 BUG();
723 842
724 return nlmsg_unicast(net->xfrm.nlsk, r_skb, spid); 843 return nlmsg_unicast(net->xfrm.nlsk, r_skb, spid);
@@ -731,7 +850,8 @@ static inline size_t xfrm_sadinfo_msgsize(void)
731 + nla_total_size(4); /* XFRMA_SAD_CNT */ 850 + nla_total_size(4); /* XFRMA_SAD_CNT */
732} 851}
733 852
734static int build_sadinfo(struct sk_buff *skb, u32 pid, u32 seq, u32 flags) 853static int build_sadinfo(struct sk_buff *skb, struct net *net,
854 u32 pid, u32 seq, u32 flags)
735{ 855{
736 struct xfrmk_sadinfo si; 856 struct xfrmk_sadinfo si;
737 struct xfrmu_sadhinfo sh; 857 struct xfrmu_sadhinfo sh;
@@ -744,7 +864,7 @@ static int build_sadinfo(struct sk_buff *skb, u32 pid, u32 seq, u32 flags)
744 864
745 f = nlmsg_data(nlh); 865 f = nlmsg_data(nlh);
746 *f = flags; 866 *f = flags;
747 xfrm_sad_getinfo(&si); 867 xfrm_sad_getinfo(net, &si);
748 868
749 sh.sadhmcnt = si.sadhmcnt; 869 sh.sadhmcnt = si.sadhmcnt;
750 sh.sadhcnt = si.sadhcnt; 870 sh.sadhcnt = si.sadhcnt;
@@ -772,7 +892,7 @@ static int xfrm_get_sadinfo(struct sk_buff *skb, struct nlmsghdr *nlh,
772 if (r_skb == NULL) 892 if (r_skb == NULL)
773 return -ENOMEM; 893 return -ENOMEM;
774 894
775 if (build_sadinfo(r_skb, spid, seq, *flags) < 0) 895 if (build_sadinfo(r_skb, net, spid, seq, *flags) < 0)
776 BUG(); 896 BUG();
777 897
778 return nlmsg_unicast(net->xfrm.nlsk, r_skb, spid); 898 return nlmsg_unicast(net->xfrm.nlsk, r_skb, spid);
@@ -835,6 +955,8 @@ static int xfrm_alloc_userspi(struct sk_buff *skb, struct nlmsghdr *nlh,
835 xfrm_address_t *daddr; 955 xfrm_address_t *daddr;
836 int family; 956 int family;
837 int err; 957 int err;
958 u32 mark;
959 struct xfrm_mark m;
838 960
839 p = nlmsg_data(nlh); 961 p = nlmsg_data(nlh);
840 err = verify_userspi_info(p); 962 err = verify_userspi_info(p);
@@ -845,8 +967,10 @@ static int xfrm_alloc_userspi(struct sk_buff *skb, struct nlmsghdr *nlh,
845 daddr = &p->info.id.daddr; 967 daddr = &p->info.id.daddr;
846 968
847 x = NULL; 969 x = NULL;
970
971 mark = xfrm_mark_get(attrs, &m);
848 if (p->info.seq) { 972 if (p->info.seq) {
849 x = xfrm_find_acq_byseq(net, p->info.seq); 973 x = xfrm_find_acq_byseq(net, mark, p->info.seq);
850 if (x && xfrm_addr_cmp(&x->id.daddr, daddr, family)) { 974 if (x && xfrm_addr_cmp(&x->id.daddr, daddr, family)) {
851 xfrm_state_put(x); 975 xfrm_state_put(x);
852 x = NULL; 976 x = NULL;
@@ -854,7 +978,7 @@ static int xfrm_alloc_userspi(struct sk_buff *skb, struct nlmsghdr *nlh,
854 } 978 }
855 979
856 if (!x) 980 if (!x)
857 x = xfrm_find_acq(net, p->info.mode, p->info.reqid, 981 x = xfrm_find_acq(net, &m, p->info.mode, p->info.reqid,
858 p->info.id.proto, daddr, 982 p->info.id.proto, daddr,
859 &p->info.saddr, 1, 983 &p->info.saddr, 1,
860 family); 984 family);
@@ -1108,6 +1232,8 @@ static struct xfrm_policy *xfrm_policy_construct(struct net *net, struct xfrm_us
1108 if (err) 1232 if (err)
1109 goto error; 1233 goto error;
1110 1234
1235 xfrm_mark_get(attrs, &xp->mark);
1236
1111 return xp; 1237 return xp;
1112 error: 1238 error:
1113 *errp = err; 1239 *errp = err;
@@ -1254,10 +1380,13 @@ static int dump_one_policy(struct xfrm_policy *xp, int dir, int count, void *ptr
1254 goto nlmsg_failure; 1380 goto nlmsg_failure;
1255 if (copy_to_user_policy_type(xp->type, skb) < 0) 1381 if (copy_to_user_policy_type(xp->type, skb) < 0)
1256 goto nlmsg_failure; 1382 goto nlmsg_failure;
1383 if (xfrm_mark_put(skb, &xp->mark))
1384 goto nla_put_failure;
1257 1385
1258 nlmsg_end(skb, nlh); 1386 nlmsg_end(skb, nlh);
1259 return 0; 1387 return 0;
1260 1388
1389nla_put_failure:
1261nlmsg_failure: 1390nlmsg_failure:
1262 nlmsg_cancel(skb, nlh); 1391 nlmsg_cancel(skb, nlh);
1263 return -EMSGSIZE; 1392 return -EMSGSIZE;
@@ -1329,6 +1458,8 @@ static int xfrm_get_policy(struct sk_buff *skb, struct nlmsghdr *nlh,
1329 int err; 1458 int err;
1330 struct km_event c; 1459 struct km_event c;
1331 int delete; 1460 int delete;
1461 struct xfrm_mark m;
1462 u32 mark = xfrm_mark_get(attrs, &m);
1332 1463
1333 p = nlmsg_data(nlh); 1464 p = nlmsg_data(nlh);
1334 delete = nlh->nlmsg_type == XFRM_MSG_DELPOLICY; 1465 delete = nlh->nlmsg_type == XFRM_MSG_DELPOLICY;
@@ -1342,7 +1473,7 @@ static int xfrm_get_policy(struct sk_buff *skb, struct nlmsghdr *nlh,
1342 return err; 1473 return err;
1343 1474
1344 if (p->index) 1475 if (p->index)
1345 xp = xfrm_policy_byid(net, type, p->dir, p->index, delete, &err); 1476 xp = xfrm_policy_byid(net, mark, type, p->dir, p->index, delete, &err);
1346 else { 1477 else {
1347 struct nlattr *rt = attrs[XFRMA_SEC_CTX]; 1478 struct nlattr *rt = attrs[XFRMA_SEC_CTX];
1348 struct xfrm_sec_ctx *ctx; 1479 struct xfrm_sec_ctx *ctx;
@@ -1359,8 +1490,8 @@ static int xfrm_get_policy(struct sk_buff *skb, struct nlmsghdr *nlh,
1359 if (err) 1490 if (err)
1360 return err; 1491 return err;
1361 } 1492 }
1362 xp = xfrm_policy_bysel_ctx(net, type, p->dir, &p->sel, ctx, 1493 xp = xfrm_policy_bysel_ctx(net, mark, type, p->dir, &p->sel,
1363 delete, &err); 1494 ctx, delete, &err);
1364 security_xfrm_policy_free(ctx); 1495 security_xfrm_policy_free(ctx);
1365 } 1496 }
1366 if (xp == NULL) 1497 if (xp == NULL)
@@ -1412,8 +1543,11 @@ static int xfrm_flush_sa(struct sk_buff *skb, struct nlmsghdr *nlh,
1412 audit_info.sessionid = NETLINK_CB(skb).sessionid; 1543 audit_info.sessionid = NETLINK_CB(skb).sessionid;
1413 audit_info.secid = NETLINK_CB(skb).sid; 1544 audit_info.secid = NETLINK_CB(skb).sid;
1414 err = xfrm_state_flush(net, p->proto, &audit_info); 1545 err = xfrm_state_flush(net, p->proto, &audit_info);
1415 if (err) 1546 if (err) {
1547 if (err == -ESRCH) /* empty table */
1548 return 0;
1416 return err; 1549 return err;
1550 }
1417 c.data.proto = p->proto; 1551 c.data.proto = p->proto;
1418 c.event = nlh->nlmsg_type; 1552 c.event = nlh->nlmsg_type;
1419 c.seq = nlh->nlmsg_seq; 1553 c.seq = nlh->nlmsg_seq;
@@ -1429,6 +1563,7 @@ static inline size_t xfrm_aevent_msgsize(void)
1429 return NLMSG_ALIGN(sizeof(struct xfrm_aevent_id)) 1563 return NLMSG_ALIGN(sizeof(struct xfrm_aevent_id))
1430 + nla_total_size(sizeof(struct xfrm_replay_state)) 1564 + nla_total_size(sizeof(struct xfrm_replay_state))
1431 + nla_total_size(sizeof(struct xfrm_lifetime_cur)) 1565 + nla_total_size(sizeof(struct xfrm_lifetime_cur))
1566 + nla_total_size(sizeof(struct xfrm_mark))
1432 + nla_total_size(4) /* XFRM_AE_RTHR */ 1567 + nla_total_size(4) /* XFRM_AE_RTHR */
1433 + nla_total_size(4); /* XFRM_AE_ETHR */ 1568 + nla_total_size(4); /* XFRM_AE_ETHR */
1434} 1569}
@@ -1461,6 +1596,9 @@ static int build_aevent(struct sk_buff *skb, struct xfrm_state *x, struct km_eve
1461 NLA_PUT_U32(skb, XFRMA_ETIMER_THRESH, 1596 NLA_PUT_U32(skb, XFRMA_ETIMER_THRESH,
1462 x->replay_maxage * 10 / HZ); 1597 x->replay_maxage * 10 / HZ);
1463 1598
1599 if (xfrm_mark_put(skb, &x->mark))
1600 goto nla_put_failure;
1601
1464 return nlmsg_end(skb, nlh); 1602 return nlmsg_end(skb, nlh);
1465 1603
1466nla_put_failure: 1604nla_put_failure:
@@ -1476,6 +1614,8 @@ static int xfrm_get_ae(struct sk_buff *skb, struct nlmsghdr *nlh,
1476 struct sk_buff *r_skb; 1614 struct sk_buff *r_skb;
1477 int err; 1615 int err;
1478 struct km_event c; 1616 struct km_event c;
1617 u32 mark;
1618 struct xfrm_mark m;
1479 struct xfrm_aevent_id *p = nlmsg_data(nlh); 1619 struct xfrm_aevent_id *p = nlmsg_data(nlh);
1480 struct xfrm_usersa_id *id = &p->sa_id; 1620 struct xfrm_usersa_id *id = &p->sa_id;
1481 1621
@@ -1483,7 +1623,9 @@ static int xfrm_get_ae(struct sk_buff *skb, struct nlmsghdr *nlh,
1483 if (r_skb == NULL) 1623 if (r_skb == NULL)
1484 return -ENOMEM; 1624 return -ENOMEM;
1485 1625
1486 x = xfrm_state_lookup(net, &id->daddr, id->spi, id->proto, id->family); 1626 mark = xfrm_mark_get(attrs, &m);
1627
1628 x = xfrm_state_lookup(net, mark, &id->daddr, id->spi, id->proto, id->family);
1487 if (x == NULL) { 1629 if (x == NULL) {
1488 kfree_skb(r_skb); 1630 kfree_skb(r_skb);
1489 return -ESRCH; 1631 return -ESRCH;
@@ -1514,6 +1656,8 @@ static int xfrm_new_ae(struct sk_buff *skb, struct nlmsghdr *nlh,
1514 struct xfrm_state *x; 1656 struct xfrm_state *x;
1515 struct km_event c; 1657 struct km_event c;
1516 int err = - EINVAL; 1658 int err = - EINVAL;
1659 u32 mark = 0;
1660 struct xfrm_mark m;
1517 struct xfrm_aevent_id *p = nlmsg_data(nlh); 1661 struct xfrm_aevent_id *p = nlmsg_data(nlh);
1518 struct nlattr *rp = attrs[XFRMA_REPLAY_VAL]; 1662 struct nlattr *rp = attrs[XFRMA_REPLAY_VAL];
1519 struct nlattr *lt = attrs[XFRMA_LTIME_VAL]; 1663 struct nlattr *lt = attrs[XFRMA_LTIME_VAL];
@@ -1525,7 +1669,9 @@ static int xfrm_new_ae(struct sk_buff *skb, struct nlmsghdr *nlh,
1525 if (!(nlh->nlmsg_flags&NLM_F_REPLACE)) 1669 if (!(nlh->nlmsg_flags&NLM_F_REPLACE))
1526 return err; 1670 return err;
1527 1671
1528 x = xfrm_state_lookup(net, &p->sa_id.daddr, p->sa_id.spi, p->sa_id.proto, p->sa_id.family); 1672 mark = xfrm_mark_get(attrs, &m);
1673
1674 x = xfrm_state_lookup(net, mark, &p->sa_id.daddr, p->sa_id.spi, p->sa_id.proto, p->sa_id.family);
1529 if (x == NULL) 1675 if (x == NULL)
1530 return -ESRCH; 1676 return -ESRCH;
1531 1677
@@ -1564,8 +1710,12 @@ static int xfrm_flush_policy(struct sk_buff *skb, struct nlmsghdr *nlh,
1564 audit_info.sessionid = NETLINK_CB(skb).sessionid; 1710 audit_info.sessionid = NETLINK_CB(skb).sessionid;
1565 audit_info.secid = NETLINK_CB(skb).sid; 1711 audit_info.secid = NETLINK_CB(skb).sid;
1566 err = xfrm_policy_flush(net, type, &audit_info); 1712 err = xfrm_policy_flush(net, type, &audit_info);
1567 if (err) 1713 if (err) {
1714 if (err == -ESRCH) /* empty table */
1715 return 0;
1568 return err; 1716 return err;
1717 }
1718
1569 c.data.type = type; 1719 c.data.type = type;
1570 c.event = nlh->nlmsg_type; 1720 c.event = nlh->nlmsg_type;
1571 c.seq = nlh->nlmsg_seq; 1721 c.seq = nlh->nlmsg_seq;
@@ -1584,13 +1734,15 @@ static int xfrm_add_pol_expire(struct sk_buff *skb, struct nlmsghdr *nlh,
1584 struct xfrm_userpolicy_info *p = &up->pol; 1734 struct xfrm_userpolicy_info *p = &up->pol;
1585 u8 type = XFRM_POLICY_TYPE_MAIN; 1735 u8 type = XFRM_POLICY_TYPE_MAIN;
1586 int err = -ENOENT; 1736 int err = -ENOENT;
1737 struct xfrm_mark m;
1738 u32 mark = xfrm_mark_get(attrs, &m);
1587 1739
1588 err = copy_from_user_policy_type(&type, attrs); 1740 err = copy_from_user_policy_type(&type, attrs);
1589 if (err) 1741 if (err)
1590 return err; 1742 return err;
1591 1743
1592 if (p->index) 1744 if (p->index)
1593 xp = xfrm_policy_byid(net, type, p->dir, p->index, 0, &err); 1745 xp = xfrm_policy_byid(net, mark, type, p->dir, p->index, 0, &err);
1594 else { 1746 else {
1595 struct nlattr *rt = attrs[XFRMA_SEC_CTX]; 1747 struct nlattr *rt = attrs[XFRMA_SEC_CTX];
1596 struct xfrm_sec_ctx *ctx; 1748 struct xfrm_sec_ctx *ctx;
@@ -1607,7 +1759,8 @@ static int xfrm_add_pol_expire(struct sk_buff *skb, struct nlmsghdr *nlh,
1607 if (err) 1759 if (err)
1608 return err; 1760 return err;
1609 } 1761 }
1610 xp = xfrm_policy_bysel_ctx(net, type, p->dir, &p->sel, ctx, 0, &err); 1762 xp = xfrm_policy_bysel_ctx(net, mark, type, p->dir,
1763 &p->sel, ctx, 0, &err);
1611 security_xfrm_policy_free(ctx); 1764 security_xfrm_policy_free(ctx);
1612 } 1765 }
1613 if (xp == NULL) 1766 if (xp == NULL)
@@ -1647,8 +1800,10 @@ static int xfrm_add_sa_expire(struct sk_buff *skb, struct nlmsghdr *nlh,
1647 int err; 1800 int err;
1648 struct xfrm_user_expire *ue = nlmsg_data(nlh); 1801 struct xfrm_user_expire *ue = nlmsg_data(nlh);
1649 struct xfrm_usersa_info *p = &ue->state; 1802 struct xfrm_usersa_info *p = &ue->state;
1803 struct xfrm_mark m;
1804 u32 mark = xfrm_mark_get(attrs, &m);;
1650 1805
1651 x = xfrm_state_lookup(net, &p->id.daddr, p->id.spi, p->id.proto, p->family); 1806 x = xfrm_state_lookup(net, mark, &p->id.daddr, p->id.spi, p->id.proto, p->family);
1652 1807
1653 err = -ENOENT; 1808 err = -ENOENT;
1654 if (x == NULL) 1809 if (x == NULL)
@@ -1682,6 +1837,7 @@ static int xfrm_add_acquire(struct sk_buff *skb, struct nlmsghdr *nlh,
1682 struct xfrm_user_tmpl *ut; 1837 struct xfrm_user_tmpl *ut;
1683 int i; 1838 int i;
1684 struct nlattr *rt = attrs[XFRMA_TMPL]; 1839 struct nlattr *rt = attrs[XFRMA_TMPL];
1840 struct xfrm_mark mark;
1685 1841
1686 struct xfrm_user_acquire *ua = nlmsg_data(nlh); 1842 struct xfrm_user_acquire *ua = nlmsg_data(nlh);
1687 struct xfrm_state *x = xfrm_state_alloc(net); 1843 struct xfrm_state *x = xfrm_state_alloc(net);
@@ -1690,6 +1846,8 @@ static int xfrm_add_acquire(struct sk_buff *skb, struct nlmsghdr *nlh,
1690 if (!x) 1846 if (!x)
1691 goto nomem; 1847 goto nomem;
1692 1848
1849 xfrm_mark_get(attrs, &mark);
1850
1693 err = verify_newpolicy_info(&ua->policy); 1851 err = verify_newpolicy_info(&ua->policy);
1694 if (err) 1852 if (err)
1695 goto bad_policy; 1853 goto bad_policy;
@@ -1702,7 +1860,8 @@ static int xfrm_add_acquire(struct sk_buff *skb, struct nlmsghdr *nlh,
1702 memcpy(&x->id, &ua->id, sizeof(ua->id)); 1860 memcpy(&x->id, &ua->id, sizeof(ua->id));
1703 memcpy(&x->props.saddr, &ua->saddr, sizeof(ua->saddr)); 1861 memcpy(&x->props.saddr, &ua->saddr, sizeof(ua->saddr));
1704 memcpy(&x->sel, &ua->sel, sizeof(ua->sel)); 1862 memcpy(&x->sel, &ua->sel, sizeof(ua->sel));
1705 1863 xp->mark.m = x->mark.m = mark.m;
1864 xp->mark.v = x->mark.v = mark.v;
1706 ut = nla_data(rt); 1865 ut = nla_data(rt);
1707 /* extract the templates and for each call km_key */ 1866 /* extract the templates and for each call km_key */
1708 for (i = 0; i < xp->xfrm_nr; i++, ut++) { 1867 for (i = 0; i < xp->xfrm_nr; i++, ut++) {
@@ -1942,6 +2101,10 @@ static const int xfrm_msg_min[XFRM_NR_MSGTYPES] = {
1942#undef XMSGSIZE 2101#undef XMSGSIZE
1943 2102
1944static const struct nla_policy xfrma_policy[XFRMA_MAX+1] = { 2103static const struct nla_policy xfrma_policy[XFRMA_MAX+1] = {
2104 [XFRMA_SA] = { .len = sizeof(struct xfrm_usersa_info)},
2105 [XFRMA_POLICY] = { .len = sizeof(struct xfrm_userpolicy_info)},
2106 [XFRMA_LASTUSED] = { .type = NLA_U64},
2107 [XFRMA_ALG_AUTH_TRUNC] = { .len = sizeof(struct xfrm_algo_auth)},
1945 [XFRMA_ALG_AEAD] = { .len = sizeof(struct xfrm_algo_aead) }, 2108 [XFRMA_ALG_AEAD] = { .len = sizeof(struct xfrm_algo_aead) },
1946 [XFRMA_ALG_AUTH] = { .len = sizeof(struct xfrm_algo) }, 2109 [XFRMA_ALG_AUTH] = { .len = sizeof(struct xfrm_algo) },
1947 [XFRMA_ALG_CRYPT] = { .len = sizeof(struct xfrm_algo) }, 2110 [XFRMA_ALG_CRYPT] = { .len = sizeof(struct xfrm_algo) },
@@ -1958,6 +2121,7 @@ static const struct nla_policy xfrma_policy[XFRMA_MAX+1] = {
1958 [XFRMA_POLICY_TYPE] = { .len = sizeof(struct xfrm_userpolicy_type)}, 2121 [XFRMA_POLICY_TYPE] = { .len = sizeof(struct xfrm_userpolicy_type)},
1959 [XFRMA_MIGRATE] = { .len = sizeof(struct xfrm_user_migrate) }, 2122 [XFRMA_MIGRATE] = { .len = sizeof(struct xfrm_user_migrate) },
1960 [XFRMA_KMADDRESS] = { .len = sizeof(struct xfrm_user_kmaddress) }, 2123 [XFRMA_KMADDRESS] = { .len = sizeof(struct xfrm_user_kmaddress) },
2124 [XFRMA_MARK] = { .len = sizeof(struct xfrm_mark) },
1961}; 2125};
1962 2126
1963static struct xfrm_link { 2127static struct xfrm_link {
@@ -2037,7 +2201,8 @@ static void xfrm_netlink_rcv(struct sk_buff *skb)
2037 2201
2038static inline size_t xfrm_expire_msgsize(void) 2202static inline size_t xfrm_expire_msgsize(void)
2039{ 2203{
2040 return NLMSG_ALIGN(sizeof(struct xfrm_user_expire)); 2204 return NLMSG_ALIGN(sizeof(struct xfrm_user_expire))
2205 + nla_total_size(sizeof(struct xfrm_mark));
2041} 2206}
2042 2207
2043static int build_expire(struct sk_buff *skb, struct xfrm_state *x, struct km_event *c) 2208static int build_expire(struct sk_buff *skb, struct xfrm_state *x, struct km_event *c)
@@ -2053,7 +2218,13 @@ static int build_expire(struct sk_buff *skb, struct xfrm_state *x, struct km_eve
2053 copy_to_user_state(x, &ue->state); 2218 copy_to_user_state(x, &ue->state);
2054 ue->hard = (c->data.hard != 0) ? 1 : 0; 2219 ue->hard = (c->data.hard != 0) ? 1 : 0;
2055 2220
2221 if (xfrm_mark_put(skb, &x->mark))
2222 goto nla_put_failure;
2223
2056 return nlmsg_end(skb, nlh); 2224 return nlmsg_end(skb, nlh);
2225
2226nla_put_failure:
2227 return -EMSGSIZE;
2057} 2228}
2058 2229
2059static int xfrm_exp_state_notify(struct xfrm_state *x, struct km_event *c) 2230static int xfrm_exp_state_notify(struct xfrm_state *x, struct km_event *c)
@@ -2065,8 +2236,10 @@ static int xfrm_exp_state_notify(struct xfrm_state *x, struct km_event *c)
2065 if (skb == NULL) 2236 if (skb == NULL)
2066 return -ENOMEM; 2237 return -ENOMEM;
2067 2238
2068 if (build_expire(skb, x, c) < 0) 2239 if (build_expire(skb, x, c) < 0) {
2069 BUG(); 2240 kfree_skb(skb);
2241 return -EMSGSIZE;
2242 }
2070 2243
2071 return nlmsg_multicast(net->xfrm.nlsk, skb, 0, XFRMNLGRP_EXPIRE, GFP_ATOMIC); 2244 return nlmsg_multicast(net->xfrm.nlsk, skb, 0, XFRMNLGRP_EXPIRE, GFP_ATOMIC);
2072} 2245}
@@ -2117,8 +2290,11 @@ static inline size_t xfrm_sa_len(struct xfrm_state *x)
2117 size_t l = 0; 2290 size_t l = 0;
2118 if (x->aead) 2291 if (x->aead)
2119 l += nla_total_size(aead_len(x->aead)); 2292 l += nla_total_size(aead_len(x->aead));
2120 if (x->aalg) 2293 if (x->aalg) {
2121 l += nla_total_size(xfrm_alg_len(x->aalg)); 2294 l += nla_total_size(sizeof(struct xfrm_algo) +
2295 (x->aalg->alg_key_len + 7) / 8);
2296 l += nla_total_size(xfrm_alg_auth_len(x->aalg));
2297 }
2122 if (x->ealg) 2298 if (x->ealg)
2123 l += nla_total_size(xfrm_alg_len(x->ealg)); 2299 l += nla_total_size(xfrm_alg_len(x->ealg));
2124 if (x->calg) 2300 if (x->calg)
@@ -2151,6 +2327,7 @@ static int xfrm_notify_sa(struct xfrm_state *x, struct km_event *c)
2151 if (c->event == XFRM_MSG_DELSA) { 2327 if (c->event == XFRM_MSG_DELSA) {
2152 len += nla_total_size(headlen); 2328 len += nla_total_size(headlen);
2153 headlen = sizeof(*id); 2329 headlen = sizeof(*id);
2330 len += nla_total_size(sizeof(struct xfrm_mark));
2154 } 2331 }
2155 len += NLMSG_ALIGN(headlen); 2332 len += NLMSG_ALIGN(headlen);
2156 2333
@@ -2221,6 +2398,7 @@ static inline size_t xfrm_acquire_msgsize(struct xfrm_state *x,
2221{ 2398{
2222 return NLMSG_ALIGN(sizeof(struct xfrm_user_acquire)) 2399 return NLMSG_ALIGN(sizeof(struct xfrm_user_acquire))
2223 + nla_total_size(sizeof(struct xfrm_user_tmpl) * xp->xfrm_nr) 2400 + nla_total_size(sizeof(struct xfrm_user_tmpl) * xp->xfrm_nr)
2401 + nla_total_size(sizeof(struct xfrm_mark))
2224 + nla_total_size(xfrm_user_sec_ctx_size(x->security)) 2402 + nla_total_size(xfrm_user_sec_ctx_size(x->security))
2225 + userpolicy_type_attrsize(); 2403 + userpolicy_type_attrsize();
2226} 2404}
@@ -2253,9 +2431,12 @@ static int build_acquire(struct sk_buff *skb, struct xfrm_state *x,
2253 goto nlmsg_failure; 2431 goto nlmsg_failure;
2254 if (copy_to_user_policy_type(xp->type, skb) < 0) 2432 if (copy_to_user_policy_type(xp->type, skb) < 0)
2255 goto nlmsg_failure; 2433 goto nlmsg_failure;
2434 if (xfrm_mark_put(skb, &xp->mark))
2435 goto nla_put_failure;
2256 2436
2257 return nlmsg_end(skb, nlh); 2437 return nlmsg_end(skb, nlh);
2258 2438
2439nla_put_failure:
2259nlmsg_failure: 2440nlmsg_failure:
2260 nlmsg_cancel(skb, nlh); 2441 nlmsg_cancel(skb, nlh);
2261 return -EMSGSIZE; 2442 return -EMSGSIZE;
@@ -2342,6 +2523,7 @@ static inline size_t xfrm_polexpire_msgsize(struct xfrm_policy *xp)
2342 return NLMSG_ALIGN(sizeof(struct xfrm_user_polexpire)) 2523 return NLMSG_ALIGN(sizeof(struct xfrm_user_polexpire))
2343 + nla_total_size(sizeof(struct xfrm_user_tmpl) * xp->xfrm_nr) 2524 + nla_total_size(sizeof(struct xfrm_user_tmpl) * xp->xfrm_nr)
2344 + nla_total_size(xfrm_user_sec_ctx_size(xp->security)) 2525 + nla_total_size(xfrm_user_sec_ctx_size(xp->security))
2526 + nla_total_size(sizeof(struct xfrm_mark))
2345 + userpolicy_type_attrsize(); 2527 + userpolicy_type_attrsize();
2346} 2528}
2347 2529
@@ -2364,10 +2546,13 @@ static int build_polexpire(struct sk_buff *skb, struct xfrm_policy *xp,
2364 goto nlmsg_failure; 2546 goto nlmsg_failure;
2365 if (copy_to_user_policy_type(xp->type, skb) < 0) 2547 if (copy_to_user_policy_type(xp->type, skb) < 0)
2366 goto nlmsg_failure; 2548 goto nlmsg_failure;
2549 if (xfrm_mark_put(skb, &xp->mark))
2550 goto nla_put_failure;
2367 upe->hard = !!hard; 2551 upe->hard = !!hard;
2368 2552
2369 return nlmsg_end(skb, nlh); 2553 return nlmsg_end(skb, nlh);
2370 2554
2555nla_put_failure:
2371nlmsg_failure: 2556nlmsg_failure:
2372 nlmsg_cancel(skb, nlh); 2557 nlmsg_cancel(skb, nlh);
2373 return -EMSGSIZE; 2558 return -EMSGSIZE;
@@ -2404,6 +2589,7 @@ static int xfrm_notify_policy(struct xfrm_policy *xp, int dir, struct km_event *
2404 headlen = sizeof(*id); 2589 headlen = sizeof(*id);
2405 } 2590 }
2406 len += userpolicy_type_attrsize(); 2591 len += userpolicy_type_attrsize();
2592 len += nla_total_size(sizeof(struct xfrm_mark));
2407 len += NLMSG_ALIGN(headlen); 2593 len += NLMSG_ALIGN(headlen);
2408 2594
2409 skb = nlmsg_new(len, GFP_ATOMIC); 2595 skb = nlmsg_new(len, GFP_ATOMIC);
@@ -2439,10 +2625,14 @@ static int xfrm_notify_policy(struct xfrm_policy *xp, int dir, struct km_event *
2439 if (copy_to_user_policy_type(xp->type, skb) < 0) 2625 if (copy_to_user_policy_type(xp->type, skb) < 0)
2440 goto nlmsg_failure; 2626 goto nlmsg_failure;
2441 2627
2628 if (xfrm_mark_put(skb, &xp->mark))
2629 goto nla_put_failure;
2630
2442 nlmsg_end(skb, nlh); 2631 nlmsg_end(skb, nlh);
2443 2632
2444 return nlmsg_multicast(net->xfrm.nlsk, skb, 0, XFRMNLGRP_POLICY, GFP_ATOMIC); 2633 return nlmsg_multicast(net->xfrm.nlsk, skb, 0, XFRMNLGRP_POLICY, GFP_ATOMIC);
2445 2634
2635nla_put_failure:
2446nlmsg_failure: 2636nlmsg_failure:
2447 kfree_skb(skb); 2637 kfree_skb(skb);
2448 return -1; 2638 return -1;
@@ -2608,22 +2798,24 @@ static int __net_init xfrm_user_net_init(struct net *net)
2608 xfrm_netlink_rcv, NULL, THIS_MODULE); 2798 xfrm_netlink_rcv, NULL, THIS_MODULE);
2609 if (nlsk == NULL) 2799 if (nlsk == NULL)
2610 return -ENOMEM; 2800 return -ENOMEM;
2801 net->xfrm.nlsk_stash = nlsk; /* Don't set to NULL */
2611 rcu_assign_pointer(net->xfrm.nlsk, nlsk); 2802 rcu_assign_pointer(net->xfrm.nlsk, nlsk);
2612 return 0; 2803 return 0;
2613} 2804}
2614 2805
2615static void __net_exit xfrm_user_net_exit(struct net *net) 2806static void __net_exit xfrm_user_net_exit(struct list_head *net_exit_list)
2616{ 2807{
2617 struct sock *nlsk = net->xfrm.nlsk; 2808 struct net *net;
2618 2809 list_for_each_entry(net, net_exit_list, exit_list)
2619 rcu_assign_pointer(net->xfrm.nlsk, NULL); 2810 rcu_assign_pointer(net->xfrm.nlsk, NULL);
2620 synchronize_rcu(); 2811 synchronize_net();
2621 netlink_kernel_release(nlsk); 2812 list_for_each_entry(net, net_exit_list, exit_list)
2813 netlink_kernel_release(net->xfrm.nlsk_stash);
2622} 2814}
2623 2815
2624static struct pernet_operations xfrm_user_net_ops = { 2816static struct pernet_operations xfrm_user_net_ops = {
2625 .init = xfrm_user_net_init, 2817 .init = xfrm_user_net_init,
2626 .exit = xfrm_user_net_exit, 2818 .exit_batch = xfrm_user_net_exit,
2627}; 2819};
2628 2820
2629static int __init xfrm_user_init(void) 2821static int __init xfrm_user_init(void)